X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmain.cpp;h=2c8096225135354f911130e2d116798945fdecaf;hb=ec8e74c6f78502fb4c1d971051960ce9f1757978;hp=6bce28f0efe5d5e9eee4dbc044f0d6567c0139f9;hpb=867fd5d9b79c3b9c1d0fb17ba9f55cfe971b93d5;p=l2e.git diff --git a/src/main.cpp b/src/main.cpp index 6bce28f..2c80962 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,13 +11,34 @@ #include "battle/Hero.h" #include "battle/Monster.h" #include "battle/PartyLayout.h" -#include "geometry/Point.h" +#include "battle/Resources.h" +#include "battle/Stats.h" +#include "common/Ikari.h" +#include "common/Inventory.h" +#include "common/Item.h" +#include "common/Spell.h" +#include "geometry/Vector.h" +#include "graphics/ComplexAnimation.h" +#include "graphics/Font.h" +#include "graphics/Frame.h" +#include "graphics/Gauge.h" +#include "graphics/Menu.h" +#include "graphics/SimpleAnimation.h" #include "graphics/Sprite.h" +#include "loader/Interpreter.h" +#include "loader/ParsedSource.h" +#include "loader/Parser.h" +#include "loader/TypeDescription.h" +#include "sdl/InitImage.h" #include "sdl/InitScreen.h" #include "sdl/InitSDL.h" +#include +#include #include #include +#include +#include using app::Application; using app::Input; @@ -25,8 +46,24 @@ using battle::BattleState; using battle::Hero; using battle::Monster; using battle::PartyLayout; -using geometry::Point; +using battle::Stats; +using common::Ikari; +using common::Inventory; +using common::Item; +using common::Spell; +using geometry::Vector; +using graphics::ComplexAnimation; +using graphics::Font; +using graphics::Frame; +using graphics::Gauge; +using graphics::Menu; +using graphics::SimpleAnimation; using graphics::Sprite; +using loader::Interpreter; +using loader::ParsedSource; +using loader::Parser; +using loader::TypeDescription; +using sdl::InitImage; using sdl::InitScreen; using sdl::InitSDL; @@ -39,46 +76,125 @@ int main(int argc, char **argv) { const int width = 800; const int height = 480; - // temporary test data - SDL_Surface *bg(SDL_CreateRGBSurface(0, width, height, 32, 0xFF000000, 0xFF0000, 0xFF00, 0xFF)); - SDL_FillRect(bg, 0, SDL_MapRGB(bg->format, 0xFF, 0xFF, 0xFF)); - SDL_Rect r; - r.x = 1; - r.y = 1; - r.w = width - 2; - r.h = height - 2; - SDL_FillRect(bg, &r, SDL_MapRGB(bg->format, 0, 0, 0)); - PartyLayout monstersLayout; - monstersLayout.AddPosition(Point(50, 100)); - monstersLayout.AddPosition(Point(100, 100)); - monstersLayout.AddPosition(Point(150, 100)); - monstersLayout.AddPosition(Point(200, 100)); - PartyLayout heroesLayout; - heroesLayout.AddPosition(Point(27, 219)); - heroesLayout.AddPosition(Point(104, 227)); - heroesLayout.AddPosition(Point(66, 238)); - heroesLayout.AddPosition(Point(143, 246)); - SDL_Surface *white96(SDL_CreateRGBSurface(0, 96, 96, 32, 0xFF000000, 0xFF0000, 0xFF00, 0xFF)); - SDL_FillRect(white96, 0, SDL_MapRGB(bg->format, 0xFF, 0xFF, 0xFF)); - Sprite dummySprite(white96, 96, 96); - Monster monster; - monster.SetSprite(&dummySprite); - Hero hero; - hero.SetSprite(&dummySprite); +// std::srand(std::time(0)); try { InitSDL sdl; + InitImage image(IMG_INIT_PNG); + + battle::Resources::CreateTypeDescription(); + ComplexAnimation::CreateTypeDescription(); + Font::CreateTypeDescription(); + Frame::CreateTypeDescription(); + Gauge::CreateTypeDescription(); + Hero::CreateTypeDescription(); + Ikari::CreateTypeDescription(); + Interpreter::CreateTypeDescriptions(); + Item::CreateTypeDescription(); + graphics::MenuProperties::CreateTypeDescription(); + PartyLayout::CreateTypeDescription(); + SimpleAnimation::CreateTypeDescription(); + Spell::CreateTypeDescription(); + Sprite::CreateTypeDescription(); + Stats::CreateTypeDescription(); + common::TargetingMode::CreateTypeDescription(); + + ParsedSource source; + Parser("test-data/test.l2s", source).Parse(); + Parser("test-data/ikaris.l2s", source).Parse(); + Parser("test-data/items.l2s", source).Parse(); + Parser("test-data/spells.l2s", source).Parse(); + Parser("test-data/constants.l2s", source).Parse(); + Interpreter intp(source); + intp.ReadSource(); + + int battleResId(TypeDescription::GetTypeId("BattleResources")); + int heroId(TypeDescription::GetTypeId("Hero")); + int itemId(TypeDescription::GetTypeId("Item")); + int monsterId(TypeDescription::GetTypeId("Monster")); + int partyLayoutId(TypeDescription::GetTypeId("PartyLayout")); + int spellId(TypeDescription::GetTypeId("Spell")); + + // temporary test data + SDL_Surface *bg(IMG_Load("test-data/battle-bg.png")); + PartyLayout monstersLayout(*reinterpret_cast(intp.GetObject(partyLayoutId, "monstersLayout"))); + PartyLayout heroesLayout(*reinterpret_cast(intp.GetObject(partyLayoutId, "heroesLayout"))); + + Monster monster(*reinterpret_cast(intp.GetObject(monsterId, "lizard"))); + Hero maxim(*reinterpret_cast(intp.GetObject(heroId, "maxim"))); + Hero selan(*reinterpret_cast(intp.GetObject(heroId, "selan"))); + Hero guy(*reinterpret_cast(intp.GetObject(heroId, "guy"))); + Hero dekar(*reinterpret_cast(intp.GetObject(heroId, "dekar"))); + + battle::Resources *battleRes(reinterpret_cast(intp.GetObject(battleResId, "battleResources"))); + + maxim.AddSpell(reinterpret_cast(intp.GetObject(spellId, "resetSpell"))); + Spell *strongSpell(reinterpret_cast(intp.GetObject(spellId, "strongSpell"))); + maxim.AddSpell(strongSpell); + selan.AddSpell(strongSpell); + Spell *strongerSpell(reinterpret_cast(intp.GetObject(spellId, "strongerSpell"))); + maxim.AddSpell(strongerSpell); + selan.AddSpell(strongerSpell); + Spell *championSpell(reinterpret_cast(intp.GetObject(spellId, "championSpell"))); + maxim.AddSpell(championSpell); + selan.AddSpell(championSpell); + Spell *rallySpell(reinterpret_cast(intp.GetObject(spellId, "rallySpell"))); + maxim.AddSpell(rallySpell); + selan.AddSpell(rallySpell); + selan.AddSpell(reinterpret_cast(intp.GetObject(spellId, "escapeSpell"))); + Spell *valorSpell(reinterpret_cast(intp.GetObject(spellId, "valorSpell"))); + maxim.AddSpell(valorSpell); + selan.AddSpell(valorSpell); + + Inventory inventory; + inventory.Add(reinterpret_cast(intp.GetObject(itemId, "antidoteItem")), 9); + inventory.Add(reinterpret_cast(intp.GetObject(itemId, "magicJarItem")), 4); + inventory.Add(reinterpret_cast(intp.GetObject(itemId, "hiPotionItem")), 4); + inventory.Add(reinterpret_cast(intp.GetObject(itemId, "powerPotionItem")), 4); + inventory.Add(reinterpret_cast(intp.GetObject(itemId, "escapeItem")), 2); + inventory.Add(reinterpret_cast(intp.GetObject(itemId, "sleepBallItem")), 1); + battleRes->inventory = &inventory; + + maxim.SetWeapon(reinterpret_cast(intp.GetObject(itemId, "zircoSwordItem"))); + maxim.SetArmor(reinterpret_cast(intp.GetObject(itemId, "zirconArmorItem"))); + maxim.SetShield(reinterpret_cast(intp.GetObject(itemId, "holyShieldItem"))); + maxim.SetHelmet(reinterpret_cast(intp.GetObject(itemId, "legendHelmItem"))); + maxim.SetRing(reinterpret_cast(intp.GetObject(itemId, "sProRingItem"))); + maxim.SetJewel(reinterpret_cast(intp.GetObject(itemId, "evilJewelItem"))); + +// selan.SetWeapon(reinterpret_cast(intp.GetObject(itemId, "zircoWhipItem"))); + selan.SetArmor(reinterpret_cast(intp.GetObject(itemId, "zirconPlateItem"))); + selan.SetShield(reinterpret_cast(intp.GetObject(itemId, "zircoGlovesItem"))); + selan.SetHelmet(reinterpret_cast(intp.GetObject(itemId, "holyCapItem"))); + selan.SetRing(reinterpret_cast(intp.GetObject(itemId, "ghostRingItem"))); + selan.SetJewel(reinterpret_cast(intp.GetObject(itemId, "eagleRockItem"))); + +// guy.SetWeapon(reinterpret_cast(intp.GetObject(itemId, "zircoAxItem"))); + guy.SetArmor(reinterpret_cast(intp.GetObject(itemId, "zirconArmorItem"))); + guy.SetShield(reinterpret_cast(intp.GetObject(itemId, "megaShieldItem"))); + guy.SetHelmet(reinterpret_cast(intp.GetObject(itemId, "zircoHelmetItem"))); + guy.SetRing(reinterpret_cast(intp.GetObject(itemId, "powerRingItem"))); + guy.SetJewel(reinterpret_cast(intp.GetObject(itemId, "evilJewelItem"))); + + // NOTE: this is actually Artea equipment +// dekar.SetWeapon(reinterpret_cast(intp.GetObject(itemId, "lizardBlowItem"))); + dekar.SetArmor(reinterpret_cast(intp.GetObject(itemId, "holyRobeItem"))); + dekar.SetShield(reinterpret_cast(intp.GetObject(itemId, "zircoGlovesItem"))); + dekar.SetHelmet(reinterpret_cast(intp.GetObject(itemId, "holyCapItem"))); + dekar.SetRing(reinterpret_cast(intp.GetObject(itemId, "rocketRingItem"))); + dekar.SetJewel(reinterpret_cast(intp.GetObject(itemId, "krakenRockItem"))); + InitScreen screen(width, height); - BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout)); + BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, battleRes)); battleState->AddMonster(monster); battleState->AddMonster(monster); battleState->AddMonster(monster); battleState->AddMonster(monster); - battleState->AddHero(hero); - battleState->AddHero(hero); - battleState->AddHero(hero); - battleState->AddHero(hero); + battleState->AddHero(maxim); + battleState->AddHero(selan); + battleState->AddHero(guy); + battleState->AddHero(dekar); Application app(&screen, battleState); app.Buttons().MapKey(SDLK_w, Input::PAD_UP); app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT); @@ -95,6 +211,9 @@ int main(int argc, char **argv) { app.Run(); return 0; + } catch (Parser::Error &e) { + cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl; + return 1; } catch (exception &e) { cerr << "exception in main(): " << e.what() << endl; return 1;