Example #1
0
        //a method that adds a new faction:
        public void AddFaction()
        {
            //if we haven't reached the maximum allowed amount of factions
            if (Factions.Count < Maps [CurrentMapID].MaxFactions && Factions.Count < MaxFactions)
            {
                //create a new faction
                FactionVars NewFaction = new FactionVars();
                NewFaction.FactionName       = "Faction " + Factions.Count.ToString();
                NewFaction.InitialPopulation = MinPopulation;

                //taking the FactionUISample as base to create all the rest:
                GameObject FactionUIClone = (GameObject)Instantiate(FactionUISample.gameObject, Vector3.zero, Quaternion.identity);
                NewFaction.FactionUI = FactionUIClone.GetComponent <FactionUIInfo> ();
                FactionUIClone.transform.SetParent(FactionUIParent);                 //make sure to set the FactionUI objects to the same parent.
                FactionUIClone.GetComponent <RectTransform> ().localScale = new Vector3(1.0f, 1.0f, 1.0f);

                //set the faction's UI info:
                NewFaction.FactionUI.RemoveFactionButton.gameObject.SetActive(true);                  //activate this button to allow the player to discard this faction
                NewFaction.FactionUI.DifficultyMenu.gameObject.SetActive(true);                       //NPC faction so activate the difficulty menu.
                NewFaction.FactionUI.PopulationInput.text  = NewFaction.InitialPopulation.ToString(); //population
                NewFaction.FactionUI.FactionNameInput.text = NewFaction.FactionName.ToString();       //name
                NewFaction.FactionUI.ColorImg.color        = NewFaction.FactionColor;                 //color
                NewFaction.NPCDifficulty = 0;

                //the faction type:
                NewFaction.FactionUI.FactionTypeMenu.ClearOptions();
                if (Factions [0].FactionUI.FactionTypeMenu.options.Count > 0)
                {
                    NewFaction.FactionUI.FactionTypeMenu.AddOptions(Factions [0].FactionUI.FactionTypeMenu.options);
                }
                NewFaction.FactionUI.FactionTypeMenu.value = 0;
                NewFaction.FactionCode = Maps [CurrentMapID].FactionTypes [0].Code;

                NewFaction.FactionUI.Mgr = this;

                Factions.Add(NewFaction);
                NewFaction.FactionUI.Faction = Factions [Factions.Count - 1];                 //to link the FactionUI object with the map manager.
            }
            else
            {
            }
        }
Example #2
0
        public GameObject[] DifficultyLevels; //Array that holds the possible difficulty level objects (each difficulty level object is an empty object that has 3 components only: NPCBuildingPlacement, NPCResource and NPCArmy).

        // Use this for initialization
        void Awake()
        {
            DontDestroyOnLoad(this.gameObject);              //we want this object to be passed to the map's scene.

            int i = 0;

            //go through all the maps:
            if (Maps.Length > 0)
            {
                CurrentMapID = 0;
                List <string> MapNames = new List <string>();

                for (i = 0; i < Maps.Length; i++)
                {
                    //If we forgot to put the map's scene or we have less than 2 as max players, then show an error:
                    if (Maps [i].MapScene == null)
                    {
                        Debug.LogError("Map ID " + i.ToString() + " is invalid!");
                    }
                    if (Maps [i].MaxFactions < 2)
                    {
                        Debug.LogError("Map ID " + i.ToString() + " max factions (" + Maps [i].MaxFactions.ToString() + ") is lower than 2!");
                    }
                    if (Maps [i].MaxFactions > MaxFactions)
                    {
                        Debug.LogError("Map ID " + i.ToString() + " max factions (" + Maps [i].MaxFactions.ToString() + ") must be lower than the allowed amount of factions (" + MaxFactions.ToString() + ")!");
                    }
                    MapNames.Add(Maps [i].MapName);
                }

                //set the map drop down menu options to the names of the maps.
                if (MapDropDownMenu != null)
                {
                    MapDropDownMenu.ClearOptions();
                    MapDropDownMenu.AddOptions(MapNames);
                }
                else
                {
                    Debug.LogError("You must add a drop down menu to pick the maps!");
                }
            }
            else
            {
                //At least one map must be included:
                Debug.LogError("You must include at least one map in the map manager!");
            }

            //go through all the difficulty levels:
            if (DifficultyLevels.Length > 0)
            {
                for (i = 0; i < DifficultyLevels.Length; i++)
                {
                    //Show an error if one of the difficulty levels components has not been assigned:
                    if (DifficultyLevels [i] == null)
                    {
                        Debug.LogError("Difficulty Level ID " + i.ToString() + " has not been defined in the map manager!");
                    }
                }
            }
            else
            {
                //We need at least one difficulty level:
                Debug.LogError("You must include at least one difficulty level in the map manager!");
            }


            Factions = new List <FactionVars>();            //Initialize the factions info:
            //We create two factions at the start of the scene because it's the minimal amount of factions:
            for (i = 0; i < 2; i++)
            {
                FactionVars NewFaction = new FactionVars();
                //set the faction's info:
                NewFaction.FactionName       = "Faction " + i.ToString();
                NewFaction.InitialPopulation = MinPopulation;

                //Creating a UI panel for each faction:
                if (i == 0)
                {
                    NewFaction.FactionUI = FactionUISample;
                    NewFaction.FactionUI.DifficultyMenu.gameObject.SetActive(false);                      //hide the difficulty menu for the first faction (as it is always player controlled).
                }
                else
                {
                    //taking the FactionUISample as base to create all the rest:
                    GameObject FactionUIClone = (GameObject)Instantiate(FactionUISample.gameObject, Vector3.zero, Quaternion.identity);
                    FactionUIClone.transform.SetParent(FactionUIParent);                      //make sure to set the FactionUI objects to the same parent.
                    NewFaction.FactionUI = FactionUIClone.GetComponent <FactionUIInfo>();
                    FactionUIClone.GetComponent <RectTransform> ().localScale = new Vector3(1.0f, 1.0f, 1.0f);

                    NewFaction.FactionUI.DifficultyMenu.gameObject.SetActive(true);                      //activate the difficulty menu:
                }

                //rest of the UI settings:
                NewFaction.FactionUI.RemoveFactionButton.gameObject.SetActive(false);
                NewFaction.FactionUI.PopulationInput.text  = NewFaction.InitialPopulation.ToString(); //initial population
                NewFaction.FactionUI.FactionNameInput.text = NewFaction.FactionName.ToString();       //name
                NewFaction.FactionColorID           = i;                                              //color id
                NewFaction.FactionColor             = AllowedColors [i];                              //color
                NewFaction.FactionUI.ColorImg.color = NewFaction.FactionColor;
                NewFaction.NPCDifficulty            = 0;                                              //difficulty level:

                NewFaction.FactionUI.Mgr = this;

                Factions.Add(NewFaction);                                    //add a new faction to the list:

                NewFaction.FactionUI.Faction = Factions[Factions.Count - 1]; //link the FactionUI object with the map manager.
            }

            //The first faction belongs to the faction controlled by the player:
            Factions[0].ControlledByPlayer = true;

            UpdateMap();              //update the map's settings
        }
