forked from mirror/openmw-tes3mp
modified Npc and Creature class to let them store a copy of their own ID
This commit is contained in:
parent
7afc8ffd2e
commit
8d85211fa1
6 changed files with 88 additions and 25 deletions
|
@ -180,7 +180,7 @@ int main(int argc, char**argv)
|
|||
case REC_CREA:
|
||||
{
|
||||
Creature b;
|
||||
b.load(esm);
|
||||
b.load(esm, id);
|
||||
if(quiet) break;
|
||||
cout << " Name: " << b.name << endl;
|
||||
break;
|
||||
|
|
|
@ -36,6 +36,23 @@ namespace MWWorld
|
|||
return false;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool create (const ESMS::RecListWithIDT<T>& list, const std::string& name)
|
||||
{
|
||||
if (const T *instance = list.search (name))
|
||||
{
|
||||
ESMS::LiveCellRef<T, RefData> ref;
|
||||
ref.base = instance;
|
||||
|
||||
mRef = ref;
|
||||
mPtr = Ptr (&boost::any_cast<ESMS::LiveCellRef<T, RefData>&> (mRef), 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
ManualRef (const ESMS::ESMStore& store, const std::string& name)
|
||||
|
|
|
@ -62,8 +62,12 @@ struct Creature
|
|||
// Defined in loadcont.hpp
|
||||
InventoryList inventory;
|
||||
|
||||
void load(ESMReader &esm)
|
||||
std::string mId;
|
||||
|
||||
void load(ESMReader &esm, const std::string& id)
|
||||
{
|
||||
mId = id;
|
||||
|
||||
model = esm.getHNString("MODL");
|
||||
original = esm.getHNOString("CNAM");
|
||||
name = esm.getHNOString("FNAM");
|
||||
|
@ -93,7 +97,7 @@ struct Creature
|
|||
// AI_A - activate?
|
||||
|
||||
esm.skipRecord();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -97,8 +97,12 @@ struct NPC
|
|||
std::string name, model, race, cls, faction, script,
|
||||
hair, head; // body parts
|
||||
|
||||
void load(ESMReader &esm)
|
||||
std::string mId;
|
||||
|
||||
void load(ESMReader &esm, const std::string& id)
|
||||
{
|
||||
mId = id;
|
||||
|
||||
npdt52.gold = -10;
|
||||
|
||||
model = esm.getHNOString("MODL");
|
||||
|
|
|
@ -17,16 +17,16 @@ namespace ESMS
|
|||
{
|
||||
virtual void load(ESMReader &esm, const std::string &id) = 0;
|
||||
virtual int getSize() = 0;
|
||||
|
||||
|
||||
static std::string toLower (const std::string& name)
|
||||
{
|
||||
std::string lowerCase;
|
||||
|
||||
|
||||
std::transform (name.begin(), name.end(), std::back_inserter (lowerCase),
|
||||
(int(*)(int)) std::tolower);
|
||||
|
||||
|
||||
return lowerCase;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::map<int,RecList*> RecListList;
|
||||
|
@ -53,15 +53,53 @@ namespace ESMS
|
|||
return NULL;
|
||||
return &list.find(id2)->second;
|
||||
}
|
||||
|
||||
|
||||
// Find the given object ID (throws an exception if not found)
|
||||
const X* find(const std::string &id) const
|
||||
{
|
||||
const X *object = search (id);
|
||||
|
||||
|
||||
if (!object)
|
||||
throw std::runtime_error ("object " + id + " not found");
|
||||
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
int getSize() { return list.size(); }
|
||||
};
|
||||
|
||||
/// Modified version of RecListT for records, that need to store their own ID
|
||||
template <typename X>
|
||||
struct RecListWithIDT : RecList
|
||||
{
|
||||
typedef std::map<std::string,X> MapType;
|
||||
|
||||
MapType list;
|
||||
|
||||
// Load one object of this type
|
||||
void load(ESMReader &esm, const std::string &id)
|
||||
{
|
||||
std::string id2 = toLower (id);
|
||||
list[id2].load(esm, id2);
|
||||
}
|
||||
|
||||
// Find the given object ID, or return NULL if not found.
|
||||
const X* search(const std::string &id) const
|
||||
{
|
||||
std::string id2 = toLower (id);
|
||||
if(list.find(id2) == list.end())
|
||||
return NULL;
|
||||
return &list.find(id2)->second;
|
||||
}
|
||||
|
||||
// Find the given object ID (throws an exception if not found)
|
||||
const X* find(const std::string &id) const
|
||||
{
|
||||
const X *object = search (id);
|
||||
|
||||
if (!object)
|
||||
throw std::runtime_error ("object " + id + " not found");
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
|
@ -80,7 +118,7 @@ namespace ESMS
|
|||
|
||||
void load(ESMReader &esm, const std::string &id)
|
||||
{
|
||||
std::string id2 = toLower (id);
|
||||
std::string id2 = toLower (id);
|
||||
X& ref = list[id2];
|
||||
|
||||
ref.id = id;
|
||||
|
@ -95,18 +133,18 @@ namespace ESMS
|
|||
return NULL;
|
||||
return &list.find(id2)->second;
|
||||
}
|
||||
|
||||
|
||||
// Find the given object ID (throws an exception if not found)
|
||||
const X* find(const std::string &id) const
|
||||
{
|
||||
const X *object = search (id);
|
||||
|
||||
|
||||
if (!object)
|
||||
throw std::runtime_error ("object " + id + " not found");
|
||||
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
|
||||
int getSize() { return list.size(); }
|
||||
};
|
||||
|
||||
|
@ -180,7 +218,7 @@ namespace ESMS
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename X>
|
||||
struct ScriptListT : RecList
|
||||
{
|
||||
|
@ -193,16 +231,16 @@ namespace ESMS
|
|||
{
|
||||
X ref;
|
||||
ref.load (esm);
|
||||
|
||||
|
||||
std::string realId = toLower (ref.data.name.toString());
|
||||
|
||||
|
||||
std::swap (list[realId], ref);
|
||||
}
|
||||
|
||||
// Find the given object ID, or return NULL if not found.
|
||||
const X* search(const std::string &id) const
|
||||
{
|
||||
std::string id2 = toLower (id);
|
||||
std::string id2 = toLower (id);
|
||||
if(list.find(id2) == list.end())
|
||||
return NULL;
|
||||
return &list.find(id2)->second;
|
||||
|
@ -212,15 +250,15 @@ namespace ESMS
|
|||
const X* find(const std::string &id) const
|
||||
{
|
||||
const X *object = search (id);
|
||||
|
||||
|
||||
if (!object)
|
||||
throw std::runtime_error ("object " + id + " not found");
|
||||
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
int getSize() { return list.size(); }
|
||||
};
|
||||
};
|
||||
|
||||
/* We need special lists for:
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ namespace ESMS
|
|||
RecListT<Clothing> clothes;
|
||||
RecListT<LoadCNTC> contChange;
|
||||
RecListT<Container> containers;
|
||||
RecListT<Creature> creatures;
|
||||
RecListWithIDT<Creature> creatures;
|
||||
RecListT<LoadCREC> creaChange;
|
||||
RecListT<Dialogue> dialogs;
|
||||
RecListT<Door> doors;
|
||||
|
@ -53,7 +53,7 @@ namespace ESMS
|
|||
RecListT<Light> lights;
|
||||
RecListT<Tool> lockpicks;
|
||||
RecListT<Misc> miscItems;
|
||||
RecListT<NPC> npcs;
|
||||
RecListWithIDT<NPC> npcs;
|
||||
RecListT<LoadNPCC> npcChange;
|
||||
RecListT<Probe> probes;
|
||||
RecListT<Race> races;
|
||||
|
|
Loading…
Reference in a new issue