I was working on code that calculates the time that it takes a unit to travel from A to B. For no good reason I decided that I want exact calculations which match the ones done by op2. So, I looked at some disassembled function and here is how it works:
(function is at 44B760)
Note: this is for movement from one tile to an adjacent tile only
Note: <time unit> is probably a tick (time measurements suggest that), but I didn't verify it yet.
1. rotation: Before a vehicle will move from one tile to an adjacent tile, it will turn into the direction of the adjacent (destination) tile. This is done by taking the rotation difference (rotation is 32 times the direction) and decreasing it by the vehicle's turn rate every <time unit>, until it reaches 0 which means that the vehicle is heading in the direction of the destination tile.
2. movement: First a check is done whether a unit or lava or a wall or blight expansion is on the destination tile. If neither is the case, the game calculates movement costs as follows:
sourceTrackTypeSpeed = CellTypeInfo[cellType of sourceTile].trackTypeSpeed[trackType of moving unit]
destTrackTypeSpeed = CellTypeInfo[cellType of destTile].trackTypeSpeed[trackType of moving unit]
if destTrackTypeSpeed == 0 (tile is impassible) the function is aborted
adjustedMovementPoints = movementPoints (*724/512, result truncated if moving diagonally)
costs = (sourceTrackTypeSpeed + destTrackTypeSpeed) * adjustedMovementPoints / 1024
if lights are off and there is no daylight everywhere, (costs * light brightness at vec position / 32) will be added to costs.
if the vehicle is damaged, (damage * costs / hitPoints) will be added to the costs.
if costs are smaller than 2, they are set to 2
it will take the unit cost <time unit>s to move from the source tile to the destination tile
Edit: corrected (small) mistakes