Skip to content

Defensive AI

Tom Sherman edited this page Mar 7, 2017 · 8 revisions

Previous Section: Recovery

Overview

Example

The final step is to make the AI act out of hitstun.

Acting Out of histun

First we define the function that adds the double jump to the AI.

void actOutOfHitstun(AI* ai)
{
    doubleJump(ai, -40.f);
    resetAfterFrameLogic.condition.arg1.u = CURRENT_FRAME + 10;
    addLogic(ai, &resetAfterFrameLogic);
    addLogic(ai, &onLedgeLogic);    
    addLogic(ai, &resetOnHitLogic);
    addLogic(&cpuPlayer, &recoveryLogic);
}

The AI tries to jump near the middle of the stage. If no other conditions are met, it resets after 10 frames.

In order to call this function, we need to set up a certain amount of delay.

void exitHitstun(AI* ai)
{
    float minDelay = 20 - 2 * _gameState.playerData[ai->port]->aiLevel;
    u32 delay = (u32) uniform(minDelay, minDelay + 5.f);

    actOutOfHitstunLogic.condition.arg1.u = CURRENT_FRAME + delay;
    addLogic(ai, &actOutOfHitstunLogic);

    ...

The delay ranges anywhere from 23 frames to 2 frames. While the AI is waiting this many frames it is left tumbling in hitstun, thus there are quite a few logic rules we need to account for:

    addLogic(ai, &onLedgeLogic);    
    addLogic(ai, &resetOnHitLogic);
    addLogic(ai, &resetOnWaitLogic);
    addLogic(ai, &resetOnGroundLogic);
    addLogic(ai, &resetOnDeathLogic);
    addLogic(&cpuPlayer, &hitTechLogic);
    addLogic(&cpuPlayer, &recoveryLogic);

Creating the Program

hitstun.c contains most of the new code in this program.

The full code is here. Run the standard wiimake command to build the iso.

Possible Expansions

  • add more options
  • add character specific options (e.g. shine)

Continuing on Your Own

Now that this tutorial is finished, I hope you understand the library enough to get started on your own mods!