/// <summary>
 /// Called to request for the NPC faction to expand its territory by creating a new center building.
 /// </summary>
 /// <param name="auto">True if the call was made by the NPCTerritoryManager instance, otherwise false.</param>
 public void OnExpandRequest(bool auto)
 {
     //if this has been requested by another NPC component yet it's not allowed:
     if (auto == false && expandOnDemand == false)
     {
         return; //do not proceed.
     }
     //request building creator to create new instance:
     npcMgr.GetNPCComp <NPCBuildingCreator>().OnCreateBuildingRequest(
         centerMonitor.GetRandomCode(),
         false,
         npcMgr.GetNPCComp <NPCBuildingCreator>().GetCapitalBuildingRegualtor().buildingCenter);
 }
        /// <summary>
        /// Requests to place a new popultion building if all requirements are met.
        /// </summary>
        /// <param name="auto">True if the request is coming from the NPCPopulationManager instance.</param>
        /// <returns>True if the request is accepted by the NPCBuildingCreator instance, otherwise false.</returns>
        public bool OnAddPopulationRequest(bool auto)
        {
            //if this request has been made by another NPC component but it can't be accepted...
            if (!auto && !populationOnDemand.CanAccept()
                //or the NPC faction already reached its target population slots amount
                || factionMgr.Slot.GetMaxPopulation() >= targetPopulation)
            {
                return(false);
            }

            //attempt to add population building
            return(npcMgr.GetNPCComp <NPCBuildingCreator>().OnCreateBuildingRequest(
                       populationBuildingsMonitor.GetRandomCode(), //choose a random population building
                       false,                                      //request is coming from outside the NPCBuildingCreator instance component
                       null));                                     //building center hasn't been specified
        }
        /// <summary>
        /// Called to request the NPCBuildingConstructor instance to send builders to construct a building.
        /// </summary>
        /// <param name="building">The Building instance to construct.</param>
        /// <param name="auto">True if the request is coming from the actual NPCBuildingConstructor instance.</param>
        /// <param name="force">True if the building's construction is urged.</param>
        public void OnBuildingConstructionRequest(Building building, bool auto, bool force)
        {
            if (building == null || //if the building instance is not valid
                building.HealthComp.CurrHealth >= building.HealthComp.MaxHealth || //or if the building has enough health points
                (!force && auto == false && constructOnDemand == false)) //or if this is a request from another NPC component and this component doesn't allow that.
            {
                return;                                                  //do not proceed.
            }
            //how much builders does this building can have?
            int requiredBuilders = GetTargetBuildersAmount(building) - building.WorkerMgr.currWorkers;

            int         i = 0;                                                                                                                             //counter.
            List <Unit> currentBuilders = npcMgr.GetNPCComp <NPCUnitCreator>().GetActiveUnitRegulator(builderMonitor.GetRandomCode()).GetIdleUnitsFirst(); //get the list of the current faction builders.

            //while we still need builders for the building and we haven't gone through all builders.
            while (i < currentBuilders.Count && requiredBuilders > 0)
            {
                //making sure the builder is valid:
                if (currentBuilders[i] != null)
                {
                    //is the builder currently in idle mode or do we force him to construct this building?
                    //& make sure it's not already constructing a building.
                    if ((currentBuilders[i].IsIdle() || force == true) && !currentBuilders[i].BuilderComp.IsActive())
                    {
                        //send to construct the building:
                        currentBuilders[i].BuilderComp.SetTarget(building);
                        //decrement amount of required builders:
                        requiredBuilders--;
                    }
                }

                i++;
            }
        }