const vector< string >& getStringList( int playernum, const string &mykey ) { if ( playernum < 0 || (unsigned int) playernum >= _Universe->numPlayers() ) { static const vector<string> empty; return empty; } SaveGame *savegame = _Universe->AccessCockpit( playernum )->savegame; /* Should check old-style string lists, but it would defeat the purpose of this fast getter. Besides, any functionality that uses this one is using the new-style string lists, so we're cool (or ought to be) */ return savegame->readMissionStringData( mykey ); }
vector< string > loadStringList( int playernum, const string &mykey ) { if ( playernum < 0 || (unsigned int) playernum >= _Universe->numPlayers() ) return vector< string > (); SaveGame *savegame = _Universe->AccessCockpit( playernum )->savegame; vector< string >rez; const vector< string > &ans = savegame->readMissionStringData( mykey ); if (ans.size() > 0) { /* This is the modern way to store string data: as strings */ rez.reserve(ans.size()); rez.insert(rez.end(), ans.begin(), ans.end()); } else { /* This variant loads it from float data, converting to character data. It's a legacy variant, highly and unpleasantly convoluted and sub-performant, but we must support it to be compatible with old savegames */ const vector< float > &ans = savegame->readMissionData( mykey ); int lengt = ans.size(); rez.reserve(ans.size()); if (lengt >= 1) { string curstr; int length = (int)ans[0]; for (int j = 0; j < length && j < lengt; j++) { char myint = (char)ans[j+1]; if (myint != '\0') { curstr += myint; } else { rez.push_back( curstr ); curstr = ""; } } } } return rez; }