예제 #1
0
        //get a list of units and then sends them back to their creator buildings
        public void SendBackUnits(List <Unit> unitsList)
        {
            //go through the units:
            foreach (Unit u in unitsList)
            {
                //if the unit is valid:
                if (u != null)
                {
                    //if it doesn't have a creator building
                    if (u.CreatedBy == null)
                    {
                        u.CreatedBy = gameMgr.Factions[factionMgr.FactionID].CapitalBuilding;
                    }

                    //send unit to back to creator building:
                    mvtMgr.Move(u, u.CreatedBy.transform.position, u.CreatedBy.Radius, u.CreatedBy.gameObject, InputTargetMode.Building);
                }
            }
        }
예제 #2
0
        //method called to check if the player clicked on the minimap and update accordinly:
        void OnMinimapClick()
        {
            Ray RayCheck;

            RaycastHit[] Hits;

            //create a raycast using the minimap camera
            RayCheck = MinimapCam.ScreenPointToRay(Input.mousePosition);
            Hits     = Physics.RaycastAll(RayCheck, 100.0f);

            if (Hits.Length > 0)
            {
                for (int i = 0; i < Hits.Length; i++)
                {
                    //If we clicked on a part of the terrain:
                    if (Hits[i].transform.gameObject == TerrainMgr.FlatTerrain)
                    {
                        //if this is the left mouse button and the selection box is disabled
                        if (Input.GetMouseButtonUp(0) && SelectionMgr.SelectionBoxEnabled == false)
                        {
                            //stop following the unit if it's enabled
                            if (CanFollowUnit == true)
                            {
                                UnitToFollow = null;
                            }
                            //make the camera look at the position we clicked in the minimap
                            LookAt(Hits[i].point);
                            //mark as moved:
                            Moved = true;
                        }
                        //TO BE CHANGED
                        //if the player presses the right mouse button
                        else if (Input.GetMouseButtonUp(1))
                        {
                            //move the selected units to the new clicked position in the minimap
                            MvtMgr.Move(SelectionMgr.SelectedUnits, Hits[i].point, 0.0f, null, InputTargetMode.None);
                        }
                    }
                }
            }
        }
예제 #3
0
        //Send units to attack a center:
        public void SendUnitsToTargetBuilding()
        {
            if (TargetBuilding != null)               //if there's a target building
            {
                GameObject Target = TargetBuilding.gameObject;

                //if the target building is currently being fixed by builders
                if (TargetBuilding.WorkerMgr.CurrentWorkers > 0)
                {
                    int n = 0;
                    //attack these builders instead.
                    while (n < TargetBuilding.WorkerMgr.WorkerPositions.Length)
                    {
                        //first check if there's a worker in this slot:
                        if (TargetBuilding.WorkerMgr.WorkerPositions[n].CurrentUnit != null)
                        {
                            //if the worker is constructing
                            if (TargetBuilding.WorkerMgr.WorkerPositions[n].CurrentUnit.BuilderMgr.IsBuilding == true)
                            {
                                //set him as target
                                Target            = TargetBuilding.WorkerMgr.GetWorker().gameObject;
                                TargetingBuilders = true;
                            }
                        }
                        n++;
                    }
                }
                else
                {
                    TargetingBuilders = false;
                }

                if (Army.Count > 0)
                {
                    for (int i = 0; i < Army.Count; i++)
                    {
                        if (Army [i] != null)
                        {
                            if (Army [i].AttackMgr.AttackTarget == null)                               //set the attacking support range that will call nearby units for support.
                            {
                                Army [i].AttackMgr.SearchRange = AttackingSupportRange;
                            }
                        }
                    }
                    MvtMgr.LaunchAttack(Army, Target.gameObject, (TargetingBuilders == true) ? MovementManager.AttackModes.Change : MovementManager.AttackModes.None);  //launch the attack.

                    //move healers and converters to the target building
                    //Healers:
                    int HealersAmount    = Mathf.RoundToInt(FactionMgr.Healers.Count * HealersRatio);
                    int ConvertersAmount = Mathf.RoundToInt(FactionMgr.Converters.Count * ConvertersRatio);
                    //if there are healers to send:
                    int j = 0;
                    while (HealersAmount > 0 && j < FactionMgr.Healers.Count)
                    {
                        if (FactionMgr.Healers [j].TargetUnit == null)                           //only move the unit if it has no target
                        {
                            MvtMgr.Move(FactionMgr.Healers[j].UnitMvt, Target.transform.position, TargetBuilding.Radius, Target, InputTargetMode.Building);
                        }
                        HealersAmount--;
                        ExtraArmyUnits.Add(FactionMgr.Healers [j].UnitMvt);
                        j++;
                    }
                    j = 0;
                    //if there are converters to send, do it:
                    while (ConvertersAmount > 0 && j < FactionMgr.Converters.Count)
                    {
                        if (FactionMgr.Converters [j].TargetUnit == null)
                        {
                            MvtMgr.Move(FactionMgr.Converters[j].UnitMvt, Target.transform.position, TargetBuilding.Radius, Target, InputTargetMode.Building);
                        }
                        ConvertersAmount--;
                        ExtraArmyUnits.Add(FactionMgr.Converters [j].UnitMvt);
                        j++;
                    }
                }
            }
        }