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.4 by root, Sun Sep 10 16:06:37 2006 UTC vs.
Revision 1.29 by root, Mon Oct 12 14:00:58 2009 UTC

1
2/* 1/*
3 * static char *rcsid_wall_c = 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
4 * "$Id: wall.C,v 1.4 2006/09/10 16:06:37 root Exp $"; 3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 *
8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * the terms of the Affero GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your
11 * 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 Affero GNU General Public License
19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
21 *
22 * The authors can be reached via e-mail to <support@deliantra.net>
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
34/* Put in the walls and autojoin them. */ 29/* Put in the walls and autojoin them. */
35 30
36
37/* given a layout and a coordinate, tell me which squares up/down/right/left 31/* given a layout and a coordinate, tell me which squares up/down/right/left
38 are occupied. */ 32 are occupied. */
39
40int 33int
41surround_flag (char **layout, int i, int j, RMParms * RP) 34surround_flag (char **layout, int i, int j, random_map_params *RP)
42{ 35{
43 /* 1 = wall to left, 36 /* 1 = wall to left,
44 2 = wall to right, 37 2 = wall to right,
45 4 = wall above 38 4 = wall above
46 8 = wall below */ 39 8 = wall below */
60 53
61/* like surround_flag, but only walls count. 54/* like surround_flag, but only walls count.
62 */ 55 */
63 56
64int 57int
65surround_flag2 (char **layout, int i, int j, RMParms * RP) 58surround_flag2 (char **layout, int i, int j, random_map_params *RP)
66{ 59{
67 /* 1 = wall to left, 60 /* 1 = wall to left,
68 2 = wall to right, 61 2 = wall to right,
69 4 = wall above 62 4 = wall above
70 8 = wall below */ 63 8 = wall below */
86 * Since this is part of the random map code, presumption 79 * Since this is part of the random map code, presumption
87 * is that this is not a tiled map. 80 * is that this is not a tiled map.
88 * What is considered blocking and not is somewhat hard coded. 81 * What is considered blocking and not is somewhat hard coded.
89 */ 82 */
90int 83int
91surround_flag3 (mapstruct *map, sint16 i, sint16 j, RMParms * RP) 84surround_flag3 (maptile *map, sint16 i, sint16 j, random_map_params *RP)
92{ 85{
93 /* 86 /*
94 * 1 = blocked to left, 87 * 1 = blocked to left,
95 * 2 = blocked to right, 88 * 2 = blocked to right,
96 * 4 = blocked above 89 * 4 = blocked above
97 * 8 = blocked below 90 * 8 = blocked below
98 */ 91 */
99 92
100 int surround_index = 0; 93 int surround_index = 0;
101 94
95 // don't forget to update the mapspace!
96 if (i > 0) map->at (i - 1, j ).update ();
97 if (i < RP->Xsize - 1) map->at (i + 1, j ).update ();
98 if (j > 0) map->at (i , j - 1).update ();
99 if (j < RP->Ysize - 1) map->at (i , j + 1).update ();
100
102 if ((i > 0) && (GET_MAP_MOVE_BLOCK (map, i - 1, j) & ~MOVE_BLOCK_DEFAULT)) 101 if ((i > 0) && (GET_MAP_MOVE_BLOCK (map, i - 1, j) & MOVE_WALK))
103 surround_index |= 1; 102 surround_index |= 1;
104 if ((i < RP->Xsize - 1) && (GET_MAP_MOVE_BLOCK (map, i + 1, j) & ~MOVE_BLOCK_DEFAULT)) 103 if ((i < RP->Xsize - 1) && (GET_MAP_MOVE_BLOCK (map, i + 1, j) & MOVE_WALK))
105 surround_index |= 2; 104 surround_index |= 2;
106 if ((j > 0) && (GET_MAP_MOVE_BLOCK (map, i, j - 1) & ~MOVE_BLOCK_DEFAULT)) 105 if ((j > 0) && (GET_MAP_MOVE_BLOCK (map, i, j - 1) & MOVE_WALK))
107 surround_index |= 4; 106 surround_index |= 4;
108 if ((j < RP->Ysize - 1) && (GET_MAP_MOVE_BLOCK (map, i, j + 1) & ~MOVE_BLOCK_DEFAULT)) 107 if ((j < RP->Ysize - 1) && (GET_MAP_MOVE_BLOCK (map, i, j + 1) & MOVE_WALK))
109 surround_index |= 8; 108 surround_index |= 8;
110 109
111 return surround_index; 110 return surround_index;
112} 111}
113 112
114/* like surround_flag2, except it checks a map, not a layout. */ 113/* like surround_flag2, except it checks a map, not a layout. */
115 114
116int 115int
117surround_flag4 (mapstruct *map, int i, int j, RMParms * RP) 116surround_flag4 (maptile *map, int i, int j, random_map_params *RP)
118{ 117{
119 /* 1 = blocked to left, 118 /* 1 = blocked to left,
120 2 = blocked to right, 119 2 = blocked to right,
121 4 = blocked above 120 4 = blocked above
122 8 = blocked below */ 121 8 = blocked below */
136 135
137/* takes a map and a layout, and puts walls in the map (picked from 136/* takes a map and a layout, and puts walls in the map (picked from
138 w_style) at '#' marks. */ 137 w_style) at '#' marks. */
139 138
140void 139void
141make_map_walls (mapstruct *map, char **layout, char *w_style, RMParms * RP) 140make_map_walls (maptile *map, char **layout, char *w_style, random_map_params *RP)
142{ 141{
143 char styledirname[256]; 142 char styledirname[1024];
144 char stylefilepath[256]; 143 char stylefilepath[1024];
145 mapstruct *style_map = 0; 144 maptile *style_map = 0;
146 object *the_wall; 145 object *the_wall;
147 146
148 /* get the style map */ 147 /* get the style map */
149 if (!strcmp (w_style, "none")) 148 if (!strcmp (w_style, "none"))
150 return; 149 return;
151 sprintf (styledirname, "%s", "/styles/wallstyles"); 150 sprintf (styledirname, "%s", "/styles/wallstyles");
152 sprintf (stylefilepath, "%s/%s", styledirname, w_style); 151 sprintf (stylefilepath, "%s/%s", styledirname, w_style);
153 style_map = find_style (styledirname, w_style, -1); 152 style_map = find_style (styledirname, w_style, -1);
154 if (style_map == 0) 153 if (!style_map)
155 return; 154 return;
156 155
157 /* fill up the map with the given floor style */ 156 /* fill up the map with the given floor style */
158 if ((the_wall = pick_random_object (style_map)) != NULL) 157 if ((the_wall = style_map->pick_random_object (rmg_rndm)))
159 { 158 {
160 int i, j; 159 int i, j;
161 char *cp; 160 char *cp;
162 int joinedwalls = 0; 161 int joinedwalls = 0;
163 object *thiswall; 162 object *thiswall;
164 163
165 sprintf (RP->wall_name, "%s", &the_wall->arch->name); 164 sprintf (RP->wall_name, "%s", &the_wall->arch->archname);
166 if ((cp = strchr (RP->wall_name, '_')) != NULL) 165 if ((cp = strchr (RP->wall_name, '_')) != NULL)
167 { 166 {
168 *cp = 0; 167 *cp = 0;
169 joinedwalls = 1; 168 joinedwalls = 1;
170 } 169 }
190 189
191/* picks the right wall type for this square, to make it look nice, 190/* picks the right wall type for this square, to make it look nice,
192 and have everything nicely joined. It uses the layout. */ 191 and have everything nicely joined. It uses the layout. */
193 192
194object * 193object *
195pick_joined_wall (object *the_wall, char **layout, int i, int j, RMParms * RP) 194pick_joined_wall (object *the_wall, char **layout, int i, int j, random_map_params *RP)
196{ 195{
197 /* 1 = wall to left, 196 /* 1 = wall to left,
198 2 = wall to right, 197 2 = wall to right,
199 4 = wall above 198 4 = wall above
200 8 = wall below */ 199 8 = wall below */
201 int surround_index = 0; 200 int surround_index = 0;
202 int l; 201 int l;
203 char wall_name[64]; 202 char wall_name[1024];
204 archetype *wall_arch = 0; 203 archetype *wall_arch = 0;
205 204
206 strcpy (wall_name, the_wall->arch->name); 205 assign (wall_name, the_wall->arch->archname);
207 206
208 /* conventionally, walls are named like this: 207 /* conventionally, walls are named like this:
209 wallname_wallcode, where wallcode indicates 208 wallname_wallcode, where wallcode indicates
210 a joinedness, and wallname is the wall. 209 a joinedness, and wallname is the wall.
211 this code depends on the convention for 210 this code depends on the convention for
223 222
224 surround_index = surround_flag2 (layout, i, j, RP); 223 surround_index = surround_flag2 (layout, i, j, RP);
225 224
226 switch (surround_index) 225 switch (surround_index)
227 { 226 {
228 case 0: 227 case 0:
229 strcat (wall_name, "_0"); 228 strcat (wall_name, "_0");
230 break; 229 break;
231 case 1: 230 case 1:
232 strcat (wall_name, "_1_3"); 231 strcat (wall_name, "_1_3");
233 break; 232 break;
234 case 2: 233 case 2:
235 strcat (wall_name, "_1_4"); 234 strcat (wall_name, "_1_4");
236 break; 235 break;
237 case 3: 236 case 3:
238 strcat (wall_name, "_2_1_2"); 237 strcat (wall_name, "_2_1_2");
239 break; 238 break;
240 case 4: 239 case 4:
241 strcat (wall_name, "_1_2"); 240 strcat (wall_name, "_1_2");
242 break; 241 break;
243 case 5: 242 case 5:
244 strcat (wall_name, "_2_2_4"); 243 strcat (wall_name, "_2_2_4");
245 break; 244 break;
246 case 6: 245 case 6:
247 strcat (wall_name, "_2_2_1"); 246 strcat (wall_name, "_2_2_1");
248 break; 247 break;
249 case 7: 248 case 7:
250 strcat (wall_name, "_3_1"); 249 strcat (wall_name, "_3_1");
251 break; 250 break;
252 case 8: 251 case 8:
253 strcat (wall_name, "_1_1"); 252 strcat (wall_name, "_1_1");
254 break; 253 break;
255 case 9: 254 case 9:
256 strcat (wall_name, "_2_2_3"); 255 strcat (wall_name, "_2_2_3");
257 break; 256 break;
258 case 10: 257 case 10:
259 strcat (wall_name, "_2_2_2"); 258 strcat (wall_name, "_2_2_2");
260 break; 259 break;
261 case 11: 260 case 11:
262 strcat (wall_name, "_3_3"); 261 strcat (wall_name, "_3_3");
263 break; 262 break;
264 case 12: 263 case 12:
265 strcat (wall_name, "_2_1_1"); 264 strcat (wall_name, "_2_1_1");
266 break; 265 break;
267 case 13: 266 case 13:
268 strcat (wall_name, "_3_4"); 267 strcat (wall_name, "_3_4");
269 break; 268 break;
270 case 14: 269 case 14:
271 strcat (wall_name, "_3_2"); 270 strcat (wall_name, "_3_2");
272 break; 271 break;
273 case 15: 272 case 15:
274 strcat (wall_name, "_4"); 273 strcat (wall_name, "_4");
275 break; 274 break;
276 } 275 }
277 wall_arch = find_archetype (wall_name); 276 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 277
286 278 return wall_arch ? arch_to_object (wall_arch) : arch_to_object (the_wall->arch);
287} 279}
288 280
289 281
290/* this takes a map, and changes an existing wall to match what's blocked 282/* 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 283 * around it, counting only doors and walls as blocked. If insert_flag is
294 * remove anything. It depends on the 286 * remove anything. It depends on the
295 * global, previously-set variable, "wall_name" 287 * global, previously-set variable, "wall_name"
296 */ 288 */
297 289
298object * 290object *
299retrofit_joined_wall (mapstruct *the_map, int i, int j, int insert_flag, RMParms * RP) 291retrofit_joined_wall (maptile *the_map, int i, int j, int insert_flag, random_map_params *RP)
300{ 292{
301 /* 1 = wall to left, 293 /* 1 = wall to left,
302 * 2 = wall to right, 294 * 2 = wall to right,
303 * 4 = wall above 295 * 4 = wall above
304 * 8 = wall below 296 * 8 = wall below
308 object *the_wall = 0; 300 object *the_wall = 0;
309 object *new_wall = 0; 301 object *new_wall = 0;
310 archetype *wall_arch = 0; 302 archetype *wall_arch = 0;
311 303
312 /* first find the wall */ 304 /* first find the wall */
313 for (the_wall = get_map_ob (the_map, i, j); the_wall != NULL; the_wall = the_wall->above) 305 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) 306 if ((the_wall->move_type & MOVE_WALK) && the_wall->type != EXIT && the_wall->type != TELEPORTER)
315 break; 307 break;
316 308
317 309
318 /* if what we found is a door, don't remove it, set the_wall to NULL to 310 /* 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, 336 /* This would be a lot cleaner to just us a lookup table,
345 * eg, wall_suffix[surround_index] 337 * eg, wall_suffix[surround_index]
346 */ 338 */
347 switch (surround_index) 339 switch (surround_index)
348 { 340 {
349 case 0: 341 case 0:
350 strcat (RP->wall_name, "_0"); 342 strcat (RP->wall_name, "_0");
351 break; 343 break;
352 case 1: 344 case 1:
353 strcat (RP->wall_name, "_1_3"); 345 strcat (RP->wall_name, "_1_3");
354 break; 346 break;
355 case 2: 347 case 2:
356 strcat (RP->wall_name, "_1_4"); 348 strcat (RP->wall_name, "_1_4");
357 break; 349 break;
358 case 3: 350 case 3:
359 strcat (RP->wall_name, "_2_1_2"); 351 strcat (RP->wall_name, "_2_1_2");
360 break; 352 break;
361 case 4: 353 case 4:
362 strcat (RP->wall_name, "_1_2"); 354 strcat (RP->wall_name, "_1_2");
363 break; 355 break;
364 case 5: 356 case 5:
365 strcat (RP->wall_name, "_2_2_4"); 357 strcat (RP->wall_name, "_2_2_4");
366 break; 358 break;
367 case 6: 359 case 6:
368 strcat (RP->wall_name, "_2_2_1"); 360 strcat (RP->wall_name, "_2_2_1");
369 break; 361 break;
370 case 7: 362 case 7:
371 strcat (RP->wall_name, "_3_1"); 363 strcat (RP->wall_name, "_3_1");
372 break; 364 break;
373 case 8: 365 case 8:
374 strcat (RP->wall_name, "_1_1"); 366 strcat (RP->wall_name, "_1_1");
375 break; 367 break;
376 case 9: 368 case 9:
377 strcat (RP->wall_name, "_2_2_3"); 369 strcat (RP->wall_name, "_2_2_3");
378 break; 370 break;
379 case 10: 371 case 10:
380 strcat (RP->wall_name, "_2_2_2"); 372 strcat (RP->wall_name, "_2_2_2");
381 break; 373 break;
382 case 11: 374 case 11:
383 strcat (RP->wall_name, "_3_3"); 375 strcat (RP->wall_name, "_3_3");
384 break; 376 break;
385 case 12: 377 case 12:
386 strcat (RP->wall_name, "_2_1_1"); 378 strcat (RP->wall_name, "_2_1_1");
387 break; 379 break;
388 case 13: 380 case 13:
389 strcat (RP->wall_name, "_3_4"); 381 strcat (RP->wall_name, "_3_4");
390 break; 382 break;
391 case 14: 383 case 14:
392 strcat (RP->wall_name, "_3_2"); 384 strcat (RP->wall_name, "_3_2");
393 break; 385 break;
394 case 15: 386 case 15:
395 strcat (RP->wall_name, "_4"); 387 strcat (RP->wall_name, "_4");
396 break; 388 break;
397 } 389 }
390
398 wall_arch = find_archetype (RP->wall_name); 391 wall_arch = archetype::find (RP->wall_name);
392
399 if (wall_arch != NULL) 393 if (!wall_arch)
400 { 394 {
401 new_wall = arch_to_object (wall_arch); 395 new_wall = arch_to_object (wall_arch);
402 new_wall->x = i; 396 new_wall->x = i;
403 new_wall->y = j; 397 new_wall->y = j;
398
404 if (the_wall && the_wall->map) 399 if (the_wall && the_wall->map)
405 { 400 the_wall->destroy ();
406 remove_ob (the_wall); 401
407 free_object (the_wall);
408 }
409 the_wall->move_block = MOVE_ALL; 402 the_wall->move_block = MOVE_ALL;
410 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);
411 } 404 }
412 else 405
413 nroferrors--; /* it's OK not to find an arch. */
414 return new_wall; 406 return new_wall;
415} 407}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines