Debian Codegraph @

engine/game/loadgame.cpp

raw
1 // ____ _ __
2 // / __ )____ _____ | | / /___ ___________
3 // / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
4 // / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
5 // /_____/\____/____/ |__/|__/\__,_/_/ /____/
6 //
7 // A futuristic real-time strategy game.
8 // This file is part of Bos Wars.
9 //
10 /**@name loadgame.cpp - Load game. */
11 //
12 // (c) Copyright 2001-2008 by Lutz Sammer, Andreas Arens
13 //
14 // This program is free software; you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation; only version 2 of the License.
17 //
18 // This program is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU General Public License for more details.
22 //
23 // You should have received a copy of the GNU General Public License
24 // along with this program; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 // 02111-1307, USA.
27 //
28
29 //@{
30
31 /*----------------------------------------------------------------------------
32 -- Includes
33 ----------------------------------------------------------------------------*/
34
35 #include <stdio.h>
36 #include <stdlib.h>
37
38 #include "stratagus.h"
39 #include "icons.h"
40 #include "cursor.h"
41 #include "construct.h"
42 #include "unittype.h"
43 #include "upgrade.h"
44 #include "interface.h"
45 #include "missile.h"
46 #include "map.h"
47 #include "script.h"
48 #include "ui.h"
49 #include "ai.h"
50 #include "results.h"
51 #include "trigger.h"
52 #include "actions.h"
53 #include "minimap.h"
54 #include "replay.h"
55 #include "sound.h"
56 #include "sound_server.h"
57 #include "font.h"
58 #include "pathfinder.h"
59 #include "spells.h"
60 #include "particle.h"
61
62 /*----------------------------------------------------------------------------
63 -- Variables
64 ----------------------------------------------------------------------------*/
65
66 /*----------------------------------------------------------------------------
67 -- Functions
68 ----------------------------------------------------------------------------*/
69
70 void InitDefinedVariables();
71
72 /**
73 ** Cleanup modules.
74 **
75 ** Call each module to clean up.
76 */
77 void CleanModules(void)
78 {
79 EndReplayLog();
80 CleanMessages();
81
82 CleanIcons();
83 CleanCursors();
84 CleanUserInterface();
85 CleanFonts();
86 CleanTriggers();
87 FreeAi();
88 CleanPlayers();
89 CleanConstructions();
90 CleanDecorations();
91 CleanUnitTypes();
92 CleanUnits();
93 CleanSelections();
94 CleanGroups();
95 CleanButtons();
96 CleanMissileTypes();
97 CleanMissiles();
98 Map.Clean();
99 Map.CleanFogOfWar();
100 CParticleManager::exit();
101 CleanReplayLog();
102 CleanSpells();
103 FreeVisionTable();
104 FreePathfinder();
105 }
106
107 /**
108 ** Initialize all modules.
109 **
110 ** Call each module to initialize.
111 */
112 void InitModules(void)
113 {
114 GameCycle = 0;
115 FastForwardCycle = 0;
116 SyncHash = 0;
117
118 CallbackMusicOn();
119 InitSyncRand();
120 InitIcons();
121 InitVideoCursors();
122 InitUserInterface();
123 InitPlayers();
124 InitMissileTypes();
125 InitMissiles();
126 InitConstructions();
127
128 // LUDO : 0 = don't reset player stats ( units level , upgrades, ... ) !
129 InitUnitTypes(0);
130
131 InitUnits();
132 InitSelections();
133 InitGroups();
134 InitSpells();
135
136 InitButtons();
137 InitTriggers();
138
139 InitAiModule();
140
141 Map.Init();
142 }
143
144 /**
145 ** Load all.
146 **
147 ** Call each module to load additional files (graphics,sounds).
148 */
149 void LoadModules(void)
150 {
151 LoadFonts();
152 LoadIcons();
153 LoadCursors();
154 UI.Load();
155 LoadMissileSprites();
156 LoadConstructions();
157 LoadDecorations();
158 LoadUnitTypes();
159
160 InitPathfinder();
161
162 LoadUnitSounds();
163 MapUnitSounds();
164 if (SoundEnabled()) {
165 InitSoundClient();
166 }
167
168 SetPlayersPalette();
169 UI.Minimap.Create();
170
171 SetDefaultTextColors(UI.NormalFontColor, UI.ReverseFontColor);
172 }
173
174 /**
175 ** Load a game to file.
176 **
177 ** @param filename File name to be loaded.
178 */
179 void LoadGame(const std::string &filename)
180 {
181 unsigned long game_cycle;
182 unsigned syncrand;
183 unsigned synchash;
184 int i;
185
186 SaveGameLoading = true;
187
188 SetDefaultTextColors(FontYellow, FontWhite);
189 LoadFonts();
190
191 CclGarbageCollect(0);
192 InitVisionTable();
193 InitUnitTypes(1);
194 LuaLoadFile(filename);
195 CclGarbageCollect(0);
196
197 for (i = 0; i < NumPlayers; ++i) {
198 Players[i].RebuildUnitsConsumingResourcesList();
199 }
200
201 // Place units
202 for (i = 0; i < NumUnits; ++i) {
203 CUnit *unit = Units[i];
204 if (!unit->Removed) {
205 unit->Removed = 1;
206 unit->Place(unit->X, unit->Y);
207 }
208 }
209
210 game_cycle = GameCycle;
211 syncrand = SyncRandSeed;
212 synchash = SyncHash;
213
214 InitModules();
215 LoadModules();
216
217 GameCycle = game_cycle;
218 SyncRandSeed = syncrand;
219 SyncHash = synchash;
220 SelectionChanged();
221 }
222
223 //@}