2020-01-15 12:07:48 +00:00
|
|
|
#include "Runtime/AutoMapper/CMapWorldInfo.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/CMemoryCardSys.hpp"
|
|
|
|
#include "Runtime/GameGlobalObjects.hpp"
|
2015-08-17 22:05:00 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
namespace urde {
|
2016-09-25 01:58:20 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CMapWorldInfo::CMapWorldInfo(CBitStreamReader& reader, const CSaveWorld& savw, CAssetId mlvlId) {
|
|
|
|
const CSaveWorldMemory& worldMem = g_MemoryCardSys->GetSaveWorldMemory(mlvlId);
|
2016-10-09 21:41:23 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x4_visitedAreas.reserve((worldMem.GetAreaCount() + 31) / 32);
|
2019-06-12 02:05:17 +00:00
|
|
|
for (u32 i = 0; i < worldMem.GetAreaCount(); ++i) {
|
2020-04-05 10:25:42 +00:00
|
|
|
const bool visited = reader.ReadEncoded(1) != 0;
|
2018-12-08 05:30:43 +00:00
|
|
|
SetAreaVisited(i, visited);
|
|
|
|
}
|
2017-02-08 06:48:43 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x18_mappedAreas.reserve((worldMem.GetAreaCount() + 31) / 32);
|
2019-06-12 02:05:17 +00:00
|
|
|
for (u32 i = 0; i < worldMem.GetAreaCount(); ++i) {
|
2020-04-05 10:25:42 +00:00
|
|
|
const bool mapped = reader.ReadEncoded(1) != 0;
|
2018-12-08 05:30:43 +00:00
|
|
|
SetIsMapped(i, mapped);
|
|
|
|
}
|
2016-04-22 20:22:45 +00:00
|
|
|
|
2020-09-18 21:04:50 +00:00
|
|
|
for (const auto& doorId : savw.GetDoors()) {
|
2020-04-05 10:25:42 +00:00
|
|
|
SetDoorVisited(doorId, reader.ReadEncoded(1) != 0);
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2020-04-05 10:25:42 +00:00
|
|
|
x38_mapStationUsed = reader.ReadEncoded(1) != 0;
|
2016-08-14 03:00:58 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CMapWorldInfo::PutTo(CBitStreamWriter& writer, const CSaveWorld& savw, CAssetId mlvlId) const {
|
|
|
|
const CSaveWorldMemory& worldMem = g_MemoryCardSys->GetSaveWorldMemory(mlvlId);
|
|
|
|
|
2019-06-12 02:05:17 +00:00
|
|
|
for (u32 i = 0; i < worldMem.GetAreaCount(); ++i) {
|
2020-04-05 10:25:42 +00:00
|
|
|
if (i < x0_visitedAreasAllocated) {
|
|
|
|
writer.WriteEncoded(u32(IsAreaVisited(i)), 1);
|
|
|
|
} else {
|
2018-12-08 05:30:43 +00:00
|
|
|
writer.WriteEncoded(0, 1);
|
2020-04-05 10:25:42 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
2019-06-12 02:05:17 +00:00
|
|
|
for (u32 i = 0; i < worldMem.GetAreaCount(); ++i) {
|
2020-04-05 10:25:42 +00:00
|
|
|
if (i < x14_mappedAreasAllocated) {
|
|
|
|
writer.WriteEncoded(u32(IsMapped(i)), 1);
|
|
|
|
} else {
|
2018-12-08 05:30:43 +00:00
|
|
|
writer.WriteEncoded(0, 1);
|
2020-04-05 10:25:42 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
2020-09-18 21:04:50 +00:00
|
|
|
for (const auto& doorId : savw.GetDoors()) {
|
2020-04-05 10:25:42 +00:00
|
|
|
writer.WriteEncoded(u32(IsDoorVisited(doorId)), 1);
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2020-04-05 10:25:42 +00:00
|
|
|
writer.WriteEncoded(u32(x38_mapStationUsed), 1);
|
2016-08-14 03:00:58 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CMapWorldInfo::SetDoorVisited(TEditorId eid, bool visited) { x28_visitedDoors[eid] = visited; }
|
|
|
|
|
|
|
|
bool CMapWorldInfo::IsDoorVisited(TEditorId eid) const { return x28_visitedDoors.find(eid) != x28_visitedDoors.end(); }
|
|
|
|
|
2020-03-13 20:18:59 +00:00
|
|
|
bool CMapWorldInfo::IsAreaVisited(TAreaId aid) const {
|
2020-03-13 20:10:20 +00:00
|
|
|
if (u32(aid) + 1 > x0_visitedAreasAllocated) {
|
2020-04-05 10:30:23 +00:00
|
|
|
x4_visitedAreas.resize((u32(aid) + 32) / 32);
|
|
|
|
x0_visitedAreasAllocated = u32(aid) + 1;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-04-05 10:25:42 +00:00
|
|
|
return ((x4_visitedAreas[aid / 32] >> (aid % 32)) & 1) != 0;
|
2017-02-08 06:48:43 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CMapWorldInfo::SetAreaVisited(TAreaId aid, bool visited) {
|
2020-03-13 20:10:20 +00:00
|
|
|
if (u32(aid) + 1 > x0_visitedAreasAllocated) {
|
2020-04-05 10:25:42 +00:00
|
|
|
x4_visitedAreas.resize((u32(aid) + 32) / 32);
|
|
|
|
x0_visitedAreasAllocated = u32(aid) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (visited) {
|
|
|
|
x4_visitedAreas[aid / 32] |= 1U << (aid % 32);
|
|
|
|
} else {
|
|
|
|
x4_visitedAreas[aid / 32] &= ~(1U << (aid % 32));
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-02-08 06:48:43 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CMapWorldInfo::IsMapped(TAreaId aid) const {
|
2020-03-13 20:10:20 +00:00
|
|
|
if (u32(aid) + 1 > x14_mappedAreasAllocated) {
|
2020-04-05 10:30:23 +00:00
|
|
|
x18_mappedAreas.resize((u32(aid) + 32) / 32);
|
|
|
|
x14_mappedAreasAllocated = u32(aid) + 1;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-04-05 10:25:42 +00:00
|
|
|
return ((x18_mappedAreas[aid / 32] >> (aid % 32)) & 1) != 0;
|
2017-02-08 06:48:43 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CMapWorldInfo::SetIsMapped(TAreaId aid, bool mapped) {
|
2020-03-13 20:10:20 +00:00
|
|
|
if (u32(aid) + 1 > x14_mappedAreasAllocated) {
|
2020-04-05 10:25:42 +00:00
|
|
|
x18_mappedAreas.resize((u32(aid) + 32) / 32);
|
|
|
|
x14_mappedAreasAllocated = u32(aid) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mapped) {
|
|
|
|
x18_mappedAreas[aid / 32] |= 1U << (aid % 32);
|
|
|
|
} else {
|
|
|
|
x18_mappedAreas[aid / 32] &= ~(1U << (aid % 32));
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-04-16 05:52:43 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CMapWorldInfo::IsWorldVisible(TAreaId aid) const { return x38_mapStationUsed || IsMapped(aid); }
|
|
|
|
|
2020-03-13 20:18:59 +00:00
|
|
|
bool CMapWorldInfo::IsAreaVisible(TAreaId aid) const { return IsAreaVisited(aid) || IsMapped(aid); }
|
2017-04-16 05:52:43 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CMapWorldInfo::IsAnythingSet() const {
|
2020-04-05 10:25:42 +00:00
|
|
|
for (u32 i = 0; i < x0_visitedAreasAllocated; ++i) {
|
|
|
|
if ((x4_visitedAreas[i / 32] & (1U << (i % 32))) != 0) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return true;
|
2020-04-05 10:25:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (u32 i = 0; i < x14_mappedAreasAllocated; ++i) {
|
|
|
|
if ((x18_mappedAreas[i / 32] & (1U << (i % 32))) != 0) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return true;
|
2020-04-05 10:25:42 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return x38_mapStationUsed;
|
2015-08-17 22:05:00 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
} // namespace urde
|