DungeonCrawl
Loading...
Searching...
No Matches
game_data.c
Go to the documentation of this file.
1
5#include "game_data.h"
6
7#include "character/monster.h"
8#include "character/player.h"
9#include "common.h"
10#include "game.h"
12
13#include <stddef.h>
14#include <stdio.h>
15
16// === External Global Variables ===
17ability_table_t* ability_table;
18potion_table_t* potion_table;
19gear_table_t* gear_table;
20character_t* goblin;
21character_t* player;
22
24 ability_table = init_ability_table(main_memory_pool, &db_connection);
25 potion_table = init_potion_table(main_memory_pool, &db_connection);
26 gear_table = init_gear_table(main_memory_pool, &db_connection, ability_table);
29
30 if (ability_table == NULL || potion_table == NULL || gear_table == NULL || player == NULL) return 1;
31
32 add_potion(goblin, &potion_table->potions[HEALING]);
33
34 return 0;
35}
36
43 return 0;
44}
45
49 if (goblin == NULL) {
50 return 1;
51 }
52 add_ability(goblin, &ability_table->abilities[BITE]);
53 generate_loot(goblin, gear_table, potion_table, 1);
54 return 0;
55}
56
57int init_player(char* name) {
60 if (player == NULL) {
61 return 1;
62 }
63 player->base_attack = &ability_table->abilities[PUNCH];
64 add_ability(player, player->base_attack);
65 add_potion(player, &potion_table->potions[HEALING]);
66 add_potion(player, &potion_table->potions[MANA]);
67 add_potion(player, &potion_table->potions[STAMINA]);
68 equip_gear(player, gear_table->gears[ARMING_SWORD]);
69 if (name != NULL) {
70 snprintf(player->name, sizeof(player->name), "%s", name);
71 } else {
72 snprintf(player->name, sizeof(player->name), "Hero");
73 }
74 return 0;
75}
76
80 if (player == NULL) {
81 return 1;
82 }
83 player->base_attack = &ability_table->abilities[PUNCH];
84 add_ability(player, player->base_attack);
85 return 0;
86}
void free_ability_table(memory_pool_t *memory_pool, ability_table_t *table)
Free the ability table, deallocates memory in the memory pool.
Definition ability.c:45
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.
Definition ability.c:16
void equip_gear(character_t *character, gear_t *gear)
Equips a gear item to a character.
Definition character.c:272
void add_potion(character_t *character, potion_t *potion)
Adds a potion to a character's inventory.
Definition character.c:242
void free_character(memory_pool_t *memory_pool, character_t *character)
Frees the memory allocated for a character.
Definition character.c:60
void add_ability(character_t *character, ability_t *ability)
Adds an ability to a character.
Definition character.c:127
memory_pool_t * main_memory_pool
Global memory pool for the application.
Definition common.c:7
Defines common macros, types, and global variables for color schemes and utilities.
Declares core game states, global database connection, and main game control functions.
int reset_goblin()
Resets the goblin character data by deallocating the current goblin instance and creating a new one.
Definition game_data.c:46
int reset_player()
Resets the player character to its initial state, clearing all abilities, items, and stats.
Definition game_data.c:77
int free_game_data()
Frees game-related data structures and resources, such as ability tables, characters,...
Definition game_data.c:37
int init_player(char *name)
Initializes the player character with default abilities and items.
Definition game_data.c:57
int init_game_data()
Initializes game data for the application.
Definition game_data.c:23
Declares functions and globals for initializing, resetting, and freeing game data such as player,...
void free_gear_table(memory_pool_t *memory_pool, gear_table_t *table)
Frees the memory allocated for a gear table.
Definition gear.c:74
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.
Definition gear.c:45
void generate_loot(character_t *c, gear_table_t *gear_table, potion_table_t *potion_table, int rolls)
Generates loot for a character by randomly selecting a number of gear and potions.
Exposes functions for loot generation.
void memory_pool_free(memory_pool_t *pool, void *ptr)
Sets the given data pointer to not active in the given memory pool.
character_t * create_new_goblin(memory_pool_t *memory_pool)
Creates and initializes a new goblin character.
Definition monster.c:8
Declares routines for creating and destroying monster characters.
character_t * create_new_player(memory_pool_t *memory_pool)
Creates and initializes a new player character.
Definition player.c:8
Exposes functions for working with the player.
potion_table_t * init_potion_table(memory_pool_t *memory_pool, const db_connection_t *db_connection)
initializes a potion table with potions from the database
Definition potion.c:20
void free_potion_table(memory_pool_t *memory_pool, potion_table_t *table)
Frees the memory allocated for a potion table.
Definition potion.c:53