Actor Struct Reference

List of all members.


Detailed Description

a class for all the actors in the game.

Definition at line 180 of file main.cpp.


Public Member Functions

 Actor (const char *name="Undefined", int hp=0, int ap=0, int dp=0, long xp=0, long gold=0, long level=1)
 constructor - just initializes all members
bool deal_damage (Actor *target)
 a basic attack function.
void defense_down ()
 decrease the current defense by one, will not drop below zero
void defense_up ()
 increase the current defense by one, will not exceed the maximum defense
void get_rewards_from (Actor *source)
 get the gold and experience from the source actor, and handle leveling by calling the Actor::level_up() method
void heal (int amount)
 adds amount to the current health points, and does not allow it to go over the maximum health
void level_up ()
 level-up the actor
void show_status ()
 outputs the actor's properties on stdout
void take_damage (int amount)
 subtracts amount from the current health points, and does not allow it to go below zero
void taunt (Actor *target)
 taunt the target actor taunting the target has a 30% chance that the target will get scared and drop its defense

Public Attributes

int ap_
 how much attack power it currently has
int dp_
 how much defense power it currently has
long gold_
 how much gold it has
int hp_
 how much health it currently has
long level_
 what its current skill level is
int maxap_
 how much attack power it can ever have
int maxdp_
 how much defense power it can ever have
int maxhp_
 how much health it can ever have
string name_
 what it is called
long xp_
 how much experience it has

Constructor & Destructor Documentation

Actor::Actor ( const char *  name = "Undefined",
int  hp = 0,
int  ap = 0,
int  dp = 0,
long  xp = 0,
long  gold = 0,
long  level = 1 
)

constructor - just initializes all members

Definition at line 213 of file main.cpp.

00213                                                                                                                           :
00214         name_(name),
00215         hp_(hp),
00216         ap_(ap),
00217         dp_(dp),
00218         maxhp_(hp),
00219         maxap_(ap),
00220         maxdp_(dp),
00221         xp_(xp),
00222         gold_(gold),
00223         level_(level)
00224     {
00225     }


Member Function Documentation

bool Actor::deal_damage ( Actor target  ) 

a basic attack function.

  • basic attack is abs((target.dp * target.level) - (self.ap * self.level))
  • critical attack adds 20% more damage to the basic attack
  • you can only deal a critical attack when you have full hp
  • there is a 10% chance that you will deal a critical blow
    Returns:
    true if the blow was critical
    Parameters:
    target - a pointer to an actor to deal the damage to

Definition at line 256 of file main.cpp.

00257     {
00258         bool critical = false;
00259         int amount = (int)abs((target->dp_ * target->level_) - (dp_ * level_));
00260 
00261         if (hp_ == maxhp_)
00262         {
00263             int criticalchance = 1 + rand() % 99;
00264             if (criticalchance >= 1 && criticalchance <= 10)
00265             {
00266                 int criticalbonus = (int)(0.2f * (float)amount);
00267                 amount += criticalbonus;
00268                 if (amount > 0)
00269                 {
00270                     critical = true;
00271                 }
00272             }
00273         }
00274 
00275         if (amount <= 0)
00276         {
00277             cout << INDENT << "The " << name_ << " attacked the " << target->name_ << " and missed!" << BR;
00278         }
00279         else
00280         {
00281             cout << INDENT << "The " << name_ << " attacked the " << target->name_ << " and dealt " << amount << " damage!" << BR;
00282         }
00283 
00284         target->take_damage(amount);
00285 
00286         return critical;
00287     }

Here is the call graph for this function:

void Actor::defense_down (  ) 

decrease the current defense by one, will not drop below zero

Definition at line 339 of file main.cpp.

00340     {
00341         cout << INDENT << "The " << name_ << " dropped it's defenses..." << BR;
00342         if (--dp_ <= 0)
00343         {
00344             dp_ = 0;
00345             cout << INDENT << "*** DEFENSELESS! ***" << BR;
00346         }
00347     }

void Actor::defense_up (  ) 

increase the current defense by one, will not exceed the maximum defense

Definition at line 328 of file main.cpp.

00329     {
00330         cout << INDENT << "The " << name_ << " powers up it's defenses..." << BR;
00331         if (++dp_ > maxdp_)
00332         {
00333             dp_ = maxdp_;
00334             cout << INDENT << "*** MAXIMUM DEFENSE! ***" << BR;
00335         }
00336     }

void Actor::get_rewards_from ( Actor source  ) 

get the gold and experience from the source actor, and handle leveling by calling the Actor::level_up() method

Parameters:
source - a pointer to an actor that has the spoils to be plundered

Todo:
fix level up to use a growth rate table - currently leveling is a 45% chance

Definition at line 355 of file main.cpp.

00356     {
00357         gold_ += source->gold_;
00358         xp_ += source->xp_;
00359 
00361         int levelchance = 1 + rand() % 99;
00362         if (levelchance >= 1 && levelchance <= 45)
00363         {
00364             level_up();
00365         }
00366     }

Here is the call graph for this function:

void Actor::heal ( int  amount  ) 

