Skip to content

Commit d11c3be

Browse files
committed
forward referencing refactoring and maybe implementation progress? :/
1 parent c351e61 commit d11c3be

File tree

18 files changed

+384
-277
lines changed

18 files changed

+384
-277
lines changed

.idea/workspace.xml

Lines changed: 228 additions & 166 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/fighter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#include <stdlib.h>
66
#include "fighter.h"
77

8-
fighter *create_fighter(int hp, int defense, int power) {
9-
fighter *f = malloc(sizeof(fighter));
8+
struct fighter *create_fighter(int hp, int defense, int power) {
9+
struct fighter *f = malloc(sizeof(struct fighter));
1010
f->hp = hp;
1111
f->defense = defense;
1212
f->power = power;

src/components/fighter.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
#ifndef LIBTCOD_TUTORIAL_FIGHTER_H
66
#define LIBTCOD_TUTORIAL_FIGHTER_H
77

8-
typedef struct {
8+
struct fighter{
99
int max_hp;
1010
int hp;
1111
int defense;
1212
int power;
13-
} fighter;
13+
};
14+
;
1415

15-
fighter *create_fighter(int hp, int defense, int power);
16+
struct fighter* create_fighter(int hp, int defense, int power);
1617
#endif //LIBTCOD_TUTORIAL_FIGHTER_H

src/data/list.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
//
44
#include "list.h"
55

6-
entity *get_blocking_entities_at_location(entity_list *e, int destination_x, int destination_y) {
7-
entity_list *curr = e;
6+
struct entity *get_blocking_entities_at_location(struct entity_list *e, int destination_x, int destination_y) {
7+
struct entity_list *curr = e;
88
while (curr != NULL) {
9-
entity curr_e = *curr->data;
9+
struct entity curr_e = *curr->data;
1010
if (curr_e.blocks && curr_e.x == destination_x && curr_e.y == destination_y) {
1111
return curr->data;
1212
}

src/data/list.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
#ifndef LIBTCOD_TUTORIAL_LIST_H
66
#define LIBTCOD_TUTORIAL_LIST_H
77

8-
#include "../entity.h"
98

10-
struct node {
11-
entity *data;
12-
struct node *next;
9+
struct entity;
10+
11+
struct entity_list {
12+
struct entity *data;
13+
struct entity_list *next;
1314
};
1415

15-
typedef struct node entity_list;
16+
#include "../entity.h"
1617

17-
entity *get_blocking_entities_at_location(entity_list *e, int destination_x, int destination_y);
18+
struct entity *get_blocking_entities_at_location(struct entity_list *e, int destination_x, int destination_y);
1819

1920
#endif //LIBTCOD_TUTORIAL_LIST_H

src/entity.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66
#include <stdio.h>
77
#include "entity.h"
88

9-
void move(entity *e, int dx, int dy) {
9+
void move(struct entity *e, int dx, int dy) {
1010
e->x += dx;
1111
e->y += dy;
1212
}
1313

14-
entity *create_entity(int x,
14+
struct entity *create_entity(int x,
1515
int y,
1616
char c,
1717
TCOD_color_t color,
1818
char *name,
1919
bool blocks,
20-
fighter *fighter,
21-
void (*ai_action)(entity *)) {
22-
entity *e = malloc(sizeof(entity));
20+
struct fighter *fighter,
21+
void (*ai_action)(struct entity *, struct entity *, TCOD_Map *, struct game_map *, struct entity_list *)) {
22+
struct entity *e = malloc(sizeof(struct entity));
2323
e->x = x;
2424
e->y = y;
2525
e->c = c;
@@ -31,8 +31,3 @@ entity *create_entity(int x,
3131
return e;
3232
}
3333

34-
void basic_ai_monster_turn(entity *e) {
35-
printf("The %s wonders when it will get to move.\n", e->name);
36-
}
37-
38-

src/entity.h

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,39 @@
66
#define LIBTCOD_TUTORIAL_ENTITY_H
77

88
#include <libtcod/color.h>
9+
#include <libtcod/fov_types.h>
910

10-
#include "components/fighter.h"
11+
struct game_map;
12+
struct entity_list;
1113

12-
typedef struct entity {
14+
struct entity {
1315
int x;
1416
int y;
1517
char c;
1618
TCOD_color_t color;
1719
char *name;
1820
bool blocks;
19-
fighter *fighter;
20-
void (*ai_action)(struct entity *);
21-
} entity;
22-
23-
entity *create_entity(int x,
24-
int y,
25-
char c,
26-
TCOD_color_t color,
27-
char *name,
28-
bool blocks,
29-
fighter *fighter,
30-
void(*ai_action)(entity *));
31-
32-
void move(entity *e, int dx, int dy);
33-
34-
void basic_ai_monster_turn(entity* e);
21+
struct fighter *fighter;
22+
23+
void (*ai_action)(struct entity *, struct entity *, TCOD_Map *, struct game_map *, struct entity_list *);
24+
};
25+
26+
#include "components/fighter.h"
27+
#include "map/game_map.h"
28+
#include "data/list.h"
29+
30+
struct entity *create_entity(int x,
31+
int y,
32+
char c,
33+
TCOD_color_t color,
34+
char *name,
35+
bool blocks,
36+
struct fighter *fighter,
37+
void(*ai_action)(struct entity *,
38+
struct entity *, TCOD_Map *,
39+
struct game_map *,
40+
struct entity_list *));
41+
42+
void move(struct entity *e, int dx, int dy);
3543

3644
#endif //LIBTCOD_TUTORIAL_ENTITY_H

src/main.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ int main() {
3232
colors[LIGHT_WALL] = TCOD_color_RGB(130, 110, 50);
3333
colors[LIGHT_GROUND] = TCOD_color_RGB(200, 180, 50);
3434

35-
entity_list *entities_list_head;
36-
entity_list *player;
37-
entities_list_head = (entity_list *) malloc(sizeof(entity_list));
35+
struct entity_list *entities_list_head;
36+
struct entity_list *player;
37+
entities_list_head = (struct entity_list *) malloc(sizeof(struct entity_list));
3838
entities_list_head->next = NULL;
3939
player = entities_list_head;
40-
fighter *fighter = create_fighter(30, 2, 5);
40+
struct fighter *fighter = create_fighter(30, 2, 5);
4141
player->data = create_entity(screen_width / 2, screen_height / 2, '@', TCOD_white, "Player", true, fighter, NULL);
4242
TCOD_console_set_custom_font("terminal16x16_gs_ro.png",
4343
TCOD_FONT_TYPE_GRAYSCALE | TCOD_FONT_LAYOUT_ASCII_INROW,
@@ -46,7 +46,7 @@ int main() {
4646
TCOD_console_init_root(screen_width, screen_height, "libtcod Tutorial", false, TCOD_RENDERER_SDL2);
4747
TCOD_console_t con = TCOD_console_new(screen_width, screen_height);
4848

49-
game_map *map = create_game_map(map_width, map_height);
49+
struct game_map *map = create_game_map(map_width, map_height);
5050
make_map(map, max_rooms, room_min_size, room_max_size, map_width, map_height, player->data, entities_list_head,
5151
max_monsters_per_room);
5252

@@ -94,7 +94,7 @@ int main() {
9494
int destination_x = player->data->x + dx;
9595
int destination_y = player->data->y + dy;
9696
if (!is_blocked(map, destination_x, destination_y)) {
97-
entity *target = get_blocking_entities_at_location(entities_list_head, destination_x,
97+
struct entity *target = get_blocking_entities_at_location(entities_list_head, destination_x,
9898
destination_y);
9999
if (target) {
100100
printf("You kick the %s in the shins, much to its annoyance!\n", target->name);
@@ -111,10 +111,10 @@ int main() {
111111
}
112112

113113
if (game_state == ENEMY_TURN) {
114-
entity_list *curr = entities_list_head;
114+
struct entity_list *curr = entities_list_head;
115115
while (curr != NULL) {
116116
if (curr->data->ai_action) {
117-
(*curr->data->ai_action)(curr->data);
117+
(*curr->data->ai_action)(curr->data, player->data, fov_map, map, entities_list_head);
118118
}
119119
curr = curr->next;
120120
}

src/map/fov.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "game_map.h"
88
#include "tile.h"
99

10-
TCOD_Map* initialize_fov(game_map *map) {
10+
TCOD_Map* initialize_fov(struct game_map *map) {
1111
TCOD_Map *fov_map = TCOD_map_new(map->width, map->height);
1212
for (int y = 0; y < map->height; y++) {
1313
for (int x = 0; x < map->width; x++) {

src/map/fov.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#ifndef LIBTCOD_TUTORIAL_FOV_H
99
#define LIBTCOD_TUTORIAL_FOV_H
1010

11-
TCOD_Map* initialize_fov(game_map *map);
11+
TCOD_Map* initialize_fov(struct game_map *map);
1212
void recompute_fov(TCOD_Map* fov_map, int x, int y, int radius, bool light_walls, int algorithm);
1313

1414
#endif //LIBTCOD_TUTORIAL_FOV_H

0 commit comments

Comments
 (0)