3 * This file is part of PlomRogue. PlomRogue is licensed under the GPL version 3
4 * or any later version. For details on its copyright, license, and warranties,
5 * see the file NOTICE in the root directory of the PlomRogue source package.
9 #include <stdint.h> /* uint8_t */
10 #include <stdlib.h> /* free() */
11 #include <stdio.h> /* sprintf() */
12 #include <string.h> /* strlen(), strncmp() */
13 #include "../common/try_malloc.h" /* try_malloc() */
14 #include "../common/rexit.h" /* exit_trouble() */
15 #include "io.h" /* send() */
16 #include "world.h" /* for world */
20 extern void toggle_lookmode()
24 world.look_pos = world.player_pos;
36 extern uint8_t lookmode_nav(char * command)
38 char * prefix = "move_";
39 uint8_t len_pref = strlen(prefix);
40 if (!strncmp(prefix, command, len_pref) && strlen(command) - 1 == len_pref)
42 uint8_t open_north = world.look_pos.y > 0;
43 uint8_t open_south = world.look_pos.y < world.map.length - 1;
44 uint8_t open_west = world.look_pos.x > 0;
45 uint8_t open_east = world.look_pos.x < world.map.length - 1;
46 uint8_t indent = world.look_pos.y % 2;
47 if ('s' == command[len_pref])
49 world.look_pos.x = world.look_pos.x - open_west;
51 else if ('d' == command[len_pref])
53 world.look_pos.x = world.look_pos.x + open_east;
55 else if ('w' == command[len_pref])
57 world.look_pos.y = world.look_pos.y - open_north;
58 world.look_pos.x = world.look_pos.x - !indent * open_west;
60 else if ('e' == command[len_pref])
62 world.look_pos.y = world.look_pos.y - open_north;
63 world.look_pos.x = world.look_pos.x + indent * open_east;
65 else if ('x' == command[len_pref])
67 world.look_pos.y = world.look_pos.y + open_south;
68 world.look_pos.x = world.look_pos.x - !indent * open_west;
70 else if ('c' == command[len_pref])
72 world.look_pos.y = world.look_pos.y + open_south;
73 world.look_pos.x = world.look_pos.x + indent * open_east;
87 extern void query_mapcell()
89 free(world.things_here);
90 world.things_here = NULL;
91 char * stack = "THINGS_HERE";
92 char * stack_query = try_malloc(strlen(stack) +1+3 +1+3 +1, __func__);
93 uint8_t y = world.look ? world.look_pos.y : world.player_pos.y;
94 uint8_t x = world.look ? world.look_pos.x : world.player_pos.x;
95 int test = sprintf(stack_query, "%s %d %d", stack, y, x);
96 exit_trouble(test < 0, __func__, "sprintf");