Allies 02 code maintenance. Add FreeActorInit so free harvesters with procs can be disabled etc

This commit is contained in:
Scott_NZ
2013-02-25 20:37:08 +13:00
parent 3bc9e7d2e4
commit e57de0ebce
6 changed files with 95 additions and 182 deletions

View File

@@ -21,20 +21,22 @@ namespace OpenRA.Mods.RA
public readonly int2 SpawnOffset = int2.Zero;
public readonly int Facing = 0;
public object Create( ActorInitializer init ) { return new FreeActor(init.self, this); }
public object Create( ActorInitializer init ) { return new FreeActor(init, this); }
}
public class FreeActor
{
public FreeActor(Actor self, FreeActorInfo info)
public FreeActor(ActorInitializer init, FreeActorInfo info)
{
self.World.AddFrameEndTask(
if (init.Contains<FreeActorInit>() && !init.Get<FreeActorInit>().value) return;
init.self.World.AddFrameEndTask(
w =>
{
var a = w.CreateActor(info.Actor, new TypeDictionary
{
new LocationInit( self.Location + (CVec)info.SpawnOffset ),
new OwnerInit( self.Owner ),
new LocationInit( init.self.Location + (CVec)info.SpawnOffset ),
new OwnerInit( init.self.Owner ),
new FacingInit( info.Facing ),
});
@@ -43,4 +45,13 @@ namespace OpenRA.Mods.RA
});
}
}
public class FreeActorInit : IActorInit<bool>
{
[FieldFromYamlKey]
public readonly bool value = true;
public FreeActorInit() { }
public FreeActorInit(bool init) { value = init; }
public bool Value(World world) { return value; }
}
}

View File

