Add WormAttack notification, fix worm min count and spawn interval
Enhance usage of WormManager Minimum and Maximum properties, add escape radius to AttackSwallow
This commit is contained in:
@@ -21,17 +21,19 @@ namespace OpenRA.Mods.D2k
|
||||
[Desc("The number of ticks it takes to get in place under the target to attack.")]
|
||||
public int AttackTime = 30;
|
||||
|
||||
public readonly string WormAttackNotification = "WormAttack";
|
||||
|
||||
public override object Create(ActorInitializer init) { return new AttackSwallow(init.self, this); }
|
||||
}
|
||||
|
||||
class AttackSwallow : AttackFrontal
|
||||
{
|
||||
public readonly AttackSwallowInfo AttackSwallowInfo;
|
||||
new public readonly AttackSwallowInfo Info;
|
||||
|
||||
public AttackSwallow(Actor self, AttackSwallowInfo attackSwallowInfo)
|
||||
: base(self, attackSwallowInfo)
|
||||
public AttackSwallow(Actor self, AttackSwallowInfo info)
|
||||
: base(self, info)
|
||||
{
|
||||
AttackSwallowInfo = attackSwallowInfo;
|
||||
Info = info;
|
||||
}
|
||||
|
||||
public override void DoAttack(Actor self, Target target)
|
||||
|
||||
@@ -8,11 +8,12 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.GameRules;
|
||||
using OpenRA.Mods.Common;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Mods.RA.Move;
|
||||
using OpenRA.Mods.RA.Render;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.D2k
|
||||
@@ -21,9 +22,13 @@ namespace OpenRA.Mods.D2k
|
||||
|
||||
class SwallowActor : Activity
|
||||
{
|
||||
const int NearEnough = 1;
|
||||
|
||||
readonly CPos location;
|
||||
readonly Target target;
|
||||
readonly WeaponInfo weapon;
|
||||
readonly RenderUnit renderUnit;
|
||||
readonly RadarPings radarPings;
|
||||
readonly AttackSwallow swallow;
|
||||
readonly IPositionable positionable;
|
||||
|
||||
@@ -34,18 +39,23 @@ namespace OpenRA.Mods.D2k
|
||||
{
|
||||
this.target = target;
|
||||
this.weapon = weapon;
|
||||
positionable = self.TraitOrDefault<Mobile>();
|
||||
swallow = self.TraitOrDefault<AttackSwallow>();
|
||||
renderUnit = self.TraitOrDefault<RenderUnit>();
|
||||
countdown = swallow.AttackSwallowInfo.AttackTime;
|
||||
positionable = self.Trait<Mobile>();
|
||||
swallow = self.Trait<AttackSwallow>();
|
||||
renderUnit = self.Trait<RenderUnit>();
|
||||
radarPings = self.World.WorldActor.TraitOrDefault<RadarPings>();
|
||||
countdown = swallow.Info.AttackTime;
|
||||
|
||||
renderUnit.DefaultAnimation.ReplaceAnim("burrowed");
|
||||
stance = AttackState.Burrowed;
|
||||
location = target.Actor.Location;
|
||||
}
|
||||
|
||||
bool WormAttack(Actor worm)
|
||||
{
|
||||
var targetLocation = target.Actor.Location;
|
||||
// The target has moved too far away
|
||||
if ((location - targetLocation).Length > NearEnough)
|
||||
return false;
|
||||
|
||||
var lunch = worm.World.ActorMap.GetUnitsAt(targetLocation)
|
||||
.Where(t => !t.Equals(worm) && weapon.IsValidAgainst(t, worm));
|
||||
@@ -54,11 +64,17 @@ namespace OpenRA.Mods.D2k
|
||||
|
||||
stance = AttackState.EmergingAboveGround;
|
||||
|
||||
lunch.Do(t => t.World.AddFrameEndTask(_ => { t.World.Remove(t); t.Kill(t); })); // Dispose of the evidence (we don't want husks)
|
||||
foreach (var actor in lunch)
|
||||
actor.World.AddFrameEndTask(_ => actor.Destroy());
|
||||
|
||||
positionable.SetPosition(worm, targetLocation);
|
||||
PlayAttackAnimation(worm);
|
||||
|
||||
var attackPosition = worm.CenterPosition;
|
||||
var affectedPlayers = lunch.Select(x => x.Owner).Distinct();
|
||||
foreach (var affectedPlayer in affectedPlayers)
|
||||
NotifyPlayer(affectedPlayer, attackPosition);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -68,6 +84,12 @@ namespace OpenRA.Mods.D2k
|
||||
renderUnit.PlayCustomAnim(self, "mouth");
|
||||
}
|
||||
|
||||
void NotifyPlayer(Player player, WPos location)
|
||||
{
|
||||
Sound.PlayNotification(player.World.Map.Rules, player, "Speech", swallow.Info.WormAttackNotification, player.Country.Race);
|
||||
radarPings.Add(() => true, location, Color.Red, 50);
|
||||
}
|
||||
|
||||
public override Activity Tick(Actor self)
|
||||
{
|
||||
if (countdown > 0)
|
||||
@@ -78,17 +100,17 @@ namespace OpenRA.Mods.D2k
|
||||
|
||||
if (stance == AttackState.ReturningUnderground) // Wait for the worm to get back underground
|
||||
{
|
||||
if (self.World.SharedRandom.Next()%2 == 0) // There is a 50-50 chance that the worm would just go away
|
||||
if (self.World.SharedRandom.Next() % 2 == 0) // There is a 50-50 chance that the worm would just go away
|
||||
{
|
||||
self.CancelActivity();
|
||||
self.World.AddFrameEndTask(w => w.Remove(self));
|
||||
var wormManager = self.World.WorldActor.TraitOrDefault<WormManager>();
|
||||
if (wormManager != null)
|
||||
wormManager.DecreaseWorms();
|
||||
self.CancelActivity();
|
||||
self.World.AddFrameEndTask(w => w.Remove(self));
|
||||
var wormManager = self.World.WorldActor.TraitOrDefault<WormManager>();
|
||||
if (wormManager != null)
|
||||
wormManager.DecreaseWorms();
|
||||
}
|
||||
else
|
||||
{
|
||||
renderUnit.DefaultAnimation.ReplaceAnim("idle");
|
||||
renderUnit.DefaultAnimation.ReplaceAnim("idle");
|
||||
}
|
||||
return NextActivity;
|
||||
}
|
||||
@@ -96,14 +118,17 @@ namespace OpenRA.Mods.D2k
|
||||
if (stance == AttackState.Burrowed) // Wait for the worm to get in position
|
||||
{
|
||||
// This is so that the worm cancels an attack against a target that has reached solid rock
|
||||
if (positionable == null || !positionable.CanEnterCell(target.Actor.Location, null, false))
|
||||
if (!positionable.CanEnterCell(target.Actor.Location, null, false))
|
||||
return NextActivity;
|
||||
|
||||
var success = WormAttack(self);
|
||||
if (!success)
|
||||
{
|
||||
renderUnit.DefaultAnimation.ReplaceAnim("idle");
|
||||
return NextActivity;
|
||||
}
|
||||
|
||||
countdown = swallow.AttackSwallowInfo.ReturnTime;
|
||||
countdown = swallow.Info.ReturnTime;
|
||||
stance = AttackState.ReturningUnderground;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,10 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
@@ -21,33 +22,34 @@ namespace OpenRA.Mods.D2k
|
||||
class WormManagerInfo : ITraitInfo
|
||||
{
|
||||
[Desc("Minimum number of worms")]
|
||||
public readonly int Minimum = 1;
|
||||
public readonly int Minimum = 2;
|
||||
|
||||
[Desc("Maximum number of worms")]
|
||||
public readonly int Maximum = 8;
|
||||
public readonly int Maximum = 4;
|
||||
|
||||
[Desc("Average time (seconds) between worm spawn")]
|
||||
public readonly int SpawnInterval = 180;
|
||||
public readonly int SpawnInterval = 120;
|
||||
|
||||
public readonly string WormSignNotification = "WormSign";
|
||||
|
||||
public readonly string WormSignature = "sandworm";
|
||||
public readonly string WormOwnerPlayer = "Creeps";
|
||||
|
||||
public object Create (ActorInitializer init) { return new WormManager(this, init.self); }
|
||||
public object Create(ActorInitializer init) { return new WormManager(this, init.self); }
|
||||
}
|
||||
|
||||
class WormManager : ITick
|
||||
{
|
||||
int countdown;
|
||||
int wormsPresent;
|
||||
RadarPings radarPings;
|
||||
readonly WormManagerInfo info;
|
||||
readonly Lazy<Actor[]> spawnPoints;
|
||||
readonly Lazy<RadarPings> radarPings;
|
||||
|
||||
public WormManager(WormManagerInfo info, Actor self)
|
||||
{
|
||||
this.info = info;
|
||||
radarPings = Exts.Lazy(() => self.World.WorldActor.Trait<RadarPings>());
|
||||
spawnPoints = Exts.Lazy(() => self.World.ActorsWithTrait<WormSpawner>().Select(x => x.Actor).ToArray());
|
||||
}
|
||||
|
||||
@@ -59,31 +61,40 @@ namespace OpenRA.Mods.D2k
|
||||
if (!spawnPoints.Value.Any())
|
||||
return;
|
||||
|
||||
if (--countdown > 0)
|
||||
// Apparantly someone doesn't want worms or the maximum number of worms has been reached
|
||||
if (info.Maximum < 1 || wormsPresent >= info.Maximum)
|
||||
return;
|
||||
|
||||
if (--countdown > 0 && wormsPresent >= info.Minimum)
|
||||
return;
|
||||
|
||||
countdown = info.SpawnInterval * 25;
|
||||
if (wormsPresent < info.Maximum)
|
||||
SpawnWorm(self);
|
||||
|
||||
var wormLocations = new List<WPos>();
|
||||
|
||||
wormLocations.Add(SpawnWorm(self));
|
||||
while (wormsPresent < info.Minimum)
|
||||
wormLocations.Add(SpawnWorm(self));
|
||||
|
||||
AnnounceWormSign(self, wormLocations);
|
||||
}
|
||||
|
||||
void SpawnWorm (Actor self)
|
||||
WPos SpawnWorm(Actor self)
|
||||
{
|
||||
var spawnPosition = GetRandomSpawnPosition(self);
|
||||
var spawnLocation = self.World.Map.CellContaining(spawnPosition);
|
||||
var spawnPoint = GetRandomSpawnPoint(self);
|
||||
self.World.AddFrameEndTask(w => w.CreateActor(info.WormSignature, new TypeDictionary
|
||||
{
|
||||
new OwnerInit(w.Players.First(x => x.PlayerName == info.WormOwnerPlayer)),
|
||||
new LocationInit(spawnLocation)
|
||||
new LocationInit(spawnPoint.Location)
|
||||
}));
|
||||
wormsPresent++;
|
||||
|
||||
AnnounceWormSign(self, spawnPosition);
|
||||
|
||||
return spawnPoint.CenterPosition;
|
||||
}
|
||||
|
||||
WPos GetRandomSpawnPosition(Actor self)
|
||||
Actor GetRandomSpawnPoint(Actor self)
|
||||
{
|
||||
return spawnPoints.Value.Random(self.World.SharedRandom).CenterPosition;
|
||||
return spawnPoints.Value.Random(self.World.SharedRandom);
|
||||
}
|
||||
|
||||
public void DecreaseWorms()
|
||||
@@ -91,22 +102,17 @@ namespace OpenRA.Mods.D2k
|
||||
wormsPresent--;
|
||||
}
|
||||
|
||||
void AnnounceWormSign(Actor self, WPos wormSpawnPosition)
|
||||
void AnnounceWormSign(Actor self, IEnumerable<WPos> wormLocations)
|
||||
{
|
||||
if (self.World.LocalPlayer == null)
|
||||
if (self.World.LocalPlayer != null)
|
||||
Sound.PlayNotification(self.World.Map.Rules, self.World.LocalPlayer, "Speech", info.WormSignNotification, self.World.LocalPlayer.Country.Race);
|
||||
|
||||
if (radarPings.Value == null)
|
||||
return;
|
||||
|
||||
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>();
|
||||
}
|
||||
foreach (var wormLocation in wormLocations)
|
||||
radarPings.Value.Add(() => true, wormLocation, Color.Red, 50);
|
||||
|
||||
radarPings.Add(() => true, wormSpawnPosition, Color.Red, 50);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.GameRules;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Mods.RA.Move;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
@@ -39,6 +38,7 @@ namespace OpenRA.Mods.RA
|
||||
public IEnumerable<Armament> Armaments { get { return GetArmaments(); } }
|
||||
protected Lazy<IFacing> facing;
|
||||
protected Lazy<Building> building;
|
||||
protected Lazy<IPositionable> positionable;
|
||||
protected Func<IEnumerable<Armament>> GetArmaments;
|
||||
|
||||
readonly Actor self;
|
||||
@@ -56,6 +56,7 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
facing = Exts.Lazy(() => self.TraitOrDefault<IFacing>());
|
||||
building = Exts.Lazy(() => self.TraitOrDefault<Building>());
|
||||
positionable = Exts.Lazy(() => self.Trait<IPositionable>());
|
||||
}
|
||||
|
||||
protected virtual bool CanAttack(Actor self, Target target)
|
||||
@@ -146,8 +147,7 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
if (Info.AttackRequiresEnteringCell)
|
||||
{
|
||||
var positionable = self.TraitOrDefault<IPositionable>();
|
||||
if (positionable == null || !positionable.CanEnterCell(t.Actor.Location, null, false))
|
||||
if (!positionable.Value.CanEnterCell(t.Actor.Location, null, false))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -458,7 +458,7 @@ VICE:
|
||||
MuzzleSplitFacings: 8
|
||||
AttackFrontal:
|
||||
AttackWander:
|
||||
WanderMoveRadius: 4
|
||||
WanderMoveRadius: 2
|
||||
RenderUnit:
|
||||
WithMuzzleFlash:
|
||||
SplitFacings: true
|
||||
|
||||
Binary file not shown.
@@ -121,6 +121,8 @@ Rules:
|
||||
-MPStartLocations:
|
||||
ResourceType@Spice:
|
||||
ValuePerUnit: 0
|
||||
WormManager:
|
||||
Minimum: 1
|
||||
|
||||
Sequences:
|
||||
|
||||
|
||||
@@ -583,7 +583,7 @@ DOGGIE:
|
||||
Weapon: FiendShard
|
||||
AttackFrontal:
|
||||
AttackWander:
|
||||
WanderMoveRadius: 4
|
||||
WanderMoveRadius: 2
|
||||
|
||||
VISSML:
|
||||
Inherits: ^Infantry
|
||||
|
||||
Reference in New Issue
Block a user