From: Christian Heller <c.heller@plomlompom.de>
Date: Sat, 9 Nov 2013 04:48:57 +0000 (+0100)
Subject: Dead shoggoths corpse to "magic meat" that can now be "used" i.e. consumed for hitpoi... 
X-Git-Tag: tce~930
X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/blog?a=commitdiff_plain;h=42f6cd9789e06f0257a078a33fa13aaea0714fce;p=plomrogue

Dead shoggoths corpse to "magic meat" that can now be "used" i.e. consumed for hitpoint gaining.
---

diff --git a/README b/README
index 08428c0..dfcf65e 100644
--- a/README
+++ b/README
@@ -8,7 +8,9 @@ bizarre fashion.
 You can move around a player and meet a number of different enemies. They move
 randomly and will only accidentally hit you. You have 5 hitpoints to lose before
 death; they have either 1, 3 or 9. Your score grows by killing enemies, to the
-amount of hitpoints each killed enemy started with.
+amount of hitpoints each killed enemy started with. Dead enemies become dirt,
+skeletons or "magic meat"--such objects can be collected, and "magic meat" can
+be consumed to gain hitpoints.
 
 The map gets generated randomly, too.
 
diff --git a/config/commands b/config/commands
index ba35ecb..9368f0b 100644
--- a/config/commands
+++ b/config/commands
@@ -48,3 +48,4 @@
 48 pick pick up object from ground
 49 inv_d inventory selection down
 50 inv_u inventory selection up
+51 use use selected inventory object
diff --git a/config/defs b/config/defs
index 4689c6c..f114ce2 100644
--- a/config/defs
+++ b/config/defs
@@ -1,6 +1,7 @@
 0 5 @ 5 HUMAN
 1 4 a 1 ANT
 2 5 z 3 ZOMBIE
-3 5 S 9 SHOGGOTH
+3 6 S 9 SHOGGOTH
 4 4 # 0 DIRT
 5 4 % 0 SKELETON
+6 4 m 0 MAGIC MEAT
diff --git a/config/windows/Win_c b/config/windows/Win_c
index d6b2588..b513c69 100644
--- a/config/windows/Win_c
+++ b/config/windows/Win_c
@@ -5,3 +5,4 @@ c
 100 drop
 259 inv_u
 258 inv_d
+117 use
diff --git a/src/control.c b/src/control.c
index b282bc6..cb5ed3b 100644
--- a/src/control.c
+++ b/src/control.c
@@ -171,6 +171,7 @@ extern uint8_t player_control_by_id(int action)
     if (   try_cmd_0args('i', action, "wait", player_wait)
         || try_cmd_0args('i', action, "drop", player_drop)
         || try_cmd_0args('i', action, "pick", player_pick)
+        || try_cmd_0args('i', action, "use", player_use)
         || try_cmd_1args('i', action, "player_u", move_player, 'N')
         || try_cmd_1args('i', action, "player_d", move_player, 'S')
         || try_cmd_1args('i', action, "player_r", move_player, 'E')
diff --git a/src/main.c b/src/main.c
index b27cf5d..88d90d2 100644
--- a/src/main.c
+++ b/src/main.c
@@ -180,7 +180,8 @@ int main(int argc, char *argv[])
                 {
                     break;
                 }
-                if (is_command_id_shortdsc(action, "drop"))
+                if (   is_command_id_shortdsc(action, "drop")
+                    || is_command_id_shortdsc(action, "use"))
                 {
                     world.inventory_select = getc(file);
                 }
@@ -203,7 +204,8 @@ int main(int argc, char *argv[])
                 action = getc(file);
                 if (EOF != action)
                 {
-                    if (is_command_id_shortdsc(action, "drop"))
+                    if (   is_command_id_shortdsc(action, "drop")
+                        || is_command_id_shortdsc(action, "use"))
                     {
                         world.inventory_select = getc(file);
                     }
diff --git a/src/map_object_actions.c b/src/map_object_actions.c
index 9875997..9d1721e 100644
--- a/src/map_object_actions.c
+++ b/src/map_object_actions.c
@@ -206,3 +206,47 @@ extern void player_pick()
     }
     turn_over(get_command_id("pick"));
 }
+
+
+
+extern void player_use()
+{
+    struct MapObj * player = get_player();
+    if (NULL == player->owns)
+    {
+        update_log("\nYou try to use an object, but you own none.");
+        world.old_inventory_select = 0;
+    }
+    else
+    {
+        uint8_t i = 0;
+        struct MapObj * selected = player->owns;
+        for (; i != world.inventory_select; i++, selected = selected->next);
+        struct MapObjDef * mod = get_map_object_def(selected->type);
+        if (!strcmp("MAGIC MEAT", mod->name))
+        {
+            struct MapObj * next = selected->next;
+            free(selected);
+            if (0 < world.inventory_select)
+            {
+                world.old_inventory_select = world.inventory_select;
+                world.inventory_select--;
+                for (i = 0, selected = player->owns;
+                     i != world.inventory_select;
+                     i++, selected = selected->next);
+                selected->next = next;
+            }
+            else
+            {
+                player->owns = next;
+            }
+            player->lifepoints++;
+            update_log("\nYou consume MAGIC MEAT.");
+            }
+        else
+        {
+            update_log("\nYou try to use this object, but fail.");
+        }
+    }
+    turn_over(get_command_id("use"));
+}
diff --git a/src/map_object_actions.h b/src/map_object_actions.h
index 8e0af47..7cc9843 100644
--- a/src/map_object_actions.h
+++ b/src/map_object_actions.h
@@ -41,6 +41,9 @@ extern void player_drop();
 /* Make player pick up map object from ground. */
 extern void player_pick();
 
+/* Make player use object indexed by world.inventory_select. */
+extern void player_use();
+
 
 
 #endif
diff --git a/src/misc.c b/src/misc.c
index 9aa609d..48ced07 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -222,7 +222,8 @@ extern void turn_over(char action)
         }
         try_fclose(file_old, f_name);
         exit_err(write_uint8(action, file_new), err_write);
-        if (is_command_id_shortdsc(action, "drop"))
+        if (   is_command_id_shortdsc(action, "drop")
+            || is_command_id_shortdsc(action, "use"))
         {
             uint8_t inventory_select = world.old_inventory_select;
             exit_err(write_uint8(inventory_select, file_new), err_write);