GameMode Class Reference

#include <game_mode.h>

Collaboration diagram for GameMode:

Collaboration graph
[legend]
List of all members.

Public Member Functions

bool Load (const std::string &mode)
bool AllowCharacterSelection () const

Static Public Member Functions

static GameModeGetInstance ()

Public Attributes

uint max_characters
uint max_teams
uint duration_turn
uint duration_move_player
uint duration_exchange_player
uint duration_before_death_mode
uint damage_per_turn_during_death_mode
double gravity
double safe_fall
double damage_per_fall_unit
ExplosiveWeaponConfig death_explosion_cfg
ExplosiveWeaponConfig barrel_explosion_cfg
ExplosiveWeaponConfig bonus_box_explosion_cfg
GameMode::s_character character
int allow_character_selection

Static Public Attributes

static const int ALWAYS = 0
static const int BEFORE_FIRST_ACTION = 1
static const int BEFORE_FIRST_ACTION_AND_END_TURN = 2
static const int CHANGE_ON_END_TURN = 3
static const int NEVER = 4

Protected Member Functions

bool LoadXml (xmlpp::Element *xml)

Private Member Functions

 GameMode ()

Private Attributes

std::string m_current

Static Private Attributes

static GameModesingleton = NULL

Classes

struct  s_character

Detailed Description

Definition at line 31 of file game_mode.h.


Constructor & Destructor Documentation

GameMode::GameMode (  )  [private]

Definition at line 41 of file game_mode.cpp.

00042 {
00043   max_characters = 6;
00044   max_teams = 4;
00045   duration_turn = 60;
00046   duration_exchange_player = 2;
00047   duration_before_death_mode = 20 * 60;
00048   damage_per_turn_during_death_mode = 5;
00049   gravity = 9.81;
00050   safe_fall = 10;
00051   damage_per_fall_unit = 7;
00052   duration_move_player = 3;
00053   allow_character_selection = BEFORE_FIRST_ACTION_AND_END_TURN;
00054   character.init_energy = 100; /* overvriten whenreading XML */
00055   character.max_energy = 100; /* overvriten whenreading XML */
00056   character.mass = 100;
00057   character.air_resist_factor = 1.0;
00058   character.jump_strength = 8;
00059   character.jump_angle = -60;
00060   character.super_jump_strength = 11;
00061   character.super_jump_angle = -80;
00062   character.back_jump_strength = 9;
00063   character.back_jump_angle = -100;
00064 }

Here is the caller graph for this function:


Member Function Documentation

bool GameMode::AllowCharacterSelection (  )  const

Definition at line 202 of file game_mode.cpp.

00203 {
00204   switch (allow_character_selection)
00205   {
00206   case GameMode::ALWAYS: break;
00207 
00208   case GameMode::BEFORE_FIRST_ACTION:
00209   case GameMode::BEFORE_FIRST_ACTION_AND_END_TURN:
00210           return (GameLoop::GetInstance()->ReadState() == GameLoop::PLAYING) && !GameLoop::GetInstance()->character_already_chosen;
00211 
00212   case GameMode::CHANGE_ON_END_TURN:
00213   case GameMode::NEVER:
00214           return false;
00215   }
00216 
00217   return true;
00218 }

Here is the call graph for this function:

GameMode * GameMode::GetInstance (  )  [static]

Definition at line 34 of file game_mode.cpp.

