forked from cataclysmbnteam/Cataclysm-BN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug_menu.cpp
2091 lines (1941 loc) · 83.3 KB
/
debug_menu.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 "debug_menu.h"
// IWYU pragma: no_include <cxxabi.h>
#include <algorithm>
#include <array>
#include <chrono>
#include <csignal>
#include <cstdint>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <optional>
#include <sstream>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include "action.h"
#include "artifact.h"
#include "avatar.h"
#include "bodypart.h"
#include "calendar.h"
#include "cata_utility.h"
#include "catacharset.h"
#include "character.h"
#include "character_display.h"
#include "character_id.h"
#include "character_martial_arts.h"
#include "color.h"
#include "coordinate_conversions.h"
#include "coordinates.h"
#include "cursesdef.h"
#include "debug.h"
#include "effect.h"
#include "enum_conversions.h"
#include "enums.h"
#include "faction.h"
#include "filesystem.h"
#include "game.h"
#include "game_constants.h"
#include "game_inventory.h"
#include "input.h"
#include "inventory.h"
#include "item.h"
#include "item_group.h"
#include "item_location.h"
#include "language.h"
#include "magic.h"
#include "map.h"
#include "map_extras.h"
#include "map_iterator.h"
#include "mapgen.h"
#include "mapgendata.h"
#include "martialarts.h"
#include "memory_fast.h"
#include "messages.h"
#include "mission.h"
#include "monster.h"
#include "monstergenerator.h"
#include "morale_types.h"
#include "mtype.h"
#include "npc.h"
#include "npc_class.h"
#include "omdata.h"
#include "options.h"
#include "output.h"
#include "overmap.h"
#include "overmap_ui.h"
#include "overmapbuffer.h"
#include "pimpl.h"
#include "player.h"
#include "pldata.h"
#include "point.h"
#include "popup.h"
#include "recipe_dictionary.h"
#include "rng.h"
#include "sounds.h"
#include "stomach.h"
#include "string_formatter.h"
#include "string_id.h"
#include "string_input_popup.h"
#include "string_utils.h"
#include "trait_group.h"
#include "translations.h"
#include "type_id.h"
#include "ui.h"
#include "ui_manager.h"
#include "uistate.h"
#include "units.h"
#include "units_utility.h"
#include "url_utility.h"
#include "vehicle.h"
#include "veh_type.h"
#include "vitamin.h"
#include "vpart_position.h"
#include "weather.h"
#include "weather_gen.h"
#include "weighted_list.h"
static const mtype_id mon_generator( "mon_generator" );
extern std::map<std::string, weighted_int_list<std::shared_ptr<mapgen_function_json_nested>> >
nested_mapgen;
#if defined(TILES)
#include "sdl_wrappers.h"
#endif
namespace debug_menu
{
enum debug_menu_index {
DEBUG_WISH,
DEBUG_SHORT_TELEPORT,
DEBUG_LONG_TELEPORT,
DEBUG_REVEAL_MAP,
DEBUG_SPAWN_NPC,
DEBUG_SPAWN_MON,
DEBUG_GAME_STATE,
DEBUG_KILL_AREA,
DEBUG_KILL_NPCS,
DEBUG_MUTATE,
DEBUG_SPAWN_VEHICLE,
DEBUG_EDIT_PLAYER,
DEBUG_SPAWN_ARTIFACT,
DEBUG_SPAWN_CLAIRVOYANCE,
DEBUG_MAP_EDITOR,
DEBUG_CHANGE_WEATHER,
DEBUG_WIND_DIRECTION,
DEBUG_WIND_SPEED,
DEBUG_GEN_SOUND,
DEBUG_KILL_MONS,
DEBUG_DISPLAY_HORDES,
DEBUG_TEST_IT_GROUP,
DEBUG_DAMAGE_SELF,
DEBUG_SHOW_SOUND,
DEBUG_DISPLAY_WEATHER,
DEBUG_DISPLAY_SCENTS,
DEBUG_DISPLAY_DISTRIBUTION_GRIDS,
DEBUG_CHANGE_TIME,
DEBUG_SET_AUTOMOVE,
DEBUG_SHOW_MUT_CAT,
DEBUG_SHOW_MUT_CHANCES,
DEBUG_OM_EDITOR,
DEBUG_BENCHMARK,
DEBUG_BENCHMARK_FPS,
DEBUG_OM_TELEPORT,
DEBUG_OM_TELEPORT_COORDINATES,
DEBUG_TRAIT_GROUP,
DEBUG_SHOW_MSG,
DEBUG_CRASH_GAME,
DEBUG_RELOAD_TRANSLATIONS,
DEBUG_MAP_EXTRA,
DEBUG_DISPLAY_NPC_PATH,
DEBUG_PRINT_FACTION_INFO,
DEBUG_PRINT_NPC_MAGIC,
DEBUG_QUIT_NOSAVE,
DEBUG_TEST_WEATHER,
DEBUG_SAVE_SCREENSHOT,
DEBUG_BUG_REPORT,
DEBUG_GAME_REPORT,
DEBUG_DISPLAY_SCENTS_LOCAL,
DEBUG_DISPLAY_SCENTS_TYPE_LOCAL,
DEBUG_DISPLAY_TEMP,
DEBUG_DISPLAY_VEHICLE_AI,
DEBUG_DISPLAY_VISIBILITY,
DEBUG_DISPLAY_LIGHTING,
DEBUG_DISPLAY_RADIATION,
DEBUG_DISPLAY_TRANSPARENCY,
DEBUG_DISPLAY_SUBMAP_GRID,
DEBUG_TEST_MAP_EXTRA_DISTRIBUTION,
DEBUG_VEHICLE_BATTERY_CHARGE,
DEBUG_HOUR_TIMER,
DEBUG_NESTED_MAPGEN,
DEBUG_RESET_IGNORED_MESSAGES,
DEBUG_RELOAD_TILES,
};
class mission_debug
{
private:
// Doesn't actually "destroy" the mission, just removes assignments
static void remove_mission( mission &m );
public:
static void edit_mission( mission &m );
static void edit( player &who );
static void edit_player();
static void edit_npc( npc &who );
static std::string describe( const mission &m );
};
static int info_uilist( bool display_all_entries = true )
{
// always displayed
std::vector<uilist_entry> uilist_initializer = {
{ uilist_entry( DEBUG_SAVE_SCREENSHOT, true, 'H', _( "Take screenshot" ) ) },
{ uilist_entry( DEBUG_BUG_REPORT, true, 'U', _( "Submit a bug report on github" ) ) },
{ uilist_entry( DEBUG_GAME_REPORT, true, 'r', _( "Generate game report" ) ) },
};
if( display_all_entries ) {
const std::vector<uilist_entry> debug_only_options = {
{ uilist_entry( DEBUG_GAME_STATE, true, 'g', _( "Check game state" ) ) },
{ uilist_entry( DEBUG_DISPLAY_HORDES, true, 'h', _( "Display hordes" ) ) },
{ uilist_entry( DEBUG_TEST_IT_GROUP, true, 'i', _( "Test item group" ) ) },
{ uilist_entry( DEBUG_SHOW_SOUND, true, 'c', _( "Show sound clustering" ) ) },
{ uilist_entry( DEBUG_DISPLAY_WEATHER, true, 'w', _( "Display weather" ) ) },
{ uilist_entry( DEBUG_DISPLAY_SCENTS, true, 'S', _( "Display overmap scents" ) ) },
{ uilist_entry( DEBUG_DISPLAY_DISTRIBUTION_GRIDS, true, 'G', _( "Display overmap distribution grids" ) ) },
{ uilist_entry( DEBUG_DISPLAY_SCENTS_LOCAL, true, 's', _( "Toggle display local scents" ) ) },
{ uilist_entry( DEBUG_DISPLAY_SCENTS_TYPE_LOCAL, true, 'y', _( "Toggle display local scents type" ) ) },
{ uilist_entry( DEBUG_DISPLAY_TEMP, true, 'T', _( "Toggle display temperature" ) ) },
{ uilist_entry( DEBUG_DISPLAY_VEHICLE_AI, true, 'V', _( "Toggle display vehicle autopilot overlay" ) ) },
{ uilist_entry( DEBUG_DISPLAY_VISIBILITY, true, 'v', _( "Toggle display visibility" ) ) },
{ uilist_entry( DEBUG_DISPLAY_LIGHTING, true, 'l', _( "Toggle display lighting" ) ) },
{ uilist_entry( DEBUG_DISPLAY_TRANSPARENCY, true, 'p', _( "Toggle display transparency" ) ) },
{ uilist_entry( DEBUG_DISPLAY_RADIATION, true, 'R', _( "Toggle display radiation" ) ) },
{ uilist_entry( DEBUG_DISPLAY_SUBMAP_GRID, true, 'o', _( "Toggle display submap grid" ) ) },
{ uilist_entry( DEBUG_SHOW_MUT_CAT, true, 'm', _( "Show mutation category levels" ) ) },
{ uilist_entry( DEBUG_SHOW_MUT_CHANCES, true, 'u', _( "Show mutation trait chances" ) ) },
{ uilist_entry( DEBUG_BENCHMARK, true, 'b', _( "Draw benchmark" ) ) },
{ uilist_entry( DEBUG_BENCHMARK_FPS, true, 'B', _( "FPS benchmark" ) ) },
{ uilist_entry( DEBUG_HOUR_TIMER, true, 'E', _( "Toggle hour timer" ) ) },
{ uilist_entry( DEBUG_TRAIT_GROUP, true, 't', _( "Test trait group" ) ) },
{ uilist_entry( DEBUG_SHOW_MSG, true, 'd', _( "Show debug message" ) ) },
{ uilist_entry( DEBUG_CRASH_GAME, true, 'C', _( "Crash game (test crash handling)" ) ) },
{ uilist_entry( DEBUG_RELOAD_TRANSLATIONS, true, 'L', _( "Reload translations" ) ) },
{ uilist_entry( DEBUG_DISPLAY_NPC_PATH, true, 'n', _( "Toggle NPC pathfinding on map" ) ) },
{ uilist_entry( DEBUG_PRINT_FACTION_INFO, true, 'f', _( "Print faction info to console" ) ) },
{ uilist_entry( DEBUG_PRINT_NPC_MAGIC, true, 'M', _( "Print NPC magic info to console" ) ) },
{ uilist_entry( DEBUG_TEST_WEATHER, true, 'W', _( "Test weather" ) ) },
{ uilist_entry( DEBUG_TEST_MAP_EXTRA_DISTRIBUTION, true, 'e', _( "Test map extra list" ) ) },
{ uilist_entry( DEBUG_RESET_IGNORED_MESSAGES, true, 'I', _( "Reset ignored debug messages" ) ) },
#if defined(TILES)
{ uilist_entry( DEBUG_RELOAD_TILES, true, 'D', _( "Reload tileset and show missing tiles" ) ) },
#endif
};
uilist_initializer.insert( uilist_initializer.begin(), debug_only_options.begin(),
debug_only_options.end() );
}
return uilist( _( "Info…" ), uilist_initializer );
}
static int vehicle_uilist()
{
std::vector<uilist_entry> uilist_initializer = {
{ uilist_entry( DEBUG_VEHICLE_BATTERY_CHARGE, true, 'b', _( "Change [b]attery charge" ) ) },
};
return uilist( _( "Vehicle…" ), uilist_initializer );
}
static int teleport_uilist()
{
const std::vector<uilist_entry> uilist_initializer = {
{ uilist_entry( DEBUG_SHORT_TELEPORT, true, 's', _( "Teleport - short range" ) ) },
{ uilist_entry( DEBUG_LONG_TELEPORT, true, 'l', _( "Teleport - long range" ) ) },
{ uilist_entry( DEBUG_OM_TELEPORT, true, 'o', _( "Teleport - adjacent overmap" ) ) },
{ uilist_entry( DEBUG_OM_TELEPORT_COORDINATES, true, 'p', _( "Teleport - specific overmap coordinates" ) ) },
};
return uilist( _( "Teleport…" ), uilist_initializer );
}
static int spawning_uilist()
{
const std::vector<uilist_entry> uilist_initializer = {
{ uilist_entry( DEBUG_WISH, true, 'w', _( "Spawn an item" ) ) },
{ uilist_entry( DEBUG_SPAWN_NPC, true, 'n', _( "Spawn NPC" ) ) },
{ uilist_entry( DEBUG_SPAWN_MON, true, 'm', _( "Spawn monster" ) ) },
{ uilist_entry( DEBUG_SPAWN_VEHICLE, true, 'v', _( "Spawn a vehicle" ) ) },
{ uilist_entry( DEBUG_SPAWN_ARTIFACT, true, 'a', _( "Spawn artifact" ) ) },
{ uilist_entry( DEBUG_SPAWN_CLAIRVOYANCE, true, 'c', _( "Spawn clairvoyance artifact" ) ) },
};
return uilist( _( "Spawning…" ), uilist_initializer );
}
static int map_uilist()
{
const std::vector<uilist_entry> uilist_initializer = {
{ uilist_entry( DEBUG_REVEAL_MAP, true, 'r', _( "Reveal map" ) ) },
{ uilist_entry( DEBUG_KILL_AREA, true, 'a', _( "Kill in Area" ) ) },
{ uilist_entry( DEBUG_KILL_NPCS, true, 'k', _( "Kill NPCs" ) ) },
{ uilist_entry( DEBUG_MAP_EDITOR, true, 'M', _( "Map editor" ) ) },
{ uilist_entry( DEBUG_CHANGE_WEATHER, true, 'w', _( "Change weather" ) ) },
{ uilist_entry( DEBUG_WIND_DIRECTION, true, 'd', _( "Change wind direction" ) ) },
{ uilist_entry( DEBUG_WIND_SPEED, true, 's', _( "Change wind speed" ) ) },
{ uilist_entry( DEBUG_GEN_SOUND, true, 'S', _( "Generate sound" ) ) },
{ uilist_entry( DEBUG_KILL_MONS, true, 'K', _( "Kill all monsters" ) ) },
{ uilist_entry( DEBUG_CHANGE_TIME, true, 't', _( "Change time" ) ) },
{ uilist_entry( DEBUG_OM_EDITOR, true, 'O', _( "Overmap editor" ) ) },
{ uilist_entry( DEBUG_MAP_EXTRA, true, 'm', _( "Spawn map extra" ) ) },
{ uilist_entry( DEBUG_NESTED_MAPGEN, true, 'n', _( "Spawn nested mapgen" ) ) },
};
return uilist( _( "Map…" ), uilist_initializer );
}
/**
* Create the debug menu UI list.
* @param display_all_entries: `true` if all entries should be displayed, `false` is some entries should be hidden (for ex. when the debug menu is called from the main menu).
* This allows to have some menu elements at the same time in the main menu and in the debug menu.
* @returns The chosen action.
*/
static int debug_menu_uilist( bool display_all_entries = true )
{
std::vector<uilist_entry> menu = {
{ uilist_entry( 1, true, 'i', _( "Info…" ) ) },
};
if( display_all_entries ) {
const std::vector<uilist_entry> debug_menu = {
{ uilist_entry( DEBUG_QUIT_NOSAVE, true, 'Q', _( "Quit to main menu" ) ) },
{ uilist_entry( 2, true, 's', _( "Spawning…" ) ) },
{ uilist_entry( 3, true, 'p', _( "Player…" ) ) },
{ uilist_entry( 6, true, 'v', _( "Vehicle…" ) ) },
{ uilist_entry( 4, true, 't', _( "Teleport…" ) ) },
{ uilist_entry( 5, true, 'm', _( "Map…" ) ) },
};
// insert debug-only menu right after "Info".
menu.insert( menu.begin() + 1, debug_menu.begin(), debug_menu.end() );
}
std::string msg;
if( display_all_entries ) {
msg = _( "Debug Functions - Manipulate the fabric of reality!\nYou can use them to fix a bug or test something.\nBe careful, as some of them may potentially break things." );
} else {
msg = _( "Debug Functions" );
}
while( true ) {
const int group = uilist( msg, menu );
int action;
switch( group ) {
case DEBUG_QUIT_NOSAVE:
action = DEBUG_QUIT_NOSAVE;
break;
case 1:
action = info_uilist( display_all_entries );
break;
case 2:
action = spawning_uilist();
break;
case 3:
action = -1;
debug_menu::character_edit_menu( get_player_character() );
break;
case 4:
action = teleport_uilist();
break;
case 5:
action = map_uilist();
break;
case 6:
action = vehicle_uilist();
break;
default:
return group;
}
if( action >= 0 ) {
return action;
}
}
}
void teleport_short()
{
const std::optional<tripoint> where = g->look_around( true );
if( !where || *where == g->u.pos() ) {
return;
}
g->place_player( *where );
const tripoint new_pos( g->u.pos() );
add_msg( _( "You teleport to point (%d,%d,%d)." ), new_pos.x, new_pos.y, new_pos.z );
}
void teleport_long()
{
const tripoint_abs_omt where( ui::omap::choose_point() );
if( where == overmap::invalid_tripoint ) {
return;
}
g->place_player_overmap( where );
add_msg( _( "You teleport to submap %s." ), where.to_string() );
}
void teleport_overmap( bool specific_coordinates )
{
tripoint_abs_omt where;
if( specific_coordinates ) {
const std::string text = string_input_popup()
.title( "Teleport where?" )
.width( 20 )
.query_string();
if( text.empty() ) {
return;
}
const std::vector<std::string> coord_strings = string_split( text, ',' );
tripoint coord;
coord.x = !coord_strings.empty() ? std::atoi( coord_strings[0].c_str() ) : 0;
coord.y = coord_strings.size() >= 2 ? std::atoi( coord_strings[1].c_str() ) : 0;
coord.z = coord_strings.size() >= 3 ? std::atoi( coord_strings[2].c_str() ) : 0;
where = tripoint_abs_omt( OMAPX * coord.x, OMAPY * coord.y, coord.z );
} else {
const std::optional<tripoint> dir_ = choose_direction( _( "Where is the desired overmap?" ) );
if( !dir_ ) {
return;
}
const tripoint offset = tripoint( OMAPX * dir_->x, OMAPY * dir_->y, dir_->z );
where = g->u.global_omt_location() + offset;
}
g->place_player_overmap( where );
const tripoint_abs_om new_pos = project_to<coords::om>( g->u.global_omt_location() );
add_msg( _( "You teleport to overmap %s." ), new_pos.to_string() );
}
void spawn_nested_mapgen()
{
uilist nest_menu;
std::vector<std::string> nest_str;
for( auto &nested : nested_mapgen ) {
nest_menu.addentry( -1, true, -1, nested.first );
nest_str.push_back( nested.first );
}
nest_menu.query();
const int nest_choice = nest_menu.ret;
if( nest_choice >= 0 && nest_choice < static_cast<int>( nest_str.size() ) ) {
const std::optional<tripoint> where = g->look_around( true );
if( !where ) {
return;
}
map &here = get_map();
const tripoint_abs_ms abs_ms( here.getabs( *where ) );
const tripoint_abs_omt abs_omt = project_to<coords::omt>( abs_ms );
const tripoint_abs_sm abs_sub = project_to<coords::sm>( abs_ms );
map target_map;
target_map.load( abs_sub, true );
// TODO: fix point types
const tripoint local_ms = target_map.getlocal( abs_ms.raw() );
mapgendata md( abs_omt, target_map, 0.0f, calendar::turn, nullptr );
const auto &ptr = nested_mapgen[nest_str[nest_choice]].pick();
if( ptr == nullptr ) {
return;
}
( *ptr )->nest( md, local_ms.xy() );
target_map.save();
g->load_npcs();
here.invalidate_map_cache( g->get_levz() );
}
}
static Character &pick_character( Character &preselected )
{
std::vector< tripoint > locations;
uilist charmenu;
int charnum = 0;
charmenu.addentry( charnum++, true, MENU_AUTOASSIGN, "%s", _( "You" ) );
locations.emplace_back( g->u.pos() );
for( const npc &guy : g->all_npcs() ) {
charmenu.addentry( charnum++, true, MENU_AUTOASSIGN, guy.name );
locations.emplace_back( guy.pos() );
}
avatar &u = get_avatar();
u.view_offset = u.pos() - preselected.pos();
auto iter = std::find_if( locations.begin(), locations.end(), [&preselected]( const tripoint & p ) {
return p == preselected.pos();
} );
size_t preselect_index = iter != locations.end() ? std::distance( locations.begin(), iter ) : 0;
pointmenu_cb callback( locations );
charmenu.callback = &callback;
charmenu.w_y_setup = 0;
charmenu.set_selected( preselect_index );
charmenu.query();
if( charmenu.ret < 0 || static_cast<size_t>( charmenu.ret ) >= locations.size() ) {
return preselected;
}
const size_t index = charmenu.ret;
Character *c = g->critter_at<Character>( locations[index] );
return c != nullptr ? *c : preselected;
}
void character_edit_menu( Character &c )
{
npc *np = c.is_npc() ? static_cast<npc *>( &c ) : nullptr;
player &p = static_cast<player &>( c );
const tripoint start_view_offset = get_avatar().view_offset;
std::string nmenu_label;
if( np != nullptr ) {
std::stringstream data;
data << np->name << " " << ( np->male ? _( "Male" ) : _( "Female" ) ) << std::endl;
data << np->myclass.obj().get_name() << "; " <<
npc_attitude_name( np->get_attitude() ) << "; " <<
( np->get_faction() ? np->get_faction()->name : _( "no faction" ) ) << "; " <<
( np->get_faction() ? np->get_faction()->currency->nname( 1 ) : _( "no currency" ) )
<< "; " <<
"api: " << np->get_faction_ver() << std::endl;
if( np->has_destination() ) {
data << string_format(
_( "Destination: %s %s" ), np->goal.to_string(),
overmap_buffer.ter( np->goal )->get_name() ) << std::endl;
} else {
data << _( "No destination." ) << std::endl;
}
data << string_format( _( "Trust: %d" ), np->op_of_u.trust ) << " "
<< string_format( _( "Fear: %d" ), np->op_of_u.fear ) << " "
<< string_format( _( "Value: %d" ), np->op_of_u.value ) << " "
<< string_format( _( "Anger: %d" ), np->op_of_u.anger ) << " "
<< string_format( _( "Owed: %d" ), np->op_of_u.owed ) << std::endl;
data << string_format( _( "Aggression: %d" ),
static_cast<int>( np->personality.aggression ) ) << " "
<< string_format( _( "Bravery: %d" ), static_cast<int>( np->personality.bravery ) ) << " "
<< string_format( _( "Collector: %d" ), static_cast<int>( np->personality.collector ) ) << " "
<< string_format( _( "Altruism: %d" ), static_cast<int>( np->personality.altruism ) ) << std::endl;
data << _( "Needs:" ) << std::endl;
for( const auto &need : np->needs ) {
data << need << std::endl;
}
data << string_format( _( "Total morale: %d" ), np->get_morale_level() ) << std::endl;
nmenu_label = data.str();
} else {
nmenu_label = _( "Player" );
}
enum edit_character {
pick, desc, skills, stats, items, delete_items, item_worn,
hp, stamina, morale, pain, needs, healthy, status, mission_add, mission_edit,
tele, mutate, bionics, npc_class, attitude, opinion, effects,
learn_ma, unlock_recipes, learn_spells, level_spells
};
// Maybe TODO: this could actually be static if not for translations
const std::vector<uilist_entry> static_entries = {{
uilist_entry( edit_character::pick, true, 'p', _( "[p]ick different character" ) ),
uilist_entry( edit_character::desc, true, 'D', _( "Edit [D]escription - Name, Age, Height, Gender" ) ),
uilist_entry( edit_character::skills, true, 's', _( "Edit [s]kills" ) ),
uilist_entry( edit_character::stats, true, 't', _( "Edit s[t]ats" ) ),
uilist_entry( edit_character::items, true, 'i', _( "Grant [i]tems" ) ),
uilist_entry( edit_character::delete_items, true, 'd', _( "[d]elete (all) items" ) ),
uilist_entry( edit_character::item_worn, true, 'w', _( "[w]ear/[w]ield an item from player's inventory" ) ),
uilist_entry( edit_character::hp, true, 'h', _( "Set [h]it points" ) ),
uilist_entry( edit_character::stamina, true, 'S', _( "Set [S]tamina" ) ),
uilist_entry( edit_character::morale, true, 'o', _( "Set m[o]rale" ) ),
uilist_entry( edit_character::pain, true, 'P', _( "Cause [P]ain" ) ),
uilist_entry( edit_character::healthy, true, 'a', _( "Set he[a]lth" ) ),
uilist_entry( edit_character::needs, true, 'n', _( "Set [n]eeds" ) ),
uilist_entry( edit_character::mutate, true, 'u', _( "M[u]tate" ) ),
uilist_entry( edit_character::bionics, true, 'b', _( "Edit [b]ionics" ) ),
uilist_entry( edit_character::status, true, '@', _( "Status Window [@]" ) ),
uilist_entry( edit_character::tele, true, 'e', _( "t[e]leport" ) ),
uilist_entry( edit_character::mission_edit, true, 'M', _( "Edit [M]issions (WARNING: Unstable!)" ) ),
uilist_entry( edit_character::effects, true, 'E', _( "Edit [E]ffects" ) ),
uilist_entry( edit_character::learn_ma, true, 'l', _( "[l]earn all melee styles" ) ),
uilist_entry( edit_character::unlock_recipes, true, 'r', _( "Unlock all [r]ecipes" ) )
}
};
std::vector<uilist_entry> menu_entries = static_entries;
if( !spell_type::get_all().empty() ) {
menu_entries.emplace_back( edit_character::learn_spells, true, 'L', _( "[L]earn all Spells" ) );
menu_entries.emplace_back( edit_character::level_spells, true, 'v', _( "Le[v]el a spell" ) );
}
if( p.is_npc() ) {
menu_entries.emplace_back( edit_character::mission_add, true, 'm', _( "Add [m]ission" ) );
menu_entries.emplace_back( edit_character::npc_class, true, 'c',
_( "Randomize with [c]lass" ) );
menu_entries.emplace_back( edit_character::attitude, true, 'A', _( "Set [A]ttitude" ) );
menu_entries.emplace_back( edit_character::opinion, true, 'O', _( "Set [O]pinion" ) );
}
uilist nmenu( nmenu_label, menu_entries );
switch( nmenu.ret ) {
case edit_character::pick: {
Character &other = pick_character( c );
get_avatar().view_offset = other.pos() - get_avatar().pos();
// TODO: Make it not able to cause a stack overflow
character_edit_menu( other );
get_avatar().view_offset = start_view_offset;
}
return;
case edit_character::skills:
wishskill( &p );
break;
case edit_character::stats: {
uilist smenu;
smenu.addentry( 0, true, 'S', "%s: %d", _( "Maximum strength" ), p.str_max );
smenu.addentry( 1, true, 'D', "%s: %d", _( "Maximum dexterity" ), p.dex_max );
smenu.addentry( 2, true, 'I', "%s: %d", _( "Maximum intelligence" ), p.int_max );
smenu.addentry( 3, true, 'P', "%s: %d", _( "Maximum perception" ), p.per_max );
smenu.query();
int *bp_ptr = nullptr;
switch( smenu.ret ) {
case 0:
bp_ptr = &p.str_max;
break;
case 1:
bp_ptr = &p.dex_max;
break;
case 2:
bp_ptr = &p.int_max;
break;
case 3:
bp_ptr = &p.per_max;
break;
default:
break;
}
if( bp_ptr != nullptr ) {
int value;
if( query_int( value, _( "Set the stat to? Currently: %d" ), *bp_ptr ) && value >= 0 ) {
*bp_ptr = value;
p.reset_stats();
}
}
}
break;
case edit_character::items:
wishitem( &p );
break;
case edit_character::delete_items:
if( !query_yn( _( "Delete all items from the target?" ) ) ) {
break;
}
for( auto &it : p.worn ) {
it.on_takeoff( p );
}
p.worn.clear();
p.inv.clear();
p.primary_weapon() = item();
break;
case edit_character::item_worn: {
item_location loc = game_menus::inv::titled_menu( g->u, _( "Make target equip" ) );
if( !loc ) {
break;
}
item &to_wear = *loc;
if( to_wear.is_armor() ) {
p.on_item_wear( to_wear );
p.worn.push_back( to_wear );
} else if( !to_wear.is_null() ) {
p.primary_weapon() = to_wear;
}
}
break;
case edit_character::hp: {
const int torso_hp = p.get_part_hp_cur( bodypart_id( "torso" ) );
const int head_hp = p.get_part_hp_cur( bodypart_id( "head" ) );
const int arm_l_hp = p.get_part_hp_cur( bodypart_id( "arm_l" ) );
const int arm_r_hp = p.get_part_hp_cur( bodypart_id( "arm_r" ) );
const int leg_l_hp = p.get_part_hp_cur( bodypart_id( "leg_l" ) );
const int leg_r_hp = p.get_part_hp_cur( bodypart_id( "leg_r" ) );
uilist smenu;
smenu.addentry( 0, true, 'q', "%s: %d", _( "Torso" ), torso_hp );
smenu.addentry( 1, true, 'w', "%s: %d", _( "Head" ), head_hp );
smenu.addentry( 2, true, 'a', "%s: %d", _( "Left arm" ), arm_l_hp );
smenu.addentry( 3, true, 's', "%s: %d", _( "Right arm" ), arm_r_hp );
smenu.addentry( 4, true, 'z', "%s: %d", _( "Left leg" ), leg_l_hp );
smenu.addentry( 5, true, 'x', "%s: %d", _( "Right leg" ), leg_r_hp );
smenu.addentry( 6, true, 'e', "%s: %d", _( "All" ), p.get_lowest_hp() );
smenu.query();
bodypart_str_id bp = bodypart_str_id( "no_a_real_part" );
int bp_ptr = -1;
bool all_select = false;
switch( smenu.ret ) {
case 0:
bp = bodypart_str_id( "torso" );
bp_ptr = torso_hp;
break;
case 1:
bp = bodypart_str_id( "head" );
bp_ptr = head_hp;
break;
case 2:
bp = bodypart_str_id( "arm_l" );
bp_ptr = arm_l_hp;
break;
case 3:
bp = bodypart_str_id( "arm_r" );
bp_ptr = arm_r_hp;
break;
case 4:
bp = bodypart_str_id( "leg_l" );
bp_ptr = leg_l_hp;
break;
case 5:
bp = bodypart_str_id( "leg_r" );
bp_ptr = leg_r_hp;
break;
case 6:
all_select = true;
break;
default:
break;
}
if( bp.is_valid() ) {
int value;
if( query_int( value, _( "Set the hitpoints to? Currently: %d" ), bp_ptr ) && value >= 0 ) {
p.set_part_hp_cur( bp.id(), value );
p.reset_stats();
}
} else if( all_select ) {
int value;
if( query_int( value, _( "Set the hitpoints to? Currently: %d" ), p.get_lowest_hp() ) &&
value >= 0 ) {
p.set_all_parts_hp_cur( value );
p.reset_stats();
}
}
}
break;
case edit_character::stamina:
int value;
if( query_int( value, _( "Set stamina to? Current: %d. Max: %d." ), p.get_stamina(),
p.get_stamina_max() ) ) {
if( value >= 0 && value <= p.get_stamina_max() ) {
p.set_stamina( value );
} else {
add_msg( m_bad, _( "Target stamina value out of bounds!" ) );
}
}
break;
case edit_character::morale: {
int current_morale_level = p.get_morale_level();
int value;
if( query_int( value, _( "Set the morale to? Currently: %d" ), current_morale_level ) ) {
int morale_level_delta = value - current_morale_level;
p.add_morale( MORALE_PERM_DEBUG, morale_level_delta );
p.apply_persistent_morale();
}
}
break;
case edit_character::opinion: {
if( np == nullptr ) {
// HACK: For some reason, tidy is not satisfied with simple assert(np)
std::abort();
}
uilist smenu;
smenu.addentry( 0, true, 'h', "%s: %d", _( "trust" ), np->op_of_u.trust );
smenu.addentry( 1, true, 's', "%s: %d", _( "fear" ), np->op_of_u.fear );
smenu.addentry( 2, true, 't', "%s: %d", _( "value" ), np->op_of_u.value );
smenu.addentry( 3, true, 'f', "%s: %d", _( "anger" ), np->op_of_u.anger );
smenu.addentry( 4, true, 'd', "%s: %d", _( "owed" ), np->op_of_u.owed );
smenu.query();
int value;
switch( smenu.ret ) {
case 0:
if( query_int( value, _( "Set trust to? Currently: %d" ),
np->op_of_u.trust ) ) {
np->op_of_u.trust = value;
}
break;
case 1:
if( query_int( value, _( "Set fear to? Currently: %d" ), np->op_of_u.fear ) ) {
np->op_of_u.fear = value;
}
break;
case 2:
if( query_int( value, _( "Set value to? Currently: %d" ),
np->op_of_u.value ) ) {
np->op_of_u.value = value;
}
break;
case 3:
if( query_int( value, _( "Set anger to? Currently: %d" ),
np->op_of_u.anger ) ) {
np->op_of_u.anger = value;
}
break;
case 4:
if( query_int( value, _( "Set owed to? Currently: %d" ), np->op_of_u.owed ) ) {
np->op_of_u.owed = value;
}
break;
}
}
break;
case edit_character::desc: {
uilist smenu;
smenu.text = _( "Select a value and press enter to change it." );
if( p.is_avatar() ) {
smenu.addentry( 0, true, 's', "%s: %s", _( "Current save file name" ), get_avatar().get_save_id() );
}
smenu.addentry( 1, true, 'n', "%s: %s", _( "Current pre-Cataclysm name" ), p.name );
smenu.addentry( 2, true, 'a', "%s: %d", _( "Current age" ), p.base_age() );
smenu.addentry( 3, true, 'h', "%s: %d", _( "Current height in cm" ), p.base_height() );
smenu.addentry( 4, true, 'h', "%s: %s", _( "Current gender" ),
p.male ? _( "Male" ) : _( "Female" ) );
smenu.query();
switch( smenu.ret ) {
case 0: {
std::string buf = get_avatar().get_save_id();
string_input_popup popup;
popup
.title( _( "Rename save file (WARNING: this will duplicate the save):" ) )
.width( 85 )
.edit( buf );
if( popup.confirmed() ) {
get_avatar().set_save_id( buf );
}
}
break;
case 1: {
std::string buf = p.name;
string_input_popup popup;
popup
.title( _( "Rename character:" ) )
.width( 85 )
.edit( buf );
if( popup.confirmed() ) {
p.name = buf;
}
}
break;
case 2: {
string_input_popup popup;
popup
.title( _( "Enter age in years. Minimum 16, maximum 55" ) )
.text( string_format( "%d", p.base_age() ) )
.only_digits( true );
const int result = popup.query_int();
if( result != 0 ) {
p.set_base_age( clamp( result, 16, 55 ) );
}
}
break;
case 3: {
string_input_popup popup;
popup
.title( _( "Enter height in centimeters. Minimum 145, maximum 200" ) )
.text( string_format( "%d", p.base_height() ) )
.only_digits( true );
const int result = popup.query_int();
if( result != 0 ) {
p.set_base_height( clamp( result, 145, 200 ) );
}
}
break;
case 4: {
p.male = !p.male;
}
break;
}
}
break;
case edit_character::pain: {
int value;
if( query_int( value, _( "Cause how much pain? pain: %d" ), p.get_pain() ) ) {
p.mod_pain( value );
}
}
break;
case edit_character::needs: {
uilist smenu;
smenu.addentry( 0, true, 's', "%s: %d", _( "Stored kCal" ), p.get_stored_kcal() );
smenu.addentry( 1, true, 't', "%s: %d", _( "Thirst" ), p.get_thirst() );
smenu.addentry( 2, true, 'f', "%s: %d", _( "Fatigue" ), p.get_fatigue() );
smenu.addentry( 3, true, 'd', "%s: %d", _( "Sleep Deprivation" ), p.get_sleep_deprivation() );
smenu.addentry( 4, true, 'a', _( "Reset all basic needs" ) );
const auto &vits = vitamin::all();
for( const auto &v : vits ) {
smenu.addentry( -1, true, 0, "%s: %d", v.second.name(), p.vitamin_get( v.first ) );
}
smenu.query();
int value;
switch( smenu.ret ) {
case 0:
if( query_int( value, _( "Set stored kCal to? Currently: %d" ), p.get_stored_kcal() ) ) {
p.set_stored_kcal( value );
}
break;
case 1:
if( query_int( value, _( "Set thirst to? Currently: %d" ), p.get_thirst() ) ) {
p.set_thirst( value );
}
break;
case 2:
if( query_int( value, _( "Set fatigue to? Currently: %d" ), p.get_fatigue() ) ) {
p.set_fatigue( value );
}
break;
case 3:
if( query_int( value, _( "Set sleep deprivation to? Currently: %d" ),
p.get_sleep_deprivation() ) ) {
p.set_sleep_deprivation( value );
}
break;
case 4:
p.set_thirst( 0 );
p.set_fatigue( 0 );
p.set_sleep_deprivation( 0 );
p.set_stored_kcal( p.max_stored_kcal() );
break;
default:
const int non_vitamin_entries = smenu.entries.size() - vits.size();
if( smenu.ret >= non_vitamin_entries &&
smenu.ret < static_cast<int>( vits.size() + non_vitamin_entries ) ) {
auto iter = std::next( vits.begin(), smenu.ret - non_vitamin_entries );
if( query_int( value, _( "Set %s to? Currently: %d" ),
iter->second.name(), p.vitamin_get( iter->first ) ) ) {
p.vitamin_set( iter->first, value );
}
}
}
}
break;
case edit_character::mutate:
wishmutate( &p );
break;
case edit_character::bionics:
wishbionics( *p.as_character() );
break;
case edit_character::healthy: {
uilist smenu;
smenu.addentry( 0, true, 'h', "%s: %d", _( "Health" ), p.get_healthy() );
smenu.addentry( 1, true, 'm', "%s: %d", _( "Health modifier" ), p.get_healthy_mod() );
smenu.addentry( 2, true, 'r', "%s: %d", _( "Radiation" ), p.get_rad() );
smenu.query();
int value;
switch( smenu.ret ) {
case 0:
if( query_int( value, _( "Set the value to? Currently: %d" ), p.get_healthy() ) ) {
p.set_healthy( value );
}
break;
case 1:
if( query_int( value, _( "Set the value to? Currently: %d" ), p.get_healthy_mod() ) ) {
p.set_healthy_mod( value );
}
break;
case 2:
if( query_int( value, _( "Set the value to? Currently: %d" ), p.get_rad() ) ) {
p.set_rad( value );
}
break;
default:
break;
}
}
break;
case edit_character::status:
character_display::disp_info( p );
break;
case edit_character::mission_add: {
uilist types;
types.text = _( "Choose mission type" );
const auto all_missions = mission_type::get_all();
std::vector<const mission_type *> mts;
for( size_t i = 0; i < all_missions.size(); i++ ) {
types.addentry( i, true, -1, all_missions[i].tname() );
mts.push_back( &all_missions[i] );
}
types.query();
if( types.ret >= 0 && types.ret < static_cast<int>( mts.size() ) ) {
np->add_new_mission( mission::reserve_new( mts[types.ret]->id, np->getID() ) );
}
}
break;
case edit_character::mission_edit:
mission_debug::edit( p );
break;
case edit_character::tele: {
if( const std::optional<tripoint> newpos = g->look_around( true ) ) {
p.setpos( *newpos );
if( p.is_player() ) {
if( p.is_mounted() ) {
p.mounted_creature->setpos( *newpos );
}