After learning a little bit more on the journey of Java, I've revisited my earlier mod for the lightning effect. As some may recall, I issued a mod a couple or few years ago which made significant improvements. But I've discovered that further refinement is in order.
Let's first review the stock scheme, probably as implemented at year dot and left unchanged ever since.
- The lightning bolt itself has 5 variations, of differing degrees of zig-zagging, so that not every zap looks the same. They are randomly selected from at each occurrence. This is good.
- There were 2 illumination sources created; one 100m below the bolt top and of a low intensity/radius, and the other 1/3 the distance from sea level to the cloud base and of greater intensity/farther radius. The weaker, higher source is superfluous, really, for it is greatly dominated by the other. Having the 'main' light source position in altitude set with respect to sea level is problematic for higher terrain. When the ground is high enough the light source will be
under the surface, with the result that objects are now illuminated from below!
- The bolt is generated so that the bottom is always at seal level, and the top is at the cloud base. This is bad for two reasons. (1) Because of the zig-zagging line of the bolt, when the terrain has any significant elevation the point where the bolt emerges from the ground could be significantly displaced on the X-Y plane from the point down at sea level. This then has the bolt offset from the center of the circle of illumination, the latter of which is always exactly over the base of the bolt. (2) Having the top of the bolt terminate exactly at the cloud base, there's often a noticeable 'gap' between bolt top and the cloud; real bolts from cloud tend to extend well up into the cloud.
============================
In my earlier treatment I has made some false assumptions about the reference heights involved in the calculations. Upon looking at this again I immediately suspected my errors, and confirmed them by temporarily adding some output code to display during play the values of any variables of concern. And so I've re-jigged Zip.class for even better behaviour.
My older changes, retained:
- The bolt extends well up inside the cloud.
- The intensity of the illumination is scaled by the Sun's angular elevation, getting stronger as twilight deepens into night. I have further tweaked the algorithm.
- The color has been changed from pure white to a slight pinkish hue characteristic of lightning.
The main, current changes:
- The lightning bolt now extends to the actual ground surface, not all the way down to sea level. This ensures the illumination circle and bolt position on the ground are coincident.
- I have eliminated the superfluous second light source at the bolt top. The 'main' light source does all the work in lighting up the environs.
- The now single light source has its height fixed at 500m above ground level. This assures consistent illumination behaviour where terrain height is variable.
- When the terrain crosses a certain threshold elevation with respect to the cloud base height, lightning effects are not generated. This ensures no such silliness as a lightning flash occurring over mountains where part or all of the cloud is below ground.
- The former duration of a flash was fixed at 0.5 seconds; now it's randomly variable between 0.3 and 0.5.
- I've increased the frequency of occurrence, in large part to represent thunderstorm activity in the tropics and at lower latitudes in general. I will likely see about incorporating a check on the map CAMOUFLAGE as well as the DECLIN value, having a flash frequency rate scaled according to two or more variables. For instance, thunder activity in winter at higher latitudes should have a lower flash frequency.