@@ -57,6 +57,7 @@ namespace OpenRA.Mods.RA.Missions
Actor sam2;
Actor sam3;
Actor sam4;
Actor[] sams;
Actor tanya;
Actor einstein;
Actor engineer;
@@ -74,8 +75,6 @@ namespace OpenRA.Mods.RA.Missions
Actor parabombPoint1;
Actor parabombPoint2;
Actor sovietRallyPoint;
Actor flamersEntryPoint;
Actor tanksEntryPoint;
Actor townPoint;
Actor sovietTownAttackPoint1;
Actor sovietTownAttackPoint2;
@@ -103,7 +102,7 @@ namespace OpenRA.Mods.RA.Missions
static readonly string[] SovietVehicles1 = { "3tnk" };
static readonly string[] SovietVehicles2 = { "3tnk", "v2rl" };
const int SovietVehiclesUpgradeTicks = 1500 * 4;
const int SovietGroupSize = 20;
const int SovietGroupSize = 5;
const int ReinforcementsTicks = 1500 * 12;
static readonly string[] Reinforcements =
@@ -180,12 +179,6 @@ namespace OpenRA.Mods.RA.Missions
if (allies1 != allies2)
{
if (world.FrameNumber == TanksTicks)
RushSovietUnits();
if (world.FrameNumber == FlamersTicks)
RushSovietFlamers();
if (yak == null || (yak != null && !yak.IsDead() && (yak.GetCurrentActivity() is FlyCircle || yak.IsIdle)))
{
var alliedUnitsNearYakPoint = world.FindAliveCombatantActorsInCircle(yakAttackPoint.CenterLocation, 10)
@@ -218,22 +211,19 @@ namespace OpenRA.Mods.RA.Missions
}
if (objectives[DestroySamSitesID].Status == ObjectiveStatus.InProgress)
{
if ((sam1.Destroyed || sam1.Owner != soviets)
&& (sam2.Destroyed || sam2.Owner != soviets)
&& (sam3.Destroyed || sam3.Owner != soviets)
&& (sam4.Destroyed || sam4.Owner != soviets))
if (sams.All(s => s.IsDead() || s.Owner != soviets))
{
objectives[DestroySamSitesID].Status = ObjectiveStatus.Completed;
objectives[ExtractEinsteinID].Status = ObjectiveStatus.InProgress;
OnObjectivesUpdated(true);
SpawnSignalFlare();
world.CreateActor(SignalFlareName, new TypeDictionary { new OwnerInit(allies1), new LocationInit(extractionLZ.Location) });
Sound.Play("flaren1.aud");
ExtractEinsteinAtLZ();
}
}
if (objectives[ExtractEinsteinID].Status == ObjectiveStatus.InProgress && einsteinChinook != null)
{
if (einsteinChinook.Destroyed)
if (einsteinChinook.IsDead())
{
objectives[ExtractEinsteinID].Status = ObjectiveStatus.Failed;
objectives[MaintainPresenceID].Status = ObjectiveStatus.Failed;
@@ -253,22 +243,19 @@ namespace OpenRA.Mods.RA.Missions
}
}
if (tanya.Destroyed)
if (tanya.IsDead())
MissionFailed("Tanya was killed.");
else if (einstein.Destroyed)
else if (einstein.IsDead())
MissionFailed("Einstein was killed.");
world.AddFrameEndTask(w =>
{
if (!world.FindAliveCombatantActorsInCircle(allies2BasePoint.CenterLocation, 20)
.Any(a => a.HasTrait<Building>() && !a.HasTrait<Wall>() && (a.Owner == allies || a.Owner == allies2)))
else if (!world.Actors.Any(a => (a.Owner == allies || a.Owner == allies2) && !a.IsDead()
&& (a.HasTrait<Building>() && !a.HasTrait<Wall>()) || a.HasTrait<BaseBuilding>()))
{
objectives[MaintainPresenceID].Status = ObjectiveStatus.Failed;
OnObjectivesUpdated(true);
MissionFailed("The Allied reinforcements have been defeated.");
}
});
}
void UpdateDeaths()
@@ -308,10 +295,10 @@ namespace OpenRA.Mods.RA.Missions
void BuildSovietUnits()
{
if (!sovietBarracks.Destroyed)
if (!sovietBarracks.IsDead())
BuildSovietUnit(InfantryQueueName, SovietInfantry.Random(world.SharedRandom));
if (!sovietWarFactory.Destroyed)
if (!sovietWarFactory.IsDead())
{
var vehicles = world.FrameNumber >= SovietVehiclesUpgradeTicks ? SovietVehicles2 : SovietVehicles1;
BuildSovietUnit(VehicleQueueName, vehicles.Random(world.SharedRandom));
@@ -320,44 +307,39 @@ namespace OpenRA.Mods.RA.Missions
void ManageSovietUnits()
{
var idleSovietUnitsAtRP = world.FindAliveCombatantActorsInCircle(sovietRallyPoint.CenterLocation, 3)
.Where(a => a.Owner == soviets && a.IsIdle && a.HasTrait<IMove>());
if (idleSovietUnitsAtRP.Count() >= SovietGroupSize)
var units = world.FindAliveCombatantActorsInCircle(sovietRallyPoint.CenterLocation, 10)
.Where(u => u.IsIdle && u.HasTrait<Mobile>() && u.HasTrait<AttackBase>() && u.Owner == soviets)
.Except(world.WorldActor.Trait<SpawnMapActors>().Actors.Values);
if (units.Count() >= SovietGroupSize)
{
var firstUnit = idleSovietUnitsAtRP.FirstOrDefault();
if (firstUnit != null)
{
var closestAlliedBuilding = ClosestAlliedBuilding(firstUnit, 40);
if (closestAlliedBuilding != null)
foreach (var unit in idleSovietUnitsAtRP)
{
unit.Trait<Mobile>().Nudge(unit, unit, true);
unit.QueueActivity(new AttackMove.AttackMoveActivity(unit, new Attack(Target.FromActor(closestAlliedBuilding), 3)));
}
}
foreach (var unit in units)
MissionUtils.AttackNearestLandActor(true, unit, allies2);
}
var idleSovietUnits = world.FindAliveCombatantActorsInCircle(allies2BasePoint.CenterLocation, 20)
.Where(a => a.Owner == soviets && a.IsIdle && a.HasTrait<IMove>());
var scatteredUnits = world.Actors.Where(u => u.IsInWorld && !u.IsDead() && u.IsIdle
&& u.HasTrait<Mobile>() && u.HasTrait<AttackBase>() && u.Owner == soviets)
.Except(world.WorldActor.Trait<SpawnMapActors>().Actors.Values)
.Except(units);
foreach (var unit in idleSovietUnits)
{
var closestAlliedBuilding = ClosestAlliedBuilding(unit, 40);
if (closestAlliedBuilding != null)
unit.QueueActivity(new AttackMove.AttackMoveActivity(unit, new Attack(Target.FromActor(closestAlliedBuilding), 3)));
}
foreach (var unit in scatteredUnits)
MissionUtils.AttackNearestLandActor(true, unit, allies2);
}
Actor ClosestAlliedBuilding(Actor actor, int range)
void SetupAlliedBase()
{
return MissionUtils.ClosestPlayerBuilding(world, allies2, actor.CenterLocation, range);
foreach (var actor in world.Actors.Where(a => a.Owner == allies && a != allies.PlayerActor))
{
actor.ChangeOwner(allies2);
if (actor.Info.Name == "pbox")
{
actor.AddTrait(new TransformedAction(s => s.Trait<Cargo>().Load(s, world.CreateActor(false, "e1", allies2, null, null))));
actor.QueueActivity(new Transform(actor, "hbox.e1") { SkipMakeAnims = true });
}
if (actor.Info.Name == "proc")
actor.QueueActivity(new Transform(actor, "proc") { SkipMakeAnims = true });
foreach (var c in actor.TraitsImplementing<INotifyCapture>())
c.OnCapture(actor, actor, allies, allies2);
}
IEnumerable<Actor> ClosestAlliedBuildings(Actor actor, int range)
{
return MissionUtils.ClosestPlayerBuildings(world, allies2, actor.CenterLocation, range);
}
void InitializeSovietFactories()
@@ -365,7 +347,7 @@ namespace OpenRA.Mods.RA.Missions
var sbrp = sovietBarracks.Trait<RallyPoint>();
var swrp = sovietWarFactory.Trait<RallyPoint>();
sbrp.rallyPoint = swrp.rallyPoint = sovietRallyPoint.Location;
sbrp.nearEnough = swrp.nearEnough = 3;
sbrp.nearEnough = swrp.nearEnough = 6;
sovietBarracks.Trait<PrimaryBuilding>().SetPrimaryProducer(sovietBarracks, true);
sovietWarFactory.Trait<PrimaryBuilding>().SetPrimaryProducer(sovietWarFactory, true);
}
@@ -378,11 +360,6 @@ namespace OpenRA.Mods.RA.Missions
queue.ResolveOrder(queue.self, Order.StartProduction(queue.self, unit, 1));
}
void SpawnSignalFlare()
{
world.CreateActor(SignalFlareName, new TypeDictionary { new OwnerInit(allies1), new LocationInit(extractionLZ.Location) });
}
void StartReinforcementsTimer()
{
Sound.Play("timergo1.aud");
@@ -409,38 +386,6 @@ namespace OpenRA.Mods.RA.Missions
.QueueActivity(new Move.Move(allies2BasePoint.Location));
}
void RushSovietUnits()
{
var closestAlliedBuildings = ClosestAlliedBuildings(badgerDropPoint1, 40);
if (!closestAlliedBuildings.Any()) return;
foreach (var tank in Tanks)
{
var unit = world.CreateActor(tank, new TypeDictionary
{
new OwnerInit(soviets),
new LocationInit(tanksEntryPoint.Location)
});
foreach (var building in closestAlliedBuildings)
unit.QueueActivity(new Attack(Target.FromActor(building), 3));
}
}
void RushSovietFlamers()
{
var closestAlliedBuilding = ClosestAlliedBuilding(badgerDropPoint1, 40);
if (closestAlliedBuilding == null) return;
var apc = world.CreateActor(ApcName, new TypeDictionary { new OwnerInit(soviets), new LocationInit(flamersEntryPoint.Location) });
foreach (var flamer in Flamers)
{
var unit = world.CreateActor(false, flamer, new TypeDictionary { new OwnerInit(soviets) });
apc.Trait<Cargo>().Load(apc, unit);
}
apc.QueueActivity(new MoveAdjacentTo(Target.FromActor(closestAlliedBuilding)));
apc.QueueActivity(new UnloadCargo(true));
}
void ExtractEinsteinAtLZ()
{
einsteinChinook = MissionUtils.ExtractUnitWithChinook(
@@ -461,7 +406,7 @@ namespace OpenRA.Mods.RA.Missions
void TransferTownUnitsToAllies()
{
foreach (var unit in world.FindAliveNonCombatantActorsInCircle(townPoint.CenterLocation, AlliedTownTransferRange)
.Where(a => a.HasTrait<IMove>()))
.Where(a => a.HasTrait<Mobile>()))
unit.ChangeOwner(allies1);
}
@@ -492,11 +437,14 @@ namespace OpenRA.Mods.RA.Missions
allies = w.Players.Single(p => p.InternalName == "Allies");
soviets = w.Players.Single(p => p.InternalName == "Soviets");
soviets.PlayerActor.Trait<PlayerResources>().Cash = 1000;
var actors = w.WorldActor.Trait<SpawnMapActors>().Actors;
sam1 = actors["SAM1"];
sam2 = actors["SAM2"];
sam3 = actors["SAM3"];
sam4 = actors["SAM4"];
sams = new[] { sam1, sam2, sam3, sam4 };
tanya = actors["Tanya"];
einstein = actors["Einstein"];
engineer = actors["Engineer"];
@@ -515,17 +463,15 @@ namespace OpenRA.Mods.RA.Missions
sovietBarracks = actors["SovietBarracks"];
sovietWarFactory = actors["SovietWarFactory"];
sovietRallyPoint = actors["SovietRallyPoint"];
flamersEntryPoint = actors["FlamersEntryPoint"];
tanksEntryPoint = actors["TanksEntryPoint"];
townPoint = actors["TownPoint"];
sovietTownAttackPoint1 = actors["SovietTownAttackPoint1"];
sovietTownAttackPoint2 = actors["SovietTownAttackPoint2"];
yakEntryPoint = actors["YakEntryPoint"];
yakAttackPoint = actors["YakAttackPoint"];
SetupAlliedBase(actors);
SetupAlliedBase();
var shroud = w.WorldActor.Trait<Shroud>();
var shroud = allies1.Shroud;
shroud.Explore(w, sam1.Location, 2);
shroud.Explore(w, sam2.Location, 2);
shroud.Explore(w, sam3.Location, 2);
@@ -539,20 +485,5 @@ namespace OpenRA.Mods.RA.Missions
MissionUtils.PlayMissionMusic();
}
void SetupAlliedBase(Dictionary<string, Actor> actors)
{
world.AddFrameEndTask(w =>
{
foreach (var actor in actors.Where(a => a.Value.Owner == allies))
actor.Value.ChangeOwner(allies2);
world.CreateActor("proc", new TypeDictionary
{
new LocationInit(actors["Allies2ProcPoint"].Location),
new OwnerInit(allies2)
});
});
}
}
}

