コード例 #1
0
 //a method ot add/remove a resource instance to the resources to collect list:
 public void UpdateResourcesToCollect(Resource resource, bool add)
 {
     if (add == true) //adding
     {
         //create new instance of the struct:
         ResourceToCollectInfo newResourceToCollect = new ResourceToCollectInfo()
         {
             resource       = resource,
             collectionInfo = GetCollectionInfo(resource.Name)
         };
         //only add this resource type if it is actually supported by this component
         if (newResourceToCollect.collectionInfo != null)
         {
             //add it to the list:
             resourcesToCollect.Add(newResourceToCollect);
         }
     }
     else //removing:
     {
         //go through the list:
         int i = 0;
         while (i < resourcesToCollect.Count)
         {
             //if resource we want to remove is found
             if (resourcesToCollect[i].resource == resource)
             {
                 resourcesToCollect.RemoveAt(i);
                 return;
             }
             i++;
         }
     }
 }
コード例 #2
0
        //get the targe collectors amount:
        public int GetTargetCollectorsAmount(ResourceToCollectInfo rtc)
        {
            //if there's one:
            if (rtc.collectionInfo != null)
            {
                //calculate how much collectors are required:
                int targetCollectors = (int)(rtc.resource.WorkerMgr.WorkerPositions.Length * rtc.collectionInfo.instanceCollectorsRatio.getRandomValue());
                if (targetCollectors <= 0) //can't be lower than one
                {
                    targetCollectors = 1;
                }
                return(targetCollectors);
            }

            return(0); //resource is not regulated by this component, return 0 to send no collectors.
        }