X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bdeck_id%7D%7D/cards/%7B%7Bcard_id%7D%7D/static/gitweb.js?a=blobdiff_plain;f=src%2Fmap_objects.c;h=ed41d93ac62f30ab65c5fd194182782a8d034156;hb=b05b66a27258c581a10e81348088c3486cb8f569;hp=7e2472d0da521abe19b873088e7cb96f36571563;hpb=9d35a239f47714198b942deca3171334409a27bb;p=plomrogue diff --git a/src/map_objects.c b/src/map_objects.c index 7e2472d..ed41d93 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() */ @@ -78,9 +79,10 @@ extern void read_map_objects(struct World * world, FILE * file, char * line, char * f_name = "read_map_objects()"; struct MapObj ** mo_ptr_ptr = &world->map_objs; char * delim = " "; + struct MapObj * mo; while (try_fgets(line, linemax + 1, file, world, f_name)) { - struct MapObj * mo = malloc(sizeof(struct MapObj)); + mo = malloc(sizeof(struct MapObj)); mo->next = NULL; mo->id = atoi(strtok(line, delim)); if (mo->id > world->map_obj_count) @@ -107,9 +109,36 @@ 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); - mo->next = world->map_objs; - world->map_objs = mo; + 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; + struct MapObj ** last_ptr_ptr = &world->map_objs; + struct MapObj * mo_ptr; + while (NULL != * last_ptr_ptr) + { + mo_ptr = * last_ptr_ptr; + last_ptr_ptr = & mo_ptr->next; + } + * last_ptr_ptr = mo; } @@ -137,6 +166,25 @@ extern void free_map_objects(struct MapObj * mo_start) +extern struct MapObj * get_player(struct World * world) +{ + struct MapObj * ptr = world->map_objs; + while (1) + { + if (NULL == ptr) + { + return ptr; + } + if (0 == ptr->id) + { + return ptr; + } + ptr = ptr->next; + } +} + + + extern struct MapObjDef * get_map_object_def(struct World * w, uint8_t id) { struct MapObjDef * mod = w->map_obj_defs;