2019-09-19 22:42:45 +00:00
//-------------------------------------------------------------------------
/*
Copyright ( C ) 2010 - 2019 EDuke32 developers and contributors
Copyright ( C ) 2019 Nuke . YKT
2020-01-28 03:29:47 +00:00
Copyright ( C ) 2020 Raze developers and contributors
2019-09-19 22:42:45 +00:00
2020-01-28 03:29:47 +00:00
This file was part of NBlood .
2019-09-19 22:42:45 +00:00
NBlood is free software ; you can redistribute it and / or
modify it under the terms of the GNU General Public License version 2
as published by the Free Software Foundation .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE .
See the GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
*/
//-------------------------------------------------------------------------
2019-09-21 18:59:54 +00:00
# include "ns.h" // Must come before everything else!
2019-09-19 22:42:45 +00:00
# include "build.h"
# include "baselayer.h"
# include "compat.h"
# include "mmulti.h"
# include "common_game.h"
# include "blood.h"
2019-06-27 04:33:22 +00:00
# include "globals.h"
2019-09-19 22:42:45 +00:00
# include "levels.h"
# include "messages.h"
# include "network.h"
# include "sound.h"
# include "view.h"
2020-01-25 19:21:49 +00:00
# include "mapinfo.h"
2020-07-29 21:18:08 +00:00
# include "gamestate.h"
2019-09-19 22:42:45 +00:00
2019-09-22 06:39:22 +00:00
BEGIN_BLD_NS
2019-09-19 22:42:45 +00:00
2020-01-25 16:10:04 +00:00
void LevelWarp ( int nEpisode , int nLevel ) ;
2020-01-25 15:36:18 +00:00
2020-04-11 22:04:02 +00:00
static int osdcmd_map ( CCmdFuncPtr parm )
2019-09-19 22:42:45 +00:00
{
2020-01-25 19:21:49 +00:00
if ( parm - > numparms ! = 1 )
2020-07-14 12:00:27 +00:00
return CCMD_SHOWHELP ;
2020-01-25 19:21:49 +00:00
2020-07-26 21:59:29 +00:00
FString mapname = parm - > parms [ 0 ] ;
FString mapfilename = mapname ;
DefaultExtension ( mapfilename , " .map " ) ;
2019-09-19 22:42:45 +00:00
2020-07-26 21:59:29 +00:00
if ( ! fileSystem . FindFile ( mapfilename ) )
2019-09-19 22:42:45 +00:00
{
2020-07-27 22:01:16 +00:00
Printf ( TEXTCOLOR_RED " map: file \" %s \" not found. \n " , mapfilename . GetChars ( ) ) ;
2020-07-14 12:00:27 +00:00
return CCMD_OK ;
2019-09-19 22:42:45 +00:00
}
2020-01-25 19:21:49 +00:00
for ( int i = 0 ; i < 512 ; i + + )
{
2020-07-26 21:59:29 +00:00
if ( mapList [ i ] . labelName . CompareNoCase ( mapname ) = = 0 )
2020-01-25 19:21:49 +00:00
{
2020-08-03 18:12:33 +00:00
int e = volfromlevelnum ( mapList [ i ] . levelNumber ) ;
int m = mapfromlevelnum ( mapList [ i ] . levelNumber ) ;
2020-01-25 19:21:49 +00:00
LevelWarp ( e , m ) ;
2020-07-14 12:00:27 +00:00
return CCMD_OK ;
2020-01-25 19:21:49 +00:00
}
}
// Map has not been defined. Treat as user map.
2020-07-26 21:59:29 +00:00
levelAddUserMap ( mapname ) ;
2019-09-19 22:42:45 +00:00
if ( numplayers > 1 )
{
gPacketStartGame . episodeId = gGameOptions . nEpisode ;
gPacketStartGame . levelId = gGameOptions . nLevel ;
netBroadcastNewGame ( ) ;
gStartNewGame = 1 ;
2020-07-14 12:00:27 +00:00
return CCMD_OK ;
2019-09-19 22:42:45 +00:00
}
levelSetupOptions ( gGameOptions . nEpisode , gGameOptions . nLevel ) ;
StartLevel ( & gGameOptions ) ;
viewResizeView ( gViewSize ) ;
2020-07-14 12:00:27 +00:00
return CCMD_OK ;
2019-09-19 22:42:45 +00:00
}
2020-04-11 22:04:02 +00:00
static int osdcmd_give ( CCmdFuncPtr parm )
2019-09-19 22:42:45 +00:00
{
2020-07-29 21:18:08 +00:00
if ( numplayers ! = 1 | | gamestate ! = GS_LEVEL | | gMe - > pXSprite - > health = = 0 )
2019-09-19 22:42:45 +00:00
{
2020-04-11 21:45:45 +00:00
Printf ( " give: Cannot give while dead or not in a single-player game. \n " ) ;
2020-07-14 12:00:27 +00:00
return CCMD_OK ;
2019-09-19 22:42:45 +00:00
}
2020-07-14 12:00:27 +00:00
if ( parm - > numparms ! = 1 ) return CCMD_SHOWHELP ;
2019-09-19 22:42:45 +00:00
if ( ! Bstrcasecmp ( parm - > parms [ 0 ] , " all " ) )
{
SetWeapons ( true ) ;
SetAmmo ( true ) ;
SetToys ( true ) ;
SetArmor ( true ) ;
SetKeys ( true ) ;
2020-08-03 18:51:31 +00:00
bPlayerCheated = true ;
2020-07-14 12:00:27 +00:00
return CCMD_OK ;
2019-09-19 22:42:45 +00:00
}
else if ( ! Bstrcasecmp ( parm - > parms [ 0 ] , " health " ) )
{
actHealDude ( gMe - > pXSprite , 200 , 200 ) ;
2020-08-03 18:51:31 +00:00
bPlayerCheated = true ;
2020-07-14 12:00:27 +00:00
return CCMD_OK ;
2019-09-19 22:42:45 +00:00
}
else if ( ! Bstrcasecmp ( parm - > parms [ 0 ] , " weapons " ) )
{
SetWeapons ( true ) ;
2020-08-03 18:51:31 +00:00
bPlayerCheated = true ;
2020-07-14 12:00:27 +00:00
return CCMD_OK ;
2019-09-19 22:42:45 +00:00
}
else if ( ! Bstrcasecmp ( parm - > parms [ 0 ] , " ammo " ) )
{
SetAmmo ( true ) ;
2020-08-03 18:51:31 +00:00
bPlayerCheated = true ;
2020-07-14 12:00:27 +00:00
return CCMD_OK ;
2019-09-19 22:42:45 +00:00
}
else if ( ! Bstrcasecmp ( parm - > parms [ 0 ] , " armor " ) )
{
SetArmor ( true ) ;
2020-08-03 18:51:31 +00:00
bPlayerCheated = true ;
2020-07-14 12:00:27 +00:00
return CCMD_OK ;
2019-09-19 22:42:45 +00:00
}
else if ( ! Bstrcasecmp ( parm - > parms [ 0 ] , " keys " ) )
{
SetKeys ( true ) ;
2020-08-03 18:51:31 +00:00
bPlayerCheated = true ;
2020-07-14 12:00:27 +00:00
return CCMD_OK ;
2019-09-19 22:42:45 +00:00
}
else if ( ! Bstrcasecmp ( parm - > parms [ 0 ] , " inventory " ) )
{
SetToys ( true ) ;
2020-08-03 18:51:31 +00:00
bPlayerCheated = true ;
2020-07-14 12:00:27 +00:00
return CCMD_OK ;
2019-09-19 22:42:45 +00:00
}
2020-07-14 12:00:27 +00:00
return CCMD_SHOWHELP ;
2019-09-19 22:42:45 +00:00
}
2020-04-11 22:04:02 +00:00
static int osdcmd_god ( CCmdFuncPtr UNUSED ( parm ) )
2019-09-19 22:42:45 +00:00
{
UNREFERENCED_CONST_PARAMETER ( parm ) ;
2020-07-29 21:18:08 +00:00
if ( numplayers = = 1 & & gamestate = = GS_LEVEL )
2019-09-19 22:42:45 +00:00
{
2019-10-21 19:46:41 +00:00
SetGodMode ( ! gMe - > godMode ) ;
2020-08-03 18:51:31 +00:00
bPlayerCheated = true ;
2019-09-19 22:42:45 +00:00
}
else
2020-04-11 21:45:45 +00:00
Printf ( " god: Not in a single-player game. \n " ) ;
2019-09-19 22:42:45 +00:00
2020-07-14 12:00:27 +00:00
return CCMD_OK ;
2019-09-19 22:42:45 +00:00
}
2020-04-11 22:04:02 +00:00
static int osdcmd_noclip ( CCmdFuncPtr UNUSED ( parm ) )
2019-09-19 22:42:45 +00:00
{
UNREFERENCED_CONST_PARAMETER ( parm ) ;
2020-07-29 21:18:08 +00:00
if ( numplayers = = 1 & & gamestate = = GS_LEVEL )
2019-09-19 22:42:45 +00:00
{
SetClipMode ( ! gNoClip ) ;
2020-08-03 18:51:31 +00:00
bPlayerCheated = true ;
2019-09-19 22:42:45 +00:00
}
else
{
2020-04-11 21:45:45 +00:00
Printf ( " noclip: Not in a single-player game. \n " ) ;
2019-09-19 22:42:45 +00:00
}
2020-07-14 12:00:27 +00:00
return CCMD_OK ;
2019-09-19 22:42:45 +00:00
}
2020-04-11 22:04:02 +00:00
static int osdcmd_levelwarp ( CCmdFuncPtr parm )
2020-01-25 16:10:04 +00:00
{
if ( parm - > numparms ! = 2 )
2020-07-14 12:00:27 +00:00
return CCMD_SHOWHELP ;
2020-01-25 16:10:04 +00:00
int e = atoi ( parm - > parms [ 0 ] ) ;
int m = atoi ( parm - > parms [ 1 ] ) ;
if ( e = = 0 | | m = = 0 )
{
2020-05-25 15:11:32 +00:00
Printf ( TEXTCOLOR_RED " Invalid level!: E%sM%s \n " , parm - > parms [ 0 ] , parm - > parms [ 1 ] ) ;
2020-07-14 12:00:27 +00:00
return CCMD_OK ;
2020-01-25 16:10:04 +00:00
}
LevelWarp ( e - 1 , m - 1 ) ;
2020-07-14 12:00:27 +00:00
return CCMD_OK ;
2020-01-25 16:10:04 +00:00
}
2019-09-19 22:42:45 +00:00
2020-07-11 13:05:49 +00:00
static int osdcmd_warptocoords ( CCmdFuncPtr parm )
{
2020-08-04 12:33:17 +00:00
if ( parm - > numparms < 3 | | parm - > numparms > 5 )
2020-07-11 13:05:49 +00:00
return CCMD_SHOWHELP ;
PLAYER * pPlayer = & gPlayer [ myconnectindex ] ;
pPlayer - > pSprite - > x = gView - > pSprite - > x = atoi ( parm - > parms [ 0 ] ) ;
pPlayer - > pSprite - > y = gView - > pSprite - > y = atoi ( parm - > parms [ 1 ] ) ;
pPlayer - > zView = gView - > zView = atoi ( parm - > parms [ 2 ] ) ;
2020-08-04 12:33:17 +00:00
if ( parm - > numparms = = 4 )
{
pPlayer - > q16ang = gView - > q16ang = fix16_from_int ( atoi ( parm - > parms [ 3 ] ) ) ;
}
if ( parm - > numparms = = 5 )
{
// fix me, I'm broken.
pPlayer - > q16horiz = gView - > q16horiz = fix16_from_int ( atoi ( parm - > parms [ 4 ] ) ) ;
gViewAngle = fix16_from_dbl ( atan2 ( atoi ( parm - > parms [ 4 ] ) , 100 ) * ( 1024. / pi : : pi ( ) ) ) ;
}
2020-07-11 13:05:49 +00:00
viewBackupView ( pPlayer - > nPlayer ) ;
return CCMD_OK ;
}
2019-09-19 22:42:45 +00:00
int32_t registerosdcommands ( void )
{
2020-04-11 22:04:02 +00:00
C_RegisterFunction ( " map " , " map <mapname>: loads the given map " , osdcmd_map ) ;
2019-09-19 22:42:45 +00:00
2020-04-11 22:04:02 +00:00
C_RegisterFunction ( " give " , " give <all|health|weapons|ammo|armor|keys|inventory>: gives requested item " , osdcmd_give ) ;
C_RegisterFunction ( " god " , " god: toggles god mode " , osdcmd_god ) ;
C_RegisterFunction ( " noclip " , " noclip: toggles clipping mode " , osdcmd_noclip ) ;
2019-09-19 22:42:45 +00:00
2020-04-11 22:04:02 +00:00
C_RegisterFunction ( " levelwarp " , " levelwarp <e> <m>: warp to episode 'e' and map 'm' " , osdcmd_levelwarp ) ;
2020-01-25 16:10:04 +00:00
2020-08-04 12:33:17 +00:00
C_RegisterFunction ( " warptocoords " , " warptocoords [x] [y] [z] [ang] (optional) [horiz] (optional): warps the player to the specified coordinates " , osdcmd_warptocoords ) ;
2020-07-11 13:05:49 +00:00
2019-09-19 22:42:45 +00:00
return 0 ;
}
2019-09-22 06:39:22 +00:00
END_BLD_NS