From a0e0177a96dc910b0117f77c03f298a6ef9d9ff5 Mon Sep 17 00:00:00 2001 From: skyjake Date: Tue, 3 Jul 2012 12:48:40 +0300 Subject: [PATCH] Fixed|Hexen: Allow warp/setmap only to defined maps Warping is now only allowed to maps defined in MAPINFO. The "warp" and "set map" commands will just report failure when attempting to switch to undefined maps. --- doomsday/plugins/common/src/d_net.c | 31 ++++++++------ doomsday/plugins/jhexen/include/p_mapinfo.h | 25 +++++++++++- doomsday/plugins/jhexen/src/m_cheat.c | 4 +- doomsday/plugins/jhexen/src/p_mapinfo.c | 45 ++++++++++++--------- 4 files changed, 72 insertions(+), 33 deletions(-) diff --git a/doomsday/plugins/common/src/d_net.c b/doomsday/plugins/common/src/d_net.c index 0aa3f2ec1b..37aab2af25 100644 --- a/doomsday/plugins/common/src/d_net.c +++ b/doomsday/plugins/common/src/d_net.c @@ -822,6 +822,7 @@ D_CMD(SetMap) // Only the server can change the map. if(!IS_SERVER) return false; + #if __JDOOM__ || __JHERETIC__ if(argc != 3) { @@ -836,17 +837,7 @@ D_CMD(SetMap) } #endif - // Update game mode. - deathmatch = cfg.netDeathmatch; - noMonstersParm = cfg.netNoMonsters; -#if __JDOOM__ || __JDOOM64__ || __JHERETIC__ - respawnMonsters = cfg.netRespawn; -#endif -#if __JHEXEN__ - randomClassParm = cfg.netRandomClass; -#endif - cfg.jumpEnabled = cfg.netJumping; - + // Parse arguments. #if __JDOOM__ || __JHERETIC__ ep = atoi(argv[1]); if(ep != 0) ep -= 1; @@ -860,8 +851,24 @@ D_CMD(SetMap) map = atoi(argv[1]); if(map != 0) map -= 1; #endif #if __JHEXEN__ - map = P_TranslateMap(map); + map = P_TranslateMapIfExists(map); + if(map == P_INVALID_LOGICAL_MAP) + { + Con_Message("Map not found.\n"); + return false; + } +#endif + + // Update game mode. + deathmatch = cfg.netDeathmatch; + noMonstersParm = cfg.netNoMonsters; +#if __JDOOM__ || __JDOOM64__ || __JHERETIC__ + respawnMonsters = cfg.netRespawn; +#endif +#if __JHEXEN__ + randomClassParm = cfg.netRandomClass; #endif + cfg.jumpEnabled = cfg.netJumping; // Use the configured network skill level for the new map. G_DeferedInitNew(cfg.netSkill, ep, map); diff --git a/doomsday/plugins/jhexen/include/p_mapinfo.h b/doomsday/plugins/jhexen/include/p_mapinfo.h index cce5244cf6..50bb42dcd8 100644 --- a/doomsday/plugins/jhexen/include/p_mapinfo.h +++ b/doomsday/plugins/jhexen/include/p_mapinfo.h @@ -38,7 +38,30 @@ void P_InitMapInfo(void); void P_InitMapMusicInfo(void); int P_GetMapCluster(uint map); -uint P_TranslateMap(uint map); + +#define P_INVALID_LOGICAL_MAP 0xffffffff + +/** + * Translates a warp map number to logical map number, if possible. + * + * @param map The warp map number to translate. + * + * @return The logical map number given a warp map number. If the map is not + * found, returns P_INVALID_LOGICAL_MAP. + */ +uint P_TranslateMapIfExists(uint map); + +/** + * Translates a warp map number to logical map number. Always returns a valid + * logical map. + * + * @param map The warp map number to translate. + * + * @return The logical map number given a warp map number. If the map is not + * found, returns 0 (first available logical map). + */ +uint P_TranslateMap(uint map); + int P_GetMapCDTrack(uint map); uint P_GetMapWarpTrans(uint map); uint P_GetMapNextMap(uint map); diff --git a/doomsday/plugins/jhexen/src/m_cheat.c b/doomsday/plugins/jhexen/src/m_cheat.c index c6b34d76be..a002f7feaf 100644 --- a/doomsday/plugins/jhexen/src/m_cheat.c +++ b/doomsday/plugins/jhexen/src/m_cheat.c @@ -388,8 +388,8 @@ int Cht_WarpFunc(const int* args, int player) return false; } - map = P_TranslateMap((tens * 10 + ones) - 1); - if(userGame && map == gameMap) + map = P_TranslateMapIfExists((tens * 10 + ones) - 1); + if((userGame && map == gameMap) || map == P_INVALID_LOGICAL_MAP) { // Do not allow warping to the current map. P_SetMessage(plr, TXT_CHEATBADINPUT, false); diff --git a/doomsday/plugins/jhexen/src/p_mapinfo.c b/doomsday/plugins/jhexen/src/p_mapinfo.c index 7d274697e3..c3be8016f7 100644 --- a/doomsday/plugins/jhexen/src/p_mapinfo.c +++ b/doomsday/plugins/jhexen/src/p_mapinfo.c @@ -47,6 +47,7 @@ // TYPES ------------------------------------------------------------------- typedef struct mapinfo_s { + boolean fromMAPINFO; ///< The data for this was read from the MAPINFO lump. short cluster; uint warpTrans; uint nextMap; @@ -164,7 +165,10 @@ void P_InitMapInfo(void) mapinfo_t defMapInfo; mapinfo_t* info; + memset(&MapInfo, 0, sizeof(MapInfo)); + // Configure the defaults + defMapInfo.fromMAPINFO = false; // just default values defMapInfo.cluster = 0; defMapInfo.warpTrans = 0; defMapInfo.nextMap = 0; // Always go to map 0 if not specified. @@ -204,6 +208,9 @@ void P_InitMapInfo(void) // Restore song lump name strcpy(info->songLump, songMulch); + // This information has been parsed from MAPINFO. + info->fromMAPINFO = true; + // The warp translation defaults to the map number info->warpTrans = map; @@ -363,48 +370,50 @@ static __inline uint qualifyMap(uint map) return (map >= mapCount) ? 0 : map; } -/** - * Translates a warp map number to logical map number. - * - * @param map The warp map number to translate. - * - * @return The logical map number given a warp map number. - */ -uint P_TranslateMap(uint map) +uint P_TranslateMapIfExists(uint map) { uint i; - uint matchWithoutCluster = 0; + uint matchedWithoutCluster = P_INVALID_LOGICAL_MAP; for(i = 0; i < 99; ++i) { const mapinfo_t* info = &MapInfo[i]; -#ifdef _DEBUG - //Con_Message("P_TranslateMap: checking MAPINFO entry %i: warp %i name \"%s\"\n", i, info->warpTrans, info->name); -#endif + if(!info->fromMAPINFO) continue; // Ignoring, undefined values. if(info->warpTrans == map) { if(info->cluster) { #ifdef _DEBUG - Con_Message("P_TranslateMap: warp %i translated to logical %i, cluster %i\n", map, i, info->cluster); + Con_Message("P_TranslateMapIfExists: warp %i translated to logical %i, cluster %i\n", map, i, info->cluster); #endif return i; } else { #ifdef _DEBUG - Con_Message("P_TranslateMap: warp %i matches logical %i, but it has no cluster\n", map, i); + Con_Message("P_TranslateMapIfExists: warp %i matches logical %i, but it has no cluster\n", map, i); #endif - matchWithoutCluster = i; + matchedWithoutCluster = i; } } } #ifdef _DEBUG - Con_Message("P_TranslateMap: could not find warp %i, translating to logical %i\n", - map, matchWithoutCluster); + Con_Message("P_TranslateMapIfExists: could not find warp %i, translating to logical %i\n", + map, matchedWithoutCluster); #endif - return matchWithoutCluster; // 0 if nothing matched + return matchedWithoutCluster; +} + +uint P_TranslateMap(uint map) +{ + uint translated = P_TranslateMapIfExists(map); + if(translated == P_INVALID_LOGICAL_MAP) + { + // This function always returns a valid logical map. + return 0; + } + return translated; } /**