Compare commits

..

1 Commits

Author SHA1 Message Date
jadebenn
81b4f84d03 move IsDead to the DestroyableComponent 2024-12-24 23:00:49 -06:00
21 changed files with 156 additions and 152 deletions

View File

@@ -72,7 +72,7 @@ std::string FdbToSqlite::Convert::ReadString(std::istream& cdClientBuffer) {
const auto readString = BinaryIO::ReadU8String(cdClientBuffer);
cdClientBuffer.seekg(prevPosition);
return GeneralUtils::Latin1ToUTF8(readString);
return GeneralUtils::Latin1ToWTF8(readString);
}
int32_t FdbToSqlite::Convert::SeekPointer(std::istream& cdClientBuffer) {

View File

@@ -167,18 +167,11 @@ std::u16string GeneralUtils::ASCIIToUTF16(const std::string_view string, const s
return ret;
}
std::string GeneralUtils::Latin1ToUTF8(const std::u8string_view string, const size_t size) {
std::string toReturn{};
for (const auto u : string) {
PushUTF8CodePoint(toReturn, u);
}
return toReturn;
}
//! Converts a (potentially-ill-formed) UTF-16 string to UTF-8
//! Converts a (potentially-ill-formed) Latin1 string to UTF-8
//! See: <http://simonsapin.github.io/wtf-8/#decoding-ill-formed-utf-16>
std::string GeneralUtils::UTF16ToWTF8(const std::u16string_view string, const size_t size) {
template<typename StringType>
std::string ToWTF8(const StringType string, const size_t size) {
const size_t newSize = MinSize(size, string);
std::string ret;
ret.reserve(newSize);
@@ -203,6 +196,13 @@ std::string GeneralUtils::UTF16ToWTF8(const std::u16string_view string, const si
return ret;
}
std::string GeneralUtils::Latin1ToWTF8(const std::u8string_view string, const size_t size) {
return ToWTF8(string, size);
}
std::string GeneralUtils::UTF16ToWTF8(const std::u16string_view string, const size_t size) {
return ToWTF8(string, size);
}
bool GeneralUtils::CaseInsensitiveStringCompare(const std::string_view a, const std::string_view b) {
return std::equal(a.begin(), a.end(), b.begin(), b.end(), [](char a, char b) { return tolower(a) == tolower(b); });

View File

@@ -57,7 +57,7 @@ namespace GeneralUtils {
\param size A size to trim the string to. Default is SIZE_MAX (No trimming)
\return An UTF-8 representation of the string
*/
std::string Latin1ToUTF8(const std::u8string_view string, const size_t size = SIZE_MAX);
std::string Latin1ToWTF8(const std::u8string_view string, const size_t size = SIZE_MAX);
//! Converts a UTF-16 string to a UTF-8 string
/*!

View File

@@ -1378,7 +1378,7 @@ void Entity::OnCollisionPhantom(const LWOOBJID otherEntity) {
}
}
if (!other->GetIsDead()) {
if (!other->GetComponent<DestroyableComponent>()->GetIsDead()) {
if (GetComponent<BaseCombatAIComponent>() != nullptr) {
const auto index = std::find(m_TargetsInPhantom.begin(), m_TargetsInPhantom.end(), otherEntity);
@@ -1606,13 +1606,6 @@ void Entity::AddQuickBuildCompleteCallback(const std::function<void(Entity* user
}
}
bool Entity::GetIsDead() const {
DestroyableComponent* dest = GetComponent<DestroyableComponent>();
if (dest && dest->GetArmor() == 0 && dest->GetHealth() == 0) return true;
return false;
}
void Entity::AddLootItem(const Loot::Info& info) {
if (!IsPlayer()) return;

View File

@@ -82,8 +82,6 @@ public:
const std::vector<LDFBaseData*>& GetNetworkSettings() const { return m_NetworkSettings; }
bool GetIsDead() const;
bool GetPlayerReadyForUpdates() const { return m_PlayerIsReadyForUpdates; }
bool GetIsGhostingCandidate() const;

View File

@@ -227,7 +227,7 @@ void BasicAttackBehavior::DoBehaviorCalculation(BehaviorContext* context, RakNet
bitStream.Write(armorDamageDealt);
bitStream.Write(healthDamageDealt);
bitStream.Write(targetEntity->GetIsDead());
bitStream.Write(targetEntity->GetComponent<DestroyableComponent>()->GetIsDead());
}
bitStream.Write(successState);

View File

@@ -116,7 +116,7 @@ void TacArcBehavior::Calculate(BehaviorContext* context, RakNet::BitStream& bitS
for (auto validTarget : validTargets) {
if (targets.size() >= this->m_maxTargets) break;
if (std::find(targets.begin(), targets.end(), validTarget) != targets.end()) continue;
if (validTarget->GetIsDead()) continue;
if (validTarget->GetComponent<DestroyableComponent>()->GetIsDead()) continue;
const auto targetPos = validTarget->GetPosition();

View File

@@ -193,7 +193,7 @@ void BaseCombatAIComponent::Update(const float deltaTime) {
m_SoftTimer -= deltaTime;
}
if (m_Disabled || m_Parent->GetIsDead())
if (m_Disabled || m_Parent->GetComponent<DestroyableComponent>()->GetIsDead())
return;
bool stunnedThisFrame = m_Stunned;
CalculateCombat(deltaTime); // Putting this here for now

View File

@@ -160,7 +160,7 @@ void GameMessageHandler::HandleMessage(RakNet::BitStream& inStream, const System
}
//Kill player if health == 0
if (entity->GetIsDead()) {
if (entity->GetComponent<DestroyableComponent>()->GetIsDead()) {
entity->Smash(entity->GetObjectID());
}

View File

@@ -16,7 +16,7 @@ void BaseEnemyApe::OnStartup(Entity* self) {
void BaseEnemyApe::OnDie(Entity* self, Entity* killer) {
auto* anchor = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(u"QB"));
if (anchor != nullptr && !anchor->GetIsDead()) {
if (anchor != nullptr && !anchor->GetComponent<DestroyableComponent>()->GetIsDead()) {
anchor->Smash(self->GetObjectID(), eKillType::SILENT);
}
}

View File

@@ -152,13 +152,13 @@ void AmSkullkinDrill::FreezePlayer(Entity* self, Entity* player, bool bFreeze) {
auto StateChangeType = eStateChangeType::POP;
if (bFreeze) {
if (player->GetIsDead()) {
if (player->GetComponent<DestroyableComponent>()->GetIsDead()) {
return;
}
StateChangeType = eStateChangeType::PUSH;
} else {
if (player->GetIsDead()) {
if (player->GetComponent<DestroyableComponent>()->GetIsDead()) {
//
}
}

View File

@@ -54,7 +54,7 @@ void AgSurvivalBuffStation::OnTimerDone(Entity* self, std::string timerName) {
auto team = self->GetVar<std::vector<LWOOBJID>>(u"BuilderTeam");
for (auto memberID : team) {
auto member = Game::entityManager->GetEntity(memberID);
if (member != nullptr && !member->GetIsDead()) {
if (member != nullptr && !member->GetComponent<DestroyableComponent>()->GetIsDead()) {
GameMessages::SendDropClientLoot(member, self->GetObjectID(), powerupToDrop, 0, self->GetPosition());
}
}

View File

@@ -315,7 +315,7 @@ bool BaseSurvivalServer::CheckAllPlayersDead() {
for (const auto& playerID : state.players) {
auto* player = Game::entityManager->GetEntity(playerID);
if (player == nullptr || player->GetIsDead()) {
if (player == nullptr || player->GetComponent<DestroyableComponent>()->GetIsDead()) {
deadPlayers++;
}
}

View File

@@ -310,7 +310,7 @@ bool BaseWavesServer::CheckAllPlayersDead() {
for (const auto& playerID : state.players) {
auto* player = Game::entityManager->GetEntity(playerID);
if (player == nullptr || player->GetIsDead()) {
if (player == nullptr || player->GetComponent<DestroyableComponent>()->GetIsDead()) {
deadPlayers++;
}
}
@@ -431,7 +431,7 @@ void BaseWavesServer::SpawnWave(Entity* self) {
for (const auto& playerID : state.players) {
auto* player = Game::entityManager->GetEntity(playerID);
if (player && player->GetIsDead()) {
if (player && player->GetComponent<DestroyableComponent>()->GetIsDead()) {
player->Resurrect();
}
}
@@ -501,7 +501,7 @@ bool BaseWavesServer::UpdateSpawnedEnemies(Entity* self, LWOOBJID enemyID, uint3
for (const auto& playerID : state.players) {
auto* player = Game::entityManager->GetEntity(playerID);
if (player != nullptr && !player->GetIsDead()) {
if (player != nullptr && !player->GetComponent<DestroyableComponent>()->GetIsDead()) {
SetActivityValue(self, playerID, 1, currentTime);
SetActivityValue(self, playerID, 2, state.waveNumber);

View File

@@ -1,9 +1,9 @@
#include "ActPlayerDeathTrigger.h"
#include "DestroyableComponent.h"
#include "Entity.h"
void ActPlayerDeathTrigger::OnCollisionPhantom(Entity* self, Entity* target) {
if (!target->IsPlayer() || target->GetIsDead() || !target->GetPlayerReadyForUpdates()) return; //Don't kill already dead players or players not ready
if (!target->IsPlayer() || target->GetComponent<DestroyableComponent>()->GetIsDead() || !target->GetPlayerReadyForUpdates()) return; //Don't kill already dead players or players not ready
target->Smash(self->GetObjectID(), eKillType::SILENT);
}

View File

@@ -1,4 +1,5 @@
#include "ActSharkPlayerDeathTrigger.h"
#include "DestroyableComponent.h"
#include "MissionComponent.h"
#include "eMissionTaskType.h"
#include "Entity.h"
@@ -11,7 +12,7 @@ void ActSharkPlayerDeathTrigger::OnFireEventServerSide(Entity* self, Entity* sen
missionComponent->Progress(eMissionTaskType::SCRIPT, 8419);
if (sender->GetIsDead() || !sender->GetPlayerReadyForUpdates()) return; //Don't kill already dead players or players not ready
if (sender->GetComponent<DestroyableComponent>()->GetIsDead() || !sender->GetPlayerReadyForUpdates()) return; //Don't kill already dead players or players not ready
if (sender->GetCharacter()) {
sender->Smash(self->GetObjectID(), eKillType::VIOLENT, u"big-shark-death");

View File

@@ -1,8 +1,9 @@
#include "AgShipPlayerDeathTrigger.h"
#include "DestroyableComponent.h"
#include "Entity.h"
void AgShipPlayerDeathTrigger::OnCollisionPhantom(Entity* self, Entity* target) {
if (target->GetLOT() == 1 && !target->GetIsDead()) {
if (target->GetLOT() == 1 && !target->GetComponent<DestroyableComponent>()->GetIsDead()) {
target->Smash(self->GetObjectID(), eKillType::VIOLENT, u"electro-shock-death");
}
}

View File

@@ -1,4 +1,5 @@
#include "TriggerGas.h"
#include "DestroyableComponent.h"
#include "InventoryComponent.h"
#include "SkillComponent.h"
#include "Entity.h"
@@ -28,7 +29,7 @@ void TriggerGas::OnTimerDone(Entity* self, std::string timerName) {
if (timerName != this->m_TimerName) return;
auto players = self->GetVar<std::vector<Entity*>>(u"players");
for (auto player : players) {
if (player->GetIsDead() || !player){
if (player->GetComponent<DestroyableComponent>()->GetIsDead() || !player){
auto position = std::find(players.begin(), players.end(), player);
if (position != players.end()) players.erase(position);
continue;
@@ -46,4 +47,3 @@ void TriggerGas::OnTimerDone(Entity* self, std::string timerName) {
self->SetVar(u"players", players);
self->AddTimer(this->m_TimerName, this->m_Time);
}

View File

@@ -1,6 +1,7 @@
#include "PetDigBuild.h"
#include "EntityManager.h"
#include "EntityInfo.h"
#include "DestroyableComponent.h"
#include "MissionComponent.h"
#include "eMissionState.h"
@@ -45,7 +46,7 @@ void PetDigBuild::OnDie(Entity* self, Entity* killer) {
return;
// If the quick build expired and the treasure was not collected, hide the treasure
if (!treasure->GetIsDead()) {
if (!treasure->GetComponent<DestroyableComponent>()->GetIsDead()) {
treasure->Smash(self->GetObjectID(), eKillType::SILENT);
}
}

View File

@@ -27,7 +27,7 @@ void NsConcertInstrument::OnQuickBuildNotifyState(Entity* self, eQuickBuildState
}
void NsConcertInstrument::OnQuickBuildComplete(Entity* self, Entity* target) {
if (!target->GetIsDead()) {
if (!target->GetComponent<DestroyableComponent>()->GetIsDead()) {
self->SetVar<LWOOBJID>(u"activePlayer", target->GetObjectID());
self->AddCallbackTimer(0.2f, [self, target]() {

View File

@@ -267,20 +267,35 @@ int main(int argc, char** argv) {
// pre calculate the FDB checksum
if (Game::config->GetValue("check_fdb") == "1") {
auto cdclient = Game::assetManager->GetFile("cdclient.fdb");
if (cdclient) {
std::ifstream fileStream;
static const std::vector<std::string> aliases = {
"CDServers.fdb",
"cdserver.fdb",
"CDClient.fdb",
"cdclient.fdb",
};
for (const auto& file : aliases) {
fileStream.open(Game::assetManager->GetResPath() / file, std::ios::binary | std::ios::in);
if (fileStream.is_open()) {
break;
}
}
const int32_t bufferSize = 1024;
MD5 md5;
char fileStreamBuffer[bufferSize] = {};
char fileStreamBuffer[1024] = {};
while (!cdclient.eof()) {
while (!fileStream.eof()) {
memset(fileStreamBuffer, 0, bufferSize);
cdclient.read(fileStreamBuffer, bufferSize);
md5.update(fileStreamBuffer, cdclient.gcount());
fileStream.read(fileStreamBuffer, bufferSize);
md5.update(fileStreamBuffer, fileStream.gcount());
}
fileStream.close();
const char* nullTerminateBuffer = "\0";
md5.update(nullTerminateBuffer, 1); // null terminate the data
md5.finalize();
@@ -288,11 +303,6 @@ int main(int argc, char** argv) {
LOG("FDB Checksum calculated as: %s", databaseChecksum.c_str());
}
if (databaseChecksum.empty()) {
LOG("check_fdb is on but no fdb file found.");
return EXIT_FAILURE;
}
}
uint32_t currentFrameDelta = highFrameDelta;
// These values are adjust them selves to the current framerate should it update.