Convert GlobalUpgradable to conditions.
This commit is contained in:
@@ -331,7 +331,7 @@
|
||||
<Compile Include="Traits\GainsExperience.cs" />
|
||||
<Compile Include="Traits\GivesBounty.cs" />
|
||||
<Compile Include="Traits\GivesExperience.cs" />
|
||||
<Compile Include="Traits\GlobalUpgradable.cs" />
|
||||
<Compile Include="Traits\GrantConditionOnPrerequisite.cs" />
|
||||
<Compile Include="Traits\Guard.cs" />
|
||||
<Compile Include="Traits\Guardable.cs" />
|
||||
<Compile Include="Traits\Harvester.cs" />
|
||||
@@ -373,7 +373,7 @@
|
||||
<Compile Include="Traits\Player\ClassicProductionQueue.cs" />
|
||||
<Compile Include="Traits\Player\ConquestVictoryConditions.cs" />
|
||||
<Compile Include="Traits\Player\EnemyWatcher.cs" />
|
||||
<Compile Include="Traits\Player\GlobalUpgradeManager.cs" />
|
||||
<Compile Include="Traits\Player\GrantConditionOnPrerequisiteManager.cs" />
|
||||
<Compile Include="Traits\Player\HarvesterAttackNotifier.cs" />
|
||||
<Compile Include="Traits\Player\MissionObjectives.cs" />
|
||||
<Compile Include="Traits\Player\PlaceBeacon.cs" />
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2016 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, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Grants upgrades to the actor this is attached to when prerequisites are available.")]
|
||||
public class GlobalUpgradableInfo : ITraitInfo, Requires<UpgradeManagerInfo>
|
||||
{
|
||||
[UpgradeGrantedReference, FieldLoader.Require]
|
||||
[Desc("List of upgrades to apply.")]
|
||||
public readonly string[] Upgrades = { };
|
||||
|
||||
[FieldLoader.Require]
|
||||
[Desc("List of required prerequisites.")]
|
||||
public readonly string[] Prerequisites = { };
|
||||
|
||||
public object Create(ActorInitializer init) { return new GlobalUpgradable(init.Self, this); }
|
||||
}
|
||||
|
||||
public class GlobalUpgradable : INotifyAddedToWorld, INotifyRemovedFromWorld
|
||||
{
|
||||
readonly GlobalUpgradableInfo info;
|
||||
readonly GlobalUpgradeManager globalManager;
|
||||
readonly UpgradeManager manager;
|
||||
bool wasAvailable;
|
||||
|
||||
public GlobalUpgradable(Actor self, GlobalUpgradableInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
globalManager = self.Owner.PlayerActor.Trait<GlobalUpgradeManager>();
|
||||
manager = self.Trait<UpgradeManager>();
|
||||
}
|
||||
|
||||
public void AddedToWorld(Actor self)
|
||||
{
|
||||
if (info.Prerequisites.Any())
|
||||
globalManager.Register(self, this, info.Prerequisites);
|
||||
}
|
||||
|
||||
public void RemovedFromWorld(Actor self)
|
||||
{
|
||||
if (info.Prerequisites.Any())
|
||||
globalManager.Unregister(self, this, info.Prerequisites);
|
||||
}
|
||||
|
||||
public void PrerequisitesUpdated(Actor self, bool available)
|
||||
{
|
||||
if (available == wasAvailable)
|
||||
return;
|
||||
|
||||
if (available)
|
||||
foreach (var u in info.Upgrades)
|
||||
manager.GrantUpgrade(self, u, this);
|
||||
else
|
||||
foreach (var u in info.Upgrades)
|
||||
manager.RevokeUpgrade(self, u, this);
|
||||
|
||||
wasAvailable = available;
|
||||
}
|
||||
}
|
||||
}
|
||||
78
OpenRA.Mods.Common/Traits/GrantConditionOnPrerequisite.cs
Normal file
78
OpenRA.Mods.Common/Traits/GrantConditionOnPrerequisite.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2016 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, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Grants a condition to the actor this is attached to when prerequisites are available.")]
|
||||
public class GrantConditionOnPrerequisiteInfo : ITraitInfo
|
||||
{
|
||||
[FieldLoader.Require]
|
||||
[UpgradeGrantedReference]
|
||||
[Desc("The condition to grant.")]
|
||||
public readonly string Condition = null;
|
||||
|
||||
[FieldLoader.Require]
|
||||
[Desc("List of required prerequisites.")]
|
||||
public readonly string[] Prerequisites = { };
|
||||
|
||||
public object Create(ActorInitializer init) { return new GrantConditionOnPrerequisite(init.Self, this); }
|
||||
}
|
||||
|
||||
public class GrantConditionOnPrerequisite : INotifyCreated, INotifyAddedToWorld, INotifyRemovedFromWorld
|
||||
{
|
||||
readonly GrantConditionOnPrerequisiteInfo info;
|
||||
readonly GrantConditionOnPrerequisiteManager globalManager;
|
||||
|
||||
UpgradeManager manager;
|
||||
int conditionToken = UpgradeManager.InvalidConditionToken;
|
||||
|
||||
bool wasAvailable;
|
||||
|
||||
public GrantConditionOnPrerequisite(Actor self, GrantConditionOnPrerequisiteInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
globalManager = self.Owner.PlayerActor.Trait<GrantConditionOnPrerequisiteManager>();
|
||||
}
|
||||
|
||||
void INotifyCreated.Created(Actor self)
|
||||
{
|
||||
manager = self.TraitOrDefault<UpgradeManager>();
|
||||
}
|
||||
|
||||
void INotifyAddedToWorld.AddedToWorld(Actor self)
|
||||
{
|
||||
if (info.Prerequisites.Any())
|
||||
globalManager.Register(self, this, info.Prerequisites);
|
||||
}
|
||||
|
||||
void INotifyRemovedFromWorld.RemovedFromWorld(Actor self)
|
||||
{
|
||||
if (info.Prerequisites.Any())
|
||||
globalManager.Unregister(self, this, info.Prerequisites);
|
||||
}
|
||||
|
||||
public void PrerequisitesUpdated(Actor self, bool available)
|
||||
{
|
||||
if (available == wasAvailable || manager == null)
|
||||
return;
|
||||
|
||||
if (available && conditionToken == UpgradeManager.InvalidConditionToken)
|
||||
conditionToken = manager.GrantCondition(self, info.Condition);
|
||||
else if (!available && conditionToken != UpgradeManager.InvalidConditionToken)
|
||||
conditionToken = manager.RevokeCondition(self, conditionToken);
|
||||
|
||||
wasAvailable = available;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,18 +17,18 @@ using OpenRA.Traits;
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Attach this to the player actor.")]
|
||||
public class GlobalUpgradeManagerInfo : ITraitInfo, Requires<TechTreeInfo>
|
||||
public class GrantConditionOnPrerequisiteManagerInfo : ITraitInfo, Requires<TechTreeInfo>
|
||||
{
|
||||
public object Create(ActorInitializer init) { return new GlobalUpgradeManager(init); }
|
||||
public object Create(ActorInitializer init) { return new GrantConditionOnPrerequisiteManager(init); }
|
||||
}
|
||||
|
||||
public class GlobalUpgradeManager : ITechTreeElement
|
||||
public class GrantConditionOnPrerequisiteManager : ITechTreeElement
|
||||
{
|
||||
readonly Actor self;
|
||||
readonly Dictionary<string, List<Pair<Actor, GlobalUpgradable>>> upgradables = new Dictionary<string, List<Pair<Actor, GlobalUpgradable>>>();
|
||||
readonly Dictionary<string, List<Pair<Actor, GrantConditionOnPrerequisite>>> upgradables = new Dictionary<string, List<Pair<Actor, GrantConditionOnPrerequisite>>>();
|
||||
readonly TechTree techTree;
|
||||
|
||||
public GlobalUpgradeManager(ActorInitializer init)
|
||||
public GrantConditionOnPrerequisiteManager(ActorInitializer init)
|
||||
{
|
||||
self = init.Self;
|
||||
techTree = self.Trait<TechTree>();
|
||||
@@ -39,12 +39,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return "upgrade_" + string.Join("_", prerequisites.OrderBy(a => a));
|
||||
}
|
||||
|
||||
public void Register(Actor actor, GlobalUpgradable u, string[] prerequisites)
|
||||
public void Register(Actor actor, GrantConditionOnPrerequisite u, string[] prerequisites)
|
||||
{
|
||||
var key = MakeKey(prerequisites);
|
||||
if (!upgradables.ContainsKey(key))
|
||||
{
|
||||
upgradables.Add(key, new List<Pair<Actor, GlobalUpgradable>>());
|
||||
upgradables.Add(key, new List<Pair<Actor, GrantConditionOnPrerequisite>>());
|
||||
techTree.Add(key, prerequisites, 0, this);
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
u.PrerequisitesUpdated(actor, techTree.HasPrerequisites(prerequisites));
|
||||
}
|
||||
|
||||
public void Unregister(Actor actor, GlobalUpgradable u, string[] prerequisites)
|
||||
public void Unregister(Actor actor, GrantConditionOnPrerequisite u, string[] prerequisites)
|
||||
{
|
||||
var key = MakeKey(prerequisites);
|
||||
var list = upgradables[key];
|
||||
@@ -69,7 +69,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void PrerequisitesAvailable(string key)
|
||||
{
|
||||
List<Pair<Actor, GlobalUpgradable>> list;
|
||||
List<Pair<Actor, GrantConditionOnPrerequisite>> list;
|
||||
if (!upgradables.TryGetValue(key, out list))
|
||||
return;
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void PrerequisitesUnavailable(string key)
|
||||
{
|
||||
List<Pair<Actor, GlobalUpgradable>> list;
|
||||
List<Pair<Actor, GrantConditionOnPrerequisite>> list;
|
||||
if (!upgradables.TryGetValue(key, out list))
|
||||
return;
|
||||
|
||||
@@ -659,6 +659,15 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (node.Key.StartsWith("GlobalUpgradable", StringComparison.Ordinal))
|
||||
{
|
||||
RenameNodeKey(node, "GrantConditionOnPrerequisite");
|
||||
ConvertUpgradesToCondition(parent, node, "Upgrades", "Condition");
|
||||
}
|
||||
|
||||
if (node.Key.StartsWith("GlobalUpgradeManager", StringComparison.Ordinal))
|
||||
RenameNodeKey(node, "GrantConditionOnPrerequisiteManager");
|
||||
}
|
||||
|
||||
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||
|
||||
Reference in New Issue
Block a user