reuse CenterOfCell

This commit is contained in:
Chris Forbes
2009-12-08 20:21:24 +13:00
parent 4528ee4910
commit 073cdc202d
5 changed files with 22 additions and 22 deletions

View File

@@ -70,7 +70,7 @@ namespace OpenRa.Game
BuildingInfluence = new BuildingInfluenceMap();
UnitInfluence = new UnitInfluenceMap();
foreach (TreeReference treeReference in Rules.Map.Trees)
foreach (var treeReference in Rules.Map.Trees)
world.Add(new Actor(Rules.UnitInfo[treeReference.Image],
new int2(treeReference.Location),
null));
@@ -104,7 +104,7 @@ namespace OpenRa.Game
foreach (var s in toLoad)
{
//num=owner,type,health,location,facing,action,trigger
//num=owner,type,health,location,facing,...
var parts = s.Value.Split( ',' );
var loc = int.Parse(parts[3]);
world.Add(new Actor(Rules.UnitInfo[parts[1].ToLowerInvariant()], new int2(loc % 128, loc / 128),

View File

@@ -93,8 +93,8 @@ namespace OpenRa.Game.Traits.Activities
{
mobile.toCell = nextCell.Value;
move = new MoveFirstHalf(
CenterOfCell( mobile.fromCell ),
BetweenCells( mobile.fromCell, mobile.toCell ),
Util.CenterOfCell( mobile.fromCell ),
Util.BetweenCells( mobile.fromCell, mobile.toCell ),
unit.Facing,
unit.Facing,
0 );
@@ -142,16 +142,6 @@ namespace OpenRa.Game.Traits.Activities
return nextCell;
}
static float2 CenterOfCell( int2 loc )
{
return new float2( 12, 12 ) + Game.CellSize * (float2)loc;
}
static float2 BetweenCells( int2 from, int2 to )
{
return 0.5f * ( CenterOfCell( from ) + CenterOfCell( to ) );
}
public void Cancel( Actor self )
{
path = new List<int2>();
@@ -222,8 +212,8 @@ namespace OpenRa.Game.Traits.Activities
if( ( nextCell - mobile.toCell ) != ( mobile.toCell - mobile.fromCell ) )
{
var ret = new MoveFirstHalf(
BetweenCells( mobile.fromCell, mobile.toCell ),
BetweenCells( mobile.toCell, nextCell.Value ),
Util.BetweenCells( mobile.fromCell, mobile.toCell ),
Util.BetweenCells( mobile.toCell, nextCell.Value ),
unit.Facing,
Util.GetNearestFacing( unit.Facing, Util.GetFacing( nextCell.Value - mobile.toCell, unit.Facing ) ),
moveFraction - moveFractionTotal );
@@ -236,8 +226,8 @@ namespace OpenRa.Game.Traits.Activities
parent.path.Add( nextCell.Value );
}
var ret2 = new MoveSecondHalf(
BetweenCells( mobile.fromCell, mobile.toCell ),
CenterOfCell( mobile.toCell ),
Util.BetweenCells( mobile.fromCell, mobile.toCell ),
Util.CenterOfCell( mobile.toCell ),
unit.Facing,
unit.Facing,
moveFraction - moveFractionTotal );
@@ -256,7 +246,7 @@ namespace OpenRa.Game.Traits.Activities
protected override MovePart OnComplete( Actor self, Mobile mobile, Move parent )
{
self.CenterLocation = CenterOfCell( mobile.toCell );
self.CenterLocation = Util.CenterOfCell( mobile.toCell );
mobile.fromCell = mobile.toCell;
return null;
}

View File

@@ -44,7 +44,7 @@ namespace OpenRa.Game.Traits
if (self.Location != targetLocation)
{
var dist = Game.CellSize * (targetLocation + new float2(.5f,.5f)) - self.CenterLocation;
var dist = Util.CenterOfCell(targetLocation) - self.CenterLocation;
var desiredFacing = Util.GetFacing(dist, unit.Facing);
Util.TickFacing(ref unit.Facing, desiredFacing,
self.Info.ROT);

View File

@@ -20,8 +20,8 @@ namespace OpenRa.Game.Traits
{
var uog = Game.controller.orderGenerator as UnitOrderGenerator;
if (uog != null && self.Owner == Game.LocalPlayer && uog.selection.Contains(self))
yield return Util.Centered( self,
anim.Image, Game.CellSize * (new float2(.5f, .5f) + rallyPoint.ToFloat2()));
yield return Util.Centered(self,
anim.Image, Util.CenterOfCell(rallyPoint));
}
public Order IssueOrder(Actor self, int2 xy, bool lmb, Actor underCursor)

View File

@@ -90,6 +90,16 @@ namespace OpenRa.Game.Traits
return RotateVectorByFacing(new float2(0, recoil * self.Info.Recoil), quantizedFacing, .7f);
}
public static float2 CenterOfCell(int2 loc)
{
return new float2(12, 12) + Game.CellSize * (float2)loc;
}
public static float2 BetweenCells(int2 from, int2 to)
{
return 0.5f * (CenterOfCell(from) + CenterOfCell(to));
}
public static float2 GetTurretPosition(Actor self, Unit unit, int[] offset, float recoil)
{
if( unit == null ) return int2.Zero; /* things that don't have a rotating base don't need the turrets repositioned */