Exemple #1
0
    protected void Act()
    {
        switch (currentAction)
        {
        case CreatureAction.Exploring:
            StartMoveToCoord(Environment.GetNextTileWeighted(coord, moveFromCoord));
            break;

        case CreatureAction.GoingToFood:
            if (Coord.AreNeighbours(coord, foodTarget.coord))
            {
                LookAt(foodTarget.coord);
                currentAction = CreatureAction.Eating;
            }
            else
            {
                StartMoveToCoord(path[pathIndex]);
                pathIndex++;
            }
            break;

        case CreatureAction.GoingToWater:
            if (Coord.AreNeighbours(coord, waterTarget))
            {
                LookAt(waterTarget);
                currentAction = CreatureAction.Drinking;
            }
            else
            {
                StartMoveToCoord(path[pathIndex]);
                pathIndex++;
            }
            break;
        }
    }
Exemple #2
0
    protected virtual void ChooseNextAction()
    {
        Surroundings surroundings = Environment.Sense(coord);

        if (surroundings.nearestFoodSource != null)
        {
            currentAction = CreatureAction.GoingToFood;
            foodTarget    = surroundings.nearestFoodSource;
        }

        // If exploring, move to random tile
        if (currentAction == CreatureAction.Exploring)
        {
            StartMoveToCoord(Environment.GetNextTileWeighted(coord, moveFromCoord));
        }
        else if (currentAction == CreatureAction.GoingToFood)
        {
            if (Coord.AreNeighbours(coord, foodTarget.coord))
            {
                currentAction = CreatureAction.Eating;
            }
            else
            {
                StartMoveToCoord(EnvironmentUtility.GetNextInPath(coord.x, coord.y, foodTarget.coord.x, foodTarget.coord.y));
            }
        }
    }
Exemple #3
0
    protected void Act()
    {
        switch (currentAction)
        {
        case CreatureAction.Exploring:
            StartMoveToCoord(Environment.GetNextTileWeighted(coord, moveFromCoord));
            break;

        case CreatureAction.GoingToFood:
            if (Coord.AreNeighbours(coord, foodTarget.coord))
            {
                LookAt(foodTarget.coord);
                currentAction = CreatureAction.Eating;
            }
            else
            {
                StartMoveToCoord(path[pathIndex]);
                pathIndex++;
            }
            break;

        case CreatureAction.GoingToWater:
            if (Coord.AreNeighbours(coord, waterTarget))
            {
                LookAt(waterTarget);
                currentAction = CreatureAction.Drinking;
            }
            else
            {
                StartMoveToCoord(path[pathIndex]);
                pathIndex++;
            }
            break;

        case CreatureAction.SearchingForMate:
            if (Coord.AreNeighbours(coord, mateTarget.coord))
            {
                LookAt(mateTarget.coord);
                if (mateTarget && Math.Abs(mateTarget.lifespan - lifespan) < 0.1 && desire > 0 && mateTarget.desire > 0)
                {
                    desire            = 0;
                    mateTarget.desire = 0;
                    //mateTarget.canReproduce = false;
                    //canReproduce = false;

                    Animal entity = (Animal)Instantiate(prefab);
                    entity.Init(coord);
                    entity.genes = Genes.InheritedGenes(genes, mateTarget.genes);
                    Environment.speciesMaps[entity.species].Add(entity, coord);
                }
            }
            else
            {
                StartMoveToCoord(path[pathIndex]);
                pathIndex++;
            }
            break;
        }
    }
        protected void Act()
        {
            switch (currentAction)
            {
            case CreatureAction.None:
                break;

            case CreatureAction.Exploring:
                StartMoveToCoord(Environments.Environment.GetNextTileWeighted(coord, moveFromCoord));
                break;

            case CreatureAction.GoingToFood:
                if (Coord.AreNeighbours(coord, foodTarget.coord))
                {
                    LookAt(foodTarget.coord);
                    currentAction = CreatureAction.Eating;
                }
                else
                {
                    //StartMoveToCoord (EnvironmentUtility.GetNextInPath (coord.x, coord.y, foodTarget.coord.x, foodTarget.coord.y), true);
                    StartMoveToCoord(path[pathIndex], true);
                    pathIndex++;
                }

                break;

            case CreatureAction.GoingToWater:
                if (Coord.AreNeighbours(coord, waterTarget))
                {
                    LookAt(waterTarget);
                    currentAction = CreatureAction.Drinking;
                }
                else
                {
                    StartMoveToCoord(path[pathIndex], true);
                    pathIndex++;
                }
                break;

            case CreatureAction.Resting:
                break;

            case CreatureAction.Eating:
                break;

            case CreatureAction.Drinking:
                break;

            default:
                Debug.LogException(new ArgumentOutOfRangeException());
                break;
            }
        }
