Exposes functions for working with damage.
More...
Go to the source code of this file.
|
typedef enum damage_type_t | damage_type_t |
typedef enum dice_size_t | dice_size_t |
typedef struct damage_resistance_t | damage_resistance_t |
|
enum | damage_type_t { PHYSICAL
, MAGICAL
} |
enum | dice_size_t {
D6 = 6
, D8 = 8
, D10 = 10
, D12 = 12
,
D20 = 20
} |
|
bool | roll_hit (int attacker_dex, int defender_dex) |
| Rolls a D20 to determine if an attack hits.
|
int | roll_damage (const ability_t *ability) |
| Rolls damage based on the ability's roll amount and dice size.
|
int | deal_damage (character_t *character, damage_type_t damage_type, int damage) |
| Deals damage to a character based on the damage type and amount.
|
void | reset_current_stats (character_t *character) |
| Resets the current stats of a character to their base stats.
|
const char * | dice_size_to_string (dice_size_t size) |
| Converts a dice size enum to a string representation.
|
const char * | damage_type_to_string (damage_type_t type) |
| Converts a damage type enum to a string representation.
|
Exposes functions for working with damage.
Definition in file damage.h.
◆ DAMAGE_TYPE_COUNT
#define DAMAGE_TYPE_COUNT 2 |
◆ damage_type_t
Definition at line 13 of file damage.h.
13 {
14 PHYSICAL,
15 MAGICAL
16} damage_type_t;
◆ dice_size_t
Definition at line 18 of file damage.h.
18 {
19 D6 = 6,
20 D8 = 8,
21 D10 = 10,
22 D12 = 12,
23 D20 = 20
24} dice_size_t;
◆ damage_type_to_string()
const char * damage_type_to_string |
( |
damage_type_t | type | ) |
|
Converts a damage type enum to a string representation.
- Parameters
-
type | The damage type to convert. |
- Returns
- The string representation of the damage type.
Definition at line 78 of file damage.c.
78 {
79 switch (type) {
80 case PHYSICAL:
81 return "Physical";
82 case MAGICAL:
83 return "Magic";
84 default:
85 return "Unknown";
86 }
87}
◆ deal_damage()
int deal_damage |
( |
character_t * | character, |
|
|
damage_type_t | damage_type, |
|
|
int | damage ) |
Deals damage to a character based on the damage type and amount.
- Parameters
-
character | Pointer to the character receiving damage. |
damage_type | The type of damage being dealt. |
damage | The amount of damage to be dealt. |
- Returns
- The actual damage dealt.
Definition at line 42 of file damage.c.
42 {
43
44
45
46
47
48 if (damage < character->current_resources.health) {
49 character->current_resources.health -= damage;
50 } else {
51 character->current_resources.health = 0;
52 }
53 return damage;
54}
◆ dice_size_to_string()
const char * dice_size_to_string |
( |
dice_size_t | size | ) |
|
Converts a dice size enum to a string representation.
- Parameters
-
size | The dice size to convert. |
- Returns
- The string representation of the dice size.
Definition at line 61 of file damage.c.
61 {
62 switch (size) {
63 case D6:
64 return "D6";
65 case D8:
66 return "D8";
67 case D10:
68 return "D10";
69 case D12:
70 return "D12";
71 case D20:
72 return "D20";
73 default:
74 return "Unknown";
75 }
76}
◆ reset_current_stats()
Resets the current stats of a character to their base stats.
- Parameters
-
character | Pointer to the character whose stats are to be reset. |
Resets the current stats of a character to their base stats.
- Parameters
-
character | Pointer to the character |
Definition at line 56 of file damage.c.
56 {
57 character->current_stats = character->base_stats;
58}
◆ roll_damage()
Rolls damage based on the ability's roll amount and dice size.
- Parameters
-
ability | Pointer to the ability used for rolling damage. |
- Returns
- The total damage rolled.
Definition at line 33 of file damage.c.
33 {
34 int roll = 0;
35
36 for (int i = 0; i < ability->roll_amount; i++) {
38 }
39 return roll;
40}
int roll_dice(dice_size_t dice_size)
Rolls given dice size and returns the result.
◆ roll_hit()
bool roll_hit |
( |
int | attacker_dex, |
|
|
int | defender_dex ) |
Rolls a D20 to determine if an attack hits.
- Parameters
-
attacker_dex | The dexterity of the attacker. |
defender_dex | The dexterity of the defender. |
- Returns
- The result of the dice roll.
Definition at line 25 of file damage.c.
25 {
28 bool hit = false;
29
30 return attacker_roll + (attacker_dex / 2) > defender_roll + (defender_dex / 2);
31}