Special Aircraft Service

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Train headlight activation  (Read 869 times)

0 Members and 1 Guest are viewing this topic.

WxTech

  • Modder
  • member
  • Offline Offline
  • Posts: 6042
Train headlight activation
« on: December 10, 2022, 06:13:45 PM »

I've been going over the train stuff lately, improving effects and such. For my earlier release of my train mod work I had forgotten about the headlights being activated by time of day, between 6PM and 6AM. Because of the seasonal and latitudinal variation in times of sunset/sunrise, which gets very large at higher latitudes, the better determinant is the actual Sun angular elevation. For instance, in the dead of winter at 50 degrees latitude the Sun is setting at around 4PM; by 6PM it's already been dark for over an hour.

And so I'm altering the two locomotive classes accordingly. I'm thinking of having the lights come on when the Sun is below -6 degrees, which is the transition between civil and nautical twilight. Does this seem OK?


Also already present in the code is a test for the presence of enemy planes getting within 1.5km to cause the lights to go off. I'm going to modify this as follows. The distance threshold for the detection of an enemy plane will get smaller as twilight gets darker. A provisional range of values would be 3km when the Sun is at -6 degrees elevation, going down to perhaps 750m-1000m when the Sun is at -18 degrees and below (the end of astronomical twilight.)



If anyone has any thoughts on the Sun elevation threshold and the enemy plane distance range for turning off, let me know.
Logged
Great minds discuss ideas. Average minds discuss events. Small minds discuss people. - Hyman Rickover (but probably predating his use.)

WxTech

  • Modder
  • member
  • Offline Offline
  • Posts: 6042
Re: Train headlight activation
« Reply #1 on: December 10, 2022, 07:34:30 PM »

I was just doing some testing of the locomotive headlights turning off when my plane gets close, to verify that with increasing darkness the shut-off occurs at a shrinking distance. And I checked out some adjusted fire behaviour for destroyed wagons. Here are a couple screenies of a nighttime fuel train shoot 'em up. The first image is immediately upon one of the fuel cars exploding (there's a random chance of this happening), and the second image is of a different car going up, when the fireball has reached maximum size and is fading out. Explosions create an illumination, as does the longer lasting fire, when in the larger, initial stage (the fire shrinks down after a while.)



Logged
Great minds discuss ideas. Average minds discuss events. Small minds discuss people. - Hyman Rickover (but probably predating his use.)

WxTech

  • Modder
  • member
  • Offline Offline
  • Posts: 6042
Re: Train headlight activation
« Reply #2 on: December 10, 2022, 07:55:32 PM »

For the curious I present below the relevant code snippets in the two locomotive classes. (The original code has been 'REMed out' with "//" characters preceding.)


This first one sets the window of time within which the loco lights can be on. Previously it was set between 06h and18h; now it's when the tangent of the Sun's angular elevation is less than -0.1, or just about 6 degrees below the horizon. The addition condition, "danger", is a boolean that is true when my plane is within the distance of detection for light shut-off.

Code: [Select]
//            if((double)fn < 18D && (double)fn >= 6D || danger())
if(World.Sun().ToSun.z > -0.1 || danger())
            {
                Light1._setIntesity(0.0F);
                Light2._setIntesity(0.0F);
            }

This second snippet is the full "danger" method, which sets the varying headlight cut-off distance as darkness varies. I use the cvt method to apply a linear scaling factor of between 1.0 and 0.25 when the tangent of the Sun's elevation varies between -0.1 (about -6 degrees) and -0.31 (-18 degrees), respectively. The base distance is 3000m, which applies at a Sun depression of -6 degrees, decreasing to 0.25 * 3000 = 750m when the Sun is at -18 degrees or lower. The previous distance cut-off was a fixed 1500m.

Code: [Select]
    private boolean danger()
    {
        Point3d point3d = new Point3d();
        super.pos.getAbs(point3d);
        Vector3d vector3d = new Vector3d();
        for(java.util.Map.Entry entry1 = Engine.name2Actor().nextEntry(null); entry1 != null; entry1 = Engine.name2Actor().nextEntry(entry1))
        {
            Actor actor1 = (Actor)entry1.getValue();
float scaleDist = MiscEffects.cvt(World.Sun().ToSun.z, -0.31F, -0.1F, 0.25F, 1.0F);
//            if(Actor.isAlive(actor1) && (actor1 instanceof Aircraft) && actor1.getArmy() != myArmy && actor1.pos.getAbsPoint().distance(point3d) < 1500D)
            if(Actor.isAlive(actor1) && (actor1 instanceof Aircraft) && actor1.getArmy() != myArmy && actor1.pos.getAbsPoint().distance(point3d) < 3000F * scaleDist)
                return true;
        }

        return false;
    }
Logged
Great minds discuss ideas. Average minds discuss events. Small minds discuss people. - Hyman Rickover (but probably predating his use.)

Draken

  • member
  • Offline Offline
  • Posts: 1133
Re: Train headlight activation
« Reply #3 on: December 10, 2022, 08:15:43 PM »

Interesting stuff , even if I think that in real history no trains where attacked by night .
It would be very hazardous for attacking planes to fly at low level by night .
Logged

WxTech

  • Modder
  • member
  • Offline Offline
  • Posts: 6042
