1 | |
|
|
2 | /* |
1 | /* |
3 | CrossFire, A Multiplayer game for X-windows |
2 | * CrossFire, A Multiplayer game for X-windows |
4 | |
3 | * |
|
|
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
5 | Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
5 | * Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
6 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (C) 1992 Frank Tore Johansen |
7 | |
7 | * |
8 | This program is free software; you can redistribute it and/or modify |
8 | * 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 |
9 | * it under the terms of the GNU General Public License as published by |
10 | the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation; either version 2 of the License, or |
11 | (at your option) any later version. |
11 | * (at your option) any later version. |
12 | |
12 | * |
13 | 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, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | |
17 | * |
18 | 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 |
19 | along with this program; if not, write to the Free Software |
19 | * along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
21 | |
21 | * |
22 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
23 | */ |
23 | */ |
24 | |
24 | |
25 | /* placing treasure in maps, where appropriate. */ |
25 | /* placing treasure in maps, where appropriate. */ |
26 | |
26 | |
27 | |
27 | |
28 | |
28 | |
… | |
… | |
211 | if (i == -1) |
211 | if (i == -1) |
212 | { |
212 | { |
213 | the_chest->destroy (); |
213 | the_chest->destroy (); |
214 | return NULL; |
214 | return NULL; |
215 | } |
215 | } |
|
|
216 | |
216 | xl = x + freearr_x[i]; |
217 | xl = x + freearr_x[i]; |
217 | yl = y + freearr_y[i]; |
218 | yl = y + freearr_y[i]; |
218 | |
219 | |
219 | /* if the placement is blocked, return a fail. */ |
220 | /* if the placement is blocked, return a fail. */ |
220 | if (wall_blocked (map, xl, yl)) |
221 | if (wall_blocked (map, xl, yl)) |
… | |
… | |
366 | freeindex = -1; |
367 | freeindex = -1; |
367 | for (tries = 0; tries < 15 && freeindex == -1; tries++) |
368 | for (tries = 0; tries < 15 && freeindex == -1; tries++) |
368 | { |
369 | { |
369 | kx = (RANDOM () % (RP->Xsize - 2)) + 1; |
370 | kx = (RANDOM () % (RP->Xsize - 2)) + 1; |
370 | ky = (RANDOM () % (RP->Ysize - 2)) + 1; |
371 | ky = (RANDOM () % (RP->Ysize - 2)) + 1; |
371 | freeindex = find_first_free_spot (the_key, map, kx, ky); |
372 | freeindex = find_free_spot (the_key, map, kx, ky, 1, SIZEOFFREE1 + 1); |
372 | } |
373 | } |
|
|
374 | |
373 | if (freeindex != -1) |
375 | if (freeindex != -1) |
374 | { |
376 | { |
375 | kx += freearr_x[freeindex]; |
377 | kx += freearr_x[freeindex]; |
376 | ky += freearr_y[freeindex]; |
378 | ky += freearr_y[freeindex]; |
377 | } |
379 | } |
… | |
… | |
383 | NO_PASS_DOORS is set. */ |
385 | NO_PASS_DOORS is set. */ |
384 | if (n_keys == 1) |
386 | if (n_keys == 1) |
385 | { |
387 | { |
386 | if (wall_blocked (map, x, y)) |
388 | if (wall_blocked (map, x, y)) |
387 | return 0; |
389 | return 0; |
|
|
390 | |
388 | the_keymaster = find_monster_in_room (map, x, y, RP); |
391 | the_keymaster = find_monster_in_room (map, x, y, RP); |
389 | if (the_keymaster == NULL) /* if fail, find a spot to drop the key. */ |
392 | if (the_keymaster == NULL) /* if fail, find a spot to drop the key. */ |
390 | find_spot_in_room (map, x, y, &kx, &ky, RP); |
393 | find_spot_in_room (map, x, y, &kx, &ky, RP); |
391 | } |
394 | } |
392 | else |
395 | else |
… | |
… | |
653 | *cy = ly; |
656 | *cy = ly; |
654 | return; |
657 | return; |
655 | } |
658 | } |
656 | } |
659 | } |
657 | /* give up and return the closest free spot. */ |
660 | /* give up and return the closest free spot. */ |
658 | i = find_first_free_spot (&archetype::find ("chest")->clone, map, x, y); |
661 | i = find_free_spot (&archetype::find ("chest")->clone, map, x, y, 1, SIZEOFFREE1 + 1); |
659 | if (i != -1 && i <= SIZEOFFREE1) |
662 | |
|
|
663 | if (i != -1) |
660 | { |
664 | { |
661 | *cx = x + freearr_x[i]; |
665 | *cx = x + freearr_x[i]; |
662 | *cy = y + freearr_y[i]; |
666 | *cy = y + freearr_y[i]; |
663 | return; |
667 | } |
|
|
668 | else |
664 | } |
669 | { |
665 | /* indicate failure */ |
670 | /* indicate failure */ |
|
|
671 | *cx = -1; |
666 | *cx = *cy = -1; |
672 | *cy = -1; |
|
|
673 | } |
667 | } |
674 | } |
668 | |
675 | |
669 | |
676 | |
670 | void |
677 | void |
671 | remove_monsters (int x, int y, maptile *map) |
678 | remove_monsters (int x, int y, maptile *map) |