format codebase

This commit is contained in:
aronwk-aaron
2022-07-28 08:39:57 -05:00
parent 4f7aa11067
commit 19e77a38d8
881 changed files with 34700 additions and 38689 deletions

View File

@@ -15,12 +15,11 @@
#include "CDClientManager.h"
Level::Level(Zone* parentZone, const std::string& filepath) {
m_ParentZone = parentZone;
m_ParentZone = parentZone;
std::ifstream file(filepath, std::ios_base::in | std::ios_base::binary);
if (file) {
ReadChunks(file);
}
else {
} else {
Game::logger->Log("Level", "Failed to load %s", filepath.c_str());
}
@@ -42,7 +41,7 @@ const void Level::PrintAllObjects() {
}
}
void Level::ReadChunks(std::ifstream & file) {
void Level::ReadChunks(std::ifstream& file) {
const uint32_t CHNK_HEADER = ('C' + ('H' << 8) + ('N' << 16) + ('K' << 24));
while (!file.eof()) {
@@ -63,15 +62,13 @@ void Level::ReadChunks(std::ifstream & file) {
//We're currently not loading env or particle data
if (header.id == ChunkTypeID::FileInfo) {
ReadFileInfoChunk(file, header);
}
else if (header.id == ChunkTypeID::SceneObjectData) {
} else if (header.id == ChunkTypeID::SceneObjectData) {
ReadSceneObjectDataChunk(file, header);
}
m_ChunkHeaders.insert(std::make_pair(header.id, header));
file.seekg(target);
}
else {
} else {
if (initPos == std::streamoff(0)) { //Really old chunk version
file.seekg(0);
Header header;
@@ -98,8 +95,7 @@ void Level::ReadChunks(std::ifstream & file) {
file.ignore(4);
}
}
}
else {
} else {
file.ignore(8);
}
@@ -143,7 +139,7 @@ void Level::ReadChunks(std::ifstream & file) {
}
}
void Level::ReadFileInfoChunk(std::ifstream & file, Header & header) {
void Level::ReadFileInfoChunk(std::ifstream& file, Header& header) {
FileInfoChunk* fi = new FileInfoChunk;
BinaryIO::BinaryRead(file, fi->version);
BinaryIO::BinaryRead(file, fi->revision);
@@ -156,7 +152,7 @@ void Level::ReadFileInfoChunk(std::ifstream & file, Header & header) {
if (header.fileInfo->revision == 3452816845 && m_ParentZone->GetZoneID().GetMapID() == 1100) header.fileInfo->revision = 26;
}
void Level::ReadSceneObjectDataChunk(std::ifstream & file, Header & header) {
void Level::ReadSceneObjectDataChunk(std::ifstream& file, Header& header) {
SceneObjectDataChunk* chunk = new SceneObjectDataChunk;
uint32_t objectsCount = 0;
BinaryIO::BinaryRead(file, objectsCount);
@@ -182,25 +178,25 @@ void Level::ReadSceneObjectDataChunk(std::ifstream & file, Header & header) {
dZoneManager::Instance()->GetZone()->SetSpawnRot(obj.rotation);
}
std::u16string ldfString = u"";
uint32_t length = 0;
BinaryIO::BinaryRead(file, length);
std::u16string ldfString = u"";
uint32_t length = 0;
BinaryIO::BinaryRead(file, length);
for (uint32_t i = 0; i < length; ++i) {
uint16_t data;
BinaryIO::BinaryRead(file, data);
ldfString.push_back(data);
}
for (uint32_t i = 0; i < length; ++i) {
uint16_t data;
BinaryIO::BinaryRead(file, data);
ldfString.push_back(data);
}
std::string sData = GeneralUtils::UTF16ToWTF8(ldfString);
std::stringstream ssData(sData);
std::string token;
char deliminator = '\n';
std::string sData = GeneralUtils::UTF16ToWTF8(ldfString);
std::stringstream ssData(sData);
std::string token;
char deliminator = '\n';
while (std::getline(ssData, token, deliminator)) {
LDFBaseData * ldfData = LDFBaseData::DataFromString(token);
obj.settings.push_back(ldfData);
}
while (std::getline(ssData, token, deliminator)) {
LDFBaseData* ldfData = LDFBaseData::DataFromString(token);
obj.settings.push_back(ldfData);
}
BinaryIO::BinaryRead(file, obj.value3);
@@ -228,7 +224,7 @@ void Level::ReadSceneObjectDataChunk(std::ifstream & file, Header & header) {
continue;
}
if (obj.lot == 176) { //Spawner
if (obj.lot == 176) { //Spawner
SpawnerInfo spawnInfo = SpawnerInfo();
SpawnerNode* node = new SpawnerNode();
spawnInfo.templateID = obj.lot;
@@ -268,8 +264,7 @@ void Level::ReadSceneObjectDataChunk(std::ifstream & file, Header & header) {
if (data->GetValueType() == eLDFType::LDF_TYPE_FLOAT) // Floats are in seconds
{
spawnInfo.respawnTime = std::stof(data->GetValueAsString());
}
else if (data->GetValueType() == eLDFType::LDF_TYPE_U32) // Ints are in ms?
} else if (data->GetValueType() == eLDFType::LDF_TYPE_U32) // Ints are in ms?
{
spawnInfo.respawnTime = std::stoi(data->GetValueAsString()) / 1000;
}
@@ -296,9 +291,9 @@ void Level::ReadSceneObjectDataChunk(std::ifstream & file, Header & header) {
}
}
}
Spawner* spawner = new Spawner(spawnInfo);
dZoneManager::Instance()->AddSpawner(obj.id, spawner);
} else { //Regular object
Spawner* spawner = new Spawner(spawnInfo);
dZoneManager::Instance()->AddSpawner(obj.id, spawner);
} else { //Regular object
EntityInfo info;
info.spawnerID = 0;
info.id = obj.id;
@@ -327,16 +322,14 @@ void Level::ReadSceneObjectDataChunk(std::ifstream & file, Header & header) {
if (!clientOnly) {
// We should never have more than 1 zone control object
const auto zoneControlObject = dZoneManager::Instance()->GetZoneControlObject();
// We should never have more than 1 zone control object
const auto zoneControlObject = dZoneManager::Instance()->GetZoneControlObject();
if (zoneControlObject != nullptr && info.lot == zoneControlObject->GetLOT())
goto deleteSettings;
EntityManager::Instance()->CreateEntity(info, nullptr);
}
else
{
deleteSettings:
EntityManager::Instance()->CreateEntity(info, nullptr);
} else {
deleteSettings:
for (auto* setting : info.settings) {
delete setting;

View File

@@ -29,7 +29,7 @@ public:
struct SceneObjectDataChunk {
std::map<LWOOBJID, SceneObject> objects;
SceneObject& GetObject(LWOOBJID id) {
for (std::map<LWOOBJID, SceneObject>::iterator it = objects.begin(); it != objects.end(); ++it) {
if (it->first == id) return it->second;

View File

@@ -15,8 +15,7 @@ Spawner::Spawner(const SpawnerInfo info) {
if (!m_Info.emulated) {
m_EntityInfo.spawnerID = m_Info.spawnerID;
}
else {
} else {
m_EntityInfo.spawnerID = m_Info.emulator;
m_Info.isNetwork = false;
}
@@ -46,8 +45,7 @@ Spawner::Spawner(const SpawnerInfo info) {
m_WaitTimes.push_back(m_Info.respawnTime);
}
if (m_Info.spawnOnSmashGroupName != "")
{
if (m_Info.spawnOnSmashGroupName != "") {
std::vector<Entity*> spawnSmashEntities = EntityManager::Instance()->GetEntitiesInGroup(m_Info.spawnOnSmashGroupName);
std::vector<Spawner*> spawnSmashSpawners = dZoneManager::Instance()->GetSpawnersInGroup(m_Info.spawnOnSmashGroupName);
std::vector<Spawner*> spawnSmashSpawnersN = dZoneManager::Instance()->GetSpawnersByName(m_Info.spawnOnSmashGroupName);
@@ -55,20 +53,20 @@ Spawner::Spawner(const SpawnerInfo info) {
m_SpawnSmashFoundGroup = true;
ssEntity->AddDieCallback([=]() {
Spawn();
});
});
}
for (Spawner* ssSpawner : spawnSmashSpawners) {
m_SpawnSmashFoundGroup = true;
ssSpawner->AddSpawnedEntityDieCallback([=]() {
Spawn();
});
});
}
for (Spawner* ssSpawner : spawnSmashSpawnersN) {
m_SpawnSmashFoundGroup = true;
m_SpawnOnSmash = ssSpawner;
ssSpawner->AddSpawnedEntityDieCallback([=]() {
Spawn();
});
});
}
}
}
@@ -77,8 +75,7 @@ Spawner::~Spawner() {
}
Entity* Spawner::Spawn()
{
Entity* Spawner::Spawn() {
std::vector<SpawnerNode*> freeNodes;
for (SpawnerNode* node : m_Info.nodes) {
if (node->entities.size() < node->nodeMax) {
@@ -131,18 +128,15 @@ void Spawner::AddSpawnedEntityDieCallback(std::function<void()> callback) {
m_SpawnedEntityDieCallbacks.push_back(callback);
}
void Spawner::AddEntitySpawnedCallback(std::function<void(Entity *)> callback) {
void Spawner::AddEntitySpawnedCallback(std::function<void(Entity*)> callback) {
m_EntitySpawnedCallbacks.push_back(callback);
}
void Spawner::Reset()
{
void Spawner::Reset() {
m_Start = true;
for (auto* node : m_Info.nodes)
{
for (const auto& spawned : node->entities)
{
for (auto* node : m_Info.nodes) {
for (const auto& spawned : node->entities) {
auto* entity = EntityManager::Instance()->GetEntity(spawned);
if (entity == nullptr) continue;
@@ -159,9 +153,9 @@ void Spawner::Reset()
}
void Spawner::SoftReset() {
m_Start = true;
m_AmountSpawned = 0;
m_NeedsUpdate = true;
m_Start = true;
m_AmountSpawned = 0;
m_NeedsUpdate = true;
}
void Spawner::SetRespawnTime(float time) {
@@ -171,8 +165,8 @@ void Spawner::SetRespawnTime(float time) {
m_WaitTimes[i] = 0;
};
m_Start = true;
m_NeedsUpdate = true;
m_Start = true;
m_NeedsUpdate = true;
}
void Spawner::SetNumToMaintain(int32_t value) {
@@ -180,21 +174,19 @@ void Spawner::SetNumToMaintain(int32_t value) {
}
void Spawner::Update(const float deltaTime) {
if (m_Start && m_Active)
{
if (m_Start && m_Active) {
m_Start = false;
const auto toSpawn = m_Info.amountMaintained - m_AmountSpawned;
for (auto i = 0; i < toSpawn; ++i)
{
for (auto i = 0; i < toSpawn; ++i) {
Spawn();
}
m_WaitTimes.clear();
return;
}
if (!m_NeedsUpdate) return;
if (!m_Active) return;
//if (m_Info.noTimedSpawn) return;
@@ -223,7 +215,7 @@ void Spawner::NotifyOfEntityDeath(const LWOOBJID& objectID) {
//m_RespawnTime = 10.0f;
m_WaitTimes.push_back(0.0f);
SpawnerNode* node;
auto it = m_Entities.find(objectID);
if (it != m_Entities.end()) node = it->second;
else return;
@@ -233,29 +225,26 @@ void Spawner::NotifyOfEntityDeath(const LWOOBJID& objectID) {
}
for (size_t i = 0; i < node->entities.size(); ++i) {
if (node->entities[i] && node->entities[i] == objectID)
if (node->entities[i] && node->entities[i] == objectID)
node->entities.erase(node->entities.begin() + i);
}
m_Entities.erase(objectID);
if (m_SpawnOnSmash != nullptr)
{
if (m_SpawnOnSmash != nullptr) {
m_SpawnOnSmash->Reset();
}
}
void Spawner::Activate()
{
void Spawner::Activate() {
m_Active = true;
m_NeedsUpdate = true;
for (auto& time : m_WaitTimes)
{
for (auto& time : m_WaitTimes) {
time = 0;
}
}
void Spawner::SetSpawnLot(LOT lot) {
m_EntityInfo.lot = lot;
m_EntityInfo.lot = lot;
}

View File

@@ -37,15 +37,15 @@ struct SpawnerInfo {
bool noTimedSpawn = false;
std::string grpNameQBShowBricks = "";
bool spawnActivator = true;
bool emulated = false;
LWOOBJID emulator = LWOOBJID_EMPTY;
};
class Spawner {
public:
Spawner(SpawnerInfo info);
~Spawner();
Spawner(SpawnerInfo info);
~Spawner();
Entity* Spawn();
Entity* Spawn(std::vector<SpawnerNode*> freeNodes, bool force = false);
@@ -69,7 +69,7 @@ public:
bool m_Active = true;
private:
std::vector<std::function<void()>> m_SpawnedEntityDieCallbacks = {};
std::vector<std::function<void(Entity*)>> m_EntitySpawnedCallbacks = {};
std::vector<std::function<void(Entity*)>> m_EntitySpawnedCallbacks = {};
bool m_SpawnSmashFoundGroup = false;

View File

@@ -12,9 +12,8 @@
#include "Spawner.h"
#include "dZoneManager.h"
Zone::Zone(const LWOMAPID & mapID, const LWOINSTANCEID & instanceID, const LWOCLONEID & cloneID) :
m_ZoneID(mapID, instanceID, cloneID)
{
Zone::Zone(const LWOMAPID& mapID, const LWOINSTANCEID& instanceID, const LWOCLONEID& cloneID) :
m_ZoneID(mapID, instanceID, cloneID) {
m_NumberOfScenesLoaded = 0;
m_NumberOfObjectsLoaded = 0;
m_NumberOfSceneTransitionsLoaded = 0;
@@ -30,8 +29,7 @@ Zone::~Zone() {
}
}
void Zone::Initalize()
{
void Zone::Initalize() {
LoadZoneIntoMemory();
LoadLevelsIntoMemory();
m_CheckSum = CalculateChecksum();
@@ -63,8 +61,7 @@ void Zone::LoadZoneIntoMemory() {
uint8_t sceneCount;
BinaryIO::BinaryRead(file, sceneCount);
m_SceneCount = sceneCount;
}
else BinaryIO::BinaryRead(file, m_SceneCount);
} else BinaryIO::BinaryRead(file, m_SceneCount);
for (uint32_t i = 0; i < m_SceneCount; ++i) {
LoadScene(file);
@@ -117,23 +114,18 @@ void Zone::LoadZoneIntoMemory() {
if (data) {
if (data->GetKey() == u"spawner_node_id") {
node->nodeID = std::stoi(data->GetValueAsString());
}
else if (data->GetKey() == u"spawner_max_per_node") {
} else if (data->GetKey() == u"spawner_max_per_node") {
node->nodeMax = std::stoi(data->GetValueAsString());
}
else if (data->GetKey() == u"groupID") { // Load object group
} else if (data->GetKey() == u"groupID") { // Load object group
std::string groupStr = data->GetValueAsString();
info.groups = GeneralUtils::SplitString(groupStr, ';');
info.groups.erase(info.groups.end() - 1);
}
else if (data->GetKey() == u"grpNameQBShowBricks") {
} else if (data->GetKey() == u"grpNameQBShowBricks") {
if (data->GetValueAsString() == "") continue;
/*std::string groupStr = data->GetValueAsString();
info.groups.push_back(groupStr);*/
info.grpNameQBShowBricks = data->GetValueAsString();
}
else if (data->GetKey() == u"spawner_name")
{
} else if (data->GetKey() == u"spawner_name") {
info.name = data->GetValueAsString();
}
}
@@ -157,8 +149,7 @@ void Zone::LoadZoneIntoMemory() {
//m_PathData.resize(m_PathDataLength);
//file.read((char*)&m_PathData[0], m_PathDataLength);
}
}
else {
} else {
Game::logger->Log("Zone", "Failed to open: %s", m_ZoneFilePath.c_str());
}
m_ZonePath = m_ZoneFilePath.substr(0, m_ZoneFilePath.rfind('/') + 1);
@@ -168,11 +159,11 @@ void Zone::LoadZoneIntoMemory() {
std::string Zone::GetFilePathForZoneID() {
//We're gonna go ahead and presume we've got the db loaded already:
CDZoneTableTable * zoneTable = CDClientManager::Instance()->GetTable<CDZoneTableTable>("ZoneTable");
CDZoneTableTable* zoneTable = CDClientManager::Instance()->GetTable<CDZoneTableTable>("ZoneTable");
const CDZoneTable* zone = zoneTable->Query(this->GetZoneID().GetMapID());
if (zone != nullptr) {
std::string toReturn = "./res/maps/" + zone->zoneName;
std::transform(toReturn.begin(), toReturn.end(), toReturn.begin(), ::tolower);
std::string toReturn = "./res/maps/" + zone->zoneName;
std::transform(toReturn.begin(), toReturn.end(), toReturn.begin(), ::tolower);
return toReturn;
}
@@ -231,7 +222,7 @@ const void Zone::PrintAllGameObjects() {
}
}
void Zone::LoadScene(std::ifstream & file) {
void Zone::LoadScene(std::ifstream& file) {
SceneRef scene;
scene.level = nullptr;
LWOSCENEID lwoSceneID(LWOZONEID_INVALID, 0);
@@ -284,8 +275,7 @@ std::vector<LUTriggers::Trigger*> Zone::LoadLUTriggers(std::string triggerFile,
if (doc->Parse(data.str().c_str(), data.str().size()) == 0) {
//Game::logger->Log("Zone", "Loaded LUTriggers from file %s!", triggerFile.c_str());
}
else {
} else {
Game::logger->Log("Zone", "Failed to load LUTriggers from file %s", triggerFile.c_str());
return lvlTriggers;
}
@@ -295,7 +285,7 @@ std::vector<LUTriggers::Trigger*> Zone::LoadLUTriggers(std::string triggerFile,
auto currentTrigger = triggers->FirstChildElement("trigger");
while (currentTrigger) {
LUTriggers::Trigger *newTrigger = new LUTriggers::Trigger();
LUTriggers::Trigger* newTrigger = new LUTriggers::Trigger();
currentTrigger->QueryAttribute("enabled", &newTrigger->enabled);
currentTrigger->QueryAttribute("id", &newTrigger->id);
@@ -336,12 +326,9 @@ LUTriggers::Trigger* Zone::GetTrigger(uint32_t sceneID, uint32_t triggerID) {
return m_Scenes[sceneID].triggers[triggerID];
}
const Path* Zone::GetPath(std::string name) const
{
for (const auto& path : m_Paths)
{
if (name == path.pathName)
{
const Path* Zone::GetPath(std::string name) const {
for (const auto& path : m_Paths) {
if (name == path.pathName) {
return &path;
}
}
@@ -349,7 +336,7 @@ const Path* Zone::GetPath(std::string name) const
return nullptr;
}
void Zone::LoadSceneTransition(std::ifstream & file) {
void Zone::LoadSceneTransition(std::ifstream& file) {
SceneTransition sceneTrans;
if (m_ZoneFileFormatVersion < Zone::ZoneFileFormatVersion::LateAlpha) {
uint8_t length;
@@ -367,14 +354,14 @@ void Zone::LoadSceneTransition(std::ifstream & file) {
m_SceneTransitions.push_back(sceneTrans);
}
SceneTransitionInfo Zone::LoadSceneTransitionInfo(std::ifstream & file) {
SceneTransitionInfo Zone::LoadSceneTransitionInfo(std::ifstream& file) {
SceneTransitionInfo info;
BinaryIO::BinaryRead(file, info.sceneID);
BinaryIO::BinaryRead(file, info.position);
return info;
}
void Zone::LoadPath(std::ifstream & file) {
void Zone::LoadPath(std::ifstream& file) {
// Currently only spawner (type 4) paths are supported
Path path = Path();
@@ -400,8 +387,7 @@ void Zone::LoadPath(std::ifstream & file) {
if (path.pathVersion >= 18) {
uint8_t unknown;
BinaryIO::BinaryRead(file, unknown);
}
else if (path.pathVersion >= 13) {
} else if (path.pathVersion >= 13) {
uint8_t count;
BinaryIO::BinaryRead(file, count);
for (uint8_t i = 0; i < count; ++i) {
@@ -410,8 +396,7 @@ void Zone::LoadPath(std::ifstream & file) {
path.movingPlatform.platformTravelSound.push_back(character);
}
}
}
else if (path.pathType == PathType::Property) {
} else if (path.pathType == PathType::Property) {
int32_t unknown;
BinaryIO::BinaryRead(file, unknown);
BinaryIO::BinaryRead(file, path.property.price);
@@ -441,8 +426,7 @@ void Zone::LoadPath(std::ifstream & file) {
BinaryIO::BinaryRead(file, path.property.playerZoneCoords.y);
BinaryIO::BinaryRead(file, path.property.playerZoneCoords.z);
BinaryIO::BinaryRead(file, path.property.maxBuildHeight);
}
else if (path.pathType == PathType::Camera) {
} else if (path.pathType == PathType::Camera) {
uint8_t count;
BinaryIO::BinaryRead(file, count);
for (uint8_t i = 0; i < count; ++i) {
@@ -503,8 +487,7 @@ void Zone::LoadPath(std::ifstream & file) {
waypoint.movingPlatform.arriveSound.push_back(character);
}
}
}
else if (path.pathType == PathType::Camera) {
} else if (path.pathType == PathType::Camera) {
float unknown;
BinaryIO::BinaryRead(file, unknown);
BinaryIO::BinaryRead(file, unknown);
@@ -515,8 +498,7 @@ void Zone::LoadPath(std::ifstream & file) {
BinaryIO::BinaryRead(file, waypoint.camera.tension);
BinaryIO::BinaryRead(file, waypoint.camera.continuity);
BinaryIO::BinaryRead(file, waypoint.camera.bias);
}
else if (path.pathType == PathType::Race) {
} else if (path.pathType == PathType::Race) {
uint8_t unknown;
BinaryIO::BinaryRead(file, unknown);
BinaryIO::BinaryRead(file, unknown);
@@ -524,8 +506,7 @@ void Zone::LoadPath(std::ifstream & file) {
BinaryIO::BinaryRead(file, unknown1);
BinaryIO::BinaryRead(file, unknown1);
BinaryIO::BinaryRead(file, unknown1);
}
else if (path.pathType == PathType::Rail) {
} else if (path.pathType == PathType::Rail) {
float unknown;
BinaryIO::BinaryRead(file, unknown);
BinaryIO::BinaryRead(file, unknown);

View File

@@ -9,7 +9,7 @@
class Level;
class LUTriggers {
public:
public:
struct Command {
std::string id;
@@ -89,7 +89,7 @@ enum class PathBehavior : uint32_t {
Once = 2
};
enum class PropertyRentalTimeUnit : int32_t{
enum class PropertyRentalTimeUnit : int32_t {
Forever = 0,
Seconds = 1,
Minutes = 2,

View File

@@ -19,8 +19,8 @@ struct SceneObject {
float scale = 1.0f;
//std::string settings;
uint32_t value3;
std::vector<LDFBaseData*> settings;
std::vector<LDFBaseData*> settings;
};
#define LOT_MARKER_PLAYER_START 1931
#define LOT_MARKET_CAMERA_TARGET 2182
#define LOT_MARKET_CAMERA_TARGET 2182

View File

@@ -17,17 +17,17 @@ dZoneManager* dZoneManager::m_Address = nullptr;
void dZoneManager::Initialize(const LWOZONEID& zoneID) {
Game::logger->Log("dZoneManager", "Preparing zone: %i/%i/%i", zoneID.GetMapID(), zoneID.GetInstanceID(), zoneID.GetCloneID());
int64_t startTime = 0;
int64_t endTime = 0;
int64_t startTime = 0;
int64_t endTime = 0;
startTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
startTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
LoadZone(zoneID);
LoadZone(zoneID);
LOT zoneControlTemplate = 2365;
CDZoneTableTable* zoneTable = CDClientManager::Instance()->GetTable<CDZoneTableTable>("ZoneTable");
if (zoneTable != nullptr){
if (zoneTable != nullptr) {
const CDZoneTable* zone = zoneTable->Query(zoneID.GetMapID());
if (zone != nullptr) {
@@ -37,7 +37,7 @@ void dZoneManager::Initialize(const LWOZONEID& zoneID) {
EntityManager::Instance()->SetGhostDistanceMax(max + min);
EntityManager::Instance()->SetGhostDistanceMin(max);
m_PlayerLoseCoinsOnDeath = zone->PlayerLoseCoinsOnDeath;
}
}
}
Game::logger->Log("dZoneManager", "Creating zone control object %i", zoneControlTemplate);
@@ -51,9 +51,9 @@ void dZoneManager::Initialize(const LWOZONEID& zoneID) {
m_pZone->Initalize();
endTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
endTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
Game::logger->Log("dZoneManager", "Zone prepared in: %llu ms", (endTime - startTime));
Game::logger->Log("dZoneManager", "Zone prepared in: %llu ms", (endTime - startTime));
VanityUtilities::SpawnVanity();
}
@@ -61,17 +61,17 @@ void dZoneManager::Initialize(const LWOZONEID& zoneID) {
dZoneManager::~dZoneManager() {
if (m_pZone) delete m_pZone;
for (std::pair<LWOOBJID, Spawner*> p : m_Spawners) {
if (p.second) {
delete p.second;
p.second = nullptr;
}
for (std::pair<LWOOBJID, Spawner*> p : m_Spawners) {
if (p.second) {
delete p.second;
p.second = nullptr;
}
m_Spawners.erase(p.first);
}
m_Spawners.erase(p.first);
}
}
Zone * dZoneManager::GetZone() {
Zone* dZoneManager::GetZone() {
return m_pZone;
}
@@ -82,14 +82,14 @@ void dZoneManager::LoadZone(const LWOZONEID& zoneID) {
m_pZone = new Zone(zoneID.GetMapID(), zoneID.GetInstanceID(), zoneID.GetCloneID());
}
void dZoneManager::NotifyZone(const dZoneNotifier & notifier, const LWOOBJID& objectID) {
void dZoneManager::NotifyZone(const dZoneNotifier& notifier, const LWOOBJID& objectID) {
switch (notifier) {
case dZoneNotifier::SpawnedObjectDestroyed:
break;
case dZoneNotifier::SpawnedChildObjectDestroyed:
break;
case dZoneNotifier::ReloadZone:
Game::logger->Log("dZoneManager", "Forcing reload of zone %i", m_ZoneID.GetMapID());
Game::logger->Log("dZoneManager", "Forcing reload of zone %i", m_ZoneID.GetMapID());
LoadZone(m_ZoneID);
m_pZone->Initalize();
@@ -109,21 +109,19 @@ void dZoneManager::NotifyZone(const dZoneNotifier & notifier, const LWOOBJID& ob
}
}
void dZoneManager::AddSpawner(LWOOBJID id, Spawner* spawner)
{
void dZoneManager::AddSpawner(LWOOBJID id, Spawner* spawner) {
m_Spawners.insert_or_assign(id, spawner);
}
LWOZONEID dZoneManager::GetZoneID() const
{
LWOZONEID dZoneManager::GetZoneID() const {
return m_ZoneID;
}
uint32_t dZoneManager::GetMaxLevel() {
if (m_MaxLevel == 0) {
auto tableData = CDClientDatabase::ExecuteQuery("SELECT LevelCap FROM WorldConfig WHERE WorldConfigID = 1 LIMIT 1;");
m_MaxLevel = tableData.getIntField(0, -1);
tableData.finalize();
m_MaxLevel = tableData.getIntField(0, -1);
tableData.finalize();
}
return m_MaxLevel;
}
@@ -131,8 +129,8 @@ uint32_t dZoneManager::GetMaxLevel() {
int32_t dZoneManager::GetLevelCapCurrencyConversion() {
if (m_CurrencyConversionRate == 0) {
auto tableData = CDClientDatabase::ExecuteQuery("SELECT LevelCapCurrencyConversion FROM WorldConfig WHERE WorldConfigID = 1 LIMIT 1;");
m_CurrencyConversionRate = tableData.getIntField(0, -1);
tableData.finalize();
m_CurrencyConversionRate = tableData.getIntField(0, -1);
tableData.finalize();
}
return m_CurrencyConversionRate;
}
@@ -143,12 +141,10 @@ void dZoneManager::Update(float deltaTime) {
}
}
LWOOBJID dZoneManager::MakeSpawner(SpawnerInfo info)
{
LWOOBJID dZoneManager::MakeSpawner(SpawnerInfo info) {
auto objectId = info.spawnerID;
if (objectId == LWOOBJID_EMPTY)
{
if (objectId == LWOOBJID_EMPTY) {
objectId = ObjectIDManager::Instance()->GenerateObjectID();
objectId = GeneralUtils::SetBit(objectId, OBJECT_BIT_CLIENT);
@@ -172,8 +168,7 @@ LWOOBJID dZoneManager::MakeSpawner(SpawnerInfo info)
return objectId;
}
Spawner* dZoneManager::GetSpawner(const LWOOBJID id)
{
Spawner* dZoneManager::GetSpawner(const LWOOBJID id) {
const auto& index = m_Spawners.find(id);
if (index == m_Spawners.end()) {
@@ -183,8 +178,7 @@ Spawner* dZoneManager::GetSpawner(const LWOOBJID id)
return index->second;
}
void dZoneManager::RemoveSpawner(const LWOOBJID id)
{
void dZoneManager::RemoveSpawner(const LWOOBJID id) {
auto* spawner = GetSpawner(id);
if (spawner == nullptr) {
@@ -196,16 +190,13 @@ void dZoneManager::RemoveSpawner(const LWOOBJID id)
if (entity != nullptr) {
entity->Kill();
}
else {
} else {
Game::logger->Log("dZoneManager", "Failed to find spawner entity (%llu)", id);
}
for (auto* node : spawner->m_Info.nodes)
{
for (const auto& element : node->entities)
{
for (auto* node : spawner->m_Info.nodes) {
for (const auto& element : node->entities) {
auto* nodeEntity = EntityManager::Instance()->GetEntity(element);
if (nodeEntity == nullptr) continue;

View File

@@ -17,14 +17,14 @@ public:
};
public:
static dZoneManager* Instance() {
static dZoneManager* Instance() {
if (!m_Address) {
m_Address = new dZoneManager();
}
return m_Address;
}
void Initialize(const LWOZONEID& zoneID);
~dZoneManager();
@@ -54,12 +54,12 @@ private:
* The ratio of LEGO Score to currency when the character has hit the max level.
*/
int32_t m_CurrencyConversionRate = 0;
static dZoneManager* m_Address; //Singleton
static dZoneManager* m_Address; //Singleton
Zone* m_pZone;
LWOZONEID m_ZoneID;
bool m_PlayerLoseCoinsOnDeath; //Do players drop coins in this zone when smashed
std::map<LWOOBJID, Spawner*> m_Spawners;
bool m_PlayerLoseCoinsOnDeath; //Do players drop coins in this zone when smashed
std::map<LWOOBJID, Spawner*> m_Spawners;
Entity* m_ZoneControlObject;
};