0
0
Fork 0
mirror of https://github.com/id-Software/DOOM-3-BFG.git synced 2025-03-15 23:21:35 +00:00
doom3-bfg/base/script/weapon_pistol.script
2022-08-27 13:19:00 +02:00

124 lines
2.9 KiB
Text

/***********************************************************************
weapon_pistol.script
***********************************************************************/
#define PISTOL_FIRERATE 0.4
#define PISTOL_LOWAMMO 4
#define PISTOL_NUMPROJECTILES 1
// blend times
#define PISTOL_IDLE_TO_LOWER 2
#define PISTOL_IDLE_TO_FIRE 1
#define PISTOL_IDLE_TO_RELOAD 3
#define PISTOL_RAISE_TO_IDLE 3
#define PISTOL_FIRE_TO_IDLE 4
#define PISTOL_RELOAD_TO_IDLE 4
object weapon_pistol : weapon_base {
float next_attack;
float spread;
void init();
void Lower();
void Raise();
void Idle();
void Fire();
void Reload();
void ExitCinematic();
};
void weapon_pistol::init() {
next_attack = 0;
spread = getFloatKey( "spread" );
weaponState( "Raise", 0 );
}
void weapon_pistol::Raise() {
weaponRising();
playAnim( ANIMCHANNEL_ALL, "raise" );
waitUntil( animDone( ANIMCHANNEL_ALL, PISTOL_RAISE_TO_IDLE ) );
weaponState( "Idle", PISTOL_RAISE_TO_IDLE );
}
void weapon_pistol::Lower() {
weaponLowering();
playAnim( ANIMCHANNEL_ALL, "putaway" );
waitUntil( animDone( ANIMCHANNEL_ALL, 0 ) );
weaponHolstered();
waitUntil( WEAPON_RAISEWEAPON );
weaponState( "Raise", 0 );
}
void weapon_pistol::Idle() {
float currentTime;
float ammoClip;
float avail;
float clip_size;
clip_size = clipSize();
weaponReady();
if ( !ammoInClip() ) {
playCycle( ANIMCHANNEL_ALL, "idle_empty" );
} else {
playCycle( ANIMCHANNEL_ALL, "idle" );
}
while( 1 ) {
if ( WEAPON_LOWERWEAPON ) {
weaponState( "Lower", PISTOL_IDLE_TO_LOWER );
}
currentTime = sys.getTime();
ammoClip = ammoInClip();
if ( ( currentTime >= next_attack ) && WEAPON_ATTACK ) {
if ( ammoClip > 0 ) {
weaponState( "Fire", PISTOL_IDLE_TO_FIRE );
} else if ( ammoAvailable() > 0 ) {
if ( autoReload() ) {
netReload();
weaponState( "Reload", PISTOL_IDLE_TO_RELOAD );
}
}
}
if ( WEAPON_RELOAD && ( ammoAvailable() > ammoClip ) && ( ammoClip < clip_size ) ) {
netReload();
weaponState( "Reload", PISTOL_IDLE_TO_RELOAD );
}
if ( WEAPON_NETRELOAD ) {
WEAPON_NETRELOAD = false;
weaponState( "Reload", PISTOL_IDLE_TO_RELOAD );
}
waitFrame();
}
}
void weapon_pistol::Fire() {
float ammoClip;
next_attack = sys.getTime() + PISTOL_FIRERATE;
ammoClip = ammoInClip();
if ( ammoClip == PISTOL_LOWAMMO ) {
startSound( "snd_lowammo", SND_CHANNEL_ITEM, true );
}
launchProjectiles( PISTOL_NUMPROJECTILES, spread, 0, 1.0, 1.0 );
playAnim( ANIMCHANNEL_ALL, "fire" );
waitUntil( animDone( ANIMCHANNEL_ALL, PISTOL_FIRE_TO_IDLE ) );
weaponState( "Idle", PISTOL_FIRE_TO_IDLE );
}
void weapon_pistol::Reload() {
weaponReloading();
playAnim( ANIMCHANNEL_ALL, "reload" );
waitUntil( animDone( ANIMCHANNEL_ALL, PISTOL_RELOAD_TO_IDLE ) );
addToClip( clipSize() );
weaponState( "Idle", PISTOL_RELOAD_TO_IDLE );
}
void weapon_pistol::ExitCinematic() {
next_attack = 0;
weaponState( "Idle", 0 );
}