/* Calculate the tunnel map used in RiDE */

#include <math.h>

#include <dos/dos.h>
#include <proto/dos.h>

#define H 64
#define W 48

main()
{
   register int x, y, x2, y2, i = 0;
   UBYTE tunneltab[H*W];
   BPTR fh;

   for(y = H/2; y > -H/2; y--)
   {
      for(x = -W/2; x < W/2; x++)
      {
         if(x || y)
         {
            y2 = (int) (6000 / sqrt((double) (x*x + y*y))) & 0x3f;
            x2 = (int) (atan2((double) y, (double) x) * (256 / 3.1416)) & 0x3f;
            tunneltab[i++] = ((y2>>2)<<4)|(x2>>2);
         }
         else
         {
            tunneltab[i++] = 0; /* (0, 0) */
         }
      }
   }

   if(fh = Open("tunnelmap.bin", MODE_NEWFILE))
   {
      Write(fh, tunneltab, H*W);
      Close(fh);
   }
}

