Add more utils to MissionUtils. Extract Allies 02 countdown timer to its own class file
This commit is contained in:
@@ -145,13 +145,7 @@ namespace OpenRA.Mods.RA.Missions
|
||||
}
|
||||
if (currentAttackWave == EinsteinChinookAttackWave)
|
||||
{
|
||||
einsteinChinook = MissionUtils.ExtractUnitWithChinook(
|
||||
world,
|
||||
allies,
|
||||
einstein,
|
||||
extractionLZEntryPoint.Location,
|
||||
extractionLZ.Location,
|
||||
chinookExitPoint.Location);
|
||||
ExtractEinsteinAtLZ();
|
||||
}
|
||||
}
|
||||
if (einsteinChinook != null)
|
||||
@@ -219,8 +213,7 @@ namespace OpenRA.Mods.RA.Missions
|
||||
|
||||
bool AlliesControlLab()
|
||||
{
|
||||
var units = world.ForcesNearLocation(lab.CenterLocation, LabClearRange);
|
||||
return units.Any() && units.All(a => a.Owner == allies);
|
||||
return MissionUtils.AreaSecuredByPlayer(world, allies, lab.CenterLocation, LabClearRange);
|
||||
}
|
||||
|
||||
void SpawnEinsteinAtLab()
|
||||
@@ -239,7 +232,18 @@ namespace OpenRA.Mods.RA.Missions
|
||||
}
|
||||
}
|
||||
|
||||
void FlyTanyaToInsertionLZ()
|
||||
void ExtractEinsteinAtLZ()
|
||||
{
|
||||
einsteinChinook = MissionUtils.ExtractUnitWithChinook(
|
||||
world,
|
||||
allies,
|
||||
einstein,
|
||||
extractionLZEntryPoint.Location,
|
||||
extractionLZ.Location,
|
||||
chinookExitPoint.Location);
|
||||
}
|
||||
|
||||
void InsertTanyaAtLZ()
|
||||
{
|
||||
tanya = MissionUtils.InsertUnitWithChinook(
|
||||
world,
|
||||
@@ -248,11 +252,11 @@ namespace OpenRA.Mods.RA.Missions
|
||||
insertionLZEntryPoint.Location,
|
||||
insertionLZ.Location,
|
||||
chinookExitPoint.Location,
|
||||
unit =>
|
||||
{
|
||||
unit =>
|
||||
{
|
||||
Sound.Play("laugh1.aud");
|
||||
unit.QueueActivity(new Move.Move(insertionLZ.Location - new CVec(1, 0)));
|
||||
});
|
||||
unit.QueueActivity(new Move.Move(insertionLZ.Location - new CVec(1, 0)));
|
||||
}).Second;
|
||||
}
|
||||
|
||||
void SetAlliedUnitsToDefensiveStance()
|
||||
@@ -295,7 +299,7 @@ namespace OpenRA.Mods.RA.Missions
|
||||
{
|
||||
Media.PlayFMVFullscreen(w, "landing.vqa", () =>
|
||||
{
|
||||
FlyTanyaToInsertionLZ();
|
||||
InsertTanyaAtLZ();
|
||||
SendPatrol();
|
||||
PlayMusic();
|
||||
});
|
||||
|
||||
@@ -268,10 +268,7 @@ namespace OpenRA.Mods.RA.Missions
|
||||
|
||||
Actor ClosestAlliedBuilding(Actor actor, int range)
|
||||
{
|
||||
return world.BuildingsNearLocation(actor.CenterLocation, range)
|
||||
.Where(a => a.Owner == allies2)
|
||||
.OrderBy(a => (actor.Location - a.Location).LengthSquared)
|
||||
.FirstOrDefault();
|
||||
return MissionUtils.ClosestPlayerBuilding(world, allies2, actor.CenterLocation, range);
|
||||
}
|
||||
|
||||
void InitializeSovietFactories()
|
||||
@@ -466,81 +463,4 @@ namespace OpenRA.Mods.RA.Missions
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class CountdownTimer
|
||||
{
|
||||
public int TicksLeft { get; set; }
|
||||
|
||||
public Action<CountdownTimer> OnExpired { get; set; }
|
||||
public Action<CountdownTimer> OnOneMinuteRemaining { get; set; }
|
||||
public Action<CountdownTimer> OnTwoMinutesRemaining { get; set; }
|
||||
public Action<CountdownTimer> OnThreeMinutesRemaining { get; set; }
|
||||
public Action<CountdownTimer> OnFourMinutesRemaining { get; set; }
|
||||
public Action<CountdownTimer> OnFiveMinutesRemaining { get; set; }
|
||||
public Action<CountdownTimer> OnTenMinutesRemaining { get; set; }
|
||||
public Action<CountdownTimer> OnTwentyMinutesRemaining { get; set; }
|
||||
public Action<CountdownTimer> OnThirtyMinutesRemaining { get; set; }
|
||||
public Action<CountdownTimer> OnFortyMinutesRemaining { get; set; }
|
||||
|
||||
public CountdownTimer(int ticksLeft, Action<CountdownTimer> onExpired)
|
||||
{
|
||||
TicksLeft = ticksLeft;
|
||||
OnExpired = onExpired;
|
||||
OnOneMinuteRemaining = t => Sound.Play("1minr.aud");
|
||||
OnTwoMinutesRemaining = t => Sound.Play("2minr.aud");
|
||||
OnThreeMinutesRemaining = t => Sound.Play("3minr.aud");
|
||||
OnFourMinutesRemaining = t => Sound.Play("4minr.aud");
|
||||
OnFiveMinutesRemaining = t => Sound.Play("5minr.aud");
|
||||
OnTenMinutesRemaining = t => Sound.Play("10minr.aud");
|
||||
OnTwentyMinutesRemaining = t => Sound.Play("20minr.aud");
|
||||
OnThirtyMinutesRemaining = t => Sound.Play("30minr.aud");
|
||||
OnFortyMinutesRemaining = t => Sound.Play("40minr.aud");
|
||||
}
|
||||
|
||||
public void Tick()
|
||||
{
|
||||
if (TicksLeft > 0)
|
||||
{
|
||||
TicksLeft--;
|
||||
switch (TicksLeft)
|
||||
{
|
||||
case 1500 * 00: OnExpired(this); break;
|
||||
case 1500 * 01: OnOneMinuteRemaining(this); break;
|
||||
case 1500 * 02: OnTwoMinutesRemaining(this); break;
|
||||
case 1500 * 03: OnThreeMinutesRemaining(this); break;
|
||||
case 1500 * 04: OnFourMinutesRemaining(this); break;
|
||||
case 1500 * 05: OnFiveMinutesRemaining(this); break;
|
||||
case 1500 * 10: OnTenMinutesRemaining(this); break;
|
||||
case 1500 * 20: OnTwentyMinutesRemaining(this); break;
|
||||
case 1500 * 30: OnThirtyMinutesRemaining(this); break;
|
||||
case 1500 * 40: OnFortyMinutesRemaining(this); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class CountdownTimerWidget : Widget
|
||||
{
|
||||
public CountdownTimer CountdownTimer { get; set; }
|
||||
public string Header { get; set; }
|
||||
public float2 Position { get; set; }
|
||||
|
||||
public CountdownTimerWidget(CountdownTimer countdownTimer, string header, float2 position)
|
||||
{
|
||||
CountdownTimer = countdownTimer;
|
||||
Header = header;
|
||||
Position = position;
|
||||
}
|
||||
|
||||
public override void Draw()
|
||||
{
|
||||
if (!IsVisible())
|
||||
{
|
||||
return;
|
||||
}
|
||||
var font = Game.Renderer.Fonts["Bold"];
|
||||
var text = "{0}: {1}".F(Header, WidgetUtils.FormatTime(CountdownTimer.TicksLeft));
|
||||
font.DrawTextWithContrast(text, Position, CountdownTimer.TicksLeft == 0 && Game.LocalTick % 60 >= 30 ? Color.Red : Color.White, Color.Black, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
93
OpenRA.Mods.RA/Missions/CountdownTimer.cs
Normal file
93
OpenRA.Mods.RA/Missions/CountdownTimer.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
#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.Drawing;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.RA.Missions
|
||||
{
|
||||
public class CountdownTimer
|
||||
{
|
||||
public int TicksLeft { get; set; }
|
||||
|
||||
public Action<CountdownTimer> OnExpired { get; set; }
|
||||
public Action<CountdownTimer> OnOneMinuteRemaining { get; set; }
|
||||
public Action<CountdownTimer> OnTwoMinutesRemaining { get; set; }
|
||||
public Action<CountdownTimer> OnThreeMinutesRemaining { get; set; }
|
||||
public Action<CountdownTimer> OnFourMinutesRemaining { get; set; }
|
||||
public Action<CountdownTimer> OnFiveMinutesRemaining { get; set; }
|
||||
public Action<CountdownTimer> OnTenMinutesRemaining { get; set; }
|
||||
public Action<CountdownTimer> OnTwentyMinutesRemaining { get; set; }
|
||||
public Action<CountdownTimer> OnThirtyMinutesRemaining { get; set; }
|
||||
public Action<CountdownTimer> OnFortyMinutesRemaining { get; set; }
|
||||
|
||||
public CountdownTimer(int ticksLeft, Action<CountdownTimer> onExpired)
|
||||
{
|
||||
TicksLeft = ticksLeft;
|
||||
OnExpired = onExpired;
|
||||
OnOneMinuteRemaining = t => Sound.Play("1minr.aud");
|
||||
OnTwoMinutesRemaining = t => Sound.Play("2minr.aud");
|
||||
OnThreeMinutesRemaining = t => Sound.Play("3minr.aud");
|
||||
OnFourMinutesRemaining = t => Sound.Play("4minr.aud");
|
||||
OnFiveMinutesRemaining = t => Sound.Play("5minr.aud");
|
||||
OnTenMinutesRemaining = t => Sound.Play("10minr.aud");
|
||||
OnTwentyMinutesRemaining = t => Sound.Play("20minr.aud");
|
||||
OnThirtyMinutesRemaining = t => Sound.Play("30minr.aud");
|
||||
OnFortyMinutesRemaining = t => Sound.Play("40minr.aud");
|
||||
}
|
||||
|
||||
public void Tick()
|
||||
{
|
||||
if (TicksLeft > 0)
|
||||
{
|
||||
TicksLeft--;
|
||||
switch (TicksLeft)
|
||||
{
|
||||
case 1500 * 00: OnExpired(this); break;
|
||||
case 1500 * 01: OnOneMinuteRemaining(this); break;
|
||||
case 1500 * 02: OnTwoMinutesRemaining(this); break;
|
||||
case 1500 * 03: OnThreeMinutesRemaining(this); break;
|
||||
case 1500 * 04: OnFourMinutesRemaining(this); break;
|
||||
case 1500 * 05: OnFiveMinutesRemaining(this); break;
|
||||
case 1500 * 10: OnTenMinutesRemaining(this); break;
|
||||
case 1500 * 20: OnTwentyMinutesRemaining(this); break;
|
||||
case 1500 * 30: OnThirtyMinutesRemaining(this); break;
|
||||
case 1500 * 40: OnFortyMinutesRemaining(this); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class CountdownTimerWidget : Widget
|
||||
{
|
||||
public CountdownTimer CountdownTimer { get; set; }
|
||||
public string Header { get; set; }
|
||||
public float2 Position { get; set; }
|
||||
|
||||
public CountdownTimerWidget(CountdownTimer countdownTimer, string header, float2 position)
|
||||
{
|
||||
CountdownTimer = countdownTimer;
|
||||
Header = header;
|
||||
Position = position;
|
||||
}
|
||||
|
||||
public override void Draw()
|
||||
{
|
||||
if (!IsVisible())
|
||||
{
|
||||
return;
|
||||
}
|
||||
var font = Game.Renderer.Fonts["Bold"];
|
||||
var text = "{0}: {1}".F(Header, WidgetUtils.FormatTime(CountdownTimer.TicksLeft));
|
||||
font.DrawTextWithContrast(text, Position, CountdownTimer.TicksLeft == 0 && Game.LocalTick % 60 >= 30 ? Color.Red : Color.White, Color.Black, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,7 @@ namespace OpenRA.Mods.RA.Missions
|
||||
return chinook;
|
||||
}
|
||||
|
||||
public static Actor InsertUnitWithChinook(World world, Player owner, string unitName, CPos entry, CPos lz, CPos exit, Action<Actor> afterUnload)
|
||||
public static Pair<Actor, 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) });
|
||||
@@ -63,7 +63,21 @@ namespace OpenRA.Mods.RA.Missions
|
||||
chinook.QueueActivity(new Wait(150));
|
||||
chinook.QueueActivity(new HeliFly(Util.CenterOfCell(exit)));
|
||||
chinook.QueueActivity(new RemoveSelf());
|
||||
return unit;
|
||||
return Pair.New(chinook, unit);
|
||||
}
|
||||
|
||||
public static bool AreaSecuredByPlayer(World world, Player player, PPos location, int range)
|
||||
{
|
||||
var units = ForcesNearLocation(world, location, range);
|
||||
return units.Any() && units.All(a => a.Owner == player);
|
||||
}
|
||||
|
||||
public static Actor ClosestPlayerBuilding(World world, Player player, PPos location, int range)
|
||||
{
|
||||
return world.BuildingsNearLocation(location, range)
|
||||
.Where(a => a.Owner == player)
|
||||
.OrderBy(a => (location - a.CenterLocation).LengthSquared)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,6 +240,7 @@
|
||||
<Compile Include="Minelayer.cs" />
|
||||
<Compile Include="Missions\Allies01Script.cs" />
|
||||
<Compile Include="Missions\Allies02Script.cs" />
|
||||
<Compile Include="Missions\CountdownTimer.cs" />
|
||||
<Compile Include="Missions\DefaultShellmapScript.cs" />
|
||||
<Compile Include="Missions\MissionUtils.cs" />
|
||||
<Compile Include="Modifiers\FrozenUnderFog.cs" />
|
||||
|
||||
Reference in New Issue
Block a user