ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/layout.C
(Generate patch)

Comparing deliantra/server/random_maps/layout.C (file contents):
Revision 1.25 by root, Mon Jul 5 01:57:55 2010 UTC vs.
Revision 1.33 by root, Sat Nov 17 23:33:18 2018 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines