Skip to content

Commit

Permalink
Searchlights: don't drop items used for settings (#63429)
Browse files Browse the repository at this point in the history
Searchlights store their settings on a processor board item, so their
"beams" can have persistent behavior between turns. They do this using
item vars, but these item vars linger after their death, causing the
items not to stack.
Simple solution: Just don't drop these settings items.
Also, erase these item vars on any existing items, so that they can now
stack.

This does mean that searchlights are no longer guaranteed to drop
multiple processor items. I think that this is acceptable, but it will
mean they drop fewer items as, unlike other robots, they do not drop a
disassemblable corpse, only a random item from an itemgroup.
  • Loading branch information
ehughsbaird authored Feb 5, 2023
1 parent 7505987 commit 83ed3f6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/monattack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3366,6 +3366,9 @@ bool mattack::check_money_left( monster *z )

if( !z->inv.empty() ) {
for( const item &it : z->inv ) {
if( it.has_var( "DESTROY_ITEM_ON_MON_DEATH" ) ) {
continue;
}
get_map().add_item_or_charges( z->pos(), it );
}
z->inv.clear();
Expand Down Expand Up @@ -3809,6 +3812,7 @@ bool mattack::searchlight( monster *z )

settings.set_var( "SL_SPOT_X", 0 );
settings.set_var( "SL_SPOT_Y", 0 );
settings.set_var( "DESTROY_ITEM_ON_MON_DEATH", "TRUE" );

z->add_item( settings );
}
Expand Down
3 changes: 3 additions & 0 deletions src/monexamine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ void dump_items( monster &z )
Character &player_character = get_player_character();
map &here = get_map();
for( item &it : z.inv ) {
if( it.has_var( "DESTROY_ITEM_ON_MON_DEATH" ) ) {
continue;
}
here.add_item_or_charges( player_character.pos(), it );
}
z.inv.clear();
Expand Down
3 changes: 3 additions & 0 deletions src/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2671,6 +2671,9 @@ void monster::die( Creature *nkiller )
}
if( death_drops && !is_hallucination() ) {
for( const item &it : inv ) {
if( it.has_var( "DESTROY_ITEM_ON_MON_DEATH" ) ) {
continue;
}
if( corpse ) {
corpse->force_insert_item( it, item_pocket::pocket_type::CONTAINER );
} else {
Expand Down
13 changes: 10 additions & 3 deletions src/savegame_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3058,9 +3058,16 @@ void item::io( Archive &archive )
}
}

// Remove stored translated gerund in favor of storing the inscription tool type
item_vars.erase( "item_label_type" );
item_vars.erase( "item_note_type" );
static const std::set<std::string> removed_item_vars = {
// Searchlight monster setting vars
"SL_PREFER_UP", "SL_PREFER_DOWN", "SL_PREFER_RIGHT", "SL_PREFER_LEFT", "SL_SPOT_X", "SL_SPOT_Y", "SL_POWER", "SL_DIR",
// Remove stored translated gerund in favor of storing the inscription tool type
"item_label_type", "item_note_type"
};

for( const std::string &var : removed_item_vars ) {
item_vars.erase( var );
}

current_phase = static_cast<phase_id>( cur_phase );
// override phase if frozen, needed for legacy save
Expand Down

0 comments on commit 83ed3f6

Please sign in to comment.