1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team |
|
|
5 | * Copyright (©) 2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) Crossfire Development Team (restored, original file without copyright notice) |
6 | * Copyright (©) 1994-2004 Crossfire Development Team (restored, original file without copyright notice) |
6 | * |
7 | * |
7 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | * 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 | * 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 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | * option) any later version. |
11 | * option) any later version. |
11 | * |
12 | * |
12 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
16 | * |
17 | * |
17 | * You should have received a copy of the Affero GNU General Public License |
18 | * 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 | * and the GNU General Public License along with this program. If not, see |
19 | * <http://www.gnu.org/licenses/>. |
20 | * <http://www.gnu.org/licenses/>. |
20 | * |
21 | * |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | #include <global.h> |
25 | #include <global.h> |
25 | #include <random_map.h> |
26 | #include <rmg.h> |
26 | #include <rproto.h> |
27 | #include <rproto.h> |
27 | |
28 | |
28 | void noinline |
29 | ecb_noinline void |
29 | layout::alloc (int w, int h) |
30 | layout::alloc (int w, int h) |
30 | { |
31 | { |
31 | assert (sizeof (cell) == 1); |
32 | assert (sizeof (cell) == 1); |
32 | |
33 | |
33 | this->w = w; |
34 | this->w = w; |
… | |
… | |
74 | layout::~layout () |
75 | layout::~layout () |
75 | { |
76 | { |
76 | sfree ((char *)data, size); |
77 | sfree ((char *)data, size); |
77 | } |
78 | } |
78 | |
79 | |
79 | void noinline |
80 | ecb_noinline void |
80 | layout::fill (char fill) |
81 | layout::fill (char fill) |
81 | { |
82 | { |
82 | //memset (data [0], fill, w * h); // only when contiguous :/ |
83 | //memset (data [0], fill, w * h); // only when contiguous :/ |
83 | fill_rect (0, 0, w, h, fill); |
84 | fill_rect (0, 0, w, h, fill); |
84 | } |
85 | } |
85 | |
86 | |
86 | void noinline |
87 | ecb_noinline void |
87 | layout::replace (char from, char to) |
88 | layout::replace (char from, char to) |
88 | { |
89 | { |
89 | for (int x = 0; x < w; ++x) |
90 | for (int x = 0; x < w; ++x) |
90 | for (int y = 0; y < h; ++y) |
91 | for (int y = 0; y < h; ++y) |
91 | if (data [x][y] == from) |
92 | if (data [x][y] == from) |
92 | data [x][y] = to; |
93 | data [x][y] = to; |
93 | } |
94 | } |
94 | |
95 | |
95 | void noinline |
96 | ecb_noinline void |
96 | layout::rect (int x1, int y1, int x2, int y2, char fill) |
97 | layout::rect (int x1, int y1, int x2, int y2, char fill) |
97 | { |
98 | { |
98 | --x2; |
99 | --x2; |
99 | |
100 | |
100 | memset (data [x1] + y1, fill, y2 - y1); |
101 | memset (data [x1] + y1, fill, y2 - y1); |
… | |
… | |
102 | |
103 | |
103 | while (++x1 < x2) |
104 | while (++x1 < x2) |
104 | data [x1][y1] = data [x1][y2 - 1] = fill; |
105 | data [x1][y1] = data [x1][y2 - 1] = fill; |
105 | } |
106 | } |
106 | |
107 | |
107 | void noinline |
108 | ecb_noinline void |
108 | layout::fill_rect (int x1, int y1, int x2, int y2, char fill) |
109 | layout::fill_rect (int x1, int y1, int x2, int y2, char fill) |
109 | { |
110 | { |
110 | for (; x1 < x2; ++x1) |
111 | for (; x1 < x2; ++x1) |
111 | memset (data [x1] + y1, fill, y2 - y1); |
112 | memset (data [x1] + y1, fill, y2 - y1); |
112 | } |
113 | } |
… | |
… | |
115 | layout::border (char fill) |
116 | layout::border (char fill) |
116 | { |
117 | { |
117 | rect (0, 0, w, h, fill); |
118 | rect (0, 0, w, h, fill); |
118 | } |
119 | } |
119 | |
120 | |
120 | void noinline |
121 | ecb_noinline void |
121 | layout::fill_rand (int percent) |
122 | layout::fill_rand (int percent) |
122 | { |
123 | { |
123 | percent = lerp (percent, 0, 100, 0, 256); |
124 | percent = lerp (percent, 0, 100, 0, 256); |
124 | |
125 | |
125 | for (int x = 0; x < w; ++x) |
126 | for (int x = 0; x < w; ++x) |
… | |
… | |
128 | } |
129 | } |
129 | |
130 | |
130 | ///////////////////////////////////////////////////////////////////////////// |
131 | ///////////////////////////////////////////////////////////////////////////// |
131 | |
132 | |
132 | // erode by cellular automata |
133 | // erode by cellular automata |
133 | void noinline |
134 | ecb_noinline void |
134 | layout::erode_1_2 (int c1, int c2, int repeat) |
135 | layout::erode_1_2 (int c1, int c2, int repeat) |
135 | { |
136 | { |
136 | layout neu (w, h); |
137 | layout neu (w, h); |
137 | |
138 | |
138 | while (repeat--) |
139 | while (repeat--) |
… | |
… | |
204 | ///////////////////////////////////////////////////////////////////////////// |
205 | ///////////////////////////////////////////////////////////////////////////// |
205 | // isolation remover - ensures single connected area |
206 | // isolation remover - ensures single connected area |
206 | |
207 | |
207 | typedef fixed_stack<point> pointlist; |
208 | typedef fixed_stack<point> pointlist; |
208 | |
209 | |
209 | static void noinline |
210 | ecb_noinline static void |
210 | push_flood_fill (layout &dist, pointlist &seeds, int x, int y) |
211 | push_flood_fill (layout &dist, pointlist &seeds, int x, int y) |
211 | { |
212 | { |
212 | if (dist [x][y]) |
213 | if (dist [x][y]) |
213 | return; |
214 | return; |
214 | |
215 | |
… | |
… | |
275 | seeds.push (point (x, y)); |
276 | seeds.push (point (x, y)); |
276 | } |
277 | } |
277 | |
278 | |
278 | // isolation remover, works on a "distance" map |
279 | // isolation remover, works on a "distance" map |
279 | // the map must be initialised with 0 == rooms, 255 = walls |
280 | // the map must be initialised with 0 == rooms, 255 = walls |
280 | static void noinline |
281 | ecb_noinline static void |
281 | isolation_remover (layout &dist, unsigned int perturb = 2) |
282 | isolation_remover (layout &dist, unsigned int perturb = 2) |
282 | { |
283 | { |
283 | // dist contains |
284 | // dist contains |
284 | // 0 == invisited rooms |
285 | // 0 == invisited rooms |
285 | // 1 == visited rooms |
286 | // 1 == visited rooms |
… | |
… | |
533 | * 1 match on (i+1, j) |
534 | * 1 match on (i+1, j) |
534 | * 2 match on (i, j+1) |
535 | * 2 match on (i, j+1) |
535 | * 4 match on (i+1, j+1) |
536 | * 4 match on (i+1, j+1) |
536 | * and the possible combinations thereof. |
537 | * and the possible combinations thereof. |
537 | */ |
538 | */ |
538 | static int noinline |
539 | ecb_noinline static int |
539 | calc_pattern (char ch, layout &maze, int i, int j) |
540 | calc_pattern (char ch, layout &maze, int i, int j) |
540 | { |
541 | { |
541 | int pattern = 0; |
542 | int pattern = 0; |
542 | |
543 | |
543 | if (i + 1 < maze.w && maze[i + 1][j] == ch) |
544 | if (i + 1 < maze.w && maze[i + 1][j] == ch) |
… | |
… | |
636 | |
637 | |
637 | for (int i = 0; i < w; i++) |
638 | for (int i = 0; i < w; i++) |
638 | for (int j = 0; j < h; j++) |
639 | for (int j = 0; j < h; j++) |
639 | switch (data [i][j]) |
640 | switch (data [i][j]) |
640 | { |
641 | { |
641 | case '#': expand_wall (new_layout, i, j, *this); break; |
642 | case '#': expand_wall (new_layout, i, j, *this); break; |
642 | case 'D': expand_door (new_layout, i, j, *this); break; |
643 | case 'D': expand_door (new_layout, i, j, *this); break; |
643 | default: expand_misc (new_layout, i, j, *this); break; |
644 | default: expand_misc (new_layout, i, j, *this); break; |
644 | } |
645 | } |
645 | |
646 | |
646 | swap (new_layout); |
647 | swap (new_layout); |
647 | } |
648 | } |
… | |
… | |
1013 | static struct demo |
1014 | static struct demo |
1014 | { |
1015 | { |
1015 | demo () |
1016 | demo () |
1016 | { |
1017 | { |
1017 | rmg_rndm.seed (time (0)); |
1018 | rmg_rndm.seed (time (0)); |
|
|
1019 | extern void hack();hack (); |
1018 | |
1020 | |
1019 | for(int i=1;i<100;i++) |
1021 | for(int i=1;i<100;i++) |
1020 | { |
1022 | { |
1021 | layout maze (40, 30); |
1023 | layout maze (40, 30); |
1022 | maze.fill_rand (99); |
1024 | maze.fill_rand (99); |