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