00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "baseball.h"
00023 #include "../game/game_loop.h"
00024 #include "../map/camera.h"
00025 #include "../team/macro.h"
00026 #include "../tool/point.h"
00027 #include "../tool/i18n.h"
00028 #include "explosion.h"
00029
00030 Baseball::Baseball() : Weapon(WEAPON_BASEBALL, "baseball", new BaseballConfig())
00031 {
00032 m_name = _("Baseball Bat");
00033 m_weapon_fire = new Sprite(resource_manager.LoadImage(weapons_res_profile,m_id+"_fire"));
00034 m_weapon_fire->EnableRotationCache(32);
00035 }
00036
00037 bool Baseball::p_Shoot (){
00038
00039 double angle = ActiveCharacter().GetFiringAngle();
00040 double rayon = 0.0;
00041 bool fin = false;
00042
00043 jukebox.Play ("share","weapon/baseball");
00044
00045 do
00046 {
00047
00048 rayon += 1.0;
00049 if (cfg().range < rayon)
00050 {
00051 rayon = cfg().range;
00052 fin = true;
00053 }
00054
00055
00056 Point2i relative_pos(static_cast<int>(rayon * cos(angle)),
00057 static_cast<int>(rayon * sin(angle)) );
00058 Point2i pos_to_check = ActiveCharacter().GetHandPosition() + relative_pos;
00059
00060 FOR_ALL_LIVING_CHARACTERS(equipe,ver)
00061 if (&(*ver) != &ActiveCharacter())
00062 {
00063
00064 if( ver->ObjTouche(pos_to_check) )
00065 {
00066
00067 ver->SetSpeed (cfg().strength / ver->GetMass(), angle);
00068 ver->SetMovement("fly");
00069 camera.FollowObject (&(*ver), true, true);
00070 return true;
00071 }
00072 }
00073 } while (!fin);
00074
00075 return true;
00076 }
00077
00078 void Baseball::Refresh(){
00079 if (m_is_active)
00080 m_is_active = false;
00081 }
00082
00083 BaseballConfig& Baseball::cfg() {
00084 return static_cast<BaseballConfig&>(*extra_params);
00085 }
00086
00087 BaseballConfig::BaseballConfig(){
00088 range = 70;
00089 strength = 250;
00090 }
00091
00092 void BaseballConfig::LoadXml(xmlpp::Element *elem){
00093 WeaponConfig::LoadXml(elem);
00094 XmlReader::ReadUint(elem, "range", range);
00095 XmlReader::ReadUint(elem, "strength", strength);
00096 }