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.10 by root, Wed Dec 20 09:14:22 2006 UTC vs.
Revision 1.37 by root, Fri Jul 2 03:40:14 2010 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 3 *
4 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
6 7 *
7 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
8 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
9 the Free Software Foundation; either version 2 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
10 (at your option) any later version. 11 * option) any later version.
11 12 *
12 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,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 16 * GNU General Public License for more details.
16 17 *
17 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
18 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
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * <http://www.gnu.org/licenses/>.
20 21 *
21 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>
22*/ 23 */
23 24
24#include <global.h> 25#include <global.h>
25#include <random_map.h> 26#include <random_map.h>
26#include <rproto.h> 27#include <rproto.h>
27 28
28/* Put in the walls and autojoin them. */ 29/* Put in the walls and autojoin them. */
29 30
30
31/* given a layout and a coordinate, tell me which squares up/down/right/left 31/* given a layout and a coordinate, tell me which squares up/down/right/left
32 are occupied. */ 32 are occupied. */
33
34int 33int
35surround_flag (char **layout, int i, int j, RMParms * RP) 34surround_flag (const Layout &layout, int i, int j)
36{ 35{
37 /* 1 = wall to left, 36 /* 1 = wall to left,
38 2 = wall to right, 37 2 = wall to right,
39 4 = wall above 38 4 = wall above
40 8 = wall below */ 39 8 = wall below */
41 int surround_index = 0; 40 int surround_index = 0;
42 41
43 if ((i > 0) && layout[i - 1][j] != 0) 42 if (i > 0 && layout[i - 1][j] != 0) surround_index |= 1;
44 surround_index |= 1; 43 if (i < layout.w - 1 && layout[i + 1][j] != 0) surround_index |= 2;
45 if ((i < RP->Xsize - 1) && layout[i + 1][j] != 0) 44 if (j > 0 && layout[i][j - 1] != 0) surround_index |= 4;
46 surround_index |= 2; 45 if (j < layout.h - 1 && layout[i][j + 1] != 0) surround_index |= 8;
47 if ((j > 0) && layout[i][j - 1] != 0) 46
48 surround_index |= 4;
49 if ((j < RP->Ysize - 1) && layout[i][j + 1] != 0)
50 surround_index |= 8;
51 return surround_index; 47 return surround_index;
52} 48}
53 49
54
55/* like surround_flag, but only walls count. 50/* like surround_flag, but only walls count. */
56 */
57
58int 51int
59surround_flag2 (char **layout, int i, int j, RMParms * RP) 52surround_flag2 (const Layout &layout, int i, int j)
60{ 53{
61 /* 1 = wall to left, 54 /* 1 = wall to left,
62 2 = wall to right, 55 2 = wall to right,
63 4 = wall above 56 4 = wall above
64 8 = wall below */ 57 8 = wall below */
65 int surround_index = 0; 58 int surround_index = 0;
66 59
67 if ((i > 0) && layout[i - 1][j] == '#') 60 if (i > 0 && layout[i - 1][j] == '#') surround_index |= 1;
68 surround_index |= 1; 61 if (i < layout.w - 1 && layout[i + 1][j] == '#') surround_index |= 2;
69 if ((i < RP->Xsize - 1) && layout[i + 1][j] == '#') 62 if (j > 0 && layout[i][j - 1] == '#') surround_index |= 4;
70 surround_index |= 2; 63 if (j < layout.h - 1 && layout[i][j + 1] == '#') surround_index |= 8;
71 if ((j > 0) && layout[i][j - 1] == '#') 64
72 surround_index |= 4;
73 if ((j < RP->Ysize - 1) && layout[i][j + 1] == '#')
74 surround_index |= 8;
75 return surround_index; 65 return surround_index;
76} 66}
77
78 67
79/* like surround_flag, except it checks a map, not a layout. 68/* like surround_flag, except it checks a map, not a layout.
80 * Since this is part of the random map code, presumption 69 * Since this is part of the random map code, presumption
81 * is that this is not a tiled map. 70 * is that this is not a tiled map.
82 * What is considered blocking and not is somewhat hard coded. 71 * What is considered blocking and not is somewhat hard coded.
83 */ 72 */
84int 73int
85surround_flag3 (maptile *map, sint16 i, sint16 j, RMParms * RP) 74surround_flag3 (maptile *map, int i, int j)
86{ 75{
87 /* 76 /*
88 * 1 = blocked to left, 77 * 1 = blocked to left,
89 * 2 = blocked to right, 78 * 2 = blocked to right,
90 * 4 = blocked above 79 * 4 = blocked above
91 * 8 = blocked below 80 * 8 = blocked below
92 */ 81 */
93
94 int surround_index = 0;
95
96 if ((i > 0) && (GET_MAP_MOVE_BLOCK (map, i - 1, j) & ~MOVE_BLOCK_DEFAULT))
97 surround_index |= 1; 82 int surround_index = 0;
98 if ((i < RP->Xsize - 1) && (GET_MAP_MOVE_BLOCK (map, i + 1, j) & ~MOVE_BLOCK_DEFAULT)) 83
99 surround_index |= 2; 84 // don't forget to update the mapspace!
100 if ((j > 0) && (GET_MAP_MOVE_BLOCK (map, i, j - 1) & ~MOVE_BLOCK_DEFAULT)) 85 if (i > 0) map->at (i - 1, j ).update ();
101 surround_index |= 4; 86 if (i < map->width - 1) map->at (i + 1, j ).update ();
102 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 ();
103 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;
104 94
105 return surround_index; 95 return surround_index;
106} 96}
107 97
108/* like surround_flag2, except it checks a map, not a layout. */ 98/* like surround_flag2, except it checks a map, not a layout. */
109 99static int
110int
111surround_flag4 (maptile *map, int i, int j, RMParms * RP) 100surround_flag4 (maptile *map, int i, int j)
112{ 101{
113 /* 1 = blocked to left, 102 /* 1 = blocked to left,
114 2 = blocked to right, 103 2 = blocked to right,
115 4 = blocked above 104 4 = blocked above
116 8 = blocked below */ 105 8 = blocked below */
117 int surround_index = 0; 106 int surround_index = 0;
118 107
119 if ((i > 0) && wall_blocked (map, i - 1, j)) 108 if (i > 0 && wall_blocked (map, i - 1, j)) surround_index |= 1;
120 surround_index |= 1; 109 if (i < map->width - 1 && wall_blocked (map, i + 1, j)) surround_index |= 2;
121 if ((i < RP->Xsize - 1) && wall_blocked (map, i + 1, j)) 110 if (j > 0 && wall_blocked (map, i, j - 1)) surround_index |= 4;
122 surround_index |= 2; 111 if (j < map->height - 1 && wall_blocked (map, i, j + 1)) surround_index |= 8;
123 if ((j > 0) && wall_blocked (map, i, j - 1))
124 surround_index |= 4;
125 if ((j < RP->Ysize - 1) && wall_blocked (map, i, j + 1))
126 surround_index |= 8;
127 112
128 return surround_index; 113 return surround_index;
114}
115
116/* picks the right wall type for this square, to make it look nice,
117 and have everything nicely joined. It uses the layout. */
118static object *
119pick_joined_wall (object *the_wall, const Layout &layout, 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 (layout, 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 ();
129} 204}
130 205
131/* takes a map and a layout, and puts walls in the map (picked from 206/* takes a map and a layout, and puts walls in the map (picked from
132 w_style) at '#' marks. */ 207 w_style) at '#' marks. */
133
134void 208void
135make_map_walls (maptile *map, char **layout, char *w_style, RMParms * RP) 209make_map_walls (maptile *map, Layout &layout, const char *w_style, const char *m_style, random_map_params *RP)
136{ 210{
137 char styledirname[256];
138 char stylefilepath[256];
139 maptile *style_map = 0;
140 object *the_wall; 211 object *the_wall;
141 212
142 /* get the style map */ 213 /* get the style map */
143 if (!strcmp (w_style, "none")) 214 if (!strcmp (w_style, "none"))
144 return; 215 return;
145 sprintf (styledirname, "%s", "/styles/wallstyles"); 216
146 sprintf (stylefilepath, "%s/%s", styledirname, w_style); 217 maptile *style_map = find_style ("/styles/wallstyles", w_style, RP->difficulty);
147 style_map = find_style (styledirname, w_style, -1);
148 if (style_map == 0) 218 if (!style_map)
149 return; 219 return;
150 220
151 /* fill up the map with the given floor style */ 221 maptile *mining_map = m_style && *m_style
152 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)))
153 { 226 {
154 int i, j; 227 int i, j;
155 char *cp; 228 char *cp;
156 int joinedwalls = 0; 229 int joinedwalls = 0;
157 object *thiswall; 230 object *thiswall;
158 231
159 sprintf (RP->wall_name, "%s", &the_wall->arch->name); 232 sprintf (RP->wall_name, "%s", &the_wall->arch->archname);
160 if ((cp = strchr (RP->wall_name, '_')) != NULL) 233 if ((cp = strchr (RP->wall_name, '_')) != NULL)
161 { 234 {
162 *cp = 0; 235 *cp = 0;
163 joinedwalls = 1; 236 joinedwalls = 1;
164 } 237 }
169 if (layout[i][j] == '#') 242 if (layout[i][j] == '#')
170 { 243 {
171 if (joinedwalls) 244 if (joinedwalls)
172 thiswall = pick_joined_wall (the_wall, layout, i, j, RP); 245 thiswall = pick_joined_wall (the_wall, layout, i, j, RP);
173 else 246 else
174 thiswall = arch_to_object (the_wall->arch); 247 thiswall = the_wall->arch->instance ();
175 thiswall->x = i; 248
176 thiswall->y = j;
177 thiswall->move_block = MOVE_ALL; 249 thiswall->move_block = MOVE_ALL;
178 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);
179 } 255 }
180 } 256 }
181 } 257 }
182} 258}
183
184
185/* picks the right wall type for this square, to make it look nice,
186 and have everything nicely joined. It uses the layout. */
187
188object *
189pick_joined_wall (object *the_wall, char **layout, int i, int j, RMParms * RP)
190{
191 /* 1 = wall to left,
192 2 = wall to right,
193 4 = wall above
194 8 = wall below */
195 int surround_index = 0;
196 int l;
197 char wall_name[64];
198 archetype *wall_arch = 0;
199
200 strcpy (wall_name, the_wall->arch->name);
201
202 /* conventionally, walls are named like this:
203 wallname_wallcode, where wallcode indicates
204 a joinedness, and wallname is the wall.
205 this code depends on the convention for
206 finding the right wall. */
207
208 /* extract the wall name, which is the text up to the leading _ */
209 for (l = 0; l < 64; l++)
210 {
211 if (wall_name[l] == '_')
212 {
213 wall_name[l] = 0;
214 break;
215 }
216 }
217
218 surround_index = surround_flag2 (layout, i, j, RP);
219
220 switch (surround_index)
221 {
222 case 0:
223 strcat (wall_name, "_0");
224 break;
225 case 1:
226 strcat (wall_name, "_1_3");
227 break;
228 case 2:
229 strcat (wall_name, "_1_4");
230 break;
231 case 3:
232 strcat (wall_name, "_2_1_2");
233 break;
234 case 4:
235 strcat (wall_name, "_1_2");
236 break;
237 case 5:
238 strcat (wall_name, "_2_2_4");
239 break;
240 case 6:
241 strcat (wall_name, "_2_2_1");
242 break;
243 case 7:
244 strcat (wall_name, "_3_1");
245 break;
246 case 8:
247 strcat (wall_name, "_1_1");
248 break;
249 case 9:
250 strcat (wall_name, "_2_2_3");
251 break;
252 case 10:
253 strcat (wall_name, "_2_2_2");
254 break;
255 case 11:
256 strcat (wall_name, "_3_3");
257 break;
258 case 12:
259 strcat (wall_name, "_2_1_1");
260 break;
261 case 13:
262 strcat (wall_name, "_3_4");
263 break;
264 case 14:
265 strcat (wall_name, "_3_2");
266 break;
267 case 15:
268 strcat (wall_name, "_4");
269 break;
270 }
271 wall_arch = archetype::find (wall_name);
272 if (wall_arch)
273 return arch_to_object (wall_arch);
274 else
275 {
276 nroferrors--;
277 return arch_to_object (the_wall->arch);
278 }
279
280
281}
282
283 259
284/* 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
285 * 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
286 * 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
287 * 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
288 * remove anything. It depends on the 264 * remove anything. It depends on the
289 * global, previously-set variable, "wall_name" 265 * global, previously-set variable, "wall_name"
290 */ 266 */
291
292object * 267object *
293retrofit_joined_wall (maptile *the_map, int i, int j, int insert_flag, RMParms * RP) 268retrofit_joined_wall (maptile *the_map, int i, int j, int insert_flag, random_map_params *RP)
294{ 269{
295 /* 1 = wall to left, 270 /* 1 = wall to left,
296 * 2 = wall to right, 271 * 2 = wall to right,
297 * 4 = wall above 272 * 4 = wall above
298 * 8 = wall below 273 * 8 = wall below
332 RP->wall_name[l] = 0; 307 RP->wall_name[l] = 0;
333 break; 308 break;
334 } 309 }
335 } 310 }
336 311
337 surround_index = surround_flag4 (the_map, i, j, RP); 312 surround_index = surround_flag4 (the_map, i, j);
338 /* 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,
339 * eg, wall_suffix[surround_index] 314 * eg, wall_suffix[surround_index]
340 */ 315 */
341 switch (surround_index) 316 switch (surround_index)
342 { 317 {
343 case 0: 318 case 0:
344 strcat (RP->wall_name, "_0"); 319 strcat (RP->wall_name, "_0");
345 break; 320 break;
346 case 1: 321 case 1:
347 strcat (RP->wall_name, "_1_3"); 322 strcat (RP->wall_name, "_1_3");
348 break; 323 break;
349 case 2: 324 case 2:
350 strcat (RP->wall_name, "_1_4"); 325 strcat (RP->wall_name, "_1_4");
351 break; 326 break;
352 case 3: 327 case 3:
353 strcat (RP->wall_name, "_2_1_2"); 328 strcat (RP->wall_name, "_2_1_2");
354 break; 329 break;
355 case 4: 330 case 4:
356 strcat (RP->wall_name, "_1_2"); 331 strcat (RP->wall_name, "_1_2");
357 break; 332 break;
358 case 5: 333 case 5:
359 strcat (RP->wall_name, "_2_2_4"); 334 strcat (RP->wall_name, "_2_2_4");
360 break; 335 break;
361 case 6: 336 case 6:
362 strcat (RP->wall_name, "_2_2_1"); 337 strcat (RP->wall_name, "_2_2_1");
363 break; 338 break;
364 case 7: 339 case 7:
365 strcat (RP->wall_name, "_3_1"); 340 strcat (RP->wall_name, "_3_1");
366 break; 341 break;
367 case 8: 342 case 8:
368 strcat (RP->wall_name, "_1_1"); 343 strcat (RP->wall_name, "_1_1");
369 break; 344 break;
370 case 9: 345 case 9:
371 strcat (RP->wall_name, "_2_2_3"); 346 strcat (RP->wall_name, "_2_2_3");
372 break; 347 break;
373 case 10: 348 case 10:
374 strcat (RP->wall_name, "_2_2_2"); 349 strcat (RP->wall_name, "_2_2_2");
375 break; 350 break;
376 case 11: 351 case 11:
377 strcat (RP->wall_name, "_3_3"); 352 strcat (RP->wall_name, "_3_3");
378 break; 353 break;
379 case 12: 354 case 12:
380 strcat (RP->wall_name, "_2_1_1"); 355 strcat (RP->wall_name, "_2_1_1");
381 break; 356 break;
382 case 13: 357 case 13:
383 strcat (RP->wall_name, "_3_4"); 358 strcat (RP->wall_name, "_3_4");
384 break; 359 break;
385 case 14: 360 case 14:
386 strcat (RP->wall_name, "_3_2"); 361 strcat (RP->wall_name, "_3_2");
387 break; 362 break;
388 case 15: 363 case 15:
389 strcat (RP->wall_name, "_4"); 364 strcat (RP->wall_name, "_4");
390 break; 365 break;
391 } 366 }
367
392 wall_arch = archetype::find (RP->wall_name); 368 wall_arch = archetype::find (RP->wall_name);
369
393 if (wall_arch != NULL) 370 if (!wall_arch)
394 { 371 {
395 new_wall = arch_to_object (wall_arch); 372 new_wall = wall_arch->instance ();
396 new_wall->x = i; 373 new_wall->x = i;
397 new_wall->y = j; 374 new_wall->y = j;
375
398 if (the_wall && the_wall->map) 376 if (the_wall && the_wall->map)
399 {
400 the_wall->remove ();
401 the_wall->destroy (); 377 the_wall->destroy ();
402 } 378
403 the_wall->move_block = MOVE_ALL; 379 the_wall->move_block = MOVE_ALL;
404 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);
405 } 381 }
406 else 382
407 nroferrors--; /* it's OK not to find an arch. */
408 return new_wall; 383 return new_wall;
409} 384}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines