Fixed bug where unit would occasionally "disappear" or face in an odd direction.

This commit is contained in:
Bob
2009-10-24 20:48:36 +13:00
parent f6ae86bb53
commit 5086f6ab51
4 changed files with 47 additions and 48 deletions

View File

@@ -26,7 +26,7 @@ namespace OpenRa.Game.GameRules
return float.Parse(x.Replace("%","")) * (x.Contains( '%' ) ? 0.01f : 1f); return float.Parse(x.Replace("%","")) * (x.Contains( '%' ) ? 0.01f : 1f);
else if (fieldType == typeof(string)) else if (fieldType == typeof(string))
return x;//.ToLowerInvariant(); return x;
else if (fieldType.IsEnum) else if (fieldType.IsEnum)
return Enum.Parse(fieldType, x); return Enum.Parse(fieldType, x);

View File

@@ -59,14 +59,14 @@ namespace OpenRa.Game
} }
public void Build(SidebarItem item) public void Build(SidebarItem item)
{ {
if (item != null) if (item != null)
{ {
if (item.techTreeItem.IsStructure) if (item.techTreeItem.IsStructure)
Game.controller.orderGenerator = new PlaceBuilding(Game.LocalPlayer, Game.controller.orderGenerator = new PlaceBuilding(Game.LocalPlayer,
item.techTreeItem.tag.ToLowerInvariant()); item.techTreeItem.tag.ToLowerInvariant());
else else
Game.BuildUnit(Game.LocalPlayer, item.techTreeItem.tag.ToLowerInvariant()); Game.BuildUnit(Game.LocalPlayer, item.techTreeItem.tag.ToLowerInvariant());
} }
} }

View File

@@ -22,21 +22,21 @@ namespace OpenRa.Game.Traits
{ {
this.self = self; this.self = self;
fromCell = toCell; fromCell = toCell;
} }
public void QueueAction( CurrentAction nextAction ) public void QueueAction( CurrentAction nextAction )
{ {
if( currentAction == null ) if( currentAction == null )
{ {
currentAction = nextAction; currentAction = nextAction;
return; return;
} }
var act = currentAction; var act = currentAction;
while( act.NextAction != null ) while( act.NextAction != null )
{ {
act = act.NextAction; act = act.NextAction;
} }
act.NextAction = nextAction; act.NextAction = nextAction;
} }
public void Tick(Actor self) public void Tick(Actor self)
@@ -48,25 +48,25 @@ namespace OpenRa.Game.Traits
} }
public Order Order(Actor self, int2 xy, bool lmb) public Order Order(Actor self, int2 xy, bool lmb)
{ {
if( lmb ) return null; if( lmb ) return null;
if (xy != toCell) if (xy != toCell)
return new MoveOrder(self, xy); return new MoveOrder(self, xy);
return null; return null;
} }
public void Cancel(Actor self) public void Cancel(Actor self)
{ {
if (currentAction != null) if (currentAction != null)
currentAction.Cancel(self, this); currentAction.Cancel(self, this);
} }
public interface CurrentAction public interface CurrentAction
{ {
CurrentAction NextAction { get; set; } CurrentAction NextAction { get; set; }
void Tick( Actor self, Mobile mobile ); void Tick( Actor self, Mobile mobile );
void Cancel( Actor self, Mobile mobile ); void Cancel( Actor self, Mobile mobile );
} }
@@ -91,12 +91,12 @@ namespace OpenRa.Game.Traits
return; return;
} }
Util.TickFacing( ref mobile.facing, desiredFacing, self.unitInfo.ROT ); Util.TickFacing( ref mobile.facing, desiredFacing, self.unitInfo.ROT );
} }
public void Cancel( Actor self, Mobile mobile ) public void Cancel( Actor self, Mobile mobile )
{ {
desiredFacing = mobile.facing; desiredFacing = mobile.facing;
NextAction = null; NextAction = null;
} }
} }
@@ -168,7 +168,6 @@ namespace OpenRa.Game.Traits
{ {
moveFraction -= moveFractionTotal; moveFraction -= moveFractionTotal;
OnComplete( self, mobile ); OnComplete( self, mobile );
//mobile.fromCell = mobile.toCell;
} }
return; return;
} }
@@ -177,7 +176,7 @@ namespace OpenRa.Game.Traits
{ {
self.CenterLocation = float2.Lerp( from, to, frac ); self.CenterLocation = float2.Lerp( from, to, frac );
if( moveFraction >= moveFractionTotal ) if( moveFraction >= moveFractionTotal )
mobile.facing = toFacing; mobile.facing = toFacing & 0xFF;
else else
mobile.facing = ( fromFacing + ( toFacing - fromFacing ) * moveFraction / moveFractionTotal ) & 0xFF; mobile.facing = ( fromFacing + ( toFacing - fromFacing ) * moveFraction / moveFractionTotal ) & 0xFF;
} }
@@ -231,12 +230,12 @@ namespace OpenRa.Game.Traits
self.CenterLocation = CenterOfCell( mobile.toCell ); self.CenterLocation = CenterOfCell( mobile.toCell );
OnComplete = null; OnComplete = null;
mobile.fromCell = mobile.toCell; mobile.fromCell = mobile.toCell;
} }
public void Cancel( Actor self, Mobile mobile ) public void Cancel( Actor self, Mobile mobile )
{ {
path.Clear(); path.Clear();
NextAction = null; NextAction = null;
} }
} }
} }

View File

@@ -12,7 +12,7 @@ namespace OpenRa.Game.Traits
var leftTurn = ( facing - desiredFacing ) & 0xFF; var leftTurn = ( facing - desiredFacing ) & 0xFF;
var rightTurn = ( desiredFacing - facing ) & 0xFF; var rightTurn = ( desiredFacing - facing ) & 0xFF;
if( Math.Min( leftTurn, rightTurn ) < rot ) if( Math.Min( leftTurn, rightTurn ) < rot )
facing = desiredFacing; facing = desiredFacing & 0xFF;
else if( rightTurn < leftTurn ) else if( rightTurn < leftTurn )
facing = ( facing + rot ) & 0xFF; facing = ( facing + rot ) & 0xFF;
else else