How does a MUD work?

Started by
13 comments, last by Daerus 21 years, 1 month ago
Can someone explain to me how exactly a MUD is coded? It seems confusing to me with different rooms and being able to enter and exit those rooms. I can kind of see how a fighting system would work, but the rooms I am having a hard time with, can anyone explain how this is done? It kind of seems like there is a ''map'' type of thing, and each room has it''s own description, but how do you move around the map? Any help is appreciated, thanks.
Advertisement
Look up text-based adventure games... there are tons of them online (don''t know any off the top of my head though, sorry).. the mechanics are the same..
Disclaimer: "I am in no way qualified to present advice on any topic concerning anything and can not be held responsible for any damages that my advice may incurr (due to neither my negligence nor yours)"
Best way to figure this out is by playing one, I recommend swmud.org:6666 or (if it''s still there) mud.imaginautica.com:4000.

-- Exitus Acta Probat --
Thinking about it from an object-oriented point of view:

You''d have a CRoom object, which would have a list of CPlayer objects (pointers to the players currently in the room). It would also have pointers to it''s ''neighbour'' CRoom objects - CRoom *north, *south, *east, *west, and so on.

The CPlayer object would have a pointer to the current CRoom, and a function like ChangeRoom(CRoom *newRoom):

void ChangeRoom(CRoom *newRoom)
{
if(currentRoom)currentRoom->Print("Player has left the room");
currentRoom=newRoom;
if(currentRoom)currentRoom->Print("Player has entered the room");
}

where CRoom:rint() is a function to send a message to all players in the room.

Howzat?

Superpig
- saving pigs from untimely fates, and when he''s not doing that, runs The Binary Refinery.

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

quote:Original post by superpig
It would also have pointers to it's 'neighbour' CRoom objects - CRoom *north, *south, *east, *west, and so on.


I'm biased towards having actual Exit objects connecting rooms rather than hard-coded cardinal directions, but that's just me




[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]

[edited by - Fruny on March 11, 2003 6:41:23 PM]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
The way I am doing it is by storing all the rooms and the users in a different place inside the memory. Both have a database class to handle them. The player has 1 field in it''s database(read cache) which shows which room it is in. When you execute a look inside the room, it just runs through the userdatabase to see which user is in the same room are you.

This is a better approach then having a room holding pointers to the players because you don''t need to move around pointers(Moving around is dangerous).

The rooms are basicly nothing more then some struct on disk which I load. The roomdatabase looks a little like this:

LoadRooms(); // Loads all roomsRoomData *GetRoom(DWORD dwRoomID); // Returns pointer to room IDSaveRooms(); // Saves all rooms back to diskReloadRooms(); // In case you added roomsAddRoom(RoomData Room); // Add new roomDelRoom(DWORD dwRoomID); // Remove roomprivate:LoadRoom(DWORD dwRoomID); // Loads room and puts into cacheSaveRoom(DWORD dwRoomID); // Saves room from cache to diskUnloadRoom(DWORD dwRoomID); // Unloads from the cache 


Things a room hold are:

- Room ID- Room Name- Room Description- Room ID North- Room ID East- Room ID South- Room ID West- Flags- Key(If Required, depends on flags) 


The flags that can be set are:
- Allow fighting
- Require key
- Instant death

I hope this helps you a little into the right direction.

Sand Hawk
----------------(Inspired by Pouya)
Thanks for the help, it''s cleared up a lot of my confusion . I''m still fairly new to C/C++ though(trying very hard to learn it!), and just had another question: Is every room it''s own function, with the ID and everything inside that function? - still a little confused with that part. And also, I would assume that if you code a MUD from scratch with C/C++, it would eventually have the ability to be played by others online, not just a single player one, correct?

Again, thanks for the help.
There are much simpler, and more powerfull ways to do this.

Do NOT seperate objects into ''rooms'' and ''players'' and other such nonsense.
Every piece of the game world should be an instance of the same class. All it needs to function properly are a list of other objects it contains, the object it is in, and a set of attributes (or flags). Use the attributes for deciding wether it is an exit or a player or whathaveyou.
quote:Original post by Deyja
There are much simpler, and more powerfull ways to do this.

Do NOT seperate objects into ''rooms'' and ''players'' and other such nonsense.
Every piece of the game world should be an instance of the same class. All it needs to function properly are a list of other objects it contains, the object it is in, and a set of attributes (or flags). Use the attributes for deciding wether it is an exit or a player or whathaveyou.


That sounds incredibly complicated and inefficient. Not that I''ve ever made a MUD before, but I can''t seem to imagine an easy way to get this to work.

Would you care to elaborate? I''d enjoy hearing more about this.

500x2
quote:Original post by Daerus
Thanks for the help, it''s cleared up a lot of my confusion . I''m still fairly new to C/C++ though(trying very hard to learn it!), and just had another question: Is every room it''s own function, with the ID and everything inside that function? - still a little confused with that part. And also, I would assume that if you code a MUD from scratch with C/C++, it would eventually have the ability to be played by others online, not just a single player one, correct?

Again, thanks for the help.


In diku at least, rooms are just structures. Rooms have a list of characters in their room. Characters have a pointer to the room they''re in. When a player moves, it removes that character from the room''s list of characters, changes his room pointer to the new room, and adds that character to the list of characters in the new room.

This topic is closed to new replies.

Advertisement