Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Map Converter


Xlithan
 Share

Recommended Posts

Hi guys, I'm trying to create a map converter but it doesn't seem to be working properly. Below is some code from the main module which converts the maps, but I seem to be getting a Subscript Out of Range error on the following line:

**NewMap.Tile(x, y).Layer(1).x = OldMap.Tile(x, y).Ground**

```
Option Explicit

Sub ConvertOldMapsToNew()
Dim FileName As String
Dim FileName2 As String
Dim m As Long
Dim i As Long
Dim F As Long
Dim x As Long, y As Long
Dim OldMap As OldMapRec
Dim NewMap As NewMapRec

   For i = 1 To MAX_MAPS
       FileName = App.Path & "\maps\map" & i & ".dat"
       FileName2 = App.Path & "\new 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.Up = OldMap.Up
       NewMap.Down = OldMap.Down
       NewMap.Left = OldMap.Left
       NewMap.Right = OldMap.Right
       NewMap.BootMap = OldMap.BootMap
       NewMap.BootX = OldMap.BootX
       NewMap.BootY = OldMap.BootY
       For y = 0 To MAX_MAPY
           For x = 0 To MAX_MAPX
               NewMap.Tile(x, y).Layer(1).x = OldMap.Tile(x, y).Ground
               NewMap.Tile(x, y).Layer(1).y = OldMap.Tile(x, y).Ground
               NewMap.Tile(x, y).Layer(3).x = OldMap.Tile(x, y).Mask
               NewMap.Tile(x, y).Layer(3).y = OldMap.Tile(x, y).Mask
               NewMap.Tile(x, y).Layer(7).x = OldMap.Tile(x, y).Fringe
               NewMap.Tile(x, y).Layer(7).y = OldMap.Tile(x, y).Fringe
               NewMap.Tile(x, y).Layer(1).Tileset = 1
               NewMap.Tile(x, y).Layer(3).Tileset = 1
               NewMap.Tile(x, y).Layer(7).Tileset = 1
               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

       ' Save the new map
       F = FreeFile
       Open FileName2 For Binary As #F
           Put #F, , NewMap
       Close #F
   Next i
End Sub
```
Link to comment
Share on other sites

you will need to do something like

if  x < old_maxx and y < old_mapy then
              NewMap.Tile(x, y).Layer(1).x = OldMap.Tile(x, y).Ground
              NewMap.Tile(x, y).Layer(1).y = OldMap.Tile(x, y).Ground
              NewMap.Tile(x, y).Layer(3).x = OldMap.Tile(x, y).Mask
              NewMap.Tile(x, y).Layer(3).y = OldMap.Tile(x, y).Mask
              NewMap.Tile(x, y).Layer(7).x = OldMap.Tile(x, y).Fringe
              NewMap.Tile(x, y).Layer(7).y = OldMap.Tile(x, y).Fringe
              NewMap.Tile(x, y).Layer(1).Tileset = 1
              NewMap.Tile(x, y).Layer(3).Tileset = 1
              NewMap.Tile(x, y).Layer(7).Tileset = 1
              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
else
              NewMap.Tile(x, y).Layer(1).x = OldMap.Tile(x, y).Ground
              NewMap.Tile(x, y).Layer(1).y = 0
              NewMap.Tile(x, y).Layer(3).x = 0
              NewMap.Tile(x, y).Layer(3).y = 0
              NewMap.Tile(x, y).Layer(7).x = 0
              NewMap.Tile(x, y).Layer(7).y = 0
              NewMap.Tile(x, y).Layer(1).Tileset = 1
              NewMap.Tile(x, y).Layer(3).Tileset = 1
              NewMap.Tile(x, y).Layer(7).Tileset = 1
              NewMap.Tile(x, y).Type = 0
              NewMap.Tile(x, y).Data1 = 0
              NewMap.Tile(x, y).Data2 = 0
              NewMap.Tile(x, y).Data3 = 0
end if
Link to comment
Share on other sites

Layer constructor? It should be a very simple program, all you're doing is loading values into one variable, and saving them in another lol.

The major difference, and the only one I can see from the 2 systems, is the Layer() stuff. Most older source codes just use .Ground, .Mask, .Fringe etc. From what I can gather, the Layers are exactly the same thing, but they're set as arrays instead of singular.
With that, Layer(1) is the ground layer, Layer(3) is the mask layer, and Layer(7) is the fringe layer.

What exactly is the difference between the Layer().x and Layer().y? Since older systems just use the above as I said. What exactly is stored into these?
Link to comment
Share on other sites

The new maps are blank, and have been set to 30 to be the same as the old maps.

Where are you getting OldMap.Tile(x, y).Ground.x from?

