Skip to content

Commit

Permalink
Improved readability in EsArbol (#227)
Browse files Browse the repository at this point in the history
* Refactored EsArbol

Created a new module TileEngineHelper to group code dealing with tiles

Renamed EsArbol to IsIndexTree

Put the new IsIndexTree function in the new module

Improved readibility in EsArbol

Changed Variant for Long.

* Fix

---------

Co-authored-by: Pablo Marquez Tello <[email protected]>
  • Loading branch information
RecoX and morgolock authored Dec 6, 2024
1 parent e7d53af commit cb9ab9b
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 26 deletions.
1 change: 1 addition & 0 deletions Argentum20.vbp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ Module=ModValidateResources; CODIGO\ModValidateResources.bas
Module=ModLanguage; CODIGO\ModLanguage.bas
Module=JSON; CODIGO\VBJson\JSON.bas
ResFile32="AO20.res"
Class=clsTileEngineHelper; CODIGO\clsTileEngineHelper.cls
Class=cStringBuilder; CODIGO\VBJson\cStringBuilder.cls
IconForm="frmMain"
Startup="Sub Main"
Expand Down
2 changes: 1 addition & 1 deletion CODIGO/Recursos.bas
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,7 @@ Public Sub CargarMapa(ByVal map As Integer)

InitGrh MapData(x, y).Graphic(3), MapData(x, y).Graphic(3).GrhIndex

If EsArbol(L3(i).GrhIndex) Then
If TileEngine.TileEngineHelper.IsIndexTree(L3(i).GrhIndex) Then
MapData(x, y).Blocked = MapData(x, y).Blocked Or FLAG_ARBOL
End If
Next i
Expand Down
3 changes: 3 additions & 0 deletions CODIGO/TileEngine.bas
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ Attribute VB_Name = "TileEngine"
'
Option Explicit

Public TileEngineHelper As New clsTileEngineHelper


Public PreguntaScreen As String

Public Pregunta As Boolean
Expand Down
27 changes: 2 additions & 25 deletions CODIGO/TileEngine_Map.bas
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ Attribute VB_Name = "TileEngine_Map"
'
Option Explicit


Sub SwitchMap(ByVal Map As Integer, Optional ByVal NewResourceMap As Integer = 0)


On Error GoTo SwitchMap_Err
If NewResourceMap < 1 Then
Expand Down Expand Up @@ -166,32 +168,7 @@ HayLava_Err:

End Function

Function EsArbol(ByVal GrhIndex As Long) As Boolean

On Error GoTo EsArbol_Err

EsArbol = GrhIndex = 643 Or GrhIndex = 644 Or GrhIndex = 647 Or GrhIndex = 735 Or GrhIndex = 1121 Or GrhIndex = 2931 Or _
GrhIndex = 11903 Or GrhIndex = 11904 Or GrhIndex = 11905 Or GrhIndex = 14775 Or GrhIndex = 11906 Or _
GrhIndex = 70885 Or GrhIndex = 70884 Or GrhIndex = 71042 Or GrhIndex = 71041 Or _
GrhIndex = 15698 Or GrhIndex = 14504 Or GrhIndex = 14505 Or GrhIndex = 15697 Or GrhIndex = 15510 Or _
(GrhIndex >= 12581 And GrhIndex <= 12586) Or (GrhIndex >= 12164 And GrhIndex <= 12179) Or _
(GrhIndex >= 32142 And GrhIndex <= 32152) Or GrhIndex = 32154 Or (GrhIndex >= 55626 And GrhIndex <= 55640) Or GrhIndex = 55642 Or _
(GrhIndex >= 50985 And GrhIndex <= 50991) Or (GrhIndex >= 2547 And GrhIndex <= 2549) Or (GrhIndex >= 6597 And GrhIndex <= 6598) Or (GrhIndex >= 15108 And GrhIndex <= 15110) Or _
GrhIndex = 12160 Or GrhIndex = 7220 Or GrhIndex = 462 Or GrhIndex = 463 Or _
GrhIndex >= 1877 And GrhIndex <= 1881 Or GrhIndex = 1890 Or GrhIndex = 1892 Or GrhIndex = 433 Or GrhIndex = 460 Or GrhIndex = 461 Or _
GrhIndex = 9513 Or GrhIndex = 9514 Or GrhIndex = 9515 Or GrhIndex = 9518 Or GrhIndex = 9519 Or GrhIndex = 9520 Or GrhIndex = 9529 Or _
GrhIndex = 14687 Or GrhIndex = 47726 Or GrhIndex = 12333 Or GrhIndex = 12330 Or GrhIndex = 20369 Or GrhIndex = 21120 Or GrhIndex = 21227 Or _
GrhIndex = 21352 Or GrhIndex = 12332 Or GrhIndex = 21226

GrhIndex = 21352 Or GrhIndex = 12332 Or GrhIndex = 21226 Or GrhIndex = 8258 Or GrhIndex = 32118 Or GrhIndex = 32119 Or GrhIndex = 32129 Or GrhIndex = 32132 Or _
GrhIndex = 32133 Or GrhIndex = 32135
Exit Function

EsArbol_Err:
Call RegistrarError(Err.number, Err.Description, "TileEngine_Map.EsArbol", Erl)
Resume Next

End Function

Function AgregarSombra(ByVal GrhIndex As Long) As Boolean

Expand Down
56 changes: 56 additions & 0 deletions CODIGO/clsTileEngineHelper.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "clsTileEngineHelper"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
' Argentum 20 - Game Client Program
' Copyright (C) 2023 - Noland Studios
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU Affero General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU Affero General Public License for more details.
' You should have received a copy of the GNU Affero General Public License
' along with this program. If not, see <https://www.gnu.org/licenses/>.

Option Base 0

Option Explicit

Private ValidTreeIndices() As Variant

Function IsIndexTree(ByVal GrhIndex As Long) As Boolean
On Error Resume Next
IsIndexTree = False
Dim i As Long
For i = LBound(ValidTreeIndices) To UBound(ValidTreeIndices)
If GrhIndex = ValidTreeIndices(i) Then
IsIndexTree = True
Exit Function
End If
Next i
End Function

Private Sub Class_Initialize()

ValidTreeIndices = Array(643, 644, 647, 735, 1121, 2931, 11903, 11904, 11905, 14775, 11906, 70885, 70884, 71042, 71041, 15698, 14504, 14505, 15697, 15510, 12581, 12582, 12583, 12584, 12585, 12586, _
12164, 12165, 12166, 12167, 12168, 12169, 12170, 12171, 12172, 12173, 12174, 12175, 12176, 12177, 12178, 12179, 32142, 32143, 32144, 32145, 32146, 32147, 32148, 32149, 32150, 32151, 32152, 32154, _
55626, 55627, 55628, 55629, 55630, 55631, 55632, 55633, 55634, 55635, 55636, 55637, 55638, 55639, 55640, 55642, 50985, 50986, 50987, 50988, 50989, 50990, 50991, 2547, 2548, 2549, _
6597, 6598, 15108, 15109, 15110, 12160, 7220, 462, 463, 1877, 1878, 1879, 1880, 1881, 1890, 1892, 433, 460, 461, 9513, 9514, 9515, 9518, 9519, 9520, 9529, 14687, 47726, 12333, 12330, 20369, 21120, 21227, _
21352, 12332, 21226, 8258, 32118, 32119, 32129, 32132, 32133, 32135)

End Sub

0 comments on commit cb9ab9b

Please sign in to comment.