Merge pull request #7278 from penev92/bleed_sandworm
Enhance Sandworm behaviour
This commit is contained in:
@@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
// HACK: This would otherwise break targeting frozen actors
|
// HACK: This would otherwise break targeting frozen actors
|
||||||
// The problem is that Shroud.IsTargetable returns false (as it should) for
|
// The problem is that Shroud.IsTargetable returns false (as it should) for
|
||||||
// frozen actors, but we do want to explicitly target the underlying actor here.
|
// frozen actors, but we do want to explicitly target the underlying actor here.
|
||||||
if (type == TargetType.Actor && !Target.Actor.HasTrait<FrozenUnderFog>() && !self.Owner.Shroud.IsTargetable(Target.Actor))
|
if (!attack.Info.IgnoresVisibility && type == TargetType.Actor && !Target.Actor.HasTrait<FrozenUnderFog>() && !self.Owner.Shroud.IsTargetable(Target.Actor))
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
|
|
||||||
// Try to move within range
|
// Try to move within range
|
||||||
|
|||||||
@@ -214,6 +214,7 @@
|
|||||||
<Compile Include="Traits\ExternalCapturable.cs" />
|
<Compile Include="Traits\ExternalCapturable.cs" />
|
||||||
<Compile Include="Traits\ExternalCapturableBar.cs" />
|
<Compile Include="Traits\ExternalCapturableBar.cs" />
|
||||||
<Compile Include="Traits\ExternalCaptures.cs" />
|
<Compile Include="Traits\ExternalCaptures.cs" />
|
||||||
|
<Compile Include="Traits\IgnoresCloak.cs" />
|
||||||
<Compile Include="Traits\IgnoresDisguise.cs" />
|
<Compile Include="Traits\IgnoresDisguise.cs" />
|
||||||
<Compile Include="Traits\DetectCloaked.cs" />
|
<Compile Include="Traits\DetectCloaked.cs" />
|
||||||
<Compile Include="Traits\EngineerRepair.cs" />
|
<Compile Include="Traits\EngineerRepair.cs" />
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ using System.Drawing;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Activities;
|
using OpenRA.Activities;
|
||||||
using OpenRA.GameRules;
|
using OpenRA.GameRules;
|
||||||
using OpenRA.Mods.Common;
|
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
@@ -30,6 +29,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[Desc("Does the attack type require the attacker to enter the target's cell?")]
|
[Desc("Does the attack type require the attacker to enter the target's cell?")]
|
||||||
public readonly bool AttackRequiresEnteringCell = false;
|
public readonly bool AttackRequiresEnteringCell = false;
|
||||||
|
|
||||||
|
[Desc("Does not care about shroud or fog. Enables the actor to launch an attack against a target even if he has no visibility of it.")]
|
||||||
|
public readonly bool IgnoresVisibility = false;
|
||||||
|
|
||||||
public abstract object Create(ActorInitializer init);
|
public abstract object Create(ActorInitializer init);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,9 +29,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
attackMove = self.TraitOrDefault<AttackMove>();
|
attackMove = self.TraitOrDefault<AttackMove>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void DoAction(Actor self, CPos targetPos)
|
public override void DoAction(Actor self, CPos targetCell)
|
||||||
{
|
{
|
||||||
attackMove.ResolveOrder(self, new Order("AttackMove", self, false) { TargetLocation = targetPos });
|
attackMove.ResolveOrder(self, new Order("AttackMove", self, false) { TargetLocation = targetCell });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
18
OpenRA.Mods.Common/Traits/IgnoresCloak.cs
Normal file
18
OpenRA.Mods.Common/Traits/IgnoresCloak.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
|
||||||
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
|
* available to you under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation. For more information,
|
||||||
|
* see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.Common.Traits
|
||||||
|
{
|
||||||
|
[Desc("This actor does not care about any type of cloak its targets might have, regardless of distance.")]
|
||||||
|
class IgnoresCloakInfo : TraitInfo<IgnoresCloak> { }
|
||||||
|
class IgnoresCloak { }
|
||||||
|
}
|
||||||
@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public virtual bool TargetableBy(Actor self, Actor viewer)
|
public virtual bool TargetableBy(Actor self, Actor viewer)
|
||||||
{
|
{
|
||||||
if (cloak == null)
|
if (cloak == null || (!viewer.IsDead && viewer.HasTrait<IgnoresCloak>()))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return cloak.IsVisible(self, viewer.Owner);
|
return cloak.IsVisible(self, viewer.Owner);
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ using OpenRA.Traits;
|
|||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
[Desc("Wanders around aimlessly while idle.")]
|
[Desc("Wanders around aimlessly while idle.")]
|
||||||
abstract class WandersInfo : ITraitInfo
|
public abstract class WandersInfo : ITraitInfo
|
||||||
{
|
{
|
||||||
public readonly int WanderMoveRadius = 10;
|
public readonly int WanderMoveRadius = 1;
|
||||||
|
|
||||||
[Desc("Number of ticks to wait before decreasing the effective move radius.")]
|
[Desc("Number of ticks to wait before decreasing the effective move radius.")]
|
||||||
public readonly int TicksToWaitBeforeReducingMoveRadius = 5;
|
public readonly int TicksToWaitBeforeReducingMoveRadius = 5;
|
||||||
@@ -30,7 +30,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public abstract object Create(ActorInitializer init);
|
public abstract object Create(ActorInitializer init);
|
||||||
}
|
}
|
||||||
|
|
||||||
class Wanders : INotifyIdle, INotifyBecomingIdle
|
public class Wanders : INotifyIdle, INotifyBecomingIdle
|
||||||
{
|
{
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
readonly WandersInfo info;
|
readonly WandersInfo info;
|
||||||
@@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
effectiveMoveRadius = info.WanderMoveRadius;
|
effectiveMoveRadius = info.WanderMoveRadius;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnBecomingIdle(Actor self)
|
public virtual void OnBecomingIdle(Actor self)
|
||||||
{
|
{
|
||||||
countdown = self.World.SharedRandom.Next(info.MinMoveDelayInTicks, info.MaxMoveDelayInTicks);
|
countdown = self.World.SharedRandom.Next(info.MinMoveDelayInTicks, info.MaxMoveDelayInTicks);
|
||||||
}
|
}
|
||||||
@@ -56,9 +56,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (--countdown > 0)
|
if (--countdown > 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var targetPos = PickTargetLocation();
|
var targetCell = PickTargetLocation();
|
||||||
if (targetPos != CPos.Zero)
|
if (targetCell != CPos.Zero)
|
||||||
DoAction(self, targetPos);
|
DoAction(self, targetCell);
|
||||||
}
|
}
|
||||||
|
|
||||||
CPos PickTargetLocation()
|
CPos PickTargetLocation()
|
||||||
@@ -81,7 +81,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return targetCell;
|
return targetCell;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void DoAction(Actor self, CPos targetPos)
|
public virtual void DoAction(Actor self, CPos targetCell)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException("Base class Wanders does not implement method DoAction!");
|
throw new NotImplementedException("Base class Wanders does not implement method DoAction!");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,9 +14,6 @@ using OpenRA.Activities;
|
|||||||
using OpenRA.GameRules;
|
using OpenRA.GameRules;
|
||||||
using OpenRA.Mods.Common.Traits;
|
using OpenRA.Mods.Common.Traits;
|
||||||
using OpenRA.Mods.D2k.Traits;
|
using OpenRA.Mods.D2k.Traits;
|
||||||
using OpenRA.Mods.RA;
|
|
||||||
using OpenRA.Mods.RA.Activities;
|
|
||||||
using OpenRA.Mods.RA.Traits;
|
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.D2k.Activities
|
namespace OpenRA.Mods.D2k.Activities
|
||||||
@@ -29,11 +26,11 @@ namespace OpenRA.Mods.D2k.Activities
|
|||||||
|
|
||||||
readonly CPos location;
|
readonly CPos location;
|
||||||
readonly Target target;
|
readonly Target target;
|
||||||
|
readonly Sandworm sandworm;
|
||||||
readonly WeaponInfo weapon;
|
readonly WeaponInfo weapon;
|
||||||
readonly RenderUnit renderUnit;
|
readonly RenderUnit renderUnit;
|
||||||
readonly RadarPings radarPings;
|
readonly RadarPings radarPings;
|
||||||
readonly AttackSwallow swallow;
|
readonly AttackSwallow swallow;
|
||||||
readonly AttackSwallowInfo swallowInfo;
|
|
||||||
readonly IPositionable positionable;
|
readonly IPositionable positionable;
|
||||||
|
|
||||||
int countdown;
|
int countdown;
|
||||||
@@ -43,12 +40,12 @@ namespace OpenRA.Mods.D2k.Activities
|
|||||||
{
|
{
|
||||||
this.target = target;
|
this.target = target;
|
||||||
this.weapon = weapon;
|
this.weapon = weapon;
|
||||||
|
sandworm = self.Trait<Sandworm>();
|
||||||
positionable = self.Trait<Mobile>();
|
positionable = self.Trait<Mobile>();
|
||||||
swallow = self.Trait<AttackSwallow>();
|
swallow = self.Trait<AttackSwallow>();
|
||||||
swallowInfo = (AttackSwallowInfo)swallow.Info;
|
|
||||||
renderUnit = self.Trait<RenderUnit>();
|
renderUnit = self.Trait<RenderUnit>();
|
||||||
radarPings = self.World.WorldActor.TraitOrDefault<RadarPings>();
|
radarPings = self.World.WorldActor.TraitOrDefault<RadarPings>();
|
||||||
countdown = swallowInfo.AttackTime;
|
countdown = swallow.Info.AttackTime;
|
||||||
|
|
||||||
renderUnit.DefaultAnimation.ReplaceAnim("burrowed");
|
renderUnit.DefaultAnimation.ReplaceAnim("burrowed");
|
||||||
stance = AttackState.Burrowed;
|
stance = AttackState.Burrowed;
|
||||||
@@ -70,6 +67,7 @@ namespace OpenRA.Mods.D2k.Activities
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
stance = AttackState.EmergingAboveGround;
|
stance = AttackState.EmergingAboveGround;
|
||||||
|
sandworm.IsAttacking = true;
|
||||||
|
|
||||||
foreach (var actor in lunch)
|
foreach (var actor in lunch)
|
||||||
actor.World.AddFrameEndTask(_ => actor.Destroy());
|
actor.World.AddFrameEndTask(_ => actor.Destroy());
|
||||||
@@ -94,7 +92,7 @@ namespace OpenRA.Mods.D2k.Activities
|
|||||||
|
|
||||||
void NotifyPlayer(Player player, WPos location)
|
void NotifyPlayer(Player player, WPos location)
|
||||||
{
|
{
|
||||||
Sound.PlayNotification(player.World.Map.Rules, player, "Speech", swallowInfo.WormAttackNotification, player.Country.Race);
|
Sound.PlayNotification(player.World.Map.Rules, player, "Speech", swallow.Info.WormAttackNotification, player.Country.Race);
|
||||||
radarPings.Add(() => true, location, Color.Red, 50);
|
radarPings.Add(() => true, location, Color.Red, 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,15 +107,17 @@ namespace OpenRA.Mods.D2k.Activities
|
|||||||
// Wait for the worm to get back underground
|
// Wait for the worm to get back underground
|
||||||
if (stance == AttackState.ReturningUnderground)
|
if (stance == AttackState.ReturningUnderground)
|
||||||
{
|
{
|
||||||
// There is a 50-50 chance that the worm would just go away
|
sandworm.IsAttacking = false;
|
||||||
if (self.World.SharedRandom.Next() % 2 == 0)
|
|
||||||
|
// There is a chance that the worm would just go away after attacking
|
||||||
|
if (self.World.SharedRandom.Next() % 100 <= sandworm.Info.ChanceToDisappear)
|
||||||
{
|
{
|
||||||
self.CancelActivity();
|
self.CancelActivity();
|
||||||
self.World.AddFrameEndTask(w => w.Remove(self));
|
self.World.AddFrameEndTask(w => w.Remove(self));
|
||||||
|
|
||||||
var wormManager = self.World.WorldActor.TraitOrDefault<WormManager>();
|
var wormManager = self.World.WorldActor.TraitOrDefault<WormManager>();
|
||||||
if (wormManager != null)
|
if (wormManager != null)
|
||||||
wormManager.DecreaseWorms();
|
wormManager.DecreaseWormCount();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
renderUnit.DefaultAnimation.ReplaceAnim("idle");
|
renderUnit.DefaultAnimation.ReplaceAnim("idle");
|
||||||
@@ -138,7 +138,7 @@ namespace OpenRA.Mods.D2k.Activities
|
|||||||
return NextActivity;
|
return NextActivity;
|
||||||
}
|
}
|
||||||
|
|
||||||
countdown = swallowInfo.ReturnTime;
|
countdown = swallow.Info.ReturnTime;
|
||||||
stance = AttackState.ReturningUnderground;
|
stance = AttackState.ReturningUnderground;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -81,6 +81,7 @@
|
|||||||
<Compile Include="Traits\Render\WithDockingOverlay.cs" />
|
<Compile Include="Traits\Render\WithDockingOverlay.cs" />
|
||||||
<Compile Include="Traits\Render\WithDeliveryOverlay.cs" />
|
<Compile Include="Traits\Render\WithDeliveryOverlay.cs" />
|
||||||
<Compile Include="Traits\Render\WithProductionOverlay.cs" />
|
<Compile Include="Traits\Render\WithProductionOverlay.cs" />
|
||||||
|
<Compile Include="Traits\Sandworm.cs" />
|
||||||
<Compile Include="Traits\TemporaryOwnerManager.cs" />
|
<Compile Include="Traits\TemporaryOwnerManager.cs" />
|
||||||
<Compile Include="Traits\ThrowsShrapnel.cs" />
|
<Compile Include="Traits\ThrowsShrapnel.cs" />
|
||||||
<Compile Include="Traits\World\BuildableTerrainLayer.cs" />
|
<Compile Include="Traits\World\BuildableTerrainLayer.cs" />
|
||||||
@@ -90,6 +91,8 @@
|
|||||||
<Compile Include="Traits\World\PaletteFromR8.cs" />
|
<Compile Include="Traits\World\PaletteFromR8.cs" />
|
||||||
<Compile Include="Traits\World\PaletteFromScaledPalette.cs" />
|
<Compile Include="Traits\World\PaletteFromScaledPalette.cs" />
|
||||||
<Compile Include="Traits\World\WormManager.cs" />
|
<Compile Include="Traits\World\WormManager.cs" />
|
||||||
|
<Compile Include="Traits\AttractsWorms.cs" />
|
||||||
|
<Compile Include="Traits\WormSpawner.cs" />
|
||||||
<Compile Include="Warheads\ChangeOwnerWarhead.cs" />
|
<Compile Include="Warheads\ChangeOwnerWarhead.cs" />
|
||||||
<Compile Include="Widgets\BuildPaletteWidget.cs" />
|
<Compile Include="Widgets\BuildPaletteWidget.cs" />
|
||||||
<Compile Include="Widgets\MoneyBinWidget.cs" />
|
<Compile Include="Widgets\MoneyBinWidget.cs" />
|
||||||
|
|||||||
@@ -30,8 +30,13 @@ namespace OpenRA.Mods.D2k.Traits
|
|||||||
|
|
||||||
class AttackSwallow : AttackFrontal
|
class AttackSwallow : AttackFrontal
|
||||||
{
|
{
|
||||||
|
public readonly new AttackSwallowInfo Info;
|
||||||
|
|
||||||
public AttackSwallow(Actor self, AttackSwallowInfo info)
|
public AttackSwallow(Actor self, AttackSwallowInfo info)
|
||||||
: base(self, info) { }
|
: base(self, info)
|
||||||
|
{
|
||||||
|
Info = info;
|
||||||
|
}
|
||||||
|
|
||||||
public override void DoAttack(Actor self, Target target)
|
public override void DoAttack(Actor self, Target target)
|
||||||
{
|
{
|
||||||
|
|||||||
60
OpenRA.Mods.D2k/Traits/AttractsWorms.cs
Normal file
60
OpenRA.Mods.D2k/Traits/AttractsWorms.cs
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
|
||||||
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
|
* available to you under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation. For more information,
|
||||||
|
* see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.D2k.Traits
|
||||||
|
{
|
||||||
|
[Desc("This actor makes noise, which causes them to be targeted by actors with the Sandworm trait.")]
|
||||||
|
public class AttractsWormsInfo : ITraitInfo
|
||||||
|
{
|
||||||
|
[Desc("How much noise this actor produces.")]
|
||||||
|
public readonly int Intensity = 0;
|
||||||
|
|
||||||
|
[Desc("Noise percentage at Range step away from the actor.")]
|
||||||
|
public readonly int[] Falloff = { 100, 100, 25, 11, 6, 4, 3, 2, 1, 0 };
|
||||||
|
|
||||||
|
[Desc("Range between falloff steps.")]
|
||||||
|
public readonly WRange Spread = new WRange(3072);
|
||||||
|
|
||||||
|
[Desc("Ranges at which each Falloff step is defined. Overrides Spread.")]
|
||||||
|
public WRange[] Range = null;
|
||||||
|
|
||||||
|
public object Create(ActorInitializer init) { return new AttractsWorms(this); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class AttractsWorms
|
||||||
|
{
|
||||||
|
public readonly AttractsWormsInfo Info;
|
||||||
|
|
||||||
|
public AttractsWorms(AttractsWormsInfo info)
|
||||||
|
{
|
||||||
|
Info = info;
|
||||||
|
|
||||||
|
if (info.Range == null)
|
||||||
|
info.Range = Exts.MakeArray(info.Falloff.Length, i => i * info.Spread);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetNoisePercentageAtDistance(int distance)
|
||||||
|
{
|
||||||
|
var inner = Info.Range[0].Range;
|
||||||
|
for (var i = 1; i < Info.Range.Length; i++)
|
||||||
|
{
|
||||||
|
var outer = Info.Range[i].Range;
|
||||||
|
if (outer > distance)
|
||||||
|
return int2.Lerp(Info.Falloff[i - 1], Info.Falloff[i], distance - inner, outer - inner);
|
||||||
|
|
||||||
|
inner = outer;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
159
OpenRA.Mods.D2k/Traits/Sandworm.cs
Normal file
159
OpenRA.Mods.D2k/Traits/Sandworm.cs
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
|
||||||
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
|
* available to you under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation. For more information,
|
||||||
|
* see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using OpenRA.Mods.Common.Traits;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.D2k.Traits
|
||||||
|
{
|
||||||
|
class SandwormInfo : WandersInfo, Requires<MobileInfo>, Requires<RenderUnitInfo>, Requires<AttackBaseInfo>
|
||||||
|
{
|
||||||
|
[Desc("Time between rescanning for targets (in ticks).")]
|
||||||
|
public readonly int TargetRescanInterval = 32;
|
||||||
|
|
||||||
|
[Desc("The radius in which the worm \"searches\" for targets.")]
|
||||||
|
public readonly WRange MaxSearchRadius = WRange.FromCells(27);
|
||||||
|
|
||||||
|
[Desc("The range at which the worm launches an attack regardless of noise levels.")]
|
||||||
|
public readonly WRange IgnoreNoiseAttackRange = WRange.FromCells(3);
|
||||||
|
|
||||||
|
[Desc("The chance this actor has of disappearing after it attacks (in %).")]
|
||||||
|
public readonly int ChanceToDisappear = 80;
|
||||||
|
|
||||||
|
[Desc("Name of the sequence that is used when the actor is idle or moving (not attacking).")]
|
||||||
|
public readonly string IdleSequence = "idle";
|
||||||
|
|
||||||
|
public override object Create(ActorInitializer init) { return new Sandworm(init.Self, this); }
|
||||||
|
}
|
||||||
|
|
||||||
|
class Sandworm : Wanders, ITick, INotifyKilled
|
||||||
|
{
|
||||||
|
public readonly SandwormInfo Info;
|
||||||
|
|
||||||
|
readonly WormManager manager;
|
||||||
|
readonly Lazy<Mobile> mobile;
|
||||||
|
readonly Lazy<RenderUnit> renderUnit;
|
||||||
|
readonly Lazy<AttackBase> attackTrait;
|
||||||
|
|
||||||
|
public bool IsMovingTowardTarget { get; private set; }
|
||||||
|
|
||||||
|
public bool IsAttacking;
|
||||||
|
|
||||||
|
int targetCountdown;
|
||||||
|
|
||||||
|
public Sandworm(Actor self, SandwormInfo info)
|
||||||
|
: base(self, info)
|
||||||
|
{
|
||||||
|
Info = info;
|
||||||
|
mobile = Exts.Lazy(self.Trait<Mobile>);
|
||||||
|
renderUnit = Exts.Lazy(self.Trait<RenderUnit>);
|
||||||
|
attackTrait = Exts.Lazy(self.Trait<AttackBase>);
|
||||||
|
manager = self.World.WorldActor.Trait<WormManager>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnBecomingIdle(Actor self)
|
||||||
|
{
|
||||||
|
if (renderUnit.Value.DefaultAnimation.CurrentSequence.Name != Info.IdleSequence)
|
||||||
|
renderUnit.Value.DefaultAnimation.PlayRepeating("idle");
|
||||||
|
|
||||||
|
base.OnBecomingIdle(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DoAction(Actor self, CPos targetCell)
|
||||||
|
{
|
||||||
|
IsMovingTowardTarget = false;
|
||||||
|
|
||||||
|
RescanForTargets(self);
|
||||||
|
|
||||||
|
if (IsMovingTowardTarget)
|
||||||
|
return;
|
||||||
|
|
||||||
|
self.QueueActivity(mobile.Value.MoveWithinRange(Target.FromCell(self.World, targetCell, SubCell.Any), WRange.FromCells(1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Tick(Actor self)
|
||||||
|
{
|
||||||
|
if (--targetCountdown > 0 || IsAttacking || !self.IsInWorld)
|
||||||
|
return;
|
||||||
|
|
||||||
|
RescanForTargets(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RescanForTargets(Actor self)
|
||||||
|
{
|
||||||
|
targetCountdown = Info.TargetRescanInterval;
|
||||||
|
|
||||||
|
var actorsInRange = self.World.FindActorsInCircle(self.CenterPosition, Info.MaxSearchRadius);
|
||||||
|
var noiseDirection = WVec.Zero;
|
||||||
|
|
||||||
|
foreach (var actor in actorsInRange)
|
||||||
|
{
|
||||||
|
if (!actor.IsInWorld)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// TODO: Test if we really want to ignore actors that are on rock
|
||||||
|
if (!mobile.Value.CanEnterCell(actor.Location, null, false))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var noise = actor.TraitOrDefault<AttractsWorms>();
|
||||||
|
if (noise == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var distance = actor.CenterPosition - self.CenterPosition;
|
||||||
|
var length = distance.Length;
|
||||||
|
|
||||||
|
// Actor is too far to be heard
|
||||||
|
if (noise.Info.Range[noise.Info.Range.Length - 1].Range < length)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// If close enough, we don't care about other actors
|
||||||
|
if (length <= Info.IgnoreNoiseAttackRange.Range)
|
||||||
|
{
|
||||||
|
self.CancelActivity();
|
||||||
|
attackTrait.Value.ResolveOrder(self, new Order("Attack", actor, true) { TargetActor = actor });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var direction = 1024 * distance / length;
|
||||||
|
var percentage = noise.GetNoisePercentageAtDistance(length);
|
||||||
|
|
||||||
|
noiseDirection += direction * noise.Info.Intensity * percentage / 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
// No target was found
|
||||||
|
if (noiseDirection == WVec.Zero)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var moveTo = self.World.Map.CellContaining(self.CenterPosition + noiseDirection);
|
||||||
|
|
||||||
|
while (!self.World.Map.Contains(moveTo) || !mobile.Value.CanEnterCell(moveTo, null, false))
|
||||||
|
{
|
||||||
|
noiseDirection /= 2;
|
||||||
|
moveTo = self.World.Map.CellContaining(self.CenterPosition + noiseDirection);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't get stuck when the noise is distributed evenly! This will make the worm wander instead of trying to move to where it already is
|
||||||
|
if (moveTo == self.Location)
|
||||||
|
{
|
||||||
|
self.CancelActivity();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.QueueActivity(false, mobile.Value.MoveTo(moveTo, 3));
|
||||||
|
IsMovingTowardTarget = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Killed(Actor self, AttackInfo e)
|
||||||
|
{
|
||||||
|
manager.DecreaseWormCount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,31 +27,32 @@ namespace OpenRA.Mods.D2k.Traits
|
|||||||
[Desc("Maximum number of worms")]
|
[Desc("Maximum number of worms")]
|
||||||
public readonly int Maximum = 4;
|
public readonly int Maximum = 4;
|
||||||
|
|
||||||
[Desc("Average time (seconds) between worm spawn")]
|
[Desc("Time (in ticks) between worm spawn.")]
|
||||||
public readonly int SpawnInterval = 120;
|
public readonly int SpawnInterval = 3000;
|
||||||
|
|
||||||
|
[Desc("Name of the actor that will be spawned.")]
|
||||||
|
public readonly string WormSignature = "sandworm";
|
||||||
|
|
||||||
public readonly string WormSignNotification = "WormSign";
|
public readonly string WormSignNotification = "WormSign";
|
||||||
|
|
||||||
public readonly string WormSignature = "sandworm";
|
|
||||||
public readonly string WormOwnerPlayer = "Creeps";
|
public readonly string WormOwnerPlayer = "Creeps";
|
||||||
|
|
||||||
public object Create(ActorInitializer init) { return new WormManager(this, init.Self); }
|
public object Create(ActorInitializer init) { return new WormManager(init.Self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
class WormManager : ITick
|
class WormManager : ITick
|
||||||
{
|
{
|
||||||
readonly WormManagerInfo info;
|
readonly WormManagerInfo info;
|
||||||
readonly Lazy<Actor[]> spawnPoints;
|
readonly Lazy<Actor[]> spawnPointActors;
|
||||||
readonly Lazy<RadarPings> radarPings;
|
readonly Lazy<RadarPings> radarPings;
|
||||||
|
|
||||||
int countdown;
|
int spawnCountdown;
|
||||||
int wormsPresent;
|
int wormsPresent;
|
||||||
|
|
||||||
public WormManager(WormManagerInfo info, Actor self)
|
public WormManager(Actor self, WormManagerInfo info)
|
||||||
{
|
{
|
||||||
this.info = info;
|
this.info = info;
|
||||||
radarPings = Exts.Lazy(() => self.World.WorldActor.Trait<RadarPings>());
|
radarPings = Exts.Lazy(() => self.World.WorldActor.Trait<RadarPings>());
|
||||||
spawnPoints = Exts.Lazy(() => self.World.ActorsWithTrait<WormSpawner>().Select(x => x.Actor).ToArray());
|
spawnPointActors = Exts.Lazy(() => self.World.ActorsWithTrait<WormSpawner>().Select(x => x.Actor).ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick(Actor self)
|
public void Tick(Actor self)
|
||||||
@@ -59,18 +60,17 @@ namespace OpenRA.Mods.D2k.Traits
|
|||||||
if (!self.World.LobbyInfo.GlobalSettings.Creeps)
|
if (!self.World.LobbyInfo.GlobalSettings.Creeps)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// TODO: It would be even better to stop
|
if (!spawnPointActors.Value.Any())
|
||||||
if (!spawnPoints.Value.Any())
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Apparantly someone doesn't want worms or the maximum number of worms has been reached
|
// Apparantly someone doesn't want worms or the maximum number of worms has been reached
|
||||||
if (info.Maximum < 1 || wormsPresent >= info.Maximum)
|
if (info.Maximum < 1 || wormsPresent >= info.Maximum)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (--countdown > 0 && wormsPresent >= info.Minimum)
|
if (--spawnCountdown > 0 && wormsPresent >= info.Minimum)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
countdown = info.SpawnInterval * 25;
|
spawnCountdown = info.SpawnInterval;
|
||||||
|
|
||||||
var wormLocations = new List<WPos>();
|
var wormLocations = new List<WPos>();
|
||||||
|
|
||||||
@@ -100,10 +100,10 @@ namespace OpenRA.Mods.D2k.Traits
|
|||||||
|
|
||||||
Actor GetRandomSpawnPoint(Actor self)
|
Actor GetRandomSpawnPoint(Actor self)
|
||||||
{
|
{
|
||||||
return spawnPoints.Value.Random(self.World.SharedRandom);
|
return spawnPointActors.Value.Random(self.World.SharedRandom);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DecreaseWorms()
|
public void DecreaseWormCount()
|
||||||
{
|
{
|
||||||
wormsPresent--;
|
wormsPresent--;
|
||||||
}
|
}
|
||||||
@@ -120,8 +120,4 @@ namespace OpenRA.Mods.D2k.Traits
|
|||||||
radarPings.Value.Add(() => true, wormLocation, Color.Red, 50);
|
radarPings.Value.Add(() => true, wormLocation, Color.Red, 50);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Desc("An actor with this trait indicates a valid spawn point for sandworms.")]
|
|
||||||
class WormSpawnerInfo : TraitInfo<WormSpawner> { }
|
|
||||||
class WormSpawner { }
|
|
||||||
}
|
}
|
||||||
|
|||||||
18
OpenRA.Mods.D2k/Traits/WormSpawner.cs
Normal file
18
OpenRA.Mods.D2k/Traits/WormSpawner.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
|
||||||
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
|
* available to you under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation. For more information,
|
||||||
|
* see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.D2k.Traits
|
||||||
|
{
|
||||||
|
[Desc("An actor with this trait indicates a valid spawn point for sandworms.")]
|
||||||
|
class WormSpawnerInfo : TraitInfo<WormSpawner> { }
|
||||||
|
class WormSpawner { }
|
||||||
|
}
|
||||||
@@ -24,7 +24,7 @@ SANDWORM:
|
|||||||
Name: Sandworm
|
Name: Sandworm
|
||||||
Description: Attracted by vibrations in the sand.\nWill eat units whole and has a large appetite.
|
Description: Attracted by vibrations in the sand.\nWill eat units whole and has a large appetite.
|
||||||
Health:
|
Health:
|
||||||
HP: 10000
|
HP: 1200
|
||||||
Radius: 3
|
Radius: 3
|
||||||
Armor:
|
Armor:
|
||||||
Type: None
|
Type: None
|
||||||
@@ -35,9 +35,7 @@ SANDWORM:
|
|||||||
Dune: 100
|
Dune: 100
|
||||||
Spice: 100
|
Spice: 100
|
||||||
TargetableUnit:
|
TargetableUnit:
|
||||||
TargetTypes: Underground
|
TargetTypes: Ground
|
||||||
RevealsShroud:
|
|
||||||
Range: 32c0
|
|
||||||
RenderUnit:
|
RenderUnit:
|
||||||
WithAttackOverlay:
|
WithAttackOverlay:
|
||||||
Sequence: sand
|
Sequence: sand
|
||||||
@@ -47,9 +45,9 @@ SANDWORM:
|
|||||||
UseLocation: yes
|
UseLocation: yes
|
||||||
AttackSwallow:
|
AttackSwallow:
|
||||||
AttackRequiresEnteringCell: true
|
AttackRequiresEnteringCell: true
|
||||||
AttackMove:
|
IgnoresVisibility: true
|
||||||
AttackWander:
|
|
||||||
AutoTarget:
|
|
||||||
ScanRadius: 32
|
|
||||||
Armament:
|
Armament:
|
||||||
Weapon: WormJaw
|
Weapon: WormJaw
|
||||||
|
Sandworm:
|
||||||
|
WanderMoveRadius: 5
|
||||||
|
IgnoresCloak:
|
||||||
@@ -200,6 +200,8 @@ SONICTANK:
|
|||||||
EmptyWeapon: UnitExplodeSmall
|
EmptyWeapon: UnitExplodeSmall
|
||||||
LeavesHusk:
|
LeavesHusk:
|
||||||
HuskActor: Sonictank.Husk
|
HuskActor: Sonictank.Husk
|
||||||
|
AttractsWorms:
|
||||||
|
Intensity: 600
|
||||||
|
|
||||||
SONICTANK.Husk:
|
SONICTANK.Husk:
|
||||||
Inherits: ^Husk
|
Inherits: ^Husk
|
||||||
@@ -272,4 +274,6 @@ GRENADIER:
|
|||||||
Explodes:
|
Explodes:
|
||||||
Weapon: UnitExplodeSmall
|
Weapon: UnitExplodeSmall
|
||||||
Chance: 100
|
Chance: 100
|
||||||
|
AttractsWorms:
|
||||||
|
Intensity: 180
|
||||||
|
|
||||||
|
|||||||
@@ -203,6 +203,8 @@ DEVAST:
|
|||||||
Bounds: 44,38,0,0
|
Bounds: 44,38,0,0
|
||||||
LeavesHusk:
|
LeavesHusk:
|
||||||
HuskActor: Devast.Husk
|
HuskActor: Devast.Husk
|
||||||
|
AttractsWorms:
|
||||||
|
Intensity: 700
|
||||||
|
|
||||||
DEVAST.Husk:
|
DEVAST.Husk:
|
||||||
Inherits: ^Husk
|
Inherits: ^Husk
|
||||||
@@ -239,4 +241,6 @@ SARDAUKAR:
|
|||||||
Armament@SECONDARY:
|
Armament@SECONDARY:
|
||||||
Weapon: Slung
|
Weapon: Slung
|
||||||
AttackFrontal:
|
AttackFrontal:
|
||||||
|
AttractsWorms:
|
||||||
|
Intensity: 180
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ RIFLE:
|
|||||||
Weapon: LMG
|
Weapon: LMG
|
||||||
AttackFrontal:
|
AttackFrontal:
|
||||||
TakeCover:
|
TakeCover:
|
||||||
|
AttractsWorms:
|
||||||
|
Intensity: 120
|
||||||
|
|
||||||
ENGINEER:
|
ENGINEER:
|
||||||
Inherits: ^Infantry
|
Inherits: ^Infantry
|
||||||
@@ -46,6 +48,8 @@ ENGINEER:
|
|||||||
Captures:
|
Captures:
|
||||||
CaptureTypes: husk
|
CaptureTypes: husk
|
||||||
-AutoTarget:
|
-AutoTarget:
|
||||||
|
AttractsWorms:
|
||||||
|
Intensity: 180
|
||||||
|
|
||||||
BAZOOKA:
|
BAZOOKA:
|
||||||
Inherits: ^Infantry
|
Inherits: ^Infantry
|
||||||
@@ -69,6 +73,8 @@ BAZOOKA:
|
|||||||
LocalOffset: 0,0,555
|
LocalOffset: 0,0,555
|
||||||
AttackFrontal:
|
AttackFrontal:
|
||||||
TakeCover:
|
TakeCover:
|
||||||
|
AttractsWorms:
|
||||||
|
Intensity: 180
|
||||||
|
|
||||||
MEDIC:
|
MEDIC:
|
||||||
Inherits: ^Infantry
|
Inherits: ^Infantry
|
||||||
@@ -99,4 +105,6 @@ MEDIC:
|
|||||||
Passenger:
|
Passenger:
|
||||||
PipType: Blue
|
PipType: Blue
|
||||||
-AutoTarget:
|
-AutoTarget:
|
||||||
|
AttractsWorms:
|
||||||
|
Intensity: 180
|
||||||
|
|
||||||
|
|||||||
@@ -179,6 +179,8 @@ RAIDER:
|
|||||||
Explodes:
|
Explodes:
|
||||||
Weapon: UnitExplodeTiny
|
Weapon: UnitExplodeTiny
|
||||||
EmptyWeapon: UnitExplodeTiny
|
EmptyWeapon: UnitExplodeTiny
|
||||||
|
AttractsWorms:
|
||||||
|
Intensity: 420
|
||||||
|
|
||||||
STEALTHRAIDER:
|
STEALTHRAIDER:
|
||||||
Inherits: RAIDER
|
Inherits: RAIDER
|
||||||
@@ -247,6 +249,8 @@ DEVIATORTANK:
|
|||||||
Bounds: 30,30
|
Bounds: 30,30
|
||||||
LeavesHusk:
|
LeavesHusk:
|
||||||
HuskActor: Deviatortank.Husk
|
HuskActor: Deviatortank.Husk
|
||||||
|
AttractsWorms:
|
||||||
|
Intensity: 600
|
||||||
|
|
||||||
DEVIATORTANK.Husk:
|
DEVIATORTANK.Husk:
|
||||||
Inherits: ^Husk
|
Inherits: ^Husk
|
||||||
@@ -278,4 +282,6 @@ SABOTEUR:
|
|||||||
C4Demolition:
|
C4Demolition:
|
||||||
C4Delay: 45
|
C4Delay: 45
|
||||||
-AutoTarget:
|
-AutoTarget:
|
||||||
|
AttractsWorms:
|
||||||
|
Intensity: 120
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,8 @@
|
|||||||
TransformSounds: BUILD1.WAV
|
TransformSounds: BUILD1.WAV
|
||||||
LeavesHusk:
|
LeavesHusk:
|
||||||
HuskActor: MCV.Husk
|
HuskActor: MCV.Husk
|
||||||
|
AttractsWorms:
|
||||||
|
Intensity: 700
|
||||||
|
|
||||||
MCV.Husk:
|
MCV.Husk:
|
||||||
Inherits: ^Husk
|
Inherits: ^Husk
|
||||||
@@ -82,6 +84,8 @@ HARVESTER:
|
|||||||
LeavesHusk:
|
LeavesHusk:
|
||||||
HuskActor: Harvester.Husk
|
HuskActor: Harvester.Husk
|
||||||
WithHarvestAnimation:
|
WithHarvestAnimation:
|
||||||
|
AttractsWorms:
|
||||||
|
Intensity: 700
|
||||||
|
|
||||||
HARVESTER.Husk:
|
HARVESTER.Husk:
|
||||||
Inherits: ^Husk
|
Inherits: ^Husk
|
||||||
@@ -135,6 +139,8 @@ TRIKE:
|
|||||||
Explodes:
|
Explodes:
|
||||||
Weapon: UnitExplodeTiny
|
Weapon: UnitExplodeTiny
|
||||||
EmptyWeapon: UnitExplodeTiny
|
EmptyWeapon: UnitExplodeTiny
|
||||||
|
AttractsWorms:
|
||||||
|
Intensity: 420
|
||||||
|
|
||||||
TRIKE.starport:
|
TRIKE.starport:
|
||||||
Inherits: TRIKE
|
Inherits: TRIKE
|
||||||
@@ -176,6 +182,8 @@ QUAD:
|
|||||||
EmptyWeapon: UnitExplodeTiny
|
EmptyWeapon: UnitExplodeTiny
|
||||||
Selectable:
|
Selectable:
|
||||||
Bounds: 24,24
|
Bounds: 24,24
|
||||||
|
AttractsWorms:
|
||||||
|
Intensity: 470
|
||||||
|
|
||||||
QUAD.starport:
|
QUAD.starport:
|
||||||
Inherits: QUAD
|
Inherits: QUAD
|
||||||
@@ -226,6 +234,8 @@ QUAD.starport:
|
|||||||
EmptyWeapon: UnitExplodeSmall
|
EmptyWeapon: UnitExplodeSmall
|
||||||
Selectable:
|
Selectable:
|
||||||
Bounds: 30,30
|
Bounds: 30,30
|
||||||
|
AttractsWorms:
|
||||||
|
Intensity: 520
|
||||||
|
|
||||||
^COMBAT.Husk:
|
^COMBAT.Husk:
|
||||||
Inherits: ^Husk
|
Inherits: ^Husk
|
||||||
@@ -278,6 +288,8 @@ SIEGETANK:
|
|||||||
Bounds: 30,30
|
Bounds: 30,30
|
||||||
LeavesHusk:
|
LeavesHusk:
|
||||||
HuskActor: Siegetank.Husk
|
HuskActor: Siegetank.Husk
|
||||||
|
AttractsWorms:
|
||||||
|
Intensity: 600
|
||||||
|
|
||||||
SIEGETANK.Husk:
|
SIEGETANK.Husk:
|
||||||
Inherits: ^Husk
|
Inherits: ^Husk
|
||||||
@@ -333,6 +345,8 @@ MISSILETANK:
|
|||||||
Bounds: 30,30
|
Bounds: 30,30
|
||||||
LeavesHusk:
|
LeavesHusk:
|
||||||
HuskActor: Missiletank.Husk
|
HuskActor: Missiletank.Husk
|
||||||
|
AttractsWorms:
|
||||||
|
Intensity: 600
|
||||||
|
|
||||||
MISSILETANK.Husk:
|
MISSILETANK.Husk:
|
||||||
Inherits: ^Husk
|
Inherits: ^Husk
|
||||||
|
|||||||
@@ -201,4 +201,3 @@ World:
|
|||||||
RadarPings:
|
RadarPings:
|
||||||
ObjectivesPanel:
|
ObjectivesPanel:
|
||||||
PanelName: SKIRMISH_STATS
|
PanelName: SKIRMISH_STATS
|
||||||
|
|
||||||
|
|||||||
@@ -646,6 +646,9 @@ VISLRG:
|
|||||||
Weapon: SlimeAttack
|
Weapon: SlimeAttack
|
||||||
AttackFrontal:
|
AttackFrontal:
|
||||||
AttackWander:
|
AttackWander:
|
||||||
|
WanderMoveRadius: 2
|
||||||
|
MinMoveDelayInTicks: 25
|
||||||
|
MaxMoveDelayInTicks: 45
|
||||||
-RenderInfantry:
|
-RenderInfantry:
|
||||||
RenderUnit:
|
RenderUnit:
|
||||||
-WithDeathAnimation:
|
-WithDeathAnimation:
|
||||||
|
|||||||
Reference in New Issue
Block a user