Prepare MapCreeps code for trait-defined lobby options.
This commit is contained in:
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user