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"
36 #include "map/MapState.h"
38 #include "sdl/InitImage.h"
39 #include "sdl/InitScreen.h"
40 #include "sdl/InitSDL.h"
49 #include <SDL_image.h>
51 using app::Application;
54 using battle::BattleState;
56 using battle::Monster;
57 using battle::PartyLayout;
60 using common::Inventory;
63 using geometry::Vector;
64 using graphics::ComplexAnimation;
66 using graphics::Frame;
67 using graphics::Gauge;
69 using graphics::SimpleAnimation;
70 using graphics::Sprite;
72 using loader::Interpreter;
73 using loader::ParsedSource;
75 using loader::TypeDescription;
81 using sdl::InitScreen;
91 int main(int argc, char **argv) {
92 const int width = 800;
93 const int height = 480;
95 const bool battle(false);
97 // std::srand(std::time(0));
101 InitImage image(IMG_INIT_PNG);
103 battle::Resources::CreateTypeDescription();
104 ComplexAnimation::CreateTypeDescription();
105 Font::CreateTypeDescription();
106 Frame::CreateTypeDescription();
107 Gauge::CreateTypeDescription();
108 Hero::CreateTypeDescription();
109 Ikari::CreateTypeDescription();
110 Interpreter::CreateTypeDescriptions();
111 Item::CreateTypeDescription();
112 graphics::MenuProperties::CreateTypeDescription();
113 Monster::CreateTypeDescription();
114 PartyLayout::CreateTypeDescription();
115 SimpleAnimation::CreateTypeDescription();
116 Spell::CreateTypeDescription();
117 Sprite::CreateTypeDescription();
118 Stats::CreateTypeDescription();
119 common::TargetingMode::CreateTypeDescription();
122 args.Read(argc, argv);
126 for (vector<char *>::const_iterator i(args.Infiles().begin()), end(args.Infiles().end()); i != end; ++i) {
127 Parser(*i, source).Parse();
130 switch (args.DetectRunLevel()) {
131 case Arguments::WRITE:
133 int length(std::strlen(args.OutfilePath()));
134 switch (args.OutfilePath()[length - 1]) {
136 std::ofstream outstream(args.OutfilePath());
137 source.WriteHeader(outstream);
141 throw std::runtime_error(string("don't know how to write file ") + args.OutfilePath());
146 case Arguments::DUMP: {
147 std::cout << source << std::endl;
150 case Arguments::PLAY:
154 Interpreter intp(source);
157 if (intp.PostponedDefinitions().size() > 0) {
158 for (vector<Interpreter::PostponedDefinition>::const_iterator i(intp.PostponedDefinitions().begin()), end(intp.PostponedDefinitions().end()); i != end; ++i) {
159 std::cerr << "missing definition of " << TypeDescription::Get(i->linkedType).TypeName() << " " << i->identifier << std::endl;
166 // temporary test data
167 SDL_Surface *bg(IMG_Load("test-data/battle-bg.png"));
168 PartyLayout monstersLayout(*caster.GetPartyLayout("monstersLayout"));
169 PartyLayout heroesLayout(*caster.GetPartyLayout("heroesLayout"));
171 Monster monster(*caster.GetMonster("lizard"));
172 Hero maxim(*caster.GetHero("maxim"));
173 Hero selan(*caster.GetHero("selan"));
174 Hero guy(*caster.GetHero("guy"));
175 Hero dekar(*caster.GetHero("dekar"));
177 battle::Resources *battleRes(caster.GetBattleResources("battleResources"));
179 maxim.AddSpell(caster.GetSpell("resetSpell"));
180 Spell *strongSpell(caster.GetSpell("strongSpell"));
181 maxim.AddSpell(strongSpell);
182 selan.AddSpell(strongSpell);
183 Spell *strongerSpell(caster.GetSpell("strongerSpell"));
184 maxim.AddSpell(strongerSpell);
185 selan.AddSpell(strongerSpell);
186 Spell *championSpell(caster.GetSpell("championSpell"));
187 maxim.AddSpell(championSpell);
188 selan.AddSpell(championSpell);
189 Spell *rallySpell(caster.GetSpell("rallySpell"));
190 maxim.AddSpell(rallySpell);
191 selan.AddSpell(rallySpell);
192 selan.AddSpell(caster.GetSpell("escapeSpell"));
193 Spell *valorSpell(caster.GetSpell("valorSpell"));
194 maxim.AddSpell(valorSpell);
195 selan.AddSpell(valorSpell);
198 inventory.Add(caster.GetItem("antidoteItem"), 9);
199 inventory.Add(caster.GetItem("magicJarItem"), 4);
200 inventory.Add(caster.GetItem("hiPotionItem"), 4);
201 inventory.Add(caster.GetItem("powerPotionItem"), 4);
202 inventory.Add(caster.GetItem("escapeItem"), 2);
203 inventory.Add(caster.GetItem("sleepBallItem"), 1);
204 battleRes->inventory = &inventory;
206 maxim.SetWeapon(caster.GetItem("zircoSwordItem"));
207 maxim.SetArmor(caster.GetItem("zirconArmorItem"));
208 maxim.SetShield(caster.GetItem("holyShieldItem"));
209 maxim.SetHelmet(caster.GetItem("legendHelmItem"));
210 maxim.SetRing(caster.GetItem("sProRingItem"));
211 maxim.SetJewel(caster.GetItem("evilJewelItem"));
213 // selan.SetWeapon(cst.GetItem("zircoWhipItem"));
214 selan.SetArmor(caster.GetItem("zirconPlateItem"));
215 selan.SetShield(caster.GetItem("zircoGlovesItem"));
216 selan.SetHelmet(caster.GetItem("holyCapItem"));
217 selan.SetRing(caster.GetItem("ghostRingItem"));
218 selan.SetJewel(caster.GetItem("eagleRockItem"));
220 // guy.SetWeapon(cst.GetItem("zircoAxItem"));
221 guy.SetArmor(caster.GetItem("zirconArmorItem"));
222 guy.SetShield(caster.GetItem("megaShieldItem"));
223 guy.SetHelmet(caster.GetItem("zircoHelmetItem"));
224 guy.SetRing(caster.GetItem("powerRingItem"));
225 guy.SetJewel(caster.GetItem("evilJewelItem"));
227 // NOTE: this is actually Artea equipment
228 // dekar.SetWeapon(cst.GetItem("lizardBlowItem"));
229 dekar.SetArmor(caster.GetItem("holyRobeItem"));
230 dekar.SetShield(caster.GetItem("zircoGlovesItem"));
231 dekar.SetHelmet(caster.GetItem("holyCapItem"));
232 dekar.SetRing(caster.GetItem("rocketRingItem"));
233 dekar.SetJewel(caster.GetItem("krakenRockItem"));
237 tiles[ 0].SetOffset(Vector<int>(2, 1));
238 tiles[ 1].SetOffset(Vector<int>(4, 0));
239 tiles[ 2].SetOffset(Vector<int>(3, 0));
240 tiles[ 3].SetOffset(Vector<int>(3, 0));
241 tiles[ 4].SetOffset(Vector<int>(0, 1));
242 tiles[ 5].SetOffset(Vector<int>(2, 0));
243 tiles[ 6].SetOffset(Vector<int>(2, 0));
244 tiles[ 7].SetOffset(Vector<int>(2, 0));
246 tiles[ 8].SetOffset(Vector<int>(2, 1));
247 tiles[ 9].SetOffset(Vector<int>(4, 0));
248 tiles[10].SetOffset(Vector<int>(3, 0));
249 tiles[11].SetOffset(Vector<int>(3, 0));
250 tiles[12].SetOffset(Vector<int>(0, 2));
251 tiles[13].SetOffset(Vector<int>(1, 2));
252 tiles[14].SetOffset(Vector<int>(1, 2));
253 tiles[15].SetOffset(Vector<int>(1, 2));
255 tiles[16].SetOffset(Vector<int>(2, 1));
256 tiles[17].SetOffset(Vector<int>(4, 0));
257 tiles[18].SetOffset(Vector<int>(3, 0));
258 tiles[19].SetOffset(Vector<int>(3, 0));
259 tiles[20].SetOffset(Vector<int>(0, 3));
260 tiles[21].SetOffset(Vector<int>(1, 3));
261 tiles[22].SetOffset(Vector<int>(1, 3));
262 tiles[23].SetOffset(Vector<int>(2, 3));
264 tiles[24].SetOffset(Vector<int>(2, 1));
265 tiles[25].SetOffset(Vector<int>(4, 0));
266 tiles[26].SetOffset(Vector<int>(3, 0));
267 tiles[27].SetOffset(Vector<int>(3, 0));
268 tiles[28].SetOffset(Vector<int>(0, 4));
269 tiles[29].SetOffset(Vector<int>(1, 4));
270 tiles[30].SetOffset(Vector<int>(1, 4));
271 tiles[31].SetOffset(Vector<int>(2, 4));
273 tiles[32].SetOffset(Vector<int>(2, 1));
274 tiles[33].SetOffset(Vector<int>(4, 0));
275 tiles[34].SetOffset(Vector<int>(3, 0));
276 tiles[35].SetOffset(Vector<int>(3, 0));
277 tiles[36].SetOffset(Vector<int>(3, 0));
278 tiles[37].SetOffset(Vector<int>(3, 0));
279 tiles[38].SetOffset(Vector<int>(3, 0));
280 tiles[39].SetOffset(Vector<int>(3, 0));
282 tiles[40].SetOffset(Vector<int>(2, 1));
283 tiles[41].SetOffset(Vector<int>(4, 0));
284 tiles[42].SetOffset(Vector<int>(3, 0));
285 tiles[43].SetOffset(Vector<int>(3, 0));
286 tiles[44].SetOffset(Vector<int>(3, 0));
287 tiles[45].SetOffset(Vector<int>(4, 0));
288 tiles[46].SetOffset(Vector<int>(4, 0));
289 tiles[47].SetOffset(Vector<int>(4, 0));
291 tiles[48].SetOffset(Vector<int>(2, 1));
292 tiles[49].SetOffset(Vector<int>(4, 0));
293 tiles[50].SetOffset(Vector<int>(3, 0));
294 tiles[51].SetOffset(Vector<int>(3, 0));
295 tiles[52].SetOffset(Vector<int>(0, 0));
296 tiles[53].SetOffset(Vector<int>(1, 0));
297 tiles[54].SetOffset(Vector<int>(1, 0));
298 tiles[55].SetOffset(Vector<int>(1, 0));
300 tiles[56].SetOffset(Vector<int>(2, 1));
301 tiles[57].SetOffset(Vector<int>(4, 0));
302 tiles[58].SetOffset(Vector<int>(3, 0));
303 tiles[59].SetOffset(Vector<int>(3, 0));
304 tiles[60].SetOffset(Vector<int>(0, 1));
305 tiles[61].SetOffset(Vector<int>(1, 1));
306 tiles[62].SetOffset(Vector<int>(1, 1));
307 tiles[63].SetOffset(Vector<int>(1, 1));
310 area.SetTiles(tiles, 64);
313 SDL_Surface *tilesetImg(IMG_Load("test-data/tileset.png"));
314 Sprite tileset(tilesetImg, 32, 32);
317 map.SetAreas(&area, 1);
318 map.SetTileset(&tileset);
321 InitScreen screen(width, height);
323 app::State *state(0);
326 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, battleRes));
327 battleState->AddMonster(monster);
328 battleState->AddMonster(monster);
329 battleState->AddMonster(monster);
330 battleState->AddMonster(monster);
331 battleState->AddHero(maxim);
332 battleState->AddHero(selan);
333 battleState->AddHero(guy);
334 battleState->AddHero(dekar);
337 MapState *mapState(new MapState(&map));
341 Application app(&screen, state);
342 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
343 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
344 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
345 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
346 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
347 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
348 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
349 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
350 app.Buttons().MapKey(SDLK_RETURN, Input::START);
351 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
352 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
353 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
357 } catch (Parser::Error &e) {
358 cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl;
360 } catch (exception &e) {
361 cerr << "exception in main(): " << e.what() << endl;