Esempio n. 1
0
 void MainAIControl()
 {
     if (moving == false)
     {
         if (hunger < 50) // Find food if Hungry
         {
             if (inventory == resourceSearch.Food)
             {
                 Eat();
             }
             else if (StockpileScript.food == 0)
             {
                 objFind       = "Bush";
                 currentAction = action.Gather;
                 currentSearch = resourceSearch.Food;
                 moving        = true;
             }
             else
             {
                 currentAction = action.Collect;
                 currentSearch = resourceSearch.Food;
                 MoveToClosestStockpile();
                 moving = true;
             }
         }
         else if (BuildingToConstruct == null)
         {
             SetConstructionBuilding(FindConstruction());
             if (BuildingToConstruct == null)
             {
                 Objective = StockpileObj;
                 GatherStock();
                 moving = true;
             }
         }
         else if (BuildingToConstruct != null)
         {
             BuildConstruct();
             moving = true;
         }
         //else
         //{
         //    currentAction = action.Nothing;
         //    currentSearch = resourceSearch.Nothing;
         //}
     }
     if (moving == true)
     {
         if (Objective != null) //Checks there is objects to find
         {
             //MoveToObject(); //moves to Objective
             if (Destination()) //Checks if AI has reached Objective
             {
                 Interact();
                 moving = false;
             }
         }
     }
 }
Esempio n. 2
0
 void ResetVars()
 {
     currentAction = action.Nothing;
     currentSearch = resourceSearch.Nothing;
     objFind       = "null";
     Objective     = null;
     moving        = false;
 }
Esempio n. 3
0
 void Eat()
 {
     inventory = resourceSearch.Nothing;
     hunger   += 20;
     if (hunger > maxHunger)
     {
         hunger = maxHunger;
     }
 }
Esempio n. 4
0
    void BuildConstruct()
    {
        //Debug.Log("Build Construct");
        BuildingRequirements = BuildingToConstruct.GetComponent <BuildingConstruct>();
        if (inventory != resourceSearch.Wood && inventory != resourceSearch.Stone)
        {
            if (BuildingRequirements.wood > 0)
            {
                //Debug.Log("Jim LOOKS FOR WOOD");
                if (StockpileScript.wood <= 0)
                {
                    //Debug.Log("Jim LOOKS FOR TREES");
                    //Debug.Log("Build Construct: Wood");
                    objFind       = "Tree";
                    currentAction = action.Gather;
                    currentSearch = resourceSearch.Wood;
                }
                else if (StockpileScript.wood > 0)
                {
                    //Debug.Log("Jim LOOKS FOR WOODPILE");
                    currentAction = action.Collect;
                    currentSearch = resourceSearch.Wood;
                }
            }

            else if (BuildingRequirements.stone > 0)
            {
                if (StockpileScript.stone <= 0)
                {
                    //Debug.Log("Build Construct: Stone");
                    objFind       = "Rock";
                    currentAction = action.Gather;
                    currentSearch = resourceSearch.Stone;
                }
                else if (StockpileScript.stone > 0)
                {
                    currentAction = action.Collect;
                    currentSearch = resourceSearch.Stone;
                }
            }
        }
        else if (BuildingToConstruct != null)
        {
            //Debug.Log("Build Construct: Building");
            currentAction = action.Build;
            Objective     = BuildingToConstruct;
        }
        builtSomething = true;
    }
Esempio n. 5
0
    void Interact()
    {
        if (currentAction == action.Gather)
        {
            //Debug.Log("Gather");
            if (Objective.name == "StockpileBuilding")
            {
                //Debug.Log("Interact with Building");
                if (inventory == resourceSearch.Food)
                {
                    StockpileScript.food++;
                }
                else if (inventory == resourceSearch.Wood)
                {
                    StockpileScript.wood++;
                }
                else if (inventory == resourceSearch.Stone)
                {
                    StockpileScript.stone++;
                }
                inventory = resourceSearch.Nothing;
            }
            else
            {
                ResourceControl RCScript = Objective.GetComponent <ResourceControl>();
                if (RCScript != null)
                {
                    RCScript.numberOfResource -= 1;
                    if (Objective.name == "Bush")
                    {
                        inventory = resourceSearch.Food;
                    }
                    else if (Objective.name == "Tree")
                    {
                        inventory = resourceSearch.Wood;
                    }
                    else if (Objective.name == "Rock")
                    {
                        inventory = resourceSearch.Stone;
                    }
                }
            }

            ResetVars();
        }
        if (currentAction == action.Collect)
        {
            //Debug.Log("Collect");
            //Stockpile StockScript = Objective.GetComponent<Stockpile>();
            if (currentSearch == resourceSearch.Food && StockpileScript.food != 0)
            {
                StockpileScript.food -= 1;
                inventory             = resourceSearch.Food;
            }
            else if (currentSearch == resourceSearch.Wood && StockpileScript.wood != 0)
            {
                StockpileScript.wood -= 1;
                inventory             = resourceSearch.Wood;
            }
            else if (currentSearch == resourceSearch.Stone && StockpileScript.stone != 0)
            {
                StockpileScript.stone -= 1;
                inventory              = resourceSearch.Stone;
            }
        }
        if (currentAction == action.Build)
        {
            BuildingConstruct BuildScript = Objective.GetComponent <BuildingConstruct>();
            if (inventory == resourceSearch.Wood)
            {
                if (BuildScript.wood > 0)
                {
                    BuildScript.wood    -= 1;
                    inventory            = resourceSearch.Nothing;
                    BuildingToConstruct  = null;
                    BuildingRequirements = null;
                }
            }
            else if (inventory == resourceSearch.Stone)
            {
                if (BuildScript.stone > 0)
                {
                    BuildScript.stone   -= 1;
                    inventory            = resourceSearch.Nothing;
                    BuildingToConstruct  = null;
                    BuildingRequirements = null;
                }
            }
            else
            {
                currentAction = action.Collect;
            }
        }
        //Debug.Log("Reset Vars");
        //ResetVars();
    }