void CInput::setupInputCommand( stInputCommand *pInput, int action, const std::string &string )
{
	std::string buf = string;

	TrimSpaces(buf);
	if(buf == "") return;

	if(strCaseStartsWith(string, "Joy"))
	{
		std::string buf2;
		buf = buf.substr(3);
		size_t pos = buf.find('-');
		buf2 = buf.substr(0, pos);
		pInput[action].which = atoi(buf2);
		buf = buf.substr(pos+1);
		buf2 = buf.substr(0,1);
		buf = buf.substr(1);

		if(buf2 == "A")
		{
			pInput[action].joyeventtype = ETYPE_JOYAXIS;
			pos = buf.size()-1;
			buf2 = buf.substr(0,pos);
			pInput[action].joyaxis = atoi(buf2);
			buf2 = buf.substr(pos);
			pInput[action].joyvalue = (buf2 == "+") ? +1 : -1;
		}
		else if(buf2 == "B")
		{
			pInput[action].joyeventtype = ETYPE_JOYBUTTON;
			pInput[action].joybutton = atoi(buf);
		}
		else // Should normally be H
		{
			pInput[action].joyeventtype = ETYPE_JOYHAT;
			pInput[action].joyhatval = atoi(buf);
		}
		return;
	}

	if(strCaseStartsWith(string, "Key"))
	{
		pInput[action].joyeventtype = ETYPE_KEYBOARD;
		buf = buf.substr(3);
		TrimSpaces(buf);
#if SDL_VERSION_ATLEAST(2, 0, 0)
		pInput[action].keysym = (SDL_Keycode) atoi(buf);
#else
        pInput[action].keysym = (SDLKey) atoi(buf);
#endif
		return;
	}
}
Beispiel #2
0
///////////////////
// Load the weapons restrictions list
void CWpnRest::loadList(const std::string& szFilename, const std::string& moddir)
{
    // Shutdown the list first
    Shutdown();

    std::string fn = szFilename;
    if(!strCaseStartsWith(fn, "cfg/")) {
        if(fn.size() > 4 && !stringcaseequal(fn.substr(fn.size()-4), ".wps"))
            fn += ".wps";
        if(moddir != "" && IsFileAvailable("cfg/presets/" + moddir + "/" + fn))
            fn = "cfg/presets/" + moddir + "/" + fn;
        else
            fn = "cfg/presets/" + fn;
    }

    FILE *fp = OpenGameFile(fn, "rt");
    if( !fp )
        return;

    std::string line;

    while( !feof(fp) && !ferror(fp) ) {
        line = ReadUntil(fp, '\n');
        std::vector<std::string> exploded = explode(line,",");
        if (exploded.size() >= 2)
            addWeapon(exploded[0],from_string<int>(exploded[1]));
    }

    fclose(fp);

    // Sort the list
    sortList();
}
/**
 * \brief Filters a given Filelist using a pattern give in the parameter namefilter
 */
void FilterFilelist(std::set<std::string>& filelist, const std::string& namefilter)
{
    std::set<std::string> oldfilelist = filelist;
    filelist.clear();

    std::set<std::string>::iterator it = oldfilelist.begin();
    for( ; it != oldfilelist.end() ; it++ )
    {
        if(strCaseStartsWith(*it,namefilter))
            filelist.insert(*it);
    }
}
Beispiel #4
0
/**
 * \brief 	This function tries to read a value from string, given that
 * 			there is any type of number that comes.
 *  \param	input	a string of which we want to get the numerical value
 *  \param	output	the integer that might be detected.
 *  \param	width	optionally it can read width
 *  \return	if the number could be read true, otherwise false
 */
bool CPatcher::readIntValueAndWidth(const std::string &input, unsigned long int &output, size_t &width)
{
	if(strStartsWith(input, "$") or strCaseStartsWith(input, "0x"))
	{
		std::string line = input;
		// it is a hexadecimal number
		if(strStartsWith(line, "$"))
		{
			std::string buf;
			line.erase(0,1);
			buf = "0x"+line;
			line = buf;
		}

		stringlwr(line);

		if(line.size() <=4 )
		{
		    width = 1;
		}
		else
		{
		    if(line.find("w"))
		    {
			width = 2;
		    }
		    else
		    {
			width = 4;
		    }
		}

		// now everything is hexadecimal with the proper format
		sscanf( line.c_str(), "%lx", &output );

		return true;
	}

	// Try to read a decimal number
	if( (output = atoi(input)) != 0)
		return true;

	if(input == "00" || input == "0")
		return true;

	return false;
}