From 500c24fbaf942159c0adb7a37d1828f34a4c6267 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Fri, 10 May 2013 01:16:38 +1200 Subject: [PATCH] Players and bots surrender on disconnect. --- OpenRA.Mods.RA/ConquestVictoryConditions.cs | 27 ++++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/OpenRA.Mods.RA/ConquestVictoryConditions.cs b/OpenRA.Mods.RA/ConquestVictoryConditions.cs index f37020a031..d183cb051b 100644 --- a/OpenRA.Mods.RA/ConquestVictoryConditions.cs +++ b/OpenRA.Mods.RA/ConquestVictoryConditions.cs @@ -10,6 +10,7 @@ using System.Linq; using OpenRA.FileFormats; +using OpenRA.Network; using OpenRA.Traits; namespace OpenRA.Mods.RA @@ -31,12 +32,29 @@ namespace OpenRA.Mods.RA Info = info; } + Session.Client HumanClient(Player p) + { + var client = p.World.LobbyInfo.ClientWithIndex(p.ClientIndex); + if (client != null && client.Bot != null) + return p.World.LobbyInfo.ClientWithIndex(client.BotControllerClientIndex); + return client; + } + public void Tick(Actor self) { - if (self.Owner.WinState != WinState.Undefined || self.Owner.NonCombatant) return; + if (self.Owner.NonCombatant) + return; + + // Surrender when the controlling player disconnects + var client = HumanClient(self.Owner); + if (client != null && client.State == Session.ClientState.Disconnected) + Lose(self); + + if (self.Owner.WinState != WinState.Undefined) + return; var hasAnything = self.World.ActorsWithTrait() - .Any( a => a.Actor.Owner == self.Owner ); + .Any(a => a.Actor.Owner == self.Owner); if (!hasAnything && !self.Owner.NonCombatant) Lose(self); @@ -44,9 +62,10 @@ namespace OpenRA.Mods.RA var others = self.World.Players.Where( p => !p.NonCombatant && p != self.Owner && p.Stances[self.Owner] != Stance.Ally ); - if (others.Count() == 0) return; + if (others.Count() == 0) + return; - if(others.All(p => p.WinState == WinState.Lost)) + if (others.All(p => p.WinState == WinState.Lost)) Win(self); }