Add RadarPing on worm spawn, fix wandering issue, add new Wormspawner.shp

This commit is contained in:
penev92
2014-11-30 15:39:47 +02:00
parent 61cb74adb4
commit b4d1a605da
4 changed files with 31 additions and 11 deletions

View File

@@ -9,7 +9,9 @@
#endregion #endregion
using System; using System;
using System.Drawing;
using System.Linq; using System.Linq;
using OpenRA.Mods.Common;
using OpenRA.Primitives; using OpenRA.Primitives;
using OpenRA.Traits; using OpenRA.Traits;
@@ -22,7 +24,7 @@ namespace OpenRA.Mods.D2k
public readonly int Minimum = 1; public readonly int Minimum = 1;
[Desc("Maximum number of worms")] [Desc("Maximum number of worms")]
public readonly int Maximum = 5; public readonly int Maximum = 8;
[Desc("Average time (seconds) between worm spawn")] [Desc("Average time (seconds) between worm spawn")]
public readonly int SpawnInterval = 180; public readonly int SpawnInterval = 180;
@@ -39,6 +41,7 @@ namespace OpenRA.Mods.D2k
{ {
int countdown; int countdown;
int wormsPresent; int wormsPresent;
RadarPings radarPings;
readonly WormManagerInfo info; readonly WormManagerInfo info;
readonly Lazy<Actor[]> spawnPoints; readonly Lazy<Actor[]> spawnPoints;
@@ -66,7 +69,8 @@ namespace OpenRA.Mods.D2k
void SpawnWorm (Actor self) void SpawnWorm (Actor self)
{ {
var spawnLocation = GetRandomSpawnPosition(self); var spawnPosition = GetRandomSpawnPosition(self);
var spawnLocation = self.World.Map.CellContaining(spawnPosition);
self.World.AddFrameEndTask(w => w.CreateActor(info.WormSignature, new TypeDictionary self.World.AddFrameEndTask(w => w.CreateActor(info.WormSignature, new TypeDictionary
{ {
new OwnerInit(w.Players.First(x => x.PlayerName == info.WormOwnerPlayer)), new OwnerInit(w.Players.First(x => x.PlayerName == info.WormOwnerPlayer)),
@@ -74,12 +78,12 @@ namespace OpenRA.Mods.D2k
})); }));
wormsPresent++; wormsPresent++;
AnnounceWormSign(self); AnnounceWormSign(self, spawnPosition);
} }
CPos GetRandomSpawnPosition(Actor self) WPos GetRandomSpawnPosition(Actor self)
{ {
return spawnPoints.Value.Random(self.World.SharedRandom).Location; return spawnPoints.Value.Random(self.World.SharedRandom).CenterPosition;
} }
public void DecreaseWorms() public void DecreaseWorms()
@@ -87,10 +91,22 @@ namespace OpenRA.Mods.D2k
wormsPresent--; wormsPresent--;
} }
void AnnounceWormSign(Actor self) void AnnounceWormSign(Actor self, WPos wormSpawnPosition)
{ {
if (self.World.LocalPlayer != null) if (self.World.LocalPlayer == null)
return;
Sound.PlayNotification(self.World.Map.Rules, self.World.LocalPlayer, "Speech", info.WormSignNotification, self.World.LocalPlayer.Country.Race); Sound.PlayNotification(self.World.Map.Rules, self.World.LocalPlayer, "Speech", info.WormSignNotification, self.World.LocalPlayer.Country.Race);
if (radarPings == null)
{
if (self.World.WorldActor == null)
return;
radarPings = self.World.WorldActor.TraitOrDefault<RadarPings>();
}
radarPings.Add(() => true, wormSpawnPosition, Color.Red, 50);
} }
} }

View File

@@ -15,7 +15,7 @@ namespace OpenRA.Mods.RA
{ {
[Desc("Will AttackMove to a random location within MoveRadius when idle.", [Desc("Will AttackMove to a random location within MoveRadius when idle.",
"This conflicts with player orders and should only be added to animal creeps.")] "This conflicts with player orders and should only be added to animal creeps.")]
class AttackWanderInfo : ITraitInfo class AttackWanderInfo : ITraitInfo, Requires<AttackMoveInfo>
{ {
public readonly int WanderMoveRadius = 10; public readonly int WanderMoveRadius = 10;
@@ -29,11 +29,14 @@ namespace OpenRA.Mods.RA
{ {
int ticksIdle; int ticksIdle;
int effectiveMoveRadius; int effectiveMoveRadius;
readonly AttackMove attackMove;
readonly AttackWanderInfo Info; readonly AttackWanderInfo Info;
public AttackWander(Actor self, AttackWanderInfo info) public AttackWander(Actor self, AttackWanderInfo info)
{ {
Info = info; Info = info;
effectiveMoveRadius = info.WanderMoveRadius;
attackMove = self.TraitOrDefault<AttackMove>();
} }
public void TickIdle(Actor self) public void TickIdle(Actor self)
@@ -50,7 +53,7 @@ namespace OpenRA.Mods.RA
return; // We'll be back the next tick; better to sit idle for a few seconds than prolongue this tick indefinitely with a loop return; // We'll be back the next tick; better to sit idle for a few seconds than prolongue this tick indefinitely with a loop
} }
self.Trait<AttackMove>().ResolveOrder(self, new Order("AttackMove", self, false) { TargetLocation = targetCell }); attackMove.ResolveOrder(self, new Order("AttackMove", self, false) { TargetLocation = targetCell });
ticksIdle = 0; ticksIdle = 0;
effectiveMoveRadius = Info.WanderMoveRadius; effectiveMoveRadius = Info.WanderMoveRadius;

View File

@@ -49,7 +49,8 @@ namespace OpenRA.Mods.RA.Traits
public void TickIdle(Actor self) public void TickIdle(Actor self)
{ {
if (TargetLocation.HasValue) // This might cause the actor to be stuck if the target location is unreachable
if (TargetLocation.HasValue && self.Location != TargetLocation.Value)
Activate(self); Activate(self);
} }

Binary file not shown.