﻿# Leo VI's Mass Vassal Directives - the rule engine
#
# A rule set is an ordered list of priorities. Each priority is a small tree of
# nodes; the first priority that assigns a directive wins, and a vassal that no
# priority claims is left without one.
#
# A node is one of three kinds:
#   0  continue  - do nothing; fall through to the next priority (the default)
#   1  directive - assign this directive, if the vassal passes vanilla's gate
#   2  condition - test a condition and descend into the matching branch
#
# Nodes are heap-addressed within a priority: n1 is the root, n2/n3 are its
# branches, and n4..n7 are the grandchildren. n4..n7 are leaves and can only be
# "continue" or "directive". That depth cap is deliberate: the script language
# forbids a scripted effect from calling itself, so the walk cannot recurse and
# each level is instead written out as its own effect below.
#
# Rules live in variables on the player: leo_mvd_r<P>_n<N>_{kind,dir,cond,thresh}
# for priorities 1..6. leo_mvd_rule_count is how many of them are in use.
#
# Two things script cannot do shape the rest of this file: a variable name
# cannot be composed at runtime, and a condition cannot be chosen at runtime.
# So node access is macro-expanded with literal names ($NODE$), while the
# per-directive and per-condition chains - which would otherwise be duplicated
# into every node - are written once and driven by a value staged into a
# temporary scope.

### Staging.

# Current scope: vassal. Stages $NODE$'s directive for leo_mvd_try_assign_effect.
leo_mvd_stage_dir_effect = {
	save_temporary_scope_value_as = {
		name = leo_mvd_dir_id
		value = scope:leo_mvd_liege.var:leo_mvd_$NODE$_dir
	}
}

# Current scope: vassal. Stages $NODE$'s condition for leo_mvd_cond_holds_trigger.
leo_mvd_stage_cond_effect = {
	save_temporary_scope_value_as = {
		name = leo_mvd_cond_id
		value = scope:leo_mvd_liege.var:leo_mvd_$NODE$_cond
	}
	save_temporary_scope_value_as = {
		name = leo_mvd_thresh
		value = scope:leo_mvd_liege.var:leo_mvd_$NODE$_thresh
	}
}

### Assignment.

# Current scope: vassal. Requires scope:leo_mvd_dir_id (staged above).
# Assigns the staged directive if the vassal passes vanilla's gate for it, and
# does nothing at all otherwise - so an ineligible vassal simply falls through
# to the next priority, exactly as vanilla hides an unavailable send_option.
#
# The leo_mvd_hit guard is what stops later priorities from overwriting an
# earlier one's assignment; leo_mvd_assign_effect sets it.
leo_mvd_try_assign_effect = {
	if = {
		limit = { NOT = { has_variable = leo_mvd_hit } }

		if = {
			limit = {
				scope:leo_mvd_dir_id = 1
				leo_mvd_gate_convert_faith_trigger = yes
			}
			leo_mvd_assign_effect = { DIRECTIVE = convert_faith CODE = 1 }
		}
		else_if = {
			limit = {
				scope:leo_mvd_dir_id = 2
				leo_mvd_gate_convert_culture_trigger = yes
			}
			leo_mvd_assign_effect = { DIRECTIVE = convert_culture CODE = 2 }
		}
		else_if = {
			limit = {
				scope:leo_mvd_dir_id = 3
				leo_mvd_gate_improve_development_trigger = yes
			}
			leo_mvd_assign_effect = { DIRECTIVE = improve_development CODE = 3 }
		}
		else_if = {
			limit = {
				scope:leo_mvd_dir_id = 4
				leo_mvd_gate_train_commanders_trigger = yes
			}
			leo_mvd_assign_effect = { DIRECTIVE = train_commanders CODE = 4 }
		}
		else_if = {
			limit = {
				scope:leo_mvd_dir_id = 5
				leo_mvd_gate_build_maa_trigger = yes
			}
			leo_mvd_assign_effect = { DIRECTIVE = build_maa CODE = 5 }
		}
		else_if = {
			limit = {
				scope:leo_mvd_dir_id = 6
				leo_mvd_gate_improve_cultural_acceptance_trigger = yes
			}
			leo_mvd_assign_effect = { DIRECTIVE = improve_cultural_acceptance CODE = 6 }
		}
		else_if = {
			limit = {
				scope:leo_mvd_dir_id = 7
				leo_mvd_gate_building_focus_trigger = yes
			}
			leo_mvd_assign_effect = { DIRECTIVE = building_focus_fortification CODE = 7 }
		}
		else_if = {
			limit = {
				scope:leo_mvd_dir_id = 8
				leo_mvd_gate_building_focus_trigger = yes
			}
			leo_mvd_assign_effect = { DIRECTIVE = building_focus_military CODE = 8 }
		}
		else_if = {
			limit = {
				scope:leo_mvd_dir_id = 9
				leo_mvd_gate_building_focus_trigger = yes
			}
			leo_mvd_assign_effect = { DIRECTIVE = building_focus_economy CODE = 9 }
		}
		else_if = {
			limit = {
				scope:leo_mvd_dir_id = 10
				leo_mvd_gate_manage_fertility_trigger = yes
			}
			leo_mvd_assign_effect = { DIRECTIVE = manage_fertility CODE = 10 }
		}
		else_if = {
			limit = {
				scope:leo_mvd_dir_id = 11
				leo_mvd_gate_explore_cultures_trigger = yes
			}
			leo_mvd_assign_effect = { DIRECTIVE = explore_cultures CODE = 11 }
		}
		else_if = {
			limit = {
				scope:leo_mvd_dir_id = 12
				leo_mvd_gate_raid_innovation_intent_trigger = yes
			}
			leo_mvd_assign_effect = { DIRECTIVE = raid_innovation_intent CODE = 12 }
		}
		else_if = {
			limit = {
				scope:leo_mvd_dir_id = 13
				leo_mvd_gate_raid_herd_intent_trigger = yes
			}
			leo_mvd_assign_effect = { DIRECTIVE = raid_herd_intent CODE = 13 }
		}
	}
}

### The walk.
#
# One effect per tree level. These are near-identical by necessity: a scripted
# effect cannot call itself, so the recursion is unrolled by hand instead.

# Current scope: vassal. A leaf: continue, or assign a directive.
leo_mvd_eval_leaf_effect = {
	if = {
		limit = {
			scope:leo_mvd_liege = { var:leo_mvd_$NODE$_kind = 1 }
		}
		leo_mvd_stage_dir_effect = { NODE = $NODE$ }
		leo_mvd_try_assign_effect = yes
	}
}

