Example #1
0
    ZoneController.DataLocation GetClosestPredator(AnimalScript.AnimalData animalData, List <int> zonesInSightRange)
    {
        ZoneController.DataLocation closestPredator = new ZoneController.DataLocation(ZoneController.DataLocation.DataType.None, -1);
        float predatorDistance = -1;

        for (int i = 0; i < zonesInSightRange.Count; i++)
        {
            for (int j = 0; j < predatorFoodTypes.Length; j++)
            {
                List <ZoneController.DataLocation> animalsInZone = ZoneCalculator.GetOrganismsInZoneByFoodType(organismsByFoodTypeInZones, zonesInSightRange[i], predatorFoodTypes[j]);
                for (int f = 0; f < animalsInZone.Count; f++)
                {
                    if (animalsInZone[f].dataType == ZoneController.DataLocation.DataType.Animal)
                    {
                        float directDistance = GetDistance(animalData.position, allAnimals[animalsInZone[f].dataIndex].position);
                        if (!(DistanceInSmellRange(directDistance) || DistanceInSightRange(GetClosestDistanceFromTwoPositions(animalData.animalEyePosition, allAnimals[animalsInZone[f].dataIndex].position))))
                        {
                            continue;
                        }
                        if (closestPredator.dataType == ZoneController.DataLocation.DataType.None || directDistance < predatorDistance)
                        {
                            closestPredator  = animalsInZone[f];
                            predatorDistance = directDistance;
                        }
                    }
                }
            }
        }
        return(closestPredator);
    }
Example #2
0
 bool AnimalPairReadyToAttemptReproduction(AnimalScript.AnimalData animalData)
 {
     if (animalData.animalReproductionReady.x && animalData.animalReproductionReady.y)
     {
         return(true);
     }
     return(false);
 }
Example #3
0
 bool IsAnimalMature(AnimalScript.AnimalData animalData)
 {
     if (animalData.stage == AnimalScript.GrowthStage.Adult)
     {
         return(true);
     }
     return(false);
 }
Example #4
0
 bool IsAnimalHungry(AnimalScript.AnimalData animalData)
 {
     if (animalData.animalFood < speciesFullFood)
     {
         return(true);
     }
     return(false);
 }
Example #5
0
 bool IsAnimalFull(AnimalScript.AnimalData animalData)
 {
     if (animalData.animalFood >= speciesMaxFood * .9f)
     {
         return(true);
     }
     return(false);
 }
Example #6
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);
    }
Example #7
0
    ZoneController.DataLocation GetClosestBestSightFood(AnimalScript.AnimalData animalData, List <int> zonesInSightRange)
    {
        ZoneController.DataLocation closestBestFood = new ZoneController.DataLocation(ZoneController.DataLocation.DataType.None, -1);
        float foodDistance = -1;

        for (int j = 0; j < eddibleFoodTypes.Length; j++)
        {
            for (int i = 0; i < zonesInSightRange.Count; i++)
            {
                List <ZoneController.DataLocation> foodInZone = ZoneCalculator.GetOrganismsInZoneByFoodType(organismsByFoodTypeInZones, zonesInSightRange[i], eddibleFoodTypes[j]);
                for (int f = 0; f < foodInZone.Count; f++)
                {
                    if (foodInZone[f].dataType == ZoneController.DataLocation.DataType.Plant)
                    {
                        float directDistance = GetDistance(animalData.position, allPlants[foodInZone[f].dataIndex].position);
                        if (!(DistanceInSmellRange(directDistance) || DistanceInSightRange(GetEyeDistance(animalData.animalEyePosition, allPlants[foodInZone[f].dataIndex].position))))
                        {
                            continue;
                        }
                        if (!(closestBestFood.dataType == ZoneController.DataLocation.DataType.None || directDistance < foodDistance))
                        {
                            continue;
                        }
                        closestBestFood = foodInZone[f];
                        foodDistance    = directDistance;
                        continue;
                    }
                    if (foodInZone[f].dataType == ZoneController.DataLocation.DataType.Animal)
                    {
                        float directDistance = GetDistance(animalData.position, allAnimals[foodInZone[f].dataIndex].position);
                        if (!(DistanceInSmellRange(directDistance) || DistanceInSightRange(GetEyeDistance(animalData.animalEyePosition, allAnimals[foodInZone[f].dataIndex].position))))
                        {
                            continue;
                        }
                        if (!(closestBestFood.dataType == ZoneController.DataLocation.DataType.None || directDistance < foodDistance))
                        {
                            continue;
                        }
                        closestBestFood = foodInZone[f];
                        foodDistance    = directDistance;
                        continue;
                    }
                }
            }
        }
        return(closestBestFood);
    }
Example #8
0
    ZoneController.DataLocation GetClosestAvailableMate(AnimalScript.AnimalData animalData, List <int> zonesInSightRange)
    {
        ZoneController.DataLocation closestMate = new ZoneController.DataLocation(ZoneController.DataLocation.DataType.None, -1);
        float mateDistance = -1;

        for (int i = 0; i < zonesInSightRange.Count; i++)
        {
            List <ZoneController.DataLocation> organismsInZone = ZoneCalculator.GetOrganismsInZoneByFoodType(organismsByFoodTypeInZones, zonesInSightRange[i], speciesFoodType);
            for (int f = 0; f < organismsInZone.Count; f++)
            {
                if (organismsInZone[f].dataType != ZoneController.DataLocation.DataType.Animal)
                {
                    continue;
                }
                if (allAnimals[organismsInZone[f].dataIndex].speciesIndex != animalData.speciesIndex)
                {
                    continue;
                }
                if (animalData.animalHasMate || allAnimals[organismsInZone[f].dataIndex].animalHasMate)
                {
                    continue;
                }
                if (animalData.animalSex == allAnimals[organismsInZone[f].dataIndex].animalSex)
                {
                    continue;
                }
                float directDistance = GetDistance(animalData.position, allAnimals[organismsInZone[f].dataIndex].position);
                if (!(DistanceInSmellRange(directDistance) || DistanceInSightRange(GetEyeDistance(animalData.animalEyePosition, allAnimals[organismsInZone[f].dataIndex].position))))
                {
                    continue;
                }
                if (!(closestMate.dataType == ZoneController.DataLocation.DataType.None || directDistance < mateDistance))
                {
                    continue;
                }
                closestMate  = organismsInZone[f];
                mateDistance = directDistance;
            }
        }
        return(closestMate);
    }
Example #9
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);
    }
Example #10
0
 bool DoesAnimalHaveMate(AnimalScript.AnimalData animalData)
 {
     return(animalData.animalHasMate);
 }