X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/balance?a=blobdiff_plain;f=src%2Fserver%2Fconfigfile.c;h=8bbf4ef7a6251e61984b023ab22648f00c885f69;hb=0438f2fc5df337e4264103a86c1765ace9c6565a;hp=fc2c771f42d952a3c5c5721d8dd533153ee264f1;hpb=7433f56ec2c6cc51bc497e3c0c67d2fe3e6ab64a;p=plomrogue 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)