/
newgame.cc
2195 lines (1984 loc) · 67.9 KB
/
newgame.cc
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
/**
* @file
* @brief Functions used when starting a new game.
**/
#include "AppHdr.h"
#include "newgame.h"
#include "cio.h"
#include "command.h"
#include "database.h"
#include "end.h"
#include "english.h"
#include "files.h"
#include "hints.h"
#include "initfile.h"
#include "itemprop.h"
#include "jobs.h"
#include "libutil.h"
#include "macro.h"
#include "maps.h"
#include "menu.h"
#include "ng-input.h"
#include "ng-restr.h"
#include "options.h"
#include "prompt.h"
#include "state.h"
#include "stringutil.h"
#ifdef USE_TILE_LOCAL
#include "tilereg-crt.h"
#endif
static void _choose_gamemode_map(newgame_def& ng, newgame_def& ng_choice,
const newgame_def& defaults);
static bool _choose_weapon(newgame_def& ng, newgame_def& ng_choice,
const newgame_def& defaults);
////////////////////////////////////////////////////////////////////////
// Remember player's startup options
//
newgame_def::newgame_def()
: name(), type(GAME_TYPE_NORMAL),
species(SP_UNKNOWN), job(JOB_UNKNOWN),
weapon(WPN_UNKNOWN),
fully_random(false)
{
}
void newgame_def::clear_character()
{
species = SP_UNKNOWN;
job = JOB_UNKNOWN;
weapon = WPN_UNKNOWN;
}
enum MenuOptions
{
M_QUIT = -1,
M_ABORT = -2,
M_APTITUDES = -3,
M_HELP = -4,
M_VIABLE = -5,
M_RANDOM = -6,
M_VIABLE_CHAR = -7,
M_RANDOM_CHAR = -8,
M_DEFAULT_CHOICE = -9,
};
static bool _is_random_species(species_type sp)
{
return sp == SP_RANDOM || sp == SP_VIABLE;
}
static bool _is_random_job(job_type job)
{
return job == JOB_RANDOM || job == JOB_VIABLE;
}
static bool _is_random_choice(const newgame_def& choice)
{
return _is_random_species(choice.species)
&& _is_random_job(choice.job);
}
static bool _is_random_viable_choice(const newgame_def& choice)
{
return _is_random_choice(choice) &&
(choice.job == JOB_VIABLE || choice.species == SP_VIABLE);
}
static bool _char_defined(const newgame_def& ng)
{
return ng.species != SP_UNKNOWN && ng.job != JOB_UNKNOWN;
}
static string _char_description(const newgame_def& ng)
{
if (_is_random_viable_choice(ng))
return "Viable character";
else if (_is_random_choice(ng))
return "Random character";
else if (_is_random_job(ng.job))
{
const string j = (ng.job == JOB_RANDOM ? "Random " : "Viable ");
return j + species_name(ng.species);
}
else if (_is_random_species(ng.species))
{
const string s = (ng.species == SP_RANDOM ? "Random " : "Viable ");
return s + get_job_name(ng.job);
}
else
return species_name(ng.species) + " " + get_job_name(ng.job);
}
static string _welcome(const newgame_def& ng)
{
string text;
if (ng.species != SP_UNKNOWN)
text = species_name(ng.species);
if (ng.job != JOB_UNKNOWN)
{
if (!text.empty())
text += " ";
text += get_job_name(ng.job);
}
if (!ng.name.empty())
{
if (!text.empty())
text = " the " + text;
text = ng.name + text;
}
else if (!text.empty())
text = "unnamed " + text;
if (!text.empty())
text = ", " + text;
text = "Welcome" + text + ".";
return text;
}
static void _print_character_info(const newgame_def& ng)
{
clrscr();
textcolour(BROWN);
cprintf("%s\n", _welcome(ng).c_str());
}
void choose_tutorial_character(newgame_def& ng_choice)
{
ng_choice.species = SP_HUMAN;
ng_choice.job = JOB_FIGHTER;
ng_choice.weapon = WPN_FLAIL;
}
// March 2008: change order of species and jobs on character selection
// screen as suggested by Markus Maier.
// We have subsequently added a few new categories.
static const species_type species_order[] =
{
// comparatively human-like looks
SP_HUMAN, SP_DEEP_ELF,
SP_DEEP_DWARF, SP_HILL_ORC,
// small species
SP_HALFLING, SP_KOBOLD,
SP_SPRIGGAN,
// large species
SP_BASAJAUN, SP_OGRE,
SP_TROLL,
// significantly different body type from human ("monstrous")
SP_NAGA, SP_CENTAUR,
SP_MERFOLK, SP_MINOTAUR,
SP_TENGU, SP_BASE_DRACONIAN,
SP_GARGOYLE, SP_FORMICID,
// mostly human shape but made of a strange substance
SP_VINE_STALKER,
// celestial species
SP_DEMIGOD, SP_DEMONSPAWN,
// undead species
SP_MUMMY, SP_GHOUL,
SP_VAMPIRE,
// not humanoid at all
SP_FELID, SP_OCTOPODE,
};
COMPILE_CHECK(ARRAYSZ(species_order) <= NUM_SPECIES);
bool is_starting_species(species_type species)
{
return find(species_order, species_order + ARRAYSZ(species_order),
species) != species_order + ARRAYSZ(species_order);
}
static void _resolve_species(newgame_def& ng, const newgame_def& ng_choice)
{
// Don't overwrite existing species.
if (ng.species != SP_UNKNOWN)
return;
switch (ng_choice.species)
{
case SP_UNKNOWN:
ng.species = SP_UNKNOWN;
return;
case SP_VIABLE:
{
int good_choices = 0;
for (const species_type sp : species_order)
{
if (is_good_combination(sp, ng.job, false, true)
&& one_chance_in(++good_choices))
{
ng.species = sp;
}
}
if (good_choices)
return;
}
// intentional fall-through
case SP_RANDOM:
// any valid species will do
if (ng.job == JOB_UNKNOWN)
ng.species = RANDOM_ELEMENT(species_order);
else
{
// Pick a random legal character.
int good_choices = 0;
for (const species_type sp : species_order)
{
if (is_good_combination(sp, ng.job, false, false)
&& one_chance_in(++good_choices))
{
ng.species = sp;
}
}
if (!good_choices)
end(1, false, "Failed to find legal species.");
}
return;
default:
ng.species = ng_choice.species;
return;
}
}
static void _resolve_job(newgame_def& ng, const newgame_def& ng_choice)
{
if (ng.job != JOB_UNKNOWN)
return;
switch (ng_choice.job)
{
case JOB_UNKNOWN:
ng.job = JOB_UNKNOWN;
return;
case JOB_VIABLE:
{
int good_choices = 0;
for (int i = 0; i < NUM_JOBS; i++)
{
job_type job = job_type(i);
if (is_good_combination(ng.species, job, true, true)
&& one_chance_in(++good_choices))
{
ng.job = job;
}
}
if (good_choices)
return;
}
// intentional fall-through
case JOB_RANDOM:
if (ng.species == SP_UNKNOWN)
{
// any valid job will do
do
{
ng.job = job_type(random2(NUM_JOBS));
}
while (!is_starting_job(ng.job));
}
else
{
// Pick a random legal character.
int good_choices = 0;
for (int i = 0; i < NUM_JOBS; i++)
{
job_type job = job_type(i);
if (is_good_combination(ng.species, job, true, false)
&& one_chance_in(++good_choices))
{
ASSERT(is_starting_job(job));
ng.job = job;
}
}
if (!good_choices)
end(1, false, "Failed to find legal background.");
}
return;
default:
ng.job = ng_choice.job;
return;
}
}
static void _resolve_species_job(newgame_def& ng, const newgame_def& ng_choice)
{
// Since recommendations are no longer bidirectional, pick one of
// species or job to start. If one but not the other was specified
// as "viable", always choose that one last; otherwise use a random
// order.
const bool spfirst = ng_choice.species != SP_VIABLE
&& ng_choice.job == JOB_VIABLE;
const bool jobfirst = ng_choice.species == SP_VIABLE
&& ng_choice.job != JOB_VIABLE;
if (spfirst || !jobfirst && coinflip())
{
_resolve_species(ng, ng_choice);
_resolve_job(ng, ng_choice);
}
else
{
_resolve_job(ng, ng_choice);
_resolve_species(ng, ng_choice);
}
}
static string _highlight_pattern(const newgame_def& ng)
{
if (ng.species != SP_UNKNOWN)
return species_name(ng.species) + " ";
if (ng.job == JOB_UNKNOWN)
return "";
string ret;
for (const species_type species : species_order)
if (is_good_combination(species, ng.job, false, true))
ret += species_name(species) + " |";
if (ret != "")
ret.resize(ret.size() - 1);
return ret;
}
static void _prompt_species(newgame_def& ng, newgame_def& ng_choice,
const newgame_def& defaults);
static void _prompt_job(newgame_def& ng, newgame_def& ng_choice,
const newgame_def& defaults);
static void _choose_species_job(newgame_def& ng, newgame_def& ng_choice,
const newgame_def& defaults)
{
_resolve_species_job(ng, ng_choice);
while (ng_choice.species == SP_UNKNOWN || ng_choice.job == JOB_UNKNOWN)
{
// Slightly non-obvious behaviour here is due to the fact that
// both _prompt_species and _prompt_job can ask for an entirely
// random character to be rolled. They will reset relevant fields
// in ng for this purpose.
if (ng_choice.species == SP_UNKNOWN)
_prompt_species(ng, ng_choice, defaults);
_resolve_species_job(ng, ng_choice);
if (ng_choice.job == JOB_UNKNOWN)
_prompt_job(ng, ng_choice, defaults);
_resolve_species_job(ng, ng_choice);
}
if (!job_allowed(ng.species, ng.job))
{
// Either an invalid combination was passed in through options,
// or we messed up.
end(1, false,
"Incompatible species and background specified in options file.");
}
}
// For completely random combinations (!, #, or Options.game.fully_random)
// reroll characters until the player accepts one of them or quits.
static bool _reroll_random(newgame_def& ng)
{
clrscr();
string specs = chop_string(species_name(ng.species), 79, false);
cprintf("You are a%s %s %s.\n",
(is_vowel(specs[0])) ? "n" : "", specs.c_str(),
get_job_name(ng.job));
cprintf("\nDo you want to play this combination? (ynq) [y]");
char c = getchm();
if (key_is_escape(c) || toalower(c) == 'q')
{
#ifdef USE_TILE_WEB
tiles.send_exit_reason("cancel");
#endif
game_ended();
}
return toalower(c) == 'n' || c == '\t' || c == '!' || c == '#';
}
static void _choose_char(newgame_def& ng, newgame_def& choice,
newgame_def defaults)
{
const newgame_def ng_reset = ng;
if (ng.type == GAME_TYPE_TUTORIAL)
{
choose_tutorial_character(choice);
choice.allowed_jobs.clear();
choice.allowed_species.clear();
choice.allowed_weapons.clear();
}
else if (ng.type == GAME_TYPE_HINTS)
{
pick_hints(choice);
choice.allowed_jobs.clear();
choice.allowed_species.clear();
choice.allowed_weapons.clear();
}
#if defined(DGAMELAUNCH) && defined(TOURNEY)
// Apologies to non-public servers.
if (ng.type == GAME_TYPE_NORMAL)
{
if (!yesno("Trunk games don't count for the tournament, you want "
TOURNEY ". Play trunk anyway? (Y/N)", false, 'n'))
{
#ifdef USE_TILE_WEB
tiles.send_exit_reason("cancel");
#endif
game_ended();
}
}
#endif
while (true)
{
if (choice.allowed_combos.size())
{
choice.species = SP_UNKNOWN;
choice.job = JOB_UNKNOWN;
choice.weapon = WPN_UNKNOWN;
string combo =
choice.allowed_combos[random2(choice.allowed_combos.size())];
vector<string> parts = split_string(".", combo);
if (parts.size() > 0)
{
string character = trim_string(parts[0]);
if (character.length() == 4)
{
choice.species =
get_species_by_abbrev(
character.substr(0, 2).c_str());
choice.job =
get_job_by_abbrev(
character.substr(2, 2).c_str());
}
else
{
species_type sp = SP_UNKNOWN;;
// XXX: This is awkward; find a better way?
for (int i = 0; i < NUM_SPECIES; ++i)
{
sp = static_cast<species_type>(i);
if (character.length() >= species_name(sp).length()
&& character.substr(0, species_name(sp).length())
== species_name(sp))
{
choice.species = sp;
break;
}
}
if (sp != SP_UNKNOWN)
{
string temp =
character.substr(species_name(sp).length());
choice.job = str_to_job(trim_string(temp));
}
}
if (parts.size() > 1)
{
string weapon = trim_string(parts[1]);
choice.weapon = str_to_weapon(weapon);
}
}
}
else
{
if (choice.allowed_species.size())
{
choice.species =
choice.allowed_species[
random2(choice.allowed_species.size())];
}
if (choice.allowed_jobs.size())
{
choice.job =
choice.allowed_jobs[random2(choice.allowed_jobs.size())];
}
if (choice.allowed_weapons.size())
{
choice.weapon =
choice.allowed_weapons[
random2(choice.allowed_weapons.size())];
}
}
_choose_species_job(ng, choice, defaults);
if (choice.fully_random && _reroll_random(ng))
{
ng = ng_reset;
continue;
}
if (_choose_weapon(ng, choice, defaults))
{
// We're done!
return;
}
// Else choose again, name and type stays same.
defaults = choice;
ng = ng_reset;
choice = ng_reset;
}
}
// Read a choice of game into ng.
// Returns false if a game (with name ng.name) should
// be restored instead of starting a new character.
bool choose_game(newgame_def& ng, newgame_def& choice,
const newgame_def& defaults)
{
clrscr();
// XXX: this should be somewhere else.
if (!crawl_state.startup_errors.empty()
&& !Options.suppress_startup_errors)
{
crawl_state.show_startup_errors();
clrscr();
}
textcolour(LIGHTGREY);
ng.name = choice.name;
ng.type = choice.type;
ng.map = choice.map;
if (ng.type == GAME_TYPE_SPRINT
|| ng.type == GAME_TYPE_TUTORIAL)
{
_choose_gamemode_map(ng, choice, defaults);
}
_choose_char(ng, choice, defaults);
// Set these again, since _mark_fully_random may reset ng.
ng.name = choice.name;
ng.type = choice.type;
#ifndef DGAMELAUNCH
// New: pick name _after_ character choices.
if (choice.name.empty())
{
clrscr();
string specs = chop_string(species_name(ng.species), 79, false);
cprintf("You are a%s %s %s.\n",
(is_vowel(specs[0])) ? "n" : "", specs.c_str(),
get_job_name(ng.job));
enter_player_name(choice);
ng.name = choice.name;
ng.filename = get_save_filename(choice.name);
if (save_exists(ng.filename))
{
cprintf("\nDo you really want to overwrite your old game? ");
char c = getchm();
if (c != 'Y' && c != 'y')
return true;
}
}
#endif
if (ng.name.empty())
end(1, false, "No player name specified.");
ASSERT(is_good_name(ng.name, false, false)
&& job_allowed(ng.species, ng.job)
&& ng.type != NUM_GAME_TYPE);
write_newgame_options_file(choice);
return false;
}
// Set ng_choice to defaults without overwriting name and game type.
static void _set_default_choice(newgame_def& ng, newgame_def& ng_choice,
const newgame_def& defaults)
{
// Reset ng so _resolve_species_job will work properly.
ng.clear_character();
const string name = ng_choice.name;
const game_type type = ng_choice.type;
ng_choice = defaults;
ng_choice.name = name;
ng_choice.type = type;
}
static void _mark_fully_random(newgame_def& ng, newgame_def& ng_choice,
bool viable)
{
// Reset ng so _resolve_species_job will work properly.
ng.clear_character();
ng_choice.fully_random = true;
if (viable)
{
ng_choice.species = SP_VIABLE;
ng_choice.job = JOB_VIABLE;
}
else
{
ng_choice.species = SP_RANDOM;
ng_choice.job = JOB_RANDOM;
}
}
/**
* Helper function for _choose_species
* Constructs the menu screen
*/
static const int COLUMN_WIDTH = 25;
static const int X_MARGIN = 4;
static const int CHAR_DESC_START_Y = 16;
static const int CHAR_DESC_HEIGHT = 3;
static const int SPECIAL_KEYS_START_Y = CHAR_DESC_START_Y
+ CHAR_DESC_HEIGHT + 1;
static void _construct_species_menu(const newgame_def& ng,
const newgame_def& defaults,
MenuFreeform* menu)
{
ASSERT(menu != nullptr);
int items_in_column = ARRAYSZ(species_order);
items_in_column = (items_in_column + 2) / 3;
// Construct the menu, 3 columns
TextItem* tmp = nullptr;
string text;
coord_def min_coord(0,0);
coord_def max_coord(0,0);
int pos = 0;
for (const species_type species : species_order)
{
if (ng.job != JOB_UNKNOWN
&& species_allowed(ng.job, species) == CC_BANNED)
{
continue;
}
tmp = new TextItem();
text.clear();
if (ng.job == JOB_UNKNOWN)
{
tmp->set_fg_colour(LIGHTGRAY);
tmp->set_highlight_colour(BLUE);
}
else if (species_allowed(ng.job, species) == CC_RESTRICTED)
{
tmp->set_fg_colour(DARKGRAY);
tmp->set_highlight_colour(BLUE);
}
else
{
tmp->set_fg_colour(WHITE);
tmp->set_highlight_colour(GREEN);
}
text = index_to_letter(pos);
text += " - ";
text += species_name(species);
tmp->set_text(text);
ASSERT(pos < items_in_column * 3);
min_coord.x = X_MARGIN + (pos / items_in_column) * COLUMN_WIDTH;
min_coord.y = 3 + pos % items_in_column;
max_coord.x = min_coord.x + text.size();
max_coord.y = min_coord.y + 1;
tmp->set_bounds(min_coord, max_coord);
tmp->add_hotkey(index_to_letter(pos));
tmp->set_id(species);
tmp->set_description_text(unwrap_desc(getGameStartDescription(species_name(species))));
menu->attach_item(tmp);
tmp->set_visible(true);
if (defaults.species == species)
menu->set_active_item(tmp);
++pos;
}
// Add all the special button entries
tmp = new TextItem();
tmp->set_text("+ - Viable species");
min_coord.x = X_MARGIN;
min_coord.y = SPECIAL_KEYS_START_Y;
max_coord.x = min_coord.x + tmp->get_text().size();
max_coord.y = min_coord.y + 1;
tmp->set_bounds(min_coord, max_coord);
tmp->set_fg_colour(BROWN);
tmp->add_hotkey('+');
// If the player has a job chosen, use VIABLE, otherwise use RANDOM
if (ng.job != JOB_UNKNOWN)
tmp->set_id(M_VIABLE);
else
tmp->set_id(M_RANDOM);
tmp->set_highlight_colour(BLUE);
tmp->set_description_text("Picks a random viable species based on your current job choice.");
menu->attach_item(tmp);
tmp->set_visible(true);
tmp = new TextItem();
tmp->set_text("# - Viable character");
min_coord.x = X_MARGIN;
min_coord.y = SPECIAL_KEYS_START_Y + 1;
max_coord.x = min_coord.x + tmp->get_text().size();
max_coord.y = min_coord.y + 1;
tmp->set_bounds(min_coord, max_coord);
tmp->set_fg_colour(BROWN);
tmp->add_hotkey('#');
tmp->set_id(M_VIABLE_CHAR);
tmp->set_highlight_colour(BLUE);
tmp->set_description_text("Shuffles through random viable character combinations "
"until you accept one.");
menu->attach_item(tmp);
tmp->set_visible(true);
tmp = new TextItem();
tmp->set_text("% - List aptitudes");
min_coord.x = X_MARGIN;
min_coord.y = SPECIAL_KEYS_START_Y + 2;
max_coord.x = min_coord.x + tmp->get_text().size();
max_coord.y = min_coord.y + 1;
tmp->set_bounds(min_coord, max_coord);
tmp->set_fg_colour(BROWN);
tmp->add_hotkey('%');
tmp->set_id(M_APTITUDES);
tmp->set_description_text("Lists the numerical skill train aptitudes for all races.");
tmp->set_highlight_colour(BLUE);
menu->attach_item(tmp);
tmp->set_visible(true);
tmp = new TextItem();
tmp->set_text("? - Help");
min_coord.x = X_MARGIN;
min_coord.y = SPECIAL_KEYS_START_Y + 3;
max_coord.x = min_coord.x + tmp->get_text().size();
max_coord.y = min_coord.y + 1;
tmp->set_bounds(min_coord, max_coord);
tmp->set_fg_colour(BROWN);
tmp->add_hotkey('?');
tmp->set_id(M_HELP);
tmp->set_highlight_colour(BLUE);
tmp->set_description_text("Opens the help screen.");
menu->attach_item(tmp);
tmp->set_visible(true);
tmp = new TextItem();
tmp->set_text("* - Random species");
min_coord.x = X_MARGIN + COLUMN_WIDTH;
min_coord.y = SPECIAL_KEYS_START_Y;
max_coord.x = min_coord.x + tmp->get_text().size();
max_coord.y = min_coord.y + 1;
tmp->set_bounds(min_coord, max_coord);
tmp->set_fg_colour(BROWN);
tmp->add_hotkey('*');
tmp->set_id(M_RANDOM);
tmp->set_highlight_colour(BLUE);
tmp->set_description_text("Picks a random species.");
menu->attach_item(tmp);
tmp->set_visible(true);
tmp = new TextItem();
tmp->set_text("! - Random character");
min_coord.x = X_MARGIN + COLUMN_WIDTH;
min_coord.y = SPECIAL_KEYS_START_Y + 1;
max_coord.x = min_coord.x + tmp->get_text().size();
max_coord.y = min_coord.y + 1;
tmp->set_bounds(min_coord, max_coord);
tmp->set_fg_colour(BROWN);
tmp->add_hotkey('!');
tmp->set_id(M_RANDOM_CHAR);
tmp->set_highlight_colour(BLUE);
tmp->set_description_text("Shuffles through random character combinations "
"until you accept one.");
menu->attach_item(tmp);
tmp->set_visible(true);
// Adjust the end marker to align the - because Space text is longer by 4
tmp = new TextItem();
if (ng.job != JOB_UNKNOWN)
{
tmp->set_text("Space - Change background");
tmp->set_description_text("Lets you change your background choice.");
}
else
{
tmp->set_text("Space - Pick background first");
tmp->set_description_text("Lets you pick your background first.");
}
min_coord.x = X_MARGIN + COLUMN_WIDTH - 4;
min_coord.y = SPECIAL_KEYS_START_Y + 2;
max_coord.x = min_coord.x + tmp->get_text().size();
max_coord.y = min_coord.y + 1;
tmp->set_bounds(min_coord, max_coord);
tmp->set_fg_colour(BROWN);
tmp->add_hotkey(' ');
tmp->set_id(M_ABORT);
tmp->set_highlight_colour(BLUE);
menu->attach_item(tmp);
tmp->set_visible(true);
if (_char_defined(defaults))
{
string tmp_string = "Tab - ";
tmp_string += _char_description(defaults);
// Adjust the end marker to aling the - because
// Tab text is longer by 2
tmp = new TextItem();
tmp->set_text(tmp_string);
min_coord.x = X_MARGIN + COLUMN_WIDTH - 2;
min_coord.y = SPECIAL_KEYS_START_Y + 3;
max_coord.x = min_coord.x + tmp->get_text().size();
max_coord.y = min_coord.y + 1;
tmp->set_bounds(min_coord, max_coord);
tmp->set_fg_colour(BROWN);
tmp->add_hotkey('\t');
tmp->set_id(M_DEFAULT_CHOICE);
tmp->set_highlight_colour(BLUE);
tmp->set_description_text("Play a new game with your previous choice.");
menu->attach_item(tmp);
tmp->set_visible(true);
}
}
// Prompt the player for a choice of species.
// ng should be const, but we need to reset it for _resolve_species_job
// to work correctly in view of fully random characters.
static void _prompt_species(newgame_def& ng, newgame_def& ng_choice,
const newgame_def& defaults)
{
PrecisionMenu menu;
menu.set_select_type(PrecisionMenu::PRECISION_SINGLESELECT);
MenuFreeform* freeform = new MenuFreeform();
freeform->init(coord_def(0,0), coord_def(get_number_of_cols(),
get_number_of_lines()), "freeform");
menu.attach_object(freeform);
menu.set_active_object(freeform);
int keyn;
clrscr();
// TODO: attach these to the menu in a NoSelectTextItem
textcolour(BROWN);
cprintf("%s", _welcome(ng).c_str());
textcolour(YELLOW);
cprintf(" Please select your species.");
_construct_species_menu(ng, defaults, freeform);
MenuDescriptor* descriptor = new MenuDescriptor(&menu);
descriptor->init(coord_def(X_MARGIN, CHAR_DESC_START_Y),
coord_def(get_number_of_cols(), CHAR_DESC_START_Y
+ CHAR_DESC_HEIGHT),
"descriptor");
menu.attach_object(descriptor);
BoxMenuHighlighter* highlighter = new BoxMenuHighlighter(&menu);
highlighter->init(coord_def(0,0), coord_def(0,0), "highlighter");
menu.attach_object(highlighter);
// Did we have a previous species?
if (menu.get_active_item() == nullptr)
freeform->activate_first_item();
#ifdef USE_TILE_LOCAL
tiles.get_crt()->attach_menu(&menu);
#endif
freeform->set_visible(true);
descriptor->set_visible(true);
highlighter->set_visible(true);
textcolour(LIGHTGREY);
// Poll input until we have a conclusive escape or pick
while (true)
{
menu.draw_menu();
keyn = getch_ck();
// First process all the menu entries available
if (!menu.process_key(keyn))
{
// Process all the other keys that are not assigned to the menu
switch (keyn)
{
case 'X':
case CONTROL('Q'):
cprintf("\nGoodbye!");
#ifdef USE_TILE_WEB
tiles.send_exit_reason("cancel");
#endif
end(0);
return;
CASE_ESCAPE
case CK_MOUSE_CMD:
#ifdef USE_TILE_WEB
tiles.send_exit_reason("cancel");
#endif
game_ended();
case CK_BKSP:
ng_choice.species = SP_UNKNOWN;
return;
default:
// if we get this far, we did not get a significant selection
// from the menu, nor did we get an escape character
// continue the while loop from the beginning and poll a new key
continue;
}
}
// We have had a significant input key event
// construct the return vector
vector<MenuItem*> selection = menu.get_selected_items();
if (!selection.empty())
{
// we have a selection!
// we only care about the first selection (there should be only one)
int selection_key = selection.at(0)->get_id();
bool viable = false;
switch (selection_key)
{
case M_VIABLE_CHAR:
viable = true;
// intentional fall-through
case M_RANDOM_CHAR:
_mark_fully_random(ng, ng_choice, viable);
return;
case M_DEFAULT_CHOICE:
if (_char_defined(defaults))
{
_set_default_choice(ng, ng_choice, defaults);
return;
}
else
{
// ignore Tab because we don't have previous start options
continue;
}
case M_ABORT:
ng.species = ng_choice.species = SP_UNKNOWN;
ng.job = ng_choice.job = JOB_UNKNOWN;
return;
case M_HELP:
// access to the help files
list_commands('1');
return _prompt_species(ng, ng_choice, defaults);
case M_APTITUDES:
list_commands('%', false, _highlight_pattern(ng));
return _prompt_species(ng, ng_choice, defaults);
case M_VIABLE:
ng_choice.species = SP_VIABLE;
return;
case M_RANDOM:
ng_choice.species = SP_RANDOM;
return;
default:
// we have a species selection
species_type species = static_cast<species_type> (selection_key);
if (ng.job == JOB_UNKNOWN
|| species_allowed(ng.job, species) != CC_BANNED)
{
ng_choice.species = species;
return;