diff options
Diffstat (limited to 'npc')
-rw-r--r-- | npc/maze0/config.txt | 181 |
1 files changed, 131 insertions, 50 deletions
diff --git a/npc/maze0/config.txt b/npc/maze0/config.txt index c729b58bf..601e333f4 100644 --- a/npc/maze0/config.txt +++ b/npc/maze0/config.txt @@ -290,13 +290,60 @@ function script MazeFix { if (getd(.@v$+"$["+MAZESOUTH+"]") != "WALL") .@skip=true; - // If it doesn't, but is an edge, we don't care + // Finally skip + if (.@skip) { + .@y++; + continue; + } + + .@dirns=any(true, false); + + // If it doesn't, but is an edge, so we cannot enforce both rules // Do note (x,y) only goes to (MX-1, MY-1) because index if (.@x >= MAZE_MX-1 || .@y >= MAZE_MY-1) .@skip=true; // Finally skip if (.@skip) { + // End of X axis (row) + if (.@x >= MAZE_MX-1) { + .@x1=0; .@al=true; + while (.@x1 < .@x) { + .@vi=MazeVar(.@x1, .@y); + // There's a wall somewhere + if (getd(.@v$+"$["+MAZE_EAST+"]") == "WALL") { + .@al=false; + break; + } + .@x1++; + } + // There's no walls, so we need safeties + if (.@al) { + // Could pick a random place, but... + .@skip=false; .@dirns=true; + } + // End of Y axis (column) + } else { + .@y1=0; .@al=true; + while (.@y1 < .@y) { + .@vi=MazeVar(.@x, .@y1); + // There's a wall somewhere + if (getd(.@v$+"$["+MAZESOUTH+"]") == "WALL") { + .@al=false; + break; + } + .@y1++; + } + // There's no walls, so we need safeties + if (.@al) { + // Could pick a random place, but... + .@skip=false; .@dirns=false; + } + } + } + + // All fine, continue to next row + if (.@skip) { .@y++; continue; } @@ -304,7 +351,7 @@ function script MazeFix { debugmes "(%d, %d) editing from %d", .@x, .@y, getd(.@v$+"_ID"); // At least one of those paths must be open - if (any(true, false)) { + if (.@dirns) { // Force the opening to south .@v2$=MazeVar(.@x, .@y+1); setd(.@v$+"$["+MAZESOUTH+"]", str(.@x)+"_"+str(.@y+1)); @@ -338,11 +385,6 @@ function script MazeFix { ///////////////////////////////////////////////////////////////////////////////// // GenerateMaze(width, height) → Returns instance ID function script GenerateMaze { - // Create the Maze instance or die trying - .@inst = instance_create("Maze "+getcharid(0), getcharid(3), IOT_CHAR); - if (.@inst < 0) end; - MAZE_ID=.@inst; - // Save maze configuration MAZE_MX=getarg(0); MAZE_MY=getarg(1); @@ -479,7 +521,7 @@ function script GenerateMaze { "↑", "→", "↓", "←", "⮠", "⮡", "⮢", "⮣", "ㅓ", "ㅏ", "ㅗ", "T", - "|", "—", "𐘁"; + "|", "—", "𐘁\ "; debugmes "[STATUS] Finishing..."; for (.@y=0; .@y < MAZE_MY; .@y++) { .@l$=""; @@ -491,51 +533,17 @@ function script GenerateMaze { .@l$=.@l$+","+getd(MazeVar(.@x, .@y, "_ID")); .@lb$=.@lb$+" "+.@symbol$; } - debugmes "[REPORT] %s", .@l$; - debugmes "[REPORT] %s", .@lb$; + // Debug human readable format + a easy to grep-replace RNG + // Pseudo-rng example: $@MAZES_12_4 = Random Maze 12, Row 4 + // On the example, replace VAR_X with "MAZES_12" + debugmes "[REPORT-SA] setarray $@VAR_X_%d%s;", .@y, .@l$; // SetArray + debugmes "[REPORT-HR] %s", .@lb$; // HumanReadable } - // Sanity Check - if ($@GM_OVERRIDE) { - for (.@y=0; .@y < MAZE_MY; .@y++) { - for (.@x=0; .@x < MAZE_MX; .@x++) { - .@mid=getd(MazeVar(.@x, .@y, "_ID")); - .@v$=MazeVar(.@x, .@y); - .@n$=getd(.@v$+"$["+MAZENORTH+"]"); - .@w$=getd(.@v$+"$["+MAZE_WEST+"]"); - .@e$=getd(.@v$+"$["+MAZE_EAST+"]"); - .@s$=getd(.@v$+"$["+MAZESOUTH+"]"); - debugmes "\t%s\t\t\t", .@n$; - debugmes "%s|%s|%s\t\t", .@w$, .@s$, .@e$; - } - debugmes "%s (%d)", .@v$, .@mid; - } - } - freeloop(false); debugmes "[STATUS] Finished"; - // Attach instance maps - instance_attachmap("maze0", .@inst, false, "mz0@"+getcharid(0)); - instance_attachmap("maze1", .@inst, false, "mz1@"+getcharid(0)); - instance_attachmap("maze2", .@inst, false, "mz2@"+getcharid(0)); - instance_attachmap("maze3", .@inst, false, "mz3@"+getcharid(0)); - instance_attachmap("maze4", .@inst, false, "mz4@"+getcharid(0)); - instance_attachmap("maze5", .@inst, false, "mz5@"+getcharid(0)); - instance_attachmap("maze6", .@inst, false, "mz6@"+getcharid(0)); - instance_attachmap("maze7", .@inst, false, "mz7@"+getcharid(0)); - instance_attachmap("maze8", .@inst, false, "mz8@"+getcharid(0)); - instance_attachmap("maze9", .@inst, false, "mz9@"+getcharid(0)); - instance_attachmap("maze10", .@inst, false, "mz10@"+getcharid(0)); - instance_attachmap("maze11", .@inst, false, "mz11@"+getcharid(0)); - instance_attachmap("maze12", .@inst, false, "mz12@"+getcharid(0)); - instance_attachmap("maze13", .@inst, false, "mz13@"+getcharid(0)); - instance_attachmap("maze14", .@inst, false, "mz14@"+getcharid(0)); - instance_attachmap("maze15", .@inst, false, "mz15@"+getcharid(0)); - // Instance lasts one hour - instance_set_timeout(3600, 3600, .@inst); - instance_init(.@inst); - return .@inst; + return true; } ///////////////////////////////////////////////////////////////////////////////// @@ -583,8 +591,43 @@ function script WarpToMaze { } ///////////////////////////////////////////////////////////////////////////////// -// InitMaze(maze_x, maze_y) +// CreateMaze() +function script CreateMaze { + // Create the Maze instance or die trying + .@inst = instance_create("Maze "+getcharid(0), getcharid(3), IOT_CHAR); + if (.@inst < 0) end; + MAZE_ID=.@inst; + // Attach instance maps + instance_attachmap("maze0", .@inst, false, "mz0@"+getcharid(0)); + instance_attachmap("maze1", .@inst, false, "mz1@"+getcharid(0)); + instance_attachmap("maze2", .@inst, false, "mz2@"+getcharid(0)); + instance_attachmap("maze3", .@inst, false, "mz3@"+getcharid(0)); + instance_attachmap("maze4", .@inst, false, "mz4@"+getcharid(0)); + instance_attachmap("maze5", .@inst, false, "mz5@"+getcharid(0)); + instance_attachmap("maze6", .@inst, false, "mz6@"+getcharid(0)); + instance_attachmap("maze7", .@inst, false, "mz7@"+getcharid(0)); + instance_attachmap("maze8", .@inst, false, "mz8@"+getcharid(0)); + instance_attachmap("maze9", .@inst, false, "mz9@"+getcharid(0)); + instance_attachmap("maze10", .@inst, false, "mz10@"+getcharid(0)); + instance_attachmap("maze11", .@inst, false, "mz11@"+getcharid(0)); + instance_attachmap("maze12", .@inst, false, "mz12@"+getcharid(0)); + instance_attachmap("maze13", .@inst, false, "mz13@"+getcharid(0)); + instance_attachmap("maze14", .@inst, false, "mz14@"+getcharid(0)); + instance_attachmap("maze15", .@inst, false, "mz15@"+getcharid(0)); + // Instance lasts one hour + instance_set_timeout(3600, 3600, .@inst); + instance_init(.@inst); + + debugmes "Maze instance created: %s", MAZE_ID; + return .@inst; +} + +// InitMaze(maze_x, maze_y, {renew=True}) function script InitMaze { + // Should we renew the instance? + if (getarg(2, true)) + instance_set_timeout(3600, 3600, MAZE_ID); + MAZE_X=getarg(0); MAZE_Y=getarg(1); .@id=getd(MazeVar(MAZE_X, MAZE_Y, "_ID")); @@ -668,7 +711,45 @@ maze0,30,30,0 script #MazeMaster NPC_MONA,{ function parseConnections; */ //GenerateMaze(7, 7, 0); - GenerateMaze(5, 5); + select + l("Playtesting"), + l("RMG"), + l("RMG+Playtest"); + mes ""; + .@x=5;.@y=5; + if (@menu >= 2) { + // Width + mesf "Width (%d-25): ", max(1, @xvar); + input .@x, max(1, @xvar), 25; + + // Height + mesf "Height (%d-25): ", max(1, @yvar); + input .@y, max(1, @yvar), 25; + + // Amount of copies + mesf "N. Copies: "; + input .@loop, 1, 100; + + // Prevent bugs + @xvar=.@x; @yvar=.@y; + } + + if (@menu == 2) { + freeloop(true); + for (.@i=0; .@i < .@loop; .@i++) { + GenerateMaze(.@x, .@y); + debugmes ""; + debugmes ""; + // Throw some entropy + .@noname=rand2(.@loop*(1+.@i)); + freeloop(true); + } + freeloop(false); + close; + } + + GenerateMaze(.@x, .@y); + CreateMaze(); InitMaze(0, 0); end; } |