4 * Created on: Aug 1, 2012
8 #include "app/Application.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"
40 #include <SDL_image.h>
42 using app::Application;
44 using battle::BattleState;
46 using battle::Monster;
47 using battle::PartyLayout;
50 using common::Inventory;
53 using geometry::Vector;
54 using graphics::ComplexAnimation;
56 using graphics::Frame;
57 using graphics::Gauge;
59 using graphics::SimpleAnimation;
60 using graphics::Sprite;
61 using loader::Interpreter;
62 using loader::ParsedSource;
65 using sdl::InitScreen;
73 int main(int argc, char **argv) {
74 const int width = 800;
75 const int height = 480;
77 const int framerate = 33;
79 // std::srand(std::time(0));
83 InitImage image(IMG_INIT_PNG);
86 Parser parser("test-data/test.l2s", source);
88 Interpreter intp(source);
91 InitScreen screen(width, height);
93 // temporary test data
94 SDL_Surface *bg(IMG_Load("test-data/battle-bg.png"));
95 PartyLayout monstersLayout(*intp.GetPartyLayout("monstersLayout"));
96 PartyLayout heroesLayout(*intp.GetPartyLayout("heroesLayout"));
98 Monster monster(*intp.GetMonster("lizard"));
99 Hero maxim(*intp.GetHero("maxim"));
100 Hero selan(*intp.GetHero("selan"));
101 Hero guy(*intp.GetHero("guy"));
102 Hero dekar(*intp.GetHero("dekar"));
104 battle::Resources battleRes;
106 battleRes.swapCursor = intp.GetSprite("swapCursor");
107 battleRes.attackIcons = intp.GetSprite("attackIcons");
108 battleRes.attackChoiceIcons = intp.GetSprite("attackChoiceIcons");
109 battleRes.moveIcons = intp.GetSprite("moveIcons");
110 battleRes.titleFrame = intp.GetFrame("titleFrame");
111 battleRes.titleFont = intp.GetFont("largeFont");
112 battleRes.numberAnimationPrototype = intp.GetAnimation("numberAnimationPrototype");
113 battleRes.bigNumberSprite = intp.GetSprite("bigNumbers");
114 battleRes.greenNumberSprite = intp.GetSprite("bigGreenNumbers");
116 battleRes.heroTagLabels = intp.GetSprite("heroTagLabels");
117 battleRes.levelLabelCol = 0;
118 battleRes.levelLabelRow = 0;
119 battleRes.healthLabelCol = 0;
120 battleRes.healthLabelRow = 1;
121 battleRes.manaLabelCol = 0;
122 battleRes.manaLabelRow = 2;
123 battleRes.moveLabelCol = 0;
124 battleRes.moveLabelRow = 3;
125 battleRes.ikariLabelCol = 0;
126 battleRes.ikariLabelRow = 4;
128 battleRes.heroTagFont = intp.GetFont("heroTagFont");
129 battleRes.heroTagFrame = intp.GetFrame("heroTagFrame");
130 battleRes.activeHeroTagFrame = intp.GetFrame("activeHeroTagFrame");
131 battleRes.smallHeroTagFrame = intp.GetFrame("smallHeroTagFrame");
132 battleRes.lastSmallHeroTagFrame = intp.GetFrame("lastSmallHeroTagFrame");
133 battleRes.heroesBgColor = SDL_MapRGB(screen.Screen()->format, 0x18, 0x28, 0x31);
135 battleRes.healthGauge = intp.GetGauge("healthGauge");
136 battleRes.manaGauge = intp.GetGauge("manaGauge");
137 battleRes.ikariGauge = intp.GetGauge("ikariGauge");
139 battleRes.selectFrame = intp.GetFrame("selectFrame");
140 battleRes.normalFont = intp.GetFont("normalFont");
141 battleRes.disabledFont = intp.GetFont("disabledFont");
142 battleRes.menuCursor = intp.GetSprite("handCursor");
144 battleRes.weaponTargetCursor = intp.GetSprite("weaponTargetCursor");
145 battleRes.magicTargetCursor = intp.GetSprite("magicTargetCursor");
146 battleRes.itemTargetCursor = intp.GetSprite("itemTargetCursor");
149 resetSpell.SetName("Reset");
150 maxim.AddSpell(&resetSpell);
152 strongSpell.SetName("Strong");
153 strongSpell.SetCost(3);
154 strongSpell.SetUsableInBattle();
155 strongSpell.GetTargetingMode().TargetMultipleAllies();
156 maxim.AddSpell(&strongSpell);
157 selan.AddSpell(&strongSpell);
159 strongerSpell.SetName("Stronger");
160 strongerSpell.SetCost(8);
161 strongerSpell.SetUsableInBattle();
162 strongerSpell.GetTargetingMode().TargetMultipleAllies();
163 maxim.AddSpell(&strongerSpell);
164 selan.AddSpell(&strongerSpell);
166 championSpell.SetName("Champion");
167 championSpell.SetCost(16);
168 championSpell.SetUsableInBattle();
169 championSpell.GetTargetingMode().TargetMultipleAllies();
170 maxim.AddSpell(&championSpell);
171 selan.AddSpell(&championSpell);
173 rallySpell.SetName("Rally");
174 rallySpell.SetCost(10);
175 rallySpell.SetUsableInBattle();
176 rallySpell.GetTargetingMode().TargetMultipleAllies();
177 maxim.AddSpell(&rallySpell);
178 selan.AddSpell(&rallySpell);
180 escapeSpell.SetName("Escape");
181 escapeSpell.SetCost(8);
182 selan.AddSpell(&escapeSpell);
184 valorSpell.SetName("Valor");
185 valorSpell.SetCost(30);
186 valorSpell.SetUsableInBattle();
187 valorSpell.GetTargetingMode().TargetMultipleAllies();
188 maxim.AddSpell(&valorSpell);
189 selan.AddSpell(&valorSpell);
191 battleRes.spellMenuHeadline = "Please choose a spell.";
192 battleRes.spellMenuPrototype = Menu<const Spell *>(intp.GetFont("normalFont"), intp.GetFont("disabledFont"), intp.GetSprite("handCursor"), 9, 6, 8, 0, 2, 32, 2, ':');
194 SDL_Surface *itemIcons(IMG_Load("test-data/item-icons.png"));
195 Sprite potionIcon(itemIcons, 16, 16);
196 Sprite ballIcon(itemIcons, 16, 16, 0, 16);
197 Sprite crankIcon(itemIcons, 16, 16, 0, 32);
198 Sprite spearIcon(itemIcons, 16, 16, 0, 48);
199 Sprite swordIcon(itemIcons, 16, 16, 0, 64);
200 Sprite axIcon(itemIcons, 16, 16, 0, 80);
201 Sprite rodIcon(itemIcons, 16, 16, 0, 96);
202 Sprite armorIcon(itemIcons, 16, 16, 0, 112);
203 Sprite shieldIcon(itemIcons, 16, 16, 0, 128);
204 Sprite helmetIcon(itemIcons, 16, 16, 0, 144);
205 Sprite ringIcon(itemIcons, 16, 16, 0, 160);
206 Sprite jewelIcon(itemIcons, 16, 16, 0, 176);
208 battleRes.weaponMenuIcon = &swordIcon;
209 battleRes.armorMenuIcon = &armorIcon;
210 battleRes.shieldMenuIcon = &shieldIcon;
211 battleRes.helmetMenuIcon = &helmetIcon;
212 battleRes.ringMenuIcon = &ringIcon;
213 battleRes.jewelMenuIcon = &jewelIcon;
217 antidote.SetName("Antidote");
218 antidote.SetMenuIcon(&potionIcon);
219 antidote.SetUsableInBattle();
220 antidote.GetTargetingMode().TargetSingleAlly();
221 inventory.Add(&antidote, 9);
223 magicJar.SetName("Magic jar");
224 magicJar.SetMenuIcon(&potionIcon);
225 magicJar.SetUsableInBattle();
226 magicJar.GetTargetingMode().TargetSingleAlly();
227 inventory.Add(&magicJar, 4);
229 hiPotion.SetName("Hi-Potion");
230 hiPotion.SetMenuIcon(&potionIcon);
231 hiPotion.SetUsableInBattle();
232 hiPotion.GetTargetingMode().TargetSingleAlly();
233 inventory.Add(&hiPotion, 4);
235 powerPotion.SetName("Power potion");
236 powerPotion.SetMenuIcon(&potionIcon);
237 inventory.Add(&powerPotion, 4);
239 escape.SetName("Escape");
240 inventory.Add(&escape, 2);
242 sleepBall.SetName("Sleep ball");
243 sleepBall.SetMenuIcon(&ballIcon);
244 sleepBall.SetUsableInBattle();
245 sleepBall.GetTargetingMode().TargetSingleEnemy();
246 inventory.Add(&sleepBall, 1);
248 multiBall.SetName("Multi-ball!");
249 multiBall.SetMenuIcon(&ballIcon);
250 multiBall.SetUsableInBattle();
251 multiBall.GetTargetingMode().TargetMultipleEnemies();
252 inventory.Add(&multiBall, 1);
254 figgoru.SetName("Figgoru");
255 figgoru.SetMenuIcon(&crankIcon);
256 figgoru.GetTargetingMode().TargetAllEnemies();
257 inventory.Add(&figgoru, 1);
258 battleRes.inventory = &inventory;
260 battleRes.itemMenuHeadline = "Please choose an item.";
261 battleRes.itemMenuPrototype = Menu<const common::Item *>(intp.GetFont("normalFont"), intp.GetFont("disabledFont"), intp.GetSprite("handCursor"), 15, 6, 8, 16, 1, 32, 2, ':');
263 SDL_Surface *swordAttackImg(IMG_Load("test-data/attack-sword.png"));
264 Sprite swordAttackSprite(swordAttackImg, 96, 96);
265 SimpleAnimation swordAttackAnimation(&swordAttackSprite, 2 * framerate, 4);
268 zircoSword.SetName("Zirco sword");
269 zircoSword.SetMenuIcon(&swordIcon);
270 zircoSword.GetTargetingMode().TargetSingleEnemy();
272 firestorm.SetName("Firestorm");
273 firestorm.SetCost(224);
274 firestorm.GetTargetingMode().TargetAllEnemies();
275 firestorm.SetPhysical();
276 zircoSword.SetIkari(&firestorm);
277 zircoSword.SetAttackAnimation(&swordAttackAnimation);
278 maxim.SetWeapon(&zircoSword);
280 zirconArmor.SetName("Zircon armor");
281 zirconArmor.SetMenuIcon(&armorIcon);
283 magicCure.SetName("Magic cure");
284 magicCure.SetCost(128);
285 magicCure.GetTargetingMode().TargetSingleAlly();
286 magicCure.SetMagical();
287 zirconArmor.SetIkari(&magicCure);
288 maxim.SetArmor(&zirconArmor);
290 holyShield.SetName("Holy shield");
291 holyShield.SetMenuIcon(&shieldIcon);
293 lightGuard.SetName("Light guard");
294 lightGuard.SetCost(128);
295 lightGuard.GetTargetingMode().TargetAllAllies(); // actually only targets self
296 lightGuard.SetMagical();
297 holyShield.SetIkari(&lightGuard);
298 maxim.SetShield(&holyShield);
300 legendHelm.SetName("Legend helm");
301 legendHelm.SetMenuIcon(&helmetIcon);
303 boomerang.SetName("Boomerang");
304 boomerang.SetCost(164);
305 boomerang.GetTargetingMode().TargetAllAllies(); // actually only targets self
306 boomerang.SetMagical();
307 legendHelm.SetIkari(&boomerang);
308 maxim.SetHelmet(&legendHelm);
310 sProRing.SetName("S-pro ring");
311 sProRing.SetMenuIcon(&ringIcon);
313 courage.SetName("Courage");
315 courage.GetTargetingMode().TargetMultipleAllies();
316 courage.SetMagical();
317 sProRing.SetIkari(&courage);
318 maxim.SetRing(&sProRing);
320 evilJewel.SetName("Evil jewel");
321 evilJewel.SetMenuIcon(&jewelIcon);
323 gloomy.SetName("Gloomy");
325 gloomy.GetTargetingMode().TargetAllEnemies();
327 evilJewel.SetIkari(&gloomy);
328 maxim.SetJewel(&evilJewel);
331 zircoWhip.SetName("Zirco whip");
332 zircoWhip.SetMenuIcon(&rodIcon);
333 zircoWhip.GetTargetingMode().TargetSingleEnemy();
335 thundershriek.SetName("Thundershriek");
336 thundershriek.SetCost(224);
337 thundershriek.GetTargetingMode().TargetAllEnemies();
338 thundershriek.SetPhysical();
339 zircoWhip.SetIkari(&thundershriek);
340 // selan.SetWeapon(&zircoWhip);
342 zirconPlate.SetName("Zircon plate");
343 zirconPlate.SetMenuIcon(&armorIcon);
345 suddenCure.SetName("Sudden cure");
346 suddenCure.SetCost(96);
347 suddenCure.GetTargetingMode().TargetAllAllies();
348 suddenCure.SetMagical();
349 zirconPlate.SetIkari(&suddenCure);
350 selan.SetArmor(&zirconPlate);
352 zircoGloves.SetName("Zirco gloves");
353 zircoGloves.SetMenuIcon(&shieldIcon);
355 forcefield.SetName("Forcefield");
356 forcefield.SetCost(64);
357 forcefield.GetTargetingMode().TargetAllAllies();
358 forcefield.SetMagical();
359 zircoGloves.SetIkari(&forcefield);
360 selan.SetShield(&zircoGloves);
362 holyCap.SetName("Holy cap");
363 holyCap.SetMenuIcon(&helmetIcon);
365 vulnerable.SetName("Vulnerable");
366 vulnerable.SetCost(196);
367 vulnerable.GetTargetingMode().TargetAllEnemies();
368 vulnerable.SetPhysical();
369 holyCap.SetIkari(&vulnerable);
370 selan.SetHelmet(&holyCap);
372 ghostRing.SetName("Ghost ring");
373 ghostRing.SetMenuIcon(&ringIcon);
375 destroy.SetName("Destroy");
376 destroy.SetCost(128);
377 destroy.GetTargetingMode().TargetMultipleEnemies();
378 destroy.SetMagical();
379 ghostRing.SetIkari(&destroy);
380 selan.SetRing(&ghostRing);
382 eagleRock.SetName("Eagle rock");
383 eagleRock.SetMenuIcon(&jewelIcon);
385 dive.SetName("Dive");
387 dive.GetTargetingMode().TargetSingleEnemy();
389 eagleRock.SetIkari(&dive);
390 selan.SetJewel(&eagleRock);
393 zircoAx.SetName("Zirco ax");
394 zircoAx.SetMenuIcon(&axIcon);
395 zircoAx.GetTargetingMode().TargetSingleEnemy();
397 torrent.SetName("Torrent");
398 torrent.SetCost(224);
399 torrent.GetTargetingMode().TargetAllEnemies();
400 torrent.SetPhysical();
401 zircoAx.SetIkari(&torrent);
402 // guy.SetWeapon(&zircoAx);
403 guy.SetArmor(&zirconArmor);
405 megaShield.SetName("Mega shield");
406 megaShield.SetMenuIcon(&shieldIcon);
408 ironBarrier.SetName("Iron barrier");
409 ironBarrier.SetCost(255);
410 ironBarrier.GetTargetingMode().TargetAllAllies(); // actually only targets self
411 ironBarrier.SetMagical();
412 megaShield.SetIkari(&ironBarrier);
413 guy.SetShield(&megaShield);
415 zircoHelmet.SetName("Zirco helmet");
416 zircoHelmet.SetMenuIcon(&helmetIcon);
418 slow.SetName("Slow");
420 slow.GetTargetingMode().TargetAllEnemies();
422 zircoHelmet.SetIkari(&slow);
423 guy.SetHelmet(&zircoHelmet);
425 powerRing.SetName("Power ring");
426 powerRing.SetMenuIcon(&ringIcon);
428 trick.SetName("Trick");
430 trick.GetTargetingMode().TargetAllEnemies();
432 zircoHelmet.SetIkari(&trick);
433 guy.SetRing(&powerRing);
434 guy.SetJewel(&evilJewel);
436 // NOTE: this is actually Artea equipment
438 lizardBlow.SetName("Lizard blow");
439 lizardBlow.SetMenuIcon(&swordIcon);
440 lizardBlow.GetTargetingMode().TargetSingleEnemy();
442 dragonRush.SetName("Dragon rush");
443 dragonRush.SetCost(164);
444 dragonRush.GetTargetingMode().TargetSingleEnemy();
445 dragonRush.SetPhysical();
446 lizardBlow.SetIkari(&dragonRush);
447 // dekar.SetWeapon(&lizardBlow);
449 holyRobe.SetName("Holy robe");
450 holyRobe.SetMenuIcon(&armorIcon);
452 crisisCure.SetName("Crisis cure");
453 crisisCure.SetCost(164);
454 crisisCure.GetTargetingMode().TargetAllAllies();
455 crisisCure.SetMagical();
456 holyRobe.SetIkari(&crisisCure);
457 dekar.SetArmor(&holyRobe);
458 dekar.SetShield(&zircoGloves);
459 dekar.SetHelmet(&holyCap);
461 rocketRing.SetName("Rocket ring");
462 rocketRing.SetMenuIcon(&ringIcon);
464 fake.SetName("Fake");
466 fake.GetTargetingMode().TargetSingleAlly();
468 rocketRing.SetIkari(&fake);
469 dekar.SetRing(&rocketRing);
471 krakenRock.SetName("Kraken rock");
472 krakenRock.SetMenuIcon(&jewelIcon);
474 tenLegger.SetName("Ten-legger");
475 tenLegger.SetCost(164);
476 tenLegger.GetTargetingMode().TargetAllEnemies();
477 tenLegger.SetPhysical();
478 rocketRing.SetIkari(&tenLegger);
479 dekar.SetJewel(&krakenRock);
481 battleRes.ikariMenuHeadline = "Please choose equipment.";
482 battleRes.noEquipmentText = "No equip";
483 battleRes.ikariMenuPrototype = Menu<const Item *>(intp.GetFont("normalFont"), intp.GetFont("disabledFont"), intp.GetSprite("handCursor"), 12, 6, intp.GetFont("normalFont")->CharHeight() / 2, intp.GetFont("normalFont")->CharWidth(), 1, intp.GetFont("normalFont")->CharWidth() * 2, 0, ':', 12, intp.GetFont("normalFont")->CharWidth());
485 battleRes.escapeText = "Escapes.";
487 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &battleRes));
488 battleState->AddMonster(monster);
489 battleState->AddMonster(monster);
490 battleState->AddMonster(monster);
491 battleState->AddMonster(monster);
492 battleState->AddHero(maxim);
493 battleState->AddHero(selan);
494 battleState->AddHero(guy);
495 battleState->AddHero(dekar);
496 Application app(&screen, battleState);
497 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
498 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
499 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
500 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
501 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
502 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
503 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
504 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
505 app.Buttons().MapKey(SDLK_RETURN, Input::START);
506 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
507 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
508 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
512 } catch (Parser::Error &e) {
513 cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl;
515 } catch (exception &e) {
516 cerr << "exception in main(): " << e.what() << endl;