diff --git a/doomsday/plugins/common/include/g_common.h b/doomsday/plugins/common/include/g_common.h index 831f49fac1..18cadad3db 100644 --- a/doomsday/plugins/common/include/g_common.h +++ b/doomsday/plugins/common/include/g_common.h @@ -29,6 +29,7 @@ DENG_EXTERN_C dd_bool singledemo; +DENG_EXTERN_C uint gameEpisode; DENG_EXTERN_C uint gameMapEntrance; #if __cplusplus @@ -187,40 +188,46 @@ void G_IntermissionDone(void); } // extern "C" /** - * Returns the logical episode number for the identified map. + * Returns the logical episode number assigned to the identified map (in MapInfo). * * @param mapUri Unique identifier of the map to lookup. */ uint G_EpisodeNumberFor(de::Uri const &mapUri); +/** + * Determines the next map according to the default map progression. + * + * @param secretExit @c true= choose the map assigned to the secret exit. + */ +de::Uri G_NextMap(dd_bool secretExit); + /** * Returns the logical map number for the identified map. * * @param mapUri Unique identifier of the map to lookup. + * + * @deprecated Should use map URIs instead. */ uint G_MapNumberFor(de::Uri const &mapUri); /** - * Compose a Uri for the identified @a episode and @a map combination. + * Compose a Uri for the identified @a episode and @a map combination using the default + * form for the current game mode (i.e., MAPXX or EXMY). * * @param episode Logical episode number. * @param map Logical map number. * * @return Resultant Uri. - */ -de::Uri G_ComposeMapUri(uint episode, uint map); - -/** - * Determines the next map according to the default map progression. * - * @param secretExit @c true= choose the map assigned to the secret exit. + * @deprecated Should use map URIs instead. Map references composed of a logical episode + * and map number pair are a historical legacy that should only be used when necessary, + * for compatibility reasons. */ -de::Uri G_NextMap(dd_bool secretExit); +de::Uri G_ComposeMapUri(uint episode, uint map); extern "C" { #endif -uint G_CurrentEpisodeNumber(void); uint G_CurrentMapNumber(void); int G_Ruleset_Skill(); diff --git a/doomsday/plugins/common/src/d_netcl.cpp b/doomsday/plugins/common/src/d_netcl.cpp index ef4877bd50..1cc6921ad8 100644 --- a/doomsday/plugins/common/src/d_netcl.cpp +++ b/doomsday/plugins/common/src/d_netcl.cpp @@ -650,19 +650,20 @@ void NetCl_Intermission(Reader *msg) SN_StopAllSequences(); #endif + /// @todo Map references should be transmitted as URI. #if __JDOOM__ || __JDOOM64__ wmInfo.maxKills = de::max(1, Reader_ReadUInt16(msg)); wmInfo.maxItems = de::max(1, Reader_ReadUInt16(msg)); wmInfo.maxSecret = de::max(1, Reader_ReadUInt16(msg)); - wmInfo.nextMap = G_ComposeMapUri(G_CurrentEpisodeNumber(), Reader_ReadByte(msg)); - wmInfo.currentMap = G_ComposeMapUri(G_CurrentEpisodeNumber(), Reader_ReadByte(msg)); + wmInfo.nextMap = G_ComposeMapUri(::gameEpisode, Reader_ReadByte(msg)); + wmInfo.currentMap = G_ComposeMapUri(::gameEpisode, Reader_ReadByte(msg)); wmInfo.didSecret = Reader_ReadByte(msg); G_PrepareWIData(); #elif __JHERETIC__ - // @todo jHeretic does not transmit the intermission info! + /// @todo jHeretic does not transmit the intermission info! #elif __JHEXEN__ - ::nextMapUri = G_ComposeMapUri(G_CurrentEpisodeNumber(), Reader_ReadByte(msg)); + ::nextMapUri = G_ComposeMapUri(::gameEpisode, Reader_ReadByte(msg)); ::nextMapEntrance = Reader_ReadByte(msg); #endif diff --git a/doomsday/plugins/common/src/d_netsv.cpp b/doomsday/plugins/common/src/d_netsv.cpp index ffc7113f2b..babc99a64f 100644 --- a/doomsday/plugins/common/src/d_netsv.cpp +++ b/doomsday/plugins/common/src/d_netsv.cpp @@ -680,7 +680,8 @@ void NetSv_SendGameState(int flags, int to) Uri_Write(reinterpret_cast(&gameMapUri), writer); // Also include the episode and map numbers. - Writer_WriteByte(writer, G_CurrentEpisodeNumber()); + /// @todo Map references should be transmitted as URI. + Writer_WriteByte(writer, ::gameEpisode); Writer_WriteByte(writer, G_CurrentMapNumber()); Writer_WriteByte(writer, (COMMON_GAMESESSION->rules().deathmatch & 0x3) diff --git a/doomsday/plugins/common/src/g_game.cpp b/doomsday/plugins/common/src/g_game.cpp index 344439bb3d..345d1d4d38 100644 --- a/doomsday/plugins/common/src/g_game.cpp +++ b/doomsday/plugins/common/src/g_game.cpp @@ -112,6 +112,7 @@ int Hook_DemoStop(int hookType, int val, void *parm); game_config_t cfg; // The global cfg. +uint gameEpisode; de::Uri gameMapUri; uint gameMapEntrance; ///< Entry point, for reborn. @@ -2382,11 +2383,6 @@ uint G_MapNumberFor(de::Uri const &mapUri) return 0; } -uint G_CurrentEpisodeNumber() -{ - return G_EpisodeNumberFor(gameMapUri); -} - uint G_CurrentMapNumber() { return G_MapNumberFor(gameMapUri); @@ -2419,7 +2415,7 @@ de::Uri G_NextMap(dd_bool secretExit) DENG2_UNUSED(secretExit); #elif __JDOOM64__ - uint episode = G_CurrentEpisodeNumber(); + uint episode = ::gameEpisode; uint map = G_CurrentMapNumber(); if(secretExit) @@ -2455,7 +2451,7 @@ de::Uri G_NextMap(dd_bool secretExit) return G_ComposeMapUri(episode, map); #elif __JDOOM__ - uint episode = G_CurrentEpisodeNumber(); + uint episode = ::gameEpisode; uint map = G_CurrentMapNumber(); if(gameModeBits & GM_ANY_DOOM2) @@ -2518,7 +2514,7 @@ de::Uri G_NextMap(dd_bool secretExit) } #elif __JHERETIC__ - uint episode = G_CurrentEpisodeNumber(); + uint episode = ::gameEpisode; uint map = G_CurrentMapNumber(); // Going to the secret map? diff --git a/doomsday/plugins/common/src/gamesession.cpp b/doomsday/plugins/common/src/gamesession.cpp index 843e9f0596..d17add2120 100644 --- a/doomsday/plugins/common/src/gamesession.cpp +++ b/doomsday/plugins/common/src/gamesession.cpp @@ -476,16 +476,18 @@ DENG2_PIMPL(GameSession), public SavedSession::IMapStateReaderFactory DENG2_ASSERT(inProgress); ::gameMapUri = mapUri; - // Check that the map truly exists. if(!P_MapExists(::gameMapUri.compose().toUtf8().constData())) { ::gameMapUri = G_ComposeMapUri(0, 0); // Should exist always? } + // Determine the episode for the map (should come from MapInfo). + ::gameEpisode = G_EpisodeNumberFor(::gameMapUri); + // Update game status cvars: - Con_SetInteger2("map-id", (unsigned)G_CurrentMapNumber(), SVF_WRITE_OVERRIDE); - Con_SetInteger2("map-episode", (unsigned)G_CurrentEpisodeNumber(), SVF_WRITE_OVERRIDE); + Con_SetInteger2("map-episode", (unsigned)::gameEpisode, SVF_WRITE_OVERRIDE); + Con_SetInteger2("map-id", (unsigned)G_CurrentMapNumber(), SVF_WRITE_OVERRIDE); } /** diff --git a/doomsday/plugins/common/src/p_xgline.cpp b/doomsday/plugins/common/src/p_xgline.cpp index 28d4d9cca6..ffc644c441 100644 --- a/doomsday/plugins/common/src/p_xgline.cpp +++ b/doomsday/plugins/common/src/p_xgline.cpp @@ -2086,7 +2086,7 @@ int XLTrav_LineTeleport(Line *newLine, dd_bool /*ceiling*/, void *context, dd_bool XL_ValidateMap(uint *map, int /*type*/) { // Check that the map truly exists. - if(P_MapExists(G_ComposeMapUri(G_CurrentEpisodeNumber(), *map).compose().toUtf8().constData())) + if(P_MapExists(G_ComposeMapUri(::gameEpisode, *map).compose().toUtf8().constData())) return true; XG_Dev("XLTrav_LeaveMap: NOT A VALID MAP NUMBER %u, next will be map 1", *map); @@ -2142,7 +2142,7 @@ int XLTrav_LeaveMap(Line *line, dd_bool /*ceiling*/, void * /*context*/, if(mapSpecified) { XG_Dev("XLTrav_LeaveMap: Next map set to %u", map+1); - newMapUri = G_ComposeMapUri(G_CurrentEpisodeNumber(), map); + newMapUri = G_ComposeMapUri(::gameEpisode, map); } else { diff --git a/doomsday/plugins/doom/src/p_enemy.c b/doomsday/plugins/doom/src/p_enemy.c index 0be874f6ba..2a55be8f8e 100644 --- a/doomsday/plugins/doom/src/p_enemy.c +++ b/doomsday/plugins/doom/src/p_enemy.c @@ -1563,17 +1563,17 @@ void C_DECL A_BossDeath(mobj_t *mo) * Many classic PWADS such as "Doomsday of UAC" (UAC_DEAD.wad) rely on the * old behavior. Episode 4 is exempt by PrBoom's precedent. */ - else if(cfg.anyBossDeath && G_CurrentEpisodeNumber() < 3) + else if(cfg.anyBossDeath && gameEpisode < 3) { if(G_CurrentMapNumber() != 7) return; - if(G_CurrentEpisodeNumber() != 0 && mo->type == MT_BRUISER) + if(gameEpisode != 0 && mo->type == MT_BRUISER) return; } else { - switch(G_CurrentEpisodeNumber()) + switch(gameEpisode) { case 0: if(G_CurrentMapNumber() != 7) @@ -1669,7 +1669,7 @@ void C_DECL A_BossDeath(mobj_t *mo) } else { - if(G_CurrentEpisodeNumber() == 0) + if(gameEpisode == 0) { Line *dummyLine = P_AllocDummyLine(); P_ToXLine(dummyLine)->tag = 666; @@ -1678,7 +1678,7 @@ void C_DECL A_BossDeath(mobj_t *mo) return; } - if(G_CurrentEpisodeNumber() == 3) + if(gameEpisode == 3) { if(G_CurrentMapNumber() == 5) { diff --git a/doomsday/plugins/doom/src/wi_stuff.cpp b/doomsday/plugins/doom/src/wi_stuff.cpp index 431f968e8d..b122289a5e 100644 --- a/doomsday/plugins/doom/src/wi_stuff.cpp +++ b/doomsday/plugins/doom/src/wi_stuff.cpp @@ -232,15 +232,14 @@ static void drawBackground() GL_DrawPatchXY3(pBackground, 0, 0, ALIGN_TOPLEFT, DPF_NO_OFFSET); - uint const episode = G_EpisodeNumberFor(wbs->currentMap); - if(!(gameModeBits & GM_ANY_DOOM2) && episode < 3) + if(!(gameModeBits & GM_ANY_DOOM2) && ::gameEpisode < 3) { FR_SetFont(FID(GF_FONTB)); FR_LoadDefaultAttrib(); - for(int i = 0; i < animCounts[episode]; ++i) + for(int i = 0; i < animCounts[::gameEpisode]; ++i) { - wianimdef_t const *def = &animDefs[episode][i]; + wianimdef_t const *def = &animDefs[::gameEpisode][i]; wianimstate_t *state = &animStates[i]; // Has the animation begun yet? @@ -372,12 +371,11 @@ static void beginAnimations() { if(gameModeBits & GM_ANY_DOOM2) return; - uint const episode = G_EpisodeNumberFor(wbs->currentMap); - if(episode > 2) return; + if(::gameEpisode > 2) return; - for(int i = 0; i < animCounts[episode]; ++i) + for(int i = 0; i < animCounts[::gameEpisode]; ++i) { - wianimdef_t const *def = &animDefs[episode][i]; + wianimdef_t const *def = &animDefs[::gameEpisode][i]; wianimstate_t *state = &animStates[i]; // Is the animation active for the current map? @@ -408,12 +406,11 @@ static void animateBackground() { if(gameModeBits & GM_ANY_DOOM2) return; - uint const episode = G_EpisodeNumberFor(wbs->currentMap); - if(episode > 2) return; + if(::gameEpisode > 2) return; - for(int i = 0; i < animCounts[episode]; ++i) + for(int i = 0; i < animCounts[::gameEpisode]; ++i) { - wianimdef_t const *def = &animDefs[episode][i]; + wianimdef_t const *def = &animDefs[::gameEpisode][i]; wianimstate_t *state = &animStates[i]; // Is the animation active for the current map? @@ -541,9 +538,7 @@ static void tickShowNextMap() static void drawLocationMarks() { - uint const episode = G_EpisodeNumberFor(wbs->currentMap); - - if((gameModeBits & GM_ANY_DOOM) && episode < 3) + if((gameModeBits & GM_ANY_DOOM) && ::gameEpisode < 3) { DGL_Enable(DGL_TEXTURE_2D); DGL_Color4f(1, 1, 1, 1); @@ -556,18 +551,18 @@ static void drawLocationMarks() for(int i = 0; i <= last; ++i) { - drawPatchIfFits(pSplat, &locations[episode][i]); + drawPatchIfFits(pSplat, &locations[::gameEpisode][i]); } // Splat the secret map? if(wbs->didSecret) { - drawPatchIfFits(pSplat, &locations[episode][8]); + drawPatchIfFits(pSplat, &locations[::gameEpisode][8]); } if(drawYouAreHere) { - Point2Raw const *origin = &locations[episode][G_MapNumberFor(wbs->nextMap)]; + Point2Raw const *origin = &locations[::gameEpisode][G_MapNumberFor(wbs->nextMap)]; patchid_t const patchId = chooseYouAreHerePatch(origin); if(patchId) { @@ -1276,30 +1271,28 @@ void WI_Ticker() static void loadData() { - uint const episode = G_EpisodeNumberFor(wbs->currentMap); - - if((gameModeBits & GM_ANY_DOOM2) || (gameMode == doom_ultimate && episode > 2)) + if((gameModeBits & GM_ANY_DOOM2) || (gameMode == doom_ultimate && ::gameEpisode > 2)) { pBackground = R_DeclarePatch("INTERPIC"); } else { - char name[9]; sprintf(name, "WIMAP%u", episode); + char name[9]; sprintf(name, "WIMAP%u", ::gameEpisode); pBackground = R_DeclarePatch(name); } - if((gameModeBits & GM_ANY_DOOM) && episode < 3) + if((gameModeBits & GM_ANY_DOOM) && ::gameEpisode < 3) { pYouAreHereRight = R_DeclarePatch("WIURH0"); pYouAreHereLeft = R_DeclarePatch("WIURH1"); pSplat = R_DeclarePatch("WISPLAT"); - animStates = (wianimstate_t *)Z_Realloc(animStates, sizeof(*animStates) * animCounts[episode], PU_GAMESTATIC); - std::memset(animStates, 0, sizeof(*animStates) * animCounts[episode]); + animStates = (wianimstate_t *)Z_Realloc(animStates, sizeof(*animStates) * animCounts[::gameEpisode], PU_GAMESTATIC); + std::memset(animStates, 0, sizeof(*animStates) * animCounts[::gameEpisode]); - for(int i = 0; i < animCounts[episode]; ++i) + for(int i = 0; i < animCounts[::gameEpisode]; ++i) { - wianimdef_t const *def = &animDefs[episode][i]; + wianimdef_t const *def = &animDefs[::gameEpisode][i]; wianimstate_t *state = &animStates[i]; state->frame = -1; // Not yet begun. diff --git a/doomsday/plugins/heretic/src/in_lude.cpp b/doomsday/plugins/heretic/src/in_lude.cpp index 47aeea8b9c..b2e004d6a6 100644 --- a/doomsday/plugins/heretic/src/in_lude.cpp +++ b/doomsday/plugins/heretic/src/in_lude.cpp @@ -362,11 +362,9 @@ void IN_InitStats() void IN_LoadPics() { - uint const episode = G_EpisodeNumberFor(wbs->currentMap); - - if(episode < 3) + if(::gameEpisode < 3) { - dpInterPic = R_DeclarePatch(episode == 0? "MAPE1" : episode == 1? "MAPE2" : "MAPE3"); + dpInterPic = R_DeclarePatch(::gameEpisode == 0? "MAPE1" : ::gameEpisode == 1? "MAPE2" : "MAPE3"); } dpBeenThere = R_DeclarePatch("IN_X"); @@ -417,8 +415,6 @@ void IN_Ticker() } IN_CheckForSkip(); - uint const episode = G_EpisodeNumberFor(wbs->currentMap); - // Counter for general background animation. bcnt++; @@ -427,7 +423,7 @@ void IN_Ticker() { nextIntermissionState(); - if(episode > 2 && interState >= 1) + if(::gameEpisode > 2 && interState >= 1) { // Extended Wad levels: skip directly to the next level endIntermissionGoToNextLevel(); @@ -437,7 +433,7 @@ void IN_Ticker() { case 0: oldInterTime = interTime + 300; - if(episode > 2) + if(::gameEpisode > 2) { oldInterTime = interTime + 1200; } @@ -469,7 +465,7 @@ void IN_Ticker() NetSv_Intermission(IMF_TIME, 0, interTime); return; } - if(interState < 2 && episode < 3) + if(interState < 2 && ::gameEpisode < 3) { interState = 2; skipIntermission = false; @@ -558,8 +554,6 @@ void IN_Drawer() return; }*/ - uint const episode = G_EpisodeNumberFor(wbs->currentMap); - if(oldInterState != 2 && interState == 2) { S_LocalSound(SFX_PSTOP, NULL); @@ -593,7 +587,7 @@ void IN_Drawer() break; case 1: // Leaving old level. - if(episode < 3) + if(::gameEpisode < 3) { DGL_Enable(DGL_TEXTURE_2D); @@ -607,7 +601,7 @@ void IN_Drawer() break; case 2: // Going to the next level. - if(episode < 3) + if(::gameEpisode < 3) { DGL_Enable(DGL_TEXTURE_2D); @@ -620,7 +614,7 @@ void IN_Drawer() break; case 3: // Waiting before going to the next level. - if(episode < 3) + if(::gameEpisode < 3) { DGL_Enable(DGL_TEXTURE_2D); @@ -664,20 +658,18 @@ void IN_DrawOldLevel() FR_SetColor(defFontRGB3[0], defFontRGB3[1],defFontRGB3[2]); FR_DrawTextXY3("FINISHED", 160, 25, ALIGN_TOP, DTF_ONLY_SHADOW); - uint const episode = G_EpisodeNumberFor(wbs->currentMap); - if(G_MapNumberFor(wbs->currentMap) == 8) { DGL_Color4f(1, 1, 1, 1); uint const nextMap = G_MapNumberFor(wbs->nextMap); for(uint i = 0; i < nextMap; ++i) { - GL_DrawPatch(dpBeenThere, &YAHspot[episode][i]); + GL_DrawPatch(dpBeenThere, &YAHspot[::gameEpisode][i]); } if(!(interTime & 16)) { - GL_DrawPatch(dpBeenThere, &YAHspot[episode][8]); + GL_DrawPatch(dpBeenThere, &YAHspot[::gameEpisode][8]); } } else @@ -686,17 +678,17 @@ void IN_DrawOldLevel() uint const currentMap = G_MapNumberFor(wbs->currentMap); for(uint i = 0; i < currentMap; ++i) { - GL_DrawPatch(dpBeenThere, &YAHspot[episode][i]); + GL_DrawPatch(dpBeenThere, &YAHspot[::gameEpisode][i]); } if(players[CONSOLEPLAYER].didSecret) { - GL_DrawPatch(dpBeenThere, &YAHspot[episode][8]); + GL_DrawPatch(dpBeenThere, &YAHspot[::gameEpisode][8]); } if(!(interTime & 16)) { - GL_DrawPatch(dpBeenThere, &YAHspot[episode][currentMap]); + GL_DrawPatch(dpBeenThere, &YAHspot[::gameEpisode][currentMap]); } } @@ -716,23 +708,22 @@ void IN_DrawYAH() DGL_Color4f(1, 1, 1, 1); - uint const episode = G_EpisodeNumberFor(wbs->currentMap); uint const nextMap = G_MapNumberFor(wbs->nextMap); for(uint i = 0; i < nextMap; ++i) { - GL_DrawPatch(dpBeenThere, &YAHspot[episode][i]); + GL_DrawPatch(dpBeenThere, &YAHspot[::gameEpisode][i]); } if(players[CONSOLEPLAYER].didSecret) { - GL_DrawPatch(dpBeenThere, &YAHspot[episode][8]); + GL_DrawPatch(dpBeenThere, &YAHspot[::gameEpisode][8]); } if(!(interTime & 16) || interState == 3) { // Draw the destination 'X' - GL_DrawPatch(dpGoingThere, &YAHspot[episode][nextMap]); + GL_DrawPatch(dpGoingThere, &YAHspot[::gameEpisode][nextMap]); } } @@ -842,9 +833,7 @@ void IN_DrawSingleStats() sounds++; } - uint const episode = G_EpisodeNumberFor(wbs->currentMap); - - if(gameMode != heretic_extended || episode < 3) + if(gameMode != heretic_extended || ::gameEpisode < 3) { DGL_Enable(DGL_TEXTURE_2D); diff --git a/doomsday/plugins/heretic/src/p_enemy.c b/doomsday/plugins/heretic/src/p_enemy.c index 04412fb514..8a27164113 100644 --- a/doomsday/plugins/heretic/src/p_enemy.c +++ b/doomsday/plugins/heretic/src/p_enemy.c @@ -2122,7 +2122,7 @@ void C_DECL A_BossDeath(mobj_t *actor) return; // Not considered a boss in this episode? - if(actor->type != bossType[G_CurrentEpisodeNumber()]) + if(actor->type != bossType[gameEpisode]) return; // Scan the remaining thinkers to see if all bosses are dead. @@ -2136,7 +2136,7 @@ void C_DECL A_BossDeath(mobj_t *actor) } // Kill any remaining monsters. - if(G_CurrentEpisodeNumber() != 0) + if(gameEpisode != 0) P_Massacre(); dummyLine = P_AllocDummyLine(); diff --git a/doomsday/plugins/hexen/src/p_spec.cpp b/doomsday/plugins/hexen/src/p_spec.cpp index e75d484a58..ae4eb62d9b 100644 --- a/doomsday/plugins/hexen/src/p_spec.cpp +++ b/doomsday/plugins/hexen/src/p_spec.cpp @@ -199,7 +199,7 @@ dd_bool EV_LineSearchForPuzzleItem(Line *line, byte * /*args*/, mobj_t *mo) static de::Uri mapUriFromLogicalNumber(int number) { if(!number) return gameMapUri; // current map. - return G_ComposeMapUri(G_CurrentEpisodeNumber(), number - 1); + return G_ComposeMapUri(::gameEpisode, number - 1); } dd_bool P_StartLockedACS(Line *line, byte *args, mobj_t *mo, int side) @@ -477,7 +477,7 @@ dd_bool P_ExecuteLineSpecial(int special, byte args[5], Line *line, int side, mo // Players must be alive to teleport if(!(mo && mo->player && mo->player->playerState == PST_DEAD)) { - G_SetGameActionMapCompleted(G_ComposeMapUri(G_CurrentEpisodeNumber(), args[0]!= 0? args[0]-1 : 0), + G_SetGameActionMapCompleted(G_ComposeMapUri(::gameEpisode, args[0]!= 0? args[0]-1 : 0), args[1], false); success = true; } @@ -493,8 +493,8 @@ dd_bool P_ExecuteLineSpecial(int special, byte args[5], Line *line, int side, mo success = true; if(G_Ruleset_Deathmatch()) { - // Winning in deathmatch just goes back to map 1 - G_SetGameActionMapCompleted(0, 0, false); + // Winning in deathmatch goes back to the first map of the episode. + G_SetGameActionMapCompleted(G_ComposeMapUri(::gameEpisode, 0), 0, false); } else {