Allow custom prerequisites to be restricted by race.
This commit is contained in:
@@ -517,6 +517,7 @@
|
|||||||
<Compile Include="Render\WithRepairOverlay.cs" />
|
<Compile Include="Render\WithRepairOverlay.cs" />
|
||||||
<Compile Include="Activities\MoveWithinRange.cs" />
|
<Compile Include="Activities\MoveWithinRange.cs" />
|
||||||
<Compile Include="Lint\CheckPlayers.cs" />
|
<Compile Include="Lint\CheckPlayers.cs" />
|
||||||
|
<Compile Include="Player\ProvidesCustomPrerequisite.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.Game\OpenRA.Game.csproj">
|
<ProjectReference Include="..\OpenRA.Game\OpenRA.Game.csproj">
|
||||||
|
|||||||
77
OpenRA.Mods.RA/Player/ProvidesCustomPrerequisite.cs
Executable file
77
OpenRA.Mods.RA/Player/ProvidesCustomPrerequisite.cs
Executable file
@@ -0,0 +1,77 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
|
||||||
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
|
* available to you under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation. For more information,
|
||||||
|
* see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using OpenRA.Primitives;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.RA
|
||||||
|
{
|
||||||
|
public class ProvidesCustomPrerequisiteInfo : ITraitInfo
|
||||||
|
{
|
||||||
|
[Desc("The prerequisite type that this provides")]
|
||||||
|
public readonly string Prerequisite = null;
|
||||||
|
|
||||||
|
[Desc("Only grant this prerequisite for certain factions")]
|
||||||
|
public readonly string[] Race = { };
|
||||||
|
|
||||||
|
[Desc("Should the prerequisite remain enabled if the owner changes?")]
|
||||||
|
public readonly bool Sticky = true;
|
||||||
|
public object Create(ActorInitializer init) { return new ProvidesCustomPrerequisite(init, this); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ProvidesCustomPrerequisite : ITechTreePrerequisite, INotifyOwnerChanged
|
||||||
|
{
|
||||||
|
ProvidesCustomPrerequisiteInfo info;
|
||||||
|
bool enabled = true;
|
||||||
|
|
||||||
|
public ProvidesCustomPrerequisite(ActorInitializer init, ProvidesCustomPrerequisiteInfo info)
|
||||||
|
{
|
||||||
|
this.info = info;
|
||||||
|
|
||||||
|
if (info.Race.Any())
|
||||||
|
{
|
||||||
|
var race = init.self.Owner.Country.Race;
|
||||||
|
if (init.Contains<RaceInit>())
|
||||||
|
race = init.Get<RaceInit, string>();
|
||||||
|
|
||||||
|
enabled = info.Race.Contains(race);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<string> ProvidesPrerequisites
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (!enabled)
|
||||||
|
yield break;
|
||||||
|
|
||||||
|
yield return info.Prerequisite;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
|
||||||
|
{
|
||||||
|
if (!info.Sticky && info.Race.Any())
|
||||||
|
enabled = info.Race.Contains(self.Owner.Country.Race);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allows maps / transformations to specify the race variant of an actor.
|
||||||
|
public class RaceInit : IActorInit<string>
|
||||||
|
{
|
||||||
|
[FieldFromYamlKey] public readonly string Race;
|
||||||
|
|
||||||
|
public RaceInit() { }
|
||||||
|
public RaceInit(string race) { Race = race; }
|
||||||
|
public string Value(World world) { return Race; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#region Copyright & License Information
|
#region Copyright & License Information
|
||||||
/*
|
/*
|
||||||
* Copyright 2007-2013 The OpenRA Developers (see AUTHORS)
|
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
|
||||||
* This file is part of OpenRA, which is free software. It is made
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
* available to you under the terms of the GNU General Public License
|
* available to you under the terms of the GNU General Public License
|
||||||
* as published by the Free Software Foundation. For more information,
|
* as published by the Free Software Foundation. For more information,
|
||||||
@@ -155,23 +155,4 @@ namespace OpenRA.Mods.RA
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ProvidesCustomPrerequisiteInfo : ITraitInfo
|
|
||||||
{
|
|
||||||
public readonly string Prerequisite;
|
|
||||||
|
|
||||||
public object Create(ActorInitializer init) { return new ProvidesCustomPrerequisite(this); }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ProvidesCustomPrerequisite : ITechTreePrerequisite
|
|
||||||
{
|
|
||||||
ProvidesCustomPrerequisiteInfo info;
|
|
||||||
|
|
||||||
public IEnumerable<string> ProvidesPrerequisites { get { yield return info.Prerequisite; } }
|
|
||||||
|
|
||||||
public ProvidesCustomPrerequisite(ProvidesCustomPrerequisiteInfo info)
|
|
||||||
{
|
|
||||||
this.info = info;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user