One of the things I enjoy about designing The Devil’s Own Fun is that I can take diversions in what I’m working on. If I don’t feel like doing Order of Battle research, I’ll work on the maps. If I don’t want to do either, I’ll lay out scenario information.
Lately, I’ve gotten very interested in line-of-sight (LOS) issues with the game. It’s got a combination of 40-foot elevations, ridges, slopes, buildings and woods. All of which have an impact on whether one unit can see another.
The traditional LOS process for the Great Battles of the Civil War (GBACW) uses what is essentially specially labeled graph paper.
I thought about doing something similar, but I’ve never been happy with the way you don’t get an accurate cross section because it’s too difficult to determine the proportion of terrain that’s under various hexes along the LOS.
Since I have some programming knowledge and experience, I decided to use my knowledge to build a tool that would let me see whether any two points on the map are able to see each other.
The first step was to populate it with information from the map. I initially tried it with the full-sized map and wrote a simple program that scanned through each x and y point reading the color from the “elevation” layer of the GIMP file. This didn’t work because the function I used only read visible pixels and most of them were off the screen. So I resized the map to 42% which was big enough to provide detail but small enough to allow everything to fit on my screen. This created a database 1100 x 1000 pixels or just over 1,100,000 records. I did the same thing for the other “topographic” layers of the map:
Woods: 30 feet
Buildings: 20 feet
Slopes: +10 feet
Ridges: + 25 feet
Infantry / Artillery: 5 feet
Cavalry: 10 feet
Once the pixels were stored, it was a simple process to store each additional height and flag the type of terrain represented by it.
Next, I tested clicking on the map and setting the x/y starting and ending points and using these points to calculate the information needed to determine the equation of the line that would connect them. The equation of a line is:
y = mx + b
where m is the slope and b is the y-intercept (where the line crosses the y-axis). I also had to calculate the distance between the starting and ending points.
To generate the terrain cross-section, I ran the line through a transformation to rotate it from the angle shown to horizontal so I could overlay another window with the terrain height and the height of the elements on it.
The final step was to determine if the line connecting the starting and ending points crossed any of the pixels along the cross-section. This relied again on calculating the components of the line equation and for each x-axis value determining whether the height of the line was greater than the height of the base terrain and the terrain overlaid on it.
If any pixel of the connecting line was blocked, then the LOS was blocked and the window would display “BLOCKED” while if it wasn’t, the window would display “CLEAR.”