#include #include #include "adventure.h" size_t list_objs_at_loc(struct object *location) { size_t count = 0; struct object *obj; foreach_obj (obj) { if (obj != player && obj->location == location) { if (count++ == 0) printf("%s:\n", location->contents); printf("%s\n", obj->description); } } return count; } struct object * person_here(void) { struct object *obj; foreach_obj (obj) { if (distance_to(obj) == dist_here && obj->health > 0) return obj; } return NULL; } struct object * get_passage_to(struct object *target) { struct object *obj; foreach_obj (obj) { if (obj->location == player->location && obj->prospect == target) return obj; } return NULL; } enum distance distance_to(struct object *obj) { return !valid_obj(obj) ? dist_unknown_obj : obj == player ? dist_player : obj == player->location ? dist_location : obj->location == player ? dist_held : obj->location == player->location ? dist_here : get_passage_to(obj) != NULL ? dist_overthere : !valid_obj( obj->location) ? dist_not_here : obj->location->location == player ? dist_held_contained : obj->location->location == player->location ? dist_here_contained : dist_not_here; } void move_player(struct object *passage) { printf("%s\n", passage->text_go); if (passage->destination != NULL) { player->location = passage->destination; printf("\n"); exec_look_around(); } } int weight_of_contents(struct object *container) { int sum = 0; struct object *obj; foreach_obj (obj) { if (obj->location == container) sum += obj->weight; } return sum; } int object_within_reach(const char *verb, struct param *par) { int ok = 0; enum distance dist = par->distance; if (dist > dist_not_here) printf("I don't understand what you want to %s.\n", verb); else if (dist == dist_not_here) printf("You don't see any %s here.\n", par->tag); else if (dist >= dist_here_contained) printf("That is out of reach.\n"); else if (par->count > 1) printf("Multiple choices to %s; be more specific.\n", verb); else ok = 1; return ok; }