]> git.localhorst.tv Git - l2e.git/blob - src/main.cpp
2117a02efbe471437a050869d2c80f3200876546
[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 "loader/TypeDescription.h"
32 #include "sdl/InitImage.h"
33 #include "sdl/InitScreen.h"
34 #include "sdl/InitSDL.h"
35
36 #include <cstdlib>
37 #include <ctime>
38 #include <exception>
39 #include <iostream>
40 #include <SDL.h>
41 #include <SDL_image.h>
42
43 using app::Application;
44 using app::Input;
45 using battle::BattleState;
46 using battle::Hero;
47 using battle::Monster;
48 using battle::PartyLayout;
49 using battle::Stats;
50 using common::Ikari;
51 using common::Inventory;
52 using common::Item;
53 using common::Spell;
54 using geometry::Vector;
55 using graphics::ComplexAnimation;
56 using graphics::Font;
57 using graphics::Frame;
58 using graphics::Gauge;
59 using graphics::Menu;
60 using graphics::SimpleAnimation;
61 using graphics::Sprite;
62 using loader::Interpreter;
63 using loader::ParsedSource;
64 using loader::Parser;
65 using loader::TypeDescription;
66 using sdl::InitImage;
67 using sdl::InitScreen;
68 using sdl::InitSDL;
69
70 using std::cerr;
71 using std::cout;
72 using std::endl;
73 using std::exception;
74
75 int main(int argc, char **argv) {
76         const int width = 800;
77         const int height = 480;
78
79 //      std::srand(std::time(0));
80
81         try {
82                 InitSDL sdl;
83                 InitImage image(IMG_INIT_PNG);
84
85                 battle::Resources::CreateTypeDescription();
86                 ComplexAnimation::CreateTypeDescription();
87                 Font::CreateTypeDescription();
88                 Frame::CreateTypeDescription();
89                 Gauge::CreateTypeDescription();
90                 Hero::CreateTypeDescription();
91                 Ikari::CreateTypeDescription();
92                 Item::CreateTypeDescription();
93                 graphics::MenuProperties::CreateTypeDescription();
94                 PartyLayout::CreateTypeDescription();
95                 SimpleAnimation::CreateTypeDescription();
96                 Spell::CreateTypeDescription();
97                 Sprite::CreateTypeDescription();
98                 Stats::CreateTypeDescription();
99                 common::TargetingMode::CreateTypeDescription();
100
101                 ParsedSource source;
102                 Parser("test-data/test.l2s", source).Parse();
103                 Parser("test-data/ikaris.l2s", source).Parse();
104                 Parser("test-data/items.l2s", source).Parse();
105                 Parser("test-data/spells.l2s", source).Parse();
106                 Interpreter intp(source);
107                 intp.ReadSource();
108
109                 int battleResId(TypeDescription::GetTypeId("BattleResources"));
110                 int heroId(TypeDescription::GetTypeId("Hero"));
111                 int itemId(TypeDescription::GetTypeId("Item"));
112                 int monsterId(TypeDescription::GetTypeId("Monster"));
113                 int partyLayoutId(TypeDescription::GetTypeId("PartyLayout"));
114                 int spellId(TypeDescription::GetTypeId("Spell"));
115
116                 // temporary test data
117                 SDL_Surface *bg(IMG_Load("test-data/battle-bg.png"));
118                 PartyLayout monstersLayout(*reinterpret_cast<PartyLayout *>(intp.GetObject(partyLayoutId, "monstersLayout")));
119                 PartyLayout heroesLayout(*reinterpret_cast<PartyLayout *>(intp.GetObject(partyLayoutId, "heroesLayout")));
120
121                 Monster monster(*reinterpret_cast<Monster *>(intp.GetObject(monsterId, "lizard")));
122                 Hero maxim(*reinterpret_cast<Hero *>(intp.GetObject(heroId, "maxim")));
123                 Hero selan(*reinterpret_cast<Hero *>(intp.GetObject(heroId, "selan")));
124                 Hero guy(*reinterpret_cast<Hero *>(intp.GetObject(heroId, "guy")));
125                 Hero dekar(*reinterpret_cast<Hero *>(intp.GetObject(heroId, "dekar")));
126
127                 battle::Resources *battleRes(reinterpret_cast<battle::Resources *>(intp.GetObject(battleResId, "battleResources")));
128
129                 maxim.AddSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "resetSpell")));
130                 Spell *strongSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "strongSpell")));
131                 maxim.AddSpell(strongSpell);
132                 selan.AddSpell(strongSpell);
133                 Spell *strongerSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "strongerSpell")));
134                 maxim.AddSpell(strongerSpell);
135                 selan.AddSpell(strongerSpell);
136                 Spell *championSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "championSpell")));
137                 maxim.AddSpell(championSpell);
138                 selan.AddSpell(championSpell);
139                 Spell *rallySpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "rallySpell")));
140                 maxim.AddSpell(rallySpell);
141                 selan.AddSpell(rallySpell);
142                 selan.AddSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "escapeSpell")));
143                 Spell *valorSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "valorSpell")));
144                 maxim.AddSpell(valorSpell);
145                 selan.AddSpell(valorSpell);
146
147                 Inventory inventory;
148                 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "antidoteItem")), 9);
149                 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "magicJarItem")), 4);
150                 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "hiPotionItem")), 4);
151                 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "powerPotionItem")), 4);
152                 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "escapeItem")), 2);
153                 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "sleepBallItem")), 1);
154                 battleRes->inventory = &inventory;
155
156                 maxim.SetWeapon(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoSwordItem")));
157                 maxim.SetArmor(reinterpret_cast<Item *>(intp.GetObject(itemId, "zirconArmorItem")));
158                 maxim.SetShield(reinterpret_cast<Item *>(intp.GetObject(itemId, "holyShieldItem")));
159                 maxim.SetHelmet(reinterpret_cast<Item *>(intp.GetObject(itemId, "legendHelmItem")));
160                 maxim.SetRing(reinterpret_cast<Item *>(intp.GetObject(itemId, "sProRingItem")));
161                 maxim.SetJewel(reinterpret_cast<Item *>(intp.GetObject(itemId, "evilJewelItem")));
162
163 //              selan.SetWeapon(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoWhipItem")));
164                 selan.SetArmor(reinterpret_cast<Item *>(intp.GetObject(itemId, "zirconPlateItem")));
165                 selan.SetShield(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoGlovesItem")));
166                 selan.SetHelmet(reinterpret_cast<Item *>(intp.GetObject(itemId, "holyCapItem")));
167                 selan.SetRing(reinterpret_cast<Item *>(intp.GetObject(itemId, "ghostRingItem")));
168                 selan.SetJewel(reinterpret_cast<Item *>(intp.GetObject(itemId, "eagleRockItem")));
169
170 //              guy.SetWeapon(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoAxItem")));
171                 guy.SetArmor(reinterpret_cast<Item *>(intp.GetObject(itemId, "zirconArmorItem")));
172                 guy.SetShield(reinterpret_cast<Item *>(intp.GetObject(itemId, "megaShieldItem")));
173                 guy.SetHelmet(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoHelmetItem")));
174                 guy.SetRing(reinterpret_cast<Item *>(intp.GetObject(itemId, "powerRingItem")));
175                 guy.SetJewel(reinterpret_cast<Item *>(intp.GetObject(itemId, "evilJewelItem")));
176
177                 // NOTE: this is actually Artea equipment
178 //              dekar.SetWeapon(reinterpret_cast<Item *>(intp.GetObject(itemId, "lizardBlowItem")));
179                 dekar.SetArmor(reinterpret_cast<Item *>(intp.GetObject(itemId, "holyRobeItem")));
180                 dekar.SetShield(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoGlovesItem")));
181                 dekar.SetHelmet(reinterpret_cast<Item *>(intp.GetObject(itemId, "holyCapItem")));
182                 dekar.SetRing(reinterpret_cast<Item *>(intp.GetObject(itemId, "rocketRingItem")));
183                 dekar.SetJewel(reinterpret_cast<Item *>(intp.GetObject(itemId, "krakenRockItem")));
184
185                 InitScreen screen(width, height);
186
187                 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, battleRes));
188                 battleState->AddMonster(monster);
189                 battleState->AddMonster(monster);
190                 battleState->AddMonster(monster);
191                 battleState->AddMonster(monster);
192                 battleState->AddHero(maxim);
193                 battleState->AddHero(selan);
194                 battleState->AddHero(guy);
195                 battleState->AddHero(dekar);
196                 Application app(&screen, battleState);
197                 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
198                 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
199                 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
200                 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
201                 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
202                 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
203                 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
204                 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
205                 app.Buttons().MapKey(SDLK_RETURN, Input::START);
206                 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
207                 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
208                 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
209                 app.Run();
210
211                 return 0;
212         } catch (Parser::Error &e) {
213                 cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl;
214                 return 1;
215         } catch (exception &e) {
216                 cerr << "exception in main(): " << e.what() << endl;
217                 return 1;
218         }
219 }