2020-01-23 12:13:20 +00:00
//-------------------------------------------------------------------------
/*
Copyright ( C ) 2010 EDuke32 developers and contributors
Modified by Raze developers and contributors
This file was part of EDuke32 .
EDuke32 is free software ; you can redistribute it and / or
modify it under the terms of the GNU General Public License version 2
as published by the Free Software Foundation .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE .
See the GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
*/
//-------------------------------------------------------------------------
# include "ns.h" // Must come before everything else!
# include "osdcmds.h"
# include "ns.h"
# include "build.h"
# include "names2.h"
# include "panel.h"
# include "game.h"
# include "mytypes.h"
# include "gamecontrol.h"
# include "gstrings.h"
# include "common.h"
2020-05-25 15:11:32 +00:00
# include "v_text.h"
# include "printf.h"
2020-01-23 12:13:20 +00:00
2020-08-05 15:07:19 +00:00
# include "misc.h"
2020-01-23 12:13:20 +00:00
# include "demo.h" // g_firstDemoFile[]
# include "menus.h"
# include "mapinfo.h"
BEGIN_SW_NS
char boardfilename [ BMAX_PATH ] = { 0 } ;
struct osdcmd_cheatsinfo osdcmd_cheatsinfo_stat = { - 1 , 0 , 0 } ;
2020-04-11 22:04:02 +00:00
static int osdcmd_map ( CCmdFuncPtr parm )
2020-01-23 12:13:20 +00:00
{
2020-01-28 10:20:30 +00:00
if ( parm - > numparms ! = 1 )
2020-01-23 12:13:20 +00:00
{
2020-07-14 12:00:27 +00:00
return CCMD_SHOWHELP ;
2020-01-23 12:13:20 +00:00
}
2020-01-30 19:25:52 +00:00
FString mapname = parm - > parms [ 0 ] ;
2020-07-26 21:59:29 +00:00
FString mapfilename = mapname ;
DefaultExtension ( mapfilename , " .map " ) ;
2020-01-30 19:25:52 +00:00
2020-07-26 21:59:29 +00:00
if ( ! fileSystem . FindFile ( mapfilename ) )
2020-01-23 12:13:20 +00:00
{
2020-07-26 21:59:29 +00:00
Printf ( TEXTCOLOR_RED " map: file \" %s \" not found. \n " , mapfilename . GetChars ( ) ) ;
2020-07-14 12:00:27 +00:00
return CCMD_OK ;
2020-01-23 12:13:20 +00:00
}
2020-01-28 10:20:30 +00:00
// Check if the map is already defined.
for ( int i = 0 ; i < 32 ; i + + )
2020-01-23 12:13:20 +00:00
{
2020-01-28 10:20:30 +00:00
if ( mapList [ i ] . labelName . CompareNoCase ( mapname ) = = 0 )
{
2020-02-05 17:55:10 +00:00
FStringf cheatcode ( " swtrek%02d " , i ) ;
2020-01-28 10:20:30 +00:00
WarpCheat ( Player , cheatcode ) ;
2020-07-14 12:00:27 +00:00
return CCMD_OK ;
2020-01-28 10:20:30 +00:00
}
2020-01-23 12:13:20 +00:00
}
2020-07-14 12:00:27 +00:00
return CCMD_OK ;
2020-01-23 12:13:20 +00:00
}
2020-01-28 10:20:30 +00:00
2020-01-23 12:13:20 +00:00
2020-04-11 22:04:02 +00:00
static int osdcmd_activatecheat ( CCmdFuncPtr parm )
2020-01-23 12:13:20 +00:00
{
if ( parm - > numparms ! = 1 )
2020-07-14 12:00:27 +00:00
return CCMD_SHOWHELP ;
2020-01-23 12:13:20 +00:00
memset ( MessageInputString , ' \0 ' , sizeof ( MessageInputString ) ) ;
strcpy ( MessageInputString , parm - > parms [ 0 ] ) ;
CheatInput ( ) ;
2020-07-14 12:00:27 +00:00
return CCMD_OK ;
2020-01-23 12:13:20 +00:00
}
2020-04-11 22:04:02 +00:00
static int osdcmd_god ( CCmdFuncPtr UNUSED ( parm ) )
2020-01-23 12:13:20 +00:00
{
UNREFERENCED_CONST_PARAMETER ( parm ) ;
GodCheat ( Player , " swgod " ) ;
2020-07-14 12:00:27 +00:00
return CCMD_OK ;
2020-01-23 12:13:20 +00:00
}
2020-04-11 22:04:02 +00:00
static int osdcmd_noclip ( CCmdFuncPtr UNUSED ( parm ) )
2020-01-23 12:13:20 +00:00
{
UNREFERENCED_CONST_PARAMETER ( parm ) ;
ClipCheat ( Player , " swghost " ) ;
2020-07-14 12:00:27 +00:00
return CCMD_OK ;
2020-01-23 12:13:20 +00:00
}
2020-04-11 22:04:02 +00:00
int osdcmd_restartmap ( CCmdFuncPtr UNUSED ( parm ) )
2020-01-23 12:13:20 +00:00
{
UNREFERENCED_CONST_PARAMETER ( parm ) ;
RestartCheat ( Player , " swstart " ) ;
2020-07-14 12:00:27 +00:00
return CCMD_OK ;
2020-01-23 12:13:20 +00:00
}
2020-04-11 22:04:02 +00:00
int osdcmd_levelwarp ( CCmdFuncPtr parm )
2020-01-23 17:55:37 +00:00
{
2020-07-14 12:00:27 +00:00
if ( parm - > numparms ! = 1 ) return CCMD_SHOWHELP ;
2020-01-23 17:55:37 +00:00
char cheatcode [ 9 ] = " swtrek## " ;
for ( int i = 0 ; i < 2 ; i + + )
cheatcode [ 6 + i ] = parm - > parms [ 0 ] [ i ] ;
WarpCheat ( Player , cheatcode ) ;
2020-07-14 12:00:27 +00:00
return CCMD_OK ;
2020-01-23 17:55:37 +00:00
}
2020-01-23 12:13:20 +00:00
#if 0
2020-04-11 22:04:02 +00:00
static int osdcmd_spawn ( CCmdFuncPtr parm )
2020-01-23 12:13:20 +00:00
{
int32_t picnum = 0 ;
uint16_t cstat = 0 ;
char pal = 0 ;
int16_t ang = 0 ;
int16_t set = 0 , idx ;
vec3_t vect ;
2020-07-14 22:26:58 +00:00
if ( numplayers > 1 | | ! ( ps [ myconnectindex ] . gm & MODE_GAME ) )
2020-01-23 12:13:20 +00:00
{
2020-04-11 21:45:45 +00:00
Printf ( " spawn: Can't spawn sprites in multiplayer games or demos \n " ) ;
2020-07-14 12:00:27 +00:00
return CCMD_OK ;
2020-01-23 12:13:20 +00:00
}
switch ( parm - > numparms )
{
case 7 : // x,y,z
vect . x = Batol ( parm - > parms [ 4 ] ) ;
vect . y = Batol ( parm - > parms [ 5 ] ) ;
vect . z = Batol ( parm - > parms [ 6 ] ) ;
set | = 8 ;
fallthrough__ ;
case 4 : // ang
ang = Batol ( parm - > parms [ 3 ] ) & 2047 ;
set | = 4 ;
fallthrough__ ;
case 3 : // cstat
cstat = ( uint16_t ) Batol ( parm - > parms [ 2 ] ) ;
set | = 2 ;
fallthrough__ ;
case 2 : // pal
pal = ( uint8_t ) Batol ( parm - > parms [ 1 ] ) ;
set | = 1 ;
fallthrough__ ;
case 1 : // tile number
if ( isdigit ( parm - > parms [ 0 ] [ 0 ] ) )
{
picnum = Batol ( parm - > parms [ 0 ] ) ;
}
else
{
int32_t i ;
int32_t j ;
for ( j = 0 ; j < 2 ; j + + )
{
for ( i = 0 ; i < g_labelCnt ; i + + )
{
if ( ( j = = 0 & & ! Bstrcmp ( label + ( i < < 6 ) , parm - > parms [ 0 ] ) ) | |
( j = = 1 & & ! Bstrcasecmp ( label + ( i < < 6 ) , parm - > parms [ 0 ] ) ) )
{
picnum = labelcode [ i ] ;
break ;
}
}
if ( i < g_labelCnt )
break ;
}
if ( i = = g_labelCnt )
{
2020-04-11 21:45:45 +00:00
Printf ( " spawn: Invalid tile label given \n " ) ;
2020-07-14 12:00:27 +00:00
return CCMD_OK ;
2020-01-23 12:13:20 +00:00
}
}
if ( ( uint32_t ) picnum > = MAXUSERTILES )
{
2020-04-11 21:45:45 +00:00
Printf ( " spawn: Invalid tile number \n " ) ;
2020-07-14 12:00:27 +00:00
return CCMD_OK ;
2020-01-23 12:13:20 +00:00
}
break ;
default :
2020-07-14 12:00:27 +00:00
return CCMD_SHOWHELP ;
2020-01-23 12:13:20 +00:00
}
2020-07-14 22:26:58 +00:00
idx = A_Spawn ( ps [ myconnectindex ] . i , picnum ) ;
2020-01-23 12:13:20 +00:00
if ( set & 1 ) sprite [ idx ] . pal = ( uint8_t ) pal ;
if ( set & 2 ) sprite [ idx ] . cstat = ( int16_t ) cstat ;
if ( set & 4 ) sprite [ idx ] . ang = ang ;
if ( set & 8 )
{
if ( setsprite ( idx , & vect ) < 0 )
{
2020-04-11 21:45:45 +00:00
Printf ( " spawn: Sprite can't be spawned into null space \n " ) ;
2020-01-23 12:13:20 +00:00
A_DeleteSprite ( idx ) ;
}
}
2020-07-14 12:00:27 +00:00
return CCMD_OK ;
2020-01-23 12:13:20 +00:00
}
# endif
2020-04-11 22:04:02 +00:00
static int osdcmd_give ( CCmdFuncPtr parm )
2020-01-23 12:13:20 +00:00
{
int32_t i ;
2020-07-14 12:00:27 +00:00
if ( parm - > numparms ! = 1 ) return CCMD_SHOWHELP ;
2020-01-23 12:13:20 +00:00
if ( ! Bstrcasecmp ( parm - > parms [ 0 ] , " all " ) )
{
ItemCheat ( Player , " swgimme " ) ;
2020-07-14 12:00:27 +00:00
return CCMD_OK ;
2020-01-23 12:13:20 +00:00
}
else if ( ! Bstrcasecmp ( parm - > parms [ 0 ] , " health " ) )
{
HealCheat ( Player , " swmedic " ) ;
2020-07-14 12:00:27 +00:00
return CCMD_OK ;
2020-01-23 12:13:20 +00:00
}
else if ( ! Bstrcasecmp ( parm - > parms [ 0 ] , " weapons " ) )
{
WeaponCheat ( Player , " swguns " ) ;
2020-07-14 12:00:27 +00:00
return CCMD_OK ;
2020-01-23 12:13:20 +00:00
}
else if ( ! Bstrcasecmp ( parm - > parms [ 0 ] , " ammo " ) )
{
2020-01-23 17:55:37 +00:00
AmmoCheat ( Player , " " ) ;
2020-07-14 12:00:27 +00:00
return CCMD_OK ;
2020-01-23 12:13:20 +00:00
}
else if ( ! Bstrcasecmp ( parm - > parms [ 0 ] , " armor " ) )
{
2020-01-23 17:55:37 +00:00
ArmorCheat ( Player , " " ) ; // this cheat did not exist before
2020-07-14 12:00:27 +00:00
return CCMD_OK ;
2020-01-23 12:13:20 +00:00
}
else if ( ! Bstrcasecmp ( parm - > parms [ 0 ] , " keys " ) )
{
2020-01-23 17:55:37 +00:00
KeysCheat ( Player , " swkeys " ) ;
2020-07-14 12:00:27 +00:00
return CCMD_OK ;
2020-01-23 12:13:20 +00:00
}
else if ( ! Bstrcasecmp ( parm - > parms [ 0 ] , " inventory " ) )
{
2020-01-23 17:55:37 +00:00
InventoryCheat ( Player , " " ) ; // this cheat did not exist before
2020-07-14 12:00:27 +00:00
return CCMD_OK ;
2020-01-23 12:13:20 +00:00
}
2020-07-14 12:00:27 +00:00
return CCMD_SHOWHELP ;
2020-01-23 12:13:20 +00:00
}
2020-07-11 13:09:39 +00:00
static int osdcmd_warptocoords ( CCmdFuncPtr parm )
{
2020-08-04 12:33:17 +00:00
if ( parm - > numparms < 3 | | parm - > numparms > 5 )
2020-08-04 08:04:44 +00:00
return CCMD_SHOWHELP ;
2020-07-11 13:09:39 +00:00
Player - > oposx = Player - > posx = atoi ( parm - > parms [ 0 ] ) ;
Player - > oposy = Player - > posy = atoi ( parm - > parms [ 1 ] ) ;
Player - > oposz = Player - > posz = atoi ( parm - > parms [ 2 ] ) ;
2020-08-04 13:13:22 +00:00
if ( parm - > numparms > = 4 )
2020-08-04 12:33:17 +00:00
{
Player - > oq16ang = Player - > q16ang = Player - > camq16ang = fix16_from_int ( atoi ( parm - > parms [ 3 ] ) ) ;
}
if ( parm - > numparms = = 5 )
{
Player - > oq16horiz = Player - > q16horiz = Player - > camq16horiz = fix16_from_int ( atoi ( parm - > parms [ 4 ] ) ) ;
}
2020-07-11 13:09:39 +00:00
2020-08-04 08:04:44 +00:00
return CCMD_OK ;
2020-07-11 13:09:39 +00:00
}
2020-01-23 12:13:20 +00:00
int32_t registerosdcommands ( void )
{
2020-04-11 22:04:02 +00:00
C_RegisterFunction ( " map " , " map <mapfile>: loads the given map " , osdcmd_map ) ;
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 ) ;
2020-08-03 18:51:31 +00:00
// C_RegisterFunction("activatecheat","activatecheat <string>: activates a classic cheat code", osdcmd_activatecheat);
2020-01-23 12:13:20 +00:00
2020-04-11 22:04:02 +00:00
C_RegisterFunction ( " noclip " , " noclip: toggles clipping mode " , osdcmd_noclip ) ;
2020-01-23 12:13:20 +00:00
2020-04-11 22:04:02 +00:00
C_RegisterFunction ( " levelwarp " , " levelwarp <num>: warp to level " , osdcmd_levelwarp ) ;
2020-01-23 12:13:20 +00:00
2020-04-11 22:04:02 +00:00
C_RegisterFunction ( " restartmap " , " restartmap: restarts the current map " , osdcmd_restartmap ) ;
2020-01-23 12:13:20 +00:00
2020-04-11 22:04:02 +00:00
// C_RegisterFunction("spawn","spawn <picnum> [palnum] [cstat] [ang] [x y z]: spawns a sprite with the given properties",osdcmd_spawn);
2020-01-23 12:13:20 +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:09:39 +00:00
2020-01-23 12:13:20 +00:00
return 0 ;
}
END_SW_NS