home · contact · privacy
Server: Add inanimate things to map memory, integrate into AI searches.
[plomrogue] / src / server / things.c
index 4097f61a65707fc01dfe07a11a7cfa77b65c8dbd..7d0f62d9b19be98ab2da6d1a145887b529aa04a2 100644 (file)
@@ -28,11 +28,14 @@ struct NextAndId
 
 
 
+/* Free ThingsInMemory chain starting at "tm". */
+static void free_things_in_memory(struct ThingInMemory * tm);
+
 /* To linked list of NextAndId structs (or rather structs whose start region is
  * compatible to it) starting at "start", add newly allocated element of
  * "n_size" and an ID that is either "id" or, if "id" is <= UINT8_MAX and >=
- * "id_start", get lowest ID for new thing ("struct_id"==0), thing type
- * ("struct_id"==1) or thing action ("struct_id"==2).
+ * "id_start", get lowest ID >= "start_id" and <= UINT8_MAX for new thing
+ * ("struct_id"=0), thing type ("struct_id"=1) or thing action ("struct_id"=2).
  */
 static struct NextAndId * add_to_struct_list(size_t n_size, uint8_t start_id,
                                              int16_t id, uint8_t struct_id,
@@ -40,6 +43,18 @@ static struct NextAndId * add_to_struct_list(size_t n_size, uint8_t start_id,
 
 
 
+static void free_things_in_memory(struct ThingInMemory * tm)
+{
+    if (NULL == tm)
+    {
+        return;
+    }
+    free_things_in_memory(tm->next);
+    free(tm);
+}
+
+
+
 static struct NextAndId * add_to_struct_list(size_t n_size, uint8_t start_id,
                                              int16_t id, uint8_t struct_id,
                                              struct NextAndId ** start)
@@ -99,6 +114,7 @@ extern struct ThingType * add_thing_type(int16_t id)
                                                  &world.thing_types);
     set_cleanup_flag(CLEANUP_THING_TYPES);
     tt->name = strdup("(none)");
+    tt->corpse_id = tt->id;
     return tt;
 }
 
@@ -120,6 +136,19 @@ extern struct Thing * add_thing(int16_t id, uint8_t type, uint8_t y, uint8_t x)
 
 
 
+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 (NULL == ta)
@@ -155,6 +184,8 @@ extern void free_things(struct Thing * t)
     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    */