BonusBox Class Reference

#include <bonus_box.h>

Inheritance diagram for BonusBox:

Inheritance graph
[legend]
Collaboration diagram for BonusBox:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 BonusBox ()
 ~BonusBox ()
void Draw ()
void Refresh ()

Static Public Member Functions

static void Enable (bool _enable)
static uint CountTeams ()
static bool NewBonusBox ()

Protected Member Functions

virtual void SignalCollision ()
void SignalGhostState (bool was_already_dead)

Private Member Functions

void ApplyBonus (Team &team, Character &character)
void PickRandomWeapon ()

Static Private Member Functions

static bool PlaceBonusBox (BonusBox &bonus_box)

Private Attributes

uint nbr_ammo
bool parachute
Spriteanim
Weapon::Weapon_type contents

Static Private Attributes

static bool enable = false

Detailed Description

Definition at line 32 of file bonus_box.h.


Constructor & Destructor Documentation

BonusBox::BonusBox (  ) 

Definition at line 48 of file bonus_box.cpp.

00049   : PhysicalObj("bonus_box"){
00050   SetTestRect (29, 29, 63, 6);
00051   m_allow_negative_y = true;
00052   enable = false;
00053 
00054   Profile *res = resource_manager.LoadXMLProfile( "graphism.xml", false);
00055   anim = resource_manager.LoadSprite( res, "objet/caisse");
00056   resource_manager.UnLoadXMLProfile(res);
00057 
00058   SetSize(anim->GetSize());
00059   anim->animation.SetLoopMode(false);
00060   anim->SetCurrentFrame(0);
00061 
00062   parachute = true;
00063 
00064   //these values will get read from XML soon
00065   life_points = 41;
00066   nbr_ammo = 3;
00067 
00068   SetSpeed (SPEED, M_PI_2);
00069   PickRandomWeapon();
00070 }

Here is the call graph for this function:

Here is the caller graph for this function:

BonusBox::~BonusBox (  ) 

Definition at line 72 of file bonus_box.cpp.

00072                    {
00073   delete anim;
00074 }


Member Function Documentation

void BonusBox::ApplyBonus ( Team team,
Character character 
) [private]

Definition at line 141 of file bonus_box.cpp.

00141                                                       {
00142   std::ostringstream txt;
00143     if(ActiveTeam().ReadNbAmmos(Config::GetInstance()->GetWeaponsList()->GetWeapon(contents)->GetName())!=INFINITE_AMMO) {
00144         equipe.m_nb_ammos[ Config::GetInstance()->GetWeaponsList()->GetWeapon(contents)->GetName() ] += nbr_ammo;
00145         txt << Format(ngettext(
00146                 "%s team has won %u %s!",
00147                 "%s team has won %u %ss!",
00148                 2),
00149             ActiveTeam().GetName().c_str(), nbr_ammo, Config::GetInstance()->GetWeaponsList()->GetWeapon(contents)->GetName().c_str());
00150     }
00151     else {
00152         txt << Format(gettext("%s team already has infinite ammo for the %s!"),
00153             ActiveTeam().GetName().c_str(), Config::GetInstance()->GetWeaponsList()->GetWeapon(contents)->GetName().c_str());
00154     }
00155   GameMessages::GetInstance()->Add (txt.str());
00156 }

Here is the call graph for this function:

Here is the caller graph for this function:

uint BonusBox::CountTeams (  )  [static]

Definition at line 171 of file bonus_box.cpp.

00171                           {
00172   uint nbr_teams=0;
00173   FOR_EACH_TEAM(team) { 
00174     nbr_teams++;
00175   }
00176   return nbr_teams;
00177 }

Here is the caller graph for this function:

void BonusBox::Draw (  )  [virtual]

Implements PhysicalObj.

Definition at line 76 of file bonus_box.cpp.

00077 {
00078   anim->Draw(GetPosition());
00079 }

Here is the call graph for this function:

void BonusBox::Enable ( bool  _enable  )  [static]

Definition at line 165 of file bonus_box.cpp.

00166 {
00167   MSG_DEBUG("bonus", "Enable ? %d", _enable);
00168   enable = _enable;
00169 }

Here is the caller graph for this function:

bool BonusBox::NewBonusBox (  )  [static]

Definition at line 185 of file bonus_box.cpp.

