summaryrefslogtreecommitdiff
path: root/src/d/snd/d_snd_id_mappers.cpp
blob: 6d699350b1084fef96755c4766fdfb7327623027 (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
#include "d/snd/d_snd_id_mappers.h"

#include "common.h"
#include "d/col/bg/d_bg_pc.h"
#include "d/snd/d_snd_mgr.h"
#include "d/snd/d_snd_player_mgr.h"
#include "d/snd/d_snd_source_enums.h"
#include "d/snd/d_snd_source_group.h"
#include "d/snd/d_snd_util.h"
#include "d/snd/d_snd_id_mappers_data.h"
#include "sized_string.h"

const char *getBaseVariant(const char *name) {
    const ActorBaseNamePair *pair = sActorBaseNamePairs;
    for (int i = 0; i < sNumActorBaseNamePairs; i++) {
        if (streq(name, sActorBaseNamePairs[i].variant)) {
            return sActorBaseNamePairs[i].base;
        }
    }
    return nullptr;
}

u32 getGrpId(s32 sourceType, const char *name) {
    if (name == nullptr) {
        return -1;
    }
    if (sourceType < 0) {
        return -1;
    }

    if (sourceType >= SND_SOURCE_59 + 1) {
        return -1;
    }

    SizedString<64> label;
    label.sprintf("GRP_%s", name);
    u32 id = dSndMgr_c::GetInstance()->getArchive()->ConvertLabelStringToGroupId(label);
    if (id != -1) {
        return id;
    }
    const char *base = getBaseVariant(name);
    if (base != nullptr) {
        label.sprintf("GRP_%s", base);
        id = dSndMgr_c::GetInstance()->getArchive()->ConvertLabelStringToGroupId(label);
        return id;
    }
    return -1;
}

u32 getGrpId(dSndSourceGroup_c *pGroup) {
    if (pGroup == nullptr) {
        return -1;
    }
    u32 id = getGrpId(pGroup->getSourceType(), pGroup->getName());
    if (id == -1 && pGroup->getOrigName() != nullptr) {
        id = getGrpId(pGroup->getSourceType(), pGroup->getOrigName());
    }
    return id;
}

u32 getBnkSeId(s32 sourceType, const char *name) {
    if (name == nullptr) {
        return -1;
    }
    if (sourceType < 0) {
        return -1;
    }

    if (sourceType >= SND_SOURCE_59 + 1) {
        return -1;
    }

    SizedString<64> label;
    label.sprintf("BNK_SE_%s", name);
    u32 id = dSndMgr_c::GetInstance()->getArchive()->ConvertLabelStringToBankId(label);
    if (id != -1) {
        return id;
    }
    const char *base = getBaseVariant(name);
    if (base != nullptr) {
        label.sprintf("BNK_SE_%s", base);
        id = dSndMgr_c::GetInstance()->getArchive()->ConvertLabelStringToBankId(label);
        return id;
    }
    return -1;
}

u32 getBnkSeId(dSndSourceGroup_c *pGroup) {
    if (pGroup == nullptr) {
        return -1;
    }
    u32 id = getBnkSeId(pGroup->getSourceType(), pGroup->getName());
    if (id == -1 && pGroup->getOrigName() != nullptr) {
        id = getBnkSeId(pGroup->getSourceType(), pGroup->getOrigName());
    }
    return id;
}

u32 getSeId(s32 sourceType, const char *name) {
    if (name == nullptr) {
        return -1;
    }
    if (sourceType < 0) {
        return -1;
    }

    if (sourceType >= SND_SOURCE_59 + 1) {
        return -1;
    }

    SizedString<64> label;
    label.sprintf("SE_%s", name);
    u32 id = dSndPlayerMgr_c::GetInstance()->convertLabelStringToSoundId(label);
    if (id != -1) {
        return id;
    }
    const char *base = getBaseVariant(name);
    if (base != nullptr) {
        label.sprintf("SE_%s", base);
        id = dSndPlayerMgr_c::GetInstance()->convertLabelStringToSoundId(label);
        return id;
    }
    return -1;
}

u32 getSeId(dSndSourceGroup_c *pGroup) {
    if (pGroup == nullptr) {
        return -1;
    }
    u32 id = getSeId(pGroup->getSourceType(), pGroup->getName());
    if (id == -1 && pGroup->getOrigName() != nullptr) {
        id = getSeId(pGroup->getSourceType(), pGroup->getOrigName());
    }
    return id;
}

#pragma push
#pragma readonly_strings on
// TODO could be yet another file
const char *sSndHitEffects[] = {
    "TUTI",  "ROCK", "SAND", "GRASS", "TREE",   "LAVA",  "WATER", "STONE", "LOTUS",
    "METAL", "NUMA", "TUTA", "LIFE",  "CARPET", "QSAND", "WOOD",  "DEATH",
};

#pragma pop

const char *getHitEffectName(u32 polyAttr0) {
    if (polyAttr0 >= 1 && polyAttr0 < POLY_ATT_0_MAX) {
        polyAttr0 -= 1;
        return sSndHitEffects[polyAttr0];
    }
    return "";
}