Trainz Regional Weather Rule for TRS 2004
(Beta)

Overview
The Regional Weather Rule provides the capability to set weather in specific regions of your layout. With the conventional approach to weather changes in Trainz, changing the weather meant that the new weather applied to all the trains. However, with this rule, a specified weather pattern is applied only to a train that has the focus. So, for example, you can have a train in snow on a mountain pass, and when you change focus to a train on the seashore, it can be raining. For a train that is not in a specified region, the baseline weather applies.
Regions are specified as a (track) distance from one or more trackmarks.
Realize, however, that the weather you see on the display is created in the 3D card. So if you change, for example, from snow to clear, some snow will continue falling to the bottom of the screen.
Adding to Surveyor

When the rule is added in Surveyor, there are several parameters which may be set. Note that multiple regions may be realized by adding additional rules. Any part of the layout not within a region has its own weather (the baseline weather). For this baseline weather, there are no parameters or searches, etc.

This rule also constructs a browser in Driver Mode from which the user may change the weather in any region or the baseline weather.
Setting Parameters

Trackmarks: A weather region is specified by selecting one or more existing trackmarks. Refer to Setting up a region for details.
Check every seconds: Each region is checked for the presence of the vehicle with the focus periodically. This field determines how often this is done. Note that despite this setting, a focus change results in an immediate search. So if you switch from one vehicle to another, you do not have to wait for the search interval to time out. Refer also to Performance Considerations .

Distance from Trackmark: Each Trackmark selected is checked in both directions for the distance specified for the presence of the vehicle with the focus.
Weather Type: This is the weather type for the region. Note that the weather type chosen will not necessarily be the current weather in the region if the changeability is other than "none". Refer also to Weather Changeability.
Weather Changeability: This is the weather changeability for the region. Refer also to Weather Changeability.
Help: The HTM Help file can be read with any HTML browser. The file is in the KUID subdirectory and named helpme.htm. You should be able to locate this file in a folder with the following parameters:
C:\Program Files\Auran\TRS2004\World\dispatcher\downloads\kuid2 121843 900033 1
... you should alter this as necessary to reflect your own path to TRS 2004, if you have install in a folder other than the default installation.

This help file now opens with external browser

Setting up a region
A region is specified using existing Trackmarks. The search for a vehicle with the focus is done with the functions in the Trainz class GSTrackSearch. As stated in the documentation:
The scope of a track search is limited and can only go so far. Therefore if the end of the line is encountered or there is an obstacle like a junction set against the path of the search, then the search will end. A null return value indicates the search can't go any further, so always the returned reference for this.
Therefore, Trackmarks must be placed and selected according to the complexity of the track layout. For simple single track situations such as a mountain pass, a single trackmark and distance should suffice. Complexity such as a yard are probably not suitable for this rule.
Trackmarks will be searched in the order specified in the interface. Trackmark/distance pairs can of course overlap. However, a trackmark should never be used in two different rules, nor should a trackmark/distance pair overlap between rules because thrashing will occur.
To assist in setting up your regions, the Driver browser may be used. Refer to Driver Browser.
As perhaps a curiosity, disjoint regions could be set up from a single rule if the same weather were to be used in each region. For example, if two trackmarks were to chosen in locations remote from each other, there would in essence be two regions, both experiencing the same weather, search distance, search interval, etc.
Search Interval

