class ComponentItem;
class ComponentWeapon;
class ComponentConsumable;
class ComponentArmor;
class Object {
public:
// all the generic object code
// component lookup
virtual ComponentItem* GetComponentItem() { return NULL; }
virtual ComponentWeapon* GetComponentWeapon() { return NULL; }
virtual ComponentConsumable* GetComponentConsumable() { return NULL; }
virtual ComponentArmor* GetComponentArmor() { return NULL; }
};
// static weapon class – there would barely be any more to it in real code,
// and that little extra would just be pure boilerplate
class ObjectWeapon : public Object {
public:
virtual ComponentItem* GetComponentItem() { return &mCmpItem; }
virtual ComponentWeapon* GetComponentWeapon() { return &mCmpWeapon; }
private:
ComponentItem mCmpItem;
ComponentWeapon mCmpWeapon;
};
I'm currently stuck with a slight problem, and am trying to find a solution.
I want to allow player objects to be persistent; that is, when a player quits, I want to store their objects with them so that when they log on again their objects are there in their inventory. This is providing a bit of a problem. If I were to have a weapon, it would be easy enough to store the list of contents and then load the object, but this leads to two questions:
First, how would I serialize the object back to a weapon without storing type info? Does this mean that every object whether just an object or an instance of that opbject needs to contain a type?
Second,, short of storing versioning information on the object, how do I keep track of whether or not the object has been updated since the player last logged on? For example, if I have a weapon as follows:
struct weapon
{
int damage;
int attack;
int value;
};
And I decide to add a durability integer, I can easily add it to the structure and the serialization and deserialization functions for that object. But when a player who logged on after the change logs on again, the object will read 4 bytes past what is already there.
Last, I'm trying to set this up so I can script it in python. I would like to create an object and then let it be extended upon, if the coder wants to use python to create weapons and that he or she can, or the weapons can be created in the c++ code, and then used later in python as a type of object. Any tips here would be great. My main issue is how to manage new objects in python; will they just be created as objects? If a player creates an object of type Object, and sets it to be a clonable object of sorts and wants it to be a brink, they may add something like capacity for liquid. How would that be taken back to be serialized?
I hope this all made sense. My thoughts are kind of jumbled right now, but this seems like the biggest hurtle so far.t