forked from cataclysmbnteam/Cataclysm-BN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
newcharacter.cpp
3227 lines (2908 loc) · 131 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 "newcharacter.h" // IWYU pragma: associated
#include <algorithm>
#include <array>
#include <climits>
#include <cstdlib>
#include <functional>
#include <iosfwd>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <optional>
#include <set>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
#include "addiction.h"
#include "bionics.h"
#include "cata_utility.h"
#include "catacharset.h"
#include "character.h"
#include "character_martial_arts.h"
#include "color.h"
#include "cursesdef.h"
#include "filesystem.h"
#include "fstream_utils.h"
#include "game.h"
#include "game_constants.h"
#include "ime.h"
#include "input.h"
#include "int_id.h"
#include "inventory.h"
#include "json.h"
#include "magic.h"
#include "magic_enchantment.h"
#include "make_static.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 "pimpl.h"
#include "pldata.h"
#include "profession.h"
#include "ranged.h"
#include "recipe.h"
#include "recipe_dictionary.h"
#include "rng.h"
#include "scenario.h"
#include "skill.h"
#include "start_location.h"
#include "string_formatter.h"
#include "string_id.h"
#include "string_input_popup.h"
#include "string_utils.h"
#include "translations.h"
#include "type_id.h"
#include "ui.h"
#include "ui_manager.h"
#include "units_utility.h"
#include "veh_type.h"
#include "worldfactory.h"
static const std::string flag_CHALLENGE( "CHALLENGE" );
static const std::string flag_CITY_START( "CITY_START" );
static const std::string flag_SECRET( "SECRET" );
static const std::string flag_WET( "WET" );
static const trait_id trait_SMELLY( "SMELLY" );
static const trait_id trait_WEAKSCENT( "WEAKSCENT" );
static const trait_id trait_XS( "XS" );
static const trait_id trait_XXXL( "XXXL" );
// 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_MINOR c_light_gray // Just regular note
#define HIGH_STAT 14 // The point after which stats cost double
#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( avatar &u, points_left &points );
tab_direction set_stats( avatar &u, points_left &points );
tab_direction set_traits( avatar &u, points_left &points );
tab_direction set_scenario( avatar &u, points_left &points, tab_direction direction );
tab_direction set_profession( avatar &u, points_left &points, tab_direction direction );
tab_direction set_skills( avatar &u, points_left &points );
tab_direction set_description( avatar &you, bool allow_reroll, points_left &points );
static std::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 == character_type::NOW || type == character_type::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.\n"
"\n"
"STR: <color_white>%d</color>, DEX: <color_white>%d</color>, "
"PER: <color_white>%d</color>, INT: <color_white>%d</color>\n"
"Press [<color_yellow>%s</color>] for more info.\n" ),
u.get_str(), u.get_dex(), u.get_per(), u.get_int(),
ctxt.get_desc( "SHOW_DESCRIPTION" ) );
ma_style_callback callback( 0, styles );
menu.callback = &callback;
menu.input_category = "MELEE_STYLE_PICKER";
menu.additional_actions.emplace_back( "SHOW_DESCRIPTION", translation() );
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;
}
}
}
/**
* Check if the given player can pick this job with the given amount
* of points.
*
* @return true, if player can pick profession. Otherwise - false.
*/
static bool can_pick_prof( const profession &prof, const player &u, int points )
{
return prof.point_cost() - u.prof->point_cost() <= points;
}
static void learn_spells( const profession &prof, avatar &you )
{
for( const std::pair<spell_id, int> spell_pair : prof.spells() ) {
you.magic->learn_spell( spell_pair.first, you, true );
spell &sp = you.magic->get_spell( spell_pair.first );
while( sp.get_level() < spell_pair.second && !sp.is_max_level() ) {
sp.gain_level();
}
}
}
void avatar::randomize( const bool random_scenario, points_left &points, bool play_now )
{
const int max_stat_points = points.is_freeform() ? 20 : MAX_STAT;
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();
}
// if adjusting min and max age from 16 and 55, make sure to see set_description()
init_age = rng( 16, 55 );
// if adjusting min and max height from 145 and 200, make sure to see set_description()
init_height = rng( 145, 200 );
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( flag_CHALLENGE ) &&
( !scen.has_flag( 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();
random_start_location = true;
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;
newcharacter::add_traits( *this, points ); // adds mandatory profession/scenario traits.
for( const trait_id &mut : get_mutations() ) {
const mutation_branch &mut_info = mut.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 = newcharacter::random_bad_trait();
tries++;
} while( ( has_trait( rn ) || num_btraits - rn->points > max_trait_points ) &&
tries < 5 );
if( tries < 5 && !newcharacter::has_conflicting_trait( *this, 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 = newcharacter::random_good_trait();
auto &mdata = rn.obj();
if( !has_trait( rn ) && points.trait_points_left() >= mdata.points &&
num_gtraits + mdata.points <= max_trait_points &&
!newcharacter::has_conflicting_trait( *this, 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_points ) {
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_points ) {
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_points ) {
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_points ) {
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 && 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++;
}
set_body();
}
bool avatar::create( character_type type, const std::string &tempname )
{
primary_weapon() = item( "null", calendar::start_of_cataclysm );
prof = profession::generic();
g->scen = scenario::generic();
const bool interactive = type != character_type::NOW &&
type != character_type::FULL_RANDOM;
int tab = 0;
points_left points = points_left();
switch( type ) {
case character_type::CUSTOM:
break;
case character_type::RANDOM:
//random scenario, default name if exist
randomize( true, points );
tab = NEWCHAR_TAB_MAX;
break;
case character_type::NOW:
//default world, fixed scenario, random name
randomize( false, points, true );
break;
case character_type::FULL_RANDOM:
//default world, random scenario, random name
randomize( true, points, true );
break;
case character_type::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_save_id( name ) ) &&
!query_yn( _( "A save with the name '%s' already exists in this world.\n"
"Saving will overwrite the already existing character.\n\n"
"Continue anyways?" ), name );
};
set_body();
const bool allow_reroll = type == character_type::RANDOM;
tab_direction result = tab_direction::QUIT;
do {
if( !interactive ) {
// no window is created because "Play now" does not require any configuration
if( nameExists( name ) ) {
return false;
}
break;
}
if( points.limit == points_left::TRANSFER ) {
tab = 6;
}
switch( tab ) {
case 0:
result = set_points( *this, points );
break;
case 1:
result = set_scenario( *this, points, result );
break;
case 2:
result = set_profession( *this, points, result );
break;
case 3:
result = set_stats( *this, points );
break;
case 4:
result = set_traits( *this, points );
break;
case 5:
result = set_skills( *this, points );
break;
case 6:
result = set_description( *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();
if( has_trait( trait_SMELLY ) ) {
scent = 800;
}
if( has_trait( trait_WEAKSCENT ) ) {
scent = 300;
}
primary_weapon() = item( "null", calendar::start_of_cataclysm );
// Grab the skills from the profession, if there are any
// We want to do this before the recipes
for( const profession::StartingSkill &e : prof->skills() ) {
mod_skill_level( e.first, e.second );
}
// setup staring bank money
cash = rng( -200000, 200000 );
if( has_trait( trait_XS ) ) {
set_stored_kcal( 10000 );
toggle_trait( trait_XS );
}
if( has_trait( trait_XXXL ) ) {
set_stored_kcal( 125000 );
toggle_trait( trait_XXXL );
}
// Learn recipes
for( const auto &e : recipe_dict ) {
const auto &r = e.second;
if( !r.has_flag( flag_SECRET ) && !knows_recipe( &r ) && has_recipe_requirements( r ) ) {
learn_recipe( &r );
}
}
for( mtype_id elem : prof->pets() ) {
starting_pets.push_back( elem );
}
if( g->scen->vehicle() != vproto_id::NULL_ID() ) {
starting_vehicle = g->scen->vehicle();
} else {
starting_vehicle = prof->vehicle();
}
std::list<item> prof_items = prof->items( male, get_mutations() );
for( item &it : prof_items ) {
if( it.has_flag( 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( const bionic_id &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() ) {
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;
}
}
learn_spells( *prof, *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 sorting.)" ),
sort_order, ctxt.get_desc( "SORT" ) );
fold_and_print( w_sorting, point_zero, ( TERMX / 2 ), c_light_gray, sort_text );
}
tab_direction set_points( avatar &, points_left &points )
{
tab_direction retval = tab_direction::NONE;
ui_adaptor ui;
catacurses::window w;
catacurses::window w_description;
const auto init_windows = [&]( ui_adaptor & ui ) {
w = catacurses::newwin( TERMY, TERMX, point_zero );
w_description = catacurses::newwin( TERMY - 6, TERMX - 35, point( 31, 5 ) );
ui.position_from_window( w );
};
init_windows( ui );
ui.on_screen_resize( init_windows );
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;
ui.on_redraw( [&]( const ui_adaptor & ) {
draw_character_tabs( w, _( "POINTS" ) );
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 ) );
wnoutrefresh( w );
wnoutrefresh( w_description );
} );
do {
if( highlighted < 0 ) {
highlighted = opts.size() - 1;
} else if( highlighted >= static_cast<int>( opts.size() ) ) {
highlighted = 0;
}
ui_manager::redraw();
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 == "CONFIRM" ) {
const auto &cur_opt = opts[highlighted];
points.limit = std::get<0>( cur_opt );
}
} while( retval == tab_direction::NONE );
return retval;
}
tab_direction set_stats( avatar &u, points_left &points )
{
const int max_stat_points = points.is_freeform() ? 20 : MAX_STAT;
unsigned char sel = 1;
const int iSecondColumn = std::max( 27, utf8_width( points.to_string(), true ) + 9 );
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" );
ui_adaptor ui;
catacurses::window w;
catacurses::window w_description;
const auto init_windows = [&]( ui_adaptor & ui ) {
w = catacurses::newwin( TERMY, TERMX, point_zero );
w_description = catacurses::newwin( 8, TERMX - iSecondColumn - 1,
point( iSecondColumn, 6 ) );
ui.position_from_window( w );
};
init_windows( ui );
ui.on_screen_resize( init_windows );
// 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();
// set position back to 0 to prevent out-of-bound access to lightmap
// array in map::build_seen_cache()
u.setx( 0 );
ui.on_redraw( [&]( const ui_adaptor & ) {
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.\n"
"\n"
" <color_light_green>%s</color> lets you view and alter keybindings.\n"
" <color_light_green>%s</color> takes you to the next tab.\n"
" <color_light_green>%s</color> returns you to the main menu." ),
ctxt.get_desc( "UP" ), ctxt.get_desc( "DOWN" ),
ctxt.get_desc( "RIGHT" ), ctxt.get_desc( "LEFT" ),
ctxt.get_desc( "HELP_KEYBINDINGS" ), ctxt.get_desc( "NEXT_TAB" ), 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.get_part_hp_max( bodypart_id( "head" ) ) );
// 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_melee_hit_base() );
// NOLINTNEXTLINE(cata-use-named-point-constants)
mvwprintz( w_description, point( 0, 1 ), COL_STAT_BONUS,
_( "Throwing penalty per target's dodge: +%d" ),
ranged::throw_dispersion_per_dodge( u, 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." ) );
}
const int 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() );
mvwprintz( w_description, point( 0, 2 ), COL_STAT_BONUS, _( "Crafting bonus: +%d%%" ),
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() );
}
mvwprintz( w_description, point( 0, 2 ), COL_STAT_BONUS, _( "Night vision bonus: +%.1f" ),
vision::nv_range_from_per( u.per_max ) );
fold_and_print( w_description, point( 0, 4 ), getmaxx( w_description ) - 1, COL_STAT_NEUTRAL,
_( "Perception is also used for detecting traps and other things of interest." ) );
break;
}
wnoutrefresh( w );
wnoutrefresh( w_description );
} );
do {
ui_manager::redraw();
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 ) {
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 ) {
points.stat_points--;
if( u.dex_max >= HIGH_STAT ) {
points.stat_points--;