Exemplo n.º 1
0
    public bool IsBetterCamp(FSMControler controler)
    {
        Building[] buildings = FindObjectsOfType <Building>();
        Building   target    = controler.target.GetComponent <Building>();
        Citizen    citizen   = controler.GetComponent <Citizen>();

        foreach (RessourceTank rt in controler.GetComponent <RessourceInventory>().ressourcesList)
        {
            foreach (Building building in buildings)

            {
                if (building.tag == "Camp" && building.isPlaced && building.isConstruct)
                {
                    foreach (RessourceTank rT in building.GetComponent <RessourceInventory>().ressourcesList)
                    {
                        if (rT.number >= rt.numberToTransport)
                        {
                            controler.target = building.gameObject;
                            return(true);
                        }
                    }
                }
            }
        }

        return(false);
    }
    private void FindRessource(FSMControler controler)
    {
        Citizen citizen = controler.GetComponent <Citizen>();

        citizen.refreshSoundBools();

        GameObject[] shelterList = GameObject.FindGameObjectsWithTag("Camp");
        controler.target = null;
        if (shelterList.Length > 0)
        {
            foreach (GameObject gO in shelterList)
            {
                if (gO.GetComponent <Building>().isConstruct)
                {
                    Building building = gO.GetComponent <Building>();

                    /*
                     * foreach (RessourceTank rT in controler.GetComponent<Citizen>().ressourcesToTransport.ressourcesList)
                     * {
                     *  if (building.inventory.nbElementsTotal(rT.ressource) > 0)
                     *  {
                     *
                     *      controler.target = gO;
                     */
                    foreach (Tool t in controler.GetComponent <Citizen>().toolsToTransport.toolInventory)
                    {
                        if (building.toolsInventory.nbElementsTotal(t) > 0)
                        {
                            controler.target = gO;
                            return;
                        }
                    }
                }
            }

            //}

            //}

            foreach (GameObject gO in shelterList)
            {
                if (gO.GetComponent <Building>().isConstruct)
                {
                    Building building = gO.GetComponent <Building>();

                    foreach (RessourceTank rT in controler.GetComponent <Citizen>().ressourcesToTransport.ressourcesList)
                    {
                        if (building.inventory.nbElementsTotal(rT.ressource) > 0)
                        {
                            controler.target = gO;
                            return;
                        }
                    }
                }
            }
        }

        controler.target = null;
    }
    public void updateInventory(Building building, FSMControler controler)
    {
        foreach (RessourceTank rt in controler.citizen.ressourcesToTransport.ressourcesList)
        {
            rt.neededToTransport = false;
            rt.numberToTransport = 0;
        }

        foreach (Tool t in controler.citizen.toolsToTransport.toolInventory)
        {
            t.neededToTransport = false;
            t.nbToTransport     = 0;
        }

        if (building.needRessources && building.isPlaced)
        {
            foreach (RessourceTank rt in building.getRessourcesNeeded())
            {
                controler.GetComponent <Citizen>().ressourcesToTransport.add(rt);
            }
            if (building.needTools)
            {
                foreach (Tool t in building.getToolsNeeded())
                {
                    controler.GetComponent <Citizen>().toolsToTransport.add(t);
                }
                return;
            }
            else
            {
                foreach (Tool t in controler.GetComponent <Citizen>().toolsToTransport.toolInventory)
                {
                    t.neededToTransport = false;
                }
            }
        }
        else if (building.needTools && building.isPlaced)
        {
            foreach (Tool t in building.getToolsNeeded())
            {
                controler.GetComponent <Citizen>().toolsToTransport.add(t);
            }
            foreach (RessourceTank rT in controler.GetComponent <Citizen>().ressourcesToTransport.ressourcesList)
            {
                rT.neededToTransport = false;
            }
            return;
        }
    }
    public void give(FSMControler controler)
    {
        Citizen citizen = controler.GetComponent <Citizen>();

        citizen.refreshSoundBools();
        Building target = controler.finalTarget.GetComponent <Building>();

        foreach (RessourceTank rT in citizen.ressourcesToTransport.getRessourcesNeededTransport())
        {
            if (target.needRessources)
            {
                target.take(rT.ressource, citizen);
            }
            else
            {
                break;
            }
        }

        foreach (Tool t in citizen.toolsToTransport.getToolsNeededTransport())
        {
            if (target.needTools)
            {
                target.takeTool(t, citizen);
            }
            else
            {
                break;
            }
        }
    }
    private void FindRessource(FSMControler controler)
    {
        Citizen citizen = controler.GetComponent <Citizen>();

        if (citizen.ressourcesToTransport.ressourcesList.Count != 0)
        {
            citizen.ressourcesToTransport.ressourcesList[0].neededToTransport = true;
            citizen.ressourcesToTransport.ressourcesList[0].numberLimit       = 5;
        }
        citizen.refreshSoundBools();
        GameObject ressourceTank = GameObject.FindGameObjectWithTag("RessourceTank");

        if (controler.manualTarget == null)
        {
            if (ressourceTank)
            {
                controler.target = ressourceTank;
            }
            else
            {
                ressourceTank    = GameObject.FindGameObjectWithTag("Camp");
                controler.target = ressourceTank;
            }
        }
        else
        {
            controler.target = controler.manualTarget;
        }
    }
    public bool bagFull(FSMControler controler)
    {
        int     nbTotal         = 0;
        int     nbTotalPossible = 0;
        Citizen citizen         = controler.GetComponent <Citizen>();

        if (citizen.ressourcesToTransport.ressourcesList.Count == 0)
        {
            return(false);
        }
        foreach (RessourceTank rT in citizen.ressourcesToTransport.ressourcesList)
        {
            nbTotal         += rT.number;
            nbTotalPossible += rT.numberLimit;
        }

        //if(nbTotal >= citizen.citizenSetting.inventorySize)
        if (nbTotal >= nbTotalPossible)
        {
            //controler.target = controler.finalTarget;
            return(true);
        }
        else
        {
            return(false);
        }
    }