# Current scope: vassal. A mid node: its branches must be leaves.
leo_mvd_eval_mid_effect = {
	if = {
		limit = {
			scope:leo_mvd_liege = { var:leo_mvd_$NODE$_kind = 2 }
		}
		leo_mvd_stage_cond_effect = { NODE = $NODE$ }
		if = {
			limit = { leo_mvd_cond_holds_trigger = yes }
			leo_mvd_eval_leaf_effect = { NODE = $LEFT$ }
		}
		else = {
			leo_mvd_eval_leaf_effect = { NODE = $RIGHT$ }
		}
	}
	else_if = {
		limit = {
			scope:leo_mvd_liege = { var:leo_mvd_$NODE$_kind = 1 }
		}
		leo_mvd_stage_dir_effect = { NODE = $NODE$ }
		leo_mvd_try_assign_effect = yes
	}
}

# Current scope: vassal. A priority's root node; its branches may be conditions.
leo_mvd_eval_root_effect = {
	if = {
		limit = {
			scope:leo_mvd_liege = { var:leo_mvd_$NODE$_kind = 2 }
		}
		leo_mvd_stage_cond_effect = { NODE = $NODE$ }
		if = {
			limit = { leo_mvd_cond_holds_trigger = yes }
			leo_mvd_eval_mid_effect = { NODE = $LEFT$ LEFT = $LL$ RIGHT = $LR$ }
		}
		else = {
			leo_mvd_eval_mid_effect = { NODE = $RIGHT$ LEFT = $RL$ RIGHT = $RR$ }
		}
	}
	else_if = {
		limit = {
			scope:leo_mvd_liege = { var:leo_mvd_$NODE$_kind = 1 }
		}
		leo_mvd_stage_dir_effect = { NODE = $NODE$ }
		leo_mvd_try_assign_effect = yes
	}
}

# Current scope: vassal. Evaluates priority $P$, the $N$th of the rule set whose
# length is $COUNT$. Priorities beyond that are skipped, so the unused slots a
# rule set does not fill cost nothing.
leo_mvd_eval_priority_effect = {
	if = {
		limit = {
			scope:leo_mvd_liege = { var:$COUNT$ >= $N$ }
		}
		leo_mvd_eval_root_effect = {
			NODE = $P$_n1
			LEFT = $P$_n2
			RIGHT = $P$_n3
			LL = $P$_n4
			LR = $P$_n5
			RL = $P$_n6
			RR = $P$_n7
		}
	}
}

### Editing.
#
# The panel cannot hand script a number, so "set node N's directive to D" cannot
# be one call. Instead a radio click runs two scripted GUIs in order: the first
# points leo_mvd_edit_node at the node, the second stages a field and value and
# calls the dispatch below. That makes the cost of the editor one scripted GUI
# per node plus one per option, rather than one per node-and-option pair.
#
# leo_mvd_edit_node addresses a node as priority * 10 + node, so r1_n1 is 11 and
# r6_n7 is 67.

# Current scope: the player. Writes the staged field to $NODE$.
leo_mvd_write_node_effect = {
	if = {
		limit = { var:leo_mvd_stage_field = 1 }
		set_variable = { name = leo_mvd_$NODE$_kind value = var:leo_mvd_stage_value }
	}
	else_if = {
		limit = { var:leo_mvd_stage_field = 2 }
		set_variable = { name = leo_mvd_$NODE$_cond value = var:leo_mvd_stage_value }
	}
	else_if = {
		limit = { var:leo_mvd_stage_field = 3 }
		set_variable = { name = leo_mvd_$NODE$_thresh value = var:leo_mvd_stage_value }
	}
	else_if = {
		limit = { var:leo_mvd_stage_field = 4 }
		set_variable = { name = leo_mvd_$NODE$_dir value = var:leo_mvd_stage_value }
	}
}

