Refactor supply traits to *Cash traits

Adding 'Type' and 'Stances' support as well.
This commit is contained in:
reaperrr
2017-03-20 20:13:10 +01:00
parent 361cbc34cc
commit 80ec530e4c
13 changed files with 83 additions and 47 deletions

View File

@@ -248,7 +248,7 @@
<Compile Include="Scripting\Properties\ParadropProperties.cs" />
<Compile Include="Scripting\Properties\ParatroopersProperties.cs" />
<Compile Include="TraitsInterfaces.cs" />
<Compile Include="Traits\AcceptsSupplies.cs" />
<Compile Include="Traits\AcceptsDeliveredCash.cs" />
<Compile Include="Traits\Air\Aircraft.cs" />
<Compile Include="Traits\Air\AttackBomber.cs" />
<Compile Include="Traits\Air\AttackHeli.cs" />
@@ -478,7 +478,7 @@
<Compile Include="Traits\Sound\DeathSounds.cs" />
<Compile Include="Traits\Sound\SoundOnDamageTransition.cs" />
<Compile Include="Traits\Sound\AttackSounds.cs" />
<Compile Include="Traits\SupplyTruck.cs" />
<Compile Include="Traits\DeliversCash.cs" />
<Compile Include="Traits\SupportPowers\AirstrikePower.cs" />
<Compile Include="Traits\SupportPowers\GrantExternalConditionPower.cs" />
<Compile Include="Traits\SupportPowers\NukePower.cs" />

View File

@@ -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<string> ValidTypes = new HashSet<string>();
[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) { }
}
}

View File

@@ -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<AcceptsSupplies> { }
class AcceptsSupplies { }
}

View File

@@ -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<IOrderTargeter> 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<AcceptsSuppliesInfo>();
var type = self.Info.TraitInfo<DeliversCashInfo>().Type;
var targetInfo = target.Info.TraitInfoOrDefault<AcceptsDeliveredCashInfo>();
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<AcceptsSuppliesInfo>();
var type = self.Info.TraitInfo<DeliversCashInfo>().Type;
var targetInfo = target.Info.TraitInfoOrDefault<AcceptsDeliveredCashInfo>();
return targetInfo != null
&& targetInfo.ValidStances.HasStance(target.Owner.Stances[self.Owner])
&& (targetInfo.ValidTypes.Count == 0
|| (!string.IsNullOrEmpty(type) && targetInfo.ValidTypes.Contains(type)));
}
}
}

View File

@@ -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);
}

View File

@@ -82,7 +82,7 @@ TRUK.Hijackable:
ExternalCapturable:
Type: MissionObjective
CaptureCompleteTime: 1
-SupplyTruck:
-DeliversCash:
RenderSprites:
Image: TRUK
Palette: truk-soviets

View File

@@ -102,7 +102,7 @@ APC:
TRUK:
-SpawnActorOnDeath:
-SupplyTruck:
-DeliversCash:
Buildable:
Prerequisites: ~disabled

View File

@@ -102,7 +102,7 @@ APC:
TRUK:
-SpawnActorOnDeath:
-SupplyTruck:
-DeliversCash:
Buildable:
Prerequisites: ~disabled

View File

@@ -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:

View File

@@ -403,7 +403,7 @@ PDOX:
DisplayRadarPing: True
Range: 2
SupportPowerChargeBar:
-AcceptsSupplies:
-AcceptsDeliveredCash:
Power:
Amount: -200
MustBeDestroyed:

View File

@@ -476,7 +476,7 @@ TRUK:
Speed: 128
RevealsShroud:
Range: 4c0
SupplyTruck:
DeliversCash:
Payload: 500
PlayerExperience: 50
SpawnActorOnDeath:

View File

@@ -1309,7 +1309,6 @@ GAICBM:
Inherits: ^Building
Valued:
Cost: 800
-AcceptsSupplies:
Tooltip:
Name: Deployed ICBM
-GivesBuildableArea:

View File

@@ -152,7 +152,6 @@
Type: Footprint
EngineerRepairable:
ShakeOnDeath:
AcceptsSupplies:
Guardable:
Range: 3c0
Demolishable: