src/weapon/construct.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  * Add a structure to the ground
00020  *****************************************************************************/
00021 
00022 #include "construct.h"
00023 #include "explosion.h"
00024 #include "../game/game_loop.h"
00025 #include "../game/game_mode.h"
00026 #include "../include/action_handler.h"
00027 #include "../interface/mouse.h"
00028 #include "../map/camera.h"
00029 #include "../map/map.h"
00030 #include "../network/network.h"
00031 #include "../team/teams_list.h"
00032 #include "../tool/i18n.h"
00033 
00034 const double angle_step = M_PI / 6.0; // should be a multiple
00035 
00036 
00037 Construct::Construct() : Weapon(WEAPON_CONSTRUCT, "construct",
00038                                         new WeaponConfig(),
00039                                         NEVER_VISIBLE)
00040 {
00041   construct_spr = resource_manager.LoadSprite( weapons_res_profile, "construct_spr");
00042   construct_spr->EnableRotationCache(static_cast<int>(2 * M_PI / angle_step));
00043   m_name = _("Construct");
00044   angle = 0;
00045   force_override_keys = true;
00046   target_chosen = false;
00047 }
00048 
00049 Construct::~Construct()
00050 {
00051   delete construct_spr;
00052 }
00053 
00054 bool Construct::p_Shoot ()
00055 {
00056   if(!target_chosen)
00057         return false;
00058   jukebox.Play("share", "weapon/construct");
00059   world.MergeSprite(dst - construct_spr->GetSizeMax()/2, construct_spr);
00060   GameLoop::GetInstance()->interaction_enabled = false;
00061   return true;
00062 }
00063 
00064 void Construct::Refresh()
00065 {
00066   m_is_active = false;
00067 }
00068 
00069 void Construct::Draw()
00070 {
00071   if (!m_is_active) {
00072     Weapon::Draw();
00073 
00074     dst = Mouse::GetInstance()->GetWorldPosition();
00075     construct_spr->SetRotation_rad(angle);
00076     construct_spr->Draw(dst - construct_spr->GetSize()/2);
00077   }
00078 }
00079 
00080 void Construct::ChooseTarget(Point2i mouse_pos)
00081 {
00082   dst = mouse_pos;
00083   target_chosen = true;
00084   Shoot();
00085 }
00086 
00087 void Construct::HandleKeyEvent(Action::Action_t action, Keyboard::Key_Event_t event_type)
00088 {
00089   switch (action) {
00090     case Action::ACTION_UP:
00091       if (event_type == Keyboard::KEY_PRESSED)
00092         Up();
00093       break ;
00094     case Action::ACTION_DOWN:
00095       if (event_type == Keyboard::KEY_PRESSED)
00096         Down();
00097       break ;
00098     default:
00099       ActiveCharacter().HandleKeyEvent( action, event_type);
00100       break ;
00101   }
00102 }
00103 
00104 void Construct::ActionUp()
00105 {
00106   Up();
00107 }
00108 
00109 void Construct::ActionDown()
00110 {
00111   Down();
00112 }
00113 
00114 void Construct::Up()
00115 {
00116   Action a(Action::ACTION_CONSTRUCTION_UP);
00117   if(ActiveTeam().IsLocal() || ActiveTeam().IsLocalAI())
00118     network.SendAction(&a);
00119   angle += angle_step;
00120 }
00121 
00122 void Construct::Down()
00123 {
00124   Action a(Action::ACTION_CONSTRUCTION_DOWN);
00125   if(ActiveTeam().IsLocal() || ActiveTeam().IsLocalAI())
00126     network.SendAction(&a);
00127   angle -= angle_step;
00128 }
00129 
00130 WeaponConfig& Construct::cfg()
00131 { return static_cast<WeaponConfig&>(*extra_params); }
00132 

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