Support a maximum building range (Fixes #2156).

This also implements support for a per-provider
cooldown between placing structures, allowing mods
with multiple structure queues to rate-limit
placement around a single provider.

An initial delay parameter is included to
support units that deploy into a base provider and
require an initial setup time (e.g. the Surveyor
unit from C&C TW).

The range and time restrictions are not applied to
walls as a balance choice.
This commit is contained in:
Paul Chote
2013-03-10 18:15:42 +13:00
parent 4dc5c4a871
commit 9127d0dcf4
7 changed files with 142 additions and 2 deletions

View File

@@ -31,17 +31,40 @@ namespace OpenRA.Mods.RA.Buildings
[Desc("x means space it blocks, _ is a part that is passable by actors.")]
public readonly string Footprint = "x";
public readonly int2 Dimensions = new int2(1, 1);
public readonly bool RequiresBaseProvider = false;
public readonly string[] BuildSounds = {"placbldg.aud", "build5.aud"};
public readonly string[] SellSounds = {"cashturn.aud"};
public object Create(ActorInitializer init) { return new Building(init, this); }
public PPos CenterLocation(CPos topLeft)
{
return (PPos)((2 * topLeft.ToInt2() + Dimensions) * Game.CellSize / 2);
}
bool HasBaseProvider(World world, Player p, CPos topLeft)
{
var center = CenterLocation(topLeft);
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;
}
return false;
}
public bool IsCloseEnoughToBase(World world, Player p, string buildingName, CPos topLeft)
{
if (p.PlayerActor.Trait<DeveloperMode>().BuildAnywhere)
return true;
if (RequiresBaseProvider && !HasBaseProvider(world, p, topLeft))
return false;
var buildingMaxBounds = (CVec)Dimensions;
if (Rules.Info[buildingName].Traits.Contains<BibInfo>())
buildingMaxBounds += new CVec(0, 1);
@@ -103,7 +126,7 @@ namespace OpenRA.Mods.RA.Buildings
occupiedCells = FootprintUtils.UnpathableTiles( self.Info.Name, Info, TopLeft )
.Select(c => Pair.New(c, SubCell.FullCell)).ToArray();
pxPosition = (PPos) (( 2 * topLeft.ToInt2() + Info.Dimensions ) * Game.CellSize / 2);
pxPosition = Info.CenterLocation(topLeft);
}
public int GetPowerUsage()