```
Type OldTileRec
Ground As Long
Mask As Long
Anim As Long
Mask2 As Long
M2Anim As Long
Fringe As Long
FAnim As Long
Fringe2 As Long
F2Anim As Long
Type As Byte
Data1 As Long
Data2 As Long
Data3 As Long
String1 As String
String2 As String
String3 As String
End Type
```

* * *

Neither of those work, I just get type mismatch errors.

* * *

**modTypes**:

```
Option Explicit

Public Const MAX_MAPS = 400
Public Const MAX_MAPX = 30
Public Const MAX_MAPY = 30

Type OldTileRec
Ground As Long
Mask As Long
Anim As Long
Mask2 As Long
M2Anim As Long
Fringe As Long
FAnim As Long
Fringe2 As Long
F2Anim As Long
Type As Byte
Data1 As Long
Data2 As Long
Data3 As Long
String1 As String
String2 As String
String3 As String
End Type

Type OldMapRec
Name As String * 30
Revision As Long
Moral As Byte
Up As Long
Down As Long
Left As Long
Right As Long
Music As String
BootMap As Long
BootX As Byte
BootY As Byte
Shop As Byte
Indoors As Byte
Tile() As OldTileRec
Npc(1 To 15) As Byte
End Type

Private Type EventRec
Name As String
End Type

Type NewTileDataRec
x As Long
y As Long
Tileset As Long
End Type

Type NewTileRec
Layer(1 To MapLayer.Layer_Count - 1) As NewTileDataRec
Type As Byte
Data1 As Long
Data2 As Long
Data3 As Long
DirBlock As Byte
End Type

Type NewMapRec
Name As String * 30
Music As String * 30

Revision As Long
Moral As Byte

Up As Long
Down As Long
Left As Long
Right As Long

BootMap As Long
BootX As Byte
BootY As Byte

MaxX As Byte
MaxY As Byte

Tile() As NewTileRec
Npc(1 To 15) As Long
EventCount As Long
Events() As EventRec
End Type

```
**modEnums**:

```
Option Explicit

' Layers in a map
Public Enum MapLayer
Ground = 1
Autotile
Mask1
Mask2
Mask3
Mask4
Fringe1
Fringe2
Fringe3
Fringe4
' Make sure Layer_Count is below everything else
Layer_Count
End Enum

```
Link to comment
Share on other sites

to get the Y you will need to do

(Map.Tile(X, Y).Ground \ TILESHEET_WIDTH) * PIC_Y

to get the X you will need to do.

(Map.Tile(X, Y).Ground Mod TILESHEET_WIDTH) * PIC_X
those based on the map tile position setup are how ground, mask and fringe are used within the old mirage based system.
also sorry i thought you where converting from a map style which migth have had the variable names as ground and mask but has a x, y. I forgot the old mirage had a set integer for pixel position.

oh and also ou have to set the array before you can load data into the array like

Tile(0 To MAX_MAPX, 0 To MAX_MAPY) As TileRec

otherwise you need to use a realloc on the tile to set it to its dimension before trying to load the data into it. =']
otherwise the tile index's are none existent on either side.
Link to comment
Share on other sites

Still same error

```
Option Explicit

Sub ConvertOldMapsToNew()
Dim FileName As String
Dim FileName2 As String
Dim m As Long
Dim i As Long
Dim F As Long
Dim x As Long, y As Long
Dim OldMap As OldMapRec
Dim NewMap As NewMapRec

For i = 1 To MAX_MAPS
FileName = App.Path & "\maps\map" & i & ".dat"
FileName2 = App.Path & "\new 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)

ReDim NewMap.Tile(0 To NewMap.MaxX, 0 To NewMap.MaxY)

' Convert
NewMap.Name = OldMap.Name
NewMap.Up = OldMap.Up
NewMap.Down = OldMap.Down
NewMap.Left = OldMap.Left
NewMap.Right = OldMap.Right
NewMap.BootMap = OldMap.BootMap
NewMap.BootX = OldMap.BootX
NewMap.BootY = OldMap.BootY
For y = 0 To MAX_MAPY
For x = 0 To MAX_MAPX
NewMap.Tile(x, y).Layer(1).x = (OldMap.Tile(x, y).Ground \ 224) * PIC_X
NewMap.Tile(x, y).Layer(1).y = (OldMap.Tile(x, y).Ground \ 224) * PIC_Y
NewMap.Tile(x, y).Layer(3).x = (OldMap.Tile(x, y).Mask \ 224) * PIC_X
NewMap.Tile(x, y).Layer(3).y = (OldMap.Tile(x, y).Mask \ 224) * PIC_Y
NewMap.Tile(x, y).Layer(7).x = (OldMap.Tile(x, y).Fringe \ 224) * PIC_X
NewMap.Tile(x, y).Layer(7).y = (OldMap.Tile(x, y).Fringe \ 224) * PIC_Y
NewMap.Tile(x, y).Layer(1).Tileset = 1
NewMap.Tile(x, y).Layer(3).Tileset = 1
NewMap.Tile(x, y).Layer(7).Tileset = 1
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

' Save the new map
F = FreeFile
Open FileName2 For Binary As #F
Put #F, , NewMap
Close #F
Next i
End Sub

```
Link to comment
Share on other sites

