Merge pull request #11176 from pchote/lobby-trait-checkbox-prep

Query lobby checkbox state via their owning traits.
This commit is contained in:
reaperrr
2016-05-16 19:00:35 +02:00
18 changed files with 194 additions and 148 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);
}
}