width can't be higher than uint8_t values.
{
try_resize_winmap(win, world.map.size.y, world.map.size.x);
uint16_t z = 0;
- uint16_t x, y;
+ uint8_t x, y;
for (y = 0; y < world.map.size.y; y++)
{
for (x = 0; x < world.map.size.x; x++)
char * f_name = "read_map_cells()";
free(world.map.cells);
world.map.cells = try_malloc(world.map.size.y * world.map.size.x, f_name);
- uint16_t y, x;
+ uint8_t y, x;
for (y = 0; y < world.map.size.y; y++)
{
for (x = 0; x < world.map.size.x; x++)
/* src/client/map.c */
#include "map.h"
-#include <stdint.h> /* uint16_t */
+#include <stdint.h> /* uint8_t */
#include "misc.h" /* center_offset() */
#include "windows.h" /* struct Win, get_win_by_id() */
#include "world.h" /* for global world */
extern void map_scroll(char d)
{
struct Win * win = get_win_by_id('m');
- uint16_t offset;
+ uint8_t offset;
if (('8' == d || '2' == d) && world.map.size.y > win->frame_size.y)
{
offset = center_offset(win->center.y,
extern void map_center()
{
struct Win * win_map = get_win_by_id('m');
- win_map->center = world.player_pos;
+ win_map->center.y = world.player_pos.y;
+ win_map->center.x = world.player_pos.x;
}
#include <ncurses.h> /* WINDOW, chtype */
#include <stdint.h> /* uint8_t, int16_t, uint16_t */
-#include "keybindings.h" /* struct KeyBindingDB */
#include "../common/yx_uint16.h" /* yx_uint16 struct */
+#include "keybindings.h" /* struct KeyBindingDB */
#include <stdint.h> /* uint8_t, uint16_t */
#include <sys/types.h> /* time_t */
#include "map.h" /* struct Map */
-#include "../common/yx_uint16.h" /* struct yx_uint16 */
+#include "../common/yx_uint8.h" /* struct yx_uint8 */
#include "keybindings.h" /* stuct KeyBindingDB */
#include "command_db.h" /* struct CommandDB */
#include "windows.h" /* WinDB */
struct KeyBindingDB kb_winkeys; /* Win keybindings config view keybindings*/
struct Map map; /* game map geometry and content */
time_t last_update; /* used for comparison with server outfile' mtime */
- struct yx_uint16 player_pos; /* coordinates of player on map */
char * log; /* log of player's activities */
char * path_server_in; /* path of server's input fifo */
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 * delim; /* delimiter for multi-line blocks in config files */
+ struct yx_uint8 player_pos; /* coordinates of player on map */
uint16_t turn; /* world/game turn */
uint16_t player_score; /* player's score*/
uint8_t halfdelay; /* how long to wait for getch() input in io_loop() */
+++ /dev/null
-/* src/common/map.h
- *
- * Struct for the game map.
- */
-
-#ifndef MAP_H
-#define MAP_H
-
-#include "yx_uint16.h" /* yx_uint16 struct */
-
-
-
-struct Map
-{
- struct yx_uint16 size; /* map's height/width in number of cells */
- char * cells; /* sequence of bytes encoding map cells */
-};
-
-
-
-#endif
/* yx_uint16.h
*
- * Struct coordinates in 2-dimensional space (such as the ncurses screen and
- * game maps).
+ * Used for window / screen maps and game map size.
*/
#ifndef YX_UINT16_H
static void write_map(FILE * file)
{
char * f_name = "write_map()";
- uint32_t map_size = world.map.size.y * world.map.size.x;
+ uint16_t map_size = world.map.size.y * world.map.size.x;
char visible_map[map_size];
memcpy(visible_map, world.map.cells, map_size);
struct MapObj * o;
}
}
}
- uint16_t x, y;
+ uint8_t x, y;
for (y = 0; y < world.map.size.y; y++)
{
for (x = 0; x < world.map.size.x; x++)
/* src/server/map.c */
#include "map.h"
-#include <stdint.h> /* uint8_t, uint16_t, uint32_t */
+#include <stdint.h> /* uint8_t, uint16_t */
#include "../common/try_malloc.h" /* try_malloc() */
-#include "../common/yx_uint16.h" /* struct yx_uint16 */
+#include "../common/yx_uint8.h" /* struct yx_uint8 */
#include "rrand.h" /* rrand() */
#include "world.h" /* global world */
extern void init_map()
{
char * f_name = "init_map()";
- uint32_t size = world.map.size.x * world.map.size.y;
+ uint16_t size = world.map.size.x * world.map.size.y;
world.map.cells = try_malloc(size, f_name);
- uint16_t y, x;
+ uint8_t y, x;
for (y = 0; y < world.map.size.y; y++)
{
for (x = 0;
world.map.cells[(y * world.map.size.x) + x] = '~', x++);
}
world.map.cells[size / 2 + (world.map.size.x / 2)] = '.';
- uint32_t curpos;
+ uint16_t curpos;
while (1)
{
y = rrand() % world.map.size.y;
-extern uint8_t is_passable(struct yx_uint16 pos)
+extern uint8_t is_passable(struct yx_uint8 pos)
{
uint8_t passable = 0;
if ( 0 <= pos.x && pos.x < world.map.size.x
#define MAP_H
#include <stdint.h> /* uint8_t */
+#include "../common/yx_uint8.h" /* yx_uint8 struct */
#include "../common/yx_uint16.h" /* yx_uint16 struct */
struct Map
{
- struct yx_uint16 size; /* Map's height/width in number of cells. */
+ struct yx_uint16 size; /* Map's height/width (use max. 256x256)! */
char * cells; /* Sequence of bytes encoding map cells. */
uint8_t dist_orthogonal; /* Ratio of the diagonal movement penalty as */
uint8_t dist_diagonal; /* encoded by (.dist_diagonal/.dist_orthonal). */
/* Check if coordinate "pos" on (or beyond) world.map is accessible to map
* object movement.
*/
-extern uint8_t is_passable(struct yx_uint16 pos);
+extern uint8_t is_passable(struct yx_uint8 pos);
*/
#include "../common/rexit.h" /* exit_err(), exit_trouble() */
#include "../common/try_malloc.h" /* try_malloc() */
-#include "../common/yx_uint16.h" /* yx_uint16 struct */
+#include "../common/yx_uint8.h" /* struct yx_uint8 */
#include "cleanup.h" /* set_cleanup_flag() */
#include "map_objects.h" /* structs MapObj, MapObjDef, get_player(),
* set_object_position(), own_map_object(),
* get_map_object_def()
*/
#include "map.h" /* is_passable() */
-#include "yx_uint16.h" /* mv_yx_in_dir(), yx_uint16_cmp() */
+#include "yx_uint8.h" /* mv_yx_in_dir(), yx_uint8_cmp() */
#include "world.h" /* global world */
{
char * f_name = "init_map_object_actions()";
FILE * file = try_fopen(world.path_map_obj_acts, "r", f_name);
- uint16_t linemax = textfile_sizes(file, NULL);
+ uint32_t linemax = textfile_sizes(file, NULL);
char line[linemax + 1];
struct MapObjAct ** moa_ptr_ptr = &world.map_obj_acts;
char * context = "Failed reading map object actions config file. ";
extern void actor_move(struct MapObj * mo)
{
char d = mo->arg;
- struct yx_uint16 target = mv_yx_in_dir(d, mo->pos);
+ struct yx_uint8 target = mv_yx_in_dir(d, mo->pos);
struct MapObj * other_mo;
for (other_mo = world.map_objs; other_mo != 0; other_mo = other_mo->next)
{
{
continue;
}
- if (yx_uint16_cmp(&target, &other_mo->pos))
+ if (yx_uint8_cmp(&target, &other_mo->pos))
{
actor_hits_actor(mo, other_mo);
return;
struct MapObj * mo_i;
for (mo_i = world.map_objs; NULL != mo_i; mo_i = mo_i->next)
{
- if (mo_i != mo && yx_uint16_cmp(&mo_i->pos, &mo->pos))
+ if (mo_i != mo && yx_uint8_cmp(&mo_i->pos, &mo->pos))
{
picked = mo_i;
}
*/
#include "../common/rexit.h" /* exit_err(), exit_trouble() */
#include "../common/try_malloc.h" /* try_malloc() */
-#include "../common/yx_uint16.h" /* yx_uint16 struct */
+#include "../common/yx_uint8.h" /* yx_uint8 struct */
#include "cleanup.h" /* set_cleanup_flag() */
#include "map.h" /* is_passable() */
#include "rrand.h" /* rrand() */
#include "world.h" /* global world */
-#include "yx_uint16.h" /* yx_uint16_cmp() */
+#include "yx_uint8.h" /* yx_uint8_cmp() */
static struct MapObj * get_map_object(struct MapObj * ptr, uint8_t id);
/* Return random passable (as by is_passable()) position on world.map. */
-static struct yx_uint16 find_passable_pos();
+static struct yx_uint8 find_passable_pos();
/* Add object of "type" to map on random position. Don't place actor on actor.*/
static void add_map_object(uint8_t type);
-static struct yx_uint16 find_passable_pos()
+static struct yx_uint8 find_passable_pos()
{
- struct yx_uint16 pos;
+ struct yx_uint8 pos;
for (pos.y = pos.x = 0; 0 == is_passable(pos);)
{
pos.y = rrand() % world.map.size.y;
mo->lifepoints = mod->lifepoints;
while (1)
{
- struct yx_uint16 pos = find_passable_pos(world.map);
+ struct yx_uint8 pos = find_passable_pos(world.map);
struct MapObj * mo_ptr;
uint8_t clear = 1;
for (mo_ptr = world.map_objs; mo_ptr != NULL; mo_ptr = mo_ptr->next)
{
- if (yx_uint16_cmp(&pos, &mo_ptr->pos) && 0 != mo_ptr->lifepoints)
+ if (yx_uint8_cmp(&pos, &mo_ptr->pos) && 0 != mo_ptr->lifepoints)
{
clear = 0;
break;
char * err_toolarge = "Value is too large.";
char * err_uniq = "Declaration of ID already used.";
FILE * file = try_fopen(world.path_map_obj_defs, "r", f_name);
- uint16_t linemax = textfile_sizes(file, NULL);
+ uint32_t linemax = textfile_sizes(file, NULL);
struct MapObjDef ** last_mod_ptr_ptr = &world.map_obj_defs;
char line[linemax + 1];
reset_err_try_fgets_counter();
-extern void set_object_position(struct MapObj * mo, struct yx_uint16 pos)
+extern void set_object_position(struct MapObj * mo, struct yx_uint8 pos)
{
mo->pos = pos;
struct MapObj * owned = mo->owns;
#define MAP_OBJECTS_H
#include <stdint.h> /* uint8_t */
-#include "../common/yx_uint16.h" /* yx_uint16 structs */
+#include "../common/yx_uint8.h" /* yx_uint8 structs */
{
struct MapObj * next; /* pointer to next one in map object chain */
struct MapObj * owns; /* chain of map objects owned / in inventory */
- struct yx_uint16 pos; /* coordinate on map */
+ struct yx_uint8 pos; /* coordinate on map */
uint8_t id; /* individual map object's unique identifier */
uint8_t type; /* ID of appropriate map object definition */
uint8_t lifepoints; /* 0: object is inanimate; >0: hitpoints */
extern struct MapObjDef * get_map_object_def(uint8_t id);
/* Move not only "mo" to "pos", but also all map objects owned by it. */
-extern void set_object_position(struct MapObj * mo, struct yx_uint16 pos);
+extern void set_object_position(struct MapObj * mo, struct yx_uint8 pos);
+++ /dev/null
-/* src/server/yx_uint16.c */
-
-#include "yx_uint16.h"
-#include <stdint.h> /* uint8_t, UINT16_MAX */
-#include "../common/yx_uint16.h" /* yx_uint16 struct */
-
-
-
-extern uint8_t yx_uint16_cmp(struct yx_uint16 * a, struct yx_uint16 * b)
-{
- if (a->y == b->y && a->x == b->x)
- {
- return 1;
- }
- return 0;
-}
-
-
-
-extern struct yx_uint16 mv_yx_in_dir(char d, struct yx_uint16 yx)
-{
- if (d == '8' && yx.y > 0)
- {
- yx.y--;
- }
- else if (d == '9' && yx.y > 0 && yx.x < UINT16_MAX)
- {
- yx.y--;
- yx.x++;
- }
- else if (d == '6' && yx.x < UINT16_MAX)
- {
- yx.x++;
- }
- else if (d == '3' && yx.x < UINT16_MAX && yx.y < UINT16_MAX)
- {
- yx.y++;
- yx.x++;
- }
- else if (d == '2' && yx.y < UINT16_MAX)
- {
- yx.y++;
- }
- else if (d == '1' && yx.y < UINT16_MAX && yx.x > 0)
- {
- yx.y++;
- yx.x--;
- }
- else if (d == '4' && yx.x > 0)
- {
- yx.x--;
- }
- else if (d == '7' && yx.x > 0 && yx.y > 0)
- {
- yx.y--;
- yx.x--;
- }
- return yx;
-}
+++ /dev/null
-/* src/server/yx_uint16.h
- *
- * Routines for comparison and movement with yx_uin16 structs.
- */
-
-#ifndef YX_UINT16_H_SERVER
-#define YX_UINT16_H_SERVER
-
-#include <stdint.h> /* uint8_t */
-#include "../common/yx_uint16.h" /* yx_uint16 struct */
-
-
-
-/* Return 1 if two yx_uint16 coordinates at "a" and "b" are equal, else 0. */
-extern uint8_t yx_uint16_cmp(struct yx_uint16 * a, struct yx_uint16 * b);
-
-/* Return yx_uint16 coordinate one step from "yx" in direction "dir" (numpad
- * digits: north '8', east: '6', etc.) If "dir" is invalid or would wrap the
- * move around the edge of a 2^16x2^16 cells field, "yx" remains unchanged.
- */
-extern struct yx_uint16 mv_yx_in_dir(char dir, struct yx_uint16 yx);
-
-
-
-#endif
--- /dev/null
+/* src/server/yx_uint8.c */
+
+#include "yx_uint8.h"
+#include <stdint.h> /* uint8_t, UINT8_MAX */
+#include "../common/yx_uint8.h" /* yx_uint8 struct */
+
+
+
+extern uint8_t yx_uint8_cmp(struct yx_uint8 * a, struct yx_uint8 * b)
+{
+ if (a->y == b->y && a->x == b->x)
+ {
+ return 1;
+ }
+ return 0;
+}
+
+
+
+extern struct yx_uint8 mv_yx_in_dir(char d, struct yx_uint8 yx)
+{
+ if (d == '8' && yx.y > 0)
+ {
+ yx.y--;
+ }
+ else if (d == '9' && yx.y > 0 && yx.x < UINT8_MAX)
+ {
+ yx.y--;
+ yx.x++;
+ }
+ else if (d == '6' && yx.x < UINT8_MAX)
+ {
+ yx.x++;
+ }
+ else if (d == '3' && yx.x < UINT8_MAX && yx.y < UINT8_MAX)
+ {
+ yx.y++;
+ yx.x++;
+ }
+ else if (d == '2' && yx.y < UINT8_MAX)
+ {
+ yx.y++;
+ }
+ else if (d == '1' && yx.y < UINT8_MAX && yx.x > 0)
+ {
+ yx.y++;
+ yx.x--;
+ }
+ else if (d == '4' && yx.x > 0)
+ {
+ yx.x--;
+ }
+ else if (d == '7' && yx.x > 0 && yx.y > 0)
+ {
+ yx.y--;
+ yx.x--;
+ }
+ return yx;
+}
--- /dev/null
+/* src/server/yx_uint8.h
+ *
+ * Routines for comparison and movement with yx_uint8 structs.
+ */
+
+#ifndef YX_UINT8_H_SERVER
+#define YX_UINT8_H_SERVER
+
+#include <stdint.h> /* uint8_t */
+#include "../common/yx_uint8.h" /* yx_uint8 struct */
+
+
+
+/* Return 1 if two yx_uint8 coordinates at "a" and "b" are equal, else 0. */
+extern uint8_t yx_uint8_cmp(struct yx_uint8 * a, struct yx_uint8 * b);
+
+/* Return yx_uint8 coordinate one step from "yx" in direction "dir" (numpad
+ * digits: north '8', east: '6', etc.) If "dir" is invalid or would wrap the
+ * move around the edge of a 2^16x2^16 cells field, "yx" remains unchanged.
+ */
+extern struct yx_uint8 mv_yx_in_dir(char dir, struct yx_uint8 yx);
+
+
+
+#endif