From: Christian Heller Date: Wed, 25 Sep 2013 22:40:48 +0000 (+0200) Subject: Simplified adding new objects to map. X-Git-Tag: tce~950 X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/%7B%7Bprefix%7D%7D/do_tasks?a=commitdiff_plain;h=9d35a239f47714198b942deca3171334409a27bb;p=plomrogue Simplified adding new objects to map. --- diff --git a/src/main.c b/src/main.c index 5d253ce..71a5370 100644 --- a/src/main.c +++ b/src/main.c @@ -138,12 +138,12 @@ int main(int argc, char *argv[]) if (0 == world.turn) { player.pos = find_passable_pos(world.map); - struct MapObj ** ptr; - ptr = build_map_objects(&world, &world.map_objs, 1, 1 + rrand() % 27); - ptr = build_map_objects(&world, ptr, 2, 1 + rrand() % 9); - ptr = build_map_objects(&world, ptr, 3, 1 + rrand() % 3); - ptr = build_map_objects(&world, ptr, 4, 1 + rrand() % 3); - ptr = build_map_objects(&world, ptr, 5, 1 + rrand() % 3); + world.map_objs = NULL; + add_map_objects(&world, 1, 1 + rrand() % 27); + add_map_objects(&world, 2, 1 + rrand() % 9); + add_map_objects(&world, 3, 1 + rrand() % 3); + add_map_objects(&world, 4, 1 + rrand() % 3); + add_map_objects(&world, 5, 1 + rrand() % 3); set_cleanup_flag(CLEANUP_MAP_OBJECTS); world.turn = 1; } diff --git a/src/map_objects.c b/src/map_objects.c index e690281..7e2472d 100644 --- a/src/map_objects.c +++ b/src/map_objects.c @@ -98,27 +98,29 @@ extern void read_map_objects(struct World * world, FILE * file, char * line, -extern struct MapObj ** build_map_objects(struct World * w, - struct MapObj ** mo_ptr_ptr, - uint8_t type, uint8_t n) +extern void add_map_object(struct World * world, uint8_t type) { - char * f_name = "build_map_objects()"; - uint8_t i = 0; - struct MapObjDef * mod = get_map_object_def(w, type); - while (i < n) + char * f_name = "add_map_object"; + struct MapObjDef * mod = get_map_object_def(world, type); + struct MapObj * mo = try_malloc(sizeof(struct MapObj), world, f_name); + mo->id = world->map_obj_count; + world->map_obj_count++; + mo->type = mod->id; + mo->lifepoints = mod->lifepoints; + mo->pos = find_passable_pos(world->map); + mo->next = world->map_objs; + world->map_objs = mo; +} + + + +extern void add_map_objects(struct World * world, uint8_t type, uint8_t n) +{ + uint8_t i; + for (i = 0; i < n; i++) { - struct MapObj * mo = try_malloc(sizeof(struct MapObj), w, f_name); - mo->id = w->map_obj_count; - w->map_obj_count++; - mo->type = mod->id; - mo->next = NULL; - mo->lifepoints = mod->lifepoints; - mo->pos = find_passable_pos(w->map); - i++; - * mo_ptr_ptr = mo; - mo_ptr_ptr = &mo->next; + add_map_object(world, type); } - return mo_ptr_ptr; } diff --git a/src/map_objects.h b/src/map_objects.h index 29bae85..ced2ab3 100644 --- a/src/map_objects.h +++ b/src/map_objects.h @@ -57,10 +57,11 @@ extern void init_map_object_defs(struct World * world, char * filename); extern void free_map_object_defs(struct MapObjDef * mod_start); -/* Build chain of "n" map objects of "tpye" to start at "mo_ptr_ptr". */ -extern struct MapObj ** build_map_objects(struct World * w, - struct MapObj ** mo_ptr_ptr, - uint8_t type, uint8_t n); + +/* Add new object(s) ("n": how many?) of "type" to map on random position(s). */ +extern void add_map_object(struct World * world, uint8_t type); +extern void add_map_objects(struct World * world, uint8_t type, uint8_t n); + /* Write map objects chain to "file". */