Esempio n. 1
0
        private bool collectOnDemand = true; //when another component requests to collect a resource, allow it or not?
        #endregion

        #region Initializing/Terminating
        /// <summary>
        /// Initializes the NPCResourceCollector instance, called from the NPCManager instance responsible for this component.
        /// </summary>
        /// <param name="gameMgr">GameManager instance of the current game.</param>
        /// <param name="npcMgr">NPCManager instance that manages this NPCComponent instance.</param>
        /// <param name="factionMgr">FactionManager instance of the faction that this component manages.</param>
        public override void Init(GameManager gameMgr, NPCManager npcMgr, FactionManager factionMgr)
        {
            base.Init(gameMgr, npcMgr, factionMgr);

            InitResourceCollectionInfo(); //initialize the dictionary data structure that basically controls how each resource type is collected

            //add event listeners:
            CustomEvents.UnitStopCollecting  += OnUnitStopCollecting;
            CustomEvents.UnitCollectionOrder += OnUnitCollectionOrder;
            CustomEvents.ResourceEmpty       += OnResourceEmpty;
            CustomEvents.UnitCreated         += OnUnitCreated;
        }
Esempio n. 2
0
        public override void Init(GameManager gameMgr, NPCManager npcMgr, FactionManager factionMgr)
        {
            base.Init(gameMgr, npcMgr, factionMgr);

            //clear the active unit regulator list per default:
            activeUnitRegulators.Clear();

            foreach (NPCUnitRegulator nue in independentUnitRegulators)
            {
                ActivateUnitRegulator(nue);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes the NPCComponent instance.
        /// </summary>
        /// <param name="gameMgr">GameManager instance of the current game.</param>
        /// <param name="npcMgr">NPCManager instance that manages this NPCComponent instance.</param>
        /// <param name="factionMgr">FactionManager instance of the faction that this component manages.</param>
        public virtual void Init(GameManager gameMgr, NPCManager npcMgr, FactionManager factionMgr)
        {
            //assign components
            this.gameMgr = gameMgr;
            Assert.IsNotNull(this.gameMgr, "[NPCComponent] Initializing without a reference to the GameManager instance is not allowed!");

            this.npcMgr = npcMgr;
            Assert.IsNotNull(this.npcMgr, "[NPCComponent] Initializing without a reference to the faction's NPCManager instance is not allowed!");

            this.factionMgr = factionMgr;
            Assert.IsNotNull(this.factionMgr, "[NPCComponent] Initializing without a reference to the faction's FactionManager instance is not allowed!");
        }
Esempio n. 4
0
 //a method to get the faction ID of the task holder:
 public void SetFactionInfo()
 {
     if (TaskHolder == TaskHolders.Unit)
     {
         FactionID  = RefUnit.FactionID;
         FactionMgr = RefUnit.FactionMgr;
     }
     else
     {
         FactionID  = RefBuilding.FactionID;
         FactionMgr = RefBuilding.FactionMgr;
     }
 }
        /// <summary>
        /// Initializes the NPCActiveRegulatorMonitor instance.
        /// </summary>
        /// <param name="factionMgr">FactionManager instance that controls this instance.</param>
        public void Init(FactionManager factionMgr)
        {
            Assert.IsNotNull(factionMgr,
                             "[NPCActiveRegulatorMonitor] Unable to initialize due to invalid FactionManager instance.");

            this.factionMgr = factionMgr;

            codes.Clear();

            //subscribe to custom events:
            CustomEvents.UnitUpgraded     += OnFactionEntityUpgraded;
            CustomEvents.BuildingUpgraded += OnFactionEntityUpgraded;
        }
Esempio n. 6
0
		void Awake () {
			GameMgr = GameManager.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.UnitSpawner = 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 ());
				}
			}
		}
