--- [EMAIL PROTECTED] wrote:

> One possible way to do this is to have your table of objects. And then
> have a table called Contents. The Contents table would store the object id
> of a container (object_container_id) and the object id of the inner object
> (inner_object_id). Since a container is an object, it could appear in
> either of those columns. Tables used in this way are often referred to as
> "mapping tables" as they just show how two objects relate, but don't story
> any data themselves.


I like this method, and would recommend it. A general schema which could be
applied to stock ROM would be:

Table players
===================
/* insert normal player character attributes here */

object_inventory_id  int   /* foriegn key for the object_inventory table */



Table object_inventory
====================
id int /* unique identifier */
max_items int /* total number of objects which can be contained */
max_weight int /* total weight of objects which can be contained */


Table objects
==============================
id int                  /* unique identifier */
object_inventory_id int /* foriegn key for this object's inventory (if any) */
/* object related stuff */


Table object_inventory_contents
===============================
id int                  /* unique identifier */
object_inventory_id int /* foriegn key for the object_inventory_table */
object_id           int /* foriegn key for the objects table */
position            int /* an optional sort order (if you care) */



Then to get all the objects in a person's inventory it'd just be:

SELECT o.name, o.type 
   FROM objects o, players p, object_inventory oi, object_inventory_contents
oic
   WHERE o.id = oic.object_id AND oic.object_inventory_id = oi.id 
         AND player.object_inventory_id = oi.id AND player.name = "Kender"



The recursion searching can get a bit tricky, but the relationships are all
good. Also, the added benifit to this sort of layout, is that you could
actually use another table like 

Table containable_entity
=========================
id int              /* unique identifier */
weight     int      /* for checking */

Then change the object_inventory_contents table to use containable_entity_id
and you can pretty easily have players carrying players in a sac (like a giant
or something). 

This sort of database layout lends itself well to good OO design of your class 
heirarchy.

=====
-----BEGIN GEEK CODE BLOCK-----
Version 3.1
GCS/L/C/O d-(+) s++: a-- C+++$>++++ UBLS++++$ 
P+++(--)$ L+++>++++ E--- W+>++$ N !o K? w(--) !O 
M- !V PS+ PE(++) Y+ PGP->+ t+ 5 X+() R(+) tv+@ 
b++(+++) !DI+++ D G(-) e>+++$ h---() r+++ y+++
------END GEEK CODE BLOCK------


                
__________________________________ 
Do you Yahoo!? 
The all-new My Yahoo! - Get yours free! 
http://my.yahoo.com 
 

Reply via email to