]> git.localhorst.tv Git - l2e.git/blob - src/main.cpp
ff49b66bb578b11a9536fb476abcb7b868d6b75d
[l2e.git] / src / main.cpp
1 /*
2  * main.cpp
3  *
4  *  Created on: Aug 1, 2012
5  *      Author: holy
6  */
7
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 "common/GameState.h"
17 #include "common/Hero.h"
18 #include "common/Ikari.h"
19 #include "common/Inventory.h"
20 #include "common/Item.h"
21 #include "common/Spell.h"
22 #include "common/Stats.h"
23 #include "geometry/Vector.h"
24 #include "graphics/ComplexAnimation.h"
25 #include "graphics/Font.h"
26 #include "graphics/Frame.h"
27 #include "graphics/Gauge.h"
28 #include "graphics/Menu.h"
29 #include "graphics/SimpleAnimation.h"
30 #include "graphics/Sprite.h"
31 #include "loader/Caster.h"
32 #include "loader/Interpreter.h"
33 #include "loader/ParsedSource.h"
34 #include "loader/Parser.h"
35 #include "loader/TypeDescription.h"
36 #include "map/Area.h"
37 #include "map/Entity.h"
38 #include "map/Map.h"
39 #include "map/MapState.h"
40 #include "map/Tile.h"
41 #include "map/Trigger.h"
42 #include "sdl/InitImage.h"
43 #include "sdl/InitScreen.h"
44 #include "sdl/InitSDL.h"
45
46 #include <cstdlib>
47 #include <cstring>
48 #include <ctime>
49 #include <exception>
50 #include <iostream>
51 #include <string>
52 #include <SDL.h>
53 #include <SDL_image.h>
54
55 using app::Application;
56 using app::Arguments;
57 using app::Input;
58 using battle::BattleState;
59 using battle::Monster;
60 using battle::PartyLayout;
61 using common::GameState;
62 using common::Hero;
63 using common::Ikari;
64 using common::Inventory;
65 using common::Item;
66 using common::Spell;
67 using common::Stats;
68 using geometry::Vector;
69 using graphics::ComplexAnimation;
70 using graphics::Font;
71 using graphics::Frame;
72 using graphics::Gauge;
73 using graphics::Menu;
74 using graphics::SimpleAnimation;
75 using graphics::Sprite;
76 using loader::Caster;
77 using loader::Interpreter;
78 using loader::ParsedSource;
79 using loader::Parser;
80 using loader::TypeDescription;
81 using map::Area;
82 using map::Entity;
83 using map::Map;
84 using map::MapState;
85 using map::Tile;
86 using map::Trigger;
87 using sdl::InitImage;
88 using sdl::InitScreen;
89 using sdl::InitSDL;
90
91 using std::cerr;
92 using std::cout;
93 using std::endl;
94 using std::exception;
95 using std::string;
96 using std::vector;
97
98 int main(int argc, char **argv) {
99         const int width = 800;
100         const int height = 480;
101
102         const int tileSize = 32;
103         const float walkSpeed = 128.0f;
104
105         const bool battle(false);
106
107 //      std::srand(std::time(0));
108
109         try {
110                 InitSDL sdl;
111                 InitImage image(IMG_INIT_PNG);
112
113                 battle::Resources::CreateTypeDescription();
114                 ComplexAnimation::CreateTypeDescription();
115                 Font::CreateTypeDescription();
116                 Frame::CreateTypeDescription();
117                 Gauge::CreateTypeDescription();
118                 Hero::CreateTypeDescription();
119                 Ikari::CreateTypeDescription();
120                 Interpreter::CreateTypeDescriptions();
121                 Item::CreateTypeDescription();
122                 graphics::MenuProperties::CreateTypeDescription();
123                 Monster::CreateTypeDescription();
124                 PartyLayout::CreateTypeDescription();
125                 SimpleAnimation::CreateTypeDescription();
126                 Spell::CreateTypeDescription();
127                 Sprite::CreateTypeDescription();
128                 Stats::CreateTypeDescription();
129                 common::TargetingMode::CreateTypeDescription();
130
131                 Arguments args;
132                 args.Read(argc, argv);
133
134                 ParsedSource source;
135
136                 for (vector<char *>::const_iterator i(args.Infiles().begin()), end(args.Infiles().end()); i != end; ++i) {
137                         Parser(*i, source).Parse();
138                 }
139
140                 switch (args.DetectRunLevel()) {
141                         case Arguments::WRITE:
142                         {
143                                 int length(std::strlen(args.OutfilePath()));
144                                 switch (args.OutfilePath()[length - 1]) {
145                                         case 'h': {
146                                                 std::ofstream outstream(args.OutfilePath());
147                                                 source.WriteHeader(outstream);
148                                                 break;
149                                         }
150                                         default: {
151                                                 throw std::runtime_error(string("don't know how to write file ") + args.OutfilePath());
152                                         }
153                                 }
154                                 return 0;
155                         }
156                         case Arguments::DUMP: {
157                                 std::cout << source << std::endl;
158                                 return 0;
159                         }
160                         case Arguments::PLAY:
161                                 break;
162                 }
163
164                 Interpreter intp(source);
165                 intp.ReadSource();
166
167                 if (intp.PostponedDefinitions().size() > 0) {
168                         for (vector<Interpreter::PostponedDefinition>::const_iterator i(intp.PostponedDefinitions().begin()), end(intp.PostponedDefinitions().end()); i != end; ++i) {
169                                 std::cerr << "missing definition of " << TypeDescription::Get(i->linkedType).TypeName() << " " << i->identifier << std::endl;
170                         }
171                         return 3;
172                 }
173
174                 Caster caster(intp);
175
176                 GameState gameState;
177
178                 gameState.heroes[0] = *caster.GetHero("maxim");
179                 gameState.heroes[1] = *caster.GetHero("selan");
180                 gameState.heroes[2] = *caster.GetHero("guy");
181                 gameState.heroes[3] = *caster.GetHero("dekar");
182
183                 gameState.party[0] = &gameState.heroes[0];
184                 gameState.party[1] = &gameState.heroes[1];
185                 gameState.party[2] = &gameState.heroes[2];
186                 gameState.party[3] = &gameState.heroes[3];
187
188                 // temporary test data
189                 SDL_Surface *bg(IMG_Load("test-data/battle-bg.png"));
190                 PartyLayout monstersLayout(*caster.GetPartyLayout("monstersLayout"));
191                 PartyLayout heroesLayout(*caster.GetPartyLayout("heroesLayout"));
192
193                 Monster monster(*caster.GetMonster("lizard"));
194
195                 battle::Resources *battleRes(caster.GetBattleResources("battleResources"));
196
197                 gameState.heroes[0].AddSpell(caster.GetSpell("resetSpell"));
198                 Spell *strongSpell(caster.GetSpell("strongSpell"));
199                 gameState.heroes[0].AddSpell(strongSpell);
200                 gameState.heroes[1].AddSpell(strongSpell);
201                 Spell *strongerSpell(caster.GetSpell("strongerSpell"));
202                 gameState.heroes[0].AddSpell(strongerSpell);
203                 gameState.heroes[1].AddSpell(strongerSpell);
204                 Spell *championSpell(caster.GetSpell("championSpell"));
205                 gameState.heroes[0].AddSpell(championSpell);
206                 gameState.heroes[1].AddSpell(championSpell);
207                 Spell *rallySpell(caster.GetSpell("rallySpell"));
208                 gameState.heroes[0].AddSpell(rallySpell);
209                 gameState.heroes[1].AddSpell(rallySpell);
210                 gameState.heroes[1].AddSpell(caster.GetSpell("escapeSpell"));
211                 Spell *valorSpell(caster.GetSpell("valorSpell"));
212                 gameState.heroes[0].AddSpell(valorSpell);
213                 gameState.heroes[1].AddSpell(valorSpell);
214
215                 Inventory inventory;
216                 inventory.Add(caster.GetItem("antidoteItem"), 9);
217                 inventory.Add(caster.GetItem("magicJarItem"), 4);
218                 inventory.Add(caster.GetItem("hiPotionItem"), 4);
219                 inventory.Add(caster.GetItem("powerPotionItem"), 4);
220                 inventory.Add(caster.GetItem("escapeItem"), 2);
221                 inventory.Add(caster.GetItem("sleepBallItem"), 1);
222                 battleRes->inventory = &inventory;
223
224                 gameState.heroes[0].SetWeapon(caster.GetItem("zircoSwordItem"));
225                 gameState.heroes[0].SetArmor(caster.GetItem("zirconArmorItem"));
226                 gameState.heroes[0].SetShield(caster.GetItem("holyShieldItem"));
227                 gameState.heroes[0].SetHelmet(caster.GetItem("legendHelmItem"));
228                 gameState.heroes[0].SetRing(caster.GetItem("sProRingItem"));
229                 gameState.heroes[0].SetJewel(caster.GetItem("evilJewelItem"));
230
231 //              gameState.heroes[1].SetWeapon(cst.GetItem("zircoWhipItem"));
232                 gameState.heroes[1].SetArmor(caster.GetItem("zirconPlateItem"));
233                 gameState.heroes[1].SetShield(caster.GetItem("zircoGlovesItem"));
234                 gameState.heroes[1].SetHelmet(caster.GetItem("holyCapItem"));
235                 gameState.heroes[1].SetRing(caster.GetItem("ghostRingItem"));
236                 gameState.heroes[1].SetJewel(caster.GetItem("eagleRockItem"));
237
238 //              gameState.heroes[2].SetWeapon(cst.GetItem("zircoAxItem"));
239                 gameState.heroes[2].SetArmor(caster.GetItem("zirconArmorItem"));
240                 gameState.heroes[2].SetShield(caster.GetItem("megaShieldItem"));
241                 gameState.heroes[2].SetHelmet(caster.GetItem("zircoHelmetItem"));
242                 gameState.heroes[2].SetRing(caster.GetItem("powerRingItem"));
243                 gameState.heroes[2].SetJewel(caster.GetItem("evilJewelItem"));
244
245                 // NOTE: this is actually Artea equipment
246 //              gameState.heroes[3].SetWeapon(cst.GetItem("lizardBlowItem"));
247                 gameState.heroes[3].SetArmor(caster.GetItem("holyRobeItem"));
248                 gameState.heroes[3].SetShield(caster.GetItem("zircoGlovesItem"));
249                 gameState.heroes[3].SetHelmet(caster.GetItem("holyCapItem"));
250                 gameState.heroes[3].SetRing(caster.GetItem("rocketRingItem"));
251                 gameState.heroes[3].SetJewel(caster.GetItem("krakenRockItem"));
252
253                 Tile tiles1[64];
254
255                 tiles1[ 0].SetOffset(Vector<int>(2, 1));
256                 tiles1[ 1].SetOffset(Vector<int>(4, 0)).SetFlags(Tile::BLOCK_NORTH | Tile::BLOCK_WEST);
257                 tiles1[ 2].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_NORTH);
258                 tiles1[ 3].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_NORTH | Tile::BLOCK_EAST);
259                 tiles1[ 4].SetOffset(Vector<int>(0, 1));
260                 tiles1[ 5].SetOffset(Vector<int>(2, 0));
261                 tiles1[ 6].SetOffset(Vector<int>(2, 0));
262                 tiles1[ 7].SetOffset(Vector<int>(2, 0));
263
264                 tiles1[ 8].SetOffset(Vector<int>(2, 1));
265                 tiles1[ 9].SetOffset(Vector<int>(4, 0)).SetFlags(Tile::BLOCK_WEST);
266                 tiles1[10].SetOffset(Vector<int>(3, 0));
267                 tiles1[11].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_EAST);
268                 tiles1[12].SetOffset(Vector<int>(0, 2));
269                 tiles1[13].SetOffset(Vector<int>(1, 2));
270                 tiles1[14].SetOffset(Vector<int>(1, 2));
271                 tiles1[15].SetOffset(Vector<int>(1, 2));
272
273                 tiles1[16].SetOffset(Vector<int>(2, 1));
274                 tiles1[17].SetOffset(Vector<int>(4, 0)).SetFlags(Tile::BLOCK_WEST);
275                 tiles1[18].SetOffset(Vector<int>(3, 0));
276                 tiles1[19].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_EAST);
277                 tiles1[20].SetOffset(Vector<int>(0, 3));
278                 tiles1[21].SetOffset(Vector<int>(1, 3));
279                 tiles1[22].SetOffset(Vector<int>(1, 3));
280                 tiles1[23].SetOffset(Vector<int>(2, 3));
281
282                 tiles1[24].SetOffset(Vector<int>(2, 1));
283                 tiles1[25].SetOffset(Vector<int>(4, 0)).SetFlags(Tile::BLOCK_WEST);
284                 tiles1[26].SetOffset(Vector<int>(3, 0));
285                 tiles1[27].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_EAST);
286                 tiles1[28].SetOffset(Vector<int>(0, 4));
287                 tiles1[29].SetOffset(Vector<int>(1, 4));
288                 tiles1[30].SetOffset(Vector<int>(1, 4));
289                 tiles1[31].SetOffset(Vector<int>(2, 4));
290
291                 tiles1[32].SetOffset(Vector<int>(2, 1));
292                 tiles1[33].SetOffset(Vector<int>(4, 0)).SetFlags(Tile::BLOCK_WEST);
293                 tiles1[34].SetOffset(Vector<int>(3, 0));
294                 tiles1[35].SetOffset(Vector<int>(3, 0));
295                 tiles1[36].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_NORTH);
296                 tiles1[37].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_NORTH);
297                 tiles1[38].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_NORTH);
298                 tiles1[39].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_NORTH);
299
300                 tiles1[40].SetOffset(Vector<int>(2, 1));
301                 tiles1[41].SetOffset(Vector<int>(4, 0)).SetFlags(Tile::BLOCK_WEST);
302                 tiles1[42].SetOffset(Vector<int>(3, 0));
303                 tiles1[43].SetOffset(Vector<int>(3, 0));
304                 tiles1[44].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_SOUTH);
305                 tiles1[45].SetOffset(Vector<int>(4, 0)).SetFlags(Tile::BLOCK_SOUTH);
306                 tiles1[46].SetOffset(Vector<int>(4, 0)).SetFlags(Tile::BLOCK_SOUTH);
307                 tiles1[47].SetOffset(Vector<int>(4, 0)).SetFlags(Tile::BLOCK_SOUTH);
308
309                 tiles1[48].SetOffset(Vector<int>(2, 1));
310                 tiles1[49].SetOffset(Vector<int>(4, 0)).SetFlags(Tile::BLOCK_WEST);
311                 tiles1[50].SetOffset(Vector<int>(3, 0));
312                 tiles1[51].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_EAST);
313                 tiles1[52].SetOffset(Vector<int>(0, 0));
314                 tiles1[53].SetOffset(Vector<int>(1, 0));
315                 tiles1[54].SetOffset(Vector<int>(1, 0));
316                 tiles1[55].SetOffset(Vector<int>(1, 0));
317
318                 tiles1[56].SetOffset(Vector<int>(2, 1));
319                 tiles1[57].SetOffset(Vector<int>(4, 0)).SetFlags(Tile::BLOCK_SOUTH | Tile::BLOCK_WEST);
320                 tiles1[58].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_SOUTH);
321                 tiles1[59].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_SOUTH | Tile::BLOCK_EAST);
322                 tiles1[60].SetOffset(Vector<int>(0, 1));
323                 tiles1[61].SetOffset(Vector<int>(1, 1));
324                 tiles1[62].SetOffset(Vector<int>(1, 1));
325                 tiles1[63].SetOffset(Vector<int>(1, 1));
326
327                 Tile tiles2[64];
328
329                 tiles2[ 0].SetOffset(Vector<int>(2, 0));
330                 tiles2[ 1].SetOffset(Vector<int>(2, 0));
331                 tiles2[ 2].SetOffset(Vector<int>(2, 0));
332                 tiles2[ 3].SetOffset(Vector<int>(2, 0));
333                 tiles2[ 4].SetOffset(Vector<int>(2, 0));
334                 tiles2[ 5].SetOffset(Vector<int>(2, 0));
335                 tiles2[ 6].SetOffset(Vector<int>(2, 0));
336                 tiles2[ 7].SetOffset(Vector<int>(2, 0));
337
338                 tiles2[ 8].SetOffset(Vector<int>(1, 2));
339                 tiles2[ 9].SetOffset(Vector<int>(1, 2));
340                 tiles2[10].SetOffset(Vector<int>(5, 3));
341                 tiles2[11].SetOffset(Vector<int>(2, 0));
342                 tiles2[12].SetOffset(Vector<int>(2, 0));
343                 tiles2[13].SetOffset(Vector<int>(2, 0));
344                 tiles2[14].SetOffset(Vector<int>(2, 0));
345                 tiles2[15].SetOffset(Vector<int>(2, 0));
346
347                 tiles2[16].SetOffset(Vector<int>(3, 3));
348                 tiles2[17].SetOffset(Vector<int>(0, 3));
349                 tiles2[18].SetOffset(Vector<int>(0, 1));
350                 tiles2[19].SetOffset(Vector<int>(2, 0));
351                 tiles2[20].SetOffset(Vector<int>(2, 0));
352                 tiles2[21].SetOffset(Vector<int>(2, 0));
353                 tiles2[22].SetOffset(Vector<int>(2, 0));
354                 tiles2[23].SetOffset(Vector<int>(2, 0));
355
356                 tiles2[24].SetOffset(Vector<int>(3, 4)).SetFlags(Tile::BLOCK_NORTH | Tile::BLOCK_EAST | Tile::BLOCK_WEST);
357                 tiles2[25].SetOffset(Vector<int>(0, 4));
358                 tiles2[26].SetOffset(Vector<int>(0, 1));
359                 tiles2[27].SetOffset(Vector<int>(2, 0));
360                 tiles2[28].SetOffset(Vector<int>(2, 0));
361                 tiles2[29].SetOffset(Vector<int>(2, 0));
362                 tiles2[30].SetOffset(Vector<int>(2, 0));
363                 tiles2[31].SetOffset(Vector<int>(2, 0));
364
365                 tiles2[32].SetOffset(Vector<int>(5, 0));
366                 tiles2[33].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_NORTH | Tile::BLOCK_EAST);
367                 tiles2[34].SetOffset(Vector<int>(0, 1));
368                 tiles2[35].SetOffset(Vector<int>(2, 0));
369                 tiles2[36].SetOffset(Vector<int>(2, 0));
370                 tiles2[37].SetOffset(Vector<int>(2, 0));
371                 tiles2[38].SetOffset(Vector<int>(2, 0));
372                 tiles2[39].SetOffset(Vector<int>(2, 0));
373
374                 tiles2[40].SetOffset(Vector<int>(4, 0)).SetFlags(Tile::BLOCK_SOUTH);
375                 tiles2[41].SetOffset(Vector<int>(4, 0)).SetFlags(Tile::BLOCK_SOUTH | Tile::BLOCK_EAST);
376                 tiles2[42].SetOffset(Vector<int>(0, 1));
377                 tiles2[43].SetOffset(Vector<int>(2, 0));
378                 tiles2[44].SetOffset(Vector<int>(2, 0));
379                 tiles2[45].SetOffset(Vector<int>(2, 0));
380                 tiles2[46].SetOffset(Vector<int>(2, 0));
381                 tiles2[47].SetOffset(Vector<int>(2, 0));
382
383                 tiles2[48].SetOffset(Vector<int>(1, 0));
384                 tiles2[49].SetOffset(Vector<int>(1, 0));
385                 tiles2[50].SetOffset(Vector<int>(5, 4));
386                 tiles2[51].SetOffset(Vector<int>(2, 0));
387                 tiles2[52].SetOffset(Vector<int>(2, 0));
388                 tiles2[53].SetOffset(Vector<int>(2, 0));
389                 tiles2[54].SetOffset(Vector<int>(2, 0));
390                 tiles2[55].SetOffset(Vector<int>(2, 0));
391
392                 tiles2[56].SetOffset(Vector<int>(2, 0));
393                 tiles2[57].SetOffset(Vector<int>(2, 0));
394                 tiles2[58].SetOffset(Vector<int>(2, 0));
395                 tiles2[59].SetOffset(Vector<int>(2, 0));
396                 tiles2[60].SetOffset(Vector<int>(2, 0));
397                 tiles2[61].SetOffset(Vector<int>(2, 0));
398                 tiles2[62].SetOffset(Vector<int>(2, 0));
399                 tiles2[63].SetOffset(Vector<int>(2, 0));
400
401                 Area areas1[2];
402                 areas1[0].SetTiles(tiles1, 64);
403                 areas1[0].SetWidth(8);
404                 areas1[1].SetTiles(tiles2, 64);
405                 areas1[1].SetWidth(8);
406
407                 Trigger triggers1[1];
408                 triggers1[0].SetTilePosition(Vector<int>(8, 3));
409
410                 SDL_Surface *tilesetImg(IMG_Load("test-data/tileset.png"));
411                 Sprite tileset(tilesetImg, tileSize, tileSize);
412
413                 Map map1;
414                 map1.SetAreas(areas1, 2);
415                 map1.SetTileset(&tileset);
416                 map1.SetTriggers(triggers1, 1);
417                 map1.SetWidth(2);
418
419                 Tile tiles3[64];
420
421                 tiles3[ 0].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_NORTH | Tile::BLOCK_WEST);
422                 tiles3[ 1].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_NORTH);
423                 tiles3[ 2].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_NORTH);
424                 tiles3[ 3].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_NORTH);
425                 tiles3[ 4].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_NORTH);
426                 tiles3[ 5].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_NORTH);
427                 tiles3[ 6].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_NORTH);
428                 tiles3[ 7].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_NORTH | Tile::BLOCK_EAST);
429
430                 tiles3[ 8].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_WEST);
431                 tiles3[ 9].SetOffset(Vector<int>(3, 0));
432                 tiles3[10].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_SOUTH);
433                 tiles3[11].SetOffset(Vector<int>(4, 0)).SetFlags(Tile::BLOCK_SOUTH);
434                 tiles3[12].SetOffset(Vector<int>(4, 0)).SetFlags(Tile::BLOCK_SOUTH);
435                 tiles3[13].SetOffset(Vector<int>(4, 0)).SetFlags(Tile::BLOCK_SOUTH);
436                 tiles3[14].SetOffset(Vector<int>(4, 0));
437                 tiles3[15].SetOffset(Vector<int>(4, 0)).SetFlags(Tile::BLOCK_EAST | Tile::BLOCK_SOUTH);
438
439                 tiles3[16].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_WEST);
440                 tiles3[17].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_EAST);
441                 tiles3[18].SetOffset(Vector<int>(0, 0));
442                 tiles3[19].SetOffset(Vector<int>(1, 0));
443                 tiles3[20].SetOffset(Vector<int>(1, 0));
444                 tiles3[21].SetOffset(Vector<int>(3, 2));
445                 tiles3[22].SetOffset(Vector<int>(4, 2)).SetFlags(Tile::BLOCK_EAST | Tile::BLOCK_SOUTH | Tile::BLOCK_WEST);
446                 tiles3[23].SetOffset(Vector<int>(5, 2));
447
448                 tiles3[24].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_WEST);
449                 tiles3[25].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_EAST);
450                 tiles3[26].SetOffset(Vector<int>(0, 1));
451                 tiles3[27].SetOffset(Vector<int>(2, 0));
452                 tiles3[28].SetOffset(Vector<int>(2, 0));
453                 tiles3[29].SetOffset(Vector<int>(1, 2));
454                 tiles3[30].SetOffset(Vector<int>(1, 2));
455                 tiles3[31].SetOffset(Vector<int>(1, 2));
456
457                 tiles3[32].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_WEST);
458                 tiles3[33].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_EAST);
459                 tiles3[34].SetOffset(Vector<int>(0, 1));
460                 tiles3[35].SetOffset(Vector<int>(2, 0));
461                 tiles3[36].SetOffset(Vector<int>(2, 0));
462                 tiles3[37].SetOffset(Vector<int>(2, 3));
463                 tiles3[38].SetOffset(Vector<int>(3, 3));
464                 tiles3[39].SetOffset(Vector<int>(0, 3));
465
466                 tiles3[40].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_WEST);
467                 tiles3[41].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_EAST);
468                 tiles3[42].SetOffset(Vector<int>(0, 1));
469                 tiles3[43].SetOffset(Vector<int>(2, 0));
470                 tiles3[44].SetOffset(Vector<int>(2, 0));
471                 tiles3[45].SetOffset(Vector<int>(2, 4));
472                 tiles3[46].SetOffset(Vector<int>(3, 4));
473                 tiles3[47].SetOffset(Vector<int>(0, 4));
474
475                 tiles3[48].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_WEST);
476                 tiles3[49].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_EAST);
477                 tiles3[50].SetOffset(Vector<int>(0, 1));
478                 tiles3[51].SetOffset(Vector<int>(2, 0));
479                 tiles3[52].SetOffset(Vector<int>(2, 0));
480                 tiles3[53].SetOffset(Vector<int>(4, 1));
481                 tiles3[54].SetOffset(Vector<int>(5, 1));
482                 tiles3[55].SetOffset(Vector<int>(3, 1));
483
484                 tiles3[56].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_SOUTH | Tile::BLOCK_WEST);
485                 tiles3[57].SetOffset(Vector<int>(3, 0)).SetFlags(Tile::BLOCK_EAST | Tile::BLOCK_SOUTH);
486                 tiles3[58].SetOffset(Vector<int>(0, 1));
487                 tiles3[59].SetOffset(Vector<int>(2, 0));
488                 tiles3[60].SetOffset(Vector<int>(2, 0));
489                 tiles3[61].SetOffset(Vector<int>(2, 0));
490                 tiles3[62].SetOffset(Vector<int>(2, 0));
491                 tiles3[63].SetOffset(Vector<int>(2, 0));
492
493                 Area areas2[1];
494                 areas2[0].SetTiles(tiles3, 64);
495                 areas2[0].SetWidth(8);
496
497                 Trigger triggers2[1];
498                 triggers2[0].SetTilePosition(Vector<int>(6, 2));
499
500                 Map map2;
501                 map2.SetAreas(areas2, 1);
502                 map2.SetTileset(&tileset);
503                 map2.SetTriggers(triggers2, 1);
504                 map2.SetWidth(1);
505
506                 triggers1[0].map = &map2;
507                 triggers1[0].target = Vector<int>(6, 2);
508
509                 triggers2[0].map = &map1;
510                 triggers2[0].target = Vector<int>(8, 3);
511
512                 SimpleAnimation mapMaximAnimation(gameState.heroes[0].MapSprite(), (tileSize/walkSpeed) / 2 * 1000, 2, 0, 0, true);
513                 Entity mapMaxim;
514                 mapMaxim.SetAnimation(&mapMaximAnimation);
515                 mapMaxim.Position() = Vector<float>(64, 128);
516                 mapMaxim.SpriteOffset() = Vector<float>(0, -32);
517
518                 SimpleAnimation mapSelanAnimation(gameState.heroes[1].MapSprite(), (tileSize/walkSpeed) / 2 * 1000, 2, 0, 0, true);
519                 Entity mapSelan;
520                 mapSelan.SetAnimation(&mapSelanAnimation);
521                 mapSelan.Position() = Vector<float>(64, 128);
522                 mapSelan.SpriteOffset() = Vector<float>(0, -32);
523                 mapSelan.SetFlags(Entity::FLAG_NONBLOCKING);
524                 mapMaxim.AddFollower(&mapSelan);
525
526                 SimpleAnimation mapGuyAnimation(gameState.heroes[2].MapSprite(), (tileSize/walkSpeed) / 2 * 1000, 2, 0, 0, true);
527                 Entity mapGuy;
528                 mapGuy.SetAnimation(&mapGuyAnimation);
529                 mapGuy.Position() = Vector<float>(64, 128);
530                 mapGuy.SpriteOffset() = Vector<float>(0, -32);
531                 mapGuy.SetFlags(Entity::FLAG_NONBLOCKING);
532                 mapSelan.AddFollower(&mapGuy);
533
534                 SimpleAnimation mapDekarAnimation(gameState.heroes[3].MapSprite(), (tileSize/walkSpeed) / 2 * 1000, 2, 0, 0, true);
535                 Entity mapDekar;
536                 mapDekar.SetAnimation(&mapDekarAnimation);
537                 mapDekar.Position() = Vector<float>(64, 128);
538                 mapDekar.SpriteOffset() = Vector<float>(0, -32);
539                 mapDekar.SetFlags(Entity::FLAG_NONBLOCKING);
540                 mapGuy.AddFollower(&mapDekar);
541
542                 SDL_Surface *mapMonsterImg(IMG_Load("test-data/monster-map.png"));
543                 Sprite mapMonsterSprite(mapMonsterImg, 32, 32);
544                 SimpleAnimation mapMonsterAnimation(&mapMonsterSprite, 500, 2, 0, 0, true);
545                 Entity mapMonster;
546                 mapMonster.SetAnimation(&mapMonsterAnimation);
547                 mapMonster.Position() = Vector<float>(64, 32);
548                 mapMonster.SetOrientation(Entity::ORIENTATION_SOUTH);
549                 map1.SetEntities(&mapMonster, 1);
550
551                 InitScreen screen(width, height);
552
553                 app::State *state(0);
554
555                 if (battle) {
556                         BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, battleRes));
557                         battleState->AddMonster(monster);
558                         battleState->AddMonster(monster);
559                         battleState->AddMonster(monster);
560                         battleState->AddMonster(monster);
561                         battleState->AddHero(gameState.heroes[0]);
562                         battleState->AddHero(gameState.heroes[1]);
563                         battleState->AddHero(gameState.heroes[2]);
564                         battleState->AddHero(gameState.heroes[3]);
565                         state = battleState;
566                 } else {
567                         MapState *mapState(new MapState(&map1));
568
569                         mapState->ControlEntity(&mapMaxim);
570                         mapState->SetWalkingSpeed(walkSpeed);
571                         mapMonster.StartAnimation(*mapState);
572
573                         state = mapState;
574                 }
575
576                 Application app(&screen, state);
577                 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
578                 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
579                 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
580                 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
581                 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
582                 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
583                 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
584                 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
585                 app.Buttons().MapKey(SDLK_RETURN, Input::START);
586                 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
587                 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
588                 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
589                 app.Buttons().MapKey(SDLK_1, Input::DEBUG_1);
590                 app.Buttons().MapKey(SDLK_2, Input::DEBUG_2);
591                 app.Buttons().MapKey(SDLK_3, Input::DEBUG_3);
592                 app.Buttons().MapKey(SDLK_4, Input::DEBUG_4);
593                 app.Run();
594
595                 return 0;
596         } catch (Parser::Error &e) {
597                 cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl;
598                 return 2;
599         } catch (exception &e) {
600                 cerr << "exception in main(): " << e.what() << endl;
601                 return 1;
602         }
603 }