Esempio n. 7
0
        public override void Init(GameManager gameMgr, NPCManager npcMgr, FactionManager factionMgr)
        {
            base.Init(gameMgr, npcMgr, factionMgr);

            currentTerritoryRatio = 0.0f; //initially set to 0.0f
            //start the expand timer:
            expandTimer = expandReloadRange.getRandomValue();
            //set as active by default:
            isActive = true;

            //listen to delegate events:
            CustomEvents.BorderActivated   += OnBorderActivated;
            CustomEvents.BuildingDestroyed += OnBuildingDestroyed;
        }
        //called to activate the border
        public void ActivateBorder()
        {
            //make sure to get the game manager and resource manager components
            GameMgr     = GameManager.Instance;
            ResourceMgr = GameMgr.ResourceMgr;

            //if the border is not active yet
            if (IsActive == false)
            {
                //shuffle building defs list:
                RTSHelper.ShuffleList <BuildingsInsideBorderVars>(BuildingsInsideBorder);

                //if we're allowed to spawn the border object
                if (SpawnBorderObj == true)
                {
                    //create and spawn it
                    BorderObj = (GameObject)Instantiate(BorderObj, new Vector3(transform.position.x, BorderHeight, transform.position.z), Quaternion.identity);
                    BorderObj.transform.localScale = new Vector3(Size * BorderSizeMultiplier, BorderObj.transform.localScale.y, Size * BorderSizeMultiplier);
                    BorderObj.transform.SetParent(transform, true);

                    //Set the border's color to the faction it belongs to:
                    Color FactionColor = GameMgr.Factions[MainBuilding.FactionID].FactionColor;
                    BorderObj.GetComponent <MeshRenderer>().material.color = new Color(FactionColor.r, FactionColor.g, FactionColor.b, BorderColorTransparency);
                    //Set the border's sorting order:
                    BorderObj.GetComponent <MeshRenderer>().sortingOrder = GameMgr.LastBorderSortingOrder;
                    GameMgr.LastBorderSortingOrder--;
                }


                //Add the border to all borders list:
                GameMgr.AllBorders.Add(this);

                CheckBorderResources(); //check the resources around the border

                IsActive = true;        //mark the border as active

                //Custom Event:
                if (GameMgr.Events)
                {
                    GameMgr.Events.OnBorderActivated(this);
                }
            }

            //set the faction manager
            FactionMgr = GameMgr.Factions[MainBuilding.FactionID].FactionMgr;

            //check the buildings in the border
            CheckBuildingsInBorder();
        }
        /// <summary>
        /// A method that stops the NPC faction from attacking and resets its targets.
        /// </summary>
        public void CancelAttack()
        {
            //send back units:
            npcMgr.GetNPCComp <NPCDefenseManager>().SendBackUnits(currentAttackUnits);

            //clear the current attack units:
            currentAttackUnits.Clear();

            currentTarget = null; //reset the target.

            targetFaction = null;

            //stop attacking:
            IsAttacking = false;
        }
Esempio n. 10
0
        //a method to cancel the attack:
        public void CancelAttack()
        {
            //send back units:
            npcMgr.defenseManager_NPC.SendBackUnits(currentAttackUnits);

            //clear the current attack units:
            currentAttackUnits.Clear();

            currentTargetBuilding = null; //reset the target building.

            targetFaction = null;

            //stop attacking:
            isAttacking = false;
        }
        private bool constructOnDemand = true; //if another NPC component requests the construction of one of a building, is it allowed or not?
        #endregion

        #region Initializing/Terminating
        /// <summary>
        /// Initializes the NPCBuildingConstructor instance, called from the NPCManager instance responsible for this component.
        /// </summary>
        /// <param name="gameMgr">GameManager instance of the current game.</param>
        /// <param name="npcMgr">NPCManager instance that manages this NPCComponent instance.</param>
        /// <param name="factionMgr">FactionManager instance of the faction that this component manages.</param>
        public override void Init(GameManager gameMgr, NPCManager npcMgr, FactionManager factionMgr)
        {
            base.Init(gameMgr, npcMgr, factionMgr);

            //reset construction timer:
            constructionTimer = constructionTimerRange.getRandomValue();

            Activate();

            ActivateBuilderRegulator();

            //add event listeners for following delegate events:
            CustomEvents.BuildingPlaced        += OnBuildingPlaced;
            CustomEvents.BuildingHealthUpdated += OnBuildingHealthUpdated;
        }
