// These macros are for the gtcpp pre-processor which is a modified cpp that allows macros to use array syntax.
// The macros are only used on linux if your username is gtoal :-) I.e. don't worry about this for a Vectrex build.

$define PPy[m][p] PPy[rangecheck("PPy[" #m " <-- ][" #p "]", m, 0, 3)][rangecheck("PPy[" #m "][" #p " <-- ]", p, 0, 3)]
$define PPx[p] PPx[rangecheck("PPx[" #p " <-- ]", p, 0, 3)]

$define PState[p] PState[rangecheck("PState[" #p "]", p, 0, 3)]

$define directions[d] directions[rangecheck("directions[" #d "]", d, 0, 4)]
$define name[d] name[rangecheck("name[" #d "]", d, 0, 4)]
$define dx[x] dx[rangecheck("dx[" #x "]", x, 0, 4)]
$define dy[y] dy[rangecheck("dy[" #y "]", y, 0, 4)]

//$define GState[x] GState[rangecheck("GState[" #x "]", x, 0, 3)]

$define Ghost[x] Ghost[rangecheck("Ghost[" #x "]", x, 0, 3)]

$define distanceMatrix[g][t] distanceMatrix[rangecheck("distanceMatrix[" #g " <-- ][" #t "]", g, 0, 3)] \
                                           [rangecheck("distanceMatrix[" #g "][" #t " <-- ]", t, 0, 3)]

$define Target[t] Target[rangecheck("Target[" #t " <-- ]", t, 0, 3)]

$define order[x][y] order[rangecheck("order[" #x " <-- ][" #y "]", x, 0, PERMS-1)][rangecheck("order[" #x "][" #y " <-- ]", y, 0, N-1)]

$define wallmap[m][r][c] wallmap[rangecheck("wallmap[" #m " <-- ][" #r "][" #c "]", m, 0, 3)]              \
                                [rangecheck("wallmap[" #m "][" #r " <-- ][" #c "]", r, 0, MAZEROWS31 - 1)] \
                                [rangecheck("wallmap[" #m "][" #r "][" #c " <-- ]", c, 0, MAZECOLS28)] /* We allow 28 to check the \0 byte at the end of a string */
$define dotmap[x][y][z] dotmap[rangecheck("dotmap[" #x " <-- ][" #y "][" #z "]", x, 0, 3)]                 \
                              [rangecheck("dotmap[" #x "][" #y " <-- ][" #z "]", y, 0, MAZEROWS31 - 1)]    \
                              [rangecheck("dotmap[" #x "][" #y "][" #z " <-- ]", z, 0, MAZECOLS28 + 1)] /* not so sure about +1 */

// list of y,x positions of pills for each level.  Pointed to by const array (in EPROM) dotmap[mapno][y][x]

// row and col are in separate arrays for efficiency of indexing (using byte registers on the 6809)

$define pillrow[mapno][pillno] pillrow[rangecheck("pillrow[" #mapno " <-- ][" #pillno "]", mapno, 0, 3)] \
                                      [rangecheck("pillrow[" #mapno "][" #pillno " <-- ]", pillno, 0, MAXPILL[mapno])]
$define pillcol[mapno][pillno] pillcol[rangecheck("pillcol[" #mapno " <-- ][" #pillno "]", mapno, 0, 3)] \
                                      [rangecheck("pillcol[" #mapno "][" #pillno " <-- ]", pillno, 0, MAXPILL[mapno])]

// Maze image for ncurses

$define UTFBoard[x][y] UTFBoard[rangecheck("UTFBoard[" #x " <-- ][" #y "]", x, 0, 3)] \
                               [rangecheck("UTFBoard[" #x "][" #y " <-- ]", y, 0, 30)]

$define corridormap[x][y][z] corridormap[rangecheck("corridormap[" #x " <-- ][" #y "][" #z "]", x, 0, 3)]              \
                                        [rangecheck("corridormap[" #x "][" #y " <-- ][" #z "]", y, 0, MAZEROWS31 - 1)] \
                                        [rangecheck("corridormap[" #x "][" #y "][" #z " <-- ]", z, 0, MAZECOLS28)] /* We allow 28 to check the \0 byte at the end of a string */
 
$define end1[mapno][corridoridx] end1[rangecheck("end1[" #mapno " <-- ][" #corridoridx "]", mapno, 0, 3)] \
                                     [rangecheck("end1[" #mapno "][" #corridoridx " <-- ]", corridoridx, 0, strlen(end1[mapno]) - 1)]

$define end2[mapno][corridoridx] end2[rangecheck("end2[" #mapno " <-- ][" #corridoridx "]", mapno, 0, 3)] \
                                     [rangecheck("end2[" #mapno "][" #corridoridx " <-- ]", corridoridx, 0, strlen(end2[mapno]) - 1)]
 
$define MAXPILL[x] MAXPILL[rangecheck("MAXPILL[" #x "]", x, 0, 3)]

$define eaten[x] eaten[rangecheck("eaten[" #x "]", x, 0, MAXMAXPILL)]
