From: Christian Heller Date: Fri, 21 Nov 2014 00:08:49 +0000 (+0100) Subject: Display stack of things player is standing on. X-Git-Tag: tce~580 X-Git-Url: https://plomlompom.com/repos/?a=commitdiff_plain;h=bc7c3a7ee20d49d725c76d14705b9ef56c096c42;p=plomrogue Display stack of things player is standing on. --- diff --git a/confclient/commands b/confclient/commands index 71004bf..b8b9387 100644 --- a/confclient/commands +++ b/confclient/commands @@ -161,12 +161,12 @@ DESCRIPTION 'map right' COMMAND map_c DESCRIPTION 'map center player' -COMMAND to_a_keywin -DESCRIPTION 'window keys of active window' - COMMAND to_inv DESCRIPTION 'window inventory' +COMMAND to_terrain +DESCRIPTION 'standing-on window' + COMMAND to_g_keywin DESCRIPTION 'window global keys' diff --git a/confclient/interface_conf b/confclient/interface_conf index ff45f81..d2b02e6 100644 --- a/confclient/interface_conf +++ b/confclient/interface_conf @@ -1,3 +1,4 @@ + KEYBINDINGS 'global' KEY 81 quit KEY 87 winconf @@ -10,10 +11,11 @@ KEY 67 save_conf KEY 265 to_mapwin KEY 266 to_infowin KEY 267 to_inv -KEY 268 to_logwin -KEY 269 to_g_keywin -KEY 270 to_wg_keywin -KEY 271 to_wk_keywin +KEY 268 to_terrain +KEY 269 to_logwin +KEY 270 to_g_keywin +KEY 271 to_wg_keywin +KEY 272 to_wk_keywin KEYBINDINGS 'wingeom' KEY 258 shift_f @@ -31,7 +33,7 @@ KEY 258 keyb_dw KEY 259 keyb_uw KEY 10 keyb_mw -WIN_ORDER 'lc0im' +WIN_ORDER 'l0csim' WIN_FOCUS 'm' WINDOW 0 @@ -65,12 +67,18 @@ WINDOW c NAME 'Inventory' BREAK 1 WIDTH 14 -HEIGHT 7 +HEIGHT 11 KEY 68 drop KEY 259 inv_u KEY 258 inv_d KEY 117 use +WINDOW s +NAME 'Standing on' +BREAK 1 +WIDTH 14 +HEIGHT -12 + WINDOW i NAME 'Info' BREAK 2 @@ -80,7 +88,7 @@ HEIGHT 1 WINDOW l NAME 'Log' BREAK 0 -WIDTH 37 +WIDTH 22 HEIGHT -8 WINDOW m diff --git a/confclient/single_wins/info b/confclient/single_wins/info index 34cabd2..4999883 100644 --- a/confclient/single_wins/info +++ b/confclient/single_wins/info @@ -3,10 +3,11 @@ KEY 81 quit KEY 265 to_mapwin KEY 266 to_infowin KEY 267 to_inv -KEY 268 to_logwin -KEY 269 to_g_keywin -KEY 270 to_wg_keywin -KEY 271 to_wk_keywin +KEY 268 to_terrain +KEY 269 to_logwin +KEY 270 to_g_keywin +KEY 271 to_wg_keywin +KEY 272 to_wk_keywin KEY 87 winconf KEY 62 cyc_win_f KEY 60 cyc_win_b @@ -90,6 +91,12 @@ KEY 259 inv_u KEY 258 inv_d KEY 117 use +WINDOW s +NAME 'Standing on' +BREAK 1 +WIDTH 14 +HEIGHT -12 + WINDOW l NAME 'Log' BREAK 0 diff --git a/confclient/single_wins/inventory b/confclient/single_wins/inventory index 763fa72..067b27d 100644 --- a/confclient/single_wins/inventory +++ b/confclient/single_wins/inventory @@ -3,10 +3,11 @@ KEY 81 quit KEY 265 to_mapwin KEY 266 to_infowin KEY 267 to_inv -KEY 268 to_logwin -KEY 269 to_g_keywin -KEY 270 to_wg_keywin -KEY 271 to_wk_keywin +KEY 268 to_terrain +KEY 269 to_logwin +KEY 270 to_g_keywin +KEY 271 to_wg_keywin +KEY 272 to_wk_keywin KEY 87 winconf KEY 62 cyc_win_f KEY 60 cyc_win_b @@ -82,6 +83,12 @@ KEY 258 keyb_dk KEY 259 keyb_uk KEY 10 keyb_mk +WINDOW s +NAME 'Standing on' +BREAK 1 +WIDTH 14 +HEIGHT -12 + WINDOW i NAME 'Info' BREAK 0 diff --git a/confclient/single_wins/log b/confclient/single_wins/log index 42d2fba..81eea84 100644 --- a/confclient/single_wins/log +++ b/confclient/single_wins/log @@ -3,10 +3,11 @@ KEY 81 quit KEY 265 to_mapwin KEY 266 to_infowin KEY 267 to_inv -KEY 268 to_logwin -KEY 269 to_g_keywin -KEY 270 to_wg_keywin -KEY 271 to_wk_keywin +KEY 268 to_terrain +KEY 269 to_logwin +KEY 270 to_g_keywin +KEY 271 to_wg_keywin +KEY 272 to_wk_keywin KEY 87 winconf KEY 62 cyc_win_f KEY 60 cyc_win_b @@ -90,6 +91,12 @@ KEY 259 inv_u KEY 258 inv_d KEY 117 use +WINDOW s +NAME 'Standing on' +BREAK 1 +WIDTH 14 +HEIGHT -12 + WINDOW i NAME 'Info' BREAK 0 diff --git a/confclient/single_wins/map b/confclient/single_wins/map index 689f9c4..d9d6e38 100644 --- a/confclient/single_wins/map +++ b/confclient/single_wins/map @@ -3,10 +3,11 @@ KEY 81 quit KEY 265 to_mapwin KEY 266 to_infowin KEY 267 to_inv -KEY 268 to_logwin -KEY 269 to_g_keywin -KEY 270 to_wg_keywin -KEY 271 to_wk_keywin +KEY 268 to_terrain +KEY 269 to_logwin +KEY 270 to_g_keywin +KEY 271 to_wg_keywin +KEY 272 to_wk_keywin KEY 87 winconf KEY 62 cyc_win_f KEY 60 cyc_win_b @@ -94,6 +95,12 @@ KEY 259 inv_u KEY 258 inv_d KEY 117 use +WINDOW s +NAME 'Standing on' +BREAK 1 +WIDTH 14 +HEIGHT -12 + WINDOW i NAME 'Info' BREAK 0 diff --git a/confclient/single_wins/standing_on b/confclient/single_wins/standing_on new file mode 100644 index 0000000..59ee7b4 --- /dev/null +++ b/confclient/single_wins/standing_on @@ -0,0 +1,126 @@ + +KEYBINDINGS 'global' +KEY 81 quit +KEY 265 to_mapwin +KEY 266 to_infowin +KEY 267 to_inv +KEY 268 to_terrain +KEY 269 to_logwin +KEY 270 to_g_keywin +KEY 271 to_wg_keywin +KEY 272 to_wk_keywin +KEY 87 winconf +KEY 62 cyc_win_f +KEY 60 cyc_win_b +KEY 262 scrl_l +KEY 360 scrl_r +KEY 82 reload_conf +KEY 67 save_conf +KEY 97 ai +KEY 112 pick +KEY 58 wait +KEY 101 move_e +KEY 100 move_d +KEY 99 move_c +KEY 120 move_x +KEY 115 move_s +KEY 119 move_w +KEY 46 map_c +KEY 68 drop +KEY 117 use +KEY 70 to_autofocus + +KEYBINDINGS 'wingeom' +KEY 258 shift_f +KEY 259 shift_b +KEY 42 grow_h +KEY 95 shri_h +KEY 43 grow_v +KEY 45 shri_v +KEY 98 to_break +KEY 121 to_height_t +KEY 120 to_width_t + +KEYBINDINGS 'winkeys' +KEY 258 keyb_dw +KEY 259 keyb_uw +KEY 10 keyb_mw + +WIN_ORDER 's' +WIN_FOCUS 's' + +WINDOW 0 +NAME 'Set global keys' +BREAK 0 +WIDTH 22 +HEIGHT 7 +KEY 258 keyb_dG +KEY 259 keyb_uG +KEY 10 keyb_mG + +WINDOW 1 +NAME 'Set window geometry keys' +BREAK 0 +WIDTH 29 +HEIGHT 9 +KEY 258 keyb_dg +KEY 259 keyb_ug +KEY 10 keyb_mg + +WINDOW 2 +NAME 'Set window keybinding keys' +BREAK 0 +WIDTH 29 +HEIGHT 3 +KEY 258 keyb_dk +KEY 259 keyb_uk +KEY 10 keyb_mk + +WINDOW c +NAME 'Inventory' +BREAK 1 +WIDTH 14 +HEIGHT 11 +KEY 68 drop +KEY 259 inv_u +KEY 258 inv_d +KEY 117 use + +WINDOW s +NAME 'Standing on' +BREAK 1 +WIDTH 0 +HEIGHT 0 + +WINDOW i +NAME 'Info' +BREAK 2 +WIDTH -38 +HEIGHT 1 + +WINDOW l +NAME 'Log' +BREAK 0 +WIDTH 22 +HEIGHT -8 + +WINDOW m +NAME 'Map' +BREAK 0 +WIDTH -38 +HEIGHT -2 +KEY 97 ai +KEY 112 pick +KEY 58 wait +KEY 101 move_e +KEY 100 move_d +KEY 99 move_c +KEY 120 move_x +KEY 115 move_s +KEY 119 move_w +KEY 259 map_u +KEY 258 map_d +KEY 260 map_l +KEY 261 map_r +KEY 46 map_c +KEY 70 to_autofocus diff --git a/src/client/cleanup.c b/src/client/cleanup.c index 60a2625..d889ae9 100644 --- a/src/client/cleanup.c +++ b/src/client/cleanup.c @@ -26,6 +26,7 @@ extern void cleanup() free(world.map.cells); free(world.mem_map); free(world.log); + free(world.things_below_player); free(world.queue); free(world.player_inventory); if (cleanup_flags & CLEANUP_INTERFACE) diff --git a/src/client/control.c b/src/client/control.c index d525d56..cfc9757 100644 --- a/src/client/control.c +++ b/src/client/control.c @@ -154,6 +154,7 @@ static uint8_t try_client_commands(struct Command * command) || try_1args(command, "to_infowin", toggle_window, 'i') || try_1args(command, "to_inv", toggle_window, 'c') || try_1args(command, "to_logwin", toggle_window, 'l') + || try_1args(command, "to_terrain", toggle_window, 's') || try_0args(command, "winconf", toggle_winconfig) || try_1args(command, "grow_h", resize_active_win, '*') || try_1args(command, "shri_h", resize_active_win, '_') diff --git a/src/client/draw_wins.c b/src/client/draw_wins.c index 5b87646..63fb8a0 100644 --- a/src/client/draw_wins.c +++ b/src/client/draw_wins.c @@ -434,6 +434,16 @@ extern void draw_win_inventory(struct Win * win) +extern void draw_win_terrain_stack(struct Win * win) +{ + if (world.things_below_player) + { + add_text_with_linebreaks(win, world.things_below_player); + } +} + + + extern void draw_win_keybindings_global(struct Win * win) { win->center.y = world.kb_global.select; diff --git a/src/client/draw_wins.h b/src/client/draw_wins.h index f760ac8..43e3a12 100644 --- a/src/client/draw_wins.h +++ b/src/client/draw_wins.h @@ -19,6 +19,7 @@ extern void draw_win_log(struct Win * win); extern void draw_win_map(struct Win * win); extern void draw_win_info(struct Win * win); extern void draw_win_inventory(struct Win * win); +extern void draw_win_terrain_stack(struct Win * win); extern void draw_win_active_windows_keys(struct Win * win); extern void draw_win_keybindings_global(struct Win * win); extern void draw_win_keybindings_winconf_geometry(struct Win * win); diff --git a/src/client/io.c b/src/client/io.c index 6b55de9..995ffb5 100644 --- a/src/client/io.c +++ b/src/client/io.c @@ -10,7 +10,7 @@ #include /* PIPE_BUF */ #include /* halfdelay(), getch() */ #include /* NULL */ -#include /* uint8_t, uint16_t, uint32_t */ +#include /* uint8_t, uint16_t, uint32_t, UINT32_MAX */ #include /* FILE, sprintf(), fseek(), fflush() */ #include /* strcmp(), strlen(), memcpy() */ #include /* free(), atoi() */ @@ -80,6 +80,9 @@ static uint8_t read_worldstate(); */ static void test_and_poll_server(); +/* If "string", append \n-prefixed "append", else write "append" as "string". */ +static void nl_append_string(char * append, char ** string); + /* Read messages from queue, act on them. */ static uint8_t read_queue(); @@ -230,35 +233,68 @@ static void test_and_poll_server() +static void nl_append_string(char * append, char ** string) +{ + char * err = "too large sizes"; + exit_trouble(UINT32_MAX < strlen(append), __func__, err); + uint32_t new_size = strlen(append); + uint32_t old_size = 0; + uint8_t add_nl = 0; + if (*string) + { + exit_trouble(UINT32_MAX < new_size + strlen(*string), __func__, err); + old_size = strlen(*string); + add_nl = 1; + } + char * new_string = try_malloc(old_size + add_nl + new_size + 1, __func__); + memcpy(new_string, *string, old_size); + char * pattern = add_nl ? "\n%s" : "%s"; + int test = sprintf(new_string + old_size, pattern, append); + exit_trouble(test < 0, __func__, "sprintf"); + free(*string); + *string = new_string; +} + + + static uint8_t read_queue() { + static uint8_t things_below_player_parsing = 0; uint8_t ret = 0; char * msg; while (NULL != (msg = get_message_from_queue(&world.queue))) { char * log_prefix = "LOG "; - if (!strcmp(msg, "NEW_WORLD")) + if (!strcmp(msg, "THINGS_BELOW_PLAYER START")) { ret = 1; - free(world.log); - world.log = NULL; + things_below_player_parsing = 1; + free(world.things_below_player); + world.things_below_player = NULL; + } + else if (!strcmp(msg, "THINGS_BELOW_PLAYER END")) + { + things_below_player_parsing = 0; + } + else if (things_below_player_parsing) + { + ret = 1; + nl_append_string(msg, &world.things_below_player); } else if (!strncmp(msg, log_prefix, strlen(log_prefix))) { ret = 1; - char * log_msg = msg + strlen(log_prefix); - int old_size = 0; - if (world.log) - { - old_size = strlen(world.log); - } - int new_size = strlen(log_msg); - char * new_log = try_malloc(old_size + 1 + new_size + 1, __func__); - memcpy(new_log, world.log, old_size); - int test = sprintf(new_log + old_size, "\n%s", log_msg); - exit_trouble(test < 0, __func__, "sprintf"); + nl_append_string(msg + strlen(log_prefix), &world.log); + } + else if (!strcmp(msg, "NEW_WORLD")) + { + ret = 1; free(world.log); - world.log = new_log; + world.log = NULL; + } + else if (!strcmp(msg, "WORLD_UPDATED")) + { + send("STACK"); } free(msg); } diff --git a/src/client/main.c b/src/client/main.c index d08ac7d..2c1fbf4 100644 --- a/src/client/main.c +++ b/src/client/main.c @@ -33,7 +33,7 @@ int main(int argc, char * argv[]) /* Declare hard-coded paths and values here. */ world.path_commands = "confclient/commands"; world.path_interface = "confclient/interface_conf"; - world.winDB.legal_ids = "012cilm"; + world.winDB.legal_ids = "012cilms"; char * path_server_in = "server/in"; char * path_server_out = "server/out"; diff --git a/src/client/windows.c b/src/client/windows.c index 576cd56..b12db33 100644 --- a/src/client/windows.c +++ b/src/client/windows.c @@ -23,7 +23,8 @@ * draw_win_inventory(), draw_win_info(), draw_win_log(), * draw_win_keybindings_winconf_keybindings(), * draw_win_keybindings_winconf_geometry(), - * draw_win_keybindings_global(), draw_win_map() + * draw_win_keybindings_global(), draw_win_map(), + * draw_win_terrain_stack() */ #include "wincontrol.h" /* toggle_window() */ #include "world.h" /* world */ @@ -118,6 +119,7 @@ static void (* get_drawfunc_by_char(char c)) () { void (* f) (struct Win *) = NULL; if ( match_func(c, &f, 'c', draw_win_inventory) + || match_func(c, &f, 's', draw_win_terrain_stack) || match_func(c, &f, 'i', draw_win_info) || match_func(c, &f, 'l', draw_win_log) || match_func(c, &f, 'm', draw_win_map) diff --git a/src/client/world.h b/src/client/world.h index 745100a..e907922 100644 --- a/src/client/world.h +++ b/src/client/world.h @@ -33,11 +33,12 @@ struct World struct Map map; /* game map geometry and content of player's map view */ time_t last_update; /* used for comparison with worldstate file's mtime */ char * log; /* log of player's activities */ + char * things_below_player; /* list of things below the player */ char * path_interface; /* path of interface configuration file */ char * path_commands; /* path of commands config file */ char * player_inventory; /* one-item-per-line string list of owned items */ char * mem_map; /* map cells of player's map memory */ - char * queue; /* Stores un-processed messages read from the input file. */ + char * queue; /* stores un-processed messages read from the input file */ struct yx_uint8 player_pos; /* coordinates of player on map */ uint16_t turn; /* world/game turn */ uint8_t halfdelay; /* how long to wait for getch() input in io_loop() */ diff --git a/src/common/parse_file.h b/src/common/parse_file.h index 87d3cdf..e0e3c7a 100644 --- a/src/common/parse_file.h +++ b/src/common/parse_file.h @@ -36,7 +36,7 @@ extern uint8_t err_line(uint8_t test, char * msg); * the second, with the next token_from_line() call starting its token search * after that second quote. The only way to return an empty string (instead of * NULL) as a token is to delimit the token by two succeeding single quotes. - * */ + */ extern char * token_from_line(char * line); /* Test for "string" to represent proper int16 (type: "i"), uint8 ("8"), uint16