Shift movement cost/speed into IMove; regressions in a few areas

This commit is contained in:
Paul Chote
2010-06-25 17:05:56 +12:00
parent 6a5869f2c6
commit 29fa9e3aeb
20 changed files with 178 additions and 132 deletions

View File

@@ -19,6 +19,7 @@
#endregion
using System;
using System.Linq;
using OpenRA.GameRules;
using OpenRA.Traits;
@@ -66,7 +67,8 @@ namespace OpenRA.Mods.RA.Activities
public static void Fly(Actor self, int desiredAltitude )
{
var unit = self.traits.Get<Unit>();
var speed = .2f * Util.GetEffectiveSpeed(self, UnitMovementType.Fly);
var mobile = self.traits.WithInterface<IMove>().FirstOrDefault();
var speed = .2f * mobile.MovementSpeedForCell(self, self.Location);
var angle = unit.Facing / 128f * Math.PI;
var aircraft = self.traits.Get<Aircraft>();

View File

@@ -59,8 +59,9 @@ namespace OpenRA.Mods.RA.Activities
var desiredFacing = Util.GetFacing(dist, unit.Facing);
Util.TickFacing(ref unit.Facing, desiredFacing, self.Info.Traits.Get<UnitInfo>().ROT);
var rawSpeed = .2f * Util.GetEffectiveSpeed(self, UnitMovementType.Fly);
var mobile = self.traits.WithInterface<IMove>().FirstOrDefault();
var rawSpeed = .2f * mobile.MovementSpeedForCell(self, self.Location);
if (!float2.WithinEpsilon(float2.Zero, dist, range * Game.CellSize))
self.CenterLocation += (rawSpeed / dist.Length) * dist;

View File

@@ -63,7 +63,8 @@ namespace OpenRA.Mods.RA.Activities
Util.TickFacing(ref unit.Facing, desiredFacing,
self.Info.Traits.Get<UnitInfo>().ROT);
var rawSpeed = .2f * Util.GetEffectiveSpeed(self, UnitMovementType.Fly);
var mobile = self.traits.WithInterface<IMove>().FirstOrDefault();
var rawSpeed = .2f * mobile.MovementSpeedForCell(self, self.Location);
self.CenterLocation += (rawSpeed / dist.Length) * dist;
aircraft.Location = Util.CellContaining(self.CenterLocation);

View File

@@ -19,6 +19,7 @@
#endregion
using System;
using System.Linq;
using OpenRA.GameRules;
using OpenRA.Traits;
@@ -57,7 +58,8 @@ namespace OpenRA.Mods.RA.Activities
var desiredFacing = Util.GetFacing(d, unit.Facing);
Util.TickFacing(ref unit.Facing, desiredFacing, self.Info.Traits.Get<UnitInfo>().ROT);
var speed = .2f * Util.GetEffectiveSpeed(self, UnitMovementType.Fly);
var mobile = self.traits.WithInterface<IMove>().FirstOrDefault();
var speed = .2f * mobile.MovementSpeedForCell(self, self.Location);
var angle = unit.Facing / 128f * Math.PI;
self.CenterLocation += speed * -float2.FromAngle((float)angle);

View File

@@ -53,7 +53,9 @@ namespace OpenRA.Mods.RA.Activities
var landPos = dest.CenterLocation;
var unit = self.traits.Get<Unit>();
var speed = .2f * Util.GetEffectiveSpeed(self, UnitMovementType.Fly);
var mobile = self.traits.WithInterface<IMove>().FirstOrDefault();
var speed = .2f * mobile.MovementSpeedForCell(self, self.Location);
var approachStart = landPos - new float2(unit.Altitude * speed, 0);
var turnRadius = (128f / self.Info.Traits.Get<UnitInfo>().ROT) * speed / (float)Math.PI;

View File

@@ -70,11 +70,23 @@ namespace OpenRA.Mods.RA
return new float2[] { move.Pos };
}
public UnitMovementType GetMovementType() { return UnitMovementType.Fly; }
public bool CanEnterCell(int2 location) { return true; }
public float MovementCostForCell(Actor self, int2 cell) { return 1f; }
public float MovementSpeedForCell(Actor self, int2 cell)
{
var unitInfo = self.Info.Traits.GetOrDefault<UnitInfo>();
if( unitInfo == null)
return 0f;
var modifier = self.traits
.WithInterface<ISpeedModifier>()
.Select(t => t.GetSpeedModifier())
.Product();
return unitInfo.Speed * modifier;
}
int2[] noCells = new int2[] { };
public IEnumerable<int2> OccupiedCells() { return noCells; }
}

View File

@@ -92,17 +92,19 @@ namespace OpenRA.Mods.RA
public float GetCost(int2 p, Actor forActor)
{
var umt = forActor.traits.Get<Mobile>().GetMovementType();
if (customTerrain[p.X, p.Y] != null)
return customTerrain[p.X,p.Y].GetCost(p,umt);
// Todo: Do we even need to reenable this since cost = 100% for everything?
//var umt = forActor.traits.Get<Mobile>().GetMovementType();
//if (customTerrain[p.X, p.Y] != null)
// return customTerrain[p.X,p.Y].GetCost(p,umt);
return 1f;
}
public float GetSpeedModifier(int2 p, Actor forActor)
{
var umt = forActor.traits.Get<Mobile>().GetMovementType();
if (customTerrain[p.X, p.Y] != null)
return customTerrain[p.X,p.Y].GetSpeedModifier(p,umt);
// Todo: Do we even need to reenable this since cost = 100% for everything?
//var umt = forActor.traits.Get<Mobile>().GetMovementType();
//if (customTerrain[p.X, p.Y] != null)
// return customTerrain[p.X,p.Y].GetSpeedModifier(p,umt);
return 1f;
}

View File

@@ -110,7 +110,8 @@ namespace OpenRA.Mods.RA
return;
var Info = self.Info.Traits.Get<HelicopterInfo>();
var rawSpeed = .2f * Util.GetEffectiveSpeed(self, UnitMovementType.Fly);
var mobile = self.traits.WithInterface<IMove>().FirstOrDefault();
var rawSpeed = .2f * mobile.MovementSpeedForCell(self, self.Location);
var otherHelis = self.World.FindUnitsInCircle(self.CenterLocation, Info.IdealSeparation)
.Where(a => a.traits.Contains<Helicopter>());

View File

@@ -44,8 +44,9 @@ namespace OpenRA.Mods.RA
if (cargo == null || cargo.IsFull(underCursor))
return null;
var umt = self.traits.Get<IMove>().GetMovementType();
if (!underCursor.Info.Traits.Get<CargoInfo>().PassengerTypes.Contains(umt))
// Todo: Use something better for cargo management
//var umt = self.traits.Get<IMove>().GetMovementType();
//if (!underCursor.Info.Traits.Get<CargoInfo>().PassengerTypes.Contains(umt))
return null;
return new Order("EnterTransport", self, underCursor);