race maps and maps without race convert spawns correctly, possible issue with maps with both
This commit is contained in:
parent
fde15235bd
commit
802f0bc99a
@ -137,7 +137,34 @@ EntityConverter::convert(std::vector<std::string> lines)
|
||||
}
|
||||
|
||||
|
||||
if ( type == "Pickup" ) {
|
||||
// RETURN EMPTY VECTOR if type is WorldSpawn
|
||||
if ( type == "WorldSpawn" ) {
|
||||
for ( int i = 1; i < lines.size(); ++i ) {
|
||||
// only works for maps that support race AND other modes
|
||||
if ( lines[i].find("modeRace 0") != std::string::npos) {
|
||||
std::cout << "disabled race because worldspawn" << std::endl;
|
||||
mapinfo_.cts = false;
|
||||
}
|
||||
else if ( lines[i].find("modeCTF 0") != std::string::npos) {
|
||||
std::cout << "disabled ctf because worldspawn" << std::endl;
|
||||
mapinfo_.ctf = false;
|
||||
}
|
||||
else if ( lines[i].find("modeFFA 0") != std::string::npos) {
|
||||
std::cout << "disabled ffa because worldspawn" << std::endl;
|
||||
mapinfo_.ffa = false;
|
||||
}
|
||||
else if ( lines[i].find("modeTDM 0") != std::string::npos) {
|
||||
std::cout << "disabled tdm because worldspawn" << std::endl;
|
||||
mapinfo_.tdm = false;
|
||||
}
|
||||
else if ( lines[i].find("mode1v1 0") != std::string::npos) {
|
||||
std::cout << "disabled duel because worldspawn" << std::endl;
|
||||
mapinfo_.duel = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if ( type == "Pickup" ) {
|
||||
return convertPickup(lines);
|
||||
}
|
||||
else if ( type == "PlayerSpawn" ) {
|
||||
@ -286,14 +313,8 @@ EntityConverter::convertPlayerSpawn(std::vector<std::string> &lines)
|
||||
}
|
||||
|
||||
if ( havePosition ) {
|
||||
if ( mapinfo_.cts && isModeRace ) {
|
||||
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" );
|
||||
}
|
||||
else {
|
||||
// Will convert all race points to dm/team spawns on maps that support race AND others
|
||||
if ( mapinfo_.ctf || mapinfo_.tdm || mapinfo_.ffa || mapinfo_.duel ) {
|
||||
switch (team) {
|
||||
case 0:
|
||||
convertedLines.push_back ( "\"classname\" \"info_player_deathmatch\"\n" );
|
||||
@ -306,6 +327,13 @@ EntityConverter::convertPlayerSpawn(std::vector<std::string> &lines)
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if ( mapinfo_.cts && isModeRace ) {
|
||||
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 oss;
|
||||
@ -554,27 +582,6 @@ EntityConverter::extractFromEntity(std::string &line, std::istream &is)
|
||||
}
|
||||
targetMap_.insert ( std::pair<std::string, std::string>(targetName, "JumpPad") );
|
||||
}
|
||||
else if ( line.find("type WorldSpawn") != std::string::npos) {
|
||||
while ( std::getline(is, line)) {
|
||||
// only works for maps that support race AND other modes
|
||||
if ( line.find("modeRace 0") != std::string::npos) {
|
||||
mapinfo_.cts = false;
|
||||
}
|
||||
else if ( line.find("modeCTF 0") != std::string::npos) {
|
||||
mapinfo_.ctf = false;
|
||||
}
|
||||
else if ( line.find("modeFFA 0") != std::string::npos) {
|
||||
mapinfo_.ffa = false;
|
||||
}
|
||||
else if ( line.find("modeTDM 0") != std::string::npos) {
|
||||
mapinfo_.tdm = false;
|
||||
}
|
||||
else if ( line.find("mode1v1 0") != std::string::npos) {
|
||||
mapinfo_.duel = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -37,7 +37,7 @@ TEST_CASE( "r2x: Unsupported entity types cause return of empty vector", "[Entit
|
||||
|
||||
// Mock up entity
|
||||
std::vector<std::string> entity;
|
||||
entity.push_back(" type Worldspawn");
|
||||
entity.push_back(" type NotAType");
|
||||
|
||||
// Mock up entity queue
|
||||
std::queue<std::vector<std::string>> q;
|
||||
@ -98,6 +98,16 @@ TEST_CASE( "r2x: a single PlayerSpawn (race) entity can be converted", "[EntityC
|
||||
// Instantiate object
|
||||
EntityConverter ec (PICKUP_FILENAME);
|
||||
|
||||
// Mock up WorldSpawn entity
|
||||
// (needed for mode info)
|
||||
std::vector<std::string> worldspawn;
|
||||
worldspawn.push_back(" type WorldSpawn");
|
||||
worldspawn.push_back(" Bool8 modeCTF 0");
|
||||
worldspawn.push_back(" Bool8 modeFFA 0");
|
||||
worldspawn.push_back(" Bool8 modeTDM 0");
|
||||
worldspawn.push_back(" Bool8 mode1v1 0");
|
||||
|
||||
|
||||
// Mock up entity
|
||||
std::vector<std::string> entity;
|
||||
entity.push_back(" type PlayerSpawn");
|
||||
@ -110,16 +120,17 @@ TEST_CASE( "r2x: a single PlayerSpawn (race) entity can be converted", "[EntityC
|
||||
entity.push_back(" Bool8 modeTDM 0");
|
||||
entity.push_back(" Bool8 mode1v1 0");
|
||||
|
||||
// With how map info works, at least one other spawn must be
|
||||
|
||||
// Mock up entity queue
|
||||
std::queue<std::vector<std::string>> q;
|
||||
q.push( worldspawn );
|
||||
q.push( entity );
|
||||
|
||||
// Match related entities (none)
|
||||
ec.extractMapInfo( q );
|
||||
|
||||
// Convert a single entity
|
||||
// Convert a single entity (worldspawn conversion returns empty vector
|
||||
// BUT sets the supported game modes for entities in that worldspawn
|
||||
std::vector<std::string> unused = ec.convert(worldspawn);
|
||||
std::vector<std::string> converted = ec.convert(entity);
|
||||
|
||||
REQUIRE( converted[0] == "\"classname\" \"info_player_race\"\n" );
|
||||
|
Loading…
Reference in New Issue
Block a user