summaryrefslogtreecommitdiff
path: root/src/object/enemyItem.c
blob: b44b85b9fad70bd2a88af22b43e87027948d8b3c (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
 * @file enemyItem.c
 * @ingroup Objects
 *
 * @brief Enemy Item object
 */
#include "scroll.h"
#include "object.h"
#include "flags.h"
#include "physics.h"
#include "item.h"

typedef struct {
    /*0x00*/ Entity base;
    /*0x68*/ u8 unk_68[0x1e];
    /*0x86*/ u16 flag;
} EnemyItemEntity;

void sub_080A2500(EnemyItemEntity*);
void sub_080A2534(EnemyItemEntity*);
void sub_080A2508(EnemyItemEntity*);

void EnemyItem(EnemyItemEntity* this) {
    Entity* entity;
    LinkedList* list;

    if (CheckFlags(this->flag)) {
        sub_080A2500(this);
    }
    if (super->action == 0) {
        super->action++;
        super->type = super->timer;
        super->child = NULL;
        list = &gEntityLists[4];
        for (entity = list->first; entity != (Entity*)list; entity = entity->next) {
            if ((((entity->kind == 3) && (super->type2 == entity->id)) &&
                 (((entity->x.HALF.HI - super->x.HALF.HI) + 0x10U) << 0x10 >> 0x10 < 0x20)) &&
                (((entity->y.HALF.HI - super->y.HALF.HI) + 0x10U) << 0x10 >> 0x10 < 0x20)) {
                super->child = entity;
                break;
            }
        }
        if (super->child == NULL) {
            sub_080A2534(this);
        }
        DisableRandomDrops();
    }
    entity = super->child;
    if (entity != NULL) {
        PositionRelative(entity, super, 0x40000, 0x10000);
        super->z.HALF.HI -= 4;
        if (entity->next == NULL) {
            sub_080A2508(this);
        }
    }
    sub_08080CB4(super);
}

void sub_080A2500(EnemyItemEntity* this) {
    DeleteThisEntity();
}

void sub_080A2508(EnemyItemEntity* this) {
    EnemyItemEntity* entity;

    entity = (EnemyItemEntity*)CreateObjectWithParent(super, GROUND_ITEM, super->type, 0);
    if (entity != NULL) {
        (entity->base).timer = 5;
        entity->flag = this->flag;
    }
    sub_080A2500(this);
}

void sub_080A2534(EnemyItemEntity* this) {
    EnemyItemEntity* entity;

    entity = (EnemyItemEntity*)CreateObjectWithParent(super, GROUND_ITEM, super->type, 0);
    if (entity != NULL) {
        (entity->base).timer = 4;
        entity->flag = this->flag;
    }
    sub_080A2500(this);
}