00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "gnu.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 Gnu::Gnu(ExplosiveWeaponConfig& cfg,
00038 WeaponLauncher * p_launcher) :
00039 WeaponProjectile("gnu", cfg, p_launcher)
00040 {
00041 explode_with_collision = false;
00042 }
00043
00044 void Gnu::Shoot (double strength)
00045 {
00046 WeaponProjectile::Shoot(strength);
00047
00048 save_x=GetX();
00049 save_y=GetY();
00050
00051 double angle = ActiveCharacter().GetFiringAngle();
00052
00053 if(angle<M_PI/2 && angle>-M_PI/2)
00054 m_sens = 1;
00055 else
00056 m_sens = -1;
00057 }
00058
00059 void Gnu::Refresh()
00060 {
00061 WeaponProjectile::Refresh();
00062
00063 double norme, angle;
00064
00065 if(!IsMoving()&& !FootsInVacuum())
00066 {
00067
00068 int x = GetX();
00069 int y = GetY();
00070 if(x==save_x && y==save_y)
00071 m_sens = - m_sens;
00072 save_x = x;
00073 save_y = y;
00074
00075
00076 norme = randomSync.GetDouble(2.0, 5.0);
00077 PutOutOfGround();
00078 SetSpeedXY(Point2d(m_sens * norme , - norme * 3.0));
00079 }
00080
00081
00082
00083 GetSpeed(norme, angle);
00084
00085 while(angle < -M_PI)
00086 angle += M_PI;
00087 while(angle > M_PI)
00088 angle -= M_PI;
00089
00090 angle /= 2.0;
00091 if(m_sens == -1)
00092 {
00093 if(angle > 0)
00094 angle -= M_PI_2;
00095 else
00096 angle += M_PI_2;
00097 }
00098
00099 if(angle > 4 * M_PI)
00100 angle = 0;
00101
00102 image->SetRotation_rad(angle);
00103 image->Scale((double)m_sens,1.0);
00104 image->Update();
00105
00106 SetTestRect ( image->GetWidth()/2-1,
00107 image->GetWidth()/2-1,
00108 image->GetHeight()/2-1,
00109 image->GetHeight()/2-1);
00110 }
00111
00112 void Gnu::SignalOutOfMap()
00113 {
00114 GameMessages::GetInstance()->Add (_("The Gnu left the battlefield before exploding"));
00115 WeaponProjectile::SignalOutOfMap();
00116 }
00117
00118
00119 GnuLauncher::GnuLauncher() :
00120 WeaponLauncher(WEAPON_GNU, "gnulauncher", new ExplosiveWeaponConfig(), VISIBLE_ONLY_WHEN_INACTIVE)
00121 {
00122 m_name = _("Gnu Launcher");
00123 ReloadLauncher();
00124 }
00125
00126 WeaponProjectile * GnuLauncher::GetProjectileInstance()
00127 {
00128 return dynamic_cast<WeaponProjectile *>
00129 (new Gnu(cfg(),dynamic_cast<WeaponLauncher *>(this)));
00130 }