1 #include "Loading_Screen.h"
2 
3 #include "Campaign_Types.h"
4 #include "ContentManager.h"
5 #include "Debug.h"
6 #include "Directories.h"
7 #include "Font.h"
8 #include "Font_Control.h"
9 #include "Game_Clock.h"
10 #include "GameInstance.h"
11 #include "LoadingScreenModel.h"
12 #include "Local.h"
13 #include "Random.h"
14 #include "Render_Dirty.h"
15 #include "StrategicMap.h"
16 #include "Strategic_Movement.h"
17 #include "VSurface.h"
18 #include "Video.h"
19 #include "UILayout.h"
20 
21 #include <string_theory/format>
22 
23 
24 UINT8 gubLastLoadingScreenID = LOADINGSCREEN_NOTHING;
25 
26 
GetLoadScreenID(INT16 const x,INT16 const y,INT8 const z)27 UINT8 GetLoadScreenID(INT16 const x, INT16 const y, INT8 const z)
28 {
29 	bool  const night     = NightTime();
30 	UINT8 const sector_id = SECTOR(x, y);
31 
32 	if (DidGameJustStart()) return LOADINGSCREEN_HELI;
33 
34 	const LoadingScreen* screen = GCM->getLoadingScreenForSector(sector_id, z, night);
35 	if (screen != NULL)
36 	{
37 		return screen->index;
38 	}
39 
40 	switch (z)
41 	{
42 		case 0:
43 			if (IsThisSectorASAMSector(x, y, z))
44 			{
45 				return night ? LOADINGSCREEN_NIGHTSAM : LOADINGSCREEN_DAYSAM;
46 			}
47 
48 			switch (SectorInfo[sector_id].ubTraversability[THROUGH_STRATEGIC_MOVE])
49 			{
50 				case TOWN:
51 					return Random(2) == 0 ?
52 						(night ? LOADINGSCREEN_NIGHTTOWN1 : LOADINGSCREEN_DAYTOWN1) :
53 						(night ? LOADINGSCREEN_NIGHTTOWN2 : LOADINGSCREEN_DAYTOWN2);
54 				case SAND:
55 				case SAND_ROAD:
56 					return night ? LOADINGSCREEN_NIGHTDESERT : LOADINGSCREEN_DAYDESERT;
57 				case FARMLAND:
58 				case FARMLAND_ROAD:
59 				case ROAD:
60 					return night ? LOADINGSCREEN_NIGHTGENERIC : LOADINGSCREEN_DAYGENERIC;
61 				case PLAINS:
62 				case SPARSE:
63 				case HILLS:
64 				case PLAINS_ROAD:
65 				case SPARSE_ROAD:
66 				case HILLS_ROAD:
67 					return night ? LOADINGSCREEN_NIGHTWILD : LOADINGSCREEN_DAYWILD;
68 				case DENSE:
69 				case SWAMP:
70 				case SWAMP_ROAD:
71 				case DENSE_ROAD:
72 					return night ? LOADINGSCREEN_NIGHTFOREST : LOADINGSCREEN_DAYFOREST;
73 				case TROPICS:
74 				case TROPICS_ROAD:
75 				case WATER:
76 				case NS_RIVER:
77 				case EW_RIVER:
78 				case COASTAL:
79 				case COASTAL_ROAD:
80 					return night ? LOADINGSCREEN_NIGHTTROPICAL : LOADINGSCREEN_DAYTROPICAL;
81 				default:
82 					Assert(false);
83 					return night ? LOADINGSCREEN_NIGHTGENERIC : LOADINGSCREEN_DAYGENERIC;
84 			}
85 
86 		case 1:
87 			// All sectors at this level, except mine sectors, are mapped to specific loading screens
88 			return LOADINGSCREEN_MINE;
89 
90 		case 2:
91 		case 3:
92 			// All level 2 and 3 maps are caves.
93 			return LOADINGSCREEN_CAVE;
94 
95 		default:
96 			Assert(false); // Shouldn't ever happen
97 			return night ? LOADINGSCREEN_NIGHTGENERIC : LOADINGSCREEN_DAYGENERIC;
98 	}
99 }
100 
101 
DisplayLoadScreenWithID(UINT8 const id)102 void DisplayLoadScreenWithID(UINT8 const id)
103 {
104 	const LoadingScreen* screen = GCM->getLoadingScreen(id);
105 	ST::string filename = LOADSCREENSDIR + screen->filename;
106 
107 	try
108 	{ // Blit the background image.
109 		BltVideoSurfaceOnce(FRAME_BUFFER, filename.c_str(), STD_SCREEN_X, STD_SCREEN_Y);
110 	}
111 	catch (...)
112 	{ // Failed to load the file, so use a black screen and print out message.
113 		SetFontAttributes(FONT10ARIAL, FONT_YELLOW);
114 		FRAME_BUFFER->Fill(0);
115 		MPrint(5, 5, ST::format("{} loadscreen data file not found", filename));
116 	}
117 
118 	gubLastLoadingScreenID = id;
119 	InvalidateScreen();
120 	ExecuteBaseDirtyRectQueue();
121 	RefreshScreen();
122 }
123