4 * Created on: Aug 1, 2012
8 #include "app/Application.h"
9 #include "app/Arguments.h"
10 #include "app/Input.h"
11 #include "battle/BattleState.h"
12 #include "battle/Hero.h"
13 #include "battle/Monster.h"
14 #include "battle/PartyLayout.h"
15 #include "battle/Resources.h"
16 #include "battle/Stats.h"
17 #include "common/Ikari.h"
18 #include "common/Inventory.h"
19 #include "common/Item.h"
20 #include "common/Spell.h"
21 #include "geometry/Vector.h"
22 #include "graphics/ComplexAnimation.h"
23 #include "graphics/Font.h"
24 #include "graphics/Frame.h"
25 #include "graphics/Gauge.h"
26 #include "graphics/Menu.h"
27 #include "graphics/SimpleAnimation.h"
28 #include "graphics/Sprite.h"
29 #include "loader/Compiler.h"
30 #include "loader/Interpreter.h"
31 #include "loader/ParsedSource.h"
32 #include "loader/Parser.h"
33 #include "loader/TypeDescription.h"
34 #include "sdl/InitImage.h"
35 #include "sdl/InitScreen.h"
36 #include "sdl/InitSDL.h"
44 #include <SDL_image.h>
46 using app::Application;
49 using battle::BattleState;
51 using battle::Monster;
52 using battle::PartyLayout;
55 using common::Inventory;
58 using geometry::Vector;
59 using graphics::ComplexAnimation;
61 using graphics::Frame;
62 using graphics::Gauge;
64 using graphics::SimpleAnimation;
65 using graphics::Sprite;
66 using loader::Compiler;
67 using loader::Interpreter;
68 using loader::ParsedSource;
70 using loader::TypeDescription;
72 using sdl::InitScreen;
82 int main(int argc, char **argv) {
83 const int width = 800;
84 const int height = 480;
86 // std::srand(std::time(0));
90 InitImage image(IMG_INIT_PNG);
92 battle::Resources::CreateTypeDescription();
93 ComplexAnimation::CreateTypeDescription();
94 Font::CreateTypeDescription();
95 Frame::CreateTypeDescription();
96 Gauge::CreateTypeDescription();
97 Hero::CreateTypeDescription();
98 Ikari::CreateTypeDescription();
99 Interpreter::CreateTypeDescriptions();
100 Item::CreateTypeDescription();
101 graphics::MenuProperties::CreateTypeDescription();
102 Monster::CreateTypeDescription();
103 PartyLayout::CreateTypeDescription();
104 SimpleAnimation::CreateTypeDescription();
105 Spell::CreateTypeDescription();
106 Sprite::CreateTypeDescription();
107 Stats::CreateTypeDescription();
108 common::TargetingMode::CreateTypeDescription();
111 args.Read(argc, argv);
115 for (vector<char *>::const_iterator i(args.Infiles().begin()), end(args.Infiles().end()); i != end; ++i) {
117 switch (filePath[filePath.size() - 1]) {
119 // TODO: load object file
122 Parser(filePath, source).Parse();
125 throw std::runtime_error("don't know what to do with " + filePath);
129 // Parser("test-data/test.l2s", source).Parse();
130 // Parser("test-data/ikaris.l2s", source).Parse();
131 // Parser("test-data/items.l2s", source).Parse();
132 // Parser("test-data/spells.l2s", source).Parse();
133 // Parser("test-data/constants.l2s", source).Parse();
135 Interpreter intp(source);
138 if (args.OutfileSet()) {
139 std::ofstream testOut(args.OutfilePath());
140 Compiler(intp).Write(testOut);
144 int battleResId(TypeDescription::GetTypeId("BattleResources"));
145 int heroId(TypeDescription::GetTypeId("Hero"));
146 int itemId(TypeDescription::GetTypeId("Item"));
147 int monsterId(TypeDescription::GetTypeId("Monster"));
148 int partyLayoutId(TypeDescription::GetTypeId("PartyLayout"));
149 int spellId(TypeDescription::GetTypeId("Spell"));
151 // temporary test data
152 SDL_Surface *bg(IMG_Load("test-data/battle-bg.png"));
153 PartyLayout monstersLayout(*reinterpret_cast<PartyLayout *>(intp.GetObject(partyLayoutId, "monstersLayout")));
154 PartyLayout heroesLayout(*reinterpret_cast<PartyLayout *>(intp.GetObject(partyLayoutId, "heroesLayout")));
156 Monster monster(*reinterpret_cast<Monster *>(intp.GetObject(monsterId, "lizard")));
157 Hero maxim(*reinterpret_cast<Hero *>(intp.GetObject(heroId, "maxim")));
158 Hero selan(*reinterpret_cast<Hero *>(intp.GetObject(heroId, "selan")));
159 Hero guy(*reinterpret_cast<Hero *>(intp.GetObject(heroId, "guy")));
160 Hero dekar(*reinterpret_cast<Hero *>(intp.GetObject(heroId, "dekar")));
162 battle::Resources *battleRes(reinterpret_cast<battle::Resources *>(intp.GetObject(battleResId, "battleResources")));
164 maxim.AddSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "resetSpell")));
165 Spell *strongSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "strongSpell")));
166 maxim.AddSpell(strongSpell);
167 selan.AddSpell(strongSpell);
168 Spell *strongerSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "strongerSpell")));
169 maxim.AddSpell(strongerSpell);
170 selan.AddSpell(strongerSpell);
171 Spell *championSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "championSpell")));
172 maxim.AddSpell(championSpell);
173 selan.AddSpell(championSpell);
174 Spell *rallySpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "rallySpell")));
175 maxim.AddSpell(rallySpell);
176 selan.AddSpell(rallySpell);
177 selan.AddSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "escapeSpell")));
178 Spell *valorSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "valorSpell")));
179 maxim.AddSpell(valorSpell);
180 selan.AddSpell(valorSpell);
183 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "antidoteItem")), 9);
184 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "magicJarItem")), 4);
185 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "hiPotionItem")), 4);
186 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "powerPotionItem")), 4);
187 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "escapeItem")), 2);
188 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "sleepBallItem")), 1);
189 battleRes->inventory = &inventory;
191 maxim.SetWeapon(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoSwordItem")));
192 maxim.SetArmor(reinterpret_cast<Item *>(intp.GetObject(itemId, "zirconArmorItem")));
193 maxim.SetShield(reinterpret_cast<Item *>(intp.GetObject(itemId, "holyShieldItem")));
194 maxim.SetHelmet(reinterpret_cast<Item *>(intp.GetObject(itemId, "legendHelmItem")));
195 maxim.SetRing(reinterpret_cast<Item *>(intp.GetObject(itemId, "sProRingItem")));
196 maxim.SetJewel(reinterpret_cast<Item *>(intp.GetObject(itemId, "evilJewelItem")));
198 // selan.SetWeapon(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoWhipItem")));
199 selan.SetArmor(reinterpret_cast<Item *>(intp.GetObject(itemId, "zirconPlateItem")));
200 selan.SetShield(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoGlovesItem")));
201 selan.SetHelmet(reinterpret_cast<Item *>(intp.GetObject(itemId, "holyCapItem")));
202 selan.SetRing(reinterpret_cast<Item *>(intp.GetObject(itemId, "ghostRingItem")));
203 selan.SetJewel(reinterpret_cast<Item *>(intp.GetObject(itemId, "eagleRockItem")));
205 // guy.SetWeapon(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoAxItem")));
206 guy.SetArmor(reinterpret_cast<Item *>(intp.GetObject(itemId, "zirconArmorItem")));
207 guy.SetShield(reinterpret_cast<Item *>(intp.GetObject(itemId, "megaShieldItem")));
208 guy.SetHelmet(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoHelmetItem")));
209 guy.SetRing(reinterpret_cast<Item *>(intp.GetObject(itemId, "powerRingItem")));
210 guy.SetJewel(reinterpret_cast<Item *>(intp.GetObject(itemId, "evilJewelItem")));
212 // NOTE: this is actually Artea equipment
213 // dekar.SetWeapon(reinterpret_cast<Item *>(intp.GetObject(itemId, "lizardBlowItem")));
214 dekar.SetArmor(reinterpret_cast<Item *>(intp.GetObject(itemId, "holyRobeItem")));
215 dekar.SetShield(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoGlovesItem")));
216 dekar.SetHelmet(reinterpret_cast<Item *>(intp.GetObject(itemId, "holyCapItem")));
217 dekar.SetRing(reinterpret_cast<Item *>(intp.GetObject(itemId, "rocketRingItem")));
218 dekar.SetJewel(reinterpret_cast<Item *>(intp.GetObject(itemId, "krakenRockItem")));
220 InitScreen screen(width, height);
222 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, battleRes));
223 battleState->AddMonster(monster);
224 battleState->AddMonster(monster);
225 battleState->AddMonster(monster);
226 battleState->AddMonster(monster);
227 battleState->AddHero(maxim);
228 battleState->AddHero(selan);
229 battleState->AddHero(guy);
230 battleState->AddHero(dekar);
231 Application app(&screen, battleState);
232 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
233 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
234 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
235 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
236 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
237 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
238 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
239 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
240 app.Buttons().MapKey(SDLK_RETURN, Input::START);
241 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
242 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
243 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
247 } catch (Parser::Error &e) {
248 cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl;
250 } catch (exception &e) {
251 cerr << "exception in main(): " << e.what() << endl;