Skip to content

Commit 40b6557

Browse files
More Gun Mod Upgrades (#54961)
1 parent fed22a0 commit 40b6557

File tree

5 files changed

+43
-5
lines changed

5 files changed

+43
-5
lines changed

src/item.cpp

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -575,8 +575,8 @@ item &item::ammo_set( const itype_id &ammo, int qty )
575575
qty = ammo_capacity( ammo_type );
576576

577577
// else try to add a magazine using default ammo count property if set
578-
} else if( !magazine_default().is_null() ) {
579-
item mag( magazine_default() );
578+
} else if( !magazine_default( true ).is_null() ) {
579+
item mag( magazine_default( true ) );
580580
if( mag.type->magazine->count > 0 ) {
581581
qty = mag.type->magazine->count;
582582
} else {
@@ -9600,6 +9600,24 @@ skill_id item::melee_skill() const
96009600
return res;
96019601
}
96029602

9603+
9604+
int item::min_cycle_recoil() const
9605+
{
9606+
if( !is_gun() ) {
9607+
return 0;
9608+
}
9609+
int to_cycle = type->gun->min_cycle_recoil;
9610+
// This should only be used for one mod or it'll mess things up
9611+
// TODO: maybe generalize this so you can have mods for hot loads or whatever
9612+
for( const item *mod : gunmods() ) {
9613+
// this value defaults to -1
9614+
if( mod->type->gunmod->overwrite_min_cycle_recoil > 0 ) {
9615+
to_cycle = mod->type->gunmod->overwrite_min_cycle_recoil;
9616+
}
9617+
}
9618+
return to_cycle;
9619+
}
9620+
96039621
int item::gun_dispersion( bool with_ammo, bool with_scaling ) const
96049622
{
96059623
if( !is_gun() ) {
@@ -10117,8 +10135,20 @@ bool item::uses_magazine() const
1011710135
return contents.has_pocket_type( item_pocket::pocket_type::MAGAZINE_WELL );
1011810136
}
1011910137

10120-
itype_id item::magazine_default( bool /* conversion */ ) const
10138+
itype_id item::magazine_default( bool conversion ) const
1012110139
{
10140+
// consider modded ammo types
10141+
if( conversion && !ammo_types().empty() ) {
10142+
const itype_id ammo = ammo_default();
10143+
for( const itype_id mag : contents.magazine_compatible() ) {
10144+
auto mag_types = mag->magazine->type;
10145+
if( mag_types.find( ammo->ammo->type ) != mag_types.end() ) {
10146+
return mag;
10147+
}
10148+
}
10149+
}
10150+
10151+
// otherwise return the default
1012210152
return contents.magazine_default();
1012310153
}
1012410154

src/item.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2244,7 +2244,7 @@ class item : public visitable
22442244
/** Get the default magazine type (if any) for the current effective ammo type
22452245
* @param conversion whether to include the effect of any flags or mods which convert item's ammo type
22462246
* @return magazine type or "null" if item has integral magazine or no magazines for current ammo type */
2247-
itype_id magazine_default( bool conversion = true ) const;
2247+
itype_id magazine_default( bool conversion = false ) const;
22482248

22492249
/** Get compatible magazines (if any) for this item
22502250
* @return magazine compatibility which is always empty if item has integral magazine
@@ -2344,6 +2344,10 @@ class item : public visitable
23442344
* Returns empty instance on non-gun items.
23452345
*/
23462346
damage_instance gun_damage( bool with_ammo = true, bool shot = false ) const;
2347+
/**
2348+
* The minimum force required to cycle the gun, can be overridden by mods
2349+
*/
2350+
int min_cycle_recoil() const;
23472351
/**
23482352
* Summed dispersion of a gun, including values from mods. Returns 0 on non-gun items.
23492353
*/

src/item_factory.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2931,6 +2931,7 @@ void Item_factory::load( islot_gunmod &slot, const JsonObject &jo, const std::st
29312931
assign( jo, "ammo_to_fire_multiplier", slot.ammo_to_fire_multiplier );
29322932
assign( jo, "ammo_to_fire_modifier", slot.ammo_to_fire_modifier );
29332933
assign( jo, "weight_multiplier", slot.weight_multiplier );
2934+
assign( jo, "overwrite_min_cycle_recoil", slot.overwrite_min_cycle_recoil );
29342935
// convert aim_speed to FoV and aim_speed_modifier automatically, if FoV is not set
29352936
if( slot.aim_speed >= 0 && slot.field_of_view <= 0 ) {
29362937
if( slot.aim_speed > 6 ) {

src/itype.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,9 @@ struct islot_gunmod : common_ranged_data {
791791

792792
/** Not compatable on weapons that have this mod slot */
793793
std::set<gunmod_location> blacklist_mod;
794+
795+
// minimum recoil to cycle while this is installed
796+
int overwrite_min_cycle_recoil = -1;
794797
};
795798

796799
struct islot_magazine {

src/ranged.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ bool Character::handle_gun_damage( item &it )
658658
it.inc_damage();
659659
}
660660
if( !it.has_flag( flag_PRIMITIVE_RANGED_WEAPON ) ) {
661-
if( it.ammo_data() != nullptr && ( ( it.ammo_data()->ammo->recoil < firing.min_cycle_recoil ) ||
661+
if( it.ammo_data() != nullptr && ( ( it.ammo_data()->ammo->recoil < it.min_cycle_recoil() ) ||
662662
( it.has_fault_flag( "BAD_CYCLING" ) && one_in( 16 ) ) ) &&
663663
it.faults_potential().count( fault_gun_chamber_spent ) ) {
664664
add_msg_player_or_npc( m_bad, _( "Your %s fails to cycle!" ),

0 commit comments

Comments
 (0)