//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); } }
//called by the server when the game is about to start: public void OnStartGame() { if (isLocalPlayer == false || manager.IsHost == false) //the host must be the only one able to start the game { return; } List <int> factionSlots = RTSHelper.GenerateIndexList(manager.maxConnections); RTSHelper.ShuffleList <int>(factionSlots); //randomize the faction slots list IDs by shuffling it RpcOnGameStart(factionSlots.ToArray()); //let all clients know that the game is starting }