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.26 by root, Sun May 4 14:12:38 2008 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines