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"
45 #include <SDL_image.h>
47 using app::Application;
50 using battle::BattleState;
52 using battle::Monster;
53 using battle::PartyLayout;
56 using common::Inventory;
59 using geometry::Vector;
60 using graphics::ComplexAnimation;
62 using graphics::Frame;
63 using graphics::Gauge;
65 using graphics::SimpleAnimation;
66 using graphics::Sprite;
67 using loader::Compiler;
68 using loader::Interpreter;
69 using loader::ParsedSource;
71 using loader::TypeDescription;
73 using sdl::InitScreen;
83 int main(int argc, char **argv) {
84 const int width = 800;
85 const int height = 480;
87 // std::srand(std::time(0));
91 InitImage image(IMG_INIT_PNG);
93 battle::Resources::CreateTypeDescription();
94 ComplexAnimation::CreateTypeDescription();
95 Font::CreateTypeDescription();
96 Frame::CreateTypeDescription();
97 Gauge::CreateTypeDescription();
98 Hero::CreateTypeDescription();
99 Ikari::CreateTypeDescription();
100 Interpreter::CreateTypeDescriptions();
101 Item::CreateTypeDescription();
102 graphics::MenuProperties::CreateTypeDescription();
103 Monster::CreateTypeDescription();
104 PartyLayout::CreateTypeDescription();
105 SimpleAnimation::CreateTypeDescription();
106 Spell::CreateTypeDescription();
107 Sprite::CreateTypeDescription();
108 Stats::CreateTypeDescription();
109 common::TargetingMode::CreateTypeDescription();
112 args.Read(argc, argv);
116 for (vector<char *>::const_iterator i(args.Infiles().begin()), end(args.Infiles().end()); i != end; ++i) {
118 switch (filePath[filePath.size() - 1]) {
120 // TODO: load object file
123 Parser(filePath, source).Parse();
126 throw std::runtime_error("don't know what to do with " + filePath);
130 // Parser("test-data/test.l2s", source).Parse();
131 // Parser("test-data/ikaris.l2s", source).Parse();
132 // Parser("test-data/items.l2s", source).Parse();
133 // Parser("test-data/spells.l2s", source).Parse();
134 // Parser("test-data/constants.l2s", source).Parse();
136 Interpreter intp(source);
139 switch (args.DetectRunLevel()) {
140 case Arguments::COMPILE:
142 int length(std::strlen(args.OutfilePath()));
143 switch (args.OutfilePath()[length - 1]) {
145 std::ofstream outstream(args.OutfilePath());
146 source.WriteHeader(outstream);
151 std::ofstream outstream(args.OutfilePath());
152 Compiler(intp).Write(outstream);
158 case Arguments::DUMP: {
159 std::cout << source << std::endl;
162 case Arguments::PLAY:
166 int battleResId(TypeDescription::GetTypeId("BattleResources"));
167 int heroId(TypeDescription::GetTypeId("Hero"));
168 int itemId(TypeDescription::GetTypeId("Item"));
169 int monsterId(TypeDescription::GetTypeId("Monster"));
170 int partyLayoutId(TypeDescription::GetTypeId("PartyLayout"));
171 int spellId(TypeDescription::GetTypeId("Spell"));
173 // temporary test data
174 SDL_Surface *bg(IMG_Load("test-data/battle-bg.png"));
175 PartyLayout monstersLayout(*reinterpret_cast<PartyLayout *>(intp.GetObject(partyLayoutId, "monstersLayout")));
176 PartyLayout heroesLayout(*reinterpret_cast<PartyLayout *>(intp.GetObject(partyLayoutId, "heroesLayout")));
178 Monster monster(*reinterpret_cast<Monster *>(intp.GetObject(monsterId, "lizard")));
179 Hero maxim(*reinterpret_cast<Hero *>(intp.GetObject(heroId, "maxim")));
180 Hero selan(*reinterpret_cast<Hero *>(intp.GetObject(heroId, "selan")));
181 Hero guy(*reinterpret_cast<Hero *>(intp.GetObject(heroId, "guy")));
182 Hero dekar(*reinterpret_cast<Hero *>(intp.GetObject(heroId, "dekar")));
184 battle::Resources *battleRes(reinterpret_cast<battle::Resources *>(intp.GetObject(battleResId, "battleResources")));
186 maxim.AddSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "resetSpell")));
187 Spell *strongSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "strongSpell")));
188 maxim.AddSpell(strongSpell);
189 selan.AddSpell(strongSpell);
190 Spell *strongerSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "strongerSpell")));
191 maxim.AddSpell(strongerSpell);
192 selan.AddSpell(strongerSpell);
193 Spell *championSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "championSpell")));
194 maxim.AddSpell(championSpell);
195 selan.AddSpell(championSpell);
196 Spell *rallySpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "rallySpell")));
197 maxim.AddSpell(rallySpell);
198 selan.AddSpell(rallySpell);
199 selan.AddSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "escapeSpell")));
200 Spell *valorSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "valorSpell")));
201 maxim.AddSpell(valorSpell);
202 selan.AddSpell(valorSpell);
205 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "antidoteItem")), 9);
206 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "magicJarItem")), 4);
207 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "hiPotionItem")), 4);
208 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "powerPotionItem")), 4);
209 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "escapeItem")), 2);
210 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "sleepBallItem")), 1);
211 battleRes->inventory = &inventory;
213 maxim.SetWeapon(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoSwordItem")));
214 maxim.SetArmor(reinterpret_cast<Item *>(intp.GetObject(itemId, "zirconArmorItem")));
215 maxim.SetShield(reinterpret_cast<Item *>(intp.GetObject(itemId, "holyShieldItem")));
216 maxim.SetHelmet(reinterpret_cast<Item *>(intp.GetObject(itemId, "legendHelmItem")));
217 maxim.SetRing(reinterpret_cast<Item *>(intp.GetObject(itemId, "sProRingItem")));
218 maxim.SetJewel(reinterpret_cast<Item *>(intp.GetObject(itemId, "evilJewelItem")));
220 // selan.SetWeapon(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoWhipItem")));
221 selan.SetArmor(reinterpret_cast<Item *>(intp.GetObject(itemId, "zirconPlateItem")));
222 selan.SetShield(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoGlovesItem")));
223 selan.SetHelmet(reinterpret_cast<Item *>(intp.GetObject(itemId, "holyCapItem")));
224 selan.SetRing(reinterpret_cast<Item *>(intp.GetObject(itemId, "ghostRingItem")));
225 selan.SetJewel(reinterpret_cast<Item *>(intp.GetObject(itemId, "eagleRockItem")));
227 // guy.SetWeapon(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoAxItem")));
228 guy.SetArmor(reinterpret_cast<Item *>(intp.GetObject(itemId, "zirconArmorItem")));
229 guy.SetShield(reinterpret_cast<Item *>(intp.GetObject(itemId, "megaShieldItem")));
230 guy.SetHelmet(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoHelmetItem")));
231 guy.SetRing(reinterpret_cast<Item *>(intp.GetObject(itemId, "powerRingItem")));
232 guy.SetJewel(reinterpret_cast<Item *>(intp.GetObject(itemId, "evilJewelItem")));
234 // NOTE: this is actually Artea equipment
235 // dekar.SetWeapon(reinterpret_cast<Item *>(intp.GetObject(itemId, "lizardBlowItem")));
236 dekar.SetArmor(reinterpret_cast<Item *>(intp.GetObject(itemId, "holyRobeItem")));
237 dekar.SetShield(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoGlovesItem")));
238 dekar.SetHelmet(reinterpret_cast<Item *>(intp.GetObject(itemId, "holyCapItem")));
239 dekar.SetRing(reinterpret_cast<Item *>(intp.GetObject(itemId, "rocketRingItem")));
240 dekar.SetJewel(reinterpret_cast<Item *>(intp.GetObject(itemId, "krakenRockItem")));
242 InitScreen screen(width, height);
244 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, battleRes));
245 battleState->AddMonster(monster);
246 battleState->AddMonster(monster);
247 battleState->AddMonster(monster);
248 battleState->AddMonster(monster);
249 battleState->AddHero(maxim);
250 battleState->AddHero(selan);
251 battleState->AddHero(guy);
252 battleState->AddHero(dekar);
253 Application app(&screen, battleState);
254 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
255 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
256 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
257 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
258 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
259 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
260 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
261 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
262 app.Buttons().MapKey(SDLK_RETURN, Input::START);
263 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
264 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
265 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
269 } catch (Parser::Error &e) {
270 cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl;
272 } catch (exception &e) {
273 cerr << "exception in main(): " << e.what() << endl;