-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
bionics.cpp
1810 lines (1672 loc) · 69 KB
/
bionics.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 "player.h"
#include "action.h"
#include "game.h"
#include "map.h"
#include "debug.h"
#include "rng.h"
#include "input.h"
#include "item.h"
#include "bionics.h"
#include "line.h"
#include "json.h"
#include "messages.h"
#include "overmapbuffer.h"
#include "sounds.h"
#include "translations.h"
#include "catacharset.h"
#include "input.h"
#include "monster.h"
#include "overmap.h"
#include "itype.h"
#include "vehicle.h"
#include "field.h"
#include "weather_gen.h"
#include "weather.h"
#include "cata_utility.h"
#include <math.h> //sqrt
#include <algorithm> //std::min
#include <sstream>
// '!', '-' and '=' are uses as default bindings in the menu
const invlet_wrapper bionic_chars("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\"#&()*+./:;@[\\]^_{|}");
const skill_id skilll_electronics( "electronics" );
const skill_id skilll_firstaid( "firstaid" );
const skill_id skilll_mechanics( "mechanics" );
namespace {
std::map<std::string, bionic_data> bionics;
std::vector<std::string> faulty_bionics;
} //namespace
bool is_valid_bionic(std::string const& id)
{
return !!bionics.count(id);
}
bionic_data const& bionic_info(std::string const &id)
{
auto const it = bionics.find(id);
if (it != bionics.end()) {
return it->second;
}
debugmsg("bad bionic id");
static bionic_data const null_value {"bad bionic", false, false, 0, 0, 0, 0, 0, "bad_bionic", false};
return null_value;
}
void bionics_install_failure(player *u, int difficulty, int success);
bionic_data::bionic_data(std::string nname, bool ps, bool tog, int pac, int pad, int pot,
int ct, int cap, std::string desc, bool fault
) : name(std::move(nname)), description(std::move(desc)), power_activate(pac),
power_deactivate(pad), power_over_time(pot), charge_time(ct), capacity(cap), faulty(fault),
power_source(ps), activated(tog || pac || ct), toggled(tog)
{
}
void show_bionics_titlebar(WINDOW *window, player *p, std::string menu_mode)
{
werase(window);
std::string caption = _("BIONICS -");
int cap_offset = utf8_width(caption) + 1;
mvwprintz(window, 0, 0, c_blue, "%s", caption.c_str());
std::stringstream pwr;
pwr << string_format(_("Power: %i/%i"), int(p->power_level), int(p->max_power_level));
int pwr_length = utf8_width(pwr.str()) + 1;
mvwprintz(window, 0, getmaxx(window) - pwr_length, c_white, "%s", pwr.str().c_str());
std::string desc;
int desc_length = getmaxx(window) - cap_offset - pwr_length;
if(menu_mode == "reassigning") {
desc = _("Reassigning.\nSelect a bionic to reassign or press SPACE to cancel.");
} else if(menu_mode == "activating") {
desc = _("<color_green>Activating</color> <color_yellow>!</color> to examine, <color_yellow>-</color> to remove, <color_yellow>=</color> to reassign, <color_yellow>TAB</color> to switch tabs.");
} else if(menu_mode == "removing") {
desc = _("<color_red>Removing</color> <color_yellow>!</color> to activate, <color_yellow>-</color> to remove, <color_yellow>=</color> to reassign, <color_yellow>TAB</color> to switch tabs.");
} else if(menu_mode == "examining") {
desc = _("<color_ltblue>Examining</color> <color_yellow>!</color> to activate, <color_yellow>-</color> to remove, <color_yellow>=</color> to reassign, <color_yellow>TAB</color> to switch tabs.");
}
fold_and_print(window, 0, cap_offset, desc_length, c_white, desc);
wrefresh(window);
}
//builds the power usage string of a given bionic
std::string build_bionic_poweronly_string(bionic const &bio)
{
std::ostringstream power_desc;
bool hasPreviousText = false;
if (bionics[bio.id].power_over_time > 0 && bionics[bio.id].charge_time > 0) {
power_desc << (
bionics[bio.id].charge_time == 1
? string_format(_("%d PU / turn"),
bionics[bio.id].power_over_time)
: string_format(_("%d PU / %d turns"),
bionics[bio.id].power_over_time,
bionics[bio.id].charge_time));
hasPreviousText = true;
}
if (bionics[bio.id].power_activate > 0 && !bionics[bio.id].charge_time) {
if(hasPreviousText){
power_desc << ", ";
}
power_desc << string_format(_("%d PU act"),
bionics[bio.id].power_activate);
hasPreviousText = true;
}
if (bionics[bio.id].power_deactivate > 0 && !bionics[bio.id].charge_time) {
if(hasPreviousText){
power_desc << ", ";
}
power_desc << string_format(_("%d PU deact"),
bionics[bio.id].power_deactivate);
hasPreviousText = true;
}
if (bionics[bio.id].toggled) {
if(hasPreviousText){
power_desc << ", ";
}
power_desc << (bio.powered ? _("ON") : _("OFF"));
}
return power_desc.str();
}
//generates the string that show how much power a bionic uses
std::string build_bionic_powerdesc_string(bionic const &bio)
{
std::ostringstream power_desc;
std::string power_string = build_bionic_poweronly_string(bio);
power_desc << bionics[bio.id].name;
if(power_string.length()>0){
power_desc << ", " << power_string;
}
return power_desc.str();
}
//get a text color depending on the power/powering state of the bionic
nc_color get_bionic_text_color(bionic const &bio, bool const isHighlightedBionic)
{
nc_color type = c_white;
if(bionics[bio.id].activated){
if(isHighlightedBionic){
if (bio.powered && !bionics[bio.id].power_source) {
type = h_red;
} else if (bionics[bio.id].power_source && !bio.powered) {
type = h_ltcyan;
} else if (bionics[bio.id].power_source && bio.powered) {
type = h_ltgreen;
} else {
type = h_ltred;
}
}else{
if (bio.powered && !bionics[bio.id].power_source) {
type = c_red;
} else if (bionics[bio.id].power_source && !bio.powered) {
type = c_ltcyan;
} else if (bionics[bio.id].power_source && bio.powered) {
type = c_ltgreen;
} else {
type = c_ltred;
}
}
}else{
if(isHighlightedBionic){
if (bionics[bio.id].power_source) {
type = h_ltcyan;
} else {
type = h_cyan;
}
}else{
if (bionics[bio.id].power_source) {
type = c_ltcyan;
} else {
type = c_cyan;
}
}
}
return type;
}
void player::power_bionics()
{
std::vector <bionic *> passive;
std::vector <bionic *> active;
bionic *bio_last = NULL;
std::string tab_mode = "TAB_ACTIVE";
for( auto &elem : my_bionics ) {
if( !bionics[elem.id].activated ) {
passive.push_back( &elem );
} else {
active.push_back( &elem );
}
}
// maximal number of rows in both columns
int active_bionic_count = active.size();
int passive_bionic_count = passive.size();
int bionic_count = std::max(passive_bionic_count, active_bionic_count);
//added title_tab_height for the tabbed bionic display
int TITLE_HEIGHT = 2;
int TITLE_TAB_HEIGHT = 3;
// Main window
/** Total required height is:
* top frame line: + 1
* height of title window: + TITLE_HEIGHT
* height of tabs: + TITLE_TAB_HEIGHT
* height of the biggest list of active/passive bionics: + bionic_count
* bottom frame line: + 1
* TOTAL: TITLE_HEIGHT + TITLE_TAB_HEIGHT + bionic_count + 2
*/
int HEIGHT = std::min(TERMY, std::max(FULL_SCREEN_HEIGHT,
TITLE_HEIGHT + TITLE_TAB_HEIGHT + bionic_count + 2));
int WIDTH = FULL_SCREEN_WIDTH + (TERMX - FULL_SCREEN_WIDTH) / 2;
int START_X = (TERMX - WIDTH) / 2;
int START_Y = (TERMY - HEIGHT) / 2;
//wBio is the entire bionic window
WINDOW *wBio = newwin(HEIGHT, WIDTH, START_Y, START_X);
WINDOW_PTR wBioptr( wBio );
int LIST_HEIGHT = HEIGHT - TITLE_HEIGHT - TITLE_TAB_HEIGHT - 2;
int DESCRIPTION_WIDTH = WIDTH - 2 - 40;
int DESCRIPTION_START_Y = START_Y + TITLE_HEIGHT + TITLE_TAB_HEIGHT + 1;
int DESCRIPTION_START_X = START_X + 1 + 40;
//w_description is the description panel that is controlled with ! key
WINDOW *w_description = newwin(LIST_HEIGHT, DESCRIPTION_WIDTH,
DESCRIPTION_START_Y, DESCRIPTION_START_X);
WINDOW_PTR w_descriptionptr( w_description );
// Title window
int TITLE_START_Y = START_Y + 1;
int HEADER_LINE_Y = TITLE_HEIGHT + TITLE_TAB_HEIGHT + 1; // + lines with text in titlebar, local
WINDOW *w_title = newwin(TITLE_HEIGHT, WIDTH - 2, TITLE_START_Y, START_X + 1);
WINDOW_PTR w_titleptr( w_title );
int TAB_START_Y = TITLE_START_Y + 2;
//w_tabs is the tab bar for passive and active bionic groups
WINDOW *w_tabs = newwin(TITLE_TAB_HEIGHT, WIDTH - 2, TAB_START_Y, START_X + 1);
WINDOW_PTR w_tabsptr( w_tabs );
int scroll_position = 0;
int cursor = 0;
//generate the tab title string and a count of the bionics owned
std::string menu_mode = "activating";
std::ostringstream tabname;
tabname << _("ACTIVE");
if(active_bionic_count>0){
tabname << "(" << active_bionic_count << ")";
}
std::string active_tab_name = tabname.str();
tabname.str("");
tabname << _("PASSIVE");
if(passive_bionic_count > 0){
tabname << "(" << passive_bionic_count << ")";
}
std::string passive_tab_name = tabname.str();
const int tabs_start = 1;
const int tab_step = 3;
// offset for display: bionic with index i is drawn at y=list_start_y+i
// drawing the bionics starts with bionic[scroll_position]
const int list_start_y = HEADER_LINE_Y;// - scroll_position;
int half_list_view_location = LIST_HEIGHT / 2;
int max_scroll_position = std::max(0, (tab_mode == "TAB_ACTIVE" ? active_bionic_count : passive_bionic_count) - LIST_HEIGHT);
input_context ctxt("BIONICS");
ctxt.register_updown();
ctxt.register_action("ANY_INPUT");
ctxt.register_action("TOGGLE_EXAMINE");
ctxt.register_action("REASSIGN");
ctxt.register_action("REMOVE");
ctxt.register_action("NEXT_TAB");
ctxt.register_action("PREV_TAB");
ctxt.register_action("CONFIRM");
ctxt.register_action("HELP_KEYBINDINGS");
bool recalc = false;
bool redraw = true;
for (;;) {
if(recalc) {
active.clear();
passive.clear();
for( auto &elem : my_bionics ) {
if( !bionics[elem.id].activated ) {
passive.push_back( &elem );
} else {
active.push_back( &elem );
}
}
active_bionic_count = active.size();
passive_bionic_count = passive.size();
bionic_count = std::max(passive_bionic_count, active_bionic_count);
if(active_bionic_count == 0 && passive_bionic_count > 0){
tab_mode = "TAB_PASSIVE";
}
max_scroll_position = std::max(0, (tab_mode == "TAB_ACTIVE" ? active_bionic_count : passive_bionic_count) - LIST_HEIGHT);
if(--cursor < 0) {
cursor = 0;
}
if(scroll_position > max_scroll_position && cursor - scroll_position < LIST_HEIGHT - half_list_view_location) {
scroll_position--;
}
recalc = false;
}
//track which list we are looking at
std::vector<bionic*> *current_bionic_list = (tab_mode == "TAB_ACTIVE" ? &active : &passive);
if(redraw) {
redraw = false;
werase(wBio);
draw_border(wBio);
// Draw symbols to connect additional lines to border
mvwputch(wBio, HEADER_LINE_Y - 1, 0, BORDER_COLOR, LINE_XXXO); // |-
mvwputch(wBio, HEADER_LINE_Y - 1, WIDTH - 1, BORDER_COLOR, LINE_XOXX); // -|
nc_color type;
if(tab_mode == "TAB_PASSIVE"){
if (passive.empty()) {
mvwprintz(wBio, list_start_y + 1, 2, c_ltgray, _("No passive bionics installed."));
} else {
for (size_t i = scroll_position; i < passive.size(); i++) {
if (list_start_y + static_cast<int>(i) - scroll_position == HEIGHT - 1) {
break;
}
bool isHighlighted = false;
if(cursor == static_cast<int>(i)){
isHighlighted = true;
}
type = get_bionic_text_color(*passive[i], isHighlighted);
mvwprintz(wBio, list_start_y + i - scroll_position, 2, type, "%c %s", passive[i]->invlet,
bionics[passive[i]->id].name.c_str());
}
}
}
if(tab_mode == "TAB_ACTIVE"){
if (active.empty()) {
mvwprintz(wBio, list_start_y + 1, 2, c_ltgray, _("No activatable bionics installed."));
} else {
for (size_t i = scroll_position; i < active.size(); i++) {
if (list_start_y + static_cast<int>(i) - scroll_position == HEIGHT - 1) {
break;
}
bool isHighlighted = false;
if(cursor == static_cast<int>(i)){
isHighlighted = true;
}
type = get_bionic_text_color(*active[i], isHighlighted);
mvwputch(wBio, list_start_y + i - scroll_position, 2, type, active[i]->invlet);
mvwputch(wBio, list_start_y + i - scroll_position, 3, type, ' ');
std::string power_desc = build_bionic_powerdesc_string(*active[i]);
std::string tmp = utf8_truncate(power_desc, WIDTH - 3);
mvwprintz(wBio, list_start_y + i - scroll_position, 2 + 2, type, tmp.c_str());
}
}
}
// Scrollbar
if(scroll_position > 0) {
mvwputch(wBio, HEADER_LINE_Y, 0, c_ltgreen, '^');
}
if(scroll_position < max_scroll_position && max_scroll_position > 0) {
mvwputch(wBio, HEIGHT - 1 - 1,
0, c_ltgreen, 'v');
}
}
wrefresh(wBio);
//handle tab drawing after main window is refreshed
werase(w_tabs);
int width = getmaxx(w_tabs);
for (int i = 0; i < width; i++) {
mvwputch(w_tabs, 2, i, BORDER_COLOR, LINE_OXOX);
}
int tab_x = tabs_start;
draw_tab(w_tabs, tab_x, active_tab_name, tab_mode == "TAB_ACTIVE");
tab_x += tab_step + utf8_width(active_tab_name);
draw_tab(w_tabs, tab_x, passive_tab_name, tab_mode != "TAB_ACTIVE");
wrefresh(w_tabs);
show_bionics_titlebar(w_title, this, menu_mode);
// Description
if(menu_mode == "examining" && current_bionic_list->size() > 0){
werase(w_description);
std::ostringstream power_only_desc;
std::string poweronly_string;
std::string bionic_name;
if(tab_mode == "TAB_ACTIVE"){
bionic_name = bionics[active[cursor]->id].name;
poweronly_string = build_bionic_poweronly_string(*active[cursor]);
}else{
bionic_name = bionics[passive[cursor]->id].name;
poweronly_string = build_bionic_poweronly_string(*passive[cursor]);
}
int ypos = 0;
ypos += fold_and_print(w_description, ypos, 0, DESCRIPTION_WIDTH, c_white, bionic_name);
if(poweronly_string.length() > 0){
power_only_desc << _("Power usage: ") << poweronly_string;
ypos += fold_and_print(w_description, ypos, 0, DESCRIPTION_WIDTH, c_ltgray, power_only_desc.str());
}
ypos += fold_and_print(w_description, ypos, 0, DESCRIPTION_WIDTH, c_ltblue, bionics[(*current_bionic_list)[cursor]->id].description);
wrefresh(w_description);
}
const std::string action = ctxt.handle_input();
const long ch = ctxt.get_raw_input().get_first_input();
bionic *tmp = NULL;
bool confirmCheck = false;
if (menu_mode == "reassigning") {
menu_mode = "activating";
tmp = bionic_by_invlet(ch);
if(tmp == nullptr) {
// Selected an non-existing bionic (or escape, or ...)
continue;
}
redraw = true;
const long newch = popup_getkey(_("%s; enter new letter."),
bionics[tmp->id].name.c_str());
wrefresh(wBio);
if(newch == ch || newch == ' ' || newch == KEY_ESCAPE) {
continue;
}
if( !bionic_chars.valid( newch ) ) {
popup( _("Invlid bionic letter. Only those characters are valid:\n\n%s"),
bionic_chars.get_allowed_chars().c_str() );
continue;
}
bionic *otmp = bionic_by_invlet(newch);
if(otmp != nullptr) {
std::swap(tmp->invlet, otmp->invlet);
} else {
tmp->invlet = newch;
}
// TODO: show a message like when reassigning a key to an item?
} else if (action == "NEXT_TAB") {
redraw = true;
scroll_position = 0;
cursor = 0;
if(tab_mode == "TAB_ACTIVE"){
tab_mode = "TAB_PASSIVE";
}else{
tab_mode = "TAB_ACTIVE";
}
} else if (action == "PREV_TAB") {
redraw = true;
scroll_position = 0;
cursor = 0;
if(tab_mode == "TAB_PASSIVE"){
tab_mode = "TAB_ACTIVE";
}else{
tab_mode = "TAB_PASSIVE";
}
} else if (action == "DOWN") {
redraw = true;
if(static_cast<size_t>(cursor)<current_bionic_list->size()-1){
cursor++;
}
if(scroll_position < max_scroll_position && cursor - scroll_position > LIST_HEIGHT - half_list_view_location) {
scroll_position++;
}
} else if (action == "UP") {
redraw = true;
if(cursor>0){
cursor--;
}
if(scroll_position > 0 && cursor - scroll_position < half_list_view_location) {
scroll_position--;
}
} else if (action == "REASSIGN") {
menu_mode = "reassigning";
} else if (action == "TOGGLE_EXAMINE") { // switches between activation and examination
menu_mode = menu_mode == "activating" ? "examining" : "activating";
redraw = true;
} else if (action == "REMOVE") {
menu_mode = "removing";
redraw = true;
} else if (action == "HELP_KEYBINDINGS") {
redraw = true;
} else if (action == "CONFIRM"){
confirmCheck = true;
} else {
confirmCheck = true;
}
//confirmation either occurred by pressing enter where the bionic cursor is, or the hotkey was selected
if(confirmCheck){
auto& bio_list = tab_mode == "TAB_ACTIVE" ? active : passive;
if(action == "CONFIRM" && current_bionic_list->size() > 0){
tmp = bio_list[cursor];
}else{
tmp = bionic_by_invlet(ch);
if(tmp && tmp != bio_last) {
// new bionic selected, update cursor and scroll position
int temp_cursor = 0;
for(temp_cursor = 0; temp_cursor < (int)bio_list.size(); temp_cursor++) {
if(bio_list[temp_cursor] == tmp) {
break;
}
}
// if bionic is not found in current list, ignore the attempt to view/activate
if(temp_cursor >= (int)bio_list.size()) {
continue;
}
//relocate cursor to the bionic that was found
cursor = temp_cursor;
scroll_position = 0;
while(scroll_position < max_scroll_position && cursor - scroll_position > LIST_HEIGHT - half_list_view_location) {
scroll_position++;
}
}
}
if(!tmp) {
// entered a key that is not mapped to any bionic,
// -> leave screen
break;
}
bio_last = tmp;
const std::string &bio_id = tmp->id;
const bionic_data &bio_data = bionics[bio_id];
if (menu_mode == "removing") {
if (uninstall_bionic(bio_id)) {
recalc = true;
redraw = true;
continue;
}
}
if (menu_mode == "activating") {
if (bio_data.activated) {
int b = tmp - &my_bionics[0];
if (tmp->powered) {
deactivate_bionic(b);
} else {
activate_bionic(b);
}
// update message log and the menu
g->refresh_all();
redraw = true;
continue;
} else {
popup(_("You can not activate %s!\n"
"To read a description of %s, press '!', then '%c'."), bio_data.name.c_str(), bio_data.name.c_str(), tmp->invlet);
redraw = true;
}
} else if (menu_mode == "examining") { // Describing bionics, allow user to jump to description key
redraw = true;
if(action != "CONFIRM"){
for(size_t i = 0; i < active.size(); i++){
if(active[i] == tmp){
tab_mode = "TAB_ACTIVE";
cursor = static_cast<int>(i);
int max_scroll_check = std::max(0, active_bionic_count - LIST_HEIGHT);
if(static_cast<int>(i) > max_scroll_check){
scroll_position = max_scroll_check;
}else{
scroll_position = i;
}
break;
}
}
for(size_t i = 0; i < passive.size(); i++){
if(passive[i] == tmp){
tab_mode = "TAB_PASSIVE";
cursor = static_cast<int>(i);
int max_scroll_check = std::max(0, passive_bionic_count - LIST_HEIGHT);
if(static_cast<int>(i) > max_scroll_check){
scroll_position = max_scroll_check;
}else{
scroll_position = i;
}
break;
}
}
}
}
}
}
}
void draw_exam_window(WINDOW *win, int border_line, bool examination)
{
int width = getmaxx(win);
if (examination) {
for (int i = 1; i < width - 1; i++) {
mvwputch(win, border_line, i, BORDER_COLOR, LINE_OXOX); // Draw line above description
}
mvwputch(win, border_line, 0, BORDER_COLOR, LINE_XXXO); // |-
mvwputch(win, border_line, width - 1, BORDER_COLOR, LINE_XOXX); // -|
} else {
for (int i = 1; i < width - 1; i++) {
mvwprintz(win, border_line, i, c_black, " "); // Erase line
}
mvwputch(win, border_line, 0, BORDER_COLOR, LINE_XOXO); // |
mvwputch(win, border_line, width, BORDER_COLOR, LINE_XOXO); // |
}
}
// Why put this in a Big Switch? Why not let bionics have pointers to
// functions, much like monsters and items?
//
// Well, because like diseases, which are also in a Big Switch, bionics don't
// share functions....
bool player::activate_bionic(int b, bool eff_only)
{
bionic &bio = my_bionics[b];
// Special compatibility code for people who updated saves with their claws out
if ((weapon.type->id == "bio_claws_weapon" && bio.id == "bio_claws_weapon") ||
(weapon.type->id == "bio_blade_weapon" && bio.id == "bio_blade_weapon")) {
return deactivate_bionic(b);
}
// eff_only means only do the effect without messing with stats or displaying messages
if (!eff_only) {
if (bio.powered) {
// It's already on!
return false;
}
if (power_level < bionics[bio.id].power_activate) {
add_msg(m_info, _("You don't have the power to activate your %s."), bionics[bio.id].name.c_str());
return false;
}
//We can actually activate now, do activation-y things
charge_power(-bionics[bio.id].power_activate);
if (bionics[bio.id].toggled || bionics[bio.id].charge_time > 0) {
bio.powered = true;
}
if (bionics[bio.id].charge_time > 0) {
bio.charge = bionics[bio.id].charge_time;
}
add_msg(m_info, _("You activate your %s."), bionics[bio.id].name.c_str());
}
std::vector<std::string> good;
std::vector<std::string> bad;
tripoint dirp = pos();
int &dirx = dirp.x;
int &diry = dirp.y;
item tmp_item;
w_point const weatherPoint = g->weather_gen->get_weather( global_square_location(), calendar::turn );
// On activation effects go here
if(bio.id == "bio_painkiller") {
pkill += 6;
pain -= 2;
if (pkill > pain) {
pkill = pain;
}
} else if (bio.id == "bio_ears" && has_active_bionic("bio_earplugs")) {
for (auto &i : my_bionics) {
if (i.id == "bio_earplugs") {
i.powered = false;
add_msg(m_info, _("Your %s automatically turn off."), bionics[i.id].name.c_str());
}
}
} else if (bio.id == "bio_earplugs" && has_active_bionic("bio_ears")) {
for (auto &i : my_bionics) {
if (i.id == "bio_ears") {
i.powered = false;
add_msg(m_info, _("Your %s automatically turns off."), bionics[i.id].name.c_str());
}
}
} else if (bio.id == "bio_tools") {
invalidate_crafting_inventory();
} else if (bio.id == "bio_cqb") {
if (!pick_style()) {
bio.powered = false;
add_msg(m_info, _("You change your mind and turn it off."));
return false;
}
} else if (bio.id == "bio_nanobots") {
remove_effect("bleed");
healall(4);
} else if (bio.id == "bio_resonator") {
//~Sound of a bionic sonic-resonator shaking the area
sounds::sound( pos(), 30, _("VRRRRMP!"));
for (int i = posx() - 1; i <= posx() + 1; i++) {
for (int j = posy() - 1; j <= posy() + 1; j++) {
tripoint bashpoint( i, j, posz() );
g->m.bash( bashpoint, 110 );
g->m.bash( bashpoint, 110 ); // Multibash effect, so that doors &c will fall
g->m.bash( bashpoint, 110 );
}
}
} else if (bio.id == "bio_time_freeze") {
moves += power_level;
power_level = 0;
add_msg(m_good, _("Your speed suddenly increases!"));
if (one_in(3)) {
add_msg(m_bad, _("Your muscles tear with the strain."));
apply_damage( nullptr, bp_arm_l, rng( 5, 10 ) );
apply_damage( nullptr, bp_arm_r, rng( 5, 10 ) );
apply_damage( nullptr, bp_leg_l, rng( 7, 12 ) );
apply_damage( nullptr, bp_leg_r, rng( 7, 12 ) );
apply_damage( nullptr, bp_torso, rng( 5, 15 ) );
}
if (one_in(5)) {
add_effect("teleglow", rng(50, 400));
}
} else if (bio.id == "bio_teleport") {
g->teleport();
add_effect("teleglow", 300);
// TODO: More stuff here (and bio_blood_filter)
} else if(bio.id == "bio_blood_anal") {
WINDOW *w = newwin(20, 40, 3 + ((TERMY > 25) ? (TERMY - 25) / 2 : 0),
10 + ((TERMX > 80) ? (TERMX - 80) / 2 : 0));
draw_border(w);
if (has_effect("fungus")) {
bad.push_back(_("Fungal Parasite"));
}
if (has_effect("dermatik")) {
bad.push_back(_("Insect Parasite"));
}
if (has_effect("stung")) {
bad.push_back(_("Stung"));
}
if (has_effect("poison")) {
bad.push_back(_("Poison"));
}
if (radiation > 0) {
bad.push_back(_("Irradiated"));
}
if (has_effect("pkill1")) {
good.push_back(_("Minor Painkiller"));
}
if (has_effect("pkill2")) {
good.push_back(_("Moderate Painkiller"));
}
if (has_effect("pkill3")) {
good.push_back(_("Heavy Painkiller"));
}
if (has_effect("pkill_l")) {
good.push_back(_("Slow-Release Painkiller"));
}
if (has_effect("drunk")) {
good.push_back(_("Alcohol"));
}
if (has_effect("cig")) {
good.push_back(_("Nicotine"));
}
if (has_effect("meth")) {
good.push_back(_("Methamphetamines"));
}
if (has_effect("high")) {
good.push_back(_("Intoxicant: Other"));
}
if (has_effect("weed_high")) {
good.push_back(_("THC Intoxication"));
}
if (has_effect("hallu") || has_effect("visuals")) {
bad.push_back(_("Hallucinations"));
}
if (has_effect("iodine")) {
good.push_back(_("Iodine"));
}
if (has_effect("datura")) {
good.push_back(_("Anticholinergic Tropane Alkaloids"));
}
if (has_effect("took_xanax")) {
good.push_back(_("Xanax"));
}
if (has_effect("took_prozac")) {
good.push_back(_("Prozac"));
}
if (has_effect("took_flumed")) {
good.push_back(_("Antihistamines"));
}
if (has_effect("adrenaline")) {
good.push_back(_("Adrenaline Spike"));
}
if (has_effect("adrenaline_mycus")) {
good.push_back(_("Mycal Spike"));
}
if (has_effect("tapeworm")) { // This little guy is immune to the blood filter though, as he lives in your bowels.
good.push_back(_("Intestinal Parasite"));
}
if (has_effect("bloodworms")) {
good.push_back(_("Hemolytic Parasites"));
}
if (has_effect("brainworms")) { // These little guys are immune to the blood filter too, as they live in your brain.
good.push_back(_("Intracranial Parasite"));
}
if (has_effect("paincysts")) { // These little guys are immune to the blood filter too, as they live in your muscles.
good.push_back(_("Intramuscular Parasites"));
}
if (has_effect("tetanus")) { // Tetanus infection.
good.push_back(_("Clostridium Tetani Infection"));
}
if (good.empty() && bad.empty()) {
mvwprintz(w, 1, 1, c_white, _("No effects."));
} else {
for (unsigned line = 1; line < 39 && line <= good.size() + bad.size(); line++) {
if (line <= bad.size()) {
mvwprintz(w, line, 1, c_red, "%s", bad[line - 1].c_str());
} else {
mvwprintz(w, line, 1, c_green, "%s", good[line - 1 - bad.size()].c_str());
}
}
}
wrefresh(w);
refresh();
getch();
delwin(w);
} else if(bio.id == "bio_blood_filter") {
remove_effect("fungus");
remove_effect("dermatik");
remove_effect("bloodworms");
remove_effect("tetanus");
remove_effect("poison");
remove_effect("stung");
remove_effect("pkill1");
remove_effect("pkill2");
remove_effect("pkill3");
remove_effect("pkill_l");
remove_effect("drunk");
remove_effect("cig");
remove_effect("high");
remove_effect("hallu");
remove_effect("visuals");
remove_effect("iodine");
remove_effect("datura");
remove_effect("took_xanax");
remove_effect("took_prozac");
remove_effect("took_flumed");
remove_effect("adrenaline");
remove_effect("meth");
pkill = 0;
stim = 0;
} else if(bio.id == "bio_evap") {
item water = item("water_clean", 0);
int humidity = weatherPoint.humidity;
int water_charges = (humidity * 3.0) / 100.0 + 0.5;
// At 50% relative humidity or more, the player will draw 2 units of water
// At 16% relative humidity or less, the player will draw 0 units of water
water.charges = water_charges;
if (water_charges == 0) {
add_msg_if_player(m_bad, _("There was not enough moisture in the air from which to draw water!"));
} else if (g->handle_liquid(water, true, false)) {
moves -= 100;
} else {
water.charges -= drink_from_hands( water );
if( water.charges == water_charges ) {
charge_power(bionics["bio_evap"].power_activate);
}
}
} else if(bio.id == "bio_lighter") {
if(!choose_adjacent(_("Start a fire where?"), dirp) ||
(!g->m.add_field(dirp, fd_fire, 1, 0))) {
add_msg_if_player(m_info, _("You can't light a fire there."));
charge_power(bionics["bio_lighter"].power_activate);
}
} else if(bio.id == "bio_leukocyte") {
set_healthy(std::min(100, get_healthy() + 2));
mod_healthy_mod(20, 100);
} else if(bio.id == "bio_geiger") {
add_msg(m_info, _("Your radiation level: %d"), radiation);
} else if(bio.id == "bio_radscrubber") {
if (radiation > 4) {
radiation -= 5;
} else {
radiation = 0;
}
} else if(bio.id == "bio_adrenaline") {
if (has_effect("adrenaline")) {
add_effect("adrenaline", 50);
} else {
add_effect("adrenaline", 200);
}
} else if(bio.id == "bio_blaster") {
tmp_item = weapon;
weapon = item("bio_blaster_gun", 0);
g->refresh_all();
g->plfire(false);
if(weapon.charges == 1) { // not fired
charge_power(bionics[bio.id].power_activate);
}
weapon = tmp_item;
} else if (bio.id == "bio_laser") {
tmp_item = weapon;
weapon = item("bio_laser_gun", 0);
g->refresh_all();
g->plfire(false);
if(weapon.charges == 1) { // not fired
charge_power(bionics[bio.id].power_activate);
}
weapon = tmp_item;
} else if(bio.id == "bio_chain_lightning") {
tmp_item = weapon;
weapon = item("bio_lightning", 0);
g->refresh_all();
g->plfire(false);
if(weapon.charges == 1) { // not fired
charge_power(bionics[bio.id].power_activate);
}
weapon = tmp_item;
} else if (bio.id == "bio_emp") {
if(choose_adjacent(_("Create an EMP where?"), dirx, diry)) {
g->emp_blast( tripoint( dirx, diry, posz() ) );
} else {
charge_power(bionics["bio_emp"].power_activate);
}
} else if (bio.id == "bio_hydraulics") {
add_msg(m_good, _("Your muscles hiss as hydraulic strength fills them!"));
// Sound of hissing hydraulic muscle! (not quite as loud as a car horn)
sounds::sound( pos(), 19, _("HISISSS!"));
} else if (bio.id == "bio_water_extractor") {
bool extracted = false;
for( auto it = g->m.i_at(posx(), posy()).begin();
it != g->m.i_at(posx(), posy()).end(); ++it) {
if( it->is_corpse() ) {
const int avail = it->get_var( "remaining_water", it->volume() / 2 );
if(avail > 0 && query_yn(_("Extract water from the %s"), it->tname().c_str())) {
item water = item("water_clean", 0);
water.charges = avail;
if (g->handle_liquid(water, true, false)) {
moves -= 100;
} else {
water.charges -= drink_from_hands( water );
}
if( water.charges != avail ) {
extracted = true;
it->set_var( "remaining_water", static_cast<int>( water.charges ) );
}
break;
}
}
}
if (!extracted) {
charge_power(bionics["bio_water_extractor"].power_activate);
}
} else if(bio.id == "bio_magnet") {
std::vector<tripoint> traj;
for (int i = posx() - 10; i <= posx() + 10; i++) {
for (int j = posy() - 10; j <= posy() + 10; j++) {
if (g->m.i_at(i, j).size() > 0) {
traj = g->m.find_clear_path( {i, j, posz()}, pos3() );
}
traj.insert(traj.begin(), {i, j, posz()});
if( g->m.has_flag( "SEALED", i, j ) ) {
continue;
}
for (unsigned k = 0; k < g->m.i_at(i, j).size(); k++) {
tmp_item = g->m.i_at(i, j)[k];
if( (tmp_item.made_of("iron") || tmp_item.made_of("steel")) &&
tmp_item.weight() < weight_capacity() ) {
g->m.i_rem(i, j, k);
std::vector<tripoint>::iterator it;
for (it = traj.begin(); it != traj.end(); ++it) {
int index = g->mon_at(*it);
if (index != -1) {
g->zombie(index).apply_damage( this, bp_torso, tmp_item.weight() / 225 );
g->zombie(index).check_dead_state();
g->m.add_item_or_charges(it->x, it->y, tmp_item);
break;
} else if (g->m.move_cost(it->x, it->y) == 0) {
if (it != traj.begin()) {
g->m.bash( tripoint( it->x, it->y, posz() ), tmp_item.weight() / 225 );
if (g->m.move_cost(it->x, it->y) == 0) {
g->m.add_item_or_charges((it - 1)->x, (it - 1)->y, tmp_item);
break;
}
} else {
g->m.bash( *it, tmp_item.weight() / 225 );
if (g->m.move_cost(it->x, it->y) == 0) {
break;
}
}
}