From b1713d7e675113b9d257bfb1d42ca51f09b451f0 Mon Sep 17 00:00:00 2001 From: nukeykt Date: Tue, 24 Sep 2019 11:14:59 +0900 Subject: [PATCH] Add quickload/save osdcmd --- source/blood/src/blood.cpp | 109 ++++++++++++++++++++++-------------- source/blood/src/blood.h | 1 + source/blood/src/osdcmd.cpp | 36 +++++++++++- 3 files changed, 103 insertions(+), 43 deletions(-) diff --git a/source/blood/src/blood.cpp b/source/blood/src/blood.cpp index 9bc5186cd..433a8bf74 100644 --- a/source/blood/src/blood.cpp +++ b/source/blood/src/blood.cpp @@ -744,6 +744,40 @@ void StartNetworkLevel(void) StartLevel(&gGameOptions); } +int gDoQuickSave = 0; + +static void DoQuickLoad(void) +{ + if (!gGameMenuMgr.m_bActive) + { + if (gQuickLoadSlot != -1) + { + QuickLoadGame(); + return; + } + if (gQuickLoadSlot == -1 && gQuickSaveSlot != -1) + { + gQuickLoadSlot = gQuickSaveSlot; + QuickLoadGame(); + return; + } + gGameMenuMgr.Push(&menuLoadGame,-1); + } +} + +static void DoQuickSave(void) +{ + if (gGameStarted && !gGameMenuMgr.m_bActive && gPlayer[myconnectindex].pXSprite->health != 0) + { + if (gQuickSaveSlot != -1) + { + QuickSaveGame(); + return; + } + gGameMenuMgr.Push(&menuSaveGame,-1); + } +} + void LocalKeys(void) { char alt = keystatus[sc_LeftAlt] | keystatus[sc_RightAlt]; @@ -781,12 +815,27 @@ void LocalKeys(void) gView = &gPlayer[gViewIndex]; } } + if (gDoQuickSave) + { + keyFlushScans(); + switch (gDoQuickSave) + { + case 1: + DoQuickSave(); + break; + case 2: + DoQuickLoad(); + break; + } + gDoQuickSave = 0; + return; + } char key; if ((key = keyGetScan()) != 0) { - if ((alt || shift) && gGameOptions.nGameType > 0 && key >= 0x3b && key <= 0x44) + if ((alt || shift) && gGameOptions.nGameType > 0 && key >= sc_F1 && key <= sc_F10) { - char fk = key - 0x3b; + char fk = key - sc_F1; if (alt) { netBroadcastTaunt(myconnectindex, fk); @@ -798,20 +847,20 @@ void LocalKeys(void) } keyFlushScans(); keystatus[key] = 0; - CONTROL_ClearButton(41); + CONTROL_ClearButton(gamefunc_See_Chase_View); return; } switch (key) { - case 0x53: - case 0xd3: + case sc_kpad_Period: + case sc_Delete: if (ctrl && alt) { gQuitGame = 1; return; } break; - case 0x01: + case sc_Escape: keyFlushScans(); if (gGameStarted && gPlayer[myconnectindex].pXSprite->health != 0) { @@ -824,73 +873,51 @@ void LocalKeys(void) gGameMenuMgr.Push(&menuMain,-1); } return; - case 0x3b: + case sc_F1: keyFlushScans(); if (gGameOptions.nGameType == 0) gGameMenuMgr.Push(&menuOrder,-1); break; - case 0x3c: + case sc_F2: keyFlushScans(); if (!gGameMenuMgr.m_bActive && gGameOptions.nGameType == 0) gGameMenuMgr.Push(&menuSaveGame,-1); break; - case 0x3d: + case sc_F3: keyFlushScans(); if (!gGameMenuMgr.m_bActive && gGameOptions.nGameType == 0) gGameMenuMgr.Push(&menuLoadGame,-1); break; - case 0x3e: + case sc_F4: keyFlushScans(); if (!gGameMenuMgr.m_bActive) gGameMenuMgr.Push(&menuOptionsSound,-1); return; - case 0x3f: + case sc_F5: keyFlushScans(); if (!gGameMenuMgr.m_bActive) gGameMenuMgr.Push(&menuOptions,-1); return; - case 0x40: + case sc_F6: keyFlushScans(); - if (gGameStarted && !gGameMenuMgr.m_bActive && gPlayer[myconnectindex].pXSprite->health != 0) - { - if (gQuickSaveSlot != -1) - { - QuickSaveGame(); - return; - } - gGameMenuMgr.Push(&menuSaveGame,-1); - } + DoQuickSave(); break; - case 0x42: + case sc_F8: keyFlushScans(); gGameMenuMgr.Push(&menuOptions,-1); break; - case 0x43: + case sc_F9: keyFlushScans(); - if (!gGameMenuMgr.m_bActive) - { - if (gQuickLoadSlot != -1) - { - QuickLoadGame(); - return; - } - if (gQuickLoadSlot == -1 && gQuickSaveSlot != -1) - { - gQuickLoadSlot = gQuickSaveSlot; - QuickLoadGame(); - return; - } - gGameMenuMgr.Push(&menuLoadGame,-1); - } + DoQuickLoad(); break; - case 0x44: + case sc_F10: keyFlushScans(); if (!gGameMenuMgr.m_bActive) gGameMenuMgr.Push(&menuQuit,-1); break; - case 0x57: + case sc_F11: break; - case 0x58: + case sc_F12: videoCaptureScreen("blud0000.tga", 0); break; } diff --git a/source/blood/src/blood.h b/source/blood/src/blood.h index 5d033c2e9..640b816f2 100644 --- a/source/blood/src/blood.h +++ b/source/blood/src/blood.h @@ -71,6 +71,7 @@ extern bool gSavingGame; extern bool gQuitGame; extern int gQuitRequest; extern int gCacheMiss; +extern int gDoQuickSave; void QuitGame(void); void PreloadCache(void); diff --git a/source/blood/src/osdcmd.cpp b/source/blood/src/osdcmd.cpp index 2fb6742a5..d8341e3ee 100644 --- a/source/blood/src/osdcmd.cpp +++ b/source/blood/src/osdcmd.cpp @@ -690,6 +690,37 @@ static int osdcmd_unbind(osdcmdptr_t parm) return OSDCMD_SHOWHELP; } +static int osdcmd_unbound(osdcmdptr_t parm) +{ + if (parm->numparms != 1) + return OSDCMD_OK; + + int const gameFunc = CONFIG_FunctionNameToNum(parm->parms[0]); + + if (gameFunc != -1) + KeyboardKeys[gameFunc][0] = 0; + + return OSDCMD_OK; +} + +static int osdcmd_quicksave(osdcmdptr_t UNUSED(parm)) +{ + UNREFERENCED_CONST_PARAMETER(parm); + if (!gGameStarted || gDemo.at1 || gGameMenuMgr.m_bActive) + OSD_Printf("quicksave: not in a game.\n"); + else gDoQuickSave = 1; + return OSDCMD_OK; +} + +static int osdcmd_quickload(osdcmdptr_t UNUSED(parm)) +{ + UNREFERENCED_CONST_PARAMETER(parm); + if (!gGameStarted || gDemo.at1 || gGameMenuMgr.m_bActive) + OSD_Printf("quickload: not in a game.\n"); + else gDoQuickSave = 2; + return OSDCMD_OK; +} + static int osdcmd_screenshot(osdcmdptr_t parm) { static const char *fn = "blud0000.png"; @@ -1109,8 +1140,8 @@ int32_t registerosdcommands(void) // // OSD_RegisterFunction("purgesaves", "purgesaves: deletes obsolete and unreadable save files", osdcmd_purgesaves); // -// OSD_RegisterFunction("quicksave","quicksave: performs a quick save", osdcmd_quicksave); -// OSD_RegisterFunction("quickload","quickload: performs a quick load", osdcmd_quickload); + OSD_RegisterFunction("quicksave","quicksave: performs a quick save", osdcmd_quicksave); + OSD_RegisterFunction("quickload","quickload: performs a quick load", osdcmd_quickload); OSD_RegisterFunction("quit","quit: exits the game immediately", osdcmd_quit); OSD_RegisterFunction("exit","exit: exits the game immediately", osdcmd_quit); // @@ -1131,6 +1162,7 @@ int32_t registerosdcommands(void) OSD_RegisterFunction("unbind","unbind : unbinds a key", osdcmd_unbind); OSD_RegisterFunction("unbindall","unbindall: unbinds all keys", osdcmd_unbindall); + OSD_RegisterFunction("unbound", NULL, osdcmd_unbound); OSD_RegisterFunction("vidmode","vidmode : change the video mode",osdcmd_vidmode); #ifdef USE_OPENGL