ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/door.C
Revision: 1.20
Committed: Mon Oct 12 14:00:58 2009 UTC (14 years, 7 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-2_82, rel-2_81
Changes since 1.19: +7 -6 lines
Log Message:
clarify license

File Contents

# User Rev Content
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.17 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 root 1.15 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6     * Copyright (©) 1992,2007 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     #include <random_map.h>
27     #include <rproto.h>
28    
29     /* where are there adjacent doors or walls? */
30 root 1.3 int
31     surround_check2 (char **layout, int i, int j, int Xsize, int Ysize)
32     {
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.19 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 elmex 1.1 return surround_index;
45     }
46    
47 root 1.3 void
48 root 1.9 put_doors (maptile *the_map, char **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.3 vdoors = find_style ("/styles/doorstyles", doorstyle, -1);
59 root 1.8
60 root 1.3 if (vdoors)
61     hdoors = vdoors;
62     else
63     {
64     vdoors = find_style ("/styles/doorstyles/vdoors", doorstyle, -1);
65     if (!vdoors)
66     return;
67 root 1.13
68 root 1.3 sprintf (doorpath, "/styles/doorstyles/hdoors%s", strrchr (vdoors->path, '/'));
69     hdoors = find_style (doorpath, 0, -1);
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.18 int sindex = surround_check2 (maze, i, j, RP->Xsize, RP->Ysize);
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