Convert BaseProvider range check to world coords.

This commit is contained in:
Paul Chote
2013-07-06 16:10:31 +12:00
parent d631f1b06b
commit 39e699d119
7 changed files with 25 additions and 30 deletions

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA
{
// Offset effective position to the top of the northernmost occupied cell
var bi = self.Info.Traits.GetOrDefault<BuildingInfo>();
offset = (bi != null) ? -FootprintUtils.CenterOffset(bi).Y : -512;
offset = ((bi != null) ? -FootprintUtils.CenterOffset(bi).Y : 0) - 512;
}
public IEnumerable<IRenderable> ModifyRender(Actor self, WorldRenderer wr, IEnumerable<IRenderable> r)

View File

@@ -17,7 +17,7 @@ namespace OpenRA.Mods.RA.Buildings
{
public class BaseProviderInfo : ITraitInfo
{
public readonly float Range = 10;
public readonly int Range = 10;
public readonly int Cooldown = 0;
public readonly int InitialDelay = 0;

View File

@@ -38,23 +38,20 @@ namespace OpenRA.Mods.RA.Buildings
public object Create(ActorInitializer init) { return new Building(init, this); }
public PPos CenterLocation(CPos topLeft)
public Actor FindBaseProvider(World world, Player p, CPos topLeft)
{
return (PPos)((2 * topLeft.ToInt2() + Dimensions) * Game.CellSize / 2);
}
bool HasBaseProvider(World world, Player p, CPos topLeft)
{
var center = CenterLocation(topLeft);
var center = topLeft.CenterPosition + FootprintUtils.CenterOffset(this);
foreach (var bp in world.ActorsWithTrait<BaseProvider>())
{
if (bp.Actor.Owner.Stances[p] != Stance.Ally || !bp.Trait.Ready())
continue;
if (Combat.IsInRange(center, bp.Trait.Info.Range, bp.Actor.CenterLocation))
return true;
// Range is counted from the center of the actor, not from each cell.
var target = Target.FromPos(bp.Actor.CenterLocation);
if (target.IsInRange(center, WRange.FromCells(bp.Trait.Info.Range)))
return bp.Actor;
}
return false;
return null;
}
public bool IsCloseEnoughToBase(World world, Player p, string buildingName, CPos topLeft)
@@ -62,7 +59,7 @@ namespace OpenRA.Mods.RA.Buildings
if (p.PlayerActor.Trait<DeveloperMode>().BuildAnywhere)
return true;
if (RequiresBaseProvider && !HasBaseProvider(world, p, topLeft))
if (RequiresBaseProvider && FindBaseProvider(world, p, topLeft) == null)
return false;
var buildingMaxBounds = (CVec)Dimensions;
@@ -126,7 +123,9 @@ namespace OpenRA.Mods.RA.Buildings
occupiedCells = FootprintUtils.UnpathableTiles( self.Info.Name, Info, TopLeft )
.Select(c => Pair.New(c, SubCell.FullCell)).ToArray();
pxPosition = Info.CenterLocation(topLeft);
var position = topLeft.CenterPosition + FootprintUtils.CenterOffset(Info);
pxPosition = PPos.FromWPosHackZ(position);
}
public int GetPowerUsage()

View File

@@ -65,7 +65,8 @@ namespace OpenRA.Mods.RA.Buildings
public static WVec CenterOffset(BuildingInfo buildingInfo)
{
var dim = buildingInfo.Dimensions;
return new CVec(dim.X, dim.Y).ToWVec() / 2;
// Offset is measured relative to the center of the cell, so need to subtract an additional half cell.
return new CVec(dim.X, dim.Y).ToWVec() / 2 - new WVec(512, 512, 0);
}
}
}

View File

@@ -98,7 +98,7 @@ namespace OpenRA.Mods.RA.Orders
initialized = true;
}
var offset = (topLeft - CPos.Zero).ToWVec() + FootprintUtils.CenterOffset(BuildingInfo);
var offset = topLeft.CenterPosition + FootprintUtils.CenterOffset(BuildingInfo) - WPos.Zero;
foreach (var r in preview)
r.WithPos(r.Pos + offset).Render(wr);

View File

@@ -83,18 +83,11 @@ namespace OpenRA.Mods.RA
if (buildingInfo.RequiresBaseProvider)
{
var center = buildingInfo.CenterLocation(order.TargetLocation);
foreach (var bp in w.ActorsWithTrait<BaseProvider>())
{
if (bp.Actor.Owner.Stances[self.Owner] != Stance.Ally || !bp.Trait.Ready())
continue;
if (Combat.IsInRange(center, bp.Trait.Info.Range, bp.Actor.CenterLocation))
{
bp.Trait.BeginCooldown();
break;
}
}
// May be null if the build anywhere cheat is active
// BuildingInfo.IsCloseEnoughToBase has already verified that this is a valid build location
var producer = buildingInfo.FindBaseProvider(w, self.Owner, order.TargetLocation);
if (producer != null)
producer.Trait<BaseProvider>().BeginCooldown();
}
if (GetNumBuildables(self.Owner) > prevItems)

View File

@@ -49,10 +49,12 @@ namespace OpenRA.Mods.RA.Render
: base(init, info)
{
roof = new Animation(GetImage(init.self));
var bi = init.self.Info.Traits.Get<BuildingInfo>();
// Additional 512 units move from center -> top of cell
var offset = FootprintUtils.CenterOffset(bi).Y + 512;
anims.Add("roof", new AnimationWithOffset(roof, null,
() => !buildComplete, FootprintUtils.CenterOffset(bi).Y));
() => !buildComplete, offset));
}
public void BuildingComplete( Actor self )