forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
player_display.cpp
1613 lines (1493 loc) · 73.1 KB
/
player_display.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 <algorithm>
#include <array>
#include <cmath>
#include <cstddef>
#include <cstdlib>
#include <functional>
#include <memory>
#include <string>
#include "addiction.h"
#include "avatar.h"
#include "bionics.h"
#include "bodygraph.h"
#include "bodypart.h"
#include "calendar.h"
#include "cata_utility.h"
#include "catacharset.h"
#include "character.h"
#include "character_modifier.h"
#include "color.h"
#include "cursesdef.h"
#include "debug.h"
#include "display.h"
#include "effect.h"
#include "enum_conversions.h"
#include "game.h"
#include "input.h"
#include "localized_comparator.h"
#include "mutation.h"
#include "options.h"
#include "output.h"
#include "pimpl.h"
#include "profession.h"
#include "proficiency.h"
#include "skill.h"
#include "string_formatter.h"
#include "string_input_popup.h"
#include "translations.h"
#include "ui_manager.h"
#include "units.h"
#include "units_utility.h"
#include "weather.h"
#include "weather_type.h"
static const bionic_id bio_cqb( "bio_cqb" );
static const skill_id skill_bashing( "bashing" );
static const skill_id skill_cutting( "cutting" );
static const skill_id skill_dodge( "dodge" );
static const skill_id skill_melee( "melee" );
static const skill_id skill_stabbing( "stabbing" );
static const skill_id skill_unarmed( "unarmed" );
static const trait_id trait_COLDBLOOD4( "COLDBLOOD4" );
static const trait_id trait_SUNLIGHT_DEPENDENT( "SUNLIGHT_DEPENDENT" );
static const trait_id trait_TROGLO( "TROGLO" );
static const trait_id trait_TROGLO2( "TROGLO2" );
static const trait_id trait_TROGLO3( "TROGLO3" );
static const std::string title_STATS = translate_marker( "STATS" );
static const std::string title_ENCUMB = translate_marker( "ENCUMBRANCE AND WARMTH" );
static const std::string title_EFFECTS = translate_marker( "EFFECTS" );
static const std::string title_SPEED = translate_marker( "SPEED" );
static const std::string title_SKILLS = translate_marker( "SKILLS" );
static const std::string title_BIONICS = translate_marker( "BIONICS" );
static const std::string title_TRAITS = translate_marker( "TRAITS" );
static const std::string title_PROFICIENCIES = translate_marker( "PROFICIENCIES" );
// use this instead of having to type out 26 spaces like before
static const std::string header_spaces( 26, ' ' );
static const unsigned int grid_width = 26;
// Rescale temperature value to one that the player sees
static int temperature_print_rescaling( int temp )
{
return ( temp / 100.0 ) * 2 - 100;
}
static bool should_combine_bps( const Character &p, const bodypart_id &l, const bodypart_id &r,
const item *selected_clothing )
{
const encumbrance_data &enc_l = p.get_part_encumbrance_data( l );
const encumbrance_data &enc_r = p.get_part_encumbrance_data( r );
return l != r && // are different parts
l == r->opposite_part && r == l->opposite_part && // are complementary parts
// same encumbrance & temperature
enc_l == enc_r &&
temperature_print_rescaling( p.get_part_temp_conv( l ) ) == temperature_print_rescaling(
p.get_part_temp_conv( r ) ) &&
// selected_clothing covers both or neither parts
( !selected_clothing || ( selected_clothing->covers( l ) == selected_clothing->covers( r ) ) ) &&
// they have the same HP
p.get_part_hp_cur( l ) == p.get_part_hp_cur( r );
}
static std::vector<std::pair<bodypart_id, bool>> list_and_combine_bps( const Character &p,
const item *selected_clothing )
{
// bool represents whether the part has been combined with its other half
std::vector<std::pair<bodypart_id, bool>> bps;
for( const bodypart_id &bp : p.get_all_body_parts( get_body_part_flags::sorted ) ) {
// assuming that a body part has at most one other half
if( should_combine_bps( p, bp, bp->opposite_part.id(), selected_clothing ) ) {
if( std::find( bps.begin(), bps.end(), std::pair<bodypart_id, bool>( bp->opposite_part.id(),
true ) ) == bps.end() ) {
// only add one
bps.emplace_back( bp, true );
}
} else {
bps.emplace_back( bp, false );
}
}
return bps;
}
static std::pair<int, int> subindex_around_cursor(
const int num_entries, const int available_space, const int cursor_pos, const bool focused )
/**
* Return indexes [start, end) that should be displayed from list long `num_entries`,
* given that cursor is at position `cursor_pos` and we have `available_space` spaces.
*
* Example:
* num_entries = 6, available_space = 3, cursor_pos = 2, focused = true;
* so choose 3 from indexes [0, 1, 2, 3, 4, 5]
* return {1, 4}
*/
{
if( !focused || num_entries <= available_space ) {
return std::make_pair( 0, std::min( available_space, num_entries ) );
}
int slice_start = std::min( std::max( 0, cursor_pos - available_space / 2 ),
num_entries - available_space );
return std::make_pair( slice_start, slice_start + available_space );
}
void Character::print_encumbrance( const catacurses::window &win, const int line,
const item *const selected_clothing ) const
{
// bool represents whether the part has been combined with its other half
const std::vector<std::pair<bodypart_id, bool>> bps = list_and_combine_bps( *this,
selected_clothing );
// width/height excluding title & scrollbar
const int height = getmaxy( win ) - 1;
const bool do_draw_scrollbar = height < static_cast<int>( bps.size() );
const int width = getmaxx( win ) - ( do_draw_scrollbar ? 1 : 0 );
// index of the first printed bodypart from `bps`
const int firstline = clamp( line - height / 2, 0, std::max( 0,
static_cast<int>( bps.size() ) - height ) );
/*** I chose to instead only display X+Y instead of X+Y=Z. More room was needed ***
*** for displaying triple digit encumbrance, due to new encumbrance system. ***
*** If the player wants to see the total without having to do them maths, the ***
*** armor layers ui shows everything they want :-) -Davek ***/
for( int i = 0; i < height; ++i ) {
int thisline = firstline + i;
if( thisline < 0 ) {
continue;
}
if( static_cast<size_t>( thisline ) >= bps.size() ) {
break;
}
const bodypart_id &bp = bps[thisline].first;
const bool combine = bps[thisline].second;
const encumbrance_data &e = get_part_encumbrance_data( bp );
const bool highlighted = selected_clothing ? selected_clothing->covers( bp ) : false;
std::string out = body_part_name_as_heading( bp, combine ? 2 : 1 );
if( utf8_width( out ) > 7 ) {
out = utf8_truncate( out, 7 );
}
// Two different highlighting schemes, highlight if the line is selected as per line being set.
// Make the text green if this part is covered by the passed in item.
nc_color limb_color = thisline == line ?
( highlighted ? h_green : h_light_gray ) :
( highlighted ? c_green : c_light_gray );
mvwprintz( win, point( 1, 1 + i ), limb_color, "%s", out );
// accumulated encumbrance from clothing, plus extra encumbrance from layering
int column = std::max( 10, ( width / 2 ) - 3 ); //Ideally the encumbrance data is centred
mvwprintz( win, point( column, 1 + i ), display::encumb_color( e.encumbrance ), "%3d",
e.encumbrance - e.layer_penalty );
// separator in low toned color
column += 3; //Prepared for 3-digit encumbrance
mvwprintz( win, point( column, 1 + i ), c_light_gray, "+" );
column += 1; // "+"
// take into account the new encumbrance system for layers
mvwprintz( win, point( column, 1 + i ), display::encumb_color( e.encumbrance ), "%-3d",
e.layer_penalty );
// print warmth, tethered to right hand side of the window
mvwprintz( win, point( width - 6, 1 + i ), display::bodytemp_color( *this, bp ), "(% 3d)",
temperature_print_rescaling( get_part_temp_conv( bp ) ) );
}
draw_scrollbar( win, firstline, height, bps.size(), point( width, 1 ), c_white, true );
}
static nc_color limb_score_current_color( float cur_score, float bp_score )
{
if( cur_score < bp_score * 0.25 ) {
return c_brown;
}
if( cur_score < bp_score * 0.5 ) {
return c_light_red;
}
if( cur_score < bp_score * 0.8 ) {
return c_yellow;
}
return c_white;
}
static std::string get_score_text( const std::string &sc_name, float cur_score, float bp_score )
{
if( std::abs( bp_score ) <= std::numeric_limits<float>::epsilon() ) {
return std::string();
}
nc_color score_c = limb_score_current_color( cur_score, bp_score );
std::string sc_txt = colorize( string_format( "%.2f (%.f%%)", cur_score,
cur_score * 100.f / bp_score ), score_c );
//~ 1$ = name of the limb score (ex: Balance), 2$ = current score value (colored)
return string_format( _( "%1$s score: %2$s" ), sc_name, sc_txt );
}
static std::vector<std::string> get_encumbrance_description( const Character &you,
const bodypart_id &bp )
{
std::vector<std::string> s;
const bodypart *part = you.get_part( bp );
if( !bp->encumb_text.empty() ) {
s.emplace_back( colorize( string_format( _( "Encumbrance effects: %s" ), bp->encumb_text ),
c_magenta ) );
}
if( bp->encumb_impacts_dodge && you.is_avatar() ) {
int dodge = get_avatar().limb_dodge_encumbrance();
nc_color dodge_c = dodge > 10 ? c_light_red : dodge > 5 ? c_yellow : c_white;
std::string dodge_str = colorize( string_format( "-%d", dodge ), dodge_c );
s.emplace_back( string_format( _( "Encumbrance dodge modifier: %s" ), dodge_str ) );
}
for( const limb_score &sc : limb_score::get_all() ) {
if( !bp->has_limb_score( sc.getId() ) ) {
continue;
}
float cur_score = part->get_limb_score( sc.getId() );
float bp_score = bp->get_limb_score( sc.getId() );
s.emplace_back( get_score_text( sc.name().translated(), cur_score, bp_score ) );
}
for( const character_modifier &mod : character_modifier::get_all() ) {
for( const auto &sc : mod.use_limb_scores() ) {
if( sc.second == 0.0f || sc.first.is_null() || !bp->has_limb_score( sc.first ) ) {
continue;
}
std::string desc = mod.description().translated();
std::string valstr = colorize( string_format( "%.2f", mod.modifier( you ) ),
limb_score_current_color( part->get_limb_score( sc.first ) * sc.second,
bp->get_limb_score( sc.first ) * sc.second ) );
s.emplace_back( string_format( "%s: %s%s", desc, mod.mod_type_str(), valstr ) );
}
}
return s;
}
static bool is_cqb_skill( const skill_id &id )
{
// TODO: this skill list here is used in other places as well. Useless redundancy and
// dependency. Maybe change it into a flag of the skill that indicates it's a skill used
// by the bionic?
static const std::array<skill_id, 5> cqb_skills = { {
skill_melee, skill_unarmed, skill_cutting,
skill_bashing, skill_stabbing,
}
};
return std::find( cqb_skills.begin(), cqb_skills.end(), id ) != cqb_skills.end();
}
namespace
{
enum class player_display_tab : int {
stats,
encumbrance,
skills,
traits,
bionics,
effects,
proficiencies,
num_tabs,
};
} // namespace
static player_display_tab next_tab( const player_display_tab tab )
{
if( static_cast<int>( tab ) + 1 < static_cast<int>( player_display_tab::num_tabs ) ) {
return static_cast<player_display_tab>( static_cast<int>( tab ) + 1 );
} else {
return static_cast<player_display_tab>( 0 );
}
}
static player_display_tab prev_tab( const player_display_tab tab )
{
if( static_cast<int>( tab ) > 0 ) {
return static_cast<player_display_tab>( static_cast<int>( tab ) - 1 );
} else {
return static_cast<player_display_tab>( static_cast<int>( player_display_tab::num_tabs ) - 1 );
}
}
static void draw_proficiencies_tab( const catacurses::window &win, const unsigned line,
const Character &guy, const player_display_tab curtab,
const input_context &ctxt )
{
werase( win );
const std::vector<display_proficiency> profs = guy.display_proficiencies();
const bool focused = curtab == player_display_tab::proficiencies;
const nc_color title_color = focused ? h_light_gray : c_light_gray;
center_print( win, 0, title_color, string_format( "[<color_yellow>%s</color>] %s",
ctxt.get_desc( "VIEW_PROFICIENCIES" ), _( title_PROFICIENCIES ) ) );
const int height = getmaxy( win ) - 1;
const bool do_draw_scrollbar = height < static_cast<int>( profs.size() );
const int width = getmaxx( win ) - 1 - ( do_draw_scrollbar ? 1 : 0 ); // -1 for beginning space
const std::pair<const int, const int> range = subindex_around_cursor( profs.size(), height, line,
focused );
for( size_t i = range.first; i < static_cast<size_t>( range.second ); ++i ) {
std::string name;
const display_proficiency &cur = profs[i];
if( !cur.known && cur.id->can_learn() ) {
name = string_format( "%s %2.0f%%",
left_justify( trim_by_length( cur.id->name(), width - 4 ), width - 4 ),
std::floor( cur.practice * 100 ) );
} else {
name = trim_by_length( cur.id->name(), width );
}
const nc_color col = focused && i == line ? hilite( cur.color ) : cur.color;
nc_color col_cur = col; // make non const copy
print_colored_text( win, point( 1, 1 + i - range.first ), col_cur, col, name );
}
draw_scrollbar( win, range.first, height, profs.size(), point( width + 1, 1 ), c_white, true );
wnoutrefresh( win );
}
static void draw_proficiencies_info( const catacurses::window &w_info, const unsigned line,
const Character &guy )
{
werase( w_info );
const std::vector<display_proficiency> profs = guy.display_proficiencies();
if( line < profs.size() ) {
const display_proficiency &cur = profs[line];
std::string progress;
if( cur.known ) {
progress = _( "You know this proficiency." );
} else {
progress = string_format( _( "You are %2.1f%% of the way towards learning this proficiency." ),
cur.practice * 100 );
if( debug_mode ) {
progress += string_format( "\nYou have spent %s practicing this proficiency.",
to_string( cur.spent ) );
}
}
int y = 0;
y += fold_and_print( w_info, point( 1, y ), getmaxx( w_info ) - 1, cur.color, cur.id->name() );
y += fold_and_print( w_info, point( 1, y ), getmaxx( w_info ) - 1, c_cyan, progress );
fold_and_print( w_info, point( 1, y ), getmaxx( w_info ) - 1, c_white, cur.id->description() );
}
wnoutrefresh( w_info );
}
static void draw_stats_tab( const catacurses::window &w_stats, const Character &you,
const unsigned line, const player_display_tab curtab, const input_context &ctxt )
{
werase( w_stats );
const nc_color title_col = curtab == player_display_tab::stats ? h_light_gray : c_light_gray;
center_print( w_stats, 0, title_col,
string_format( "[<color_yellow>%s</color>] %s",
ctxt.get_desc( "VIEW_BODYSTAT" ), _( title_STATS ) ) );
const auto line_color = [curtab, line]( const unsigned line_to_draw ) {
if( curtab == player_display_tab::stats && line == line_to_draw ) {
return h_light_gray;
} else {
return c_light_gray;
}
};
// Stats
const auto display_stat = [&w_stats]( const char *name, int cur, int max, int line_n,
const nc_color & col ) {
nc_color cstatus;
if( cur <= 0 ) {
cstatus = c_dark_gray;
} else if( cur < max / 2 ) {
cstatus = c_red;
} else if( cur < max ) {
cstatus = c_light_red;
} else if( cur == max ) {
cstatus = c_white;
} else if( cur < max * 1.5 ) {
cstatus = c_light_green;
} else {
cstatus = c_green;
}
mvwprintz( w_stats, point( 1, line_n ), col, name );
mvwprintz( w_stats, point( 18, line_n ), cstatus, "%2d", cur );
mvwprintz( w_stats, point( 21, line_n ), c_light_gray, "(%2d)", max );
};
display_stat( _( "Strength:" ), you.get_str(), you.get_str_base(), 1, line_color( 0 ) );
display_stat( _( "Dexterity:" ), you.get_dex(), you.get_dex_base(), 2, line_color( 1 ) );
display_stat( _( "Intelligence:" ), you.get_int(), you.get_int_base(), 3, line_color( 2 ) );
display_stat( _( "Perception:" ), you.get_per(), you.get_per_base(), 4, line_color( 3 ) );
mvwprintz( w_stats, point( 1, 5 ), line_color( 4 ), _( "Weight:" ) );
right_print( w_stats, 5, 1, c_light_gray, display::weight_string( you ) );
mvwprintz( w_stats, point( 1, 6 ), line_color( 5 ), _( "Height:" ) );
mvwprintz( w_stats, point( 25 - utf8_width( you.height_string() ), 6 ), c_light_gray,
you.height_string() );
mvwprintz( w_stats, point( 1, 7 ), line_color( 6 ), _( "Age:" ) );
mvwprintz( w_stats, point( 25 - utf8_width( you.age_string() ), 7 ), c_light_gray,
you.age_string() );
mvwprintz( w_stats, point( 1, 8 ), line_color( 7 ), _( "Blood type:" ) );
mvwprintz( w_stats, point( 25 - utf8_width( io::enum_to_string( you.my_blood_type ) +
( you.blood_rh_factor ? "+" : "-" ) ), 8 ),
c_light_gray,
io::enum_to_string( you.my_blood_type ) + ( you.blood_rh_factor ? "+" : "-" ) );
wnoutrefresh( w_stats );
}
static void draw_stats_info( const catacurses::window &w_info, const Character &you,
const unsigned line )
{
werase( w_info );
nc_color col_temp = c_light_gray;
if( line == 0 ) {
// NOLINTNEXTLINE(cata-use-named-point-constants)
fold_and_print( w_info, point( 1, 0 ), FULL_SCREEN_WIDTH - 2, c_magenta,
_( "Strength affects your melee damage, the amount of weight you can carry, your total HP, "
"your resistance to many diseases, and the effectiveness of actions which require brute force." ) );
print_colored_text( w_info, point( 1, 3 ), col_temp, c_light_gray,
string_format( _( "Base HP: <color_white>%d</color>" ),
you.get_part_hp_max( you.get_root_body_part() ) ) );
print_colored_text( w_info, point( 1, 4 ), col_temp, c_light_gray,
string_format( _( "Carry weight (%s): <color_white>%.1f</color>" ), weight_units(),
convert_weight( you.weight_capacity() ) ) );
print_colored_text( w_info, point( 1, 5 ), col_temp, c_light_gray,
string_format( _( "Bash damage: <color_white>%.1f</color>" ), you.bonus_damage( false ) ) );
} else if( line == 1 ) {
// NOLINTNEXTLINE(cata-use-named-point-constants)
fold_and_print( w_info, point( 1, 0 ), FULL_SCREEN_WIDTH - 2, c_magenta,
_( "Dexterity affects your chance to hit in melee combat, helps you steady your "
"gun for ranged combat, and enhances many actions that require finesse." ) );
print_colored_text( w_info, point( 1, 3 ), col_temp, c_light_gray,
string_format( _( "Melee to-hit bonus: <color_white>%+.1lf</color>" ), you.get_melee_hit_base() ) );
print_colored_text( w_info, point( 1, 4 ), col_temp, c_light_gray,
string_format( _( "Ranged penalty: <color_white>%+d</color>" ),
-std::abs( you.ranged_dex_mod() ) ) );
print_colored_text( w_info, point( 1, 5 ), col_temp, c_light_gray,
string_format( _( "Throwing penalty per target's dodge: <color_white>%+d</color>" ),
you.throw_dispersion_per_dodge( false ) ) );
} else if( line == 2 ) {
// NOLINTNEXTLINE(cata-use-named-point-constants)
fold_and_print( w_info, point( 1, 0 ), FULL_SCREEN_WIDTH - 2, c_magenta,
_( "Intelligence is less important in most situations, but it is vital for more complex tasks like "
"electronics crafting. It also affects how much skill you can pick up from reading a book." ) );
print_colored_text( w_info, point( 1, 4 ), col_temp, c_light_gray,
string_format( _( "Read times: <color_white>%d%%</color>" ), you.read_speed() ) );
print_colored_text( w_info, point( 1, 5 ), col_temp, c_light_gray,
string_format( _( "Crafting bonus: <color_white>%d%%</color>" ), you.get_int() ) );
} else if( line == 3 ) {
// NOLINTNEXTLINE(cata-use-named-point-constants)
fold_and_print( w_info, point( 1, 0 ), FULL_SCREEN_WIDTH - 2, c_magenta,
_( "Perception is the most important stat for ranged combat. It's also used for "
"detecting traps and other things of interest." ) );
print_colored_text( w_info, point( 1, 4 ), col_temp, c_light_gray,
string_format( _( "Trap detection level: <color_white>%d</color>" ), you.get_per() ) );
if( you.ranged_per_mod() > 0 ) {
print_colored_text( w_info, point( 1, 5 ), col_temp, c_light_gray,
string_format( _( "Aiming penalty: <color_white>%+d</color>" ), -you.ranged_per_mod() ) );
}
} else if( line == 4 ) {
// NOLINTNEXTLINE(cata-use-named-point-constants)
const int lines = fold_and_print( w_info, point( 1, 0 ), FULL_SCREEN_WIDTH - 2, c_magenta,
_( "Your weight is a general indicator of how much fat your body has stored up,"
" which in turn shows how prepared you are to survive for a time without food."
" Having too much, or too little, can be unhealthy." ) );
fold_and_print( w_info, point( 1, 1 + lines ), FULL_SCREEN_WIDTH - 2, c_light_gray,
display::weight_long_description( you ) );
} else if( line == 5 ) {
// NOLINTNEXTLINE(cata-use-named-point-constants)
const int lines = fold_and_print( w_info, point( 1, 0 ), FULL_SCREEN_WIDTH - 2, c_magenta,
_( "Your height. Simply how tall you are." ) );
fold_and_print( w_info, point( 1, 1 + lines ), FULL_SCREEN_WIDTH - 2, c_light_gray,
you.height_string() );
} else if( line == 6 ) {
// NOLINTNEXTLINE(cata-use-named-point-constants)
const int lines = fold_and_print( w_info, point( 1, 0 ), FULL_SCREEN_WIDTH - 2, c_magenta,
_( "This is how old you are." ) );
fold_and_print( w_info, point( 1, 1 + lines ), FULL_SCREEN_WIDTH - 2, c_light_gray,
you.age_string() );
} else if( line == 7 ) {
// NOLINTNEXTLINE(cata-use-named-point-constants)
const int lines = fold_and_print( w_info, point( 1, 0 ), FULL_SCREEN_WIDTH - 2, c_magenta,
_( "This is your blood type and Rh factor." ) );
fold_and_print( w_info, point( 1, 1 + lines ), FULL_SCREEN_WIDTH - 2, c_light_gray,
string_format( _( "Blood type: %s" ), io::enum_to_string( you.my_blood_type ) ) );
fold_and_print( w_info, point( 1, 2 + lines ), FULL_SCREEN_WIDTH - 2, c_light_gray,
string_format( _( "Rh factor: %s" ),
you.blood_rh_factor ? _( "positive (+)" ) : _( "negative (-)" ) ) );
}
wnoutrefresh( w_info );
}
static void draw_encumbrance_tab( const catacurses::window &w_encumb, const Character &you,
const unsigned line, const player_display_tab curtab )
{
werase( w_encumb );
const bool is_current_tab = curtab == player_display_tab::encumbrance;
const nc_color title_col = is_current_tab ? h_light_gray : c_light_gray;
center_print( w_encumb, 0, title_col, _( title_ENCUMB ) );
if( is_current_tab ) {
you.print_encumbrance( w_encumb, line );
} else {
you.print_encumbrance( w_encumb );
}
wnoutrefresh( w_encumb );
}
static void draw_encumbrance_info( const catacurses::window &w_info, const Character &you,
const unsigned line, const unsigned info_line )
{
const std::vector<std::pair<bodypart_id, bool>> bps = list_and_combine_bps( you, nullptr );
werase( w_info );
bodypart_id bp;
if( line < bps.size() ) {
bp = bps[line].first;
}
const std::vector<std::string> s = get_encumbrance_description( you, bp );
const int winh = catacurses::getmaxy( w_info );
const bool do_scroll = s.size() > static_cast<unsigned>( std::abs( winh ) );
const int winw = FULL_SCREEN_WIDTH - ( do_scroll ? 3 : 2 );
const int fline = do_scroll ? info_line % ( s.size() + 1 - winh ) : 0;
const int lline = do_scroll ? fline + winh : s.size();
for( int i = fline; i < lline; i++ ) {
trim_and_print( w_info, point( 1, i - fline ), winw, c_light_gray, s[i] );
}
draw_scrollbar( w_info, fline, winh, s.size(), point( winw, 0 ), c_white, true );
wnoutrefresh( w_info );
}
static void draw_traits_tab( const catacurses::window &w_traits, const unsigned line,
const player_display_tab curtab, const std::vector<trait_and_var> &traitslist )
{
werase( w_traits );
const bool is_current_tab = curtab == player_display_tab::traits;
const nc_color title_col = is_current_tab ? h_light_gray : c_light_gray;
center_print( w_traits, 0, title_col, _( title_TRAITS ) );
const int height = getmaxy( w_traits ) - 1;
const bool do_draw_scrollbar = height < static_cast<int>( traitslist.size() );
const int width = getmaxx( w_traits ) - 1 - ( do_draw_scrollbar ? 1 : 0 );
const std::pair<const int, const int> range = subindex_around_cursor( traitslist.size(), height,
line, is_current_tab );
for( size_t i = range.first; i < static_cast<size_t>( range.second ); ++i ) {
const trait_and_var &cur = traitslist[i];
const nc_color color = cur.trait->get_display_color();
trim_and_print( w_traits, point( 1, static_cast<int>( 1 + i - range.first ) ), width,
is_current_tab && i == line ? hilite( color ) : color, cur.name() );
}
draw_scrollbar( w_traits, range.first, height, traitslist.size(), point( width + 1, 1 ), c_white,
true );
wnoutrefresh( w_traits );
}
static void draw_traits_info( const catacurses::window &w_info, const unsigned line,
const std::vector<trait_and_var> &traitslist )
{
werase( w_info );
if( line < traitslist.size() ) {
const trait_and_var &cur = traitslist[line];
// NOLINTNEXTLINE(cata-use-named-point-constants)
fold_and_print( w_info, point( 1, 0 ), FULL_SCREEN_WIDTH - 2, c_light_gray, string_format( "%s: %s",
colorize( cur.name(), cur.trait->get_display_color() ), cur.desc() ) );
}
wnoutrefresh( w_info );
}
static void draw_bionics_tab( const catacurses::window &w_bionics, const Character &you,
const unsigned line, const player_display_tab curtab, const std::vector<bionic> &bionicslist )
{
werase( w_bionics );
const bool is_current_tab = curtab == player_display_tab::bionics;
const nc_color title_col = is_current_tab ? h_light_gray : c_light_gray;
center_print( w_bionics, 0, title_col, _( title_BIONICS ) );
int power_amount;
std::string power_unit;
if( you.get_power_level() < 1_J ) {
power_amount = units::to_millijoule( you.get_power_level() );
power_unit = pgettext( "energy unit: millijoule", "mJ" );
} else if( you.get_power_level() < 1_kJ ) {
power_amount = units::to_joule( you.get_power_level() );
power_unit = pgettext( "energy unit: joule", "J" );
} else {
power_amount = units::to_kilojoule( you.get_power_level() );
power_unit = pgettext( "energy unit: kilojoule", "kJ" );
}
// NOLINTNEXTLINE(cata-use-named-point-constants)
trim_and_print( w_bionics, point( 1, 1 ), getmaxx( w_bionics ) - 1, c_white,
string_format( _( "Power: <color_light_blue>%1$d %2$s</color>"
" / <color_light_blue>%3$d kJ</color>" ),
power_amount, power_unit, units::to_kilojoule( you.get_max_power_level() ) ) );
const int height = getmaxy( w_bionics ) - 2; // -2 for headline and power_level
const bool do_draw_scrollbar = height < static_cast<int>( bionicslist.size() );
const int width = getmaxx( w_bionics ) - 1 - ( do_draw_scrollbar ? 1 : 0 );
const std::pair<const int, const int> range = subindex_around_cursor( bionicslist.size(), height,
line, is_current_tab );
for( size_t i = range.first; i < static_cast<size_t>( range.second ); ++i ) {
trim_and_print( w_bionics, point( 1, static_cast<int>( 2 + i - range.first ) ), width,
is_current_tab && i == line ? hilite( c_white ) : c_white, "%s", bionicslist[i].info().name );
}
draw_scrollbar( w_bionics, range.first, height, bionicslist.size(), point( width + 1, 2 ), c_white,
true );
wnoutrefresh( w_bionics );
}
static void draw_bionics_info( const catacurses::window &w_info, const unsigned line,
const std::vector<bionic> &bionicslist )
{
werase( w_info );
if( line < bionicslist.size() ) {
// NOLINTNEXTLINE(cata-use-named-point-constants)
fold_and_print( w_info, point( 1, 0 ), FULL_SCREEN_WIDTH - 2, c_light_gray, "%s",
bionicslist[line].info().description );
}
wnoutrefresh( w_info );
}
static void draw_effects_tab( const catacurses::window &w_effects, const unsigned line,
const player_display_tab curtab,
const std::vector<std::pair<std::string, std::string>> &effect_name_and_text )
{
werase( w_effects );
const bool is_current_tab = curtab == player_display_tab::effects;
const nc_color title_col = is_current_tab ? h_light_gray : c_light_gray;
center_print( w_effects, 0, title_col, _( title_EFFECTS ) );
const int height = getmaxy( w_effects ) - 1;
const bool do_draw_scrollbar = height < static_cast<int>( effect_name_and_text.size() );
const int width = getmaxx( w_effects ) - 1 - ( do_draw_scrollbar ? 1 : 0 );
const std::pair<const int, const int> range = subindex_around_cursor( effect_name_and_text.size(),
height, line, is_current_tab );
for( size_t i = range.first; i < static_cast<size_t>( range.second ); ++i ) {
trim_and_print( w_effects, point( 1, static_cast<int>( 1 + i - range.first ) ), width,
is_current_tab && i == line ? h_light_gray : c_light_gray, effect_name_and_text[i].first );
}
draw_scrollbar( w_effects, range.first, height, effect_name_and_text.size(), point( width + 1, 1 ),
c_white, true );
wnoutrefresh( w_effects );
}
static void draw_effects_info( const catacurses::window &w_info, const unsigned line,
const std::vector<std::pair<std::string, std::string>> &effect_name_and_text )
{
werase( w_info );
const size_t actual_size = effect_name_and_text.size();
if( line < actual_size ) {
// NOLINTNEXTLINE(cata-use-named-point-constants)
fold_and_print( w_info, point( 1, 0 ), FULL_SCREEN_WIDTH - 2, c_light_gray,
effect_name_and_text[line].second );
}
wnoutrefresh( w_info );
}
struct HeaderSkill {
const Skill *skill;
bool is_header;
HeaderSkill( const Skill *skill, bool is_header ): skill( skill ), is_header( is_header ) {
}
};
static void draw_skills_tab( const catacurses::window &w_skills,
Character &you, unsigned int line, const player_display_tab curtab,
std::vector<HeaderSkill> &skillslist,
const size_t skill_win_size_y )
{
const int col_width = 25;
if( line == 0 ) { //can't point to a header;
line = 1;
}
werase( w_skills );
const bool is_current_tab = curtab == player_display_tab::skills;
nc_color cstatus = is_current_tab ? h_light_gray : c_light_gray;
center_print( w_skills, 0, cstatus, _( title_SKILLS ) );
size_t min = 0;
size_t max = 0;
const size_t half_y = ( skill_win_size_y - 1 ) / 2;
if( !is_current_tab || line <= half_y ) {
min = 0;
} else if( line >= skillslist.size() - half_y ) {
min = ( skillslist.size() < skill_win_size_y - 1 ? 0 : skillslist.size() -
skill_win_size_y + 1 );
} else {
min = line - half_y;
}
max = std::min( min + skill_win_size_y - 1, skillslist.size() );
int y_pos = 1;
for( size_t i = min; i < max; ++i, ++y_pos ) {
const Skill *aSkill = skillslist[i].skill;
const SkillLevel &level = you.get_skill_level_object( aSkill->ident() );
if( skillslist[i].is_header ) {
const SkillDisplayType t = SkillDisplayType::get_skill_type( aSkill->display_category() );
std::string type_name = t.display_string();
mvwprintz( w_skills, point( 0, y_pos ), c_light_gray, header_spaces );
center_print( w_skills, y_pos, c_yellow, type_name );
} else {
const bool can_train = level.can_train();
const bool training = level.isTraining();
const bool rusty = level.isRusty();
int exercise = level.exercise();
int level_num = level.level();
bool locked = false;
if( you.has_active_bionic( bio_cqb ) && is_cqb_skill( aSkill->ident() ) ) {
level_num = 5;
exercise = 0;
locked = true;
}
if( is_current_tab && i == line ) {
if( locked ) {
cstatus = h_yellow;
} else if( !can_train ) {
cstatus = rusty ? h_light_red : h_white;
} else if( exercise >= 100 ) {
cstatus = training ? h_pink : h_magenta;
} else if( rusty ) {
cstatus = training ? h_light_red : h_red;
} else {
cstatus = training ? h_light_blue : h_blue;
}
mvwprintz( w_skills, point( 1, y_pos ), cstatus, std::string( col_width, ' ' ) );
} else {
if( locked ) {
cstatus = c_yellow;
} else if( rusty ) {
cstatus = training ? c_light_red : c_red;
} else if( !can_train ) {
cstatus = c_white;
} else {
cstatus = training ? c_light_blue : c_blue;
}
mvwprintz( w_skills, point( 1, y_pos ), c_light_gray, std::string( col_width, ' ' ) );
}
mvwprintz( w_skills, point( 1, y_pos ), cstatus, "%s:", aSkill->name() );
if( aSkill->ident() == skill_dodge ) {
mvwprintz( w_skills, point( 14, y_pos ), cstatus, "%4.1f/%-2d(%2d%%)",
you.get_dodge(),
level_num,
( exercise < 0 ? 0 : exercise ) );
} else {
mvwprintz( w_skills, point( 19, y_pos ), cstatus, "%-2d(%2d%%)",
level_num,
( exercise < 0 ? 0 : exercise ) );
}
}
}
if( is_current_tab && skillslist.size() > skill_win_size_y - 1 ) {
draw_scrollbar( w_skills, line - 1, skill_win_size_y - 1, skillslist.size() - 1,
// NOLINTNEXTLINE(cata-use-named-point-constants)
point( 0, 1 ) );
}
wnoutrefresh( w_skills );
}
static void draw_skills_info( const catacurses::window &w_info, const Character &you,
unsigned int line,
const std::vector<HeaderSkill> &skillslist )
{
werase( w_info );
if( line < 1 ) {
line = 1;
}
const Skill *selectedSkill = nullptr;
if( line < skillslist.size() && !skillslist[line].is_header ) {
selectedSkill = skillslist[line].skill;
}
werase( w_info );
if( selectedSkill ) {
const SkillLevel &level = you.get_skill_level_object( selectedSkill->ident() );
std::string info_text = selectedSkill->description();
if( level.isRusty() ) {
info_text = string_format( _( "%s\n\nKnowledge level: %d (%d%%)" ), info_text,
level.knowledgeLevel(), level.knowledgeExperience() );
}
// NOLINTNEXTLINE(cata-use-named-point-constants)
fold_and_print( w_info, point( 1, 0 ), FULL_SCREEN_WIDTH - 2, c_light_gray, info_text );
}
wnoutrefresh( w_info );
}
static void draw_speed_tab( const catacurses::window &w_speed,
const Character &you,
const std::map<std::string, int> &speed_effects )
{
werase( w_speed );
// Finally, draw speed.
center_print( w_speed, 0, c_light_gray, _( title_SPEED ) );
// NOLINTNEXTLINE(cata-use-named-point-constants)
mvwprintz( w_speed, point( 1, 1 ), c_light_gray, _( "Base Move Cost:" ) );
mvwprintz( w_speed, point( 1, 2 ), c_light_gray, _( "Current Speed:" ) );
int newmoves = you.get_speed();
int pen = 0;
unsigned int line = 3;
if( you.weight_carried() > you.weight_capacity() ) {
pen = 25 * ( you.weight_carried() - you.weight_capacity() ) / you.weight_capacity();
mvwprintz( w_speed, point( 1, line ), c_red,
pgettext( "speed penalty", "Overburdened -%2d%%" ), pen );
++line;
}
pen = you.get_pain_penalty().speed;
if( pen >= 1 ) {
mvwprintz( w_speed, point( 1, line ), c_red,
pgettext( "speed penalty", "Pain -%2d%%" ), pen );
++line;
}
if( you.get_thirst() > 40 ) {
pen = std::abs( Character::thirst_speed_penalty( you.get_thirst() ) );
mvwprintz( w_speed, point( 1, line ), c_red,
pgettext( "speed penalty", "Thirst -%2d%%" ), pen );
++line;
}
if( you.kcal_speed_penalty() < 0 ) {
pen = std::abs( you.kcal_speed_penalty() );
const std::string inanition = you.get_bmi() < character_weight_category::underweight ?
_( "Starving" ) : _( "Underfed" );
//~ %s: Starving/Underfed (already left-justified), %2d: speed penalty
mvwprintz( w_speed, point( 1, line ), c_red, pgettext( "speed penalty", "%s-%2d%%" ),
left_justify( inanition, 20 ), pen );
++line;
}
if( you.has_trait( trait_SUNLIGHT_DEPENDENT ) && !g->is_in_sunlight( you.pos() ) ) {
pen = ( g->light_level( you.posz() ) >= 12 ? 5 : 10 );
mvwprintz( w_speed, point( 1, line ), c_red,
pgettext( "speed penalty", "Out of Sunlight -%2d%%" ), pen );
++line;
}
const float temperature_speed_modifier = you.mutation_value( "temperature_speed_modifier" );
if( temperature_speed_modifier != 0 ) {
nc_color pen_color;
std::string pen_sign;
const int player_local_temp = get_weather().get_temperature( you.pos() );
if( you.has_trait( trait_COLDBLOOD4 ) && player_local_temp > 65 ) {
pen_color = c_green;
pen_sign = "+";
} else if( player_local_temp < 65 ) {
pen_color = c_red;
pen_sign = "-";
}
if( !pen_sign.empty() ) {
pen = ( player_local_temp - 65 ) * temperature_speed_modifier;
mvwprintz( w_speed, point( 1, line ), pen_color,
//~ %s: sign of bonus/penalty, %2d: speed bonus/penalty
pgettext( "speed modifier", "Cold-Blooded %s%2d%%" ), pen_sign, std::abs( pen ) );
++line;
}
}
const int speed_modifier = you.get_enchantment_speed_bonus();
if( speed_modifier != 0 ) {
mvwprintz( w_speed, point( 1, line ), c_green,
pgettext( "speed bonus", "Bio/Mut/Effects +%2d" ), speed_modifier );
++line;
}
for( const std::pair<const std::string, int> &speed_effect : speed_effects ) {
nc_color col = ( speed_effect.second > 0 ? c_green : c_red );
mvwprintz( w_speed, point( 1, line ), col, "%s", speed_effect.first );
mvwprintz( w_speed, point( 21, line ), col, ( speed_effect.second > 0 ? "+" : "-" ) );
mvwprintz( w_speed, point( std::abs( speed_effect.second ) >= 10 ? 22 : 23, line ), col, "%d%%",
std::abs( speed_effect.second ) );
++line;
}
int runcost = you.run_cost( 100 );
nc_color col = ( runcost <= 100 ? c_green : c_red );
mvwprintz( w_speed, point( 21 + ( runcost >= 100 ? 0 : ( runcost < 10 ? 2 : 1 ) ), 1 ), col,
"%d", runcost );
col = ( newmoves >= 100 ? c_green : c_red );
mvwprintz( w_speed, point( 21 + ( newmoves >= 100 ? 0 : ( newmoves < 10 ? 2 : 1 ) ), 2 ), col,
"%d", newmoves );
wnoutrefresh( w_speed );
}
static void draw_info_window( const catacurses::window &w_info, const Character &you,
const unsigned line, const unsigned info_line, const player_display_tab curtab,
const std::vector<trait_and_var> &traitslist,
const std::vector<bionic> &bionicslist,
const std::vector<std::pair<std::string, std::string>> &effect_name_and_text,
const std::vector<HeaderSkill> &skillslist )
{
switch( curtab ) {
case player_display_tab::stats:
draw_stats_info( w_info, you, line );
break;
case player_display_tab::encumbrance:
draw_encumbrance_info( w_info, you, line, info_line );
break;
case player_display_tab::skills:
draw_skills_info( w_info, you, line, skillslist );
break;
case player_display_tab::traits:
draw_traits_info( w_info, line, traitslist );
break;
case player_display_tab::bionics:
draw_bionics_info( w_info, line, bionicslist );
break;
case player_display_tab::effects:
draw_effects_info( w_info, line, effect_name_and_text );
break;
case player_display_tab::proficiencies:
draw_proficiencies_info( w_info, line, you );
break;
case player_display_tab::num_tabs:
cata_fatal( "Invalid curtab" );
}
}
static void draw_tip( const catacurses::window &w_tip, const Character &you,
const std::string &race, const input_context &ctxt, bool customize_character )
{
werase( w_tip );
// Print name and header
if( you.custom_profession.empty() ) {
if( you.crossed_threshold() ) {
//~ player info window: 1s - name, 2s - gender, 3s - Prof or Mutation name
mvwprintz( w_tip, point_zero, c_white, _( " %1$s | %2$s | %3$s" ), you.get_name(),
you.male ? _( "Male" ) : _( "Female" ), race );
} else if( you.prof == nullptr || you.prof == profession::generic() ) {
// Regular person. Nothing interesting.
//~ player info window: 1s - name, 2s - gender '|' - field separator.
mvwprintz( w_tip, point_zero, c_white, _( " %1$s | %2$s" ), you.get_name(),
you.male ? _( "Male" ) : _( "Female" ) );
} else {
mvwprintz( w_tip, point_zero, c_white, _( " %1$s | %2$s | %3$s" ), you.get_name(),
you.male ? _( "Male" ) : _( "Female" ),
you.prof->gender_appropriate_name( you.male ) );
}
} else {
mvwprintz( w_tip, point_zero, c_white, _( " %1$s | %2$s | %3$s" ), you.get_name(),
you.male ? _( "Male" ) : _( "Female" ), you.custom_profession );
}
if( customize_character ) {
right_print( w_tip, 0, 8, c_light_gray, string_format(
_( "[<color_yellow>%s</color>] Customize character" ),
ctxt.get_desc( "SWITCH_GENDER" ) ) );
}
right_print( w_tip, 0, 1, c_light_gray, string_format(
_( "[<color_yellow>%s</color>]" ),
ctxt.get_desc( "HELP_KEYBINDINGS" ) ) );
right_print( w_tip, 0, 0, c_light_gray, string_format( "%s", LINE_XOXO_S ) );
wnoutrefresh( w_tip );
}
static bool handle_player_display_action( Character &you, unsigned int &line,
unsigned int &info_line,
player_display_tab &curtab, input_context &ctxt, const ui_adaptor &ui_tip,
const ui_adaptor &ui_info, const ui_adaptor &ui_stats, const ui_adaptor &ui_encumb,
const ui_adaptor &ui_traits, const ui_adaptor &ui_bionics, const ui_adaptor &ui_effects,
const ui_adaptor &ui_skills, const ui_adaptor &ui_proficiencies,
std::vector<trait_and_var> &traitslist, const std::vector<bionic> &bionicslist,
const std::vector<std::pair<std::string, std::string>> &effect_name_and_text,
const std::vector<HeaderSkill> &skillslist, bool customize_character )
{
const auto invalidate_tab = [&]( const player_display_tab tab ) {
switch( tab ) {
case player_display_tab::stats:
ui_stats.invalidate_ui();
break;