예제 #1
0
 public FindZoneData(FindZoneData oldData, int zone)
 {
     this.dataLocation = oldData.dataLocation;
     this.position     = oldData.position;
     this.range        = oldData.range;
     this.zone         = zone;
 }
예제 #2
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);
    }
예제 #3
0
 public override void OnPlantAddToZone(int zone, ZoneController.DataLocation dataLocation)
 {
     if (stemheight > 0)
     {
         GrowOrgan(0);
     }
 }
예제 #4
0
 public FindZoneData(ZoneController.DataLocation dataLocation, int zone, float3 position, float range)
 {
     this.dataLocation = dataLocation;
     this.position     = position;
     this.range        = range;
     this.zone         = zone;
 }
예제 #5
0
 public override void OnPlantAddToZone(int zone, ZoneController.DataLocation dataLocation)
 {
     if (plantScript.stage == PlantScript.GrowthStage.Seed)
     {
         Spawn();
     }
 }
예제 #6
0
 public override void OnPlantAddToZone(int zone, ZoneController.DataLocation dataLocation)
 {
     if (bladeArea > 0)
     {
         GrowOrgan(0);
     }
 }
예제 #7
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);
    }
예제 #8
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);
    }
예제 #9
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);
    }
예제 #10
0
 public virtual void OnPlantAddToZone(int zone, ZoneController.DataLocation dataLocation)
 {
     return;
 }
예제 #11
0
 public override void RemoveFromZone(int zoneIndex, ZoneController.DataLocation dataLocation)
 {
     GetZoneController().RemoveFoodTypeFromZone(zoneIndex, GetFoodIndex(), dataLocation);
 }
예제 #12
0
 public override void AddToZone(int zoneIndex, ZoneController.DataLocation dataLocation)
 {
     GetZoneController().AddFoodTypeToZone(zoneIndex, GetFoodIndex(), dataLocation);
 }
예제 #13
0
 public override void RemoveFromZone(int zoneIndex, ZoneController.DataLocation dataLocation)
 {
     GetZoneController().RemoveFoodTypeFromZone(zoneIndex, speciesRoots.organFoodIndex, dataLocation);
 }
예제 #14
0
 public override void AddToZone(int zoneIndex, ZoneController.DataLocation dataLocation)
 {
     GetZoneController().AddFoodTypeToZone(zoneIndex, speciesRoots.organFoodIndex, dataLocation);
 }
예제 #15
0
 public virtual void RemoveFromZone(int zoneIndex, ZoneController.DataLocation dataLocation)
 {
     return;
 }
예제 #16
0
 public virtual void AddToZone(int zoneIndex, ZoneController.DataLocation dataLocation)
 {
     return;
 }
예제 #17
0
 public AnimalActions(ActionType actionType, ZoneController.DataLocation dataLocation)
 {
     this.actionType   = actionType;
     this.dataLocation = dataLocation;
 }
예제 #18
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);
    }