Drawbmp.cpp
上传用户:s2588lin
上传日期:2007-01-07
资源大小:306k
文件大小:64k
源码类别:

其他智力游戏

开发平台:

Visual C++

  1. #include<afxwin.h>
  2. #include"main.h"
  3. #include<ddraw.h>
  4. #include<dinput.h>
  5. #include<math.h>
  6. #define Surface      LPDIRECTDRAWSURFACE7
  7. #define SurfaceDesc  DDSURFACEDESC2
  8. double dir[6]={ 0, 0.1 ,0.3  ,0.52  ,0.78 ,1.11};
  9. //  Define Global Data   //
  10.     LPDIRECTDRAW7           lpDD;
  11. LPDIRECTINPUT7          DInput;
  12. LPDIRECTINPUTDEVICE2    Keyboard;
  13. LPDIRECTINPUTDEVICE2    Mouse;
  14.     DDSURFACEDESC2          ddsd; 
  15. Surface  Primary;
  16. Surface  PrimaryBack; 
  17.     Surface  BackGround; 
  18.     Surface  BackUp;
  19. Surface  Land; 
  20.     Surface  Circle;
  21. //DDOVERLAYFX           OverlayFX;         // DirectDraw overlay effects struct
  22.     //DDCAPS                DDCaps;            // DirectDraw hardware capabilities struct
  23. //DWORD                 OverlayFlags;
  24. //HRESULT               hRet;
  25.     //HBITMAP               hbitmap; 
  26.     //BITMAP                bmp; 
  27.     //RECT                  rs,rd;
  28. //POINT                 p={0,0}; 
  29. #define INIT_DIRECTDRAW_STRUCT(x) (ZeroMemory(&x, sizeof(x)), x.dwSize=sizeof(x))
  30.             //       Unit Directions Define         //
  31. #define UP    0
  32. #define UR    1
  33. #define RIGHT 2 
  34. #define DR    3
  35. #define DOWN  4
  36. #define DL    5
  37. #define LEFT  6
  38. #define UL    7 
  39.            //        Building Type Define           //
  40. #define PYRAMID   0
  41. #define LAKE      1
  42. #define WONDER    2
  43. #define TOWER     3
  44. #define HOUSE     4
  45.            //        Unit Order Define             //
  46. #define UMOVE       0
  47. #define UATTACK     1
  48. #define UHOLDPLACE  2
  49.           //         UnitGroup Shape               //
  50. #define CONCENTRATE 0
  51. #define SURROUND    1
  52. #define squaresize 20
  53. #define SpaceStartx 0
  54. #define SpaceStarty 0
  55. #define SpaceEndx 799
  56. #define SpaceEndy 479
  57. #define ScrollStep 20
  58. #define BmpWidth 150
  59. #define BmpHeight 100
  60. #define BaseTime 20
  61. #define MapWidth 60
  62. #define MapHeight 60
  63. #define MAXH 13
  64. #define MAXL 13
  65. int      SeekCount=0;
  66. int      MapPixelWidth=squaresize*MapWidth;
  67. int      MapPixelHeight=squaresize*MapHeight;
  68. int      map[MapHeight][MapWidth];
  69. int      xstart=0,ystart=0;
  70. int      CoverSign,UpdateFrame;
  71. int      BuildingCount=0;
  72. int      ChooseSx,ChooseSy,ChooseEx,ChooseEy,OldCx,OldCy;
  73. int      xscroll,yscroll;
  74. int      Mousex=398,Mousey=298;
  75. int      xlimit,ylimit;
  76. bool     TimeIsUp=FALSE;  
  77. bool     ChooseGroup=FALSE;
  78. bool     BeginChoose=FALSE;
  79. //int      pathmapMode;
  80. HWND mWnd;
  81.     
  82. void DrawLittleMap()
  83. {
  84. int i,j;
  85. CBrush cr1,cr2,cr3,cr4;
  86. cr1.CreateSolidBrush(RGB(50,120,70));
  87. cr2.CreateSolidBrush(RGB(210,10,50));
  88. cr3.CreateSolidBrush(RGB(50,10,250));
  89. cr4.CreateSolidBrush(RGB(0,0,20));
  90. int si,sj;
  91. si=680;
  92. sj=479;    
  93. HDC hdc;
  94. CRect re(si,sj,si+120,sj+120);    
  95. int x1,y1,x2,y2;
  96. PrimaryBack->GetDC(&hdc);
  97. FillRect(hdc,re,cr1);
  98. for(j=0;j<=59;j++)
  99. for(i=0;i<=59;i++)
  100. {
  101. x1=si+i*2;
  102. x2=si+i*2+2;
  103. y1=sj+j*2;
  104. y2=sj+j*2+2;
  105. if(map[j][i]==1||map[j][i]==2)     FillRect(hdc,CRect(x1,y1,x2,y2),cr2);
  106. if(map[j][i]==3)     FillRect(hdc,CRect(x1,y1,x2,y2),cr3);
  107. if(map[j][i]==4)     FillRect(hdc,CRect(x1,y1,x2,y2),cr4);
  108. }
  109. PrimaryBack->ReleaseDC(hdc);
  110. DeleteObject(cr1);
  111. DeleteObject(cr2);
  112. DeleteObject(cr3);
  113. }
  114. void DrawRect(HDC hdc,CRect re)
  115. {     
  116. CBrush cr;
  117.     cr.CreateSolidBrush(RGB(0,0,0));
  118.     FillRect(hdc,re,cr);
  119.     cr.DeleteObject();
  120. }
  121. void ShowInt(int x,int y,int num)
  122. {
  123. HDC hdc;
  124. char bb[4];
  125. itoa(num,bb,10);
  126. Primary->GetDC(&hdc);
  127. SetBkMode(hdc,TRANSPARENT);
  128. SetTextColor(hdc,RGB(200,200,100));
  129. DrawRect(hdc,CRect(x,y,x+50,y+20));
  130. TextOut(hdc,x,y,bb,strlen(bb));
  131. Primary->ReleaseDC(hdc);
  132. PrimaryBack->GetDC(&hdc);
  133. SetBkMode(hdc,TRANSPARENT);
  134. DrawRect(hdc,CRect(x,y,x+50,y+20));
  135. SetTextColor(hdc,RGB(200,200,100));
  136. TextOut(hdc,x,y,bb,strlen(bb));
  137. PrimaryBack->ReleaseDC(hdc);
  138. }
  139. BOOL ImageToSurface(Surface lpdds,int ResID)
  140. {
  141.     HBITMAP hbm;
  142.     HDC     hdcImage= NULL;
  143.     HDC     hdcSurf = NULL;
  144.     HRESULT ddrval;
  145.     SurfaceDesc          ddsd; 
  146.     INIT_DIRECTDRAW_STRUCT(ddsd);
  147.     ddsd.dwFlags = DDSD_HEIGHT | DDSD_WIDTH;
  148.     ddrval = lpdds->GetSurfaceDesc(&ddsd);
  149.     if(ddrval!=DD_OK) { MessageBox(NULL,"GetSurface size failed!","error",MB_OK); return FALSE;}  
  150. hbm = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(ResID), IMAGE_BITMAP, ddsd.dwWidth, ddsd.dwHeight, LR_DEFAULTCOLOR|LR_DEFAULTSIZE);//LR_CREATEDIBSECTION);
  151.     hdcImage = CreateCompatibleDC(NULL);
  152.     SelectObject(hdcImage, hbm);
  153.     ddrval = lpdds->GetDC(&hdcSurf);
  154.     if(BitBlt(hdcSurf, 0, 0, ddsd.dwWidth, ddsd.dwHeight, hdcImage, 0, 0, SRCCOPY)==FALSE)
  155. DeleteDC(hdcImage); DeleteObject(hbm); lpdds->ReleaseDC(hdcSurf);
  156. return TRUE;
  157. }
  158. void DrawRect(CRect re)
  159. {     
  160. CBrush cr;
  161.     cr.CreateSolidBrush(RGB(0,0,0));
  162.     HDC hdc;
  163.     Primary->GetDC(&hdc);
  164.     FillRect(hdc,re,cr);
  165.     Primary->ReleaseDC(hdc);
  166.     PrimaryBack->GetDC(&hdc);
  167.     FillRect(hdc,re,cr);
  168.     PrimaryBack->ReleaseDC(hdc);
  169. }
  170. typedef struct tagPathx
  171. {
  172. int cx;
  173. int cy;
  174. struct tagPathx *Next;
  175. struct tagPathx *Last;
  176. }PATHX;
  177. class Object
  178. {
  179. public:
  180. Surface surface; 
  181.     CString name;
  182. int  width,height;
  183. int  PixelWidth,PixelHeight;
  184. int  x,y;
  185. int  RIDnormal;
  186. virtual bool Init();
  187.     virtual void Show() {};
  188. virtual void Destroy();
  189. };
  190. bool Object::Init()
  191. {
  192.     SurfaceDesc          ddsd; 
  193.     PixelWidth=width*squaresize;
  194.     PixelHeight=height*squaresize;
  195.     INIT_DIRECTDRAW_STRUCT(ddsd);
  196. ddsd.dwFlags=DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT;
  197. ddsd.ddsCaps.dwCaps=DDSCAPS_OFFSCREENPLAIN;
  198. ddsd.dwWidth=PixelWidth;
  199. ddsd.dwHeight=PixelHeight;
  200. HRESULT hRet=lpDD->CreateSurface(&ddsd,&surface,NULL);
  201.     if(hRet!=DD_OK) return FALSE;
  202.     DDCOLORKEY KColor;
  203.     KColor.dwColorSpaceLowValue=RGB(0,0,0);
  204.     KColor.dwColorSpaceHighValue=RGB(0,0,0);
  205. surface->SetColorKey(DDCKEY_SRCBLT,&KColor);
  206. return TRUE;
  207. }
  208. void Object::Destroy()
  209. {
  210. if(surface) { surface->Release(); surface=NULL; }
  211. }
  212. //------------------------------------------------------------------------
  213. class BuildingType:public Object
  214. {
  215. public:
  216. int     takeup[MAXH][MAXL];
  217.     int     RIDchoose;
  218. int     RIDanimation[5];
  219.     void    Init(int arraytemp[MAXH][MAXL]);
  220. };
  221. void BuildingType::Init(int arraytemp[MAXH][MAXL])
  222. {
  223. Object::Init();
  224. ImageToSurface(surface,RIDnormal);
  225.     for(int i=0;i<=width-1;i++)
  226.     for(int j=0;j<=height-1;j++)
  227. { takeup[j][i]=arraytemp[j][i]; }
  228. }
  229. class UnitType:public Object
  230. {
  231. public:
  232. int      RIDanimation[5];
  233.     int      RIDDirection[8];
  234.     int      TakeUp[8][16];
  235. int      TimeCount;
  236. int      Time;
  237. int      steplen,stepx,stepy;
  238. Surface  DirectionSurf[8]; 
  239. bool     Init();
  240. };
  241. bool UnitType::Init()
  242. {    
  243. HRESULT hRet;
  244. SurfaceDesc          ddsd; 
  245.     PixelWidth=width*squaresize;
  246. PixelHeight=height*squaresize;
  247. INIT_DIRECTDRAW_STRUCT(ddsd);
  248. ddsd.dwFlags=DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT;
  249. ddsd.ddsCaps.dwCaps=DDSCAPS_SYSTEMMEMORY|DDSCAPS_OFFSCREENPLAIN;
  250. ddsd.dwWidth=PixelWidth;
  251. ddsd.dwHeight=PixelHeight;
  252. TimeCount=0;
  253. for(int i=0;i<=7;i++) 
  254. {
  255.  hRet=lpDD->CreateSurface(&ddsd,&DirectionSurf[i],NULL);
  256.  if(hRet!=DD_OK) return FALSE;
  257.  ImageToSurface(DirectionSurf[i],RIDDirection[i]);
  258. }
  259.    return TRUE;
  260. }
  261. class Building:public Object
  262. {
  263. public:
  264.     int  Breakage;
  265.     int  Type;
  266. BuildingType *m_BType;
  267. virtual bool Init(BuildingType *BType);
  268.     virtual void Show(int x,int y);
  269. };
  270. bool Building::Init(BuildingType *BType)
  271. {
  272.     m_BType=BType;
  273. RIDnormal=m_BType->RIDnormal;
  274. width=m_BType->width;
  275. height=m_BType->height;
  276. Object::Init();
  277. surface->Blt(CRect(0,0,PixelWidth,PixelHeight),BType->surface,CRect(0,0,PixelWidth,PixelHeight),0,NULL);
  278. return TRUE;
  279. }
  280. void Building::Show(int tx,int ty)
  281. {
  282. x=tx,y=ty;
  283. for(int i=0;i<=width-1;i++)
  284. for(int j=0;j<=height-1;j++)
  285. { map[y+j][x+i]=m_BType->takeup[j][i]; }
  286. int x1=xstart+squaresize*x;
  287. int y1=xstart+squaresize*y;
  288. BackGround->Blt(CRect(x1,y1,x1+PixelWidth,y1+PixelHeight),surface,CRect(0,0,PixelWidth,PixelHeight),DDBLT_KEYSRC,NULL); 
  289. }
  290. //----------------------------------------------------------------------------------
  291.    
  292. class BuildingGroup
  293. {
  294. public:
  295. CPtrList BuildingList;
  296. void Recover();
  297. void Destroy();
  298. };
  299. void BuildingGroup::Destroy()
  300. {
  301.     POSITION pos;
  302. for(pos=BuildingList.GetHeadPosition();pos!=NULL;)
  303. {
  304. Building *ttBuild;
  305. ttBuild=(Building*)BuildingList.GetNext(pos);
  306. ttBuild->Destroy();
  307. }
  308.     BuildingList.RemoveAll();
  309. }
  310. BuildingGroup AllBuildings;
  311. //----------------------------------------------------------------------------------
  312. //-------------------------------------------------------------------------------
  313. class Unit:public Object
  314. {
  315. public:
  316.    int          Breakage;
  317.    int          Direction;
  318.    int          RIDchoose;
  319.    int          lastx,lasty,mtx,mty,oldmtx,oldmty,endpx,endpy,xfsign,yfsign;
  320.    int          stepx,stepy,steplen;
  321.    int          Targetx,Targety;
  322.    int          Attackx,Attacky;
  323.    int          MoveSign,StepBegin;
  324.    int          NodeCount;
  325.    int          pathmap[MapHeight][MapWidth];
  326.    PATHX        *Pathx,*PathHead;
  327.    PATHX        *PathRecord[3600];
  328.    UnitType     *m_UType;
  329.    int          Time,TimeCount,SeekInterval,SeekTime;
  330.    int          FireInterval,FireTimeCount;
  331.    int          OrderList[5];
  332.    int          OrderCount;
  333.    bool         BeChosed;
  334.    bool         IsBlock;
  335.    bool         AllowShow;
  336.    bool         Seek(int Tarx,int Tary);
  337.    void         Recover();
  338.    void         Redraw();
  339.    inline int   GetOrder() { return OrderList[OrderCount]; }
  340.    virtual bool Init(UnitType *UType);
  341.    virtual void Show();
  342. };
  343. bool Unit::Init(UnitType *UType)
  344. {  
  345. m_UType=UType;                   //  Set Type
  346. Time=m_UType->Time;
  347. steplen=m_UType->steplen;
  348.     stepx=m_UType->stepx;
  349.     stepy=m_UType->stepy;
  350.     width=m_UType->width;
  351. height=m_UType->height;
  352. PixelWidth=m_UType->PixelWidth;
  353.     PixelHeight=m_UType->PixelHeight;
  354.     HRESULT hRet;                    //  Set Surface
  355. INIT_DIRECTDRAW_STRUCT(ddsd);
  356. ddsd.dwFlags=DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT;
  357. ddsd.ddsCaps.dwCaps=DDSCAPS_OFFSCREENPLAIN;
  358. ddsd.dwWidth=PixelWidth;
  359. ddsd.dwHeight=PixelHeight;
  360. hRet=lpDD->CreateSurface(&ddsd,&surface,NULL);
  361.     if(hRet!=DD_OK) return FALSE;
  362.     DDCOLORKEY KColor;
  363.     KColor.dwColorSpaceLowValue=RGB(0,0,0);
  364.     KColor.dwColorSpaceHighValue=RGB(0,0,0);
  365. surface->SetColorKey(DDCKEY_SRCBLT,&KColor);
  366.     surface->Blt(CRect(0,0,PixelWidth,PixelHeight),m_UType->DirectionSurf[Direction],CRect(0,0,PixelWidth,PixelHeight),0,NULL);
  367. if(hRet!=DD_OK) return FALSE;
  368. MoveSign=0;Pathx=NULL;PathHead=NULL;     // Set Other Information
  369. xfsign=0;yfsign=0;
  370.     lastx=x;lasty=y;
  371. mtx=xstart+x*squaresize;
  372. mty=ystart+y*squaresize;
  373. OrderCount=0;
  374. OrderList[0]=UHOLDPLACE;
  375. SeekInterval=8;
  376. SeekTime=0;
  377. BeChosed=FALSE;
  378. IsBlock=FALSE;
  379. FireTimeCount=0;
  380. FireInterval=10;
  381. for(int j=y;j<=y+height-1;j++)
  382.     for(int i=x;i<=x+width-1 ;i++) map[j][i]=3;
  383.   return TRUE;
  384. }
  385. void Unit::Redraw()
  386. {  
  387.    if(BeChosed)BackGround->Blt(CRect(mtx,mty,mtx+PixelWidth,mty+PixelHeight),Circle,CRect(0,0,PixelWidth,PixelHeight),DDBLT_KEYSRC,NULL);
  388.    BackGround->Blt(CRect(mtx,mty,mtx+PixelWidth,mty+PixelHeight),surface,CRect(0,0,PixelWidth,PixelHeight),DDBLT_KEYSRC,NULL);
  389. }
  390. bool Unit::Seek(int tarx,int tary)
  391. {
  392. int i,j;                          //    Get the path    //
  393. for( i=0;i<=NodeCount-1;i++)
  394. {
  395. if(PathRecord[i]!=NULL) delete PathRecord[i];
  396. }
  397. NodeCount=0;
  398. PATHX *NodeChain,*Rnode;
  399. PathHead=new PATHX;
  400. PathHead->cx=tarx;
  401. PathHead->cy=tary;
  402. PathHead->Next=NULL; 
  403. PathHead->Last=NULL;
  404. Pathx=PathHead;
  405. Rnode=PathHead;
  406. NodeChain=PathHead;
  407. PathRecord[NodeCount]=PathHead;
  408. NodeCount++;
  409. int tx,ty;
  410. int oldtx,oldty;
  411. int stx=x;
  412. int sty=y;
  413. int n=0;
  414. int dire;
  415. for(tx=0;tx<=MapWidth-1;tx++) for(ty=0;ty<=MapHeight-1;ty++) pathmap[ty][tx]=map[ty][tx];
  416. int FindSign=0;
  417. while((NodeChain->cx!=stx||NodeChain->cy!=sty))
  418. {
  419. n++;
  420. if(n>=MapWidth*MapHeight) 
  421. {
  422. //ShowInt(300,560,n/10);
  423.     FindSign=0;
  424. break;
  425. }
  426. oldtx=NodeChain->cx;
  427. oldty=NodeChain->cy;
  428.     for(dire=0;dire<=7;dire++)
  429. switch(dire)
  430. {
  431. case 0: {tx=oldtx-1; ty=oldty  ;  break;}  // go left ?
  432. case 1: {tx=oldtx+1; ty=oldty  ;  break;}  // go right ?
  433.     case 2: {tx=oldtx;   ty=oldty-1;  break;}  // go up ?
  434. case 3: {tx=oldtx;   ty=oldty+1;  break;}  // go down ?*/
  435. case 4: {tx=oldtx-1; ty=oldty-1  ; 
  436. if((map[oldty][tx]==1||map[ty][oldtx]==1))
  437. {   tx=oldtx-1; ty=oldty  ; }
  438. break;
  439. } // go left ?
  440. case 5: {tx=oldtx+1; ty=oldty+1  ; 
  441. if((map[oldty][tx]==1||map[ty][oldtx]==1))
  442. {   tx=oldtx+1; ty=oldty ; } 
  443.         break;
  444. } // go right ?
  445.     case 6: {tx=oldtx+1; ty=oldty-1; 
  446. if((map[oldty][tx]==1||map[ty][oldtx]==1))
  447. { tx=oldtx+1; ty=oldty  ;}
  448. break;
  449. }
  450. case 7: {tx=oldtx-1;ty=oldty+1; 
  451. if((map[oldty][tx]==1||map[ty][oldtx]==1))
  452. {   tx=oldtx-1; ty=oldty  ; }
  453.    break;
  454. }
  455. };
  456. if(tx>=0&&(tx+width-1)<=(MapWidth-1)&&ty>=0&&(ty+height-1)<=(MapHeight-1))
  457. {
  458.   bool MapCannotMove=FALSE;
  459. bool FindDest=FALSE;
  460. for(j=ty;j<=ty+height-1;j++)
  461. for(i=tx;i<=tx+width-1;i++)
  462. {
  463.         if(map[j][i]==1||map[j][i]==3||map[j][i]==4) MapCannotMove=TRUE; 
  464.        }         
  465.          if( (!MapCannotMove) && (pathmap[ty][tx]!=1) ) 
  466.   {
  467.   pathmap[ty][tx]=1;
  468.           PATHX *NewNode; NewNode=new PATHX;
  469.           NewNode->cx=tx; NewNode->cy=ty;
  470.           NewNode->Last=NodeChain;
  471.           NewNode->Next=NULL;
  472.           Rnode->Next=NewNode;
  473.           Rnode=Rnode->Next;
  474.           PathRecord[NodeCount]=NewNode;
  475.   NodeCount++;
  476.   if(tx==x&&ty==y) 
  477.   {  
  478.  Pathx=NewNode; MoveSign=1; 
  479.     lastx=stx;
  480.      lasty=sty;
  481.      FindSign=1; 
  482.  Targetx=tarx;Targety=tary;
  483.      IsBlock=FALSE;
  484.  break;
  485.   }
  486. }
  487. }
  488. }
  489. if(NodeChain->Next!=NULL) NodeChain=NodeChain->Next;
  490. }
  491. if(FindSign==0) 
  492.     for(i=0;i<=NodeCount-1;i++) { if(PathRecord[i]!=NULL) delete PathRecord[i]; }
  493.     NodeCount=0;
  494. PathHead=new PATHX;
  495. PathHead->cx=x;
  496. PathHead->cy=y;
  497. PathHead->Last=NULL; 
  498. PathHead->Next=NULL; 
  499. Pathx=PathHead;
  500.     PathRecord[NodeCount]=PathHead;
  501.     NodeCount++;
  502. StepBegin=0;
  503. MoveSign=1;
  504. Targetx=tarx;Targety=tary;
  505.     IsBlock=TRUE;
  506. return FALSE;
  507. }
  508. return TRUE;
  509. }
  510. class UnitGroup
  511. {
  512. public:
  513.    int       MemberCount;
  514.    CPtrList  UnitList;
  515.    bool      CanStop(int xt,int yt,int uw,int uh,POSITION pos);
  516.    void      MoveTo(int tarx,int tary,int shape);
  517.    void      Recover();
  518.    void      Show();
  519.    void      Destroy();
  520. };
  521. UnitGroup AllUnits,ChosedGroup;
  522. void UnitGroup::Show()
  523. {
  524. POSITION posx;
  525. for(posx=UnitList.GetHeadPosition();posx!=NULL;)
  526. {
  527.     Unit *ttUnit;
  528. ttUnit=(Unit*)UnitList.GetNext(posx);
  529. ttUnit->Show();
  530. }
  531. }
  532. void UnitGroup::Recover()
  533. {
  534. POSITION pos;
  535. for(pos=UnitList.GetHeadPosition();pos!=NULL;)
  536. {
  537.     Unit *ttUnit;
  538. ttUnit=(Unit*)UnitList.GetNext(pos);
  539. ttUnit->Recover();
  540. }
  541. }
  542. bool UnitGroup::CanStop(int xt,int yt,int uw,int uh,POSITION pos)
  543. {
  544.      
  545.    if(xt<0||xt>MapWidth-uw||yt<0||yt>MapHeight-uh) return FALSE;
  546.  int j,i,uy,ux; 
  547.  bool CannotStop=FALSE;
  548.      for(j=yt;j<=yt+uh-1;j++) 
  549.      for(i=xt;i<=xt+uw-1;i++)
  550.      if(!map[j][i]==0) CannotStop=TRUE;
  551.      Unit *ttUnit;
  552.  if(!CannotStop) 
  553.  {
  554.      ttUnit=(Unit*)UnitList.GetNext(pos); 
  555.  uy=ttUnit->y;ux=ttUnit->x;
  556.      for(j=uy;j<=uy+uh-1;j++) for(i=ux;i<=ux+uw-1;i++) {if(map[j][i]==3) map[j][i]=0; }
  557.      ttUnit->Seek(xt,yt);
  558.  ttUnit->OrderCount=0;
  559.  ttUnit->OrderList[0]=UMOVE;
  560.  ttUnit->OrderList[1]=UHOLDPLACE;
  561.  return TRUE; 
  562.  }  
  563.      return FALSE;
  564. }
  565. void UnitGroup::MoveTo(int tarx1,int tary1,int shape)
  566. {
  567.      POSITION pos;
  568.  pos = UnitList.GetHeadPosition();
  569.  int   i=0,j=0;
  570.  int   radio=0;
  571.  int   uw,uh; 
  572.      int   xt=tarx1,yt=tary1,n;
  573.  int   ux,uy;
  574.  bool  FindSpace=FALSE;
  575.  bool  FindSign=FALSE;
  576.  Unit  *ttUnit;
  577.  
  578.  switch(shape)
  579.  { 
  580.  case CONCENTRATE: 
  581.  {
  582.  ttUnit=(Unit*)UnitList.GetAt(pos); 
  583.          uw=ttUnit->width; uh=ttUnit->height;  
  584.          if(CanStop(xt,yt,uw,uh,pos)) ttUnit=(Unit*)UnitList.GetNext(pos); 
  585.          ux=ttUnit->x; uy=ttUnit->y;
  586.          while(pos!=NULL)
  587.  {
  588.       for(n=0;n<=radio;n++)
  589.   {
  590.        xt+=uw;    
  591.            ttUnit=(Unit*)UnitList.GetAt(pos); 
  592.            uw=ttUnit->width; uh=ttUnit->height;  
  593.            if(CanStop(xt,yt,uw,uh,pos)) ttUnit=(Unit*)UnitList.GetNext(pos); 
  594.            if(pos==NULL) return;
  595.   }
  596.           for(n=0;n<=radio;n++)
  597.   {
  598.            yt+=uh;    
  599.            ttUnit=(Unit*)UnitList.GetAt(pos); 
  600.            uw=ttUnit->width; uh=ttUnit->height;  
  601.            if(CanStop(xt,yt,uw,uh,pos)) ttUnit=(Unit*)UnitList.GetNext(pos); 
  602.            if(pos==NULL) return;
  603.   }
  604.           for(n=0;n<=radio+1;n++)
  605.   {
  606.            xt-=uw;    
  607.            ttUnit=(Unit*)UnitList.GetAt(pos); 
  608.            uw=ttUnit->width; uh=ttUnit->height;  
  609.            if(CanStop(xt,yt,uw,uh,pos)) ttUnit=(Unit*)UnitList.GetNext(pos); 
  610.            if(pos==NULL) return;
  611.   }
  612.           for(n=0;n<=radio+1;n++)
  613.   {
  614.            yt-=uw;    
  615.            ttUnit=(Unit*)UnitList.GetAt(pos); 
  616.            uw=ttUnit->width; uh=ttUnit->height;
  617.            if(CanStop(xt,yt,uw,uh,pos)) ttUnit=(Unit*)UnitList.GetNext(pos); 
  618.            if(pos==NULL) return;
  619.   }
  620.           radio+=2;
  621.  }
  622.   break;
  623.  }
  624.      case SURROUND:
  625.  {
  626.         int r;
  627.     int targetx,targety;
  628. while(pos!=NULL)
  629.  {
  630.           ttUnit=(Unit*)UnitList.GetNext(pos); 
  631.               ux=ttUnit->x; uy=ttUnit->y;
  632.   uw=ttUnit->width; uh=ttUnit->height;
  633.   r=(int)sqrt((ux-xt)*(ux-xt)+(uy-yt)*(uy-yt));
  634.   targetx=xt-(int)(9*(xt-ux)/r);
  635.   targety=yt-(int)(9*(yt-uy)/r);
  636.   for(j=uy;j<=uy+uh-1;j++) for(i=ux;i<=ux+uw-1;i++) {if(map[j][i]==3) map[j][i]=0; }
  637.           if(!ttUnit->Seek(targetx,targety))
  638.   {
  639.   for(j=uy;j<=uy+uh-1;j++) for(i=ux;i<=ux+uw-1;i++) {if(map[j][i]==0) map[j][i]=3; }
  640.   }
  641.   ttUnit->Attackx=xt;
  642.   ttUnit->Attacky=yt;
  643.   ttUnit->OrderCount=0;
  644.   ttUnit->OrderList[0]=UMOVE;
  645.   ttUnit->OrderList[1]=UATTACK;
  646.   ttUnit->OrderList[2]=UHOLDPLACE;
  647.  }
  648.    break;
  649.  }
  650.  };
  651. }
  652. void UnitGroup::Destroy()
  653. {
  654. POSITION pos;
  655. for(pos=UnitList.GetHeadPosition();pos!=NULL;)
  656. {
  657.     Unit *ttUnit;
  658. ttUnit=(Unit*)UnitList.GetNext(pos);
  659. ttUnit->Destroy();
  660. }
  661. UnitList.RemoveAll();
  662. }
  663. void Unit::Recover()
  664. {
  665.     if(MoveSign==1)
  666.    {
  667. oldmtx=mtx;oldmty=mty;
  668.     BackGround->Blt(CRect(oldmtx,oldmty,oldmtx+PixelWidth,oldmty+PixelHeight),BackUp,CRect(oldmtx,oldmty,oldmtx+PixelWidth,oldmty+PixelHeight),0,NULL);
  669.     int mx=oldmtx/squaresize;
  670.     int my=oldmty/squaresize;
  671.     int xt,yt;
  672.     Unit *ttUnit;
  673.     POSITION pos;
  674.     CRect rectsrc(mx,my,mx+width+1,my+height+1);
  675.     for(pos=AllUnits.UnitList.GetHeadPosition();pos!=NULL;)
  676.     {
  677.    ttUnit=(Unit*)AllUnits.UnitList.GetNext(pos);
  678.        xt=ttUnit->x; yt=ttUnit->y;
  679.    if((!(xt==x&&yt==y))&&ttUnit->MoveSign==0&&map[yt][xt]!=2)
  680.    {
  681.    CRect temprect;
  682.    if(IntersectRect(temprect,rectsrc,CRect(xt,yt,xt+width+1,yt+height+1)))
  683.     ttUnit->Redraw();
  684.    }
  685.     }
  686.    }
  687. }
  688. //-----------------------------------------------------//
  689. //               Signal Define And Functions           //
  690. //-----------------------------------------------------//
  691. class Signal:public Object
  692. {
  693. public:
  694. int   RIDanimation[3];
  695.     int   CurrentFrame;
  696. int   Time;
  697. int   TimeCount;
  698. bool  ShowBegin;
  699. Surface MoveSignal[3];
  700. void         Recover();
  701. virtual bool Init();
  702.     virtual void Show();
  703.     virtual void Destroy();
  704. };
  705. Signal   MSignal;
  706. bool Signal::Init()
  707. {
  708.     PixelWidth=width*squaresize;
  709. PixelHeight=height*squaresize;
  710. DDCOLORKEY KColor;
  711.     KColor.dwColorSpaceLowValue=RGB(0,0,0);
  712.     KColor.dwColorSpaceHighValue=RGB(0,0,0);
  713. INIT_DIRECTDRAW_STRUCT(ddsd);
  714. ddsd.dwFlags=DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT;
  715. ddsd.ddsCaps.dwCaps=DDSCAPS_OFFSCREENPLAIN;
  716. ddsd.dwWidth=PixelWidth;
  717. ddsd.dwHeight=PixelHeight;
  718. HRESULT hRet;
  719.     hRet=lpDD->CreateSurface(&ddsd,&surface,NULL);
  720.     surface->SetColorKey(DDCKEY_SRCBLT,&KColor);
  721.     for(int i=0;i<=2;i++)
  722. {
  723. hRet=lpDD->CreateSurface(&ddsd,&MoveSignal[i],NULL);
  724.         ImageToSurface(MoveSignal[i],RIDanimation[i]);
  725.    }
  726.    if(hRet!=DD_OK) return FALSE;
  727.    ShowBegin=FALSE;
  728.    CurrentFrame=0;
  729.    return TRUE;
  730. }
  731. void Signal::Recover()
  732. {
  733.  if(CurrentFrame==3) 
  734.  {
  735.     int x1,y1,x2,y2;
  736.     int uw,uh;
  737. x1=xstart+x;y1=ystart+y;
  738.     x2=x1+PixelWidth;y2=y1+PixelHeight;
  739. CurrentFrame=0;ShowBegin=FALSE; 
  740.     BackGround->Blt(CRect(x1,y1,x2,y2),BackUp,CRect(x1,y1,x2,y2),0,NULL); 
  741.     int xt,yt;
  742.     Unit *ttUnit;
  743.     POSITION posU;
  744.     int xr1,yr1,xr2,yr2;
  745. xr1=x1/squaresize;
  746. xr2=x2/squaresize;
  747. yr1=y1/squaresize;
  748. yr2=y2/squaresize;
  749. CRect temprect;
  750. for(posU=AllUnits.UnitList.GetHeadPosition();posU!=NULL;)
  751.     {
  752.    ttUnit=(Unit*)AllUnits.UnitList.GetNext(posU);
  753.        uw=ttUnit->width;
  754.    uh=ttUnit->height;
  755.    xt=ttUnit->x;
  756.    yt=ttUnit->y;
  757.    if(IntersectRect(temprect,CRect(xr1-1,yr1-1,xr2+1,yr2+1),CRect(xt,yt,xt+uw,yt+uh)))
  758.        {
  759.    bool CannotRedraw=FALSE;
  760.    for(int j=yr1;j<=yr2;j++)
  761.            for(int i=xr1;i<=xr2;i++)
  762.    { if(map[j][i]==2) CannotRedraw=TRUE; }
  763.        if(!CannotRedraw) ttUnit->Redraw();
  764.    }
  765. }
  766.  }
  767. }
  768. void Signal::Show()
  769. {
  770.  TimeCount++;
  771.  if(TimeCount==Time)
  772.  {
  773.  TimeCount=0;
  774.  int x1,y1,x2,y2,w,h;
  775.  w=width*squaresize;h=height*squaresize;
  776.  x1=xstart+x;y1=ystart+y;
  777.  x2=x1+PixelWidth;y2=y1+PixelHeight;
  778.  
  779.  if(ShowBegin)
  780.  {
  781.  surface->Blt(CRect(0,0,w,h),MoveSignal[CurrentFrame],CRect(0,0,w,h),0,NULL);
  782.      BackGround->Blt(CRect(x1,y1,x2,y2),surface,CRect(0,0,w,h),DDBLT_KEYSRC,NULL); 
  783.      CurrentFrame++;
  784.  }
  785.  }
  786. }
  787. void Signal::Destroy()
  788. {
  789. if(surface) surface->Release(); surface=NULL;
  790. for(int i=0;i<=2;i++) 
  791. {
  792. if(MoveSignal[i]) {MoveSignal[i]->Release();MoveSignal[i]=NULL; }
  793. }
  794. }
  795. void BuildingGroup::Recover()
  796. {
  797. POSITION posB;
  798. POSITION posU;
  799. Building *tempB;
  800. Unit     *tempU;
  801. bool     FindCover;
  802. int x1,y1,x2,y2,xtl,ytl,xtn,ytn;
  803. int i,j,uw,uh;
  804.  for(posB=BuildingList.GetHeadPosition();posB!=NULL;)
  805.  {
  806.     FindCover=FALSE;
  807. tempB=(Building*)BuildingList.GetNext(posB);  
  808.     x1=tempB->x;y1=tempB->y;x2=x1+tempB->width;y2=y1+tempB->height;
  809.     CRect rectsrc(x1,y1,x2,y2);
  810. CRect temprect;
  811. for(posU=AllUnits.UnitList.GetHeadPosition();posU!=NULL;)
  812.     {
  813.   tempU=(Unit*)AllUnits.UnitList.GetNext(posU);
  814.   xtl=tempU->lastx; ytl=tempU->lasty;
  815.   xtn=tempU->x    ; ytn=tempU->y;
  816.   if(tempU->MoveSign==1)
  817.   {
  818.   uw=tempU->width;
  819.   uh=tempU->height;
  820.   if(IntersectRect(temprect,rectsrc,CRect(xtl,ytl,xtl+uw,ytl+uh)))
  821.           { 
  822.       for(j=temprect.top;j<=temprect.bottom;j++)
  823.       for(i=temprect.left;i<=temprect.right;i++)
  824.           if(map[j][i]==2) {FindCover=TRUE; break; }
  825.   }
  826.   if(IntersectRect(temprect,rectsrc,CRect(xtn,ytn,xtn+uw,ytn+uh)))
  827.           { 
  828.       for(j=temprect.top;j<=temprect.bottom;j++)
  829.       for(i=temprect.left;i<=temprect.right;i++)
  830.   if(map[j][i]==2) {FindCover=TRUE; break; }
  831.   }
  832.   }
  833. }
  834.   if(FindCover) tempB->Show(x1,y1);
  835.  }
  836. }
  837. class WeaponType:public Object
  838. {
  839. public:
  840. int      RIDanimation[5];
  841.     int      RIDDirection[20];
  842.     int      RIDExplosion[14];
  843. int      Time;
  844.     int      DirectionCount;
  845. float    steplen;
  846.     Surface  DirectionSurf[20]; 
  847. Surface  Explosion[14];
  848. bool     Init();
  849. };
  850. bool WeaponType::Init()
  851. {    
  852. HRESULT hRet;
  853. SurfaceDesc          ddsd; 
  854.     PixelWidth=width*squaresize;
  855. PixelHeight=height*squaresize;
  856. INIT_DIRECTDRAW_STRUCT(ddsd);
  857. ddsd.dwFlags=DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT;
  858. ddsd.ddsCaps.dwCaps=DDSCAPS_SYSTEMMEMORY|DDSCAPS_OFFSCREENPLAIN;
  859. ddsd.dwWidth=PixelWidth;
  860. ddsd.dwHeight=PixelHeight;
  861. DDCOLORKEY KColor;
  862.     KColor.dwColorSpaceLowValue=RGB(0,0,0);
  863.     KColor.dwColorSpaceHighValue=RGB(0,0,0);
  864. int i;
  865. for(i=0;i<=DirectionCount-1;i++) 
  866. {
  867.  hRet=lpDD->CreateSurface(&ddsd,&DirectionSurf[i],NULL);
  868.  DirectionSurf[i]->SetColorKey(DDCKEY_SRCBLT,&KColor);
  869.      if(hRet!=DD_OK) return FALSE;
  870.  ImageToSurface(DirectionSurf[i],RIDDirection[i]);
  871. }
  872.    for(i=0;i<=13;i++) 
  873. {
  874.  hRet=lpDD->CreateSurface(&ddsd,&Explosion[i],NULL);
  875.  Explosion[i]->SetColorKey(DDCKEY_SRCBLT,&KColor);
  876.      if(hRet!=DD_OK) return FALSE;
  877.  ImageToSurface(Explosion[i],RIDExplosion[i]);
  878. }
  879.    return TRUE;
  880. }
  881. class Weapon:public Object
  882. {
  883. public:
  884.    int          Direction;
  885.    int          xfsign,yfsign;
  886.    int          Targetx,Targety;
  887.    int          Time,TimeCount;
  888.    float        oldx,oldy,newx,newy,endx,endy;
  889.    float        stepx,stepy,steplen;
  890.    bool         AllowShow;
  891.    bool         MoveSign;
  892.    bool         ExplosionBegin;
  893.    void         Recover();
  894.    void         Redraw();
  895.    int          Explo_FrameCount;
  896.    WeaponType   *m_WType;
  897.    virtual bool Init(WeaponType *WType,int sx,int sy,int Ax,int Ay);
  898.    virtual void Show();
  899. };
  900. bool Weapon::Init(WeaponType *WType,int sx,int sy,int Ax,int Ay)
  901. {  
  902. m_WType=WType;
  903. Time=m_WType->Time;
  904. TimeCount=0;
  905. width=m_WType->width;
  906. height=m_WType->height;
  907. steplen=m_WType->steplen;
  908. PixelWidth=m_WType->PixelWidth;
  909.     PixelHeight=m_WType->PixelHeight;
  910.     HRESULT hRet;
  911. INIT_DIRECTDRAW_STRUCT(ddsd);
  912. ddsd.dwFlags=DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT;
  913. ddsd.ddsCaps.dwCaps=DDSCAPS_OFFSCREENPLAIN;
  914. ddsd.dwWidth=PixelWidth;
  915. ddsd.dwHeight=PixelHeight;
  916. hRet=lpDD->CreateSurface(&ddsd,&surface,NULL);
  917.     if(hRet!=DD_OK) return FALSE;
  918.     DDCOLORKEY KColor;
  919.     KColor.dwColorSpaceLowValue=RGB(0,0,0);
  920.     KColor.dwColorSpaceHighValue=RGB(0,0,0);
  921. surface->SetColorKey(DDCKEY_SRCBLT,&KColor);
  922.     newx=(float)sx*squaresize;
  923.     newy=(float)sy*squaresize;
  924.     endx=(float)Ax*squaresize;
  925.     endy=(float)Ay*squaresize;
  926. float disx=fabs(endx-newx);
  927. float disy=fabs(endy-newy);
  928. float dis=_hypot(disx,disy);
  929. stepx=0;stepy=0;
  930. stepx=steplen*disx/dis; stepy=steplen*disy/dis;
  931. if(endx<newx) { stepx=-stepx; }
  932.     if(endy<newy) { stepy=-stepy; }
  933. xfsign=0;yfsign=0;
  934. //               Count         Directions
  935. float rx=8;
  936. float dd=fabs((Ay-sy)/rx);
  937. for(int i=0;i<=5;i++)
  938. {
  939.   if(dd>=dir[i]&&dd<=dir[i+1])
  940.       {
  941.  if(Ax>=sx&&Ay>sy) { Direction=5+i; break; }
  942.  if(Ax>=sx&&Ay<sy) { Direction=6-i;   break; }
  943.  
  944.  if(Ax<=sx&&Ay<sy) { Direction=14+i;   break; }
  945.  if(Ax<=sx&&Ay>sy) { Direction=15-i;   break; }
  946.  //if(Ax<=sx&&Ay<sy) { Direction=5-i;   break; }
  947.       }
  948. }
  949. if(Ax==sx)
  950. {
  951.   if(stepy<0) Direction=0;
  952.   if(stepy>0) Direction=10;
  953. }
  954. if(Ay==sy)
  955. {
  956.   if(stepx<0) Direction=15;
  957.   if(stepx>0) Direction=5;
  958. }
  959.  
  960.     if(Direction<0||Direction>19) Direction=0;
  961. //-------------------------------------------//
  962. surface->Blt(CRect(0,0,PixelWidth,PixelHeight),m_WType->DirectionSurf[Direction],CRect(0,0,PixelWidth,PixelHeight),0,NULL);
  963. if(hRet!=DD_OK) return FALSE;
  964. MoveSign=TRUE;
  965. oldx=newx;oldy=newy;
  966. Explo_FrameCount=0;
  967. ExplosionBegin=FALSE;
  968. return TRUE;
  969. }
  970. void Weapon::Show()
  971. {
  972.    
  973.  if(ExplosionBegin)
  974.  {
  975.    BackGround->Blt(CRect(newx,newy,newx+PixelWidth,newy+PixelHeight),m_WType->Explosion[Explo_FrameCount],CRect(0,0,PixelWidth,PixelHeight),DDBLT_KEYSRC,NULL);
  976.    Explo_FrameCount++;
  977.    if(Explo_FrameCount==13) ExplosionBegin=FALSE;
  978.  }
  979.  
  980. if(MoveSign)             //       It is Moving..
  981.    {
  982.    if(xfsign==0) newx=newx+stepx;
  983.    if(yfsign==0) newy=newy+stepy;
  984.    if( ( (stepx>=0) && (newx>=endx)) || ( (stepx<=0) && (newx<=endx) )) xfsign=1; 
  985.    if( ( (stepy>=0) &&( newy>=endy)) || ( (stepy<=0) && (newy<=endy) )) yfsign=1; 
  986.    if(xfsign==1&&yfsign==1) 
  987.  { 
  988.   xfsign=0;yfsign=0;
  989.   ExplosionBegin=TRUE;
  990.   MoveSign=FALSE; 
  991.       }
  992.   else
  993.  { 
  994.   BackGround->Blt(CRect(newx,newy,newx+PixelWidth,newy+PixelHeight),surface,CRect(0,0,PixelWidth,PixelHeight),DDBLT_KEYSRC,NULL);
  995.      }
  996.    }        
  997. }
  998. void Weapon::Recover()
  999. {
  1000.    
  1001. if(MoveSign||ExplosionBegin)
  1002.     {
  1003.     oldx=newx;oldy=newy;
  1004.     BackGround->Blt(CRect(oldx,oldy,oldx+PixelWidth,oldy+PixelHeight),BackUp,CRect(oldx,oldy,oldx+PixelWidth,oldy+PixelHeight),0,NULL);
  1005.     }
  1006.     
  1007. int mx=oldx/squaresize;
  1008.     int my=oldy/squaresize;
  1009.     int xt,yt;
  1010.     int uw,uh;
  1011. Unit *ttUnit;
  1012.     POSITION pos;
  1013.     CRect rectsrc(mx,my,mx+width+1,my+height+1);
  1014.     for(pos=AllUnits.UnitList.GetHeadPosition();pos!=NULL;)
  1015.     {
  1016.    ttUnit=(Unit*)AllUnits.UnitList.GetNext(pos);
  1017.        xt=ttUnit->x; yt=ttUnit->y;
  1018.    uw=ttUnit->width;uh=ttUnit->height;
  1019.    if((!(xt==x&&yt==y))&&ttUnit->MoveSign==0&&map[yt][xt]!=2)
  1020.    {
  1021.    CRect temprect;
  1022.    if(IntersectRect(temprect,rectsrc,CRect(xt,yt,xt+uw+1,yt+uh+1)))
  1023.     ttUnit->Redraw();
  1024.    }
  1025.     }
  1026.  }
  1027. class WeaponGroup
  1028. {
  1029. public:
  1030.    int       MemberCount;
  1031.    CPtrList  WeaponList;
  1032.    void      Recover();
  1033.    void      Show();
  1034.    void      Destroy();
  1035. };
  1036. void WeaponGroup::Show()
  1037. {
  1038. POSITION posW,pos2;
  1039. Weapon *ttWeapon;
  1040. for(posW=WeaponList.GetHeadPosition();(pos2=posW)!=NULL;)
  1041. {
  1042.   ttWeapon=(Weapon*)WeaponList.GetNext(posW);
  1043.   ttWeapon->Show();
  1044.   if( (!ttWeapon->MoveSign) && (!ttWeapon->ExplosionBegin)) 
  1045.   {
  1046.   ttWeapon->Recover();
  1047.   WeaponList.RemoveAt(pos2);
  1048.       delete ttWeapon;
  1049.   }
  1050. }
  1051. }
  1052. void WeaponGroup::Recover()
  1053. {
  1054. POSITION posW;
  1055. Weapon *ttWeapon;
  1056. for(posW=WeaponList.GetHeadPosition();posW!=NULL;)
  1057. {
  1058.   ttWeapon=(Weapon*)WeaponList.GetNext(posW);
  1059.   ttWeapon->Recover();
  1060. }
  1061. }
  1062. WeaponGroup AllWeapons;
  1063. WeaponType  *Missle;
  1064. void Unit::Show()
  1065. {
  1066.    
  1067.    int CurrentOrder=GetOrder();
  1068.    switch(CurrentOrder)
  1069.    {
  1070.          case UHOLDPLACE:
  1071.  {
  1072.           break;
  1073.  }
  1074.          case UMOVE:
  1075.    {
  1076.   int i,j;
  1077.               if(StepBegin==1) // from one square to another
  1078.   {
  1079.                if(xfsign==0) mtx=mtx+stepx;
  1080.                if(yfsign==0) mty=mty+stepy;
  1081.                if((stepx>0&&mtx>=endpx)||(stepx<0&&mtx<=endpx)) {oldmtx=endpx;mtx=endpx;xfsign=1; }
  1082.                if((stepy>0&&mty>=endpy)||(stepy<0&&mty<=endpy)) {oldmty=endpy;mty=endpy;yfsign=1; }
  1083.                if(xfsign==1&&yfsign==1) { xfsign=0;yfsign=0;StepBegin=0;oldmtx=-1; }
  1084.            else 
  1085.    { 
  1086.    
  1087.    if(BeChosed)BackGround->Blt(CRect(mtx,mty,mtx+PixelWidth,mty+PixelHeight),Circle,CRect(0,0,PixelWidth,PixelHeight),DDBLT_KEYSRC,NULL);
  1088.    BackGround->Blt(CRect(mtx,mty,mtx+PixelWidth,mty+PixelHeight),surface,CRect(0,0,PixelWidth,PixelHeight),DDBLT_KEYSRC,NULL);
  1089.    }
  1090.   }        
  1091.               if(Pathx!=NULL&&MoveSign==1&&StepBegin==0)
  1092.   {
  1093.             lastx=x;lasty=y;  
  1094.               if(Pathx->cx!=Targetx||Pathx->cy!=Targety) 
  1095.   {
  1096.  
  1097.               for(j=lasty;j<=lasty+height-1;j++)
  1098.                   for(i=lastx;i<=lastx+width-1;i++)
  1099.                   if(map[j][i]==3) map[j][i]=0; 
  1100.       PATHX *ttPath;
  1101.           ttPath=Pathx->Last;
  1102.           bool SeekAgain=FALSE;
  1103.           if(ttPath!=NULL)
  1104.   {
  1105.         int xt=ttPath->cx;
  1106.             int yt=ttPath->cy;
  1107.           for(j=yt;j<=yt+height-1;j++)
  1108.                     for(i=xt;i<=xt+width-1;i++)
  1109. { if(map[j][i]==3||map[j][i]==1) { SeekAgain=TRUE; break; } }
  1110.   }
  1111.           if(IsBlock||SeekAgain) 
  1112.  {
  1113.         if(!IsBlock) IsBlock=TRUE;
  1114.         StepBegin=0;
  1115.                     SeekCount++;
  1116.         if(SeekCount==SeekInterval)
  1117. {
  1118.          SeekCount=0;
  1119.  SeekTime++;
  1120.  for(j=y;j<=y+height-1;j++)
  1121.                      for(i=x;i<=x+width-1;i++)
  1122.              if(map[j][i]==3) map[j][i]=0;
  1123.      if(Seek(Targetx,Targety)) IsBlock=FALSE;
  1124.  
  1125.  if(OrderList[OrderCount+1]==UATTACK)
  1126.  {
  1127.      MoveSign=0; SeekTime=0;
  1128.   int r=(int)sqrt((x-Attackx)*(x-Attackx)+(y-Attacky)*(y-Attacky));
  1129.                           if(r<=9) OrderCount++; 
  1130. }
  1131.  
  1132.  
  1133.  
  1134.  if(SeekTime==12)
  1135.   { 
  1136.   MoveSign=0; SeekTime=0; 
  1137.   }
  1138. }
  1139.             for(j=y;j<=y+height-1;j++)
  1140.                     for(i=x;i<=x+width-1;i++)
  1141. if(map[j][i]==0) map[j][i]=3; 
  1142.    if(BeChosed)BackGround->Blt(CRect(mtx,mty,mtx+PixelWidth,mty+PixelHeight),Circle,CRect(0,0,PixelWidth,PixelHeight),DDBLT_KEYSRC,NULL);
  1143. BackGround->Blt(CRect(mtx,mty,mtx+PixelWidth,mty+PixelHeight),surface,CRect(0,0,PixelWidth,PixelHeight),DDBLT_KEYSRC,NULL);
  1144.                    return;
  1145.  }
  1146.    
  1147.   Pathx=Pathx->Last;
  1148.           x=Pathx->cx;
  1149.               y=Pathx->cy;
  1150.           for(j=y;j<=y+height-1;j++)
  1151.           for(i=x;i<=x+width-1;i++)
  1152.           if(map[j][i]==0) map[j][i]=3; 
  1153.           endpx  =xstart+x*squaresize;
  1154.                   endpy  =ystart+y*squaresize;
  1155.                mtx=xstart+lastx*squaresize;
  1156.                   mty=ystart+lasty*squaresize;
  1157.                   if(endpx>mtx) {stepx=steplen;  Direction=RIGHT;}
  1158.                   if(endpx<mtx) {stepx=-steplen; Direction=LEFT; }
  1159.                   if(endpy>mty) {stepy=steplen ; Direction=DOWN; }
  1160.           if(endpy<mty) {stepy=-steplen; Direction=UP;   }
  1161.           if(endpx>mtx&&endpy>mty)       Direction=DR; 
  1162.           if(endpx>mtx&&endpy<mty)       Direction=UR;
  1163.           if(endpx<mtx&&endpy<mty)       Direction=UL;
  1164.           if(endpx<mtx&&endpy>mty)       Direction=DL;
  1165.           surface->Blt(CRect(0,0,PixelWidth,PixelHeight),m_UType->DirectionSurf[Direction],CRect(0,0,PixelWidth,PixelHeight),0,NULL);
  1166.   if(BeChosed)BackGround->Blt(CRect(mtx,mty,mtx+PixelWidth,mty+PixelHeight),Circle,CRect(0,0,PixelWidth,PixelHeight),DDBLT_KEYSRC,NULL);
  1167.           BackGround->Blt(CRect(mtx,mty,mtx+PixelWidth,mty+PixelHeight),surface,CRect(0,0,PixelWidth,PixelHeight),DDBLT_KEYSRC,NULL);
  1168.                   StepBegin=1;
  1169.       for(j=y;j<=y+height-1;j++)
  1170.           for(i=x;i<=x+width-1;i++)
  1171.           if(map[j][i]==0) map[j][i]=3; 
  1172.   }
  1173.      else
  1174.  {
  1175.                 if(BeChosed)BackGround->Blt(CRect(mtx,mty,mtx+PixelWidth,mty+PixelHeight),Circle,CRect(0,0,PixelWidth,PixelHeight),DDBLT_KEYSRC,NULL);
  1176.                 BackGround->Blt(CRect(mtx,mty,mtx+PixelWidth,mty+PixelHeight),surface,CRect(0,0,PixelWidth,PixelHeight),DDBLT_KEYSRC,NULL);
  1177.                 AllBuildings.Recover();
  1178.         OrderCount++;
  1179. StepBegin=0;
  1180.         MoveSign=0;
  1181.                 for(j=y;j<=y+height-1;j++)
  1182.         for(i=x;i<=x+width-1;i++)
  1183.         if(map[j][i]==0) map[j][i]=3; 
  1184.  }
  1185.   }
  1186.   break;
  1187.  }        //         UMOVE END
  1188.    case UATTACK:
  1189.    {
  1190.        if(FireTimeCount==FireInterval)
  1191.    {
  1192.                  Weapon *ttWeapon;
  1193.                  ttWeapon=new Weapon;
  1194.                  ttWeapon->Init(Missle,x+1,y+1,Attackx,Attacky);
  1195.                  AllWeapons.WeaponList.AddTail(ttWeapon);
  1196.                  FireTimeCount=0;  
  1197.    } 
  1198.    FireTimeCount++;
  1199.    break;
  1200.    }          //         UATTACK END
  1201. };                //         SWITCH  END
  1202. }
  1203.             //------------------Signal End-----------------------//
  1204. //------------------------------------------------------------------------//
  1205. BEGIN_MESSAGE_MAP(CMydrawApp, CWinApp)
  1206. //{{AFX_MSG_MAP(MydrawApp)
  1207. //}}AFX_MSG_MAP
  1208. END_MESSAGE_MAP()
  1209. void DestroyOverlay()
  1210. {
  1211.     
  1212. if (Land) { Land->Release(); Land = NULL; }
  1213.     if (BackGround) { BackGround->Release(); BackGround=NULL;}
  1214.   AllUnits.Destroy();
  1215. AllBuildings.Destroy();
  1216. MSignal.Destroy();
  1217.     //for(int i=0;i<=7;i++) { DirectionSurf[i]->Release();DirectionSurf[i]=NULL;} 
  1218.     // buildingtype release()   
  1219. }
  1220. void DestroyPrimary()
  1221. {
  1222.     if(PrimaryBack)   {PrimaryBack->Release(); PrimaryBack = NULL;}
  1223.     if(Primary)       {Primary->Release(); Primary = NULL;}
  1224. }
  1225. void InitDirectInput()
  1226. {
  1227. HRESULT hRet;
  1228. hRet=DirectInputCreateEx( (HINSTANCE)GetWindowLong(mWnd, GWL_HINSTANCE ),
  1229.                       DIRECTINPUT_VERSION, IID_IDirectInput7, (LPVOID*)&DInput, NULL);
  1230. if(hRet!=DI_OK)  MessageBox(NULL,"Create InputDevice Failed!","Error",MB_OK); 
  1231.     hRet=DInput->CreateDeviceEx(GUID_SysMouse,IID_IDirectInputDevice2,
  1232.                                (VOID**)&Mouse, NULL );
  1233. if(hRet!=DI_OK) TRACE("Mouseinput create failed!n"); 
  1234.     hRet=Mouse->SetDataFormat(&c_dfDIMouse);
  1235.     if(hRet!=DI_OK) TRACE("Mouseinput set dataformat failed!n");
  1236.     hRet=Mouse->SetCooperativeLevel(mWnd,DISCL_NONEXCLUSIVE|DISCL_FOREGROUND);
  1237.     if(hRet!=DI_OK) TRACE("mouse SetCooperativeLevel Failed!n");
  1238.     DIPROPDWORD Property;
  1239.     Property.diph.dwSize=sizeof(DIPROPDWORD);
  1240.     Property.diph.dwHeaderSize=sizeof(DIPROPHEADER);
  1241.     Property.diph.dwObj=0;
  1242.     Property.diph.dwHow=DIPH_DEVICE;
  1243.     Property.dwData=128;
  1244.     Mouse->SetProperty(DIPROP_BUFFERSIZE,&Property.diph);
  1245. }
  1246. LPCSTR InitDDraw()
  1247. {
  1248.   InitDirectInput();
  1249.   HRESULT Result;
  1250.   Result = DirectDrawCreateEx(NULL, (VOID**)&lpDD, IID_IDirectDraw7, NULL);
  1251.   if(Result!=DD_OK) return "Create DirectDrawObject Failed!";
  1252.   Result = lpDD->SetCooperativeLevel(mWnd, DDSCL_EXCLUSIVE|DDSCL_FULLSCREEN);
  1253.   if(Result!=DD_OK) return "SetCooperativeLevel Failed!";
  1254.   Result = lpDD->SetDisplayMode(800,600,16,0,0);
  1255.   if(Result!=DD_OK) return "SetDisplayMode Failed!";
  1256.   return "OK";
  1257. }
  1258. LPCSTR InitPrimarySurface()
  1259. {
  1260. HRESULT hRet;
  1261. INIT_DIRECTDRAW_STRUCT(ddsd);
  1262.     ddsd.dwFlags = DDSD_CAPS|DDSD_BACKBUFFERCOUNT;
  1263.     ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE|DDSCAPS_FLIP|DDSCAPS_COMPLEX;
  1264.     ddsd.dwBackBufferCount = 1;
  1265.     hRet=lpDD->CreateSurface(&ddsd, &Primary, NULL); 
  1266. if(hRet!=DD_OK) return "Create Primary Surface Failed!"; 
  1267.     
  1268. DDSCAPS2 ddsCaps;
  1269.     ZeroMemory(&ddsCaps,sizeof(ddsCaps));
  1270. ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
  1271.     hRet = Primary->GetAttachedSurface(&ddsCaps, &PrimaryBack);
  1272.     if(hRet!=DD_OK)return "Create BackBuffer Action Failed";
  1273. return "OK";
  1274. }
  1275. LPCSTR InitOverlaySurface()
  1276. {
  1277. HRESULT hRet;
  1278. INIT_DIRECTDRAW_STRUCT(ddsd);
  1279. ddsd.dwFlags=DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT;
  1280. ddsd.ddsCaps.dwCaps=DDSCAPS_SYSTEMMEMORY|DDSCAPS_OFFSCREENPLAIN;
  1281. ddsd.dwWidth=1200;
  1282. ddsd.dwHeight=1200;
  1283. hRet=lpDD->CreateSurface(&ddsd,&BackGround,NULL);
  1284.     hRet=lpDD->CreateSurface(&ddsd,&BackUp,NULL);
  1285.     if(hRet!=DD_OK) return "Create BackGround Surface Action Failed";
  1286. INIT_DIRECTDRAW_STRUCT(ddsd);
  1287. ddsd.dwFlags=DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT;
  1288. ddsd.ddsCaps.dwCaps=DDSCAPS_SYSTEMMEMORY|DDSCAPS_OFFSCREENPLAIN;
  1289. ddsd.dwWidth=400;
  1290. ddsd.dwHeight=400;
  1291. hRet=lpDD->CreateSurface(&ddsd,&Land,NULL);
  1292.     if(hRet!=DD_OK) return "Create Land Surface Action Failed";
  1293. INIT_DIRECTDRAW_STRUCT(ddsd);
  1294. ddsd.dwFlags=DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT;
  1295. ddsd.ddsCaps.dwCaps=DDSCAPS_SYSTEMMEMORY|DDSCAPS_OFFSCREENPLAIN;
  1296. ddsd.dwWidth=60;
  1297. ddsd.dwHeight=60;
  1298. hRet=lpDD->CreateSurface(&ddsd,&Circle,NULL);
  1299.     DDCOLORKEY KColor;
  1300.     KColor.dwColorSpaceLowValue=RGB(0,0,0);
  1301.     KColor.dwColorSpaceHighValue=RGB(0,0,0);
  1302. Circle->SetColorKey(DDCKEY_SRCBLT,&KColor);
  1303.     if(hRet!=DD_OK) return "Create Circle Surface Action Failed";
  1304. return "OK";
  1305. }
  1306. BOOL LoadImageOntoSurface(Surface lpdds,LPSTR lpstrResID,int Bmpx,int Bmpy)
  1307. {
  1308.     HBITMAP hbm;
  1309.     HDC     hdcImage= NULL;
  1310.     HDC     hdcSurf = NULL;
  1311.     BOOL bRetVal = FALSE;
  1312.     HRESULT ddrval;
  1313.     DDSURFACEDESC2 ddsd;
  1314.     INIT_DIRECTDRAW_STRUCT(ddsd);
  1315.     ddsd.dwFlags = DDSD_HEIGHT | DDSD_WIDTH;
  1316.     ddrval = lpdds->GetSurfaceDesc(&ddsd);
  1317.     if(ddrval!=DD_OK)
  1318. {
  1319. MessageBox(NULL,"HATE YOU","error",MB_OK);  
  1320. }
  1321.     hbm = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(lpstrResID), IMAGE_BITMAP, Bmpx, Bmpy, LR_DEFAULTCOLOR);//LR_CREATEDIBSECTION);
  1322.     hdcImage = CreateCompatibleDC(NULL);
  1323.     SelectObject(hdcImage, hbm);
  1324.     ddrval = lpdds->GetDC(&hdcSurf);
  1325.     if(BitBlt(hdcSurf, 0, 0, ddsd.dwWidth, ddsd.dwHeight, hdcImage, 0, 0, SRCCOPY)==FALSE)
  1326. { MessageBox(NULL,"HATE YOU","error",MB_OK);   }
  1327.     DeleteDC(hdcImage);
  1328.     DeleteObject(hbm);
  1329. lpdds->ReleaseDC(hdcSurf);
  1330. return TRUE;
  1331.   }
  1332. void PrepareMap(int randseed)
  1333. {
  1334. int i,j;
  1335. for(i=0;i<=2;i++)
  1336. for(j=0;j<=2;j++)
  1337. BackGround->Blt(CRect(xstart+i*400,ystart+j*400,xstart+squaresize*20+i*400,ystart+squaresize*20+j*400),Land,CRect(0,0,400,400),0,NULL);
  1338.  
  1339.     i=2;j=4;
  1340.     POSITION posB;  
  1341.     Building *NewBuild;
  1342. for(posB=AllBuildings.BuildingList.GetHeadPosition();posB!=NULL;)
  1343. {
  1344. j=j+3;
  1345. NewBuild=(Building*)AllBuildings.BuildingList.GetNext(posB);
  1346. NewBuild->Show(i,j);
  1347. i=i+15;
  1348. if(i>=50) i=2;
  1349. }
  1350.     BackUp->Blt(CRect(0,0,1200,1200),BackGround,CRect(0,0,1200,1200),0,NULL); 
  1351.      
  1352. POSITION posU;  
  1353.     Unit *ttUnit;
  1354. for(posU=AllUnits.UnitList.GetHeadPosition();posU!=NULL;)
  1355. {
  1356. ttUnit=(Unit*)AllUnits.UnitList.GetNext(posU);
  1357. ttUnit->Redraw();
  1358. }
  1359. }
  1360. void InitGraph()
  1361. {
  1362.    CString Result; 
  1363.    Result=InitDDraw();
  1364.           if(Result!="OK"){ MessageBox(mWnd,Result,"error",MB_OK); return ;}
  1365.    Result=InitPrimarySurface();
  1366.           if(Result!="OK"){ MessageBox(mWnd,Result,"error",MB_OK); return ;}
  1367.    Result=InitOverlaySurface();
  1368.           if(Result!="OK"){ MessageBox(mWnd,Result,"error",MB_OK); return ;}
  1369.   
  1370. int i;
  1371.    Missle=new WeaponType;
  1372. Missle->width=1;
  1373. Missle->height=1;
  1374. Missle->Time=1;
  1375.     Missle->steplen=8;
  1376. Missle->DirectionCount=20;
  1377. for(i=0;i<=Missle->DirectionCount-1;i++) Missle->RIDDirection[i]=297+i;
  1378. for(i=0;i<=13;i++)  Missle->RIDExplosion[i]=256+i;
  1379. Missle->Init();
  1380.        
  1381.     UnitType *Tank,*SpaceCar;
  1382. Tank=new UnitType;
  1383. Tank->width=3;
  1384. Tank->height=3;
  1385. Tank->RIDDirection[0]=227;
  1386. Tank->Time=2;
  1387.     Tank->steplen=8;
  1388. Tank->stepx=Tank->steplen;
  1389. Tank->stepy=Tank->steplen;
  1390.     Tank->RIDDirection[1]=226;
  1391. Tank->RIDDirection[2]=225;
  1392. Tank->RIDDirection[3]=224;
  1393. Tank->RIDDirection[4]=223;
  1394. Tank->RIDDirection[5]=222;
  1395. Tank->RIDDirection[6]=228;
  1396. Tank->RIDDirection[7]=221;
  1397. Tank->Init();
  1398.     
  1399. SpaceCar=new UnitType;
  1400. SpaceCar->Time=2;
  1401. SpaceCar->steplen=5;
  1402. SpaceCar->stepx=SpaceCar->steplen;
  1403. SpaceCar->stepy=SpaceCar->steplen;
  1404.     SpaceCar->width=3;
  1405. SpaceCar->height=3;
  1406. SpaceCar->RIDDirection[0]=235;
  1407. SpaceCar->RIDDirection[1]=234;
  1408. SpaceCar->RIDDirection[2]=233;
  1409. SpaceCar->RIDDirection[3]=232;
  1410. SpaceCar->RIDDirection[4]=231;
  1411. SpaceCar->RIDDirection[5]=230;
  1412. SpaceCar->RIDDirection[6]=236;
  1413. SpaceCar->RIDDirection[7]=229;
  1414. SpaceCar->Init();
  1415.     
  1416. LoadImageOntoSurface(Land,MAKEINTRESOURCE(193),400,400);
  1417. LoadImageOntoSurface(Circle,MAKEINTRESOURCE(270),60,60);
  1418.     
  1419. int j=0;
  1420.     for(i=0;i<=7;i++)
  1421. {
  1422. Unit *car;
  1423.     car=new Unit;
  1424.     car->x=i*4+3;
  1425. car->y=3;
  1426. if(j>=8) j=0;
  1427. car->Direction=j;
  1428. j++;
  1429. car->Init(Tank);
  1430. AllUnits.UnitList.AddTail(car);
  1431. }
  1432. for(i=0;i<=2;i++)
  1433. {
  1434. Unit *car;
  1435.     car=new Unit;
  1436.     car->x=i*4+40;
  1437. car->y=3;
  1438. if(j>=8) j=0;
  1439. car->Direction=j;
  1440. j++;
  1441. car->Init(Tank);
  1442. AllUnits.UnitList.AddTail(car);
  1443. }
  1444. MSignal.RIDanimation[0]=194;
  1445.     MSignal.RIDanimation[1]=196;
  1446.     MSignal.RIDanimation[2]=195;
  1447.     MSignal.CurrentFrame=0;
  1448. MSignal.width=2;
  1449. MSignal.height=2;
  1450. MSignal.Time=2;
  1451.     MSignal.TimeCount=0;
  1452.     MSignal.Init();   
  1453.   
  1454.     BuildingType *m_pyramid,*m_tower,*m_wonder,*m_crackship;
  1455. m_pyramid= new BuildingType;
  1456.     m_tower  = new BuildingType;
  1457.     m_wonder = new BuildingType;
  1458.     m_crackship = new BuildingType;
  1459.     
  1460. m_pyramid->width=11;
  1461. m_pyramid->height=7;
  1462. m_pyramid->name="pyramid";
  1463. m_pyramid->RIDnormal=216;
  1464. int arraytemp0[MAXH][MAXL]={0,0,0,2,2,2,2,2,0,0,0,0,0,
  1465.                         0,0,2,2,2,2,2,2,2,2,2,0,0,
  1466.             0,0,2,1,1,1,1,1,2,2,2,0,0,
  1467.             1,1,1,1,1,1,1,1,1,1,1,0,0,
  1468.             0,1,1,1,1,1,1,1,1,1,1,0,0,
  1469.                             0,0,0,1,1,1,1,1,1,1,0,0,0, 
  1470.                             0,0,0,0,1,1,1,1,0,0,0,0,0,  
  1471.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  1472.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  1473.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  1474.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  1475.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  1476.                             0,0,0,0,0,0,0,0,0,0,0,0,0 }; 
  1477. m_pyramid->Init(arraytemp0);
  1478.     
  1479. m_tower->width=3;
  1480. m_tower->height=6;
  1481. m_tower->name="Tower";
  1482. m_tower->RIDnormal=217;
  1483. int arraytemp1[MAXH][MAXL]={4,4,4,0,0,0,0,0,0,0,0,0,0,
  1484.                         4,4,4,0,0,0,0,0,0,0,0,0,0,
  1485.             4,4,4,0,0,0,0,0,0,0,0,0,0,
  1486.             4,4,4,0,0,0,0,0,0,0,0,0,0,
  1487.             4,4,4,0,0,0,0,0,0,0,0,0,0,
  1488.                             4,4,4,0,0,0,0,0,0,0,0,0,0,
  1489.                             0,0,0,0,0,0,0,0,0,0,0,0,0,  
  1490.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  1491.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  1492.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  1493.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  1494.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  1495.                             0,0,0,0,0,0,0,0,0,0,0,0,0 }; 
  1496. /*int arraytemp1[MAXH][MAXL]={2,2,2,0,0,0,0,0,0,0,0,0,0,
  1497.                         2,2,2,0,0,0,0,0,0,0,0,0,0,
  1498.             2,2,2,0,0,0,0,0,0,0,0,0,0,
  1499.             2,1,2,0,0,0,0,0,0,0,0,0,0,
  1500.             1,1,1,0,0,0,0,0,0,0,0,0,0,
  1501.                             1,1,1,0,0,0,0,0,0,0,0,0,0,
  1502.                             0,0,0,0,0,0,0,0,0,0,0,0,0,  
  1503.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  1504.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  1505.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  1506.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  1507.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  1508.                             0,0,0,0,0,0,0,0,0,0,0,0,0 }; */
  1509. m_tower->Init(arraytemp1);
  1510.     
  1511. m_wonder->width=8;
  1512. m_wonder->height=11;
  1513. m_wonder->name="Wonder";
  1514. m_wonder->RIDnormal=219;
  1515. int arraytemp2[MAXH][MAXL]={0,2,2,2,2,2,0,0,0,0,0,0,0,
  1516.                         0,2,2,2,2,2,0,0,0,0,0,0,0,
  1517.             0,2,2,2,2,0,0,0,0,0,0,0,0,
  1518.             0,2,2,2,2,2,0,0,0,0,0,0,0,
  1519.             0,0,0,2,2,2,0,0,0,0,0,0,0,
  1520.                             0,0,0,2,2,2,0,0,0,0,0,0,0,
  1521.                             0,0,0,1,1,0,0,0,0,0,0,0,0,  
  1522.                             0,1,1,1,1,1,0,0,0,0,0,0,0, 
  1523.                             1,1,1,1,1,1,1,1,0,0,0,0,0, 
  1524.                             0,1,1,1,1,1,1,0,0,0,0,0,0, 
  1525.                             0,0,1,1,1,0,0,0,0,0,0,0,0, 
  1526.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  1527.                             0,0,0,0,0,0,0,0,0,0,0,0,0 }; 
  1528. m_wonder->Init(arraytemp2);
  1529.     
  1530. m_crackship->width=6;
  1531. m_crackship->height=6;
  1532. m_crackship->name="CrackShip";
  1533. m_crackship->RIDnormal=220;
  1534. /*int arraytemp3[MAXH][MAXL]={0,0,0,2,2,0,0,0,0,0,0,0,0,
  1535.                         0,0,2,2,2,0,0,0,0,0,0,0,0,
  1536.             0,2,2,2,2,2,0,0,0,0,0,0,0,
  1537.             0,1,1,1,2,2,0,0,0,0,0,0,0,
  1538.             0,1,1,1,1,0,0,0,0,0,0,0,0,
  1539.                             0,0,1,1,0,0,0,0,0,0,0,0,0,
  1540.                             0,0,0,0,0,0,0,0,0,0,0,0,0,  
  1541.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  1542.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  1543.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  1544.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  1545.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  1546.                             0,0,0,0,0,0,0,0,0,0,0,0,0 }; */
  1547. int arraytemp3[MAXH][MAXL]={0,0,0,4,4,0,0,0,0,0,0,0,0,
  1548.                         0,0,4,4,4,0,0,0,0,0,0,0,0,
  1549.             0,4,4,4,4,4,0,0,0,0,0,0,0,
  1550.             0,4,4,4,4,4,0,0,0,0,0,0,0,
  1551.             0,4,4,4,4,0,0,0,0,0,0,0,0,
  1552.                             0,0,4,4,0,0,0,0,0,0,0,0,0,
  1553.                             0,0,0,0,0,0,0,0,0,0,0,0,0,  
  1554.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  1555.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  1556.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  1557.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  1558.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  1559.                             0,0,0,0,0,0,0,0,0,0,0,0,0 }; 
  1560. m_crackship->Init(arraytemp3);
  1561. for(i=0;i<=2;i++)
  1562. {
  1563. Building *NewBuild;
  1564. NewBuild=new Building;
  1565.     NewBuild->Init(m_pyramid);
  1566. AllBuildings.BuildingList.AddTail(NewBuild);
  1567. BuildingCount++;
  1568. }
  1569. Building *NewBuild;
  1570. NewBuild=new Building;
  1571.     NewBuild->Init(m_wonder);
  1572. AllBuildings.BuildingList.AddTail(NewBuild);
  1573. BuildingCount++;
  1574.     for(i=0;i<=3;i++)
  1575. {
  1576. Building *NewBuild;
  1577. NewBuild=new Building;
  1578.     NewBuild->Init(m_tower);
  1579. AllBuildings.BuildingList.AddTail(NewBuild);
  1580. BuildingCount++;
  1581. }
  1582. Building *NewBuild1;
  1583. NewBuild1=new Building;
  1584.     NewBuild1->Init(m_crackship);
  1585. AllBuildings.BuildingList.AddTail(NewBuild1);
  1586. BuildingCount++;
  1587. CBrush br(RGB(0,0,0));
  1588. CRect rc;
  1589. HDC hdc;
  1590. Primary->GetDC(&hdc);
  1591. GetWindowRect(mWnd,&rc);
  1592. FillRect(hdc,&rc, (HBRUSH)br);
  1593. Primary->ReleaseDC(hdc);
  1594. PrimaryBack->GetDC(&hdc);
  1595. GetWindowRect(mWnd,&rc);
  1596. FillRect(hdc,&rc, (HBRUSH)br);
  1597. PrimaryBack->ReleaseDC(hdc);
  1598. BackGround->GetDC(&hdc);
  1599. GetWindowRect(mWnd,&rc);
  1600. FillRect(hdc,&rc, (HBRUSH)br);
  1601. BackGround->ReleaseDC(hdc);
  1602. PrepareMap(0);
  1603.    
  1604. }
  1605. void ShowString(int x,int y,char *str)
  1606. {
  1607. HDC hdc;
  1608. Primary->GetDC(&hdc);
  1609. TextOut(hdc,x,y,"####",4);
  1610. TextOut(hdc,x,y,str,strlen(str));
  1611. Primary->ReleaseDC(hdc);
  1612. PrimaryBack->GetDC(&hdc);
  1613. TextOut(hdc,x,y,"####",4);
  1614. TextOut(hdc,x,y,str,strlen(str));
  1615. PrimaryBack->ReleaseDC(hdc);
  1616. }
  1617. int GetRand(int s,int e)
  1618. {
  1619.      int nRand;
  1620.  float tempnum,tempnum1;
  1621.      nRand=rand();
  1622.  tempnum=(float)e/RAND_MAX;
  1623.      tempnum1=(float)nRand*tempnum+0.5F;
  1624.      return int(tempnum1);
  1625. }
  1626. void ShowChooseRect()
  1627. {
  1628.        HDC hdc;
  1629.    POINT cp;
  1630.    BackGround->GetDC(&hdc);
  1631.    CPen cpen;
  1632.    cpen.CreatePen(PS_SOLID,1,RGB(255,255,255));
  1633.    SelectObject(hdc,cpen);
  1634.    MoveToEx(hdc,ChooseSx,ChooseSy,&cp);
  1635.        int x1,y1;
  1636.    x1=Mousex+xscroll-xstart;
  1637.    y1=Mousey+yscroll-ystart;
  1638.    if(x1<=2) x1=1;
  1639.    if(x1>MapPixelWidth-1) x1=MapPixelWidth-1;
  1640.        if(y1<1) y1=1;
  1641.    if(y1>MapPixelHeight-1) y1=MapPixelHeight-1;
  1642.        LineTo(hdc,x1,ChooseSy);
  1643.        LineTo(hdc,x1,y1);
  1644.    LineTo(hdc,ChooseSx,y1);
  1645.    LineTo(hdc,ChooseSx,ChooseSy);
  1646.    BackGround->ReleaseDC(hdc);
  1647.        cpen.DeleteObject();
  1648.        OldCx=x1;
  1649.        OldCy=y1;
  1650. }
  1651. void ShowChooseRecover()
  1652. {
  1653.    int x1,y1,x2,y2,xt,yt,uw,uh;
  1654.    if(ChooseSx<=OldCx) { x1=ChooseSx;x2=OldCx;}
  1655.    else                { x2=ChooseSx;x1=OldCx;}
  1656.    if(ChooseSy<=OldCy) { y1=ChooseSy;y2=OldCy;}
  1657.    else                { y2=ChooseSy;y1=OldCy;}
  1658.    int range=1;
  1659.    BackGround->Blt(CRect(x1-range,y1-range,x2+range,y1+range),BackUp,CRect(x1-range,y1-range,x2+range,y1+range),0,NULL);
  1660.    BackGround->Blt(CRect(x2-range,y1-range,x2+range,y2+range),BackUp,CRect(x2-range,y1-range,x2+range,y2+range),0,NULL);
  1661.    BackGround->Blt(CRect(x1-range,y2-range,x2+range,y2+range),BackUp,CRect(x1-range,y2-range,x2+range,y2+range),0,NULL);
  1662.    BackGround->Blt(CRect(x1-range,y1-range,x1+range,y2+range),BackUp,CRect(x1-range,y1-range,x1+range,y2+range),0,NULL);
  1663.    POSITION posU;
  1664.    Unit *ttUnit;
  1665.    int RectStartx=x1/squaresize;
  1666.    int RectEndx=x2/squaresize;
  1667.    int RectStarty=y1/squaresize;
  1668.    int RectEndy=y2/squaresize;
  1669.    for(posU=AllUnits.UnitList.GetHeadPosition();posU!=NULL;)
  1670.    {
  1671.      ttUnit=(Unit*)AllUnits.UnitList.GetNext(posU);
  1672.      xt=ttUnit->x;yt=ttUnit->y;
  1673.      uw=ttUnit->width;uh=ttUnit->height;
  1674.  CRect *temprect=new CRect;
  1675.  IntersectRect(temprect,CRect(RectStartx,RectStarty,RectEndx,RectStarty+1),CRect(xt,yt,xt+uw,yt+uh));
  1676.  if(!temprect->IsRectNull())
  1677.  { ttUnit->Redraw(); } 
  1678.  IntersectRect(temprect,CRect(RectStartx,RectEndy,RectEndx,RectEndy+1),CRect(xt,yt,xt+uw,yt+uh));
  1679.  if(!temprect->IsRectNull())
  1680.  { ttUnit->Redraw(); } 
  1681.  IntersectRect(temprect,CRect(RectStartx,RectStarty,RectStartx+1,RectEndy),CRect(xt,yt,xt+uw,yt+uh));
  1682.  if(!temprect->IsRectNull())
  1683.  { ttUnit->Redraw(); } 
  1684.  IntersectRect(temprect,CRect(RectEndx,RectStarty,RectEndx+1,RectEndy),CRect(xt,yt,xt+uw,yt+uh));
  1685.  if(!temprect->IsRectNull())
  1686.  { ttUnit->Redraw(); } 
  1687.  delete temprect; 
  1688. }
  1689. }
  1690. //------------------------- Begin------------------------------------------------------------//
  1691. CMydrawApp theApp;
  1692. CMydrawApp::CMydrawApp()
  1693. {
  1694. }
  1695. BOOL CMydrawApp::InitInstance()
  1696. {
  1697.    m_pMainWnd=new CMydrawFrame();
  1698.    InitGraph();
  1699.    m_pMainWnd->ShowWindow(SW_NORMAL); 
  1700.    m_pMainWnd->UpdateWindow();
  1701.    xlimit=1200-800-1;
  1702.    ylimit=1200-480-1;
  1703.    xscroll=0;
  1704.    yscroll=0;
  1705.    DrawLittleMap();
  1706.    PrimaryBack->Blt(CRect(SpaceStartx,SpaceStarty,SpaceEndx,SpaceEndy)
  1707.    ,BackGround,CRect(xscroll,yscroll,xscroll+SpaceEndx,yscroll+SpaceEndy),0,NULL);
  1708.    Primary->Flip(NULL,0);
  1709.    return TRUE;
  1710. }
  1711. BOOL CMydrawApp::OnIdle(LONG)
  1712. {
  1713. int OldMx=Mousex;
  1714. int OldMy=Mousey;
  1715. POINT mpp;
  1716. GetCursorPos(&mpp);
  1717. Mousex=mpp.x;
  1718. Mousey=mpp.y;
  1719. bool Scroll=FALSE;
  1720. if(Mousex!=OldMx||Mousey!=OldMy)
  1721.   {
  1722.       
  1723.       if(Mousex>=SpaceEndx)
  1724.   {
  1725.   Mousex=SpaceEndx-1;
  1726.           if(xscroll<xlimit) {xscroll+=ScrollStep; Scroll=TRUE;}
  1727.   }
  1728.   
  1729.   if(Mousex<=SpaceStartx) 
  1730.   {   
  1731.   Mousex=SpaceStartx+1;
  1732.           if(xscroll>1) {xscroll-=ScrollStep; Scroll=TRUE;} 
  1733.   }
  1734.   
  1735.   if(Mousey>=599) 
  1736.   {
  1737.    Mousey=598;
  1738.        if(yscroll<ylimit) {yscroll+=ScrollStep; Scroll=TRUE;} 
  1739.       }
  1740.   
  1741.   if(Mousey<=0) 
  1742.   {
  1743.   Mousey=1;
  1744.           if(yscroll>1)   {yscroll-=ScrollStep; Scroll=TRUE;}
  1745.   }
  1746.       if(Scroll)
  1747.   {
  1748.            UpdateFrame=TRUE;
  1749.        Scroll=FALSE;
  1750.   }
  1751.  
  1752.   if(BeginChoose)  UpdateFrame=TRUE;
  1753. }
  1754.        
  1755.   if(TimeIsUp||UpdateFrame)
  1756.   {
  1757.   
  1758.   if(BeginChoose) ShowChooseRecover();
  1759.       if(TimeIsUp)
  1760.   {
  1761.   if(MSignal.ShowBegin) MSignal.Recover();
  1762.   AllWeapons.Recover();
  1763.   AllUnits.Recover();
  1764.   AllUnits.Show();
  1765.   AllBuildings.Recover();
  1766.   AllWeapons.Show();
  1767.   if(MSignal.ShowBegin)   MSignal.Show();
  1768.               TimeIsUp=FALSE;
  1769.   DrawLittleMap();
  1770.   }
  1771.   if(BeginChoose) { ShowChooseRect(); }
  1772.   PrimaryBack->Blt(CRect(SpaceStartx,SpaceStarty,SpaceEndx,SpaceEndy),BackGround,CRect(xscroll,yscroll,xscroll+SpaceEndx,yscroll+SpaceEndy),0,NULL);
  1773.           Primary->Flip(NULL,0);
  1774.   UpdateFrame=FALSE;
  1775.       }
  1776.   
  1777.   
  1778.       return TRUE;
  1779.   }
  1780. BEGIN_MESSAGE_MAP(CMydrawFrame,CFrameWnd)
  1781.     ON_WM_ACTIVATE() 
  1782.     ON_WM_TIMER()
  1783.     ON_WM_KEYDOWN()
  1784.     ON_WM_LBUTTONDOWN()
  1785.     ON_WM_RBUTTONDOWN()
  1786.     ON_WM_LBUTTONUP()
  1787. END_MESSAGE_MAP()
  1788. CMydrawFrame::CMydrawFrame()
  1789. {
  1790. CString sClassName;
  1791. sClassName = AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW,LoadCursor(0, IDC_ARROW),
  1792. (HBRUSH )GetStockObject(BLACK_BRUSH), LoadIcon(AfxGetInstanceHandle(), NULL));
  1793. CreateEx( WS_EX_TOPMOST, sClassName, "asap", WS_POPUP, 0,0,100,100,NULL,NULL);
  1794. mWnd=m_hWnd;
  1795.     SetTimer(1,BaseTime,NULL);
  1796. }
  1797. void CMydrawFrame::OnActivate(UINT nState,CWnd *pWndOther,BOOL bMinimized)
  1798. {
  1799. if(nState!=WA_INACTIVE)
  1800. {
  1801.     if(Mouse) Mouse->Acquire();
  1802. }
  1803. }
  1804. void CMydrawFrame::OnRButtonDown(UINT fl,CPoint mp)
  1805. {
  1806.  ChooseGroup=FALSE;
  1807.  POSITION posU;
  1808.  Unit *ttUnit;
  1809.  int sign=0;
  1810.  for(posU=ChosedGroup.UnitList.GetHeadPosition();posU!=NULL;)
  1811.  {
  1812.    ttUnit=(Unit*)ChosedGroup.UnitList.GetNext(posU);
  1813.    ttUnit->BeChosed=FALSE;
  1814.    sign=0;
  1815.    if(ttUnit->MoveSign==0){ ttUnit->MoveSign=1; sign=1;}
  1816.    ttUnit->Recover();
  1817.    if(sign==1) ttUnit->MoveSign=0; 
  1818.    ttUnit->Redraw();
  1819.  }
  1820. }
  1821. void CMydrawFrame::OnLButtonUp(UINT fl,CPoint mp)
  1822. {
  1823.       if(BeginChoose) 
  1824. {
  1825.    ShowChooseRecover();
  1826.    BeginChoose=FALSE;
  1827.        POSITION posU;
  1828.        int x1,y1,x2,y2,xt,yt;
  1829.        if(ChooseSx<=OldCx) { x1=ChooseSx;x2=OldCx;}
  1830.        else                { x2=ChooseSx;x1=OldCx;}
  1831.        if(ChooseSy<=OldCy) { y1=ChooseSy;y2=OldCy;}
  1832.        else                { y2=ChooseSy;y1=OldCy;}
  1833.      int RectStartx=x1/squaresize;
  1834.        int RectEndx=x2/squaresize;
  1835.        int RectStarty=y1/squaresize;
  1836.        int RectEndy=y2/squaresize;
  1837.        ChosedGroup.UnitList.RemoveAll();
  1838.    ChosedGroup.MemberCount=0;
  1839.        Unit *ttUnit;
  1840.    for(posU=AllUnits.UnitList.GetHeadPosition();posU!=NULL;)
  1841.    {
  1842.          ttUnit=(Unit*)AllUnits.UnitList.GetNext(posU);
  1843.          ttUnit->BeChosed=FALSE;
  1844.  xt=ttUnit->x;yt=ttUnit->y;
  1845.      if(xt>=RectStartx&&xt<=RectEndx&&yt>=RectStarty&&yt<=RectEndy)
  1846.  {
  1847.      ttUnit->BeChosed=TRUE;
  1848.      ttUnit->Redraw();
  1849.  ChosedGroup.UnitList.AddTail(ttUnit);
  1850.      ChosedGroup.MemberCount++;
  1851.  }
  1852.      if(ChosedGroup.MemberCount>0) ChooseGroup=TRUE; else ChooseGroup=FALSE; 
  1853. // ShowInt(20,500,ChosedGroup.MemberCount);
  1854. }
  1855.   }
  1856. }
  1857. void CMydrawFrame::OnLButtonDown(UINT fl,CPoint mp)
  1858. {
  1859. SetCapture();
  1860. Mousex=mp.x;
  1861. Mousey=mp.y;
  1862. int x1,y1,x,y;
  1863. x=(Mousex+xscroll-xstart)/squaresize;
  1864. y=(Mousey+yscroll-ystart)/squaresize;
  1865. if(!ChooseGroup)
  1866. {
  1867. BeginChoose=TRUE;
  1868.     ChooseSx=Mousex+xscroll-xstart;
  1869.     ChooseSy=Mousey+yscroll-ystart;
  1870. }
  1871. //------------------ Group have been chosed ----------------------------//
  1872. if(ChooseGroup)
  1873. {
  1874. int uu1=x,uu2=y;
  1875.     if(x>=0&&y>=0&&x<=(MapWidth-1)&&y<=(MapHeight-1))
  1876. {
  1877.  if(map[y][x]==0)
  1878.  {
  1879.     if(MSignal.ShowBegin==FALSE)
  1880. { MSignal.ShowBegin=TRUE;
  1881.       MSignal.x=Mousex-20+xscroll+xstart;
  1882.           MSignal.y=Mousey-20+yscroll+ystart; 
  1883. }
  1884.         x1=xstart+x*squaresize-xscroll;
  1885.         y1=ystart+y*squaresize-yscroll;
  1886.     //SignalSign=1;
  1887.         ChosedGroup.MoveTo(uu1,uu2,CONCENTRATE);
  1888.  }
  1889.  if(map[y][x]==4)
  1890.  {
  1891.     ChosedGroup.MoveTo(uu1,uu2,SURROUND);
  1892.  }
  1893. }
  1894. }
  1895. }
  1896. //----------------------------------------------------------------------//
  1897. void CMydrawFrame::OnTimer(UINT nIDEvent)
  1898. {
  1899. TimeIsUp=TRUE;
  1900. }
  1901. void CMydrawFrame::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  1902. {
  1903.  if(nChar==VK_ESCAPE)
  1904.  {
  1905.  DestroyOverlay();
  1906.  DestroyPrimary();
  1907.  if(DInput)   {DInput->Release(); DInput=NULL;}
  1908.  delete lpDD;
  1909.  PostMessage(WM_DESTROY,0,0);
  1910.  }
  1911. }
  1912.  
  1913.  
  1914.  /*int step=2;
  1915.  ttUnit=(Unit*)ChosedGroup.UnitList.GetNext(pos); 
  1916.  uy=ttUnit->y;
  1917.  ux=ttUnit->x;
  1918.  uw=ttUnit->width;
  1919.  uh=ttUnit->height;
  1920.  for(j=uy;j<=uy+uh-1;j++) for(i=ux;i<=ux+uw-1;i++) {if(map[j][i]==3) map[j][i]=0; }
  1921.  if(!ttUnit->Seek(uu1,uu2)) 
  1922.  { for(j=uy;j<=uy+uh-1;j++) for(i=ux;i<=ux+uw-1;i++) {if(map[j][i]!=2) map[j][i]=3; }}
  1923.    while(pos!=NULL)
  1924.   {
  1925.     radio+=step;
  1926. xt=uu1-radio;
  1927.     for(yt=uu2-radio;yt<=uu2+radio;yt+=step)
  1928. if(map[yt][xt]==0) 
  1929. {
  1930. if(xt>=0&&yt>=0&&xt<=(MapWidth-1)&&yt<=(MapHeight-1))
  1931.             {
  1932. if(pos==NULL)  return;
  1933. ttUnit=(Unit*)ChosedGroup.UnitList.GetNext(pos); 
  1934. uy=ttUnit->y;
  1935. ux=ttUnit->x;
  1936.     for(j=uy;j<=uy+uh-1;j++) for(i=ux;i<=ux+uw-1;i++) {if(map[j][i]==3) map[j][i]=0; }
  1937.             if(!ttUnit->Seek(xt,yt))  
  1938. { for(j=uy;j<=uy+uh-1;j++) for(i=ux;i<=ux+uw-1;i++) {if(map[j][i]!=2) map[j][i]=3; }}
  1939. }
  1940.  
  1941. }
  1942.    xt=uu1+radio;
  1943.    for(yt=uu2-radio;yt<=uu2+radio;yt+=step)
  1944. if(map[yt][xt]==0) 
  1945. {
  1946. if(xt>=0&&yt>=0&&xt<=(MapWidth-1)&&yt<=(MapHeight-1))
  1947.             {
  1948. if(pos==NULL)  return;
  1949. ttUnit=(Unit*)ChosedGroup.UnitList.GetNext(pos); 
  1950. uy=ttUnit->y;ux=ttUnit->x;
  1951. for(j=uy;j<=uy+uh-1;j++) for(i=ux;i<=ux+uw-1;i++) {if(map[j][i]==3) map[j][i]=0; }
  1952.         if(!ttUnit->Seek(xt,yt))  
  1953. {for(j=uy;j<=uy+uh-1;j++) for(i=ux;i<=ux+uw-1;i++) {if(map[j][i]!=2) map[j][i]=3; }}
  1954. }
  1955. }
  1956.    yt=uu2-radio;
  1957.    for(xt=uu1-radio+1;xt<=uu1+radio-1;xt+=step)
  1958. if(map[yt][xt]==0) 
  1959. {
  1960. if(pos==NULL)  return;
  1961.         if(xt>=0&&yt>=0&&xt<=(MapWidth-1)&&yt<=(MapHeight-1))
  1962.             {
  1963. ttUnit=(Unit*)ChosedGroup.UnitList.GetNext(pos); 
  1964. uy=ttUnit->y;ux=ttUnit->x;
  1965. for(j=uy;j<=uy+uh-1;j++) for(i=ux;i<=ux+uw-1;i++) {if(map[j][i]==3) map[j][i]=0; }
  1966.         if(!ttUnit->Seek(xt,yt))  
  1967.     for(j=uy;j<=uy+uh-1;j++) for(i=ux;i<=ux+uw-1;i++) {if(map[j][i]!=2) map[j][i]=3; }
  1968. }
  1969. }
  1970.    yt=uu2+radio;
  1971.    for(xt=uu1-radio+1;xt<=uu1+radio-1;xt+=step)
  1972. if(map[yt][xt]==0) 
  1973. {
  1974. if(xt>=0&&yt>=0&&xt<=(MapWidth-1)&&yt<=(MapHeight-1))
  1975.             {
  1976. if(pos==NULL)  return;
  1977.             ttUnit=(Unit*)ChosedGroup.UnitList.GetNext(pos); 
  1978.     uy=ttUnit->y;ux=ttUnit->x;
  1979.     for(j=uy;j<=uy+uh-1;j++) for(i=ux;i<=ux+uw-1;i++) {if(map[j][i]==3) map[j][i]=0; }
  1980.             if(!ttUnit->Seek(xt,yt))  
  1981.         for(j=uy;j<=uy+uh-1;j++) for(i=ux;i<=ux+uw-1;i++) {if(map[j][i]!=2) map[j][i]=3; }
  1982. }
  1983. }
  1984.   }
  1985.  
  1986.     /*n=2;
  1987. Building[n].width=8;
  1988. Building[n].height=5;
  1989. Building[n].name="Water";
  1990. Building[n].RIDnormal=218;
  1991. int arraytemp2[MAXH][MAXL]={0,0,1,1,1,0,0,0,0,0,0,0,0,
  1992.                         0,1,1,1,1,1,0,0,0,0,0,0,0,
  1993.             1,1,1,1,1,1,0,1,0,0,0,0,0,
  1994.             0,1,1,1,1,1,1,1,0,0,0,0,0,
  1995.             0,0,0,1,1,1,1,0,0,0,0,0,0,
  1996.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  1997.                             0,0,0,0,0,0,0,0,0,0,0,0,0,  
  1998.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  1999.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  2000.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  2001.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  2002.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  2003.                             0,0,0,0,0,0,0,0,0,0,0,0,0}; 
  2004. Building[n].Init(arraytemp2);
  2005.     n=3;   
  2006.     Building[n].width=3;
  2007. Building[n].height=6;
  2008. Building[n].name="Tower2";
  2009. Building[n].RIDnormal=217;
  2010. int arraytemp3[MAXH][MAXL]={0,2,0,0,0,0,0,0,0,0,0,0,0,
  2011.                         2,2,2,0,0,0,0,0,0,0,0,0,0,
  2012.             2,2,2,0,0,0,0,0,0,0,0,0,0,
  2013.             2,2,2,0,0,0,0,0,0,0,0,0,0,
  2014.             1,1,1,0,0,0,0,0,0,0,0,0,0,
  2015.                             0,1,0,0,0,0,0,0,0,0,0,0,0,
  2016.                             0,0,0,0,0,0,0,0,0,0,0,0,0,  
  2017.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  2018.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  2019.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  2020.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  2021.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  2022.                             0,0,0,0,0,0,0,0,0,0,0,0,0 }; 
  2023. Building[n].Init(arraytemp3);
  2024.     n=4;   
  2025.     Building[n].width=5;
  2026. Building[n].height=5;
  2027. Building[n].name="House1";
  2028. Building[n].RIDnormal=186;
  2029. int arraytemp4[MAXH][MAXL]={2,2,2,2,2,0,0,0,0,0,0,0,0,
  2030.                         2,2,1,1,1,0,0,0,0,0,0,0,0,
  2031.             1,1,1,1,1,0,0,0,0,0,0,0,0,
  2032.             1,1,1,0,0,0,0,0,0,0,0,0,0,
  2033.             0,0,0,0,0,0,0,0,0,0,0,0,0,
  2034.                             0,0,0,0,0,0,0,0,0,0,0,0,0,
  2035.                             0,0,0,0,0,0,0,0,0,0,0,0,0,  
  2036.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  2037.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  2038.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  2039.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  2040.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  2041.                             0,0,0,0,0,0,0,0,0,0,0,0,0 }; 
  2042. Building[n].Init(arraytemp4);
  2043.     n=5;   
  2044.     Building[n].width=5;
  2045. Building[n].height=5;
  2046. Building[n].name="House2";
  2047. Building[n].RIDnormal=186;
  2048. int arraytemp5[MAXH][MAXL]={2,2,2,2,2,0,0,0,0,0,0,0,0,
  2049.                         2,2,1,1,1,0,0,0,0,0,0,0,0,
  2050.             1,1,1,1,1,0,0,0,0,0,0,0,0,
  2051.             1,1,1,0,0,0,0,0,0,0,0,0,0,
  2052.             0,0,0,0,0,0,0,0,0,0,0,0,0,
  2053.                             0,0,0,0,0,0,0,0,0,0,0,0,0,
  2054.                             0,0,0,0,0,0,0,0,0,0,0,0,0,  
  2055.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  2056.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  2057.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  2058.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  2059.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  2060.                             0,0,0,0,0,0,0,0,0,0,0,0,0 }; 
  2061. Building[n].Init(arraytemp5);
  2062.     n=6;   
  2063.     Building[n].width=8;
  2064. Building[n].height=11;
  2065. Building[n].name="House2";
  2066. Building[n].RIDnormal=219;
  2067. int arraytemp6[MAXH][MAXL]={0,2,2,2,2,2,0,0,0,0,0,0,0,
  2068.                         0,2,2,2,2,2,0,0,0,0,0,0,0,
  2069.             0,2,2,2,2,0,0,0,0,0,0,0,0,
  2070.             0,2,2,2,2,2,0,0,0,0,0,0,0,
  2071.             0,0,0,2,2,2,0,0,0,0,0,0,0,
  2072.                             0,0,0,2,2,2,0,0,0,0,0,0,0,
  2073.                             0,0,0,1,1,0,0,0,0,0,0,0,0,  
  2074.                             0,1,1,1,1,1,0,0,0,0,0,0,0, 
  2075.                             1,1,1,1,1,1,1,1,0,0,0,0,0, 
  2076.                             0,1,1,1,1,1,1,0,0,0,0,0,0, 
  2077.                             0,0,1,1,1,0,0,0,0,0,0,0,0, 
  2078.                             0,0,0,0,0,0,0,0,0,0,0,0,0, 
  2079.                             0,0,0,0,0,0,0,0,0,0,0,0,0 }; 
  2080.    Building[n].Init(arraytemp6);
  2081.   
  2082.   
  2083.   
  2084.   
  2085.   if(abs(xt-ux)<=13&&abs(yt-uy)<=13) 
  2086.  {
  2087.          ShowInt(30,530,777);
  2088.          Weapon *ttWeapon;
  2089.          ttWeapon=new Weapon;
  2090.  ttWeapon->newx=ux*squaresize;
  2091.  ttWeapon->newy=uy*squaresize;
  2092.  ttWeapon->endx=xt*squaresize;
  2093.  ttWeapon->endy=yt*squaresize;
  2094.  ttWeapon->Init(ux,uy,xt,yt,Missle);
  2095.  ttWeapon->MoveSign=TRUE;
  2096.  AllWeapons.WeaponList.AddTail(ttWeapon);
  2097.  }*/
  2098.