Rule Resolution

Rule resolution is a search algorithm used to find the most appropriate instance of a rule to assemble during product build. Rule resolution occurs whenever a rule is needed to accomplish processing of a flow or a state machine.

Rule resolution applies to rules that are used to create game logic:

  • Message
  • Monobehaviour Flow
  • Animation Flow
  • State Machine
  • Logic
  • When
  • Property

Rule resolution does not apply to other rule types:

  • Application
  • Class
  • Ruleset
  • Library
  • Product

Rule resolution steps

Rule Resolution is the mechanism used to determine the most appropriate rule to assemble for script generation.

_images/ruleresolutionflow.png

During rule assembly, when a rule is referenced, rule resolution attempts to locate instances of the rule. The point of the rule resolution is to return the most appropriate rule to satisfy the need.

All rule resolution starts from the primary class. The primary class is the class specified in the product flow list and state machine list. When checking a preview of the generated C#, the primary class is the class of the rule itself. That means that code generated for the C# preview can differ from the actual generated script if the primary class is different.

_images/ruleresolutionprimaryclass.png

The key inputs to the rule resolution algorithm are the:

  • Key parts of a rule, such as the class, rule name, and rule type
  • Class hierarchy calculated for the primary class
  • Application ruleset list and version
  • Availability of the rule (Draft, Available, Withdrawn)

During rule asembly, the rule resolution mechanism retrieves from the database all rules of selected type (e.g. Flow) with rule name (e.g. TankHealth) where ruleset is in application ruleset list and class in hierarchy class list.

Then rules are ordered by:

  1. Class (following primary class hierarchy)
  2. Ruleset (following ordered ruleset list in application)
  3. Version

Then rule availability is checked:

  • Draft: the rule is discarded
  • Withdrawn: discard the rule itself and all rules from same class and same ruleset with smaller version
  • Available: keep the rule for rule resolution

Once all these steps are done, the best rule instance is identified and assembled to generate C#.

For each rule, name, class and availability are visible from the rule header form:

_images/ruleresolutionheaderform.png

Rule resolution examples

We want to assemble the flow TankHealth from primary class Tanks-Tank-Panzer. Rule assembly will first execute rule resolution for flow TankHealth.

The class hierarchy for Tanks-Tank-Panzer is:

  • Tanks-Tank-Panzer
  • Tanks-Tank
  • Tanks
  • Core

The ruleset list of Tanks application is:

  • Tanks
  • GameRulesCore

For this first example, we get:

Example 1
Class Rule type Rule name Availability Ruleset Version
Tanks-Tank Flow TankHealth Available Tanks 1
Core Flow TankHealth Available GameRulesCore 2

Hint

First row is chosen as the class Tanks-Tank is higher than Core in class hierarchy.

For this second example, we get:

Example 2
Class Rule type Rule name Availability Ruleset Version
Tanks-Tank Flow TankHealth Available Tanks 2
Tanks-Tank Flow TankHealth Available Tanks 1
Core Flow TankHealth Available GameRulesCore 2

Hint

Inside class Tanks-Tank, TankHealth has been saved in a higher ruleset version.

For this third example, we get:

Example 3
Class Rule type Rule name Availability Ruleset Version
Tanks-Tank Flow TankHealth Withdrawn Tanks 3
Tanks-Tank Flow TankHealth Available Tanks 2
Tanks-Tank Flow TankHealth Available Tanks 1
Core Flow TankHealth Available GameRulesCore 2

Hint

As TankHealth is withdrawn in version 3, it invalidates all rules from Tanks-Tank with ruleset Tanks in version 1 and 2. So TankHealth from Core class is used.

Important

Then for each consecutive rules called (logic, when, property, message), the same rule resolution mechanism is executed, keeping same class hierarchy from the primary class and same ruleset list.

Siblings

To help developers to figure out which other rules with same name and type exist in the application, potentially in different class, ruleset and version, the view siblings window from Actions menu shall be used.

_images/ruleresolutionsiblingsmenu.png

_images/ruleresolutionsiblingswindow.png