Example #3
0
        //a method that adds a new faction:
        public void AddFaction()
        {
            //if we haven't reached the maximum allowed amount of factions
            if (Factions.Count < Maps [CurrentMapID].MaxFactions)
            {
                //create a new faction
                FactionVars NewFaction = new FactionVars();
                NewFaction.FactionName       = "Faction " + Factions.Count.ToString();
                NewFaction.InitialPopulation = MinPopulation;

                //Creating a UI panel for each faction:
                if (Factions.Count == 0) //first faction to be created -> player faction
                {
                    NewFaction.playerControlled = true;

                    NewFaction.FactionUI = FactionUISample;

                    //add the NPC Managers from the list in this component as options in the npc manager menu:
                    //first put the names of the npc managers inside a list of strings:
                    List <string> npcMgrOptions = new List <string>();
                    foreach (NPCManager mgr in npcManagers)
                    {
                        npcMgrOptions.Add(mgr.Name);
                    }
                    //add the above list as the options for the npc manager menu:
                    NewFaction.FactionUI.npcManagerMenu.ClearOptions();
                    NewFaction.FactionUI.npcManagerMenu.AddOptions(npcMgrOptions);
                    //we only need to set the npc manager menu once as it will be copied from other factions later.

                    NewFaction.FactionUI.npcManagerMenu.gameObject.SetActive(false); //hide the npc manager menu for the first faction (as it is always player controlled).
                }
                else
                {
                    NewFaction.playerControlled = false; //not player controlled.

                    //taking the FactionUISample as base to create all the rest:
                    GameObject FactionUIClone = (GameObject)Instantiate(FactionUISample.gameObject, Vector3.zero, Quaternion.identity);
                    FactionUIClone.transform.SetParent(FactionUIParent); //make sure to set the FactionUI objects to the same parent.
                    NewFaction.FactionUI = FactionUIClone.GetComponent <FactionUIInfo>();
                    FactionUIClone.GetComponent <RectTransform>().localScale = new Vector3(1.0f, 1.0f, 1.0f);

                    NewFaction.FactionUI.npcManagerMenu.gameObject.SetActive(true); //activate the npc manager menu for NPC factions.
                }

                //set the faction's UI info:
                //if these are the first two factions, then they can not be removed, if not they can be removed:
                NewFaction.FactionUI.RemoveFactionButton.gameObject.SetActive((Factions.Count < 2) ? false : true);

                NewFaction.FactionUI.PopulationInput.text  = NewFaction.InitialPopulation.ToString(); //population
                NewFaction.FactionUI.FactionNameInput.text = NewFaction.FactionName.ToString();       //name
                NewFaction.FactionUI.ColorImg.color        = NewFaction.FactionColor;                 //color
                NewFaction.npcMgr = npcManagers[0];

                //the faction type:
                NewFaction.FactionUI.FactionTypeMenu.ClearOptions();  //clear the default faction type menu options.
                //if this is not the player controlled faction/first faction:
                if (Factions.Count > 0)
                {
                    //simply copy the faction type menu options from the first created faction.
                    if (Factions[0].FactionUI.FactionTypeMenu.options.Count > 0)
                    {
                        NewFaction.FactionUI.FactionTypeMenu.AddOptions(Factions[0].FactionUI.FactionTypeMenu.options);
                    }
                }
                NewFaction.FactionUI.FactionTypeMenu.value = 0;                 //pick the first type in the list by default.
                NewFaction.TypeInfo = Maps [CurrentMapID].FactionTypes [0];

                NewFaction.FactionUI.Mgr = this;

                Factions.Add(NewFaction);
                NewFaction.FactionUI.Faction = Factions [Factions.Count - 1];                 //to link the FactionUI object with the map manager.
            }
            else
            {
                Debug.LogError("[Single Player Manager]: Map maximum factions amount has been reached.");
            }
        }