home · contact · privacy
Server: Free memorized things on map upon actor death.
authorChristian Heller <c.heller@plomlompom.de>
Sun, 17 Aug 2014 03:15:51 +0000 (05:15 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Sun, 17 Aug 2014 03:15:51 +0000 (05:15 +0200)
src/server/thing_actions.c
src/server/things.c
src/server/things.h

index ec713ae5bd02dc2e9dac915c48066e154812b151..9befd76234bc1efba1f2c9edf0c047d99eb7946c 100644 (file)
@@ -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.");
     }
index bbe9dbffe39388399b741965c7ead8bb2aa61baa..ffa30b01324b4405c143fa6d3c5617d06cb052fe 100644 (file)
@@ -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;
index 365e308b4c4cb8da0ab67bca087c92ef92694171..d5ac7ef1556a3c26c8ea68dc55647f8b08b67906 100644 (file)
@@ -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);