Race and other mode spawns play nice when on same map now

This commit is contained in:
suhrke 2017-07-06 08:52:59 -07:00
parent c88cf1405b
commit d16f3f8503
2 changed files with 51 additions and 25 deletions

View File

@ -29,31 +29,34 @@
* PUBLIC * PUBLIC
*-----------------------------------------------------------------------------*/ *-----------------------------------------------------------------------------*/
EntityConverter::EntityConverter(const std::string &entityMapFile) : OFFSET_PLAYER(32.0), OFFSET_PICKUP(2.0), BRIGHTNESS_ADJUST(50.0) EntityConverter::EntityConverter(const std::string &entityMapFile) :
OFFSET_PLAYER(32.0), OFFSET_PICKUP(2.0), BRIGHTNESS_ADJUST(50.0)
{ {
//MUST RUN extractMapInfo method after this constructor //MUST RUN extractMapInfo method after this constructor
haveMapInfo_ = false; haveMapInfo_ = false;
// game modes default to enabled // game modes default to enabled
mapinfo_.cts = true; ws_.cts = true;
mapinfo_.ctf = true; ws_.ctf = true;
mapinfo_.ffa = true; ws_.ffa = true;
mapinfo_.tdm = true; ws_.tdm = true;
mapinfo_.duel = true; ws_.duel = true;
mapEntities(entityMapFile); mapEntities(entityMapFile);
} }
EntityConverter::EntityConverter(const std::string &entityMapFile, const std::string &reflexMapFile) : OFFSET_PLAYER(32.0), OFFSET_PICKUP(2.0), BRIGHTNESS_ADJUST(50.0) EntityConverter::EntityConverter(const std::string &entityMapFile,
const std::string &reflexMapFile) : OFFSET_PLAYER(32.0),
OFFSET_PICKUP(2.0), BRIGHTNESS_ADJUST(50.0)
{ {
haveMapInfo_ = false; haveMapInfo_ = false;
// game modes default to enabled // game modes default to enabled
mapinfo_.cts = true; ws_.cts = true;
mapinfo_.ctf = true; ws_.ctf = true;
mapinfo_.ffa = true; ws_.ffa = true;
mapinfo_.tdm = true; ws_.tdm = true;
mapinfo_.duel = true; ws_.duel = true;
mapEntities(entityMapFile); mapEntities(entityMapFile);
@ -138,22 +141,29 @@ EntityConverter::convert(const std::vector<std::string> &lines)
// RETURN EMPTY VECTOR if type is WorldSpawn // RETURN EMPTY VECTOR if type is WorldSpawn
if ( type == "WorldSpawn" ) { if ( type == "WorldSpawn" ) {
//All modes enabled by default, reset for new worldspawn
ws_.cts = true;
ws_.ctf = true;
ws_.ffa = true;
ws_.tdm = true;
ws_.duel = true;
// Each worldspawn can specify modes enabled/disabled
for ( int i = 1; i < lines.size(); ++i ) { 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) { if ( lines[i].find("modeRace 0") != std::string::npos) {
mapinfo_.cts = false; ws_.cts = false;
} }
else if ( lines[i].find("modeCTF 0") != std::string::npos) { else if ( lines[i].find("modeCTF 0") != std::string::npos) {
mapinfo_.ctf = false; ws_.ctf = false;
} }
else if ( lines[i].find("modeFFA 0") != std::string::npos) { else if ( lines[i].find("modeFFA 0") != std::string::npos) {
mapinfo_.ffa = false; ws_.ffa = false;
} }
else if ( lines[i].find("modeTDM 0") != std::string::npos) { else if ( lines[i].find("modeTDM 0") != std::string::npos) {
mapinfo_.tdm = false; ws_.tdm = false;
} }
else if ( lines[i].find("mode1v1 0") != std::string::npos) { else if ( lines[i].find("mode1v1 0") != std::string::npos) {
mapinfo_.duel = false; ws_.duel = false;
} }
} }
@ -273,7 +283,11 @@ EntityConverter::convertPlayerSpawn(const std::vector<std::string> &lines)
int team = 0; int team = 0;
std::string trash; std::string trash;
bool havePosition = false; bool havePosition = false;
bool isModeRace = true; bool isModeRace = ws_.cts;
bool isModeCtf = ws_.ctf;
bool isModeTdm = ws_.tdm;
bool isModeFfa = ws_.ffa;
bool isModeDuel = ws_.duel;
if ( lines.size() < 2 ) { if ( lines.size() < 2 ) {
@ -298,8 +312,21 @@ EntityConverter::convertPlayerSpawn(const std::vector<std::string> &lines)
throw std::runtime_error("error: Pickup entity requires Pickup ID"); throw std::runtime_error("error: Pickup entity requires Pickup ID");
} }
} }
// Bool8 modeX 0 indicates this spawn is not for game mode X
else if ( type == "modeRace" ) { else if ( type == "modeRace" ) {
isModeRace = false; // Bool8 modeRace 0 indicates this spawn is not for race isModeRace = false;
}
else if ( type == "modeCTF" ) {
isModeCtf = false;
}
else if ( type == "modeTDM" ) {
isModeTdm = false;
}
else if ( type == "modeFFA" ) {
isModeFfa = false;
}
else if ( type == "mode1v1" ) {
isModeDuel = false;
} }
else if ( type == "teamA" ) { else if ( type == "teamA" ) {
team = 2; // Bool8 teamA 0 indicates teamB only team = 2; // Bool8 teamA 0 indicates teamB only
@ -311,7 +338,7 @@ EntityConverter::convertPlayerSpawn(const std::vector<std::string> &lines)
if ( havePosition ) { if ( havePosition ) {
// Will convert all race points to dm/team spawns on maps that support race AND others // 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 ) { if ( isModeCtf || isModeTdm || isModeFfa || isModeDuel ) {
switch (team) { switch (team) {
case 0: case 0:
convertedLines.push_back ( "\"classname\" \"info_player_deathmatch\"\n" ); convertedLines.push_back ( "\"classname\" \"info_player_deathmatch\"\n" );
@ -324,7 +351,7 @@ EntityConverter::convertPlayerSpawn(const std::vector<std::string> &lines)
break; break;
} }
} }
else if ( mapinfo_.cts && isModeRace ) { else {
convertedLines.push_back ( "\"classname\" \"info_player_race\"\n" ); convertedLines.push_back ( "\"classname\" \"info_player_race\"\n" );
// Reflex maps have only start and finish, point to start on spawn // Reflex maps have only start and finish, point to start on spawn
convertedLines.push_back ( "\"target\" \"cp1\"\n" ); convertedLines.push_back ( "\"target\" \"cp1\"\n" );
@ -332,7 +359,6 @@ EntityConverter::convertPlayerSpawn(const std::vector<std::string> &lines)
convertedLines.push_back ( "\"race_place\" \"-1\"\n" ); convertedLines.push_back ( "\"race_place\" \"-1\"\n" );
} }
std::stringstream positionStream; std::stringstream positionStream;
// coordinates reordered to x, z, y // coordinates reordered to x, z, y
positionStream << "\"origin\" \"" << coords[0] << " " << coords[2] << " " << positionStream << "\"origin\" \"" << coords[0] << " " << coords[2] << " " <<

View File

@ -37,7 +37,7 @@
struct MapInfo struct WorldSpawn
{ {
bool cts; bool cts;
bool ctf; bool ctf;
@ -130,7 +130,7 @@ class EntityConverter
std::map<std::string, std::string> targetMap_; std::map<std::string, std::string> targetMap_;
// Related entities must be matched prior to entity conversion // Related entities must be matched prior to entity conversion
bool haveMapInfo_; bool haveMapInfo_;
MapInfo mapinfo_; WorldSpawn ws_;
// Offsets for item/spawn height // Offsets for item/spawn height
const float OFFSET_PLAYER; const float OFFSET_PLAYER;