From 8392a443149bd04814aa38ec3689d9b6d649c768 Mon Sep 17 00:00:00 2001 From: geckosoft Date: Mon, 1 Nov 2010 03:58:46 +0100 Subject: [PATCH] Added: Support for not-synced traits (ITraitNotSynced) --- OpenRA.Game/Network/SyncReport.cs | 2 ++ OpenRA.Game/Traits/TraitsInterfaces.cs | 2 ++ OpenRA.Game/World.cs | 6 +++- OpenRA.Mods.RA/World/WorldGameOver.cs | 50 ++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 OpenRA.Mods.RA/World/WorldGameOver.cs diff --git a/OpenRA.Game/Network/SyncReport.cs b/OpenRA.Game/Network/SyncReport.cs index 5d5048e38f..860cd174b2 100755 --- a/OpenRA.Game/Network/SyncReport.cs +++ b/OpenRA.Game/Network/SyncReport.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using OpenRA.FileFormats; using OpenRA.Support; +using OpenRA.Traits; namespace OpenRA.Network { @@ -37,6 +38,7 @@ namespace OpenRA.Network report.Traits.Clear(); foreach (var a in orderManager.world.Queries.WithTraitMultiple()) { + if (a.Trait is ITraitNotSynced ) continue; var sync = Sync.CalculateSyncHash(a.Trait); if (sync != 0) report.Traits.Add(new TraitReport() diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index d7440bf5a3..d4403603e3 100755 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -190,6 +190,8 @@ namespace OpenRA.Traits public interface IPostRenderSelection { void RenderAfterWorld(WorldRenderer wr, Actor self); } public interface IPreRenderSelection { void RenderBeforeWorld(WorldRenderer wr, Actor self); } + public interface ITraitNotSynced{} // Traits marked with NotSynced arent sync-checked + public struct Target // a target: either an actor, or a fixed location. { Actor actor; diff --git a/OpenRA.Game/World.cs b/OpenRA.Game/World.cs index 30dc027bf6..68cf59886b 100644 --- a/OpenRA.Game/World.cs +++ b/OpenRA.Game/World.cs @@ -199,7 +199,11 @@ namespace OpenRA // hash all the traits that tick foreach (var x in traitDict.ActorsWithTraitMultiple(this)) - ret += n++ * (int)x.Actor.ActorID * Sync.CalculateSyncHash(x.Trait); + { + if (x.Trait is ITraitNotSynced) continue; + + ret += n++*(int) x.Actor.ActorID*Sync.CalculateSyncHash(x.Trait); + } // Hash the shared rng ret += SharedRandom.Last; diff --git a/OpenRA.Mods.RA/World/WorldGameOver.cs b/OpenRA.Mods.RA/World/WorldGameOver.cs new file mode 100644 index 0000000000..de2b99e30d --- /dev/null +++ b/OpenRA.Mods.RA/World/WorldGameOver.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using OpenRA.Traits; + +namespace OpenRA.Mods.RA +{ + class WorldGameOverInfo : TraitInfo + { + public readonly bool ReturnToLobby = false; + public readonly int Delay = 30; + public readonly string EndMessage = "The game will end in {0} seconds."; + } + + class WorldGameOver : ITick + { + public WorldGameOverInfo Info = null; + int? _delayLeft = null; + + public void Tick(Actor self) + { + if (Info == null) + Info = self.Info.Traits.GetOrDefault(); + + if (Info == null || !Info.ReturnToLobby) + return; + + // See if there is anyone left who hasnt won / lost (if not, means game over) + if (!self.World.players.Any(p => !p.Value.NonCombatant && p.Value.WinState == WinState.Undefined)) + { + if (_delayLeft == null) + { + _delayLeft = Info.Delay * 25; + if (Info.EndMessage.Trim() != "" && Info.EndMessage.Contains("{0}")) + Game.AddChatLine(Color.Green, "", + Info.EndMessage.Trim().F( ((int)(_delayLeft / 25)) + "")); + else if (Info.EndMessage.Trim() != "") + Game.AddChatLine(Color.Green, "",Info.EndMessage.Trim()); + } + + _delayLeft--; + + if (_delayLeft <= 0 ) + Game.RejoinLobby(self.World); + } + } + } +}