#include <enemy.h>
Public Member Functions | |
Enemy () | |
Enemy (int _x, int _y, int _chunk_x, int _chunk_y, int _depth, EnemyType enemy) | |
void | run_ai (TilePointerMatrix &surroundings, IntPoint sur_chunk, IntPoint sur_coords, std::vector< Character * > char_list, long delta_ms) |
bool | validate_target () |
void | aggressive_ai (TilePointerMatrix &, IntPoint sur_chunk, IntPoint sur_coords, std::vector< Character * > char_list, long delta_ms) |
void | passive_ai (TilePointerMatrix &surroundings, IntPoint sur_chunk, IntPoint sur_coords, std::vector< Character * > char_list, long delta_ms) |
int | get_sight () |
int | get_id () |
void | dump_matrix (TilePointerMatrix &map, IntPoint tl, IntPoint br) |
std::vector< IntPoint > | sight_tiles () |
![]() | |
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 () |
Item * | get_corpse () |
int | get_depth () |
Character * | get_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 Member Functions | |
std::vector< Equipment * > | generate_equipment (std::vector< EquipType > equipment_list) |
Weapon * | generate_weapon (std::vector< WeaponType >) |
void | move (int x_change, int y_change) |
IntPoint | get_next_step (IntPoint goal, TilePointerMatrix &surroundings, IntPoint cur_coords) |
int | is_in (IntPoint point, std::vector< ATile > list) |
std::vector< IntPoint > | a_star (IntPoint start, IntPoint goal, TilePointerMatrix &surroundings) |
int | manhattan (IntPoint, IntPoint) |
int | get_smallest_f (std::vector< ATile > &list) |
IntPoint | get_sur_coords (IntPoint sur_chunk, IntPoint sur_coords, IntPoint _chunk, IntPoint _coords) |
Character * | find_best_target (int target_id, int selectability, std::vector< Character * > enemy_list) |
Character * | passive_best_target (int target_id, int selectability, std::vector< Character * > enemy_list) |
IntPoint | get_spooked (IntPoint abs_coords, IntPoint target_abs) |
bool | in_sight_range (IntPoint _coords, IntPoint _chunk) |
bool | in_sight (IntPoint _coords, IntPoint _chunk) |
void | turn (IntPoint coords) |
IntPoint | get_fov () |
Protected Attributes | |
int | id |
int | sight |
int | direction |
int | view |
bool | spooked |
IntPoint | direction_spooked |
int | time_spooked |
std::string | name |
![]() | |
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 |
Item * | corpse |
int | depth |
IntPoint | chunk |
Character * | target |
bool | conscious |
long | timer |
int | speed |
Private Types | |
typedef std::vector < std::vector< Tile * > > | TilePointerMatrix |
The enemy class. The primary antagonists of the game. A class which will randomly spawn and attempt to kill or assist the main character. Right now it's a fairly simple class, but it should become increasingly complex as we go.
Enemy::Enemy | ( | ) |
The default constructor.
Enemy::Enemy | ( | int | _x, |
int | _y, | ||
int | _chunk_x, | ||
int | _chunk_y, | ||
int | _depth, | ||
EnemyType | enemy | ||
) |
The constructor for the enemy class.
|
protected |
A pathfinding algorithm. This calculates the best path between two coordinates on a given array of tiles using the a* algorithm. This is done by keeping track of an "open" and a "closed" list of tiles. The open list represents tiles that could potentially be looked at, and the closed list is a list of tiles that have already been looked at.
The current tile is the tile that is currently being considered, and every tile around it is added to the open list, assuming that those tiles can be moved through and are not on the closed list. Each tile added to the open list is given a g, h, and f score, and the curren tile becomes the parent. G represents the distance from the start point to the tile, h (standing for heuristic) is a measure from the tile to the goal, and f = h + g. If a tile is on the open list, then f is recalculated for the current tile. If it is lower, then the current tile becomes the new parent.
Each loop, the current tile is the one on the open list with the shortest f score. If the goal is on the open list, or the open list is empty, then the algorithm is stopped. See the source for further documentation.
start | The starting point for the algorithm. |
goal | The place the enemy is trying to get to. |
surroundings | The surroundings within the sight of the enemy. |
void Enemy::aggressive_ai | ( | TilePointerMatrix & | surroundings, |
IntPoint | sur_chunk, | ||
IntPoint | sur_coords, | ||
std::vector< Character * > | char_list, | ||
long | delta_ms | ||
) |
The ai for the aggressive enemies. The AI searches for a target (find_best_target()) and moves towards that target. If it is next to the target, it will attack it. If no target is found, it will move randomly.
surroundings | The tiles around the enemy. |
sur_chunk | The chunk of the surrounding coords. |
sur_coords | The coordinates of the surrounding tilematrix. |
char_list | The list of characters the enemy can see. |
delta_ms | The change in millisenconds since the last time ai was called. |
A debugging function. Dumps the paths to cout as they are calculated by a-star. Only enable if a-star is not working propery or if you like seeing the a-star algrorithm work. Or if you like massive dumps to cout. Alternatively, you can use it to dump a different matrix.
map | The matrix to dump. |
tl | The top left corner of the area to dump. |
br | The bottom right corner of the area to dump. |
|
protected |
Finds a target for non-passive enemies. Finds the best target to act on by searching for the character with the closest morality to the target_id.
target_id | The target morality that the enemy is looking for. |
selectability | The range that the morality can fall within. |
enemy_list | The list of enemies to check. |
|
protected |
Generates the equipment from a list of EquipType. Loops through a list of possible equipment that an enemy can have, and the returned list goes into the inventory.
equipment_list | A list of possible equipment that the enemy can have. |
|
protected |
Generates the weapon from a list of WeaponType. Loops through a list of possible weapons that an enemy can have, and the returned weapon goes into the inventory.
Make the enemy equip the weapon.
Posbbily make this multiple weapons and have it pick the best one.
weapon_list | A list of possible weapons that the enemy can have. |
|
protected |
Calculates the upper and lower angles (from 1-100) of the field of view.
int Enemy::get_id | ( | ) |
|
protected |
Determines the best next move to make to reach a goal. This function loods at the current coordinates, the coordinates of the goal, and surroundings, and decides what the next move on the shortest path is to reach that goal.
goal | THe coordinates of the goal to reach |
surroundings | A matrix of the tiles surrounding the enemy. |
cur_coords | The current coordinates in the surroundings matrix. |
int Enemy::get_sight | ( | ) |
Public accessor for the sight.
|
protected |
Returns the ATile with the smallest f value. A helper fucntion for the a-star algorithm which finds the smallest f-value.
A | reference to a list of ATiles. |
Gets the direction that an enemy should be spooked. Takes in a chunk and coordinates in the direction of the spooker, and calculates the direction to run away from the the spooker.
abs_coords | The absolute coordinates of the spook-e. |
target_abs | The absolute coordinates of the spooker. |
|
protected |
Converts chunk/coords into the enemies surroundings coordinates. Converts the passed in chunk/coordinates to absolute coordinates, and then subtracts that from the top right of the enemy's line of sight, givng coordinates relative to the enemy's LOS.
_chunk | The chunk of the object to be converted. |
_coords | The coords of the object to be converted. |
sur_chunk | The chunk of top left corner of the surroundings. |
sur_coords | The coordinates of the top left corner of the surroundings. |
Checks to see if the enemy can see something. Looks at a point/chunk to see if it it's within the enemies slice of view. Assumes that the enemy can't see everything, as having the upper and lower bounds being the same will make everything pretty wonky. _coords The coordinates of the target. _chunk The chunk of the target.
Checks to see if a point is within the enemy's range of sight. Looks at a point/chunk to see if it it's within the enemies range of vision. _coords The coordinates of the target. _chunk The chunk of the target.
Determines whether the coords are in the list of Tiles. A helper function for the a_star which determines if a given set of coords already exists in a list of ATiles.
point | The point to check against. |
list | The list of ATiles which may possess the point. |
A heuristic to estimate the distance from a point to the goal. A helper function for the a-star algorithm, it calculates the distance as the x_change + y_change between a point and the goal.
current | The current point. |
goal | The goal the enemy is trying to reach. |
|
protected |
void Enemy::passive_ai | ( | TilePointerMatrix & | surroundings, |
IntPoint | sur_chunk, | ||
IntPoint | sur_coords, | ||
std::vector< Character * > | char_list, | ||
long | delta_ms | ||
) |
The ai for the passive enemies. The AI searches for a target (passive_best_target()) and will run away from any non-passive targets found. As time passes, it has a greater and greater chance of being un-spooked and going back to grazing.
surroundings | The tiles around the enemy. |
sur_chunk | The chunk of the surrounding coords. |
sur_coords | The coordinates of the surrounding tilematrix. |
char_list | The list of characters the enemy can see. |
delta_ms | The change in millisenconds since the last time ai was called. |
|
protected |
Finds an enemy that isn't pasive. If a character is found that isn't passive, it returns that character. Otherwise it returns NULL.
selectability | The range that the morality can fall within. |
enemy_list | The list of enemies to check. |
void Enemy::run_ai | ( | TilePointerMatrix & | surroundings, |
IntPoint | sur_chunk, | ||
IntPoint | sur_coords, | ||
std::vector< Character * > | char_list, | ||
long | delta_ms | ||
) |
Wrapper function for calling different types of AI. Depending on the type of enemy, this function will call a different type of AI. It is necessary to pass in the sur_chunk and sur_coords so that the coordinates of the character an be converted into the coords of the surroundnigs tilematrix.
surroundings | The tiles around the enemy. |
sur_chunk | The chunk of the surrounding coords. |
sur_coords | The coordinates of the surrounding tilematrix. |
char_list | The list of characters the enemy can see. |
delta_ms | The change in millisenconds since the last time ai was called. |
std::vector< IntPoint > Enemy::sight_tiles | ( | ) |
Gets all the coordinates that the enemy can currently see.
|
protected |
Turns the enemy. coords The difference between the target coords and current coords.
bool Enemy::validate_target | ( | ) |
Ensures that the target is still within the view.
|
protected |
Member variable to hold where the enemy is looking. This is 0-100, where 0 (and 100) are directly right.
|
protected |
The direction that the spooked enemy will run in. Once the enemy has been spooked, the direction for it to go will be determined based on what spooked it. direction_spooked will be an IntPoint with the possible values of +/- 1 or 0.
|
protected |
The id of the enemy. Each enemy type has an id, starting at 0, e.g. kobolds id=0. This is to allow accessing things by index based on the id of the enemy.
|
protected |
A string of the name of the enemy. This is a generic string, as in "kobold," or "rabbit."
|
protected |
Member variable to hold how far the enemy can see.
|
protected |
Determines whether or not the enemy will flee. If spooked is true, enemies will begin to flee from anything with a morality that is different from its own.
|
protected |
The number of this enemy's actions which have passed since it was spooked.
|
protected |
Member variable to hold the enemies field of view. This is a percentage of the field of view (1-100).