--------------------------------------------
The ./confserver/world file defines the map object types, actions available to
-them, the map itself, the map object type (species) of the player and whether
-enemies see the whole map or only a line-of-sight field of view. Each definition
-consists of a single- or multi-line block wherein each line sets one attribute.
-
-Here's a typical map definition block:
-
-MAP_TYPE 0
-HEIGHT 64
-WIDTH 64
-
-A line of "MAP_TYPE" followed by a non-empty token starts the map definition
-block. In the future, the second token may differentiate different map types,
-but as of right now, only one is available and the value is not interpreted.
-The numbers after "HEIGHT" and "WIDTH" give the map's vertical and horizontal
-extensions in cells. They must be >= 1 and <= 256.
+them, the map geometry and the map object type (species) of the player. Each
+definition consists of a single- or multi-line block wherein each line sets one
+attribute.
Here's a typical action definition block:
after, it may even be the same). "START_NUMBER" sets the number of objects that
are to appear of the given type on the map on game start.
-A line of "PLAYER_TYPE" followed by a number sets the map object type (id) of
-the player's creature.
+The map is defined by a single-line block. Its number value sets the map
+square's edge length. It must be >= 1 and <= 256:
+
+MAP_LENGTH 64
+
+The player type / species is also defined by a single line block. Its number
+value sets the player's creature's map object type by its id:
+
+PLAYER_TYPE 0
-All these definition block members must be present within their blocks, but only
-"ACTION" / "OBJECT" / "MAP_TYPE" must be positioned at their respective blocks'
-first line; the others may appear in whatever order and even multiple times. If
-an object or action definition block is finished, however, it cannot be
-re-defined by starting a new block with the same object type or action id.
+All these definition block members must be present within their respective
+blocks, but only "ACTION" and "OBJECT" must be positioned at their respective
+blocks' first line; the others may appear in whatever order and even multiple
+times. If an object or action definition block is finished, however, it cannot
+be re-defined by starting a new block with the same object type or action id.
Tokens in this config file are separated by whitespace. Single quotes can be
put around string values that are to include whitespace by themslves. Note that
- be more strict and humble when allocating memory from the stack
-- maps are always as wide as high, so only use one of the two values
-
SERVER:
- optimize too-slow AI / FOV algorithms
-MAP_TYPE 0
-HEIGHT 64
-WIDTH 64
-
+MAP_LENGTH 64
PLAYER_TYPE 0
ACTION 1
#include <string.h> /* memset(), strchr(), strdup/(), strlen() */
#include "../common/rexit.h" /* exit_err() */
#include "../common/try_malloc.h" /* try_malloc() */
-#include "../common/yx_uint16.h" /* struct yx_uint16 */
#include "keybindings.h" /* struct KeyBindingDB, get_keyname_to_keycode() */
-#include "windows.h" /* struct Win, get_win_by_id() */
+#include "windows.h" /* yx_uint16, Win, get_win_by_id() */
#include "world.h" /* global world */
extern void draw_win_map(struct Win * win)
{
- try_resize_winmap(win, world.map.size.y, world.map.size.x * 2);
+ try_resize_winmap(win, world.map.length, world.map.length * 2);
uint16_t z = 0;
uint16_t x, y;
- for (y = 0; y < world.map.size.y; y++)
+ for (y = 0; y < world.map.length; y++)
{
- for (x = 0; x < world.map.size.x; x++)
+ for (x = 0; x < world.map.length; x++)
{
set_ch_on_yx(win, y, x * 2 + (y % 2), world.map.cells[z]);
z++;
static void read_inventory(char * read_buf, uint32_t linemax, FILE * file);
/* Read the next characters in "file" into world.map.cells. In detail: Read
- * world.map.size.y times world.map.size.x characters, followed by one ignored
+ * world.map.length times world.map.length characters, followed by one ignored
* character (that we assume is a newline).
*/
static void read_map_cells(FILE * file);
{
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);
+ world.map.cells = try_malloc(world.map.length * world.map.length, f_name);
uint16_t y, x;
- for (y = 0; y < world.map.size.y; y++)
+ for (y = 0; y < world.map.length; y++)
{
- for (x = 0; x < world.map.size.x; x++)
+ for (x = 0; x < world.map.length; x++)
{
char c = try_fgetc(file, f_name);
- world.map.cells[(y * world.map.size.x) + x] = c;
+ world.map.cells[(y * world.map.length) + x] = c;
}
try_fgetc(file, f_name);
}
map_center();
first_read = 0;
}
- world.map.size.y = read_value_from_line(read_buf, linemax, file);
- world.map.size.x = read_value_from_line(read_buf, linemax, file);
+ world.map.length = read_value_from_line(read_buf, linemax, file);
read_map_cells(file);
read_log(read_buf, linemax, file);
free(read_buf);
{
struct Win * win = get_win_by_id('m');
uint16_t offset;
- if (('8' == d || '2' == d) && world.map.size.y > win->frame_size.y)
+ if (('8' == d || '2' == d) && world.map.length > win->frame_size.y)
{
offset = center_offset(win->center.y,
- world.map.size.y, win->frame_size.y);
+ world.map.length, win->frame_size.y);
win->center.y = offset + (win->frame_size.y / 2);
- if ('2' == d && win->center.y < world.map.size.y - 1)
+ if ('2' == d && win->center.y < world.map.length - 1)
{
win->center.y++;
return;
}
win->center.y = win->center.y - ('8' == d && win->center.y > 0);
}
- else if (('4' == d || '6' == d) && (world.map.size.x*2) > win->frame_size.x)
+ else if (('4' == d || '6' == d) && (world.map.length*2) > win->frame_size.x)
{
offset = center_offset(win->center.x,
- world.map.size.x*2, win->frame_size.x);
+ world.map.length*2, win->frame_size.x);
win->center.x = offset + (win->frame_size.x / 2);
- if ('6' == d && win->center.x < (world.map.size.x * 2) - 1)
+ if ('6' == d && win->center.x < (world.map.length * 2) - 1)
{
win->center.x++;
return;
#include <string.h> /* memcpy(), memset(), strchr(), strlen() */
#include "../common/rexit.h" /* exit_err() */
#include "../common/try_malloc.h" /* try_malloc() */
-#include "../common/yx_uint16.h" /* struct yx_uint16 */
-#include "windows.h" /* struct Win, get_win_by_id(), get_win_pos_in_order() */
+#include "windows.h" /* Win,yx_uint16, get_win_by_id(),get_win_pos_in_order() */
#include "world.h" /* global world */
#include <stdlib.h> /* free() */
#include <string.h> /* memcpy(), strlen(), strnlen(), memset() */
#include "../common/rexit.h" /* exit_trouble(), exit_err() */
-#include "../common/yx_uint16.h" /* struct yx_uint16 */
#include "draw_wins.h" /* draw_winconf_geometry(), draw_winconf_keybindings(),
* draw_win_inventory(), draw_win_info(), draw_win_log(),
* draw_win_available_keybindings(), draw_win_map(),
* draw_win_keybindings_global()
*/
#include "wincontrol.h" /* toggle_window() */
-#include "world.h" /* global world */
+#include "world.h" /* world */
#include <ncurses.h> /* WINDOW, chtype */
#include <stdint.h> /* uint8_t, int16_t, uint16_t, uint32_t */
-#include "../common/yx_uint16.h" /* yx_uint16 struct */
#include "keybindings.h" /* struct KeyBindingDB */
+struct yx_uint16
+{
+ uint16_t y;
+ uint16_t x;
+};
+
struct WinDB
{
WINDOW * t_screen; /* ncurses' pointer to the terminal screen */
#ifndef MAP_H
#define MAP_H
-#include "yx_uint16.h" /* yx_uint16 struct */
+#include <stdint.h> /* uint16_t */
+
struct Map
{
- struct yx_uint16 size; /* map's height/width in number of cells */
char * cells; /* sequence of bytes encoding map cells */
+ uint16_t length; /* map's edge length */
};
+++ /dev/null
-/* yx_uint16.h
- *
- * Used for window / screen maps and game map size.
- */
-
-#ifndef YX_UINT16_H
-#define YX_UINT16_H
-
-#include <stdint.h> /* for uint16_t */
-
-
-
-/* Coordinates for maps of max. 65536x65536 cells. */
-struct yx_uint16
-{
- uint16_t y;
- uint16_t x;
-};
-
-
-
-#endif
static void get_neighbor_scores(uint16_t * score_map, uint16_t pos_i,
uint16_t max_score, uint16_t * neighbors)
{
- uint32_t map_size = world.map.size.y * world.map.size.x;
+ uint32_t map_size = world.map.length * world.map.length;
uint8_t i_dir;
for (i_dir = 0; i_dir < N_DIRS; neighbors[i_dir] = max_score, i_dir++);
- uint8_t open_north = pos_i >= world.map.size.x;
- uint8_t open_east = pos_i + 1 % world.map.size.x;
- uint8_t open_south = pos_i + world.map.size.x < map_size;
- uint8_t open_west = pos_i % world.map.size.x;
- uint8_t is_indented = (pos_i / world.map.size.x) % 2;
+ uint8_t open_north = pos_i >= world.map.length;
+ uint8_t open_east = pos_i + 1 % world.map.length;
+ uint8_t open_south = pos_i + world.map.length < map_size;
+ uint8_t open_west = pos_i % world.map.length;
+ uint8_t is_indented = (pos_i / world.map.length) % 2;
uint8_t open_diag_west = is_indented || open_west;
uint8_t open_diag_east = !is_indented || open_east;
if (open_north && open_diag_east)
{
- neighbors[0] = score_map[pos_i - world.map.size.x + is_indented];
+ neighbors[0] = score_map[pos_i - world.map.length + is_indented];
}
if (open_east)
{
}
if (open_south && open_diag_east)
{
- neighbors[2] = score_map[pos_i + world.map.size.x + is_indented];
+ neighbors[2] = score_map[pos_i + world.map.length + is_indented];
}
if (open_south && open_diag_west)
{
- neighbors[3] = score_map[pos_i + world.map.size.x - !is_indented];
+ neighbors[3] = score_map[pos_i + world.map.length - !is_indented];
}
if (open_west)
{
}
if (open_north && open_diag_west)
{
- neighbors[5] = score_map[pos_i - world.map.size.x - !is_indented];
+ neighbors[5] = score_map[pos_i - world.map.length - !is_indented];
}
}
static void dijkstra_map(uint16_t * score_map, uint16_t max_score)
{
- uint32_t map_size = world.map.size.y * world.map.size.x;
+ uint32_t map_size = world.map.length * world.map.length;
uint16_t pos, i_scans, neighbors[N_DIRS], min_neighbor;
uint8_t scores_still_changing = 1;
uint8_t i_dirs;
* "mo_origin", with movement only possible in the directions of "dir".
* (Actors' own cells start with a distance of 0 towards themselves.)
*/
- uint32_t map_size = world.map.size.y * world.map.size.x;
+ uint32_t map_size = world.map.length * world.map.length;
uint16_t max_score = UINT16_MAX - 1;
uint16_t * score_map = try_malloc(map_size * sizeof(uint16_t), f_name);
uint32_t i;
{
continue;
}
- score_map[(mo->pos.y * world.map.size.x) + mo->pos.x] = 0;
+ score_map[(mo->pos.y * world.map.length) + mo->pos.x] = 0;
}
dijkstra_map(score_map, max_score);
/* Return direction of "mo_origin"'s lowest-scored neighbor cell. */
uint16_t neighbors[N_DIRS];
- uint16_t pos_i = (mo_origin->pos.y * world.map.size.x) + mo_origin->pos.x;
+ uint16_t pos_i = (mo_origin->pos.y * world.map.length) + mo_origin->pos.x;
get_neighbor_scores(score_map, pos_i, max_score, neighbors);
free(score_map);
char dir_to_nearest_enemy = 0;
START_N_SET = 0x40,
READY_ACT = NAME_SET | EFFORT_SET,
READY_OBJ = NAME_SET | CORPSE_ID_SET | SYMBOL_SET | LIFEPOINTS_SET
- | CONSUMABLE_SET | START_N_SET,
- READY_MAP = HEIGHT_SET | WIDTH_SET
+ | CONSUMABLE_SET | START_N_SET
};
struct EntryHead ** entry,
struct EntryHead * entry_cmp);
-/* Start reading map definition if "token0" matches "comparand". Set "map_flags"
- * to EDIT_STARTED to mark beginning of map definition reading.
- */
-static uint8_t start_map(char * token0, char * comparand, uint8_t * map_flags);
-
/* Write DB entry pointed to by "entry" to its appropriate location. */
static void write_if_entry(struct EntryHead ** entry,
struct EntryHead *** entry_p_p_p);
*/
static void test_corpse_ids();
-/* set_members() helper specifically for editing world.map members. */
-static uint8_t set_map_members(char * token0,char * token1,uint8_t * map_flags);
-
/* If "token0" matches "comparand", set world.player_type to int in "token1". */
static uint8_t set_player_type(char * token0, char * comparand, char * token1);
+/* If "token0" matches "comparand", set world.map.length to int in "token1". */
+static uint8_t set_map_length(char * token0, char * comparand, char * token1);
+
/* Try to read tokens as members for the definition currently edited, which may
- * be "mod" or "moa" or that of world.map. What member of which of the three is
- * set depends on which of the flags has EDIT_STARTED set and on the key name in
- * "token0". Return 1 if interpretation succeeds, else 0.
+ * be "mod" or "moa". What member of which of the two is set depends on which of
+ * the flags has EDIT_STARTED set and on the key name in "token0". Return 1 if
+ * interpretation succeeds, else 0.
*
* Note that MapObjAct entries' .name also determines their .func.
*/
-static uint8_t set_members(char * token0, char * token1, uint8_t * object_flags,
- uint8_t * action_flags, uint8_t * map_flags,
+static uint8_t set_members(char * token0, char * token1,
+ uint8_t * object_flags, uint8_t * action_flags,
struct MapObjDef * mod, struct MapObjAct * moa);
/* If "name" fits "moa"->name, set "moa"->func to "func". (Derives MapObjAct
{
char * str_act = "ACTION";
char * str_obj = "OBJECT";
- char * str_map = "MAP_TYPE";
char * str_player = "PLAYER_TYPE";
+ char * str_map_length = "MAP_LENGTH";
static struct MapObjAct ** moa_p_p = &world.map_obj_acts;
static struct MapObjDef ** mod_p_p = &world.map_obj_defs;
static uint8_t action_flags = READY_ACT;
static uint8_t object_flags = READY_OBJ;
- static uint8_t map_flags = READY_MAP;
static struct EntryHead * moa = NULL;
static struct EntryHead * mod = NULL;
if (!token0 || !strcmp(token0, str_act) || !strcmp(token0, str_obj)
- || !strcmp(token0, str_map) || !strcmp(token0, str_player))
+ || !strcmp(token0, str_player))
{
parse_and_reduce_to_readyflag(&action_flags, READY_ACT);
parse_and_reduce_to_readyflag(&object_flags, READY_OBJ);
- parse_and_reduce_to_readyflag(&map_flags, READY_MAP);
write_if_entry(&moa, (struct EntryHead ***) &moa_p_p);
write_if_entry(&mod, (struct EntryHead ***) &mod_p_p);
}
sizeof(struct MapObjDef),
(struct EntryHead**) &mod,
(struct EntryHead *) world.map_obj_defs)
- || start_map(token0, str_map, &map_flags)
|| set_player_type(token0, str_player, token1)
+ || set_map_length(token0, str_map_length, token1)
|| set_members(token0, token1, &object_flags, &action_flags,
- &map_flags, (struct MapObjDef *)mod,
+ (struct MapObjDef *)mod,
(struct MapObjAct *) moa)))
{
parse_unknown_arg();
-static uint8_t start_map(char * token0, char * comparand, uint8_t * map_flags)
-{
- if (strcmp(token0, comparand))
- {
- return 0;
- }
- *map_flags = EDIT_STARTED;
- return 1;
-}
-
-
-
static void write_if_entry(struct EntryHead ** entry,
struct EntryHead *** entry_p_p_p)
{
-static uint8_t set_map_members(char * token0, char * token1,uint8_t * map_flags)
+static uint8_t set_player_type(char * token0, char * comparand, char * token1)
{
- if ( parse_val(token0, token1, "HEIGHT", map_flags,
- HEIGHT_SET, 'i', (char *) &world.map.size.y)
- || parse_val(token0, token1, "WIDTH", map_flags,
- WIDTH_SET, 'i', (char *) &world.map.size.x))
+ if (strcmp(token0, comparand))
{
- int test = atoi(token1) > 256 || atoi(token1) < 1;
- err_line(test, "Value must be >= 1 and <= 256.");
- return 1;
+ return 0;
}
- return 0;
+ parsetest_int(token1, '8');
+ world.player_type = atoi(token1);
+ return 1;
}
-static uint8_t set_player_type(char * token0, char * comparand, char * token1)
+static uint8_t set_map_length(char * token0, char * comparand, char * token1)
{
if (strcmp(token0, comparand))
{
return 0;
}
- parsetest_int(token1, '8');
- world.player_type = atoi(token1);
+ parsetest_int(token1, 'i');
+ int test = atoi(token1) > 256 || atoi(token1) < 1;
+ err_line(test, "Value must be >= 1 and <= 256.");
+ world.map.length = atoi(token1);
return 1;
}
static uint8_t set_members(char * token0, char * token1, uint8_t * object_flags,
- uint8_t * action_flags, uint8_t * map_flags,
+ uint8_t * action_flags,
struct MapObjDef * mod, struct MapObjAct * moa)
{
if ( *action_flags & EDIT_STARTED
*action_flags = *action_flags | NAME_SET;
return 1;
}
- else if ( set_map_members(token0, token1, map_flags)
- || parse_val(token0, token1, "NAME", object_flags,
+ else if ( parse_val(token0, token1, "NAME", object_flags,
NAME_SET, 's', (char *) &mod->name)
|| parse_val(token0, token1, "SYMBOL", object_flags,
SYMBOL_SET, 'c', (char *) &mod->char_on_map)
extern void read_config_file()
{
parse_file(world.path_config, tokens_into_entries);
- exit_err(!world.map.size.y, "Map not defined in config file.");
+ exit_err(!world.map.length, "Map size not defined in config file.");
uint8_t player_type_is_valid = 0;
struct MapObjDef * mod;
for (mod = world.map_obj_defs; NULL != mod; mod = mod->next)
extern uint8_t mv_yx_in_dir_legal(char dir, struct yx_uint8 * yx)
{
uint8_t wraptest = mv_yx_in_dir_wrap(dir, yx, 0);
- if (!wraptest && yx->x < world.map.size.x && yx->y < world.map.size.y)
+ if (!wraptest && yx->x < world.map.length && yx->y < world.map.length)
{
return 1;
}
static uint8_t is_top_left_shaded(uint16_t pos_a, uint16_t pos_b,
int16_t a_y_on_left)
{
- uint16_t start_last_row = world.map.size.x * (world.map.size.y - 1);
+ uint16_t start_last_row = world.map.length * (world.map.length - 1);
uint8_t a_on_left_or_bottom = 0 <= a_y_on_left
|| (pos_a >= start_last_row);
- uint8_t b_on_top_or_right = pos_b < world.map.size.x
- || pos_b % world.map.size.x==world.map.size.x-1;
+ uint8_t b_on_top_or_right = pos_b < world.map.length
+ || pos_b % world.map.length==world.map.length-1;
return pos_a != pos_b && b_on_top_or_right && a_on_left_or_bottom;
}
static void fill_shadow(struct yx_uint8 * yx_eye, struct yx_uint8 * yx_cell,
uint8_t * fov_map, uint16_t pos_a, uint16_t pos_b)
{
- int16_t a_y_on_left = !(pos_a%world.map.size.x)? pos_a/world.map.size.x :-1;
- int16_t b_y_on_left = !(pos_b%world.map.size.x)? pos_b/world.map.size.x :-1;
+ int16_t a_y_on_left = !(pos_a%world.map.length)? pos_a/world.map.length :-1;
+ int16_t b_y_on_left = !(pos_b%world.map.length)? pos_b/world.map.length :-1;
uint8_t top_left_shaded = is_top_left_shaded(pos_a, pos_b, a_y_on_left);
uint16_t pos;
uint8_t y, x, in_shade;
- for (y = 0; y < world.map.size.y; y++)
+ for (y = 0; y < world.map.length; y++)
{
in_shade = (top_left_shaded || (b_y_on_left >= 0 && y > b_y_on_left))
&& (a_y_on_left < 0 || y < a_y_on_left);
- for (x = 0; x < world.map.size.x; x++)
+ for (x = 0; x < world.map.length; x++)
{
- pos = (y * world.map.size.x) + x;
+ pos = (y * world.map.length) + x;
if (yx_eye->y == yx_cell->y && yx_eye->x < yx_cell->x)
{
uint8_t val = fov_map[pos] & (SHADOW_LEFT | SHADOW_RIGHT);
pos_start = yx_to_map_pos(yx_start);
fov_map[pos_start] = fov_map[pos_start] | SHADOW_LEFT | SHADOW_RIGHT;
fill_shadow(yx_eye, yx_start, fov_map, pos_a, pos_b);
- for (i = 0; i < world.map.size.y * world.map.size.x; i++)
+ for (i = 0; i < world.map.length * world.map.length; i++)
{
if (fov_map[i] & (SHADOW_LEFT | SHADOW_RIGHT) && i != pos_start)
{
extern uint8_t * build_fov_map(struct MapObj * eye)
{
char * f_name = "build_fov_map()";
- uint8_t radius = 2 * world.map.size.y;
- uint32_t map_size = world.map.size.y * world.map.size.x;
+ uint8_t radius = 2 * world.map.length;
+ uint32_t map_size = world.map.length * world.map.length;
struct yx_uint8 yx = eye->pos;
uint8_t * fov_map = try_malloc(map_size, f_name);
memset(fov_map, 0, map_size);
}
}
uint16_t i;
- for (i = 0; i < world.map.size.y * world.map.size.x; i++)
+ for (i = 0; i < world.map.length * world.map.length; i++)
{
if (fov_map[i] & HIDE_LATER)
{
write_inventory(player, file);
write_value_as_line(player->pos.y, file);
write_value_as_line(player->pos.x, file);
- write_value_as_line(world.map.size.y, file);
- write_value_as_line(world.map.size.x, file);
+ write_value_as_line(world.map.length, file);
write_map(player, file);
if (world.log)
{
static char * build_visible_map(struct MapObj * player)
{
char * f_name = "build_visible_map()";
- uint32_t map_size = world.map.size.y * world.map.size.x;
+ uint32_t map_size = world.map.length * world.map.length;
char * visible_map = try_malloc(map_size, f_name);
memset(visible_map, ' ', map_size);
uint16_t pos_i;
char * f_name = "write_map()";
char * visible_map = build_visible_map(player);
uint16_t x, y;
- for (y = 0; y < world.map.size.y; y++)
+ for (y = 0; y < world.map.length; y++)
{
- for (x = 0; x < world.map.size.x; x++)
+ for (x = 0; x < world.map.length; x++)
{
- try_fputc(visible_map[(y * world.map.size.x) + x], file, f_name);
+ try_fputc(visible_map[(y * world.map.length) + x], file, f_name);
}
try_fputc('\n', file, f_name);
}
{
uint8_t ind = pos.y % 2;
uint8_t diag_west = pos.x + ind > 0;
- uint8_t diag_east = pos.x + ind <= world.map.size.x - 1;
- uint16_t pos_i = (pos.y * world.map.size.x) + pos.x;
+ uint8_t diag_east = pos.x + ind <= world.map.length - 1;
+ uint16_t pos_i = (pos.y * world.map.length) + pos.x;
if ( ( pos.y > 0 && diag_east
- && type == world.map.cells[pos_i - world.map.size.x + ind])
- || ( pos.x < world.map.size.x - 1
+ && type == world.map.cells[pos_i - world.map.length + ind])
+ || ( pos.x < world.map.length - 1
&& type == world.map.cells[pos_i + 1])
- || ( pos.y < world.map.size.y - 1 && diag_east
- && type == world.map.cells[pos_i + world.map.size.x + ind])
+ || ( pos.y < world.map.length - 1 && diag_east
+ && type == world.map.cells[pos_i + world.map.length + ind])
|| ( pos.y > 0 && diag_west
- && type == world.map.cells[pos_i - world.map.size.x - !ind])
+ && type == world.map.cells[pos_i - world.map.length - !ind])
|| ( pos.x > 0
&& type == world.map.cells[pos_i - 1])
- || ( pos.y < world.map.size.y - 1 && diag_west
- && type == world.map.cells[pos_i + world.map.size.x - !ind]))
+ || ( pos.y < world.map.length - 1 && diag_west
+ && type == world.map.cells[pos_i + world.map.length - !ind]))
{
return 1;
}
static void make_sea()
{
uint16_t y, x;
- for (y = 0; y < world.map.size.y; y++)
+ for (y = 0; y < world.map.length; y++)
{
for (x = 0;
- x < world.map.size.x;
- world.map.cells[(y * world.map.size.x) + x] = '~', x++);
+ x < world.map.length;
+ world.map.cells[(y * world.map.length) + x] = '~', x++);
}
}
static void make_island()
{
char type = '.';
- uint8_t add_half_width = !(world.map.size.y % 2) * (world.map.size.x / 2);
- uint32_t size = world.map.size.x * world.map.size.y;
+ uint8_t add_half_width = !(world.map.length % 2) * (world.map.length / 2);
+ uint32_t size = world.map.length * world.map.length;
world.map.cells[(size / 2) + add_half_width] = type;
struct yx_uint8 pos;
iter_limit(1);
while (iter_limit(0))
{
- pos.y = rrand() % world.map.size.y;
- pos.x = rrand() % world.map.size.x;
- uint16_t pos_i = (pos.y * world.map.size.x) + pos.x;
+ pos.y = rrand() % world.map.length;
+ pos.x = rrand() % world.map.length;
+ uint16_t pos_i = (pos.y * world.map.length) + pos.x;
if ('~' == world.map.cells[pos_i] && is_neighbor(pos, type))
{
- if ( pos.y == 0 || pos.y == world.map.size.y - 1
- || pos.x == 0 || pos.x == world.map.size.x - 1)
+ if ( pos.y == 0 || pos.y == world.map.length - 1
+ || pos.x == 0 || pos.x == world.map.length - 1)
{
break;
}
{
char type = 'X';
struct yx_uint8 pos;
- uint16_t n_trees = (world.map.size.x * world.map.size.y) / 16;
+ uint16_t n_trees = (world.map.length * world.map.length) / 16;
uint16_t i_trees = 0;
iter_limit(1);
while (i_trees <= n_trees && iter_limit(0))
{
uint8_t single_allowed = rrand() % 32;
- pos.y = rrand() % world.map.size.y;
- pos.x = rrand() % world.map.size.x;
- uint16_t pos_i = (pos.y * world.map.size.x) + pos.x;
+ pos.y = rrand() % world.map.length;
+ pos.x = rrand() % world.map.length;
+ uint16_t pos_i = (pos.y * world.map.length) + pos.x;
if ('.' == world.map.cells[pos_i]
&& (!single_allowed || is_neighbor(pos, type)))
{
extern void init_map()
{
char * f_name = "init_map()";
- world.map.cells = try_malloc(world.map.size.x * world.map.size.y, f_name);
+ world.map.cells = try_malloc(world.map.length * world.map.length, f_name);
make_sea();
make_island();
make_trees();
extern uint8_t is_passable(struct yx_uint8 pos)
{
uint8_t passable = 0;
- if (pos.x < world.map.size.x && pos.y < world.map.size.y)
+ if (pos.x < world.map.length && pos.y < world.map.length)
{
- passable = ('.' == world.map.cells[(pos.y * world.map.size.x) + pos.x]);
+ passable = ('.' == world.map.cells[(pos.y * world.map.length) + pos.x]);
}
return passable;
}
extern uint16_t yx_to_map_pos(struct yx_uint8 * yx)
{
- return (yx->y * world.map.size.x) + yx->x;
+ return (yx->y * world.map.length) + yx->x;
}
for (pos.y = pos.x = 0; 0 == is_passable(pos); i++)
{
exit_err(UINT16_MAX == i, err);
- pos.y = rrand() % world.map.size.y;
- pos.x = rrand() % world.map.size.x;
+ pos.y = rrand() % world.map.length;
+ pos.x = rrand() % world.map.length;
}
struct MapObj * mo_ptr;
uint8_t clear = 1;