selected.lua -
The function expects 3 inputs. isSelected(unit,unitTarget,args).
unit is a reference unit (not the ID but the actual unit table), only important for checking radius and target affects.
unitTarget is the unit you wish to make the various checks on, can be the same as unit
args is a list of arguments, can be taken directly from the autoSyndrome or syndromeTrigger inputs
Note, the above is only important if you wish to use this selection criteria in your own scripts. The scripts included in this thread already have the necessary modifications included.
Now for the fun stuff!
All checks take the form
type@
logic;value;subvalue (not all have all three). Below is a detailed list of all accepted inputs. Multiple checks can be included in the same type by separating with commas (e.g.
type@
logic;value;subvalue,
logic;value;subvalue,
logic;value;subvalue)
- radius - Used to test if unitTarget is within certain distance of unit
- circle - treats the radius as circular, x^2+y^2+z^2
- square - treats the radius as absolute, covers all squares
- outside - treats the radius as exclusive, covers all squares not in specified radius
- x,y,z value - integers 0+, will change large values to preserve map size
- EXAMPLE: radius@circle;10,10,0
- target - Used to test unitTarget's relationship to unit
- foreign - checks that civ ID is different
- civ - checks that civ ID is the same
- aclass - Checks creature classes specified in raws (see below for information on logic check)
- ANY SELF DECLARED CREATURE CLASS
- N/A
- EXAMPLE: aclass@GENERAL_POISON
- acreature - Checks if specific creature;caste (see below for information on logic check)
- ANY CREATURE;CASTE COMBINATION
- N/A
- EXAMPLE: acreature@DWARF;FEMALE
- asyndrome - Checks syndrome classes specified in individual creature (see below for information on logic check)
- ANY SELF DECLARED SYNDROME CLASS
- N/A
- EXAMPLE: asyndrome@SPEED_CHANGE
- atoken - Checks creature tokens specified in raws (see below for information on logic check)
- ANY OF THE TOKENS FOUND HERE
- N/A
- EXAMPLE: atoken@AMPHIBOUS,AQUATIC
- iclass - Checks creature classes specified in raws (see below for information on logic check)
- ANY SELF DECLARED CREATURE CLASS
- N/A
- EXAMPLE: iclass@GENERAL_POISON
- icreature - Checks if specific creature;caste (see below for information on logic check)
- ANY CREATURE;CASTE COMBINATION
- N/A
- EXAMPLE: icreature@DWARF;FEMALE
- isyndrome - Checks syndrome classes specified in individual creature (see below for information on logic check)
- ANY SELF DECLARED SYNDROME CLASS
- N/A
- EXAMPLE: isyndrome@SPEED_CHANGE
- itoken - Checks creature tokens specified in raws (see below for information on logic check)
- ANY OF THE TOKENS FOUND HERE
- N/A
- EXAMPLE: itoken@AMPHIBOUS,AQUATIC
- physical - Checks the physical attributes of the unitTarget
- max
- min
- STRENGTH
- AGILITY
- TOUGHNESS
- ENDURANCE
- RECUPERATION
- DISEASE_RESISTANCE
- attribute value
- EXAMPLE: physical@min;STRENGTH;2500,min;AGILITY;2500
- mental - Checks the mental attributes of the unitTarget
- max
- min
- ANALYTICAL_ABILITY
- FOCUS
- WILLPOWER
- CREATIVITY
- INTUITION
- PATIENCE
- MEMORY
- LINGUISTIC_ABILITY
- SPATIAL_SENSE
- MUSICALITY
- KINESTHETIC_SENSE
- EMPATHY
- SOCIAL_AWARENESS
- attribute value
- EXAMPLE: mental@min;MEMORY;3000
- skills - Checks the skills of the unitTarget
- max
- min
- any of the skills found here
- skill level (0-20)
- EXAMPLE: skills@min;ALCHEMY;15
- traits - Checks the personality traits of the unitTarget
- max
- min
- any of the personality traits found here
- trait level (0-100)
- EXAMPLE: traits@max;ANGER;50
- age - Checks the age of the unitTarget as determined by dfhack.units.getAge(unit), "Returns the age of the unit in years as a floating-point value."
- max
- min
- age value (0+)
- EXAMPLE: age@min;80
- speed - Checks the movement speed of the unitTarget as determined by dfhack.units.computeMovementSpeed(unit), "Computes number of frames * 100 it takes the unit to move in its current state of mind and body."
- max
- min
- movement speed value (0+)
- EXAMPLE: speed@min;1000
- noble - Checks the noble positions of the unitTarget
- required
- immune
- ANY NOBLE POSITION TOKEN
- EXAMPLE: noble@required;MONARCH
- profession - Checks the profession of the unitTarget
- required
- immune
- any profession token found here
- EXAMPLE: profession@immune;BABY,immune;CHILD
Remark on the logic used:
The logic used to determine if a unitTarget passes or fails these checks is similar to the current logic in syndromes and interactions. It starts by checking the radius and target values if they are present. After those are passed it goes on to check the age, speed, physical, mental, skills, traits, noble, and position checks (again only if they are present). After it has passed all of these checks it begins to look through the iclass, icreature, isyndrome, and itoken checks. If the unitTarget has any of these classes or tokens it will fail (as would be expected). If it has passed all of the above checks it then looks at the aclass, acreature, and asyndrome checks. These checks are treated slightly differently than the others. If none of them are present, the unitTarget will pass and the script will return true. However, if any one of these checks is present the creature will fail UNLESS the creature has the required class or token (e.g. if you have acreature@DWARF;FEMALE than only the FEMALE caste of the DWARF creature will be targeted). Finally the atoken is checked. This check requires that the creature has ALL of the listed tokens, not just one of them.
I believe this logic is fairly intuitive, and am pretty sure is what is used in the games interactions logic. If you have any questions about the logic, please feel free to ask.
Lastly, these are the currently accepted values (as you can see, there is A LOT that can be done with these checks). While typing this up I thought of some additional checks for all of those that are looking for a min/max value.
- less and greater! This would check the unitTarget against the unit and determine if it has a lesser value or a greater value (e.g. check if the target is faster than the reference unit, if it is the interaction doesn't work)
- ratio! Check the ratio of ages (Meph mentioned this below), and the ratio of different values
EDIT: Another thing that might be interesting is entity specific interactions, I will look into figuring out the entity of the unitTarget using DFHack.