コード例 #1
0
        private bool InitMirrorMultiplayerGame()
        {
#if RTSENGINE_MIRROR
            NetworkManager_Mirror = (NetworkLobbyManager_Mirror)NetworkLobbyManager_Mirror.singleton;

            if (NetworkManager_Mirror == null) //if there's mirror network lobby manager component in the scene then this is not a multiplayer game
            {
                return(false);
            }

            //randomize the faction slots in this map before starting the assignment of each faction slot
            RandomizeFactionSlots(NetworkManager_Mirror.FactionSlotIndexes);

            MultiplayerGame = true;                                                                     //this is now a multiplayer game.
            List <NetworkLobbyFaction_Mirror> lobbyfactions = NetworkLobbyManager_Mirror.LobbyFactions; //get all lobby faction components into a list

            if (lobbyfactions.Count > factions.Count)                                                   //if there aren't enough slots in this map for all factions.
            {
                Debug.LogError("[Game Manager]: Not enough slots available for all the factions coming from the multiplayer menu.");
                return(false);
            }

            //set the defeat condition & speed modifier:
            defeatCondition = NetworkManager_Mirror.UIMgr.defeatConditionMenu.GetValue();
            speedModifier   = NetworkManager_Mirror.UIMgr.speedModifierMenu.GetValue();

            //we have enough slots:
            for (int i = 0; i < lobbyfactions.Count; i++) //Loop through all the slots and set up the factions.
            {
                int index = lobbyfactions[i].index;       //get the faction ID.
                factions[index].Init(
                    lobbyfactions[i].GetFactionName(),
                    NetworkManager_Mirror.GetFactionTypeInfo(lobbyfactions[i].GetFactionTypeID()),
                    NetworkManager_Mirror.FactionColor.Get(lobbyfactions[i].GetFactionColorID()),
                    lobbyfactions[i].isLocalPlayer,
                    NetworkManager_Mirror.GetMapInitialPopulation(),
                    null,
                    gameObject.AddComponent <FactionManager>(), i, this);

                if (lobbyfactions[i].IsHost) //does this lobby faction belong to the host?
                {
                    HostFactionID = i;       //mark it.
                }
                factions[index].InitMultiplayer(lobbyfactions[i]);
            }

            //if there are more slots than required, remove them
            while (lobbyfactions.Count < factions.Count)
            {
                factions[factions.Count - 1].InitDestroy();
                factions.RemoveAt(factions.Count - 1);
            }
#endif
            return(true);
        }
コード例 #2
0
        //a method that initializes a single player game:
        private bool InitSinglePlayerGame()
        {
            //if there's no single player manager then
            if (LobbyManager.instance == null)
            {
                return(false); //do not proceed.
            }
            //If there's a map manager script in the scene, it means that we just came from the single player menu, so we need to set the NPC players settings!

            //randomzie the faction slots
            List <int> factionSlots = RTSHelper.GenerateIndexList(factions.Count);

            RTSHelper.ShuffleList <int>(factionSlots); //randomize the faction slots indexes list IDs by shuffling it.
            RandomizeFactionSlots(factionSlots.ToArray());

            //This where we will set the NPC settings using the info from the single player manager:
            //First check if we have enough faction slots available:
            if (LobbyManager.instance.LobbyFactions.Count <= factions.Count)
            {
                defeatCondition = LobbyManager.instance.UIMgr.defeatConditionMenu.GetValue(); //set defeat condition
                speedModifier   = LobbyManager.instance.UIMgr.speedModifierMenu.GetValue();   //set speed modifier

                //loop through the factions slots of this map:
                for (int i = 0; i < LobbyManager.instance.LobbyFactions.Count; i++)
                {
                    factions[i].Init(
                        LobbyManager.instance.LobbyFactions[i].GetFactionName(),
                        LobbyManager.instance.LobbyFactions[i].GetFactionType(),
                        LobbyManager.instance.LobbyFactions[i].GetFactionColor(),
                        LobbyManager.instance.LobbyFactions[i].PlayerControlled,
                        LobbyManager.instance.GetCurrentMap().GetInitialPopulation(),
                        LobbyManager.instance.LobbyFactions[i].GetNPCType(),
                        gameObject.AddComponent <FactionManager>(), i, this);
                }

                //if there are more slots than required.
                while (LobbyManager.instance.LobbyFactions.Count < factions.Count)
                {
                    //remove the extra slots:
                    factions[factions.Count - 1].InitDestroy();
                    factions.RemoveAt(factions.Count - 1);
                }

                //Destroy the map manager script because we don't really need it anymore:
                DestroyImmediate(LobbyManager.instance.gameObject);

                return(true);
            }
            else
            {
                Debug.LogError("[Game Manager]: Not enough slots available for all the factions coming from the single player menu.");
                return(false);
            }
        }
コード例 #3
0
 public Scenario Clone()
 {
     return(new Scenario
     {
         Name = Name,
         City = City.Clone(),
         StartDateString = StartDate.ToString(),
         EndDateString = EndDate.ToString(),
         VictoryConditions = VictoryConditions.Select(g => g.Clone()).ToList(),
         DefeatConditions = DefeatConditions.Select(g => g.Clone()).ToList(),
         RequireAchievementNames = RequireAchievementNames.ToList(),
         VictoryAchievement = VictoryAchievement
     });
 }
コード例 #4
0
 public BasicMapParams(byte players_value,
                       byte width_size,
                       byte height_size,
                       string scenario_name,
                       VictoryConditions victory_conditions,
                       DefeatConditions defeat_conditions)
 {
     this.players_value      = players_value;
     this.width_size         = width_size;
     this.height_size        = height_size;
     this.scenario_name      = scenario_name;
     this.victory_conditions = victory_conditions;
     this.defeat_conditions  = defeat_conditions;
 }
コード例 #5
0
        public void CheckGoals(City city)
        {
            // TODO priority:bug this whole method doesn't seems to work
            if (VictoryConditions.All(g => g.IsMet(city)))
            {
                OnVictory();
            }

            if (DefeatConditions.Any(g => g.IsMet(city)))
            {
                OnDefeat();
            }

            foreach (var achievement in PrototypeManager.Instance.Achievements)
            {
                if (achievement.IsGoalRelated)
                {
                    if (achievement.Goals.All(g => g.IsMet(city)))
                    {
                        OnAchievement(achievement);
                    }
                }
            }
        }