src/weapon/blowtorch.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  * Blowtorch - burns holes into walls
00020  *****************************************************************************/
00021 
00022 #include "../weapon/blowtorch.h"
00023 #include "../tool/i18n.h"
00024 #include "../map/map.h"
00025 #include "../team/teams_list.h"
00026 #include "../game/game_loop.h"
00027 #include "../game/time.h"
00028 #include "../character/move.h"
00029 #include "../character/body.h"
00030 #include "explosion.h"
00031 
00032 static const uint pause_time = 200;     // milliseconds
00033 
00034 Blowtorch::Blowtorch() : Weapon(WEAPON_BLOWTORCH, "blowtorch", new BlowtorchConfig())
00035 {
00036   m_name = _("Blowtorch");
00037   override_keys = true;
00038 
00039   new_timer = 0;
00040   old_timer = 0;
00041 
00042   m_weapon_fire = new Sprite(resource_manager.LoadImage(weapons_res_profile, "blowtorch_fire"));
00043 }
00044 
00045 void Blowtorch::Refresh()
00046 {
00047 
00048 }
00049 
00050 void Blowtorch::EndTurn()
00051 {
00052   ActiveCharacter().body->ResetWalk();
00053   ActiveCharacter().body->StopWalk();
00054   ActiveTeam().AccessNbUnits() = 0;
00055   m_is_active = false;
00056 
00057         // XXX This doesn't seem to be the correct to end a turn, does it?
00058   GameLoop::GetInstance()->SetState(GameLoop::HAS_PLAYED);
00059 }
00060 
00061 bool Blowtorch::p_Shoot()
00062 {
00063   ActiveCharacter().SetRebounding(false);
00064   ActiveCharacter().body->StartWalk();
00065 
00066   Point2i hole = ActiveCharacter().GetCenter();
00067 
00068   double angle = ActiveCharacter().GetFiringAngle();
00069   uint h = cfg().range;
00070   double dx = cos(angle) * h;
00071   double dy = sin(angle) * h;
00072 
00073   Point2i pos = Point2i(hole.x+(int)dx, hole.y+(int)dy);
00074   world.Dig(pos, ActiveCharacter().GetHeight()/2);
00075 
00076   MoveCharacter(ActiveCharacter());
00077   ActiveCharacter().SetXY(ActiveCharacter().GetPosition());
00078 
00079   return true;
00080 }
00081 
00082 void Blowtorch::HandleKeyEvent(Action::Action_t action, Keyboard::Key_Event_t event_type)
00083 {
00084   switch(action)
00085   {
00086     case Action::ACTION_SHOOT:
00087       if(event_type ==  Keyboard:: Keyboard::KEY_RELEASED)
00088         EndTurn();
00089       else if(event_type == Keyboard::KEY_REFRESH)
00090       {
00091         if(!EnoughAmmoUnit() || ActiveCharacter().GotInjured())
00092           EndTurn();
00093 
00094         new_timer = Time::GetInstance()->Read();
00095         if(new_timer - old_timer >= pause_time)
00096         {
00097           NewActionShoot();
00098           old_timer = new_timer;
00099         }
00100       }
00101 
00102       break;
00103     default:
00104       break;
00105   }
00106 }
00107 
00108 //-------------------------------------------------------------------------------------
00109 
00110 BlowtorchConfig::BlowtorchConfig()
00111 {
00112   range = 2;
00113 }
00114 
00115 BlowtorchConfig& Blowtorch::cfg()
00116 {
00117   return static_cast<BlowtorchConfig&>(*extra_params);
00118 }
00119 
00120 void BlowtorchConfig::LoadXml(xmlpp::Element* elem)
00121 {
00122   WeaponConfig::LoadXml(elem);
00123   XmlReader::ReadUint(elem, "range", range);
00124 }

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