nuclide/Source/Shared/WeaponGlock18.c

167 lines
4.2 KiB
C
Raw Normal View History

2016-12-01 17:50:48 +00:00
/*
Copyright 2016-2018 Marco "eukara" Hladik
MIT LICENSE
2016-12-01 17:50:48 +00:00
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
2016-12-01 17:50:48 +00:00
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
2016-12-01 17:50:48 +00:00
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
2016-12-01 17:50:48 +00:00
*/
.int iMag_GLOCK18;
2016-12-01 17:50:48 +00:00
#ifdef SSQC
2016-12-01 17:50:48 +00:00
.int iMode_GLOCK18;
#else
int iWeaponMode_GLOCK18;
#endif
// Weapon Info
weaponinfo_t wptGLOCK18 = {
WEAPON_GLOCK18, // Identifier
SLOT_SECONDARY, // Slot
2016-12-01 17:50:48 +00:00
400, // Price
CALIBER_9MM, // Caliber ID
1.0, // Max Player Speed
2016-12-01 17:50:48 +00:00
1, // Bullets Per Shot
20, // Clip/MagSize
25, // Damage Per Bullet
1, // Penetration Multiplier
4096, // Bullet Range
0.75, // Range Modifier
TYPE_SEMI, // Firing Type
2016-12-01 17:50:48 +00:00
0.15, // Attack-Delay
2.1, // Reload-Delay
2016-12-01 17:50:48 +00:00
iAmmo_9MM, // Caliber Pointer
iMag_GLOCK18, // Clip Pointer
200, // Accuracy Divisor
0.55, // Accuracy Offset
1.4, // Max Inaccuracyy
8, // Minimum Crosshair Distance
3, // Crosshair Movement Delta
1.05, // Armor penetration ratio
ATYPE_ONEHAND, // Animation Type
SHELL_PISTOL
2016-12-01 17:50:48 +00:00
};
// Anim Table
enum {
ANIM_GLOCK_IDLE1,
ANIM_GLOCK_IDLE2,
ANIM_GLOCK_IDLE3,
ANIM_GLOCK_SHOOT_BURST1,
ANIM_GLOCK_SHOOT_BURST2,
ANIM_GLOCK_SHOOT,
ANIM_GLOCK_SHOOT_EMPTY,
ANIM_GLOCK_RELOAD1,
ANIM_GLOCK_DRAW1,
ANIM_GLOCK_UNUSED1,
ANIM_GLOCK_UNUSED2,
ANIM_GLOCK_DRAW2,
ANIM_GLOCK_RELOAD2
};
void WeaponGLOCK18_Draw( void ) {
#ifdef SSQC
BaseGun_Draw();
2016-12-01 17:50:48 +00:00
#else
2016-12-01 21:55:31 +00:00
if ( random() <= 0.5 ) {
View_PlayAnimation( ANIM_GLOCK_DRAW1 );
} else {
View_PlayAnimation( ANIM_GLOCK_DRAW2 );
}
2016-12-01 17:50:48 +00:00
#endif
}
void WeaponGLOCK18_PrimaryFire( void ) {
#ifdef SSQC
if ( self.iMode_GLOCK18 == FALSE ) {
if ( BaseGun_PrimaryFire() == TRUE ) {
2016-12-01 17:50:48 +00:00
sound( self, CHAN_WEAPON, "weapons/glock18-2.wav", 1, ATTN_NORM );
}
} else {
if ( self.iMag_GLOCK18 <= 0 ) {
return;
}
for ( int i = 0; i < 3; i++ ) {
if ( self.iMag_GLOCK18 ) {
BaseGun_ShotMultiplierHandle( 1 );
BaseGun_AccuracyCalc();
TraceAttack_FireBullets( 1, ( self.origin + self.view_ofs ) );
self.iMag_GLOCK18 -= 1;
}
}
self.fAttackFinished = time + 0.5;
sound( self, CHAN_WEAPON, "weapons/glock18-1.wav", 1, ATTN_NORM );
Client_SendEvent( self, EV_WEAPON_PRIMARYATTACK );
2016-12-01 17:50:48 +00:00
}
#else
if ( iWeaponMode_GLOCK18 == FALSE ) {
if ( getstatf( STAT_CURRENT_MAG ) == 0 ) {
2016-12-01 17:50:48 +00:00
View_PlayAnimation( ANIM_GLOCK_SHOOT_EMPTY );
} else {
View_PlayAnimation( ANIM_GLOCK_SHOOT );
}
BaseGun_ShotMultiplierHandle( 1 );
2016-12-01 17:50:48 +00:00
} else {
if ( random() <= 0.5 ) {
View_PlayAnimation( ANIM_GLOCK_SHOOT_BURST1 );
} else {
View_PlayAnimation( ANIM_GLOCK_SHOOT_BURST2 );
}
BaseGun_ShotMultiplierHandle( 3 );
2016-12-01 17:50:48 +00:00
}
#endif
}
void WeaponGLOCK18_Secondary( void ) {
#ifdef SSQC
2016-12-01 17:50:48 +00:00
// Just switch the modes quickly
self.iMode_GLOCK18 = 1 - self.iMode_GLOCK18;
self.fAttackFinished = time + 0.2;
2016-12-01 17:50:48 +00:00
// Tell the client that we switched modes, too
Client_SendEvent( self, EV_WEAPON_SECONDARYATTACK );
// TODO: Move to the clientside
2016-12-01 17:50:48 +00:00
if ( self.iMode_GLOCK18 == TRUE ) {
centerprint( self, "Switched to Burst-Fire mode" );
} else {
centerprint( self, "Switched to Semi-Automatic mode" );
}
#else
iWeaponMode_GLOCK18 = 1 - iWeaponMode_GLOCK18;
#endif
}
void WeaponGLOCK18_Reload( void ) {
#ifdef SSQC
if ( BaseGun_Reload() == TRUE ) {
2016-12-01 17:50:48 +00:00
// Play Sound
}
#else
if ( random() <= 0.5 ) {
2016-12-01 17:50:48 +00:00
View_PlayAnimation( ANIM_GLOCK_RELOAD1 );
} else {
View_PlayAnimation( ANIM_GLOCK_RELOAD2 );
}
#endif
}