[comp.lang.c] data structure for dungeons

sofmac@porthos.rutgers.edu (Sofus Macskassy) (08/21/89)

I am trying to build up a 3d dungeon, but can't figure out
what kind of data structure to use.  I don't want to use 
arrays, but would rather use some kind of linked list.
If somebody knows a good and short structure, that uses
minimal memory, I would appreciate it if they would mail
me at sofmac@porthos.rutgers.edu

   thanks in advance
	     -- Sofus

plb@cbnewsi.ATT.COM (peter.l.berghold) (08/22/89)

In article <Aug.20.16.38.37.1989.24164@porthos.rutgers.edu> sofmac@porthos.rutgers.edu (Sofus Macskassy) writes:
>
>I am trying to build up a 3d dungeon, but can't figure out
>what kind of data structure to use.  I don't want to use 
>arrays, but would rather use some kind of linked list.
>If somebody knows a good and short structure, that uses
>minimal memory, I would appreciate it if they would mail
>me at sofmac@porthos.rutgers.edu


Your data structures would depend on what kind of data that you would be 
includeing in each record.   However, for sake of generalization, here is a 
scheme that might work.

--------------- code starts here...
typedef struct Dimensions{
	int	height,width,length;	/* Self explainatory */
} Dimensions;

typedef struct DungeonPiece {
	enum type={corridor,room,door,..etc... you get the idea};
	Dimensions	dimensions;
	struct DungeonPiece **MadeOf;	/* All the pieces that make this peice*/
	struct DungeonPiece *Next; /* Next room, corrideor, etc. */
} DungeonPiece;

typedef struct DungeonLevel {
	struct DungeonLevel	*NextLevel,*LastLevel;
	DungeonPiece		*FirstPiece;
} DungeonLevel;

      |
-------------- code ends here...


In this manner your dungeon goes together as a linked list of pieces with 
the last piece pointing to (DungeonPiece *)0.  You could simplify the coding
of it by creating "black box" modules of code that operate on one data type 
at a time and just handing off the neccesary information to them.  If you have
access to a C++ compiler, the whole thing could be handled as "objects"....


Pete

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|     _   /|    || Peter L. Berghold, AT&T, HRSAG, UUCP: att!violin!plb        |
|     \`o_O'    ||============================================================ |
|       ( )     || Disclaimer: If you find an opinion in this posting somewhere|
|        U      || it is no doubt mine, and not my employers.  I'm the only    |
|    Aachk!     || person crazy enough to take this stand!                     |
|        Phft!  ||                                                             |
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV