Roguelike
 All Classes Namespaces Functions Variables Typedefs Friends Pages
Public Member Functions | Protected Attributes | List of all members
Character Class Reference

#include <character.h>

Inheritance diagram for Character:
Enemy Main_Character

Public Member Functions

 Character ()
 
 Character (std::vector< int > _stats, int _x, int _y, Tile _sprite, MiscType _corpse, int _chunk_x, int _chunk_y, int _depth, int _morality, int _speed)
 
 Character (int _x, int _y, int _chunk_x, int _chunk_y, int _depth)
 
void act (long ms)
 
bool is_alive () const
 
void take_damage (int damage)
 
void attack (Character *_chara)
 
int did_hit (Character *_chara)
 
int damage_dealt (Character *_chara)
 
std::vector< Item * > * get_inventory ()
 
std::vector< Item * > * get_equipment ()
 
void add_item (Item *new_item)
 
void drop_item (Item *item)
 
void drop_item (int item)
 
void destroy_item (Item *item)
 
void equip_item (Item *item)
 
void remove_item (int item)
 
void remove_all ()
 
int get_x ()
 
int get_y ()
 
IntPoint get_coords ()
 
IntPoint get_chunk ()
 
int get_chunk_x ()
 
int get_chunk_y ()
 
Tile get_char ()
 
Itemget_corpse ()
 
int get_depth ()
 
Characterget_target ()
 
int get_max_hp ()
 
int get_cur_hp ()
 
int get_moral ()
 
int get_armor_hit (int body_part, int type)
 
float get_armor_dam (int body_part, int type)
 
void set_x (int _x)
 
void set_y (int _y)
 
void set_chunk (IntPoint _chunk)
 
void set_chunk_x (int _chunk_x)
 
void set_chunk_y (int _chunk_y)
 
void set_depth (int)
 
void set_target (Character *_target)
 
void consume_item (Item *item)
 
int get_stat (int)
 
void set_stat (int stat, int amount)
 
int get_current_stat (int)
 
void set_current_stat (int stat, int amount)
 
void regain_consciousness ()
 
void pass_out ()
 
bool is_conscious ()
 
void reduce_endurance (int factor)
 
void gain_endurance (int factor)
 
bool can_act ()
 

Protected Attributes

int moral
 
std::vector< int > stats
 
std::vector< int > current_stats
 
int x
 
int y
 
std::vector< Item * > inventory
 
std::vector< Item * > equipment
 
int inventory_size
 
Tile sprite
 
Itemcorpse
 
int depth
 
IntPoint chunk
 
Charactertarget
 
bool conscious
 
long timer
 
int speed
 

Detailed Description

A class which is used to construct all characters in game. This is the class that acts as the base for all enemies, NPCs, the main character, and anything else that may be considered an enemy in the game.

Constructor & Destructor Documentation

Character::Character ( )

The default constructor.

Character::Character ( std::vector< int >  _stats,
int  _x,
int  _y,
Tile  _sprite,
MiscType  _corpse,
int  _chunk_x,
int  _chunk_y,
int  _depth,
int  _morality,
int  _speed 
)

The constructor for the character class. This is the constructor which is used to construct the enemy and main character derived classes.

Parameters
_statsThe stats to give the character.
_spriteThe sprite of the character.
_corpseThe corpse to be crated from the MiscType.
_moralityThe morality to give the character.
_xThe x value to give the character.
_yThe y value to give to the character.
_chunk_xThe x coordinate of the chunk to place the character.
_chunk_yThe y coordinate of the chunk to place the character.
_depthThe depth in the chunk to place the charcter.
Character::Character ( int  _x,
int  _y,
int  _chunk_x,
int  _chunk_y,
int  _depth 
)

The constructor for the character class. This is the constructor which is used to construct the enemy and main character derived classes.

Parameters
_xThe x value to give the character.
_yThe y value to give to the character.
_chunk_xThe x coordinate of the chunk to place the character.
_chunk_yThe y coordinate of the chunk to place the character.
_depthThe depth in the chunk to place the charcter.

Member Function Documentation

void Character::act ( long  ms)

Run the actions that happen to the character every frame.

void Character::add_item ( Item new_item)

Add an item to the character's inventory.

Parameters
new_itemThe item to place in the character's inventory.
void Character::attack ( Character _chara)

Reduces a given character's health by a certain amount. Damages another character by calling take_damage() on that character.

