rodecomp/Source/Contents/Effects/CartCannon.cpp
ragnarok-clanker ea6accf842 Decompile fn_06897 (CCartCannon::Open)
Batch #15695 by Yommy: 0 byte-identical, 1 confirmed by peer review.

- fn_06897 CCartCannon::Open: logic confirmed by peer review

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

156 lines
4.7 KiB
C++

#include "Contents/Effects/CartCannon.h"
#include "Client/Mode/CGameMode.h"
#include "Client/Mode/ModeMgr.h"
#include "Contents/Camera/Camera.h"
#include "Contents/Configuration/ServiceOptions.h"
#include "Contents/Effects/EffectMemoryMgr.h"
#include "Utility/Math/AffineMatrix.h"
#include <cmath>
// OFFSET: 0x006FA900
// FUNCTION: fn_06894
CCartCannon::CCartCannon() : CEffect(-1) {
this->currentPosition.x = 0.0f;
this->currentPosition.y = 0.0f;
this->currentPosition.z = 0.0f;
this->stepDelta.x = 0.0f;
this->stepDelta.y = 0.0f;
this->stepDelta.z = 0.0f;
this->startPosition.x = 0.0f;
this->startPosition.y = 0.0f;
this->startPosition.z = 0.0f;
this->rotationParameter = 0;
}
// OFFSET: 0x006FAA80
// FUNCTION: fn_06896
void CCartCannon::Close() {
FreeParticle(this->particle);
}
// OFFSET: 0x006FAA90
// FUNCTION: fn_06897
void CCartCannon::Open() {
this->currentPosition.x = this->position[0];
this->currentPosition.y = this->position[1];
this->currentPosition.z = this->position[2];
CEZ2STRParticle* particle = static_cast<CEZ2STRParticle*>(CreateEZ2STRParticle(&this->currentPosition, 5));
if (g_serviceOptions.Get(229)) {
particle->Open("mineffect\\new_cart_cannon\\new_cart_cannon\\new_cart_cannon.str");
} else {
particle->Open("new_cart_cannon\\new_cart_cannon\\new_cart_cannon.str");
}
particle->m_loop = true;
this->particle = particle;
this->speed = 1.0f;
this->delay = 0;
this->currentPosition.y -= 10.0f;
vector3d target = *reinterpret_cast<const vector3d*>(this->sourcePosition);
this->currentStep = 0;
target.y -= 10.0f;
this->stepDelta.x = target.x - this->currentPosition.x;
this->stepDelta.y = target.y - this->currentPosition.y;
this->stepDelta.z = target.z - this->currentPosition.z;
const float length = SquareRoot(
this->stepDelta.x * this->stepDelta.x +
this->stepDelta.y * this->stepDelta.y +
this->stepDelta.z * this->stepDelta.z
);
this->stepDelta.x /= 10.0f;
this->stepDelta.y /= 10.0f;
this->stepDelta.z /= 10.0f;
if (length < 40.0f) {
this->speed = 40.0f / length;
this->stepDelta.x *= this->speed;
this->stepDelta.y *= this->speed;
this->stepDelta.z *= this->speed;
}
const float dx = target.x - this->currentPosition.x;
const float dy = target.y - this->currentPosition.y;
const float dz = target.z - this->currentPosition.z;
const float inverse = 1.0f / SquareRoot(dx * dx + dy * dy + dz * dz);
this->currentPosition.x = inverse * dx * 4.0f + this->currentPosition.x;
this->currentPosition.y = inverse * dy * 4.0f + this->currentPosition.y;
this->currentPosition.z = inverse * dz * 4.0f + this->currentPosition.z;
this->startPosition = this->currentPosition;
this->position[0] = this->currentPosition.x;
this->position[1] = this->currentPosition.y;
this->position[2] = this->currentPosition.z;
CGameMode* mode = static_cast<CGameMode*>(g_modeMgr.GetGameMode());
const float angle = static_cast<float>(atan2(static_cast<double>(target.z - this->currentPosition.z), static_cast<double>(target.x - this->currentPosition.x)));
float yaw = mode->CameraDesiredYaw() + angle / 3.141592f * 180.0f;
if (yaw < 0.0f) {
yaw += 360.0f;
}
yaw = 270.0f - yaw;
if (yaw < 0.0f) {
yaw += 360.0f;
}
this->particle->m_angle = yaw;
}
// OFFSET: 0x006FAEC0
// FUNCTION: fn_06898
bool CCartCannon::IsAlive() {
if (static_cast<float>(this->currentStep) > 10.0f / this->speed) {
return false;
}
return true;
}
// OFFSET: 0x006FAEF0
// FUNCTION: fn_06899
void CCartCannon::OnProcess() {
if (this->delay > 0) {
this->delay -= 16;
return;
}
CEZ2STRParticle* particle = this->particle;
if (particle) {
const float step = static_cast<float>(this->currentStep);
this->currentPosition.x = step * this->stepDelta.x + this->startPosition.x;
this->currentPosition.y = step * this->stepDelta.y + this->startPosition.y;
this->currentPosition.z = step * this->stepDelta.z + this->startPosition.z;
this->position[0] = this->currentPosition.x;
this->position[1] = this->currentPosition.y;
this->position[2] = this->currentPosition.z;
particle->position.x = this->currentPosition.x;
particle->position.y = this->currentPosition.y;
particle->position.z = this->currentPosition.z;
particle->Process(0.0f, 0.0f, 0.0f);
}
++this->currentStep;
}
// OFFSET: 0x006FB080
// FUNCTION: fn_06900
void CCartCannon::Render() {
CEZ2STRParticle* particle = this->particle;
if (particle) {
CGameMode* mode = static_cast<CGameMode*>(g_modeMgr.GetGameMode());
particle->DrawScreen(mode->camera->frame.view);
}
}
// OFFSET: 0x006FB0E0
// FUNCTION: fn_06901
void CCartCannon::SetDelay(int delay) {
this->delay = delay;
}