/
teeny/db/
teeny/dbm/
teeny/doc/
teeny/includes/
/*
	Basic structs and stuff for TeenyMUD
*/

struct dsc; /* Forward */

struct obj_data {

	/* The usual ints and dbref-ish ints */

	int pennies;
	int loc;

/* This also holds the destination of an exit. Do NOT change this. */
	int home_drpto;
	int owner;
	int contents;
	int exits;

#ifdef TIMESTAMPS
	int timestamp;	/* This will be in minutes into the epoch */
#endif

	/* This is an array of ints */

	int *lock;

	/* These are the usual zero terminated strings. */

	char *suc;
	char *osuc;
	char *fail;
	char *ofail;
	char *desc;

	/* for use by the caching system */

	struct dsc *descriptor;
	struct obj_data *fwd;
	struct obj_data *back;

	/* Stow the current offset of where the disk version lives */
	/* and size of this disk chunk here. Only disk.c knows about these */

	long offset;
	long chunk_size;
};

/*
	A little union to point at either in-memory or on-disk data, or even a
live object descriptor.

*/

struct net_handle; /* Forward */

union raw_data {
	struct obj_data *data;		/* If in cache, or...	*/
	long chunk;			/* .. on disk		*/
};

/*

	A typical memory resident descriptor. If it describes an actual object,
it will be referenced by the main object index array, and the name field of the
ptr union will be meaningful. If it describes a free chunk, the next field will
be. We do it this way so objects can conveniently be destroyed.

*/

struct dsc {
	int flags;
	int size;	/* Size on disk. */
	int list_next;	/* Used for exits/contents lists */
 	union {
		char *name;		/* If describing real data, or.. */
		struct dsc *next;	/* .. a free chunk/descriptor    */
	} ptr;

 	union raw_data where;	/* The actual data for the thing */
};
/*
	For reaching in to a descriptor.
*/


#define StickyP(a)	((a)->flags & STICKY)
#define WizP(a)		((a)->flags & WIZARD)
#define TempleP(a)	((a)->flags & TEMPLE)
#define LinkOkP(a)	((a)->flags & LINK_OK)
#define ResidentP(a)	((a)->flags & IN_MEMORY)
#define DirtyP(a)	((a)->flags & DIRTY)
#define AliveP(a)	((a)->flags & ALIVE)
#define PlayerP(a)	(((a)->flags & TYPE_MASK) == TYP_PLAYER)
#define ThingP(a)	(((a)->flags & TYPE_MASK) == TYP_THING)
#define RoomP(a)	(((a)->flags & TYPE_MASK) == TYP_ROOM)
#define ExitP(a)	(((a)->flags & TYPE_MASK) == TYP_EXIT)

#define DSC_NAME(a)	(((a)->ptr).name)
#define DSC_CHUNK(a)	(((a)->where).chunk)
#define DSC_DATA(a)	(((a)->where).data)
#define DSC_SIZE(a)	((a)->size)
#define DSC_FLAGS(a)	((a)->flags)


/*
	This is the very largest an object can be on disk. We have to watch
out for things growing too big (mostly in locks and contents lists).
*/

#define MAX_DISK_SIZE 4096

/*
	Initial size of an object (a *total* grey box).
One int each for: pennies, location, home/dropto, owner, exits, contents,
One int for a blank lock (a -1 on disk),
A \0 on disk for each of the 5 empty strings suc, osuc, fail, ofail, desc

*/
#ifdef TIMESTAMPS
#define INITIAL_SIZE (8 * sizeof(int)) + 5
#else
#define INITIAL_SIZE (7 * sizeof(int)) + 5
#endif

/*
Tuning variables -- how much to grow the index by when you run out of
space for more entries, and how much slack space to start with when you
bring up an existing database. Ideally, SLACK is the number of objects that
will be created between start time, and when you bring it down, so you never
actually run out of index space.
*/

#define GROWTH_INCREMENT 1024
#define SLACK 512