this week was a short one due to valborg here.

Munition triggers

we want munitions to be capable of various actions driven by the player. some examples of what the player should be able to make:

  • flak
    • rounds that explode in air after N seconds or within proximity
  • shaped rounds
    • rounds that dont explode on impact, but instead explode when another part of the munition hits the target
  • guidance systems
    • change the round trajectory of the round up or down by some nº based on where the target was on firing
  • cluster munitions
    • at distance x, unweld from peers
  • hybrid rockets
    • when speed below x, engage rocket system

but we want to have the smallest instruction set possible. what are these instructions and how do we handle them?

the process i ended up making was essentially a callback on event loop. it works like so

  1. a projectile has a bunch of events that it issues. eg
    1. block is destroyed
    2. fly for n seconds
    3. fly n meters
    4. impact something
    5. get within n meters of something
    6. reach speed x
    7. reach rotation xº
    8. front is aligned with something (ie targeting reticule)
    9. signal received
    10. electrical impulse recieved
  2. each component has a number of events that it can react to. for example an explosive block listens for block destroyed.

Then the loop during flight

  1. when a projectile reaches a given milestone, it issues an event. lets take block destroyed when it impacts something.
  2. each component of the projectile listens for those events.
  3. when that event is received, each component checks if it has a reaction accordingly. such as our explosive block above would react to itself being destroyed
  4. the block then places its reaction request into an event queue inside the projectile entity
  5. the projectile sorts these then just works its way down until all events are clear or no longer valid

An example

  1. A munition made of an altitude trigger configured for 500m and an explosive is fired at a flying target
  2. the munition flies along calling the altitude trigger every 5 meters of height (resolution variable)
  3. when the altitude trigger detects an alt of 500m, it issues an electrical impulse event to all of its neighbours
  4. this event goes in the queue, but the only valid neighbour is the explosive block
  5. the explosive block is listening for an electrical impulse and adds an explode event to the queue
  6. the explosive event is called, detonating the projectile and (possibly) destroying the target with shrapnel

This gives us a pretty open slate to add novel reactions to blocks that can be combined easily.