]> git.localhorst.tv Git - l2e.git/blob - src/main.cpp
moved Guy's and Dekar's (well, Artea's) equipment to items.l2s
[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                 InitSDL sdl;
83                 InitImage image(IMG_INIT_PNG);
84
85                 ParsedSource source;
86                 Parser parser("test-data/test.l2s", source);
87                 parser.Parse();
88                 Interpreter intp(source);
89                 intp.ReadSource();
90
91                 InitScreen screen(width, height);
92
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"));
97
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"));
103
104                 battle::Resources battleRes;
105
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");
115
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;
127
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);
134
135                 battleRes.healthGauge = intp.GetGauge("healthGauge");
136                 battleRes.manaGauge = intp.GetGauge("manaGauge");
137                 battleRes.ikariGauge = intp.GetGauge("ikariGauge");
138
139                 battleRes.selectFrame = intp.GetFrame("selectFrame");
140                 battleRes.normalFont = intp.GetFont("normalFont");
141                 battleRes.disabledFont = intp.GetFont("disabledFont");
142                 battleRes.menuCursor = intp.GetSprite("handCursor");
143
144                 battleRes.weaponTargetCursor = intp.GetSprite("weaponTargetCursor");
145                 battleRes.magicTargetCursor = intp.GetSprite("magicTargetCursor");
146                 battleRes.itemTargetCursor = intp.GetSprite("itemTargetCursor");
147
148                 maxim.AddSpell(intp.GetSpell("resetSpell"));
149                 Spell *strongSpell(intp.GetSpell("strongSpell"));
150                 maxim.AddSpell(strongSpell);
151                 selan.AddSpell(strongSpell);
152                 Spell *strongerSpell(intp.GetSpell("strongerSpell"));
153                 maxim.AddSpell(strongerSpell);
154                 selan.AddSpell(strongerSpell);
155                 Spell *championSpell(intp.GetSpell("championSpell"));
156                 maxim.AddSpell(championSpell);
157                 selan.AddSpell(championSpell);
158                 Spell *rallySpell(intp.GetSpell("rallySpell"));
159                 maxim.AddSpell(rallySpell);
160                 selan.AddSpell(rallySpell);
161                 selan.AddSpell(intp.GetSpell("escapeSpell"));
162                 Spell *valorSpell(intp.GetSpell("valorSpell"));
163                 maxim.AddSpell(valorSpell);
164                 selan.AddSpell(valorSpell);
165
166                 battleRes.spellMenuHeadline = intp.GetString("spellMenuHeadline");
167                 battleRes.spellMenuPrototype = Menu<const Spell *>(intp.GetFont("normalFont"), intp.GetFont("disabledFont"), intp.GetSprite("handCursor"), 9, 6, 8, 0, 2, 32, 2, ':');
168
169                 battleRes.weaponMenuIcon = intp.GetSprite("swordIcon");
170                 battleRes.armorMenuIcon = intp.GetSprite("armorIcon");
171                 battleRes.shieldMenuIcon = intp.GetSprite("shieldIcon");
172                 battleRes.helmetMenuIcon = intp.GetSprite("helmetIcon");
173                 battleRes.ringMenuIcon = intp.GetSprite("ringIcon");
174                 battleRes.jewelMenuIcon = intp.GetSprite("jewelIcon");
175
176                 Inventory inventory;
177                 inventory.Add(intp.GetItem("antidoteItem"), 9);
178                 inventory.Add(intp.GetItem("magicJarItem"), 4);
179                 inventory.Add(intp.GetItem("hiPotionItem"), 4);
180                 inventory.Add(intp.GetItem("powerPotionItem"), 4);
181                 inventory.Add(intp.GetItem("escapeItem"), 2);
182                 inventory.Add(intp.GetItem("sleepBallItem"), 1);
183                 battleRes.inventory = &inventory;
184
185                 battleRes.itemMenuHeadline = intp.GetString("itemMenuHeadline");
186                 battleRes.itemMenuPrototype = Menu<const common::Item *>(intp.GetFont("normalFont"), intp.GetFont("disabledFont"), intp.GetSprite("handCursor"), 15, 6, 8, 16, 1, 32, 2, ':');
187
188                 SDL_Surface *swordAttackImg(IMG_Load("test-data/attack-sword.png"));
189                 Sprite swordAttackSprite(swordAttackImg, 96, 96);
190                 SimpleAnimation swordAttackAnimation(&swordAttackSprite, 2 * framerate, 4);
191
192                 maxim.SetWeapon(intp.GetItem("zircoSwordItem"));
193                 maxim.SetArmor(intp.GetItem("zirconArmorItem"));
194                 maxim.SetShield(intp.GetItem("holyShieldItem"));
195                 maxim.SetHelmet(intp.GetItem("legendHelmItem"));
196                 maxim.SetRing(intp.GetItem("sProRingItem"));
197                 maxim.SetJewel(intp.GetItem("evilJewelItem"));
198
199 //              selan.SetWeapon(intp.GetItem("zircoWhipItem"));
200                 selan.SetArmor(intp.GetItem("zirconPlateItem"));
201                 selan.SetShield(intp.GetItem("zircoGlovesItem"));
202                 selan.SetHelmet(intp.GetItem("holyCapItem"));
203                 selan.SetRing(intp.GetItem("ghostRingItem"));
204                 selan.SetJewel(intp.GetItem("eagleRockItem"));
205
206 //              guy.SetWeapon(intp.GetItem("zircoAxItem"));
207                 guy.SetArmor(intp.GetItem("zirconArmorItem"));
208                 guy.SetShield(intp.GetItem("megaShieldItem"));
209                 guy.SetHelmet(intp.GetItem("zircoHelmetItem"));
210                 guy.SetRing(intp.GetItem("powerRingItem"));
211                 guy.SetJewel(intp.GetItem("evilJewelItem"));
212
213                 // NOTE: this is actually Artea equipment
214 //              dekar.SetWeapon(intp.GetItem("lizardBlowItem"));
215                 dekar.SetArmor(intp.GetItem("holyRobeItem"));
216                 dekar.SetShield(intp.GetItem("zircoGlovesItem"));
217                 dekar.SetHelmet(intp.GetItem("holyCapItem"));
218                 dekar.SetRing(intp.GetItem("rocketRingItem"));
219                 dekar.SetJewel(intp.GetItem("krakenRockItem"));
220
221                 battleRes.ikariMenuHeadline = "Please choose equipment.";
222                 battleRes.noEquipmentText = "No equip";
223                 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());
224
225                 battleRes.escapeText = "Escapes.";
226
227                 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &battleRes));
228                 battleState->AddMonster(monster);
229                 battleState->AddMonster(monster);
230                 battleState->AddMonster(monster);
231                 battleState->AddMonster(monster);
232                 battleState->AddHero(maxim);
233                 battleState->AddHero(selan);
234                 battleState->AddHero(guy);
235                 battleState->AddHero(dekar);
236                 Application app(&screen, battleState);
237                 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
238                 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
239                 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
240                 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
241                 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
242                 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
243                 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
244                 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
245                 app.Buttons().MapKey(SDLK_RETURN, Input::START);
246                 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
247                 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
248                 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
249                 app.Run();
250
251                 return 0;
252         } catch (Parser::Error &e) {
253                 cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl;
254                 return 1;
255         } catch (exception &e) {
256                 cerr << "exception in main(): " << e.what() << endl;
257                 return 1;
258         }
259 }