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.15 by pippijn, Sat Jan 6 14:42:30 2007 UTC

1
1/* 2/*
2 CrossFire, A Multiplayer game for X-windows 3 CrossFire, A Multiplayer game for X-windows
3 4
5 Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 6 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 7 Copyright (C) 1992 Frank Tore Johansen
6 8
7 This program is free software; you can redistribute it and/or modify 9 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 10 it under the terms of the GNU General Public License as published by
30 32
31/* given a layout and a coordinate, tell me which squares up/down/right/left 33/* given a layout and a coordinate, tell me which squares up/down/right/left
32 are occupied. */ 34 are occupied. */
33 35
34int 36int
35surround_flag (char **layout, int i, int j, RMParms * RP) 37surround_flag (char **layout, int i, int j, random_map_params *RP)
36{ 38{
37 /* 1 = wall to left, 39 /* 1 = wall to left,
38 2 = wall to right, 40 2 = wall to right,
39 4 = wall above 41 4 = wall above
40 8 = wall below */ 42 8 = wall below */
54 56
55/* like surround_flag, but only walls count. 57/* like surround_flag, but only walls count.
56 */ 58 */
57 59
58int 60int
59surround_flag2 (char **layout, int i, int j, RMParms * RP) 61surround_flag2 (char **layout, int i, int j, random_map_params *RP)
60{ 62{
61 /* 1 = wall to left, 63 /* 1 = wall to left,
62 2 = wall to right, 64 2 = wall to right,
63 4 = wall above 65 4 = wall above
64 8 = wall below */ 66 8 = wall below */
80 * Since this is part of the random map code, presumption 82 * Since this is part of the random map code, presumption
81 * is that this is not a tiled map. 83 * is that this is not a tiled map.
82 * What is considered blocking and not is somewhat hard coded. 84 * What is considered blocking and not is somewhat hard coded.
83 */ 85 */
84int 86int
85surround_flag3 (maptile *map, sint16 i, sint16 j, RMParms * RP) 87surround_flag3 (maptile *map, sint16 i, sint16 j, random_map_params *RP)
86{ 88{
87 /* 89 /*
88 * 1 = blocked to left, 90 * 1 = blocked to left,
89 * 2 = blocked to right, 91 * 2 = blocked to right,
90 * 4 = blocked above 92 * 4 = blocked above
106} 108}
107 109
108/* like surround_flag2, except it checks a map, not a layout. */ 110/* like surround_flag2, except it checks a map, not a layout. */
109 111
110int 112int
111surround_flag4 (maptile *map, int i, int j, RMParms * RP) 113surround_flag4 (maptile *map, int i, int j, random_map_params *RP)
112{ 114{
113 /* 1 = blocked to left, 115 /* 1 = blocked to left,
114 2 = blocked to right, 116 2 = blocked to right,
115 4 = blocked above 117 4 = blocked above
116 8 = blocked below */ 118 8 = blocked below */
130 132
131/* takes a map and a layout, and puts walls in the map (picked from 133/* takes a map and a layout, and puts walls in the map (picked from
132 w_style) at '#' marks. */ 134 w_style) at '#' marks. */
133 135
134void 136void
135make_map_walls (maptile *map, char **layout, char *w_style, RMParms * RP) 137make_map_walls (maptile *map, char **layout, char *w_style, random_map_params *RP)
136{ 138{
137 char styledirname[256]; 139 char styledirname[1024];
138 char stylefilepath[256]; 140 char stylefilepath[1024];
139 maptile *style_map = 0; 141 maptile *style_map = 0;
140 object *the_wall; 142 object *the_wall;
141 143
142 /* get the style map */ 144 /* get the style map */
143 if (!strcmp (w_style, "none")) 145 if (!strcmp (w_style, "none"))
184 186
185/* picks the right wall type for this square, to make it look nice, 187/* picks the right wall type for this square, to make it look nice,
186 and have everything nicely joined. It uses the layout. */ 188 and have everything nicely joined. It uses the layout. */
187 189
188object * 190object *
189pick_joined_wall (object *the_wall, char **layout, int i, int j, RMParms * RP) 191pick_joined_wall (object *the_wall, char **layout, int i, int j, random_map_params *RP)
190{ 192{
191 /* 1 = wall to left, 193 /* 1 = wall to left,
192 2 = wall to right, 194 2 = wall to right,
193 4 = wall above 195 4 = wall above
194 8 = wall below */ 196 8 = wall below */
195 int surround_index = 0; 197 int surround_index = 0;
196 int l; 198 int l;
197 char wall_name[64]; 199 char wall_name[1024];
198 archetype *wall_arch = 0; 200 archetype *wall_arch = 0;
199 201
200 strcpy (wall_name, the_wall->arch->name); 202 strcpy (wall_name, the_wall->arch->name);
201 203
202 /* conventionally, walls are named like this: 204 /* conventionally, walls are named like this:
217 219
218 surround_index = surround_flag2 (layout, i, j, RP); 220 surround_index = surround_flag2 (layout, i, j, RP);
219 221
220 switch (surround_index) 222 switch (surround_index)
221 { 223 {
222 case 0: 224 case 0:
223 strcat (wall_name, "_0"); 225 strcat (wall_name, "_0");
224 break; 226 break;
225 case 1: 227 case 1:
226 strcat (wall_name, "_1_3"); 228 strcat (wall_name, "_1_3");
227 break; 229 break;
228 case 2: 230 case 2:
229 strcat (wall_name, "_1_4"); 231 strcat (wall_name, "_1_4");
230 break; 232 break;
231 case 3: 233 case 3:
232 strcat (wall_name, "_2_1_2"); 234 strcat (wall_name, "_2_1_2");
233 break; 235 break;
234 case 4: 236 case 4:
235 strcat (wall_name, "_1_2"); 237 strcat (wall_name, "_1_2");
236 break; 238 break;
237 case 5: 239 case 5:
238 strcat (wall_name, "_2_2_4"); 240 strcat (wall_name, "_2_2_4");
239 break; 241 break;
240 case 6: 242 case 6:
241 strcat (wall_name, "_2_2_1"); 243 strcat (wall_name, "_2_2_1");
242 break; 244 break;
243 case 7: 245 case 7:
244 strcat (wall_name, "_3_1"); 246 strcat (wall_name, "_3_1");
245 break; 247 break;
246 case 8: 248 case 8:
247 strcat (wall_name, "_1_1"); 249 strcat (wall_name, "_1_1");
248 break; 250 break;
249 case 9: 251 case 9:
250 strcat (wall_name, "_2_2_3"); 252 strcat (wall_name, "_2_2_3");
251 break; 253 break;
252 case 10: 254 case 10:
253 strcat (wall_name, "_2_2_2"); 255 strcat (wall_name, "_2_2_2");
254 break; 256 break;
255 case 11: 257 case 11:
256 strcat (wall_name, "_3_3"); 258 strcat (wall_name, "_3_3");
257 break; 259 break;
258 case 12: 260 case 12:
259 strcat (wall_name, "_2_1_1"); 261 strcat (wall_name, "_2_1_1");
260 break; 262 break;
261 case 13: 263 case 13:
262 strcat (wall_name, "_3_4"); 264 strcat (wall_name, "_3_4");
263 break; 265 break;
264 case 14: 266 case 14:
265 strcat (wall_name, "_3_2"); 267 strcat (wall_name, "_3_2");
266 break; 268 break;
267 case 15: 269 case 15:
268 strcat (wall_name, "_4"); 270 strcat (wall_name, "_4");
269 break; 271 break;
270 } 272 }
271 wall_arch = archetype::find (wall_name); 273 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 274
280 275 return wall_arch ? arch_to_object (wall_arch) : arch_to_object (the_wall->arch);
281} 276}
282 277
283 278
284/* this takes a map, and changes an existing wall to match what's blocked 279/* 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 280 * around it, counting only doors and walls as blocked. If insert_flag is
288 * remove anything. It depends on the 283 * remove anything. It depends on the
289 * global, previously-set variable, "wall_name" 284 * global, previously-set variable, "wall_name"
290 */ 285 */
291 286
292object * 287object *
293retrofit_joined_wall (maptile *the_map, int i, int j, int insert_flag, RMParms * RP) 288retrofit_joined_wall (maptile *the_map, int i, int j, int insert_flag, random_map_params *RP)
294{ 289{
295 /* 1 = wall to left, 290 /* 1 = wall to left,
296 * 2 = wall to right, 291 * 2 = wall to right,
297 * 4 = wall above 292 * 4 = wall above
298 * 8 = wall below 293 * 8 = wall below
338 /* This would be a lot cleaner to just us a lookup table, 333 /* This would be a lot cleaner to just us a lookup table,
339 * eg, wall_suffix[surround_index] 334 * eg, wall_suffix[surround_index]
340 */ 335 */
341 switch (surround_index) 336 switch (surround_index)
342 { 337 {
343 case 0: 338 case 0:
344 strcat (RP->wall_name, "_0"); 339 strcat (RP->wall_name, "_0");
345 break; 340 break;
346 case 1: 341 case 1:
347 strcat (RP->wall_name, "_1_3"); 342 strcat (RP->wall_name, "_1_3");
348 break; 343 break;
349 case 2: 344 case 2:
350 strcat (RP->wall_name, "_1_4"); 345 strcat (RP->wall_name, "_1_4");
351 break; 346 break;
352 case 3: 347 case 3:
353 strcat (RP->wall_name, "_2_1_2"); 348 strcat (RP->wall_name, "_2_1_2");
354 break; 349 break;
355 case 4: 350 case 4:
356 strcat (RP->wall_name, "_1_2"); 351 strcat (RP->wall_name, "_1_2");
357 break; 352 break;
358 case 5: 353 case 5:
359 strcat (RP->wall_name, "_2_2_4"); 354 strcat (RP->wall_name, "_2_2_4");
360 break; 355 break;
361 case 6: 356 case 6:
362 strcat (RP->wall_name, "_2_2_1"); 357 strcat (RP->wall_name, "_2_2_1");
363 break; 358 break;
364 case 7: 359 case 7:
365 strcat (RP->wall_name, "_3_1"); 360 strcat (RP->wall_name, "_3_1");
366 break; 361 break;
367 case 8: 362 case 8:
368 strcat (RP->wall_name, "_1_1"); 363 strcat (RP->wall_name, "_1_1");
369 break; 364 break;
370 case 9: 365 case 9:
371 strcat (RP->wall_name, "_2_2_3"); 366 strcat (RP->wall_name, "_2_2_3");
372 break; 367 break;
373 case 10: 368 case 10:
374 strcat (RP->wall_name, "_2_2_2"); 369 strcat (RP->wall_name, "_2_2_2");
375 break; 370 break;
376 case 11: 371 case 11:
377 strcat (RP->wall_name, "_3_3"); 372 strcat (RP->wall_name, "_3_3");
378 break; 373 break;
379 case 12: 374 case 12:
380 strcat (RP->wall_name, "_2_1_1"); 375 strcat (RP->wall_name, "_2_1_1");
381 break; 376 break;
382 case 13: 377 case 13:
383 strcat (RP->wall_name, "_3_4"); 378 strcat (RP->wall_name, "_3_4");
384 break; 379 break;
385 case 14: 380 case 14:
386 strcat (RP->wall_name, "_3_2"); 381 strcat (RP->wall_name, "_3_2");
387 break; 382 break;
388 case 15: 383 case 15:
389 strcat (RP->wall_name, "_4"); 384 strcat (RP->wall_name, "_4");
390 break; 385 break;
391 } 386 }
387
392 wall_arch = archetype::find (RP->wall_name); 388 wall_arch = archetype::find (RP->wall_name);
389
393 if (wall_arch != NULL) 390 if (!wall_arch)
394 { 391 {
395 new_wall = arch_to_object (wall_arch); 392 new_wall = arch_to_object (wall_arch);
396 new_wall->x = i; 393 new_wall->x = i;
397 new_wall->y = j; 394 new_wall->y = j;
395
398 if (the_wall && the_wall->map) 396 if (the_wall && the_wall->map)
399 { 397 {
400 the_wall->remove (); 398 the_wall->remove ();
401 the_wall->destroy (); 399 the_wall->destroy ();
402 } 400 }
401
403 the_wall->move_block = MOVE_ALL; 402 the_wall->move_block = MOVE_ALL;
404 insert_ob_in_map (new_wall, the_map, new_wall, INS_NO_MERGE | INS_NO_WALK_ON); 403 insert_ob_in_map (new_wall, the_map, new_wall, INS_NO_MERGE | INS_NO_WALK_ON);
405 } 404 }
406 else 405
407 nroferrors--; /* it's OK not to find an arch. */
408 return new_wall; 406 return new_wall;
409} 407}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines