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
*-----------------------------------------------------------------------------*/
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
haveMapInfo_ = false;
// game modes default to enabled
mapinfo_.cts = true;
mapinfo_.ctf = true;
mapinfo_.ffa = true;
mapinfo_.tdm = true;
mapinfo_.duel = true;
ws_.cts = true;
ws_.ctf = true;
ws_.ffa = true;
ws_.tdm = true;
ws_.duel = true;
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;
// game modes default to enabled
mapinfo_.cts = true;
mapinfo_.ctf = true;
mapinfo_.ffa = true;
mapinfo_.tdm = true;
mapinfo_.duel = true;
ws_.cts = true;
ws_.ctf = true;
ws_.ffa = true;
ws_.tdm = true;
ws_.duel = true;
mapEntities(entityMapFile);
@ -138,22 +141,29 @@ EntityConverter::convert(const std::vector<std::string> &lines)
// RETURN EMPTY VECTOR if type is 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 ) {
// only works for maps that support race AND other modes
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) {
mapinfo_.ctf = false;
ws_.ctf = false;
}
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) {
mapinfo_.tdm = false;
ws_.tdm = false;
}
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;
std::string trash;
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 ) {
@ -298,8 +312,21 @@ EntityConverter::convertPlayerSpawn(const std::vector<std::string> &lines)
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" ) {
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" ) {
team = 2; // Bool8 teamA 0 indicates teamB only
@ -311,7 +338,7 @@ EntityConverter::convertPlayerSpawn(const std::vector<std::string> &lines)
if ( havePosition ) {
// 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) {
case 0:
convertedLines.push_back ( "\"classname\" \"info_player_deathmatch\"\n" );
@ -324,7 +351,7 @@ EntityConverter::convertPlayerSpawn(const std::vector<std::string> &lines)
break;
}
}
else if ( mapinfo_.cts && isModeRace ) {
else {
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" );
@ -332,7 +359,6 @@ EntityConverter::convertPlayerSpawn(const std::vector<std::string> &lines)
convertedLines.push_back ( "\"race_place\" \"-1\"\n" );
}
std::stringstream positionStream;
// coordinates reordered to x, z, y
positionStream << "\"origin\" \"" << coords[0] << " " << coords[2] << " " <<

View File

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