예제 #1
0
 public void register(AnimalAI animal)
 {
     if (!entries.Keys.Contains(animal))
     {
         entries[animal] = new PerceptionEntry(animal, animal.getSpecies() == self.getSpecies());
     }
 }
예제 #2
0
    public Transform findInteractableZone(AnimalAI animal, Interactable.Type type)
    {
        InteractableZone candidate = null;
        int highestCount           = int.MaxValue;
        int currentCount           = 0;

        float            closestDistance = float.MaxValue;
        InteractableZone closestZone     = needsZones[0];

        foreach (InteractableZone zone in needsZones)
        {
            if (zone.hasNeedsInteractable(type))
            {
                currentCount = zone.getAnimalCount(animal.getSpecies());
                if (zone.isAnimalInZone(animal))
                {
                    currentCount--;
                }

                if (currentCount < highestCount)
                {
                    highestCount = currentCount;
                    candidate    = zone;
                }

                float currentDistance = (zone.transform.position - animal.transform.position).magnitude;
                if (currentDistance <= closestDistance)
                {
                    closestDistance = currentDistance;
                    closestZone     = zone;
                }
            }
        }
        if (candidate == null)
        {
            return(closestZone.transform);
        }
        else
        {
            return(candidate.transform);
        }
    }
예제 #3
0
    public Transform findRallyZone(AnimalAI animal)
    {
        InteractableZone candidate = null;
        int bestCount                 = 0;
        int currentCount              = 0;
        int leastOccupiedZone         = int.MaxValue;
        InteractableZone clearestZone = null;

        foreach (InteractableZone zone in rallyZones)
        {
            currentCount = zone.getAnimalCount(animal.getSpecies());
            if (zone.isAnimalInZone(animal))
            {
                currentCount--;
            }

            if (currentCount > bestCount)
            {
                bestCount = currentCount;
                candidate = zone;
            }

            int animalCount = zone.getAllAnimalCount();
            if (animalCount <= leastOccupiedZone)
            {
                leastOccupiedZone = animalCount;
                clearestZone      = zone;
            }
        }

        if (candidate == null)
        {
            return(clearestZone.transform);
        }
        else
        {
            return(candidate.transform);
        }
    }