From 5ceb0eae5db13e8aaa235ee6d84ab16b6a800e59 Mon Sep 17 00:00:00 2001
From: Bill Rossi <bassguitarbill@gmail.com>
Date: Thu, 23 Jan 2025 20:25:56 -0500
Subject: [PATCH] Add a way to remove items from existence

---
 01_text_adventure/data/actions.txt  | 21 +++++++++++++++++++--
 01_text_adventure/data/room_ins.txt |  5 +++--
 01_text_adventure/data/rooms.txt    |  3 ++-
 01_text_adventure/data/words.txt    |  4 ++++
 01_text_adventure/effect.c          |  8 ++++++++
 01_text_adventure/effect.h          |  1 +
 01_text_adventure/item.c            |  6 ++++++
 01_text_adventure/item.h            |  1 +
 8 files changed, 44 insertions(+), 5 deletions(-)

diff --git a/01_text_adventure/data/actions.txt b/01_text_adventure/data/actions.txt
index 74896af..0e83636 100644
--- a/01_text_adventure/data/actions.txt
+++ b/01_text_adventure/data/actions.txt
@@ -8,15 +8,32 @@ EAST | * | 1 | You can't go east from here. |
 WEST | * | 1 | You can't go west from here. |
 NORTH | IN(FIRST_ROOM) | 10 | You head through the door. | GOTO(SECOND_ROOM)
 SOUTH | IN(SECOND_ROOM) | 10 | You head back through the door. | GOTO(FIRST_ROOM)
-EAST | IN(FIRST_ROOM) & ENABLED(LEVER_PULLED) | 20 | You crouch under the portcullis and enter the room. | GOTO(LAST_ROOM)
+EAST | IN(FIRST_ROOM) & ENABLED(LEVER_PULLED) | 20 | You crouch under the portcullis and enter the room. | GOTO(FIRE_ROOM)
 EAST | IN(FIRST_ROOM) | 10 | There is a portcullis in the way. |
-WEST | IN(LAST_ROOM) | 10 | You crouch under the portcullis and return to the room. | GOTO(FIRST_ROOM)
+WEST | IN(FIRE_ROOM) | 10 | You crouch under the portcullis and return to the room. | GOTO(FIRST_ROOM)
+WEST | IN(FIRST_ROOM) | 10 | It's way too dark in there. You shouldn't go in without a light source. |
+WEST | IN(FIRST_ROOM) & HAS_ITEM(LIT_TORCH) | 100 | You cautiously enter the darkened room. | GOTO(DARK_ROOM)
+EAST | IN(DARK_ROOM) | 10 | You make your way out of the darkened room. | GOTO(FIRST_ROOM)
 PULL       | *                                      | 1    | You don't see anything to pull |
 PULL       | IN(SECOND_ROOM)                         | 10   | What do you want to pull? |
 PULL LEVER | IN(SECOND_ROOM)                         | 100  | You pull the lever and the sound of grinding machinery comes from the first room. | ENABLE(LEVER_PULLED)
 PULL LEVER | IN(SECOND_ROOM) & ENABLED(LEVER_PULLED) | 1000 | You already pulled it.    |
 TAKE TORCH | ITEM_HERE(UNLIT_TORCH) | 1000 | You pick up the torch | TAKE(UNLIT_TORCH)
+TAKE TORCH | ITEM_HERE(LIT_TORCH) | 1000 | You carefully pick up the torch | TAKE(LIT_TORCH)
 TAKE TORCH | HAS_ITEM(UNLIT_TORCH) | 1001 | You already have a torch |
+TAKE TORCH | HAS_ITEM(LIT_TORCH) | 1001 | You already have a torch |
 TAKE TORCH | * | 100 | What torch? |
 DROP TORCH | * | 100 | What torch? |
 DROP TORCH | HAS_ITEM(UNLIT_TORCH) | 1000 | You lay the torch carefully on the ground. | DROP(UNLIT_TORCH)
+DROP TORCH | HAS_ITEM(LIT_TORCH) | 1000 | You lay the torch carefully on the ground. | DROP(LIT_TORCH)
+LIGHT TORCH | HAS_ITEM(LIT_TORCH) | 1000 | The torch is already burning brightly. |
+LIGHT TORCH | * | 1 | What torch? |
+LIGHT TORCH | HAS_ITEM(UNLIT_TORCH) | 10 | You don't have any way to light that. |
+LIGHT TORCH | HAS_ITEM(UNLIT_TORCH) & IN(FIRE_ROOM) | 100 | You light the torch in the fire. It can illuminate a decent area. | TAKE(LIT_TORCH) & DESTROY(UNLIT_TORCH)
+TOUCH FIRE | * | 1 | Why? What fire? |
+TOUCH FIRE | HAS_ITEM(LIT_TORCH) | 10 | The torch singes your hand. Why would you do such a thing? |
+TOUCH FIRE | IN(FIRE_ROOM) | 100 | You burn your hand quite badly in the flames! Why would you do that? |
+LOOK PORTCULLIS | * | 1 | What portcullis? |
+LOOK PORTCULLIS | IN(FIRST_ROOM) | 10 | The portcullis is made of wide metal slabs. In the room behind it, a merry fire crackles. |
+LOOK PORTCULLIS | IN(FIRST_ROOM) & ENABLED(LEVER_PULLED) | 100 | The portcullis is mostly retracted into a slot in the ceiling in the doorway. |
+LOOK PORTCULLIS | IN(FIRE_ROOM) | 100 | The portcullis is mostly retracted into a slot in the ceiling in the doorway. |
diff --git a/01_text_adventure/data/room_ins.txt b/01_text_adventure/data/room_ins.txt
index 9ec1d02..f1f351d 100644
--- a/01_text_adventure/data/room_ins.txt
+++ b/01_text_adventure/data/room_ins.txt
@@ -1,4 +1,5 @@
-FIRST_ROOM  | *                     | 1  | You are in a plain room. A doorway is on the north wall, and a portcullis obstructs a doorway to the east. 
+FIRST_ROOM  | *                     | 1  | You are in a plain room. A doorway is on the north wall, and a portcullis obstructs a doorway to the east. A pitch-dark room is through a doorway to the west.
 FIRST_ROOM  | ENABLED(LEVER_PULLED) | 10 | You are in a plain room. A doorway is on the north wall, and the doorway once obstructed by the portcullis is to the east.
 SECOND_ROOM | *                     | 1 | This is a small room. It's painted blue. There's a doorway on the south wall, and a conspicuous lever in the middle of the floor.
