bool CMissionParser::solveTextsParams(uint32 lineNum, TVectorParamCheck & txtParams, CMissionSpecificParsingData & missionData  )
{
	if (  txtParams.empty() )
		return true;
	std::vector< std::pair< std::string, STRING_MANAGER::TParamType> > & paramTypes = missionData.ChatParams;
	bool ret = true;
	for ( uint i = 0; i < txtParams.size(); i++ )
	{
		std::map< std::string, uint >::iterator itInt = missionData.Integers.find( txtParams[i].Identifier );
		if ( itInt != missionData.Integers.end() )
		{
			txtParams[i].Identifier.clear();
			txtParams[i].Type = STRING_MANAGER::integer;
			txtParams[i].Int = (*itInt).second;
		}
		// if it is a bot name param
		else if ( txtParams[i].Identifier.size() > 2 && txtParams[i].Identifier[0] =='\"' &&  txtParams[i].Identifier[ txtParams[i].Identifier.size() - 1] =='\"' )
		{
			// remove quotes
			txtParams[i].Identifier.erase(txtParams[i].Identifier.begin());
			//txtParams[i].Identifier.pop_back();
			txtParams[i].Identifier.resize(txtParams[i].Identifier.size()-1);
			txtParams[i].Type = STRING_MANAGER::bot_name;
		}
		else
		{
			uint j = 0;
			for (; j < paramTypes.size(); j++ )
			{
				if ( txtParams[i].Identifier == paramTypes[j].first )
				{
					txtParams[i].Identifier.clear();
					if ( !fillTextParam( txtParams[i],paramTypes[j].first,paramTypes[j].second ) )
					{
						MISLOG("<MISSIONS> at line %u: param '%s' could not be parsed", lineNum, paramTypes[j].first.c_str());
						ret = false;
					}
					break;
				}
			}
			if ( j == paramTypes.size() )
			{
				txtParams[i].Type = STRING_MANAGER::integer;
				NLMISC::fromString( txtParams[i].Identifier, txtParams[i].Int);
				if ( txtParams[i].Int == 0 && txtParams[i].Identifier != "0" )
				{
					MISLOG("<MISSIONS> at line %u: param '%s' has an unknown type", lineNum, txtParams[i].Identifier.c_str());
					ret = false;
				}
				txtParams[i].Identifier.clear();
			}
		}
	}
	return ret;
}// CMissionTemplate::solveTextsParams
void CMissionParser::solvePlayerName( TVectorParamCheck & params , const TDataSetRow & playerRow )
{
	CCharacter * user = PlayerManager.getChar(playerRow);
	if( !user )
	{
		nlwarning("<CMissionParser solvePlayerName>Invalid user %u",playerRow.getIndex());
		return;
	}
	for ( uint i = 0; i< params.size(); i++)
	{
		if ( params[i].Type == STRING_MANAGER::player  )
		{
			params[i].setEIdAIAlias( user->getId(), CAIAliasTranslator::getInstance()->getAIAlias(user->getId()) );
		}
	}
}
void CMissionParser::solveEntitiesNames( TVectorParamCheck & params , const TDataSetRow & playerRow,const NLMISC::CEntityId& giver )
{
	CCharacter * user = PlayerManager.getChar(playerRow);
	if( !user )
	{
		nlwarning("<CMissionParser solveEntitiesNames>Invalid user %u",playerRow.getIndex());
		return;
	}
	for ( uint i = 0; i< params.size(); i++)
	{
		if ( params[i].Type == STRING_MANAGER::player  )
		{
			params[i].setEIdAIAlias( user->getId(), CAIAliasTranslator::getInstance()->getAIAlias(user->getId()) );
		}
		else if ( params[i].Type == STRING_MANAGER::bot  )
		{
			if ( params[i].getEId() == NLMISC::CEntityId::Unknown )
			{
				if ( params[i].Identifier == "giver" )
				{
					params[i].setEIdAIAlias( giver, CAIAliasTranslator::getInstance()->getAIAlias(giver) );
				}
				else
				{
					params[i].setEIdAIAlias( CAIAliasTranslator::getInstance()->getEntityId( params[i].Int ), params[i].Int );
				}
			}
		}
		else if ( params[i].Type == STRING_MANAGER::string_id && params[i].Identifier == "$guild_name$" )
		{
			// resolve the player guild name
			/// todo guild mission
			/*
			CGuild *g = user->getGuild();
			if (g == NULL)
			{
				nlwarning("<CMissionParser solveEntitiesNames>No guild for user %u",playerRow.getIndex());
				return;
			}
			params[i].StringId = g->getNameId();
			*/
		}
	}
}
uint32 IMissionStepTemplate::sendRpStepText(CCharacter * user,const std::vector<uint32>& stepStates,const NLMISC::CEntityId & giver)
{
	TVectorParamCheck params;
	string buffer;
	uint nbSteps = 0;
	const std::string* textPtr = NULL;

	_User = user;

	if ( !_RoleplayText.empty() )
	{
		// build the param list
		getTextParams(nbSteps,(const std::string *&)textPtr,params,stepStates);

		params.reserve(params.size() + _AdditionalParams.size());
		params.insert(params.end(), _AdditionalParams.begin(), _AdditionalParams.end());
		if ( textPtr && !textPtr->empty() && (*textPtr)[textPtr->size()-1] == '_' )
		{
			buffer = _RoleplayText + "_";
			textPtr = &buffer;
		}
		else
			textPtr = &_RoleplayText;
	}
	
	if( !textPtr )
		return 0;

	// solve dynamic names
	CMissionParser::solveEntitiesNames(params,user->getEntityRowId(),giver);

	// if the text was generated, compute its suffix
	if ( !textPtr->empty() && (*textPtr)[textPtr->size()-1] == '_' )
	{
		std::string text = NLMISC::toString( "%s%u", textPtr->c_str(),nbSteps );
		return STRING_MANAGER::sendStringToClient( user->getEntityRowId(),text,params);
	}
	else
		return STRING_MANAGER::sendStringToClient( user->getEntityRowId(),*textPtr,params);

}// IMissionStepTemplate::sendRpStepText
uint32 IMissionStepTemplate::sendStepText(CCharacter * user,const std::vector<uint32>& stepStates,const NLMISC::CEntityId & giver)
{
	TVectorParamCheck params;
	string buffer;
	uint nbSteps = 0;
	const std::string* textPtr = NULL;

	_User = user;

	// build the param list
	getTextParams(nbSteps,(const std::string *&)textPtr,params,stepStates);
	
	// If the text is overriden, add the overide parameters
	if ( !_OverridenText.empty() )
	{
		if ( _AddDefaultParams )
		{
			params.reserve(params.size() + _AdditionalParams.size());
			params.insert(params.end(), _AdditionalParams.begin(), _AdditionalParams.end());
			if ( textPtr && !textPtr->empty() && (*textPtr)[textPtr->size()-1] == '_' )
			{
				buffer = _OverridenText + "_";
				textPtr = &buffer;
			}
			else
				textPtr = &_OverridenText;
		}
		else
		{
			params = _AdditionalParams;
			textPtr = &_OverridenText;
		}

	}

	if( !textPtr )
		return 0;

	// solve dynamic names
	CMissionParser::solveEntitiesNames(params,user->getEntityRowId(),giver);

	// if the text was generated, compute its suffix
	if ( !textPtr->empty() && (*textPtr)[textPtr->size()-1] == '_' )
	{
//		if( !isAny() )
		{
			std::string text = NLMISC::toString( "%s%u", textPtr->c_str(),nbSteps );
			return STRING_MANAGER::sendStringToClient( user->getEntityRowId(),text,params);
		}
//		else
//		{
//			std::string text = NLMISC::toString( "%s%u", textPtr->c_str(),nbSteps );
//			SM_STATIC_PARAMS_1(paramsAnyOr, STRING_MANAGER::dyn_string_id);
//			paramsAnyOr[0].StringId = STRING_MANAGER::sendStringToClient( user->getEntityRowId(),text,params);
//			return STRING_MANAGER::sendStringToClient( user->getEntityRowId(),"MISSION_GOAL_STEP_ANY_OR",paramsAnyOr);
//		}
	}
	else
	{
//		if( !isAny() )
		{
			return STRING_MANAGER::sendStringToClient( user->getEntityRowId(),*textPtr,params);
		}
//		else
//		{
//			SM_STATIC_PARAMS_1(paramsAnyOr, STRING_MANAGER::dyn_string_id);
//			paramsAnyOr[0].StringId = STRING_MANAGER::sendStringToClient( user->getEntityRowId(),*textPtr,params);
//			return STRING_MANAGER::sendStringToClient( user->getEntityRowId(),"MISSION_GOAL_STEP_ANY_OR",paramsAnyOr);
//		}
	}
}// IMissionStepTemplate::sendStepText