summaryrefslogtreecommitdiff
path: root/src/object/carlovObject.c
blob: 00536c0b006f9f3a7c93ab60d5e77993bf1d812e (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/**
 * @file carlovObject.c
 * @ingroup Objects
 *
 * @brief Carlov Object object
 */
#include "object/lockedDoor.h"
#include "object.h"
#include "asm.h"
#include "sound.h"
#include "flags.h"
#include "effects.h"
#include "room.h"
#include "physics.h"
#include "player.h"
#include "tiles.h"

typedef struct {
    /*0x00*/ Entity base;
    /*0x68*/ u8 unk_68[8];
    /*0x70*/ u16 unk_70;
    /*0x72*/ u16 unk_72;
    /*0x74*/ u16 unk_74;
    /*0x76*/ u16 unk_76;
} CarlovObjectEntity;

extern void sub_080836DC(Entity*, u32, u32); // lockedDoor
extern void sub_08083814(Entity*, u32);      // lockedDoor
void CarlovObject_Type0(CarlovObjectEntity*);
void CarlovObject_Type1(CarlovObjectEntity*);
void CarlovObject_Type2(CarlovObjectEntity*);
void CarlovObject_Type0Init(CarlovObjectEntity*);
void CarlovObject_Type0Action1(CarlovObjectEntity*);
void CarlovObject_Type0Action2(CarlovObjectEntity*);
void CarlovObject_Type1Init(CarlovObjectEntity*);
void CarlovObject_Type1Action1(CarlovObjectEntity*);
void CarlovObject_Type1Action2(CarlovObjectEntity*);
void CarlovObject_Type1Action3(CarlovObjectEntity*);
void CarlovObject_Type1Action4(CarlovObjectEntity*);
void CarlovObject_Type1Action5(CarlovObjectEntity*);
void CarlovObject_Type2Init(CarlovObjectEntity*);
void CarlovObject_Type2Action1(CarlovObjectEntity*);

void CarlovObject(CarlovObjectEntity* this) {
    static void (*const CarlovObject_Types[])(CarlovObjectEntity*) = {
        CarlovObject_Type0,
        CarlovObject_Type1,
        CarlovObject_Type2,
    };
    CarlovObject_Types[super->type](this);
}

void CarlovObject_Type0(CarlovObjectEntity* this) {
    static void (*const CarlovObject_Type0Actions[])(CarlovObjectEntity*) = {
        CarlovObject_Type0Init,
        CarlovObject_Type0Action1,
        CarlovObject_Type0Action2,
    };
    CarlovObject_Type0Actions[super->action](this);
}

void CarlovObject_Type0Init(CarlovObjectEntity* this) {
    super->action = 2;
    super->type2 = 2;
    super->collisionLayer = 2;
    UpdateSpriteForCollisionLayer(super);
    super->spritePriority.b0 = 1;
    super->timer = -76;
    InitializeAnimation(super, super->type2);
}

void CarlovObject_Type0Action1(CarlovObjectEntity* this) {
    s8 tmp;
    GetNextFrame(super);
    if (--super->timer == 0) {
        super->timer = -76;
        super->type2++;
        tmp = 3;
        super->type2 %= tmp;
        InitializeAnimation(super, super->type2);
    }
}

void CarlovObject_Type0Action2(CarlovObjectEntity* this) {
    GetNextFrame(super);
}

void CarlovObject_Type1(CarlovObjectEntity* this) {
    static void (*const CarlovObject_Type1Actions[])(CarlovObjectEntity*) = {
        CarlovObject_Type1Init,    CarlovObject_Type1Action1, CarlovObject_Type1Action2,
        CarlovObject_Type1Action3, CarlovObject_Type1Action4, CarlovObject_Type1Action5,
    };
    CarlovObject_Type1Actions[super->action](this);
    gPlayerState.mobility |= 0x80;
}

void CarlovObject_Type1Init(CarlovObjectEntity* this) {
    super->speed = 0x300;
    super->frameIndex = 0;
    this->unk_70 = super->x.HALF.HI;
    this->unk_72 = super->y.HALF.HI;
    super->spritePriority.b0 = 5;
    this->unk_76 = COORD_TO_TILE(super);
    this->unk_74 = GetTileIndex(this->unk_76, super->collisionLayer);
    if (super->timer == 0) {
        super->action = 1;
        super->subtimer = 120;
        SetTile(SPECIAL_TILE_34, this->unk_76, super->collisionLayer);
    } else {
        super->action = 3;
        super->spriteSettings.draw = 0;
        super->spriteSettings.flipY = 1;
        super->timer = 0;
    }
}

void CarlovObject_Type1Action1(CarlovObjectEntity* this) {
    if (CheckRoomFlag(0)) {
        super->action = 2;
        super->timer = 7;
        super->direction = 0;
        SetTile(this->unk_74, this->unk_76, super->collisionLayer);
        EnqueueSFX(SFX_10B);
    }
}

void CarlovObject_Type1Action2(CarlovObjectEntity* this) {
    LinearMoveUpdate(super);
    if (--super->timer == 0) {
        super->action = 5;
        super->timer = 8;
        super->spriteSettings.draw = 0;
        super->x.HALF.HI = this->unk_70;
        super->y.HALF.HI = this->unk_72;
    }
}

void CarlovObject_Type1Action3(CarlovObjectEntity* this) {
    if (sub_08083734(super, 2)) {
        super->action = 4;
        sub_080836DC(super, 2, this->unk_76);
    }
}

void CarlovObject_Type1Action4(CarlovObjectEntity* this) {
    LinearMoveUpdate(super);
    if (--super->timer == 0) {
        super->action = 5;
        sub_08083814(super, 2);
        EnqueueSFX(SFX_10B);
        SetTile(SPECIAL_TILE_34, this->unk_76, super->collisionLayer);
    }
}

void CarlovObject_Type1Action5(CarlovObjectEntity* this) {
}

void CarlovObject_Type2(CarlovObjectEntity* this) {
    static void (*const CarlovObject_Type2Actions[])(CarlovObjectEntity*) = {
        CarlovObject_Type2Init,
        CarlovObject_Type2Action1,
    };
    CarlovObject_Type2Actions[super->action](this);
}

void CarlovObject_Type2Init(CarlovObjectEntity* this) {
    super->action = 1;
    super->timer = 16;
    super->z.HALF.HI -= 0x10;
    if (super->type2 == 0) {
        super->frameIndex = 2;
    } else {
        super->frameIndex = 0;
        if (((super->parent)->x.HALF.HI & 0x10) != 0) {
            super->frameIndex = 1;
        }
    }
    CreateDeathFx(super);
}

void CarlovObject_Type2Action1(CarlovObjectEntity* this) {
    if (--super->timer == 0) {
        DeleteThisEntity();
    }
}