Exemplo n.º 7
0
    private bool ResourcesNotGathered(FSMControler controler)
    {
        Building target  = controler.finalTarget.GetComponent <Building>();
        Citizen  citizen = controler.GetComponent <Citizen>();

        foreach (RessourceTank rT in citizen.ressourcesToTransport.getRessourcesNeededTransport())
        {
            //s'il en reste renvoie true
            if (rT.number < rT.numberToTransport && target.needRessources)
            {
                return(true);
            }
        }

        foreach (Tool tool in citizen.toolsToTransport.getToolsNeededTransport())
        {
            //s'il en reste renvoie true
            if (tool.number < 1 && target.needTools)
            {
                return(true);
            }
        }

        return(false);
    }
    public bool HaveEnoughResources(FSMControler controler)
    {
        Citizen citizen = controler.GetComponent <Citizen>();

        citizen.refreshSoundBools();
        if (!controler.target)
        {
            return(false);
        }
        //Camp building = controler.target.gameObject.GetComponent<Camp>();
        //if (!building) return false;

        // L'outil à construire
        Tool tool = controler.target.GetComponent <ToolInventory>().activeTool;

        // La ressource qu'il faut pour le construire
        Ressource ressource = tool.ressourceNeeded;

        // Le nombre de cette ressource qu'il faut
        int nbrRessource = tool.numberRessourcesNeeded;
        // Le nombre de la ressource contenu dans le batiment
        int stockRessource = controler.target.GetComponent <RessourceInventory>().nbElementsTotal(ressource);

        return(stockRessource >= nbrRessource);
    }
Exemplo n.º 9
0
    private void Stop(FSMControler controler)
    {
        Citizen citizen = controler.GetComponent <Citizen>();

        citizen.isWalking = false;
        citizen.GetComponent <FSMControler>().manualTarget = null;
        citizen.GetComponent <FSMControler>().finalTarget  = null;
        controler.agent.isStopped = true;
    }
