00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <sstream>
00026 #include "../map/map.h"
00027 #include "../game/time.h"
00028 #include "../object/objects_list.h"
00029 #include "../team/teams_list.h"
00030 #include "../tool/i18n.h"
00031 #include "../interface/game_msg.h"
00032 #include "../interface/game_msg.h"
00033 #include "../weapon/explosion.h"
00034 #include "../weapon/submachine_gun.h"
00035 #include "../network/randomsync.h"
00036
00037 const uint SUBMACHINE_BULLET_SPEED = 30;
00038 const double SUBMACHINE_TIME_BETWEEN_SHOOT = 70;
00039 const double SUBMACHINE_RANDOM_ANGLE = 0.01;
00040
00041 SubMachineGunBullet::SubMachineGunBullet(ExplosiveWeaponConfig& cfg,
00042 WeaponLauncher * p_launcher) :
00043 WeaponBullet("m16_bullet", cfg, p_launcher)
00044 {
00045 }
00046
00047 void SubMachineGunBullet::RandomizeShoot(double &angle,double &strength)
00048 {
00049 angle += M_PI * randomSync.GetDouble(-SUBMACHINE_RANDOM_ANGLE,SUBMACHINE_RANDOM_ANGLE);
00050 }
00051
00052 void SubMachineGunBullet::ShootSound()
00053 {
00054 jukebox.Play("share", "weapon/m16");
00055 }
00056
00057
00058
00059 SubMachineGun::SubMachineGun() : WeaponLauncher(WEAPON_SUBMACHINE_GUN, "m16", new ExplosiveWeaponConfig())
00060 {
00061 m_name = _("Submachine Gun");
00062
00063 override_keys = true ;
00064 ignore_collision_signal = true;
00065 ignore_explosion_signal = true;
00066 ignore_ghost_state_signal = true;
00067 ignore_drowning_signal = true;
00068 announce_missed_shots = false;
00069
00070 m_weapon_fire = new Sprite(resource_manager.LoadImage(weapons_res_profile,m_id+"_fire"));
00071 m_weapon_fire->EnableRotationCache(32);
00072
00073 ReloadLauncher();
00074 }
00075
00076
00077 WeaponProjectile * SubMachineGun::GetProjectileInstance()
00078 {
00079 return dynamic_cast<WeaponProjectile *>
00080 (new SubMachineGunBullet(cfg(),dynamic_cast<WeaponLauncher *>(this)));
00081 }
00082
00083 void SubMachineGun::IncMissedShots()
00084 {
00085 if(missed_shots + 1 == ReadInitialNbUnit())
00086 announce_missed_shots = true;
00087 WeaponLauncher::IncMissedShots();
00088 }
00089
00090 bool SubMachineGun::p_Shoot ()
00091 {
00092 if (m_is_active)
00093 return false;
00094
00095 projectile->Shoot(SUBMACHINE_BULLET_SPEED);
00096 projectile = NULL;
00097 ReloadLauncher();
00098
00099 Point2i pos = ActiveCharacter().GetHandPosition();
00100 double angle = - M_PI_2 - ActiveCharacter().GetDirection()
00101 * (float)(Time::GetInstance()->Read() % 100) * M_PI_4 / 100.0;
00102 particle.AddNow(pos, 1, particle_BULLET, true, angle,
00103 5.0 + (Time::GetInstance()->Read() % 6));
00104
00105 m_is_active = true;
00106 announce_missed_shots = false;
00107 return true;
00108 }
00109
00110
00111 void SubMachineGun::RepeatShoot()
00112 {
00113 if ( m_is_active )
00114 {
00115 uint tmp = Time::GetInstance()->Read();
00116 uint time = tmp - m_last_fire_time;
00117
00118 if (time >= SUBMACHINE_TIME_BETWEEN_SHOOT)
00119 {
00120 m_is_active = false;
00121 NewActionShoot();
00122 m_last_fire_time = tmp;
00123 }
00124 }
00125 }
00126
00127
00128 void SubMachineGun::HandleKeyEvent(Action::Action_t action, Keyboard::Key_Event_t event_type)
00129 {
00130 switch (action) {
00131 case Action::ACTION_SHOOT:
00132 if (event_type == Keyboard::KEY_REFRESH)
00133 m_is_active = true;
00134 if (event_type == Keyboard::KEY_RELEASED)
00135 m_is_active = false;
00136 if (m_is_active) RepeatShoot();
00137 break;
00138 default:
00139 break;
00140 };
00141 }