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.15 by root, Sun Dec 31 17:17:23 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>
33#include <rproto.h> 27#include <rproto.h>
34 28
35
36/* find a character in the layout. fx and fy are pointers to 29/* find a character in the layout. fx and fy are pointers to
37 where to find the char. fx,fy = -1 if not found. */ 30 where to find the char. fx,fy = -1 if not found. */
38void 31void
39find_in_layout (int mode, char target, int *fx, int *fy, char **layout, RMParms * RP) 32find_in_layout (int mode, char target, int *fx, int *fy, char **layout, random_map_params * RP)
40{ 33{
41 int M; 34 int M;
42 int i, j; 35 int i, j;
43 36
44 *fx = -1; 37 *fx = -1;
112 break; 105 break;
113 } 106 }
114 } 107 }
115} 108}
116 109
117
118
119
120
121
122/* orientation: 0 means random, 110/* orientation: 0 means random,
123 1 means descending dungeon 111 1 means descending dungeon
124 2 means ascending dungeon 112 2 means ascending dungeon
125 3 means rightward 113 3 means rightward
126 4 means leftward 114 4 means leftward
127 5 means northward 115 5 means northward
128 6 means southward 116 6 means southward
129*/ 117*/
130
131void 118void
132place_exits (mapstruct *map, char **maze, char *exitstyle, int orientation, RMParms * RP) 119place_exits (maptile *map, char **maze, char *exitstyle, int orientation, random_map_params *RP)
133{ 120{
134 char styledirname[256]; 121 char styledirname[256];
135 mapstruct *style_map_down = 0; /* harder maze */ 122 maptile *style_map_down = 0; /* harder maze */
136 mapstruct *style_map_up = 0; /* easier maze */ 123 maptile *style_map_up = 0; /* easier maze */
137 object *the_exit_down; /* harder maze */ 124 object *the_exit_down; /* harder maze */
138 object *the_exit_up; /* easier maze */ 125 object *the_exit_up; /* easier maze */
139 object *random_sign; /* magic mouth saying this is a random map. */ 126 object *random_sign; /* magic mouth saying this is a random map. */
140 char buf[512]; 127 char buf[512];
141 int cx = -1, cy = -1; /* location of a map center */ 128 int cx = -1, cy = -1; /* location of a map center */
152 if (orientation == 0) 139 if (orientation == 0)
153 orientation = RANDOM () % 6 + 1; 140 orientation = RANDOM () % 6 + 1;
154 141
155 switch (orientation) 142 switch (orientation)
156 { 143 {
157 case 1: 144 case 1:
158 { 145 {
159 sprintf (styledirname, "/styles/exitstyles/up"); 146 sprintf (styledirname, "/styles/exitstyles/up");
160 style_map_up = find_style (styledirname, exitstyle, -1); 147 style_map_up = find_style (styledirname, exitstyle, -1);
161 sprintf (styledirname, "/styles/exitstyles/down"); 148 sprintf (styledirname, "/styles/exitstyles/down");
162 style_map_down = find_style (styledirname, exitstyle, -1); 149 style_map_down = find_style (styledirname, exitstyle, -1);
163 break; 150 break;
164 } 151 }
152
165 case 2: 153 case 2:
166 { 154 {
167 sprintf (styledirname, "/styles/exitstyles/down"); 155 sprintf (styledirname, "/styles/exitstyles/down");
168 style_map_up = find_style (styledirname, exitstyle, -1); 156 style_map_up = find_style (styledirname, exitstyle, -1);
169 sprintf (styledirname, "/styles/exitstyles/up"); 157 sprintf (styledirname, "/styles/exitstyles/up");
170 style_map_down = find_style (styledirname, exitstyle, -1); 158 style_map_down = find_style (styledirname, exitstyle, -1);
171 break; 159 break;
172 } 160 }
161
173 default: 162 default:
174 { 163 {
175 sprintf (styledirname, "/styles/exitstyles/generic"); 164 sprintf (styledirname, "/styles/exitstyles/generic");
176 style_map_up = find_style (styledirname, exitstyle, -1); 165 style_map_up = find_style (styledirname, exitstyle, -1);
177 style_map_down = style_map_up; 166 style_map_down = style_map_up;
178 break; 167 break;
179 } 168 }
180 } 169 }
170
181 if (style_map_up == 0) 171 if (style_map_up == 0)
182 the_exit_up = arch_to_object (find_archetype ("exit")); 172 the_exit_up = arch_to_object (archetype::find ("exit"));
183 else 173 else
184 { 174 {
185 object *tmp; 175 object *tmp;
186 176
187 tmp = pick_random_object (style_map_up); 177 tmp = pick_random_object (style_map_up);
189 } 179 }
190 180
191 /* we need a down exit only if we're recursing. */ 181 /* we need a down exit only if we're recursing. */
192 if (RP->dungeon_level < RP->dungeon_depth || RP->final_map[0] != 0) 182 if (RP->dungeon_level < RP->dungeon_depth || RP->final_map[0] != 0)
193 if (style_map_down == 0) 183 if (style_map_down == 0)
194 the_exit_down = arch_to_object (find_archetype ("exit")); 184 the_exit_down = arch_to_object (archetype::find ("exit"));
195 else 185 else
196 { 186 {
197 object *tmp; 187 object *tmp;
198 188
199 tmp = pick_random_object (style_map_down); 189 tmp = pick_random_object (style_map_down);
203 the_exit_down = 0; 193 the_exit_down = 0;
204 194
205 /* set up the up exit */ 195 /* set up the up exit */
206 the_exit_up->stats.hp = RP->origin_x; 196 the_exit_up->stats.hp = RP->origin_x;
207 the_exit_up->stats.sp = RP->origin_y; 197 the_exit_up->stats.sp = RP->origin_y;
208 the_exit_up->slaying = RP->origin_map; 198 the_exit_up->slaying = RP->origin_map;
209 199
210 /* figure out where to put the entrance */ 200 /* figure out where to put the entrance */
211 /* begin a logical block */ 201 /* begin a logical block */
212 { 202 {
213 int i, j; 203 int i, j;
268 258
269 insert_ob_in_map (the_exit_up, map, NULL, 0); 259 insert_ob_in_map (the_exit_up, map, NULL, 0);
270 maze[the_exit_up->x][the_exit_up->y] = '<'; 260 maze[the_exit_up->x][the_exit_up->y] = '<';
271 261
272 /* set the starting x,y for this map */ 262 /* set the starting x,y for this map */
273 MAP_ENTER_X (map) = the_exit_up->x; 263 map->enter_x = the_exit_up->x;
274 MAP_ENTER_Y (map) = the_exit_up->y; 264 map->enter_y = the_exit_up->y;
275 265
276 /* first, look for a '>' character */ 266 /* first, look for a '>' character */
277 find_in_layout (0, '>', &downx, &downy, maze, RP); 267 find_in_layout (0, '>', &downx, &downy, maze, RP);
278 /* if no > is found use C */ 268 /* if no > is found use C */
279 if (downx == -1) 269 if (downx == -1)
320 write_map_parameters_to_string (buf, RP); 310 write_map_parameters_to_string (buf, RP);
321 the_exit_down->msg = buf; 311 the_exit_down->msg = buf;
322 /* the identifier for making a random map. */ 312 /* the identifier for making a random map. */
323 if (RP->dungeon_level >= RP->dungeon_depth && RP->final_map[0] != 0) 313 if (RP->dungeon_level >= RP->dungeon_depth && RP->final_map[0] != 0)
324 { 314 {
325 mapstruct *new_map; 315 maptile *new_map;
326 object *the_exit_back = arch_to_object (the_exit_up->arch), *tmp; 316 object *the_exit_back = arch_to_object (the_exit_up->arch), *tmp;
327 317
328#if 0 318#if 0
329 /* I'm not sure if there was any reason to change the path to the 319 /* 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' 320 * map other than to maybe make it more descriptive in the 'maps'
337 /* give the final map a name */ 327 /* give the final map a name */
338 sprintf (new_map_name, "%sfinal_map", RP->final_map); 328 sprintf (new_map_name, "%sfinal_map", RP->final_map);
339 /* set the exit down. */ 329 /* set the exit down. */
340#endif 330#endif
341 /* load it */ 331 /* load it */
342 if ((new_map = ready_map_name (RP->final_map, 0)) == NULL) 332 if (!(new_map = maptile::load_map_sync (RP->final_map)))
343 return; 333 return;
344 334
345 the_exit_down->slaying = RP->final_map; 335 the_exit_down->slaying = RP->final_map;
346 strcpy (new_map->path, RP->final_map);
347 336
348 for (tmp = GET_MAP_OB (new_map, MAP_ENTER_X (new_map), MAP_ENTER_Y (new_map)); tmp; tmp = tmp->above) 337 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 338 /* 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 339 * 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 340 * would require keeping a 'next' pointer, ad free_object kills tmp, which
352 * breaks the for loop. 341 * breaks the for loop.
353 */ 342 */
354 if (tmp->type == EXIT && EXIT_PATH (tmp) && !strncmp (EXIT_PATH (tmp), "/random/", 8)) 343 if (tmp->type == EXIT && EXIT_PATH (tmp) && !strncmp (EXIT_PATH (tmp), "/random/", 8))
355 { 344 {
356 remove_ob (tmp); 345 tmp->destroy ();
357 free_object (tmp);
358 break; 346 break;
359 } 347 }
360 348
361 if (final_map_exit == 1) 349 if (final_map_exit == 1)
362 { 350 {
363 /* setup the exit back */ 351 /* setup the exit back */
364 the_exit_back->slaying = map->path; 352 the_exit_back->slaying = map->path;
365 the_exit_back->stats.hp = the_exit_down->x; 353 the_exit_back->stats.hp = the_exit_down->x;
366 the_exit_back->stats.sp = the_exit_down->y; 354 the_exit_back->stats.sp = the_exit_down->y;
367 the_exit_back->x = MAP_ENTER_X (new_map); 355 the_exit_back->x = new_map->enter_x;
368 the_exit_back->y = MAP_ENTER_Y (new_map); 356 the_exit_back->y = new_map->enter_y;
369 357
370 insert_ob_in_map (the_exit_back, new_map, NULL, 0); 358 insert_ob_in_map (the_exit_back, new_map, NULL, 0);
371 } 359 }
372
373 set_map_timeout (new_map); /* So it gets swapped out */
374 } 360 }
375 else 361 else
376 the_exit_down->slaying = "/!"; 362 the_exit_down->slaying = "/!";
377 363
378 /* Block the exit so things don't get dumped on top of it. */ 364 /* Block the exit so things don't get dumped on top of it. */
382 } 368 }
383 } 369 }
384 370
385} 371}
386 372
387
388
389/* this function unblocks the exits. We blocked them to 373/* this function unblocks the exits. We blocked them to
390 keep things from being dumped on them during the other 374 keep things from being dumped on them during the other
391 phases of random map generation. */ 375 phases of random map generation. */
392void 376void
393unblock_exits (mapstruct *map, char **maze, RMParms * RP) 377unblock_exits (maptile *map, char **maze, random_map_params * RP)
394{ 378{
395 int i = 0, j = 0; 379 int i = 0, j = 0;
396 object *walk; 380 object *walk;
397 381
398 for (i = 0; i < RP->Xsize; i++) 382 for (i = 0; i < RP->Xsize; i++)
399 for (j = 0; j < RP->Ysize; j++) 383 for (j = 0; j < RP->Ysize; j++)
400 if (maze[i][j] == '>' || maze[i][j] == '<') 384 if (maze[i][j] == '>' || maze[i][j] == '<')
401 { 385 {
402 for (walk = get_map_ob (map, i, j); walk != NULL; walk = walk->above) 386 for (walk = GET_MAP_OB (map, i, j); walk != NULL; walk = walk->above)
403 { 387 {
404 if (walk->move_block == MOVE_ALL && walk->type != LOCKED_DOOR) 388 if (walk->move_block == MOVE_ALL && walk->type != LOCKED_DOOR)
405 { 389 {
406 walk->move_block = MOVE_BLOCK_DEFAULT; 390 walk->move_block = MOVE_BLOCK_DEFAULT;
407 update_object (walk, UP_OBJ_CHANGE); 391 update_object (walk, UP_OBJ_CHANGE);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines