summaryrefslogtreecommitdiff
path: root/src/object/cloud.c
blob: c55e0d579e24b27edc607671e424713913bcce43 (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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#include "global.h"
#include "entity.h"
#include "room.h"
#include "link.h"
#include "flags.h"

extern void sub_0809F7BC(Entity*);
extern void PlaySFX(u32);
extern void sub_0809F814(u32);
extern void sub_0809F7F4(Entity*);
extern void LoadRoomEntityList();
extern void DeleteThisEntity();
extern u32 CheckRoomFlag(u32);
extern void sub_08078A90(u32);
extern void sub_08078B48(void);
extern u32 Random(void);
extern void sub_0806F69C(Entity*);
extern void (*gUnk_08124798[])(Entity*);
extern void (*gUnk_081247A0[])(Entity*);
extern void (*gUnk_081247AC[])(Entity*);
extern Entity* CreateObject(u32, u32, u32);
extern void PositionEntityOnTop(Entity*, Entity*);
extern void sub_0807BB68(u32*, u32, u32);

extern u8 gUnk_02034490;
extern u32 gUnk_030010A0;
extern void* gUnk_080DD750;
extern Entity gLinkEntity;
extern LinkState gLinkState;
extern u8 gUnk_081247C0[];
extern u16 gUnk_081247C8[];
extern u32 gUnk_081247D0;

void Cloud(Entity* this) {
    gUnk_08124798[(this->entityType).form](this);
}

void sub_0809F4DC(Entity* this) {
    if ((this->entityType).parameter == 0) {
        gUnk_081247A0[this->action](this);
    } else {
        gUnk_081247AC[this->action](this);
    }
}

void sub_0809F514(Entity* this) {
    this->action = 1;
    this->actionDelay = 120;
    this->spriteSettings.b.draw = 0;
    *(u8*)&this->field_0x68 = 12;
    gRoomControls.cameraTarget = this;
    gUnk_02034490 = 255;
    sub_0809F7BC(this);
}

void sub_0809F548(Entity* this) {

    if (--this->actionDelay == 0) {
        this->action = 2;
        this->actionDelay = 90;
        PlaySFX(285);
        sub_0809F814((((this->x.HALF.HI - gRoomControls.roomOriginX) >> 4) & 63) |
                     (((this->y.HALF.HI - gRoomControls.roomOriginY) >> 4) & 63) << 6);
    } else {
        if ((gUnk_030010A0 & 7) == 0) {
            sub_0809F7BC(this);
        }
        sub_0809F7F4(this);
    }
}

void sub_0809F5B0(Entity* this) {
    if (--this->actionDelay == 0) {
        PlaySFX(115);
        SetGlobalFlag(KUMOTATSUMAKI);
        LoadRoomEntityList(&gUnk_080DD750);
        DeleteThisEntity();
    }
}

void sub_0809F5DC(Entity* this) {
    this->action = 1;
    this->spriteSettings.b.draw = 0;
    *(u8*)&this->field_0x68 = 12;
}

void sub_0809F5F0(Entity* this) {
    u32 iVar1;

    iVar1 = CheckRoomFlag(this->actionDelay);
    if (iVar1 != 0) {
        this->action = 2;
        this->actionDelay = 120;
        sub_08078A90(3);
        sub_08078B48();
        gRoomControls.cameraTarget = this;
    }
}

void sub_0809F61C(Entity* this) {

    if ((gRoomControls.unk6 & 4) == 0) {
        if (this->actionDelay == 30) {
            SetLocalFlag(this->entityType.parameter);
        }
        if (--this->actionDelay == 0) {
            this->action = 3;
            this->actionDelay = 120;
            PlaySFX(285);
            sub_0809F814((((this->x.HALF.HI - gRoomControls.roomOriginX) >> 4) & 63) |
                         (((this->y.HALF.HI - gRoomControls.roomOriginY) >> 4) & 63) << 6);
        } else {
            if ((gUnk_030010A0 & 7) == 0) {
                sub_0809F7BC(this);
            }
            sub_0809F7F4(this);
        }
    }
}

void sub_0809F69C(Entity* this) {

    if (--this->actionDelay == 0) {
        this->actionDelay = 30;
        this->action = 4;
        gRoomControls.cameraTarget = &gLinkEntity;
        PlaySFX(115);
    }
}

void sub_0809F6CC(Entity* this) {

    if (((gRoomControls.unk6 & 4) == 0) && (--this->actionDelay == 0)) {
        gLinkState.field_0x8b = 1;
        DeleteThisEntity();
    }
}

void sub_0809F700(Entity* this) {
    u8 bVar1;
    u32 uVar2;

    if (this->action == 0) {
        this->action = 1;
        this->actionDelay = (Random() & 30) + 8;
        this->flags = this->flags | 12;
    }
    if ((gUnk_030010A0 & 3) == 0) {
        uVar2 = Random();
        this->spriteOffsetX = gUnk_081247C0[uVar2 & 7];
        this->spriteOffsetY = gUnk_081247C0[uVar2 >> 4 & 7];
    }
    sub_0806F69C(this);
    if (--this->actionDelay == 0) {
        DeleteThisEntity();
    }
}

#ifdef NON_MATCHING
Entity* sub_0809F770(Entity* this) {
    Entity* cloud;
    s32 uVar1;

    cloud = CreateObject(163, 1, 0);
    if (cloud != NULL) {
        PositionEntityOnTop(this, cloud);
        uVar1 = Random();
        cloud->x.HALF.HI = ((cloud->x.HALF.HI - 16) + (uVar1 >> 0)) & 31;
        cloud->y.HALF.HI = ((cloud->y.HALF.HI - 16) + (uVar1 >> 8)) & 31;
        cloud->animationList = (u8)(uVar1 >> 16) & 3;
        cloud->direction = 255;
    }
    return cloud;
}
#else
NAKED
Entity* sub_0809F770(Entity* this) {
    asm(".include \"asm/non_matching/cloud/sub_0809F770.inc\"");
}
#endif

void sub_0809F7BC(Entity* this) {
    Entity* cloud;
    u32 uVar1;
    u32 uVar2;

    for (uVar2 = 0; uVar2 < 8; uVar2++) {
        cloud = sub_0809F770(this);
        if (cloud != NULL) {
            uVar1 = Random();
            cloud->nonPlanarMovement = gUnk_081247C8[uVar1 & 3];
            cloud->direction = (u8)(uVar1 >> 8) & 31;
        }
    }
}

void sub_0809F7F4(Entity* this) {
    u8 cVar1;
    u8* puVar2;

    puVar2 = (u8*)&this->field_0x68;
    *puVar2 -= 1;

    if (*puVar2 == 0) {
        *puVar2 = 12;
        PlaySFX(388);
    }
}

void sub_0809F814(u32 r0) {
    sub_0807BB68(&gUnk_081247D0, r0, 1);
}