static bool Lua_Scenery_Valid(int32 index) { if (index < 0 || index >= MAXIMUM_OBJECTS_PER_MAP) return false; object_data *object = GetMemberWithBounds(objects, index, MAXIMUM_OBJECTS_PER_MAP); if (SLOT_IS_USED(object)) { if (GET_OBJECT_OWNER(object) == _object_is_scenery) return true; else if (GET_OBJECT_OWNER(object) == _object_is_normal) { // check to make sure it's not a player's legs or torso for (int player_index = 0; player_index < dynamic_world->player_count; player_index++) { player_data *player = get_player_data(player_index); monster_data *monster = get_monster_data(player->monster_index); if (monster->object_index == index) return false; else { object_data *object = get_object_data(monster->object_index); if (object->parasitic_object == index) return false; } } return true; } } return false; }
// LP addition: animator void animate_items() { object_data *object; ix object_index; for (object_index= 0, object= objects; object_index < MAXIMUM_OBJECTS_PER_MAP; ++object_index, ++object) { if (SLOT_IS_USED(object) && GET_OBJECT_OWNER(object)==_object_is_item && !OBJECT_IS_INVISIBLE(object)) { auto type = object->permutation; if (get_item_kind(type) != NONE) { item_definition *ItemDef = get_item_definition(type); // LP change: added idiot-proofing if (!ItemDef) continue; shape_descriptor shape = ItemDef->base_shape; shape_animation_data *animation= get_shape_animation_data(shape); if (!animation) continue; // Randomize if non-animated; do only once if (object->facing >= 0) { if (randomize_object_sequence(object_index,shape)) { object->facing = NONE; } } // Now the animation if (object->facing >= 0) animate_object(object_index); } } } }
bool Lua_Item_Valid(int32 index) { if (index < 0 || index >= MAXIMUM_OBJECTS_PER_MAP) return false; object_data *object = GetMemberWithBounds(objects, index, MAXIMUM_OBJECTS_PER_MAP); return (SLOT_IS_USED(object) && GET_OBJECT_OWNER(object) == _object_is_item); }
static int Lua_Scenery_Get_Damaged(lua_State *L) { object_data *object = get_object_data(Lua_Scenery::Index(L, 1)); // if it made it this far (past valid() check), // it's either scenery or normal lua_pushboolean(L, GET_OBJECT_OWNER(object) == _object_is_normal); return 1; }
static void m2_swipe_nearby_items(short player_index) { object_data *object; object_data *player_object; player_data *player= get_player_data(player_index); short next_object; polygon_data *polygon; short *neighbor_indexes; short i; player_object= get_object_data(get_monster_data(player->monster_index)->object_index); polygon= get_polygon_data(player_object->polygon); neighbor_indexes= get_map_indexes(polygon->first_neighbor_index, polygon->neighbor_count); // Skip this step if neighbor indexes were not found if (!neighbor_indexes) return; for (i=0;i<polygon->neighbor_count;++i) { polygon_data *neighboring_polygon= get_polygon_data(*neighbor_indexes++); if (POLYGON_IS_DETACHED(neighboring_polygon)) continue; next_object= neighboring_polygon->first_object; while(next_object != NONE) { object= get_object_data(next_object); if (GET_OBJECT_OWNER(object)==_object_is_item && !OBJECT_IS_INVISIBLE(object)) { if (guess_distance2d((world_point2d *) &player->location, (world_point2d *) &object->location)<=MAXIMUM_ARM_REACH) { world_distance radius, height; get_monster_dimensions(player->monster_index, &radius, &height); if (object->location.z >= player->location.z - MAXIMUM_ARM_REACH && object->location.z <= player->location.z + height && test_item_retrieval(player_object->polygon, &player_object->location, &object->location)) { if(get_item(player_index, next_object)) { /* Start the search again.. */ next_object= neighboring_polygon->first_object; continue; } } } } next_object= object->next_object; } } }
static bool get_item(short player_index, short object_index) { object_data *object = get_object_data(object_index); bool success; assert(GET_OBJECT_OWNER(object)==_object_is_item); success = try_and_add_player_item(player_index, object->permutation); if (success) { /* remove it */ remove_map_object(object_index); } return success; }
bool unretrieved_items_on_map() { bool found_item = false; object_data *object; short object_index; for (object_index= 0, object= objects; object_index<MAXIMUM_OBJECTS_PER_MAP; ++object_index, ++object) { if (SLOT_IS_USED(object) && GET_OBJECT_OWNER(object)==_object_is_item) { if (get_item_kind(object->permutation)==_item) { found_item= true; break; } } } return found_item; }
void trigger_nearby_items(short polygon_index) { polygon_index = flood_map(polygon_index, INT32_MAX, item_trigger_cost_function, _breadth_first, nullptr); while(polygon_index != NONE) { object_data *object; for(auto object_index = get_polygon_data(polygon_index)->first_object; object_index != NONE; object_index = object->next_object) { object = get_object_data(object_index); switch (GET_OBJECT_OWNER(object)) { case _object_is_item: if (OBJECT_IS_INVISIBLE(object) && object->permutation!=NONE) { teleport_object_in(object_index); } break; } } polygon_index= flood_map(NONE, INT32_MAX, item_trigger_cost_function, _breadth_first, nullptr); } }
static void a1_swipe_nearby_items(short player_index) { object_data *object; object_data *player_object; player_data *player = get_player_data(player_index); short next_object; polygon_data *polygon; short *neighbor_indexes; short i; player_object = get_object_data(get_monster_data(player->monster_index)->object_index); polygon= get_polygon_data(player_object->polygon); neighbor_indexes= get_map_indexes(polygon->first_neighbor_index, polygon->neighbor_count); // Skip this step if neighbor indexes were not found if (!neighbor_indexes) return; for (i=0;i<polygon->neighbor_count;++i) { struct polygon_data *neighboring_polygon= get_polygon_data(*neighbor_indexes++); /* LP change: since precalculate_map_indexes() and its associated routine intersecting_flood_proc() appear to have some bugs in them, I will instead search the neighbors of each indexed polygon. Starting the search from -1 is a kludge designed to include a search for the current polygon. */ polygon_data *source_polygon = neighboring_polygon; for (int ngbr_indx = -1; ngbr_indx<source_polygon->vertex_count; ngbr_indx++) { if (ngbr_indx >= 0) { // Be sure to check on whether there is a valid polygon on the other side auto adjacent_index = source_polygon->adjacent_polygon_indexes[ngbr_indx]; if (adjacent_index == NONE) continue; neighboring_polygon = get_polygon_data(adjacent_index); } else neighboring_polygon = source_polygon; if (!POLYGON_IS_DETACHED(neighboring_polygon)) { next_object= neighboring_polygon->first_object; while(next_object != NONE) { object= get_object_data(next_object); if (GET_OBJECT_OWNER(object)==_object_is_item && !OBJECT_IS_INVISIBLE(object)) { if (guess_distance2d((world_point2d *) &player->location, (world_point2d *) &object->location)<=MAXIMUM_ARM_REACH) { world_distance radius, height; get_monster_dimensions(player->monster_index, &radius, &height); if (object->location.z >= player->location.z - MAXIMUM_ARM_REACH && object->location.z <= player->location.z + height && test_item_retrieval(player_object->polygon, &player_object->location, &object->location)) { if(get_item(player_index, next_object)) { /* Start the search again.. */ next_object= neighboring_polygon->first_object; continue; } } } } next_object= object->next_object; } } // LP addition: end of that kludgy search loop } } }