From 5086f6ab514d6801c3e767b6a3e0cf157c1f6099 Mon Sep 17 00:00:00 2001 From: Bob Date: Sat, 24 Oct 2009 20:48:36 +1300 Subject: [PATCH] Fixed bug where unit would occasionally "disappear" or face in an odd direction. --- OpenRa.Game/GameRules/FieldLoader.cs | 2 +- OpenRa.Game/Sidebar.cs | 16 +++--- OpenRa.Game/Traits/Mobile.cs | 75 ++++++++++++++-------------- OpenRa.Game/Traits/Util.cs | 2 +- 4 files changed, 47 insertions(+), 48 deletions(-) diff --git a/OpenRa.Game/GameRules/FieldLoader.cs b/OpenRa.Game/GameRules/FieldLoader.cs index 7529abe387..f187edf9c7 100755 --- a/OpenRa.Game/GameRules/FieldLoader.cs +++ b/OpenRa.Game/GameRules/FieldLoader.cs @@ -26,7 +26,7 @@ namespace OpenRa.Game.GameRules return float.Parse(x.Replace("%","")) * (x.Contains( '%' ) ? 0.01f : 1f); else if (fieldType == typeof(string)) - return x;//.ToLowerInvariant(); + return x; else if (fieldType.IsEnum) return Enum.Parse(fieldType, x); diff --git a/OpenRa.Game/Sidebar.cs b/OpenRa.Game/Sidebar.cs index 0d10a1c508..82b04a64d3 100644 --- a/OpenRa.Game/Sidebar.cs +++ b/OpenRa.Game/Sidebar.cs @@ -59,14 +59,14 @@ namespace OpenRa.Game } public void Build(SidebarItem item) - { - if (item != null) - { - if (item.techTreeItem.IsStructure) - Game.controller.orderGenerator = new PlaceBuilding(Game.LocalPlayer, - item.techTreeItem.tag.ToLowerInvariant()); - else - Game.BuildUnit(Game.LocalPlayer, item.techTreeItem.tag.ToLowerInvariant()); + { + if (item != null) + { + if (item.techTreeItem.IsStructure) + Game.controller.orderGenerator = new PlaceBuilding(Game.LocalPlayer, + item.techTreeItem.tag.ToLowerInvariant()); + else + Game.BuildUnit(Game.LocalPlayer, item.techTreeItem.tag.ToLowerInvariant()); } } diff --git a/OpenRa.Game/Traits/Mobile.cs b/OpenRa.Game/Traits/Mobile.cs index dd431470c9..fc550e57f9 100644 --- a/OpenRa.Game/Traits/Mobile.cs +++ b/OpenRa.Game/Traits/Mobile.cs @@ -22,21 +22,21 @@ namespace OpenRa.Game.Traits { this.self = self; fromCell = toCell; - } - - public void QueueAction( CurrentAction nextAction ) - { - if( currentAction == null ) - { - currentAction = nextAction; - return; - } - var act = currentAction; - while( act.NextAction != null ) - { - act = act.NextAction; - } - act.NextAction = nextAction; + } + + public void QueueAction( CurrentAction nextAction ) + { + if( currentAction == null ) + { + currentAction = nextAction; + return; + } + var act = currentAction; + while( act.NextAction != null ) + { + act = act.NextAction; + } + act.NextAction = nextAction; } public void Tick(Actor self) @@ -48,25 +48,25 @@ namespace OpenRa.Game.Traits } public Order Order(Actor self, int2 xy, bool lmb) - { + { if( lmb ) return null; if (xy != toCell) return new MoveOrder(self, xy); return null; - } - - public void Cancel(Actor self) - { - if (currentAction != null) - currentAction.Cancel(self, this); + } + + public void Cancel(Actor self) + { + if (currentAction != null) + currentAction.Cancel(self, this); } public interface CurrentAction - { + { CurrentAction NextAction { get; set; } - void Tick( Actor self, Mobile mobile ); + void Tick( Actor self, Mobile mobile ); void Cancel( Actor self, Mobile mobile ); } @@ -91,12 +91,12 @@ namespace OpenRa.Game.Traits return; } Util.TickFacing( ref mobile.facing, desiredFacing, self.unitInfo.ROT ); - } - - public void Cancel( Actor self, Mobile mobile ) - { - desiredFacing = mobile.facing; - NextAction = null; + } + + public void Cancel( Actor self, Mobile mobile ) + { + desiredFacing = mobile.facing; + NextAction = null; } } @@ -168,7 +168,6 @@ namespace OpenRa.Game.Traits { moveFraction -= moveFractionTotal; OnComplete( self, mobile ); - //mobile.fromCell = mobile.toCell; } return; } @@ -177,7 +176,7 @@ namespace OpenRa.Game.Traits { self.CenterLocation = float2.Lerp( from, to, frac ); if( moveFraction >= moveFractionTotal ) - mobile.facing = toFacing; + mobile.facing = toFacing & 0xFF; else mobile.facing = ( fromFacing + ( toFacing - fromFacing ) * moveFraction / moveFractionTotal ) & 0xFF; } @@ -231,12 +230,12 @@ namespace OpenRa.Game.Traits self.CenterLocation = CenterOfCell( mobile.toCell ); OnComplete = null; mobile.fromCell = mobile.toCell; - } - - public void Cancel( Actor self, Mobile mobile ) - { - path.Clear(); - NextAction = null; + } + + public void Cancel( Actor self, Mobile mobile ) + { + path.Clear(); + NextAction = null; } } } diff --git a/OpenRa.Game/Traits/Util.cs b/OpenRa.Game/Traits/Util.cs index 40303f559b..32e1c5a843 100755 --- a/OpenRa.Game/Traits/Util.cs +++ b/OpenRa.Game/Traits/Util.cs @@ -12,7 +12,7 @@ namespace OpenRa.Game.Traits var leftTurn = ( facing - desiredFacing ) & 0xFF; var rightTurn = ( desiredFacing - facing ) & 0xFF; if( Math.Min( leftTurn, rightTurn ) < rot ) - facing = desiredFacing; + facing = desiredFacing & 0xFF; else if( rightTurn < leftTurn ) facing = ( facing + rot ) & 0xFF; else