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.37 by root, Fri Jul 2 03:40:14 2010 UTC vs.
Revision 1.38 by root, Fri Jul 2 15:03:57 2010 UTC

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/* 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
32 are occupied. */ 32 are occupied. */
33int 33int
34surround_flag (const Layout &layout, int i, int j) 34surround_flag (const layout &maze, 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) surround_index |= 1; 42 if (i > 0 && maze[i - 1][j] != 0) surround_index |= 1;
43 if (i < layout.w - 1 && layout[i + 1][j] != 0) surround_index |= 2; 43 if (i < maze.w - 1 && maze[i + 1][j] != 0) surround_index |= 2;
44 if (j > 0 && layout[i][j - 1] != 0) surround_index |= 4; 44 if (j > 0 && maze[i][j - 1] != 0) surround_index |= 4;
45 if (j < layout.h - 1 && layout[i][j + 1] != 0) surround_index |= 8; 45 if (j < maze.h - 1 && maze[i][j + 1] != 0) surround_index |= 8;
46 46
47 return surround_index; 47 return surround_index;
48} 48}
49 49
50/* like surround_flag, but only walls count. */ 50/* like surround_flag, but only walls count. */
51int 51int
52surround_flag2 (const Layout &layout, int i, int j) 52surround_flag2 (const layout &maze, int i, int j)
53{ 53{
54 /* 1 = wall to left, 54 /* 1 = wall to left,
55 2 = wall to right, 55 2 = wall to right,
56 4 = wall above 56 4 = wall above
57 8 = wall below */ 57 8 = wall below */
58 int surround_index = 0; 58 int surround_index = 0;
59 59
60 if (i > 0 && layout[i - 1][j] == '#') surround_index |= 1; 60 if (i > 0 && maze[i - 1][j] == '#') surround_index |= 1;
61 if (i < layout.w - 1 && layout[i + 1][j] == '#') surround_index |= 2; 61 if (i < maze.w - 1 && maze[i + 1][j] == '#') surround_index |= 2;
62 if (j > 0 && layout[i][j - 1] == '#') surround_index |= 4; 62 if (j > 0 && maze[i][j - 1] == '#') surround_index |= 4;
63 if (j < layout.h - 1 && layout[i][j + 1] == '#') surround_index |= 8; 63 if (j < maze.h - 1 && maze[i][j + 1] == '#') surround_index |= 8;
64 64
65 return surround_index; 65 return surround_index;
66} 66}
67 67
68/* like surround_flag, except it checks a map, not a layout. 68/* like surround_flag, except it checks a map, not a maze.
69 * Since this is part of the random map code, presumption 69 * Since this is part of the random map code, presumption
70 * is that this is not a tiled map. 70 * is that this is not a tiled map.
71 * What is considered blocking and not is somewhat hard coded. 71 * What is considered blocking and not is somewhat hard coded.
72 */ 72 */
73int 73int
93 if (j < map->height - 1 && (GET_MAP_MOVE_BLOCK (map, i, j + 1) & MOVE_WALK)) surround_index |= 8; 93 if (j < map->height - 1 && (GET_MAP_MOVE_BLOCK (map, i, j + 1) & MOVE_WALK)) surround_index |= 8;
94 94
95 return surround_index; 95 return surround_index;
96} 96}
97 97
98/* like surround_flag2, except it checks a map, not a layout. */ 98/* like surround_flag2, except it checks a map, not a maze. */
99static int 99static int
100surround_flag4 (maptile *map, int i, int j) 100surround_flag4 (maptile *map, int i, int j)
101{ 101{
102 /* 1 = blocked to left, 102 /* 1 = blocked to left,
103 2 = blocked to right, 103 2 = blocked to right,
112 112
113 return surround_index; 113 return surround_index;
114} 114}
115 115
116/* 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,
117 and have everything nicely joined. It uses the layout. */ 117 and have everything nicely joined. It uses the maze. */
118static object * 118static object *
119pick_joined_wall (object *the_wall, const Layout &layout, int i, int j, random_map_params *RP) 119pick_joined_wall (object *the_wall, const layout &maze, int i, int j, random_map_params *RP)
120{ 120{
121 /* 1 = wall to left, 121 /* 1 = wall to left,
122 2 = wall to right, 122 2 = wall to right,
123 4 = wall above 123 4 = wall above
124 8 = wall below */ 124 8 = wall below */
143 wall_name[l] = 0; 143 wall_name[l] = 0;
144 break; 144 break;
145 } 145 }
146 } 146 }
147 147
148 surround_index = surround_flag2 (layout, i, j); 148 surround_index = surround_flag2 (maze, i, j);
149 149
150 switch (surround_index) 150 switch (surround_index)
151 { 151 {
152 case 0: 152 case 0:
153 strcat (wall_name, "_0"); 153 strcat (wall_name, "_0");
201 wall_arch = archetype::find (wall_name); 201 wall_arch = archetype::find (wall_name);
202 202
203 return wall_arch ? wall_arch->instance () : the_wall->arch->instance (); 203 return wall_arch ? wall_arch->instance () : the_wall->arch->instance ();
204} 204}
205 205
206/* 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
207 w_style) at '#' marks. */ 207 w_style) at '#' marks. */
208void 208void
209make_map_walls (maptile *map, Layout &layout, const char *w_style, const char *m_style, random_map_params *RP) 209make_map_walls (maptile *map, layout &maze, const char *w_style, const char *m_style, random_map_params *RP)
210{ 210{
211 object *the_wall; 211 object *the_wall;
212 212
213 /* get the style map */ 213 /* get the style map */
214 if (!strcmp (w_style, "none")) 214 if (!strcmp (w_style, "none"))
237 } 237 }
238 238
239 for (i = 0; i < RP->Xsize; i++) 239 for (i = 0; i < RP->Xsize; i++)
240 for (j = 0; j < RP->Ysize; j++) 240 for (j = 0; j < RP->Ysize; j++)
241 { 241 {
242 if (layout[i][j] == '#') 242 if (maze[i][j] == '#')
243 { 243 {
244 if (joinedwalls) 244 if (joinedwalls)
245 thiswall = pick_joined_wall (the_wall, layout, i, j, RP); 245 thiswall = pick_joined_wall (the_wall, maze, i, j, RP);
246 else 246 else
247 thiswall = the_wall->arch->instance (); 247 thiswall = the_wall->arch->instance ();
248 248
249 thiswall->move_block = MOVE_ALL; 249 thiswall->move_block = MOVE_ALL;
250 map->insert (thiswall, i, j, thiswall, INS_NO_MERGE | INS_NO_WALK_ON); 250 map->insert (thiswall, i, j, thiswall, INS_NO_MERGE | INS_NO_WALK_ON);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines