home · contact · privacy
Changed way world.map_obj_count is transmitted; also re-factoring of map_objects...
[plomrogue] / src / map_object_actions.c
index 1d3139fd157b1a2fa2fb806457a3a97c49d4600e..7059863bd722dfdc0462f9379b242be10b069cc7 100644 (file)
@@ -12,7 +12,7 @@
 #include "misc.h" /* for update_log(), try_malloc() */
 #include "map.h" /* for is_passable() */
 #include "main.h" /* for world global */
-#include "readwrite.h" /* for try_fopen(), try_fclose(), get_linemax() */
+#include "readwrite.h" /* for try_fopen(), try_fclose(), textfile_sizes() */
 #include "rexit.h" /* for exit_err() */
 
 
@@ -27,7 +27,7 @@ static uint8_t try_func_name(struct MapObjAct * moa,
 static void actor_hits_actor(struct MapObj * hitter, struct MapObj * hitted);
 
 /* Bonus stuff to actor_*() to happen if actor==player. Mostly writing of log
- * messages; _pick and _drop also decrement world.inventory_select by 1 if >0.
+ * messages; _pick and _drop also decrement world.inventory_sel by 1 if >0.
  */
 static void playerbonus_wait();
 static void playerbonus_move(char d, uint8_t passable);
@@ -135,9 +135,9 @@ static void playerbonus_drop(uint8_t owns_none)
     else
     {
         update_log("\nYou drop an object.");
-        if (0 < world.inventory_select)
+        if (0 < world.inventory_sel)
         {
-            world.inventory_select--;
+            world.inventory_sel--;
         }
     }
 }
@@ -171,9 +171,9 @@ static void playerbonus_use(uint8_t no_object, uint8_t wrong_object)
     else
     {
         update_log("\nYou consume MAGIC MEAT.");
-        if (0 < world.inventory_select)
+        if (0 < world.inventory_sel)
         {
-            world.inventory_select--;
+            world.inventory_sel--;
         }
     }
 }
@@ -186,7 +186,7 @@ extern void init_map_object_actions()
 
     char * path = "config/map_object_actions";
     FILE * file = try_fopen(path, "r", f_name);
-    uint16_t linemax = get_linemax(file, f_name);
+    uint16_t linemax = textfile_sizes(file, NULL);
     char line[linemax + 1];
 
     struct MapObjAct ** moa_ptr_ptr = &world.map_obj_acts;
@@ -233,6 +233,23 @@ extern void free_map_object_actions(struct MapObjAct * moa)
 
 
 
+extern uint8_t get_moa_id_by_name(char * name)
+{
+    struct MapObjAct * moa = world.map_obj_acts;
+    while (NULL != moa)
+    {
+        if (0 == strcmp(moa->name, name))
+        {
+            break;
+        }
+        moa = moa->next;
+    }
+    exit_err(NULL == moa, "get_moa_id_name() did not find map object action.");
+    return moa->id;
+}
+
+
+
 extern void actor_wait(struct MapObj * mo)
 {
     if (mo == get_player())