コード例 #1
0
	/// <summary>
	/// compare the fed worldstate to a newly generated one, if they have different enemy data, replan.
	/// </summary>
	/// <param name="_worldState">World state.</param>
	public override bool Sense(GoapPlan _currentPlan, GoapWorldstate _worldState)
	{
		bool changeSensed = false;

		GoapWorldstate oldState = _worldState,
		newState = new GoapWorldstate();

		//generate a new worldstate
		newState.generateWorldState(core.actor);

		//if the enemy data is different, the enemies have changed and a new plan should be forged
		if (CompareEnemyData(oldState.enemyData, newState.enemyData))
		{
			//drop the current target enemy
			core.actor.targetEnemy = null;

			changeSensed = true;
		}

		//push the new worldstate into the core
		core.setWorldState(newState);

		//return the verdict
		return changeSensed;
	}
コード例 #2
0
	/// <summary>
	/// Updates the worldstate.
	/// </summary>
	/// <returns>The new worldstate.</returns>
	private GoapWorldstate UpdateWorldstate ()
	{
		GoapWorldstate newWorldState = new GoapWorldstate();

		newWorldState.generateWorldState (actor);

		return newWorldState;
	}
コード例 #3
0
	private GoapPlan ExecutePlan(GoapPlan _currentPlan, GoapWorldstate _worldState)
	{
		bool actionSuccess = true;

		int currentPlanAction = 0;

		//try to carry out the plan until an action attempt fails (or sensors interrupt)
		while (actor.actionPoints > 0)
		{

			//test all actions up to the current int value for retroactive analysis
			for (int i = 0; i < currentPlanAction; i++)
			{
				if (_currentPlan.actionOrder[i].Test(_worldState))
				{
					currentPlanAction = i;
					break;
				}
			}


			//if the action on the top of the stack needs to be done
			if (_currentPlan.actionOrder[currentPlanAction].Test (_worldState))
			{
				//run sensors
				GoapPlan tempPlan = CheckSensors(_currentPlan, _worldState);

				//if the plans differ
				if (!ComparePlans(_currentPlan, tempPlan))
				{
					return tempPlan;
				}

				//try to carry it out and have it set the result of actionSuccess depending on a success or failure
				actionSuccess = _currentPlan.actionOrder[currentPlanAction].Action(_currentPlan, _worldState);

				if (actionSuccess) //if an action was successfully done,check if it will need to be continued (with a new worldstate)
				{
					_worldState.generateWorldState (actor);

					//if the action no longer needs to be done, pop it from the stack
					if (!_currentPlan.actionOrder[currentPlanAction].Test (_worldState))
					{
						currentPlanAction ++;
					}

					tempPlan = CheckSensors (_currentPlan, getworldState ()); //call sensors as a precaution

					if (!ComparePlans(_currentPlan, tempPlan))
					{
						return tempPlan;
					}
				}
			}
			else//move to the next operation in the plan the plan, as it doesnt need to be carried out
			{
				currentPlanAction++;
			}
		}

		//return the plan now that it has been processed and attempted
		return _currentPlan;
	}