Elvas Tower: HASHEAD signal function - Elvas Tower

Jump to content

  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

HASHEAD signal function How, if at all, can it be used? Rate Topic: -----

#1 User is offline   ebnertra000 

  • Superintendant
  • Group: Status: Elite Member
  • Posts: 1,234
  • Joined: 27-February 17
  • Gender:Male
  • Location:East-Central Minnesota
  • Simulator:OR/TSRE
  • Country:

Posted 13 May 2019 - 01:42 PM

I'm working on some signals, and ran into a problem: for the same rule, the aspect is completely different between two- and three-headed signals. I wondered, could I use this HASHEAD function to differentiate between two- and three-head signals, and get the right aspect for each case? Or would I be better off trying to use one of the user settings to achieve this effect?

#2 User is offline   eugenR 

  • Conductor
  • Group: Status: Contributing Member
  • Posts: 472
  • Joined: 15-April 13
  • Gender:Male
  • Simulator:MSTS
  • Country:

Posted 14 May 2019 - 05:33 AM

I am not sure if I understand your Problem correct:
You will use a shape with a optional third Signalhead and if the third Head is in use, the signal has to show different aspects?

Yes for that you can use HASHEAD

In the signalshape-definition in the sigcfg.dat You will have the optional Signalhead which, as example, has the name HEAD3:
			SignalSubObj ( 4
				"HEAD3"
				"Signalkopf Ausfahrvorsignal"
				SigSubType ( SIGNAL_HEAD )
				SignalFlags ( DEFAULT OPTIONAL )
				SigSubSType ( "ChLVorsignal" )
			)

In the script of this signal in the sigscr.dat
you need the following code:
float    test;
test = HASHEAD(HEAD3);

If test = 1 ;
{
code a;
}
else
{
code b;
}

so you can write different code for zwo and three-Head-Signals
See Manual Chapter 10.15.6

#3 User is offline   ebnertra000 

  • Superintendant
  • Group: Status: Elite Member
  • Posts: 1,234
  • Joined: 27-February 17
  • Gender:Male
  • Location:East-Central Minnesota
  • Simulator:OR/TSRE
  • Country:

Posted 14 May 2019 - 07:56 AM

That's exactly what I was thinking of doing with it. I suppose the next question is can you do multiple tests for heads in the same script (I have up to four heads available in the third head position, depending on how many lights the head needs). I assume it would just need a separate float for each test?

Those code snippets might be useful in the Manual, as I wasn't really sure how to use it.

Oh, and is that supposed to be a normal colon after HASHEAD(HEAD3)?

#4 User is offline   eugenR 

  • Conductor
  • Group: Status: Contributing Member
  • Posts: 472
  • Joined: 15-April 13
  • Gender:Male
  • Simulator:MSTS
  • Country:

Posted 14 May 2019 - 08:52 AM

View Postebnertra000, on 14 May 2019 - 07:56 AM, said:

That's exactly what I was thinking of doing with it. I suppose the next question is can you do multiple tests for heads in the same script (I have up to four heads available in the third head position, depending on how many lights the head needs). I assume it would just need a separate float for each test?

Those code snippets might be useful in the Manual, as I wasn't really sure how to use it.

Oh, and is that supposed to be a normal colon after HASHEAD(HEAD3)?

No, semicolon as usual, It was an error, sorry.
I have not used this as multiple test, but I don't see a problem. As you have written, just separate floats.

You can use this feature also, if you need more then the four USER1...4 in this case you use a signalhead-name that doesn't exist in the shape.

#5 User is offline   roeter 

  • Vice President
  • Group: Status: Elite Member
  • Posts: 2,420
  • Joined: 25-October 11
  • Gender:Male
  • Country:

Posted 16 May 2019 - 02:49 AM

View PosteugenR, on 14 May 2019 - 08:52 AM, said:

You can use this feature also, if you need more then the four USER1...4 in this case you use a signalhead-name that doesn't exist in the shape.

