Prepare MapCreeps code for trait-defined lobby options.
This commit is contained in:
@@ -52,17 +52,18 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
readonly SpawnActorOnDeathInfo info;
|
readonly SpawnActorOnDeathInfo info;
|
||||||
readonly string faction;
|
readonly string faction;
|
||||||
|
readonly bool enabled;
|
||||||
|
|
||||||
public SpawnActorOnDeath(ActorInitializer init, SpawnActorOnDeathInfo info)
|
public SpawnActorOnDeath(ActorInitializer init, SpawnActorOnDeathInfo info)
|
||||||
{
|
{
|
||||||
this.info = 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;
|
faction = init.Contains<FactionInit>() ? init.Get<FactionInit, string>() : init.Self.Owner.Faction.InternalName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Killed(Actor self, AttackInfo e)
|
public void Killed(Actor self, AttackInfo e)
|
||||||
{
|
{
|
||||||
if (info.RequiresLobbyCreeps && !self.World.LobbyInfo.GlobalSettings.Creeps)
|
if (!enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!self.IsInWorld)
|
if (!self.IsInWorld)
|
||||||
|
|||||||
@@ -24,5 +24,13 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public readonly bool Locked = false;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,13 +12,14 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using OpenRA.Mods.Common.Traits;
|
||||||
using OpenRA.Primitives;
|
using OpenRA.Primitives;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.D2k.Traits
|
namespace OpenRA.Mods.D2k.Traits
|
||||||
{
|
{
|
||||||
[Desc("Controls the spawning of sandworms. Attach this to the world actor.")]
|
[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")]
|
[Desc("Minimum number of worms")]
|
||||||
public readonly int Minimum = 0;
|
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); }
|
public object Create(ActorInitializer init) { return new WormManager(init.Self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
class WormManager : ITick
|
class WormManager : ITick, INotifyCreated
|
||||||
{
|
{
|
||||||
readonly WormManagerInfo info;
|
readonly WormManagerInfo info;
|
||||||
readonly Lazy<Actor[]> spawnPointActors;
|
readonly Lazy<Actor[]> spawnPointActors;
|
||||||
|
|
||||||
|
bool enabled;
|
||||||
int spawnCountdown;
|
int spawnCountdown;
|
||||||
int wormsPresent;
|
int wormsPresent;
|
||||||
|
|
||||||
@@ -52,9 +54,14 @@ namespace OpenRA.Mods.D2k.Traits
|
|||||||
spawnPointActors = Exts.Lazy(() => self.World.ActorsHavingTrait<WormSpawner>().ToArray());
|
spawnPointActors = Exts.Lazy(() => self.World.ActorsHavingTrait<WormSpawner>().ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void INotifyCreated.Created(Actor self)
|
||||||
|
{
|
||||||
|
enabled = self.Trait<MapCreeps>().Enabled;
|
||||||
|
}
|
||||||
|
|
||||||
public void Tick(Actor self)
|
public void Tick(Actor self)
|
||||||
{
|
{
|
||||||
if (!self.World.LobbyInfo.GlobalSettings.Creeps)
|
if (!enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!spawnPointActors.Value.Any())
|
if (!spawnPointActors.Value.Any())
|
||||||
|
|||||||
Reference in New Issue
Block a user