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

@@ -24,10 +24,15 @@ namespace OpenRA.Mods.Common.Commands
public class DevCommands : IChatCommand, IWorldLoaded
{
World world;
DeveloperMode developerMode;
public void WorldLoaded(World w, WorldRenderer wr)
{
world = w;
if (world.LocalPlayer != null)
developerMode = world.LocalPlayer.PlayerActor.Trait<DeveloperMode>();
var console = world.WorldActor.Trait<ChatCommands>();
var help = world.WorldActor.Trait<HelpCommand>();
@@ -55,7 +60,7 @@ namespace OpenRA.Mods.Common.Commands
if (world.LocalPlayer == null)
return;
if (!world.AllowDevCommands)
if (!developerMode.Enabled)
{
Game.Debug("Cheats are disabled.");
return;

View File

@@ -18,7 +18,8 @@ namespace OpenRA.Mods.Common
{
public static bool HasNoRequiredUnits(this Player player)
{
if (player.World.LobbyInfo.GlobalSettings.ShortGame)
var mapOptions = player.World.WorldActor.Trait<MapOptions>();
if (mapOptions.ShortGame)
return !player.World.ActorsHavingTrait<MustBeDestroyed>(t => t.Info.RequiredForShortGame).Any(a => a.Owner == player);
return !player.World.ActorsHavingTrait<MustBeDestroyed>().Any(a => a.Owner == player && a.IsInWorld);
}

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

@@ -36,10 +36,10 @@ namespace OpenRA.Mods.Common.Traits
{
foreach (var player in collector.World.Players)
if (collector.Owner.IsAlliedWith(player))
player.Shroud.ExploreAll(player.World);
player.Shroud.ExploreAll();
}
else
collector.Owner.Shroud.ExploreAll(collector.World);
collector.Owner.Shroud.ExploreAll();
base.Activate(collector);
}

View File

@@ -97,11 +97,12 @@ namespace OpenRA.Mods.Common.Traits
public void ResolveOrder(Actor self, Order order)
{
if (!self.World.AllowDevCommands)
return;
if (order.OrderString == "DevLevelUp")
{
var developerMode = self.Owner.PlayerActor.Trait<DeveloperMode>();
if (!developerMode.Enabled)
return;
if ((int)order.ExtraData > 0)
GiveLevels((int)order.ExtraData);
else

View File

@@ -125,7 +125,7 @@ namespace OpenRA.Mods.Common.Traits
public override int GetBuildTime(ActorInfo unit, BuildableInfo bi = null)
{
if (self.World.AllowDevCommands && self.Owner.PlayerActor.Trait<DeveloperMode>().FastBuild)
if (developerMode.FastBuild)
return 0;
var time = unit.GetBuildTime() * Info.BuildSpeed / 100;

View File

@@ -204,7 +204,7 @@ namespace OpenRA.Mods.Common.Traits
public virtual IEnumerable<ActorInfo> AllItems()
{
if (self.World.AllowDevCommands && developerMode.AllTech)
if (developerMode.AllTech)
return producible.Keys;
return allProducibles;
@@ -214,7 +214,7 @@ namespace OpenRA.Mods.Common.Traits
{
if (!Enabled)
return Enumerable.Empty<ActorInfo>();
if (self.World.AllowDevCommands && developerMode.AllTech)
if (developerMode.AllTech)
return producible.Keys;
return buildableProducibles;
@@ -226,7 +226,7 @@ namespace OpenRA.Mods.Common.Traits
if (!producible.TryGetValue(actor, out ps))
return false;
return ps.Buildable || (self.World.AllowDevCommands && developerMode.AllTech);
return ps.Buildable || developerMode.AllTech;
}
public virtual void Tick(Actor self)
@@ -316,7 +316,7 @@ namespace OpenRA.Mods.Common.Traits
public virtual int GetBuildTime(ActorInfo unit, BuildableInfo bi = null)
{
if (self.World.AllowDevCommands && self.Owner.PlayerActor.Trait<DeveloperMode>().FastBuild)
if (developerMode.FastBuild)
return 0;
var time = unit.GetBuildTime() * Info.BuildSpeed / 100;

View File

@@ -52,17 +52,18 @@ namespace OpenRA.Mods.Common.Traits
{
readonly SpawnActorOnDeathInfo info;
readonly string faction;
readonly bool enabled;
public SpawnActorOnDeath(ActorInitializer init, SpawnActorOnDeathInfo info)
{
this.info = info;
enabled = !info.RequiresLobbyCreeps || init.Self.World.WorldActor.Trait<MapCreeps>().Enabled;
faction = init.Contains<FactionInit>() ? init.Get<FactionInit, string>() : init.Self.Owner.Faction.InternalName;
}
public void Killed(Actor self, AttackInfo e)
{
if (info.RequiresLobbyCreeps && !self.World.LobbyInfo.GlobalSettings.Creeps)
if (!enabled)
return;
if (!self.IsInWorld)

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;
}
}
}

View File

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

View File

@@ -39,5 +39,13 @@ namespace OpenRA.Mods.Common.Traits
public readonly bool DifficultyLocked = false;
}
public class MapOptions { }
public class MapOptions : INotifyCreated
{
public bool ShortGame { get; private set; }
void INotifyCreated.Created(Actor self)
{
ShortGame = self.World.LobbyInfo.GlobalSettings.ShortGame;
}
}
}

View File

@@ -64,14 +64,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
}
}
var diplomacy = widget.GetOrNull<MenuButtonWidget>("DIPLOMACY_BUTTON");
if (diplomacy != null)
{
diplomacy.Visible = !world.Map.Visibility.HasFlag(MapVisibility.MissionSelector) && world.Players.Any(a => a != world.LocalPlayer && !a.NonCombatant);
diplomacy.IsDisabled = () => disableSystemButtons;
diplomacy.OnClick = () => OpenMenuPanel(diplomacy);
}
var debug = widget.GetOrNull<MenuButtonWidget>("DEBUG_BUTTON");
if (debug != null)
{