youforgot to redim the oldmap tiles as well. just add this to it.

ReDim oldMap.Tile(0 To MAX_MAPX, 0 To MAX_MAPY)

also the 224 should be 7 as that's what the original amount of tiles there where in a tile sheet originally.  other wise the math will not turn out correct. since the x and y are done by tile index rather than by actual size.

so math wise   ground being lets say 5

  5 / 7 = 0 because of rounding. * 32 = 0
  5 mod 7 = 5 * 32 = 160;

now with what you did

   5/224 = 0 becuase of rounding but  8/224 = 0 as well when it should equal 1 after rounding.
while also
5 mod 224 = 5 but
8 mod 224 = 8 when it

now when you do it like this with the new numbers

8 mod 7 = 1 * 32 = 32
8 / 7 = 1 * 32 = 32

which is the correct number of pixels to the tile's square.  Though you can simply remove  *32 to keep just the tile position then times it by 32 later that way you can make the x and y a byte
Link to comment
Share on other sites

TILESHEET_WIDTH = 224 pixels for the tilesheet im using. Or do I divide 224 by 32 to get the correct TILESHEET_WIDTH?

* * *

Still get subscript out of range with this code.

```
Sub ConvertOldMapsToNew()
Dim FileName As String
Dim FileName2 As String
Dim m As Long
Dim i As Long
Dim F As Long
Dim x As Long, y As Long
Dim OldMap As OldMapRec
Dim NewMap As NewMapRec
ReDim NewMap.Tile(0 To MAX_MAPX, 0 To MAX_MAPY)
ReDim OldMap.Tile(0 To MAX_MAPX, 0 To MAX_MAPY)

For i = 1 To MAX_MAPS
FileName = App.Path & "\maps\map" & i & ".dat"
FileName2 = App.Path & "\new 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.Up = OldMap.Up
NewMap.Down = OldMap.Down
NewMap.Left = OldMap.Left
NewMap.Right = OldMap.Right
NewMap.BootMap = OldMap.BootMap
NewMap.BootX = OldMap.BootX
NewMap.BootY = OldMap.BootY
For y = 0 To MAX_MAPY
For x = 0 To MAX_MAPX
NewMap.Tile(x, y).Layer(1).x = (OldMap.Tile(x, y).Ground \ 7) * PIC_X
NewMap.Tile(x, y).Layer(1).y = (OldMap.Tile(x, y).Ground \ 7) * PIC_Y
NewMap.Tile(x, y).Layer(3).x = (OldMap.Tile(x, y).Mask \ 7) * PIC_X
NewMap.Tile(x, y).Layer(3).y = (OldMap.Tile(x, y).Mask \ 7) * PIC_Y
NewMap.Tile(x, y).Layer(7).x = (OldMap.Tile(x, y).Fringe \ 7) * PIC_X
NewMap.Tile(x, y).Layer(7).y = (OldMap.Tile(x, y).Fringe \ 7) * PIC_Y
NewMap.Tile(x, y).Layer(1).Tileset = 1
NewMap.Tile(x, y).Layer(3).Tileset = 1
NewMap.Tile(x, y).Layer(7).Tileset = 1
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

' Save the new map
F = FreeFile
Open FileName2 For Binary As #F
Put #F, , NewMap
Close #F
Next i
End Sub
```
Link to comment
Share on other sites

Does your old maps use Mask2 or Fringe2 at all? If so:

```
Sub ConvertOldMapsToNew()
   Dim FileName As String, FileName2 As String
   Dim M As Long, I As Long, F As Long, X As Long, Y As Long
   Dim OldMap As OldMapRec
   Dim NewMap As NewMapRec

   ReDim NewMap.Tile(0 To MAX_MAPX, 0 To MAX_MAPY) As NewTileRec
   ReDim OldMap.Tile(0 To MAX_MAPX, 0 To MAX_MAPY) As OldTileRec

   For I = 1 To MAX_MAPS
       FileName = App.Path & "\maps\map" & I & ".dat"
       FileName2 = App.Path & "\new maps\map" & I & ".dat"

       ' Get the old file.
       F = FreeFile
       Open FileName For Binary Access Read As #F
           Get #F, , OldMap
       Close #F

       ' Convert.
       NewMap.Name = OldMap.Name
       NewMap.Music = OldMap.Music
       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.BootMap = OldMap.BootMap
       NewMap.BootX = OldMap.BootX
       NewMap.BootY = OldMap.BootY
       NewMap.MaxX = MAX_MAPX
       NewMap.MaxY = MAX_MAPY

       For Y = 0 To MAX_MAPY
           For X = 0 To MAX_MAPX
               NewMap.Tile(X, Y).Layer(MapLayer.Ground).X = (OldMap.Tile(X, Y).Ground \ 7) * PIC_X
               NewMap.Tile(X, Y).Layer(MapLayer.Ground).Y = (OldMap.Tile(X, Y).Ground \ 7) * PIC_Y
               NewMap.Tile(X, Y).Layer(MapLayer.Mask1).X = (OldMap.Tile(X, Y).Mask \ 7) * PIC_X
               NewMap.Tile(X, Y).Layer(MapLayer.Mask1).Y = (OldMap.Tile(X, Y).Mask \ 7) * PIC_Y
               NewMap.Tile(X, Y).Layer(MapLayer.Mask2).X = (OldMap.Tile(X, Y).Mask2 \ 7) * PIC_X
               NewMap.Tile(X, Y).Layer(MapLayer.Mask2).Y = (OldMap.Tile(X, Y).Mask2 \ 7) * PIC_Y
               NewMap.Tile(X, Y).Layer(MapLayer.Fringe1).X = (OldMap.Tile(X, Y).Fringe \ 7) * PIC_X
               NewMap.Tile(X, Y).Layer(MapLayer.Fringe1).Y = (OldMap.Tile(X, Y).Fringe \ 7) * PIC_Y
               NewMap.Tile(X, Y).Layer(MapLayer.Fringe2).X = (OldMap.Tile(X, Y).Fringe \ 7) * PIC_X
               NewMap.Tile(X, Y).Layer(MapLayer.Fringe2).Y = (OldMap.Tile(X, Y).Fringe \ 7) * PIC_Y
               NewMap.Tile(X, Y).Layer(MapLayer.Ground).Tileset = 1
               NewMap.Tile(X, Y).Layer(MapLayer.Mask1).Tileset = 1
               NewMap.Tile(X, Y).Layer(MapLayer.Mask2).Tileset = 1
               NewMap.Tile(X, Y).Layer(MapLayer.Fringe1).Tileset = 1
               NewMap.Tile(X, Y).Layer(MapLayer.Fringe2).Tileset = 1
               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
       Next

       For X = 1 To 15
           NewMap.Npc(X) = OldMap.Npc(X)
       Next

       ' Save the new map
       F = FreeFile
       Open FileName2 For Binary Access Write As #F
           Put #F, , NewMap
       Close #F
   Next
End Sub
```
I didn't know if you have any NPCs on your old maps either, so I added a convert to that too.

Also for your error, what line is it pointing to?
Link to comment
Share on other sites

@'Xlithan':

> TILESHEET_WIDTH = 224 pixels for the tilesheet im using. Or do I divide 224 by 32 to get the correct TILESHEET_WIDTH?
>
> * * *
>
> Still get subscript out of range with this code.

first of all 7 *32 is 224\. also make sure those maps exist in the folder before trying to read them and what line is the subscript out of range happening on exactly? if all else fails it might not be reading the data into the map so you may need to break point debug it to insure the data exists. If you need help with this i can help you.
Link to comment
Share on other sites

Nickpop that wouldn't make a difference anyway.

Genusis the maps exist, it loads them just fine as it sets the name value ok. It's only when it gets to the tiles part that I get the error.

it's when it gets to this line:
**NewMap.Tile(x, y).Layer(MapLayer.Ground).x = (OldMap.Tile(x, y).Ground \ 7) * PIC_X**

and the error comes from:
**OldMap.Tile(x, y).Ground**
Link to comment
Share on other sites

If this still hasn't been fixed, I'd like to butt in and suggest a possible fix.

You say the error come from **OldMap.Tile(x, y).Ground**. I think it's because you're not loading the old maps properly.
```
' Get the old file
F = FreeFile
Open FileName For Binary As #F
Get #F, , OldMap
Close #F

```In Eclipse, the Maps are saved by dumping every variable manually and not the entire structure because there is a variable sized array (the Tile array in Map). So, you'll have to load the OldMap each variable at a time like
```
f = freefile
open file name for binary as #f
get #f, , oldmap.Name
.
.
.
close #f

```You can get the loading code from server side map loading, if you don't want to type it all over again.
You'll have to save the map the same way, one variable at a time.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...