Esempio n. 12
0
        bool AllBuilt = false;         //Are all required buildings inside the border built or not?


        public void ActivateBorder()
        {
            GameMgr     = GameManager.Instance;
            ResourceMgr = GameMgr.ResourceMgr;

            if (IsActive == false)
            {
                if (SpawnBorderObj == true)
                {
                    BorderObj = (GameObject)Instantiate(BorderObj, gameObject.transform.position, Quaternion.identity);
                    BorderObj.transform.localScale = new Vector3(Size * BorderObjSizeMultiplier, BorderObj.transform.localScale.y, Size * BorderObjSizeMultiplier);
                    BorderObj.transform.SetParent(transform, true);

                    //Set the border's color to the faction it belongs to:
                    Color FactionColor = GameMgr.Factions [gameObject.GetComponent <Building> ().FactionID].FactionColor;
                    BorderObj.GetComponent <MeshRenderer> ().material.color = FactionColor;
                    //Set the border's sorting order:
                    BorderObj.gameObject.GetComponent <MeshRenderer> ().sortingOrder = GameMgr.LastBorderSortingOrder;
                    GameMgr.LastBorderSortingOrder--;
                }


                //Add the border to all borders list:
                GameMgr.AllBorders.Add(this);

                CheckBorderResources();

                IsActive = true;
            }

            FactionMgr = GameMgr.Factions[gameObject.GetComponent <Building> ().FactionID].FactionMgr;

            if (FactionMgr != null)
            {
                if (FactionMgr.FactionID != GameManager.PlayerFactionID && GameManager.MultiplayerGame == false)
                {
                    Timer = Random.Range(BuildingCheckMinTimer, BuildingCheckMaxTimer);
                }
            }

            //Inform the faction's resource manager that we need to check resource inside the new border:
            if (FactionMgr.ResourceMgr != null)
            {
                FactionMgr.ResourceMgr.CheckResources = true;
            }

            CheckBuildingsInBorder();
        }
Esempio n. 13
0
        //Picking the weakest faction or picking a random target:
        public void PickTargetFaction()
        {
            //if we're not picking the target faction randomly.
            if (RandomlyPickTarget == false)
            {
                //Pick the weakest enemy faction available:
                int TargetID = -1;
                for (int i = 0; i < GameMgr.Factions.Count; i++)
                {
                    if (i != FactionID && GameMgr.Factions [i].Lost == false)
                    {
                        if (TargetID == -1)
                        {
                            TargetID = i;
                        }
                        else
                        {
                            if (GameMgr.Factions [i].FactionMgr.ArmyPower < GameMgr.Factions [TargetID].FactionMgr.ArmyPower)
                            {
                                TargetID = i;
                            }
                        }
                    }
                }

                if (TargetID >= 0)
                {
                    TargetFaction = GameMgr.Factions [TargetID].FactionMgr;
                }
            }
            else
            {
                List <FactionManager> AvailableFactions = new List <FactionManager>();
                for (int i = 0; i < GameMgr.Factions.Count; i++)
                {
                    if (i != FactionID && GameMgr.Factions [i].Lost == false)
                    {
                        AvailableFactions.Add(GameMgr.Factions [i].FactionMgr);
                    }
                }

                //Randomly pick one:
                if (AvailableFactions.Count > 0)
                {
                    TargetFaction = AvailableFactions [Random.Range(0, AvailableFactions.Count)];
                }
            }
        }
Esempio n. 14
0
        //Search for the nearest enemy building center to attack, we will search from the capital of this faction:
        public void SetTargetBuilding()
        {
            //always start the search from the faction capital..
            Vector3 SearchFrom = FactionMgr.BuildingCenters [0].transform.position;

            //unless we've already targeted a building before..
            if (TargetBuilding != null)
            {
                //in that case, start from the last targeted building:
                SearchFrom = LastTargetBuildingPos;
            }
            TargetBuilding = null;

            //make sure the target faction still has a capital building
            if (GameMgr.Factions[TargetFaction.FactionID].CapitalBuilding != null)
            {
                //search for the nearest building to attack.
                TargetBuilding = TargetFaction.BuildingCenters [0];
                float Distance = Vector3.Distance(TargetBuilding.transform.position, SearchFrom);
                if (TargetFaction.Buildings.Count > 1)
                {
                    for (int i = 1; i < TargetFaction.Buildings.Count; i++)
                    {
                        if (TargetFaction.Buildings [i].Placed == true && TargetFaction.Buildings [i].CanBeAttacked == true)
                        {
                            if (Distance > Vector3.Distance(TargetFaction.Buildings [i].transform.position, SearchFrom))
                            {
                                TargetBuilding = TargetFaction.Buildings [i];
                                Distance       = Vector3.Distance(TargetFaction.Buildings [i].transform.position, SearchFrom);
                            }
                        }
                    }
                }

                if (TargetBuilding != null)
                {
                    LastTargetBuildingPos = TargetBuilding.transform.position;
                }
            }
            else
            {
                //If the capital building of the target faction does not exist then
                TargetFaction = null;
                Attacking     = false;

                StopAttack();
            }
        }
