Upgraded to new APIs

This commit is contained in:
wincent
2023-10-07 15:15:15 +02:00
parent 2097dbfff1
commit 89339d3003
7 changed files with 18 additions and 109 deletions

View File

@@ -3,5 +3,6 @@ set(DZONEMANAGER_SOURCES "dZoneManager.cpp"
"Spawner.cpp"
"Zone.cpp")
set(DZONEMANAGER_SOURCES ${DZONEMANAGER_SOURCES} PARENT_SCOPE)
add_library(dZoneManager STATIC ${DZONEMANAGER_SOURCES})
target_link_libraries(dZoneManager dPhysics)
# target_link_libraries(dZoneManager dPhysics)

View File

@@ -166,100 +166,11 @@ Entity* Spawner::Spawn(std::vector<SpawnerNode*> freeNodes, const bool force) {
m_LotsToCheck.push_back(spawn);
}
Entity* rezdE = EntityManager::Instance()->CreateEntity(copy, nullptr);
Entity* rezdE = Game::entityManager->CreateEntity(copy, nullptr);
rezdE->GetGroups() = m_Info.groups;
EntityManager::Instance()->ConstructEntity(rezdE);
m_Entities.insert({ rezdE->GetObjectID(), spawnNode });
spawnNode->entities.push_back(rezdE->GetObjectID());
for (const auto& cb : m_EntitySpawnedCallbacks) {
cb(rezdE);
}
if (first == nullptr) {
first = rezdE;
}
break;
}
usedSpawnPattern = true;
if (m_Entities.size() == m_Info.amountMaintained) {
m_NeedsUpdate = false;
}
return first;
}
}
}
bool usedSpawnPattern = false;
if (m_SpawnPattern != nullptr) {
auto pattern = m_SpawnPattern->GetSpawnPatterns();
// Check the area rating
// std::map<LOT, std::vector<std::pair<NiPoint3, float>>> m_Ratings
for (const auto& lot : m_LotsToCheck)
{
const auto& it = m_Ratings.find(lot);
int32_t rating = 0;
if (it != m_Ratings.end()) {
// Check if we are within 50units of a rating
for (const auto& ratingIt : it->second)
{
if (NiPoint3::DistanceSquared(ratingIt.first, m_EntityInfo.pos) <= 100.0f * 100.0f)
{
rating = ratingIt.second;
break;
}
}
}
for (const auto& it : pattern)
{
if (it.first > rating) continue;
// Random number between 0 and 1
float random = GeneralUtils::GenerateRandomNumber<float>(0, 1);
const auto& change = it.second.first;
if (random >= change) continue;
usedSpawnPattern = true;
Entity* first = nullptr;
for (const auto& spawn : it.second.second)
{
float angle = GeneralUtils::GenerateRandomNumber<float>(0, 360) * M_PI / 180.0f;
float radius = GeneralUtils::GenerateRandomNumber<float>(0, 6);
float x = radius * cos(angle);
float z = radius * sin(angle);
auto copy = m_EntityInfo;
copy.pos.x += x;
copy.pos.z += z;
copy.lot = spawn;
if (std::find(m_LotsToCheck.begin(), m_LotsToCheck.end(), spawn) == m_LotsToCheck.end()) {
m_LotsToCheck.push_back(spawn);
}
Entity* rezdE = EntityManager::Instance()->CreateEntity(copy, nullptr);
rezdE->GetGroups() = m_Info.groups;
EntityManager::Instance()->ConstructEntity(rezdE);
Game::entityManager->ConstructEntity(rezdE);
m_Entities.insert({ rezdE->GetObjectID(), spawnNode });

View File

@@ -13,7 +13,7 @@
#include "CDZoneTableTable.h"
#include "Spawner.h"
#include "dZoneManager.h"
#include "dpWorld.h"
//#include "dpWorld.h"
#include "eTriggerCommandType.h"
#include "eTriggerEventType.h"
@@ -557,12 +557,13 @@ void Zone::LoadPath(std::istream& file) {
}
// We verify the waypoint heights against the navmesh because in many movement paths,
// the waypoint is located near 0 height,
if (path.pathType == PathType::Movement) {
/*if (path.pathType == PathType::Movement) {
if (dpWorld::Instance().IsLoaded()) {
// 2000 should be large enough for every world.
waypoint.position.y = dpWorld::Instance().GetNavMesh()->GetHeightAtPoint(waypoint.position, 2000.0f);
}
}
*/
path.pathWaypoints.push_back(waypoint);
}
m_Paths.push_back(path);