ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/wall.C
(Generate patch)

Comparing deliantra/server/random_maps/wall.C (file contents):
Revision 1.13 by root, Sun Dec 31 19:02:24 2006 UTC vs.
Revision 1.38 by root, Fri Jul 2 15:03:57 2010 UTC

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,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992 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 it under
9 it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
10 the Free Software Foundation; either version 2 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
11 (at your option) any later version. 11 * 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 Affero GNU General Public License
19 along with this program; if not, write to the Free Software 19 * and the GNU General Public License along with this program. If not, see
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * <http://www.gnu.org/licenses/>.
21 21 *
22 The authors can be reached via e-mail at <crossfire@schmorp.de> 22 * The authors can be reached via e-mail to <support@deliantra.net>
23*/ 23 */
24 24
25#include <global.h> 25#include <global.h>
26#include <random_map.h> 26#include <random_map.h>
27#include <rproto.h> 27#include <rproto.h>
28 28
29/* Put in the walls and autojoin them. */ 29/* Put in the walls and autojoin them. */
30 30
31
32/* given a layout and a coordinate, tell me which squares up/down/right/left 31/* given a maze and a coordinate, tell me which squares up/down/right/left
33 are occupied. */ 32 are occupied. */
34
35int 33int
36surround_flag (char **layout, int i, int j, random_map_params *RP) 34surround_flag (const layout &maze, int i, int j)
37{ 35{
38 /* 1 = wall to left, 36 /* 1 = wall to left,
39 2 = wall to right, 37 2 = wall to right,
40 4 = wall above 38 4 = wall above
41 8 = wall below */ 39 8 = wall below */
42 int surround_index = 0; 40 int surround_index = 0;
43 41
44 if ((i > 0) && layout[i - 1][j] != 0) 42 if (i > 0 && maze[i - 1][j] != 0) surround_index |= 1;
45 surround_index |= 1; 43 if (i < maze.w - 1 && maze[i + 1][j] != 0) surround_index |= 2;
46 if ((i < RP->Xsize - 1) && layout[i + 1][j] != 0) 44 if (j > 0 && maze[i][j - 1] != 0) surround_index |= 4;
47 surround_index |= 2; 45 if (j < maze.h - 1 && maze[i][j + 1] != 0) surround_index |= 8;
48 if ((j > 0) && layout[i][j - 1] != 0) 46
49 surround_index |= 4;
50 if ((j < RP->Ysize - 1) && layout[i][j + 1] != 0)
51 surround_index |= 8;
52 return surround_index; 47 return surround_index;
53} 48}
54 49
55
56/* like surround_flag, but only walls count. 50/* like surround_flag, but only walls count. */
57 */
58
59int 51int
60surround_flag2 (char **layout, int i, int j, random_map_params *RP) 52surround_flag2 (const layout &maze, int i, int j)
61{ 53{
62 /* 1 = wall to left, 54 /* 1 = wall to left,
63 2 = wall to right, 55 2 = wall to right,
64 4 = wall above 56 4 = wall above
65 8 = wall below */ 57 8 = wall below */
66 int surround_index = 0; 58 int surround_index = 0;
67 59
68 if ((i > 0) && layout[i - 1][j] == '#') 60 if (i > 0 && maze[i - 1][j] == '#') surround_index |= 1;
69 surround_index |= 1; 61 if (i < maze.w - 1 && maze[i + 1][j] == '#') surround_index |= 2;
70 if ((i < RP->Xsize - 1) && layout[i + 1][j] == '#') 62 if (j > 0 && maze[i][j - 1] == '#') surround_index |= 4;
71 surround_index |= 2; 63 if (j < maze.h - 1 && maze[i][j + 1] == '#') surround_index |= 8;
72 if ((j > 0) && layout[i][j - 1] == '#') 64
73 surround_index |= 4;
74 if ((j < RP->Ysize - 1) && layout[i][j + 1] == '#')
75 surround_index |= 8;
76 return surround_index; 65 return surround_index;
77} 66}
78 67
79
80/* like surround_flag, except it checks a map, not a layout. 68/* like surround_flag, except it checks a map, not a maze.
81 * Since this is part of the random map code, presumption 69 * Since this is part of the random map code, presumption
82 * is that this is not a tiled map. 70 * is that this is not a tiled map.
83 * What is considered blocking and not is somewhat hard coded. 71 * What is considered blocking and not is somewhat hard coded.
84 */ 72 */
85int 73int
86surround_flag3 (maptile *map, sint16 i, sint16 j, random_map_params *RP) 74surround_flag3 (maptile *map, int i, int j)
87{ 75{
88 /* 76 /*
89 * 1 = blocked to left, 77 * 1 = blocked to left,
90 * 2 = blocked to right, 78 * 2 = blocked to right,
91 * 4 = blocked above 79 * 4 = blocked above
92 * 8 = blocked below 80 * 8 = blocked below
93 */ 81 */
94
95 int surround_index = 0;
96
97 if ((i > 0) && (GET_MAP_MOVE_BLOCK (map, i - 1, j) & ~MOVE_BLOCK_DEFAULT))
98 surround_index |= 1; 82 int surround_index = 0;
99 if ((i < RP->Xsize - 1) && (GET_MAP_MOVE_BLOCK (map, i + 1, j) & ~MOVE_BLOCK_DEFAULT)) 83
100 surround_index |= 2; 84 // don't forget to update the mapspace!
101 if ((j > 0) && (GET_MAP_MOVE_BLOCK (map, i, j - 1) & ~MOVE_BLOCK_DEFAULT)) 85 if (i > 0) map->at (i - 1, j ).update ();
102 surround_index |= 4; 86 if (i < map->width - 1) map->at (i + 1, j ).update ();
103 if ((j < RP->Ysize - 1) && (GET_MAP_MOVE_BLOCK (map, i, j + 1) & ~MOVE_BLOCK_DEFAULT)) 87 if (j > 0) map->at (i , j - 1).update ();
104 surround_index |= 8; 88 if (j < map->height - 1) map->at (i , j + 1).update ();
89
90 if (i > 0 && (GET_MAP_MOVE_BLOCK (map, i - 1, j) & MOVE_WALK)) surround_index |= 1;
91 if (i < map->width - 1 && (GET_MAP_MOVE_BLOCK (map, i + 1, j) & MOVE_WALK)) surround_index |= 2;
92 if (j > 0 && (GET_MAP_MOVE_BLOCK (map, i, j - 1) & MOVE_WALK)) surround_index |= 4;
93 if (j < map->height - 1 && (GET_MAP_MOVE_BLOCK (map, i, j + 1) & MOVE_WALK)) surround_index |= 8;
105 94
106 return surround_index; 95 return surround_index;
107} 96}
108 97
109/* like surround_flag2, except it checks a map, not a layout. */ 98/* like surround_flag2, except it checks a map, not a maze. */
110 99static int
111int
112surround_flag4 (maptile *map, int i, int j, random_map_params *RP) 100surround_flag4 (maptile *map, int i, int j)
113{ 101{
114 /* 1 = blocked to left, 102 /* 1 = blocked to left,
115 2 = blocked to right, 103 2 = blocked to right,
116 4 = blocked above 104 4 = blocked above
117 8 = blocked below */ 105 8 = blocked below */
118 int surround_index = 0; 106 int surround_index = 0;
119 107
120 if ((i > 0) && wall_blocked (map, i - 1, j)) 108 if (i > 0 && wall_blocked (map, i - 1, j)) surround_index |= 1;
121 surround_index |= 1; 109 if (i < map->width - 1 && wall_blocked (map, i + 1, j)) surround_index |= 2;
122 if ((i < RP->Xsize - 1) && wall_blocked (map, i + 1, j)) 110 if (j > 0 && wall_blocked (map, i, j - 1)) surround_index |= 4;
123 surround_index |= 2; 111 if (j < map->height - 1 && wall_blocked (map, i, j + 1)) surround_index |= 8;
124 if ((j > 0) && wall_blocked (map, i, j - 1))
125 surround_index |= 4;
126 if ((j < RP->Ysize - 1) && wall_blocked (map, i, j + 1))
127 surround_index |= 8;
128 112
129 return surround_index; 113 return surround_index;
130} 114}
131 115
116/* picks the right wall type for this square, to make it look nice,
117 and have everything nicely joined. It uses the maze. */
118static object *
119pick_joined_wall (object *the_wall, const layout &maze, int i, int j, random_map_params *RP)
120{
121 /* 1 = wall to left,
122 2 = wall to right,
123 4 = wall above
124 8 = wall below */
125 int surround_index = 0;
126 int l;
127 char wall_name[1024];
128 archetype *wall_arch = 0;
129
130 assign (wall_name, the_wall->arch->archname);
131
132 /* conventionally, walls are named like this:
133 wallname_wallcode, where wallcode indicates
134 a joinedness, and wallname is the wall.
135 this code depends on the convention for
136 finding the right wall. */
137
138 /* extract the wall name, which is the text up to the leading _ */
139 for (l = 0; l < 64; l++)
140 {
141 if (wall_name[l] == '_')
142 {
143 wall_name[l] = 0;
144 break;
145 }
146 }
147
148 surround_index = surround_flag2 (maze, i, j);
149
150 switch (surround_index)
151 {
152 case 0:
153 strcat (wall_name, "_0");
154 break;
155 case 1:
156 strcat (wall_name, "_1_3");
157 break;
158 case 2:
159 strcat (wall_name, "_1_4");
160 break;
161 case 3:
162 strcat (wall_name, "_2_1_2");
163 break;
164 case 4:
165 strcat (wall_name, "_1_2");
166 break;
167 case 5:
168 strcat (wall_name, "_2_2_4");
169 break;
170 case 6:
171 strcat (wall_name, "_2_2_1");
172 break;
173 case 7:
174 strcat (wall_name, "_3_1");
175 break;
176 case 8:
177 strcat (wall_name, "_1_1");
178 break;
179 case 9:
180 strcat (wall_name, "_2_2_3");
181 break;
182 case 10:
183 strcat (wall_name, "_2_2_2");
184 break;
185 case 11:
186 strcat (wall_name, "_3_3");
187 break;
188 case 12:
189 strcat (wall_name, "_2_1_1");
190 break;
191 case 13:
192 strcat (wall_name, "_3_4");
193 break;
194 case 14:
195 strcat (wall_name, "_3_2");
196 break;
197 case 15:
198 strcat (wall_name, "_4");
199 break;
200 }
201 wall_arch = archetype::find (wall_name);
202
203 return wall_arch ? wall_arch->instance () : the_wall->arch->instance ();
204}
205
132/* takes a map and a layout, and puts walls in the map (picked from 206/* takes a map and a maze, and puts walls in the map (picked from
133 w_style) at '#' marks. */ 207 w_style) at '#' marks. */
134
135void 208void
136make_map_walls (maptile *map, char **layout, char *w_style, random_map_params *RP) 209make_map_walls (maptile *map, layout &maze, const char *w_style, const char *m_style, random_map_params *RP)
137{ 210{
138 char styledirname[256];
139 char stylefilepath[256];
140 maptile *style_map = 0;
141 object *the_wall; 211 object *the_wall;
142 212
143 /* get the style map */ 213 /* get the style map */
144 if (!strcmp (w_style, "none")) 214 if (!strcmp (w_style, "none"))
145 return; 215 return;
146 sprintf (styledirname, "%s", "/styles/wallstyles"); 216
147 sprintf (stylefilepath, "%s/%s", styledirname, w_style); 217 maptile *style_map = find_style ("/styles/wallstyles", w_style, RP->difficulty);
148 style_map = find_style (styledirname, w_style, -1);
149 if (style_map == 0) 218 if (!style_map)
150 return; 219 return;
151 220
152 /* fill up the map with the given floor style */ 221 maptile *mining_map = m_style && *m_style
153 if ((the_wall = pick_random_object (style_map)) != NULL) 222 ? find_style ("/styles/miningstyles", m_style, RP->difficulty)
223 : 0;
224
225 if ((the_wall = style_map->pick_random_object (rmg_rndm)))
154 { 226 {
155 int i, j; 227 int i, j;
156 char *cp; 228 char *cp;
157 int joinedwalls = 0; 229 int joinedwalls = 0;
158 object *thiswall; 230 object *thiswall;
159 231
160 sprintf (RP->wall_name, "%s", &the_wall->arch->name); 232 sprintf (RP->wall_name, "%s", &the_wall->arch->archname);
161 if ((cp = strchr (RP->wall_name, '_')) != NULL) 233 if ((cp = strchr (RP->wall_name, '_')) != NULL)
162 { 234 {
163 *cp = 0; 235 *cp = 0;
164 joinedwalls = 1; 236 joinedwalls = 1;
165 } 237 }
166 238
167 for (i = 0; i < RP->Xsize; i++) 239 for (i = 0; i < RP->Xsize; i++)
168 for (j = 0; j < RP->Ysize; j++) 240 for (j = 0; j < RP->Ysize; j++)
169 { 241 {
170 if (layout[i][j] == '#') 242 if (maze[i][j] == '#')
171 { 243 {
172 if (joinedwalls) 244 if (joinedwalls)
173 thiswall = pick_joined_wall (the_wall, layout, i, j, RP); 245 thiswall = pick_joined_wall (the_wall, maze, i, j, RP);
174 else 246 else
175 thiswall = arch_to_object (the_wall->arch); 247 thiswall = the_wall->arch->instance ();
176 thiswall->x = i; 248
177 thiswall->y = j;
178 thiswall->move_block = MOVE_ALL; 249 thiswall->move_block = MOVE_ALL;
179 insert_ob_in_map (thiswall, map, thiswall, INS_NO_MERGE | INS_NO_WALK_ON); 250 map->insert (thiswall, i, j, thiswall, INS_NO_MERGE | INS_NO_WALK_ON);
251
252 if (mining_map)
253 if (object *vein = mining_map->at (rmg_rndm (mining_map->width), rmg_rndm (mining_map->height)).bot)
254 map->insert (vein->clone (), i, j, thiswall, INS_NO_MERGE | INS_NO_WALK_ON);
180 } 255 }
181 } 256 }
182 } 257 }
183} 258}
184
185
186/* picks the right wall type for this square, to make it look nice,
187 and have everything nicely joined. It uses the layout. */
188
189object *
190pick_joined_wall (object *the_wall, char **layout, int i, int j, random_map_params *RP)
191{
192 /* 1 = wall to left,
193 2 = wall to right,
194 4 = wall above
195 8 = wall below */
196 int surround_index = 0;
197 int l;
198 char wall_name[64];
199 archetype *wall_arch = 0;
200
201 strcpy (wall_name, the_wall->arch->name);
202
203 /* conventionally, walls are named like this:
204 wallname_wallcode, where wallcode indicates
205 a joinedness, and wallname is the wall.
206 this code depends on the convention for
207 finding the right wall. */
208
209 /* extract the wall name, which is the text up to the leading _ */
210 for (l = 0; l < 64; l++)
211 {
212 if (wall_name[l] == '_')
213 {
214 wall_name[l] = 0;
215 break;
216 }
217 }
218
219 surround_index = surround_flag2 (layout, i, j, RP);
220
221 switch (surround_index)
222 {
223 case 0:
224 strcat (wall_name, "_0");
225 break;
226 case 1:
227 strcat (wall_name, "_1_3");
228 break;
229 case 2:
230 strcat (wall_name, "_1_4");
231 break;
232 case 3:
233 strcat (wall_name, "_2_1_2");
234 break;
235 case 4:
236 strcat (wall_name, "_1_2");
237 break;
238 case 5:
239 strcat (wall_name, "_2_2_4");
240 break;
241 case 6:
242 strcat (wall_name, "_2_2_1");
243 break;
244 case 7:
245 strcat (wall_name, "_3_1");
246 break;
247 case 8:
248 strcat (wall_name, "_1_1");
249 break;
250 case 9:
251 strcat (wall_name, "_2_2_3");
252 break;
253 case 10:
254 strcat (wall_name, "_2_2_2");
255 break;
256 case 11:
257 strcat (wall_name, "_3_3");
258 break;
259 case 12:
260 strcat (wall_name, "_2_1_1");
261 break;
262 case 13:
263 strcat (wall_name, "_3_4");
264 break;
265 case 14:
266 strcat (wall_name, "_3_2");
267 break;
268 case 15:
269 strcat (wall_name, "_4");
270 break;
271 }
272 wall_arch = archetype::find (wall_name);
273
274 return wall_arch ? arch_to_object (wall_arch) : arch_to_object (the_wall->arch);
275}
276
277 259
278/* this takes a map, and changes an existing wall to match what's blocked 260/* this takes a map, and changes an existing wall to match what's blocked
279 * around it, counting only doors and walls as blocked. If insert_flag is 261 * around it, counting only doors and walls as blocked. If insert_flag is
280 * 1, it will go ahead and insert the wall into the map. If not, it 262 * 1, it will go ahead and insert the wall into the map. If not, it
281 * will only return the wall which would belong there, and doesn't 263 * will only return the wall which would belong there, and doesn't
282 * remove anything. It depends on the 264 * remove anything. It depends on the
283 * global, previously-set variable, "wall_name" 265 * global, previously-set variable, "wall_name"
284 */ 266 */
285
286object * 267object *
287retrofit_joined_wall (maptile *the_map, int i, int j, int insert_flag, random_map_params *RP) 268retrofit_joined_wall (maptile *the_map, int i, int j, int insert_flag, random_map_params *RP)
288{ 269{
289 /* 1 = wall to left, 270 /* 1 = wall to left,
290 * 2 = wall to right, 271 * 2 = wall to right,
326 RP->wall_name[l] = 0; 307 RP->wall_name[l] = 0;
327 break; 308 break;
328 } 309 }
329 } 310 }
330 311
331 surround_index = surround_flag4 (the_map, i, j, RP); 312 surround_index = surround_flag4 (the_map, i, j);
332 /* This would be a lot cleaner to just us a lookup table, 313 /* This would be a lot cleaner to just us a lookup table,
333 * eg, wall_suffix[surround_index] 314 * eg, wall_suffix[surround_index]
334 */ 315 */
335 switch (surround_index) 316 switch (surround_index)
336 { 317 {
386 367
387 wall_arch = archetype::find (RP->wall_name); 368 wall_arch = archetype::find (RP->wall_name);
388 369
389 if (!wall_arch) 370 if (!wall_arch)
390 { 371 {
391 new_wall = arch_to_object (wall_arch); 372 new_wall = wall_arch->instance ();
392 new_wall->x = i; 373 new_wall->x = i;
393 new_wall->y = j; 374 new_wall->y = j;
394 375
395 if (the_wall && the_wall->map) 376 if (the_wall && the_wall->map)
396 {
397 the_wall->remove ();
398 the_wall->destroy (); 377 the_wall->destroy ();
399 }
400 378
401 the_wall->move_block = MOVE_ALL; 379 the_wall->move_block = MOVE_ALL;
402 insert_ob_in_map (new_wall, the_map, new_wall, INS_NO_MERGE | INS_NO_WALK_ON); 380 insert_ob_in_map (new_wall, the_map, new_wall, INS_NO_MERGE | INS_NO_WALK_ON);
403 } 381 }
404 382

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines