15 NULL_PTR_HANDLER_RETURN(memory_pool, NULL,
"Gear",
"In init_gear memory pool is NULL");
16 NULL_PTR_HANDLER_RETURN(name, NULL,
"Gear",
"In init_gear name is NULL");
20 NULL_PTR_HANDLER_RETURN(gear, NULL,
"Gear",
"Failed to allocate memory for gear: %s", name);
22 snprintf(gear->local_key,
sizeof(gear->local_key),
"%s", name);
23 gear->gear_identifier = gear_identifier;
26 gear->defenses = defenses;
27 gear->num_abilities = num_abilities;
30 for (; i < MAX_ABILITY_PER_GEAR && i < num_abilities; ++i) {
31 ability_names_t idx = abilities[i];
32 if (idx < MAX_ABILITIES) {
33 gear->abilities[i] = &ability_table->abilities[abilities[i]];
38 for (; i < MAX_ABILITY_PER_GEAR; ++i) {
46 NULL_PTR_HANDLER_RETURN(memory_pool, NULL,
"Gear",
"Memory pool is NULL");
49 NULL_PTR_HANDLER_RETURN(rows, NULL,
"Gear",
"Could not fetch gear data from DB");
54 NULL_PTR_HANDLER_RETURN(table, NULL,
"Gear",
"Failed to allocate gear table");
56 table->num_gears = count;
57 NULL_PTR_HANDLER_RETURN(table->gears, NULL,
"Gear",
"Failed to allocate gear array for table");
59 for (
int i = 0; i < count; ++i) {
62 rows[i].gear_identifier,
67 rows[i].ability_names,
68 rows[i].num_abilities);
75 NULL_PTR_HANDLER_RETURN(memory_pool, ,
"Gear",
"In free_gear_table memory pool is NULL");
76 NULL_PTR_HANDLER_RETURN(table, ,
"Gear",
"In free_gear_table table is NULL");
77 for (
int i = 0; i < table->num_gears; ++i) {
78 gear_t* gear = table->gears[i];
100 case SLOT_FINGER_RIGHT:
101 return "Right Finger";
102 case SLOT_FINGER_LEFT:
103 return "Left Finger";
106 case SLOT_RIGHT_HAND:
108 case SLOT_BOTH_HANDS:
111 return "Unknown Slot";
void free_gear_table(memory_pool_t *memory_pool, gear_table_t *table)
Frees the memory allocated for a gear table.
gear_t * init_gear(memory_pool_t *memory_pool, const char *name, gear_identifier_t gear_identifier, gear_slot_t slot, stats_t stats, defenses_t defenses, ability_table_t *ability_table, ability_names_t *abilities, int num_abilities)
Initializes a gear object.
gear_table_t * init_gear_table(memory_pool_t *memory_pool, const db_connection_t *db_connection, ability_table_t *ability_table)
Initializes a gear table.
const char * gear_slot_to_string(gear_slot_t slot)
Converts a gear slot enumeration value to its string representation.
Exposes functions for working with gear.
gear_init_t * init_gear_table_from_db(const db_connection_t *db_connection)
Get the gear table from the database.
void free_gear_table_from_db(gear_init_t *gear_init_table, const db_connection_t *db_connection)
Clean up the gear table Call this function to free the memory allocated for the gear table.
int count_gear_in_db(const db_connection_t *db_connection)
Count the number of gears in the database.
Declares functions to load and free potion and gear tables from the game database,...
Header file for logging functionality of the game.
void * memory_pool_alloc(memory_pool_t *pool, size_t size)
Allocates memory on the given memory pool.
void memory_pool_free(memory_pool_t *pool, void *ptr)
Sets the given data pointer to not active in the given memory pool.
This struct is used for the database connection in SQLite.
To get gear table from the database, we need to define a struct This struct is for the initialization...