Exemplo n.º 10
0
    private void Craft(FSMControler controler)
    {
        Citizen citizen = controler.GetComponent <Citizen>();

        citizen.refreshSoundBools();
        citizen.isProductTool = true;

        if (!controler.target)
        {
            return;
        }
        Building building = controler.target.GetComponent <Building>();

        if (!building)
        {
            return;
        }
        Tool tool = building.GetComponent <ToolInventory>().activeTool;

        // TEMPORAIRE. Récupération du 1er outil dispo dans la liste
        //Tool tool = building.toolsStock.Keys.;


        // Regarde le niveau de compétence du villageois
        if (!controler.citizen.competences.ContainsKey(building.nameCompetence))
        {
            controler.citizen.competences[building.nameCompetence] = 1;
        }

        /*
         * //Niveau du citoyen
         * int level = controler.citizen.competences[building.nameCompetence];
         * //Frequence de construction du citoyen
         * float citizenFrequence = building.timeToBuild * bonusLevel(level);
         * //si le temps passé à construire est
         */
        /*if (!building.GetComponent<ToolInventory>().isCrafted())
         * {
         *  building.GetComponent<ToolInventory>().isGettingCrafted();
         * }
         *
         * else
         * {
         *  building.GetComponent<ToolInventory>().addTool();
         *  building.GetComponent<ToolInventory>().add(tool);
         *  for (int i = 0; i < tool.numberRessourcesNeeded; i++)
         *  {
         *      building.GetComponent<RessourceInventory>().remove(tool.ressourceNeeded);
         *  }
         *
         * }*/

        if (!controler.citizen.isCraftingTool && building.inventory.nbElementsTotal(tool.ressourceNeeded) >= tool.numberRessourcesNeeded)
        {
            controler.citizen.product(tool, building);
        }
    }
 private void WalkTowardsTarget(FSMControler controler)
 {
     if (controler.target)
     {
         Citizen citizen = controler.GetComponent <Citizen>();
         citizen.refreshSoundBools();
         citizen.isWalking = true;
         controler.agent.SetDestination(controler.target.transform.position);
     }
 }
Exemplo n.º 12
0
    /* private void Stock(FSMControler controler)
     * {
     *   if (controler.target.GetComponent<Building>() && controler.citizen.ressources.Count != 0)
     *   {
     *       controler.target.GetComponent<Building>().addRessource(controler.citizen.ressources[0], 1);
     *       controler.citizen.ressources.RemoveAt(0);
     *   }
     * }
     */
    private void Stock(FSMControler controler)
    {
        Building target  = controler.citizen.workPlace.GetComponent <Building>();
        Citizen  citizen = controler.GetComponent <Citizen>();

        citizen.refreshSoundBools();
        foreach (RessourceTank rT in citizen.ressourcesToTransport.getRessourcesNeededTransport())
        {
            Text woodText = GameObject.Find("WoodTotal").GetComponent <Text>();
            woodText.text = (int.Parse(woodText.text) - 1).ToString();
            target.take(rT.ressource, citizen);
        }
    }
    public void FindBuildingToDeliver(FSMControler controler)
    {
        Building[] buildings = FindObjectsOfType <Building>();

        Citizen citizen = controler.GetComponent <Citizen>();

        citizen.refreshSoundBools();

        if (controler.manualTarget != null)
        {
            controler.finalTarget = controler.manualTarget;

            return;
        }

        foreach (Building building in buildings)
        {
            if (building.needRessources && building.isPlaced)
            {
                controler.finalTarget = building.gameObject;
                foreach (RessourceTank rt in building.getRessourcesNeeded())
                {
                    controler.GetComponent <Citizen>().ressourcesToTransport.add(rt);
                }
                if (building.needTools)
                {
                    foreach (Tool t in building.getToolsNeeded())
                    {
                        controler.GetComponent <Citizen>().toolsToTransport.add(t);
                    }
                    return;
                }
                else
                {
                    foreach (Tool t in controler.GetComponent <Citizen>().toolsToTransport.toolInventory)
                    {
                        t.neededToTransport = false;
                    }
                }
            }
            else if (building.needTools && building.isPlaced)
            {
                controler.finalTarget = building.gameObject;
                foreach (Tool t in building.getToolsNeeded())
                {
                    controler.GetComponent <Citizen>().toolsToTransport.add(t);
                }
                foreach (RessourceTank rT in controler.GetComponent <Citizen>().ressourcesToTransport.ressourcesList)
                {
                    rT.neededToTransport = false;
                }
                return;
            }
        }
    }
Exemplo n.º 14
0
    private bool ToolsGathered(FSMControler controler)
    {
        //Building target = controler.target.GetComponent<Building>();
        Citizen citizen = controler.GetComponent <Citizen>();

        foreach (Tool t in citizen.toolsToTransport.getToolsNeededTransport())
        {
            //s'il en reste renvoie true
            if (t.number < 1)
            {
                return(false);
            }
        }
        //controler.target = controler.finalTarget;
        return(true);
    }
Exemplo n.º 15
0
    private bool ResourcesGathered(FSMControler controler)
    {
        //Building target = controler.target.GetComponent<Building>();
        Citizen citizen = controler.GetComponent <Citizen>();

        foreach (RessourceTank rT in citizen.ressourcesToTransport.getRessourcesNeededTransport())
        {
            //s'il en reste renvoie true
            if (rT.number < rT.numberToTransport)
            {
                return(false);
            }
        }
        //controler.target = controler.finalTarget;
        return(true);
    }
    public bool HaveEnoughResources(FSMControler controler)
    {
        Citizen citizen = controler.GetComponent <Citizen>();

        citizen.refreshSoundBools();
        if (!controler.target)
        {
            return(false);
        }
        Building building = controler.target.gameObject.GetComponent <Building>();

        if (!building)
        {
            return(false);
        }
        return(building.enoughConstructToBuild);
    }
Exemplo n.º 17
0
    public bool bagEmpty(FSMControler controler)
    {
        int     nbTotal = 0;
        Citizen citizen = controler.GetComponent <Citizen>();

        foreach (RessourceTank rT in citizen.ressourcesToTransport.ressourcesList)
        {
            nbTotal += rT.number;
        }

        if (nbTotal == 0)
        {
            //controler.target = controler.finalTarget;
            return(true);
        }
        else
        {
            return(false);
        }
    }
    public bool bagToolsEmpty(FSMControler controler)
    {
        int     nbTotal = 0;
        Citizen citizen = controler.GetComponent <Citizen>();

        foreach (Tool t in citizen.toolsToTransport.toolInventory)
        {
            nbTotal += t.number;
        }

        if (nbTotal == 0)
        {
            //controler.target = controler.finalTarget;
            return(true);
        }
        else
        {
            return(false);
        }
    }
    public void FindBuilding(FSMControler controler)
    {
        Citizen citizen = controler.GetComponent <Citizen>();

        citizen.refreshSoundBools();
        Building[] buildings = FindObjectsOfType <Building>();
        Citizen[]  citizens  = FindObjectsOfType <Citizen>();

        if (citizen.workPlace != null)
        {
            citizen.workPlace = null;
        }

        foreach (Building building in buildings)

        {
            if (building.tag == "Camp" && building.isPlaced && building.isConstruct)
            {
                foreach (RessourceTank rt in building.GetComponent <RessourceInventory>().ressourcesList)
                {
                    if (rt.number >= 10)
                    {
                        controler.target = building.gameObject;
                        return;
                    }
                }
            }
        }


        foreach (Building building in buildings)
        {
            if (building.tag == "Camp" && building.isPlaced && building.isConstruct)
            {
                controler.target = building.gameObject;
                return;
            }
        }
    }
    private void Build(FSMControler controler)
    {
        Citizen citizen = controler.GetComponent <Citizen>();

        citizen.refreshSoundBools();
        citizen.isBuilding = true;

        if (!controler.target)
        {
            return;
        }
        Building building = controler.target.GetComponent <Building>();

        if (!building)
        {
            return;
        }
        if (building.enoughConstructToBuild && building.enoughToolsToBuild && !building.isConstruct)
        {
            building.construct(controler.citizen);
        }
    }
Exemplo n.º 21
0
    public bool targetFull(FSMControler controler)
    {
        int     nbTotal         = 0;
        int     nbTotalPossible = 0;
        Citizen citizen         = controler.GetComponent <Citizen>();

        if (!controler.target)
        {
            return(false);
        }
        Building building = controler.target.GetComponent <Building>();

        if (!building)
        {
            return(false);
        }
        if (building.inventory.ressourcesList.Count == 0)
        {
            return(false);
        }
        foreach (RessourceTank rT in building.inventory.ressourcesList)
        {
            nbTotal         += rT.number;
            nbTotalPossible += rT.numberLimit;
        }

        //if(nbTotal >= citizen.citizenSetting.inventorySize)
        if (nbTotal >= nbTotalPossible)
        {
            //controler.target = controler.finalTarget;
            citizen.workPlace = null;
            return(true);
        }
        else
        {
            return(false);
        }
    }
    private void GatherResources(FSMControler controler)
    {
        Building target  = controler.target.GetComponent <Building>();
        Citizen  citizen = controler.GetComponent <Citizen>();

        citizen.refreshSoundBools();

        foreach (RessourceTank rT in citizen.ressourcesToTransport.getRessourcesNeededTransport())
        {
            if (rT.number < rT.numberLimit)
            {
                target.give(rT.ressource, citizen);
            }
        }

        foreach (Tool t in citizen.toolsToTransport.getToolsNeededTransport())
        {
            if (t.number < t.numberLimit)
            {
                target.giveTool(t, citizen);
            }
        }
    }
