Skip to content

Latest commit

 

History

History
103 lines (78 loc) · 2.57 KB

nw_file_specification.org

File metadata and controls

103 lines (78 loc) · 2.57 KB

I found this forum post that explains the board layout, which is quoted below with some corrections:

file header:

GLEVNW01 - File version string

file body:

For each horizontal row containing any modifications:

BOARD - Prefix for board data (real) - X position of the board data (always 0 in practice) (real) - Y position of the board data (between 0 and 32) (real) - Run of the board data (always 64 in practice) (real) - Layer of the board data (always 0 because layers were never implemented in the editor)

(string)[run] - Contains tile data in repeated sequences of ‘XX’ where ‘XX’ is a base64 string.

NPC - Prefix for Oldscript NPC data (string) - Contains NPC’s image file (- if no image) (real) - NPC X position on the board (real) - NPC Y position on the board (string) - Contains entire NPC’s script NPCEND - Marks the end of the NPC

file footer:

File is null terminated

What follows is python code and notes for mapping the tile data as stored in the board to coordinates from the pics1.png tile map:

import string
data = open("worldp-08.nw", "r").readlines()
b64 = string.ascii_uppercase + string.ascii_lowercase + string.digits + "+/"

def decode(aa):
    lhs = b64.index(aa[0])*64
    rhs = b64.index(aa[1])
    return lhs + rhs

lines = open("test.nw", "r").readlines()
row = data[line][16:].strip()

Test.nw reveals the tile arrangement pattern. The tile set is arranged in memory to have a X width of 32. The tile set itself is 32 tiles in height though.

So I thiiiiink we can do something like this: di = data tile index. Some value between 0 and 4095, base64. tx, ty = editor tile coordinates. tx is always 0-15. ty is 0-255 bx, by = apparent board coordinates; eg as they are laid out in the image.

tx = di % 16
ty = di/16 # python rounds this down

EG, IA = 512. So:

tx = 512 % 16 # 0
ty = 512 / 16 # 32

but we want it to be

bx = 16
by = 0

So…

bx = ty / 32 * 16 + tx
by = ty % 32

Lets try this with the next one right and down:

IR = 529
tx = 1
ty = 33
bx = 17
by = 1

Looks good I think? So the final equation should look like this:

di = decode('//')
tx = di % 16
ty = di / 16
bx = ty / 32 * 16 + tx
by = ty % 32