Convert PrimaryBuilding to conditions.
This commit is contained in:
@@ -26,10 +26,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
|
||||
[Desc("Used together with ClassicProductionQueue.")]
|
||||
public class PrimaryBuildingInfo : ITraitInfo, Requires<UpgradeManagerInfo>
|
||||
public class PrimaryBuildingInfo : ITraitInfo
|
||||
{
|
||||
[UpgradeGrantedReference, Desc("The upgrades to grant while the primary building.")]
|
||||
public readonly string[] Upgrades = { "primary" };
|
||||
[UpgradeGrantedReference]
|
||||
[Desc("The condition to grant to self while this is the primary building.")]
|
||||
public readonly string PrimaryCondition = null;
|
||||
|
||||
[Desc("The speech notification to play when selecting a primary building.")]
|
||||
public readonly string SelectionNotification = "PrimaryBuildingSelected";
|
||||
@@ -37,25 +38,30 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public object Create(ActorInitializer init) { return new PrimaryBuilding(init.Self, this); }
|
||||
}
|
||||
|
||||
public class PrimaryBuilding : IIssueOrder, IResolveOrder
|
||||
public class PrimaryBuilding : INotifyCreated, IIssueOrder, IResolveOrder
|
||||
{
|
||||
readonly PrimaryBuildingInfo info;
|
||||
readonly UpgradeManager manager;
|
||||
UpgradeManager um;
|
||||
int primaryToken = UpgradeManager.InvalidConditionToken;
|
||||
|
||||
public bool IsPrimary { get; private set; }
|
||||
|
||||
public PrimaryBuilding(Actor self, PrimaryBuildingInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
manager = self.Trait<UpgradeManager>();
|
||||
}
|
||||
|
||||
public IEnumerable<IOrderTargeter> Orders
|
||||
void INotifyCreated.Created(Actor self)
|
||||
{
|
||||
um = self.TraitOrDefault<UpgradeManager>();
|
||||
}
|
||||
|
||||
IEnumerable<IOrderTargeter> IIssueOrder.Orders
|
||||
{
|
||||
get { yield return new DeployOrderTargeter("PrimaryProducer", 1); }
|
||||
}
|
||||
|
||||
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
|
||||
Order IIssueOrder.IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
|
||||
{
|
||||
if (order.OrderID == "PrimaryProducer")
|
||||
return new Order(order.OrderID, self, false);
|
||||
@@ -63,41 +69,39 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return null;
|
||||
}
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
void IResolveOrder.ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
if (order.OrderString == "PrimaryProducer")
|
||||
SetPrimaryProducer(self, !IsPrimary);
|
||||
}
|
||||
|
||||
public void SetPrimaryProducer(Actor self, bool state)
|
||||
public void SetPrimaryProducer(Actor self, bool isPrimary)
|
||||
{
|
||||
if (state == false)
|
||||
{
|
||||
IsPrimary = false;
|
||||
foreach (var up in info.Upgrades)
|
||||
manager.RevokeUpgrade(self, up, this);
|
||||
return;
|
||||
}
|
||||
IsPrimary = isPrimary;
|
||||
|
||||
// TODO: THIS IS SHIT
|
||||
if (isPrimary)
|
||||
{
|
||||
// Cancel existing primaries
|
||||
// TODO: THIS IS SHIT
|
||||
foreach (var p in self.Info.TraitInfo<ProductionInfo>().Produces)
|
||||
{
|
||||
var productionType = p; // benign closure hazard
|
||||
foreach (var b in self.World
|
||||
.ActorsWithTrait<PrimaryBuilding>()
|
||||
.Where(a =>
|
||||
a.Actor != self &&
|
||||
a.Actor.Owner == self.Owner &&
|
||||
a.Trait.IsPrimary &&
|
||||
a.Actor.Info.TraitInfo<ProductionInfo>().Produces.Contains(productionType)))
|
||||
a.Actor.Info.TraitInfo<ProductionInfo>().Produces.Contains(p)))
|
||||
b.Trait.SetPrimaryProducer(b.Actor, false);
|
||||
}
|
||||
|
||||
IsPrimary = true;
|
||||
foreach (var up in info.Upgrades)
|
||||
manager.GrantUpgrade(self, up, this);
|
||||
if (um != null && primaryToken == UpgradeManager.InvalidConditionToken && !string.IsNullOrEmpty(info.PrimaryCondition))
|
||||
primaryToken = um.GrantCondition(self, info.PrimaryCondition);
|
||||
|
||||
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", info.SelectionNotification, self.Owner.Faction.InternalName);
|
||||
}
|
||||
else if (primaryToken != UpgradeManager.InvalidConditionToken)
|
||||
primaryToken = um.RevokeCondition(self, primaryToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -610,6 +610,13 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
if (!node.Value.Nodes.Any(n => n.Key == "ParachutingCondition"))
|
||||
node.Value.Nodes.Add(new MiniYamlNode("ParachutingCondition", "parachute"));
|
||||
}
|
||||
|
||||
if (node.Key == "PrimaryBuilding")
|
||||
{
|
||||
ConvertUpgradesToCondition(parent, node, "Upgrades", "PrimaryCondition");
|
||||
if (!node.Value.Nodes.Any(n => n.Key == "PrimaryCondition"))
|
||||
node.Value.Nodes.Add(new MiniYamlNode("PrimaryCondition", "primary"));
|
||||
}
|
||||
}
|
||||
|
||||
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||
|
||||
@@ -88,6 +88,7 @@ construction_yard:
|
||||
WithBuildingPlacedOverlay:
|
||||
Palette: d2k
|
||||
PrimaryBuilding:
|
||||
PrimaryCondition: primary
|
||||
ProvidesPrerequisite@buildingname:
|
||||
GlobalUpgradable:
|
||||
Prerequisites: upgrade.conyard
|
||||
@@ -181,6 +182,7 @@ barracks:
|
||||
Production:
|
||||
Produces: Infantry
|
||||
PrimaryBuilding:
|
||||
PrimaryCondition: primary
|
||||
ProductionBar:
|
||||
ProvidesPrerequisite@atreides:
|
||||
Prerequisite: barracks.atreides
|
||||
@@ -360,6 +362,7 @@ light_factory:
|
||||
Production:
|
||||
Produces: Vehicle
|
||||
PrimaryBuilding:
|
||||
PrimaryCondition: primary
|
||||
ProductionBar:
|
||||
ProvidesPrerequisite@atreides:
|
||||
Prerequisite: light.atreides
|
||||
@@ -430,6 +433,7 @@ heavy_factory:
|
||||
Production:
|
||||
Produces: Armor
|
||||
PrimaryBuilding:
|
||||
PrimaryCondition: primary
|
||||
ProductionBar:
|
||||
ProvidesPrerequisite@atreides:
|
||||
Prerequisite: heavy.atreides
|
||||
@@ -567,6 +571,7 @@ starport:
|
||||
Palette: starportlights
|
||||
ProductionBar:
|
||||
PrimaryBuilding:
|
||||
PrimaryCondition: primary
|
||||
RequiresPower:
|
||||
CanPowerDown:
|
||||
PowerupSound: EnablePower
|
||||
|
||||
@@ -134,6 +134,7 @@ SPEN:
|
||||
Production:
|
||||
Produces: Ship, Submarine
|
||||
PrimaryBuilding:
|
||||
PrimaryCondition: primary
|
||||
-EmitInfantryOnSell:
|
||||
RepairsUnits:
|
||||
FinishRepairingNotification: UnitRepaired
|
||||
@@ -223,6 +224,7 @@ SYRD:
|
||||
Production:
|
||||
Produces: Ship, Boat
|
||||
PrimaryBuilding:
|
||||
PrimaryCondition: primary
|
||||
-EmitInfantryOnSell:
|
||||
RepairsUnits:
|
||||
FinishRepairingNotification: UnitRepaired
|
||||
@@ -854,6 +856,7 @@ WEAP:
|
||||
RequiresPrerequisites: structures.ukraine
|
||||
Prerequisite: vehicles.ukraine
|
||||
PrimaryBuilding:
|
||||
PrimaryCondition: primary
|
||||
ProductionBar:
|
||||
Power:
|
||||
Amount: -30
|
||||
@@ -1060,6 +1063,7 @@ HPAD:
|
||||
Reservable:
|
||||
ProductionBar:
|
||||
PrimaryBuilding:
|
||||
PrimaryCondition: primary
|
||||
Power:
|
||||
Amount: -10
|
||||
ProvidesPrerequisite@allies:
|
||||
@@ -1206,6 +1210,7 @@ AFLD:
|
||||
ProductionBar:
|
||||
SupportPowerChargeBar:
|
||||
PrimaryBuilding:
|
||||
PrimaryCondition: primary
|
||||
Power:
|
||||
Amount: -20
|
||||
ProvidesPrerequisite@buildingname:
|
||||
@@ -1354,6 +1359,7 @@ BARR:
|
||||
Production:
|
||||
Produces: Infantry, Soldier
|
||||
PrimaryBuilding:
|
||||
PrimaryCondition: primary
|
||||
ProductionBar:
|
||||
ProvidesPrerequisite:
|
||||
Prerequisite: barracks
|
||||
@@ -1428,6 +1434,7 @@ KENN:
|
||||
Production:
|
||||
Produces: Infantry, Dog
|
||||
PrimaryBuilding:
|
||||
PrimaryCondition: primary
|
||||
ProductionBar:
|
||||
-EmitInfantryOnSell:
|
||||
Power:
|
||||
@@ -1472,6 +1479,7 @@ TENT:
|
||||
Production:
|
||||
Produces: Infantry, Soldier
|
||||
PrimaryBuilding:
|
||||
PrimaryCondition: primary
|
||||
ProductionBar:
|
||||
ProvidesPrerequisite@barracks:
|
||||
Prerequisite: barracks
|
||||
|
||||
@@ -96,6 +96,7 @@ GAPILE:
|
||||
Production:
|
||||
Produces: Infantry
|
||||
PrimaryBuilding:
|
||||
PrimaryCondition: primary
|
||||
ProductionBar:
|
||||
WithProductionOverlay@LIGHTS:
|
||||
Sequence: production-lights
|
||||
@@ -153,6 +154,7 @@ GAWEAP:
|
||||
Production:
|
||||
Produces: Vehicle
|
||||
PrimaryBuilding:
|
||||
PrimaryCondition: primary
|
||||
ProductionBar:
|
||||
WithIdleOverlay@ROOF:
|
||||
Sequence: idle-roof
|
||||
@@ -206,6 +208,7 @@ GAHPAD:
|
||||
Production:
|
||||
Produces: Air
|
||||
PrimaryBuilding:
|
||||
PrimaryCondition: primary
|
||||
Reservable:
|
||||
RepairsUnits:
|
||||
PlayerExperience: 15
|
||||
|
||||
@@ -112,6 +112,7 @@ NAHAND:
|
||||
Production:
|
||||
Produces: Infantry
|
||||
PrimaryBuilding:
|
||||
PrimaryCondition: primary
|
||||
ProductionBar:
|
||||
WithIdleOverlay@LIGHTS:
|
||||
Sequence: idle-lights
|
||||
@@ -167,6 +168,7 @@ NAWEAP:
|
||||
Production:
|
||||
Produces: Vehicle
|
||||
PrimaryBuilding:
|
||||
PrimaryCondition: primary
|
||||
ProductionBar:
|
||||
WithIdleOverlay@ROOF:
|
||||
Sequence: idle-roof
|
||||
@@ -216,6 +218,7 @@ NAHPAD:
|
||||
Production:
|
||||
Produces: Air
|
||||
PrimaryBuilding:
|
||||
PrimaryCondition: primary
|
||||
Reservable:
|
||||
RepairsUnits:
|
||||
PlayerExperience: 15
|
||||
|
||||
Reference in New Issue
Block a user