Skip to main content

sm.ai

AI utility functions.

Functions

directPathAvailable

sm.ai.directPathAvailable( unit, position )

Checks if the unit can reach the target position by moving straight.

Arguments:
  • unit [ Unit ]: The unit.
  • position [ Vec3 ]: The target position.
Returns:
  • [ bool ]: Whether the target position is directly reachable or not.

getAimPosition

sm.ai.getAimPosition( character, target, range, width )

Returns true if the character can fire at the target within a given fire lane.

Also returns the aim position that allows the character to succeed.

Arguments:
  • character [ Character ]: The firing character.
  • target [ Harvestable /character ]: The target.
  • range [ number ]: The maximum firing distance.
  • width [ number ]: The width of the fire lane.
Returns:
  • [ bool ]: Whether the character can fire at the target or not.
  • [ Vec3 ]: The aim position, if available.

getBreachablePosition

sm.ai.getBreachablePosition( unit, position, range, attack )

Check if there's an attackable object between the unit and a position.

Arguments:
  • unit [ Unit ]: The unit.
  • position [ Vec3 ]: The target position.
  • range [ number ]: The distance.
  • attack [ int ]: The possible attack level from the attacker.
Returns:
  • [ bool ]: True if a breachable object was found or no object was found. False if the found object is unbreachable.
  • [ Vec3 ]: The attackable position, if found.
  • [ Shape / Harvestable /lift ]: The object to attack.

getClosestTree

sm.ai.getClosestTree( position, world )

Find the closest "tree" harvestable in a world.

Arguments:
Returns:

getClosestVisibleCharacterType

sm.ai.getClosestVisibleCharacterType( unit, uuid )

Returns the closest visible character with matching uuid.

Arguments:
  • unit [ Unit ]: The unit.
  • uuid [ Uuid ]: The character uuid.
Returns:

getClosestVisibleCrop

sm.ai.getClosestVisibleCrop( unit )

Returns the closest visible farming harvestable.

Arguments:
Returns:

getClosestVisiblePlayerCharacter

sm.ai.getClosestVisiblePlayerCharacter( unit )

Returns the closest visible player character.

Arguments:
Returns:

getClosestVisibleTeamOpponent

sm.ai.getClosestVisibleTeamOpponent( unit, color )

Returns the closest visible character that does not have the given color.

Arguments:
Returns:

getRandomCreationPosition

sm.ai.getRandomCreationPosition( body )

Returns a random position on the given body.

Arguments:
Returns:
  • [ Vec3 ]: The random position.

isReachable

sm.ai.isReachable( unit, position )

Check if the unit can reach the target position by moving along a path.

Arguments:
  • unit [ Unit ]: The unit.
  • position [ Vec3 ]: The target position.
Returns:
  • [ bool ]: Whether the position is reachable or not.