summaryrefslogtreecommitdiff
path: root/src/KingSystem/GameData/gdtSpecialFlags.cpp
blob: e08a4dd25f5d6740101e00531ed72d8b4ecb2688 (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
#include "KingSystem/GameData/gdtSpecialFlags.h"
#include <prim/seadStringUtil.h>
#include "KingSystem/GameData/gdtCommonFlagsUtils.h"
#include "KingSystem/GameData/gdtFlagUtils.h"

namespace ksys::gdt {

const char* str_Dungeon = "Dungeon";
const char* str_Remains = "Remains";
const char* sSmallKeyNumFlagSuffix = "_SmallKeyNum";
const char* sDungeonClearFlagPrefix = "Clear_";
const char* sDungeonEnterFlagPrefix = "Enter_";

#define GDT_DEFINE_BOOL_GETTER(FLAG)                                                               \
    bool getBool_##FLAG(bool debug = false) {                                                      \
        return getBool(flag_##FLAG(), debug);                                                      \
    }

GDT_DEFINE_BOOL_GETTER(SaveProhibition)
GDT_DEFINE_BOOL_GETTER(SaveProhibitionArea)
GDT_DEFINE_BOOL_GETTER(WarpProhibition)
GDT_DEFINE_BOOL_GETTER(WarpProhibitionArea)
GDT_DEFINE_BOOL_GETTER(WarpProhibitionArea_Fire_Relic)
GDT_DEFINE_BOOL_GETTER(KillTimeProhibition)
GDT_DEFINE_BOOL_GETTER(KillTimeProhibitionArea)
GDT_DEFINE_BOOL_GETTER(KillTimeProhibitionArea_Fire_Relic)

#undef GDT_DEFINE_BOOL_GETTER

s32 getSmallKeyFlag(s32 idx, bool debug = false) {
    return getS32(flag_SmallKey(), idx, debug);
}

bool isSaveProhibited() {
    if (getBool_SaveProhibition())
        return true;
    if (getBool_SaveProhibitionArea())
        return true;
    return false;
}

bool isWarpProhibited() {
    if (getBool_WarpProhibition())
        return true;
    if (getBool_WarpProhibitionArea())
        return true;
    if (getBool_WarpProhibitionArea_Fire_Relic())
        return true;
    return false;
}

bool isKillTimeProhibited() {
    if (getBool_KillTimeProhibition())
        return true;
    if (getBool_KillTimeProhibitionArea())
        return true;
    if (getBool_KillTimeProhibitionArea_Fire_Relic())
        return true;
    return false;
}

s32 getSmallKeyNum(const sead::SafeString& map, bool debug) {
    if (map.startsWith(str_Remains)) {
        sead::FixedSafeString<32> flag{map};
        flag.append(sSmallKeyNumFlagSuffix);
        return getS32ByKey(flag, debug);
    }

    const s32 dungeon_num = getDungeonNum(map);
    if (dungeon_num == -1)
        return 0;

    return getSmallKeyFlag(dungeon_num, debug);
}

s32 getS32ByKey(const sead::SafeString& flag, bool debug) {
    s32 value{};

    auto* mgr = Manager::instance();
    if (mgr) {
        if (debug)
            mgr->getParamBypassPerm().get().getS32(&value, flag);
        else
            mgr->getParam().get().getS32(&value, flag);
    }

    return value;
}

s32 getDungeonNum(const sead::SafeString& map) {
    if (map.startsWith(str_Dungeon)) {
        const sead::FixedSafeString<32> buffer{str_Dungeon};
        s32 ret = -1;

        const auto part = map.getPart(buffer.calcLength());
        if (sead::StringUtil::tryParseS32(&ret, part, sead::StringUtil::CardinalNumber::Base10))
            return ret;
    }
    return -1;
}

void incrementSmallKeyNum(const sead::SafeString& map, s32 value, bool debug) {
    if (map.startsWith(str_Remains)) {
        sead::FixedSafeString<32> flag{map};
        flag.append(sSmallKeyNumFlagSuffix);
        increaseS32CommonFlag(value, flag, -1, debug);
    } else {
        const s32 dungeon_number = getDungeonNum(map);
        if (dungeon_number != -1)
            increaseS32CommonFlag(value, "SmallKey", dungeon_number, debug);
    }
}

bool setS32ByKey(s32 value, const sead::SafeString& flag, bool debug) {
    auto* mgr = Manager::instance();
    return mgr && mgr->setS32Special(value, flag, debug, true);
}

bool setBoolByKey(bool value, const sead::SafeString& flag, bool debug) {
    auto* mgr = Manager::instance();
    return mgr && mgr->setBoolSpecial(value, flag, debug, true);
}

bool getBoolByKey(const sead::SafeString& flag, bool debug) {
    bool value{};

    auto* mgr = Manager::instance();
    if (mgr) {
        if (debug)
            mgr->getParamBypassPerm().get().getBool(&value, flag);
        else
            mgr->getParam().get().getBool(&value, flag);
    }

    return value;
}

bool isDungeonCleared(const sead::SafeString& map, bool debug) {
    sead::FixedSafeString<32> flag{sDungeonClearFlagPrefix};
    flag.append(map, 32 - sizeof("Clear_"));
    return getBoolByKey(flag, debug);
}

void setDungeonCleared(const sead::SafeString& map, bool cleared, bool debug) {
    sead::FixedSafeString<32> flag{sDungeonClearFlagPrefix};
    flag.append(map, 32 - sizeof("Clear_"));
    setBoolByKey(cleared, flag, debug);
}

bool isDungeonEntered(const sead::SafeString& map, bool debug) {
    sead::FixedSafeString<32> flag{sDungeonEnterFlagPrefix};
    flag.append(map, 32 - sizeof("Enter_"));
    return getBoolByKey(flag, debug);
}

void setDungeonEntered(const sead::SafeString& map, bool cleared, bool debug) {
    sead::FixedSafeString<32> flag{sDungeonEnterFlagPrefix};
    flag.append(map, 32 - sizeof("Enter_"));
    setBoolByKey(cleared, flag, debug);
}

f32 getF32ByKey(const sead::SafeString& flag, bool debug) {
    f32 value{};

    auto* mgr = Manager::instance();
    if (mgr) {
        if (debug)
            mgr->getParamBypassPerm().get().getF32(&value, flag);
        else
            mgr->getParam().get().getF32(&value, flag);
    }

    return value;
}

void getStr64ByKey(const char** value, const sead::SafeString& flag, bool debug) {
    auto* mgr = Manager::instance();
    if (mgr) {
        if (debug)
            mgr->getParamBypassPerm().get().getStr64(value, flag);
        else
            mgr->getParam().get().getStr64(value, flag);
    }
}

void getVec3fByKey(sead::Vector3f* value, const sead::SafeString& flag, bool debug) {
    auto* mgr = Manager::instance();
    if (mgr) {
        if (debug)
            mgr->getParamBypassPerm().get().getVec3f(value, flag);
        else
            mgr->getParam().get().getVec3f(value, flag);
    }
}

s32 getS32ByKey(const sead::SafeString& flag, s32 sub_idx, bool debug) {
    s32 value{};

    auto* mgr = Manager::instance();
    if (mgr) {
        if (debug)
            mgr->getParamBypassPerm().get().getS32(&value, flag, sub_idx);
        else
            mgr->getParam().get().getS32(&value, flag, sub_idx);
    }

    return value;
}

f32 getF32ByKey(const sead::SafeString& flag, s32 sub_idx, bool debug) {
    f32 value{};

    auto* mgr = Manager::instance();
    if (mgr) {
        if (debug)
            mgr->getParamBypassPerm().get().getF32(&value, flag, sub_idx);
        else
            mgr->getParam().get().getF32(&value, flag, sub_idx);
    }

    return value;
}

void getStr64ByKey(const char** value, const sead::SafeString& flag, s32 sub_idx, bool debug) {
    auto* mgr = Manager::instance();
    if (mgr) {
        if (debug)
            mgr->getParamBypassPerm().get().getStr64(value, flag, sub_idx);
        else
            mgr->getParam().get().getStr64(value, flag, sub_idx);
    }
}

bool setF32ByKey(f32 value, const sead::SafeString& flag, bool debug) {
    auto* mgr = Manager::instance();
    return mgr && mgr->setF32Special(value, flag, debug, true);
}

bool setStr64ByKey(const sead::SafeString& value, const sead::SafeString& flag, bool debug) {
    auto* mgr = Manager::instance();
    return mgr && mgr->setStr64Special(value, flag, debug, true);
}

}  // namespace ksys::gdt