Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        //hunger = ant.getHunger();
        food         = ant.getFood();
        money        = ant.getMoney();
        foodSupplies = home.getFoodSupplies();
        state        = ant.getState();
        // lets check it the number is goin down

        foodText.text         = food.ToString();
        moneyText.text        = money.ToString();
        foodSuppliesText.text = foodSupplies.ToString();
        antStateText.text     = state.ToString();

        currentSalary.text    = salarySlider.value.ToString();
        currentFoodPrice.text = foodPriceSlider.value.ToString();
        currentFoodPack.text  = foodPackSlider.value.ToString();
        Debug.Log("Current Salary: " + salarySlider.value + ", current Food Price: " + foodPriceSlider.value + ", current Food Pack size: " + foodPackSlider.value);

        currentEnergyConsumption.text = energySlider.value.ToString();
    }
Esempio n. 2
0
    // In update happens the main choise making
    // ant has  need for food to stay alive but the supplies will grow short.
    // Ant needs to go to work to gain more money to spend in store in order
    // to fill the suppliment storage and survive

    void Update()
    {
        // First we need a constant reduction of energy
        energyConsumption = UIController.GetEnergyConsumption();
        DecreaseFood(energyConsumption);

        // just to make sure our ant is alive..
        if (food <= 0)
        {
            Debug.Log("Ant died");
            food = 0;
            return;
        }
        else
        {                                                    // since it is..
            if (getFood() < hunger && !satisfiedBoolean)     // if low on food and not satisfied
            {
                hungerBoolean = true;                        // we are hungry
            }
            else if (getFood() > hunger && satisfiedBoolean) // if high on food and satisfied
            {
                hungerBoolean = false;                       // we are not hungry
            }
            if (getFood() > satisfied)                       // if more than enough food
            {
                satisfiedBoolean = true;                     // we are satisfied
            }
            else if (getFood() < satisfied)                  // if not
            {
                satisfiedBoolean = false;                    // we are not satisfied
            }
            if (getMoney() <= 0)                             // if we have no money
            {
                brokeBoolean = true;                         // we are broke
            }
            else if (getMoney() > 0)
            {
                brokeBoolean = false;
            }
            switch (getState())                                 // here happens the choice making
            {
            case 0:
                //idle
                if (hungerBoolean)                                  // if hungry, go home
                {
                    changeState(1);
                }
                if (homeScript.getFoodSupplies() <= 0)              // if there's no food, go buy it
                {
                    changeState(2);
                }
                if (satisfiedBoolean || brokeBoolean)               // if satisfied OR broken, go to work
                {
                    changeState(3);
                }
                break;

            case 1:
                //seek home
                moveTo("home");
                if (homeScript.getFoodSupplies() <= 0)              // if there's no food, go buy it
                {
                    changeState(2);
                }
                else if (satisfiedBoolean || brokeBoolean)          // if satisfied OR broke, go to work
                {
                    changeState(3);
                }
                break;

            case 2:
                //seek store
                moveTo("store");
                if (hungerBoolean && homeScript.getFoodSupplies() >= 5)     // if hungry AND food at home, go home
                {
                    changeState(1);
                }
                else if (brokeBoolean)
                {
                    changeState(3);                                         // if broke, go to work
                }
                break;

            case 3:
                //seek work
                moveTo("work");
                if (hungerBoolean && !brokeBoolean)                         // if hunger BUT NOT broken, go to home
                {
                    changeState(1);
                }
                else if (homeScript.getFoodSupplies() <= 5 && !brokeBoolean && getMoney() >= storeScript.getFoodPrice())
                {
                    changeState(2);                                         // if there's low food at home AND Ant has money
                }                                                           //  AND it has more than enough money
                break;                                                      // to buy food, go to store

            default:
                break;
            }
        }
    }