8 extern char is_passable (struct Map * map, uint16_t y, uint16_t x) {
9 // Check if coordinate on (or beyond) map is accessible to actor movement.
11 if (0 <= x && x < map->size.x && 0 <= y && y < map->size.y)
12 if ('.' == map->cells[y * map->size.x + x])
16 extern void move_monster (struct World * world, struct Monster * monster) {
17 // Move monster in random direction, trigger fighting when hindered by player/monster.
18 char d = rrand(0, 0) % 5;
19 struct yx_uint16 t = mv_yx_in_dir (d, monster->pos);
20 if (yx_uint16_cmp (t, world->player->pos)) {
21 update_log (world, "\nThe monster hits you.");
23 struct Monster * other_monster;
24 for (other_monster = world->monster; other_monster != 0; other_monster = other_monster->next) {
25 if (other_monster == monster)
27 if (yx_uint16_cmp (t, other_monster->pos)) {
28 update_log (world, "\nMonster hits monster.");
30 if (is_passable(world->map, t.y, t.x))
33 extern void move_player (struct World * world, char d) {
34 // Move player in direction d, increment turn counter and update log.
35 struct yx_uint16 t = mv_yx_in_dir (d, world->player->pos);
36 struct Monster * monster;
37 for (monster = world->monster; monster != 0; monster = monster->next)
38 if (yx_uint16_cmp (t, monster->pos)) {
39 update_log (world, "\nYou hit the monster.");
42 char * msg = calloc(25, sizeof(char));
43 char * msg_content = "You fail to move";
45 if (NORTH == d) dir = "north";
46 else if (EAST == d) dir = "east" ;
47 else if (SOUTH == d) dir = "south";
48 else if (WEST == d) dir = "west" ;
49 if (is_passable(world->map, t.y, t.x)) {
50 msg_content = "You move";
51 world->player->pos = t; }
52 sprintf(msg, "\n%s %s.", msg_content, dir);
53 update_log (world, msg);
55 turn_over (world, d); }
57 extern void player_wait (struct World * world) {
58 // Make player wait one turn.
59 update_log (world, "\nYou wait.");
60 turn_over (world, 0); }