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 "../common/yx_uint8.h" /* yx_uint8 */
16 #include "io.h" /* send() */
17 #include "windows.h" /* struct Win, center_offset(), get_win_by_id() */
18 #include "world.h" /* for global world */
22 extern void map_scroll(char d)
24 struct Win * win = get_win_by_id('m');
26 if (('8' == d || '2' == d) && world.map.length > win->frame_size.y)
28 offset = center_offset(win->center.y,
29 world.map.length, win->frame_size.y);
30 win->center.y = offset + (win->frame_size.y / 2);
31 if ('2' == d && win->center.y < world.map.length - 1)
36 win->center.y = win->center.y - ('8' == d && win->center.y > 0);
38 else if (('4' == d || '6' == d) && (world.map.length*2) > win->frame_size.x)
40 offset = center_offset(win->center.x,
41 world.map.length*2, win->frame_size.x);
42 win->center.x = offset + (win->frame_size.x / 2);
43 if ('6' == d && win->center.x < (world.map.length * 2) - 1)
48 win->center.x = win->center.x - ('4' == d && win->center.x > 0);
54 extern void toggle_lookmode()
58 world.look_pos = world.player_pos;
70 extern uint8_t lookmode_nav(char * command)
72 char * prefix = "move_";
73 uint8_t len_pref = strlen(prefix);
74 if (!strncmp(prefix, command, len_pref) && strlen(command) - 1 == len_pref)
76 uint8_t open_north = world.look_pos.y > 0;
77 uint8_t open_south = world.look_pos.y < world.map.length - 1;
78 uint8_t open_west = world.look_pos.x > 0;
79 uint8_t open_east = world.look_pos.x < world.map.length - 1;
80 uint8_t indent = world.look_pos.y % 2;
81 if ('s' == command[len_pref])
83 world.look_pos.x = world.look_pos.x - open_west;
85 else if ('d' == command[len_pref])
87 world.look_pos.x = world.look_pos.x + open_east;
89 else if ('w' == command[len_pref])
91 world.look_pos.y = world.look_pos.y - open_north;
92 world.look_pos.x = world.look_pos.x - !indent * open_west;
94 else if ('e' == command[len_pref])
96 world.look_pos.y = world.look_pos.y - open_north;
97 world.look_pos.x = world.look_pos.x + indent * open_east;
99 else if ('x' == command[len_pref])
101 world.look_pos.y = world.look_pos.y + open_south;
102 world.look_pos.x = world.look_pos.x - !indent * open_west;
104 else if ('c' == command[len_pref])
106 world.look_pos.y = world.look_pos.y + open_south;
107 world.look_pos.x = world.look_pos.x + indent * open_east;
121 extern void query_mapcell()
123 free(world.things_here);
124 world.things_here = NULL;
125 char * stack = "THINGS_HERE";
126 char * stack_query = try_malloc(strlen(stack) +1+3 +1+3 +1, __func__);
127 uint8_t y = world.look ? world.look_pos.y : world.player_pos.y;
128 uint8_t x = world.look ? world.look_pos.x : world.player_pos.x;
129 int test = sprintf(stack_query, "%s %d %d", stack, y, x);
130 exit_trouble(test < 0, __func__, "sprintf");