diff --git a/Source/Client/Event.c b/Source/Client/Event.c index fb2f3c46..c100f7fb 100644 --- a/Source/Client/Event.c +++ b/Source/Client/Event.c @@ -28,7 +28,8 @@ Init all the cmds in one place void CSQC_ConsoleCommand_Init( void ) { registercommand( "buy" ); registercommand( "chooseteam" ); - registercommand( "testobt" ); + registercommand( "invnext" ); + registercommand( "invprev" ); registercommand( "+showscores" ); registercommand( "-showscores" ); } @@ -42,8 +43,7 @@ Can interject cmds and create new ones */ float CSQC_ConsoleCommand( string sCMD ) { tokenize( sCMD ); - switch ( argv(0) ) - { + switch ( argv(0) ) { case "buy": if( getstatf( STAT_BUYZONE ) == TRUE ) { fVGUI_Display = VGUI_BM_MAIN; @@ -54,6 +54,14 @@ float CSQC_ConsoleCommand( string sCMD ) { fVGUI_Display = VGUI_TEAMSELECT; return TRUE; break; + case "invnext": + HUD_DrawWeaponSelect_Back(); + return TRUE; + break; + case "invprev": + HUD_DrawWeaponSelect_Forward(); + return TRUE; + break; case "+showscores": iShowScores = TRUE; return TRUE; @@ -163,4 +171,9 @@ void CSQC_Input_Frame( void ) { input_buttons = 0; input_impulse = 0; } + + if ( ( fHUDWeaponSelected ) && ( input_buttons & INPUT_BUTTON0 ) ) { + HUD_DrawWeaponSelect_Trigger(); + input_buttons = 0; + } } diff --git a/Source/Client/HUD.c b/Source/Client/HUD.c index 71e17c1c..7b869a41 100644 --- a/Source/Client/HUD.c +++ b/Source/Client/HUD.c @@ -400,4 +400,5 @@ void HUD_Draw( void ) { HUD_DrawAmmo(); HUD_DrawOrbituaries(); HUD_DrawProgressBar(); + HUD_DrawWeaponSelect(); } diff --git a/Source/Client/HUDWeaponSelect.c b/Source/Client/HUDWeaponSelect.c new file mode 100644 index 00000000..ad5c3ff9 --- /dev/null +++ b/Source/Client/HUDWeaponSelect.c @@ -0,0 +1,255 @@ +/* +OpenCS Project +Copyright (C) 2015 Marco "eukara" Hladik + +This program 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 +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +typedef struct { + string sSprite; + vector vOrigin; +} weaponsymbolinfo_t; + +weaponsymbolinfo_t wpSymbolTable[ CS_WEAPON_COUNT ] = { + { "", '0 0' }, //WEAPON_NONE + { "sprites/640hud10.spr_0.tga", '0 0.52734375' }, //WEAPON_KNIFE + { "sprites/640hud1.spr_0.tga", '0 0.3515625' }, //WEAPON_USP45 + { "sprites/640hud1.spr_0.tga", '0 0.17578125' }, //WEAPON_GLOCK18 + { "sprites/640hud10.spr_0.tga", '0 0.3515625' }, //WEAPON_DEAGLE + { "sprites/640hud12.spr_0.tga", '0 0.3515625' }, //WEAPON_P228 + { "sprites/640hud14.spr_0.tga", '0 0.3515625' }, //WEAPON_ELITES + { "sprites/640hud14.spr_0.tga", '0 0.52734375' }, //WEAPON_FIVESEVEN + { "sprites/640hud1.spr_0.tga", '0 0.52734375' }, //WEAPON_M3 + { "sprites/640hud12.spr_0.tga", '0 0.52734375' }, //WEAPON_XM1014 + { "sprites/640hud1.spr_0.tga", '0 0.703125' }, //WEAPON_MP5 + { "sprites/640hud12.spr_0.tga", '0 0' }, //WEAPON_P90 + { "sprites/640hud16.spr_0.tga", '0 0' }, //WEAPON_UMP45 + { "sprites/640hud14.spr_0.tga", '0 0' }, //WEAPON_MAC10 + { "sprites/640hud12.spr_0.tga", '0 0' }, //WEAPON_TMP + { "sprites/640hud10.spr_0.tga", '0 0' }, //WEAPON_AK47 + { "sprites/640hud10.spr_0.tga", '0 0.17578125' }, //WEAPON_SG552 + { "sprites/640hud2.spr_0.tga", '0 0.17578125' }, //WEAPON_M4A1 + { "sprites/640hud14.spr_0.tga", '0 0.17578125' }, //WEAPON_AUG + { "sprites/640hud12.spr_0.tga", '0 0.17578125' }, //WEAPON_SCOUT + { "sprites/640hud2.spr_0.tga", '0 0.52734375' }, //WEAPON_AWP + { "sprites/640hud2.spr_0.tga", '0 0.703125' }, //WEAPON_G3SG1 + { "sprites/640hud14.spr_0.tga", '0 0.703125' }, //WEAPON_SG550 + { "sprites/640hud3.spr_0.tga", '0 0' }, //WEAPON_PARA + { "sprites/640hud3.spr_1.tga", '0 0' } //WEAPON_C4BOMB +}; + +vector vHUDSlotNumPos[ 4 ] = { + '0.65625 0.28125 0', // 1 PRIMARY + '0.734375 0.28125 0', // 2 SECONDARY + '0.8125 0.28125 0', // 3 MELEE + '0.65625 0.359375 0', // 4 GRENADE +}; + +float fHUDWeaponSelectTime; +float fHUDWeaponSelected; + +/* +================= +HUD_DrawWeaponSelect_NextItem + +Checks and returns the next slot with a weapon in it +================= +*/ +float HUD_DrawWeaponSelect_NextItem( float fSlot ) { + if ( fSlot == SLOT_PRIMARY ) { + if ( getstatf( STAT_SLOT_SECONDARY ) ) { + return SLOT_SECONDARY; + } else { + return HUD_DrawWeaponSelect_NextItem( SLOT_SECONDARY ); + } + } else if ( fSlot == SLOT_SECONDARY ) { + if ( getstatf( STAT_SLOT_MELEE ) ) { + return SLOT_MELEE; + } else { + return HUD_DrawWeaponSelect_NextItem( SLOT_MELEE ); + } + } else if ( fSlot == SLOT_MELEE ) { + if ( getstatf( STAT_SLOT_GRENADE ) ) { + return SLOT_GRENADE; + } else { + return HUD_DrawWeaponSelect_NextItem( SLOT_GRENADE ); + } + } else { + if ( getstatf( STAT_SLOT_PRIMARY ) ) { + return SLOT_PRIMARY; + } else { + return HUD_DrawWeaponSelect_NextItem( SLOT_PRIMARY ); + } + } +} + +/* +================= +HUD_DrawWeaponSelect_PreviousItem + +Checks and returns the previous slot with a weapon in it +================= +*/ +float HUD_DrawWeaponSelect_PreviousItem( float fSlot ) { + if ( fSlot == SLOT_PRIMARY ) { + if ( getstatf( STAT_SLOT_GRENADE ) ) { + return SLOT_GRENADE; + } else { + return HUD_DrawWeaponSelect_PreviousItem( SLOT_GRENADE ); + } + } else if ( fSlot == SLOT_SECONDARY ) { + if ( getstatf( STAT_SLOT_PRIMARY ) ) { + return SLOT_PRIMARY; + } else { + return HUD_DrawWeaponSelect_PreviousItem( SLOT_PRIMARY ); + } + } else if ( fSlot == SLOT_MELEE ) { + if ( getstatf( STAT_SLOT_SECONDARY ) ) { + return SLOT_SECONDARY; + } else { + return HUD_DrawWeaponSelect_PreviousItem( SLOT_SECONDARY ); + } + } else { + if ( getstatf( STAT_SLOT_MELEE ) ) { + return SLOT_MELEE; + } else { + return HUD_DrawWeaponSelect_PreviousItem( SLOT_MELEE ); + } + } +} + +/* +================= +HUD_DrawWeaponSelect_GetWeapon + +Returns what weapon is in which slot +================= +*/ +float HUD_DrawWeaponSelect_GetWeapon( float fSlot ) { + if ( fSlot == SLOT_PRIMARY ) { + return getstatf( STAT_SLOT_PRIMARY ); + } else if ( fSlot == SLOT_SECONDARY ) { + return getstatf( STAT_SLOT_SECONDARY ); + } else if ( fSlot == SLOT_MELEE ) { + return getstatf( STAT_SLOT_MELEE ); + } else { + return getstatf( STAT_SLOT_GRENADE ); + } +} + +/* +================= +HUD_DrawWeaponSelect_Forward + +Called via the invprev command +================= +*/ +void HUD_DrawWeaponSelect_Forward( void ) { + if ( !getstatf( STAT_SLOT_MELEE ) && !getstatf( STAT_SLOT_MELEE ) && !getstatf( STAT_SLOT_MELEE ) && !getstatf( STAT_SLOT_MELEE ) ) { + return; + } + + if ( fHUDWeaponSelected == 0 ) { + sound( self, CHAN_ITEM, "common/wpn_hudon.wav", 0.5, ATTN_NONE ); + fHUDWeaponSelected = HUD_DrawWeaponSelect_GetWeapon( HUD_DrawWeaponSelect_NextItem( wptTable[ getstatf( STAT_ACTIVEWEAPON ) ].iSlot ) ); + } else { + sound( self, CHAN_ITEM, "common/wpn_moveselect.wav", 0.5, ATTN_NONE ); + fHUDWeaponSelected = HUD_DrawWeaponSelect_GetWeapon( HUD_DrawWeaponSelect_NextItem( wptTable[ fHUDWeaponSelected ].iSlot ) ); + } + + print( sprintf( "Selected %f\n", fHUDWeaponSelected ) ); + fHUDWeaponSelectTime = time + 3; +} + +/* +================= +HUD_DrawWeaponSelect_Back + +Called via the invnext command +================= +*/ +void HUD_DrawWeaponSelect_Back( void ) { + if ( !getstatf( STAT_SLOT_MELEE ) && !getstatf( STAT_SLOT_MELEE ) && !getstatf( STAT_SLOT_MELEE ) && !getstatf( STAT_SLOT_MELEE ) ) { + return; + } + + if ( fHUDWeaponSelected == 0 ) { + sound( self, CHAN_ITEM, "common/wpn_hudon.wav", 0.5, ATTN_NONE ); + fHUDWeaponSelected = HUD_DrawWeaponSelect_GetWeapon( HUD_DrawWeaponSelect_PreviousItem( wptTable[ getstatf( STAT_ACTIVEWEAPON ) ].iSlot ) ); + } else { + sound( self, CHAN_ITEM, "common/wpn_moveselect.wav", 0.5, ATTN_NONE ); + fHUDWeaponSelected = HUD_DrawWeaponSelect_GetWeapon( HUD_DrawWeaponSelect_PreviousItem( wptTable[ fHUDWeaponSelected ].iSlot ) ); + } + + fHUDWeaponSelectTime = time + 3; +} + +/* +================= +HUD_DrawWeaponSelect_Num + +Draws the numbers 1-4 on the selection display +================= +*/ +void HUD_DrawWeaponSelect_Num( vector vPos, float fValue ) { + drawsubpic( vPos, '20 20', "sprites/640hud7.spr_0.tga", vHUDSlotNumPos[ fValue ], [ 0.078125, 0.078125 ], VGUI_WINDOW_FGCOLOR, 1, DRAWFLAG_ADDITIVE ); +} + +/* +================= +HUD_DrawWeaponSelect + +Drawn every frame through HUD.c +================= +*/ +void HUD_DrawWeaponSelect( void ) { + if ( fHUDWeaponSelectTime < time ) { + if ( fHUDWeaponSelected ) { + sound( self, CHAN_ITEM, "common/wpn_hudoff.wav", 0.5, ATTN_NONE ); + fHUDWeaponSelected = 0; + } + return; + } + + vector vSelectPos = '138 12 0'; + + for ( int i = 0; i < 4; i++ ) { + HUD_DrawWeaponSelect_Num( vSelectPos, i ); + + if ( wptTable[ fHUDWeaponSelected ].iSlot == i ) { + drawsubpic( vSelectPos + '0 20', '170 45', wpSymbolTable[ fHUDWeaponSelected ].sSprite, wpSymbolTable[ fHUDWeaponSelected ].vOrigin, [ 0.6640625, 0.17578125 ], VGUI_WINDOW_FGCOLOR, 1, DRAWFLAG_ADDITIVE ); + vSelectPos_x += 170; + } else { + vSelectPos_x += 20; + } + } +} + +/* +================= +HUD_DrawWeaponSelect + +Called by CSQC_Input_Frame when conditions are met +================= +*/ +void HUD_DrawWeaponSelect_Trigger( void ) { + if ( fHUDWeaponSelected != getstatf( STAT_ACTIVEWEAPON ) ) { + sendevent( "PlayerSwitchWeapon", "f", fHUDWeaponSelected ); + } + sound( self, CHAN_ITEM, "common/wpn_select.wav", 0.5, ATTN_NONE ); + fHUDWeaponSelectTime = 0; + fHUDWeaponSelected = 0; +} diff --git a/Source/Client/Init.c b/Source/Client/Init.c index 753e74ce..70eda46e 100644 --- a/Source/Client/Init.c +++ b/Source/Client/Init.c @@ -30,6 +30,17 @@ void CSQC_Init(float apilevel, string enginename, float engineversion) { precache_model( "sprites/640hud1.spr" ); precache_model( "sprites/640hud16.spr" ); + precache_model( "sprites/640hud2.spr" ); + precache_model( "sprites/640hud10.spr" ); + precache_model( "sprites/640hud12.spr" ); + precache_model( "sprites/640hud14.spr" ); + precache_model( "sprites/640hud3.spr" ); + + precache_sound( "common/wpn_hudon.wav" ); + precache_sound( "common/wpn_hudoff.wav" ); + precache_sound( "common/wpn_moveselect.wav" ); + precache_sound( "common/wpn_select.wav" ); + for( int i = 0; i < CS_WEAPON_COUNT; i++ ) { precache_model( sViewModels[ i ] ); } diff --git a/Source/Client/progs.src b/Source/Client/progs.src index 67dbf6e8..605db5b0 100644 --- a/Source/Client/progs.src +++ b/Source/Client/progs.src @@ -48,6 +48,7 @@ VGUIMOTD.c VGUIBuyMenu.c VGUITeamSelect.c VGUI.c +HUDWeaponSelect.c HUDOrbituaries.c HUD.c Draw.c diff --git a/Source/Globals.h b/Source/Globals.h index 19c005a5..9713dec2 100644 --- a/Source/Globals.h +++ b/Source/Globals.h @@ -127,9 +127,9 @@ enum { // Slot types enum { - SLOT_MELEE, - SLOT_SECONDARY, SLOT_PRIMARY, + SLOT_SECONDARY, + SLOT_MELEE, SLOT_GRENADE }; @@ -206,6 +206,14 @@ enum { MATERIAL_NONE }; +// Actually used by input_button etc. +#define INPUT_BUTTON0 1 +#define INPUT_BUTTON2 2 +#define INPUT_BUTTON3 4 +#define INPUT_BUTTON4 8 +#define INPUT_BUTTON5 16 +#define INPUT_BUTTON6 32 + float clamp(float d, float imin, float imax) { float t; @@ -219,3 +227,5 @@ float clamp(float d, float imin, float imax) { else return t; } + +void Empty( void ) { } diff --git a/Source/Server/Ammo.c b/Source/Server/Ammo.c index 2889c0c9..008ae2f0 100644 --- a/Source/Server/Ammo.c +++ b/Source/Server/Ammo.c @@ -33,42 +33,43 @@ ammoinfo_t ammoTable[11] = { }; void Ammo_BuyPrimary( void ) { - if ( !self.iSlotPrimary ) { + if ( !self.fSlotPrimary ) { return; } - int iRequiredAmmo = ( ammoTable[ wptTable[ self.iSlotPrimary ].iCaliber ].iMaxAmount - self.(wptTable[ self.iSlotPrimary ].iCaliberfld)); - float fNew = ceil( ( (float)iRequiredAmmo / (float)ammoTable[ wptTable[ self.iSlotPrimary ].iCaliber ].iSize ) ); + int iRequiredAmmo = ( ammoTable[ wptTable[ self.fSlotPrimary ].iCaliber ].iMaxAmount - self.(wptTable[ self.fSlotPrimary ].iCaliberfld)); + float fNew = ceil( ( (float)iRequiredAmmo / (float)ammoTable[ wptTable[ self.fSlotPrimary ].iCaliber ].iSize ) ); for ( int i = 0; i < fNew; i++ ) { - self.(wptTable[ self.iSlotPrimary ].iCaliberfld) += ammoTable[ wptTable[ self.iSlotPrimary ].iCaliber ].iSize; - Money_AddMoney( self, -ammoTable[ wptTable[ self.iSlotPrimary ].iCaliber ].iPrice ); + self.(wptTable[ self.fSlotPrimary ].iCaliberfld) += ammoTable[ wptTable[ self.fSlotPrimary ].iCaliber ].iSize; + Money_AddMoney( self, -ammoTable[ wptTable[ self.fSlotPrimary ].iCaliber ].iPrice ); + sound( self, CHAN_ITEM, "items/9mmclip1.wav", 1, ATTN_IDLE ); - if ( self.(wptTable[ self.iSlotPrimary ].iCaliberfld) > ammoTable[ wptTable[ self.iSlotPrimary ].iCaliber ].iMaxAmount ) { - self.(wptTable[ self.iSlotPrimary ].iCaliberfld) = ammoTable[ wptTable[ self.iSlotPrimary ].iCaliber ].iMaxAmount; + if ( self.(wptTable[ self.fSlotPrimary ].iCaliberfld) > ammoTable[ wptTable[ self.fSlotPrimary ].iCaliber ].iMaxAmount ) { + self.(wptTable[ self.fSlotPrimary ].iCaliberfld) = ammoTable[ wptTable[ self.fSlotPrimary ].iCaliber ].iMaxAmount; } } } void Ammo_BuySecondary( void ) { - if ( !self.iSlotSecondary ) { + if ( !self.fSlotSecondary ) { return; } - int iRequiredAmmo = ( ammoTable[ wptTable[ self.iSlotSecondary ].iCaliber ].iMaxAmount - self.(wptTable[ self.iSlotSecondary ].iCaliberfld)); - float fNew = ceil( ( (float)iRequiredAmmo / (float)ammoTable[ wptTable[ self.iSlotSecondary ].iCaliber ].iSize ) ); + int iRequiredAmmo = ( ammoTable[ wptTable[ self.fSlotSecondary ].iCaliber ].iMaxAmount - self.(wptTable[ self.fSlotSecondary ].iCaliberfld)); + float fNew = ceil( ( (float)iRequiredAmmo / (float)ammoTable[ wptTable[ self.fSlotSecondary ].iCaliber ].iSize ) ); for ( int i = 0; i < fNew; i++ ) { - if ( self.fMoney - ammoTable[ wptTable[ self.iSlotSecondary ].iCaliber ].iPrice < 0 ) { + if ( self.fMoney - ammoTable[ wptTable[ self.fSlotSecondary ].iCaliber ].iPrice < 0 ) { break; } - self.(wptTable[ self.iSlotSecondary ].iCaliberfld) += ammoTable[ wptTable[ self.iSlotSecondary ].iCaliber ].iSize; - Money_AddMoney( self, -ammoTable[ wptTable[ self.iSlotSecondary ].iCaliber ].iPrice ); + self.(wptTable[ self.fSlotSecondary ].iCaliberfld) += ammoTable[ wptTable[ self.fSlotSecondary ].iCaliber ].iSize; + Money_AddMoney( self, -ammoTable[ wptTable[ self.fSlotSecondary ].iCaliber ].iPrice ); sound( self, CHAN_ITEM, "items/9mmclip1.wav", 1, ATTN_IDLE ); - if ( self.(wptTable[ self.iSlotSecondary ].iCaliberfld) > ammoTable[ wptTable[ self.iSlotSecondary ].iCaliber ].iMaxAmount ) { - self.(wptTable[ self.iSlotSecondary ].iCaliberfld) = ammoTable[ wptTable[ self.iSlotSecondary ].iCaliber ].iMaxAmount; + if ( self.(wptTable[ self.fSlotSecondary ].iCaliberfld) > ammoTable[ wptTable[ self.fSlotSecondary ].iCaliber ].iMaxAmount ) { + self.(wptTable[ self.fSlotSecondary ].iCaliberfld) = ammoTable[ wptTable[ self.fSlotSecondary ].iCaliber ].iMaxAmount; } } } diff --git a/Source/Server/Defs.h b/Source/Server/Defs.h index d92ca39e..cd5a8dd0 100644 --- a/Source/Server/Defs.h +++ b/Source/Server/Defs.h @@ -61,7 +61,7 @@ float fGameTime; // Weapon specific fields .int iCurrentClip; .int iCurrentCaliber; -.int iSlotMelee, iSlotPrimary, iSlotSecondary, iSlotGrenade; +.float fSlotMelee, fSlotPrimary, fSlotSecondary, fSlotGrenade; .float fAttackFinished; .float fAccuracy; @@ -116,6 +116,7 @@ void Spawn_MakeSpectator( void ); void Client_SendEvent( entity eClient, float fEVType ); void Client_TriggerCamera( entity eTarget, vector vPos, vector vEndPos, float fResetTime ); void Weapon_SwitchBest( void ); +void Weapon_UpdateCurrents( void ); void OpenCSGunBase_AccuracyCalc( void ); void OpenCSGunBase_Draw( void ); diff --git a/Source/Server/Input.c b/Source/Server/Input.c index 4429df94..c41c6e6f 100644 --- a/Source/Server/Input.c +++ b/Source/Server/Input.c @@ -20,11 +20,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. void Input_Handle( void ) { // TODO: Make this fast switch only - if ( self.impulse == 1 ) { + if ( self.impulse == 3 ) { Weapon_Switch( SLOT_MELEE ); } else if ( self.impulse == 2 ) { Weapon_Switch( SLOT_SECONDARY ); - } else if ( self.impulse == 3 ) { + } else if ( self.impulse == 1 ) { Weapon_Switch( SLOT_PRIMARY ); } else if ( self.impulse == 4 ) { Weapon_Switch( SLOT_GRENADE ); diff --git a/Source/Server/Main.c b/Source/Server/Main.c index a659c979..832298e7 100644 --- a/Source/Server/Main.c +++ b/Source/Server/Main.c @@ -273,10 +273,10 @@ void worldspawn( void ) { clientstat( 4, EV_FLOAT, armor ); clientstat( STAT_MONEY, EV_FLOAT, fMoney ); - clientstat( STAT_SLOT_MELEE, EV_INTEGER, iSlotMelee ); - clientstat( STAT_SLOT_PRIMARY, EV_INTEGER, iSlotPrimary ); - clientstat( STAT_SLOT_SECONDARY, EV_INTEGER, iSlotSecondary ); - clientstat( STAT_SLOT_GRENADE, EV_INTEGER, iSlotGrenade ); + clientstat( STAT_SLOT_MELEE, EV_FLOAT, fSlotMelee ); + clientstat( STAT_SLOT_PRIMARY, EV_FLOAT, fSlotPrimary ); + clientstat( STAT_SLOT_SECONDARY, EV_FLOAT, fSlotSecondary ); + clientstat( STAT_SLOT_GRENADE, EV_FLOAT, fSlotGrenade ); clientstat( STAT_CURRENT_CLIP, EV_INTEGER, iCurrentClip ); clientstat( STAT_CURRENT_CALIBER, EV_INTEGER, iCurrentCaliber ); clientstat( STAT_TEAM, EV_INTEGER, team ); diff --git a/Source/Server/Spawn.c b/Source/Server/Spawn.c index a7d9c09e..409ab1f8 100644 --- a/Source/Server/Spawn.c +++ b/Source/Server/Spawn.c @@ -171,7 +171,7 @@ void Spawn_MakeSpectator( void ) { } // Clear the inventory - self.iSlotMelee = self.iSlotPrimary = self.iSlotSecondary = self.iSlotGrenade = 0; + self.fSlotMelee = self.fSlotPrimary = self.fSlotSecondary = self.fSlotGrenade = 0; } // Event Handling, called by the Client codebase via 'sendevent' diff --git a/Source/Shared/WeaponBase.c b/Source/Shared/WeaponBase.c index 255ef3f0..e46bd548 100644 --- a/Source/Shared/WeaponBase.c +++ b/Source/Shared/WeaponBase.c @@ -79,6 +79,19 @@ float OpenCSGunBase_PrimaryFire( void ) { } float OpenCSGunBase_Reload( void ) { + static void OpenCSGunBase_FinishReload( void ) { + // What if we've got less in our caliberfield than we need + if ( self.(wptTable[ self.weapon ].iCaliberfld) < wptTable[ self.weapon ].iClipSize ) { + self.(wptTable[ self.weapon ].iClipfld) = self.(wptTable[ self.weapon ].iCaliberfld); + self.(wptTable[ self.weapon ].iCaliberfld) = 0; + } else { + self.(wptTable[ self.weapon ].iCaliberfld) -= ( wptTable[ self.weapon ].iClipSize - self.(wptTable[ self.weapon ].iClipfld) ); + self.(wptTable[ self.weapon ].iClipfld) = wptTable[ self.weapon ].iClipSize; + } + + Weapon_UpdateCurrents(); + } + // Don't bother reloading the gun when full if ( self.(wptTable[ self.weapon ].iClipfld) == wptTable[ self.weapon ].iClipSize ) { return FALSE; @@ -89,16 +102,10 @@ float OpenCSGunBase_Reload( void ) { return FALSE; } - // What if we've got less in our caliberfield than we need - if ( self.(wptTable[ self.weapon ].iCaliberfld) < wptTable[ self.weapon ].iClipSize ) { - self.(wptTable[ self.weapon ].iClipfld) = self.(wptTable[ self.weapon ].iCaliberfld); - self.(wptTable[ self.weapon ].iCaliberfld) = 0; - } else { - self.(wptTable[ self.weapon ].iCaliberfld) -= ( wptTable[ self.weapon ].iClipSize - self.(wptTable[ self.weapon ].iClipfld) ); - self.(wptTable[ self.weapon ].iClipfld) = wptTable[ self.weapon ].iClipSize; - } - self.fAttackFinished = time + wptTable[ self.weapon ].fReloadFinished; + self.think = OpenCSGunBase_FinishReload; + self.nextthink = time + wptTable[ self.weapon ].fReloadFinished; + self.fAttackFinished = self.nextthink; Client_SendEvent( self, EV_WEAPON_RELOAD ); return TRUE; diff --git a/Source/Shared/WeaponC4Bomb.c b/Source/Shared/WeaponC4Bomb.c index 932ef5ee..3b6c9023 100644 --- a/Source/Shared/WeaponC4Bomb.c +++ b/Source/Shared/WeaponC4Bomb.c @@ -150,7 +150,7 @@ void WeaponC4BOMB_Drop( vector vBombPos ) { iBombPlanted = TRUE; // Tell the bomb-planter to get rid of the weapon! - self.iSlotGrenade = self.iSlotGrenade - WEAPON_C4BOMB; + self.fSlotGrenade = self.fSlotGrenade - WEAPON_C4BOMB; Weapon_SwitchBest(); } #endif diff --git a/Source/Shared/Weapons.c b/Source/Shared/Weapons.c index 6ee3821d..ce92aa23 100644 --- a/Source/Shared/Weapons.c +++ b/Source/Shared/Weapons.c @@ -58,6 +58,9 @@ void Weapon_Draw( float fWeapon ) { return; } + // In case reloading logic is still going on + self.think = Empty; + wpnFuncTable[ fWeapon ].vDraw(); #ifdef SSQC @@ -97,7 +100,6 @@ void Weapon_Reload( float fWeapon ) { } #ifdef SSQC - void Weapon_Switch( int iSlot ) { if ( self.fAttackFinished > time ) { return; @@ -106,13 +108,13 @@ void Weapon_Switch( int iSlot ) { float fWeapon; if ( iSlot == SLOT_MELEE ) { - fWeapon = self.iSlotMelee; + fWeapon = self.fSlotMelee; } else if ( iSlot == SLOT_PRIMARY ) { - fWeapon = self.iSlotPrimary; + fWeapon = self.fSlotPrimary; } else if ( iSlot == SLOT_SECONDARY ) { - fWeapon = self.iSlotSecondary; + fWeapon = self.fSlotSecondary; } else if ( iSlot == SLOT_GRENADE ) { - fWeapon = self.iSlotGrenade; + fWeapon = self.fSlotGrenade; } if ( !fWeapon || self.weapon == fWeapon ) { @@ -134,13 +136,13 @@ void Weapon_AddItem( float fWeapon ) { // Add the gun to the appropriate slot if( wptTable[ fWeapon ].iSlot == SLOT_MELEE ) { - self.iSlotMelee = fWeapon; + self.fSlotMelee = fWeapon; } else if ( wptTable[ fWeapon ].iSlot == SLOT_SECONDARY ) { - self.iSlotSecondary = fWeapon; + self.fSlotSecondary = fWeapon; } else if( wptTable[ fWeapon ].iSlot == SLOT_PRIMARY ) { - self.iSlotPrimary = fWeapon; + self.fSlotPrimary = fWeapon; } else if ( wptTable[ fWeapon ].iSlot == SLOT_GRENADE ) { - self.iSlotGrenade = fWeapon; + self.fSlotGrenade = fWeapon; } // Switch to it @@ -156,9 +158,9 @@ void Weapon_GiveAmmo( float fWeapon, float fAmount ) { } void Weapon_SwitchBest( void ) { - if ( self.iSlotSecondary ) { + if ( self.fSlotSecondary ) { Weapon_Switch( SLOT_SECONDARY ); - } else if ( self.iSlotPrimary ) { + } else if ( self.fSlotPrimary ) { Weapon_Switch( SLOT_PRIMARY ); } else { Weapon_Switch( SLOT_MELEE ); @@ -178,4 +180,11 @@ void CSEv_PlayerBuyWeapon_f( float fWeapon ) { } self.fAttackFinished = time + 1.0; } + +void CSEv_PlayerSwitchWeapon_f( float fWeapon ) { + self.weapon = fWeapon; + Weapon_Draw( fWeapon ); + + self.fAttackFinished = time + 1.0; +} #endif