]> git.localhorst.tv Git - l2e.git/blob - src/main.cpp
refactored battle resources to better compatibility with loader
[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 //      std::srand(std::time(0));
78
79         try {
80                 InitSDL sdl;
81                 InitImage image(IMG_INIT_PNG);
82
83                 ParsedSource source;
84                 Parser parser("test-data/test.l2s", source);
85                 parser.Parse();
86                 Interpreter intp(source);
87                 intp.ReadSource();
88
89                 InitScreen screen(width, height);
90
91                 // temporary test data
92                 SDL_Surface *bg(IMG_Load("test-data/battle-bg.png"));
93                 PartyLayout monstersLayout(*intp.GetPartyLayout("monstersLayout"));
94                 PartyLayout heroesLayout(*intp.GetPartyLayout("heroesLayout"));
95
96                 Monster monster(*intp.GetMonster("lizard"));
97                 Hero maxim(*intp.GetHero("maxim"));
98                 Hero selan(*intp.GetHero("selan"));
99                 Hero guy(*intp.GetHero("guy"));
100                 Hero dekar(*intp.GetHero("dekar"));
101
102                 battle::Resources battleRes;
103
104                 battleRes.swapCursor = intp.GetSprite("swapCursor");
105                 battleRes.attackIcons = intp.GetSprite("attackIcons");
106                 battleRes.attackChoiceIcons = intp.GetSprite("attackChoiceIcons");
107                 battleRes.moveIcons = intp.GetSprite("moveIcons");
108                 battleRes.titleFrame = intp.GetFrame("titleFrame");
109                 battleRes.titleFont = intp.GetFont("largeFont");
110                 battleRes.numberAnimationPrototype = intp.GetAnimation("numberAnimationPrototype");
111                 battleRes.bigNumberSprite = intp.GetSprite("bigNumbers");
112                 battleRes.greenNumberSprite = intp.GetSprite("bigGreenNumbers");
113
114                 battleRes.heroTagLabels = intp.GetSprite("heroTagLabels");
115                 battleRes.levelLabelCol = 0;
116                 battleRes.levelLabelRow = 0;
117                 battleRes.healthLabelCol = 0;
118                 battleRes.healthLabelRow = 1;
119                 battleRes.manaLabelCol = 0;
120                 battleRes.manaLabelRow = 2;
121                 battleRes.moveLabelCol = 0;
122                 battleRes.moveLabelRow = 3;
123                 battleRes.ikariLabelCol = 0;
124                 battleRes.ikariLabelRow = 4;
125
126                 battleRes.heroTagFont = intp.GetFont("heroTagFont");
127                 battleRes.heroTagFrame = intp.GetFrame("heroTagFrame");
128                 battleRes.activeHeroTagFrame = intp.GetFrame("activeHeroTagFrame");
129                 battleRes.smallHeroTagFrame = intp.GetFrame("smallHeroTagFrame");
130                 battleRes.lastSmallHeroTagFrame = intp.GetFrame("lastSmallHeroTagFrame");
131                 battleRes.heroesBgColor = intp.GetColor("heroesBgColor");
132
133                 battleRes.healthGauge = intp.GetGauge("healthGauge");
134                 battleRes.manaGauge = intp.GetGauge("manaGauge");
135                 battleRes.ikariGauge = intp.GetGauge("ikariGauge");
136
137                 battleRes.selectFrame = intp.GetFrame("selectFrame");
138                 battleRes.normalFont = intp.GetFont("normalFont");
139                 battleRes.disabledFont = intp.GetFont("disabledFont");
140                 battleRes.menuCursor = intp.GetSprite("handCursor");
141
142                 battleRes.weaponTargetCursor = intp.GetSprite("weaponTargetCursor");
143                 battleRes.magicTargetCursor = intp.GetSprite("magicTargetCursor");
144                 battleRes.itemTargetCursor = intp.GetSprite("itemTargetCursor");
145
146                 maxim.AddSpell(intp.GetSpell("resetSpell"));
147                 Spell *strongSpell(intp.GetSpell("strongSpell"));
148                 maxim.AddSpell(strongSpell);
149                 selan.AddSpell(strongSpell);
150                 Spell *strongerSpell(intp.GetSpell("strongerSpell"));
151                 maxim.AddSpell(strongerSpell);
152                 selan.AddSpell(strongerSpell);
153                 Spell *championSpell(intp.GetSpell("championSpell"));
154                 maxim.AddSpell(championSpell);
155                 selan.AddSpell(championSpell);
156                 Spell *rallySpell(intp.GetSpell("rallySpell"));
157                 maxim.AddSpell(rallySpell);
158                 selan.AddSpell(rallySpell);
159                 selan.AddSpell(intp.GetSpell("escapeSpell"));
160                 Spell *valorSpell(intp.GetSpell("valorSpell"));
161                 maxim.AddSpell(valorSpell);
162                 selan.AddSpell(valorSpell);
163
164                 battleRes.spellMenuHeadline = intp.GetString("spellMenuHeadline");
165                 battleRes.spellMenuProperties = intp.GetMenuProperties("spellMenuPrototype");
166
167                 battleRes.weaponMenuIcon = intp.GetSprite("swordIcon");
168                 battleRes.armorMenuIcon = intp.GetSprite("armorIcon");
169                 battleRes.shieldMenuIcon = intp.GetSprite("shieldIcon");
170                 battleRes.helmetMenuIcon = intp.GetSprite("helmetIcon");
171                 battleRes.ringMenuIcon = intp.GetSprite("ringIcon");
172                 battleRes.jewelMenuIcon = intp.GetSprite("jewelIcon");
173
174                 Inventory inventory;
175                 inventory.Add(intp.GetItem("antidoteItem"), 9);
176                 inventory.Add(intp.GetItem("magicJarItem"), 4);
177                 inventory.Add(intp.GetItem("hiPotionItem"), 4);
178                 inventory.Add(intp.GetItem("powerPotionItem"), 4);
179                 inventory.Add(intp.GetItem("escapeItem"), 2);
180                 inventory.Add(intp.GetItem("sleepBallItem"), 1);
181                 battleRes.inventory = &inventory;
182
183                 battleRes.itemMenuHeadline = intp.GetString("itemMenuHeadline");
184                 battleRes.itemMenuProperties = intp.GetMenuProperties("itemMenuPrototype");
185
186                 maxim.SetWeapon(intp.GetItem("zircoSwordItem"));
187                 maxim.SetArmor(intp.GetItem("zirconArmorItem"));
188                 maxim.SetShield(intp.GetItem("holyShieldItem"));
189                 maxim.SetHelmet(intp.GetItem("legendHelmItem"));
190                 maxim.SetRing(intp.GetItem("sProRingItem"));
191                 maxim.SetJewel(intp.GetItem("evilJewelItem"));
192
193 //              selan.SetWeapon(intp.GetItem("zircoWhipItem"));
194                 selan.SetArmor(intp.GetItem("zirconPlateItem"));
195                 selan.SetShield(intp.GetItem("zircoGlovesItem"));
196                 selan.SetHelmet(intp.GetItem("holyCapItem"));
197                 selan.SetRing(intp.GetItem("ghostRingItem"));
198                 selan.SetJewel(intp.GetItem("eagleRockItem"));
199
200 //              guy.SetWeapon(intp.GetItem("zircoAxItem"));
201                 guy.SetArmor(intp.GetItem("zirconArmorItem"));
202                 guy.SetShield(intp.GetItem("megaShieldItem"));
203                 guy.SetHelmet(intp.GetItem("zircoHelmetItem"));
204                 guy.SetRing(intp.GetItem("powerRingItem"));
205                 guy.SetJewel(intp.GetItem("evilJewelItem"));
206
207                 // NOTE: this is actually Artea equipment
208 //              dekar.SetWeapon(intp.GetItem("lizardBlowItem"));
209                 dekar.SetArmor(intp.GetItem("holyRobeItem"));
210                 dekar.SetShield(intp.GetItem("zircoGlovesItem"));
211                 dekar.SetHelmet(intp.GetItem("holyCapItem"));
212                 dekar.SetRing(intp.GetItem("rocketRingItem"));
213                 dekar.SetJewel(intp.GetItem("krakenRockItem"));
214
215                 battleRes.ikariMenuHeadline = intp.GetString("ikariMenuHeadline");
216                 battleRes.noEquipmentText = intp.GetString("noEquipmentText");
217                 battleRes.ikariMenuProperties = intp.GetMenuProperties("ikariMenuPrototype");
218                 battleRes.escapeText = intp.GetString("escapeText");
219
220                 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &battleRes));
221                 battleState->AddMonster(monster);
222                 battleState->AddMonster(monster);
223                 battleState->AddMonster(monster);
224                 battleState->AddMonster(monster);
225                 battleState->AddHero(maxim);
226                 battleState->AddHero(selan);
227                 battleState->AddHero(guy);
228                 battleState->AddHero(dekar);
229                 Application app(&screen, battleState);
230                 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
231                 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
232                 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
233                 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
234                 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
235                 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
236                 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
237                 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
238                 app.Buttons().MapKey(SDLK_RETURN, Input::START);
239                 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
240                 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
241                 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
242                 app.Run();
243
244                 return 0;
245         } catch (Parser::Error &e) {
246                 cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl;
247                 return 1;
248         } catch (exception &e) {
249                 cerr << "exception in main(): " << e.what() << endl;
250                 return 1;
251         }
252 }