void delete_monster_carried_object( int monster_index, int monster_index_for_switch, boolean unit_control_case, boolean switch_to_next_item) { struct monster_data *monster= get_monster_data(monster_index); assert(!(unit_control_case && switch_to_next_item)); if (monster->carrying_object_index!= NONE) { int new_held_index= NONE; boolean really_delete_object= TRUE; if (monster->held_object_count) { int i; // look for carried object in the inventory for (i=0; iheld_object_count; i++) { if (monster->held_object_indexes[i] == monster->carrying_object_index) { break; } } if (i < monster->held_object_count) // we found it { // remove the empty place in the list if (i < monster->held_object_count - 1) { memmove(monster->held_object_indexes + i, monster->held_object_indexes + i + 1, ((monster->held_object_count - i) - 1) * sizeof(short)); } else { monster->held_object_indexes[i] = NONE; } monster->held_object_count--; if (switch_to_next_item) { // choose new item to be held by unit if (i >= monster->held_object_count) { // if monster->held_object_count == 0, then i becomes NONE which is exactly what we want. i = monster->held_object_count - 1; } if (monster->held_object_count || get_game_play_version() > GAMEPLAY_VERSION_172) { new_held_index= i; } else { really_delete_object= FALSE; // leak the object, because this is what the code used to do! } } } } if(really_delete_object) { delete_object(monster->carrying_object_index); monster->carrying_object_index= new_held_index != NONE ? monster->held_object_indexes[i] : NONE; if(!unit_control_case) { monster->artifact_index= NONE; } } if (unit_control_case && monster->artifact_index != NONE || !unit_control_case && get_game_play_version() > GAMEPLAY_VERSION_130) { // if monster->carrying_object_index == NONE, switch_monster_artifact also sets monster->artifact_index to NONE. switch_monster_artifact(monster_index_for_switch); } } if(unit_control_case) { // this is almost certainly a NOP, unless monster->carrying_object_index== NONE && monster->artifact_index!= NONE is possible. monster->artifact_index= NONE; } monster->display_dirty_flags|= _monster_items_dirty_flag; if (monster->action_permutation==ARTIFACT_ATTACK_INDEX) { monster->action_permutation= NONE; } }