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 switch (args.DetectRunLevel()) {
139 case Arguments::COMPILE:
141 std::ofstream testOut(args.OutfilePath());
142 Compiler(intp).Write(testOut);
145 case Arguments::DUMP:
147 std::cout << source << std::endl;
150 case Arguments::PLAY:
154 int battleResId(TypeDescription::GetTypeId("BattleResources"));
155 int heroId(TypeDescription::GetTypeId("Hero"));
156 int itemId(TypeDescription::GetTypeId("Item"));
157 int monsterId(TypeDescription::GetTypeId("Monster"));
158 int partyLayoutId(TypeDescription::GetTypeId("PartyLayout"));
159 int spellId(TypeDescription::GetTypeId("Spell"));
161 // temporary test data
162 SDL_Surface *bg(IMG_Load("test-data/battle-bg.png"));
163 PartyLayout monstersLayout(*reinterpret_cast<PartyLayout *>(intp.GetObject(partyLayoutId, "monstersLayout")));
164 PartyLayout heroesLayout(*reinterpret_cast<PartyLayout *>(intp.GetObject(partyLayoutId, "heroesLayout")));
166 Monster monster(*reinterpret_cast<Monster *>(intp.GetObject(monsterId, "lizard")));
167 Hero maxim(*reinterpret_cast<Hero *>(intp.GetObject(heroId, "maxim")));
168 Hero selan(*reinterpret_cast<Hero *>(intp.GetObject(heroId, "selan")));
169 Hero guy(*reinterpret_cast<Hero *>(intp.GetObject(heroId, "guy")));
170 Hero dekar(*reinterpret_cast<Hero *>(intp.GetObject(heroId, "dekar")));
172 battle::Resources *battleRes(reinterpret_cast<battle::Resources *>(intp.GetObject(battleResId, "battleResources")));
174 maxim.AddSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "resetSpell")));
175 Spell *strongSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "strongSpell")));
176 maxim.AddSpell(strongSpell);
177 selan.AddSpell(strongSpell);
178 Spell *strongerSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "strongerSpell")));
179 maxim.AddSpell(strongerSpell);
180 selan.AddSpell(strongerSpell);
181 Spell *championSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "championSpell")));
182 maxim.AddSpell(championSpell);
183 selan.AddSpell(championSpell);
184 Spell *rallySpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "rallySpell")));
185 maxim.AddSpell(rallySpell);
186 selan.AddSpell(rallySpell);
187 selan.AddSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "escapeSpell")));
188 Spell *valorSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "valorSpell")));
189 maxim.AddSpell(valorSpell);
190 selan.AddSpell(valorSpell);
193 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "antidoteItem")), 9);
194 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "magicJarItem")), 4);
195 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "hiPotionItem")), 4);
196 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "powerPotionItem")), 4);
197 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "escapeItem")), 2);
198 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "sleepBallItem")), 1);
199 battleRes->inventory = &inventory;
201 maxim.SetWeapon(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoSwordItem")));
202 maxim.SetArmor(reinterpret_cast<Item *>(intp.GetObject(itemId, "zirconArmorItem")));
203 maxim.SetShield(reinterpret_cast<Item *>(intp.GetObject(itemId, "holyShieldItem")));
204 maxim.SetHelmet(reinterpret_cast<Item *>(intp.GetObject(itemId, "legendHelmItem")));
205 maxim.SetRing(reinterpret_cast<Item *>(intp.GetObject(itemId, "sProRingItem")));
206 maxim.SetJewel(reinterpret_cast<Item *>(intp.GetObject(itemId, "evilJewelItem")));
208 // selan.SetWeapon(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoWhipItem")));
209 selan.SetArmor(reinterpret_cast<Item *>(intp.GetObject(itemId, "zirconPlateItem")));
210 selan.SetShield(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoGlovesItem")));
211 selan.SetHelmet(reinterpret_cast<Item *>(intp.GetObject(itemId, "holyCapItem")));
212 selan.SetRing(reinterpret_cast<Item *>(intp.GetObject(itemId, "ghostRingItem")));
213 selan.SetJewel(reinterpret_cast<Item *>(intp.GetObject(itemId, "eagleRockItem")));
215 // guy.SetWeapon(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoAxItem")));
216 guy.SetArmor(reinterpret_cast<Item *>(intp.GetObject(itemId, "zirconArmorItem")));
217 guy.SetShield(reinterpret_cast<Item *>(intp.GetObject(itemId, "megaShieldItem")));
218 guy.SetHelmet(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoHelmetItem")));
219 guy.SetRing(reinterpret_cast<Item *>(intp.GetObject(itemId, "powerRingItem")));
220 guy.SetJewel(reinterpret_cast<Item *>(intp.GetObject(itemId, "evilJewelItem")));
222 // NOTE: this is actually Artea equipment
223 // dekar.SetWeapon(reinterpret_cast<Item *>(intp.GetObject(itemId, "lizardBlowItem")));
224 dekar.SetArmor(reinterpret_cast<Item *>(intp.GetObject(itemId, "holyRobeItem")));
225 dekar.SetShield(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoGlovesItem")));
226 dekar.SetHelmet(reinterpret_cast<Item *>(intp.GetObject(itemId, "holyCapItem")));
227 dekar.SetRing(reinterpret_cast<Item *>(intp.GetObject(itemId, "rocketRingItem")));
228 dekar.SetJewel(reinterpret_cast<Item *>(intp.GetObject(itemId, "krakenRockItem")));
230 InitScreen screen(width, height);
232 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, battleRes));
233 battleState->AddMonster(monster);
234 battleState->AddMonster(monster);
235 battleState->AddMonster(monster);
236 battleState->AddMonster(monster);
237 battleState->AddHero(maxim);
238 battleState->AddHero(selan);
239 battleState->AddHero(guy);
240 battleState->AddHero(dekar);
241 Application app(&screen, battleState);
242 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
243 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
244 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
245 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
246 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
247 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
248 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
249 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
250 app.Buttons().MapKey(SDLK_RETURN, Input::START);
251 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
252 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
253 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
257 } catch (Parser::Error &e) {
258 cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl;
260 } catch (exception &e) {
261 cerr << "exception in main(): " << e.what() << endl;