a pile of plane simplifications
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
|
||||
using System;
|
||||
using OpenRA.Traits.Activities;
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenRA.Traits.AI
|
||||
{
|
||||
@@ -34,8 +35,17 @@ namespace OpenRA.Traits.AI
|
||||
var altitude = self.traits.Get<Unit>().Altitude;
|
||||
if (altitude == 0) return; // we're on the ground, let's stay there.
|
||||
|
||||
self.QueueActivity(new ReturnToBase(self, null));
|
||||
self.QueueActivity(new Rearm());
|
||||
var airfield = ReturnToBase.ChooseAirfield(self);
|
||||
if (airfield != null)
|
||||
{
|
||||
self.QueueActivity(new ReturnToBase(self, airfield));
|
||||
self.QueueActivity(new Rearm());
|
||||
}
|
||||
else
|
||||
{
|
||||
Game.chat.AddLine(Color.White, "Debug", "Plane has nowhere to land; flying away");
|
||||
self.QueueActivity(new FlyOffMap());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace OpenRA.Traits.Activities
|
||||
|
||||
return Util.SequenceActivities(
|
||||
new Fly(Target.CenterLocation),
|
||||
new FlyTimed(50, 20),
|
||||
new FlyTimed(50),
|
||||
this);
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace OpenRA.Traits.Activities
|
||||
|
||||
return Util.SequenceActivities(
|
||||
new Fly(Util.CenterOfCell(Target)),
|
||||
new FlyTimed(50, 20),
|
||||
new FlyTimed(50),
|
||||
this);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,12 +26,12 @@ namespace OpenRA.Traits.Activities
|
||||
{
|
||||
public IActivity NextActivity { get; set; }
|
||||
int remainingTicks;
|
||||
int targetAltitude;
|
||||
|
||||
public FlyTimed(int ticks, int targetAltitude) { remainingTicks = ticks; this.targetAltitude = targetAltitude; }
|
||||
public FlyTimed(int ticks) { remainingTicks = ticks; }
|
||||
|
||||
public IActivity Tick(Actor self)
|
||||
{
|
||||
var targetAltitude = self.Info.Traits.Get<PlaneInfo>().CruiseAltitude;
|
||||
if (remainingTicks-- == 0) return NextActivity;
|
||||
FlyUtil.Fly(self, targetAltitude);
|
||||
return this;
|
||||
@@ -43,19 +43,25 @@ namespace OpenRA.Traits.Activities
|
||||
public class FlyOffMap : IActivity
|
||||
{
|
||||
public IActivity NextActivity { get; set; }
|
||||
readonly int targetAltitude;
|
||||
bool isCanceled;
|
||||
public bool Interruptible = true;
|
||||
|
||||
public FlyOffMap(int targetAltitude) { this.targetAltitude = targetAltitude; }
|
||||
|
||||
public IActivity Tick(Actor self)
|
||||
{
|
||||
var targetAltitude = self.Info.Traits.Get<PlaneInfo>().CruiseAltitude;
|
||||
if (isCanceled || !self.World.Map.IsInMap(self.Location)) return NextActivity;
|
||||
FlyUtil.Fly(self, targetAltitude);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void Cancel(Actor self) { isCanceled = true; NextActivity = null; }
|
||||
public void Cancel(Actor self)
|
||||
{
|
||||
if (Interruptible)
|
||||
{
|
||||
isCanceled = true;
|
||||
NextActivity = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,17 +34,12 @@ namespace OpenRA.Traits.Activities
|
||||
float2 w1, w2, w3; /* tangent points to turn circles */
|
||||
float2 landPoint;
|
||||
|
||||
Actor ChooseAirfield(Actor self)
|
||||
public static Actor ChooseAirfield(Actor self)
|
||||
{
|
||||
var airfield = self.World.Queries.OwnedBy[self.Owner]
|
||||
return self.World.Queries.OwnedBy[self.Owner]
|
||||
.Where(a => a.Info.Name == "afld"
|
||||
&& !Reservable.IsReserved(a))
|
||||
.FirstOrDefault();
|
||||
|
||||
if (airfield == null)
|
||||
throw new NotImplementedException("nowhere to land; what to do?");
|
||||
|
||||
return airfield;
|
||||
}
|
||||
|
||||
void Calculate(Actor self)
|
||||
|
||||
@@ -35,8 +35,6 @@ namespace OpenRA.Traits
|
||||
{
|
||||
target = order.TargetActor;
|
||||
self.QueueActivity(new FlyAttack(order.TargetActor));
|
||||
self.QueueActivity(new ReturnToBase(self, null));
|
||||
self.QueueActivity(new Rearm());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,8 +73,6 @@ namespace OpenRA.Traits
|
||||
{
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new Fly(Util.CenterOfCell(order.TargetLocation)));
|
||||
self.QueueActivity(new ReturnToBase(self, null));
|
||||
self.QueueActivity(new Rearm());
|
||||
}
|
||||
|
||||
if (order.OrderString == "Enter")
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace OpenRA.Mods.RA
|
||||
void FinishedDropping(Actor self)
|
||||
{
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new FlyOffMap(20));
|
||||
self.QueueActivity(new FlyOffMap { Interruptible = false });
|
||||
self.QueueActivity(new RemoveSelf());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace OpenRA.Mods.RA
|
||||
plane.QueueActivity(new CallFunc(
|
||||
() => Owner.Shroud.Explore(Owner.World, order.TargetLocation,
|
||||
(Info as SpyPlanePowerInfo).Range)));
|
||||
plane.QueueActivity(new FlyOffMap(20));
|
||||
plane.QueueActivity(new FlyOffMap { Interruptible = false });
|
||||
plane.QueueActivity(new RemoveSelf());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1149,6 +1149,7 @@ MIG:
|
||||
LimitedAmmo:
|
||||
Ammo: 3
|
||||
IronCurtainable:
|
||||
ReturnOnIdle:
|
||||
|
||||
YAK:
|
||||
Inherits: ^Plane
|
||||
@@ -1177,6 +1178,7 @@ YAK:
|
||||
LimitedAmmo:
|
||||
Ammo: 15
|
||||
IronCurtainable:
|
||||
ReturnOnIdle:
|
||||
|
||||
TRAN:
|
||||
Inherits: ^Plane
|
||||
|
||||
Reference in New Issue
Block a user