1 cc9bbf61 2020-04-01 op #include <stdio.h>
2 cc9bbf61 2020-04-01 op #include <string.h>
4 cc9bbf61 2020-04-01 op #include "adventure.h"
7 cc9bbf61 2020-04-01 op list_objs_at_loc(struct object *location)
9 cc9bbf61 2020-04-01 op size_t count = 0;
10 cc9bbf61 2020-04-01 op struct object *obj;
12 8852ffaf 2020-04-03 op foreach_obj (obj) {
13 cc9bbf61 2020-04-01 op if (obj != player && obj->location == location) {
14 cc9bbf61 2020-04-01 op if (count++ == 0)
15 cc9bbf61 2020-04-01 op printf("%s:\n", location->contents);
16 cc9bbf61 2020-04-01 op printf("%s\n", obj->description);
23 cc9bbf61 2020-04-01 op struct object *
24 cc9bbf61 2020-04-01 op person_here(void)
26 cc9bbf61 2020-04-01 op struct object *obj;
28 8852ffaf 2020-04-03 op foreach_obj (obj) {
29 cc9bbf61 2020-04-01 op if (distance_to(obj) == dist_here && obj->health > 0)
36 cc9bbf61 2020-04-01 op struct object *
37 cc9bbf61 2020-04-01 op get_passage_to(struct object *target)
39 cc9bbf61 2020-04-01 op struct object *obj;
41 8852ffaf 2020-04-03 op foreach_obj (obj) {
42 7f40f3f5 2020-04-03 op if (obj->location == player->location
43 7f40f3f5 2020-04-03 op && obj->prospect == target)
51 cc9bbf61 2020-04-01 op distance_to(struct object *obj)
53 7f40f3f5 2020-04-03 op return !valid_obj(obj) ? dist_unknown_obj
54 7f40f3f5 2020-04-03 op : obj == player
56 7f40f3f5 2020-04-03 op : obj == player->location ? dist_location
57 7f40f3f5 2020-04-03 op : obj->location == player
59 7f40f3f5 2020-04-03 op : obj->location == player->location
61 7f40f3f5 2020-04-03 op : get_passage_to(obj) != NULL
62 7f40f3f5 2020-04-03 op ? dist_overthere
64 7f40f3f5 2020-04-03 op obj->location)
65 7f40f3f5 2020-04-03 op ? dist_not_here
66 7f40f3f5 2020-04-03 op : obj->location->location
68 7f40f3f5 2020-04-03 op ? dist_held_contained
69 7f40f3f5 2020-04-03 op : obj->location->location
70 7f40f3f5 2020-04-03 op == player->location
71 7f40f3f5 2020-04-03 op ? dist_here_contained
72 7f40f3f5 2020-04-03 op : dist_not_here;
76 cc9bbf61 2020-04-01 op move_player(struct object *passage)
78 cc9bbf61 2020-04-01 op printf("%s\n", passage->text_go);
79 cc9bbf61 2020-04-01 op if (passage->destination != NULL) {
80 cc9bbf61 2020-04-01 op player->location = passage->destination;
82 cc9bbf61 2020-04-01 op exec_look_around();
87 cc9bbf61 2020-04-01 op weight_of_contents(struct object *container)
90 cc9bbf61 2020-04-01 op struct object *obj;
92 8852ffaf 2020-04-03 op foreach_obj (obj) {
93 cc9bbf61 2020-04-01 op if (obj->location == container)
94 cc9bbf61 2020-04-01 op sum += obj->weight;
100 cc9bbf61 2020-04-01 op object_within_reach(const char *verb, struct param *par)
104 cc9bbf61 2020-04-01 op enum distance dist = par->distance;
106 cc9bbf61 2020-04-01 op if (dist > dist_not_here)
107 cc9bbf61 2020-04-01 op printf("I don't understand what you want to %s.\n", verb);
108 cc9bbf61 2020-04-01 op else if (dist == dist_not_here)
109 cc9bbf61 2020-04-01 op printf("You don't see any %s here.\n", par->tag);
110 cc9bbf61 2020-04-01 op else if (dist >= dist_here_contained)
111 cc9bbf61 2020-04-01 op printf("That is out of reach.\n");
112 cc9bbf61 2020-04-01 op else if (par->count > 1)
113 cc9bbf61 2020-04-01 op printf("Multiple choices to %s; be more specific.\n", verb);