Exemplo n.º 1
0
    public override void UpdateOrganismsBehavior()
    {
        for (int i = 0; i < activeAnimals.Count; i++)
        {
            AnimalScript.AnimalActions animalAction = GetAnimalJobController().animalActions[i];
            AnimalScript animal = animals[activeAnimals[i]];
            switch (animalAction.actionType)
            {
            case AnimalScript.AnimalActions.ActionType.Idle:
                animal.Idle();
                User.Instance.PrintState("SittingStill", speciesDisplayName, 1);
                break;

            case AnimalScript.AnimalActions.ActionType.RunFromPredator:
                BasicOrganismScript targetPredatorOrganism = earth.GetZoneController().GetOrganismFromDataLocation(animalAction.dataLocation);
                if (targetPredatorOrganism.spawned)
                {
                    animal.RunFromOrganism(targetPredatorOrganism);
                    User.Instance.PrintState("PredatorFound", speciesDisplayName, 2);
                    break;
                }
                animal.Explore();
                User.Instance.PrintState("Exploring", speciesDisplayName, 1);
                break;

            case AnimalScript.AnimalActions.ActionType.EatFood:
                if (animalAction.dataLocation.dataType == ZoneController.DataLocation.DataType.Animal)
                {
                    AnimalScript targetAnimal = earth.GetZoneController().GetAnimalFromDataLocation(animalAction.dataLocation);
                    if (targetAnimal.spawned && animal.Eat(targetAnimal))
                    {
                        animal.LookAtPoint(earth.GetZoneController().GetOrganismFromDataLocation(animalAction.dataLocation).position);
                        User.Instance.PrintState("Eating", speciesDisplayName, 2);
                        break;
                    }
                }
                if (animalAction.dataLocation.dataType == ZoneController.DataLocation.DataType.Plant)
                {
                    PlantScript targetPlant = earth.GetZoneController().GetPlantFromDataLocation(animalAction.dataLocation);
                    if (targetPlant.spawned && animal.Eat(targetPlant))
                    {
                        animal.LookAtPoint(earth.GetZoneController().GetOrganismFromDataLocation(animalAction.dataLocation).position);
                        User.Instance.PrintState("Eating", speciesDisplayName, 2);
                        break;
                    }
                }
                animal.Explore();
                User.Instance.PrintState("Exploring", speciesDisplayName, 1);
                break;

            case AnimalScript.AnimalActions.ActionType.GoToFood:
                BasicOrganismScript targetGoToOrganism = earth.GetZoneController().GetOrganismFromDataLocation(animalAction.dataLocation);
                if (targetGoToOrganism.spawned)
                {
                    animal.GoToPoint(targetGoToOrganism.position);
                    User.Instance.PrintState("GoingToFood", speciesDisplayName, 1);
                }
                else
                {
                    animal.Explore();
                    User.Instance.PrintState("Exploring", speciesDisplayName, 1);
                }
                break;

            case AnimalScript.AnimalActions.ActionType.AttemptReproduction:
                if (animal.mate.spawned && animal.GetReproductive().AttemptReproduction())
                {
                    animal.LookAtPoint(animal.mate.position);
                    User.Instance.PrintState("AttemptReproduction", speciesDisplayName, 2);
                }
                else
                {
                    animal.Idle();
                    User.Instance.PrintState("SittingStill", speciesDisplayName, 1);
                }
                break;

            case AnimalScript.AnimalActions.ActionType.AttemptToMate:
                AnimalScript targetMate = earth.GetZoneController().GetAnimalFromDataLocation(animalAction.dataLocation);
                if (targetMate.spawned && animal.AttemptToMate(targetMate))
                {
                    animal.LookAtPoint(targetMate.position);
                    User.Instance.PrintState("FoundMate", speciesDisplayName, 2);
                }
                else
                {
                    animal.Explore();
                    User.Instance.PrintState("Exploring", speciesDisplayName, 1);
                }
                break;

            case AnimalScript.AnimalActions.ActionType.Explore:
                animal.Explore();
                User.Instance.PrintState("Exploring", speciesDisplayName, 1);
                break;
            }
        }
    }
Exemplo n.º 2
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);
    }