home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mnth0104.zip / Timur / vol1n4.txt < prev   
Text File  |  1994-03-25  |  8KB  |  157 lines

  1. You can be the Captain
  2.  
  3. Some of the more astute gamers among you may have noticed a 
  4. familiarity in the description of this project last month.  The 
  5. rumors are true - this game will be an OS/2 version of Fasa's 
  6. Battletech and Mechwarrior.  Fasa is a company based in Chicago 
  7. that specializes in role-playing games.  A simple agreement 
  8. between us allows me to use Fasa's trademarks, provided I share 
  9. the copyright with them and include all the appropriate dis
  10. claimers and trademark notices in everything I publish.
  11.  
  12. The most important thing to remember is that this game is not an 
  13. official product from Fasa.  When I spoke with the president, I 
  14. only asked for permission to use their trademarks.  Beyond that, 
  15. they have no connection with it, so any correspondence should be 
  16. directed to me.
  17.  
  18. Before I describe this month's source code, there are a few terms 
  19. which need to be defined.  These terms will be used throughout 
  20. the entire project.  Anyone who is interested in following or 
  21. contributing to the development should obtain the rule books.  A 
  22. good start would be Fasa's "The Rules of Warfare" Battletech 
  23. manual, available at your local gaming store.
  24.  
  25. Battlemech - a trademark of Fasa, this is the name given to the 
  26. humanoid tanks described in last month's article.  It is usually 
  27. abbreviated as 'Mech.
  28.  
  29. hex - a regular hexagon, where all six sides and all six interior 
  30. angles are the same size.  Figure 1 is an example.
  31.  
  32. hex map - a map of a playing field divided into hexagons.  This 
  33. setup allows a player to move in six directions, while a normal 
  34. quadrile grid only allows four.
  35.                  
  36. trajectory - a straight line between the center-points of any two 
  37. hexagons which indicates the path a projectile can take if it 
  38. were launched from one hex and aimed at the other.
  39.  
  40. shortest path - a connecting series of hexes that trace the 
  41. shortest route from one hex to another.  A walking 'Mech would 
  42. most likely take the shortest path.  If he were to fire a rocket, 
  43. its path would be a trajectory.
  44.  
  45. The complete source code will not be published in this magazine 
  46. because of its length, but it will be available electronically 
  47. and (eventually) on disk.  Listed at the end are some BBS's which 
  48. will get the files directly from me.  Feel free to distribute 
  49. them to all your friends and loved ones.
  50.  
  51. The code is intended to be compiled under OS/2 2.0 only, and at 
  52. this writing the only compiler that qualifies is a pre-release of 
  53. IBM's C Set/2.  This compiler (or its full-release version) will 
  54. be used until Borland C++ for OS/2 is released, hopefully in the 
  55. fourth quarter of this year.  At that point we will also make the 
  56. code somewhat object-oriented.
  57.  
  58. The following list describes the files that accompany this 
  59. month's installment:
  60.  
  61.     GAME.C    Main executable
  62.     HEXES.C    Map/targetting routines
  63.     HEXES.H    Header/Prototype file for HEXES.C
  64.     GAME.EXE    Ready-to-run executable
  65.     GAME.ICO    Icon file
  66.     GAME.RC    Resource source file (for the icon)
  67.     HEX.PCX    PCX bitmap description of a hexagon
  68.     GAME.PRJ    WorkFrame/2 project file
  69.  
  70. The game is divided into three sections: initialization and 
  71. shutdown (function main() in GAMES.C), the window procedure 
  72. (function WinProc() in GAMES.C), and the hex map routines (file 
  73. HEXES.C).  This first version of the program demonstrates the 
  74. targetting mechanism of combat mode.  Upon startup, it draws a 
  75. dark grey hex map on a black background.  Use the mouse to select 
  76. an origin hex, and drag the targetting line to a destination.  
  77. While you are dragging, a background thread highlights the origin 
  78. hex.
  79.  
  80. Figure 1 is a diagram of a hexagon marked with various constants 
  81. which explain their definitions.  HEX_SIDE is the only constant 
  82. that needs to be specified, since the length of a side is all 
  83. that is needed to determine the size of a regular hexagon.  How
  84. ever, to insure that our visual representation is accurate, 
  85. HEX_HEIGHT is given a value that creates a symmetrical hexagon on 
  86. a VGA monitor.  Future versions will overcome this limitation.
  87.  
  88. File HEXES.H includes a hex map that shows how the indices are 
  89. chosen.  This particular numbering scheme makes certain calcula
  90. tions easier, such as the screen pixel algorithms in function 
  91. HexCoord().  Next month, we will look at algorithms for the dis
  92. tance and the shortest path that also benefit from this method.
  93.  
  94. The size of the window is given by WINDOW_WIDTH and 
  95. WINDOW_HEIGHT, two constants defined in HEXES.H.  This is actu
  96. ally the size of the client window.  Unfortunately, we can only 
  97. specify the size of the frame window, which has a title bar for a 
  98. top border.  The height of the title bar can only be determined 
  99. after it has been drawn, so we need to draw the window, find the 
  100. title bar's handle, obtain its size, and re-size the frame again 
  101. with the added height.
  102.  
  103. The window procedure handles only five messages: create, repaint, 
  104. button down, button up, and button moved.  The code for WM_CREATE 
  105. calculates the maximum number of colors that the display can 
  106. handle.  This is used by HexHighlight() to choose the highlight
  107. ing method, either color-cycling if there are more than sixteen 
  108. colors, or blinking if the selection is not as wide.  
  109.  
  110. I had to create both methods since the color-cycling routine did 
  111. not work as expected on a 16-color screen.  It seems that lines 
  112. are not ditehered, so all you see are two alternating shades of 
  113. red.  Since I do not have access to a 256-color display, this 
  114. portion of the code has not been fully tested.
  115.  
  116. The drawing of the actual map is handled by WM_PAINT.  Targetting 
  117. is cancelled in the rare event that the window is repainted while 
  118. we are aiming our rockets.  Remember that WM_PAINT must be able 
  119. to redraw all the graphics in the window at any time.  Before 
  120. long, it will become the largest section of the window procedure.
  121.  
  122. The remaining three messages regulate the targetting mechanism. 
  123. WM_BUTTON1DOWN activates it, WM_BUTTON1UP terminates it, and 
  124. WM_MOUSEMOVE moves the line.  When button one is pressed, the 
  125. index of the hex under the mouse pointer is determined.  If it is 
  126. found, then 'target' is initialized with data on the origin hex.  
  127. Two presentation space handles are obtained - one for the line 
  128. and another for hex highlighting.  The parameters for line draw
  129. ing are set, and then HexHighlight() is started.
  130.  
  131. When the button is released, 'fActive' is set to false, causing 
  132. the while-loop in HexHighlight() to terminate.  The targetting 
  133. line is erased, and its presentation space is released.
  134.  
  135. If the mouse is moved while targetting is active, then 
  136. WM_MOUSEMOVE determines whether the new location warrants 
  137. redrawing the line.  If so, it erases the existing line (if any), 
  138. stores the new destination-hex information, and draws the new 
  139. line.
  140.  
  141. The code in HEXES.C should be rather straightforward and easy to 
  142. understand.  The only possible exception is the array of POINTL's 
  143. in function HexDraw().  The value returned by HexCoord() is the 
  144. X,Y coordinate of the lower-left vertex.  A hexagon is created by 
  145. drawing the six sides in a counter-clockwise fashion.  The array 
  146. is a list of all the vertices, in counter-clockwise order, rela
  147. tive to the lower-left corner.  Add the proper offset to each 
  148. point, call GpiPolyLine to draw them all at once, and you have a 
  149. hexagon.
  150.  
  151. That wraps up this month's installment.  Please feel free to mail 
  152. any comments, suggestions, or complaints to me, because I am very 
  153. interested in knowing your thoughts.  Next month's installment 
  154. will continue the development of the targetting machanism and 
  155. introduce the code for terrains.  It would be very nice if some
  156. one volunteered a few bitmaps to represent the different surfaces 
  157. (hint, hint).