Merge pull request #7671 from reaperrr/random-optimisations
More constructor caching and minor random optimisations
This commit is contained in:
@@ -59,16 +59,16 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var altitude = self.World.Map.Rules.Actors[actorType].Traits.Get<PlaneInfo>().CruiseAltitude;
|
var altitude = self.World.Map.Rules.Actors[actorType].Traits.Get<PlaneInfo>().CruiseAltitude;
|
||||||
var a = w.CreateActor(actorType, new TypeDictionary
|
var actor = w.CreateActor(actorType, new TypeDictionary
|
||||||
{
|
{
|
||||||
new CenterPositionInit(w.Map.CenterOfCell(startPos) + new WVec(WRange.Zero, WRange.Zero, altitude)),
|
new CenterPositionInit(w.Map.CenterOfCell(startPos) + new WVec(WRange.Zero, WRange.Zero, altitude)),
|
||||||
new OwnerInit(owner),
|
new OwnerInit(owner),
|
||||||
new FacingInit(64)
|
new FacingInit(64)
|
||||||
});
|
});
|
||||||
|
|
||||||
a.QueueActivity(new Fly(a, Target.FromCell(w, self.Location + new CVec(9, 0))));
|
actor.QueueActivity(new Fly(actor, Target.FromCell(w, self.Location + new CVec(9, 0))));
|
||||||
a.QueueActivity(new Land(Target.FromActor(self)));
|
actor.QueueActivity(new Land(actor, Target.FromActor(self)));
|
||||||
a.QueueActivity(new CallFunc(() =>
|
actor.QueueActivity(new CallFunc(() =>
|
||||||
{
|
{
|
||||||
if (!self.IsInWorld || self.IsDead)
|
if (!self.IsInWorld || self.IsDead)
|
||||||
return;
|
return;
|
||||||
@@ -80,8 +80,8 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", info.ReadyAudio, self.Owner.Country.Race);
|
Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", info.ReadyAudio, self.Owner.Country.Race);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
a.QueueActivity(new Fly(a, Target.FromCell(w, endPos)));
|
actor.QueueActivity(new Fly(actor, Target.FromCell(w, endPos)));
|
||||||
a.QueueActivity(new RemoveSelf());
|
actor.QueueActivity(new RemoveSelf());
|
||||||
});
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -18,20 +18,21 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
{
|
{
|
||||||
public class FallToEarth : Activity
|
public class FallToEarth : Activity
|
||||||
{
|
{
|
||||||
|
readonly Aircraft aircraft;
|
||||||
|
readonly FallsToEarthInfo info;
|
||||||
int acceleration = 0;
|
int acceleration = 0;
|
||||||
int spin = 0;
|
int spin = 0;
|
||||||
FallsToEarthInfo info;
|
|
||||||
|
|
||||||
public FallToEarth(Actor self, FallsToEarthInfo info)
|
public FallToEarth(Actor self, FallsToEarthInfo info)
|
||||||
{
|
{
|
||||||
this.info = info;
|
this.info = info;
|
||||||
|
aircraft = self.Trait<Aircraft>();
|
||||||
if (info.Spins)
|
if (info.Spins)
|
||||||
acceleration = self.World.SharedRandom.Next(2) * 2 - 1;
|
acceleration = self.World.SharedRandom.Next(2) * 2 - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Activity Tick(Actor self)
|
public override Activity Tick(Actor self)
|
||||||
{
|
{
|
||||||
var aircraft = self.Trait<Aircraft>();
|
|
||||||
if (self.CenterPosition.Z <= 0)
|
if (self.CenterPosition.Z <= 0)
|
||||||
{
|
{
|
||||||
if (info.Explosion != null)
|
if (info.Explosion != null)
|
||||||
|
|||||||
@@ -52,9 +52,9 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
// TODO: This should fire each weapon at its maximum range
|
// TODO: This should fire each weapon at its maximum range
|
||||||
if (target.IsInRange(self.CenterPosition, attackPlane.Armaments.Select(a => a.Weapon.MinRange).Min()))
|
if (target.IsInRange(self.CenterPosition, attackPlane.Armaments.Select(a => a.Weapon.MinRange).Min()))
|
||||||
inner = Util.SequenceActivities(new FlyTimed(ticksUntilTurn), new Fly(self, target), new FlyTimed(ticksUntilTurn));
|
inner = Util.SequenceActivities(new FlyTimed(ticksUntilTurn, self), new Fly(self, target), new FlyTimed(ticksUntilTurn, self));
|
||||||
else
|
else
|
||||||
inner = Util.SequenceActivities(new Fly(self, target), new FlyTimed(ticksUntilTurn));
|
inner = Util.SequenceActivities(new Fly(self, target), new FlyTimed(ticksUntilTurn, self));
|
||||||
}
|
}
|
||||||
|
|
||||||
inner = Util.RunActivity(self, inner);
|
inner = Util.RunActivity(self, inner);
|
||||||
|
|||||||
@@ -16,16 +16,23 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
{
|
{
|
||||||
public class FlyCircle : Activity
|
public class FlyCircle : Activity
|
||||||
{
|
{
|
||||||
|
readonly Plane plane;
|
||||||
|
readonly WRange cruiseAltitude;
|
||||||
|
|
||||||
|
public FlyCircle(Actor self)
|
||||||
|
{
|
||||||
|
plane = self.Trait<Plane>();
|
||||||
|
cruiseAltitude = plane.Info.CruiseAltitude;
|
||||||
|
}
|
||||||
|
|
||||||
public override Activity Tick(Actor self)
|
public override Activity Tick(Actor self)
|
||||||
{
|
{
|
||||||
if (IsCanceled)
|
if (IsCanceled)
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
|
|
||||||
var plane = self.Trait<Plane>();
|
|
||||||
|
|
||||||
// We can't possibly turn this fast
|
// We can't possibly turn this fast
|
||||||
var desiredFacing = plane.Facing + 64;
|
var desiredFacing = plane.Facing + 64;
|
||||||
Fly.FlyToward(self, plane, desiredFacing, plane.Info.CruiseAltitude);
|
Fly.FlyToward(self, plane, desiredFacing, cruiseAltitude);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
35
OpenRA.Mods.Common/Activities/Air/FlyOffMap.cs
Normal file
35
OpenRA.Mods.Common/Activities/Air/FlyOffMap.cs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#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.Activities;
|
||||||
|
using OpenRA.Mods.Common.Traits;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.Common.Activities
|
||||||
|
{
|
||||||
|
public class FlyOffMap : Activity
|
||||||
|
{
|
||||||
|
readonly Plane plane;
|
||||||
|
|
||||||
|
public FlyOffMap(Actor self)
|
||||||
|
{
|
||||||
|
plane = self.Trait<Plane>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Activity Tick(Actor self)
|
||||||
|
{
|
||||||
|
if (IsCanceled || !self.World.Map.Contains(self.Location))
|
||||||
|
return NextActivity;
|
||||||
|
|
||||||
|
Fly.FlyToward(self, plane, plane.Facing, plane.Info.CruiseAltitude);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,37 +16,25 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
{
|
{
|
||||||
public class FlyTimed : Activity
|
public class FlyTimed : Activity
|
||||||
{
|
{
|
||||||
|
readonly Plane plane;
|
||||||
|
readonly WRange cruiseAltitude;
|
||||||
int remainingTicks;
|
int remainingTicks;
|
||||||
|
|
||||||
public FlyTimed(int ticks) { remainingTicks = ticks; }
|
public FlyTimed(int ticks, Actor self)
|
||||||
|
{
|
||||||
|
remainingTicks = ticks;
|
||||||
|
plane = self.Trait<Plane>();
|
||||||
|
cruiseAltitude = plane.Info.CruiseAltitude;
|
||||||
|
}
|
||||||
|
|
||||||
public override Activity Tick(Actor self)
|
public override Activity Tick(Actor self)
|
||||||
{
|
{
|
||||||
if (IsCanceled || remainingTicks-- == 0)
|
if (IsCanceled || remainingTicks-- == 0)
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
|
|
||||||
var plane = self.Trait<Plane>();
|
Fly.FlyToward(self, plane, plane.Facing, cruiseAltitude);
|
||||||
Fly.FlyToward(self, plane, plane.Facing, plane.Info.CruiseAltitude);
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class FlyOffMap : Activity
|
|
||||||
{
|
|
||||||
public override Activity Tick(Actor self)
|
|
||||||
{
|
|
||||||
if (IsCanceled || !self.World.Map.Contains(self.Location))
|
|
||||||
return NextActivity;
|
|
||||||
|
|
||||||
var plane = self.Trait<Plane>();
|
|
||||||
Fly.FlyToward(self, plane, plane.Facing, plane.Info.CruiseAltitude);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Cancel(Actor self)
|
|
||||||
{
|
|
||||||
base.Cancel(self);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
// If all ammo pools are depleted and none reload automatically, return to helipad to reload and then move to next activity
|
// If all ammo pools are depleted and none reload automatically, return to helipad to reload and then move to next activity
|
||||||
// TODO: This should check whether there is ammo left that is actually suitable for the target
|
// TODO: This should check whether there is ammo left that is actually suitable for the target
|
||||||
if (ammoPools != null && ammoPools.All(x => !x.Info.SelfReloads && !x.HasAmmo()))
|
if (ammoPools != null && ammoPools.All(x => !x.Info.SelfReloads && !x.HasAmmo()))
|
||||||
return Util.SequenceActivities(new HeliReturn(), NextActivity);
|
return Util.SequenceActivities(new HeliReturn(self), NextActivity);
|
||||||
|
|
||||||
var dist = target.CenterPosition - self.CenterPosition;
|
var dist = target.CenterPosition - self.CenterPosition;
|
||||||
|
|
||||||
|
|||||||
@@ -15,11 +15,15 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
{
|
{
|
||||||
public class HeliLand : Activity
|
public class HeliLand : Activity
|
||||||
{
|
{
|
||||||
|
readonly Helicopter helicopter;
|
||||||
|
readonly WRange landAltitude;
|
||||||
bool requireSpace;
|
bool requireSpace;
|
||||||
|
|
||||||
public HeliLand(bool requireSpace)
|
public HeliLand(Actor self, bool requireSpace)
|
||||||
{
|
{
|
||||||
this.requireSpace = requireSpace;
|
this.requireSpace = requireSpace;
|
||||||
|
helicopter = self.Trait<Helicopter>();
|
||||||
|
landAltitude = helicopter.Info.LandAltitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Activity Tick(Actor self)
|
public override Activity Tick(Actor self)
|
||||||
@@ -27,12 +31,10 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
if (IsCanceled)
|
if (IsCanceled)
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
|
|
||||||
var helicopter = self.Trait<Helicopter>();
|
|
||||||
|
|
||||||
if (requireSpace && !helicopter.CanLand(self.Location))
|
if (requireSpace && !helicopter.CanLand(self.Location))
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
if (HeliFly.AdjustAltitude(self, helicopter, helicopter.Info.LandAltitude))
|
if (HeliFly.AdjustAltitude(self, helicopter, landAltitude))
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
|
|||||||
@@ -17,7 +17,18 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
{
|
{
|
||||||
public class HeliReturn : Activity
|
public class HeliReturn : Activity
|
||||||
{
|
{
|
||||||
static Actor ChooseHelipad(Actor self)
|
readonly AircraftInfo aircraftInfo;
|
||||||
|
readonly Helicopter heli;
|
||||||
|
readonly HelicopterInfo heliInfo;
|
||||||
|
|
||||||
|
public HeliReturn(Actor self)
|
||||||
|
{
|
||||||
|
aircraftInfo = self.Info.Traits.Get<AircraftInfo>();
|
||||||
|
heli = self.Trait<Helicopter>();
|
||||||
|
heliInfo = self.Info.Traits.Get<HelicopterInfo>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Actor ChooseHelipad(Actor self)
|
||||||
{
|
{
|
||||||
var rearmBuildings = self.Info.Traits.Get<HelicopterInfo>().RearmBuildings;
|
var rearmBuildings = self.Info.Traits.Get<HelicopterInfo>().RearmBuildings;
|
||||||
return self.World.Actors.Where(a => a.Owner == self.Owner).FirstOrDefault(
|
return self.World.Actors.Where(a => a.Owner == self.Owner).FirstOrDefault(
|
||||||
@@ -30,24 +41,23 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
return NextActivity;
|
return NextActivity;
|
||||||
|
|
||||||
var dest = ChooseHelipad(self);
|
var dest = ChooseHelipad(self);
|
||||||
var initialFacing = self.Info.Traits.Get<AircraftInfo>().InitialFacing;
|
var initialFacing = aircraftInfo.InitialFacing;
|
||||||
|
|
||||||
if (dest == null)
|
if (dest == null)
|
||||||
{
|
{
|
||||||
var rearmBuildings = self.Info.Traits.Get<HelicopterInfo>().RearmBuildings;
|
var rearmBuildings = heliInfo.RearmBuildings;
|
||||||
var nearestHpad = self.World.ActorsWithTrait<Reservable>()
|
var nearestHpad = self.World.ActorsWithTrait<Reservable>()
|
||||||
.Where(a => a.Actor.Owner == self.Owner && rearmBuildings.Contains(a.Actor.Info.Name))
|
.Where(a => a.Actor.Owner == self.Owner && rearmBuildings.Contains(a.Actor.Info.Name))
|
||||||
.Select(a => a.Actor)
|
.Select(a => a.Actor)
|
||||||
.ClosestTo(self);
|
.ClosestTo(self);
|
||||||
|
|
||||||
if (nearestHpad == null)
|
if (nearestHpad == null)
|
||||||
return Util.SequenceActivities(new Turn(self, initialFacing), new HeliLand(true), NextActivity);
|
return Util.SequenceActivities(new Turn(self, initialFacing), new HeliLand(self, true), NextActivity);
|
||||||
else
|
else
|
||||||
return Util.SequenceActivities(new HeliFly(self, Target.FromActor(nearestHpad)));
|
return Util.SequenceActivities(new HeliFly(self, Target.FromActor(nearestHpad)));
|
||||||
}
|
}
|
||||||
|
|
||||||
var res = dest.TraitOrDefault<Reservable>();
|
var res = dest.TraitOrDefault<Reservable>();
|
||||||
var heli = self.Trait<Helicopter>();
|
|
||||||
|
|
||||||
if (res != null)
|
if (res != null)
|
||||||
{
|
{
|
||||||
@@ -61,8 +71,8 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
return Util.SequenceActivities(
|
return Util.SequenceActivities(
|
||||||
new HeliFly(self, Target.FromPos(dest.CenterPosition + offset)),
|
new HeliFly(self, Target.FromPos(dest.CenterPosition + offset)),
|
||||||
new Turn(self, initialFacing),
|
new Turn(self, initialFacing),
|
||||||
new HeliLand(false),
|
new HeliLand(self, false),
|
||||||
new ResupplyAircraft());
|
new ResupplyAircraft(self));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,9 +16,14 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
{
|
{
|
||||||
public class Land : Activity
|
public class Land : Activity
|
||||||
{
|
{
|
||||||
Target target;
|
readonly Target target;
|
||||||
|
readonly Plane plane;
|
||||||
|
|
||||||
public Land(Target t) { target = t; }
|
public Land(Actor self, Target t)
|
||||||
|
{
|
||||||
|
target = t;
|
||||||
|
plane = self.Trait<Plane>();
|
||||||
|
}
|
||||||
|
|
||||||
public override Activity Tick(Actor self)
|
public override Activity Tick(Actor self)
|
||||||
{
|
{
|
||||||
@@ -28,7 +33,6 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
if (IsCanceled)
|
if (IsCanceled)
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
|
|
||||||
var plane = self.Trait<Plane>();
|
|
||||||
var d = target.CenterPosition - self.CenterPosition;
|
var d = target.CenterPosition - self.CenterPosition;
|
||||||
|
|
||||||
// The next move would overshoot, so just set the final position
|
// The next move would overshoot, so just set the final position
|
||||||
|
|||||||
@@ -20,9 +20,15 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
{
|
{
|
||||||
public class ResupplyAircraft : Activity
|
public class ResupplyAircraft : Activity
|
||||||
{
|
{
|
||||||
|
readonly Aircraft aircraft;
|
||||||
|
|
||||||
|
public ResupplyAircraft(Actor self)
|
||||||
|
{
|
||||||
|
aircraft = self.Trait<Aircraft>();
|
||||||
|
}
|
||||||
|
|
||||||
public override Activity Tick(Actor self)
|
public override Activity Tick(Actor self)
|
||||||
{
|
{
|
||||||
var aircraft = self.Trait<Aircraft>();
|
|
||||||
var host = aircraft.GetActorBelow();
|
var host = aircraft.GetActorBelow();
|
||||||
|
|
||||||
if (host == null)
|
if (host == null)
|
||||||
|
|||||||
@@ -18,10 +18,19 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
{
|
{
|
||||||
public class ReturnToBase : Activity
|
public class ReturnToBase : Activity
|
||||||
{
|
{
|
||||||
|
readonly Plane plane;
|
||||||
|
readonly PlaneInfo planeInfo;
|
||||||
bool isCalculated;
|
bool isCalculated;
|
||||||
Actor dest;
|
Actor dest;
|
||||||
WPos w1, w2, w3;
|
WPos w1, w2, w3;
|
||||||
|
|
||||||
|
public ReturnToBase(Actor self, Actor dest)
|
||||||
|
{
|
||||||
|
this.dest = dest;
|
||||||
|
plane = self.Trait<Plane>();
|
||||||
|
planeInfo = self.Info.Traits.Get<PlaneInfo>();
|
||||||
|
}
|
||||||
|
|
||||||
public static Actor ChooseAirfield(Actor self, bool unreservedOnly)
|
public static Actor ChooseAirfield(Actor self, bool unreservedOnly)
|
||||||
{
|
{
|
||||||
var rearmBuildings = self.Info.Traits.Get<PlaneInfo>().RearmBuildings;
|
var rearmBuildings = self.Info.Traits.Get<PlaneInfo>().RearmBuildings;
|
||||||
@@ -41,8 +50,6 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
if (dest == null)
|
if (dest == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var plane = self.Trait<Plane>();
|
|
||||||
var planeInfo = self.Info.Traits.Get<PlaneInfo>();
|
|
||||||
var res = dest.TraitOrDefault<Reservable>();
|
var res = dest.TraitOrDefault<Reservable>();
|
||||||
if (res != null)
|
if (res != null)
|
||||||
{
|
{
|
||||||
@@ -54,7 +61,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
var altitude = planeInfo.CruiseAltitude.Range;
|
var altitude = planeInfo.CruiseAltitude.Range;
|
||||||
|
|
||||||
// Distance required for descent.
|
// Distance required for descent.
|
||||||
var landDistance = altitude * 1024 / plane.Info.MaximumPitch.Tan();
|
var landDistance = altitude * 1024 / planeInfo.MaximumPitch.Tan();
|
||||||
|
|
||||||
// Land towards the east
|
// Land towards the east
|
||||||
var approachStart = landPos + new WVec(-landDistance, 0, altitude);
|
var approachStart = landPos + new WVec(-landDistance, 0, altitude);
|
||||||
@@ -92,11 +99,6 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
isCalculated = true;
|
isCalculated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReturnToBase(Actor self, Actor dest)
|
|
||||||
{
|
|
||||||
this.dest = dest;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Activity Tick(Actor self)
|
public override Activity Tick(Actor self)
|
||||||
{
|
{
|
||||||
if (IsCanceled || self.IsDead)
|
if (IsCanceled || self.IsDead)
|
||||||
@@ -111,16 +113,16 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
self.CancelActivity();
|
self.CancelActivity();
|
||||||
if (nearestAfld != null)
|
if (nearestAfld != null)
|
||||||
return Util.SequenceActivities(new Fly(self, Target.FromActor(nearestAfld)), new FlyCircle());
|
return Util.SequenceActivities(new Fly(self, Target.FromActor(nearestAfld)), new FlyCircle(self));
|
||||||
else
|
else
|
||||||
return new FlyCircle();
|
return new FlyCircle(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Util.SequenceActivities(
|
return Util.SequenceActivities(
|
||||||
new Fly(self, Target.FromPos(w1)),
|
new Fly(self, Target.FromPos(w1)),
|
||||||
new Fly(self, Target.FromPos(w2)),
|
new Fly(self, Target.FromPos(w2)),
|
||||||
new Fly(self, Target.FromPos(w3)),
|
new Fly(self, Target.FromPos(w3)),
|
||||||
new Land(Target.FromActor(dest)),
|
new Land(self, Target.FromActor(dest)),
|
||||||
NextActivity);
|
NextActivity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,10 +16,17 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
{
|
{
|
||||||
public class TakeOff : Activity
|
public class TakeOff : Activity
|
||||||
{
|
{
|
||||||
|
readonly Aircraft aircraft;
|
||||||
|
readonly IMove move;
|
||||||
|
|
||||||
|
public TakeOff(Actor self)
|
||||||
|
{
|
||||||
|
aircraft = self.Trait<Aircraft>();
|
||||||
|
move = self.Trait<IMove>();
|
||||||
|
}
|
||||||
|
|
||||||
public override Activity Tick(Actor self)
|
public override Activity Tick(Actor self)
|
||||||
{
|
{
|
||||||
var aircraft = self.Trait<Aircraft>();
|
|
||||||
|
|
||||||
self.CancelActivity();
|
self.CancelActivity();
|
||||||
|
|
||||||
var reservation = aircraft.Reservation;
|
var reservation = aircraft.Reservation;
|
||||||
@@ -36,7 +43,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
var destination = rp != null ? rp.Location :
|
var destination = rp != null ? rp.Location :
|
||||||
(hasHost ? self.World.Map.CellContaining(host.CenterPosition) : self.Location);
|
(hasHost ? self.World.Map.CellContaining(host.CenterPosition) : self.Location);
|
||||||
|
|
||||||
return new AttackMoveActivity(self, self.Trait<IMove>().MoveTo(destination, 1));
|
return new AttackMoveActivity(self, move.MoveTo(destination, 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,15 +16,19 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
public class CaptureActor : Enter
|
public class CaptureActor : Enter
|
||||||
{
|
{
|
||||||
readonly Actor actor;
|
readonly Actor actor;
|
||||||
|
readonly Building building;
|
||||||
readonly Capturable capturable;
|
readonly Capturable capturable;
|
||||||
readonly CapturesInfo capturesInfo;
|
readonly CapturesInfo capturesInfo;
|
||||||
|
readonly Health health;
|
||||||
|
|
||||||
public CaptureActor(Actor self, Actor target)
|
public CaptureActor(Actor self, Actor target)
|
||||||
: base(self, target)
|
: base(self, target)
|
||||||
{
|
{
|
||||||
actor = target;
|
actor = target;
|
||||||
|
building = actor.TraitOrDefault<Building>();
|
||||||
capturesInfo = self.Info.Traits.Get<CapturesInfo>();
|
capturesInfo = self.Info.Traits.Get<CapturesInfo>();
|
||||||
capturable = target.Trait<Capturable>();
|
capturable = target.Trait<Capturable>();
|
||||||
|
health = actor.Trait<Health>();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool CanReserve(Actor self)
|
protected override bool CanReserve(Actor self)
|
||||||
@@ -37,20 +41,17 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
if (actor.IsDead || capturable.BeingCaptured)
|
if (actor.IsDead || capturable.BeingCaptured)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var b = actor.TraitOrDefault<Building>();
|
if (building != null && !building.Lock())
|
||||||
if (b != null && !b.Lock())
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
self.World.AddFrameEndTask(w =>
|
self.World.AddFrameEndTask(w =>
|
||||||
{
|
{
|
||||||
if (b != null && b.Locked)
|
if (building != null && building.Locked)
|
||||||
b.Unlock();
|
building.Unlock();
|
||||||
|
|
||||||
if (actor.IsDead || capturable.BeingCaptured)
|
if (actor.IsDead || capturable.BeingCaptured)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var health = actor.Trait<Health>();
|
|
||||||
|
|
||||||
var lowEnoughHealth = health.HP <= capturable.Info.CaptureThreshold * health.MaxHP;
|
var lowEnoughHealth = health.HP <= capturable.Info.CaptureThreshold * health.MaxHP;
|
||||||
if (!capturesInfo.Sabotage || lowEnoughHealth || actor.Owner.NonCombatant)
|
if (!capturesInfo.Sabotage || lowEnoughHealth || actor.Owner.NonCombatant)
|
||||||
{
|
{
|
||||||
@@ -61,8 +62,8 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
foreach (var t in actor.TraitsImplementing<INotifyCapture>())
|
foreach (var t in actor.TraitsImplementing<INotifyCapture>())
|
||||||
t.OnCapture(actor, self, oldOwner, self.Owner);
|
t.OnCapture(actor, self, oldOwner, self.Owner);
|
||||||
|
|
||||||
if (b != null && b.Locked)
|
if (building != null && building.Locked)
|
||||||
b.Unlock();
|
building.Unlock();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,17 +17,24 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
{
|
{
|
||||||
class ExternalCaptureActor : Activity
|
class ExternalCaptureActor : Activity
|
||||||
{
|
{
|
||||||
Target target;
|
readonly ExternalCapturable capturable;
|
||||||
|
readonly ExternalCapturesInfo capturesInfo;
|
||||||
|
readonly Mobile mobile;
|
||||||
|
readonly Target target;
|
||||||
|
|
||||||
public ExternalCaptureActor(Target target) { this.target = target; }
|
public ExternalCaptureActor(Actor self, Target target)
|
||||||
|
{
|
||||||
|
this.target = target;
|
||||||
|
capturable = target.Actor.Trait<ExternalCapturable>();
|
||||||
|
capturesInfo = self.Info.Traits.Get<ExternalCapturesInfo>();
|
||||||
|
mobile = self.Trait<Mobile>();
|
||||||
|
}
|
||||||
|
|
||||||
public override Activity Tick(Actor self)
|
public override Activity Tick(Actor self)
|
||||||
{
|
{
|
||||||
if (target.Type != TargetType.Actor)
|
if (target.Type != TargetType.Actor)
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
|
|
||||||
var capturable = target.Actor.Trait<ExternalCapturable>();
|
|
||||||
|
|
||||||
if (IsCanceled || !self.IsInWorld || self.IsDead || !target.IsValidFor(self))
|
if (IsCanceled || !self.IsInWorld || self.IsDead || !target.IsValidFor(self))
|
||||||
{
|
{
|
||||||
if (capturable.CaptureInProgress)
|
if (capturable.CaptureInProgress)
|
||||||
@@ -36,7 +43,6 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
return NextActivity;
|
return NextActivity;
|
||||||
}
|
}
|
||||||
|
|
||||||
var mobile = self.Trait<Mobile>();
|
|
||||||
var nearest = target.Actor.OccupiesSpace.NearestCellTo(mobile.ToCell);
|
var nearest = target.Actor.OccupiesSpace.NearestCellTo(mobile.ToCell);
|
||||||
|
|
||||||
if ((nearest - mobile.ToCell).LengthSquared > 2)
|
if ((nearest - mobile.ToCell).LengthSquared > 2)
|
||||||
@@ -56,8 +62,6 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
if (capturable.CaptureProgressTime == capturable.Info.CaptureCompleteTime * 25)
|
if (capturable.CaptureProgressTime == capturable.Info.CaptureCompleteTime * 25)
|
||||||
{
|
{
|
||||||
var capturesInfo = self.Info.Traits.Get<ExternalCapturesInfo>();
|
|
||||||
|
|
||||||
self.World.AddFrameEndTask(w =>
|
self.World.AddFrameEndTask(w =>
|
||||||
{
|
{
|
||||||
if (target.Actor.IsDead)
|
if (target.Actor.IsDead)
|
||||||
|
|||||||
@@ -17,16 +17,23 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
{
|
{
|
||||||
class Sell : Activity
|
class Sell : Activity
|
||||||
{
|
{
|
||||||
|
readonly Health health;
|
||||||
|
readonly SellableInfo sellableInfo;
|
||||||
|
readonly PlayerResources playerResources;
|
||||||
|
|
||||||
|
public Sell(Actor self)
|
||||||
|
{
|
||||||
|
health = self.TraitOrDefault<Health>();
|
||||||
|
sellableInfo = self.Info.Traits.Get<SellableInfo>();
|
||||||
|
playerResources = self.Owner.PlayerActor.Trait<PlayerResources>();
|
||||||
|
}
|
||||||
|
|
||||||
public override Activity Tick(Actor self)
|
public override Activity Tick(Actor self)
|
||||||
{
|
{
|
||||||
var h = self.TraitOrDefault<Health>();
|
|
||||||
var si = self.Info.Traits.Get<SellableInfo>();
|
|
||||||
var pr = self.Owner.PlayerActor.Trait<PlayerResources>();
|
|
||||||
|
|
||||||
var cost = self.GetSellValue();
|
var cost = self.GetSellValue();
|
||||||
|
|
||||||
var refund = (cost * si.RefundPercent * (h == null ? 1 : h.HP)) / (100 * (h == null ? 1 : h.MaxHP));
|
var refund = (cost * sellableInfo.RefundPercent * (health == null ? 1 : health.HP)) / (100 * (health == null ? 1 : health.MaxHP));
|
||||||
pr.GiveCash(refund);
|
playerResources.GiveCash(refund);
|
||||||
|
|
||||||
foreach (var ns in self.TraitsImplementing<INotifySold>())
|
foreach (var ns in self.TraitsImplementing<INotifySold>())
|
||||||
ns.Sold(self);
|
ns.Sold(self);
|
||||||
|
|||||||
@@ -81,6 +81,7 @@
|
|||||||
<Compile Include="Activities\Air\FlyAttack.cs" />
|
<Compile Include="Activities\Air\FlyAttack.cs" />
|
||||||
<Compile Include="Activities\Air\FlyCircle.cs" />
|
<Compile Include="Activities\Air\FlyCircle.cs" />
|
||||||
<Compile Include="Activities\Air\FlyFollow.cs" />
|
<Compile Include="Activities\Air\FlyFollow.cs" />
|
||||||
|
<Compile Include="Activities\Air\FlyOffMap.cs" />
|
||||||
<Compile Include="Activities\Air\FlyTimed.cs" />
|
<Compile Include="Activities\Air\FlyTimed.cs" />
|
||||||
<Compile Include="Activities\Air\HeliAttack.cs" />
|
<Compile Include="Activities\Air\HeliAttack.cs" />
|
||||||
<Compile Include="Activities\Air\HeliFly.cs" />
|
<Compile Include="Activities\Air\HeliFly.cs" />
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ namespace OpenRA.Mods.Common.Scripting
|
|||||||
if (heli != null)
|
if (heli != null)
|
||||||
{
|
{
|
||||||
transport.QueueActivity(new Turn(transport, heli.Info.InitialFacing));
|
transport.QueueActivity(new Turn(transport, heli.Info.InitialFacing));
|
||||||
transport.QueueActivity(new HeliLand(true));
|
transport.QueueActivity(new HeliLand(transport, true));
|
||||||
transport.QueueActivity(new Wait(15));
|
transport.QueueActivity(new Wait(15));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
public void TickIdle(Actor self)
|
public void TickIdle(Actor self)
|
||||||
{
|
{
|
||||||
self.QueueActivity(new FlyOffMap());
|
self.QueueActivity(new FlyOffMap(self));
|
||||||
self.QueueActivity(new RemoveSelf());
|
self.QueueActivity(new RemoveSelf());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public class Helicopter : Aircraft, ITick, IResolveOrder, IMove
|
public class Helicopter : Aircraft, ITick, IResolveOrder, IMove
|
||||||
{
|
{
|
||||||
public HelicopterInfo Info;
|
public readonly HelicopterInfo Info;
|
||||||
|
readonly bool fallsToEarth;
|
||||||
Actor self;
|
Actor self;
|
||||||
bool firstTick = true;
|
bool firstTick = true;
|
||||||
public bool IsMoving { get { return self.CenterPosition.Z > 0; } set { } }
|
public bool IsMoving { get { return self.CenterPosition.Z > 0; } set { } }
|
||||||
@@ -45,6 +46,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
self = init.Self;
|
self = init.Self;
|
||||||
Info = info;
|
Info = info;
|
||||||
|
fallsToEarth = self.HasTrait<FallsToEarth>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ResolveOrder(Actor self, Order order)
|
public void ResolveOrder(Actor self, Order order)
|
||||||
@@ -74,7 +76,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (Info.TurnToLand)
|
if (Info.TurnToLand)
|
||||||
self.QueueActivity(new Turn(self, Info.InitialFacing));
|
self.QueueActivity(new Turn(self, Info.InitialFacing));
|
||||||
|
|
||||||
self.QueueActivity(new HeliLand(true));
|
self.QueueActivity(new HeliLand(self, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +85,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (Reservable.IsReserved(order.TargetActor))
|
if (Reservable.IsReserved(order.TargetActor))
|
||||||
{
|
{
|
||||||
self.CancelActivity();
|
self.CancelActivity();
|
||||||
self.QueueActivity(new HeliReturn());
|
self.QueueActivity(new HeliReturn(self));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -99,16 +101,16 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
self.CancelActivity();
|
self.CancelActivity();
|
||||||
self.QueueActivity(new HeliFly(self, Target.FromPos(order.TargetActor.CenterPosition + offset)));
|
self.QueueActivity(new HeliFly(self, Target.FromPos(order.TargetActor.CenterPosition + offset)));
|
||||||
self.QueueActivity(new Turn(self, Info.InitialFacing));
|
self.QueueActivity(new Turn(self, Info.InitialFacing));
|
||||||
self.QueueActivity(new HeliLand(false));
|
self.QueueActivity(new HeliLand(self, false));
|
||||||
self.QueueActivity(new ResupplyAircraft());
|
self.QueueActivity(new ResupplyAircraft(self));
|
||||||
self.QueueActivity(new TakeOff());
|
self.QueueActivity(new TakeOff(self));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (order.OrderString == "ReturnToBase")
|
if (order.OrderString == "ReturnToBase")
|
||||||
{
|
{
|
||||||
self.CancelActivity();
|
self.CancelActivity();
|
||||||
self.QueueActivity(new HeliReturn());
|
self.QueueActivity(new HeliReturn(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (order.OrderString == "Stop")
|
if (order.OrderString == "Stop")
|
||||||
@@ -120,7 +122,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (Info.TurnToLand)
|
if (Info.TurnToLand)
|
||||||
self.QueueActivity(new Turn(self, Info.InitialFacing));
|
self.QueueActivity(new Turn(self, Info.InitialFacing));
|
||||||
|
|
||||||
self.QueueActivity(new HeliLand(true));
|
self.QueueActivity(new HeliLand(self, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -130,14 +132,14 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (firstTick)
|
if (firstTick)
|
||||||
{
|
{
|
||||||
firstTick = false;
|
firstTick = false;
|
||||||
if (!self.HasTrait<FallsToEarth>()) // TODO: Aircraft husks don't properly unreserve.
|
if (!fallsToEarth) // TODO: Aircraft husks don't properly unreserve.
|
||||||
ReserveSpawnBuilding();
|
ReserveSpawnBuilding();
|
||||||
|
|
||||||
var host = GetActorBelow();
|
var host = GetActorBelow();
|
||||||
if (host == null)
|
if (host == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
self.QueueActivity(new TakeOff());
|
self.QueueActivity(new TakeOff(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
Repulse();
|
Repulse();
|
||||||
@@ -155,7 +157,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return new HeliFly(self, Target.FromCell(self.World, cell, subCell));
|
return new HeliFly(self, Target.FromCell(self.World, cell, subCell));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Activity MoveIntoTarget(Actor self, Target target) { return new HeliLand(false); }
|
public Activity MoveIntoTarget(Actor self, Target target) { return new HeliLand(self, false); }
|
||||||
public Activity MoveToTarget(Actor self, Target target)
|
public Activity MoveToTarget(Actor self, Target target)
|
||||||
{
|
{
|
||||||
return Util.SequenceActivities(new HeliFly(self, target), new Turn(self, Info.InitialFacing));
|
return Util.SequenceActivities(new HeliFly(self, target), new Turn(self, Info.InitialFacing));
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public class Plane : Aircraft, IResolveOrder, IMove, ITick, ISync
|
public class Plane : Aircraft, IResolveOrder, IMove, ITick, ISync
|
||||||
{
|
{
|
||||||
public readonly PlaneInfo Info;
|
public readonly PlaneInfo Info;
|
||||||
|
readonly bool fallsToEarth;
|
||||||
[Sync] public WPos RTBPathHash;
|
[Sync] public WPos RTBPathHash;
|
||||||
Actor self;
|
Actor self;
|
||||||
public bool IsMoving { get { return self.CenterPosition.Z > 0; } set { } }
|
public bool IsMoving { get { return self.CenterPosition.Z > 0; } set { } }
|
||||||
@@ -35,6 +36,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
self = init.Self;
|
self = init.Self;
|
||||||
Info = info;
|
Info = info;
|
||||||
|
fallsToEarth = self.HasTrait<FallsToEarth>();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool firstTick = true;
|
bool firstTick = true;
|
||||||
@@ -43,14 +45,14 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (firstTick)
|
if (firstTick)
|
||||||
{
|
{
|
||||||
firstTick = false;
|
firstTick = false;
|
||||||
if (!self.HasTrait<FallsToEarth>()) // TODO: Aircraft husks don't properly unreserve.
|
if (!fallsToEarth) // TODO: Aircraft husks don't properly unreserve.
|
||||||
ReserveSpawnBuilding();
|
ReserveSpawnBuilding();
|
||||||
|
|
||||||
var host = GetActorBelow();
|
var host = GetActorBelow();
|
||||||
if (host == null)
|
if (host == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
self.QueueActivity(new TakeOff());
|
self.QueueActivity(new TakeOff(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
Repulse();
|
Repulse();
|
||||||
@@ -89,7 +91,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
self.SetTargetLine(target, Color.Green);
|
self.SetTargetLine(target, Color.Green);
|
||||||
self.CancelActivity();
|
self.CancelActivity();
|
||||||
self.QueueActivity(new Fly(self, target));
|
self.QueueActivity(new Fly(self, target));
|
||||||
self.QueueActivity(new FlyCircle());
|
self.QueueActivity(new FlyCircle(self));
|
||||||
}
|
}
|
||||||
else if (order.OrderString == "Enter")
|
else if (order.OrderString == "Enter")
|
||||||
{
|
{
|
||||||
@@ -101,7 +103,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
self.CancelActivity();
|
self.CancelActivity();
|
||||||
self.QueueActivity(new ReturnToBase(self, order.TargetActor));
|
self.QueueActivity(new ReturnToBase(self, order.TargetActor));
|
||||||
self.QueueActivity(new ResupplyAircraft());
|
self.QueueActivity(new ResupplyAircraft(self));
|
||||||
}
|
}
|
||||||
else if (order.OrderString == "Stop")
|
else if (order.OrderString == "Stop")
|
||||||
{
|
{
|
||||||
@@ -117,7 +119,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
self.CancelActivity();
|
self.CancelActivity();
|
||||||
self.SetTargetLine(Target.FromActor(airfield), Color.Green);
|
self.SetTargetLine(Target.FromActor(airfield), Color.Green);
|
||||||
self.QueueActivity(new ReturnToBase(self, airfield));
|
self.QueueActivity(new ReturnToBase(self, airfield));
|
||||||
self.QueueActivity(new ResupplyAircraft());
|
self.QueueActivity(new ResupplyAircraft(self));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -126,12 +128,12 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Activity MoveTo(CPos cell, int nearEnough) { return Util.SequenceActivities(new Fly(self, Target.FromCell(self.World, cell)), new FlyCircle()); }
|
public Activity MoveTo(CPos cell, int nearEnough) { return Util.SequenceActivities(new Fly(self, Target.FromCell(self.World, cell)), new FlyCircle(self)); }
|
||||||
public Activity MoveTo(CPos cell, Actor ignoredActor) { return Util.SequenceActivities(new Fly(self, Target.FromCell(self.World, cell)), new FlyCircle()); }
|
public Activity MoveTo(CPos cell, Actor ignoredActor) { return Util.SequenceActivities(new Fly(self, Target.FromCell(self.World, cell)), new FlyCircle(self)); }
|
||||||
public Activity MoveWithinRange(Target target, WRange range) { return Util.SequenceActivities(new Fly(self, target, WRange.Zero, range), new FlyCircle()); }
|
public Activity MoveWithinRange(Target target, WRange range) { return Util.SequenceActivities(new Fly(self, target, WRange.Zero, range), new FlyCircle(self)); }
|
||||||
public Activity MoveWithinRange(Target target, WRange minRange, WRange maxRange)
|
public Activity MoveWithinRange(Target target, WRange minRange, WRange maxRange)
|
||||||
{
|
{
|
||||||
return Util.SequenceActivities(new Fly(self, target, minRange, maxRange), new FlyCircle());
|
return Util.SequenceActivities(new Fly(self, target, minRange, maxRange), new FlyCircle(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Activity MoveFollow(Actor self, Target target, WRange minRange, WRange maxRange) { return new FlyFollow(self, target, minRange, maxRange); }
|
public Activity MoveFollow(Actor self, Target target, WRange minRange, WRange maxRange) { return new FlyFollow(self, target, minRange, maxRange); }
|
||||||
@@ -144,6 +146,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Activity MoveToTarget(Actor self, Target target) { return new Fly(self, target, WRange.FromCells(3), WRange.FromCells(5)); }
|
public Activity MoveToTarget(Actor self, Target target) { return new Fly(self, target, WRange.FromCells(3), WRange.FromCells(5)); }
|
||||||
public Activity MoveIntoTarget(Actor self, Target target) { return new Land(target); }
|
public Activity MoveIntoTarget(Actor self, Target target) { return new Land(self, target); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (airfield != null)
|
if (airfield != null)
|
||||||
{
|
{
|
||||||
self.QueueActivity(new ReturnToBase(self, airfield));
|
self.QueueActivity(new ReturnToBase(self, airfield));
|
||||||
self.QueueActivity(new ResupplyAircraft());
|
self.QueueActivity(new ResupplyAircraft(self));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -49,13 +49,13 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (someBuilding == null)
|
if (someBuilding == null)
|
||||||
{
|
{
|
||||||
// ... going down the garden to eat worms ...
|
// ... going down the garden to eat worms ...
|
||||||
self.QueueActivity(new FlyOffMap());
|
self.QueueActivity(new FlyOffMap(self));
|
||||||
self.QueueActivity(new RemoveSelf());
|
self.QueueActivity(new RemoveSelf());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.QueueActivity(new Fly(self, Target.FromActor(someBuilding)));
|
self.QueueActivity(new Fly(self, Target.FromActor(someBuilding)));
|
||||||
self.QueueActivity(new FlyCircle());
|
self.QueueActivity(new FlyCircle(self));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
class Burns : ITick, ISync
|
class Burns : ITick, ISync
|
||||||
{
|
{
|
||||||
|
readonly BurnsInfo info;
|
||||||
[Sync] int ticks;
|
[Sync] int ticks;
|
||||||
BurnsInfo info;
|
|
||||||
|
|
||||||
public Burns(Actor self, BurnsInfo info)
|
public Burns(Actor self, BurnsInfo info)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
Unloading = true;
|
Unloading = true;
|
||||||
self.CancelActivity();
|
self.CancelActivity();
|
||||||
if (helicopter != null)
|
if (helicopter != null)
|
||||||
self.QueueActivity(new HeliLand(true));
|
self.QueueActivity(new HeliLand(self, true));
|
||||||
self.QueueActivity(new UnloadCargo(self, true));
|
self.QueueActivity(new UnloadCargo(self, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,21 +51,20 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public class ExternalCapturable : ITick
|
public class ExternalCapturable : ITick
|
||||||
{
|
{
|
||||||
|
readonly Building building;
|
||||||
[Sync] public int CaptureProgressTime = 0;
|
[Sync] public int CaptureProgressTime = 0;
|
||||||
[Sync] public Actor Captor;
|
[Sync] public Actor Captor;
|
||||||
private Actor self;
|
|
||||||
public ExternalCapturableInfo Info;
|
public ExternalCapturableInfo Info;
|
||||||
public bool CaptureInProgress { get { return Captor != null; } }
|
public bool CaptureInProgress { get { return Captor != null; } }
|
||||||
|
|
||||||
public ExternalCapturable(Actor self, ExternalCapturableInfo info)
|
public ExternalCapturable(Actor self, ExternalCapturableInfo info)
|
||||||
{
|
{
|
||||||
this.self = self;
|
|
||||||
Info = info;
|
Info = info;
|
||||||
|
building = self.TraitOrDefault<Building>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void BeginCapture(Actor captor)
|
public void BeginCapture(Actor captor)
|
||||||
{
|
{
|
||||||
var building = self.TraitOrDefault<Building>();
|
|
||||||
if (building != null)
|
if (building != null)
|
||||||
building.Lock();
|
building.Lock();
|
||||||
|
|
||||||
@@ -74,7 +73,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public void EndCapture()
|
public void EndCapture()
|
||||||
{
|
{
|
||||||
var building = self.TraitOrDefault<Building>();
|
|
||||||
if (building != null)
|
if (building != null)
|
||||||
building.Unlock();
|
building.Unlock();
|
||||||
|
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
self.CancelActivity();
|
self.CancelActivity();
|
||||||
|
|
||||||
self.SetTargetLine(target, Color.Red);
|
self.SetTargetLine(target, Color.Red);
|
||||||
self.QueueActivity(new ExternalCaptureActor(target));
|
self.QueueActivity(new ExternalCaptureActor(self, target));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
class ScaredyCat : ITick, INotifyIdle, INotifyDamage, INotifyAttack, ISpeedModifier, ISync, IRenderInfantrySequenceModifier
|
class ScaredyCat : ITick, INotifyIdle, INotifyDamage, INotifyAttack, ISpeedModifier, ISync, IRenderInfantrySequenceModifier
|
||||||
{
|
{
|
||||||
readonly ScaredyCatInfo info;
|
readonly ScaredyCatInfo info;
|
||||||
|
readonly Mobile mobile;
|
||||||
[Sync] readonly Actor self;
|
[Sync] readonly Actor self;
|
||||||
[Sync] int panicStartedTick;
|
[Sync] int panicStartedTick;
|
||||||
bool Panicking { get { return panicStartedTick > 0; } }
|
bool Panicking { get { return panicStartedTick > 0; } }
|
||||||
@@ -41,6 +42,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
this.self = self;
|
this.self = self;
|
||||||
this.info = info;
|
this.info = info;
|
||||||
|
mobile = self.Trait<Mobile>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Panic()
|
public void Panic()
|
||||||
@@ -68,7 +70,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (!Panicking)
|
if (!Panicking)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
self.Trait<Mobile>().Nudge(self, self, true);
|
mobile.Nudge(self, self, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Damaged(Actor self, AttackInfo e)
|
public void Damaged(Actor self, AttackInfo e)
|
||||||
|
|||||||
@@ -27,21 +27,22 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[Desc("Custom palette name")]
|
[Desc("Custom palette name")]
|
||||||
public readonly string Palette = "effect";
|
public readonly string Palette = "effect";
|
||||||
|
|
||||||
public object Create(ActorInitializer init) { return new WithBuildingExplosion(this); }
|
public object Create(ActorInitializer init) { return new WithBuildingExplosion(init.Self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
class WithBuildingExplosion : INotifyKilled
|
class WithBuildingExplosion : INotifyKilled
|
||||||
{
|
{
|
||||||
WithBuildingExplosionInfo info;
|
WithBuildingExplosionInfo info;
|
||||||
|
BuildingInfo buildingInfo;
|
||||||
|
|
||||||
public WithBuildingExplosion(WithBuildingExplosionInfo info)
|
public WithBuildingExplosion(Actor self, WithBuildingExplosionInfo info)
|
||||||
{
|
{
|
||||||
this.info = info;
|
this.info = info;
|
||||||
|
buildingInfo = self.Info.Traits.Get<BuildingInfo>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Killed(Actor self, AttackInfo e)
|
public void Killed(Actor self, AttackInfo e)
|
||||||
{
|
{
|
||||||
var buildingInfo = self.Info.Traits.Get<BuildingInfo>();
|
|
||||||
var cells = FootprintUtils.UnpathableTiles(self.Info.Name, buildingInfo, self.Location);
|
var cells = FootprintUtils.UnpathableTiles(self.Info.Name, buildingInfo, self.Location);
|
||||||
|
|
||||||
if (info.Delay > 0)
|
if (info.Delay > 0)
|
||||||
|
|||||||
@@ -29,8 +29,14 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
readonly RepairableNearInfo info;
|
readonly RepairableNearInfo info;
|
||||||
|
readonly IMove movement;
|
||||||
|
|
||||||
public RepairableNear(Actor self, RepairableNearInfo info) { this.self = self; this.info = info; }
|
public RepairableNear(Actor self, RepairableNearInfo info)
|
||||||
|
{
|
||||||
|
this.self = self;
|
||||||
|
this.info = info;
|
||||||
|
movement = self.Trait<IMove>();
|
||||||
|
}
|
||||||
|
|
||||||
public IEnumerable<IOrderTargeter> Orders
|
public IEnumerable<IOrderTargeter> Orders
|
||||||
{
|
{
|
||||||
@@ -63,7 +69,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
if (order.OrderString == "RepairNear" && CanRepairAt(order.TargetActor) && ShouldRepair())
|
if (order.OrderString == "RepairNear" && CanRepairAt(order.TargetActor) && ShouldRepair())
|
||||||
{
|
{
|
||||||
var movement = self.Trait<IMove>();
|
|
||||||
var target = Target.FromOrder(self.World, order);
|
var target = Target.FromOrder(self.World, order);
|
||||||
|
|
||||||
self.CancelActivity();
|
self.CancelActivity();
|
||||||
|
|||||||
@@ -29,12 +29,18 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
readonly Lazy<Health> health;
|
readonly Lazy<Health> health;
|
||||||
|
readonly SellableInfo info;
|
||||||
|
readonly Building building;
|
||||||
|
readonly WithMakeAnimation makeAnimation;
|
||||||
|
|
||||||
public Sellable(Actor self, SellableInfo info)
|
public Sellable(Actor self, SellableInfo info)
|
||||||
: base(info)
|
: base(info)
|
||||||
{
|
{
|
||||||
this.self = self;
|
this.self = self;
|
||||||
|
this.info = info;
|
||||||
health = Exts.Lazy(() => self.TraitOrDefault<Health>());
|
health = Exts.Lazy(() => self.TraitOrDefault<Health>());
|
||||||
|
building = self.TraitOrDefault<Building>();
|
||||||
|
makeAnimation = self.TraitOrDefault<WithMakeAnimation>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ResolveOrder(Actor self, Order order)
|
public void ResolveOrder(Actor self, Order order)
|
||||||
@@ -48,23 +54,21 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (IsTraitDisabled)
|
if (IsTraitDisabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var building = self.TraitOrDefault<Building>();
|
|
||||||
if (building != null && !building.Lock())
|
if (building != null && !building.Lock())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
self.CancelActivity();
|
self.CancelActivity();
|
||||||
|
|
||||||
foreach (var s in Info.SellSounds)
|
foreach (var s in info.SellSounds)
|
||||||
Sound.PlayToPlayer(self.Owner, s, self.CenterPosition);
|
Sound.PlayToPlayer(self.Owner, s, self.CenterPosition);
|
||||||
|
|
||||||
foreach (var ns in self.TraitsImplementing<INotifySold>())
|
foreach (var ns in self.TraitsImplementing<INotifySold>())
|
||||||
ns.Selling(self);
|
ns.Selling(self);
|
||||||
|
|
||||||
var makeAnimation = self.TraitOrDefault<WithMakeAnimation>();
|
|
||||||
if (makeAnimation != null)
|
if (makeAnimation != null)
|
||||||
makeAnimation.Reverse(self, new Sell(), false);
|
makeAnimation.Reverse(self, new Sell(self), false);
|
||||||
else
|
else
|
||||||
self.QueueActivity(false, new Sell());
|
self.QueueActivity(false, new Sell(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsTooltipVisible(Player forPlayer)
|
public bool IsTooltipVisible(Player forPlayer)
|
||||||
@@ -78,7 +82,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var sellValue = self.GetSellValue() * Info.RefundPercent / 100;
|
var sellValue = self.GetSellValue() * info.RefundPercent / 100;
|
||||||
if (health.Value != null)
|
if (health.Value != null)
|
||||||
{
|
{
|
||||||
sellValue *= health.Value.HP;
|
sellValue *= health.Value.HP;
|
||||||
|
|||||||
@@ -46,14 +46,18 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
readonly TransformsInfo info;
|
readonly TransformsInfo info;
|
||||||
readonly BuildingInfo bi;
|
readonly Building building;
|
||||||
|
readonly BuildingInfo buildingInfo;
|
||||||
readonly string race;
|
readonly string race;
|
||||||
|
readonly WithMakeAnimation makeAnimation;
|
||||||
|
|
||||||
public Transforms(ActorInitializer init, TransformsInfo info)
|
public Transforms(ActorInitializer init, TransformsInfo info)
|
||||||
{
|
{
|
||||||
self = init.Self;
|
self = init.Self;
|
||||||
this.info = info;
|
this.info = info;
|
||||||
bi = self.World.Map.Rules.Actors[info.IntoActor].Traits.GetOrDefault<BuildingInfo>();
|
buildingInfo = self.World.Map.Rules.Actors[info.IntoActor].Traits.GetOrDefault<BuildingInfo>();
|
||||||
|
building = self.TraitOrDefault<Building>();
|
||||||
|
makeAnimation = self.TraitOrDefault<WithMakeAnimation>();
|
||||||
race = init.Contains<RaceInit>() ? init.Get<RaceInit, string>() : self.Owner.Country.Race;
|
race = init.Contains<RaceInit>() ? init.Get<RaceInit, string>() : self.Owner.Country.Race;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,11 +68,10 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
bool CanDeploy()
|
bool CanDeploy()
|
||||||
{
|
{
|
||||||
var b = self.TraitOrDefault<Building>();
|
if (building != null && building.Locked)
|
||||||
if (b != null && b.Locked)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return bi == null || self.World.CanPlaceBuilding(info.IntoActor, bi, self.Location + info.Offset, self);
|
return buildingInfo == null || self.World.CanPlaceBuilding(info.IntoActor, buildingInfo, self.Location + info.Offset, self);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<IOrderTargeter> Orders
|
public IEnumerable<IOrderTargeter> Orders
|
||||||
@@ -86,9 +89,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public void DeployTransform(bool queued)
|
public void DeployTransform(bool queued)
|
||||||
{
|
{
|
||||||
var b = self.TraitOrDefault<Building>();
|
if (!CanDeploy() || (building != null && !building.Lock()))
|
||||||
|
|
||||||
if (!CanDeploy() || (b != null && !b.Lock()))
|
|
||||||
{
|
{
|
||||||
foreach (var s in info.NoTransformSounds)
|
foreach (var s in info.NoTransformSounds)
|
||||||
Sound.PlayToPlayer(self.Owner, s);
|
Sound.PlayToPlayer(self.Owner, s);
|
||||||
@@ -116,7 +117,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
Race = race
|
Race = race
|
||||||
};
|
};
|
||||||
|
|
||||||
var makeAnimation = self.TraitOrDefault<WithMakeAnimation>();
|
|
||||||
if (makeAnimation != null)
|
if (makeAnimation != null)
|
||||||
makeAnimation.Reverse(self, transform);
|
makeAnimation.Reverse(self, transform);
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ namespace OpenRA.Mods.D2k.Activities
|
|||||||
if (selfFacing.Facing != cargoFacing.Facing)
|
if (selfFacing.Facing != cargoFacing.Facing)
|
||||||
return Util.SequenceActivities(new Turn(self, cargoFacing.Facing), this);
|
return Util.SequenceActivities(new Turn(self, cargoFacing.Facing), this);
|
||||||
state = State.Pickup;
|
state = State.Pickup;
|
||||||
return Util.SequenceActivities(new HeliLand(false), new Wait(10), this);
|
return Util.SequenceActivities(new HeliLand(self, false), new Wait(10), this);
|
||||||
|
|
||||||
case State.Pickup:
|
case State.Pickup:
|
||||||
// Remove our carryable from world
|
// Remove our carryable from world
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA.Scripting
|
|||||||
{
|
{
|
||||||
paradrop.SetLZ(cell, true);
|
paradrop.SetLZ(cell, true);
|
||||||
Self.QueueActivity(new Fly(Self, Target.FromCell(Self.World, cell)));
|
Self.QueueActivity(new Fly(Self, Target.FromCell(Self.World, cell)));
|
||||||
Self.QueueActivity(new FlyOffMap());
|
Self.QueueActivity(new FlyOffMap(Self));
|
||||||
Self.QueueActivity(new RemoveSelf());
|
Self.QueueActivity(new RemoveSelf());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user