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 * Suicide. 00020 *****************************************************************************/ 00021 00022 #include "suicide.h" 00023 #include <iostream> 00024 #include "explosion.h" 00025 #include "../character/body.h" 00026 #include "../game/game_loop.h" 00027 #include "../team/teams_list.h" 00028 #include "../tool/i18n.h" 00029 #include "../include/action_handler.h" 00030 00031 Suicide::Suicide() : Weapon(WEAPON_SUICIDE, "suicide", new ExplosiveWeaponConfig()) 00032 { 00033 m_name = _("Commit Suicide"); 00034 sound_channel = -1; 00035 } 00036 00037 void Suicide::p_Select() 00038 { 00039 is_dying = false; 00040 } 00041 00042 bool Suicide::p_Shoot() 00043 { 00044 sound_channel = jukebox.Play ("share", "weapon/suicide"); 00045 00046 GameLoop::GetInstance()->interaction_enabled=false; 00047 is_dying = true; 00048 00049 return true; 00050 } 00051 00052 void Suicide::Refresh() 00053 { 00054 if (!is_dying) return; 00055 00056 m_is_active = sound_channel != -1 && Mix_Playing(sound_channel); 00057 00058 if(!m_is_active && !ActiveCharacter().IsDead()) 00059 { 00060 ActiveCharacter().DisableDeathExplosion(); 00061 ActiveCharacter().body->MakeParticles(ActiveCharacter().GetPosition()); 00062 Action* a = new Action(Action::ACTION_SET_CHARACTER_ENERGY); 00063 a->Push((int)ActiveCharacter().GetTeamIndex()); 00064 a->Push((int)ActiveCharacter().GetCharacterIndex()); 00065 a->Push(0); // Set energy to 0 => death 00066 ActionHandler::GetInstance()->NewAction(a); 00067 ApplyExplosion(ActiveCharacter().GetCenter(),cfg()); 00068 } 00069 } 00070 00071 ExplosiveWeaponConfig& Suicide::cfg() 00072 { return static_cast<ExplosiveWeaponConfig&>(*extra_params); } 00073