-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
game.cpp
15147 lines (13686 loc) · 538 KB
/
game.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 "game.h"
#include "rng.h"
#include "input.h"
#include "output.h"
#include "skill.h"
#include "line.h"
#include "computer.h"
#include "veh_interact.h"
#include "options.h"
#include "auto_pickup.h"
#include "gamemode.h"
#include "mapbuffer.h"
#include "debug.h"
#include "editmap.h"
#include "bodypart.h"
#include "map.h"
#include "uistate.h"
#include "item_factory.h"
#include "helper.h"
#include "json.h"
#include "artifact.h"
#include "overmapbuffer.h"
#include "trap.h"
#include "mapdata.h"
#include "catacharset.h"
#include "translations.h"
#include "init.h"
#include "help.h"
#include "action.h"
#include "monstergenerator.h"
#include "monattack.h"
#include "worldfactory.h"
#include "file_finder.h"
#include "file_wrapper.h"
#include "mod_manager.h"
#include "path_info.h"
#include "mapbuffer.h"
#include "mapsharing.h"
#include "messages.h"
#include "pickup.h"
#include "weather_gen.h"
#include "start_location.h"
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <fstream>
#include <sstream>
#include <cmath>
#include <vector>
#ifdef _MSC_VER
#include "wdirent.h"
#include <direct.h>
#else
#include <unistd.h>
#include <dirent.h>
#endif
#include <sys/stat.h>
#include "debug.h"
#include "catalua.h"
#include <cassert>
#if (defined _WIN32 || defined __WIN32__)
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <windows.h>
#include <tchar.h>
#endif
#define dbg(x) DebugLog((DebugLevel)(x),D_GAME) << __FILE__ << ":" << __LINE__ << ": "
void intro();
nc_color sev(int a); // Right now, ONLY used for scent debugging....
//The one and only game instance
game *g;
extern worldfactory *world_generator;
input_context get_default_mode_input_context();
uistatedata uistate;
bool is_valid_in_w_terrain(int x, int y)
{
return x >= 0 && x < TERRAIN_WINDOW_WIDTH && y >= 0 && y < TERRAIN_WINDOW_HEIGHT;
}
// This is the main game set-up process.
game::game() :
new_game(false),
uquit(QUIT_NO),
w_terrain(NULL),
w_overmap(NULL),
w_omlegend(NULL),
w_minimap(NULL),
w_HP(NULL),
w_messages(NULL),
w_location(NULL),
w_status(NULL),
w_status2(NULL),
w_blackspace(NULL),
dangerous_proximity(5),
safe_mode(SAFE_MODE_ON),
mostseen(0),
gamemode(NULL),
lookHeight(13),
tileset_zoom(16)
{
world_generator = new worldfactory();
// do nothing, everything that was in here is moved to init_data() which is called immediately after g = new game; in main.cpp
// The reason for this move is so that g is not uninitialized when it gets to installing the parts into vehicles.
}
// Load everything that will not depend on any mods
void game::load_static_data()
{
#ifdef LUA
init_lua(); // Set up lua (SEE catalua.cpp)
#endif
// UI stuff, not mod-specific per definition
inp_mngr.init(); // Load input config JSON
// Init mappings for loading the json stuff
DynamicDataLoader::get_instance();
// Only need to load names once, they do not depend on mods
init_names();
narrow_sidebar = OPTIONS["SIDEBAR_STYLE"] == "narrow";
fullscreen = false;
was_fullscreen = false;
// These functions do not load stuff from json.
// The content they load/initialize is hardcoded into the program.
// Therefore they can be loaded here.
// If this changes (if they load data from json), they have to
// be moved to game::load_mod or game::load_core_data
init_body_parts();
init_ter_bitflags_map();
init_vpart_bitflag_map();
init_colormap();
init_mapgen_builtin_functions();
init_fields();
init_morale();
init_diseases(); // Set up disease lookup table
init_savedata_translation_tables();
init_npctalk();
init_artifacts();
init_weather();
init_weather_anim();
init_faction_data();
// --- move/delete everything below
// TODO: move this to player class
moveCount = 0;
}
void game::check_all_mod_data()
{
mod_manager *mm = world_generator->get_mod_manager();
dependency_tree &dtree = mm->get_tree();
if (mm->mod_map.empty()) {
// If we don't have any mods, test core data only
load_core_data();
DynamicDataLoader::get_instance().finalize_loaded_data();
}
for (mod_manager::t_mod_map::iterator a = mm->mod_map.begin(); a != mm->mod_map.end(); ++a) {
MOD_INFORMATION *mod = a->second;
if (!dtree.is_available(mod->ident)) {
debugmsg("Skipping mod %s (%s)", mod->name.c_str(), dtree.get_node(mod->ident)->s_errors().c_str());
continue;
}
std::vector<std::string> deps = dtree.get_dependents_of_X_as_strings(mod->ident);
if (!deps.empty()) {
// mod is dependency of another mod(s)
// When those mods get checked, they will pull in
// this mod, so there is no need to check this mod now.
continue;
}
popup_nowait("checking mod %s", mod->name.c_str());
// Reset & load core data, than load dependencies
// and the actual mod and finally finalize all.
load_core_data();
deps = dtree.get_dependencies_of_X_as_strings(mod->ident);
for(std::vector<std::string>::iterator it = deps.begin(); it != deps.end(); ++it) {
// assert(mm->has_mod(deps[i]));
// ^^ dependency tree takes care of that case
MOD_INFORMATION *dmod = mm->mod_map[*it];
load_data_from_dir(dmod->path);
}
load_data_from_dir(mod->path);
DynamicDataLoader::get_instance().finalize_loaded_data();
}
}
void game::load_core_data()
{
// core data can be loaded only once and must be first
// anyway.
DynamicDataLoader::get_instance().unload_data();
load_data_from_dir(FILENAMES["jsondir"]);
}
void game::load_data_from_dir(const std::string &path)
{
#ifdef LUA
// Process a preload file before the .json files,
// so that custom IUSE's can be defined before
// the items that need them are parsed
lua_loadmod(lua_state, path, "preload.lua");
#endif
try {
DynamicDataLoader::get_instance().load_data_from_path(path);
} catch (std::string &err) {
debugmsg("Error loading data from json: %s", err.c_str());
}
#ifdef LUA
// main.lua will be executed after JSON, allowing to
// work with items defined by mod's JSON
lua_loadmod(lua_state, path, "main.lua");
#endif
}
game::~game()
{
DynamicDataLoader::get_instance().unload_data();
MAPBUFFER.reset();
delete gamemode;
delwin(w_terrain);
delwin(w_minimap);
delwin(w_HP);
delwin(w_messages);
delwin(w_location);
delwin(w_status);
delwin(w_status2);
delete world_generator;
}
// Fixed window sizes
#define MINIMAP_HEIGHT 7
#define MINIMAP_WIDTH 7
#if (defined TILES)
// defined in sdltiles.cpp
void to_map_font_dimension(int &w, int &h);
void from_map_font_dimension(int &w, int &h);
void to_overmap_font_dimension(int &w, int &h);
void reinitialize_framebuffer();
#else
// unchanged, nothing to be translated without tiles
void to_map_font_dimension(int &, int &) { }
void from_map_font_dimension(int &, int &) { }
void to_overmap_font_dimension(int &, int &) { }
//in pure curses, the framebuffer won't need reinitializing
void reinitialize_framebuffer() { }
#endif
void game::init_ui()
{
// clear the screen
static bool first_init = true;
if (first_init) {
clear();
// set minimum FULL_SCREEN sizes
FULL_SCREEN_WIDTH = 80;
FULL_SCREEN_HEIGHT = 24;
// print an intro screen, making sure the terminal is the correct size
intro();
first_init = false;
}
int sidebarWidth = narrow_sidebar ? 45 : 55;
// First get TERMX, TERMY
#if (defined TILES || defined _WIN32 || defined __WIN32__)
TERMX = get_terminal_width();
TERMY = get_terminal_height();
#else
getmaxyx(stdscr, TERMY, TERMX);
// try to make FULL_SCREEN_HEIGHT symmetric according to TERMY
if (TERMY % 2) {
FULL_SCREEN_HEIGHT = 25;
} else {
FULL_SCREEN_HEIGHT = 24;
}
// now that TERMX and TERMY are set,
// check if sidebar style needs to be overridden
sidebarWidth = use_narrow_sidebar() ? 45 : 55;
if(fullscreen) {
sidebarWidth = 0;
}
#endif
// remove some space for the sidebar, this is the maximal space
// (using standard font) that the terrain window can have
TERRAIN_WINDOW_HEIGHT = TERMY;
TERRAIN_WINDOW_WIDTH = TERMX - sidebarWidth;
TERRAIN_WINDOW_TERM_WIDTH = TERRAIN_WINDOW_WIDTH;
TERRAIN_WINDOW_TERM_HEIGHT = TERRAIN_WINDOW_HEIGHT;
/**
* In tiles mode w_terrain can have a different font (with a different
* tile dimension) or can be drawn by cata_tiles which uses tiles that again
* might have a different dimension then the normal font used everywhere else.
*
* TERRAIN_WINDOW_WIDTH/TERRAIN_WINDOW_HEIGHT defines how many squares can
* be displayed in w_terrain (using it's specific tile dimension), not
* including partially drawn squares at the right/bottom. You should
* use it whenever you want to draw specific squares in that window or to
* determine whether a specific square is draw on screen (or outside the screen
* and needs scrolling).
*
* TERRAIN_WINDOW_TERM_WIDTH/TERRAIN_WINDOW_TERM_HEIGHT defines the size of
* w_terrain in the standard font dimension (the font that everything else uses).
* You usually don't have to use it, expect for positioning of windows,
* because the window positions use the standard font dimension.
*
* VIEW_OFFSET_X/VIEW_OFFSET_Y is the position of w_terrain on screen,
* it is (as every window position) in standard font dimension.
* As the sidebar is located right of w_terrain it also controls its position.
* It is used to move everything into the center of the screen,
* when the screen is larger than what the game requires.
*
* The code here calculates size available for w_terrain, caps it at
* max_view_size (the maximal view range than any character can have at
* any time).
* It is stored in TERRAIN_WINDOW_*.
* If w_terrain does not occupy the whole available area, VIEW_OFFSET_*
* are set to move everything into the middle of the screen.
*/
to_map_font_dimension(TERRAIN_WINDOW_WIDTH, TERRAIN_WINDOW_HEIGHT);
static const int max_view_size = DAYLIGHT_LEVEL * 2 + 1;
if (TERRAIN_WINDOW_WIDTH > max_view_size) {
VIEW_OFFSET_X = (TERRAIN_WINDOW_WIDTH - max_view_size) / 2;
TERRAIN_WINDOW_TERM_WIDTH = max_view_size * TERRAIN_WINDOW_TERM_WIDTH / TERRAIN_WINDOW_WIDTH;
TERRAIN_WINDOW_WIDTH = max_view_size;
} else {
VIEW_OFFSET_X = 0;
}
if (TERRAIN_WINDOW_HEIGHT > max_view_size) {
VIEW_OFFSET_Y = (TERRAIN_WINDOW_HEIGHT - max_view_size) / 2;
TERRAIN_WINDOW_TERM_HEIGHT = max_view_size * TERRAIN_WINDOW_TERM_HEIGHT / TERRAIN_WINDOW_HEIGHT;
TERRAIN_WINDOW_HEIGHT = max_view_size;
} else {
VIEW_OFFSET_Y = 0;
}
// VIEW_OFFSET_* are in standard font dimension.
from_map_font_dimension(VIEW_OFFSET_X, VIEW_OFFSET_Y);
// Position of the player in the terrain window, it is always in the center
POSX = TERRAIN_WINDOW_WIDTH / 2;
POSY = TERRAIN_WINDOW_HEIGHT / 2;
// Set up the main UI windows.
w_terrain = newwin(TERRAIN_WINDOW_HEIGHT, TERRAIN_WINDOW_WIDTH, VIEW_OFFSET_Y, VIEW_OFFSET_X);
werase(w_terrain);
/**
* Doing the same thing as above for the overmap
*/
static const int OVERMAP_LEGEND_WIDTH = 28;
OVERMAP_WINDOW_HEIGHT = TERMY;
OVERMAP_WINDOW_WIDTH = TERMX - OVERMAP_LEGEND_WIDTH;
to_overmap_font_dimension(OVERMAP_WINDOW_WIDTH, OVERMAP_WINDOW_HEIGHT);
//Bring the framebuffer to the maximum required dimensions
//Otherwise it segfaults when the overmap needs a bigger buffer size than it provides
reinitialize_framebuffer();
int minimapX, minimapY; // always MINIMAP_WIDTH x MINIMAP_HEIGHT in size
int hpX, hpY, hpW, hpH;
int messX, messY, messW, messH;
int locX, locY, locW, locH;
int statX, statY, statW, statH;
int stat2X, stat2Y, stat2W, stat2H;
int mouseview_y, mouseview_h;
if (use_narrow_sidebar()) {
// First, figure out how large each element will be.
hpH = 7;
hpW = 14;
statH = 7;
statW = sidebarWidth - MINIMAP_WIDTH - hpW;
locH = 1;
locW = sidebarWidth;
stat2H = 2;
stat2W = sidebarWidth;
messH = TERMY - (statH + locH + stat2H);
messW = sidebarWidth;
// Now position the elements relative to each other.
minimapX = 0;
minimapY = 0;
hpX = minimapX + MINIMAP_WIDTH;
hpY = 0;
locX = 0;
locY = minimapY + MINIMAP_HEIGHT;
statX = hpX + hpW;
statY = 0;
stat2X = 0;
stat2Y = locY + locH;
messX = 0;
messY = stat2Y + stat2H;
mouseview_y = messY + 7;
mouseview_h = TERMY - mouseview_y - 5;
} else {
// standard sidebar style
minimapX = 0;
minimapY = 0;
messX = MINIMAP_WIDTH;
messY = 0;
messW = sidebarWidth - messX;
messH = TERMY - 5; // 1 for w_location + 4 for w_stat, w_messages starts at 0
hpX = 0;
hpY = MINIMAP_HEIGHT;
// under the minimap, but down to the same line as w_messages (even when that is to much),
// so it erases the space between w_terrain and w_messages
hpH = messH - MINIMAP_HEIGHT;
hpW = 7;
locX = MINIMAP_WIDTH;
locY = messY + messH;
locH = 1;
locW = sidebarWidth - locX;
statX = 0;
statY = locY + locH;
statH = 4;
statW = sidebarWidth;
// The default style only uses one status window.
stat2X = 0;
stat2Y = statY + statH;
stat2H = 1;
stat2W = sidebarWidth;
mouseview_y = stat2Y + stat2H;
mouseview_h = TERMY - mouseview_y;
}
int _y = VIEW_OFFSET_Y;
int _x = TERMX - VIEW_OFFSET_X - sidebarWidth;
w_minimap = newwin(MINIMAP_HEIGHT, MINIMAP_WIDTH, _y + minimapY, _x + minimapX);
werase(w_minimap);
w_HP = newwin(hpH, hpW, _y + hpY, _x + hpX);
werase(w_HP);
w_messages = newwin(messH, messW, _y + messY, _x + messX);
werase(w_messages);
w_location = newwin(locH, locW, _y + locY, _x + locX);
werase(w_location);
w_status = newwin(statH, statW, _y + statY, _x + statX);
werase(w_status);
int mouse_view_x = _x + minimapX;
int mouse_view_width = sidebarWidth;
if (mouseview_h < lookHeight) {
// Not enough room below the status bar, just use the regular lookaround area
get_lookaround_dimensions(mouse_view_width, mouseview_y, mouse_view_x);
mouseview_h = lookHeight;
liveview.compact_view = true;
if (!use_narrow_sidebar()) {
// Second status window must now take care of clearing the area to the
// bottom of the screen.
stat2H = TERMY - stat2Y;
}
}
liveview.init(mouse_view_x, mouseview_y, sidebarWidth, mouseview_h);
w_status2 = newwin(stat2H, stat2W, _y + stat2Y, _x + stat2X);
werase(w_status2);
}
void game::toggle_sidebar_style(void)
{
narrow_sidebar = !narrow_sidebar;
init_ui();
refresh_all();
}
void game::toggle_fullscreen(void)
{
#ifndef TILES
if (TERMX > 121 || TERMY > 121) {
return;
}
fullscreen = !fullscreen;
init_ui();
refresh_all();
#endif
}
// temporarily switch out of fullscreen for functions that rely
// on displaying some part of the sidebar
void game::temp_exit_fullscreen(void)
{
if (fullscreen) {
was_fullscreen = true;
toggle_fullscreen();
} else {
was_fullscreen = false;
}
}
void game::reenter_fullscreen(void)
{
if (was_fullscreen) {
if (!fullscreen) {
toggle_fullscreen();
}
}
}
/*
* Initialize more stuff after mapbuffer is loaded.
*/
void game::setup()
{
m = map(); // reset the main map
load_world_modfiles(world_generator->active_world);
next_npc_id = 1;
next_faction_id = 1;
next_mission_id = 1;
// Clear monstair values
monstairx = -1;
monstairy = -1;
monstairz = -1;
last_target = -1; // We haven't targeted any monsters yet
last_target_was_npc = false;
new_game = true;
uquit = QUIT_NO; // We haven't quit the game
weather = WEATHER_CLEAR; // Start with some nice weather...
// Weather shift in 30
nextweather = HOURS((int)OPTIONS["INITIAL_TIME"]) + MINUTES(30);
turnssincelastmon = 0; //Auto safe mode init
autosafemode = OPTIONS["AUTOSAFEMODE"];
safemodeveh =
OPTIONS["SAFEMODEVEH"]; //Vehicle safemode check, in practice didn't trigger when needed
footsteps.clear();
footsteps_source.clear();
clear_zombies();
coming_to_stairs.clear();
active_npc.clear();
factions.clear();
active_missions.clear();
items_dragged.clear();
Messages::clear_messages();
events.clear();
SCT.vSCT.clear(); //Delete pending messages
// reset kill counts
kills.clear();
// Set the scent map to 0
for (int i = 0; i < SEEX * MAPSIZE; i++) {
for (int j = 0; j < SEEX * MAPSIZE; j++) {
grscent[i][j] = 0;
}
}
load_auto_pickup(false); // Load global auto pickup rules
// back to menu for save loading, new game etc
}
bool game::has_gametype() const
{
return gamemode && gamemode->id() != SGAME_NULL;
}
special_game_id game::gametype() const
{
return gamemode != nullptr ? gamemode->id() : SGAME_NULL;
}
// Set up all default values for a new game
void game::start_game(std::string worldname)
{
if (gamemode == NULL) {
gamemode = new special_game();
}
new_game = true;
start_calendar();
nextweather = calendar::turn;
weatherSeed = rand();
safe_mode = (OPTIONS["SAFEMODE"] ? SAFE_MODE_ON : SAFE_MODE_OFF);
mostseen = 0; // ...and mostseen is 0, we haven't seen any monsters yet.
init_autosave();
clear();
refresh();
popup_nowait(_("Please wait as we build your world"));
// Init some factions.
if (!load_master(worldname)) { // Master data record contains factions.
create_factions();
}
u.setID( assign_npc_id() ); // should be as soon as possible, but *after* load_master
const start_location &start_loc = *start_location::find( u.start_location );
start_loc.setup( cur_om, levx, levy, levz );
// Start the overmap with out immediate neighborhood visible
overmap_buffer.reveal(point(om_global_location().x, om_global_location().y), OPTIONS["DISTANCE_INITIAL_VISIBILITY"], 0);
// Init the starting map at this location.
m.load( levx, levy, levz, true, cur_om );
m.build_map_cache();
// Do this after the map cache has been build!
start_loc.place_player( u );
u.moves = 0;
u.reset_bonuses();
u.process_turn(); // process_turn adds the initial move points
nextspawn = int(calendar::turn);
temperature = 65; // Springtime-appropriate?
update_weather(); // Springtime-appropriate, definitely.
u.next_climate_control_check = 0; // Force recheck at startup
u.last_climate_control_ret = false;
//Reset character pickup rules
vAutoPickupRules[2].clear();
//Put some NPCs in there!
create_starting_npcs();
//Load NPCs. Set nearby npcs to active.
load_npcs();
//spawn the monsters
m.spawn_monsters( true ); // Static monsters
//Create mutation_category_level
u.set_highest_cat_level();
//Calc mutation drench protection stats
u.drench_mut_calc();
if (scen->has_flag("FIRE_START")){
m.add_field(u.pos().x + 5, u.pos().y + 3, field_from_ident("fd_fire"), 3 );
m.add_field(u.pos().x + 7, u.pos().y + 6, field_from_ident("fd_fire"), 3 );
m.add_field(u.pos().x + 3, u.pos().y + 4, field_from_ident("fd_fire"), 3 );
}
if (scen->has_flag("INFECTED")){u.add_disease("infected", 14401, false, 1, 1, 0, 0, random_body_part(), true);}
if (scen->has_flag("BAD_DAY")){
u.add_disease("flu", 10000);
u.add_disease("drunk", 2700 - (12 * u.str_max));
u.add_morale(MORALE_FEELING_BAD,-100,50,50,50);
}
//~ %s is player name
u.add_memorial_log(pgettext("memorial_male", "%s began their journey into the Cataclysm."),
pgettext("memorial_female", "%s began their journey into the Cataclysm."),
u.name.c_str());
}
void game::create_factions()
{
faction tmp;
std::vector<std::string> faction_vector = tmp.all_json_factions();
for(std::vector<std::string>::reverse_iterator it = faction_vector.rbegin(); it != faction_vector.rend(); ++it) {
tmp = faction(it[0].c_str());
tmp.randomize();
tmp.load_faction_template(it[0].c_str());
factions.push_back(tmp);
}
}
//Make any nearby overmap npcs active, and put them in the right location.
void game::load_npcs()
{
const int radius = int(MAPSIZE / 2) - 1;
// uses submap coordinates
std::vector<npc *> npcs = overmap_buffer.get_npcs_near_player(radius);
for (std::vector<npc *>::iterator it = npcs.begin();
it != npcs.end(); ++it) {
npc *temp = *it;
if (temp->is_active()) {
continue;
}
const tripoint p = temp->global_sm_location();
add_msg( m_debug, "game::load_npcs: Spawning static NPC, %d:%d (%d:%d)",
levx, levy, p.x, p.y);
temp->place_on_map();
// In the rare case the npc was marked for death while
// it was on the overmap. Kill it.
if (temp->marked_for_death) {
temp->die( nullptr );
} else {
active_npc.push_back(temp);
}
}
}
void game::create_starting_npcs()
{
if (!ACTIVE_WORLD_OPTIONS["STATIC_NPC"]) {
return; //Do not generate a starting npc.
}
//We don't want more than one starting npc per shelter
const int radius = 1;
std::vector<npc *> npcs = overmap_buffer.get_npcs_near_player(radius);
if (npcs.size() >= 1) {
return; //There is already an NPC in this shelter
}
npc *tmp = new npc();
tmp->normalize();
tmp->randomize((one_in(2) ? NC_DOCTOR : NC_NONE));
// spawn the npc in the overmap, sets its overmap and submap coordinates
tmp->spawn_at( get_abs_levx(), get_abs_levy(), levz );
tmp->posx = SEEX * int(MAPSIZE / 2) + SEEX;
tmp->posy = SEEY * int(MAPSIZE / 2) + 6;
tmp->form_opinion(&u);
tmp->attitude = NPCATT_NULL;
//This sets the npc mission. This NPC remains in the shelter.
tmp->mission = NPC_MISSION_SHELTER;
tmp->chatbin.first_topic = TALK_SHELTER;
//one random shelter mission.
tmp->chatbin.missions.push_back(
reserve_random_mission(ORIGIN_OPENER_NPC, om_location(), tmp->getID()));
}
void game::cleanup_at_end()
{
draw_sidebar();
if (uquit == QUIT_DIED || uquit == QUIT_SUICIDE) {
// Save the factions', missions and set the NPC's overmap coords
// Npcs are saved in the overmap.
save_factions_missions_npcs(); //missions need to be saved as they are global for all saves.
// save artifacts.
save_artifacts();
// and the overmap, and the local map.
save_maps(); //Omap also contains the npcs who need to be saved.
}
// Clear the future weather for future projects
weather_log.clear();
if (uquit == QUIT_DIED || uquit == QUIT_SUICIDE) {
std::vector<std::string> vRip;
int iMaxWidth = 0;
int iNameLine = 0;
int iInfoLine = 0;
if (u.has_amount("holybook_bible1", 1) || u.has_amount("holybook_bible2", 1) ||
u.has_amount("holybook_bible3", 1)) {
if (!(u.has_trait("CANNIBAL") || u.has_trait("PSYCHOPATH"))) {
vRip.push_back(" _______ ___");
vRip.push_back(" < `/ |");
vRip.push_back(" > _ _ (");
vRip.push_back(" | |_) | |_) |");
vRip.push_back(" | | \\ | | |");
vRip.push_back(" ______.__%_| |_________ __");
vRip.push_back(" _/ \\| |");
iNameLine = vRip.size();
vRip.push_back("| <");
vRip.push_back("| |");
iMaxWidth = vRip[vRip.size() - 1].length();
vRip.push_back("| |");
vRip.push_back("|_____.-._____ __/|_________|");
vRip.push_back(" | |");
iInfoLine = vRip.size();
vRip.push_back(" | |");
vRip.push_back(" | <");
vRip.push_back(" | |");
vRip.push_back(" | _ |");
vRip.push_back(" |__/ |");
vRip.push_back(" % / `--. |%");
vRip.push_back(" * .%%| -< @%%%");
vRip.push_back(" `\\%`@| |@@%@%%");
vRip.push_back(" .%%%@@@|% ` % @@@%%@%%%%");
vRip.push_back(" _.%%%%%%@@@@@@%%%__/\\%@@%%@@@@@@@%%%%%%");
} else {
vRip.push_back(" _______ ___");
vRip.push_back(" | \\/ |");
vRip.push_back(" | |");
vRip.push_back(" | |");
iInfoLine = vRip.size();
vRip.push_back(" | |");
vRip.push_back(" | |");
vRip.push_back(" | |");
vRip.push_back(" | |");
vRip.push_back(" | <");
vRip.push_back(" | _ |");
vRip.push_back(" |__/ |");
vRip.push_back(" ______.__%_| |__________ _");
vRip.push_back(" _/ \\| \\");
iNameLine = vRip.size();
vRip.push_back("| <");
vRip.push_back("| |");
iMaxWidth = vRip[vRip.size() - 1].length();
vRip.push_back("| |");
vRip.push_back("|_____.-._______ __/|__________|");
vRip.push_back(" % / `_-. _ |%");
vRip.push_back(" * .%%| |_) | |_)< @%%%");
vRip.push_back(" `\\%`@| | \\ | | |@@%@%%");
vRip.push_back(" .%%%@@@|% ` % @@@%%@%%%%");
vRip.push_back(" _.%%%%%%@@@@@@%%%__/\\%@@%%@@@@@@@%%%%%%");
}
} else {
vRip.push_back(" _________ ____ ");
vRip.push_back(" _/ `/ \\_ ");
vRip.push_back(" _/ _ _ \\_. ");
vRip.push_back(" _%\\ |_) | |_) \\_ ");
vRip.push_back(" _/ \\/ | \\ | | \\_ ");
vRip.push_back(" _/ \\_ ");
vRip.push_back("| |");
iNameLine = vRip.size();
vRip.push_back(" ) < ");
vRip.push_back("| |");
vRip.push_back("| |");
vRip.push_back("| _ |");
vRip.push_back("|__/ |");
iMaxWidth = vRip[vRip.size() - 1].length();
vRip.push_back(" / `--. |");
vRip.push_back("| ( ");
iInfoLine = vRip.size();
vRip.push_back("| |");
vRip.push_back(" \\_ _/");
vRip.push_back(" \\_% ._/ ");
vRip.push_back(" @`\\_ _/%% ");
vRip.push_back(" %@%@%\\_ * _/%`%@% ");
vRip.push_back(" %@@@.%@%\\%% `\\ %%.%%@@%@");
vRip.push_back("@%@@%%%%%@@@@@@%%%%%%%%@@%%@@@%%%@%%@");
}
const int iOffsetX = (TERMX > FULL_SCREEN_WIDTH) ? (TERMX - FULL_SCREEN_WIDTH) / 2 : 0;
const int iOffsetY = (TERMY > FULL_SCREEN_HEIGHT) ? (TERMY - FULL_SCREEN_HEIGHT) / 2 : 0;
WINDOW *w_rip = newwin(FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, iOffsetY, iOffsetX);
draw_border(w_rip);
for (unsigned int iY = 0; iY < vRip.size(); ++iY) {
for (unsigned int iX = 0; iX < vRip[iY].length(); ++iX) {
char cTemp = vRip[iY][iX];
if (cTemp != ' ') {
nc_color ncColor = c_ltgray;
if (cTemp == '%') {
ncColor = c_green;
} else if (cTemp == '_' || cTemp == '|') {
ncColor = c_white;
} else if (cTemp == '@') {
ncColor = c_brown;
} else if (cTemp == '*') {
ncColor = c_red;
}
mvwputch(w_rip, iY + 1, iX + (FULL_SCREEN_WIDTH / 2) - (iMaxWidth / 2), ncColor, vRip[iY][iX]);
}
}
}
std::string sTemp;
std::stringstream ssTemp;
int days_survived = int(calendar::turn.get_turn() / DAYS(1));
int days_adventured = int((calendar::turn.get_turn() - calendar::start.get_turn()) / DAYS(1));
for (int lifespan = 0; lifespan < 2; ++lifespan) {
// Show the second, "Adventured", lifespan
// only if it's different from the first.
if (lifespan && days_adventured == days_survived) {
continue;
}
sTemp = lifespan ? _("Adventured:") : _("Survived:");
mvwprintz(w_rip, iInfoLine++, (FULL_SCREEN_WIDTH / 2) - 5, c_ltgray, (sTemp + " ").c_str());
int iDays = lifespan ? days_adventured : days_survived;
ssTemp << iDays;
wprintz(w_rip, c_magenta, ssTemp.str().c_str());
ssTemp.str("");
sTemp = (iDays == 1) ? _("day") : _("days");
wprintz(w_rip, c_white, (" " + sTemp).c_str());
}
int iTotalKills = 0;
const std::map<std::string, mtype *> monids = MonsterGenerator::generator().get_all_mtypes();
for (std::map<std::string, mtype *>::const_iterator mon = monids.begin(); mon != monids.end();
++mon) {
if (kill_count(mon->first) > 0) {
iTotalKills += kill_count(mon->first);
}
}
ssTemp << iTotalKills;
sTemp = _("Kills:");
mvwprintz(w_rip, 1 + iInfoLine++, (FULL_SCREEN_WIDTH / 2) - 5, c_ltgray, (sTemp + " ").c_str());
wprintz(w_rip, c_magenta, ssTemp.str().c_str());
sTemp = _("In memory of:");
mvwprintz(w_rip, iNameLine++, (FULL_SCREEN_WIDTH / 2) - (sTemp.length() / 2), c_ltgray,
sTemp.c_str());
sTemp = u.name;
mvwprintz(w_rip, iNameLine++, (FULL_SCREEN_WIDTH / 2) - (sTemp.length() / 2), c_white,
sTemp.c_str());
sTemp = _("Last Words:");
mvwprintz(w_rip, iNameLine++, (FULL_SCREEN_WIDTH / 2) - (sTemp.length() / 2), c_ltgray,
sTemp.c_str());
long cInput = '\n';
int iPos = -1;
int iStartX = (FULL_SCREEN_WIDTH / 2) - ((iMaxWidth - 4) / 2);
std::string sLastWords = string_input_win(w_rip, "", iMaxWidth - 4 - 1,
iStartX, iNameLine, iStartX + iMaxWidth - 4 - 1,
true, cInput, iPos);
death_screen();
if (uquit == QUIT_SUICIDE) {
u.add_memorial_log(pgettext("memorial_male", "%s committed suicide."),
pgettext("memorial_female", "%s committed suicide."),
u.name.c_str());
} else {
u.add_memorial_log(pgettext("memorial_male", "%s was killed."),
pgettext("memorial_female", "%s was killed."),
u.name.c_str());
}
if (!sLastWords.empty()) {
u.add_memorial_log( _("Last words: %s"), sLastWords.c_str(), _("Last words: %s"), sLastWords.c_str() );
}
// Struck the save_player_data here to forestall Weirdness
move_save_to_graveyard();
write_memorial_file(sLastWords);
u.memorial_log.clear();
std::vector<std::string> characters = list_active_characters();
// remove current player from the active characters list, as they are dead
std::vector<std::string>::iterator curchar = std::find(characters.begin(),
characters.end(), u.name);
if (curchar != characters.end()) {
characters.erase(curchar);
}
if (characters.empty()) {
if (ACTIVE_WORLD_OPTIONS["DELETE_WORLD"] == "yes" ||
(ACTIVE_WORLD_OPTIONS["DELETE_WORLD"] == "query" &&
query_yn(_("Delete saved world?")))) {
delete_world(world_generator->active_world->world_name, true);
}
} else if (ACTIVE_WORLD_OPTIONS["DELETE_WORLD"] != "no") {
std::stringstream message;
std::string tmpmessage;
for (std::vector<std::string>::iterator it = characters.begin();
it != characters.end(); ++it) {
tmpmessage += "\n ";
tmpmessage += *it;
}
message << string_format(_("World retained. Characters remaining:%s"),tmpmessage.c_str());
popup(message.str(), PF_NONE);
}
if (gamemode) {
delete gamemode;
gamemode = new special_game; // null gamemode or something..
}
}
MAPBUFFER.reset();
overmap_buffer.clear();
}
static int veh_lumi(vehicle *veh)
{
float veh_luminance = 0.0;
float iteration = 1.0;
std::vector<int> light_indices = veh->all_parts_with_feature(VPFLAG_CONE_LIGHT);
for (std::vector<int>::iterator part = light_indices.begin();
part != light_indices.end(); ++part) {
veh_luminance += (veh->part_info(*part).bonus / iteration);
iteration = iteration * 1.1;
}
// Calculation: see lightmap.cpp
return LIGHT_RANGE((veh_luminance * 3));
}
void game::calc_driving_offset(vehicle *veh)
{
if (veh == NULL || !(OPTIONS["DRIVING_VIEW_OFFSET"] == true)) {
set_driving_view_offset(point(0, 0));