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 "graphics/Texture.h"
34 #include "loader/Caster.h"
35 #include "loader/Interpreter.h"
36 #include "loader/ParsedSource.h"
37 #include "loader/Parser.h"
38 #include "loader/TypeDescription.h"
40 #include "map/Entity.h"
42 #include "map/MapState.h"
44 #include "map/Trigger.h"
45 #include "menu/Resources.h"
46 #include "sdl/InitImage.h"
47 #include "sdl/InitScreen.h"
48 #include "sdl/InitSDL.h"
57 #include <SDL_image.h>
59 using app::Application;
62 using battle::BattleState;
63 using battle::Monster;
64 using battle::PartyLayout;
65 using common::GameConfig;
66 using common::GameState;
68 using geometry::Vector;
69 using graphics::Texture;
71 using loader::Interpreter;
72 using loader::ParsedSource;
74 using loader::TypeDescription;
78 using sdl::InitScreen;
88 int main(int argc, char **argv) {
89 const int width = 512;
90 const int height = 448;
92 const float walkSpeed = 128.0f;
96 // std::srand(std::time(0));
100 InitImage image(IMG_INIT_PNG);
102 Interpreter::CreateTypeDescriptions();
104 battle::Resources::CreateTypeDescription();
105 battle::Monster::CreateTypeDescription();
106 battle::PartyLayout::CreateTypeDescription();
108 common::Hero::CreateTypeDescription();
109 common::Ikari::CreateTypeDescription();
110 common::Item::CreateTypeDescription();
111 common::Stats::CreateTypeDescription();
112 common::Spell::CreateTypeDescription();
113 common::TargetingMode::CreateTypeDescription();
115 graphics::Animation::CreateTypeDescription();
116 graphics::ComplexAnimation::CreateTypeDescription();
117 graphics::Font::CreateTypeDescription();
118 graphics::Frame::CreateTypeDescription();
119 graphics::Gauge::CreateTypeDescription();
120 graphics::MenuProperties::CreateTypeDescription();
121 graphics::SimpleAnimation::CreateTypeDescription();
122 graphics::Sprite::CreateTypeDescription();
124 map::Area::CreateTypeDescription();
125 map::Entity::CreateTypeDescription();
126 map::Map::CreateTypeDescription();
127 map::Tile::CreateTypeDescription();
128 map::Trigger::CreateTypeDescription();
131 args.Read(argc, argv);
135 for (vector<char *>::const_iterator i(args.Infiles().begin()), end(args.Infiles().end()); i != end; ++i) {
136 Parser(*i, source).Parse();
139 switch (args.GetRunLevel()) {
140 case Arguments::WRITE:
142 int length(std::strlen(args.OutfilePath()));
143 switch (args.OutfilePath()[length - 1]) {
145 std::ofstream outstream(args.OutfilePath());
146 source.WriteHeader(outstream);
150 throw std::runtime_error(string("don't know how to write file ") + args.OutfilePath());
155 case Arguments::DUMP: {
156 std::cout << source << std::endl;
159 case Arguments::SOURCE_WIKI: {
160 TypeDescription::WriteSourceWiki(std::cout);
163 case Arguments::BATTLE:
166 case Arguments::PLAY:
171 Interpreter intp(source);
174 if (intp.PostponedDefinitions().size() > 0) {
175 for (vector<Interpreter::PostponedDefinition>::const_iterator i(intp.PostponedDefinitions().begin()), end(intp.PostponedDefinitions().end()); i != end; ++i) {
176 std::cerr << "missing definition of " << TypeDescription::Get(i->linkedType).TypeName() << " " << i->identifier << std::endl;
185 gameState.heroes[0] = *caster.GetHero("maxim");
186 gameState.heroes[1] = *caster.GetHero("selan");
187 gameState.heroes[2] = *caster.GetHero("guy");
188 gameState.heroes[3] = *caster.GetHero("dekar");
190 gameState.party[0] = &gameState.heroes[0];
191 gameState.party[1] = &gameState.heroes[1];
192 gameState.party[2] = &gameState.heroes[2];
193 gameState.party[3] = &gameState.heroes[3];
195 GameConfig gameConfig;
196 gameConfig.state = &gameState;
197 gameConfig.heroesLayout = caster.GetPartyLayout("heroesLayout");
198 gameConfig.battleResources = caster.GetBattleResources("battleResources");
200 // temporary test data
201 SDL_Surface *bg(IMG_Load("test-data/battle-bg.png"));
202 PartyLayout monstersLayout(*caster.GetPartyLayout("monstersLayout"));
204 Monster monster(*caster.GetMonster("lizard"));
206 gameState.heroes[0].AddSpell(caster.GetSpell("resetSpell"));
207 Spell *strongSpell(caster.GetSpell("strongSpell"));
208 gameState.heroes[0].AddSpell(strongSpell);
209 gameState.heroes[1].AddSpell(strongSpell);
210 Spell *strongerSpell(caster.GetSpell("strongerSpell"));
211 gameState.heroes[0].AddSpell(strongerSpell);
212 gameState.heroes[1].AddSpell(strongerSpell);
213 Spell *championSpell(caster.GetSpell("championSpell"));
214 gameState.heroes[0].AddSpell(championSpell);
215 gameState.heroes[1].AddSpell(championSpell);
216 Spell *rallySpell(caster.GetSpell("rallySpell"));
217 gameState.heroes[0].AddSpell(rallySpell);
218 gameState.heroes[1].AddSpell(rallySpell);
219 gameState.heroes[1].AddSpell(caster.GetSpell("escapeSpell"));
220 Spell *valorSpell(caster.GetSpell("valorSpell"));
221 gameState.heroes[0].AddSpell(valorSpell);
222 gameState.heroes[1].AddSpell(valorSpell);
224 gameState.inventory.Add(caster.GetItem("antidoteItem"), 9);
225 gameState.inventory.Add(caster.GetItem("magicJarItem"), 4);
226 gameState.inventory.Add(caster.GetItem("hiPotionItem"), 4);
227 gameState.inventory.Add(caster.GetItem("powerPotionItem"), 4);
228 gameState.inventory.Add(caster.GetItem("escapeItem"), 2);
229 gameState.inventory.Add(caster.GetItem("sleepBallItem"), 1);
231 gameState.heroes[0].SetWeapon(caster.GetItem("zircoSwordItem"));
232 gameState.heroes[0].SetArmor(caster.GetItem("zirconArmorItem"));
233 gameState.heroes[0].SetShield(caster.GetItem("holyShieldItem"));
234 gameState.heroes[0].SetHelmet(caster.GetItem("legendHelmItem"));
235 gameState.heroes[0].SetRing(caster.GetItem("sProRingItem"));
236 gameState.heroes[0].SetJewel(caster.GetItem("evilJewelItem"));
238 // gameState.heroes[1].SetWeapon(cst.GetItem("zircoWhipItem"));
239 gameState.heroes[1].SetArmor(caster.GetItem("zirconPlateItem"));
240 gameState.heroes[1].SetShield(caster.GetItem("zircoGlovesItem"));
241 gameState.heroes[1].SetHelmet(caster.GetItem("holyCapItem"));
242 gameState.heroes[1].SetRing(caster.GetItem("ghostRingItem"));
243 gameState.heroes[1].SetJewel(caster.GetItem("eagleRockItem"));
245 // gameState.heroes[2].SetWeapon(cst.GetItem("zircoAxItem"));
246 gameState.heroes[2].SetArmor(caster.GetItem("zirconArmorItem"));
247 gameState.heroes[2].SetShield(caster.GetItem("megaShieldItem"));
248 gameState.heroes[2].SetHelmet(caster.GetItem("zircoHelmetItem"));
249 gameState.heroes[2].SetRing(caster.GetItem("powerRingItem"));
250 gameState.heroes[2].SetJewel(caster.GetItem("evilJewelItem"));
252 // NOTE: this is actually Artea equipment
253 // gameState.heroes[3].SetWeapon(cst.GetItem("lizardBlowItem"));
254 gameState.heroes[3].SetArmor(caster.GetItem("holyRobeItem"));
255 gameState.heroes[3].SetShield(caster.GetItem("zircoGlovesItem"));
256 gameState.heroes[3].SetHelmet(caster.GetItem("holyCapItem"));
257 gameState.heroes[3].SetRing(caster.GetItem("rocketRingItem"));
258 gameState.heroes[3].SetJewel(caster.GetItem("krakenRockItem"));
260 gameState.heroes[0].MapEntity().Position() = Vector<float>(64, 128);
262 gameState.heroes[1].MapEntity().Position() = Vector<float>(64, 128);
263 gameState.heroes[1].MapEntity().SetFlags(Entity::FLAG_NONBLOCKING);
264 gameState.heroes[0].MapEntity().AddFollower(&gameState.heroes[1].MapEntity());
266 gameState.heroes[2].MapEntity().Position() = Vector<float>(64, 128);
267 gameState.heroes[2].MapEntity().SetFlags(Entity::FLAG_NONBLOCKING);
268 gameState.heroes[1].MapEntity().AddFollower(&gameState.heroes[2].MapEntity());
270 gameState.heroes[3].MapEntity().Position() = Vector<float>(64, 128);
271 gameState.heroes[3].MapEntity().SetFlags(Entity::FLAG_NONBLOCKING);
272 gameState.heroes[2].MapEntity().AddFollower(&gameState.heroes[3].MapEntity());
274 menu::Resources menuResources;
275 gameConfig.menuResources = &menuResources;
278 menubg.SetSurface(IMG_Load("test-data/menubg.png"));
279 menubg.SetSize(Vector<int>(64, 64));
280 menuResources.menubg = &menubg;
282 menuResources.normalFont = gameConfig.battleResources->normalFont;
284 graphics::Sprite statusLabels(IMG_Load("test-data/status-labels.png"), 32, 16);
285 menuResources.statusLabels = &statusLabels;
287 graphics::Frame statusFrame(IMG_Load("test-data/status-frame.png"), 32, 32, 32, 32);
288 menuResources.statusFrame = &statusFrame;
290 InitScreen screen(width, height);
292 app::State *state(0);
295 BattleState *battleState(new BattleState(&gameConfig, bg, &monstersLayout));
296 battleState->AddMonster(monster);
297 battleState->AddMonster(monster);
298 battleState->AddMonster(monster);
299 battleState->AddMonster(monster);
300 battleState->AddHero(gameState.heroes[0]);
301 battleState->AddHero(gameState.heroes[1]);
302 battleState->AddHero(gameState.heroes[2]);
303 battleState->AddHero(gameState.heroes[3]);
306 MapState *mapState(new MapState(&gameConfig, caster.GetMap("map1")));
308 mapState->ControlEntity(&gameState.heroes[0].MapEntity());
309 mapState->SetWalkingSpeed(walkSpeed);
314 Application app(screen, state);
315 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
316 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
317 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
318 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
319 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
320 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
321 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
322 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
323 app.Buttons().MapKey(SDLK_RETURN, Input::START);
324 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
325 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
326 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
327 app.Buttons().MapKey(SDLK_1, Input::DEBUG_1);
328 app.Buttons().MapKey(SDLK_2, Input::DEBUG_2);
329 app.Buttons().MapKey(SDLK_3, Input::DEBUG_3);
330 app.Buttons().MapKey(SDLK_4, Input::DEBUG_4);
334 } catch (Parser::Error &e) {
335 cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl;
337 } catch (exception &e) {
338 cerr << "exception in main(): " << e.what() << endl;