2019-10-25 17:07:14 +00:00
/*
* * gamecvars . cpp
* *
* * most of the game CVARs from the frontend consolidated to only have one instance
* *
* * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* * Copyright 2019 Christoph Oelckers
* * All rights reserved .
* *
* * Redistribution and use in source and binary forms , with or without
* * modification , are permitted provided that the following conditions
* * are met :
* *
* * 1. Redistributions of source code must retain the above copyright
* * notice , this list of conditions and the following disclaimer .
* * 2. Redistributions in binary form must reproduce the above copyright
* * notice , this list of conditions and the following disclaimer in the
* * documentation and / or other materials provided with the distribution .
* * 3. The name of the author may not be used to endorse or promote products
* * derived from this software without specific prior written permission .
* *
* * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ` ` AS IS ' ' AND ANY EXPRESS OR
* * IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED WARRANTIES
* * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED .
* * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT , INDIRECT ,
* * INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES ( INCLUDING , BUT
* * NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE ,
* * DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY
* * THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT
* * ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF
* * THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
* * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* *
* *
*/
2019-10-21 22:18:58 +00:00
# include "c_cvars.h"
2019-10-22 21:31:46 +00:00
# include "gameconfigfile.h"
2019-10-26 07:22:49 +00:00
# include "gamecontrol.h"
2019-10-27 08:38:55 +00:00
# include "m_argv.h"
2019-10-27 12:40:24 +00:00
# include "rts.h"
2019-11-10 10:42:25 +00:00
# include "stats.h"
2020-04-12 06:07:48 +00:00
# include "raze_music.h"
2019-12-02 23:57:03 +00:00
# include "c_dispatch.h"
# include "gstrings.h"
2019-12-08 23:33:14 +00:00
# include "quotemgr.h"
2020-06-20 16:01:02 +00:00
# include "gamestruct.h"
2020-08-16 00:55:50 +00:00
# include "statusbar.h"
2019-10-21 22:18:58 +00:00
CVARD ( Bool , cl_crosshair , true , CVAR_ARCHIVE , " enable/disable crosshair " ) ;
2019-10-21 22:58:51 +00:00
CVARD ( Bool , cl_automsg , false , CVAR_ARCHIVE , " enable/disable automatically sending messages to all players " ) // Not implemented for Blood
2019-12-08 23:33:14 +00:00
CVARD ( Bool , cl_autorun , true , CVAR_ARCHIVE , " enable/disable autorun " )
2019-10-21 22:52:07 +00:00
CVARD ( Bool , cl_runmode , true , CVAR_ARCHIVE , " enable/disable modernized run key operation " )
2019-12-05 00:08:35 +00:00
bool G_CheckAutorun ( bool button )
{
if ( cl_runmode ) return button | | cl_autorun ;
else return button ^ ! ! cl_autorun ;
}
2019-10-21 22:58:51 +00:00
CVARD ( Bool , cl_autosave , true , CVAR_ARCHIVE , " enable/disable autosaves " ) // Not implemented for Blood (but looks like the other games never check it either.)
CVARD ( Bool , cl_autosavedeletion , true , CVAR_ARCHIVE , " enable/disable automatic deletion of autosaves " ) // Not implemented for Blood
CVARD ( Int , cl_maxautosaves , 8 , CVAR_ARCHIVE , " number of autosaves to keep before deleting the oldest " ) // Not implemented for Blood
2020-08-26 15:05:17 +00:00
CVARD ( Bool , cl_obituaries , true , CVAR_ARCHIVE , " enable/disable multiplayer death messages " ) // Not implemented
2019-10-27 16:55:14 +00:00
CVARD ( Bool , cl_idplayers , true , CVAR_ARCHIVE , " enable/disable name display when aiming at opponents " )
2020-08-26 15:05:17 +00:00
CVARD ( Bool , cl_weaponsway , true , CVAR_ARCHIVE , " enable/disable player weapon swaying " )
2019-10-21 22:18:58 +00:00
2019-10-22 00:15:24 +00:00
// Todo: Consolidate these to be consistent across games?
2020-08-26 15:05:17 +00:00
CVARD ( Bool , cl_viewbob , true , CVAR_ARCHIVE , " enable/disable player head bobbing " )
CVARD ( Bool , cl_viewhbob , true , CVAR_ARCHIVE , " enable/disable view horizontal bobbing " ) // Only implemented in Blood
CVARD ( Bool , cl_viewvbob , true , CVAR_ARCHIVE , " enable/disable view vertical bobbing " ) // Only implemented in Blood
2019-10-22 00:15:24 +00:00
CVARD ( Bool , cl_interpolate , true , CVAR_ARCHIVE , " enable/disable view interpolation " ) // only implemented in Blood
CVARD ( Bool , cl_slopetilting , false , CVAR_ARCHIVE , " enable/disable slope tilting " ) // only implemented in Blood
2019-10-27 12:48:03 +00:00
CVARD ( Int , cl_showweapon , 1 , CVAR_ARCHIVE , " enable/disable show weapons " ) // only implemented in Blood
2020-05-22 23:26:51 +00:00
CVARD ( Bool , cl_sointerpolation , true , CVAR_ARCHIVE , " enable/disable sector object interpolation " ) // only implemented in SW
2020-08-26 10:37:16 +00:00
CVARD ( Bool , cl_syncinput , false , CVAR_ARCHIVE , " enable/disable synchronized input with game's ticrate " ) // only implemented in Duke
2021-07-10 12:07:05 +00:00
CVARD ( Bool , cl_swsmoothsway , true , CVAR_ARCHIVE , " move SW weapon left and right smoothly while bobbing " )
2020-08-27 12:42:50 +00:00
CVARD ( Bool , cl_showmagamt , false , CVAR_ARCHIVE , " show the amount of rounds left in the magazine of your weapon on the modern HUD " )
2020-09-15 06:27:03 +00:00
CVARD ( Bool , cl_nomeleeblur , false , CVAR_ARCHIVE , " enable/disable blur effect with melee weapons in SW " )
2020-09-24 12:32:37 +00:00
CVARD ( Bool , cl_exhumedoldturn , false , CVAR_ARCHIVE , " enable/disable legacy turning speed for Powerslave/Exhumed " )
2021-04-15 03:35:42 +00:00
CVARD ( Bool , cl_hudinterpolation , true , CVAR_ARCHIVE , " enable/disable HUD (weapon drawer) interpolation " )
2019-10-22 15:00:22 +00:00
2019-10-22 00:15:24 +00:00
2019-10-22 15:47:24 +00:00
CUSTOM_CVARD ( Int , cl_autoaim , 1 , CVAR_ARCHIVE | CVAR_USERINFO , " enable/disable weapon autoaim " )
2019-10-21 22:18:58 +00:00
{
2021-06-26 10:18:27 +00:00
int automodes = ( g_gameType & ( GAMEFLAG_DUKECOMPAT | GAMEFLAG_BLOOD | GAMEFLAG_SW ) ) ? 2 : 1 ;
2021-02-06 09:56:11 +00:00
if ( self < 0 | | self > automodes ) self = 1 ;
2019-10-21 22:18:58 +00:00
} ;
2019-10-22 15:47:24 +00:00
CUSTOM_CVARD ( Int , cl_weaponswitch , 3 , CVAR_ARCHIVE | CVAR_USERINFO , " enable/disable auto weapon switching " )
2019-10-22 00:31:14 +00:00
{
if ( self < 0 ) self = 0 ;
2020-02-12 21:46:18 +00:00
if ( self > 1 & & ( g_gameType & GAMEFLAG_SW ) ) self = 1 ;
2021-01-02 03:46:58 +00:00
if ( self > 3 & & isBlood ( ) ) self = 3 ;
2019-10-22 00:31:14 +00:00
if ( self > 7 ) self = 7 ;
}
2019-10-22 00:01:05 +00:00
// Sound
2019-12-07 20:39:17 +00:00
CUSTOM_CVARD ( Bool , snd_ambience , true , CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL , " enables/disables ambient sounds " ) // Not implemented for Blood
2019-12-07 19:48:16 +00:00
{
gi - > SetAmbience ( self ) ;
}
2019-10-22 00:01:05 +00:00
CVARD ( Bool , snd_tryformats , true , CVAR_ARCHIVE | CVAR_GLOBALCONFIG , " enables/disables automatic discovery of replacement sounds and music in .flac and .ogg formats " )
2020-10-23 20:53:02 +00:00
CVARD ( Bool , mus_restartonload , false , CVAR_ARCHIVE , " restart the music when loading a saved game with the same map or not " )
2019-12-26 12:04:29 +00:00
CVARD ( Bool , mus_redbook , true , CVAR_ARCHIVE , " enables/disables redbook audio " )
2019-10-22 00:01:05 +00:00
2020-10-23 20:53:02 +00:00
CUSTOM_CVARD ( Int , snd_speech , 1 , CVAR_ARCHIVE , " enables/disables player speech " )
2019-10-22 00:01:05 +00:00
{
2019-10-22 21:31:46 +00:00
if ( self < 0 ) self = 0 ;
2020-01-28 20:31:48 +00:00
else if ( self > 1 ) self = 1 ;
2019-10-22 00:01:05 +00:00
}
2019-10-24 18:28:46 +00:00
2019-10-22 21:31:46 +00:00
// HUD
2020-08-24 20:02:49 +00:00
CUSTOM_CVARD ( Int , hud_size , Hud_Stbar , CVAR_ARCHIVE , " Defines the HUD size and style " )
2019-10-22 21:31:46 +00:00
{
if ( self < 0 ) self = 0 ;
2020-08-16 00:55:50 +00:00
else if ( self > Hud_Nothing ) self = Hud_Nothing ;
else setViewport ( self ) ;
2019-10-22 21:31:46 +00:00
}
2020-10-28 16:16:42 +00:00
CUSTOM_CVARD ( Float , hud_scalefactor , 1 , CVAR_ARCHIVE , " changes the hud scale " )
2020-07-15 17:48:04 +00:00
{
2020-08-24 19:48:47 +00:00
if ( self < 0.36f ) self = 0.36f ;
else if ( self > 1 ) self = 1 ;
2020-08-16 00:55:50 +00:00
else setViewport ( hud_size ) ;
2020-07-15 17:48:04 +00:00
}
2020-08-24 18:20:15 +00:00
// Note: The shift detection here should be part of the key event data, but that requires a lot more work. Ideally use a ShiftBinds mapping. For control through bound keys this should be fine, bunt not for use from the console.
CCMD ( sizeup )
2020-07-15 17:48:04 +00:00
{
2020-08-24 18:20:15 +00:00
if ( ! inputState . ShiftPressed ( ) )
{
if ( hud_size < Hud_Nothing )
{
hud_size = hud_size + 1 ;
gi - > PlayHudSound ( ) ;
}
}
else
{
2021-05-11 23:50:41 +00:00
hud_scalefactor = hud_scalefactor + 0.04f ;
2020-08-24 18:20:15 +00:00
}
2020-07-15 17:48:04 +00:00
}
2020-08-24 18:20:15 +00:00
CCMD ( sizedown )
2020-07-15 17:48:04 +00:00
{
2020-08-24 18:20:15 +00:00
if ( ! inputState . ShiftPressed ( ) )
{
if ( hud_size > 0 )
{
hud_size = hud_size - 1 ;
gi - > PlayHudSound ( ) ;
}
}
else
{
2021-05-11 23:50:41 +00:00
hud_scalefactor = hud_scalefactor - 0.04f ;
2020-08-24 18:20:15 +00:00
}
2020-07-15 17:48:04 +00:00
}
2020-08-24 18:20:15 +00:00
2020-08-24 20:02:49 +00:00
CUSTOM_CVARD ( Float , hud_statscale , 0.5 , CVAR_ARCHIVE , " change the scale of the stats display " )
2020-07-26 21:06:27 +00:00
{
2020-08-24 21:14:55 +00:00
if ( self < 0.36f ) self = 0.36f ;
2020-08-24 20:02:49 +00:00
else if ( self > 1 ) self = 1 ;
2020-07-26 21:06:27 +00:00
}
2019-10-22 22:20:27 +00:00
CVARD ( Bool , hud_stats , false , CVAR_ARCHIVE | CVAR_GLOBALCONFIG , " enable/disable level statistics display " )
CVARD ( Bool , hud_showmapname , true , CVAR_ARCHIVE | CVAR_GLOBALCONFIG , " enable/disable map name display on load " )
2019-10-23 23:30:33 +00:00
CVARD ( Bool , hud_position , false , CVAR_ARCHIVE , " aligns the status bar to the bottom/top " )
2020-08-26 15:05:17 +00:00
CVARD ( Bool , hud_bgstretch , false , CVAR_ARCHIVE , " enable/disable background image stretching in wide resolutions " )
2020-08-23 20:46:53 +00:00
CVARD ( Bool , hud_messages , 1 , CVAR_ARCHIVE , " enable/disable showing messages " )
2019-12-04 00:38:51 +00:00
2019-12-08 23:33:14 +00:00
// This cannot be done with the 'toggle' CCMD because it needs to control itself when to output the message
2019-12-02 23:57:03 +00:00
CCMD ( togglemessages )
{
if ( hud_messages )
{
2020-06-30 20:53:15 +00:00
Printf ( PRINT_MEDIUM | PRINT_NOTIFY , " %s \n " , quoteMgr . GetQuote ( 24 ) ) ;
2019-12-02 23:57:03 +00:00
hud_messages = false ;
}
else
{
hud_messages = true ;
2020-06-30 20:53:15 +00:00
Printf ( PRINT_MEDIUM | PRINT_NOTIFY , " %s \n " , quoteMgr . GetQuote ( 23 ) ) ;
2019-12-02 23:57:03 +00:00
}
}
2020-08-26 15:05:17 +00:00
CVARD_NAMED ( Int , hud_flashing , althud_flashing , true , CVAR_ARCHIVE , " enable/disable althud flashing " )
2019-10-23 23:30:33 +00:00
CUSTOM_CVARD ( Int , r_fov , 90 , CVAR_ARCHIVE | CVAR_GLOBALCONFIG , " change the field of view " )
2019-10-22 22:20:27 +00:00
{
if ( self < 60 ) self = 60 ;
2019-10-26 11:16:32 +00:00
else if ( self > 140 ) self = 140 ;
2019-10-22 22:20:27 +00:00
}
2019-10-22 21:31:46 +00:00
2019-12-05 00:08:35 +00:00
CVARD ( Bool , in_mousemode , true , CVAR_ARCHIVE | CVAR_GLOBALCONFIG , " toggles vertical mouse view " )
CVAR ( Bool , silentmouseaimtoggle , false , CVAR_ARCHIVE | CVAR_GLOBALCONFIG )
CCMD ( togglemouseaim )
2019-10-22 23:30:43 +00:00
{
2019-12-05 00:08:35 +00:00
in_mousemode = ! in_mousemode ;
if ( ! silentmouseaimtoggle )
{
2020-07-23 14:35:54 +00:00
Printf ( PRINT_MEDIUM | PRINT_NOTIFY , " %s \n " , in_mousemode ? GStrings ( " TXT_MOUSEAIMON " ) : GStrings ( " TXT_MOUSEAIMOFF " ) ) ;
2019-12-05 00:08:35 +00:00
}
2019-10-22 23:30:43 +00:00
}
2019-10-22 23:04:07 +00:00
CUSTOM_CVARD ( Int , r_drawweapon , 1 , CVAR_ARCHIVE | CVAR_GLOBALCONFIG , " enable/disable weapon drawing " )
{
if ( self < 0 | | self > 2 ) self = 1 ;
}
2019-11-10 10:42:25 +00:00
ADD_STAT ( fps )
{
return gi - > statFPS ( ) ;
}
2019-12-23 19:55:12 +00:00
ADD_STAT ( coord )
{
return gi - > GetCoordString ( ) ;
}
2019-10-22 23:04:07 +00:00
CUSTOM_CVARD ( Int , r_showfps , 0 , 0 , " show the frame rate counter " )
{
if ( self < 0 | | self > 3 ) self = 1 ;
2019-11-10 10:42:25 +00:00
FStat : : EnableStat ( " fps " , self ! = 0 ) ;
2019-10-22 23:04:07 +00:00
}
2019-10-21 22:18:58 +00:00
2019-10-22 23:04:07 +00:00
CUSTOM_CVARD ( Int , r_showfpsperiod , 0 , 0 , " time in seconds before averaging min and max stats for r_showfps 2+ " )
{
if ( self < 0 | | self > 5 ) self = 1 ;
}
2019-10-22 22:59:01 +00:00
2019-10-22 23:30:43 +00:00
CUSTOM_CVARD ( Float , r_ambientlight , 1.0 , CVAR_ARCHIVE | CVAR_GLOBALCONFIG , " sets the global map light level " )
{
if ( self < 0.1f ) self = 0.1f ;
else if ( self > 10.f ) self = 10.f ;
}
2019-10-21 22:18:58 +00:00
2019-11-05 19:25:57 +00:00
CVARD ( Bool , r_shadows , true , CVAR_ARCHIVE | CVAR_GLOBALCONFIG , " enable/disable sprite and model shadows " )
2019-10-21 22:18:58 +00:00
2019-10-23 12:39:33 +00:00
CVARD ( Bool , r_precache , true , CVAR_ARCHIVE | CVAR_GLOBALCONFIG , " enable/disable the pre-level caching routine " )
2019-10-23 19:11:37 +00:00
CVARD ( Bool , r_voxels , true , CVAR_ARCHIVE , " enable/disable automatic sprite->voxel rendering " )
2019-10-21 22:18:58 +00:00
2020-04-11 22:04:02 +00:00
// color code format is as follows:
// ^## sets a color, where ## is the palette number
// ^S# sets a shade, range is 0-7 equiv to shades 0-14
// ^O resets formatting to defaults
static const char * OSD_StripColors ( char * outBuf , const char * inBuf )
{
const char * ptr = outBuf ;
while ( * inBuf )
{
if ( * inBuf = = ' ^ ' )
{
if ( isdigit ( * ( inBuf + 1 ) ) )
{
inBuf + = 2 + ! ! isdigit ( * ( inBuf + 2 ) ) ;
continue ;
}
else if ( ( toupper ( * ( inBuf + 1 ) ) = = ' O ' ) )
{
inBuf + = 2 ;
continue ;
}
else if ( ( toupper ( * ( inBuf + 1 ) ) = = ' S ' ) & & isdigit ( * ( inBuf + 2 ) ) )
{
inBuf + = 3 ;
continue ;
}
}
* ( outBuf + + ) = * ( inBuf + + ) ;
}
* outBuf = ' \0 ' ;
return ptr ;
}
2019-10-27 12:40:24 +00:00
CVAR ( Bool , adult_lockout , false , CVAR_ARCHIVE )
CUSTOM_CVAR ( String , playername , " Player " , CVAR_ARCHIVE | CVAR_USERINFO )
2019-10-27 08:38:55 +00:00
{
2019-10-27 12:40:24 +00:00
TArray < char > buffer ( strlen ( self ) + 1 , 1 ) ;
OSD_StripColors ( buffer . Data ( ) , self ) ;
if ( buffer . Size ( ) < strlen ( self ) )
{
self = buffer . Data ( ) ;
}
2019-10-27 13:09:56 +00:00
//Net_SendClientInfo(); This is in the client code. Todo.
2019-10-27 08:38:55 +00:00
}
2019-11-09 18:15:03 +00:00
2019-10-27 12:40:24 +00:00
CUSTOM_CVAR ( String , rtsname , " " , CVAR_ARCHIVE | CVAR_USERINFO )
{
RTS_Init ( self ) ;
}
2019-10-27 08:38:55 +00:00
2019-11-02 00:30:21 +00:00
CVAR ( String , usermapfolder , " " , CVAR_ARCHIVE ) ;
2019-10-27 08:38:55 +00:00
2019-12-04 00:38:51 +00:00
CUSTOM_CVAR ( Int , playercolor , 0 , CVAR_ARCHIVE | CVAR_USERINFO )
{
if ( self < 0 | | self > 10 ) self = 0 ;
2020-07-15 16:10:31 +00:00
else ; // gi->PlayerColorChanged(); // this part is game specific
2019-12-04 00:38:51 +00:00
}
2019-12-05 18:52:46 +00:00
// Will only become useful if the obituary system gets overhauled and for localization
2019-12-04 00:38:51 +00:00
CUSTOM_CVAR ( Int , playergender , 0 , CVAR_USERINFO | CVAR_ARCHIVE )
{
if ( self < 0 | | self > 3 ) self = 0 ;
}
2019-11-09 18:15:03 +00:00
2020-01-26 21:22:41 +00:00
2020-08-23 22:05:36 +00:00
2019-11-09 18:15:03 +00:00
CVAR ( Int , m_coop , 0 , CVAR_NOSET )
2020-09-05 14:31:01 +00:00
//CVAR(Int, skill, 2, CVAR_ARCHIVE)
2019-10-22 22:20:27 +00:00
// Currently unavailable due to dependency on an obsolete OpenGL feature
2020-09-05 14:31:01 +00:00
//{ "deliriumblur", "enable/disable delirium blur effect(polymost)", (void *)&gDeliriumBlur, CVAR_BOOL, 0, 1 },