示例#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);
    }
示例#2
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);
    }
示例#3
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);
    }
示例#4
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);
    }