New types for cell and pixel coordinate position/vectors.

This commit is contained in:
James Dunne
2012-06-20 23:22:27 -05:00
parent 0b98a8ce5e
commit 9c49143534
162 changed files with 1291 additions and 865 deletions

View File

@@ -72,7 +72,7 @@ namespace OpenRA.Mods.RA.AI
readonly HackyAIInfo Info;
Cache<Player,Enemy> aggro = new Cache<Player, Enemy>( _ => new Enemy() );
int2 baseCenter;
CPos baseCenter;
XRandom random = new XRandom(); //we do not use the synced random number generator.
BaseBuilder[] builders;
@@ -116,7 +116,7 @@ namespace OpenRA.Mods.RA.AI
ActorInfo ChooseRandomUnitToBuild(ProductionQueue queue)
{
var buildableThings = queue.BuildableItems();
if (buildableThings.Count() == 0) return null;
if (!buildableThings.Any()) return null;
return buildableThings.ElementAtOrDefault(random.Next(buildableThings.Count()));
}
@@ -154,13 +154,13 @@ namespace OpenRA.Mods.RA.AI
return null;
}
bool NoBuildingsUnder(IEnumerable<int2> cells)
bool NoBuildingsUnder(IEnumerable<CPos> cells)
{
var bi = world.WorldActor.Trait<BuildingInfluence>();
return cells.All(c => bi.GetBuildingAt(c) == null);
}
public int2? ChooseBuildLocation(string actorType)
public CPos? ChooseBuildLocation(string actorType)
{
var bi = Rules.Info[actorType].Traits.Get<BuildingInfo>();
@@ -200,12 +200,12 @@ namespace OpenRA.Mods.RA.AI
//A bunch of hardcoded lists to keep track of which units are doing what.
List<Actor> unitsHangingAroundTheBase = new List<Actor>();
List<Actor> attackForce = new List<Actor>();
int2? attackTarget;
CPos? attackTarget;
//Units that the ai already knows about. Any unit not on this list needs to be given a role.
List<Actor> activeUnits = new List<Actor>();
int2? ChooseEnemyTarget()
CPos? ChooseEnemyTarget()
{
var liveEnemies = world.Players
.Where(q => p != q && p.Stances[q] == Stance.Enemy)
@@ -219,14 +219,14 @@ namespace OpenRA.Mods.RA.AI
if (leastLikedEnemies == null)
return null;
var enemy = leastLikedEnemies != null ? leastLikedEnemies.Random(random) : null;
var enemy = leastLikedEnemies.Random(random);
/* pick something worth attacking owned by that player */
var targets = world.Actors
.Where(a => a.Owner == enemy && a.HasTrait<IOccupySpace>());
Actor target=null;
Actor target = null;
if (targets.Count()>0)
if (targets.Any())
target = targets.Random(random);
if (target == null)
@@ -346,7 +346,7 @@ namespace OpenRA.Mods.RA.AI
}
}
bool IsRallyPointValid(int2 x)
bool IsRallyPointValid(CPos x)
{
// this is actually WRONG as soon as HackyAI is building units with a variety of
// movement capabilities. (has always been wrong)
@@ -363,16 +363,15 @@ namespace OpenRA.Mods.RA.AI
BotDebug("Bot {0} needs to find rallypoints for {1} buildings.",
p.PlayerName, buildings.Length);
foreach (var a in buildings)
{
int2 newRallyPoint = ChooseRallyLocationNear(a.Actor.Location);
CPos newRallyPoint = ChooseRallyLocationNear(a.Actor.Location);
world.IssueOrder(new Order("SetRallyPoint", a.Actor, false) { TargetLocation = newRallyPoint });
}
}
//won't work for shipyards...
int2 ChooseRallyLocationNear(int2 startPos)
CPos ChooseRallyLocationNear(CPos startPos)
{
var possibleRallyPoints = world.FindTilesInCircle(startPos, 8).Where(IsRallyPointValid).ToArray();
if (possibleRallyPoints.Length == 0)
@@ -384,18 +383,18 @@ namespace OpenRA.Mods.RA.AI
return possibleRallyPoints.Random(random);
}
int2? ChooseDestinationNear(Actor a, int2 desiredMoveTarget)
CPos? ChooseDestinationNear(Actor a, CPos desiredMoveTarget)
{
var move = a.TraitOrDefault<IMove>();
if (move == null) return null;
int2 xy;
CPos xy;
int loopCount = 0; //avoid infinite loops.
int range = 2;
do
{
//loop until we find a valid move location
xy = new int2(desiredMoveTarget.X + random.Next(-range, range), desiredMoveTarget.Y + random.Next(-range, range));
xy = new CPos(desiredMoveTarget.X + random.Next(-range, range), desiredMoveTarget.Y + random.Next(-range, range));
loopCount++;
range = Math.Max(range, loopCount / 2);
if (loopCount > 10) return null;
@@ -406,7 +405,7 @@ namespace OpenRA.Mods.RA.AI
//try very hard to find a valid move destination near the target.
//(Don't accept a move onto the subject's current position. maybe this is already not allowed? )
bool TryToMove(Actor a, int2 desiredMoveTarget, bool attackMove)
bool TryToMove(Actor a, CPos desiredMoveTarget, bool attackMove)
{
var xy = ChooseDestinationNear(a, desiredMoveTarget);
if (xy == null)

View File

@@ -44,7 +44,7 @@ namespace OpenRA.Mods.RA.Activities
public override IEnumerable<Target> GetTargets(Actor self)
{
yield return Target.FromPos(self.Location);
yield return Target.FromCell(self.Location);
}
}

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Mods.RA.Activities
if (IsCanceled) return NextActivity;
if (!Target.IsValid) return NextActivity;
var inRange = ( Util.CellContaining( Target.CenterLocation ) - self.Location ).LengthSquared < Range * Range;
var inRange = ( Target.CenterLocation.ToCPos() - self.Location ).LengthSquared < Range * Range;
if( inRange ) return this;
if (--nextPathTime > 0) return this;

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Mods.RA.Activities
return Util.SequenceActivities(
new MoveAdjacentTo(Target.FromActor(rearmTarget)),
mobile.MoveTo(Traits.Util.CellContaining(rearmTarget.CenterLocation), rearmTarget),
mobile.MoveTo(rearmTarget.CenterLocation.ToCPos(), rearmTarget),
new Rearm(self),
new Repair(rearmTarget),
this );
@@ -65,11 +65,10 @@ namespace OpenRA.Mods.RA.Activities
return new Wait(20); // nothing to do here
}
bool ShouldLayMine(Actor self, int2 p)
bool ShouldLayMine(Actor self, CPos p)
{
// if there is no unit (other than me) here, we want to place a mine here
return !self.World.ActorMap
.GetUnitsAt(p).Any(a => a != self);
return !self.World.ActorMap.GetUnitsAt(p).Any(a => a != self);
}
void LayMine(Actor self)

View File

@@ -18,7 +18,7 @@ namespace OpenRA.Mods.RA.Activities
class Leap : Activity
{
Target target;
int2 initialLocation;
PPos initialLocation;
int moveFraction;
const int delay = 6;
@@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Activities
public Leap(Actor self, Target target)
{
this.target = target;
initialLocation = self.Trait<Mobile>().PxPosition;
initialLocation = (PPos) self.Trait<Mobile>().PxPosition;
self.Trait<RenderInfantry>().Attacking(self, target);
Sound.Play("dogg5p.aud", self.CenterLocation);
@@ -41,12 +41,12 @@ namespace OpenRA.Mods.RA.Activities
var mobile = self.Trait<Mobile>();
++moveFraction;
mobile.PxPosition = int2.Lerp(initialLocation, target.PxPosition, moveFraction, delay);
mobile.PxPosition = PPos.Lerp(initialLocation, target.PxPosition, moveFraction, delay);
if (moveFraction >= delay)
{
self.TraitsImplementing<IMove>().FirstOrDefault()
.SetPosition(self, Util.CellContaining(target.CenterLocation));
.SetPosition(self, target.CenterLocation.ToCPos());
if (target.IsActor)
target.Actor.Kill(self);

View File

@@ -40,7 +40,7 @@ namespace OpenRA.Mods.RA.Activities
ps1.heuristic = PathSearch.DefaultEstimator( mobile.toCell );
var ps2 = PathSearch.FromPoint( self.World, mobile.Info, self.Owner, mobile.toCell, Util.CellContaining(target.CenterLocation), true );
var ps2 = PathSearch.FromPoint( self.World, mobile.Info, self.Owner, mobile.toCell, target.CenterLocation.ToCPos(), true );
var ret = self.World.WorldActor.Trait<PathFinder>().FindBidiPath( ps1, ps2 );
return Util.SequenceActivities( mobile.MoveTo( () => ret ), this );

View File

@@ -15,9 +15,9 @@ namespace OpenRA.Mods.RA.Activities
{
public class Teleport : Activity
{
int2 destination;
CPos destination;
public Teleport(int2 destination)
public Teleport(CPos destination)
{
this.destination = destination;
}

View File

@@ -17,7 +17,7 @@ namespace OpenRA.Mods.RA.Activities
class Transform : Activity
{
public readonly string ToActor = null;
public int2 Offset = new int2(0,0);
public CVec Offset = new CVec(0, 0);
public int Facing = 96;
public string[] Sounds = {};
public int ForceHealthPercentage = 0;

View File

@@ -18,7 +18,7 @@ namespace OpenRA.Mods.RA.Activities
{
public class UnloadCargo : Activity
{
int2? ChooseExitTile(Actor self, Actor cargo)
CPos? ChooseExitTile(Actor self, Actor cargo)
{
// is anyone still hogging this tile?
if (self.World.ActorMap.GetUnitsAt(self.Location).Count() > 1)
@@ -29,8 +29,8 @@ namespace OpenRA.Mods.RA.Activities
for (var i = -1; i < 2; i++)
for (var j = -1; j < 2; j++)
if ((i != 0 || j != 0) &&
mobile.CanEnterCell(self.Location + new int2(i, j)))
return self.Location + new int2(i, j);
mobile.CanEnterCell(self.Location + new CVec(i, j)))
return self.Location + new CVec(i, j);
return null;
}
@@ -70,7 +70,7 @@ namespace OpenRA.Mods.RA.Activities
if (actor.Destroyed) return;
var mobile = actor.Trait<Mobile>();
mobile.Facing = Util.GetFacing( exitPx - currentPx, mobile.Facing );
mobile.Facing = Util.GetFacing( (exitPx - currentPx).ToInt2(), mobile.Facing );
mobile.SetPosition(actor, exitTile.Value);
mobile.AdjustPxPosition(actor, currentPx);
var speed = mobile.MovementSpeedForCell(actor, exitTile.Value);

View File

@@ -108,8 +108,8 @@ namespace OpenRA.Mods.RA.Air
public int Altitude { get; set; }
[Sync]
public int2 SubPxPosition;
public int2 PxPosition { get { return new int2( SubPxPosition.X / 1024, SubPxPosition.Y / 1024 ); } }
public int2 TopLeft { get { return Util.CellContaining( PxPosition ); } }
public PPos PxPosition { get { return new PPos( SubPxPosition.X / 1024, SubPxPosition.Y / 1024 ); } }
public CPos TopLeft { get { return PxPosition.ToCPos(); } }
readonly AircraftInfo Info;
@@ -117,7 +117,7 @@ namespace OpenRA.Mods.RA.Air
{
this.self = init.self;
if( init.Contains<LocationInit>() )
this.SubPxPosition = 1024 * Util.CenterOfCell( init.Get<LocationInit, int2>() );
this.SubPxPosition = 1024 * Util.CenterOfCell( init.Get<LocationInit, CPos>() ).ToInt2();
this.Facing = init.Contains<FacingInit>() ? init.Get<FacingInit,int>() : info.InitialFacing;
this.Altitude = init.Contains<AltitudeInit>() ? init.Get<AltitudeInit,int>() : 0;
@@ -151,17 +151,17 @@ namespace OpenRA.Mods.RA.Air
public int InitialFacing { get { return Info.InitialFacing; } }
public void SetPosition(Actor self, int2 cell)
public void SetPosition(Actor self, CPos cell)
{
SetPxPosition( self, Util.CenterOfCell( cell ) );
}
public void SetPxPosition( Actor self, int2 px )
public void SetPxPosition( Actor self, PPos px )
{
SubPxPosition = px * 1024;
SubPxPosition = px.ToInt2() * 1024;
}
public void AdjustPxPosition(Actor self, int2 px) { SetPxPosition(self, px); }
public void AdjustPxPosition(Actor self, PPos px) { SetPxPosition(self, px); }
public bool AircraftCanEnter(Actor a)
{
@@ -170,7 +170,7 @@ namespace OpenRA.Mods.RA.Air
|| Info.RepairBuildings.Contains( a.Info.Name );
}
public bool CanEnterCell(int2 location) { return true; }
public bool CanEnterCell(CPos location) { return true; }
public int MovementSpeed
{
@@ -183,8 +183,8 @@ namespace OpenRA.Mods.RA.Air
}
}
Pair<int2, SubCell>[] noCells = new Pair<int2, SubCell>[] { };
public IEnumerable<Pair<int2, SubCell>> OccupiedCells() { return noCells; }
Pair<CPos, SubCell>[] noCells = new Pair<CPos, SubCell>[] { };
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { return noCells; }
public void TickMove( int speed, int facing )
{
@@ -192,7 +192,7 @@ namespace OpenRA.Mods.RA.Air
SubPxPosition += rawspeed * -Util.SubPxVector[facing];
}
public bool CanLand(int2 cell)
public bool CanLand(CPos cell)
{
if (!self.World.Map.IsInMap(cell))
return false;
@@ -230,7 +230,7 @@ namespace OpenRA.Mods.RA.Air
return new Order(order.OrderID, self, queued) { TargetActor = target.Actor };
if (order.OrderID == "Move")
return new Order(order.OrderID, self, queued) { TargetLocation = Util.CellContaining(target.CenterLocation) };
return new Order(order.OrderID, self, queued) { TargetLocation = target.CenterLocation.ToCPos() };
return null;
}
@@ -273,7 +273,7 @@ namespace OpenRA.Mods.RA.Air
return false;
}
public bool CanTargetLocation(Actor self, int2 location, List<Actor> actorsAtLocation, bool forceAttack, bool forceQueued, ref string cursor)
public bool CanTargetLocation(Actor self, CPos location, List<Actor> actorsAtLocation, bool forceAttack, bool forceQueued, ref string cursor)
{
IsQueued = forceQueued;
cursor = self.World.Map.IsInMap(location) ? "move" : "move-blocked";

View File

@@ -37,7 +37,7 @@ namespace OpenRA.Mods.RA
{
self.World.AddFrameEndTask(w => w.Add(
new Parachute(pilot.Owner,
Util.CenterOfCell(Util.CellContaining(self.CenterLocation)),
Util.CenterOfCell(self.CenterLocation.ToCPos()),
aircraft.Altitude, pilot)));
Sound.Play(info.ChuteSound, self.CenterLocation);
@@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA
pilot.Destroy();
}
bool IsSuitableCell(Actor actorToDrop, int2 p)
bool IsSuitableCell(Actor actorToDrop, CPos p)
{
return actorToDrop.Trait<ITeleportable>().CanEnterCell(p);
}

View File

@@ -16,12 +16,12 @@ namespace OpenRA.Mods.RA.Air
{
public class Fly : Activity
{
public readonly int2 Pos;
public readonly PPos Pos;
Fly( int2 px ) { Pos = px; }
Fly(PPos px) { Pos = px; }
public static Fly ToPx( int2 px ) { return new Fly( px ); }
public static Fly ToCell( int2 pos ) { return new Fly( Util.CenterOfCell( pos ) ); }
public static Fly ToPx( PPos px ) { return new Fly( px ); }
public static Fly ToCell(CPos pos) { return new Fly(Util.CenterOfCell(pos)); }
public override Activity Tick(Actor self)
{
@@ -35,7 +35,7 @@ namespace OpenRA.Mods.RA.Air
var aircraft = self.Trait<Aircraft>();
var desiredFacing = Util.GetFacing(d, aircraft.Facing);
var desiredFacing = Util.GetFacing(d.ToInt2(), aircraft.Facing);
if (aircraft.Altitude == cruiseAltitude)
aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, aircraft.ROT);

View File

@@ -44,7 +44,7 @@ namespace OpenRA.Mods.RA.Air
var desiredFacing = Util.GetFacing(dist, aircraft.Facing);
aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, aircraft.ROT);
if( !float2.WithinEpsilon( float2.Zero, dist, range * Game.CellSize ) )
if( !float2.WithinEpsilon( float2.Zero, dist.ToFloat2(), range * Game.CellSize ) )
aircraft.TickMove( 1024 * aircraft.MovementSpeed, desiredFacing );
attack.DoAttack( self, target );

View File

@@ -16,8 +16,8 @@ namespace OpenRA.Mods.RA.Air
{
class HeliFly : Activity
{
public readonly int2 Dest;
public HeliFly(int2 dest)
public readonly PPos Dest;
public HeliFly(PPos dest)
{
Dest = dest;
}
@@ -36,9 +36,9 @@ namespace OpenRA.Mods.RA.Air
}
var dist = Dest - aircraft.PxPosition;
if (float2.WithinEpsilon(float2.Zero, dist, 2))
if (float2.WithinEpsilon(float2.Zero, dist.ToFloat2(), 2))
{
aircraft.SubPxPosition = Dest * 1024;
aircraft.SubPxPosition = (Dest.ToInt2() * 1024);
return NextActivity;
}

View File

@@ -37,11 +37,11 @@ namespace OpenRA.Mods.RA.Air
var nearestHpad = self.World.ActorsWithTrait<Reservable>()
.Where(a => a.Actor.Owner == self.Owner && rearmBuildings.Contains(a.Actor.Info.Name))
.Select(a => a.Actor)
.ClosestTo(self.CenterLocation);
if (nearestHpad == null)
return Util.SequenceActivities(new Turn(initialFacing), new HeliLand(true), NextActivity);
else
.ClosestTo(self.CenterLocation);
if (nearestHpad == null)
return Util.SequenceActivities(new Turn(initialFacing), new HeliLand(true), NextActivity);
else
return Util.SequenceActivities(new HeliFly(Util.CenterOfCell(nearestHpad.Location)));
}
@@ -51,7 +51,7 @@ namespace OpenRA.Mods.RA.Air
heli.reservation = res.Reserve(dest, self, heli);
var exit = dest.Info.Traits.WithInterface<ExitInfo>().FirstOrDefault();
var offset = exit != null ? exit.SpawnOffset : int2.Zero;
var offset = exit != null ? exit.SpawnOffsetVector : PVecInt.Zero;
return Util.SequenceActivities(
new HeliFly(dest.Trait<IHasLocation>().PxPosition + offset),

View File

@@ -70,7 +70,7 @@ namespace OpenRA.Mods.RA.Air
reservation = res.Reserve(order.TargetActor, self, this);
var exit = order.TargetActor.Info.Traits.WithInterface<ExitInfo>().FirstOrDefault();
var offset = exit != null ? exit.SpawnOffset : int2.Zero;
var offset = exit != null ? exit.SpawnOffsetVector : PVecInt.Zero;
self.SetTargetLine(Target.FromActor(order.TargetActor), Color.Green);
@@ -118,9 +118,9 @@ namespace OpenRA.Mods.RA.Air
.Select(h => GetRepulseForce(self, h))
.Aggregate(int2.Zero, (a, b) => a + b);
int RepulsionFacing = Util.GetFacing( f, -1 );
if( RepulsionFacing != -1 )
TickMove( 1024 * MovementSpeed, RepulsionFacing );
int repulsionFacing = Util.GetFacing( f, -1 );
if( repulsionFacing != -1 )
TickMove( 1024 * MovementSpeed, repulsionFacing );
}
// Returns an int2 in subPx units
@@ -137,7 +137,7 @@ namespace OpenRA.Mods.RA.Air
if (d.LengthSquared < 1)
return Util.SubPxVector[self.World.SharedRandom.Next(255)];
return (5120 / d.LengthSquared) * d;
return (5120 / d.LengthSquared) * d.ToInt2();
}
}
}

View File

@@ -21,7 +21,7 @@ namespace OpenRA.Mods.RA.Air
public class Plane : Aircraft, IResolveOrder, ITick, ISync
{
[Sync] public int2 RTBPathHash;
[Sync] public PVecInt RTBPathHash;
public Plane( ActorInitializer init, PlaneInfo info )
: base( init, info ) { }

View File

@@ -20,7 +20,7 @@ namespace OpenRA.Mods.RA.Air
bool isCalculated;
Actor dest;
int2 w1, w2, w3; /* tangent points to turn circles */
PPos w1, w2, w3; /* tangent points to turn circles */
public static Actor ChooseAirfield(Actor self)
{
@@ -52,19 +52,18 @@ namespace OpenRA.Mods.RA.Air
var speed = .2f * aircraft.MovementSpeed;
var approachStart = landPos - new float2(aircraft.Altitude * speed, 0);
var approachStart = landPos.ToFloat2() - new float2(aircraft.Altitude * speed, 0);
var turnRadius = (128f / self.Info.Traits.Get<AircraftInfo>().ROT) * speed / (float)Math.PI;
/* work out the center points */
var fwd = -float2.FromAngle(aircraft.Facing / 128f * (float)Math.PI);
var side = new float2(-fwd.Y, fwd.X); /* rotate */
var sideTowardBase = new[] { side, -side }
.OrderBy(a => float2.Dot(a, self.CenterLocation - approachStart))
.OrderBy(a => float2.Dot(a, self.CenterLocation.ToFloat2() - approachStart))
.First();
var c1 = self.CenterLocation + turnRadius * sideTowardBase;
var c2 = approachStart + new float2(0,
turnRadius * Math.Sign(self.CenterLocation.Y - approachStart.Y)); // above or below start point
var c1 = self.CenterLocation.ToFloat2() + turnRadius * sideTowardBase;
var c2 = approachStart + new float2(0, turnRadius * Math.Sign(self.CenterLocation.Y - approachStart.Y)); // above or below start point
/* work out tangent points */
var d = c2 - c1;
@@ -75,10 +74,10 @@ namespace OpenRA.Mods.RA.Air
if (f.X > 0) f = -f;
w1 = (c1 + f).ToInt2();
w2 = (c2 + f).ToInt2();
w3 = (approachStart).ToInt2();
plane.RTBPathHash = w1 + w2 + w3;
w1 = (PPos)(c1 + f).ToInt2();
w2 = (PPos)(c2 + f).ToInt2();
w3 = (PPos)(approachStart).ToInt2();
plane.RTBPathHash = (PVecInt)w1 + (PVecInt)w2 + (PVecInt)w3;
isCalculated = true;
}

View File

@@ -28,10 +28,10 @@ namespace OpenRA.Mods.RA
public AppearsOnRadar(AppearsOnRadarInfo info) { this.info = info; }
public IEnumerable<int2> RadarSignatureCells(Actor self)
public IEnumerable<CPos> RadarSignatureCells(Actor self)
{
if (info.UseLocation)
return new int2[] { self.Location };
return new CPos[] { self.Location };
else
return self.OccupiesSpace.OccupiedCells().Select(c => c.First);
}

View File

@@ -149,7 +149,7 @@ namespace OpenRA.Mods.RA
if( target.IsActor )
return new Order("Attack", self, queued) { TargetActor = target.Actor };
else
return new Order( "Attack", self, queued ) { TargetLocation = Util.CellContaining( target.CenterLocation ) };
return new Order( "Attack", self, queued ) { TargetLocation = target.CenterLocation.ToCPos() };
}
return null;
}
@@ -217,7 +217,7 @@ namespace OpenRA.Mods.RA
return self.Owner.Stances[ target.Owner ] == targetableRelationship;
}
public bool CanTargetLocation(Actor self, int2 location, List<Actor> actorsAtLocation, bool forceAttack, bool forceQueued, ref string cursor)
public bool CanTargetLocation(Actor self, CPos location, List<Actor> actorsAtLocation, bool forceAttack, bool forceQueued, ref string cursor)
{
if (!self.World.Map.IsInMap(location))
return false;

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.RA
public void TickIdle(Actor self)
{
var target = Util.SubPxVector[self.World.SharedRandom.Next(255)]* Info.MoveRadius / 1024 + self.Location;
var target = (CVec)( Util.SubPxVector[self.World.SharedRandom.Next(255)] * Info.MoveRadius / 1024) + self.Location;
self.Trait<AttackMove>().ResolveOrder(self, new Order("AttackMove", self, false) { TargetLocation = target });
}
}

View File

@@ -23,8 +23,8 @@ namespace OpenRA.Mods.RA
class AttackMove : IResolveOrder, IOrderVoice, INotifyIdle, ISync
{
[Sync] public int2 _targetLocation { get { return TargetLocation.HasValue ? TargetLocation.Value : int2.Zero; } }
public int2? TargetLocation = null;
[Sync] public CPos _targetLocation { get { return TargetLocation.HasValue ? TargetLocation.Value : CPos.Zero; } }
public CPos? TargetLocation = null;
readonly Mobile mobile;
readonly AttackMoveInfo Info;

View File

@@ -67,7 +67,7 @@ namespace OpenRA.Mods.RA
static string cachedTileset;
static Cache<TileReference<ushort,byte>, Sprite> sprites;
Dictionary<ushort, Dictionary<int2, Sprite>> TileSprites = new Dictionary<ushort, Dictionary<int2, Sprite>>();
Dictionary<ushort, Dictionary<CPos, Sprite>> TileSprites = new Dictionary<ushort, Dictionary<CPos, Sprite>>();
Dictionary<ushort, TileTemplate> Templates = new Dictionary<ushort, TileTemplate>();
ushort currentTemplate;
@@ -86,7 +86,7 @@ namespace OpenRA.Mods.RA
this.Type = self.Info.Name;
}
public void Create(ushort template, Dictionary<int2, byte> subtiles)
public void Create(ushort template, Dictionary<CPos, byte> subtiles)
{
currentTemplate = template;
@@ -103,7 +103,7 @@ namespace OpenRA.Mods.RA
foreach (var t in Info.Templates)
{
Templates.Add(t.First,self.World.TileSet.Templates[t.First]);
TileSprites.Add(t.First,subtiles.ToDictionary(
TileSprites.Add(t.First, subtiles.ToDictionary(
a => a.Key,
a => sprites[new TileReference<ushort,byte>(t.First, (byte)a.Value)]));
}
@@ -113,10 +113,10 @@ namespace OpenRA.Mods.RA
self.World.Map.CustomTerrain[c.X, c.Y] = GetTerrainType(c);
}
public string GetTerrainType(int2 cell)
public string GetTerrainType(CPos cell)
{
var dx = cell - self.Location;
var index = dx.X + Templates[currentTemplate].Size.X*dx.Y;
var index = dx.X + Templates[currentTemplate].Size.X * dx.Y;
return self.World.TileSet.GetTerrainType(new TileReference<ushort, byte>(currentTemplate,(byte)index));
}
@@ -132,13 +132,13 @@ namespace OpenRA.Mods.RA
public Bridge GetNeighbor(int[] offset, BridgeLayer bridges)
{
if (offset == null) return null;
return bridges.GetBridge(self.Location + new int2(offset[0], offset[1]));
return bridges.GetBridge(self.Location + new CVec(offset[0], offset[1]));
}
public IEnumerable<Renderable> RenderAsTerrain(Actor self)
{
foreach (var t in TileSprites[currentTemplate])
yield return new Renderable(t.Value, Game.CellSize * t.Key, "terrain", Game.CellSize * t.Key.Y);
yield return new Renderable(t.Value, t.Key.ToPPos().ToFloat2(), "terrain", Game.CellSize * t.Key.Y);
}
bool IsIntact(Bridge b)

View File

@@ -75,12 +75,12 @@ namespace OpenRA.Mods.RA
// Create a new actor for this bridge and keep track of which subtiles this bridge includes
var bridge = w.CreateActor(BridgeTypes[tile].First, new TypeDictionary
{
new LocationInit( new int2(ni, nj) ),
new LocationInit( new CPos(ni, nj) ),
new OwnerInit( w.WorldActor.Owner ),
new HealthInit( BridgeTypes[tile].Second ),
}).Trait<Bridge>();
Dictionary<int2, byte> subTiles = new Dictionary<int2, byte>();
var subTiles = new Dictionary<CPos, byte>();
// For each subtile in the template
for (byte ind = 0; ind < template.Size.X*template.Size.Y; ind++)
@@ -97,16 +97,16 @@ namespace OpenRA.Mods.RA
if (!w.Map.IsInMap(x, y) || w.Map.MapTiles.Value[x, y].index != ind)
continue;
subTiles.Add(new int2(x,y),ind);
subTiles.Add(new CPos(x, y), ind);
Bridges[x,y] = bridge;
}
bridge.Create(tile, subTiles);
}
// Used to check for neighbouring bridges
public Bridge GetBridge(int2 cell)
public Bridge GetBridge(CPos cell)
{
if (!world.Map.IsInMap(cell.X, cell.Y))
if (!world.Map.IsInMap(cell))
return null;
return Bridges[ cell.X, cell.Y ];

View File

@@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA.Buildings
{
World world;
BibLayerInfo info;
Dictionary<int2, TileReference<byte, byte>> tiles;
Dictionary<CPos, TileReference<byte, byte>> tiles;
Sprite[][] bibSprites;
public BibLayer(Actor self, BibLayerInfo info)
@@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA.Buildings
public void WorldLoaded(World w)
{
world = w;
tiles = new Dictionary<int2, TileReference<byte, byte>>();
tiles = new Dictionary<CPos, TileReference<byte, byte>>();
}
public void DoBib(Actor b, bool isAdd)
@@ -63,9 +63,9 @@ namespace OpenRA.Mods.RA.Buildings
for (int i = 0; i < 2 * size; i++)
{
var p = b.Location + new int2(i % size, i / size + bibOffset);
var p = b.Location + new CVec(i % size, i / size + bibOffset);
if (isAdd)
tiles[p] = new TileReference<byte, byte>((byte)((isAdd) ? bib + 1 : 0), (byte)i);
tiles[p] = new TileReference<byte, byte>((byte)(bib + 1), (byte)i);
else
tiles.Remove(p);
}
@@ -81,8 +81,7 @@ namespace OpenRA.Mods.RA.Buildings
if (!world.LocalShroud.IsExplored(kv.Key))
continue;
bibSprites[kv.Value.type - 1][kv.Value.index].DrawAt( wr,
Game.CellSize * kv.Key, "terrain");
bibSprites[kv.Value.type - 1][kv.Value.index].DrawAt(wr, kv.Key.ToPPos().ToFloat2(), "terrain");
}
}
}

View File

@@ -32,28 +32,28 @@ namespace OpenRA.Mods.RA.Buildings
public object Create(ActorInitializer init) { return new Building(init, this); }
public bool IsCloseEnoughToBase(World world, Player p, string buildingName, int2 topLeft)
public bool IsCloseEnoughToBase(World world, Player p, string buildingName, CPos topLeft)
{
if (p.PlayerActor.Trait<DeveloperMode>().BuildAnywhere)
return true;
var buildingMaxBounds = Dimensions;
var buildingMaxBounds = (CVec)Dimensions;
if( Rules.Info[ buildingName ].Traits.Contains<BibInfo>() )
buildingMaxBounds.Y += 1;
buildingMaxBounds += new CVec(0, 1);
var scanStart = world.ClampToWorld( topLeft - new int2( Adjacent, Adjacent ) );
var scanEnd = world.ClampToWorld( topLeft + buildingMaxBounds + new int2( Adjacent, Adjacent ) );
var scanStart = world.ClampToWorld( topLeft - new CVec( Adjacent, Adjacent ) );
var scanEnd = world.ClampToWorld(topLeft + buildingMaxBounds + new CVec(Adjacent, Adjacent));
var nearnessCandidates = new List<int2>();
var nearnessCandidates = new List<CPos>();
var bi = world.WorldActor.Trait<BuildingInfluence>();
for( int y = scanStart.Y ; y < scanEnd.Y ; y++ )
for( int x = scanStart.X ; x < scanEnd.X ; x++ )
{
var at = bi.GetBuildingAt( new int2( x, y ) );
var at = bi.GetBuildingAt( new CPos( x, y ) );
if( at != null && at.Owner.Stances[ p ] == Stance.Ally && at.HasTrait<GivesBuildableArea>() )
nearnessCandidates.Add( new int2( x, y ) );
nearnessCandidates.Add( new CPos( x, y ) );
}
var buildingTiles = FootprintUtils.Tiles( buildingName, this, topLeft ).ToList();
@@ -68,27 +68,26 @@ namespace OpenRA.Mods.RA.Buildings
{
readonly Actor self;
public readonly BuildingInfo Info;
[Sync]
readonly int2 topLeft;
[Sync] readonly CPos topLeft;
PowerManager PlayerPower;
int2 pxPosition;
PPos pxPosition;
public int2 TopLeft { get { return topLeft; } }
public int2 PxPosition { get { return pxPosition; } }
public CPos TopLeft { get { return topLeft; } }
public PPos PxPosition { get { return pxPosition; } }
public IEnumerable<string> ProvidesPrerequisites { get { yield return self.Info.Name; } }
public Building(ActorInitializer init, BuildingInfo info)
{
this.self = init.self;
this.topLeft = init.Get<LocationInit,int2>();
this.topLeft = init.Get<LocationInit, CPos>();
this.Info = info;
this.PlayerPower = init.self.Owner.PlayerActor.Trait<PowerManager>();
occupiedCells = FootprintUtils.UnpathableTiles( self.Info.Name, Info, TopLeft )
.Select(c => Pair.New(c, SubCell.FullCell)).ToArray();
pxPosition = ( 2 * topLeft + Info.Dimensions ) * Game.CellSize / 2;
pxPosition = (PPos) (( 2 * topLeft.ToInt2() + Info.Dimensions ) * Game.CellSize / 2);
}
public int GetPowerUsage()
@@ -107,8 +106,8 @@ namespace OpenRA.Mods.RA.Buildings
PlayerPower.UpdateActor(self, GetPowerUsage());
}
Pair<int2,SubCell>[] occupiedCells;
public IEnumerable<Pair<int2, SubCell>> OccupiedCells() { return occupiedCells; }
Pair<CPos, SubCell>[] occupiedCells;
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { return occupiedCells; }
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
{

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Mods.RA.Buildings
influence[ u.X, u.Y ] = isAdd ? a : null;
}
public Actor GetBuildingAt(int2 cell)
public Actor GetBuildingAt(CPos cell)
{
if (!map.IsInMap(cell)) return null;
return influence[cell.X, cell.Y];

View File

@@ -16,34 +16,34 @@ namespace OpenRA.Mods.RA.Buildings
{
public static class FootprintUtils
{
public static IEnumerable<int2> Tiles( string name, BuildingInfo buildingInfo, int2 topLeft )
public static IEnumerable<CPos> Tiles(string name, BuildingInfo buildingInfo, CPos topLeft)
{
var dim = buildingInfo.Dimensions;
var dim = (CVec)buildingInfo.Dimensions;
var footprint = buildingInfo.Footprint.Where(x => !char.IsWhiteSpace(x));
if (Rules.Info[ name ].Traits.Contains<BibInfo>())
{
dim.Y += 1;
dim += new CVec(0, 1);
footprint = footprint.Concat(new char[dim.X]);
}
return TilesWhere( name, dim, footprint.ToArray(), a => a != '_' ).Select( t => t + topLeft );
}
public static IEnumerable<int2> Tiles(Actor a)
public static IEnumerable<CPos> Tiles(Actor a)
{
return Tiles( a.Info.Name, a.Info.Traits.Get<BuildingInfo>(), a.Location );
}
public static IEnumerable<int2> UnpathableTiles( string name, BuildingInfo buildingInfo, int2 position )
public static IEnumerable<CPos> UnpathableTiles(string name, BuildingInfo buildingInfo, CPos position)
{
var footprint = buildingInfo.Footprint.Where( x => !char.IsWhiteSpace( x ) ).ToArray();
foreach( var tile in TilesWhere( name, buildingInfo.Dimensions, footprint, a => a == 'x' ) )
foreach( var tile in TilesWhere( name, (CVec)buildingInfo.Dimensions, footprint, a => a == 'x' ) )
yield return tile + position;
}
static IEnumerable<int2> TilesWhere( string name, int2 dim, char[] footprint, Func<char, bool> cond )
static IEnumerable<CVec> TilesWhere(string name, CVec dim, char[] footprint, Func<char, bool> cond)
{
if( footprint.Length != dim.X * dim.Y )
throw new InvalidOperationException( "Invalid footprint for " + name );
@@ -52,13 +52,13 @@ namespace OpenRA.Mods.RA.Buildings
for( int y = 0 ; y < dim.Y ; y++ )
for( int x = 0 ; x < dim.X ; x++ )
if( cond( footprint[ index++ ] ) )
yield return new int2( x, y );
yield return new CVec(x, y);
}
public static int2 AdjustForBuildingSize( BuildingInfo buildingInfo )
public static CVec AdjustForBuildingSize( BuildingInfo buildingInfo )
{
var dim = buildingInfo.Dimensions;
return new int2( dim.X / 2, dim.Y > 1 ? ( dim.Y + 1 ) / 2 : 0 );
return new CVec(dim.X / 2, dim.Y > 1 ? (dim.Y + 1) / 2 : 0);
}
}
}

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA.Buildings
public void Killed(Actor self, AttackInfo e)
{
self.World.WorldActor.Trait<ScreenShaker>().AddEffect(Info.Intensity, self.CenterLocation, 1);
self.World.WorldActor.Trait<ScreenShaker>().AddEffect(Info.Intensity, self.CenterLocation.ToFloat2(), 1);
}
}
}

View File

@@ -16,12 +16,12 @@ namespace OpenRA.Mods.RA.Buildings
{
public static class BuildingUtils
{
public static bool IsCellBuildable(this World world, int2 a, BuildingInfo bi)
public static bool IsCellBuildable(this World world, CPos a, BuildingInfo bi)
{
return world.IsCellBuildable(a, bi, null);
}
public static bool IsCellBuildable(this World world, int2 a, BuildingInfo bi, Actor toIgnore)
public static bool IsCellBuildable(this World world, CPos a, BuildingInfo bi, Actor toIgnore)
{
if (world.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(a) != null) return false;
if (world.ActorMap.GetUnitsAt(a).Any(b => b != toIgnore)) return false;
@@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA.Buildings
return world.Map.IsInMap(a) && bi.TerrainTypes.Contains(world.GetTerrainType(a));
}
public static bool CanPlaceBuilding(this World world, string name, BuildingInfo building, int2 topLeft, Actor toIgnore)
public static bool CanPlaceBuilding(this World world, string name, BuildingInfo building, CPos topLeft, Actor toIgnore)
{
var res = world.WorldActor.Trait<ResourceLayer>();
return FootprintUtils.Tiles(name, building, topLeft).All(
@@ -37,7 +37,7 @@ namespace OpenRA.Mods.RA.Buildings
world.IsCellBuildable(t, building, toIgnore));
}
public static IEnumerable<int2> GetLineBuildCells(World world, int2 location, string name, BuildingInfo bi)
public static IEnumerable<CPos> GetLineBuildCells(World world, CPos location, string name, BuildingInfo bi)
{
int range = Rules.Info[name].Traits.Get<LineBuildInfo>().Range;
var topLeft = location; // 1x1 assumption!
@@ -47,7 +47,7 @@ namespace OpenRA.Mods.RA.Buildings
// Start at place location, search outwards
// TODO: First make it work, then make it nice
var vecs = new[] { new int2(1, 0), new int2(0, 1), new int2(-1, 0), new int2(0, -1) };
var vecs = new[] { new CVec(1, 0), new CVec(0, 1), new CVec(-1, 0), new CVec(0, -1) };
int[] dirs = { 0, 0, 0, 0 };
for (int d = 0; d < 4; d++)
{
@@ -56,7 +56,7 @@ namespace OpenRA.Mods.RA.Buildings
if (dirs[d] != 0)
continue;
int2 cell = topLeft + i * vecs[d];
CPos cell = topLeft + i * vecs[d];
if (world.IsCellBuildable(cell, bi))
continue; // Cell is empty; continue search

View File

@@ -24,8 +24,7 @@ namespace OpenRA.Mods.RA
class Burns : ITick, ISync
{
[Sync]
int ticks;
[Sync] int ticks;
BurnsInfo Info;
public Burns(Actor self, BurnsInfo info)

View File

@@ -22,16 +22,16 @@ namespace OpenRA.Mods.RA
class CarpetBomb : ITick // todo: maybe integrate this better with the normal weapons system?
{
int2 Target;
CPos Target;
int dropDelay;
public void SetTarget(int2 targetCell) { Target = targetCell; }
public void SetTarget(CPos targetCell) { Target = targetCell; }
public void Tick(Actor self)
{
var info = self.Info.Traits.Get<CarpetBombInfo>();
if( !Combat.IsInRange( self.CenterLocation, info.Range, Target * Game.CellSize ) )
if( !Combat.IsInRange( self.CenterLocation, info.Range, Target.ToPPos() ) )
return;
var limitedAmmo = self.TraitOrDefault<LimitedAmmo>();

View File

@@ -26,8 +26,7 @@ namespace OpenRA.Mods.RA
class CashTrickler : ITick, ISync
{
[Sync]
int ticks;
[Sync] int ticks;
CashTricklerInfo Info;
public CashTrickler(CashTricklerInfo info)
{

View File

@@ -24,8 +24,7 @@ namespace OpenRA.Mods.RA
class ChronoshiftDeploy : IIssueOrder, IResolveOrder, ITick, IPips, IOrderVoice, ISync
{
// Recharge logic
[Sync]
int chargeTick = 0; // How long until we can chronoshift again?
[Sync] int chargeTick = 0; // How long until we can chronoshift again?
public void Tick(Actor self)
{
@@ -60,7 +59,7 @@ namespace OpenRA.Mods.RA
self.CancelActivity();
self.QueueActivity(new Teleport(order.TargetLocation));
Sound.Play("chrotnk1.aud", self.CenterLocation);
Sound.Play("chrotnk1.aud", Game.CellSize * order.TargetLocation.ToFloat2());
Sound.Play("chrotnk1.aud", order.TargetLocation.ToPPos());
chargeTick = 25 * self.Info.Traits.Get<ChronoshiftDeployInfo>().ChargeTime;
foreach (var a in self.World.ActorsWithTrait<ChronoshiftPaletteEffect>())

View File

@@ -18,10 +18,8 @@ namespace OpenRA.Mods.RA
public class Chronoshiftable : ITick, ISync
{
// Return-to-sender logic
[Sync]
int2 chronoshiftOrigin;
[Sync]
int chronoshiftReturnTicks = 0;
[Sync] CPos chronoshiftOrigin;
[Sync] int chronoshiftReturnTicks = 0;
public void Tick(Actor self)
{
@@ -41,7 +39,7 @@ namespace OpenRA.Mods.RA
}
// Can't be used in synced code, except with ignoreVis.
public virtual bool CanChronoshiftTo(Actor self, int2 targetLocation, bool ignoreVis)
public virtual bool CanChronoshiftTo(Actor self, CPos targetLocation, bool ignoreVis)
{
// Todo: Allow enemy units to be chronoshifted into bad terrain to kill them
return self.HasTrait<ITeleportable>() &&
@@ -49,7 +47,7 @@ namespace OpenRA.Mods.RA
(ignoreVis || self.World.LocalShroud.IsExplored(targetLocation));
}
public virtual bool Teleport(Actor self, int2 targetLocation, int duration, bool killCargo, Actor chronosphere)
public virtual bool Teleport(Actor self, CPos targetLocation, int duration, bool killCargo, Actor chronosphere)
{
/// Set up return-to-sender info
chronoshiftOrigin = self.Location;

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA
public static void DoImpact(WarheadInfo warhead, ProjectileArgs args)
{
var world = args.firedBy.World;
var targetTile = Util.CellContaining(args.dest);
var targetTile = args.dest.ToCPos();
if (!world.Map.IsInMap(targetTile))
return;
@@ -92,7 +92,7 @@ namespace OpenRA.Mods.RA
case DamageModel.PerCell:
{
foreach (var t in world.FindTilesInCircle(targetTile, warhead.Size[0]))
foreach (var unit in world.FindUnits(Game.CellSize * t, Game.CellSize * (t + new int2(1,1))))
foreach (var unit in world.FindUnits(t.ToPPos(), (t + new CVec(1,1)).ToPPos()))
unit.InflictDamage(args.firedBy,
(int)(warhead.Damage * warhead.EffectivenessAgainst(unit)), warhead);
} break;
@@ -103,16 +103,19 @@ namespace OpenRA.Mods.RA
{
foreach (var warhead in args.weapon.Warheads)
{
Action a = () => DoImpact(warhead, args);
// NOTE(jsd): Fixed access to modified closure bug!
var warheadClosed = warhead;
Action a = () => DoImpact(warheadClosed, args);
if (warhead.Delay > 0)
args.firedBy.World.AddFrameEndTask(
w => w.Add(new DelayedAction(warhead.Delay, a)));
w => w.Add(new DelayedAction(warheadClosed.Delay, a)));
else
a();
}
}
public static void DoExplosion(Actor attacker, string weapontype, int2 pos, int altitude)
public static void DoExplosion(Actor attacker, string weapontype, PPos pos, int altitude)
{
var args = new ProjectileArgs
{
@@ -174,7 +177,7 @@ namespace OpenRA.Mods.RA
return true;
}
public static bool WeaponValidForTarget( WeaponInfo weapon, World world, int2 location )
public static bool WeaponValidForTarget( WeaponInfo weapon, World world, CPos location )
{
if( weapon.ValidTargets.Contains( "Ground" ) && world.GetTerrainType( location ) != "Water" ) return true;
if( weapon.ValidTargets.Contains( "Water" ) && world.GetTerrainType( location ) == "Water" ) return true;
@@ -192,7 +195,7 @@ namespace OpenRA.Mods.RA
return Util.RotateVectorByFacing(localRecoil, facing, .7f);
}
public static float2 GetTurretPosition(Actor self, IFacing facing, Turret turret)
public static PVecInt GetTurretPosition(Actor self, IFacing facing, Turret turret)
{
if (facing == null) return turret.ScreenSpacePosition; /* things that don't have a rotating base don't need the turrets repositioned */
@@ -201,41 +204,41 @@ namespace OpenRA.Mods.RA
var bodyFacing = facing.Facing;
var quantizedFacing = Util.QuantizeFacing(bodyFacing, numDirs) * (256 / numDirs);
return (Util.RotateVectorByFacing(turret.UnitSpacePosition, quantizedFacing, .7f)
return (PVecInt) ((PVecFloat)(Util.RotateVectorByFacing(turret.UnitSpacePosition.ToFloat2(), quantizedFacing, .7f)
+ GetRecoil(self, turret.Recoil))
+ turret.ScreenSpacePosition;
+ turret.ScreenSpacePosition);
}
// gets the screen-space position of a barrel.
public static float2 GetBarrelPosition(Actor self, IFacing facing, Turret turret, Barrel barrel)
public static PVecInt GetBarrelPosition(Actor self, IFacing facing, Turret turret, Barrel barrel)
{
var turreted = self.TraitOrDefault<Turreted>();
if (turreted == null && facing == null)
return float2.Zero;
return PVecInt.Zero;
var turretFacing = turreted != null ? turreted.turretFacing : facing.Facing;
return GetTurretPosition(self, facing, turret) + barrel.ScreenSpaceOffset
+ Util.RotateVectorByFacing(barrel.TurretSpaceOffset, turretFacing, .7f);
+ (PVecInt)(PVecFloat)Util.RotateVectorByFacing(barrel.TurretSpaceOffset.ToFloat2(), turretFacing, .7f);
}
public static bool IsInRange( float2 attackOrigin, float range, Actor target )
public static bool IsInRange( PPos attackOrigin, float range, Actor target )
{
var rsq = range * range * Game.CellSize * Game.CellSize;
foreach( var cell in target.Trait<ITargetable>().TargetableCells( target ) )
if( ( attackOrigin - cell * Game.CellSize ).LengthSquared <= rsq )
foreach ( var cell in target.Trait<ITargetable>().TargetableCells( target ) )
if ( (attackOrigin - cell.ToPPos()).LengthSquared <= rsq )
return true;
return false;
}
public static bool IsInRange( float2 attackOrigin, float range, float2 targetLocation )
public static bool IsInRange(PPos attackOrigin, float range, PPos targetLocation)
{
var rsq = range * range * Game.CellSize * Game.CellSize;
return ( attackOrigin - targetLocation ).LengthSquared <= rsq;
}
public static bool IsInRange( float2 attackOrigin, float range, Target target )
public static bool IsInRange(PPos attackOrigin, float range, Target target)
{
if( !target.IsValid ) return false;
if( target.IsActor )

View File

@@ -39,7 +39,7 @@ namespace OpenRA.Mods.RA
{
readonly Actor self;
[Sync] int ticks;
[Sync] public int2 Location;
[Sync] public CPos Location;
CrateInfo Info;
public Crate(ActorInitializer init, CrateInfo info)
@@ -47,7 +47,7 @@ namespace OpenRA.Mods.RA
this.self = init.self;
if (init.Contains<LocationInit>())
{
this.Location = init.Get<LocationInit, int2>();
this.Location = init.Get<LocationInit, CPos>();
PxPosition = Util.CenterOfCell(Location);
}
this.Info = info;
@@ -79,19 +79,19 @@ namespace OpenRA.Mods.RA
self.Destroy();
}
public int2 TopLeft { get { return Location; } }
public IEnumerable<Pair<int2, SubCell>> OccupiedCells() { yield return Pair.New( Location, SubCell.FullCell); }
public CPos TopLeft { get { return Location; } }
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { yield return Pair.New( Location, SubCell.FullCell); }
public int2 PxPosition { get; private set; }
public PPos PxPosition { get; private set; }
public void SetPxPosition( Actor self, int2 px )
public void SetPxPosition(Actor self, PPos px)
{
SetPosition( self, Util.CellContaining( px ) );
SetPosition( self, px.ToCPos() );
}
public void AdjustPxPosition(Actor self, int2 px) { SetPxPosition(self, px); }
public void AdjustPxPosition(Actor self, PPos px) { SetPxPosition(self, px); }
public bool CanEnterCell(int2 cell)
public bool CanEnterCell(CPos cell)
{
if (!self.World.Map.IsInMap(cell.X, cell.Y)) return false;
var type = self.World.GetTerrainType(cell);
@@ -104,7 +104,7 @@ namespace OpenRA.Mods.RA
return true;
}
public void SetPosition(Actor self, int2 cell)
public void SetPosition(Actor self, CPos cell)
{
if( self.IsInWorld )
self.World.ActorMap.Remove(self, this);

View File

@@ -54,7 +54,7 @@ namespace OpenRA.Mods.RA
}
}
int2? ChooseDropCell(Actor self, bool inWater, int maxTries)
CPos? ChooseDropCell(Actor self, bool inWater, int maxTries)
{
for( var n = 0; n < maxTries; n++ )
{

View File

@@ -60,17 +60,17 @@ namespace OpenRA.Mods.RA.Crates
base.Activate(collector);
}
IEnumerable<int2> GetSuitableCells(int2 near)
IEnumerable<CPos> GetSuitableCells(CPos near)
{
var mi = Rules.Info[Info.Unit].Traits.Get<MobileInfo>();
for (var i = -1; i < 2; i++)
for (var j = -1; j < 2; j++)
if (mi.CanEnterCell(self.World, self.Owner, near + new int2(i, j), null, true))
yield return near + new int2(i, j);
if (mi.CanEnterCell(self.World, self.Owner, near + new CVec(i, j), null, true))
yield return near + new CVec(i, j);
}
int2? ChooseEmptyCellNear(Actor a)
CPos? ChooseEmptyCellNear(Actor a)
{
var possibleCells = GetSuitableCells(a.Location).ToArray();
if (possibleCells.Length == 0)

View File

@@ -17,7 +17,7 @@ namespace OpenRA.Mods.RA
class DemoTruck : Chronoshiftable, INotifyKilled
{
// Explode on chronoshift
public override bool Teleport(Actor self, int2 targetLocation, int duration, bool killCargo, Actor chronosphere)
public override bool Teleport(Actor self, CPos targetLocation, int duration, bool killCargo, Actor chronosphere)
{
Detonate(self, chronosphere);
return false;

View File

@@ -57,8 +57,8 @@ namespace OpenRA.Mods.RA.Effects
if (info.Inaccuracy > 0)
{
var factor = ((Args.dest - Args.src).Length / Game.CellSize) / args.weapon.Range;
Args.dest += (info.Inaccuracy * factor * args.firedBy.World.SharedRandom.Gauss2D(2)).ToInt2();
var factor = ((Args.dest - Args.src).Length / (float)Game.CellSize) / args.weapon.Range;
Args.dest += (PVecInt) (info.Inaccuracy * factor * args.firedBy.World.SharedRandom.Gauss2D(2)).ToInt2();
}
if (Info.Image != null)
@@ -110,7 +110,7 @@ namespace OpenRA.Mods.RA.Effects
{
var at = (float)t / TotalTime();
var altitude = float2.Lerp(Args.srcAltitude, Args.destAltitude, at);
var pos = float2.Lerp(Args.src, Args.dest, at) - new float2(0, altitude);
var pos = float2.Lerp(Args.src.ToFloat2(), Args.dest.ToFloat2(), at) - new float2(0, altitude);
var highPos = (Info.High || Info.Angle > 0)
? (pos - new float2(0, GetAltitude()))
@@ -119,24 +119,24 @@ namespace OpenRA.Mods.RA.Effects
if (Info.Trail != null && --ticksToNextSmoke < 0)
{
world.AddFrameEndTask(w => w.Add(
new Smoke(w, highPos.ToInt2(), Info.Trail)));
new Smoke(w, (PPos) highPos.ToInt2(), Info.Trail)));
ticksToNextSmoke = Info.TrailInterval;
}
if (Trail != null)
Trail.Tick(highPos);
Trail.Tick((PPos)highPos.ToInt2());
}
if (!Info.High) // check for hitting a wall
{
var at = (float)t / TotalTime();
var pos = float2.Lerp(Args.src, Args.dest, at);
var cell = Traits.Util.CellContaining(pos);
var pos = float2.Lerp(Args.src.ToFloat2(), Args.dest.ToFloat2(), at);
var cell = ((PPos) pos.ToInt2()).ToCPos();
if (world.ActorMap.GetUnitsAt(cell).Any(
a => a.HasTrait<IBlocksBullets>()))
{
Args.dest = pos.ToInt2();
Args.dest = (PPos) pos.ToInt2();
Explode(world);
}
}
@@ -151,9 +151,9 @@ namespace OpenRA.Mods.RA.Effects
var at = (float)t / TotalTime();
var altitude = float2.Lerp(Args.srcAltitude, Args.destAltitude, at);
var pos = float2.Lerp(Args.src, Args.dest, at) - new float2(0, altitude);
var pos = float2.Lerp(Args.src.ToFloat2(), Args.dest.ToFloat2(), at) - new float2(0, altitude);
if (Args.firedBy.World.LocalShroud.IsVisible(OpenRA.Traits.Util.CellContaining(pos)))
if (Args.firedBy.World.LocalShroud.IsVisible(((PPos) pos.ToInt2()).ToCPos()))
{
if (Info.High || Info.Angle > 0)
{

View File

@@ -18,19 +18,20 @@ namespace OpenRA.Mods.RA.Effects
{
class CashTick : IEffect
{
string s;
readonly string s;
int remaining;
int velocity;
float2 pos, offset;
Color color;
SpriteFont font;
readonly int velocity;
PPos pos;
readonly float2 offset;
readonly Color color;
readonly SpriteFont font;
static string FormatCashAmount(int x) { return "{0}${1}".F(x < 0 ? "-" : "+", x); }
public CashTick(int value, int lifetime, int velocity, float2 pos, Color color)
public CashTick(int value, int lifetime, int velocity, PPos pos, Color color)
: this( FormatCashAmount(value), lifetime, velocity, pos, color ) { }
public CashTick(string value, int lifetime, int velocity, float2 pos, Color color)
public CashTick(string value, int lifetime, int velocity, PPos pos, Color color)
{
this.color = color;
this.velocity = velocity;
@@ -45,12 +46,12 @@ namespace OpenRA.Mods.RA.Effects
{
if (--remaining <= 0)
world.AddFrameEndTask(w => w.Remove(this));
pos.Y -= velocity;
pos -= new PVecInt(0, velocity);
}
public IEnumerable<Renderable> Render()
{
font.DrawTextWithContrast(s, Game.viewport.Zoom*(pos - Game.viewport.Location) - offset, color, Color.Black,1);
font.DrawTextWithContrast(s, Game.viewport.Zoom*(pos.ToFloat2() - Game.viewport.Location) - offset, color, Color.Black,1);
yield break;
}
}

View File

@@ -45,8 +45,7 @@ namespace OpenRA.Mods.RA
public void Tick(Actor self)
{
history.Tick(self.CenterLocation - new int2(0, move.Altitude)
- Combat.GetTurretPosition(self, facing, contrailTurret));
history.Tick(self.CenterLocation - new PVecInt(0, move.Altitude) - Combat.GetTurretPosition(self, facing, contrailTurret));
}
public void RenderAfterWorld(WorldRenderer wr, Actor self) { history.Render(self); }
@@ -54,7 +53,7 @@ namespace OpenRA.Mods.RA
class ContrailHistory
{
List<float2> positions = new List<float2>();
List<PPos> positions = new List<PPos>();
readonly int TrailLength;
readonly Color Color;
readonly int StartSkip;
@@ -75,7 +74,7 @@ namespace OpenRA.Mods.RA
this.StartSkip = startSkip;
}
public void Tick(float2 currentPos)
public void Tick(PPos currentPos)
{
positions.Add(currentPos);
if (positions.Count >= TrailLength)
@@ -85,22 +84,20 @@ namespace OpenRA.Mods.RA
public void Render(Actor self)
{
Color trailStart = Color;
Color trailEnd = Color.FromArgb(trailStart.A - 255 / TrailLength, trailStart.R,
trailStart.G, trailStart.B);
Color trailEnd = Color.FromArgb(trailStart.A - 255 / TrailLength, trailStart.R, trailStart.G, trailStart.B);
for (int i = positions.Count - 1 - StartSkip; i >= 1; --i)
{
var conPos = positions[i];
var nextPos = positions[i - 1];
if (self.World.LocalShroud.IsVisible(OpenRA.Traits.Util.CellContaining(conPos)) ||
self.World.LocalShroud.IsVisible(OpenRA.Traits.Util.CellContaining(nextPos)))
if (self.World.LocalShroud.IsVisible(conPos.ToCPos()) ||
self.World.LocalShroud.IsVisible(nextPos.ToCPos()))
{
Game.Renderer.WorldLineRenderer.DrawLine(conPos, nextPos, trailStart, trailEnd);
Game.Renderer.WorldLineRenderer.DrawLine(conPos.ToFloat2(), nextPos.ToFloat2(), trailStart, trailEnd);
trailStart = trailEnd;
trailEnd = Color.FromArgb(trailStart.A - 255 / positions.Count, trailStart.R,
trailStart.G, trailStart.B);
trailEnd = Color.FromArgb(trailStart.A - 255 / positions.Count, trailStart.R, trailStart.G, trailStart.B);
}
}
}

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA.Effects
anim.PlayThen(sequence,
() => fromActor.World.AddFrameEndTask(w => w.Remove(this)));
pos = fromActor.CenterLocation;
pos = fromActor.CenterLocation.ToFloat2();
}
public void Tick( World world ) { anim.Tick(); }

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Mods.RA.Effects
{
if (a.IsInWorld)
yield return new Renderable(anim.Image,
a.CenterLocation - .5f * anim.Image.size + offset, "effect", (int)a.CenterLocation.Y);
a.CenterLocation.ToFloat2() - .5f * anim.Image.size + offset, "effect", (int)a.CenterLocation.Y);
}
}
}

View File

@@ -18,10 +18,10 @@ namespace OpenRA.Mods.RA.Effects
public class Explosion : IEffect
{
Animation anim;
int2 pos;
PPos pos;
int altitude;
public Explosion(World world, int2 pixelPos, string style, bool isWater, int altitude)
public Explosion(World world, PPos pixelPos, string style, bool isWater, int altitude)
{
this.pos = pixelPos;
this.altitude = altitude;
@@ -35,7 +35,7 @@ namespace OpenRA.Mods.RA.Effects
public IEnumerable<Renderable> Render()
{
yield return new Renderable(anim.Image,
pos - .5f * anim.Image.size - new int2(0,altitude),
pos.ToFloat2() - .5f * anim.Image.size - new int2(0,altitude),
"effect", (int)pos.Y - altitude);
}

View File

@@ -70,7 +70,7 @@ namespace OpenRA.Mods.RA.Effects
if (show && !self.Destroyed)
{
var p = self.CenterLocation;
yield return new Renderable(anim.Image, p - 0.5f * anim.Image.size, rs.Palette(self.Owner), p.Y)
yield return new Renderable(anim.Image, p.ToFloat2() - 0.5f * anim.Image.size, rs.Palette(self.Owner), p.Y)
.WithScale(1.5f);
}
}

View File

@@ -54,7 +54,7 @@ namespace OpenRA.Mods.RA.Effects
public IEnumerable<Renderable> Render()
{
yield return new Renderable(anim.Image,
Args.dest - new int2(0, altitude) - .5f * anim.Image.size, "effect", Args.dest.Y);
Args.dest.ToInt2() - new int2(0, altitude) - .5f * anim.Image.size, "effect", Args.dest.Y);
}
}
}

View File

@@ -78,7 +78,7 @@ namespace OpenRA.Mods.RA.Effects
{
if (explosion != null)
yield return new Renderable(explosion.Image,
args.dest - .5f * explosion.Image.size, "effect", (int)args.dest.Y);
args.dest.ToFloat2() - .5f * explosion.Image.size, "effect", (int)args.dest.Y);
if (ticks >= info.BeamDuration)
yield break;
@@ -87,7 +87,7 @@ namespace OpenRA.Mods.RA.Effects
var wlr = Game.Renderer.WorldLineRenderer;
wlr.LineWidth = info.BeamRadius * 2;
wlr.DrawLine(args.src, args.dest, rc, rc);
wlr.DrawLine(args.src.ToFloat2(), args.dest.ToFloat2(), rc, rc);
wlr.Flush();
wlr.LineWidth = 1f;
}

View File

@@ -46,9 +46,9 @@ namespace OpenRA.Mods.RA.Effects
readonly MissileInfo Info;
readonly ProjectileArgs Args;
int2 offset;
PVecInt offset;
public int2 SubPxPosition;
public int2 PxPosition { get { return new int2( SubPxPosition.X / 1024, SubPxPosition.Y / 1024 ); } }
public PPos PxPosition { get { return new PPos(SubPxPosition.X / 1024, SubPxPosition.Y / 1024); } }
readonly Animation anim;
int Facing;
@@ -61,12 +61,12 @@ namespace OpenRA.Mods.RA.Effects
Info = info;
Args = args;
SubPxPosition = 1024 * Args.src;
SubPxPosition = 1024 * Args.src.ToInt2();
Altitude = Args.srcAltitude;
Facing = Args.facing;
if (info.Inaccuracy > 0)
offset = (info.Inaccuracy * args.firedBy.World.SharedRandom.Gauss2D(2)).ToInt2();
offset = (PVecInt)(info.Inaccuracy * args.firedBy.World.SharedRandom.Gauss2D(2)).ToInt2();
if (Info.Image != null)
{
@@ -121,7 +121,7 @@ namespace OpenRA.Mods.RA.Effects
if (Info.Trail != null)
{
var sp = (SubPxPosition - (move * 3) / 2) / 1024 - new int2(0, Altitude);
var sp = (PPos)((SubPxPosition - (move * 3) / 2) / 1024) - new PVecInt(0, Altitude);
if (--ticksToNextSmoke < 0)
{
@@ -135,14 +135,13 @@ namespace OpenRA.Mods.RA.Effects
if (!Info.High) // check for hitting a wall
{
var cell = Traits.Util.CellContaining(PxPosition);
if (world.ActorMap.GetUnitsAt(cell).Any(
a => a.HasTrait<IBlocksBullets>()))
var cell = PxPosition.ToCPos();
if (world.ActorMap.GetUnitsAt(cell).Any(a => a.HasTrait<IBlocksBullets>()))
Explode(world);
}
if (Trail != null)
Trail.Tick(PxPosition - new float2(0,Altitude));
Trail.Tick(PxPosition - new PVecInt(0, Altitude));
}
void Explode(World world)
@@ -155,8 +154,8 @@ namespace OpenRA.Mods.RA.Effects
public IEnumerable<Renderable> Render()
{
if (Args.firedBy.World.LocalShroud.IsVisible(OpenRA.Traits.Util.CellContaining(PxPosition.ToFloat2())))
yield return new Renderable(anim.Image,PxPosition.ToFloat2() - 0.5f * anim.Image.size - new float2(0, Altitude),
if (Args.firedBy.World.LocalShroud.IsVisible(PxPosition.ToCPos()))
yield return new Renderable(anim.Image, PxPosition.ToFloat2() - 0.5f * anim.Image.size - new float2(0, Altitude),
Args.weapon.Underwater ? "shadow" : "effect", PxPosition.Y);
if (Trail != null)

View File

@@ -19,13 +19,13 @@ namespace OpenRA.Mods.RA.Effects
{
readonly Player firedBy;
Animation anim;
int2 pos;
int2 targetLocation;
PPos pos;
CPos targetLocation;
int altitude;
bool goingUp = true;
string weapon;
public NukeLaunch(Player firedBy, Actor silo, string weapon, int2 spawnOffset, int2 targetLocation)
public NukeLaunch(Player firedBy, Actor silo, string weapon, PVecInt spawnOffset, CPos targetLocation)
{
this.firedBy = firedBy;
this.targetLocation = targetLocation;
@@ -71,7 +71,7 @@ namespace OpenRA.Mods.RA.Effects
{
world.AddFrameEndTask(w => w.Remove(this));
Combat.DoExplosion(firedBy.PlayerActor, weapon, pos, 0);
world.WorldActor.Trait<ScreenShaker>().AddEffect(20, pos, 5);
world.WorldActor.Trait<ScreenShaker>().AddEffect(20, pos.ToFloat2(), 5);
foreach (var a in world.ActorsWithTrait<NukePaletteEffect>())
a.Trait.Enable();
@@ -79,7 +79,7 @@ namespace OpenRA.Mods.RA.Effects
public IEnumerable<Renderable> Render()
{
yield return new Renderable(anim.Image, pos - 0.5f * anim.Image.size - new float2(0, altitude),
yield return new Renderable(anim.Image, pos.ToFloat2() - 0.5f * anim.Image.size - new float2(0, altitude),
"effect", (int)pos.Y);
}
}

View File

@@ -20,7 +20,7 @@ namespace OpenRA.Mods.RA.Effects
readonly Animation anim;
readonly string palette;
readonly Animation paraAnim;
readonly float2 location;
readonly PPos location;
readonly Actor cargo;
@@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA.Effects
float altitude;
const float fallRate = .3f;
public Parachute(Player owner, float2 location, int altitude, Actor cargo)
public Parachute(Player owner, PPos location, int altitude, Actor cargo)
{
this.location = location;
this.altitude = altitude;
@@ -63,7 +63,7 @@ namespace OpenRA.Mods.RA.Effects
world.AddFrameEndTask(w =>
{
w.Remove(this);
var loc = Traits.Util.CellContaining(location);
var loc = location.ToCPos();
cargo.CancelActivity();
cargo.Trait<ITeleportable>().SetPosition(cargo, loc);
w.Add(cargo);
@@ -72,8 +72,8 @@ namespace OpenRA.Mods.RA.Effects
public IEnumerable<Renderable> Render()
{
var pos = location - new float2(0, altitude);
yield return new Renderable(anim.Image, location - .5f * anim.Image.size, "shadow", 0);
var pos = location.ToFloat2() - new float2(0, altitude);
yield return new Renderable(anim.Image, location.ToFloat2() - .5f * anim.Image.size, "shadow", 0);
yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, palette, 2);
yield return new Renderable(paraAnim.Image, pos - .5f * paraAnim.Image.size + offset, palette, 3);
}

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Mods.RA.Effects
{
if (!a.Destroyed && (a.World.LocalPlayer == null || a.Owner.Stances[a.Owner.World.LocalPlayer] == Stance.Ally))
yield return new Renderable(anim.Image,
a.CenterLocation - .5f * anim.Image.size, "chrome", (int)a.CenterLocation.Y);
a.CenterLocation.ToFloat2() - .5f * anim.Image.size, "chrome", (int)a.CenterLocation.Y);
}
}
}

View File

@@ -18,8 +18,8 @@ namespace OpenRA.Mods.RA.Effects
{
class RallyPoint : IEffect
{
Actor building;
RA.RallyPoint rp;
readonly Actor building;
readonly RA.RallyPoint rp;
public Animation flag = new Animation("rallypoint");
public Animation circles = new Animation("rallypoint");
@@ -31,7 +31,7 @@ namespace OpenRA.Mods.RA.Effects
circles.Play("circles");
}
int2 cachedLocation;
CPos cachedLocation;
public void Tick( World world )
{
flag.Tick();
@@ -55,11 +55,11 @@ namespace OpenRA.Mods.RA.Effects
var palette = building.Trait<RenderSimple>().Palette(building.Owner);
yield return new Renderable(circles.Image,
pos - .5f * circles.Image.size,
pos.ToFloat2() - .5f * circles.Image.size,
palette, (int)pos.Y);
yield return new Renderable(flag.Image,
pos + new float2(-1,-17),
pos.ToFloat2() + new float2(-1,-17),
palette, (int)pos.Y);
}
}

View File

@@ -47,7 +47,7 @@ namespace OpenRA.Mods.RA.Effects
var palette = building.Trait<RenderSimple>().Palette(player);
yield return new Renderable(anim.Image,
building.CenterLocation - .5f * anim.Image.size, palette, (int)building.CenterLocation.Y);
building.CenterLocation.ToFloat2() - .5f * anim.Image.size, palette, (int)building.CenterLocation.Y);
}
}
}

View File

@@ -27,7 +27,7 @@ namespace OpenRA.Mods.RA.Effects
doors.PlayThen("active",
() => a.World.AddFrameEndTask(w => w.Remove(this)));
pos = a.CenterLocation - .5f * doors.Image.size + doorOffset;
pos = a.CenterLocation.ToFloat2() - .5f * doors.Image.size + doorOffset;
}
public void Tick( World world )

View File

@@ -17,10 +17,10 @@ namespace OpenRA.Mods.RA.Effects
{
public class Smoke : IEffect
{
readonly int2 pos;
readonly PPos pos;
readonly Animation anim;
public Smoke(World world, int2 pos, string trail)
public Smoke(World world, PPos pos, string trail)
{
this.pos = pos;
anim = new Animation(trail);
@@ -35,7 +35,7 @@ namespace OpenRA.Mods.RA.Effects
public IEnumerable<Renderable> Render()
{
yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, "effect", (int)pos.Y);
yield return new Renderable(anim.Image, pos.ToFloat2() - .5f * anim.Image.size, "effect", (int)pos.Y);
}
}
}

View File

@@ -64,7 +64,7 @@ namespace OpenRA.Mods.RA.Effects
public IEnumerable<Renderable> Render() { return renderables; }
static IEnumerable<Renderable> DrawZapWandering(int2 from, int2 to, Sequence s)
static IEnumerable<Renderable> DrawZapWandering(PPos from, PPos to, Sequence s)
{
var z = float2.Zero; /* hack */
var dist = to - from;
@@ -73,19 +73,19 @@ namespace OpenRA.Mods.RA.Effects
var renderables = new List<Renderable>();
if (Game.CosmeticRandom.Next(2) != 0)
{
var p1 = from + (1 / 3f) * dist.ToFloat2() + Game.CosmeticRandom.Gauss1D(1) * .2f * dist.Length * norm;
var p2 = from + (2 / 3f) * dist.ToFloat2() + Game.CosmeticRandom.Gauss1D(1) * .2f * dist.Length * norm;
var p1 = from.ToFloat2() + (1 / 3f) * dist.ToFloat2() + Game.CosmeticRandom.Gauss1D(1) * .2f * dist.Length * norm;
var p2 = from.ToFloat2() + (2 / 3f) * dist.ToFloat2() + Game.CosmeticRandom.Gauss1D(1) * .2f * dist.Length * norm;
renderables.AddRange(DrawZap(from, p1, s, out p1));
renderables.AddRange(DrawZap(from.ToFloat2(), p1, s, out p1));
renderables.AddRange(DrawZap(p1, p2, s, out p2));
renderables.AddRange(DrawZap(p2, to, s, out z));
renderables.AddRange(DrawZap(p2, to.ToFloat2(), s, out z));
}
else
{
var p1 = from + (1 / 2f) * dist.ToFloat2() + Game.CosmeticRandom.Gauss1D(1) * .2f * dist.Length * norm;
var p1 = from.ToFloat2() + (1 / 2f) * dist.ToFloat2() + Game.CosmeticRandom.Gauss1D(1) * .2f * dist.Length * norm;
renderables.AddRange(DrawZap(from, p1, s, out p1));
renderables.AddRange(DrawZap(p1, to, s, out z));
renderables.AddRange(DrawZap(from.ToFloat2(), p1, s, out p1));
renderables.AddRange(DrawZap(p1, to.ToFloat2(), s, out z));
}
return renderables;

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Mods.RA
{
var a = w.CreateActor(info.Actor, new TypeDictionary
{
new LocationInit( self.Location + info.SpawnOffset ),
new LocationInit( self.Location + (CVec)info.SpawnOffset ),
new OwnerInit( self.Owner ),
new FacingInit( info.Facing ),
});

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Mods.RA
[Sync] public Actor LinkedProc = null;
[Sync] int currentUnloadTicks;
public int2? LastHarvestedCell = null;
public CPos? LastHarvestedCell = null;
[Sync] public int ContentValue { get { return contents.Sum(c => c.Key.ValuePerUnit*c.Value); } }
readonly HarvesterInfo Info;
@@ -131,7 +131,7 @@ namespace OpenRA.Mods.RA
return new Order(order.OrderID, self, queued) { TargetActor = target.Actor };
if( order.OrderID == "Harvest" )
return new Order(order.OrderID, self, queued) { TargetLocation = Util.CellContaining(target.CenterLocation) };
return new Order(order.OrderID, self, queued) { TargetLocation = target.CenterLocation.ToCPos() };
return null;
}
@@ -147,7 +147,7 @@ namespace OpenRA.Mods.RA
{
var mobile = self.Trait<Mobile>();
self.CancelActivity();
if (order.TargetLocation != int2.Zero)
if (order.TargetLocation != CPos.Zero)
{
self.QueueActivity(mobile.MoveTo(order.TargetLocation, 0));
self.SetTargetLine(Target.FromOrder(order), Color.Red);
@@ -218,7 +218,7 @@ namespace OpenRA.Mods.RA
return false;
}
public bool CanTargetLocation(Actor self, int2 location, List<Actor> actorsAtLocation, bool forceAttack, bool forceQueued, ref string cursor)
public bool CanTargetLocation(Actor self, CPos location, List<Actor> actorsAtLocation, bool forceAttack, bool forceQueued, ref string cursor)
{
// Don't leak info about resources under the shroud
if (!self.World.LocalShroud.IsExplored(location)) return false;

View File

@@ -22,22 +22,19 @@ namespace OpenRA.Mods.RA
class Husk : IOccupySpace, IFacing, ISync
{
[Sync]
int2 location;
[Sync] CPos location;
[Sync]
public int2 PxPosition { get; set; }
[Sync] public PPos PxPosition { get; set; }
[Sync]
public int Facing { get; set; }
[Sync] public int Facing { get; set; }
public int ROT { get { return 0; } }
public int InitialFacing { get { return 128; } }
public Husk(ActorInitializer init)
{
var self = init.self;
location = init.Get<LocationInit,int2>();
PxPosition = init.Get<CenterLocationInit, int2>();
location = init.Get<LocationInit, CPos>();
PxPosition = init.Get<CenterLocationInit, PPos>();
Facing = init.Contains<FacingInit>() ? init.Get<FacingInit,int>() : 128;
var speed = init.Contains<HuskSpeedInit>() ? init.Get<HuskSpeedInit,int>() : 0;
@@ -49,18 +46,18 @@ namespace OpenRA.Mods.RA
}
}
public int2 TopLeft { get { return location; } }
public CPos TopLeft { get { return location; } }
public IEnumerable<Pair<int2, SubCell>> OccupiedCells() { yield return Pair.New(TopLeft, SubCell.FullCell); }
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { yield return Pair.New(TopLeft, SubCell.FullCell); }
class DragHusk : Activity
{
Husk husk;
int2 endLocation;
int2 startLocation;
PPos endLocation;
PPos startLocation;
int length;
public DragHusk(int2 start, int2 end, int length, Husk husk)
public DragHusk(PPos start, PPos end, int length, Husk husk)
{
startLocation = start;
endLocation = end;
@@ -77,7 +74,7 @@ namespace OpenRA.Mods.RA
return NextActivity;
}
husk.PxPosition = int2.Lerp(startLocation, endLocation, ticks++, length - 1);
husk.PxPosition = PPos.Lerp(startLocation, endLocation, ticks++, length - 1);
return this;
}

View File

@@ -18,8 +18,7 @@ namespace OpenRA.Mods.RA
class IronCurtainable : IDamageModifier, ITick, ISync
{
[Sync]
int RemainingTicks = 0;
[Sync] int RemainingTicks = 0;
public void Tick(Actor self)
{

View File

@@ -24,8 +24,7 @@ namespace OpenRA.Mods.RA
public class LimitedAmmo : INotifyAttack, IPips, ISync
{
[Sync]
int ammo;
[Sync] int ammo;
LimitedAmmoInfo Info;
public LimitedAmmo(LimitedAmmoInfo info)

View File

@@ -24,13 +24,13 @@ namespace OpenRA.Mods.RA
public class MPStartLocations : IWorldLoaded
{
public Dictionary<Player, int2> Start = new Dictionary<Player, int2>();
public Dictionary<Player, CPos> Start = new Dictionary<Player, CPos>();
public void WorldLoaded(World world)
{
var taken = world.LobbyInfo.Clients.Where(c => c.SpawnPoint != 0 && c.Slot != null)
.Select(c => world.Map.GetSpawnPoints()[c.SpawnPoint-1]).ToList();
var available = world.Map.GetSpawnPoints().Except(taken).ToList();
.Select(c => (CPos) world.Map.GetSpawnPoints()[c.SpawnPoint-1]).ToList();
var available = world.Map.GetSpawnPoints().Select(c => (CPos)c).Except(taken).ToList();
// Set spawn
foreach (var kv in world.LobbyInfo.Slots)
@@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA
var client = world.LobbyInfo.ClientInSlot(kv.Key);
var spid = (client == null || client.SpawnPoint == 0)
? ChooseSpawnPoint(world, available, taken)
: world.Map.GetSpawnPoints()[client.SpawnPoint-1];
: (CPos)world.Map.GetSpawnPoints()[client.SpawnPoint-1];
Start.Add(player, spid);
}
@@ -54,7 +54,7 @@ namespace OpenRA.Mods.RA
// Set viewport
if (world.LocalPlayer != null && Start.ContainsKey(world.LocalPlayer))
Game.viewport.Center(Start[world.LocalPlayer]);
Game.viewport.Center(Start[world.LocalPlayer].ToFloat2());
}
static Player FindPlayerInSlot(World world, string pr)
@@ -62,7 +62,7 @@ namespace OpenRA.Mods.RA
return world.Players.FirstOrDefault(p => p.PlayerReference.Name == pr);
}
static int2 ChooseSpawnPoint(World world, List<int2> available, List<int2> taken)
static CPos ChooseSpawnPoint(World world, List<CPos> available, List<CPos> taken)
{
if (available.Count == 0)
throw new InvalidOperationException("No free spawnpoint.");

View File

@@ -31,13 +31,13 @@ namespace OpenRA.Mods.RA
{
readonly Actor self;
readonly MineInfo info;
[Sync] readonly int2 location;
[Sync] readonly CPos location;
public Mine(ActorInitializer init, MineInfo info)
{
this.self = init.self;
this.info = info;
this.location = init.Get<LocationInit,int2>();
this.location = init.Get<LocationInit,CPos>();
}
public void WarnCrush(Actor crusher) {}
@@ -60,10 +60,10 @@ namespace OpenRA.Mods.RA
return info.CrushClasses.Intersect(crushClasses).Any();
}
public int2 TopLeft { get { return location; } }
public CPos TopLeft { get { return location; } }
public IEnumerable<Pair<int2, SubCell>> OccupiedCells() { yield return Pair.New(TopLeft, SubCell.FullCell); }
public int2 PxPosition { get { return Util.CenterOfCell( location ); } }
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { yield return Pair.New(TopLeft, SubCell.FullCell); }
public PPos PxPosition { get { return Util.CenterOfCell( location ); } }
}
/* tag trait for stuff that shouldnt trigger mines */

View File

@@ -31,8 +31,8 @@ namespace OpenRA.Mods.RA
class Minelayer : IIssueOrder, IResolveOrder, IPostRenderSelection, ISync
{
/* [Sync] when sync can cope with arrays! */
public int2[] minefield = null;
[Sync] int2 minefieldStart;
public CPos[] minefield = null;
[Sync] CPos minefieldStart;
Actor self;
public Minelayer(Actor self) { this.self = self; }
@@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA
{
if( order is BeginMinefieldOrderTargeter )
{
var start = Traits.Util.CellContaining( target.CenterLocation );
var start = target.CenterLocation.ToCPos();
self.World.OrderGenerator = new MinefieldOrderGenerator( self, start );
return new Order("BeginMinefield", self, false) { TargetLocation = start };
}
@@ -71,34 +71,34 @@ namespace OpenRA.Mods.RA
}
}
static IEnumerable<int2> GetMinefieldCells(int2 start, int2 end, float depth)
static IEnumerable<CPos> GetMinefieldCells(CPos start, CPos end, float depth)
{
var mins = int2.Min(start, end);
var maxs = int2.Max(start, end);
var mins = CPos.Min(start, end);
var maxs = CPos.Max(start, end);
/* todo: proper endcaps, if anyone cares (which won't happen unless depth is large) */
var p = end - start;
var q = new float2(p.Y, -p.X);
q = (start != end) ? (1 / q.Length) * q : new float2(1, 0);
var c = -float2.Dot(q, start);
var c = -float2.Dot(q, start.ToFloat2());
/* return all points such that |ax + by + c| < depth */
for (var i = mins.X; i <= maxs.X; i++)
for (var j = mins.Y; j <= maxs.Y; j++)
if (Math.Abs(q.X * i + q.Y * j + c) < depth)
yield return new int2(i, j);
yield return new CPos(i, j);
}
class MinefieldOrderGenerator : IOrderGenerator
{
readonly Actor minelayer;
readonly int2 minefieldStart;
readonly CPos minefieldStart;
public MinefieldOrderGenerator(Actor self, int2 xy ) { minelayer = self; minefieldStart = xy; }
public MinefieldOrderGenerator(Actor self, CPos xy ) { minelayer = self; minefieldStart = xy; }
public IEnumerable<Order> Order(World world, int2 xy, MouseInput mi)
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)
{
if (mi.Button == MouseButton.Left)
{
@@ -124,7 +124,7 @@ namespace OpenRA.Mods.RA
world.CancelInputMode();
}
int2 lastMousePos;
CPos lastMousePos;
public void RenderAfterWorld(WorldRenderer wr, World world)
{
if (!minelayer.IsInWorld)
@@ -140,7 +140,7 @@ namespace OpenRA.Mods.RA
public void RenderBeforeWorld(WorldRenderer wr, World world) { }
public string GetCursor(World world, int2 xy, MouseInput mi) { lastMousePos = xy; return "ability"; } /* todo */
public string GetCursor(World world, CPos xy, MouseInput mi) { lastMousePos = xy; return "ability"; } /* todo */
}
public void RenderAfterWorld(WorldRenderer wr)
@@ -162,7 +162,7 @@ namespace OpenRA.Mods.RA
return false;
}
public bool CanTargetLocation(Actor self, int2 location, List<Actor> actorsAtLocation, bool forceAttack, bool forceQueued, ref string cursor)
public bool CanTargetLocation(Actor self, CPos location, List<Actor> actorsAtLocation, bool forceAttack, bool forceQueued, ref string cursor)
{
if (!self.World.Map.IsInMap(location))
return false;

View File

@@ -204,8 +204,8 @@ namespace OpenRA.Mods.RA.Missions
for (int i = 0; i < ships.Length; i++)
{
var actor = self.World.CreateActor(ships[i],
new TypeDictionary { new OwnerInit(allies), new LocationInit(shipSpawnPoint.Location + new int2(i * 2, 0)) });
actor.QueueActivity(new Move.Move(shipMovePoint.Location + new int2(i * 4, 0)));
new TypeDictionary { new OwnerInit(allies), new LocationInit(shipSpawnPoint.Location + new CVec(i * 2, 0)) });
actor.QueueActivity(new Move.Move(shipMovePoint.Location + new CVec(i * 4, 0)));
}
}

View File

@@ -21,13 +21,13 @@ namespace OpenRA.Mods.RA
class DefaultShellmapScript: IWorldLoaded, ITick
{
Dictionary<string, Actor> Actors;
static int2 ViewportOrigin;
static CPos ViewportOrigin;
public void WorldLoaded(World w)
{
var b = w.Map.Bounds;
ViewportOrigin = new int2(b.Left + b.Width/2, b.Top + b.Height/2);
Game.MoveViewport(ViewportOrigin);
ViewportOrigin = new CPos(b.Left + b.Width/2, b.Top + b.Height/2);
Game.MoveViewport(ViewportOrigin.ToFloat2());
Actors = w.WorldActor.Trait<SpawnMapActors>().Actors;
Sound.SoundVolumeModifier = 0.25f;
@@ -39,26 +39,27 @@ namespace OpenRA.Mods.RA
{
var loc = new float2(
(float)(System.Math.Sin((ticks + 45) % (360f * speed) * (Math.PI / 180) * 1f / speed) * 15f + ViewportOrigin.X),
(float)(System.Math.Cos((ticks + 45) % (360f * speed) * (Math.PI / 180) * 1f / speed) * 10f + ViewportOrigin.Y));
(float)(System.Math.Cos((ticks + 45) % (360f * speed) * (Math.PI / 180) * 1f / speed) * 10f + ViewportOrigin.Y)
);
Game.MoveViewport(loc);
if (ticks == 250)
{
Scripting.RASpecialPowers.Chronoshift(self.World, new List<Pair<Actor, int2>>()
Scripting.RASpecialPowers.Chronoshift(self.World, new List<Pair<Actor, CPos>>()
{
Pair.New(Actors["ca1"], new int2(90, 70)),
Pair.New(Actors["ca2"], new int2(92, 71))
Pair.New(Actors["ca1"], new CPos(90, 70)),
Pair.New(Actors["ca2"], new CPos(92, 71))
}, Actors["pdox"], -1, false);
}
if (ticks == 100)
Actors["mslo1"].Trait<NukePower>().Activate(Actors["mslo1"], new Order(){ TargetLocation = new int2(98, 52) });
Actors["mslo1"].Trait<NukePower>().Activate(Actors["mslo1"], new Order() { TargetLocation = new CPos(98, 52) });
if (ticks == 140)
Actors["mslo2"].Trait<NukePower>().Activate(Actors["mslo2"], new Order(){ TargetLocation = new int2(95, 54) });
Actors["mslo2"].Trait<NukePower>().Activate(Actors["mslo2"], new Order() { TargetLocation = new CPos(95, 54) });
if (ticks == 180)
Actors["mslo3"].Trait<NukePower>().Activate(Actors["mslo3"], new Order(){ TargetLocation = new int2(95, 49) });
Actors["mslo3"].Trait<NukePower>().Activate(Actors["mslo3"], new Order() { TargetLocation = new CPos(95, 49) });
if (ticks == 430)
{
@@ -70,6 +71,4 @@ namespace OpenRA.Mods.RA
ticks++;
}
}
}

View File

@@ -15,12 +15,12 @@ namespace OpenRA.Mods.RA.Move
{
public class Drag : Activity
{
int2 endLocation;
int2 startLocation;
PPos endLocation;
PPos startLocation;
int length;
int ticks = 0;
public Drag(int2 start, int2 end, int length)
public Drag(PPos start, PPos end, int length)
{
startLocation = start;
endLocation = end;
@@ -31,7 +31,7 @@ namespace OpenRA.Mods.RA.Move
{
var mobile = self.Trait<Mobile>();
mobile.PxPosition = length > 1
? int2.Lerp(startLocation, endLocation, ticks, length - 1)
? PPos.Lerp(startLocation, endLocation, ticks, length - 1)
: endLocation;
if (++ticks >= length)

View File

@@ -55,7 +55,7 @@ namespace OpenRA.Mods.RA.Move
public decimal Speed = 0;
}
public int MovementCostForCell(World world, int2 cell)
public int MovementCostForCell(World world, CPos cell)
{
if (!world.Map.IsInMap(cell.X, cell.Y))
return int.MaxValue;
@@ -67,17 +67,17 @@ namespace OpenRA.Mods.RA.Move
return TerrainSpeeds[type].Cost;
}
public readonly Dictionary<SubCell, int2> SubCellOffsets = new Dictionary<SubCell, int2>()
public readonly Dictionary<SubCell, PVecInt> SubCellOffsets = new Dictionary<SubCell, PVecInt>()
{
{SubCell.TopLeft, new int2(-7,-6)},
{SubCell.TopRight, new int2(6,-6)},
{SubCell.Center, new int2(0,0)},
{SubCell.BottomLeft, new int2(-7,6)},
{SubCell.BottomRight, new int2(6,6)},
{SubCell.FullCell, new int2(0,0)},
{SubCell.TopLeft, new PVecInt(-7,-6)},
{SubCell.TopRight, new PVecInt(6,-6)},
{SubCell.Center, new PVecInt(0,0)},
{SubCell.BottomLeft, new PVecInt(-7,6)},
{SubCell.BottomRight, new PVecInt(6,6)},
{SubCell.FullCell, new PVecInt(0,0)},
};
public bool CanEnterCell(World world, Player owner, int2 cell, Actor ignoreActor, bool checkTransientActors)
public bool CanEnterCell(World world, Player owner, CPos cell, Actor ignoreActor, bool checkTransientActors)
{
if (MovementCostForCell(world, cell) == int.MaxValue)
return false;
@@ -108,35 +108,29 @@ namespace OpenRA.Mods.RA.Move
public bool IsMoving { get; internal set; }
int __facing;
int2 __fromCell, __toCell;
CPos __fromCell, __toCell;
public SubCell fromSubCell, toSubCell;
//int __altitude;
[Sync]
public int Facing
[Sync] public int Facing
{
get { return __facing; }
set { __facing = value; }
}
[Sync]
public int Altitude { get; set; }
[Sync] public int Altitude { get; set; }
public int ROT { get { return Info.ROT; } }
public int InitialFacing { get { return Info.InitialFacing; } }
[Sync]
public int2 PxPosition { get; set; }
[Sync]
public int2 fromCell { get { return __fromCell; } }
[Sync]
public int2 toCell { get { return __toCell; } }
[Sync] public PPos PxPosition { get; set; }
[Sync] public CPos fromCell { get { return __fromCell; } }
[Sync] public CPos toCell { get { return __toCell; } }
[Sync]
public int PathHash; // written by Move.EvalPath, to temporarily debug this crap.
[Sync] public int PathHash; // written by Move.EvalPath, to temporarily debug this crap.
public void SetLocation(int2 from, SubCell fromSub, int2 to, SubCell toSub)
public void SetLocation(CPos from, SubCell fromSub, CPos to, SubCell toSub)
{
if (fromCell == from && toCell == to) return;
RemoveInfluence();
@@ -164,7 +158,7 @@ namespace OpenRA.Mods.RA.Move
if (init.Contains<LocationInit>())
{
this.__fromCell = this.__toCell = init.Get<LocationInit, int2>();
this.__fromCell = this.__toCell = init.Get<LocationInit, CPos>();
this.PxPosition = Util.CenterOfCell(fromCell) + info.SubCellOffsets[fromSubCell];
}
@@ -172,22 +166,22 @@ namespace OpenRA.Mods.RA.Move
this.Altitude = init.Contains<AltitudeInit>() ? init.Get<AltitudeInit, int>() : 0;
}
public void SetPosition(Actor self, int2 cell)
public void SetPosition(Actor self, CPos cell)
{
SetLocation(cell,fromSubCell, cell,fromSubCell);
PxPosition = Util.CenterOfCell(fromCell) + Info.SubCellOffsets[fromSubCell];
FinishedMoving(self);
}
public void SetPxPosition(Actor self, int2 px)
public void SetPxPosition(Actor self, PPos px)
{
var cell = Util.CellContaining(px);
var cell = px.ToCPos();
SetLocation(cell,fromSubCell, cell,fromSubCell);
PxPosition = px;
FinishedMoving(self);
}
public void AdjustPxPosition(Actor self, int2 px) /* visual hack only */
public void AdjustPxPosition(Actor self, PPos px) /* visual hack only */
{
PxPosition = px;
}
@@ -200,17 +194,17 @@ namespace OpenRA.Mods.RA.Move
if (order is MoveOrderTargeter)
{
if (Info.OnRails) return null;
return new Order("Move", self, queued) { TargetLocation = Util.CellContaining(target.CenterLocation) };
return new Order("Move", self, queued) { TargetLocation = target.CenterLocation.ToCPos() };
}
return null;
}
public int2 NearestMoveableCell(int2 target)
public CPos NearestMoveableCell(CPos target)
{
if (CanEnterCell(target))
return target;
var searched = new List<int2>() { };
var searched = new List<CPos>();
// Limit search to a radius of 10 tiles
for (int r = 1; r < 10; r++)
foreach (var tile in self.World.FindTilesInCircle(target, r).Except(searched))
@@ -225,9 +219,9 @@ namespace OpenRA.Mods.RA.Move
return target;
}
void PerformMoveInner(Actor self, int2 targetLocation, bool queued)
void PerformMoveInner(Actor self, CPos targetLocation, bool queued)
{
int2 currentLocation = NearestMoveableCell(targetLocation);
var currentLocation = NearestMoveableCell(targetLocation);
if (!CanEnterCell(currentLocation))
{
@@ -244,12 +238,12 @@ namespace OpenRA.Mods.RA.Move
self.SetTargetLine(Target.FromCell(currentLocation), Color.Green);
}
protected void PerformMove(Actor self, int2 targetLocation, bool queued)
protected void PerformMove(Actor self, CPos targetLocation, bool queued)
{
if (queued)
self.QueueActivity(new CallFunc(() => PerformMoveInner(self, targetLocation, queued)));
self.QueueActivity(new CallFunc(() => PerformMoveInner(self, targetLocation, true)));
else
PerformMoveInner(self, targetLocation, queued);
PerformMoveInner(self, targetLocation, false);
}
public void ResolveOrder(Actor self, Order order)
@@ -278,9 +272,9 @@ namespace OpenRA.Mods.RA.Move
}
}
public int2 TopLeft { get { return toCell; } }
public CPos TopLeft { get { return toCell; } }
public IEnumerable<Pair<int2, SubCell>> OccupiedCells()
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells()
{
if (fromCell == toCell)
yield return Pair.New(fromCell, fromSubCell);
@@ -293,7 +287,7 @@ namespace OpenRA.Mods.RA.Move
}
}
public SubCell GetDesiredSubcell(int2 a, Actor ignoreActor)
public SubCell GetDesiredSubcell(CPos a, Actor ignoreActor)
{
if (!Info.SharesCell)
return SubCell.FullCell;
@@ -303,7 +297,7 @@ namespace OpenRA.Mods.RA.Move
SubCell.BottomLeft, SubCell.BottomRight}.First(b =>
{
var blockingActors = self.World.ActorMap.GetUnitsAt(a,b).Where(c => c != ignoreActor);
if (blockingActors.Count() > 0)
if (blockingActors.Any())
{
// Non-sharable unit can enter a cell with shareable units only if it can crush all of them
if (Info.Crushes == null)
@@ -317,12 +311,12 @@ namespace OpenRA.Mods.RA.Move
});
}
public bool CanEnterCell(int2 p)
public bool CanEnterCell(CPos p)
{
return CanEnterCell(p, null, true);
}
public bool CanEnterCell(int2 cell, Actor ignoreActor, bool checkTransientActors)
public bool CanEnterCell(CPos cell, Actor ignoreActor, bool checkTransientActors)
{
return Info.CanEnterCell(self.World, self.Owner, cell, ignoreActor, checkTransientActors);
}
@@ -349,7 +343,7 @@ namespace OpenRA.Mods.RA.Move
}
}
public int MovementSpeedForCell(Actor self, int2 cell)
public int MovementSpeedForCell(Actor self, CPos cell)
{
var type = self.World.GetTerrainType(cell);
@@ -385,13 +379,13 @@ namespace OpenRA.Mods.RA.Move
return; /* don't nudge if we're busy doing something! */
// pick an adjacent available cell.
var availCells = new List<int2>();
var notStupidCells = new List<int2>();
var availCells = new List<CPos>();
var notStupidCells = new List<CPos>();
for (var i = -1; i < 2; i++)
for (var j = -1; j < 2; j++)
{
var p = toCell + new int2(i, j);
var p = toCell + new CVec(i, j);
if (CanEnterCell(p))
availCells.Add(p);
else
@@ -400,7 +394,7 @@ namespace OpenRA.Mods.RA.Move
}
var moveTo = availCells.Any() ? availCells.Random(self.World.SharedRandom) :
notStupidCells.Any() ? notStupidCells.Random(self.World.SharedRandom) : (int2?)null;
notStupidCells.Any() ? notStupidCells.Random(self.World.SharedRandom) : (CPos?)null;
if (moveTo.HasValue)
{
@@ -434,7 +428,7 @@ namespace OpenRA.Mods.RA.Move
return false;
}
public bool CanTargetLocation(Actor self, int2 location, List<Actor> actorsAtLocation, bool forceAttack, bool forceQueued, ref string cursor)
public bool CanTargetLocation(Actor self, CPos location, List<Actor> actorsAtLocation, bool forceAttack, bool forceQueued, ref string cursor)
{
IsQueued = forceQueued;
cursor = "move";
@@ -446,10 +440,10 @@ namespace OpenRA.Mods.RA.Move
}
}
public Activity ScriptedMove(int2 cell) { return new Move(cell); }
public Activity MoveTo(int2 cell, int nearEnough) { return new Move(cell, nearEnough); }
public Activity MoveTo(int2 cell, Actor ignoredActor) { return new Move(cell, ignoredActor); }
public Activity ScriptedMove(CPos cell) { return new Move(cell); }
public Activity MoveTo(CPos cell, int nearEnough) { return new Move(cell, nearEnough); }
public Activity MoveTo(CPos cell, Actor ignoredActor) { return new Move(cell, ignoredActor); }
public Activity MoveWithinRange(Target target, int range) { return new Move(target, range); }
public Activity MoveTo(Func<List<int2>> pathFunc) { return new Move(pathFunc); }
public Activity MoveTo(Func<List<CPos>> pathFunc) { return new Move(pathFunc); }
}
}

View File

@@ -20,15 +20,15 @@ namespace OpenRA.Mods.RA.Move
{
class Move : Activity
{
int2? destination;
CPos? destination;
int nearEnough;
public List<int2> path;
Func<Actor, Mobile, List<int2>> getPath;
public List<CPos> path;
Func<Actor, Mobile, List<CPos>> getPath;
public Actor ignoreBuilding;
// Scriptable move order
// Ignores lane bias and nearby units
public Move( int2 destination )
public Move(CPos destination)
{
this.getPath = (self,mobile) =>
self.World.WorldActor.Trait<PathFinder>().FindPath(
@@ -38,14 +38,14 @@ namespace OpenRA.Mods.RA.Move
this.nearEnough = 0;
}
public Move( int2 destination, int nearEnough )
public Move(CPos destination, int nearEnough)
{
this.getPath = (self,mobile) => self.World.WorldActor.Trait<PathFinder>().FindUnitPath( mobile.toCell, destination, self );
this.destination = destination;
this.nearEnough = nearEnough;
}
public Move(int2 destination, Actor ignoreBuilding)
public Move(CPos destination, Actor ignoreBuilding)
{
this.getPath = (self,mobile) =>
self.World.WorldActor.Trait<PathFinder>().FindPath(
@@ -60,13 +60,13 @@ namespace OpenRA.Mods.RA.Move
public Move(Target target, int range)
{
this.getPath = (self,mobile) => self.World.WorldActor.Trait<PathFinder>().FindUnitPathToRange(
mobile.toCell, Util.CellContaining(target.CenterLocation),
mobile.toCell, target.CenterLocation.ToCPos(),
range, self);
this.destination = null;
this.nearEnough = range;
}
public Move(Func<List<int2>> getPath)
public Move(Func<List<CPos>> getPath)
{
this.getPath = (_1,_2) => getPath();
this.destination = null;
@@ -83,7 +83,7 @@ namespace OpenRA.Mods.RA.Move
return hash;
}
List<int2> EvalPath( Actor self, Mobile mobile )
List<CPos> EvalPath(Actor self, Mobile mobile)
{
var path = getPath(self, mobile).TakeWhile(a => a != mobile.toCell).ToList();
mobile.PathHash = HashList(path);
@@ -131,7 +131,7 @@ namespace OpenRA.Mods.RA.Move
if( nextCell == null )
return this;
int2 dir = nextCell.Value.First - mobile.fromCell;
var dir = nextCell.Value.First - mobile.fromCell;
var firstFacing = Util.GetFacing( dir, mobile.Facing );
if( firstFacing != mobile.Facing )
{
@@ -167,7 +167,7 @@ namespace OpenRA.Mods.RA.Move
bool hasNudged;
int waitTicksRemaining;
void NudgeBlocker(Actor self, int2 nextCell)
void NudgeBlocker(Actor self, CPos nextCell)
{
var blocker = self.World.ActorMap.GetUnitsAt(nextCell).FirstOrDefault();
if (blocker == null) return;
@@ -180,7 +180,7 @@ namespace OpenRA.Mods.RA.Move
nudge.OnNudge(blocker, self, false);
}
Pair<int2, SubCell>? PopPath( Actor self, Mobile mobile )
Pair<CPos, SubCell>? PopPath(Actor self, Mobile mobile)
{
if( path.Count == 0 ) return null;
var nextCell = path[ path.Count - 1 ];
@@ -233,7 +233,7 @@ namespace OpenRA.Mods.RA.Move
public override void Cancel( Actor self )
{
path = new List<int2>();
path = new List<CPos>();
base.Cancel(self);
}
@@ -242,19 +242,19 @@ namespace OpenRA.Mods.RA.Move
if( path != null )
return Enumerable.Reverse(path).Select( c => Target.FromCell(c) );
if( destination != null )
return new Target[] { Target.FromPos(destination.Value) };
return new Target[] { Target.FromCell(destination.Value) };
return Target.NoTargets;
}
abstract class MovePart : Activity
{
public readonly Move move;
public readonly int2 from, to;
public readonly PPos from, to;
public readonly int fromFacing, toFacing;
public int moveFraction;
public readonly int moveFractionTotal;
public MovePart( Move move, int2 from, int2 to, int fromFacing, int toFacing, int startingFraction )
public MovePart(Move move, PPos from, PPos to, int fromFacing, int toFacing, int startingFraction)
{
this.move = move;
this.from = from;
@@ -304,7 +304,7 @@ namespace OpenRA.Mods.RA.Move
void UpdateCenterLocation( Actor self, Mobile mobile )
{
mobile.PxPosition = int2.Lerp( from, to, moveFraction, moveFractionTotal );
mobile.PxPosition = PPos.Lerp(from, to, moveFraction, moveFractionTotal);
if( moveFraction >= moveFractionTotal )
mobile.Facing = toFacing & 0xFF;
@@ -322,10 +322,10 @@ namespace OpenRA.Mods.RA.Move
class MoveFirstHalf : MovePart
{
public MoveFirstHalf( Move move, int2 from, int2 to, int fromFacing, int toFacing, int startingFraction )
public MoveFirstHalf(Move move, PPos from, PPos to, int fromFacing, int toFacing, int startingFraction)
: base( move, from, to, fromFacing, toFacing, startingFraction ) { }
static bool IsTurn( Mobile mobile, int2 nextCell )
static bool IsTurn( Mobile mobile, CPos nextCell )
{
return nextCell - mobile.toCell !=
mobile.toCell - mobile.fromCell;
@@ -373,7 +373,7 @@ namespace OpenRA.Mods.RA.Move
class MoveSecondHalf : MovePart
{
public MoveSecondHalf( Move move, int2 from, int2 to, int fromFacing, int toFacing, int startingFraction )
public MoveSecondHalf(Move move, PPos from, PPos to, int fromFacing, int toFacing, int startingFraction)
: base( move, from, to, fromFacing, toFacing, startingFraction )
{
}

View File

@@ -29,9 +29,9 @@ namespace OpenRA.Mods.RA.Move
class CachedPath
{
public int2 from;
public int2 to;
public List<int2> result;
public CPos from;
public CPos to;
public List<CPos> result;
public int tick;
public Actor actor;
}
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.RA.Move
List<CachedPath> CachedPaths = new List<CachedPath>();
const int MaxPathAge = 50; /* x 40ms ticks */
public List<int2> FindUnitPath(int2 from, int2 target, Actor self)
public List<CPos> FindUnitPath(CPos from, CPos target, Actor self)
{
using (new PerfSample("Pathfinder"))
{
@@ -48,25 +48,25 @@ namespace OpenRA.Mods.RA.Move
{
Log.Write("debug", "Actor {0} asked for a path from {1} tick(s) ago", self.ActorID, world.FrameNumber - cached.tick);
cached.tick = world.FrameNumber;
return new List<int2>(cached.result);
return new List<CPos>(cached.result);
}
var mi = self.Info.Traits.Get<MobileInfo>();
var pb = FindBidiPath(
PathSearch.FromPoint(world, mi, self.Owner, target, from, true),
PathSearch.FromPoint(world, mi, self.Owner, from, target, true)
.InReverse());
PathSearch.FromPoint(world, mi, self.Owner, from, target, true).InReverse()
);
CheckSanePath2(pb, from, target);
CachedPaths.RemoveAll(p => world.FrameNumber - p.tick > MaxPathAge);
CachedPaths.Add(new CachedPath { from = from, to = target, actor = self, result = pb, tick = world.FrameNumber });
return new List<int2>(pb);
return new List<CPos>(pb);
}
}
public List<int2> FindUnitPathToRange( int2 src, int2 target, int range, Actor self )
public List<CPos> FindUnitPathToRange(CPos src, CPos target, int range, Actor self)
{
using( new PerfSample( "Pathfinder" ) )
{
@@ -76,18 +76,18 @@ namespace OpenRA.Mods.RA.Move
var path = FindBidiPath(
PathSearch.FromPoints(world, mi, self.Owner, tilesInRange, src, true),
PathSearch.FromPoint(world, mi, self.Owner, src, target, true)
.InReverse());
PathSearch.FromPoint(world, mi, self.Owner, src, target, true).InReverse()
);
return path;
}
}
public List<int2> FindPath( PathSearch search )
public List<CPos> FindPath(PathSearch search)
{
using (new PerfSample("Pathfinder"))
{
using(search)
using (search)
while (!search.queue.Empty)
{
var p = search.Expand(world);
@@ -96,14 +96,14 @@ namespace OpenRA.Mods.RA.Move
}
// no path exists
return new List<int2>();
return new List<CPos>(0);
}
}
static List<int2> MakePath( CellInfo[ , ] cellInfo, int2 destination )
static List<CPos> MakePath(CellInfo[,] cellInfo, CPos destination)
{
List<int2> ret = new List<int2>();
int2 pathNode = destination;
var ret = new List<CPos>();
CPos pathNode = destination;
while( cellInfo[ pathNode.X, pathNode.Y ].Path != pathNode )
{
@@ -116,9 +116,7 @@ namespace OpenRA.Mods.RA.Move
return ret;
}
public List<int2> FindBidiPath( /* searches from both ends toward each other */
public List<CPos> FindBidiPath( /* searches from both ends toward each other */
PathSearch fromSrc,
PathSearch fromDest)
{
@@ -141,16 +139,16 @@ namespace OpenRA.Mods.RA.Move
return MakeBidiPath(fromSrc, fromDest, q);
}
return new List<int2>();
return new List<CPos>(0);
}
}
static List<int2> MakeBidiPath(PathSearch a, PathSearch b, int2 p)
static List<CPos> MakeBidiPath(PathSearch a, PathSearch b, CPos p)
{
var ca = a.cellInfo;
var cb = b.cellInfo;
var ret = new List<int2>();
var ret = new List<CPos>();
var q = p;
while (ca[q.X, q.Y].Path != q)
@@ -174,7 +172,7 @@ namespace OpenRA.Mods.RA.Move
}
[Conditional( "SANITY_CHECKS" )]
static void CheckSanePath( List<int2> path )
static void CheckSanePath(List<CPos> path)
{
if( path.Count == 0 )
return;
@@ -189,7 +187,7 @@ namespace OpenRA.Mods.RA.Move
}
[Conditional("SANITY_CHECKS")]
static void CheckSanePath2(List<int2> path, int2 src, int2 dest)
static void CheckSanePath2(List<CPos> path, CPos src, CPos dest)
{
if (path.Count == 0)
return;
@@ -204,10 +202,10 @@ namespace OpenRA.Mods.RA.Move
public struct CellInfo
{
public int MinCost;
public int2 Path;
public CPos Path;
public bool Seen;
public CellInfo( int minCost, int2 path, bool seen )
public CellInfo(int minCost, CPos path, bool seen)
{
MinCost = minCost;
Path = path;
@@ -218,9 +216,9 @@ namespace OpenRA.Mods.RA.Move
public struct PathDistance : IComparable<PathDistance>
{
public int EstTotal;
public int2 Location;
public CPos Location;
public PathDistance(int estTotal, int2 location)
public PathDistance(int estTotal, CPos location)
{
EstTotal = estTotal;
Location = location;

View File

@@ -20,8 +20,8 @@ namespace OpenRA.Mods.RA.Move
World world;
public CellInfo[ , ] cellInfo;
public PriorityQueue<PathDistance> queue;
public Func<int2, int> heuristic;
Func<int2, bool> customBlock;
public Func<CPos, int> heuristic;
Func<CPos, bool> customBlock;
public bool checkForBlocked;
public Actor ignoreBuilding;
public bool inReverse;
@@ -44,7 +44,7 @@ namespace OpenRA.Mods.RA.Move
return this;
}
public PathSearch WithCustomBlocker(Func<int2, bool> customBlock)
public PathSearch WithCustomBlocker(Func<CPos, bool> customBlock)
{
this.customBlock = customBlock;
return this;
@@ -56,7 +56,7 @@ namespace OpenRA.Mods.RA.Move
return this;
}
public PathSearch WithHeuristic(Func<int2, int> h)
public PathSearch WithHeuristic(Func<CPos, int> h)
{
heuristic = h;
return this;
@@ -68,7 +68,7 @@ namespace OpenRA.Mods.RA.Move
return this;
}
public PathSearch FromPoint(int2 from)
public PathSearch FromPoint(CPos from)
{
AddInitialCell( from );
return this;
@@ -76,7 +76,7 @@ namespace OpenRA.Mods.RA.Move
int LaneBias = 1;
public int2 Expand( World world )
public CPos Expand(World world)
{
var p = queue.Pop();
while (cellInfo[p.Location.X, p.Location.Y].Seen)
@@ -92,9 +92,9 @@ namespace OpenRA.Mods.RA.Move
if (thisCost == int.MaxValue)
return p.Location;
foreach( int2 d in directions )
foreach( CVec d in directions )
{
int2 newHere = p.Location + d;
CPos newHere = p.Location + d;
if (!world.Map.IsInMap(newHere.X, newHere.Y)) continue;
if( cellInfo[ newHere.X, newHere.Y ].Seen )
@@ -141,19 +141,19 @@ namespace OpenRA.Mods.RA.Move
return p.Location;
}
static readonly int2[] directions =
static readonly CVec[] directions =
{
new int2( -1, -1 ),
new int2( -1, 0 ),
new int2( -1, 1 ),
new int2( 0, -1 ),
new int2( 0, 1 ),
new int2( 1, -1 ),
new int2( 1, 0 ),
new int2( 1, 1 ),
new CVec( -1, -1 ),
new CVec( -1, 0 ),
new CVec( -1, 1 ),
new CVec( 0, -1 ),
new CVec( 0, 1 ),
new CVec( 1, -1 ),
new CVec( 1, 0 ),
new CVec( 1, 1 ),
};
public void AddInitialCell( int2 location )
public void AddInitialCell(CPos location)
{
if (!world.Map.IsInMap(location.X, location.Y))
return;
@@ -169,7 +169,7 @@ namespace OpenRA.Mods.RA.Move
return search;
}
public static PathSearch FromPoint( World world, MobileInfo mi, Player owner, int2 from, int2 target, bool checkForBlocked )
public static PathSearch FromPoint(World world, MobileInfo mi, Player owner, CPos from, CPos target, bool checkForBlocked)
{
var search = new PathSearch(world, mi, owner) {
heuristic = DefaultEstimator( target ),
@@ -179,7 +179,7 @@ namespace OpenRA.Mods.RA.Move
return search;
}
public static PathSearch FromPoints(World world, MobileInfo mi, Player owner, IEnumerable<int2> froms, int2 target, bool checkForBlocked)
public static PathSearch FromPoints(World world, MobileInfo mi, Player owner, IEnumerable<CPos> froms, CPos target, bool checkForBlocked)
{
var search = new PathSearch(world, mi, owner)
{
@@ -229,16 +229,16 @@ namespace OpenRA.Mods.RA.Move
for( int x = 0 ; x < world.Map.MapSize.X ; x++ )
for( int y = 0 ; y < world.Map.MapSize.Y ; y++ )
result[ x, y ] = new CellInfo( int.MaxValue, new int2( x, y ), false );
result[ x, y ] = new CellInfo( int.MaxValue, new CPos( x, y ), false );
return result;
}
public static Func<int2, int> DefaultEstimator( int2 destination )
public static Func<CPos, int> DefaultEstimator(CPos destination)
{
return here =>
{
int2 d = ( here - destination ).Abs();
CVec d = (here - destination).Abs();
int diag = Math.Min( d.X, d.Y );
int straight = Math.Abs( d.X - d.Y );
return (3400 * diag / 24) + (100 * straight);

View File

@@ -42,7 +42,7 @@ namespace OpenRA.Mods.RA.Orders
return self == target;
}
public bool CanTargetLocation(Actor self, int2 location, List<Actor> actorsAtLocation, bool forceAttack, bool forceQueued, ref string cursor)
public bool CanTargetLocation(Actor self, CPos location, List<Actor> actorsAtLocation, bool forceAttack, bool forceQueued, ref string cursor)
{
return false;
}

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Mods.RA.Orders
buildBlocked = SequenceProvider.GetSequence("overlay", "build-invalid").GetSprite(0);
}
public IEnumerable<Order> Order(World world, int2 xy, MouseInput mi)
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)
{
if (mi.Button == MouseButton.Right)
world.CancelInputMode();
@@ -50,7 +50,7 @@ namespace OpenRA.Mods.RA.Orders
return ret;
}
IEnumerable<Order> InnerOrder(World world, int2 xy, MouseInput mi)
IEnumerable<Order> InnerOrder(World world, CPos xy, MouseInput mi)
{
if (mi.Button == MouseButton.Left)
{
@@ -73,14 +73,14 @@ namespace OpenRA.Mods.RA.Orders
public void RenderAfterWorld( WorldRenderer wr, World world ) {}
public void RenderBeforeWorld( WorldRenderer wr, World world )
{
var position = Game.viewport.ViewToWorld(Viewport.LastMousePos).ToInt2();
var position = Game.viewport.ViewToWorld(Viewport.LastMousePos);
var topLeft = position - FootprintUtils.AdjustForBuildingSize( BuildingInfo );
var actorInfo = Rules.Info[Building];
foreach (var dec in actorInfo.Traits.WithInterface<IPlaceBuildingDecoration>())
dec.Render(wr, world, actorInfo, Traits.Util.CenterOfCell(position)); /* hack hack */
var cells = new Dictionary<int2, bool>();
var cells = new Dictionary<CPos, bool>();
// Linebuild for walls.
// Assumes a 1x1 footprint; weird things will happen for other footprints
if (Rules.Info[Building].Traits.Contains<LineBuildInfo>())
@@ -91,7 +91,7 @@ namespace OpenRA.Mods.RA.Orders
else
{
foreach (var r in Preview)
r.Sprite.DrawAt(Game.CellSize*topLeft + r.Pos,
r.Sprite.DrawAt(topLeft.ToPPos().ToFloat2() + r.Pos,
wr.GetPaletteIndex(r.Palette),
r.Scale*r.Sprite.size);
@@ -102,9 +102,9 @@ namespace OpenRA.Mods.RA.Orders
}
foreach( var c in cells )
( c.Value ? buildOk : buildBlocked ).DrawAt( wr, Game.CellSize * c.Key, "terrain" );
( c.Value ? buildOk : buildBlocked ).DrawAt(wr, c.Key.ToPPos().ToFloat2(), "terrain" );
}
public string GetCursor(World world, int2 xy, MouseInput mi) { return "default"; }
public string GetCursor(World world, CPos xy, MouseInput mi) { return "default"; }
}
}

View File

@@ -27,7 +27,7 @@ namespace OpenRA.Mods.RA.Orders
this.order = order;
}
public IEnumerable<Order> Order(World world, int2 xy, MouseInput mi)
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)
{
if (mi.Button == MouseButton.Right)
world.CancelInputMode();
@@ -35,7 +35,7 @@ namespace OpenRA.Mods.RA.Orders
return OrderInner(world, xy, mi);
}
IEnumerable<Order> OrderInner(World world, int2 xy, MouseInput mi)
IEnumerable<Order> OrderInner(World world, CPos xy, MouseInput mi)
{
if (mi.Button == MouseButton.Left)
{
@@ -58,7 +58,7 @@ namespace OpenRA.Mods.RA.Orders
public void RenderAfterWorld(WorldRenderer wr, World world) { }
public void RenderBeforeWorld(WorldRenderer wr, World world) { }
public string GetCursor(World world, int2 xy, MouseInput mi)
public string GetCursor(World world, CPos xy, MouseInput mi)
{
mi.Button = MouseButton.Left;
return cursor + (OrderInner(world, xy, mi).Any() ? "" : "-blocked");

View File

@@ -18,7 +18,7 @@ namespace OpenRA.Mods.RA.Orders
{
public class RepairOrderGenerator : IOrderGenerator
{
public IEnumerable<Order> Order(World world, int2 xy, MouseInput mi)
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)
{
if (mi.Button == MouseButton.Right)
world.CancelInputMode();
@@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Orders
return OrderInner(world, xy, mi);
}
IEnumerable<Order> OrderInner(World world, int2 xy, MouseInput mi)
IEnumerable<Order> OrderInner(World world, CPos xy, MouseInput mi)
{
if (mi.Button == MouseButton.Left)
{
@@ -52,7 +52,7 @@ namespace OpenRA.Mods.RA.Orders
public void RenderAfterWorld(WorldRenderer wr, World world) { }
public void RenderBeforeWorld(WorldRenderer wr, World world) { }
public string GetCursor(World world, int2 xy, MouseInput mi)
public string GetCursor(World world, CPos xy, MouseInput mi)
{
mi.Button = MouseButton.Left;
return OrderInner(world, xy, mi).Any()

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA.Orders
this.self = self;
}
public IEnumerable<Order> Order(World world, int2 xy, MouseInput mi)
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)
{
if (mi.Button == MouseButton.Left)
{
@@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA.Orders
public void RenderBeforeWorld( WorldRenderer wr, World world ) { }
public string GetCursor(World world, int2 xy, MouseInput mi)
public string GetCursor(World world, CPos xy, MouseInput mi)
{
if (!world.LocalPlayer.Shroud.IsExplored(xy))
return "move-blocked";

View File

@@ -50,7 +50,7 @@ namespace OpenRA.Mods.RA.Orders
return true;
}
public virtual bool CanTargetLocation(Actor self, int2 location, List<Actor> actorsAtLocation, bool forceAttack, bool forceQueued, ref string cursor)
public virtual bool CanTargetLocation(Actor self, CPos location, List<Actor> actorsAtLocation, bool forceAttack, bool forceQueued, ref string cursor)
{
return false;
}

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Mods.RA
[Sync] bool preventDock = false;
public bool AllowDocking { get { return !preventDock; } }
public int2 DeliverOffset { get { return Info.DockOffset; } }
public CVec DeliverOffset { get { return (CVec)Info.DockOffset; } }
public virtual Activity DockSequence(Actor harv, Actor self) { return new RAHarvesterDockSequence(harv, self); }

View File

@@ -24,10 +24,10 @@ namespace OpenRA.Mods.RA
public class ParaDrop : ITick
{
readonly List<int2> droppedAt = new List<int2>();
int2 lz;
readonly List<CPos> droppedAt = new List<CPos>();
CPos lz;
public void SetLZ(int2 lz)
public void SetLZ(CPos lz)
{
this.lz = lz;
droppedAt.Clear();
@@ -55,16 +55,19 @@ namespace OpenRA.Mods.RA
var aircraft = self.Trait<IMove>();
self.World.AddFrameEndTask(w => w.Add(
new Parachute(self.Owner,
Util.CenterOfCell(Util.CellContaining(self.CenterLocation)),
aircraft.Altitude, a)));
new Parachute(
self.Owner,
Util.CenterOfCell(self.CenterLocation.ToCPos()),
aircraft.Altitude, a
)
));
Sound.Play(info.ChuteSound, self.CenterLocation);
}
}
}
bool IsSuitableCell(Actor actorToDrop, int2 p)
bool IsSuitableCell(Actor actorToDrop, CPos p)
{
return actorToDrop.Trait<ITeleportable>().CanEnterCell(p);
}

View File

@@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA
BaseAttackNotifierInfo info;
public int lastAttackTime = -1;
public float2 lastAttackLocation;
public CPos lastAttackLocation;
public BaseAttackNotifier(BaseAttackNotifierInfo info) { this.info = info; }
@@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA
if (self.World.FrameNumber - lastAttackTime > info.NotifyInterval * 25)
Sound.PlayToPlayer(self.Owner, info.Audio);
lastAttackLocation = self.CenterLocation / Game.CellSize;
lastAttackLocation = self.CenterLocation.ToCPos();
lastAttackTime = self.World.FrameNumber;
}
}

View File

@@ -44,18 +44,12 @@ namespace OpenRA.Mods.RA
// A list of things we are currently building
public List<ProductionItem> Queue = new List<ProductionItem>();
[Sync]
public int QueueLength { get { return Queue.Count; } }
[Sync]
public int CurrentRemainingCost { get { return QueueLength == 0 ? 0 : Queue[0].RemainingCost; } }
[Sync]
public int CurrentRemainingTime { get { return QueueLength == 0 ? 0 : Queue[0].RemainingTime; } }
[Sync]
public int CurrentSlowdown { get { return QueueLength == 0 ? 0 : Queue[0].slowdown; } }
[Sync]
public bool CurrentPaused { get { return QueueLength == 0 ? false : Queue[0].Paused; } }
[Sync]
public bool CurrentDone { get { return QueueLength == 0 ? false : Queue[0].Done; } }
[Sync] public int QueueLength { get { return Queue.Count; } }
[Sync] public int CurrentRemainingCost { get { return QueueLength == 0 ? 0 : Queue[0].RemainingCost; } }
[Sync] public int CurrentRemainingTime { get { return QueueLength == 0 ? 0 : Queue[0].RemainingTime; } }
[Sync] public int CurrentSlowdown { get { return QueueLength == 0 ? 0 : Queue[0].slowdown; } }
[Sync] public bool CurrentPaused { get { return QueueLength == 0 ? false : Queue[0].Paused; } }
[Sync] public bool CurrentDone { get { return QueueLength == 0 ? false : Queue[0].Done; } }
// A list of things we could possibly build, even if our race doesn't normally get it
public Dictionary<ActorInfo, ProductionState> Produceable;

View File

@@ -27,9 +27,12 @@ namespace OpenRA.Mods.RA
public class ExitInfo : TraitInfo<Exit>
{
public readonly int2 SpawnOffset = int2.Zero; // in px relative to CenterLocation
public readonly int2 ExitCell = int2.Zero; // in cells relative to TopLeft
public readonly int2 SpawnOffset = int2.Zero; // in px relative to CenterLocation
public readonly int2 ExitCell = int2.Zero; // in cells relative to TopLeft
public readonly int Facing = -1;
public PVecInt SpawnOffsetVector { get { return (PVecInt)SpawnOffset; } }
public CVec ExitCellVector { get { return (CVec)ExitCell; } }
}
public class Exit {}
@@ -48,8 +51,8 @@ namespace OpenRA.Mods.RA
new OwnerInit( self.Owner ),
});
var exit = self.Location + exitinfo.ExitCell;
var spawn = self.Trait<IHasLocation>().PxPosition + exitinfo.SpawnOffset;
var exit = self.Location + exitinfo.ExitCellVector;
var spawn = self.Trait<IHasLocation>().PxPosition + exitinfo.SpawnOffsetVector;
var teleportable = newUnit.Trait<ITeleportable>();
var facing = newUnit.TraitOrDefault<IFacing>();
@@ -78,7 +81,7 @@ namespace OpenRA.Mods.RA
t.UnitProduced(self, newUnit, exit);
}
static int2 MoveToRallyPoint(Actor self, Actor newUnit, int2 exitLocation)
static CPos MoveToRallyPoint(Actor self, Actor newUnit, CPos exitLocation)
{
var rp = self.TraitOrDefault<RallyPoint>();
if (rp == null)
@@ -126,7 +129,7 @@ namespace OpenRA.Mods.RA
var mobileInfo = producee.Traits.GetOrDefault<MobileInfo>();
return mobileInfo == null ||
mobileInfo.CanEnterCell(self.World, self.Owner, self.Location + s.ExitCell, self, true);
mobileInfo.CanEnterCell(self.World, self.Owner, self.Location + s.ExitCellVector, self, true);
}
}
}

View File

@@ -23,12 +23,12 @@ namespace OpenRA.Mods.RA
public class RallyPoint : IIssueOrder, IResolveOrder, ISync
{
[Sync] public int2 rallyPoint;
[Sync] public CPos rallyPoint;
public RallyPoint(Actor self)
{
var info = self.Info.Traits.Get<RallyPointInfo>();
rallyPoint = self.Location + new int2(info.RallyPoint[0], info.RallyPoint[1]);
rallyPoint = self.Location + new CVec(info.RallyPoint[0], info.RallyPoint[1]);
self.World.AddFrameEndTask(w => w.Add(new Effects.RallyPoint(self)));
}
@@ -40,7 +40,7 @@ namespace OpenRA.Mods.RA
public Order IssueOrder( Actor self, IOrderTargeter order, Target target, bool queued )
{
if( order.OrderID == "SetRallyPoint" )
return new Order(order.OrderID, self, false) { TargetLocation = Traits.Util.CellContaining(target.CenterLocation) };
return new Order(order.OrderID, self, false) { TargetLocation = target.CenterLocation.ToCPos() };
return null;
}
@@ -61,7 +61,7 @@ namespace OpenRA.Mods.RA
return false;
}
public bool CanTargetLocation(Actor self, int2 location, List<Actor> actorsAtLocation, bool forceAttack, bool forceQueued, ref string cursor)
public bool CanTargetLocation(Actor self, CPos location, List<Actor> actorsAtLocation, bool forceAttack, bool forceQueued, ref string cursor)
{
if (self.World.Map.IsInMap(location))
{

View File

@@ -56,8 +56,7 @@ namespace OpenRA.Mods.RA.Render
if (!hasTicked)
{
var oneCell = new int2(Game.CellSize, Game.CellSize);
var adjWalls = self.World.FindUnits(self.CenterLocation - oneCell, self.CenterLocation + oneCell)
var adjWalls = self.World.FindUnits(self.CenterLocation - PVecInt.OneCell, self.CenterLocation + PVecInt.OneCell)
.Where(a => a.Info == self.Info && a != self);
foreach (var w in adjWalls)
@@ -69,12 +68,12 @@ namespace OpenRA.Mods.RA.Render
}
}
void AddAdjacentWall(int2 location, int2 otherLocation)
void AddAdjacentWall(CPos location, CPos otherLocation)
{
if (otherLocation == location + new int2(0, -1)) adjacentWalls |= 1;
if (otherLocation == location + new int2(+1, 0)) adjacentWalls |= 2;
if (otherLocation == location + new int2(0, +1)) adjacentWalls |= 4;
if (otherLocation == location + new int2(-1, 0)) adjacentWalls |= 8;
if (otherLocation == location + new CVec(0, -1)) adjacentWalls |= 1;
if (otherLocation == location + new CVec(+1, 0)) adjacentWalls |= 2;
if (otherLocation == location + new CVec(0, +1)) adjacentWalls |= 4;
if (otherLocation == location + new CVec(-1, 0)) adjacentWalls |= 8;
}
}
}

View File

@@ -42,7 +42,7 @@ namespace OpenRA.Mods.RA.Render
{
Animation roof;
[Sync] bool isOpen;
[Sync] int2 openExit;
[Sync] CPos openExit;
bool buildComplete;
public RenderBuildingWarFactory(ActorInitializer init, RenderBuildingInfo info)
@@ -64,8 +64,7 @@ namespace OpenRA.Mods.RA.Render
public override void Tick(Actor self)
{
base.Tick(self);
if (isOpen && !self.World.ActorMap.GetUnitsAt(openExit)
.Any( a => a != self ))
if (isOpen && !self.World.ActorMap.GetUnitsAt(openExit).Any( a => a != self ))
{
isOpen = false;
roof.PlayBackwardsThen(NormalizeSequence(self, "build-top"),
@@ -86,7 +85,7 @@ namespace OpenRA.Mods.RA.Render
base.DamageStateChanged(self, e);
}
public void UnitProduced(Actor self, Actor other, int2 exit)
public void UnitProduced(Actor self, Actor other, CPos exit)
{
roof.PlayThen(NormalizeSequence(self, "build-top"), () => { isOpen = true; openExit = exit; });
}

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Mods.RA.Render
anims.Add("spinner", new AnimationWithOffset(
spinnerAnim,
() => Combat.GetTurretPosition( self, facing, new Turret(info.Offset)),
() => Combat.GetTurretPosition( self, facing, new Turret(info.Offset)).ToFloat2(),
null ) { ZOffset = 1 } );
}
}

View File

@@ -35,7 +35,7 @@ namespace OpenRA.Mods.RA.Render
var turret = attack.Turrets[i];
anims.Add( "turret_{0}".F(i),
new AnimationWithOffset( turretAnim,
() => Combat.GetTurretPosition( self, facing, turret ),
() => Combat.GetTurretPosition( self, facing, turret ).ToFloat2(),
null));
}
}

View File

@@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA.Render
muzzleFlashes.Add("muzzle{0}".F(muzzleFlashes.Count), new AnimationWithOffset(
muzzleFlash,
() => Combat.GetBarrelPosition(self, facing, turret, barrel),
() => Combat.GetBarrelPosition(self, facing, turret, barrel).ToFloat2(),
() => !isShowing));
}
}

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA.Render
rotorAnim.PlayRepeating("rotor");
rs.anims.Add(info.Id, new AnimationWithOffset(
rotorAnim,
() => Combat.GetTurretPosition( self, facing, new Turret(info.Offset)),
() => Combat.GetTurretPosition( self, facing, new Turret(info.Offset)).ToFloat2(),
null ) { ZOffset = 1 } );
}

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA
wr.DrawRangeCircle(
Color.FromArgb(128, Color.LimeGreen),
self.CenterLocation, self.Info.Traits.Get<DetectCloakedInfo>().Range);
self.CenterLocation.ToFloat2(), self.Info.Traits.Get<DetectCloakedInfo>().Range);
}
}
}

View File

@@ -16,18 +16,18 @@ namespace OpenRA.Mods.RA
{
public interface IPlaceBuildingDecoration
{
void Render(WorldRenderer wr, World w, ActorInfo ai, int2 centerLocation);
void Render(WorldRenderer wr, World w, ActorInfo ai, PPos centerLocation);
}
class RenderRangeCircleInfo : TraitInfo<RenderRangeCircle>, IPlaceBuildingDecoration
{
public readonly string RangeCircleType = null;
public void Render(WorldRenderer wr, World w, ActorInfo ai, int2 centerLocation)
public void Render(WorldRenderer wr, World w, ActorInfo ai, PPos centerLocation)
{
wr.DrawRangeCircle(
Color.FromArgb(128, Color.Yellow),
centerLocation,
centerLocation.ToFloat2(),
ai.Traits.Get<AttackBaseInfo>().GetMaximumRange());
foreach (var a in w.ActorsWithTrait<RenderRangeCircle>())
@@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA
wr.DrawRangeCircle(
Color.FromArgb(128, Color.Yellow),
self.CenterLocation, (int)self.Trait<AttackBase>().GetMaximumRange());
self.CenterLocation.ToFloat2(), (int)self.Trait<AttackBase>().GetMaximumRange());
}
}
}

View File

@@ -16,11 +16,11 @@ namespace OpenRA.Mods.RA
{
class RenderShroudCircleInfo : TraitInfo<RenderShroudCircle>, IPlaceBuildingDecoration
{
public void Render(WorldRenderer wr, World w, ActorInfo ai, int2 centerLocation)
public void Render(WorldRenderer wr, World w, ActorInfo ai, PPos centerLocation)
{
wr.DrawRangeCircle(
Color.FromArgb(128, Color.Cyan),
centerLocation,
centerLocation.ToFloat2(),
ai.Traits.Get<CreatesShroudInfo>().Range);
foreach (var a in w.ActorsWithTrait<RenderShroudCircle>())
@@ -38,7 +38,7 @@ namespace OpenRA.Mods.RA
wr.DrawRangeCircle(
Color.FromArgb(128, Color.Cyan),
self.CenterLocation, (int)self.Info.Traits.Get<CreatesShroudInfo>().Range);
self.CenterLocation.ToFloat2(), (int)self.Info.Traits.Get<CreatesShroudInfo>().Range);
}
}
}

View File

@@ -78,7 +78,7 @@ namespace OpenRA.Mods.RA
self.CancelActivity();
self.QueueActivity(new MoveAdjacentTo(target));
self.QueueActivity(mobile.MoveTo(Traits.Util.CellContaining(order.TargetActor.CenterLocation), order.TargetActor));
self.QueueActivity(mobile.MoveTo(order.TargetActor.CenterLocation.ToCPos(), order.TargetActor));
self.QueueActivity(new Rearm(self));
self.QueueActivity(new Repair(order.TargetActor));

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.RA
{
if (!Panicked) return;
var target = Util.SubPxVector[self.World.SharedRandom.Next(255)]* Info.MoveRadius / 1024 + self.Location;
var target = (CVec)( Util.SubPxVector[self.World.SharedRandom.Next(255)] * Info.MoveRadius / 1024 ) + self.Location;
self.Trait<Mobile>().ResolveOrder(self, new Order("Move", self, false) { TargetLocation = target });
}

View File

@@ -18,7 +18,7 @@ namespace OpenRA.Scripting
{
public class RASpecialPowers
{
public static void Chronoshift(World world, List<Pair<Actor, int2>>units, Actor chronosphere, int duration, bool killCargo)
public static void Chronoshift(World world, List<Pair<Actor, CPos>> units, Actor chronosphere, int duration, bool killCargo)
{
if (chronosphere != null)
chronosphere.Trait<RenderBuilding>().PlayCustomAnim(chronosphere, "active");

View File

@@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA
var cell = RandomWalk(self.Location, self.World.SharedRandom)
.Take(info.MaxRange)
.SkipWhile(p => resLayer.GetResource(p) == resourceType && resLayer.IsFull(p.X, p.Y))
.Cast<int2?>().FirstOrDefault();
.Cast<CPos?>().FirstOrDefault();
if (cell != null && self.World.Map.IsInMap(cell.Value) &&
(resLayer.GetResource(cell.Value) == resourceType
@@ -64,7 +64,7 @@ namespace OpenRA.Mods.RA
}
}
static IEnumerable<int2> RandomWalk(int2 p, Thirdparty.Random r)
static IEnumerable<CPos> RandomWalk(CPos p, Thirdparty.Random r)
{
for (; ; )
{
@@ -74,8 +74,7 @@ namespace OpenRA.Mods.RA
if (dx == 0 && dy == 0)
continue;
p.X += dx;
p.Y += dy;
p += new CVec(dx, dy);
yield return p;
}
}

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA
class SmokeTrailWhenDamaged : ITick
{
Turret smokeTurret;
int2 position;
PPos position;
int interval;
int ticks;
@@ -42,10 +42,10 @@ namespace OpenRA.Mods.RA
if (move.Altitude > 0 && self.GetDamageState() >= DamageState.Heavy)
{
var facing = self.Trait<IFacing>();
var altitude = new int2(0, move.Altitude);
position = (self.CenterLocation - Combat.GetTurretPosition(self, facing, smokeTurret)).ToInt2();
var altitude = new PVecInt(0, move.Altitude);
position = (self.CenterLocation - Combat.GetTurretPosition(self, facing, smokeTurret));
if (self.World.LocalShroud.IsVisible(Util.CellContaining(position)))
if (self.World.LocalShroud.IsVisible(position.ToCPos()))
self.World.AddFrameEndTask(
w => w.Add(new Smoke(w, position - altitude, "smokey")));
}

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Mods.RA
SpawnUnitsForPlayer(s.Key, s.Value);
}
void SpawnUnitsForPlayer(Player p, int2 sp)
void SpawnUnitsForPlayer(Player p, CPos sp)
{
if (!p.PlayerReference.DefaultStartingUnits)
return; /* they don't want an mcv, the map provides something else for them */

Some files were not shown because too many files have changed in this diff Show More