Skip to content

Commit

Permalink
Refactor: Commonized the "warp" console command (now in game.c)
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Sep 6, 2012
1 parent ae8f170 commit a3a4cba
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 266 deletions.
138 changes: 129 additions & 9 deletions doomsday/plugins/common/src/g_game.c
Expand Up @@ -38,15 +38,7 @@
#include <stdio.h>
#include <stdlib.h>

#if __JDOOM__
# include "jdoom.h"
#elif __JDOOM64__
# include "jdoom64.h"
#elif __JHERETIC__
# include "jheretic.h"
#elif __JHEXEN__
# include "jhexen.h"
#endif
#include "common.h"

#include "dmu_lib.h"
#include "fi_lib.h"
Expand Down Expand Up @@ -143,6 +135,7 @@ D_CMD(QuickLoadGame);
D_CMD(QuickSaveGame);
D_CMD(SaveGame);
D_CMD(OpenSaveMenu);
D_CMD(WarpMap);

void G_PlayerReborn(int player);
void G_DoReborn(int playernum);
Expand Down Expand Up @@ -472,6 +465,16 @@ void G_Register(void)

for(i = 0; gameCmds[i].name; ++i)
Con_AddCommand(gameCmds + i);

C_CMD("warp", "i", WarpMap);
#if __JDOOM__ || __JHERETIC__
# if __JDOOM__
if(!(gameModeBits & GM_ANY_DOOM2))
# endif
{
C_CMD("warp", "ii", WarpMap);
}
#endif
}

boolean G_QuitInProgress(void)
Expand Down Expand Up @@ -4069,3 +4072,120 @@ D_CMD(ListMaps)
G_PrintMapList();
return true;
}

D_CMD(WarpMap)
{
int epsd, map, i;

// Only server operators can warp maps in network games.
/// @todo Implement vote or similar mechanics.
if(IS_NETGAME && !IS_NETWORK_SERVER) return false;

#if __JDOOM__ || __JDOOM64__ || __JHEXEN__
# if __JDOOM__
if(gameModeBits & GM_ANY_DOOM2)
# endif
{
// "warp M":
epsd = 0;
map = atoi(argv[1]);
}
#endif
#if __JDOOM__
else
#endif
#if __JDOOM__ || __JHERETIC__
if(argc == 2)
{
// "warp EM" or "warp M":
int num = atoi(argv[1]);
epsd = num / 10;
map = num % 10;
}
else // (argc == 3)
{
// "warp E M":
epsd = atoi(argv[1]);
map = atoi(argv[2]);
}
#endif

// Internally epsiode and map numbers are zero-based.
if(epsd > 0) epsd -= 1;
if(map > 0) map -= 1;

// Catch invalid maps.
#if __JHEXEN__
// Hexen map numbers require translation.
map = P_TranslateMapIfExists(map);
#endif
if(!G_ValidateMap(&epsd, &map))
{
const char* fmtString = argc == 3? "Unknown map \"%s, %s\"." : "Unknown map \"%s%s\".";
AutoStr* msg = Str_Appendf(AutoStr_NewStd(), fmtString, argv[1], argc == 3? argv[2] : "");
P_SetMessage(players + CONSOLEPLAYER, Str_Text(msg), true);
return false;
}

#if __JHEXEN__
// Hexen does not allow warping to the current map.
if(userGame && map == gameMap)
{
P_SetMessage(players + CONSOLEPLAYER, "Cannot warp to the current map.", true);
return false;
}
#endif

// Close any left open UIs.
/// @todo Still necessary here?
for(i = 0; i < MAXPLAYERS; ++i)
{
player_t* plr = players + i;
ddplayer_t* ddplr = plr->plr;
if(!ddplr->inGame) continue;

ST_AutomapOpen(i, false, true);
#if __JHERETIC__ || __JHEXEN__
Hu_InventoryOpen(i, false);
#endif
}
Hu_MenuCommand(MCMD_CLOSEFAST);

// So be it.
#if __JHEXEN__
if(userGame)
{
nextMap = map;
nextMapEntryPoint = 0;
briefDisabled = true;
G_SetGameAction(GA_LEAVEMAP);
}
else
{
G_DeferredNewGame(dSkill, epsd, map, 0/*default*/);
}
#else
briefDisabled = true;
G_DeferredNewGame(gameSkill, epsd, map, 0/*default*/);
#endif

// If the command src was "us" the game library then it was probably in response to
// the local player entering a cheat event sequence, so set the "CHANGING MAP" message.
// Somewhat of a kludge...
if(src == CMDS_GAME && !(IS_NETGAME && IS_SERVER))
{
#if __JHEXEN__
const char* msg = TXT_CHEATWARP;
int soundId = SFX_PLATFORM_STOP;
#elif __JHERETIC__
const char* msg = TXT_CHEATWARP;
int soundId = SFX_DORCLS;
#else //__JDOOM__ || __JDOOM64__
const char* msg = STSTR_CLEV;
int soundId = SFX_NONE;
#endif
P_SetMessage(players + CONSOLEPLAYER, msg, true);
S_LocalSound(soundId, NULL);
}
return true;
}
5 changes: 0 additions & 5 deletions doomsday/plugins/jdoom/src/d_console.c
Expand Up @@ -28,7 +28,6 @@
D_CMD(Cheat);
D_CMD(CheatGod);
D_CMD(CheatNoClip);
D_CMD(CheatWarp);
D_CMD(CheatReveal);
D_CMD(CheatGive);
D_CMD(CheatMassacre);
Expand Down Expand Up @@ -214,10 +213,6 @@ void G_ConsoleRegistration(void)
Con_AddVariable(&gameCVars[i]);
for(i = 0; gameCCmds[i].name; ++i)
Con_AddCommand(&gameCCmds[i]);

