Skip to content

Commit

Permalink
Add Soviet apc/flamer rush after 7 minutes
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott_NZ authored and Scott_NZ committed Aug 18, 2012
1 parent 222f17a commit 3114a5b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 23 deletions.
83 changes: 60 additions & 23 deletions OpenRA.Mods.RA/Missions/Allies02Script.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ class Allies02Script : IWorldLoaded, ITick
Actor badgerEntryPoint;
Actor badgerDropPoint;
Actor sovietRallyPoint;
Actor flamersEntryPoint;

Actor einsteinChinook;

World world;

Player allies1;
Player allies2;
Player soviets;
Expand All @@ -67,19 +67,24 @@ class Allies02Script : IWorldLoaded, ITick

const string InfantryQueueName = "Infantry";
const string VehicleQueueName = "Vehicle";
static readonly string[] SovietInfantry = { "e1", "e2", "e3" };
static readonly string[] SovietVehicles = { "3tnk" };
const int SovietGroupSize = 5;
static List<string> sovietInfantry = new List<string> { "e1", "e2", "e3" };
static List<string> sovietVehicles = new List<string> { "3tnk" };
static readonly string[] SovietVehicleAdditions = { "v2rl" };
const int SovietGroupSize = 3;
const int SovietVehicleAdditionsTicks = 1500 * 4;

const int StartReinforcementsTicks = 25 * 10;
const int ReinforcementsTicks = 1500 * 12;
static readonly string[] Reinforcements = { "2tnk", "2tnk", "2tnk", "mcv" };
const int ReinforcementsCash = 2000;

const int ParatroopersTicks = 1500 * 5;
const int ParatroopersTicks = 1500 * 10;
static readonly string[] Paratroopers = { "e1", "e1", "e1", "e2", "3tnk" };
const string BadgerName = "badr";

const int FlamerTicks = 1500 * 7;
static readonly string[] Flamers = { "e4", "e4", "e4", "e4", "e4" };
const string ApcName = "apc";

const string ChinookName = "tran";
const string SignalFlareName = "flare";
const string EngineerName = "e6";
Expand Down Expand Up @@ -138,15 +143,20 @@ public void Tick(Actor self)
if (world.FrameNumber == 1)
{
InitializeSovietFactories();
}
if (world.FrameNumber == StartReinforcementsTicks)
{
StartReinforcementsTimer();
}
if (world.FrameNumber == ParatroopersTicks)
{
ParadropSovietUnits();
}
if (world.FrameNumber == FlamerTicks)
{
RushSovietFlamers();
}
if (world.FrameNumber == SovietVehicleAdditionsTicks)
{
sovietVehicles.AddRange(SovietVehicleAdditions);
}
if (world.FrameNumber % 25 == 0)
{
AddSovietCashIfRequired();
Expand Down Expand Up @@ -212,35 +222,40 @@ void BuildSovietUnits()
{
if (!sovietBarracks.Destroyed)
{
BuildSovietUnit(InfantryQueueName, SovietInfantry.Random(world.SharedRandom));
BuildSovietUnit(InfantryQueueName, sovietInfantry.Random(world.SharedRandom));
}
if (!sovietWarFactory.Destroyed)
{
BuildSovietUnit(VehicleQueueName, SovietVehicles.Random(world.SharedRandom));
BuildSovietUnit(VehicleQueueName, sovietVehicles.Random(world.SharedRandom));
}
}

void ManageSovietUnits()
{
var idleSovietUnits = UnitsNearActor(allies2BasePoint, 20).Where(a => a.Owner == soviets && a.IsIdle);
var idleSovietUnitsAtRP = UnitsNearActor(sovietRallyPoint, 5).Where(a => a.Owner == soviets && a.IsIdle);
var idleSovietUnits = ForcesNearActor(allies2BasePoint, 20).Where(a => a.Owner == soviets && a.IsIdle);
var idleSovietUnitsAtRP = ForcesNearActor(sovietRallyPoint, 5).Where(a => a.Owner == soviets && a.IsIdle);
if (idleSovietUnitsAtRP.Count() >= SovietGroupSize)
{
idleSovietUnits = idleSovietUnits.Union(idleSovietUnitsAtRP);
}
foreach (var unit in idleSovietUnits)
{
var closestAlliedBuilding = BuildingsNearActor(allies2BasePoint, 20)
.Where(a => a.Owner == allies2)
.OrderBy(a => (unit.Location - a.Location).LengthSquared)
.FirstOrDefault();
var closestAlliedBuilding = ClosestAlliedBuilding(unit, 20);
if (closestAlliedBuilding != null)
{
unit.QueueActivity(new AttackMove.AttackMoveActivity(unit, new Move.Move(closestAlliedBuilding.Location, 3)));
}
}
}

Actor ClosestAlliedBuilding(Actor actor, int range)
{
return BuildingsNearActor(allies2BasePoint, range)
.Where(a => a.Owner == allies2)
.OrderBy(a => (actor.Location - a.Location).LengthSquared)
.FirstOrDefault();
}

void InitializeSovietFactories()
{
sovietBarracks.Trait<RallyPoint>().rallyPoint = sovietRallyPoint.Location;
Expand Down Expand Up @@ -296,6 +311,23 @@ void ParadropSovietUnits()
}
}

