@@ -229,6 +229,23 @@ float Character::morale_crafting_speed_multiplier( const recipe &rec ) const
229
229
return 1 .0f / morale_effect;
230
230
}
231
231
232
+ float Character::limb_score_crafting_speed_multiplier ( const recipe &rec ) const
233
+ {
234
+ return rec.has_flag ( flag_NO_MANIP ) ? 1 .0f : get_limb_score ( limb_score_manip );
235
+ }
236
+
237
+ float Character::pain_crafting_speed_multiplier ( const recipe &rec ) const
238
+ {
239
+ return rec.has_flag ( flag_AFFECTED_BY_PAIN ) ? std::max ( 0 .0f ,
240
+ 1 .0f - ( get_perceived_pain () / 100 .0f ) ) : 1 .0f ;
241
+ }
242
+
243
+ float Character::mut_crafting_speed_multiplier ( const recipe &rec ) const
244
+ {
245
+ return rec.has_flag ( flag_NO_ENCHANTMENT ) ? 1 .0f : 1.0 + enchantment_cache->get_value_multiply (
246
+ enchant_vals::mod::CRAFTING_SPEED_MULTIPLIER );
247
+ }
248
+
232
249
template <typename T>
233
250
static float lerped_multiplier ( const T &value, const T &low, const T &high )
234
251
{
@@ -303,14 +320,12 @@ float Character::workbench_crafting_speed_multiplier( const item &craft,
303
320
float Character::crafting_speed_multiplier ( const recipe &rec ) const
304
321
{
305
322
306
- const float limb_score = rec.has_flag ( flag_NO_MANIP ) ? 1 .0f : get_limb_score (
307
- limb_score_manip );
308
- const float pain_multi = rec.has_flag ( flag_AFFECTED_BY_PAIN ) ? std::max ( 0 .0f ,
309
- 1 .0f - ( get_perceived_pain () / 100 .0f ) ) : 1 .0f ;
323
+ const float limb_score_multi = limb_score_crafting_speed_multiplier ( rec );
324
+ const float pain_multi = pain_crafting_speed_multiplier ( rec );
310
325
311
- float crafting_speed = morale_crafting_speed_multiplier ( rec ) *
312
- lighting_craft_speed_multiplier ( rec ) *
313
- limb_score * pain_multi;
326
+ const float crafting_speed = morale_crafting_speed_multiplier ( rec ) *
327
+ lighting_craft_speed_multiplier ( rec ) *
328
+ limb_score_multi * pain_multi;
314
329
315
330
const float result = enchantment_cache->modify_value ( enchant_vals::mod::CRAFTING_SPEED_MULTIPLIER,
316
331
crafting_speed );
@@ -333,20 +348,17 @@ float Character::crafting_speed_multiplier( const item &craft,
333
348
const recipe &rec = craft.get_making ();
334
349
335
350
const float light_multi = lighting_craft_speed_multiplier ( rec );
336
- const float bench_value = ( use_cached_workbench_multiplier ||
337
- cached_workbench_multiplier > 0 .0f ) ? cached_workbench_multiplier :
351
+ const float bench_multi = rec.has_flag ( flag_NO_BENCH ) ?
352
+ 1 .0f :
353
+ ( use_cached_workbench_multiplier || cached_workbench_multiplier > 0 .0f ) ?
354
+ cached_workbench_multiplier :
338
355
workbench_crafting_speed_multiplier ( craft, loc );
339
- const float bench_multi = rec.has_flag ( flag_NO_BENCH ) ? 1 .0f : bench_value;
340
356
const float morale_multi = morale_crafting_speed_multiplier ( rec );
341
- const float mut_multi = rec.has_flag ( flag_NO_ENCHANTMENT ) ? 1 .0f : 1.0 +
342
- enchantment_cache->get_value_multiply (
343
- enchant_vals::mod::CRAFTING_SPEED_MULTIPLIER );
344
- const float limb_score = rec.has_flag ( flag_NO_MANIP ) ? 1 .0f : get_limb_score (
345
- limb_score_manip );
346
- const float pain_multi = rec.has_flag ( flag_AFFECTED_BY_PAIN ) ? std::max ( 0 .0f ,
347
- 1 .0f - ( get_perceived_pain () / 100 .0f ) ) : 1 .0f ;
348
-
349
- const float total_multi = light_multi * bench_multi * morale_multi * mut_multi * limb_score *
357
+ const float mut_multi = mut_crafting_speed_multiplier ( rec );
358
+ const float limb_score_multi = limb_score_crafting_speed_multiplier ( rec );
359
+ const float pain_multi = pain_crafting_speed_multiplier ( rec );
360
+
361
+ const float total_multi = light_multi * bench_multi * morale_multi * mut_multi * limb_score_multi *
350
362
pain_multi;
351
363
352
364
if ( light_multi <= 0 .0f ) {
@@ -750,11 +762,7 @@ static item_location set_item_inventory( Character &p, item &newit )
750
762
{
751
763
item_location ret_val = item_location::nowhere;
752
764
if ( newit.made_of ( phase_id::LIQUID ) ) {
753
- if ( p.is_avatar () ) {
754
- liquid_handler::handle_all_liquid ( newit, PICKUP_RANGE );
755
- } else {
756
- liquid_handler::handle_npc_liquid ( newit, p );
757
- }
765
+ liquid_handler::handle_all_or_npc_liquid ( p, newit, PICKUP_RANGE );
758
766
} else {
759
767
p.inv ->assign_empty_invlet ( newit, p );
760
768
// We might not have space for the item
@@ -866,18 +874,21 @@ static item_location place_craft_or_disassembly(
866
874
}
867
875
}
868
876
877
+ auto craft_wield = [&craft_in_world, &ch, &craft]() {
878
+ if ( std::optional<item_location> it_loc = wield_craft ( ch, craft ) ) {
879
+ craft_in_world = *it_loc;
880
+ } else {
881
+ // This almost certainly shouldn't happen
882
+ put_into_vehicle_or_drop ( ch, item_drop_reason::tumbling, {craft} );
883
+ }
884
+ };
885
+
869
886
// Crafting without a workbench
870
887
if ( !target ) {
871
888
if ( !ch.has_two_arms_lifting () ) {
872
889
craft_in_world = set_item_map_or_vehicle ( ch, ch.pos_bub (), craft );
873
890
} else if ( !ch.has_wield_conflicts ( craft ) || ch.is_npc () ) {
874
- // NPC always tries wield craft first
875
- if ( std::optional<item_location> it_loc = wield_craft ( ch, craft ) ) {
876
- craft_in_world = *it_loc;
877
- } else {
878
- // This almost certainly shouldn't happen
879
- put_into_vehicle_or_drop ( ch, item_drop_reason::tumbling, {craft} );
880
- }
891
+ craft_wield ();
881
892
} else {
882
893
enum option : int {
883
894
WIELD_CRAFT = 0 ,
@@ -902,12 +913,7 @@ static item_location place_craft_or_disassembly(
902
913
const option choice = amenu.ret == UILIST_CANCEL ? DROP : static_cast <option>( amenu.ret );
903
914
switch ( choice ) {
904
915
case WIELD_CRAFT: {
905
- if ( std::optional<item_location> it_loc = wield_craft ( ch, craft ) ) {
906
- craft_in_world = *it_loc;
907
- } else {
908
- // This almost certainly shouldn't happen
909
- put_into_vehicle_or_drop ( ch, item_drop_reason::tumbling, {craft} );
910
- }
916
+ craft_wield ();
911
917
break ;
912
918
}
913
919
case DROP_CRAFT: {
@@ -1494,11 +1500,7 @@ static void spawn_items( Character &guy, std::vector<item> &results,
1494
1500
1495
1501
newit.set_owner ( guy.get_faction ()->id );
1496
1502
if ( newit.made_of ( phase_id::LIQUID ) ) {
1497
- if ( guy.is_avatar () ) {
1498
- liquid_handler::handle_all_liquid ( newit, PICKUP_RANGE );
1499
- } else {
1500
- liquid_handler::handle_npc_liquid ( newit, guy );
1501
- }
1503
+ liquid_handler::handle_all_or_npc_liquid ( guy, newit, PICKUP_RANGE );
1502
1504
} else if ( !loc && allow_wield && !guy.has_wield_conflicts ( newit ) &&
1503
1505
guy.can_wield ( newit ).success () ) {
1504
1506
wield_craft ( guy, newit );
@@ -2872,18 +2874,7 @@ void Character::complete_disassemble( item_location &target, const recipe &dis )
2872
2874
if ( dis_item.count_by_charges () ) {
2873
2875
compcount *= activity.position ;
2874
2876
}
2875
- const bool is_liquid = newit.made_of ( phase_id::LIQUID );
2876
- // Compress liquids and counted-by-charges items into one item,
2877
- // they are added together on the map anyway and handle_liquid
2878
- // should only be called once to put it all into a container at once.
2879
- if ( newit.count_by_charges () || is_liquid ) {
2880
- newit.charges = compcount;
2881
- compcount = 1 ;
2882
- } else if ( !newit.craft_has_charges () && newit.charges > 0 ) {
2883
- // tools that can be unloaded should be created unloaded,
2884
- // tools that can't be unloaded will keep their default charges.
2885
- newit.charges = 0 ;
2886
- }
2877
+ newit.compress_charges_or_liquid ( compcount );
2887
2878
2888
2879
// If the recipe has a `FULL_MAGAZINE` flag, spawn any magazines full of ammo
2889
2880
if ( newit.is_magazine () && dis.has_flag ( flag_FULL_MAGAZINE ) ) {
@@ -2980,11 +2971,7 @@ void Character::complete_disassemble( item_location &target, const recipe &dis )
2980
2971
}
2981
2972
2982
2973
if ( act_item.made_of ( phase_id::LIQUID ) ) {
2983
- if ( is_avatar () ) {
2984
- liquid_handler::handle_all_liquid ( act_item, PICKUP_RANGE );
2985
- } else {
2986
- liquid_handler::handle_npc_liquid ( act_item, *this );
2987
- }
2974
+ liquid_handler::handle_all_or_npc_liquid ( *this , act_item, PICKUP_RANGE );
2988
2975
} else {
2989
2976
drop_items.push_back ( act_item );
2990
2977
}
@@ -3051,14 +3038,10 @@ void remove_ammo( std::list<item> &dis_items, Character &p )
3051
3038
3052
3039
void drop_or_handle ( const item &newit, Character &p )
3053
3040
{
3041
+ item tmp ( newit );
3054
3042
if ( newit.made_of ( phase_id::LIQUID ) ) {
3055
- if ( p.is_avatar () ) {
3056
- liquid_handler::handle_all_liquid ( newit, PICKUP_RANGE );
3057
- } else {
3058
- liquid_handler::handle_npc_liquid ( newit, p );
3059
- }
3043
+ liquid_handler::handle_all_or_npc_liquid ( p, tmp, PICKUP_RANGE );
3060
3044
} else {
3061
- item tmp ( newit );
3062
3045
p.i_add_or_drop ( tmp );
3063
3046
}
3064
3047
}
0 commit comments