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