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 7f40f3f5 2020-04-03 op foreach_obj(obj)
14 cc9bbf61 2020-04-01 op if (obj != player && obj->location == location) {
15 cc9bbf61 2020-04-01 op if (count++ == 0)
16 cc9bbf61 2020-04-01 op printf("%s:\n", location->contents);
17 cc9bbf61 2020-04-01 op printf("%s\n", obj->description);
24 cc9bbf61 2020-04-01 op struct object *
25 cc9bbf61 2020-04-01 op person_here(void)
27 cc9bbf61 2020-04-01 op struct object *obj;
29 7f40f3f5 2020-04-03 op foreach_obj(obj)
31 cc9bbf61 2020-04-01 op if (distance_to(obj) == dist_here && obj->health > 0)
38 cc9bbf61 2020-04-01 op struct object *
39 cc9bbf61 2020-04-01 op get_passage_to(struct object *target)
41 cc9bbf61 2020-04-01 op struct object *obj;
43 7f40f3f5 2020-04-03 op foreach_obj(obj)
45 7f40f3f5 2020-04-03 op if (obj->location == player->location
46 7f40f3f5 2020-04-03 op && obj->prospect == target)
54 cc9bbf61 2020-04-01 op distance_to(struct object *obj)
56 7f40f3f5 2020-04-03 op return !valid_obj(obj) ? dist_unknown_obj
57 7f40f3f5 2020-04-03 op : obj == player
59 7f40f3f5 2020-04-03 op : obj == player->location ? dist_location
60 7f40f3f5 2020-04-03 op : obj->location == player
62 7f40f3f5 2020-04-03 op : obj->location == player->location
64 7f40f3f5 2020-04-03 op : get_passage_to(obj) != NULL
65 7f40f3f5 2020-04-03 op ? dist_overthere
67 7f40f3f5 2020-04-03 op obj->location)
68 7f40f3f5 2020-04-03 op ? dist_not_here
69 7f40f3f5 2020-04-03 op : obj->location->location
71 7f40f3f5 2020-04-03 op ? dist_held_contained
72 7f40f3f5 2020-04-03 op : obj->location->location
73 7f40f3f5 2020-04-03 op == player->location
74 7f40f3f5 2020-04-03 op ? dist_here_contained
75 7f40f3f5 2020-04-03 op : dist_not_here;
79 cc9bbf61 2020-04-01 op move_player(struct object *passage)
81 cc9bbf61 2020-04-01 op printf("%s\n", passage->text_go);
82 cc9bbf61 2020-04-01 op if (passage->destination != NULL) {
83 cc9bbf61 2020-04-01 op player->location = passage->destination;
85 cc9bbf61 2020-04-01 op exec_look_around();
90 cc9bbf61 2020-04-01 op weight_of_contents(struct object *container)
93 cc9bbf61 2020-04-01 op struct object *obj;
95 7f40f3f5 2020-04-03 op foreach_obj(obj)
97 cc9bbf61 2020-04-01 op if (obj->location == container)
98 cc9bbf61 2020-04-01 op sum += obj->weight;
104 cc9bbf61 2020-04-01 op object_within_reach(const char *verb, struct param *par)
108 cc9bbf61 2020-04-01 op enum distance dist = par->distance;
110 cc9bbf61 2020-04-01 op if (dist > dist_not_here)
111 cc9bbf61 2020-04-01 op printf("I don't understand what you want to %s.\n", verb);
112 cc9bbf61 2020-04-01 op else if (dist == dist_not_here)
113 cc9bbf61 2020-04-01 op printf("You don't see any %s here.\n", par->tag);
114 cc9bbf61 2020-04-01 op else if (dist >= dist_here_contained)
115 cc9bbf61 2020-04-01 op printf("That is out of reach.\n");
116 cc9bbf61 2020-04-01 op else if (par->count > 1)
117 cc9bbf61 2020-04-01 op printf("Multiple choices to %s; be more specific.\n", verb);