1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "common/config-manager.h"
24 #include "common/translation.h"
25 
26 #include "ultima/ultima8/misc/pent_include.h"
27 #include "ultima/ultima8/games/cru_game.h"
28 #include "ultima/ultima8/games/start_crusader_process.h"
29 #include "ultima/ultima8/filesys/file_system.h"
30 #include "ultima/ultima8/graphics/palette_manager.h"
31 #include "ultima/ultima8/gumps/movie_gump.h"
32 #include "ultima/ultima8/gumps/gump_notify_process.h"
33 #include "ultima/ultima8/gumps/main_menu_process.h"
34 #include "ultima/ultima8/gumps/cru_credits_gump.h"
35 #include "ultima/ultima8/gumps/cru_demo_gump.h"
36 #include "ultima/ultima8/kernel/object_manager.h"
37 #include "ultima/ultima8/kernel/kernel.h"
38 #include "ultima/ultima8/world/world.h"
39 #include "ultima/ultima8/graphics/xform_blend.h"
40 #include "ultima/ultima8/games/game_data.h"
41 #include "ultima/ultima8/ultima8.h"
42 #include "ultima/ultima8/world/item_factory.h"
43 #include "ultima/ultima8/world/actors/main_actor.h"
44 #include "ultima/ultima8/world/actors/npc_dat.h"
45 #include "common/memstream.h"
46 
47 #include "gui/message.h"
48 
49 namespace Ultima {
50 namespace Ultima8 {
51 
CruGame()52 CruGame::CruGame() : Game(), _skipIntroMovie(false) {
53 }
54 
~CruGame()55 CruGame::~CruGame() {
56 
57 }
58 
loadPalette(const char * path,PaletteManager::PalIndex index)59 static bool loadPalette(const char *path, PaletteManager::PalIndex index) {
60 	Common::SeekableReadStream *pf = FileSystem::get_instance()->ReadFile(path);
61 	if (!pf) {
62 		perr << "Unable to load " << path << Std::endl;
63 		return false;
64 	}
65 
66 	Common::MemoryReadStream xfds(CruXFormPal, 1024);
67 	PaletteManager::get_instance()->load(index, *pf, xfds);
68 	delete pf;
69 
70 	return true;
71 }
72 
loadFiles()73 bool CruGame::loadFiles() {
74 	// Load palette
75 	pout << "Load Palettes" << Std::endl;
76 
77 	if (!loadPalette("static/gamepal.pal", PaletteManager::Pal_Game))
78 		return false;
79 	// This one is not always present and only needed for the credits,
80 	// let it fail if needed.
81 	loadPalette("static/cred.pal", PaletteManager::Pal_Cred);
82 	if (!loadPalette("static/diff.pal", PaletteManager::Pal_Diff))
83 		return false;
84 	if (!loadPalette("static/misc.pal", PaletteManager::Pal_Misc))
85 		return false;
86 	if (!loadPalette("static/misc2.pal", PaletteManager::Pal_Misc2))
87 		return false;
88 	// We don't use his one at the moment, ok to fail.
89 	loadPalette("static/star.pal", PaletteManager::Pal_Star);
90 
91 	pout << "Load GameData" << Std::endl;
92 	GameData::get_instance()->loadRemorseData();
93 
94 	return true;
95 }
96 
startGame()97 bool CruGame::startGame() {
98 	// NOTE: assumes the entire engine has been reset!
99 
100 	pout << "Starting new Crusader: No Remorse game." << Std::endl;
101 
102 	ObjectManager *objman = ObjectManager::get_instance();
103 
104 	// reserve a number of objids just in case we'll need them sometime
105 	for (uint16 i = 384; i < 512; ++i)
106 		objman->reserveObjId(i);
107 
108 	Actor *actor = ItemFactory::createActor(1, 0, 0, Item::FLG_IN_NPC_LIST,
109 	                                        1, 1, Item::EXT_PERMANENT_NPC, false);
110 	if (!actor)
111 		error("Couldn't create MainActor");
112 
113 	const NPCDat *npcData = GameData::get_instance()->getNPCDataForShape(1);
114 
115 	actor->setStr(75);
116 	actor->setHP(npcData->getMaxHp());
117 	actor->setInt(5000); // max mana (energy) is 2x intelligence, or 10000.
118 	actor->setMana(2500);
119 
120 	ObjectManager::get_instance()->assignActorObjId(actor, 1);
121 
122 	actor->setLocation(0, 0, 0); // Map 1 (mission 1)
123 
124 	// Some useful points to warp into for testing No Remorse
125 	//actor->setLocation(60716, 59400, 16); // Map 1 (mission 1)
126 	//actor->setLocation(42493, 26621, 16); // Map 2 (mission 1 / level 4)
127 	//actor->setLocation(34302, 32254, 16); // Map 3 (mission 2)
128 	//actor->setLocation(34813, 33789, 16); // Map 4
129 	//actor->setLocation(37373, 30205, 16); // Map 5
130 	//actor->setLocation(37373, 30205, 16); // Map 6
131 	//actor->setLocation(35070, 26142, 96); // Map 7
132 	//actor->setLocation(29693, 32253, 0); // Map 8 - unfinished area?
133 	//actor->setLocation(2046, 2046, 0); // Map 9
134 	//actor->setLocation(14845, 6141, 0); // Map 22 - debugging map
135 	//actor->setLocation(34302, 32254, 16); // Map 40 (Rebel base)
136 
137 	World::get_instance()->switchMap(0);
138 
139 	return true;
140 }
141 
startInitialUsecode(int saveSlot)142 bool CruGame::startInitialUsecode(int saveSlot) {
143 	if (saveSlot >= 0 && ConfMan.getBool("skip_intro"))
144 		_skipIntroMovie = true;
145 	Process* proc = new StartCrusaderProcess(saveSlot);
146 	Kernel::get_instance()->addProcess(proc);
147 	return true;
148 }
149 
150 
playMovie(const char * movieID,bool fade,bool noScale)151 static ProcId playMovie(const char *movieID, bool fade, bool noScale) {
152 	MovieGump *gump = MovieGump::CruMovieViewer(movieID, 640, 480, nullptr, nullptr, 0);
153 	if (!gump) {
154 		pout << "RemorseGame::playIntro: movie " << movieID << " not found." << Std::endl;
155 		return 0;
156 	}
157 	gump->CreateNotifier();
158 	return gump->GetNotifyProcess()->getPid();
159 }
160 
playIntroMovie(bool fade)161 ProcId CruGame::playIntroMovie(bool fade) {
162 	if (_skipIntroMovie)
163 		return 0;
164 	const char *name = (GAME_IS_REMORSE ? "T01" : "origin");
165 	ProcId pid = playMovie(name, fade, true);
166 	if (!pid) {
167 		GUI::MessageDialogWithURL dialog(_("Crusader intro movie file missing - check that the FLICS and SOUND directories have been copied from the CD.  More instructions are on the wiki: https://wiki.scummvm.org/index.php?title=Crusader:_No_Remorse."), "https://wiki.scummvm.org/index.php?title=Crusader:_No_Remorse");
168 		dialog.runModal();
169 	}
170 	return pid;
171 }
172 
playIntroMovie2(bool fade)173 ProcId CruGame::playIntroMovie2(bool fade) {
174 	if (_skipIntroMovie)
175 		return 0;
176 	const char *name = (GAME_IS_REMORSE ? "T02" : "ANIM01");
177 	return playMovie(name, fade, false);
178 }
179 
playEndgameMovie(bool fade)180 ProcId CruGame::playEndgameMovie(bool fade) {
181 	return playMovie("O01", fade, false);
182 }
183 
playDemoScreen()184 void CruGame::playDemoScreen() {
185 	Process *menuproc = new MainMenuProcess();
186 	Kernel::get_instance()->addProcess(menuproc);
187 
188 	static const Std::string bmp_filename = "static/buyme.dat";
189 	Common::SeekableReadStream *bmprs = FileSystem::get_instance()->ReadFile(bmp_filename);
190 	if (!bmprs) {
191 		perr << "RemorseGame::playDemoScreen: error opening demo background: "
192 			 << bmp_filename << Std::endl;
193 		return;
194 	}
195 	Gump *gump = new CruDemoGump(bmprs);
196 	gump->InitGump(0);
197 	gump->CreateNotifier();
198 	Process *notifyproc = gump->GetNotifyProcess();
199 
200 	if (notifyproc) {
201 		menuproc->waitFor(notifyproc);
202 	}
203 }
204 
playCreditsNoMenu()205 ProcId CruGame::playCreditsNoMenu() {
206 	static const Std::string txt_filename = "static/credits.dat";
207 	static const Std::string bmp_filename = "static/cred.dat";
208 	Common::SeekableReadStream *txtrs = FileSystem::get_instance()->ReadFile(txt_filename);
209 	Common::SeekableReadStream *bmprs = FileSystem::get_instance()->ReadFile(bmp_filename);
210 
211 	if (!txtrs) {
212 		perr << "RemorseGame::playCredits: error opening credits text: "
213 			 << txt_filename << Std::endl;
214 		return 0;
215 	}
216 	if (!bmprs) {
217 		perr << "RemorseGame::playCredits: error opening credits background: "
218 			 << bmp_filename << Std::endl;
219 		return 0;
220 	}
221 	Gump *creditsgump = new CruCreditsGump(txtrs, bmprs);
222 	creditsgump->InitGump(nullptr);
223 	creditsgump->CreateNotifier();
224 	Process *notifyproc = creditsgump->GetNotifyProcess();
225 	return notifyproc->getPid();
226 }
227 
228 
playCredits()229 void CruGame::playCredits() {
230 	Process *menuproc = new MainMenuProcess();
231 	Kernel::get_instance()->addProcess(menuproc);
232 
233 	ProcId creditsnotify = playCreditsNoMenu();
234 
235 	if (creditsnotify) {
236 		menuproc->waitFor(creditsnotify);
237 	}
238 }
239 
writeSaveInfo(Common::WriteStream * ws)240 void CruGame::writeSaveInfo(Common::WriteStream *ws) {
241 }
242 
243 } // End of namespace Ultima8
244 } // End of namespace Ultima
245