1 |
elmex |
1.1 |
/* |
2 |
root |
1.16 |
* This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 |
pippijn |
1.12 |
* |
4 |
root |
1.23 |
* Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 |
root |
1.22 |
* Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 |
|
|
* Copyright (©) 1992 Frank Tore Johansen |
7 |
pippijn |
1.12 |
* |
8 |
root |
1.20 |
* 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 |
pippijn |
1.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 |
root |
1.15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
pippijn |
1.12 |
* GNU General Public License for more details. |
17 |
|
|
* |
18 |
root |
1.20 |
* 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 |
root |
1.15 |
* |
22 |
root |
1.16 |
* The authors can be reached via e-mail to <support@deliantra.net> |
23 |
pippijn |
1.12 |
*/ |
24 |
elmex |
1.1 |
|
25 |
|
|
#include <global.h> |
26 |
root |
1.27 |
#include <rmg.h> |
27 |
elmex |
1.1 |
#include <rproto.h> |
28 |
|
|
|
29 |
|
|
/* where are there adjacent doors or walls? */ |
30 |
root |
1.21 |
static int |
31 |
root |
1.26 |
surround_check2 (layout &maze, int i, int j) |
32 |
root |
1.3 |
{ |
33 |
elmex |
1.1 |
/* 1 = door or wall to left, |
34 |
root |
1.3 |
2 = door or wall to right, |
35 |
|
|
4 = door or wall above |
36 |
|
|
8 = door or wall below */ |
37 |
elmex |
1.1 |
int surround_index = 0; |
38 |
root |
1.3 |
|
39 |
root |
1.26 |
if ((i > 0) && (maze[i - 1][j] == 'D' || maze[i - 1][j] == '#')) surround_index |= 1; |
40 |
|
|
if ((i < maze.w - 1) && (maze[i + 1][j] == 'D' || maze[i + 1][j] == '#')) surround_index |= 2; |
41 |
|
|
if ((j > 0) && (maze[i][j - 1] == 'D' || maze[i][j - 1] == '#')) surround_index |= 4; |
42 |
|
|
if ((j < maze.h - 1) && (maze[i][j + 1] == 'D' || maze[i][j + 1] == '#')) surround_index |= 8; |
43 |
root |
1.19 |
|
44 |
elmex |
1.1 |
return surround_index; |
45 |
|
|
} |
46 |
|
|
|
47 |
root |
1.3 |
void |
48 |
root |
1.26 |
put_doors (maptile *the_map, layout &maze, const char *doorstyle, random_map_params *RP) |
49 |
root |
1.3 |
{ |
50 |
|
|
int i, j; |
51 |
root |
1.5 |
maptile *vdoors; |
52 |
|
|
maptile *hdoors; |
53 |
root |
1.10 |
char doorpath[1024]; |
54 |
root |
1.3 |
|
55 |
|
|
if (!strcmp (doorstyle, "none")) |
56 |
|
|
return; |
57 |
root |
1.8 |
|
58 |
root |
1.24 |
vdoors = find_style ("/styles/doorstyles", doorstyle, RP->difficulty); |
59 |
root |
1.8 |
|
60 |
root |
1.3 |
if (vdoors) |
61 |
|
|
hdoors = vdoors; |
62 |
|
|
else |
63 |
|
|
{ |
64 |
root |
1.24 |
vdoors = find_style ("/styles/doorstyles/vdoors", doorstyle, RP->difficulty); |
65 |
root |
1.3 |
if (!vdoors) |
66 |
|
|
return; |
67 |
root |
1.13 |
|
68 |
root |
1.3 |
sprintf (doorpath, "/styles/doorstyles/hdoors%s", strrchr (vdoors->path, '/')); |
69 |
root |
1.24 |
hdoors = find_style (doorpath, 0, RP->difficulty); |
70 |
root |
1.13 |
if (!hdoors) |
71 |
|
|
return; |
72 |
root |
1.3 |
} |
73 |
root |
1.8 |
|
74 |
root |
1.3 |
for (i = 0; i < RP->Xsize; i++) |
75 |
|
|
for (j = 0; j < RP->Ysize; j++) |
76 |
|
|
{ |
77 |
|
|
if (maze[i][j] == 'D') |
78 |
|
|
{ |
79 |
root |
1.26 |
int sindex = surround_check2 (maze, i, j); |
80 |
root |
1.3 |
|
81 |
root |
1.18 |
object *this_door = (sindex == 3 ? hdoors : vdoors) |
82 |
root |
1.19 |
->pick_random_object (rmg_rndm); |
83 |
root |
1.8 |
|
84 |
root |
1.19 |
the_map->insert (this_door->clone (), i, j, 0, 0); |
85 |
root |
1.3 |
} |
86 |
|
|
} |
87 |
elmex |
1.1 |
} |
88 |
root |
1.13 |
|