]> git.localhorst.tv Git - l2e.git/blob - src/main.cpp
added interpretation of battle resources
[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(intp.GetBattleResources("battleResources"));
103
104                 maxim.AddSpell(intp.GetSpell("resetSpell"));
105                 Spell *strongSpell(intp.GetSpell("strongSpell"));
106                 maxim.AddSpell(strongSpell);
107                 selan.AddSpell(strongSpell);
108                 Spell *strongerSpell(intp.GetSpell("strongerSpell"));
109                 maxim.AddSpell(strongerSpell);
110                 selan.AddSpell(strongerSpell);
111                 Spell *championSpell(intp.GetSpell("championSpell"));
112                 maxim.AddSpell(championSpell);
113                 selan.AddSpell(championSpell);
114                 Spell *rallySpell(intp.GetSpell("rallySpell"));
115                 maxim.AddSpell(rallySpell);
116                 selan.AddSpell(rallySpell);
117                 selan.AddSpell(intp.GetSpell("escapeSpell"));
118                 Spell *valorSpell(intp.GetSpell("valorSpell"));
119                 maxim.AddSpell(valorSpell);
120                 selan.AddSpell(valorSpell);
121
122                 Inventory inventory;
123                 inventory.Add(intp.GetItem("antidoteItem"), 9);
124                 inventory.Add(intp.GetItem("magicJarItem"), 4);
125                 inventory.Add(intp.GetItem("hiPotionItem"), 4);
126                 inventory.Add(intp.GetItem("powerPotionItem"), 4);
127                 inventory.Add(intp.GetItem("escapeItem"), 2);
128                 inventory.Add(intp.GetItem("sleepBallItem"), 1);
129                 battleRes->inventory = &inventory;
130
131                 maxim.SetWeapon(intp.GetItem("zircoSwordItem"));
132                 maxim.SetArmor(intp.GetItem("zirconArmorItem"));
133                 maxim.SetShield(intp.GetItem("holyShieldItem"));
134                 maxim.SetHelmet(intp.GetItem("legendHelmItem"));
135                 maxim.SetRing(intp.GetItem("sProRingItem"));
136                 maxim.SetJewel(intp.GetItem("evilJewelItem"));
137
138 //              selan.SetWeapon(intp.GetItem("zircoWhipItem"));
139                 selan.SetArmor(intp.GetItem("zirconPlateItem"));
140                 selan.SetShield(intp.GetItem("zircoGlovesItem"));
141                 selan.SetHelmet(intp.GetItem("holyCapItem"));
142                 selan.SetRing(intp.GetItem("ghostRingItem"));
143                 selan.SetJewel(intp.GetItem("eagleRockItem"));
144
145 //              guy.SetWeapon(intp.GetItem("zircoAxItem"));
146                 guy.SetArmor(intp.GetItem("zirconArmorItem"));
147                 guy.SetShield(intp.GetItem("megaShieldItem"));
148                 guy.SetHelmet(intp.GetItem("zircoHelmetItem"));
149                 guy.SetRing(intp.GetItem("powerRingItem"));
150                 guy.SetJewel(intp.GetItem("evilJewelItem"));
151
152                 // NOTE: this is actually Artea equipment
153 //              dekar.SetWeapon(intp.GetItem("lizardBlowItem"));
154                 dekar.SetArmor(intp.GetItem("holyRobeItem"));
155                 dekar.SetShield(intp.GetItem("zircoGlovesItem"));
156                 dekar.SetHelmet(intp.GetItem("holyCapItem"));
157                 dekar.SetRing(intp.GetItem("rocketRingItem"));
158                 dekar.SetJewel(intp.GetItem("krakenRockItem"));
159
160                 BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, battleRes));
161                 battleState->AddMonster(monster);
162                 battleState->AddMonster(monster);
163                 battleState->AddMonster(monster);
164                 battleState->AddMonster(monster);
165                 battleState->AddHero(maxim);
166                 battleState->AddHero(selan);
167                 battleState->AddHero(guy);
168                 battleState->AddHero(dekar);
169                 Application app(&screen, battleState);
170                 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
171                 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
172                 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
173                 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
174                 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
175                 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
176                 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
177                 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
178                 app.Buttons().MapKey(SDLK_RETURN, Input::START);
179                 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
180                 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
181                 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
182                 app.Run();
183
184                 return 0;
185         } catch (Parser::Error &e) {
186                 cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl;
187                 return 1;
188         } catch (exception &e) {
189                 cerr << "exception in main(): " << e.what() << endl;
190                 return 1;
191         }
192 }