Re: Train headlight activation
« Reply #4 on: December 11, 2022, 12:40:39 AM »

In twilight one can see well enough. And around the time of full Moon.

Anyhoo, with regard to the Loco lights I'm working with the existing feature, refining it further at no resource or performance cost.
Logged
Great minds discuss ideas. Average minds discuss events. Small minds discuss people. - Hyman Rickover (but probably predating his use.)

shardana

  • member
  • Offline Offline
  • Posts: 863
Re: Train headlight activation
« Reply #5 on: December 11, 2022, 03:41:36 AM »

Love it
Logged

PO_MAK_249RIP

  • CMON U SPURS!
  • member
  • Offline Offline
  • Posts: 2099
Re: Train headlight activation
« Reply #6 on: December 11, 2022, 06:24:05 AM »

WxTech the wızard!! More great stuff
Logged
Corsair Carbide case, Intel core i5 4690 3.5ghz with Arctic Cooler, Asus Rock H97 performance, MSI Ventus XS OC 1660GTX 6GB DDR6, 32GB Patriot Viper 1600Mhz, 256GB/500GB Crucial SSDs, Windows 10 64bit.

ecf111

  • member
  • Offline Offline
  • Posts: 344
Re: Train headlight activation
« Reply #7 on: December 11, 2022, 07:34:19 AM »

This is great thanks!! Perfect for Korean Era night interdiction missions!
Logged
Create.

Dimlee

  • member
  • Offline Offline
  • Posts: 1267
Re: Train headlight activation
« Reply #8 on: December 11, 2022, 02:23:47 PM »

Regarding the Sun elevation...  In the days of old, on merchant vessels, we had a tradition to switch on navigation lights immediately after sunset in perfect weather and somewhat earlier when visibility was worse. Train drivers know better, of course, there must be some regulations in their department.
Logged

Epervier

  • 4.09 Guardian Angel !
  • SAS Team
  • member
  • Offline Offline
  • Posts: 9544
  • I'm French and Rebel_409! Nobody is perfect!
    • Some tinkering here
Re: Train headlight activation
« Reply #9 on: December 11, 2022, 03:54:27 PM »

That's weird!
I had a doubt, so I checked the 409 code I've been using for a long time for headlight detection and activation.
And I have been using the sun for a long time: LocomotiveUSSR
Code: [Select]
public void TrainEffects(float f) {
if (danger()) {
hierMesh().chunkVisible("LocoLightFC", false);   //Headlight
hierMesh().chunkVisible("LocoLightL", false);
hierMesh().chunkVisible("LocoLightR", false);
hierMesh().chunkVisible("TenderLightL", false);   //Red rear light
} else if (((Tuple3f) (World.Sun().ToSun)).z > 0.01F) {
hierMesh().chunkVisible("LocoLightFC", false);
hierMesh().chunkVisible("LocoLightL", false);
hierMesh().chunkVisible("LocoLightR", false);
hierMesh().chunkVisible("TenderLightL", false);
} else if (((Tuple3f) (World.Sun().ToSun)).z > -0.22F) {
hierMesh().chunkVisible("LocoLightFC", false);
hierMesh().chunkVisible("LocoLightL", true);
hierMesh().chunkVisible("LocoLightR", true);
hierMesh().chunkVisible("TenderLightL", true);
} else {
hierMesh().chunkVisible("LocoLightFC", true);
hierMesh().chunkVisible("LocoLightL", true);
hierMesh().chunkVisible("LocoLightR", true);
hierMesh().chunkVisible("TenderLightL", true);
}
}

public void StopEffects() {
hierMesh().chunkVisible("LocoLightFC", false);
hierMesh().chunkVisible("LocoLightL", false);
hierMesh().chunkVisible("LocoLightR", false);
hierMesh().chunkVisible("TenderLightL", false);
}

On the other hand I do have a simple hazard detection at 1500m in all weathers!
Where does the code you refer to come from? BAT?
Logged
If your results do not live up to your expectations, tell yourself that the great oak was once an acorn too. - Lao Zi -

WxTech

  • Modder
  • member
  • Offline Offline
  • Posts: 6042
Re: Train headlight activation
« Reply #10 on: December 11, 2022, 04:17:47 PM »

Gabriel,
The danger method I built upon is taken from The New Train Mod, which is available in the Vehicles sub-Forum. This is incorporated into B.A.T., at least as far back as 4.0.

I see that the light activation in your older locolight mod puts more versatility into the various lights, the three groupings being the upper headlight, lower headlight pair, and the tender car's red light.
Logged
Great minds discuss ideas. Average minds discuss events. Small minds discuss people. - Hyman Rickover (but probably predating his use.)

Epervier

  • 4.09 Guardian Angel !
  • SAS Team
  • member
  • Offline Offline
  • Posts: 9544
  • I'm French and Rebel_409! Nobody is perfect!
    • Some tinkering here
Re: Train headlight activation
« Reply #11 on: December 12, 2022, 03:16:36 AM »

Thanks !  ;)
Logged
If your results do not live up to your expectations, tell yourself that the great oak was once an acorn too. - Lao Zi -
Pages: [1]   Go Up
 

Page created in 0.028 seconds with 24 queries.