Remove CVec -> WVec conversion.
This commit is contained in:
@@ -44,8 +44,6 @@ namespace OpenRA
|
|||||||
public int LengthSquared { get { return X * X + Y * Y; } }
|
public int LengthSquared { get { return X * X + Y * Y; } }
|
||||||
public int Length { get { return (int)Math.Sqrt(LengthSquared); } }
|
public int Length { get { return (int)Math.Sqrt(LengthSquared); } }
|
||||||
|
|
||||||
public WVec ToWVec() { return new WVec(X*1024, Y*1024, 0); }
|
|
||||||
|
|
||||||
public CVec Clamp(Rectangle r)
|
public CVec Clamp(Rectangle r)
|
||||||
{
|
{
|
||||||
return new CVec(
|
return new CVec(
|
||||||
@@ -115,7 +113,6 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
case "X": return X;
|
case "X": return X;
|
||||||
case "Y": return Y;
|
case "Y": return Y;
|
||||||
case "Facing": return Traits.Util.GetFacing(this, 0);
|
|
||||||
default: throw new LuaException("CVec does not define a member '{0}'".F(key));
|
default: throw new LuaException("CVec does not define a member '{0}'".F(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -476,6 +476,11 @@ namespace OpenRA
|
|||||||
return new CPos(pos.X / 1024, pos.Y / 1024);
|
return new CPos(pos.X / 1024, pos.Y / 1024);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int FacingBetween(CPos cell, CPos towards, int fallbackfacing)
|
||||||
|
{
|
||||||
|
return Traits.Util.GetFacing(CenterOfCell(towards) - CenterOfCell(cell), fallbackfacing);
|
||||||
|
}
|
||||||
|
|
||||||
public void Resize(int width, int height) // editor magic.
|
public void Resize(int width, int height) // editor magic.
|
||||||
{
|
{
|
||||||
var oldMapTiles = MapTiles.Value;
|
var oldMapTiles = MapTiles.Value;
|
||||||
|
|||||||
@@ -42,11 +42,6 @@ namespace OpenRA.Traits
|
|||||||
return (angle / 4 - 0x40) & 0xFF;
|
return (angle / 4 - 0x40) & 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int GetFacing(CVec d, int currentFacing)
|
|
||||||
{
|
|
||||||
return GetFacing(d.ToWVec(), currentFacing);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int GetNearestFacing(int facing, int desiredFacing)
|
public static int GetNearestFacing(int facing, int desiredFacing)
|
||||||
{
|
{
|
||||||
var turn = desiredFacing - facing;
|
var turn = desiredFacing - facing;
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA
|
|||||||
{
|
{
|
||||||
// Offset effective position to the top of the northernmost occupied cell
|
// Offset effective position to the top of the northernmost occupied cell
|
||||||
var bi = self.Info.Traits.GetOrDefault<BuildingInfo>();
|
var bi = self.Info.Traits.GetOrDefault<BuildingInfo>();
|
||||||
offset = ((bi != null) ? -FootprintUtils.CenterOffset(bi).Y : 0) - 512;
|
offset = ((bi != null) ? -FootprintUtils.CenterOffset(self.World, bi).Y : 0) - 512;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<IRenderable> ModifyRender(Actor self, WorldRenderer wr, IEnumerable<IRenderable> r)
|
public IEnumerable<IRenderable> ModifyRender(Actor self, WorldRenderer wr, IEnumerable<IRenderable> r)
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.RA.Buildings
|
|||||||
{
|
{
|
||||||
var width = bi.Dimensions.X;
|
var width = bi.Dimensions.X;
|
||||||
var bibOffset = bi.Dimensions.Y - 1;
|
var bibOffset = bi.Dimensions.Y - 1;
|
||||||
var centerOffset = FootprintUtils.CenterOffset(bi);
|
var centerOffset = FootprintUtils.CenterOffset(self.World, bi);
|
||||||
var location = self.Location;
|
var location = self.Location;
|
||||||
var rows = info.HasMinibib ? 1 : 2;
|
var rows = info.HasMinibib ? 1 : 2;
|
||||||
var map = self.World.Map;
|
var map = self.World.Map;
|
||||||
@@ -49,16 +49,17 @@ namespace OpenRA.Mods.RA.Buildings
|
|||||||
var index = i;
|
var index = i;
|
||||||
var anim = new Animation(self.World, rs.GetImage(self));
|
var anim = new Animation(self.World, rs.GetImage(self));
|
||||||
var cellOffset = new CVec(i % width, i / width + bibOffset);
|
var cellOffset = new CVec(i % width, i / width + bibOffset);
|
||||||
|
var cell = location + cellOffset;
|
||||||
|
|
||||||
// Some mods may define terrain-specific bibs
|
// Some mods may define terrain-specific bibs
|
||||||
var terrain = map.GetTerrainInfo(location + cellOffset).Type;
|
var terrain = map.GetTerrainInfo(cell).Type;
|
||||||
var testSequence = info.Sequence + "-" + terrain;
|
var testSequence = info.Sequence + "-" + terrain;
|
||||||
var sequence = anim.HasSequence(testSequence) ? testSequence : info.Sequence;
|
var sequence = anim.HasSequence(testSequence) ? testSequence : info.Sequence;
|
||||||
anim.PlayFetchIndex(sequence, () => index);
|
anim.PlayFetchIndex(sequence, () => index);
|
||||||
anim.IsDecoration = true;
|
anim.IsDecoration = true;
|
||||||
|
|
||||||
// Z-order is one set to the top of the footprint
|
// Z-order is one set to the top of the footprint
|
||||||
var offset = cellOffset.ToWVec() - centerOffset;
|
var offset = self.World.Map.CenterOfCell(cell) - self.World.Map.CenterOfCell(location) - centerOffset;
|
||||||
var awo = new AnimationWithOffset(anim, () => offset, null, -(offset.Y + centerOffset.Y + 512));
|
var awo = new AnimationWithOffset(anim, () => offset, null, -(offset.Y + centerOffset.Y + 512));
|
||||||
rs.Add("bib_{0}".F(i), awo, info.Palette);
|
rs.Add("bib_{0}".F(i), awo, info.Palette);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA.Buildings
|
|||||||
|
|
||||||
public Actor FindBaseProvider(World world, Player p, CPos topLeft)
|
public Actor FindBaseProvider(World world, Player p, CPos topLeft)
|
||||||
{
|
{
|
||||||
var center = world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(this);
|
var center = world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(world, this);
|
||||||
foreach (var bp in world.ActorsWithTrait<BaseProvider>())
|
foreach (var bp in world.ActorsWithTrait<BaseProvider>())
|
||||||
{
|
{
|
||||||
var validOwner = bp.Actor.Owner == p || (world.LobbyInfo.GlobalSettings.AllyBuildRadius && bp.Actor.Owner.Stances[p] == Stance.Ally);
|
var validOwner = bp.Actor.Owner == p || (world.LobbyInfo.GlobalSettings.AllyBuildRadius && bp.Actor.Owner.Stances[p] == Stance.Ally);
|
||||||
@@ -137,7 +137,7 @@ namespace OpenRA.Mods.RA.Buildings
|
|||||||
occupiedCells = FootprintUtils.UnpathableTiles( self.Info.Name, Info, TopLeft )
|
occupiedCells = FootprintUtils.UnpathableTiles( self.Info.Name, Info, TopLeft )
|
||||||
.Select(c => Pair.New(c, SubCell.FullCell)).ToArray();
|
.Select(c => Pair.New(c, SubCell.FullCell)).ToArray();
|
||||||
|
|
||||||
CenterPosition = init.world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(Info);
|
CenterPosition = init.world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(init.world, Info);
|
||||||
BuildComplete = init.Contains<SkipMakeAnimsInit>();
|
BuildComplete = init.Contains<SkipMakeAnimsInit>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,11 +62,10 @@ namespace OpenRA.Mods.RA.Buildings
|
|||||||
return new CVec(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);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WVec CenterOffset(BuildingInfo buildingInfo)
|
public static WVec CenterOffset(World w, BuildingInfo buildingInfo)
|
||||||
{
|
{
|
||||||
var dim = buildingInfo.Dimensions;
|
var dim = buildingInfo.Dimensions;
|
||||||
// Offset is measured relative to the center of the cell, so need to subtract an additional half cell.
|
return (w.Map.CenterOfCell(CPos.Zero + new CVec(dim.X, dim.Y)) - w.Map.CenterOfCell(new CPos(1, 1))) / 2;
|
||||||
return new CVec(dim.X, dim.Y).ToWVec() / 2 - new WVec(512, 512, 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ namespace OpenRA.Mods.RA
|
|||||||
{
|
{
|
||||||
new CenterPositionInit(w.Map.CenterOfCell(startPos) + new WVec(WRange.Zero, WRange.Zero, altitude)),
|
new CenterPositionInit(w.Map.CenterOfCell(startPos) + new WVec(WRange.Zero, WRange.Zero, altitude)),
|
||||||
new OwnerInit(w.WorldActor.Owner),
|
new OwnerInit(w.WorldActor.Owner),
|
||||||
new FacingInit(Util.GetFacing(p - startPos, 0))
|
new FacingInit(w.Map.FacingBetween(startPos, p, 0))
|
||||||
});
|
});
|
||||||
|
|
||||||
plane.CancelActivity();
|
plane.CancelActivity();
|
||||||
|
|||||||
@@ -139,8 +139,7 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
if (nextCell == null)
|
if (nextCell == null)
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
var dir = nextCell.Value.First - mobile.fromCell;
|
var firstFacing = self.World.Map.FacingBetween(mobile.fromCell, nextCell.Value.First, mobile.Facing);
|
||||||
var firstFacing = Util.GetFacing(dir, mobile.Facing);
|
|
||||||
if (firstFacing != mobile.Facing)
|
if (firstFacing != mobile.Facing)
|
||||||
{
|
{
|
||||||
path.Add(nextCell.Value.First);
|
path.Add(nextCell.Value.First);
|
||||||
@@ -362,7 +361,7 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
Util.BetweenCells(self.World, mobile.fromCell, mobile.toCell) + (fromSubcellOffset + toSubcellOffset) / 2,
|
Util.BetweenCells(self.World, mobile.fromCell, mobile.toCell) + (fromSubcellOffset + toSubcellOffset) / 2,
|
||||||
Util.BetweenCells(self.World, mobile.toCell, nextCell.Value.First) + (toSubcellOffset + nextSubcellOffset) / 2,
|
Util.BetweenCells(self.World, mobile.toCell, nextCell.Value.First) + (toSubcellOffset + nextSubcellOffset) / 2,
|
||||||
mobile.Facing,
|
mobile.Facing,
|
||||||
Util.GetNearestFacing(mobile.Facing, Util.GetFacing(nextCell.Value.First - mobile.toCell, mobile.Facing)),
|
Util.GetNearestFacing(mobile.Facing, self.World.Map.FacingBetween(mobile.toCell, nextCell.Value.First, mobile.Facing)),
|
||||||
moveFraction - moveFractionTotal);
|
moveFraction - moveFractionTotal);
|
||||||
|
|
||||||
mobile.SetLocation(mobile.toCell, mobile.toSubCell, nextCell.Value.First, nextCell.Value.Second);
|
mobile.SetLocation(mobile.toCell, mobile.toSubCell, nextCell.Value.First, nextCell.Value.Second);
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ namespace OpenRA.Mods.RA.Orders
|
|||||||
initialized = true;
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var offset = world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(BuildingInfo) - WPos.Zero;
|
var offset = world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(world, BuildingInfo) - WPos.Zero;
|
||||||
foreach (var r in preview)
|
foreach (var r in preview)
|
||||||
r.OffsetBy(offset).Render(wr);
|
r.OffsetBy(offset).Render(wr);
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ namespace OpenRA.Mods.RA.Render
|
|||||||
var bi = init.self.Info.Traits.Get<BuildingInfo>();
|
var bi = init.self.Info.Traits.Get<BuildingInfo>();
|
||||||
|
|
||||||
// Additional 512 units move from center -> top of cell
|
// Additional 512 units move from center -> top of cell
|
||||||
var offset = FootprintUtils.CenterOffset(bi).Y + 512;
|
var offset = FootprintUtils.CenterOffset(init.world, bi).Y + 512;
|
||||||
Add("roof", new AnimationWithOffset(roof, null,
|
Add("roof", new AnimationWithOffset(roof, null,
|
||||||
() => !buildComplete, offset));
|
() => !buildComplete, offset));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ namespace OpenRA.Mods.RA.Scripting
|
|||||||
public int GetFacing(object vec, double currentFacing)
|
public int GetFacing(object vec, double currentFacing)
|
||||||
{
|
{
|
||||||
if (vec is CVec)
|
if (vec is CVec)
|
||||||
return Util.GetFacing((CVec)vec, (int)currentFacing);
|
return world.Map.FacingBetween(CPos.Zero, CPos.Zero + (CVec)vec, (int)currentFacing);
|
||||||
if (vec is WVec)
|
if (vec is WVec)
|
||||||
return Util.GetFacing((WVec)vec, (int)currentFacing);
|
return Util.GetFacing((WVec)vec, (int)currentFacing);
|
||||||
throw new ArgumentException("Unsupported vector type: {0}".F(vec.GetType()));
|
throw new ArgumentException("Unsupported vector type: {0}".F(vec.GetType()));
|
||||||
|
|||||||
@@ -226,7 +226,7 @@ namespace OpenRA.Mods.RA
|
|||||||
// Unit previews
|
// Unit previews
|
||||||
foreach (var unit in power.UnitsInRange(sourceLocation))
|
foreach (var unit in power.UnitsInRange(sourceLocation))
|
||||||
{
|
{
|
||||||
var offset = (xy - sourceLocation).ToWVec();
|
var offset = world.Map.CenterOfCell(xy) - world.Map.CenterOfCell(sourceLocation);
|
||||||
if (manager.self.Owner.Shroud.IsTargetable(unit))
|
if (manager.self.Owner.Shroud.IsTargetable(unit))
|
||||||
foreach (var r in unit.Render(wr))
|
foreach (var r in unit.Render(wr))
|
||||||
yield return r.OffsetBy(offset);
|
yield return r.OffsetBy(offset);
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ namespace OpenRA.Mods.RA
|
|||||||
{
|
{
|
||||||
new CenterPositionInit(w.Map.CenterOfCell(startPos) + new WVec(WRange.Zero, WRange.Zero, altitude)),
|
new CenterPositionInit(w.Map.CenterOfCell(startPos) + new WVec(WRange.Zero, WRange.Zero, altitude)),
|
||||||
new OwnerInit(self.Owner),
|
new OwnerInit(self.Owner),
|
||||||
new FacingInit(Util.GetFacing(order.TargetLocation - startPos, 0))
|
new FacingInit(w.Map.FacingBetween(startPos, order.TargetLocation, 0))
|
||||||
});
|
});
|
||||||
|
|
||||||
a.CancelActivity();
|
a.CancelActivity();
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ namespace OpenRA.Mods.RA
|
|||||||
{
|
{
|
||||||
new CenterPositionInit(self.World.Map.CenterOfCell(enterCell) + new WVec(WRange.Zero, WRange.Zero, altitude)),
|
new CenterPositionInit(self.World.Map.CenterOfCell(enterCell) + new WVec(WRange.Zero, WRange.Zero, altitude)),
|
||||||
new OwnerInit(self.Owner),
|
new OwnerInit(self.Owner),
|
||||||
new FacingInit(Util.GetFacing(order.TargetLocation - enterCell, 0))
|
new FacingInit(self.World.Map.FacingBetween(enterCell, order.TargetLocation, 0))
|
||||||
});
|
});
|
||||||
|
|
||||||
plane.CancelActivity();
|
plane.CancelActivity();
|
||||||
|
|||||||
Reference in New Issue
Block a user