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