PlayerSpawn defaults to 0,0,0 if position unspecified

This commit is contained in:
suhrke 2017-07-11 22:26:21 -07:00
parent e52d284142
commit 11f8989558

View File

@ -315,13 +315,12 @@ EntityConverter::convertPlayerSpawn(const std::vector<std::string> &lines) const
{ {
std::vector<std::string> convertedLines; std::vector<std::string> convertedLines;
// Requires position coordinate // Requires position coordinate
std::string coords[3]; std::string coords[3] = {"0.0", "0.0", "0.0"};
// Requires an angle, default to 0 degrees (floating point) // Requires an angle, default to 0 degrees (floating point)
std::string angle("0.0"); std::string angle("0.0");
// 1-2 for corresponding team, 0 for deathmatch spawn // 1-2 for corresponding team, 0 for deathmatch spawn
int team = 0; int team = 0;
std::string trash; std::string trash;
bool havePosition = false;
bool isModeRace = ws_.cts; bool isModeRace = ws_.cts;
bool isModeCtf = ws_.ctf; bool isModeCtf = ws_.ctf;
bool isModeTdm = ws_.tdm; bool isModeTdm = ws_.tdm;
@ -329,10 +328,6 @@ EntityConverter::convertPlayerSpawn(const std::vector<std::string> &lines) const
bool isModeDuel = ws_.duel; bool isModeDuel = ws_.duel;
if ( lines.size() < 2 ) {
throw std::runtime_error(
makeErrorMessage( "error: PlayerSpawn entity requires at least 2 lines", lines ));
}
for (int i = 1; i < lines.size(); i++) { for (int i = 1; i < lines.size(); i++) {
std::string type = getAttributeType(lines[i]); std::string type = getAttributeType(lines[i]);
@ -342,9 +337,8 @@ EntityConverter::convertPlayerSpawn(const std::vector<std::string> &lines) const
if ( ! (iss >> trash >> trash >> if ( ! (iss >> trash >> trash >>
coords[0] >> coords[1] >> coords[2])) { coords[0] >> coords[1] >> coords[2])) {
throw std::runtime_error( throw std::runtime_error(
makeErrorMessage( "error: PlayerSpawn entity requires position coordinates", lines )); makeErrorMessage( "error: PlayerSpawn entity must have valid position coordinates if specified", lines ));
} }
havePosition = true;
} }
else if ( type == "angles" ) { else if ( type == "angles" ) {
std::istringstream iss(lines[i]); std::istringstream iss(lines[i]);
@ -378,42 +372,37 @@ EntityConverter::convertPlayerSpawn(const std::vector<std::string> &lines) const
} }
} }
if ( havePosition ) { if ( isModeCtf || isModeTdm || isModeFfa || isModeDuel ) {
if ( isModeCtf || isModeTdm || isModeFfa || isModeDuel ) { switch (team) {
switch (team) { case 0:
case 0: convertedLines.push_back ( "\"classname\" \"info_player_deathmatch\"\n" );
convertedLines.push_back ( "\"classname\" \"info_player_deathmatch\"\n" ); break;
break; case 1:
case 1: convertedLines.push_back ( "\"classname\" \"info_player_team1\"\n" );
convertedLines.push_back ( "\"classname\" \"info_player_team1\"\n" ); break;
break; case 2:
case 2: convertedLines.push_back ( "\"classname\" \"info_player_team2\"\n" );
convertedLines.push_back ( "\"classname\" \"info_player_team2\"\n" ); break;
break;
}
} }
else {
convertedLines.push_back ( "\"classname\" \"info_player_race\"\n" );
// Reflex maps have only start and finish, point to start on spawn
convertedLines.push_back ( "\"target\" \"cp1\"\n" );
// Reflex maps are only cts, set spawn to cts-only type
convertedLines.push_back ( "\"race_place\" \"-1\"\n" );
}
std::stringstream positionStream;
// coordinates reordered to x, z, y
positionStream << "\"origin\" \"" << coords[0] << " " << coords[2] << " " <<
offset(coords[1], OFFSET_PLAYER) << "\"" << std::endl;
convertedLines.push_back ( positionStream.str() );
std::stringstream angleStream;
angleStream << "\"angle\" \"" << adjustAngleForHandedness(angle) << "\"" << std::endl;
convertedLines.push_back (angleStream.str() );
return convertedLines;
} }
else { else {
throw std::runtime_error( convertedLines.push_back ( "\"classname\" \"info_player_race\"\n" );
makeErrorMessage( "error: PlayerSpawn entity requires position coordinates", lines )); // Reflex maps have only start and finish, point to start on spawn
convertedLines.push_back ( "\"target\" \"cp1\"\n" );
// Reflex maps are only cts, set spawn to cts-only type
convertedLines.push_back ( "\"race_place\" \"-1\"\n" );
} }
std::stringstream positionStream;
// coordinates reordered to x, z, y
positionStream << "\"origin\" \"" << coords[0] << " " << coords[2] << " " <<
offset(coords[1], OFFSET_PLAYER) << "\"" << std::endl;
convertedLines.push_back ( positionStream.str() );
std::stringstream angleStream;
angleStream << "\"angle\" \"" << adjustAngleForHandedness(angle) << "\"" << std::endl;
convertedLines.push_back (angleStream.str() );
return convertedLines;
} }