00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "parachute.h"
00023 #include "explosion.h"
00024 #include "../game/game.h"
00025 #include "../game/game_mode.h"
00026 #include "../game/game_loop.h"
00027 #include "../interface/game_msg.h"
00028 #include "../object/physical_obj.h"
00029 #include "../sound/jukebox.h"
00030 #include "../team/teams_list.h"
00031 #include "../tool/i18n.h"
00032
00033 Parachute::Parachute() : Weapon(WEAPON_PARACHUTE, "parachute", new ParachuteConfig(), NEVER_VISIBLE)
00034 {
00035 m_name = _("Parachute");
00036 m_initial_nb_ammo = 2 ;
00037 use_unit_on_first_shoot = false;
00038
00039 image = resource_manager.LoadSprite(weapons_res_profile,"parachute_sprite");
00040 }
00041
00042 void Parachute::p_Select()
00043 {
00044 m_is_active = true ;
00045 open = false ;
00046 closing = false ;
00047 image->animation.SetShowOnFinish(SpriteAnimation::show_last_frame);
00048 }
00049
00050 void Parachute::p_Deselect()
00051 {
00052 ActiveCharacter().ResetConstants();
00053 m_is_active = false;
00054 }
00055
00056 bool Parachute::p_Shoot()
00057 {
00058 GameMessages::GetInstance()->Add(_("Parachute is activated automatically."));
00059 return false;
00060 }
00061
00062 void Parachute::Draw()
00063 {
00064 if (open)
00065 {
00066 image->Update();
00067 image->Draw(ActiveCharacter().GetHandPosition() - Point2i(image->GetWidth()/2,image->GetHeight()));
00068 }
00069 }
00070
00071 void Parachute::Refresh()
00072 {
00073 double speed;
00074 double angle;
00075
00076 ActiveCharacter().GetSpeed(speed, angle);
00077
00078 if (ActiveCharacter().FootsInVacuum() && speed != 0.0)
00079 {
00080 if (!open && (speed > GameMode::GetInstance()->safe_fall))
00081 {
00082 if (EnoughAmmo())
00083 {
00084 UseAmmo();
00085 ActiveCharacter().SetAirResistFactor(cfg().air_resist_factor);
00086 ActiveCharacter().SetWindFactor(cfg().wind_factor);
00087 open = true ;
00088 image->animation.SetPlayBackward(false);
00089 image->Start();
00090 ActiveCharacter().SetSpeedXY(Point2d(0,0));
00091 ActiveCharacter().SetMovement("parachute");
00092 }
00093 }
00094 }
00095 else
00096 {
00097
00098 if (open)
00099 {
00100
00101 if (!closing)
00102 {
00103
00104 image->animation.SetPlayBackward(true);
00105 image->animation.SetShowOnFinish(SpriteAnimation::show_blank);
00106 image->Start();
00107 closing = true ;
00108 }
00109 else
00110 {
00111 if (image->IsFinished())
00112 {
00113
00114
00115 open = false ;
00116 closing = false ;
00117 UseAmmoUnit();
00118 }
00119 }
00120 }
00121 }
00122 }
00123
00124 void Parachute::SignalTurnEnd()
00125 {
00126 p_Deselect();
00127 }
00128
00129 ParachuteConfig& Parachute::cfg() {
00130 return static_cast<ParachuteConfig&>(*extra_params);
00131 }
00132
00133 ParachuteConfig::ParachuteConfig(){
00134 wind_factor = 10.0;
00135 air_resist_factor = 140.0 ;
00136 }
00137
00138 void ParachuteConfig::LoadXml(xmlpp::Element *elem){
00139 WeaponConfig::LoadXml(elem);
00140 XmlReader::ReadDouble(elem, "wind_factor", wind_factor);
00141 XmlReader::ReadDouble(elem, "air_resist_factor", air_resist_factor);
00142 }