Team Class Reference

#include <team.h>

Collaboration diagram for Team:

Collaboration graph
[legend]
List of all members.

Public Types

typedef std::list< Character
>::iterator 
iterator
typedef std::list< Character
>::const_iterator 
const_iterator

Public Member Functions

void LoadGamingData (uint howmany)
void UnloadGamingData ()
bool IsSameAs (const Team &other) const
void SetNbCharacters (uint howmany)
uint GetNbCharacters () const
void NextCharacter ()
void SelectCharacter (uint index)
void PrepareTurn ()
CharacterActiveCharacter ()
void DrawEnergy (const Point2i &pos)
void Refresh ()
void SetWeapon (Weapon::Weapon_type nv_arme)
int NbAliveCharacter () const
WeaponAccessWeapon () const
const WeaponGetWeapon () const
Weapon::Weapon_type GetWeaponType () const
void InitEnergy (uint max)
void UpdateEnergyBar ()
TeamEnergyGetEnergyBar ()
uint ReadEnergy ()
const std::string & GetName () const
const std::string & GetId () const
const std::string & GetPlayerName () const
const std::string & GetSoundProfile () const
iterator begin ()
iterator end ()
CharacterFindByIndex (uint index)
void SetPlayerName (const std::string &player_name)
int ReadNbAmmos () const
int ReadNbAmmos (const std::string &weapon_name) const
int & AccessNbAmmos ()
int ReadNbUnits () const
int ReadNbUnits (const std::string &weapon_name) const
int & AccessNbUnits ()
void ResetNbUnits ()
bool IsLocal () const
bool IsLocalAI () const
bool IsActiveTeam () const
void SetLocal ()
void SetLocalAI ()
void SetRemote ()

Static Public Member Functions

static TeamCreateTeam (const std::string &teams_dir, const std::string &id)

Public Attributes

std::map< std::string, int > m_nb_ammos
std::map< std::string, int > m_nb_units
CrossHair crosshair
Surface flag
Point2i sauve_camera
TeamEnergy energy

Private Member Functions

 Team (const std::string &_teams_dir, const std::string &_id, const std::string &_name, const Surface &_flag, const std::string &_sound_profile)
bool LoadCharacters (uint howmany)

Private Attributes

bool is_camera_saved
std::string m_teams_dir
std::string m_id
std::string m_name
std::string m_player_name
std::string m_sound_profile
std::list< Charactercharacters
iterator active_character
Weaponactive_weapon
uint nb_characters
team_player_type_t type_of_player

Detailed Description

Definition at line 46 of file team.h.


Member Typedef Documentation

typedef std::list<Character>::const_iterator Team::const_iterator

Definition at line 50 of file team.h.

typedef std::list<Character>::iterator Team::iterator

Definition at line 49 of file team.h.


Constructor & Destructor Documentation

Team::Team ( const std::string &  _teams_dir,
const std::string &  _id,
const std::string &  _name,
const Surface _flag,
const std::string &  _sound_profile 
) [private]

Definition at line 43 of file team.cpp.

00048   : energy(this)
00049 {
00050   active_character = characters.end();
00051 
00052   is_camera_saved = false;
00053   active_weapon = Config::GetInstance()->GetWeaponsList()->GetWeapon(Weapon::WEAPON_DYNAMITE);
00054 
00055   m_teams_dir = _teams_dir;
00056   m_id = _id;
00057   m_name = _name;
00058   m_sound_profile = _sound_profile;
00059   m_player_name = "";
00060 
00061   nb_characters = GameMode::GetInstance()->max_characters;
00062 
00063   flag = _flag;
00064 
00065   type_of_player = TEAM_human_local;
00066 }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Function Documentation

int & Team::AccessNbAmmos (  ) 

Definition at line 333 of file team.cpp.

00334 {
00335   // if value not initialized, it initialize to 0 and then return 0
00336   return m_nb_ammos[ active_weapon->GetName() ] ;
00337 }

Here is the call graph for this function:

Here is the caller graph for this function:

int & Team::AccessNbUnits (  ) 

Definition at line 339 of file team.cpp.

00340 {
00341   // if value not initialized, it initialize to 0 and then return 0
00342   return m_nb_units[ active_weapon->GetName() ] ;
00343 }

Here is the call graph for this function:

Here is the caller graph for this function:

Weapon & Team::AccessWeapon (  )  const

Definition at line 426 of file team.cpp.

00426 { return *active_weapon; }

Here is the caller graph for this function:

Character & Team::ActiveCharacter (  ) 

