-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
activity_handlers.cpp
3888 lines (3558 loc) · 157 KB
/
activity_handlers.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "activity_handlers.h"
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iterator>
#include <memory>
#include <optional>
#include <ostream>
#include <queue>
#include <set>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <utility>
#include "action.h"
#include "activity_type.h"
#include "advanced_inv.h"
#include "avatar.h"
#include "avatar_action.h"
#include "bionics.h"
#include "bodypart.h"
#include "butchery_requirements.h"
#include "calendar.h"
#include "cata_utility.h"
#include "character.h"
#include "character_martial_arts.h"
#include "clzones.h"
#include "colony.h"
#include "color.h"
#include "construction.h"
#include "coordinates.h"
#include "creature.h"
#include "creature_tracker.h"
#include "damage.h"
#include "debug.h"
#include "effect_source.h"
#include "enums.h"
#include "event.h"
#include "event_bus.h"
#include "fault.h"
#include "field_type.h"
#include "flag.h"
#include "game.h"
#include "game_constants.h"
#include "game_inventory.h"
#include "handle_liquid.h"
#include "harvest.h"
#include "iexamine.h"
#include "inventory.h"
#include "item.h"
#include "item_factory.h"
#include "item_location.h"
#include "item_pocket.h"
#include "item_stack.h"
#include "itype.h"
#include "iuse.h"
#include "iuse_actor.h"
#include "line.h"
#include "magic.h"
#include "map.h"
#include "map_iterator.h"
#include "map_selector.h"
#include "mapdata.h"
#include "martialarts.h"
#include "memory_fast.h"
#include "messages.h"
#include "mongroup.h"
#include "monster.h"
#include "morale_types.h"
#include "mtype.h"
#include "npc.h"
#include "omdata.h"
#include "output.h"
#include "overmapbuffer.h"
#include "pimpl.h"
#include "player_activity.h"
#include "point.h"
#include "proficiency.h"
#include "ranged.h"
#include "recipe_dictionary.h"
#include "requirements.h"
#include "ret_val.h"
#include "rng.h"
#include "skill.h"
#include "sounds.h"
#include "string_formatter.h"
#include "text_snippets.h"
#include "translations.h"
#include "type_id.h"
#include "ui.h"
#include "units.h"
#include "value_ptr.h"
#include "veh_interact.h"
#include "vehicle.h"
#include "vpart_position.h"
#include "weather.h"
enum class creature_size : int;
#define dbg(x) DebugLog((x),D_GAME) << __FILE__ << ":" << __LINE__ << ": "
static const activity_id ACT_ADV_INVENTORY( "ACT_ADV_INVENTORY" );
static const activity_id ACT_ARMOR_LAYERS( "ACT_ARMOR_LAYERS" );
static const activity_id ACT_ATM( "ACT_ATM" );
static const activity_id ACT_BLEED( "ACT_BLEED" );
static const activity_id ACT_BUILD( "ACT_BUILD" );
static const activity_id ACT_BUTCHER( "ACT_BUTCHER" );
static const activity_id ACT_BUTCHER_FULL( "ACT_BUTCHER_FULL" );
static const activity_id ACT_CONSUME_DRINK_MENU( "ACT_CONSUME_DRINK_MENU" );
static const activity_id ACT_CONSUME_FOOD_MENU( "ACT_CONSUME_FOOD_MENU" );
static const activity_id ACT_CONSUME_MEDS_MENU( "ACT_CONSUME_MEDS_MENU" );
static const activity_id ACT_DISMEMBER( "ACT_DISMEMBER" );
static const activity_id ACT_DISSECT( "ACT_DISSECT" );
static const activity_id ACT_EAT_MENU( "ACT_EAT_MENU" );
static const activity_id ACT_FERTILIZE_PLOT( "ACT_FERTILIZE_PLOT" );
static const activity_id ACT_FETCH_REQUIRED( "ACT_FETCH_REQUIRED" );
static const activity_id ACT_FIELD_DRESS( "ACT_FIELD_DRESS" );
static const activity_id ACT_FILL_LIQUID( "ACT_FILL_LIQUID" );
static const activity_id ACT_FIND_MOUNT( "ACT_FIND_MOUNT" );
static const activity_id ACT_FISH( "ACT_FISH" );
static const activity_id ACT_GAME( "ACT_GAME" );
static const activity_id ACT_GENERIC_GAME( "ACT_GENERIC_GAME" );
static const activity_id ACT_HAND_CRANK( "ACT_HAND_CRANK" );
static const activity_id ACT_HEATING( "ACT_HEATING" );
static const activity_id ACT_JACKHAMMER( "ACT_JACKHAMMER" );
static const activity_id ACT_MEND_ITEM( "ACT_MEND_ITEM" );
static const activity_id ACT_MOVE_LOOT( "ACT_MOVE_LOOT" );
static const activity_id ACT_MULTIPLE_BUTCHER( "ACT_MULTIPLE_BUTCHER" );
static const activity_id ACT_MULTIPLE_CHOP_PLANKS( "ACT_MULTIPLE_CHOP_PLANKS" );
static const activity_id ACT_MULTIPLE_CHOP_TREES( "ACT_MULTIPLE_CHOP_TREES" );
static const activity_id ACT_MULTIPLE_CONSTRUCTION( "ACT_MULTIPLE_CONSTRUCTION" );
static const activity_id ACT_MULTIPLE_CRAFT( "ACT_MULTIPLE_CRAFT" );
static const activity_id ACT_MULTIPLE_DIS( "ACT_MULTIPLE_DIS" );
static const activity_id ACT_MULTIPLE_FARM( "ACT_MULTIPLE_FARM" );
static const activity_id ACT_MULTIPLE_FISH( "ACT_MULTIPLE_FISH" );
static const activity_id ACT_MULTIPLE_MINE( "ACT_MULTIPLE_MINE" );
static const activity_id ACT_MULTIPLE_MOP( "ACT_MULTIPLE_MOP" );
static const activity_id ACT_MULTIPLE_READ( "ACT_MULTIPLE_READ" );
static const activity_id ACT_OPERATION( "ACT_OPERATION" );
static const activity_id ACT_PICKAXE( "ACT_PICKAXE" );
static const activity_id ACT_PLANT_SEED( "ACT_PLANT_SEED" );
static const activity_id ACT_PULL_CREATURE( "ACT_PULL_CREATURE" );
static const activity_id ACT_PULP( "ACT_PULP" );
static const activity_id ACT_QUARTER( "ACT_QUARTER" );
static const activity_id ACT_REPAIR_ITEM( "ACT_REPAIR_ITEM" );
static const activity_id ACT_ROBOT_CONTROL( "ACT_ROBOT_CONTROL" );
static const activity_id ACT_SKIN( "ACT_SKIN" );
static const activity_id ACT_SOCIALIZE( "ACT_SOCIALIZE" );
static const activity_id ACT_SPELLCASTING( "ACT_SPELLCASTING" );
static const activity_id ACT_START_ENGINES( "ACT_START_ENGINES" );
static const activity_id ACT_START_FIRE( "ACT_START_FIRE" );
static const activity_id ACT_STUDY_SPELL( "ACT_STUDY_SPELL" );
static const activity_id ACT_TIDY_UP( "ACT_TIDY_UP" );
static const activity_id ACT_TOOLMOD_ADD( "ACT_TOOLMOD_ADD" );
static const activity_id ACT_TRAIN( "ACT_TRAIN" );
static const activity_id ACT_TRAIN_TEACHER( "ACT_TRAIN_TEACHER" );
static const activity_id ACT_TRAVELLING( "ACT_TRAVELLING" );
static const activity_id ACT_TREE_COMMUNION( "ACT_TREE_COMMUNION" );
static const activity_id ACT_VEHICLE( "ACT_VEHICLE" );
static const activity_id ACT_VEHICLE_DECONSTRUCTION( "ACT_VEHICLE_DECONSTRUCTION" );
static const activity_id ACT_VEHICLE_REPAIR( "ACT_VEHICLE_REPAIR" );
static const activity_id ACT_VIBE( "ACT_VIBE" );
static const activity_id ACT_VIEW_RECIPE( "ACT_VIEW_RECIPE" );
static const activity_id ACT_WAIT( "ACT_WAIT" );
static const activity_id ACT_WAIT_NPC( "ACT_WAIT_NPC" );
static const activity_id ACT_WAIT_STAMINA( "ACT_WAIT_STAMINA" );
static const activity_id ACT_WAIT_WEATHER( "ACT_WAIT_WEATHER" );
static const ammotype ammo_battery( "battery" );
static const bionic_id bio_painkiller( "bio_painkiller" );
static const damage_type_id damage_acid( "acid" );
static const damage_type_id damage_bash( "bash" );
static const damage_type_id damage_cut( "cut" );
static const damage_type_id damage_stab( "stab" );
static const efftype_id effect_bleed( "bleed" );
static const efftype_id effect_blind( "blind" );
static const efftype_id effect_controlled( "controlled" );
static const efftype_id effect_narcosis( "narcosis" );
static const efftype_id effect_pet( "pet" );
static const efftype_id effect_sleep( "sleep" );
static const efftype_id effect_under_operation( "under_operation" );
static const harvest_drop_type_id harvest_drop_blood( "blood" );
static const harvest_drop_type_id harvest_drop_bone( "bone" );
static const harvest_drop_type_id harvest_drop_flesh( "flesh" );
static const harvest_drop_type_id harvest_drop_offal( "offal" );
static const harvest_drop_type_id harvest_drop_skin( "skin" );
static const itype_id itype_animal( "animal" );
static const itype_id itype_battery( "battery" );
static const itype_id itype_burnt_out_bionic( "burnt_out_bionic" );
static const itype_id itype_muscle( "muscle" );
static const json_character_flag json_flag_CANNIBAL( "CANNIBAL" );
static const json_character_flag json_flag_PAIN_IMMUNE( "PAIN_IMMUNE" );
static const json_character_flag json_flag_PSYCHOPATH( "PSYCHOPATH" );
static const json_character_flag json_flag_SAPIOVORE( "SAPIOVORE" );
static const json_character_flag json_flag_SILENT_SPELL( "SILENT_SPELL" );
static const mon_flag_str_id mon_flag_RIDEABLE_MECH( "RIDEABLE_MECH" );
static const mongroup_id GROUP_FISH( "GROUP_FISH" );
static const proficiency_id proficiency_prof_dissect_humans( "prof_dissect_humans" );
static const quality_id qual_BUTCHER( "BUTCHER" );
static const quality_id qual_CUT_FINE( "CUT_FINE" );
static const quality_id qual_FISHING_ROD( "FISHING_ROD" );
static const skill_id skill_computer( "computer" );
static const skill_id skill_firstaid( "firstaid" );
static const skill_id skill_survival( "survival" );
static const species_id species_HUMAN( "HUMAN" );
static const species_id species_ZOMBIE( "ZOMBIE" );
static const trait_id trait_DEBUG_HS( "DEBUG_HS" );
static const trait_id trait_SPIRITUAL( "SPIRITUAL" );
static const trait_id trait_STOCKY_TROGLO( "STOCKY_TROGLO" );
static const zone_type_id zone_type_FARM_PLOT( "FARM_PLOT" );
using namespace activity_handlers;
const std::map< activity_id, std::function<void( player_activity *, Character * )> >
activity_handlers::do_turn_functions = {
{ ACT_FILL_LIQUID, fill_liquid_do_turn },
{ ACT_PICKAXE, pickaxe_do_turn },
{ ACT_PULP, pulp_do_turn },
{ ACT_GAME, game_do_turn },
{ ACT_GENERIC_GAME, generic_game_do_turn },
{ ACT_START_FIRE, start_fire_do_turn },
{ ACT_VIBE, vibe_do_turn },
{ ACT_HAND_CRANK, hand_crank_do_turn },
{ ACT_MULTIPLE_FISH, multiple_fish_do_turn },
{ ACT_MULTIPLE_CONSTRUCTION, multiple_construction_do_turn },
{ ACT_MULTIPLE_MINE, multiple_mine_do_turn },
{ ACT_MULTIPLE_MOP, multiple_mop_do_turn },
{ ACT_MULTIPLE_BUTCHER, multiple_butcher_do_turn },
{ ACT_MULTIPLE_FARM, multiple_farm_do_turn },
{ ACT_FETCH_REQUIRED, fetch_do_turn },
{ ACT_BUILD, build_do_turn },
{ ACT_EAT_MENU, eat_menu_do_turn },
{ ACT_VEHICLE_DECONSTRUCTION, vehicle_deconstruction_do_turn },
{ ACT_VEHICLE_REPAIR, vehicle_repair_do_turn },
{ ACT_MULTIPLE_CHOP_TREES, chop_trees_do_turn },
{ ACT_CONSUME_FOOD_MENU, consume_food_menu_do_turn },
{ ACT_CONSUME_DRINK_MENU, consume_drink_menu_do_turn },
{ ACT_CONSUME_MEDS_MENU, consume_meds_menu_do_turn },
{ ACT_VIEW_RECIPE, view_recipe_do_turn },
{ ACT_MOVE_LOOT, move_loot_do_turn },
{ ACT_ADV_INVENTORY, adv_inventory_do_turn },
{ ACT_ARMOR_LAYERS, armor_layers_do_turn },
{ ACT_ATM, atm_do_turn },
{ ACT_FISH, fish_do_turn },
{ ACT_REPAIR_ITEM, repair_item_do_turn },
{ ACT_BLEED, butcher_do_turn },
{ ACT_BUTCHER, butcher_do_turn },
{ ACT_BUTCHER_FULL, butcher_do_turn },
{ ACT_TRAVELLING, travel_do_turn },
{ ACT_FIELD_DRESS, butcher_do_turn },
{ ACT_SKIN, butcher_do_turn },
{ ACT_QUARTER, butcher_do_turn },
{ ACT_DISMEMBER, butcher_do_turn },
{ ACT_DISSECT, butcher_do_turn },
{ ACT_TIDY_UP, tidy_up_do_turn },
{ ACT_TIDY_UP, tidy_up_do_turn },
{ ACT_JACKHAMMER, jackhammer_do_turn },
{ ACT_FIND_MOUNT, find_mount_do_turn },
{ ACT_MULTIPLE_CHOP_PLANKS, multiple_chop_planks_do_turn },
{ ACT_FERTILIZE_PLOT, fertilize_plot_do_turn },
{ ACT_OPERATION, operation_do_turn },
{ ACT_ROBOT_CONTROL, robot_control_do_turn },
{ ACT_TREE_COMMUNION, tree_communion_do_turn },
{ ACT_STUDY_SPELL, study_spell_do_turn },
{ ACT_WAIT_STAMINA, wait_stamina_do_turn },
{ ACT_MULTIPLE_CRAFT, multiple_craft_do_turn },
{ ACT_MULTIPLE_DIS, multiple_dis_do_turn },
{ ACT_MULTIPLE_READ, multiple_read_do_turn },
};
const std::map< activity_id, std::function<void( player_activity *, Character * )> >
activity_handlers::finish_functions = {
{ ACT_BLEED, butcher_finish },
{ ACT_BUTCHER, butcher_finish },
{ ACT_BUTCHER_FULL, butcher_finish },
{ ACT_FIELD_DRESS, butcher_finish },
{ ACT_SKIN, butcher_finish },
{ ACT_QUARTER, butcher_finish },
{ ACT_DISMEMBER, butcher_finish },
{ ACT_DISSECT, butcher_finish },
{ ACT_FISH, fish_finish },
{ ACT_PICKAXE, pickaxe_finish },
{ ACT_START_FIRE, start_fire_finish },
{ ACT_GENERIC_GAME, generic_game_finish },
{ ACT_TRAIN, train_finish },
{ ACT_TRAIN_TEACHER, teach_finish },
{ ACT_PLANT_SEED, plant_seed_finish },
{ ACT_VEHICLE, vehicle_finish },
{ ACT_START_ENGINES, start_engines_finish },
{ ACT_PULP, pulp_finish },
{ ACT_REPAIR_ITEM, repair_item_finish },
{ ACT_HEATING, heat_item_finish },
{ ACT_MEND_ITEM, mend_item_finish },
{ ACT_TOOLMOD_ADD, toolmod_add_finish },
{ ACT_WAIT, wait_finish },
{ ACT_WAIT_WEATHER, wait_weather_finish },
{ ACT_WAIT_NPC, wait_npc_finish },
{ ACT_WAIT_STAMINA, wait_stamina_finish },
{ ACT_SOCIALIZE, socialize_finish },
{ ACT_OPERATION, operation_finish },
{ ACT_VIBE, vibe_finish },
{ ACT_ATM, atm_finish },
{ ACT_EAT_MENU, eat_menu_finish },
{ ACT_CONSUME_FOOD_MENU, eat_menu_finish },
{ ACT_CONSUME_DRINK_MENU, eat_menu_finish },
{ ACT_CONSUME_MEDS_MENU, eat_menu_finish },
{ ACT_VIEW_RECIPE, view_recipe_finish },
{ ACT_JACKHAMMER, jackhammer_finish },
{ ACT_ROBOT_CONTROL, robot_control_finish },
{ ACT_PULL_CREATURE, pull_creature_finish },
{ ACT_SPELLCASTING, spellcasting_finish },
{ ACT_STUDY_SPELL, study_spell_finish },
};
namespace io
{
// *INDENT-OFF*
template<>
std::string enum_to_string<butcher_type>( butcher_type data )
{
switch( data ) {
case butcher_type::BLEED: return "BLEED";
case butcher_type::DISMEMBER: return "DISMEMBER";
case butcher_type::DISSECT: return "DISSECT";
case butcher_type::FIELD_DRESS: return "FIELD_DRESS";
case butcher_type::FULL: return "FULL";
case butcher_type::QUARTER: return "QUARTER";
case butcher_type::QUICK: return "QUICK";
case butcher_type::SKIN: return "SKIN";
case butcher_type::NUM_TYPES: break;
}
cata_fatal( "Invalid valid_target" );
}
// *INDENT-ON*
} // namespace io
bool activity_handlers::resume_for_multi_activities( Character &you )
{
if( !you.backlog.empty() ) {
player_activity &back_act = you.backlog.front();
if( back_act.is_multi_type() ) {
you.assign_activity( you.backlog.front().id() );
you.backlog.clear();
return true;
}
}
return false;
}
static bool check_butcher_dissect( const int roll )
{
// Failure rates for dissection rolls
// 100% at roll 0, 66% at roll 1, 50% at roll 2, 40% @ 3, 33% @ 4, 28% @ 5, ... , 16% @ 10
// Roll is roughly a rng(0, -3 + 1st_aid + fine_cut_quality + 1/2 electronics + small_dex_bonus)
// Roll is reduced by corpse damage level, but to no less then 0
add_msg_debug( debugmode::DF_ACT_BUTCHER, "Roll = %i", roll );
add_msg_debug( debugmode::DF_ACT_BUTCHER, "Failure chance = %f%%",
( 10.0f / ( 10.0f + roll * 5.0f ) ) * 100.0f );
const bool failed = x_in_y( 10, ( 10 + roll * 5 ) );
return !failed;
}
static bool butcher_dissect_item( item &what, const tripoint &pos,
const time_point &age, const int roll )
{
if( roll < 0 ) {
return false;
}
bool success = check_butcher_dissect( roll );
map &here = get_map();
if( what.is_bionic() && !success ) {
item burnt_out_cbm( itype_burnt_out_bionic, age );
add_msg( m_good, _( "You discover a %s!" ), burnt_out_cbm.tname() );
here.add_item( pos, burnt_out_cbm );
} else if( success ) {
add_msg( m_good, _( "You discover a %s!" ), what.tname() );
here.add_item( pos, what );
}
return success;
}
static void set_up_butchery( player_activity &act, Character &you, butcher_type action )
{
const int factor = you.max_quality( action == butcher_type::DISSECT ? qual_CUT_FINE : qual_BUTCHER,
PICKUP_RANGE );
const item &corpse_item = *act.targets.back();
const mtype &corpse = *corpse_item.get_mtype();
if( action != butcher_type::DISSECT ) {
if( factor == INT_MIN ) {
you.add_msg_if_player( m_info,
_( "None of your cutting tools are suitable for butchering." ) );
act.set_to_null();
return;
} else if( factor < 0 && one_in( 3 ) ) {
you.add_msg_if_player( m_bad,
_( "You don't trust the quality of your tools, but carry on anyway." ) );
}
}
if( action == butcher_type::DISSECT ) {
switch( factor ) {
case INT_MIN:
you.add_msg_if_player( m_info, _( "None of your tools are sharp and precise enough to do that." ) );
act.set_to_null();
return;
case 1:
you.add_msg_if_player( m_info, _( "You could use a better tool, but this will do." ) );
break;
case 2:
you.add_msg_if_player( m_info, _( "This tool is great, but you still would like a scalpel." ) );
break;
case 3:
you.add_msg_if_player( m_info, _( "You dissect the corpse with a trusty scalpel." ) );
break;
case 5:
you.add_msg_if_player( m_info,
_( "You dissect the corpse with a sophisticated system of surgical grade scalpels." ) );
break;
}
}
const std::pair<float, requirement_id> butchery_requirements =
corpse.harvest->get_butchery_requirements().get_fastest_requirements( you.crafting_inventory(),
corpse.size, action );
// Requirements for the various types
const requirement_id butchery_requirement = butchery_requirements.second;
if( !butchery_requirement->can_make_with_inventory(
you.crafting_inventory( you.pos(), PICKUP_RANGE ), is_crafting_component ) ) {
std::string popup_output = _( "You can't butcher this; you are missing some tools.\n" );
for( const std::string &str : butchery_requirement->get_folded_components_list(
45, c_light_gray, you.crafting_inventory( you.pos(), PICKUP_RANGE ), is_crafting_component ) ) {
popup_output += str + '\n';
}
for( const std::string &str : butchery_requirement->get_folded_tools_list(
45, c_light_gray, you.crafting_inventory( you.pos(), PICKUP_RANGE ) ) ) {
popup_output += str + '\n';
}
act.set_to_null();
popup( popup_output );
return;
}
if( action == butcher_type::BLEED && ( corpse_item.has_flag( flag_BLED ) ||
corpse_item.has_flag( flag_QUARTERED ) || corpse_item.has_flag( flag_FIELD_DRESS_FAILED ) ||
corpse_item.has_flag( flag_FIELD_DRESS ) ) ) {
you.add_msg_if_player( m_info, _( "This corpse has already been bled." ) );
act.targets.pop_back();
return;
}
if( action == butcher_type::DISSECT && ( corpse_item.has_flag( flag_QUARTERED ) ||
corpse_item.has_flag( flag_FIELD_DRESS_FAILED ) ) ) {
you.add_msg_if_player( m_info,
_( "It would be futile to dissect this badly damaged corpse." ) );
act.targets.pop_back();
return;
}
if( action == butcher_type::FIELD_DRESS && ( corpse_item.has_flag( flag_FIELD_DRESS ) ||
corpse_item.has_flag( flag_FIELD_DRESS_FAILED ) ) ) {
you.add_msg_if_player( m_info, _( "This corpse is already field dressed." ) );
act.targets.pop_back();
return;
}
if( action == butcher_type::SKIN && corpse_item.has_flag( flag_SKINNED ) ) {
you.add_msg_if_player( m_info, _( "This corpse is already skinned." ) );
act.targets.pop_back();
return;
}
if( action == butcher_type::QUARTER ) {
if( corpse.size == creature_size::tiny ) {
you.add_msg_if_player( m_bad, _( "This corpse is too small to quarter without damaging." ),
corpse.nname() );
act.targets.pop_back();
return;
}
if( corpse_item.has_flag( flag_QUARTERED ) ) {
you.add_msg_if_player( m_bad, _( "This is already quartered." ), corpse.nname() );
act.targets.pop_back();
return;
}
if( !( corpse_item.has_flag( flag_FIELD_DRESS ) ||
corpse_item.has_flag( flag_FIELD_DRESS_FAILED ) ) &&
corpse_item.get_mtype()->harvest->has_entry_type( harvest_drop_offal ) ) {
you.add_msg_if_player( m_bad, _( "You need to perform field dressing before quartering." ),
corpse.nname() );
act.targets.pop_back();
return;
}
}
const bool is_human = corpse.id == mtype_id::NULL_ID() || ( corpse.in_species( species_HUMAN ) &&
!corpse.in_species( species_ZOMBIE ) );
// applies to all butchery actions except for dissections
if( is_human && action != butcher_type::DISSECT && !( you.has_flag( json_flag_CANNIBAL ) ||
you.has_flag( json_flag_PSYCHOPATH ) || you.has_flag( json_flag_SAPIOVORE ) ) ) {
//first determine if the butcherer has the dissect_humans proficiency.
if( you.has_proficiency( proficiency_prof_dissect_humans ) ) {
//if it's player doing the butchery, ask them first.
if( you.is_avatar() ) {
if( query_yn(
_( "Really desecrate the mortal remains of a fellow human being by butchering them for meat?" ) ) ) {
//give the player a random message showing their disgust and cause morale penalty.
switch( rng( 1, 3 ) ) {
case 1:
you.add_msg_if_player( m_bad, _( "You clench your teeth at the prospect of this gruesome job." ) );
break;
case 2:
you.add_msg_if_player( m_bad, _( "This will haunt you in your dreams." ) );
break;
case 3:
you.add_msg_if_player( m_bad,
_( "You try to look away, but this gruesome image will stay on your mind for some time." ) );
break;
}
get_player_character().add_morale( MORALE_BUTCHER, -50, 0, 2_days, 3_hours );
} else {
//player has the dissect_humans prof, so they're familiar with dissection. reference this in their refusal to butcher
you.add_msg_if_player( m_good, _( "You were trained for autopsies, not butchery." ) );
act.targets.pop_back();
return;
}
} else {
//if not the avatar, don't ask, just do it and suffer without comment
you.add_morale( MORALE_BUTCHER, -50, 0, 2_days, 3_hours );
}
} else {
//this runs if the butcherer does NOT have prof_dissect_humans
if( you.is_avatar() ) {
if( query_yn( _( "Would you dare desecrate the mortal remains of a fellow human being?" ) ) ) {
//random message and morale penalty
switch( rng( 1, 3 ) ) {
case 1:
you.add_msg_if_player( m_bad, _( "You clench your teeth at the prospect of this gruesome job." ) );
break;
case 2:
you.add_msg_if_player( m_bad, _( "This will haunt you in your dreams." ) );
break;
case 3:
you.add_msg_if_player( m_bad,
_( "You try to look away, but this gruesome image will stay on your mind for some time." ) );
break;
}
get_player_character().add_morale( MORALE_BUTCHER, -50, 0, 2_days, 3_hours );
} else {
//player doesn't have dissect_humans, so just give a regular refusal to mess with the corpse
you.add_msg_if_player( m_good, _( "It needs a coffin, not a knife." ) );
act.targets.pop_back();
return;
}
} else {
//again, don't complain about it, or inform about it, just do it
you.add_morale( MORALE_BUTCHER, -50, 0, 2_days, 3_hours );
}
}
}
// applies to only dissections, so that dissect_humans training makes a difference.
if( is_human && action == butcher_type::DISSECT && !( you.has_flag( json_flag_CANNIBAL ) ||
you.has_flag( json_flag_PSYCHOPATH ) || you.has_flag( json_flag_SAPIOVORE ) ) ) {
if( you.has_proficiency( proficiency_prof_dissect_humans ) ) {
//you're either trained for this, densensitized, or both. doesn't bother you.
if( you.is_avatar() ) {
//this is a dissection, and we are trained for dissection, so no morale penalty, and lighter flavor text.
switch( rng( 1, 3 ) ) {
case 1:
you.add_msg_if_player( m_good, _( "You grit your teeth and get to work." ) );
break;
case 2:
you.add_msg_if_player( m_good,
_( "The task at hand is unpleasant, but you steel your nerves regardless." ) );
break;
case 3:
you.add_msg_if_player( m_good,
_( "Hopefully whatever you can glean from this autopsy is worth the effort." ) );
break;
}
}
//if we're not the avatar, we aren't getting a morale penalty as usual, and no message, so nothing happens
} else {
//we don't have dissect_humans but are trying to dissect anyways.
if( you.is_avatar() ) {
if( query_yn( _( "Really dissect the remains of a fellow human being?" ) ) ) {
//give us a message indicating we are dissecting without the stomach for it, but not actually butchering. lower morale penalty.
switch( rng( 1, 3 ) ) {
case 1:
you.add_msg_if_player( m_bad,
_( "This is nothing like dissecting a frog in biology class. You feel sick inside." ) );
break;
case 2:
you.add_msg_if_player( m_bad, _( "You wonder how anyone manages to do this ghastly work." ) );
break;
case 3:
you.add_msg_if_player( m_bad,
_( "The grim nature of your task deeply upsets you, leaving you feeling disgusted with yourself." ) );
break;
}
get_player_character().add_morale( MORALE_BUTCHER, -40, 0, 1_days, 2_hours );
} else {
//standard refusal to butcher
you.add_msg_if_player( m_good, _( "It needs a coffin, not a knife." ) );
act.targets.pop_back();
return;
}
} else {
//if we're not player and don't have dissect_humans, just add morale penalty.
you.add_morale( MORALE_BUTCHER, -40, 0, 1_days, 2_hours );
}
}
}
act.moves_left = butcher_time_to_cut( you, corpse_item, action ) * butchery_requirements.first;
// We have a valid target, so preform the full finish function
// instead of just selecting the next valid target
act.index = false;
}
int butcher_time_to_cut( Character &you, const item &corpse_item, const butcher_type action )
{
const mtype &corpse = *corpse_item.get_mtype();
const int factor = you.max_quality( action == butcher_type::DISSECT ? qual_CUT_FINE : qual_BUTCHER,
PICKUP_RANGE );
int time_to_cut;
switch( corpse.size ) {
// Time (roughly) in turns to cut up the corpse
case creature_size::tiny:
time_to_cut = 150;
break;
case creature_size::small:
time_to_cut = 300;
break;
case creature_size::medium:
time_to_cut = 450;
break;
case creature_size::large:
time_to_cut = 600;
break;
case creature_size::huge:
time_to_cut = 1800;
break;
default:
debugmsg( "ERROR: Invalid creature_size on %s", corpse.nname() );
time_to_cut = 450; // default to medium
break;
}
// At factor 0, base 100 time_to_cut remains 100. At factor 50, it's 50 , at factor 75 it's 25
time_to_cut *= std::max( 25, 100 - factor );
switch( action ) {
case butcher_type::QUICK:
case butcher_type::BLEED:
break;
case butcher_type::FULL:
if( !corpse_item.has_flag( flag_FIELD_DRESS ) || corpse_item.has_flag( flag_FIELD_DRESS_FAILED ) ) {
time_to_cut *= 6;
} else {
time_to_cut *= 4;
}
break;
case butcher_type::FIELD_DRESS:
case butcher_type::SKIN:
time_to_cut *= 2;
break;
case butcher_type::QUARTER:
time_to_cut /= 4;
if( time_to_cut < 1200 ) {
time_to_cut = 1200;
}
break;
case butcher_type::DISMEMBER:
time_to_cut /= 10;
if( time_to_cut < 600 ) {
time_to_cut = 600;
}
break;
case butcher_type::DISSECT:
time_to_cut *= 6;
break;
case butcher_type::NUM_TYPES:
debugmsg( "ERROR: Invalid butcher_type" );
break;
}
if( corpse_item.has_flag( flag_QUARTERED ) ) {
time_to_cut /= 4;
}
time_to_cut *= ( 1.0f - ( get_player_character().get_num_crafting_helpers( 3 ) / 10.0f ) );
return time_to_cut;
}
// this function modifies the input weight by its damage level, depending on the bodypart
static int corpse_damage_effect( int weight, const harvest_drop_type_id &entry_type,
int damage_level )
{
const float slight_damage = 0.9f;
const float damage = 0.75f;
const float high_damage = 0.5f;
const int destroyed = 0;
switch( damage_level ) {
case 2:
// "damaged"
if( entry_type == harvest_drop_offal ) {
return std::round( weight * damage );
}
if( entry_type == harvest_drop_skin ) {
return std::round( weight * damage );
}
if( entry_type == harvest_drop_flesh ) {
return std::round( weight * slight_damage );
}
break;
case 3:
// "mangled"
if( entry_type == harvest_drop_offal ) {
return destroyed;
}
if( entry_type == harvest_drop_skin ) {
return std::round( weight * high_damage );
}
if( entry_type == harvest_drop_bone ) {
return std::round( weight * slight_damage );
}
if( entry_type == harvest_drop_flesh ) {
return std::round( weight * damage );
}
break;
case 4:
// "pulped"
if( entry_type == harvest_drop_offal ) {
return destroyed;
}
if( entry_type == harvest_drop_skin ) {
return destroyed;
}
if( entry_type == harvest_drop_bone ) {
return std::round( weight * damage );
}
if( entry_type == harvest_drop_flesh ) {
return std::round( weight * high_damage );
}
break;
default:
// "bruised" modifier is almost impossible to avoid; also includes no modifier (zero damage)
break;
}
return weight;
}
static int butchery_dissect_skill_level( Character &you, int tool_quality,
const harvest_drop_type_id &htype )
{
// DISSECT has special case factor calculation and results.
if( htype.is_valid() ) {
float sk_total = 0;
int sk_count = 0;
for( const skill_id &sk : htype->get_harvest_skills() ) {
sk_total += you.get_average_skill_level( sk );
sk_count++;
}
return round( ( sk_total + tool_quality ) / ( sk_count > 0 ? sk_count : 1 ) );
}
return round( you.get_average_skill_level( skill_survival ) );
}
static int roll_butchery_dissect( int skill_level, int dex, int tool_quality )
{
double skill_shift = 0.0;
///\EFFECT_SURVIVAL randomly increases butcher rolls
skill_shift += rng_float( 0, skill_level - 3 );
///\EFFECT_DEX >8 randomly increases butcher rolls, slightly, <8 decreases
skill_shift += rng_float( 0, dex - 8 ) / 4.0;
if( tool_quality < 0 ) {
skill_shift -= rng_float( 0, -tool_quality / 5.0 );
} else {
skill_shift += std::min( tool_quality, 4 );
}
return static_cast<int>( std::round( skill_shift ) );
}
// A number between 0 and 1 that represents how much usable material can be harvested
// as a fraction of the maximum possible amount.
static double butchery_dissect_yield_mult( int skill_level, int dex, int tool_quality )
{
const double skill_score = skill_level / 10.0;
const double tool_score = ( tool_quality + 50.0 ) / 100.0;
const double dex_score = dex / 20.0;
return 0.5 * clamp( skill_score, 0.0, 1.0 ) +
0.3 * clamp( tool_score, 0.0, 1.0 ) +
0.2 * clamp( dex_score, 0.0, 1.0 );
}
static std::vector<item> create_charge_items( const itype *drop, int count,
const harvest_entry &entry, const item *corpse_item, const Character &you )
{
std::vector<item> objs;
while( count > 0 ) {
item obj( drop, calendar::turn, 1 );
obj.charges = std::min( count, 1000_liter / obj.volume() );
count -= obj.charges;
if( obj.has_temperature() ) {
obj.set_item_temperature( corpse_item->temperature );
if( obj.goes_bad() ) {
obj.set_rot( corpse_item->get_rot() );
}
}
for( const flag_id &flg : entry.flags ) {
obj.set_flag( flg );
}
for( const fault_id &flt : entry.faults ) {
obj.faults.emplace( flt );
}
if( !you.backlog.empty() && you.backlog.front().id() == ACT_MULTIPLE_BUTCHER ) {
obj.set_var( "activity_var", you.name );
}
objs.push_back( obj );
}
return objs;
}
// Returns false if the calling function should abort
static bool butchery_drops_harvest( item *corpse_item, const mtype &mt, Character &you,
butcher_type action )
{
const int tool_quality = you.max_quality( action == butcher_type::DISSECT ? qual_CUT_FINE :
qual_BUTCHER, PICKUP_RANGE );
//all BUTCHERY types - FATAL FAILURE
if( action != butcher_type::DISSECT &&
roll_butchery_dissect( round( you.get_average_skill_level( skill_survival ) ), you.dex_cur,
tool_quality ) <= ( -15 ) && one_in( 2 ) ) {
return false;
}
you.add_msg_if_player( m_neutral, mt.harvest->message() );
int monster_weight = to_gram( mt.weight );
monster_weight += std::round( monster_weight * rng_float( -0.1, 0.1 ) );
if( corpse_item->has_flag( flag_QUARTERED ) ) {
monster_weight *= 0.95;
}
if( corpse_item->has_flag( flag_GIBBED ) ) {
monster_weight = std::round( 0.85 * monster_weight );
if( action != butcher_type::FIELD_DRESS ) {
you.add_msg_if_player( m_bad,
_( "You salvage what you can from the corpse, but it is badly damaged." ) );
}
}
if( corpse_item->has_flag( flag_UNDERFED ) ) {
monster_weight = std::round( 0.9 * monster_weight );
if( action != butcher_type::FIELD_DRESS && action != butcher_type::SKIN &&
action != butcher_type::DISSECT ) {
you.add_msg_if_player( m_bad,
_( "The corpse looks a little underweight…" ) );
}
}
if( corpse_item->has_flag( flag_SKINNED ) ) {
monster_weight = std::round( 0.85 * monster_weight );
}
const int entry_count = ( action == butcher_type::DISSECT &&
!mt.dissect.is_empty() ) ? mt.dissect->get_all().size() : mt.harvest->get_all().size();
int monster_weight_remaining = monster_weight;
int practice = 0;
if( mt.harvest.is_null() ) {
debugmsg( "ERROR: %s has no harvest entry.", mt.id.c_str() );
return false;
}
if( action == butcher_type::DISSECT ) {
int dissectable_practice = 0;
int dissectable_num = 0;
for( item *item : corpse_item->all_items_top( item_pocket::pocket_type::CORPSE ) ) {
dissectable_num++;
const int skill_level = butchery_dissect_skill_level( you, tool_quality,
item->dropped_from );
const int butchery = roll_butchery_dissect( skill_level, you.dex_cur, tool_quality );
dissectable_practice += ( 4 + butchery );
int roll = butchery - corpse_item->damage_level();
roll = roll < 0 ? 0 : roll;
add_msg_debug( debugmode::DF_ACT_BUTCHER, "Roll penalty for corpse damage = %s",
0 - corpse_item->damage_level() );
butcher_dissect_item( *item, you.pos(), calendar::turn, roll );
}
if( dissectable_num > 0 ) {
practice += dissectable_practice / dissectable_num;
}
}
map &here = get_map();
for( const harvest_entry &entry : ( action == butcher_type::DISSECT &&
!mt.dissect.is_empty() ) ? *mt.dissect : *mt.harvest ) {
const int skill_level = butchery_dissect_skill_level( you, tool_quality, entry.type );
const int butchery = roll_butchery_dissect( skill_level, you.dex_cur, tool_quality );
practice += ( 4 + butchery ) / entry_count;
const float min_num = entry.base_num.first + butchery * entry.scale_num.first;
const float max_num = entry.base_num.second + butchery * entry.scale_num.second;
int roll = 0;
// mass_ratio will override the use of base_num, scale_num, and max
if( entry.mass_ratio != 0.00f ) {
roll = static_cast<int>( std::round( entry.mass_ratio * monster_weight ) );
roll = corpse_damage_effect( roll, entry.type, corpse_item->damage_level() );
} else {
roll = std::min<int>( entry.max, std::round( rng_float( min_num, max_num ) ) );
// will not give less than min_num defined in the JSON
roll = std::max<int>( corpse_damage_effect( roll, entry.type, corpse_item->damage_level() ),
entry.base_num.first );
}
itype_id drop_id = itype_id::NULL_ID();
const itype *drop = nullptr;
if( entry.type->is_itype() ) {
drop_id = itype_id( entry.drop );
drop = item::find_type( drop_id );
}
// Check if monster was gibbed, and handle accordingly
if( corpse_item->has_flag( flag_GIBBED ) && ( entry.type == harvest_drop_flesh ||
entry.type == harvest_drop_bone ) ) {
roll /= 2;
}
if( corpse_item->has_flag( flag_UNDERFED ) && ( entry.type == harvest_drop_flesh ) ) {
roll /= 1.6;
}
if( corpse_item->has_flag( flag_SKINNED ) && entry.type == harvest_drop_skin ) {
roll = 0;
}
// QUICK BUTCHERY
if( action == butcher_type::QUICK ) {
if( entry.type == harvest_drop_flesh ) {
roll /= 4;
} else if( entry.type == harvest_drop_bone ) { // NOLINT(bugprone-branch-clone)
roll /= 2;
} else if( corpse_item->get_mtype()->size >= creature_size::medium &&
entry.type == harvest_drop_skin ) {
roll /= 2;
} else if( entry.type == harvest_drop_offal ) {
roll /= 5;
} else {
continue;
}
}
// RIP AND TEAR
if( action == butcher_type::DISMEMBER ) {
if( entry.type == harvest_drop_flesh ) {
roll /= 6;
} else {
continue;
}
}
// field dressing ignores skin, flesh, and blood
if( action == butcher_type::FIELD_DRESS ) {
if( entry.type == harvest_drop_bone ) {
roll = rng( 0, roll / 2 );
}
if( entry.type == harvest_drop_flesh ) {
continue;
}
if( entry.type == harvest_drop_skin ) {
continue;
}
}
// you only get the blood from bleeding
if( action == butcher_type::BLEED ) {
if( entry.type != harvest_drop_blood ) {