summaryrefslogtreecommitdiff
path: root/src/object/object63.c
blob: 8557fb2fdead15ae6a58ae7ab06e3d19ad9ea4ed (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
/**
 * @file object63.c
 * @ingroup Objects
 *
 * @brief Object63 object
 */
#include "object.h"
#include "physics.h"
#include "item.h"

void Object63_Init(Entity*);
void Object63_Action1(Entity*);
void Object63_Delete(Entity*);
void sub_08093E10(Entity*, Entity*);

void Object63(Entity* this) {
    static void (*const Object63_Actions[])(Entity*) = {
        Object63_Init,
        Object63_Action1,
        Object63_Delete,
    };

    Object63_Actions[this->action]((Entity*)this);
}

void Object63_Init(Entity* this) {
    Entity* objEnt;

    this->action = 1;
    this->z.HALF.HI -= 8;
    this->zVelocity = Q_16_16(2.625);
    this->timer = 32;
    switch (this->type) {
        case 0:
            if (CreateRandomItemDrop(this, 4) == 0) {
                this->action = 2;
            }
            this->child->zVelocity = this->zVelocity;
            break;
        case 1:
            objEnt = CreateObject(0, OBJECT_BLOCKING_STAIRS, 0);
            if (objEnt != NULL) {
                objEnt->timer = 5;
                sub_08093E10(this, objEnt);
            }
            break;
    }
}

void Object63_Action1(Entity* this) {
    if (--this->timer == 0) {
        this->action = 2;
    }

    if ((this->timer & 1) != 0) {
        this->child->y.HALF.HI++;
    }
}

void Object63_Delete(Entity* this) {
    DeleteEntity(this);
}

void sub_08093E10(Entity* this, Entity* ent) {
    CopyPosition(this, ent);
    ent->parent = this;
    this->child = ent;
    ent->zVelocity = this->zVelocity;
}