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.31 by root, Wed Nov 16 23:42:02 2016 UTC vs.
Revision 1.35 by root, Sat Dec 1 20:22:13 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 (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
4 * Copyright (©) 2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 5 * Copyright (©) 2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 1994-2004 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
23 24
24#include <global.h> 25#include <global.h>
25#include <rmg.h> 26#include <rmg.h>
26#include <rproto.h> 27#include <rproto.h>
27 28
28void noinline 29ecb_noinline void
29layout::alloc (int w, int h) 30layout::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;
74layout::~layout () 75layout::~layout ()
75{ 76{
76 sfree ((char *)data, size); 77 sfree ((char *)data, size);
77} 78}
78 79
79void noinline 80ecb_noinline void
80layout::fill (char fill) 81layout::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
86void noinline 87ecb_noinline void
87layout::replace (char from, char to) 88layout::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
95void noinline 96ecb_noinline void
96layout::rect (int x1, int y1, int x2, int y2, char fill) 97layout::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
107void noinline 108ecb_noinline void
108layout::fill_rect (int x1, int y1, int x2, int y2, char fill) 109layout::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}
115layout::border (char fill) 116layout::border (char fill)
116{ 117{
117 rect (0, 0, w, h, fill); 118 rect (0, 0, w, h, fill);
118} 119}
119 120
120void noinline 121ecb_noinline void
121layout::fill_rand (int percent) 122layout::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
133void noinline 134ecb_noinline void
134layout::erode_1_2 (int c1, int c2, int repeat) 135layout::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--)
152 { 0, -2, 0 }, { 0, -1, 1 }, { 0, 0, 1 }, { 0, 1, 1 }, { 0, 2, 0 }, 153 { 0, -2, 0 }, { 0, -1, 1 }, { 0, 0, 1 }, { 0, 1, 1 }, { 0, 2, 0 },
153 { 1, -2, 0 }, { 1, -1, 1 }, { 1, 0, 1 }, { 1, 1, 1 }, { 1, 2, 0 }, 154 { 1, -2, 0 }, { 1, -1, 1 }, { 1, 0, 1 }, { 1, 1, 1 }, { 1, 2, 0 },
154 { 2, -1, 0 }, { 2, 0, 0 }, { 2, 1, 0 }, 155 { 2, -1, 0 }, { 2, 0, 0 }, { 2, 1, 0 },
155 }; 156 };
156 157
157 for (int i = array_length (dds); i--; ) 158 for (int i = ecb_array_length (dds); i--; )
158 { 159 {
159 int nx = x + dds [i][0]; 160 int nx = x + dds [i][0];
160 int ny = y + dds [i][1]; 161 int ny = y + dds [i][1];
161 162
162 if (!IN_RANGE_EXC (nx, 0, w) || !IN_RANGE_EXC (ny, 0, h) || !data [nx][ny]) 163 if (!IN_RANGE_EXC (nx, 0, w) || !IN_RANGE_EXC (ny, 0, h) || !data [nx][ny])
204///////////////////////////////////////////////////////////////////////////// 205/////////////////////////////////////////////////////////////////////////////
205// isolation remover - ensures single connected area 206// isolation remover - ensures single connected area
206 207
207typedef fixed_stack<point> pointlist; 208typedef fixed_stack<point> pointlist;
208 209
209static void noinline 210ecb_noinline static void
210push_flood_fill (layout &dist, pointlist &seeds, int x, int y) 211push_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
280static void noinline 281ecb_noinline static void
281isolation_remover (layout &dist, unsigned int perturb = 2) 282isolation_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 */
538static int noinline 539ecb_noinline static int
539calc_pattern (char ch, layout &maze, int i, int j) 540calc_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}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines