summaryrefslogtreecommitdiff
path: root/src/d/d_detect.cpp
blob: 8fc1976817f777da9f87cfdebfadc26609f627a7 (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
//
// Generated by dtk
// Translation Unit: d_detect.cpp
//

#include "d/dolzel.h" // IWYU pragma: keep
#include "d/d_detect.h"
#include "d/d_com_inf_game.h"
#include "d/actor/d_a_player.h"
#include "d/actor/d_a_tag_light.h"

const dDetect_c::Attr_c dDetect_c::M_attr = {
    /* maxDistXZ */ 500.0f,
    /* maxY      */ 500.0f,
    /* minY      */ -200.0f
};

/* 8009BFD4-8009BFFC       .text __ct__14dDetectPlace_cFv */
dDetectPlace_c::dDetectPlace_c() {
    mPos = cXyz::Zero;
    mTimer = 0;
}

/* 8009BFFC-8009C038       .text __dt__14dDetectPlace_cFv */
dDetectPlace_c::~dDetectPlace_c() {}

/* 8009C038-8009C048       .text chk_enable__14dDetectPlace_cCFv */
bool dDetectPlace_c::chk_enable() const {
    return mTimer != 0;
}

/* 8009C048-8009C098       .text __ct__9dDetect_cFv */
dDetect_c::dDetect_c() {
    mTimer = 0;
}

/* 8009C098-8009C0F8       .text __dt__9dDetect_cFv */
dDetect_c::~dDetect_c() {}

/* 8009C0F8-8009C14C       .text proc__9dDetect_cFv */
void dDetect_c::proc() {
    /* Nonmatching - 1 literal load order */
    if (mPlace[0].mTimer > 0) {
        mPlace[0].mTimer--;
    } else if (mPlace[0].mTimer < 0) {
        mPlace[0].mTimer = 1;
    }

    if (mTimer > 0) {
        mTimer--;
    } else if (mTimer < 0) {
        mTimer = 1;
    }
}

/* 8009C14C-8009C1E0       .text chk_quake__9dDetect_cCFPC4cXyz */
bool dDetect_c::chk_quake(const cXyz* pos) const {
    daPy_py_c* player = daPy_getPlayerActorClass();
    bool ret = false;
    if (mTimer > 0) {
        ret = true;
    } else {
        if (player->checkFrontRollCrash()) {
            if (pos) {
                if (chk_quake_area(pos)) {
                    ret = true;
                }
            } else {
                ret = true;
            }
        }
        if (mPlace[0].mTimer > 0) {
            ret = true;
        }
    }
    return ret;
}

/* 8009C1E0-8009C254       .text set_quake__9dDetect_cFPC4cXyz */
void dDetect_c::set_quake(const cXyz* pos) {
    /* Nonmatching - regalloc, load order */
    if (pos) {
        if (!mPlace[0].chk_enable()) {
            mPlace[0].mTimer = -1;
            mPlace[0].mPos = *pos;
        } else {
            // Possible fakematch: There's a double branch here that probably means something got optimized out, but
            // it's not clear what it was, or if this is exactly the right spot for it.
            mPlace[0].mPos.y = mPlace[0].mPos.y;
        }
    } else {
        mTimer = -1;
    }
}

/* 8009C254-8009C32C       .text chk_quake_area__9dDetect_cCFPC4cXyz */
bool dDetect_c::chk_quake_area(const cXyz* pos) const {
    daPy_py_c* player = daPy_getPlayerActorClass();
    f32 maxDist2XZ = SQUARE(attr().maxDistXZ);
    f32 dist2XZ = player->current.pos.abs2XZ(*pos);
    f32 diffY = pos->y - player->current.pos.y;
    return dist2XZ <= maxDist2XZ && diffY <= attr().maxY && diffY >= attr().minY;
}

/* 8009C32C-8009C588       .text search_tag_light__9dDetect_cFPvPv */
void* dDetect_c::search_tag_light(void* i_proc, void* i_pos) {
    if (fopAc_IsActor(i_proc) && fopAcM_GetName(i_proc) == fpcNm_Tag_Light_e) {
        daTagLight::Act_c* light = (daTagLight::Act_c*)i_proc;
        const cXyz* pos = (const cXyz*)i_pos;
        if (light->chk_inside(pos)) {
            return light;
        }
    }
    return NULL;
}

/* 8009C588-8009C5B8       .text chk_light__9dDetect_cCFPC4cXyz */
bool dDetect_c::chk_light(const cXyz* pos) const {
    return fopAcIt_Judge(&dDetect_c::search_tag_light, (void*)pos) != NULL;
}

/* 8009C5B8-8009C620       .text chk_attention__9dDetect_cCFP4cXyz */
bool dDetect_c::chk_attention(cXyz* outPos) const {
    fopAc_ac_c* target = dComIfGp_getAttention().getLook2Target();
    if (target == NULL)
        return false;
    
    *outPos = target->eyePos;
    return true;
}