From: Christian Heller Date: Sun, 17 Aug 2014 03:15:51 +0000 (+0200) Subject: Server: Free memorized things on map upon actor death. X-Git-Tag: tce~652 X-Git-Url: https://plomlompom.com/repos/ledger?a=commitdiff_plain;h=6b72c6d2208d2a6bf120ef2239c0134550ed32f0;p=plomrogue Server: Free memorized things on map upon actor death. --- diff --git a/src/server/thing_actions.c b/src/server/thing_actions.c index ec713ae..9befd76 100644 --- a/src/server/thing_actions.c +++ b/src/server/thing_actions.c @@ -12,7 +12,8 @@ #include "field_of_view.h" /* build_fov_map() */ #include "hardcoded_strings.h" /* s */ #include "things.h" /* Thing, ThingType, get_player(), own_thing(), - * set_thing_position(), get_thing_type() + * set_thing_position(), get_thing_type(), + * free_things_in_memory() */ #include "map.h" /* is_passable() */ #include "yx_uint8.h" /* mv_yx_in_dir(), yx_uint8_cmp() */ @@ -151,6 +152,8 @@ static void actor_hits_actor(struct Thing * hitter, struct Thing * hitted) hitted->fov_map = NULL; free(hitted->mem_map); hitted->mem_map = NULL; + free_things_in_memory(hitted->t_mem); + hitted->t_mem = NULL; } update_log(" It dies."); } diff --git a/src/server/things.c b/src/server/things.c index bbe9dbf..ffa30b0 100644 --- a/src/server/things.c +++ b/src/server/things.c @@ -28,9 +28,6 @@ struct NextAndId -/* Free ThingsInMemory chain starting at "tm". */ -static void free_things_in_memory(struct ThingInMemory * tm); - /* To linked list of NextAndId structs (or rather structs whose start region is * compatible to it) starting at "start", add newly allocated element of * "n_size" and an ID that is either "id" or, if "id" is <= UINT8_MAX and >= @@ -43,18 +40,6 @@ static struct NextAndId * add_to_struct_list(size_t n_size, uint8_t start_id, -static void free_things_in_memory(struct ThingInMemory * tm) -{ - if (!tm) - { - return; - } - free_things_in_memory(tm->next); - free(tm); -} - - - static struct NextAndId * add_to_struct_list(size_t n_size, uint8_t start_id, int16_t id, uint8_t struct_id, struct NextAndId ** start) @@ -195,6 +180,18 @@ extern void free_things(struct Thing * t) +extern void free_things_in_memory(struct ThingInMemory * tm) +{ + if (!tm) + { + return; + } + free_things_in_memory(tm->next); + free(tm); +} + + + extern struct ThingAction * get_thing_action(uint8_t id) { struct ThingAction * ta = world.thing_actions; diff --git a/src/server/things.h b/src/server/things.h index 365e308..d5ac7ef 100644 --- a/src/server/things.h +++ b/src/server/things.h @@ -79,10 +79,13 @@ extern struct Thing * add_thing(int16_t id, uint8_t type, uint8_t y, uint8_t x); extern void add_thing_to_memory_map(struct Thing * t, uint8_t type, uint8_t y, uint8_t x); -/* Free ThingAction/ThingType/Thing chain starting at "ta"/"tt"/"t". */ +/* Free ThingAction / ThingType / Thing / ThingInMemory chain starting at "ta" / + * "tt" / "t" / "tm". + */ extern void free_thing_actions(struct ThingAction * ta); extern void free_thing_types(struct ThingType * tt); extern void free_things(struct Thing * t); +extern void free_things_in_memory(struct ThingInMemory * tm); /* Return pointer to ThingAction/ThingType of "id", or NULL if none found. */ extern struct ThingAction * get_thing_action(uint8_t id);