Exemple #1
0
        //TODO modify this to look over the list of the top actions for each objective not just the best action
        public void ChooseNewActions()
        {
            List <Objective> objectives = brain.GetSortedObjectives(this);

            if (objectives.Count == 0)
            {
                Debug.Break();
            }
            while (HasAvailableResources() && HasDoableActions())
            {
                foreach (var objective in objectives)
                {
                    if (action2Objective.ContainsValue(objective))
                    {
                        continue;
                    }
                    EventComponent action = GetBestDoableAction(objective);
                    if (action != null)
                    {
                        if (action is PickUpEvent)
                        {
                            Math.Sqrt(2);
                        }
                        if (action is MoveEvent && objective is FullySpecifiedObjective)
                        {
                            FullySpecifiedObjective fso = (FullySpecifiedObjective)objective;
                            if (fso.wayToDoObjective is PickUpEvent)
                            {
                                Math.Sqrt(2);
                            }
                        }
                        action2Objective.Add(action, objective);
                        AllocateResources(action);
                    }
                    else
                    {
                        Debug.Log("No best doable action");
                        Debug.Break();
                    }
                }
            }
        }
Exemple #2
0
        public override List <Objective> GetSortedObjectives(BehaviorComponent agentComponent)
        {
            if (objectives.Count == 0)
            {
                List <PositionComponent> foods = ProceduralWorldSimulator.instance.foods;
                // AI goes here.
                //*
                if (UnityEngine.Random.value > .1f)
                {
                    // Building.
                    objectives.Add(new BuildObjective(agentComponent, new Vector2(UnityEngine.Random.Range(-10, 10), UnityEngine.Random.Range(-10, 10))));
                    Debug.Log("Starting objective to build something");
                }
                else if (UnityEngine.Random.value > .5)
                {
                    // Inventory.
                    InventoryComponent inventoryComponent = GetEntity().GetComponent <InventoryComponent> ();
                    if (!inventoryComponent.haulingSlot.IsFree())
                    {
                        // Drop it.
                        objectives.Add(new FullySpecifiedObjective(new DropEvent(inventoryComponent, inventoryComponent.haulingSlot, inventoryComponent.GetEntity().GetComponent <UnityMeshComponent> ())));
                        Debug.Log("Starting objective to drop hauled item");
                    }
                    else
                    {
                        // Pick something up.
                        if (foods.Count == 0)
                        {
                            return(new List <Objective> ());
                        }
                        var targetFood = foods [UnityEngine.Random.Range(0, foods.Count - 1)];
                        if (targetFood.GetEntity().GetComponent <CarriableComponent> ().carrier == null)
                        {
                            Debug.Log("Starting objective to pick up food at " + targetFood.position);
                            objectives.Add(new FullySpecifiedObjective(new PickUpEvent(inventoryComponent, targetFood.GetEntity().GetComponent <CarriableComponent> (), inventoryComponent.GetEntity().GetComponent <UnityMeshComponent> ())));
                        }
                    }
                }
                else
                {
                    // Eating.
                    if (foods.Count == 0)
                    {
                        return(new List <Objective> ());
                    }
                    var targetFood = foods [UnityEngine.Random.Range(0, foods.Count - 1)];
                    Debug.Log("Starting objective to eat food at " + targetFood.position);
                    objectives.Add(new FullySpecifiedObjective(new EatEvent(GetEntity(), targetFood)));
                }                //*/
                if (objectives.Count == 0)
                {
                    Debug.Log("No objectives!!!");
                }
            }
            else
            {
                Objective obj = objectives [0];
                if (obj is FullySpecifiedObjective)
                {
                    FullySpecifiedObjective fso = (FullySpecifiedObjective)obj;
                    if (fso.wayToDoObjective is PickUpEvent)
                    {
                        Math.Sqrt(2);
                    }
                }
                Math.Sqrt(2);
            }

            return(objectives);
        }