Esempio n. 15
0
        private Dictionary <Building, BuildingCenterResources> centerResources = new Dictionary <Building, BuildingCenterResources>(); //resources that belong to this faction...
        //...and which are not being collected will remain in this list with the building centers they belong to.
        #endregion

        #region Initializing/Terminating
        /// <summary>
        /// Initializes the NPCResourceManager instance, called from the NPCManager instance responsible for this component.
        /// </summary>
        /// <param name="gameMgr">GameManager instance of the current game.</param>
        /// <param name="npcMgr">NPCManager instance that manages this NPCComponent instance.</param>
        /// <param name="factionMgr">FactionManager instance of the faction that this component manages.</param>
        public override void Init(GameManager gameMgr, NPCManager npcMgr, FactionManager factionMgr)
        {
            base.Init(gameMgr, npcMgr, factionMgr);

            //set the resource need ratio for the faction:
            gameMgr.ResourceMgr.GetFactionResources(factionMgr.FactionID).UpdateResourceNeedRatio(resourceNeedRatioRange.getRandomValue());

            //start listening to the required delegate events:
            CustomEvents.NPCFactionInit += OnNPCFactionInit;

            Border.BorderResourceAdded     += OnBorderResourceAdded;
            Border.BorderResourceRemoved   += OnBorderResourceRemoved;
            CustomEvents.BorderDeactivated += OnBorderDeactivated;

            CustomEvents.ResourceEmpty += OnResourceEmpty;
        }
Esempio n. 16
0
        //a method that assings a new faction for the unit
        public void AssignFaction(FactionManager factionMgr)
        {
            FactionMgr = factionMgr;                                       //set the new faction
            FactionID  = FactionMgr.FactionID;                             //set the new faction ID
            free       = false;                                            //if this was a free unit then not anymore

            Creator = gameMgr.GetFaction(FactionID).GetCapitalBuilding();  //make the unit's producer, the capital of the new faction

            UpdateFactionColors(gameMgr.GetFaction(FactionID).GetColor()); //set the new faction colors
            selection.UpdateMinimapIconColor();                            //assign the new faction color for the unit in the minimap icon

            if (TaskLauncherComp != null)                                  //if the unit has a task launcher
            {
                TaskLauncherComp.Init(gameMgr, this);                      //update the task launcher info
            }
        }
        /// <summary>
        /// Initializes the NPCArmyCreator instance, called from the NPCManager instance responsible for this component.
        /// </summary>
        /// <param name="gameMgr">GameManager instance of the current game.</param>
        /// <param name="npcMgr">NPCManager instance that manages this NPCComponent instance.</param>
        /// <param name="factionMgr">FactionManager instance of the faction that this component manages.</param>
        public override void Init(GameManager gameMgr, NPCManager npcMgr, FactionManager factionMgr)
        {
            base.Init(gameMgr, npcMgr, factionMgr);

            //only activate if army unit creation is forced.
            if (forceArmyCreation)
            {
                Activate();
            }
            else
            {
                Deactivate();
            }

            ActivateArmyUnitRegulators();
        }
Esempio n. 18
0
 void Start()
 {
     GameMgr = GameManager.Instance;
     //get the faction manager from the unit APC
     if (gameObject.GetComponent <Unit> ())
     {
         FactionMgr  = GameMgr.Factions[gameObject.GetComponent <Unit> ().FactionID].FactionMgr;
         MFactionMgr = GameMgr.Factions[gameObject.GetComponent <Unit> ().FactionID].MFactionMgr;
     }
     //get the faction manager from the building APC.
     else if (gameObject.GetComponent <Building> ())
     {
         FactionMgr  = GameMgr.Factions[gameObject.GetComponent <Building> ().FactionID].FactionMgr;
         MFactionMgr = GameMgr.Factions[gameObject.GetComponent <Building> ().FactionID].MFactionMgr;
     }
 }
