From 8e2d422054cd968c2f8602a431abe318eab67911 Mon Sep 17 00:00:00 2001 From: alzeih Date: Wed, 21 Jul 2010 20:20:12 +1200 Subject: [PATCH] Improvements to VictoryConditions, and Dead = Chat to all --- OpenRA.Game/Network/UnitOrders.cs | 14 +++++++-- OpenRA.Game/Player.cs | 6 ++-- OpenRA.Game/Traits/TraitsInterfaces.cs | 2 +- OpenRA.Game/Widgets/ChatDisplayWidget.cs | 2 +- .../Widgets/Delegates/IngameChromeDelegate.cs | 20 +++--------- OpenRA.Mods.RA/ConquestVictoryConditions.cs | 31 +++++++++++++------ 6 files changed, 43 insertions(+), 32 deletions(-) diff --git a/OpenRA.Game/Network/UnitOrders.cs b/OpenRA.Game/Network/UnitOrders.cs index 12bfe96d6e..80c89e9363 100755 --- a/OpenRA.Game/Network/UnitOrders.cs +++ b/OpenRA.Game/Network/UnitOrders.cs @@ -24,8 +24,13 @@ namespace OpenRA.Network { var client = Game.LobbyInfo.Clients.FirstOrDefault(c => c.Index == clientId); if (client != null) - Game.AddChatLine(client.Color1, - client.Name, order.TargetString); + { + var player = Game.world.players.Values.FirstOrDefault(p => p.Index == client.Index); + if (player.WinState == WinState.Lost) + Game.AddChatLine(client.Color1, client.Name + " (Dead)", order.TargetString); + else + Game.AddChatLine(client.Color1, client.Name, order.TargetString); + } break; } case "TeamChat": @@ -34,12 +39,15 @@ namespace OpenRA.Network if (client != null) { var player = Game.world.players.Values.FirstOrDefault(p => p.Index == client.Index); + var isAlly = (world.GameHasStarted) ? player != null && Game.world.LocalPlayer != null && player.Stances[Game.world.LocalPlayer] == Stance.Ally : client == Game.LocalClient || (client.Team == Game.LocalClient.Team && client.Team != 0); - if (isAlly) + if (isAlly && player.WinState != WinState.Lost) Game.AddChatLine(client.Color1, client.Name + " (Team)", order.TargetString); + else if (player.WinState == WinState.Lost) + Game.AddChatLine(client.Color1, client.Name + " (Dead)", order.TargetString); } break; } diff --git a/OpenRA.Game/Player.cs b/OpenRA.Game/Player.cs index 920886e0e0..1475f02ba1 100644 --- a/OpenRA.Game/Player.cs +++ b/OpenRA.Game/Player.cs @@ -17,12 +17,14 @@ using OpenRA.Traits; namespace OpenRA { public enum PowerState { Normal, Low, Critical }; - + public enum WinState { Won, Lost, Undefined }; + public class Player { public Actor PlayerActor; public int Kills; - public int Deaths; + public int Deaths; + public WinState WinState = WinState.Undefined; public readonly string Palette; public readonly Color Color; diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 19770642b4..5cfb502207 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -154,6 +154,6 @@ namespace OpenRA.Traits public interface IRenderOverlay { void Render(); } public interface INotifyIdle { void Idle(Actor self); } - public interface IVictoryConditions { bool HasLost { get; } bool HasWon { get; } } + public interface IVictoryConditions { } public interface IBlocksBullets { } } diff --git a/OpenRA.Game/Widgets/ChatDisplayWidget.cs b/OpenRA.Game/Widgets/ChatDisplayWidget.cs index 8fc074b283..6a0a7d889c 100644 --- a/OpenRA.Game/Widgets/ChatDisplayWidget.cs +++ b/OpenRA.Game/Widgets/ChatDisplayWidget.cs @@ -16,7 +16,7 @@ namespace OpenRA.Widgets { class ChatDisplayWidget : Widget { - const int logLength = 10; + const int logLength = 9; public string Notification = ""; public bool DrawBackground = true; diff --git a/OpenRA.Game/Widgets/Delegates/IngameChromeDelegate.cs b/OpenRA.Game/Widgets/Delegates/IngameChromeDelegate.cs index 2751732595..fa83e661fd 100644 --- a/OpenRA.Game/Widgets/Delegates/IngameChromeDelegate.cs +++ b/OpenRA.Game/Widgets/Delegates/IngameChromeDelegate.cs @@ -62,26 +62,14 @@ namespace OpenRA.Widgets.Delegates var postgameText = postgameBG.GetWidget("TEXT"); postgameBG.IsVisible = () => { - var conds = Game.world.Queries.WithTrait() - .Where(c => !c.Actor.Owner.NonCombatant); - - if (Game.world.LocalPlayer != null && conds.Count() > 1) - { - if (conds.Any(c => c.Actor.Owner == Game.world.LocalPlayer && c.Trait.HasLost) - || conds.All(c => AreMutualAllies(c.Actor.Owner, Game.world.LocalPlayer) || c.Trait.HasLost)) - return true; - } - - return false; + return Game.world.LocalPlayer.WinState != WinState.Undefined; }; postgameText.GetText = () => { - var lost = Game.world.Queries.WithTrait() - .Where(c => c.Actor.Owner == Game.world.LocalPlayer) - .Any(c => c.Trait.HasLost); - - return (lost) ? "YOU ARE DEFEATED" : "YOU ARE VICTORIOUS"; + var state = Game.world.LocalPlayer.WinState; + return (state == WinState.Undefined)? "" : + ((state == WinState.Lost)? "YOU ARE DEFEATED" : "YOU ARE VICTORIOUS"); }; } bool AreMutualAllies(Player a, Player b) { return a.Stances[b] == Stance.Ally && b.Stances[a] == Stance.Ally; } diff --git a/OpenRA.Mods.RA/ConquestVictoryConditions.cs b/OpenRA.Mods.RA/ConquestVictoryConditions.cs index 0f2b1d0bf4..60d120a357 100644 --- a/OpenRA.Mods.RA/ConquestVictoryConditions.cs +++ b/OpenRA.Mods.RA/ConquestVictoryConditions.cs @@ -17,20 +17,21 @@ namespace OpenRA.Mods.RA class ConquestVictoryConditions : ITick, IVictoryConditions, IResolveOrder { - public bool HasLost { get; private set; } - public bool HasWon { get; private set; } - public void Tick(Actor self) { + if (self.Owner.WinState != WinState.Undefined || self.Owner.NonCombatant) return; + var hasAnything = self.World.Queries.OwnedBy[self.Owner] .WithTrait().Any(); - var hasLost = !hasAnything && !self.Owner.NonCombatant; - - if (hasLost && !HasLost) + if (!hasAnything && !self.Owner.NonCombatant) Surrender(self); - - HasLost = hasLost; + + var others = self.World.players.Where( p => !p.Value.NonCombatant && p.Value != self.Owner && p.Value.Stances[self.Owner] != Stance.Ally ); + if (others.Count() == 0) return; + + if(others.All(p => p.Value.WinState == WinState.Lost)) + Win(self); } public void ResolveOrder(Actor self, Order order) @@ -41,12 +42,24 @@ namespace OpenRA.Mods.RA void Surrender(Actor self) { + if (self.Owner.WinState == WinState.Lost) return; + self.Owner.WinState = WinState.Lost; + Game.Debug("{0} is defeated.".F(self.Owner.PlayerName)); foreach (var a in self.World.Queries.OwnedBy[self.Owner]) a.InflictDamage(a, a.Health, null); self.Owner.Shroud.Disabled = true; - HasLost = true; + + } + + void Win(Actor self) + { + if (self.Owner.WinState == WinState.Won) return; + self.Owner.WinState = WinState.Won; + + Game.Debug("{0} is victorious.".F(self.Owner.PlayerName)); + self.Owner.Shroud.Disabled = true; } }