VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsMapping"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Function craftMap(roomID As Long) As Integer
Dim roomItem() As String, itemDat() As String, colourPart() As String, spotX As Integer, spotY As Integer, fX As Integer, fY As Integer

'Get a free mapslot
For s = 1 To UBound(mINDEX)
If mINDEX(s) = 0 Then
    craftMap = s
    Exit For
End If
Next s

mINDEX(craftMap) = roomID

'Dump previous map for this slot
For D = -1 To 60
For e = 1 To 60
mWALK(craftMap, D, e) = 0
Next e
Next D

mWALK(craftMap, -1, 0) = modelID(HoloDB.runRead("SELECT model FROM guestrooms WHERE id = '" & roomID & "'"))

fRow = HoloDB.runRead("SELECT ftype,pos,rot,height,var,colour,top FROM furniture WHERE room = '" & roomID & "' AND not(ftype = 'poster')")
3
If fRow <> "" Then
    roomItem() = Split(fRow, Chr(13))
    For I = 0 To UBound(roomItem)
        itemDat() = Split(roomItem(I), Chr(9))
        
        fX = Split(itemDat(1), " ")(0)
        fY = Split(itemDat(1), " ")(1)
        
        colourPart() = Split(itemDat(5), Chr(30))
        
        If Val(itemDat(2)) = 0 Or Val(itemDat(2)) = 4 Then
            extX = Val(colourPart(0))
            extY = Val(colourPart(1))
        Else
            extX = Val(colourPart(1))
            extY = Val(colourPart(0))
        End If
                
        Select Case itemDat(0)
            Case "solid"
                If Val(itemDat(3)) = 0 And (mWALK(craftMap, spotX, spotY) = 2) = False Then 'If the furniture you are picking up is standing on the ground (so not stacked) and there isn't a chair on the same spot (so a stacked chair)
                    newBlock = 1
                End If
                
            Case "sit"
                newBlock = 2
        End Select
        
        For spotX = fX To fX + extX - 1
            For spotY = fY To fY + extY - 1
                mWALK(craftMap, spotX, spotY) = newBlock
                If newBlock = 2 Then
                    mROT(craftMap, spotX, spotY) = Val(itemDat(2))
                    mHSIT(craftMap, spotX, spotY) = Replace(Val(itemDat(3)) + Val(itemDat(6)), ",", ".")
                End If
            Next spotY
        Next spotX
                
    Next I
End If
End Function
Function simplePath(Index As Integer) As String
Dim checkX As Integer, checkY As Integer, checkR As Integer
simplePath = 0
With Holo(Index)

'If the user has reached destination, stop
If .PosX = .DestX And .PosY = .DestY Then Exit Function

'Find the next square
If .PosX > .DestX And .PosY > .DestY Then
    checkX = .PosX - 1
    checkY = .PosY - 1
    checkR = 7
ElseIf .PosX < .DestX And .PosY < .DestY Then
    checkX = .PosX + 1
    checkY = .PosY + 1
    checkR = 3
ElseIf .PosX > .DestX And .PosY < .DestY Then
    checkX = .PosX - 1
    checkY = .PosY + 1
    checkR = 5
ElseIf .PosX < .DestX And .PosY > .DestY Then
    checkX = .PosX + 1
    checkY = .PosY - 1
    checkR = 1
ElseIf .PosX > .DestX Then
    checkX = .PosX - 1
    checkY = .PosY
    checkR = 6
ElseIf .PosX < .DestX Then
    checkX = .PosX + 1
    checkY = .PosY
    checkR = 2
ElseIf .PosY < .DestY Then
    checkX = .PosX
    checkY = .PosY + 1
    checkR = 4
ElseIf .PosY > .DestY Then
    checkX = .PosX
    checkY = .PosY - 1
    checkR = 0
End If

'Check if the square is inside the heightmap, if it is, set the new height, if not (so it's 20) stop here
nHeight = staticModel(mWALK(.guestMapSlot, -1, 0)).mapSpot(checkX, checkY)
If nHeight = 20 Then Exit Function
nHeight = nHeight & ".0" 'Fix the height

'Check if there is no solid furniture on the spot
If mWALK(.guestMapSlot, checkX, checkY) = 1 Then Exit Function

'Check if a user is on the next square
For p = 1 To Server.sckCount
If Holo(p).guestRoom = .guestRoom Then If Holo(p).PosX = checkX And Holo(p).PosY = checkY Then Exit Function
Next p
        
'Output the result
simplePath = checkX & "/" & checkY & "/" & checkR & "/" & nHeight

End With
End Function

