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 const bool battle(false);
89 // std::srand(std::time(0));
93 InitImage image(IMG_INIT_PNG);
95 battle::Resources::CreateTypeDescription();
96 ComplexAnimation::CreateTypeDescription();
97 Font::CreateTypeDescription();
98 Frame::CreateTypeDescription();
99 Gauge::CreateTypeDescription();
100 Hero::CreateTypeDescription();
101 Ikari::CreateTypeDescription();
102 Interpreter::CreateTypeDescriptions();
103 Item::CreateTypeDescription();
104 graphics::MenuProperties::CreateTypeDescription();
105 Monster::CreateTypeDescription();
106 PartyLayout::CreateTypeDescription();
107 SimpleAnimation::CreateTypeDescription();
108 Spell::CreateTypeDescription();
109 Sprite::CreateTypeDescription();
110 Stats::CreateTypeDescription();
111 common::TargetingMode::CreateTypeDescription();
114 args.Read(argc, argv);
118 for (vector<char *>::const_iterator i(args.Infiles().begin()), end(args.Infiles().end()); i != end; ++i) {
119 Parser(*i, source).Parse();
122 switch (args.DetectRunLevel()) {
123 case Arguments::WRITE:
125 int length(std::strlen(args.OutfilePath()));
126 switch (args.OutfilePath()[length - 1]) {
128 std::ofstream outstream(args.OutfilePath());
129 source.WriteHeader(outstream);
133 throw std::runtime_error(string("don't know how to write file ") + args.OutfilePath());
138 case Arguments::DUMP: {
139 std::cout << source << std::endl;
142 case Arguments::PLAY:
146 Interpreter intp(source);
149 if (intp.PostponedDefinitions().size() > 0) {
150 for (vector<Interpreter::PostponedDefinition>::const_iterator i(intp.PostponedDefinitions().begin()), end(intp.PostponedDefinitions().end()); i != end; ++i) {
151 std::cerr << "missing definition of " << TypeDescription::Get(i->linkedType).TypeName() << " " << i->identifier << std::endl;
158 // temporary test data
159 SDL_Surface *bg(IMG_Load("test-data/battle-bg.png"));
160 PartyLayout monstersLayout(*caster.GetPartyLayout("monstersLayout"));
161 PartyLayout heroesLayout(*caster.GetPartyLayout("heroesLayout"));
163 Monster monster(*caster.GetMonster("lizard"));
164 Hero maxim(*caster.GetHero("maxim"));
165 Hero selan(*caster.GetHero("selan"));
166 Hero guy(*caster.GetHero("guy"));
167 Hero dekar(*caster.GetHero("dekar"));
169 battle::Resources *battleRes(caster.GetBattleResources("battleResources"));
171 maxim.AddSpell(caster.GetSpell("resetSpell"));
172 Spell *strongSpell(caster.GetSpell("strongSpell"));
173 maxim.AddSpell(strongSpell);
174 selan.AddSpell(strongSpell);
175 Spell *strongerSpell(caster.GetSpell("strongerSpell"));
176 maxim.AddSpell(strongerSpell);
177 selan.AddSpell(strongerSpell);
178 Spell *championSpell(caster.GetSpell("championSpell"));
179 maxim.AddSpell(championSpell);
180 selan.AddSpell(championSpell);
181 Spell *rallySpell(caster.GetSpell("rallySpell"));
182 maxim.AddSpell(rallySpell);
183 selan.AddSpell(rallySpell);
184 selan.AddSpell(caster.GetSpell("escapeSpell"));
185 Spell *valorSpell(caster.GetSpell("valorSpell"));
186 maxim.AddSpell(valorSpell);
187 selan.AddSpell(valorSpell);
190 inventory.Add(caster.GetItem("antidoteItem"), 9);
191 inventory.Add(caster.GetItem("magicJarItem"), 4);
192 inventory.Add(caster.GetItem("hiPotionItem"), 4);
193 inventory.Add(caster.GetItem("powerPotionItem"), 4);
194 inventory.Add(caster.GetItem("escapeItem"), 2);
195 inventory.Add(caster.GetItem("sleepBallItem"), 1);
196 battleRes->inventory = &inventory;
198 maxim.SetWeapon(caster.GetItem("zircoSwordItem"));
199 maxim.SetArmor(caster.GetItem("zirconArmorItem"));
200 maxim.SetShield(caster.GetItem("holyShieldItem"));
201 maxim.SetHelmet(caster.GetItem("legendHelmItem"));
202 maxim.SetRing(caster.GetItem("sProRingItem"));
203 maxim.SetJewel(caster.GetItem("evilJewelItem"));
205 // selan.SetWeapon(cst.GetItem("zircoWhipItem"));
206 selan.SetArmor(caster.GetItem("zirconPlateItem"));
207 selan.SetShield(caster.GetItem("zircoGlovesItem"));
208 selan.SetHelmet(caster.GetItem("holyCapItem"));
209 selan.SetRing(caster.GetItem("ghostRingItem"));
210 selan.SetJewel(caster.GetItem("eagleRockItem"));
212 // guy.SetWeapon(cst.GetItem("zircoAxItem"));
213 guy.SetArmor(caster.GetItem("zirconArmorItem"));
214 guy.SetShield(caster.GetItem("megaShieldItem"));
215 guy.SetHelmet(caster.GetItem("zircoHelmetItem"));
216 guy.SetRing(caster.GetItem("powerRingItem"));
217 guy.SetJewel(caster.GetItem("evilJewelItem"));
219 // NOTE: this is actually Artea equipment
220 // dekar.SetWeapon(cst.GetItem("lizardBlowItem"));
221 dekar.SetArmor(caster.GetItem("holyRobeItem"));
222 dekar.SetShield(caster.GetItem("zircoGlovesItem"));
223 dekar.SetHelmet(caster.GetItem("holyCapItem"));
224 dekar.SetRing(caster.GetItem("rocketRingItem"));
225 dekar.SetJewel(caster.GetItem("krakenRockItem"));
227 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);
258 } catch (Parser::Error &e) {
259 cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl;
261 } catch (exception &e) {
262 cerr << "exception in main(): " << e.what() << endl;