home *** CD-ROM | disk | FTP | other *** search
/ WarCraft 2000 - Nuclear Epidemic / W2000.nrg / SOURCE.War2000 / Find.cpp < prev    next >
C/C++ Source or Header  |  1998-09-17  |  3KB  |  147 lines

  1. #include "ddini.h"
  2. #include "ResFile.h"
  3. #include "FastDraw.h"
  4. #include "mgraph.h"
  5. #include "mouse.h"
  6. #include "menu.h"
  7. #include "MapDiscr.h"
  8. #include "multipl.h"
  9. #include "fog.h"
  10. #include "walls.h"
  11. #include "Nature.h"
  12. #include <time.h>
  13. #include "Nucl.h"
  14. #include "TopZones.h"
  15. #include "Megapolis.h"
  16. bool FindLEmpty(int* x,int* y,int r){
  17.     int x1=*x;
  18.     int y1=*y;
  19.     int d=0;
  20.     if(!LLock[y1][x1])return true;
  21.     do{
  22.         for(int    t=0;t<d;t++){
  23.             if(x1>0&&y1>1&&x1<=msx&&y1<=msy
  24.                 &&!LLock[y1][x1])goto fina;
  25.             x1++;
  26.         };
  27.         for(t=0;t<d;t++){
  28.             if(x1>0&&y1>1&&x1<=msx&&y1<=msy
  29.                 &&!LLock[y1][x1])goto fina;
  30.             y1++;
  31.         };
  32.         for(t=0;t<d;t++){
  33.             if(x1>0&&y1>1&&x1<=msx&&y1<=msy
  34.                 &&!LLock[y1][x1])goto fina;
  35.             x1--;
  36.         };
  37.         for(t=0;t<d;t++){
  38.             if(x1>0&&y1>1&&x1<=msx&&y1<=msy
  39.                 &&!LLock[y1][x1])goto fina;
  40.             y1--;
  41.         };
  42.         d+=2;
  43.         x1--;
  44.         y1--;
  45.     }while(d<r);
  46.     return false;
  47. fina:
  48.     *x=x1;
  49.     *y=y1;
  50.     return true;
  51. };
  52. bool FindTLEmpty(int* x,int* y,int r,ZType z1){
  53.     int x1=*x;
  54.     int y1=*y;
  55.     int d=0;
  56.     if(!LLock[y1][x1]&&TZones[y1][x1]==z1)return true;
  57.  
  58.     do{
  59.         for(int    t=0;t<d;t++){
  60.             if(x1>0&&y1>1&&x1<=msx&&y1<=msy
  61.                 &&!LLock[y1][x1])goto fina;
  62.             x1++;
  63.         };
  64.         for(t=0;t<d;t++){
  65.             if(x1>0&&y1>1&&x1<=msx&&y1<=msy&&TZones[y1][x1]==z1
  66.                 &&!LLock[y1][x1])goto fina;
  67.             y1++;
  68.         };
  69.         for(t=0;t<d;t++){
  70.             if(x1>0&&y1>1&&x1<=msx&&y1<=msy&&TZones[y1][x1]==z1
  71.                 &&!LLock[y1][x1])goto fina;
  72.             x1--;
  73.         };
  74.         for(t=0;t<d;t++){
  75.             if(x1>0&&y1>1&&x1<=msx&&y1<=msy&&TZones[y1][x1]==z1
  76.                 &&!LLock[y1][x1])goto fina;
  77.             y1--;
  78.         };
  79.         d+=2;
  80.         x1--;
  81.         y1--;
  82.     }while(d<r);
  83.     return false;
  84. fina:
  85.     *x=x1;
  86.     *y=y1;
  87.     return true;
  88. };
  89. bool WFindTLEmpty(int* x,int* y,int r,ZType z1){
  90.     int x1=(*x)&254;
  91.     int y1=(*y)&254;
  92.     int d=0;
  93.     if(!WLock[y1][x1]&&TZones[y1][x1]==z1)return true;
  94.  
  95.     do{
  96.         for(int    t=0;t<d;t++){
  97.             if(x1>0&&y1>1&&x1<=msx&&y1<=msy
  98.                 &&!WMap[y1][x1])goto fina;
  99.             x1+=2;
  100.         };
  101.         for(t=0;t<d;t++){
  102.             if(x1>0&&y1>1&&x1<=msx&&y1<=msy&&TZones[y1][x1]==z1
  103.                 &&!WMap[y1][x1])goto fina;
  104.             y1+=2;
  105.         };
  106.         for(t=0;t<d;t++){
  107.             if(x1>0&&y1>1&&x1<=msx&&y1<=msy&&TZones[y1][x1]==z1
  108.                 &&!WMap[y1][x1])goto fina;
  109.             x1-=2;
  110.         };
  111.         for(t=0;t<d;t++){
  112.             if(x1>0&&y1>1&&x1<=msx&&y1<=msy&&TZones[y1][x1]==z1
  113.                 &&!WMap[y1][x1])goto fina;
  114.             y1-=2;
  115.         };
  116.         d+=2;
  117.         x1-=2;
  118.         y1-=2;
  119.     }while(d<r);
  120.     return false;
  121. fina:
  122.     *x=x1;
  123.     *y=y1;
  124.     return true;
  125. };
  126. bool WFindTLEmptyDirect(int* x,int* y,ZType z1,int xd,int yd){
  127.     int x1=(*x)&254;
  128.     int y1=(*y)&254;
  129.     int x2=xd&254;
  130.     int y2=yd&254;
  131.     do{
  132.         int dx=x2-x1;
  133.         int dy=y2-y1;
  134.         if(dx>1)dx=1;
  135.         if(dy>1)dy=1;
  136.         if(dx<-1)dx=-1;
  137.         if(dy<-1)dy=-1;
  138.         x1+=dx+dx;
  139.         y1+=dy+dy;
  140.         if(!WLock[y1][x1]&&TZones[y1][x1]==z1){
  141.             *x=x1;
  142.             *y=y1;
  143.             return true;
  144.         };
  145.     }while(!(x1==x2&&y1==y2));
  146.     return false;
  147. };