# Current scope: the player. Routes the staged write to whichever node the
# cursor points at. Written out in full because a variable name cannot be built
# from a value at runtime.
leo_mvd_write_field_effect = {
	if = { limit = { var:leo_mvd_edit_node = 11 } leo_mvd_write_node_effect = { NODE = r1_n1 } }
	else_if = { limit = { var:leo_mvd_edit_node = 12 } leo_mvd_write_node_effect = { NODE = r1_n2 } }
	else_if = { limit = { var:leo_mvd_edit_node = 13 } leo_mvd_write_node_effect = { NODE = r1_n3 } }
	else_if = { limit = { var:leo_mvd_edit_node = 14 } leo_mvd_write_node_effect = { NODE = r1_n4 } }
	else_if = { limit = { var:leo_mvd_edit_node = 15 } leo_mvd_write_node_effect = { NODE = r1_n5 } }
	else_if = { limit = { var:leo_mvd_edit_node = 16 } leo_mvd_write_node_effect = { NODE = r1_n6 } }
	else_if = { limit = { var:leo_mvd_edit_node = 17 } leo_mvd_write_node_effect = { NODE = r1_n7 } }
	else_if = { limit = { var:leo_mvd_edit_node = 21 } leo_mvd_write_node_effect = { NODE = r2_n1 } }
	else_if = { limit = { var:leo_mvd_edit_node = 22 } leo_mvd_write_node_effect = { NODE = r2_n2 } }
	else_if = { limit = { var:leo_mvd_edit_node = 23 } leo_mvd_write_node_effect = { NODE = r2_n3 } }
	else_if = { limit = { var:leo_mvd_edit_node = 24 } leo_mvd_write_node_effect = { NODE = r2_n4 } }
	else_if = { limit = { var:leo_mvd_edit_node = 25 } leo_mvd_write_node_effect = { NODE = r2_n5 } }
	else_if = { limit = { var:leo_mvd_edit_node = 26 } leo_mvd_write_node_effect = { NODE = r2_n6 } }
	else_if = { limit = { var:leo_mvd_edit_node = 27 } leo_mvd_write_node_effect = { NODE = r2_n7 } }
	else_if = { limit = { var:leo_mvd_edit_node = 31 } leo_mvd_write_node_effect = { NODE = r3_n1 } }
	else_if = { limit = { var:leo_mvd_edit_node = 32 } leo_mvd_write_node_effect = { NODE = r3_n2 } }
	else_if = { limit = { var:leo_mvd_edit_node = 33 } leo_mvd_write_node_effect = { NODE = r3_n3 } }
	else_if = { limit = { var:leo_mvd_edit_node = 34 } leo_mvd_write_node_effect = { NODE = r3_n4 } }
	else_if = { limit = { var:leo_mvd_edit_node = 35 } leo_mvd_write_node_effect = { NODE = r3_n5 } }
	else_if = { limit = { var:leo_mvd_edit_node = 36 } leo_mvd_write_node_effect = { NODE = r3_n6 } }
	else_if = { limit = { var:leo_mvd_edit_node = 37 } leo_mvd_write_node_effect = { NODE = r3_n7 } }
	else_if = { limit = { var:leo_mvd_edit_node = 41 } leo_mvd_write_node_effect = { NODE = r4_n1 } }
	else_if = { limit = { var:leo_mvd_edit_node = 42 } leo_mvd_write_node_effect = { NODE = r4_n2 } }
	else_if = { limit = { var:leo_mvd_edit_node = 43 } leo_mvd_write_node_effect = { NODE = r4_n3 } }
	else_if = { limit = { var:leo_mvd_edit_node = 44 } leo_mvd_write_node_effect = { NODE = r4_n4 } }
	else_if = { limit = { var:leo_mvd_edit_node = 45 } leo_mvd_write_node_effect = { NODE = r4_n5 } }
	else_if = { limit = { var:leo_mvd_edit_node = 46 } leo_mvd_write_node_effect = { NODE = r4_n6 } }
	else_if = { limit = { var:leo_mvd_edit_node = 47 } leo_mvd_write_node_effect = { NODE = r4_n7 } }
	else_if = { limit = { var:leo_mvd_edit_node = 51 } leo_mvd_write_node_effect = { NODE = r5_n1 } }
	else_if = { limit = { var:leo_mvd_edit_node = 52 } leo_mvd_write_node_effect = { NODE = r5_n2 } }
	else_if = { limit = { var:leo_mvd_edit_node = 53 } leo_mvd_write_node_effect = { NODE = r5_n3 } }
	else_if = { limit = { var:leo_mvd_edit_node = 54 } leo_mvd_write_node_effect = { NODE = r5_n4 } }
	else_if = { limit = { var:leo_mvd_edit_node = 55 } leo_mvd_write_node_effect = { NODE = r5_n5 } }
	else_if = { limit = { var:leo_mvd_edit_node = 56 } leo_mvd_write_node_effect = { NODE = r5_n6 } }
	else_if = { limit = { var:leo_mvd_edit_node = 57 } leo_mvd_write_node_effect = { NODE = r5_n7 } }
	else_if = { limit = { var:leo_mvd_edit_node = 61 } leo_mvd_write_node_effect = { NODE = r6_n1 } }
	else_if = { limit = { var:leo_mvd_edit_node = 62 } leo_mvd_write_node_effect = { NODE = r6_n2 } }
	else_if = { limit = { var:leo_mvd_edit_node = 63 } leo_mvd_write_node_effect = { NODE = r6_n3 } }
	else_if = { limit = { var:leo_mvd_edit_node = 64 } leo_mvd_write_node_effect = { NODE = r6_n4 } }
	else_if = { limit = { var:leo_mvd_edit_node = 65 } leo_mvd_write_node_effect = { NODE = r6_n5 } }
	else_if = { limit = { var:leo_mvd_edit_node = 66 } leo_mvd_write_node_effect = { NODE = r6_n6 } }
	else_if = { limit = { var:leo_mvd_edit_node = 67 } leo_mvd_write_node_effect = { NODE = r6_n7 } }
	else_if = { limit = { var:leo_mvd_edit_node = 111 } leo_mvd_write_node_effect = { NODE = q1_n1 } }
	else_if = { limit = { var:leo_mvd_edit_node = 112 } leo_mvd_write_node_effect = { NODE = q1_n2 } }
	else_if = { limit = { var:leo_mvd_edit_node = 113 } leo_mvd_write_node_effect = { NODE = q1_n3 } }
	else_if = { limit = { var:leo_mvd_edit_node = 114 } leo_mvd_write_node_effect = { NODE = q1_n4 } }
	else_if = { limit = { var:leo_mvd_edit_node = 115 } leo_mvd_write_node_effect = { NODE = q1_n5 } }
	else_if = { limit = { var:leo_mvd_edit_node = 116 } leo_mvd_write_node_effect = { NODE = q1_n6 } }
	else_if = { limit = { var:leo_mvd_edit_node = 117 } leo_mvd_write_node_effect = { NODE = q1_n7 } }
	else_if = { limit = { var:leo_mvd_edit_node = 121 } leo_mvd_write_node_effect = { NODE = q2_n1 } }
	else_if = { limit = { var:leo_mvd_edit_node = 122 } leo_mvd_write_node_effect = { NODE = q2_n2 } }
	else_if = { limit = { var:leo_mvd_edit_node = 123 } leo_mvd_write_node_effect = { NODE = q2_n3 } }
	else_if = { limit = { var:leo_mvd_edit_node = 124 } leo_mvd_write_node_effect = { NODE = q2_n4 } }
	else_if = { limit = { var:leo_mvd_edit_node = 125 } leo_mvd_write_node_effect = { NODE = q2_n5 } }
	else_if = { limit = { var:leo_mvd_edit_node = 126 } leo_mvd_write_node_effect = { NODE = q2_n6 } }
	else_if = { limit = { var:leo_mvd_edit_node = 127 } leo_mvd_write_node_effect = { NODE = q2_n7 } }
	else_if = { limit = { var:leo_mvd_edit_node = 131 } leo_mvd_write_node_effect = { NODE = q3_n1 } }
	else_if = { limit = { var:leo_mvd_edit_node = 132 } leo_mvd_write_node_effect = { NODE = q3_n2 } }
	else_if = { limit = { var:leo_mvd_edit_node = 133 } leo_mvd_write_node_effect = { NODE = q3_n3 } }
	else_if = { limit = { var:leo_mvd_edit_node = 134 } leo_mvd_write_node_effect = { NODE = q3_n4 } }
	else_if = { limit = { var:leo_mvd_edit_node = 135 } leo_mvd_write_node_effect = { NODE = q3_n5 } }
	else_if = { limit = { var:leo_mvd_edit_node = 136 } leo_mvd_write_node_effect = { NODE = q3_n6 } }
	else_if = { limit = { var:leo_mvd_edit_node = 137 } leo_mvd_write_node_effect = { NODE = q3_n7 } }
}

# Current scope: the player. Point the cursor at $NODE$.
leo_mvd_focus_effect = {
	set_variable = { name = leo_mvd_edit_node value = $CODE$ }
}

