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