src/weapon/airhammer.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  * AirHammer - Use it to dig
00020  *****************************************************************************/
00021 
00022 #include "../weapon/airhammer.h"
00023 //-----------------------------------------------------------------------------
00024 #include <sstream>
00025 #include "../game/game.h"
00026 #include "../game/game_loop.h"
00027 #include "../game/time.h"
00028 #include "../include/action_handler.h"
00029 #include "../map/map.h"
00030 #include "../object/objects_list.h"
00031 #include "../team/teams_list.h"
00032 #include "../team/macro.h"
00033 #include "../tool/i18n.h"
00034 #include "../interface/game_msg.h"
00035 #include "../weapon/explosion.h"
00036 
00037 //-----------------------------------------------------------------------------
00038 
00039 const uint MIN_TIME_BETWEEN_JOLT = 100; // in milliseconds
00040 
00041 //-----------------------------------------------------------------------------
00042 //-----------------------------------------------------------------------------
00043 
00044 Airhammer::Airhammer() : Weapon(WEAPON_AIR_HAMMER,"airhammer",new AirhammerConfig())
00045 {
00046   m_name = _("Airhammer");
00047   override_keys = true ;
00048 
00049   impact = resource_manager.LoadImage( weapons_res_profile, "airhammer_impact");
00050   m_last_jolt = 0;
00051 }
00052 
00053 //-----------------------------------------------------------------------------
00054 
00055 void Airhammer::p_Deselect()
00056 {
00057   m_is_active = false;
00058 }
00059 
00060 //-----------------------------------------------------------------------------
00061 
00062 bool Airhammer::p_Shoot()
00063 {
00064   jukebox.Play("share","weapon/airhammer");
00065 
00066   // initiate movement ;-)
00067   ActiveCharacter().SetRebounding(false);
00068 
00069   // Little hack, so the character notices he is in the vaccum and begins to fall in the hole
00070   ActiveCharacter().SetXY( ActiveCharacter().GetPosition() );
00071 
00072   Point2i pos = Point2i(ActiveCharacter().GetX() + ActiveCharacter().GetWidth()/2 - impact.GetWidth()/2,
00073                         ActiveCharacter().GetTestRect().GetPositionY() +
00074                         ActiveCharacter().GetHeight()  -15);
00075 
00076   ParticleEngine::AddNow(pos + Point2i(impact.GetWidth()/4,9), 1, particle_AIR_HAMMER,
00077                          true, -3.0 * M_PI_4, 5.0 + Time::GetInstance()->Read() % 5);
00078   ParticleEngine::AddNow(pos + Point2i(3*impact.GetWidth()/4,9), 1, particle_AIR_HAMMER,
00079                          true, -M_PI_4, 5.0 + Time::GetInstance()->Read() % 5);
00080   world.Dig( pos, impact );
00081 
00082   uint range = 0;
00083   int x,y; // Testing coordinates
00084   bool end = false;
00085   do
00086   {
00087     // Did we have finished the computation
00088     range += 1;
00089     if (range > cfg().range)
00090     {
00091       range = cfg().range;
00092       end = true;
00093     }
00094 
00095     // Compute point coordinates
00096     y = ActiveCharacter().GetHandPosition().y + range;
00097     x = ActiveCharacter().GetHandPosition().x;
00098 
00099     FOR_ALL_LIVING_CHARACTERS(team, character)
00100     if (&(*character) != &ActiveCharacter())
00101     {
00102       // Did we touch somebody ?
00103       if( character->ObjTouche(Point2i(x, y)) )
00104       {
00105         // Apply damage (*ver).SetEnergyDelta (-cfg().damage);
00106         character->SetEnergyDelta(-cfg().damage);
00107         end = true;
00108       }
00109     }
00110   } while (!end);
00111 
00112   return true;
00113 }
00114 
00115 //-----------------------------------------------------------------------------
00116 
00117 void Airhammer::RepeatShoot()
00118 {
00119   uint time = Time::GetInstance()->Read() - m_last_jolt;
00120   uint tmp = Time::GetInstance()->Read();
00121 
00122   if (time >= MIN_TIME_BETWEEN_JOLT)
00123   {
00124     m_is_active = false;
00125     NewActionShoot();
00126     m_last_jolt = tmp;
00127   }
00128 
00129 }
00130 
00131 //-----------------------------------------------------------------------------
00132 
00133 void Airhammer::Refresh()
00134 {
00135 }
00136 
00137 //-----------------------------------------------------------------------------
00138 
00139 void Airhammer::HandleKeyEvent(Action::Action_t action, Keyboard::Key_Event_t event_type)
00140 {
00141   switch (action) {
00142 
00143     case Action::ACTION_SHOOT:
00144 
00145       if (event_type == Keyboard::KEY_RELEASED || ActiveCharacter().GotInjured()) {
00146         // stop when key is released or character got injured
00147         ActiveTeam().AccessNbUnits() = 0;
00148         m_is_active = false;
00149         GameLoop::GetInstance()->SetState(GameLoop::HAS_PLAYED);
00150       }
00151 
00152       if (event_type == Keyboard::KEY_REFRESH)
00153         RepeatShoot();
00154 
00155       break ;
00156 
00157     default:
00158       break ;
00159   }
00160 
00161 }
00162 //-----------------------------------------------------------------------------
00163 
00164 AirhammerConfig& Airhammer::cfg() {
00165   return static_cast<AirhammerConfig&>(*extra_params);
00166 }
00167 
00168 //-----------------------------------------------------------------------------
00169 
00170 AirhammerConfig::AirhammerConfig(){
00171   range =  30;
00172   damage = 3;
00173 }
00174 
00175 //-----------------------------------------------------------------------------
00176 
00177 void AirhammerConfig::LoadXml(xmlpp::Element *elem){
00178   WeaponConfig::LoadXml(elem);
00179   XmlReader::ReadUint(elem, "range", range);
00180   XmlReader::ReadUint(elem, "damage", damage);
00181 }

Generated on Mon Jan 1 13:10:59 2007 for Wormux by  doxygen 1.4.7