summaryrefslogtreecommitdiff
path: root/src/npc.c
blob: 67f70a3d7df5e87f33f871d5013f605f18ae6fdf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "global.h"
#include "entity.h"
#include "room.h"
#include "npc.h"
#include "flags.h"

extern u32 gUnk_020342F8;

extern void InitNPC(Entity*);

void NPCUpdate(Entity* this) {
    u32 health = this->health;
    u32 temp;
    if ((health & 0x7f) && !ReadBit(&gUnk_020342F8, health - 1))
        DeleteThisEntity();
    if (this->action == 0 && (this->flags & ENT_DID_INIT) == 0)
        NPCInit(this);
    if (!EntityDisabled(this))
        gNPCFunctions[this->id][0](this);
    if (this->next != NULL) {
        if (gNPCFunctions[this->id][1] != NULL)
            gNPCFunctions[this->id][1](this);

        if (this->health % 0x80) { // If this NPC was created by DelayedEntityLoadManager_Main, we need to update the
                                   // location in gNPCData.
            NPCStruct* npc = gNPCData;
            npc += (this->health - 1);
            npc->x = this->x.HALF.HI - gRoomControls.origin_x;
            npc->y = this->y.HALF.HI - gRoomControls.origin_y;
        }
        DrawEntity(this);
    }
}