Correct - you can add 'flags' to a signal definition by defining an optional 'head', with SigSubType 'DECOR'. The head does not need to exist in the shape. A signal definition can have upto 32 heads, that's the maximum.

Here is an example of a banner repeater signal (light display, not semaphore), which has a set of options which define when the banner is to show the 'clear' aspect :

	SignalShape (
		"NF_Theatre_Banner.s"
		"NF Banner Light"
		SignalSubObjs ( 9
			SignalSubObj ( 0
				"HEAD1"
				"Signal"
				SigSubType ( SIGNAL_HEAD )
				SignalFlags ( DEFAULT )
				SigSubSType ( "NF_THEATRE_Banner_Clear" )
			)
			SignalSubObj ( 1
				"HEAD2"
				"Signal"
				SigSubType ( SIGNAL_HEAD )
				SignalFlags ( DEFAULT )
				SigSubSType ( "NF_THEATRE_Banner_Stop" )
			)
			SignalSubObj ( 2
				"USECL2"
				"Display on CLEAR_2"
				SigSubType ( DECOR )
				SignalFlags ( DEFAULT OPTIONAL )
			)
			SignalSubObj ( 3
				"USECL1"
				"Display on CLEAR_1"
				SigSubType ( DECOR )
				SignalFlags ( DEFAULT OPTIONAL )
			)
			SignalSubObj ( 4
				"USEAP3"
				"Display on APPROACH_3"
				SigSubType ( DECOR )
				SignalFlags ( DEFAULT OPTIONAL )
			)
			SignalSubObj ( 5
				"USEAP2"
				"Display on APPROACH_2"
				SigSubType ( DECOR )
				SignalFlags ( DEFAULT OPTIONAL )
			)
			SignalSubObj ( 6
				"USEAP1"
				"Display on APPROACH_1"
				SigSubType ( DECOR )
				SignalFlags ( DEFAULT OPTIONAL )
			)
			SignalSubObj ( 7
				"USERES"
				"Display on RESTRICTING"
				SigSubType ( DECOR )
				SignalFlags ( OPTIONAL )
			)
			SignalSubObj ( 8
				"USESPR"
				"Display on STOP_AND_PROCEED"
				SigSubType ( DECOR )
				SignalFlags ( OPTIONAL )
			)
		)
	)


The two signaltypes defined in this shape, share the same script with just the display state reversed :

	SignalType ( "NF_THEATRE_BANNER_CLEAR" 
		SignalFnType ( INFO )
		SignalLightTex ( "tb-banner-clear-ltex" )
		ORTSScript ( NF_BANNER_LIGHT )

		SignalLights ( 1
			SignalLight ( 0 "White Light"
				Position ( 0 0.405 0.1 )
				Radius ( 0.38 )
			)
		)

		SignalDrawStates ( 2
			SignalDrawState ( 0
				"Blank"
			)
			SignalDrawState ( 1
				"Show"
				Drawlights ( 1
					DrawLight ( 0 )
				)
			)
		)

		SignalAspects ( 0 )
	)

	SignalType ( "NF_THEATRE_BANNER_STOP" 
		SignalFnType ( INFO )
		SignalLightTex ( "tb-banner-stop-ltex" )
		ORTSScript ( NF_BANNER_LIGHT )

		SignalLights ( 1
			SignalLight ( 0 "White Light"
				Position ( 0 0.405 0.1 )
				Radius ( 0.38 )
			)
		)

		SignalDrawStates ( 2
			SignalDrawState ( 0
				"Show"
				Drawlights ( 1
					DrawLight ( 0 )
				)
			)
			SignalDrawState ( 1
				"Blank"
			)
		)

		SignalAspects ( 0 )
	)


And this the related script :


SCRIPT NF_BANNER_LIGHT

// Banner Repeater Light General Script

	extern float	route_set ();
	extern float	next_sig_lr ();
	extern float	draw_state;
        float           routevalid;
        float           nextstate;

