Exemplo n.º 1
0
        void Awake()
        {
            //Some values are chosen at the beginning of the game only
            ArmyPowerRatio      = Random.Range(ArmyPowerRatioRange.x, ArmyPowerRatioRange.y);
            MinArmyPower        = Random.Range(MinArmyPowerRange.x, MinArmyPowerRange.y);
            DefenseUnitsRatio   = Random.Range(DefenseUnitsRatioRange.x, DefenseUnitsRatioRange.y);
            HealersRatio        = Random.Range(HealersRatioRange.x, HealersRatioRange.y);
            ConvertersRatio     = Random.Range(ConvertersRatioRange.x, ConvertersRatioRange.y);
            NonAttackUnitsRatio = Random.Range(NonAttackUnitsRatioRange.x, NonAttackUnitsRatioRange.y);
            MaxNonAttackUnits   = Mathf.CeilToInt(Random.Range(MaxNonAttackUnitsRange.x, MaxNonAttackUnitsRange.y));

            Attacking      = false;
            CheckArmyTimer = Random.Range(CheckArmyReload.x, CheckArmyReload.y);

            GameMgr = GameManager.Instance;
            MvtMgr  = MovementManager.Instance;

            //If there's a map manager script in the scene, it means that we just came from the map menu, so the faction manager and the settings have been already set by the game manager:
            if (GameMgr.SinglePlayerMgr == null)
            {
                FactionMgr         = GameMgr.Factions [FactionID].FactionMgr;
                FactionMgr.ArmyMgr = this;

                if (FactionMgr == null)
                {
                    //If we can't find the AI Faction manager script, then print an error:
                    Debug.LogError("Can't find the AI Faction Manager for Faction ID: " + FactionID.ToString());
                }
            }
        }
Exemplo n.º 2
0
        //CREATE NEW NPC HEALERS MANAGER: MOVE HEALERS FROM POS A TO POS B when army is moving
        //SAME THING TO APPLY FOR CONVERTERS.

        //NPC Manager: Editor script that can create NPC difficulty levels and manage them including:
        //a generate unit regulator tool that scans already created regulators and unit prefabs to produce unit regulators
        //a generate buildings regulator tool that does the same for buildings
        //user will have created regulators appear in a scroll list and he can select them and they will be selected in inspector to modify
        //create everything in known paths in the project and manipulate everything using that path.

        void Start()
        {
            gameMgr = GameManager.Instance;
            mvtMgr  = MovementManager.Instance;

            //if we can't attack then disable this component:
            if (canAttack == false)
            {
                enabled = false;
            }
            else
            {
                targetFaction         = null;
                setTargetFactionTimer = setTargetFactionDelay.getRandomValue(); //start the set attack target timer.
            }

            //start timers:
            setTargetFactionTimer = setTargetFactionDelay.getRandomValue();
            launchAttackTimer     = launchAttackReloadRange.getRandomValue();

            //assign target buildings codes:
            UpdateTargetBuildingCodes();

            //start listening to events:
            CustomEvents.UnitDead          += OnUnitDead;
            CustomEvents.UnitConverted     += OnUnitConverted;
            CustomEvents.FactionEliminated += OnFactionEliminated;
        }
Exemplo n.º 3
0
        void Start()
        {
            //get the ame manager script
            GameMgr   = GameManager.Instance;
            MvtMgr    = MovementManager.Instance;
            AttackMgr = AttackManager.Instance;

            //default values for the timers:
            AttackTimer = 0.0f;
            SearchTimer = 0.0f;

            ObjPool = EffectObjPool.Instance;

            if (AttackAllTypes == false)
            { //if it can not attack all the units
                AttackMgr.AssignAttackExceptions(AttackExceptions, ref AttackExceptionList);
            }

            //if there's a weapon object:
            if (WeaponObj)
            {
                WeaponIdleRotation.eulerAngles = WeaponIdleAngles;
            }

            //get the range type ID from the attack manager
            RangeTypeID = AttackMgr.GetRangeTypeID(RangeType);
        }
Exemplo n.º 4
0
        void Start()
        {
            gameMgr = GameManager.Instance;
            mvtMgr  = MovementManager.Instance;

            //add event listeners:
            CustomEvents.UnitHealthUpdated     += OnUnitHealthUpdated;
            CustomEvents.BuildingHealthUpdated += OnBuildingHealthUpdated;
        }
Exemplo n.º 5
0
 void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
     }
     else if (Instance != this)
     {
         Destroy(this);
     }
 }
