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 {
14 if (obj != player && obj->location == location) {
15 if (count++ == 0)
16 printf("%s:\n", location->contents);
17 printf("%s\n", obj->description);
18 }
19 }
21 return count;
22 }
24 struct object *
25 person_here(void)
26 {
27 struct object *obj;
29 foreach_obj(obj)
30 {
31 if (distance_to(obj) == dist_here && obj->health > 0)
32 return obj;
33 }
35 return NULL;
36 }
38 struct object *
39 get_passage_to(struct object *target)
40 {
41 struct object *obj;
43 foreach_obj(obj)
44 {
45 if (obj->location == player->location
46 && obj->prospect == target)
47 return obj;
48 }
50 return NULL;
51 }
53 enum distance
54 distance_to(struct object *obj)
55 {
56 return !valid_obj(obj) ? dist_unknown_obj
57 : obj == player
58 ? dist_player
59 : obj == player->location ? dist_location
60 : obj->location == player
61 ? dist_held
62 : obj->location == player->location
63 ? dist_here
64 : get_passage_to(obj) != NULL
65 ? dist_overthere
66 : !valid_obj(
67 obj->location)
68 ? dist_not_here
69 : obj->location->location
70 == player
71 ? dist_held_contained
72 : obj->location->location
73 == player->location
74 ? dist_here_contained
75 : dist_not_here;
76 }
78 void
79 move_player(struct object *passage)
80 {
81 printf("%s\n", passage->text_go);
82 if (passage->destination != NULL) {
83 player->location = passage->destination;
84 printf("\n");
85 exec_look_around();
86 }
87 }
89 int
90 weight_of_contents(struct object *container)
91 {
92 int sum = 0;
93 struct object *obj;
95 foreach_obj(obj)
96 {
97 if (obj->location == container)
98 sum += obj->weight;
99 }
100 return sum;
103 int
104 object_within_reach(const char *verb, struct param *par)
106 int ok = 0;
108 enum distance dist = par->distance;
110 if (dist > dist_not_here)
111 printf("I don't understand what you want to %s.\n", verb);
112 else if (dist == dist_not_here)
113 printf("You don't see any %s here.\n", par->tag);
114 else if (dist >= dist_here_contained)
115 printf("That is out of reach.\n");
116 else if (par->count > 1)
117 printf("Multiple choices to %s; be more specific.\n", verb);
118 else
119 ok = 1;
121 return ok;