Prepare ally build adjacency code for trait-defined lobby options.

This commit is contained in:
Paul Chote
2016-04-24 15:35:28 +01:00
parent c412e4e86c
commit e3bc73a168
3 changed files with 21 additions and 9 deletions

View File

@@ -30,10 +30,12 @@ namespace OpenRA.Mods.Common.Traits
public class BaseProvider : ITick, IPostRenderSelection, ISelectionBar
{
public readonly BaseProviderInfo Info;
DeveloperMode devMode;
Actor self;
readonly DeveloperMode devMode;
readonly Actor self;
int total;
int progress;
bool allyBuildEnabled;
public BaseProvider(Actor self, BaseProviderInfo info)
{
@@ -41,6 +43,7 @@ namespace OpenRA.Mods.Common.Traits
this.self = self;
devMode = self.Owner.PlayerActor.Trait<DeveloperMode>();
progress = total = info.InitialDelay;
allyBuildEnabled = self.World.WorldActor.Trait<MapBuildRadius>().AllyBuildRadiusEnabled;
}
public void Tick(Actor self)
@@ -61,8 +64,7 @@ namespace OpenRA.Mods.Common.Traits
bool ValidRenderPlayer()
{
var allyBuildRadius = self.World.LobbyInfo.GlobalSettings.AllyBuildRadius;
return self.Owner == self.World.RenderPlayer || (allyBuildRadius && self.Owner.IsAlliedWith(self.World.RenderPlayer));
return self.Owner == self.World.RenderPlayer || (allyBuildEnabled && self.Owner.IsAlliedWith(self.World.RenderPlayer));
}
public IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr)

View File

@@ -43,9 +43,11 @@ namespace OpenRA.Mods.Common.Traits
public Actor FindBaseProvider(World world, Player p, CPos topLeft)
{
var center = world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(world, this);
var allyBuildEnabled = world.WorldActor.Trait<MapBuildRadius>().AllyBuildRadiusEnabled;
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 || (allyBuildEnabled && bp.Actor.Owner.Stances[p] == Stance.Ally);
if (!validOwner || !bp.Trait.Ready())
continue;
@@ -76,7 +78,7 @@ namespace OpenRA.Mods.Common.Traits
var nearnessCandidates = new List<CPos>();
var bi = world.WorldActor.Trait<BuildingInfluence>();
var allyBuildRadius = world.LobbyInfo.GlobalSettings.AllyBuildRadius;
var allyBuildEnabled = world.WorldActor.Trait<MapBuildRadius>().AllyBuildRadiusEnabled;
for (var y = scanStart.Y; y < scanEnd.Y; y++)
{
@@ -89,14 +91,14 @@ namespace OpenRA.Mods.Common.Traits
if (buildingAtPos == null)
{
var unitsAtPos = world.ActorMap.GetActorsAt(pos).Where(a => a.IsInWorld
&& (a.Owner == p || (allyBuildRadius && a.Owner.Stances[p] == Stance.Ally))
&& (a.Owner == p || (allyBuildEnabled && a.Owner.Stances[p] == Stance.Ally))
&& a.Info.HasTraitInfo<GivesBuildableAreaInfo>());
if (unitsAtPos.Any())
nearnessCandidates.Add(pos);
}
else if (buildingAtPos.IsInWorld && buildingAtPos.Info.HasTraitInfo<GivesBuildableAreaInfo>()
&& (buildingAtPos.Owner == p || (allyBuildRadius && buildingAtPos.Owner.Stances[p] == Stance.Ally)))
&& (buildingAtPos.Owner == p || (allyBuildEnabled && buildingAtPos.Owner.Stances[p] == Stance.Ally)))
nearnessCandidates.Add(pos);
}
}

View File

@@ -24,5 +24,13 @@ namespace OpenRA.Mods.Common.Traits
public readonly bool AllyBuildRadiusLocked = false;
}
public class MapBuildRadius { }
public class MapBuildRadius : INotifyCreated
{
public bool AllyBuildRadiusEnabled { get; private set; }
void INotifyCreated.Created(Actor self)
{
AllyBuildRadiusEnabled = self.World.LobbyInfo.GlobalSettings.AllyBuildRadius;
}
}
}