Add a way to remove items from existence
This commit is contained in:
		
							parent
							
								
									eb43986876
								
							
						
					
					
						commit
						5ceb0eae5d
					
				| @ -8,15 +8,32 @@ EAST | * | 1 | You can't go east from here. | | |||||||
| WEST | * | 1 | You can't go west from here. | | WEST | * | 1 | You can't go west from here. | | ||||||
| NORTH | IN(FIRST_ROOM) | 10 | You head through the door. | GOTO(SECOND_ROOM) | 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) | 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. | | 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       | *                                      | 1    | You don't see anything to pull | | ||||||
| PULL       | IN(SECOND_ROOM)                         | 10   | What do you want 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)                         | 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.    | | 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(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(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? | | TAKE TORCH | * | 100 | What torch? | | ||||||
| DROP 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(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. | | ||||||
|  | |||||||
| @ -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. | 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. | 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. | ||||||
|  | |||||||
| @ -1,3 +1,4 @@ | |||||||
| FIRST_ROOM | FIRST_ROOM | ||||||
| SECOND_ROOM | SECOND_ROOM | ||||||
| LAST_ROOM | FIRE_ROOM | ||||||
|  | DARK_ROOM | ||||||
|  | |||||||
| @ -14,3 +14,7 @@ FLASK|FLASK,BOTTLE,JAR | |||||||
| TORCH|TORCH | TORCH|TORCH | ||||||
| TAKE|TAKE,PICKUP,GET | TAKE|TAKE,PICKUP,GET | ||||||
| DROP|DROP | DROP|DROP | ||||||
|  | LIGHT|LIGHT | ||||||
|  | TOUCH|TOUCH,FEEL | ||||||
|  | FIRE|FIRE,FLAMES,FLAME | ||||||
|  | PORTCULLIS|PORTCULLIS | ||||||
|  | |||||||
| @ -40,6 +40,9 @@ void cause_effect(Game *g, Effect *e) { | |||||||
|   case EFFECT_DROP_ITEM: |   case EFFECT_DROP_ITEM: | ||||||
|     drop_item(g, e->argument); |     drop_item(g, e->argument); | ||||||
|     break; |     break; | ||||||
|  |   case EFFECT_DESTROY_ITEM: | ||||||
|  |     destroy_item(g, e->argument); | ||||||
|  |     break; | ||||||
|   case EFFECT_CHECK_INVENTORY: |   case EFFECT_CHECK_INVENTORY: | ||||||
|     check_inventory(g); |     check_inventory(g); | ||||||
|     break; |     break; | ||||||
| @ -74,6 +77,8 @@ Effect *create_effect(Game *g, const char *string) { | |||||||
|       e->type = EFFECT_TAKE_ITEM; |       e->type = EFFECT_TAKE_ITEM; | ||||||
|     } else if (strcmp(token, "DROP") == 0) { |     } else if (strcmp(token, "DROP") == 0) { | ||||||
|       e->type = EFFECT_DROP_ITEM; |       e->type = EFFECT_DROP_ITEM; | ||||||
|  |     } else if (strcmp(token, "DESTROY") == 0) { | ||||||
|  |       e->type = EFFECT_DESTROY_ITEM; | ||||||
|     } else if (strcmp(token, "CHECK_INVENTORY") == 0) { |     } else if (strcmp(token, "CHECK_INVENTORY") == 0) { | ||||||
|       e->type = EFFECT_CHECK_INVENTORY; |       e->type = EFFECT_CHECK_INVENTORY; | ||||||
|     } |     } | ||||||
| @ -121,6 +126,9 @@ void print_effect(Effect *e) { | |||||||
|   case EFFECT_DROP_ITEM: |   case EFFECT_DROP_ITEM: | ||||||
|     printf("DROP(%s)", e->argument); |     printf("DROP(%s)", e->argument); | ||||||
|     break; |     break; | ||||||
|  |   case EFFECT_DESTROY_ITEM: | ||||||
|  |     printf("DESTROY(%s)", e->argument); | ||||||
|  |     break; | ||||||
|   case EFFECT_CHECK_INVENTORY: |   case EFFECT_CHECK_INVENTORY: | ||||||
|     printf("CHECK_INVENTORY()"); |     printf("CHECK_INVENTORY()"); | ||||||
|     break; |     break; | ||||||
|  | |||||||
| @ -14,6 +14,7 @@ typedef enum EffectType { | |||||||
|   EFFECT_LOOK_ROOM, |   EFFECT_LOOK_ROOM, | ||||||
|   EFFECT_TAKE_ITEM, |   EFFECT_TAKE_ITEM, | ||||||
|   EFFECT_DROP_ITEM, |   EFFECT_DROP_ITEM, | ||||||
|  |   EFFECT_DESTROY_ITEM, | ||||||
|   EFFECT_CHECK_INVENTORY, |   EFFECT_CHECK_INVENTORY, | ||||||
| } EffectType; | } EffectType; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -80,6 +80,12 @@ void drop_item(Game *g, char *item_name) { | |||||||
|   item->in_inventory = false; |   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) { | void check_inventory(Game *g) { | ||||||
|   bool empty = true; |   bool empty = true; | ||||||
|   for (int i = 0; i < g->items->count; i++) { |   for (int i = 0; i < g->items->count; i++) { | ||||||
|  | |||||||
| @ -26,6 +26,7 @@ void log_items_in_room(Game *g, Room *r); | |||||||
| Item *find_item(Items *items, char *item_name); | Item *find_item(Items *items, char *item_name); | ||||||
| void take_item(Game *g, char *item_name); | void take_item(Game *g, char *item_name); | ||||||
| void drop_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); | void check_inventory(Game *g); | ||||||
| 
 | 
 | ||||||
| #endif | #endif | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user