Step three in implementing sandworms
Removed/fixed comments Code style fixes Fixed AttackWander, addressed style nits Fix Travis crash
This commit is contained in:
@@ -17,66 +17,53 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.D2k
|
||||
{
|
||||
public enum AttackState { Burrowed, EmergingAboveGround, ReturningUndergrown }
|
||||
public enum AttackState { Burrowed, EmergingAboveGround, ReturningUnderground }
|
||||
|
||||
class SwallowActor : Activity
|
||||
{
|
||||
readonly Actor target;
|
||||
readonly Mobile mobile;
|
||||
readonly Target target;
|
||||
readonly Sandworm sandworm;
|
||||
readonly WeaponInfo weapon;
|
||||
readonly AttackSwallow swallow;
|
||||
readonly IPositionable positionable;
|
||||
|
||||
int countdown;
|
||||
AttackState stance = AttackState.Burrowed;
|
||||
|
||||
// TODO: random numbers to make it look ok
|
||||
[Desc("The number of ticks it takes to return underground.")]
|
||||
const int ReturnTime = 60;
|
||||
[Desc("The number of ticks it takes to get in place under the target to attack.")]
|
||||
const int AttackTime = 30;
|
||||
|
||||
public SwallowActor(Actor self, Actor target, WeaponInfo weapon)
|
||||
public SwallowActor(Actor self, Target target, WeaponInfo weapon)
|
||||
{
|
||||
if (!target.HasTrait<Mobile>())
|
||||
throw new InvalidOperationException("SwallowActor requires a target actor with the Mobile trait");
|
||||
|
||||
this.target = target;
|
||||
this.weapon = weapon;
|
||||
mobile = self.TraitOrDefault<Mobile>();
|
||||
positionable = self.TraitOrDefault<Mobile>();
|
||||
sandworm = self.TraitOrDefault<Sandworm>();
|
||||
countdown = AttackTime;
|
||||
swallow = self.TraitOrDefault<AttackSwallow>();
|
||||
countdown = swallow.AttackSwallowInfo.AttackTime;
|
||||
}
|
||||
|
||||
bool WormAttack(Actor worm)
|
||||
{
|
||||
var targetLocation = target.Location;
|
||||
var targetLocation = target.Actor.Location;
|
||||
|
||||
var lunch = worm.World.ActorMap.GetUnitsAt(targetLocation)
|
||||
.Except(new[] { worm })
|
||||
.Where(t => weapon.IsValidAgainst(t, worm));
|
||||
.Where(t => !t.Equals(worm) && weapon.IsValidAgainst(t, worm));
|
||||
if (!lunch.Any())
|
||||
return false;
|
||||
|
||||
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)
|
||||
lunch.Do(t => t.World.AddFrameEndTask(_ => { t.World.Remove(t); t.Kill(t); })); // Dispose of the evidence (we don't want husks)
|
||||
|
||||
mobile.SetPosition(worm, targetLocation);
|
||||
positionable.SetPosition(worm, targetLocation);
|
||||
PlayAttackAnimation(worm);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool PlayAttackAnimation(Actor self)
|
||||
void PlayAttackAnimation(Actor self)
|
||||
{
|
||||
var renderUnit = self.Trait<RenderUnit>();
|
||||
renderUnit.PlayCustomAnim(self, "sand");
|
||||
renderUnit.PlayCustomAnim(self, "mouth");
|
||||
|
||||
// TODO: Someone familiar with how the sounds work should fix this:
|
||||
//Sound.PlayNotification(self.Owner, "Speech", "WormAttack", self.Owner.Country.Race);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override Activity Tick(Actor self)
|
||||
@@ -87,47 +74,36 @@ namespace OpenRA.Mods.D2k
|
||||
return this;
|
||||
}
|
||||
|
||||
if (stance == AttackState.ReturningUndergrown) // wait for the worm to get back underground
|
||||
if (stance == AttackState.ReturningUnderground) // Wait for the worm to get back underground
|
||||
{
|
||||
#region DisappearToMapEdge
|
||||
|
||||
// More random numbers used for min and max bounds
|
||||
var rand = self.World.SharedRandom.Next(200, 400);
|
||||
if (rand % 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.WorldActor.QueueActivity(new DisappearToMapEdge(self, rand));
|
||||
self.World.AddFrameEndTask(w => w.Remove(self));
|
||||
var wormManager = self.World.WorldActor.TraitOrDefault<WormManager>();
|
||||
if (wormManager != null)
|
||||
wormManager.DecreaseWorms();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
// TODO: if the worm did not disappear, make the animation reappear here
|
||||
// TODO: If the worm did not disappear, make the animation reappear here
|
||||
|
||||
return NextActivity;
|
||||
}
|
||||
|
||||
if (stance == AttackState.Burrowed) // wait for the worm to get in position
|
||||
if (stance == AttackState.Burrowed) // Wait for the worm to get in position
|
||||
{
|
||||
// TODO: make the worm animation (currenty the lightning) disappear here
|
||||
// TODO: Make the worm animation (currenty the lightning) disappear here
|
||||
|
||||
// this is so that the worm cancels an attack against a target that has reached solid rock
|
||||
if (sandworm == null || !sandworm.CanAttackAtLocation(self, target.Location))
|
||||
{
|
||||
// This is so that the worm cancels an attack against a target that has reached solid rock
|
||||
if (sandworm == null || positionable == null || !positionable.CanEnterCell(target.Actor.Location, null, false))
|
||||
return NextActivity;
|
||||
}
|
||||
|
||||
var success = WormAttack(self);
|
||||
if (!success)
|
||||
{
|
||||
return NextActivity;
|
||||
}
|
||||
|
||||
countdown = ReturnTime;
|
||||
stance = AttackState.ReturningUndergrown;
|
||||
countdown = swallow.AttackSwallowInfo.ReturnTime;
|
||||
stance = AttackState.ReturningUnderground;
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
Reference in New Issue
Block a user