X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Floader%2FCaster.cpp;h=63b389adc9d848dda118d22490a23eb3b5ed2049;hb=45bb35881a10720ae26701ddf075f756419cd627;hp=78a31b548db4737e0cd4cba08ee104fd73a9313f;hpb=0285546b22f9e8f496ca6b1abffdd232647b6b6a;p=l2e.git diff --git a/src/loader/Caster.cpp b/src/loader/Caster.cpp index 78a31b5..63b389a 100644 --- a/src/loader/Caster.cpp +++ b/src/loader/Caster.cpp @@ -1,9 +1,12 @@ #include "Caster.h" +#include "Interpreter.h" +#include "Loader.h" #include "TypeDescription.h" #include "../battle/Resources.h" #include "../battle/Monster.h" #include "../battle/PartyLayout.h" +#include "../common/Capsule.h" #include "../common/Hero.h" #include "../common/Item.h" #include "../common/Spell.h" @@ -12,6 +15,7 @@ using battle::Monster; using battle::PartyLayout; +using common::Capsule; using common::Hero; using common::Item; using common::Spell; @@ -21,45 +25,71 @@ using std::string; namespace loader { -Caster::Caster(Interpreter &intp) -: intp(intp) { +Caster::Caster(Loader &ld, Interpreter &intp) +: ld(ld) +, intp(intp) { } battle::Resources *Caster::GetBattleResources(const string &ident) { return reinterpret_cast( - intp.GetObject(battle::Resources::TYPE_ID, ident)); + GetObject(battle::Resources::TYPE_ID, ident)); +} + +Capsule *Caster::GetCapsule(const string &ident) { + return reinterpret_cast( + GetObject(Capsule::TYPE_ID, ident)); } Hero *Caster::GetHero(const string &ident) { - return reinterpret_cast(intp.GetObject(Hero::TYPE_ID, ident)); + return reinterpret_cast( + GetObject(Hero::TYPE_ID, ident)); } Item *Caster::GetItem(const string &ident) { - return reinterpret_cast(intp.GetObject(Item::TYPE_ID, ident)); + return reinterpret_cast( + GetObject(Item::TYPE_ID, ident)); } Map *Caster::GetMap(const string &ident) { - return reinterpret_cast(intp.GetObject(Map::TYPE_ID, ident)); + return reinterpret_cast( + GetObject(Map::TYPE_ID, ident)); } menu::Resources *Caster::GetMenuResources(const string &ident) { return reinterpret_cast( - intp.GetObject(menu::Resources::TYPE_ID, ident)); + GetObject(menu::Resources::TYPE_ID, ident)); } Monster *Caster::GetMonster(const string &ident) { - return reinterpret_cast(intp.GetObject(Monster::TYPE_ID, ident)); + return reinterpret_cast( + GetObject(Monster::TYPE_ID, ident)); } PartyLayout *Caster::GetPartyLayout(const string &ident) { return reinterpret_cast( - intp.GetObject(PartyLayout::TYPE_ID, ident)); + GetObject(PartyLayout::TYPE_ID, ident)); } Spell *Caster::GetSpell(const string &ident) { - return reinterpret_cast(intp.GetObject(Spell::TYPE_ID, ident)); + return reinterpret_cast( + GetObject(Spell::TYPE_ID, ident)); +} + + +void *Caster::GetObject(int typeId, const string &ident) { + std::map::const_iterator i( + ld.Exports().find(ident)); + if (i != ld.Exports().end()) { + if (i->second.typeId != typeId) { + throw std::runtime_error("mismatched type for " + + ident); + } else { + return i->second.location; + } + } + return intp.GetObject(typeId, ident); } }