metaforce/Runtime/CSaveWorld.cpp

91 lines
2.6 KiB
C++
Raw Normal View History

#include "Runtime/CSaveWorld.hpp"
#include "Runtime/CToken.hpp"
2016-07-24 01:51:15 +00:00
2018-12-08 05:30:43 +00:00
namespace urde {
CSaveWorld::CSaveWorld(CInputStream& in) {
in.readUint32Big();
const u32 version = in.readUint32Big();
if (version > 1) {
2018-12-08 05:30:43 +00:00
x0_areaCount = in.readUint32Big();
}
2018-12-08 05:30:43 +00:00
if (version > 2) {
const u32 cinematicCount = in.readUint32Big();
2018-12-08 05:30:43 +00:00
x4_cinematics.reserve(cinematicCount);
for (u32 i = 0; i < cinematicCount; ++i) {
2018-12-08 05:30:43 +00:00
x4_cinematics.push_back(in.readUint32Big());
}
2016-07-24 07:39:58 +00:00
const u32 relayCount = in.readUint32Big();
2018-12-08 05:30:43 +00:00
x14_relays.reserve(relayCount);
for (u32 i = 0; i < relayCount; ++i) {
2018-12-08 05:30:43 +00:00
x14_relays.push_back(in.readUint32Big());
}
2018-12-08 05:30:43 +00:00
}
2016-07-24 07:39:58 +00:00
const u32 layerCount = in.readUint32Big();
2018-12-08 05:30:43 +00:00
x24_layers.reserve(layerCount);
for (u32 i = 0; i < layerCount; ++i) {
SLayerState& st = x24_layers.emplace_back();
2018-12-08 05:30:43 +00:00
st.x0_area = in.readUint32Big();
st.x4_layer = in.readUint32Big();
}
2016-07-24 07:39:58 +00:00
const u32 doorCount = in.readUint32Big();
2018-12-08 05:30:43 +00:00
x34_doors.reserve(doorCount);
for (u32 i = 0; i < doorCount; ++i) {
2018-12-08 05:30:43 +00:00
x34_doors.push_back(in.readUint32Big());
}
if (version <= 0) {
return;
}
const u32 scanCount = in.readUint32Big();
x44_scans.reserve(scanCount);
for (u32 i = 0; i < scanCount; ++i) {
SScanState& st = x44_scans.emplace_back();
st.x0_id = in.readUint32Big();
st.x4_category = EScanCategory(in.readUint32Big());
2018-12-08 05:30:43 +00:00
}
2016-07-24 07:39:58 +00:00
}
2018-12-08 05:30:43 +00:00
u32 CSaveWorld::GetAreaCount() const { return x0_areaCount; }
2016-07-24 07:39:58 +00:00
2018-12-08 05:30:43 +00:00
u32 CSaveWorld::GetCinematicCount() const { return x4_cinematics.size(); }
2016-07-24 07:39:58 +00:00
2018-12-08 05:30:43 +00:00
s32 CSaveWorld::GetCinematicIndex(const TEditorId& id) const {
auto it = std::find(x4_cinematics.begin(), x4_cinematics.end(), id);
if (it == x4_cinematics.end())
return -1;
return it - x4_cinematics.begin();
2016-07-24 07:39:58 +00:00
}
2018-12-08 05:30:43 +00:00
u32 CSaveWorld::GetRelayCount() const { return x14_relays.size(); }
2016-07-24 07:39:58 +00:00
2018-12-08 05:30:43 +00:00
s32 CSaveWorld::GetRelayIndex(const TEditorId& id) const {
auto it = std::find(x14_relays.begin(), x14_relays.end(), id);
if (it == x14_relays.end())
return -1;
return it - x14_relays.begin();
2016-07-24 23:14:58 +00:00
}
2016-07-24 07:39:58 +00:00
2018-12-08 05:30:43 +00:00
TEditorId CSaveWorld::GetRelayEditorId(u32 idx) const { return x14_relays[idx]; }
2016-07-24 07:39:58 +00:00
2018-12-08 05:30:43 +00:00
u32 CSaveWorld::GetDoorCount() const { return x34_doors.size(); }
2016-07-24 07:39:58 +00:00
2018-12-08 05:30:43 +00:00
s32 CSaveWorld::GetDoorIndex(const TEditorId& id) const {
auto it = std::find(x34_doors.begin(), x34_doors.end(), id);
if (it == x34_doors.end())
return -1;
return it - x34_doors.begin();
2016-07-24 01:51:15 +00:00
}
CFactoryFnReturn FSaveWorldFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& param,
2018-12-08 05:30:43 +00:00
CObjectReference* selfRef) {
return TToken<CSaveWorld>::GetIObjObjectFor(std::make_unique<CSaveWorld>(in));
}
2018-12-08 05:30:43 +00:00
} // namespace urde