/
iexamine.cpp
4339 lines (3882 loc) · 156 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 "ammo.h"
#include "basecamp.h"
#include "bionics.h"
#include "calendar.h"
#include "cata_utility.h"
#include "catacharset.h"
#include "compatibility.h" // needed for the workaround for the std::to_string bug in some compilers
#include "coordinate_conversions.h"
#include "craft_command.h"
#include "debug.h"
#include "event.h"
#include "fungal_effects.h"
#include "game.h"
#include "harvest.h"
#include "input.h"
#include "inventory.h"
#include "line.h"
#include "map.h"
#include "map_iterator.h"
#include "mapdata.h"
#include "material.h"
#include "messages.h"
#include "monster.h"
#include "mtype.h"
#include "iuse_actor.h"
#include "npc.h"
#include "options.h"
#include "output.h"
#include "player.h"
#include "requirements.h"
#include "rng.h"
#include "sounds.h"
#include "string_formatter.h"
#include "string_input_popup.h"
#include "translations.h"
#include "trap.h"
#include "ui.h"
#include "uistate.h"
#include "units.h"
#include "vpart_position.h"
#include "weather.h"
#include <algorithm>
#include <cstdlib>
#include <sstream>
const mtype_id mon_dark_wyrm( "mon_dark_wyrm" );
const mtype_id mon_fungal_blossom( "mon_fungal_blossom" );
const mtype_id mon_spider_web_s( "mon_spider_web_s" );
const mtype_id mon_spider_widow_giant_s( "mon_spider_widow_giant_s" );
const mtype_id mon_spider_cellar_giant_s( "mon_spider_cellar_giant_s" );
const mtype_id mon_turret( "mon_turret" );
const mtype_id mon_turret_rifle( "mon_turret_rifle" );
const skill_id skill_computer( "computer" );
const skill_id skill_fabrication( "fabrication" );
const skill_id skill_electronics( "electronics" );
const skill_id skill_firstaid( "firstaid" );
const skill_id skill_mechanics( "mechanics" );
const skill_id skill_cooking( "cooking" );
const skill_id skill_survival( "survival" );
const efftype_id effect_pkill2( "pkill2" );
const efftype_id effect_teleglow( "teleglow" );
const efftype_id effect_sleep( "sleep" );
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_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_PARKOUR( "PARKOUR" );
static const trait_id trait_THRESH_MARLOSS( "THRESH_MARLOSS" );
static const trait_id trait_THRESH_MYCUS( "THRESH_MYCUS" );
static const trait_id trait_BURROW( "BURROW" );
static void pick_plant( player &p, const tripoint &examp, const std::string &itemType, ter_id new_ter,
bool seeds = false );
/**
* Nothing player can interact with here.
*/
void iexamine::none(player &p, const tripoint &examp)
{
(void)p; //unused
add_msg(_("That is a %s."), g->m.name(examp).c_str());
}
/**
* Pick an appropriate item and apply diamond coating if possible.
*/
void iexamine::cvdmachine( player &p, const tripoint & ) {
// Select an item to which it is possible to apply a diamond coating
auto loc = g->inv_map_splice( []( const item &e ) {
return ( e.is_melee( DT_CUT ) || e.is_melee( DT_STAB ) ) && e.made_of( material_id( "steel" ) ) &&
!e.has_flag( "DIAMOND" ) && !e.has_flag( "NO_CVD" );
}, _( "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 );
auto reqs = *requirement_id( "cvd_diamond" ) * qty;
if( !reqs.can_make_with_inventory( p.crafting_inventory() ) ) {
popup( "%s", reqs.list_missing().c_str() );
return;
}
// Consume materials
for( const auto& e : reqs.get_components() ) {
p.consume_items( e );
}
for( const auto& e : reqs.get_tools() ) {
p.consume_tools( e );
}
p.invalidate_crafting_inventory();
// Apply flag to item
loc->item_tags.insert( "DIAMOND" );
add_msg( m_good, _( "You apply a diamond coating to your %s" ), loc->type_name().c_str() );
p.mod_moves( -1000 );
}
/**
* Use "gas pump." Will pump any liquids on tile.
*/
void iexamine::gaspump(player &p, const tripoint &examp)
{
if (!query_yn(_("Use the %s?"), g->m.tername(examp).c_str())) {
none(p, examp);
return;
}
auto items = g->m.i_at( examp );
for( auto item_it = items.begin(); item_it != items.end(); ++item_it ) {
if( item_it->made_of(LIQUID) ) {
///\EFFECT_DEX decreases chance of spilling gas from a pump
if( one_in(10 + p.get_dex()) ) {
add_msg(m_bad, _("You accidentally spill the %s."), item_it->type_name().c_str());
static const auto max_spill_volume = units::from_liter( 1 );
const long max_spill_charges = std::max( 1l, item_it->charges_per_volume( max_spill_volume ) );
///\EFFECT_DEX decreases amount of gas spilled from a pump
const int qty = rng( 1l, max_spill_charges * 8.0 / std::max( 1, p.get_dex() ) );
item spill = item_it->split( qty );
if( spill.is_null() ) {
g->m.add_item_or_charges( p.pos(), *item_it );
items.erase( item_it );
} else {
g->m.add_item_or_charges( p.pos(), spill );
}
} else {
g->handle_liquid_from_ground( item_it, examp, 1 );
}
return;
}
}
add_msg(m_info, _("Out of order."));
}
namespace {
//--------------------------------------------------------------------------------------------------
//! Implements iexamine::atm(...)
//--------------------------------------------------------------------------------------------------
class atm_menu {
public:
// menu choices
enum options : int {
cancel, purchase_card, deposit_money, withdraw_money, 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(player &p) : u(p) {
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 transfer_all_money: result = do_transfer_all_money(); break;
default:
return;
}
if( !u.activity.is_null() ) {
break;
}
g->draw();
}
}
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( u.activity.id() == activity_id( "ACT_ATM" ) ) {
return static_cast<options>( u.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 = u.amount_of("cash_card");
const int charge_count = card_count ? u.charges_of("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( u.cash ) );
if (u.cash >= 100) {
add_choice(purchase_card, _("Purchase cash card?"));
} else {
add_info(purchase_card, _("You need $1.00 in your account to purchase a card."));
}
if (card_count && u.cash > 0) {
add_choice(withdraw_money, _("Withdraw Money") );
} else if (u.cash > 0) {
add_info(withdraw_money, _("You need a cash card before you can withdraw money!"));
} 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 >= 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) {
add_msg(m_info, _("Your account now holds %s."), format_money(u.cash));
}
u.moves -= 100;
}
//! Prompt for an integral value clamped to [0, max].
static long prompt_for_amount(const char *const msg, const long max) {
const std::string formatted = string_format(msg, max);
const long amount = string_input_popup()
.title( formatted )
.width( 20 )
.text( to_string( max ) )
.only_digits( true )
.query_long();
return (amount > max) ? max : (amount <= 0) ? 0 : amount;
}
//!Get a new cash card. $1.00 fine.
bool do_purchase_card() {
const char *prompt = _("This will automatically deduct $1.00 from your bank account. Continue?");
if (!query_yn(prompt)) {
return false;
}
item card("cash_card", calendar::turn);
card.charges = 0;
u.i_add(card);
u.cash -= 100;
u.moves -= 100;
finish_interaction();
return true;
}
//!Deposit money from cash card into bank account.
bool do_deposit_money() {
long money = u.charges_of( "cash_card" );
if (!money) {
popup(_("You can only deposit money from charged cash cards!"));
return false;
}
const int amount = prompt_for_amount(ngettext(
"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, "amount: %d", amount );
u.use_charges( "cash_card", amount );
u.cash += amount;
u.moves -= 100;
finish_interaction();
return true;
}
//!Move money from bank account onto cash card.
bool do_withdraw_money() {
int pos = u.inv.position_by_type( "cash_card" );
item *dst = &u.i_at( pos );
const int amount = prompt_for_amount(ngettext(
"Withdraw how much? Max: %d cent. (0 to cancel) ",
"Withdraw how much? Max: %d cents. (0 to cancel) ", u.cash), u.cash);
if (!amount) {
return false;
}
dst->charges += amount;
u.cash -= amount;
u.moves -= 100;
finish_interaction();
return true;
}
//!Move the money from all the cash cards in inventory to a single card.
bool do_transfer_all_money() {
item *dst;
if( u.activity.id() == activity_id( "ACT_ATM" ) ) {
u.activity.set_to_null(); // stop for now, if required, it will be created again.
dst = &u.i_at( u.activity.position );
if( dst->is_null() || dst->typeId() != "cash_card" ) {
return false;
}
} else {
const int pos = u.inv.position_by_type( "cash_card" );
if( pos == INT_MIN ) {
return false;
}
dst = &u.i_at( pos );
}
for (auto &i : u.inv_dump()) {
if( i == dst || i->charges <= 0 || i->typeId() != "cash_card" ) {
continue;
}
if( u.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.
u.assign_activity( activity_id( "ACT_ATM" ), 0, transfer_all_money, u.get_item_position( dst ) );
break;
}
dst->charges += i->charges;
i->charges = 0;
u.moves -= 10;
}
return true;
}
player &u;
uilist amenu;
};
} //namespace
/**
* launches the atm menu class which then handles all the atm interactions.
*/
void iexamine::atm(player &p, const tripoint& )
{
atm_menu {p}.start();
}
/**
* Generates vending machine UI and allows players to purchase contained items with a cash card.
*/
void iexamine::vending( player &p, const tripoint &examp )
{
constexpr int moves_cost = 250;
long money = p.charges_of( "cash_card" );
auto vend_items = g->m.i_at( examp );
if( vend_items.empty() ) {
add_msg( m_info, _( "The vending machine is empty!" ) );
return;
} else if( !money ) {
popup( _( "You need a charged cash card to purchase things!" ) );
return;
}
const int padding_x = std::max( 0, TERMX - FULL_SCREEN_WIDTH ) / 4;
const int padding_y = std::max( 0, TERMY - FULL_SCREEN_HEIGHT ) / 6;
const int window_h = FULL_SCREEN_HEIGHT + std::max( 0, TERMY - FULL_SCREEN_HEIGHT ) * 2 / 3;
const int window_w = FULL_SCREEN_WIDTH + std::max( 0, TERMX - FULL_SCREEN_WIDTH ) / 2;
const int w_items_w = window_w / 2;
const int w_info_w = window_w - w_items_w;
const int list_lines = window_h - 4; // minus for header and footer
constexpr int first_item_offset = 3; // header size
catacurses::window const w = catacurses::newwin( window_h, w_items_w, padding_y, padding_x );
catacurses::window const w_item_info = catacurses::newwin( window_h, w_info_w, padding_y,
padding_x + w_items_w );
bool used_machine = false;
input_context ctxt( "VENDING_MACHINE" );
ctxt.register_updown();
ctxt.register_action( "CONFIRM" );
ctxt.register_action( "QUIT" );
ctxt.register_action( "HELP_KEYBINDINGS" );
// Collate identical items.
// First, build a map {item::tname} => {item_it, item_it, item_it...}
using iterator_t = decltype( std::begin( vend_items ) ); // map_stack::iterator doesn't exist.
std::map<std::string, std::vector<iterator_t>> item_map;
for( auto it = std::begin( vend_items ); it != std::end( vend_items ); ++it ) {
// |# {name}|
// 123 4
item_map[utf8_truncate( it->tname(), static_cast<size_t>( w_items_w - 4 ) )].push_back( it );
}
// Next, put pointers to the pairs in the map in a vector to allow indexing.
std::vector<std::map<std::string, std::vector<iterator_t>>::value_type *> item_list;
item_list.reserve( item_map.size() );
for( auto &pair : item_map ) {
item_list.emplace_back( &pair );
}
const int lines_above = list_lines / 2; // lines above the selector
const int lines_below = list_lines / 2 + list_lines % 2; // lines below the selector
int cur_pos = 0;
for( ;; ) {
const int num_items = item_list.size();
const int page_size = std::min( num_items, list_lines );
werase( w );
wborder( w, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX,
LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX );
mvwhline( w, first_item_offset - 1, 1, LINE_OXOX, w_items_w - 2 );
mvwaddch( w, first_item_offset - 1, 0, LINE_XXXO ); // |-
mvwaddch( w, first_item_offset - 1, w_items_w - 1, LINE_XOXX ); // -|
trim_and_print( w, 1, 2, w_items_w - 3, c_light_gray,
_( "Money left: %s" ), format_money( money ) );
// Keep the item selector centered in the page.
int page_beg = 0;
int page_end = page_size;
if( cur_pos < num_items - cur_pos ) {
page_beg = std::max( 0, cur_pos - lines_above );
page_end = std::min( num_items, page_beg + list_lines );
} else {
page_end = std::min( num_items, cur_pos + lines_below );
page_beg = std::max( 0, page_end - list_lines );
}
for( int line = 0; line < page_size; ++line ) {
const int i = page_beg + line;
const auto color = (i == cur_pos) ? h_light_gray : c_light_gray;
const auto &elem = item_list[i];
const int count = elem->second.size();
const char c = (count < 10) ? ('0' + count) : '*';
trim_and_print(w, first_item_offset + line, 1, w_items_w-3, color, "%c %s", c, elem->first.c_str());
}
draw_scrollbar(w, cur_pos, list_lines, num_items, first_item_offset);
wrefresh(w);
// Item info
auto &cur_items = item_list[static_cast<size_t>(cur_pos)]->second;
auto &cur_item = cur_items.back();
werase(w_item_info);
// | {line}|
// 12 3
fold_and_print(w_item_info, 1, 2, w_info_w - 3, c_light_gray, cur_item->info(true));
wborder(w_item_info, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX,
LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX );
//+<{name}>+
//12 34
const std::string name = utf8_truncate(cur_item->display_name(), static_cast<size_t>(w_info_w - 4));
mvwprintw(w_item_info, 0, 1, "<%s>", name.c_str());
wrefresh(w_item_info);
const std::string &action = ctxt.handle_input();
if (action == "DOWN") {
cur_pos = (cur_pos + 1) % num_items;
} else if (action == "UP") {
cur_pos = (cur_pos + num_items - 1) % num_items;
} else if (action == "CONFIRM") {
const int iprice = cur_item->price( false );
if ( iprice > money ) {
popup(_("That item is too expensive!"));
continue;
}
if( !used_machine ) {
used_machine = true;
p.moves -= moves_cost;
}
money -= iprice;
p.use_charges( "cash_card", iprice );
p.i_add_or_drop( *cur_item );
vend_items.erase( cur_item );
cur_items.pop_back();
if( !cur_items.empty() ) {
continue;
}
item_list.erase( std::begin( item_list ) + cur_pos );
if( item_list.empty() ) {
add_msg( _( "With a beep, the empty vending machine shuts down" ) );
return;
} else if( cur_pos == num_items - 1 ) {
cur_pos--;
}
} else if( action == "QUIT" ) {
break;
}
}
}
/**
* If there's water, allow its usage but add chance of poison.
*/
void iexamine::toilet(player &p, const tripoint &examp)
{
auto items = g->m.i_at(examp);
auto water = items.begin();
for( ; water != items.end(); ++water ) {
if( water->typeId() == "water") {
break;
}
}
if( water == items.end() ) {
add_msg(m_info, _("This toilet is empty."));
} else if( !water->made_of( LIQUID ) ) {
add_msg( m_info, _( "The toilet water is frozen solid!" ) );
} else {
// Use a different poison value each time water is drawn from the toilet.
water->poison = one_in(3) ? 0 : rng(1, 3);
(void) p; // @todo: use me
g->handle_liquid_from_ground( water, examp );
}
}
/**
* If underground, move 2 levels up else move 2 levels down. Stable movement between levels 0 and -2.
*/
void iexamine::elevator(player &p, const tripoint &examp)
{
(void)p; //unused
if (!query_yn(_("Use the %s?"), g->m.tername(examp).c_str())) {
return;
}
int movez = (examp.z < 0 ? 2 : -2);
g->vertical_move( movez, false );
}
/**
* Open gate.
*/
void iexamine::controls_gate(player &p, const tripoint &examp)
{
if (!query_yn(_("Use the %s?"), g->m.tername( examp ).c_str())) {
none( p, examp );
return;
}
g->open_gate( examp );
}
/**
* Use id/hack reader. Using an id despawns turrets.
*/
void iexamine::cardreader( player &p, const tripoint &examp )
{
bool open = false;
itype_id card_type = ( g->m.ter(examp) == t_card_science ? "id_science" :
"id_military" );
if( p.has_amount( card_type, 1 ) && query_yn( _( "Swipe your ID card?" ) ) ) {
p.mod_moves( -100 );
for( const tripoint &tmp : g->m.points_in_radius( examp, 3 ) ) {
if( g->m.ter( tmp ) == t_door_metal_locked ) {
g->m.ter_set( tmp, t_floor );
open = true;
}
}
for( monster &critter : g->all_monsters() ) {
// Check 1) same overmap coords, 2) turret, 3) hostile
if( ms_to_omt_copy(g->m.getabs(critter.pos())) == ms_to_omt_copy(g->m.getabs(examp)) &&
( critter.type->id == mon_turret ||
critter.type->id == mon_turret_rifle ) &&
critter.attitude_to( p ) == Creature::Attitude::A_HOSTILE ) {
g->remove_zombie( critter );
}
}
if( open ) {
add_msg( _( "You insert your ID card." ) );
add_msg( m_good, _( "The nearby doors slide into the floor." ) );
p.use_amount( card_type, 1 );
} else {
add_msg( _( "The nearby doors are already opened." ) );
}
} else {
switch( hack_attempt( p ) ) {
case HACK_FAIL:
g->m.ter_set( examp, t_card_reader_broken );
break;
case HACK_NOTHING:
add_msg( _( "Nothing happens." ) );
break;
case HACK_SUCCESS:
{
add_msg( _( "You activate the panel!" ) );
add_msg( m_good, _( "The nearby doors slide into the floor." ) );
g->m.ter_set( examp, t_card_reader_broken );
for( const tripoint &tmp : g->m.points_in_radius( examp, 3 ) ) {
if( g->m.ter( tmp ) == t_door_metal_locked ) {
g->m.ter_set( tmp, t_floor );
}
}
}
break;
case HACK_UNABLE:
add_msg(
m_info,
p.get_skill_level( skill_computer ) > 0 ?
_( "Looks like you need a %s, or a tool to hack it with." ) :
_( "Looks like you need a %s." ),
item::nname( card_type ).c_str()
);
break;
}
}
}
/**
* Prompt removal of rubble. Select best shovel and invoke "CLEAR_RUBBLE" on tile.
*/
void iexamine::rubble(player &p, const tripoint &examp)
{
int moves;
if( p.has_quality( quality_id( "DIG" ), 3 ) || p.has_trait( trait_BURROW ) ) {
moves = 1250;
} else if( p.has_quality( quality_id( "DIG" ), 2 ) ) {
moves = 2500;
} else {
add_msg( m_info, _("If only you had a shovel...") );
return;
}
if( ( g->m.veh_at( examp ) || !g->m.tr_at( examp ).is_null() ||
g->critter_at( examp ) != nullptr ) &&
!query_yn(_("Clear up that %s?"), g->m.furnname( examp ).c_str() ) ) {
return;
}
p.assign_activity( activity_id( "ACT_CLEAR_RUBBLE" ), moves, -1, 0 );
p.activity.placement = examp;
return;
}
/**
* Try to pry crate open with crowbar.
*/
void iexamine::crate(player &p, const tripoint &examp)
{
// Check for a crowbar in the inventory
bool has_prying_tool = p.crafting_inventory().has_quality( quality_id( "PRY" ), 1 );
if( !has_prying_tool ) {
add_msg( m_info, _("If only you had a crowbar...") );
return;
}
// Ask if there's something possibly more interesting than this crate here
// Shouldn't happen (what kind of creature lives in a crate?), but better safe than getting complaints
std::string xname = g->m.furnname(examp);
if( ( g->m.veh_at( examp ) ||
!g->m.tr_at( examp ).is_null() ||
g->critter_at( examp ) != nullptr ) &&
!query_yn(_("Pry that %s?"), xname.c_str() ) ) {
none( p, examp );
return;
}
// HACK ALERT: player::items_with returns const item* vector and so can't be used
// so we'll be making a fake crowbar here
// Not a problem for now, but if crowbar iuse-s ever get different, this will need a fix
item fakecrow( "crowbar", 0 );
iuse dummy;
dummy.crowbar( &p, &fakecrow, false, examp );
}
/**
* Prompt climbing over fence. Calculates move cost, applies it to player and, moves them.
*/
void iexamine::chainfence( player &p, const tripoint &examp )
{
// Skip prompt if easy to climb.
if( !g->m.has_flag( "CLIMB_SIMPLE", examp ) ) {
if( !query_yn( _( "Climb %s?" ), g->m.tername( examp ).c_str() ) ) {
none( p, examp );
return;
}
}
if ( g->m.has_flag( "CLIMB_SIMPLE", examp ) && p.has_trait( trait_PARKOUR ) ) {
add_msg( _( "You vault over the obstacle with ease." ) );
p.moves -= 100; // Not tall enough to warrant spider-climbing, so only relevant trait.
} else if ( g->m.has_flag( "CLIMB_SIMPLE", examp ) ) {
add_msg( _( "You vault over the obstacle." ) );
p.moves -= 300; // Most common move cost for barricades pre-change.
} else if( p.has_trait( trait_ARACHNID_ARMS_OK ) && !p.wearing_something_on( bp_torso ) ) {
add_msg( _( "Climbing this obstacle is trivial for one such as you." ) );
p.moves -= 75; // Yes, faster than walking. 6-8 limbs are impressive.
} else if( p.has_trait( trait_INSECT_ARMS_OK ) && !p.wearing_something_on( bp_torso ) ) {
add_msg( _( "You quickly scale the fence." ) );
p.moves -= 90;
} else if( p.has_trait( trait_PARKOUR ) ) {
add_msg( _( "This obstacle is no match for your freerunning abilities." ) );
p.moves -= 100;
} else {
p.moves -= 400;
///\EFFECT_DEX decreases chances of slipping while climbing
int climb = p.dex_cur;
if (p.has_trait( trait_BADKNEES )) {
climb = climb / 2;
}
if( one_in( climb ) ) {
add_msg( m_bad, _( "You slip while climbing and fall down again." ) );
if( climb <= 1 ) {
add_msg( m_bad, _( "Climbing this obstacle is impossible in your current state." ) );
}
return;
}
p.moves += climb * 10;
sfx::play_variant_sound( "plmove", "clear_obstacle", sfx::get_heard_volume(g->u.pos()) );
}
if( p.in_vehicle ) {
g->m.unboard_vehicle( p.pos() );
}
p.setpos( examp );
if( examp.x < SEEX * int( MAPSIZE / 2 ) || examp.y < SEEY * int( MAPSIZE / 2 ) ||
examp.x >= SEEX * ( 1 + int( MAPSIZE / 2 ) ) || examp.y >= SEEY * ( 1 + int( MAPSIZE / 2 ) ) ) {
if( p.is_player() ) {
g->update_map( p );
}
}
}
/**
* If player has amorphous trait, slip through the bars.
*/
void iexamine::bars(player &p, const tripoint &examp)
{
if(!(p.has_trait(trait_AMORPHOUS))) {
none( p, examp );
return;
}
if ( ((p.encumb(bp_torso)) >= 10) && ((p.encumb(bp_head)) >= 10) &&
(p.encumb(bp_foot_l) >= 10 ||
p.encumb(bp_foot_r) >= 10) ) { // Most likely places for rigid gear that would catch on the bars.
add_msg(m_info, _("Your amorphous body could slip though the %s, but your cumbersome gear can't."),
g->m.tername(examp).c_str());
return;
}
if (!query_yn(_("Slip through the %s?"), g->m.tername(examp).c_str())) {
none( p, examp );
return;
}
p.moves -= 200;
add_msg(_("You slide right between the bars."));
p.setpos( examp );
}
void iexamine::deployed_furniture( player &p, const tripoint &pos )
{
if ( !query_yn( _( "Take down the %s?" ), g->m.furn( pos ).obj().name().c_str() ) ) {
return;
}
p.add_msg_if_player( m_info, _( "You take down the %s." ),
g->m.furn( pos ).obj().name().c_str() );
const auto furn_item = g->m.furn( pos ).obj().deployed_item;
g->m.add_item_or_charges( pos, item( furn_item, calendar::turn ) );
g->m.furn_set( pos, f_null );
}
static std::pair<itype_id, const deploy_tent_actor*> find_tent_itype( const furn_str_id id )
{
const itype_id &iid = id->deployed_item;
if( item::type_is_defined( iid ) ) {
const itype &type = *item::find_type( iid );
for( const auto &pair : type.use_methods ) {
const auto actor = dynamic_cast<const deploy_tent_actor*>(pair.second.get_actor_ptr());
if( !actor ) {
continue;
}
if( (actor->floor_center && *actor->floor_center == id) || (!actor->floor_center && actor->floor == id) ) {
return std::make_pair( iid, actor );
}
}
}
return std::make_pair( iid, nullptr );
}
/**
* Determine structure's type and prompts its removal.
*/
void iexamine::portable_structure(player &p, const tripoint &examp)
{
const furn_str_id fid = g->m.furn( examp ).id();
const std::pair<itype_id, const deploy_tent_actor *> tent_item_type = find_tent_itype( fid );
if( tent_item_type.first == "null" ) {
debugmsg( "unknown furniture %s: don't know how to transform it into an item", fid.str() );
return;
}
itype_id dropped = tent_item_type.first;
std::string name = item::nname( dropped );
int radius;
if( tent_item_type.second ) {
const deploy_tent_actor &actor = *tent_item_type.second;
if( !actor.check_intact( examp ) ) {
if( !actor.broken_type ) {
add_msg( _( "The %s is broken and can not be picked up." ), name );
none( p, examp );
return;
}
dropped = *actor.broken_type;
name = string_format( _( "damaged %s" ), name );
}
radius = actor.radius;
} else {
radius = std::max( 1, fid->bash.collapse_radius );
}
if( !query_yn( _( "Take down the %s?" ), name ) ) {
none( p, examp );
return;
}
p.moves -= 200;
for( const tripoint &pt : g->m.points_in_radius( examp, radius ) ) {
g->m.furn_set( pt, f_null );
}
g->m.add_item_or_charges( examp, item( dropped, calendar::turn ) );
}
/**
* If there is a 2x4 around, prompt placing it across pit.
*/
void iexamine::pit( player &p, const tripoint &examp )
{
const inventory &crafting_inv = p.crafting_inventory();
if( !crafting_inv.has_amount( "2x4", 1 ) ) {
none( p, examp );
return;
}
std::vector<item_comp> planks;
planks.push_back( item_comp( "2x4", 1 ) );
if( query_yn( _( "Place a plank over the pit?" ) ) ) {
p.consume_items( planks );
if( g->m.ter( examp ) == t_pit ) {
g->m.ter_set( examp, t_pit_covered );
} else if( g->m.ter( examp ) == t_pit_spiked ) {
g->m.ter_set( examp, t_pit_spiked_covered );
} else if( g->m.ter( examp ) == t_pit_glass ) {
g->m.ter_set( examp, t_pit_glass_covered );
}
add_msg( _( "You place a plank of wood over the pit." ) );
p.mod_moves( -100 );
}
}
/**
* Prompt removing the 2x4 placed across the pit
*/
void iexamine::pit_covered(player &p, const tripoint &examp)
{
if(!query_yn(_("Remove cover?"))) {
none( p, examp );
return;
}
item plank("2x4", calendar::turn);
add_msg(_("You remove the plank."));
g->m.add_item_or_charges(p.pos(), plank);
if( g->m.ter(examp) == t_pit_covered ) {
g->m.ter_set(examp, t_pit);
} else if( g->m.ter(examp) == t_pit_spiked_covered ) {
g->m.ter_set(examp, t_pit_spiked);
} else if( g->m.ter(examp) == t_pit_glass_covered ) {
g->m.ter_set(examp, t_pit_glass);
}
p.mod_moves( -100 );
}
/**
* Loop prompt to bet $10.
*/
void iexamine::slot_machine( player &p, const tripoint& )
{
if (p.cash < 10) {
add_msg(m_info, _("You need $10 to play."));
} else if (query_yn(_("Insert $10?"))) {
do {
if (one_in(5)) {
popup(_("Three cherries... you get your money back!"));
} else if (one_in(20)) {
popup(_("Three bells... you win $50!"));
p.cash += 40; // Minus the $10 we wagered
} else if (one_in(50)) {
popup(_("Three stars... you win $200!"));
p.cash += 190;
} else if (one_in(1000)) {
popup(_("JACKPOT! You win $3000!"));
p.cash += 2990;
} else {
popup(_("No win."));
p.cash -= 10;
}
} while (p.cash >= 10 && query_yn(_("Play again?")));
}
}
/**
* Attempt to crack safe through audio-feedback manual lock manipulation.
*
* Try to unlock the safe by moving the dial and listening for the mechanism to "click into place."
* Time per attempt affected by perception and mechanics. 30 minutes per attempt minimum.
* Small chance of just guessing the combo without listening device.
*/
void iexamine::safe(player &p, const tripoint &examp)
{
if ( !( p.has_amount("stethoscope", 1) || p.has_bionic( bionic_id( "bio_ears" ) ) ) ) {
p.moves -= 100;
// one_in(30^3) chance of guessing
if (one_in(27000)) {
p.add_msg_if_player(m_good, _("You mess with the dial for a little bit... and it opens!"));
g->m.furn_set(examp, f_safe_o);
return;
} else {
p.add_msg_if_player(m_info, _("You mess with the dial for a little bit."));
return;
}
}
if (query_yn(_("Attempt to crack the safe?"))) {
if (p.is_deaf()) {
add_msg(m_info, _("You can't crack a safe while deaf!"));
return;
}
// 150 minutes +/- 20 minutes per mechanics point away from 3 +/- 10 minutes per
// perception point away from 8; capped at 30 minutes minimum. *100 to convert to moves
///\EFFECT_PER speeds up safe cracking
///\EFFECT_MECHANICS speeds up safe cracking
const time_duration time = std::max( 150_minutes - 20_minutes * ( p.get_skill_level( skill_mechanics ) - 3 ) - 10_minutes * ( p.get_per() - 8 ), 30_minutes );
p.assign_activity( activity_id( "ACT_CRACKING" ), to_moves<int>( time ) );