From bd2a2cefbb7b8170f3877b6fecb4041b80b4d941 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Thu, 17 Dec 2009 09:44:22 +1300 Subject: [PATCH] moving altitude onto Unit --- OpenRa.Game/Traits/Helicopter.cs | 11 +++++------ OpenRa.Game/Traits/RenderUnitRotor.cs | 8 +++----- OpenRa.Game/Traits/Unit.cs | 1 + 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/OpenRa.Game/Traits/Helicopter.cs b/OpenRa.Game/Traits/Helicopter.cs index f1438fb148..67354418c0 100644 --- a/OpenRa.Game/Traits/Helicopter.cs +++ b/OpenRa.Game/Traits/Helicopter.cs @@ -6,7 +6,6 @@ namespace OpenRa.Game.Traits { class Helicopter : ITick, IOrder { - public int altitude; public int2 targetLocation; const int CruiseAltitude = 20; @@ -54,7 +53,7 @@ namespace OpenRa.Game.Traits var angle = (unit.Facing - desiredFacing) / 128f * Math.PI; var scale = .4f + .6f * (float)Math.Cos(angle); - if (altitude > CruiseAltitude / 2) // do some movement. + if (unit.Altitude > CruiseAltitude / 2) // do some movement. { self.CenterLocation += (rawSpeed * scale / dist.Length) * dist; self.CenterLocation += (1f - scale) * rawSpeed @@ -62,16 +61,16 @@ namespace OpenRa.Game.Traits self.Location = ((1 / 24f) * self.CenterLocation).ToInt2(); } - if (altitude < CruiseAltitude) + if (unit.Altitude < CruiseAltitude) { - ++altitude; + ++unit.Altitude; return; } } - else if (altitude > 0 && + else if (unit.Altitude > 0 && Game.IsCellBuildable( self.Location, UnitMovementType.Foot )) { - --altitude; + --unit.Altitude; } /* todo: bob slightly when hovering */ diff --git a/OpenRa.Game/Traits/RenderUnitRotor.cs b/OpenRa.Game/Traits/RenderUnitRotor.cs index 673716127c..dee1f255c7 100755 --- a/OpenRa.Game/Traits/RenderUnitRotor.cs +++ b/OpenRa.Game/Traits/RenderUnitRotor.cs @@ -31,8 +31,7 @@ namespace OpenRa.Game.Traits yield return Util.CenteredShadow(self, (secondRotorAnim ?? rotorAnim).Image, self.CenterLocation + Util.GetTurretPosition(self, unit, self.Info.SecondaryOffset, 0)); - var heli = self.traits.Get(); - var p = self.CenterLocation - new float2( 0, heli.altitude ); + var p = self.CenterLocation - new float2( 0, unit.Altitude ); yield return Util.Centered(self, anim.Image, p); yield return Util.Centered(self, rotorAnim.Image, p @@ -49,10 +48,9 @@ namespace OpenRa.Game.Traits if (secondRotorAnim != null) secondRotorAnim.Tick(); - var heli = self.traits.GetOrDefault(); - if (heli == null) return; + var unit = self.traits.Get(); - var isFlying = heli.altitude > 0; + var isFlying = unit.Altitude > 0; if (isFlying ^ (rotorAnim.CurrentSequence.Name != "rotor")) return; diff --git a/OpenRa.Game/Traits/Unit.cs b/OpenRa.Game/Traits/Unit.cs index 6c8a2013ae..53d1cff06b 100755 --- a/OpenRa.Game/Traits/Unit.cs +++ b/OpenRa.Game/Traits/Unit.cs @@ -4,6 +4,7 @@ namespace OpenRa.Game.Traits class Unit { public int Facing; + public int Altitude; public Unit( Actor self ) { } }