-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
activity_handlers.cpp
3132 lines (2784 loc) · 118 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 "action.h"
#include "catalua.h"
#include "clzones.h"
#include "construction.h"
#include "craft_command.h"
#include "debug.h"
#include "fault.h"
#include "field.h"
#include "game.h"
#include "gates.h"
#include "harvest.h"
#include "iexamine.h"
#include "itype.h"
#include "iuse_actor.h"
#include "map.h"
#include "map_iterator.h"
#include "mapdata.h"
#include "martialarts.h"
#include "messages.h"
#include "mongroup.h"
#include "morale_types.h"
#include "mtype.h"
#include "output.h"
#include "player.h"
#include "requirements.h"
#include "rng.h"
#include "skill.h"
#include "sounds.h"
#include "string_formatter.h"
#include "translations.h"
#include "ui.h"
#include "veh_interact.h"
#include "vehicle.h"
#include "vpart_position.h"
#include "map_selector.h"
#include <algorithm>
#include <cmath>
#define dbg(x) DebugLog((DebugLevel)(x),D_GAME) << __FILE__ << ":" << __LINE__ << ": "
const skill_id skill_survival( "survival" );
const skill_id skill_firstaid( "firstaid" );
const skill_id skill_electronics( "electronics" );
const species_id HUMAN( "HUMAN" );
const species_id ZOMBIE( "ZOMBIE" );
const efftype_id effect_milked( "milked" );
const efftype_id effect_sleep( "sleep" );
using namespace activity_handlers;
const std::map< activity_id, std::function<void( player_activity *, player * )> >
activity_handlers::do_turn_functions = {
{ activity_id( "ACT_BURROW" ), burrow_do_turn },
{ activity_id( "ACT_CRAFT" ), craft_do_turn },
{ activity_id( "ACT_LONGCRAFT" ), craft_do_turn },
{ activity_id( "ACT_FILL_LIQUID" ), fill_liquid_do_turn },
{ activity_id( "ACT_PICKAXE" ), pickaxe_do_turn },
{ activity_id( "ACT_DROP" ), drop_do_turn },
{ activity_id( "ACT_STASH" ), stash_do_turn },
{ activity_id( "ACT_PULP" ), pulp_do_turn },
{ activity_id( "ACT_GAME" ), game_do_turn },
{ activity_id( "ACT_START_FIRE" ), start_fire_do_turn },
{ activity_id( "ACT_VIBE" ), vibe_do_turn },
{ activity_id( "ACT_OXYTORCH" ), oxytorch_do_turn },
{ activity_id( "ACT_AIM" ), aim_do_turn },
{ activity_id( "ACT_PICKUP" ), pickup_do_turn },
{ activity_id( "ACT_MOVE_ITEMS" ), move_items_do_turn },
{ activity_id( "ACT_MOVE_LOOT" ), move_loot_do_turn },
{ activity_id( "ACT_ADV_INVENTORY" ), adv_inventory_do_turn },
{ activity_id( "ACT_ARMOR_LAYERS" ), armor_layers_do_turn },
{ activity_id( "ACT_ATM" ), atm_do_turn },
{ activity_id( "ACT_CRACKING" ), cracking_do_turn },
{ activity_id( "ACT_REPAIR_ITEM" ), repair_item_do_turn },
{ activity_id( "ACT_BUTCHER" ), butcher_do_turn },
{ activity_id( "ACT_BUTCHER_FULL" ), butcher_do_turn },
{ activity_id( "ACT_FIELD_DRESS" ), butcher_do_turn },
{ activity_id( "ACT_QUARTER" ), butcher_do_turn },
{ activity_id( "ACT_DISSECT" ), butcher_do_turn },
{ activity_id( "ACT_HACKSAW" ), hacksaw_do_turn },
{ activity_id( "ACT_CHOP_TREE" ), chop_tree_do_turn },
{ activity_id( "ACT_CHOP_LOGS" ), chop_tree_do_turn },
{ activity_id( "ACT_JACKHAMMER" ), jackhammer_do_turn },
{ activity_id( "ACT_DIG" ), dig_do_turn },
{ activity_id( "ACT_FILL_PIT" ), fill_pit_do_turn },
{ activity_id( "ACT_TILL_PLOT" ), till_plot_do_turn },
{ activity_id( "ACT_PLANT_PLOT" ), plant_plot_do_turn },
{ activity_id( "ACT_TRY_SLEEP" ), try_sleep_do_turn }
};
const std::map< activity_id, std::function<void( player_activity *, player * )> >
activity_handlers::finish_functions = {
{ activity_id( "ACT_BURROW" ), burrow_finish },
{ activity_id( "ACT_BUTCHER" ), butcher_finish },
{ activity_id( "ACT_BUTCHER_FULL" ), butcher_finish },
{ activity_id( "ACT_FIELD_DRESS" ), butcher_finish },
{ activity_id( "ACT_QUARTER" ), butcher_finish },
{ activity_id( "ACT_DISSECT" ), butcher_finish },
{ activity_id( "ACT_FIRSTAID" ), firstaid_finish },
{ activity_id( "ACT_FISH" ), fish_finish },
{ activity_id( "ACT_FORAGE" ), forage_finish },
{ activity_id( "ACT_HOTWIRE_CAR" ), hotwire_finish },
{ activity_id( "ACT_LONGSALVAGE" ), longsalvage_finish },
{ activity_id( "ACT_MAKE_ZLAVE" ), make_zlave_finish },
{ activity_id( "ACT_PICKAXE" ), pickaxe_finish },
{ activity_id( "ACT_PICKUP" ), pickup_finish },
{ activity_id( "ACT_RELOAD" ), reload_finish },
{ activity_id( "ACT_START_FIRE" ), start_fire_finish },
{ activity_id( "ACT_TRAIN" ), train_finish },
{ activity_id( "ACT_VEHICLE" ), vehicle_finish },
{ activity_id( "ACT_START_ENGINES" ), start_engines_finish },
{ activity_id( "ACT_OXYTORCH" ), oxytorch_finish },
{ activity_id( "ACT_CRACKING" ), cracking_finish },
{ activity_id( "ACT_OPEN_GATE" ), open_gate_finish },
{ activity_id( "ACT_REPAIR_ITEM" ), repair_item_finish },
{ activity_id( "ACT_MEND_ITEM" ), mend_item_finish },
{ activity_id( "ACT_GUNMOD_ADD" ), gunmod_add_finish },
{ activity_id( "ACT_TOOLMOD_ADD" ), toolmod_add_finish },
{ activity_id( "ACT_CLEAR_RUBBLE" ), clear_rubble_finish },
{ activity_id( "ACT_MEDITATE" ), meditate_finish },
{ activity_id( "ACT_READ" ), read_finish },
{ activity_id( "ACT_WAIT" ), wait_finish },
{ activity_id( "ACT_WAIT_WEATHER" ), wait_weather_finish },
{ activity_id( "ACT_WAIT_NPC" ), wait_npc_finish },
{ activity_id( "ACT_TRY_SLEEP" ), try_sleep_finish },
{ activity_id( "ACT_CRAFT" ), craft_finish },
{ activity_id( "ACT_LONGCRAFT" ), longcraft_finish },
{ activity_id( "ACT_DISASSEMBLE" ), disassemble_finish },
{ activity_id( "ACT_BUILD" ), build_finish },
{ activity_id( "ACT_VIBE" ), vibe_finish },
{ activity_id( "ACT_MOVE_ITEMS" ), move_items_finish },
{ activity_id( "ACT_MOVE_LOOT" ), move_loot_finish },
{ activity_id( "ACT_ATM" ), atm_finish },
{ activity_id( "ACT_AIM" ), aim_finish },
{ activity_id( "ACT_WASH" ), washing_finish },
{ activity_id( "ACT_HACKSAW" ), hacksaw_finish },
{ activity_id( "ACT_CHOP_TREE" ), chop_tree_finish },
{ activity_id( "ACT_CHOP_LOGS" ), chop_logs_finish },
{ activity_id( "ACT_JACKHAMMER" ), jackhammer_finish },
{ activity_id( "ACT_DIG" ), dig_finish },
{ activity_id( "ACT_FILL_PIT" ), fill_pit_finish },
{ activity_id( "ACT_SHAVE" ), shaving_finish },
{ activity_id( "ACT_HAIRCUT" ), haircut_finish }
};
void messages_in_process( const player_activity &act, const player &p )
{
if( act.moves_left <= 91000 && act.moves_left > 89000 ) {
p.add_msg_if_player( m_info, _( "You figure it'll take about an hour and a half at this rate." ) );
return;
}
if( act.moves_left <= 61000 && act.moves_left > 59000 ) {
p.add_msg_if_player( m_info, _( "About an hour left to go." ) );
return;
}
if( act.moves_left <= 31000 && act.moves_left > 29000 ) {
p.add_msg_if_player( m_info, _( "Shouldn't be more than half an hour or so now!" ) );
return;
}
if( act.moves_left <= 11000 && act.moves_left > 9000 ) {
p.add_msg_if_player( m_info, _( "Almost there! Ten more minutes of work and you'll be through." ) );
return;
}
}
void activity_handlers::burrow_do_turn( player_activity *act, player *p )
{
if( calendar::once_every( 1_minutes ) ) {
//~ Sound of a Rat mutant burrowing!
sounds::sound( act->placement, 10, sounds::sound_t::movement,
_( "ScratchCrunchScrabbleScurry." ) );
messages_in_process( *act, *p );
}
}
void activity_handlers::burrow_finish( player_activity *act, player *p )
{
const tripoint &pos = act->placement;
if( g->m.is_bashable( pos ) && g->m.has_flag( "SUPPORTS_ROOF", pos ) &&
g->m.ter( pos ) != t_tree ) {
// Tunneling through solid rock is hungry, sweaty, tiring, backbreaking work
// Not quite as bad as the pickaxe, though
p->mod_hunger( 10 );
p->mod_thirst( 10 );
p->mod_fatigue( 15 );
p->mod_pain( 3 * rng( 1, 3 ) );
} else if( g->m.move_cost( pos ) == 2 && g->get_levz() == 0 &&
g->m.ter( pos ) != t_dirt && g->m.ter( pos ) != t_grass ) {
//Breaking up concrete on the surface? not nearly as bad
p->mod_hunger( 5 );
p->mod_thirst( 5 );
p->mod_fatigue( 10 );
}
p->add_msg_if_player( m_good, _( "You finish burrowing." ) );
g->m.destroy( pos, true );
act->set_to_null();
}
bool check_butcher_cbm( const int roll )
{
// 2/3 chance of failure with a roll of 0, 2/6 with a roll of 1, 2/9 etc.
// The roll is usually b/t 0 and first_aid-3, so first_aid 4 will succeed
// 50%, first_aid 5 will succeed 61%, first_aid 6 will succeed 67%, etc.
bool failed = x_in_y( 2, 3 + roll * 3 );
return !failed;
}
void butcher_cbm_item( const std::string &what, const tripoint &pos,
const time_point &age, const int roll )
{
if( roll < 0 ) {
return;
}
item cbm( check_butcher_cbm( roll ) ? what : "burnt_out_bionic", age );
add_msg( m_good, _( "You discover a %s!" ), cbm.tname().c_str() );
g->m.add_item( pos, cbm );
}
void butcher_cbm_group( const std::string &group, const tripoint &pos,
const time_point &age, const int roll )
{
if( roll < 0 ) {
return;
}
//To see if it spawns a random additional CBM
if( check_butcher_cbm( roll ) ) {
//The CBM works
const auto spawned = g->m.put_items_from_loc( group, pos, age );
for( const auto &it : spawned ) {
add_msg( m_good, _( "You discover a %s!" ), it->tname().c_str() );
}
} else {
//There is a burnt out CBM
item cbm( "burnt_out_bionic", age );
add_msg( m_good, _( "You discover a %s!" ), cbm.tname().c_str() );
g->m.add_item( pos, cbm );
}
}
void set_up_butchery( player_activity &act, player &u, butcher_type action )
{
if( !act.values.empty() ) {
act.index = act.values.back();
act.values.pop_back();
} else {
debugmsg( "Invalid butchery item index %d", act.index );
act.set_to_null();
return;
}
int factor = u.max_quality( action == DISSECT ? quality_id( "CUT_FINE" ) :
quality_id( "BUTCHER" ) );
auto items = g->m.i_at( u.pos() );
if( static_cast<size_t>( act.index ) >= items.size() ) {
// Let it print a msg for lack of corpses
act.index = INT_MAX;
return;
}
item corpse_item = items[act.index];
const mtype *corpse_ptr = corpse_item.get_mtype();
if( corpse_ptr == nullptr ) {
debugmsg( "Tried to butcher a non-corpse item, %s",
corpse_item.tname( corpse_item.count() ) );
act.set_to_null();
return;
}
const mtype &corpse = *corpse_ptr;
if( action != DISSECT ) {
if( factor == INT_MIN ) {
u.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 ) ) {
u.add_msg_if_player( m_bad,
_( "You don't trust the quality of your tools, but carry on anyway." ) );
}
}
if( action == DISSECT ) {
switch( factor ) {
case INT_MIN:
u.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:
u.add_msg_if_player( m_info, _( "You could use a better tool, but this will do." ) );
break;
case 2:
u.add_msg_if_player( m_info, _( "This tool is great, but you still would like a scalpel." ) );
break;
case 3:
u.add_msg_if_player( m_info, _( "You dissect the corpse with a trusty scalpel." ) );
break;
}
}
bool has_table_nearby = false;
for( const tripoint &pt : g->m.points_in_radius( u.pos(), 2 ) ) {
if( g->m.has_flag_furn( "FLAT_SURF", pt ) || g->m.has_flag( "FLAT_SURF", pt ) ||
( g->m.veh_at( pt ) && g->m.veh_at( pt )->vehicle().has_part( "KITCHEN" ) ) ) {
has_table_nearby = true;
}
}
bool has_tree_nearby = false;
for( const tripoint &pt : g->m.points_in_radius( u.pos(), 2 ) ) {
if( g->m.has_flag( "TREE", pt ) ) {
has_tree_nearby = true;
}
}
// workshop butchery (full) prequisites
if( action == BUTCHER_FULL ) {
bool has_rope = u.has_amount( "rope_30", 1 ) || u.has_amount( "rope_makeshift_30", 1 ) ||
u.has_amount( "vine_30", 1 ) ;
bool b_rack_present = g->m.has_flag_furn( "BUTCHER_EQ", u.pos() );
bool big_corpse = corpse.size >= MS_MEDIUM;
if( big_corpse && has_rope && !has_tree_nearby && !b_rack_present ) {
u.add_msg_if_player( m_info,
_( "You need to suspend this corpse to butcher it, you have a rope to lift the corpse but there is no tree nearby." ) );
act.index = -1;
return;
} else if( big_corpse && !has_rope && !b_rack_present ) {
u.add_msg_if_player( m_info,
_( "For a corpse this big you need a rope and a nearby tree or a butchering rack to perform a full butchery." ) );
act.index = -1;
return;
}
if( big_corpse && !has_table_nearby ) {
u.add_msg_if_player( m_info,
_( "For a corpse this big you need a table nearby or something else with a flat surface to perform a full butchery." ) );
act.index = -1;
return;
}
if( !u.has_quality( quality_id( "CUT" ) ) ) {
u.add_msg_if_player( m_info, _( "You need a cutting tool to perform a full butchery." ) );
act.index = -1;
return;
}
if( big_corpse && !( u.has_quality( quality_id( "SAW_W" ) ) ||
u.has_quality( quality_id( "SAW_M" ) ) ) ) {
u.add_msg_if_player( m_info,
_( "For a corpse this big you need a saw to perform a full butchery." ) );
act.index = -1;
return;
}
}
if( action == DISSECT && ( corpse_item.has_flag( "QUARTERED" ) ||
corpse_item.has_flag( "FIELD_DRESS_FAILED" ) ) ) {
u.add_msg_if_player( m_info,
_( "It would be futile to search for implants inside this badly damaged corpse." ) );
act.index = -1;
return;
}
if( action == F_DRESS && ( corpse_item.has_flag( "FIELD_DRESS" ) ||
corpse_item.has_flag( "FIELD_DRESS_FAILED" ) ) ) {
u.add_msg_if_player( m_info, _( "This corpse is already field dressed." ) );
act.index = -1;
return;
}
if( action == QUARTER ) {
if( corpse.size == MS_TINY ) {
u.add_msg_if_player( m_bad, _( "This corpse is too small to quarter without damaging." ),
corpse.nname().c_str() );
act.index = -1;
return;
}
if( corpse_item.has_flag( "QUARTERED" ) ) {
u.add_msg_if_player( m_bad, _( "This is already quartered." ), corpse.nname().c_str() );
act.index = -1;
return;
}
if( !( corpse_item.has_flag( "FIELD_DRESS" ) || corpse_item.has_flag( "FIELD_DRESS_FAILED" ) ) ) {
u.add_msg_if_player( m_bad, _( "You need to perform field dressing before quartering." ),
corpse.nname().c_str() );
act.index = -1;
return;
}
}
// applies to all butchery actions
bool is_human = corpse.id == mtype_id::NULL_ID() || ( corpse.in_species( HUMAN ) &&
!corpse.in_species( ZOMBIE ) );
if( is_human && !( u.has_trait_flag( "CANNIBAL" ) || u.has_trait_flag( "PSYCHOPATH" ) ||
u.has_trait_flag( "SAPIOVORE" ) ) ) {
if( query_yn( _( "Would you dare desecrate the mortal remains of a fellow human being?" ) ) ) {
g->u.add_morale( MORALE_BUTCHER, -50, 0, 2_days, 3_hours );
switch( rng( 1, 3 ) ) {
case 1:
u.add_msg_if_player( m_bad, _( "You clench your teeth at the prospect of this gruesome job." ) );
break;
case 2:
u.add_msg_if_player( m_bad, _( "This will haunt you in your dreams." ) );
break;
case 3:
u.add_msg_if_player( m_bad,
_( "You try to look away, but this gruesome image will stay on your mind for some time." ) );
break;
}
} else {
u.add_msg_if_player( m_good, _( "It needs a coffin, not a knife." ) );
act.index = -1;
return;
}
}
act.moves_left = butcher_time_to_cut( u, corpse_item, action );
}
int butcher_time_to_cut( const player &u, const item &corpse_item, const butcher_type action )
{
const mtype &corpse = *corpse_item.get_mtype();
const int factor = u.max_quality( action == DISSECT ? quality_id( "CUT_FINE" ) :
quality_id( "BUTCHER" ) );
int time_to_cut = 0;
switch( corpse.size ) {
// Time (roughly) in turns to cut up the corpse
case MS_TINY:
time_to_cut = 25;
break;
case MS_SMALL:
time_to_cut = 50;
break;
case MS_MEDIUM:
time_to_cut = 75;
break;
case MS_LARGE:
time_to_cut = 100;
break;
case MS_HUGE:
time_to_cut = 300;
break;
}
// At factor 0, 10 time_to_cut is 10 turns. At factor 50, it's 5 turns, at 75 it's 2.5
time_to_cut *= std::max( 25, 100 - factor );
if( time_to_cut < 500 ) {
time_to_cut = 500;
}
switch( action ) {
case BUTCHER:
break;
case BUTCHER_FULL:
if( !corpse_item.has_flag( "FIELD_DRESS" ) || corpse_item.has_flag( "FIELD_DRESS_FAILED" ) ) {
time_to_cut *= 6;
} else {
time_to_cut *= 4;
}
break;
case F_DRESS:
time_to_cut *= 2;
break;
case QUARTER:
time_to_cut /= 4;
if( time_to_cut < 200 ) {
time_to_cut = 200;
}
break;
case DISSECT:
time_to_cut *= 6;
break;
}
if( corpse_item.has_flag( "QUARTERED" ) ) {
time_to_cut /= 4;
}
return time_to_cut;
}
void butchery_drops_hardcoded( item *corpse_item, const mtype *corpse, player *p,
const time_point &age, const std::function<int()> &roll_butchery, butcher_type action )
{
itype_id meat = corpse->get_meat_itype();
int pieces = corpse->get_meat_chunks_count();
int skins = 0;
int bones = 0;
int fats = pieces / 5;
int sinews = 0;
int feathers = 0;
int wool = 0;
bool stomach = false;
int max_practice = 4;
switch( corpse->size ) {
case MS_TINY:
skins = 1;
bones = 1;
fats = 1;
sinews = 1;
feathers = 4;
wool = 1;
break;
case MS_SMALL:
skins = 2;
bones = 8;
sinews = 4;
feathers = 12;
wool = 4;
break;
case MS_MEDIUM:
skins = 5;
bones = 18;
sinews = 9;
feathers = 22;
wool = 8;
break;
case MS_LARGE:
skins = 10;
bones = 28;
sinews = 14;
feathers = 36;
wool = 16;
max_practice = 5;
break;
case MS_HUGE:
skins = 20;
bones = 42;
sinews = 21;
feathers = 48;
wool = 32;
max_practice = 6;
break;
}
if( corpse->made_of( material_id( "bone" ) ) ) {
//For butchering yield purposes, we treat it as bones, not meat
meat = "null";
bones += pieces / 4;
pieces = 0;
}
// Lose some meat, skins, etc if the rolls are low
pieces += std::min( 0, roll_butchery() );
skins += std::min( 0, roll_butchery() - 4 );
bones += std::min( 0, roll_butchery() - 2 );
fats += std::min( 0, roll_butchery() - 4 );
sinews += std::min( 0, roll_butchery() - 8 );
feathers += std::min( 0, roll_butchery() - 1 );
wool += std::min( 0, roll_butchery() );
stomach = roll_butchery() >= 0;
// (QUICK) BUTCHERY
if( action == BUTCHER && ( !corpse_item->has_flag( "FIELD_DRESS" ) ||
!corpse_item->has_flag( "FIELD_DRESS_FAILED" ) ) ) {
pieces /= 4;
if( corpse->size >= MS_MEDIUM ) {
skins /= 2;
}
bones /= 2;
fats /= 4;
sinews /= 4;
// feathers unchanged
wool /= 4;
stomach = false;
} else if( action == BUTCHER ) {
stomach = roll_butchery() >= 0;
}
//FIELD DRESSING
if( action == F_DRESS ) {
// "pieces" left unchanged because they are 'converted' to offal and don't yield meat
skins = 0;
bones = rng( 0, bones / 2 );
fats = 0;
sinews = 0;
feathers = 0;
wool = 0;
stomach = roll_butchery() >= 0;
}
// field dressing removed innards and bones from meatless limbs
if( action == BUTCHER_FULL && corpse_item->has_flag( "FIELD_DRESS" ) ) {
stomach = false;
bones = ( bones / 2 ) + rng( bones / 2, bones );
}
// unskillfull field dressing damaged the skin, meat, and other parts
if( action == BUTCHER_FULL && corpse_item->has_flag( "FIELD_DRESS_FAILED" ) ) {
pieces = rng( 0, pieces );
skins = rng( 0, skins );
bones = ( bones / 2 ) + rng( bones / 2, bones );
fats = rng( 0, fats );
feathers = rng( 0, feathers );
wool = rng( 0, wool );
stomach = false;
}
if( corpse_item->has_flag( "QUARTERED" ) ) {
pieces /= 4;
skins = 0; //quartering ruins skin
bones /= 4;
fats /= 4;
sinews /= 4;
feathers /= 4;
wool /= 4;
}
if( action == DISSECT ) {
pieces = 0;
skins = 0;
bones = 0;
fats = 0;
sinews = 0;
feathers = 0;
wool = 0;
stomach = false;
}
int practice = std::max( 0, 4 + pieces + roll_butchery() );
if( action == DISSECT ) {
p->practice( skill_firstaid, practice, max_practice );
} else {
p->practice( skill_survival, practice, max_practice );
}
if( bones > 0 ) {
if( corpse->made_of( material_id( "veggy" ) ) ) {
g->m.spawn_item( p->pos(), "plant_sac", bones, 0, age );
p->add_msg_if_player( m_good, _( "You harvest some fluid bladders!" ) );
} else if( corpse->has_flag( MF_BONES ) && corpse->has_flag( MF_POISON ) ) {
g->m.spawn_item( p->pos(), "bone_tainted", bones / 2, 0, age );
p->add_msg_if_player( m_good, _( "You harvest some salvageable bones!" ) );
} else if( corpse->has_flag( MF_BONES ) && corpse->has_flag( MF_HUMAN ) ) {
g->m.spawn_item( p->pos(), "bone_human", bones, 0, age );
p->add_msg_if_player( m_good, _( "You harvest some salvageable bones!" ) );
} else if( corpse->has_flag( MF_BONES ) ) {
g->m.spawn_item( p->pos(), "bone", bones, 0, age );
p->add_msg_if_player( m_good, _( "You harvest some usable bones!" ) );
}
} else if( meat == "null" && corpse->has_flag( MF_BONES ) ) {
//print a failure message only if the corpse doesn't have meat and has bones
p->add_msg_if_player( m_bad, _( "Your clumsy butchering destroys the bones!" ) );
}
if( sinews > 0 ) {
if( corpse->has_flag( MF_BONES ) && !corpse->has_flag( MF_POISON ) ) {
g->m.spawn_item( p->pos(), "sinew", sinews, 0, age );
p->add_msg_if_player( m_good, _( "You harvest some usable sinews!" ) );
} else if( corpse->made_of( material_id( "veggy" ) ) ) {
g->m.spawn_item( p->pos(), "plant_fibre", sinews, 0, age );
p->add_msg_if_player( m_good, _( "You harvest some plant fibers!" ) );
}
}
if( stomach ) {
const itype_id meat = corpse->get_meat_itype();
if( meat == "meat" ) {
if( corpse->size == MS_SMALL || corpse->size == MS_MEDIUM ) {
g->m.spawn_item( p->pos(), "stomach", 1, 0, age );
p->add_msg_if_player( m_good, _( "You harvest the stomach!" ) );
} else if( corpse->size == MS_LARGE || corpse->size == MS_HUGE ) {
g->m.spawn_item( p->pos(), "stomach_large", 1, 0, age );
p->add_msg_if_player( m_good, _( "You harvest the stomach!" ) );
}
} else if( meat == "human_flesh" ) {
if( corpse->size == MS_SMALL || corpse->size == MS_MEDIUM ) {
g->m.spawn_item( p->pos(), "hstomach", 1, 0, age );
p->add_msg_if_player( m_good, _( "You harvest the stomach!" ) );
} else if( corpse->size == MS_LARGE || corpse->size == MS_HUGE ) {
g->m.spawn_item( p->pos(), "hstomach_large", 1, 0, age );
p->add_msg_if_player( m_good, _( "You harvest the stomach!" ) );
}
}
}
if( ( corpse->has_flag( MF_FUR ) || corpse->has_flag( MF_LEATHER ) ||
corpse->has_flag( MF_CHITIN ) ) && skins > 0 ) {
p->add_msg_if_player( m_good, _( "You manage to skin the %s!" ), corpse->nname().c_str() );
int fur = 0;
int tainted_fur = 0;
int leather = 0;
int tainted_leather = 0;
int human_leather = 0;
int chitin = 0;
while( skins > 0 ) {
if( corpse->has_flag( MF_CHITIN ) ) {
chitin = rng( 0, skins );
skins -= chitin;
skins = std::max( skins, 0 );
}
if( corpse->has_flag( MF_FUR ) ) {
if( corpse->has_flag( MF_POISON ) ) {
tainted_fur = rng( 0, skins );
skins -= tainted_fur;
} else {
fur = rng( 0, skins );
skins -= fur;
}
skins = std::max( skins, 0 );
}
if( corpse->has_flag( MF_LEATHER ) ) {
if( corpse->has_flag( MF_POISON ) ) {
tainted_leather = rng( 0, skins );
skins -= tainted_leather;
} else if( corpse->has_flag( MF_HUMAN ) ) {
human_leather = rng( 0, skins );
skins -= human_leather;
} else {
leather = rng( 0, skins );
skins -= leather;
}
skins = std::max( skins, 0 );
}
}
if( chitin > 0 ) {
g->m.spawn_item( p->pos(), "chitin_piece", chitin, 0, age );
}
if( fur > 0 ) {
g->m.spawn_item( p->pos(), "raw_fur", fur, 0, age );
}
if( tainted_fur > 0 ) {
g->m.spawn_item( p->pos(), "raw_tainted_fur", fur, 0, age );
}
if( leather > 0 ) {
g->m.spawn_item( p->pos(), "raw_leather", leather, 0, age );
}
if( human_leather > 0 ) {
g->m.spawn_item( p->pos(), "raw_hleather", leather, 0, age );
}
if( tainted_leather > 0 ) {
g->m.spawn_item( p->pos(), "raw_tainted_leather", leather, 0, age );
}
}
if( feathers > 0 ) {
if( corpse->has_flag( MF_FEATHER ) ) {
g->m.spawn_item( p->pos(), "feather", feathers, 0, age );
p->add_msg_if_player( m_good, _( "You harvest some feathers!" ) );
}
}
if( wool > 0 ) {
if( corpse->has_flag( MF_WOOL ) ) {
g->m.spawn_item( p->pos(), "wool_staple", wool, 0, age );
p->add_msg_if_player( m_good, _( "You harvest some wool staples!" ) );
}
}
if( fats > 0 ) {
if( corpse->has_flag( MF_FAT ) && corpse->has_flag( MF_POISON ) ) {
g->m.spawn_item( p->pos(), "fat_tainted", fats, 0, age );
p->add_msg_if_player( m_good, _( "You harvest some gooey fat!" ) );
} else if( corpse->has_flag( MF_FAT ) ) {
g->m.spawn_item( p->pos(), "fat", fats, 0, age );
p->add_msg_if_player( m_good, _( "You harvest some fat!" ) );
}
}
//Add a chance of CBM recovery.
//As long as the factor is above -4 (the sinew cutoff), you will be able to extract CBMs
if( action == DISSECT ) {
if( corpse->has_flag( MF_CBM_CIV ) ) {
butcher_cbm_item( "bio_power_storage", p->pos(), age, roll_butchery() );
butcher_cbm_group( "bionics_common", p->pos(), age, roll_butchery() );
}
// Zombie scientist bionics
if( corpse->has_flag( MF_CBM_SCI ) ) {
butcher_cbm_item( "bio_power_storage", p->pos(), age, roll_butchery() );
butcher_cbm_group( "bionics_sci", p->pos(), age, roll_butchery() );
}
// Zombie technician bionics
if( corpse->has_flag( MF_CBM_TECH ) ) {
butcher_cbm_item( "bio_power_storage", p->pos(), age, roll_butchery() );
butcher_cbm_group( "bionics_tech", p->pos(), age, roll_butchery() );
}
// Substation mini-boss bionics
if( corpse->has_flag( MF_CBM_SUBS ) ) {
butcher_cbm_item( "bio_power_storage", p->pos(), age, roll_butchery() );
butcher_cbm_group( "bionics_subs", p->pos(), age, roll_butchery() );
butcher_cbm_group( "bionics_subs", p->pos(), age, roll_butchery() );
}
// Payoff for butchering the zombie bio-op
if( corpse->has_flag( MF_CBM_OP ) ) {
butcher_cbm_item( "bio_power_storage_mkII", p->pos(), age, roll_butchery() );
butcher_cbm_group( "bionics_op", p->pos(), age, roll_butchery() );
}
//Add a chance of CBM power storage recovery.
if( corpse->has_flag( MF_CBM_POWER ) ) {
butcher_cbm_item( "bio_power_storage", p->pos(), age, roll_butchery() );
}
}
// feedback that this type of corpse has implants that can be potentialy removed
if( corpse->has_flag( MF_CBM_CIV ) || corpse->has_flag( MF_CBM_SCI ) ||
corpse->has_flag( MF_CBM_TECH ) ||
corpse->has_flag( MF_CBM_SUBS ) || corpse->has_flag( MF_CBM_OP ) ||
corpse->has_flag( MF_CBM_POWER ) ) {
if( action == F_DRESS ) {
p->add_msg_if_player( m_bad,
_( "You suspect there might be bionics implanted in this corpse, that careful dissection might reveal." ) );
}
if( action == BUTCHER || action == BUTCHER_FULL ) {
switch( rng( 1, 3 ) ) {
case 1:
p->add_msg_if_player( m_bad,
_( "Your butchering tool encounters something implanted in this corpse, but your rough cuts destroy it." ) );
break;
case 2:
p->add_msg_if_player( m_bad,
_( "You find traces of implants in the body, but you care only for the flesh." ) );
break;
case 3:
p->add_msg_if_player( m_bad,
_( "You found some bionics in the body, but harvesting them would require more surgical approach." ) );
break;
}
}
}
//now handle the meat, if there is any
if( meat != "null" ) {
if( pieces <= 0 ) {
if( action == BUTCHER || action == BUTCHER_FULL ) {
p->add_msg_if_player( m_bad, _( "Your clumsy butchering destroys the flesh!" ) );
}
} else {
if( action == BUTCHER || action == BUTCHER_FULL ) {
p->add_msg_if_player( m_good, _( "You harvest some flesh." ) );
}
item chunk( meat, age, 1 );
chunk.set_mtype( corpse );
item parts( "offal", age, 0 );
parts.set_mtype( corpse );
// for now don't drop tainted or cannibal. parts overhaul of taint system to not require excessive item duplication
// also field dressing removed innards so no offal
bool make_offal = !chunk.is_tainted() && !chunk.has_flag( "CANNIBALISM" ) &&
!( corpse_item->has_flag( "FIELD_DRESS" ) || corpse_item->has_flag( "FIELD_DRESS_FAILED" ) ) &&
!chunk.made_of( material_id( "veggy" ) );
if( action == F_DRESS ) {
for( int i = 1; i < pieces; ++i ) {
if( make_offal && one_in( 3 ) ) {
parts.charges++;
}
}
chunk.charges = 0;
} else {
for( int i = 1; i < pieces; ++i ) {
if( make_offal && one_in( 6 ) ) {
parts.charges++;
} else {
chunk.charges++;
}
}
}
if( chunk.charges > 0 ) {
g->m.add_item_or_charges( p->pos(), chunk );
}
if( parts.charges > 0 ) {
g->m.add_item_or_charges( p->pos(), parts );
}
}
}
}
void butchery_drops_harvest( item *corpse_item, const mtype &mt, player &p, const time_point &age,
const std::function<int()> &roll_butchery, butcher_type action )
{
p.add_msg_if_player( m_neutral, _( mt.harvest->message().c_str() ) );
int practice = 4 + roll_butchery();
for( const auto &entry : *mt.harvest ) {
int butchery = roll_butchery();
float min_num = entry.base_num.first + butchery * entry.scale_num.first;
float max_num = entry.base_num.second + butchery * entry.scale_num.second;
int roll = std::min<int>( entry.max, round( rng_float( min_num, max_num ) ) );
const itype *drop = item::find_type( entry.drop );
// BIONIC handling - no code for DISSECT to let the bionic drop fall through
if( drop->bionic.has_value() ) {
if( action == F_DRESS ) {
p.add_msg_if_player( m_bad,
_( "You suspect there might be bionics implanted in this corpse, that careful dissection might reveal." ) );
continue;
}
if( action == BUTCHER || action == BUTCHER_FULL ) {
switch( rng( 1, 3 ) ) {
case 1:
p.add_msg_if_player( m_bad,
_( "Your butchering tool encounters something implanted in this corpse, but your rough cuts destroy it." ) );
break;
case 2:
p.add_msg_if_player( m_bad,
_( "You find traces of implants in the body, but you care only for the flesh." ) );
break;
case 3:
p.add_msg_if_player( m_bad,
_( "You found some bionics in the body, but harvesting them would require more surgical approach." ) );
break;
}
continue;
}
} else if( action == DISSECT ) {
continue;
}
// QUICK BUTCHERY
if( action == BUTCHER ) {
if( entry.drop == "meat" || entry.drop == "meat_tainted" || entry.drop == "fish" ||
entry.drop == "veggy" || entry.drop == "veggy_tainted" || entry.drop == "scrap" ||
entry.drop == "wool_staple" || entry.drop == "fat" || entry.drop == "fat_tainted" ) {
roll = roll / 4;
} else if( entry.drop != "bone" ) {
roll = roll / 2;
} else if( corpse_item->get_mtype()->size >= MS_MEDIUM && ( entry.drop == "raw_fur" ||
entry.drop == "raw_leather" ||
entry.drop == "raw_tainted_fur" || entry.drop == "raw_tainted_leather" ||
entry.drop == "raw_hleather" || entry.drop == "chitin_piece" ||
entry.drop == "acidchitin_piece" ) ) {
roll /= 2 ;
} else {
continue;
}
}
// field dressing ignores everything outside below list
if( action == F_DRESS ) {
if( entry.drop != "bone" ) {
roll = rng( 0, roll / 2 );
}
if( entry.drop == "fat" || entry.drop == "fat_tainted" || entry.drop == "meat" ||
entry.drop == "meat_tainted" || entry.drop == "fish" ||
entry.drop == "feathers" || entry.drop == "raw_fur" || entry.drop == "raw_leather" ||
entry.drop == "raw_tainted_fur" || entry.drop == "raw_tainted_leather" ||
entry.drop == "raw_hleather" || entry.drop == "wool_staple" || entry.drop == "chitin_piece" ||
entry.drop == "acidchitin_piece" || entry.drop == "veggy" || entry.drop == "veggy tainted" ||
entry.drop == "brain" ) {
continue;
}
}
// field dressing removed innards and bones from meatless limbs
if( ( action == BUTCHER_FULL ) && corpse_item->has_flag( "FIELD_DRESS" ) ) {
if( entry.drop == "stomach" || entry.drop == "stomach_large" ||
entry.drop == "hstomach" || entry.drop == "hstomach_large" ||
entry.drop == "offal" || entry.drop == "plant_sac" ||
entry.drop == "liver" || entry.drop == "kidney" ||
entry.drop == "lung" || entry.drop == "sweetbread" ) {
continue;
}
if( entry.drop == "bone" ) {
roll = ( roll / 2 ) + rng( roll / 2, roll );
}
}
// unskillfull field dressing may damage the skin, meat, and other parts
if( ( action == BUTCHER_FULL ) && corpse_item->has_flag( "FIELD_DRESS_FAILED" ) ) {
if( entry.drop == "stomach" || entry.drop == "stomach_large" ||
entry.drop == "hstomach" || entry.drop == "hstomach_large" ||
entry.drop == "offal" ) {
continue;
}
if( entry.drop == "bone" || entry.drop == "bone_human" ) {
roll = ( roll / 2 ) + rng( roll / 2, roll );
}
if( entry.drop == "fat" || entry.drop == "fat_tainted" || entry.drop == "meat" ||
entry.drop == "meat_tainted" || entry.drop == "fish" ||
entry.drop == "feathers" || entry.drop == "raw_fur" || entry.drop == "raw_leather" ||
entry.drop == "raw_tainted_fur" || entry.drop == "raw_tainted_leather" ||
entry.drop == "raw_hleather" || entry.drop == "wool_staple" || entry.drop == "chitin_piece" ||
entry.drop == "acidchitin_piece" || entry.drop == "veggy" || entry.drop == "veggy tainted" ) {
roll = rng( 0, roll );
}
}
// quartering ruins skin
if( corpse_item->has_flag( "QUARTERED" ) ) {
if( entry.drop == "feathers" || entry.drop == "raw_fur" || entry.drop == "raw_leather" ||
entry.drop == "raw_hleather" || entry.drop == "wool_staple" ||
entry.drop == "raw_tainted_leather" || entry.drop == "chitin_piece" ||
entry.drop == "acidchitin_piece" ) {
roll = 0; //not continue to show fail effect
} else {
roll /= 4;
}
}
if( roll <= 0 ) {