-LAST_ROOM   | *                     | 1 | This room is in disrepair. A doorway is open to the west.
+FIRE_ROOM   | *                     | 1 | This room is in disrepair. A fire crackles merrily in a small fireplace. A doorway is open to the west.
+DARK_ROOM | * | 1 | This room is gloomy and very cold. There's no reason to be in here, but it's the last room in the game so far.
diff --git a/01_text_adventure/data/rooms.txt b/01_text_adventure/data/rooms.txt
index 55bac6b..074c3a1 100644
--- a/01_text_adventure/data/rooms.txt
+++ b/01_text_adventure/data/rooms.txt
@@ -1,3 +1,4 @@
 FIRST_ROOM
 SECOND_ROOM
-LAST_ROOM
+FIRE_ROOM
+DARK_ROOM
diff --git a/01_text_adventure/data/words.txt b/01_text_adventure/data/words.txt
index cebe125..d99e47e 100644
--- a/01_text_adventure/data/words.txt
+++ b/01_text_adventure/data/words.txt
@@ -14,3 +14,7 @@ FLASK|FLASK,BOTTLE,JAR
 TORCH|TORCH
 TAKE|TAKE,PICKUP,GET
 DROP|DROP
+LIGHT|LIGHT
+TOUCH|TOUCH,FEEL
+FIRE|FIRE,FLAMES,FLAME
+PORTCULLIS|PORTCULLIS
diff --git a/01_text_adventure/effect.c b/01_text_adventure/effect.c
index cc5af56..4f9fdfe 100644
--- a/01_text_adventure/effect.c
+++ b/01_text_adventure/effect.c
@@ -40,6 +40,9 @@ void cause_effect(Game *g, Effect *e) {
   case EFFECT_DROP_ITEM:
     drop_item(g, e->argument);
     break;
+  case EFFECT_DESTROY_ITEM:
+    destroy_item(g, e->argument);
+    break;
   case EFFECT_CHECK_INVENTORY:
     check_inventory(g);
     break;
@@ -74,6 +77,8 @@ Effect *create_effect(Game *g, const char *string) {
       e->type = EFFECT_TAKE_ITEM;
     } else if (strcmp(token, "DROP") == 0) {
       e->type = EFFECT_DROP_ITEM;
+    } else if (strcmp(token, "DESTROY") == 0) {
+      e->type = EFFECT_DESTROY_ITEM;
     } else if (strcmp(token, "CHECK_INVENTORY") == 0) {
       e->type = EFFECT_CHECK_INVENTORY;
     }
@@ -121,6 +126,9 @@ void print_effect(Effect *e) {
   case EFFECT_DROP_ITEM:
     printf("DROP(%s)", e->argument);
     break;
+  case EFFECT_DESTROY_ITEM:
+    printf("DESTROY(%s)", e->argument);
+    break;
   case EFFECT_CHECK_INVENTORY:
     printf("CHECK_INVENTORY()");
     break;
diff --git a/01_text_adventure/effect.h b/01_text_adventure/effect.h
index 8f769a2..9437612 100644
--- a/01_text_adventure/effect.h
+++ b/01_text_adventure/effect.h
@@ -14,6 +14,7 @@ typedef enum EffectType {
   EFFECT_LOOK_ROOM,
   EFFECT_TAKE_ITEM,
   EFFECT_DROP_ITEM,
+  EFFECT_DESTROY_ITEM,
   EFFECT_CHECK_INVENTORY,
 } EffectType;
 
diff --git a/01_text_adventure/item.c b/01_text_adventure/item.c
index 92fd582..479a4a7 100644
--- a/01_text_adventure/item.c
+++ b/01_text_adventure/item.c
@@ -80,6 +80,12 @@ void drop_item(Game *g, char *item_name) {
   item->in_inventory = false;
 }
 
+void destroy_item(Game *g, char *item_name) {
+  Item *item = find_item(g->items, item_name);
+  item->location = NULL;
+  item->in_inventory = false;
+}
+
 void check_inventory(Game *g) {
   bool empty = true;
   for (int i = 0; i < g->items->count; i++) {
diff --git a/01_text_adventure/item.h b/01_text_adventure/item.h
index bf4688b..27a0638 100644
--- a/01_text_adventure/item.h
+++ b/01_text_adventure/item.h
@@ -26,6 +26,7 @@ void log_items_in_room(Game *g, Room *r);
 Item *find_item(Items *items, char *item_name);
 void take_item(Game *g, char *item_name);
 void drop_item(Game *g, char *item_name);
+void destroy_item(Game *g, char *item_name);
 void check_inventory(Game *g);
 
 #endif