# Current scope: the player. Stage field $FIELD$ = $VALUE$ and write it to the
# focused node.
#
# Changing anything makes the rules the player's own, whatever preset they came
# from. That is what lets a preset be a starting point: tweak one of its rules
# and you keep the rest of it, rather than building the whole waterfall again to
# change one directive. A built-in cannot be edited in place because it would no
# longer be the preset it still claimed to be.
leo_mvd_edit_effect = {
	set_variable = { name = leo_mvd_stage_field value = $FIELD$ }
	set_variable = { name = leo_mvd_stage_value value = $VALUE$ }
	leo_mvd_write_field_effect = yes
	leo_mvd_after_edit_effect = yes
}

### Rule authoring.
#
# Used to build the rule sets below, and by the panel's editor.

# Current scope: the player. Reset one node to "continue to next priority".
leo_mvd_clear_node_effect = {
	set_variable = { name = leo_mvd_$NODE$_kind value = 0 }
	set_variable = { name = leo_mvd_$NODE$_dir value = 0 }
	set_variable = { name = leo_mvd_$NODE$_cond value = 0 }
	set_variable = { name = leo_mvd_$NODE$_thresh value = 0 }
}

# Current scope: the player. Reset every node of priority $P$.
leo_mvd_clear_priority_effect = {
	leo_mvd_clear_node_effect = { NODE = $P$_n1 }
	leo_mvd_clear_node_effect = { NODE = $P$_n2 }
	leo_mvd_clear_node_effect = { NODE = $P$_n3 }
	leo_mvd_clear_node_effect = { NODE = $P$_n4 }
	leo_mvd_clear_node_effect = { NODE = $P$_n5 }
	leo_mvd_clear_node_effect = { NODE = $P$_n6 }
	leo_mvd_clear_node_effect = { NODE = $P$_n7 }
}

# Current scope: the player. Reset the whole main rule set to empty. Also the
# one place that guarantees every rule variable exists, which the panel relies
# on: it reads them straight from GUI, where an undefined variable has no
# defined reading.
#
# rule_count 0 means there are no priorities at all, so the waterfall assigns
# nothing and merely cleans up after itself.
leo_mvd_clear_rules_effect = {
	leo_mvd_clear_priority_effect = { P = r1 }
	leo_mvd_clear_priority_effect = { P = r2 }
	leo_mvd_clear_priority_effect = { P = r3 }
	leo_mvd_clear_priority_effect = { P = r4 }
	leo_mvd_clear_priority_effect = { P = r5 }
	leo_mvd_clear_priority_effect = { P = r6 }
	set_variable = { name = leo_mvd_rule_count value = 0 }
	leo_mvd_clear_priority_effect = { P = q1 }
	leo_mvd_clear_priority_effect = { P = q2 }
	leo_mvd_clear_priority_effect = { P = q3 }
	set_variable = { name = leo_mvd_qrule_count value = 0 }
}

# Current scope: the player. Make $NODE$ assign directive $DIR$.
leo_mvd_set_node_dir_effect = {
	set_variable = { name = leo_mvd_$NODE$_kind value = 1 }
	set_variable = { name = leo_mvd_$NODE$_dir value = $DIR$ }
}

# Current scope: the player. Make $NODE$ test condition $COND$ against $THRESH$
# ($THRESH$ is ignored by the boolean conditions; pass 0).
leo_mvd_set_node_cond_effect = {
	set_variable = { name = leo_mvd_$NODE$_kind value = 2 }
	set_variable = { name = leo_mvd_$NODE$_cond value = $COND$ }
	set_variable = { name = leo_mvd_$NODE$_thresh value = $THRESH$ }
}

# Current scope: the player. A priority the player has yet to fill in: one node,
# ready to assign a directive, with no directive chosen. An unset directive
# matches nothing, so it stays inert until it is picked.
leo_mvd_init_priority_effect = {
	leo_mvd_clear_priority_effect = { P = $P$ }
	leo_mvd_set_node_dir_effect = { NODE = $P$_n1 DIR = 0 }
}

# Current scope: the player. Copy one node onto another, on the same character.
leo_mvd_copy_node_between_effect = {
	set_variable = { name = leo_mvd_$TO$_kind value = var:leo_mvd_$FROM$_kind }
	set_variable = { name = leo_mvd_$TO$_dir value = var:leo_mvd_$FROM$_dir }
	set_variable = { name = leo_mvd_$TO$_cond value = var:leo_mvd_$FROM$_cond }
	set_variable = { name = leo_mvd_$TO$_thresh value = var:leo_mvd_$FROM$_thresh }
}

# Current scope: the player. Copy a whole priority onto another.
leo_mvd_copy_priority_between_effect = {
	leo_mvd_copy_node_between_effect = { FROM = $FROM$_n1 TO = $TO$_n1 }
	leo_mvd_copy_node_between_effect = { FROM = $FROM$_n2 TO = $TO$_n2 }
	leo_mvd_copy_node_between_effect = { FROM = $FROM$_n3 TO = $TO$_n3 }
	leo_mvd_copy_node_between_effect = { FROM = $FROM$_n4 TO = $TO$_n4 }
	leo_mvd_copy_node_between_effect = { FROM = $FROM$_n5 TO = $TO$_n5 }
	leo_mvd_copy_node_between_effect = { FROM = $FROM$_n6 TO = $TO$_n6 }
	leo_mvd_copy_node_between_effect = { FROM = $FROM$_n7 TO = $TO$_n7 }
}

### The Custom slot.
#
# There is one live rule set, and selecting a preset overwrites it - so the
# player's own rules are kept aside in a parallel set while a built-in is
# loaded, and handed back when they return to Custom. Without this, trying a
# preset would cost you your own waterfall.

# Current scope: the player. Set the live rules aside as the player's own.
leo_mvd_backup_custom_effect = {
	leo_mvd_copy_priority_between_effect = { FROM = r1 TO = cr1 }
	leo_mvd_copy_priority_between_effect = { FROM = r2 TO = cr2 }
	leo_mvd_copy_priority_between_effect = { FROM = r3 TO = cr3 }
	leo_mvd_copy_priority_between_effect = { FROM = r4 TO = cr4 }
	leo_mvd_copy_priority_between_effect = { FROM = r5 TO = cr5 }
	leo_mvd_copy_priority_between_effect = { FROM = r6 TO = cr6 }
	set_variable = { name = leo_mvd_crule_count value = var:leo_mvd_rule_count }
	leo_mvd_copy_priority_between_effect = { FROM = q1 TO = cq1 }
	leo_mvd_copy_priority_between_effect = { FROM = q2 TO = cq2 }
	leo_mvd_copy_priority_between_effect = { FROM = q3 TO = cq3 }
	set_variable = { name = leo_mvd_cqrule_count value = var:leo_mvd_qrule_count }
	set_variable = leo_mvd_has_custom
}

