//Method used by other components to request to collect a certain resource: public void OnResourceCollectionRequest(Resource resource, int targetCollectorsAmount, bool auto, bool force) { if (auto == false && collectOnDemand == false) //if this was requested by another component and we don't allow collection on demand { return; } //making sure the resource is valid and it's not empty if (resource != null && resource.IsEmpty() == false) { //how much collectors is required? int requiredCollectors = targetCollectorsAmount - resource.WorkerMgr.currWorkers; int i = 0; //counter. List <Unit> currentCollectors = collectorRegulatorIns.GetIdleUnitsFirst(); //get the list of the current faction collectors. //while we still need collectors for the building and we haven't gone through all collectors. while (i < currentCollectors.Count && requiredCollectors > 0) { //is the collector currently in idle mode or do we force him to construct this building ? //& make sure it's not already collecting this resource. if (currentCollectors[i] != null && (currentCollectors[i].IsIdle() || force == true) && currentCollectors[i].CollectorComp.GetTarget() != resource) { //send to collect the resource: currentCollectors[i].CollectorComp.SetTarget(resource); //decrement amount of required builders: requiredCollectors--; } i++; } } }
//used to request the NPC Building Constructor to send units to construct this building. public void OnBuildingConstructionRequest(Building building, bool auto, bool force) { if (auto == false && constructOnDemand == false) //if this is a request from another NPC component and this component doesn't allow that. { return; //do not proceed. } //making sure the building is valid: if (building != null) { //making sure the building needs construction: if (building.HealthComp.CurrHealth < building.HealthComp.MaxHealth) { //how much builders does this building can have? int requiredBuilders = GetTargetBuildersAmount(building) - building.WorkerMgr.currWorkers; int i = 0; //counter. List <Unit> currentBuilders = builderRegulatorIns.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() == false) { //send to construct the building: currentBuilders[i].BuilderComp.SetTarget(building); //decrement amount of required builders: requiredBuilders--; } } i++; } } } }