コード例 #1
0
        private void InfluenceHarvest()
        {
            if (nearbyAgent)
            {
                ResourceDeposit closestResource      = nearbyAgent.GetAbility <ResourceDeposit>();
                Structure       closestResourceStore = nearbyAgent.GetAbility <Structure>();

                if (closestResource && closestResource.ResourceType == cachedHarvest.HarvestType ||
                    closestResourceStore && nearbyAgent.GetAbility <Structure>().CanStoreResources(cachedAgent.GetAbility <Harvest>().HarvestType))
                {
                    // send harvest command
                    Command harvestCom = new Command(AbilityDataItem.FindInterfacer("Harvest").ListenInputID);
                    harvestCom.Add(new DefaultData(DataType.UShort, nearbyAgent.GlobalID));

                    harvestCom.ControllerID = cachedAgent.Controller.ControllerID;
                    harvestCom.Add(new Influence(cachedAgent));

                    CommandManager.SendCommand(harvestCom);
                }
            }
        }
コード例 #2
0
 public override void DecideWhatToDo()
 {
     base.DecideWhatToDo();
     if (Agent.Tag == AgentTag.Harvester && cachedHarvest.IsFocused)
     {
         //convert to fast list...
         List <RTSAgent> resources = new List <RTSAgent>();
         foreach (RTSAgent nearbyObject in nearbyObjects)
         {
             ResourceDeposit resource = nearbyObject.GetAbility <ResourceDeposit>();
             if (resource && !resource.IsEmpty())
             {
                 resources.Add(nearbyObject);
             }
         }
         RTSAgent nearestObject = WorkManager.FindNearestWorldObjectInListToPosition(resources, transform.position);
         if (nearestObject)
         {
             ResourceDeposit closestResource = nearestObject.GetAbility <ResourceDeposit>();
             // only harvest resources the worker is assigned to
             if (closestResource && closestResource.ResourceType == cachedHarvest.HarvestType)
             {
                 // send harvest command
                 Command harvestCom = new Command(AbilityDataItem.FindInterfacer("Harvest").ListenInputID);
                 harvestCom.Add <DefaultData>(new DefaultData(DataType.UShort, nearestObject.GlobalID));
                 UserInputHelper.SendCommand(harvestCom);
             }
         }
     }
     if (Agent.Tag == AgentTag.Builder && cachedBuild.IsFocused)
     {
         //convert to fast array
         List <RTSAgent> buildings = new List <RTSAgent>();
         foreach (RTSAgent nearbyObject in nearbyObjects)
         {
             if (nearbyObject.GetCommander() != Agent.Controller.Commander)
             {
                 continue;
             }
             RTSAgent nearbyBuilding = nearbyObject.GetComponent <RTSAgent>();
             if (nearbyBuilding && nearbyBuilding.GetAbility <Structure>().UnderConstruction())
             {
                 buildings.Add(nearbyObject);
             }
         }
         RTSAgent nearestObject = WorkManager.FindNearestWorldObjectInListToPosition(buildings, transform.position);
         if (nearestObject)
         {
             RTSAgent closestBuilding = nearestObject.GetComponent <RTSAgent>();
             if (closestBuilding)
             {
                 // send build command
                 Command buildCom = new Command(AbilityDataItem.FindInterfacer("Construct").ListenInputID);
                 buildCom.Add <DefaultData>(new DefaultData(DataType.UShort, closestBuilding.GlobalID));
                 UserInputHelper.SendCommand(buildCom);
             }
         }
         else
         {
             cachedBuild.SetCurrentProject(null);
         }
     }
 }