From b05b66a27258c581a10e81348088c3486cb8f569 Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Wed, 2 Oct 2013 11:24:10 +0200
Subject: [PATCH] Changed the way the end of the map object list is identified.

---
 src/main.c        |  1 -
 src/main.h        |  1 -
 src/map_objects.c | 14 ++++++--------
 3 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/src/main.c b/src/main.c
index adeddce..68b1ebb 100644
--- a/src/main.c
+++ b/src/main.c
@@ -135,7 +135,6 @@ int main(int argc, char *argv[])
     if (0 == world.turn)
     {
         world.map_objs = NULL;
-        world.last_map_obj = NULL;
         add_map_objects(&world, 0, 1);
         add_map_objects(&world, 1, 1 + rrand() % 27);
         add_map_objects(&world, 2, 1 + rrand() % 9);
diff --git a/src/main.h b/src/main.h
index cd6e6c0..56d458b 100644
--- a/src/main.h
+++ b/src/main.h
@@ -37,7 +37,6 @@ struct World
     uint8_t map_obj_count;            /* Counts map objects generated so far. */
     struct MapObjDef * map_obj_defs;  /* Map object type definitions chain. */
     struct MapObj * map_objs;         /* Pointer to map objects chain start. */
-    struct MapObj * last_map_obj;     /* Pointer to map objects chain end. */
 };
 
 
diff --git a/src/map_objects.c b/src/map_objects.c
index 93f4684..ed41d93 100644
--- a/src/map_objects.c
+++ b/src/map_objects.c
@@ -96,7 +96,6 @@ extern void read_map_objects(struct World * world, FILE * file, char * line,
         * mo_ptr_ptr = mo;
         mo_ptr_ptr = &mo->next;
     }
-    world->last_map_obj = mo;
 }
 
 
@@ -132,15 +131,14 @@ extern void add_map_object(struct World * world, uint8_t type)
         }
     }
     mo->next = NULL;
-    if (NULL == world->last_map_obj)
+    struct MapObj ** last_ptr_ptr = &world->map_objs;
+    struct MapObj * mo_ptr;
+    while (NULL != * last_ptr_ptr)
     {
-        world->map_objs = mo;
+        mo_ptr = * last_ptr_ptr;
+        last_ptr_ptr = & mo_ptr->next;
     }
-    else
-    {
-        world->last_map_obj->next = mo;
-    }
-    world->last_map_obj = mo;
+    * last_ptr_ptr = mo;
 }
 
 
-- 
2.30.2