X-Git-Url: https://plomlompom.com/repos/foo.html?a=blobdiff_plain;f=src%2Fserver%2Fconfigfile.c;h=8bbf4ef7a6251e61984b023ab22648f00c885f69;hb=0438f2fc5df337e4264103a86c1765ace9c6565a;hp=a48c494a2d4ab8a7ba49d767f568015430df75d4;hpb=d361b21fb63d9e1fd2ff7774c2322fab3e4eb239;p=plomrogue
diff --git a/src/server/configfile.c b/src/server/configfile.c
index a48c494..8bbf4ef 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 */
@@ -26,15 +26,18 @@
*/
enum flag
{
+ HEIGHT_SET = 0x02,
+ WIDTH_SET = 0x04,
NAME_SET = 0x02,
EFFORT_SET = 0x04,
CORPSE_ID_SET = 0x04,
SYMBOL_SET = 0x08,
LIFEPOINTS_SET = 0x10,
CONSUMABLE_SET = 0x20,
+ START_N_SET = 0x40,
READY_ACT = NAME_SET | EFFORT_SET,
READY_OBJ = NAME_SET | CORPSE_ID_SET | SYMBOL_SET | LIFEPOINTS_SET
- | CONSUMABLE_SET
+ | CONSUMABLE_SET | START_N_SET
};
@@ -81,16 +84,22 @@ static void write_if_entry(struct EntryHead ** entry,
*/
static void test_corpse_ids();
-/* Try to read tokens as members for the entry currently edited, which must be
- * either "mod" or "moa". What member of which of the two is set depends on
- * which of "object_flags" and "action_flags" has EDIT_STARTED set and on the
- * key name in "token0". Return 1 if interpretation succeeds, else 0.
+/* 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". 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, struct MapObjDef * mod,
- struct MapObjAct * moa);
+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
* .func from .name for set_members().
@@ -104,13 +113,16 @@ static void tokens_into_entries(char * token0, char * token1)
{
char * str_act = "ACTION";
char * str_obj = "OBJECT";
+ 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 struct EntryHead * moa = NULL;
static struct EntryHead * mod = NULL;
- if (!token0 || !strcmp(token0,str_act) || !strcmp(token0,str_obj))
+ if (!token0 || !strcmp(token0, str_act) || !strcmp(token0, str_obj)
+ || !strcmp(token0, str_player))
{
parse_and_reduce_to_readyflag(&action_flags, READY_ACT);
parse_and_reduce_to_readyflag(&object_flags, READY_OBJ);
@@ -120,14 +132,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)
- || set_members(token0, token1, &object_flags, &action_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)
+ || set_player_type(token0, str_player, token1)
+ || set_map_length(token0, str_map_length, token1)
+ || set_members(token0, token1, &object_flags, &action_flags,
+ (struct MapObjDef *)mod,
+ (struct MapObjAct *) moa)))
{
parse_unknown_arg();
}
@@ -200,9 +219,37 @@ static void test_corpse_ids()
+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_map_length(char * token0, char * comparand, char * token1)
+{
+ if (strcmp(token0, comparand))
+ {
+ return 0;
+ }
+ 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, struct MapObjDef * mod,
- struct MapObjAct * moa)
+ uint8_t * action_flags,
+ struct MapObjDef * mod, struct MapObjAct * moa)
{
if ( *action_flags & EDIT_STARTED
&& parse_val(token0, token1, "NAME", action_flags,
@@ -224,6 +271,8 @@ static uint8_t set_members(char * token0, char * token1, uint8_t * object_flags,
SYMBOL_SET, 'c', (char *) &mod->char_on_map)
|| parse_val(token0, token1, "EFFORT", action_flags,
EFFORT_SET, '8', (char *) &moa->effort)
+ || parse_val(token0, token1, "START_NUMBER", object_flags,
+ START_N_SET, '8', (char *) &mod->start_n)
|| parse_val(token0, token1, "LIFEPOINTS", object_flags,
LIFEPOINTS_SET, '8', (char *) &mod->lifepoints)
|| parse_val(token0, token1, "CONSUMABLE", object_flags,
@@ -254,6 +303,18 @@ 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.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)
+ {
+ 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();
}