Skip to content

Commit a4cc887

Browse files
add a "prev map" key binding
Fixes #2007
1 parent 6cf2f26 commit a4cc887

File tree

5 files changed

+62
-0
lines changed

5 files changed

+62
-0
lines changed

src/g_game.c

+47
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,53 @@ int G_GotoNextLevel(int *pEpi, int *pMap)
11601160
return false;
11611161
}
11621162

1163+
int G_GotoPrevLevel(void)
1164+
{
1165+
const int cur_epsd = gameepisode;
1166+
const int cur_map = gamemap;
1167+
int epsd_count, map_count;
1168+
int ret = false;
1169+
1170+
for (epsd_count = 0; epsd_count < 10; epsd_count++, gameepisode = (gameepisode + 9) % 10)
1171+
{
1172+
for (map_count= 0, gamemap--; map_count < 100; map_count++, gamemap = (gamemap + 99) % 100)
1173+
{
1174+
int next_epsd, next_map;
1175+
G_GotoNextLevel(&next_epsd, &next_map);
1176+
1177+
if (next_epsd == cur_epsd && next_map == cur_map &&
1178+
(gameepisode != cur_epsd || gamemap != cur_map))
1179+
{
1180+
char *name = MapName(gameepisode, gamemap);
1181+
1182+
if (W_CheckNumForName(name) != -1)
1183+
{
1184+
G_DeferedInitNew(gameskill, gameepisode, gamemap);
1185+
ret = true;
1186+
break;
1187+
}
1188+
}
1189+
}
1190+
1191+
// only check one episode in Doom 2
1192+
if (gamemode == commercial)
1193+
{
1194+
break;
1195+
}
1196+
}
1197+
1198+
gameepisode = cur_epsd;
1199+
gamemap = cur_map;
1200+
1201+
if (ret == false)
1202+
{
1203+
char *name = MapName(gameepisode, gamemap);
1204+
displaymsg("Previous level not found for %s", name);
1205+
}
1206+
1207+
return ret;
1208+
}
1209+
11631210
static boolean G_StrictModeSkipEvent(event_t *ev)
11641211
{
11651212
static boolean enable_mouse = false;

src/g_game.h

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ demo_version_t G_GetNamedComplevel(const char *arg);
8484
const char *G_GetCurrentComplevelName(void);
8585

8686
int G_GotoNextLevel(int *pEpi, int *pMap);
87+
int G_GotoPrevLevel(void);
8788

8889
void G_BindGameInputVariables(void);
8990
void G_BindGameVariables(void);

src/m_input.c

+1
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,7 @@ void M_BindInputVariables(void)
702702

703703
BIND_INPUT(input_menu_reloadlevel, "Restart current level/demo");
704704
BIND_INPUT(input_menu_nextlevel, "Go to next level");
705+
BIND_INPUT(input_menu_prevlevel, "Go to previous level");
705706

706707
BIND_INPUT(input_hud_timestats, "Toggle display of level stats and time");
707708

src/m_input.h

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ enum
6868
input_menu_clear,
6969
input_menu_reloadlevel,
7070
input_menu_nextlevel,
71+
input_menu_prevlevel,
7172

7273
input_hud_timestats,
7374

src/mn_menu.c

+12
Original file line numberDiff line numberDiff line change
@@ -2608,6 +2608,18 @@ boolean M_ShortcutResponder(const event_t *ev)
26082608
}
26092609
}
26102610

2611+
if (M_InputActivated(input_menu_prevlevel))
2612+
{
2613+
if (demoplayback && singledemo && !PLAYBACK_SKIP)
2614+
{
2615+
return false;
2616+
}
2617+
else if (G_GotoPrevLevel())
2618+
{
2619+
return true;
2620+
}
2621+
}
2622+
26112623
if (M_InputActivated(input_demo_fforward))
26122624
{
26132625
if (demoplayback && !PLAYBACK_SKIP && !fastdemo && !D_CheckNetConnect())

0 commit comments

Comments
 (0)