| 1 |
root |
1.1 |
/* |
| 2 |
|
|
* This file is part of Deliantra, the Roguelike Realtime MMORPG. |
| 3 |
|
|
* |
| 4 |
root |
1.2 |
* Copyright (©) 2005,2006,2007,2008,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
| 5 |
root |
1.1 |
* |
| 6 |
|
|
* Deliantra is free software: you can redistribute it and/or modify it under |
| 7 |
|
|
* the terms of the Affero GNU General Public License as published by the |
| 8 |
|
|
* Free Software Foundation, either version 3 of the License, or (at your |
| 9 |
|
|
* option) any later version. |
| 10 |
|
|
* |
| 11 |
|
|
* This program is distributed in the hope that it will be useful, |
| 12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
|
|
* GNU General Public License for more details. |
| 15 |
|
|
* |
| 16 |
|
|
* You should have received a copy of the Affero GNU General Public License |
| 17 |
|
|
* and the GNU General Public License along with this program. If not, see |
| 18 |
|
|
* <http://www.gnu.org/licenses/>. |
| 19 |
|
|
* |
| 20 |
|
|
* The authors can be reached via e-mail to <support@deliantra.net> |
| 21 |
|
|
*/ |
| 22 |
|
|
|
| 23 |
|
|
#ifndef LAYOUT_H |
| 24 |
|
|
#define LAYOUT_H |
| 25 |
|
|
|
| 26 |
|
|
// a simple point helper struct |
| 27 |
|
|
struct point |
| 28 |
|
|
{ |
| 29 |
|
|
int x; |
| 30 |
|
|
int y; |
| 31 |
|
|
|
| 32 |
|
|
point () |
| 33 |
|
|
{ |
| 34 |
|
|
} |
| 35 |
|
|
|
| 36 |
|
|
point (int x, int y) |
| 37 |
|
|
: x(x), y(y) |
| 38 |
|
|
{ |
| 39 |
|
|
} |
| 40 |
|
|
}; |
| 41 |
|
|
|
| 42 |
|
|
// |
| 43 |
|
|
// reference |
| 44 |
|
|
// |
| 45 |
|
|
// \0 floor only |
| 46 |
|
|
// # wall |
| 47 |
|
|
// D door |
| 48 |
|
|
// < entrance (traditionally up) |
| 49 |
|
|
// > exit (traditionally down) |
| 50 |
|
|
// C "center" (of onion maze) |
| 51 |
|
|
// . ?? (rogue) |
| 52 |
|
|
// |
| 53 |
|
|
|
| 54 |
|
|
// use this in new code |
| 55 |
|
|
INTERFACE_CLASS(layout) |
| 56 |
|
|
struct layout |
| 57 |
|
|
{ |
| 58 |
|
|
typedef char cell; |
| 59 |
|
|
|
| 60 |
|
|
cell **data; |
| 61 |
|
|
int w, h; |
| 62 |
|
|
|
| 63 |
|
|
layout (int w, int h); |
| 64 |
|
|
layout (layout ©); |
| 65 |
|
|
|
| 66 |
|
|
// reference rect in other layout - will not keep the data alive, |
| 67 |
|
|
// so never swap with it's orig, or free the orig when in use. |
| 68 |
|
|
layout (layout &orig, int x1, int y1, int x2, int y2); |
| 69 |
|
|
|
| 70 |
|
|
~layout (); |
| 71 |
|
|
|
| 72 |
|
|
operator cell **() const |
| 73 |
|
|
{ |
| 74 |
|
|
return data; |
| 75 |
|
|
} |
| 76 |
|
|
|
| 77 |
|
|
void swap (layout &maze) |
| 78 |
|
|
{ |
| 79 |
|
|
::swap (maze.data, data); |
| 80 |
|
|
::swap (maze.w , w ); |
| 81 |
|
|
::swap (maze.h , h ); |
| 82 |
|
|
::swap (maze.size, size); |
| 83 |
|
|
} |
| 84 |
|
|
|
| 85 |
|
|
MTH void swap (layout *maze) { swap (*maze); } |
| 86 |
|
|
|
| 87 |
|
|
// for debugging, print maze to stdout |
| 88 |
|
|
MTH void print () const; |
| 89 |
|
|
|
| 90 |
|
|
// simple inpainting |
| 91 |
|
|
MTH void fill (char fill); |
| 92 |
|
|
MTH void clear () { fill (0); } |
| 93 |
|
|
MTH void border (char fill = '#'); |
| 94 |
|
|
MTH void rect (int x1, int y1, int x2, int y2, char fill); // x2, y2 exclusive |
| 95 |
|
|
MTH void fill_rect (int x1, int y1, int x2, int y2, char fill); // x2, y2 exclusive |
| 96 |
|
|
|
| 97 |
|
|
MTH void fill_rand (int perc); |
| 98 |
|
|
MTH void replace (char from, char to); |
| 99 |
|
|
|
| 100 |
|
|
point find (char target, int mode = 0); // mode 0=random, 1=upleft, 2=upright, 3=downright, 4=downleft |
| 101 |
|
|
|
| 102 |
|
|
// makes sure all areas are connected |
| 103 |
|
|
// perturb = 0 - very horz/vert tunnels |
| 104 |
|
|
// perturb = 1 - straight but round |
| 105 |
|
|
// perturb = 2 - snaky tunnels |
| 106 |
|
|
MTH void isolation_remover (int perturb = 2); |
| 107 |
|
|
|
| 108 |
|
|
// generates a cave, subtype 0 is a rough cave, randomly open or closed |
| 109 |
|
|
MTH void gen_cave (int subtype); |
| 110 |
|
|
MTH void gen_castle (); // generates straightish structures |
| 111 |
|
|
|
| 112 |
|
|
// helper functions to modify the maze |
| 113 |
|
|
MTH void erode_1_2 (int c1, int c2 = -1, int repeat = 1); |
| 114 |
|
|
MTH void doorify (); |
| 115 |
|
|
MTH void roomify (); // make some rooms in it, works best on onions |
| 116 |
|
|
MTH void expand2x (); |
| 117 |
|
|
MTH void symmetrize (int symmetry); |
| 118 |
|
|
MTH void rotate (int rotation); // rotate by 1=90, 2=180, 3=270 degrees |
| 119 |
|
|
|
| 120 |
|
|
void generate (random_map_params *RP); |
| 121 |
|
|
private: |
| 122 |
|
|
int size; |
| 123 |
|
|
void alloc (int w, int h); |
| 124 |
|
|
}; |
| 125 |
|
|
|
| 126 |
|
|
#endif |
| 127 |
|
|
|