2 #include "app/Application.h"
3 #include "app/Arguments.h"
5 #include "battle/BattleState.h"
6 #include "battle/Capsule.h"
7 #include "battle/Hero.h"
8 #include "battle/Monster.h"
9 #include "battle/PartyLayout.h"
10 #include "battle/Resources.h"
11 #include "common/Capsule.h"
12 #include "common/GameConfig.h"
13 #include "common/GameState.h"
14 #include "common/Hero.h"
15 #include "common/Ikari.h"
16 #include "common/Inventory.h"
17 #include "common/Item.h"
18 #include "common/LevelUp.h"
19 #include "common/Script.h"
20 #include "common/Spell.h"
21 #include "common/Stats.h"
22 #include "graphics/CharSelect.h"
23 #include "graphics/ComplexAnimation.h"
24 #include "graphics/Font.h"
25 #include "graphics/Frame.h"
26 #include "graphics/Gauge.h"
27 #include "graphics/Menu.h"
28 #include "graphics/SimpleAnimation.h"
29 #include "graphics/Sprite.h"
30 #include "graphics/Texture.h"
31 #include "loader/Caster.h"
32 #include "loader/Compiler.h"
33 #include "loader/Interpreter.h"
34 #include "loader/Loader.h"
35 #include "loader/ParsedSource.h"
36 #include "loader/Parser.h"
37 #include "loader/TypeDescription.h"
39 #include "map/Entity.h"
41 #include "map/MapState.h"
43 #include "map/Trigger.h"
44 #include "math/Fixed.h"
45 #include "math/Vector.h"
46 #include "menu/Resources.h"
47 #include "sdl/InitImage.h"
48 #include "sdl/InitScreen.h"
49 #include "sdl/InitSDL.h"
58 #include <SDL_image.h>
60 using app::Application;
63 using battle::BattleState;
64 using battle::Monster;
65 using battle::PartyLayout;
66 using common::Capsule;
67 using common::GameConfig;
68 using common::GameState;
71 using graphics::Texture;
73 using loader::Compiler;
74 using loader::Interpreter;
76 using loader::ParsedSource;
78 using loader::TypeDescription;
84 using sdl::InitScreen;
94 int main(int argc, char **argv) {
95 const int width = 512;
96 const int height = 448;
98 const Fixed<8> walkSpeed = Fixed<8>(1, 8);
102 // std::srand(std::time(0));
106 InitImage image(IMG_INIT_PNG);
108 Interpreter::CreateTypeDescriptions();
110 battle::Resources::CreateTypeDescription();
111 battle::Monster::CreateTypeDescription();
112 battle::PartyLayout::CreateTypeDescription();
114 common::Capsule::CreateTypeDescription();
115 common::Hero::CreateTypeDescription();
116 common::Ikari::CreateTypeDescription();
117 common::Item::CreateTypeDescription();
118 common::LevelUp::CreateTypeDescription();
119 common::Stats::CreateTypeDescription();
120 common::Spell::CreateTypeDescription();
121 common::TargetingMode::CreateTypeDescription();
123 graphics::Animation::CreateTypeDescription();
124 graphics::CharSelect::CreateTypeDescription();
125 graphics::ComplexAnimation::CreateTypeDescription();
126 graphics::Font::CreateTypeDescription();
127 graphics::Frame::CreateTypeDescription();
128 graphics::Gauge::CreateTypeDescription();
129 graphics::MenuProperties::CreateTypeDescription();
130 graphics::SimpleAnimation::CreateTypeDescription();
131 graphics::Sprite::CreateTypeDescription();
132 graphics::Texture::CreateTypeDescription();
134 map::Area::CreateTypeDescription();
135 map::Entity::CreateTypeDescription();
136 map::Map::CreateTypeDescription();
137 map::Tile::CreateTypeDescription();
138 map::Trigger::CreateTypeDescription();
140 menu::Resources::CreateTypeDescription();
143 args.Read(argc, argv);
149 for (vector<char *>::const_iterator i(args.Infiles().begin()), end(args.Infiles().end()); i != end; ++i) {
151 switch (filePath[filePath.size() - 1]) {
156 Parser(filePath, source).Parse();
159 throw std::runtime_error("don't know what to do with " + filePath);
163 Interpreter intp(source);
166 switch (args.GetRunLevel()) {
167 case Arguments::WRITE:
169 int length(std::strlen(args.OutfilePath()));
170 switch (args.OutfilePath()[length - 1]) {
172 std::ofstream outstream(args.OutfilePath());
173 source.WriteHeader(outstream);
177 std::fstream outstream(args.OutfilePath(), std::ios_base::out|std::ios_base::trunc);
180 outstream.open(args.OutfilePath());
181 outstream.exceptions(std::ios_base::badbit|std::ios_base::failbit);
182 Compiler(intp).Write(outstream);
186 throw std::runtime_error(string("don't know how to write file ") + args.OutfilePath());
191 case Arguments::DUMP: {
192 std::cout << source << std::endl;
195 case Arguments::SOURCE_WIKI: {
196 TypeDescription::WriteSourceWiki(std::cout);
199 case Arguments::BATTLE:
202 case Arguments::PLAY:
207 if (intp.PostponedDefinitions().size() > 0) {
208 for (vector<Interpreter::PostponedDefinition>::const_iterator i(intp.PostponedDefinitions().begin()), end(intp.PostponedDefinitions().end()); i != end; ++i) {
209 std::cerr << "missing definition of " << TypeDescription::Get(i->type).TypeName() << " " << i->identifier << std::endl;
214 Caster caster(ld, intp);
218 gameState.heroes[0] = *caster.GetHero("maxim");
219 gameState.heroes[1] = *caster.GetHero("selan");
220 gameState.heroes[2] = *caster.GetHero("guy");
221 gameState.heroes[3] = *caster.GetHero("dekar");
223 gameState.party[0] = &gameState.heroes[0];
224 gameState.party[1] = &gameState.heroes[1];
225 gameState.party[2] = &gameState.heroes[2];
226 gameState.party[3] = &gameState.heroes[3];
227 gameState.partySize = 4;
229 gameState.capsules[1] = *caster.GetCapsule("flash");
230 gameState.capsules[1].UpgradeClass();
231 gameState.capsules[1].UpgradeClass();
232 gameState.capsules[1].UpgradeClass();
233 gameState.capsules[1].UpgradeClass();
234 gameState.capsule = 1;
236 GameConfig gameConfig;
237 gameConfig.state = &gameState;
238 gameConfig.heroesLayout = caster.GetPartyLayout("heroesLayout");
239 gameConfig.battleResources = caster.GetBattleResources("battleResources");
240 gameConfig.menuResources = caster.GetMenuResources("menuResources");
242 // temporary test data
243 SDL_Surface *bg(IMG_Load("test-data/battle-bg.png"));
244 PartyLayout monstersLayout(*caster.GetPartyLayout("monstersLayout"));
246 Monster monster(*caster.GetMonster("lizard"));
248 gameState.heroes[0].AddSpell(caster.GetSpell("resetSpell"));
249 Spell *strongSpell(caster.GetSpell("strongSpell"));
250 gameState.heroes[0].AddSpell(strongSpell);
251 gameState.heroes[1].AddSpell(strongSpell);
252 Spell *strongerSpell(caster.GetSpell("strongerSpell"));
253 gameState.heroes[0].AddSpell(strongerSpell);
254 gameState.heroes[1].AddSpell(strongerSpell);
255 Spell *championSpell(caster.GetSpell("championSpell"));
256 gameState.heroes[0].AddSpell(championSpell);
257 gameState.heroes[1].AddSpell(championSpell);
258 Spell *rallySpell(caster.GetSpell("rallySpell"));
259 gameState.heroes[0].AddSpell(rallySpell);
260 gameState.heroes[1].AddSpell(rallySpell);
261 gameState.heroes[1].AddSpell(caster.GetSpell("escapeSpell"));
262 Spell *valorSpell(caster.GetSpell("valorSpell"));
263 gameState.heroes[0].AddSpell(valorSpell);
264 gameState.heroes[1].AddSpell(valorSpell);
266 gameState.inventory.Add(caster.GetItem("zirconPlateItem"), 32);
267 gameState.inventory.Add(caster.GetItem("holyFruitItem"));
268 gameState.inventory.Add(caster.GetItem("darkFruitItem"));
269 gameState.inventory.Add(caster.GetItem("antidoteItem"), 9);
270 gameState.inventory.Add(caster.GetItem("powerRingItem"));
271 gameState.inventory.Add(caster.GetItem("magicJarItem"), 4);
272 gameState.inventory.Add(caster.GetItem("sProRingItem"));
273 gameState.inventory.Add(caster.GetItem("hiPotionItem"), 4);
274 gameState.inventory.Add(caster.GetItem("powerRingItem"));
275 gameState.inventory.Add(caster.GetItem("powerPotionItem"), 4);
276 gameState.inventory.Add(caster.GetItem("zircoSwordItem"));
277 gameState.inventory.Add(caster.GetItem("escapeItem"), 2);
278 gameState.inventory.Add(caster.GetItem("zircoHelmetItem"));
279 gameState.inventory.Add(caster.GetItem("sleepBallItem"), 1);
280 gameState.inventory.Add(caster.GetItem("zirconPlateItem"));
282 gameState.heroes[0].SetEquipment(Hero::EQUIP_WEAPON, caster.GetItem("zircoSwordItem"));
283 gameState.heroes[0].SetEquipment(Hero::EQUIP_ARMOR, caster.GetItem("zirconArmorItem"));
284 gameState.heroes[0].SetEquipment(Hero::EQUIP_SHIELD, caster.GetItem("holyShieldItem"));
285 gameState.heroes[0].SetEquipment(Hero::EQUIP_HELMET, caster.GetItem("legendHelmItem"));
286 gameState.heroes[0].SetEquipment(Hero::EQUIP_RING, caster.GetItem("sProRingItem"));
287 gameState.heroes[0].SetEquipment(Hero::EQUIP_JEWEL, caster.GetItem("evilJewelItem"));
289 // gameState.heroes[1].SetEquipment(Hero::EQUIP_WEAPON, caster.GetItem("zircoWhipItem"));
290 gameState.heroes[1].SetEquipment(Hero::EQUIP_ARMOR, caster.GetItem("zirconPlateItem"));
291 gameState.heroes[1].SetEquipment(Hero::EQUIP_SHIELD, caster.GetItem("zircoGlovesItem"));
292 gameState.heroes[1].SetEquipment(Hero::EQUIP_HELMET, caster.GetItem("holyCapItem"));
293 gameState.heroes[1].SetEquipment(Hero::EQUIP_RING, caster.GetItem("ghostRingItem"));
294 gameState.heroes[1].SetEquipment(Hero::EQUIP_JEWEL, caster.GetItem("eagleRockItem"));
296 // gameState.heroes[2].SetEquipment(Hero::EQUIP_WEAPON, caster.GetItem("zircoAxItem"));
297 gameState.heroes[2].SetEquipment(Hero::EQUIP_ARMOR, caster.GetItem("zirconArmorItem"));
298 gameState.heroes[2].SetEquipment(Hero::EQUIP_SHIELD, caster.GetItem("megaShieldItem"));
299 gameState.heroes[2].SetEquipment(Hero::EQUIP_HELMET, caster.GetItem("zircoHelmetItem"));
300 gameState.heroes[2].SetEquipment(Hero::EQUIP_RING, caster.GetItem("powerRingItem"));
301 gameState.heroes[2].SetEquipment(Hero::EQUIP_JEWEL, caster.GetItem("evilJewelItem"));
303 // NOTE: this is actually Artea equipment
304 // gameState.heroes[3].SetEquipment(Hero::EQUIP_WEAPON, caster.GetItem("lizardBlowItem"));
305 gameState.heroes[3].SetEquipment(Hero::EQUIP_ARMOR, caster.GetItem("holyRobeItem"));
306 gameState.heroes[3].SetEquipment(Hero::EQUIP_SHIELD, caster.GetItem("zircoGlovesItem"));
307 gameState.heroes[3].SetEquipment(Hero::EQUIP_HELMET, caster.GetItem("holyCapItem"));
308 gameState.heroes[3].SetEquipment(Hero::EQUIP_RING, caster.GetItem("rocketRingItem"));
309 gameState.heroes[3].SetEquipment(Hero::EQUIP_JEWEL, caster.GetItem("krakenRockItem"));
311 gameState.heroes[0].MapEntity().Position() = Vector<Fixed<8> >(64, 128);
313 gameState.heroes[1].MapEntity().Position() = Vector<Fixed<8> >(64, 128);
314 gameState.heroes[1].MapEntity().SetFlags(Entity::FLAG_NONBLOCKING);
315 gameState.heroes[0].MapEntity().AddFollower(&gameState.heroes[1].MapEntity());
317 gameState.heroes[2].MapEntity().Position() = Vector<Fixed<8> >(64, 128);
318 gameState.heroes[2].MapEntity().SetFlags(Entity::FLAG_NONBLOCKING);
319 gameState.heroes[1].MapEntity().AddFollower(&gameState.heroes[2].MapEntity());
321 gameState.heroes[3].MapEntity().Position() = Vector<Fixed<8> >(64, 128);
322 gameState.heroes[3].MapEntity().SetFlags(Entity::FLAG_NONBLOCKING);
323 gameState.heroes[2].MapEntity().AddFollower(&gameState.heroes[3].MapEntity());
325 InitScreen screen(width, height);
327 app::State *state(0);
330 BattleState *battleState(new BattleState(&gameConfig, bg, &monstersLayout));
331 battleState->AddMonster(monster);
332 battleState->AddMonster(monster);
333 battleState->AddMonster(monster);
334 battleState->AddMonster(monster);
335 battleState->SetCapsule(caster.GetCapsule("flash"));
336 battleState->AddHero(gameState.heroes[0]);
337 battleState->AddHero(gameState.heroes[1]);
338 battleState->AddHero(gameState.heroes[2]);
339 battleState->AddHero(gameState.heroes[3]);
342 MapState *mapState(new MapState(&gameConfig, caster.GetMap("map1")));
344 mapState->ControlEntity(&gameState.heroes[0].MapEntity());
345 mapState->SetWalkingSpeed(walkSpeed);
350 Application app(screen, state);
351 MapKeys(app.Buttons());
355 } catch (Parser::Error &e) {
356 cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl;
358 } catch (exception &e) {
359 cerr << "exception in main(): " << e.what() << endl;