X-Git-Url: https://plomlompom.com/repos/berlin_corona.txt?a=blobdiff_plain;ds=sidebyside;f=src%2Fserver%2Fconfigfile.c;h=537650246dd8e84e09e8d29b1ed71c5f06de89ed;hb=12239c92a51581d5bf621992f3f3ef9de6b76e59;hp=ab368b0ea65ad1496caac6397a516c005679ff34;hpb=2a60941d0815c19c11a01943faed931e0b364d4f;p=plomrogue diff --git a/src/server/configfile.c b/src/server/configfile.c index ab368b0..5376502 100644 --- a/src/server/configfile.c +++ b/src/server/configfile.c @@ -15,8 +15,8 @@ #include "cleanup.h" /* set_cleanup_flag(), CLEANUP_MAP_OBJ_DEFS, * CLEANUP_MAP_OBJ_ACTS */ -#include "map_object_actions.h" /* struct MapObjAct */ -#include "map_objects.h" /* struct MapObj, struct MapObjDef */ +#include "map_object_actions.h" /* MapObjAct */ +#include "map_objects.h" /* MapObj, MapObjDef, struct MapObjDef */ #include "world.h" /* world global */ @@ -92,6 +92,9 @@ static void write_if_entry(struct EntryHead ** entry, */ static void test_corpse_ids(); +/* If "token0" matches "comparand", set world.player_type to int in "token1". */ +static uint8_t set_player_type(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 @@ -119,6 +122,7 @@ 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"; 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; @@ -127,7 +131,7 @@ static void tokens_into_entries(char * token0, char * token1) 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_map) || !strcmp(token0, str_player)) { parse_and_reduce_to_readyflag(&action_flags, READY_ACT); parse_and_reduce_to_readyflag(&object_flags, READY_OBJ); @@ -138,16 +142,21 @@ static void tokens_into_entries(char * token0, char * token1) if (token0) { parsetest_too_many_values(); - if (!( start_entry(token0, token1, str_act, &action_flags, - sizeof(struct MapObjAct),(struct EntryHead**) &moa, - (struct EntryHead *) world.map_obj_acts) - || start_entry(token0, token1, str_obj, &object_flags, - sizeof(struct MapObjDef),(struct EntryHead**) &mod, - (struct EntryHead *) world.map_obj_defs) - || start_map(token0, str_map, &map_flags) - || set_members(token0, token1, &object_flags, &action_flags, - &map_flags, (struct MapObjDef *)mod, - (struct MapObjAct *) moa))) + if (start_entry(token0, token1, str_act, &action_flags, + sizeof(struct MapObjAct), (struct EntryHead**) &moa, + (struct EntryHead *) world.map_obj_acts)) + { + err_line(0 == atoi(token1), "Value must not be 0."); + } + else if (!( start_entry(token0, token1, str_obj, &object_flags, + 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_members(token0, token1, &object_flags, &action_flags, + &map_flags, (struct MapObjDef *)mod, + (struct MapObjAct *) moa))) { parse_unknown_arg(); } @@ -232,7 +241,7 @@ static void test_corpse_ids() -static uint8_t set_map_members(char * token0, char * token1, uint8_t * map_flags) +static uint8_t set_map_members(char * token0, char * token1,uint8_t * map_flags) { if ( parse_val(token0, token1, "HEIGHT", map_flags, HEIGHT_SET, 'i', (char *) &world.map.size.y) @@ -244,9 +253,9 @@ static uint8_t set_map_members(char * token0, char * token1, uint8_t * map_flags return 1; } else if ( parse_val(token0, token1, "DIST_ORTHOGONAL", map_flags, - ORTH_SET, '8', (char *) &world.map.dist_orthogonal) + ORTH_SET, '8', (char *) &world.map.dist_orthogonal) || parse_val(token0, token1, "DIST_DIAGONAL", map_flags, - DIAG_SET, '8', (char *) &world.map.dist_diagonal)) + DIAG_SET, '8', (char *) &world.map.dist_diagonal)) { err_line(0 == atoi(token1), "Value must not be zero."); return 1; @@ -256,6 +265,19 @@ 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 (strcmp(token0, comparand)) + { + return 0; + } + parsetest_int(token1, '8'); + world.player_type = 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, struct MapObjDef * mod, struct MapObjAct * moa) @@ -314,6 +336,17 @@ 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."); + uint8_t player_type_is_valid = 0; + struct MapObjDef * mod; + for (mod = world.map_obj_defs; NULL != mod; mod = mod->next) + { + if (world.player_type == mod->id) + { + player_type_is_valid = 1; + break; + } + } + exit_err(!player_type_is_valid, "No valid map object type set for player."); set_cleanup_flag(CLEANUP_MAP_OBJECT_ACTS | CLEANUP_MAP_OBJECT_DEFS); test_corpse_ids(); }