Help with Fallout map rendering

derpf123

First time out of the vault
Hello all!

I've been working on a Fallout 1/2 map viewer, but I've run into a bit of an issue rendering objects.
Here's a screenshot of my viewer (with a hex grid overlay on):
9iZZcGh.png
and here's the same map in Mapper2:

pR1vek9.png

As you can see, some of the objects are rendered at the wrong position. What I do is take the screen position from the hex position of the object, and then subtract width/2 and height from it, and then add the FRM offsets. For the most part I've been working off of ancient FIFE engine code, because it's the only readable source I could find.

Does anyone have any source code for positioning/drawing Fallout maps I could use? I would greatly appreciate it.

Thanks
 
Yep, I've tried to compile it with BCB5 but it won't link without dxguid.lib, which it doesn't ship with oddly enough. Might use the DX7 SDK?
 
Thanks.

I ended up finally getting Mapper2 to compile(!) and poked around at some things. I think FIFE's geometry must have been all wrong. :P Anyway, I got drawing working correctly now!

For anyone who may happen themselves upon the same problem, here's the geometry stuff I ported from Mapper2:

Code:
function tileToScreen(x, y) {
    x = 99 - x // this algorithm expects x to be reversed
    var sx = 4752 + (32 * y) - (48 * x)
    var sy = (24 * y) + (12 * x)


   return {x: sx, y: sy}
}


function tileFromScreen(x, y) {
    var off_x = -4800 + x
    var off_y = y
    var xx = off_x - off_y * 4 / 3
    var tx = xx / 64


    if (xx >= 0) tx++
    tx = -tx
    var yy = off_y + off_x / 4
    ty = yy / 32
    if (yy < 0) ty--


    return {x: 99 - Math.round(tx), y: Math.round(ty)}
}


function hexToScreen(x, y) {
    var sx = 4816 - ((((x + 1) >> 1) << 5) + ((x >> 1) << 4) - (y << 4))
    var sy = ((12 * (x >> 1)) + (y * 12)) + 11


    return {x: sx, y: sy}
}


function hexFromScreen(x, y) {
    var x0 = 4800
    var y0 = 0
    var nx, ny


    if (x - x0 < 0)
        nx = (x - x0 + 1) / 16 - 1
    else
        nx = (x - x0) / 16


    if (y - y0 < 0)
        ny = (y - y0 + 1) / 12 - 1
    else
        ny = (y - y0) / 12


    if (Math.abs(nx) % 2 != Math.abs(ny) % 2)
        nx--;


    var xhBase = x0 + 16 * nx
    var yhBase = y0 + 12 * ny


    var hx = (4 * (yhBase - y0) - 3 * (xhBase - x0)) / 96
    var hy = (yhBase - y0) / 12 - hx / 2


    var dx = x - xhBase
    var dy = y - yhBase


    switch(dy)
    {
      case 0:
         if (dx < 12)
         {
        hy--;
        break;
     }
     if (dx > 18)
         {
        if (hx % 2 == 1)
           hy--;
            hx--;
            break;
         }


      case 1:
         if (dx < 8)
         {
        hx--;
        break;
     }
     if (dx > 23)
         {
        if (hx % 2 == 1)
           hy--;
        hx--;
        break;
     }


      case 2:
     if (dx < 4)
         {
        hy--;
        break;
     }
         if (dx > 28)
         {
        if (hx % 2 == 1)
           hy--;
            hx--;
        break;
     }
      default:
         break;
    }




    return {x: Math.round(hx), y: Math.round(hy)}
}

Originally, Mapper2 expects tileToScreen's x coordinate to be in Fallout's format (Fallout maps are reversed in their x coordinate), so if you need to do that then just pass in 99 - x.
The *FromScreen functions originally depended on the camera (i.e. scrolled portion) coordinates as well, now they don't.
 
Last edited:
Back
Top