void IStrategizer::GatherResourceAction::HandleMessage( RtsGame* pRtsGame, Message* p_msg, bool& p_consumed )
{
	if(PlanStepEx::State() == ESTATE_Executing && p_msg->MessageTypeID() == MSG_EntityDestroy)
	{
		EntityDestroyMessage*	pMsg = static_cast<EntityDestroyMessage*>(p_msg);
		TID resourceId;

		if (pMsg->Data()->OwnerId != PLAYER_Neutral)
			return;

		assert(pMsg && pMsg->Data());
		resourceId = pMsg->Data()->EntityId;

		if (resourceId != _resourceId)
			return;

		// Resource being gathered is destroyed, so adapt a new resource and gather it
		AbstractAdapter*	pAdapter = g_OnlineCaseBasedPlanner->Reasoner()->Adapter();		
		ResourceType		resourceType = (ResourceType)_params[PARAM_ResourceId];
		assert(pAdapter);

		_resourceId = pAdapter->AdaptResourceForGathering(resourceType, Parameters());

		if(_resourceId != INVALID_TID)
		{
			GameEntity* pGameGatherer = g_Game->Self()->GetEntity(_gathererId);
			GameEntity* pGameResource = g_Game->GetPlayer(PLAYER_Neutral)->GetEntity(_resourceId);
			assert(pGameGatherer);
			assert(pGameResource);

			if (pGameGatherer->GatherResourceEntity(_resourceId))
			{
				_gatherIssued = true;
				pGameGatherer->Lock(this);
			}
		}
	}
}
bool IStrategizer::GatherResourceAction::ExecuteAux(RtsGame* pRtsGame, const WorldClock& p_clock )
{
	EntityClassType		gathererType = (EntityClassType)_params[PARAM_EntityClassId];
	ResourceType		resourceType;
	AbstractAdapter*	pAdapter = g_OnlineCaseBasedPlanner->Reasoner()->Adapter();
	bool				bOK = false;

	// Adapt gatherer
	_gathererId = pAdapter->GetEntityObjectId(gathererType, AdapterEx::WorkerStatesRankVector);

	if(_gathererId != INVALID_TID)
	{
		resourceType = (ResourceType)_params[PARAM_ResourceId];

		// Initialize gather state
		_gatherStarted = false;

		// Adapt resource id
		assert(pAdapter);
		_resourceId = pAdapter->AdaptResourceForGathering(resourceType, Parameters());
		if(_resourceId != INVALID_TID)
		{
			GameEntity* pGameGatherer = g_Game->Self()->GetEntity(_gathererId);
			GameEntity* pGameResource = g_Game->GetPlayer(PLAYER_Neutral)->GetEntity(_resourceId);
			assert(pGameGatherer);
			assert(pGameResource);
			bOK = pGameGatherer->GatherResourceEntity(_resourceId);

			if (bOK)
			{
				_gatherIssued = true;
				pGameGatherer->Lock(this);
			}
		}
	}

	return bOK;
}