Skip to content

Commit

Permalink
Fixed|Hexen: Allow warp/setmap only to defined maps
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
skyjake committed Jul 3, 2012
1 parent 26ad7b7 commit a0e0177
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 33 deletions.
31 changes: 19 additions & 12 deletions doomsday/plugins/common/src/d_net.c
Expand Up @@ -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)
{
Expand All @@ -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;
Expand All @@ -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);
Expand Down
25 changes: 24 additions & 1 deletion doomsday/plugins/jhexen/include/p_mapinfo.h
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions doomsday/plugins/jhexen/src/m_cheat.c
Expand Up @@ -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);
Expand Down
45 changes: 27 additions & 18 deletions doomsday/plugins/jhexen/src/p_mapinfo.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit a0e0177

Please sign in to comment.