Esempio n. 19
0
        public override void Init(GameManager gameMgr, NPCManager npcMgr, FactionManager factionMgr)
        {
            base.Init(gameMgr, npcMgr, factionMgr);

            //initially, this component is active:
            Activate();

            //start the timer:
            timer = timerReloadRange.getRandomValue();

            //start listening to the delegate events
            CustomEvents.TaskLauncherAdded   += OnTaskLauncherAdded;
            CustomEvents.TaskLauncherRemoved += OnTaskLauncherRemoved;
            CustomEvents.BuildingUpgraded    += OnFactionEntityUpgraded;
            CustomEvents.UnitUpgraded        += OnFactionEntityUpgraded;
        }
Esempio n. 20
0
        private Dictionary <string, ActiveUnitRegulator> activeUnitRegulators = new Dictionary <string, ActiveUnitRegulator>(); //holds the active unit regulators
        #endregion

        #region Initiliazing/Terminating
        /// <summary>
        /// Initializes the NPCUnitCreator instance, called from the NPCManager instance responsible for this component.
        /// </summary>
        /// <param name="gameMgr">GameManager instance of the current game.</param>
        /// <param name="npcMgr">NPCManager instance that manages this NPCComponent instance.</param>
        /// <param name="factionMgr">FactionManager instance of the faction that this component manages.</param>
        public override void Init(GameManager gameMgr, NPCManager npcMgr, FactionManager factionMgr)
        {
            base.Init(gameMgr, npcMgr, factionMgr);

            //clear the active unit regulator list per default:
            activeUnitRegulators.Clear();

            //go through the independent units that this component is able to create:
            foreach (Unit unit in independentUnits)
            {
                //for each unit, get the NPCUnitRegulatorData instance that suits the current NPC type and its faction type and attempt to activate it
                ActivateUnitRegulator(unit);
            }

            //subscribe to custom events:
            CustomEvents.UnitUpgraded += OnUnitUpgraded;
        }
Esempio n. 21
0
        void Start()
        {
            GameMgr     = GameManager.Instance;
            UnitMgr     = gameObject.GetComponent <Unit>();
            BuildingMgr = gameObject.GetComponent <Building>();

            //get the faction manager from the unit APC
            if (UnitMgr)
            {
                FactionMgr = GameMgr.Factions[UnitMgr.FactionID].FactionMgr;
            }
            //get the faction manager from the building APC.
            else if (BuildingMgr)
            {
                FactionMgr = GameMgr.Factions[BuildingMgr.FactionID].FactionMgr;
            }
        }
