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.19 by root, Sat Feb 17 23:32:11 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines