X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=src%2Fserver%2Fio.c;h=d8190c6038ec0f8588e688d988074af5dbc0853f;hb=cf0d81ea863df7adb1bdd862708571b0e40a73cb;hp=14b5e48efaa79016d21269336c765eef7707b051;hpb=b01c00f25907d81051b38d9dc39b6781f087ea90;p=plomrogue diff --git a/src/server/io.c b/src/server/io.c index 14b5e48..d8190c6 100644 --- a/src/server/io.c +++ b/src/server/io.c @@ -18,8 +18,8 @@ #include "../common/try_malloc.h" /* try_malloc() */ #include "cleanup.h" /* set_cleanup_flag() */ #include "hardcoded_strings.h" /* s */ -#include "things.h" /* Thing, ThingType, ThingAction, get_thing_type(), - * get_player() +#include "things.h" /* Thing, ThingType, ThingInMemory, ThingAction, + * get_thing_type(), get_player() */ #include "world.h" /* global world */ @@ -67,7 +67,7 @@ static char * build_visible_map(struct Thing * player); /* Write to "file" game map as visible to "player" right now, as drawn by * build_visible_map(), and thereafter game map as memorized by player in its - * .mem_map. Write one row per \n-delimited line. + * .mem_map and .t_mem. Write one row per \n-delimited line. */ static void write_map(struct Thing * player, FILE * file); @@ -165,6 +165,17 @@ static void write_thing(FILE * file, struct Thing * t) try_fputc('\n', file, __func__); } free(mem_map_copy); + struct ThingInMemory * tm = t->t_mem; + for (; tm; tm = tm->next) + { + write_key_space(file, s[S_CMD_T_MEMTHING]); + write_value(file, tm->type); + try_fputc(' ', file, __func__); + write_value(file, tm->pos.y); + try_fputc(' ', file, __func__); + write_value(file, tm->pos.x); + try_fputc('\n', file, __func__); + } } try_fputc('\n', file, __func__); } @@ -278,7 +289,7 @@ static void write_value_as_line(uint32_t value, FILE * file) static void write_inventory(struct Thing * player, FILE * file) { struct Thing * owned = player->owns; - if (NULL == owned) + if (!owned) { char * empty = "(none)\n"; try_fwrite(empty, strlen(empty), 1, file, __func__); @@ -286,7 +297,7 @@ static void write_inventory(struct Thing * player, FILE * file) else { uint8_t q; - for (q = 0; NULL != owned; q++) + for (q = 0; owned; q++) { struct ThingType * tt = get_thing_type(owned->type); try_fwrite(tt->name, strlen(tt->name), 1, file, __func__); @@ -322,7 +333,7 @@ static char * build_visible_map(struct Thing * player) { for (t = world.things; t != 0; t = t->next) { - if ('v'==player->fov_map[t->pos.y*world.map.length+t->pos.x]) + if ('v' == player->fov_map[t->pos.y*world.map.length+t->pos.x]) { struct ThingType * tt = get_thing_type(t->type); if ( (0 == i && !t->lifepoints && !tt->consumable) @@ -354,14 +365,36 @@ static void write_map(struct Thing * player, FILE * file) try_fputc('\n', file, __func__); } free(visible_map); + uint32_t map_size = world.map.length * world.map.length; + char * mem_map = try_malloc(map_size, __func__); + memcpy(mem_map, player->mem_map, map_size); + uint8_t i; + struct ThingInMemory * tm; + for (i = 0; i < 2; i++) + { + for (tm = player->t_mem; tm; tm = tm->next) + { + if (' ' != player->mem_map[tm->pos.y*world.map.length+tm->pos.x]) + { + struct ThingType * tt = get_thing_type(tm->type); + if ( (0 == i && !tt->consumable) + || (1 == i && tt->consumable)) + { + char c = tt->char_on_map; + mem_map[tm->pos.y * world.map.length + tm->pos.x] = c; + } + } + } + } for (y = 0; y < world.map.length; y++) { for (x = 0; x < world.map.length; x++) { - try_fputc(player->mem_map[y * world.map.length + x], file, __func__); + try_fputc(mem_map[y * world.map.length + x], file, __func__); } try_fputc('\n', file, __func__); } + free(mem_map); }