cntrl/src/game/ritual.cpp

82 lines
3 KiB
C++

#include "game/ritual.hpp"
#include <cmath>
#include <cstring>
namespace {
constexpr float kPi = 3.14159265358979f;
constexpr const char* kBaitName = "LIGHTSWITCH_BAIT";
}
void RitualSystem::start_lightswitch(BuffSystem& buff_system) {
type_ = RitualType::Lightswitch;
state_ = State::InProgress;
elapsed_ = 0.0f;
caught_ = 0;
required_ = 0;
// Drop the bait ring around the switch — the House leaves objects near
// its broken switches as bait (GAME_DESIGN.md §2.3).
for (int i = 0; i < kSwitchObjectsRequired; ++i) {
const float a = (2.0f * kPi * static_cast<float>(i))
/ static_cast<float>(kSwitchObjectsRequired);
const Vec2 off = {std::cos(a) * kSwitchObjectsRingRadius,
std::sin(a) * kSwitchObjectsRingRadius};
if (buff_system.spawn_bait(kLightSwitchPos + off, kBaitName)) {
++required_;
}
}
}
void RitualSystem::activate_lightswitch(BuffSystem& buff_system, EnemySystem& enemies) {
state_ = State::Complete;
elapsed_ = 0.0f;
// Fluorescent Light reward (§4.5 "Fluorescent Light"): the revived
// fluorescents are light, and light burns the House — enemies in the
// revival zone take +25% damage for 12 s.
BuffEffect e;
e.damage_taken_mult = kLightDamageMult;
for (std::size_t j = 0; j < enemies.enemies.size(); ++j) {
if (distance(enemies.enemies[j].pos, kLightSwitchPos) < kLightRadius) {
buff_system.apply(static_cast<int>(j), e, kLightDuration, "FLUORESCENT LIGHT");
}
}
}
void RitualSystem::update(float dt, const Player& player, BuffSystem& buff_system,
EnemySystem& enemies) {
if (state_ == State::Idle) {
if (type_ == RitualType::TV && distance(player.pos, kTVPos) <= kTVRadius) {
state_ = State::InProgress;
elapsed_ = 0.0f;
} else if (distance(player.pos, kLightSwitchPos) <= kSwitchRadius) {
start_lightswitch(buff_system);
}
return;
}
if (state_ == State::InProgress && type_ == RitualType::TV) {
elapsed_ += dt;
// Epsilon so float accumulation of the 60 s budget can't stall it.
if (elapsed_ >= kTVDuration - 0.01f) {
state_ = State::Complete;
// TV ritual reward (MVP): the channel opens — debuff-clearing.
BuffEffect e;
e.damage_taken_mult = 0.9f;
buff_system.apply(-1, e, 600.0f, "TV LIVE");
}
return;
}
if (state_ == State::InProgress && type_ == RitualType::Lightswitch) {
// A catch counts when the ritual's bait leaves the world-object pool
// (the magnet pick-up removes it, PickupSystem catches it).
int pool_bait = 0;
for (int j = 0; j < buff_system.world_object_count(); ++j) {
if (std::strcmp(buff_system.world_object(j).name, kBaitName) == 0) ++pool_bait;
}
caught_ = required_ - pool_bait;
if (caught_ >= required_) {
activate_lightswitch(buff_system, enemies);
}
}
}