chore: Eradicate C-style casts and further clean up some code (#1361)

* cast and code cleanup

* cast cleanup

* bug fixes and improvements

* no getBoolField method exists

* fixes

* unbroke sg cannon scoring

* removing comments

* Remove the c-style cast warning I added from CMakeLists now that they're gone (it triggers on 3rd party dependencies and slows down compilation)

* (Hopefully) fix MacOS compilation error

* partially-implemented feedback

* more updates to account for feedback

* change bool default

---------

Co-authored-by: jadebenn <jonahebenn@yahoo.com>
This commit is contained in:
jadebenn
2023-12-27 22:18:20 -06:00
committed by GitHub
parent 46ac039a3b
commit ef6f2f133e
68 changed files with 281 additions and 270 deletions

View File

@@ -52,7 +52,7 @@ void NpcAgCourseStarter::OnMessageBoxResponse(Entity* self, Entity* sender, int3
time_t startTime = std::time(0) + 4; // Offset for starting timer
data->values[1] = *(float*)&startTime;
data->values[1] = *reinterpret_cast<float*>(&startTime);
Game::entityManager->SerializeEntity(self);
} else if (identifier == u"FootRaceCancel") {
@@ -81,9 +81,9 @@ void NpcAgCourseStarter::OnFireEventServerSide(Entity* self, Entity* sender, std
scriptedActivityComponent->RemoveActivityPlayerData(sender->GetObjectID());
} else if (args == "course_finish") {
time_t endTime = std::time(0);
time_t finish = (endTime - *(time_t*)&data->values[1]);
time_t finish = (endTime - *reinterpret_cast<time_t*>(&data->values[1]));
data->values[2] = *(float*)&finish;
data->values[2] = *reinterpret_cast<float*>(&finish);
auto* missionComponent = sender->GetComponent<MissionComponent>();
if (missionComponent != nullptr) {

View File

@@ -99,7 +99,7 @@ void AmDrawBridge::MoveBridgeDown(Entity* self, Entity* bridge, bool down) {
const auto travelTime = 2.0f;
forwardVect = forwardVect * (float)((degrees / travelTime) * (3.14f / 180.0f));
forwardVect = forwardVect * static_cast<float>((degrees / travelTime) * (3.14f / 180.0f));
simplePhysicsComponent->SetAngularVelocity(forwardVect);

View File

@@ -4,7 +4,7 @@
#include "Amf3.h"
void NsLegoClubDoor::OnStartup(Entity* self) {
self->SetVar(u"currentZone", (int32_t)Game::zoneManager->GetZoneID().GetMapID());
self->SetVar(u"currentZone", static_cast<int32_t>(Game::zoneManager->GetZoneID().GetMapID()));
self->SetVar(u"choiceZone", m_ChoiceZoneID);
self->SetVar(u"teleportAnim", m_TeleportAnim);
self->SetVar(u"teleportString", m_TeleportString);

View File

@@ -4,7 +4,7 @@
#include "Amf3.h"
void NsLupTeleport::OnStartup(Entity* self) {
self->SetVar(u"currentZone", (int32_t)Game::zoneManager->GetZoneID().GetMapID());
self->SetVar(u"currentZone", static_cast<int32_t>(Game::zoneManager->GetZoneID().GetMapID()));
self->SetVar(u"choiceZone", m_ChoiceZoneID);
self->SetVar(u"teleportAnim", m_TeleportAnim);
self->SetVar(u"teleportString", m_TeleportString);

View File

@@ -437,7 +437,7 @@ std::vector<Wave> ZoneNsWaves::GetWaves() {
}, {}, {},
"Treasure_Camera",
5.0f,
(uint32_t)-1,
static_cast<uint32_t>(-1),
true,
60,
},

View File

@@ -53,9 +53,9 @@ void NjMonastryBossInstance::OnPlayerLoaded(Entity* self, Entity* player) {
// Buff the player
auto* destroyableComponent = player->GetComponent<DestroyableComponent>();
if (destroyableComponent != nullptr) {
destroyableComponent->SetHealth((int32_t)destroyableComponent->GetMaxHealth());
destroyableComponent->SetArmor((int32_t)destroyableComponent->GetMaxArmor());
destroyableComponent->SetImagination((int32_t)destroyableComponent->GetMaxImagination());
destroyableComponent->SetHealth(static_cast<int32_t>(destroyableComponent->GetMaxHealth()));
destroyableComponent->SetArmor(static_cast<int32_t>(destroyableComponent->GetMaxArmor()));
destroyableComponent->SetImagination(static_cast<int32_t>(destroyableComponent->GetMaxImagination()));
}
// Add player ID to instance
@@ -117,7 +117,7 @@ void NjMonastryBossInstance::OnPlayerExit(Entity* self, Entity* player) {
void NjMonastryBossInstance::OnActivityTimerDone(Entity* self, const std::string& name) {
auto split = GeneralUtils::SplitString(name, TimerSplitChar);
auto timerName = split[0];
auto objectID = split.size() > 1 ? (LWOOBJID)std::stoull(split[1]) : LWOOBJID_EMPTY;
auto objectID = split.size() > 1 ? static_cast<LWOOBJID>(std::stoull(split[1])) : LWOOBJID_EMPTY;
if (timerName == WaitingForPlayersTimer) {
StartFight(self);
@@ -309,7 +309,7 @@ void NjMonastryBossInstance::HandleLowerFrakjawSpawned(Entity* self, Entity* low
if (destroyableComponent != nullptr) {
const auto doubleHealth = destroyableComponent->GetHealth() * 2;
destroyableComponent->SetHealth(doubleHealth);
destroyableComponent->SetMaxHealth((float_t)doubleHealth);
destroyableComponent->SetMaxHealth(static_cast<float_t>(doubleHealth));
}
ActivityTimerStart(self, FrakjawSpawnInTimer + std::to_string(lowerFrakjaw->GetObjectID()),
@@ -328,7 +328,7 @@ void NjMonastryBossInstance::HandleLowerFrakjawHit(Entity* self, Entity* lowerFr
return;
// Progress the fight to the last wave if frakjaw has less than 50% of his health left
if (destroyableComponent->GetHealth() <= (uint32_t)destroyableComponent->GetMaxHealth() / 2 && !self->GetVar<bool>(OnLastWaveVarbiale)) {
if (destroyableComponent->GetHealth() <= static_cast<uint32_t>(destroyableComponent->GetMaxHealth()) / 2 && !self->GetVar<bool>(OnLastWaveVarbiale)) {
self->SetVar<bool>(OnLastWaveVarbiale, true);
// Stun frakjaw during the cinematic

View File

@@ -115,7 +115,7 @@ void BaseSurvivalServer::BasePlayerExit(Entity* self, Entity* player) {
SetActivityValue(self, player->GetObjectID(), 1, 0);
self->SetNetworkVar<uint32_t>(NumberOfPlayersVariable,
std::min((uint32_t)0, self->GetNetworkVar<uint32_t>(NumberOfPlayersVariable) - 1));
std::min(static_cast<uint32_t>(0), self->GetNetworkVar<uint32_t>(NumberOfPlayersVariable) - 1));
}
void BaseSurvivalServer::BaseFireEvent(Entity* self, Entity* sender, const std::string& args, int32_t param1, int32_t param2,
@@ -370,7 +370,7 @@ void BaseSurvivalServer::GameOver(Entity* self) {
for (const auto& survivalMission : missionsToUpdate) {
auto* mission = missionComponent->GetMission(survivalMission.first);
if (mission != nullptr && (uint32_t)time >= survivalMission.second
if (mission != nullptr && static_cast<uint32_t>(time) >= survivalMission.second
&& (mission->GetMissionState() == eMissionState::ACTIVE
|| mission->GetMissionState() == eMissionState::COMPLETE_ACTIVE)) {
@@ -421,7 +421,7 @@ void BaseSurvivalServer::SpawnerReset(SpawnerNetworkCollection& spawnerNetworkCo
}
}
state.totalSpawned = std::max((uint32_t)totalSpawned, state.totalSpawned);
state.totalSpawned = std::max(static_cast<uint32_t>(totalSpawned), state.totalSpawned);
}
void BaseSurvivalServer::SpawnerUpdate(Entity* self, SpawnerNetworkCollection& spawnerNetworkCollection, uint32_t amount) {

View File

@@ -95,7 +95,7 @@ void BaseWavesServer::BasePlayerExit(Entity* self, Entity* player) {
SetActivityValue(self, player->GetObjectID(), 2, 0);
self->SetNetworkVar<uint32_t>(NumberOfPlayersVariable,
std::min((uint32_t)0, self->GetNetworkVar<uint32_t>(NumberOfPlayersVariable) - 1));
std::min(static_cast<uint32_t>(0), self->GetNetworkVar<uint32_t>(NumberOfPlayersVariable) - 1));
}
// Done
@@ -212,7 +212,7 @@ void BaseWavesServer::OnActivityTimerDone(Entity* self, const std::string& name)
const auto currentTime = ActivityTimerGetCurrentTime(self, ClockTickTimer);
const auto currentWave = state.waveNumber;
self->SetNetworkVar<uint32_t>(WaveCompleteVariable, { currentWave, (uint32_t)currentTime });
self->SetNetworkVar<uint32_t>(WaveCompleteVariable, { currentWave, static_cast<uint32_t>(currentTime) });
} else if (name == GameOverWinTimer) {
GameOver(self, true);
} else if (name == CinematicDoneTimer) {
@@ -421,7 +421,7 @@ void BaseWavesServer::SpawnWave(Entity* self) {
const auto wave = waves.at(state.waveNumber);
// Handles meta info to the client about the current round
if (wave.winDelay != (uint32_t)-1) {
if (wave.winDelay != static_cast<uint32_t>(-1)) {
self->SetNetworkVar<bool>(WonWaveVariable, true);
// Close the game if we don't expect a notification from an other entity to end it
@@ -436,7 +436,7 @@ void BaseWavesServer::SpawnWave(Entity* self) {
}
}
} else {
if (wave.timeLimit != (uint32_t)-1) {
if (wave.timeLimit != static_cast<uint32_t>(-1)) {
ActivityTimerStart(self, TimedWaveTimer, 1.0f, wave.timeLimit);
self->SetNetworkVar<uint32_t>(StartTimedWaveVariable, { wave.timeLimit, state.waveNumber + 1 });
} else {
@@ -548,7 +548,7 @@ bool BaseWavesServer::UpdateSpawnedEnemies(Entity* self, LWOOBJID enemyID, uint3
}
// Might seem odd to send the next wave but the client isn't 0-indexed so it thinks it completed the correct wave
self->SetNetworkVar<uint32_t>(WaveCompleteVariable, { state.waveNumber, (uint32_t)currentTime });
self->SetNetworkVar<uint32_t>(WaveCompleteVariable, { state.waveNumber, static_cast<uint32_t>(currentTime) });
return true;
}

View File

@@ -171,7 +171,7 @@ void SGCannon::SuperChargeTimerFunc(Entity* self) {
void SGCannon::SpawnWaveTimerFunc(Entity* self) {
if (self->GetVar<bool>(GameStartedVariable)) {
self->SetVar<bool>(WaveStatusVariable, true);
const auto wave = (int32_t)self->GetVar<uint32_t>(ThisWaveVariable);
const auto wave = static_cast<int32_t>(self->GetVar<uint32_t>(ThisWaveVariable));
if (wave != 0 && self->GetVar<bool>(SuperChargePausedVariable)) {
StartChargedCannon(self, self->GetVar<uint32_t>(CurrentSuperChargedTimeVariable));
@@ -187,7 +187,7 @@ void SGCannon::SpawnWaveTimerFunc(Entity* self) {
LOG("Current wave spawn: %i/%i", wave, m_Waves.size());
// All waves completed
const auto timeLimit = (float_t)self->GetVar<uint32_t>(TimeLimitVariable);
const auto timeLimit = static_cast<float_t>(self->GetVar<uint32_t>(TimeLimitVariable));
if (wave >= m_Waves.size()) {
ActivityTimerStart(self, GameOverTimer, timeLimit, timeLimit);
} else {
@@ -262,7 +262,7 @@ void SGCannon::GameOverTimerFunc(Entity* self) {
void SGCannon::DoSpawnTimerFunc(Entity* self, const std::string& name) {
if (self->GetVar<bool>(GameStartedVariable)) {
LOG_DEBUG("time name %s %s", name.c_str(), name.substr(7).c_str());
const auto spawnNumber = (uint32_t)std::stoi(name.substr(7));
const auto spawnNumber = static_cast<uint32_t>(std::stoi(name.substr(7)));
const auto& activeSpawns = self->GetVar<std::vector<SGEnemy>>(ActiveSpawnsVariable);
LOG_DEBUG("size %i, %i", activeSpawns.size(), spawnNumber);
if (activeSpawns.size() <= spawnNumber) {
@@ -518,7 +518,7 @@ void SGCannon::SpawnObject(Entity* self, const SGEnemy& toSpawn, bool spawnNow)
}
void SGCannon::RecordPlayerScore(Entity* self) {
const auto totalScore = self->GetVar<uint32_t>(TotalScoreVariable);
const auto totalScore = self->GetVar<int32_t>(TotalScoreVariable);
const auto currentWave = self->GetVar<uint32_t>(ThisWaveVariable);
if (currentWave > 0) {
@@ -555,7 +555,7 @@ void SGCannon::PlaySceneAnimation(Entity* self, const std::u16string& animationN
}
void SGCannon::PauseChargeCannon(Entity* self) {
const auto time = std::max((uint32_t)std::ceil(ActivityTimerGetCurrentTime(self, SuperChargeTimer)), (uint32_t)1);
const auto time = std::max(static_cast<uint32_t>(std::ceil(ActivityTimerGetCurrentTime(self, SuperChargeTimer))), static_cast<uint32_t>(1));
self->SetVar<bool>(SuperChargePausedVariable, true);
self->SetVar<uint32_t>(CurrentSuperChargedTimeVariable, time);
@@ -587,17 +587,17 @@ void SGCannon::StopGame(Entity* self, bool cancel) {
auto* missionComponent = player->GetComponent<MissionComponent>();
if (missionComponent != nullptr) {
missionComponent->Progress(eMissionTaskType::PERFORM_ACTIVITY, self->GetVar<uint32_t>(TotalScoreVariable), self->GetObjectID(), "performact_score");
missionComponent->Progress(eMissionTaskType::PERFORM_ACTIVITY, self->GetVar<int32_t>(TotalScoreVariable), self->GetObjectID(), "performact_score");
missionComponent->Progress(eMissionTaskType::PERFORM_ACTIVITY, self->GetVar<uint32_t>(MaxStreakVariable), self->GetObjectID(), "performact_streak");
missionComponent->Progress(eMissionTaskType::ACTIVITY, m_CannonLot, 0, "", self->GetVar<uint32_t>(TotalScoreVariable));
missionComponent->Progress(eMissionTaskType::ACTIVITY, m_CannonLot, 0, "", self->GetVar<int32_t>(TotalScoreVariable));
}
Loot::GiveActivityLoot(player, self, GetGameID(self), self->GetVar<uint32_t>(TotalScoreVariable));
Loot::GiveActivityLoot(player, self, GetGameID(self), self->GetVar<int32_t>(TotalScoreVariable));
SaveScore(self, player->GetObjectID(),
static_cast<float>(self->GetVar<uint32_t>(TotalScoreVariable)), static_cast<float>(self->GetVar<uint32_t>(MaxStreakVariable)), percentage);
static_cast<float>(self->GetVar<int32_t>(TotalScoreVariable)), static_cast<float>(self->GetVar<uint32_t>(MaxStreakVariable)), percentage);
StopActivity(self, player->GetObjectID(), self->GetVar<uint32_t>(TotalScoreVariable), self->GetVar<uint32_t>(MaxStreakVariable), percentage);
StopActivity(self, player->GetObjectID(), self->GetVar<int32_t>(TotalScoreVariable), self->GetVar<uint32_t>(MaxStreakVariable), percentage);
self->SetNetworkVar<bool>(AudioFinalWaveDoneVariable, true);
// Give the player the model rewards they earned
@@ -609,7 +609,7 @@ void SGCannon::StopGame(Entity* self, bool cancel) {
}
self->SetNetworkVar<std::u16string>(u"UI_Rewards",
GeneralUtils::to_u16string(self->GetVar<uint32_t>(TotalScoreVariable)) + u"_0_0_0_0_0_0"
GeneralUtils::to_u16string(self->GetVar<int32_t>(TotalScoreVariable)) + u"_0_0_0_0_0_0"
);
}
@@ -634,7 +634,7 @@ void SGCannon::RegisterHit(Entity* self, Entity* target, const std::string& time
ActivityTimerStart(self, timerName, respawnTime, respawnTime);
}
int score = spawnInfo.score;
int32_t score = spawnInfo.score;
if (score > 0) {
score += score * GetCurrentBonus(self);
@@ -652,7 +652,7 @@ void SGCannon::RegisterHit(Entity* self, Entity* target, const std::string& time
auto lastSuperTotal = self->GetVar<uint32_t>(u"LastSuperTotal");
auto scScore = self->GetVar<uint32_t>(TotalScoreVariable) - lastSuperTotal;
auto scScore = self->GetVar<int32_t>(TotalScoreVariable) - lastSuperTotal;
LOG("LastSuperTotal: %i, scScore: %i, constants.chargedPoints: %i",
lastSuperTotal, scScore, constants.chargedPoints
@@ -661,7 +661,7 @@ void SGCannon::RegisterHit(Entity* self, Entity* target, const std::string& time
if (!self->GetVar<bool>(SuperChargeActiveVariable) && scScore >= constants.chargedPoints && score >= 0) {
StartChargedCannon(self);
self->SetNetworkVar<float>(u"SuperChargeBar", 100.0f);
self->SetVar<uint32_t>(u"LastSuperTotal", self->GetVar<uint32_t>(TotalScoreVariable));
self->SetVar<uint32_t>(u"LastSuperTotal", self->GetVar<int32_t>(TotalScoreVariable));
}
UpdateStreak(self);
@@ -673,13 +673,13 @@ void SGCannon::RegisterHit(Entity* self, Entity* target, const std::string& time
target->GetPosition()
);
auto newScore = (int)self->GetVar<uint32_t>(TotalScoreVariable) + score;
auto newScore = self->GetVar<int32_t>(TotalScoreVariable) + score;
if (newScore < 0) {
newScore = 0;
}
self->SetVar<uint32_t>(TotalScoreVariable, newScore);
self->SetVar<int32_t>(TotalScoreVariable, newScore);
self->SetNetworkVar<uint32_t>(u"updateScore", newScore);
@@ -1038,7 +1038,7 @@ void SGCannon::ResetVars(Entity* self) {
self->SetVar<uint32_t>(LastSuperTotalVariable, 0);
self->SetVar<LOT>(CurrentRewardVariable, LOT_NULL);
self->SetVar<std::vector<LOT>>(RewardsVariable, {});
self->SetVar<uint32_t>(TotalScoreVariable, 0);
self->SetVar<int32_t>(TotalScoreVariable, 0);
self->SetVar<uint32_t>(u"m_curStreak", 0);
self->SetNetworkVar<float>(u"SuperChargeBar", 0);

View File

@@ -30,8 +30,8 @@ void FvRaceSmashEggImagineServer::OnDie(Entity* self, Entity* killer) {
}
if (missionComponent == nullptr) return;
// Dragon eggs have their own smash server so we handle mission progression for them here.
missionComponent->Progress(eMissionTaskType::RACING, 0, (LWOOBJID)eRacingTaskParam::SMASHABLES);
missionComponent->Progress(eMissionTaskType::RACING, self->GetLOT(), (LWOOBJID)eRacingTaskParam::SMASH_SPECIFIC_SMASHABLE);
missionComponent->Progress(eMissionTaskType::RACING, 0, static_cast<LWOOBJID>(eRacingTaskParam::SMASHABLES));
missionComponent->Progress(eMissionTaskType::RACING, self->GetLOT(), static_cast<LWOOBJID>(eRacingTaskParam::SMASH_SPECIFIC_SMASHABLE));
}
}

View File

@@ -50,7 +50,7 @@ void RaceImagineCrateServer::OnDie(Entity* self, Entity* killer) {
// Progress racing smashable missions
if (missionComponent == nullptr) return;
missionComponent->Progress(eMissionTaskType::RACING, 0, (LWOOBJID)eRacingTaskParam::SMASHABLES);
missionComponent->Progress(eMissionTaskType::RACING, 0, static_cast<LWOOBJID>(eRacingTaskParam::SMASHABLES));
}
}
}

View File

@@ -32,6 +32,6 @@ void RaceImaginePowerup::OnFireEventServerSide(Entity* self, Entity* sender, std
auto* missionComponent = sender->GetComponent<MissionComponent>();
if (missionComponent == nullptr) return;
missionComponent->Progress(eMissionTaskType::RACING, self->GetLOT(), (LWOOBJID)eRacingTaskParam::COLLECT_IMAGINATION);
missionComponent->Progress(eMissionTaskType::RACING, self->GetLOT(), static_cast<LWOOBJID>(eRacingTaskParam::COLLECT_IMAGINATION));
}
}

View File

@@ -23,9 +23,9 @@ void RaceSmashServer::OnDie(Entity* self, Entity* killer) {
// Progress racing smashable missions
if (missionComponent == nullptr) return;
missionComponent->Progress(eMissionTaskType::RACING, 0, (LWOOBJID)eRacingTaskParam::SMASHABLES);
missionComponent->Progress(eMissionTaskType::RACING, 0, static_cast<LWOOBJID>(eRacingTaskParam::SMASHABLES));
// Progress missions that ask us to smash a specific smashable.
missionComponent->Progress(eMissionTaskType::RACING, self->GetLOT(), (LWOOBJID)eRacingTaskParam::SMASH_SPECIFIC_SMASHABLE);
missionComponent->Progress(eMissionTaskType::RACING, self->GetLOT(), static_cast<LWOOBJID>(eRacingTaskParam::SMASH_SPECIFIC_SMASHABLE));
}
}
}