From: Christian Heller Date: Wed, 9 Apr 2014 04:06:51 +0000 (+0200) Subject: Server: Make config file set number of objects' start appearances. X-Git-Tag: tce~773 X-Git-Url: https://plomlompom.com/repos/%22https:/validator.w3.org/%7B%7Bprefix%7D%7D/day?a=commitdiff_plain;h=2a60941d0815c19c11a01943faed931e0b364d4f;p=plomrogue Server: Make config file set number of objects' start appearances. --- diff --git a/README b/README index a944cea..90fd601 100644 --- a/README +++ b/README @@ -126,6 +126,7 @@ SYMBOL z LIFEPOINTS 3 CORPSE_ID 5 CONSUMABLE 0 +START_NUMBER 9 A line of "OBJECT" followed by a number starts it, and the number sets the object type's internal id. The number after "CONSUMABLE" defines the object @@ -137,7 +138,8 @@ the id of the object type that objects of this type degrade to if their hitpoints drop to zero if they start out as inanimate (what is not implemented yet: or if they are inanimate, but are otherwise crushed). Note that the "CORPSE_ID" must match the id of an object type defined in the file (before or -after, it may even be the same). +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. All these definition block members must be present within their blocks, but only "ACTION" / "OBJECT" / "MAP_TYPE" must be positioned at their respective blocks' diff --git a/confserver/world b/confserver/world index 84e747d..16e86cb 100644 --- a/confserver/world +++ b/confserver/world @@ -30,6 +30,7 @@ SYMBOL @ LIFEPOINTS 5 CORPSE_ID 5 CONSUMABLE 0 +START_NUMBER 1 OBJECT 1 NAME ANT @@ -37,6 +38,7 @@ SYMBOL a LIFEPOINTS 1 CORPSE_ID 4 CONSUMABLE 0 +START_NUMBER 27 OBJECT 2 NAME ZOMBIE @@ -44,6 +46,7 @@ SYMBOL z LIFEPOINTS 3 CORPSE_ID 5 CONSUMABLE 0 +START_NUMBER 9 OBJECT 3 NAME SHOGGOTH @@ -51,6 +54,7 @@ SYMBOL S LIFEPOINTS 9 CORPSE_ID 6 CONSUMABLE 0 +START_NUMBER 3 OBJECT 4 NAME DIRT @@ -58,6 +62,7 @@ SYMBOL # LIFEPOINTS 0 CORPSE_ID 4 CONSUMABLE 0 +START_NUMBER 9 OBJECT 5 NAME SKELETON @@ -65,6 +70,7 @@ SYMBOL % LIFEPOINTS 0 CORPSE_ID 4 CONSUMABLE 0 +START_NUMBER 9 OBJECT 6 NAME 'MAGIC MEAT' @@ -72,3 +78,4 @@ SYMBOL m LIFEPOINTS 0 CORPSE_ID 4 CONSUMABLE 3 +START_NUMBER 1 diff --git a/src/server/configfile.c b/src/server/configfile.c index 1eb5165..ab368b0 100644 --- a/src/server/configfile.c +++ b/src/server/configfile.c @@ -36,9 +36,10 @@ enum flag 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, READY_MAP = HEIGHT_SET | WIDTH_SET | ORTH_SET | DIAG_SET }; @@ -280,6 +281,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, diff --git a/src/server/init.c b/src/server/init.c index 9f2a4e9..2f6428e 100644 --- a/src/server/init.c +++ b/src/server/init.c @@ -19,8 +19,7 @@ #include "../common/try_malloc.h" /* try_malloc() */ #include "cleanup.h" /* set_cleanup_flag() */ #include "map.h" /* init_map() */ -#include "map_objects.h" /* free_map_objects(), add_map_objects() */ -#include "rrand.h" /* rrand() */ +#include "map_objects.h" /* MapObjDef, free_map_objects(), add_map_objects() */ #include "run.h" /* obey_msg(), io_loop() */ #include "world.h" /* global world */ @@ -87,12 +86,11 @@ extern void remake_world(uint32_t seed) free_map_objects(world.map_objs); world.last_update_turn = 0; init_map(); - add_map_objects(0, 1); - add_map_objects(1, 1 + rrand() % 27); - add_map_objects(2, 1 + rrand() % 9); - add_map_objects(3, 1 + rrand() % 3); - add_map_objects(4, 1 + rrand() % 3); - add_map_objects(5, 1 + rrand() % 3); + struct MapObjDef * mod; + for (mod = world.map_obj_defs; NULL != mod; mod = mod->next) + { + add_map_objects(mod->id, mod->start_n); + } set_cleanup_flag(CLEANUP_MAP_OBJECTS); if (world.turn) { diff --git a/src/server/init.h b/src/server/init.h index 0be0dfd..1cc6706 100644 --- a/src/server/init.h +++ b/src/server/init.h @@ -23,8 +23,7 @@ extern void setup_server_io(); * Map object (action) definitions read in from server config directory are not * affected. world.last_update_turn is set to 0 and world.turn to 1, so that * io_round()'s criteria for updating the output file are triggered even when - * this function is called during a round 1. How many map objects of what type - * id are generated on the map is currently hard-coded. + * this function is called during a round 1. */ extern void remake_world(uint32_t seed); diff --git a/src/server/map_objects.h b/src/server/map_objects.h index fdd11f9..d18e3c2 100644 --- a/src/server/map_objects.h +++ b/src/server/map_objects.h @@ -34,6 +34,7 @@ struct MapObjDef uint8_t corpse_id; /* type to change map object into upon destruction */ uint8_t lifepoints; /* default start value for map object's .lifepoints */ uint8_t consumable; /* can be eaten if !0, for so much hitpoint win */ + uint8_t start_n; /* how many of these does the map start with? */ };