コード例 #1
0
ファイル: AgentGOAP.cs プロジェクト: sondrex76/aitanks
    private void createPerformActionState()
    {
        performActionState = (fsm, obj) => {
            if (!hasActionPlan())
            {
                //Go find new plan and tell the agent it is finished
                fsm.popState();
                fsm.pushState(idleState);
                dataProvider.actionsFinished();
                return;
            }

            AbstractGOAPAction action = currentActions.Peek();
            if (action.isDone())
            {
                //Take action out of action queue
                currentActions.Dequeue();
            }

            if (hasActionPlan())
            {
                //Set action to the action on top of the queue
                action = currentActions.Peek();
                //Check if you need to be in range
                bool inRange = action.requiresInRange() ? action.isInRange() : true;


                if (inRange)
                {
                    //Check if we could perfrom action if not go to idle state and find a new plan
                    bool success = action.perform(obj);
                    if (!success)
                    {
                        fsm.popState();
                        fsm.pushState(idleState);
                        //ABORT
                        dataProvider.planAborted(action);
                    }
                }
                else
                {
                    fsm.pushState(moveToState);
                }
            }
            else
            {
                //I don't have a plan and need to find one
                fsm.popState();
                fsm.pushState(idleState);
                dataProvider.actionsFinished();
            }
        };
    }
コード例 #2
0
ファイル: AgentGOAP.cs プロジェクト: sondrex76/aitanks
    private void createMoveToState()
    {
        moveToState = (fsm, gameObject) => {
            AbstractGOAPAction action = currentActions.Peek();
            if (action.requiresInRange() && action.target == null)
            {
                fsm.popState();
                fsm.popState();
                fsm.pushState(idleState);
                return;
            }

            if (dataProvider.moveAgent(action))
            {
                fsm.popState();
            }
        };
    }