summaryrefslogtreecommitdiff
path: root/src/KingSystem/Map/mapObjectLink.cpp
blob: 700ab069d70b647dbdb864c4ff9e1777a1470889 (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
#include "KingSystem/Map/mapObjectLink.h"
#include <container/seadBuffer.h>
#include "KingSystem/ActorSystem/actActorConstDataAccess.h"
#include "KingSystem/Map/mapObject.h"
#include "KingSystem/Map/mapObjectGenGroup.h"
#include "KingSystem/Map/mapRail.h"

namespace ksys::map {

struct MapLinkDefinition {
    const char* name;
    const char* desc;
    MapLinkDefType type;
};

static constexpr u32 sNumTypes = 42;
static constexpr sead::SafeArray<MapLinkDefinition, sNumTypes> sMapLinkDefinitions{{
    {"-AxisX", "マイナスX軸シグナル", MapLinkDefType::NAxisX},
    {"-AxisY", "マイナスY軸シグナル", MapLinkDefType::NAxisY},
    {"-AxisZ", "マイナスZ軸シグナル", MapLinkDefType::NAxisZ},
    {"AreaCol", "エリア(センサ)指定", MapLinkDefType::AreaCol},
    {"AxisX", "X軸シグナル", MapLinkDefType::AxisX},
    {"AxisY", "Y軸シグナル", MapLinkDefType::AxisY},
    {"AxisZ", "Z軸シグナル", MapLinkDefType::AxisZ},
    {"BAndSCs", "ボール&ソケットCS", MapLinkDefType::BAndSCs},
    {"BAndSLimitAngYCs", "Y角速度制限付ボール&ソケットCS", MapLinkDefType::BAndSLimitAngYCs},
    {"BasicSig", "基本シグナル", MapLinkDefType::BasicSig},
    {"BasicSigOnOnly", "オンのみ基本シグナル", MapLinkDefType::BasicSigOnOnly},
    {"ChangeAtnSig", "アテンション変更時シグナル", MapLinkDefType::ChangeAtnSig},
    {"CogWheelCs", "歯車CS", MapLinkDefType::CogWheelCs},
    {"CopyWaitRevival", "配置自動セーブ継承", MapLinkDefType::CopyWaitRevival},
    {"Create", "生成", MapLinkDefType::Create},
    {"DeadUp", "死んだらオン", MapLinkDefType::DeadUp},
    {"DemoMember", "デモ参加", MapLinkDefType::DemoMember},
    {"FixedCs", "固定CS", MapLinkDefType::FixedCs},
    {"ForSale", "売り物", MapLinkDefType::ForSale},
    {"ForbidAttention", "アテンションタイプ変更", MapLinkDefType::ForbidAttention},
    {"Freeze", "凍結", MapLinkDefType::Freeze},
    {"GimmickSuccess", "ネタ成功シグナル", MapLinkDefType::GimmickSuccess},
    {"HingeCs", "ヒンジCS", MapLinkDefType::HingeCs},
    {"LifeZero", "ライフ0", MapLinkDefType::LifeZero},
    {"LimitHingeCs", "制限付ヒンジCS", MapLinkDefType::LimitHingeCs},
    {"ModelBind", "モデルバインド", MapLinkDefType::ModelBind},
    {"MtxCopyCreate", "位置継承生成", MapLinkDefType::MtxCopyCreate},
    {"OffWaitRevival", "配置自動セーブオフ", MapLinkDefType::OffWaitRevival},
    {"PhysSystemGroup", "物理システムグループ", MapLinkDefType::PhysSystemGroup},
    {"PlacementLOD", "配置LOD", MapLinkDefType::PlacementLOD},
    {"PulleyCs", "滑車CS", MapLinkDefType::PulleyCs},
    {"RackAndPinionCs", "ラック&ピニオンCS", MapLinkDefType::RackAndPinionCs},
    {"Recreate", "再生成", MapLinkDefType::Recreate},
    {"Reference", "参照", MapLinkDefType::Reference},
    {"Remains", "遺物シグナル", MapLinkDefType::Remains},
    {"SensorBind", "センサバインド", MapLinkDefType::SensorBlind},
    {"SliderCs", "スライダーCS", MapLinkDefType::SliderCs},
    {"Stable", "安定", MapLinkDefType::Stable},
    {"StackLink", "スタック", MapLinkDefType::StackLink},
    {"SyncLink", "生成グループ", MapLinkDefType::SyncLink},
    {"VelocityControl", "速度制御シグナル", MapLinkDefType::VelocityControl},
}};

const char* ObjectLink::getDescription() const {
    return getDescriptionForType(type);
}

const char* ObjectLink::getDescriptionForType(MapLinkDefType t) {
    const char* desc = "不定";  // invalid

    for (int i = 0; i < sMapLinkDefinitions.size(); ++i) {
        if (sMapLinkDefinitions[i].type == t) {
            desc = sMapLinkDefinitions[i].desc;
            break;
        }
    }

    return desc;
}

MapLinkDefType ObjectLink::getTypeForName(const sead::SafeString& name) {
    sead::Buffer<const MapLinkDefinition> buf{sMapLinkDefinitions.size(),
                                              sMapLinkDefinitions.getBufferPtr()};

    s32 idx = buf.binarySearchC(
        [&](const MapLinkDefinition& item) { return sead::SafeString(item.name).compare(name); });

    if (idx == -1)
        return MapLinkDefType::Invalid;
    return buf[idx].type;
}

bool ObjectLink::sub_7100D4E310(MapLinkDefType t) {
    switch (t) {
    case MapLinkDefType::Create:
    case MapLinkDefType::Delete:
    case MapLinkDefType::MtxCopyCreate:
    case MapLinkDefType::Freeze:
    case MapLinkDefType::ForbidAttention:
        return true;
    default:
        break;
    case MapLinkDefType::BasicSig:
    case MapLinkDefType::AxisX:
    case MapLinkDefType::AxisY:
    case MapLinkDefType::AxisZ:
    case MapLinkDefType::NAxisX:
    case MapLinkDefType::NAxisY:
    case MapLinkDefType::NAxisZ:
    case MapLinkDefType::GimmickSuccess:
    case MapLinkDefType::VelocityControl:
    case MapLinkDefType::BasicSigOnOnly:
    case MapLinkDefType::Remains:
    case MapLinkDefType::DeadUp:
    case MapLinkDefType::LifeZero:
    case MapLinkDefType::Stable:
    case MapLinkDefType::ChangeAtnSig:
        return true;
    }

    return false;
}

bool ObjectLink::isPlacementLODOrForSaleLink(MapLinkDefType t) {
    return t == MapLinkDefType::PlacementLOD || t == MapLinkDefType::ForSale;
}

act::Actor* ObjectLink::getObjectActor() const {
    if (other_obj == nullptr)
        return nullptr;

    return other_obj->tryGetActor(false);
}

bool ObjectLink::getObjectProcWithAccessor(act::ActorLinkConstDataAccess& accessor) const {
    if (other_obj == nullptr)
        return accessor.acquire(nullptr);
    else
        return other_obj->getActorWithAccessor(accessor);
}

ObjectLinkData::ObjectLinkData() = default;

void ObjectLinkData::deleteArrays() {
    if (mRails) {
        delete[] mRails;
        mRails = nullptr;
    }

    mLinksOther.links.freeBuffer();
    mLinksCs.links.freeBuffer();
    mObjects.freeBuffer();
    mLinksToSelf.links.freeBuffer();
}

bool ObjectLinkData::allocLinksToSelf(s32 num_links, sead::Heap* heap) {
    if (num_links >= 1) {
        mLinksToSelf.links.tryAllocBuffer(num_links, heap);
        if (!mLinksToSelf.links.isBufferReady())
            return false;
    }
    return true;
}

ObjectLink* ObjectLinkData::findLinkWithType(MapLinkDefType t) {
    return findLinkWithType_0(t);
}

ObjectLink* ObjectLinkData::findLinkWithType_0(MapLinkDefType t) {
    switch (t) {
    case MapLinkDefType::FixedCs:
    case MapLinkDefType::HingeCs:
    case MapLinkDefType::LimitHingeCs:
    case MapLinkDefType::SliderCs:
    case MapLinkDefType::PulleyCs:
    case MapLinkDefType::BAndSCs:
    case MapLinkDefType::BAndSLimitAngYCs:
    case MapLinkDefType::CogWheelCs:
    case MapLinkDefType::RackAndPinionCs:
        return mLinksCs.findLinkWithType(t);
    default:
        return mLinksOther.findLinkWithType(t);
    }
}

void ObjectLinkData::setGenGroup(GenGroup* group) {
    if (mGenGroup == nullptr)
        mGenGroup = group;
}

// NON_MATCHING
bool ObjectLinkArray::checkLink(MapLinkDefType t, bool b) {
    bool x_exists;
    ObjectLink* link = nullptr;

    if (t != MapLinkDefType::BasicSig) {
        x_exists = false;
    } else {
        link = findLinkWithType(MapLinkDefType::BasicSigOnOnly);
        x_exists = link != nullptr;

        if (link != nullptr)
            goto done;
    }

    link = findLinkWithType(t);

    if (link == nullptr)
        return false;
    if (link->type == MapLinkDefType::VelocityControl)
        return false;

done:
    act::ActorConstDataAccess acc{};

    if (link->other_obj != nullptr)
        link->other_obj->getActorWithAccessor(acc);
    else
        acc.acquire(nullptr);
    return acc.checkLinkTagActivated(b, x_exists);
}

ObjectLink* ObjectLinkArray::findLinkWithType(MapLinkDefType type) {
    return findLinkWithType_0(type);
}

ObjectLink* ObjectLinkArray::findLinkWithType_0(MapLinkDefType type) {
    for (auto it = links.begin(), end = links.end(); it != end; ++it) {
        if (it->type == type)
            return &*it;
    }
    return nullptr;
}

}  // namespace ksys::map