-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
initfile.cc
5086 lines (4524 loc) · 155 KB
/
initfile.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 Simple reading of an init file and system variables
* @detailed read_init_file is the main function, but read_option_line does
* most of the work though. Read through read_init_file to get an overview of
* how Crawl loads options. This file also contains a large number of utility
* functions for setting particular options and converting between human
* readable strings and internal values. (E.g. str_to_enemy_hp_colour,
* _weapon_to_str). There is also some code dealing with sorting menus.
**/
#include "AppHdr.h"
#include "initfile.h"
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <set>
#include <string>
#include "chardump.h"
#include "clua.h"
#include "colour.h"
#include "confirm-butcher-type.h"
#include "defines.h"
#include "delay.h"
#include "describe.h"
#include "directn.h"
#include "dlua.h"
#include "end.h"
#include "errors.h"
#include "files.h"
#include "game-options.h"
#include "ghost.h"
#include "invent.h"
#include "item-prop.h"
#include "items.h"
#include "jobs.h"
#include "kills.h"
#include "libutil.h"
#include "macro.h"
#include "mapdef.h"
#include "message.h"
#include "misc.h"
#include "mon-util.h"
#include "monster.h"
#include "newgame.h"
#include "options.h"
#include "playable.h"
#include "player.h"
#include "prompt.h"
#include "slot-select-mode.h"
#include "species.h"
#include "spl-util.h"
#include "stash.h"
#include "state.h"
#include "stringutil.h"
#include "syscalls.h"
#include "tags.h"
#include "throw.h"
#include "travel.h"
#include "unwind.h"
#include "version.h"
#include "viewchar.h"
#include "view.h"
#include "wizard-option-type.h"
#ifdef USE_TILE
#include "tilepick.h"
#include "tiledef-player.h"
#endif
#include "tiles-build-specific.h"
// For finding the executable's path
#ifdef TARGET_OS_WINDOWS
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <shlwapi.h>
#include <shlobj.h>
#elif defined(TARGET_OS_MACOSX)
extern char **NXArgv;
#ifndef DATA_DIR_PATH
#include <unistd.h>
#endif
#elif defined(TARGET_OS_LINUX) || defined(TARGET_OS_CYGWIN)
#include <unistd.h>
#endif
const string game_options::interrupt_prefix = "interrupt_";
system_environment SysEnv;
game_options Options;
static string _get_save_path(string subdir);
static string _supported_language_listing();
static bool _first_less(const pair<int, int> &l, const pair<int, int> &r)
{
return l.first < r.first;
}
static bool _first_greater(const pair<int, int> &l, const pair<int, int> &r)
{
return l.first > r.first;
}
const vector<GameOption*> game_options::build_options_list()
{
const bool USING_TOUCH =
#if defined(TOUCH_UI)
true;
#else
false;
#endif
const bool USING_DGL =
#if defined(DGAMELAUNCH)
true;
#else
false;
#endif
const bool USING_UNIX =
#if defined(UNIX)
true;
#else
false;
#endif
#ifdef USE_TILE
const bool USING_WEB_TILES =
#if defined(USE_TILE_WEB)
true;
#else
false;
#endif
#endif
#define SIMPLE_NAME(_opt) _opt, {#_opt}
vector<GameOption*> options = {
new BoolGameOption(SIMPLE_NAME(autopickup_starting_ammo), true),
new BoolGameOption(SIMPLE_NAME(easy_door), true),
new BoolGameOption(SIMPLE_NAME(default_show_all_skills), false),
new BoolGameOption(SIMPLE_NAME(read_persist_options), false),
new BoolGameOption(SIMPLE_NAME(auto_switch), false),
new BoolGameOption(SIMPLE_NAME(suppress_startup_errors), false),
new BoolGameOption(SIMPLE_NAME(simple_targeting), false),
new BoolGameOption(easy_quit_item_prompts,
{ "easy_quit_item_prompts", "easy_quit_item_lists" },
true),
new BoolGameOption(SIMPLE_NAME(travel_open_doors), true),
new BoolGameOption(easy_unequip,
{ "easy_unequip", "easy_armour", "easy_armor" },
true),
new BoolGameOption(SIMPLE_NAME(equip_unequip), false),
new BoolGameOption(SIMPLE_NAME(jewellery_prompt), false),
new BoolGameOption(SIMPLE_NAME(easy_door), true),
new BoolGameOption(SIMPLE_NAME(warn_hatches), false),
new BoolGameOption(SIMPLE_NAME(enable_recast_spell), true),
new BoolGameOption(SIMPLE_NAME(easy_eat_chunks), false),
new BoolGameOption(SIMPLE_NAME(auto_eat_chunks), true),
new BoolGameOption(SIMPLE_NAME(auto_hide_spells), false),
new BoolGameOption(SIMPLE_NAME(blink_brightens_background), false),
new BoolGameOption(SIMPLE_NAME(bold_brightens_foreground), false),
new BoolGameOption(SIMPLE_NAME(best_effort_brighten_background), false),
#ifdef TARGET_OS_MACOSX
new BoolGameOption(SIMPLE_NAME(best_effort_brighten_foreground), false),
new BoolGameOption(SIMPLE_NAME(allow_extended_colours), true),
#else
new BoolGameOption(SIMPLE_NAME(best_effort_brighten_foreground), true),
new BoolGameOption(SIMPLE_NAME(allow_extended_colours), false),
#endif
new BoolGameOption(SIMPLE_NAME(regex_search), false),
new BoolGameOption(SIMPLE_NAME(autopickup_search), false),
new BoolGameOption(SIMPLE_NAME(show_newturn_mark), true),
new BoolGameOption(SIMPLE_NAME(show_game_time), true),
new BoolGameOption(SIMPLE_NAME(equip_bar), false),
new BoolGameOption(SIMPLE_NAME(mouse_input), false),
new BoolGameOption(SIMPLE_NAME(mlist_allow_alternate_layout), false),
new BoolGameOption(SIMPLE_NAME(messages_at_top), false),
new BoolGameOption(SIMPLE_NAME(msg_condense_repeats), true),
new BoolGameOption(SIMPLE_NAME(msg_condense_short), true),
new BoolGameOption(SIMPLE_NAME(view_lock_x), true),
new BoolGameOption(SIMPLE_NAME(view_lock_y), true),
new BoolGameOption(SIMPLE_NAME(center_on_scroll), false),
new BoolGameOption(SIMPLE_NAME(symmetric_scroll), true),
new BoolGameOption(SIMPLE_NAME(always_show_exclusions), true),
new BoolGameOption(SIMPLE_NAME(note_all_skill_levels), false),
new BoolGameOption(SIMPLE_NAME(note_skill_max), true),
new BoolGameOption(SIMPLE_NAME(note_xom_effects), true),
new BoolGameOption(SIMPLE_NAME(note_chat_messages), false),
new BoolGameOption(SIMPLE_NAME(note_dgl_messages), true),
new BoolGameOption(SIMPLE_NAME(clear_messages), false),
new BoolGameOption(SIMPLE_NAME(show_more), !USING_TOUCH),
new BoolGameOption(SIMPLE_NAME(small_more), false),
new BoolGameOption(SIMPLE_NAME(pickup_thrown), true),
new BoolGameOption(SIMPLE_NAME(show_travel_trail), USING_DGL),
new BoolGameOption(SIMPLE_NAME(use_fake_cursor), USING_UNIX ),
new BoolGameOption(SIMPLE_NAME(use_fake_player_cursor), true),
new BoolGameOption(SIMPLE_NAME(show_player_species), false),
new BoolGameOption(SIMPLE_NAME(use_modifier_prefix_keys), true),
new BoolGameOption(SIMPLE_NAME(ability_menu), true),
new BoolGameOption(SIMPLE_NAME(easy_floor_use), true),
new BoolGameOption(SIMPLE_NAME(dos_use_background_intensity), true),
new BoolGameOption(SIMPLE_NAME(explore_greedy), true),
new BoolGameOption(SIMPLE_NAME(explore_auto_rest), false),
new BoolGameOption(SIMPLE_NAME(travel_key_stop), true),
new BoolGameOption(SIMPLE_NAME(dump_on_save), true),
new BoolGameOption(SIMPLE_NAME(rest_wait_both), false),
new BoolGameOption(SIMPLE_NAME(cloud_status), !is_tiles()),
new BoolGameOption(SIMPLE_NAME(wall_jump_prompt), false),
new BoolGameOption(SIMPLE_NAME(wall_jump_move), true),
new BoolGameOption(SIMPLE_NAME(darken_beyond_range), true),
new BoolGameOption(SIMPLE_NAME(dump_book_spells), true),
new BoolGameOption(SIMPLE_NAME(arena_dump_msgs), false),
new BoolGameOption(SIMPLE_NAME(arena_dump_msgs_all), false),
new BoolGameOption(SIMPLE_NAME(arena_list_eq), false),
new BoolGameOption(SIMPLE_NAME(default_manual_training), false),
new BoolGameOption(SIMPLE_NAME(one_SDL_sound_channel), false),
new BoolGameOption(SIMPLE_NAME(sounds_on), true),
new ColourGameOption(SIMPLE_NAME(tc_reachable), BLUE),
new ColourGameOption(SIMPLE_NAME(tc_excluded), LIGHTMAGENTA),
new ColourGameOption(SIMPLE_NAME(tc_exclude_circle), RED),
new ColourGameOption(SIMPLE_NAME(tc_forbidden), LIGHTCYAN),
new ColourGameOption(SIMPLE_NAME(tc_dangerous), CYAN),
new ColourGameOption(SIMPLE_NAME(tc_disconnected), DARKGREY),
// [ds] Default to jazzy colours.
new ColourGameOption(SIMPLE_NAME(detected_item_colour), GREEN),
new ColourGameOption(SIMPLE_NAME(detected_monster_colour), LIGHTRED),
new ColourGameOption(SIMPLE_NAME(remembered_monster_colour), DARKGREY),
new ColourGameOption(SIMPLE_NAME(status_caption_colour), BROWN, false),
new ColourGameOption(SIMPLE_NAME(background_colour), BLACK, false),
new ColourGameOption(SIMPLE_NAME(foreground_colour), LIGHTGREY, false),
new CursesGameOption(SIMPLE_NAME(friend_brand),
CHATTR_HILITE | (GREEN << 8)),
new CursesGameOption(SIMPLE_NAME(neutral_brand),
CHATTR_HILITE | (LIGHTGREY << 8)),
new CursesGameOption(SIMPLE_NAME(stab_brand),
CHATTR_HILITE | (BLUE << 8)),
new CursesGameOption(SIMPLE_NAME(may_stab_brand),
CHATTR_HILITE | (YELLOW << 8)),
new CursesGameOption(SIMPLE_NAME(feature_item_brand), CHATTR_REVERSE),
new CursesGameOption(SIMPLE_NAME(trap_item_brand), CHATTR_REVERSE),
new CursesGameOption(SIMPLE_NAME(heap_brand), CHATTR_REVERSE),
new IntGameOption(SIMPLE_NAME(note_hp_percent), 5, 0, 100),
new IntGameOption(SIMPLE_NAME(hp_warning), 30, 0, 100),
new IntGameOption(magic_point_warning, {"mp_warning"}, 0, 0, 100),
new IntGameOption(SIMPLE_NAME(autofight_warning), 0, 0, 1000),
// These need to be odd, hence allow +1.
new IntGameOption(SIMPLE_NAME(view_max_width),
max(VIEW_BASE_WIDTH, VIEW_MIN_WIDTH),
VIEW_MIN_WIDTH, GXM + 1),
new IntGameOption(SIMPLE_NAME(view_max_height), max(21, VIEW_MIN_HEIGHT),
VIEW_MIN_HEIGHT, GYM + 1),
new IntGameOption(SIMPLE_NAME(mlist_min_height), 4, 0),
new IntGameOption(SIMPLE_NAME(msg_min_height), max(7, MSG_MIN_HEIGHT),
MSG_MIN_HEIGHT),
new IntGameOption(SIMPLE_NAME(msg_max_height), max(10, MSG_MIN_HEIGHT),
MSG_MIN_HEIGHT),
new IntGameOption(SIMPLE_NAME(msg_webtiles_height), -1),
new IntGameOption(SIMPLE_NAME(rest_wait_percent), 100, 0, 100),
new IntGameOption(SIMPLE_NAME(pickup_menu_limit), 1),
new IntGameOption(SIMPLE_NAME(view_delay), DEFAULT_VIEW_DELAY, 0),
new IntGameOption(SIMPLE_NAME(fail_severity_to_confirm), 3, -1, 3),
new IntGameOption(SIMPLE_NAME(travel_delay), USING_DGL ? -1 : 20,
-1, 2000),
new IntGameOption(SIMPLE_NAME(rest_delay), USING_DGL ? -1 : 0,
-1, 2000),
new IntGameOption(SIMPLE_NAME(explore_delay), -1, -1, 2000),
new IntGameOption(SIMPLE_NAME(explore_item_greed), 10, -1000, 1000),
new IntGameOption(SIMPLE_NAME(explore_wall_bias), 0, 0, 1000),
new IntGameOption(SIMPLE_NAME(scroll_margin_x), 2, 0),
new IntGameOption(SIMPLE_NAME(scroll_margin_y), 2, 0),
new IntGameOption(SIMPLE_NAME(item_stack_summary_minimum), 4),
new IntGameOption(SIMPLE_NAME(level_map_cursor_step), 7, 1, 50),
new IntGameOption(SIMPLE_NAME(dump_item_origin_price), -1, -1),
new IntGameOption(SIMPLE_NAME(dump_message_count), 20),
new ListGameOption<text_pattern>(SIMPLE_NAME(confirm_action)),
new ListGameOption<text_pattern>(SIMPLE_NAME(drop_filter)),
new ListGameOption<text_pattern>(SIMPLE_NAME(note_monsters)),
new ListGameOption<text_pattern>(SIMPLE_NAME(note_messages)),
new ListGameOption<text_pattern>(SIMPLE_NAME(note_items)),
new ListGameOption<text_pattern>(SIMPLE_NAME(auto_exclude)),
new ListGameOption<text_pattern>(SIMPLE_NAME(explore_stop_pickup_ignore)),
new ColourThresholdOption(hp_colour, {"hp_colour", "hp_color"},
"50:yellow, 25:red", _first_greater),
new ColourThresholdOption(mp_colour, {"mp_colour", "mp_color"},
"50:yellow, 25:red", _first_greater),
new ColourThresholdOption(stat_colour, {"stat_colour", "stat_color"},
"3:red", _first_less),
new StringGameOption(SIMPLE_NAME(sound_file_path), ""),
#ifdef DGL_SIMPLE_MESSAGING
new BoolGameOption(SIMPLE_NAME(messaging), false),
#endif
#ifndef DGAMELAUNCH
new BoolGameOption(SIMPLE_NAME(name_bypasses_menu), true),
new BoolGameOption(SIMPLE_NAME(restart_after_save), false),
new BoolGameOption(SIMPLE_NAME(newgame_after_quit), false),
new StringGameOption(SIMPLE_NAME(map_file_name), ""),
new StringGameOption(SIMPLE_NAME(save_dir), _get_save_path("saves/")),
new StringGameOption(SIMPLE_NAME(morgue_dir),
_get_save_path("morgue/")),
#endif
#ifdef USE_TILE
new BoolGameOption(SIMPLE_NAME(tile_skip_title), false),
new BoolGameOption(SIMPLE_NAME(tile_menu_icons), true),
new BoolGameOption(SIMPLE_NAME(tile_filter_scaling), false),
new BoolGameOption(SIMPLE_NAME(tile_force_overlay), false),
new BoolGameOption(SIMPLE_NAME(tile_show_minihealthbar), true),
new BoolGameOption(SIMPLE_NAME(tile_show_minimagicbar), true),
new BoolGameOption(SIMPLE_NAME(tile_show_demon_tier), false),
new StringGameOption(SIMPLE_NAME(tile_show_items), "!?/%=([)x}:|\\"),
// disabled by default due to performance issues
new BoolGameOption(SIMPLE_NAME(tile_water_anim), !USING_WEB_TILES),
new BoolGameOption(SIMPLE_NAME(tile_misc_anim), true),
new IntGameOption(SIMPLE_NAME(tile_font_crt_size), 0, 0, INT_MAX),
new IntGameOption(SIMPLE_NAME(tile_font_msg_size), 0, 0, INT_MAX),
new IntGameOption(SIMPLE_NAME(tile_font_stat_size), 0, 0, INT_MAX),
new IntGameOption(SIMPLE_NAME(tile_font_tip_size), 0, 0, INT_MAX),
new IntGameOption(SIMPLE_NAME(tile_font_lbl_size), 0, 0, INT_MAX),
new IntGameOption(SIMPLE_NAME(tile_cell_pixels), 32, 1, INT_MAX),
new IntGameOption(SIMPLE_NAME(tile_map_pixels), 0, 0, INT_MAX),
new IntGameOption(SIMPLE_NAME(tile_tooltip_ms), 500, 0, INT_MAX),
new IntGameOption(SIMPLE_NAME(tile_update_rate), 1000, 50, INT_MAX),
new IntGameOption(SIMPLE_NAME(tile_runrest_rate), 100, 0, INT_MAX),
// minimap colours
new TileColGameOption(SIMPLE_NAME(tile_branchstairs_col), "#ff7788"),
new TileColGameOption(SIMPLE_NAME(tile_deep_water_col), "#001122"),
new TileColGameOption(SIMPLE_NAME(tile_door_col), "#775544"),
new TileColGameOption(SIMPLE_NAME(tile_downstairs_col), "#ff00ff"),
new TileColGameOption(SIMPLE_NAME(tile_excl_centre_col), "#552266"),
new TileColGameOption(SIMPLE_NAME(tile_excluded_col), "#552266"),
new TileColGameOption(SIMPLE_NAME(tile_explore_horizon_col), "#6B301B"),
new TileColGameOption(SIMPLE_NAME(tile_feature_col), "#997700"),
new TileColGameOption(SIMPLE_NAME(tile_floor_col), "#333333"),
new TileColGameOption(SIMPLE_NAME(tile_item_col), "#005544"),
new TileColGameOption(SIMPLE_NAME(tile_lava_col), "#552211"),
new TileColGameOption(SIMPLE_NAME(tile_mapped_floor_col), "#222266"),
new TileColGameOption(SIMPLE_NAME(tile_mapped_wall_col), "#444499"),
new TileColGameOption(SIMPLE_NAME(tile_monster_col), "#660000"),
new TileColGameOption(SIMPLE_NAME(tile_plant_col), "#446633"),
new TileColGameOption(SIMPLE_NAME(tile_player_col), "white"),
new TileColGameOption(SIMPLE_NAME(tile_portal_col), "#ffdd00"),
new TileColGameOption(SIMPLE_NAME(tile_trap_col), "#aa6644"),
new TileColGameOption(SIMPLE_NAME(tile_unseen_col), "black"),
new TileColGameOption(SIMPLE_NAME(tile_upstairs_col), "cyan"),
new TileColGameOption(SIMPLE_NAME(tile_transporter_col), "#0000ff"),
new TileColGameOption(SIMPLE_NAME(tile_transporter_landing_col), "#5200aa"),
new TileColGameOption(SIMPLE_NAME(tile_wall_col), "#666666"),
new TileColGameOption(SIMPLE_NAME(tile_water_col), "#114455"),
new TileColGameOption(SIMPLE_NAME(tile_window_col), "#558855"),
new ListGameOption<string>(SIMPLE_NAME(tile_layout_priority),
#ifdef TOUCH_UI
split_string(",", "minimap, command, inventory, "
"command2, spell, ability, monster")),
#else
split_string(",", "minimap, inventory, command, "
"spell, ability, monster")),
#endif
#endif
#ifdef USE_TILE_LOCAL
new IntGameOption(SIMPLE_NAME(tile_key_repeat_delay), 200, 0, INT_MAX),
new IntGameOption(SIMPLE_NAME(tile_window_width), -90, INT_MIN, INT_MAX),
new IntGameOption(SIMPLE_NAME(tile_window_height), -90, INT_MIN, INT_MAX),
new StringGameOption(SIMPLE_NAME(tile_font_crt_file), MONOSPACED_FONT),
new StringGameOption(SIMPLE_NAME(tile_font_msg_file), MONOSPACED_FONT),
new StringGameOption(SIMPLE_NAME(tile_font_stat_file), MONOSPACED_FONT),
new StringGameOption(SIMPLE_NAME(tile_font_tip_file), MONOSPACED_FONT),
new StringGameOption(SIMPLE_NAME(tile_font_lbl_file), PROPORTIONAL_FONT),
new BoolGameOption(SIMPLE_NAME(tile_single_column_menus), true),
#endif
#ifdef USE_TILE_WEB
new BoolGameOption(SIMPLE_NAME(tile_realtime_anim), false),
new BoolGameOption(SIMPLE_NAME(tile_level_map_hide_messages), true),
new BoolGameOption(SIMPLE_NAME(tile_level_map_hide_sidebar), false),
new BoolGameOption(SIMPLE_NAME(tile_web_mouse_control), true),
new StringGameOption(SIMPLE_NAME(tile_font_crt_family), "monospace"),
new StringGameOption(SIMPLE_NAME(tile_font_msg_family), "monospace"),
new StringGameOption(SIMPLE_NAME(tile_font_stat_family), "monospace"),
new StringGameOption(SIMPLE_NAME(tile_font_lbl_family), "monospace"),
#endif
#ifdef USE_FT
new BoolGameOption(SIMPLE_NAME(tile_font_ft_light), false),
#endif
#ifdef WIZARD
new BoolGameOption(SIMPLE_NAME(fsim_csv), false),
new ListGameOption<string>(SIMPLE_NAME(fsim_scale)),
new ListGameOption<string>(SIMPLE_NAME(fsim_kit)),
new StringGameOption(SIMPLE_NAME(fsim_mode), ""),
new StringGameOption(SIMPLE_NAME(fsim_mons), ""),
new IntGameOption(SIMPLE_NAME(fsim_rounds), 4000, 1000, 500000),
#endif
#if !defined(DGAMELAUNCH) || defined(DGL_REMEMBER_NAME)
new BoolGameOption(SIMPLE_NAME(remember_name), true),
#endif
};
#undef SIMPLE_NAME
return options;
}
map<string, GameOption*> game_options::build_options_map(
const vector<GameOption*> &options)
{
map<string, GameOption*> option_map;
for (GameOption* option : options)
for (string name : option->getNames())
option_map[name] = option;
return option_map;
}
object_class_type item_class_by_sym(char32_t c)
{
switch (c)
{
case ')':
return OBJ_WEAPONS;
case '(':
case U'➹':
return OBJ_MISSILES;
case '[':
return OBJ_ARMOUR;
case '/':
return OBJ_WANDS;
case '%':
return OBJ_FOOD;
case '?':
return OBJ_SCROLLS;
case '"': // Make the amulet symbol equiv to ring -- bwross
case '=':
case U'°':
return OBJ_JEWELLERY;
case '!':
return OBJ_POTIONS;
case ':':
case '+': // ??? -- was the only symbol working for tile order up to 0.10,
// so keeping it for compat purposes (user configs).
case U'∞':
return OBJ_BOOKS;
case '|':
return OBJ_STAVES;
case '0':
return OBJ_ORBS;
case '}':
return OBJ_MISCELLANY;
case '&':
case 'X':
case 'x':
return OBJ_CORPSES;
case '$':
case U'€':
case U'£':
case U'¥': // FR: support more currencies
return OBJ_GOLD;
#if TAG_MAJOR_VERSION == 34
case '\\': // Compat break: used to be staves (why not '|'?).
return OBJ_RODS;
#endif
default:
return NUM_OBJECT_CLASSES;
}
}
// Returns MSGCOL_NONE if unmatched else returns 0-15.
static msg_colour_type _str_to_channel_colour(const string &str)
{
int col = str_to_colour(str);
msg_colour_type ret = MSGCOL_NONE;
if (col == -1)
{
if (str == "mute")
ret = MSGCOL_MUTED;
else if (str == "plain" || str == "off")
ret = MSGCOL_PLAIN;
else if (str == "default" || str == "on")
ret = MSGCOL_DEFAULT;
else if (str == "alternate")
ret = MSGCOL_ALTERNATE;
}
else
ret = msg_colour(col);
return ret;
}
static const string message_channel_names[] =
{
"plain", "friend_action", "prompt", "god", "duration", "danger", "warning",
"food", "recovery", "sound", "talk", "talk_visual", "intrinsic_gain",
"mutation", "monster_spell", "monster_enchant", "friend_spell",
"friend_enchant", "monster_damage", "monster_target", "banishment",
"rotten_meat", "equipment", "floor", "multiturn", "examine",
"examine_filter", "diagnostic", "error", "tutorial", "orb", "timed_portal",
"hell_effect", "monster_warning", "dgl_message",
};
// returns -1 if unmatched else returns 0--(NUM_MESSAGE_CHANNELS-1)
int str_to_channel(const string &str)
{
COMPILE_CHECK(ARRAYSZ(message_channel_names) == NUM_MESSAGE_CHANNELS);
// widespread aliases
if (str == "visual")
return MSGCH_TALK_VISUAL;
else if (str == "spell")
return MSGCH_MONSTER_SPELL;
for (int ret = 0; ret < NUM_MESSAGE_CHANNELS; ret++)
{
if (str == message_channel_names[ret])
return ret;
}
return -1;
}
string channel_to_str(int channel)
{
if (channel < 0 || channel >= NUM_MESSAGE_CHANNELS)
return "";
return message_channel_names[channel];
}
// The map used to interpret a crawlrc entry as a starting weapon
// type. For most entries, we can just look up which weapon has the entry as
// its name; this map contains the exceptions.
// This should be const, but operator[] on maps isn't const.
static map<string, weapon_type> _special_weapon_map = {
// "staff" normally refers to a magical staff, but here we want to
// interpret it as a quarterstaff.
{"staff", WPN_QUARTERSTAFF},
// These weapons' base names have changed; we want to interpret the old
// names correctly.
{"sling", WPN_HUNTING_SLING},
{"crossbow", WPN_HAND_CROSSBOW},
// Pseudo-weapons.
{"unarmed", WPN_UNARMED},
{"claws", WPN_UNARMED},
{"thrown", WPN_THROWN},
{"rocks", WPN_THROWN},
{"tomahawks", WPN_THROWN},
{"javelins", WPN_THROWN},
{"random", WPN_RANDOM},
{"viable", WPN_VIABLE},
};
/**
* Interpret a crawlrc entry as a starting weapon type.
*
* @param str The value of the crawlrc entry.
* @return The weapon the string refers to, or WPN_UNKNOWN if invalid
*/
weapon_type str_to_weapon(const string &str)
{
string str_nospace = str;
remove_whitespace(str_nospace);
// Synonyms and pseudo-weapons.
if (_special_weapon_map.count(str_nospace))
return _special_weapon_map[str_nospace];
// Real weapons referred to by their standard names.
return name_nospace_to_weapon(str_nospace);
}
static string _weapon_to_str(weapon_type wpn_type)
{
if (wpn_type >= 0 && wpn_type < NUM_WEAPONS)
return weapon_base_name(wpn_type);
switch (wpn_type)
{
case WPN_UNARMED:
return "claws";
case WPN_THROWN:
return "thrown";
case WPN_VIABLE:
return "viable";
case WPN_RANDOM:
default:
return "random";
}
}
// Summon types can be any of mon_summon_type (enum.h), or a relevant summoning
// spell.
int str_to_summon_type(const string &str)
{
if (str == "clone")
return MON_SUMM_CLONE;
if (str == "animate")
return MON_SUMM_ANIMATE;
if (str == "chaos")
return MON_SUMM_CHAOS;
if (str == "miscast")
return MON_SUMM_MISCAST;
if (str == "zot")
return MON_SUMM_ZOT;
if (str == "wrath")
return MON_SUMM_WRATH;
if (str == "aid")
return MON_SUMM_AID;
return spell_by_name(str);
}
static fire_type _str_to_fire_types(const string &str)
{
if (str == "launcher")
return FIRE_LAUNCHER;
else if (str == "stone")
return FIRE_STONE;
else if (str == "rock")
return FIRE_ROCK;
else if (str == "javelin")
return FIRE_JAVELIN;
else if (str == "tomahawk")
return FIRE_TOMAHAWK;
else if (str == "net")
return FIRE_NET;
else if (str == "return" || str == "returning")
return FIRE_RETURNING;
else if (str == "inscribed")
return FIRE_INSCRIBED;
return FIRE_NONE;
}
string gametype_to_str(game_type type)
{
switch (type)
{
case GAME_TYPE_NORMAL:
return "normal";
case GAME_TYPE_TUTORIAL:
return "tutorial";
case GAME_TYPE_ARENA:
return "arena";
case GAME_TYPE_SPRINT:
return "sprint";
case GAME_TYPE_HINTS:
return "hints";
default:
return "none";
}
}
#ifndef DGAMELAUNCH
static game_type _str_to_gametype(const string& s)
{
for (int i = 0; i < NUM_GAME_TYPE; ++i)
{
game_type t = static_cast<game_type>(i);
if (s == gametype_to_str(t))
return t;
}
return NUM_GAME_TYPE;
}
#endif
static string _species_to_str(species_type sp)
{
if (sp == SP_RANDOM)
return "random";
else if (sp == SP_VIABLE)
return "viable";
else
return species_name(sp);
}
static species_type _str_to_species(const string &str)
{
if (str == "random")
return SP_RANDOM;
else if (str == "viable")
return SP_VIABLE;
species_type ret = SP_UNKNOWN;
if (str.length() == 2) // scan abbreviations
ret = get_species_by_abbrev(str.c_str());
// if we don't have a match, scan the full names
if (ret == SP_UNKNOWN && str.length() >= 2)
ret = find_species_from_string(str, true);
if (!is_starting_species(ret))
ret = SP_UNKNOWN;
if (ret == SP_UNKNOWN)
fprintf(stderr, "Unknown species choice: %s\n", str.c_str());
return ret;
}
static string _job_to_str(job_type job)
{
if (job == JOB_RANDOM)
return "random";
else if (job == JOB_VIABLE)
return "viable";
else
return get_job_name(job);
}
job_type str_to_job(const string &str)
{
if (str == "random")
return JOB_RANDOM;
else if (str == "viable")
return JOB_VIABLE;
job_type job = JOB_UNKNOWN;
if (str.length() == 2) // scan abbreviations
job = get_job_by_abbrev(str.c_str());
// if we don't have a match, scan the full names
if (job == JOB_UNKNOWN)
job = get_job_by_name(str.c_str());
if (!is_starting_job(job))
job = JOB_UNKNOWN;
if (job == JOB_UNKNOWN)
fprintf(stderr, "Unknown background choice: %s\n", str.c_str());
return job;
}
// read a value which can be either a boolean (in which case return
// 0 for true, -1 for false), or a string of the form PREFIX:NUMBER
// (e.g., auto:7), in which case return NUMBER as an int.
static int _read_bool_or_number(const string &field, int def_value,
const string& num_prefix)
{
int ret = def_value;
if (field == "true" || field == "1" || field == "yes")
ret = 0;
if (field == "false" || field == "0" || field == "no")
ret = -1;
if (starts_with(field, num_prefix))
ret = atoi(field.c_str() + num_prefix.size());
return ret;
}
void game_options::str_to_enemy_hp_colour(const string &colours, bool prepend)
{
vector<string> colour_list = split_string(" ", colours, true, true);
if (prepend)
reverse(colour_list.begin(), colour_list.end());
for (const string &colstr : colour_list)
{
const int col = str_to_colour(colstr);
if (col < 0)
{
Options.report_error("Bad enemy_hp_colour: %s\n", colstr.c_str());
return;
}
else if (prepend)
enemy_hp_colour.insert(enemy_hp_colour.begin(), col);
else
enemy_hp_colour.push_back(col);
}
}
#ifdef USE_TILE
static FixedVector<const char*, TAGPREF_MAX>
tag_prefs("none", "tutorial", "named", "enemy");
static tag_pref _str_to_tag_pref(const char *opt)
{
for (int i = 0; i < TAGPREF_MAX; i++)
{
if (!strcasecmp(opt, tag_prefs[i]))
return (tag_pref)i;
}
return TAGPREF_ENEMY;
}
#endif
void game_options::new_dump_fields(const string &text, bool add, bool prepend)
{
// Easy; chardump.cc has most of the intelligence.
vector<string> fields = split_string(",", text, true, true);
if (add)
merge_lists(dump_order, fields, prepend);
else
{
for (const string &field : fields)
erase_val(dump_order, field);
}
}
static string _correct_spelling(const string& str)
{
if (str == "armor_on")
return "armour_on";
if (str == "armor_off")
return "armour_off";
if (str == "memorize")
return "memorise";
if (str == "jewelry_on")
return "jewellery_on";
return str;
}
void game_options::set_default_activity_interrupts()
{
const char *default_activity_interrupts[] =
{
"interrupt_armour_on = hp_loss, monster_attack, monster, mimic",
"interrupt_armour_off = interrupt_armour_on",
"interrupt_drop_item = interrupt_armour_on",
"interrupt_jewellery_on = interrupt_armour_on",
"interrupt_memorise = hp_loss, monster_attack, stat",
"interrupt_butcher = interrupt_armour_on, teleport, stat",
"interrupt_bottle_blood = interrupt_butcher",
"interrupt_vampire_feed = interrupt_butcher",
"interrupt_multidrop = hp_loss, monster_attack, teleport, stat",
"interrupt_macro = interrupt_multidrop",
"interrupt_travel = interrupt_butcher, hungry, hit_monster, "
"sense_monster",
"interrupt_run = interrupt_travel, message",
"interrupt_rest = interrupt_run, full_hp, full_mp",
// Stair ascents/descents cannot be interrupted except by
// teleportation. Attempts to interrupt the delay will just
// trash all queued delays, including travel.
"interrupt_ascending_stairs = teleport",
"interrupt_descending_stairs = teleport",
// These are totally uninterruptible by default, since it's
// impossible for them to be interrupted anyway.
"interrupt_drop_item = ",
"interrupt_jewellery_off =",
};
for (const char* line : default_activity_interrupts)
read_option_line(line, false);
}
void game_options::set_activity_interrupt(
FixedBitVector<NUM_AINTERRUPTS> &eints,
const string &interrupt)
{
if (starts_with(interrupt, interrupt_prefix))
{
string delay_name =
_correct_spelling(interrupt.substr(interrupt_prefix.length()));
if (!activity_interrupts.count(delay_name))
return report_error("Unknown delay: %s\n", delay_name.c_str());
FixedBitVector<NUM_AINTERRUPTS> &refints =
activity_interrupts[delay_name];
eints |= refints;
return;
}
activity_interrupt_type ai = get_activity_interrupt(interrupt);
if (ai == NUM_AINTERRUPTS)
{
return report_error("Delay interrupt name \"%s\" not recognised.\n",
interrupt.c_str());
}
eints.set(ai);
}
void game_options::set_activity_interrupt(const string &activity_name,
const string &interrupt_names,
bool append_interrupts,
bool remove_interrupts)
{
vector<string> interrupts = split_string(",", interrupt_names);
auto & eints = activity_interrupts[_correct_spelling(activity_name)];
if (remove_interrupts)
{
FixedBitVector<NUM_AINTERRUPTS> refints;
for (const string &interrupt : interrupts)
set_activity_interrupt(refints, interrupt);
for (int i = 0; i < NUM_AINTERRUPTS; ++i)
if (refints[i])
eints.set(i, false);
}
else
{
if (!append_interrupts)
eints.reset();
for (const string &interrupt : interrupts)
set_activity_interrupt(eints, interrupt);
}
eints.set(AI_FORCE_INTERRUPT);
}
#if defined(DGAMELAUNCH)
static string _resolve_dir(string path, string suffix)
{
return catpath(path, "");
}
#else
static string _user_home_dir()
{
#ifdef TARGET_OS_WINDOWS
wchar_t home[MAX_PATH];
if (SHGetFolderPathW(0, CSIDL_APPDATA, 0, 0, home))
return "./";
else
return utf16_to_8(home);
#else
const char *home = getenv("HOME");
if (!home || !*home)
return "./";
else
return mb_to_utf8(home);
#endif
}
static string _user_home_subpath(const string &subpath)
{
return catpath(_user_home_dir(), subpath);
}
static string _resolve_dir(string path, string suffix)
{
if (path[0] != '~')
return catpath(string(path), suffix);
else
return _user_home_subpath(catpath(path.substr(1), suffix));
}
#endif
static string _get_save_path(string subdir)
{
return _resolve_dir(SysEnv.crawl_dir, subdir);
}
void game_options::reset_options()
{
// XXX: do we really need to rebuild the list and map every time?
// Will they ever change within a single execution of Crawl?
// GameOption::value's value will change of course, but not the reference.
deleteAll(option_behaviour);
option_behaviour = build_options_list();
options_by_name = build_options_map(option_behaviour);
for (GameOption* option : option_behaviour)
option->reset();
filename = "unknown";
basefilename = "unknown";
line_num = -1;
set_default_activity_interrupts();
#ifdef DEBUG_DIAGNOSTICS
quiet_debug_messages.reset();
#ifdef DEBUG_MONSPEAK
quiet_debug_messages.set(DIAG_SPEECH);
#endif
# ifdef DEBUG_MONINDEX
quiet_debug_messages.set(DIAG_MONINDEX);
# endif
#endif
macro_dir = SysEnv.macro_dir;
#ifdef DGAMELAUNCH
save_dir = _get_save_path("saves/");
morgue_dir = _get_save_path("morgue/");
#else
if (macro_dir.empty())
{
#ifdef UNIX
macro_dir = _user_home_subpath(".crawl");
#else
macro_dir = "settings/";
#endif
}
#endif
#if defined(TARGET_OS_MACOSX)
UNUSED(_resolve_dir);