home *** CD-ROM | disk | FTP | other *** search
/ WarCraft 2000 - Nuclear Epidemic / W2000.nrg / SOURCE.War2000 / Select.cpp < prev    next >
C/C++ Source or Header  |  1998-09-25  |  6KB  |  249 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 "FlyObj.h"
  9. SelGroup SelSet[80];
  10. SelGroup::SelGroup(){
  11.     NMemb=0;
  12.     Member=NULL;
  13.     SerialN=NULL;
  14.     CanMove=true;
  15.     CanSearchVictim=true;
  16.     CanHelpToFriend=true;
  17.     Egoizm=false;
  18. };
  19. void SelGroup::CreateFromSelection(byte NI){
  20.     if(int(Member))DeleteMembers(NI);
  21.     Member=new word[NSL[NI]];
  22.     SerialN=new word[NSL[NI]];
  23.     word Nsel=NSL[NI];
  24.     memcpy(Member,Selm[NI],Nsel<<1);
  25.     memcpy(SerialN,SerN[NI],Nsel<<1);
  26.     int k;
  27.     word MID;
  28.     word NG1;
  29.     OneObject* OB;
  30.     word* mem1;
  31.     for(k=0;k<Nsel;k++){
  32.         MID=Member[k];
  33.         if(k!=0xFFFF){
  34.             OB=Group[k];
  35.             if(OB){
  36.                 //if(OB->GroupIndex){
  37.                 //    NG1=OB->GroupIndex->NMemb;
  38.                 //    mem1=OB->GroupIndex->Member;
  39.                 //    for(int i=0;i<NG1;i++)
  40.                 //        if(mem1[i]==MID)mem1[i]=0xFFFF;
  41.                 //};
  42.                 OB->Egoist=false;
  43.                 OB->GroupIndex=NULL;//this;
  44.             };
  45.         };
  46.     };
  47.     NMemb=Nsel;
  48. };
  49. void SelGroup::DeleteMembers(byte NI){
  50.     word MID;
  51.     OneObject* OB;
  52.     word Nsel=NSL[NI];
  53.     word * SMon=Selm[NI];
  54.     for(int k=0;k<Nsel;k++){
  55.         MID=Member[k];
  56.         if(k!=0xFFFF){
  57.             OB=Group[k];
  58.             if(OB){
  59.                 OB->Egoist=false;
  60.                 OB->GroupIndex=NULL;
  61.             };
  62.         };
  63.     };
  64.     if(int(Member))free(Member);
  65.     if(int(SerialN))free(SerialN);
  66.     SelGroup();
  67. };
  68. void SelGroup::SelectMembers(byte NI){
  69.     word MID;
  70.     OneObject* OB;
  71.     word Nsel=NSL[NI];
  72.     word* SMon=Selm[NI];
  73.     word* ser=SerN[NI];
  74.     for(int i=0;i<Nsel;i++){
  75.         MID=SMon[i];
  76.         if(MID!=0xFFFF){
  77.             OB=Group[MID];
  78.             if(int(OB)&&OB->Serial==ser[i]){
  79.                 OB->Egoist=false;
  80.                 OB->Selected=false;
  81.             };
  82.         };
  83.     };
  84.     word NR=0;
  85.     if(Nsel){
  86.         free(SMon);
  87.         free(ser);
  88.     };
  89.     SMon=new word[NMemb];
  90.     ser=new word[NMemb];
  91.     Selm[NI]=SMon;
  92.     SerN[NI]=ser;
  93.     for(i=0;i<NMemb;i++){
  94.         MID=Member[i];
  95.         if(MID!=0xFFFF){
  96.             SMon[NR]=MID;
  97.             ser[NR]=SerialN[i];
  98.             NR++;
  99.             OB=Group[MID];
  100.             if(int(OB)&&OB->Serial==SerialN[i]){
  101.                 OB->Egoist=false;
  102.                 OB->Selected=true;
  103.             };
  104.         };
  105.     };
  106.     NSL[NI]=NR;
  107.  
  108. };
  109. inline bool PxInside(int x,int y,int x1,int y1,int xp,int yp){
  110.     if(xp>=x&&xp<=x1&&yp>=y&&yp<=y1)return true;
  111.     else return false;
  112. };
  113. const sdrx[8]={0,1,1,1,0,-1,-1,-1};
  114. const sdry[8]={-1,-1,0,1,1,1,0,-1};
  115. word GetOwner(int x,int y){
  116.     int xx=x>>7;
  117.     int yy=y>>7;
  118.     for(int xx1=xx-1;xx1<xx+1;xx1++)
  119.         for(int yy1=yy-1;yy1<yy+1;yy1++)
  120.             if(xx1>0&&yy1>0&&xx1<64&&yy1<64){
  121.                 FlyCell* FC=&FlyMap[yy1][xx1];
  122.                 if(FC->NFly){
  123.                     for(int p=0;p<15;p++){
  124.                         word MID=FC->FlyList[p];
  125.                         if(MID!=0xFFFF){
  126.                             OneObject* OB=Group[MID];
  127.                             if(OB&&OB->Media==2){
  128.                                 int xs=(OB->RealX>>4)-60;
  129.                                 int ys=(OB->RealY>>4)-60+10;
  130.                                 int xs1=xs+120;
  131.                                 int ys1=ys+120;
  132.                                 if(PxInside(xs,ys,xs1,ys1,x,y))
  133.                                     return MID;
  134.                             };
  135.                         };
  136.                     };
  137.                 };
  138.             };
  139.     //search for terrain(on water)monsters
  140.     xx=x>>5;
  141.     yy=y>>5;
  142.     for(xx1=xx-1;xx1<xx+1;xx1++)
  143.         for(int yy1=yy-1;yy1<yy+1;yy1++){
  144.             word MID=Mops[yy1][xx1];
  145.             if(MID!=0xFFFF){
  146.                 OneObject* OB=Group[MID];
  147.                 int ox=(int(OB->x)<<5)+int(OB->Addx);
  148.                 int oy=(int(OB->y)<<5)+int(OB->Addy);
  149.                 if(OB->isMoving&&!OB->capBuilding){
  150.                     int nsp=OB->CurAnm->count;
  151.                     if(nsp>3){
  152.                         ox+=div(32*OB->CurrentSprite*sdrx[OB->Direction],nsp).quot;
  153.                         oy+=div(32*OB->CurrentSprite*sdry[OB->Direction],nsp).quot;
  154.                     };
  155.                 };
  156.                 //if(PxInside(ox-25,oy-25,ox+(OB->Lx<<5)+25,oy+(OB->Lx<<5)+25,x,y))
  157.                 return MID;
  158.             };
  159.         };
  160.     return 0xFFFF;
  161. };
  162. void GetRect(OneObject* ZZ,int* x,int* y,int* Lx);
  163. word GetEnemy(int x,int y,byte NI){
  164.     byte nms=1<<NI;
  165.     int ux,uy,ulx;
  166.     int xx=x>>7;
  167.     int yy=y>>7;
  168.     for(int xx1=xx-1;xx1<=xx+1;xx1++)
  169.         for(int yy1=yy-1;yy1<=yy+1;yy1++)
  170.             if(xx1>0&&yy1>0&&xx1<64&&yy1<64){
  171.                 FlyCell* FC=&FlyMap[yy1][xx1];
  172.                 if(FC->NFly){
  173.                     for(int p=0;p<15;p++){
  174.                         word MID=FC->FlyList[p];
  175.                         if(MID!=0xFFFF){
  176.                             OneObject* OB=Group[MID];
  177.                             if(OB&&OB->Media==2&&!(OB->NMask&nms)){
  178.                                 GetRect(OB,&ux,&uy,&ulx);
  179.                                 int xs=(OB->RealX>>4)-60;
  180.                                 int ys=(OB->RealY>>4)-60+10;
  181.                                 int xs1=xs+120;
  182.                                 int ys1=ys+120;
  183.                                 if(PxInside(ux,uy,ux+ulx-1,uy+ulx-1,x,y))
  184.                                     return MID;
  185.                             };
  186.                         };
  187.                     };
  188.                 };
  189.             };
  190.     //search for terrain(on water)monsters
  191.     xx=x>>5;
  192.     yy=y>>5;
  193.     for(xx1=xx-1;xx1<=xx+1;xx1++)
  194.         for(int yy1=yy-1;yy1<=yy+1;yy1++){
  195.             word MID=Mops[yy1][xx1];
  196.             if(MID!=0xFFFF){
  197.                 OneObject* OB=Group[MID];
  198.                 if(OB&&!(OB->NMask&nms)){
  199.                     GetRect(OB,&ux,&uy,&ulx);
  200.                     if(PxInside(ux-4,uy-4,ux+ulx+3,uy+ulx+3,x,y))
  201.                         return MID;
  202.                 };
  203.             };
  204.         };
  205.     return 0xFFFF;
  206. };
  207. word GetFriend(int x,int y,byte NI){
  208.     int ux,uy,ulx;
  209.     int xx=x>>7;
  210.     int yy=y>>7;
  211.     for(int xx1=xx-1;xx1<=xx+1;xx1++)
  212.         for(int yy1=yy-1;yy1<=yy+1;yy1++)
  213.             if(xx1>0&&yy1>0&&xx1<64&&yy1<64){
  214.                 FlyCell* FC=&FlyMap[yy1][xx1];
  215.                 if(FC->NFly){
  216.                     for(int p=0;p<15;p++){
  217.                         word MID=FC->FlyList[p];
  218.                         if(MID!=0xFFFF){
  219.                             OneObject* OB=Group[MID];
  220.                             if(OB&&OB->Media==2&&OB->NNUM==NI){
  221.                                 GetRect(OB,&ux,&uy,&ulx);
  222.                                 int xs=(OB->RealX>>4)-60;
  223.                                 int ys=(OB->RealY>>4)-60+10;
  224.                                 int xs1=xs+120;
  225.                                 int ys1=ys+120;
  226.                                 if(PxInside(ux-4,uy+4,ux+ulx+3,uy+ulx+3,x,y))
  227.                                     return MID;
  228.                             };
  229.                         };
  230.                     };
  231.                 };
  232.             };
  233.     //search for terrain(on water)monsters
  234.     xx=x>>5;
  235.     yy=y>>5;
  236.     for(xx1=xx-1;xx1<=xx+1;xx1++)
  237.         for(int yy1=yy-1;yy1<=yy+1;yy1++){
  238.             word MID=Mops[yy1][xx1];
  239.             if(MID!=0xFFFF){
  240.                 OneObject* OB=Group[MID];
  241.                 if(OB&&OB->NNUM==NI){
  242.                     GetRect(OB,&ux,&uy,&ulx);
  243.                     if(PxInside(ux,uy,ux+ulx-1,uy+ulx-1,x,y))
  244.                         return MID;
  245.                 };
  246.             };
  247.         };
  248.     return 0xFFFF;
  249. };