Definition at line 285 of file team.cpp.

00286 {
00287   return (*active_character);
00288 }

Here is the caller graph for this function:

Team::iterator Team::begin (  ) 

Definition at line 350 of file team.cpp.

00350 { return characters.begin(); }

Here is the caller graph for this function:

Team * Team::CreateTeam ( const std::string &  teams_dir,
const std::string &  id 
) [static]

Definition at line 68 of file team.cpp.

00070 {
00071   std::string nomfich;
00072   try
00073   {
00074     XmlReader doc;
00075 
00076     // Load XML
00077     nomfich = teams_dir+id+PATH_SEPARATOR+ "team.xml";
00078     if (!IsFileExist(nomfich)) return false;
00079     if (!doc.Load(nomfich)) return false;
00080 
00081     // Load name
00082     std::string name;
00083     if (!XmlReader::ReadString(doc.GetRoot(), "name", name)) return NULL;
00084 
00085     // Load flag
00086     Profile *res = resource_manager.LoadXMLProfile( nomfich, true);
00087     Surface flag = resource_manager.LoadImage(res, "flag");
00088     resource_manager.UnLoadXMLProfile(res);
00089 
00090     // Get sound profile
00091     std::string sound_profile;
00092     if (!XmlReader::ReadString(doc.GetRoot(), "sound_profile", sound_profile))
00093       sound_profile = "default";
00094 
00095     return new Team(teams_dir, id, name, flag, sound_profile) ;
00096   }
00097   catch (const xmlpp::exception &e)
00098   {
00099     std::cerr << std::endl
00100         << Format(_("Error loading team %s:"), id.c_str())
00101         << std::endl << e.what() << std::endl;
00102     return NULL;
00103   }
00104 
00105   return NULL;
00106 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Team::DrawEnergy ( const Point2i pos  ) 

Definition at line 416 of file team.cpp.

00417 {
00418   energy.Draw(pos);
00419 }

Here is the call graph for this function:

Team::iterator Team::end (  ) 

Definition at line 351 of file team.cpp.

00351 { return characters.end(); }

Here is the caller graph for this function:

Character * Team::FindByIndex ( uint  index  ) 

Definition at line 353 of file team.cpp.

00354 {
00355   assert(index < characters.size());
00356   iterator it= characters.begin(), end=characters.end();
00357 
00358   while(index != 0 && it != characters.end())
00359   {
00360     index--;
00361     it++;
00362   }
00363   return &(*it);
00364 }

Here is the call graph for this function:

Here is the caller graph for this function:

TeamEnergy & Team::GetEnergyBar (  ) 

Definition at line 213 of file team.cpp.

00214 {
00215   return energy;
00216 }

const std::string& Team::GetId (  )  const [inline]

Definition at line 128 of file team.h.

00128 { return m_id; }

Here is the caller graph for this function:

const std::string& Team::GetName (  )  const [inline]

Definition at line 127 of file team.h.

00127 { return m_name; }

Here is the caller graph for this function:

uint Team::GetNbCharacters (  )  const [inline]

Definition at line 92 of file team.h.

00092 { return nb_characters; }

Here is the caller graph for this function:

const std::string& Team::GetPlayerName (  )  const [inline]

Definition at line 129 of file team.h.

00129 { return m_player_name; }

Here is the caller graph for this function:

const std::string& Team::GetSoundProfile (  )  const [inline]

Definition at line 130 of file team.h.

00130 { return m_sound_profile; }

const Weapon & Team::GetWeapon (  )  const

Definition at line 427 of file team.cpp.

00427 { return *active_weapon; }

Here is the caller graph for this function:

Weapon::Weapon_type Team::GetWeaponType (  )  const

Definition at line 428 of file team.cpp.

00428 { return GetWeapon().GetType(); }

Here is the call graph for this function:

void Team::InitEnergy ( uint  max  ) 

Definition at line 189 of file team.cpp.

00190 {
00191   energy.Config(ReadEnergy(), max);
00192 }

Here is the call graph for this function:

bool Team::IsActiveTeam (  )  const

Definition at line 435 of file team.cpp.

00436 {
00437   return this == &ActiveTeam();
00438 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool Team::IsLocal (  )  const

Definition at line 440 of file team.cpp.

00441 {
00442   if (type_of_player == TEAM_human_local)
00443     return true;
00444 
00445   return false;
00446 }

Here is the caller graph for this function:

bool Team::IsLocalAI (  )  const

Definition at line 448 of file team.cpp.

00449 {
00450   if (type_of_player == TEAM_ai_local)
00451     return true;
00452 
00453   return false;
00454 }

Here is the caller graph for this function:

bool Team::IsSameAs ( const Team other  )  const

Definition at line 430 of file team.cpp.

00431 {
00432   return (strcmp(m_id.c_str(), other.GetId().c_str()) == 0);
00433 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool Team::LoadCharacters ( uint  howmany  )  [private]

Definition at line 109 of file team.cpp.

00110 {
00111   //assert(howmany <= GameMode::GetInstance()->max_characters);
00112   assert (howmany <= 10);
00113 
00114   std::string nomfich;
00115   try
00116   {
00117     XmlReader doc;
00118 
00119     // Load XML
00120     nomfich = m_teams_dir+m_id+PATH_SEPARATOR+ "team.xml";
00121     if (!IsFileExist(nomfich)) return false;
00122     if (!doc.Load(nomfich)) return false;
00123 
00124     // Create the characters
00125     xmlpp::Element *xml = XmlReader::GetMarker(doc.GetRoot(), "team");
00126 
00127     xmlpp::Node::NodeList nodes = xml->get_children("character");
00128     xmlpp::Node::NodeList::iterator it=nodes.begin();
00129 
00130     characters.clear();
00131     active_character = characters.end();
00132     do
00133     {
00134       xmlpp::Element *elem = dynamic_cast<xmlpp::Element*> (*it);
00135       Body* body;
00136       std::string character_name="Soldat Inconnu";
00137       std::string body_name="";
00138       XmlReader::ReadStringAttr(elem, "name", character_name);
00139       XmlReader::ReadStringAttr(elem, "body", body_name);
00140 
00141       if (!(body = body_list.GetBody(body_name)) )
00142       {
00143         std::cerr
00144             << Format(_("Error: can't find the body \"%s\" for the team \"%s\"."),
00145                       body_name.c_str(),
00146                       m_name.c_str())
00147             << std::endl;
00148         return false;
00149       }
00150 
00151       // Create a new character and add him to the team
00152       Character new_character(*this, character_name, body);
00153       characters.push_back(new_character);
00154       active_character = characters.begin(); // we need active_character to be initialized here !!
00155       if (!characters.back().PutRandomly(false, world.dst_min_entre_vers))
00156       {
00157         // We haven't found any place to put the characters!!
00158         if (!characters.back().PutRandomly(false, world.dst_min_entre_vers/2)) {
00159           std::cerr << std::endl;
00160           std::cerr << "Error: " << character_name.c_str() << " will be probably misplaced!" << std::endl;
00161           std::cerr << std::endl;
00162 
00163             // Put it with no space...
00164           characters.back().PutRandomly(false, 0);
00165         }
00166       }
00167       characters.back().Init();
00168 
00169       MSG_DEBUG("team", "Add %s in team %s", character_name.c_str(), m_name.c_str());
00170 
00171         // C'est la fin ?
00172       ++it;
00173     } while (it!=nodes.end() && characters.size() < howmany );
00174 
00175     active_character = characters.begin();
00176 
00177   }
00178   catch (const xmlpp::exception &e)
00179   {
00180     std::cerr << std::endl
00181         << Format(_("Error loading team's data %s:"), m_id.c_str())
00182         << std::endl << e.what() << std::endl;
00183     return false;
00184   }
00185 
00186   return (characters.size() == howmany);
00187 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Team::LoadGamingData ( uint  howmany  ) 

Definition at line 366 of file team.cpp.

00367 {
00368   // Reset ammos
00369   m_nb_ammos.clear();
00370   m_nb_units.clear();
00371   std::list<Weapon *> l_weapons_list = Config::GetInstance()->GetWeaponsList()->GetList() ;
00372   std::list<Weapon *>::iterator itw = l_weapons_list.begin(),
00373   end = l_weapons_list.end();
00374 
00375   for (; itw != end ; ++itw) {
00376     m_nb_ammos[ (*itw)->GetName() ] = (*itw)->ReadInitialNbAmmo();
00377     m_nb_units[ (*itw)->GetName() ] = (*itw)->ReadInitialNbUnit();
00378   }
00379 
00380   // Disable non-working weapons in network games
00381   if(network.IsConnected())
00382   {
00383     m_nb_ammos[ Config::GetInstance()->GetWeaponsList()->GetWeapon(Weapon::WEAPON_NINJA_ROPE)->GetName() ] = 0;
00384     m_nb_ammos[ Config::GetInstance()->GetWeaponsList()->GetWeapon(Weapon::WEAPON_AIR_HAMMER)->GetName() ] = 0;
00385     m_nb_ammos[ Config::GetInstance()->GetWeaponsList()->GetWeapon(Weapon::WEAPON_BLOWTORCH)->GetName() ] = 0;
00386     m_nb_ammos[ Config::GetInstance()->GetWeaponsList()->GetWeapon(Weapon::WEAPON_SUBMACHINE_GUN)->GetName() ] = 0;
00387   }
00388 
00389   active_weapon = Config::GetInstance()->GetWeaponsList()->GetWeapon(Weapon::WEAPON_DYNAMITE);
00390   is_camera_saved = false;
00391 
00392   if (howmany == 0)
00393     LoadCharacters(nb_characters);
00394   else
00395     LoadCharacters(howmany);
00396 }

Here is the call graph for this function:

int Team::NbAliveCharacter (  )  const

Definition at line 249 of file team.cpp.

00250 {
00251   uint nbr = 0;
00252   const_iterator it= characters.begin(), end=characters.end();
00253 
00254   for (; it!=end; ++it)
00255     if ( !(*it).IsDead() ) nbr++;
00256 
00257   return nbr;
00258 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Team::NextCharacter (  ) 

Definition at line 227 of file team.cpp.

00228 {
00229   assert (0 < NbAliveCharacter());
00230   ActiveCharacter().StopPlaying();
00231   do
00232   {
00233     ++active_character;
00234     if (active_character == characters.end())
00235       active_character = characters.begin();
00236   } while (ActiveCharacter().IsDead());
00237   ActiveCharacter().StartPlaying();
00238 
00239   if (is_camera_saved) camera.SetXYabs (sauve_camera.x, sauve_camera.y);
00240   camera.FollowObject (&ActiveCharacter(),
00241                           !is_camera_saved, !is_camera_saved,
00242                           true);
00243   MSG_DEBUG("team", "%s (%d, %d)is now the active character",
00244             ActiveCharacter().GetName().c_str(),
00245             ActiveCharacter().GetX(),
00246             ActiveCharacter().GetY());
00247 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Team::PrepareTurn (  ) 

Definition at line 261 of file team.cpp.

00262 {
00263   // Get a living character if possible
00264   if (ActiveCharacter().IsDead())
00265   {
00266     is_camera_saved = false;
00267     NextCharacter();
00268   }
00269 
00270   if (is_camera_saved) camera.SetXYabs (sauve_camera.x, sauve_camera.y);
00271   camera.FollowObject (&ActiveCharacter(),
00272                           !is_camera_saved, !is_camera_saved,
00273                           true);
00274   CharacterCursor::GetInstance()->FollowActiveCharacter();
00275 
00276   // Active last weapon use if EnoughAmmo
00277   if (AccessWeapon().EnoughAmmo())
00278     AccessWeapon().Select();
00279   else { // try to find another weapon !!
00280     active_weapon = Config::GetInstance()->GetWeaponsList()->GetWeapon(Weapon::WEAPON_BAZOOKA);
00281     AccessWeapon().Select();
00282   }
00283 }

Here is the call graph for this function:

Here is the caller graph for this function:

uint Team::ReadEnergy (  ) 

Definition at line 194 of file team.cpp.

00195 {
00196   uint total_energy = 0;
00197 
00198   iterator it = characters.begin(), end = characters.end();
00199 
00200   for (; it != end; ++it) {
00201     if ( !(*it).IsDead() )
00202       total_energy += (*it).GetEnergy();
00203   }
00204 
00205   return total_energy;
00206 }

Here is the call graph for this function:

Here is the caller graph for this function:

int Team::ReadNbAmmos ( const std::string &  weapon_name  )  const

Definition at line 307 of file team.cpp.

00308 {
00309   // Read in the Map
00310   // The same method as in AccesNbAmmos can't be use on const team !
00311   std::map<std::string, int>::const_iterator it =
00312       m_nb_ammos.find( weapon_name );
00313 
00314   if (it !=  m_nb_ammos.end()) return ( it->second ) ;
00315   // We should not be here !
00316   MSG_DEBUG("team", "%s : not found into the ammo map.", weapon_name.c_str());
00317   assert(false);
00318   return 0 ;
00319 }

int Team::ReadNbAmmos (  )  const

Definition at line 297 of file team.cpp.

00298 {
00299   return ReadNbAmmos(active_weapon->GetName());
00300 }

Here is the call graph for this function:

Here is the caller graph for this function:

int Team::ReadNbUnits ( const std::string &  weapon_name  )  const

Definition at line 321 of file team.cpp.

00322 {
00323   std::map<std::string, int>::const_iterator it =
00324       m_nb_units.find( weapon_name );
00325 
00326   if (it !=  m_nb_units.end()) return ( it->second ) ;
00327   // We should not be here !
00328   MSG_DEBUG("team", "%s : not found into the ammo map.", weapon_name.c_str());
00329   assert(false);
00330   return 0 ;
00331 }

int Team::ReadNbUnits (  )  const

Definition at line 302 of file team.cpp.

00303 {
00304   return ReadNbUnits( active_weapon->GetName());
00305 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Team::Refresh (  ) 

Definition at line 421 of file team.cpp.

00422 {
00423   energy.Refresh();
00424 }

Here is the call graph for this function:

void Team::ResetNbUnits (  ) 

Definition at line 345 of file team.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void Team::SelectCharacter ( uint  index  ) 

Definition at line 218 of file team.cpp.

00219 {
00220   assert(index <= characters.size());
00221   ActiveCharacter().StopPlaying();
00222   active_character = characters.begin();
00223   for(uint i = 0; i < index; ++i)
00224     ++active_character;
00225 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Team::SetLocal (  ) 

Definition at line 456 of file team.cpp.

00457 {
00458   type_of_player = TEAM_human_local;
00459 }

Here is the caller graph for this function:

void Team::SetLocalAI (  ) 

Definition at line 461 of file team.cpp.

00462 {
00463   type_of_player = TEAM_ai_local;
00464 }

Here is the caller graph for this function:

void Team::SetNbCharacters ( uint  howmany  ) 

Definition at line 404 of file team.cpp.

00405 {
00406   assert(howmany >= 2 && howmany <= 10);
00407   nb_characters = howmany;
00408 }

Here is the caller graph for this function:

void Team::SetPlayerName ( const std::string &  player_name  ) 

Definition at line 410 of file team.cpp.

00411 {
00412   m_player_name = _player_name;
00413   // energy.SetTeamName(m_player_name+" - "+m_name);
00414 }

Here is the caller graph for this function:

void Team::SetRemote (  ) 

Definition at line 466 of file team.cpp.

00467 {
00468   type_of_player = TEAM_remote;
00469 }

Here is the caller graph for this function:

void Team::SetWeapon ( Weapon::Weapon_type  nv_arme  ) 

Definition at line 290 of file team.cpp.

00291 {
00292   AccessWeapon().Deselect();
00293   active_weapon = Config::GetInstance()->GetWeaponsList()->GetWeapon(type);
00294   AccessWeapon().Select();
00295 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Team::UnloadGamingData (  ) 

Definition at line 398 of file team.cpp.

00399 {
00400   // Clear list of characters
00401   characters.clear();
00402 }

void Team::UpdateEnergyBar (  ) 

Definition at line 208 of file team.cpp.

00209 {
00210   energy.SetValue(ReadEnergy());
00211 }

Here is the call graph for this function:


Member Data Documentation

iterator Team::active_character [private]

Definition at line 69 of file team.h.

Weapon* Team::active_weapon [private]

Definition at line 70 of file team.h.

std::list<Character> Team::characters [private]

Definition at line 68 of file team.h.

CrossHair Team::crosshair

Definition at line 56 of file team.h.

TeamEnergy Team::energy

Definition at line 59 of file team.h.

Surface Team::flag

Definition at line 57 of file team.h.

bool Team::is_camera_saved [private]

Definition at line 62 of file team.h.

std::string Team::m_id [private]

Definition at line 64 of file team.h.

std::string Team::m_name [private]

Definition at line 65 of file team.h.

std::map<std::string, int> Team::m_nb_ammos

Definition at line 52 of file team.h.

std::map<std::string, int> Team::m_nb_units

Definition at line 53 of file team.h.

std::string Team::m_player_name [private]

Definition at line 66 of file team.h.

std::string Team::m_sound_profile [private]

Definition at line 67 of file team.h.

std::string Team::m_teams_dir [private]

Definition at line 63 of file team.h.

uint Team::nb_characters [private]

Definition at line 71 of file team.h.

Point2i Team::sauve_camera

Definition at line 58 of file team.h.

team_player_type_t Team::type_of_player [private]

Definition at line 73 of file team.h.


The documentation for this class was generated from the following files:
Generated on Mon Jan 1 14:22:45 2007 for Wormux by  doxygen 1.4.7