From cb9ab9b1adcb30c617b6a7ba1bafbd50464b5853 Mon Sep 17 00:00:00 2001 From: Lucas Recoaro Date: Sat, 7 Dec 2024 12:10:48 +1300 Subject: [PATCH] Improved readability in EsArbol (#227) * 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 --- Argentum20.vbp | 1 + CODIGO/Recursos.bas | 2 +- CODIGO/TileEngine.bas | 3 ++ CODIGO/TileEngine_Map.bas | 27 ++-------------- CODIGO/clsTileEngineHelper.cls | 56 ++++++++++++++++++++++++++++++++++ 5 files changed, 63 insertions(+), 26 deletions(-) create mode 100644 CODIGO/clsTileEngineHelper.cls diff --git a/Argentum20.vbp b/Argentum20.vbp index a7bb2a6b..a26fe9d9 100644 --- a/Argentum20.vbp +++ b/Argentum20.vbp @@ -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" diff --git a/CODIGO/Recursos.bas b/CODIGO/Recursos.bas index 4f0ac507..4504b8a0 100644 --- a/CODIGO/Recursos.bas +++ b/CODIGO/Recursos.bas @@ -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 diff --git a/CODIGO/TileEngine.bas b/CODIGO/TileEngine.bas index ddea21a5..7a43b980 100644 --- a/CODIGO/TileEngine.bas +++ b/CODIGO/TileEngine.bas @@ -17,6 +17,9 @@ Attribute VB_Name = "TileEngine" ' Option Explicit +Public TileEngineHelper As New clsTileEngineHelper + + Public PreguntaScreen As String Public Pregunta As Boolean diff --git a/CODIGO/TileEngine_Map.bas b/CODIGO/TileEngine_Map.bas index 4083fe06..7951bdde 100644 --- a/CODIGO/TileEngine_Map.bas +++ b/CODIGO/TileEngine_Map.bas @@ -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 @@ -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 diff --git a/CODIGO/clsTileEngineHelper.cls b/CODIGO/clsTileEngineHelper.cls new file mode 100644 index 00000000..2d309ec3 --- /dev/null +++ b/CODIGO/clsTileEngineHelper.cls @@ -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 . + +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 +