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.3 by root, Sun Sep 3 00:18:42 2006 UTC vs.
Revision 1.4 by root, Sun Sep 10 16:06:37 2006 UTC

1
1/* 2/*
2 * static char *rcsid_wall_c = 3 * static char *rcsid_wall_c =
3 * "$Id: wall.C,v 1.3 2006/09/03 00:18:42 root Exp $"; 4 * "$Id: wall.C,v 1.4 2006/09/10 16:06:37 root Exp $";
4 */ 5 */
5 6
6/* 7/*
7 CrossFire, A Multiplayer game for X-windows 8 CrossFire, A Multiplayer game for X-windows
8 9
34 35
35 36
36/* given a layout and a coordinate, tell me which squares up/down/right/left 37/* given a layout and a coordinate, tell me which squares up/down/right/left
37 are occupied. */ 38 are occupied. */
38 39
40int
39int surround_flag(char **layout,int i,int j,RMParms *RP){ 41surround_flag (char **layout, int i, int j, RMParms * RP)
42{
40 /* 1 = wall to left, 43 /* 1 = wall to left,
41 2 = wall to right, 44 2 = wall to right,
42 4 = wall above 45 4 = wall above
43 8 = wall below */ 46 8 = wall below */
47 int surround_index = 0;
48
49 if ((i > 0) && layout[i - 1][j] != 0)
44 int surround_index = 0; 50 surround_index |= 1;
45 if((i > 0) && layout[i-1][j]!=0) surround_index |=1;
46 if((i < RP->Xsize-1) && layout[i+1][j]!=0) surround_index |=2; 51 if ((i < RP->Xsize - 1) && layout[i + 1][j] != 0)
47 if((j > 0) && layout[i][j-1]!=0) surround_index |=4; 52 surround_index |= 2;
53 if ((j > 0) && layout[i][j - 1] != 0)
54 surround_index |= 4;
48 if((j < RP->Ysize-1) && layout[i][j+1]!=0) surround_index |=8; 55 if ((j < RP->Ysize - 1) && layout[i][j + 1] != 0)
56 surround_index |= 8;
49 return surround_index; 57 return surround_index;
50} 58}
51 59
52 60
53/* like surround_flag, but only walls count. 61/* like surround_flag, but only walls count.
54 */ 62 */
55 63
64int
56int surround_flag2(char **layout,int i,int j,RMParms *RP){ 65surround_flag2 (char **layout, int i, int j, RMParms * RP)
66{
57 /* 1 = wall to left, 67 /* 1 = wall to left,
58 2 = wall to right, 68 2 = wall to right,
59 4 = wall above 69 4 = wall above
60 8 = wall below */ 70 8 = wall below */
71 int surround_index = 0;
72
73 if ((i > 0) && layout[i - 1][j] == '#')
61 int surround_index = 0; 74 surround_index |= 1;
62 if((i > 0) && layout[i-1][j]=='#') surround_index |=1;
63 if((i < RP->Xsize-1) && layout[i+1][j]=='#') surround_index |=2; 75 if ((i < RP->Xsize - 1) && layout[i + 1][j] == '#')
64 if((j > 0) && layout[i][j-1]=='#') surround_index |=4; 76 surround_index |= 2;
77 if ((j > 0) && layout[i][j - 1] == '#')
78 surround_index |= 4;
65 if((j < RP->Ysize-1) && layout[i][j+1]=='#') surround_index |=8; 79 if ((j < RP->Ysize - 1) && layout[i][j + 1] == '#')
80 surround_index |= 8;
66 return surround_index; 81 return surround_index;
67} 82}
68 83
69 84
70/* like surround_flag, except it checks a map, not a layout. 85/* like surround_flag, except it checks a map, not a layout.
71 * Since this is part of the random map code, presumption 86 * Since this is part of the random map code, presumption
72 * is that this is not a tiled map. 87 * is that this is not a tiled map.
73 * What is considered blocking and not is somewhat hard coded. 88 * What is considered blocking and not is somewhat hard coded.
74 */ 89 */
90int
75int surround_flag3(mapstruct *map,sint16 i,sint16 j,RMParms *RP){ 91surround_flag3 (mapstruct *map, sint16 i, sint16 j, RMParms * RP)
92{
76 /* 93 /*
77 * 1 = blocked to left, 94 * 1 = blocked to left,
78 * 2 = blocked to right, 95 * 2 = blocked to right,
79 * 4 = blocked above 96 * 4 = blocked above
80 * 8 = blocked below 97 * 8 = blocked below
81 */ 98 */
82 99
83 int surround_index = 0; 100 int surround_index = 0;
84 101
85 if((i > 0) && (GET_MAP_MOVE_BLOCK(map, i-1,j) & ~MOVE_BLOCK_DEFAULT)) 102 if ((i > 0) && (GET_MAP_MOVE_BLOCK (map, i - 1, j) & ~MOVE_BLOCK_DEFAULT))
86 surround_index |=1; 103 surround_index |= 1;
87 if((i < RP->Xsize-1) && (GET_MAP_MOVE_BLOCK(map, i+1,j) & ~MOVE_BLOCK_DEFAULT)) 104 if ((i < RP->Xsize - 1) && (GET_MAP_MOVE_BLOCK (map, i + 1, j) & ~MOVE_BLOCK_DEFAULT))
88 surround_index |=2; 105 surround_index |= 2;
89 if((j > 0) && (GET_MAP_MOVE_BLOCK(map, i,j-1) & ~MOVE_BLOCK_DEFAULT)) 106 if ((j > 0) && (GET_MAP_MOVE_BLOCK (map, i, j - 1) & ~MOVE_BLOCK_DEFAULT))
90 surround_index |=4; 107 surround_index |= 4;
91 if((j < RP->Ysize-1) && (GET_MAP_MOVE_BLOCK(map,i,j+1) & ~MOVE_BLOCK_DEFAULT)) 108 if ((j < RP->Ysize - 1) && (GET_MAP_MOVE_BLOCK (map, i, j + 1) & ~MOVE_BLOCK_DEFAULT))
92 surround_index |=8; 109 surround_index |= 8;
93 110
94 return surround_index; 111 return surround_index;
95} 112}
96 113
97/* like surround_flag2, except it checks a map, not a layout. */ 114/* like surround_flag2, except it checks a map, not a layout. */
98 115
116int
99int surround_flag4(mapstruct *map,int i,int j,RMParms *RP){ 117surround_flag4 (mapstruct *map, int i, int j, RMParms * RP)
118{
100 /* 1 = blocked to left, 119 /* 1 = blocked to left,
101 2 = blocked to right, 120 2 = blocked to right,
102 4 = blocked above 121 4 = blocked above
103 8 = blocked below */ 122 8 = blocked below */
123 int surround_index = 0;
124
125 if ((i > 0) && wall_blocked (map, i - 1, j))
104 int surround_index = 0; 126 surround_index |= 1;
105
106 if((i > 0) && wall_blocked(map,i-1,j)) surround_index |=1;
107 if((i < RP->Xsize-1) && wall_blocked(map,i+1,j)) surround_index |=2; 127 if ((i < RP->Xsize - 1) && wall_blocked (map, i + 1, j))
128 surround_index |= 2;
108 if((j > 0) && wall_blocked(map,i,j-1)) surround_index |=4; 129 if ((j > 0) && wall_blocked (map, i, j - 1))
130 surround_index |= 4;
109 if((j < RP->Ysize-1) && wall_blocked(map,i,j+1)) surround_index |=8; 131 if ((j < RP->Ysize - 1) && wall_blocked (map, i, j + 1))
132 surround_index |= 8;
110 133
111 return surround_index; 134 return surround_index;
112} 135}
113 136
114/* takes a map and a layout, and puts walls in the map (picked from 137/* takes a map and a layout, and puts walls in the map (picked from
115 w_style) at '#' marks. */ 138 w_style) at '#' marks. */
116 139
140void
117void make_map_walls(mapstruct *map,char **layout, char *w_style,RMParms *RP) { 141make_map_walls (mapstruct *map, char **layout, char *w_style, RMParms * RP)
142{
118 char styledirname[256]; 143 char styledirname[256];
119 char stylefilepath[256]; 144 char stylefilepath[256];
120 mapstruct *style_map=0; 145 mapstruct *style_map = 0;
121 object *the_wall; 146 object *the_wall;
122 147
123 /* get the style map */ 148 /* get the style map */
124 if(!strcmp(w_style,"none")) return; 149 if (!strcmp (w_style, "none"))
150 return;
125 sprintf(styledirname,"%s","/styles/wallstyles"); 151 sprintf (styledirname, "%s", "/styles/wallstyles");
126 sprintf(stylefilepath,"%s/%s",styledirname,w_style); 152 sprintf (stylefilepath, "%s/%s", styledirname, w_style);
127 style_map = find_style(styledirname,w_style,-1); 153 style_map = find_style (styledirname, w_style, -1);
128 if(style_map == 0) return; 154 if (style_map == 0)
155 return;
129 156
130 /* fill up the map with the given floor style */ 157 /* fill up the map with the given floor style */
131 if((the_wall=pick_random_object(style_map))!=NULL) { 158 if ((the_wall = pick_random_object (style_map)) != NULL)
159 {
132 int i,j; 160 int i, j;
133 char *cp; 161 char *cp;
134 int joinedwalls=0; 162 int joinedwalls = 0;
135 object *thiswall; 163 object *thiswall;
136 164
137 sprintf(RP->wall_name,"%s", &the_wall->arch->name); 165 sprintf (RP->wall_name, "%s", &the_wall->arch->name);
138 if ((cp=strchr(RP->wall_name,'_'))!=NULL) { 166 if ((cp = strchr (RP->wall_name, '_')) != NULL)
167 {
139 *cp=0; 168 *cp = 0;
140 joinedwalls=1; 169 joinedwalls = 1;
141 } 170 }
142 171
143 for(i=0;i<RP->Xsize;i++) 172 for (i = 0; i < RP->Xsize; i++)
144 for(j=0;j<RP->Ysize;j++) { 173 for (j = 0; j < RP->Ysize; j++)
174 {
145 if(layout[i][j]=='#') { 175 if (layout[i][j] == '#')
176 {
146 if(joinedwalls) 177 if (joinedwalls)
147 thiswall=pick_joined_wall(the_wall,layout,i,j,RP); 178 thiswall = pick_joined_wall (the_wall, layout, i, j, RP);
148 else 179 else
149 thiswall=arch_to_object(the_wall->arch); 180 thiswall = arch_to_object (the_wall->arch);
150 thiswall->x = i; 181 thiswall->x = i;
151 thiswall->y = j; 182 thiswall->y = j;
152 thiswall->move_block = MOVE_ALL; 183 thiswall->move_block = MOVE_ALL;
153 insert_ob_in_map(thiswall,map,thiswall,INS_NO_MERGE | INS_NO_WALK_ON); 184 insert_ob_in_map (thiswall, map, thiswall, INS_NO_MERGE | INS_NO_WALK_ON);
154 } 185 }
155 } 186 }
156 } 187 }
157} 188}
158 189
159 190
160/* picks the right wall type for this square, to make it look nice, 191/* picks the right wall type for this square, to make it look nice,
161 and have everything nicely joined. It uses the layout. */ 192 and have everything nicely joined. It uses the layout. */
162 193
194object *
163object *pick_joined_wall(object *the_wall,char **layout,int i,int j,RMParms *RP) { 195pick_joined_wall (object *the_wall, char **layout, int i, int j, RMParms * RP)
196{
164 /* 1 = wall to left, 197 /* 1 = wall to left,
165 2 = wall to right, 198 2 = wall to right,
166 4 = wall above 199 4 = wall above
167 8 = wall below */ 200 8 = wall below */
168 int surround_index=0; 201 int surround_index = 0;
169 int l; 202 int l;
170 char wall_name[64]; 203 char wall_name[64];
171 archetype *wall_arch=0; 204 archetype *wall_arch = 0;
172 205
173 strcpy(wall_name,the_wall->arch->name); 206 strcpy (wall_name, the_wall->arch->name);
174 207
175 /* conventionally, walls are named like this: 208 /* conventionally, walls are named like this:
176 wallname_wallcode, where wallcode indicates 209 wallname_wallcode, where wallcode indicates
177 a joinedness, and wallname is the wall. 210 a joinedness, and wallname is the wall.
178 this code depends on the convention for 211 this code depends on the convention for
179 finding the right wall. */ 212 finding the right wall. */
180 213
181 /* extract the wall name, which is the text up to the leading _ */ 214 /* extract the wall name, which is the text up to the leading _ */
182 for(l=0;l<64;l++) { 215 for (l = 0; l < 64; l++)
216 {
183 if(wall_name[l]=='_') { 217 if (wall_name[l] == '_')
218 {
184 wall_name[l] = 0; 219 wall_name[l] = 0;
185 break;
186 }
187 }
188
189 surround_index = surround_flag2(layout,i,j,RP);
190
191 switch(surround_index) {
192 case 0:
193 strcat(wall_name,"_0");
194 break; 220 break;
195 case 1: 221 }
222 }
223
224 surround_index = surround_flag2 (layout, i, j, RP);
225
226 switch (surround_index)
227 {
228 case 0:
196 strcat(wall_name,"_1_3"); 229 strcat (wall_name, "_0");
197 break; 230 break;
198 case 2: 231 case 1:
199 strcat(wall_name,"_1_4"); 232 strcat (wall_name, "_1_3");
200 break; 233 break;
201 case 3: 234 case 2:
202 strcat(wall_name,"_2_1_2"); 235 strcat (wall_name, "_1_4");
203 break; 236 break;
204 case 4: 237 case 3:
205 strcat(wall_name,"_1_2"); 238 strcat (wall_name, "_2_1_2");
206 break; 239 break;
207 case 5: 240 case 4:
208 strcat(wall_name,"_2_2_4"); 241 strcat (wall_name, "_1_2");
209 break; 242 break;
210 case 6: 243 case 5:
211 strcat(wall_name,"_2_2_1"); 244 strcat (wall_name, "_2_2_4");
212 break; 245 break;
213 case 7: 246 case 6:
214 strcat(wall_name,"_3_1"); 247 strcat (wall_name, "_2_2_1");
215 break; 248 break;
216 case 8: 249 case 7:
217 strcat(wall_name,"_1_1"); 250 strcat (wall_name, "_3_1");
218 break; 251 break;
219 case 9: 252 case 8:
220 strcat(wall_name,"_2_2_3"); 253 strcat (wall_name, "_1_1");
221 break; 254 break;
222 case 10: 255 case 9:
223 strcat(wall_name,"_2_2_2"); 256 strcat (wall_name, "_2_2_3");
224 break; 257 break;
225 case 11: 258 case 10:
226 strcat(wall_name,"_3_3"); 259 strcat (wall_name, "_2_2_2");
227 break; 260 break;
228 case 12: 261 case 11:
229 strcat(wall_name,"_2_1_1"); 262 strcat (wall_name, "_3_3");
230 break; 263 break;
231 case 13: 264 case 12:
232 strcat(wall_name,"_3_4"); 265 strcat (wall_name, "_2_1_1");
233 break; 266 break;
234 case 14: 267 case 13:
235 strcat(wall_name,"_3_2"); 268 strcat (wall_name, "_3_4");
236 break; 269 break;
237 case 15: 270 case 14:
238 strcat(wall_name,"_4"); 271 strcat (wall_name, "_3_2");
239 break; 272 break;
273 case 15:
274 strcat (wall_name, "_4");
275 break;
240 } 276 }
241 wall_arch = find_archetype(wall_name); 277 wall_arch = find_archetype (wall_name);
278 if (wall_arch)
242 if(wall_arch) return arch_to_object(wall_arch); 279 return arch_to_object (wall_arch);
243 else { 280 else
281 {
244 nroferrors--; 282 nroferrors--;
245 return arch_to_object(the_wall->arch); 283 return arch_to_object (the_wall->arch);
246 } 284 }
247 285
248 286
249} 287}
250 288
251 289
252/* this takes a map, and changes an existing wall to match what's blocked 290/* this takes a map, and changes an existing wall to match what's blocked
253 * around it, counting only doors and walls as blocked. If insert_flag is 291 * around it, counting only doors and walls as blocked. If insert_flag is
254 * 1, it will go ahead and insert the wall into the map. If not, it 292 * 1, it will go ahead and insert the wall into the map. If not, it
255 * will only return the wall which would belong there, and doesn't 293 * will only return the wall which would belong there, and doesn't
256 * remove anything. It depends on the 294 * remove anything. It depends on the
257 * global, previously-set variable, "wall_name" 295 * global, previously-set variable, "wall_name"
258 */ 296 */
259 297
298object *
260object * retrofit_joined_wall(mapstruct *the_map,int i,int j,int insert_flag,RMParms *RP) { 299retrofit_joined_wall (mapstruct *the_map, int i, int j, int insert_flag, RMParms * RP)
300{
261 /* 1 = wall to left, 301 /* 1 = wall to left,
262 * 2 = wall to right, 302 * 2 = wall to right,
263 * 4 = wall above 303 * 4 = wall above
264 * 8 = wall below 304 * 8 = wall below
265 */ 305 */
266 int surround_index=0; 306 int surround_index = 0;
267 int l; 307 int l;
268 object *the_wall=0; 308 object *the_wall = 0;
269 object *new_wall=0; 309 object *new_wall = 0;
270 archetype * wall_arch=0; 310 archetype *wall_arch = 0;
271 311
272 /* first find the wall */ 312 /* first find the wall */
273 for(the_wall = get_map_ob(the_map,i,j);the_wall!=NULL;the_wall=the_wall->above) 313 for (the_wall = get_map_ob (the_map, i, j); the_wall != NULL; the_wall = the_wall->above)
274 if ((the_wall->move_type & MOVE_WALK) && the_wall->type!=EXIT && the_wall->type!=TELEPORTER) 314 if ((the_wall->move_type & MOVE_WALK) && the_wall->type != EXIT && the_wall->type != TELEPORTER)
275 break; 315 break;
276 316
277 317
278 /* if what we found is a door, don't remove it, set the_wall to NULL to 318 /* if what we found is a door, don't remove it, set the_wall to NULL to
279 * signal that later. 319 * signal that later.
280 */ 320 */
281 if(the_wall && (the_wall->type==DOOR || the_wall->type==LOCKED_DOOR) ) { 321 if (the_wall && (the_wall->type == DOOR || the_wall->type == LOCKED_DOOR))
322 {
282 the_wall=NULL; 323 the_wall = NULL;
283 /* if we're not supposed to insert a new wall where there wasn't one, 324 /* if we're not supposed to insert a new wall where there wasn't one,
284 * we've gotta leave. 325 * we've gotta leave.
285 */ 326 */
286 if(insert_flag==0) return 0; 327 if (insert_flag == 0)
328 return 0;
287 } 329 }
288 else if(the_wall==NULL) return NULL; 330 else if (the_wall == NULL)
331 return NULL;
289 332
290 /* canonicalize the wall name */ 333 /* canonicalize the wall name */
291 for(l=0;l<64;l++) { 334 for (l = 0; l < 64; l++)
335 {
292 if(RP->wall_name[l]=='_') { 336 if (RP->wall_name[l] == '_')
337 {
293 RP->wall_name[l] = 0; 338 RP->wall_name[l] = 0;
294 break; 339 break;
295 } 340 }
296 } 341 }
297 342
298 surround_index = surround_flag4(the_map,i,j,RP); 343 surround_index = surround_flag4 (the_map, i, j, RP);
299 /* This would be a lot cleaner to just us a lookup table, 344 /* This would be a lot cleaner to just us a lookup table,
300 * eg, wall_suffix[surround_index] 345 * eg, wall_suffix[surround_index]
301 */ 346 */
302 switch(surround_index) { 347 switch (surround_index)
348 {
303 case 0: 349 case 0:
304 strcat(RP->wall_name,"_0"); 350 strcat (RP->wall_name, "_0");
305 break; 351 break;
306 case 1: 352 case 1:
307 strcat(RP->wall_name,"_1_3"); 353 strcat (RP->wall_name, "_1_3");
308 break; 354 break;
309 case 2: 355 case 2:
310 strcat(RP->wall_name,"_1_4"); 356 strcat (RP->wall_name, "_1_4");
311 break; 357 break;
312 case 3: 358 case 3:
313 strcat(RP->wall_name,"_2_1_2"); 359 strcat (RP->wall_name, "_2_1_2");
314 break; 360 break;
315 case 4: 361 case 4:
316 strcat(RP->wall_name,"_1_2"); 362 strcat (RP->wall_name, "_1_2");
317 break; 363 break;
318 case 5: 364 case 5:
319 strcat(RP->wall_name,"_2_2_4"); 365 strcat (RP->wall_name, "_2_2_4");
320 break; 366 break;
321 case 6: 367 case 6:
322 strcat(RP->wall_name,"_2_2_1"); 368 strcat (RP->wall_name, "_2_2_1");
323 break; 369 break;
324 case 7: 370 case 7:
325 strcat(RP->wall_name,"_3_1"); 371 strcat (RP->wall_name, "_3_1");
326 break; 372 break;
327 case 8: 373 case 8:
328 strcat(RP->wall_name,"_1_1"); 374 strcat (RP->wall_name, "_1_1");
329 break; 375 break;
330 case 9: 376 case 9:
331 strcat(RP->wall_name,"_2_2_3"); 377 strcat (RP->wall_name, "_2_2_3");
332 break; 378 break;
333 case 10: 379 case 10:
334 strcat(RP->wall_name,"_2_2_2"); 380 strcat (RP->wall_name, "_2_2_2");
335 break; 381 break;
336 case 11: 382 case 11:
337 strcat(RP->wall_name,"_3_3"); 383 strcat (RP->wall_name, "_3_3");
338 break; 384 break;
339 case 12: 385 case 12:
340 strcat(RP->wall_name,"_2_1_1"); 386 strcat (RP->wall_name, "_2_1_1");
341 break; 387 break;
342 case 13: 388 case 13:
343 strcat(RP->wall_name,"_3_4"); 389 strcat (RP->wall_name, "_3_4");
344 break; 390 break;
345 case 14: 391 case 14:
346 strcat(RP->wall_name,"_3_2"); 392 strcat (RP->wall_name, "_3_2");
347 break; 393 break;
348 case 15: 394 case 15:
349 strcat(RP->wall_name,"_4"); 395 strcat (RP->wall_name, "_4");
350 break; 396 break;
351 } 397 }
352 wall_arch = find_archetype(RP->wall_name); 398 wall_arch = find_archetype (RP->wall_name);
353 if(wall_arch!=NULL) { 399 if (wall_arch != NULL)
400 {
354 new_wall=arch_to_object(wall_arch); 401 new_wall = arch_to_object (wall_arch);
355 new_wall->x = i; 402 new_wall->x = i;
356 new_wall->y = j; 403 new_wall->y = j;
357 if(the_wall && the_wall->map) { 404 if (the_wall && the_wall->map)
405 {
358 remove_ob(the_wall); 406 remove_ob (the_wall);
359 free_object(the_wall); 407 free_object (the_wall);
360 } 408 }
361 the_wall->move_block = MOVE_ALL; 409 the_wall->move_block = MOVE_ALL;
362 insert_ob_in_map(new_wall,the_map,new_wall,INS_NO_MERGE | INS_NO_WALK_ON); 410 insert_ob_in_map (new_wall, the_map, new_wall, INS_NO_MERGE | INS_NO_WALK_ON);
363 } 411 }
364 else 412 else
365 nroferrors--; /* it's OK not to find an arch. */ 413 nroferrors--; /* it's OK not to find an arch. */
366 return new_wall; 414 return new_wall;
367} 415}
368
369

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines