Virtual random maze creator
/ ************************************************** ***** * Maze is something that is often used in a game. The previous maze requires * * Wizard a room to manually draw, time-furnished, and once * * is found by players, labyrinth The pattern is leaked, the labyrinth is not called its * * is a maze, so the wizards have twisted brains to put the maze design as complicated as possible, * *, but more complex maze will be found in the right route, and too much * * * Visually walking maze also makes players feel too cumbersome, reducing fun. So production * * Life Ideas. * * Random labyrinth generating algorithm is simple as possible, the labyrinth storage is ascended as much as possible to memory * * body, the labyrinth room uses a virtual object, handling flexible, labyrinth room only in the * * player, will be installed into memory, and labyrinth room is also like Ordinary Room * * When it is not referred to a period of time for a while, it can be destroyed, and it is not a reference to it. It can be completely destroyed for a while. The next time you need * * will be re-established. Will produce a new maze. Regional Wizard * * Writing Random Maze only requires some preset parameters such as the single-sided long, * * room description, entrance and exit description, dozens of or thousands of rooms, route * * Different random maze Ok, greatly improve the regional writing efficiency * * and the playability of the game. * * This item is currently suitable for random maze, namely: the description of the room in the labyrinth * * is the same, such as a wood, a grave, etc., if you want this object to create * * complete random area, there is a certain plot, In the area of a certain pattern, it is required to specify some of the rules described in the maze in the maze according to their own situation, and the description of the neighboring room is reasonable, and the items in the room are coordinated. If * * * Members can only make the connection part of the maze, and use several maze portfolios * * into a completely random area, ha, then make a wizard to be more relaxed. * * At present, the labyrinth used in this game is generally 10 to 40 single-sided lengths. I don't know how to do more * big maze, and there is a description of this, to be based on the server performance of my * *, However, I think the most common machine makes an area * * The labyrinth for 100x100 should be a relaxed thing. * * Due to the use of Virtual Object, it is necessary to adjust the root * * according to its own system. * ********************************************************** ***** / #pragma Optimize #define N 8 #define s 4 #define W 2 #define E 1 #define all 15 / **************************** ************************* * The biggest value of the maze of the maze is currently tentative for 100, due to random maze * Create and operate the labyrinth 'area "of the resource single-edge length 100 is the * 100x100 equal to 10,000 rooms, which is generally not available. A general real-time maze (real-time maze refers to the labyrinth of the game running in the game running process * as needed to be created with a single side of the labyrinth that needs to be created with 10 to 50. If you need to create a giant maze, if there are a few * Wan and more than 10,000 rooms, the creation work should be placed in the game. When the game is turned to do, the game starts for a while (such as 20 seconds) prohibits players from login. * The game updates this maze by regular restarting. * I don't know who will use such a big maze. . . . . .
*********************************************************** ** / #define max_long 100 // As long as you can have an entrance to the room connected to other rooms. // The possible exports have three. // Define This rule can only have two exits. // It is to close one if there are three exports of rooms. // will not make players who have an export of exports because they see four directions.
#define two_valid_leaves inherit f_clean_up; class coordinate {int x; int y;} Class Coordinate * newpath = (}), / * Treat Queue * / Enter, / * Entrance coordinate * / leave; / * Exit coordinate * / private String * Valid_dirs = ({"South", "North", "West", "EAST"}); private mapping reverse_dir = ([NORTH ":" South "," South ":" North "," West ": "EAST", "EAST": "West",]); // full labyrinth export array. Private mixed * all; / ******************************** Features: **************** / Private int L; // Single long private string * inherit_rooms = ({}); // Maze allows inherited file Name Private String entry_dir; // Maze Port_Entry_Dir; // Maze Port and Region Connection Direction PRIVATE STRING LINK_ENTRY_ROOM; // Laboked Link_Exit_Dir; // Laboratory Outlet and Region Connection Direction PRIVATE String link_exit_room; // Laboratory export connection area file name Private String entry_short; // Malaze entry short description private string entry_desc; // Malaze EXIT_SHORT; // Maze Export Short description Private string exit_Desc ; // 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描 描/ Maze room is outdoor private string * maze_npcs = ({}); // Monster in the labyrinth / ******************* ---- END --- ********************* / / / set up tags. Private int maze_built = 0; // Reset the whole area variable. Private void refresh_vars (); // Establishment Maze private void create_maze (); // Select the random exit. Private int random_out (int x, int y, int N); // Processing connection. Private void link_to_north (int x, int y); private void link_to_south (int X, INT Y); Private Void Link_TO_WEST (int X, int y); Private void link_to_east (int x, int y); // Draw a map of the built labyrinth. Private void Paint_vrm_map (); private string mroom_fname (int X, int y) ) {RETURN SPRINTF ("% S /% D /% D", base_name (this_Object ()), x, y)
} Private void refresh_vars () // Reset the whole domain variable. {NewPath = (}); all = 0;} // Check private int check_vars () {INT i, N; IF on some of the necessary parameters (L <5) || L> Max_long) Return 0; inherit_rooms - = ({0}); if (! n = sizeof (inherit_rooms)) Return 0; for (i = 0; i
// Western room is not in the list newPath. // IF (Member_Array (Temp, NewPath) == -1) Outs = ({w});} // The East Room IS (x 1, y (N & E && ((x 1)
ENTER-> y = 0; all [enter-> x] [Enter-> y] | = S; Break; Case "North": ENTER-> x = TO_INT (L / 2); ENTER-> Y = L- 1; All [Enter-> x] [Enter-> Y] | = n; Break; Case "West": ENTER-> Y = TO_INT (L / 2); ENTER-> x = 0; All [Enter-> x] [ENTER-> Y] | = W; Break; Case "EAST": ENTER-> Y = TO_INT (L / 2); ENTER-> X = L-1; All [ENTER-> X] [ENTER- > y] | = E; Break;} // stores to be processed queue. NewPath = ({ENTER}); // Enter the main loop. Do {Int x, y, out, numb; // Monitoring Initialization. IF (! (NUMB = SIZEOF (NewPath))) Continue; Numb = Random (Numb); Reset_EVAL_COST (); x = newpath [Numb] -> x; y = newpath [numb] -> y; // If There are three possible exports to close an exit: OUT = all ^ (all [x] [y]); out = random_out (x, y, out); if (! Out) // There is no possible export. {NewPath - = ({NewPath [Numb]}); Continue;} // Processing connection. IF (out & w) LINK_TO_WEST (X, Y); IF (OUT & E) LINK_TO_EAST (X, Y); if (out & n) LINK_TO_NORTH (X, Y ); If (out & s) link_to_south (x, y); // The current room is complete. NewPath - = ({newpath [numb]});} while (sizeof (newpath)); switch (entry_dir) {Case "West" : For (i = 0; i
x = i; temp-> y = 0; Valid_leaves = ({TEMP});} Break;} if (! (i = sizeof (valid_leaves))) // No exit must re-establish {Call_OTher (this_Object (), "create_maze"); return;} if (i == 1) Leave = Valid_leaves [0]; else leave = valid_leaves [random (i)]; // randomly select one. Switch (entry_dir) {Case "South": all [Leave-> Y] | = n; Break; Case "North": all [Leave-> x] [Leave-> Y] | = S; Break; Case "West": all [Leave -> x] [Leave-> Y] | = E; BREAK; CASE "EAST": All [Leave-> X] [Leave-> Y] | = W; Break;} // Maze creation. MAZE_BUILT = 1; // Draw the completed maze map. // The map file is the '.map' file of the same name in the same directory, // Draw a map may benefit the work of the regional wizard. // If you need to open objects to 'write' in this directory.
// paint_vrm_map ();} private void link_to_west (int x, int y) // the West Room IS (x-1, y) {class coordinate Temp; // can't link. The current room is already the most west The room was. IF ((x-1) <0) return; temp = new (class coordinate); temp-> x = x-1; temp-> y = y; // The room has been in PATH, Or already in the list newPath. If (all [Temp-> x] [TEMP-> Y] / * || MEMBER_ARRAY (TEMP, NewPath) * /) Return; All [x] [Y] | = W; All [temp-> x] | = E; newPath = ({temp});} private void link_to_east (int x, int y) // the East Room IS (x 1, y) {Class Coordinate Temp; // can't link. The current room is already the most east room. IF ((x 1)> = L) Return; temp = new (class coordinate); TEMP-> x = x 1; TEMP-> Y = Y; // The east is in Path, or is already in the list of newPaths to be processed. If (all [Temp-> x] [TEMP-> Y] / * || MEMBER_ARRAY (TEMP, NewPath) * /) Return; All [x] [Y] | = E; All [Temp-> x] [TEMP-> Y] | = W; newPath = ({TEMP});} private void LINK_TO_SOUTH (INT X, INT Y) // The South Room IS (X, Y-1) {Class Coordinate Temp; // CAN't Link. The current room is already the southernmost room. IF ((Y-1) <0) return; temp = new (class coordinate); TEMP-> x = x; TEMP-> Y = Y-1; // The southern end has been In PATH, or have been in the list NewPath. IF (all (all [temp-> x] [TEMP-> Y] / * || MEMBER_ARRAY (TEMP, NewPath) * /) return; all [x] [y] | = S; All [Temp-> x] [TEMP-> Y] | = n; newPath = ({TEMP});} private void link_to_north (int x, int y) // the North Room IS (X, Y 1) {class coordinate Temp; // can't link. The current room is already the northernmost room. IF (Y 1)> = L) Return; Temp = New (class coordinate); TEMP-> X = x; TEMP-> Y = Y 1; // The north end room has been in PATH, or is already in the list newpath. if (all (all) / * | | Member_Array (Temp, NewPath) * /) Return; All [x] [Y] | = n; all [Temp-> x] [TEMP->
Y] | = S; newPath = ({temp});} // Draw a mapped mapped in the built labyrinth. Private void Paint_vrm_map () {String Hor = "─", Ver = "│", Room = "◎", SROOM = "●"; int x, y; string output = "", map_file; for (y = (l-1); y> = 0; y -) {reset_eval_cost (); OUTPUT = Sprintf ("Y =% - 3D: ", Y); for (x = 0; x
Else {destruct (this_Object ()); return 0;}} // Wizard can update the labyrinth, // but at this time, the player in the labyrin is going to void. Void Remove (String EUID) {string fname = base_name (this_Object ()); object m_room; int x, y; for (x = 0; x
Void set_inherit_room (mixed rooms) {if (Stringp (Rooms)) {// does this file exist if (file_size ("% sc", Rooms))> 0) inherit_rooms = ({Rooms}); Return;} Else IF (ArrayP (Rooms) {for (String F in Rooms) {if (! Stringp (f) || f == ") RETURN; if (file_size (sprintf ("% sc ", f)) <= 0 );} Inherit_rooms = rooms; return;} return;} // Inlet direction (export in opposite side) VOID SET_ENTRY_DIR (String Dir) {if (! Stringp (dir)) returno; // Init direction legal check. IF (MEMBER_ARRAY (DIR, VALID_DIRS) == -1) Return; entry_dir = DIR;} // Inlet and zone connection direction VOID SET_LINK_ENTRY_DIR (String Dir) {if (! Stringp (DIR) || DIR == "") Return LINK_ENTRY_DIR = DIR;} // The file name void set_link_entry_room (String Lroom) {if (! Stringp (Lroom) || LROOM == "") Return; IF (Sprintf ("% sc) "LROOM) <= 0) Return; link_entry_room = lroom;} // Export and region connection direction void set_link_exit_dir (String Dir) {if (! Stringp (DIR) || DIR ==") Return; link_exit_dir = DIR;} // Laboked export connection area file name void set_link_exit_room (String Lroom) {if (! Stringp (lroom) || lroom == "" "Return; IF (Fil) E_SIZE (Sprintf ("% SC", LROOM)) <= 0) Return; link_exit_room = lroom;} // Short description void set_entry_short (String Desc) {if (! Stringp (DESC) || Desc == " ") Return; entry_short = desc;} // Length description of the labyrinth entrance VOID set_entry_desc (String DESC) {if (! Stringp (decing) || desc ==" ") return; entry_desc = desc;} // Maze export Short description void set_exit_short (String DESC) {if (! Stringp (dec) || dec == "") return; exit_short = desc;} // Length description void set_exit_desc (String Desc) {if (! Stringp) {ix DESC) || DESC == "") return; exit_desc =
DESC;} // Short description of the labyrinth room void set_maze_room_short (string dec) {if (! Stringp (dec) || dec== ") Return; maze_room_short = desc;} // Maze room description, if there are multiple Description, a random number will be randomly selected during each room / /. Void set_maze_room_desc (smings) {maze_room_desc = ({deSCES}); return;}}} {foreach (string descin des) if (! stringp (desc) Return Maze_room_desc = des; return;}} // Is the labyrinth room is an outdoor room void set_outdoors (int out) {if (! INTP (OUTD)) Return; if (outd) IS_outdooors = 1;} // Monster in the labyrinth VOID SET_MAZE_NPCS (Mixed NPC) {IF (StringP (NPC)) {// Does this file exist if (file_size ("% sc", npc))> 0) maze_npcs = ({npc}); Return;} Else IF (ArrayP (NPC)) {FOREACH (String F in NPC) {if (! Stringp (f) || f == ") Return; IF (file_size (sprintf ("% sc ", f)) <= 0) Return;} maze_npcs = npc; return;} Return;} / **** The above is the interface function of the preset maze parameters **** // creates a labyrinth room, called Virtual_D.
Nomask Object Query_maze_room (string str) {int RANDOM_RATE = 20; // Room Place NPC Possibility INT IDX, X, Y, EXITS; Object Ob; String F; IF (Previous_Object () && (getEuid (previous_object ()) ! = Root_uid)) Return 0; if (! Stringp (STR) || Str == "") Return 0; if (! Maze_built) // Maze does not establish create_maze (); if (! Maze_built) Return 0; IF ( Str == "entry") // Maze entry room {f = inherit_rooms [random (sizeof (inherit_rooms))]; ob = new (f); if (! ob) return 0; OB-> set ("Virtual_Room", 1); OB-> set ("short", entry_short); OB-> set ("long", entry_desc); if (is_outdoors) OB-> set ("OutDoors", 1); OB-> SET (Sprintf "EXITS /% SETRY_ENTRY_DIR, LINK_ENTRY_ROOM); OB-> SET (Sprintf (" EXITS /% S ", Reverse_Dir [Entry_Dir]), MROOM_FNAME (Enter -> X, ENTER-> Y); if (Sizeof (MAZE_NPCS) && (rDOM (100) <= random_rate)) {OB-> Set ("Objects", ([MAZE_NPCS [Random (SizeOf (MAZE_NPCS))]: 1,])); OB-> setup (); } Return Ob;} if (str == "exit") // Maze Outlet Room {f = inherit_rooms [Random (Sizeof (inherit_rooms))]; ob = new (f); if (! Ob) return 0; OB- > set ("Virtual_Room", 1); OB-> Set ("Short", E XIT_SHORT); OB-> Set ("long", exit_desc); if (is_outdoors) OB-> set ("OutDoors", 1); OB-> Set (Sprintf ("EXITS /% S", LINK_EXIT_DIR), LINK_EXIT_ROOM) ; OB-> set (Sprintf ("EXITS /% S", Entry_Dir, MROOM_FNAME (Leave-> X, Leave-> Y)); if (SizeOf (MAZE_NPCS) && (Random (100) <= random_rate) { Ob-> set ("Objects", ([MAZE_NPCS [Random (SizeOf (MAZE_NPCS))]: 1,])); OB-> setup ();} Return OB;} IDX = Member_Array ('/', STR) ; If (idx == -1) return 0;