2020-05-17 06:51:49 +00:00
//-------------------------------------------------------------------------
/*
Copyright ( C ) 1996 , 2003 - 3 D Realms Entertainment
Copyright ( C ) 2000 , 2003 - Matt Saettler ( EDuke Enhancements )
2020-06-28 07:03:31 +00:00
Copyright ( C ) 2020 - Christoph Oelckers
2020-05-17 06:51:49 +00:00
This file is part of Enhanced Duke Nukem 3 D version 1.5 - Atomic Edition
Duke Nukem 3 D 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
2020-05-17 11:51:18 +00:00
Foundation , Inc . , 59 Temple Place - Suite 330 , Boston , MA 02111 - 1307 , USA .
2020-05-17 06:51:49 +00:00
Original Source : 1996 - Todd Replogle
Prepared for public release : 03 / 21 / 2003 - Charlie Wiederhold , 3 D Realms
EDuke enhancements integrated : 04 / 13 / 2003 - Matt Saettler
Note : EDuke source was in transition . Changes are in - progress in the
source as it is released .
*/
//-------------------------------------------------------------------------
# include "ns.h"
# include "global.h"
2020-08-24 18:34:18 +00:00
# include "gamecontrol.h"
2020-08-31 17:18:53 +00:00
# include "v_video.h"
2020-10-21 08:48:38 +00:00
# include "dukeactor.h"
2020-05-17 06:51:49 +00:00
2021-12-06 06:21:41 +00:00
EXTERN_CVAR ( Float , m_sensitivity_x )
EXTERN_CVAR ( Float , m_yaw )
2020-07-17 18:56:10 +00:00
BEGIN_DUKE_NS
2020-05-17 06:51:49 +00:00
2020-07-18 11:27:24 +00:00
// State timer counters.
2020-08-29 19:20:10 +00:00
static InputPacket loc ; // input accumulation buffer.
2020-07-18 11:27:24 +00:00
2020-05-17 06:51:49 +00:00
//---------------------------------------------------------------------------
//
2020-05-17 11:25:39 +00:00
// handles all HUD related input, i.e. inventory item selection and activation plus weapon selection.
//
// Note: This doesn't restrict the events to WW2GI - since the other games do
// not define any by default there is no harm done keeping the code clean.
2020-05-17 06:51:49 +00:00
//
//---------------------------------------------------------------------------
2020-05-17 11:25:39 +00:00
2020-11-01 16:57:40 +00:00
void hud_input ( int plnum )
2020-05-17 11:25:39 +00:00
{
int i , k ;
uint8_t dainv ;
struct player_struct * p ;
2020-11-01 16:57:40 +00:00
p = & ps [ plnum ] ;
2020-11-02 19:23:48 +00:00
auto pact = p - > GetActor ( ) ;
2020-05-17 11:25:39 +00:00
i = p - > aim_mode ;
2020-11-01 16:57:40 +00:00
p - > aim_mode = ! PlayerInput ( plnum , SB_AIMMODE ) ;
2020-05-17 11:25:39 +00:00
if ( p - > aim_mode < i )
2020-09-24 14:09:31 +00:00
p - > sync . actions | = SB_CENTERVIEW ;
2020-05-17 11:25:39 +00:00
2020-08-03 03:28:16 +00:00
// Backup weapon here as hud_input() is the first function where any one of the weapon variables can change.
2020-11-29 08:00:00 +00:00
p - > backupweapon ( ) ;
2020-08-02 13:00:53 +00:00
2020-05-17 11:25:39 +00:00
if ( isRR ( ) )
{
2020-11-01 16:57:40 +00:00
if ( PlayerInput ( plnum , SB_QUICK_KICK ) & & p - > last_pissed_time = = 0 )
2020-05-17 11:25:39 +00:00
{
2021-12-21 17:19:45 +00:00
if ( ! isRRRA ( ) | | p - > GetActor ( ) - > spr . extra > 0 )
2020-05-17 11:25:39 +00:00
{
p - > last_pissed_time = 4000 ;
2020-11-02 19:23:48 +00:00
S_PlayActorSound ( 437 , pact ) ;
2021-12-21 17:19:45 +00:00
if ( p - > GetActor ( ) - > spr . extra < = gs . max_player_health - gs . max_player_health / 10 )
2020-05-17 11:25:39 +00:00
{
2021-12-21 17:19:45 +00:00
p - > GetActor ( ) - > spr . extra + = 2 ;
p - > last_extra = p - > GetActor ( ) - > spr . extra ;
2021-04-15 08:00:58 +00:00
p - > resurrected = true ;
2020-05-17 11:25:39 +00:00
}
2021-12-21 17:19:45 +00:00
else if ( p - > GetActor ( ) - > spr . extra < gs . max_player_health )
p - > GetActor ( ) - > spr . extra = gs . max_player_health ;
2020-05-17 11:25:39 +00:00
}
}
}
else
{
2020-11-01 16:57:40 +00:00
if ( PlayerInput ( plnum , SB_QUICK_KICK ) & & p - > quick_kick = = 0 & & ( p - > curr_weapon ! = KNEE_WEAPON | | p - > kickback_pic = = 0 ) )
2020-05-17 11:25:39 +00:00
{
2020-11-01 17:23:09 +00:00
SetGameVarID ( g_iReturnVarID , 0 , nullptr , plnum ) ;
2020-11-01 16:57:40 +00:00
OnEvent ( EVENT_QUICKKICK , plnum , nullptr , - 1 ) ;
2021-12-05 16:36:57 +00:00
if ( GetGameVarID ( g_iReturnVarID , nullptr , plnum ) . value ( ) = = 0 )
2020-05-17 11:25:39 +00:00
{
p - > quick_kick = 14 ;
2020-11-01 16:57:40 +00:00
if ( ! p - > quick_kick_msg & & plnum = = screenpeek ) FTA ( QUOTE_MIGHTY_FOOT , p ) ;
2020-07-28 18:43:33 +00:00
p - > quick_kick_msg = true ;
2020-05-17 11:25:39 +00:00
}
}
}
2020-11-01 16:57:40 +00:00
if ( ! PlayerInput ( plnum , SB_QUICK_KICK ) ) p - > quick_kick_msg = false ;
2020-05-17 11:25:39 +00:00
2020-11-01 16:57:40 +00:00
if ( ! PlayerInputBits ( plnum , SB_INTERFACE_BITS ) )
2020-05-17 11:25:39 +00:00
p - > interface_toggle_flag = 0 ;
else if ( p - > interface_toggle_flag = = 0 )
{
p - > interface_toggle_flag = 1 ;
2020-05-17 11:51:18 +00:00
// Don't go on if paused or dead.
2020-07-15 16:10:31 +00:00
if ( paused ) return ;
2021-12-21 17:19:45 +00:00
if ( p - > GetActor ( ) - > spr . extra < = 0 ) return ;
2020-05-17 11:51:18 +00:00
// Activate an inventory item. This just forwards to the other inventory bits. If the inventory selector was taken out of the playsim this could be removed.
2020-11-02 23:20:51 +00:00
if ( PlayerInput ( plnum , SB_INVUSE ) & & p - > newOwner = = nullptr )
2020-05-17 11:25:39 +00:00
{
2020-11-01 17:23:09 +00:00
SetGameVarID ( g_iReturnVarID , 0 , nullptr , plnum ) ;
2020-11-01 16:57:40 +00:00
OnEvent ( EVENT_INVENTORY , plnum , nullptr , - 1 ) ;
2021-12-05 16:36:57 +00:00
if ( GetGameVarID ( g_iReturnVarID , nullptr , plnum ) . value ( ) = = 0 )
2020-05-17 11:25:39 +00:00
{
2020-11-01 16:57:40 +00:00
if ( p - > inven_icon > ICON_NONE & & p - > inven_icon < = ICON_HEATS ) PlayerSetItemUsed ( plnum , p - > inven_icon ) ;
2020-05-17 11:25:39 +00:00
}
}
2020-11-01 16:57:40 +00:00
if ( ! isRR ( ) & & PlayerUseItem ( plnum , ICON_HEATS ) )
2020-05-17 11:25:39 +00:00
{
2020-11-01 17:23:09 +00:00
SetGameVarID ( g_iReturnVarID , 0 , nullptr , plnum ) ;
2020-11-01 16:57:40 +00:00
OnEvent ( EVENT_USENIGHTVISION , plnum , nullptr , - 1 ) ;
2021-12-05 16:36:57 +00:00
if ( GetGameVarID ( g_iReturnVarID , nullptr , plnum ) . value ( ) = = 0 & & p - > heat_amount > 0 )
2020-05-17 11:51:18 +00:00
{
p - > heat_on = ! p - > heat_on ;
p - > inven_icon = 5 ;
2020-11-02 19:23:48 +00:00
S_PlayActorSound ( NITEVISION_ONOFF , pact ) ;
2020-05-17 11:51:18 +00:00
FTA ( 106 + ( ! p - > heat_on ) , p ) ;
}
2020-05-17 11:25:39 +00:00
}
2020-11-01 16:57:40 +00:00
if ( PlayerUseItem ( plnum , ICON_STEROIDS ) )
2020-05-17 11:25:39 +00:00
{
2020-11-01 17:23:09 +00:00
SetGameVarID ( g_iReturnVarID , 0 , nullptr , plnum ) ;
2020-11-01 16:57:40 +00:00
OnEvent ( EVENT_USESTEROIDS , plnum , nullptr , - 1 ) ;
2021-12-05 16:36:57 +00:00
if ( GetGameVarID ( g_iReturnVarID , nullptr , plnum ) . value ( ) = = 0 )
2020-05-17 11:25:39 +00:00
{
2020-05-17 11:51:18 +00:00
if ( p - > steroids_amount = = 400 )
{
p - > steroids_amount - - ;
2020-11-02 19:23:48 +00:00
S_PlayActorSound ( DUKE_TAKEPILLS , pact ) ;
2020-05-17 11:51:18 +00:00
p - > inven_icon = ICON_STEROIDS ;
FTA ( 12 , p ) ;
}
2020-05-17 11:25:39 +00:00
}
2020-05-17 11:51:18 +00:00
return ;
2020-05-17 11:25:39 +00:00
}
2020-11-01 16:57:40 +00:00
if ( PlayerInput ( plnum , SB_INVPREV ) | | PlayerInput ( plnum , SB_INVNEXT ) )
2020-05-17 11:51:18 +00:00
{
p - > invdisptime = 26 * 2 ;
2020-05-17 11:25:39 +00:00
2020-11-01 16:57:40 +00:00
if ( PlayerInput ( plnum , SB_INVNEXT ) ) k = 1 ;
2020-05-17 11:51:18 +00:00
else k = 0 ;
2020-05-17 11:25:39 +00:00
2020-05-17 11:51:18 +00:00
dainv = p - > inven_icon ;
2020-05-17 11:25:39 +00:00
2020-05-17 11:51:18 +00:00
i = 0 ;
CHECKINV1 :
2020-05-17 11:25:39 +00:00
2020-05-17 11:51:18 +00:00
if ( i < 9 )
2020-05-17 11:25:39 +00:00
{
2020-05-17 11:51:18 +00:00
i + + ;
switch ( dainv )
{
case 4 :
if ( p - > jetpack_amount > 0 & & i > 1 )
break ;
if ( k ) dainv = 5 ;
else dainv = 3 ;
goto CHECKINV1 ;
case 6 :
if ( p - > scuba_amount > 0 & & i > 1 )
break ;
if ( k ) dainv = 7 ;
else dainv = 5 ;
goto CHECKINV1 ;
case 2 :
if ( p - > steroids_amount > 0 & & i > 1 )
break ;
if ( k ) dainv = 3 ;
else dainv = 1 ;
goto CHECKINV1 ;
case 3 :
if ( p - > holoduke_amount > 0 & & i > 1 )
break ;
if ( k ) dainv = 4 ;
else dainv = 2 ;
goto CHECKINV1 ;
case 0 :
case 1 :
if ( p - > firstaid_amount > 0 & & i > 1 )
break ;
if ( k ) dainv = 2 ;
else dainv = 7 ;
goto CHECKINV1 ;
case 5 :
if ( p - > heat_amount > 0 & & i > 1 )
break ;
if ( k ) dainv = 6 ;
else dainv = 4 ;
goto CHECKINV1 ;
case 7 :
if ( p - > boot_amount > 0 & & i > 1 )
break ;
if ( k ) dainv = 1 ;
else dainv = 6 ;
goto CHECKINV1 ;
}
2020-05-17 11:25:39 +00:00
}
2020-05-17 11:51:18 +00:00
else dainv = 0 ;
2020-05-17 11:25:39 +00:00
2020-05-17 11:51:18 +00:00
// These events force us to keep the inventory selector in the playsim as opposed to the UI where it really belongs.
2020-11-01 16:57:40 +00:00
if ( PlayerInput ( plnum , SB_INVPREV ) )
2020-05-17 11:51:18 +00:00
{
2020-11-01 17:23:09 +00:00
SetGameVarID ( g_iReturnVarID , dainv , nullptr , plnum ) ;
2020-11-01 16:57:40 +00:00
OnEvent ( EVENT_INVENTORYLEFT , plnum , nullptr , - 1 ) ;
2021-12-05 16:36:57 +00:00
dainv = GetGameVarID ( g_iReturnVarID , nullptr , plnum ) . safeValue ( ) ;
2020-05-17 11:51:18 +00:00
}
2020-11-01 16:57:40 +00:00
if ( PlayerInput ( plnum , SB_INVNEXT ) )
2020-05-17 11:51:18 +00:00
{
2020-11-01 17:23:09 +00:00
SetGameVarID ( g_iReturnVarID , dainv , nullptr , plnum ) ;
2020-11-01 16:57:40 +00:00
OnEvent ( EVENT_INVENTORYRIGHT , plnum , nullptr , - 1 ) ;
2021-12-05 16:36:57 +00:00
dainv = GetGameVarID ( g_iReturnVarID , nullptr , plnum ) . safeValue ( ) ;
2020-05-17 11:51:18 +00:00
}
p - > inven_icon = dainv ;
// Someone must have really hated constant data, doing this with a switch/case (and of course also with literal numbers...)
static const uint8_t invquotes [ ] = { QUOTE_MEDKIT , QUOTE_STEROIDS , QUOTE_HOLODUKE , QUOTE_JETPACK , QUOTE_NVG , QUOTE_SCUBA , QUOTE_BOOTS } ;
if ( dainv > = 1 & & dainv < 8 ) FTA ( invquotes [ dainv - 1 ] , p ) ;
2020-05-17 11:25:39 +00:00
}
2020-11-01 16:57:40 +00:00
int weap = PlayerNewWeapon ( plnum ) ;
2021-07-17 12:42:58 +00:00
if ( weap > 1 & & p - > kickback_pic > 0 )
p - > wantweaponfire = weap - 1 ;
2020-05-17 11:25:39 +00:00
// Here we have to be extra careful that the weapons do not get mixed up, so let's keep the code for Duke and RR completely separate.
2020-11-01 16:57:40 +00:00
fi . selectweapon ( plnum , weap ) ;
2020-05-17 11:25:39 +00:00
2020-11-01 16:57:40 +00:00
if ( PlayerInput ( plnum , SB_HOLSTER ) )
2020-05-17 11:25:39 +00:00
{
if ( p - > curr_weapon > KNEE_WEAPON )
{
if ( p - > holster_weapon = = 0 & & p - > weapon_pos = = 0 )
{
p - > holster_weapon = 1 ;
p - > weapon_pos = - 1 ;
FTA ( QUOTE_WEAPON_LOWERED , p ) ;
}
else if ( p - > holster_weapon = = 1 & & p - > weapon_pos = = - 9 )
{
p - > holster_weapon = 0 ;
p - > weapon_pos = 10 ;
FTA ( QUOTE_WEAPON_RAISED , p ) ;
}
}
}
2020-11-02 23:20:51 +00:00
if ( PlayerUseItem ( plnum , ICON_HOLODUKE ) & & ( isRR ( ) | | p - > newOwner = = nullptr ) )
2020-05-17 11:25:39 +00:00
{
2020-11-01 17:23:09 +00:00
SetGameVarID ( g_iReturnVarID , 0 , nullptr , plnum ) ;
2020-11-01 16:57:40 +00:00
OnEvent ( EVENT_HOLODUKEON , plnum , nullptr , - 1 ) ;
2021-12-05 16:36:57 +00:00
if ( GetGameVarID ( g_iReturnVarID , nullptr , plnum ) . value ( ) = = 0 )
2020-05-17 11:25:39 +00:00
{
2020-05-17 11:51:18 +00:00
if ( ! isRR ( ) )
2020-05-17 11:25:39 +00:00
{
2020-10-21 08:48:38 +00:00
if ( p - > holoduke_on = = nullptr )
2020-05-17 11:25:39 +00:00
{
2020-05-17 11:51:18 +00:00
if ( p - > holoduke_amount > 0 )
{
p - > inven_icon = 3 ;
2020-10-23 17:02:58 +00:00
auto pactor =
2021-11-21 07:56:39 +00:00
EGS ( p - > cursector ,
2021-12-22 09:36:09 +00:00
p - > pos . X ,
2021-12-22 09:40:26 +00:00
p - > pos . Y ,
2021-12-22 09:41:47 +00:00
p - > pos . Z + ( 30 < < 8 ) , TILE_APLAYER , - 64 , 0 , 0 , p - > angle . ang . asbuild ( ) , 0 , 0 , nullptr , 10 ) ;
2020-10-23 17:02:58 +00:00
pactor - > temp_data [ 3 ] = pactor - > temp_data [ 4 ] = 0 ;
p - > holoduke_on = pactor ;
2021-12-21 17:19:45 +00:00
pactor - > spr . yvel = plnum ;
pactor - > spr . extra = 0 ;
2020-08-31 18:01:55 +00:00
FTA ( QUOTE_HOLODUKE_ON , p ) ;
2020-08-31 18:04:20 +00:00
S_PlayActorSound ( TELEPORTER , p - > holoduke_on ) ;
2020-05-17 11:51:18 +00:00
}
2020-08-31 18:01:55 +00:00
else FTA ( QUOTE_HOLODUKE_NOT_FOUND , p ) ;
2020-05-17 11:25:39 +00:00
}
2020-05-17 11:51:18 +00:00
else
{
2020-07-25 07:32:54 +00:00
S_PlayActorSound ( TELEPORTER , p - > holoduke_on ) ;
2020-10-21 08:48:38 +00:00
p - > holoduke_on = nullptr ;
2020-08-31 18:01:55 +00:00
FTA ( QUOTE_HOLODUKE_OFF , p ) ;
2020-05-17 11:51:18 +00:00
}
2020-05-17 11:25:39 +00:00
}
2020-05-17 11:51:18 +00:00
else // In RR this means drinking whiskey.
2020-05-17 11:25:39 +00:00
{
2021-12-21 17:19:45 +00:00
if ( p - > holoduke_amount > 0 & & p - > GetActor ( ) - > spr . extra < gs . max_player_health )
2020-05-17 11:51:18 +00:00
{
p - > holoduke_amount - = 400 ;
2021-12-21 17:19:45 +00:00
p - > GetActor ( ) - > spr . extra + = 5 ;
if ( p - > GetActor ( ) - > spr . extra > gs . max_player_health )
p - > GetActor ( ) - > spr . extra = gs . max_player_health ;
2020-05-17 11:51:18 +00:00
p - > drink_amt + = 5 ;
p - > inven_icon = 3 ;
if ( p - > holoduke_amount = = 0 )
checkavailinven ( p ) ;
2020-11-02 19:23:48 +00:00
if ( p - > drink_amt < 99 & & ! S_CheckActorSoundPlaying ( pact , 425 ) )
S_PlayActorSound ( 425 , pact ) ;
2020-05-17 11:51:18 +00:00
}
2020-05-17 11:25:39 +00:00
}
}
}
2020-11-02 23:20:51 +00:00
if ( isRR ( ) & & PlayerUseItem ( plnum , ICON_HEATS ) & & p - > newOwner = = nullptr )
2020-05-17 11:25:39 +00:00
{
2020-11-01 17:23:09 +00:00
SetGameVarID ( g_iReturnVarID , 0 , nullptr , plnum ) ;
2020-11-01 16:57:40 +00:00
OnEvent ( EVENT_USENIGHTVISION , plnum , nullptr , - 1 ) ;
2021-12-05 16:36:57 +00:00
if ( GetGameVarID ( g_iReturnVarID , nullptr , plnum ) . value ( ) = = 0 )
2020-05-17 11:25:39 +00:00
{
2020-05-17 11:51:18 +00:00
if ( p - > yehaa_timer = = 0 )
2020-05-17 11:25:39 +00:00
{
2020-05-17 11:51:18 +00:00
p - > yehaa_timer = 126 ;
2020-11-02 19:23:48 +00:00
S_PlayActorSound ( 390 , pact ) ;
2020-05-17 11:51:18 +00:00
p - > noise_radius = 16384 ;
2020-11-01 16:57:40 +00:00
madenoise ( plnum ) ;
2021-11-21 07:56:39 +00:00
if ( p - > cursector - > lotag = = 857 )
2020-05-17 11:25:39 +00:00
{
2021-12-21 17:19:45 +00:00
if ( p - > GetActor ( ) - > spr . extra < = gs . max_player_health )
2020-05-17 11:51:18 +00:00
{
2021-12-21 17:19:45 +00:00
p - > GetActor ( ) - > spr . extra + = 10 ;
if ( p - > GetActor ( ) - > spr . extra > = gs . max_player_health )
p - > GetActor ( ) - > spr . extra = gs . max_player_health ;
2020-05-17 11:51:18 +00:00
}
2020-05-17 11:25:39 +00:00
}
2020-05-17 11:51:18 +00:00
else
2020-05-17 11:25:39 +00:00
{
2021-12-21 17:19:45 +00:00
if ( p - > GetActor ( ) - > spr . extra + 1 < = gs . max_player_health )
2020-05-17 11:51:18 +00:00
{
2021-12-21 17:19:45 +00:00
p - > GetActor ( ) - > spr . extra + + ;
2020-05-17 11:51:18 +00:00
}
2020-05-17 11:25:39 +00:00
}
}
}
}
2020-11-01 16:57:40 +00:00
if ( PlayerUseItem ( plnum , ICON_FIRSTAID ) )
2020-05-17 11:25:39 +00:00
{
2020-11-01 17:23:09 +00:00
SetGameVarID ( g_iReturnVarID , 0 , nullptr , plnum ) ;
2020-11-01 16:57:40 +00:00
OnEvent ( EVENT_USEMEDKIT , plnum , nullptr , - 1 ) ;
2021-12-05 16:36:57 +00:00
if ( GetGameVarID ( g_iReturnVarID , nullptr , plnum ) . value ( ) = = 0 )
2020-05-17 11:25:39 +00:00
{
2021-12-21 17:19:45 +00:00
if ( p - > firstaid_amount > 0 & & p - > GetActor ( ) - > spr . extra < gs . max_player_health )
2020-05-17 11:25:39 +00:00
{
2020-05-17 11:51:18 +00:00
if ( ! isRR ( ) )
2020-05-17 11:25:39 +00:00
{
2021-12-21 17:19:45 +00:00
int j = gs . max_player_health - p - > GetActor ( ) - > spr . extra ;
2020-05-17 11:51:18 +00:00
2021-05-12 15:57:36 +00:00
if ( p - > firstaid_amount > j )
2020-05-17 11:51:18 +00:00
{
p - > firstaid_amount - = j ;
2021-12-21 17:19:45 +00:00
p - > GetActor ( ) - > spr . extra = gs . max_player_health ;
2020-05-17 11:51:18 +00:00
p - > inven_icon = 1 ;
}
else
{
2021-12-21 17:19:45 +00:00
p - > GetActor ( ) - > spr . extra + = p - > firstaid_amount ;
2020-05-17 11:51:18 +00:00
p - > firstaid_amount = 0 ;
checkavailinven ( p ) ;
}
2020-11-02 19:23:48 +00:00
S_PlayActorSound ( DUKE_USEMEDKIT , pact ) ;
2020-05-17 11:25:39 +00:00
}
else
{
2020-08-26 22:53:35 +00:00
int j = 10 ;
2020-05-17 11:51:18 +00:00
if ( p - > firstaid_amount > j )
{
p - > firstaid_amount - = j ;
2021-12-21 17:19:45 +00:00
p - > GetActor ( ) - > spr . extra + = j ;
if ( p - > GetActor ( ) - > spr . extra > gs . max_player_health )
p - > GetActor ( ) - > spr . extra = gs . max_player_health ;
2020-05-17 11:51:18 +00:00
p - > inven_icon = 1 ;
}
else
{
2021-12-21 17:19:45 +00:00
p - > GetActor ( ) - > spr . extra + = p - > firstaid_amount ;
2020-05-17 11:51:18 +00:00
p - > firstaid_amount = 0 ;
checkavailinven ( p ) ;
}
2021-12-21 17:19:45 +00:00
if ( p - > GetActor ( ) - > spr . extra > gs . max_player_health )
p - > GetActor ( ) - > spr . extra = gs . max_player_health ;
2020-05-17 11:51:18 +00:00
p - > drink_amt + = 10 ;
2020-11-02 19:23:48 +00:00
if ( p - > drink_amt < = 100 & & ! S_CheckActorSoundPlaying ( pact , DUKE_USEMEDKIT ) )
S_PlayActorSound ( DUKE_USEMEDKIT , pact ) ;
2020-05-17 11:25:39 +00:00
}
}
}
}
2020-11-02 23:20:51 +00:00
if ( PlayerUseItem ( plnum , ICON_JETPACK ) & & ( isRR ( ) | | p - > newOwner = = nullptr ) )
2020-05-17 11:25:39 +00:00
{
2020-11-01 17:23:09 +00:00
SetGameVarID ( g_iReturnVarID , 0 , nullptr , plnum ) ;
2020-11-01 16:57:40 +00:00
OnEvent ( EVENT_USEJETPACK , plnum , nullptr , - 1 ) ;
2021-12-05 16:36:57 +00:00
if ( GetGameVarID ( g_iReturnVarID , nullptr , plnum ) . value ( ) = = 0 )
2020-05-17 11:25:39 +00:00
{
2020-05-17 11:51:18 +00:00
if ( ! isRR ( ) )
2020-05-17 11:25:39 +00:00
{
2020-05-17 11:51:18 +00:00
if ( p - > jetpack_amount > 0 )
2020-05-17 11:25:39 +00:00
{
2020-05-17 11:51:18 +00:00
p - > jetpack_on = ! p - > jetpack_on ;
if ( p - > jetpack_on )
{
p - > inven_icon = 4 ;
2020-11-02 19:23:48 +00:00
S_StopSound ( - 1 , pact , CHAN_VOICE ) ; // this will stop the falling scream
S_PlayActorSound ( DUKE_JETPACK_ON , pact ) ;
2020-05-17 11:51:18 +00:00
FTA ( QUOTE_JETPACK_ON , p ) ;
}
else
{
p - > hard_landing = 0 ;
p - > poszv = 0 ;
2020-11-02 19:23:48 +00:00
S_PlayActorSound ( DUKE_JETPACK_OFF , pact ) ;
S_StopSound ( DUKE_JETPACK_IDLE , pact ) ;
S_StopSound ( DUKE_JETPACK_ON , pact ) ;
2020-05-17 11:51:18 +00:00
FTA ( QUOTE_JETPACK_OFF , p ) ;
}
2020-05-17 11:25:39 +00:00
}
2020-05-17 11:51:18 +00:00
else FTA ( QUOTE_JETPACK_NOT_FOUND , p ) ;
2020-05-17 11:25:39 +00:00
}
2020-05-17 11:51:18 +00:00
else
2020-05-17 11:25:39 +00:00
{
2020-05-17 11:51:18 +00:00
// eat cow pie
2021-12-21 17:19:45 +00:00
if ( p - > jetpack_amount > 0 & & p - > GetActor ( ) - > spr . extra < gs . max_player_health )
2020-05-17 11:25:39 +00:00
{
2020-11-02 19:23:48 +00:00
if ( ! S_CheckActorSoundPlaying ( pact , 429 ) )
S_PlayActorSound ( 429 , pact ) ;
2020-05-17 11:51:18 +00:00
p - > jetpack_amount - = 100 ;
if ( p - > drink_amt > 0 )
{
p - > drink_amt - = 5 ;
if ( p - > drink_amt < 0 )
p - > drink_amt = 0 ;
}
if ( p - > eat < 100 )
{
p - > eat + = 5 ;
if ( p - > eat > 100 )
p - > eat = 100 ;
}
2021-12-21 17:19:45 +00:00
p - > GetActor ( ) - > spr . extra + = 5 ;
2020-05-17 11:25:39 +00:00
2020-05-17 11:51:18 +00:00
p - > inven_icon = 4 ;
2020-05-17 11:25:39 +00:00
2021-12-21 17:19:45 +00:00
if ( p - > GetActor ( ) - > spr . extra > gs . max_player_health )
p - > GetActor ( ) - > spr . extra = gs . max_player_health ;
2020-05-17 11:25:39 +00:00
2020-05-17 11:51:18 +00:00
if ( p - > jetpack_amount < = 0 )
checkavailinven ( p ) ;
}
2020-05-17 11:25:39 +00:00
}
}
}
2021-04-11 05:43:11 +00:00
if ( PlayerInput ( plnum , SB_TURNAROUND ) & & p - > angle . spin = = 0 & & p - > on_crane = = nullptr )
2020-05-17 11:25:39 +00:00
{
2020-11-01 17:23:09 +00:00
SetGameVarID ( g_iReturnVarID , 0 , nullptr , plnum ) ;
2020-11-01 16:57:40 +00:00
OnEvent ( EVENT_TURNAROUND , plnum , nullptr , - 1 ) ;
2021-12-05 16:36:57 +00:00
if ( GetGameVarID ( g_iReturnVarID , nullptr , plnum ) . value ( ) ! = 0 )
2020-05-17 11:51:18 +00:00
{
2020-09-24 14:09:31 +00:00
p - > sync . actions & = ~ SB_TURNAROUND ;
2020-05-17 11:51:18 +00:00
}
2020-05-17 11:25:39 +00:00
}
}
}
2020-07-16 16:58:31 +00:00
2020-07-17 22:34:20 +00:00
//---------------------------------------------------------------------------
//
2020-07-18 07:59:16 +00:00
// Main input routine.
// This includes several input improvements from EDuke32, but this code
// has been mostly rewritten completely to make it clearer and reduce redundancy.
2020-07-17 22:34:20 +00:00
//
//---------------------------------------------------------------------------
2020-07-16 16:58:31 +00:00
2021-01-01 23:09:42 +00:00
#if 0
2020-07-16 16:58:31 +00:00
enum
{
2021-01-01 23:09:42 +00:00
2020-10-15 08:47:14 +00:00
TURBOTURNTIME = ( TICRATE / 8 ) , // 7
2020-07-17 22:34:20 +00:00
NORMALTURN = 15 ,
PREAMBLETURN = 5 ,
NORMALKEYMOVE = 40 ,
MAXVEL = ( ( NORMALKEYMOVE * 2 ) + 10 ) ,
MAXSVEL = ( ( NORMALKEYMOVE * 2 ) + 10 ) ,
2020-10-15 08:47:14 +00:00
MAXANGVEL = 1024 , // 127
MAXHORIZVEL = 256 , // 127
2021-01-01 23:09:42 +00:00
} ;
# endif
2020-07-17 22:34:20 +00:00
2021-01-01 23:09:42 +00:00
enum
{
2020-11-06 05:34:46 +00:00
MAXVELMOTO = 120 ,
VEHICLETURN = 20
2020-07-16 16:58:31 +00:00
} ;
2020-07-16 20:49:26 +00:00
//---------------------------------------------------------------------------
//
2020-07-17 22:34:20 +00:00
// handles the input bits
2020-07-16 20:49:26 +00:00
//
//---------------------------------------------------------------------------
2020-09-06 10:17:54 +00:00
static void processInputBits ( player_struct * p , ControlInfo * const hidInput )
2020-07-16 20:49:26 +00:00
{
2020-11-07 07:16:16 +00:00
// Set-up crouch bools.
2021-11-21 07:56:39 +00:00
int const sectorLotag = p - > insector ( ) ? p - > cursector - > lotag : 0 ;
2020-11-07 07:16:16 +00:00
bool const crouchable = sectorLotag ! = ST_2_UNDERWATER & & ( sectorLotag ! = ST_1_ABOVE_WATER | | p - > spritebridge ) ;
bool const disableToggle = p - > jetpack_on | | ( ! crouchable & & p - > on_ground ) | | ( isRRRA ( ) & & ( p - > OnMotorcycle | | p - > OnBoat ) ) ;
ApplyGlobalInput ( loc , hidInput , crouchable , disableToggle ) ;
2020-08-29 19:09:04 +00:00
if ( isRR ( ) & & ( loc . actions & SB_CROUCH ) ) loc . actions & = ~ SB_JUMP ;
2020-08-28 20:51:05 +00:00
2020-08-29 11:32:14 +00:00
if ( p - > OnMotorcycle | | p - > OnBoat )
2020-08-27 22:03:35 +00:00
{
// mask out all actions not compatible with vehicles.
2020-08-29 19:09:04 +00:00
loc . actions & = ~ ( SB_WEAPONMASK_BITS | SB_TURNAROUND | SB_CENTERVIEW | SB_HOLSTER | SB_JUMP | SB_CROUCH | SB_RUN |
2020-08-29 11:32:14 +00:00
SB_AIM_UP | SB_AIM_DOWN | SB_AIMMODE | SB_LOOK_UP | SB_LOOK_DOWN | SB_LOOK_LEFT | SB_LOOK_RIGHT ) ;
2020-07-16 20:49:26 +00:00
}
2020-08-29 11:32:14 +00:00
else
{
if ( buttonMap . ButtonDown ( gamefunc_Quick_Kick ) ) // this shares a bit with another function so cannot be in the common code.
2020-08-29 19:09:04 +00:00
loc . actions | = SB_QUICK_KICK ;
2020-07-17 18:56:10 +00:00
2020-08-29 19:09:04 +00:00
if ( ( isRR ( ) & & p - > drink_amt > 88 ) ) loc . actions | = SB_LOOK_LEFT ;
if ( ( isRR ( ) & & p - > drink_amt > 99 ) ) loc . actions | = SB_LOOK_DOWN ;
2020-08-29 11:32:14 +00:00
}
2020-07-16 21:32:00 +00:00
}
2020-07-16 17:16:56 +00:00
//---------------------------------------------------------------------------
//
2020-07-17 22:34:20 +00:00
// split out for readability
2020-07-16 17:16:56 +00:00
//
//---------------------------------------------------------------------------
2020-11-06 05:34:46 +00:00
static double motoApplyTurn ( player_struct * p , ControlInfo * const hidInput , bool const kbdLeft , bool const kbdRight , double const factor )
2020-07-16 17:16:56 +00:00
{
2020-11-06 05:34:46 +00:00
double turnvel = 0 ;
2020-08-04 07:10:44 +00:00
p - > oTiltStatus = p - > TiltStatus ;
2020-07-24 10:46:20 +00:00
2020-07-16 17:16:56 +00:00
if ( p - > MotoSpeed = = 0 | | ! p - > on_ground )
{
2021-01-01 22:59:51 +00:00
resetTurnHeldAmt ( ) ;
2020-11-06 05:34:46 +00:00
if ( kbdLeft | | hidInput - > mouseturnx < 0 | | hidInput - > dyaw < 0 )
2020-07-16 17:16:56 +00:00
{
2021-05-12 15:57:36 +00:00
p - > TiltStatus - = ( float ) factor ;
2020-07-16 17:16:56 +00:00
if ( p - > TiltStatus < - 10 )
p - > TiltStatus = - 10 ;
}
2020-11-06 05:34:46 +00:00
else if ( kbdRight | | hidInput - > mouseturnx > 0 | | hidInput - > dyaw > 0 )
2020-07-16 17:16:56 +00:00
{
2021-05-12 15:57:36 +00:00
p - > TiltStatus + = ( float ) factor ;
2020-07-16 17:16:56 +00:00
if ( p - > TiltStatus > 10 )
p - > TiltStatus = 10 ;
}
}
else
{
2020-11-06 05:34:46 +00:00
if ( kbdLeft | | kbdRight | | p - > moto_drink | | hidInput - > mouseturnx | | hidInput - > dyaw )
2020-07-16 17:16:56 +00:00
{
2021-01-01 10:21:26 +00:00
double const velScale = 3. / 10 ;
2020-11-06 05:34:46 +00:00
auto const baseVel = ( buttonMap . ButtonDown ( gamefunc_Move_Backward ) | | hidInput - > dz < 0 ) & & p - > MotoSpeed < = 0 ? - VEHICLETURN : VEHICLETURN ;
if ( kbdLeft | | p - > moto_drink < 0 | | hidInput - > mouseturnx < 0 | | hidInput - > dyaw < 0 )
2020-07-16 17:16:56 +00:00
{
2021-01-01 22:59:51 +00:00
updateTurnHeldAmt ( factor ) ;
2021-05-12 15:57:36 +00:00
p - > TiltStatus - = ( float ) factor ;
2020-11-06 05:34:46 +00:00
2020-07-24 10:46:20 +00:00
if ( p - > TiltStatus < - 10 )
p - > TiltStatus = - 10 ;
2020-11-06 05:34:46 +00:00
if ( kbdLeft )
2021-01-01 22:59:51 +00:00
turnvel - = isTurboTurnTime ( ) & & p - > MotoSpeed > 0 ? baseVel : baseVel * velScale ;
2020-11-06 05:34:46 +00:00
if ( hidInput - > mouseturnx < 0 )
2021-01-01 10:21:26 +00:00
turnvel - = sqrt ( ( p - > MotoSpeed > 0 ? baseVel : baseVel * velScale ) * - ( hidInput - > mouseturnx / factor ) * 2. ) ;
2020-11-06 05:34:46 +00:00
if ( hidInput - > dyaw < 0 )
2021-01-01 10:21:26 +00:00
turnvel + = ( p - > MotoSpeed > 0 ? baseVel : baseVel * velScale ) * hidInput - > dyaw ;
2020-07-16 17:16:56 +00:00
}
2020-07-24 10:46:20 +00:00
2020-11-06 05:34:46 +00:00
if ( kbdRight | | p - > moto_drink > 0 | | hidInput - > mouseturnx > 0 | | hidInput - > dyaw > 0 )
2020-07-16 17:16:56 +00:00
{
2021-01-01 22:59:51 +00:00
updateTurnHeldAmt ( factor ) ;
2021-05-12 15:57:36 +00:00
p - > TiltStatus + = ( float ) factor ;
2020-11-06 05:34:46 +00:00
2020-07-24 10:46:20 +00:00
if ( p - > TiltStatus > 10 )
p - > TiltStatus = 10 ;
2020-11-06 05:34:46 +00:00
if ( kbdRight )
2021-01-01 22:59:51 +00:00
turnvel + = isTurboTurnTime ( ) & & p - > MotoSpeed > 0 ? baseVel : baseVel * velScale ;
2020-11-06 05:34:46 +00:00
if ( hidInput - > mouseturnx > 0 )
2021-01-01 10:21:26 +00:00
turnvel + = sqrt ( ( p - > MotoSpeed > 0 ? baseVel : baseVel * velScale ) * ( hidInput - > mouseturnx / factor ) * 2. ) ;
2020-11-06 05:34:46 +00:00
if ( hidInput - > dyaw > 0 )
2021-01-01 10:21:26 +00:00
turnvel + = ( p - > MotoSpeed > 0 ? baseVel : baseVel * velScale ) * hidInput - > dyaw ;
2020-07-16 17:16:56 +00:00
}
}
else
{
2021-01-01 22:59:51 +00:00
resetTurnHeldAmt ( ) ;
2020-07-16 17:16:56 +00:00
if ( p - > TiltStatus > 0 )
2021-05-12 15:57:36 +00:00
p - > TiltStatus - = ( float ) factor ;
2020-07-16 17:16:56 +00:00
else if ( p - > TiltStatus < 0 )
2021-05-12 15:57:36 +00:00
p - > TiltStatus + = ( float ) factor ;
2020-07-16 17:16:56 +00:00
}
}
2020-07-24 23:51:52 +00:00
if ( fabs ( p - > TiltStatus ) < factor )
p - > TiltStatus = 0 ;
2020-07-24 10:46:20 +00:00
return turnvel * factor ;
2020-07-16 17:16:56 +00:00
}
2020-07-16 16:58:31 +00:00
//---------------------------------------------------------------------------
//
2020-07-16 17:16:56 +00:00
// same for the boat
2020-07-16 16:58:31 +00:00
//
//---------------------------------------------------------------------------
2020-11-06 05:34:46 +00:00
static double boatApplyTurn ( player_struct * p , ControlInfo * const hidInput , bool const kbdLeft , bool const kbdRight , double const factor )
2020-07-16 16:58:31 +00:00
{
2020-11-06 05:34:46 +00:00
double turnvel = 0 ;
p - > oTiltStatus = p - > TiltStatus ;
2020-07-16 16:58:31 +00:00
if ( p - > MotoSpeed )
{
2020-11-06 05:34:46 +00:00
if ( kbdLeft | | kbdRight | | p - > moto_drink | | hidInput - > mouseturnx | | hidInput - > dyaw )
2020-07-16 16:58:31 +00:00
{
2021-11-14 11:25:25 +00:00
double const velScale = ! p - > NotOnWater ? 1. : 6. / 19. ;
auto const baseVel = + VEHICLETURN * velScale ;
2020-11-06 05:34:46 +00:00
if ( kbdLeft | | p - > moto_drink < 0 | | hidInput - > mouseturnx < 0 | | hidInput - > dyaw < 0 )
2020-07-16 16:58:31 +00:00
{
2021-01-01 22:59:51 +00:00
updateTurnHeldAmt ( factor ) ;
2020-11-06 05:34:46 +00:00
2020-07-24 11:27:47 +00:00
if ( ! p - > NotOnWater )
{
2021-05-12 15:57:36 +00:00
p - > TiltStatus - = ( float ) factor ;
2020-07-24 11:27:47 +00:00
if ( p - > TiltStatus < - 10 )
p - > TiltStatus = - 10 ;
}
2020-11-06 05:34:46 +00:00
2020-11-06 06:11:15 +00:00
if ( kbdLeft )
2021-01-01 22:59:51 +00:00
turnvel - = isTurboTurnTime ( ) ? baseVel : baseVel * velScale ;
2020-11-06 05:34:46 +00:00
if ( hidInput - > mouseturnx < 0 )
2020-11-06 22:48:26 +00:00
turnvel - = sqrt ( baseVel * - ( hidInput - > mouseturnx / factor ) * 2. ) ;
2020-11-06 05:34:46 +00:00
if ( hidInput - > dyaw < 0 )
turnvel + = baseVel * hidInput - > dyaw ;
2020-07-16 16:58:31 +00:00
}
2020-07-24 11:27:47 +00:00
2020-11-06 05:34:46 +00:00
if ( kbdRight | | p - > moto_drink > 0 | | hidInput - > mouseturnx > 0 | | hidInput - > dyaw > 0 )
2020-07-16 16:58:31 +00:00
{
2021-01-01 22:59:51 +00:00
updateTurnHeldAmt ( factor ) ;
2020-11-06 05:34:46 +00:00
2020-07-24 11:27:47 +00:00
if ( ! p - > NotOnWater )
{
2021-05-12 15:57:36 +00:00
p - > TiltStatus + = ( float ) factor ;
2020-07-24 11:27:47 +00:00
if ( p - > TiltStatus > 10 )
p - > TiltStatus = 10 ;
}
2020-11-06 05:34:46 +00:00
if ( kbdRight )
2021-01-01 22:59:51 +00:00
turnvel + = isTurboTurnTime ( ) ? baseVel : baseVel * velScale ;
2020-11-06 05:34:46 +00:00
if ( hidInput - > mouseturnx > 0 )
2020-11-06 22:48:26 +00:00
turnvel + = sqrt ( baseVel * ( hidInput - > mouseturnx / factor ) * 2. ) ;
2020-11-06 05:34:46 +00:00
if ( hidInput - > dyaw > 0 )
turnvel + = baseVel * hidInput - > dyaw ;
2020-07-16 16:58:31 +00:00
}
}
else if ( ! p - > NotOnWater )
{
2021-01-01 22:59:51 +00:00
resetTurnHeldAmt ( ) ;
2020-07-16 16:58:31 +00:00
if ( p - > TiltStatus > 0 )
2021-05-12 15:57:36 +00:00
p - > TiltStatus - = ( float ) factor ;
2020-07-16 16:58:31 +00:00
else if ( p - > TiltStatus < 0 )
2021-05-12 15:57:36 +00:00
p - > TiltStatus + = ( float ) factor ;
2020-07-16 16:58:31 +00:00
}
}
2020-07-24 11:27:47 +00:00
else if ( ! p - > NotOnWater )
2020-07-18 11:27:24 +00:00
{
2021-01-01 22:59:51 +00:00
resetTurnHeldAmt ( ) ;
2020-07-24 11:27:47 +00:00
if ( p - > TiltStatus > 0 )
2021-05-12 15:57:36 +00:00
p - > TiltStatus - = ( float ) factor ;
2020-07-24 11:27:47 +00:00
else if ( p - > TiltStatus < 0 )
2021-05-12 15:57:36 +00:00
p - > TiltStatus + = ( float ) factor ;
2020-07-18 11:27:24 +00:00
}
2020-07-24 11:27:47 +00:00
2020-07-24 11:38:11 +00:00
if ( fabs ( p - > TiltStatus ) < factor )
2020-07-24 11:27:47 +00:00
p - > TiltStatus = 0 ;
return turnvel * factor ;
2020-07-16 16:58:31 +00:00
}
2020-07-17 18:56:10 +00:00
//---------------------------------------------------------------------------
//
// much of this was rewritten from scratch to make the logic easier to follow.
//
//---------------------------------------------------------------------------
2020-11-06 05:34:46 +00:00
static void processVehicleInput ( player_struct * p , ControlInfo * const hidInput , InputPacket & input , double const scaleAdjust )
2020-07-17 18:56:10 +00:00
{
2020-11-06 05:34:46 +00:00
bool const kbdLeft = buttonMap . ButtonDown ( gamefunc_Turn_Left ) | | buttonMap . ButtonDown ( gamefunc_Strafe_Left ) ;
bool const kbdRight = buttonMap . ButtonDown ( gamefunc_Turn_Right ) | | buttonMap . ButtonDown ( gamefunc_Strafe_Right ) ;
2021-12-06 06:21:41 +00:00
// Cancel out micro-movement
if ( fabs ( hidInput - > mouseturnx ) < ( m_sensitivity_x * m_yaw * backendinputscale ( ) * 2.f ) ) hidInput - > mouseturnx = 0 ;
2020-11-06 05:34:46 +00:00
p - > vehTurnLeft = kbdLeft | | hidInput - > mouseturnx < 0 | | hidInput - > dyaw < 0 ;
p - > vehTurnRight = kbdRight | | hidInput - > mouseturnx > 0 | | hidInput - > dyaw > 0 ;
2020-07-17 18:56:10 +00:00
2020-07-17 20:09:01 +00:00
if ( p - > OnBoat | | ! p - > moto_underwater )
{
2021-10-30 08:21:43 +00:00
p - > vehForwardScale = min ( ( buttonMap . ButtonDown ( gamefunc_Move_Forward ) | | buttonMap . ButtonDown ( gamefunc_Strafe ) ) + hidInput - > dz , 1.f ) ;
p - > vehReverseScale = min ( buttonMap . ButtonDown ( gamefunc_Move_Backward ) + - hidInput - > dz , 1.f ) ;
2021-01-03 08:25:49 +00:00
p - > vehBraking = buttonMap . ButtonDown ( gamefunc_Run ) ;
2020-07-17 20:09:01 +00:00
}
2020-07-17 18:56:10 +00:00
2020-07-17 20:09:01 +00:00
if ( p - > OnMotorcycle )
{
2021-05-12 15:57:36 +00:00
input . avel = ( float ) motoApplyTurn ( p , hidInput , kbdLeft , kbdRight , scaleAdjust ) ;
2020-07-17 20:09:01 +00:00
if ( p - > moto_underwater ) p - > MotoSpeed = 0 ;
}
else
{
2021-05-12 15:57:36 +00:00
input . avel = ( float ) boatApplyTurn ( p , hidInput , kbdLeft , kbdRight , scaleAdjust ) ;
2020-07-17 20:09:01 +00:00
}
2020-07-17 18:56:10 +00:00
2021-12-06 06:21:41 +00:00
loc . fvel = clamp < int16_t > ( xs_CRoundToInt ( p - > MotoSpeed ) , - ( MAXVELMOTO > > 3 ) , MAXVELMOTO ) ;
2021-03-31 23:42:22 +00:00
input . avel * = BAngToDegree ;
2020-11-06 05:34:46 +00:00
loc . avel + = input . avel ;
2020-07-17 18:56:10 +00:00
}
2020-07-18 07:59:16 +00:00
//---------------------------------------------------------------------------
//
// finalizes the input and passes it to the global input buffer
//
//---------------------------------------------------------------------------
2021-04-15 08:58:57 +00:00
static void FinalizeInput ( player_struct * p , InputPacket & input )
2020-07-18 07:59:16 +00:00
{
2021-12-21 17:19:45 +00:00
if ( gamestate ! = GS_LEVEL | | movementBlocked ( p ) | | p - > GetActor ( ) - > spr . extra < = 0 | | ( p - > dead_flag & & ! ud . god & & ! p - > resurrected ) )
2020-07-18 07:59:16 +00:00
{
2021-08-30 06:06:26 +00:00
// neutralize all movement when not in a game, blocked or in automap follow mode
2020-08-29 19:09:04 +00:00
loc . fvel = loc . svel = 0 ;
2020-10-08 03:47:30 +00:00
loc . avel = loc . horz = 0 ;
input . avel = input . horz = 0 ;
2020-07-18 07:59:16 +00:00
}
else
{
2021-04-15 08:58:57 +00:00
if ( p - > on_crane ! = nullptr )
2020-08-05 21:25:04 +00:00
{
2020-08-29 19:09:04 +00:00
loc . fvel = input . fvel = 0 ;
loc . svel = input . svel = 0 ;
2020-08-05 21:25:04 +00:00
}
2020-07-18 07:59:16 +00:00
2021-01-03 09:14:40 +00:00
if ( p - > newOwner ! = nullptr | | p - > on_crane ! = nullptr )
2020-07-18 07:59:16 +00:00
{
2021-01-03 09:14:40 +00:00
loc . avel = input . avel = 0 ;
}
2020-07-18 07:59:16 +00:00
2021-01-03 09:14:40 +00:00
if ( p - > newOwner ! = nullptr | | ( p - > sync . actions & SB_CENTERVIEW & & abs ( p - > horizon . horiz . asbuild ( ) ) > 5 ) )
{
loc . horz = input . horz = 0 ;
2020-08-05 21:25:04 +00:00
}
2020-07-18 07:59:16 +00:00
}
}
2020-09-24 12:32:37 +00:00
2020-07-17 22:59:10 +00:00
//---------------------------------------------------------------------------
//
2020-09-24 12:32:37 +00:00
// External entry point
2020-07-17 22:59:10 +00:00
//
//---------------------------------------------------------------------------
2021-11-12 07:59:52 +00:00
void GameInterface : : GetInput ( ControlInfo * const hidInput , double const scaleAdjust , InputPacket * packet )
2020-07-17 22:59:10 +00:00
{
2021-08-30 06:06:26 +00:00
if ( paused | | gamestate ! = GS_LEVEL )
2020-07-17 22:59:10 +00:00
{
loc = { } ;
return ;
}
2020-09-24 12:32:37 +00:00
auto const p = & ps [ myconnectindex ] ;
2020-08-26 15:12:48 +00:00
InputPacket input { } ;
2020-07-17 22:59:10 +00:00
2021-01-01 10:33:00 +00:00
processInputBits ( p , hidInput ) ;
2021-11-12 07:59:52 +00:00
if ( isRRRA ( ) & & ( p - > OnMotorcycle | | p - > OnBoat ) )
2020-07-17 22:59:10 +00:00
{
2020-09-06 10:17:54 +00:00
processVehicleInput ( p , hidInput , input , scaleAdjust ) ;
2020-07-17 22:59:10 +00:00
}
else
{
2020-09-25 12:26:50 +00:00
processMovement ( & input , & loc , hidInput , scaleAdjust , p - > drink_amt ) ;
2020-08-05 07:53:22 +00:00
}
2020-07-17 22:59:10 +00:00
2021-04-15 08:58:57 +00:00
FinalizeInput ( p , input ) ;
2021-01-01 10:33:00 +00:00
2020-11-30 22:40:16 +00:00
if ( ! SyncInput ( ) )
2020-08-05 07:53:22 +00:00
{
2021-12-21 17:19:45 +00:00
if ( p - > GetActor ( ) - > spr . extra > 0 )
2020-09-21 05:51:33 +00:00
{
// Do these in the same order as the old code.
2021-01-01 13:30:01 +00:00
doslopetilting ( p , scaleAdjust ) ;
2021-04-21 10:41:04 +00:00
p - > angle . applyinput ( p - > adjustavel ( input . avel ) , & p - > sync . actions , scaleAdjust ) ;
2021-01-03 08:59:39 +00:00
p - > apply_seasick ( scaleAdjust ) ;
2021-04-21 10:41:04 +00:00
p - > horizon . applyinput ( input . horz , & p - > sync . actions , scaleAdjust ) ;
2020-09-21 05:51:33 +00:00
}
2020-10-07 12:13:21 +00:00
p - > angle . processhelpers ( scaleAdjust ) ;
2020-10-07 06:12:37 +00:00
p - > horizon . processhelpers ( scaleAdjust ) ;
2021-12-21 17:19:45 +00:00
p - > GetActor ( ) - > spr . ang = p - > angle . ang . asbuild ( ) ;
2020-07-17 22:59:10 +00:00
}
2020-07-17 20:09:01 +00:00
2020-08-29 19:20:10 +00:00
if ( packet )
{
* packet = loc ;
2021-12-22 09:26:51 +00:00
packet - > fvel = MulScale ( loc . fvel , p - > angle . ang . bcos ( ) , 9 ) + MulScale ( loc . svel , p - > angle . ang . bsin ( ) , 9 ) + p - > fric . X ;
2021-12-22 09:28:51 +00:00
packet - > svel = MulScale ( loc . fvel , p - > angle . ang . bsin ( ) , 9 ) - MulScale ( loc . svel , p - > angle . ang . bcos ( ) , 9 ) + p - > fric . Y ;
2020-08-29 19:20:10 +00:00
loc = { } ;
}
}
//---------------------------------------------------------------------------
//
2020-09-23 14:20:40 +00:00
// This is called from InputState::ClearAllInput and resets all static state being used here.
2020-08-29 19:20:10 +00:00
//
//---------------------------------------------------------------------------
2020-07-17 18:56:10 +00:00
void GameInterface : : clearlocalinputstate ( )
{
2020-08-29 19:20:10 +00:00
loc = { } ;
2020-07-17 18:56:10 +00:00
}
2020-08-29 19:20:10 +00:00
2020-05-17 11:25:39 +00:00
END_DUKE_NS