From: Christian Heller Date: Wed, 14 May 2014 04:04:11 +0000 (+0200) Subject: Maps are always squares, therefore define only their edge lengths. X-Git-Tag: tce~745 X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/static/%7B%7Byoutube_prefix%7D%7D%7B%7Bvideo_data.id_%7D%7D?a=commitdiff_plain;h=0438f2fc5df337e4264103a86c1765ace9c6565a;p=plomrogue Maps are always squares, therefore define only their edge lengths. --- diff --git a/README b/README index 2a0206d..5ec2f4a 100644 --- a/README +++ b/README @@ -78,21 +78,9 @@ Hacking / server internals and configuration -------------------------------------------- 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: @@ -131,14 +119,21 @@ yet: or if they are inanimate, but are otherwise crushed). Note that the 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 diff --git a/TODO b/TODO index 46a647e..c6623da 100644 --- a/TODO +++ b/TODO @@ -9,8 +9,6 @@ BOTH SERVER/CLIENT: - 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 diff --git a/confserver/world b/confserver/world index 724d012..a44535c 100644 --- a/confserver/world +++ b/confserver/world @@ -1,7 +1,4 @@ -MAP_TYPE 0 -HEIGHT 64 -WIDTH 64 - +MAP_LENGTH 64 PLAYER_TYPE 0 ACTION 1 diff --git a/src/client/draw_wins.c b/src/client/draw_wins.c index 5c35dd6..69278e8 100644 --- a/src/client/draw_wins.c +++ b/src/client/draw_wins.c @@ -10,9 +10,8 @@ #include /* 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 */ @@ -339,12 +338,12 @@ extern void draw_win_log(struct Win * win) 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++; diff --git a/src/client/io.c b/src/client/io.c index 1995b14..e304723 100644 --- a/src/client/io.c +++ b/src/client/io.c @@ -31,7 +31,7 @@ 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); @@ -120,14 +120,14 @@ 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); } @@ -216,8 +216,7 @@ static uint8_t read_world() 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); diff --git a/src/client/map.c b/src/client/map.c index 2e3c12d..7c2dcc3 100644 --- a/src/client/map.c +++ b/src/client/map.c @@ -11,24 +11,24 @@ extern void map_scroll(char d) { 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; diff --git a/src/client/wincontrol.c b/src/client/wincontrol.c index 21308e7..09cff03 100644 --- a/src/client/wincontrol.c +++ b/src/client/wincontrol.c @@ -9,8 +9,7 @@ #include /* 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 */ diff --git a/src/client/windows.c b/src/client/windows.c index 4952a4d..faf1f8a 100644 --- a/src/client/windows.c +++ b/src/client/windows.c @@ -13,7 +13,6 @@ #include /* free() */ #include /* 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(), @@ -22,7 +21,7 @@ * draw_win_keybindings_global() */ #include "wincontrol.h" /* toggle_window() */ -#include "world.h" /* global world */ +#include "world.h" /* world */ diff --git a/src/client/windows.h b/src/client/windows.h index dd03d8b..e2d39c2 100644 --- a/src/client/windows.h +++ b/src/client/windows.h @@ -26,11 +26,16 @@ #include /* WINDOW, chtype */ #include /* 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 */ diff --git a/src/common/map.h b/src/common/map.h index 8d454ca..4a6d041 100644 --- a/src/common/map.h +++ b/src/common/map.h @@ -6,13 +6,14 @@ #ifndef MAP_H #define MAP_H -#include "yx_uint16.h" /* yx_uint16 struct */ +#include /* 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 */ }; diff --git a/src/common/yx_uint16.h b/src/common/yx_uint16.h deleted file mode 100644 index 05cf29e..0000000 --- a/src/common/yx_uint16.h +++ /dev/null @@ -1,22 +0,0 @@ -/* yx_uint16.h - * - * Used for window / screen maps and game map size. - */ - -#ifndef YX_UINT16_H -#define YX_UINT16_H - -#include /* for uint16_t */ - - - -/* Coordinates for maps of max. 65536x65536 cells. */ -struct yx_uint16 -{ - uint16_t y; - uint16_t x; -}; - - - -#endif diff --git a/src/server/ai.c b/src/server/ai.c index 1596d5a..ea77dd4 100644 --- a/src/server/ai.c +++ b/src/server/ai.c @@ -46,19 +46,19 @@ static char get_dir_to_nearest_enemy(struct MapObj * mo_origin); 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) { @@ -66,11 +66,11 @@ static void get_neighbor_scores(uint16_t * score_map, uint16_t pos_i, } 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) { @@ -78,7 +78,7 @@ static void get_neighbor_scores(uint16_t * score_map, uint16_t pos_i, } 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]; } } @@ -86,7 +86,7 @@ static void get_neighbor_scores(uint16_t * score_map, uint16_t pos_i, 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; @@ -126,7 +126,7 @@ static char get_dir_to_nearest_enemy(struct MapObj * mo_origin) * "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; @@ -141,13 +141,13 @@ static char get_dir_to_nearest_enemy(struct MapObj * mo_origin) { 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; diff --git a/src/server/configfile.c b/src/server/configfile.c index fc2c771..8bbf4ef 100644 --- a/src/server/configfile.c +++ b/src/server/configfile.c @@ -37,8 +37,7 @@ enum flag 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 }; @@ -76,11 +75,6 @@ static uint8_t start_entry(char * token0, char * token1, char * comparand, 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); @@ -90,21 +84,21 @@ static void write_if_entry(struct EntryHead ** entry, */ 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 @@ -119,21 +113,19 @@ static void tokens_into_entries(char * token0, char * token1) { 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); } @@ -150,10 +142,10 @@ static void tokens_into_entries(char * token0, char * token1) 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(); @@ -184,18 +176,6 @@ static uint8_t start_entry(char * token0, char * token1, char * comparand, -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) { @@ -239,37 +219,36 @@ static void test_corpse_ids() -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 @@ -286,8 +265,7 @@ static uint8_t set_members(char * token0, char * token1, uint8_t * object_flags, *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) @@ -325,7 +303,7 @@ static uint8_t try_func_name(struct MapObjAct * moa, char * name, 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) diff --git a/src/server/field_of_view.c b/src/server/field_of_view.c index 61ebf88..ad58a19 100644 --- a/src/server/field_of_view.c +++ b/src/server/field_of_view.c @@ -205,7 +205,7 @@ static uint8_t mv_yx_in_dir_wrap(char d, struct yx_uint8 * yx, uint8_t unwrap) 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; } @@ -420,11 +420,11 @@ static char * eye_to_cell(struct yx_uint8 * yx_eye, struct yx_uint8 * yx_cell, 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; } @@ -433,18 +433,18 @@ static uint8_t is_top_left_shaded(uint16_t pos_a, uint16_t pos_b, 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); @@ -512,7 +512,7 @@ static void shadow(struct yx_uint8 * yx_eye, struct yx_uint8 * yx_start, 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) { @@ -560,8 +560,8 @@ static void set_view_of_cell_and_shadows(struct yx_uint8 * yx_cell, 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); @@ -584,7 +584,7 @@ extern uint8_t * build_fov_map(struct MapObj * eye) } } 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) { diff --git a/src/server/io.c b/src/server/io.c index 964e06a..488f92b 100644 --- a/src/server/io.c +++ b/src/server/io.c @@ -144,8 +144,7 @@ static void update_worldstate_file() 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) { @@ -199,7 +198,7 @@ static void write_inventory(struct MapObj * player, FILE * file) 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; @@ -238,11 +237,11 @@ static void write_map(struct MapObj * player, FILE * file) 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); } diff --git a/src/server/map.c b/src/server/map.c index 464f6e2..1c9a2f1 100644 --- a/src/server/map.c +++ b/src/server/map.c @@ -50,20 +50,20 @@ static uint8_t is_neighbor(struct yx_uint8 pos, char type) { 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; } @@ -75,11 +75,11 @@ static uint8_t is_neighbor(struct yx_uint8 pos, char type) 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++); } } @@ -88,20 +88,20 @@ static void make_sea() 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; } @@ -116,15 +116,15 @@ static void make_trees() { 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))) { @@ -139,7 +139,7 @@ static void make_trees() 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(); @@ -150,9 +150,9 @@ extern void init_map() 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; } @@ -161,5 +161,5 @@ extern uint8_t is_passable(struct yx_uint8 pos) 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; } diff --git a/src/server/map_objects.c b/src/server/map_objects.c index 975c748..fa20c17 100644 --- a/src/server/map_objects.c +++ b/src/server/map_objects.c @@ -59,8 +59,8 @@ static void add_map_object(uint8_t type) 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;