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

  1. /* HEXES.H
  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. This file assumes that it is included after os2.h
  11.  
  12. The file HEX.PCX is a diagram describing the dimensions of a hexagon.
  13. HEX_SIDE is given a value, the others are all derived from it.
  14.  
  15. The hex map is indexed as shown:
  16.              __      __      __      __
  17.             /  \    /  \    /  \    /  \
  18.          __/ 15 \__/ 35 \__/ 55 \__/ 75 \__
  19.         /  \    /  \    /  \    /  \    /  \
  20.        / 04 \__/ 24 \__/ 44 \__/ 64 \__/ 84 \
  21.        \    /  \    /  \    /  \    /  \    /
  22.         \__/ 13 \__/ 33 \__/ 53 \__/ 73 \__/
  23.         /  \    /  \    /  \    /  \    /  \
  24.        / 02 \__/ 22 \__/ 42 \__/ 62 \__/ 82 \
  25.        \    /  \    /  \    /  \    /  \    /
  26.         \__/ 11 \__/ 31 \__/ 51 \__/ 71 \__/
  27.         /  \    /  \    /  \    /  \    /  \
  28.        / 00 \__/ 20 \__/ 40 \__/ 60 \__/ 80 \
  29.        \    /  \    /  \    /  \    /  \    /
  30.         \__/    \__/    \__/    \__/    \__/
  31.  
  32. */
  33.  
  34. #define HEX_SIDE 14              // Must be even
  35. #define HEX_HEIGHT 24            // 2 * sin(60) * HEX_SIDE, must be be even
  36. #define HEX_EXT (HEX_SIDE/2)     // HEX_SIDE * cos(60)
  37. #define HEX_DIAM (HEX_SIDE*2)    // The long diameter (width)
  38. #define HEX_COLOR CLR_BLACK
  39.  
  40. // The next two values must be odd
  41. #define NUM_COLUMNS 21           // The number of columns on the map
  42. #define NUM_ROWS 29              // The number of rows.
  43.  
  44. // The spacing between the hexagons.  A value of 1 (no space) is the minimum
  45. #define XLAG 2
  46. #define YLAG 2
  47.  
  48.  
  49. typedef struct {          // The column and row index of a hex
  50.   int c;
  51.   int r;
  52. } HEXINDEX;
  53.  
  54. typedef struct {
  55.   int iTerrain;        // Terrain ID
  56.   int iHeight;      // The height, where ground level is zero
  57. } MAP;
  58.  
  59. // Global variables
  60. #ifdef HEXES_C
  61. #define EXTERN
  62. #else
  63. #define EXTERN extern
  64. #endif
  65.  
  66. EXTERN long lNumColors;                        // The number of colors, for HexHighlight()
  67. EXTERN MAP amap[NUM_COLUMNS][NUM_ROWS];        // Data for each hex on the map
  68. EXTERN HBITMAP hbmHexMask;                     // Hex bitmap mask.  Erases the hexagon before a bitblt
  69.  
  70. #undef EXTERN
  71.  
  72. // Determine whether two hex indices are equal
  73. #define HI_EQUAL(hi1,hi2) (hi1.c==hi2.c && hi1.r==hi2.r)
  74.  
  75. POINTL HexCoord(HEXINDEX);
  76. // Returns the X,Y coordinate of the bottom-left corner of a hex
  77.  
  78. POINTL HexMidpoint(HEXINDEX);
  79. // Returns the X,Y coordinate of the midpoint of a hex
  80.  
  81. void HexDraw(HPS, HEXINDEX);
  82. // Draws a single hex outline
  83.  
  84. void HexFillDraw(HEXINDEX);
  85. // Draws a hex with outline HEX_COLOR and filled with the terrain color
  86.  
  87. void HexInitMap(HWND);
  88. // Initializes the map array, given the window handle during WM_CREATE
  89.  
  90. BOOL HexInPoint(POINTL, HEXINDEX);
  91. // Returns true of a given X,Y point is within a given hex
  92.  
  93. BOOL HexLocate(POINTL, HEXINDEX *);
  94. // Returns the hex index of the given X,Y coordinate
  95.  
  96. void HexDrawMap(HWND);
  97. // Draws the playing field
  98.  
  99. void APIENTRY HexHighlight(ULONG);
  100. // Thread which highlights the starting hex
  101.  
  102. HEXINDEX HexNextShortest(HEXINDEX, HEXINDEX);
  103. // Returns the next hex in a shortest-distance path from hi1 to hi2
  104.  
  105. int HexNextSide(HEXINDEX hi, int iSide, POINTL ptl1, POINTL ptl2);
  106. // returns the exiting side of hi through which a line from ptl1 to ptl would pass,
  107. //  if it entered at side iSide
  108.  
  109. HEXINDEX HexFromSide(HEXINDEX, int iSide);
  110. // returns the hex that is across side iSide of hex hi
  111.  
  112. int HexFirstSide(HEXINDEX, HEXINDEX);
  113. // returns the side of hi1 through which the target line to hi2 passes
  114.  
  115. void HexPointFromSide(HEXINDEX, int iSide, PPOINTL, PPOINTL);
  116. // Sets pptl1 & pptl2 to the two endpoints of side iSide of the hexagon
  117.