Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Converter from old maps to new
#1
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:
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...)
Reply
#2
Did you test to see if the new maps load in Mirage after the conversion?

It's bound to increase in size due to the added Mask3 and Fringe3 layers I would assume.
Reply
#3
Yup. I did test it, and it doesn't work. The increase in size was from a straight conversion from old->old with no extra changes, just the same stuff. I made sure to not change the recs or anything.

I basically loaded it into memory and saved it again, but the folder size went from 4.56MB to 4.62MB with NO changes, just a load and a save with my program, so the new attributes aren't the problem..

With a load into memory and a save from old->new, the folder size goes from 4.56MB to 6.09MB.
Reply
#4
I originally had a zero there, but after seeing grim's tutorial, I though it might've been necessary. When they are zeros and everything else is default, it still goes from 4.56MB to 4.62MB.
Reply
#5
And what's the problem with that? It should increase in size...I don't see any reason why it might not work...
Reply
#6
Grr.. you guys aren't reading what I said. I said I did a straight load->save. I didn't add anything. It increased in size from a straight memory load and a memory save with no changes, so I know there's something wrong with that part. Adding the new layers is the next part I have to fix, but first I must focus on this.

As I said before,
Quote:Yup. I did test it, and it doesn't work. The increase in size was from a straight conversion from old->old with no extra changes, just the same stuff. I made sure to not change the recs or anything.
I loaded the EXACT OldMapRec and OldTileRec into memory and saved it as OldNewMapRec (It's the same as the old one) and OldNewTileRec (Same as the old one) and it's increasing in size with NOTHING added -- just a straight load and save.

When I go onto the map on the older client, all the maps are messed up.
Reply
#7
There is no way that the binary file would be any different if you wrote it using the same "Old Map" structure. Check to ensure that your "Old Map" structure has the same variables in your new client as your older client. If necessary, debug to ensure that the correct values are being written. This isn't rocket science.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)