sm.ai

AI utility functions.

Functions

directPathAvailable

sm.ai.directPathAvailable( unit, position, range )

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

Parameters:

Name Type Description
unit Unit The unit.
position Vec3 The target position.
range number The maximum allowed distance to target position.

Returns:

Type Description
boolean Returns true if the position is available directly.

getAimPosition - Harvestable

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

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

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

Parameters:

Name Type Description
self Character The firing character.
target Harvestable The target harvestable.
range number The maximum firing distance.
width number The width of the fire lane.

Returns:

Type Description
boolean
Vec3
The result.

getAimPosition - Character

sm.ai.getAimPosition( self, target, range, width, attack )

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

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

Any obstacle shape that blocks the target, but can be destroyed by the projectile, will be targeted instead.

Parameters:

Name Type Description
self Character The firing character.
target Character The target character.
range number The maximum firing distance.
width number The width of the fire lane.
attack integer The attack level of the projectile. (Defaults to 5)

Returns:

Type Description
boolean
Vec3
The result.

getBreachablePosition

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

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

Parameters:

Name Type Description
unit Unit The unit.
position Vec3 The target position.
range number The distance.
attack integer The possible attack level from the breacher.

Returns:

Type Description
boolean
Vec3
Shape
Returns true if a breachable object is found, an attackable position, and an attackable shape.
boolean
Vec3
Harvestable
Returns true if a breachable object is found, an attackable position, and an attackable harvestable.
boolean
Vec3
Lift
Returns true if a breachable object is found, an attackable position, and an attackable lift.
boolean
Vec3
Returns false if the object is unbreachable and an attackable position.
boolean Returns true when nothing is found.

getClosestTree

sm.ai.getClosestTree( position, world )

Find the closest harvestable of 'tree' type in a world.

Parameters:

Name Type Description
position Vec3 The world position to search around.
world (optional) World The world to search in. (Defaults to the world of the script that is calling the function)

Returns:

Type Description
Harvestable The closest tree harvestable.

getClosestVisibleCharacterType

sm.ai.getClosestVisibleCharacterType( unit, uuid )

Returns the character of a given uuid type that is closest to the unit.

Parameters:

Name Type Description
unit Unit The unit.
uuid Uuid The character uuid.

Returns:

Type Description
Character The character.

getClosestVisibleCrop

sm.ai.getClosestVisibleCrop( unit )

Returns the farming harvestable that is closest to the unit.

Parameters:

Name Type Description
unit Unit The unit.

Returns:

Type Description
Harvestable The harvestable.

getClosestVisiblePlayerCharacter

sm.ai.getClosestVisiblePlayerCharacter( unit )

Returns the character closest to the unit.

Parameters:

Name Type Description
unit Unit The unit.

Returns:

Type Description
Character The character.

getClosestVisibleTeamOpponent

sm.ai.getClosestVisibleTeamOpponent( unit, color )

Returns the character, with an opposing color, closest to the unit.

Parameters:

Name Type Description
unit Unit The unit.
color Color The color.

Returns:

Type Description
Character The character.

getRandomCreationPosition

sm.ai.getRandomCreationPosition( body )

eturns a random position on a given body.

Parameters:

Name Type Description
body Body The body.

Returns:

Type Description
Vec3 The position.

isReachable

sm.ai.isReachable( unit, position )

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

Parameters:

Name Type Description
unit Unit The unit.
position Vec3 The target position.

Returns:

Type Description
boolean Returns true if the position is reachable.