Campaign: reduce failed/accomplished code duplication
This commit is contained in:
@@ -78,30 +78,14 @@ namespace OpenRA.Mods.RA.Missions
|
||||
|
||||
string difficulty;
|
||||
|
||||
void MissionFailed(string text)
|
||||
{
|
||||
if (allies.WinState != WinState.Undefined)
|
||||
{
|
||||
return;
|
||||
}
|
||||
allies.WinState = WinState.Lost;
|
||||
foreach (var actor in world.Actors.Where(a => a.IsInWorld && a.Owner == allies && !a.IsDead()))
|
||||
{
|
||||
actor.Kill(actor);
|
||||
}
|
||||
Game.AddChatLine(Color.Red, "Mission failed", text);
|
||||
Sound.Play("misnlst1.aud");
|
||||
}
|
||||
|
||||
void MissionAccomplished(string text)
|
||||
{
|
||||
if (allies.WinState != WinState.Undefined)
|
||||
{
|
||||
return;
|
||||
}
|
||||
allies.WinState = WinState.Won;
|
||||
Game.AddChatLine(Color.Blue, "Mission accomplished", text);
|
||||
Sound.Play("misnwon1.aud");
|
||||
MissionUtils.CoopMissionAccomplished(world, text, allies);
|
||||
}
|
||||
|
||||
void MissionFailed(string text)
|
||||
{
|
||||
MissionUtils.CoopMissionFailed(world, text, allies);
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
@@ -171,7 +155,7 @@ namespace OpenRA.Mods.RA.Missions
|
||||
{
|
||||
objectives[ExtractEinsteinID].Status = ObjectiveStatus.Completed;
|
||||
OnObjectivesUpdated(true);
|
||||
MissionAccomplished("Einstein was rescued.");
|
||||
MissionAccomplished("Einstein was rescued");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,36 +142,16 @@ namespace OpenRA.Mods.RA.Missions
|
||||
|
||||
void MissionFailed(string text)
|
||||
{
|
||||
if (allies1.WinState != WinState.Undefined)
|
||||
{
|
||||
return;
|
||||
}
|
||||
allies1.WinState = allies2.WinState = WinState.Lost;
|
||||
MissionUtils.CoopMissionFailed(world, text, allies1, allies2);
|
||||
if (reinforcementsTimer != null)
|
||||
{
|
||||
reinforcementsTimerWidget.Visible = false;
|
||||
}
|
||||
foreach (var actor in world.Actors.Where(a => a.IsInWorld && (a.Owner == allies1 || a.Owner == allies2) && !a.IsDead()))
|
||||
{
|
||||
actor.Kill(actor);
|
||||
}
|
||||
Game.AddChatLine(Color.Red, "Mission failed", text);
|
||||
Sound.Play("misnlst1.aud");
|
||||
}
|
||||
|
||||
void MissionAccomplished(string text)
|
||||
{
|
||||
if (allies1.WinState != WinState.Undefined)
|
||||
{
|
||||
return;
|
||||
}
|
||||
allies1.WinState = allies2.WinState = WinState.Won;
|
||||
if (reinforcementsTimer != null)
|
||||
{
|
||||
reinforcementsTimerWidget.Visible = false;
|
||||
}
|
||||
Game.AddChatLine(Color.Blue, "Mission accomplished", text);
|
||||
Sound.Play("misnwon1.aud");
|
||||
MissionUtils.CoopMissionAccomplished(world, text, allies1, allies2);
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
|
||||
@@ -122,28 +122,12 @@ namespace OpenRA.Mods.RA.Missions
|
||||
|
||||
void MissionFailed(string text)
|
||||
{
|
||||
if (allies1.WinState != WinState.Undefined)
|
||||
{
|
||||
return;
|
||||
}
|
||||
allies1.WinState = allies2.WinState = WinState.Lost;
|
||||
foreach (var actor in world.Actors.Where(a => a.IsInWorld && (a.Owner == allies1 || a.Owner == allies2) && !a.IsDead()))
|
||||
{
|
||||
actor.Kill(actor);
|
||||
}
|
||||
Game.AddChatLine(Color.Red, "Mission failed", text);
|
||||
Sound.Play("misnlst1.aud");
|
||||
MissionUtils.CoopMissionFailed(world, text, allies1, allies2);
|
||||
}
|
||||
|
||||
void MissionAccomplished(string text)
|
||||
{
|
||||
if (allies1.WinState != WinState.Undefined)
|
||||
{
|
||||
return;
|
||||
}
|
||||
allies1.WinState = allies2.WinState = WinState.Won;
|
||||
Game.AddChatLine(Color.Blue, "Mission accomplished", text);
|
||||
Sound.Play("misnwon1.aud");
|
||||
MissionUtils.CoopMissionAccomplished(world, text, allies1, allies2);
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
|
||||
@@ -94,28 +94,12 @@ namespace OpenRA.Mods.RA.Missions
|
||||
|
||||
void MissionFailed(string text)
|
||||
{
|
||||
if (allies1.WinState != WinState.Undefined)
|
||||
{
|
||||
return;
|
||||
}
|
||||
allies1.WinState = allies2.WinState = WinState.Lost;
|
||||
foreach (var actor in world.Actors.Where(a => a.IsInWorld && (a.Owner == allies1 || a.Owner == allies2) && !a.IsDead()))
|
||||
{
|
||||
actor.Kill(actor);
|
||||
}
|
||||
Game.AddChatLine(Color.Red, "Mission failed", text);
|
||||
Sound.Play("misnlst1.aud");
|
||||
MissionUtils.CoopMissionFailed(world, text, allies1, allies2);
|
||||
}
|
||||
|
||||
void MissionAccomplished(string text)
|
||||
{
|
||||
if (allies1.WinState != WinState.Undefined)
|
||||
{
|
||||
return;
|
||||
}
|
||||
allies1.WinState = allies2.WinState = WinState.Won;
|
||||
Game.AddChatLine(Color.Blue, "Mission accomplished", text);
|
||||
Sound.Play("misnwon1.aud");
|
||||
MissionUtils.CoopMissionAccomplished(world, text, allies1, allies2);
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
@@ -169,5 +170,39 @@ namespace OpenRA.Mods.RA.Missions
|
||||
Game.ConnectionStateChanged -= StopMusic;
|
||||
}
|
||||
}
|
||||
|
||||
public static void CoopMissionAccomplished(World world, string text, params Player[] players)
|
||||
{
|
||||
if (players.First().WinState != WinState.Undefined)
|
||||
return;
|
||||
|
||||
foreach (var player in players)
|
||||
player.WinState = WinState.Won;
|
||||
|
||||
if (text != null)
|
||||
Game.AddChatLine(Color.Blue, "Mission accomplished", text);
|
||||
|
||||
Sound.Play("misnwon1.aud");
|
||||
}
|
||||
|
||||
public static void CoopMissionFailed(World world, string text, params Player[] players)
|
||||
{
|
||||
if (players.First().WinState != WinState.Undefined)
|
||||
return;
|
||||
|
||||
foreach (var player in players)
|
||||
{
|
||||
player.WinState = WinState.Lost;
|
||||
foreach (var actor in world.Actors.Where(a => a.IsInWorld && a.Owner == player && !a.IsDead()))
|
||||
{
|
||||
actor.Kill(actor);
|
||||
}
|
||||
}
|
||||
|
||||
if (text != null)
|
||||
Game.AddChatLine(Color.Red, "Mission failed", text);
|
||||
|
||||
Sound.Play("misnlst1.aud");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,28 +62,14 @@ namespace OpenRA.Mods.RA.Missions
|
||||
const string BadgerName = "badr";
|
||||
static readonly string[] Reinforcements = { "e1", "e1", "e1", "e2", "e2" };
|
||||
|
||||
void MissionFailed()
|
||||
void MissionAccomplished(string text)
|
||||
{
|
||||
if (ussr.WinState != WinState.Undefined)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ussr.WinState = WinState.Lost;
|
||||
foreach (var actor in world.Actors.Where(a => a.IsInWorld && a.Owner == ussr && !a.IsDead()))
|
||||
{
|
||||
actor.Kill(actor);
|
||||
}
|
||||
Sound.Play("misnlst1.aud");
|
||||
MissionUtils.CoopMissionAccomplished(world, text, ussr);
|
||||
}
|
||||
|
||||
void MissionAccomplished()
|
||||
void MissionFailed(string text)
|
||||
{
|
||||
if (ussr.WinState != WinState.Undefined)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ussr.WinState = WinState.Won;
|
||||
Sound.Play("misnwon1.aud");
|
||||
MissionUtils.CoopMissionFailed(world, text, ussr);
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
@@ -92,12 +78,12 @@ namespace OpenRA.Mods.RA.Missions
|
||||
if (!unitsAndBuildings.Any(a => a.Owner == france))
|
||||
{
|
||||
objectives[DestroyID].Status = ObjectiveStatus.Completed;
|
||||
MissionAccomplished();
|
||||
MissionAccomplished("We destroyed the resistance.");
|
||||
}
|
||||
else if (!unitsAndBuildings.Any(a => a.Owner == ussr))
|
||||
{
|
||||
objectives[DestroyID].Status = ObjectiveStatus.Failed;
|
||||
MissionFailed();
|
||||
MissionFailed("We were destroyed by the resistance.");
|
||||
}
|
||||
if (!startJeepParadropped && startJeep.IsDead())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user