Skip to content
Carmina16 edited this page Apr 2, 2018 · 9 revisions

Arena Distance Metric

Arena uses the following approximation of the linear distance between two points:

dx <- abs( x1 - x2 )
dy <- abs( y1 - y2 )
dist <- max(dx, dy) + min(dx, dy) / 4

Local and Global coordinates

Each destination has its global coordinates, which point to the corresponding pixel on the world map.

local2global(x, y, rect) <-
   gX <- (x*((rect.width*100)/320))/100+rect.left
   gY <- (y*((rect.height*100)/200))/100+rect.top
   return gX, gY

rect is taken from the province header in CITYDATA.0x.

Intercity travel

Travel distance shown is arenaDist(start, destination) * 20 km.

function getQuarter(x,y) <-
   for province in Provinces
      if (x,y) in province.Rectangle then
         localx, localy <- global2local( x, y, province.Rectangle)
         quarter <- province.id * 4
         if localx >= 160 then quarter <- quarter + 1
         if localy >= 100 then quarter <- quarter + 2
         return quarter 

x1, y1 <- local2global( startCity.XY )
x2, y2 <- local2global( destinationCity.XY )
points <- getBresenhamLine( x1, y1, x2, y2 )
totalTime <- 0
foreach x, y in points
   month <- GameMonth()
   month <- ( month + totalTime / 3000 ) mod 12
   quarter <- getQuarter(x, y)
   weather <- Weather[quarter]
   terrain <- getTerrain(x, y)
   speed <- (speedTable[month][terrain]*weatherMod[weather][terrain])/100
   time <- 2000 / speed
   totalTime <- totalTime + time
travelDays <- totalTime / 100
if travelDays < 1 then travelDays <- 1
if travelDays > 2000 then travelDays <- 2000

if travelDays > 20 then
   travelDays <- travelDays + rnd(10) - 5

Ranger PCs adjust the calculated travel time according to their level.

After the travel, the time is advanced by 0..22 hours.

Tables

speedTable @428c6 7 arrays of 12 bytes, for each climate.

weatherMod @4291a 7 arrays of 8 bytes, for each climate. The value of 0 represents 100.

Terrain types

Each point on the world map corresponds to a point on TERRAIN.IMG which defines the terrain.

The color indices denoting the terrain type are 254, 249, 251, 253, 250, 252, and 248 corresponds to the sea.

Due to bug, the actual point tested lies 12 pixels to the left (wrapping to the previous row if necessary).

There is also a failsafe mechanism to find the terrain if the tested point lies in the sea. It uses the following algorithm:

dist <- 1
while dist < 200
   if map[x,y+dist] != 248 then return map[x,y+dist]
   else if map[x,y-dist] != 248 then return map[x,y-dist]
   else if map[x+dist,y] != 248 then return map[x+dist,y]
   if map[x-dist,y] != 248 then return map[x-dist,y]
   dist <- dist + 1
return 254

Please note that x and y are wrapped around if they are negative or too big.

Terrain types 1 and 4 correspond to the mountain tileset, 3 and 5 to the desert one.

Clone this wiki locally