# Current scope: the player. Put the player's own rules back.
# Only ever called when leo_mvd_has_custom says there are some.
leo_mvd_restore_custom_effect = {
	leo_mvd_copy_priority_between_effect = { FROM = cr1 TO = r1 }
	leo_mvd_copy_priority_between_effect = { FROM = cr2 TO = r2 }
	leo_mvd_copy_priority_between_effect = { FROM = cr3 TO = r3 }
	leo_mvd_copy_priority_between_effect = { FROM = cr4 TO = r4 }
	leo_mvd_copy_priority_between_effect = { FROM = cr5 TO = r5 }
	leo_mvd_copy_priority_between_effect = { FROM = cr6 TO = r6 }
	set_variable = { name = leo_mvd_rule_count value = var:leo_mvd_crule_count }
	leo_mvd_copy_priority_between_effect = { FROM = cq1 TO = q1 }
	leo_mvd_copy_priority_between_effect = { FROM = cq2 TO = q2 }
	leo_mvd_copy_priority_between_effect = { FROM = cq3 TO = q3 }
	set_variable = { name = leo_mvd_qrule_count value = var:leo_mvd_cqrule_count }
}

### Built-in rule sets.
#
# Built-ins are rule data, not hardcoded logic: each one loads a rule set that
# the engine then evaluates by the same path as a hand-built one. So there is a
# single implementation of the waterfall, and "Convert and Develop" reproducing
# the mod's original behavior doubles as the engine's regression test.
#
# Selecting one overwrites the rule set. leo_mvd_preset records which is loaded:
# 0 none, 1-4 built-in, 5 the player's own rules.

# Current scope: the player.
# No rules at all, and the default for a player who has not chosen yet. The mod
# assigns nothing until a preset is picked; the waterfall still runs when
# automation is on, but with no priorities it only clears directives the mod
# assigned earlier, leaving manual ones alone.
leo_mvd_preset_0_effect = {
	leo_mvd_clear_rules_effect = yes
	set_variable = { name = leo_mvd_preset value = 0 }
}

# Current scope: the player.
# Steer vassals onto your faith, then your culture, then grow them: strong
# vassals develop their land, weaker ones raise men-at-arms where they can and
# build up their economy where they cannot.
leo_mvd_preset_1_effect = {
	leo_mvd_clear_rules_effect = yes

	# 1: Faith is Yours -> Convert Faith. Vanilla's gate only asks whether a
	# vassal holds an off-faith county, not whose faith they hold, so without
	# this condition an off-faith vassal would be told to spread their own.
	leo_mvd_set_node_cond_effect = { NODE = r1_n1 COND = 1 THRESH = 0 }
	leo_mvd_set_node_dir_effect = { NODE = r1_n2 DIR = 1 }

	# 2: Culture is Yours -> Promote Culture (the same reasoning)
	leo_mvd_set_node_cond_effect = { NODE = r2_n1 COND = 2 THRESH = 0 }
	leo_mvd_set_node_dir_effect = { NODE = r2_n2 DIR = 2 }

	# 3+: grow the realm. Where administrative vassals exist the strong develop
	# their land and the weak raise men-at-arms, with a fourth priority behind
	# both: it catches the strong who fail Improve Development's duchy gate and
	# the weak who are not administrative and so cannot recruit at all. Where
	# such vassals do not exist there is no Improve Development directive, so the
	# strong build economy instead and the catch-all is not needed. Either
	# expansion supplies an administrative government, so both are asked about.
	if = {
		limit = { OR = { has_dlc_feature = roads_to_power has_dlc_feature = all_under_heaven } }
		set_variable = { name = leo_mvd_rule_count value = 4 }
		leo_mvd_set_node_cond_effect = { NODE = r3_n1 COND = 9 THRESH = leo_mvd_mil_baseline }
		leo_mvd_set_node_dir_effect = { NODE = r3_n2 DIR = 3 }
		leo_mvd_set_node_dir_effect = { NODE = r3_n3 DIR = 5 }
		leo_mvd_set_node_dir_effect = { NODE = r4_n1 DIR = 9 }
	}
	else = {
		set_variable = { name = leo_mvd_rule_count value = 3 }
		leo_mvd_set_node_cond_effect = { NODE = r3_n1 COND = 9 THRESH = leo_mvd_mil_baseline }
		leo_mvd_set_node_dir_effect = { NODE = r3_n2 DIR = 9 }
		leo_mvd_set_node_dir_effect = { NODE = r3_n3 DIR = 8 }
	}

	# Nomads: learn from the neighbors they hold, otherwise grow.
	set_variable = { name = leo_mvd_qrule_count value = 2 }
	leo_mvd_set_node_dir_effect = { NODE = q1_n1 DIR = 11 }
	leo_mvd_set_node_dir_effect = { NODE = q2_n1 DIR = 10 }

	set_variable = { name = leo_mvd_preset value = 1 }
}

# Current scope: the player.
# Homogenize the realm: convert faith, then culture, then grind down what is
# left with cultural acceptance.
leo_mvd_preset_2_effect = {
	leo_mvd_clear_rules_effect = yes
	set_variable = { name = leo_mvd_rule_count value = 4 }

	leo_mvd_set_node_cond_effect = { NODE = r1_n1 COND = 1 THRESH = 0 }
	leo_mvd_set_node_dir_effect = { NODE = r1_n2 DIR = 1 }

	leo_mvd_set_node_cond_effect = { NODE = r2_n1 COND = 2 THRESH = 0 }
	leo_mvd_set_node_dir_effect = { NODE = r2_n2 DIR = 2 }

	# 3: no condition needed - the directive's own vanilla gate already limits
	# it to duchy-tier vassals who still hold off-culture counties
	leo_mvd_set_node_dir_effect = { NODE = r3_n1 DIR = 6 }

	leo_mvd_set_node_dir_effect = { NODE = r4_n1 DIR = 9 }

	# Nomads: learn from the neighbors they hold, otherwise grow.
	set_variable = { name = leo_mvd_qrule_count value = 2 }
	leo_mvd_set_node_dir_effect = { NODE = q1_n1 DIR = 11 }
	leo_mvd_set_node_dir_effect = { NODE = q2_n1 DIR = 10 }

	set_variable = { name = leo_mvd_preset value = 2 }
}

# Current scope: the player.
# Arm the realm, each vassal to their strength. Administrative vassals put their
# men-at-arms to work, the rest build fortifications or military buildings. A
# single priority places every vassal, so it is the only one either way.
leo_mvd_preset_3_effect = {
	leo_mvd_clear_rules_effect = yes
	set_variable = { name = leo_mvd_rule_count value = 1 }

	# Where administrative vassals exist the priority splits first on government,
	# then on strength. Administrative vassals field troops of their own: the
	# strong sharpen the ones they have, the weak raise more. The rest build,
	# fortifications for the strong and military buildings for the weak. Where
	# such vassals do not exist there is no men-at-arms directive either, so it
	# splits on strength alone: the strong fortify, the weak build military. Both
	# trees place every vassal, so neither needs a catch-all priority behind it.
	if = {
		limit = { OR = { has_dlc_feature = roads_to_power has_dlc_feature = all_under_heaven } }
		leo_mvd_set_node_cond_effect = { NODE = r1_n1 COND = 6 THRESH = 0 }
		leo_mvd_set_node_cond_effect = { NODE = r1_n2 COND = 9 THRESH = leo_mvd_mil_baseline }
		leo_mvd_set_node_cond_effect = { NODE = r1_n3 COND = 9 THRESH = leo_mvd_mil_baseline }
		leo_mvd_set_node_dir_effect = { NODE = r1_n4 DIR = 4 }
		leo_mvd_set_node_dir_effect = { NODE = r1_n5 DIR = 5 }
		leo_mvd_set_node_dir_effect = { NODE = r1_n6 DIR = 7 }
		leo_mvd_set_node_dir_effect = { NODE = r1_n7 DIR = 8 }
	}
	else = {
		leo_mvd_set_node_cond_effect = { NODE = r1_n1 COND = 9 THRESH = leo_mvd_mil_baseline }
		leo_mvd_set_node_dir_effect = { NODE = r1_n2 DIR = 7 }
		leo_mvd_set_node_dir_effect = { NODE = r1_n3 DIR = 8 }
	}

	# Nomads: raid for herd, and grow what they hold.
	set_variable = { name = leo_mvd_qrule_count value = 2 }
	leo_mvd_set_node_dir_effect = { NODE = q1_n1 DIR = 13 }
	leo_mvd_set_node_dir_effect = { NODE = q2_n1 DIR = 10 }

	set_variable = { name = leo_mvd_preset value = 3 }
}

# Current scope: the player.
# Build wealth. Underdeveloped vassals raise their development first; once they
# are established they turn to economic buildings.
leo_mvd_preset_4_effect = {
	leo_mvd_clear_rules_effect = yes

	# Where administrative vassals exist, underdeveloped ones raise their
	# development first and turn to economic buildings once established, with a
	# second priority to catch those who fail Improve Development's gate. Where
	# they do not there is no development directive, so growth is economic
	# buildings for everyone.
	if = {
		limit = { OR = { has_dlc_feature = roads_to_power has_dlc_feature = all_under_heaven } }
		set_variable = { name = leo_mvd_rule_count value = 2 }
		leo_mvd_set_node_cond_effect = { NODE = r1_n1 COND = 11 THRESH = 40 }
		leo_mvd_set_node_dir_effect = { NODE = r1_n2 DIR = 9 }
		leo_mvd_set_node_dir_effect = { NODE = r1_n3 DIR = 3 }
		leo_mvd_set_node_dir_effect = { NODE = r2_n1 DIR = 9 }
	}
	else = {
		set_variable = { name = leo_mvd_rule_count value = 1 }
		leo_mvd_set_node_dir_effect = { NODE = r1_n1 DIR = 9 }
	}

	# Nomads: grow what they hold.
	set_variable = { name = leo_mvd_qrule_count value = 1 }
	leo_mvd_set_node_dir_effect = { NODE = q1_n1 DIR = 10 }

	set_variable = { name = leo_mvd_preset value = 4 }
}

