home · contact · privacy
While adding cleaning up / freeing of map objects, fixed bug that initialized map...
[plomrogue] / src / map_objects.c
index a5158cec3bbcfc2033e9ccb8d450b6037ff1df92..f0f002caa31feddaaaba44d6cdef7a7a935404fa 100644 (file)
@@ -4,7 +4,7 @@
 #include <stdlib.h> /* for malloc(), calloc(), free(), atoi() */
 #include <stdint.h> /* for uint8_t */
 #include <stdio.h> /* for FILE typedef */
-#include <string.h> /* for strchr(), strlen(), memcpy()  */
+#include <string.h> /* for strchr(), strlen(), memcpy(), strtok() */
 #include "readwrite.h" /* for [read/write]_uint[8/16/23][_bigendian]() */
 #include "misc.h" /* for textfile_sizes(), find_passable_pos() */
 #include "main.h" /* for World struct */
@@ -139,6 +139,31 @@ extern void init_map_object_defs(struct World * world, char * filename)
 
 
 
+extern void free_item_defs(struct ItemDef * id_start)
+{
+    if (0 != id_start->map_obj_def.next)
+    {
+        free_item_defs((struct ItemDef *) id_start->map_obj_def.next);
+    }
+    free(id_start->map_obj_def.desc);
+    free(id_start);
+}
+
+
+
+
+extern void free_monster_defs(struct MonsterDef * md_start)
+{
+    if (0 != md_start->map_obj_def.next)
+    {
+        free_monster_defs((struct MonsterDef *) md_start->map_obj_def.next);
+    }
+    free(md_start->map_obj_def.desc);
+    free(md_start);
+}
+
+
+
 extern uint8_t write_map_objects(struct World * world, void * start,
                                  FILE * file)
 {
@@ -265,7 +290,29 @@ extern void * build_map_objects(struct World * world, void * start, char def_id,
 
 
 
-extern struct MapObjDef * get_map_obj_def (struct World * world, char def_id)
+extern void free_items(struct Item * item)
+{
+    if (0 != item->map_obj.next)
+    {
+        free_items((struct Item *) item->map_obj.next);
+    }
+    free(item);
+}
+
+
+
+extern void free_monsters(struct Monster * monster)
+{
+    if (0 != monster->map_obj.next)
+    {
+        free_monsters((struct Monster *) monster->map_obj.next);
+    }
+    free(monster);
+}
+
+
+
+extern struct MapObjDef * get_map_obj_def(struct World * world, char def_id)
 {
     struct MapObjDef * d = NULL;
     for (d = (struct MapObjDef *) world->monster_def;