/** * Update the player's knowledge of the objects on a grid in the current level */ void square_know_pile(struct chunk *c, int y, int x) { struct object *obj; if (c != cave) return; object_lists_check_integrity(c, player->cave); /* Know every item on this grid, greater knowledge for the player grid */ for (obj = square_object(c, y, x); obj; obj = obj->next) { object_see(player, obj); if ((y == player->py) && (x == player->px)) { object_touch(player, obj); } } /* Remove known location of anything not on this grid */ obj = square_object(player->cave, y, x); while (obj) { struct object *next = obj->next; assert(c->objects[obj->oidx]); if (!square_holds_object(c, y, x, c->objects[obj->oidx])) { struct object *original = c->objects[obj->oidx]; square_excise_object(player->cave, y, x, obj); obj->iy = 0; obj->ix = 0; /* Delete objects which no longer exist anywhere */ if (obj->notice & OBJ_NOTICE_IMAGINED) { delist_object(player->cave, obj); object_delete(&obj); original->known = NULL; delist_object(c, original); object_delete(&original); } } obj = next; } }
/** * Update the player's knowledge of the objects on a grid in the current level */ void floor_pile_know(struct chunk *c, int y, int x) { struct object *obj; if (c != cave) return; object_lists_check_integrity(); /* Know every item on this grid */ for (obj = square_object(c, y, x); obj; obj = obj->next) { struct object *known_obj = cave_k->objects[obj->oidx]; /* Make new known objects, fully know sensed ones, relocate old ones */ if (known_obj == NULL) { /* Make and/or list the new object */ struct object *new_obj; /* Check whether we need to make a new one or list the old one */ if (obj->known) { new_obj = obj->known; } else { new_obj = object_new(); obj->known = new_obj; object_set_base_known(obj); } cave_k->objects[obj->oidx] = new_obj; new_obj->oidx = obj->oidx; /* Attach it to the current floor pile */ new_obj->iy = y; new_obj->ix = x; new_obj->number = obj->number; if (!square_holds_object(cave_k, y, x, new_obj)) pile_insert_end(&cave_k->squares[y][x].obj, new_obj); } else if (known_obj->kind != obj->kind) { int iy = known_obj->iy; int ix = known_obj->ix; /* Make sure knowledge is correct */ assert(known_obj == obj->known); /* Detach from any old pile (possibly the correct one) */ if (iy && ix && square_holds_object(cave_k, iy, ix, known_obj)) square_excise_object(cave_k, iy, ix, known_obj); /* Copy over actual details */ object_set_base_known(obj); /* Attach it to the current floor pile */ known_obj->iy = y; known_obj->ix = x; known_obj->held_m_idx = 0; if (!square_holds_object(cave_k, y, x, known_obj)) pile_insert_end(&cave_k->squares[y][x].obj, known_obj); } else if (!square_holds_object(cave_k, y, x, known_obj)) { int iy = known_obj->iy; int ix = known_obj->ix; /* Make sure knowledge is correct */ assert(known_obj == obj->known); known_obj->number = obj->number; /* Detach from any old pile */ if (iy && ix && square_holds_object(cave_k, iy, ix, known_obj)) square_excise_object(cave_k, iy, ix, known_obj); /* Attach it to the current floor pile */ known_obj->iy = y; known_obj->ix = x; known_obj->held_m_idx = 0; pile_insert_end(&cave_k->squares[y][x].obj, known_obj); } } /* Remove known location of anything not on this grid */ obj = square_object(cave_k, y, x); while (obj) { struct object *next = obj->next; assert(c->objects[obj->oidx]); if (!square_holds_object(c, y, x, c->objects[obj->oidx])) { struct object *original = c->objects[obj->oidx]; square_excise_object(cave_k, y, x, obj); obj->iy = 0; obj->ix = 0; /* Delete objects which no longer exist anywhere */ if (obj->notice & OBJ_NOTICE_IMAGINED) { delist_object(cave_k, obj); object_delete(&obj); original->known = NULL; delist_object(c, original); object_delete(&original); } } obj = next; } }