Space Engineers

Space Engineers

[APck] AutoPillock Core 1.0
cheerkin  [developer] 12 Feb, 2024 @ 2:13pm
Engineer guide (conditions and shifters)
This is tier-3 difficulty so I decided to call it Engineer guide. You are comfortable with simple usage and understand how to build APck agents, now you probably want to use the system to its full potential.



Condition checks & triggers

You can add a Condition to be tested during specific task. This is the way to dynamically alter agent behavior based on circumstances.
Coupled with Shifters, this allow you to make things like single-trhuster missile equipped with fixed guns, that can dive on top of target shooting and dropping payload, then returning back, making drones that launch missiles with certain chance and alter their combat style on the fly, and stuff like that.

Format: command:add-condition:{task-kind aka type}:{interval?}:{cooldown?}:{check1}&{check2?}&{checkN?}:{command|toggle}:{the rest is usual command tail}|{command2}...|{commandN}

  • task-kind aka type: thing what you see in the log, like "move", "attack", etc (see at the bottom part of this guide). Additionally, response states are accepted here (FreeFiring|Attacking).
  • interval: optional, default is 300, how often the check is performed (in ticks). 300 ticks is 5 seconds
  • cooldown: optional, if a check is passed, then the next check would be postponed by this value in ticks, set to high value to stop the check from happening after first trigger (e.g. changing behavior at terminal missile attack stage)
  • check: {check type}{operator}{value}, e.g. targetSize<20. Can be combined with & symbol to act as AND gate.
  • after that, the rest of the line is treated like a normal command with appropriate parameters separated by ':'

Possible conditions for now:
  • targetType - type of current (SmallGrid, LargeGrid, CharacterHuman, Planet, Missile, etc). E.g. targetType=LargeGrid
  • rnd - random number from 0 to 1. E.g. rnd<0.8 means 80% chance
  • targetSize - target bounding box extents
  • distance - distance to current target (waypoint, dock, etc)
  • rc-distance - does raycast towards target point and returns that distance, needs camera
  • dot - dot product between direction to target and forward vector [-1, 1]. 1 means perfect alignment, 0 is perpendicular, -1 is opposite
  • targetVelocity - target velocity (can be velocity of connector during docking task, same with wingman task, etc)
  • blockEnabled - checks if block is on or off. E.g. blockEnabled=my_customname_tag
  • taskElapsedTicks - ticks elaped since the start of current task (actual start, not creation, this is different)
  • custom-val - tests against "custom-val" variable (you can set that with command:set-value:custom-val:100). E.g. custom-val>100
  • toggle - tests toggle, passes if said toggle is in "true" state. E.g. toggle=vtol-hybrid
  • alt - checks altidude above surface, always false in zero-g
  • ng - checks natural gravity magnitude
  • climb-rate - checks velocity projection on gravity vector, i.e. how fast an agent gains or loses altitude, always false in zero-g

Example
command:add-condition:attack:targetSize>10&targetType=SmallGrid&rnd<0.2:command:wb-range-override:100
- if the target is small grid larger that 10m, set combat range to 100m with 20% chance. Since tests are commited each 5 seconds, we can assume that an agent would go point blank in about half a minute, or if we have five agents attacking, when one of them would go point blank immediately (statistically speaking)

Example
command:add-condition:attack:rnd>0:command:wb-cycle-face
- cycle WeaponFace every 5 seconds to make gun-kata-style drone

Example
command:add-condition:attack:5:3600:distance<1200:command:set-value:sp-limit:1000|toggle:allow-1t-up-shifter:false
- during attack task, every 5 seconds check distance to target, if it is less than 1200, the condition goes to 3600 cooldown, and two actions are applied ("command:set-value:sp-limit:1000" and "toggle:allow-1t-up-shifter:false")



Position Shifters aka Behaviors

These are named pieces of code that transform input vector (target position) into another vector (shifted position). For example, you may want to add circling to your flight trajectory, or make aimpoint "sway" left/right to spread fire over a big target. All shifters can be "chained" to make a series of transformations. E.g. default close combat task uses a chain like this: AdjustOrbit=>OrbitPoint=>RepelGround=>MakeAxis=>Sin, which roughly means "select some altitude along up axis and orbit around that point, but not too low to the ground, and also add a phase offset (sin(t)) on top of that".

Since default attack task has this chain preset for move channel, you need to clear that if you want to make a missile.
This can be done with this command: command:replace-behavior-task:attack:move:Empty (meaning, for each following attack task erase the move shifter chain), which would make an agent fly straight to target intercept point.

channel is "move", "aim" or "up". Move is a point where agent moves, aim is for aiming (usually yaw/pitch), up - alignment for Up vector of the refence block (usually defines roll). For example, during attack task without any shifters, move point is an interception point (meaning it would collide with the target if they both continue moving with their current velocities), and aim point is just a target position. By default, attack task attaches BallisticSolver shifter, which alters aimpoint to a fire solution for current active weapon group.

Commands:
  • replace-behavior-task:{task kind}:{channel}:{behavior id} - ignores default task transformation* and works with raw target point, applying shifter(s) for all upcoming tasks of that kind (e.g. attack)
  • replace-behavior-current:{channel}:{behavior id} - ignores default task transformation and works with raw target point, applying shifter(s) just for current task instance, cancels itself after task completion
  • chain-behavior-task:{task kind}:{channel}:{behavior id} - appends shifter(s) to the result of default task transformation (for all upcoming tasks of that kind)
  • chain-behavior-current:{channel}:{behavior id} - appends shifter to the result of current task instance transformation, next time a new task of the same kind would have initial behavior chain again
