1 | |
|
|
2 | /* |
1 | /* |
3 | CrossFire, A Multiplayer game for X-windows |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
4 | |
3 | * |
|
|
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | |
7 | * |
8 | This program is free software; you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
10 | the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | (at your option) any later version. |
11 | * (at your option) any later version. |
12 | |
12 | * |
13 | This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | |
17 | * |
18 | You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * |
21 | |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
|
|
23 | */ |
22 | */ |
24 | |
23 | |
25 | #include <global.h> |
24 | #include <global.h> |
26 | #include <random_map.h> |
25 | #include <random_map.h> |
27 | #include <rproto.h> |
26 | #include <rproto.h> |
28 | |
27 | |
29 | /* Put in the walls and autojoin them. */ |
28 | /* Put in the walls and autojoin them. */ |
30 | |
29 | |
31 | |
|
|
32 | /* given a layout and a coordinate, tell me which squares up/down/right/left |
30 | /* given a layout and a coordinate, tell me which squares up/down/right/left |
33 | are occupied. */ |
31 | are occupied. */ |
34 | |
|
|
35 | int |
32 | int |
36 | surround_flag (char **layout, int i, int j, random_map_params *RP) |
33 | surround_flag (char **layout, int i, int j, random_map_params *RP) |
37 | { |
34 | { |
38 | /* 1 = wall to left, |
35 | /* 1 = wall to left, |
39 | 2 = wall to right, |
36 | 2 = wall to right, |
… | |
… | |
92 | * 8 = blocked below |
89 | * 8 = blocked below |
93 | */ |
90 | */ |
94 | |
91 | |
95 | int surround_index = 0; |
92 | int surround_index = 0; |
96 | |
93 | |
|
|
94 | // don't forget to update the mapspace! |
|
|
95 | if (i > 0) map->at (i - 1, j ).update (); |
|
|
96 | if (i < RP->Xsize - 1) map->at (i + 1, j ).update (); |
|
|
97 | if (j > 0) map->at (i , j - 1).update (); |
|
|
98 | if (j < RP->Ysize - 1) map->at (i , j + 1).update (); |
|
|
99 | |
97 | if ((i > 0) && (GET_MAP_MOVE_BLOCK (map, i - 1, j) & ~MOVE_BLOCK_DEFAULT)) |
100 | if ((i > 0) && (GET_MAP_MOVE_BLOCK (map, i - 1, j) & MOVE_WALK)) |
98 | surround_index |= 1; |
101 | surround_index |= 1; |
99 | if ((i < RP->Xsize - 1) && (GET_MAP_MOVE_BLOCK (map, i + 1, j) & ~MOVE_BLOCK_DEFAULT)) |
102 | if ((i < RP->Xsize - 1) && (GET_MAP_MOVE_BLOCK (map, i + 1, j) & MOVE_WALK)) |
100 | surround_index |= 2; |
103 | surround_index |= 2; |
101 | if ((j > 0) && (GET_MAP_MOVE_BLOCK (map, i, j - 1) & ~MOVE_BLOCK_DEFAULT)) |
104 | if ((j > 0) && (GET_MAP_MOVE_BLOCK (map, i, j - 1) & MOVE_WALK)) |
102 | surround_index |= 4; |
105 | surround_index |= 4; |
103 | if ((j < RP->Ysize - 1) && (GET_MAP_MOVE_BLOCK (map, i, j + 1) & ~MOVE_BLOCK_DEFAULT)) |
106 | if ((j < RP->Ysize - 1) && (GET_MAP_MOVE_BLOCK (map, i, j + 1) & MOVE_WALK)) |
104 | surround_index |= 8; |
107 | surround_index |= 8; |
105 | |
108 | |
106 | return surround_index; |
109 | return surround_index; |
107 | } |
110 | } |
108 | |
111 | |
… | |
… | |
133 | w_style) at '#' marks. */ |
136 | w_style) at '#' marks. */ |
134 | |
137 | |
135 | void |
138 | void |
136 | make_map_walls (maptile *map, char **layout, char *w_style, random_map_params *RP) |
139 | make_map_walls (maptile *map, char **layout, char *w_style, random_map_params *RP) |
137 | { |
140 | { |
138 | char styledirname[256]; |
141 | char styledirname[1024]; |
139 | char stylefilepath[256]; |
142 | char stylefilepath[1024]; |
140 | maptile *style_map = 0; |
143 | maptile *style_map = 0; |
141 | object *the_wall; |
144 | object *the_wall; |
142 | |
145 | |
143 | /* get the style map */ |
146 | /* get the style map */ |
144 | if (!strcmp (w_style, "none")) |
147 | if (!strcmp (w_style, "none")) |
145 | return; |
148 | return; |
146 | sprintf (styledirname, "%s", "/styles/wallstyles"); |
149 | sprintf (styledirname, "%s", "/styles/wallstyles"); |
147 | sprintf (stylefilepath, "%s/%s", styledirname, w_style); |
150 | sprintf (stylefilepath, "%s/%s", styledirname, w_style); |
148 | style_map = find_style (styledirname, w_style, -1); |
151 | style_map = find_style (styledirname, w_style, -1); |
149 | if (style_map == 0) |
152 | if (!style_map) |
150 | return; |
153 | return; |
151 | |
154 | |
152 | /* fill up the map with the given floor style */ |
155 | /* fill up the map with the given floor style */ |
153 | if ((the_wall = pick_random_object (style_map)) != NULL) |
156 | if ((the_wall = style_map->pick_random_object ())) |
154 | { |
157 | { |
155 | int i, j; |
158 | int i, j; |
156 | char *cp; |
159 | char *cp; |
157 | int joinedwalls = 0; |
160 | int joinedwalls = 0; |
158 | object *thiswall; |
161 | object *thiswall; |
159 | |
162 | |
160 | sprintf (RP->wall_name, "%s", &the_wall->arch->name); |
163 | sprintf (RP->wall_name, "%s", &the_wall->arch->archname); |
161 | if ((cp = strchr (RP->wall_name, '_')) != NULL) |
164 | if ((cp = strchr (RP->wall_name, '_')) != NULL) |
162 | { |
165 | { |
163 | *cp = 0; |
166 | *cp = 0; |
164 | joinedwalls = 1; |
167 | joinedwalls = 1; |
165 | } |
168 | } |
… | |
… | |
193 | 2 = wall to right, |
196 | 2 = wall to right, |
194 | 4 = wall above |
197 | 4 = wall above |
195 | 8 = wall below */ |
198 | 8 = wall below */ |
196 | int surround_index = 0; |
199 | int surround_index = 0; |
197 | int l; |
200 | int l; |
198 | char wall_name[64]; |
201 | char wall_name[1024]; |
199 | archetype *wall_arch = 0; |
202 | archetype *wall_arch = 0; |
200 | |
203 | |
201 | strcpy (wall_name, the_wall->arch->name); |
204 | assign (wall_name, the_wall->arch->archname); |
202 | |
205 | |
203 | /* conventionally, walls are named like this: |
206 | /* conventionally, walls are named like this: |
204 | wallname_wallcode, where wallcode indicates |
207 | wallname_wallcode, where wallcode indicates |
205 | a joinedness, and wallname is the wall. |
208 | a joinedness, and wallname is the wall. |
206 | this code depends on the convention for |
209 | this code depends on the convention for |