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 "math/Fixed.h"
23 #include "math/Vector.h"
24 #include "graphics/CharSelect.h"
25 #include "graphics/ComplexAnimation.h"
26 #include "graphics/Font.h"
27 #include "graphics/Frame.h"
28 #include "graphics/Gauge.h"
29 #include "graphics/Menu.h"
30 #include "graphics/SimpleAnimation.h"
31 #include "graphics/Sprite.h"
32 #include "graphics/Texture.h"
33 #include "loader/Caster.h"
34 #include "loader/Interpreter.h"
35 #include "loader/Loader.h"
36 #include "loader/ParsedSource.h"
37 #include "loader/Parser.h"
38 #include "loader/TypeDescription.h"
40 #include "map/Entity.h"
42 #include "map/MapState.h"
44 #include "map/Trigger.h"
45 #include "menu/Resources.h"
46 #include "sdl/InitImage.h"
47 #include "sdl/InitScreen.h"
48 #include "sdl/InitSDL.h"
57 #include <SDL_image.h>
59 using app::Application;
62 using battle::BattleState;
63 using battle::Monster;
64 using battle::PartyLayout;
65 using common::Capsule;
66 using common::GameConfig;
67 using common::GameState;
72 using graphics::Texture;
74 using loader::Interpreter;
76 using loader::ParsedSource;
78 using loader::TypeDescription;
82 using sdl::InitScreen;
92 int main(int argc, char **argv) {
93 const int width = 512;
94 const int height = 448;
96 const Fixed<8> walkSpeed = Fixed<8>(1, 8);
100 // std::srand(std::time(0));
104 InitImage image(IMG_INIT_PNG);
106 Interpreter::CreateTypeDescriptions();
108 battle::Resources::CreateTypeDescription();
109 battle::Monster::CreateTypeDescription();
110 battle::PartyLayout::CreateTypeDescription();
112 common::Capsule::CreateTypeDescription();
113 common::Hero::CreateTypeDescription();
114 common::Ikari::CreateTypeDescription();
115 common::Item::CreateTypeDescription();
116 common::LevelUp::CreateTypeDescription();
117 common::Stats::CreateTypeDescription();
118 common::Spell::CreateTypeDescription();
119 common::TargetingMode::CreateTypeDescription();
121 graphics::Animation::CreateTypeDescription();
122 graphics::CharSelect::CreateTypeDescription();
123 graphics::ComplexAnimation::CreateTypeDescription();
124 graphics::Font::CreateTypeDescription();
125 graphics::Frame::CreateTypeDescription();
126 graphics::Gauge::CreateTypeDescription();
127 graphics::MenuProperties::CreateTypeDescription();
128 graphics::SimpleAnimation::CreateTypeDescription();
129 graphics::Sprite::CreateTypeDescription();
130 graphics::Texture::CreateTypeDescription();
132 map::Area::CreateTypeDescription();
133 map::Entity::CreateTypeDescription();
134 map::Map::CreateTypeDescription();
135 map::Tile::CreateTypeDescription();
136 map::Trigger::CreateTypeDescription();
138 menu::Resources::CreateTypeDescription();
141 args.Read(argc, argv);
147 for (vector<char *>::const_iterator i(args.Infiles().begin()), end(args.Infiles().end()); i != end; ++i) {
149 switch (filePath[filePath.size() - 1]) {
154 Parser(filePath, source).Parse();
157 throw std::runtime_error("don't know what to do with " + filePath);
161 switch (args.GetRunLevel()) {
162 case Arguments::WRITE:
164 int length(std::strlen(args.OutfilePath()));
165 switch (args.OutfilePath()[length - 1]) {
167 std::ofstream outstream(args.OutfilePath());
168 source.WriteHeader(outstream);
172 std::ofstream outstream(args.OutfilePath());
173 Compiler(intp).Write(outstream);
176 throw std::runtime_error(string("don't know how to write file ") + args.OutfilePath());
181 case Arguments::DUMP: {
182 std::cout << source << std::endl;
185 case Arguments::SOURCE_WIKI: {
186 TypeDescription::WriteSourceWiki(std::cout);
189 case Arguments::BATTLE:
192 case Arguments::PLAY:
197 Interpreter intp(source);
200 if (intp.PostponedDefinitions().size() > 0) {
201 for (vector<Interpreter::PostponedDefinition>::const_iterator i(intp.PostponedDefinitions().begin()), end(intp.PostponedDefinitions().end()); i != end; ++i) {
202 std::cerr << "missing definition of " << TypeDescription::Get(i->type).TypeName() << " " << i->identifier << std::endl;
211 gameState.heroes[0] = *caster.GetHero("maxim");
212 gameState.heroes[1] = *caster.GetHero("selan");
213 gameState.heroes[2] = *caster.GetHero("guy");
214 gameState.heroes[3] = *caster.GetHero("dekar");
216 gameState.party[0] = &gameState.heroes[0];
217 gameState.party[1] = &gameState.heroes[1];
218 gameState.party[2] = &gameState.heroes[2];
219 gameState.party[3] = &gameState.heroes[3];
220 gameState.partySize = 4;
222 gameState.capsules[1] = *caster.GetCapsule("flash");
223 gameState.capsules[1].UpgradeClass();
224 gameState.capsules[1].UpgradeClass();
225 gameState.capsules[1].UpgradeClass();
226 gameState.capsules[1].UpgradeClass();
227 gameState.capsule = 1;
229 GameConfig gameConfig;
230 gameConfig.state = &gameState;
231 gameConfig.heroesLayout = caster.GetPartyLayout("heroesLayout");
232 gameConfig.battleResources = caster.GetBattleResources("battleResources");
233 gameConfig.menuResources = caster.GetMenuResources("menuResources");
235 // temporary test data
236 SDL_Surface *bg(IMG_Load("test-data/battle-bg.png"));
237 PartyLayout monstersLayout(*caster.GetPartyLayout("monstersLayout"));
239 Monster monster(*caster.GetMonster("lizard"));
241 gameState.heroes[0].AddSpell(caster.GetSpell("resetSpell"));
242 Spell *strongSpell(caster.GetSpell("strongSpell"));
243 gameState.heroes[0].AddSpell(strongSpell);
244 gameState.heroes[1].AddSpell(strongSpell);
245 Spell *strongerSpell(caster.GetSpell("strongerSpell"));
246 gameState.heroes[0].AddSpell(strongerSpell);
247 gameState.heroes[1].AddSpell(strongerSpell);
248 Spell *championSpell(caster.GetSpell("championSpell"));
249 gameState.heroes[0].AddSpell(championSpell);
250 gameState.heroes[1].AddSpell(championSpell);
251 Spell *rallySpell(caster.GetSpell("rallySpell"));
252 gameState.heroes[0].AddSpell(rallySpell);
253 gameState.heroes[1].AddSpell(rallySpell);
254 gameState.heroes[1].AddSpell(caster.GetSpell("escapeSpell"));
255 Spell *valorSpell(caster.GetSpell("valorSpell"));
256 gameState.heroes[0].AddSpell(valorSpell);
257 gameState.heroes[1].AddSpell(valorSpell);
259 gameState.inventory.Add(caster.GetItem("zirconPlateItem"), 32);
260 gameState.inventory.Add(caster.GetItem("holyFruitItem"));
261 gameState.inventory.Add(caster.GetItem("darkFruitItem"));
262 gameState.inventory.Add(caster.GetItem("antidoteItem"), 9);
263 gameState.inventory.Add(caster.GetItem("powerRingItem"));
264 gameState.inventory.Add(caster.GetItem("magicJarItem"), 4);
265 gameState.inventory.Add(caster.GetItem("sProRingItem"));
266 gameState.inventory.Add(caster.GetItem("hiPotionItem"), 4);
267 gameState.inventory.Add(caster.GetItem("powerRingItem"));
268 gameState.inventory.Add(caster.GetItem("powerPotionItem"), 4);
269 gameState.inventory.Add(caster.GetItem("zircoSwordItem"));
270 gameState.inventory.Add(caster.GetItem("escapeItem"), 2);
271 gameState.inventory.Add(caster.GetItem("zircoHelmetItem"));
272 gameState.inventory.Add(caster.GetItem("sleepBallItem"), 1);
273 gameState.inventory.Add(caster.GetItem("zirconPlateItem"));
275 gameState.heroes[0].SetEquipment(Hero::EQUIP_WEAPON, caster.GetItem("zircoSwordItem"));
276 gameState.heroes[0].SetEquipment(Hero::EQUIP_ARMOR, caster.GetItem("zirconArmorItem"));
277 gameState.heroes[0].SetEquipment(Hero::EQUIP_SHIELD, caster.GetItem("holyShieldItem"));
278 gameState.heroes[0].SetEquipment(Hero::EQUIP_HELMET, caster.GetItem("legendHelmItem"));
279 gameState.heroes[0].SetEquipment(Hero::EQUIP_RING, caster.GetItem("sProRingItem"));
280 gameState.heroes[0].SetEquipment(Hero::EQUIP_JEWEL, caster.GetItem("evilJewelItem"));
282 // gameState.heroes[1].SetEquipment(Hero::EQUIP_WEAPON, caster.GetItem("zircoWhipItem"));
283 gameState.heroes[1].SetEquipment(Hero::EQUIP_ARMOR, caster.GetItem("zirconPlateItem"));
284 gameState.heroes[1].SetEquipment(Hero::EQUIP_SHIELD, caster.GetItem("zircoGlovesItem"));
285 gameState.heroes[1].SetEquipment(Hero::EQUIP_HELMET, caster.GetItem("holyCapItem"));
286 gameState.heroes[1].SetEquipment(Hero::EQUIP_RING, caster.GetItem("ghostRingItem"));
287 gameState.heroes[1].SetEquipment(Hero::EQUIP_JEWEL, caster.GetItem("eagleRockItem"));
289 // gameState.heroes[2].SetEquipment(Hero::EQUIP_WEAPON, caster.GetItem("zircoAxItem"));
290 gameState.heroes[2].SetEquipment(Hero::EQUIP_ARMOR, caster.GetItem("zirconArmorItem"));
291 gameState.heroes[2].SetEquipment(Hero::EQUIP_SHIELD, caster.GetItem("megaShieldItem"));
292 gameState.heroes[2].SetEquipment(Hero::EQUIP_HELMET, caster.GetItem("zircoHelmetItem"));
293 gameState.heroes[2].SetEquipment(Hero::EQUIP_RING, caster.GetItem("powerRingItem"));
294 gameState.heroes[2].SetEquipment(Hero::EQUIP_JEWEL, caster.GetItem("evilJewelItem"));
296 // NOTE: this is actually Artea equipment
297 // gameState.heroes[3].SetEquipment(Hero::EQUIP_WEAPON, caster.GetItem("lizardBlowItem"));
298 gameState.heroes[3].SetEquipment(Hero::EQUIP_ARMOR, caster.GetItem("holyRobeItem"));
299 gameState.heroes[3].SetEquipment(Hero::EQUIP_SHIELD, caster.GetItem("zircoGlovesItem"));
300 gameState.heroes[3].SetEquipment(Hero::EQUIP_HELMET, caster.GetItem("holyCapItem"));
301 gameState.heroes[3].SetEquipment(Hero::EQUIP_RING, caster.GetItem("rocketRingItem"));
302 gameState.heroes[3].SetEquipment(Hero::EQUIP_JEWEL, caster.GetItem("krakenRockItem"));
304 gameState.heroes[0].MapEntity().Position() = Vector<Fixed<8> >(64, 128);
306 gameState.heroes[1].MapEntity().Position() = Vector<Fixed<8> >(64, 128);
307 gameState.heroes[1].MapEntity().SetFlags(Entity::FLAG_NONBLOCKING);
308 gameState.heroes[0].MapEntity().AddFollower(&gameState.heroes[1].MapEntity());
310 gameState.heroes[2].MapEntity().Position() = Vector<Fixed<8> >(64, 128);
311 gameState.heroes[2].MapEntity().SetFlags(Entity::FLAG_NONBLOCKING);
312 gameState.heroes[1].MapEntity().AddFollower(&gameState.heroes[2].MapEntity());
314 gameState.heroes[3].MapEntity().Position() = Vector<Fixed<8> >(64, 128);
315 gameState.heroes[3].MapEntity().SetFlags(Entity::FLAG_NONBLOCKING);
316 gameState.heroes[2].MapEntity().AddFollower(&gameState.heroes[3].MapEntity());
318 InitScreen screen(width, height);
320 app::State *state(0);
323 BattleState *battleState(new BattleState(&gameConfig, bg, &monstersLayout));
324 battleState->AddMonster(monster);
325 battleState->AddMonster(monster);
326 battleState->AddMonster(monster);
327 battleState->AddMonster(monster);
328 battleState->SetCapsule(caster.GetCapsule("flash"));
329 battleState->AddHero(gameState.heroes[0]);
330 battleState->AddHero(gameState.heroes[1]);
331 battleState->AddHero(gameState.heroes[2]);
332 battleState->AddHero(gameState.heroes[3]);
335 MapState *mapState(new MapState(&gameConfig, caster.GetMap("map1")));
337 mapState->ControlEntity(&gameState.heroes[0].MapEntity());
338 mapState->SetWalkingSpeed(walkSpeed);
343 Application app(screen, state);
344 MapKeys(app.Buttons());
348 } catch (Parser::Error &e) {
349 cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl;
351 } catch (exception &e) {
352 cerr << "exception in main(): " << e.what() << endl;