-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
iexamine.cpp
6810 lines (6132 loc) · 264 KB
/
iexamine.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 "iexamine.h"
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iterator>
#include <map>
#include <memory>
#include <new>
#include <set>
#include <string>
#include <type_traits>
#include <utility>
#include "activity_actor_definitions.h"
#include "activity_type.h"
#include "ammo.h"
#include "avatar.h"
#include "basecamp.h"
#include "bionics.h"
#include "bodypart.h"
#include "calendar.h"
#include "cata_utility.h"
#include "catacharset.h"
#include "character.h"
#include "colony.h"
#include "color.h"
#include "construction.h"
#include "construction_group.h"
#include "coordinate_conversions.h"
#include "coordinates.h"
#include "craft_command.h"
#include "creature.h"
#include "creature_tracker.h"
#include "cursesdef.h"
#include "damage.h"
#include "debug.h"
#include "effect.h"
#include "enums.h"
#include "event.h"
#include "event_bus.h"
#include "field_type.h"
#include "flag.h"
#include "fungal_effects.h"
#include "game.h"
#include "game_constants.h"
#include "game_inventory.h"
#include "handle_liquid.h"
#include "harvest.h"
#include "input.h"
#include "inventory.h"
#include "item.h"
#include "item_location.h"
#include "item_stack.h"
#include "itype.h"
#include "iuse.h"
#include "iuse_actor.h"
#include "line.h"
#include "magic.h"
#include "magic_teleporter_list.h"
#include "make_static.h"
#include "map.h"
#include "map_iterator.h"
#include "map_selector.h"
#include "mapdata.h"
#include "material.h"
#include "messages.h"
#include "mission_companion.h"
#include "monster.h"
#include "morale_types.h"
#include "mtype.h"
#include "mutation.h"
#include "npc.h"
#include "options.h"
#include "output.h"
#include "overmapbuffer.h"
#include "pickup.h"
#include "pimpl.h"
#include "player_activity.h"
#include "point.h"
#include "recipe.h"
#include "requirements.h"
#include "rng.h"
#include "sounds.h"
#include "string_formatter.h"
#include "string_input_popup.h"
#include "talker.h"
#include "timed_event.h"
#include "translations.h"
#include "trap.h"
#include "try_parse_integer.h"
#include "ui.h"
#include "ui_manager.h"
#include "uistate.h"
#include "units.h"
#include "units_utility.h"
#include "value_ptr.h"
#include "vehicle.h"
#include "vehicle_selector.h"
#include "visitable.h"
#include "vpart_position.h"
#include "weather.h"
static const activity_id ACT_ATM( "ACT_ATM" );
static const activity_id ACT_BUILD( "ACT_BUILD" );
static const activity_id ACT_OPERATION( "ACT_OPERATION" );
static const activity_id ACT_PLANT_SEED( "ACT_PLANT_SEED" );
static const ammotype ammo_money( "money" );
static const bionic_id bio_lighter( "bio_lighter" );
static const bionic_id bio_lockpick( "bio_lockpick" );
static const bionic_id bio_painkiller( "bio_painkiller" );
static const character_modifier_id character_modifier_obstacle_climb_mod( "obstacle_climb_mod" );
static const efftype_id effect_antibiotic( "antibiotic" );
static const efftype_id effect_bite( "bite" );
static const efftype_id effect_bleed( "bleed" );
static const efftype_id effect_disinfected( "disinfected" );
static const efftype_id effect_earphones( "earphones" );
static const efftype_id effect_incorporeal( "incorporeal" );
static const efftype_id effect_infected( "infected" );
static const efftype_id effect_mending( "mending" );
static const efftype_id effect_pblue( "pblue" );
static const efftype_id effect_pkill2( "pkill2" );
static const efftype_id effect_sleep( "sleep" );
static const efftype_id effect_strong_antibiotic( "strong_antibiotic" );
static const efftype_id effect_strong_antibiotic_visible( "strong_antibiotic_visible" );
static const efftype_id effect_teleglow( "teleglow" );
static const efftype_id effect_tetanus( "tetanus" );
static const efftype_id effect_weak_antibiotic( "weak_antibiotic" );
static const furn_str_id furn_f_diesel_tank( "f_diesel_tank" );
static const furn_str_id furn_f_gas_tank( "f_gas_tank" );
static const furn_str_id furn_f_metal_smoking_rack( "f_metal_smoking_rack" );
static const furn_str_id furn_f_metal_smoking_rack_active( "f_metal_smoking_rack_active" );
static const furn_str_id furn_f_rope_up( "f_rope_up" );
static const furn_str_id furn_f_smoking_rack_active( "f_smoking_rack_active" );
static const furn_str_id furn_f_water_mill( "f_water_mill" );
static const furn_str_id furn_f_water_mill_active( "f_water_mill_active" );
static const furn_str_id furn_f_web_up( "f_web_up" );
static const furn_str_id furn_f_wind_mill( "f_wind_mill" );
static const furn_str_id furn_f_wind_mill_active( "f_wind_mill_active" );
static const itype_id itype_2x4( "2x4" );
static const itype_id itype_arm_splint( "arm_splint" );
static const itype_id itype_bot_broken_cyborg( "bot_broken_cyborg" );
static const itype_id itype_bot_prototype_cyborg( "bot_prototype_cyborg" );
static const itype_id itype_cash_card( "cash_card" );
static const itype_id itype_charcoal( "charcoal" );
static const itype_id itype_chem_carbide( "chem_carbide" );
static const itype_id itype_corpse( "corpse" );
static const itype_id itype_disassembly( "disassembly" );
static const itype_id itype_electrohack( "electrohack" );
static const itype_id itype_fake_milling_item( "fake_milling_item" );
static const itype_id itype_fake_smoke_plume( "fake_smoke_plume" );
static const itype_id itype_fertilizer( "fertilizer" );
static const itype_id itype_fire( "fire" );
static const itype_id itype_foodperson_mask( "foodperson_mask" );
static const itype_id itype_foodperson_mask_on( "foodperson_mask_on" );
static const itype_id itype_fungal_seeds( "fungal_seeds" );
static const itype_id itype_grapnel( "grapnel" );
static const itype_id itype_hickory_root( "hickory_root" );
static const itype_id itype_id_science( "id_science" );
static const itype_id itype_leg_splint( "leg_splint" );
static const itype_id itype_maple_sap( "maple_sap" );
static const itype_id itype_marloss_berry( "marloss_berry" );
static const itype_id itype_marloss_seed( "marloss_seed" );
static const itype_id itype_mycus_fruit( "mycus_fruit" );
static const itype_id itype_nail( "nail" );
static const itype_id itype_nanomaterial( "nanomaterial" );
static const itype_id itype_petrified_eye( "petrified_eye" );
static const itype_id itype_sheet( "sheet" );
static const itype_id itype_stick( "stick" );
static const itype_id itype_string_36( "string_36" );
static const itype_id itype_tree_spile( "tree_spile" );
static const itype_id itype_unfinished_cac2( "unfinished_cac2" );
static const itype_id itype_unfinished_charcoal( "unfinished_charcoal" );
static const json_character_flag json_flag_ATTUNEMENT( "ATTUNEMENT" );
static const json_character_flag json_flag_SUPER_HEARING( "SUPER_HEARING" );
static const json_character_flag json_flag_WALL_CLING( "WALL_CLING" );
static const json_character_flag json_flag_WEB_RAPPEL( "WEB_RAPPEL" );
static const material_id material_bone( "bone" );
static const material_id material_cac2powder( "cac2powder" );
static const material_id material_ch_steel( "ch_steel" );
static const material_id material_hc_steel( "hc_steel" );
static const material_id material_lc_steel( "lc_steel" );
static const material_id material_mc_steel( "mc_steel" );
static const material_id material_qt_steel( "qt_steel" );
static const material_id material_steel( "steel" );
static const material_id material_wood( "wood" );
static const mtype_id mon_broken_cyborg( "mon_broken_cyborg" );
static const mtype_id mon_dark_wyrm( "mon_dark_wyrm" );
static const mtype_id mon_fungal_blossom( "mon_fungal_blossom" );
static const mtype_id mon_prototype_cyborg( "mon_prototype_cyborg" );
static const mtype_id mon_spider_cellar_giant_s( "mon_spider_cellar_giant_s" );
static const mtype_id mon_spider_web_s( "mon_spider_web_s" );
static const mtype_id mon_spider_widow_giant_s( "mon_spider_widow_giant_s" );
static const npc_class_id NC_ROBOFAC_INTERCOM( "NC_ROBOFAC_INTERCOM" );
static const proficiency_id proficiency_prof_disarming( "prof_disarming" );
static const proficiency_id proficiency_prof_parkour( "prof_parkour" );
static const proficiency_id proficiency_prof_traps( "prof_traps" );
static const proficiency_id proficiency_prof_trapsetting( "prof_trapsetting" );
static const quality_id qual_ANESTHESIA( "ANESTHESIA" );
static const quality_id qual_DIG( "DIG" );
static const quality_id qual_DRILL( "DRILL" );
static const quality_id qual_HAMMER( "HAMMER" );
static const quality_id qual_LOCKPICK( "LOCKPICK" );
static const quality_id qual_PRY( "PRY" );
static const requirement_id requirement_data_anesthetic( "anesthetic" );
static const requirement_id requirement_data_autoclave( "autoclave" );
static const requirement_id requirement_data_cvd_diamond( "cvd_diamond" );
static const skill_id skill_cooking( "cooking" );
static const skill_id skill_fabrication( "fabrication" );
static const skill_id skill_survival( "survival" );
static const skill_id skill_traps( "traps" );
static const ter_str_id ter_t_diesel_pump( "t_diesel_pump" );
static const ter_str_id ter_t_diesel_pump_a( "t_diesel_pump_a" );
static const ter_str_id ter_t_gas_pump( "t_gas_pump" );
static const ter_str_id ter_t_gas_pump_a( "t_gas_pump_a" );
static const trait_id trait_AMORPHOUS( "AMORPHOUS" );
static const trait_id trait_ARACHNID_ARMS_OK( "ARACHNID_ARMS_OK" );
static const trait_id trait_BADKNEES( "BADKNEES" );
static const trait_id trait_BEAK_HUM( "BEAK_HUM" );
static const trait_id trait_BURROW( "BURROW" );
static const trait_id trait_BURROWLARGE( "BURROWLARGE" );
static const trait_id trait_DEBUG_HS( "DEBUG_HS" );
static const trait_id trait_ILLITERATE( "ILLITERATE" );
static const trait_id trait_INSECT_ARMS_OK( "INSECT_ARMS_OK" );
static const trait_id trait_M_DEFENDER( "M_DEFENDER" );
static const trait_id trait_M_DEPENDENT( "M_DEPENDENT" );
static const trait_id trait_M_FERTILE( "M_FERTILE" );
static const trait_id trait_M_SPORES( "M_SPORES" );
static const trait_id trait_NOPAIN( "NOPAIN" );
static const trait_id trait_PROBOSCIS( "PROBOSCIS" );
static const trait_id trait_PYROMANIA( "PYROMANIA" );
static const trait_id trait_SHELL2( "SHELL2" );
static const trait_id trait_SHELL3( "SHELL3" );
static const trait_id trait_THRESH_MARLOSS( "THRESH_MARLOSS" );
static const trait_id trait_THRESH_MYCUS( "THRESH_MYCUS" );
// @TODO maybe make this a property of the item (depend on volume/type)
static const time_duration milling_time = 6_hours;
/**
* Nothing player can interact with here.
*/
void iexamine::none( Character &/*p*/, const tripoint &examp )
{
add_msg( _( "That is a %s." ), get_map().name( examp ) );
}
bool iexamine::always_false( const tripoint &/*examp*/ )
{
return false;
}
bool iexamine::false_and_debugmsg( const tripoint &examp )
{
debugmsg( "Called false_and_debugmsg on %s - was a terrain with an actor configured incorrectly?",
get_map().tername( examp ) );
return false;
}
bool iexamine::always_true( const tripoint &/*examp*/ )
{
return true;
}
bool iexamine::harvestable_now( const tripoint &examp )
{
const harvest_id hid = get_map().get_harvest( examp );
return !hid->is_null() && !hid->empty();
}
/**
* Pick an appropriate item and apply diamond coating if possible.
*/
void iexamine::cvdmachine( Character &you, const tripoint & )
{
// Select an item to which it is possible to apply a diamond coating
item_location loc = g->inv_map_splice( []( const item & e ) {
return ( e.is_melee( damage_type::CUT ) || e.is_melee( damage_type::STAB ) ) &&
!e.has_flag( flag_DIAMOND ) && !e.has_flag( flag_NO_CVD ) &&
( e.made_of( material_steel ) || e.made_of( material_ch_steel ) ||
e.made_of( material_hc_steel ) || e.made_of( material_lc_steel ) ||
e.made_of( material_mc_steel ) || e.made_of( material_qt_steel ) );
}, _( "Apply diamond coating" ), 1, _( "You don't have a suitable item to coat with diamond" ) );
if( !loc ) {
return;
}
// Require materials proportional to selected item volume
auto qty = loc->volume() / units::legacy_volume_factor;
qty = std::max( 1, qty );
requirement_data reqs = *requirement_data_cvd_diamond * qty;
if( !reqs.can_make_with_inventory( you.crafting_inventory(), is_crafting_component ) ) {
popup( "%s", reqs.list_missing() );
return;
}
// Consume materials
for( const auto &e : reqs.get_components() ) {
you.consume_items( e, 1, is_crafting_component );
}
for( const auto &e : reqs.get_tools() ) {
you.consume_tools( e );
}
you.invalidate_crafting_inventory();
// Apply flag to item
loc->set_flag( flag_DIAMOND );
add_msg( m_good, _( "You apply a diamond coating to your %s" ), loc->type_name() );
you.mod_moves( -to_moves<int>( 10_seconds ) );
}
/**
* Change player eye and skin color
*/
void iexamine::change_appearance( Character &you, const tripoint & )
{
uilist amenu;
amenu.title = _( "Change what?" );
amenu.addentry( 0, true, MENU_AUTOASSIGN, _( "Change eye color" ) );
amenu.addentry( 1, true, MENU_AUTOASSIGN, _( "Change skin color" ) );
amenu.query();
if( amenu.ret == 0 ) {
you.customize_appearance( customize_appearance_choice::EYES );
} else if( amenu.ret == 1 ) {
you.customize_appearance( customize_appearance_choice::SKIN );
}
}
/**
* TEMPLATE FABRICATORS
* Generate items from found blueprints.
*/
void iexamine::nanofab( Character &you, const tripoint &examp )
{
bool table_exists = false;
std::list<item_location> on_table;
item_location nanofab_template;
tripoint spawn_point;
map &here = get_map();
std::set<itype_id> allowed_template = here.ter( examp )->allowed_template_id;
for( const tripoint &valid_location : here.points_in_radius( examp, 1 ) ) {
if( here.has_flag( ter_furn_flag::TFLAG_NANOFAB_TABLE, valid_location ) ) {
spawn_point = valid_location;
table_exists = true;
on_table = here.items_with( valid_location, [&]( const item & it ) {
return it.has_flag( flag_NANOFAB_REPAIR );
} );
break;
}
}
if( !table_exists ) {
return;
}
item new_item;
requirement_data reqs;
// If there is something on the table that can be repaired suggest to repair that instead of printing something new
if( !on_table.empty() ) {
new_item = item( on_table.front()->typeId(), calendar::turn );
int damage = on_table.front()->damage_level();
if( damage <= 0 ) {
popup( _( "FABRICATOR COMPLIANT ITEM %s DETECTED, BUT NOT DAMAGED REMOVE WORKING ITEM FROM FABRICATOR" ),
new_item.display_name() );
sounds::sound( spawn_point, 10, sounds::sound_t::speech,
_( "REMOVE WORKING ITEM FROM FABRICATOR." ), true );
return;
}
if( !on_table.front()->empty() ) {
popup( _( "ITEM %s DETECTED, CONTENTS OF ITEM WILL BE DESTROYED BY FABRICATOR PLEASE EMPTY ITEM AND RETURN" ),
new_item.display_name() );
sounds::sound( spawn_point, 10, sounds::sound_t::speech,
_( "PLEASE EMPTY ITEM AND RETURN." ), true );
return;
}
sounds::sound( spawn_point, 10, sounds::sound_t::speech,
_( "REPAIR INTEGRITY DAMAGE?" ), true );
if( !query_yn( _( "FABRICATOR COMPLIANT ITEM %s DETECTED, REPAIR INTEGRITY DAMAGE?" ),
new_item.display_name() ) ) {
return;
}
// multiplier for the item being not completely destroyed
float dam_mult = .05f * damage;
int qty = std::max( 1, static_cast<int>( dam_mult * new_item.volume() / 250_ml ) );
std::vector<std::vector<item_comp>> requirement_comp_vector;
std::vector<std::vector<quality_requirement>> quality_comp_vector;
std::vector<std::vector<tool_comp>> tool_comp_vector;
std::vector<item_comp> nano_req = { item_comp( itype_nanomaterial, 5 * qty ) };
requirement_comp_vector.push_back( nano_req );
std::vector<item_comp> item_req = { item_comp( on_table.front()->typeId(), 1 ) };
requirement_comp_vector.push_back( item_req );
reqs = requirement_data( tool_comp_vector, quality_comp_vector, requirement_comp_vector );
} else {
//Create a list of the names of all acceptable templates.
std::set<std::string> templatenames;
for( const itype_id &id : allowed_template ) {
templatenames.insert( id->nname( 1 ) );
}
std::string name_list = enumerate_as_string( templatenames );
//Template selection
nanofab_template = g->inv_map_splice( [&]( const item & e ) {
return std::any_of( allowed_template.begin(), allowed_template.end(),
[&e]( const itype_id itid ) {
return e.typeId() == itid;
} );
}, _( "Introduce a compatible template." ), PICKUP_RANGE,
_( "You don't have any usable templates.\n\nCompatible templates are: " ) + name_list );
if( !nanofab_template ) {
return;
}
new_item = item( nanofab_template->get_var( "NANOFAB_ITEM_ID" ), calendar::turn );
int qty = std::max( 1, new_item.volume() / 250_ml );
reqs = *nanofab_template->type->template_requirements * qty;
}
// either way the new item should have the nanofabricator flag
if( !new_item.has_flag( flag_NANOFAB_REPAIR ) ) {
new_item.set_flag( flag_NANOFAB_REPAIR );
}
if( !reqs.can_make_with_inventory( you.crafting_inventory(), is_crafting_component ) ) {
popup( "%s", reqs.list_missing() );
return;
}
// Consume materials
for( const auto &e : reqs.get_components() ) {
you.consume_items( e, 1, is_crafting_component );
}
for( const auto &e : reqs.get_tools() ) {
you.consume_tools( e );
}
you.invalidate_crafting_inventory();
if( new_item.is_armor() && new_item.has_flag( flag_VARSIZE ) ) {
new_item.set_flag( flag_FIT );
}
here.add_item_or_charges( spawn_point, new_item );
// if this template is single use
// also check if the template exists at all
if( nanofab_template && nanofab_template->has_flag( flag_NANOFAB_TEMPLATE_SINGLE_USE ) ) {
nanofab_template.remove_item();
}
}
/// @brief Use "gas pump."
/// @details Will pump any liquids on tile.
void iexamine::gaspump( Character &you, const tripoint &examp )
{
map &here = get_map();
if( !query_yn( _( "Use the %s?" ), here.tername( examp ) ) ) {
none( you, examp );
return;
}
map_stack items = here.i_at( examp );
for( auto item_it = items.begin(); item_it != items.end(); ++item_it ) {
if( item_it->made_of( phase_id::LIQUID ) ) {
/// @note \EFFECT_DEX decreases chance of spilling gas from a pump
if( one_in( 10 + you.get_dex() ) ) {
add_msg( m_bad, _( "You accidentally spill the %s." ), item_it->type_name() );
static const auto max_spill_volume = units::from_liter( 1 );
const int max_spill_charges = std::max( 1, item_it->charges_per_volume( max_spill_volume ) );
/// @note \EFFECT_DEX decreases amount of gas spilled, if gas is spilled from pump
const int qty = rng( 1, max_spill_charges * 8.0 / std::max( 1, you.get_dex() ) );
item spill = item_it->split( qty );
if( spill.is_null() ) {
here.add_item_or_charges( you.pos(), *item_it );
items.erase( item_it );
} else {
here.add_item_or_charges( you.pos(), spill );
}
} else {
liquid_handler::handle_liquid_from_ground( item_it, examp, 1 );
}
return;
}
}
add_msg( m_info, _( "Out of order." ) );
}
static bool has_attunement_spell_prereqs( Character &you, const trait_id &attunement )
{
// for each prereq we need to check that the player has 2 level 15 spells
for( const trait_id &prereq : attunement->prereqs ) {
int spells_known = 0;
for( const spell &sp : you.spells_known_of_class( prereq ) ) {
if( sp.get_level() >= 15 ) {
spells_known++;
}
}
if( spells_known < 2 ) {
return false;
}
}
return true;
}
void iexamine::attunement_altar( Character &you, const tripoint & )
{
std::set<trait_id> attunements;
for( const mutation_branch &mut : mutation_branch::get_all() ) {
if( mut.flags.count( json_flag_ATTUNEMENT ) ) {
attunements.emplace( mut.id );
}
}
// remove the attunements the player does not have prereqs for
for( auto iter = attunements.begin(); iter != attunements.end(); ) {
bool has_prereq = true;
// the normal usage of prereqs only needs one, but attunements put all their prereqs into the same array
// each prereqs is required for it as well
for( const trait_id &prereq : ( *iter )->prereqs ) {
if( !you.has_trait( prereq ) ) {
has_prereq = false;
break;
}
}
if( has_prereq ) {
++iter;
} else {
iter = attunements.erase( iter );
}
}
if( attunements.empty() ) {
// the player doesn't have at least two base classes
you.add_msg_if_player( _( "This altar gives you the creeps." ) );
return;
}
// remove the attunements the player has conflicts for
for( auto iter = attunements.begin(); iter != attunements.end(); ) {
if( !you.has_opposite_trait( *iter ) && you.mutation_ok( *iter, true, true, true ) ) {
++iter;
} else {
iter = attunements.erase( iter );
}
}
if( attunements.empty() ) {
you.add_msg_if_player( _( "You've attained what you can for now." ) );
return;
}
for( auto iter = attunements.begin(); iter != attunements.end(); ) {
if( has_attunement_spell_prereqs( you, *iter ) ) {
++iter;
} else {
iter = attunements.erase( iter );
}
}
if( attunements.empty() ) {
you.add_msg_if_player( _( "You feel that the altar does not deem you worthy, yet." ) );
return;
}
uilist attunement_list;
attunement_list.title = _( "Pick an Attunement to show the world your Worth." );
for( const trait_id &attunement : attunements ) {
// There's no way for you to have this mutation, so a variant is pointless
attunement_list.addentry( attunement->name() );
}
attunement_list.query();
if( attunement_list.ret == UILIST_CANCEL ) {
you.add_msg_if_player( _( "Maybe later." ) );
return;
}
auto attunement_iter = attunements.begin();
std::advance( attunement_iter, attunement_list.ret );
const trait_id &attunement = *attunement_iter;
// There's no way for you to have this mutation, so a variant is pointless
if( query_yn( string_format( _( "Are you sure you want to pick %s? This selection is permanent." ),
attunement->name() ) ) ) {
you.toggle_trait( attunement );
// There's no way for you to have this mutation, so a variant is pointless
you.add_msg_if_player( m_info, attunement->desc() );
} else {
you.add_msg_if_player( _( "Maybe later." ) );
}
}
void iexamine::translocator( Character &, const tripoint &examp )
{
/// @todo fix point types
const tripoint_abs_omt omt_loc( ms_to_omt_copy( get_map().getabs( examp ) ) );
avatar &player_character = get_avatar();
const bool activated = player_character.translocators.knows_translocator( omt_loc );
if( !activated ) {
player_character.translocators.activate_teleporter( omt_loc, examp );
add_msg( m_info, _( "Translocator gate active." ) );
} else {
if( query_yn( _( "Do you want to deactivate this active Translocator?" ) ) ) {
player_character.translocators.deactivate_teleporter( omt_loc, examp );
}
}
}
namespace
{
//--------------------------------------------------------------------------------------------------
//! Implements iexamine::atm(...)
//--------------------------------------------------------------------------------------------------
class atm_menu
{
public:
// menu choices
enum options : int {
cancel, purchase_card, deposit_money, withdraw_money, exchange_cash, transfer_all_money
};
atm_menu() = delete;
atm_menu( atm_menu const & ) = delete;
atm_menu( atm_menu && ) = delete;
atm_menu &operator=( atm_menu const & ) = delete;
atm_menu &operator=( atm_menu && ) = delete;
explicit atm_menu( Character &you ) : you( you ) {
reset( false );
}
void start() {
for( bool result = false; !result; ) {
switch( choose_option() ) {
case purchase_card:
result = do_purchase_card();
break;
case deposit_money:
result = do_deposit_money();
break;
case withdraw_money:
result = do_withdraw_money();
break;
case exchange_cash:
result = do_exchange_cash();
break;
case transfer_all_money:
result = do_transfer_all_money();
break;
default:
return;
}
if( !you.activity.is_null() ) {
break;
}
}
}
private:
void add_choice( const int i, const char *const title ) {
amenu.addentry( i, true, -1, title );
}
void add_info( const int i, const char *const title ) {
amenu.addentry( i, false, -1, title );
}
options choose_option() {
if( you.activity.id() == ACT_ATM ) {
return static_cast<options>( you.activity.index );
}
amenu.query();
uistate.iexamine_atm_selected = amenu.selected;
return amenu.ret < 0 ? cancel : static_cast<options>( amenu.ret );
}
//! Reset and repopulate the menu; with a fair bit of work this could be more efficient.
void reset( const bool clear = true ) {
const int card_count = you.amount_of( itype_cash_card );
const int charge_count = card_count ? you.charges_of( itype_cash_card ) : 0;
if( clear ) {
amenu.reset();
}
amenu.selected = uistate.iexamine_atm_selected;
amenu.text = string_format( _( "Welcome to the C.C.B.o.t.T. ATM. What would you like to do?\n"
"Your current balance is: %s" ),
format_money( you.cash ) );
if( you.cash >= 1000 ) {
add_choice( purchase_card, _( "Purchase cash card?" ) );
} else {
add_info( purchase_card, _( "You need $10.00 in your account to purchase a card." ) );
}
if( card_count && you.cash > 0 ) {
add_choice( withdraw_money, _( "Withdraw Money" ) );
} else if( you.cash > 0 ) {
add_info( withdraw_money, _( "You need a cash card before you can withdraw money!" ) );
} else if( you.cash < 0 ) {
add_info( withdraw_money,
_( "You need to pay down your debt first!" ) );
} else {
add_info( withdraw_money,
_( "You need money in your account before you can withdraw money!" ) );
}
if( charge_count ) {
add_choice( deposit_money, _( "Deposit Money" ) );
} else {
add_info( deposit_money,
_( "You need a charged cash card before you can deposit money!" ) );
}
if( card_count >= 1 && you.has_item_with_flag( flag_OLD_CURRENCY ) ) {
add_choice( exchange_cash, _( "Exchange Cash for eCash (1%% fee)" ) );
}
if( card_count >= 2 && charge_count ) {
add_choice( transfer_all_money, _( "Transfer All Money" ) );
}
}
//! print a bank statement for @p print = true;
void finish_interaction( const bool print = true ) {
if( print ) {
if( you.cash < 0 ) {
add_msg( m_info, _( "Your debt is now %s." ), format_money( you.cash ) );
} else {
add_msg( m_info, _( "Your account now holds %s." ), format_money( you.cash ) );
}
}
you.moves -= to_moves<int>( 5_seconds );
}
//! Prompt for an integral value clamped to [0, max].
static int prompt_for_amount( const char *const msg, const int max ) {
const std::string formatted = string_format( msg, max );
const int amount = string_input_popup()
.title( formatted )
.width( 20 )
.text( std::to_string( max ) )
.only_digits( true )
.query_int();
return clamp( amount, 0, max );
}
//!Get a new cash card. $10.00 fine.
bool do_purchase_card() {
const char *prompt =
_( "This will automatically deduct $10.00 from your bank account. Continue?" );
if( !query_yn( prompt ) ) {
return false;
}
item card( "cash_card", calendar::turn );
card.ammo_set( card.ammo_default(), 0 );
you.i_add( card );
you.cash -= 1000;
you.moves -= to_moves<int>( 5_seconds );
finish_interaction();
return true;
}
//!Deposit money from cash card into bank account.
bool do_deposit_money() {
int money = you.charges_of( itype_cash_card );
if( !money ) {
popup( _( "You can only deposit money from charged cash cards!" ) );
return false;
}
const int amount = prompt_for_amount( n_gettext(
"Deposit how much? Max: %d cent. (0 to cancel) ",
"Deposit how much? Max: %d cents. (0 to cancel) ", money ), money );
if( !amount ) {
return false;
}
add_msg( m_info, _( "You deposit %s into your account." ), format_money( amount ) );
you.use_charges( itype_cash_card, amount );
you.cash += amount;
you.moves -= to_moves<int>( 10_seconds );
finish_interaction();
return true;
}
//!Move money from bank account onto cash card.
bool do_withdraw_money() {
std::vector<item *> cash_cards_on_hand = you.items_with( []( const item & i ) {
return i.typeId() == itype_cash_card;
} );
if( cash_cards_on_hand.empty() ) {
//Just in case we run into an edge case
popup( _( "You do not have a cash card to withdraw money!" ) );
return false;
}
const int amount = prompt_for_amount( n_gettext(
"Withdraw how much? Max: %d cent. (0 to cancel) ",
"Withdraw how much? Max: %d cents. (0 to cancel) ", you.cash ), you.cash );
if( !amount ) {
return false;
}
int inserted = 0;
int remaining = amount;
std::sort( cash_cards_on_hand.begin(), cash_cards_on_hand.end(), []( item * one, item * two ) {
int balance_one = one->ammo_remaining();
int balance_two = two->ammo_remaining();
return balance_one > balance_two;
} );
for( item * const &cc : cash_cards_on_hand ) {
if( inserted == amount ) {
break;
}
int max_cap = cc->ammo_capacity( ammo_money ) - cc->ammo_remaining();
int to_insert = std::min( max_cap, remaining );
// insert whatever there's room for + the old balance.
cc->ammo_set( cc->ammo_default(), to_insert + cc->ammo_remaining() );
inserted += to_insert;
remaining -= to_insert;
}
if( remaining ) {
add_msg( m_info, _( "All cash cards at maximum capacity." ) );
}
//dst->charges += amount;
you.cash -= amount - remaining;
you.moves -= to_moves<int>( 10_seconds );
finish_interaction();
return true;
}
//!Deposit pre-Cataclysm currency and receive equivalent amount minus fees on a card.
bool do_exchange_cash() {
item *dst;
if( you.activity.id() == ACT_ATM ) {
dst = you.activity.targets.front().get_item();
you.activity.set_to_null();
if( dst->is_null() || dst->typeId() != itype_cash_card ) {
debugmsg( "do_exchange_cash lost the destination card" );
return false;
}
} else {
const std::vector<item *> cash_cards = you.items_with( []( const item & i ) {
return i.typeId() == itype_cash_card;
} );
if( cash_cards.empty() ) {
popup( _( "You do not have a cash card." ) );
return false;
}
dst = *std::max_element( cash_cards.begin(), cash_cards.end(), []( const item * a,
const item * b ) {
return a->ammo_remaining() < b->ammo_remaining();
} );
if( !query_yn( _( "Exchange all paper bills and coins in inventory?" ) ) ) {
return false;
}
}
item *cash_item = nullptr;
you.visit_items( [&]( item * e, const item * ) {
if( e->type->has_flag( flag_OLD_CURRENCY ) ) {
cash_item = e;
return VisitResponse::ABORT;
}
return VisitResponse::NEXT;
} );
if( !cash_item ) {
return false;
}
// Feeding a bill into the machine takes at least one turn
you.moves -= std::max( 100, you.moves );
int value = units::to_cent( cash_item->type->price );
value *= 0.99; // subtract fee
if( value > dst->ammo_capacity( ammo_money ) - dst->ammo_remaining() ) {
popup( _( "Destination card is full." ) );
return false;
}
if( cash_item->charges > 1 ) {
cash_item->charges--;
} else {
item_location( you, cash_item ).remove_item();
}
dst->ammo_set( dst->ammo_default(), dst->ammo_remaining() + value );
you.assign_activity( ACT_ATM, 0, exchange_cash );
you.activity.targets.emplace_back( you, dst );
return true;
}
//!Move the money from all the cash cards in inventory to a single card.
bool do_transfer_all_money() {
item *dst;
std::vector<item *> cash_cards_on_hand = you.items_with( []( const item & i ) {
return i.typeId() == itype_cash_card;
} );
if( you.activity.id() == ACT_ATM ) {
dst = you.activity.targets.front().get_item();
you.activity.set_to_null(); // stop for now, if required, it will be created again.
if( dst->is_null() || dst->typeId() != itype_cash_card ) {
debugmsg( "do_transfer_all_money lost the destination card" );
return false;
}
} else {
if( cash_cards_on_hand.empty() ) {
return false;
}
dst = cash_cards_on_hand.front();
}
for( item *i : cash_cards_on_hand ) {
if( i == dst || i->ammo_remaining() <= 0 || i->typeId() != itype_cash_card ) {
continue;
}
if( you.moves < 0 ) {
// Money from `*i` could be transferred, but we're out of moves, schedule it for
// the next turn. Putting this here makes sure there will be something to be
// done next turn.
you.assign_activity( ACT_ATM, 0, transfer_all_money );
you.activity.targets.emplace_back( you, dst );
break;
}
// should we check for max capacity here?
if( i->ammo_remaining() > dst->ammo_capacity( ammo_money ) - dst->ammo_remaining() ) {
popup( _( "Destination card is full." ) );
return false;
}
dst->ammo_set( dst->ammo_default(), i->ammo_remaining() + dst->ammo_remaining() );
i->ammo_set( i->ammo_default(), 0 );
you.moves -= 10;
}
return true;
}
Character &you;
uilist amenu;
};
} //namespace
/**
* launches the atm menu class which then handles all the atm interactions.
*/
void iexamine::atm( Character &you, const tripoint & )
{
atm_menu {you}.start();
}
/**
* Generates vending machine UI and allows players to purchase contained items with a cash card.
*/
void iexamine::vending( Character &you, const tripoint &examp )
{
constexpr int moves_cost = to_moves<int>( 5_seconds );
int money = you.charges_of( itype_cash_card );
map_stack vend_items = get_map().i_at( examp );
if( vend_items.empty() ) {
add_msg( m_info, _( "The vending machine is empty." ) );
return;
}
if( !money ) {
popup( _( "You need some money on a cash card to buy things." ) );
}
int w_items_w = 0;
int w_info_w = 0;
int list_lines = 0;