rodecomp/Source/Contents/Effects/JupitelThunderStormEffect.cpp
ragnarok-clanker e61e97867b Decompile fn_07045 (CJupitelThunderStormEffect::OnProcess)
Batch #15625 by Yommy: 0 byte-identical, 1 confirmed by peer review.

- fn_07045 CJupitelThunderStormEffect::OnProcess: logic confirmed by peer review

Peer-reviewed-by: eAthena, bgamez23
Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes).
2026-11-10 11:39:52 +00:00

157 lines
5.8 KiB
C++

#include "Contents/Effects/JupitelThunderStormEffect.h"
#include "Client/Mode/CGameMode.h"
#include "Client/Mode/ModeMgr.h"
#include "Contents/Camera/Camera.h"
#include "Contents/Effects/EZ2STREffectEx.h"
#include "Contents/Effects/EffectMemoryMgr.h"
#include "Contents/Effects/Particle.h"
#include "Contents/MapSkyMgr.h"
#include "Utility/Math/AffineMatrix.h"
#include "Utility/Text/FormatString.h"
#include <algorithm>
#include <cstdlib>
#include <string>
// INLINED
static __forceinline bool ParticleAlive(const CParticle* particle) {
if (0.0f == particle->life) {
return true;
}
return particle->life * 60.0f > static_cast<float>(particle->elapsedFrames);
}
// OFFSET: 0x00705F80
// FUNCTION: fn_07040
CJupitelThunderStormEffect::CJupitelThunderStormEffect() : CEffect(2366), particle(nullptr), step{}, duration(10) {
}
// OFFSET: 0x00706110
// FUNCTION: fn_07042
void CJupitelThunderStormEffect::Close() {
if (this->particle) {
FreeParticle(this->particle);
this->particle = nullptr;
}
for (std::vector<CParticle*>::iterator it = this->particles.begin(); it != this->particles.end(); ++it) {
if (*it) {
FreeParticle(*it);
}
}
this->particles.clear();
}
// OFFSET: 0x00706180
// FUNCTION: fn_07043
void CJupitelThunderStormEffect::Open() {
const float dy = this->sourcePosition[1] - this->position[1];
const float dx = this->sourcePosition[0] - this->position[0];
const float dz = this->sourcePosition[2] - this->position[2];
const float speed = SquareRoot(dy * dy + dx * dx + dz * dz) / static_cast<float>(this->duration);
this->step.x = this->sourcePosition[0] - this->position[0];
this->step.y = this->sourcePosition[1] - this->position[1];
this->step.z = this->sourcePosition[2] - this->position[2];
const float scale = 1.0f / SquareRoot(this->step.x * this->step.x + this->step.y * this->step.y + this->step.z * this->step.z);
this->step.x = scale * this->step.x * speed;
this->step.y = scale * this->step.y * speed;
this->step.z = scale * this->step.z * speed;
const float angle = ScreenAngle(this->position, this->sourcePosition, static_cast<CGameMode*>(g_modeMgr.GetGameMode())->camera->frame.view.values);
CEZ2STRParticle* ball = static_cast<CEZ2STRParticle*>(CreateEZ2STRParticle(reinterpret_cast<const vector3d*>(this->position), 5));
this->particle = ball;
if (ball) {
ball->Load(std::string("HYPER_NOVICE\\HN_JUPITEL_THUNDER_STORM\\jupitel_thunder_storm_ball\\jupitel_thunder_storm_ball.str"));
static_cast<CEZ2STRParticle*>(this->particle)->m_angle = angle;
}
int corners[4][2] = {{-1, 1}, {1, 1}, {-1, -1}, {1, -1}};
int index = 0;
const int rings = (this->effectLevel - 1) / 4;
const int lastDelay = ((this->effectLevel - 1) / 2 + 6) * 150;
for (int delay = 80; delay <= lastDelay; delay += 80, ++index) {
CEZ2STRParticle* bolt = static_cast<CEZ2STRParticle*>(CreateEZ2STRParticle(reinterpret_cast<const vector3d*>(this->position), 5));
if (!bolt) {
continue;
}
const int range = (rings * 10 + 25) / 2;
const int corner = index % 4;
int offsetX = 0;
float offsetZ;
if (range == 0) {
offsetZ = static_cast<float>(corners[corner][1]) * g_depthAverageHalf;
} else {
const int randomZ = rand() % range;
offsetX = std::max(rand() % range, 0);
offsetZ = (static_cast<float>(std::max(randomZ, 0)) + g_depthAverageHalf) * static_cast<float>(corners[corner][1]);
}
bolt->Load(FormatOwnedString("HYPER_NOVICE\\HN_JUPITEL_THUNDER_STORM\\jupitel_thunder_storm\\jupitel_thunder_storm_%02d.str", std::max(rand() % 3, 0)));
bolt->position.z = offsetZ + this->sourcePosition[2];
bolt->position.y = this->sourcePosition[1] - 15.0f;
bolt->position.x = static_cast<float>(corners[corner][0]) * (static_cast<float>(offsetX) + g_depthAverageHalf) + this->sourcePosition[0];
bolt->m_delay = delay;
this->particles.push_back(bolt);
if (corner == 0) {
this->AddEvent(0, "effect\\HYPER_NOVICE\\hu_jupitel_thunder_storm.wav", delay / 16 + 1, 0);
}
}
}
// OFFSET: 0x007065F0
// FUNCTION: fn_07044
bool CJupitelThunderStormEffect::IsAlive() {
if (this->particle && ParticleAlive(this->particle)) {
return true;
}
return std::find_if(this->particles.begin(), this->particles.end(),
[](const CParticle* particle) { return particle && ParticleAlive(particle); }) != this->particles.end();
}
// OFFSET: 0x00706690
// FUNCTION: fn_07045
void CJupitelThunderStormEffect::OnProcess() {
if (CParticle* particle = this->particle) {
if (!ParticleAlive(particle)) {
FreeParticle(particle);
this->particle = nullptr;
} else {
vector3d position;
if (this->frame < this->duration) {
position.x = particle->position.x + this->step.x;
position.y = particle->position.y + this->step.y;
position.z = particle->position.z + this->step.z;
} else {
position = *reinterpret_cast<const vector3d*>(this->sourcePosition);
}
particle->position.x = position.x;
particle->position.y = position.y;
particle->position.z = position.z;
static_cast<CEZ2STRParticle*>(this->particle)->Process(0.0f, 0.0f, 0.0f);
}
}
for (std::vector<CParticle*>::iterator it = this->particles.begin(); it != this->particles.end(); ++it) {
if (*it) {
static_cast<CEZ2STRParticle*>(*it)->Process(0.0f, 0.0f, 0.0f);
}
}
}
// OFFSET: 0x007067C0
// FUNCTION: fn_07046
void CJupitelThunderStormEffect::Render() {
if (this->particle) {
static_cast<CEZ2STRParticle*>(this->particle)->DrawScreen(static_cast<CGameMode*>(g_modeMgr.GetGameMode())->camera->frame.view);
}
for (std::vector<CParticle*>::iterator it = this->particles.begin(); it != this->particles.end(); ++it) {
if (*it) {
static_cast<CEZ2STRParticle*>(*it)->DrawScreen(static_cast<CGameMode*>(g_modeMgr.GetGameMode())->camera->frame.view);
}
}
}