]> git.localhorst.tv Git - l2e.git/blob - src/main.cpp
7a8b425d1a8bea52ddb3f302556f8c1ca5923d3e
[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/Input.h"
10 #include "battle/BattleState.h"
11 #include "battle/Hero.h"
12 #include "battle/Monster.h"
13 #include "battle/PartyLayout.h"
14 #include "battle/Resources.h"
15 #include "battle/Stats.h"
16 #include "common/Ikari.h"
17 #include "common/Inventory.h"
18 #include "common/Item.h"
19 #include "common/Spell.h"
20 #include "geometry/Vector.h"
21 #include "graphics/ComplexAnimation.h"
22 #include "graphics/Font.h"
23 #include "graphics/Frame.h"
24 #include "graphics/Gauge.h"
25 #include "graphics/Menu.h"
26 #include "graphics/SimpleAnimation.h"
27 #include "graphics/Sprite.h"
28 #include "loader/Interpreter.h"
29 #include "loader/ParsedSource.h"
30 #include "loader/Parser.h"
31 #include "sdl/InitImage.h"
32 #include "sdl/InitScreen.h"
33 #include "sdl/InitSDL.h"
34
35 #include <cstdlib>
36 #include <ctime>
37 #include <exception>
38 #include <iostream>
39 #include <SDL.h>
40 #include <SDL_image.h>
41
42 using app::Application;
43 using app::Input;
44 using battle::BattleState;
45 using battle::Hero;
46 using battle::Monster;
47 using battle::PartyLayout;
48 using battle::Stats;
49 using common::Ikari;
50 using common::Inventory;
51 using common::Item;
52 using common::Spell;
53 using geometry::Vector;
54 using graphics::ComplexAnimation;
55 using graphics::Font;
56 using graphics::Frame;
57 using graphics::Gauge;
58 using graphics::Menu;
59 using graphics::SimpleAnimation;
60 using graphics::Sprite;
61 using loader::Interpreter;
62 using loader::ParsedSource;
63 using loader::Parser;
64 using sdl::InitImage;
65 using sdl::InitScreen;
66 using sdl::InitSDL;
67
68 using std::cerr;
69 using std::cout;
70 using std::endl;
71 using std::exception;
72
73 int main(int argc, char **argv) {
74         const int width = 800;
75         const int height = 480;
76
77         const int framerate = 33;
78
79 //      std::srand(std::time(0));
80
81         try {
82                 ParsedSource source;
83                 Parser parser("test-data/test.l2s", source);
84                 parser.Parse();
85                 cout << source;
86                 Interpreter intp(source);
87                 intp.ReadSource();
88
89                 return 0;
90
91                 InitSDL sdl;
92                 InitImage image(IMG_INIT_PNG);
93                 InitScreen screen(width, height);
94
95                 // temporary test data
96                 SDL_Surface *bg(IMG_Load("test-data/battle-bg.png"));
97                 PartyLayout monstersLayout;
98                 monstersLayout.AddPosition(Vector<Uint8>(88, 88));
99                 monstersLayout.AddPosition(Vector<Uint8>(128, 88));
100                 monstersLayout.AddPosition(Vector<Uint8>(168, 88));
101                 monstersLayout.AddPosition(Vector<Uint8>(208, 88));
102                 PartyLayout heroesLayout;
103                 heroesLayout.AddPosition(Vector<Uint8>(48, 136));
104                 heroesLayout.AddPosition(Vector<Uint8>(128, 136));
105                 heroesLayout.AddPosition(Vector<Uint8>(80, 152));
106                 heroesLayout.AddPosition(Vector<Uint8>(160, 152));
107
108                 SDL_Surface *monsterImg(IMG_Load("test-data/monster.png"));
109                 Sprite monsterSprite(monsterImg, 64, 64);
110                 Monster monster;
111                 monster.SetName("Lizard");
112                 monster.SetSprite(&monsterSprite);
113                 monster.SetLevel(1);
114                 monster.SetMaxHealth(8);
115                 monster.SetHealth(8);
116                 monster.SetStats(Stats(14, 6, 6, 6, 6, 6, 6));
117                 monster.SetReward(3, 5);
118                 ComplexAnimation monsterAttackAnimation(&monsterSprite, 4 * framerate);
119                 monsterAttackAnimation.AddFrame(0, 1, Vector<int>(0, 16));
120                 monsterAttackAnimation.AddFrame(0, 0, Vector<int>(0, 16));
121                 monsterAttackAnimation.AddFrame(0, 1, Vector<int>(0, 16));
122                 monster.SetAttackAnimation(&monsterAttackAnimation);
123                 SDL_Surface *monsterMeleeImg(IMG_Load("test-data/attack-monster.png"));
124                 Sprite monsterMeleeSprite(monsterMeleeImg, 96, 64);
125                 SimpleAnimation monsterMeleeAnimation(&monsterMeleeSprite, framerate, 14);
126                 monster.SetMeleeAnimation(&monsterMeleeAnimation);
127
128                 SDL_Surface *maximImg(IMG_Load("test-data/maxim.png"));
129                 Sprite maximSprite(maximImg, 64, 64);
130                 Hero maxim;
131                 maxim.SetName("Maxim");
132                 maxim.SetLevel(1);
133                 maxim.SetSprite(&maximSprite);
134                 maxim.SetMaxHealth(33);
135                 maxim.SetHealth(33);
136                 maxim.SetMaxMana(20);
137                 maxim.SetMana(20);
138                 maxim.SetIP(0);
139                 maxim.SetStats(Stats(28, 22, 28, 17, 14, 100, 10));
140                 ComplexAnimation maximAttackAnimation(&maximSprite, framerate);
141                 maximAttackAnimation.AddFrames(1, 0, Vector<int>(0,  0), 7);
142                 maximAttackAnimation.AddFrames(1, 0, Vector<int>(4, -1), 2);
143                 maximAttackAnimation.AddFrames(2, 0, Vector<int>(4, -2), 2);
144                 maximAttackAnimation.AddFrames(2, 0, Vector<int>(6, -2), 2);
145                 maximAttackAnimation.AddFrames(2, 1, Vector<int>(6, -1), 1);
146                 maximAttackAnimation.AddFrames(2, 1, Vector<int>(3, -1), 2);
147                 maximAttackAnimation.AddFrames(2, 1, Vector<int>(0,  0), 1);
148                 maximAttackAnimation.AddFrames(2, 2, Vector<int>(0,  0), 2);
149                 maximAttackAnimation.AddFrames(2, 2, Vector<int>(2,  0), 1);
150                 maximAttackAnimation.AddFrames(1, 0, Vector<int>(0,  0), 7);
151                 maxim.SetAttackAnimation(&maximAttackAnimation);
152                 ComplexAnimation maximSpellAnimation(&maximSprite, 5 * framerate);
153                 maximSpellAnimation.AddFrames(3, 0, Vector<int>(), 2);
154                 maximSpellAnimation.AddFrame(3, 1);
155                 maxim.SetSpellAnimation(&maximSpellAnimation);
156                 SDL_Surface *maximMeleeImg(IMG_Load("test-data/melee-maxim.png"));
157                 Sprite maximMeleeSprite(maximMeleeImg, 96, 96);
158                 SimpleAnimation maximMeleeAnimation(&maximMeleeSprite, 2 * framerate, 4);
159                 maxim.SetMeleeAnimation(&maximMeleeAnimation);
160
161                 SDL_Surface *selanImg(IMG_Load("test-data/selan.png"));
162                 Sprite selanSprite(selanImg, 64, 64);
163                 Hero selan;
164                 selan.SetName("Selan");
165                 selan.SetLevel(1);
166                 selan.SetSprite(&selanSprite);
167                 selan.SetMaxHealth(28);
168                 selan.SetHealth(28);
169                 selan.SetMaxMana(23);
170                 selan.SetMana(23);
171                 selan.SetIP(0);
172                 selan.SetStats(Stats(23, 21, 23, 19, 22, 80, 13));
173                 ComplexAnimation selanAttackAnimation(&selanSprite, framerate);
174                 selanAttackAnimation.AddFrames(1, 0, Vector<int>(4, 0), 2);
175                 selanAttackAnimation.AddFrame(1, 0, Vector<int>(8, 2));
176                 selanAttackAnimation.AddFrame(2, 0, Vector<int>(10, 4));
177                 selanAttackAnimation.AddFrame(2, 0, Vector<int>(14, 4));
178                 selanAttackAnimation.AddFrames(2, 0, Vector<int>(12, 2), 3);
179                 selanAttackAnimation.AddFrames(2, 1, Vector<int>(14, 2), 2);
180                 selanAttackAnimation.AddFrame(2, 1, Vector<int>(2, 0));
181                 selanAttackAnimation.AddFrame(2, 2, Vector<int>(-2, -4));
182                 selanAttackAnimation.AddFrame(2, 2, Vector<int>(-8, -8));
183                 selanAttackAnimation.AddFrame(2, 2);
184                 selan.SetAttackAnimation(&selanAttackAnimation);
185                 ComplexAnimation selanSpellAnimation(&selanSprite, framerate);
186                 selanSpellAnimation.AddFrames(2, 0, Vector<int>(), 3);
187                 selanSpellAnimation.AddFrames(2, 1, Vector<int>(), 2);
188                 selanSpellAnimation.AddFrames(2, 2, Vector<int>(), 3);
189                 selanSpellAnimation.AddFrames(2, 3, Vector<int>(), 2);
190                 selan.SetSpellAnimation(&selanSpellAnimation);
191                 SDL_Surface *selanMeleeImg(IMG_Load("test-data/melee-selan.png"));
192                 Sprite selanMeleeSprite(selanMeleeImg, 96, 96);
193                 SimpleAnimation selanMeleeAnimation(&selanMeleeSprite, 2 * framerate, 4);
194                 selan.SetMeleeAnimation(&selanMeleeAnimation);
195
196                 SDL_Surface *guyImg(IMG_Load("test-data/guy.png"));
197                 Sprite guySprite(guyImg, 64, 64);
198                 Hero guy;
199                 guy.SetName("Guy");
200                 guy.SetLevel(1);
201                 guy.SetSprite(&guySprite);
202                 guy.SetMaxHealth(38);
203                 guy.SetHealth(38);
204                 guy.SetMaxMana(0);
205                 guy.SetMana(0);
206                 guy.SetIP(0);
207                 guy.SetStats(Stats(38, 25, 38, 13, 8, 90, 8));
208                 ComplexAnimation guyAttackAnimation(&guySprite, framerate);
209                 guyAttackAnimation.AddFrames(1, 0, Vector<int>(-4, 0), 2);
210                 guyAttackAnimation.AddFrames(1, 0, Vector<int>(-8, 0), 2);
211                 guyAttackAnimation.AddFrames(2, 0, Vector<int>(-8, 0), 2);
212                 guyAttackAnimation.AddFrame(2, 0, Vector<int>(-4, 0));
213                 guyAttackAnimation.AddFrames(2, 0, Vector<int>(), 2);
214                 guyAttackAnimation.AddFrame(2, 1);
215                 guyAttackAnimation.AddFrame(2, 1, Vector<int>(4, 0));
216                 guyAttackAnimation.AddFrame(2, 1, Vector<int>(10, 0));
217                 guyAttackAnimation.AddFrame(2, 2, Vector<int>(10, 0));
218                 guyAttackAnimation.AddFrame(2, 2);
219                 guy.SetAttackAnimation(&guyAttackAnimation);
220                 SDL_Surface *guyMeleeImg(IMG_Load("test-data/melee-guy.png"));
221                 Sprite guyMeleeSprite(guyMeleeImg, 96, 96);
222                 SimpleAnimation guyMeleeAnimation(&guyMeleeSprite, 2 * framerate, 4);
223                 guy.SetMeleeAnimation(&guyMeleeAnimation);
224
225                 SDL_Surface *dekarImg(IMG_Load("test-data/dekar.png"));
226                 Sprite dekarSprite(dekarImg, 64, 64);
227                 Hero dekar;
228                 dekar.SetName("Dekar");
229                 dekar.SetLevel(1);
230                 dekar.SetSprite(&dekarSprite);
231                 dekar.SetMaxHealth(38);
232                 dekar.SetHealth(38);
233                 dekar.SetMaxMana(0);
234                 dekar.SetMana(0);
235                 dekar.SetIP(0);
236                 dekar.SetStats(Stats(46, 29, 46, 13, 7, 100, 5));
237                 ComplexAnimation dekarAttackAnimation(&dekarSprite, framerate);
238                 dekarAttackAnimation.AddFrame(1, 0, Vector<int>(4, 0));
239                 dekarAttackAnimation.AddFrame(1, 0, Vector<int>(8, 2));
240                 dekarAttackAnimation.AddFrame(2, 0, Vector<int>(12, 4));
241                 dekarAttackAnimation.AddFrame(2, 0, Vector<int>(16, 4));
242                 dekarAttackAnimation.AddFrames(2, 0, Vector<int>(10, 2), 4);
243                 dekarAttackAnimation.AddFrame(2, 1, Vector<int>(6, 2));
244                 dekarAttackAnimation.AddFrame(2, 1, Vector<int>());
245                 dekarAttackAnimation.AddFrame(2, 2, Vector<int>(-2, 0));
246                 dekarAttackAnimation.AddFrames(2, 2, Vector<int>(0, 0), 3);
247                 dekar.SetAttackAnimation(&dekarAttackAnimation);
248                 ComplexAnimation dekarSpellAnimation(&dekarSprite, framerate);
249                 dekarSpellAnimation.AddFrames(2, 0, Vector<int>(), 6);
250                 dekarSpellAnimation.AddFrames(2, 1, Vector<int>(), 2);
251                 dekarSpellAnimation.AddFrames(2, 2, Vector<int>(), 3);
252                 dekar.SetSpellAnimation(&dekarSpellAnimation);
253                 SDL_Surface *dekarMeleeImg(IMG_Load("test-data/melee-dekar.png"));
254                 Sprite dekarMeleeSprite(dekarMeleeImg, 96, 96);
255                 SimpleAnimation dekarMeleeAnimation(&dekarMeleeSprite, 2 * framerate, 4);
256                 dekar.SetMeleeAnimation(&dekarMeleeAnimation);
257
258                 battle::Resources battleRes;
259
260                 SDL_Surface *swapCursorImg(IMG_Load("test-data/swap-cursor.png"));
261                 Sprite swapCursorSprite(swapCursorImg, 32, 32);
262                 battleRes.swapCursor = &swapCursorSprite;
263                 SDL_Surface *attackIconsImg(IMG_Load("test-data/attack-type-icons.png"));
264                 Sprite attackIconsSprite(attackIconsImg, 32, 32);
265                 battleRes.attackIcons = &attackIconsSprite;
266                 SDL_Surface *attackChoiceIconsImg(IMG_Load("test-data/attack-choice-icons.png"));
267                 Sprite attackChoiceIconsSprite(attackChoiceIconsImg, 16, 16);
268                 battleRes.attackChoiceIcons = &attackChoiceIconsSprite;
269                 SDL_Surface *moveIconsImg(IMG_Load("test-data/move-icons.png"));
270                 Sprite moveIconsSprite(moveIconsImg, 32, 32);
271                 battleRes.moveIcons = &moveIconsSprite;
272
273                 SDL_Surface *titleFrameImg(IMG_Load("test-data/title-frame.png"));
274                 Frame titleFrame(titleFrameImg, 16, 16);
275                 battleRes.titleFrame = &titleFrame;
276
277                 SDL_Surface *largeFontImg(IMG_Load("test-data/large-font.png"));
278                 Sprite largeFontSprite(largeFontImg, 16, 32);
279                 Font largeFont(&largeFontSprite, 0, -2);
280                 battleRes.titleFont = &largeFont;
281
282                 ComplexAnimation numberAnimationPrototype(0, framerate);
283                 numberAnimationPrototype.AddFrame(0, 0);
284                 numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -26));
285                 numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -42));
286                 numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -48));
287                 numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -42));
288                 numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -26));
289                 numberAnimationPrototype.AddFrame(0, 0);
290                 numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -12));
291                 numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -20));
292                 numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -24));
293                 numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -20));
294                 numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -12));
295                 numberAnimationPrototype.AddFrame(0, 0);
296                 numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -6));
297                 numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -10));
298                 numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -12));
299                 numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -10));
300                 numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -6));
301                 numberAnimationPrototype.AddFrames(0, 0, Vector<int>(), 14);
302                 numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -36));
303                 numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -32));
304                 numberAnimationPrototype.AddFrame(0, 0, Vector<int>(0, -18));
305                 battleRes.numberAnimationPrototype = &numberAnimationPrototype;
306
307                 SDL_Surface *bigNumbersImg(IMG_Load("test-data/big-numbers.png"));
308                 Sprite bigNumbersSprite(bigNumbersImg, 16, 32);
309                 battleRes.bigNumberSprite = &bigNumbersSprite;
310                 SDL_Surface *bigGreenNumbersImg(IMG_Load("test-data/big-green-numbers.png"));
311                 Sprite bigGreenNumbersSprite(bigGreenNumbersImg, 16, 32);
312                 battleRes.greenNumberSprite = &bigGreenNumbersSprite;
313
314                 SDL_Surface *heroTagImg(IMG_Load("test-data/hero-tag-sprites.png"));
315                 Sprite heroTagSprite(heroTagImg, 32, 16);
316                 battleRes.heroTagLabels = &heroTagSprite;
317                 battleRes.levelLabelCol = 0;
318                 battleRes.levelLabelRow = 0;
319                 battleRes.healthLabelCol = 0;
320                 battleRes.healthLabelRow = 1;
321                 battleRes.manaLabelCol = 0;
322                 battleRes.manaLabelRow = 2;
323                 battleRes.moveLabelCol = 0;
324                 battleRes.moveLabelRow = 3;
325                 battleRes.ikariLabelCol = 0;
326                 battleRes.ikariLabelRow = 4;
327
328                 SDL_Surface *numbersImg(IMG_Load("test-data/numbers.png"));
329                 Sprite numbersSprite(numbersImg, 16, 16);
330                 Font heroTagFont(&numbersSprite, 0, -3);
331                 battleRes.heroTagFont = &heroTagFont;
332                 SDL_Surface *tagFramesImg(IMG_Load("test-data/tag-frames.png"));
333                 Frame heroTagFrame(tagFramesImg, 16, 16, 1, 1, 0, 33);
334                 battleRes.heroTagFrame = &heroTagFrame;
335                 Frame activeHeroTagFrame(tagFramesImg, 16, 16);
336                 battleRes.activeHeroTagFrame = &activeHeroTagFrame;
337                 SDL_Surface *smallTagFrameImg(IMG_Load("test-data/small-tag-frame.png"));
338                 Frame smallTagFrame(smallTagFrameImg, 8, 16);
339                 battleRes.smallHeroTagFrame = &smallTagFrame;
340                 Frame lastSmallTagFrame(smallTagFrameImg, 8, 16, 1, 1, 0, 33);
341                 battleRes.lastSmallHeroTagFrame = &lastSmallTagFrame;
342                 battleRes.heroesBgColor = SDL_MapRGB(screen.Screen()->format, 0x18, 0x28, 0x31);
343
344                 SDL_Surface *gauges(IMG_Load("test-data/gauges.png"));
345                 Gauge healthGauge(gauges, 0, 16, 0, 0, 16, 6, 1, 6);
346                 battleRes.healthGauge = &healthGauge;
347                 Gauge manaGauge(gauges, 0, 32, 0, 0, 16, 6, 1, 6);
348                 battleRes.manaGauge = &manaGauge;
349                 Gauge ikariGauge(gauges, 0, 48, 0, 0, 16, 6, 1, 6);
350                 battleRes.ikariGauge = &ikariGauge;
351
352                 SDL_Surface *selectFrameImg(IMG_Load("test-data/select-frame.png"));
353                 Frame selectFrame(selectFrameImg, 16, 16);
354                 battleRes.selectFrame = &selectFrame;
355
356                 SDL_Surface *normalFontImg(IMG_Load("test-data/normal-font.png"));
357                 Sprite normalFontSprite(normalFontImg, 16, 16);
358                 Font normalFont(&normalFontSprite, 0, -2);
359                 battleRes.normalFont = &normalFont;
360
361                 SDL_Surface *disabledFontImg(IMG_Load("test-data/disabled-font.png"));
362                 Sprite disabledFontSprite(disabledFontImg, 16, 16);
363                 Font disabledFont(&disabledFontSprite, 0, -2);
364                 battleRes.disabledFont = &disabledFont;
365
366                 SDL_Surface *handCursorImg(IMG_Load("test-data/cursor-hand.png"));
367                 Sprite handCursorSprite(handCursorImg, 32, 32);
368                 battleRes.menuCursor = &handCursorSprite;
369
370                 SDL_Surface *targetingIconsImg(IMG_Load("test-data/targeting-icons.png"));
371                 Sprite weaponTargetCursor(targetingIconsImg, 32, 32);
372                 Sprite magicTargetCursor(targetingIconsImg, 32, 32, 0, 32);
373                 Sprite itemTargetCursor(targetingIconsImg, 32, 32, 0, 64);
374                 battleRes.weaponTargetCursor = &weaponTargetCursor;
375                 battleRes.magicTargetCursor = &magicTargetCursor;
376                 battleRes.itemTargetCursor = &itemTargetCursor;
377
378                 Spell resetSpell;
379                 resetSpell.SetName("Reset");
380                 maxim.AddSpell(&resetSpell);
381                 Spell strongSpell;
382                 strongSpell.SetName("Strong");
383                 strongSpell.SetCost(3);
384                 strongSpell.SetUsableInBattle();
385                 strongSpell.GetTargetingMode().TargetMultipleAllies();
386                 maxim.AddSpell(&strongSpell);
387                 selan.AddSpell(&strongSpell);
388                 Spell strongerSpell;
389                 strongerSpell.SetName("Stronger");
390                 strongerSpell.SetCost(8);
391                 strongerSpell.SetUsableInBattle();
392                 strongerSpell.GetTargetingMode().TargetMultipleAllies();
393                 maxim.AddSpell(&strongerSpell);
394                 selan.AddSpell(&strongerSpell);
395                 Spell championSpell;
396                 championSpell.SetName("Champion");
397                 championSpell.SetCost(16);
398                 championSpell.SetUsableInBattle();
399                 championSpell.GetTargetingMode().TargetMultipleAllies();
400                 maxim.AddSpell(&championSpell);
401                 selan.AddSpell(&championSpell);
402                 Spell rallySpell;
403                 rallySpell.SetName("Rally");
404                 rallySpell.SetCost(10);
405                 rallySpell.SetUsableInBattle();
406                 rallySpell.GetTargetingMode().TargetMultipleAllies();
407                 maxim.AddSpell(&rallySpell);
408                 selan.AddSpell(&rallySpell);
409                 Spell escapeSpell;
410                 escapeSpell.SetName("Escape");
411                 escapeSpell.SetCost(8);
412                 selan.AddSpell(&escapeSpell);
413                 Spell valorSpell;
414                 valorSpell.SetName("Valor");
415                 valorSpell.SetCost(30);
416                 valorSpell.SetUsableInBattle();
417                 valorSpell.GetTargetingMode().TargetMultipleAllies();
418                 maxim.AddSpell(&valorSpell);
419                 selan.AddSpell(&valorSpell);
420
421                 battleRes.spellMenuHeadline = "Please choose a spell.";
422                 battleRes.spellMenuPrototype = Menu<const Spell *>(&normalFont, &disabledFont, &handCursorSprite, 9, 6, 8, 0, 2, 32, 2, ':');
423
424                 SDL_Surface *itemIcons(IMG_Load("test-data/item-icons.png"));
425                 Sprite potionIcon(itemIcons, 16, 16);
426                 Sprite ballIcon(itemIcons, 16, 16, 0, 16);
427                 Sprite crankIcon(itemIcons, 16, 16, 0, 32);
428                 Sprite spearIcon(itemIcons, 16, 16, 0, 48);
429                 Sprite swordIcon(itemIcons, 16, 16, 0, 64);
430                 Sprite axIcon(itemIcons, 16, 16, 0, 80);
431                 Sprite rodIcon(itemIcons, 16, 16, 0, 96);
432                 Sprite armorIcon(itemIcons, 16, 16, 0, 112);
433                 Sprite shieldIcon(itemIcons, 16, 16, 0, 128);
434                 Sprite helmetIcon(itemIcons, 16, 16, 0, 144);
435                 Sprite ringIcon(itemIcons, 16, 16, 0, 160);
436                 Sprite jewelIcon(itemIcons, 16, 16, 0, 176);
437
438                 battleRes.weaponMenuIcon = &swordIcon;
439                 battleRes.armorMenuIcon = &armorIcon;
440                 battleRes.shieldMenuIcon = &shieldIcon;
441                 battleRes.helmetMenuIcon = &helmetIcon;
442                 battleRes.ringMenuIcon = &ringIcon;
443                 battleRes.jewelMenuIcon = &jewelIcon;
444
445                 Inventory inventory;
446                 Item antidote;
447                 antidote.SetName("Antidote");
448                 antidote.SetMenuIcon(&potionIcon);
449                 antidote.SetUsableInBattle();
450                 antidote.GetTargetingMode().TargetSingleAlly();
451                 inventory.Add(&antidote, 9);
452                 Item magicJar;
453                 magicJar.SetName("Magic jar");
454                 magicJar.SetMenuIcon(&potionIcon);
455                 magicJar.SetUsableInBattle();
456                 magicJar.GetTargetingMode().TargetSingleAlly();
457                 inventory.Add(&magicJar, 4);
458                 Item hiPotion;
459                 hiPotion.SetName("Hi-Potion");
460                 hiPotion.SetMenuIcon(&potionIcon);
461                 hiPotion.SetUsableInBattle();
462                 hiPotion.GetTargetingMode().TargetSingleAlly();
463                 inventory.Add(&hiPotion, 4);
464                 Item powerPotion;
465                 powerPotion.SetName("Power potion");
466                 powerPotion.SetMenuIcon(&potionIcon);
467                 inventory.Add(&powerPotion, 4);
468                 Item escape;
469                 escape.SetName("Escape");
470                 inventory.Add(&escape, 2);
471                 Item sleepBall;
472                 sleepBall.SetName("Sleep ball");
473                 sleepBall.SetMenuIcon(&ballIcon);
474                 sleepBall.SetUsableInBattle();
475                 sleepBall.GetTargetingMode().TargetSingleEnemy();
476                 inventory.Add(&sleepBall, 1);
477                 Item multiBall;
478                 multiBall.SetName("Multi-ball!");
479                 multiBall.SetMenuIcon(&ballIcon);
480                 multiBall.SetUsableInBattle();
481                 multiBall.GetTargetingMode().TargetMultipleEnemies();
482                 inventory.Add(&multiBall, 1);
483                 Item figgoru;
484                 figgoru.SetName("Figgoru");
485                 figgoru.SetMenuIcon(&crankIcon);
486                 figgoru.GetTargetingMode().TargetAllEnemies();
487                 inventory.Add(&figgoru, 1);
488                 battleRes.inventory = &inventory;
489
490                 battleRes.itemMenuHeadline = "Please choose an item.";
491                 battleRes.itemMenuPrototype = Menu<const common::Item *>(&normalFont, &disabledFont, &handCursorSprite, 15, 6, 8, 16, 1, 32, 2, ':');
492
493                 SDL_Surface *swordAttackImg(IMG_Load("test-data/attack-sword.png"));
494                 Sprite swordAttackSprite(swordAttackImg, 96, 96);
495                 SimpleAnimation swordAttackAnimation(&swordAttackSprite, 2 * framerate, 4);
496
497                 Item zircoSword;
498                 zircoSword.SetName("Zirco sword");
499                 zircoSword.SetMenuIcon(&swordIcon);
500                 zircoSword.GetTargetingMode().TargetSingleEnemy();
501                 Ikari firestorm;
502                 firestorm.SetName("Firestorm");
503                 firestorm.SetCost(224);
504                 firestorm.GetTargetingMode().TargetAllEnemies();
505                 firestorm.SetPhysical();
506                 zircoSword.SetIkari(&firestorm);
507                 zircoSword.SetAttackAnimation(&swordAttackAnimation);
508                 maxim.SetWeapon(&zircoSword);
509                 Item zirconArmor;
510                 zirconArmor.SetName("Zircon armor");
511                 zirconArmor.SetMenuIcon(&armorIcon);
512                 Ikari magicCure;
513                 magicCure.SetName("Magic cure");
514                 magicCure.SetCost(128);
515                 magicCure.GetTargetingMode().TargetSingleAlly();
516                 magicCure.SetMagical();
517                 zirconArmor.SetIkari(&magicCure);
518                 maxim.SetArmor(&zirconArmor);
519                 Item holyShield;
520                 holyShield.SetName("Holy shield");
521                 holyShield.SetMenuIcon(&shieldIcon);
522                 Ikari lightGuard;
523                 lightGuard.SetName("Light guard");
524                 lightGuard.SetCost(128);
525                 lightGuard.GetTargetingMode().TargetAllAllies(); // actually only targets self
526                 lightGuard.SetMagical();
527                 holyShield.SetIkari(&lightGuard);
528                 maxim.SetShield(&holyShield);
529                 Item legendHelm;
530                 legendHelm.SetName("Legend helm");
531                 legendHelm.SetMenuIcon(&helmetIcon);
532                 Ikari boomerang;
533                 boomerang.SetName("Boomerang");
534                 boomerang.SetCost(164);
535                 boomerang.GetTargetingMode().TargetAllAllies(); // actually only targets self
536                 boomerang.SetMagical();
537                 legendHelm.SetIkari(&boomerang);
538                 maxim.SetHelmet(&legendHelm);
539                 Item sProRing;
540                 sProRing.SetName("S-pro ring");
541                 sProRing.SetMenuIcon(&ringIcon);
542                 Ikari courage;
543                 courage.SetName("Courage");
544                 courage.SetCost(64);
545                 courage.GetTargetingMode().TargetMultipleAllies();
546                 courage.SetMagical();
547                 sProRing.SetIkari(&courage);
548                 maxim.SetRing(&sProRing);
549                 Item evilJewel;
550                 evilJewel.SetName("Evil jewel");
551                 evilJewel.SetMenuIcon(&jewelIcon);
552                 Ikari gloomy;
553                 gloomy.SetName("Gloomy");
554                 gloomy.SetCost(164);
555                 gloomy.GetTargetingMode().TargetAllEnemies();
556                 gloomy.SetMagical();
557                 evilJewel.SetIkari(&gloomy);
558                 maxim.SetJewel(&evilJewel);
559
560                 Item zircoWhip;
561                 zircoWhip.SetName("Zirco whip");
562                 zircoWhip.SetMenuIcon(&rodIcon);
563                 zircoWhip.GetTargetingMode().TargetSingleEnemy();
564                 Ikari thundershriek;
565                 thundershriek.SetName("Thundershriek");
566                 thundershriek.SetCost(224);
567                 thundershriek.GetTargetingMode().TargetAllEnemies();
568                 thundershriek.SetPhysical();
569                 zircoWhip.SetIkari(&thundershriek);
570 //              selan.SetWeapon(&zircoWhip);
571                 Item zirconPlate;
572                 zirconPlate.SetName("Zircon plate");
573                 zirconPlate.SetMenuIcon(&armorIcon);
574                 Ikari suddenCure;
575                 suddenCure.SetName("Sudden cure");
576                 suddenCure.SetCost(96);
577                 suddenCure.GetTargetingMode().TargetAllAllies();
578                 suddenCure.SetMagical();
579                 zirconPlate.SetIkari(&suddenCure);
580                 selan.SetArmor(&zirconPlate);
581                 Item zircoGloves;
582                 zircoGloves.SetName("Zirco gloves");
583                 zircoGloves.SetMenuIcon(&shieldIcon);
584                 Ikari forcefield;
585                 forcefield.SetName("Forcefield");
586                 forcefield.SetCost(64);
587                 forcefield.GetTargetingMode().TargetAllAllies();
588                 forcefield.SetMagical();
589                 zircoGloves.SetIkari(&forcefield);
590                 selan.SetShield(&zircoGloves);
591                 Item holyCap;
592                 holyCap.SetName("Holy cap");
593                 holyCap.SetMenuIcon(&helmetIcon);
594                 Ikari vulnerable;
595                 vulnerable.SetName("Vulnerable");
596                 vulnerable.SetCost(196);
597                 vulnerable.GetTargetingMode().TargetAllEnemies();
598                 vulnerable.SetPhysical();
599                 holyCap.SetIkari(&vulnerable);
600                 selan.SetHelmet(&holyCap);
601                 Item ghostRing;
602                 ghostRing.SetName("Ghost ring");
603                 ghostRing.SetMenuIcon(&ringIcon);
604                 Ikari destroy;
605                 destroy.SetName("Destroy");
606                 destroy.SetCost(128);
607                 destroy.GetTargetingMode().TargetMultipleEnemies();
608                 destroy.SetMagical();
609                 ghostRing.SetIkari(&destroy);
610                 selan.SetRing(&ghostRing);
611                 Item eagleRock;
612                 eagleRock.SetName("Eagle rock");
613                 eagleRock.SetMenuIcon(&jewelIcon);
614                 Ikari dive;
615                 dive.SetName("Dive");
616                 dive.SetCost(128);
617                 dive.GetTargetingMode().TargetSingleEnemy();
618                 dive.SetPhysical();
619                 eagleRock.SetIkari(&dive);
620                 selan.SetJewel(&eagleRock);
621
622                 Item zircoAx;
623                 zircoAx.SetName("Zirco ax");
624                 zircoAx.SetMenuIcon(&axIcon);
625                 zircoAx.GetTargetingMode().TargetSingleEnemy();
626                 Ikari torrent;
627                 torrent.SetName("Torrent");
628                 torrent.SetCost(224);
629                 torrent.GetTargetingMode().TargetAllEnemies();
630                 torrent.SetPhysical();
631                 zircoAx.SetIkari(&torrent);
632 //              guy.SetWeapon(&zircoAx);
633                 guy.SetArmor(&zirconArmor);
634                 Item megaShield;
635                 megaShield.SetName("Mega shield");
636                 megaShield.SetMenuIcon(&shieldIcon);
637                 Ikari ironBarrier;
638                 ironBarrier.SetName("Iron barrier");
639                 ironBarrier.SetCost(255);
640                 ironBarrier.GetTargetingMode().TargetAllAllies(); // actually only targets self
641                 ironBarrier.SetMagical();
642                 megaShield.SetIkari(&ironBarrier);
643                 guy.SetShield(&megaShield);
644                 Item zircoHelmet;
645                 zircoHelmet.SetName("Zirco helmet");
646                 zircoHelmet.SetMenuIcon(&helmetIcon);
647                 Ikari slow;
648                 slow.SetName("Slow");
649                 slow.SetCost(196);
650                 slow.GetTargetingMode().TargetAllEnemies();
651                 slow.SetPhysical();
652                 zircoHelmet.SetIkari(&slow);
653                 guy.SetHelmet(&zircoHelmet);
654                 Item powerRing;
655                 powerRing.SetName("Power ring");
656                 powerRing.SetMenuIcon(&ringIcon);
657                 Ikari trick;
658                 trick.SetName("Trick");
659                 trick.SetCost(32);
660                 trick.GetTargetingMode().TargetAllEnemies();
661                 trick.SetMagical();
662                 zircoHelmet.SetIkari(&trick);
663                 guy.SetRing(&powerRing);
664                 guy.SetJewel(&evilJewel);
665
666                 // NOTE: this is actually Artea equipment
667                 Item lizardBlow;
668                 lizardBlow.SetName("Lizard blow");
669                 lizardBlow.SetMenuIcon(&swordIcon);
670                 lizardBlow.GetTargetingMode().TargetSingleEnemy();
671                 Ikari dragonRush;
672                 dragonRush.SetName("Dragon rush");
673                 dragonRush.SetCost(164);
674                 dragonRush.GetTargetingMode().TargetSingleEnemy();
675                 dragonRush.SetPhysical();
676                 lizardBlow.SetIkari(&dragonRush);
677 //              dekar.SetWeapon(&lizardBlow);
678                 Item holyRobe;
679                 holyRobe.SetName("Holy robe");
680                 holyRobe.SetMenuIcon(&armorIcon);
681                 Ikari crisisCure;
682                 crisisCure.SetName("Crisis cure");
683                 crisisCure.SetCost(164);
684                 crisisCure.GetTargetingMode().TargetAllAllies();
685                 crisisCure.SetMagical();
686                 holyRobe.SetIkari(&crisisCure);
687                 dekar.SetArmor(&holyRobe);
688                 dekar.SetShield(&zircoGloves);
689                 dekar.SetHelmet(&holyCap);
690                 Item rocketRing;
691                 rocketRing.SetName("Rocket ring");
692                 rocketRing.SetMenuIcon(&ringIcon);
693                 Ikari fake;
694                 fake.SetName("Fake");
695                 fake.SetCost(32);
696                 fake.GetTargetingMode().TargetSingleAlly();
697                 fake.SetMagical();
698                 rocketRing.SetIkari(&fake);
699                 dekar.SetRing(&rocketRing);
700                 Item krakenRock;
701                 krakenRock.SetName("Kraken rock");
702                 krakenRock.SetMenuIcon(&jewelIcon);
703                 Ikari tenLegger;
704                 tenLegger.SetName("Ten-legger");
705                 tenLegger.SetCost(164);
706                 tenLegger.GetTargetingMode().TargetAllEnemies();
707                 tenLegger.SetPhysical();
708                 rocketRing.SetIkari(&tenLegger);
709                 dekar.SetJewel(&krakenRock);
710
711                 battleRes.ikariMenuHeadline = "Please choose equipment.";
712                 battleRes.noEquipmentText = "No equip";
713                 battleRes.ikariMenuPrototype = Menu<const Item *>(&normalFont, &disabledFont, &handCursorSprite, 12, 6, normalFont.CharHeight() / 2, normalFont.CharWidth(), 1, normalFont.CharWidth() * 2, 0, ':', 12, normalFont.CharWidth());
714
715                 battleRes.escapeText = "Escapes.";
716
717                 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &battleRes));
718                 battleState->AddMonster(monster);
719                 battleState->AddMonster(monster);
720                 battleState->AddMonster(monster);
721                 battleState->AddMonster(monster);
722                 battleState->AddHero(maxim);
723                 battleState->AddHero(selan);
724                 battleState->AddHero(guy);
725                 battleState->AddHero(dekar);
726                 Application app(&screen, battleState);
727                 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
728                 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
729                 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
730                 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
731                 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
732                 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
733                 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
734                 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
735                 app.Buttons().MapKey(SDLK_RETURN, Input::START);
736                 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
737                 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
738                 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
739                 app.Run();
740
741                 return 0;
742         } catch (Parser::Error &e) {
743                 cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl;
744                 return 1;
745         } catch (exception &e) {
746                 cerr << "exception in main(): " << e.what() << endl;
747                 return 1;
748         }
749 }