WeaponsList Class Reference

#include <weapons_list.h>

List of all members.

Public Types

typedef std::list< Weapon * > weapons_list_type
typedef std::list< Weapon
* >::iterator 
weapons_list_it

Public Member Functions

 WeaponsList ()
 ~WeaponsList ()
void Init ()
void Refresh ()
weapons_list_typeGetList ()
WeaponGetWeapon (Weapon::Weapon_type type)
bool GetWeaponBySort (uint num_sort, Weapon::Weapon_type &type)

Private Types

typedef std::multimap< uint,
Weapon * >::value_type 
keybind
typedef std::multimap< uint,
Weapon * >::iterator 
weapons_map_it

Private Member Functions

void AddToList (Weapon *arme, uint num_sort)
WeaponGetNextWeapon (uint sort, uint index)

Private Attributes

weapons_list_type m_weapons_list
std::multimap< uint, Weapon * > m_weapons_map


Detailed Description

Definition at line 32 of file weapons_list.h.


Member Typedef Documentation

typedef std::multimap<uint, Weapon*>::value_type WeaponsList::keybind [private]

Definition at line 43 of file weapons_list.h.

typedef std::list<Weapon*>::iterator WeaponsList::weapons_list_it

Definition at line 36 of file weapons_list.h.

typedef std::list<Weapon*> WeaponsList::weapons_list_type

Definition at line 35 of file weapons_list.h.

typedef std::multimap<uint, Weapon*>::iterator WeaponsList::weapons_map_it [private]

Definition at line 44 of file weapons_list.h.


Constructor & Destructor Documentation

WeaponsList::WeaponsList (  ) 

Definition at line 61 of file weapons_list.cpp.

00062 {
00063   weapons_res_profile = resource_manager.LoadXMLProfile( "weapons.xml", false);
00064   Bazooka* bazooka = new Bazooka;
00065   SubMachineGun* submachine_gun = new SubMachineGun;
00066   Gun* gun = new Gun;
00067   Shotgun* shotgun = new Shotgun;
00068   SnipeRifle* snipe_rifle = new SnipeRifle;
00069   RiotBomb* riot_bomb = new RiotBomb;
00070   AutomaticBazooka* auto_bazooka = new AutomaticBazooka;
00071   Dynamite* dynamite = new Dynamite;
00072   GrenadeLauncher* grenade_launcher = new GrenadeLauncher;
00073   DiscoGrenadeLauncher* disco_grenade_launcher = new DiscoGrenadeLauncher;
00074   ClusterLauncher* cluster_launcher = new ClusterLauncher;
00075   Baseball* baseball = new Baseball;
00076   Mine* mine = new Mine;
00077   AirAttack* air_attack = new AirAttack;
00078   AnvilLauncher* anvil = new AnvilLauncher;
00079   TuxLauncher* tux = new TuxLauncher;
00080   GnuLauncher* gnu_launcher = new GnuLauncher;
00081   PolecatLauncher* polecat_launcher = new PolecatLauncher;
00082   BounceBallLauncher* bounce_ball_launcher = new BounceBallLauncher;
00083   Teleportation* teleportation = new Teleportation;
00084   Parachute* parachute = new Parachute;
00085   Suicide* suicide = new Suicide;
00086   SkipTurn* skipturn = new SkipTurn;
00087   JetPack* jetpack = new JetPack;
00088   Airhammer* airhammer = new Airhammer;
00089   Construct* construct = new Construct;
00090   LowGrav* lowgrav = new LowGrav;
00091   NinjaRope* ninjarope = new NinjaRope;
00092   Blowtorch* blowtorch = new Blowtorch;
00093   Syringe* syringe = new Syringe;
00094 
00095   // Category 1
00096   AddToList(bazooka, 1);
00097   AddToList(submachine_gun, 1);
00098   AddToList(snipe_rifle, 1);
00099   AddToList(gun, 1);
00100   AddToList(shotgun, 1);
00101   AddToList(riot_bomb, 1);
00102   AddToList(auto_bazooka, 1);
00103 
00104   // Category 2
00105   AddToList(dynamite,2);
00106   AddToList(grenade_launcher, 2);
00107   AddToList(cluster_launcher, 2);
00108   AddToList(disco_grenade_launcher, 2);
00109   AddToList(mine,2);
00110 
00111   // Category 3
00112   AddToList(baseball, 3);
00113   AddToList(syringe,3);
00114   AddToList(tux,3);
00115   AddToList(gnu_launcher,3);
00116   AddToList(polecat_launcher,3);
00117   AddToList(air_attack,3);
00118   AddToList(anvil,3);
00119   AddToList(bounce_ball_launcher,3);
00120 
00121   // Category 4
00122   AddToList(ninjarope,4);
00123   AddToList(jetpack,4);
00124   AddToList(parachute,4);
00125   AddToList(teleportation,4);
00126   AddToList(lowgrav,4);
00127 
00128   // Category 5
00129   AddToList(skipturn,5);
00130   AddToList(airhammer,5);
00131   AddToList(construct,5);
00132   AddToList(blowtorch,5);
00133   AddToList(suicide,5);
00134 }

