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/Script.h"
19 #include "common/Spell.h"
20 #include "common/Stats.h"
21 #include "math/Fixed.h"
22 #include "math/Vector.h"
23 #include "graphics/CharSelect.h"
24 #include "graphics/ComplexAnimation.h"
25 #include "graphics/Font.h"
26 #include "graphics/Frame.h"
27 #include "graphics/Gauge.h"
28 #include "graphics/Menu.h"
29 #include "graphics/SimpleAnimation.h"
30 #include "graphics/Sprite.h"
31 #include "graphics/Texture.h"
32 #include "loader/Caster.h"
33 #include "loader/Interpreter.h"
34 #include "loader/ParsedSource.h"
35 #include "loader/Parser.h"
36 #include "loader/TypeDescription.h"
38 #include "map/Entity.h"
40 #include "map/MapState.h"
42 #include "map/Trigger.h"
43 #include "menu/Resources.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::Capsule;
64 using common::GameConfig;
65 using common::GameState;
70 using graphics::Texture;
72 using loader::Interpreter;
73 using loader::ParsedSource;
75 using loader::TypeDescription;
79 using sdl::InitScreen;
89 int main(int argc, char **argv) {
90 const int width = 512;
91 const int height = 448;
93 const Fixed<8> walkSpeed = Fixed<8>(1, 8);
97 // std::srand(std::time(0));
101 InitImage image(IMG_INIT_PNG);
103 Interpreter::CreateTypeDescriptions();
105 battle::Resources::CreateTypeDescription();
106 battle::Monster::CreateTypeDescription();
107 battle::PartyLayout::CreateTypeDescription();
109 common::Capsule::CreateTypeDescription();
110 common::Hero::CreateTypeDescription();
111 common::Ikari::CreateTypeDescription();
112 common::Item::CreateTypeDescription();
113 common::Stats::CreateTypeDescription();
114 common::Spell::CreateTypeDescription();
115 common::TargetingMode::CreateTypeDescription();
117 graphics::Animation::CreateTypeDescription();
118 graphics::CharSelect::CreateTypeDescription();
119 graphics::ComplexAnimation::CreateTypeDescription();
120 graphics::Font::CreateTypeDescription();
121 graphics::Frame::CreateTypeDescription();
122 graphics::Gauge::CreateTypeDescription();
123 graphics::MenuProperties::CreateTypeDescription();
124 graphics::SimpleAnimation::CreateTypeDescription();
125 graphics::Sprite::CreateTypeDescription();
126 graphics::Texture::CreateTypeDescription();
128 map::Area::CreateTypeDescription();
129 map::Entity::CreateTypeDescription();
130 map::Map::CreateTypeDescription();
131 map::Tile::CreateTypeDescription();
132 map::Trigger::CreateTypeDescription();
134 menu::Resources::CreateTypeDescription();
137 args.Read(argc, argv);
141 for (vector<char *>::const_iterator i(args.Infiles().begin()), end(args.Infiles().end()); i != end; ++i) {
142 Parser(*i, source).Parse();
145 switch (args.GetRunLevel()) {
146 case Arguments::WRITE:
148 int length(std::strlen(args.OutfilePath()));
149 switch (args.OutfilePath()[length - 1]) {
151 std::ofstream outstream(args.OutfilePath());
152 source.WriteHeader(outstream);
156 throw std::runtime_error(string("don't know how to write file ") + args.OutfilePath());
161 case Arguments::DUMP: {
162 std::cout << source << std::endl;
165 case Arguments::SOURCE_WIKI: {
166 TypeDescription::WriteSourceWiki(std::cout);
169 case Arguments::BATTLE:
172 case Arguments::PLAY:
177 Interpreter intp(source);
180 if (intp.PostponedDefinitions().size() > 0) {
181 for (vector<Interpreter::PostponedDefinition>::const_iterator i(intp.PostponedDefinitions().begin()), end(intp.PostponedDefinitions().end()); i != end; ++i) {
182 std::cerr << "missing definition of " << TypeDescription::Get(i->type).TypeName() << " " << i->identifier << std::endl;
191 gameState.heroes[0] = *caster.GetHero("maxim");
192 gameState.heroes[1] = *caster.GetHero("selan");
193 gameState.heroes[2] = *caster.GetHero("guy");
194 gameState.heroes[3] = *caster.GetHero("dekar");
196 gameState.party[0] = &gameState.heroes[0];
197 gameState.party[1] = &gameState.heroes[1];
198 gameState.party[2] = &gameState.heroes[2];
199 gameState.party[3] = &gameState.heroes[3];
200 gameState.partySize = 4;
202 gameState.capsules[1] = *caster.GetCapsule("flash");
203 gameState.capsules[1].UpgradeClass();
204 gameState.capsules[1].UpgradeClass();
205 gameState.capsules[1].UpgradeClass();
206 gameState.capsules[1].UpgradeClass();
207 gameState.capsule = 1;
209 GameConfig gameConfig;
210 gameConfig.state = &gameState;
211 gameConfig.heroesLayout = caster.GetPartyLayout("heroesLayout");
212 gameConfig.battleResources = caster.GetBattleResources("battleResources");
213 gameConfig.menuResources = caster.GetMenuResources("menuResources");
215 // temporary test data
216 SDL_Surface *bg(IMG_Load("test-data/battle-bg.png"));
217 PartyLayout monstersLayout(*caster.GetPartyLayout("monstersLayout"));
219 Monster monster(*caster.GetMonster("lizard"));
221 gameState.heroes[0].AddSpell(caster.GetSpell("resetSpell"));
222 Spell *strongSpell(caster.GetSpell("strongSpell"));
223 gameState.heroes[0].AddSpell(strongSpell);
224 gameState.heroes[1].AddSpell(strongSpell);
225 Spell *strongerSpell(caster.GetSpell("strongerSpell"));
226 gameState.heroes[0].AddSpell(strongerSpell);
227 gameState.heroes[1].AddSpell(strongerSpell);
228 Spell *championSpell(caster.GetSpell("championSpell"));
229 gameState.heroes[0].AddSpell(championSpell);
230 gameState.heroes[1].AddSpell(championSpell);
231 Spell *rallySpell(caster.GetSpell("rallySpell"));
232 gameState.heroes[0].AddSpell(rallySpell);
233 gameState.heroes[1].AddSpell(rallySpell);
234 gameState.heroes[1].AddSpell(caster.GetSpell("escapeSpell"));
235 Spell *valorSpell(caster.GetSpell("valorSpell"));
236 gameState.heroes[0].AddSpell(valorSpell);
237 gameState.heroes[1].AddSpell(valorSpell);
239 gameState.inventory.Add(caster.GetItem("zirconPlateItem"), 32);
240 gameState.inventory.Add(caster.GetItem("holyFruitItem"));
241 gameState.inventory.Add(caster.GetItem("darkFruitItem"));
242 gameState.inventory.Add(caster.GetItem("antidoteItem"), 9);
243 gameState.inventory.Add(caster.GetItem("powerRingItem"));
244 gameState.inventory.Add(caster.GetItem("magicJarItem"), 4);
245 gameState.inventory.Add(caster.GetItem("sProRingItem"));
246 gameState.inventory.Add(caster.GetItem("hiPotionItem"), 4);
247 gameState.inventory.Add(caster.GetItem("powerRingItem"));
248 gameState.inventory.Add(caster.GetItem("powerPotionItem"), 4);
249 gameState.inventory.Add(caster.GetItem("zircoSwordItem"));
250 gameState.inventory.Add(caster.GetItem("escapeItem"), 2);
251 gameState.inventory.Add(caster.GetItem("zircoHelmetItem"));
252 gameState.inventory.Add(caster.GetItem("sleepBallItem"), 1);
253 gameState.inventory.Add(caster.GetItem("zirconPlateItem"));
255 gameState.heroes[0].SetEquipment(Hero::EQUIP_WEAPON, caster.GetItem("zircoSwordItem"));
256 gameState.heroes[0].SetEquipment(Hero::EQUIP_ARMOR, caster.GetItem("zirconArmorItem"));
257 gameState.heroes[0].SetEquipment(Hero::EQUIP_SHIELD, caster.GetItem("holyShieldItem"));
258 gameState.heroes[0].SetEquipment(Hero::EQUIP_HELMET, caster.GetItem("legendHelmItem"));
259 gameState.heroes[0].SetEquipment(Hero::EQUIP_RING, caster.GetItem("sProRingItem"));
260 gameState.heroes[0].SetEquipment(Hero::EQUIP_JEWEL, caster.GetItem("evilJewelItem"));
262 // gameState.heroes[1].SetEquipment(Hero::EQUIP_WEAPON, caster.GetItem("zircoWhipItem"));
263 gameState.heroes[1].SetEquipment(Hero::EQUIP_ARMOR, caster.GetItem("zirconPlateItem"));
264 gameState.heroes[1].SetEquipment(Hero::EQUIP_SHIELD, caster.GetItem("zircoGlovesItem"));
265 gameState.heroes[1].SetEquipment(Hero::EQUIP_HELMET, caster.GetItem("holyCapItem"));
266 gameState.heroes[1].SetEquipment(Hero::EQUIP_RING, caster.GetItem("ghostRingItem"));
267 gameState.heroes[1].SetEquipment(Hero::EQUIP_JEWEL, caster.GetItem("eagleRockItem"));
269 // gameState.heroes[2].SetEquipment(Hero::EQUIP_WEAPON, caster.GetItem("zircoAxItem"));
270 gameState.heroes[2].SetEquipment(Hero::EQUIP_ARMOR, caster.GetItem("zirconArmorItem"));
271 gameState.heroes[2].SetEquipment(Hero::EQUIP_SHIELD, caster.GetItem("megaShieldItem"));
272 gameState.heroes[2].SetEquipment(Hero::EQUIP_HELMET, caster.GetItem("zircoHelmetItem"));
273 gameState.heroes[2].SetEquipment(Hero::EQUIP_RING, caster.GetItem("powerRingItem"));
274 gameState.heroes[2].SetEquipment(Hero::EQUIP_JEWEL, caster.GetItem("evilJewelItem"));
276 // NOTE: this is actually Artea equipment
277 // gameState.heroes[3].SetEquipment(Hero::EQUIP_WEAPON, caster.GetItem("lizardBlowItem"));
278 gameState.heroes[3].SetEquipment(Hero::EQUIP_ARMOR, caster.GetItem("holyRobeItem"));
279 gameState.heroes[3].SetEquipment(Hero::EQUIP_SHIELD, caster.GetItem("zircoGlovesItem"));
280 gameState.heroes[3].SetEquipment(Hero::EQUIP_HELMET, caster.GetItem("holyCapItem"));
281 gameState.heroes[3].SetEquipment(Hero::EQUIP_RING, caster.GetItem("rocketRingItem"));
282 gameState.heroes[3].SetEquipment(Hero::EQUIP_JEWEL, caster.GetItem("krakenRockItem"));
284 gameState.heroes[0].MapEntity().Position() = Vector<Fixed<8> >(64, 128);
286 gameState.heroes[1].MapEntity().Position() = Vector<Fixed<8> >(64, 128);
287 gameState.heroes[1].MapEntity().SetFlags(Entity::FLAG_NONBLOCKING);
288 gameState.heroes[0].MapEntity().AddFollower(&gameState.heroes[1].MapEntity());
290 gameState.heroes[2].MapEntity().Position() = Vector<Fixed<8> >(64, 128);
291 gameState.heroes[2].MapEntity().SetFlags(Entity::FLAG_NONBLOCKING);
292 gameState.heroes[1].MapEntity().AddFollower(&gameState.heroes[2].MapEntity());
294 gameState.heroes[3].MapEntity().Position() = Vector<Fixed<8> >(64, 128);
295 gameState.heroes[3].MapEntity().SetFlags(Entity::FLAG_NONBLOCKING);
296 gameState.heroes[2].MapEntity().AddFollower(&gameState.heroes[3].MapEntity());
298 InitScreen screen(width, height);
300 app::State *state(0);
303 BattleState *battleState(new BattleState(&gameConfig, bg, &monstersLayout));
304 battleState->AddMonster(monster);
305 battleState->AddMonster(monster);
306 battleState->AddMonster(monster);
307 battleState->AddMonster(monster);
308 battleState->SetCapsule(caster.GetCapsule("flash"));
309 battleState->AddHero(gameState.heroes[0]);
310 battleState->AddHero(gameState.heroes[1]);
311 battleState->AddHero(gameState.heroes[2]);
312 battleState->AddHero(gameState.heroes[3]);
315 MapState *mapState(new MapState(&gameConfig, caster.GetMap("map1")));
317 mapState->ControlEntity(&gameState.heroes[0].MapEntity());
318 mapState->SetWalkingSpeed(walkSpeed);
323 Application app(screen, state);
324 MapKeys(app.Buttons());
328 } catch (Parser::Error &e) {
329 cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl;
331 } catch (exception &e) {
332 cerr << "exception in main(): " << e.what() << endl;