00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "polecat.h"
00023 #include <sstream>
00024 #include "explosion.h"
00025 #include "../game/config.h"
00026 #include "../game/time.h"
00027 #include "../graphic/video.h"
00028 #include "../interface/game_msg.h"
00029 #include "../map/camera.h"
00030 #include "../object/objects_list.h"
00031 #include "../sound/jukebox.h"
00032 #include "../team/teams_list.h"
00033 #include "../tool/math_tools.h"
00034 #include "../tool/i18n.h"
00035 #include "../network/randomsync.h"
00036
00037 const uint TIME_BETWEEN_FART = 500;
00038
00039 PolecatFart::PolecatFart(ExplosiveWeaponConfig& cfg,
00040 WeaponLauncher * p_launcher) :
00041 WeaponProjectile("polecat_fart", cfg, p_launcher)
00042 {
00043 explode_with_collision = false;
00044 }
00045
00046 Polecat::Polecat(ExplosiveWeaponConfig& cfg,
00047 WeaponLauncher * p_launcher) :
00048 WeaponProjectile("polecat", cfg, p_launcher)
00049 {
00050 explode_with_collision = false;
00051 last_fart_time = 0;
00052 }
00053
00054 void Polecat::Shoot (double strength)
00055 {
00056 WeaponProjectile::Shoot(strength);
00057 last_fart_time = Time::GetInstance()->Read() + TIME_BETWEEN_FART;
00058
00059 save_x=GetX();
00060 save_y=GetY();
00061
00062 double angle = ActiveCharacter().GetFiringAngle();
00063
00064 if(angle<M_PI/2 && angle>-M_PI/2)
00065 m_sens = 1;
00066 else
00067 m_sens = -1;
00068 }
00069
00070 void Polecat::Refresh()
00071 {
00072 WeaponProjectile::Refresh();
00073
00074 double norme, angle;
00075
00076 if(!IsMoving() && !FootsInVacuum())
00077 {
00078
00079 int x = GetX();
00080 int y = GetY();
00081 if(x==save_x && y==save_y)
00082 m_sens = - m_sens;
00083 save_x = x;
00084 save_y = y;
00085
00086
00087 norme = randomSync.GetDouble(1.0, 2.0);
00088 PutOutOfGround();
00089 SetSpeedXY(Point2d(m_sens * norme , - norme * 3.0));
00090 }
00091 if (last_fart_time + TIME_BETWEEN_FART < Time::GetInstance()->Read()) {
00092 double norme = randomSync.GetLong(0, 5000)/100;
00093 double angle = randomSync.GetLong(0, 3000)/1000;
00094 ParticleEngine::AddNow(GetPosition(), 1, particle_POLECAT_FART, true, norme, angle);
00095 last_fart_time = Time::GetInstance()->Read();
00096 }
00097
00098
00099 GetSpeed(norme, angle);
00100
00101 while(angle < -M_PI)
00102 angle += M_PI;
00103 while(angle > M_PI)
00104 angle -= M_PI;
00105
00106 angle /= 2.0;
00107 if(m_sens == -1)
00108 {
00109 if(angle > 0)
00110 angle -= M_PI_2;
00111 else
00112 angle += M_PI_2;
00113 }
00114
00115 image->SetRotation_rad(angle);
00116 image->Scale((double)m_sens,1.0);
00117 image->Update();
00118
00119 SetTestRect ( image->GetWidth()/2-1,
00120 image->GetWidth()/2-1,
00121 image->GetHeight()/2-1,
00122 image->GetHeight()/2-1);
00123 }
00124
00125 void Polecat::SignalOutOfMap()
00126 {
00127 GameMessages::GetInstance()->Add (_("The Polecat left the battlefield before exploding"));
00128 WeaponProjectile::SignalOutOfMap();
00129 }
00130
00131
00132 PolecatLauncher::PolecatLauncher() :
00133 WeaponLauncher(WEAPON_POLECAT, "polecatlauncher", new ExplosiveWeaponConfig(), VISIBLE_ONLY_WHEN_INACTIVE)
00134 {
00135 m_name = _("Polecat Launcher");
00136 ReloadLauncher();
00137 }
00138
00139 WeaponProjectile * PolecatLauncher::GetProjectileInstance()
00140 {
00141 return dynamic_cast<WeaponProjectile *>
00142 (new Polecat(cfg(),dynamic_cast<WeaponLauncher *>(this)));
00143 }