1 #include "app/Application.h"
2 #include "app/Arguments.h"
4 #include "battle/BattleState.h"
5 #include "battle/Capsule.h"
6 #include "battle/Hero.h"
7 #include "battle/Monster.h"
8 #include "battle/PartyLayout.h"
9 #include "battle/Resources.h"
10 #include "common/Capsule.h"
11 #include "common/GameConfig.h"
12 #include "common/GameState.h"
13 #include "common/Hero.h"
14 #include "common/Ikari.h"
15 #include "common/Inventory.h"
16 #include "common/Item.h"
17 #include "common/Script.h"
18 #include "common/Spell.h"
19 #include "common/Stats.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 "graphics/Texture.h"
29 #include "loader/Caster.h"
30 #include "loader/Interpreter.h"
31 #include "loader/ParsedSource.h"
32 #include "loader/Parser.h"
33 #include "loader/TypeDescription.h"
35 #include "map/Entity.h"
37 #include "map/MapState.h"
39 #include "map/Trigger.h"
40 #include "menu/Resources.h"
41 #include "sdl/InitImage.h"
42 #include "sdl/InitScreen.h"
43 #include "sdl/InitSDL.h"
52 #include <SDL_image.h>
54 using app::Application;
57 using battle::BattleState;
58 using battle::Monster;
59 using battle::PartyLayout;
60 using common::Capsule;
61 using common::GameConfig;
62 using common::GameState;
65 using geometry::Vector;
66 using graphics::Texture;
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 = 512;
87 const int height = 448;
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::Capsule::CreateTypeDescription();
106 common::Hero::CreateTypeDescription();
107 common::Ikari::CreateTypeDescription();
108 common::Item::CreateTypeDescription();
109 common::Stats::CreateTypeDescription();
110 common::Spell::CreateTypeDescription();
111 common::TargetingMode::CreateTypeDescription();
113 graphics::Animation::CreateTypeDescription();
114 graphics::ComplexAnimation::CreateTypeDescription();
115 graphics::Font::CreateTypeDescription();
116 graphics::Frame::CreateTypeDescription();
117 graphics::Gauge::CreateTypeDescription();
118 graphics::MenuProperties::CreateTypeDescription();
119 graphics::SimpleAnimation::CreateTypeDescription();
120 graphics::Sprite::CreateTypeDescription();
121 graphics::Texture::CreateTypeDescription();
123 map::Area::CreateTypeDescription();
124 map::Entity::CreateTypeDescription();
125 map::Map::CreateTypeDescription();
126 map::Tile::CreateTypeDescription();
127 map::Trigger::CreateTypeDescription();
129 menu::Resources::CreateTypeDescription();
132 args.Read(argc, argv);
136 for (vector<char *>::const_iterator i(args.Infiles().begin()), end(args.Infiles().end()); i != end; ++i) {
137 Parser(*i, source).Parse();
140 switch (args.GetRunLevel()) {
141 case Arguments::WRITE:
143 int length(std::strlen(args.OutfilePath()));
144 switch (args.OutfilePath()[length - 1]) {
146 std::ofstream outstream(args.OutfilePath());
147 source.WriteHeader(outstream);
151 throw std::runtime_error(string("don't know how to write file ") + args.OutfilePath());
156 case Arguments::DUMP: {
157 std::cout << source << std::endl;
160 case Arguments::SOURCE_WIKI: {
161 TypeDescription::WriteSourceWiki(std::cout);
164 case Arguments::BATTLE:
167 case Arguments::PLAY:
172 Interpreter intp(source);
175 if (intp.PostponedDefinitions().size() > 0) {
176 for (vector<Interpreter::PostponedDefinition>::const_iterator i(intp.PostponedDefinitions().begin()), end(intp.PostponedDefinitions().end()); i != end; ++i) {
177 std::cerr << "missing definition of " << TypeDescription::Get(i->linkedType).TypeName() << " " << i->identifier << std::endl;
186 gameState.heroes[0] = *caster.GetHero("maxim");
187 gameState.heroes[1] = *caster.GetHero("selan");
188 gameState.heroes[2] = *caster.GetHero("guy");
189 gameState.heroes[3] = *caster.GetHero("dekar");
191 gameState.party[0] = &gameState.heroes[0];
192 gameState.party[1] = &gameState.heroes[1];
193 gameState.party[2] = &gameState.heroes[2];
194 gameState.party[3] = &gameState.heroes[3];
195 gameState.partySize = 4;
197 gameState.capsules[0] = *caster.GetCapsule("flash");
198 gameState.capsule = gameState.capsules;
200 GameConfig gameConfig;
201 gameConfig.state = &gameState;
202 gameConfig.heroesLayout = caster.GetPartyLayout("heroesLayout");
203 gameConfig.battleResources = caster.GetBattleResources("battleResources");
204 gameConfig.menuResources = caster.GetMenuResources("menuResources");
206 // temporary test data
207 SDL_Surface *bg(IMG_Load("test-data/battle-bg.png"));
208 PartyLayout monstersLayout(*caster.GetPartyLayout("monstersLayout"));
210 Monster monster(*caster.GetMonster("lizard"));
212 gameState.heroes[0].AddSpell(caster.GetSpell("resetSpell"));
213 Spell *strongSpell(caster.GetSpell("strongSpell"));
214 gameState.heroes[0].AddSpell(strongSpell);
215 gameState.heroes[1].AddSpell(strongSpell);
216 Spell *strongerSpell(caster.GetSpell("strongerSpell"));
217 gameState.heroes[0].AddSpell(strongerSpell);
218 gameState.heroes[1].AddSpell(strongerSpell);
219 Spell *championSpell(caster.GetSpell("championSpell"));
220 gameState.heroes[0].AddSpell(championSpell);
221 gameState.heroes[1].AddSpell(championSpell);
222 Spell *rallySpell(caster.GetSpell("rallySpell"));
223 gameState.heroes[0].AddSpell(rallySpell);
224 gameState.heroes[1].AddSpell(rallySpell);
225 gameState.heroes[1].AddSpell(caster.GetSpell("escapeSpell"));
226 Spell *valorSpell(caster.GetSpell("valorSpell"));
227 gameState.heroes[0].AddSpell(valorSpell);
228 gameState.heroes[1].AddSpell(valorSpell);
230 gameState.inventory.Add(caster.GetItem("zirconPlateItem"));
231 gameState.inventory.Add(caster.GetItem("antidoteItem"), 9);
232 gameState.inventory.Add(caster.GetItem("powerRingItem"));
233 gameState.inventory.Add(caster.GetItem("magicJarItem"), 4);
234 gameState.inventory.Add(caster.GetItem("sProRingItem"));
235 gameState.inventory.Add(caster.GetItem("hiPotionItem"), 4);
236 gameState.inventory.Add(caster.GetItem("powerRingItem"));
237 gameState.inventory.Add(caster.GetItem("powerPotionItem"), 4);
238 gameState.inventory.Add(caster.GetItem("zircoSwordItem"));
239 gameState.inventory.Add(caster.GetItem("escapeItem"), 2);
240 gameState.inventory.Add(caster.GetItem("zircoHelmetItem"));
241 gameState.inventory.Add(caster.GetItem("sleepBallItem"), 1);
242 gameState.inventory.Add(caster.GetItem("zirconPlateItem"));
244 gameState.heroes[0].SetEquipment(Hero::EQUIP_WEAPON, caster.GetItem("zircoSwordItem"));
245 gameState.heroes[0].SetEquipment(Hero::EQUIP_ARMOR, caster.GetItem("zirconArmorItem"));
246 gameState.heroes[0].SetEquipment(Hero::EQUIP_SHIELD, caster.GetItem("holyShieldItem"));
247 gameState.heroes[0].SetEquipment(Hero::EQUIP_HELMET, caster.GetItem("legendHelmItem"));
248 gameState.heroes[0].SetEquipment(Hero::EQUIP_RING, caster.GetItem("sProRingItem"));
249 gameState.heroes[0].SetEquipment(Hero::EQUIP_JEWEL, caster.GetItem("evilJewelItem"));
251 // gameState.heroes[1].SetEquipment(Hero::EQUIP_WEAPON, caster.GetItem("zircoWhipItem"));
252 gameState.heroes[1].SetEquipment(Hero::EQUIP_ARMOR, caster.GetItem("zirconPlateItem"));
253 gameState.heroes[1].SetEquipment(Hero::EQUIP_SHIELD, caster.GetItem("zircoGlovesItem"));
254 gameState.heroes[1].SetEquipment(Hero::EQUIP_HELMET, caster.GetItem("holyCapItem"));
255 gameState.heroes[1].SetEquipment(Hero::EQUIP_RING, caster.GetItem("ghostRingItem"));
256 gameState.heroes[1].SetEquipment(Hero::EQUIP_JEWEL, caster.GetItem("eagleRockItem"));
258 // gameState.heroes[2].SetEquipment(Hero::EQUIP_WEAPON, caster.GetItem("zircoAxItem"));
259 gameState.heroes[2].SetEquipment(Hero::EQUIP_ARMOR, caster.GetItem("zirconArmorItem"));
260 gameState.heroes[2].SetEquipment(Hero::EQUIP_SHIELD, caster.GetItem("megaShieldItem"));
261 gameState.heroes[2].SetEquipment(Hero::EQUIP_HELMET, caster.GetItem("zircoHelmetItem"));
262 gameState.heroes[2].SetEquipment(Hero::EQUIP_RING, caster.GetItem("powerRingItem"));
263 gameState.heroes[2].SetEquipment(Hero::EQUIP_JEWEL, caster.GetItem("evilJewelItem"));
265 // NOTE: this is actually Artea equipment
266 // gameState.heroes[3].SetEquipment(Hero::EQUIP_WEAPON, caster.GetItem("lizardBlowItem"));
267 gameState.heroes[3].SetEquipment(Hero::EQUIP_ARMOR, caster.GetItem("holyRobeItem"));
268 gameState.heroes[3].SetEquipment(Hero::EQUIP_SHIELD, caster.GetItem("zircoGlovesItem"));
269 gameState.heroes[3].SetEquipment(Hero::EQUIP_HELMET, caster.GetItem("holyCapItem"));
270 gameState.heroes[3].SetEquipment(Hero::EQUIP_RING, caster.GetItem("rocketRingItem"));
271 gameState.heroes[3].SetEquipment(Hero::EQUIP_JEWEL, caster.GetItem("krakenRockItem"));
273 gameState.heroes[0].MapEntity().Position() = Vector<float>(64, 128);
275 gameState.heroes[1].MapEntity().Position() = Vector<float>(64, 128);
276 gameState.heroes[1].MapEntity().SetFlags(Entity::FLAG_NONBLOCKING);
277 gameState.heroes[0].MapEntity().AddFollower(&gameState.heroes[1].MapEntity());
279 gameState.heroes[2].MapEntity().Position() = Vector<float>(64, 128);
280 gameState.heroes[2].MapEntity().SetFlags(Entity::FLAG_NONBLOCKING);
281 gameState.heroes[1].MapEntity().AddFollower(&gameState.heroes[2].MapEntity());
283 gameState.heroes[3].MapEntity().Position() = Vector<float>(64, 128);
284 gameState.heroes[3].MapEntity().SetFlags(Entity::FLAG_NONBLOCKING);
285 gameState.heroes[2].MapEntity().AddFollower(&gameState.heroes[3].MapEntity());
287 InitScreen screen(width, height);
289 app::State *state(0);
292 BattleState *battleState(new BattleState(&gameConfig, bg, &monstersLayout));
293 battleState->AddMonster(monster);
294 battleState->AddMonster(monster);
295 battleState->AddMonster(monster);
296 battleState->AddMonster(monster);
297 battleState->SetCapsule(caster.GetCapsule("flash"));
298 battleState->AddHero(gameState.heroes[0]);
299 battleState->AddHero(gameState.heroes[1]);
300 battleState->AddHero(gameState.heroes[2]);
301 battleState->AddHero(gameState.heroes[3]);
304 MapState *mapState(new MapState(&gameConfig, caster.GetMap("map1")));
306 mapState->ControlEntity(&gameState.heroes[0].MapEntity());
307 mapState->SetWalkingSpeed(walkSpeed);
312 Application app(screen, state);
313 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
314 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
315 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
316 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
317 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
318 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
319 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
320 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
321 app.Buttons().MapKey(SDLK_RETURN, Input::START);
322 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
323 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
324 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
325 app.Buttons().MapKey(SDLK_1, Input::DEBUG_1);
326 app.Buttons().MapKey(SDLK_2, Input::DEBUG_2);
327 app.Buttons().MapKey(SDLK_3, Input::DEBUG_3);
328 app.Buttons().MapKey(SDLK_4, Input::DEBUG_4);
332 } catch (Parser::Error &e) {
333 cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl;
335 } catch (exception &e) {
336 cerr << "exception in main(): " << e.what() << endl;