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);
|
||||
|
||||
@@ -283,8 +283,8 @@
|
||||
DamageInterval: 16
|
||||
DamageTypes: TiberiumDeath
|
||||
RequiresCondition: !hazmatsuits
|
||||
GlobalUpgradable@BIO:
|
||||
Upgrades: hazmatsuits
|
||||
GrantConditionOnPrerequisite@BIO:
|
||||
Condition: hazmatsuits
|
||||
Prerequisites: bio
|
||||
WithDecoration@HAZMAT:
|
||||
Image: pips
|
||||
@@ -309,8 +309,8 @@
|
||||
HealIfBelow: 100
|
||||
DamageCooldown: 125
|
||||
RequiresCondition: hospitalheal
|
||||
GlobalUpgradable@HOSPITAL:
|
||||
Upgrades: hospitalheal
|
||||
GrantConditionOnPrerequisite@HOSPITAL:
|
||||
Condition: hospitalheal
|
||||
Prerequisites: hosp
|
||||
WithDecoration@REDCROSS:
|
||||
Image: pips
|
||||
|
||||
@@ -32,6 +32,6 @@ Player:
|
||||
Name: Unrestricted
|
||||
Prerequisites: techlevel.low, techlevel.medium, techlevel.high, techlevel.superweapons
|
||||
Id: unrestricted
|
||||
GlobalUpgradeManager:
|
||||
GrantConditionOnPrerequisiteManager:
|
||||
ResourceStorageWarning:
|
||||
PlayerExperience:
|
||||
|
||||
@@ -88,7 +88,7 @@ Player:
|
||||
Id: unrestricted
|
||||
EnemyWatcher:
|
||||
HarvesterInsurance:
|
||||
GlobalUpgradeManager:
|
||||
GrantConditionOnPrerequisiteManager:
|
||||
ResourceStorageWarning:
|
||||
AdviceInterval: 26
|
||||
PlayerExperience:
|
||||
|
||||
@@ -90,9 +90,9 @@ construction_yard:
|
||||
PrimaryBuilding:
|
||||
PrimaryCondition: primary
|
||||
ProvidesPrerequisite@buildingname:
|
||||
GlobalUpgradable:
|
||||
GrantConditionOnPrerequisite:
|
||||
Prerequisites: upgrade.conyard
|
||||
Upgrades: stardecoration
|
||||
Condition: stardecoration
|
||||
WithDecoration@upgraded:
|
||||
RequiresSelection: true
|
||||
Image: pips
|
||||
@@ -203,9 +203,9 @@ barracks:
|
||||
smuggler: barracks.ordos
|
||||
mercenary: barracks.ordos
|
||||
ProvidesPrerequisite@buildingname:
|
||||
GlobalUpgradable:
|
||||
GrantConditionOnPrerequisite:
|
||||
Prerequisites: upgrade.barracks
|
||||
Upgrades: stardecoration
|
||||
Condition: stardecoration
|
||||
WithDecoration@upgraded:
|
||||
RequiresSelection: true
|
||||
Image: pips
|
||||
@@ -383,9 +383,9 @@ light_factory:
|
||||
Sequence: idle-top
|
||||
Power:
|
||||
Amount: -125
|
||||
GlobalUpgradable:
|
||||
GrantConditionOnPrerequisite:
|
||||
Prerequisites: upgrade.light
|
||||
Upgrades: stardecoration
|
||||
Condition: stardecoration
|
||||
WithDecoration@upgraded:
|
||||
RequiresSelection: true
|
||||
Image: pips
|
||||
@@ -463,9 +463,9 @@ heavy_factory:
|
||||
ProvidesPrerequisite@buildingname:
|
||||
SelectionDecorations:
|
||||
VisualBounds: 96,96
|
||||
GlobalUpgradable:
|
||||
GrantConditionOnPrerequisite:
|
||||
Prerequisites: upgrade.heavy
|
||||
Upgrades: stardecoration
|
||||
Condition: stardecoration
|
||||
WithDecoration@upgraded:
|
||||
RequiresSelection: true
|
||||
Image: pips
|
||||
@@ -841,9 +841,9 @@ high_tech_factory:
|
||||
Amount: -75
|
||||
SelectionDecorations:
|
||||
VisualBounds: 96,96
|
||||
GlobalUpgradable:
|
||||
GrantConditionOnPrerequisite:
|
||||
Prerequisites: upgrade.hightech
|
||||
Upgrades: stardecoration
|
||||
Condition: stardecoration
|
||||
WithDecoration@upgraded:
|
||||
RequiresSelection: true
|
||||
Image: pips
|
||||
|
||||
@@ -291,8 +291,8 @@
|
||||
HealIfBelow: 100
|
||||
DamageCooldown: 125
|
||||
RequiresCondition: hospitalheal
|
||||
GlobalUpgradable:
|
||||
Upgrades: hospitalheal
|
||||
GrantConditionOnPrerequisite:
|
||||
Condition: hospitalheal
|
||||
Prerequisites: hosp
|
||||
DeathSounds@NORMAL:
|
||||
DeathTypes: DefaultDeath, BulletDeath, SmallExplosionDeath, ExplosionDeath
|
||||
|
||||
@@ -69,7 +69,7 @@ Player:
|
||||
Name: Unrestricted
|
||||
Prerequisites: techlevel.infonly, techlevel.low, techlevel.medium, techlevel.high, techlevel.unrestricted
|
||||
Id: unrestricted
|
||||
GlobalUpgradeManager:
|
||||
GrantConditionOnPrerequisiteManager:
|
||||
EnemyWatcher:
|
||||
VeteranProductionIconOverlay:
|
||||
Image: iconchevrons
|
||||
|
||||
@@ -326,8 +326,8 @@
|
||||
HealIfBelow: 100
|
||||
DamageCooldown: 125
|
||||
RequiresCondition: hospitalheal
|
||||
GlobalUpgradable@HOSPITAL:
|
||||
Upgrades: hospitalheal
|
||||
GrantConditionOnPrerequisite@HOSPITAL:
|
||||
Condition: hospitalheal
|
||||
Prerequisites: cahosp
|
||||
WithDecoration@REDCROSS:
|
||||
Image: pips
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
Player:
|
||||
AlwaysVisible:
|
||||
TechTree:
|
||||
GlobalUpgradeManager:
|
||||
GrantConditionOnPrerequisiteManager:
|
||||
ClassicProductionQueue@Building:
|
||||
Type: Building
|
||||
BuildDurationModifier: 120
|
||||
|
||||
Reference in New Issue
Block a user