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.5 by root, Thu Sep 14 21:16:12 2006 UTC vs.
Revision 1.19 by root, Sat Feb 17 23:32:11 2007 UTC

1
2/* 1/*
3 * static char *rcsid_wall_c = 2 * CrossFire, A Multiplayer game for X-windows
4 * "$Id: wall.C,v 1.5 2006/09/14 21:16:12 root Exp $"; 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 * The authors can be reached via e-mail at <crossfire@schmorp.de>
5 */ 23 */
6
7/*
8 CrossFire, A Multiplayer game for X-windows
9
10 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26
27 The authors can be reached via e-mail at crossfire-devel@real-time.com
28*/
29 24
30#include <global.h> 25#include <global.h>
31#include <random_map.h> 26#include <random_map.h>
32#include <rproto.h> 27#include <rproto.h>
33 28
36 31
37/* given a layout and a coordinate, tell me which squares up/down/right/left 32/* given a layout and a coordinate, tell me which squares up/down/right/left
38 are occupied. */ 33 are occupied. */
39 34
40int 35int
41surround_flag (char **layout, int i, int j, RMParms * RP) 36surround_flag (char **layout, int i, int j, random_map_params *RP)
42{ 37{
43 /* 1 = wall to left, 38 /* 1 = wall to left,
44 2 = wall to right, 39 2 = wall to right,
45 4 = wall above 40 4 = wall above
46 8 = wall below */ 41 8 = wall below */
60 55
61/* like surround_flag, but only walls count. 56/* like surround_flag, but only walls count.
62 */ 57 */
63 58
64int 59int
65surround_flag2 (char **layout, int i, int j, RMParms * RP) 60surround_flag2 (char **layout, int i, int j, random_map_params *RP)
66{ 61{
67 /* 1 = wall to left, 62 /* 1 = wall to left,
68 2 = wall to right, 63 2 = wall to right,
69 4 = wall above 64 4 = wall above
70 8 = wall below */ 65 8 = wall below */
86 * Since this is part of the random map code, presumption 81 * Since this is part of the random map code, presumption
87 * is that this is not a tiled map. 82 * is that this is not a tiled map.
88 * What is considered blocking and not is somewhat hard coded. 83 * What is considered blocking and not is somewhat hard coded.
89 */ 84 */
90int 85int
91surround_flag3 (mapstruct *map, sint16 i, sint16 j, RMParms * RP) 86surround_flag3 (maptile *map, sint16 i, sint16 j, random_map_params *RP)
92{ 87{
93 /* 88 /*
94 * 1 = blocked to left, 89 * 1 = blocked to left,
95 * 2 = blocked to right, 90 * 2 = blocked to right,
96 * 4 = blocked above 91 * 4 = blocked above
112} 107}
113 108
114/* like surround_flag2, except it checks a map, not a layout. */ 109/* like surround_flag2, except it checks a map, not a layout. */
115 110
116int 111int
117surround_flag4 (mapstruct *map, int i, int j, RMParms * RP) 112surround_flag4 (maptile *map, int i, int j, random_map_params *RP)
118{ 113{
119 /* 1 = blocked to left, 114 /* 1 = blocked to left,
120 2 = blocked to right, 115 2 = blocked to right,
121 4 = blocked above 116 4 = blocked above
122 8 = blocked below */ 117 8 = blocked below */
136 131
137/* takes a map and a layout, and puts walls in the map (picked from 132/* takes a map and a layout, and puts walls in the map (picked from
138 w_style) at '#' marks. */ 133 w_style) at '#' marks. */
139 134
140void 135void
141make_map_walls (mapstruct *map, char **layout, char *w_style, RMParms * RP) 136make_map_walls (maptile *map, char **layout, char *w_style, random_map_params *RP)
142{ 137{
143 char styledirname[256]; 138 char styledirname[1024];
144 char stylefilepath[256]; 139 char stylefilepath[1024];
145 mapstruct *style_map = 0; 140 maptile *style_map = 0;
146 object *the_wall; 141 object *the_wall;
147 142
148 /* get the style map */ 143 /* get the style map */
149 if (!strcmp (w_style, "none")) 144 if (!strcmp (w_style, "none"))
150 return; 145 return;
151 sprintf (styledirname, "%s", "/styles/wallstyles"); 146 sprintf (styledirname, "%s", "/styles/wallstyles");
152 sprintf (stylefilepath, "%s/%s", styledirname, w_style); 147 sprintf (stylefilepath, "%s/%s", styledirname, w_style);
153 style_map = find_style (styledirname, w_style, -1); 148 style_map = find_style (styledirname, w_style, -1);
154 if (style_map == 0) 149 if (!style_map)
155 return; 150 return;
156 151
157 /* fill up the map with the given floor style */ 152 /* fill up the map with the given floor style */
158 if ((the_wall = pick_random_object (style_map)) != NULL) 153 if ((the_wall = style_map->pick_random_object ()))
159 { 154 {
160 int i, j; 155 int i, j;
161 char *cp; 156 char *cp;
162 int joinedwalls = 0; 157 int joinedwalls = 0;
163 object *thiswall; 158 object *thiswall;
190 185
191/* picks the right wall type for this square, to make it look nice, 186/* picks the right wall type for this square, to make it look nice,
192 and have everything nicely joined. It uses the layout. */ 187 and have everything nicely joined. It uses the layout. */
193 188
194object * 189object *
195pick_joined_wall (object *the_wall, char **layout, int i, int j, RMParms * RP) 190pick_joined_wall (object *the_wall, char **layout, int i, int j, random_map_params *RP)
196{ 191{
197 /* 1 = wall to left, 192 /* 1 = wall to left,
198 2 = wall to right, 193 2 = wall to right,
199 4 = wall above 194 4 = wall above
200 8 = wall below */ 195 8 = wall below */
201 int surround_index = 0; 196 int surround_index = 0;
202 int l; 197 int l;
203 char wall_name[64]; 198 char wall_name[1024];
204 archetype *wall_arch = 0; 199 archetype *wall_arch = 0;
205 200
206 strcpy (wall_name, the_wall->arch->name); 201 assign (wall_name, the_wall->arch->name);
207 202
208 /* conventionally, walls are named like this: 203 /* conventionally, walls are named like this:
209 wallname_wallcode, where wallcode indicates 204 wallname_wallcode, where wallcode indicates
210 a joinedness, and wallname is the wall. 205 a joinedness, and wallname is the wall.
211 this code depends on the convention for 206 this code depends on the convention for
223 218
224 surround_index = surround_flag2 (layout, i, j, RP); 219 surround_index = surround_flag2 (layout, i, j, RP);
225 220
226 switch (surround_index) 221 switch (surround_index)
227 { 222 {
228 case 0: 223 case 0:
229 strcat (wall_name, "_0"); 224 strcat (wall_name, "_0");
230 break; 225 break;
231 case 1: 226 case 1:
232 strcat (wall_name, "_1_3"); 227 strcat (wall_name, "_1_3");
233 break; 228 break;
234 case 2: 229 case 2:
235 strcat (wall_name, "_1_4"); 230 strcat (wall_name, "_1_4");
236 break; 231 break;
237 case 3: 232 case 3:
238 strcat (wall_name, "_2_1_2"); 233 strcat (wall_name, "_2_1_2");
239 break; 234 break;
240 case 4: 235 case 4:
241 strcat (wall_name, "_1_2"); 236 strcat (wall_name, "_1_2");
242 break; 237 break;
243 case 5: 238 case 5:
244 strcat (wall_name, "_2_2_4"); 239 strcat (wall_name, "_2_2_4");
245 break; 240 break;
246 case 6: 241 case 6:
247 strcat (wall_name, "_2_2_1"); 242 strcat (wall_name, "_2_2_1");
248 break; 243 break;
249 case 7: 244 case 7:
250 strcat (wall_name, "_3_1"); 245 strcat (wall_name, "_3_1");
251 break; 246 break;
252 case 8: 247 case 8:
253 strcat (wall_name, "_1_1"); 248 strcat (wall_name, "_1_1");
254 break; 249 break;
255 case 9: 250 case 9:
256 strcat (wall_name, "_2_2_3"); 251 strcat (wall_name, "_2_2_3");
257 break; 252 break;
258 case 10: 253 case 10:
259 strcat (wall_name, "_2_2_2"); 254 strcat (wall_name, "_2_2_2");
260 break; 255 break;
261 case 11: 256 case 11:
262 strcat (wall_name, "_3_3"); 257 strcat (wall_name, "_3_3");
263 break; 258 break;
264 case 12: 259 case 12:
265 strcat (wall_name, "_2_1_1"); 260 strcat (wall_name, "_2_1_1");
266 break; 261 break;
267 case 13: 262 case 13:
268 strcat (wall_name, "_3_4"); 263 strcat (wall_name, "_3_4");
269 break; 264 break;
270 case 14: 265 case 14:
271 strcat (wall_name, "_3_2"); 266 strcat (wall_name, "_3_2");
272 break; 267 break;
273 case 15: 268 case 15:
274 strcat (wall_name, "_4"); 269 strcat (wall_name, "_4");
275 break; 270 break;
276 } 271 }
277 wall_arch = archetype::find (wall_name); 272 wall_arch = archetype::find (wall_name);
278 if (wall_arch)
279 return arch_to_object (wall_arch);
280 else
281 {
282 nroferrors--;
283 return arch_to_object (the_wall->arch);
284 }
285 273
286 274 return wall_arch ? arch_to_object (wall_arch) : arch_to_object (the_wall->arch);
287} 275}
288 276
289 277
290/* this takes a map, and changes an existing wall to match what's blocked 278/* this takes a map, and changes an existing wall to match what's blocked
291 * around it, counting only doors and walls as blocked. If insert_flag is 279 * around it, counting only doors and walls as blocked. If insert_flag is
294 * remove anything. It depends on the 282 * remove anything. It depends on the
295 * global, previously-set variable, "wall_name" 283 * global, previously-set variable, "wall_name"
296 */ 284 */
297 285
298object * 286object *
299retrofit_joined_wall (mapstruct *the_map, int i, int j, int insert_flag, RMParms * RP) 287retrofit_joined_wall (maptile *the_map, int i, int j, int insert_flag, random_map_params *RP)
300{ 288{
301 /* 1 = wall to left, 289 /* 1 = wall to left,
302 * 2 = wall to right, 290 * 2 = wall to right,
303 * 4 = wall above 291 * 4 = wall above
304 * 8 = wall below 292 * 8 = wall below
308 object *the_wall = 0; 296 object *the_wall = 0;
309 object *new_wall = 0; 297 object *new_wall = 0;
310 archetype *wall_arch = 0; 298 archetype *wall_arch = 0;
311 299
312 /* first find the wall */ 300 /* first find the wall */
313 for (the_wall = get_map_ob (the_map, i, j); the_wall != NULL; the_wall = the_wall->above) 301 for (the_wall = GET_MAP_OB (the_map, i, j); the_wall != NULL; the_wall = the_wall->above)
314 if ((the_wall->move_type & MOVE_WALK) && the_wall->type != EXIT && the_wall->type != TELEPORTER) 302 if ((the_wall->move_type & MOVE_WALK) && the_wall->type != EXIT && the_wall->type != TELEPORTER)
315 break; 303 break;
316 304
317 305
318 /* if what we found is a door, don't remove it, set the_wall to NULL to 306 /* if what we found is a door, don't remove it, set the_wall to NULL to
344 /* This would be a lot cleaner to just us a lookup table, 332 /* This would be a lot cleaner to just us a lookup table,
345 * eg, wall_suffix[surround_index] 333 * eg, wall_suffix[surround_index]
346 */ 334 */
347 switch (surround_index) 335 switch (surround_index)
348 { 336 {
349 case 0: 337 case 0:
350 strcat (RP->wall_name, "_0"); 338 strcat (RP->wall_name, "_0");
351 break; 339 break;
352 case 1: 340 case 1:
353 strcat (RP->wall_name, "_1_3"); 341 strcat (RP->wall_name, "_1_3");
354 break; 342 break;
355 case 2: 343 case 2:
356 strcat (RP->wall_name, "_1_4"); 344 strcat (RP->wall_name, "_1_4");
357 break; 345 break;
358 case 3: 346 case 3:
359 strcat (RP->wall_name, "_2_1_2"); 347 strcat (RP->wall_name, "_2_1_2");
360 break; 348 break;
361 case 4: 349 case 4:
362 strcat (RP->wall_name, "_1_2"); 350 strcat (RP->wall_name, "_1_2");
363 break; 351 break;
364 case 5: 352 case 5:
365 strcat (RP->wall_name, "_2_2_4"); 353 strcat (RP->wall_name, "_2_2_4");
366 break; 354 break;
367 case 6: 355 case 6:
368 strcat (RP->wall_name, "_2_2_1"); 356 strcat (RP->wall_name, "_2_2_1");
369 break; 357 break;
370 case 7: 358 case 7:
371 strcat (RP->wall_name, "_3_1"); 359 strcat (RP->wall_name, "_3_1");
372 break; 360 break;
373 case 8: 361 case 8:
374 strcat (RP->wall_name, "_1_1"); 362 strcat (RP->wall_name, "_1_1");
375 break; 363 break;
376 case 9: 364 case 9:
377 strcat (RP->wall_name, "_2_2_3"); 365 strcat (RP->wall_name, "_2_2_3");
378 break; 366 break;
379 case 10: 367 case 10:
380 strcat (RP->wall_name, "_2_2_2"); 368 strcat (RP->wall_name, "_2_2_2");
381 break; 369 break;
382 case 11: 370 case 11:
383 strcat (RP->wall_name, "_3_3"); 371 strcat (RP->wall_name, "_3_3");
384 break; 372 break;
385 case 12: 373 case 12:
386 strcat (RP->wall_name, "_2_1_1"); 374 strcat (RP->wall_name, "_2_1_1");
387 break; 375 break;
388 case 13: 376 case 13:
389 strcat (RP->wall_name, "_3_4"); 377 strcat (RP->wall_name, "_3_4");
390 break; 378 break;
391 case 14: 379 case 14:
392 strcat (RP->wall_name, "_3_2"); 380 strcat (RP->wall_name, "_3_2");
393 break; 381 break;
394 case 15: 382 case 15:
395 strcat (RP->wall_name, "_4"); 383 strcat (RP->wall_name, "_4");
396 break; 384 break;
397 } 385 }
386
398 wall_arch = archetype::find (RP->wall_name); 387 wall_arch = archetype::find (RP->wall_name);
388
399 if (wall_arch != NULL) 389 if (!wall_arch)
400 { 390 {
401 new_wall = arch_to_object (wall_arch); 391 new_wall = arch_to_object (wall_arch);
402 new_wall->x = i; 392 new_wall->x = i;
403 new_wall->y = j; 393 new_wall->y = j;
394
404 if (the_wall && the_wall->map) 395 if (the_wall && the_wall->map)
405 { 396 {
406 remove_ob (the_wall); 397 the_wall->remove ();
407 free_object (the_wall); 398 the_wall->destroy ();
408 } 399 }
400
409 the_wall->move_block = MOVE_ALL; 401 the_wall->move_block = MOVE_ALL;
410 insert_ob_in_map (new_wall, the_map, new_wall, INS_NO_MERGE | INS_NO_WALK_ON); 402 insert_ob_in_map (new_wall, the_map, new_wall, INS_NO_MERGE | INS_NO_WALK_ON);
411 } 403 }
412 else 404
413 nroferrors--; /* it's OK not to find an arch. */
414 return new_wall; 405 return new_wall;
415} 406}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines