TF2-DMB / CBaseNPC

Provides a friendly interface for plugins to use in order to create custom NPCs on the game Team Fortress 2
36 stars 5 forks source link

Add CBaseEntity-based typedefs to typesets #28

Closed KitRifty closed 2 years ago

KitRifty commented 2 years ago

No extension changes. This adds typedefs to typesets containing entity index parameters replaced with a CBaseEntity (or derived) methodmap parameter.

The main motivation behind this is to eliminate the need to cast from an entity index to a custom entity methodmap in a callback, which can happen a lot when it comes to NextBotAction callback functions. These typesets takes advantage of methodmap "inheritance", where it is valid to specify a methodmap that "inherits" from the methodmap parameter in the typedef.

The original typedefs have not changed for backwards compatibility.

As a result, we can now reduce this:

static int OnStart(NextBotAction action, int actor, NextBotAction prevAction)
{
    TestScoutBot ent = TestScoutBot(actor);

    int sequence = ent.LookupSequence( "taunt_laugh" );
    if (sequence == -1)
    {
        return action.Done();
    }

    // ...

    return action.Continue();
}

To this:

static int OnStart(TestScoutBotLaughAction action, TestScoutBot actor, NextBotAction prevAction)
{
    int sequence = actor.LookupSequence( "taunt_laugh" );
    if (sequence == -1)
    {
        return action.Done();
    }

    // ...

    return action.Continue();
}