ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/layout.h
Revision: 1.7
Committed: Sat Nov 17 23:40:01 2018 UTC (5 years, 6 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +1 -0 lines
Log Message:
copyright update 2018

File Contents

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