home *** CD-ROM | disk | FTP | other *** search
/ WarCraft 2000 - Nuclear Epidemic / W2000.nrg / SOURCE.War2000 / War2000.cpp < prev    next >
C/C++ Source or Header  |  1998-11-26  |  32KB  |  1,442 lines

  1. /*==========================================================================
  2.  *
  3.  *  1997-1998. Andrew (GSC).
  4.  *
  5.  *  The Main cycle of the strategical game
  6.  *  
  7.  *
  8.  ***************************************************************************/
  9.  
  10. #define NAME "Kernel"
  11. #define TITLE "Game"
  12. int LASTRAND,LASTIND;
  13.  
  14. //#define WIN32_LEAN_AND_MEAN
  15. #include "ddini.h"
  16. #include "ResFile.h"
  17. #include "FastDraw.h"
  18. #include "mgraph.h"
  19. #include "mouse.h"
  20. #include "menu.h"
  21. #include "MapDiscr.h"
  22. #include "multipl.h"
  23. #include "fog.h"
  24. #include "walls.h"
  25. #include "Nature.h"
  26. #include <time.h>
  27. #include "Nucl.h"
  28. #include "TopZones.h"
  29. #include "Megapolis.h"
  30. #include "dialogs.h"
  31. #include <assert.h>
  32. #include "MapEdit.h"
  33. #include "3DSurf.h"
  34. #include "CDirSnd.h"
  35. #include "GSound.h"
  36. #include "Video.h"
  37. #include "dplay.h"
  38. #include "process.h"
  39. #include "direct.h"
  40. extern bool ChangeNation;
  41. extern bool MultiTvar;
  42. extern DPID MyDPID;
  43. extern DPID ServerDPID;
  44. extern int curdx;
  45. extern int curdy;
  46. extern bool CheapMode;
  47. extern int WarSound;
  48. extern int WorkSound;
  49. extern int OrderSound;
  50. extern int MidiSound;
  51. extern int FPSTime;
  52. extern int NMyUnits;
  53. extern int NThemUnits;
  54. void MFix();
  55. void WinnerControl();
  56. bool fixed;
  57. bool MUSTDRAW;
  58. int Shifter;
  59. int Multip;
  60. bool MiniMode;
  61. int AutoTime;
  62. extern int sfVersion;
  63. void OnMouseMoveRedraw();
  64. void GetForces();
  65. bool HealthMode;
  66. #define TIMER_ID        1
  67. #define TIMER_RATE      50
  68. extern int MenuType;
  69. extern bool MakeMenu;
  70. extern byte SpecCmd;
  71. extern int RealLx;
  72. extern int RealLy;
  73. extern bool BuildMode;
  74. extern bool CINFMOD;
  75. extern word rpos;
  76. extern bool realLpressed;
  77. extern bool realRpressed;
  78. extern int MaxAllowedComputerAI;
  79. extern bool GetCoord;
  80. extern int FogMode;
  81. extern CDirSound* CDS;
  82. void ProcessUFO();
  83. void SaveGame(char* fnm,char* gg,int ID);
  84. void LoadGame(char* fnm);
  85. void makeFden();
  86. byte Quality;
  87. HugeExplosion HE;
  88. bool FASTMODE;
  89. void InitDialogs();
  90. int processMainMenu();
  91. //╬≡παφΦτα÷Φ  ∩α≡αδδσδⁿφε Γ√∩εδφ σ∞√⌡ ταΣα≈
  92. typedef void EventHandPro(void*);
  93. void HandleMultiplayer();
  94. bool EgoFlag;
  95. int tmtmt;
  96. bool MEditMode;
  97. bool EditMapMode;
  98. bool HeightEditMode;
  99. bool HelpMode;
  100. bool ChoosePosition;
  101. CDirSound CDIRSND;
  102. int  ReliefBrush;
  103. int  TerrBrush;
  104. int BlobMode;
  105. int MaxSizeX;
  106. int MaxSizeY;
  107. byte EditMedia;
  108. extern int curptr;
  109. void InitDestn();
  110. Menu MainMenu;
  111. Menu Options;
  112. Menu LoadFile;
  113. Menu About;
  114. word Creator;
  115. Nation WEP;
  116. Weapon FlyFire1;
  117. Weapon Vibux1;
  118. Weapon Fire1;
  119. Weapon Lasso;
  120. Weapon Molnia;
  121. Weapon Sphere;
  122. Weapon MolniaVibux;
  123. Weapon Arrow;
  124. Weapon Flystar;
  125. Weapon Magvib;
  126. byte PlayerMask;
  127. Legion LG;
  128. City CITY[8];
  129. /*City CITY1;
  130. City CITY2;
  131. City CITY3;
  132. City CITY4;
  133. City CITY5;
  134. City CITY6;
  135. City CITY7;*/
  136. static word MsPerFrame=40;
  137. int Flips;
  138. int LastKey;
  139. bool KeyPressed;
  140. int NMONS;
  141. bool DeathMode;
  142. bool AttackMode;
  143. bool InfoMode;
  144. void SetEgoFlag(bool EgoMod);
  145. extern word PlayerMenuMode;
  146. WIN32_FIND_DATA findfi;
  147. struct EventsTag{
  148.     EventHandPro* Pro;
  149.     int    Type;
  150.     int    Handle;
  151.     bool Blocking;
  152.     void* Param;
  153. };
  154. #define maxTask 32
  155. void PlayerMenuWork();
  156. EventsTag Events[maxTask];
  157. int RegisterEventHandler(EventHandPro* pro,int Type,void* param){
  158.     for(int i=0;int(Events[i].Pro)&&i<maxTask;i++);
  159.     if(i>=maxTask)return -1;
  160.     Events[i].Pro=pro;
  161.     Events[i].Type=Type;
  162.     Events[i].Handle=i;
  163.     Events[i].Blocking=false;
  164.     Events[i].Param=param;
  165.     return i;
  166. };
  167. void CloseEventHandler(int i){
  168.     memset(&Events[i],0,sizeof Events[i]);
  169. };
  170.  
  171. HWND                hwnd;
  172. RLCTable IMM;
  173. RLCTable mIMM;
  174. RLCTable rlc;
  175. RLCFont rlf;
  176. RLCFont rlf1;
  177. RLCTable mon;
  178. RLCTable rlc_s;
  179. RLCFont rlf_s;
  180. RLCFont rlf1_s;
  181. RLCTable mon_s;
  182. RLCTable RCross;
  183. RLCTable mRCross;
  184. //fonts
  185. RLCTable t32x32r;
  186. RLCFont  f32x32r;
  187. RLCTable t32x32g;
  188. RLCFont  f32x32g;
  189. RLCTable t32x32w;
  190. RLCFont  f32x32w;
  191. RLCTable t16x16r;
  192. RLCFont  f16x16r;
  193. RLCTable t16x16y;
  194. RLCFont  f16x16y;
  195. RLCTable t16x16w;
  196. RLCFont  f16x16w;
  197. RLCTable t16x16g;
  198. RLCFont  f16x16g;
  199. int cadr;
  200. int tima;
  201. int tmtim;
  202. /*
  203.  * Timer Callback 
  204.  */
  205. int xxx;
  206. void ShowFon1();
  207. void WaterCorrection();
  208. void TimerProc(void)
  209. {
  210.     
  211.     //LockSurface();
  212.     //FlipPages();
  213.     
  214.     if(PlayerMenuMode==1){
  215.         ShowFon1();
  216.         for(int j=0;j<maxTask;j++)
  217.         if(Events[j].Pro)(*(Events[j].Pro))(Events[j].Param);
  218.         SetRLCWindow(0,1,MaxSizeX,RSCRSizeY-1,ScrWidth);
  219.         //-ShowMPtr();
  220.     }else{
  221.         //ShowMPtr();
  222.         ShowMap();
  223.         SetRLCWindow(0,1,MaxSizeY,RSCRSizeY-1,ScrWidth);
  224.         //-ShowMPtr();
  225.     };
  226.     HandleMouse(mouseX,mouseY);
  227.     MFix();
  228.     FlipPages();
  229.     //UnlockSurface();
  230.     
  231.     
  232. }
  233. //Loading...
  234. void LoadWeapon();
  235. void LoadNation(char* fn,byte msk,byte NIndex);
  236. void Loading()
  237. {
  238.     LoadFon();
  239.     LoadRDS();
  240.     LoadFog();
  241.     LoadTiles();
  242.     LoadWalls();
  243.     LoadLock();
  244.     LoadMap("map13h.mpf");
  245.     LoadPointer("cursor_y.rlc");
  246.     LoadMonsters();
  247.     LoadWeapon();
  248.     LoadNation("PEOPLES.nds",1,0);
  249.     LoadNation("Orcs.nds",2,1);
  250.     LoadNation("PEOPLES.nds",4,2);
  251.     LoadNation("Orcs.nds",8,3);
  252.     LoadNation("orcs.nds",16,4);
  253.     LoadNation("PEOPLES.nds",32,5);
  254.     LoadNation("orcs.nds",64,6);
  255.     LoadNation("PEOPLES.nds",128,7);
  256.     CITY[0].CreateCity(200,30,0);
  257.     CITY[1].CreateCity(190,130,1);
  258.     CITY[2].CreateCity(190,90,2);
  259.     CITY[3].CreateCity(100,80,3);
  260.     CITY[4].CreateCity(50,70,4);
  261.     CITY[5].CreateCity(180,50,5);
  262.     CITY[6].CreateCity(50,180,6);
  263.     CITY[7].CreateCity(180,170,7);
  264.     CITY[4].IntellectEnabled=true;
  265.     CITY[5].IntellectEnabled=true;
  266.     CITY[6].IntellectEnabled=true;
  267.     CITY[7].IntellectEnabled=true;
  268.     LoadPalettes();
  269.     InitPrpBar();
  270.     MyNation=0;
  271.     InitExplosions();
  272.     //HE.CreateExpl(20,20,64,256*8,300);
  273.     //CreateOilSpotAnyway();
  274.     //CreateOilSpotAnyway();
  275.     //CreateOilSpotAnyway();
  276.     //CreateOilSpotAnyway();
  277.     //CreateOilSpotAnyway();
  278. };
  279. void SaveScreen(){
  280.     ResFile ff1=RRewrite("screen.raw");
  281.     for(int i=0;i<RSCRSizeY;i++){
  282.         char* pos=(char*)(int(ScreenPtr)+i*SCRSizeX);
  283.         RBlockWrite(ff1,pos,RSCRSizeX);
  284.     };
  285.     RClose(ff1);
  286. };
  287. /*
  288.  * finiObjects
  289.  *
  290.  * finished with all objects we use; release them
  291.  */
  292. static void finiObjects( void )
  293. {
  294.    FreeDDObjects();
  295. } /* finiObjects */
  296.  
  297.  
  298. void MyMCINotify(HWND hwnd,WPARAM wParam,LPARAM lParam)
  299. {
  300.   if((wParam==MCI_NOTIFY_SUCCESSFUL)&&(lParam==LPARAM(wAVIDeviceID)))
  301.   {
  302.       CloseAVI(hwnd);
  303.       Lpressed=true;
  304.   }
  305.   if((wParam==MCI_NOTIFY_SUCCESSFUL)&&(lParam==LPARAM(wMIDDeviceID)))
  306.   {
  307.       CloseMIDI(hwnd);
  308.   }
  309. };
  310.  
  311. long FAR PASCAL WindowProc( HWND hWnd, UINT message, 
  312.                             WPARAM wParam, LPARAM lParam )
  313. {
  314.     PAINTSTRUCT ps;
  315.     RECT        rc;
  316.     SIZE        size;
  317.     static BYTE phase = 0;
  318. //    HDC         hdc;
  319.     
  320.  
  321.     switch( message )
  322.     {
  323.     case MM_MCINOTIFY:
  324.         MyMCINotify(hWnd,wParam,lParam);
  325.         break;
  326.     case WM_LBUTTONDOWN:
  327.         wParam=wParam|MK_LBUTTON;
  328.         Lpressed=true;
  329.         realLpressed=true;
  330.         fixed=false;
  331.         //xLpressed=true;
  332.         SetMPtr(LOWORD(lParam),HIWORD(lParam),wParam);
  333.         break;
  334.     case WM_LBUTTONUP:
  335.         wParam=wParam&!MK_LBUTTON;
  336.         if(fixed)Lpressed=false;
  337.         realLpressed=false;
  338.         //xLpressed=false;
  339.         SetMPtr(LOWORD(lParam),HIWORD(lParam),wParam);
  340.         break;
  341.     case WM_RBUTTONDOWN:
  342.         wParam=wParam|MK_RBUTTON;
  343.         Rpressed=true;
  344.         realRpressed=true;
  345.         fixed=false;
  346.         //xRpressed=true;
  347.         SetMPtr(LOWORD(lParam),HIWORD(lParam),wParam);
  348.         break;
  349.     case WM_RBUTTONUP:
  350.         wParam=wParam&!MK_RBUTTON;
  351.         Rpressed=false;
  352.         if(fixed)Rpressed=false;
  353.         //xRpressed=false;
  354.         SetMPtr(LOWORD(lParam),HIWORD(lParam),wParam);
  355.         break;
  356.     case WM_MOUSEMOVE:
  357.         if(LOWORD(lParam)!=mouseX||HIWORD(lParam)!=mouseY){
  358.             SetMPtr(LOWORD(lParam),HIWORD(lParam),wParam);
  359.             OnMouseMoveRedraw();
  360.         };
  361.         //ShowMPtra();
  362.         break;
  363.     case WM_ACTIVATEAPP:
  364.         bActive = wParam;
  365.         //if(bActive)MUSTDRAW=true;
  366.         break;
  367.  
  368.     case WM_CREATE:
  369.         break;
  370.  
  371.     case WM_SETCURSOR:
  372.         SetCursor(NULL);
  373.         return TRUE;
  374.  
  375.     case WM_TIMER:
  376.         // Flip surfaces
  377.         if( bActive )
  378.         {
  379.             //ShowMPtra();
  380.             //TimerProc();
  381.         }
  382.         break;
  383.     
  384.     
  385.     case WM_KEYDOWN:
  386.         LastKey=wParam;
  387.         KeyPressed=true;
  388.         break;
  389.     case WM_PAINT:
  390.         BeginPaint( hWnd, &ps );
  391.         GetClientRect(hWnd, &rc);
  392.         SetBkColor( ps.hdc, RGB( 0, 0, 255 ) );
  393.         SetTextColor( ps.hdc, RGB( 255, 255, 0 ) );
  394.         EndPaint( hWnd, &ps );
  395.         break;
  396.  
  397.     case WM_DESTROY:
  398.         finiObjects();
  399.         PostQuitMessage( 0 );
  400.         break;
  401.     }
  402.  
  403.     return DefWindowProc(hWnd, message, wParam, lParam);
  404.  
  405. } /* WindowProc */
  406.  
  407. /*
  408.  * doInit - do work required for every instance of the application:
  409.  *                create the window, initialize data
  410.  */
  411. void EditorKeyCheck();
  412. void GameKeyCheck(){
  413.     if(EditMapMode){
  414.         EditorKeyCheck();
  415.         return;
  416.     };
  417.     if(KeyPressed){
  418.         KeyPressed=false;
  419.         int wParam=LastKey;
  420.             switch( wParam ){
  421.                 case VK_ESCAPE:
  422.                     BuildMode=false;
  423.                     BuildWall=false;
  424.                     GetCoord=false;
  425.                     curptr=0;
  426.                     curdx=0;
  427.                     curdy=0;
  428.                     //if(PlayerMenuMode==2)
  429.                     //MainMenu.ShowModal();
  430.                     //Options.ShowModal();
  431.                     break;
  432.                 //case 'G':
  433.                 //    smapx+=16;
  434.                 //    smaplx--;
  435.                 //    smapy+=16;
  436.                 //    smaply--;
  437.                 //    ShowFon();
  438.                 //    break;
  439.                 //case 'H':
  440.                 //    smapx-=16;
  441.                 //    smaplx++;
  442.                 //    smapy-=16;
  443.                 //    smaply++;
  444.                 //    ShowFon();
  445.                 //    break;
  446.                 case 'V':
  447.                     //SaveGame("save1.wsf","my game");
  448.                     break;
  449.                 case 'M':
  450.                     //LoadGame("save1.wsf");
  451.                     MEditMode=!MEditMode;
  452.                     if(!MEditMode)BlobMode=0;
  453.                     break;
  454.                case VK_F12:
  455.                     //UnlockSurface();
  456.                     //CloseExplosions();
  457.                     //ShutdownMultiplayer();
  458.                     //PostMessage(hwnd, WM_CLOSE, 0, 0);
  459.                     MenuType=1;
  460.                     MakeMenu=true;
  461.                     break;
  462.                 case VK_F1:
  463.                     MenuType=4;
  464.                     MakeMenu=true;
  465.                     //Creator=0;
  466.                     break;
  467.                 case 192:
  468.                     HealthMode=!HealthMode;
  469.                     break;
  470.                 case VK_F2:
  471.                     //Creator=1;
  472.                     break;
  473.                 case VK_F3:
  474.                     //Creator=2;
  475.                     break;
  476.                 case VK_F4:
  477.                     //Creator=3;
  478.                     break;
  479.                 case VK_F5:
  480.                     //Creator=5;
  481.                     break;
  482.                 case VK_F6:
  483.                     //Creator=11;
  484.                     break;
  485.                 case VK_F7:
  486.                     //Creator=13;
  487.                     break;
  488.                 case VK_F8:
  489.                     //Creator=15;
  490.                     break;
  491.                 case 'D':
  492.                     if(GetKeyState(VK_CONTROL)&0x8000)
  493.                         SpecCmd=200;//Die
  494.                     else SpecCmd=201;//Sit down
  495.                     break;
  496.                 case 'A':
  497.                     if(GetKeyState(VK_CONTROL)&0x8000)SpecCmd=1;
  498.                     else SpecCmd=2;
  499.                     break;
  500.                 case 'S':
  501.                     SpecCmd=2;
  502.                     break;
  503.                 case 'W':
  504.                     SetBuildWallMode();
  505.                     break;
  506.                 case 'J':
  507.                     //RSCRSizeX++;
  508.                     break;
  509.                 case 'K':
  510.                     //Quality++;
  511.                     //if(Quality>=4)Quality=0;
  512.                     //RSCRSizeX--;
  513.                     break;
  514.                 case 'N':
  515.                     //switch(RSCRSizeX){
  516.                     //    case 800:RSCRSizeX=1024;
  517.                     //            break;
  518.                     //    case 1024:RSCRSizeX=800+32;
  519.                     //            break;
  520.                     //    case 1280:RSCRSizeX=1600;
  521.                     //        break;
  522.                     //    case 1600:RSCRSizeX=800;
  523.                     //        break;
  524.                     //    default:
  525.                     //        RSCRSizeX=800;
  526.                     //};
  527.                     /*if(RSCRSizeX!=1024)RSCRSizeX=1024;
  528.                     else RSCRSizeX=800;*/
  529.                     break;
  530.                 case 'C':
  531.                     CINFMOD=!CINFMOD;
  532.                     break;
  533.                 //case 'F':
  534.                 //    //FASTMODE=true;
  535.                 //    break;
  536.                 case 'G':
  537.                     SaveScreen();
  538.                     break;
  539.                 //    //FASTMODE=false;
  540.                 //    break;
  541.                 case 'X':
  542.                     if(GetKeyState(VK_CONTROL)&0x8000)SpecCmd=5;
  543.                     else SpecCmd=6;
  544.                     break;
  545.                 case 'Q':
  546.                     if(GetKeyState(VK_CONTROL)&0x8000)SpecCmd=3;
  547.                     else SpecCmd=4;
  548.                     break;
  549.                 case 'B':
  550.                     if(GetKeyState(VK_CONTROL)&0x8000)SpecCmd=9;
  551.                     else SpecCmd=10;
  552.                     break;
  553.                 case 'Z':
  554.                     if(GetKeyState(VK_CONTROL)&0x8000)SpecCmd=11;
  555.                     else SpecCmd=12;
  556.                     break;
  557.                 case 'F':
  558.                     if(GetKeyState(VK_CONTROL)&0x8000)SpecCmd=13;
  559.                     else SpecCmd=14;
  560.                     break;
  561.                 case VK_F9:
  562.                     Creator=255;
  563.                     break;
  564.                 case VK_NUMPAD1:
  565.                     if(MEditMode)EditMedia=0;
  566.                     else{
  567.                         if(ChangeNation)MyNation=0;
  568.                         PlayerMask=1;
  569.                     };
  570.                     break;
  571.                 case VK_NUMPAD2:
  572.                     if(MEditMode)EditMedia=1;
  573.                     else{
  574.                         if(ChangeNation)MyNation=1;
  575.                         PlayerMask=2;
  576.                     };
  577.                     break;
  578.                 case VK_NUMPAD3:
  579.                     if(MEditMode)EditMedia=2;
  580.                     else{
  581.                         if(ChangeNation)MyNation=2;
  582.                         PlayerMask=4;
  583.                     };
  584.                     break;
  585.                 case VK_NUMPAD4:
  586.                     if(MEditMode)EditMedia=3;
  587.                     else{
  588.                         if(ChangeNation)MyNation=3;
  589.                         PlayerMask=8;
  590.                     };
  591.                     break;
  592.                 case VK_NUMPAD5:
  593.                     if(MEditMode)EditMedia=4;
  594.                     else{
  595.                         if(ChangeNation)MyNation=4;
  596.                         PlayerMask=16;
  597.                     };
  598.                     break;
  599.                 case VK_NUMPAD6:
  600.                     if(MEditMode)BlobMode=1;
  601.                     else{
  602.                         if(ChangeNation)MyNation=5;
  603.                         PlayerMask=32;
  604.                     };
  605.                     break;
  606.                 case VK_NUMPAD7:
  607.                     if(MEditMode)BlobMode=-1;
  608.                     else{
  609.                         if(ChangeNation)MyNation=6;
  610.                         PlayerMask=64;
  611.                     };
  612.                     break;
  613.                 case VK_NUMPAD8:
  614.                     if(ChangeNation)MyNation=7;
  615.                     PlayerMask=128;
  616.                     break;
  617.                 case 'I':
  618.                     InfoMode=!InfoMode;
  619.                 break;
  620.                 case VK_CAPITAL:
  621.                     EgoFlag=!EgoFlag;
  622.                     SetEgoFlag(EgoFlag);
  623.                     break;
  624.                 case 'O':
  625.                     if(MsPerFrame)MsPerFrame--;
  626.                     break;
  627.                 case 'P':
  628.                     //MsPerFrame++;
  629.                     //if(GetKeyState(VK_CONTROL)&0x8000)RotatePhiI();
  630.                     //RotatePhi();
  631.                     if(MultiTvar){
  632.                         MakeMenu=true;
  633.                         MenuType=2;
  634.                     };
  635.                     break;
  636.                 case 13:
  637.                     MakeMenu=true;
  638.                     MenuType=3;
  639.                     break;
  640.                 case 'L':
  641.                     //LG.CreateLegionFromSelection(PlayerMask);
  642.                     if(!MiniMode)SetMiniMode();
  643.                     else ClearMiniMode();
  644.                     break;
  645.                 default:
  646.                     if(wParam>='0'&&wParam<='9'){
  647.                         if(GetKeyState(VK_CONTROL)&0x8000)
  648.                             CmdMemSelection(MyNation,wParam-'0');
  649.                         else CmdRememSelection(MyNation,wParam-'0');
  650.                     };
  651.              };
  652.     };
  653. };
  654. void EditorKeyCheck(){
  655.     if(KeyPressed){
  656.         KeyPressed=false;
  657.         int wParam=LastKey;
  658.             switch( wParam ){
  659.                 case '1':
  660.                     if(HeightEditMode)ReliefBrush=1;
  661.                     else TerrBrush=1;
  662.                     break;
  663.                 case '2':
  664.                     if(HeightEditMode)ReliefBrush=2;
  665.                     else TerrBrush=2;
  666.                     break;
  667.                 case '3':
  668.                     if(HeightEditMode)ReliefBrush=1;
  669.                     else TerrBrush=3;
  670.                     break;
  671.                 case '4':
  672.                     if(HeightEditMode)ReliefBrush=4;
  673.                     else TerrBrush=4;
  674.                     break;
  675.                 case '5':
  676.                     if(HeightEditMode)ReliefBrush=5;
  677.                     else TerrBrush=5;
  678.                     break;
  679.                 case '6':
  680.                     if(HeightEditMode)ReliefBrush=6;
  681.                     else TerrBrush=6;
  682.                     break;
  683.                 case '7':
  684.                     if(HeightEditMode)ReliefBrush=7;
  685.                     else TerrBrush=7;
  686.                     break;
  687.                 case '8':
  688.                     if(HeightEditMode)ReliefBrush=8;
  689.                     else TerrBrush=8;
  690.                     break;
  691.                 case '9':
  692.                     if(HeightEditMode)ReliefBrush=9;
  693.                     else TerrBrush=9;
  694.                     break;
  695.                 case VK_ESCAPE:
  696.                     BuildMode=false;
  697.                     BuildWall=false;
  698.                     GetCoord=false;
  699.                     curptr=0;
  700.                     curdx=0;
  701.                     curdy=0;
  702.                     //if(PlayerMenuMode==2)
  703.                     //MainMenu.ShowModal();
  704.                     //Options.ShowModal();
  705.                     break;
  706.                case VK_F12:
  707.                     //UnlockSurface();
  708.                     //CloseExplosions();
  709.                     //ShutdownMultiplayer();
  710.                     //PostMessage(hwnd, WM_CLOSE, 0, 0);
  711.                     MenuType=1;
  712.                     MakeMenu=true;
  713.                     break;
  714.                 case 192:
  715.                     HealthMode=!HealthMode;
  716.                     break;
  717.                case VK_F1:
  718.                     HelpMode=!HelpMode;
  719.                     break;
  720.                case VK_F2:
  721.                     HeightEditMode=false;
  722.                     MEditMode=true;
  723.                     EditMedia=0;
  724.                     break;
  725.                 case VK_F3:
  726.                     HeightEditMode=false;
  727.                     MEditMode=true;
  728.                     EditMedia=1;
  729.                     break;
  730.                 case VK_F4:
  731.                     HeightEditMode=false;
  732.                     MEditMode=true;
  733.                     EditMedia=2;
  734.                     break;
  735.                 case VK_F5:
  736.                     HeightEditMode=false;
  737.                     MEditMode=true;
  738.                     EditMedia=3;
  739.                     break;
  740.                 case 'F':
  741.                     HeightEditMode=false;
  742.                     MEditMode=true;
  743.                     EditMedia=5;
  744.                     break;
  745.                 case VK_F6:
  746.                     HeightEditMode=false;
  747.                     MEditMode=true;
  748.                     EditMedia=4;
  749.                     break;
  750.                 case VK_F7:
  751.                     HeightEditMode=true;
  752.                     MEditMode=false;
  753.                     BlobMode=1;
  754.                     break;
  755.                 case VK_F8:
  756.                     HeightEditMode=true;
  757.                     MEditMode=false;
  758.                     BlobMode=-1;
  759.                     break;
  760.                 case 'N':
  761.                     HeightEditMode=false;
  762.                     MEditMode=true;
  763.                     EditMedia=5;
  764.                     break;
  765.                 case 'D':
  766.                     if(GetKeyState(VK_CONTROL)&0x8000)
  767.                         SpecCmd=200;//Die
  768.                     else SpecCmd=201;//Sit down
  769.                     break;
  770.                 case 'A':
  771.                     if(GetKeyState(VK_CONTROL)&0x8000)SpecCmd=1;
  772.                     else SpecCmd=2;
  773.                     break;
  774.                 case 'S':
  775.                     MEditMode=false;
  776.                     SpecCmd=2;
  777.                     break;
  778.                 case 'W':
  779.                     MEditMode=false;
  780.                     HeightEditMode=false;
  781.                     SetBuildWallMode();
  782.                     break;
  783.                     /*
  784.                 case 'N':
  785.                     switch(RSCRSizeX){
  786.                         case 800:RSCRSizeX=1024;
  787.                                 break;
  788.                         case 1024:RSCRSizeX=800+32;
  789.                                 break;
  790.                         case 1280:RSCRSizeX=1600;
  791.                             break;
  792.                         case 1600:RSCRSizeX=800;
  793.                             break;
  794.                         default:
  795.                             RSCRSizeX=800;
  796.                     };*/
  797.                     /*if(RSCRSizeX!=1024)RSCRSizeX=1024;
  798.                     else RSCRSizeX=800;*/
  799.                     //break;
  800.                 //case 'C':
  801.                 //    CINFMOD=!CINFMOD;
  802.                 //    break;
  803.                 case 'X':
  804.                     if(GetKeyState(VK_CONTROL)&0x8000)SpecCmd=5;
  805.                     else SpecCmd=6;
  806.                     break;
  807.                 case 'Q':
  808.                     if(GetKeyState(VK_CONTROL)&0x8000)SpecCmd=3;
  809.                     else SpecCmd=4;
  810.                     break;
  811.                 case 'B':
  812.                     if(GetKeyState(VK_CONTROL)&0x8000)SpecCmd=9;
  813.                     else SpecCmd=10;
  814.                     break;
  815.                 case 'Z':
  816.                     if(GetKeyState(VK_CONTROL)&0x8000)SpecCmd=11;
  817.                     else SpecCmd=12;
  818.                     break;
  819.                 //case VK_F11:
  820.                 //    WaterCorrection();
  821.                 //    break;
  822.                 case VK_F9:
  823.                     MEditMode=false;
  824.                     HeightEditMode=false;
  825.                     Creator=255;
  826.                     break;
  827.                 case VK_NUMPAD1:
  828.                     MyNation=0;
  829.                     MEditMode=false;
  830.                     HeightEditMode=false;
  831.                     PlayerMask=1;
  832.                     break;
  833.                 case VK_NUMPAD2:
  834.                     MyNation=1;
  835.                     MEditMode=false;
  836.                     HeightEditMode=false;
  837.                     PlayerMask=2;
  838.                     break;
  839.                 case VK_NUMPAD3:
  840.                     MyNation=2;
  841.                     MEditMode=false;
  842.                     HeightEditMode=false;
  843.                     PlayerMask=4;
  844.                     break;
  845.                 case VK_NUMPAD4:
  846.                     MyNation=3;
  847.                     MEditMode=false;
  848.                     HeightEditMode=false;
  849.                     PlayerMask=8;
  850.                     break;
  851.                 case VK_NUMPAD5:
  852.                     MyNation=4;
  853.                     MEditMode=false;
  854.                     HeightEditMode=false;
  855.                     PlayerMask=16;
  856.                     break;
  857.                 case VK_NUMPAD6:
  858.                     MyNation=5;
  859.                     MEditMode=false;
  860.                     HeightEditMode=false;
  861.                     PlayerMask=32;
  862.                     break;
  863.                 case VK_NUMPAD7:
  864.                     MyNation=6;
  865.                     MEditMode=false;
  866.                     HeightEditMode=false;
  867.                     PlayerMask=64;
  868.                     break;
  869.                 case VK_NUMPAD8:
  870.                     MyNation=7;
  871.                     MEditMode=false;
  872.                     HeightEditMode=false;PlayerMask=128;
  873.                     break;
  874.                 case 'I':
  875.                     InfoMode=!InfoMode;
  876.                     break;
  877.                 case 'O':
  878.                     WaterCorrection();
  879.                     //if(MsPerFrame)MsPerFrame--;
  880.                     break;
  881.                 case 'P':
  882.                     //MsPerFrame++;
  883.                     //if(GetKeyState(VK_CONTROL)&0x8000)RotatePhiI();
  884.                     //RotatePhi();
  885.                     MEditMode=false;
  886.                     HeightEditMode=false;
  887.                     MakeMenu=true;
  888.                     MenuType=2;
  889.                     break;
  890.                 case 'R':
  891.                     MEditMode=false;
  892.                     HeightEditMode=false;
  893.                     MakeMenu=true;
  894.                     MenuType=3;
  895.                     break;
  896.                 case 'L':
  897.                     if(!MiniMode)SetMiniMode();
  898.                     else ClearMiniMode();
  899.                     MEditMode=false;
  900.                     break;
  901.                 case 'T':
  902.                     HeightEditMode=false;
  903.                     ChoosePosition=true;
  904.                     break;
  905.                 case 'G':
  906.                     SaveScreen();
  907.                     break;
  908.                 default:
  909.                     if(wParam>='0'&&wParam<='9'){
  910.                         if(GetKeyState(VK_CONTROL)&0x8000)
  911.                             CmdMemSelection(MyNation,wParam-'0');
  912.                         else CmdRememSelection(MyNation,wParam-'0');
  913.                     };
  914.              };
  915.     };
  916. };
  917. void SERROR();
  918. void SERROR1();
  919. void SERROR2();
  920. bool PalDone;
  921. bool InitScreen(){
  922.     PalDone=false;
  923.     CreateDDObjects(hwnd); 
  924.     PalDone=false;
  925.     LoadPalette("darkw.pal");
  926.     if(!DDError)
  927.     {
  928.         LockSurface();
  929.         UnlockSurface();
  930.         //LockSurface();
  931.         //UnlockSurface();
  932.         ShowCursor(true);
  933.         RECT OOO;
  934.         OOO.left=-16;
  935.         OOO.top=-16;
  936.         OOO.right=1500;
  937.         OOO.bottom=1200;
  938.         ClipCursor(&OOO);
  939.         SetCursorPos(4000,2000);//!!!!!!!!!!!!!!!!
  940.         ShowCursor(false);
  941.         OOO.left=0;
  942.         OOO.top=0;
  943.         OOO.right=RealLx-1;
  944.         OOO.bottom=RealLy-1;
  945.         ClipCursor(&OOO);
  946.         return true;
  947.     }else{
  948.         PlayEffect(0,0,0);
  949.     };
  950.     return false;
  951. };
  952. BOOL CreateRGBDDObjects(HWND hwnd);
  953. bool InitRGBScreen(){
  954.     PalDone=false;
  955.     CreateRGBDDObjects(hwnd); 
  956.     PalDone=false;
  957.     if(!DDError)
  958.     {
  959.         LockSurface();
  960.         UnlockSurface();
  961.         //LockSurface();
  962.         //UnlockSurface();
  963.         ShowCursor(true);
  964.         RECT OOO;
  965.         OOO.left=-16;
  966.         OOO.top=-16;
  967.         OOO.right=1500;
  968.         OOO.bottom=1200;
  969.         ClipCursor(&OOO);
  970.         SetCursorPos(4000,2000);//!!!!!!!!!!!!!!!!
  971.         ShowCursor(false);
  972.         OOO.left=0;
  973.         OOO.top=0;
  974.         OOO.right=RealLx-1;
  975.         OOO.bottom=RealLy-1;
  976.         ClipCursor(&OOO);
  977.         return true;
  978.     };
  979.     return false;
  980. };
  981. BOOL CreateRGB640DDObjects(HWND hwnd);
  982. bool InitRGB640Screen(){
  983.     CreateRGB640DDObjects(hwnd); 
  984.     if(!DDError)
  985.     {
  986.         LockSurface();
  987.         UnlockSurface();
  988.         //LockSurface();
  989.         //UnlockSurface();
  990.         ShowCursor(true);
  991.         RECT OOO;
  992.         OOO.left=-16;
  993.         OOO.top=-16;
  994.         OOO.right=1500;
  995.         OOO.bottom=1200;
  996.         ClipCursor(&OOO);
  997.         SetCursorPos(4000,2000);//!!!!!!!!!!!!!!!!
  998.         ShowCursor(false);
  999.         OOO.left=0;
  1000.         OOO.top=0;
  1001.         OOO.right=RealLx-1;
  1002.         OOO.bottom=RealLy-1;
  1003.         ClipCursor(&OOO);
  1004.         return true;
  1005.     };
  1006.     return false;
  1007. };
  1008. bool ProcessMessages();
  1009. bool xLockMouse;
  1010. void PlayVideo(){
  1011.     FreeDDObjects();
  1012.     //InitRGB640Screen();
  1013.     MiniMode=false;
  1014.     CDIRSND.~CDirSound();
  1015.     LPCSTR Vid=GetCDROMWithFile("Video\\warVideo.exe");
  1016.     if(strcmp(Vid,"none")){
  1017.         char fnn[128];
  1018.         char cwd[128];
  1019.         _getcwd(cwd,128);
  1020.         sprintf(fnn,"%sVideo",Vid);
  1021.         _chdir(fnn);
  1022.         sprintf(fnn,"%sVideo\\warVideo.exe",Vid);
  1023.         _spawnl(_P_WAIT,fnn,"warVideo.exe",NULL);
  1024.         _chdir(cwd);
  1025.     };
  1026. //    PlayAVI(hwnd,"e:\T_Z211.avi");
  1027. //    xLockMouse=true;
  1028. //    do{
  1029. //        ProcessMessages();
  1030. //    }while(!(KeyPressed));
  1031. //    CloseAVI(hwnd);
  1032.     Lpressed=false;
  1033.     KeyPressed=false;
  1034.     //FreeDDObjects();
  1035.     InitScreen();
  1036.     CDIRSND.CreateDirSound(hwnd);
  1037.     CDS=&CDIRSND;
  1038.     LoadSounds("SoundList.txt");
  1039.     xLockMouse=false;
  1040. };
  1041. extern bool Lpressed;
  1042. static BOOL doInit( HINSTANCE hInstance, int nCmdShow )
  1043. {
  1044.  
  1045.     WNDCLASS            wc;
  1046.     HRESULT             ddrval;
  1047.     HDC                 hdc;
  1048.     char                buf[256];
  1049.  
  1050.     /*
  1051.      * set up and register window class
  1052.      */
  1053.     wc.style = CS_HREDRAW | CS_VREDRAW;
  1054.     wc.lpfnWndProc = WindowProc;
  1055.     wc.cbClsExtra = 0;
  1056.     wc.cbWndExtra = 0;
  1057.     wc.hInstance = hInstance;
  1058.     wc.hIcon = LoadIcon( hInstance, IDI_APPLICATION );
  1059.     wc.hCursor = LoadCursor( NULL, IDC_ARROW );
  1060.     wc.hbrBackground = NULL;
  1061.     wc.lpszMenuName = NAME;
  1062.     wc.lpszClassName = NAME;
  1063.     RegisterClass( &wc );
  1064.     
  1065.     /*
  1066.      * create a window
  1067.      */
  1068.     hwnd = CreateWindowEx(
  1069.         WS_EX_APPWINDOW/*TOPMOST*/,
  1070.         NAME,
  1071.         TITLE,
  1072.         WS_POPUP,
  1073.         0, 0,
  1074.         GetSystemMetrics( SM_CXSCREEN ),
  1075.         GetSystemMetrics( SM_CYSCREEN ),
  1076.         NULL,
  1077.         NULL,
  1078.         hInstance,
  1079.         NULL );
  1080.  
  1081.     if( !hwnd )
  1082.     {
  1083.         return FALSE;
  1084.     }
  1085.     //UpdateWindow( hwnd );
  1086.     ShowWindow( hwnd, SW_SHOWNORMAL);//nCmdShow );
  1087.     UpdateWindow( hwnd );
  1088.     CDIRSND.CreateDirSound(hwnd);
  1089.     CDS=&CDIRSND;
  1090.     LoadSounds("SoundList.txt");
  1091.     //SetCapture(hwnd);
  1092.     Loading();
  1093.     //HCURSOR mcr=LoadCursorFromFile("curs1.cur");
  1094.     //SetCursor(mcr);
  1095.     //ShowCursor(true);
  1096.     SetCursorPos(4000,2000);//!!!!!!!!!!!!!!!!
  1097.     ShowCursor(false);
  1098.  
  1099.     //HANDLE hh1=LoadImage(NULL,"mcur.bmp",IMAGE_BITMAP,32,32,LR_LOADFROMFILE);
  1100.     CurrentSurface=FALSE;
  1101.     
  1102.     /*
  1103.      * create the main DirectDraw object
  1104.      */
  1105.     PalDone=false;
  1106. /*    InitScreen();
  1107.     InitRGBScreen();
  1108.     xLockMouse=true;
  1109.     ResFile ff1=RReset("war2000.raw");
  1110.     for(int i=0;i<600;i++){
  1111.         RBlockRead(ff1,(char*)(int(RealScreenPtr)+4*800*i),4*800);
  1112.     };
  1113.     RClose(ff1);
  1114.     do{
  1115.         ProcessMessages();
  1116.     }while(!(Lpressed||KeyPressed));
  1117.     xLockMouse=false;
  1118.     FreeDDObjects();*/
  1119.     KeyPressed=false;
  1120.     CreateDDObjects(hwnd); 
  1121.     LoadPalette("darkw.pal");
  1122.     if(!DDError)
  1123.     {
  1124.         //hdc=GetSDC();
  1125.         //lpDDSPrimary->ReleaseDC(hdc);
  1126.         //FlipPages();
  1127.         //hdc=GetSDC();
  1128.         //lpDDSBack->ReleaseDC(hdc);
  1129.         LockSurface();
  1130.         //ShowFon();
  1131.         //ShowMap();
  1132.         //ShowMPtr();
  1133.         UnlockSurface();
  1134.         //FlipPages();
  1135.         LockSurface();
  1136.         //ShowFon();
  1137.         //ShowMap();
  1138.         //ShowMPtr();
  1139.         UnlockSurface();
  1140.         //HCURSOR mcrs=LoadCursorFromFile("cursor1.cur");
  1141.         //SetCursor(mcrs);
  1142.         //SetCursor(mcr);
  1143.         // Create a timer to flip the pages
  1144.         ShowCursor(true);
  1145.         RECT OOO;
  1146.         OOO.left=-16;
  1147.         OOO.top=-16;
  1148.         OOO.right=1500;
  1149.         OOO.bottom=1200;
  1150.         ClipCursor(&OOO);
  1151.         SetCursorPos(4000,2000);//!!!!!!!!!!!!!!!!
  1152.         ShowCursor(false);
  1153.         OOO.left=0;
  1154.         OOO.top=0;
  1155.         OOO.right=RealLx-1;
  1156.         OOO.bottom=RealLy-1;
  1157.         ClipCursor(&OOO);
  1158.         if( SetTimer(hwnd, TIMER_ID, 20, NULL ) )
  1159.         {
  1160.             return TRUE;
  1161.         }
  1162.         //FlipPages();
  1163.     }
  1164.     wsprintf(buf, "Direct Draw Init Failed (%08lx)\n", ddrval );
  1165.     MessageBox( hwnd, buf, "ERROR", MB_OK );
  1166.     finiObjects();
  1167.     DestroyWindow( hwnd );
  1168.     return FALSE;
  1169. }; /* doInit */
  1170. void HandleAntiNuc();
  1171. void AddDestn(byte x,byte y);
  1172. int PrevTime;
  1173. void PreDrawGameProcess(){
  1174.     WinnerControl();
  1175.     PrevTime=GetTickCount();
  1176.     InitDestn();
  1177.     if(tima!=time(NULL)){
  1178.         Flips=tmtim;    
  1179.         tmtim=0;
  1180.         tima=time(NULL);
  1181.     };
  1182.     if(!(tmtmt&63)){
  1183.         LASTRAND=rando();
  1184.         LASTIND=rpos;
  1185.     };
  1186.     tmtim++;
  1187.     tmtmt++;
  1188.     GameKeyCheck();
  1189. //    GETALL();
  1190.     NMONS=0;
  1191.     int tmm=tmtmt&7;
  1192.     if(!tmm)CITY[0].ProcessCreation();
  1193.     if(tmm==1)CITY[1].ProcessCreation();
  1194.     if(tmm==2)CITY[2].ProcessCreation();
  1195.     if(tmm==3)CITY[3].ProcessCreation();
  1196.     if(tmm==4)CITY[4].ProcessCreation();
  1197.     if(tmm==5)CITY[5].ProcessCreation();
  1198.     if(tmm==6)CITY[6].ProcessCreation();
  1199.     if(tmm==7)CITY[7].ProcessCreation();
  1200.     //Computer AI handling
  1201.     if(tmm==0){
  1202.         GetForces();
  1203.         //Calculate maximal allowed computer AI
  1204.         int MaxHumAI=0;
  1205.         for(int i=0;i<8;i++){
  1206.             Nation* NT=&NATIONS[i];
  1207.             if(!NT->CITY&&NForces[i].StrongFactor>MaxAllowedComputerAI)
  1208.                 MaxAllowedComputerAI=NForces[i].StrongFactor;
  1209.         };
  1210.     };
  1211.     PrepareProcessing();
  1212.     for(int i=0;i<MAXOBJECT;i++)if(int(Group[i])){
  1213.         Group[i]->MakePreProcess();
  1214.     };
  1215.     MakePostProcess();
  1216.     PrepareProcessing();
  1217.     for(i=0;i<MAXOBJECT;i++){
  1218.         OneObject* OB=Group[i];
  1219.         if(OB){
  1220.             if(OB->DstX&&OB->Selected&&OB->NNUM==MyNation)AddDestn(OB->DstX,OB->DstY);
  1221.             OB->MakeWPreProcess();
  1222.         };
  1223.     };
  1224.     MakeWPostProcess();
  1225.     ClearFlyMarkers();
  1226.     for(i=0;i<MAXOBJECT;i++)if(int(Group[i])){
  1227.         Group[i]->ProcessFly();
  1228.     };
  1229.     SetFlyMarkers();
  1230.     CarryOutOrder();
  1231.     LG.Process();
  1232.     GWALLS.ProcessClusters();
  1233.     HandleAntiNuc();
  1234.     if(!tmm)ProcessUFO();
  1235.     //TimerProc();
  1236.     //HandleMultiplayer();
  1237.     //ExecuteBuffer();
  1238.     //HandleHExpls();
  1239.     //HandleSW();
  1240.     //return true;
  1241.     //CHKALL();
  1242. };
  1243. bool ProcessMessages();
  1244. extern word NPlayers;;
  1245. void CmdSaveNetworkGame(byte NI,int ID,char* Name);
  1246. int SaveTime;
  1247. extern char SaveFileName[128];
  1248. void PostDrawGameProcess(){
  1249.     HandleMultiplayer();
  1250.     ExecuteBuffer();
  1251.     //HandleHExpls();
  1252.     HandleSW();
  1253.     int difTime=GetTickCount()-AutoTime;
  1254.     if(difTime>60000){
  1255.         if(NPlayers>1){
  1256.             if(MyDPID==ServerDPID)
  1257.                 CmdSaveNetworkGame(MyNation,GetTickCount(),SaveFileName);
  1258.              //SaveGame("saveNETW.sav","NETWORK SAVE",0);
  1259.         }else SaveGame("saveAUTO.sav","└┬╥╬╤╬╒╨└═┼═╚┼",0);
  1260.         AutoTime=GetTickCount();
  1261.     };
  1262.     /*
  1263.     if(NPlayers>1&&MyDPID==ServerDPID&&SaveTime-GetTickCount()>60000*5){
  1264.         CmdSaveNetworkGame(MyNation,GetTickCount(),"NETWORK SAVE");
  1265.         SaveTime=GetTickCount();
  1266.     };
  1267.     */
  1268.     do{
  1269.         ProcessMessages(); 
  1270.     }while(GetTickCount()-PrevTime<FPSTime);
  1271. };
  1272.  
  1273. /*
  1274.  * WinMain - initialization, message loop
  1275.  */
  1276. void AllGame();
  1277. void PrepareToEdit(){
  1278.     ReliefBrush=3;
  1279.     TerrBrush=2;
  1280.     EditMedia=0;
  1281.     HeightEditMode=false;
  1282.     MEditMode=false;
  1283.     EditMapMode=true;
  1284.     FogMode=0;
  1285.     HelpMode=true;
  1286.     ChoosePosition=false;
  1287.     CheapMode=false;
  1288.     NMyUnits=1;
  1289.     NThemUnits=1;
  1290.     AutoTime=GetTickCount()+180000;
  1291. };
  1292. void PrepareToGame(){
  1293.     ReliefBrush=3;
  1294.     TerrBrush=2;
  1295.     EditMedia=0;
  1296.     HeightEditMode=false;
  1297.     MEditMode=false;
  1298.     EditMapMode=false;
  1299.     FogMode=1;
  1300.     HelpMode=false;
  1301.     ChoosePosition=false;
  1302.     CheapMode=false;
  1303.     NMyUnits=1;
  1304.     NThemUnits=1;
  1305.     SaveTime=GetTickCount();
  1306.     AutoTime=GetTickCount()+180000;
  1307. };
  1308. void ShowIntro(){
  1309.  
  1310. };
  1311. void SetupRenderStack();
  1312. int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  1313.                         LPSTR lpCmdLine, int nCmdShow)
  1314. {
  1315.     MaxSizeX=1600;
  1316.     MaxSizeY=1200;
  1317.     Shifter=5;
  1318.     Multip=0;
  1319.     SetupRenderStack();
  1320.     ChangeNation=false;
  1321.     MultiTvar=false;
  1322.     AutoTime=0;
  1323.     BlobMode=0;
  1324.     MEditMode=false;
  1325.     EditMedia=0;
  1326.     LoadMediaFile();
  1327.     SpecCmd=0;
  1328.     sfVersion=15;
  1329.     Quality=2;
  1330.     RealLx=1024;
  1331.     RealLy=768;
  1332.     WarSound=0;
  1333.     WorkSound=0;
  1334.     OrderSound=0;
  1335.     MidiSound=0;
  1336.     FPSTime=50;
  1337.     FILE* fff=fopen("mode.dat","rt");
  1338.     if(fff){
  1339.         fscanf(fff,"%d%d%d%d%d%d%d",&RealLx,&RealLy,&WarSound,&OrderSound,&OrderSound,&MidiSound,&FPSTime);
  1340.         fclose(fff);
  1341.     };
  1342.     HealthMode=false;                
  1343.     tima=0;
  1344.     PlayerMask=1;
  1345.     Flips=0;
  1346.     tmtim=0;
  1347.     InfoMode=true;
  1348.     MSG         msg;
  1349.     DeathMode=false;
  1350.     AttackMode=false;
  1351.     NoDebugMode();
  1352.     makeFden();
  1353.     PlayerMenuMode=1;
  1354.     InitStack();
  1355.     Creator=255;
  1356.     xxx=0;
  1357.     cadr=0;
  1358.     InitZones();
  1359.     InitEBuf();
  1360.     InitDialogs();
  1361.     MUSTDRAW=false;
  1362.     LoadRLC("xrcross.rlc",&RCross);
  1363.     LoadRLC("xrcross.rlx",&mRCross);
  1364.     LoadRLC("64x64dc9.rlc",&rlc);
  1365.     LoadRLC("64x64dc4.rlc",&mon);
  1366.     LoadRLC("16x16dr1.rlc",&rlc_s);
  1367.     LoadRLC("16x16dr1.rlc",&mon_s);
  1368.  
  1369.     LoadRLC("32x32r.rlc",&t32x32r);
  1370.     LoadRLC("32x32g.rlc",&t32x32g);
  1371.     LoadRLC("32x32w.rlc",&t32x32w);
  1372.     LoadRLC("16x16r.rlc",&t16x16r);
  1373.     LoadRLC("16x16y.rlc",&t16x16y);
  1374.     LoadRLC("16x16w.rlc",&t16x16w);
  1375.     LoadRLC("16x16g.rlc",&t16x16g);
  1376.     LoadRLC("img.rlc",&IMM);
  1377.     LoadRLC("img.rlx",&mIMM);
  1378.     RegisterRLCFont(&rlf,rlc,0);
  1379.     RegisterRLCFont(&rlf1,mon,0);
  1380.     RegisterRLCFont(&rlf_s,rlc_s,0);
  1381.     RegisterRLCFont(&rlf1_s,mon_s,0);
  1382.  
  1383.     RegisterRLCFont(&f32x32r,t32x32r,0);
  1384.     RegisterRLCFont(&f32x32g,t32x32g,0);
  1385.     RegisterRLCFont(&f32x32w,t32x32w,0);
  1386.     RegisterRLCFont(&f16x16r,t16x16r,0);
  1387.     RegisterRLCFont(&f16x16y,t16x16y,0);
  1388.     RegisterRLCFont(&f16x16w,t16x16w,0);
  1389.     RegisterRLCFont(&f16x16g,t16x16g,0);
  1390.     memset(Events,0,sizeof Events);
  1391.     MainMenu.CreateMenu("LOAD GAME|SAVE GAME|OPTIONS|ABOUT|EXIT",&rlf1,&rlf,NULL,
  1392.         MCP_MAKESHIFT|MCP_CHANGEFONT);
  1393.     Options.CreateMenu("SPEED|SOUND|MAIN MENU",&rlf1,&rlf,NULL,
  1394.         MCP_MAKESHIFT|MCP_CHANGEFONT);
  1395.     LoadFile.CreateMenu("MAIN MENU",&rlf1_s,&rlf_s,NULL,
  1396.                         MCP_MAKESHIFT|MCP_CHANGEFONT);
  1397.     About.CreateMenu("THIS GAME|WAS CREATED|BY ANDREW SHPAGIN|IN GAME WORLD| |MAIN MENU",&rlf1_s,&rlf_s,NULL,
  1398.                         MCP_MAKESHIFT|MCP_CHANGEFONT);
  1399.     if( !doInit( hInstance, nCmdShow ) )
  1400.     {
  1401.         return FALSE;
  1402.     }
  1403.     SetupMultiplayer(hInstance);
  1404.     InitMultiDialogs();
  1405.     SetupHint();
  1406.     tmtmt=0;
  1407.     //processMainMenu();
  1408.     KeyPressed=false;
  1409.     while (TRUE)
  1410.     {
  1411.         while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  1412.         {
  1413.             if (msg.message == WM_QUIT)
  1414.             {
  1415.                 PostQuitMessage(msg.wParam);
  1416.                 return 1;
  1417.             }
  1418.  
  1419.         
  1420.             TranslateMessage(&msg);
  1421.             DispatchMessage(&msg);
  1422.         }
  1423.  
  1424.         if(bActive){
  1425.             //int Ticki=GetTickCount();    
  1426.             //while(GetTickCount()-Ticki<MsPerFrame);
  1427.             AllGame();
  1428.             CloseExplosions();
  1429.             ShutdownMultiplayer();
  1430.             FILE* fff=fopen("mode.dat","wt");
  1431.             if(fff){
  1432.                 fprintf(fff,"%d %d %d %d %d %d %d",RealLx,RealLy,WarSound,OrderSound,OrderSound,MidiSound,FPSTime);
  1433.                 fclose(fff);
  1434.             };
  1435.             //CDS->~CDirSound();
  1436.             PostMessage(hwnd, WM_CLOSE, 0, 0);
  1437.         };
  1438.     };
  1439.     return msg.wParam;
  1440.  
  1441. }; /* WinMain */
  1442.