示例#1
0
        /// <summary>
        /// Returns the best suited target for the agent. It could either be a bee or a cell.
        /// </summary>
        /// <returns>The best target.</returns>
        private GameObject FindBestTarget()
        {
            GameObject targetBee         = null;
            GameObject targetCell        = null;
            Vector2    distanceToClosest = Vector2.zero;

            //Since in targets the bees are inserted always before the cells AND (for the moment) bees
            //have a higher priority than the cells, if we find a bee, we stop the search.
            foreach (GameObject entity in targets)
            {
                if (EntityManager.Instance.IsBee(entity))
                {
                    //Choose the bee with less life as target
                    if (targetBee == null)
                    {
                        targetBee = entity;
                    }
                    else if (targetBee.GetComponent <Life>().CurrentLife
                             > entity.GetComponent <Life>().CurrentLife)
                    {
                        targetBee = entity;
                    }
                }
                else
                {
                    //To save time, interrupt the search if a bee is already selected as target (see foreach comment)
                    if (targetBee != null)
                    {
                        return(targetBee);
                    }
                    //Choose the closest cell
                    if (targetCell == null)
                    {
                        //Check if its hive contains resources
                        HiveWarehouse warehouse = entity.GetComponentInParent <HiveWarehouse>();
                        if (warehouse != null && !warehouse.IsEmpty)
                        {
                            targetCell        = entity;
                            distanceToClosest = targetCell.transform.position - owner.transform.position;
                        }
                    }
                    else
                    {
                        Vector2 distanceToCheck = entity.transform.position - owner.transform.position;
                        if (distanceToClosest.sqrMagnitude > distanceToCheck.sqrMagnitude)
                        {
                            //Add as target only if its hive contains some resources
                            HiveWarehouse warehouse = entity.GetComponentInParent <HiveWarehouse>();
                            if (!warehouse.IsEmpty)
                            {
                                targetCell        = entity;
                                distanceToClosest = distanceToCheck;
                            }
                        }
                    }
                }
            }
            if (targetBee != null)
            {
                return(targetBee);
            }
            return(targetCell);
        }
示例#2
0
 public Loot(GameObject agent, GameObject cell) : base(agent, TaskType.Loot)
 {
     this.cell = cell;
     hive      = cell.GetComponentInParent <HiveWarehouse>();
 }
示例#3
0
 public StealResources(GameObject agent, HiveWarehouse hiveWarehouse) : base(agent, TaskType.StealResources)
 {
     warehouse = hiveWarehouse;
     stats     = agent.GetComponent <Stats>();
 }
示例#4
0
 public Deposit(GameObject agent, GameObject targetBeehive) : base(agent, TaskType.Deposit)
 {
     targetHive = targetBeehive.GetComponent <HiveWarehouse>();
     load       = agent.GetComponent <BeeLoad>();
 }