ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/exit.C
(Generate patch)

Comparing deliantra/server/random_maps/exit.C (file contents):
Revision 1.4 by root, Sun Sep 10 16:06:37 2006 UTC vs.
Revision 1.14 by root, Sun Dec 31 10:28:36 2006 UTC

1
2/*
3 * static char *rcsid_exit_c =
4 * "$Id: exit.C,v 1.4 2006/09/10 16:06:37 root Exp $";
5 */
6
7/* 1/*
8 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
9 3
10 Copyright (C) 2001 Mark Wedel & Crossfire Development Team 4 Copyright (C) 2001 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen 5 Copyright (C) 1992 Frank Tore Johansen
22 16
23 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 20
27 The authors can be reached via e-mail at crossfire-devel@real-time.com 21 The authors can be reached via e-mail at <crossfire@schmorp.de>
28*/ 22*/
29 23
30#include <global.h> 24#include <global.h>
31#include <random_map.h> 25#include <random_map.h>
32#include <sproto.h> 26#include <sproto.h>
34 28
35 29
36/* find a character in the layout. fx and fy are pointers to 30/* find a character in the layout. fx and fy are pointers to
37 where to find the char. fx,fy = -1 if not found. */ 31 where to find the char. fx,fy = -1 if not found. */
38void 32void
39find_in_layout (int mode, char target, int *fx, int *fy, char **layout, RMParms * RP) 33find_in_layout (int mode, char target, int *fx, int *fy, char **layout, random_map_params * RP)
40{ 34{
41 int M; 35 int M;
42 int i, j; 36 int i, j;
43 37
44 *fx = -1; 38 *fx = -1;
112 break; 106 break;
113 } 107 }
114 } 108 }
115} 109}
116 110
117
118
119
120
121
122/* orientation: 0 means random, 111/* orientation: 0 means random,
123 1 means descending dungeon 112 1 means descending dungeon
124 2 means ascending dungeon 113 2 means ascending dungeon
125 3 means rightward 114 3 means rightward
126 4 means leftward 115 4 means leftward
127 5 means northward 116 5 means northward
128 6 means southward 117 6 means southward
129*/ 118*/
130
131void 119void
132place_exits (mapstruct *map, char **maze, char *exitstyle, int orientation, RMParms * RP) 120place_exits (maptile *map, char **maze, char *exitstyle, int orientation, random_map_params *RP)
133{ 121{
134 char styledirname[256]; 122 char styledirname[256];
135 mapstruct *style_map_down = 0; /* harder maze */ 123 maptile *style_map_down = 0; /* harder maze */
136 mapstruct *style_map_up = 0; /* easier maze */ 124 maptile *style_map_up = 0; /* easier maze */
137 object *the_exit_down; /* harder maze */ 125 object *the_exit_down; /* harder maze */
138 object *the_exit_up; /* easier maze */ 126 object *the_exit_up; /* easier maze */
139 object *random_sign; /* magic mouth saying this is a random map. */ 127 object *random_sign; /* magic mouth saying this is a random map. */
140 char buf[512]; 128 char buf[512];
141 int cx = -1, cy = -1; /* location of a map center */ 129 int cx = -1, cy = -1; /* location of a map center */
177 style_map_down = style_map_up; 165 style_map_down = style_map_up;
178 break; 166 break;
179 } 167 }
180 } 168 }
181 if (style_map_up == 0) 169 if (style_map_up == 0)
182 the_exit_up = arch_to_object (find_archetype ("exit")); 170 the_exit_up = arch_to_object (archetype::find ("exit"));
183 else 171 else
184 { 172 {
185 object *tmp; 173 object *tmp;
186 174
187 tmp = pick_random_object (style_map_up); 175 tmp = pick_random_object (style_map_up);
189 } 177 }
190 178
191 /* we need a down exit only if we're recursing. */ 179 /* we need a down exit only if we're recursing. */
192 if (RP->dungeon_level < RP->dungeon_depth || RP->final_map[0] != 0) 180 if (RP->dungeon_level < RP->dungeon_depth || RP->final_map[0] != 0)
193 if (style_map_down == 0) 181 if (style_map_down == 0)
194 the_exit_down = arch_to_object (find_archetype ("exit")); 182 the_exit_down = arch_to_object (archetype::find ("exit"));
195 else 183 else
196 { 184 {
197 object *tmp; 185 object *tmp;
198 186
199 tmp = pick_random_object (style_map_down); 187 tmp = pick_random_object (style_map_down);
268 256
269 insert_ob_in_map (the_exit_up, map, NULL, 0); 257 insert_ob_in_map (the_exit_up, map, NULL, 0);
270 maze[the_exit_up->x][the_exit_up->y] = '<'; 258 maze[the_exit_up->x][the_exit_up->y] = '<';
271 259
272 /* set the starting x,y for this map */ 260 /* set the starting x,y for this map */
273 MAP_ENTER_X (map) = the_exit_up->x; 261 map->enter_x = the_exit_up->x;
274 MAP_ENTER_Y (map) = the_exit_up->y; 262 map->enter_y = the_exit_up->y;
275 263
276 /* first, look for a '>' character */ 264 /* first, look for a '>' character */
277 find_in_layout (0, '>', &downx, &downy, maze, RP); 265 find_in_layout (0, '>', &downx, &downy, maze, RP);
278 /* if no > is found use C */ 266 /* if no > is found use C */
279 if (downx == -1) 267 if (downx == -1)
320 write_map_parameters_to_string (buf, RP); 308 write_map_parameters_to_string (buf, RP);
321 the_exit_down->msg = buf; 309 the_exit_down->msg = buf;
322 /* the identifier for making a random map. */ 310 /* the identifier for making a random map. */
323 if (RP->dungeon_level >= RP->dungeon_depth && RP->final_map[0] != 0) 311 if (RP->dungeon_level >= RP->dungeon_depth && RP->final_map[0] != 0)
324 { 312 {
325 mapstruct *new_map; 313 maptile *new_map;
326 object *the_exit_back = arch_to_object (the_exit_up->arch), *tmp; 314 object *the_exit_back = arch_to_object (the_exit_up->arch), *tmp;
327 315
328#if 0 316#if 0
329 /* I'm not sure if there was any reason to change the path to the 317 /* I'm not sure if there was any reason to change the path to the
330 * map other than to maybe make it more descriptive in the 'maps' 318 * map other than to maybe make it more descriptive in the 'maps'
337 /* give the final map a name */ 325 /* give the final map a name */
338 sprintf (new_map_name, "%sfinal_map", RP->final_map); 326 sprintf (new_map_name, "%sfinal_map", RP->final_map);
339 /* set the exit down. */ 327 /* set the exit down. */
340#endif 328#endif
341 /* load it */ 329 /* load it */
342 if ((new_map = ready_map_name (RP->final_map, 0)) == NULL) 330 if (!(new_map = maptile::load_map_sync (RP->final_map)))
343 return; 331 return;
344 332
345 the_exit_down->slaying = RP->final_map; 333 the_exit_down->slaying = RP->final_map;
346 strcpy (new_map->path, RP->final_map);
347 334
348 for (tmp = GET_MAP_OB (new_map, MAP_ENTER_X (new_map), MAP_ENTER_Y (new_map)); tmp; tmp = tmp->above) 335 for (tmp = new_map->at (new_map->enter_x, new_map->enter_y).bot; tmp; tmp = tmp->above)
349 /* Remove exit back to previous random map. There should only be one 336 /* Remove exit back to previous random map. There should only be one
350 * which is why we break out. To try to process more than one 337 * which is why we break out. To try to process more than one
351 * would require keeping a 'next' pointer, ad free_object kills tmp, which 338 * would require keeping a 'next' pointer, ad free_object kills tmp, which
352 * breaks the for loop. 339 * breaks the for loop.
353 */ 340 */
354 if (tmp->type == EXIT && EXIT_PATH (tmp) && !strncmp (EXIT_PATH (tmp), "/random/", 8)) 341 if (tmp->type == EXIT && EXIT_PATH (tmp) && !strncmp (EXIT_PATH (tmp), "/random/", 8))
355 { 342 {
356 remove_ob (tmp); 343 tmp->destroy ();
357 free_object (tmp);
358 break; 344 break;
359 } 345 }
360 346
361 if (final_map_exit == 1) 347 if (final_map_exit == 1)
362 { 348 {
363 /* setup the exit back */ 349 /* setup the exit back */
364 the_exit_back->slaying = map->path; 350 the_exit_back->slaying = map->path;
365 the_exit_back->stats.hp = the_exit_down->x; 351 the_exit_back->stats.hp = the_exit_down->x;
366 the_exit_back->stats.sp = the_exit_down->y; 352 the_exit_back->stats.sp = the_exit_down->y;
367 the_exit_back->x = MAP_ENTER_X (new_map); 353 the_exit_back->x = new_map->enter_x;
368 the_exit_back->y = MAP_ENTER_Y (new_map); 354 the_exit_back->y = new_map->enter_y;
369 355
370 insert_ob_in_map (the_exit_back, new_map, NULL, 0); 356 insert_ob_in_map (the_exit_back, new_map, NULL, 0);
371 } 357 }
372
373 set_map_timeout (new_map); /* So it gets swapped out */
374 } 358 }
375 else 359 else
376 the_exit_down->slaying = "/!"; 360 the_exit_down->slaying = "/!";
377 361
378 /* Block the exit so things don't get dumped on top of it. */ 362 /* Block the exit so things don't get dumped on top of it. */
382 } 366 }
383 } 367 }
384 368
385} 369}
386 370
387
388
389/* this function unblocks the exits. We blocked them to 371/* this function unblocks the exits. We blocked them to
390 keep things from being dumped on them during the other 372 keep things from being dumped on them during the other
391 phases of random map generation. */ 373 phases of random map generation. */
392void 374void
393unblock_exits (mapstruct *map, char **maze, RMParms * RP) 375unblock_exits (maptile *map, char **maze, random_map_params * RP)
394{ 376{
395 int i = 0, j = 0; 377 int i = 0, j = 0;
396 object *walk; 378 object *walk;
397 379
398 for (i = 0; i < RP->Xsize; i++) 380 for (i = 0; i < RP->Xsize; i++)
399 for (j = 0; j < RP->Ysize; j++) 381 for (j = 0; j < RP->Ysize; j++)
400 if (maze[i][j] == '>' || maze[i][j] == '<') 382 if (maze[i][j] == '>' || maze[i][j] == '<')
401 { 383 {
402 for (walk = get_map_ob (map, i, j); walk != NULL; walk = walk->above) 384 for (walk = GET_MAP_OB (map, i, j); walk != NULL; walk = walk->above)
403 { 385 {
404 if (walk->move_block == MOVE_ALL && walk->type != LOCKED_DOOR) 386 if (walk->move_block == MOVE_ALL && walk->type != LOCKED_DOOR)
405 { 387 {
406 walk->move_block = MOVE_BLOCK_DEFAULT; 388 walk->move_block = MOVE_BLOCK_DEFAULT;
407 update_object (walk, UP_OBJ_CHANGE); 389 update_object (walk, UP_OBJ_CHANGE);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines