Revert "add IHasLocation"

This reverts commit 699b4b1154.
This commit is contained in:
Chris Forbes
2010-09-28 07:43:49 +13:00
parent a3c0448e15
commit f402ec7898
31 changed files with 105 additions and 136 deletions

View File

@@ -18,13 +18,8 @@ namespace OpenRA.Mods.RA.Activities
{
public readonly float2 Pos;
private Fly( float2 pos )
{
this.Pos = pos;
}
public static Fly ToPx( float2 px ) { return new Fly( px ); }
public static Fly ToCell( int2 pos ) { return new Fly( Util.CenterOfCell( pos ) ); }
public Fly(float2 pos) { Pos = pos; }
public Fly(int2 pos) { Pos = Util.CenterOfCell(pos); }
public override IActivity Tick(Actor self)
{
@@ -62,7 +57,7 @@ namespace OpenRA.Mods.RA.Activities
var aircraft = self.Trait<Aircraft>();
var speed = .2f * aircraft.MovementSpeedForCell(self, self.Location);
var angle = aircraft.Facing / 128f * Math.PI;
aircraft.center += speed * -float2.FromAngle((float)angle);
self.CenterLocation += speed * -float2.FromAngle((float)angle);
aircraft.Location = Util.CellContaining(self.CenterLocation);
aircraft.Altitude += Math.Sign(desiredAltitude - aircraft.Altitude);
}

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA.Activities
return NextActivity;
return Util.SequenceActivities(
Fly.ToPx(Target.CenterLocation),
new Fly(Target.CenterLocation),
new FlyTimed(50),
this);
}
@@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA.Activities
if( IsCanceled ) return NextActivity;
return Util.SequenceActivities(
Fly.ToPx(Util.CenterOfCell(Target)),
new Fly(Util.CenterOfCell(Target)),
new FlyTimed(50),
this);
}

View File

@@ -47,7 +47,7 @@ namespace OpenRA.Mods.RA.Activities
var rawSpeed = .2f * aircraft.MovementSpeedForCell(self, self.Location);
if (!float2.WithinEpsilon(float2.Zero, dist, range * Game.CellSize))
aircraft.center += (rawSpeed / dist.Length) * dist;
self.CenterLocation += (rawSpeed / dist.Length) * dist;
return this;
}

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Mods.RA.Activities
var dist = Dest - self.CenterLocation;
if (float2.WithinEpsilon(float2.Zero, dist, 2))
{
aircraft.center = Dest;
self.CenterLocation = Dest;
aircraft.Location = Util.CellContaining(self.CenterLocation);
return NextActivity;
}
@@ -48,7 +48,7 @@ namespace OpenRA.Mods.RA.Activities
aircraft.ROT);
var rawSpeed = .2f * aircraft.MovementSpeedForCell(self, self.Location);
aircraft.center += (rawSpeed / dist.Length) * dist;
self.CenterLocation += (rawSpeed / dist.Length) * dist;
aircraft.Location = Util.CellContaining(self.CenterLocation);
return this;

View File

@@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA.Activities
var speed = .2f * aircraft.MovementSpeedForCell(self, self.Location);
var angle = aircraft.Facing / 128f * Math.PI;
aircraft.center += speed * -float2.FromAngle((float)angle);
self.CenterLocation += speed * -float2.FromAngle((float)angle);
aircraft.Location = Util.CellContaining(self.CenterLocation);
return this;

View File

@@ -17,15 +17,15 @@ namespace OpenRA.Mods.RA.Activities
class Leap : CancelableActivity
{
Target target;
int2 initialLocation;
float2 initialLocation;
float t;
const int delay = 6;
int moveFraction;
public Leap(Actor self, Target target)
{
this.target = target;
initialLocation = self.Trait<Mobile>().PxPosition;
initialLocation = self.CenterLocation;
self.Trait<RenderInfantry>().Attacking(self);
Sound.Play("dogg5p.aud", self.CenterLocation);
@@ -33,16 +33,16 @@ namespace OpenRA.Mods.RA.Activities
public override IActivity Tick(Actor self)
{
if( moveFraction == 0 && IsCanceled ) return NextActivity;
if( t == 0 && IsCanceled ) return NextActivity;
if (!target.IsValid) return NextActivity;
self.Trait<AttackLeap>().IsLeaping = true;
var mobile = self.Trait<Mobile>();
++moveFraction;
mobile.PxPosition = int2.Lerp(initialLocation, target.PxPosition, moveFraction, delay);
t += (1f / delay);
if (moveFraction >= delay)
self.CenterLocation = float2.Lerp(initialLocation, target.CenterLocation, t);
if (t >= 1f)
{
self.TraitsImplementing<IMove>().FirstOrDefault()
.SetPosition(self, Util.CellContaining(target.CenterLocation));

View File

@@ -92,9 +92,9 @@ namespace OpenRA.Mods.RA.Activities
Calculate(self);
return Util.SequenceActivities(
Fly.ToPx(w1),
Fly.ToPx(w2),
Fly.ToPx(w3),
new Fly(w1),
new Fly(w2),
new Fly(w3),
new Land(Target.FromActor(dest)),
NextActivity);
}

View File

@@ -36,18 +36,13 @@ namespace OpenRA.Mods.RA
public int Facing { get; set; }
[Sync]
public int Altitude { get; set; }
public float2 center;
AircraftInfo Info;
public Aircraft( ActorInitializer init , AircraftInfo info)
{
if( init.Contains<LocationInit>() )
{
this.Location = init.Get<LocationInit, int2>();
this.center = Util.CenterOfCell( Location );
}
if (init.Contains<LocationInit>())
this.Location = init.Get<LocationInit,int2>();
this.Facing = init.Contains<FacingInit>() ? init.Get<FacingInit,int>() : info.InitialFacing;
this.Altitude = init.Contains<AltitudeInit>() ? init.Get<AltitudeInit,int>() : 0;
@@ -66,15 +61,9 @@ namespace OpenRA.Mods.RA
public void SetPosition(Actor self, int2 cell)
{
Location = cell;
center = Util.CenterOfCell(cell);
self.CenterLocation = Util.CenterOfCell(cell);
}
public void SetPxPosition(Actor self, int2 px)
{
Location = Util.CellContaining(px);
center = px;
}
public bool AircraftCanEnter(Actor self, Actor a)
{
return Info.RearmBuildings.Contains( a.Info.Name )
@@ -94,6 +83,5 @@ namespace OpenRA.Mods.RA
int2[] noCells = new int2[] { };
public IEnumerable<int2> OccupiedCells() { return noCells; }
public int2 PxPosition { get { return center.ToInt2(); } }
}
}

View File

@@ -82,13 +82,6 @@ namespace OpenRA.Mods.RA
public int2 TopLeft { get { return Location; } }
public IEnumerable<int2> OccupiedCells() { return new int2[] { Location }; }
public int2 PxPosition { get; private set; }
public void SetPxPosition( Actor self, int2 px )
{
SetPosition( self, Util.CellContaining( px ) );
}
public bool CanEnterCell(int2 cell)
{
if (!self.World.Map.IsInMap(cell.X, cell.Y)) return false;
@@ -103,7 +96,7 @@ namespace OpenRA.Mods.RA
uim.Remove(self, this);
Location = cell;
PxPosition = Util.CenterOfCell(cell);
self.CenterLocation = Util.CenterOfCell(cell);
var seq = self.World.GetTerrainInfo(cell).IsWater ? "water" : "idle";
if (seq != self.Trait<RenderSimple>().anim.CurrentSequence.Name)

View File

@@ -58,7 +58,18 @@ namespace OpenRA.Mods.RA.Effects
w.Remove(this);
var loc = Traits.Util.CellContaining(location);
cargo.CancelActivity();
cargo.Trait<ITeleportable>().SetPosition(cargo, loc);
var mobile = cargo.TraitOrDefault<ITeleportable>();
if (mobile != null)
mobile.SetPosition(cargo, loc);
else
{
cargo.CenterLocation = Traits.Util.CenterOfCell(loc);
if (cargo.HasTrait<IOccupySpace>())
world.WorldActor.Trait<UnitInfluence>().Add(cargo, cargo.Trait<IOccupySpace>());
}
w.Add(cargo);
});
}

View File

@@ -145,11 +145,11 @@ namespace OpenRA.Mods.RA
.Select(h => self.Trait<Helicopter>().GetRepulseForce(self, h))
.Aggregate(float2.Zero, (a, b) => a + b);
aircraft.center += rawSpeed * f;
self.CenterLocation += rawSpeed * f;
if (--offsetTicks <= 0)
{
aircraft.center += Info.InstabilityMagnitude * self.World.SharedRandom.Gauss2D(5);
self.CenterLocation += Info.InstabilityMagnitude * self.World.SharedRandom.Gauss2D(5);
aircraft.Altitude += (int)(Info.InstabilityMagnitude * self.World.SharedRandom.Gauss1D(5));
offsetTicks = Info.InstabilityTicks;
}

View File

@@ -40,7 +40,5 @@ namespace OpenRA.Mods.RA
public int2 TopLeft { get { return location; } }
public IEnumerable<int2> OccupiedCells() { yield return TopLeft; }
public int2 PxPosition { get { return Util.CenterOfCell( location ); } }
}
}

View File

