1 | |
1 | |
2 | /* |
2 | /* |
3 | CrossFire, A Multiplayer game for X-windows |
3 | CrossFire, A Multiplayer game for X-windows |
4 | |
4 | |
|
|
5 | Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
5 | Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
6 | Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
6 | Copyright (C) 1992 Frank Tore Johansen |
7 | Copyright (C) 1992 Frank Tore Johansen |
7 | |
8 | |
8 | This program is free software; you can redistribute it and/or modify |
9 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by |
10 | it under the terms of the GNU General Public License as published by |
… | |
… | |
211 | if (i == -1) |
212 | if (i == -1) |
212 | { |
213 | { |
213 | the_chest->destroy (); |
214 | the_chest->destroy (); |
214 | return NULL; |
215 | return NULL; |
215 | } |
216 | } |
|
|
217 | |
216 | xl = x + freearr_x[i]; |
218 | xl = x + freearr_x[i]; |
217 | yl = y + freearr_y[i]; |
219 | yl = y + freearr_y[i]; |
218 | |
220 | |
219 | /* if the placement is blocked, return a fail. */ |
221 | /* if the placement is blocked, return a fail. */ |
220 | if (wall_blocked (map, xl, yl)) |
222 | if (wall_blocked (map, xl, yl)) |
… | |
… | |
366 | freeindex = -1; |
368 | freeindex = -1; |
367 | for (tries = 0; tries < 15 && freeindex == -1; tries++) |
369 | for (tries = 0; tries < 15 && freeindex == -1; tries++) |
368 | { |
370 | { |
369 | kx = (RANDOM () % (RP->Xsize - 2)) + 1; |
371 | kx = (RANDOM () % (RP->Xsize - 2)) + 1; |
370 | ky = (RANDOM () % (RP->Ysize - 2)) + 1; |
372 | ky = (RANDOM () % (RP->Ysize - 2)) + 1; |
371 | freeindex = find_first_free_spot (the_key, map, kx, ky); |
373 | freeindex = find_free_spot (the_key, map, kx, ky, 1, SIZEOFFREE1 + 1); |
372 | } |
374 | } |
|
|
375 | |
373 | if (freeindex != -1) |
376 | if (freeindex != -1) |
374 | { |
377 | { |
375 | kx += freearr_x[freeindex]; |
378 | kx += freearr_x[freeindex]; |
376 | ky += freearr_y[freeindex]; |
379 | ky += freearr_y[freeindex]; |
377 | } |
380 | } |
… | |
… | |
383 | NO_PASS_DOORS is set. */ |
386 | NO_PASS_DOORS is set. */ |
384 | if (n_keys == 1) |
387 | if (n_keys == 1) |
385 | { |
388 | { |
386 | if (wall_blocked (map, x, y)) |
389 | if (wall_blocked (map, x, y)) |
387 | return 0; |
390 | return 0; |
|
|
391 | |
388 | the_keymaster = find_monster_in_room (map, x, y, RP); |
392 | the_keymaster = find_monster_in_room (map, x, y, RP); |
389 | if (the_keymaster == NULL) /* if fail, find a spot to drop the key. */ |
393 | if (the_keymaster == NULL) /* if fail, find a spot to drop the key. */ |
390 | find_spot_in_room (map, x, y, &kx, &ky, RP); |
394 | find_spot_in_room (map, x, y, &kx, &ky, RP); |
391 | } |
395 | } |
392 | else |
396 | else |
… | |
… | |
653 | *cy = ly; |
657 | *cy = ly; |
654 | return; |
658 | return; |
655 | } |
659 | } |
656 | } |
660 | } |
657 | /* give up and return the closest free spot. */ |
661 | /* give up and return the closest free spot. */ |
658 | i = find_first_free_spot (&archetype::find ("chest")->clone, map, x, y); |
662 | i = find_free_spot (&archetype::find ("chest")->clone, map, x, y, 1, SIZEOFFREE1 + 1); |
659 | if (i != -1 && i <= SIZEOFFREE1) |
663 | |
|
|
664 | if (i != -1) |
660 | { |
665 | { |
661 | *cx = x + freearr_x[i]; |
666 | *cx = x + freearr_x[i]; |
662 | *cy = y + freearr_y[i]; |
667 | *cy = y + freearr_y[i]; |
663 | return; |
668 | } |
|
|
669 | else |
664 | } |
670 | { |
665 | /* indicate failure */ |
671 | /* indicate failure */ |
|
|
672 | *cx = -1; |
666 | *cx = *cy = -1; |
673 | *cy = -1; |
|
|
674 | } |
667 | } |
675 | } |
668 | |
676 | |
669 | |
677 | |
670 | void |
678 | void |
671 | remove_monsters (int x, int y, maptile *map) |
679 | remove_monsters (int x, int y, maptile *map) |