Board index » delphi » Hex map

Hex map

(Apologies if this is the wrong group for this 'general' graphics enquiry.
Please do inform me if this is so..)

Wonder if anyone has had any experience using Delphi (4) to write a routine
to display a map, (of the ancient Mediterranean), overlayed with a hexagon
pattern. The sort of thing people use to play tabletop war games with.

If anybody has any experience, tips etc I would be really glad of some
assistance.

many thanks

Gary Bond

 

Re:Hex map


Quote
Gary Bond wrote:

> (Apologies if this is the wrong group for this 'general' graphics enquiry.
> Please do inform me if this is so..)

> Wonder if anyone has had any experience using Delphi (4) to write a routine
> to display a map, (of the ancient Mediterranean), overlayed with a hexagon
> pattern. The sort of thing people use to play tabletop war games with.

> If anybody has any experience, tips etc I would be really glad of some
> assistance.

Put a Timage on your form ...

image.picture.loadfromfile('map.bmp') load the bitmap map (i guess you
use a bitmap,
right ???)

image.picture.bitmap.canvas.pen.color:=rgb(0,0,0); // black

then draw the hex grid with the

image.picture.bitmap.canvas.moveto
and
image.picture.bitmap.canvas.lineto

commands ( i guess you can fiddle out the right
coordinates by your own)

                                                                Andreas

Re:Hex map


Gary: There is a component on the Delphi SuperSite to do hex maps (THexMap
by Kemp/Dalton).  It lets you overlay a hexgrid on any picture.  Exactly
what you're looking for.  I have a faster rangefinding algorithm for hexes
than the one used in the component, though.  HexMap comes with source, so if
you'd like the faster algorithm, let me know.

 I would also recommend getting the TouchScroller component.  This is a
nifty little tool that lets you use a smaller version of your Mediterranean
image as a "strategic map".  Put your HexMap in a ScrollBox, then use
TouchScroller to autoscroll it to where you click on the small image.

Reece Watkins
(replace all occurrances of 'Z' with AT or DOT symbols to reply)
reecewZmindspringZcom

Quote
Gary Bond <g...@smile.anglia.ac.uk> wrote in message

news:7tvd91$ckb6@forums.borland.com...
Quote
> (Apologies if this is the wrong group for this 'general' graphics enquiry.
> Please do inform me if this is so..)

> Wonder if anyone has had any experience using Delphi (4) to write a
routine
> to display a map, (of the ancient Mediterranean), overlayed with a hexagon
> pattern. The sort of thing people use to play tabletop war games with.

> If anybody has any experience, tips etc I would be really glad of some
> assistance.

> many thanks

> Gary Bond

Re:Hex map


Gary,

I have written a Hex Map editing program and HexMap component.

If you would like to discuss it drop me an e-mail

Tim Howe
rasi...@erols.com

On Tue, 12 Oct 1999 14:37:10 +0100, "Gary Bond"

Quote
<g...@smile.anglia.ac.uk> wrote:
>(Apologies if this is the wrong group for this 'general' graphics enquiry.
>Please do inform me if this is so..)

>Wonder if anyone has had any experience using Delphi (4) to write a routine
>to display a map, (of the ancient Mediterranean), overlayed with a hexagon
>pattern. The sort of thing people use to play tabletop war games with.

>If anybody has any experience, tips etc I would be really glad of some
>assistance.

>many thanks

>Gary Bond

Re:Hex map


Reece,

I would be very interested in seeing your range finding algorithms, as
I have been working on a set of hex based components for some time.

Also, if anyone has any algorithm for path finding on a hex map, I am
also looking for help with that.

Many thanks,

Tim Howe
rasi...@erols.com

On Tue, 12 Oct 1999 10:33:16 -0400, "Reece Watkins"

Quote
<ree...@mindspring.com> wrote:
>Gary: There is a component on the Delphi SuperSite to do hex maps (THexMap
>by Kemp/Dalton).  It lets you overlay a hexgrid on any picture.  Exactly
>what you're looking for.  I have a faster rangefinding algorithm for hexes
>than the one used in the component, though.  HexMap comes with source, so if
>you'd like the faster algorithm, let me know.

> I would also recommend getting the TouchScroller component.  This is a
>nifty little tool that lets you use a smaller version of your Mediterranean
>image as a "strategic map".  Put your HexMap in a ScrollBox, then use
>TouchScroller to autoscroll it to where you click on the small image.