@@ -55,8 +55,6 @@ namespace OpenRA.Mods.RA
public int2 TopLeft { get { return location; } }
public IEnumerable<int2> OccupiedCells() { yield return TopLeft; }
public int2 PxPosition { get { return Util.CenterOfCell( location ); } }
}
/* tag trait for stuff that shouldnt trigger mines */

View File

@@ -101,7 +101,7 @@ namespace OpenRA.Mods.RA
});
self.CancelActivity();
self.QueueActivity(Fly.ToPx(Util.CenterOfCell(order.TargetLocation)));
self.QueueActivity(new Fly(Util.CenterOfCell(order.TargetLocation)));
}
else if (order.OrderString == "Enter")

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA
public class ExitInfo : TraitInfo<Exit>
{
public readonly int2 SpawnOffset = int2.Zero; // in px relative to CenterLocation
public readonly float2 SpawnOffset = float2.Zero; // in px relative to CenterLocation
public readonly int2 ExitCell = int2.Zero; // in cells relative to TopLeft
public readonly int Facing = -1;
}
@@ -46,21 +46,21 @@ namespace OpenRA.Mods.RA
});
var exit = self.Location + exitinfo.ExitCell;
var spawn = self.CenterLocation.ToInt2() + exitinfo.SpawnOffset;
var spawn = self.CenterLocation + exitinfo.SpawnOffset;
var mobile = newUnit.Trait<Mobile>();
var move = newUnit.Trait<IMove>();
var facing = newUnit.TraitOrDefault<IFacing>();
// Set the physical position of the unit as the exit cell
mobile.SetPosition(newUnit,exit);
move.SetPosition(newUnit,exit);
var to = Util.CenterOfCell(exit);
mobile.PxPosition = spawn;
newUnit.CenterLocation = spawn;
if (facing != null)
facing.Facing = exitinfo.Facing < 0 ? Util.GetFacing(to - spawn, facing.Facing) : exitinfo.Facing;
self.World.Add(newUnit);
// Animate the spawn -> exit transition
var speed = mobile.MovementSpeedForCell(self, exit);
var speed = move.MovementSpeedForCell(self, exit);
var length = speed > 0 ? (int)( ( to - spawn ).Length*3 / speed ) : 0;
newUnit.QueueActivity(new Drag(spawn, to, length));

View File

@@ -91,7 +91,7 @@ namespace OpenRA.Mods.RA.Render
foreach (var t in Footprint.UnpathableTiles( self.Info.Name, self.Info.Traits.Get<BuildingInfo>(), self.Location ))
{
var cell = t; // required: c# fails at bindings
self.World.AddFrameEndTask(w => w.Add(new Explosion(w, Util.CenterOfCell(cell), "building", false)));
self.World.AddFrameEndTask(w => w.Add(new Explosion(w, Util.CenterOfCell(cell).ToInt2(), "building", false)));
}
else if (e.DamageState >= DamageState.Heavy && e.PreviousDamageState < DamageState.Heavy)
{

View File

@@ -35,7 +35,7 @@ namespace OpenRA.Mods.RA
foreach (var s in self.Info.Traits.WithInterface<ExitInfo>())
{
var exit = self.Location + s.ExitCell;
var spawn = self.Trait<IHasLocation>().PxPosition + s.SpawnOffset;
var spawn = self.CenterLocation + s.SpawnOffset;
if (!self.World.WorldActor.Trait<UnitInfluence>().GetUnitsAt( exit ).Any())
{
var newUnit = self.World.CreateActor( producee.Name, new TypeDictionary
@@ -43,7 +43,8 @@ namespace OpenRA.Mods.RA
new LocationInit( exit ),
new OwnerInit( self.Owner ),
});
newUnit.CenterLocation = spawn;
var rp = self.TraitOrDefault<RallyPoint>();
if( rp != null )
{

View File

@@ -62,7 +62,7 @@ namespace OpenRA.Mods.RA
a.Trait<CarpetBomb>().SetTarget(order.TargetLocation);
a.CancelActivity();
a.QueueActivity(Fly.ToCell(order.TargetLocation));
a.QueueActivity(new Fly(order.TargetLocation));
if (flare != null)
a.QueueActivity(new CallFunc(() => flare.Destroy()));

View File

@@ -55,7 +55,7 @@ namespace OpenRA.Mods.RA
});
plane.CancelActivity();
plane.QueueActivity(Fly.ToPx(Util.CenterOfCell(order.TargetLocation)));
plane.QueueActivity(new Fly(Util.CenterOfCell(order.TargetLocation)));
plane.QueueActivity(new CallFunc(() => plane.World.AddFrameEndTask( w =>
{
var camera = w.CreateActor("camera", new TypeDictionary