// Draw state : 
//   0 : not shown
//   1 : shown
//
// No signal aspects
//
// User flags :
//
//   2 : USECL2    : display on CLEAR_2
//   3 : USECL1    : display on CLEAR_1
//   4 : USEAP3    : display on APPROACH_3
//   5 : USEAP2    : display on APPROACH_2
//   6 : USEAP1    : display on APPROACH_1
//   7 : USERES    : display on RESTRICTING
//   8 : USESPR    : display on STOP_AND_PROCEED

// Set default to no display
    draw_state = 0;

    nextstate = next_sig_lr(SIGFN_NORMAL);

// set on next aspect

    if (hashead(2) && nextstate ==# SIGASP_CLEAR_2)
    {
        draw_state = 1;
    }

    if (hashead(3) && nextstate ==# SIGASP_CLEAR_1)
    {
        draw_state = 1;
    }

    if (hashead(4) && nextstate ==# SIGASP_APPROACH_3)
    {
        draw_state = 1;
    }

    if (hashead(5) && nextstate ==# SIGASP_APPROACH_2)
    {
        draw_state = 1;
    }

    if (hashead(6) && nextstate ==# SIGASP_APPROACH_1)
    {
        draw_state = 1;
    }

    if (hashead(7) && nextstate ==# SIGASP_RESTRICTING)
    {
        draw_state = 1;
    }

    if (hashead(8) && nextstate ==# SIGASP_STOP_AND_PROCEED)
    {
        draw_state = 1;
    }


Hope this helps,
Rob Roeterdink

#6 User is offline   ebnertra000 

  • Superintendant
  • Group: Status: Elite Member
  • Posts: 1,234
  • Joined: 27-February 17
  • Gender:Male
  • Location:East-Central Minnesota
  • Simulator:OR/TSRE
  • Country:

Posted 16 May 2019 - 03:29 AM

Rob

I'll have to try that method when I get home. The log keeps telling me HEAD6 is an invalid parameter, and not showing what it's supposed to. I probably messed up in how I used it

#7 User is offline   eugenR 

  • Conductor
  • Group: Status: Contributing Member
  • Posts: 472
  • Joined: 15-April 13
  • Gender:Male
  • Simulator:MSTS
  • Country:

Posted 16 May 2019 - 04:12 AM

@Rob:
In your example the function HASHEAD( ) has a number instead of the name of the SignalSubObj:
if (hashead(2) && nextstate ==# SIGASP_CLEAR_2)

Is this the number of the SignalSubObj?
can I use in the Function both, number or Name?

Regards
Eugen

#8 User is offline   roeter 

  • Vice President
  • Group: Status: Elite Member
  • Posts: 2,420
  • Joined: 25-October 11
  • Gender:Male
  • Country:

Posted 16 May 2019 - 04:21 AM

The number must be used, which is the index of the SignalSubObj. It is now a couple of years ago since I created this function, but I don't think there is a 'translation' from the name to the number, and the function has an integer passed as parameter.
I have always used it with numbers only.

Regards,
Rob Roeterdink

#9 User is offline   eugenR 

  • Conductor
  • Group: Status: Contributing Member
  • Posts: 472
  • Joined: 15-April 13
  • Gender:Male
  • Simulator:MSTS
  • Country:

Posted 16 May 2019 - 05:17 AM

View Postebnertra000, on 16 May 2019 - 03:29 AM, said:

Rob

I'll have to try that method when I get home. The log keeps telling me HEAD6 is an invalid parameter, and not showing what it's supposed to. I probably messed up in how I used it


In the Manual Chapter 10.15.6 the function is defined with Headname:
state = HASHEAD(headname)

In my signalfile it works with a Headname, but the Headname is existimg in the shape.

regards
Eugen

#10 User is offline   ebnertra000 

  • Superintendant
  • Group: Status: Elite Member
  • Posts: 1,234
  • Joined: 27-February 17
  • Gender:Male
  • Location:East-Central Minnesota
  • Simulator:OR/TSRE
  • Country:

Posted 16 May 2019 - 06:38 AM

HEAD6 does exist on the shape I use. I may try to redo how I have it set up. I'll also try the SubObj number, too

  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users