From: Christian Heller Date: Thu, 26 Sep 2013 03:00:09 +0000 (+0200) Subject: New animate map objects are never placed on a square with other animated map objects... X-Git-Tag: tce~947 X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/move_down?a=commitdiff_plain;h=2c2521789dc5c8bb77eb36362d4244606f878420;p=plomrogue New animate map objects are never placed on a square with other animated map objects; also fixed a bug that hindered compilation. --- diff --git a/src/map_object_actions.c b/src/map_object_actions.c index 3e9ead2..387b18a 100644 --- a/src/map_object_actions.c +++ b/src/map_object_actions.c @@ -15,7 +15,7 @@ * reach zero in the process, killing it. Generates appropriate log message. */ static void actor_hits_actor(struct World * world, struct MapObj * hitter, - struct MapObj * hitted) + struct MapObj * hitted); diff --git a/src/map_objects.c b/src/map_objects.c index e825755..93f4684 100644 --- a/src/map_objects.c +++ b/src/map_objects.c @@ -11,6 +11,7 @@ #include "misc.h" /* for try_malloc(), try_calloc(), find_passable_pos() */ #include "main.h" /* for World struct */ #include "rexit.h" /* for err_exit() */ +#include "yx_uint16.h" /* for yx_uint16 struct, yx_uint16_cmp() */ @@ -109,7 +110,27 @@ extern void add_map_object(struct World * world, uint8_t type) world->map_obj_count++; mo->type = mod->id; mo->lifepoints = mod->lifepoints; - mo->pos = find_passable_pos(world->map); + while (1) + { + struct yx_uint16 pos = find_passable_pos(world->map); + struct MapObj * mo_ptr; + uint8_t clear = 1; + for (mo_ptr = world->map_objs; + mo_ptr != NULL; + mo_ptr = mo_ptr->next) + { + if (yx_uint16_cmp(&pos, &mo_ptr->pos) && 0 != mo_ptr->lifepoints) + { + clear = 0; + break; + } + } + if (1 == clear) + { + mo->pos = pos; + break; + } + } mo->next = NULL; if (NULL == world->last_map_obj) { diff --git a/src/map_objects.h b/src/map_objects.h index a56595f..5cbab7b 100644 --- a/src/map_objects.h +++ b/src/map_objects.h @@ -49,7 +49,10 @@ extern void free_map_object_defs(struct MapObjDef * mod_start); -/* Add new object(s) ("n": how many?) of "type" to map on random position(s). */ +/* Add new object(s) ("n": how many?) of "type" to map on random position(s). + * New animate objects are never placed in the same square with other animated + * ones. + */ 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);