Exemplo n.º 6
0
        void Start()
        {
            MvtMgr = MovementManager.Instance;

            //if this belongs to the local player, destroy it
            if (FactionID == GameManager.PlayerFactionID)
            {
                Destroy(this);
                return;
            }
            else
            {
                CheckArmyUnitsPriority(0, ArmyUnits.Length);
            }
        }
Exemplo n.º 7
0
        void Start()
        {
            //initially not following any unit
            UnitToFollow = null;

            SelectionMgr = GameManager.Instance.SelectionMgr;
            TerrainMgr   = GameManager.Instance.TerrainMgr;
            MvtMgr       = MovementManager.Instance;

            if (MainCamera == null)
            {
                Debug.LogError("Please set the main camera");
            }
            else
            {
                //get the camera FOV
                FOV = MainCamera.fieldOfView;
                //set the camera's position and rotation angles
                MainCamera.transform.position    = new Vector3(MainCamera.transform.position.x, CameraHeight, MainCamera.transform.position.z);
                MainCamera.transform.eulerAngles = new Vector3(45.0f, 45.0f, 0.0f);
            }
        }
Exemplo n.º 8
0
        void Start()
        {
            //get the ame manager script
            GameMgr   = GameManager.Instance;
            MvtMgr    = MovementManager.Instance;
            AttackMgr = AttackManager.Instance;

            //default values for the timers:
            AttackTimer = 0.0f;
            SearchTimer = 0.0f;

            ObjPool = EffectObjPool.Instance;

            //if there's a weapon object:
            if (WeaponObj)
            {
                WeaponIdleRotation.eulerAngles = WeaponIdleAngles;
            }

            //get the range type ID from the attack manager
            RangeTypeID = AttackMgr.GetRangeTypeID(RangeType);
        }
