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 cc9bbf61 2020-04-01 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 cc9bbf61 2020-04-01 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 cc9bbf61 2020-04-01 op foreach_obj (obj) {
42 cc9bbf61 2020-04-01 op if (obj->location == player->location &&
43 cc9bbf61 2020-04-01 op obj->prospect == target)
51 cc9bbf61 2020-04-01 op distance_to(struct object *obj)
54 cc9bbf61 2020-04-01 op !valid_obj(obj) ? dist_unknown_obj :
55 cc9bbf61 2020-04-01 op obj == player ? dist_player :
56 cc9bbf61 2020-04-01 op obj == player->location ? dist_location :
57 cc9bbf61 2020-04-01 op obj->location == player ? dist_held :
58 cc9bbf61 2020-04-01 op obj->location == player->location ? dist_here :
59 cc9bbf61 2020-04-01 op get_passage_to(obj) != NULL ? dist_overthere :
60 cc9bbf61 2020-04-01 op !valid_obj(obj->location) ? dist_not_here :
61 cc9bbf61 2020-04-01 op obj->location->location == player ? dist_held_contained :
62 cc9bbf61 2020-04-01 op obj->location->location == player->location ? dist_here_contained :
63 cc9bbf61 2020-04-01 op dist_not_here;
67 cc9bbf61 2020-04-01 op move_player(struct object *passage)
69 cc9bbf61 2020-04-01 op printf("%s\n", passage->text_go);
70 cc9bbf61 2020-04-01 op if (passage->destination != NULL) {
71 cc9bbf61 2020-04-01 op player->location = passage->destination;
73 cc9bbf61 2020-04-01 op exec_look_around();
78 cc9bbf61 2020-04-01 op weight_of_contents(struct object *container)
81 cc9bbf61 2020-04-01 op struct object *obj;
83 cc9bbf61 2020-04-01 op foreach_obj (obj) {
84 cc9bbf61 2020-04-01 op if (obj->location == container)
85 cc9bbf61 2020-04-01 op sum += obj->weight;
91 cc9bbf61 2020-04-01 op object_within_reach(const char *verb, struct param *par)
95 cc9bbf61 2020-04-01 op enum distance dist = par->distance;
97 cc9bbf61 2020-04-01 op if (dist > dist_not_here)
98 cc9bbf61 2020-04-01 op printf("I don't understand what you want to %s.\n", verb);
99 cc9bbf61 2020-04-01 op else if (dist == dist_not_here)
100 cc9bbf61 2020-04-01 op printf("You don't see any %s here.\n", par->tag);
101 cc9bbf61 2020-04-01 op else if (dist >= dist_here_contained)
102 cc9bbf61 2020-04-01 op printf("That is out of reach.\n");
103 cc9bbf61 2020-04-01 op else if (par->count > 1)
104 cc9bbf61 2020-04-01 op printf("Multiple choices to %s; be more specific.\n", verb);