# Expressions

From Wildermyth Wiki

Most places that require you to enter a value (when making Effects, most commonly) do so through the use of Expressions. These can be made up of regular numbers, addition, subtraction, multiplication, and division, in addition to the functions and variables listed below.

## Functions

function | example | returns | explanation/usage |
---|---|---|---|

abs(x) | abs(-5) | 5 | The absolute value of the input value |

atan2(x, y) | atan2(1, 1)*180/3.14 | 45.02 | atan2 of the given x, y position. Good for angles! |

boolean(x) | boolean(5) | 1 | Returns 0 if the given expression evaluates to 0, 1 otherwise |

ceil(x) | ceil(2.7) | 3 | Rounds up |

floor(x) | floor(2.7) | 2 | Rounds down |

round(x) | round(2.7) | 3 | Rounds to nearest |

max(x, y, z...) | max(2, 3, 8, 6) | 8 | Returns the max of any number of parameters |

min(x, y, z...) | min(2, 3, 8, 6) | 2 | Returns the min of any number of parameters |

pow(x, e) | pow(2, 3) | 8 | Returns the first parameter to the power of the second parameter |

sqrt(x) | sqrt(16) | 4 | Returns the square root |

sin(x) | sin(3.14/2) | 1 | |

cos(x) | cos(3.14/2) | 0 | |

sign(x) | sign(5) | 1 | Returns the signum; zero if the argument is zero, 1 if the argument is greater than zero, -1 if the argument is less than zero. |

smoothstep(x) | smoothstep(0.75) | 0.84 | Given a number between 0 and 1, returns that number put into the smoothstep function (x*x*(3-2*x)) |

smootherstep(x) | smootherstep(0.75) | 0.89 | Given a number between 0 and 1, returns that number put into the smootherstep function (x*x*x*(10+x*(6*x-15))) |

## Variables

variable | example | returns | explanation/usage |
---|---|---|---|

EVENT_ROLL | A number between 1 and 100 | Used in choice target tests, in the Chose Outcome, generally seen together with roll_one, roll_two, roll_three, etc. expressions | |

IS_FLANKING | 1 if flanking, 0 otherwise | If this event contains attack info (e.g. a DAMAGE_ROLL, DAMAGE_ROLL_INCOMING, DAMAGE_ROLL_AFTER_ARMOR), returns whether or not the attack is flanking. | |

THIS_ASPECT | The integer value of this event's parent aspect | If this event has a parent aspect, returns the value of that aspect. | |

TOWN_POPULATION_LIMIT | The population limit for all towns (200) | ||

RECRUIT_COST_ADJUSTMENT | -1 if company size < 3, 0 if >= 3, 1 if >= 6, 2 if >= 8, 3 if >= 10 |
Adjustment for recruit cost based on company size. This is used to make recruits cheaper if you have fewer of them, and more expensive if you have more. | |

RECRUIT_ENCOUNTER_SCORE_OFFSET | If chapter 1, returns 0.5 if company size=3, 2 if size=2, 4 if size=1. If chapter > 1, returns 0.5 if company size=4, 2 if size=3, 4 if size=2, 9 if size=1. Returns 0 otherwise. |
An offset for recruit encounters that makes it so the encounter is more likely to happen if you have a smaller company. This is used in events that give you recruits. | |

