Xref: utzoo rec.games.programmer:1120 comp.lang.c:21052 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!sun-barr!rutgers!dptg!att!cbnewsi!plb From: plb@cbnewsi.ATT.COM (peter.l.berghold) Newsgroups: rec.games.programmer,comp.lang.c Subject: Re: data structure for dungeons Message-ID: <611@cbnewsi.ATT.COM> Date: 22 Aug 89 14:34:18 GMT References: Reply-To: plb@cbnewsi.ATT.COM (peter.l.berghold,hr,) Distribution: na Organization: AT&T Bell Laboratories Lines: 52 In article 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