summaryrefslogtreecommitdiff
path: root/src/engine/objects/HotAirBalloon.cpp
blob: 234eef6d92d07da891efec167df82542b2cf68eb (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
#include "HotAirBalloon.h"
#include "World.h"
#include "port/Game.h"

extern "C" {
#include "render_objects.h"
#include "update_objects.h"
#include "assets/luigi_raceway_data.h"
#include "assets/common_data.h"
#include "math_util.h"
#include "math_util_2.h"
#include "code_80086E70.h"
#include "code_80057C60.h"
#include "actors.h"
}

OHotAirBalloon::OHotAirBalloon(const FVector& pos) {
    _pos = pos;

    D_80165898 = 0;

    // Spawn balloon on second lap.
    if (GetCourse() == GetLuigiRaceway()) {
        _visible = (bool*)&D_80165898;
    } else { // Spawn balloon on race start
        bool mod = true;
        _visible = &mod;
    }

    init_object(indexObjectList1[0], 0);
}

void OHotAirBalloon::Tick() {
    s32 objectIndex = indexObjectList1[0];
    
    if (*_visible) {
        if (gObjectList[objectIndex].state != 0) {
            OHotAirBalloon::func_80085768(objectIndex);
            OHotAirBalloon::func_80085534(objectIndex);
            object_calculate_new_pos_offset(objectIndex);
            if (gObjectList[objectIndex].state >= 2) {
                gActorHotAirBalloonItemBox->pos[0] = gObjectList[objectIndex].pos[0];
                gActorHotAirBalloonItemBox->pos[1] = gObjectList[objectIndex].pos[1] - 10.0;
                gActorHotAirBalloonItemBox->pos[2] = gObjectList[objectIndex].pos[2];
            }
        }
    }
}

void OHotAirBalloon::Draw(s32 cameraId) {
    s32 objectIndex;
    objectIndex = indexObjectList1[0];
    if (*_visible) {
        if (gGamestate != CREDITS_SEQUENCE) {
            func_8008A1D0(objectIndex, cameraId, 0x000005DC, 0x00000BB8);
            if (is_obj_flag_status_active(objectIndex, VISIBLE) != 0) {
                OHotAirBalloon::func_80055CCC(objectIndex, cameraId);
            }
        } else {
            clear_object_flag(objectIndex, 0x00100000);
            OHotAirBalloon::func_80055CCC(objectIndex, cameraId);
        }
    }
}

void OHotAirBalloon::func_80055CCC(s32 objectIndex, s32 cameraId) {
    UNUSED s32 pad;
    f32 test;
    Camera* camera;

    camera = &camera1[cameraId];
    if (gObjectList[objectIndex].state >= 2) {
        func_8008A454(objectIndex, cameraId, 0x0000012C);
        test = gObjectList[objectIndex].pos[1] - gObjectList[objectIndex].surfaceHeight;
        func_8004A6EC(objectIndex, (20.0 / test) + 0.5);
        if (is_obj_index_flag_status_inactive(objectIndex, 0x00100000) != 0) {
            func_80043328(gObjectList[objectIndex].pos, (u16*) gObjectList[objectIndex].direction_angle,
                          gObjectList[objectIndex].sizeScaling, (Gfx*)d_course_luigi_raceway_dl_F960);
            gSPDisplayList(gDisplayListHead++, (Gfx*)d_course_luigi_raceway_dl_F650);
        } else {
            D_80183E80[0] = (s16) gObjectList[objectIndex].direction_angle[0];
            D_80183E80[1] =
                (s16) (func_800418AC(gObjectList[objectIndex].pos[0], gObjectList[objectIndex].pos[2], camera->pos) +
                       0x8000);
            D_80183E80[2] = (u16) gObjectList[objectIndex].direction_angle[2];
            func_80043328(gObjectList[objectIndex].pos, D_80183E80, gObjectList[objectIndex].sizeScaling,
                          (Gfx*)d_course_luigi_raceway_dl_FBE0);
            gSPDisplayList(gDisplayListHead++, (Gfx*)d_course_luigi_raceway_dl_FA20);
            if (gPlayerCountSelection1 == 1) {
                gObjectList[objectIndex].direction_angle[1] = 0;
            }
        }
    }
}

void OHotAirBalloon::init_hot_air_balloon(s32 objectIndex) {
    gObjectList[objectIndex].sizeScaling = 1.0f;
    gObjectList[objectIndex].model = (Gfx*)d_course_luigi_raceway_dl_F960;
    if (gGamestate != CREDITS_SEQUENCE) {
        set_obj_origin_pos(objectIndex, xOrientation * _pos.x, _pos.y, _pos.z);
        set_obj_origin_offset(objectIndex, 0.0f, 300.0f, 0.0f);
    } else {
        set_obj_origin_pos(objectIndex, xOrientation * _pos.x, _pos.y, _pos.z);
        set_obj_origin_offset(objectIndex, 0.0f, 300.0f, 0.0f);
    }
    func_8008B844(objectIndex);
    func_800886F4(objectIndex);
    func_80086EF0(objectIndex);
    gObjectList[objectIndex].velocity[1] = -2.0f;
    init_actor_hot_air_balloon_item_box(0.0f, 0.0f, 0.0f);
    object_next_state(objectIndex);
}

void OHotAirBalloon::func_80085534(s32 objectIndex) {
    switch (gObjectList[objectIndex].unk_0AE) {
        case 1:
            if (gObjectList[objectIndex].offset[1] <= 18.0) {
                func_80086FD4(objectIndex);
            }
            break;
        case 2:
            f32_step_towards(&gObjectList[objectIndex].velocity[1], 0.0f, 0.05f);
            if (gObjectList[objectIndex].velocity[1] == 0.0) {
                func_80086FD4(objectIndex);
            }
            break;
        case 3:
            func_800871AC(objectIndex, 1);
            break;
        case 4:
            f32_step_towards(&gObjectList[objectIndex].velocity[1], 1.0f, 0.05f);
            if (gObjectList[objectIndex].velocity[1] == 1.0) {
                func_80086FD4(objectIndex);
            }
            break;
        case 5:
            func_800871AC(objectIndex, 90);
            break;
        case 6:
            f32_step_towards(&gObjectList[objectIndex].velocity[1], 0.0f, 0.05f);
            if (gObjectList[objectIndex].velocity[1] == 0.0) {
                func_80086FD4(objectIndex);
            }
            break;
        case 7:
            f32_step_towards(&gObjectList[objectIndex].velocity[1], -1.0f, 0.05f);
            if (gObjectList[objectIndex].velocity[1] == -1.0) {
                func_80086FD4(objectIndex);
            }
            break;
        case 8:
            func_800871AC(objectIndex, 90);
            break;
        case 9:
            f32_step_towards(&gObjectList[objectIndex].velocity[1], 0.0f, 0.05f);
            if (func_80087060(objectIndex, 90) != 0) {
                func_8008701C(objectIndex, 3);
            }
            break;
    }
    object_add_velocity_offset_y(objectIndex);
    gObjectList[objectIndex].direction_angle[1] += 0x100;
}

void OHotAirBalloon::func_80085768(s32 objectIndex) {
    switch (gObjectList[objectIndex].state) { /* irregular */
        case 1:
            OHotAirBalloon::init_hot_air_balloon(objectIndex);
            break;
        case 0:
        case 2:
            break;
    }
}