isDefender | isDefender.hero | 1 if the given role is the current defender of an AttackRoll Outcome, 0 otherwise | Generally used if you want different damage for one enemy in an attack than for others. (See how fireleash works, dealing half damage to defenders that aren't on the target tile) |

RESOURCE | RESOURCE.legacyPoints | The amount of the given resource | Can be used to find the amount of any resource: legacyPoints, heartwoods, hides, ingots, fabrics, and spellthreads |

COUNT | COUNT.target | How many matches were made for the given target | Often used in the effect.info.aiPriority field to make give AOE attacks higher priority if they hit more targets. Also used in the Damage Outcome for multi-target abilities, to divide stunt chance among the targets. |

WEAPON_TIER | WEAPON_TIER.weapon | The tier of the given weapon, or -1 if there isn't one or it isn't a weapon | ex: stuntEffect_fire |

distanceTo | target.distanceTo.targetTile | In a mission, the distance between two roles (can be entities or tiles) | Used to calculate the extra damage dealt from knockback attacks, and certain other edge cases like making sure the Thrixl Thrusk is still in range to attack again after its first attack (e.g. if the defender has Riposte and a knockback weapon) |

ticksPerTurn | 2 | Used along with timeCostPerStep for movement abilities | |

SIZE | source.SIZE | Number of tiles a mission entity takes up, or its max footprint dimension | Used in Splinterblast to give larger objects greater AOE |

AGE_IN_YEARS | The age of the current target. | ||

MIN_ATTACK_RANGE | self.MIN_ATTACK_RANGE | The minimum range at which the given target can attack. | Used for movement abilities to determine whether to show the dotted-line attack suggestion. |

MAX_ATTACK_RANGE | self.MAX_ATTACK_RANGE | The maximum range at which the given target can attack. | Used for movement abilities to determine whether to show the dotted-line attack suggestion. |

MAX_MELEE_ATTACK_RANGE | self.MAX_MELEE_ATTACK_RANGE | The maximum range at which the given target can melee attack. | Used for guarding abilities to show range feedback. |

maxValue | self.maxValue.gorgonCorruptedTileRel | The maximum value of any aspects the given target has starting with the given string | |

HAS_FRIEND | 1 if the current target has a friend, 0 otherwise | Used in events when we want to match a target that has a friend | |

HAS_LOVER | 1 if the current target has a lover, 0 otherwise | Used in events when we want to match a target that has a lover | |

HAS_RIVAL | 1 if the current target has a rival, 0 otherwise | Used in events when we want to match a target that has a rival | |

HAS_FAMILY | 1 if the current target has family (a parent, child, grandparent, etc), 0 otherwise | ||

HAS_PARENT | 1 if the current target has a parent, 0 otherwise | ||

HAS_CHILD | 1 if the current target has a child, 0 otherwise | ||

LEVEL | self.LEVEL | The level of the given hero target, or 0 if none | Generally used in abilities when we want the ability's power to scale with level |

raw | raw.POTENCY | The raw stat (a float, not converted to an integer) | |

CAN_ROMANCE | CAN_ROMANCE.hook | 1 if the current target can romance the given target, 0 otherwise | Must be mutually attracted, not already have lovers, and non-family |

CAN_RIVAL | CAN_RIVAL.hook | 1 if the current target can be rivals with the given target, 0 otherwise | Must not already have rivals |

SHIP_WITH | SHIP_WITH.hook | The tier of the relationship between the current target and the given target | This can be any kind of relationship; lovers, rivals, or friends |

FRIEND_WITH | FRIEND_WITH.hook | The tier of the friendship between the current target and the given target, 0 if not friends | |

LOVER_WITH | LOVER_WITH.hook | The tier of the romance between the current target and the given target, 0 if not lovers | |

RIVAL_WITH | RIVAL_WITH.hook | The tier of the rivalry between the current target and the given target, 0 if not rivals | |

FAMILY_WITH | FAMILY_WITH.hook | 1 if the current target is family with the given target, 0 otherwise | |

PARENT_OF | PARENT_OF.hook | 1 if the current target is the parent of the given target, 0 otherwise | |

CHILD_OF | CHILD_OF.hook | 1 if the current target is the child of the given target, 0 otherwise | |

NOT_FAMILY_WITH | NOT_FAMILY_WITH.hook | 0 if the current target is family with the given target, 1 otherwise. | NOT_FAMILY_WITH.hook is equivalent to (1 - FAMILY_WITH.hook) |