-
Notifications
You must be signed in to change notification settings - Fork 4
/
CGame_Init.cpp
244 lines (223 loc) · 8.78 KB
/
CGame_Init.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
// Copyright (C) 2009 - 2021 Marc Vester (XaserLE)
// Copyright (C) 2009 - 2021 Settlers Freaks <sf-team at siedler25.org>
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include "CGame.h"
#include "CIO/CFile.h"
#include "CMap.h"
#include "CSurface.h"
#include "SGE/sge_blib.h"
#include "SGE/sge_surface.h"
#include "callbacks.h"
#include "globals.h"
#include "lua/GameDataLoader.h"
#include <iostream>
#include <vector>
bool CGame::ReCreateWindow()
{
displayTexture_.reset();
renderer_.reset();
window_.reset();
window_.reset(SDL_CreateWindow("Return to the Roots Map editor [BETA]", SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED, GameResolution.x, GameResolution.y,
fullscreen ? SDL_WINDOW_FULLSCREEN : 0));
if(!window_)
return false;
renderer_.reset(SDL_CreateRenderer(window_.get(), -1, 0));
if(!renderer_)
return false;
displayTexture_ = makeSdlTexture(renderer_, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, GameResolution.x,
GameResolution.y);
Surf_Display = makeRGBSurface(GameResolution.x, GameResolution.y, true);
if(!displayTexture_ || !Surf_Display)
return false;
SetAppIcon();
return true;
}
bool CGame::Init()
{
std::cout << "Return to the Roots Map editor\n";
SDL_ShowCursor(SDL_DISABLE);
std::cout << "Create Window...";
if(!ReCreateWindow())
{
std::cout << "failure";
return false;
}
sge_Lock_OFF();
CFile::init();
/*NOTE: its important to load a palette at first,
* otherwise all images will be black (in exception of the LBM-Files, they have their own palette).
* if its necessary to load pictures from a
* specified file with a special palette, so
* load this palette from a file and set
* CFile::palActual = CFile::palArray - 1 (--> last loaden palette)
* and after loading the images set
* CFile::palActual = CFile::palArray (--> first palette)
*/
// load some pictures (after all the splash-screens)
// at first GFX/PICS/SETUP997.LBM, cause this is the S2-loading picture
std::cout << "\nLoading file: GFX/PICS/SETUP997.LBM...";
if(!CFile::open_file(global::gameDataFilePath / "GFX/PICS/SETUP997.LBM", LBM))
{
std::cout << "failure";
// if SETUP997.LBM doesn't exist, it's probably settlers2+mission cd and there we have SETUP998.LBM instead
std::cout << "\nTry to load file: GFX/PICS/SETUP998.LBM instead...";
if(!CFile::open_file(global::gameDataFilePath / "GFX/PICS/SETUP998.LBM", LBM))
{
std::cout << "failure";
return false;
}
}
// std::cout << "\nShow loading screen...";
showLoadScreen = true;
// CSurface::Draw(Surf_Display, global::bmpArray[SPLASHSCREEN_LOADING_S2SCREEN].surface, 0, 0);
auto& surfSplash = global::bmpArray[SPLASHSCREEN_LOADING_S2SCREEN].surface;
sge_TexturedRect(Surf_Display.get(), 0, 0, Surf_Display->w - 1, 0, 0, Surf_Display->h - 1, Surf_Display->w - 1,
Surf_Display->h - 1, surfSplash.get(), 0, 0, surfSplash->w - 1, 0, 0, surfSplash->h - 1,
surfSplash->w - 1, surfSplash->h - 1);
RenderPresent();
GameDataLoader gdLoader(global::worldDesc);
if(!gdLoader.Load())
{
std::cerr << "Failed to load game data!" << std::endl;
return false;
}
// continue loading pictures
for(const std::string file :
{"GFX/PICS/SETUP000.LBM", "GFX/PICS/SETUP010.LBM", "GFX/PICS/SETUP011.LBM", "GFX/PICS/SETUP012.LBM",
"GFX/PICS/SETUP013.LBM", "GFX/PICS/SETUP014.LBM", "GFX/PICS/SETUP015.LBM"})
{
std::cout << "\nLoading file: " << file << "...";
if(!CFile::open_file(global::gameDataFilePath / file, LBM))
{
std::cout << "failure";
// if it doesn't exist, it's probably settlers2+missioncd and we simply load SETUP010.LBM instead
std::cout << "\nLoading file: GFX/PICS/SETUP010.LBM instead...";
if(!CFile::open_file(global::gameDataFilePath / "GFX/PICS/SETUP010.LBM", LBM))
{
std::cout << "failure";
return false;
}
}
}
for(const std::string file :
{"GFX/PICS/SETUP666.LBM", "GFX/PICS/SETUP667.LBM", "GFX/PICS/SETUP801.LBM", "GFX/PICS/SETUP802.LBM",
"GFX/PICS/SETUP803.LBM", "GFX/PICS/SETUP804.LBM", "GFX/PICS/SETUP805.LBM", "GFX/PICS/SETUP806.LBM",
"GFX/PICS/SETUP810.LBM", "GFX/PICS/SETUP811.LBM", "GFX/PICS/SETUP895.LBM", "GFX/PICS/SETUP896.LBM"})
{
std::cout << "\nLoading file: " << file << "...";
if(!CFile::open_file(global::gameDataFilePath / file, LBM))
{
std::cout << "failure";
return false;
}
}
for(const std::string file : {"GFX/PICS/SETUP897.LBM", "GFX/PICS/SETUP898.LBM"})
{
std::cout << "\nLoading file: " << file << "...";
if(!CFile::open_file(global::gameDataFilePath / file, LBM))
{
std::cout << "failure";
// if it doesn't exist, it's probably settlers2+missioncd and we simply load SETUP896.LBM instead
std::cout << "\nLoading file: GFX/PICS/SETUP896.LBM instead...";
if(!CFile::open_file(global::gameDataFilePath / "GFX/PICS/SETUP896.LBM", LBM))
{
std::cout << "failure";
return false;
}
}
}
for(const std::string file :
{"GFX/PICS/SETUP899.LBM", "GFX/PICS/SETUP990.LBM", "GFX/PICS/WORLD.LBM", "GFX/PICS/WORLDMSK.LBM"})
{
std::cout << "\nLoading file: " << file << "...";
if(!CFile::open_file(global::gameDataFilePath / file, LBM))
{
std::cout << "failure";
return false;
}
}
// load gouraud data
for(const std::string file : {"DATA/TEXTURES/GOU5.DAT", "DATA/TEXTURES/GOU6.DAT", "DATA/TEXTURES/GOU7.DAT"})
{
std::cout << "\nLoading file: " << file << "...";
if(!CFile::open_file(global::gameDataFilePath / file, GOU))
{
std::cout << "failure";
return false;
}
}
// load only the palette at this time from editres.idx
std::cout << "\nLoading palette from file: DATA/EDITRES.IDX...";
if(!CFile::open_file(global::gameDataFilePath / "DATA/EDITRES.IDX", IDX, true))
{
std::cout << "failure";
return false;
}
// set the right palette
CFile::set_palActual(CFile::get_palArray() - 1);
std::cout << "\nLoading file: DATA/EDITRES.IDX...";
if(!CFile::open_file(global::gameDataFilePath / "DATA/EDITRES.IDX", IDX))
{
std::cout << "failure";
return false;
}
// set back palette
CFile::set_palActual(CFile::get_palArray());
// load only the palette at this time from editio.idx
std::cout << "\nLoading palette from file: DATA/IO/EDITIO.IDX...";
if(!CFile::open_file(global::gameDataFilePath / "DATA/IO/EDITIO.IDX", IDX, true))
{
std::cout << "failure";
return false;
}
// set the right palette
CFile::set_palActual(CFile::get_palArray() - 1);
std::cout << "\nLoading file: DATA/IO/EDITIO.IDX...";
if(!CFile::open_file(global::gameDataFilePath / "DATA/IO/EDITIO.IDX", IDX))
{
std::cout << "failure";
return false;
}
// set back palette
CFile::set_palActual(CFile::get_palArray());
std::cout << "\nLoading file: DATA/EDITBOB.LST...";
if(!CFile::open_file(global::gameDataFilePath / "DATA/EDITBOB.LST", LST))
{
std::cout << "failure";
return false;
}
// texture tilesets
for(const std::string file : {"GFX/TEXTURES/TEX5.LBM", "GFX/TEXTURES/TEX6.LBM", "GFX/TEXTURES/TEX7.LBM"})
{
std::cout << "\nLoading file: " << file << "...";
if(!CFile::open_file(global::gameDataFilePath / file, LBM))
{
std::cout << "failure";
return false;
}
}
/*
std::cout << "\nLoading palette from file: GFX/PALETTE/PAL5.BBM...";
if ( !CFile::open_file(global::gameDataFilePath / "GFX/PALETTE/PAL5.BBM", BBM, true) )
{
std::cout << "failure";
return false;
}
*/
// EVERY MISSION-FILE SHOULD BE LOADED SEPARATLY IF THE SPECIFIED MISSION GOES ON -- SO THIS IS TEMPORARY
for(const std::string file : {"DATA/MIS0BOBS.LST", "DATA/MIS1BOBS.LST", "DATA/MIS2BOBS.LST", "DATA/MIS3BOBS.LST",
"DATA/MIS4BOBS.LST", "DATA/MIS5BOBS.LST"})
{
std::cout << "\nLoading file: " << file << "...";
if(!CFile::open_file(global::gameDataFilePath / file, LST))
{
std::cout << "failure";
return false;
}
}
// create the mainmenu
callback::mainmenu(INITIALIZING_CALL);
return true;
}