]> git.localhorst.tv Git - l2e.git/blob - src/loader/Caster.cpp
activated the loader
[l2e.git] / src / loader / Caster.cpp
1 #include "Caster.h"
2
3 #include "Interpreter.h"
4 #include "Loader.h"
5 #include "TypeDescription.h"
6 #include "../battle/Resources.h"
7 #include "../battle/Monster.h"
8 #include "../battle/PartyLayout.h"
9 #include "../common/Capsule.h"
10 #include "../common/Hero.h"
11 #include "../common/Item.h"
12 #include "../common/Spell.h"
13 #include "../map/Map.h"
14 #include "../menu/Resources.h"
15
16 using battle::Monster;
17 using battle::PartyLayout;
18 using common::Capsule;
19 using common::Hero;
20 using common::Item;
21 using common::Spell;
22 using map::Map;
23 using std::string;
24
25
26 namespace loader {
27
28 Caster::Caster(Loader &ld, Interpreter &intp)
29 : ld(ld)
30 , intp(intp) {
31
32 }
33
34
35 battle::Resources *Caster::GetBattleResources(const string &ident) {
36         return reinterpret_cast<battle::Resources *>(
37                         GetObject(battle::Resources::TYPE_ID, ident));
38 }
39
40 Capsule *Caster::GetCapsule(const string &ident) {
41         return reinterpret_cast<Capsule *>(
42                         GetObject(Capsule::TYPE_ID, ident));
43 }
44
45 Hero *Caster::GetHero(const string &ident) {
46         return reinterpret_cast<Hero *>(
47                         GetObject(Hero::TYPE_ID, ident));
48 }
49
50 Item *Caster::GetItem(const string &ident) {
51         return reinterpret_cast<Item *>(
52                         GetObject(Item::TYPE_ID, ident));
53 }
54
55 Map *Caster::GetMap(const string &ident) {
56         return reinterpret_cast<Map *>(
57                         GetObject(Map::TYPE_ID, ident));
58 }
59
60 menu::Resources *Caster::GetMenuResources(const string &ident) {
61         return reinterpret_cast<menu::Resources *>(
62                         GetObject(menu::Resources::TYPE_ID, ident));
63 }
64
65 Monster *Caster::GetMonster(const string &ident) {
66         return reinterpret_cast<Monster *>(
67                         GetObject(Monster::TYPE_ID, ident));
68 }
69
70 PartyLayout *Caster::GetPartyLayout(const string &ident) {
71         return reinterpret_cast<PartyLayout *>(
72                         GetObject(PartyLayout::TYPE_ID, ident));
73 }
74
75 Spell *Caster::GetSpell(const string &ident) {
76         return reinterpret_cast<Spell *>(
77                         GetObject(Spell::TYPE_ID, ident));
78 }
79
80
81 void *Caster::GetObject(int typeId, const string &ident) {
82         std::map<string, LoadedExport>::const_iterator i(
83                         ld.Exports().find(ident));
84         if (i != ld.Exports().end()) {
85                 if (i->second.typeId != typeId) {
86                         throw std::runtime_error("mismatched type for "
87                                         + ident);
88                 } else {
89                         return i->second.location;
90                 }
91         }
92         return intp.GetObject(typeId, ident);
93 }
94
95 }