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 * Character of a team. 00020 *****************************************************************************/ 00021 00022 #ifndef _CHARACTER_H 00023 #define _CHARACTER_H 00024 00025 #include <string> 00026 #include <SDL.h> 00027 #include "../gui/EnergyBar.h" 00028 #include "../graphic/sprite.h" 00029 #include "../graphic/text.h" 00030 #include "../include/base.h" 00031 #include "../object/physical_obj.h" 00032 #include "../particles/particle.h" 00033 #include "../interface/keyboard.h" 00034 #include "body.h" 00035 00036 class Team; 00037 class ParticleEngine; 00038 00039 class Character : public PhysicalObj 00040 { 00041 private: 00042 std::string character_name; 00043 Team &m_team; 00044 bool step_sound_played; 00045 bool prepare_shoot; 00046 bool back_jumping; 00047 bool death_explosion; 00048 double firing_angle; 00049 00050 uint disease_damage_per_turn; 00051 uint disease_duration; 00052 int damage_other_team; 00053 int damage_own_team; 00054 int max_damage; 00055 int current_total_damage; 00056 EnergyBar energy_bar; 00057 00058 // survived games 00059 int survivals; 00060 00061 // name 00062 Text* name_text; 00063 00064 // chrono 00065 uint pause_bouge_dg; // pause pour mouvement droite/gauche 00066 uint do_nothing_time; 00067 uint animation_time; 00068 int lost_energy; 00069 bool hidden; //The character is hidden (needed by teleportation) 00070 00071 // Channel used for sound 00072 int channel_step; 00073 00074 // Generates green bubbles when the character is ill 00075 ParticleEngine bubble_engine; 00076 public: 00077 00078 // Previous strength 00079 double previous_strength; 00080 00081 Body* body; 00082 00083 private: 00084 void DrawEnergyBar(int dy); 00085 void DrawName(int dy) const; 00086 00087 void SignalDrowning(); 00088 void SignalGhostState(bool was_dead); 00089 void SignalCollision(); 00090 void SetBody(Body* char_body); 00091 00092 public: 00093 00094 Character (Team& my_team, const std::string &name, Body *char_body); 00095 Character (const Character& acharacter); 00096 ~Character(); 00097 00098 void SignalExplosion(); 00099 00100 // Energy related 00101 void SetEnergyDelta (int delta, bool do_report=true); 00102 void SetEnergy(int new_energy); 00103 inline const int & GetEnergy() const { return life_points;} 00104 00105 bool GotInjured() const; 00106 void Die(); 00107 void DisableDeathExplosion(); 00108 bool IsActiveCharacter() const; 00109 // Disease handling 00110 bool IsDiseased() const; 00111 void SetDiseaseDamage(const uint damage_per_turn, const uint disease_duration); 00112 uint GetDiseaseDamage() const; 00113 uint GetDiseaseDuration() const; 00114 void DecDiseaseDuration(); 00115 00116 void Draw(); 00117 void Refresh(); 00118 00119 void PrepareTurn(); 00120 void StartPlaying(); 00121 void StopPlaying(); 00122 00123 // Handle a key event on the character 00124 void HandleKeyEvent(Action::Action_t action, Keyboard::Key_Event_t event_type); 00125 void PrepareShoot(); 00126 void DoShoot(); 00127 void HandleShoot(Keyboard::Key_Event_t event_type); 00128 double GetFiringAngle() const; 00129 double GetAbsFiringAngle() const; 00130 void SetFiringAngle(double angle); 00131 void AddFiringAngle(double angle); 00132 00133 // Show hide the Character 00134 void Hide(); 00135 void Show(); 00136 00137 // ---- Movement ----- 00138 // Can we move (check a timeout) 00139 bool MouvementDG_Autorise() const; 00140 bool CanJump() const; 00141 00142 // Jumps 00143 void Jump(double strength, double angle); 00144 void Jump(); 00145 void HighJump(); 00146 void BackJump(); 00147 00148 // Initialise left or right movement 00149 void InitMouvementDG (uint pause); 00150 bool CanStillMoveDG (uint pause); 00151 00152 // Direction of the character ( -1 == looks to the left / +1 == looks to the right) 00153 void SetDirection(Body::Direction_t direction); 00154 Body::Direction_t GetDirection() const; 00155 00156 // Team owner 00157 const Team& GetTeam() const; 00158 uint GetTeamIndex(); 00159 uint GetCharacterIndex(); 00160 00161 // Access to character info 00162 const std::string& GetName() const { return character_name; } 00163 bool IsSameAs(const Character& other) { return (GetName() == other.GetName()); } 00164 00165 // Hand position 00166 const Point2i & GetHandPosition() const; 00167 00168 // Damage report 00169 void HandleMostDamage(); 00170 void MadeDamage(const int Dmg, const Character &other); 00171 int GetMostDamage() const { return max_damage; } 00172 int GetOwnDamage() const { return damage_own_team; } 00173 int GetOtherDamage() const { return damage_other_team; } 00174 00175 // Body handling 00176 Body * GetBody() const; 00177 void SetWeaponClothe(); 00178 void SetClothe(std::string name); 00179 void SetMovement(std::string name); 00180 void SetClotheOnce(std::string name); 00181 void SetMovementOnce(std::string name); 00182 }; 00183 00184 #endif