From: Christian Heller Date: Thu, 18 Jul 2013 02:11:42 +0000 (+0200) Subject: Emptied map_objects library of stuff that fits better elsewhere, like a new map_objec... X-Git-Tag: tce~1151 X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/%7B%7Bprefix%7D%7D/static/edit?a=commitdiff_plain;h=00a66e3c7cbcad13b5c29162e6c1c33235be9f07;p=plomrogue Emptied map_objects library of stuff that fits better elsewhere, like a new map_object_actions library. --- diff --git a/src/draw_wins.c b/src/draw_wins.c index 9efc8c9..81281b7 100644 --- a/src/draw_wins.c +++ b/src/draw_wins.c @@ -101,8 +101,8 @@ extern void draw_map_win (struct Win * win) { if (y < height_map_av && x < width_map_av) { mvwaddch(win->frame.curses_win, y, x, cells[z]); z++; } } } - draw_map_objects (world, world->item, map, win); - draw_map_objects (world, world->monster, map, win); + draw_map_objects (world, (struct MapObj *) world->item, map, win); + draw_map_objects (world, (struct MapObj *) world->monster, map, win); if ( player->pos.y >= map->offset.y && player->pos.y < map->offset.y + win->frame.size.y && player->pos.x >= map->offset.x && player->pos.x < map->offset.x + win->frame.size.x) mvwaddch(win->frame.curses_win, player->pos.y - map->offset.y, player->pos.x - map->offset.x, '@'); } diff --git a/src/main.c b/src/main.c index 53784b8..3d6c0d3 100644 --- a/src/main.c +++ b/src/main.c @@ -8,6 +8,7 @@ #include "keybindings.h" #include "readwrite.h" #include "map_objects.h" +#include "map_object_actions.h" #include "map.h" #include "misc.h" diff --git a/src/map_objects.c b/src/map_objects.c index 7c13ed2..731d830 100644 --- a/src/map_objects.c +++ b/src/map_objects.c @@ -1,10 +1,8 @@ #include "map_objects.h" #include #include -#include "yx_uint16.h" #include "readwrite.h" #include "misc.h" -#include "map.h" #include "main.h" static struct MapObj * get_next_map_obj (void *, char *, size_t, struct MapObj *); @@ -96,93 +94,3 @@ extern struct MapObjDef * get_map_obj_def (struct World * world, char def_id) { if (d->id != def_id) for (d = (struct MapObjDef *) world->item_def; d->id != def_id && 0 != d->next; d = d->next); return d; } - -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 char is_passable (struct Map * map, struct yx_uint16 pos) { -// Check if coordinate on (or beyond) map is accessible to actor movement. - char passable = 0; - if (0 <= pos.x && pos.x < map->size.x && 0 <= pos.y && pos.y < map->size.y) - if ('.' == map->cells[pos.y * map->size.x + pos.x]) - passable = 1; - return passable; } - -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; - struct yx_uint16 t = mv_yx_in_dir (d, monster->map_obj.pos); - char * msg = malloc(100); - struct MapObjDef * mod = get_map_obj_def (world, monster->map_obj.type); - char * desc = mod->desc; - char * desc_other; - if (yx_uint16_cmp (t, world->player->pos)) { - sprintf(msg, "\nThe %s hits you.", desc); - update_log (world, msg); - world->player->hitpoints--; - if (0 == world->player->hitpoints) - update_log (world, "\nYou are dead."); - return; } - struct Monster * other_monster; - for (other_monster = world->monster; other_monster != 0; other_monster = other_monster->map_obj.next) { - if (other_monster == monster) - continue; - if (yx_uint16_cmp (t, other_monster->map_obj.pos)) { - mod = get_map_obj_def (world, monster->map_obj.type); - desc_other = mod->desc; - sprintf(msg, "\n%s bumps into %s.", desc, desc_other); - update_log (world, msg); - return; } } - free (msg); - if (is_passable(world->map, t)) - monster->map_obj.pos = t; } - -extern void move_player (struct World * world, char d) { -// Move player in direction d, update log and turn over to the enemy. - struct yx_uint16 t = mv_yx_in_dir (d, world->player->pos); - struct Monster * monster; - struct MapObjDef * mod; - char * msg = calloc(100, sizeof(char)); - char * desc; - for (monster = world->monster; monster != 0; monster = monster->map_obj.next) - if (yx_uint16_cmp (t, monster->map_obj.pos)) { - mod = get_map_obj_def (world, monster->map_obj.type); - desc = mod->desc; - sprintf (msg, "\nYou hit the %s.", desc); - update_log (world, msg); - monster->hitpoints--; - if (0 == monster->hitpoints) { - sprintf (msg, "\nYou kill the %s.", desc); - update_log (world, msg); - if (world->monster == monster) - world->monster = world->monster->map_obj.next; - else { - struct Monster * m_prev; - for (m_prev = world->monster; m_prev->map_obj.next != monster; m_prev = m_prev->map_obj.next); - m_prev->map_obj.next = monster->map_obj.next; } - free(monster); } - turn_over (world, d); - return; } - char * msg_content = "You fail to move"; - char * dir; - if (NORTH == d) dir = "north"; - else if (EAST == d) dir = "east" ; - else if (SOUTH == d) dir = "south"; - else if (WEST == d) dir = "west" ; - if (is_passable(world->map, t)) { - msg_content = "You move"; - world->player->pos = t; } - sprintf(msg, "\n%s %s.", msg_content, dir); - update_log (world, msg); - free(msg); - turn_over (world, d); } - -extern void player_wait (struct World * world) { -// Make player wait one turn. - update_log (world, "\nYou wait."); - turn_over (world, 0); } diff --git a/src/map_objects.h b/src/map_objects.h index 80e7c0f..9ef7f3b 100644 --- a/src/map_objects.h +++ b/src/map_objects.h @@ -5,7 +5,6 @@ #include "yx_uint16.h" struct World; -struct Map; struct Player { struct yx_uint16 pos; @@ -47,10 +46,4 @@ extern void * build_map_objects (struct World *, void *, char, unsigned char, si void (*) (struct MapObjDef *, void *)); extern struct MapObjDef * get_map_obj_def (struct World *, char); -extern struct yx_uint16 find_passable_pos (struct Map *); -extern char is_passable (struct Map *, struct yx_uint16); -extern void move_monster (struct World *, struct Monster *); -extern void move_player (struct World *, char); -extern void player_wait(struct World *); - #endif diff --git a/src/misc.c b/src/misc.c index 83ed263..683346f 100644 --- a/src/misc.c +++ b/src/misc.c @@ -5,8 +5,10 @@ #include "keybindings.h" #include "readwrite.h" #include "map_objects.h" +#include "map_object_actions.h" #include "map.h" #include "main.h" +#include "yx_uint16.h" extern uint16_t rrand(char use_seed, uint32_t new_seed) { // Pseudo-random number generator (LGC algorithm). Use instead of rand() to ensure portable predictability. @@ -98,6 +100,14 @@ extern void growshrink_active_window (struct WinMeta * win_meta, char change) { else if (change == '*') size.x++; resize_active_win (win_meta, size); } } +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 unsigned char meta_keys(int key, struct World * world, struct WinMeta * win_meta, struct Win * win_keys, struct Win * win_map, struct Win * win_info, struct Win * win_log) { diff --git a/src/misc.h b/src/misc.h index 5bccd40..64e10db 100644 --- a/src/misc.h +++ b/src/misc.h @@ -2,10 +2,12 @@ #define MISC_H #include +#include "yx_uint16.h" struct World; struct WinMeta; struct Win; +struct Map; extern uint16_t rrand(char, uint32_t); extern void update_log (struct World *, char *); @@ -15,6 +17,7 @@ extern void save_game(struct World *); extern void toggle_window (struct WinMeta *, struct Win *); extern void scroll_pad (struct WinMeta *, char); extern void growshrink_active_window (struct WinMeta *, char); +extern struct yx_uint16 find_passable_pos (struct Map *); extern unsigned char meta_keys(int, struct World *, struct WinMeta *, struct Win *, struct Win *, struct Win *, struct Win *); #endif