atl/ai.hpp
Combat and AI: sm.projectile, sm.melee, sm.ai, sm.pathfinder and sm.pathNode.
sm::projectile
Section titled "sm::projectile"Firing projectiles. Damage is dealt by the game when a projectile hits.
template <class Source> void attack(const Uuid &projectile, int damage, Vec3 position, Vec3 velocity, const Source &source, const Options &o = {});Fires a projectile from source (a player, unit or other object).
Parameters
projectile(const Uuid &)damage(int)position(Vec3)velocity(Vec3)source(const Source &)o(const Options &)
Lua: sm.projectile.projectileAttack
template <class Source> void customAttack(const Value &customData, const Uuid &projectile, int damage, Vec3 position, Vec3 velocity, const Source &source, const Options &o = {});[server] Fires a projectile carrying customData to whatever it hits.
Parameters
customData(const Value &)projectile(const Uuid &)damage(int)position(Vec3)velocity(Vec3)source(const Source &)o(const Options &)
Lua: sm.projectile.customProjectileAttack
inline void shapeAttack(const Uuid &projectile, int damage, Vec3 position, Vec3 velocity, const Shape &source, const Options &o = {});Fires a projectile from a shape.
Parameters
projectile(const Uuid &)damage(int)position(Vec3)velocity(Vec3)source(const Shape &)o(const Options &)
Lua: sm.projectile.shapeProjectileAttack
inline void shapeCustomAttack(const Value &customData, const Uuid &projectile, int damage, Vec3 position, Vec3 velocity, const Shape &source, const Options &o = {});[server] Fires a projectile carrying customData from a shape.
Parameters
customData(const Value &)projectile(const Uuid &)damage(int)position(Vec3)velocity(Vec3)source(const Shape &)o(const Options &)
Lua: sm.projectile.shapeCustomProjectileAttack
inline void harvestableAttack(const Uuid &projectile, int damage, Vec3 position, Vec3 velocity, const Harvestable &source, const Options &o = {});Fires a projectile from a harvestable.
Parameters
projectile(const Uuid &)damage(int)position(Vec3)velocity(Vec3)source(const Harvestable &)o(const Options &)
Lua: sm.projectile.harvestableProjectileAttack
inline void harvestableCustomAttack(const Value &customData, const Uuid &projectile, int damage, Vec3 position, Vec3 velocity, const Harvestable &source, const Options &o = {});[server] Fires a projectile carrying customData from a harvestable.
Parameters
customData(const Value &)projectile(const Uuid &)damage(int)position(Vec3)velocity(Vec3)source(const Harvestable &)o(const Options &)
Lua: sm.projectile.harvestableCustomProjectileAttack
inline void playerFire(const Uuid &projectile, Vec3 position, Vec3 velocity, const Options &o = {});[client] Fires a projectile from the local player.
Parameters
projectile(const Uuid &)position(Vec3)velocity(Vec3)o(const Options &)
Lua: sm.projectile.playerFire
inline void shapeFire(const Shape &shape, const Uuid &projectile, Vec3 position, Vec3 velocity, Optional<int> delay = atl::none, Optional<int> amount = atl::none);[server] Fires a projectile from a shape, optionally amount at once.
Parameters
shape(const Shape &): The shape.projectile(const Uuid &): The projectile's uuid.position(Vec3): The start position.velocity(Vec3): The direction and velocity.delay(Optional<int>): The number of ticks before firing. (Defaults to 0)amount(Optional<int>): The amount of shots that will be fired. Uses projectile amount from json if not set (Optional, range of 0-255)
Lua: sm.projectile.shapeFire
template <class Source> void removeWithSource(const Source &source, Optional<int> delay = atl::none);Removes projectiles fired by source, optionally after a delay.
Parameters
source(const Source &)delay(Optional<int>)
Lua: sm.projectile.removeProjectilesWithSource
inline void removeWithSource(const Character &source, Optional<int> delay, const World &world);Removes projectiles fired by a character in a given world.
Parameters
source(const Character &): The Character that is the source of the projectile.delay(Optional<int>): The number of ticks before destroying the projectile. (Defaults to 0)world(const World &): The world the projectiles should be removed from. (Defaults to same world as source.)
Lua: sm.projectile.removeProjectilesWithSource
inline double mass(const Uuid &projectile);A projectile type's mass and radius.
Parameters
projectile(const Uuid &): The projectile's uuid.
Returns double
Lua: sm.projectile.getProjectileMass
inline double radius(const Uuid &projectile);A projectile type's mass and radius.
Parameters
projectile(const Uuid &): The projectile's uuid.
Returns double
Lua: sm.projectile.getProjectileRadius
inline Optional<Arc> solveBallisticArc(Vec3 from, Vec3 target, double velocity, double gravity);Solves the launch velocities that hit target from from at a given speed; none if out of reach.
Parameters
from(Vec3): The position the projectile is fired from.target(Vec3): The position the projectile should hit.velocity(double): The fire velocity of the projectile.gravity(double): The gravity ( positive down ).
Returns Optional<Arc>
Lua: sm.projectile.solveBallisticArc
Options
Section titled "Options"Optional projectile settings. fakePos* set where the projectile appears to start in third / first person; delay and lifetime are in ticks.
struct OptionsOptional<Vec3> fakePosThird;Optional<Vec3> fakePosFirst;Optional<int> delay;Optional<double> acceleration;Optional<int> lifetime;The two launch velocities that hit a target: a low and a high arc.
struct ArcVec3 low, high;sm::melee
Section titled "sm::melee"Melee attacks.
template <class Source> void attack(const Uuid &melee, int damage, Vec3 origin, Vec3 directionRange, const Source &source, Optional<int> delay = atl::none, Optional<double> power = atl::none, const Vector<Character> &ignore = {});Performs a melee attack from origin in directionRange (direction scaled by reach).
ignore lists characters the attack passes through.
Parameters
melee(const Uuid &): The uuid of the melee attack.damage(int): The damage the attack will inflict.origin(Vec3): The source position of the attack.directionRange(Vec3): The direction and reach of the attack.source(const Source &): The player that is the source of the attack.delay(Optional<int>): The number of ticks before performing the attack. (Defaults to 0)power(Optional<double>): The strength of the knockback power. (Defaults to 5000)ignore(const Vector<Character> &): A table of characters to ignore in the attack. (optional)
Lua: sm.melee.meleeAttack
inline Vector<physics::RaycastHit> attackHits(const Uuid &melee, Vec3 origin, Vec3 directionRange, const Unit &source);What a unit's melee attack would hit, without attacking.
Parameters
melee(const Uuid &): The uuid of the melee attack.origin(Vec3): The source position of the attack.directionRange(Vec3): The direction and reach of the attack.source(const Unit &): The unit that is the source of the attack.
Returns Vector<physics::RaycastHit>
Lua: sm.melee.getMeleeAttackHits
sm::ai
Section titled "sm::ai"Helpers for AI units.
inline bool isReachable(const Unit &unit, Vec3 position);True if the unit can walk to position.
Parameters
unit(const Unit &): The unit.position(Vec3): The target position.
Returns bool
Lua: sm.ai.isReachable
inline bool directPathAvailable(const Unit &unit, Vec3 position, double range);True if there is a straight unobstructed path within range.
Parameters
unit(const Unit &): The unit.position(Vec3): The target position.range(double): The maximum allowed distance to target position.
Returns bool
Lua: sm.ai.directPathAvailable
template <class T> Optional<Vec3> aimPosition(const Character &character, const T &target, double range, double width, Optional<int> attack = atl::none);Where the character should aim to hit target, or none if it can't.
Parameters
character(const Character &): The firing character.target(const T &): The target character.range(double): The maximum firing distance.width(double): The width of the fire lane.attack(Optional<int>): The attack level of the projectile. (Defaults to 5)
Returns Optional<Vec3>
Lua: sm.ai.getAimPosition
inline Optional<Breach> breachablePosition(const Unit &unit, Vec3 position, double range, int attackLevel);Something the unit could break through on the way to position.
Parameters
unit(const Unit &): The unit.position(Vec3): The target position.range(double): The distance.attackLevel(int): The possible attack level from the breacher.
Returns Optional<Breach>
Lua: sm.ai.getBreachablePosition
inline Character closestVisiblePlayerCharacter(const Unit &unit);The nearest player character the unit can see.
Parameters
unit(const Unit &): The unit.
Returns Character
Lua: sm.ai.getClosestVisiblePlayerCharacter
inline Character closestVisibleCharacterType(const Unit &unit, const Uuid &characterType);The nearest visible character of a given type.
Parameters
unit(const Unit &): The unit.characterType(const Uuid &): The character uuid.
Returns Character
Lua: sm.ai.getClosestVisibleCharacterType
inline Character closestVisibleTeamOpponent(const Unit &unit, Color teamColor);The nearest visible character not on the given team.
Parameters
unit(const Unit &): The unit.teamColor(Color): The color.
Returns Character
Lua: sm.ai.getClosestVisibleTeamOpponent
inline Harvestable closestVisibleCrop(const Unit &unit);The nearest visible crop.
Parameters
unit(const Unit &): The unit.
Returns Harvestable
Lua: sm.ai.getClosestVisibleCrop
inline Harvestable closestTree(Vec3 position, const World &world = {});The nearest tree to a position.
Parameters
position(Vec3): The world position to search around.world(const World &): The world to search in. (Defaults to the world of the script that is calling the function)
Returns Harvestable
Lua: sm.ai.getClosestTree
inline Vec3 randomCreationPosition(const Body &body);A random point on a creation's body.
Parameters
body(const Body &): The body.
Returns Vec3
Lua: sm.ai.getRandomCreationPosition
Breach
Section titled "Breach"A blocking object the unit could break through, and where.
struct BreachVec3 position;Target object;sm::pathfinder
Section titled "sm::pathfinder"Navigation-mesh pathfinding.
inline Vec3 constrainToNavMesh(const World &world, Vec3 point, const Optional<Abilities> &a = atl::none);[server] The nearest point to point on the navigation mesh.
Parameters
world(const World &): The world to look in.point(Vec3): The point.a(const Optional<Abilities> &)
Returns Vec3
Lua: sm.pathfinder.constrainPointToNavMesh
inline Vec3 randomPoint(const World &world, Vec3 point, double radius, const Optional<Abilities> &a = atl::none);[server] A random reachable point within radius of point.
Parameters
world(const World &): The world to look in.point(Vec3): The point.radius(double): The radius to search in.a(const Optional<Abilities> &)
Returns Vec3
Lua: sm.pathfinder.getRandomPoint
inline Value path(const Character &character, Vec3 destination, Optional<bool> groundPosition = atl::none, const Optional<Abilities> &a = atl::none, const Optional<Costs> &c = atl::none);[server] A path for a character to destination, as the game's path table.
Parameters
character(const Character &): The character to find path fordestination(Vec3): The path destinationgroundPosition(Optional<bool>): If the destination is ground level (ignored if nav mesh is used) (Defaults to true)a(const Optional<Abilities> &)c(const Optional<Costs> &)
Returns Value
Lua: sm.pathfinder.getPath
inline Vector<PathNode> worldPath(const World &world, Vec3 start, Vec3 destination, const Optional<Abilities> &a = atl::none, const Optional<Costs> &c = atl::none);[server] The nodes of a path between two points in a world.
Parameters
world(const World &): The world to look instart(Vec3): The path startdestination(Vec3): The path destinationa(const Optional<Abilities> &)c(const Optional<Costs> &)
Returns Vector<PathNode>
Lua: sm.pathfinder.getWorldPath
inline Vector<PathNode> sortedNodes(Vec3 position, double minDistance, double maxDistance);[server] Path nodes around position between the two distances, nearest first.
Parameters
position(Vec3): The position to look inminDistance(double): Minimum distance around posmaxDistance(double): Maximum distance around pos
Returns Vector<PathNode>
Lua: sm.pathfinder.getSortedNodes
inline Traversal traversableRaycast(const World &world, Vec3 start, Vec3 destination, const Optional<Abilities> &a = atl::none);[server] Checks whether a unit can move in a straight line from start to destination.
Parameters
world(const World &): The world to look in.start(Vec3): The path startdestination(Vec3): The path destinationa(const Optional<Abilities> &)
Returns Traversal
Lua: sm.pathfinder.traversableRaycast
Abilities
Section titled "Abilities"Movement abilities; unset fields keep the game's defaults.
struct AbilitiesOptional<bool> canWalk;Optional<bool> canSwim;Per-terrain movement costs; unset fields keep the game's defaults.
struct CostsOptional<double> ground, water, chemicals, oil, lava;Traversal
Section titled "Traversal"Result of traversableRaycast: whether the way is clear, and how far it got (0..1).
struct Traversalbool clear = false;double fraction = 0;sm::pathNodes
Section titled "sm::pathNodes"Placed path nodes.
inline PathNode create(Vec3 position, double radius, bool temporary = false);[server] Creates a path node; a temporary one isn't saved.
Parameters
position(Vec3): The node's world positionradius(double): The node's radiustemporary(bool): Temporary nodes are not saved and relies on lua garbage collection for removal (defaults to false).
Returns PathNode
Lua: sm.pathNode.createPathNode