2 #include "app/Application.h"
3 #include "app/Arguments.h"
5 #include "battle/BattleState.h"
6 #include "battle/Capsule.h"
7 #include "battle/Hero.h"
8 #include "battle/Monster.h"
9 #include "battle/PartyLayout.h"
10 #include "battle/Resources.h"
11 #include "common/Capsule.h"
12 #include "common/GameConfig.h"
13 #include "common/GameState.h"
14 #include "common/Hero.h"
15 #include "common/Ikari.h"
16 #include "common/Inventory.h"
17 #include "common/Item.h"
18 #include "common/LevelUp.h"
19 #include "common/Script.h"
20 #include "common/Spell.h"
21 #include "common/Stats.h"
22 #include "math/Fixed.h"
23 #include "math/Vector.h"
24 #include "graphics/CharSelect.h"
25 #include "graphics/ComplexAnimation.h"
26 #include "graphics/Font.h"
27 #include "graphics/Frame.h"
28 #include "graphics/Gauge.h"
29 #include "graphics/Menu.h"
30 #include "graphics/SimpleAnimation.h"
31 #include "graphics/Sprite.h"
32 #include "graphics/Texture.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 "menu/Resources.h"
45 #include "sdl/InitImage.h"
46 #include "sdl/InitScreen.h"
47 #include "sdl/InitSDL.h"
56 #include <SDL_image.h>
58 using app::Application;
61 using battle::BattleState;
62 using battle::Monster;
63 using battle::PartyLayout;
64 using common::Capsule;
65 using common::GameConfig;
66 using common::GameState;
71 using graphics::Texture;
73 using loader::Interpreter;
74 using loader::ParsedSource;
76 using loader::TypeDescription;
80 using sdl::InitScreen;
90 int main(int argc, char **argv) {
91 const int width = 512;
92 const int height = 448;
94 const Fixed<8> walkSpeed = Fixed<8>(1, 8);
98 // std::srand(std::time(0));
102 InitImage image(IMG_INIT_PNG);
104 Interpreter::CreateTypeDescriptions();
106 battle::Resources::CreateTypeDescription();
107 battle::Monster::CreateTypeDescription();
108 battle::PartyLayout::CreateTypeDescription();
110 common::Capsule::CreateTypeDescription();
111 common::Hero::CreateTypeDescription();
112 common::Ikari::CreateTypeDescription();
113 common::Item::CreateTypeDescription();
114 common::LevelUp::CreateTypeDescription();
115 common::Stats::CreateTypeDescription();
116 common::Spell::CreateTypeDescription();
117 common::TargetingMode::CreateTypeDescription();
119 graphics::Animation::CreateTypeDescription();
120 graphics::CharSelect::CreateTypeDescription();
121 graphics::ComplexAnimation::CreateTypeDescription();
122 graphics::Font::CreateTypeDescription();
123 graphics::Frame::CreateTypeDescription();
124 graphics::Gauge::CreateTypeDescription();
125 graphics::MenuProperties::CreateTypeDescription();
126 graphics::SimpleAnimation::CreateTypeDescription();
127 graphics::Sprite::CreateTypeDescription();
128 graphics::Texture::CreateTypeDescription();
130 map::Area::CreateTypeDescription();
131 map::Entity::CreateTypeDescription();
132 map::Map::CreateTypeDescription();
133 map::Tile::CreateTypeDescription();
134 map::Trigger::CreateTypeDescription();
136 menu::Resources::CreateTypeDescription();
139 args.Read(argc, argv);
143 for (vector<char *>::const_iterator i(args.Infiles().begin()), end(args.Infiles().end()); i != end; ++i) {
144 Parser(*i, source).Parse();
147 switch (args.GetRunLevel()) {
148 case Arguments::WRITE:
150 int length(std::strlen(args.OutfilePath()));
151 switch (args.OutfilePath()[length - 1]) {
153 std::ofstream outstream(args.OutfilePath());
154 source.WriteHeader(outstream);
158 throw std::runtime_error(string("don't know how to write file ") + args.OutfilePath());
163 case Arguments::DUMP: {
164 std::cout << source << std::endl;
167 case Arguments::SOURCE_WIKI: {
168 TypeDescription::WriteSourceWiki(std::cout);
171 case Arguments::BATTLE:
174 case Arguments::PLAY:
179 Interpreter intp(source);
182 if (intp.PostponedDefinitions().size() > 0) {
183 for (vector<Interpreter::PostponedDefinition>::const_iterator i(intp.PostponedDefinitions().begin()), end(intp.PostponedDefinitions().end()); i != end; ++i) {
184 std::cerr << "missing definition of " << TypeDescription::Get(i->type).TypeName() << " " << i->identifier << std::endl;
193 gameState.heroes[0] = *caster.GetHero("maxim");
194 gameState.heroes[1] = *caster.GetHero("selan");
195 gameState.heroes[2] = *caster.GetHero("guy");
196 gameState.heroes[3] = *caster.GetHero("dekar");
198 gameState.party[0] = &gameState.heroes[0];
199 gameState.party[1] = &gameState.heroes[1];
200 gameState.party[2] = &gameState.heroes[2];
201 gameState.party[3] = &gameState.heroes[3];
202 gameState.partySize = 4;
204 gameState.capsules[1] = *caster.GetCapsule("flash");
205 gameState.capsules[1].UpgradeClass();
206 gameState.capsules[1].UpgradeClass();
207 gameState.capsules[1].UpgradeClass();
208 gameState.capsules[1].UpgradeClass();
209 gameState.capsule = 1;
211 GameConfig gameConfig;
212 gameConfig.state = &gameState;
213 gameConfig.heroesLayout = caster.GetPartyLayout("heroesLayout");
214 gameConfig.battleResources = caster.GetBattleResources("battleResources");
215 gameConfig.menuResources = caster.GetMenuResources("menuResources");
217 // temporary test data
218 SDL_Surface *bg(IMG_Load("test-data/battle-bg.png"));
219 PartyLayout monstersLayout(*caster.GetPartyLayout("monstersLayout"));
221 Monster monster(*caster.GetMonster("lizard"));
223 gameState.heroes[0].AddSpell(caster.GetSpell("resetSpell"));
224 Spell *strongSpell(caster.GetSpell("strongSpell"));
225 gameState.heroes[0].AddSpell(strongSpell);
226 gameState.heroes[1].AddSpell(strongSpell);
227 Spell *strongerSpell(caster.GetSpell("strongerSpell"));
228 gameState.heroes[0].AddSpell(strongerSpell);
229 gameState.heroes[1].AddSpell(strongerSpell);
230 Spell *championSpell(caster.GetSpell("championSpell"));
231 gameState.heroes[0].AddSpell(championSpell);
232 gameState.heroes[1].AddSpell(championSpell);
233 Spell *rallySpell(caster.GetSpell("rallySpell"));
234 gameState.heroes[0].AddSpell(rallySpell);
235 gameState.heroes[1].AddSpell(rallySpell);
236 gameState.heroes[1].AddSpell(caster.GetSpell("escapeSpell"));
237 Spell *valorSpell(caster.GetSpell("valorSpell"));
238 gameState.heroes[0].AddSpell(valorSpell);
239 gameState.heroes[1].AddSpell(valorSpell);
241 gameState.inventory.Add(caster.GetItem("zirconPlateItem"), 32);
242 gameState.inventory.Add(caster.GetItem("holyFruitItem"));
243 gameState.inventory.Add(caster.GetItem("darkFruitItem"));
244 gameState.inventory.Add(caster.GetItem("antidoteItem"), 9);
245 gameState.inventory.Add(caster.GetItem("powerRingItem"));
246 gameState.inventory.Add(caster.GetItem("magicJarItem"), 4);
247 gameState.inventory.Add(caster.GetItem("sProRingItem"));
248 gameState.inventory.Add(caster.GetItem("hiPotionItem"), 4);
249 gameState.inventory.Add(caster.GetItem("powerRingItem"));
250 gameState.inventory.Add(caster.GetItem("powerPotionItem"), 4);
251 gameState.inventory.Add(caster.GetItem("zircoSwordItem"));
252 gameState.inventory.Add(caster.GetItem("escapeItem"), 2);
253 gameState.inventory.Add(caster.GetItem("zircoHelmetItem"));
254 gameState.inventory.Add(caster.GetItem("sleepBallItem"), 1);
255 gameState.inventory.Add(caster.GetItem("zirconPlateItem"));
257 gameState.heroes[0].SetEquipment(Hero::EQUIP_WEAPON, caster.GetItem("zircoSwordItem"));
258 gameState.heroes[0].SetEquipment(Hero::EQUIP_ARMOR, caster.GetItem("zirconArmorItem"));
259 gameState.heroes[0].SetEquipment(Hero::EQUIP_SHIELD, caster.GetItem("holyShieldItem"));
260 gameState.heroes[0].SetEquipment(Hero::EQUIP_HELMET, caster.GetItem("legendHelmItem"));
261 gameState.heroes[0].SetEquipment(Hero::EQUIP_RING, caster.GetItem("sProRingItem"));
262 gameState.heroes[0].SetEquipment(Hero::EQUIP_JEWEL, caster.GetItem("evilJewelItem"));
264 // gameState.heroes[1].SetEquipment(Hero::EQUIP_WEAPON, caster.GetItem("zircoWhipItem"));
265 gameState.heroes[1].SetEquipment(Hero::EQUIP_ARMOR, caster.GetItem("zirconPlateItem"));
266 gameState.heroes[1].SetEquipment(Hero::EQUIP_SHIELD, caster.GetItem("zircoGlovesItem"));
267 gameState.heroes[1].SetEquipment(Hero::EQUIP_HELMET, caster.GetItem("holyCapItem"));
268 gameState.heroes[1].SetEquipment(Hero::EQUIP_RING, caster.GetItem("ghostRingItem"));
269 gameState.heroes[1].SetEquipment(Hero::EQUIP_JEWEL, caster.GetItem("eagleRockItem"));
271 // gameState.heroes[2].SetEquipment(Hero::EQUIP_WEAPON, caster.GetItem("zircoAxItem"));
272 gameState.heroes[2].SetEquipment(Hero::EQUIP_ARMOR, caster.GetItem("zirconArmorItem"));
273 gameState.heroes[2].SetEquipment(Hero::EQUIP_SHIELD, caster.GetItem("megaShieldItem"));
274 gameState.heroes[2].SetEquipment(Hero::EQUIP_HELMET, caster.GetItem("zircoHelmetItem"));
275 gameState.heroes[2].SetEquipment(Hero::EQUIP_RING, caster.GetItem("powerRingItem"));
276 gameState.heroes[2].SetEquipment(Hero::EQUIP_JEWEL, caster.GetItem("evilJewelItem"));
278 // NOTE: this is actually Artea equipment
279 // gameState.heroes[3].SetEquipment(Hero::EQUIP_WEAPON, caster.GetItem("lizardBlowItem"));
280 gameState.heroes[3].SetEquipment(Hero::EQUIP_ARMOR, caster.GetItem("holyRobeItem"));
281 gameState.heroes[3].SetEquipment(Hero::EQUIP_SHIELD, caster.GetItem("zircoGlovesItem"));
282 gameState.heroes[3].SetEquipment(Hero::EQUIP_HELMET, caster.GetItem("holyCapItem"));
283 gameState.heroes[3].SetEquipment(Hero::EQUIP_RING, caster.GetItem("rocketRingItem"));
284 gameState.heroes[3].SetEquipment(Hero::EQUIP_JEWEL, caster.GetItem("krakenRockItem"));
286 gameState.heroes[0].MapEntity().Position() = Vector<Fixed<8> >(64, 128);
288 gameState.heroes[1].MapEntity().Position() = Vector<Fixed<8> >(64, 128);
289 gameState.heroes[1].MapEntity().SetFlags(Entity::FLAG_NONBLOCKING);
290 gameState.heroes[0].MapEntity().AddFollower(&gameState.heroes[1].MapEntity());
292 gameState.heroes[2].MapEntity().Position() = Vector<Fixed<8> >(64, 128);
293 gameState.heroes[2].MapEntity().SetFlags(Entity::FLAG_NONBLOCKING);
294 gameState.heroes[1].MapEntity().AddFollower(&gameState.heroes[2].MapEntity());
296 gameState.heroes[3].MapEntity().Position() = Vector<Fixed<8> >(64, 128);
297 gameState.heroes[3].MapEntity().SetFlags(Entity::FLAG_NONBLOCKING);
298 gameState.heroes[2].MapEntity().AddFollower(&gameState.heroes[3].MapEntity());
300 InitScreen screen(width, height);
302 app::State *state(0);
305 BattleState *battleState(new BattleState(&gameConfig, bg, &monstersLayout));
306 battleState->AddMonster(monster);
307 battleState->AddMonster(monster);
308 battleState->AddMonster(monster);
309 battleState->AddMonster(monster);
310 battleState->SetCapsule(caster.GetCapsule("flash"));
311 battleState->AddHero(gameState.heroes[0]);
312 battleState->AddHero(gameState.heroes[1]);
313 battleState->AddHero(gameState.heroes[2]);
314 battleState->AddHero(gameState.heroes[3]);
317 MapState *mapState(new MapState(&gameConfig, caster.GetMap("map1")));
319 mapState->ControlEntity(&gameState.heroes[0].MapEntity());
320 mapState->SetWalkingSpeed(walkSpeed);
325 Application app(screen, state);
326 MapKeys(app.Buttons());
330 } catch (Parser::Error &e) {
331 cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl;
333 } catch (exception &e) {
334 cerr << "exception in main(): " << e.what() << endl;