4 * Created on: Aug 1, 2012
8 #include "app/Application.h"
10 #include "battle/BattleState.h"
11 #include "battle/Hero.h"
12 #include "battle/Monster.h"
13 #include "battle/PartyLayout.h"
14 #include "battle/Resources.h"
15 #include "battle/Stats.h"
16 #include "common/Ikari.h"
17 #include "common/Inventory.h"
18 #include "common/Item.h"
19 #include "common/Spell.h"
20 #include "geometry/Vector.h"
21 #include "graphics/ComplexAnimation.h"
22 #include "graphics/Font.h"
23 #include "graphics/Frame.h"
24 #include "graphics/Gauge.h"
25 #include "graphics/Menu.h"
26 #include "graphics/SimpleAnimation.h"
27 #include "graphics/Sprite.h"
28 #include "loader/Interpreter.h"
29 #include "loader/ParsedSource.h"
30 #include "loader/Parser.h"
31 #include "loader/TypeDescription.h"
32 #include "sdl/InitImage.h"
33 #include "sdl/InitScreen.h"
34 #include "sdl/InitSDL.h"
41 #include <SDL_image.h>
43 using app::Application;
45 using battle::BattleState;
47 using battle::Monster;
48 using battle::PartyLayout;
51 using common::Inventory;
54 using geometry::Vector;
55 using graphics::ComplexAnimation;
57 using graphics::Frame;
58 using graphics::Gauge;
60 using graphics::SimpleAnimation;
61 using graphics::Sprite;
62 using loader::Interpreter;
63 using loader::ParsedSource;
65 using loader::TypeDescription;
67 using sdl::InitScreen;
75 int main(int argc, char **argv) {
76 const int width = 800;
77 const int height = 480;
79 // std::srand(std::time(0));
83 InitImage image(IMG_INIT_PNG);
85 battle::Resources::CreateTypeDescription();
86 ComplexAnimation::CreateTypeDescription();
87 Font::CreateTypeDescription();
88 Frame::CreateTypeDescription();
89 Gauge::CreateTypeDescription();
90 Hero::CreateTypeDescription();
91 Ikari::CreateTypeDescription();
92 Interpreter::CreateTypeDescriptions();
93 Item::CreateTypeDescription();
94 graphics::MenuProperties::CreateTypeDescription();
95 Monster::CreateTypeDescription();
96 PartyLayout::CreateTypeDescription();
97 SimpleAnimation::CreateTypeDescription();
98 Spell::CreateTypeDescription();
99 Sprite::CreateTypeDescription();
100 Stats::CreateTypeDescription();
101 common::TargetingMode::CreateTypeDescription();
104 Parser("test-data/test.l2s", source).Parse();
105 Parser("test-data/ikaris.l2s", source).Parse();
106 Parser("test-data/items.l2s", source).Parse();
107 Parser("test-data/spells.l2s", source).Parse();
108 Parser("test-data/constants.l2s", source).Parse();
109 Interpreter intp(source);
112 int battleResId(TypeDescription::GetTypeId("BattleResources"));
113 int heroId(TypeDescription::GetTypeId("Hero"));
114 int itemId(TypeDescription::GetTypeId("Item"));
115 int monsterId(TypeDescription::GetTypeId("Monster"));
116 int partyLayoutId(TypeDescription::GetTypeId("PartyLayout"));
117 int spellId(TypeDescription::GetTypeId("Spell"));
119 // temporary test data
120 SDL_Surface *bg(IMG_Load("test-data/battle-bg.png"));
121 PartyLayout monstersLayout(*reinterpret_cast<PartyLayout *>(intp.GetObject(partyLayoutId, "monstersLayout")));
122 PartyLayout heroesLayout(*reinterpret_cast<PartyLayout *>(intp.GetObject(partyLayoutId, "heroesLayout")));
124 Monster monster(*reinterpret_cast<Monster *>(intp.GetObject(monsterId, "lizard")));
125 Hero maxim(*reinterpret_cast<Hero *>(intp.GetObject(heroId, "maxim")));
126 Hero selan(*reinterpret_cast<Hero *>(intp.GetObject(heroId, "selan")));
127 Hero guy(*reinterpret_cast<Hero *>(intp.GetObject(heroId, "guy")));
128 Hero dekar(*reinterpret_cast<Hero *>(intp.GetObject(heroId, "dekar")));
130 battle::Resources *battleRes(reinterpret_cast<battle::Resources *>(intp.GetObject(battleResId, "battleResources")));
132 maxim.AddSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "resetSpell")));
133 Spell *strongSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "strongSpell")));
134 maxim.AddSpell(strongSpell);
135 selan.AddSpell(strongSpell);
136 Spell *strongerSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "strongerSpell")));
137 maxim.AddSpell(strongerSpell);
138 selan.AddSpell(strongerSpell);
139 Spell *championSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "championSpell")));
140 maxim.AddSpell(championSpell);
141 selan.AddSpell(championSpell);
142 Spell *rallySpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "rallySpell")));
143 maxim.AddSpell(rallySpell);
144 selan.AddSpell(rallySpell);
145 selan.AddSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "escapeSpell")));
146 Spell *valorSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "valorSpell")));
147 maxim.AddSpell(valorSpell);
148 selan.AddSpell(valorSpell);
151 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "antidoteItem")), 9);
152 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "magicJarItem")), 4);
153 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "hiPotionItem")), 4);
154 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "powerPotionItem")), 4);
155 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "escapeItem")), 2);
156 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "sleepBallItem")), 1);
157 battleRes->inventory = &inventory;
159 maxim.SetWeapon(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoSwordItem")));
160 maxim.SetArmor(reinterpret_cast<Item *>(intp.GetObject(itemId, "zirconArmorItem")));
161 maxim.SetShield(reinterpret_cast<Item *>(intp.GetObject(itemId, "holyShieldItem")));
162 maxim.SetHelmet(reinterpret_cast<Item *>(intp.GetObject(itemId, "legendHelmItem")));
163 maxim.SetRing(reinterpret_cast<Item *>(intp.GetObject(itemId, "sProRingItem")));
164 maxim.SetJewel(reinterpret_cast<Item *>(intp.GetObject(itemId, "evilJewelItem")));
166 // selan.SetWeapon(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoWhipItem")));
167 selan.SetArmor(reinterpret_cast<Item *>(intp.GetObject(itemId, "zirconPlateItem")));
168 selan.SetShield(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoGlovesItem")));
169 selan.SetHelmet(reinterpret_cast<Item *>(intp.GetObject(itemId, "holyCapItem")));
170 selan.SetRing(reinterpret_cast<Item *>(intp.GetObject(itemId, "ghostRingItem")));
171 selan.SetJewel(reinterpret_cast<Item *>(intp.GetObject(itemId, "eagleRockItem")));
173 // guy.SetWeapon(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoAxItem")));
174 guy.SetArmor(reinterpret_cast<Item *>(intp.GetObject(itemId, "zirconArmorItem")));
175 guy.SetShield(reinterpret_cast<Item *>(intp.GetObject(itemId, "megaShieldItem")));
176 guy.SetHelmet(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoHelmetItem")));
177 guy.SetRing(reinterpret_cast<Item *>(intp.GetObject(itemId, "powerRingItem")));
178 guy.SetJewel(reinterpret_cast<Item *>(intp.GetObject(itemId, "evilJewelItem")));
180 // NOTE: this is actually Artea equipment
181 // dekar.SetWeapon(reinterpret_cast<Item *>(intp.GetObject(itemId, "lizardBlowItem")));
182 dekar.SetArmor(reinterpret_cast<Item *>(intp.GetObject(itemId, "holyRobeItem")));
183 dekar.SetShield(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoGlovesItem")));
184 dekar.SetHelmet(reinterpret_cast<Item *>(intp.GetObject(itemId, "holyCapItem")));
185 dekar.SetRing(reinterpret_cast<Item *>(intp.GetObject(itemId, "rocketRingItem")));
186 dekar.SetJewel(reinterpret_cast<Item *>(intp.GetObject(itemId, "krakenRockItem")));
188 InitScreen screen(width, height);
190 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, battleRes));
191 battleState->AddMonster(monster);
192 battleState->AddMonster(monster);
193 battleState->AddMonster(monster);
194 battleState->AddMonster(monster);
195 battleState->AddHero(maxim);
196 battleState->AddHero(selan);
197 battleState->AddHero(guy);
198 battleState->AddHero(dekar);
199 Application app(&screen, battleState);
200 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
201 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
202 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
203 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
204 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
205 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
206 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
207 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
208 app.Buttons().MapKey(SDLK_RETURN, Input::START);
209 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
210 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
211 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
215 } catch (Parser::Error &e) {
216 cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl;
218 } catch (exception &e) {
219 cerr << "exception in main(): " << e.what() << endl;