00186 {
00187 
00188   if (!enable) {
00189      enable=true;
00190     return false;
00191   }
00192   uint nbr_teams=CountTeams();
00193   if(nbr_teams<=1) {
00194         MSG_DEBUG("bonus", "There is less than 2 teams in the game");
00195     return false;
00196   }
00197   // .7 is a magic number to get the probability of boxes falling once every round close to .333
00198   double randValue = randomSync.GetDouble();
00199   if(randValue > (1-pow(.7,1.0/nbr_teams))) {
00200        return false;
00201   }
00202 
00203   BonusBox * box = new BonusBox();
00204   if (!PlaceBonusBox(*box)) {
00205     MSG_DEBUG("bonus", "Missed to put the bonus box");
00206     delete box;
00207   } else {
00208     lst_objects.AddObject(box);
00209     camera.FollowObject(box, true, true);
00210     GameMessages::GetInstance()->Add (_("Is it a gift?"));
00211     return true;
00212   }
00213 
00214   return false;
00215 }

Here is the call graph for this function:

Here is the caller graph for this function:

void BonusBox::PickRandomWeapon (  )  [private]

Definition at line 122 of file bonus_box.cpp.

00122                                 {
00123 
00124   int weapon_count = 0;
00125   int weapon_num = 0;
00126   WeaponsList::weapons_list_it it;
00127   for(it = Config::GetInstance()->GetWeaponsList()->GetList().begin(); it != Config::GetInstance()->GetWeaponsList()->GetList().end(); it++) {
00128     weapon_count++;
00129   }
00130   weapon_num = (int)randomSync.GetDouble(1,weapon_count);
00131   it = Config::GetInstance()->GetWeaponsList()->GetList().begin();
00132   int a=0;
00133   while(a < weapon_num && it != Config::GetInstance()->GetWeaponsList()->GetList().end()) {
00134     it++;
00135     a++;
00136   }
00137   contents = (*it)->GetType();
00138   std::cout<<"Out of "<<weapon_count<<" weapons, weapon "<<weapon_num<<" was selected."<<std::endl;
00139 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool BonusBox::PlaceBonusBox ( BonusBox bonus_box  )  [static, private]

Definition at line 179 of file bonus_box.cpp.

00180 {
00181   if (!bonus_box.PutRandomly(true, 0)) return false;
00182   return true;
00183 }

Here is the call graph for this function:

Here is the caller graph for this function:

void BonusBox::Refresh (  )  [virtual]

Implements PhysicalObj.

Definition at line 81 of file bonus_box.cpp.

00082 {
00083   // If we touch a character, we remove the bonus box
00084   FOR_ALL_LIVING_CHARACTERS(team, character)
00085   {
00086     if( ObjTouche(*character) )
00087     {
00088       // here is the gift (truly a gift ?!? :)
00089       ApplyBonus (**team, *character);
00090       Ghost();
00091       return;
00092     }
00093   }
00094 
00095   // Refresh animation
00096   if (!anim->IsFinished() && !parachute) anim->Update();
00097 }

Here is the call graph for this function:

void BonusBox::SignalCollision (  )  [protected, virtual]

Reimplemented from PhysicalObj.

Definition at line 100 of file bonus_box.cpp.

00101 {
00102   SetAirResistFactor(1.0);
00103 
00104   MSG_DEBUG("bonus", "End of the fall: parachute=%d", parachute);
00105   if (!parachute) return;
00106 
00107   MSG_DEBUG("bonus", "Start of the animation 'fold of the parachute'.");
00108   parachute = false;
00109 
00110   anim->SetCurrentFrame(0);
00111   anim->Start();
00112 }

Here is the call graph for this function:

void BonusBox::SignalGhostState ( bool  was_already_dead  )  [protected, virtual]

Reimplemented from Physics.

Definition at line 115 of file bonus_box.cpp.

00116 {
00117   if(life_points > 0) return;
00118   ParticleEngine::AddNow(GetCenter() , 10, particle_FIRE, true);
00119   ApplyExplosion(GetCenter(), GameMode::GetInstance()->bonus_box_explosion_cfg);
00120 }

Here is the call graph for this function:


Member Data Documentation

Sprite* BonusBox::anim [private]

Definition at line 39 of file bonus_box.h.

Weapon::Weapon_type BonusBox::contents [private]

Definition at line 41 of file bonus_box.h.

bool BonusBox::enable = false [static, private]

Definition at line 35 of file bonus_box.h.

uint BonusBox::nbr_ammo [private]

Definition at line 36 of file bonus_box.h.

bool BonusBox::parachute [private]

Definition at line 38 of file bonus_box.h.


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