00034                                  {
00035   if (singleton == NULL) {
00036     singleton = new GameMode();
00037   }
00038   return singleton;
00039 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool GameMode::Load ( const std::string &  mode  ) 

Definition at line 166 of file game_mode.cpp.

00167 {
00168   if (mode == m_current) return true;
00169   m_current = mode;
00170 
00171   std::string fullname;
00172   try
00173   {
00174     XmlReader doc;
00175     std::string filename =
00176       PATH_SEPARATOR
00177       + std::string("game_mode")
00178       + std::string(PATH_SEPARATOR)
00179       + mode
00180       + std::string(".xml");
00181 
00182     Config * config = Config::GetInstance();
00183     fullname = config->GetPersonalDir() + filename;
00184 
00185     if(!IsFileExist(fullname))
00186       fullname = config->GetDataDir() + filename;
00187     if(!doc.Load(fullname))
00188       return false;
00189     if(!LoadXml(doc.GetRoot()))
00190       return false;
00191   }
00192   catch (const xmlpp::exception &e)
00193   {
00194     std::cerr << Format(_("Error while loading game mode %s (file %s):"),
00195                         mode.c_str(), fullname.c_str())
00196                           << std::endl << e.what() << std::endl;
00197     return false;
00198   }
00199   return true;
00200 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool GameMode::LoadXml ( xmlpp::Element *  xml  )  [protected]

Definition at line 67 of file game_mode.cpp.

00068 {
00069   std::string txt;
00070   if (XmlReader::ReadString(xml, "allow_character_selection", txt))
00071   {
00072     if (txt == "always")
00073       allow_character_selection = ALWAYS;
00074     else if (txt == "never")
00075       allow_character_selection = NEVER;
00076     else if (txt == "change_on_end_turn")
00077       allow_character_selection = CHANGE_ON_END_TURN;
00078     else if (txt == "before_first_action_and_end_turn")
00079       allow_character_selection = BEFORE_FIRST_ACTION_AND_END_TURN;
00080     else if (txt == "before_first_action")
00081       allow_character_selection = BEFORE_FIRST_ACTION;
00082   }
00083 
00084   XmlReader::ReadUint(xml, "duration_turn", duration_turn);
00085   XmlReader::ReadUint(xml, "duration_move_player", duration_move_player);
00086   XmlReader::ReadUint(xml, "duration_exchange_player", duration_exchange_player);
00087   XmlReader::ReadUint(xml, "duration_before_death_mode", duration_before_death_mode);
00088   XmlReader::ReadUint(xml, "damage_per_turn_during_death_mode", damage_per_turn_during_death_mode);
00089   XmlReader::ReadUint(xml, "max_teams", max_teams);
00090   XmlReader::ReadUint(xml, "max_characters", max_characters);
00091   XmlReader::ReadDouble(xml, "gravity", gravity);
00092   XmlReader::ReadDouble(xml, "safe_fall", safe_fall);
00093   XmlReader::ReadDouble(xml, "damage_per_fall_unit", damage_per_fall_unit);
00094 
00095   // Character options
00096   xmlpp::Element *character_xml = XmlReader::GetMarker(xml, "character");
00097   if (character_xml != NULL)
00098   {
00099     xmlpp::Element *item = XmlReader::GetMarker(character_xml, "energy");
00100     if (item != NULL) {
00101       XmlReader::ReadUintAttr(item, "initial", character.init_energy);
00102       XmlReader::ReadUintAttr(item, "maximum", character.max_energy);
00103       if (character.init_energy==0) character.init_energy = 1;
00104       if (character.max_energy==0) character.max_energy = 1;
00105     }
00106     XmlReader::ReadUint(character_xml, "mass", character.mass);
00107     XmlReader::ReadDouble(character_xml, "air_resist_factor", character.air_resist_factor);
00108     item = XmlReader::GetMarker(character_xml, "jump");
00109     if (item != NULL) {
00110       int angle_deg;
00111       XmlReader::ReadUintAttr(item, "strength", character.jump_strength);
00112       XmlReader::ReadIntAttr(item, "angle", angle_deg);
00113       character.jump_angle = static_cast<double>(angle_deg) * M_PI / 180;
00114     }
00115 
00116     item = XmlReader::GetMarker(character_xml, "super_jump");
00117     if (item != NULL) {
00118       int angle_deg;
00119       XmlReader::ReadUintAttr(item, "strength", character.super_jump_strength);
00120       XmlReader::ReadIntAttr(item, "angle", angle_deg);
00121       character.super_jump_angle = static_cast<double>(angle_deg) * M_PI / 180;
00122     }
00123     item = XmlReader::GetMarker(character_xml, "back_jump");
00124     if (item != NULL) {
00125       int angle_deg;
00126       XmlReader::ReadUintAttr(item, "strength", character.back_jump_strength);
00127       XmlReader::ReadIntAttr(item, "angle", angle_deg);
00128       character.back_jump_angle = static_cast<double>(angle_deg) * M_PI / 180;
00129     }
00130     xmlpp::Element *explosion = XmlReader::GetMarker(character_xml, "death_explosion");
00131     if (explosion != NULL)
00132       death_explosion_cfg.LoadXml(explosion);
00133   }
00134 
00135   // Barrel explosion
00136   xmlpp::Element *barrel_xml = XmlReader::GetMarker(xml, "barrel");
00137   if(barrel_xml != NULL) {
00138     xmlpp::Element *barrel_explosion = XmlReader::GetMarker(barrel_xml, "explosion");
00139     if (barrel_explosion != NULL)
00140       barrel_explosion_cfg.LoadXml(barrel_explosion);
00141   }
00142 
00143   // Bonus box explosion
00144   xmlpp::Element *bonus_box_xml = XmlReader::GetMarker(xml, "bonus_box");
00145   if(bonus_box_xml != NULL) {
00146     xmlpp::Element *bonus_box_explosion = XmlReader::GetMarker(bonus_box_xml, "explosion");
00147     if (bonus_box_explosion != NULL)
00148       bonus_box_explosion_cfg.LoadXml(bonus_box_explosion);
00149   }
00150 
00151   //=== Weapons ===
00152   xmlpp::Element *armes = XmlReader::GetMarker(xml, "weapons");
00153   if (armes != NULL)
00154   {
00155     std::list<Weapon*> l_weapons_list = Config::GetInstance()->GetWeaponsList()->GetList() ;
00156     std::list<Weapon*>::iterator
00157       itw = l_weapons_list.begin(),
00158       end = l_weapons_list.end();
00159 
00160     for (; itw != end ; ++itw) (*itw)->LoadXml(armes);
00161   }
00162 
00163   return true;
00164 }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

int GameMode::allow_character_selection

Definition at line 62 of file game_mode.h.

const int GameMode::ALWAYS = 0 [static]

Definition at line 64 of file game_mode.h.

ExplosiveWeaponConfig GameMode::barrel_explosion_cfg

Definition at line 45 of file game_mode.h.

const int GameMode::BEFORE_FIRST_ACTION = 1 [static]

Definition at line 65 of file game_mode.h.

const int GameMode::BEFORE_FIRST_ACTION_AND_END_TURN = 2 [static]

Definition at line 66 of file game_mode.h.

ExplosiveWeaponConfig GameMode::bonus_box_explosion_cfg

Definition at line 46 of file game_mode.h.

const int GameMode::CHANGE_ON_END_TURN = 3 [static]

Definition at line 67 of file game_mode.h.

struct GameMode::s_character GameMode::character

double GameMode::damage_per_fall_unit

Definition at line 43 of file game_mode.h.

uint GameMode::damage_per_turn_during_death_mode

Definition at line 40 of file game_mode.h.

ExplosiveWeaponConfig GameMode::death_explosion_cfg

Definition at line 44 of file game_mode.h.

uint GameMode::duration_before_death_mode

Definition at line 39 of file game_mode.h.

uint GameMode::duration_exchange_player

Definition at line 38 of file game_mode.h.

uint GameMode::duration_move_player

Definition at line 37 of file game_mode.h.

uint GameMode::duration_turn

Definition at line 36 of file game_mode.h.

double GameMode::gravity

Definition at line 41 of file game_mode.h.

std::string GameMode::m_current [private]

Definition at line 71 of file game_mode.h.

uint GameMode::max_characters

Definition at line 34 of file game_mode.h.

uint GameMode::max_teams

Definition at line 35 of file game_mode.h.

const int GameMode::NEVER = 4 [static]

Definition at line 68 of file game_mode.h.

double GameMode::safe_fall

Definition at line 42 of file game_mode.h.

GameMode * GameMode::singleton = NULL [static, private]

Definition at line 72 of file game_mode.h.


The documentation for this class was generated from the following files:
Generated on Mon Jan 1 13:50:31 2007 for Wormux by  doxygen 1.4.7