-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
newcharacter.cpp
2660 lines (2389 loc) · 109 KB
/
newcharacter.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 "avatar.h" // IWYU pragma: associated
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <iterator>
#include <tuple>
#include <array>
#include <functional>
#include <list>
#include <map>
#include <memory>
#include <set>
#include <unordered_map>
#include <utility>
#include "addiction.h"
#include "bionics.h"
#include "cata_utility.h"
#include "catacharset.h"
#include "game.h"
#include "ime.h"
#include "input.h"
#include "json.h"
#include "mapsharing.h"
#include "martialarts.h"
#include "monster.h"
#include "mutation.h"
#include "name.h"
#include "options.h"
#include "output.h"
#include "path_info.h"
#include "profession.h"
#include "recipe_dictionary.h"
#include "rng.h"
#include "scenario.h"
#include "skill.h"
#include "start_location.h"
#include "string_formatter.h"
#include "string_input_popup.h"
#include "translations.h"
#include "ui.h"
#include "worldfactory.h"
#include "recipe.h"
#include "string_id.h"
#include "character.h"
#include "color.h"
#include "cursesdef.h"
#include "game_constants.h"
#include "inventory.h"
#include "optional.h"
#include "pimpl.h"
#include "type_id.h"
// Colors used in this file: (Most else defaults to c_light_gray)
#define COL_STAT_ACT c_white // Selected stat
#define COL_STAT_BONUS c_light_green // Bonus
#define COL_STAT_NEUTRAL c_white // Neutral Property
#define COL_STAT_PENALTY c_light_red // Penalty
#define COL_TR_GOOD c_green // Good trait descriptive text
#define COL_TR_GOOD_OFF_ACT c_light_gray // A toggled-off good trait
#define COL_TR_GOOD_ON_ACT c_light_green // A toggled-on good trait
#define COL_TR_GOOD_OFF_PAS c_dark_gray // A toggled-off good trait
#define COL_TR_GOOD_ON_PAS c_green // A toggled-on good trait
#define COL_TR_BAD c_red // Bad trait descriptive text
#define COL_TR_BAD_OFF_ACT c_light_gray // A toggled-off bad trait
#define COL_TR_BAD_ON_ACT c_light_red // A toggled-on bad trait
#define COL_TR_BAD_OFF_PAS c_dark_gray // A toggled-off bad trait
#define COL_TR_BAD_ON_PAS c_red // A toggled-on bad trait
#define COL_TR_NEUT c_brown // Neutral trait descriptive text
#define COL_TR_NEUT_OFF_ACT c_dark_gray // A toggled-off neutral trait
#define COL_TR_NEUT_ON_ACT c_yellow // A toggled-on neutral trait
#define COL_TR_NEUT_OFF_PAS c_dark_gray // A toggled-off neutral trait
#define COL_TR_NEUT_ON_PAS c_brown // A toggled-on neutral trait
#define COL_SKILL_USED c_green // A skill with at least one point
#define COL_HEADER c_white // Captions, like "Profession items"
#define COL_NOTE_MAJOR c_green // Important note
#define COL_NOTE_MINOR c_light_gray // Just regular note
#define HIGH_STAT 14 // The point after which stats cost double
#define MAX_STAT 20 // The point after which stats can not be increased further
#define NEWCHAR_TAB_MAX 6 // The ID of the rightmost tab
static int skill_increment_cost( const Character &u, const skill_id &skill );
enum struct tab_direction {
NONE,
FORWARD,
BACKWARD,
QUIT
};
tab_direction set_points( const catacurses::window &w, avatar &u, points_left &points );
tab_direction set_stats( const catacurses::window &w, avatar &u, points_left &points );
tab_direction set_traits( const catacurses::window &w, avatar &u, points_left &points );
tab_direction set_scenario( const catacurses::window &w, avatar &u, points_left &points,
tab_direction direction );
tab_direction set_profession( const catacurses::window &w, avatar &u, points_left &points,
tab_direction direction );
tab_direction set_skills( const catacurses::window &w, avatar &u, points_left &points );
tab_direction set_description( const catacurses::window &w, avatar &you, bool allow_reroll,
points_left &points );
static cata::optional<std::string> query_for_template_name();
void reset_scenario( avatar &u, const scenario *scen );
void Character::pick_name( bool bUseDefault )
{
if( bUseDefault && !get_option<std::string>( "DEF_CHAR_NAME" ).empty() ) {
name = get_option<std::string>( "DEF_CHAR_NAME" );
} else {
name = Name::generate( male );
}
}
static matype_id choose_ma_style( const character_type type, const std::vector<matype_id> &styles,
const avatar &u )
{
if( type == PLTYPE_NOW || type == PLTYPE_FULL_RANDOM ) {
return random_entry( styles );
}
if( styles.size() == 1 ) {
return styles.front();
}
input_context ctxt( "MELEE_STYLE_PICKER" );
ctxt.register_action( "SHOW_DESCRIPTION" );
uilist menu;
menu.allow_cancel = false;
menu.text = string_format( _( "Select a style. (press %s for more info)\n"
"STR: %d, DEX: %d, PER: %d, INT: %d" ),
ctxt.get_desc( "SHOW_DESCRIPTION" ),
u.get_str(), u.get_dex(), u.get_per(), u.get_int() );
ma_style_callback callback( 0, styles );
menu.callback = &callback;
menu.input_category = "MELEE_STYLE_PICKER";
menu.additional_actions.emplace_back( "SHOW_DESCRIPTION", "" );
menu.desc_enabled = true;
for( auto &s : styles ) {
auto &style = s.obj();
menu.addentry_desc( style.name.translated(), style.description.translated() );
}
while( true ) {
menu.query( true );
auto &selected = styles[menu.ret];
if( query_yn( _( "Use this style?" ) ) ) {
return selected;
}
}
}
void avatar::randomize( const bool random_scenario, points_left &points, bool play_now )
{
const int max_trait_points = get_option<int>( "MAX_TRAIT_POINTS" );
// Reset everything to the defaults to have a clean state.
*this = avatar();
male = ( rng( 1, 100 ) > 50 );
if( !MAP_SHARING::isSharing() ) {
play_now ? pick_name() : pick_name( true );
} else {
name = MAP_SHARING::getUsername();
}
bool cities_enabled = world_generator->active_world->WORLD_OPTIONS["CITY_SIZE"].getValue() != "0";
if( random_scenario ) {
std::vector<const scenario *> scenarios;
for( const auto &scen : scenario::get_all() ) {
if( !scen.has_flag( "CHALLENGE" ) &&
( !scen.has_flag( "CITY_START" ) || cities_enabled ) ) {
scenarios.emplace_back( &scen );
}
}
g->scen = random_entry( scenarios );
} else if( !cities_enabled ) {
static const string_id<scenario> wilderness_only_scenario( "wilderness" );
g->scen = &wilderness_only_scenario.obj();
}
prof = g->scen->weighted_random_profession();
start_location = g->scen->random_start_location();
str_max = rng( 6, HIGH_STAT - 2 );
dex_max = rng( 6, HIGH_STAT - 2 );
int_max = rng( 6, HIGH_STAT - 2 );
per_max = rng( 6, HIGH_STAT - 2 );
points.stat_points = points.stat_points - str_max - dex_max - int_max - per_max;
points.skill_points = points.skill_points - prof->point_cost() - g->scen->point_cost();
// The default for each stat is 8, and that default does not cost any points.
// Values below give points back, values above require points. The line above has removed
// to many points, therefore they are added back.
points.stat_points += 8 * 4;
int num_gtraits = 0;
int num_btraits = 0;
int tries = 0;
add_traits( points ); // adds mandatory profession/scenario traits.
for( const auto &mut : my_mutations ) {
const mutation_branch &mut_info = mut.first.obj();
if( mut_info.profession ) {
continue;
}
// Scenario/profession traits do not cost any points, but they are counted toward
// the limit (MAX_TRAIT_POINTS)
if( mut_info.points >= 0 ) {
num_gtraits += mut_info.points;
} else {
num_btraits -= mut_info.points;
}
}
/* The loops variable is used to prevent the algorithm running in an infinite loop */
unsigned int loops = 0;
while( loops <= 100000 && ( !points.is_valid() || rng( -3, 20 ) > points.skill_points_left() ) ) {
loops++;
trait_id rn;
if( num_btraits < max_trait_points && one_in( 3 ) ) {
tries = 0;
do {
rn = random_bad_trait();
tries++;
} while( ( has_trait( rn ) || num_btraits - rn->points > max_trait_points ) &&
tries < 5 );
if( tries < 5 && !has_conflicting_trait( rn ) ) {
toggle_trait( rn );
points.trait_points -= rn->points;
num_btraits -= rn->points;
}
} else {
switch( rng( 1, 4 ) ) {
case 1:
if( str_max > 5 ) {
str_max--;
points.stat_points++;
}
break;
case 2:
if( dex_max > 5 ) {
dex_max--;
points.stat_points++;
}
break;
case 3:
if( int_max > 5 ) {
int_max--;
points.stat_points++;
}
break;
case 4:
if( per_max > 5 ) {
per_max--;
points.stat_points++;
}
break;
}
}
}
loops = 0;
while( points.has_spare() && loops <= 100000 ) {
const bool allow_stats = points.stat_points_left() > 0;
const bool allow_traits = points.trait_points_left() > 0 && num_gtraits < max_trait_points;
int r = rng( 1, 9 );
trait_id rn;
switch( r ) {
case 1:
case 2:
case 3:
case 4:
if( allow_traits ) {
rn = random_good_trait();
auto &mdata = rn.obj();
if( !has_trait( rn ) && points.trait_points_left() >= mdata.points &&
num_gtraits + mdata.points <= max_trait_points && !has_conflicting_trait( rn ) ) {
toggle_trait( rn );
points.trait_points -= mdata.points;
num_gtraits += mdata.points;
}
break;
}
/* fallthrough */
case 5:
if( allow_stats ) {
switch( rng( 1, 4 ) ) {
case 1:
if( str_max < HIGH_STAT ) {
str_max++;
points.stat_points--;
} else if( points.stat_points_left() >= 2 && str_max < MAX_STAT ) {
str_max++;
points.stat_points = points.stat_points - 2;
}
break;
case 2:
if( dex_max < HIGH_STAT ) {
dex_max++;
points.stat_points--;
} else if( points.stat_points_left() >= 2 && dex_max < MAX_STAT ) {
dex_max++;
points.stat_points = points.stat_points - 2;
}
break;
case 3:
if( int_max < HIGH_STAT ) {
int_max++;
points.stat_points--;
} else if( points.stat_points_left() >= 2 && int_max < MAX_STAT ) {
int_max++;
points.stat_points = points.stat_points - 2;
}
break;
case 4:
if( per_max < HIGH_STAT ) {
per_max++;
points.stat_points--;
} else if( points.stat_points_left() >= 2 && per_max < MAX_STAT ) {
per_max++;
points.stat_points = points.stat_points - 2;
}
break;
}
break;
}
/* fallthrough */
case 6:
case 7:
case 8:
case 9:
const skill_id aSkill = Skill::random_skill();
const int level = get_skill_level( aSkill );
if( level < points.skill_points_left() && level < MAX_SKILL && ( level <= MAX_SKILL ||
loops > 10000 ) ) {
points.skill_points -= skill_increment_cost( *this, aSkill );
// For balance reasons, increasing a skill from level 0 gives you 1 extra level for free
set_skill_level( aSkill, ( level == 0 ? 2 : level + 1 ) );
}
break;
}
loops++;
}
}
bool avatar::create( character_type type, const std::string &tempname )
{
weapon = item( "null", 0 );
prof = profession::generic();
g->scen = scenario::generic();
catacurses::window w;
if( type != PLTYPE_NOW && type != PLTYPE_FULL_RANDOM ) {
w = catacurses::newwin( TERMY, TERMX, point_zero );
}
int tab = 0;
points_left points = points_left();
switch( type ) {
case PLTYPE_CUSTOM:
break;
case PLTYPE_RANDOM:
//random scenario, default name if exist
randomize( true, points );
tab = NEWCHAR_TAB_MAX;
break;
case PLTYPE_NOW:
//default world, fixed scenario, random name
randomize( false, points, true );
break;
case PLTYPE_FULL_RANDOM:
//default world, random scenario, random name
randomize( true, points, true );
break;
case PLTYPE_TEMPLATE:
if( !load_template( tempname, points ) ) {
return false;
}
// We want to prevent recipes known by the template from being applied to the
// new character. The recipe list will be rebuilt when entering the game.
// Except if it is a character transfer template
if( points.limit != points_left::TRANSFER ) {
learned_recipes->clear();
}
tab = NEWCHAR_TAB_MAX;
break;
}
auto nameExists = [&]( const std::string & name ) {
return world_generator->active_world->save_exists( save_t::from_player_name( name ) ) &&
!query_yn( _( "A character with the name '%s' already exists in this world.\n"
"Saving will override the already existing character.\n\n"
"Continue anyways?" ), name );
};
const bool allow_reroll = type == PLTYPE_RANDOM;
tab_direction result = tab_direction::QUIT;
do {
if( !w ) {
// assert( type == PLTYPE_NOW );
// no window is created because "Play now" does not require any configuration
if( nameExists( name ) ) {
return false;
}
break;
}
werase( w );
wrefresh( w );
if( points.limit == points_left::TRANSFER ) {
tab = 6;
}
switch( tab ) {
case 0:
result = set_points( w, *this, points );
break;
case 1:
result = set_scenario( w, *this, points, result );
break;
case 2:
result = set_profession( w, *this, points, result );
break;
case 3:
result = set_stats( w, *this, points );
break;
case 4:
result = set_traits( w, *this, points );
break;
case 5:
result = set_skills( w, *this, points );
break;
case 6:
result = set_description( w, *this, allow_reroll, points );
break;
}
switch( result ) {
case tab_direction::NONE:
break;
case tab_direction::FORWARD:
tab++;
break;
case tab_direction::BACKWARD:
tab--;
break;
case tab_direction::QUIT:
tab = -1;
break;
}
if( !( tab >= 0 && tab <= NEWCHAR_TAB_MAX ) ) {
if( tab != -1 && nameExists( name ) ) {
tab = NEWCHAR_TAB_MAX;
} else {
break;
}
}
} while( true );
if( tab < 0 ) {
return false;
}
if( points.limit == points_left::TRANSFER ) {
return true;
}
save_template( _( "Last Character" ), points );
recalc_hp();
for( int i = 0; i < num_hp_parts; i++ ) {
hp_cur[i] = hp_max[i];
}
if( has_trait( trait_id( "SMELLY" ) ) ) {
scent = 800;
}
if( has_trait( trait_id( "WEAKSCENT" ) ) ) {
scent = 300;
}
weapon = item( "null", 0 );
// Grab the skills from the profession, if there are any
// We want to do this before the recipes
for( auto &e : prof->skills() ) {
mod_skill_level( e.first, e.second );
}
// setup staring bank money
cash = rng( -200000, 200000 );
if( has_trait( trait_id( "XS" ) ) ) {
set_stored_kcal( 10000 );
toggle_trait( trait_id( "XS" ) );
}
if( has_trait( trait_id( "XXXL" ) ) ) {
set_stored_kcal( 125000 );
toggle_trait( trait_id( "XXXL" ) );
}
// Learn recipes
for( const auto &e : recipe_dict ) {
const auto &r = e.second;
if( !r.has_flag( "SECRET" ) && !knows_recipe( &r ) && has_recipe_requirements( r ) ) {
learn_recipe( &r );
}
}
for( mtype_id elem : prof->pets() ) {
starting_pets.push_back( elem );
}
std::list<item> prof_items = prof->items( male, get_mutations() );
for( item &it : prof_items ) {
if( it.has_flag( "WET" ) ) {
it.active = true;
it.item_counter = 450; // Give it some time to dry off
}
// TODO: debugmsg if food that isn't a seed is inedible
if( it.has_flag( "no_auto_equip" ) ) {
it.unset_flag( "no_auto_equip" );
inv.push_back( it );
} else if( it.has_flag( "auto_wield" ) ) {
it.unset_flag( "auto_wield" );
if( !is_armed() ) {
wield( it );
} else {
inv.push_back( it );
}
} else if( it.is_armor() ) {
// TODO: debugmsg if wearing fails
wear_item( it, false );
} else {
inv.push_back( it );
}
if( it.is_book() ) {
items_identified.insert( it.typeId() );
}
}
std::vector<addiction> prof_addictions = prof->addictions();
for( std::vector<addiction>::const_iterator iter = prof_addictions.begin();
iter != prof_addictions.end(); ++iter ) {
addictions.push_back( *iter );
}
for( auto &bio : prof->CBMs() ) {
add_bionic( bio );
}
// Adjust current energy level to maximum
set_power_level( get_max_power_level() );
for( const trait_id &t : get_base_traits() ) {
std::vector<matype_id> styles;
for( const matype_id &s : t->initial_ma_styles ) {
if( !martial_arts_data.has_martialart( s ) ) {
styles.push_back( s );
}
}
if( !styles.empty() ) {
werase( w );
wrefresh( w );
const matype_id ma_type = choose_ma_style( type, styles, *this );
martial_arts_data.add_martialart( ma_type );
martial_arts_data.set_style( ma_type );
}
}
// Activate some mutations right from the start.
for( const trait_id &mut : get_mutations() ) {
const auto &branch = mut.obj();
if( branch.starts_active ) {
my_mutations[mut].powered = true;
}
}
prof->learn_spells( *this );
// Ensure that persistent morale effects (e.g. Optimist) are present at the start.
apply_persistent_morale();
return true;
}
static void draw_character_tabs( const catacurses::window &w, const std::string &sTab )
{
std::vector<std::string> tab_captions = {
_( "POINTS" ),
_( "SCENARIO" ),
_( "PROFESSION" ),
_( "STATS" ),
_( "TRAITS" ),
_( "SKILLS" ),
_( "DESCRIPTION" ),
};
draw_tabs( w, tab_captions, sTab );
draw_border_below_tabs( w );
for( int i = 1; i < TERMX - 1; i++ ) {
mvwputch( w, point( i, 4 ), BORDER_COLOR, LINE_OXOX );
}
mvwputch( w, point( 0, 4 ), BORDER_COLOR, LINE_XXXO ); // |-
mvwputch( w, point( TERMX - 1, 4 ), BORDER_COLOR, LINE_XOXX ); // -|
}
static void draw_points( const catacurses::window &w, points_left &points, int netPointCost = 0 )
{
// Clear line (except borders)
mvwprintz( w, point( 2, 3 ), c_black, std::string( getmaxx( w ) - 3, ' ' ) );
std::string points_msg = points.to_string();
int pMsg_length = utf8_width( remove_color_tags( points_msg ), true );
nc_color color = c_light_gray;
print_colored_text( w, point( 2, 3 ), color, c_light_gray, points_msg );
if( netPointCost > 0 ) {
mvwprintz( w, point( pMsg_length + 2, 3 ), c_red, "(-%d)", std::abs( netPointCost ) );
} else if( netPointCost < 0 ) {
mvwprintz( w, point( pMsg_length + 2, 3 ), c_green, "(+%d)", std::abs( netPointCost ) );
}
}
template <class Compare>
void draw_sorting_indicator( const catacurses::window &w_sorting, const input_context &ctxt,
Compare sorter )
{
const auto sort_order = sorter.sort_by_points ? _( "points" ) : _( "name" );
const auto sort_text = string_format(
_( "<color_white>Sort by: </color>%1$s (Press <color_light_green>%2$s</color> to change)" ),
sort_order, ctxt.get_desc( "SORT" ) );
fold_and_print( w_sorting, point_zero, ( TERMX / 2 ), c_light_gray, sort_text );
}
tab_direction set_points( const catacurses::window &w, avatar &, points_left &points )
{
tab_direction retval = tab_direction::NONE;
const int content_height = TERMY - 6;
catacurses::window w_description = catacurses::newwin( content_height, TERMX - 35,
point( 31 + getbegx( w ), 5 + getbegy( w ) ) );
draw_character_tabs( w, _( "POINTS" ) );
input_context ctxt( "NEW_CHAR_POINTS" );
ctxt.register_cardinal();
ctxt.register_action( "PREV_TAB" );
ctxt.register_action( "HELP_KEYBINDINGS" );
ctxt.register_action( "NEXT_TAB" );
ctxt.register_action( "QUIT" );
ctxt.register_action( "CONFIRM" );
const std::string point_pool = get_option<std::string>( "CHARACTER_POINT_POOLS" );
using point_limit_tuple = std::tuple<points_left::point_limit, std::string, std::string>;
std::vector<point_limit_tuple> opts;
const point_limit_tuple multi_pool = std::make_tuple( points_left::MULTI_POOL,
_( "Multiple pools" ),
_( "Stats, traits and skills have separate point pools.\n"
"Putting stat points into traits and skills is allowed and putting trait points into skills is allowed.\n"
"Scenarios and professions affect skill point pool" ) );
const point_limit_tuple one_pool = std::make_tuple( points_left::ONE_POOL, _( "Single pool" ),
_( "Stats, traits and skills share a single point pool." ) );
const point_limit_tuple freeform = std::make_tuple( points_left::FREEFORM, _( "Freeform" ),
_( "No point limits are enforced" ) );
if( point_pool == "multi_pool" ) {
opts = {{ multi_pool }};
} else if( point_pool == "no_freeform" ) {
opts = {{ multi_pool, one_pool }};
} else {
opts = {{ multi_pool, one_pool, freeform }};
}
int highlighted = 0;
do {
if( highlighted < 0 ) {
highlighted = opts.size() - 1;
} else if( highlighted >= static_cast<int>( opts.size() ) ) {
highlighted = 0;
}
const auto &cur_opt = opts[highlighted];
draw_points( w, points );
// Clear the bottom of the screen.
werase( w_description );
for( int i = 0; i < static_cast<int>( opts.size() ); i++ ) {
nc_color color = ( points.limit == std::get<0>( opts[i] ) ? COL_SKILL_USED : c_light_gray );
if( highlighted == i ) {
color = hilite( color );
}
mvwprintz( w, point( 2, 5 + i ), color, std::get<1>( opts[i] ) );
}
fold_and_print( w_description, point_zero, getmaxx( w_description ),
COL_SKILL_USED, std::get<2>( cur_opt ) );
wrefresh( w );
wrefresh( w_description );
const std::string action = ctxt.handle_input();
if( action == "DOWN" ) {
highlighted++;
} else if( action == "UP" ) {
highlighted--;
} else if( action == "PREV_TAB" && query_yn( _( "Return to main menu?" ) ) ) {
retval = tab_direction::BACKWARD;
} else if( action == "NEXT_TAB" ) {
retval = tab_direction::FORWARD;
} else if( action == "QUIT" && query_yn( _( "Return to main menu?" ) ) ) {
retval = tab_direction::QUIT;
} else if( action == "HELP_KEYBINDINGS" ) {
// Need to redraw since the help window obscured everything.
draw_character_tabs( w, _( "POINTS" ) );
} else if( action == "CONFIRM" ) {
points.limit = std::get<0>( cur_opt );
}
} while( retval == tab_direction::NONE );
return retval;
}
tab_direction set_stats( const catacurses::window &w, avatar &u, points_left &points )
{
unsigned char sel = 1;
const int iSecondColumn = 27;
input_context ctxt( "NEW_CHAR_STATS" );
ctxt.register_cardinal();
ctxt.register_action( "PREV_TAB" );
ctxt.register_action( "HELP_KEYBINDINGS" );
ctxt.register_action( "NEXT_TAB" );
ctxt.register_action( "QUIT" );
int read_spd;
catacurses::window w_description = catacurses::newwin( 8, TERMX - iSecondColumn - 1,
point( iSecondColumn + getbegx( w ), 6 + getbegy( w ) ) );
// There is no map loaded currently, so any access to the map will
// fail (player::suffer, called from player::reset_stats), might access
// the map:
// There are traits that check/change the radioactivity on the map,
// that check if in sunlight...
// Setting the position to -1 ensures that the INBOUNDS check in
// map.cpp is triggered. This check prevents access to invalid position
// on the map (like -1,0) and instead returns a dummy default value.
u.setx( -1 );
u.reset();
do {
werase( w );
draw_character_tabs( w, _( "STATS" ) );
fold_and_print( w, point( 2, 16 ), getmaxx( w ) - 4, COL_NOTE_MINOR,
_( " <color_light_green>%s</color> / <color_light_green>%s</color> to select a statistic.\n"
" <color_light_green>%s</color> to increase the statistic.\n"
" <color_light_green>%s</color> to decrease the statistic." ),
ctxt.get_desc( "UP" ), ctxt.get_desc( "DOWN" ),
ctxt.get_desc( "RIGHT" ), ctxt.get_desc( "LEFT" )
);
mvwprintz( w, point( 2, TERMY - 4 ), COL_NOTE_MAJOR,
_( "%s lets you view and alter keybindings." ), ctxt.get_desc( "HELP_KEYBINDINGS" ) );
mvwprintz( w, point( 2, TERMY - 3 ), COL_NOTE_MAJOR, _( "%s takes you to the next tab." ),
ctxt.get_desc( "NEXT_TAB" ) );
mvwprintz( w, point( 2, TERMY - 2 ), COL_NOTE_MAJOR, _( "%s returns you to the main menu." ),
ctxt.get_desc( "PREV_TAB" ) );
// This is description line, meaning its length excludes first column and border
const std::string clear_line( getmaxx( w ) - iSecondColumn - 1, ' ' );
mvwprintz( w, point( iSecondColumn, 3 ), c_black, clear_line );
for( int i = 6; i < 13; i++ ) {
mvwprintz( w, point( iSecondColumn, i ), c_black, clear_line );
}
draw_points( w, points );
mvwprintz( w, point( 2, 6 ), c_light_gray, _( "Strength:" ) );
mvwprintz( w, point( 16, 6 ), c_light_gray, "%2d", u.str_max );
mvwprintz( w, point( 2, 7 ), c_light_gray, _( "Dexterity:" ) );
mvwprintz( w, point( 16, 7 ), c_light_gray, "%2d", u.dex_max );
mvwprintz( w, point( 2, 8 ), c_light_gray, _( "Intelligence:" ) );
mvwprintz( w, point( 16, 8 ), c_light_gray, "%2d", u.int_max );
mvwprintz( w, point( 2, 9 ), c_light_gray, _( "Perception:" ) );
mvwprintz( w, point( 16, 9 ), c_light_gray, "%2d", u.per_max );
werase( w_description );
switch( sel ) {
case 1:
mvwprintz( w, point( 2, 6 ), COL_STAT_ACT, _( "Strength:" ) );
mvwprintz( w, point( 16, 6 ), COL_STAT_ACT, "%2d", u.str_max );
if( u.str_max >= HIGH_STAT ) {
mvwprintz( w, point( iSecondColumn, 3 ), c_light_red,
_( "Increasing Str further costs 2 points." ) );
}
u.recalc_hp();
mvwprintz( w_description, point_zero, COL_STAT_NEUTRAL, _( "Base HP: %d" ), u.hp_max[0] );
// NOLINTNEXTLINE(cata-use-named-point-constants)
mvwprintz( w_description, point( 0, 1 ), COL_STAT_NEUTRAL, _( "Carry weight: %.1f %s" ),
convert_weight( u.weight_capacity() ), weight_units() );
mvwprintz( w_description, point( 0, 2 ), COL_STAT_BONUS, _( "Melee damage bonus: %.1f" ),
u.bonus_damage( false ) );
fold_and_print( w_description, point( 0, 4 ), getmaxx( w_description ) - 1, COL_STAT_NEUTRAL,
_( "Strength also makes you more resistant to many diseases and poisons, and makes actions which require brute force more effective." ) );
break;
case 2:
mvwprintz( w, point( 2, 7 ), COL_STAT_ACT, _( "Dexterity:" ) );
mvwprintz( w, point( 16, 7 ), COL_STAT_ACT, "%2d", u.dex_max );
if( u.dex_max >= HIGH_STAT ) {
mvwprintz( w, point( iSecondColumn, 3 ), c_light_red,
_( "Increasing Dex further costs 2 points." ) );
}
mvwprintz( w_description, point_zero, COL_STAT_BONUS, _( "Melee to-hit bonus: +%.2f" ),
u.get_hit_base() );
// NOLINTNEXTLINE(cata-use-named-point-constants)
mvwprintz( w_description, point( 0, 1 ), COL_STAT_BONUS,
_( "Throwing penalty per target's dodge: +%d" ),
u.throw_dispersion_per_dodge( false ) );
if( u.ranged_dex_mod() != 0 ) {
mvwprintz( w_description, point( 0, 2 ), COL_STAT_PENALTY, _( "Ranged penalty: -%d" ),
std::abs( u.ranged_dex_mod() ) );
}
fold_and_print( w_description, point( 0, 4 ), getmaxx( w_description ) - 1, COL_STAT_NEUTRAL,
_( "Dexterity also enhances many actions which require finesse." ) );
break;
case 3:
mvwprintz( w, point( 2, 8 ), COL_STAT_ACT, _( "Intelligence:" ) );
mvwprintz( w, point( 16, 8 ), COL_STAT_ACT, "%2d", u.int_max );
if( u.int_max >= HIGH_STAT ) {
mvwprintz( w, point( iSecondColumn, 3 ), c_light_red,
_( "Increasing Int further costs 2 points." ) );
}
read_spd = u.read_speed( false );
mvwprintz( w_description, point_zero, ( read_spd == 100 ? COL_STAT_NEUTRAL :
( read_spd < 100 ? COL_STAT_BONUS : COL_STAT_PENALTY ) ),
_( "Read times: %d%%" ), read_spd );
// NOLINTNEXTLINE(cata-use-named-point-constants)
mvwprintz( w_description, point( 0, 1 ), COL_STAT_PENALTY, _( "Skill rust: %d%%" ),
u.rust_rate( false ) );
mvwprintz( w_description, point( 0, 2 ), COL_STAT_BONUS, _( "Crafting bonus: %2d%%" ),
u.get_int() );
fold_and_print( w_description, point( 0, 4 ), getmaxx( w_description ) - 1, COL_STAT_NEUTRAL,
_( "Intelligence is also used when crafting, installing bionics, and interacting with NPCs." ) );
break;
case 4:
mvwprintz( w, point( 2, 9 ), COL_STAT_ACT, _( "Perception:" ) );
mvwprintz( w, point( 16, 9 ), COL_STAT_ACT, "%2d", u.per_max );
if( u.per_max >= HIGH_STAT ) {
mvwprintz( w, point( iSecondColumn, 3 ), c_light_red,
_( "Increasing Per further costs 2 points." ) );
}
if( u.ranged_per_mod() > 0 ) {
mvwprintz( w_description, point_zero, COL_STAT_PENALTY, _( "Aiming penalty: -%d" ),
u.ranged_per_mod() );
}
fold_and_print( w_description, point( 0, 2 ), getmaxx( w_description ) - 1, COL_STAT_NEUTRAL,
_( "Perception is also used for detecting traps and other things of interest." ) );
break;
}
wrefresh( w );
wrefresh( w_description );
const std::string action = ctxt.handle_input();
if( action == "DOWN" ) {
if( sel < 4 ) {
sel++;
} else {
sel = 1;
}
} else if( action == "UP" ) {
if( sel > 1 ) {
sel--;
} else {
sel = 4;
}
} else if( action == "LEFT" ) {
if( sel == 1 && u.str_max > 4 ) {
if( u.str_max > HIGH_STAT ) {
points.stat_points++;
}
u.str_max--;
points.stat_points++;
} else if( sel == 2 && u.dex_max > 4 ) {
if( u.dex_max > HIGH_STAT ) {
points.stat_points++;
}
u.dex_max--;
points.stat_points++;
} else if( sel == 3 && u.int_max > 4 ) {
if( u.int_max > HIGH_STAT ) {
points.stat_points++;
}
u.int_max--;
points.stat_points++;
} else if( sel == 4 && u.per_max > 4 ) {
if( u.per_max > HIGH_STAT ) {
points.stat_points++;
}
u.per_max--;
points.stat_points++;
}
} else if( action == "RIGHT" ) {
if( sel == 1 && u.str_max < MAX_STAT ) {
points.stat_points--;
if( u.str_max >= HIGH_STAT ) {
points.stat_points--;
}
u.str_max++;
} else if( sel == 2 && u.dex_max < MAX_STAT ) {
points.stat_points--;
if( u.dex_max >= HIGH_STAT ) {
points.stat_points--;
}
u.dex_max++;
} else if( sel == 3 && u.int_max < MAX_STAT ) {
points.stat_points--;
if( u.int_max >= HIGH_STAT ) {
points.stat_points--;
}
u.int_max++;
} else if( sel == 4 && u.per_max < MAX_STAT ) {
points.stat_points--;
if( u.per_max >= HIGH_STAT ) {
points.stat_points--;
}
u.per_max++;
}
} else if( action == "PREV_TAB" ) {
return tab_direction::BACKWARD;
} else if( action == "NEXT_TAB" ) {
return tab_direction::FORWARD;
} else if( action == "HELP_KEYBINDINGS" ) {
// Need to redraw since the help window obscured everything.
draw_character_tabs( w, _( "STATS" ) );
} else if( action == "QUIT" && query_yn( _( "Return to main menu?" ) ) ) {
return tab_direction::QUIT;
}
} while( true );
}
tab_direction set_traits( const catacurses::window &w, avatar &u, points_left &points )
{
const int max_trait_points = get_option<int>( "MAX_TRAIT_POINTS" );
draw_character_tabs( w, _( "TRAITS" ) );
catacurses::window w_description =
catacurses::newwin( 3, TERMX - 2, point( 1 + getbegx( w ), TERMY - 4 + getbegy( w ) ) );
// Track how many good / bad POINTS we have; cap both at MAX_TRAIT_POINTS
int num_good = 0;
int num_bad = 0;
std::vector<trait_id> vStartingTraits[3];
for( auto &traits_iter : mutation_branch::get_all() ) {
// Don't list blacklisted traits
if( mutation_branch::trait_is_blacklisted( traits_iter.id ) ) {
continue;
}
// Always show profession locked traits, regardless of if they are forbidden
const std::vector<trait_id> proftraits = u.prof->get_locked_traits();
const bool is_proftrait = std::find( proftraits.begin(), proftraits.end(),
traits_iter.id ) != proftraits.end();
// We show all starting traits, even if we can't pick them, to keep the interface consistent.
if( traits_iter.startingtrait || g->scen->traitquery( traits_iter.id ) || is_proftrait ) {
if( traits_iter.points > 0 ) {
vStartingTraits[0].push_back( traits_iter.id );
if( u.has_trait( traits_iter.id ) ) {
num_good += traits_iter.points;
}
} else if( traits_iter.points < 0 ) {
vStartingTraits[1].push_back( traits_iter.id );
if( u.has_trait( traits_iter.id ) ) {
num_bad += traits_iter.points;
}
} else {
vStartingTraits[2].push_back( traits_iter.id );
}
}
}
//If the third page is empty, only use the first two.
const int used_pages = vStartingTraits[2].empty() ? 2 : 3;
for( auto &vStartingTrait : vStartingTraits ) {
std::sort( vStartingTrait.begin(), vStartingTrait.end(), trait_display_sort );
}
nc_color col_on_act, col_off_act, col_on_pas, col_off_pas, hi_on, hi_off, col_tr;