Blob


1 #include <stdio.h>
2 #include <string.h>
4 #include "adventure.h"
6 size_t
7 list_objs_at_loc(struct object *location)
8 {
9 size_t count = 0;
10 struct object *obj;
12 foreach_obj (obj) {
13 if (obj != player && obj->location == location) {
14 if (count++ == 0)
15 printf("%s:\n", location->contents);
16 printf("%s\n", obj->description);
17 }
18 }
20 return count;
21 }
23 struct object *
24 person_here(void)
25 {
26 struct object *obj;
28 foreach_obj (obj) {
29 if (distance_to(obj) == dist_here && obj->health > 0)
30 return obj;
31 }
33 return NULL;
34 }
36 struct object *
37 get_passage_to(struct object *target)
38 {
39 struct object *obj;
41 foreach_obj (obj) {
42 if (obj->location == player->location
43 && obj->prospect == target)
44 return obj;
45 }
47 return NULL;
48 }
50 enum distance
51 distance_to(struct object *obj)
52 {
53 return !valid_obj(obj) ? dist_unknown_obj
54 : obj == player
55 ? dist_player
56 : obj == player->location ? dist_location
57 : obj->location == player
58 ? dist_held
59 : obj->location == player->location
60 ? dist_here
61 : get_passage_to(obj) != NULL
62 ? dist_overthere
63 : !valid_obj(
64 obj->location)
65 ? dist_not_here
66 : obj->location->location
67 == player
68 ? dist_held_contained
69 : obj->location->location
70 == player->location
71 ? dist_here_contained
72 : dist_not_here;
73 }
75 void
76 move_player(struct object *passage)
77 {
78 printf("%s\n", passage->text_go);
79 if (passage->destination != NULL) {
80 player->location = passage->destination;
81 printf("\n");
82 exec_look_around();
83 }
84 }
86 int
87 weight_of_contents(struct object *container)
88 {
89 int sum = 0;
90 struct object *obj;
92 foreach_obj (obj) {
93 if (obj->location == container)
94 sum += obj->weight;
95 }
96 return sum;
97 }
99 int
100 object_within_reach(const char *verb, struct param *par)
102 int ok = 0;
104 enum distance dist = par->distance;
106 if (dist > dist_not_here)
107 printf("I don't understand what you want to %s.\n", verb);
108 else if (dist == dist_not_here)
109 printf("You don't see any %s here.\n", par->tag);
110 else if (dist >= dist_here_contained)
111 printf("That is out of reach.\n");
112 else if (par->count > 1)
113 printf("Multiple choices to %s; be more specific.\n", verb);
114 else
115 ok = 1;
117 return ok;