See also
take_damage(int damage)
current_stats
stats
bool Character::can_act ( )

Checks to see if the character is good to act!

void Character::consume_item ( Item item)

Consume an item based on the stats of that item. Checks to see if the item is consumable. If so, alter the appropriate stats based on the item's attributes.

Parameters
itemThe item to consume.
See also
Consumable
int Character::damage_dealt ( Character _chara)

Determines the amount of damage done by the attack. _chara The character being attacked.

Returns
The damage done.
void Character::destroy_item ( Item item)

Remove an item from the inventory and destroy the reference to it. This function IS memory safe, and will remove the pointer to the item. This means that there should no longer be ANY references to this object upon calling this function. If the item is not found in the inventory, nothing will happen.

Parameters
itemThe item to destroy.
int Character::did_hit ( Character _chara)

Determines whether or not the attack hit the character. _chara The character being attacked.

Returns
-1 If missed, otherwise the index of the body part hit.
void Character::drop_item ( Item item)

Remove an item from the character's inventory. This function is NOT memory safe, and only remove's the pointer to the item, it does not delete the item. The item should always be asisgned somewhere else (in the case of this function, it should be in the chunk). If the item passed in is not in the inventory, nothing will happen.

Parameters
itemThe item to remove from the inventory.
void Character::drop_item ( int  item)

Remove an item from the character's inventory by index. Behaves the same as add_item(Item* new_item)

See also
add_item(Item* new_item)
void Character::equip_item ( Item item)

Moves an item from the inventory to the equipment. Checks if it is possible to equip or wield the item. If so, it checks the equipment slot that item should go into and places it in that slot. If an item is already equipped, it will remove it from the equipment. The armor or attack is updated based on the item's stats.

Parameters
itemTHe item which will be equipped.
See also
equipment
remove_item(int item)
Item
void Character::gain_endurance ( int  factor)

Gains endurance based on the factor.

float Character::get_armor_dam ( int  body_part,
int  type 
)

Public accessor for the armor. Gets the damage reduction of the armor.

int Character::get_armor_hit ( int  body_part,
int  type 
)

Public accessor for the armor. Gets the hit resistance value of the armor.

Tile Character::get_char ( )

Public accessor for the sprite.

Returns
Member variable sprite.
See also
sprite
IntPoint Character::get_chunk ( )

Public accessor for the chunk coordinates.

Returns
Member variable chunk.
See also
chunk
int Character::get_chunk_x ( )

Public accessor for the x component of the chunk.

Returns
Column component of chunk.
See also
chunk
int Character::get_chunk_y ( )

Public accessor for the y component of the chunk.

Returns
Row component of chunk.
See also
chunk
IntPoint Character::get_coords ( )

Public accessor or the coordinates.

Returns
IntPoint containing y, x.
Item * Character::get_corpse ( )

Public accessor for the corpse.

Returns
Member variable corpse.
See also
corpse
int Character::get_cur_hp ( )

Public accessor for the current health. Current health corresponds to current_stats[HEALTH].

Returns
Member variable current_stats[HEALTH].
See also
current_stats
int Character::get_current_stat ( int  stat)

Public getter for accessing a stat value.

Parameters
statThe index value of the stat to access.
Returns
The current value of that stat from the array current_stats.
See also
current_stats
int Character::get_depth ( )

Public accessor for the depth.

Returns
Member variable depth.
See also
depth
vector< Item * > * Character::get_equipment ( )

Public access function for the character's equipment.

Returns
The character's equipment.
See also
equipment
vector< Item * > * Character::get_inventory ( )

Public access function for the character's inventory.

Returns
The character's inventory.
See also
inventory
int Character::get_max_hp ( )

Public accessor for the max health. Max health corresponds to stats[HEALTH].

Returns
Member variable stats[HEALTH].
See also
stats
int Character::get_moral ( )

Public accessor for the moral member variable.

Returns
Member variable moral.
See also
moral
int Character::get_stat ( int  stat)

Public getter for accessing a current stat value.

Parameters
statThe index value of the stat to access.
Returns
The current value of that stat from the array stats.
See also
stats
Character * Character::get_target ( )

Public accessor for the target.

Returns
Member variable target.
See also
target
int Character::get_x ( )

Public accessor for the x coordinate.

Returns
Member variable x.
See also
x
int Character::get_y ( )

Public accessor for the y coordinate.

