home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mnth0108.zip / Timur / game.c < prev    next >
Text File  |  1993-03-14  |  5KB  |  162 lines

  1. /* The Ultimate OS/2 Game.
  2.  
  3. Copyright (c) 1993 Timur Tabi
  4. Copyright (c) 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 program accompanies Timur Tabi's column "The Ultimate OS/2 Game", which
  11. appears in "OS/2 Monthly".  It is a computer representation of the BattleTech and
  12. Mechwarrior board games, as produced and distributed by the Fasa Coporation.
  13.  
  14. Developed on:
  15.  
  16. IBM PS/2 70-A21 with 16MB, 640x480x16 VGA
  17.  
  18. OS/2 2.0 GA w/ various CSD's applied
  19. IBM C/Set 2 compiler, with CSD #22 applied
  20. EPM 5.51 enhanced editor
  21. IBM WorkFrame/2, with CSD #3 applied
  22. IBM NMake with HPFS-support
  23.  
  24. Special thanx go to:
  25.  
  26. Scott Cherkofsky, for great ideas since the very beginning.
  27. Erin Sasaki, for proofreading my articles, even during finals.
  28. Sam Lewis, president of Fasa, for giving me permission.
  29.  
  30. Contributors:
  31. Brian C. Ladd (BCL) - Hex map routines
  32. Chris A. Masters (CAM) - Targetting algorithms
  33.  
  34. */
  35.  
  36. #define INCL_WIN
  37. #define INCL_GPIPRIMITIVES
  38. #define INCL_DEV
  39. #define INCL_GPIBITMAPS                               // for terrain.h
  40. #include <os2.h>
  41.  
  42. #include "header.h"
  43. #include "window.h"
  44. #include "resource.h"
  45. #include "target.h"
  46. #include "dialog.h"
  47. #include "files.h"
  48. #include "menu.h"
  49. #include "mech.h"
  50. #include "bitmap.h"
  51. #include "terrain.h"
  52.  
  53. MRESULT EXPENTRY WinProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  54.   POINTL ptl={0,0};
  55.   HEXINDEX hi;
  56.   static HDC hdc;             // We don't need this on the stack
  57.  
  58.   switch (msg) {
  59.     case WM_CREATE:
  60.       hdc=WinOpenWindowDC(hwnd);
  61.       DevQueryCaps(hdc,CAPS_COLORS,1L,&lNumColors);
  62.       TgtInitialize(hwnd);
  63.       TerrainInit();
  64.       MechInit();
  65.       HexInitMap(hwnd);
  66.       break;
  67.     case WM_PAINT:
  68.       HexDrawMap(hwnd);
  69.       break;
  70.     case WM_BUTTON1DOWN:
  71.       if (target.fActive) break;
  72.       ptl.x=SHORT1FROMMP(mp1);
  73.       ptl.y=SHORT2FROMMP(mp1);
  74.       if (!HexLocate(ptl,&hi)) break;                  // hi = origin hex
  75.  
  76.       switch (iMode) {
  77.         case IDM_MODE_MOVE:
  78.           MechMove(hi);
  79.           break;
  80.         case IDM_MODE_TARGET:
  81.           TgtStart(mech.hi);
  82.           break;
  83.         case IDM_MODE_EDIT:
  84.           amap[hi.c][hi.r].iTerrain=iCurTer;
  85.           HexFillDraw(hi);
  86.           if HI_EQUAL(hi,mech.hi) MechDraw();                  // In case we drew over our 'Mech
  87.           break;
  88.        }
  89.        break;
  90.     case WM_BUTTON1UP:
  91.       if (target.fActive) TgtEnd();
  92.       break;
  93.     case WM_MOUSEMOVE:
  94.       if (!target.fActive) break;
  95.       ptl.x=SHORT1FROMMP(mp1);                 // get the X,Y coordinates
  96.       ptl.y=SHORT2FROMMP(mp1);
  97.       if (!HexLocate(ptl,&hi)) break;          // Find out which hex it is
  98.       TgtMove(hi);
  99.       break;
  100.     case WM_COMMAND:
  101.       MainCommand(SHORT1FROMMP(mp1));
  102.       break;
  103.     default:
  104.       return WinDefWindowProc(hwnd,msg,mp1,mp2);
  105.   } // end switch (msg)
  106.   return 0;
  107. }
  108.  
  109. // The width and the height of the client window, in pixels
  110. #define WINDOW_WIDTH (XLAG+HEX_DIAM+(NUM_COLUMNS-1)*(HEX_SIDE+HEX_EXT+XLAG))
  111. #define WINDOW_HEIGHT ((HEX_HEIGHT+YLAG)*(NUM_ROWS+1)/2)
  112.  
  113. int main(void) {
  114.   HMQ hmq;
  115.   QMSG qmsg;
  116.   ULONG flStyle = (ULONG) (FCF_TITLEBAR|FCF_SYSMENU|FCF_TASKLIST|FCF_MINBUTTON|FCF_MENU|FCF_ICON);
  117.  
  118. // Standard variables for PM programs
  119.   static char *szClassName="TIMUR";                     // What?  You don't like it?
  120.   static char *szWinTitle="The Ultimate OS/2 Game";
  121.  
  122.   LONG lx,ly;                                       // For positioning the Info Box
  123.  
  124.   hab=WinInitialize(0);
  125.   hmq=WinCreateMsgQueue(hab,0);
  126.  
  127.   if (!WinRegisterClass(hab,szClassName,WinProc,CS_SIZEREDRAW,0UL)) DosExit(EXIT_PROCESS,0);
  128.   hwndFrame=WinCreateStdWindow(HWND_DESKTOP,0,&flStyle,szClassName,"",CS_SIZEREDRAW,0UL,ID_RESOURCE,&hwndClient);
  129.   if (!hwndFrame) DosExit(EXIT_PROCESS,0);
  130.  
  131.   WinSetWindowText(hwndFrame,szWinTitle);
  132.  
  133. // We must display the window before we can get the height of the title and menu bars
  134.   WinSetWindowPos(hwndFrame,0,0,0,WINDOW_WIDTH,WINDOW_HEIGHT,SWP_ACTIVATE|SWP_MOVE|SWP_SHOW|SWP_SIZE);
  135.  
  136.   hwndTitleBar=WinWindowFromID(hwndFrame,FID_TITLEBAR);
  137.   if (!WinQueryWindowRect(hwndTitleBar,&rclTitleBar)) DosExit(EXIT_PROCESS,0);
  138.   hwndMenu=WinWindowFromID(hwndFrame,FID_MENU);
  139.   if (!WinQueryWindowRect(hwndMenu,&rclMenu)) DosExit(EXIT_PROCESS,0);
  140.  
  141. // Now that we have the bar heights, re-size the window again.
  142.   WinSetWindowPos(hwndFrame,0,0,0,WINDOW_WIDTH,WINDOW_HEIGHT+rclTitleBar.yTop+rclMenu.yTop,SWP_SIZE);
  143.  
  144. // Load and position the info box
  145.   hwndInfoBox=WinLoadDlg(HWND_DESKTOP,HWND_DESKTOP,NULL,NULLHANDLE,IDD_TARGETTING,NULL);
  146.   WinQueryWindowRect(hwndFrame,&rclFrame);
  147.   WinQueryWindowRect(hwndInfoBox,&rclBox);
  148.   lx=rclFrame.xRight+10;
  149.   ly=rclFrame.yTop-(rclBox.yTop-rclBox.yBottom);
  150.   WinSetWindowPos(hwndInfoBox,HWND_BOTTOM,lx,ly,0,0,SWP_MOVE | SWP_SHOW);
  151.  
  152. // You know what this does
  153.   while (WinGetMsg(hab,&qmsg,0,0,0)) WinDispatchMsg(hab,&qmsg);
  154.  
  155.   BitmapShutdown();
  156.   TgtShutdown();
  157.   WinDestroyWindow(hwndFrame);
  158.   WinDestroyMsgQueue(hmq);
  159.   WinTerminate(hab);
  160.   return 0;
  161. }
  162.