Create MissionUtils.cs for shared mission code
This commit is contained in:
@@ -145,7 +145,13 @@ namespace OpenRA.Mods.RA.Missions
|
||||
}
|
||||
if (currentAttackWave == EinsteinChinookAttackWave)
|
||||
{
|
||||
FlyEinsteinFromExtractionLZ();
|
||||
einsteinChinook = MissionUtils.ExtractUnitWithChinook(
|
||||
world,
|
||||
allies,
|
||||
einstein,
|
||||
extractionLZEntryPoint.Location,
|
||||
extractionLZ.Location,
|
||||
chinookExitPoint.Location);
|
||||
}
|
||||
}
|
||||
if (einsteinChinook != null)
|
||||
@@ -211,15 +217,9 @@ namespace OpenRA.Mods.RA.Missions
|
||||
}
|
||||
}
|
||||
|
||||
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<IMove>() && !a.Owner.NonCombatant);
|
||||
}
|
||||
|
||||
bool AlliesControlLab()
|
||||
{
|
||||
var units = UnitsNearActor(lab, LabClearRange);
|
||||
var units = world.ForcesNearLocation(lab.CenterLocation, LabClearRange);
|
||||
return units.Any() && units.All(a => a.Owner == allies);
|
||||
}
|
||||
|
||||
@@ -239,32 +239,20 @@ namespace OpenRA.Mods.RA.Missions
|
||||
}
|
||||
}
|
||||
|
||||
void FlyEinsteinFromExtractionLZ()
|
||||
{
|
||||
einsteinChinook = world.CreateActor(ChinookName, new TypeDictionary { new OwnerInit(allies), new LocationInit(extractionLZEntryPoint.Location) });
|
||||
einsteinChinook.QueueActivity(new HeliFly(extractionLZ.CenterLocation));
|
||||
einsteinChinook.QueueActivity(new Turn(0));
|
||||
einsteinChinook.QueueActivity(new HeliLand(true, 0));
|
||||
einsteinChinook.QueueActivity(new WaitFor(() => einsteinChinook.Trait<Cargo>().Passengers.Contains(einstein)));
|
||||
einsteinChinook.QueueActivity(new Wait(150));
|
||||
einsteinChinook.QueueActivity(new HeliFly(chinookExitPoint.CenterLocation));
|
||||
einsteinChinook.QueueActivity(new RemoveSelf());
|
||||
}
|
||||
|
||||
void FlyTanyaToInsertionLZ()
|
||||
{
|
||||
tanya = world.CreateActor(false, TanyaName, new TypeDictionary { new OwnerInit(allies) });
|
||||
var chinook = world.CreateActor(ChinookName, new TypeDictionary { new OwnerInit(allies), new LocationInit(insertionLZEntryPoint.Location) });
|
||||
chinook.Trait<Cargo>().Load(chinook, tanya);
|
||||
chinook.QueueActivity(new HeliFly(insertionLZ.CenterLocation));
|
||||
chinook.QueueActivity(new Turn(0));
|
||||
chinook.QueueActivity(new HeliLand(true, 0));
|
||||
chinook.QueueActivity(new UnloadCargo(true));
|
||||
chinook.QueueActivity(new CallFunc(() => Sound.Play("laugh1.aud")));
|
||||
chinook.QueueActivity(new CallFunc(() => tanya.QueueActivity(new Move.Move(insertionLZ.Location - new CVec(1, 0)))));
|
||||
chinook.QueueActivity(new Wait(150));
|
||||
chinook.QueueActivity(new HeliFly(chinookExitPoint.CenterLocation));
|
||||
chinook.QueueActivity(new RemoveSelf());
|
||||
tanya = MissionUtils.InsertUnitWithChinook(
|
||||
world,
|
||||
allies,
|
||||
TanyaName,
|
||||
insertionLZEntryPoint.Location,
|
||||
insertionLZ.Location,
|
||||
chinookExitPoint.Location,
|
||||
unit =>
|
||||
{
|
||||
Sound.Play("laugh1.aud");
|
||||
unit.QueueActivity(new Move.Move(insertionLZ.Location - new CVec(1, 0)));
|
||||
});
|
||||
}
|
||||
|
||||
void SetAlliedUnitsToDefensiveStance()
|
||||
|
||||
@@ -238,7 +238,7 @@ namespace OpenRA.Mods.RA.Missions
|
||||
|
||||
void ManageSovietUnits()
|
||||
{
|
||||
var idleSovietUnitsAtRP = ForcesNearLocation(sovietRallyPoint.CenterLocation, 3).Where(a => a.Owner == soviets && a.IsIdle && a.HasTrait<Mobile>());
|
||||
var idleSovietUnitsAtRP = world.ForcesNearLocation(sovietRallyPoint.CenterLocation, 3).Where(a => a.Owner == soviets && a.IsIdle && a.HasTrait<Mobile>());
|
||||
if (idleSovietUnitsAtRP.Count() >= SovietGroupSize)
|
||||
{
|
||||
var firstUnit = idleSovietUnitsAtRP.FirstOrDefault();
|
||||
@@ -255,7 +255,7 @@ namespace OpenRA.Mods.RA.Missions
|
||||
}
|
||||
}
|
||||
}
|
||||
var idleSovietUnits = ForcesNearLocation(allies2BasePoint.CenterLocation, 20).Where(a => a.Owner == soviets && a.IsIdle);
|
||||
var idleSovietUnits = world.ForcesNearLocation(allies2BasePoint.CenterLocation, 20).Where(a => a.Owner == soviets && a.IsIdle);
|
||||
foreach (var unit in idleSovietUnits)
|
||||
{
|
||||
var closestAlliedBuilding = ClosestAlliedBuilding(unit, 40);
|
||||
@@ -268,7 +268,7 @@ namespace OpenRA.Mods.RA.Missions
|
||||
|
||||
Actor ClosestAlliedBuilding(Actor actor, int range)
|
||||
{
|
||||
return BuildingsNearLocation(actor.CenterLocation, range)
|
||||
return world.BuildingsNearLocation(actor.CenterLocation, range)
|
||||
.Where(a => a.Owner == allies2)
|
||||
.OrderBy(a => (actor.Location - a.Location).LengthSquared)
|
||||
.FirstOrDefault();
|
||||
@@ -387,29 +387,13 @@ namespace OpenRA.Mods.RA.Missions
|
||||
einsteinChinook.QueueActivity(new RemoveSelf());
|
||||
}
|
||||
|
||||
IEnumerable<Actor> UnitsNearLocation(PPos location, int range)
|
||||
{
|
||||
return world.FindUnitsInCircle(location, Game.CellSize * range)
|
||||
.Where(a => a.IsInWorld && a != world.WorldActor && !a.Destroyed && !a.Owner.NonCombatant);
|
||||
}
|
||||
|
||||
IEnumerable<Actor> BuildingsNearLocation(PPos location, int range)
|
||||
{
|
||||
return UnitsNearLocation(location, range).Where(a => a.HasTrait<Building>() && !a.HasTrait<Wall>());
|
||||
}
|
||||
|
||||
IEnumerable<Actor> ForcesNearLocation(PPos location, int range)
|
||||
{
|
||||
return UnitsNearLocation(location, range).Where(a => a.HasTrait<IMove>());
|
||||
}
|
||||
|
||||
bool EngineerSafe()
|
||||
{
|
||||
if (engineer.Destroyed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var units = ForcesNearLocation(engineer.CenterLocation, EngineerSafeRange);
|
||||
var units = world.ForcesNearLocation(engineer.CenterLocation, EngineerSafeRange);
|
||||
return units.Any() && units.All(a => a.Owner == allies1);
|
||||
}
|
||||
|
||||
|
||||
69
OpenRA.Mods.RA/Missions/MissionUtils.cs
Normal file
69
OpenRA.Mods.RA/Missions/MissionUtils.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2012 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 System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Mods.RA.Air;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Missions
|
||||
{
|
||||
public static class MissionUtils
|
||||
{
|
||||
public static IEnumerable<Actor> UnitsNearLocation(this World world, PPos location, int range)
|
||||
{
|
||||
return world.FindUnitsInCircle(location, Game.CellSize * range)
|
||||
.Where(a => a.IsInWorld && a != world.WorldActor && !a.Destroyed && !a.Owner.NonCombatant);
|
||||
}
|
||||
|
||||
public static IEnumerable<Actor> BuildingsNearLocation(this World world, PPos location, int range)
|
||||
{
|
||||
return UnitsNearLocation(world, location, range).Where(a => a.HasTrait<Building>() && !a.HasTrait<Wall>());
|
||||
}
|
||||
|
||||
public static IEnumerable<Actor> ForcesNearLocation(this World world, PPos location, int range)
|
||||
{
|
||||
return UnitsNearLocation(world, location, range).Where(a => a.HasTrait<IMove>());
|
||||
}
|
||||
|
||||
public static Actor ExtractUnitWithChinook(World world, Player owner, Actor unit, CPos entry, CPos lz, CPos exit)
|
||||
{
|
||||
var chinook = world.CreateActor("tran", new TypeDictionary { new OwnerInit(owner), new LocationInit(entry) });
|
||||
chinook.QueueActivity(new HeliFly(Util.CenterOfCell(lz)));
|
||||
chinook.QueueActivity(new Turn(0));
|
||||
chinook.QueueActivity(new HeliLand(true, 0));
|
||||
chinook.QueueActivity(new WaitFor(() => chinook.Trait<Cargo>().Passengers.Contains(unit)));
|
||||
chinook.QueueActivity(new Wait(150));
|
||||
chinook.QueueActivity(new HeliFly(Util.CenterOfCell(exit)));
|
||||
chinook.QueueActivity(new RemoveSelf());
|
||||
return chinook;
|
||||
}
|
||||
|
||||
public static Actor InsertUnitWithChinook(World world, Player owner, string unitName, CPos entry, CPos lz, CPos exit, Action<Actor> afterUnload)
|
||||
{
|
||||
var unit = world.CreateActor(false, unitName, new TypeDictionary { new OwnerInit(owner) });
|
||||
var chinook = world.CreateActor("tran", new TypeDictionary { new OwnerInit(owner), new LocationInit(entry) });
|
||||
chinook.Trait<Cargo>().Load(chinook, unit);
|
||||
chinook.QueueActivity(new HeliFly(Util.CenterOfCell(lz)));
|
||||
chinook.QueueActivity(new Turn(0));
|
||||
chinook.QueueActivity(new HeliLand(true, 0));
|
||||
chinook.QueueActivity(new UnloadCargo(true));
|
||||
chinook.QueueActivity(new CallFunc(() => afterUnload(unit)));
|
||||
chinook.QueueActivity(new Wait(150));
|
||||
chinook.QueueActivity(new HeliFly(Util.CenterOfCell(exit)));
|
||||
chinook.QueueActivity(new RemoveSelf());
|
||||
return unit;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -241,6 +241,7 @@
|
||||
<Compile Include="Missions\Allies01Script.cs" />
|
||||
<Compile Include="Missions\Allies02Script.cs" />
|
||||
<Compile Include="Missions\DefaultShellmapScript.cs" />
|
||||
<Compile Include="Missions\MissionUtils.cs" />
|
||||
<Compile Include="Modifiers\FrozenUnderFog.cs" />
|
||||
<Compile Include="Modifiers\HiddenUnderFog.cs" />
|
||||
<Compile Include="Move\Drag.cs" />
|
||||
|
||||
Reference in New Issue
Block a user