Returns
Member variable y.
See also
y
bool Character::is_alive ( ) const

A check to see whether or not the character is alive.

Returns
True if the character's current health is > 0, otherwise false.
See also
current_stats, stats
bool Character::is_conscious ( )

Returns whether or not the character is conscious.

void Character::pass_out ( )

Sets conscious to false.

void Character::reduce_endurance ( int  factor)

Reduces the current endurance of the character by a factor. The amount passed in indicates what factor the endurance should be reduced by (e.g. walking reduces the endurance by 1, which will be multiplied by something to reduce endurance).

void Character::regain_consciousness ( )

Sets conscious to true.

void Character::remove_all ( )

Removes all equipment.

void Character::remove_item ( int  item)

Removes an item from the equipment by index. If there is an item equipped, it will remove it.

Parameters
itemThe index of the item to be removed.
void Character::set_chunk ( IntPoint  _chunk)

Public setter for the chunk.

Parameters
_chunkNew set of chunk coordinates.
See also
chunk
void Character::set_chunk_x ( int  _chunk_x)

Public setter for the x component of chunk.

Parameters
_chunk_xNew x component of the chunk.
See also
chunk
void Character::set_chunk_y ( int  _chunk_y)

Public setter for the y component of chunk.

Parameters
_chunk_yNew y component of the chunk.
See also
chunk
void Character::set_current_stat ( int  stat,
int  amount 
)

Public setter for setting a stat value.

Parameters
statThe index value of the stat to set.
amountThe value the stat should be set to.
See also
stats
void Character::set_depth ( int  d)

Public setter for the depth.

Parameters
dNew depth.
See also
depth
void Character::set_stat ( int  stat,
int  amount 
)

Public setter for setting a current stat value.

Parameters
statThe index value of the stat to set.
amountThe value the stat should be set to.
See also
current_stats
void Character::set_target ( Character _target)

Public setter for the target.

Parameters
_targetNew target.
See also
target
void Character::set_x ( int  _x)

Public setter for the x coordinate.

Parameters
_xNew x coordinate.
See also
x
void Character::set_y ( int  _y)

Public setter for the y coordinate.

Parameters
_yNew y coordinate.
See also
y
void Character::take_damage ( int  damage)

Reduces the character's current health by a given amount.

Parameters
damageThe amount to reduce the character's health by.
See also
current_stats
stats

Member Data Documentation

IntPoint Character::chunk
protected

An IntPoint object of the character's coordinates in the chunk_map.

bool Character::conscious
protected

Whether or not the character is conscious.

Item* Character::corpse
protected

An item representing the body of the character. An item that is completely separate from the inventory that is droppped onto the map upon the death of the character. Because it will always be moved to the chunk object before destructing the character, it does not need to be deleted by the character.

std::vector<int> Character::current_stats
protected

A vector representing the current stats of a character. Whenever one of the player's stats temporarily changes, as in a lowering or raising of health, or lowering or raising of another stat, it will be held in this vector.

int Character::depth
protected

The depth the character is in the chunk.

std::vector<Item*> Character::equipment
protected

A vector representing the character's equipment. This will be "statically" sized, and certain indices represent certain item slots, e.g. head

std::vector<Item*> Character::inventory
protected

A vector representing the character's current inventory.

int Character::inventory_size
protected

An integer representing the maximum size of a characters inventory.

Todo:
Implement this so that character's cannot carry more than their inventory.
int Character::moral
protected

A protected spectrum ranging from 0-5. Morality acts as the basis for whether or not characters will attack each other, i.e. characters with 0 will attack characters with 5.

Todo:
Make this an enum.
int Character::speed
protected

How quickly the character moves. Represents the threshold for how many milliseconds must pass before the character can act.

See also
timer
Tile Character::sprite
protected

How the character will appear in the game.

std::vector<int> Character::stats
protected

A vector representation of the stats of a character. All of the stats of a character (health, armor, strength, etc. will be held in this vector.

Character* Character::target
protected

What the character is currently focused on. For the main character, this will primarily be to display information about the enemy or NPC that they are focused on. For non-players characters (both enemies and NPCs, this will act as a continuous representation of their focus.

long Character::timer
protected

The current timer of the character.

int Character::x
protected

The character's coordinate in the x direction.

int Character::y
protected

The character's coordinates in the y direction.


The documentation for this class was generated from the following files: