Ensure that all combatants have a defined WinState at the end of the game
This commit is contained in:
@@ -136,12 +136,8 @@ namespace OpenRA.Mods.RA
|
||||
void CheckIfGameIsOver(Player player)
|
||||
{
|
||||
var players = player.World.Players.Where(p => !p.NonCombatant);
|
||||
var allies = players.Where(p => p.IsAlliedWith(player));
|
||||
|
||||
var gameOver = ((info.EarlyGameOver && !info.Cooperative && player.WinState != WinState.Undefined) ||
|
||||
(info.EarlyGameOver && info.Cooperative && allies.All(p => p.WinState != WinState.Undefined)) ||
|
||||
players.All(p => p.WinState != WinState.Undefined));
|
||||
|
||||
var gameOver = players.All(p => p.WinState != WinState.Undefined);
|
||||
if (gameOver)
|
||||
{
|
||||
Game.RunAfterDelay(info.GameOverDelay, () =>
|
||||
@@ -155,48 +151,82 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
public void OnPlayerWon(Player player)
|
||||
{
|
||||
var players = player.World.Players.Where(p => !p.NonCombatant);
|
||||
var enemies = players.Where(p => !p.IsAlliedWith(player));
|
||||
|
||||
if (info.Cooperative)
|
||||
{
|
||||
WinStateCooperative = WinState.Won;
|
||||
var players = player.World.Players.Where(p => !p.NonCombatant);
|
||||
var allies = players.Where(p => p.IsAlliedWith(player));
|
||||
|
||||
if (allies.All(p => p.PlayerActor.Trait<MissionObjectives>().WinStateCooperative == WinState.Won))
|
||||
{
|
||||
foreach (var p in allies)
|
||||
{
|
||||
p.WinState = WinState.Won;
|
||||
p.World.OnPlayerWinStateChanged(p);
|
||||
}
|
||||
|
||||
if (info.EarlyGameOver)
|
||||
foreach (var p in enemies)
|
||||
p.PlayerActor.Trait<MissionObjectives>().ForceDefeat(p);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
player.WinState = WinState.Won;
|
||||
player.World.OnPlayerWinStateChanged(player);
|
||||
|
||||
if (info.EarlyGameOver)
|
||||
foreach (var p in enemies)
|
||||
p.PlayerActor.Trait<MissionObjectives>().ForceDefeat(p);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPlayerLost(Player player)
|
||||
{
|
||||
var players = player.World.Players.Where(p => !p.NonCombatant);
|
||||
var enemies = players.Where(p => !p.IsAlliedWith(player));
|
||||
|
||||
if (info.Cooperative)
|
||||
{
|
||||
WinStateCooperative = WinState.Lost;
|
||||
var players = player.World.Players.Where(p => !p.NonCombatant);
|
||||
var allies = players.Where(p => p.IsAlliedWith(player));
|
||||
|
||||
if (allies.Any(p => p.PlayerActor.Trait<MissionObjectives>().WinStateCooperative == WinState.Lost))
|
||||
{
|
||||
foreach (var p in allies)
|
||||
{
|
||||
p.WinState = WinState.Lost;
|
||||
p.World.OnPlayerWinStateChanged(p);
|
||||
}
|
||||
|
||||
if (info.EarlyGameOver)
|
||||
foreach (var p in enemies)
|
||||
p.PlayerActor.Trait<MissionObjectives>().ForceDefeat(p);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
player.WinState = WinState.Lost;
|
||||
player.World.OnPlayerWinStateChanged(player);
|
||||
|
||||
if (info.EarlyGameOver)
|
||||
foreach (var p in enemies)
|
||||
{
|
||||
p.WinState = WinState.Won;
|
||||
p.World.OnPlayerWinStateChanged(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ForceDefeat(Player player)
|
||||
{
|
||||
for (var id = 0; id < Objectives.Count; id++)
|
||||
if (Objectives[id].State == ObjectiveState.Incomplete)
|
||||
MarkFailed(player, id);
|
||||
}
|
||||
|
||||
public event Action<Player> ObjectiveAdded = player => { };
|
||||
|
||||
public void OnObjectiveAdded(Player player, int id) {}
|
||||
@@ -206,8 +236,7 @@ namespace OpenRA.Mods.RA
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
if (order.OrderString == "Surrender")
|
||||
for (var id = 0; id < objectives.Count; id++)
|
||||
MarkFailed(self.Owner, id);
|
||||
ForceDefeat(self.Owner);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user