1 | /* |
1 | /* |
2 | * static char *rcsid_treasure_c = |
2 | * static char *rcsid_treasure_c = |
3 | * "$Id: treasure.c,v 1.3 2006/03/04 19:29:03 root Exp $"; |
3 | * "$Id: treasure.c,v 1.4 2006/03/15 15:35:52 elmex Exp $"; |
4 | */ |
4 | */ |
5 | |
5 | |
6 | /* |
6 | /* |
7 | CrossFire, A Multiplayer game for X-windows |
7 | CrossFire, A Multiplayer game for X-windows |
8 | |
8 | |
… | |
… | |
255 | for(i=0;i<SIZEOFFREE;i++) { |
255 | for(i=0;i<SIZEOFFREE;i++) { |
256 | int lx,ly; |
256 | int lx,ly; |
257 | lx=x+freearr_x[i]; |
257 | lx=x+freearr_x[i]; |
258 | ly=y+freearr_y[i]; |
258 | ly=y+freearr_y[i]; |
259 | /* boundscheck */ |
259 | /* boundscheck */ |
260 | if(lx > 0 && ly > 0 && lx < RP->Xsize && ly < RP->Ysize) |
260 | if(lx >= 0 && ly >= 0 && lx < RP->Xsize && ly < RP->Ysize) |
261 | /* don't bother searching this square unless the map says life exists.*/ |
261 | /* don't bother searching this square unless the map says life exists.*/ |
262 | if(GET_MAP_FLAGS(map,lx,ly) & P_IS_ALIVE) { |
262 | if(GET_MAP_FLAGS(map,lx,ly) & P_IS_ALIVE) { |
263 | object *the_monster=get_map_ob(map,lx,ly); |
263 | object *the_monster=get_map_ob(map,lx,ly); |
264 | for(;the_monster!=NULL&&(!QUERY_FLAG(the_monster,FLAG_MONSTER));the_monster=the_monster->above); |
264 | for(;the_monster!=NULL&&(!QUERY_FLAG(the_monster,FLAG_MONSTER));the_monster=the_monster->above); |
265 | if(the_monster && QUERY_FLAG(the_monster,FLAG_MONSTER)) |
265 | if(the_monster && QUERY_FLAG(the_monster,FLAG_MONSTER)) |
… | |
… | |
502 | void find_enclosed_spot(mapstruct *map, int *cx, int *cy,RMParms *RP) { |
502 | void find_enclosed_spot(mapstruct *map, int *cx, int *cy,RMParms *RP) { |
503 | int x,y; |
503 | int x,y; |
504 | int i; |
504 | int i; |
505 | x = *cx;y=*cy; |
505 | x = *cx;y=*cy; |
506 | |
506 | |
507 | for(i=0;i<SIZEOFFREE1;i++) { |
507 | for(i=0;i<=SIZEOFFREE1;i++) { |
508 | int lx,ly,sindex; |
508 | int lx,ly,sindex; |
509 | lx = x +freearr_x[i]; |
509 | lx = x +freearr_x[i]; |
510 | ly = y +freearr_y[i]; |
510 | ly = y +freearr_y[i]; |
511 | sindex = surround_flag3(map,lx,ly,RP); |
511 | sindex = surround_flag3(map,lx,ly,RP); |
512 | /* if it's blocked on 3 sides, it's enclosed */ |
512 | /* if it's blocked on 3 sides, it's enclosed */ |
… | |
… | |
516 | } |
516 | } |
517 | } |
517 | } |
518 | |
518 | |
519 | /* OK, if we got here, we're obviously someplace where there's no enclosed |
519 | /* OK, if we got here, we're obviously someplace where there's no enclosed |
520 | spots--try to find someplace which is 2x enclosed. */ |
520 | spots--try to find someplace which is 2x enclosed. */ |
521 | for(i=0;i<SIZEOFFREE1;i++) { |
521 | for(i=0;i<=SIZEOFFREE1;i++) { |
522 | int lx,ly,sindex; |
522 | int lx,ly,sindex; |
523 | lx = x +freearr_x[i]; |
523 | lx = x +freearr_x[i]; |
524 | ly = y +freearr_y[i]; |
524 | ly = y +freearr_y[i]; |
525 | sindex = surround_flag3(map,lx,ly,RP); |
525 | sindex = surround_flag3(map,lx,ly,RP); |
526 | /* if it's blocked on 3 sides, it's enclosed */ |
526 | /* if it's blocked on 3 sides, it's enclosed */ |
… | |
… | |
529 | return; |
529 | return; |
530 | } |
530 | } |
531 | } |
531 | } |
532 | |
532 | |
533 | /* settle for one surround point */ |
533 | /* settle for one surround point */ |
534 | for(i=0;i<SIZEOFFREE1;i++) { |
534 | for(i=0;i<=SIZEOFFREE1;i++) { |
535 | int lx,ly,sindex; |
535 | int lx,ly,sindex; |
536 | lx = x +freearr_x[i]; |
536 | lx = x +freearr_x[i]; |
537 | ly = y +freearr_y[i]; |
537 | ly = y +freearr_y[i]; |
538 | sindex = surround_flag3(map,lx,ly,RP); |
538 | sindex = surround_flag3(map,lx,ly,RP); |
539 | /* if it's blocked on 3 sides, it's enclosed */ |
539 | /* if it's blocked on 3 sides, it's enclosed */ |
… | |
… | |
542 | return; |
542 | return; |
543 | } |
543 | } |
544 | } |
544 | } |
545 | /* give up and return the closest free spot. */ |
545 | /* give up and return the closest free spot. */ |
546 | i = find_first_free_spot(&find_archetype("chest")->clone,map,x,y); |
546 | i = find_first_free_spot(&find_archetype("chest")->clone,map,x,y); |
547 | if(i!=-1&&i<SIZEOFFREE1) { |
547 | if(i!=-1&&i<=SIZEOFFREE1) { |
548 | *cx = x +freearr_x[i]; |
548 | *cx = x +freearr_x[i]; |
549 | *cy = y +freearr_y[i]; |
549 | *cy = y +freearr_y[i]; |
|
|
550 | return; |
550 | } |
551 | } |
551 | /* indicate failure */ |
552 | /* indicate failure */ |
552 | *cx=*cy=-1; |
553 | *cx=*cy=-1; |
553 | } |
554 | } |
554 | |
555 | |