extern uint8_t player_control_by_id(int action)
{
if ( try_player_cmd(action, "wait", "wait", 0)
- || try_player_cmd(action, "drop", "drop", world.inventory_select)
+ || try_player_cmd(action, "drop", "drop", world.inventory_sel)
|| try_player_cmd(action, "pick", "pick_up", 0)
- || try_player_cmd(action, "use", "use", world.inventory_select)
+ || try_player_cmd(action, "use", "use", world.inventory_sel)
|| try_player_cmd(action, "player_u", "move", 'N')
|| try_player_cmd(action, "player_d", "move", 'S')
|| try_player_cmd(action, "player_r", "move", 'E')
add_line(win, "(none)", 0, 0);
return;
}
- win->center.y = world.inventory_select;
+ win->center.y = world.inventory_sel;
struct MapObj * owned = player->owns;
uint8_t y;
for (y = 0; NULL != owned; y++)
{
attr_t attri = 0;
- if (y == world.inventory_select)
+ if (y == world.inventory_sel)
{
attri = A_REVERSE;
}
win_map->center = player->pos;
/* Initialize player's inventory selection index to start position. */
- world.inventory_select = 0;
+ world.inventory_sel = 0;
/* Replay mode. */
int key;
if ( is_command_id_shortdsc(action, "drop")
|| is_command_id_shortdsc(action, "use"))
{
- world.inventory_select = try_fgetc_noeof(file, f_name);
+ world.inventory_sel = try_fgetc_noeof(file, f_name);
}
player_control_by_id(action);
}
if ( is_command_id_shortdsc(action, "drop")
|| is_command_id_shortdsc(action, "use"))
{
- world.inventory_select = try_fgetc_noeof(file, f_name);
+ world.inventory_sel = try_fgetc_noeof(file, f_name);
}
player_control_by_id(action);
}
uint8_t map_obj_count; /* Counts map objects generated so far. */
struct MapObjDef * map_obj_defs; /* Map object type definitions chain. */
struct MapObj * map_objs; /* Pointer to map objects chain start. */
- uint8_t inventory_select; /* Player's inventory selection index. */
+ uint8_t inventory_sel; /* Player's inventory selection index. */
struct MapObjAct * map_obj_acts; /* Pointer to map object actions chain. */
} world;
static void actor_hits_actor(struct MapObj * hitter, struct MapObj * hitted);
/* Bonus stuff to actor_*() to happen if actor==player. Mostly writing of log
- * messages; _pick and _drop also decrement world.inventory_select by 1 if >0.
+ * messages; _pick and _drop also decrement world.inventory_sel by 1 if >0.
*/
static void playerbonus_wait();
static void playerbonus_move(char d, uint8_t passable);
else
{
update_log("\nYou drop an object.");
- if (0 < world.inventory_select)
+ if (0 < world.inventory_sel)
{
- world.inventory_select--;
+ world.inventory_sel--;
}
}
}
else
{
update_log("\nYou consume MAGIC MEAT.");
- if (0 < world.inventory_select)
+ if (0 < world.inventory_sel)
{
- world.inventory_select--;
+ world.inventory_sel--;
}
}
}
extern uint16_t rrand()
-{
- /* Constants as recommended by POSIX.1-2001 (see man page rand(3)). */
+{ /* Constants as recommended by POSIX.1-2001 (see man page rand(3)). */
world.seed = ((world.seed * 1103515245) + 12345) % 4294967296;
return (world.seed >> 16); /* Ignore less random least significant bits. */
}
-extern uint16_t center_offset(uint16_t pos, uint16_t mapsize,
+extern uint16_t center_offset(uint16_t position, uint16_t mapsize,
uint16_t framesize)
{
uint16_t offset = 0;
if (mapsize > framesize)
{
- if (pos > framesize / 2)
+ if (position > framesize / 2)
{
- if (pos < mapsize - (framesize / 2))
+ if (position < mapsize - (framesize / 2))
{
- offset = pos - (framesize / 2);
+ offset = position - (framesize / 2);
}
else
{
if ( is_command_id_shortdsc(action, "drop")
|| is_command_id_shortdsc(action, "use"))
{
- try_fputc(world.inventory_select, file_new, f_name);
+ try_fputc(world.inventory_sel, file_new, f_name);
}
try_fclose_unlink_rename(file_new, recordfile_tmp, recordfile, f_name);
}
{
if ('u' == dir)
{
- if (world.inventory_select > 0)
- {
- world.inventory_select--;
- }
+ world.inventory_sel = world.inventory_sel - (world.inventory_sel > 0);
return;
}
struct MapObj * player = get_player();
}
uint8_t n_owned = 0;
for (; NULL != owned->next; owned = owned->next, n_owned++);
- if (world.inventory_select < n_owned)
- {
- world.inventory_select++;
- }
+ world.inventory_sel = world.inventory_sel + (world.inventory_sel < n_owned);
}
*/
extern uint16_t rrand();
-/* Wrappers to malloc(), calloc() from function called "f" calling exit_err()
- * with trouble_msg() error message if necessary.
- */
+/* Wrappers to malloc(), calloc() from function "f"; exit_trouble() on error. */
extern void * try_malloc(size_t size, char * f);
extern void * try_calloc(size_t nmemb, size_t size, char * f);
-/* Check if tempfile "path" exists, and if so, exit with explanation that. */
-extern void check_tempfile(char * path);
-
/* If one and only one of files at "p1", "p2" exists, fail with explanation. */
extern void check_files_xor(char * p1, char * p2);
+/* Check if tempfile "path" exists, and if so, exit with explanation that. */
+extern void check_tempfile(char * path);
+
/* Save / load / unload (free) / reload interface configuration data. */
extern void save_interface_conf();
extern void load_interface_conf();
extern void unload_interface_conf();
extern void reload_interface_conf();
-/* Update game log by appending "text", or by appending a "." if "text" is the
- * same as the last one passed.
- */
+/* Append "text" to game log, or a "." if "text" is the same as the last one. */
extern void update_log(char * text);
-/* Return the offset necessary to center a map of "mapsize" on position "pos" in
- * a frame of "framesize.
- */
-extern uint16_t center_offset(uint16_t pos,
+/* Return offset nto center map of "mapsize" on "position" in "framesize". */
+extern uint16_t center_offset(uint16_t position,
uint16_t mapsize, uint16_t framesize);
-/* Record last player "action" in game record file "record, increment the game
- * turn and trigger enemy movement.
- */
+/* Record "action" in record file, do all movements until player's next turn. */
extern void turn_over(char action);
/* Save or load current game data to / from file "savefile". */
extern void save_game();
extern void load_game();
-/* Return a random position on the map "map" that is passable (as determined by
- * is_passable().
- */
+/* Return random passable (as by is_passable()) position on "map". */
extern struct yx_uint16 find_passable_pos(struct Map * map);
-/* Navigate (as far as possible) up (dir=='u') or (else) down in player's
- * inventory selection.
- */
+/* Move world.inventory_sel up ("dir"="u") or down (else) as far as possible. */
extern void nav_inventory(char dir);
/* readwrite.c */
#include "readwrite.h"
+#include <stdlib.h> /* for size_t */
#include <stdio.h> /* for FILE typedef, fopen(), fgetc(), fputc(), fseek(),
* sprintf(), fwrite(), ferror()
*/
#include <string.h> /* for strlen() */
#include <unistd.h> /* for unlink() */
#include "rexit.h" /* for exit_err(), exit_trouble() */
-#include "main.h" /* for world global */