>Reece Watkins
>(replace all occurrances of 'Z' with AT or DOT symbols to reply)
>reecewZmindspringZcom

>Gary Bond <g...@smile.anglia.ac.uk> wrote in message
>news:7tvd91$ckb6@forums.borland.com...
>> (Apologies if this is the wrong group for this 'general' graphics enquiry.
>> Please do inform me if this is so..)

>> Wonder if anyone has had any experience using Delphi (4) to write a
>routine
>> to display a map, (of the ancient Mediterranean), overlayed with a hexagon
>> pattern. The sort of thing people use to play tabletop war games with.

>> If anybody has any experience, tips etc I would be really glad of some
>> assistance.

>> many thanks

>> Gary Bond

Re:Hex map


Tim:  Here you go!  This was based on the Star Fleet Battles map system,
where hexes were numbered in the XXYY system (0101, etc.).  Hex 0101 was
northwest of hex 0201.  Some older games (OGRE being one) had hex 0101
southwest of 0201, so this system would have to be modified accordingly in
those situations.

I forget how HexMap did its RangeInHexes function, but I believe it was a
recursive call (maybe a Bresenham approximation) but this one beats it by a
good margin--it calculates the range in constant time, rather than linear or
logarithmic.  The bigger the map, the better RANGER finishes.  It's all done
with integers, and the most difficult function called in the routine is the
ABS() function.

Some people have a hard time grasping how this works, but all you have to do
is let it number the range from your center hex to every other hex on the
map, and you'll see it's 100% accurate, every time.  I worked it out myself
from staring at that *@&!#^* map for quite a long while...

(more after the source code)
========clip here====================
{
  RANGER.PAS function  Copyright 1993, 1999 Reece Watkins. All rights
reserved. Not public domain.

  This gives you the distance in hexes from hex1 to hex2, regardless of
where they are on the map,
  provided that hex 0101 is NW of hex 0201.

  It takes advantage of "circles of range" that manifest themselves on
hexgrids. You can
  see these if you start in the middle of a hexmap and start writing the
ranges to the
  surrounding hexes from the start.  Now pick any hex on the map and compare
its range
  relative to the start hex.  If it's on the range circle, then the range is
also equal to the
  difference in the x-coordinates.  If not, you'll see that the distance on
Hex2's column from
  Hex2 to the upper or lower bound of the range circle, plus the "value" of
the range circle
  itself is equal to the range you've printed in Hex2.

  This always works, so all you really have to discover is the upper and
lower bounds
  of the range circle for Hex2's column.  These numbers differ if Hex1's
column is odd or even,
  but they're still easy to calculate.  It cuts the code down to ~ 25 lines,
and
  gets rid of the need to traverse the intervening hexes.

  Some terms:
  dx = distance between the two columns.
  lw = y-coord of the lower boundary of the range circle equal to dx on
Hex2's column
  up = y-coord of the upper boundary of the same range circle as lw.

Quote
}

function ranger(hex1, hex2:TPoint):integer;
var
  dx,lw,up : integer;
begin

// find the distance between the two columns.
  dx := abs(Hex1.x-Hex2.x);

// calculate up and lw.
// if Hex1 is in an even-numbered column then...
  if Hex1.x mod 2 = 0 then
  begin
    up := Hex1.y - (dx div 2);
    lw := Hex1.y + ((dx+1) div 2);
  end
  else
  begin
    up := Hex1.y - ((dx+1) div 2);
    lw := Hex1.y + (dx div 2);
  end;

// If Hex2.y falls between up and lw, then the range = dx.
// If not, then just add in the range between lw or up and
// Hex2.y, which will equal the true range.

  if (Hex2.y >= up) and (Hex2.y <= lw) then
    result := dx
  else
    if Hex2.y > lw then
      result := dx + abs(Hex2.y - lw)
    else
      if Hex2.y < up then
        result := dx + abs(Hex2.y - up);
end;
===========clip here=======================

As for pathfinding on a hex grid, that's a little more complex.  Not because
of the hexes, though!  Any pathfinding algorithm will work on a hex grid
just like it does on a square grid.  You just have to change your adjacency
function so that each node will visit six neighbors instead of four or
eight.  You can even represent all of your in-code hex maps on rectangular
arrays, due to the fact that hexes act just like squares, except that every
even-numbered column is offset by half the square height.  In array terms,
this means nothing for vertical neighbors--they are just like squares--but
you just have to watch the even/odd column coordinate, and pick horizontal
neighbors accordingly.  That's trivial.