View File

@@ -109,30 +109,6 @@ namespace OpenRA.Mods.RA.Missions
return units.Any() && units.All(a => a.Owner == player);
}
public static Actor ClosestPlayerUnit(World world, Player player, PPos location, int range)
{
return ClosestPlayerUnits(world, player, location, range).FirstOrDefault();
}
public static IEnumerable<Actor> ClosestPlayerUnits(World world, Player player, PPos location, int range)
{
return world.FindAliveCombatantActorsInCircle(location, range)
.Where(a => a.Owner == player && a.HasTrait<IMove>())
.OrderBy(a => (location - a.CenterLocation).LengthSquared);
}
public static Actor ClosestPlayerBuilding(World world, Player player, PPos location, int range)
{
return ClosestPlayerBuildings(world, player, location, range).FirstOrDefault();
}
public static IEnumerable<Actor> ClosestPlayerBuildings(World world, Player player, PPos location, int range)
{
return world.FindAliveCombatantActorsInCircle(location, range)
.Where(a => a.Owner == player && a.HasTrait<Building>() && !a.HasTrait<Wall>())
.OrderBy(a => (location - a.CenterLocation).LengthSquared);
}
public static IEnumerable<ProductionQueue> FindQueues(World world, Player player, string category)
{
return world.ActorsWithTrait<ProductionQueue>()
@@ -231,7 +207,7 @@ namespace OpenRA.Mods.RA.Missions
public static void AttackNearestLandActor(bool queued, Actor self, Player enemyPlayer)
{
var enemies = self.World.Actors.Where(u => u.AppearsHostileTo(self) && u.Owner == enemyPlayer
&& ((u.HasTrait<Building>() && !u.HasTrait<Wall>()) || u.HasTrait<Mobile>()) && u.IsInWorld && !u.IsDead());
&& ((u.HasTrait<Building>() && !u.HasTrait<Wall>()) || (u.HasTrait<Mobile>() && !u.HasTrait<Aircraft>())) && u.IsInWorld && !u.IsDead());
var enemy = enemies.OrderBy(u => (self.CenterLocation - u.CenterLocation).LengthSquared).FirstOrDefault();
if (enemy != null)

View File

@@ -8,13 +8,13 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Mods.RA.Move;
using OpenRA.Traits;
using System;
using System.Collections.Generic;
using System.Linq;
namespace OpenRA.Mods.RA.Missions
{
@@ -137,11 +137,10 @@ namespace OpenRA.Mods.RA.Missions
if (baseTransferredTick == -1)
{
var actorsInBase = world.FindUnits(alliedBaseTopLeft.CenterLocation, alliedBaseBottomRight.CenterLocation).Where(a => !a.IsDead() && a.IsInWorld);
var actorsInBase = world.FindUnits(alliedBaseTopLeft.CenterLocation, alliedBaseBottomRight.CenterLocation).Where(a => a != a.Owner.PlayerActor);
if (actorsInBase.Any(a => a.Owner == greece))
{
foreach (var actor in actorsInBase)
TransferActorToAllies(actor);
SetupAlliedBase(actorsInBase);
baseTransferredTick = world.FrameNumber;
objectives[FindOutpostID].Status = ObjectiveStatus.Completed;
OnObjectivesUpdated(true);
@@ -234,7 +233,9 @@ namespace OpenRA.Mods.RA.Missions
}
}
void TransferActorToAllies(Actor actor)
void SetupAlliedBase(IEnumerable<Actor> actors)
{
foreach (var actor in actors)
{
// hack hack hack
actor.ChangeOwner(greece);
@@ -243,11 +244,11 @@ namespace OpenRA.Mods.RA.Missions
actor.AddTrait(new TransformedAction(s => s.Trait<Cargo>().Load(s, world.CreateActor(false, "e1", greece, null, null))));
actor.QueueActivity(new Transform(actor, "hbox.e1") { SkipMakeAnims = true });
}
else if (actor.Info.Name == "proc.nofreeactor")
else if (actor.Info.Name == "proc")
actor.QueueActivity(new Transform(actor, "proc") { SkipMakeAnims = true });
var building = actor.TraitOrDefault<Building>();
if (building != null)
building.OnCapture(actor, actor, neutral, greece);
foreach (var c in actor.TraitsImplementing<INotifyCapture>())
c.OnCapture(actor, actor, neutral, greece);
}
}
void EvacuateCivilians()

View File

@@ -852,9 +852,6 @@ Actors:
Actor301: tc04
Location: 27,33
Owner: Neutral
Actor265: miss
Location: 27,23
Owner: Soviets
Actor402: brik
Location: 22,67
Owner: Soviets
@@ -1481,9 +1478,10 @@ Actors:
Actor290: apwr
Location: 52,42
Owner: Soviets
Allies2ProcPoint: waypoint
Actor875: proc
Location: 25,95
Owner: Allies
FreeActor: False
Actor455: fenc
Location: 31,93
Owner: Allies
@@ -1517,13 +1515,13 @@ Actors:
Actor470: fenc
Location: 26,93
Owner: Allies
Actor454: pbox.e1
Actor454: pbox
Location: 32,93
Owner: Allies
Actor465: fenc
Location: 30,93
Owner: Allies
Actor473: pbox.e1
Actor473: pbox
Location: 40,93
Owner: Allies
Actor472: gun
@@ -3006,6 +3004,9 @@ Rules:
CTNK:
Buildable:
Owner: None
MGG:
Buildable:
Owner: None
CRATE:
GiveCashCrateAction:
SelectionShares: 0

View File

@@ -1754,11 +1754,12 @@ Actors:
Owner: BadGuy
Health: 1
Facing: 0
AlliedBaseProc: proc.nofreeactor
AlliedBaseProc: proc
Location: 27,25
Owner: Neutral
Health: 0.3476563
Facing: 0
FreeActor: False
Actor508: silo
Location: 36,18
Owner: Neutral
@@ -2609,14 +2610,6 @@ Rules:
RenderBuilding:
Image: DOME
-InfiltrateForExploration:
PROC.NoFreeActor:
Inherits: PROC
-Buildable:
RenderBuilding:
Image: PROC
Tooltip:
Icon: procicon
-FreeActor:
V19:
AutoTargetIgnore:
TRAN: