-
Notifications
You must be signed in to change notification settings - Fork 32
Chapter H: LOS Code Revisions
Doug Rimmer edited this page Sep 21, 2025
·
2 revisions
Back in the day David Sullivan did an excellent job of creating the current LOS tool. In its initial creation the tool did not handle boards that had been cropped or flipped or had overlays added to them or were HASL maps. Over time, piecemeal efforts to include boards of this type have added a level complexity to the tool that is not longer effective or sustainable. Thus it has been necessary to revamp the LOS Code to handle multiple board configurations and types. VASL6.7.1-beta6 includes the first iteration of the revised code.
The LOS code does two different things:
- Sets up the LOS Engine environment When a game is opened various code classes extract data from the board files and create a series of objects to hold this data which is used when conducting a LOS check.
- Implements the LOS rules When a LOS Check is made during play, various code classes implement the LOS rules, using the data objects created at startup. The initial revamp of the LOS Code includes changes to deal with the first aspect, setting up the LOS Engine environment, and does not change the implementation of LOS rules (one or two bug fixes aside). Additional stages of the revamp will (1) revise the code used to apply LOS rules and (2) move all of the LOS code into one area of the VASL code base. At present bits and pieces of the code used are found in a number of classes which often makes debugging harder.
The flow of revised code is as follows:
- A new game is (a) created via Boardpicker or (b) opened from a saved game file (.vsav).
- The game initialises for normal VASL use without change.
- As part of that initialization process, ASLMap.setBoards() invokes the buildVASLMap() method in ASLMap. All of the LOS setup is triggered by the call to the buildVASLMap() method. At some point this method should be migrated out of ASLMap. All changes to the LOS code begin at this point in the LOS process. However, a few minor additions have been made to classes such as ASLBoards to enable retrieval of data required by the LOS code, such as crop values.
- buildVASLMap() sets and calculates a number of variables related to cropping and flipping for each of the boards in the map. It then creates a LOS.Map.Map object and adds to it a HexGrid[][] object sized and shaped to the final full map configuration (adjusting both the width of the left and right edge hexes and the height of the topleft hex (half or full width depending on crop dimensions).
- Finally, buildVASLMap calls ASLMap.addBoardstoMap to populate the hexGrid, create and populate the TerrainGrid and Elevation Grid, and then amend those as necessary to apply terrain transformations, overlays and then flipping.
- addBoardstoMap() cycles through each board in the Map. First, in BoardArchive.addLOSDataToMap() it opens the board archive file and reads the LOSData file, storing the required information in the TerrainGrid and ElevationGrid objects for the map. This information is filtered by the crop dimensions (if any) and only the necessary data is added to the Grid.
- Next, addLOSDataToMap() calls board.applyColorSSRulestoTerrainElevationGrids() to apply terrain transformations to the LOSData. Individual pixels in the TerrainGrid and ElevationGrid are changed to the appropriate terrain typeCode as per the terrainType in the SharedBoardMetaData.xml file.
- After that, addLOSDataToMap() calls ASLMap.adjustLOSForOverlays() which performs a similar pixel exchange, this time using pixel values from the overlay to replace data in the TerrainGrid and ElevationGrid. Almost all traditional overlays handled by boardPicker are handled here.
- Next, addLOSDataToMap() calls LOS.Map.Map.flipTerrainAndElevationGrids() which reset the TerrainGrid and ElevationGrid values in flipped order. It is important to apply all changes to the LOSData before flipping the grids in order to properly align these changes.
- At this stage all of the required setup up and modification of the TerrainGrid and ElevationGrid are complete.
- addLOSDataToMap now adds data to the emply hexGrid for the map as a whole, created by ASLMap.buildVASLMap. For the hexGrid, if the board is flipped the data is not added to hexGrid but is stored in a new hexGrid, flippedGrid in an unflipped configuration. flippedGrid is then used to “flip” the hexGrid by copying hexes into hexGrid in reverse order. addLOSDataToMap also performs several updates to data stored in the individual Hex objects held in the hexGrid.
- Next, addLOSDataToMap() calls board.applyColorSSRulestoHexGrid() to apply terrain transformations to the hexGrid. After that addLOSDataToMap() calls ASLMap.adjustLOSForOverlays() which changes hexGrid data to reflect overlays present in the map.
- After that, addLOSDataToMap() calls LOS.Map.Map.setRBrrembankments(), .setPartialOrchards() and .setSlopes to further update the hexGrid.
- Finally, addBoardstoMap calls LOS.Map.Map.resetHexTerrain() in order to update values stored in the Hex objects held in the hexGrid with the all the previous changes to the TerrainGrid and ElevationGrid.
- At this stage all of the required setup and modifications of the hexGrid are complete.
- Once steps 6 – 15 are completed for each board in the map, ASLMap.addBoardsToMap calls LOS.Map.Map.resetHexTerrain() one more time to make any final changes required to the hexGrid (Note: this may no longer be necessary).