diff --git a/OpenRA.Game/Traits/Health.cs b/OpenRA.Game/Traits/Health.cs index e2df65ef12..8c3b5d5c75 100644 --- a/OpenRA.Game/Traits/Health.cs +++ b/OpenRA.Game/Traits/Health.cs @@ -131,15 +131,6 @@ namespace OpenRA.Traits Warhead = warhead }); } - - public void TransferHPFromActor(Actor self, Actor from, bool transferPercentage) - { - var fromHealth = from.traits.GetOrDefault(); - if (fromHealth == null) - return; - - hp = (transferPercentage) ? (int)(fromHealth.HPFraction*MaxHP) : Math.Min(fromHealth.HP, MaxHP); - } } public static class HealthExts diff --git a/OpenRA.Mods.RA/Activities/TransformIntoActor.cs b/OpenRA.Mods.RA/Activities/TransformIntoActor.cs index 3765421ee5..555d24e4e3 100644 --- a/OpenRA.Mods.RA/Activities/TransformIntoActor.cs +++ b/OpenRA.Mods.RA/Activities/TransformIntoActor.cs @@ -19,17 +19,14 @@ namespace OpenRA.Mods.RA.Activities { string actor = null; int2 offset; - string[] sounds = null; - bool transferPercentage; - + string[] sounds = null; bool isCanceled; - public TransformIntoActor(string actor, int2 offset, bool transferHealthPercentage, string[] sounds) + public TransformIntoActor(string actor, int2 offset, string[] sounds) { this.actor = actor; this.offset = offset; this.sounds = sounds; - this.transferPercentage = transferHealthPercentage; } public IActivity NextActivity { get; set; } @@ -47,11 +44,10 @@ namespace OpenRA.Mods.RA.Activities Sound.PlayToPlayer(self.Owner, s, self.CenterLocation); var a = w.CreateActor(actor, self.Location + offset, self.Owner); - var health = a.traits.GetOrDefault(); - if (health != null) - { - health.TransferHPFromActor(a, self, transferPercentage); - } + var oldHealth = self.traits.GetOrDefault(); + var newHealth = a.traits.GetOrDefault(); + if (oldHealth != null && newHealth != null) + newHealth.HPFraction = oldHealth.HPFraction; if (selected) w.Selection.Add(w, a); diff --git a/OpenRA.Mods.RA/Activities/UndeployMcv.cs b/OpenRA.Mods.RA/Activities/UndeployMcv.cs index 66e6875435..f508aa81b9 100755 --- a/OpenRA.Mods.RA/Activities/UndeployMcv.cs +++ b/OpenRA.Mods.RA/Activities/UndeployMcv.cs @@ -25,11 +25,10 @@ namespace OpenRA.Mods.RA.Activities var mcv = w.CreateActor("mcv", self.Location + new int2(1, 1), self.Owner); - var health = mcv.traits.GetOrDefault(); - if (health != null) - { - health.TransferHPFromActor(mcv, self, true); - } + var oldHealth = self.traits.GetOrDefault(); + var newHealth = mcv.traits.GetOrDefault(); + if (oldHealth != null && newHealth != null) + newHealth.HPFraction = oldHealth.HPFraction; mcv.traits.Get().Facing = 96; diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 91d63d20fb..40360f7428 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -1,4 +1,4 @@ - + Debug @@ -218,7 +218,6 @@ - @@ -233,6 +232,7 @@ + diff --git a/OpenRA.Mods.RA/Transforms.cs b/OpenRA.Mods.RA/Transforms.cs new file mode 100644 index 0000000000..f9be3d9418 --- /dev/null +++ b/OpenRA.Mods.RA/Transforms.cs @@ -0,0 +1,86 @@ +#region Copyright & License Information +/* + * Copyright 2007-2010 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. For more information, + * see LICENSE. + */ +#endregion + +using OpenRA.Mods.RA.Activities; +using OpenRA.Traits; +using OpenRA.Traits.Activities; +using OpenRA.GameRules; + +namespace OpenRA.Mods.RA +{ + class TransformsInfo : ITraitInfo + { + [ActorReference] + public readonly string IntoActor; + public readonly int2 Offset = int2.Zero; + public readonly int Facing = 96; + public readonly string[] TransformSounds = {}; + public readonly string[] NoTransformSounds = {}; + + public virtual object Create(ActorInitializer init) { return new Transforms(this); } + } + + class Transforms : IIssueOrder, IResolveOrder, IOrderCursor, IOrderVoice + { + TransformsInfo Info; + BuildingInfo bi; + + public Transforms(TransformsInfo info) + { + Info = info; + bi = Rules.Info[info.IntoActor].Traits.GetOrDefault(); + } + + public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor) + { + if (mi.Button == MouseButton.Right && self == underCursor) + return new Order("DeployTransform", self); + + return null; + } + + public string VoicePhraseForOrder(Actor self, Order order) + { + return (order.OrderString == "DeployTransform") ? "Move" : null; + } + + bool CanDeploy(Actor self) + { + return (bi == null || self.World.CanPlaceBuilding(Info.IntoActor, bi, self.Location + Info.Offset, self)); + } + + public void ResolveOrder( Actor self, Order order ) + { + if (order.OrderString == "DeployTransform") + { + if (!CanDeploy(self)) + { + foreach (var s in Info.NoTransformSounds) + Sound.PlayToPlayer(self.Owner, s); + return; + } + self.CancelActivity(); + + if (self.traits.Contains()) + self.QueueActivity(new Turn(Info.Facing)); + + self.QueueActivity(new TransformIntoActor(Info.IntoActor, Info.Offset, Info.TransformSounds)); + } + } + + public string CursorForOrder(Actor self, Order order) + { + if (order.OrderString != "DeployTransform") + return null; + + return CanDeploy(self) ? "deploy" : "deploy-blocked"; + } + } +} diff --git a/OpenRA.Mods.RA/TransformsOnDeploy.cs b/OpenRA.Mods.RA/TransformsOnDeploy.cs deleted file mode 100644 index 250c2fbe31..0000000000 --- a/OpenRA.Mods.RA/TransformsOnDeploy.cs +++ /dev/null @@ -1,94 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2010 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. For more information, - * see LICENSE. - */ -#endregion - -using OpenRA.Mods.RA.Activities; -using OpenRA.Traits; -using OpenRA.Traits.Activities; - -namespace OpenRA.Mods.RA -{ - class TransformsOnDeployInfo : TraitInfo - { - [ActorReference] - public readonly string TransformsInto = null; - public readonly int[] Offset = null; - public readonly int[] DeployDirections = new int[] {96}; - public readonly bool TransferHealthPercentage = true; // Set to false to transfer the absolute health - public readonly string[] TransformSounds = null; - public readonly string[] NoTransformSounds = null; - } - - class TransformsOnDeploy : IIssueOrder, IResolveOrder, IOrderCursor, IOrderVoice - { - public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor) - { - if (mi.Button == MouseButton.Right && self == underCursor) - return new Order("DeployTransform", self); - - return null; - } - - public string VoicePhraseForOrder(Actor self, Order order) - { - return (order.OrderString == "DeployTransform") ? "Move" : null; - } - - public void ResolveOrder( Actor self, Order order ) - { - if (order.OrderString == "DeployTransform") - { - var info = self.Info.Traits.Get(); - - var transInfo = Rules.Info[info.TransformsInto]; - - if (transInfo.Traits.Contains()) - { - var bi = transInfo.Traits.Get(); - if (!self.World.CanPlaceBuilding(info.TransformsInto, bi, self.Location + new int2(info.Offset[0], info.Offset[1]), self)) - { - foreach (var s in info.NoTransformSounds) - Sound.PlayToPlayer(self.Owner, s); - - return; - } - - } - self.CancelActivity(); - - - if (self.traits.Contains()) // Pick the closest deploy direction to turn to - { - // TODO: Pick the closest deploy direction - var bestDir = info.DeployDirections[0]; - - self.QueueActivity(new Turn(bestDir)); - } - - self.QueueActivity(new TransformIntoActor(info.TransformsInto, new int2(info.Offset[0], info.Offset[1]), info.TransferHealthPercentage, info.TransformSounds)); - } - } - - public string CursorForOrder(Actor self, Order order) - { - if (order.OrderString != "DeployTransform") - return null; - - var depInfo = self.Info.Traits.Get(); - var transInfo = Rules.Info[depInfo.TransformsInto]; - if (transInfo.Traits.Contains()) - { - var bi = transInfo.Traits.Get(); - if (!self.World.CanPlaceBuilding(depInfo.TransformsInto, bi, self.Location + new int2(depInfo.Offset[0], depInfo.Offset[1]), self)) - return "deploy-blocked"; - } - return "deploy"; - } - } -} diff --git a/mods/cnc/vehicles.yaml b/mods/cnc/vehicles.yaml index 0a8ff571ca..2afffb6285 100644 --- a/mods/cnc/vehicles.yaml +++ b/mods/cnc/vehicles.yaml @@ -17,10 +17,10 @@ MCV: Armor: light RevealsShroud: Range: 4 - TransformsOnDeploy: - TransformsInto: fact + Transforms: + IntoActor: fact Offset:-1,-1 - DeployDirections: 96 + Facing: 96 TransformSounds: constru2.aud, hvydoor1.aud NoTransformSounds: deploy1.aud RenderUnit: diff --git a/mods/ra/vehicles.yaml b/mods/ra/vehicles.yaml index 27390dcd17..2a1d65fad7 100644 --- a/mods/ra/vehicles.yaml +++ b/mods/ra/vehicles.yaml @@ -249,10 +249,10 @@ MCV: Speed: 6 RevealsShroud: Range: 4 - TransformsOnDeploy: - TransformsInto: fact + Transforms: + IntoActor: fact Offset:-1,-1 - DeployDirections: 96 + Facing: 96 TransformSounds: placbldg.aud, build5.aud NoTransformSounds: nodeply1.aud RenderUnit: