public QuestObjective(string id, string desc, ObjectiveTypes type, float g)
 {
     identifier    = id;
     objectiveDesc = desc;
     objectiveType = type;
     goal          = g;
 }
Beispiel #2
0
        //Calculates the number of times that objective is required
        public static int getObjectiveOccurances(List <ObjectiveTypes> list, ObjectiveTypes objectiveToCount)
        {
            int count = 0;

            foreach (ObjectiveTypes listObjective in list)
            {
                if (listObjective == objectiveToCount)
                {
                    count++;
                }
            }
            return(count);
        }
Beispiel #3
0
        /**
         * Setup a new objective.
         * */
        public void setupObjective(Vector3 location, ObjectiveTypes type, Vector3 direction = null)
        {
            ObjectiveInfo objInfo = new ObjectiveInfo();

            objInfo.Location = location;
            objInfo.Type     = type;
            objInfo.Progress = 0;
            objectives.Add(objInfo);

            if (direction != null)
            {
                objInfo.Direction = direction;
            }
        }
Beispiel #4
0
        //Checks if the player has meet the requirements for the given objective
        public static bool meetsRequirements(ObjectiveTypes objective)
        {
            int countRequired = getObjectiveOccurances(levelHandler.objectives, objective);

            if (countRequired == 0)
            {
                return(true);
            }
            switch (objective)
            {
            case ObjectiveTypes.FindFood:
                for (int i = 0; i <= countRequired; i++)
                {
                    if (levelHandler.player.HasItem(ItemTypes.Meat, i) &&
                        levelHandler.player.HasItem(ItemTypes.Berries, countRequired - i))
                    {
                        return(true);
                    }
                }
                return(false);

            case ObjectiveTypes.ReturnHome:     //Shouldn't be handled by this, should be handled by the act of entering the village, as it cannot be done without all other objectives being complete
                if (levelHandler.player.hiddenControl.GetType().ToString() == TileOperators.extractControlFromType(TileTypes.Home, Zone.Surface).GetType().ToString())
                {
                    return(true);
                }
                else
                {
                    return(false);
                }

            case ObjectiveTypes.CollectItem:
                Dictionary <ItemTypes, int> countPerItem = new Dictionary <ItemTypes, int>();
                foreach (ItemTypes itemType in levelHandler.itemsToCollect)
                {
                    if (countPerItem.ContainsKey(itemType))
                    {
                        countPerItem[itemType]++;
                    }
                    else
                    {
                        countPerItem.Add(itemType, 1);
                    }
                }

                foreach (ItemTypes itemType in Enum.GetValues(typeof(ItemTypes)))
                {
                    //Check if the item has an entry in the dictionary
                    int val;
                    if (!countPerItem.TryGetValue(itemType, out val))
                    {
                        continue;
                    }
                    if (!levelHandler.player.HasItem(itemType, val))
                    {
                        return(false);
                    }
                }
                return(true);

            case ObjectiveTypes.ObtainRelic:
                if (levelHandler.player.HasItem(ItemTypes.Relic, countRequired))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }

            default:
                return(false);
            }
        }
Beispiel #5
0
    void GenerateNewTask()
    {

        int Pop = 0, ARes = 0, Scout = 0, Hous = 0, Edu = 0,Spec = 0 , Money = 0, Trade = 0, War = 0;
        // first we count the number of objectives already set with specific types, so we dont focus only on one type all the time
        int ObjCap = Mathf.CeilToInt(MaxTasks *0.4f); // maximum of 40% of tasks dedicated to one objective type
        foreach(var obj in CurrentObj)
        {
            if (obj.Type == ObjectiveTypes.GoToWar)
                War++;
            else if (obj.Type == ObjectiveTypes.IncreaseAdvResources)
                ARes++;
            else if (obj.Type == ObjectiveTypes.IncreaseEducation)
                Edu++;
            else if (obj.Type == ObjectiveTypes.IncreaseHousing)
                Hous++;
            else if (obj.Type == ObjectiveTypes.IncreaseMoney)
                Money++;
            else if (obj.Type == ObjectiveTypes.IncreasePopulation)
                Pop++;
            else if (obj.Type == ObjectiveTypes.IncreaseSpecialistBuilding)
                Spec++;
            else if (obj.Type == ObjectiveTypes.ScoutArea)
                Scout++;
            else if (obj.Type == ObjectiveTypes.TradeResources)
                Trade++;
        }
        // now we take stock of what we have, to deciede what we need
        int TotPop = 0, Labs = 0, Rifle = 0, Trader = 0, BlacksP = 0, Mine = 0, Lumber = 0, Carp = 0,
            Turf = 0, House = 0, Scho = 0, Barr = 0, Stora = 0, MineB = 0, Smelt = 0, Quar = 0, Saw = 0, BlacksB = 0, Mark = 0, TotBuild = 0;
        foreach(var villager in Villagers)
        {
            TotPop++; // total population
            if (villager.Skill == Villager.Skills.Labourer)
                Labs++;
            else if (villager.Skill == Villager.Skills.Blacksmith)
                BlacksP++;
            else if (villager.Skill == Villager.Skills.Carpenter)
                Carp++;
            else if (villager.Skill == Villager.Skills.Lumberjack)
                Lumber++;
            else if (villager.Skill == Villager.Skills.Miner)
                Mine++;
            else if (villager.Skill == Villager.Skills.Rifleman)
                Rifle++;
            else if (villager.Skill == Villager.Skills.Trader)
                Trader++;
        }
        foreach(var building in Buildings)
        {
            if (building.Type == Building.BuildingType.Barracks)
                Barr++;
            else if (building.Type == Building.BuildingType.Blacksmith)
                BlacksB++;
            else if (building.Type == Building.BuildingType.House)
                House++;
            else if (building.Type == Building.BuildingType.Market)
                Mark++;
            else if (building.Type == Building.BuildingType.Mine)
                MineB++;
            else if (building.Type == Building.BuildingType.Quarry)
                Quar++;
            else if (building.Type == Building.BuildingType.Sawmill)
                Saw++;
            else if (building.Type == Building.BuildingType.School)
                Scho++;
            else if (building.Type == Building.BuildingType.Smelter)
                Smelt++;
            else if (building.Type == Building.BuildingType.Storage)
                Stora++;
            else if (building.Type == Building.BuildingType.Turf)
                Turf++;
        }
        TotBuild = Barr + BlacksB + House + Mark + MineB + Quar + Saw + Scho + Smelt + Stora + Turf;
        // and finally we take stock of the items
        int stone = 0 , wood = 0 , iron = 0 , timber = 0, ore = 0, coal = 0, axe = 0, cart = 0, RifleI = 0, MoneyI = 0, goods = 0;

        foreach (var villager in Villagers)
        {
            if (villager.Inventory == Villager.Items.Axe)
                axe++;
            else if (villager.Inventory == Villager.Items.Cart)
                cart++;
            else if (villager.Inventory == Villager.Items.Coal)
                coal++;
            else if (villager.Inventory == Villager.Items.Goods)
                goods++;
            else if (villager.Inventory == Villager.Items.Iron)
                iron++;
            else if (villager.Inventory == Villager.Items.Money)
                MoneyI++;
            else if (villager.Inventory == Villager.Items.Ore)
                ore++;
            else if (villager.Inventory == Villager.Items.Rifle)
                RifleI++;
            else if (villager.Inventory == Villager.Items.Stone)
                stone++;
            else if (villager.Inventory == Villager.Items.Timber)
                timber++;
            else if (villager.Inventory == Villager.Items.Wood)
                wood++;
        }
        foreach(var building in Buildings)
        {
            foreach(var item in building.Items)
            {
                if (item == Villager.Items.Axe)
                    axe++;
                else if (item == Villager.Items.Cart)
                    cart++;
                else if (item == Villager.Items.Coal)
                    coal++;
                else if (item == Villager.Items.Goods)
                    goods++;
                else if (item == Villager.Items.Iron)
                    iron++;
                else if (item == Villager.Items.Money)
                    MoneyI++;
                else if (item == Villager.Items.Ore)
                    ore++;
                else if (item == Villager.Items.Rifle)
                    RifleI++;
                else if (item == Villager.Items.Stone)
                    stone++;
                else if (item == Villager.Items.Timber)
                    timber++;
                else if (item == Villager.Items.Wood)
                    wood++;
            }
        }
        //IncreasePopulation, // Chosen when the number of labourers in less than 10 % pop increased untill labourers more than 25%
        //IncreaseAdvResources, // chosen when rifles less than 2 x riflemen
        //ScoutArea, // only active after pop is more than 10 , then activated when ???????? probs not gonna add it
        //IncreaseHousing, // when villagers / 2 less than current number of houses 
        //IncreaseEducation, // when specialists are less than specialist building i.e 0 blacksmith pop but 1 blacksmith
        //IncreaseSpecialistBuilding, // will build specialist buildings, such as blacksmith sawmill
        //IncreaseMoney, // when No of resources is more than 20 x no of villagers
        //TradeResources, // kinda same as above might need rework ... will need rework
        //GoToWar, // not implementing yet
        // now we are ready to gen the task
        // order task are in order of which i believe are important
        // continue to add tasks until the cap is reached
    
        int noneselected = 1; // this var is added to combat infinite loops, will reduce the requirements to activate a task until a task is met
        
        bool NeedTree = false;
        while (CurrentObj.Count < MaxTasks && noneselected < 20 && AvailableVillagers.Count > 0)
        {
            List<Villager.Skills> NeededSkills = new List<Villager.Skills>();
            ObjectiveTypes newObj = new ObjectiveTypes();
            GoalState newGoal = new GoalState();
            newGoal.NewBuildings = Building.BuildingType.None;
            newGoal.NewSkills = new List<Villager.Skills>();
            // Need to add a case for FORCED waiting to breed
            if( TotPop <= Mathf.FloorToInt(TotBuild * 0.75f)&& (House > 0 || Turf > 0)) // Increase Pop
            {

                // we need to gen a current state / decide what is going to be used here.
                newObj = ObjectiveTypes.IncreasePopulation;
                newGoal.AddNewSkills(Villager.Skills.Labourer);
                NeededSkills.Add(Villager.Skills.Any);
                NeededSkills.Add(Villager.Skills.Any);
                Pop++;// this SHOULD continually fail the second check until 2 vills are avaliable
            }
            else if (ARes < ObjCap && BlacksB > 0 && BlacksP > 0) // IncreaseAdvResources -rifles /carts axes
            {
                newObj = ObjectiveTypes.IncreaseAdvResources;
                if(RifleI < Rifle )
                {
                    newGoal.NewItems.Add( Villager.Items.Rifle);
                    ARes++;
                    NeededSkills.Add(Villager.Skills.Blacksmith);
                }
            }
            else if (Turf+House < TotPop/2 && Hous < ObjCap) // IncreaseHousing
            {
                newObj = ObjectiveTypes.IncreaseHousing;
                if(Quar>0) // build house
                {
                    newGoal.NewBuildings = Building.BuildingType.House;
                    var building = GenerateBuildingSite(Building.BuildingType.House);
                    newGoal.Site = building;
                    NeededSkills.Add(Villager.Skills.Labourer);
                    NeededSkills.Add(Villager.Skills.Lumberjack);
                    NeededSkills.Add(Villager.Skills.Carpenter);
                    Buildings.Add(building);
                    Hous++;
                }
                else // build turf
                {
                    newGoal.NewBuildings = Building.BuildingType.Turf;
                    var building = GenerateBuildingSite(Building.BuildingType.Turf);
                    newGoal.Site = building;
                    NeededSkills.Add(Villager.Skills.Labourer);
                    Buildings.Add(building);
                    Hous++;
                }

            }
            else if (Edu < ObjCap) // IncreaseEducation
            {
                newObj = ObjectiveTypes.IncreaseEducation;
                // we want ratios of people
                // 25 % labour
                // 20% lumber
                // 20% miner
                // 20% blacksmith
                // 15% rifle
                if(Lumber < Mathf.CeilToInt(0.2f * TotPop))
                {
                    newGoal.NewSkills.Add(Villager.Skills.Lumberjack);
                    NeededSkills.Add(Villager.Skills.Labourer);
                    NeededSkills.Add(Villager.Skills.Any);
                    Edu++;
                }
                else if (Mine < Mathf.CeilToInt(0.2f * TotPop))
                {
                    newGoal.NewSkills.Add(Villager.Skills.Miner);
                    NeededSkills.Add(Villager.Skills.Labourer);
                    NeededSkills.Add(Villager.Skills.Any);
                    Edu++;
                }
                else if (BlacksP < Mathf.CeilToInt(0.2f * TotPop))
                {
                    newGoal.NewSkills.Add(Villager.Skills.Blacksmith);
                    NeededSkills.Add(Villager.Skills.Labourer);
                    NeededSkills.Add(Villager.Skills.Any);
                    Edu++;
                }
                else if (Rifle < Mathf.CeilToInt(0.15f * TotPop))
                {
                    newGoal.NewSkills.Add(Villager.Skills.Rifleman);
                    NeededSkills.Add(Villager.Skills.Labourer);
                    NeededSkills.Add(Villager.Skills.Any);
                    Edu++;
                }

            }
            else if (Spec < ObjCap) // IncreaseSpecialistBuilding
            {
                newObj = ObjectiveTypes.IncreaseSpecialistBuilding;
                if (Smelt > 0 && Quar > 0)
                {
                    if(Scho == 0) // build school
                    {
                        newGoal.NewBuildings = Building.BuildingType.School;
                        var building = GenerateBuildingSite(Building.BuildingType.School);
                        newGoal.Site = building;
                        NeededSkills.Add(Villager.Skills.Labourer);
                        NeededSkills.Add(Villager.Skills.Lumberjack);
                        NeededSkills.Add(Villager.Skills.Carpenter);
                        Buildings.Add(building);
                        Spec++;
                    }
                    else if (BlacksB <(BlacksP*2)) // build blacksmith
                    {
                        newGoal.NewBuildings = Building.BuildingType.Blacksmith;
                        var building = GenerateBuildingSite(Building.BuildingType.Blacksmith);
                        newGoal.Site = building;
                        NeededSkills.Add(Villager.Skills.Labourer);
                        NeededSkills.Add(Villager.Skills.Miner);
                        Buildings.Add(building);
                        Spec++;
                    }
                    else if(Saw < Mathf.CeilToInt(0.05f*TotPop)) // build sawmill
                    {
                        newGoal.NewBuildings = Building.BuildingType.Sawmill;
                        var building = GenerateBuildingSite(Building.BuildingType.Sawmill);
                        newGoal.Site = building;
                        NeededSkills.Add(Villager.Skills.Labourer);
                        NeededSkills.Add(Villager.Skills.Miner);
                        Buildings.Add(building);
                        Spec++;
                    }
                    else if (Barr < Mathf.CeilToInt(0.05f * TotPop))
                    {
                        newGoal.NewBuildings = Building.BuildingType.Barracks;
                        var building = GenerateBuildingSite(Building.BuildingType.Barracks);
                        newGoal.Site = building;
                        NeededSkills.Add(Villager.Skills.Labourer);
                        NeededSkills.Add(Villager.Skills.Carpenter);
                        NeededSkills.Add(Villager.Skills.Lumberjack);
                        Buildings.Add(building);
                        Spec++;
                    }
                    else if (Stora < Mathf.CeilToInt(0.05f * TotPop))
                    {
                        newGoal.NewBuildings = Building.BuildingType.Storage;
                        var building = GenerateBuildingSite(Building.BuildingType.Storage);
                        NeededSkills.Add(Villager.Skills.Labourer);
                        NeededSkills.Add(Villager.Skills.Carpenter);
                        NeededSkills.Add(Villager.Skills.Lumberjack);
                        newGoal.Site = building;
                        Buildings.Add(building);
                        Spec++;
                    }
                    else if (Mark < Mathf.CeilToInt(0.05f * TotPop))
                    {
                        newGoal.NewBuildings = Building.BuildingType.Market;
                        NeededSkills.Add(Villager.Skills.Carpenter);
                        NeededSkills.Add(Villager.Skills.Lumberjack);
                        var building = GenerateBuildingSite(Building.BuildingType.Market);
                        newGoal.Site = building;
                        Buildings.Add(building);
                        Spec++;
                    }
                }
                else if (Quar > 0) // build smelter
                {
                    newGoal.NewBuildings = Building.BuildingType.Smelter;
                    NeededSkills.Add(Villager.Skills.Labourer);
                    var building = GenerateBuildingSite(Building.BuildingType.Smelter);
                    newGoal.Site = building;
                    Buildings.Add(building);
                    Spec++;
                }
                else // build quarry
                {
                    newGoal.NewBuildings = Building.BuildingType.Quarry;
                    NeededSkills.Add(Villager.Skills.Labourer);
                    var building = GenerateBuildingSite(Building.BuildingType.Quarry);
                    newGoal.Site = building;
                    Buildings.Add(building);
                    Spec++;
                }
            }
            else
                noneselected++;
            if (NeededSkills.Count != 0)
                if (GenerateGameState(NeededSkills, ref newGoal.GameState, NeedTree))
                    PassGoal(newGoal, newObj);
                else noneselected++;

            if (noneselected >= 20)
                return; // no objective set
                
        } 

    }
Beispiel #6
0
 void PassGoal(GoalState goal, ObjectiveTypes Type)
 {
     ObjectiveTasks newTask = new ObjectiveTasks();
     newTask.Type = Type;
     newTask.PathID = -1;
     newTask.TaskID = TaskPlanner.RequestTask(goal);
     newTask.BuildingSite = goal.Site;
     newTask.Stepsneeded = new List<TaskPlanning.Task>();
     Debug.Log("new task created Type : " + Type.ToString());
     CurrentObj.Add(newTask);
 }