+/* Write representation of "mo" and all of the map objects it owns to "file". */
+static void write_map_object(struct World * w, FILE * file, struct MapObj * mo);
+
+
+
+/* Return pointer to map object of "id" in chain starting at "ptr". */
+static struct MapObj * get_map_object(struct MapObj * ptr, uint8_t id);
+
+
+
+static void write_map_object(struct World * w, FILE * file, struct MapObj * mo)
+{
+ char * f_name = "write_map_object()";
+ struct MapObj * mo_ptr = mo->owns;
+ uint8_t i = 0;
+ for (; NULL != mo_ptr; mo_ptr = mo_ptr->next, i++);
+ uint8_t size = 3+1 + 3+1 + 3+1 + 5+1 + 5 + ((1+3)*i) + 1 + 1;
+ char line[size];
+ sprintf(line, "%d %d %d %d %d",
+ mo->id, mo->type, mo->lifepoints, mo->pos.y, mo->pos.x);
+ for (mo_ptr = mo->owns; NULL != mo_ptr; mo_ptr = mo_ptr->next)
+ {
+ sprintf(line + strlen(line), " %d", mo_ptr->id);
+ }
+ line[strlen(line) + 1] = '\0';
+ line[strlen(line)] = '\n';
+ try_fwrite(line, strlen(line), 1, file, w, f_name);
+ for (mo_ptr = mo->owns; NULL != mo_ptr; mo_ptr = mo_ptr->next)
+ {
+ write_map_object(w, file, mo_ptr);
+ }
+}
+
+
+
+static struct MapObj * get_map_object(struct MapObj * ptr, uint8_t id)
+{
+ while (1)
+ {
+ if (NULL == ptr || id == ptr->id)
+ {
+ return ptr;
+ }
+ struct MapObj * owned_object = get_map_object(ptr->owns, id);
+ if (NULL != owned_object)
+ {
+ return ptr;
+ }
+ ptr = ptr->next;
+ }
+}
+
+
+