Пример #1
0
        public virtual void Update()
        {
            switch (_state)
            {
            case AgentState.Planning:
            {
                _actions.Clear();
                GetWorldState(_world);
                GetGoalState(_goal);
                if (Plan(_world, _goal, _actions))
                {
                    _state = AgentState.Picking;
                }
            }
            break;

            case AgentState.Picking:
            {
                if (_actions.Count() > 0)
                {
                    _current = _actions.Dequeue();
                    _state   = AgentState.Performing;
                }
                else
                {
                    _state = AgentState.Completed;
                }
            }
            break;

            case AgentState.Performing:
            {
                if (_current.IsDone())
                {
                    ActionCompleted(_current);
                    _state = AgentState.Picking;
                }
                else if (!_current.Perform())
                {
                    _state = AgentState.Picking;
                }
            }
            break;

            case AgentState.Completed:
            {
                _current = null;
                _state   = AgentState.Planning;
            }
            break;

            case AgentState.Paused:
                break;
            }
        }
Пример #2
0
        List <GOAPAction> ActionSubset(List <GOAPAction> actions, GOAPAction removeMe)
        {
            var subset = new List <GOAPAction>();

            foreach (GOAPAction a in actions)
            {
                if (!a.Equals(removeMe))
                {
                    subset.Add(a);
                }
            }
            return(subset);
        }
Пример #3
0
        // public override void GetGoalState(Dictionary<string, object> goal)
        // {
        //     goal[GOAPAction.Effect.IS_WORKING] = true;
        //     goal[GOAPAction.Effect.IS_HUNGRY] = false;
        //     goal[GOAPAction.Effect.IS_RESTED] = true;
        //     goal[GOAPAction.Effect.IS_WARM] = true;
        //     goal[GOAPAction.Effect.IS_THIRSTY] = false;
        // }

        // public override void GetWorldState(Dictionary<string, object> world)
        // {
        //     /*
        //         Resources
        //     */
        //     foreach(InventorySlot slot in Enum.GetValues(typeof(InventorySlot)))
        //     {
        //         world[GOAPAction.Effect.IS_HOLDING_THING + slot] = _inventory.IsHoldingThing(slot);
        //         world[GOAPAction.Effect.HAS_THING + slot] = _inventory.GetTypeOfThing(slot);

        //     }

        //     world[GOAPAction.Effect.HAS_EDIBLE_THING] = _inventory.IsHoldingSomethingToEat();


        //     /*
        //         Survival
        //     */

        //     world[GOAPAction.Effect.IS_THIRSTY] = _thirst < 0f;
        //     world[GOAPAction.Effect.IS_HUNGRY] = _hunger < 0f;
        //     world[GOAPAction.Effect.IS_RESTED] = _rest > 0f;
        //     world[GOAPAction.Effect.IS_WARM] = !_needs.IsCold();
        //     world[GOAPAction.Effect.IS_WORKING] = false;
        // }

        public override void ActionCompleted(GOAPAction action)
        {
            // if (action.Effects.ContainsKey("isRested") && (bool)action.Effects["isRested"])
            //     _needs.SetRest(0f);

            // thirsty after sleeping
            if (action is Sleep)
            {
                Needs.SetThirst(-1f);
                Needs.SetHunger(-1f);
                Needs.SetRest(0f);
            }

            if (action is DrinkFromStream)
            {
                Needs.SetThirst(0f);
            }

            if (action is EastSomething)
            {
                Needs.SetHunger(0f);
            }
        }
Пример #4
0
 public abstract void ActionCompleted(GOAPAction action);
Пример #5
0
 public void AddAction(GOAPAction action)
 {
     _available.Add(action);
 }
Пример #6
0
 public Node(Node parent, float runningCost, Dictionary <string, object> state, GOAPAction action)
 {
     this.parent      = parent;
     this.runningCost = runningCost;
     this.state       = state;
     this.action      = action;
 }
Пример #7
0
 public override void ActionCompleted(GOAPAction action)
 {
 }
Пример #8
0
 public override abstract void ActionCompleted(GOAPAction action);