src/weapon/anvil.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  * Anvil : appear in top of an enemy and crush down his head
00020  *****************************************************************************/
00021 
00022 #include "anvil.h"
00023 //-----------------------------------------------------------------------------
00024 #include <sstream>
00025 #include "../game/time.h"
00026 #include "../team/teams_list.h"
00027 #include "../graphic/video.h"
00028 #include "../tool/math_tools.h"
00029 #include "../map/camera.h"
00030 #include "../weapon/explosion.h"
00031 #include "../interface/game_msg.h"
00032 #include "../tool/i18n.h"
00033 #include "../object/objects_list.h"
00034 #include "../map/map.h"
00035 //-----------------------------------------------------------------------------
00036 
00037 Anvil::Anvil(ExplosiveWeaponConfig& cfg,
00038              WeaponLauncher * p_launcher) :
00039   WeaponProjectile ("anvil", cfg, p_launcher)
00040 {
00041   explode_with_collision = false;
00042   explode_colliding_character = false;
00043   merge_time = 0;
00044 }
00045 
00046 void Anvil::SignalObjectCollision(PhysicalObj * obj)
00047 {
00048   if(typeid(*obj) == typeid(Character)) {
00049     Character * tmp = (Character *)(obj);
00050     tmp -> SetEnergyDelta (-200);
00051   }
00052 }
00053 
00054 void Anvil::SignalGroundCollision()
00055 {
00056   merge_time = Time::GetInstance()->Read() + 5000;
00057 }
00058 
00059 void Anvil::Refresh()
00060 {
00061   if(merge_time != 0 && merge_time < Time::GetInstance()->Read()) {
00062     world.MergeSprite(GetPosition(),image);
00063     Ghost();
00064   } else {
00065     WeaponProjectile::Refresh();
00066   }
00067 }
00068 
00069 //-----------------------------------------------------------------------------
00070 
00071 AnvilLauncher::AnvilLauncher() :
00072     WeaponLauncher(WEAPON_ANVIL, "anvil_launcher", new ExplosiveWeaponConfig(), VISIBLE_ONLY_WHEN_INACTIVE)
00073 {
00074   m_name = _("Anvil");
00075   mouse_character_selection = false;
00076   can_be_used_on_closed_map = false;
00077   ReloadLauncher();
00078   target_chosen = false;
00079 }
00080 
00081 void AnvilLauncher::ChooseTarget(Point2i mouse_pos)
00082 {
00083   mouse_pos.y = 0;
00084   target = mouse_pos - (projectile->GetSize() / 2);
00085   target_chosen = true;
00086   Shoot();
00087 }
00088 
00089 bool AnvilLauncher::p_Shoot ()
00090 {
00091   if(!target_chosen)
00092     return false;
00093   projectile->SetXY(target);
00094   lst_objects.AddObject(projectile);
00095   camera.FollowObject(projectile,true,true);
00096   projectile = NULL;
00097   ReloadLauncher();
00098   return true;
00099 }
00100 
00101 WeaponProjectile * AnvilLauncher::GetProjectileInstance()
00102 {
00103   return dynamic_cast<WeaponProjectile *>
00104       (new Anvil(cfg(),dynamic_cast<WeaponLauncher *>(this)));
00105 }

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