Exemplo n.º 23
0
    public bool ToolInventoryFull(FSMControler controler)
    {
        int     nbTotal         = 0;
        int     nbTotalPossible = 0;
        Citizen citizen         = controler.GetComponent <Citizen>();

        foreach (Tool t in citizen.toolsToTransport.toolInventory)
        {
            nbTotal         += t.number;
            nbTotalPossible += t.numberLimit;
        }

        //if(nbTotal >= citizen.citizenSetting.inventorySize)
        if (nbTotal >= nbTotalPossible)
        {
            //controler.target = controler.finalTarget;
            return(true);
        }
        else
        {
            return(false);
        }
    }
Exemplo n.º 24
0
    private void Recolt(FSMControler controler)
    {
        Citizen citizen = controler.GetComponent <Citizen>();

        citizen.refreshSoundBools();
        citizen.isRecoltWood = true;
        if (!controler.target)
        {
            return;
        }
        NaturalRessource naturalRessource = controler.target.GetComponent <NaturalRessource>();

        if (!naturalRessource)
        {
            return;
        }

        /*// Regarde le niveau de compétence du villageois
         * if (!controler.citizen.competences.ContainsKey(naturalRessource.nameCompetence))
         * {
         *  controler.citizen.competences[naturalRessource.nameCompetence] = 1;
         * }
         * int level = controler.citizen.competences[naturalRessource.nameCompetence];
         * float citizenFrequence = naturalRessource.recoltFrequence * bonusLevel(level);
         * //Debug.Log(1f / citizenFrequence);*/
        if (controler.farmTimer > (1f / naturalRessource.recoltFrequence))
        {
            naturalRessource.Recolt(controler.citizen);
            Text woodText = GameObject.Find("WoodTotal").GetComponent <Text>();
            woodText.text       = (int.Parse(woodText.text) + 1).ToString();
            controler.farmTimer = 0;
        }
        else
        {
            controler.farmTimer += Time.deltaTime;
        }
    }
Exemplo n.º 25
0
    public void FindBuildingNotConstruct(FSMControler controler)
    {
        Citizen citizen = controler.GetComponent <Citizen>();

        citizen.refreshSoundBools();

        Building[] buildings = FindObjectsOfType <Building>();
        Citizen[]  citizens  = FindObjectsOfType <Citizen>();


        if (controler.manualTarget != null)
        {
            controler.target = controler.manualTarget;
            return;
        }

        // S'il y a un transporteur avec une cible, prendre sa cible
        foreach (Citizen cit in citizens)
        {
            if (cit.GetComponent <Citizen>().group.ToString() == "Transport" && cit.GetComponent <FSMControler>().finalTarget != null)
            {
                controler.target = cit.GetComponent <FSMControler>().finalTarget;
                return;
            }
        }

        foreach (Building building in buildings)
        {
            if (!building.isConstruct && building.enoughConstructToBuild && building.enoughToolsToBuild && building.isPlaced)
            {
                controler.target = building.gameObject;
                return;
            }
        }

        foreach (Building building in buildings)
        {
            if (!building.isConstruct && building.enoughConstructToBuild && building.isPlaced)
            {
                controler.target = building.gameObject;
                return;
            }
        }

        foreach (Building building in buildings)
        {
            if (!building.isConstruct && building.enoughToolsToBuild && building.isPlaced)
            {
                controler.target = building.gameObject;
                return;
            }
        }

        foreach (Building building in buildings)
        {
            if (!building.isConstruct && building.isPlaced)
            {
                controler.target = building.gameObject;
                return;
            }
        }
    }