# Current scope: the player.
# Let each governor do what their administration type already makes them good
# at, and give everyone else the safe default.
#
# Every administrative government sets an administration type on its governors,
# but each has its own set of them, so this loads the rules that fit the
# player's own government. No fallback branch, unlike presets 1/3/4: a player
# whose government has no administration types would get every rule here
# collapsing to "everyone builds economy", which Grow the Economy already is.
# The panel hides this preset outright instead (preset_dlc_vis in the
# generator), so this only ever runs where there are types to sort by.
#
# Each type's directive follows what the type itself does, and matches vanilla's
# own weighting where vanilla has one (give_vassal_directive_interaction's
# ai_will_do for the themes; the men-at-arms budget in 00_ai_values.txt for the
# celestial and meritocratic types):
#
#   Military and Protectorate  raise troops (they carry the levy and damage
#                              bonuses, and vanilla spends their income on
#                              men-at-arms)
#   Civilian and Industrial    grow their land (development and tax bonuses)
#   Frontier                   fortifies (it borders another realm and may raid)
#   Naval                      builds military, which is where its ports are
#   everyone else              builds economy, from the last priority
#
# Balanced, Standard, Imperial and Metropolitan governors have no directive of
# their own: the first three carry no bonus worth steering, and the last two are
# tax provinces, which is what the economy default already serves. They fall
# through, as does every vassal who is not a governor at all.
leo_mvd_preset_8_effect = {
	leo_mvd_clear_rules_effect = yes

	if = {
		limit = { leo_mvd_admin_family_celestial_trigger = yes }
		set_variable = { name = leo_mvd_rule_count value = 3 }
		# Both military types raise troops, so one priority asks about both.
		leo_mvd_set_node_cond_effect = { NODE = r1_n1 COND = 20 THRESH = 3 }
		leo_mvd_set_node_dir_effect = { NODE = r1_n2 DIR = 5 }
		leo_mvd_set_node_cond_effect = { NODE = r1_n3 COND = 20 THRESH = 10 }
		leo_mvd_set_node_dir_effect = { NODE = r1_n6 DIR = 5 }
		leo_mvd_set_node_cond_effect = { NODE = r2_n1 COND = 20 THRESH = 8 }
		leo_mvd_set_node_dir_effect = { NODE = r2_n2 DIR = 3 }
		leo_mvd_set_node_dir_effect = { NODE = r3_n1 DIR = 9 }
	}
	else_if = {
		# Meritocratic, steppe administrative and Ritsuryo: three types each, so
		# both rules fit in one priority.
		limit = {
			OR = {
				leo_mvd_admin_family_meritocratic_trigger = yes
				leo_mvd_admin_family_ritsuryo_trigger = yes
			}
		}
		set_variable = { name = leo_mvd_rule_count value = 2 }
		leo_mvd_set_node_cond_effect = { NODE = r1_n1 COND = 20 THRESH = 3 }
		leo_mvd_set_node_dir_effect = { NODE = r1_n2 DIR = 5 }
		leo_mvd_set_node_cond_effect = { NODE = r1_n3 COND = 20 THRESH = 8 }
		leo_mvd_set_node_dir_effect = { NODE = r1_n6 DIR = 3 }
		leo_mvd_set_node_dir_effect = { NODE = r2_n1 DIR = 9 }
	}
	else = {
		# The six Roads to Power themes, which is also what this preset started
		# as. Four of them are steered, in two priorities.
		set_variable = { name = leo_mvd_rule_count value = 3 }
		leo_mvd_set_node_cond_effect = { NODE = r1_n1 COND = 20 THRESH = 3 }
		leo_mvd_set_node_dir_effect = { NODE = r1_n2 DIR = 5 }
		leo_mvd_set_node_cond_effect = { NODE = r1_n3 COND = 20 THRESH = 4 }
		leo_mvd_set_node_dir_effect = { NODE = r1_n6 DIR = 7 }
		leo_mvd_set_node_cond_effect = { NODE = r2_n1 COND = 20 THRESH = 2 }
		leo_mvd_set_node_dir_effect = { NODE = r2_n2 DIR = 3 }
		leo_mvd_set_node_cond_effect = { NODE = r2_n3 COND = 20 THRESH = 6 }
		leo_mvd_set_node_dir_effect = { NODE = r2_n6 DIR = 8 }
		leo_mvd_set_node_dir_effect = { NODE = r3_n1 DIR = 9 }
	}

	# Nomads: grow what they hold. No nomad is administrative, so there is no
	# administration type to sort them by.
	set_variable = { name = leo_mvd_qrule_count value = 1 }
	leo_mvd_set_node_dir_effect = { NODE = q1_n1 DIR = 10 }

	set_variable = { name = leo_mvd_preset value = 8 }
}

# Current scope: the player. The player's own rules.
#
# Picking Custom from a preset starts blank - one priority, waiting for a
# directive - rather than carrying that preset over. Inheriting on selection
# sounds helpful but isn't: someone who picks Custom outright wants their own
# waterfall, and would have to dismantle four priorities of someone else's
# first. Starting from a preset is a different gesture, and it already works:
# change one of its rules and leo_mvd_edit_effect makes the whole thing yours.
#
# Doing nothing when Custom is already selected matters for exactly that reason
# - otherwise picking Custom over rules that are already yours would wipe them.
leo_mvd_preset_5_effect = {
	if = {
		limit = { NOT = { var:leo_mvd_preset = 5 } }
		if = {
			# Rules of their own, set aside when they last left Custom.
			limit = { has_variable = leo_mvd_has_custom }
			leo_mvd_restore_custom_effect = yes
		}
		else = {
			leo_mvd_clear_rules_effect = yes
			set_variable = { name = leo_mvd_rule_count value = 1 }
			leo_mvd_init_priority_effect = { P = r1 }
		}
	}
	set_variable = { name = leo_mvd_preset value = 5 }
}

# Current scope: the player. Load preset $N$ and re-apply if automation is on.
#
# Leaving Custom sets the player's rules aside first, so that trying a preset
# does not cost them their own waterfall.
leo_mvd_select_preset_effect = {
	if = {
		limit = { var:leo_mvd_preset = 5 }
		leo_mvd_backup_custom_effect = yes
	}
	leo_mvd_preset_$N$_effect = yes
	if = {
		limit = { has_variable = leo_mvd_auto }
		leo_mvd_run_waterfall_effect = yes
	}
}

### Adding and removing priorities.

# Current scope: the player. Everything an edit implies: the rules become the
# player's own, and automation picks the change up at once.
leo_mvd_after_edit_effect = {
	set_variable = { name = leo_mvd_preset value = 5 }
	if = {
		limit = { has_variable = leo_mvd_auto }
		leo_mvd_run_waterfall_effect = yes
	}
}

# Current scope: the player. Append an empty priority to the waterfall.
leo_mvd_add_priority_effect = {
	if = {
		limit = { var:leo_mvd_rule_count < 6 }
		change_variable = { name = leo_mvd_rule_count add = 1 }
		# Which slot that just became. A variable name cannot be built from a
		# value, so the new priority has to be named outright.
		if = {
			limit = { var:leo_mvd_rule_count = 2 }
			leo_mvd_init_priority_effect = { P = r2 }
		}
		else_if = {
			limit = { var:leo_mvd_rule_count = 3 }
			leo_mvd_init_priority_effect = { P = r3 }
		}
		else_if = {
			limit = { var:leo_mvd_rule_count = 4 }
			leo_mvd_init_priority_effect = { P = r4 }
		}
		else_if = {
			limit = { var:leo_mvd_rule_count = 5 }
			leo_mvd_init_priority_effect = { P = r5 }
		}
		else_if = {
			limit = { var:leo_mvd_rule_count = 6 }
			leo_mvd_init_priority_effect = { P = r6 }
		}
		leo_mvd_after_edit_effect = yes
	}
}

# Current scope: the player. Shared tail of removing a priority: the ones below
# it have already moved up, so the last slot is now a duplicate.
leo_mvd_finish_remove_effect = {
	leo_mvd_clear_priority_effect = { P = r6 }
	change_variable = { name = leo_mvd_rule_count add = -1 }
	leo_mvd_after_edit_effect = yes
}

