X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=src%2Fmisc.c;h=bddf571288bc6860ef143d679042687d9545dd1a;hb=18fefabcc05bb3903384efbcc92f4303d9ac9567;hp=16ddc38a3f89cbff028bc1729cb34597fbe20bb8;hpb=fb8ddca6abc66eb7e52a007850689309b4cda938;p=plomrogue diff --git a/src/misc.c b/src/misc.c index 16ddc38..bddf571 100644 --- a/src/misc.c +++ b/src/misc.c @@ -9,10 +9,10 @@ #include "readwrite.h" /* for [read/write]_uint[8/16/32][_bigendian](), * try_fopen(), try_fclose() */ -#include "map_objects.h" /* for struct Monster, read_map_objects(), +#include "map_objects.h" /* for struct MapObj, get_player(), read_map_objects(), * write_map_objects() */ -#include "map_object_actions.h" /* for is_passable(), move_monster() */ +#include "map_object_actions.h" /* for is_passable(), move_actor() */ #include "map.h" /* for Map struct */ #include "main.h" /* for World struct */ #include "yx_uint16.h" /* for yx_uint16 struct */ @@ -22,6 +22,8 @@ * sorted_wintoggle_and_activate() */ #include "windows.h" /* for suspend_win() */ +#include "command_db.h" /* for is_command_id_shortdsc() */ + extern char * trouble_msg(struct World * w, char * parent, char * child) @@ -212,6 +214,11 @@ extern void turn_over(struct World * world, char action) } try_fclose(file_old, world, f_name); exit_err(write_uint8(action, file_new), world, err_write); + if (is_command_id_shortdsc(world, action, "drop")) + { + uint8_t inventory_select = world->old_inventory_select; + exit_err(write_uint8(inventory_select, file_new), world, err_write); + } try_fclose_unlink_rename(file_new, recordfile_tmp, recordfile, world, f_name); } @@ -222,9 +229,9 @@ extern void turn_over(struct World * world, char action) monster != 0; monster = monster->next) { - if (0 < monster->lifepoints) + if (0 < monster->lifepoints && 0 != monster->id) { - move_monster(world, monster); + move_actor(world, monster, rrand() % 5); } } } @@ -234,11 +241,9 @@ extern void turn_over(struct World * world, char action) extern void save_game(struct World * world) { char * f_name = "save_game()"; - char * savefile_tmp = "savefile_tmp"; char * savefile = "savefile"; FILE * file = try_fopen(savefile_tmp, "w", world, f_name); - char line[12]; sprintf(line, "%d\n", world->seed); try_fwrite(line, strlen(line), 1, file, world, f_name); @@ -246,14 +251,7 @@ extern void save_game(struct World * world) try_fwrite(line, strlen(line), 1, file, world, f_name); sprintf(line, "%d\n", world->score); try_fwrite(line, strlen(line), 1, file, world, f_name); - sprintf(line, "%d\n", world->player->hitpoints); - try_fwrite(line, strlen(line), 1, file, world, f_name); - sprintf(line, "%d\n", world->player->pos.y); - try_fwrite(line, strlen(line), 1, file, world, f_name); - sprintf(line, "%d\n", world->player->pos.x); - try_fwrite(line, strlen(line), 1, file, world, f_name); write_map_objects(world, file); - try_fclose_unlink_rename(file, savefile_tmp, savefile, world, f_name); } @@ -272,12 +270,6 @@ extern void load_game(struct World * world) world->turn = atoi(line); try_fgets(line, linemax + 1, file, world, f_name); world->score = atoi(line); - try_fgets(line, linemax + 1, file, world, f_name); - world->player->hitpoints = atoi(line); - try_fgets(line, linemax + 1, file, world, f_name); - world->player->pos.y = atoi(line); - try_fgets(line, linemax + 1, file, world, f_name); - world->player->pos.x = atoi(line); read_map_objects(world, file, line, linemax); try_fclose(file, world, f_name); } @@ -294,3 +286,29 @@ extern struct yx_uint16 find_passable_pos(struct Map * map) } return pos; } + + + +extern void nav_inventory(struct World * world, char dir) +{ + if ('u' == dir) + { + if (world->inventory_select > 0) + { + world->inventory_select--; + } + return; + } + struct MapObj * player = get_player(world); + struct MapObj * owned = player->owns; + if (NULL == owned) + { + return; + } + uint8_t n_owned = 0; + for (; NULL != owned->next; owned = owned->next, n_owned++); + if (world->inventory_select < n_owned) + { + world->inventory_select++; + } +}