Here is the call graph for this function:

WeaponsList::~WeaponsList (  ) 

Definition at line 38 of file weapons_list.cpp.

00039 {
00040   weapons_list_it it=m_weapons_list.begin(), end=m_weapons_list.end();
00041   for (; it != end; ++it)
00042   {
00043     delete *it;
00044   }
00045 }


Member Function Documentation

void WeaponsList::AddToList ( Weapon arme,
uint  num_sort 
) [private]

Definition at line 49 of file weapons_list.cpp.

00050 {
00051   // insert the pointer
00052   m_weapons_list.push_back(arme);
00053 
00054   m_weapons_map.insert(keybind(num_sort, arme));
00055 
00056   Interface::GetInstance()->weapons_menu.NewItem(arme,num_sort);
00057 }

Here is the call graph for this function:

Here is the caller graph for this function:

WeaponsList::weapons_list_type & WeaponsList::GetList (  ) 

Definition at line 145 of file weapons_list.cpp.

00146 {
00147   return m_weapons_list;
00148 }

Here is the caller graph for this function:

Weapon * WeaponsList::GetNextWeapon ( uint  sort,
uint  index 
) [private]

Definition at line 152 of file weapons_list.cpp.

00153 {
00154         uint n = m_weapons_map.count(sort);
00155         index = index % n;  // index can't be greater than number of weapons
00156         weapons_map_it it = m_weapons_map.lower_bound(sort);
00157 
00158         if(index + 1 < n)
00159         {
00160                 for(uint i=0; i < index + 1; i++)
00161                         it++;
00162         }
00163 
00164         return it->second;
00165 }

Here is the caller graph for this function:

Weapon * WeaponsList::GetWeapon ( Weapon::Weapon_type  type  ) 

Definition at line 217 of file weapons_list.cpp.

00218 {
00219   weapons_list_it it;
00220   it = std::find_if(m_weapons_list.begin(), m_weapons_list.end(), test_weapon_type(type));
00221   assert (it != m_weapons_list.end());
00222   return *it;
00223 }

Here is the caller graph for this function:

bool WeaponsList::GetWeaponBySort ( uint  num_sort,
Weapon::Weapon_type type 
)

Definition at line 169 of file weapons_list.cpp.

00170 {
00171   uint nb_weapons = m_weapons_map.count(sort);
00172   if (nb_weapons == 0) return false;
00173 
00174   // One or many weapons on this key
00175   std::pair<weapons_map_it, weapons_map_it> p = m_weapons_map.equal_range(sort);
00176   weapons_map_it it = p.first, end = p.second;
00177 
00178   Weapon* next_weapon = it->second;
00179 
00180   if (nb_weapons > 1)
00181     {
00182         // Find index of current weapon
00183         uint current_weapon;
00184         for(current_weapon=0; current_weapon < nb_weapons-1; current_weapon++, it++)
00185         {
00186                 if(it->second == &(ActiveTeam().GetWeapon()))
00187                         break;
00188         }
00189 
00190         // Get next weapon that has enough ammo and can be used on the map
00191         uint i = 0;
00192         do
00193         {
00194                 next_weapon = GetNextWeapon(sort, current_weapon++);
00195         } while(i++ < nb_weapons && (ActiveTeam().ReadNbAmmos(next_weapon->GetName()) == 0 || !(next_weapon->CanBeUsedOnClosedMap() || ActiveMap().IsOpened())));
00196         // this corresponds to:  while (stop-condition && (not-enoughammo || not-usable-on-map))
00197 
00198         // no right weapon has been found
00199         if(i > nb_weapons)
00200                 return false;
00201     }
00202 
00203   type = next_weapon->GetType();
00204   return true;
00205 }

Here is the call graph for this function:

void WeaponsList::Init (  ) 

void WeaponsList::Refresh (  ) 

Definition at line 138 of file weapons_list.cpp.

00139 {
00140   ActiveTeam().AccessWeapon().Manage();
00141 }

Here is the call graph for this function:


Member Data Documentation

weapons_list_type WeaponsList::m_weapons_list [private]

Definition at line 39 of file weapons_list.h.

std::multimap<uint, Weapon*> WeaponsList::m_weapons_map [private]

Definition at line 42 of file weapons_list.h.


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