Exemplo n.º 9
0
        public AudioSource GeneralAudioSource; //The audio source where audio will be played generally unless the audio is local. In that case, it will be played

        void Awake()
        {
            //set the instance:
            if (Instance == null)
            {
                Instance = this;
            }
            else if (Instance != this)
            {
                Destroy(gameObject);
            }

            AllFactionsReady = false; //faction stats are not ready, yet

            //Randomize player controlled faction:
            RandomizePlayerFaction();

            CamMov      = FindObjectOfType(typeof(CameraMovement)) as CameraMovement;   //Find the camera movement script.
            ResourceMgr = FindObjectOfType(typeof(ResourceManager)) as ResourceManager; //Find the resource manager script.
            if (ResourceMgr != null)
            {
                ResourceMgr.GameMgr = this;
            }
            UIMgr       = FindObjectOfType(typeof(UIManager)) as UIManager; //Find the UI manager script.
            BuildingMgr = FindObjectOfType(typeof(BuildingPlacement)) as BuildingPlacement;
            Events      = FindObjectOfType(typeof(CustomEvents)) as CustomEvents;
            TaskMgr     = FindObjectOfType(typeof(TaskManager)) as TaskManager;
            if (TaskMgr != null)
            {
                TaskMgr.GameMgr = this;
            }
            UnitMgr      = FindObjectOfType(typeof(UnitManager)) as UnitManager;
            SelectionMgr = FindObjectOfType(typeof(SelectionManager)) as SelectionManager;
            PlacementMgr = FindObjectOfType(typeof(BuildingPlacement)) as BuildingPlacement;
            TerrainMgr   = FindObjectOfType(typeof(TerrainManager)) as TerrainManager;
            MvtMgr       = FindObjectOfType(typeof(MovementManager)) as MovementManager;

            MultiplayerGame = false; //We start by assuming it's a simple single player game.

            //First check if there's a network manager component in the scene:
            NetworkMgr_UNET = NetworkManager_UNET.NetworkMgr;
            if (NetworkMgr_UNET != null)
            {                           //If there's actually a network map manager, it means that the map was loaded from the multiplayer menu, meaning that this is a MP game.
                ClearNPCManagers();     //clearing all the npc components in the map since it's a MP game.
                MultiplayerGame = true; //we now recongize that this a multiplayer game.

                //set the network type in the input manager
                InputManager.NetworkType = InputManager.NetworkTypes.UNET;

                List <MFactionLobby_UNET> FactionLobbyInfos = new List <MFactionLobby_UNET>();
                FactionLobbyInfos.Clear();                                               //clear this list
                //we'll add the faction lobby components to it using the lobby slots array from the network manager
                foreach (NetworkLobbyPlayer NetworkPlayer in NetworkMgr_UNET.lobbySlots) //go through all the lobby slots
                {
                    //if the slot is occupied:
                    if (NetworkPlayer != null)
                    {
                        //add the faction lobby component attached to it to the list:
                        FactionLobbyInfos.Add(NetworkPlayer.gameObject.GetComponent <MFactionLobby_UNET>());
                    }
                }
                //This where we will set the settings for all the players:
                //First check if we have enough faction slots available:
                if (FactionLobbyInfos.Count <= Factions.Count)
                {
                    //Loop through all the current factions and set up each faction slot:
                    for (int i = 0; i < FactionLobbyInfos.Count; i++)
                    {
                        MFactionLobby_UNET ThisFaction = FactionLobbyInfos[i]; //this is the faction info that we will get from the faction lobby info.

                        //Set the info for the factions that we will use:
                        Factions[i].Name         = ThisFaction.FactionName;  //get the faction name
                        Factions[i].FactionColor = ThisFaction.FactionColor; //the faction color
                        //get the initial max population from the network manager (making it the same for all the players).
                        Factions[i].MaxPopulation = NetworkMgr_UNET.Maps[ThisFaction.MapID].InitialPopulation;
                        Factions[i].Lost          = false;

                        Factions[i].MFactionLobby_UNET = ThisFaction;                                    //linking the faction with its lobby info script.
                        Factions[i].CapitalPos         = Factions[i].CapitalBuilding.transform.position; //setting the capital pos to spawn the capital building object at later.

                        Factions[i].FactionMgr = Factions[i].FactionMgr;                                 //linking the faction with its faction manager.

                        Factions[i].Code = ThisFaction.FactionCode;

                        //Setting the local player faction ID:
                        if (ThisFaction.isLocalPlayer)
                        { //isLoclPlayer determines which lobby faction info script is owned by the player..
                          //therefore the faction linked to that script is the player controlled one.
                            PlayerFactionID           = i;
                            Factions[i].PlayerControl = true;
                            PlayerFactionMgr          = Factions[i].FactionMgr;
                        }
                        else
                        {
                            //all other factions will be defined as NPC but in the reality, they are controlled by other players through the network.
                            Factions[i].PlayerControl = false;
                        }

                        //Set the master faction ID:
                        if (ThisFaction.IsServer)
                        {
                            MasterFactionID = i;
                        }
                    }

                    //loop through all the factions and destroy the default capital buildings because the server will spawn new ones for each faction.
                    for (int i = 0; i < Factions.Count; i++)
                    {
                        DestroyImmediate(Factions[i].CapitalBuilding.gameObject);
                    }

                    //if there are more slots than required.
                    while (FactionLobbyInfos.Count < Factions.Count)
                    {
                        //remove the extra slots:
                        Factions.RemoveAt(Factions.Count - 1);
                    }
                }
                else
                {
                    Debug.LogError("Not enough slots available for all the factions!");
                }
            }

            SinglePlayerMgr = FindObjectOfType(typeof(SinglePlayerManager)) as SinglePlayerManager; //search for the map manager script.
            //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!
            if (SinglePlayerMgr != null)
            {
                //This where we will set the NPC settings using the info from the map manager:
                //First check if we have enough faction slots available:
                if (SinglePlayerMgr.Factions.Count <= Factions.Count)
                {
                    ClearNPCManagers(); //remove the current npc managers as they will be replaced by other ones.

                    //loop through the factions slots of this map:
                    for (int i = 0; i < SinglePlayerMgr.Factions.Count; i++)
                    {
                        //Set the info for the factions that we will use:
                        Factions[i].Name          = SinglePlayerMgr.Factions[i].FactionName;        //name
                        Factions[i].FactionColor  = SinglePlayerMgr.Factions[i].FactionColor;       //color
                        Factions[i].PlayerControl = SinglePlayerMgr.Factions[i].ControlledByPlayer; //is this faction controlled by the player?
                        Factions[i].MaxPopulation = SinglePlayerMgr.Factions[i].InitialPopulation;  //initial maximum population (which can be increased in the game).
                        Factions[i].Code          = SinglePlayerMgr.Factions[i].FactionCode;        //the faction's code.
                        Factions[i].CapitalPos    = Factions[i].CapitalBuilding.transform.position; //setting the capital pos to spawn the capital building object at later.

                        Factions[i].Lost = false;

                        int FactionTypeID = GetFactionTypeID(Factions[i].Code);
                        if (FactionTypeID >= 0 && FactionDef[FactionTypeID].CapitalBuilding != null)
                        {                                                             //if the faction to a certain type
                            DestroyImmediate(Factions[i].CapitalBuilding.gameObject); //destroy the default capital and spawn another one:

                            //we will spawn the capital building and remove the one that already came in the scene:
                            GameObject Capital = Instantiate(FactionDef[FactionTypeID].CapitalBuilding.gameObject);

                            //set the capital's settings:
                            Capital.GetComponent <Building>().FactionID       = i;
                            Capital.GetComponent <Building>().FactionCapital  = true;
                            Capital.GetComponent <Building>().PlacedByDefault = true;

                            Capital.transform.position  = Factions[i].CapitalPos; //set the capital's position on the map.
                            Factions[i].CapitalBuilding = Capital.GetComponent <Building>();
                        }

                        //if this faction not controlled by the player
                        if (Factions[i].PlayerControl == false)
                        {
                            //Spawn the NPC managers setinngs for this faction:
                            GameObject NPCMgrObj = (GameObject)Instantiate(SinglePlayerMgr.DifficultyLevels[SinglePlayerMgr.Factions[i].NPCDifficulty], Vector3.zero, Quaternion.identity);

                            //NPC Army manager:
                            NPCMgrObj.GetComponent <NPCArmy>().FactionID  = i;
                            NPCMgrObj.GetComponent <NPCArmy>().FactionMgr = Factions[i].FactionMgr;
                            Factions[i].FactionMgr.ArmyMgr = NPCMgrObj.GetComponent <NPCArmy>();

                            //NPC Building placement manager:
                            NPCMgrObj.GetComponent <NPCBuildingPlacement>().FactionID  = i;
                            NPCMgrObj.GetComponent <NPCBuildingPlacement>().FactionMgr = Factions[i].FactionMgr;
                            Factions[i].FactionMgr.BuildingMgr = NPCMgrObj.GetComponent <NPCBuildingPlacement>();

                            //NPC Resource manager:
                            NPCMgrObj.GetComponent <NPCResource>().FactionID  = i;
                            NPCMgrObj.GetComponent <NPCResource>().FactionMgr = Factions[i].FactionMgr;
                            Factions[i].FactionMgr.ResourceMgr = NPCMgrObj.GetComponent <NPCResource>();

                            //NPC Unit spawner: (optional)
                            if (NPCMgrObj.GetComponent <NPCUnitSpawner>())
                            {
                                NPCMgrObj.GetComponent <NPCUnitSpawner>().FactionID  = i;
                                NPCMgrObj.GetComponent <NPCUnitSpawner>().FactionMgr = Factions[i].FactionMgr;
                                Factions[i].FactionMgr.UnitSpawner = NPCMgrObj.GetComponent <NPCUnitSpawner>();
                            }
                        }
                    }

                    //if there are more slots than required.
                    while (SinglePlayerMgr.Factions.Count < Factions.Count)
                    {
                        //remove the extra slots:
                        DestroyImmediate(Factions[Factions.Count - 1].CapitalBuilding.gameObject);
                        Factions.RemoveAt(Factions.Count - 1);
                    }
                }
                else
                {
                    Debug.LogError("Not enough slots available for all the factions!");
                }

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

            //If it's a multiplayer game, we still need to figure what's the local player faction ID.
            if (MultiplayerGame == false)
            {
                PlayerFactionID = -1;
            }

            if (Factions.Count > 0)
            {
                //Create as many resource info slots as the amount of the spawned factions.
                ResourceMgr.FactionResourcesInfo = new ResourceManager.FactionResourcesVars[Factions.Count];

                //Loop through all the factions:
                for (int i = 0; i < Factions.Count; i++)
                {
                    //if it's not a multiplayer game:
                    if (MultiplayerGame == false)
                    {
                        //and this faction is controlled by the player:
                        if (Factions[i].PlayerControl == true)
                        {
                            //then define this as the player faction:
                            PlayerFactionID  = i;
                            PlayerFactionMgr = Factions[i].FactionMgr;
                        }
                    }

                    //Only if it's a single player game we will be checking if the capital buildings have spawned, because in multiplayer, another script handles spawning these
                    if (MultiplayerGame == false)
                    {
                        if (Factions[i].CapitalBuilding == null)
                        {
                            Debug.LogError("Faction ID: " + i + " is missing the 'Capital Building'");
                        }
                        else
                        {
                            Factions[i].CapitalBuilding.FactionID      = i;
                            Factions[i].CapitalBuilding.FactionCapital = true;
                        }
                    }


                    ResourceMgr.FactionResourcesInfo[i] = new ResourceManager.FactionResourcesVars();
                    //Associate each team with all available resources:
                    ResourceMgr.FactionResourcesInfo[i].ResourcesTypes = new ResourceManager.ResourcesVars[ResourceMgr.ResourcesInfo.Length];

                    //Loop through all the available resources and define them for each team.
                    for (int j = 0; j < ResourceMgr.FactionResourcesInfo[i].ResourcesTypes.Length; j++)
                    {
                        ResourceMgr.FactionResourcesInfo[i].ResourcesTypes[j] = new ResourceManager.ResourcesVars();

                        ResourceMgr.FactionResourcesInfo[i].ResourcesTypes[j].Name   = ResourceMgr.ResourcesInfo[j].Name;           //Name of the resource
                        ResourceMgr.FactionResourcesInfo[i].ResourcesTypes[j].Amount = ResourceMgr.ResourcesInfo[j].StartingAmount; //Starting amount of the resource for each team.
                    }
                }
            }

            ResourceMgr.UpdateResourcesUI(); //right after setting up the resource settings above, refresh the resource UI.

            //In order to avoid having buildings that are being placed by AI players and units collide, we will ignore physics between their two layers:
            Physics.IgnoreLayerCollision(LayerMask.NameToLayer("Hidden"), LayerMask.NameToLayer("Unit"));
            //Physics.IgnoreLayerCollision(LayerMask.NameToLayer("Unit"), LayerMask.NameToLayer("Unit"));

            if (PeaceTime <= 0.0f)
            {
                //If there's no peace make factions pick their targets early:
                SetFactionTargets();
            }

            //Set the amount of the active factions:
            ActiveFactions = Factions.Count;

            GameState = GameStates.Running; //the game state is now set to running

            //reaching this point means that all faction info/stats in the game manager are ready:
            AllFactionsReady = true;
        }
Exemplo n.º 10
0
        public AudioSource GeneralAudioSource;      //The audio source where audio will be played generally unless the audio is local. In that case, it will be played

        void Awake()
        {
            //set the instance:
            if (Instance == null)
            {
                Instance = this;
            }
            else if (Instance != this)
            {
                Destroy(gameObject);
            }

            Time.timeScale = 1.0f;    //unfreeze game if it was frozen from a previous game.

            allFactionsReady = false; //faction stats are not ready, yet

            //Randomize player controlled faction:
            RandomizePlayerFaction();

            //Get components:
            CamMov      = FindObjectOfType(typeof(CameraMovement)) as CameraMovement;   //Find the camera movement script.
            ResourceMgr = FindObjectOfType(typeof(ResourceManager)) as ResourceManager; //Find the resource manager script.
            if (ResourceMgr != null)
            {
                ResourceMgr.gameMgr = this;
            }
            UIMgr        = FindObjectOfType(typeof(UIManager)) as UIManager; //Find the UI manager script.
            BuildingMgr  = FindObjectOfType(typeof(BuildingPlacement)) as BuildingPlacement;
            Events       = FindObjectOfType(typeof(CustomEvents)) as CustomEvents;
            TaskMgr      = FindObjectOfType(typeof(TaskManager)) as TaskManager;
            UnitMgr      = FindObjectOfType(typeof(UnitManager)) as UnitManager;
            SelectionMgr = FindObjectOfType(typeof(SelectionManager)) as SelectionManager;
            PlacementMgr = FindObjectOfType(typeof(BuildingPlacement)) as BuildingPlacement;
            TerrainMgr   = FindObjectOfType(typeof(TerrainManager)) as TerrainManager;
            MvtMgr       = FindObjectOfType(typeof(MovementManager)) as MovementManager;

            MultiplayerGame = false;            //We start by assuming it's a single player game.

            InitFactionMgrs();                  //create the faction managers components for the faction slots.

            InitMultiplayerGame();              //to initialize a multiplayer game.

            InitSinglePlayerGame();             //to initialize a single player game.

            SetPlayerFactionID();               //pick the player faction ID.

            InitFactionCapitals();              //init the faction capitals.

            ResourceMgr.InitFactionResources(); //init resources for factions.

            InitFactions();                     //init the faction types.

            //In order to avoid having buildings that are being placed by AI players and units collide, we will ignore physics between their two layers:
            Physics.IgnoreLayerCollision(LayerMask.NameToLayer("Hidden"), LayerMask.NameToLayer("Unit"));

            //Set the amount of the active factions:
            activeFactionsAmount = Factions.Count;

            GameState = GameStates.Running; //the game state is now set to running

            //reaching this point means that all faction info/stats in the game manager are ready:
            allFactionsReady = true;
        }