Plan for queueable attacks

From OHRRPGCE-Wiki
Jump to navigation Jump to search

This plan is done. nightly builds starting with 2010-09-30 have support for the attack queue.


Previously, each hero and enemy could have only one attack selected at a time. Attacks could be chained together with a delay, but the hero (or enemy) could not act while the chain was in progress.

It should be possible have an attacker queue an attack with a delay that does not interrupt their normal actions. For example, a time-limited stat-boost could do a queued chain to an attack that removes the stat boost after a certain number of ticks has passed, while allowing the attacker to continue to do other attacks in the meantime.

The way things work now[edit]

Each attacker has a turn counter and a delay counter. When the turn counter is full, they can choose and target an attack. Each attacker has a data member for the attack they are currently doing, and a list of targets for the current attack. Then the delay counter starts. When it is finished, the attack animates. If a chain occurs, it gets loaded, and the delay counter starts again. When no more chains are going to happen, the turn counter starts over.

The way things should work[edit]

Ideally, each attacker could have a growable list of perpared attacks and targets, each with data for whether or not they should block the start of the attacker's next turn.

But FreeBasic doesn't have a data structure that can do that, and I don't want to hack it together with pointers.

Another decent way of doing it[edit]

Maintain a list of queued attack data. It would include data for which attack, which targets, and which attacker is doing the attack, as well as data for whether or not it blocks their next turn.

  • Create an AttackQueue object (done)
    • who's attack
    • attack id
    • target list
    • normal/nonblocking attack
    • queue slot in use (for recycling them)
  • Create an array of AttackQueues (done)
  • Make code for adding a targeted attack to the queue (done)
    • recycle an empty slot if possible, otherwise resize the array (done)
  • Make code to search the attack queue for attacks belonging to a given attacker (done)
    • Make code to check if an attacker has any blocking attacks queued (done)
  • Make battle system use AttackQueues instead of the .attack and .t() members of bslot() (done)
    • Note: this step is hard! Massive battle code cleanup required to make this work without breaking anything. (wasn't as bad as I feared)
    • Special care should be taken with animation building code, which will now need to work with the queue when determining the attacker to animate. (done)
  • Make sure everything works the way it did before (tested)
  • Maybe remove .attack and .t() from battleslot? (done)
    • Does it make sense to keep them just for interactive targeting? (yes for .attack, no for .t())
    • Perhaps targeting should continue to use bslot() right up until the target is finalized, at which point the targeted attack gets copied into the attack queue (pretty much, yes)
  • Add support for non-blocking attacks (done)
    • Not only should non-blocking attacks not block other actions wile their delay counter is going, they also should not reset the attacker's turn counter when the attack animates. (no, wrong!)

Also, it would probably be constructive to add a debug tool to visualize the attack queue. (done, press F11 twice)

Other Uses[edit]

Having an attack queue implemented would make real counterattacks a snap to implement. (in progress)