*certain task types have embedded transformation of input point by default, e.g. attack task aim channel takes target data and outputs a target lead point for current active weapon (BallisticSolver), while move channel has internal sequence of transformations (described in the begginning of this section)

Some behaviors can make use of one floating point argument parameter (optional) which needs to be separated with a slash in command line. E.g. ...replace-behavior-task:attack:aim:SwayTargetXYZ/10 (move aimpoint along the largest target axis projection in 10m value range).

Command mentioned above overwrite, i.e. only the last one is in effect. If you want a chain of transformations, combine them into comma-separated line like this: command:chain-behavior-task:attack:aim:AngularOffsetX/-0.35,AngularOffsetY/-0.2



Behaviors reference

AimRestrictPlane - works in gravity, prevents tilting and elevation by projecting aimpoint to the plane parallel to the ground (i.e. always on horizon), useful for massive ships with not enough thrust.

BallisticSolver - fixed and custom guns work through this, it is the entry point for weapon bot, it caclulates intercept point for current active weapon and returns that point.

SwayTargetXYZ - time-based floating offset along the longest target axis pojection (i.e. tries to spread the fire over area, picking the largest facing orientation of a target). Param: maximum offset length, default - half of targets' bounding box.

SwayX - time-based floating offset Left/Right in the agent coordinate system (i.e. yaw). Param: maximum offset length, default 30m.

SwayY - time-based floating offset Up/Down in the agent coordinate system (i.e. pitch). Param: maximum offset length, default 30m.

CircleFw100 - time-based floating circular offset, 100m front. Param: circle radius, default 30m.

CircleTgPlane - time-based floating circular offset in target plane. Param: circle radius, default 30m.

Empty - replacer that just returns input position, used to clear default chain for certain tasks.

NegGravity - opposite of natural gravity, used for "up" channel (shift relative to agent position rather than target). Param: length of the offset, default 1.

NegGravityRejectTilt - opposite of natural gravity and tilts opposite to side velocity for better compensation. Used for "up" channel. Used by default for attack tasks in gravity. Param: tilt muiltiplier.

Closer - shift the point closer to the agent. Param: length of the offset, default 1.

Higher - shift the point higher (no effect outside of gravity). Param: length of the offset, default 1.

CqbShifter - combination of several shifters, used for "move" point in attack tasks by default. You need to replace this for missile kind of agents.

OrbitPoint - position-based float around target point. Param: desired distance to point, default 500m. On planets adjusts altitude while trying to keep the desired distance.

AngularOffsetX - angular offset in target plane, Left/Right in the agent coordinate system. Param: angle in radians, default 0.

AngularOffsetY - angular offset in target plane, Up/Down in the agent coordinate system. Param: angle in radians, default 0.

AngularOffsetV - angular offset in target plane along target velocity. Param: angle in radians, default 0. Useful for altering interception trajectory for head-on impact or chasing.

AngularOffsetNg - angular offset in target plane along natural gravity. Param: angle in radians, default 0. Useful for altering interception trajectory, i.e. top-down attacks for missiles or dive bombers.



Target Queries

Target query is pro-active target acquisition (opposed to awareness mechanism, which picks targets from global "target advertisement channel").

command:query-target:{target source}:{filters}:{callback}

Example (asks apck agents and TGPs for any targets within 3000m radius around the agent, pick the closest of matched, instructs them to send create attack task with appropriate id)
command:query-target:tgp.local.gridsense.update:TargetSelection=Closest,LocationFilter=Sphere,R=3000:command:create-task:attack:TargetId={id}

Example (asks apck agents and TGPs for any targets within 3000m radius around the (10000:0:0) gps point, picks the first matched (no TargetSelection specified), instructs them to send "command:callback")
command:query-target:tgp.local.gridsense.update:LocationFilter=Sphere,R=3000,Pos=10000;0;0:command:callback

Example (queries apck agents with Dockable flag within 0.5rad forward cone, instructs to call back with a docking task creation). This can be used to quickly autodock the ship you fly to compatible apck dock host.
command:query-target:apck-position:LocationFilter=Cone,R=0.5,TypeFilter=Dockable:command:create-task:dock:TargetId={id}

{target source} is the IGC channel tag of targeting provider

  • apck-position - "friendly" channel, apck agents emit their telemetry there
  • tgp.local.gridsense.update - "enemies" channel, targeting data from AI turrets managed by APck and TGP go there, along with raycast tracking and such

{filters} are comma delimeted key-value pairs.

TargetSelection - which target to pick by order
  • First - stop checking targets immediately when found appropriate one
  • Closest - sorts all matched targets by distance and picks the nearest
  • Random - picks a random target from matched
  • Loop - has a looped indexer which increments for every target subscription, thus distributing targets evenly

LocationFilter - area to consider
  • Sphere - optional params: R - radius (default - "awareness-range" value), Pos - center of the sphere (default - agents' current position) - note that X Y Z are separated with ; rather than :
  • Cone - required param: R - cone angle

TypeFilter
  • For hostile targets channel - detected entity type (MyDetectedEntityType) - SmallGrid, LargeGrid, CharacterHuman, etc
  • For friendly targets channel - "Dockable" (checks if connectors dock-host are present) and agent custom tag (see user/builder guide).

{callback} is a usual apck command tail
When calling back, target provider is able to substitude {id} placeholder with and actual target id there, as long as subsribing the agent to that target.
Generally there are few cases when you would use callback without {id}, i.e. command:set-response:FreeFire
Last edited by cheerkin; 18 Sep, 2024 @ 8:54am