Prepare MapCreeps code for trait-defined lobby options.

This commit is contained in:
Paul Chote
2016-04-24 15:34:53 +01:00
parent 7e49ae7eb0
commit c412e4e86c
3 changed files with 22 additions and 6 deletions

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

@@ -12,13 +12,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.D2k.Traits
{
[Desc("Controls the spawning of sandworms. Attach this to the world actor.")]
class WormManagerInfo : ITraitInfo
class WormManagerInfo : ITraitInfo, Requires<MapCreepsInfo>
{
[Desc("Minimum number of worms")]
public readonly int Minimum = 0;
@@ -38,11 +39,12 @@ namespace OpenRA.Mods.D2k.Traits
public object Create(ActorInitializer init) { return new WormManager(init.Self, this); }
}
class WormManager : ITick
class WormManager : ITick, INotifyCreated
{
readonly WormManagerInfo info;
readonly Lazy<Actor[]> spawnPointActors;
bool enabled;
int spawnCountdown;
int wormsPresent;
@@ -52,9 +54,14 @@ namespace OpenRA.Mods.D2k.Traits
spawnPointActors = Exts.Lazy(() => self.World.ActorsHavingTrait<WormSpawner>().ToArray());
}
void INotifyCreated.Created(Actor self)
{
enabled = self.Trait<MapCreeps>().Enabled;
}
public void Tick(Actor self)
{
if (!self.World.LobbyInfo.GlobalSettings.Creeps)
if (!enabled)
return;
if (!spawnPointActors.Value.Any())