Curation round 14: console and Lua API, effects, lasers, enemies, eleven bosses, the Depths and Mom, status effects, the playable characters

This commit is contained in:
shweet committed 2026-11-20 19:04:41 -05:00
1 parent 8ae02a8422
commit 6e3da161fc
138 files changed
+16754 -6825

No files matched your search

+481
View File
@@ -0,0 +1,481 @@
#include "weapon_lasers.h"
#include "boss_ai.h"
#include "entity_familiar.h"
#include "entity_laser.h"
#include "entity_player.h"
#include "entity_tear.h"
#include "game.h"
#include "log.h"
#include "manager.h"
#include "npc_ai.h"
#include "sfx_manager.h"
#include <cmath>
constexpr float LASER_INHERIT_SCALE = 0.4f;
constexpr float LASER_AIM_SPEED = 10;
constexpr float LASER_BLINK_SCALE = -0.45f;
constexpr int LASER_BLINK_BASE = 7;
constexpr int LASER_SHOTS_PER_FRAME = 8;
constexpr float SPRAY_REACH = 70;
constexpr float SPRAY_SCATTER = 50;
constexpr float LUNG_SPRAY_SCALE_STEP = 0.4f;
constexpr float SPRAY_SCALE_MIN = 0.9f;
constexpr float SPRAY_SCALE_RANGE = 0.05f;
constexpr int SPRAY_CHAIN_MIN = 3;
constexpr int SPRAY_QUIET_COUNT = 5;
constexpr float LUNG_CHARGE = 4.3f;
constexpr float LASER_CHOCOLATE_CHARGE = 2.5f;
constexpr float CHARGE_MINIMUM = 0.001f;
constexpr float TECH_X_CHARGE = 3;
constexpr int MARKED_TARGET_VARIANT = 30;
constexpr int OCCULT_TARGET_VARIANT = 153;
constexpr float BRIMSTONE_WEAK_SCALE = 0.75f;
constexpr float BRIMSTONE_THICKER_SCALE = 1.5f;
constexpr int BRIMSTONE_TIMEOUT = 9;
constexpr int BRIMSTONE_BURST_TIMEOUT = 3;
constexpr float BRIMSTONE_SHORT_REACH = 30;
constexpr float BRIMSTONE_RANGE_SCALE = 0.25f;
constexpr float BRIMSTONE_RANGE_BASE = 32;
constexpr float BRIMSTONE_RANGE_MINIMUM = 60;
constexpr float FAMILIAR_BRIMSTONE_REACH = 10;
constexpr float FAMILIAR_BRIMSTONE_LIFT = 4;
constexpr float FAMILIAR_BRIMSTONE_HEIGHT = 23;
constexpr const char* NULL_MOUTH = "Mouth";
// 009f9020's makers for the laser weapons (009f94c0, 009f9640, 009f91f0): a fresh weapon of the type, or none for the
// other types.
Weapon* weapon_laser_make(WeaponType type)
{
switch (type)
{
case WEAPON_LASER:
return new Weapon_Laser();
case WEAPON_BRIMSTONE:
return new Weapon_Brimstone();
case WEAPON_TECH_X:
return new Weapon_TechX();
default:
return nullptr;
}
}
// The player a weapon's owner fires for: the owner, or its familiar's player.
static Entity_Player* weapon_player(Entity* owner)
{
if (!owner) return nullptr;
if (owner->type == ENTITY_PLAYER) return owner->ToPlayer();
return owner->type == ENTITY_FAMILIAR ? static_cast<Entity_Familiar*>(owner)->player : nullptr;
}
// Marked's target, or Eye of the Occult's with it, or none.
static int marked_variant_get(Entity_Player* player)
{
if (!player || !player->HasCollectible(COLLECTIBLE_MARKED)) return 0;
return player->HasCollectible(COLLECTIBLE_EYE_OF_THE_OCCULT) ? OCCULT_TARGET_VARIANT : MARKED_TARGET_VARIANT;
}
// 009f3f60 The color the owner's lasers take: its player's laser color. A familiar's lasers are recolored by
// Baby-Bender, which is not reconstructed yet. Online, another player's lasers fade with the opacity option, which
// this offline build has no use for.
ColorMod Weapon::get_laser_color()
{
Entity_Player* player = weapon_player(owner);
if (!player) return COLOR_DEFAULT;
if (owner->type == ENTITY_FAMILIAR)
reconstruction_missing("Weapon::get_laser_color 009f3f60 (a familiar's lasers)");
return player->laserColor;
}
// 009f5a30 Where the owner's laser of an offset leaves from: its player's eye or mouth. A familiar's are not
// reconstructed yet.
Vector Weapon::GetOwnerLaserOffset(int laserOffsetId, const Vector& shootDirection)
{
if (!owner) return {};
if (owner->type == ENTITY_PLAYER) return owner->ToPlayer()->GetLaserOffset(laserOffsetId, shootDirection);
if (owner->type == ENTITY_FAMILIAR) reconstruction_missing("Weapon::GetOwnerLaserOffset 009f5a30 (00631a00)");
return {};
}
// 009f5f40 Fires a Brimstone beam: thicker with the damage, Technology's red-blue beam with it, doubled by a second
// Brimstone and by Azazel's Birthright or Stump, halved for a familiar or a burst (without Brimstone), the thicker
// variant past one and a half. It leaves the player's mouth (or a familiar's front) and takes the player's hit
// params. Azazel's short beam reaches by range.
Entity_Laser* Weapon::FireBrimstone(const BrimstoneShot& shot)
{
Entity* entity = shot.entity;
Entity_Familiar* familiar =
entity && entity->type == ENTITY_FAMILIAR ? static_cast<Entity_Familiar*>(entity) : nullptr;
Entity_Player* player =
familiar ? familiar->player : (entity && entity->type == ENTITY_PLAYER ? entity->ToPlayer() : nullptr);
bool isBurst = shot.fireFlags & BRIMSTONE_FIRE_BURST;
bool hasBrimstone = player && player->HasCollectible(COLLECTIBLE_BRIMSTONE);
float scale = std::sqrt(shot.damageMultiplier);
if (shot.fireFlags & BRIMSTONE_FIRE_WEAK) scale *= BRIMSTONE_WEAK_SCALE;
if (familiar) scale *= 0.5f;
int variant = LASER_THICK_RED;
if (player)
{
if (player->HasCollectible(COLLECTIBLE_TECHNOLOGY)) variant = LASER_BRIM_TECH;
if (player->GetCollectibleNum(COLLECTIBLE_BRIMSTONE) > 1) scale += scale;
}
if (!isBurst || hasBrimstone)
{
if (shot.fireFlags & BRIMSTONE_FIRE_SHORT) scale += scale;
}
else
scale *= 0.5f;
bool isAzazelBeam = player && (player->playerType == PLAYER_AZAZEL ||
player->temporaryEffects.HasTrinketEffect(TRINKET_AZAZELS_STUMP));
if (player && player->playerType == PLAYER_AZAZEL &&
(player->HasCollectible(COLLECTIBLE_BIRTHRIGHT) ||
player->temporaryEffects.HasTrinketEffect(TRINKET_AZAZELS_STUMP)))
scale += scale;
if (scale > BRIMSTONE_THICKER_SCALE)
{
variant = variant == LASER_BRIM_TECH ? LASER_THICKER_BRIM_TECH : LASER_THICKER_RED;
scale *= 0.5f;
}
Vector offset{};
if (familiar)
offset = vector_make(shot.direction.x * FAMILIAR_BRIMSTONE_REACH,
FAMILIAR_BRIMSTONE_LIFT - std::abs(shot.direction.x) * FAMILIAR_BRIMSTONE_LIFT -
FAMILIAR_BRIMSTONE_HEIGHT);
else if (player && player->HasCollectible(COLLECTIBLE_C_SECTION))
offset = vector_make(0, player->sprite.scale.y * C_SECTION_LASER_LIFT);
else if (player)
{
offset = vector_scale(player->GetCostumeNullPos(NULL_MOUTH, true, Vector{}), 1 / LASER_SCREEN_SCALE);
if (player->canFly)
offset = vector_add(offset, vector_scale(player->GetFlyingOffset(), 1 / LASER_SCREEN_SCALE));
}
bool isBurstBeam =
(shot.fireFlags & (BRIMSTONE_FIRE_BURST | BRIMSTONE_FIRE_WEAK)) == BRIMSTONE_FIRE_BURST && !hasBrimstone;
Entity_Laser* laser =
Entity_Laser::ShootAngle({.position = shot.position,
.posOffset = offset,
.source = entity,
.angleDegrees = vector_angle(shot.direction),
.timeout = isBurstBeam ? BRIMSTONE_BURST_TIMEOUT : BRIMSTONE_TIMEOUT,
.variant = variant});
laser->damageMultiplier = shot.damageMultiplier;
laser->set_scale(scale);
TearParams params;
if (player)
{
int displacement = (int)(Random() & 1) * 2 - 1;
params = player->GetTearHitParams(WEAPON_BRIMSTONE, shot.damageMultiplier, displacement, entity);
}
laser->SetCollisionDamage(params.tearDamage);
laser->renderDepthOffset = shot.direction.y <= -TECH_LASER_FACING ? TECH_LASER_BACK_DEPTH : TECH_LASER_FRONT_DEPTH;
if (isAzazelBeam && !hasBrimstone)
laser->maxDistance =
std::max(player->tearRange * BRIMSTONE_RANGE_SCALE + BRIMSTONE_RANGE_BASE, BRIMSTONE_RANGE_MINIMUM);
else if (shot.fireFlags & BRIMSTONE_FIRE_SHORT)
laser->maxDistance = BRIMSTONE_SHORT_REACH;
float massMultiplier = params.massMultiplier;
if (isBurst && !hasBrimstone) massMultiplier *= 0.5f;
laser->isPlayerParams = true;
laser->mass *= massMultiplier;
laser->tearFlags = params.tearFlags;
return laser;
}
// 009f6570 Fires a Brimstone beam from the owner in the owner's laser color.
Entity_Laser* Weapon::fire_brimstone_with_color(const Vector& shootDirection, float damageMultiplier,
uint32_t fireFlags)
{
Entity_Laser* laser = FireBrimstone({.direction = shootDirection,
.position = get_owner_position(),
.entity = owner,
.damageMultiplier = damageMultiplier,
.fireFlags = fireFlags});
laser->SetColor(get_laser_color(), -1, COLOR_PRIORITY_DEFAULT, false, true);
return laser;
}
// 009f6610 Fires a Technology laser: the player's own, a familiar's (not reconstructed yet), or a plain one from the
// owner.
Entity_Laser* Weapon::fire_laser(const TechLaserShot& shot)
{
if (owner && owner->type == ENTITY_PLAYER) return owner->ToPlayer()->FireTechLaser(shot);
if (owner && owner->type == ENTITY_FAMILIAR)
reconstruction_missing("Weapon::fire_laser 009f6610 (a familiar's laser)");
return Entity_Laser::ShootAngle({.position = get_owner_position(),
.source = owner,
.angleDegrees = vector_angle(shot.direction),
.timeout = TECH_LASER_TIMEOUT,
.variant = LASER_THIN_RED});
}
// 00a052a0 Forgets the charges. The base's reset does not run.
void Weapon_Laser::Reset()
{
cursedEyeCharges = 0;
chargeAtRelease = 0;
}
// 00a063b0 Removes Technology 2's laser and Ludovico's ring, and forgets them.
void Weapon_Laser::ClearReferences()
{
for (EntityPtr* laser : {&technology2Laser, &ludovicoLaser})
{
if (!*laser) continue;
(*laser)->Remove();
*laser = nullptr;
}
}
// 00a06870 The charge a full shot takes: Monstro's Lung's, Chocolate Milk's and Cursed Eye's, none without them.
float Weapon_Laser::GetMaxCharge()
{
float multiplier = 1;
if (modifiers & WEAPON_MOD_MONSTROS_LUNG) multiplier = LUNG_CHARGE;
if (modifiers & WEAPON_MOD_CHOCOLATE_MILK) multiplier *= LASER_CHOCOLATE_CHARGE;
if (modifiers & WEAPON_MOD_CURSED_EYE) multiplier += multiplier;
return multiplier > 1 ? (maxFireDelay + 1) * multiplier - 1 : 0;
}
// Ludovico's ring is what the camera follows (Weapon_Bombs::GetFocusEntity, which lasers share).
Entity* Weapon_Laser::GetFocusEntity()
{
return (modifiers & WEAPON_MOD_LUDOVICO_TECHNIQUE) ? ludovicoLaser.get() : nullptr;
}
// Marked's target, as Brimstone's (Weapon_Brimstone::GetMarkedTargetVariant, which lasers share).
int Weapon_Laser::GetMarkedTargetVariant()
{
return (modifiers & WEAPON_MOD_LUDOVICO_TECHNIQUE) ? 0 : marked_variant_get(weapon_player(owner));
}
// 00a068e0 Whether a half charged shot lets Cursed Eye teleport the player: not while Marked aims.
bool Weapon_Laser::CanTriggerCursedEyeTeleport()
{
if (!owner || owner->type != ENTITY_PLAYER) return false;
if (owner->ToPlayer()->markedTarget && GetMarkedTargetVariant()) return false;
return charge > 0 && charge < GetMaxCharge();
}
// Lasers ride a Tractor Beam unless Ludovico holds them (Weapon_Knife::SupportsTractorBeam, which lasers share).
bool Weapon_Laser::SupportsTractorBeam()
{
return !(modifiers & WEAPON_MOD_LUDOVICO_TECHNIQUE);
}
// 00a06330 Gives a laser the owner's tear flags, laser color and damage.
void Weapon_Laser::init_laser(Weapon& weapon, Entity_Laser& laser)
{
laser.tearFlags = weapon.get_owner_tear_flags();
laser.SetColor(weapon.get_laser_color(), -1, COLOR_PRIORITY_DEFAULT, false, true);
laser.SetCollisionDamage(weapon.get_damage());
}
// 00a06420 Fires a volley: one laser per shot of the volley, offset and turned by it, or a spray of shorter lasers
// around the direction, each scaled at random and chaining three or four more (the spray's sound plays for a big
// one).
std::vector<Entity_Laser*> Weapon_Laser::fire_lasers(const LaserVolley& volley)
{
std::vector<Entity_Laser*> fired;
int shots = volley.params ? volley.params->numTears : 1;
Entity_Player* player = weapon_player(owner);
float shotSpeed = player ? player->shotSpeed : 1;
for (int i = 0; i < shots; i++)
{
Vector position = volley.position;
Vector direction = volley.direction;
if (volley.params)
{
PosVel shot = Entity_Player::GetMultiShotPositionVelocity(i, WEAPON_LASER, volley.direction, shotSpeed,
*volley.params);
position = vector_add(position, shot.position);
direction = shot.velocity;
}
TechLaserShot laserShot = {.direction = direction,
.position = position,
.damageScale = volley.damageScale,
.offsetId = volley.offsetId,
.isLeftEye = true,
.isOneHit = true};
if (volley.sprayCount < 1)
{
fired.push_back(fire_laser(laserShot));
continue;
}
Vector reach = vector_scale(direction, SPRAY_REACH);
for (int spray = 0; spray < volley.sprayCount; spray++)
{
float angle = random_unit() * RANDOM_HALF_TURN * 2;
float scatter = random_unit();
Vector aim = vector_add(reach, vector_make(std::cos(angle) * SPRAY_SCATTER * scatter,
std::sin(angle) * SPRAY_SCATTER * scatter));
laserShot.direction = vector_normalized(aim);
Entity_Laser* laser = fire_laser(laserShot);
laser->maxDistance = vector_length(aim);
float growth = (float)(Random() & 1) * LUNG_SPRAY_SCALE_STEP + SPRAY_SCALE_MIN;
laser->scale *= growth + random_unit() * SPRAY_SCALE_RANGE;
laser->ResetSpriteScale();
laser->chainedLasers = (int)(Random() & 1) + SPRAY_CHAIN_MIN;
laser->isDisableInitSound = volley.sprayCount > SPRAY_QUIET_COUNT;
fired.push_back(laser);
}
if (volley.sprayCount > SPRAY_QUIET_COUNT) npc_sound_play(SOUND_BLOOD_LASER_LARGE, 1, 2, 1);
}
return fired;
}
// 00a052b0 Fires Technology's lasers: one volley per fire delay passed this frame (at most eight), from the eye with
// the volley's extra backward, sideways and random lasers, carrying a share of the owner's movement unless a
// Tractor Beam holds them. Ludovico's ring and the charged shots (Monstro's Lung, Chocolate Milk, Cursed Eye) are
// not reconstructed yet.
void Weapon_Laser::Fire(const Vector& shootDirection, bool isShooting, bool isInterpolated)
{
Weapon::Fire(shootDirection, isShooting, isInterpolated);
if (modifiers & WEAPON_MOD_LUDOVICO_TECHNIQUE)
reconstruction_missing("Weapon_Laser::Fire 00a052b0 (Ludovico's ring)");
if (modifiers & (WEAPON_MOD_MONSTROS_LUNG | WEAPON_MOD_CHOCOLATE_MILK | WEAPON_MOD_CURSED_EYE))
reconstruction_missing("Weapon_Laser::Fire 00a052b0 (charged lasers)");
int shots = 0;
if (isShooting)
{
if (isInterpolated) return;
while (fireDelay < 0 && shots < LASER_SHOTS_PER_FRAME)
{
shots++;
fireDelay += maxFireDelay + 1;
}
chargeAtRelease = 0;
}
Vector aim = isShooting ? shootDirection : direction;
aim = IsAxisAligned() ? vector_cardinal(aim) : vector_normalized(aim);
if (shots > 0)
{
bool isTractorBeam = modifiers & WEAPON_MOD_TRACTOR_BEAM;
Vector velocity = vector_scale(aim, LASER_AIM_SPEED);
if (!isTractorBeam)
velocity = vector_add(velocity, vector_scale(get_tear_movement_inheritance(aim), LASER_INHERIT_SCALE));
aim = vector_normalized(velocity);
SetBlinkTime(LASER_BLINK_BASE - (int)(maxFireDelay * LASER_BLINK_SCALE));
TriggerTearEffects(aim, 1);
Weapon_MultiShotParams params = GetMultiShotParams();
LaserVolley volley = {.direction = aim, .position = get_owner_position(), .params = &params};
std::vector<Entity_Laser*> fired = fire_lasers(volley);
volley.params = nullptr;
volley.offsetId = LASER_OFFSET_MOMS_EYE;
auto fire_more = [&](Vector extra) {
volley.direction = extra;
std::vector<Entity_Laser*> more = fire_lasers(volley);
fired.insert(fired.end(), more.begin(), more.end());
};
if (params.isShootingBackwards) fire_more(vector_make(-aim.x, -aim.y));
if (params.isShootingSideways)
{
fire_more(vector_make(aim.y, -aim.x));
fire_more(vector_make(-aim.y, aim.x));
}
for (int i = 0; i < params.numRandomDirTears; i++) fire_more(random_direction());
for (Entity_Laser* laser : fired)
{
laser->isDisableFollowParent = !isTractorBeam;
laser->Update();
}
}
if (isShooting) direction = IsAxisAligned() ? aim : get_aim_direction(aim);
}
// 00a00f30 The charge a full beam takes: the fire delay (Chocolate Milk's two and a half of it), none under Ludovico.
float Weapon_Brimstone::GetMaxCharge()
{
if (modifiers & WEAPON_MOD_LUDOVICO_TECHNIQUE) return 0;
float multiplier = (modifiers & WEAPON_MOD_CHOCOLATE_MILK) ? LASER_CHOCOLATE_CHARGE : 1;
return std::max(maxFireDelay, CHARGE_MINIMUM) * multiplier;
}
// 00a02790 Removes Technology 2's laser and the main beam, and forgets them.
void Weapon_Brimstone::ClearReferences()
{
for (EntityPtr* laser : {&technology2Laser, &mainLaser})
{
if (!*laser) continue;
(*laser)->Remove();
*laser = nullptr;
}
}
// 00a02870 The camera follows Ludovico's beam.
Entity* Weapon_Brimstone::GetFocusEntity()
{
return (modifiers & WEAPON_MOD_LUDOVICO_TECHNIQUE) ? mainLaser.get() : nullptr;
}
// 009f3160 The beam it fires as.
Entity* Weapon_Brimstone::GetMainEntity()
{
return mainLaser;
}
// 00a02800 Marked's target, Eye of the Occult's with it, none under Ludovico.
int Weapon_Brimstone::GetMarkedTargetVariant()
{
return (modifiers & WEAPON_MOD_LUDOVICO_TECHNIQUE) ? 0 : marked_variant_get(weapon_player(owner));
}
// The charging and firing of Brimstone are not reconstructed yet.
// 009ff360
void Weapon_Brimstone::Fire(const Vector&, bool, bool)
{
reconstruction_missing("Weapon_Brimstone::Fire 009ff360");
}
// 00a00d10
void Weapon_Brimstone::fire_c_section_fetuses()
{
reconstruction_missing("Weapon_Brimstone::fire_c_section_fetuses 00a00d10");
}
// 00a00f90
void Weapon_Brimstone::init_laser(Entity_Laser&)
{
reconstruction_missing("Weapon_Brimstone::init_laser 00a00f90");
}
// 00a01020
void Weapon_Brimstone::fire_hitscan()
{
reconstruction_missing("Weapon_Brimstone::fire_hitscan 00a01020");
}
// 00a02890
void Weapon_Brimstone::fire(float, bool)
{
reconstruction_missing("Weapon_Brimstone::fire 00a02890");
}
// 00a0e260 The charge a full ring takes: three fire delays.
float Weapon_TechX::GetMaxCharge()
{
return maxFireDelay * TECH_X_CHARGE;
}
// Marked's target, as Monstro's Lung picks it, which Tech X shares.
int Weapon_TechX::GetMarkedTargetVariant()
{
return marked_variant_get(weapon_player(owner));
}
// 00a0d9c0 The charging and firing of Tech X's rings are not reconstructed yet.
void Weapon_TechX::Fire(const Vector&, bool, bool)
{
reconstruction_missing("Weapon_TechX::Fire 00a0d9c0");
}