4 * Created on: Aug 1, 2012
8 #include "app/Application.h"
9 #include "app/Arguments.h"
10 #include "app/Input.h"
11 #include "battle/BattleState.h"
12 #include "battle/Hero.h"
13 #include "battle/Monster.h"
14 #include "battle/PartyLayout.h"
15 #include "battle/Resources.h"
16 #include "common/GameConfig.h"
17 #include "common/GameState.h"
18 #include "common/Hero.h"
19 #include "common/Ikari.h"
20 #include "common/Inventory.h"
21 #include "common/Item.h"
22 #include "common/Script.h"
23 #include "common/Spell.h"
24 #include "common/Stats.h"
25 #include "geometry/Vector.h"
26 #include "graphics/ComplexAnimation.h"
27 #include "graphics/Font.h"
28 #include "graphics/Frame.h"
29 #include "graphics/Gauge.h"
30 #include "graphics/Menu.h"
31 #include "graphics/SimpleAnimation.h"
32 #include "graphics/Sprite.h"
33 #include "loader/Caster.h"
34 #include "loader/Interpreter.h"
35 #include "loader/ParsedSource.h"
36 #include "loader/Parser.h"
37 #include "loader/TypeDescription.h"
39 #include "map/Entity.h"
41 #include "map/MapState.h"
43 #include "map/Trigger.h"
44 #include "sdl/InitImage.h"
45 #include "sdl/InitScreen.h"
46 #include "sdl/InitSDL.h"
55 #include <SDL_image.h>
57 using app::Application;
60 using battle::BattleState;
61 using battle::Monster;
62 using battle::PartyLayout;
63 using common::GameConfig;
64 using common::GameState;
66 using geometry::Vector;
68 using loader::Interpreter;
69 using loader::ParsedSource;
71 using loader::TypeDescription;
75 using sdl::InitScreen;
85 int main(int argc, char **argv) {
86 const int width = 800;
87 const int height = 480;
89 const float walkSpeed = 128.0f;
93 // std::srand(std::time(0));
97 InitImage image(IMG_INIT_PNG);
99 Interpreter::CreateTypeDescriptions();
101 battle::Resources::CreateTypeDescription();
102 battle::Monster::CreateTypeDescription();
103 battle::PartyLayout::CreateTypeDescription();
105 common::Hero::CreateTypeDescription();
106 common::Ikari::CreateTypeDescription();
107 common::Item::CreateTypeDescription();
108 common::Stats::CreateTypeDescription();
109 common::Spell::CreateTypeDescription();
110 common::TargetingMode::CreateTypeDescription();
112 graphics::Animation::CreateTypeDescription();
113 graphics::ComplexAnimation::CreateTypeDescription();
114 graphics::Font::CreateTypeDescription();
115 graphics::Frame::CreateTypeDescription();
116 graphics::Gauge::CreateTypeDescription();
117 graphics::MenuProperties::CreateTypeDescription();
118 graphics::SimpleAnimation::CreateTypeDescription();
119 graphics::Sprite::CreateTypeDescription();
121 map::Area::CreateTypeDescription();
122 map::Entity::CreateTypeDescription();
123 map::Map::CreateTypeDescription();
124 map::Tile::CreateTypeDescription();
125 map::Trigger::CreateTypeDescription();
128 args.Read(argc, argv);
132 for (vector<char *>::const_iterator i(args.Infiles().begin()), end(args.Infiles().end()); i != end; ++i) {
133 Parser(*i, source).Parse();
136 switch (args.GetRunLevel()) {
137 case Arguments::WRITE:
139 int length(std::strlen(args.OutfilePath()));
140 switch (args.OutfilePath()[length - 1]) {
142 std::ofstream outstream(args.OutfilePath());
143 source.WriteHeader(outstream);
147 throw std::runtime_error(string("don't know how to write file ") + args.OutfilePath());
152 case Arguments::DUMP: {
153 std::cout << source << std::endl;
156 case Arguments::SOURCE_WIKI: {
157 TypeDescription::WriteSourceWiki(std::cout);
160 case Arguments::BATTLE:
163 case Arguments::PLAY:
168 Interpreter intp(source);
171 if (intp.PostponedDefinitions().size() > 0) {
172 for (vector<Interpreter::PostponedDefinition>::const_iterator i(intp.PostponedDefinitions().begin()), end(intp.PostponedDefinitions().end()); i != end; ++i) {
173 std::cerr << "missing definition of " << TypeDescription::Get(i->linkedType).TypeName() << " " << i->identifier << std::endl;
182 gameState.heroes[0] = *caster.GetHero("maxim");
183 gameState.heroes[1] = *caster.GetHero("selan");
184 gameState.heroes[2] = *caster.GetHero("guy");
185 gameState.heroes[3] = *caster.GetHero("dekar");
187 gameState.party[0] = &gameState.heroes[0];
188 gameState.party[1] = &gameState.heroes[1];
189 gameState.party[2] = &gameState.heroes[2];
190 gameState.party[3] = &gameState.heroes[3];
192 GameConfig gameConfig;
193 gameConfig.state = &gameState;
194 gameConfig.heroesLayout = caster.GetPartyLayout("heroesLayout");
195 gameConfig.battleResources = caster.GetBattleResources("battleResources");
197 // temporary test data
198 SDL_Surface *bg(IMG_Load("test-data/battle-bg.png"));
199 PartyLayout monstersLayout(*caster.GetPartyLayout("monstersLayout"));
201 Monster monster(*caster.GetMonster("lizard"));
203 gameState.heroes[0].AddSpell(caster.GetSpell("resetSpell"));
204 Spell *strongSpell(caster.GetSpell("strongSpell"));
205 gameState.heroes[0].AddSpell(strongSpell);
206 gameState.heroes[1].AddSpell(strongSpell);
207 Spell *strongerSpell(caster.GetSpell("strongerSpell"));
208 gameState.heroes[0].AddSpell(strongerSpell);
209 gameState.heroes[1].AddSpell(strongerSpell);
210 Spell *championSpell(caster.GetSpell("championSpell"));
211 gameState.heroes[0].AddSpell(championSpell);
212 gameState.heroes[1].AddSpell(championSpell);
213 Spell *rallySpell(caster.GetSpell("rallySpell"));
214 gameState.heroes[0].AddSpell(rallySpell);
215 gameState.heroes[1].AddSpell(rallySpell);
216 gameState.heroes[1].AddSpell(caster.GetSpell("escapeSpell"));
217 Spell *valorSpell(caster.GetSpell("valorSpell"));
218 gameState.heroes[0].AddSpell(valorSpell);
219 gameState.heroes[1].AddSpell(valorSpell);
221 gameState.inventory.Add(caster.GetItem("antidoteItem"), 9);
222 gameState.inventory.Add(caster.GetItem("magicJarItem"), 4);
223 gameState.inventory.Add(caster.GetItem("hiPotionItem"), 4);
224 gameState.inventory.Add(caster.GetItem("powerPotionItem"), 4);
225 gameState.inventory.Add(caster.GetItem("escapeItem"), 2);
226 gameState.inventory.Add(caster.GetItem("sleepBallItem"), 1);
228 gameState.heroes[0].SetWeapon(caster.GetItem("zircoSwordItem"));
229 gameState.heroes[0].SetArmor(caster.GetItem("zirconArmorItem"));
230 gameState.heroes[0].SetShield(caster.GetItem("holyShieldItem"));
231 gameState.heroes[0].SetHelmet(caster.GetItem("legendHelmItem"));
232 gameState.heroes[0].SetRing(caster.GetItem("sProRingItem"));
233 gameState.heroes[0].SetJewel(caster.GetItem("evilJewelItem"));
235 // gameState.heroes[1].SetWeapon(cst.GetItem("zircoWhipItem"));
236 gameState.heroes[1].SetArmor(caster.GetItem("zirconPlateItem"));
237 gameState.heroes[1].SetShield(caster.GetItem("zircoGlovesItem"));
238 gameState.heroes[1].SetHelmet(caster.GetItem("holyCapItem"));
239 gameState.heroes[1].SetRing(caster.GetItem("ghostRingItem"));
240 gameState.heroes[1].SetJewel(caster.GetItem("eagleRockItem"));
242 // gameState.heroes[2].SetWeapon(cst.GetItem("zircoAxItem"));
243 gameState.heroes[2].SetArmor(caster.GetItem("zirconArmorItem"));
244 gameState.heroes[2].SetShield(caster.GetItem("megaShieldItem"));
245 gameState.heroes[2].SetHelmet(caster.GetItem("zircoHelmetItem"));
246 gameState.heroes[2].SetRing(caster.GetItem("powerRingItem"));
247 gameState.heroes[2].SetJewel(caster.GetItem("evilJewelItem"));
249 // NOTE: this is actually Artea equipment
250 // gameState.heroes[3].SetWeapon(cst.GetItem("lizardBlowItem"));
251 gameState.heroes[3].SetArmor(caster.GetItem("holyRobeItem"));
252 gameState.heroes[3].SetShield(caster.GetItem("zircoGlovesItem"));
253 gameState.heroes[3].SetHelmet(caster.GetItem("holyCapItem"));
254 gameState.heroes[3].SetRing(caster.GetItem("rocketRingItem"));
255 gameState.heroes[3].SetJewel(caster.GetItem("krakenRockItem"));
257 gameState.heroes[0].MapEntity().Position() = Vector<float>(64, 128);
259 gameState.heroes[1].MapEntity().Position() = Vector<float>(64, 128);
260 gameState.heroes[1].MapEntity().SetFlags(Entity::FLAG_NONBLOCKING);
261 gameState.heroes[0].MapEntity().AddFollower(&gameState.heroes[1].MapEntity());
263 gameState.heroes[2].MapEntity().Position() = Vector<float>(64, 128);
264 gameState.heroes[2].MapEntity().SetFlags(Entity::FLAG_NONBLOCKING);
265 gameState.heroes[1].MapEntity().AddFollower(&gameState.heroes[2].MapEntity());
267 gameState.heroes[3].MapEntity().Position() = Vector<float>(64, 128);
268 gameState.heroes[3].MapEntity().SetFlags(Entity::FLAG_NONBLOCKING);
269 gameState.heroes[2].MapEntity().AddFollower(&gameState.heroes[3].MapEntity());
271 InitScreen screen(width, height);
273 app::State *state(0);
276 BattleState *battleState(new BattleState(&gameConfig, bg, &monstersLayout));
277 battleState->AddMonster(monster);
278 battleState->AddMonster(monster);
279 battleState->AddMonster(monster);
280 battleState->AddMonster(monster);
281 battleState->AddHero(gameState.heroes[0]);
282 battleState->AddHero(gameState.heroes[1]);
283 battleState->AddHero(gameState.heroes[2]);
284 battleState->AddHero(gameState.heroes[3]);
287 MapState *mapState(new MapState(&gameConfig, caster.GetMap("map1")));
289 mapState->ControlEntity(&gameState.heroes[0].MapEntity());
290 mapState->SetWalkingSpeed(walkSpeed);
295 Application app(screen, state);
296 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
297 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
298 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
299 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
300 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
301 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
302 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
303 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
304 app.Buttons().MapKey(SDLK_RETURN, Input::START);
305 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
306 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
307 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
308 app.Buttons().MapKey(SDLK_1, Input::DEBUG_1);
309 app.Buttons().MapKey(SDLK_2, Input::DEBUG_2);
310 app.Buttons().MapKey(SDLK_3, Input::DEBUG_3);
311 app.Buttons().MapKey(SDLK_4, Input::DEBUG_4);
315 } catch (Parser::Error &e) {
316 cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl;
318 } catch (exception &e) {
319 cerr << "exception in main(): " << e.what() << endl;