reflex2q3/ReflexToQ3/includes/EntityConverter.hpp

173 lines
7.2 KiB
C++

/*
* =====================================================================================
*
* Filename: EntityConverter.hpp
*
* Description: Convert reflex entities to xonotic entities
* - Simple; operates on single entity at a time
* - Only context provided is information on what entities are related.
* (i.e. a teleport and it's destination) Can get this information
* through the pre-scan constructor of the .map file or by providing
* a queue of all the entities in the file.
* - Throws exceptions upon encountering malformed entities and when
* IO errors occur during object instantiation
*
* Version: 1.0
* Created: 05/27/2017 08:21:14 AM
* Revision: none
* Compiler: gcc
*
* Author: suhrke@teknik.io
*
* =====================================================================================
*/
#ifndef ENTITY_CONVERTER_HPP
#define ENTITY_CONVERTER_HPP
// Reflex Format
// -****While Worldspawn is an entity, an external parser handles
// this because it contains all other entities
// -"Pickup" denoted by ID
// conventional item and weapon conversion stored in r2x.ent
// -"PlayerSpawn" consists of coordinate (Vector3),
// angle (first element of Vector3),
// team indicator (on individual lines),
// game type indicator (on individual lines)
// -"JumpPad" stored as a brush and a Target
// -"Teleporter" stored as a brush and a Target
// -"Target" stored as a position (Vector3) and
// "name" (String32)
// ***Target can be destination of teleports OR jump pads
// -"RaceStart" stored as a brush
// -"RaceFinish" stored as a brush
// -MORE TO BE ADDED? (Effect, PointLight, Prefab, CameraPath, liquids)
// Xonotic Format
// -pickups prefixed by either "item_" or "weapon_"
// -spawns stored as separate entity types
// "info_player_deathmatch"
// "info_player_team1"
// "info_player_team2"
// "info_player_team3"
// "info_player_team4"
// where each consists of a coordinate "origin" (vector3)
// an angle "angle" (a single number)
// -jump pads stored as "classname" "target_push",
// a coordinate "origin" (vector3),
// a target "targetname"
// OR stored as "classname" "trigger_push",
// a target "target",
// a brush
// -teleports stored as "classname" "trigger_teleport"
// a target "target",
// a brush
// -teleport destinations stored as "classname" "misc_teleporter_dest",
// a coordinate "origin" (vector3),
// an angle "angle" (a single number),
// a target "targetname"
// -checkpoints stored as "trigger_race_checkpoint",
// a count "cnt", where "cnt" "0" is the finish line (start line?)
#include <map>
#include <string>
#include <vector>
class EntityConverter
{
public:
/*
*--------------------------------------------------------------------------------------
* Class: EntityConverter
* Method: Constructor
* Description: Creates entity format mapping
* CAUTION: Requires matchRelated method to be called after this
* Requires: .ent filename for mapping entities from reflex format to xonotic format
* THROWS: runtime_error on .ent format error
* THROWS: std::ios::failure on IO failure
*--------------------------------------------------------------------------------------
*/
EntityConverter(std::string entityMapFile);
/*
*--------------------------------------------------------------------------------------
* Class: EntityConverter
* Method: Constructor
* Description: Creates entity format mapping and pre-scans for related entities
* Parameter: string entityMapFile, file maps source to target entity formats
* Parameter: string reflexMapFile, for pre-scan
* THROWS: runtime_error on .ent format error
* THROWS: std::ios::failure on IO failure
*--------------------------------------------------------------------------------------
*/
EntityConverter(std::string entityMapFile, std::string reflexMapFile);
/*
*--------------------------------------------------------------------------------------
* Class: EntityConverter
* Method: EntityConverter :: convert
* Description: Converts a single entity from reflex to xonotic format
* Parameter: vector of strings "lines", lines that comprise a single entity
* Return: vector of strings, single entity in the converted format
* THROWS: runtime_error on malformed .map file
* THROWS: runtime_error when called before related entitios are matched
*--------------------------------------------------------------------------------------
*/
std::vector<std::string> convert(std::vector<std::string> lines);
protected:
private:
/*
*--------------------------------------------------------------------------------------
* Class: EntityConverter
* Method: EntityConverter :: getAttributeType
* Description: Extracts the type from a line
* Parameter: string "line", entity keyword followed by the type
*--------------------------------------------------------------------------------------
*/
std::string getAttributeType(std::string line);
/*
*--------------------------------------------------------------------------------------
* Class: EntityConverter
* Method: EntityConverter :: mapEntities
* Description: Prepare pickupMapping_
* Parameter: string mapFile, filename of pickup mapping
* Return: true if no error, false if error
*--------------------------------------------------------------------------------------
*/
void mapEntities(std::string mapFile);
/*
*--------------------------------------------------------------------------------------
* Class: EntityConverter
* Method: EntityConverter :: convert~EntityName~
* Description: Multiple methods to convert entity from reflex to xonotic format
* Parameter: vector of strings entity, multi-lined entity
* Return: vector of strings, the converted entity
*--------------------------------------------------------------------------------------
*/
std::vector<std::string> convertPickup(std::vector<std::string> &entity);
std::vector<std::string> convertPlayerSpawn(std::vector<std::string> &entity);
std::vector<std::string> convertJumpPad(std::vector<std::string> &entity);
std::vector<std::string> convertTeleporter(std::vector<std::string> &entity);
std::vector<std::string> convertTarget(std::vector<std::string> &entity);
std::vector<std::string> convertRaceStart(std::vector<std::string> &entity);
std::vector<std::string> convertRaceFinish(std::vector<std::string> &entity);
void printMapping(); //DEBUG
void printTargetSources(); //DEBUG
// Related entities must be matched prior to entity conversion
bool areEntitiesMatched_;
// Map Reflex pickup IDs to Xonotic pickup identifiers
std::map<int, std::string> pickupMapping_;
// Map targets (by name) to their source type
std::map<std::string, std::string> targetMap_;
};
#endif //ENTITY_CONVERTER_HPP