DungeonCrawl
Loading...
Searching...
No Matches
ability.h File Reference

Exposes functions for working with abilities. More...

#include "../common.h"
#include "../database/database.h"
#include "../memory/memory_management.h"
#include "damage.h"

Go to the source code of this file.

Data Structures

struct  ability_t
struct  ability_table_t

Typedefs

typedef struct ability_t ability_t

Enumerations

enum  ability_names_t {
  BITE , QUICK_SLASH , HEAVY_SWING , SWEEPING_STRIKE ,
  GUARDING_STANCE , HEAVY_CHOP , PIERCING_STRIKE , EXECUTE ,
  BERSERKER_RAGE , QUICK_SHOT , POWER_SHOT , STEADY_SHOT ,
  STEADY_AIM , FIREBLAST , FIREBALL , PYROBLAST ,
  MANA_SHIELD , CHOP , AXE_SWING , BACKSTAB ,
  SINISTER_STRIKE , DEFLECT , SHIELD_WALL , MACE_STRIKE ,
  CRUSHING_BLOW , ARCANE_BOLT , ARCANE_MISSILE , SWORD_SLASH ,
  RIPOSTE , PUNCH , MAX_ABILITIES
}

Functions

ability_table_tinit_ability_table (memory_pool_t *memory_pool, const db_connection_t *db_connection)
 Initialize the ability table, allocates memory and returns the pointer to the table.
void free_ability_table (memory_pool_t *memory_pool, ability_table_t *table)
 Free the ability table, deallocates memory in the memory pool.

Detailed Description

Exposes functions for working with abilities.

Definition in file ability.h.

Enumeration Type Documentation

◆ ability_names_t

enum ability_names_t

Definition at line 14 of file ability.h.

14 {
15 BITE,
16 QUICK_SLASH,
17 HEAVY_SWING,
18 SWEEPING_STRIKE,
19 GUARDING_STANCE,
20 HEAVY_CHOP,
21 PIERCING_STRIKE,
22 EXECUTE,
23 BERSERKER_RAGE,
24 QUICK_SHOT,
25 POWER_SHOT,
26 STEADY_SHOT,
27 STEADY_AIM,
28 FIREBLAST,
29 FIREBALL,
30 PYROBLAST,
31 MANA_SHIELD,
32 CHOP,
33 AXE_SWING,
34 BACKSTAB,
35 SINISTER_STRIKE,
36 DEFLECT,
37 SHIELD_WALL,
38 MACE_STRIKE,
39 CRUSHING_BLOW,
40 ARCANE_BOLT,
41 ARCANE_MISSILE,
42 SWORD_SLASH,
43 RIPOSTE,
44 PUNCH,
45 MAX_ABILITIES
46} ability_names_t;

Function Documentation

◆ free_ability_table()

void free_ability_table ( memory_pool_t * memory_pool,
ability_table_t * table )

Free the ability table, deallocates memory in the memory pool.

Parameters
memory_poolPointer to the memory pool for deallocation.
tablePointer to the ability table to be freed.

Definition at line 45 of file ability.c.

45 {
46 NULL_PTR_HANDLER_RETURN(memory_pool, , "Ability", "In free_ability_table memory pool is NULL");
47 NULL_PTR_HANDLER_RETURN(table, , "Ability", "In free_ability_table table is NULL");
48
49 memory_pool_free(memory_pool, table);
50}
void memory_pool_free(memory_pool_t *pool, void *ptr)
Sets the given data pointer to not active in the given memory pool.

◆ init_ability_table()

ability_table_t * init_ability_table ( memory_pool_t * memory_pool,
const db_connection_t * db_connection )

Initialize the ability table, allocates memory and returns the pointer to the table.

Parameters
memory_poolPointer to the memory pool for allocation.
db_connectionPointer to the database connection
Returns
Pointer to the ability table.

Definition at line 16 of file ability.c.

16 {
17 NULL_PTR_HANDLER_RETURN(memory_pool, NULL, "Ability", "Memory pool is NULL");
18
19 ability_init_t* rows = get_ability_table_from_db(db_connection);
20 NULL_PTR_HANDLER_RETURN(rows, NULL, "Ability", "Could not fetch ability data from DB");
21
22 ability_table_t* table = memory_pool_alloc(memory_pool, sizeof(ability_table_t));
23 NULL_PTR_HANDLER_RETURN(table, NULL, "Ability", "Failed to allocate memory for ability table");
24
25
26 for (int i = 0; i < MAX_ABILITIES; ++i) {
27 if (rows[i].name == NULL)
28 break;
29
30 const int slot = rows[i].ability_number;
31
32 init_ability(&table->abilities[slot],
33 rows[i].name,
34 rows[i].roll_amount,
35 rows[i].accuracy,
36 rows[i].resource_cost,
37 rows[i].dice_size,
38 rows[i].damage_type);
39 }
41 return table;
42}
void init_ability(ability_t *ability, char *name, int roll_amount, int accuracy, int resource_cost, dice_size_t dice_size, damage_type_t damage_type)
Initializes an ability with the given parameters.
Definition ability.c:62
ability_init_t * get_ability_table_from_db(const db_connection_t *db_connection)
Get the ability table from the database.
void free_ability_table_from_db(ability_init_t *ability_init_table)
Clean up the ability table Call this function to free the memory allocated for the ability table.
void * memory_pool_alloc(memory_pool_t *pool, size_t size)
Allocates memory on the given memory pool.
To get the ability table from the database, we need to define a struct This struct is for the initial...