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
54 !valid_obj(obj) ? dist_unknown_obj :
55 obj == player ? dist_player :
56 obj == player->location ? dist_location :
57 obj->location == player ? dist_held :
58 obj->location == player->location ? dist_here :
59 get_passage_to(obj) != NULL ? dist_overthere :
60 !valid_obj(obj->location) ? dist_not_here :
61 obj->location->location == player ? dist_held_contained :
62 obj->location->location == player->location ? dist_here_contained :
63 dist_not_here;
64 }
66 void
67 move_player(struct object *passage)
68 {
69 printf("%s\n", passage->text_go);
70 if (passage->destination != NULL) {
71 player->location = passage->destination;
72 printf("\n");
73 exec_look_around();
74 }
75 }
77 int
78 weight_of_contents(struct object *container)
79 {
80 int sum = 0;
81 struct object *obj;
83 foreach_obj (obj) {
84 if (obj->location == container)
85 sum += obj->weight;
86 }
87 return sum;
88 }
90 int
91 object_within_reach(const char *verb, struct param *par)
92 {
93 int ok = 0;
95 enum distance dist = par->distance;
97 if (dist > dist_not_here)
98 printf("I don't understand what you want to %s.\n", verb);
99 else if (dist == dist_not_here)
100 printf("You don't see any %s here.\n", par->tag);
101 else if (dist >= dist_here_contained)
102 printf("That is out of reach.\n");
103 else if (par->count > 1)
104 printf("Multiple choices to %s; be more specific.\n", verb);
105 else
106 ok = 1;
108 return ok;