//------------------------------------------------------------------------- /* Copyright (C) 2010-2019 EDuke32 developers and contributors Copyright (C) 2019 Nuke.YKT This file is part of NBlood. NBlood is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ //------------------------------------------------------------------------- #include "ns.h" // Must come before everything else! #include "build.h" #include "baselayer.h" #include "keyboard.h" #include "control.h" #include "osd.h" #include "compat.h" #include "mmulti.h" #include "sndcards.h" #include "common_game.h" #include "config.h" #include "blood.h" #include "demo.h" #include "gamemenu.h" #include "globals.h" #include "levels.h" #include "messages.h" #include "network.h" #include "osdcmds.h" #include "screen.h" #include "sound.h" #include "sfx.h" #include "view.h" BEGIN_BLD_NS static int osdcmd_changelevel(osdcmdptr_t parm) { int32_t volume,level; char *p; if (parm->numparms != 2) return OSDCMD_SHOWHELP; volume = strtol(parm->parms[0], &p, 10) - 1; if (p[0]) return OSDCMD_SHOWHELP; level = strtol(parm->parms[1], &p, 10) - 1; if (p[0]) return OSDCMD_SHOWHELP; if (volume < 0) return OSDCMD_SHOWHELP; if (level < 0) return OSDCMD_SHOWHELP; if (volume >= 6) { OSD_Printf("changelevel: invalid volume number (range 1-%d)\n",6); return OSDCMD_OK; } if (level >= gEpisodeInfo[volume].nLevels) { OSD_Printf("changelevel: invalid level number\n"); return OSDCMD_SHOWHELP; } if (gDemo.at1) gDemo.StopPlayback(); if (numplayers > 1) { gPacketStartGame.episodeId = volume; gPacketStartGame.levelId = level; netBroadcastNewGame(); gStartNewGame = 1; return OSDCMD_OK; } levelSetupOptions(volume, level); StartLevel(&gGameOptions); viewResizeView(gViewSize); return OSDCMD_OK; } static int osdcmd_map(osdcmdptr_t parm) { char filename[BMAX_PATH]; strcpy(filename, parm->parms[0]); ChangeExtension(filename, ""); if (!gSysRes.Lookup(filename, "MAP")) { OSD_Printf(OSD_ERROR "map: file \"%s\" not found.\n", filename); return OSDCMD_OK; } if (gDemo.at1) gDemo.StopPlayback(); levelAddUserMap(filename); if (numplayers > 1) { gPacketStartGame.episodeId = gGameOptions.nEpisode; gPacketStartGame.levelId = gGameOptions.nLevel; netBroadcastNewGame(); gStartNewGame = 1; return OSDCMD_OK; } levelSetupOptions(gGameOptions.nEpisode, gGameOptions.nLevel); StartLevel(&gGameOptions); viewResizeView(gViewSize); return OSDCMD_OK; } static int osdcmd_demo(osdcmdptr_t parm) { if (numplayers > 1) { OSD_Printf("Command not allowed in multiplayer\n"); return OSDCMD_OK; } //if (g_player[myconnectindex].ps->gm & MODE_GAME) //{ // OSD_Printf("demo: Must not be in a game.\n"); // return OSDCMD_OK; //} if (parm->numparms != 1/* && parm->numparms != 2*/) return OSDCMD_SHOWHELP; gDemo.SetupPlayback(parm->parms[0]); gGameStarted = 0; gDemo.Playback(); return OSDCMD_OK; } static int osdcmd_vidmode(osdcmdptr_t parm) { int32_t newbpp = ScreenBPP, newwidth = ScreenWidth, newheight = ScreenHeight, newfs = ScreenMode; int32_t tmp; if (parm->numparms < 1 || parm->numparms > 4) return OSDCMD_SHOWHELP; switch (parm->numparms) { case 1: // bpp switch tmp = Batol(parm->parms[0]); if (!(tmp==8 || tmp==16 || tmp==32)) return OSDCMD_SHOWHELP; newbpp = tmp; break; case 2: // res switch newwidth = Batol(parm->parms[0]); newheight = Batol(parm->parms[1]); break; case 3: // res & bpp switch case 4: newwidth = Batol(parm->parms[0]); newheight = Batol(parm->parms[1]); tmp = Batol(parm->parms[2]); if (!(tmp==8 || tmp==16 || tmp==32)) return OSDCMD_SHOWHELP; newbpp = tmp; if (parm->numparms == 4) newfs = (Batol(parm->parms[3]) != 0); break; } if (videoSetGameMode(newfs,newwidth,newheight,newbpp,upscalefactor)) { initprintf("vidmode: Mode change failed!\n"); if (videoSetGameMode(ScreenMode, ScreenWidth, ScreenHeight, ScreenBPP, upscalefactor)) ThrowError("vidmode: Reset failed!\n"); } ScreenBPP = newbpp; ScreenWidth = newwidth; ScreenHeight = newheight; ScreenMode = newfs; onvideomodechange(ScreenBPP>8); viewResizeView(gViewSize); return OSDCMD_OK; } static int osdcmd_crosshaircolor(osdcmdptr_t parm) { if (parm->numparms != 3) { OSD_Printf("crosshaircolor: r:%d g:%d b:%d\n",CrosshairColors.r,CrosshairColors.g,CrosshairColors.b); return OSDCMD_SHOWHELP; } uint8_t const r = Batol(parm->parms[0]); uint8_t const g = Batol(parm->parms[1]); uint8_t const b = Batol(parm->parms[2]); g_isAlterDefaultCrosshair = true; viewSetCrosshairColor(r,g,b); OSD_Printf("%s\n", parm->raw); return OSDCMD_OK; } static int osdcmd_resetcrosshair(osdcmdptr_t UNUSED(parm)) { UNREFERENCED_CONST_PARAMETER(parm); g_isAlterDefaultCrosshair = false; viewResetCrosshairToDefault(); return OSDCMD_OK; } static int osdcmd_give(osdcmdptr_t parm) { if (numplayers != 1 || !gGameStarted || gMe->pXSprite->health == 0) { OSD_Printf("give: Cannot give while dead or not in a single-player game.\n"); return OSDCMD_OK; } if (parm->numparms != 1) return OSDCMD_SHOWHELP; if (!Bstrcasecmp(parm->parms[0], "all")) { SetWeapons(true); SetAmmo(true); SetToys(true); SetArmor(true); SetKeys(true); gCheatMgr.m_bPlayerCheated = true; return OSDCMD_OK; } else if (!Bstrcasecmp(parm->parms[0], "health")) { actHealDude(gMe->pXSprite, 200, 200); gCheatMgr.m_bPlayerCheated = true; return OSDCMD_OK; } else if (!Bstrcasecmp(parm->parms[0], "weapons")) { SetWeapons(true); gCheatMgr.m_bPlayerCheated = true; return OSDCMD_OK; } else if (!Bstrcasecmp(parm->parms[0], "ammo")) { SetAmmo(true); gCheatMgr.m_bPlayerCheated = true; return OSDCMD_OK; } else if (!Bstrcasecmp(parm->parms[0], "armor")) { SetArmor(true); gCheatMgr.m_bPlayerCheated = true; return OSDCMD_OK; } else if (!Bstrcasecmp(parm->parms[0], "keys")) { SetKeys(true); gCheatMgr.m_bPlayerCheated = true; return OSDCMD_OK; } else if (!Bstrcasecmp(parm->parms[0], "inventory")) { SetToys(true); gCheatMgr.m_bPlayerCheated = true; return OSDCMD_OK; } return OSDCMD_SHOWHELP; } static int osdcmd_god(osdcmdptr_t UNUSED(parm)) { UNREFERENCED_CONST_PARAMETER(parm); if (numplayers == 1 && gGameStarted) { SetGodMode(!gMe->godMode); gCheatMgr.m_bPlayerCheated = true; } else OSD_Printf("god: Not in a single-player game.\n"); return OSDCMD_OK; } static int osdcmd_noclip(osdcmdptr_t UNUSED(parm)) { UNREFERENCED_CONST_PARAMETER(parm); if (numplayers == 1 && gGameStarted) { SetClipMode(!gNoClip); gCheatMgr.m_bPlayerCheated = true; } else { OSD_Printf("noclip: Not in a single-player game.\n"); } return OSDCMD_OK; } static int osdcmd_restartsound(osdcmdptr_t UNUSED(parm)) { UNREFERENCED_CONST_PARAMETER(parm); sfxTerm(); sndTerm(); sndInit(); sfxInit(); return OSDCMD_OK; } void onvideomodechange(int32_t newmode) { UNREFERENCED_PARAMETER(newmode); if (newmode) scrResetPalette(); UpdateDacs(gLastPal, false); } int32_t registerosdcommands(void) { OSD_RegisterFunction("changelevel","changelevel : warps to the given level", osdcmd_changelevel); OSD_RegisterFunction("map","map : loads the given user map", osdcmd_map); OSD_RegisterFunction("demo","demo : starts the given demo", osdcmd_demo); OSD_RegisterFunction("crosshaircolor","crosshaircolor: changes the crosshair color", osdcmd_crosshaircolor); OSD_RegisterFunction("crosshairreset", "crosshairreset: restores the original crosshair", osdcmd_resetcrosshair); OSD_RegisterFunction("give","give : gives requested item", osdcmd_give); OSD_RegisterFunction("god","god: toggles god mode", osdcmd_god); OSD_RegisterFunction("noclip","noclip: toggles clipping mode", osdcmd_noclip); OSD_RegisterFunction("restartsound","restartsound: reinitializes the sound system",osdcmd_restartsound); OSD_RegisterFunction("vidmode","vidmode : change the video mode",osdcmd_vidmode); return 0; } END_BLD_NS