src/weapon/syringe.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  * Weapon Syringe
00020  *****************************************************************************/
00021 
00022 #include "syringe.h"
00023 #include "../game/game_loop.h"
00024 #include "../team/macro.h"
00025 #include "../tool/point.h"
00026 #include "../tool/i18n.h"
00027 #include "explosion.h"
00028 
00029 Syringe::Syringe() : Weapon(WEAPON_SYRINGE, "syringe", new SyringeConfig())
00030 {
00031   m_name = _("Syringe");
00032 }
00033 
00034 void Syringe::Draw() {
00035   Weapon::Draw();
00036 }
00037 
00038 bool Syringe::p_Shoot (){
00039   double angle = ActiveCharacter().GetFiringAngle();
00040   double radius = 0.0;
00041   bool end = false;
00042 
00043   jukebox.Play ("share","weapon/syringe");
00044 
00045   do
00046   {
00047     // Did we have finished the computation
00048     radius += 1.0;
00049     if (cfg().range < radius)
00050     {
00051       radius = cfg().range;
00052       end = true;
00053     }
00054 
00055     // Compute point coordinates
00056     Point2i relative_pos(static_cast<int>(radius * cos(angle)),
00057                          static_cast<int>(radius * sin(angle)) );
00058     Point2i pos_to_check = ActiveCharacter().GetHandPosition() + relative_pos;
00059     FOR_ALL_LIVING_CHARACTERS(team, character)
00060     if (&(*character) != &ActiveCharacter())
00061     {
00062       // Did we touch somebody ?
00063       if( character->ObjTouche(pos_to_check) )
00064       {
00065         // Apply damage (*ver).SetEnergyDelta (-cfg().damage);
00066         character->SetDiseaseDamage(cfg().damage, cfg().turns);
00067         end = true;
00068       }
00069     }
00070   } while (!end);
00071 
00072   return true;
00073 }
00074 
00075 void Syringe::Refresh(){
00076   if (m_is_active)
00077     m_is_active = false;
00078 }
00079 
00080 SyringeConfig& Syringe::cfg() {
00081   return static_cast<SyringeConfig&>(*extra_params);
00082 }
00083 
00084 SyringeConfig::SyringeConfig(){
00085   range =  45;
00086   turns = 10;
00087   damage = 10;
00088 }
00089 
00090 void SyringeConfig::LoadXml(xmlpp::Element *elem){
00091   WeaponConfig::LoadXml(elem);
00092   XmlReader::ReadUint(elem, "range", range);
00093   XmlReader::ReadUint(elem, "turns", turns);
00094   XmlReader::ReadUint(elem, "damage", damage);
00095 }

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