diff --git a/doomsday/plugins/common/src/g_game.c b/doomsday/plugins/common/src/g_game.c index 4e1e9a3f9b..7ac3ec117e 100644 --- a/doomsday/plugins/common/src/g_game.c +++ b/doomsday/plugins/common/src/g_game.c @@ -968,7 +968,7 @@ void G_CommonPostInit(void) G_InitEventSequences(); #if __JDOOM__ || __JHERETIC__ || __JHEXEN__ - Cht_Init(); + G_RegisterCheats(); #endif // From this point on, the shortcuts are always active. diff --git a/doomsday/plugins/jdoom/include/m_cheat.h b/doomsday/plugins/jdoom/include/m_cheat.h index 23d567a780..6dd1fa2827 100644 --- a/doomsday/plugins/jdoom/include/m_cheat.h +++ b/doomsday/plugins/jdoom/include/m_cheat.h @@ -1,34 +1,35 @@ -/**\file - *\section License - * License: GPL - * Online License Link: http://www.gnu.org/licenses/gpl.html +/** + * @file m_cheat.h + * Cheats - Doom (plus Chex and Hacx). @ingroup libdoom * - *\author Copyright © 2003-2012 Jaakko Keränen - *\author Copyright © 2005-2012 Daniel Swanson - *\author Copyright © 1993-1996 by id Software, Inc. + * @author Copyright © 2003-2012 Jaakko Keränen + * @author Copyright © 2005-2012 Daniel Swanson * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * @par License + * GPL: http://www.gnu.org/licenses/gpl.html * - * 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 St, Fifth Floor, - * Boston, MA 02110-1301 USA + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. 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 St, Fifth Floor, Boston, MA + * 02110-1301 USA */ -#ifndef M_CHEAT -#define M_CHEAT +#ifndef LIBDOOM_M_CHEAT_H +#define LIBDOOM_M_CHEAT_H #ifndef __JDOOM__ # error "Using jDoom headers without __JDOOM__" #endif -void Cht_Init(void); -#endif /* M_CHEAT */ +/** + * Register event sequence callbacks for all cheats. + */ +void G_RegisterCheats(void); + +#endif /// LIBDOOM_M_CHEAT_H diff --git a/doomsday/plugins/jdoom/src/m_cheat.c b/doomsday/plugins/jdoom/src/m_cheat.c index a056d6c81f..723ab3bcaa 100644 --- a/doomsday/plugins/jdoom/src/m_cheat.c +++ b/doomsday/plugins/jdoom/src/m_cheat.c @@ -1,34 +1,26 @@ -/**\file m_cheat.c - *\section License - * License: GPL - * Online License Link: http://www.gnu.org/licenses/gpl.html - * - *\author Copyright © 2003-2012 Jaakko Keränen - *\author Copyright © 2005-2012 Daniel Swanson - *\author Copyright © 1993-1996 by id Software, Inc. +/** + * @file m_cheat.c + * Cheats. @ingroup libdoom * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * @author Copyright © 2003-2012 Jaakko Keränen + * @author Copyright © 2005-2012 Daniel Swanson + * @author Copyright © 1993-1996 by id Software, Inc. * - * 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. + * @par License + * GPL: http://www.gnu.org/licenses/gpl.html * - * 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 St, Fifth Floor, - * Boston, MA 02110-1301 USA + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. 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 St, Fifth Floor, Boston, MA + * 02110-1301 USA */ -/** - * Cheats - DOOM specific. - */ - -// HEADER FILES ------------------------------------------------------------ - #include #include #include @@ -49,41 +41,34 @@ #include "p_start.h" #include "g_eventsequence.h" -// MACROS ------------------------------------------------------------------ - -// TYPES ------------------------------------------------------------------- - -// EXTERNAL FUNCTION PROTOTYPES -------------------------------------------- - -// PUBLIC FUNCTION PROTOTYPES ---------------------------------------------- - -int Cht_GodFunc(const int* args, int player); -int Cht_NoClipFunc(const int* args, int player); -int Cht_ChoppersFunc(const int* args, int player); -int Cht_MyPosFunc(const int* args, int player); -int Cht_GiveWeaponsAmmoArmorKeys(const int* args, int player); -int Cht_GiveWeaponsAmmoArmor(const int* args, int player); -int Cht_WarpFunc(const int* args, int player); -int Cht_MusicFunc(const int* args, int player); -int Cht_PowerupMessage(const int* args, int player); -int Cht_PowerupFunc(const int* args, int player); -int Cht_PowerupFunc1(const int* args, int player); -int Cht_PowerupFunc2(const int* args, int player); -int Cht_PowerupFunc3(const int* args, int player); -int Cht_PowerupFunc4(const int* args, int player); -int Cht_PowerupFunc5(const int* args, int player); -int Cht_PowerupFunc6(const int* args, int player); -int Cht_Reveal(const int* args, int player); - -// PRIVATE FUNCTION PROTOTYPES --------------------------------------------- - -// EXTERNAL DATA DECLARATIONS ---------------------------------------------- - -// PUBLIC DATA DEFINITIONS ------------------------------------------------- - -// PRIVATE DATA DEFINITIONS ------------------------------------------------ - -// CODE -------------------------------------------------------------------- +typedef int (*cheatfunc_t)(const int*, int); + +/// Helper macro for forming cheat callback function names. +#define CHEAT(x) G_Cheat##x + +/// Helper macro for declaring cheat callback functions. +#define CHEAT_FUNC(x) int G_Cheat##x(const int* args, int player) + +/// Helper macro for registering new cheat event sequence handlers. +#define ADDCHEAT(name, len, callback) G_AddEventSequence((name), (len), CHEAT(callback)) + +CHEAT_FUNC(GiveAllMap); +CHEAT_FUNC(GiveChainsaw); +CHEAT_FUNC(GiveInvisibility); +CHEAT_FUNC(GiveInvulnerability); +CHEAT_FUNC(GiveInfrared); +CHEAT_FUNC(GiveIronFeet); +CHEAT_FUNC(GiveStrength); +CHEAT_FUNC(GiveWeaponsAmmoArmor); +CHEAT_FUNC(GiveWeaponsAmmoArmorKeys); +CHEAT_FUNC(God); +CHEAT_FUNC(Music); +CHEAT_FUNC(MyPos); +CHEAT_FUNC(NoClip); +CHEAT_FUNC(Powerup); +CHEAT_FUNC(PowerupMessage); +CHEAT_FUNC(Reveal); +CHEAT_FUNC(Warp); static boolean cheatsEnabled(void) { @@ -93,91 +78,88 @@ static boolean cheatsEnabled(void) return !IS_NETGAME; } -void Cht_Init(void) +void G_RegisterCheats(void) { switch(gameMode) { case doom2_hacx: { char seq[] = { 'w', 'a', 'r', 'p', 'm', 'e', 1, 0, 0 }; - G_AddEventSequence(seq, 9, Cht_WarpFunc); } + ADDCHEAT(seq, 9, Warp); } { char seq[] = { 's', 'e', 'e', 'i', 't', 1, 0 }; - G_AddEventSequence(seq, 7, Cht_PowerupFunc); } + ADDCHEAT(seq, 7, Powerup); } { char seq[] = { 't', 'u', 'n', 'e', 's', 1, 0, 0 }; - G_AddEventSequence(seq, 8, Cht_MusicFunc); } - - G_AddEventSequence("show", 4, Cht_Reveal); - G_AddEventSequence("wuss", 4, Cht_GodFunc); - G_AddEventSequence("blast", 5, Cht_GiveWeaponsAmmoArmorKeys); - G_AddEventSequence("walk", 4, Cht_NoClipFunc); - G_AddEventSequence("zap", 3, Cht_ChoppersFunc); - G_AddEventSequence("wheream", 7, Cht_MyPosFunc); - G_AddEventSequence("superman", 8, Cht_PowerupFunc1); - G_AddEventSequence("whacko", 6, Cht_PowerupFunc2); - G_AddEventSequence("ghost", 5, Cht_PowerupFunc3); - G_AddEventSequence("boots", 5, Cht_PowerupFunc4); - // G_AddEventSequence(??, ?, Cht_PowerupFunc5); Unknown?? - G_AddEventSequence("bright", 6, Cht_PowerupFunc6); + ADDCHEAT(seq, 8, Music); } + + ADDCHEAT("show", 4, Reveal); + ADDCHEAT("wuss", 4, God); + ADDCHEAT("blast", 5, GiveWeaponsAmmoArmorKeys); + ADDCHEAT("walk", 4, NoClip); + ADDCHEAT("zap", 3, GiveChainsaw); + ADDCHEAT("wheream", 7, MyPos); + ADDCHEAT("superman", 8, GiveInvulnerability); + ADDCHEAT("whacko", 6, GiveStrength); + ADDCHEAT("ghost", 5, GiveInvisibility); + ADDCHEAT("boots", 5, GiveIronFeet); + ADDCHEAT("bright", 6, GiveInfrared); break; case doom_chex: { char seq[] = { 'l', 'e', 'e', 's', 'n', 'y', 'd', 'e', 'r', 1, 0, 0 }; - G_AddEventSequence(seq, 12, Cht_WarpFunc); } + ADDCHEAT(seq, 12, Warp); } { char seq[] = { 'i', 'd', 'm', 'u', 's', 1, 0, 0 }; - G_AddEventSequence(seq, 8, Cht_MusicFunc); } - - G_AddEventSequence("joelkoenigs", 11, Cht_ChoppersFunc); - G_AddEventSequence("davidbrus", 9, Cht_GodFunc); - G_AddEventSequence("scottholman", 11, Cht_GiveWeaponsAmmoArmorKeys); - G_AddEventSequence("mikekoenigs", 11, Cht_GiveWeaponsAmmoArmor); - G_AddEventSequence("charlesjacobi", 13, Cht_NoClipFunc); - G_AddEventSequence("kimhyers", 8, Cht_MyPosFunc); - G_AddEventSequence("sherrill", 8, Cht_Reveal); - G_AddEventSequence("andrewbenson", 12, Cht_PowerupFunc1); - G_AddEventSequence("deanhyers", 9, Cht_PowerupFunc2); - G_AddEventSequence("marybregi", 9, Cht_PowerupFunc3); - G_AddEventSequence("allen", 5, Cht_PowerupFunc4); - G_AddEventSequence("digitalcafe", 11, Cht_PowerupFunc5); - G_AddEventSequence("joshuastorms", 12, Cht_PowerupFunc6); + ADDCHEAT(seq, 8, Music); } + + ADDCHEAT("joelkoenigs", 11, GiveChainsaw); + ADDCHEAT("davidbrus", 9, God); + ADDCHEAT("scottholman", 11, GiveWeaponsAmmoArmorKeys); + ADDCHEAT("mikekoenigs", 11, GiveWeaponsAmmoArmor); + ADDCHEAT("charlesjacobi", 13, NoClip); + ADDCHEAT("kimhyers", 8, MyPos); + ADDCHEAT("sherrill", 8, Reveal); + ADDCHEAT("andrewbenson", 12, GiveInvulnerability); + ADDCHEAT("deanhyers", 9, GiveStrength); + ADDCHEAT("marybregi", 9, GiveInvisibility); + ADDCHEAT("allen", 5, GiveIronFeet); + ADDCHEAT("digitalcafe", 11, GiveAllMap); + ADDCHEAT("joshuastorms", 12, GiveInfrared); break; default: // Doom { char seq[] = { 'i', 'd', 'c', 'l', 'e', 'v', 1, 0, 0 }; - G_AddEventSequence(seq, 9, Cht_WarpFunc); } + ADDCHEAT(seq, 9, Warp); } { char seq[] = { 'i', 'd', 'b', 'e', 'h', 'o', 'l', 'd', 1, 0 }; - G_AddEventSequence(seq, 10, Cht_PowerupFunc); } + ADDCHEAT(seq, 10, Powerup); } { char seq[] = { 'i', 'd', 'm', 'u', 's', 1, 0, 0 }; - G_AddEventSequence(seq, 8, Cht_MusicFunc); } - - G_AddEventSequence("iddt", 4, Cht_Reveal); - G_AddEventSequence("iddqd", 5, Cht_GodFunc); - G_AddEventSequence("idfa", 4, Cht_GiveWeaponsAmmoArmor); - G_AddEventSequence("idkfa", 5, Cht_GiveWeaponsAmmoArmorKeys); - G_AddEventSequence("idclip", 6, Cht_NoClipFunc); - G_AddEventSequence("idspispopd", 10, Cht_NoClipFunc); - G_AddEventSequence("idchoppers", 10, Cht_ChoppersFunc); - G_AddEventSequence("idmypos", 7, Cht_MyPosFunc); + ADDCHEAT(seq, 8, Music); } + + ADDCHEAT("iddt", 4, Reveal); + ADDCHEAT("iddqd", 5, God); + ADDCHEAT("idfa", 4, GiveWeaponsAmmoArmor); + ADDCHEAT("idkfa", 5, GiveWeaponsAmmoArmorKeys); + ADDCHEAT("idclip", 6, NoClip); + ADDCHEAT("idspispopd", 10, NoClip); + ADDCHEAT("idchoppers", 10, GiveChainsaw); + ADDCHEAT("idmypos", 7, MyPos); break; } } -/** - * 'iddqd' cheat for toggleable god mode. - */ -int Cht_GodFunc(const int* args, int player) +CHEAT_FUNC(God) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; plr->cheats ^= CF_GODMODE; plr->update |= PSF_STATE; @@ -190,8 +172,7 @@ int Cht_GodFunc(const int* args, int player) plr->update |= PSF_HEALTH; } - P_SetMessage(plr, - ((P_GetPlayerCheats(plr) & CF_GODMODE) ? STSTR_DQDON : STSTR_DQDOFF), false); + P_SetMessage(plr, ((P_GetPlayerCheats(plr) & CF_GODMODE) ? STSTR_DQDON : STSTR_DQDOFF), false); return true; } @@ -199,6 +180,8 @@ static void giveArmor(int player, int val) { player_t* plr = &players[player]; + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + // Support idfa/idkfa DEH Misc values val = MINMAX_OF(1, val, 3); plr->armorPoints = armorPoints[val]; @@ -211,6 +194,8 @@ static void giveWeapons(player_t* plr) { int i; + DENG_ASSERT(plr); + plr->update |= PSF_OWNED_WEAPONS; for(i = 0; i < NUM_WEAPON_TYPES; ++i) { @@ -222,33 +207,39 @@ static void giveAmmo(player_t* plr) { int i; + DENG_ASSERT(plr); + plr->update |= PSF_AMMO; for(i = 0; i < NUM_AMMO_TYPES; ++i) + { plr->ammo[i].owned = plr->ammo[i].max; + } } static void giveKeys(player_t* plr) { int i; + DENG_ASSERT(plr); + plr->update |= PSF_KEYS; for(i = 0; i < NUM_KEY_TYPES; ++i) + { plr->keys[i] = true; + } } -/** - * 'idfa' cheat for killer fucking arsenal. - */ -int Cht_GiveWeaponsAmmoArmor(const int* args, int player) +CHEAT_FUNC(GiveWeaponsAmmoArmor) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; giveWeapons(plr); giveAmmo(plr); @@ -258,19 +249,17 @@ int Cht_GiveWeaponsAmmoArmor(const int* args, int player) return true; } -/** - * 'idkfa' cheat for key full ammo. - */ -int Cht_GiveWeaponsAmmoArmorKeys(const int* args, int player) +CHEAT_FUNC(GiveWeaponsAmmoArmorKeys) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; giveWeapons(plr); giveAmmo(plr); @@ -281,20 +270,18 @@ int Cht_GiveWeaponsAmmoArmorKeys(const int* args, int player) return true; } -/** - * 'idmus' cheat for changing music. - */ -int Cht_MusicFunc(const int* args, int player) +CHEAT_FUNC(Music) { player_t* plr = &players[player]; int musnum; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_ASSERT(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; if(gameModeBits & GM_ANY_DOOM2) musnum = (args[0] - '0') * 10 + (args[1] - '0'); @@ -311,37 +298,33 @@ int Cht_MusicFunc(const int* args, int player) return false; } -/** - * 'idclip' no clipping mode cheat. - */ -int Cht_NoClipFunc(const int* args, int player) +CHEAT_FUNC(NoClip) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; plr->cheats ^= CF_NOCLIP; plr->update |= PSF_STATE; - P_SetMessage(plr, - ((P_GetPlayerCheats(plr) & CF_NOCLIP) ? STSTR_NCON : STSTR_NCOFF), false); + P_SetMessage(plr, ((P_GetPlayerCheats(plr) & CF_NOCLIP) ? STSTR_NCON : STSTR_NCOFF), false); return true; } -/** - * 'clev' change map cheat. - */ -int Cht_WarpFunc(const int* args, int player) +CHEAT_FUNC(Warp) { player_t* plr = &players[player]; uint i, epsd, map; - if(IS_NETGAME) - return false; + DENG_ASSERT(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; if(gameModeBits & GM_ANY_DOOM2) { @@ -380,13 +363,17 @@ int Cht_WarpFunc(const int* args, int player) return true; } -int Cht_Reveal(const int* args, int player) +CHEAT_FUNC(Reveal) { player_t* plr = &players[player]; - if(IS_NETGAME && deathmatch) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME && deathmatch) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; + if(ST_AutomapIsActive(player)) { ST_CycleAutomapCheatLevel(player); @@ -394,19 +381,17 @@ int Cht_Reveal(const int* args, int player) return true; } -/** - * 'idbehold' power-up menu - */ -int Cht_PowerupMessage(const int* args, int player) +CHEAT_FUNC(PowerupMessage) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; P_SetMessage(plr, STSTR_BEHOLD, false); return true; @@ -414,8 +399,7 @@ int Cht_PowerupMessage(const int* args, int player) static void givePower(player_t* plr, powertype_t type) { - if(type < 0 && type >= NUM_POWER_TYPES) - return; + if(type < 0 && type >= NUM_POWER_TYPES) return; if(!plr->powers[type]) { @@ -427,85 +411,86 @@ static void givePower(player_t* plr, powertype_t type) } } -/** - * 'idbehold?' power-up cheats. - */ -int Cht_PowerupFunc(const int* args, int player) +CHEAT_FUNC(Powerup) { static const char values[] = { 'v', 's', 'i', 'r', 'a', 'l' }; - static const size_t numValues = sizeof(values) / sizeof(values[0]); + static const int numValues = (int)(sizeof(values) / sizeof(values[0])); player_t* plr = &players[player]; - size_t i; + int i; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_ASSERT(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; for(i = 0; i < numValues; ++i) { - if(args[0] != values[i]) - continue; + if(args[0] != values[i]) continue; + givePower(plr, (powertype_t) i); P_SetMessage(plr, STSTR_BEHOLDX, false); return true; } - return false; } -int Cht_PowerupFunc1(const int* args, int player) +CHEAT_FUNC(GiveInvulnerability) { int _args[1] = {'v'}; - return Cht_PowerupFunc(_args, player); + DENG_UNUSED(args); + return CHEAT(Powerup)(_args, player); } -int Cht_PowerupFunc2(const int* args, int player) +CHEAT_FUNC(GiveStrength) { int _args[1] = {'s'}; - return Cht_PowerupFunc(_args, player); + DENG_UNUSED(args); + return CHEAT(Powerup)(_args, player); } -int Cht_PowerupFunc3(const int* args, int player) +CHEAT_FUNC(GiveInvisibility) { int _args[1] = {'i'}; - return Cht_PowerupFunc(_args, player); + DENG_UNUSED(args); + return CHEAT(Powerup)(_args, player); } -int Cht_PowerupFunc4(const int* args, int player) +CHEAT_FUNC(GiveIronFeet) { int _args[1] = {'r'}; - return Cht_PowerupFunc(_args, player); + DENG_UNUSED(args); + return CHEAT(Powerup)(_args, player); } -int Cht_PowerupFunc5(const int* args, int player) +CHEAT_FUNC(GiveAllMap) { int _args[1] = {'a'}; - return Cht_PowerupFunc(_args, player); + DENG_UNUSED(args); + return CHEAT(Powerup)(_args, player); } -int Cht_PowerupFunc6(const int* args, int player) +CHEAT_FUNC(GiveInfrared) { int _args[1] = {'l'}; - return Cht_PowerupFunc(_args, player); + DENG_UNUSED(args); + return CHEAT(Powerup)(_args, player); } -/** - * 'choppers' invulnerability & chainsaw - */ -int Cht_ChoppersFunc(const int* args, int player) +CHEAT_FUNC(GiveChainsaw) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; plr->weapons[WT_EIGHTH].owned = true; plr->powers[PT_INVULNERABILITY] = true; @@ -513,20 +498,18 @@ int Cht_ChoppersFunc(const int* args, int player) return true; } -/** - * 'mypos' for plr position - */ -int Cht_MyPosFunc(const int* args, int player) +CHEAT_FUNC(MyPos) { player_t* plr = &players[player]; char buf[80]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; sprintf(buf, "ang=0x%x;x,y,z=(%g,%g,%g)", players[CONSOLEPLAYER].plr->mo->angle, @@ -574,13 +557,12 @@ static void printDebugInfo(player_t* plr) } /** - * This is the multipurpose cheat ccmd. + * The multipurpose cheat ccmd. */ D_CMD(Cheat) { - size_t i, len = strlen(argv[1]); - // Give each of the characters in argument two to the ST event handler. + int i, len = (int)strlen(argv[1]); for(i = 0; i < len; ++i) { event_t ev; @@ -606,20 +588,17 @@ D_CMD(CheatGod) { int player = CONSOLEPLAYER; - if(IS_NETGAME && !netSvAllowCheats) - return false; + if(IS_NETGAME && !netSvAllowCheats) return false; if(argc == 2) { player = atoi(argv[1]); - if(player < 0 || player >= MAXPLAYERS) - return false; + if(player < 0 || player >= MAXPLAYERS) return false; } - if(!players[player].plr->inGame) - return false; + if(!players[player].plr->inGame) return false; - Cht_GodFunc(NULL, player); + CHEAT(God)(NULL, player); } } return true; @@ -637,20 +616,17 @@ D_CMD(CheatNoClip) { int player = CONSOLEPLAYER; - if(IS_NETGAME && !netSvAllowCheats) - return false; + if(IS_NETGAME && !netSvAllowCheats) return false; if(argc == 2) { player = atoi(argv[1]); - if(player < 0 || player >= MAXPLAYERS) - return false; + if(player < 0 || player >= MAXPLAYERS) return false; } - if(!players[player].plr->inGame) - return false; + if(!players[player].plr->inGame) return false; - Cht_NoClipFunc(NULL, player); + CHEAT(NoClip)(NULL, player); } } return true; @@ -658,6 +634,8 @@ D_CMD(CheatNoClip) static int suicideResponse(msgresponse_t response, int userValue, void* userPointer) { + DENG_UNUSED(userValue); + DENG_UNUSED(userPointer); if(response == MSG_YES) { if(IS_NETGAME && IS_CLIENT) @@ -695,26 +673,21 @@ D_CMD(CheatSuicide) plr = &players[i]; } - if(!plr->plr->inGame) - return false; - - if(plr->playerState == PST_DEAD) - return false; + if(!plr->plr->inGame) return false; + if(plr->playerState == PST_DEAD) return false; if(!IS_NETGAME || IS_CLIENT) { Hu_MsgStart(MSG_YESNO, SUICIDEASK, suicideResponse, 0, NULL); - return true; } - - P_DamageMobj(plr->plr->mo, NULL, NULL, 10000, false); + else + { + P_DamageMobj(plr->plr->mo, NULL, NULL, 10000, false); + } return true; } - else - { - Hu_MsgStart(MSG_ANYKEY, SUICIDEOUTMAP, NULL, 0, NULL); - } + Hu_MsgStart(MSG_ANYKEY, SUICIDEOUTMAP, NULL, 0, NULL); return true; } @@ -722,8 +695,7 @@ D_CMD(CheatWarp) { int args[2]; - if(!cheatsEnabled()) - return false; + if(!cheatsEnabled()) return false; if(gameModeBits & GM_ANY_DOOM2) { @@ -745,7 +717,7 @@ D_CMD(CheatWarp) } } - Cht_WarpFunc(args, CONSOLEPLAYER); + CHEAT(Warp)(args, CONSOLEPLAYER); return true; } @@ -753,21 +725,23 @@ D_CMD(CheatReveal) { int option, i; - if(!cheatsEnabled()) - return false; + if(!cheatsEnabled()) return false; option = atoi(argv[1]); - if(option < 0 || option > 3) - return false; + if(option < 0 || option > 3) return false; for(i = 0; i < MAXPLAYERS; ++i) { ST_SetAutomapCheatLevel(i, 0); ST_RevealAutomap(i, false); if(option == 1) + { ST_RevealAutomap(i, true); + } else if(option != 0) + { ST_SetAutomapCheatLevel(i, option -1); + } } return true; @@ -782,16 +756,14 @@ D_CMD(CheatGive) if(IS_CLIENT) { - if(argc != 2) - return false; + if(argc != 2) return false; sprintf(buf, "give %s", argv[1]); NetCl_CheatRequest(buf); return true; } - if(IS_NETGAME && !netSvAllowCheats) - return false; + if(IS_NETGAME && !netSvAllowCheats) return false; if(argc != 2 && argc != 3) { @@ -820,8 +792,7 @@ D_CMD(CheatGive) if(argc == 3) { player = atoi(argv[2]); - if(player < 0 || player >= MAXPLAYERS) - return false; + if(player < 0 || player >= MAXPLAYERS) return false; } if(G_GameState() != GS_MAP) @@ -830,8 +801,8 @@ D_CMD(CheatGive) return true; } - if(!players[player].plr->inGame) - return true; // Can't give to a plr who's not playing + // Can't give to a plr who's not in the game. + if(!players[player].plr->inGame) return true; plr = &players[player]; strcpy(buf, argv[1]); // Stuff is the 2nd arg. @@ -990,8 +961,7 @@ D_CMD(CheatWhere) */ D_CMD(CheatLeaveMap) { - if(!cheatsEnabled()) - return false; + if(!cheatsEnabled()) return false; if(G_GameState() != GS_MAP) { diff --git a/doomsday/plugins/jheretic/include/m_cheat.h b/doomsday/plugins/jheretic/include/m_cheat.h index c0268ec262..5f24946074 100644 --- a/doomsday/plugins/jheretic/include/m_cheat.h +++ b/doomsday/plugins/jheretic/include/m_cheat.h @@ -1,33 +1,35 @@ -/**\file - *\section License - * License: GPL - * Online License Link: http://www.gnu.org/licenses/gpl.html +/** + * @file m_cheat.h + * Cheats - Heretic specific. @ingroup libheretic * - *\author Copyright © 2006-2012 Jaakko Keränen - *\author Copyright © 2006-2012 Daniel Swanson + * @author Copyright © 2006-2012 Jaakko Keränen + * @author Copyright © 2006-2012 Daniel Swanson * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * @par License + * GPL: http://www.gnu.org/licenses/gpl.html * - * 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 St, Fifth Floor, - * Boston, MA 02110-1301 USA + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. 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 St, Fifth Floor, Boston, MA + * 02110-1301 USA */ -#ifndef M_CHEAT_H -#define M_CHEAT_H +#ifndef LIBHERETIC_M_CHEAT_H +#define LIBHERETIC_M_CHEAT_H #ifndef __JHERETIC__ # error "Using jHeretic headers without __JHERETIC__" #endif -void Cht_Init(void); -#endif /* M_CHEAT_H */ +/** + * Register event sequence callbacks for all cheats. + */ +void G_RegisterCheats(void); + +#endif /// LIBHERETIC_M_CHEAT_H diff --git a/doomsday/plugins/jheretic/src/m_cheat.c b/doomsday/plugins/jheretic/src/m_cheat.c index 2e7ac5e89d..1cec35726d 100644 --- a/doomsday/plugins/jheretic/src/m_cheat.c +++ b/doomsday/plugins/jheretic/src/m_cheat.c @@ -1,34 +1,26 @@ -/**\file m_cheat.c - *\section License - * License: GPL - * Online License Link: http://www.gnu.org/licenses/gpl.html - * - *\author Copyright © 2003-2012 Jaakko Keränen - *\author Copyright © 2005-2012 Daniel Swanson - *\author Copyright © 1999 Activision +/** + * @file m_cheat.c + * Cheats. @ingroup libheretic * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * @author Copyright © 2003-2012 Jaakko Keränen + * @author Copyright © 2005-2012 Daniel Swanson + * @author Copyright © 1999 Activision * - * 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. + * @par License + * GPL: http://www.gnu.org/licenses/gpl.html * - * 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 St, Fifth Floor, - * Boston, MA 02110-1301 USA - */ - -/** - * Cheat sequence checking. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. 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 St, Fifth Floor, Boston, MA + * 02110-1301 USA */ -// HEADER FILES ------------------------------------------------------------ - #include #include #include @@ -52,160 +44,81 @@ #include "p_inventory.h" #include "g_eventsequence.h" -// MACROS ------------------------------------------------------------------ - -// TYPES ------------------------------------------------------------------- - -// EXTERNAL FUNCTION PROTOTYPES -------------------------------------------- - -// PUBLIC FUNCTION PROTOTYPES ---------------------------------------------- - -int Cht_GodFunc(const int* args, int player); -int Cht_NoClipFunc(const int* args, int player); -int Cht_WeaponsFunc(const int* args, int player); -int Cht_PowerupFunc(const int* args, int player); -int Cht_HealthFunc(const int* args, int player); -int Cht_GiveKeysFunc(const int* args, int player); -int Cht_InvItem1Func(const int* args, int player); -int Cht_InvItem2Func(const int* args, int player); -int Cht_InvItem3Func(const int* args, int player); -int Cht_WarpFunc(const int* args, int player); -int Cht_ChickenFunc(const int* args, int player); -int Cht_MassacreFunc(const int* args, int player); -int Cht_IDKFAFunc(const int* args, int player); -int Cht_IDDQDFunc(const int* args, int player); -int Cht_SoundFunc(const int* args, int player); -int Cht_TickerFunc(const int* args, int player); -int Cht_RevealFunc(const int* args, int player); - -// PRIVATE FUNCTION PROTOTYPES --------------------------------------------- - -// EXTERNAL DATA DECLARATIONS ---------------------------------------------- - -// PUBLIC DATA DEFINITIONS ------------------------------------------------- - -// PRIVATE DATA DEFINITIONS ------------------------------------------------ - -// Toggle god mode. -static char cheatGodSeq[] = { - 'q', 'u', 'i', 'c', 'k', 'e', 'n' -}; - -// Toggle no clipping mode. -static char cheatNoClipSeq[] = { - 'k', 'i', 't', 't', 'y' -}; - -// Get all weapons and ammo. -static char cheatWeaponsSeq[] = { - 'r', 'a', 'm', 'b', 'o' -}; - -// Toggle tome of power. -static char cheatPowerSeq[] = { - 's', 'h', 'a', 'z', 'a', 'm' -}; - -// Get full health. -static char cheatHealthSeq[] = { - 'p', 'o', 'n', 'c', 'e' -}; - -// Get all keys. -static char cheatKeysSeq[] = { - 's', 'k', 'e', 'l' -}; - -// Toggle sound debug info. -static char cheatSoundSeq[] = { - 'n', 'o', 'i', 's', 'e' -}; - -// Toggle ticker. -static char cheatTickerSeq[] = { - 't', 'i', 'c', 'k', 'e', 'r' -}; - -// Get an inventory item 1st stage (ask for type). -static char cheatInvItem1Seq[] = { - 'g', 'i', 'm', 'm', 'e' -}; - -// Get an inventory item 2nd stage (ask for count). -static char cheatInvItem2Seq[] = { - 'g', 'i', 'm', 'm', 'e', 1, 0 -}; - -// Get an inventory item final stage. -static char cheatInvItem3Seq[] = { - 'g', 'i', 'm', 'm', 'e', 1, 0, 0 -}; - -// Warp to new level. -static char cheatWarpSeq[] = { - 'e', 'n', 'g', 'a', 'g', 'e', 1, 0, 0 -}; - -// Save a screenshot. -static char cheatChickenSeq[] = { - 'c', 'o', 'c', 'k', 'a', 'd', 'o', 'o', 'd', 'l', 'e', 'd', 'o', 'o' -}; - -// Kill all monsters. -static char cheatMassacreSeq[] = { - 'm', 'a', 's', 's', 'a', 'c', 'r', 'e' -}; - -static char cheatIDKFASeq[] = { - 'i', 'd', 'k', 'f', 'a' -}; - -static char cheatIDDQDSeq[] = { - 'i', 'd', 'd', 'q', 'd' -}; - -static char cheatAutomapSeq[] = { - 'r', 'a', 'v', 'm', 'a', 'p' -}; - -// CODE -------------------------------------------------------------------- +typedef int (*cheatfunc_t)(const int*, int); + +/// Helper macro for forming cheat callback function names. +#define CHEAT(x) G_Cheat##x + +/// Helper macro for declaring cheat callback functions. +#define CHEAT_FUNC(x) int G_Cheat##x(const int* args, int player) + +/// Helper macro for registering new cheat event sequence handlers. +#define ADDCHEAT(name, len, callback) G_AddEventSequence((name), (len), CHEAT(callback)) + +CHEAT_FUNC(God); +CHEAT_FUNC(NoClip); +CHEAT_FUNC(Weapons); +CHEAT_FUNC(Powerup); +CHEAT_FUNC(Health); +CHEAT_FUNC(GiveKeys); +CHEAT_FUNC(InvItem1); +CHEAT_FUNC(InvItem2); +CHEAT_FUNC(InvItem3); +CHEAT_FUNC(Warp); +CHEAT_FUNC(Chicken); +CHEAT_FUNC(Massacre); +CHEAT_FUNC(IDKFA); +CHEAT_FUNC(IDDQD); +CHEAT_FUNC(Sound); +CHEAT_FUNC(Ticker); +CHEAT_FUNC(Reveal); static boolean cheatsEnabled(void) { return !IS_NETGAME; } -void Cht_Init(void) +void G_RegisterCheats(void) { - G_AddEventSequence(cheatAutomapSeq, sizeof(cheatAutomapSeq), Cht_RevealFunc); - G_AddEventSequence(cheatGodSeq, sizeof(cheatGodSeq), Cht_GodFunc); - G_AddEventSequence(cheatNoClipSeq, sizeof(cheatNoClipSeq), Cht_NoClipFunc); - G_AddEventSequence(cheatWeaponsSeq, sizeof(cheatWeaponsSeq), Cht_WeaponsFunc); - G_AddEventSequence(cheatPowerSeq, sizeof(cheatPowerSeq), Cht_PowerupFunc); - G_AddEventSequence(cheatHealthSeq, sizeof(cheatHealthSeq), Cht_HealthFunc); - G_AddEventSequence(cheatKeysSeq, sizeof(cheatKeysSeq), Cht_GiveKeysFunc); - G_AddEventSequence(cheatSoundSeq, sizeof(cheatSoundSeq), Cht_SoundFunc); - G_AddEventSequence(cheatTickerSeq, sizeof(cheatTickerSeq), Cht_TickerFunc); - G_AddEventSequence(cheatInvItem3Seq, sizeof(cheatInvItem3Seq), Cht_InvItem3Func); - G_AddEventSequence(cheatInvItem2Seq, sizeof(cheatInvItem2Seq), Cht_InvItem2Func); - G_AddEventSequence(cheatInvItem1Seq, sizeof(cheatInvItem1Seq), Cht_InvItem1Func); - G_AddEventSequence(cheatWarpSeq, sizeof(cheatWarpSeq), Cht_WarpFunc); - G_AddEventSequence(cheatChickenSeq, sizeof(cheatChickenSeq), Cht_ChickenFunc); - G_AddEventSequence(cheatMassacreSeq, sizeof(cheatMassacreSeq), Cht_MassacreFunc); - G_AddEventSequence(cheatIDKFASeq, sizeof(cheatIDKFASeq), Cht_IDKFAFunc); - G_AddEventSequence(cheatIDDQDSeq, sizeof(cheatIDDQDSeq), Cht_IDDQDFunc); + ADDCHEAT("cockadoodledoo", 14, Chicken); + ADDCHEAT("iddqd", 5, IDDQD); + ADDCHEAT("idkfa", 5, IDKFA); + ADDCHEAT("kitty", 5, NoClip); + ADDCHEAT("massacre", 8, Massacre); + ADDCHEAT("noise", 5, Sound); + ADDCHEAT("ponce", 5, Health); + ADDCHEAT("quicken", 7, God); + ADDCHEAT("rambo", 5, Weapons); + ADDCHEAT("ravmap", 6, Reveal); + ADDCHEAT("shazam", 6, Powerup); + ADDCHEAT("skel", 4, GiveKeys); + ADDCHEAT("ticker", 6, Ticker); + + // Cheats with arguments: + + // Get an inventory item. + { char seq[] = { 'g', 'i', 'm', 'm', 'e', 1, 0, 0 }; + ADDCHEAT(seq, 8, InvItem1); // Final stage. + ADDCHEAT(seq, 7, InvItem1); // 2nd stage (ask for count). + ADDCHEAT(seq, 5, InvItem1); // 1st stage (ask for type). + } + + // Warp to new level. + { char seq[] = { 'e', 'n', 'g', 'a', 'g', 'e', 1, 0, 0 }; + ADDCHEAT(seq, 9, Warp); } } -int Cht_GodFunc(const int* args, int player) +CHEAT_FUNC(God) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; plr->cheats ^= CF_GODMODE; plr->update |= PSF_STATE; @@ -255,16 +168,17 @@ static void giveAmmo(player_t* plr) } } -int Cht_WeaponsFunc(const int* args, int player) +CHEAT_FUNC(Weapons) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; giveWeapons(plr); giveAmmo(plr); @@ -275,59 +189,60 @@ int Cht_WeaponsFunc(const int* args, int player) return true; } -int Cht_GiveKeysFunc(const int* args, int player) +CHEAT_FUNC(GiveKeys) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; plr->update |= PSF_KEYS; plr->keys[KT_YELLOW] = true; - plr->keys[KT_GREEN] = true; - plr->keys[KT_BLUE] = true; + plr->keys[KT_GREEN] = true; + plr->keys[KT_BLUE] = true; P_SetMessage(plr, TXT_CHEATKEYS, false); S_LocalSound(SFX_DORCLS, NULL); return true; } -int Cht_NoClipFunc(const int* args, int player) +CHEAT_FUNC(NoClip) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; plr->cheats ^= CF_NOCLIP; plr->update |= PSF_STATE; - P_SetMessage(plr, - ((P_GetPlayerCheats(plr) & CF_NOCLIP) ? TXT_CHEATNOCLIPON : TXT_CHEATNOCLIPOFF), false); + P_SetMessage(plr, ((P_GetPlayerCheats(plr) & CF_NOCLIP) ? TXT_CHEATNOCLIPON : TXT_CHEATNOCLIPOFF), false); S_LocalSound(SFX_DORCLS, NULL); return true; } -int Cht_WarpFunc(const int* args, int player) +CHEAT_FUNC(Warp) { player_t* plr = &players[player]; uint i, epsd, map; - if(IS_NETGAME) - return false; + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; epsd = (args[0] > '0')? args[0] - '1' : 0; - map = (args[1] > '0')? args[1] - '1' : 0; + map = (args[1] > '0')? args[1] - '1' : 0; // Catch invalid maps. - if(!G_ValidateMap(&epsd, &map)) - return false; + if(!G_ValidateMap(&epsd, &map)) return false; P_SetMessage(plr, TXT_CHEATWARP, false); S_LocalSound(SFX_DORCLS, NULL); @@ -353,16 +268,17 @@ int Cht_WarpFunc(const int* args, int player) return true; } -int Cht_PowerupFunc(const int* args, int player) +CHEAT_FUNC(Powerup) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; plr->update |= PSF_POWERS; if(plr->powers[PT_WEAPONLEVEL2]) @@ -419,16 +335,17 @@ static void printDebugInfo(int player) plr->plr->mo->height, plr->plr->mo->radius); } -int Cht_HealthFunc(const int* args, int player) +CHEAT_FUNC(Health) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; plr->update |= PSF_HEALTH; if(plr->morphTics) @@ -444,55 +361,58 @@ int Cht_HealthFunc(const int* args, int player) return true; } -int Cht_InvItem1Func(const int* args, int player) +CHEAT_FUNC(InvItem1) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; P_SetMessage(plr, TXT_CHEATINVITEMS1, false); S_LocalSound(SFX_DORCLS, NULL); return true; } -int Cht_InvItem2Func(const int* args, int player) +CHEAT_FUNC(InvItem2) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; P_SetMessage(plr, TXT_CHEATINVITEMS2, false); S_LocalSound(SFX_DORCLS, NULL); return true; } -int Cht_InvItem3Func(const int* args, int player) +CHEAT_FUNC(InvItem3) { player_t* plr = &players[player]; - int i, count; inventoryitemtype_t type; + int count; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); - type = args[0] - 'a' + 1; + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; + + type = args[0] - 'a' + 1; count = args[1] - '0'; if(type > IIT_NONE && type < NUM_INVENTORYITEM_TYPES && count > 0 && count < 10) { + int i; if(gameMode == heretic_shareware && (type == IIT_SUPERHEALTH || type == IIT_TELEPORT)) { P_SetMessage(plr, TXT_CHEATITEMSFAIL, false); @@ -514,16 +434,17 @@ int Cht_InvItem3Func(const int* args, int player) return true; } -int Cht_ChickenFunc(const int* args, int player) +CHEAT_FUNC(Chicken) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; if(plr->morphTics) { @@ -541,16 +462,17 @@ int Cht_ChickenFunc(const int* args, int player) return true; } -int Cht_MassacreFunc(const int* args, int player) +CHEAT_FUNC(Massacre) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; P_Massacre(); P_SetMessage(plr, TXT_CHEATMASSACRE, false); @@ -558,22 +480,19 @@ int Cht_MassacreFunc(const int* args, int player) return true; } -int Cht_IDKFAFunc(const int* args, int player) +CHEAT_FUNC(IDKFA) { player_t* plr = &players[player]; int i; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); - if(plr->morphTics) - { - return false; - } + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; + if(plr->morphTics) return false; for(i = 0; i < NUM_WEAPON_TYPES; ++i) { @@ -586,16 +505,17 @@ int Cht_IDKFAFunc(const int* args, int player) return true; } -int Cht_IDDQDFunc(const int* args, int player) +CHEAT_FUNC(IDDQD) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; P_DamageMobj(plr->plr->mo, NULL, plr->plr->mo, 10000, false); P_SetMessage(plr, TXT_CHEATIDDQD, false); @@ -603,45 +523,51 @@ int Cht_IDDQDFunc(const int* args, int player) return true; } -int Cht_SoundFunc(const int* args, int player) +CHEAT_FUNC(Sound) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; // Otherwise ignored. S_LocalSound(SFX_DORCLS, NULL); return true; } -int Cht_TickerFunc(const int* args, int player) +CHEAT_FUNC(Ticker) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; // Otherwise ignored. S_LocalSound(SFX_DORCLS, NULL); return true; } -int Cht_RevealFunc(const int* args, int player) +CHEAT_FUNC(Reveal) { player_t* plr = &players[player]; - if(IS_NETGAME && deathmatch) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME && deathmatch) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; + if(ST_AutomapIsActive(player)) { ST_CycleAutomapCheatLevel(player); @@ -649,17 +575,17 @@ int Cht_RevealFunc(const int* args, int player) return true; } -// This is the multipurpose cheat ccmd. +/** + * The multipurpose cheat ccmd. + */ D_CMD(Cheat) { - size_t i; - // Give each of the characters in argument two to the SB event handler. - for(i = 0; i < strlen(argv[1]); ++i) + int i, len = (int) strlen(argv[1]); + for(i = 0; i < len; ++i) { event_t ev; - - ev.type = EV_KEY; + ev.type = EV_KEY; ev.state = EVS_DOWN; ev.data1 = argv[1][i]; ev.data2 = ev.data3 = 0; @@ -680,20 +606,17 @@ D_CMD(CheatGod) { int player = CONSOLEPLAYER; - if(IS_NETGAME && !netSvAllowCheats) - return false; + if(IS_NETGAME && !netSvAllowCheats) return false; if(argc == 2) { player = atoi(argv[1]); - if(player < 0 || player >= MAXPLAYERS) - return false; + if(player < 0 || player >= MAXPLAYERS) return false; } - if(!players[player].plr->inGame) - return false; + if(!players[player].plr->inGame) return false; - Cht_GodFunc(NULL, player); + CHEAT(God)(NULL, player); } } return true; @@ -711,20 +634,17 @@ D_CMD(CheatNoClip) { int player = CONSOLEPLAYER; - if(IS_NETGAME && !netSvAllowCheats) - return false; + if(IS_NETGAME && !netSvAllowCheats) return false; if(argc == 2) { player = atoi(argv[1]); - if(player < 0 || player >= MAXPLAYERS) - return false; + if(player < 0 || player >= MAXPLAYERS) return false; } - if(!players[player].plr->inGame) - return false; + if(!players[player].plr->inGame) return false; - Cht_NoClipFunc(NULL, player); + CHEAT(NoClip)(NULL, player); } } return true; @@ -753,24 +673,21 @@ D_CMD(CheatSuicide) { player_t* plr; - if(IS_NETGAME && !netSvAllowCheats) - return false; + if(IS_NETGAME && !netSvAllowCheats) return false; if(argc == 2) { int i = atoi(argv[1]); - if(i < 0 || i >= MAXPLAYERS) - return false; + if(i < 0 || i >= MAXPLAYERS) return false; plr = &players[i]; } else + { plr = &players[CONSOLEPLAYER]; + } - if(!plr->plr->inGame) - return false; - - if(plr->playerState == PST_DEAD) - return false; + if(!plr->plr->inGame) return false; + if(plr->playerState == PST_DEAD) return false; if(!IS_NETGAME || IS_CLIENT) { @@ -793,8 +710,7 @@ D_CMD(CheatWarp) { int num, args[2]; - if(!cheatsEnabled()) - return false; + if(!cheatsEnabled()) return false; if(argc == 2) { @@ -813,7 +729,7 @@ D_CMD(CheatWarp) return true; } - Cht_WarpFunc(args, CONSOLEPLAYER); + CHEAT(Warp)(args, CONSOLEPLAYER); return true; } @@ -821,21 +737,23 @@ D_CMD(CheatReveal) { int option, i; - if(!cheatsEnabled()) - return false; + if(!cheatsEnabled()) return false; option = atoi(argv[1]); - if(option < 0 || option > 3) - return false; + if(option < 0 || option > 3) return false; for(i = 0; i < MAXPLAYERS; ++i) { ST_SetAutomapCheatLevel(i, 0); ST_RevealAutomap(i, false); if(option == 1) + { ST_RevealAutomap(i, true); + } else if(option != 0) + { ST_SetAutomapCheatLevel(i, option -1); + } } return true; @@ -850,16 +768,14 @@ D_CMD(CheatGive) if(IS_CLIENT) { - if(argc != 2) - return false; + if(argc != 2) return false; sprintf(buf, "give %s", argv[1]); NetCl_CheatRequest(buf); return true; } - if(IS_NETGAME && !netSvAllowCheats) - return false; + if(IS_NETGAME && !netSvAllowCheats) return false; if(argc != 2 && argc != 3) { @@ -981,7 +897,7 @@ D_CMD(CheatGive) break; case 'h': - Cht_HealthFunc(NULL, player); + CHEAT(Health)(NULL, player); break; case 'k': @@ -1009,7 +925,7 @@ D_CMD(CheatGive) } // Give all keys. - Cht_GiveKeysFunc(NULL, player); + CHEAT(GiveKeys)(NULL, player); break; case 'p': @@ -1037,7 +953,7 @@ D_CMD(CheatGive) break; case 't': - Cht_PowerupFunc(NULL, player); + CHEAT(Powerup)(NULL, player); break; case 'w': @@ -1082,7 +998,7 @@ D_CMD(CheatGive) D_CMD(CheatMassacre) { - Cht_MassacreFunc(NULL, CONSOLEPLAYER); + CHEAT(Massacre)(NULL, CONSOLEPLAYER); return true; } @@ -1097,8 +1013,7 @@ D_CMD(CheatWhere) */ D_CMD(CheatLeaveMap) { - if(!cheatsEnabled()) - return false; + if(!cheatsEnabled()) return false; if(G_GameState() != GS_MAP) { @@ -1113,12 +1028,10 @@ D_CMD(CheatLeaveMap) D_CMD(CheatPig) { - if(IS_NETGAME) - return false; - - if(!userGame || gameSkill == SM_NIGHTMARE || players[CONSOLEPLAYER].health <= 0) - return false; + if(IS_NETGAME || !userGame) return false; + if(gameSkill == SM_NIGHTMARE) return false; + if(players[CONSOLEPLAYER].health <= 0) return false; - Cht_ChickenFunc(NULL, CONSOLEPLAYER); + CHEAT(Chicken)(NULL, CONSOLEPLAYER); return true; } diff --git a/doomsday/plugins/jhexen/include/m_cheat.h b/doomsday/plugins/jhexen/include/m_cheat.h index 2e85a09a43..188200dd74 100644 --- a/doomsday/plugins/jhexen/include/m_cheat.h +++ b/doomsday/plugins/jhexen/include/m_cheat.h @@ -1,32 +1,35 @@ -/**\file - *\section License - * License: GPL - * Online License Link: http://www.gnu.org/licenses/gpl.html +/** + * @file m_cheat.h + * Cheats - Hexen specific. @ingroup libhexen * - *\author Copyright © 2006-2012 Daniel Swanson + * @author Copyright © 2006-2012 Jaakko Keränen + * @author Copyright © 2006-2012 Daniel Swanson * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * @par License + * GPL: http://www.gnu.org/licenses/gpl.html * - * 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 St, Fifth Floor, - * Boston, MA 02110-1301 USA + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. 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 St, Fifth Floor, Boston, MA + * 02110-1301 USA */ -#ifndef M_CHEAT -#define M_CHEAT +#ifndef LIBHEXEN_M_CHEAT_H +#define LIBHEXEN_M_CHEAT_H #ifndef __JHEXEN__ # error "Using jHexen headers without __JHEXEN__" #endif -void Cht_Init(void); -#endif /* M_CHEAT */ +/** + * Register event sequence callbacks for all cheats. + */ +void G_RegisterCheats(void); + +#endif /// LIBHEXEN_M_CHEAT_H diff --git a/doomsday/plugins/jhexen/src/m_cheat.c b/doomsday/plugins/jhexen/src/m_cheat.c index ba59916188..774c01684d 100644 --- a/doomsday/plugins/jhexen/src/m_cheat.c +++ b/doomsday/plugins/jhexen/src/m_cheat.c @@ -1,34 +1,26 @@ -/**\file m_cheat.c - *\section License - * License: GPL - * Online License Link: http://www.gnu.org/licenses/gpl.html - * - *\author Copyright © 2003-2012 Jaakko Keränen - *\author Copyright © 2006-2012 Daniel Swanson - *\author Copyright © 1999 Activision +/** + * @file m_cheat.c + * Cheats. @ingroup libhexen * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * @author Copyright © 2003-2012 Jaakko Keränen + * @author Copyright © 2006-2012 Daniel Swanson + * @author Copyright © 1999 Activision * - * 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. + * @par License + * GPL: http://www.gnu.org/licenses/gpl.html * - * 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 St, Fifth Floor, - * Boston, MA 02110-1301 USA - */ - -/** - * Cheats - Hexen specific. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. 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 St, Fifth Floor, Boston, MA + * 02110-1301 USA */ -// HEADER FILES ------------------------------------------------------------ - #include #include #include @@ -52,207 +44,105 @@ #include "hu_inventory.h" #include "g_eventsequence.h" -// MACROS ------------------------------------------------------------------ - -// TYPES ------------------------------------------------------------------- - -// EXTERNAL FUNCTION PROTOTYPES -------------------------------------------- - -// PUBLIC FUNCTION PROTOTYPES ---------------------------------------------- - -int Cht_GodFunc(const int* args, int player); -int Cht_NoClipFunc(const int* args, int player); -int Cht_WeaponsFunc(const int* args, int player); -int Cht_HealthFunc(const int* args, int player); -int Cht_ArmorFunc(const int* args, int player); -int Cht_GiveKeysFunc(const int* args, int player); -int Cht_SoundFunc(const int* args, int player); -int Cht_InventoryFunc(const int* args, int player); -int Cht_PuzzleFunc(const int* args, int player); -int Cht_InitFunc(const int* args, int player); -int Cht_WarpFunc(const int* args, int player); -int Cht_PigFunc(const int* args, int player); -int Cht_MassacreFunc(const int* args, int player); -int Cht_IDKFAFunc(const int* args, int player); -int Cht_QuickenFunc1(const int* args, int player); -int Cht_QuickenFunc2(const int* args, int player); -int Cht_QuickenFunc3(const int* args, int player); -int Cht_ClassFunc1(const int* args, int player); -int Cht_ClassFunc2(const int* args, int player); -int Cht_VersionFunc(const int* args, int player); -int Cht_ScriptFunc1(const int* args, int player); -int Cht_ScriptFunc2(const int* args, int player); -int Cht_ScriptFunc3(const int* args, int player); -int Cht_RevealFunc(const int* args, int player); -int Cht_WhereFunc(const int* args, int player); - -// PRIVATE FUNCTION PROTOTYPES --------------------------------------------- - -// EXTERNAL DATA DECLARATIONS ---------------------------------------------- - -// PUBLIC DATA DEFINITIONS ------------------------------------------------- - -// PRIVATE DATA DEFINITIONS ------------------------------------------------ - -// Toggle god mode -static char cheatGodSeq[] = { - 's', 'a', 't', 'a', 'n' -}; - -// Toggle no clipping mode -static char cheatNoClipSeq[] = { - 'c', 'a', 's', 'p', 'e', 'r' -}; - -// Get all weapons and mana -static char cheatWeaponsSeq[] = { - 'n', 'r', 'a' -}; - -// Get full health -static char cheatHealthSeq[] = { - 'c', 'l', 'u', 'b', 'm', 'e', 'd' -}; - -// Get all keys -static char cheatKeysSeq[] = { - 'l', 'o', 'c', 'k', 's', 'm', 'i', 't', 'h' -}; - -// Toggle sound debug info -static char cheatSoundSeq[] = { - 'n', 'o', 'i', 's', 'e' -}; - -// Get all inventory items -static char cheatInventorySeq[] = { - 'i', 'n', 'd', 'i', 'a', 'n', 'a' -}; - -// Get all puzzle pieces -static char cheatPuzzleSeq[] = { - 's', 'h', 'e', 'r', 'l', 'o', 'c', 'k' -}; - -// Warp to new map -static char cheatWarpSeq[] = { - 'v', 'i', 's', 'i', 't', 1, 0, 0 -}; - -// Become a pig -static char cheatPigSeq[] = { - 'd', 'e', 'l', 'i', 'v', 'e', 'r', 'a', 'n', 'c', 'e' -}; - -// Kill all monsters -static char cheatMassacreSeq[] = { - 'b', 'u', 't', 'c', 'h', 'e', 'r' -}; - -static char cheatIDKFASeq[] = { - 'c', 'o', 'n', 'a', 'n' -}; - -static char cheatQuickenSeq1[] = { - 'm', 'a', 'r', 't', 'e', 'k' -}; - -static char cheatQuickenSeq2[] = { - 'm', 'a', 'r', 't', 'e', 'k', 'm', 'a', 'r', 't', 'e', 'k' -}; - -static char cheatQuickenSeq3[] = { - 'm', 'a', 'r', 't', 'e', 'k', 'm', 'a', 'r', 't', 'e', 'k', 'm', 'a', 'r', 't', 'e', 'k' -}; - -// New class -static char cheatClass1Seq[] = { - 's', 'h', 'a', 'd', 'o', 'w', 'c', 'a', 's', 't', 'e', 'r' -}; - -static char cheatClass2Seq[] = { - 's', 'h', 'a', 'd', 'o', 'w', 'c', 'a', 's', 't', 'e', 'r', 1, 0 -}; - -static char cheatInitSeq[] = { - 'i', 'n', 'i', 't' -}; - -static char cheatVersionSeq[] = { - 'm', 'r', 'j', 'o', 'n', 'e', 's' -}; - -static char cheatDebugSeq[] = { - 'w', 'h', 'e', 'r', 'e' -}; - -static char cheatScriptSeq1[] = { - 'p', 'u', 'k', 'e' -}; - -static char cheatScriptSeq2[] = { - 'p', 'u', 'k', 'e', 1, 0 -}; - -static char cheatScriptSeq3[] = { - 'p', 'u', 'k', 'e', 1, 0, 0 -}; - -static char cheatRevealSeq[] = { - 'm', 'a', 'p', 's', 'c', 'o' -}; - -// CODE -------------------------------------------------------------------- +typedef int (*cheatfunc_t)(const int*, int); + +/// Helper macro for forming cheat callback function names. +#define CHEAT(x) G_Cheat##x + +/// Helper macro for declaring cheat callback functions. +#define CHEAT_FUNC(x) int G_Cheat##x(const int* args, int player) + +/// Helper macro for registering new cheat event sequence handlers. +#define ADDCHEAT(name, len, callback) G_AddEventSequence((name), (len), CHEAT(callback)) + +CHEAT_FUNC(Armor); +CHEAT_FUNC(Class); +CHEAT_FUNC(Class2); +CHEAT_FUNC(GiveKeys); +CHEAT_FUNC(God); +CHEAT_FUNC(Health); +CHEAT_FUNC(IDKFA); +CHEAT_FUNC(Init); +CHEAT_FUNC(Inventory); +CHEAT_FUNC(Massacre); +CHEAT_FUNC(NoClip); +CHEAT_FUNC(Pig); +CHEAT_FUNC(Puzzle); +CHEAT_FUNC(Quicken); +CHEAT_FUNC(Quicken2); +CHEAT_FUNC(Quicken3); +CHEAT_FUNC(Reveal); +CHEAT_FUNC(Script); +CHEAT_FUNC(Script2); +CHEAT_FUNC(Script3); +CHEAT_FUNC(Sound); +CHEAT_FUNC(Version); +CHEAT_FUNC(Warp); +CHEAT_FUNC(Weapons); +CHEAT_FUNC(Where); static boolean cheatsEnabled(void) { return !IS_NETGAME; } -void Cht_Init(void) +void G_RegisterCheats(void) { - G_AddEventSequence(cheatGodSeq, sizeof(cheatGodSeq), Cht_GodFunc); - G_AddEventSequence(cheatNoClipSeq, sizeof(cheatNoClipSeq), Cht_NoClipFunc); - G_AddEventSequence(cheatWeaponsSeq, sizeof(cheatWeaponsSeq), Cht_WeaponsFunc); - G_AddEventSequence(cheatHealthSeq, sizeof(cheatHealthSeq), Cht_HealthFunc); - G_AddEventSequence(cheatKeysSeq, sizeof(cheatKeysSeq), Cht_GiveKeysFunc); - G_AddEventSequence(cheatSoundSeq, sizeof(cheatSoundSeq), Cht_SoundFunc); - G_AddEventSequence(cheatInventorySeq, sizeof(cheatInventorySeq), Cht_InventoryFunc); - G_AddEventSequence(cheatPuzzleSeq, sizeof(cheatPuzzleSeq), Cht_PuzzleFunc); - G_AddEventSequence(cheatWarpSeq, sizeof(cheatWarpSeq), Cht_WarpFunc); - G_AddEventSequence(cheatPigSeq, sizeof(cheatPigSeq), Cht_PigFunc); - G_AddEventSequence(cheatMassacreSeq, sizeof(cheatMassacreSeq), Cht_MassacreFunc); - G_AddEventSequence(cheatIDKFASeq, sizeof(cheatIDKFASeq), Cht_IDKFAFunc); - G_AddEventSequence(cheatQuickenSeq3, sizeof(cheatQuickenSeq3), Cht_QuickenFunc3); - G_AddEventSequence(cheatQuickenSeq2, sizeof(cheatQuickenSeq2), Cht_QuickenFunc2); - G_AddEventSequence(cheatQuickenSeq1, sizeof(cheatQuickenSeq1), Cht_QuickenFunc1); - G_AddEventSequence(cheatClass2Seq, sizeof(cheatClass2Seq), Cht_ClassFunc2); - G_AddEventSequence(cheatClass1Seq, sizeof(cheatClass1Seq), Cht_ClassFunc1); - G_AddEventSequence(cheatInitSeq, sizeof(cheatInitSeq), Cht_InitFunc); - G_AddEventSequence(cheatVersionSeq, sizeof(cheatVersionSeq), Cht_VersionFunc); - G_AddEventSequence(cheatDebugSeq, sizeof(cheatDebugSeq), Cht_WhereFunc); - G_AddEventSequence(cheatScriptSeq3, sizeof(cheatScriptSeq3), Cht_ScriptFunc3); - G_AddEventSequence(cheatScriptSeq2, sizeof(cheatScriptSeq2), Cht_ScriptFunc2); - G_AddEventSequence(cheatScriptSeq1, sizeof(cheatScriptSeq1), Cht_ScriptFunc1); - G_AddEventSequence(cheatRevealSeq, sizeof(cheatRevealSeq), Cht_RevealFunc); + ADDCHEAT("butcher", 7, Massacre); + ADDCHEAT("casper", 6, NoClip); + ADDCHEAT("clubmed", 7, Health); + ADDCHEAT("conan", 5, IDKFA); + ADDCHEAT("deliverance", 11, Pig); + ADDCHEAT("indiana", 7, Inventory); + ADDCHEAT("init", 4, Init); + ADDCHEAT("locksmith", 9, GiveKeys); + ADDCHEAT("mapsco", 6, Reveal); + ADDCHEAT("martek", 6, Quicken); + ADDCHEAT("martekmartek", 12, Quicken2); + ADDCHEAT("martekmartekmartek", 18, Quicken3); + ADDCHEAT("mrjones", 7, Version); + ADDCHEAT("nra", 3, Weapons); + ADDCHEAT("noise", 5, Sound); + ADDCHEAT("satan", 5, God); + ADDCHEAT("sherlock", 8, Puzzle); + ADDCHEAT("where", 5, Where); + + // Cheats with arguments: + + { char seq[] = { 'p', 'u', 'k', 'e', 1, 0, 0 }; + ADDCHEAT(seq, 7, Script3); + ADDCHEAT(seq, 6, Script2); + ADDCHEAT(seq, 4, Script); + } + + // Change player class. + { char seq[] = { 's', 'h', 'a', 'd', 'o', 'w', 'c', 'a', 's', 't', 'e', 'r', 1, 0 }; + ADDCHEAT(seq, 14, Class2); + ADDCHEAT(seq, 12, Class); + } + + // Warp to a new map. + { char seq[] = { 'v', 'i', 's', 'i', 't', 1, 0, 0 }; + ADDCHEAT(seq, 8, Warp); + } } -int Cht_GodFunc(const int* args, int player) +CHEAT_FUNC(God) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; plr->cheats ^= CF_GODMODE; plr->update |= PSF_STATE; - P_SetMessage(plr, - ((P_GetPlayerCheats(plr) & CF_GODMODE) ? TXT_CHEATGODON : TXT_CHEATGODOFF), false); + P_SetMessage(plr, ((P_GetPlayerCheats(plr) & CF_GODMODE) ? TXT_CHEATGODON : TXT_CHEATGODOFF), false); S_LocalSound(SFX_PLATFORM_STOP, NULL); return true; } @@ -262,7 +152,9 @@ static void giveArmor(player_t* plr) int i; plr->update |= PSF_ARMOR_POINTS; for(i = 0; i < NUMARMOR; ++i) + { plr->armorPoints[i] = PCLASS_INFO(plr->class_)->armorIncrement[i]; + } } static void giveWeapons(player_t* plr) @@ -286,16 +178,17 @@ static void giveAmmo(player_t* plr) } } -int Cht_GiveKeysFunc(const int* args, int player) +CHEAT_FUNC(GiveKeys) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; plr->update |= PSF_KEYS; plr->keys = 2047; @@ -304,17 +197,18 @@ int Cht_GiveKeysFunc(const int* args, int player) return true; } -int Cht_GiveArmorFunc(const int* args, int player) +CHEAT_FUNC(GiveArmor) { player_t* plr = &players[player]; int i; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; for(i = (int)ARMOR_FIRST; i < (int)NUMARMOR; ++i) { @@ -324,16 +218,17 @@ int Cht_GiveArmorFunc(const int* args, int player) return true; } -int Cht_WeaponsFunc(const int* args, int player) +CHEAT_FUNC(Weapons) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; giveWeapons(plr); giveAmmo(plr); @@ -344,26 +239,26 @@ int Cht_WeaponsFunc(const int* args, int player) return true; } -int Cht_NoClipFunc(const int* args, int player) +CHEAT_FUNC(NoClip) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; plr->cheats ^= CF_NOCLIP; plr->update |= PSF_STATE; - P_SetMessage(plr, - ((P_GetPlayerCheats(plr) & CF_NOCLIP) ? TXT_CHEATNOCLIPON : TXT_CHEATNOCLIPOFF), false); + P_SetMessage(plr, ((P_GetPlayerCheats(plr) & CF_NOCLIP) ? TXT_CHEATNOCLIPON : TXT_CHEATNOCLIPOFF), false); S_LocalSound(SFX_PLATFORM_STOP, NULL); return true; } -int Cht_WarpFunc(const int* args, int player) +CHEAT_FUNC(Warp) { player_t* plr = &players[player]; int tens, ones; @@ -371,8 +266,9 @@ int Cht_WarpFunc(const int* args, int player) Uri* uri; uint i, map; - if(IS_NETGAME) - return false; + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; if(G_GameState() == GS_MAP && plr->playerState == PST_DEAD) { @@ -383,7 +279,8 @@ int Cht_WarpFunc(const int* args, int player) tens = args[0] - '0'; ones = args[1] - '0'; if(tens < 0 || tens > 9 || ones < 0 || ones > 9) - { // Bad map + { + // Bad map P_SetMessage(plr, TXT_CHEATBADINPUT, false); return false; } @@ -439,16 +336,17 @@ int Cht_WarpFunc(const int* args, int player) return true; } -int Cht_SoundFunc(const int* args, int player) +CHEAT_FUNC(Sound) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; debugSound = !debugSound; if(debugSound) @@ -500,30 +398,30 @@ static void printDebugInfo(int player) plr->plr->mo->height, plr->plr->mo->radius); } -int Cht_WhereFunc(const int* args, int player) +CHEAT_FUNC(Where) { - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(!userGame) - return false; + DENG_UNUSED(args); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + if(!userGame) return false; printDebugInfo(player); S_LocalSound(SFX_PLATFORM_STOP, NULL); return true; } -int Cht_HealthFunc(const int* args, int player) +CHEAT_FUNC(Health) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; plr->update |= PSF_HEALTH; if(plr->morphTics) @@ -539,17 +437,18 @@ int Cht_HealthFunc(const int* args, int player) return true; } -int Cht_InventoryFunc(const int* args, int player) +CHEAT_FUNC(Inventory) { player_t* plr = &players[player]; int i, j; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; for(i = IIT_NONE + 1; i < IIT_FIRSTPUZZITEM; ++i) { @@ -564,17 +463,18 @@ int Cht_InventoryFunc(const int* args, int player) return true; } -int Cht_PuzzleFunc(const int* args, int player) +CHEAT_FUNC(Puzzle) { player_t* plr = &players[player]; int i; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; for(i = IIT_FIRSTPUZZITEM; i < NUM_INVENTORYITEM_TYPES; ++i) { @@ -586,16 +486,17 @@ int Cht_PuzzleFunc(const int* args, int player) return true; } -int Cht_InitFunc(const int* args, int player) +CHEAT_FUNC(Init) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; G_SetGameAction(GA_RESTARTMAP); P_SetMessage(plr, TXT_CHEATWARP, false); @@ -603,16 +504,17 @@ int Cht_InitFunc(const int* args, int player) return true; } -int Cht_PigFunc(const int* args, int player) +CHEAT_FUNC(Pig) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; if(plr->morphTics) { @@ -628,18 +530,19 @@ int Cht_PigFunc(const int* args, int player) return true; } -int Cht_MassacreFunc(const int* args, int player) +CHEAT_FUNC(Massacre) { player_t* plr = &players[player]; int count; char buf[80]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; count = P_Massacre(); sprintf(buf, "%d monsters killed.", count); @@ -648,22 +551,19 @@ int Cht_MassacreFunc(const int* args, int player) return true; } -int Cht_IDKFAFunc(const int* args, int player) +CHEAT_FUNC(IDKFA) { player_t* plr = &players[player]; int i; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); - if(plr->morphTics) - { - return false; - } + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; + if(plr->morphTics) return false; for(i = 0; i < NUM_WEAPON_TYPES; ++i) { @@ -676,48 +576,51 @@ int Cht_IDKFAFunc(const int* args, int player) return true; } -int Cht_QuickenFunc1(const int* args, int player) +CHEAT_FUNC(Quicken) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; - P_SetMessage(plr, "Trying to cheat? That's one....", false); + P_SetMessage(plr, "Trying to cheat? That's one...", false); S_LocalSound(SFX_PLATFORM_STOP, NULL); return true; } -int Cht_QuickenFunc2(const int* args, int player) +CHEAT_FUNC(Quicken2) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); - P_SetMessage(plr, "That's two....", false); + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; + + P_SetMessage(plr, "That's two...", false); S_LocalSound(SFX_PLATFORM_STOP, NULL); return true; } -int Cht_QuickenFunc3(const int* args, int player) +CHEAT_FUNC(Quicken3) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; P_DamageMobj(plr->plr->mo, NULL, plr->plr->mo, 10000, false); P_SetMessage(plr, "That's three! Time to die.", false); @@ -725,107 +628,109 @@ int Cht_QuickenFunc3(const int* args, int player) return true; } -int Cht_ClassFunc1(const int* args, int player) +CHEAT_FUNC(Class) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; P_SetMessage(plr, "Enter new player class number", false); S_LocalSound(SFX_PLATFORM_STOP, NULL); return true; } -int Cht_ClassFunc2(const int* args, int player) +CHEAT_FUNC(Class2) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; P_PlayerChangeClass(plr, args[0] - '0'); S_LocalSound(SFX_PLATFORM_STOP, NULL); return true; } -int Cht_VersionFunc(const int* args, int player) +CHEAT_FUNC(Version) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; DD_Execute(false, "version"); S_LocalSound(SFX_PLATFORM_STOP, NULL); return true; } -int Cht_ScriptFunc1(const int* args, int player) +CHEAT_FUNC(Script) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; P_SetMessage(plr, "Run which script(01-99)?", false); S_LocalSound(SFX_PLATFORM_STOP, NULL); return true; } -int Cht_ScriptFunc2(const int* args, int player) +CHEAT_FUNC(Script2) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; P_SetMessage(plr, "Run which script(01-99)?", false); S_LocalSound(SFX_PLATFORM_STOP, NULL); return true; } -int Cht_ScriptFunc3(const int* args, int player) +CHEAT_FUNC(Script3) { player_t* plr = &players[player]; int script, tens, ones; byte scriptArgs[3]; char textBuffer[40]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; tens = args[0] - '0'; ones = args[1] - '0'; script = tens * 10 + ones; - if(script < 1) - return false; - if(script > 99) - return false; + if(script < 1 || script > 99) return false; + scriptArgs[0] = scriptArgs[1] = scriptArgs[2] = 0; if(P_StartACS(script, 0, scriptArgs, plr->plr->mo, NULL, 0)) @@ -837,16 +742,17 @@ int Cht_ScriptFunc3(const int* args, int player) return true; } -int Cht_RevealFunc(const int* args, int player) +CHEAT_FUNC(Reveal) { player_t* plr = &players[player]; - if(IS_NETGAME) - return false; - if(gameSkill == SM_NIGHTMARE) - return false; - if(plr->health <= 0) - return false; // Dead players can't cheat. + DENG_UNUSED(args); + DENG_ASSERT(player >= 0 && player < MAXPLAYERS); + + if(IS_NETGAME) return false; + if(gameSkill == SM_NIGHTMARE) return false; + // Dead players can't cheat. + if(plr->health <= 0) return false; if(ST_AutomapIsActive(player)) { @@ -857,18 +763,16 @@ int Cht_RevealFunc(const int* args, int player) } /** - * This is the multipurpose cheat ccmd. + * The multipurpose cheat ccmd. */ D_CMD(Cheat) { - size_t i; - // Give each of the characters in argument two to the SB event handler. - for(i = 0; i < strlen(argv[1]); ++i) + int i, len = (int) strlen(argv[1]); + for(i = 0; i < len; ++i) { event_t ev; - - ev.type = EV_KEY; + ev.type = EV_KEY; ev.state = EVS_DOWN; ev.data1 = argv[1][i]; ev.data2 = ev.data3 = 0; @@ -889,20 +793,17 @@ D_CMD(CheatGod) { int player = CONSOLEPLAYER; - if(IS_NETGAME && !netSvAllowCheats) - return false; + if(IS_NETGAME && !netSvAllowCheats) return false; if(argc == 2) { player = atoi(argv[1]); - if(player < 0 || player >= MAXPLAYERS) - return false; + if(player < 0 || player >= MAXPLAYERS) return false; } - if(!players[player].plr->inGame) - return false; + if(!players[player].plr->inGame) return false; - Cht_GodFunc(NULL, player); + CHEAT(God)(NULL, player); } } return true; @@ -920,20 +821,17 @@ D_CMD(CheatNoClip) { int player = CONSOLEPLAYER; - if(IS_NETGAME && !netSvAllowCheats) - return false; + if(IS_NETGAME && !netSvAllowCheats) return false; if(argc == 2) { player = atoi(argv[1]); - if(player < 0 || player >= MAXPLAYERS) - return false; + if(player < 0 || player >= MAXPLAYERS) return false; } - if(!players[player].plr->inGame) - return false; + if(!players[player].plr->inGame) return false; - Cht_NoClipFunc(NULL, player); + CHEAT(NoClip)(NULL, player); } } return true; @@ -962,24 +860,21 @@ D_CMD(CheatSuicide) { player_t* plr; - if(IS_NETGAME && !netSvAllowCheats) - return false; + if(IS_NETGAME && !netSvAllowCheats) return false; if(argc == 2) { int i = atoi(argv[1]); - if(i < 0 || i >= MAXPLAYERS) - return false; + if(i < 0 || i >= MAXPLAYERS) return false; plr = &players[i]; } else + { plr = &players[CONSOLEPLAYER]; + } - if(!plr->plr->inGame) - return false; - - if(plr->playerState == PST_DEAD) - return false; + if(!plr->plr->inGame) return false; + if(plr->playerState == PST_DEAD) return false; if(!IS_NETGAME || IS_CLIENT) { @@ -1002,8 +897,7 @@ D_CMD(CheatWarp) { int num, args[2]; - if(IS_NETGAME) - return false; + if(IS_NETGAME) return false; if(argc != 2) { @@ -1015,7 +909,7 @@ D_CMD(CheatWarp) args[0] = num / 10 + '0'; args[1] = num % 10 + '0'; - Cht_WarpFunc(args, CONSOLEPLAYER); + CHEAT(Warp)(args, CONSOLEPLAYER); return true; } @@ -1023,12 +917,10 @@ D_CMD(CheatReveal) { int option, i; - if(!cheatsEnabled()) - return false; + if(!cheatsEnabled()) return false; option = atoi(argv[1]); - if(option < 0 || option > 3) - return false; + if(option < 0 || option > 3) return false; for(i = 0; i < MAXPLAYERS; ++i) { @@ -1036,9 +928,13 @@ D_CMD(CheatReveal) ST_RevealAutomap(i, false); if(option == 1) + { ST_RevealAutomap(i, true); + } else if(option != 0) + { ST_SetAutomapCheatLevel(i, option -1); + } } return true; @@ -1053,16 +949,14 @@ D_CMD(CheatGive) if(IS_CLIENT) { - if(argc != 2) - return false; + if(argc != 2) return false; sprintf(buf, "give %s", argv[1]); NetCl_CheatRequest(buf); return true; } - if(IS_NETGAME && !netSvAllowCheats) - return false; + if(IS_NETGAME && !netSvAllowCheats) return false; if(argc != 2 && argc != 3) { @@ -1085,8 +979,7 @@ D_CMD(CheatGive) if(argc == 3) { player = atoi(argv[2]); - if(player < 0 || player >= MAXPLAYERS) - return false; + if(player < 0 || player >= MAXPLAYERS) return false; } if(G_GameState() != GS_MAP) @@ -1139,11 +1032,11 @@ D_CMD(CheatGive) break; case 'h': - Cht_HealthFunc(NULL, player); + CHEAT(Health)(NULL, player); break; case 'i': - Cht_InventoryFunc(NULL, player); + CHEAT(Inventory)(NULL, player); break; case 'k': @@ -1171,11 +1064,11 @@ D_CMD(CheatGive) } // Give all keys. - Cht_GiveKeysFunc(NULL, player); + CHEAT(GiveKeys)(NULL, player); break; case 'p': - Cht_PuzzleFunc(NULL, player); + CHEAT(Puzzle)(NULL, player); break; case 'r': @@ -1202,7 +1095,7 @@ D_CMD(CheatGive) } // Give all armors. - Cht_GiveArmorFunc(NULL, player); + CHEAT(GiveArmor)(NULL, player); break; case 'w': @@ -1244,25 +1137,22 @@ D_CMD(CheatGive) D_CMD(CheatMassacre) { - Cht_MassacreFunc(NULL, CONSOLEPLAYER); + CHEAT(Massacre)(NULL, CONSOLEPLAYER); return true; } D_CMD(CheatWhere) { - Cht_WhereFunc(NULL, CONSOLEPLAYER); + CHEAT(Where)(NULL, CONSOLEPLAYER); return true; } D_CMD(CheatPig) { - if(IS_NETGAME) - return false; + if(IS_NETGAME || !userGame) return false; + if(gameSkill == SM_NIGHTMARE || players[CONSOLEPLAYER].health <= 0) return false; - if(!userGame || gameSkill == SM_NIGHTMARE || players[CONSOLEPLAYER].health <= 0) - return false; - - Cht_PigFunc(NULL, CONSOLEPLAYER); + CHEAT(Pig)(NULL, CONSOLEPLAYER); return true; } @@ -1270,14 +1160,11 @@ D_CMD(CheatShadowcaster) { int args[2]; - if(IS_NETGAME) - return false; - - if(!userGame || gameSkill == SM_NIGHTMARE || players[CONSOLEPLAYER].health <= 0) - return false; + if(IS_NETGAME || !userGame) return false; + if(gameSkill == SM_NIGHTMARE || players[CONSOLEPLAYER].health <= 0) return false; args[0] = atoi(argv[1]) + '0'; - Cht_ClassFunc2(args, CONSOLEPLAYER); + CHEAT(Class2)(args, CONSOLEPLAYER); return true; } @@ -1285,14 +1172,12 @@ D_CMD(CheatRunScript) { int num, args[2]; - if(IS_NETGAME) - return false; - if(!userGame) - return false; + if(IS_NETGAME) return false; + if(!userGame) return false; num = atoi(argv[1]); args[0] = num / 10 + '0'; args[1] = num % 10 + '0'; - Cht_ScriptFunc3(args, CONSOLEPLAYER); + CHEAT(Script3)(args, CONSOLEPLAYER); return true; }