/* $Id: weapon.cpp,v 1.14 2005/10/20 19:46:52 chfreund Exp $ */ #include "weapon.hpp" #include "audio.hpp" #include "avatar.hpp" #include "avatar.hpp" #include "weaponshotgun.hpp" #include "weaponuzi.hpp" #include "weaponrubgun.hpp" #include "weapongrenade.hpp" #include "weaponmine.hpp" #include "weaponmissile.hpp" #include "weaponhomingmissile.hpp" #include "weaponguidedmissile.hpp" #include "weaponhelicopter.hpp" #include "weaponzapper.hpp" #include "weaponhook.hpp" #include "weaponhookrel.hpp" #include "weaponhookcut.hpp" /**********************************************************/ Weapon::Weapon() : m_ID(INVALID_WEAPON), m_maximumAmmo(0), m_reloadTime(0), m_chargeTime(0), m_chargeTimer(0), m_reloadTimer(0), m_flags(NO_FLAG), m_ammo(0), m_shotSample(0x0) {} /**********************************************************/ void Weapon::shoot( World* world, Avatar* avatar, const StationaryGun* gun ) { // if shooting is locked, do nothing if( shotIsLocked() ) return; if ( m_ammo > 0 && m_reloadTimer.isElapsed() && reallyShoot( world, avatar, gun ) ) { // play shot sample Audio::getInstance()->playSound( m_shotSample, avatar->getPos() ); // decrease ammo m_ammo--; // if no ammo is left start recharging if ( m_ammo == 0 ) { m_chargeTimer = m_chargeTime; } else { // set reload timer m_reloadTimer.setTimeToLive( m_reloadTime ); } } } /**********************************************************/ Weapon* Weapon::newWeapon( const Sint32 ID ) { Weapon* weapon = 0x0; switch( ID ) { case WEAPON_SHOTGUN: weapon = NEW WeaponShotgun(); break; case WEAPON_UZI: weapon = NEW WeaponUzi(); break; case WEAPON_RUBBERGUN: weapon = NEW WeaponRubGun(); break; case WEAPON_GRENADE: weapon = NEW WeaponGrenade(); break; case WEAPON_MINE: weapon = NEW WeaponMine(); break; case WEAPON_MISSILE: weapon = NEW WeaponMissile(); break; case WEAPON_HOMING_MISSILE: weapon = NEW WeaponHomingMissile(); break; case WEAPON_GUIDED_MISSILE: weapon = NEW WeaponGuidedMissile(); break; case WEAPON_HELICOPTER: weapon = NEW WeaponHelicopter(); break; case WEAPON_ZAPPER: weapon = NEW WeaponZapper(); break; case WEAPON_HOOK: weapon = NEW WeaponHook(); break; case WEAPON_HOOK_REL: weapon = NEW WeaponHookRel(); break; case WEAPON_HOOK_CUT: weapon = NEW WeaponHookCut(); break; default: break; } DBG(2) { ASSERT( INVALID_WEAPON < ID && ID < NUMBER_OF_WEAPON_IDs, "Weapon::newWeapon: %d is not a valid weapon ID " "from range [0,%d]\n", ID, NUMBER_OF_WEAPON_IDs-1 ); ASSERT( weapon, "Weapon::newWeapon: could not create \"%s\" object\n", Weapon::getIDString(ID) ); } return weapon; } /**********************************************************/