Overhaul ParatroopersPower:
- Adds support for multiple drop planes. - Adds support a beacon and camera. - Prevents the plane from circling if it can’t unload.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* Copyright 2007-2014 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,
|
||||
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Mods.RA.Air;
|
||||
@@ -16,48 +17,71 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
public class ParaDropInfo : TraitInfo<ParaDrop>
|
||||
public class ParaDropInfo : ITraitInfo, Requires<CargoInfo>
|
||||
{
|
||||
public readonly int LZRange = 4;
|
||||
[Desc("Distance around the drop-point to unload troops")]
|
||||
public readonly WRange DropRange = WRange.FromCells(4);
|
||||
|
||||
[Desc("Sound to play when dropping")]
|
||||
public readonly string ChuteSound = "chute1.aud";
|
||||
|
||||
public object Create(ActorInitializer init) { return new ParaDrop(init.self, this); }
|
||||
}
|
||||
|
||||
public class ParaDrop : ITick
|
||||
public class ParaDrop : ITick, INotifyRemovedFromWorld
|
||||
{
|
||||
readonly ParaDropInfo info;
|
||||
readonly Actor self;
|
||||
readonly Cargo cargo;
|
||||
readonly HashSet<CPos> droppedAt = new HashSet<CPos>();
|
||||
|
||||
public event Action<Actor> OnRemovedFromWorld = self => { };
|
||||
public event Action<Actor> OnEnteredDropRange = self => { };
|
||||
public event Action<Actor> OnExitedDropRange = self => { };
|
||||
|
||||
[Sync] bool inDropRange;
|
||||
[Sync] Target target;
|
||||
|
||||
bool checkForSuitableCell;
|
||||
readonly List<CPos> droppedAt = new List<CPos>();
|
||||
CPos lz;
|
||||
|
||||
public ParaDrop(Actor self, ParaDropInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
this.self = self;
|
||||
cargo = self.Trait<Cargo>();
|
||||
}
|
||||
|
||||
public void SetLZ(CPos lz, bool checkLandingCell)
|
||||
{
|
||||
this.lz = lz;
|
||||
droppedAt.Clear();
|
||||
target = Target.FromCell(self.World, lz);
|
||||
checkForSuitableCell = checkLandingCell;
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
var info = self.Info.Traits.Get<ParaDropInfo>();
|
||||
var r = info.LZRange;
|
||||
var wasInDropRange = inDropRange;
|
||||
inDropRange = target.IsInRange(self.CenterPosition, info.DropRange);
|
||||
|
||||
if ((self.Location - lz).LengthSquared <= r * r && !droppedAt.Contains(self.Location))
|
||||
{
|
||||
var cargo = self.Trait<Cargo>();
|
||||
if (cargo.IsEmpty(self))
|
||||
FinishedDropping(self);
|
||||
else
|
||||
{
|
||||
if (checkForSuitableCell && !IsSuitableCell(cargo.Peek(self), self.Location))
|
||||
return;
|
||||
if (inDropRange && !wasInDropRange)
|
||||
OnEnteredDropRange(self);
|
||||
|
||||
// unload a dude here
|
||||
droppedAt.Add(self.Location);
|
||||
if (!inDropRange && wasInDropRange)
|
||||
OnExitedDropRange(self);
|
||||
|
||||
var a = cargo.Unload(self);
|
||||
self.World.AddFrameEndTask(w => w.Add(new Parachute(a, self.CenterPosition)));
|
||||
Sound.Play(info.ChuteSound, self.CenterPosition);
|
||||
}
|
||||
}
|
||||
// Are we able to drop the next trooper?
|
||||
if (!inDropRange || cargo.IsEmpty(self))
|
||||
return;
|
||||
|
||||
if (droppedAt.Contains(self.Location) || checkForSuitableCell && !IsSuitableCell(cargo.Peek(self), self.Location))
|
||||
return;
|
||||
|
||||
// unload a dude here
|
||||
droppedAt.Add(self.Location);
|
||||
|
||||
var a = cargo.Unload(self);
|
||||
self.World.AddFrameEndTask(w => w.Add(new Parachute(a, self.CenterPosition)));
|
||||
Sound.Play(info.ChuteSound, self.CenterPosition);
|
||||
}
|
||||
|
||||
static bool IsSuitableCell(Actor actorToDrop, CPos p)
|
||||
@@ -65,11 +89,9 @@ namespace OpenRA.Mods.RA
|
||||
return actorToDrop.Trait<IPositionable>().CanEnterCell(p);
|
||||
}
|
||||
|
||||
static void FinishedDropping(Actor self)
|
||||
public void RemovedFromWorld(Actor self)
|
||||
{
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new FlyOffMap());
|
||||
self.QueueActivity(new RemoveSelf());
|
||||
OnRemovedFromWorld(self);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user