Create MissionUtils.cs for shared mission code
This commit is contained in:
@@ -145,7 +145,13 @@ namespace OpenRA.Mods.RA.Missions
|
|||||||
}
|
}
|
||||||
if (currentAttackWave == EinsteinChinookAttackWave)
|
if (currentAttackWave == EinsteinChinookAttackWave)
|
||||||
{
|
{
|
||||||
FlyEinsteinFromExtractionLZ();
|
einsteinChinook = MissionUtils.ExtractUnitWithChinook(
|
||||||
|
world,
|
||||||
|
allies,
|
||||||
|
einstein,
|
||||||
|
extractionLZEntryPoint.Location,
|
||||||
|
extractionLZ.Location,
|
||||||
|
chinookExitPoint.Location);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (einsteinChinook != null)
|
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()
|
bool AlliesControlLab()
|
||||||
{
|
{
|
||||||
var units = UnitsNearActor(lab, LabClearRange);
|
var units = world.ForcesNearLocation(lab.CenterLocation, LabClearRange);
|
||||||
return units.Any() && units.All(a => a.Owner == allies);
|
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()
|
void FlyTanyaToInsertionLZ()
|
||||||
{
|
{
|
||||||
tanya = world.CreateActor(false, TanyaName, new TypeDictionary { new OwnerInit(allies) });
|
tanya = MissionUtils.InsertUnitWithChinook(
|
||||||
var chinook = world.CreateActor(ChinookName, new TypeDictionary { new OwnerInit(allies), new LocationInit(insertionLZEntryPoint.Location) });
|
world,
|
||||||
chinook.Trait<Cargo>().Load(chinook, tanya);
|
allies,
|
||||||
chinook.QueueActivity(new HeliFly(insertionLZ.CenterLocation));
|
TanyaName,
|
||||||
chinook.QueueActivity(new Turn(0));
|
insertionLZEntryPoint.Location,
|
||||||
chinook.QueueActivity(new HeliLand(true, 0));
|
insertionLZ.Location,
|
||||||
chinook.QueueActivity(new UnloadCargo(true));
|
chinookExitPoint.Location,
|
||||||
chinook.QueueActivity(new CallFunc(() => Sound.Play("laugh1.aud")));
|
unit =>
|
||||||
chinook.QueueActivity(new CallFunc(() => tanya.QueueActivity(new Move.Move(insertionLZ.Location - new CVec(1, 0)))));
|
{
|
||||||
chinook.QueueActivity(new Wait(150));
|
Sound.Play("laugh1.aud");
|
||||||
chinook.QueueActivity(new HeliFly(chinookExitPoint.CenterLocation));
|
unit.QueueActivity(new Move.Move(insertionLZ.Location - new CVec(1, 0)));
|
||||||
chinook.QueueActivity(new RemoveSelf());
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetAlliedUnitsToDefensiveStance()
|
void SetAlliedUnitsToDefensiveStance()
|
||||||
|
|||||||
@@ -238,7 +238,7 @@ namespace OpenRA.Mods.RA.Missions
|
|||||||
|
|
||||||
void ManageSovietUnits()
|
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)
|
if (idleSovietUnitsAtRP.Count() >= SovietGroupSize)
|
||||||
{
|
{
|
||||||
var firstUnit = idleSovietUnitsAtRP.FirstOrDefault();
|
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)
|
foreach (var unit in idleSovietUnits)
|
||||||
{
|
{
|
||||||
var closestAlliedBuilding = ClosestAlliedBuilding(unit, 40);
|
var closestAlliedBuilding = ClosestAlliedBuilding(unit, 40);
|
||||||
@@ -268,7 +268,7 @@ namespace OpenRA.Mods.RA.Missions
|
|||||||
|
|
||||||
Actor ClosestAlliedBuilding(Actor actor, int range)
|
Actor ClosestAlliedBuilding(Actor actor, int range)
|
||||||
{
|
{
|
||||||
return BuildingsNearLocation(actor.CenterLocation, range)
|
return world.BuildingsNearLocation(actor.CenterLocation, range)
|
||||||
.Where(a => a.Owner == allies2)
|
.Where(a => a.Owner == allies2)
|
||||||
.OrderBy(a => (actor.Location - a.Location).LengthSquared)
|
.OrderBy(a => (actor.Location - a.Location).LengthSquared)
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
@@ -387,29 +387,13 @@ namespace OpenRA.Mods.RA.Missions
|
|||||||
einsteinChinook.QueueActivity(new RemoveSelf());
|
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()
|
bool EngineerSafe()
|
||||||
{
|
{
|
||||||
if (engineer.Destroyed)
|
if (engineer.Destroyed)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var units = ForcesNearLocation(engineer.CenterLocation, EngineerSafeRange);
|
var units = world.ForcesNearLocation(engineer.CenterLocation, EngineerSafeRange);
|
||||||
return units.Any() && units.All(a => a.Owner == allies1);
|
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\Allies01Script.cs" />
|
||||||
<Compile Include="Missions\Allies02Script.cs" />
|
<Compile Include="Missions\Allies02Script.cs" />
|
||||||
<Compile Include="Missions\DefaultShellmapScript.cs" />
|
<Compile Include="Missions\DefaultShellmapScript.cs" />
|
||||||
|
<Compile Include="Missions\MissionUtils.cs" />
|
||||||
<Compile Include="Modifiers\FrozenUnderFog.cs" />
|
<Compile Include="Modifiers\FrozenUnderFog.cs" />
|
||||||
<Compile Include="Modifiers\HiddenUnderFog.cs" />
|
<Compile Include="Modifiers\HiddenUnderFog.cs" />
|
||||||
<Compile Include="Move\Drag.cs" />
|
<Compile Include="Move\Drag.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user