summaryrefslogtreecommitdiff
path: root/src/d/actor/d_a_player_ladder.inc
blob: 9a806d246e1387deda44d864706bc3948afe8fa1 (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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
/**
 * d_a_player_ladder.inc
 *
 * Code relating to getting on, getting off, and climbing ladders.
 * 
 * This file is not a standalone translation unit and is instead directly 
 * included into d_a_player_main.cpp.
 * 
 * The original name of this file is not known, but a best guess was taken 
 * based on the original names of the functions it contains.
 */

#include "d/dolzel.h" // IWYU pragma: keep
#include "d/actor/d_a_player_main.h"
#include "d/actor/d_a_player_HIO.h"

/* 80132F34-80132F58       .text getLadderMoveAnmSpeed__9daPy_lk_cFv */
f32 daPy_lk_c::getLadderMoveAnmSpeed() {
    return getAnmSpeedStickRate(m_HIO->mLadder.m.field_0x28, m_HIO->mLadder.m.field_0x24);
}

/* 80132F58-80133058       .text setLadderFootSe__9daPy_lk_cFv */
void daPy_lk_c::setLadderFootSe() {
    cXyz local_28(
        current.pos.x + cM_ssin(shape_angle.y) * 50.0f, current.pos.y, current.pos.z + cM_scos(shape_angle.y) * 50.0f
    );

    mLinkLinChk.Set(&current.pos, &local_28, this);
    if (dComIfG_Bgsp()->LineCross(&mLinkLinChk)) {
        mDoAud_seStart(JA_SE_FT_LADDER_CLIMB_D, &current.pos, dComIfG_Bgsp()->GetMtrlSndId(mLinkLinChk), mReverb);
    } else {
        seStartOnlyReverb(JA_SE_FT_LADDER_CLIMB_D);
    }
}

/* 80133058-80133240       .text changeLadderMoveProc__9daPy_lk_cFi */
int daPy_lk_c::changeLadderMoveProc(int param_0) {
    cXyz local_2c;
    cXyz local_38;
    int direction;

    cLib_addCalc(&current.pos.x, m370C.x, 0.5f, 0.5f, 0.05f);
    cLib_addCalc(&current.pos.y, m370C.y, 0.5f, 0.5f, 0.05f);
    cLib_addCalc(&current.pos.z, m370C.z, 0.5f, 0.5f, 0.05f);
    if (mStickDistance > 0.05f) {
        int iVar2 = abs((s16)(m34E8 - shape_angle.y));
        if (iVar2 > 0x3c72 && iVar2 < 0x438e) {
            return false;
        }
        local_2c.x = current.pos.x;
        local_2c.z = current.pos.z;
        if (iVar2 < 0x4000) {
            local_2c.y = 50.0f + (125.0f + current.pos.y);
            direction = DIR_FORWARD;
        } else {
            local_2c.y = current.pos.y - 50.0f;
            direction = DIR_BACKWARD;
        }
        local_38.x = local_2c.x + cM_ssin(shape_angle.y) * 50.0f;
        local_38.z = local_2c.z + cM_scos(shape_angle.y) * 50.0f;
        local_38.y = local_2c.y;
        mLinkLinChk.Set(&local_2c, &local_38, this);
        if (!dComIfG_Bgsp()->LineCross(&mLinkLinChk) || dComIfG_Bgsp()->GetWallCode(mLinkLinChk) != 4) {
            if (iVar2 < 0x4000) {
                procLadderUpEnd_init(param_0);
            } else {
                procLadderDownEnd_init(param_0);
            }
        } else {
            procLadderMove_init(param_0, direction, &m370C);
        }
    }
    return false;
}

/* 80133240-801333A8       .text setMoveBGLadderCorrect__9daPy_lk_cFv */
int daPy_lk_c::setMoveBGLadderCorrect() {
    if (dComIfG_Bgsp()->ChkPolySafe(mPolyInfo)) {
        if (dComIfG_Bgsp()->ChkMoveBG(mPolyInfo)) {
            dComIfG_Bgsp()->MoveBgTransPos(mPolyInfo, true, &current.pos, &current.angle, &shape_angle);
            dComIfG_Bgsp()->MoveBgTransPos(mPolyInfo, true, &m370C, NULL, NULL);
        }
    }
    cXyz local_18(m370C.x + cM_ssin(current.angle.y) * 50.0f, m370C.y, m370C.z + cM_scos(current.angle.y) * 50.0f);
    mLinkLinChk.Set(&m370C, &local_18, this);
    if ((!dComIfG_Bgsp()->LineCross(&mLinkLinChk)) || (dComIfG_Bgsp()->GetWallCode(mLinkLinChk) != 4)) {
        return procFall_init(1, m_HIO->mWallCatch.m.field_0x54);
    } else {
        mPolyInfo = mLinkLinChk;
        return false;
    }
}

/* 801333A8-80133414       .text procLadderUpStart_init_sub__9daPy_lk_cFv */
void daPy_lk_c::procLadderUpStart_init_sub() {
    setSingleMoveAnime(ANM_LADDERUPST, m_HIO->mLadder.m.field_0x4, 0.0f, -1, m_HIO->mLadder.m.field_0x8);
    mProcVar6.m3570 = 1;
    m34C2 = 4;
    dComIfGp_setPlayerStatus0(0, daPyStts0_UNK2000000_e);
}

/* 80133414-8013356C       .text procLadderUpStart_init__9daPy_lk_cFv */
BOOL daPy_lk_c::procLadderUpStart_init() {
    commonProcInit(daPyProc_LADDER_UP_START_e);
    gravity = 0.0f;
    speed.y = 0.0f;
    mNormalSpeed = 0.0f;
    speedF = 0.0f;
    if (mEquipItem == daPyItem_NONE_e) {
        if (checkEquipAnime()) {
            resetActAnimeUpper(UPPER_MOVE2_e, -1.0f);
        }
        procLadderUpStart_init_sub();
    } else {
        setBlendMoveAnime(m_HIO->mBasic.m.field_0xC);
        setAnimeUnequip();
        mProcVar6.m3570 = 0;
        m3598 = 0.0f;
    }
    f32 fVar1 = cM_ssin(m352C);
    f32 fVar2 = cM_scos(m352C);
    current.pos.x = m3724.x + 25.0f * fVar1;
    current.pos.y = m3724.y;
    current.pos.z = m3724.z + 25.0f * fVar2;
    shape_angle.y = m352C + 0x8000;
    current.angle.y = shape_angle.y;
    m370C.x = (m3724.x + fVar1 * 20.5f) - fVar2;
    m370C.y = m3724.y + 37.5f;
    m370C.z = fVar1 + (m3724.z + fVar2 * 20.5f);
    mProcVar2.m34D4 = 0;
    return true;
}

/* 8013356C-80133670       .text procLadderUpStart__9daPy_lk_cFv */
BOOL daPy_lk_c::procLadderUpStart() {
    if (setMoveBGLadderCorrect()) {
        return true;
    }

    if (mProcVar6.m3570 == 0) {
        if (checkNoUpperAnime()) {
            procLadderUpStart_init_sub();
        }
    } else {
        J3DFrameCtrl& frameCtrl = mFrameCtrlUnder[UNDER_MOVE0_e];
        m34C2 = 5;
        if (frameCtrl.getRate() < 0.01f) {
            dComIfGp_setDoStatus(dActStts_LET_GO_e);
            if (mProcVar2.m34D4 == 0) {
                setLadderFootSe();
                mProcVar2.m34D4 = 1;
            }
            if (doTrigger()) {
                m34C2 = 0;
                procFall_init(1, m_HIO->mWallCatch.m.field_0x54);
            } else {
                changeLadderMoveProc(1);
            }
        } else {
            if (frameCtrl.checkPass(9.0f)) {
                setLadderFootSe();
            }
        }
    }
    return true;
}

/* 80133670-80133710       .text procLadderUpEnd_init__9daPy_lk_cFi */
BOOL daPy_lk_c::procLadderUpEnd_init(int param_0) {
    daPy_ANM dVar2;

    commonProcInit(daPyProc_LADDER_UP_END_e);
    if (param_0 != 0) {
        dVar2 = ANM_LADDERUPEDL;
    } else {
        dVar2 = ANM_LADDERUPEDR;
    }
    setSingleMoveAnime(dVar2, m_HIO->mLadder.m.field_0xC, 0.0f, -1, m_HIO->mLadder.m.field_0x10);
    m34C2 = 7;
    gravity = 0.0f;
    speed.y = 0.0f;
    mNormalSpeed = 0.0f;
    speedF = 0.0f;
    dComIfGp_setPlayerStatus0(0, daPyStts0_UNK2000000_e);
    return true;
}

/* 80133710-801337B4       .text procLadderUpEnd__9daPy_lk_cFv */
BOOL daPy_lk_c::procLadderUpEnd() {
    J3DFrameCtrl& frameCtrl = mFrameCtrlUnder[UNDER_MOVE0_e];

    if (setMoveBGLadderCorrect()) {
        return true;
    }

    if (frameCtrl.getRate() < 0.01f) {
        checkNextMode(0);
    } else {
        if (frameCtrl.checkPass(9.0f) || frameCtrl.checkPass(19.0f)) {
            setLadderFootSe();
        }
        m34C2 = 5;
    }
    return true;
}

/* 801337B4-8013384C       .text procLadderDownStart_init_sub__9daPy_lk_cFv */
void daPy_lk_c::procLadderDownStart_init_sub() {
    setSingleMoveAnime(ANM_LADDERDWST, m_HIO->mLadder.m.field_0x14, 0.0f, -1, m_HIO->mLadder.m.field_0x18);
    mProcVar6.m3570 = 1;
    m34C2 = 4;
    dComIfGp_setPlayerStatus0(0, daPyStts0_UNK2000000_e);
    setOldRootQuaternion(0, -0x8000, 0);
    shape_angle.y += 0x8000;
    current.angle.y = shape_angle.y;
}

/* 8013384C-8013399C       .text procLadderDownStart_init__9daPy_lk_cFv */
BOOL daPy_lk_c::procLadderDownStart_init() {
    commonProcInit(daPyProc_LADDER_DOWN_START_e);
    gravity = 0.0f;
    speed.y = 0.0f;
    mNormalSpeed = 0.0f;
    speedF = 0.0f;
    shape_angle.y = m352C + 0x8000;
    current.angle.y = m352C;
    if (mEquipItem == daPyItem_NONE_e) {
        if (checkEquipAnime()) {
            resetActAnimeUpper(UPPER_MOVE2_e, -1.0f);
        }
        procLadderDownStart_init_sub();
    } else {
        setBlendMoveAnime(m_HIO->mBasic.m.field_0xC);
        setAnimeUnequip();
        mProcVar6.m3570 = 0;
        m3598 = 0.0f;
    }
    f32 fVar1 = cM_ssin(m352C);
    f32 fVar2 = cM_scos(m352C);
    current.pos.x = m3724.x + 25.0f * fVar1;
    current.pos.y = m3724.y;
    current.pos.z = m3724.z + 25.0f * fVar2;
    m370C.x = fVar2 + (m3724.x - fVar1 * 30.5f);
    m370C.y = m3724.y - 112.5f;
    m370C.z = (m3724.z - fVar2 * 30.5f) - fVar1;
    return true;
}

/* 8013399C-80133AB8       .text procLadderDownStart__9daPy_lk_cFv */
BOOL daPy_lk_c::procLadderDownStart() {
    if (setMoveBGLadderCorrect()) {
        return true;
    }

    if (mProcVar6.m3570 == 0) {
        if (checkNoUpperAnime()) {
            procLadderDownStart_init_sub();
        }
    } else {
        J3DFrameCtrl& frameCtrl = mFrameCtrlUnder[UNDER_MOVE0_e];
        m34C2 = 5;
        if (frameCtrl.getRate() < 0.01f) {
            dComIfGp_setDoStatus(dActStts_LET_GO_e);
            if (doTrigger()) {
                m34C2 = 0;
                procFall_init(1, m_HIO->mWallCatch.m.field_0x54);
            } else {
                changeLadderMoveProc(1);
            }
        } else {
            if (frameCtrl.checkPass(26.0f) || frameCtrl.checkPass(36.0f) || frameCtrl.checkPass(43.0f)) {
                setLadderFootSe();
            }
        }
    }
    return true;
}

/* 80133AB8-80133B4C       .text procLadderDownEnd_init__9daPy_lk_cFi */
BOOL daPy_lk_c::procLadderDownEnd_init(int param_0) {
    commonProcInit(daPyProc_LADDER_DOWN_END_e);
    daPy_ANM anm;
    if (param_0 != 0) {
        anm = ANM_LADDERDWEDL;
    } else {
        anm = ANM_LADDERDWEDR;
    }
    setSingleMoveAnime(anm, m_HIO->mLadder.m.field_0x1C, 0.0f, -1, m_HIO->mLadder.m.field_0x20);
    m34C2 = 7;
    gravity = 0.0f;
    dComIfGp_setPlayerStatus0(0, daPyStts0_UNK2000000_e);
    return true;
}

/* 80133B4C-80133BB4       .text procLadderDownEnd__9daPy_lk_cFv */
BOOL daPy_lk_c::procLadderDownEnd() {
    if (setMoveBGLadderCorrect()) {
        return true;
    }

    if (mFrameCtrlUnder[UNDER_MOVE0_e].getRate() < 0.01f) {
        checkNextMode(0);
    } else {
        m34C2 = 5;
    }
    return true;
}

/* 80133BB4-80133E28       .text procLadderMove_init__9daPy_lk_cFiiP4cXyz */
BOOL daPy_lk_c::procLadderMove_init(int param_0, int direction, cXyz* param_2) {
    int uVar3 = checkModeFlg(ModeFlg_MIDAIR) ? true : false;
    float dVar4 = getLadderMoveAnmSpeed();

    commonProcInit(daPyProc_LADDER_MOVE_e);
    if (uVar3 == 0) {
        if (direction == DIR_FORWARD) {
            m370C.y = param_2->y + 37.5f;
        } else {
            dVar4 *= -1.0f;
            m370C.y = param_2->y - 37.5f;
        }
    } else {
        m370C.y = param_2->y;
    }
    m370C.x = param_2->x;
    m370C.z = param_2->z;

    daPy_ANM anm;
    if (param_0 != 0) {
        if (uVar3 != 0) {
            mProcVar6.m3570 = 1;
        } else {
            mProcVar6.m3570 = 0;
            m370C.x = m370C.x - 2.0f * cM_scos(shape_angle.y);
            m370C.z = m370C.z - -2.0f * cM_ssin(shape_angle.y);
        }
        if (dVar4 >= 0.0f) {
            anm = ANM_LADDERLTOR;
        } else {
            anm = ANM_LADDERRTOL;
        }
    } else {
        mProcVar6.m3570 = 1;
        if (dVar4 >= 0.0f) {
            anm = ANM_LADDERRTOL;
        } else {
            anm = ANM_LADDERLTOR;
        }
        m370C.x = m370C.x + 2.0f * cM_scos(shape_angle.y);
        m370C.z = m370C.z + -2.0f * cM_ssin(shape_angle.y);
    }

    setSingleMoveAnime(anm, dVar4, 0.0f, -1, m_HIO->mLadder.m.field_0x2C);
    mDirection = direction;
    if (direction == DIR_FORWARD) {
        setTextureAnime(10, 0);
    } else {
        setTextureAnime(0xb, 0);
    }
    m34C2 = 7;
    gravity = 0.0f;
    speed.y = 0.0f;
    mNormalSpeed = 0.0f;
    speedF = 0.0f;
    mProcVar0.m34D0 = 1;
    dComIfGp_setPlayerStatus0(0, daPyStts0_UNK2000000_e);
    return true;
}

/* 80133E28-80133F1C       .text procLadderMove__9daPy_lk_cFv */
BOOL daPy_lk_c::procLadderMove() {
    if (setMoveBGLadderCorrect()) {
        return true;
    }
    m34C2 = 5;
    dComIfGp_setDoStatus(dActStts_LET_GO_e);

    if (doTrigger()) {
        m34C2 = 0;
        procFall_init(1, m_HIO->mWallCatch.m.field_0x54);
    } else if (std::fabsf(mFrameCtrlUnder[UNDER_MOVE0_e].getRate()) < 0.01f) {
        if (mProcVar0.m34D0 > 0) {
            mProcVar0.m34D0--;
            setLadderFootSe();
        } else {
            changeLadderMoveProc(mProcVar6.m3570);
        }
    } else {
        f32 dVar2 = getLadderMoveAnmSpeed();
        if (mFrameCtrlUnder[UNDER_MOVE0_e].getRate() < 0.0f) {
            dVar2 *= -1.0f;
        }
        mFrameCtrlUnder[UNDER_MOVE0_e].setRate(dVar2);
    }

    return true;
}