Exemple #5
0
    protected override void Act()
    {
        switch (currentAction)
        {
        case CreatureAction.GoingToMate:
            if (Coord.AreNeighbours(coord, mate.coord))
            {
                if (myHouse != null)
                {
                    LookAt(mate.coord);
                    if (genes.isMale == false)
                    {
                        giveBirth();
                    }
                }
            }
            else
            {
                if (path != null && pathIndex < path.Length)
                {
                    StartMoveToCoord(path[pathIndex]);
                    pathIndex++;
                }
            }
            break;

        case CreatureAction.Building:
            if (Coord.AreNeighbours(coord, buildingPlace))
            {
                LookAt(buildingPlace);
                Building result = build();
                if (result is House)
                {
                    Mate(mate);
                }
                if (result is Barn)
                {
                    currentAction = CreatureAction.WorkingAtFarm;
                    CreatePath(myFarm.coord);
                }
                if (result is Farm)
                {
                    currentAction = CreatureAction.WorkingAtFarm;
                    Barn nearestBarn = Environment.senseBuilding(BuildingTypes.Barn, this, Coord.CoordPenalty) as Barn;

                    if (nearestBarn == null)
                    {
                        currentAction = CreatureAction.Building;
                        buildingPlace = chooseNear(myFarm.coord);
                        buildingOrder = barn;
                        CreatePath(buildingPlace);
                    }
                    else
                    {
                        currentAction = CreatureAction.WorkingAtFarm;
                        CreatePath(myFarm.coord);
                    }
                }
            }
            else
            {
                StartMoveToCoord(path[pathIndex]);
                pathIndex++;
            }
            break;

        case CreatureAction.WorkingAtFarm:
            if (Coord.AreNeighbours(coord, myFarm.coord))
            {
                LookAt(myFarm.coord);
                myFarm.Work();
                if (myFarm.fullness == 1)
                {
                    myFarm.fullness = 0;
                    barnTarget      = Environment.senseBuilding(BuildingTypes.Barn, this, Coord.CoordPenalty) as Barn;
                    if (barnTarget is null)
                    {
                        currentAction = CreatureAction.Building;
                        buildingPlace = chooseNear(myFarm.coord);
                        buildingOrder = barn;
                        CreatePath(buildingPlace);
                    }
                    currentAction = CreatureAction.GoingToBarn;
                    CreatePath(barnTarget.coord);
                }
            }
            else
            {
                StartMoveToCoord(path[pathIndex]);
                pathIndex++;
            }
            break;

        case CreatureAction.GoingToBarn:
            if (Coord.AreNeighbours(coord, barnTarget.coord))
            {
                LookAt(barnTarget.coord);
                barnTarget.restock();
                currentAction = CreatureAction.Resting;
            }
            else
            {
                StartMoveToCoord(path[pathIndex]);
                pathIndex++;
            }
            break;
        }
        base.Act();
    }
Exemple #6
0
    protected virtual void Act()
    {
        switch (currentAction)
        {
        case CreatureAction.RunningAway:
            StartMoveToCoord(Environment.GetNextTileAway(coord, hunter.coord));
            break;

        case CreatureAction.Exploring:
            StartMoveToCoord(Environment.GetNextTileWeighted(coord, moveFromCoord));
            break;

        case CreatureAction.SearchingForMate:
            StartMoveToCoord(Environment.GetNextTileWeighted(coord, moveFromCoord));
            break;

        case CreatureAction.GoingToMate:
            if (Coord.AreNeighbours(coord, mate.coord))
            {
                LookAt(mate.coord);
                if (genes.isMale == false)
                {
                    giveBirth();
                }
            }
            else
            {
                if (path != null && pathIndex < path.Length)
                {
                    StartMoveToCoord(path[pathIndex]);
                    pathIndex++;
                }
            }
            break;

        case CreatureAction.GoingToFood:
            if (Coord.AreNeighbours(coord, foodTarget.coord))
            {
                LookAt(foodTarget.coord);
                currentAction = CreatureAction.Eating;
            }
            else
            {
                StartMoveToCoord(path[pathIndex]);
                pathIndex++;
            }
            break;

        case CreatureAction.GoingToWater:
            if (Coord.AreNeighbours(coord, waterTarget))
            {
                LookAt(waterTarget);
                currentAction = CreatureAction.Drinking;
            }
            else
            {
                StartMoveToCoord(path[pathIndex]);
                pathIndex++;
            }
            break;
        }
    }