1 |
/* |
2 |
* This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 |
* |
4 |
* Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team |
5 |
* Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
6 |
* Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
7 |
* Copyright (©) 1992 Frank Tore Johansen |
8 |
* |
9 |
* Deliantra is free software: you can redistribute it and/or modify it under |
10 |
* the terms of the Affero GNU General Public License as published by the |
11 |
* Free Software Foundation, either version 3 of the License, or (at your |
12 |
* option) any later version. |
13 |
* |
14 |
* This program is distributed in the hope that it will be useful, |
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 |
* GNU General Public License for more details. |
18 |
* |
19 |
* You should have received a copy of the Affero GNU General Public License |
20 |
* and the GNU General Public License along with this program. If not, see |
21 |
* <http://www.gnu.org/licenses/>. |
22 |
* |
23 |
* The authors can be reached via e-mail to <support@deliantra.net> |
24 |
*/ |
25 |
|
26 |
#include <global.h> |
27 |
#include <rmg.h> |
28 |
#include <rproto.h> |
29 |
|
30 |
/* where are there adjacent doors or walls? */ |
31 |
static int |
32 |
surround_check2 (layout &maze, int i, int j) |
33 |
{ |
34 |
/* 1 = door or wall to left, |
35 |
2 = door or wall to right, |
36 |
4 = door or wall above |
37 |
8 = door or wall below */ |
38 |
int surround_index = 0; |
39 |
|
40 |
if ((i > 0) && (maze[i - 1][j] == 'D' || maze[i - 1][j] == '#')) surround_index |= 1; |
41 |
if ((i < maze.w - 1) && (maze[i + 1][j] == 'D' || maze[i + 1][j] == '#')) surround_index |= 2; |
42 |
if ((j > 0) && (maze[i][j - 1] == 'D' || maze[i][j - 1] == '#')) surround_index |= 4; |
43 |
if ((j < maze.h - 1) && (maze[i][j + 1] == 'D' || maze[i][j + 1] == '#')) surround_index |= 8; |
44 |
|
45 |
return surround_index; |
46 |
} |
47 |
|
48 |
void |
49 |
put_doors (maptile *the_map, layout &maze, const char *doorstyle, random_map_params *RP) |
50 |
{ |
51 |
int i, j; |
52 |
maptile *vdoors; |
53 |
maptile *hdoors; |
54 |
char doorpath[1024]; |
55 |
|
56 |
if (!strcmp (doorstyle, "none")) |
57 |
return; |
58 |
|
59 |
vdoors = find_style ("/styles/doorstyles", doorstyle, RP->difficulty); |
60 |
|
61 |
if (vdoors) |
62 |
hdoors = vdoors; |
63 |
else |
64 |
{ |
65 |
vdoors = find_style ("/styles/doorstyles/vdoors", doorstyle, RP->difficulty); |
66 |
if (!vdoors) |
67 |
return; |
68 |
|
69 |
sprintf (doorpath, "/styles/doorstyles/hdoors%s", strrchr (vdoors->path, '/')); |
70 |
hdoors = find_style (doorpath, 0, RP->difficulty); |
71 |
if (!hdoors) |
72 |
return; |
73 |
} |
74 |
|
75 |
for (i = 0; i < RP->Xsize; i++) |
76 |
for (j = 0; j < RP->Ysize; j++) |
77 |
{ |
78 |
if (maze[i][j] == 'D') |
79 |
{ |
80 |
int sindex = surround_check2 (maze, i, j); |
81 |
|
82 |
object *this_door = (sindex == 3 ? hdoors : vdoors) |
83 |
->pick_random_object (rmg_rndm); |
84 |
|
85 |
the_map->insert (this_door->clone (), i, j, 0, 0); |
86 |
} |
87 |
} |
88 |
} |
89 |
|