X-Git-Url: https://plomlompom.com/repos/?p=plomrogue;a=blobdiff_plain;f=src%2Fclient%2Fmap.c;h=75dd6dee5a6571ec6e5d89a694964628a03b04bf;hp=e08e7b31af79f8858ccc85c6ccd7d7bbd7158764;hb=258e57c1621533e206610453047d829cc8aa13fe;hpb=81630285494cf6d9e5ddd845e4e55702d87029b0 diff --git a/src/client/map.c b/src/client/map.c index e08e7b3..75dd6de 100644 --- a/src/client/map.c +++ b/src/client/map.c @@ -7,6 +7,13 @@ #include "map.h" #include /* uint8_t */ +#include /* free() */ +#include /* sprintf() */ +#include /* strlen(), strncmp() */ +#include "../common/try_malloc.h" /* try_malloc() */ +#include "../common/rexit.h" /* exit_trouble() */ +#include "../common/yx_uint8.h" /* yx_uint8 */ +#include "io.h" /* send() */ #include "windows.h" /* struct Win, center_offset(), get_win_by_id() */ #include "world.h" /* for global world */ @@ -14,7 +21,7 @@ extern void map_scroll(char d) { - world.focus_each_turn = 0; + world.autofocus = 0; struct Win * win = get_win_by_id('m'); uint16_t offset; if (('8' == d || '2' == d) && world.map.length > win->frame_size.y) @@ -48,13 +55,98 @@ extern void map_scroll(char d) extern void map_center() { struct Win * win_map = get_win_by_id('m'); - win_map->center.y = world.player_pos.y; - win_map->center.x = world.player_pos.x * 2 + (world.player_pos.y % 2); + struct yx_uint8 pos = world.look ? world.look_pos : world.player_pos; + win_map->center.y = pos.y; + win_map->center.x = pos.x * 2 + (pos.y % 2); } extern void toggle_autofocus() { - world.focus_each_turn = world.focus_each_turn ? 0 : 1; + world.autofocus = world.autofocus ? 0 : 1; +} + + + +extern void toggle_lookmode() +{ + if (!world.look) + { + world.look_pos = world.player_pos; + world.look = 1; + } + else + { + world.look = 0; + } + query_mapcell(); +} + + + +extern uint8_t lookmode_nav(char * command) +{ + char * prefix = "move_"; + uint8_t len_pref = strlen(prefix); + if (!strncmp(prefix, command, len_pref) && strlen(command) - 1 == len_pref) + { + uint8_t open_north = world.look_pos.y > 0; + uint8_t open_south = world.look_pos.y < world.map.length - 1; + uint8_t open_west = world.look_pos.x > 0; + uint8_t open_east = world.look_pos.x < world.map.length - 1; + uint8_t indent = world.look_pos.y % 2; + if ('s' == command[len_pref]) + { + world.look_pos.x = world.look_pos.x - open_west; + } + else if ('d' == command[len_pref]) + { + world.look_pos.x = world.look_pos.x + open_east; + } + else if ('w' == command[len_pref]) + { + world.look_pos.y = world.look_pos.y - open_north; + world.look_pos.x = world.look_pos.x - !indent * open_west; + } + else if ('e' == command[len_pref]) + { + world.look_pos.y = world.look_pos.y - open_north; + world.look_pos.x = world.look_pos.x + indent * open_east; + } + else if ('x' == command[len_pref]) + { + world.look_pos.y = world.look_pos.y + open_south; + world.look_pos.x = world.look_pos.x - !indent * open_west; + } + else if ('c' == command[len_pref]) + { + world.look_pos.y = world.look_pos.y + open_south; + world.look_pos.x = world.look_pos.x + indent * open_east; + } + else + { + return 0; + } + map_center(); + query_mapcell(); + return 1; + } + return 0; +} + + + +extern void query_mapcell() +{ + free(world.things_here); + world.things_here = NULL; + char * stack = "THINGS_HERE"; + char * stack_query = try_malloc(strlen(stack) +1+3 +1+3 +1, __func__); + uint8_t y = world.look ? world.look_pos.y : world.player_pos.y; + uint8_t x = world.look ? world.look_pos.x : world.player_pos.x; + int test = sprintf(stack_query, "%s %d %d", stack, y, x); + exit_trouble(test < 0, __func__, "sprintf"); + send(stack_query); + free(stack_query); }