Code:
class ObjectManager
class Object
{
friend class ObjectManager;
DWORD ID;
bool bCanUse;
bool bCanEat;
bool bCanDrink;
bool bCanOpenClose;
bool bCanBreak;
bool bCanHide;
bool bCanExamine;
bool bCanThrow;
bool bCanCombine;
DWORD CombinesWithID;
DWORD CreatesID;
Object(void):bCanUse(false),bCanEat(false),bCanDrink(false),bCanOpenClose(false),bCanBreak(false),bCanHide(false),bCanExamine(false),bCanThrow(false) {}
};
class ObjectManager
{
std::vector<Object> ListOfObjects;
int NumObjects;
public:
Objects(void):ListOfObjects(NULL) {}
virtual ~Objects
{
ListOfObjects.clear();
}
unsigned int AddObject(Object *newobj)
{
ListOfObjects.push_back(&newobj);
return ListOfObjects.size()-1;
}
void GetObject(Object *outObj,unsigned int ID)
{
*outObj=ListOfObjects[ID];
}
};
This is rudimentary beginning to an object class and an object resource manager class. All object manipulation and access should go through the manager class using the object's ID number - which is just its position in the vector.
So you can have any number of instances of the object class in the vector and you can have the same object twice in the game, but only once in memory by using its ID number to reference it instead of the actual object. Notice I did not put object location in the class because then that would link that object to one room and one room only.
Inventory items would be relatively simple as well. You could use a vector or you could use a linked list from the STL or a simple one that you design.
Code:
struct InventoryItem
{
unsigned int ID;
InventoryItem *Next;
InventoryItem *Prev;
};
With this method all objects in the game are referred to by their ID numbers, not by the actual instance of the class or pointer to the instance.