示例#1
0
    ZoneController.DataLocation GetClosestBestMouthFood(AnimalScript.AnimalData animalData)
    {
        ZoneController.DataLocation closestBestFood = new ZoneController.DataLocation(ZoneController.DataLocation.DataType.None, -1);
        float      foodDistance      = -1;
        List <int> zonesInMouthRange = ZoneCalculator.GetNearbyZones(zones, neiboringZones, animalData.zone, animalData.animalMouthPosition, speciesEatRange);

        for (int j = 0; j < eddibleFoodTypes.Length; j++)
        {
            for (int i = 0; i < zonesInMouthRange.Count; i++)
            {
                List <ZoneController.DataLocation> foodInZone = ZoneCalculator.GetOrganismsInZoneByFoodType(organismsByFoodTypeInZones, zonesInMouthRange[i], eddibleFoodTypes[j]);
                for (int f = 0; f < foodInZone.Count; f++)
                {
                    if (foodInZone[f].dataType == ZoneController.DataLocation.DataType.Plant)
                    {
                        float mouthDistance = GetDistance(animalData.animalMouthPosition, allPlants[foodInZone[f].dataIndex].position);
                        if (!DistanceInEatRange(mouthDistance))
                        {
                            continue;
                        }
                        if (!(closestBestFood.dataType == ZoneController.DataLocation.DataType.None || mouthDistance < foodDistance))
                        {
                            continue;
                        }
                        closestBestFood = foodInZone[f];
                        foodDistance    = mouthDistance;
                        continue;
                    }
                    if (foodInZone[f].dataType == ZoneController.DataLocation.DataType.Animal)
                    {
                        float mouthDistance = GetDistance(animalData.animalMouthPosition, allAnimals[foodInZone[f].dataIndex].position);
                        if (!DistanceInEatRange(mouthDistance))
                        {
                            continue;
                        }
                        if (!(closestBestFood.dataType == ZoneController.DataLocation.DataType.None || mouthDistance < foodDistance))
                        {
                            continue;
                        }
                        closestBestFood = foodInZone[f];
                        foodDistance    = mouthDistance;
                        continue;
                    }
                }
            }
        }
        return(closestBestFood);
    }
示例#2
0
    FindZoneController.FindZoneData FindNearbyZone(int index)
    {
        List <int> nearbyZones = ZoneCalculator.GetNearbyZones(zones, neiboringZones, findZones[index].zone, findZones[index].position, findZones[index].range);
        float      distance    = GetDistanceBetweenPoints(findZones[index].position, zones[nearbyZones[0]].position);
        int        zoneIndex   = nearbyZones[0];

        for (int i = 1; i < nearbyZones.Count; i++)
        {
            float newDistance = GetDistanceBetweenPoints(findZones[index].position, zones[nearbyZones[i]].position);
            if (newDistance < distance)
            {
                distance  = newDistance;
                zoneIndex = nearbyZones[i];
            }
        }
        return(new FindZoneController.FindZoneData(findZones[index], zoneIndex));
    }
示例#3
0
    public void Execute(int animalIndex)
    {
        AnimalScript.AnimalData animal = allAnimals[updateAnimals[animalIndex]];
        if (animal.zone == -1)
        {
            Debug.LogError("Animal zone was not set. stage: " + animal.stage + " species: " + animal.speciesIndex + " animalIndex: " + animal.animalIndex);
        }
        List <int> zonesInSightRange;

        if (speciesEyeType == EyesScript.EyeTypes.Foward)
        {
            zonesInSightRange = ZoneCalculator.GetNearbyZones(zones, neiboringZones, animal.zone, animal.animalEyePosition.c0, speciesSightRange);
        }
        else
        {
            zonesInSightRange = ZoneCalculator.GetNearbyZonesFromTwoPositions(zones, neiboringZones, animal.zone, animal.animalEyePosition, speciesSightRange);
        }
        ZoneController.DataLocation closestPredator = GetClosestPredator(animal, zonesInSightRange);
        if (closestPredator.dataIndex != -1)
        {
            animalActions[animalIndex] = new AnimalScript.AnimalActions(AnimalScript.AnimalActions.ActionType.RunFromPredator, closestPredator);
            return;
        }

        if (!IsAnimalFull(animal))
        {
            ZoneController.DataLocation closestBestMouthFood = GetClosestBestMouthFood(animal);
            if (closestBestMouthFood.dataType != ZoneController.DataLocation.DataType.None)
            {
                animalActions[animalIndex] = new AnimalScript.AnimalActions(AnimalScript.AnimalActions.ActionType.EatFood, closestBestMouthFood);
                return;
            }

            if (IsAnimalHungry(animal))
            {
                ZoneController.DataLocation closestBestSightFood = GetClosestBestSightFood(animal, zonesInSightRange);
                if (closestBestSightFood.dataType != ZoneController.DataLocation.DataType.None)
                {
                    animalActions[animalIndex] = new AnimalScript.AnimalActions(AnimalScript.AnimalActions.ActionType.GoToFood, closestBestSightFood);
                    return;
                }
            }
        }

        if (!IsAnimalHungry(animal))
        {
            if (IsAnimalMature(animal) && DoesAnimalHaveMate(animal))
            {
                if (AnimalPairReadyToAttemptReproduction(animal))
                {
                    animalActions[animalIndex] = new AnimalScript.AnimalActions(AnimalScript.AnimalActions.ActionType.AttemptReproduction, new ZoneController.DataLocation());
                    return;
                }
            }
            else
            {
                ZoneController.DataLocation closestAvailableMate = GetClosestAvailableMate(animal, zonesInSightRange);
                if (closestAvailableMate.dataType != ZoneController.DataLocation.DataType.None)
                {
                    animalActions[animalIndex] = new AnimalScript.AnimalActions(AnimalScript.AnimalActions.ActionType.AttemptToMate, closestAvailableMate);
                    return;
                }
            }
        }

        if (IsAnimalHungry(animal) || !DoesAnimalHaveMate(animal))
        {
            animalActions[animalIndex] = new AnimalScript.AnimalActions(AnimalScript.AnimalActions.ActionType.Explore);
            return;
        }

        animalActions[animalIndex] = new AnimalScript.AnimalActions(AnimalScript.AnimalActions.ActionType.Idle);
    }