# Current scope: the player. Drop a priority and close the gap, so that the
# waterfall stays an unbroken running order. Written out per slot because the
# shift depends on which one went.
leo_mvd_remove_priority_1_effect = {
	leo_mvd_copy_priority_between_effect = { FROM = r2 TO = r1 }
	leo_mvd_copy_priority_between_effect = { FROM = r3 TO = r2 }
	leo_mvd_copy_priority_between_effect = { FROM = r4 TO = r3 }
	leo_mvd_copy_priority_between_effect = { FROM = r5 TO = r4 }
	leo_mvd_copy_priority_between_effect = { FROM = r6 TO = r5 }
	leo_mvd_finish_remove_effect = yes
}
leo_mvd_remove_priority_2_effect = {
	leo_mvd_copy_priority_between_effect = { FROM = r3 TO = r2 }
	leo_mvd_copy_priority_between_effect = { FROM = r4 TO = r3 }
	leo_mvd_copy_priority_between_effect = { FROM = r5 TO = r4 }
	leo_mvd_copy_priority_between_effect = { FROM = r6 TO = r5 }
	leo_mvd_finish_remove_effect = yes
}
leo_mvd_remove_priority_3_effect = {
	leo_mvd_copy_priority_between_effect = { FROM = r4 TO = r3 }
	leo_mvd_copy_priority_between_effect = { FROM = r5 TO = r4 }
	leo_mvd_copy_priority_between_effect = { FROM = r6 TO = r5 }
	leo_mvd_finish_remove_effect = yes
}
leo_mvd_remove_priority_4_effect = {
	leo_mvd_copy_priority_between_effect = { FROM = r5 TO = r4 }
	leo_mvd_copy_priority_between_effect = { FROM = r6 TO = r5 }
	leo_mvd_finish_remove_effect = yes
}
leo_mvd_remove_priority_5_effect = {
	leo_mvd_copy_priority_between_effect = { FROM = r6 TO = r5 }
	leo_mvd_finish_remove_effect = yes
}
leo_mvd_remove_priority_6_effect = {
	leo_mvd_finish_remove_effect = yes
}

### The same, for the nomad waterfall.

leo_mvd_add_qpriority_effect = {
	if = {
		limit = { var:leo_mvd_qrule_count < 3 }
		change_variable = { name = leo_mvd_qrule_count add = 1 }
		if = {
			limit = { var:leo_mvd_qrule_count = 1 }
			leo_mvd_init_priority_effect = { P = q1 }
		}
		else_if = {
			limit = { var:leo_mvd_qrule_count = 2 }
			leo_mvd_init_priority_effect = { P = q2 }
		}
		else_if = {
			limit = { var:leo_mvd_qrule_count = 3 }
			leo_mvd_init_priority_effect = { P = q3 }
		}
		leo_mvd_after_edit_effect = yes
	}
}

# Unlike the main waterfall, this one is allowed to empty: a realm with no
# nomad vassals has no use for it, and leaving nomads alone is the mod's
# behavior until someone says otherwise.
leo_mvd_finish_qremove_effect = {
	leo_mvd_clear_priority_effect = { P = q3 }
	change_variable = { name = leo_mvd_qrule_count add = -1 }
	leo_mvd_after_edit_effect = yes
}

leo_mvd_remove_qpriority_1_effect = {
	leo_mvd_copy_priority_between_effect = { FROM = q2 TO = q1 }
	leo_mvd_copy_priority_between_effect = { FROM = q3 TO = q2 }
	leo_mvd_finish_qremove_effect = yes
}
leo_mvd_remove_qpriority_2_effect = {
	leo_mvd_copy_priority_between_effect = { FROM = q3 TO = q2 }
	leo_mvd_finish_qremove_effect = yes
}
leo_mvd_remove_qpriority_3_effect = {
	leo_mvd_finish_qremove_effect = yes
}

### Succession.

# Current scope: the heir. Copies one node from root (the dying player).
leo_mvd_copy_node_effect = {
	set_variable = { name = leo_mvd_$NODE$_kind value = root.var:leo_mvd_$NODE$_kind }
	set_variable = { name = leo_mvd_$NODE$_dir value = root.var:leo_mvd_$NODE$_dir }
	set_variable = { name = leo_mvd_$NODE$_cond value = root.var:leo_mvd_$NODE$_cond }
	set_variable = { name = leo_mvd_$NODE$_thresh value = root.var:leo_mvd_$NODE$_thresh }
}

# Current scope: the heir. Copies priority $P$ from root.
leo_mvd_copy_priority_effect = {
	leo_mvd_copy_node_effect = { NODE = $P$_n1 }
	leo_mvd_copy_node_effect = { NODE = $P$_n2 }
	leo_mvd_copy_node_effect = { NODE = $P$_n3 }
	leo_mvd_copy_node_effect = { NODE = $P$_n4 }
	leo_mvd_copy_node_effect = { NODE = $P$_n5 }
	leo_mvd_copy_node_effect = { NODE = $P$_n6 }
	leo_mvd_copy_node_effect = { NODE = $P$_n7 }
}

# Current scope: the heir. Carries the whole rule set over from root, including
# the Custom slot - an heir who inherits a preset should still find their
# predecessor's own rules waiting under Custom.
leo_mvd_copy_rules_effect = {
	set_variable = { name = leo_mvd_preset value = root.var:leo_mvd_preset }
	set_variable = { name = leo_mvd_rule_count value = root.var:leo_mvd_rule_count }
	leo_mvd_copy_priority_effect = { P = r1 }
	leo_mvd_copy_priority_effect = { P = r2 }
	leo_mvd_copy_priority_effect = { P = r3 }
	leo_mvd_copy_priority_effect = { P = r4 }
	leo_mvd_copy_priority_effect = { P = r5 }
	leo_mvd_copy_priority_effect = { P = r6 }
	set_variable = { name = leo_mvd_qrule_count value = root.var:leo_mvd_qrule_count }
	leo_mvd_copy_priority_effect = { P = q1 }
	leo_mvd_copy_priority_effect = { P = q2 }
	leo_mvd_copy_priority_effect = { P = q3 }
	if = {
		limit = { root = { has_variable = leo_mvd_has_custom } }
		set_variable = leo_mvd_has_custom
		set_variable = { name = leo_mvd_crule_count value = root.var:leo_mvd_crule_count }
		leo_mvd_copy_priority_effect = { P = cr1 }
		leo_mvd_copy_priority_effect = { P = cr2 }
		leo_mvd_copy_priority_effect = { P = cr3 }
		leo_mvd_copy_priority_effect = { P = cr4 }
		leo_mvd_copy_priority_effect = { P = cr5 }
		leo_mvd_copy_priority_effect = { P = cr6 }
		set_variable = { name = leo_mvd_cqrule_count value = root.var:leo_mvd_cqrule_count }
		leo_mvd_copy_priority_effect = { P = cq1 }
		leo_mvd_copy_priority_effect = { P = cq2 }
		leo_mvd_copy_priority_effect = { P = cq3 }
	}
}
