From 22f0a5223adddd1d6e1ea8f6f521279906b35ecd Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Wed, 3 Jul 2013 03:47:43 +0200 Subject: [PATCH] Reworked "actors" library as more inclusive "objects_on_map". --- src/draw_wins.c | 2 +- src/{actors.c => objects_on_map.c} | 10 +++++++++- src/{actors.h => objects_on_map.h} | 6 ++++++ src/roguelike.c | 10 +--------- src/roguelike.h | 6 ------ 5 files changed, 17 insertions(+), 17 deletions(-) rename src/{actors.c => objects_on_map.c} (87%) rename src/{actors.h => objects_on_map.h} (76%) diff --git a/src/draw_wins.c b/src/draw_wins.c index 5b60d81..9c53810 100644 --- a/src/draw_wins.c +++ b/src/draw_wins.c @@ -6,7 +6,7 @@ #include "windows.h" #include "roguelike.h" #include "keybindings.h" -#include "actors.h" +#include "objects_on_map.h" void draw_with_linebreaks (struct Win * win, char * text, uint16_t start_y) { // Write text into window content space. Start on row start_y. Fill unused rows with whitespace. diff --git a/src/actors.c b/src/objects_on_map.c similarity index 87% rename from src/actors.c rename to src/objects_on_map.c index ca1305c..eedf800 100644 --- a/src/actors.c +++ b/src/objects_on_map.c @@ -1,4 +1,4 @@ -#include "actors.h" +#include "objects_on_map.h" #include #include #include "yx_uint16.h" @@ -12,6 +12,14 @@ extern char is_passable (struct Map * map, struct yx_uint16 pos) { passable = 1; return passable; } +extern struct yx_uint16 find_passable_pos (struct Map * map) { +// Return a random passable position on map. + struct yx_uint16 pos; + for (pos.y = pos.x = 0; 0 == is_passable(map, pos);) { + pos.y = rrand(0, 0) % map->size.y; + pos.x = rrand(0, 0) % map->size.x; } + return pos; } + extern void move_monster (struct World * world, struct Monster * monster) { // Move monster in random direction, trigger fighting when hindered by player/monster. char d = rrand(0, 0) % 5; diff --git a/src/actors.h b/src/objects_on_map.h similarity index 76% rename from src/actors.h rename to src/objects_on_map.h index d88c66f..ac3795d 100644 --- a/src/actors.h +++ b/src/objects_on_map.h @@ -9,12 +9,18 @@ struct Map; struct Player { struct yx_uint16 pos; }; +struct Item { + struct Item * next; + char name; + struct yx_uint16 pos; }; + struct Monster { struct Monster * next; char name; struct yx_uint16 pos; }; extern char is_passable (struct Map *, struct yx_uint16); +extern struct yx_uint16 find_passable_pos (struct Map *); extern void move_monster (struct World *, struct Monster *); extern void move_player (struct World *, char); extern void player_wait(struct World *); diff --git a/src/roguelike.c b/src/roguelike.c index 68a5936..ac735ac 100644 --- a/src/roguelike.c +++ b/src/roguelike.c @@ -9,7 +9,7 @@ #include "draw_wins.h" #include "keybindings.h" #include "readwrite.h" -#include "actors.h" +#include "objects_on_map.h" uint16_t rrand(char use_seed, uint32_t new_seed) { // Pseudo-random number generator (LGC algorithm). Use instead of rand() to ensure portable predictability. @@ -70,14 +70,6 @@ struct Map init_map () { map.cells[y * map.size.x + x] = '.'; } return map; } -struct yx_uint16 find_passable_pos (struct Map * map) { -// Return a random passable position on map. - struct yx_uint16 pos; - for (pos.y = pos.x = 0; 0 == is_passable(map, pos);) { - pos.y = rrand(0, 0) % map->size.y; - pos.x = rrand(0, 0) % map->size.x; } - return pos; } - void map_scroll (struct Map * map, char dir) { // Scroll map into direction dir if possible by changing the offset. if (NORTH == dir && map->offset.y > 0) map->offset.y--; diff --git a/src/roguelike.h b/src/roguelike.h index 5041caf..14ca783 100644 --- a/src/roguelike.h +++ b/src/roguelike.h @@ -26,16 +26,10 @@ struct Map { struct yx_uint16 offset; char * cells; }; -struct Item { - struct Item * next; - char name; - struct yx_uint16 pos; }; - extern uint16_t rrand(char, uint32_t); extern void update_log (struct World *, char *); extern struct Map init_map (); -extern struct yx_uint16 find_passable_pos (struct Map *); extern void map_scroll (struct Map *, char); extern void turn_over (struct World *, char); -- 2.30.2