metaforce/Runtime/AutoMapper/CMapWorldInfo.cpp

138 lines
3.7 KiB
C++
Raw Normal View History

#include "CMapWorldInfo.hpp"
#include "GameGlobalObjects.hpp"
#include "CMemoryCardSys.hpp"
2016-03-04 23:04:53 +00:00
namespace urde
{
2017-02-08 06:48:43 +00:00
CMapWorldInfo::CMapWorldInfo(CBitStreamReader& reader, const CSaveWorld& savw, ResId mlvlId)
2016-09-25 01:58:20 +00:00
{
2017-02-08 06:48:43 +00:00
const CSaveWorldMemory& worldMem = g_MemoryCardSys->GetSaveWorldMemory(mlvlId);
2017-02-08 06:48:43 +00:00
x4_visitedAreas.reserve((worldMem.GetAreaCount() + 31) / 32);
for (int i=0 ; i<worldMem.GetAreaCount() ; ++i)
{
bool visited = reader.ReadEncoded(1);
SetAreaVisited(i, visited);
}
2017-02-08 06:48:43 +00:00
x18_mappedAreas.reserve((worldMem.GetAreaCount() + 31) / 32);
for (int i=0 ; i<worldMem.GetAreaCount() ; ++i)
{
2017-02-08 06:48:43 +00:00
bool mapped = reader.ReadEncoded(1);
SetIsMapped(i, mapped);
}
2017-02-08 06:48:43 +00:00
for (TEditorId doorId : savw.GetDoors())
SetDoorVisited(doorId, reader.ReadEncoded(1));
x38_mapStationUsed = reader.ReadEncoded(1);
2016-09-25 01:58:20 +00:00
}
2017-01-07 01:58:05 +00:00
void CMapWorldInfo::PutTo(CBitStreamWriter& writer, const CSaveWorld& savw, ResId mlvlId) const
2016-10-09 21:41:23 +00:00
{
2017-02-08 06:48:43 +00:00
const CSaveWorldMemory& worldMem = g_MemoryCardSys->GetSaveWorldMemory(mlvlId);
for (int i=0 ; i<worldMem.GetAreaCount() ; ++i)
{
if (i < x0_visitedAreasAllocated)
2017-04-16 05:52:43 +00:00
writer.WriteEncoded(IsAreaVisted(i), 1);
2017-02-08 06:48:43 +00:00
else
writer.WriteEncoded(0, 1);
}
for (int i=0 ; i<worldMem.GetAreaCount() ; ++i)
{
if (i < x14_mappedAreasAllocated)
2017-04-16 05:52:43 +00:00
writer.WriteEncoded(IsMapped(i), 1);
2017-02-08 06:48:43 +00:00
else
writer.WriteEncoded(0, 1);
}
for (TEditorId doorId : savw.GetDoors())
writer.WriteEncoded(IsDoorVisited(doorId), 1);
2016-10-09 21:41:23 +00:00
writer.WriteEncoded(x38_mapStationUsed, 1);
2016-10-09 21:41:23 +00:00
}
2016-04-22 20:22:45 +00:00
void CMapWorldInfo::SetDoorVisited(TEditorId eid, bool visited)
{
2017-02-08 06:48:43 +00:00
x28_visitedDoors[eid] = visited;
}
bool CMapWorldInfo::IsDoorVisited(TEditorId eid) const
{
return x28_visitedDoors.find(eid) != x28_visitedDoors.end();
2016-04-22 20:22:45 +00:00
}
2017-04-16 05:52:43 +00:00
bool CMapWorldInfo::IsAreaVisted(TAreaId aid) const
{
2017-02-08 06:48:43 +00:00
if (aid + 1 > x0_visitedAreasAllocated)
{
2017-04-16 05:52:43 +00:00
const_cast<CMapWorldInfo&>(*this).x4_visitedAreas.resize((aid + 32) / 32);
const_cast<CMapWorldInfo&>(*this).x0_visitedAreasAllocated = aid + 1;
2017-02-08 06:48:43 +00:00
}
return (x4_visitedAreas[aid / 32] >> (aid % 32)) & 0x1;
}
void CMapWorldInfo::SetAreaVisited(TAreaId aid, bool visited)
{
2017-02-08 06:48:43 +00:00
if (aid + 1 > x0_visitedAreasAllocated)
{
2017-03-20 05:09:53 +00:00
x4_visitedAreas.resize((aid + 32) / 32);
2017-02-08 06:48:43 +00:00
x0_visitedAreasAllocated = aid + 1;
}
if (visited)
x4_visitedAreas[aid / 32] |= 1 << (aid % 32);
else
x4_visitedAreas[aid / 32] &= ~(1 << (aid % 32));
}
2017-04-16 05:52:43 +00:00
bool CMapWorldInfo::IsMapped(TAreaId aid) const
2017-02-08 06:48:43 +00:00
{
if (aid + 1 > x14_mappedAreasAllocated)
{
2017-04-16 05:52:43 +00:00
const_cast<CMapWorldInfo&>(*this).x18_mappedAreas.resize((aid + 32) / 32);
const_cast<CMapWorldInfo&>(*this).x14_mappedAreasAllocated = aid + 1;
2017-02-08 06:48:43 +00:00
}
return (x18_mappedAreas[aid / 32] >> (aid % 32)) & 0x1;
}
void CMapWorldInfo::SetIsMapped(TAreaId aid, bool mapped)
{
if (aid + 1 > x14_mappedAreasAllocated)
{
2017-03-20 05:09:53 +00:00
x18_mappedAreas.resize((aid + 32) / 32);
2017-02-08 06:48:43 +00:00
x14_mappedAreasAllocated = aid + 1;
}
if (mapped)
x18_mappedAreas[aid / 32] |= 1 << (aid % 32);
else
x18_mappedAreas[aid / 32] &= ~(1 << (aid % 32));
}
2017-04-16 05:52:43 +00:00
bool CMapWorldInfo::IsWorldVisible(TAreaId aid) const
2017-02-08 06:48:43 +00:00
{
return x38_mapStationUsed || IsMapped(aid);
2017-02-08 06:48:43 +00:00
}
2017-04-16 05:52:43 +00:00
bool CMapWorldInfo::IsAreaVisible(TAreaId aid) const
{
if (IsAreaVisted(aid) || IsMapped(aid))
return true;
return false;
}
bool CMapWorldInfo::IsAnythingSet() const
{
for (int i=0 ; i<x0_visitedAreasAllocated ; ++i)
if (x4_visitedAreas[i / 32] & (1 << (i % 32)))
return true;
for (int i=0 ; i<x14_mappedAreasAllocated ; ++i)
if (x18_mappedAreas[i / 32] & (1 << (i % 32)))
return true;
return x38_mapStationUsed;
2017-04-16 05:52:43 +00:00
}
}