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.31 by root, Fri Nov 6 13:03:34 2009 UTC vs.
Revision 1.36 by root, Sat Apr 10 01:54:07 2010 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 8 * 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 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 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version. 11 * option) any later version.
37 2 = wall to right, 37 2 = wall to right,
38 4 = wall above 38 4 = wall above
39 8 = wall below */ 39 8 = wall below */
40 int surround_index = 0; 40 int surround_index = 0;
41 41
42 if ((i > 0) && layout[i - 1][j] != 0) 42 if (i > 0 && layout[i - 1][j] != 0) surround_index |= 1;
43 surround_index |= 1;
44 if ((i < RP->Xsize - 1) && layout[i + 1][j] != 0) 43 if (i < RP->Xsize - 1 && layout[i + 1][j] != 0) surround_index |= 2;
45 surround_index |= 2; 44 if (j > 0 && layout[i][j - 1] != 0) surround_index |= 4;
46 if ((j > 0) && layout[i][j - 1] != 0)
47 surround_index |= 4;
48 if ((j < RP->Ysize - 1) && layout[i][j + 1] != 0) 45 if (j < RP->Ysize - 1 && layout[i][j + 1] != 0) surround_index |= 8;
49 surround_index |= 8; 46
50 return surround_index; 47 return surround_index;
51} 48}
52 49
53 50
54/* like surround_flag, but only walls count. 51/* like surround_flag, but only walls count.
61 2 = wall to right, 58 2 = wall to right,
62 4 = wall above 59 4 = wall above
63 8 = wall below */ 60 8 = wall below */
64 int surround_index = 0; 61 int surround_index = 0;
65 62
66 if ((i > 0) && layout[i - 1][j] == '#') 63 if (i > 0 && layout[i - 1][j] == '#') surround_index |= 1;
67 surround_index |= 1;
68 if ((i < RP->Xsize - 1) && layout[i + 1][j] == '#') 64 if (i < RP->Xsize - 1 && layout[i + 1][j] == '#') surround_index |= 2;
69 surround_index |= 2; 65 if (j > 0 && layout[i][j - 1] == '#') surround_index |= 4;
70 if ((j > 0) && layout[i][j - 1] == '#')
71 surround_index |= 4;
72 if ((j < RP->Ysize - 1) && layout[i][j + 1] == '#') 66 if (j < RP->Ysize - 1 && layout[i][j + 1] == '#') surround_index |= 8;
73 surround_index |= 8; 67
74 return surround_index; 68 return surround_index;
75} 69}
76 70
77 71
78/* like surround_flag, except it checks a map, not a layout. 72/* like surround_flag, except it checks a map, not a layout.
96 if (i > 0) map->at (i - 1, j ).update (); 90 if (i > 0) map->at (i - 1, j ).update ();
97 if (i < RP->Xsize - 1) map->at (i + 1, j ).update (); 91 if (i < RP->Xsize - 1) map->at (i + 1, j ).update ();
98 if (j > 0) map->at (i , j - 1).update (); 92 if (j > 0) map->at (i , j - 1).update ();
99 if (j < RP->Ysize - 1) map->at (i , j + 1).update (); 93 if (j < RP->Ysize - 1) map->at (i , j + 1).update ();
100 94
101 if ((i > 0) && (GET_MAP_MOVE_BLOCK (map, i - 1, j) & MOVE_WALK)) 95 if (i > 0 && (GET_MAP_MOVE_BLOCK (map, i - 1, j) & MOVE_WALK)) surround_index |= 1;
102 surround_index |= 1;
103 if ((i < RP->Xsize - 1) && (GET_MAP_MOVE_BLOCK (map, i + 1, j) & MOVE_WALK)) 96 if (i < RP->Xsize - 1 && (GET_MAP_MOVE_BLOCK (map, i + 1, j) & MOVE_WALK)) surround_index |= 2;
104 surround_index |= 2;
105 if ((j > 0) && (GET_MAP_MOVE_BLOCK (map, i, j - 1) & MOVE_WALK)) 97 if (j > 0 && (GET_MAP_MOVE_BLOCK (map, i, j - 1) & MOVE_WALK)) surround_index |= 4;
106 surround_index |= 4;
107 if ((j < RP->Ysize - 1) && (GET_MAP_MOVE_BLOCK (map, i, j + 1) & MOVE_WALK)) 98 if (j < RP->Ysize - 1 && (GET_MAP_MOVE_BLOCK (map, i, j + 1) & MOVE_WALK)) surround_index |= 8;
108 surround_index |= 8;
109 99
110 return surround_index; 100 return surround_index;
111} 101}
112 102
113/* like surround_flag2, except it checks a map, not a layout. */ 103/* like surround_flag2, except it checks a map, not a layout. */
118 2 = blocked to right, 108 2 = blocked to right,
119 4 = blocked above 109 4 = blocked above
120 8 = blocked below */ 110 8 = blocked below */
121 int surround_index = 0; 111 int surround_index = 0;
122 112
123 if ((i > 0) && wall_blocked (map, i - 1, j)) 113 if (i > 0 && wall_blocked (map, i - 1, j)) surround_index |= 1;
124 surround_index |= 1;
125 if ((i < RP->Xsize - 1) && wall_blocked (map, i + 1, j)) 114 if (i < RP->Xsize - 1 && wall_blocked (map, i + 1, j)) surround_index |= 2;
126 surround_index |= 2; 115 if (j > 0 && wall_blocked (map, i, j - 1)) surround_index |= 4;
127 if ((j > 0) && wall_blocked (map, i, j - 1))
128 surround_index |= 4;
129 if ((j < RP->Ysize - 1) && wall_blocked (map, i, j + 1)) 116 if (j < RP->Ysize - 1 && wall_blocked (map, i, j + 1)) surround_index |= 8;
130 surround_index |= 8;
131 117
132 return surround_index; 118 return surround_index;
133} 119}
134 120
135/* picks the right wall type for this square, to make it look nice, 121/* picks the right wall type for this square, to make it look nice,
217 strcat (wall_name, "_4"); 203 strcat (wall_name, "_4");
218 break; 204 break;
219 } 205 }
220 wall_arch = archetype::find (wall_name); 206 wall_arch = archetype::find (wall_name);
221 207
222 return wall_arch ? arch_to_object (wall_arch) : arch_to_object (the_wall->arch); 208 return wall_arch ? wall_arch->instance () : the_wall->arch->instance ();
223} 209}
224 210
225/* takes a map and a layout, and puts walls in the map (picked from 211/* takes a map and a layout, and puts walls in the map (picked from
226 w_style) at '#' marks. */ 212 w_style) at '#' marks. */
227void 213void
228make_map_walls (maptile *map, char **layout, char *w_style, random_map_params *RP) 214make_map_walls (maptile *map, char **layout, const char *w_style, const char *m_style, random_map_params *RP)
229{ 215{
230 char styledirname[1024];
231 char stylefilepath[1024];
232 maptile *style_map = 0;
233 object *the_wall; 216 object *the_wall;
234 217
235 /* get the style map */ 218 /* get the style map */
236 if (!strcmp (w_style, "none")) 219 if (!strcmp (w_style, "none"))
237 return; 220 return;
238 sprintf (styledirname, "%s", "/styles/wallstyles"); 221
239 sprintf (stylefilepath, "%s/%s", styledirname, w_style); 222 maptile *style_map = find_style ("/styles/wallstyles", w_style, RP->difficulty);
240 style_map = find_style (styledirname, w_style, -1);
241 if (!style_map) 223 if (!style_map)
242 return; 224 return;
243 225
244 /* fill up the map with the given floor style */ 226 maptile *mining_map = m_style && *m_style
227 ? find_style ("/styles/miningstyles", m_style, RP->difficulty)
228 : 0;
229
245 if ((the_wall = style_map->pick_random_object (rmg_rndm))) 230 if ((the_wall = style_map->pick_random_object (rmg_rndm)))
246 { 231 {
247 int i, j; 232 int i, j;
248 char *cp; 233 char *cp;
249 int joinedwalls = 0; 234 int joinedwalls = 0;
262 if (layout[i][j] == '#') 247 if (layout[i][j] == '#')
263 { 248 {
264 if (joinedwalls) 249 if (joinedwalls)
265 thiswall = pick_joined_wall (the_wall, layout, i, j, RP); 250 thiswall = pick_joined_wall (the_wall, layout, i, j, RP);
266 else 251 else
267 thiswall = arch_to_object (the_wall->arch); 252 thiswall = the_wall->arch->instance ();
268 253
269 thiswall->x = i;
270 thiswall->y = j;
271 thiswall->move_block = MOVE_ALL; 254 thiswall->move_block = MOVE_ALL;
272 insert_ob_in_map (thiswall, map, thiswall, INS_NO_MERGE | INS_NO_WALK_ON); 255 map->insert (thiswall, i, j, thiswall, INS_NO_MERGE | INS_NO_WALK_ON);
256
257 if (mining_map)
258 if (object *vein = mining_map->at (rmg_rndm (mining_map->width), rmg_rndm (mining_map->height)).bot)
259 map->insert (vein->clone (), i, j, thiswall, INS_NO_MERGE | INS_NO_WALK_ON);
273 } 260 }
274 } 261 }
275 } 262 }
276} 263}
277 264
385 372
386 wall_arch = archetype::find (RP->wall_name); 373 wall_arch = archetype::find (RP->wall_name);
387 374
388 if (!wall_arch) 375 if (!wall_arch)
389 { 376 {
390 new_wall = arch_to_object (wall_arch); 377 new_wall = wall_arch->instance ();
391 new_wall->x = i; 378 new_wall->x = i;
392 new_wall->y = j; 379 new_wall->y = j;
393 380
394 if (the_wall && the_wall->map) 381 if (the_wall && the_wall->map)
395 the_wall->destroy (); 382 the_wall->destroy ();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines