diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index 91b1559146..fe0e735928 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -248,7 +248,7 @@ - + @@ -478,7 +478,7 @@ - + diff --git a/OpenRA.Mods.Common/Traits/AcceptsDeliveredCash.cs b/OpenRA.Mods.Common/Traits/AcceptsDeliveredCash.cs new file mode 100644 index 0000000000..f1a814e8ab --- /dev/null +++ b/OpenRA.Mods.Common/Traits/AcceptsDeliveredCash.cs @@ -0,0 +1,33 @@ +#region Copyright & License Information +/* + * Copyright 2007-2017 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.Collections.Generic; +using OpenRA.Traits; + +namespace OpenRA.Mods.Common.Traits +{ + [Desc("Tag trait for actors with `DeliversCash`.")] + public class AcceptsDeliveredCashInfo : ITraitInfo + { + [Desc("Accepted `DeliversCash` types. Leave empty to accept all types.")] + public readonly HashSet ValidTypes = new HashSet(); + + [Desc("Stance the delivering actor needs to enter.")] + public readonly Stance ValidStances = Stance.Ally; + + public object Create(ActorInitializer init) { return new AcceptsDeliveredCash(init.Self, this); } + } + + public class AcceptsDeliveredCash + { + public AcceptsDeliveredCash(Actor self, AcceptsDeliveredCashInfo info) { } + } +} diff --git a/OpenRA.Mods.Common/Traits/AcceptsSupplies.cs b/OpenRA.Mods.Common/Traits/AcceptsSupplies.cs deleted file mode 100644 index 636021621a..0000000000 --- a/OpenRA.Mods.Common/Traits/AcceptsSupplies.cs +++ /dev/null @@ -1,20 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2017 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 OpenRA.Traits; - -namespace OpenRA.Mods.Common.Traits -{ - [Desc("Tag trait for `SupplyTruck` actors.")] - class AcceptsSuppliesInfo : TraitInfo { } - - class AcceptsSupplies { } -} diff --git a/OpenRA.Mods.Common/Traits/SupplyTruck.cs b/OpenRA.Mods.Common/Traits/DeliversCash.cs similarity index 57% rename from OpenRA.Mods.Common/Traits/SupplyTruck.cs rename to OpenRA.Mods.Common/Traits/DeliversCash.cs index f86036568c..5712e88b6d 100644 --- a/OpenRA.Mods.Common/Traits/SupplyTruck.cs +++ b/OpenRA.Mods.Common/Traits/DeliversCash.cs @@ -17,8 +17,8 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { - [Desc("Donate money to actors with the `AcceptSupplies` trait.")] - class SupplyTruckInfo : ITraitInfo + [Desc("Donate money to actors with the `AcceptsDeliveredCash` trait.")] + class DeliversCashInfo : ITraitInfo { [Desc("The amount of cash the owner receives.")] public readonly int Payload = 500; @@ -26,28 +26,31 @@ namespace OpenRA.Mods.Common.Traits [Desc("The amount of experience the donating player receives.")] public readonly int PlayerExperience = 0; + [Desc("Identifier checked against AcceptsDeliveredCash.ValidTypes. Only needed if the latter is not empty.")] + public readonly string Type = null; + [VoiceReference] public readonly string Voice = "Action"; - public object Create(ActorInitializer init) { return new SupplyTruck(this); } + public object Create(ActorInitializer init) { return new DeliversCash(this); } } - class SupplyTruck : IIssueOrder, IResolveOrder, IOrderVoice + class DeliversCash : IIssueOrder, IResolveOrder, IOrderVoice { - readonly SupplyTruckInfo info; + readonly DeliversCashInfo info; - public SupplyTruck(SupplyTruckInfo info) + public DeliversCash(DeliversCashInfo info) { this.info = info; } public IEnumerable Orders { - get { yield return new SupplyTruckOrderTargeter(); } + get { yield return new DeliversCashOrderTargeter(); } } public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued) { - if (order.OrderID != "DeliverSupplies") + if (order.OrderID != "DeliverCash") return null; if (target.Type == TargetType.FrozenActor) @@ -63,7 +66,7 @@ namespace OpenRA.Mods.Common.Traits public void ResolveOrder(Actor self, Order order) { - if (order.OrderString != "DeliverSupplies") + if (order.OrderString != "DeliverCash") return; var target = self.ResolveFrozenActorOrder(order, Color.Yellow); @@ -77,21 +80,29 @@ namespace OpenRA.Mods.Common.Traits self.QueueActivity(new DonateSupplies(self, target.Actor, info.Payload, info.PlayerExperience)); } - class SupplyTruckOrderTargeter : UnitOrderTargeter + public class DeliversCashOrderTargeter : UnitOrderTargeter { - public SupplyTruckOrderTargeter() - : base("DeliverSupplies", 5, "enter", false, true) - { - } + public DeliversCashOrderTargeter() + : base("DeliverCash", 5, "enter", false, true) { } public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor) { - return target.Info.HasTraitInfo(); + var type = self.Info.TraitInfo().Type; + var targetInfo = target.Info.TraitInfoOrDefault(); + return targetInfo != null + && targetInfo.ValidStances.HasStance(target.Owner.Stances[self.Owner]) + && (targetInfo.ValidTypes.Count == 0 + || (!string.IsNullOrEmpty(type) && targetInfo.ValidTypes.Contains(type))); } public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor) { - return target.Info.HasTraitInfo(); + var type = self.Info.TraitInfo().Type; + var targetInfo = target.Info.TraitInfoOrDefault(); + return targetInfo != null + && targetInfo.ValidStances.HasStance(target.Owner.Stances[self.Owner]) + && (targetInfo.ValidTypes.Count == 0 + || (!string.IsNullOrEmpty(type) && targetInfo.ValidTypes.Contains(type))); } } } diff --git a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs index 376d6d536f..0115b2484a 100644 --- a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs +++ b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs @@ -582,6 +582,20 @@ namespace OpenRA.Mods.Common.UtilityCommands if (engineVersion < 20170318) node.Value.Nodes.RemoveAll(n => n.Key == "ActorGroupProxy"); + // Refactor SupplyTruck/AcceptsSupplies traits to DeliversCash/AcceptsDeliveredCash + if (engineVersion < 20170415) + { + if (node.Key == "SupplyTruck") + RenameNodeKey(node, "DeliversCash"); + if (node.Key == "-SupplyTruck") + RenameNodeKey(node, "-DeliversCash"); + + if (node.Key == "AcceptsSupplies") + RenameNodeKey(node, "AcceptsDeliveredCash"); + if (node.Key == "-AcceptsSupplies") + RenameNodeKey(node, "-AcceptsDeliveredCash"); + } + UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1); } diff --git a/mods/ra/maps/infiltration/rules.yaml b/mods/ra/maps/infiltration/rules.yaml index 2e9f56a035..7baf69fa81 100644 --- a/mods/ra/maps/infiltration/rules.yaml +++ b/mods/ra/maps/infiltration/rules.yaml @@ -82,7 +82,7 @@ TRUK.Hijackable: ExternalCapturable: Type: MissionObjective CaptureCompleteTime: 1 - -SupplyTruck: + -DeliversCash: RenderSprites: Image: TRUK Palette: truk-soviets diff --git a/mods/ra/maps/soviet-06a/rules.yaml b/mods/ra/maps/soviet-06a/rules.yaml index 2368ed4ae5..3d12778c0e 100644 --- a/mods/ra/maps/soviet-06a/rules.yaml +++ b/mods/ra/maps/soviet-06a/rules.yaml @@ -102,7 +102,7 @@ APC: TRUK: -SpawnActorOnDeath: - -SupplyTruck: + -DeliversCash: Buildable: Prerequisites: ~disabled diff --git a/mods/ra/maps/soviet-06b/rules.yaml b/mods/ra/maps/soviet-06b/rules.yaml index b7968d374d..1ea3b7f6af 100644 --- a/mods/ra/maps/soviet-06b/rules.yaml +++ b/mods/ra/maps/soviet-06b/rules.yaml @@ -102,7 +102,7 @@ APC: TRUK: -SpawnActorOnDeath: - -SupplyTruck: + -DeliversCash: Buildable: Prerequisites: ~disabled diff --git a/mods/ra/rules/defaults.yaml b/mods/ra/rules/defaults.yaml index 7998a308ac..d10e940a71 100644 --- a/mods/ra/rules/defaults.yaml +++ b/mods/ra/rules/defaults.yaml @@ -527,7 +527,7 @@ RepairableBuilding: PlayerExperience: 25 EngineerRepairable: - AcceptsSupplies: + AcceptsDeliveredCash: WithMakeAnimation: ExternalCapturable: ExternalCapturableBar: @@ -553,7 +553,7 @@ RequiredForShortGame: false AutoTarget: -GivesBuildableArea: - -AcceptsSupplies: + -AcceptsDeliveredCash: DrawLineToTarget: RenderRangeCircle: Explodes: diff --git a/mods/ra/rules/structures.yaml b/mods/ra/rules/structures.yaml index 9f5ee33f45..8fc688e0ca 100644 --- a/mods/ra/rules/structures.yaml +++ b/mods/ra/rules/structures.yaml @@ -403,7 +403,7 @@ PDOX: DisplayRadarPing: True Range: 2 SupportPowerChargeBar: - -AcceptsSupplies: + -AcceptsDeliveredCash: Power: Amount: -200 MustBeDestroyed: diff --git a/mods/ra/rules/vehicles.yaml b/mods/ra/rules/vehicles.yaml index ffe6bd14b0..0f092b1732 100644 --- a/mods/ra/rules/vehicles.yaml +++ b/mods/ra/rules/vehicles.yaml @@ -476,7 +476,7 @@ TRUK: Speed: 128 RevealsShroud: Range: 4c0 - SupplyTruck: + DeliversCash: Payload: 500 PlayerExperience: 50 SpawnActorOnDeath: diff --git a/mods/ts/rules/civilian-structures.yaml b/mods/ts/rules/civilian-structures.yaml index 1a649092f8..0173ad1116 100644 --- a/mods/ts/rules/civilian-structures.yaml +++ b/mods/ts/rules/civilian-structures.yaml @@ -1309,7 +1309,6 @@ GAICBM: Inherits: ^Building Valued: Cost: 800 - -AcceptsSupplies: Tooltip: Name: Deployed ICBM -GivesBuildableArea: diff --git a/mods/ts/rules/defaults.yaml b/mods/ts/rules/defaults.yaml index e506ed8b9c..635212b4bb 100644 --- a/mods/ts/rules/defaults.yaml +++ b/mods/ts/rules/defaults.yaml @@ -152,7 +152,6 @@ Type: Footprint EngineerRepairable: ShakeOnDeath: - AcceptsSupplies: Guardable: Range: 3c0 Demolishable: