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/Interpreter.h"
30 #include "loader/ParsedSource.h"
31 #include "loader/Parser.h"
32 #include "loader/TypeDescription.h"
33 #include "sdl/InitImage.h"
34 #include "sdl/InitScreen.h"
35 #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::Interpreter;
67 using loader::ParsedSource;
69 using loader::TypeDescription;
71 using sdl::InitScreen;
81 int main(int argc, char **argv) {
82 const int width = 800;
83 const int height = 480;
85 // std::srand(std::time(0));
89 InitImage image(IMG_INIT_PNG);
91 battle::Resources::CreateTypeDescription();
92 ComplexAnimation::CreateTypeDescription();
93 Font::CreateTypeDescription();
94 Frame::CreateTypeDescription();
95 Gauge::CreateTypeDescription();
96 Hero::CreateTypeDescription();
97 Ikari::CreateTypeDescription();
98 Interpreter::CreateTypeDescriptions();
99 Item::CreateTypeDescription();
100 graphics::MenuProperties::CreateTypeDescription();
101 Monster::CreateTypeDescription();
102 PartyLayout::CreateTypeDescription();
103 SimpleAnimation::CreateTypeDescription();
104 Spell::CreateTypeDescription();
105 Sprite::CreateTypeDescription();
106 Stats::CreateTypeDescription();
107 common::TargetingMode::CreateTypeDescription();
110 args.Read(argc, argv);
114 for (vector<char *>::const_iterator i(args.Infiles().begin()), end(args.Infiles().end()); i != end; ++i) {
115 Parser(*i, source).Parse();
118 switch (args.DetectRunLevel()) {
119 case Arguments::WRITE:
121 int length(std::strlen(args.OutfilePath()));
122 switch (args.OutfilePath()[length - 1]) {
124 std::ofstream outstream(args.OutfilePath());
125 source.WriteHeader(outstream);
129 throw std::runtime_error(string("don't know how to write file ") + args.OutfilePath());
134 case Arguments::DUMP: {
135 std::cout << source << std::endl;
138 case Arguments::PLAY:
142 Interpreter intp(source);
145 if (intp.PostponedDefinitions().size() > 0) {
146 for (vector<Interpreter::PostponedDefinition>::const_iterator i(intp.PostponedDefinitions().begin()), end(intp.PostponedDefinitions().end()); i != end; ++i) {
147 std::cerr << "missing definition of " << TypeDescription::Get(i->linkedType).TypeName() << " " << i->identifier << std::endl;
152 int battleResId(TypeDescription::GetTypeId("BattleResources"));
153 int heroId(TypeDescription::GetTypeId("Hero"));
154 int itemId(TypeDescription::GetTypeId("Item"));
155 int monsterId(TypeDescription::GetTypeId("Monster"));
156 int partyLayoutId(TypeDescription::GetTypeId("PartyLayout"));
157 int spellId(TypeDescription::GetTypeId("Spell"));
159 // temporary test data
160 SDL_Surface *bg(IMG_Load("test-data/battle-bg.png"));
161 PartyLayout monstersLayout(*reinterpret_cast<PartyLayout *>(intp.GetObject(partyLayoutId, "monstersLayout")));
162 PartyLayout heroesLayout(*reinterpret_cast<PartyLayout *>(intp.GetObject(partyLayoutId, "heroesLayout")));
164 Monster monster(*reinterpret_cast<Monster *>(intp.GetObject(monsterId, "lizard")));
165 Hero maxim(*reinterpret_cast<Hero *>(intp.GetObject(heroId, "maxim")));
166 Hero selan(*reinterpret_cast<Hero *>(intp.GetObject(heroId, "selan")));
167 Hero guy(*reinterpret_cast<Hero *>(intp.GetObject(heroId, "guy")));
168 Hero dekar(*reinterpret_cast<Hero *>(intp.GetObject(heroId, "dekar")));
170 battle::Resources *battleRes(reinterpret_cast<battle::Resources *>(intp.GetObject(battleResId, "battleResources")));
172 maxim.AddSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "resetSpell")));
173 Spell *strongSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "strongSpell")));
174 maxim.AddSpell(strongSpell);
175 selan.AddSpell(strongSpell);
176 Spell *strongerSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "strongerSpell")));
177 maxim.AddSpell(strongerSpell);
178 selan.AddSpell(strongerSpell);
179 Spell *championSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "championSpell")));
180 maxim.AddSpell(championSpell);
181 selan.AddSpell(championSpell);
182 Spell *rallySpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "rallySpell")));
183 maxim.AddSpell(rallySpell);
184 selan.AddSpell(rallySpell);
185 selan.AddSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "escapeSpell")));
186 Spell *valorSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "valorSpell")));
187 maxim.AddSpell(valorSpell);
188 selan.AddSpell(valorSpell);
191 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "antidoteItem")), 9);
192 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "magicJarItem")), 4);
193 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "hiPotionItem")), 4);
194 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "powerPotionItem")), 4);
195 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "escapeItem")), 2);
196 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "sleepBallItem")), 1);
197 battleRes->inventory = &inventory;
199 maxim.SetWeapon(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoSwordItem")));
200 maxim.SetArmor(reinterpret_cast<Item *>(intp.GetObject(itemId, "zirconArmorItem")));
201 maxim.SetShield(reinterpret_cast<Item *>(intp.GetObject(itemId, "holyShieldItem")));
202 maxim.SetHelmet(reinterpret_cast<Item *>(intp.GetObject(itemId, "legendHelmItem")));
203 maxim.SetRing(reinterpret_cast<Item *>(intp.GetObject(itemId, "sProRingItem")));
204 maxim.SetJewel(reinterpret_cast<Item *>(intp.GetObject(itemId, "evilJewelItem")));
206 // selan.SetWeapon(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoWhipItem")));
207 selan.SetArmor(reinterpret_cast<Item *>(intp.GetObject(itemId, "zirconPlateItem")));
208 selan.SetShield(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoGlovesItem")));
209 selan.SetHelmet(reinterpret_cast<Item *>(intp.GetObject(itemId, "holyCapItem")));
210 selan.SetRing(reinterpret_cast<Item *>(intp.GetObject(itemId, "ghostRingItem")));
211 selan.SetJewel(reinterpret_cast<Item *>(intp.GetObject(itemId, "eagleRockItem")));
213 // guy.SetWeapon(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoAxItem")));
214 guy.SetArmor(reinterpret_cast<Item *>(intp.GetObject(itemId, "zirconArmorItem")));
215 guy.SetShield(reinterpret_cast<Item *>(intp.GetObject(itemId, "megaShieldItem")));
216 guy.SetHelmet(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoHelmetItem")));
217 guy.SetRing(reinterpret_cast<Item *>(intp.GetObject(itemId, "powerRingItem")));
218 guy.SetJewel(reinterpret_cast<Item *>(intp.GetObject(itemId, "evilJewelItem")));
220 // NOTE: this is actually Artea equipment
221 // dekar.SetWeapon(reinterpret_cast<Item *>(intp.GetObject(itemId, "lizardBlowItem")));
222 dekar.SetArmor(reinterpret_cast<Item *>(intp.GetObject(itemId, "holyRobeItem")));
223 dekar.SetShield(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoGlovesItem")));
224 dekar.SetHelmet(reinterpret_cast<Item *>(intp.GetObject(itemId, "holyCapItem")));
225 dekar.SetRing(reinterpret_cast<Item *>(intp.GetObject(itemId, "rocketRingItem")));
226 dekar.SetJewel(reinterpret_cast<Item *>(intp.GetObject(itemId, "krakenRockItem")));
228 InitScreen screen(width, height);
230 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, battleRes));
231 battleState->AddMonster(monster);
232 battleState->AddMonster(monster);
233 battleState->AddMonster(monster);
234 battleState->AddMonster(monster);
235 battleState->AddHero(maxim);
236 battleState->AddHero(selan);
237 battleState->AddHero(guy);
238 battleState->AddHero(dekar);
239 Application app(&screen, battleState);
240 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
241 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
242 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
243 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
244 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
245 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
246 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
247 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
248 app.Buttons().MapKey(SDLK_RETURN, Input::START);
249 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
250 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
251 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
255 } catch (Parser::Error &e) {
256 cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl;
258 } catch (exception &e) {
259 cerr << "exception in main(): " << e.what() << endl;