home *** CD-ROM | disk | FTP | other *** search
/ WarCraft 2000 - Nuclear Epidemic / W2000.nrg / SOURCE.War2000 / TopZones.cpp < prev    next >
C/C++ Source or Header  |  1998-07-16  |  3KB  |  153 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. void CreateRZAMap();
  13. typedef char ZType;
  14. ZType TZones[256][256];
  15. ZType RZAMap[256][256];
  16. const idrx1[8]={0,1,1,1,0,-1,-1,-1};
  17. const idry1[8]={-1,-1,0,1,1,1,0,-1};
  18. void EquZones(ZType id1,ZType id2){
  19.     for(int i=1;i<=msx;i++)
  20.     for(int j=1;j<=msy;j++){
  21.         if(TZones[j][i]==id1)TZones[j][i]=id2;
  22.         if(RZAMap[j][i]==id1)RZAMap[j][i]=id2;
  23.     };
  24. };
  25. void FillTerrainZone(ZType id){
  26.     ZType* zt;
  27.     bool chan;
  28.     do{
  29.         chan=false;
  30.         for(int i=1;i<=msx;i++)
  31.             for(int j=1;j<=msy;j++){
  32.                 if(!TrMap[j][i]){
  33.                     zt=&TZones[j][i];
  34.                     if(*(zt+1)==id||*(zt-1)==id||*(zt+256)==id||*(zt-256)==id||
  35.                         *(zt+257)==id||*(zt-257)==id||*(zt+255)==id||*(zt-255)==id)
  36.                         if(*zt!=id){
  37.                             *zt=id;
  38.                             chan=true;
  39.                     };
  40.                 };
  41.             };
  42.     }while(chan);
  43. };
  44. void FillWZone(ZType id){
  45.     ZType* zt;
  46.     bool chan;
  47.     do{
  48.         chan=false;
  49.         for(int i=1;i<=msx;i++)
  50.             for(int j=1;j<=msy;j++){
  51.                 if(!WMap[j][i]){
  52.                     zt=&TZones[j][i];
  53.                     if(*(zt+1)==id||*(zt-1)==id||*(zt+256)==id||*(zt-256)==id||
  54.                         *(zt+257)==id||*(zt-257)==id||*(zt+255)==id||*(zt-255)==id)
  55.                         if(*zt!=id){
  56.                             *zt=id;
  57.                             chan=true;
  58.                     };
  59.                 };
  60.             };
  61.     }while(chan);
  62. };
  63. bool FindEmpty(ZType id){
  64.     for(int i=1;i<=msx;i++)
  65.         for(int j=1;j<=msy;j++){
  66.             if((!TrMap[j][i])&&TZones[j][i]==-1){
  67.                 TZones[j][i]=id;
  68.                 return true;
  69.             };
  70.         };
  71.     return false;
  72. };
  73. bool FindWEmpty(ZType id){
  74.     for(int i=1;i<=msx;i++)
  75.         for(int j=1;j<=msy;j++){
  76.             if((!WMap[j][i])&&TZones[j][i]==-1){
  77.                 TZones[j][i]=id;
  78.                 return true;
  79.             };
  80.         };
  81.     return false;
  82. };
  83. void CreateTZones(){
  84.     memset(TZones,255,sizeof TZones);
  85.     bool Distributed=false;
  86.     ZType ID=1;
  87.     do{
  88.         if(FindEmpty(ID)){
  89.             FillTerrainZone(ID);
  90.             ID++;
  91.         }else Distributed=true;
  92.     }while(!Distributed);
  93.     Distributed=false;
  94.     do{
  95.         if(FindWEmpty(ID)){
  96.             FillWZone(ID);
  97.             ID++;
  98.         }else Distributed=true;
  99.  
  100.     }while(!Distributed);
  101.     CreateRZAMap();
  102. };
  103. void SetRAPoint(byte i,byte j){
  104.     ZType* ztp;
  105.     ZType* RZ=&RZAMap[j][i];
  106.     *RZ=-1;
  107.     if(ramap[j][i]||ramap[j+1][i]||ramap[j+1][i+1]||ramap[j][i+1]){
  108.         ztp=(ZType*)(int(&TZones[j][i])-((sizeof ZType)<<9));
  109.         if(*(ztp+1+512)!=-1)  
  110.             *RZ=*(ztp+1+512);
  111.         if(ztp[512-1]!=0xFFFFFFFF)
  112.             *RZ=ztp[512-1];
  113.         if(*(ztp+256+512)!=-1)
  114.             *RZ=*(ztp+256+512);
  115.         if(*(ztp-256+512)!=-1)
  116.             *RZ=*(ztp-256+512);
  117.         if(*(ztp+255+512)!=-1)
  118.             *RZ=*(ztp+255+512);
  119.         if(*(ztp-255+512)!=-1)
  120.             *RZ=*(ztp-255+512);
  121.         if(*(ztp+257+512)!=-1)
  122.             *RZ=*(ztp+257+512);
  123.         if(*(ztp-257+512)!=-1)
  124.             *RZ=*(ztp-257+512);
  125.     };
  126. };
  127. void CreateRZAMap(){
  128.     memset(&RZAMap[0][0],255,sizeof RZAMap);
  129.     for(int i=1;i<=msx;i++)
  130.         for(int j=1;j<=msy;j++)SetRAPoint(i,j);
  131. };
  132. void PutZCell(int x,int y){
  133.     if(x>0&&x<=msx&&y>0&&y<=msy){
  134.         ZType zz1=-1;
  135.         ZType zz2;
  136.         for(int i=0;i<8;i++){
  137.             short idx=idrx1[i]+x;
  138.             short idy=idry1[i]+y;
  139.             zz2=TZones[idy][idx];
  140.             if(zz1!=zz2){
  141.                 if(zz1==-1)zz1=zz2;
  142.                 if(zz2!=-1&&zz1!=zz2) EquZones(zz2,zz1);
  143.             };
  144.         };
  145.         TZones[y][x]=zz1;
  146.         for(i=0;i<8;i++){
  147.             short idx=idrx1[i];
  148.             short idy=idry1[i];
  149.             SetRAPoint(idx+x,idy+y);
  150.         };
  151.         SetRAPoint(x,y);
  152.     };
  153. };