C_CMD("warp", "i", CheatWarp);
if(gameModeBits & GM_ANY_DOOM)
C_CMD("warp", "ii", CheatWarp);
}

/**
Expand Down
61 changes: 0 additions & 61 deletions doomsday/plugins/jdoom/src/m_cheat.c
Expand Up @@ -632,67 +632,6 @@ D_CMD(CheatSuicide)
return true;
}

D_CMD(CheatWarp)
{
int epsd, map, i;

if(!cheatsEnabled()) return false;

if(gameModeBits & GM_ANY_DOOM2)
{
// "warp M"
epsd = 0;
map = atoi(argv[1]);
}
else
{
if(argc == 2)
{
// "warp EM"
epsd = argv[1][0] - '0';
map = atoi(argv[1] + 1);
}
else // (argc == 3)
{
// "warp E M"
epsd = atoi(argv[1]);
map = atoi(argv[2]);
}
}

// Internally epsiode and map numbers are zero-based.
if(epsd > 0) epsd -= 1;
if(map > 0) map -= 1;

// Catch invalid maps.
if(!G_ValidateMap(&epsd, &map)) return false;

// Close any left open UIs.
/// @todo Still necessary here?
for(i = 0; i < MAXPLAYERS; ++i)
{
player_t* plr = players + i;
ddplayer_t* ddplr = plr->plr;
if(!ddplr->inGame) continue;

ST_AutomapOpen(i, false, true);
}
Hu_MenuCommand(MCMD_CLOSEFAST);

// So be it.
briefDisabled = true;
G_DeferredNewGame(gameSkill, epsd, map, 0/*default*/);

// If the command src was "us" the game library then it was probably in response to
// the local player entering a cheat event sequence, so set the "CHANGING MAP" message.
// Somewhat of a kludge...
if(src == CMDS_GAME && !(IS_NETGAME && IS_SERVER))
{
P_SetMessage(players + CONSOLEPLAYER, STSTR_CLEV, false);
}
return true;
}

