===== MT =====

MT is the working name for a new capability in JAS that allow users to change the onHand and/or authorized amounts of Bse assets. These changes can be made absolutely or relatively, and can occur at specific sim times or be triggered by knowledge base changes.

==== Data ====


Currently MT data is read from a csv file. The location of this file is specified by the MtData setting under the System heading in the jasS.ini file. The name of this file is user-specified. Future development will include a gui.

<code>
; File:     jasS.ini
; Title:    Settings file for JAS Simulation System
 
[System]
ErrorLogFile=simError.log
MtData=C:\Documents and Settings\DefaultUser\My Documents\JAS\resourceChanges.csv
</code>

There are 11 data fields in the input file:

  - side - the **string** US-JTF or OPFOR. Required.
  - time - integer or float. Empty means nil.
  - factValue - the value passed by the knowledge base action Process MT. Empty means nil.
  - bseId - a **string** specifying the name of the bse whose resourceAccount will be changed. Required.
  - appliesToSubordinates - one of I(mmediate), A(ll), or (N)one. Required.
  - assetName - the **string** name of the asset to be changed. Required.
  - onHandChangeType - Absolute or Relative. Only the first character is considered. Not case-sensitive. Empty means nil.
  - onHandChangeAmount - integer or float. Empty means nil.
  - authorizedChangeType- Absolute or Relative. Only the first character is considered. Not case-sensitive. Empty means nil.
  - authorizedChangeAmount - integer or float. Empty means nil.
  - comments - optional

==== Data Editing ====
  * Time cannot be negative.
  * Time or factValue is required. 
  * A line with both time and factValue is an error. 
  * The bse specified by bseId must exist in scenario data and be playing. It does not have to be active.
  * The asset specified by assetName must exist in scenario data. It does not have to be in the specified bse's resource account. 
  * One of onHandChangeType or authorizedChangeType is required to be absolute ('A') or relative ('r'). Both is ok.
  * Both onHandChangeAmount or authorizedChangeAmount cannot be empty.
  * If either onHandChangeType or authorizedChangeType is absolute ('A'), the respective changeAmount must not be negative. Only relative ('R') changes can be negative

==== MT Activation ====
The MT data file is read during sim initialization. Each line in the file is checked for errors, the results are logged to the Jas message log, and each line that passes edit checks is stored in the scenario data as a JwResourceChange object. 
JwResourceChange objects can be activated in two different ways:
  * by time
  * by the knowledge base

=== Time Activation ===

Once the simulation is through with initialization, it asks each object in the scenario if there is anything it wants to do before the sim starts playing by sending the message simulationIsAboutToStart. When the JtfC2 object for each side receives this message, it selects all the JwResourceChanges that belong to its side that have an explicit time value. These JwResourceChanges are scheduled for execution at the time specified if the bse is still alive (not dead and not dissolved).

=== Knowledge Base Activation ===
JwResourceChanges that have a factValue rather than an explicit time are scheduled for immediate execution if the fact that references them turns true in the knowledge base, and the bse is still alive (not dead and not dissolved).

==== MT Execution ====
=== On Hand Amount Changes ===
== Absolute Amount Changes ==
There are two possibilities when the onHandChangeType is absolute ('A')-- the bse does or does not have the asset.    
  - if the bse does have the asset, the onHand amount of the existing asset is changed to the JwResourceChange onHandChangeAmount absolutely.
  - if the bse does not have the asset, a new asset is created with both the onHand and authorized amounts set to the JwResourceChange onHandChangeAmount.
 
== Relative Amount Changes ==
Relative amount changes are only applied to existing assets and in no case will the resulting onHand amount be negative. 
^ OnHand Before      ^ Relative Change       ^ OnHand After           ^
| 100    | 12     | 112        |
| 100    | -12| 88 |
| 100    | -112     | 0        |
=== Authorized Amount Changes ===
== Absolute Amount Changes ==
There are two possibilities when the authorizedChangeType is absolute ('A')-- the bse does or does not have the asset.    
  - if the bse does have the asset, the authorized amount of the existing asset is changed to the JwResourceChange authorizedChangeAmount absolutely.
  - if the bse does not have the asset, a new asset is created with the authorized amount set to the JwResourceChange authorizedChangeAmount and the onHand amount set to zero.
== Relative Amount Changes ==
Relative amount changes are only applied to existing assets and in no case will the resulting authorized amount be negative. 
^ Authorized Before      ^ Relative Change       ^ Authorized After           ^
| 100    | 12     | 112        |
| 100    | -12| 88 |
| 100    | -112     | 0        |
== Applying Changes to Subordinates ==
Resource changes to a bse can be applied to A(ll) of a bse's subordinates, N)one of them, or to just the bse's I(mmediate) subordinates.
^ Value of appliesToSubordinates      ^ Change       ^  
| N| Bse only     | 
| I| Bse and **immediate** subordinates only | 
| A| Bse and **all** subordinates     |  

==== Knowledge Base ====
To trigger resource changes from the knowledge base, first set up a fact that will eventually evaluate to true. This fact should logically be put on the JtfC2 knowledge base for the appropriate side. This example uses a ScheduledEvent that goes true at time = 4.0.
On the ScheduledEvent, select Process MT as the action.
{{:wiki:mtprocessmt.jpg|}}

Then enter a value in the Requested MT Value field that corresponds to the factValue of the JwResourceChanges that you want to execute on this fact.

{{:wiki:mtdialog.jpg|}}

The completed ScheduledEvent looks like this:
{{:wiki:mtkb.jpg|}}

==== Instrumentation and Logging ====
There is currently no specific MT instrumentation. The results of changes to onHand amounts can be seen in the Resource Accounting instrument.
You can see the results of MT processing in the JAS message log by turning on the MTDebug message category. 

{{:wiki:mtmsgcat.jpg|}}

==== To Do ====  
  * Gui
  * Instrumentation

==== Alternate Names ====


  * REC - Resource Explicit Change
  * MAJIC - Manual Adjustment of Jas Inventory Contents