adds amount to the current health points, and does not allow it to go over the maximum health

Parameters:
amount - how much to try to add to the current health

Definition at line 241 of file main.cpp.

00242     {
00243         hp_ += amount;
00244         hp_ = (hp_ > maxhp_) ? maxhp_ : hp_; // keep hp from going over maximum hp
00245     }

void Actor::level_up (  ) 

level-up the actor

  • current hp, ap, and dp are replenished to maximum
  • three dice are rolled to determine the level-up bonuses
  • can gain anywhere between 10 and 30 maximum health
  • can gain anywhere between 1 and 10 maximum attack power
  • can gain anywhere between 1 and 10 maximum defense power
  • 5% chance of gaining a super bonus multiplier of X2 to all stats

Definition at line 377 of file main.cpp.

00378     {
00379         if (++level_ > 100)
00380         {
00381             level_ = 100;
00382             cout << INDENT << HR << "*** REACHED MAXIMUM LEVEL! ***" << HR;
00383             return;
00384         }
00385 
00386         cout << INDENT << "The " << name_ << " has gained a level!" << BR;
00387 
00388         // handle the 5% chance for a super bonus X2 multiplier
00389         bool superbonus = false;
00390         int superbonuschance = 1 + rand() % 99;
00391         if (superbonuschance >= 1 && superbonuschance <= 5)
00392         {
00393             superbonus = true;
00394         }
00395 
00396         // roll the dice
00397         int d1 = 10 + roll_die(20);
00398         int d2 = 1 + roll_die(10);
00399         int d3 = 1 + roll_die(10);
00400 
00401         // apply bonuses
00402         maxhp_ += (superbonus) ? d1 * 2 : d1;
00403         maxap_ += (superbonus) ? d2 * 2 : d2;
00404         maxdp_ += (superbonus) ? d3 * 2 : d3;
00405 
00406         // replenish stats
00407         hp_ = maxhp_;
00408         ap_ = maxap_;
00409         dp_ = maxdp_;
00410 
00411         cout
00412             << HR
00413             << INDENT << "* Maximum Health increased by " << d1 << BR
00414             << INDENT << "* Maximum Attack Power increased by " << d2 << BR
00415             << INDENT << "* Maximum Defense Power increased by " << d3 << BR
00416             << INDENT << "* Health, Attack Power, and Defense Power Replenished!" << BR
00417             << HR;
00418     }

Here is the call graph for this function:

void Actor::show_status (  ) 

outputs the actor's properties on stdout

Definition at line 290 of file main.cpp.

00291     {
00292         cout
00293             << HR
00294             << INDENT << "CHARACTER STATUS INFORMATION" << BR
00295             << HR
00296             << INDENT << "Name: " << name_ << BR
00297             << INDENT << "HP: " << hp_ << "/" << maxhp_ << BR
00298             << INDENT << "AP: " << ap_ << "/" << maxap_ << BR
00299             << INDENT << "DP: " << dp_ << "/" << maxdp_ << BR
00300             << INDENT << "L" << level_ << INDENT << xp_ << "XP" << BR
00301             << INDENT << "$" << gold_ << BR
00302             << HR;
00303     }

void Actor::take_damage ( int  amount  ) 

subtracts amount from the current health points, and does not allow it to go below zero

Parameters:
amount - how much health to try to take from current health

Definition at line 231 of file main.cpp.

00232     {
00233         hp_ -= amount;
00234         hp_ = (hp_ < 0) ? 0 : hp_; // keep hp from going below zero
00235     }

void Actor::taunt ( Actor target  ) 

taunt the target actor taunting the target has a 30% chance that the target will get scared and drop its defense

Parameters:
target - a pointer to an actor to taunt

Definition at line 310 of file main.cpp.

00311     {
00312         cout << INDENT << "The " << name_ << " taunts the " << target->name_ << "..." << BR;
00313 
00314         int scarechance = 1 + rand() % 99;
00315         if (scarechance >= 1 && scarechance <= 30)
00316         {
00317             // target is scared
00318             cout << INDENT << "The " << target->name_ << " was frightened!" << BR;
00319             target->defense_down();
00320         }
00321         else
00322         {
00323             cout << INDENT << "The " << target->name_ << " is not affected." << BR;
00324         }
00325     }

Here is the call graph for this function:


Member Data Documentation

how much attack power it currently has

Definition at line 189 of file main.cpp.

how much defense power it currently has

Definition at line 192 of file main.cpp.

how much gold it has

Definition at line 207 of file main.cpp.

how much health it currently has

Definition at line 186 of file main.cpp.

what its current skill level is

Definition at line 210 of file main.cpp.

how much attack power it can ever have

Definition at line 198 of file main.cpp.

how much defense power it can ever have

Definition at line 201 of file main.cpp.

how much health it can ever have

Definition at line 195 of file main.cpp.

string Actor::name_

what it is called

Definition at line 183 of file main.cpp.

long Actor::xp_

how much experience it has

Definition at line 204 of file main.cpp.


The documentation for this struct was generated from the following file:

Generated on Sat Aug 29 17:55:33 2009 for Simple Battle by  doxygen 1.5.5