00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "weapon.h"
00021 #include "player.h"
00022
00029 Weapon::Weapon(Player *p) :
00030 pawn(p), canFireStanding(false), canFireInAir(false), canFireCrouching(false), canMoveWhileFiring(false),
00031 ammo(-1), bHeldFire(false), fireAnimSpeed(spriteObject::TICKSPERFRAME), bFiring(false), bWasFiring(false)
00032 {
00033 #ifdef __MDDEBUG
00034 className = "weapon";
00035 macros::debugMessage(className, "constructor");
00036 #endif
00037 }
00038
00039 Weapon::~Weapon()
00040 {
00041 #ifdef __MDDEBUG
00042 macros::debugMessage(className, "destructor");
00043 #endif
00044 stopFiring();
00045 pawn->weaponDestroyed();
00046 }
00047
00054 bool Weapon::fire()
00055 {
00056 if (pawn->isOnRope())
00057 return false;
00058
00059 if (pawn->isOnGround() && pawn->isCrouched())
00060 bFiring = canFireCrouching;
00061 else if (pawn->isOnGround())
00062 bFiring = canFireStanding;
00063 else
00064 bFiring = canFireInAir;
00065
00066 if (bFiring && !bHeldFire)
00067 {
00068 weaponFireAction();
00069 if (bFiring)
00070 handleMovementAndAmmo();
00071 }
00072
00073 return bFiring;
00074 }
00075
00079 void Weapon::stopFiring()
00080 {
00081 #ifdef __MDDEBUG
00082 macros::debugMessage(className, "stopFiring");
00083 #endif
00084 bFiring = false;
00085 }
00086
00090 void Weapon::weaponTick()
00091 {
00092 if (bHeldFire && bFiring)
00093 {
00094 weaponFireAction();
00095 handleMovementAndAmmo();
00096 }
00097 bWasFiring = bFiring;
00098 }
00099
00104 void Weapon::handleMovementAndAmmo()
00105 {
00106 if (!canMoveWhileFiring)
00107 pawn->setvx(0);
00108
00109 if (firingAnim.size() > 0 && !bHeldFire)
00110 {
00111 pawn->setArbitraryAnim(firingAnim, false, fireAnimSpeed);
00112 pawn->setInputInterrupt(fireAnimSpeed * firingAnim.size());
00113 }
00114
00115 if (ammo != -1)
00116 ammo--;
00117 if (ammo == 0)
00118 delete this;
00119 }