| 1 |
elmex |
1.1 |
/* |
| 2 |
root |
1.11 |
* This file is part of Deliantra, the Roguelike Realtime MMORPG. |
| 3 |
root |
1.25 |
* |
| 4 |
root |
1.27 |
* Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team |
| 5 |
root |
1.26 |
* Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
| 6 |
root |
1.18 |
* Copyright (©) 2001 Mark Wedel & Crossfire Development Team |
| 7 |
|
|
* Copyright (©) 1992 Frank Tore Johansen |
| 8 |
root |
1.25 |
* |
| 9 |
root |
1.17 |
* Deliantra is free software: you can redistribute it and/or modify it under |
| 10 |
|
|
* the terms of the Affero GNU General Public License as published by the |
| 11 |
|
|
* Free Software Foundation, either version 3 of the License, or (at your |
| 12 |
|
|
* option) any later version. |
| 13 |
root |
1.25 |
* |
| 14 |
pippijn |
1.7 |
* This program is distributed in the hope that it will be useful, |
| 15 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
root |
1.10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
pippijn |
1.7 |
* GNU General Public License for more details. |
| 18 |
root |
1.25 |
* |
| 19 |
root |
1.17 |
* You should have received a copy of the Affero GNU General Public License |
| 20 |
|
|
* and the GNU General Public License along with this program. If not, see |
| 21 |
|
|
* <http://www.gnu.org/licenses/>. |
| 22 |
root |
1.25 |
* |
| 23 |
root |
1.11 |
* The authors can be reached via e-mail to <support@deliantra.net> |
| 24 |
pippijn |
1.7 |
*/ |
| 25 |
elmex |
1.1 |
|
| 26 |
|
|
/* peterm@langmuir.eecs.berkeley.edu: this function generates a random |
| 27 |
root |
1.21 |
snake-type maze. |
| 28 |
elmex |
1.1 |
|
| 29 |
|
|
input: xsize, ysize; |
| 30 |
|
|
output: a char** array with # and . for closed and open respectively. |
| 31 |
|
|
|
| 32 |
|
|
a char value of 0 represents a blank space: a '#' is |
| 33 |
|
|
a wall. |
| 34 |
|
|
|
| 35 |
|
|
*/ |
| 36 |
|
|
|
| 37 |
|
|
#include <global.h> |
| 38 |
|
|
|
| 39 |
root |
1.22 |
#include <rmg.h> |
| 40 |
root |
1.12 |
#include "rproto.h" |
| 41 |
elmex |
1.1 |
|
| 42 |
|
|
/* These are some helper functions which help with |
| 43 |
|
|
manipulating a centered onion and turning it into |
| 44 |
|
|
a square spiral */ |
| 45 |
root |
1.13 |
void |
| 46 |
root |
1.21 |
make_square_spiral_layout (layout &maze, int options) |
| 47 |
root |
1.2 |
{ |
| 48 |
elmex |
1.1 |
/* generate and allocate a doorless, centered onion */ |
| 49 |
root |
1.13 |
map_gen_onion (maze, RMOPT_CENTERED | RMOPT_NO_DOORS, 0); |
| 50 |
|
|
|
| 51 |
root |
1.20 |
int xsize = maze.w; |
| 52 |
|
|
int ysize = maze.h; |
| 53 |
elmex |
1.1 |
|
| 54 |
root |
1.21 |
/* find the maze center. */ |
| 55 |
root |
1.15 |
int cx = 0; |
| 56 |
|
|
int cy = 0; |
| 57 |
|
|
for (int i = 0; i < xsize; i++) |
| 58 |
|
|
for (int j = 0; j < ysize; j++) |
| 59 |
root |
1.9 |
if (maze[i][j] == 'C') |
| 60 |
|
|
{ |
| 61 |
|
|
cx = i; |
| 62 |
|
|
cy = j; |
| 63 |
root |
1.15 |
break; |
| 64 |
root |
1.9 |
} |
| 65 |
|
|
|
| 66 |
root |
1.15 |
int tx = cx; |
| 67 |
|
|
int ty = cy; |
| 68 |
root |
1.9 |
for (;;) |
| 69 |
root |
1.2 |
{ |
| 70 |
root |
1.15 |
/* this starts from within a centered onion layer (or between two layers), |
| 71 |
|
|
and looks up until it finds a wall, and then looks right until it |
| 72 |
|
|
finds a vertical wall, i.e., the corner. It sets tx and ty to that. |
| 73 |
|
|
it also starts from tx and ty. */ |
| 74 |
|
|
--ty; |
| 75 |
|
|
|
| 76 |
|
|
/* find the top wall. */ |
| 77 |
|
|
while (maze[tx][ty] != '#') |
| 78 |
|
|
--ty; |
| 79 |
|
|
|
| 80 |
|
|
/* proceed right until a corner is detected */ |
| 81 |
|
|
while (maze[tx][ty + 1] != '#') |
| 82 |
|
|
++tx; |
| 83 |
root |
1.2 |
|
| 84 |
root |
1.15 |
/* tx and ty should now be the top-right corner of the onion layer */ |
| 85 |
root |
1.2 |
if (ty < 2 || tx < 2 || tx > xsize - 2 || ty > ysize - 2) |
| 86 |
|
|
break; |
| 87 |
root |
1.9 |
|
| 88 |
root |
1.2 |
make_wall (maze, tx, ty - 1, 1); /* make a vertical wall with a door */ |
| 89 |
|
|
|
| 90 |
|
|
maze[tx][ty - 1] = '#'; /* convert the door that make_wall puts here to a wall */ |
| 91 |
|
|
maze[tx - 1][ty] = 'D'; /* make a doorway out of this layer */ |
| 92 |
elmex |
1.1 |
|
| 93 |
root |
1.2 |
/* walk left until we find the top-left corner */ |
| 94 |
root |
1.15 |
while (tx > 2 && maze[tx - 1][ty]) |
| 95 |
|
|
--tx; |
| 96 |
elmex |
1.1 |
|
| 97 |
root |
1.2 |
make_wall (maze, tx - 1, ty, 0); /* make a horizontal wall with a door */ |
| 98 |
elmex |
1.1 |
|
| 99 |
root |
1.2 |
/* walk down until we find the bottom-left corner */ |
| 100 |
root |
1.15 |
while (ty + 1 < ysize && maze[tx][ty + 1]) |
| 101 |
|
|
++ty; |
| 102 |
elmex |
1.1 |
|
| 103 |
root |
1.2 |
make_wall (maze, tx, ty + 1, 1); /* make a vertical wall with a door */ |
| 104 |
elmex |
1.1 |
|
| 105 |
root |
1.2 |
/* walk rightuntil we find the bottom-right corner */ |
| 106 |
root |
1.15 |
while (tx + 1 < xsize && maze[tx + 1][ty]) |
| 107 |
|
|
++tx; |
| 108 |
elmex |
1.1 |
|
| 109 |
root |
1.2 |
make_wall (maze, tx + 1, ty, 0); /* make a horizontal wall with a door */ |
| 110 |
root |
1.15 |
++tx; /* set up for next layer. */ |
| 111 |
root |
1.2 |
} |
| 112 |
elmex |
1.1 |
|
| 113 |
|
|
/* place the exits. */ |
| 114 |
|
|
|
| 115 |
root |
1.16 |
if (rmg_rndm (2)) |
| 116 |
root |
1.2 |
{ |
| 117 |
|
|
maze[cx][cy] = '>'; |
| 118 |
|
|
maze[xsize - 2][1] = '<'; |
| 119 |
|
|
} |
| 120 |
|
|
else |
| 121 |
|
|
{ |
| 122 |
|
|
maze[cx][cy] = '<'; |
| 123 |
|
|
maze[xsize - 2][1] = '>'; |
| 124 |
|
|
} |
| 125 |
elmex |
1.1 |
} |
| 126 |
root |
1.9 |
|