home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mnth0109.zip / Timur / game.c < prev    next >
Text File  |  1993-06-07  |  6KB  |  167 lines

  1. /* The Ultimate OS/2 Game.
  2.  
  3. Copyright (c) 1992-1993 Timur Tabi
  4. Copyright (c) 1992-1993 Fasa Corporation
  5.  
  6. The following trademarks are the property of Fasa Corporation:
  7. BattleTech, CityTech, AeroTech, MechWarrior, BattleMech, and 'Mech.
  8. The use of these trademarks should not be construed as a challenge to these marks.
  9.  
  10. The final and all interim code, in whole or in part, may only be for personal use
  11. and may not be used as a basis for any shareware or commercial software.
  12.  
  13. The program accompanies Timur Tabi's column "The Ultimate OS/2 Game", which
  14. appears in "OS/2 Monthly".  It is a computer representation of the BattleTech and
  15. Mechwarrior board games, as produced and distributed by the Fasa Coporation.
  16.  
  17. Developed on:
  18.  
  19. IBM PS/2 70-A21 with 16MB, standard VGA, 80386DX-25 w/ 80387-25
  20.  
  21. OS/2 2.1 March Beta
  22. IBM C/Set 2 compiler, with CSD #44 applied
  23. EPM 5.51 enhanced editor
  24. IBM WorkFrame/2 1.1
  25. IBM OS/2 2.1 Toolkit
  26.  
  27. Special thanx go to:
  28.  
  29. Scott Cherkofsky, for great ideas and cool icons.
  30. Erin Sasaki, for proofreading my articles, even during finals.
  31. Sam Lewis, president of Fasa, for giving me permission.
  32.  
  33. Contributions:
  34. Brian C. Ladd (BCL) - Hex map routines
  35. Chris A. Masters (CAM) - Targetting algorithms
  36.  
  37. */
  38.  
  39. #define INCL_WIN
  40. #define INCL_GPIPRIMITIVES
  41. #define INCL_DEV
  42. #define INCL_GPIBITMAPS                               // for terrain.h
  43. #include <os2.h>
  44.  
  45. #include "header.h"
  46. #include "errors.h"
  47. #include "window.h"
  48. #include "resource.h"
  49. #include "hexes.h"
  50. #include "target.h"
  51. #include "dialog.h"
  52. #include "files.h"
  53. #include "menu.h"
  54. #include "mech.h"
  55. #include "bitmap.h"
  56. #include "terrain.h"
  57.  
  58. MRESULT EXPENTRY WinProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  59.   POINTL ptl;
  60.   HEXINDEX hi;
  61.   HPS hps;
  62.   static HDC hdc;             // We don't need this on the stack
  63.  
  64.   switch (msg) {
  65.     case WM_CREATE:
  66.       hdc=WinOpenWindowDC(hwnd);
  67.       DevQueryCaps(hdc,CAPS_COLORS,1L,&lNumColors);
  68.       break;
  69.     case WM_PAINT:
  70.       TerrainDrawMap(hwnd);
  71.       break;
  72.     case WM_MINMAXFRAME:                               // To hide/show infobox
  73.       if ( ((PSWP) mp1)->fl & SWP_MINIMIZE )
  74.         WinSetWindowPos(hwndInfoBox,NULLHANDLE,0,0,0,0,SWP_HIDE);
  75.       if ( ((PSWP) mp1)->fl & SWP_RESTORE )
  76.         WinSetWindowPos(hwndInfoBox,NULLHANDLE,0,0,0,0,SWP_SHOW);
  77.       break;
  78.     case WM_BUTTON1DOWN:
  79.     case WM_BUTTON2DOWN:
  80.       if (target.fActive) break;
  81.       ptl.x=SHORT1FROMMP(mp1);
  82.       ptl.y=SHORT2FROMMP(mp1);
  83.       if (!HexLocate(ptl,&hi)) break;                  // hi = origin hex
  84.  
  85.       switch (iMode) {
  86.         case IDM_MODE_MOVE:
  87.           if (msg==WM_BUTTON1DOWN)
  88.             MechMove(hi);                              // Button 1 moves
  89.           else
  90.             TgtStart(mech.hi);                         // Button 2 targets
  91.           break;
  92.         case IDM_MODE_EDIT:                            // Make this a separate function
  93.           amap[hi.c][hi.r].iTerrain=iCurTer;
  94.           hps=WinGetPS(hwnd);
  95.           HexFillDraw(hps,hi);
  96.           WinReleasePS(hps);
  97.           if HI_EQUAL(hi,mech.hi) MechDraw();          // In case we drew over our 'Mech
  98.           break;
  99.        }
  100.        break;
  101.     case WM_BUTTON2UP:
  102.       if (target.fActive) TgtEnd();
  103.       break;
  104.     case WM_MOUSEMOVE:
  105.       if (!target.fActive) break;
  106.       ptl.x=SHORT1FROMMP(mp1);                 // get the X,Y coordinates
  107.       ptl.y=SHORT2FROMMP(mp1);
  108.       if (!HexLocate(ptl,&hi)) break;          // Find out which hex it is
  109.       TgtMove(hi);
  110.       break;
  111.     case WM_COMMAND:
  112.       MainCommand(SHORT1FROMMP(mp1));
  113.       break;
  114.   } // end switch (msg)
  115.   return WinDefWindowProc(hwnd,msg,mp1,mp2);
  116. }
  117.  
  118. // The width and the height of the client window, in pixels
  119. #define WINDOW_WIDTH (XLAG+HEX_DIAM+(NUM_COLUMNS-1)*(HEX_SIDE+HEX_EXT+XLAG))
  120. #define WINDOW_HEIGHT ((HEX_HEIGHT+YLAG)*(NUM_ROWS+1)/2)
  121.  
  122. int main(void) {
  123.   HMQ hmq;
  124.   QMSG qmsg;
  125.   ULONG flStyle = (ULONG) (FCF_TITLEBAR|FCF_SYSMENU|FCF_TASKLIST|FCF_MINBUTTON|FCF_MENU|FCF_ICON|FCF_ACCELTABLE);
  126.   RECTL rclTitleBar,rclMenu;
  127.  
  128. // Standard variables for PM programs
  129.   static char *szClassName="TIMUR";                 // What?  You don't like it?
  130.  
  131.   hab=WinInitialize(0);
  132.   if (hab==NULLHANDLE) DosExit(EXIT_PROCESS,1);     // if we can't even get an anchor block, then just give up
  133.  
  134.   hmq=WinCreateMsgQueue(hab,0);
  135.  
  136.   if (!WinRegisterClass(hab,szClassName,WinProc,CS_SIZEREDRAW,0UL)) DosExit(EXIT_PROCESS,1);
  137.   hwndFrame=WinCreateStdWindow(HWND_DESKTOP,0,&flStyle,szClassName,"",CS_SIZEREDRAW,0UL,ID_RESOURCE,&hwndClient);
  138.   if (!hwndFrame) DosExit(EXIT_PROCESS,1);
  139.  
  140. // We must display the window before we can get the height of the title and menu bars
  141.   WinSetWindowPos(hwndFrame,0,0,0,WINDOW_WIDTH,WINDOW_HEIGHT,SWP_ACTIVATE|SWP_MOVE|SWP_SHOW|SWP_SIZE);
  142.  
  143. // Get the sizes of the titlebar and menu
  144.   if (!WinQueryWindowRect(WinWindowFromID(hwndFrame,FID_TITLEBAR),&rclTitleBar)) DosExit(EXIT_PROCESS,1);
  145.   hwndMenu=WinWindowFromID(hwndFrame,FID_MENU);
  146.   if (!WinQueryWindowRect(hwndMenu,&rclMenu)) DosExit(EXIT_PROCESS,1);
  147.  
  148. // Now that we have the bar heights, re-size the window again.
  149.   WinSetWindowPos(hwndFrame,0,0,0,WINDOW_WIDTH,WINDOW_HEIGHT+rclTitleBar.yTop+rclMenu.yTop,SWP_SIZE);
  150.  
  151. // The window has been displayed.  Let's initialize all the modules.  Some of them depend on
  152. // hwndFrame and hwndClient.
  153.   TgtInit();
  154.   TerrainInit();
  155.   MechInit();
  156.   WindowSetTitle(NULL);
  157.  
  158. // You know what this does
  159.   while (WinGetMsg(hab,&qmsg,0,0,0)) WinDispatchMsg(hab,&qmsg);
  160.  
  161.   BitmapShutdown();
  162.   WinDestroyWindow(hwndFrame);
  163.   WinDestroyMsgQueue(hmq);
  164.   WinTerminate(hab);
  165.   return 0;
  166. }
  167.