home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / v / vol1n7.zip / GAME.C < prev    next >
Text File  |  1992-10-10  |  5KB  |  152 lines

  1. /* The Ultimate OS/2 Game.
  2.  
  3. Copyright (c) 1992 Timur Tabi 
  4. Copyright (c) 1992 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. Special thanx go to:
  15.  
  16. Scott Cherkofsky, for great ideas since the very beginning.
  17. Erin Sasaki, for proofreading my articles, even during finals.
  18. Sam Lewis, president of Fasa, for giving me permission.
  19.  
  20. Contributors:
  21. Brian C. Ladd (BCL) - Hex map routines
  22. Chris A. Masters (CAM) - Targetting algorithms
  23.  
  24. */
  25.  
  26. #define INCL_WIN
  27. #define INCL_GPIPRIMITIVES
  28. #define INCL_DEV
  29. #include <os2.h>
  30. #include "header.h"
  31. #include "game.h"
  32. #include "target.h"
  33. #include "dialog.h"
  34. #include "files.h"
  35. #include "menu.h"
  36.  
  37. MRESULT EXPENTRY AboutDlgProc(HWND, ULONG, MPARAM, MPARAM);
  38.  
  39. // The width and the heigh of the client window, in pixels
  40. #define WINDOW_WIDTH (1+HEX_DIAM+(NUM_COLUMNS-1)*(HEX_DIAM+HEX_SIDE)/2)
  41. #define WINDOW_HEIGHT (1+HEX_HEIGHT*(NUM_ROWS+1)/2)
  42.  
  43. // Future enhancement: localize the following variables
  44.  
  45. // Standard variables for PM programs
  46. char *szClassName="TIMUR";                     // What?  You don't like it?
  47. char *szWinTitle="The Ultimate OS/2 Game";
  48. HAB hab;
  49. HMQ hmq;
  50. QMSG qmsg;
  51. HWND hwndFrame,hwndClient;
  52. ULONG flStyle = (ULONG) (FCF_TITLEBAR|FCF_SYSMENU|FCF_TASKLIST|FCF_MINBUTTON|FCF_MENU|FCF_ICON);
  53.  
  54. // For determining the title and menu bar heights
  55. HWND hwndTitleBar,hwndMenu;
  56. RECTL rclTitleBar,rclMenu,rclFrame,rclBox;
  57.  
  58. MRESULT EXPENTRY WinProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  59.   POINTL ptl={0,0};
  60.   HEXINDEX hi;
  61.   static HDC hdc;             // We don't need this on the stack
  62. //  static HPS hps=0;                          // For all drawing functions
  63.  
  64.   switch (msg) {
  65.     case WM_CREATE:
  66.       hdc=WinOpenWindowDC(hwnd);
  67.       DevQueryCaps(hdc,CAPS_COLORS,1L,&lNumColors);
  68.       TgtInitialize(hwnd);
  69.       hpsHex=WinGetPS(hwnd);
  70.       HexInitMap();
  71.       InitMenu();
  72.       break;
  73.     case WM_PAINT:
  74.       HexDrawMap(hwnd);
  75.       break;
  76.     case WM_BUTTON1DOWN:
  77.       if (target.fActive) break;
  78.       ptl.x=SHORT1FROMMP(mp1);
  79.       ptl.y=SHORT2FROMMP(mp1);
  80.       if (!HexLocate(ptl,&hi)) break;                  // hi = origin hex
  81.  
  82.       switch (eMode) {
  83.         case MODE_TARGET:
  84.           TgtStart(hi);
  85.           break;
  86.         case MODE_EDIT:
  87.           amap[hi.c][hi.r].iTerrain=usCurTer;
  88.           HexFillDraw(hi);
  89.           break;
  90.        }
  91.        break;
  92.     case WM_BUTTON1UP:
  93.       if (target.fActive) TgtEnd();
  94.       break;
  95.     case WM_MOUSEMOVE:
  96.       if (!target.fActive) break;
  97.       ptl.x=SHORT1FROMMP(mp1);                 // get the X,Y coordinates
  98.       ptl.y=SHORT2FROMMP(mp1);
  99.       if (!HexLocate(ptl,&hi)) break;          // Find out which hex it is
  100.       TgtMove(hi);
  101.       break;
  102.     case WM_COMMAND:
  103.       MainCommand(SHORT1FROMMP(mp1));
  104.       break;
  105.     default:
  106.       return WinDefWindowProc(hwnd,msg,mp1,mp2);
  107.   } // end switch (msg)
  108.   return 0;
  109. }
  110.  
  111. int main(void) {
  112.  
  113.   LONG lx,ly;                                       // For positioning the Info Box
  114.  
  115.   hab=WinInitialize(0);
  116.   hmq=WinCreateMsgQueue(hab,0);
  117.   
  118.   if (!WinRegisterClass(hab,szClassName,WinProc,CS_SIZEREDRAW,0UL)) DosExit(EXIT_PROCESS,0);
  119.   hwndFrame=WinCreateStdWindow(HWND_DESKTOP,0,&flStyle,szClassName,"",CS_SIZEREDRAW,0UL,ID_RESOURCE,&hwndClient);
  120.   if (!hwndFrame) DosExit(EXIT_PROCESS,0);
  121.  
  122.   WinSetWindowText(hwndFrame,szWinTitle);
  123.  
  124. // We must display the window before we can get the height of the title and menu bars
  125.   WinSetWindowPos(hwndFrame,0,0,0,WINDOW_WIDTH,WINDOW_HEIGHT,SWP_ACTIVATE|SWP_MOVE|SWP_SHOW|SWP_SIZE);
  126.  
  127.   hwndTitleBar=WinWindowFromID(hwndFrame,FID_TITLEBAR);
  128.   if (!WinQueryWindowRect(hwndTitleBar,&rclTitleBar)) DosExit(EXIT_PROCESS,0);
  129.   hwndMenu=WinWindowFromID(hwndFrame,FID_MENU);
  130.   if (!WinQueryWindowRect(hwndMenu,&rclMenu)) DosExit(EXIT_PROCESS,0);
  131.  
  132. // Now that we have the bar heights, re-size the window again.
  133.   WinSetWindowPos(hwndFrame,0,0,0,WINDOW_WIDTH,WINDOW_HEIGHT+rclTitleBar.yTop+rclMenu.yTop,SWP_SIZE);
  134.  
  135. // Load and position the info box
  136.   hwndInfoBox=WinLoadDlg(HWND_DESKTOP,HWND_DESKTOP,NULL,NULLHANDLE,IDD_TARGETTING,NULL);
  137.   WinQueryWindowRect(hwndFrame,&rclFrame);
  138.   WinQueryWindowRect(hwndInfoBox,&rclBox);
  139.   lx=rclFrame.xRight+10;
  140.   ly=rclFrame.yTop-(rclBox.yTop-rclBox.yBottom);
  141.   WinSetWindowPos(hwndInfoBox,HWND_BOTTOM,lx,ly,0,0,SWP_MOVE | SWP_SHOW);
  142.  
  143. // You know what this does
  144.   while (WinGetMsg(hab,&qmsg,0,0,0)) WinDispatchMsg(hab,&qmsg);
  145.  
  146.   TgtShutdown();
  147.   WinDestroyWindow(hwndFrame);
  148.   WinDestroyMsgQueue(hmq);
  149.   WinTerminate(hab);
  150.   return 0;
  151. }
  152.