From: Christian Heller Date: Thu, 27 Jun 2013 23:06:03 +0000 (+0200) Subject: Make is_passable() use yx_uint16 for coordinates instead of two ints. X-Git-Tag: tce~1187 X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7Btodo.comment%7D%7D?a=commitdiff_plain;h=c23b884c2b47fffde180af8179cd8ede5ff67241;p=plomrogue Make is_passable() use yx_uint16 for coordinates instead of two ints. --- diff --git a/src/actors.c b/src/actors.c index b70f279..0552587 100644 --- a/src/actors.c +++ b/src/actors.c @@ -5,11 +5,11 @@ #include "yx_uint16.h" #include "roguelike.h" -extern char is_passable (struct Map * map, uint16_t y, uint16_t x) { +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 <= x && x < map->size.x && 0 <= y && y < map->size.y) - if ('.' == map->cells[y * map->size.x + x]) + 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; } @@ -27,7 +27,7 @@ extern void move_monster (struct World * world, struct Monster * monster) { if (yx_uint16_cmp (t, other_monster->pos)) { update_log (world, "\nMonster hits monster."); return; } } - if (is_passable(world->map, t.y, t.x)) + if (is_passable(world->map, t)) monster->pos = t; } extern void move_player (struct World * world, char d) { @@ -46,7 +46,7 @@ extern void move_player (struct World * world, char d) { else if (EAST == d) dir = "east" ; else if (SOUTH == d) dir = "south"; else if (WEST == d) dir = "west" ; - if (is_passable(world->map, t.y, t.x)) { + if (is_passable(world->map, t)) { msg_content = "You move"; world->player->pos = t; } sprintf(msg, "\n%s %s.", msg_content, dir); diff --git a/src/actors.h b/src/actors.h index c97d91b..51d6612 100644 --- a/src/actors.h +++ b/src/actors.h @@ -15,7 +15,7 @@ struct Monster { char name; struct yx_uint16 pos; }; -extern char is_passable (struct Map *, uint16_t, uint16_t); +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 *); diff --git a/src/roguelike.c b/src/roguelike.c index 0d1e96b..d212388 100644 --- a/src/roguelike.c +++ b/src/roguelike.c @@ -237,12 +237,12 @@ int main (int argc, char *argv[]) { struct Map map = init_map(); world.map = ↦ if (1 == world.turn) { - for (player.pos.y = player.pos.x = 0; 0 == is_passable(&map, player.pos.y, player.pos.x);) { + for (player.pos.y = player.pos.x = 0; 0 == is_passable(&map, player.pos);) { player.pos.y = rrand(0, 0) % map.size.y; player.pos.x = rrand(0, 0) % map.size.x; } struct Monster * monster; for (monster = world.monster; monster != 0; monster = monster->next) - for (monster->pos.y = monster->pos.x = 0; 0 == is_passable(&map, monster->pos.y, monster->pos.x);) { + for (monster->pos.y = monster->pos.x = 0; 0 == is_passable(&map, monster->pos);) { monster->pos.y = rrand(0, 0) % map.size.y; monster->pos.x = rrand(0, 0) % map.size.x; } }