removing a bunch of excessively low-level pixel -> cell conversions
This commit is contained in:
@@ -43,7 +43,7 @@ namespace OpenRA
|
||||
public static void DoImpact(WarheadInfo warhead, ProjectileArgs args)
|
||||
{
|
||||
var world = args.firedBy.World;
|
||||
var targetTile = ((1f / Game.CellSize) * args.dest.ToFloat2()).ToInt2();
|
||||
var targetTile = Util.CellContaining(args.dest);
|
||||
|
||||
if (!world.Map.IsInMap(targetTile))
|
||||
return;
|
||||
|
||||
@@ -98,7 +98,7 @@ namespace OpenRA.Effects
|
||||
{
|
||||
var at = (float)t / TotalTime();
|
||||
var pos = float2.Lerp(Args.src, Args.dest, at);
|
||||
var cell = ((1f/Game.CellSize) * pos).ToInt2();
|
||||
var cell = Traits.Util.CellContaining(pos);
|
||||
|
||||
if (world.WorldActor.traits.Get<UnitInfluence>().GetUnitsAt(cell).Any(
|
||||
a => a.traits.Contains<IBlocksBullets>()))
|
||||
|
||||
@@ -113,7 +113,7 @@ namespace OpenRA.Effects
|
||||
|
||||
if (!Info.High) // check for hitting a wall
|
||||
{
|
||||
var cell = ((1f / Game.CellSize) * Pos).ToInt2();
|
||||
var cell = Traits.Util.CellContaining(Pos);
|
||||
|
||||
if (world.WorldActor.traits.Get<UnitInfluence>().GetUnitsAt(cell).Any(
|
||||
a => a.traits.Contains<IBlocksBullets>()))
|
||||
|
||||
@@ -137,7 +137,7 @@ namespace OpenRA.Traits
|
||||
var move = self.GetCurrentActivity() as Activities.Move;
|
||||
if (move == null || move.path == null) return new float2[] { };
|
||||
|
||||
return Enumerable.Reverse(move.path).Select( c => Game.CellSize * c + new float2(12,12) );
|
||||
return Enumerable.Reverse(move.path).Select( c => Util.CenterOfCell(c) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,19 +36,19 @@ namespace OpenRA.Traits
|
||||
{
|
||||
public virtual int2? CreationLocation( Actor self, ActorInfo producee )
|
||||
{
|
||||
var pos = (1 / 24f * self.CenterLocation).ToInt2();
|
||||
var pos = Util.CellContaining(self.CenterLocation);
|
||||
var pi = self.Info.Traits.Get<ProductionInfo>();
|
||||
if (pi.ProductionOffset != null)
|
||||
pos += new int2(pi.ProductionOffset[0], pi.ProductionOffset[1]);
|
||||
pos += pi.ProductionOffset.AsInt2();
|
||||
return pos;
|
||||
}
|
||||
|
||||
public virtual int2? ExitLocation(Actor self, ActorInfo producee)
|
||||
{
|
||||
var pos = (1 / 24f * self.CenterLocation).ToInt2();
|
||||
var pos = Util.CellContaining(self.CenterLocation);
|
||||
var pi = self.Info.Traits.Get<ProductionInfo>();
|
||||
if (pi.ExitOffset != null)
|
||||
pos += new int2(pi.ExitOffset[0], pi.ExitOffset[1]);
|
||||
pos += pi.ExitOffset.AsInt2();
|
||||
return pos;
|
||||
}
|
||||
|
||||
@@ -68,23 +68,21 @@ namespace OpenRA.Traits
|
||||
|
||||
var pi = self.Info.Traits.Get<ProductionInfo>();
|
||||
var rp = self.traits.GetOrDefault<RallyPoint>();
|
||||
if( rp != null || pi.ExitOffset != null)
|
||||
if (rp != null || pi.ExitOffset != null)
|
||||
{
|
||||
var mobile = newUnit.traits.GetOrDefault<Mobile>();
|
||||
if( mobile != null )
|
||||
if (mobile != null)
|
||||
{
|
||||
if (pi.ExitOffset != null)
|
||||
newUnit.QueueActivity(new Activities.Move(ExitLocation( self, producee).Value, 1));
|
||||
|
||||
newUnit.QueueActivity(new Activities.Move(ExitLocation(self, producee).Value, 1));
|
||||
|
||||
if (rp != null)
|
||||
newUnit.QueueActivity( new Activities.Move( rp.rallyPoint, 1 ) );
|
||||
newUnit.QueueActivity(new Activities.Move(rp.rallyPoint, 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (pi != null && pi.SpawnOffset != null)
|
||||
newUnit.CenterLocation = self.CenterLocation
|
||||
+ new float2(pi.SpawnOffset[0], pi.SpawnOffset[1]);
|
||||
newUnit.CenterLocation = self.CenterLocation + pi.SpawnOffset.AsInt2();
|
||||
|
||||
foreach (var t in self.traits.WithInterface<INotifyProduction>())
|
||||
t.UnitProduced(self, newUnit);
|
||||
|
||||
@@ -127,6 +127,7 @@ namespace OpenRA.Traits
|
||||
+ offset.AbsOffset();
|
||||
}
|
||||
|
||||
public static int2 AsInt2(this int[] xs) { return new int2(xs[0], xs[1]); }
|
||||
public static float2 RelOffset(this int[] offset) { return new float2(offset[0], offset[1]); }
|
||||
public static float2 AbsOffset(this int[] offset) { return new float2(offset.ElementAtOrDefault(2), offset.ElementAtOrDefault(3)); }
|
||||
|
||||
@@ -171,5 +172,7 @@ namespace OpenRA.Traits
|
||||
}
|
||||
|
||||
public static Color ArrayToColor(int[] x) { return Color.FromArgb(x[0], x[1], x[2]); }
|
||||
|
||||
public static int2 CellContaining(float2 pos) { return (1 / 24f * pos).ToInt2(); }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user