+ struct NextAndId * nai = try_malloc(n_size, __func__);
+ memset(nai, 0, n_size);
+ if (start_id <= id && id <= UINT8_MAX)
+ {
+ nai->id = id;
+ }
+ else
+ {
+ while (1)
+ {
+ if ( (0 == struct_id && !get_thing(world.things, start_id, 1))
+ || (1 == struct_id && !get_thing_type(start_id))
+ || (2 == struct_id && !get_thing_action(start_id)))
+ {
+ nai->id = start_id;
+ break;
+ }
+ char * err = "No unused ID available to add to ID list.";
+ exit_err(start_id == UINT8_MAX, err);
+ start_id++;
+ }
+ }
+ struct NextAndId ** nai_ptr_ptr = start;
+ for (; * nai_ptr_ptr; nai_ptr_ptr = &(*nai_ptr_ptr)->next);
+ *nai_ptr_ptr = nai;
+ return nai;
+}
+
+
+
+extern struct ThingAction * add_thing_action(uint8_t id)
+{
+ struct ThingAction * ta;
+ ta = (struct ThingAction *) add_to_struct_list(sizeof(struct ThingAction),
+ 1, (int16_t) id, 2,
+ (struct NextAndId **)
+ &world.thing_actions);
+ set_cleanup_flag(CLEANUP_THING_ACTIONS);
+ ta->name = strdup(s[S_CMD_WAIT]);
+ ta->effort = 1;
+ ta->func = actor_wait;
+ return ta;
+}
+
+
+
+extern struct ThingType * add_thing_type(int16_t id)
+{
+ struct ThingType * tt;
+ tt = (struct ThingType *) add_to_struct_list(sizeof(struct ThingType),
+ 0, id, 1,
+ (struct NextAndId **)
+ &world.thing_types);
+ set_cleanup_flag(CLEANUP_THING_TYPES);
+ tt->name = strdup("(none)");
+ tt->corpse_id = tt->id;
+ return tt;
+}
+
+
+
+extern struct Thing * add_thing(int16_t id, uint8_t type, uint8_t y, uint8_t x)
+{
+ struct Thing * t;
+ t = (struct Thing *) add_to_struct_list(sizeof(struct Thing), 0, id, 0,
+ (struct NextAndId **)&world.things);
+ struct ThingType * tt = get_thing_type(type);
+ set_cleanup_flag(CLEANUP_THINGS);
+ t->type = tt->id;
+ t->lifepoints = tt->lifepoints;
+ t->pos.y = y;
+ t->pos.x = x;
+ if (t->lifepoints && world.exists)
+ {
+ build_fov_map(t);
+ }
+ return t;
+}
+
+
+
+extern void add_thing_to_memory_map(struct Thing * t, uint8_t type,
+ uint8_t y, uint8_t x)
+{
+ struct ThingInMemory * tm=try_malloc(sizeof(struct ThingInMemory),__func__);
+ tm->type = type;
+ tm->pos.y = y;
+ tm->pos.x = x;
+ tm->next = t->t_mem;
+ t->t_mem = tm;
+}
+
+
+
+extern void free_thing_actions(struct ThingAction * ta)
+{
+ if (!ta)
+ {
+ return;
+ }
+ free_thing_actions(ta->next);
+ free(ta->name);
+ free(ta);
+}
+
+
+
+extern void free_thing_types(struct ThingType * tt)
+{
+ if (!tt)
+ {
+ return;
+ }
+ free_thing_types(tt->next);
+ free(tt->name);
+ free(tt);
+}
+
+
+
+extern void free_things(struct Thing * t)
+{
+ if (!t)
+ {
+ return;
+ }
+ free_things(t->owns);
+ free_things(t->next);
+ free(t->fov_map);
+ free(t->mem_map);
+ free_things_in_memory(t->t_mem);
+ free(t);
+ if (t == world.things) /* So add_things()' NULL-delimited thing */
+ { /* iteration loop does not iterate over */
+ world.things = NULL; /* freed memory when called the first time */
+ } /* after world re-seeding. */
+}
+
+
+
+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;
+ for (; ta && id != ta->id; ta = ta->next);
+ return ta;
+}
+
+
+
+extern struct ThingType * get_thing_type(uint8_t id)
+{
+ struct ThingType * tt = world.thing_types;
+ for (; tt && id != tt->id; tt = tt->next);
+ return tt;
+}
+
+
+
+extern uint8_t get_thing_action_id_by_name(char * name)
+{
+ struct ThingAction * ta = world.thing_actions;
+ while (ta)