void RushSovietFlamers()
{
var closestAlliedBuilding = ClosestAlliedBuilding(badgerDropPoint, 10);
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 ReinforcementsTimerExpired(CountdownTimerWidget timer)
{
timer.Visible = false;
Expand Down Expand Up @@ -331,21 +363,25 @@ void SendChinook()
einsteinChinook.QueueActivity(new RemoveSelf());
}

IEnumerable<Actor> BuildingsNearActor(Actor actor, int range)
IEnumerable<Actor> UnitsNearActor(Actor actor, int range)
{
return world.FindUnitsInCircle(actor.CenterLocation, Game.CellSize * range)
.Where(a => a.IsInWorld && a != world.WorldActor && !a.Destroyed && a.HasTrait<Building>() && !a.HasTrait<Wall>() && !a.Owner.NonCombatant);
.Where(a => a.IsInWorld && a != world.WorldActor && !a.Destroyed && !a.Owner.NonCombatant);
}

IEnumerable<Actor> UnitsNearActor(Actor actor, int range)
IEnumerable<Actor> BuildingsNearActor(Actor actor, int range)
{
return world.FindUnitsInCircle(actor.CenterLocation, Game.CellSize * range)
.Where(a => a.IsInWorld && a != world.WorldActor && !a.Destroyed && a.HasTrait<IMove>() && !a.Owner.NonCombatant);
return UnitsNearActor(actor, range).Where(a => a.HasTrait<Building>() && !a.HasTrait<Wall>());
}

IEnumerable<Actor> ForcesNearActor(Actor actor, int range)
{
return UnitsNearActor(actor, range).Where(a => a.HasTrait<IMove>());
}

bool AlliesControlMiss()
{
var units = UnitsNearActor(engineerMiss, EngineerMissClearRange);
var units = ForcesNearActor(engineerMiss, EngineerMissClearRange);
return units.Any() && units.All(a => a.Owner == allies1);
}

Expand Down Expand Up @@ -379,6 +415,7 @@ public void WorldLoaded(World w)
sovietBarracks = actors["SovietBarracks"];
sovietWarFactory = actors["SovietWarFactory"];
sovietRallyPoint = actors["SovietRallyPoint"];
flamersEntryPoint = actors["FlamersEntryPoint"];
w.WorldActor.Trait<Shroud>().Explore(w, sam1.Location, 2);
w.WorldActor.Trait<Shroud>().Explore(w, sam2.Location, 2);
w.WorldActor.Trait<Shroud>().Explore(w, sam3.Location, 2);
Expand Down
Binary file modified mods/ra/maps/allies-02.oramap
Binary file not shown.

0 comments on commit 3114a5b

Please sign in to comment.