From f2b0341da38b82ad4f0a0cf258b0f6e6d8335fda Mon Sep 17 00:00:00 2001 From: suhrke Date: Sat, 19 Aug 2017 22:01:01 -0700 Subject: [PATCH] Player spawns added to entity file, used by EntityConverter --- r2cpma.ent | 25 ----------------------- r2q3.ent | 8 +++++--- r2xonotic.ent | 2 ++ src/EntityConverter.cpp | 44 +++++++++++++++++++++++++++++++---------- src/EntityConverter.hpp | 8 ++++++++ 5 files changed, 49 insertions(+), 38 deletions(-) delete mode 100644 r2cpma.ent diff --git a/r2cpma.ent b/r2cpma.ent deleted file mode 100644 index b2072eb..0000000 --- a/r2cpma.ent +++ /dev/null @@ -1,25 +0,0 @@ -40 item_health_small -41 item_health -42 item_health_large -43 item_health_mega -50 item_armor_shard -51 item_armor_jacket -52 item_armor_combat -53 item_armor_body -1 weapon_shotgun -2 weapon_grenadelauncher -3 weapon_plasmagun -4 weapon_rocketlauncher -5 weapon_lightning -6 weapon_railgun -20 ammo_bullets -21 ammo_shells -22 ammo_rockets -23 ammo_lightning -24 ammo_rockets -25 ammo_bullets -26 ammo_lightning -60 item_quad -62 item_enviro -70 team_CTF_redflag -71 team_CTF_blueflag diff --git a/r2q3.ent b/r2q3.ent index 76e36cd..0eb4a26 100644 --- a/r2q3.ent +++ b/r2q3.ent @@ -20,6 +20,8 @@ 25 item_bullets 26 item_lightning 60 item_quad -62 item_shield? -70 item_flag_team1 -71 item_flag_team2 +62 item_enviro +70 team_CTF_redflag +71 team_CTF_blueflag +team1 team_CTF_redspawn +team2 team_CTF_bluespawn diff --git a/r2xonotic.ent b/r2xonotic.ent index a396f18..d4edbd4 100644 --- a/r2xonotic.ent +++ b/r2xonotic.ent @@ -23,3 +23,5 @@ 62 item_invincible 70 item_flag_team1 71 item_flag_team2 +team1 info_player_team1 +team2 info_player_team2 diff --git a/src/EntityConverter.cpp b/src/EntityConverter.cpp index 0771b2f..93fd302 100644 --- a/src/EntityConverter.cpp +++ b/src/EntityConverter.cpp @@ -79,12 +79,11 @@ EntityConverter::EntityConverter(const std::string &entityMapFile, else { throw std::ios::failure( "Error: EntityConverter failed to open .map file " + reflexMapFile ); } - fin.close(); - haveMapInfo_ = true; - //DEBUG - //printMapping(); - //printTargetSources(); + fin.close(); + + if (haveRequiredMappings()) + haveMapInfo_ = true; } @@ -111,7 +110,8 @@ EntityConverter::extractMapInfo(std::queue> entities) } } - haveMapInfo_ = true; + if (haveRequiredMappings()) + haveMapInfo_ = true; } @@ -371,15 +371,21 @@ EntityConverter::convertPlayerSpawn(const std::vector &lines) const } if ( isModeCtf || isModeTdm || isModeFfa || isModeDuel ) { + std::stringstream ss; + std::map::const_iterator it; switch (team) { case 0: - convertedLines.push_back ( "\"classname\" \"info_player_deathmatch\"\n" ); + convertedLines.push_back ("\"classname\" \"info_player_deathmatch\"\n" ); break; - case 1: - convertedLines.push_back ( "\"classname\" \"info_player_team1\"\n" ); + case 1: + it = entityMap_.find("team1"); + ss << "\"classname\" \"" << it->second << "\"" << std::endl; + convertedLines.push_back (ss.str()); break; case 2: - convertedLines.push_back ( "\"classname\" \"info_player_team2\"\n" ); + it = entityMap_.find("team2"); + ss << "\"classname\" \"" << it->second << "\"" << std::endl; + convertedLines.push_back (ss.str()); break; } } @@ -698,6 +704,24 @@ EntityConverter::mapEntities(const std::string &mapFile) +bool +EntityConverter::haveRequiredMappings() +{ + std::vector required = { "team1", + "team2" }; + for (std::string id : required) { + auto pickupIter = entityMap_.find(id); + if ( pickupIter == entityMap_.end() ) { + throw std::runtime_error ("error: Missing required entity mappings"); + return false; + } + } + + return true; +} + + + void EntityConverter::extractFromEntity(const std::string &line, std::istream &is) { diff --git a/src/EntityConverter.hpp b/src/EntityConverter.hpp index 04181db..0ee8d5f 100644 --- a/src/EntityConverter.hpp +++ b/src/EntityConverter.hpp @@ -152,6 +152,14 @@ class EntityConverter *-------------------------------------------------------------------------------------- */ void mapEntities(const std::string &mapFile); + /* + *-------------------------------------------------------------------------------------- + * Class: EntityConverter + * Method: EntityConverter :: haveRequiredMappings + * Description: Check that required mappings exist + *-------------------------------------------------------------------------------------- + */ + bool haveRequiredMappings(); /* *-------------------------------------------------------------------------------------- * Class: EntityConverter