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