00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <sstream>
00023 #include "../map/map.h"
00024 #include "../game/time.h"
00025 #include "../object/objects_list.h"
00026 #include "../team/teams_list.h"
00027 #include "../tool/i18n.h"
00028 #include "../interface/game_msg.h"
00029 #include "../network/randomsync.h"
00030 #include "explosion.h"
00031 #include "shotgun.h"
00032
00033 const uint SHOTGUN_BUCKSHOT_SPEED = 30;
00034 const uint SHOTGUN_EXPLOSION_RANGE = 1;
00035 const double SHOTGUN_RANDOM_ANGLE = 0.02;
00036 const double SHOTGUN_RANDOM_STRENGTH = 2.0;
00037 const int nb_bullets = 4;
00038
00039 ShotgunBuckshot::ShotgunBuckshot(ExplosiveWeaponConfig& cfg,
00040 WeaponLauncher * p_launcher) :
00041 WeaponBullet("buckshot", cfg, p_launcher)
00042 {
00043 cfg.explosion_range = SHOTGUN_EXPLOSION_RANGE;
00044 }
00045
00046 void ShotgunBuckshot::RandomizeShoot(double &angle,double &strength)
00047 {
00048 angle += M_PI * randomSync.GetDouble(-SHOTGUN_RANDOM_ANGLE,SHOTGUN_RANDOM_ANGLE);
00049 strength += randomSync.GetDouble(-SHOTGUN_RANDOM_STRENGTH,SHOTGUN_RANDOM_STRENGTH);
00050 }
00051
00052 bool ShotgunBuckshot::IsOverlapping(const PhysicalObj* obj) const
00053 {
00054 if(GetName() == obj->GetName()) return true;
00055 return m_overlapping_object == obj;
00056 }
00057
00058
00059
00060 Shotgun::Shotgun() : WeaponLauncher(WEAPON_SHOTGUN, "shotgun", new ExplosiveWeaponConfig())
00061 {
00062 m_name = _("Shotgun");
00063
00064 override_keys = true ;
00065 announce_missed_shots = false;
00066 m_weapon_fire = new Sprite(resource_manager.LoadImage(weapons_res_profile,m_id+"_fire"));
00067 m_weapon_fire->EnableRotationCache(32);
00068
00069 ReloadLauncher();
00070 }
00071
00072
00073 WeaponProjectile * Shotgun::GetProjectileInstance()
00074 {
00075 return dynamic_cast<WeaponProjectile *>
00076 (new ShotgunBuckshot(cfg(),dynamic_cast<WeaponLauncher *>(this)));
00077 }
00078
00079 void Shotgun::ShootSound()
00080 {
00081 jukebox.Play("share", "weapon/shotgun");
00082 }
00083
00084 void Shotgun::IncMissedShots()
00085 {
00086 if(missed_shots + 1 == nb_bullets)
00087 announce_missed_shots = true;
00088 WeaponLauncher::IncMissedShots();
00089 }
00090
00091 bool Shotgun::p_Shoot ()
00092 {
00093 missed_shots = 0;
00094 announce_missed_shots = false;
00095 if (m_is_active)
00096 return false;
00097 for(int i = 0; i < nb_bullets; i++) {
00098 projectile->Shoot(SHOTGUN_BUCKSHOT_SPEED);
00099 projectile = NULL;
00100 ReloadLauncher();
00101 }
00102 ShootSound();
00103 m_last_fire_time = Time::GetInstance()->Read();
00104 m_is_active = true;
00105 return true;
00106 }
00107