From 1db87a6e612c717a08d2902e1281f2ee7538f72f Mon Sep 17 00:00:00 2001 From: Kp Date: Tue, 14 Jul 2015 02:42:11 +0000 Subject: [PATCH] Return objnum_t from get_next_object --- similar/editor/eobject.cpp | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/similar/editor/eobject.cpp b/similar/editor/eobject.cpp index acc7aa057..e31730e3a 100644 --- a/similar/editor/eobject.cpp +++ b/similar/editor/eobject.cpp @@ -71,28 +71,31 @@ static void show_objects_in_segment(const vcsegptr_t sp) } //returns the number of the first object in a segment, skipping the player -static int get_first_object(const vsegptr_t seg) +static objnum_t get_first_object(const vsegptr_t seg) { - int id; - - id = seg->objects; - - if (id == (ConsoleObject-Objects)) - id = Objects[id].next; - + const auto id = seg->objects; + if (id == object_none) + return object_none; + const auto &&o = vobjptr(id); + if (o == ConsoleObject) + return o->next; return id; } //returns the number of the next object in a segment, skipping the player -static int get_next_object(const vsegptr_t seg,objnum_t id) +static objnum_t get_next_object(const vsegptr_t seg,objnum_t id) { - if (id==object_none || (id=Objects[id].next)==object_none) + if (id == object_none) return get_first_object(seg); - - if (id == (ConsoleObject-Objects)) - return get_next_object(seg,id); - - return id; + for (auto o = vobjptr(id);;) + { + id = o->next; + if (id == object_none) + return get_first_object(seg); + o = vobjptr(id); + if (o != ConsoleObject) + return id; + } }