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/Caster.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;
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) {
117 Parser(*i, source).Parse();
120 switch (args.DetectRunLevel()) {
121 case Arguments::WRITE:
123 int length(std::strlen(args.OutfilePath()));
124 switch (args.OutfilePath()[length - 1]) {
126 std::ofstream outstream(args.OutfilePath());
127 source.WriteHeader(outstream);
131 throw std::runtime_error(string("don't know how to write file ") + args.OutfilePath());
136 case Arguments::DUMP: {
137 std::cout << source << std::endl;
140 case Arguments::PLAY:
144 Interpreter intp(source);
147 if (intp.PostponedDefinitions().size() > 0) {
148 for (vector<Interpreter::PostponedDefinition>::const_iterator i(intp.PostponedDefinitions().begin()), end(intp.PostponedDefinitions().end()); i != end; ++i) {
149 std::cerr << "missing definition of " << TypeDescription::Get(i->linkedType).TypeName() << " " << i->identifier << std::endl;
156 // temporary test data
157 SDL_Surface *bg(IMG_Load("test-data/battle-bg.png"));
158 PartyLayout monstersLayout(*caster.GetPartyLayout("monstersLayout"));
159 PartyLayout heroesLayout(*caster.GetPartyLayout("heroesLayout"));
161 Monster monster(*caster.GetMonster("lizard"));
162 Hero maxim(*caster.GetHero("maxim"));
163 Hero selan(*caster.GetHero("selan"));
164 Hero guy(*caster.GetHero("guy"));
165 Hero dekar(*caster.GetHero("dekar"));
167 battle::Resources *battleRes(caster.GetBattleResources("battleResources"));
169 maxim.AddSpell(caster.GetSpell("resetSpell"));
170 Spell *strongSpell(caster.GetSpell("strongSpell"));
171 maxim.AddSpell(strongSpell);
172 selan.AddSpell(strongSpell);
173 Spell *strongerSpell(caster.GetSpell("strongerSpell"));
174 maxim.AddSpell(strongerSpell);
175 selan.AddSpell(strongerSpell);
176 Spell *championSpell(caster.GetSpell("championSpell"));
177 maxim.AddSpell(championSpell);
178 selan.AddSpell(championSpell);
179 Spell *rallySpell(caster.GetSpell("rallySpell"));
180 maxim.AddSpell(rallySpell);
181 selan.AddSpell(rallySpell);
182 selan.AddSpell(caster.GetSpell("escapeSpell"));
183 Spell *valorSpell(caster.GetSpell("valorSpell"));
184 maxim.AddSpell(valorSpell);
185 selan.AddSpell(valorSpell);
188 inventory.Add(caster.GetItem("antidoteItem"), 9);
189 inventory.Add(caster.GetItem("magicJarItem"), 4);
190 inventory.Add(caster.GetItem("hiPotionItem"), 4);
191 inventory.Add(caster.GetItem("powerPotionItem"), 4);
192 inventory.Add(caster.GetItem("escapeItem"), 2);
193 inventory.Add(caster.GetItem("sleepBallItem"), 1);
194 battleRes->inventory = &inventory;
196 maxim.SetWeapon(caster.GetItem("zircoSwordItem"));
197 maxim.SetArmor(caster.GetItem("zirconArmorItem"));
198 maxim.SetShield(caster.GetItem("holyShieldItem"));
199 maxim.SetHelmet(caster.GetItem("legendHelmItem"));
200 maxim.SetRing(caster.GetItem("sProRingItem"));
201 maxim.SetJewel(caster.GetItem("evilJewelItem"));
203 // selan.SetWeapon(cst.GetItem("zircoWhipItem"));
204 selan.SetArmor(caster.GetItem("zirconPlateItem"));
205 selan.SetShield(caster.GetItem("zircoGlovesItem"));
206 selan.SetHelmet(caster.GetItem("holyCapItem"));
207 selan.SetRing(caster.GetItem("ghostRingItem"));
208 selan.SetJewel(caster.GetItem("eagleRockItem"));
210 // guy.SetWeapon(cst.GetItem("zircoAxItem"));
211 guy.SetArmor(caster.GetItem("zirconArmorItem"));
212 guy.SetShield(caster.GetItem("megaShieldItem"));
213 guy.SetHelmet(caster.GetItem("zircoHelmetItem"));
214 guy.SetRing(caster.GetItem("powerRingItem"));
215 guy.SetJewel(caster.GetItem("evilJewelItem"));
217 // NOTE: this is actually Artea equipment
218 // dekar.SetWeapon(cst.GetItem("lizardBlowItem"));
219 dekar.SetArmor(caster.GetItem("holyRobeItem"));
220 dekar.SetShield(caster.GetItem("zircoGlovesItem"));
221 dekar.SetHelmet(caster.GetItem("holyCapItem"));
222 dekar.SetRing(caster.GetItem("rocketRingItem"));
223 dekar.SetJewel(caster.GetItem("krakenRockItem"));
225 InitScreen screen(width, height);
227 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, battleRes));
228 battleState->AddMonster(monster);
229 battleState->AddMonster(monster);
230 battleState->AddMonster(monster);
231 battleState->AddMonster(monster);
232 battleState->AddHero(maxim);
233 battleState->AddHero(selan);
234 battleState->AddHero(guy);
235 battleState->AddHero(dekar);
236 Application app(&screen, battleState);
237 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
238 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
239 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
240 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
241 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
242 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
243 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
244 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
245 app.Buttons().MapKey(SDLK_RETURN, Input::START);
246 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
247 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
248 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
252 } catch (Parser::Error &e) {
253 cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl;
255 } catch (exception &e) {
256 cerr << "exception in main(): " << e.what() << endl;