Esempio n. 22
0
        //a method to set a target faction:
        void SetTargetFaction()
        {
            //first get the factions that are not yet defeated in a list:
            List <GameManager.FactionInfo> activeFactions = new List <GameManager.FactionInfo>();

            activeFactions.AddRange(gameMgr.Factions);

            //remove the defeated factions and pick the weakest:
            FactionManager weakestFaction = null;

            int i = 0; //counter

            while (i < activeFactions.Count)
            {
                //if this is the player's faction or faction is already defeated:
                if (activeFactions[i].FactionMgr == factionMgr || activeFactions[i].Lost == true)
                {
                    //remove from list:
                    activeFactions.RemoveAt(i);
                }
                else
                {
                    if (pickWeakestFaction == true) //if we're picking the weakest faction as the target:
                    {
                        //look for weakest faction:
                        if (weakestFaction == null)
                        {
                            weakestFaction = activeFactions[i].FactionMgr;
                        }
                        //if this faction has less army power than the current weakest:
                        else if (weakestFaction.GetCurrentAttackPower() > activeFactions[i].FactionMgr.GetCurrentAttackPower())
                        {
                            //assign new weakest faction:
                            weakestFaction = activeFactions[i].FactionMgr;
                        }
                    }

                    //increment timer:
                    i++;
                }
            }

            //pick weakest faction or random faction:
            targetFaction = (pickWeakestFaction == true) ? weakestFaction : activeFactions[Random.Range(0, activeFactions.Count)].FactionMgr;
        }
        /// <summary>
        /// Initializes the NPCTerritoryManager instance, called from the NPCManager instance responsible for this component.
        /// </summary>
        /// <param name="gameMgr">GameManager instance of the current game.</param>
        /// <param name="npcMgr">NPCManager instance that manages this NPCComponent instance.</param>
        /// <param name="factionMgr">FactionManager instance of the faction that this component manages.</param>
        public override void Init(GameManager gameMgr, NPCManager npcMgr, FactionManager factionMgr)
        {
            base.Init(gameMgr, npcMgr, factionMgr);

            currentTerritoryRatio = 0.0f; //initially set to 0.0f

            //start the expand timers:
            expandDelayTimer = expandDelayRange.getRandomValue();
            expandTimer      = expandReloadRange.getRandomValue();

            Activate();

            //listen to delegate events:
            CustomEvents.NPCFactionInit += OnNPCFactionInit;

            CustomEvents.BorderDeactivated += OnBorderDeactivated;
            CustomEvents.BorderActivated   += OnBorderActivated;
        }
Esempio n. 24
0
        protected virtual void InitItem(NPCManager npcMgr)
        {
            this.npcMgr = npcMgr;
            factionMgr  = npcMgr.FactionMgr;

            //if there are no unit prefabs:
            if (prefabs.Count < 0)
            {
                //stop here and destroy this instance.
                Destroy(this);
                return;
            }

            //pick the rest random settings from the given info.
            maxAmount = maxAmountRange.getRandomValue();
            minAmount = minAmountRange.getRandomValue();

            amount = 0;
        }
        /// <summary>
        /// Set the NPC faction's target faction to the one given in the 'newTarget' parameter
        /// </summary>
        /// <param name="newTarget">The FactionManager instance that manages the new target faction.</param>
        /// <param name="launchAttack">Should the NPC faction instantly launch its attack towards the new faction?</param>
        /// <returns>True if the new target has been successfully set, otherwise false.</returns>
        public bool SetTargetFaction(FactionManager newTarget, bool launchAttack)
        {
            //if the new target faction is invalid, it's already eliminated, it's this faction or already set as the target faction, do nada.
            if (newTarget == null ||
                newTarget == factionMgr ||
                gameMgr.GetFaction(newTarget.FactionID).Lost ||
                newTarget == targetFaction)
            {
                return(false);
            }

            CancelAttack();            //cancel current attack
            targetFaction = newTarget; //set the new target faction.
            if (launchAttack)          //if we're supposed to directly launch an attack, do it
            {
                LaunchAttack();
            }

            return(true);
        }
