Skip to content

Commit

Permalink
Prevent loop of "fixed fail to feed - found the gun failed to feed"
Browse files Browse the repository at this point in the history
  • Loading branch information
GuardianDll committed Aug 17, 2024
1 parent 0510a46 commit e714e29
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/activity_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,8 @@ bool aim_activity_actor::check_gun_ability_to_shoot( Character &who, item &it )
_( "Your %s has some mechanical malfunction. You tried to quickly fix it, and it works now!" ),
it.tname() );
it.faults.erase( faults::random_of_type_item_has( it, gun_mechanical_simple ) );
islot_gun &firing = *it.type->gun;
firing.u_know_round_in_chamber = true;
} else {
who.add_msg_if_player( m_warning,
_( "Your %s has some mechanical malfunction. You tried to quickly fix it, but failed!" ),
Expand Down
5 changes: 5 additions & 0 deletions src/itype.h
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,11 @@ struct islot_gun : common_ranged_data {
*/
double gun_jam_mult = 1;

/**
* character spend time to repair failure to feed, so if true, it is guarantee the round is in the chamber
*/
bool u_know_round_in_chamber = false;

std::map<ammotype, std::set<itype_id>> cached_ammos;

/**
Expand Down
8 changes: 7 additions & 1 deletion src/ranged.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ bool Character::handle_gun_damage( item &it )
return false;

// Chance for the weapon to suffer a failure, caused by the magazine size, quality, or condition
} else if( x_in_y( jam_chance, 1 ) &&
} else if( x_in_y( jam_chance, 1 ) && !firing.u_know_round_in_chamber &&
faults::get_random_of_type_item_can_have( it, gun_mechanical_simple ) != fault_id::NULL_ID() ) {
add_msg_player_or_npc( _( "Your %s didn't load into the chamber!" ),
_( "<npcname>'s %s didn't load into the chamber!" ),
Expand Down Expand Up @@ -853,6 +853,12 @@ bool Character::handle_gun_damage( item &it )
// Don't increment until after the message
it.inc_damage();
}

if( firing.u_know_round_in_chamber ) {
islot_gun gun = *it.type->gun;
gun.u_know_round_in_chamber = false;
}

return true;
}

Expand Down

0 comments on commit e714e29

Please sign in to comment.