From 0e61e02259bfeb871eaf20d12b1f5c8491f119ca Mon Sep 17 00:00:00 2001 From: suhrke Date: Wed, 5 Jul 2017 16:14:17 -0700 Subject: [PATCH] EC: fixed malformed race spawn conversion, issue #33 --- ReflexToQ3/includes/EntityConverter.cpp | 6 ++-- ReflexToQ3/test/catch.cpp | 48 +++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/ReflexToQ3/includes/EntityConverter.cpp b/ReflexToQ3/includes/EntityConverter.cpp index d3b6c10..da3e24e 100644 --- a/ReflexToQ3/includes/EntityConverter.cpp +++ b/ReflexToQ3/includes/EntityConverter.cpp @@ -286,11 +286,11 @@ EntityConverter::convertPlayerSpawn(std::vector &lines) } else { - convertedLines.push_back ( "\"classname\" \"info_player_race\"" ); + 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\"" ); + convertedLines.push_back ( "\"target\" \"cp1\"\n" ); // Reflex maps are only cts, set spawn to cts-only type - convertedLines.push_back ( "\"race_place\" \"-1\"" ); + convertedLines.push_back ( "\"race_place\" \"-1\"\n" ); } std::stringstream oss; diff --git a/ReflexToQ3/test/catch.cpp b/ReflexToQ3/test/catch.cpp index cada5d2..5d247a0 100644 --- a/ReflexToQ3/test/catch.cpp +++ b/ReflexToQ3/test/catch.cpp @@ -93,6 +93,54 @@ TEST_CASE( "r2x: a single Pickup entity can be converted", "[EntityConverter]" ) +TEST_CASE( "r2x: a single PlayerSpawn (race) entity can be converted", "[EntityConverter]" ) { + + // Instantiate object + EntityConverter ec (PICKUP_FILENAME); + + // Mock up entity + std::vector entity; + entity.push_back(" type PlayerSpawn"); + entity.push_back(" Vector3 position -216.00000 -132.00000 -1488.000488"); + entity.push_back(" Vector3 angles 180.00000 0.00000 0.00000"); + entity.push_back(" Bool8 teamA 0"); + entity.push_back(" Bool8 teamB 0"); + entity.push_back(" Bool8 modeCTF 0"); + entity.push_back(" Bool8 modeFFA 0"); + entity.push_back(" Bool8 modeTDM 0"); + entity.push_back(" Bool8 mode1v1 0"); + + // Mock up entity queue + std::queue> q; + q.push( entity ); + + // Match related entities (none) + ec.matchRelated( q ); + + // Convert a single entity + std::vector converted = ec.convert(entity); + + REQUIRE( converted[0] == "\"classname\" \"info_player_race\"\n" ); + REQUIRE( converted[1] == "\"target\" \"cp1\"\n" ); + REQUIRE( converted[2] == "\"race_place\" \"-1\"\n" ); + REQUIRE( converted[4] == "\"angle\" \"180.00000\"\n" ); + + // The z (vertical) is offset by +32 + std::istringstream iss(converted[3]); + std::string attribute; + std::string coords[2]; + float offsetCoord; + iss >> attribute >> coords[0] >> coords[1] >> offsetCoord; + + REQUIRE( attribute == "\"origin\"" ); + REQUIRE( coords[0] == "\"-216.00000" ); + REQUIRE( coords[1] == "-1488.000488" ); + REQUIRE( fabs(-100.00000 - offsetCoord) <= DELTA ); +} + + + + TEST_CASE( "r2x: a single PlayerSpawn (teamA) entity can be converted", "[EntityConverter]" ) { // Instantiate object