]> git.localhorst.tv Git - l2e.git/blob - src/main.cpp
converted pseudo-fields into real ones
[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                 Parser("test-data/constants.l2s", source).Parse();
107                 Interpreter intp(source);
108                 intp.ReadSource();
109
110                 int battleResId(TypeDescription::GetTypeId("BattleResources"));
111                 int heroId(TypeDescription::GetTypeId("Hero"));
112                 int itemId(TypeDescription::GetTypeId("Item"));
113                 int monsterId(TypeDescription::GetTypeId("Monster"));
114                 int partyLayoutId(TypeDescription::GetTypeId("PartyLayout"));
115                 int spellId(TypeDescription::GetTypeId("Spell"));
116
117                 // temporary test data
118                 SDL_Surface *bg(IMG_Load("test-data/battle-bg.png"));
119                 PartyLayout monstersLayout(*reinterpret_cast<PartyLayout *>(intp.GetObject(partyLayoutId, "monstersLayout")));
120                 PartyLayout heroesLayout(*reinterpret_cast<PartyLayout *>(intp.GetObject(partyLayoutId, "heroesLayout")));
121
122                 Monster monster(*reinterpret_cast<Monster *>(intp.GetObject(monsterId, "lizard")));
123                 Hero maxim(*reinterpret_cast<Hero *>(intp.GetObject(heroId, "maxim")));
124                 Hero selan(*reinterpret_cast<Hero *>(intp.GetObject(heroId, "selan")));
125                 Hero guy(*reinterpret_cast<Hero *>(intp.GetObject(heroId, "guy")));
126                 Hero dekar(*reinterpret_cast<Hero *>(intp.GetObject(heroId, "dekar")));
127
128                 battle::Resources *battleRes(reinterpret_cast<battle::Resources *>(intp.GetObject(battleResId, "battleResources")));
129
130                 maxim.AddSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "resetSpell")));
131                 Spell *strongSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "strongSpell")));
132                 maxim.AddSpell(strongSpell);
133                 selan.AddSpell(strongSpell);
134                 Spell *strongerSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "strongerSpell")));
135                 maxim.AddSpell(strongerSpell);
136                 selan.AddSpell(strongerSpell);
137                 Spell *championSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "championSpell")));
138                 maxim.AddSpell(championSpell);
139                 selan.AddSpell(championSpell);
140                 Spell *rallySpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "rallySpell")));
141                 maxim.AddSpell(rallySpell);
142                 selan.AddSpell(rallySpell);
143                 selan.AddSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "escapeSpell")));
144                 Spell *valorSpell(reinterpret_cast<Spell *>(intp.GetObject(spellId, "valorSpell")));
145                 maxim.AddSpell(valorSpell);
146                 selan.AddSpell(valorSpell);
147
148                 Inventory inventory;
149                 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "antidoteItem")), 9);
150                 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "magicJarItem")), 4);
151                 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "hiPotionItem")), 4);
152                 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "powerPotionItem")), 4);
153                 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "escapeItem")), 2);
154                 inventory.Add(reinterpret_cast<Item *>(intp.GetObject(itemId, "sleepBallItem")), 1);
155                 battleRes->inventory = &inventory;
156
157                 maxim.SetWeapon(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoSwordItem")));
158                 maxim.SetArmor(reinterpret_cast<Item *>(intp.GetObject(itemId, "zirconArmorItem")));
159                 maxim.SetShield(reinterpret_cast<Item *>(intp.GetObject(itemId, "holyShieldItem")));
160                 maxim.SetHelmet(reinterpret_cast<Item *>(intp.GetObject(itemId, "legendHelmItem")));
161                 maxim.SetRing(reinterpret_cast<Item *>(intp.GetObject(itemId, "sProRingItem")));
162                 maxim.SetJewel(reinterpret_cast<Item *>(intp.GetObject(itemId, "evilJewelItem")));
163
164 //              selan.SetWeapon(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoWhipItem")));
165                 selan.SetArmor(reinterpret_cast<Item *>(intp.GetObject(itemId, "zirconPlateItem")));
166                 selan.SetShield(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoGlovesItem")));
167                 selan.SetHelmet(reinterpret_cast<Item *>(intp.GetObject(itemId, "holyCapItem")));
168                 selan.SetRing(reinterpret_cast<Item *>(intp.GetObject(itemId, "ghostRingItem")));
169                 selan.SetJewel(reinterpret_cast<Item *>(intp.GetObject(itemId, "eagleRockItem")));
170
171 //              guy.SetWeapon(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoAxItem")));
172                 guy.SetArmor(reinterpret_cast<Item *>(intp.GetObject(itemId, "zirconArmorItem")));
173                 guy.SetShield(reinterpret_cast<Item *>(intp.GetObject(itemId, "megaShieldItem")));
174                 guy.SetHelmet(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoHelmetItem")));
175                 guy.SetRing(reinterpret_cast<Item *>(intp.GetObject(itemId, "powerRingItem")));
176                 guy.SetJewel(reinterpret_cast<Item *>(intp.GetObject(itemId, "evilJewelItem")));
177
178                 // NOTE: this is actually Artea equipment
179 //              dekar.SetWeapon(reinterpret_cast<Item *>(intp.GetObject(itemId, "lizardBlowItem")));
180                 dekar.SetArmor(reinterpret_cast<Item *>(intp.GetObject(itemId, "holyRobeItem")));
181                 dekar.SetShield(reinterpret_cast<Item *>(intp.GetObject(itemId, "zircoGlovesItem")));
182                 dekar.SetHelmet(reinterpret_cast<Item *>(intp.GetObject(itemId, "holyCapItem")));
183                 dekar.SetRing(reinterpret_cast<Item *>(intp.GetObject(itemId, "rocketRingItem")));
184                 dekar.SetJewel(reinterpret_cast<Item *>(intp.GetObject(itemId, "krakenRockItem")));
185
186                 InitScreen screen(width, height);
187
188                 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, battleRes));
189                 battleState->AddMonster(monster);
190                 battleState->AddMonster(monster);
191                 battleState->AddMonster(monster);
192                 battleState->AddMonster(monster);
193                 battleState->AddHero(maxim);
194                 battleState->AddHero(selan);
195                 battleState->AddHero(guy);
196                 battleState->AddHero(dekar);
197                 Application app(&screen, battleState);
198                 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
199                 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
200                 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
201                 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
202                 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
203                 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
204                 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
205                 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
206                 app.Buttons().MapKey(SDLK_RETURN, Input::START);
207                 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
208                 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
209                 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
210                 app.Run();
211
212                 return 0;
213         } catch (Parser::Error &e) {
214                 cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl;
215                 return 1;
216         } catch (exception &e) {
217                 cerr << "exception in main(): " << e.what() << endl;
218                 return 1;
219         }
220 }