As for pathfinding itself, what you want to look for is implementations of
the Dijkstra (pronounced "dike-stra")or A* (pronounced "A-star") algorithms.
A* is faster than Dijkstra, except in some special cases, and is what a
great deal of a.i. programming is based on today.

I have a pathfinder that will use either one on a four-way (no diagonal
adjacency) or eight-way square map, and I had six-way written into the code
as well, but I never used it.  The only problem is that it is UGLY code.  I
mean REALLY UGLY code.  I hacked it together from Sedgewick's "Algorithms"
book, put part of it into a component-ized priority queue, etc., etc.  Ugly,
ugly, ugly.  I sent it to John Ayres for possible use in his upcoming Delphi
games book, so maybe he'll clean it up and publish it.  It works, but I'm
really not that proud of it.  If you just HAVE to have it, I guess I could
send it to you, but you'll probably be sorry you asked!  You'll probably
want line-of-sight code, too--it's a common situation in games.

We Delphi games-creators really ought to have a site of our own somewhere.
With Delphi-for-Linux on the horizon, we could help Delphi sales with some
good "made with Delphi" games...

Just a thought,
Reece Watkins
(replace all Zs with appropriate symbols)
reecewZmindspringZcom

Quote
Tim Howe <th...@zzzwwauto.com> wrote in message

news:E2cDOHsYYQk4accI4bjeggxhttP1@4ax.com...
Quote
> Reece,

> I would be very interested in seeing your range finding algorithms, as
> I have been working on a set of hex based components for some time.

> Also, if anyone has any algorithm for path finding on a hex map, I am
> also looking for help with that.

> Many thanks,

> Tim Howe
> rasi...@erols.com

Re:Hex map


Dear Reece or anyone else,

can you please tell me where to get more information on this
TouchScroller component. I search the super pages etc but didn't seem to
be able to find it.

Thanks

Willem van Deursen

Quote
Reece Watkins wrote:

> Gary: There is a component on the Delphi SuperSite to do hex maps (THexMap
> by Kemp/Dalton).  It lets you overlay a hexgrid on any picture.  Exactly
> what you're looking for.  I have a faster rangefinding algorithm for hexes
> than the one used in the component, though.  HexMap comes with source, so if
> you'd like the faster algorithm, let me know.

>  I would also recommend getting the TouchScroller component.  This is a
> nifty little tool that lets you use a smaller version of your Mediterranean
> image as a "strategic map".  Put your HexMap in a ScrollBox, then use
> TouchScroller to autoscroll it to where you click on the small image.

> Reece Watkins
> (replace all occurrances of 'Z' with AT or DOT symbols to reply)
> reecewZmindspringZcom

Re:Hex map


Reece,

Thanks for the great help.
Havn't had chance to put this to use yet in my program, but it's just
the sort of thing I was looking for.

Tim
rasi...@erols.com

On Tue, 12 Oct 1999 15:50:33 -0400, "Reece Watkins"

Quote
<ree...@mindspring.com> wrote:
>Tim:  Here you go!  This was based on the Star Fleet Battles map system,
>where hexes were numbered in the XXYY system (0101, etc.).  Hex 0101 was
>northwest of hex 0201.  Some older games (OGRE being one) had hex 0101
>southwest of 0201, so this system would have to be modified accordingly in
>those situations.

<SNIP>

Re:Hex map


Tim,

Happy to be of service!  I also had an algorithm that would determine
line-of-sight (actually, Star Fleet Battles' firing arc) based on the
relative facing of two units and their positions. (60-, 120-, and 180-degree
pie slices, but hard to describe if you've never played SFB...)  Don't know
if it would be all that useful, but if you'd like, I can dig it out for you.

--R.

Quote
Tim Howe <th...@zzzwwauto.com> wrote in message

news:qlkHODHsH8Q2nEs+2JoVmQnjrPtN@4ax.com...
Quote
> Reece,

> Thanks for the great help.
> Havn't had chance to put this to use yet in my program, but it's just
> the sort of thing I was looking for.

> Tim
> rasi...@erols.com

Re:Hex map


Been having trouble with my email, so would just like to say here thanks to
all who replied to this...Its been a great help to me!

Regards,

Gary

Other Threads