25-06-2008, 12:29 PM
I've been working on adding some more layers lately, and I can't seem to get a converter correctly. I've seen the one posted by grim and messed around with it, but I haven't had much luck with that one so I went back to the one I made.
Old TileRec and MapRec:
New TileRec and MapRec:
Converter Code:
I just can't seem to figure it out. The data doesn't seem to be lining up very well. I tested a conversion without and of the new attributes, just the stuff that's already there, and the folder size of maps went from 4.56MB to 4.62MB, so I know something is being added that's unnecessary, but I've no idea what as of now.
Thanks.
I appreciate your time!
:: Erik
(Just so you know, I'm pretty unfamiliar with Binary loading and saving, so if it's something obvious, please go and explain well if you wouldn't mind...)
Old TileRec and MapRec:
Code:
Type OldTileRec
Ground As Integer
Mask As Integer
Anim As Integer
Mask2 As Integer
M2Anim As Integer
Fringe As Integer
FAnim As Integer
Fringe2 As Integer
F2Anim As Integer
Type As Byte
Data1 As Integer
Data2 As Integer
Data3 As Integer
End Type
Type OldMapRec
Name As String * NAME_LENGTH
Revision As Long
Moral As Byte
Up As Integer
Down As Integer
Left As Integer
Right As Integer
Music As Byte
BootMap As Integer
BootX As Byte
BootY As Byte
Shop As Byte
Tile(0 To MAX_MAPX, 0 To MAX_MAPY) As OldTileRec
Npc(1 To MAX_MAP_NPCS) As Byte
End Type
New TileRec and MapRec:
Code:
Type TileRec
Ground As Integer
Mask As Integer
Anim As Integer
Mask2 As Integer
M2Anim As Integer
Mask3 As Integer
M3Anim As Integer
Fringe As Integer
FAnim As Integer
Fringe2 As Integer
F2Anim As Integer
Fringe3 As Integer
F3Anim As Integer
Type As Byte
Data1 As Integer
Data2 As Integer
Data3 As Integer
End Type
Type MapRec
Name As String * NAME_LENGTH
Revision As Long
Moral As Byte
Up As Integer
Down As Integer
Left As Integer
Right As Integer
Music As Byte
BootMap As Integer
BootX As Byte
BootY As Byte
Shop As Byte
Indoors As Byte
Tile(0 To MAX_MAPX, 0 To MAX_MAPY) As TileRec
Npc(1 To MAX_MAP_NPCS) As Byte
End Type
Converter Code:
Code:
Sub ConvertOldMapsToNew()
Dim filename As String
Dim i As Long
Dim f As Long
Dim r As Long
Dim a As Long
Dim x As Long, y As Long
Dim OldMap As OldMapRec
Dim NewMap As MapRec
Dim TempByte As Byte
' Check if the maps directory is there, if its not make it
If LCase$(Dir(App.Path & "\mapsNEW", vbDirectory)) "mapsNEW" Then
Call MkDir(App.Path & "\mapsNEW")
End If
For i = 1 To MAX_MAPS
frmMain.lblProgress.Caption = (i / 10)
frmMain.Refresh
filename = App.Path & "\maps\map" & i & ".dat"
' Get the old file
f = FreeFile
Open filename For Binary As #f
Get #f, , OldMap
Close #f
' Delete the old file
'Call Kill(filename)
' Convert
NewMap.Name = OldMap.Name
NewMap.Revision = OldMap.Revision
NewMap.Moral = OldMap.Moral
NewMap.Up = OldMap.Up
NewMap.Down = OldMap.Down
NewMap.Left = OldMap.Left
NewMap.Right = OldMap.Right
NewMap.Music = OldMap.Music
NewMap.BootMap = OldMap.BootMap
NewMap.BootX = OldMap.BootX
NewMap.BootY = OldMap.BootY
NewMap.Shop = OldMap.Shop
NewMap.Indoors = TempByte
For y = 0 To MAX_MAPY
For x = 0 To MAX_MAPX
NewMap.Tile(x, y).Ground = Val(OldMap.Tile(x, y).Ground)
NewMap.Tile(x, y).Mask = Val(OldMap.Tile(x, y).Mask)
NewMap.Tile(x, y).Anim = Val(OldMap.Tile(x, y).Anim)
NewMap.Tile(x, y).Mask2 = Val(OldMap.Tile(x, y).Mask2)
NewMap.Tile(x, y).M2Anim = Val(OldMap.Tile(x, y).M2Anim)
NewMap.Tile(x, y).Mask3 = TempByte
NewMap.Tile(x, y).M3Anim = TempByte
NewMap.Tile(x, y).Fringe = Val(OldMap.Tile(x, y).Fringe)
NewMap.Tile(x, y).FAnim = Val(OldMap.Tile(x, y).FAnim)
NewMap.Tile(x, y).Fringe2 = Val(OldMap.Tile(x, y).Fringe2)
NewMap.Tile(x, y).F2Anim = OldMap.Tile(x, y).F2Anim
NewMap.Tile(x, y).Fringe3 = TempByte
NewMap.Tile(x, y).F3Anim = TempByte
NewMap.Tile(x, y).Type = OldMap.Tile(x, y).Type
NewMap.Tile(x, y).Data1 = OldMap.Tile(x, y).Data1
NewMap.Tile(x, y).Data2 = OldMap.Tile(x, y).Data2
NewMap.Tile(x, y).Data3 = OldMap.Tile(x, y).Data3
Next x
Next y
For x = 1 To MAX_MAP_NPCS
NewMap.Npc(x) = OldMap.Npc(x)
Next x
filename = App.Path & "\mapsNEW\map" & i & ".dat"
' Save the new map
r = FreeFile
Open filename For Binary As #r
Put #r, , NewMap
Close #r
Next i
MsgBox "Done!", vbOKOnly, "Done!"
End Sub
I just can't seem to figure it out. The data doesn't seem to be lining up very well. I tested a conversion without and of the new attributes, just the stuff that's already there, and the folder size of maps went from 4.56MB to 4.62MB, so I know something is being added that's unnecessary, but I've no idea what as of now.
Thanks.
I appreciate your time!
:: Erik
(Just so you know, I'm pretty unfamiliar with Binary loading and saving, so if it's something obvious, please go and explain well if you wouldn't mind...)