diff --git a/ReflexToQ3/includes/EntityConverter.cpp b/ReflexToQ3/includes/EntityConverter.cpp index 42507ee..9993af5 100644 --- a/ReflexToQ3/includes/EntityConverter.cpp +++ b/ReflexToQ3/includes/EntityConverter.cpp @@ -315,13 +315,12 @@ EntityConverter::convertPlayerSpawn(const std::vector &lines) const { std::vector convertedLines; // 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) std::string angle("0.0"); // 1-2 for corresponding team, 0 for deathmatch spawn int team = 0; std::string trash; - bool havePosition = false; bool isModeRace = ws_.cts; bool isModeCtf = ws_.ctf; bool isModeTdm = ws_.tdm; @@ -329,10 +328,6 @@ EntityConverter::convertPlayerSpawn(const std::vector &lines) const 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++) { std::string type = getAttributeType(lines[i]); @@ -342,9 +337,8 @@ EntityConverter::convertPlayerSpawn(const std::vector &lines) const if ( ! (iss >> trash >> trash >> coords[0] >> coords[1] >> coords[2])) { 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" ) { std::istringstream iss(lines[i]); @@ -378,42 +372,37 @@ EntityConverter::convertPlayerSpawn(const std::vector &lines) const } } - if ( havePosition ) { - if ( isModeCtf || isModeTdm || isModeFfa || isModeDuel ) { - switch (team) { - case 0: - convertedLines.push_back ( "\"classname\" \"info_player_deathmatch\"\n" ); - break; - case 1: - convertedLines.push_back ( "\"classname\" \"info_player_team1\"\n" ); - break; - case 2: - convertedLines.push_back ( "\"classname\" \"info_player_team2\"\n" ); - break; - } + if ( isModeCtf || isModeTdm || isModeFfa || isModeDuel ) { + switch (team) { + case 0: + convertedLines.push_back ( "\"classname\" \"info_player_deathmatch\"\n" ); + break; + case 1: + convertedLines.push_back ( "\"classname\" \"info_player_team1\"\n" ); + break; + case 2: + convertedLines.push_back ( "\"classname\" \"info_player_team2\"\n" ); + 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 { - throw std::runtime_error( - makeErrorMessage( "error: PlayerSpawn entity requires position coordinates", lines )); + 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; + }