src/weapon/baseball.cpp

Go to the documentation of this file.
00001 /******************************************************************************
00002  *  Wormux is a convivial mass murder game.
00003  *  Copyright (C) 2001-2004 Lawrence Azzoug.
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
00018  ******************************************************************************
00019  * baseball bat
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     // Did we have finished the computation
00048     rayon += 1.0;
00049     if (cfg().range < rayon)
00050     {
00051       rayon = cfg().range;
00052       fin = true;
00053     }
00054 
00055     // Compute point coordinates
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       // Did we touch somebody ?
00064       if( ver->ObjTouche(pos_to_check) )
00065       {
00066         // Apply damage (*ver).SetEnergyDelta (-cfg().damage);
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 }

Generated on Mon Jan 1 13:11:00 2007 for Wormux by  doxygen 1.4.7