D_CMD(CheatReveal)
{
int option, i;
Expand Down
2 changes: 0 additions & 2 deletions doomsday/plugins/jdoom64/src/d_console.c
Expand Up @@ -43,7 +43,6 @@

D_CMD(CheatGod);
D_CMD(CheatNoClip);
D_CMD(CheatWarp);
D_CMD(CheatReveal);
D_CMD(CheatGive);
D_CMD(CheatMassacre);
Expand Down Expand Up @@ -201,7 +200,6 @@ ccmdtemplate_t gameCCmds[] = {
// $cheats
{"god", NULL, CCmdCheatGod},
{"noclip", NULL, CCmdCheatNoClip},
{"warp", "i", CCmdCheatWarp},
{"reveal", "i", CCmdCheatReveal},
{"give", NULL, CCmdCheatGive},
{"kill", "", CCmdCheatMassacre},
Expand Down
53 changes: 0 additions & 53 deletions doomsday/plugins/jdoom64/src/m_cheat.c
Expand Up @@ -74,7 +74,6 @@ void Cht_GiveAmmoFunc(player_t* plr);
void Cht_GiveKeysFunc(player_t* plr);
void Cht_NoClipFunc(player_t* plr);
void Cht_GiveArmorFunc(player_t* plr);
boolean Cht_WarpFunc(player_t* plr, cheatseq_t* cheat);
boolean Cht_PowerUpFunc(player_t* plr, cheatseq_t* cheat);

// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
Expand Down Expand Up @@ -156,39 +155,6 @@ void Cht_NoClipFunc(player_t* plr)
((P_GetPlayerCheats(plr) & CF_NOCLIP) ? STSTR_NCON : STSTR_NCOFF), false);
}

boolean Cht_WarpFunc(player_t* plr, cheatseq_t* cheat)
{
uint i, epsd, map;

epsd = 0;
map = (cheat->args[0] - '0') * 10 + cheat->args[1] - '0';
if(map != 0) map -= 1;

// Catch invalid maps.
if(!G_ValidateMap(&epsd, &map))
return false;

P_SetMessage(plr, STSTR_CLEV, false);

for(i = 0; i < MAXPLAYERS; ++i)
{
player_t* plr = players + i;
ddplayer_t* ddplr = plr->plr;
if(!ddplr->inGame) continue;

ST_AutomapOpen(i, false, true);
}

// Close the menu if open.
Hu_MenuCommand(MCMD_CLOSEFAST);

// So be it.
briefDisabled = true;
G_DeferredNewGame(gameSkill, epsd, map, 0/*default*/);

return true;
}

boolean Cht_PowerUpFunc(player_t* plr, cheatseq_t* cheat)
{
static const char args[] = { 'v', 's', 'i', 'r', 'a', 'l' };
Expand Down Expand Up @@ -401,25 +367,6 @@ D_CMD(CheatSuicide)
return true;
}

D_CMD(CheatWarp)
{
cheatseq_t cheat;
int num;

if(!cheatsEnabled())
return false;

if(argc != 2)
return false;

num = atoi(argv[1]);
cheat.args[0] = num / 10 + '0';
cheat.args[1] = num % 10 + '0';

Cht_WarpFunc(&players[CONSOLEPLAYER], &cheat);
return true;
}

D_CMD(CheatReveal)
{
int option, i;
Expand Down
3 changes: 0 additions & 3 deletions doomsday/plugins/jheretic/src/h_console.c
Expand Up @@ -30,7 +30,6 @@
D_CMD(Cheat);
D_CMD(CheatGod);
D_CMD(CheatNoClip);
D_CMD(CheatWarp);
D_CMD(CheatReveal);
D_CMD(CheatGive);
D_CMD(CheatMassacre);
Expand Down Expand Up @@ -169,8 +168,6 @@ ccmdtemplate_t gameCCmds[] = {
{"cheat", "s", CCmdCheat},
{"god", NULL, CCmdCheatGod},
{"noclip", NULL, CCmdCheatNoClip},
{"warp", "i", CCmdCheatWarp},
{"warp", "ii", CCmdCheatWarp},
{"reveal", "i", CCmdCheatReveal},
{"give", NULL, CCmdCheatGive},
{"kill", "", CCmdCheatMassacre},
Expand Down

0 comments on commit a3a4cba

Please sign in to comment.