Esempio n. 26
0
        void Awake()
        {
            GameMgr     = GameManager.Instance;         //get the game manager comp
            ResourceMgr = GameMgr.ResourceMgr;          //get the resource manager comp

            //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.MapMgr == null)
            {
                FactionMgr             = GameMgr.Factions [FactionID].FactionMgr;
                FactionMgr.BuildingMgr = 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());
                }
            }

            //start the buildings check timer (at the end of the timer, the script checks for unbuilt buildings and those who need fixing and sends builders to fix them.
            BuildingsCheckTimer = Random.Range(BuildingsCheckTimeRange.x, BuildingsCheckTimeRange.y);
        }
        private int minFreePopulationSlots = 3; //whenever the free population slots amount is <= this value then this would attempt to place a new population building.
                                                //when set to -1 (or below) there will be no minimum free population slots amount that trigger placing a population building.
        #endregion

        #region Initializing/Terminating
        /// <summary>
        /// Initializes the NPCPopulationManager instance, called from the NPCManager instance responsible for this component.
        /// </summary>
        /// <param name="gameMgr">GameManager instance of the current game.</param>
        /// <param name="npcMgr">NPCManager instance that manages this NPCComponent instance.</param>
        /// <param name="factionMgr">FactionManager instance of the faction that this component manages.</param>
        public override void Init(GameManager gameMgr, NPCManager npcMgr, FactionManager factionMgr)
        {
            base.Init(gameMgr, npcMgr, factionMgr);

            //pick a target population amount:
            targetPopulation = Random.Range(targetPopulationRange.min, targetPopulationRange.max);

            //pending population is null by default:
            pendingPopulationSlots = 0;

            //start the population monitor timer:
            monitorPopulationTimer = monitorPopulationReloadRange.getRandomValue();

            //custom event listeners:
            CustomEvents.MaxPopulationUpdated     += OnPopulationUpdated;
            CustomEvents.CurrentPopulationUpdated += OnPopulationUpdated;

            CustomEvents.BuildingStartPlacement += OnPendingPopulationEnter;
            CustomEvents.BuildingStopPlacement  += OnPendingPopulationExit;
            CustomEvents.BuildingBuilt          += OnPendingPopulationExit;
        }
        /// <summary>
        /// Initializes the NPCTaskManager instance, called from the NPCManager instance responsible for this component.
        /// </summary>
        /// <param name="gameMgr">GameManager instance of the current game.</param>
        /// <param name="npcMgr">NPCManager instance that manages this NPCComponent instance.</param>
        /// <param name="factionMgr">FactionManager instance of the faction that this component manages.</param>
        public override void Init(GameManager gameMgr, NPCManager npcMgr, FactionManager factionMgr)
        {
            base.Init(gameMgr, npcMgr, factionMgr);

            Assert.IsTrue(priorityQueuesAmount >= 1,
                          $"[NPCTaskManager] NPC Faction ID {factionMgr.FactionID} must have at least priority queue");

            Count = 0;
            //create priority queues:
            queues = new NPCTaskQueue[priorityQueuesAmount];
            //initialize each queue
            for (int i = 0; i < priorityQueuesAmount; i++)
            {
                queues[i] = new NPCTaskQueue
                {
                    tasks = new List <NPCTask>()
                }
            }
            ;

            promotionTimer = promotionTimeRange.getRandomValue(); //start the promotion timer
        }
        /// <summary>
        /// NPCRegulator constructor.
        /// </summary>
        /// <param name="data">Holds information regarding how the faction entity type that will be regulated.</param>
        /// <param name="prefab">FactionEntity derived prefab to regulate.</param>
        /// <param name="gameMgr">GameManager instance of the currently active game.</param>
        /// <param name="npcMgr">NPCManager instance that manages the NPC faction to whome the regulator component belongs.</param>
        public NPCRegulator(NPCRegulatorData data, FactionEntity prefab, GameManager gameMgr, NPCManager npcMgr)
        {
            //assign components
            this.gameMgr = gameMgr;
            Assert.IsNotNull(this.gameMgr, "[NPCRegulator] Initializing without a reference to the GameManager instance is not allowed!");

            this.npcMgr = npcMgr;
            Assert.IsNotNull(this.npcMgr, "[NPCRegulator] Initializing without a reference to the faction's NPCManager instance is not allowed!");

            this.factionMgr = npcMgr.FactionMgr;
            Assert.IsNotNull(this.factionMgr, "[NPCRegulator] Initializing without a reference to the faction's FactionManager instance is not allowed!");

            //pick the rest random settings from the given info.
            MaxAmount        = data.GetMaxAmount();
            MinAmount        = data.GetMinAmount();
            MaxPendingAmount = data.GetMaxPendingAmount();

            Count = 0;

            //get the code and category
            Code     = prefab.GetCode();
            Category = prefab.GetCategory();
        }
Esempio n. 30
0
        void Start()
        {
            GameMgr     = GameManager.Instance;
            UnitMgr     = gameObject.GetComponent <Unit>();
            BuildingMgr = gameObject.GetComponent <Building>();

            //get the faction manager from the unit APC
            if (UnitMgr)
            {
                FactionMgr = GameMgr.Factions[UnitMgr.FactionID].FactionMgr;
            }
            //get the faction manager from the building APC.
            else if (BuildingMgr)
            {
                FactionMgr = GameMgr.Factions[BuildingMgr.FactionID].FactionMgr;
            }

            //if there's no interaction pos:
            if (InteractionPos == null)
            {
                InteractionPos = transform; //set the interaction pos as the building's pos
            }
        }