CREATE TABLE types (
type_id SERIAL PRIMARY KEY NOT NULL,
type_name TEXT NOT NULL
);
INSERT INTO types(type_name) VALUES ('object');
INSERT INTO types(type_name) VALUES ('creature');
INSERT INTO types(type_name) VALUES ('human');
CREATE TABLE things (
obj_id SERIAL PRIMARY KEY NOT NULL,
type_id INTEGER NOT NULL REFERENCES types(type_id),
keyword TEXT UNIQUE NOT NULL
);
INSERT INTO things (type_id, keyword) VALUES (1, 'Sword');
INSERT INTO things (type_id, keyword) VALUES (3, 'Teqneek');
INSERT INTO things (type_id, keyword) VALUES (2, 'Troll');
CREATE TABLE things_instances (
obj_id INTEGER REFERENCES things(obj_id) NOT NULL,
instance_id SERIAL NOT NULL,
owner_id INTEGER REFRENCES things(obj_id)
– other transitory state information that varies from one item to the next
);
CREATE UNIQUE INDEX ix_thing_instance ON things_instances(obj_id, instance_id);
INSERT INTO things_instances(obj_id, owner_id) VALUES (1, 2);
Looking for some input / suggestions / ideas/ work around for an ID system for objects and creatures and methods for storing them. A little overview of my question/idea:
Im at a point where Im starting to load objects and npcs into my game. All data is accessed via a SQL db. table: mud_npcs, mud_objects (->mud_object_modifiers)
All "Entities (objects, creatures, etc)" are derived from base class "Entity", the main game manager houses a global static map of master records of both objects and npcs (to be cloned from to make an instance of that obj/npc) and a map of all existing game entities (when they are created, spawned, etc).
The base class entity defines string uid; Which I was using to store a custom string (which I later parse with, getUID()) that represented a type unique game id:
Type DB ID keyword
O 1 Sword // Object
C 20 Troll // Creature
H 14 Teqneek // Player (Human)
O1Sword, C20Troll, H14Teqneek
Searching and iterating is a breeze using a STL Multimap… The issue I have is.
Multiple instances; I could easily add a number to the end of the ID, eg. O1Sword4 , or I may want 20 trolls for an army, C20Troll18..19..20 etc
but when a creature dies, or an item is destroyed should i be reusing that id, keeping track of use in an array? int idPool[x]; for every master object.
Honestly I dont know, seeking advice!