// Update is called once per frame
 void Update()
 {
     if (umc == null)
     {
         umc = GetComponent <UnityMeshComponent> ();
     }
     if (umc == null)
     {
         return;
     }
     entity = umc.GetEntity();
     if (entity == null)
     {
         return;
     }
     ac = entity.GetComponent <BehaviorComponent> ();
     if (ac == null)
     {
         return;
     }
     currentBehavior = "";            //TODO get entity name component
     targets.Clear();
     foreach (var entry in ac.action2Objective)
     {
         currentBehavior += "Performing " + entry.Key.ToString() + " pursuant of " + entry.Value.ToString() + System.Environment.NewLine;
         if (entry.Key.DbgGetTarget() != null)
         {
             targets.Add(entry.Key.DbgGetTarget());
         }
     }
 }
 public BuildObjective(BehaviorComponent builder, Vector2 pos)
 {
     this.builder = builder;
     this.pos     = pos;
     // TODO pass in the type of building.
     buildableComponent = new BuildableComponent();
 }
Example #3
0
 public virtual List <Objective> GetSortedObjectives(BehaviorComponent agentComponent)
 {
     //TODO modify the algorithm so instead of just using the sorted objectives we have an objective priority queue
     //the order of which we modify as we elaborate on the queue
     //the idea is to greedily expand our options and then adjust rank based on certainty and expected outcome given
     //prediction of the actions other entities will take toward us and potentially the other thigns we are attentive to
     //we can then keep track of utility as well as uncertainty and cache the results for next update
     //if we compute a hash from what we checked at each step we can even check any values changed so we don't need to recompute
     //we can then update until we hit an expanded option and start assigning resources and bail once all resources are assigned
     //or we get to the bottom of the list (idle can always be an action)
     return(objectives);
 }
Example #4
0
 public MoveEvent(IPathfindingInterface pc, BehaviorComponent mover, Vector2 desiredPosition, float moveSpeed)
 {
     this.pc            = pc;
     this.mover         = mover;
     this.moverPosition = mover.GetEntity().GetComponent <PositionComponent> ();
     if (float.IsNaN(desiredPosition.x))
     {
         Debug.Log("SUPER UNCOOL");
     }
     this.desiredPosition = desiredPosition;
     this.moveSpeed       = moveSpeed;
     this.maxDist         = Vector2.Distance(desiredPosition, moverPosition.position);
 }
Example #5
0
        private void SetupWorld()
        {
            //TODO initialize the view first...
            int numPeople = 5;
            int mapSize   = 50;
            int numFoods  = 20;

            for (int i = 0; i < numFoods; ++i)
            {
                Vector2 pos = positionManager.closestEmpty(new Vector3(UnityEngine.Random.value * mapSize, 0f, UnityEngine.Random.value * mapSize));
                if (PositionManager.IsBogus(pos))
                {
                    continue;
                }
                Entity            food     = new Entity();
                PositionComponent position = new PositionComponent();
                position.position = pos;
                food.AddComponent(position);
                foods.Add(position);
                PlantComponent plant = new PlantComponent();
                food.AddComponent(plant);
                food.AddComponent(new CarriableComponent());
                positionManager.ObjectSpawnedAt(food, pos);
                UnityView.AddEntity(food);
            }
            for (int i = 0; i < numPeople; ++i)
            {
                Vector2 pos = positionManager.closestEmpty(new Vector3(UnityEngine.Random.value * mapSize, 0f, UnityEngine.Random.value * mapSize));
                if (PositionManager.IsBogus(pos))
                {
                    continue;
                }
                Entity            person   = new Entity();
                PositionComponent position = new PositionComponent();
                position.position = pos;
                person.AddComponent(position);
                HumanoidAI brain = new HumanoidAI();
                person.AddComponent(brain);
                BehaviorComponent agent = new BehaviorComponent(brain);
                agent.name = GetRandomName();
                person.AddComponent(agent);
                person.AddComponent(new InventoryComponent());
                positionManager.ObjectSpawnedAt(person, pos);
                UnityView.AddEntity(person);
                UnityView.RegisterControllableAgent(person);
            }
        }
 public CreateFoundationEvent(BehaviorComponent builder, BuildableComponent building, Vector2 pos)
 {
     this.builder  = builder;
     this.building = building;
     this.pos      = pos;
 }
 public DoBuildingWorkEvent(BehaviorComponent builder, BuildableComponent building)
 {
     this.builder  = builder;
     this.building = building;
 }
 public AddResourceEvent(BehaviorComponent builder, BuildableComponent building, BuildingResource resource)
 {
     this.builder  = builder;
     this.building = building;
     this.resource = resource;
 }
Example #9
0
 public EatEvent(IEntity eater, PositionComponent food)
 {
     this.eater = eater.GetComponent <BehaviorComponent>();
     this.food  = food;
     this.plant = food.GetEntity().GetComponent <PlantComponent> ();
 }
Example #10
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);
        }