From 821d6001bfb22100039fa2ed7aa3f217293859a4 Mon Sep 17 00:00:00 2001 From: suhrke Date: Thu, 6 Jul 2017 16:14:06 -0700 Subject: [PATCH] fixed error with unmatched target and source --- ReflexToQ3/includes/EntityConverter.cpp | 27 ++++++++++++++++++++----- ReflexToQ3/includes/EntityConverter.hpp | 4 ++-- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/ReflexToQ3/includes/EntityConverter.cpp b/ReflexToQ3/includes/EntityConverter.cpp index f5fd1da..1defa51 100644 --- a/ReflexToQ3/includes/EntityConverter.cpp +++ b/ReflexToQ3/includes/EntityConverter.cpp @@ -262,8 +262,12 @@ EntityConverter::convertPickup(const std::vector &lines) const } if ( havePosition && havePickupID ) { + auto pickupIter = pickupMap_.find(pickupID); + if ( pickupIter == pickupMap_.end() ) { + throw std::runtime_error("error: Pickup ID must be valid"); + } std::stringstream pickupStream; - pickupStream << "\"classname\" \"" << pickupMapping_.find(pickupID)->second << "\"" << std::endl; + pickupStream << "\"classname\" \"" << pickupIter->second << "\"" << std::endl; convertedLines.push_back ( pickupStream.str() ); // coordinates reordered to x, z, y std::stringstream positionStream; @@ -493,7 +497,20 @@ EntityConverter::convertTarget(const std::vector &lines) const } if ( havePosition && haveName) { - if ( targetMap_.find(targetName)->second == "Teleporter") { + auto targetIter = targetMap_.find(targetName); + if ( targetIter == targetMap_.end() ) { + std::cerr << "EntityConverter doesn't know what the source of a Target entity with the " + << "following attributes. It is probably an unsupported entity type or feature. " + << "(game over camera, etc). Returning an empty vector." << std::endl; + std::vector::const_iterator it; + for ( it=lines.begin(); it!=lines.end(); ++it ) { + std::cerr << *it << std::endl; + } + std::cerr << std::endl; + std::vector empty; + return empty; + } + if ( targetIter->second == "Teleporter") { convertedLines.push_back ( "\"classname\" \"misc_teleporter_dest\"\n" ); // coordinates reordered to x, z, y // teleporter height is OFFSET @@ -502,7 +519,7 @@ EntityConverter::convertTarget(const std::vector &lines) const offset(coords[1], OFFSET_PLAYER) << "\"" << std::endl; convertedLines.push_back ( oss.str() ); } - else if ( targetMap_.find(targetName)->second == "JumpPad") { + else if ( targetIter->second == "JumpPad") { convertedLines.push_back ( "\"classname\" \"target_position\"\n" ); // coordinates reordered to x, z, y std::stringstream oss; @@ -669,7 +686,7 @@ EntityConverter::mapEntities(const std::string &mapFile) if ( ! (iss >> id >> pickup)) { throw std::runtime_error( "format error in .ent file" ); } - pickupMapping_.insert ( std::pair(id, pickup) ); + pickupMap_.insert ( std::pair(id, pickup) ); } } else { @@ -756,7 +773,7 @@ EntityConverter::printMapping() const { std::cout << std::endl << "Reflex pickup ID mapped to Xonotic pickup names: " << std::endl; std::map::const_iterator it; - for ( it=pickupMapping_.begin(); it!=pickupMapping_.end(); ++it ) + for ( it=pickupMap_.begin(); it!=pickupMap_.end(); ++it ) std::cout << it->first << " => " << it->second << std::endl; } diff --git a/ReflexToQ3/includes/EntityConverter.hpp b/ReflexToQ3/includes/EntityConverter.hpp index 52cce09..5f3403a 100644 --- a/ReflexToQ3/includes/EntityConverter.hpp +++ b/ReflexToQ3/includes/EntityConverter.hpp @@ -136,7 +136,7 @@ class EntityConverter // Map Reflex pickup IDs to Xonotic pickup identifiers - std::map pickupMapping_; + std::map pickupMap_; // Map targets (by name) to their source type std::map targetMap_; // Related entities must be matched prior to entity conversion @@ -165,7 +165,7 @@ class EntityConverter *-------------------------------------------------------------------------------------- * Class: EntityConverter * Method: EntityConverter :: mapEntities - * Description: Prepare pickupMapping_ + * Description: Prepare pickupMap * Parameter: string mapFile, filename of pickup mapping * Return: true if no error, false if error *--------------------------------------------------------------------------------------