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/CharSelect.h"
22 #include "graphics/ComplexAnimation.h"
23 #include "graphics/Font.h"
24 #include "graphics/Frame.h"
25 #include "graphics/Gauge.h"
26 #include "graphics/Menu.h"
27 #include "graphics/SimpleAnimation.h"
28 #include "graphics/Sprite.h"
29 #include "graphics/Texture.h"
30 #include "loader/Caster.h"
31 #include "loader/Interpreter.h"
32 #include "loader/ParsedSource.h"
33 #include "loader/Parser.h"
34 #include "loader/TypeDescription.h"
36 #include "map/Entity.h"
38 #include "map/MapState.h"
40 #include "map/Trigger.h"
41 #include "menu/Resources.h"
42 #include "sdl/InitImage.h"
43 #include "sdl/InitScreen.h"
44 #include "sdl/InitSDL.h"
53 #include <SDL_image.h>
55 using app::Application;
58 using battle::BattleState;
59 using battle::Monster;
60 using battle::PartyLayout;
61 using common::Capsule;
62 using common::GameConfig;
63 using common::GameState;
66 using geometry::Vector;
67 using graphics::Texture;
69 using loader::Interpreter;
70 using loader::ParsedSource;
72 using loader::TypeDescription;
76 using sdl::InitScreen;
86 int main(int argc, char **argv) {
87 const int width = 512;
88 const int height = 448;
90 const float walkSpeed = 128.0f;
94 // std::srand(std::time(0));
98 InitImage image(IMG_INIT_PNG);
100 Interpreter::CreateTypeDescriptions();
102 battle::Resources::CreateTypeDescription();
103 battle::Monster::CreateTypeDescription();
104 battle::PartyLayout::CreateTypeDescription();
106 common::Capsule::CreateTypeDescription();
107 common::Hero::CreateTypeDescription();
108 common::Ikari::CreateTypeDescription();
109 common::Item::CreateTypeDescription();
110 common::Stats::CreateTypeDescription();
111 common::Spell::CreateTypeDescription();
112 common::TargetingMode::CreateTypeDescription();
114 graphics::Animation::CreateTypeDescription();
115 graphics::CharSelect::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();
123 graphics::Texture::CreateTypeDescription();
125 map::Area::CreateTypeDescription();
126 map::Entity::CreateTypeDescription();
127 map::Map::CreateTypeDescription();
128 map::Tile::CreateTypeDescription();
129 map::Trigger::CreateTypeDescription();
131 menu::Resources::CreateTypeDescription();
134 args.Read(argc, argv);
138 for (vector<char *>::const_iterator i(args.Infiles().begin()), end(args.Infiles().end()); i != end; ++i) {
139 Parser(*i, source).Parse();
142 switch (args.GetRunLevel()) {
143 case Arguments::WRITE:
145 int length(std::strlen(args.OutfilePath()));
146 switch (args.OutfilePath()[length - 1]) {
148 std::ofstream outstream(args.OutfilePath());
149 source.WriteHeader(outstream);
153 throw std::runtime_error(string("don't know how to write file ") + args.OutfilePath());
158 case Arguments::DUMP: {
159 std::cout << source << std::endl;
162 case Arguments::SOURCE_WIKI: {
163 TypeDescription::WriteSourceWiki(std::cout);
166 case Arguments::BATTLE:
169 case Arguments::PLAY:
174 Interpreter intp(source);
177 if (intp.PostponedDefinitions().size() > 0) {
178 for (vector<Interpreter::PostponedDefinition>::const_iterator i(intp.PostponedDefinitions().begin()), end(intp.PostponedDefinitions().end()); i != end; ++i) {
179 std::cerr << "missing definition of " << TypeDescription::Get(i->linkedType).TypeName() << " " << i->identifier << std::endl;
188 gameState.heroes[0] = *caster.GetHero("maxim");
189 gameState.heroes[1] = *caster.GetHero("selan");
190 gameState.heroes[2] = *caster.GetHero("guy");
191 gameState.heroes[3] = *caster.GetHero("dekar");
193 gameState.party[0] = &gameState.heroes[0];
194 gameState.party[1] = &gameState.heroes[1];
195 gameState.party[2] = &gameState.heroes[2];
196 gameState.party[3] = &gameState.heroes[3];
197 gameState.partySize = 4;
199 gameState.capsules[1] = *caster.GetCapsule("flash");
200 gameState.capsules[1].UpgradeClass();
201 gameState.capsules[1].UpgradeClass();
202 gameState.capsules[1].UpgradeClass();
203 gameState.capsules[1].UpgradeClass();
204 gameState.capsule = 1;
206 GameConfig gameConfig;
207 gameConfig.state = &gameState;
208 gameConfig.heroesLayout = caster.GetPartyLayout("heroesLayout");
209 gameConfig.battleResources = caster.GetBattleResources("battleResources");
210 gameConfig.menuResources = caster.GetMenuResources("menuResources");
212 // temporary test data
213 SDL_Surface *bg(IMG_Load("test-data/battle-bg.png"));
214 PartyLayout monstersLayout(*caster.GetPartyLayout("monstersLayout"));
216 Monster monster(*caster.GetMonster("lizard"));
218 gameState.heroes[0].AddSpell(caster.GetSpell("resetSpell"));
219 Spell *strongSpell(caster.GetSpell("strongSpell"));
220 gameState.heroes[0].AddSpell(strongSpell);
221 gameState.heroes[1].AddSpell(strongSpell);
222 Spell *strongerSpell(caster.GetSpell("strongerSpell"));
223 gameState.heroes[0].AddSpell(strongerSpell);
224 gameState.heroes[1].AddSpell(strongerSpell);
225 Spell *championSpell(caster.GetSpell("championSpell"));
226 gameState.heroes[0].AddSpell(championSpell);
227 gameState.heroes[1].AddSpell(championSpell);
228 Spell *rallySpell(caster.GetSpell("rallySpell"));
229 gameState.heroes[0].AddSpell(rallySpell);
230 gameState.heroes[1].AddSpell(rallySpell);
231 gameState.heroes[1].AddSpell(caster.GetSpell("escapeSpell"));
232 Spell *valorSpell(caster.GetSpell("valorSpell"));
233 gameState.heroes[0].AddSpell(valorSpell);
234 gameState.heroes[1].AddSpell(valorSpell);
236 gameState.inventory.Add(caster.GetItem("zirconPlateItem"), 32);
237 gameState.inventory.Add(caster.GetItem("holyFruitItem"));
238 gameState.inventory.Add(caster.GetItem("darkFruitItem"));
239 gameState.inventory.Add(caster.GetItem("antidoteItem"), 9);
240 gameState.inventory.Add(caster.GetItem("powerRingItem"));
241 gameState.inventory.Add(caster.GetItem("magicJarItem"), 4);
242 gameState.inventory.Add(caster.GetItem("sProRingItem"));
243 gameState.inventory.Add(caster.GetItem("hiPotionItem"), 4);
244 gameState.inventory.Add(caster.GetItem("powerRingItem"));
245 gameState.inventory.Add(caster.GetItem("powerPotionItem"), 4);
246 gameState.inventory.Add(caster.GetItem("zircoSwordItem"));
247 gameState.inventory.Add(caster.GetItem("escapeItem"), 2);
248 gameState.inventory.Add(caster.GetItem("zircoHelmetItem"));
249 gameState.inventory.Add(caster.GetItem("sleepBallItem"), 1);
250 gameState.inventory.Add(caster.GetItem("zirconPlateItem"));
252 gameState.heroes[0].SetEquipment(Hero::EQUIP_WEAPON, caster.GetItem("zircoSwordItem"));
253 gameState.heroes[0].SetEquipment(Hero::EQUIP_ARMOR, caster.GetItem("zirconArmorItem"));
254 gameState.heroes[0].SetEquipment(Hero::EQUIP_SHIELD, caster.GetItem("holyShieldItem"));
255 gameState.heroes[0].SetEquipment(Hero::EQUIP_HELMET, caster.GetItem("legendHelmItem"));
256 gameState.heroes[0].SetEquipment(Hero::EQUIP_RING, caster.GetItem("sProRingItem"));
257 gameState.heroes[0].SetEquipment(Hero::EQUIP_JEWEL, caster.GetItem("evilJewelItem"));
259 // gameState.heroes[1].SetEquipment(Hero::EQUIP_WEAPON, caster.GetItem("zircoWhipItem"));
260 gameState.heroes[1].SetEquipment(Hero::EQUIP_ARMOR, caster.GetItem("zirconPlateItem"));
261 gameState.heroes[1].SetEquipment(Hero::EQUIP_SHIELD, caster.GetItem("zircoGlovesItem"));
262 gameState.heroes[1].SetEquipment(Hero::EQUIP_HELMET, caster.GetItem("holyCapItem"));
263 gameState.heroes[1].SetEquipment(Hero::EQUIP_RING, caster.GetItem("ghostRingItem"));
264 gameState.heroes[1].SetEquipment(Hero::EQUIP_JEWEL, caster.GetItem("eagleRockItem"));
266 // gameState.heroes[2].SetEquipment(Hero::EQUIP_WEAPON, caster.GetItem("zircoAxItem"));
267 gameState.heroes[2].SetEquipment(Hero::EQUIP_ARMOR, caster.GetItem("zirconArmorItem"));
268 gameState.heroes[2].SetEquipment(Hero::EQUIP_SHIELD, caster.GetItem("megaShieldItem"));
269 gameState.heroes[2].SetEquipment(Hero::EQUIP_HELMET, caster.GetItem("zircoHelmetItem"));
270 gameState.heroes[2].SetEquipment(Hero::EQUIP_RING, caster.GetItem("powerRingItem"));
271 gameState.heroes[2].SetEquipment(Hero::EQUIP_JEWEL, caster.GetItem("evilJewelItem"));
273 // NOTE: this is actually Artea equipment
274 // gameState.heroes[3].SetEquipment(Hero::EQUIP_WEAPON, caster.GetItem("lizardBlowItem"));
275 gameState.heroes[3].SetEquipment(Hero::EQUIP_ARMOR, caster.GetItem("holyRobeItem"));
276 gameState.heroes[3].SetEquipment(Hero::EQUIP_SHIELD, caster.GetItem("zircoGlovesItem"));
277 gameState.heroes[3].SetEquipment(Hero::EQUIP_HELMET, caster.GetItem("holyCapItem"));
278 gameState.heroes[3].SetEquipment(Hero::EQUIP_RING, caster.GetItem("rocketRingItem"));
279 gameState.heroes[3].SetEquipment(Hero::EQUIP_JEWEL, caster.GetItem("krakenRockItem"));
281 gameState.heroes[0].MapEntity().Position() = Vector<float>(64, 128);
283 gameState.heroes[1].MapEntity().Position() = Vector<float>(64, 128);
284 gameState.heroes[1].MapEntity().SetFlags(Entity::FLAG_NONBLOCKING);
285 gameState.heroes[0].MapEntity().AddFollower(&gameState.heroes[1].MapEntity());
287 gameState.heroes[2].MapEntity().Position() = Vector<float>(64, 128);
288 gameState.heroes[2].MapEntity().SetFlags(Entity::FLAG_NONBLOCKING);
289 gameState.heroes[1].MapEntity().AddFollower(&gameState.heroes[2].MapEntity());
291 gameState.heroes[3].MapEntity().Position() = Vector<float>(64, 128);
292 gameState.heroes[3].MapEntity().SetFlags(Entity::FLAG_NONBLOCKING);
293 gameState.heroes[2].MapEntity().AddFollower(&gameState.heroes[3].MapEntity());
295 InitScreen screen(width, height);
297 app::State *state(0);
300 BattleState *battleState(new BattleState(&gameConfig, bg, &monstersLayout));
301 battleState->AddMonster(monster);
302 battleState->AddMonster(monster);
303 battleState->AddMonster(monster);
304 battleState->AddMonster(monster);
305 battleState->SetCapsule(caster.GetCapsule("flash"));
306 battleState->AddHero(gameState.heroes[0]);
307 battleState->AddHero(gameState.heroes[1]);
308 battleState->AddHero(gameState.heroes[2]);
309 battleState->AddHero(gameState.heroes[3]);
312 MapState *mapState(new MapState(&gameConfig, caster.GetMap("map1")));
314 mapState->ControlEntity(&gameState.heroes[0].MapEntity());
315 mapState->SetWalkingSpeed(walkSpeed);
320 Application app(screen, state);
321 app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
322 app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
323 app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
324 app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
325 app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
326 app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
327 app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
328 app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
329 app.Buttons().MapKey(SDLK_RETURN, Input::START);
330 app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
331 app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
332 app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
333 app.Buttons().MapKey(SDLK_1, Input::DEBUG_1);
334 app.Buttons().MapKey(SDLK_2, Input::DEBUG_2);
335 app.Buttons().MapKey(SDLK_3, Input::DEBUG_3);
336 app.Buttons().MapKey(SDLK_4, Input::DEBUG_4);
340 } catch (Parser::Error &e) {
341 cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl;
343 } catch (exception &e) {
344 cerr << "exception in main(): " << e.what() << endl;