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.37 by root, Fri Jul 2 03:40:14 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.
29/* Put in the walls and autojoin them. */ 29/* Put in the walls and autojoin them. */
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. */
33int 33int
34surround_flag (char **layout, int i, int j, random_map_params *RP) 34surround_flag (const Layout &layout, int i, int j)
35{ 35{
36 /* 1 = wall to left, 36 /* 1 = wall to left,
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; 43 if (i < layout.w - 1 && layout[i + 1][j] != 0) surround_index |= 2;
44 if ((i < RP->Xsize - 1) && layout[i + 1][j] != 0) 44 if (j > 0 && layout[i][j - 1] != 0) surround_index |= 4;
45 surround_index |= 2; 45 if (j < layout.h - 1 && layout[i][j + 1] != 0) surround_index |= 8;
46 if ((j > 0) && layout[i][j - 1] != 0) 46
47 surround_index |= 4;
48 if ((j < RP->Ysize - 1) && layout[i][j + 1] != 0)
49 surround_index |= 8;
50 return surround_index; 47 return surround_index;
51} 48}
52 49
53
54/* like surround_flag, but only walls count. 50/* like surround_flag, but only walls count. */
55 */
56
57int 51int
58surround_flag2 (char **layout, int i, int j, random_map_params *RP) 52surround_flag2 (const Layout &layout, int i, int j)
59{ 53{
60 /* 1 = wall to left, 54 /* 1 = wall to left,
61 2 = wall to right, 55 2 = wall to right,
62 4 = wall above 56 4 = wall above
63 8 = wall below */ 57 8 = wall below */
64 int surround_index = 0; 58 int surround_index = 0;
65 59
66 if ((i > 0) && layout[i - 1][j] == '#') 60 if (i > 0 && layout[i - 1][j] == '#') surround_index |= 1;
67 surround_index |= 1; 61 if (i < layout.w - 1 && layout[i + 1][j] == '#') surround_index |= 2;
68 if ((i < RP->Xsize - 1) && layout[i + 1][j] == '#') 62 if (j > 0 && layout[i][j - 1] == '#') surround_index |= 4;
69 surround_index |= 2; 63 if (j < layout.h - 1 && layout[i][j + 1] == '#') surround_index |= 8;
70 if ((j > 0) && layout[i][j - 1] == '#') 64
71 surround_index |= 4;
72 if ((j < RP->Ysize - 1) && layout[i][j + 1] == '#')
73 surround_index |= 8;
74 return surround_index; 65 return surround_index;
75} 66}
76
77 67
78/* like surround_flag, except it checks a map, not a layout. 68/* like surround_flag, except it checks a map, not a layout.
79 * Since this is part of the random map code, presumption 69 * Since this is part of the random map code, presumption
80 * is that this is not a tiled map. 70 * is that this is not a tiled map.
81 * What is considered blocking and not is somewhat hard coded. 71 * What is considered blocking and not is somewhat hard coded.
82 */ 72 */
83int 73int
84surround_flag3 (maptile *map, sint16 i, sint16 j, random_map_params *RP) 74surround_flag3 (maptile *map, int i, int j)
85{ 75{
86 /* 76 /*
87 * 1 = blocked to left, 77 * 1 = blocked to left,
88 * 2 = blocked to right, 78 * 2 = blocked to right,
89 * 4 = blocked above 79 * 4 = blocked above
90 * 8 = blocked below 80 * 8 = blocked below
91 */ 81 */
92
93 int surround_index = 0; 82 int surround_index = 0;
94 83
95 // don't forget to update the mapspace! 84 // don't forget to update the mapspace!
96 if (i > 0) map->at (i - 1, j ).update (); 85 if (i > 0) map->at (i - 1, j ).update ();
97 if (i < RP->Xsize - 1) map->at (i + 1, j ).update (); 86 if (i < map->width - 1) map->at (i + 1, j ).update ();
98 if (j > 0) map->at (i , j - 1).update (); 87 if (j > 0) map->at (i , j - 1).update ();
99 if (j < RP->Ysize - 1) map->at (i , j + 1).update (); 88 if (j < map->height - 1) map->at (i , j + 1).update ();
100 89
101 if ((i > 0) && (GET_MAP_MOVE_BLOCK (map, i - 1, j) & MOVE_WALK)) 90 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)) 91 if (i < map->width - 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)) 92 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)) 93 if (j < map->height - 1 && (GET_MAP_MOVE_BLOCK (map, i, j + 1) & MOVE_WALK)) surround_index |= 8;
108 surround_index |= 8;
109 94
110 return surround_index; 95 return surround_index;
111} 96}
112 97
113/* like surround_flag2, except it checks a map, not a layout. */ 98/* like surround_flag2, except it checks a map, not a layout. */
114static int 99static int
115surround_flag4 (maptile *map, int i, int j, random_map_params *RP) 100surround_flag4 (maptile *map, int i, int j)
116{ 101{
117 /* 1 = blocked to left, 102 /* 1 = blocked to left,
118 2 = blocked to right, 103 2 = blocked to right,
119 4 = blocked above 104 4 = blocked above
120 8 = blocked below */ 105 8 = blocked below */
121 int surround_index = 0; 106 int surround_index = 0;
122 107
123 if ((i > 0) && wall_blocked (map, i - 1, j)) 108 if (i > 0 && wall_blocked (map, i - 1, j)) surround_index |= 1;
124 surround_index |= 1; 109 if (i < map->width - 1 && wall_blocked (map, i + 1, j)) surround_index |= 2;
125 if ((i < RP->Xsize - 1) && wall_blocked (map, i + 1, j)) 110 if (j > 0 && wall_blocked (map, i, j - 1)) surround_index |= 4;
126 surround_index |= 2; 111 if (j < map->height - 1 && wall_blocked (map, i, j + 1)) surround_index |= 8;
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))
130 surround_index |= 8;
131 112
132 return surround_index; 113 return surround_index;
133} 114}
134 115
135/* picks the right wall type for this square, to make it look nice, 116/* picks the right wall type for this square, to make it look nice,
136 and have everything nicely joined. It uses the layout. */ 117 and have everything nicely joined. It uses the layout. */
137static object * 118static object *
138pick_joined_wall (object *the_wall, char **layout, int i, int j, random_map_params *RP) 119pick_joined_wall (object *the_wall, const Layout &layout, int i, int j, random_map_params *RP)
139{ 120{
140 /* 1 = wall to left, 121 /* 1 = wall to left,
141 2 = wall to right, 122 2 = wall to right,
142 4 = wall above 123 4 = wall above
143 8 = wall below */ 124 8 = wall below */
162 wall_name[l] = 0; 143 wall_name[l] = 0;
163 break; 144 break;
164 } 145 }
165 } 146 }
166 147
167 surround_index = surround_flag2 (layout, i, j, RP); 148 surround_index = surround_flag2 (layout, i, j);
168 149
169 switch (surround_index) 150 switch (surround_index)
170 { 151 {
171 case 0: 152 case 0:
172 strcat (wall_name, "_0"); 153 strcat (wall_name, "_0");
217 strcat (wall_name, "_4"); 198 strcat (wall_name, "_4");
218 break; 199 break;
219 } 200 }
220 wall_arch = archetype::find (wall_name); 201 wall_arch = archetype::find (wall_name);
221 202
222 return wall_arch ? arch_to_object (wall_arch) : arch_to_object (the_wall->arch); 203 return wall_arch ? wall_arch->instance () : the_wall->arch->instance ();
223} 204}
224 205
225/* 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
226 w_style) at '#' marks. */ 207 w_style) at '#' marks. */
227void 208void
228make_map_walls (maptile *map, char **layout, char *w_style, random_map_params *RP) 209make_map_walls (maptile *map, Layout &layout, const char *w_style, const char *m_style, random_map_params *RP)
229{ 210{
230 char styledirname[1024];
231 char stylefilepath[1024];
232 maptile *style_map = 0;
233 object *the_wall; 211 object *the_wall;
234 212
235 /* get the style map */ 213 /* get the style map */
236 if (!strcmp (w_style, "none")) 214 if (!strcmp (w_style, "none"))
237 return; 215 return;
238 sprintf (styledirname, "%s", "/styles/wallstyles"); 216
239 sprintf (stylefilepath, "%s/%s", styledirname, w_style); 217 maptile *style_map = find_style ("/styles/wallstyles", w_style, RP->difficulty);
240 style_map = find_style (styledirname, w_style, -1);
241 if (!style_map) 218 if (!style_map)
242 return; 219 return;
243 220
244 /* fill up the map with the given floor style */ 221 maptile *mining_map = m_style && *m_style
222 ? find_style ("/styles/miningstyles", m_style, RP->difficulty)
223 : 0;
224
245 if ((the_wall = style_map->pick_random_object (rmg_rndm))) 225 if ((the_wall = style_map->pick_random_object (rmg_rndm)))
246 { 226 {
247 int i, j; 227 int i, j;
248 char *cp; 228 char *cp;
249 int joinedwalls = 0; 229 int joinedwalls = 0;
262 if (layout[i][j] == '#') 242 if (layout[i][j] == '#')
263 { 243 {
264 if (joinedwalls) 244 if (joinedwalls)
265 thiswall = pick_joined_wall (the_wall, layout, i, j, RP); 245 thiswall = pick_joined_wall (the_wall, layout, i, j, RP);
266 else 246 else
267 thiswall = arch_to_object (the_wall->arch); 247 thiswall = the_wall->arch->instance ();
268 248
269 thiswall->x = i;
270 thiswall->y = j;
271 thiswall->move_block = MOVE_ALL; 249 thiswall->move_block = MOVE_ALL;
272 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);
273 } 255 }
274 } 256 }
275 } 257 }
276} 258}
277 259
325 RP->wall_name[l] = 0; 307 RP->wall_name[l] = 0;
326 break; 308 break;
327 } 309 }
328 } 310 }
329 311
330 surround_index = surround_flag4 (the_map, i, j, RP); 312 surround_index = surround_flag4 (the_map, i, j);
331 /* 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,
332 * eg, wall_suffix[surround_index] 314 * eg, wall_suffix[surround_index]
333 */ 315 */
334 switch (surround_index) 316 switch (surround_index)
335 { 317 {
385 367
386 wall_arch = archetype::find (RP->wall_name); 368 wall_arch = archetype::find (RP->wall_name);
387 369
388 if (!wall_arch) 370 if (!wall_arch)
389 { 371 {
390 new_wall = arch_to_object (wall_arch); 372 new_wall = wall_arch->instance ();
391 new_wall->x = i; 373 new_wall->x = i;
392 new_wall->y = j; 374 new_wall->y = j;
393 375
394 if (the_wall && the_wall->map) 376 if (the_wall && the_wall->map)
395 the_wall->destroy (); 377 the_wall->destroy ();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines