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

  1. /* HEXES.H
  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. 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      // The color of the outline of a hex
  39.  
  40. /* The spacing between the hexagons.  These are included only to improve the readability of the
  41.    code.  They _MUST_ both be set to a value of 2.  Anything else not only causes the targetting
  42.    mechanism to fail, but it doesn't make any sense either.
  43. */
  44. #define XLAG 2
  45. #define YLAG 2
  46.  
  47. // Names for each of the six directions of a hexagon
  48. #define HEXDIR_SE       0
  49. #define HEXDIR_NE       1
  50. #define HEXDIR_NORTH    2
  51. #define HEXDIR_NW       3
  52. #define HEXDIR_SW       4
  53. #define HEXDIR_SOUTH    5
  54.  
  55. typedef struct {          // The column and row index of a hex
  56.   int c;
  57.   int r;
  58. } HEXINDEX;
  59.  
  60. // Global variables
  61. #ifdef HEXES_C
  62. #define EXTERN
  63. #else
  64. #define EXTERN extern
  65. #endif
  66.  
  67. EXTERN HBITMAP hbmHexMask;                     // Hex bitmap mask.  Erases the hexagon before a bitblt
  68.  
  69. #undef EXTERN
  70.  
  71. // Determine whether two hex indices are equal
  72. #define HI_EQUAL(hi1,hi2) ((hi1).c==(hi2).c && (hi1).r==(hi2).r)
  73.  
  74. POINTL HexCoord(HEXINDEX);
  75. // Returns the X,Y coordinate of the bottom-left corner of a hex
  76.  
  77. POINTL HexMidpoint(HEXINDEX);
  78. // Returns the X,Y coordinate of the midpoint of a hex
  79.  
  80. void HexDraw(HPS, HEXINDEX);
  81. // Draws a single hex outline
  82.  
  83. void HexFillDraw(HPS, HEXINDEX);
  84. // Draws a hex with outline HEX_COLOR and filled with the terrain color
  85.  
  86. void HexOutline(HPS, HEXINDEX);
  87. // Outlines a single hexagon
  88.  
  89. BOOL HexInPoint(POINTL, HEXINDEX);
  90. // Returns TRUE if a given X,Y point is within a given hex
  91.  
  92. BOOL HexLocate(POINTL, HEXINDEX *);
  93. // Finds the hex index of the given X,Y coordinate.  Returns TRUE if it finds one
  94.  
  95. HEXINDEX HexNextShortest(HEXINDEX, HEXINDEX);
  96. // Returns the next hex in a shortest-distance path from hi1 to hi2
  97.  
  98. HEXINDEX HexFromSide(HEXINDEX, int iSide);
  99. // returns the hex that is across side iSide of hex hi
  100.  
  101. void HexPointsFromSide(HEXINDEX, int iSide, PPOINTL, PPOINTL);
  102. // Sets pptl1 & pptl2 to the two endpoints of side iSide of the hexagon
  103.