00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "disco_grenade.h"
00023 #include <sstream>
00024 #include "explosion.h"
00025 #include "../game/time.h"
00026 #include "../graphic/video.h"
00027 #include "../interface/game_msg.h"
00028 #include "../map/camera.h"
00029 #include "../object/objects_list.h"
00030 #include "../team/teams_list.h"
00031 #include "../tool/math_tools.h"
00032 #include "../tool/i18n.h"
00033
00034 DiscoGrenade::DiscoGrenade(ExplosiveWeaponConfig& cfg,
00035 WeaponLauncher * p_launcher) :
00036 WeaponProjectile ("disco_grenade", cfg, p_launcher),
00037 smoke_engine(40)
00038 {
00039 m_rebound_sound = "weapon/disco_grenade_bounce";
00040 have_played_music = false;
00041 explode_with_collision = false;
00042 }
00043
00044 void DiscoGrenade::Explosion()
00045 {
00046 const uint star_nbr = 9;
00047 const float cos_angle[] = {1.000000, 0.766044, 0.173648, -0.500000, -0.939693, -0.939693, -0.500000, 0.173648, 0.766044};
00048 const float sin_angle[] = {0.000000, 0.642788, 0.984808, 0.866025, 0.342020, -0.342020, -0.866025, -0.984808, -0.642788};
00049
00050 for(uint i=0;i < star_nbr;i++)
00051 {
00052 double angle = 2.0*(double)i*M_PI/(double)star_nbr;
00053
00054
00055 smoke_engine.AddNow(Point2i(GetX()+(int)(cos_angle[i]*(float)cfg.explosion_range),
00056 GetY()+(int)(sin_angle[i]*(float)cfg.explosion_range)),
00057 1,particle_MAGIC_STAR,false,angle,2.5);
00058 }
00059 WeaponProjectile::Explosion();
00060 }
00061
00062 void DiscoGrenade::Refresh()
00063 {
00064 WeaponProjectile::Refresh();
00065
00066 #ifdef HAVE_A_REALLY_BIG_CPU
00067 if(IsMoving())
00068 {
00069 double norme,angle;
00070 GetSpeed(norme,angle);
00071 for(int i = -3; i<4 ; i++)
00072 smoke_engine.AddNow(GetPosition(), 1,particle_MAGIC_STAR, false,angle+(i*M_PI_4/3.0)+M_PI_2,2.0);
00073 }
00074 else
00075 {
00076 smoke_engine.AddNow(GetPosition(), 1,particle_MAGIC_STAR, false,((float)(Time::GetInstance()->Read()%500)-250.0) * M_PI / 250.0,3.0);
00077 }
00078 #else // :-P
00079 smoke_engine.AddPeriodic(GetPosition(), particle_MAGIC_STAR, false);
00080 #endif //HAVE_A_REALLY_BIG_CPU
00081
00082 double tmp = Time::GetInstance()->Read() - begin_time;
00083
00084 if (GetTotalTimeout() >= 2 && tmp > (1000 * GetTotalTimeout() - 2000) && !have_played_music) {
00085 jukebox.Play("share","weapon/alleluia") ;
00086 have_played_music = true;
00087 }
00088 image->SetRotation_rad(GetSpeedAngle());
00089 }
00090
00091 void DiscoGrenade::SignalOutOfMap()
00092 {
00093 GameMessages::GetInstance()->Add (_("The disco grenade has left the dance floor before exploding"));
00094 WeaponProjectile::SignalOutOfMap();
00095 }
00096
00097
00098
00099 DiscoGrenadeLauncher::DiscoGrenadeLauncher() :
00100 WeaponLauncher(WEAPON_DISCO_GRENADE, "disco_grenade", new ExplosiveWeaponConfig(), VISIBLE_ONLY_WHEN_INACTIVE)
00101 {
00102 m_name = _("Disco Grenade");
00103 m_allow_change_timeout = true;
00104 ignore_collision_signal = true;
00105 ReloadLauncher();
00106 }
00107
00108 WeaponProjectile * DiscoGrenadeLauncher::GetProjectileInstance()
00109 {
00110 return dynamic_cast<WeaponProjectile *>
00111 (new DiscoGrenade(cfg(),dynamic_cast<WeaponLauncher *>(this)));
00112 }