Beispiel #1
0
        public RTSWorld()
            : base()
        {
            // Add default, neutral team.
            Team neutral = new Team(0, "Neutral", Color.LightGray);
            this.Teams.Add(neutral);

            #if MULTIPLAYER
            // Get global session information.
            this.m_GlobalSession = new Distributed<GlobalSession>("rts-session");
            this.m_GlobalSession.LogEmitted += (sender, ev) => { this.UiManager.Log(ev.ToString()); };
            this.m_LocalPlayer = this.m_GlobalSession.Join();

            // Hook the game started event.
            if (LocalNode.Singleton.IsServer)
                this.m_GlobalSession.ServerGameStarted += this._HandleServerGameStart;
            else
                this.m_GlobalSession.ClientGameStarted += this._HandleClientGameStart;
            #else
            // Get global session information.
            this.m_GlobalSession = new GlobalSession();
            this.m_GlobalSession.LogEmitted += (sender, ev) => { this.UiManager.Log(ev.ToString()); };
            this.m_LocalPlayer = this.m_GlobalSession.Join();

            // Hook the game started event.
            this.m_GlobalSession.ServerGameStarted += (sender, ev) => { this.HandleServerGameStart(); };
            #endif
        }
Beispiel #2
0
        private void HandleTeamAllocations()
        {
            Stack<Color> colors = new Stack<Color>(new Color[] {
                Color.Blue,
                Color.Red,
                Color.Yellow,
                Color.Green,
                Color.Gray,
                Color.Purple,
                Color.Violet,
                Color.Cyan
            });

            // Assign teams.
            foreach (Player p in this.m_GlobalSession.Players)
            {
                Team t = new Team(p.PlayerID, "Player " + p.PlayerID, colors.Pop());
                this.m_Teams.Add(t);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Force resynchronsiation of data with global session.
        /// </summary>
        public void ForceSynchronisation()
        {
            // Make sure this is a synchronised unit.
            if (this.SynchronisationData == null ||
                this.Team.SynchronisationData == null)
                throw new InvalidOperationException("Unable to synchronise unit that does not have associated synchronisation data.");

            // Find team instance with the specified player ID.
            Team teamInstance = (this.Level.World as RTSWorld).Teams.DefaultIfEmpty(null).First(v => (v.SynchronisationData.PlayerID == this.Team.SynchronisationData.PlayerID));
            if (teamInstance == null)
                throw new ProtogameException("Unable to find team instance with player ID '" + this.Team.SynchronisationData.PlayerID + "'.");
            this.Team = teamInstance;
        }