Each rule sleeps for the period chosen by the user, then does the vehicle check. Setting short intervals will result in more precise performance, but see also Performance Considerations.
Search Distance
The region in each direction from the specified trackmarks will be searched for the distance specified in meters. To assist in setting up your regions, the Driver browser may be used. Refer to Driver Browser.Weather Changeability
When weather changeability is set to other than "none", the weather type does not remain constant as to what the user selected. For example, I ran the following test on my TRS2004 installation for 5 minutes (This functionality is not documented insofar as I am aware, so it may not apply to your version of Trainz).
- When the weather is set to any type 0-4 inclusive, with changeability set to extreme,
- the weather type cycles between 0 and 4. When the weather is set to any type 5-7 (inclusive),
- with changeability set to extreme, the weather type cycles between 5- 7 (inclusive).
Changing the weather
Each region keeps track of its own weather. The weather within a region may change over time due to the changeability setting. This also provides the user with the opportunity to change the weather for a region. If the weather is changed with the Driver Browser while a region is active, this becomes the new weather for this region. It is not necessary to end the session and use Surveyor. The Driver Browser may also be used to change the baseline weather.
Note that this rule does not cooperate well with weather changes applied outside of the Driver Browser. For example, if a rule other than the subject rule changes the weather, such as indented after a trigger rule, the weather will surely change, but for which region? This is because a train can change the weather in this case without having the focus. It is recommended that weather control reside in this rule, or let the user beware.
Performance Considerations
There are numberless hardware and software configurations in the Trainz community. You will have to experiment for yourself as to number of trackmarks, search interval, search distance, and how this affects the performance of your RR operation. For slow moving trains and/or large regions, it should suffice to specify long search intervals.
Driver Browser.
New Weather rule icon brings up driver browser. To hide driver browser, press F5
The Driver Browser is hacked from the Set Driver Conditions Rule. It appears set below the SDCR in the event the user wishes to use both. It can be minimized, and will be if entering Driver mode from Surveyor. Minimized, it will appear as (W) on the left of the screen. The browser provides the capability of changing the regional and baseline weather; refer to Changing the weather.

Additonally, it is an aid in setting up your regions. Appearing are: the Vehicle with the focus
- The trackmark where the focus vehicle was found
- the distance at which the focus vehicle was found.
Note that unless focus changes are involved, the trackmark and distance fields will be updated at the search interval specified.
Driver Browser
The driver browser can change the weather in whatever region is active at the time. You have to have a vehicle with the focus within a region. A region is defined between two trackmarks. They have to be trackmarks that you have specified as a region. You can tell this if a trackmark is shown with a distance. If no regions are active,then you are changing the weather for the "baseline", that is, the entire route.
A few gory details.
Rather than having each instance of the rule message each other, the first instance of the rule instantiates a "Master Controller" as a static class. The first instance of the rule also constructs a browser. Since only one rule instantiated the browser, the rules themselves, except the first one, should not talk directly to the browser, but rather do so through the master controller. The master controller also assigns IDs to each rule object at run time. The operation of this rule is made significantly more complex owing to the system changing the weather type if changeability is not "none". Otherwise, each rule could simply store the initial weather specified in the Surveyor edit browser. Further complication arises from the fact that no message is sent out when the system or any other agent changes the weather. There is also no way that I know of to determine the vehicle with the current focus at any given time, but rather one can only determine this when the focus changes. Hence, this rule really cannot cooperate with other weather change agents such as weather rules or the Set Driver Conditions Rule (when operated in Driver).
Discussion and Support
All supoort and discussion for this weather rule may be found on this Trainz Forum. You must be a registered user of Trainz to particpate.
Conditions of Download
This asset is free software and is distributed as such, but WITHOUT ANY WARRANTY. You may redistribute and/or modify it freely with the following conditions:
- You MUST leave all copyright and licensing information intact and it must accompany any distribution;
- You MAY NOT sell or make money from this asset without the explicit written permission of the author;
- You MAY NOT under any circumstances distribute or otherwise make available this asset to unlicensed users of Auran Trainz(tm) software.
Revisions
- Help- helpme file no longer displayed from the surveyor interface. Now a note appears suggesting that the user open the helpme.htm file with a browser. The trainz browser is not capable of displaying the helpme file adequately.
- Text- The text for the help note is now in red.
- Icon - added for the rule as it appears in surveyor.
- Description:- the description in surveyor is corrected to refer to regions instead of triggers
- Driver Browser - the browser in driver will show the first trackmark of interest according to the order trackmarks are entered in surveyor.
- Distance to next trackmark in Driver Browser- the distance in the driver browser is now displayed as in integer
Download
Download Regional Weather Rule (CDP file)(Beta 1, Build 2)
Download Regional Weather Rule (Zip file) (Beta 1, Build 2)
Regional Weather Rule © Paul Austgen, 2006