Curation round 16: Mom's Knife and the bone club, sin minibosses and death rewards, slots and beggars, NPC rendering and twelve bosses, alt path visuals, the Forgotten's flight and tainted HUDs, Sheol and the Cathedral to the credits, familiars and transformations
This commit is contained in:
1 parent
76c594f9a0
commit
e9de039d0f
151 files changed
+14996
-5208
No files matched your search
+11
@@ -296,6 +296,16 @@ struct ANM2Base
|
||||
bool isUnknown108 = false;
|
||||
};
|
||||
|
||||
// What GetTexel samples: a screen position, where the sprite draws, the alpha a texel must reach and the layer it looks
|
||||
// in (any for -1).
|
||||
struct TexelQuery
|
||||
{
|
||||
Vector renderPos{};
|
||||
Vector sample{};
|
||||
float alphaThreshold = 0;
|
||||
int layerId = -1;
|
||||
};
|
||||
|
||||
// 004074c0, 00408170 Construction and destruction are the defaults.
|
||||
// Sprite's field accessors (004073d0, 00407410, 00407420, 00407430, 00417200, 00417210, 00420160, 00420170, 00431300,
|
||||
// 00435c60, 0043ee80, 00440e40, 00456340, 00456360, 0049cb40) are the public fields.
|
||||
@@ -345,6 +355,7 @@ struct ANM2 : ANM2Base
|
||||
|
||||
bool IsEventTriggered(std::string_view eventName) const;
|
||||
bool WasEventTriggered(std::string_view eventName) const;
|
||||
KColor GetTexel(const TexelQuery& query) const;
|
||||
|
||||
LayerState* GetLayer(int layerId);
|
||||
LayerState* GetLayer(std::string_view name);
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
#include "anm2.h"
|
||||
#include "fx_layers.h"
|
||||
#include "npc_ai.h"
|
||||
#include "room_render.h"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
// Turns a point about the origin, as KAGE's Quad::rotate turns a quad's corners.
|
||||
static Vector point_turn(Vector point, float cosine, float sine)
|
||||
{
|
||||
return vector_make(point.x * cosine - point.y * sine, point.y * cosine + point.x * sine);
|
||||
}
|
||||
|
||||
// 0040b600 The color an animation of a sprite shows at a screen position: the texel of the first visible layer
|
||||
// keyframe over it that reaches the alpha, in the sprite's, layer's and keyframe's tints and offsets (colorize aside),
|
||||
// else clear. A turned layer is turned back about the origin, sample and all.
|
||||
static KColor animation_texel_get(const ANM2& sprite, const AnimationState& animation, const TexelQuery& query)
|
||||
{
|
||||
if (!animation.animData) return {};
|
||||
|
||||
const std::vector<AnimationLayer>& tracks = animation.animData->animLayers;
|
||||
for (size_t track = 0; track < tracks.size(); track++)
|
||||
{
|
||||
const AnimationLayer& layer = tracks[track];
|
||||
int frameIndex = track < animation.layerFrames.size() ? animation.layerFrames[track] : -1;
|
||||
bool isLayerKnown = layer.layerId >= 0 && layer.layerId < (int)sprite.layerStates.size();
|
||||
if (layer.frames.empty() || (query.layerId >= 0 && layer.layerId != query.layerId) || !isLayerKnown) continue;
|
||||
if (frameIndex < 0 || frameIndex >= (int)layer.frames.size()) continue;
|
||||
|
||||
const AnimationFrame& frame = layer.frames[frameIndex];
|
||||
const LayerState& state = sprite.layerStates[layer.layerId];
|
||||
if (!frame.isVisible || !state.isVisible || !state.spriteSheet) continue;
|
||||
|
||||
SpriteDraw draw = {.position = query.renderPos};
|
||||
SourceQuad source = AnimationLayer::GetSourceQuad(frame, state, draw, sprite);
|
||||
DestinationQuad screen = AnimationLayer::GetDestQuad(frame, state, draw, sprite);
|
||||
Vector sample = query.sample;
|
||||
float layerTurn = frame.rotation + state.rotation;
|
||||
float spriteTurn = sprite.rotation;
|
||||
if (spriteTurn != 0 || layerTurn != 0)
|
||||
{
|
||||
float layerScaleX = frame.scale.x * state.size.x;
|
||||
float layerScaleY = state.isFlipY ? -(frame.scale.y * state.size.y) : frame.scale.y * state.size.y;
|
||||
float spriteScaleY = sprite.isFlipY ? -sprite.scale.y : sprite.scale.y;
|
||||
if ((sprite.scale.x < 0) != (layerScaleX < 0))
|
||||
{
|
||||
if (sprite.scale.x < 0)
|
||||
{
|
||||
layerTurn = -layerTurn;
|
||||
spriteTurn = -spriteTurn;
|
||||
}
|
||||
if (layerScaleX < 0) layerTurn = -layerTurn;
|
||||
}
|
||||
if ((spriteScaleY < 0) != (layerScaleY < 0))
|
||||
{
|
||||
if (spriteScaleY < 0)
|
||||
{
|
||||
layerTurn = -layerTurn;
|
||||
spriteTurn = -spriteTurn;
|
||||
}
|
||||
if (layerScaleY < 0) layerTurn = -layerTurn;
|
||||
}
|
||||
|
||||
float angle = -(layerTurn + spriteTurn) * DEGREES_TO_RADIANS;
|
||||
float cosine = std::cos(angle);
|
||||
float sine = std::sin(angle);
|
||||
for (Vector* corner : {&screen._topLeft, &screen._topRight, &screen._bottomLeft, &screen._bottomRight})
|
||||
*corner = point_turn(*corner, cosine, sine);
|
||||
sample = point_turn(sample, cosine, sine);
|
||||
}
|
||||
|
||||
Vector topLeft = screen._topLeft;
|
||||
Vector bottomRight = screen._bottomRight;
|
||||
bool isOverX = topLeft.x < sample.x && sample.x < bottomRight.x;
|
||||
if (!isOverX || topLeft.y >= sample.y || sample.y >= bottomRight.y) continue;
|
||||
|
||||
float across = std::clamp((sample.x - topLeft.x) / (bottomRight.x - topLeft.x), 0.0f, 1.0f);
|
||||
float down = std::clamp((sample.y - topLeft.y) / (bottomRight.y - topLeft.y), 0.0f, 1.0f);
|
||||
float texelX = (source._bottomRight.x - source._topLeft.x) * across + source._topLeft.x;
|
||||
float texelY = (source._bottomRight.y - source._topLeft.y) * down + source._topLeft.y;
|
||||
KColor texel = image_texel_get(*state.spriteSheet, (uint32_t)(int)texelX, (uint32_t)(int)texelY);
|
||||
if (texel._alpha < query.alphaThreshold) continue;
|
||||
|
||||
ColorMod color = sprite.color;
|
||||
color_multiply(color, state.color);
|
||||
color_multiply(color, frame.color);
|
||||
float red = color._tint[0] * texel._red + color._offset[0];
|
||||
float green = color._tint[1] * texel._green + color._offset[1];
|
||||
float blue = color._tint[2] * texel._blue + color._offset[2];
|
||||
return kcolor_rgba(red, green, blue, color._tint[3] * texel._alpha);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
// 0040b590 The color the sprite shows at a screen position: its overlay's, unless that falls short of the alpha, then
|
||||
// its main animation's.
|
||||
KColor ANM2::GetTexel(const TexelQuery& query) const
|
||||
{
|
||||
KColor texel = animation_texel_get(*this, overlayAnimState, query);
|
||||
if (texel._alpha < query.alphaThreshold) texel = animation_texel_get(*this, animState, query);
|
||||
return texel;
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
#include "beam_renderer.h"
|
||||
#include "fx_layers.h"
|
||||
#include "kage_graphics.h"
|
||||
#include "npc_ai.h"
|
||||
#include "render_passes.h"
|
||||
#include <cmath>
|
||||
|
||||
// A point's edges spread along its direction turned a quarter, and a joint's normal is never shortened past this.
|
||||
constexpr float BEAM_NORMAL_TURN = 1.5707964f;
|
||||
constexpr float JOINT_DOT_MIN = 0.4f;
|
||||
constexpr float HALF_WIDTH = 0.5f;
|
||||
|
||||
BeamRenderer g_beamRenderer;
|
||||
|
||||
// The unit direction from one point to another turned a quarter clockwise, the way KAGE turns it (by cos and sin of a
|
||||
// float quarter turn, so x keeps a trace of the direction).
|
||||
static Vector normal_get(Vector from, Vector to)
|
||||
{
|
||||
Vector direction = vector_normalized(vector_sub(to, from));
|
||||
float cosine = std::cos(BEAM_NORMAL_TURN);
|
||||
float sine = std::sin(BEAM_NORMAL_TURN);
|
||||
return vector_make(direction.x * cosine - direction.y * sine, sine * direction.x + cosine * direction.y);
|
||||
}
|
||||
|
||||
// 0041e4c0 (Point::UpdateNormal) Bends the normal toward the next point: the new segment's normal when it has none,
|
||||
// else the mean of both, lengthened as the joint sharpens so the strip keeps its width.
|
||||
void BeamPoint::UpdateNormal(Vector next)
|
||||
{
|
||||
Vector turned = normal_get(pos, next);
|
||||
if (vector_is_zero(normal))
|
||||
{
|
||||
normal = turned;
|
||||
return;
|
||||
}
|
||||
|
||||
Vector mean = vector_add(turned, normal);
|
||||
Vector unit = vector_length(mean) > 0 ? vector_normalized(mean) : mean;
|
||||
float sharpness = std::max(vector_dot(normal, unit), JOINT_DOT_MIN);
|
||||
normal = vector_scale(unit, 1 / sharpness);
|
||||
}
|
||||
|
||||
// 0041e480 Starts a beam of a sprite's layer, dropping the points of the last one.
|
||||
void BeamRenderer::Begin(ANM2& beamSprite, int beamLayerId, BeamFrame beamFrame, BeamCoordinate beamCoordinate)
|
||||
{
|
||||
sprite = &beamSprite;
|
||||
layerId = beamLayerId;
|
||||
frame = beamFrame;
|
||||
coordinate = beamCoordinate;
|
||||
points.clear();
|
||||
}
|
||||
|
||||
// 0041e720 Adds a point, its normal along the segment from the last one, whose own normal bends toward it.
|
||||
void BeamRenderer::Add(BeamPoint point)
|
||||
{
|
||||
point.normal = {};
|
||||
if (!points.empty())
|
||||
{
|
||||
point.normal = normal_get(points.back().pos, point.pos);
|
||||
points.back().UpdateNormal(point.pos);
|
||||
}
|
||||
points.push_back(point);
|
||||
}
|
||||
|
||||
// The color a point draws in over the keyframe's: tints multiplied, offsets added, and the keyframe's colorize taken
|
||||
// when the point has none, else the mean of both.
|
||||
static ColorMod point_color(const ColorMod& point, const ColorMod& keyframe)
|
||||
{
|
||||
ColorMod color = point;
|
||||
for (int channel = 0; channel < 4; channel++) color._tint[channel] *= keyframe._tint[channel];
|
||||
for (int channel = 0; channel < 3; channel++) color._offset[channel] += keyframe._offset[channel];
|
||||
|
||||
bool isKeyframeColorized = keyframe._colorize[0] + keyframe._colorize[1] + keyframe._colorize[2] != 0;
|
||||
bool isPointColorized = point._colorize[0] + point._colorize[1] + point._colorize[2] != 0;
|
||||
for (int channel = 0; isKeyframeColorized && channel < 4; channel++)
|
||||
{
|
||||
float mean = (keyframe._colorize[channel] + point._colorize[channel]) / 2;
|
||||
color._colorize[channel] = isPointColorized ? mean : keyframe._colorize[channel];
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
// The quad between two points, each edge as wide as the keyframe times the point's width.
|
||||
static KAGE::Graphics::ColorQuad segment_quad(const BeamPoint& start, const BeamPoint& end, float keyframeWidth)
|
||||
{
|
||||
Vector startEdge = vector_scale(start.normal, keyframeWidth * start.width * HALF_WIDTH);
|
||||
Vector endEdge = vector_scale(end.normal, keyframeWidth * end.width * HALF_WIDTH);
|
||||
KAGE::Graphics::ColorQuad quad;
|
||||
quad._topLeft = vector_add(start.pos, startEdge);
|
||||
quad._topRight = vector_sub(start.pos, startEdge);
|
||||
quad._bottomLeft = vector_add(end.pos, endEdge);
|
||||
quad._bottomRight = vector_sub(end.pos, endEdge);
|
||||
return quad;
|
||||
}
|
||||
|
||||
// 0041e960 Draws the strip: the keyframe's spritesheet column stretched along each segment, mirrored when the layer
|
||||
// and the sprite flip differently, in the layer's blending with the points' colors over the keyframe's. Needs a
|
||||
// texture, a keyframe and two points.
|
||||
// The original switches to a per-vertex color shader when the points' colorize or offset differ, and to its static
|
||||
// shader for ANIM_RENDER_STATIC. Here each segment takes its first point's colorize and offset through the sprite
|
||||
// shader, as the uniform shader does.
|
||||
void BeamRenderer::End()
|
||||
{
|
||||
LayerState* layer = sprite ? sprite->GetLayer(layerId) : nullptr;
|
||||
if (!layer || !layer->spriteSheet || points.size() < 2) return;
|
||||
|
||||
const AnimationState& animation = frame == BEAM_FRAME_OVERLAY ? sprite->overlayAnimState : sprite->animState;
|
||||
const AnimationFrame* keyframe = animation.GetLayerFrame(layerId);
|
||||
if (!keyframe) return;
|
||||
|
||||
namespace Graphics = KAGE::Graphics;
|
||||
using Factor = Graphics::BlendFactor;
|
||||
Graphics::ImageBase& image = *layer->spriteSheet;
|
||||
const std::array<int, BLEND_PART_COUNT>& mode = layer->blendMode;
|
||||
Graphics::BlendMode saved = Graphics::manager.blendMode;
|
||||
Graphics::manager.blendMode = {(Graphics::BlendEquation)mode[BLEND_EQUATION], (Factor)mode[BLEND_RGB_SOURCE],
|
||||
(Factor)mode[BLEND_RGB_DEST], (Factor)mode[BLEND_ALPHA_SOURCE],
|
||||
(Factor)mode[BLEND_ALPHA_DEST]};
|
||||
|
||||
bool isMirrored = layer->isFlipX != sprite->isFlipX;
|
||||
float left = isMirrored ? keyframe->crop.x + keyframe->width : keyframe->crop.x;
|
||||
float right = isMirrored ? keyframe->crop.x : keyframe->crop.x + keyframe->width;
|
||||
float coordinateScale = coordinate == BEAM_COORDINATE_HEIGHTS ? keyframe->height : 1;
|
||||
for (size_t index = 0; index + 1 < points.size(); index++)
|
||||
{
|
||||
const BeamPoint& start = points[index];
|
||||
const BeamPoint& end = points[index + 1];
|
||||
float top = keyframe->crop.y + start.coordinate * coordinateScale;
|
||||
float bottom = keyframe->crop.y + end.coordinate * coordinateScale;
|
||||
SourceQuad source;
|
||||
source._topLeft = vector_make(left, top);
|
||||
source._topRight = vector_make(right, top);
|
||||
source._bottomLeft = vector_make(left, bottom);
|
||||
source._bottomRight = vector_make(right, bottom);
|
||||
source._coordinateSpace = Graphics::COORDINATES_PIXEL;
|
||||
|
||||
ColorMod startColor = point_color(start.color, keyframe->color);
|
||||
ColorMod endColor = point_color(end.color, keyframe->color);
|
||||
KColor startTint =
|
||||
kcolor_rgba(startColor._tint[0], startColor._tint[1], startColor._tint[2], startColor._tint[3]);
|
||||
KColor endTint = kcolor_rgba(endColor._tint[0], endColor._tint[1], endColor._tint[2], endColor._tint[3]);
|
||||
Graphics::ColorQuad quad = segment_quad(start, end, keyframe->width);
|
||||
quad.colors = {startTint, startTint, endTint, endTint};
|
||||
apply_sprite_shader_params(startColor, SPRITE_SHADER_COLOR_APPLY, image);
|
||||
image.Render({&source, 1}, {&quad, 1});
|
||||
}
|
||||
|
||||
Graphics::manager.blendMode = saved;
|
||||
Graphics::manager.shader_default_set();
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include "anm2.h"
|
||||
#include <vector>
|
||||
|
||||
// Which animation of the sprite a beam takes its layer's keyframe from.
|
||||
enum BeamFrame
|
||||
{
|
||||
BEAM_FRAME_MAIN,
|
||||
BEAM_FRAME_OVERLAY
|
||||
};
|
||||
|
||||
// Whether a point's spritesheet coordinate counts pixels down the keyframe, or keyframe heights.
|
||||
enum BeamCoordinate
|
||||
{
|
||||
BEAM_COORDINATE_PIXELS,
|
||||
BEAM_COORDINATE_HEIGHTS
|
||||
};
|
||||
|
||||
// One point of a beam: where it is, the normal its edges spread along, its width as a scale of the keyframe's, its
|
||||
// spritesheet coordinate and its color.
|
||||
struct BeamPoint
|
||||
{
|
||||
ColorMod color = COLOR_DEFAULT;
|
||||
Vector normal{};
|
||||
Vector pos{};
|
||||
float coordinate = 0;
|
||||
float width = 0;
|
||||
|
||||
void UpdateNormal(Vector next);
|
||||
};
|
||||
|
||||
// KAGE's strip renderer: a layer of a sprite drawn along the points Add collects between Begin and End, one textured
|
||||
// quad between each two points.
|
||||
struct BeamRenderer
|
||||
{
|
||||
std::vector<BeamPoint> points;
|
||||
ANM2* sprite = nullptr;
|
||||
BeamCoordinate coordinate = BEAM_COORDINATE_PIXELS;
|
||||
BeamFrame frame = BEAM_FRAME_MAIN;
|
||||
int layerId = 0;
|
||||
|
||||
void Begin(ANM2& beamSprite, int beamLayerId, BeamFrame beamFrame, BeamCoordinate beamCoordinate);
|
||||
void Add(BeamPoint point);
|
||||
void End();
|
||||
};
|
||||
|
||||
extern BeamRenderer g_beamRenderer;
|
||||
@@ -75,7 +75,7 @@ static bool is_scissored(Entity* source)
|
||||
|
||||
// Room::CheckLine's explosion mode (2): the line walked in steps, cell by cell. A metal block stops it, and so does a
|
||||
// wall, unless it is a door, a wall the check ignores, or a lock Broken Padlock lets the blast through.
|
||||
static bool explosion_line_clear(const Vector& start, const Vector& end, bool isIgnoreWalls)
|
||||
bool explosion_line_clear(const Vector& start, const Vector& end, bool isIgnoreWalls)
|
||||
{
|
||||
Room& room = *g_game->room;
|
||||
Vector step = vector_sub(start, end);
|
||||
|
||||
@@ -141,6 +141,7 @@ void boss_baby_plum_update(Entity_NPC& npc);
|
||||
void boss_blastocyst_update(Entity_NPC& npc);
|
||||
void boss_cage_update(Entity_NPC& npc);
|
||||
void boss_chub_update(Entity_NPC& npc);
|
||||
void boss_daddy_long_legs_update(Entity_NPC& npc);
|
||||
void boss_dingle_update(Entity_NPC& npc);
|
||||
void boss_duke_update(Entity_NPC& npc);
|
||||
void boss_famine_update(Entity_NPC& npc);
|
||||
@@ -166,6 +167,9 @@ void boss_peep_update(Entity_NPC& npc);
|
||||
void boss_pestilence_update(Entity_NPC& npc);
|
||||
void boss_polycephalus_update(Entity_NPC& npc);
|
||||
void boss_widow_update(Entity_NPC& npc);
|
||||
void boss_satan_update(Entity_NPC& npc);
|
||||
void boss_fallen_update(Entity_NPC& npc);
|
||||
void boss_music_crossfade();
|
||||
|
||||
// Gemini's baby, the variant its twin is tied to.
|
||||
constexpr int GEMINI_BABY = 10;
|
||||
@@ -0,0 +1,402 @@
|
||||
#include "boss_ai.h"
|
||||
#include "entity_bomb.h"
|
||||
#include "entity_config.h"
|
||||
#include "grid_entity_trap_door.h"
|
||||
#include "npc_caves.h"
|
||||
#include "room_grid.h"
|
||||
|
||||
// Daddy Long Legs (variant 0) and the Triachnid stomp from above the room: the body (i1 0) rises and drops onto its
|
||||
// target, or sends down legs (i1 1, copies of itself that each stomp once and vanish), spits spiders or Trites.
|
||||
constexpr int TRIACHNID = 1;
|
||||
constexpr int DLL_RISE = NPC_STATE_JUMP;
|
||||
constexpr int DLL_STOMP = NPC_STATE_STOMP;
|
||||
constexpr int DLL_SPIT = NPC_STATE_ATTACK;
|
||||
constexpr int DLL_LEGS = NPC_STATE_ATTACK2;
|
||||
constexpr int DLL_LEG = 1;
|
||||
constexpr float DLL_FRICTION = 0.8f;
|
||||
|
||||
// Resting, it acts 1 time in 20: rising, sending legs or spitting, never spitting with 4 or more enemies about.
|
||||
constexpr uint32_t DLL_ACT_ODDS = 20;
|
||||
constexpr std::array<int, 5> DLL_ACTIONS = {DLL_RISE, DLL_LEGS, DLL_LEGS, DLL_SPIT, DLL_SPIT};
|
||||
constexpr int DLL_CROWD = 4;
|
||||
constexpr uint32_t DLL_CROWDED_ACTIONS = 3;
|
||||
|
||||
// It stomps 4 times (the Triachnid 3), then 1 time in 7 once more. Its body is half as wide while up.
|
||||
constexpr int DLL_STOMPS = 4;
|
||||
constexpr int TRIACHNID_STOMPS = 3;
|
||||
constexpr uint32_t DLL_EXTRA_STOMP_ODDS = 7;
|
||||
constexpr int DLL_STOMP_LIMB_LIMIT = 4;
|
||||
constexpr float DLL_UP_WIDTH = 0.5f;
|
||||
|
||||
// A landing: 300 crushing damage within 44 (50 for a Delirium form). The body's drop rings out shots at 10 (the
|
||||
// Triachnid's in black and white), a ripple and a grey dust cloud. A leg's stomp puffs dust on it.
|
||||
constexpr float DLL_CRUSH_DAMAGE = 300;
|
||||
constexpr float DLL_DELIRIUM_CRUSH_DAMAGE = 50;
|
||||
constexpr float DLL_CRUSH_RADIUS = 44;
|
||||
constexpr float DLL_SHOT_SPEED = 10;
|
||||
constexpr ColorMod TRIACHNID_SHOT_COLOR = {{0, 0, 0, 1}, {0, 0, 0, 0}, {1, 1, 1}};
|
||||
constexpr float DLL_DROP_VOLUME = 0.7f;
|
||||
constexpr int DLL_DROP_SHAKE = 12;
|
||||
constexpr int DLL_STOMP_SHAKE = 8;
|
||||
constexpr float DLL_RIPPLE_AMPLITUDE = 0.04f;
|
||||
constexpr float DLL_RIPPLE_SPEED = 0.025f;
|
||||
constexpr int DLL_RIPPLE_DURATION = 13;
|
||||
constexpr ColorMod DLL_DUST_COLOR = {{0.62f, 0.62f, 0.62f, 0.8f}, {0, 0, 0, 0}, {0, 0, 0}};
|
||||
constexpr ColorMod DLL_STOMP_DUST_COLOR = {{0.8f, 0.8f, 0.8f, 0.7f}, {0, 0, 0, 0}, {0, 0, 0}};
|
||||
constexpr int DLL_STOMP_DUST_SUBTYPE = 2;
|
||||
constexpr float DLL_STOMP_DUST_DROP = 15;
|
||||
constexpr int DLL_DUST_PRIORITY = 255;
|
||||
|
||||
// The Triachnid's landings leave white creep, twice as large, and its drop spreads more for 24 frames, 50 and 2 a
|
||||
// frame further out, 1.05 times larger each.
|
||||
constexpr float TRIACHNID_CREEP_SCALE = 2;
|
||||
constexpr int TRIACHNID_CREEP_FRAMES = 24;
|
||||
constexpr float TRIACHNID_CREEP_REACH = 50;
|
||||
constexpr float TRIACHNID_CREEP_GROWTH = 0.05f;
|
||||
|
||||
// The spit: a grey cloud, then two or three spiders thrown 100 out (at most 3 for a Delirium form), or a Trite.
|
||||
constexpr ColorMod DLL_CLOUD_COLOR = {{0, 0, 0, 0.55f}, {0, 0, 0, 0}, {0.4f, 0.38f, 0.34f}};
|
||||
constexpr float DLL_CLOUD_SCALE = 0.75f;
|
||||
constexpr float DLL_CLOUD_LIFT = -26;
|
||||
constexpr int DLL_SPIDERS = 2;
|
||||
constexpr int DLL_DELIRIUM_SPIDERS = 3;
|
||||
constexpr float DLL_SPIDER_REACH = 100;
|
||||
constexpr int DLL_PATH_LIMIT = 951;
|
||||
constexpr float DLL_SPIDER_ARC = -8;
|
||||
constexpr float DLL_SPIDER_PACE = 0.04f;
|
||||
constexpr float DLL_SPIDER_LIFT = 10;
|
||||
constexpr int TRITE_VARIANT = 1;
|
||||
constexpr int TRITE_SPIN_UP = 5;
|
||||
|
||||
// The legs: one lands on the target's path (a fraction of 20 frames ahead, 20 around), the rest 80 to 180 from the
|
||||
// target 1 time in 4, else up to 400 from the body, each scattered 20, 5 picks drawn. They fall 16 frames in, 10
|
||||
// apart.
|
||||
constexpr float LEG_LEAD_FRAMES = 20;
|
||||
constexpr float LEG_NEAR = 20;
|
||||
constexpr float LEG_SCATTER = 40;
|
||||
constexpr float LEG_TARGET_SPREAD = 100;
|
||||
constexpr float LEG_TARGET_MIN = 80;
|
||||
constexpr float LEG_BODY_SPREAD = 400;
|
||||
constexpr int LEG_PICKS = 5;
|
||||
constexpr int LEG_FIRST_DELAY = 16;
|
||||
constexpr int LEG_DELAY_STEP = 10;
|
||||
|
||||
// Its death bleeds the walls for 30 frames, 7 drops.
|
||||
constexpr int DLL_DEATH_BLOOD_FRAMES = 30;
|
||||
constexpr int DLL_DEATH_BLOOD_DROPS = 7;
|
||||
|
||||
static bool dll_is_calm(Entity_NPC& npc)
|
||||
{
|
||||
return npc.HasEntityFlags(FLAG_DELIRIUM_FORM) && room_is_clear();
|
||||
}
|
||||
|
||||
// Its stomp animation: an arm on the first two of a stomp (always for the Triachnid), a leg after, mirrored in turn.
|
||||
static std::string_view dll_stomp_animation(Entity_NPC& npc, int stomp)
|
||||
{
|
||||
npc.sprite.isFlipX = (stomp & 1) == 0;
|
||||
return stomp / 2 == 0 || npc.variant == TRIACHNID ? "StompArm" : "StompLeg";
|
||||
}
|
||||
|
||||
// Its animation ended: the next stomp or the drop, a rise turning into stomps, else rest. A leg vanishes.
|
||||
static void dll_animation_end(Entity_NPC& npc)
|
||||
{
|
||||
if (npc.state == DLL_STOMP)
|
||||
{
|
||||
if (npc.i1 != 0) return npc.Remove();
|
||||
|
||||
int stomp = npc.i2++;
|
||||
int stomps = npc.variant == TRIACHNID ? TRIACHNID_STOMPS : DLL_STOMPS;
|
||||
if (stomp < stomps || Random() % DLL_EXTRA_STOMP_ODDS == 0)
|
||||
{
|
||||
int limb = std::min(npc.i2, DLL_STOMP_LIMB_LIMIT) - 1;
|
||||
std::string_view animation = dll_stomp_animation(npc, limb);
|
||||
npc_anim_restart(npc.sprite, animation);
|
||||
return;
|
||||
}
|
||||
npc.state = NPC_STATE_MOVE;
|
||||
npc.sprite.Play("Down");
|
||||
npc.stateFrame = 0;
|
||||
npc.SetSize(npc.config->collisionRadius, vector_make(-1, -1), -1);
|
||||
return;
|
||||
}
|
||||
if (npc.state == DLL_RISE)
|
||||
{
|
||||
npc.state = DLL_STOMP;
|
||||
npc.SetSize(npc.config->collisionRadius * DLL_UP_WIDTH, vector_make(-1, -1), -1);
|
||||
return;
|
||||
}
|
||||
npc.state = NPC_STATE_IDLE;
|
||||
npc.sprite.Play("Idle");
|
||||
}
|
||||
|
||||
// A landing: the body's drop ripples, rings out shots and kicks up dust, a leg's stomp puffs dust. Both crush what is
|
||||
// under them, and the Triachnid's leave white creep.
|
||||
static void dll_land(Entity_NPC& npc)
|
||||
{
|
||||
bool isDrop = npc.state == NPC_STATE_MOVE;
|
||||
if (isDrop)
|
||||
{
|
||||
npc.PlaySound(SOUND_HELLBOSS_GROUNDPOUND, DLL_DROP_VOLUME, 2, false, 1);
|
||||
shockwave_make(npc.pos, DLL_RIPPLE_AMPLITUDE, DLL_RIPPLE_SPEED, DLL_RIPPLE_DURATION);
|
||||
game_shake_screen(DLL_DROP_SHAKE);
|
||||
npc.MakeGroundPoof(npc.pos, DLL_DUST_COLOR, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
npc.PlaySound(SOUND_FORESTBOSS_STOMPS, 1, 2, false, 1);
|
||||
game_shake_screen(DLL_STOMP_SHAKE);
|
||||
auto* dust = static_cast<Entity_Effect*>(g_game->Spawn({.position = npc.pos,
|
||||
.spawner = &npc,
|
||||
.subType = DLL_STOMP_DUST_SUBTYPE,
|
||||
.type = ENTITY_EFFECT,
|
||||
.variant = EFFECT_POOF02,
|
||||
.seed = Random()}));
|
||||
bool isFlipped = (Random() & 1) == 0;
|
||||
dust->sprite.offset = vector_make(0, DLL_STOMP_DUST_DROP);
|
||||
dust->sprite.isFlipX = isFlipped;
|
||||
dust->SetColor(DLL_STOMP_DUST_COLOR, -1, DLL_DUST_PRIORITY, false, true);
|
||||
dust->FollowParent(&npc);
|
||||
dust->Update();
|
||||
}
|
||||
|
||||
float damage = npc.HasEntityFlags(FLAG_DELIRIUM_FORM) ? DLL_DELIRIUM_CRUSH_DAMAGE : DLL_CRUSH_DAMAGE;
|
||||
explosion_damage({.position = npc.pos,
|
||||
.source = &npc,
|
||||
.damageFlags = DAMAGE_CRUSH,
|
||||
.damage = damage,
|
||||
.radius = DLL_CRUSH_RADIUS,
|
||||
.isLineCheck = false});
|
||||
if (isDrop)
|
||||
{
|
||||
ProjectileParams params;
|
||||
if (npc.variant == TRIACHNID)
|
||||
{
|
||||
std::ranges::copy(TRIACHNID_SHOT_COLOR._tint, params.color._tint);
|
||||
std::ranges::copy(TRIACHNID_SHOT_COLOR._offset, params.color._offset);
|
||||
}
|
||||
npc.FireProjectiles(npc.pos, vector_make(DLL_SHOT_SPEED, 0), PROJECTILES_EIGHT, params);
|
||||
}
|
||||
if (npc.variant != TRIACHNID) return;
|
||||
|
||||
Entity* creep = g_game->Spawn({.position = npc.pos, .spawner = &npc, .type = ENTITY_EFFECT, .variant = EFFECT_CREEP_WHITE, .seed = Random()});
|
||||
creep->sprite.scale = vector_make(TRIACHNID_CREEP_SCALE, TRIACHNID_CREEP_SCALE);
|
||||
creep->Update();
|
||||
}
|
||||
|
||||
// Resting: 1 time in 20 it picks its next move.
|
||||
static void dll_rest(Entity_NPC& npc)
|
||||
{
|
||||
if (dll_is_calm(npc) || Random() % DLL_ACT_ODDS != 0) return;
|
||||
|
||||
uint32_t choices = g_game->room->GetAliveEnemiesCount() < DLL_CROWD ? (uint32_t)DLL_ACTIONS.size() : DLL_CROWDED_ACTIONS;
|
||||
npc.state = DLL_ACTIONS[Random() % choices];
|
||||
npc.stateFrame = 0;
|
||||
npc.i2 = 0;
|
||||
}
|
||||
|
||||
// Dropping: harmless until it lands, the Triachnid spreading creep after, and on its first frame it hangs over its
|
||||
// target's column.
|
||||
static void dll_drop(Entity_NPC& npc, int ticks)
|
||||
{
|
||||
npc.sprite.Play("Down");
|
||||
bool isLanded = npc.sprite.WasEventTriggered("Land");
|
||||
npc.entityCollisionClass = isLanded ? ENTCOLL_ALL : ENTCOLL_NONE;
|
||||
for (int tick = 0; isLanded && tick < ticks; tick++)
|
||||
{
|
||||
npc.stateFrame++;
|
||||
if (npc.variant != TRIACHNID || npc.stateFrame >= TRIACHNID_CREEP_FRAMES) continue;
|
||||
|
||||
float angle = random_unit() * RANDOM_HALF_TURN;
|
||||
angle += angle;
|
||||
float reach = (float)npc.stateFrame + (float)npc.stateFrame + TRIACHNID_CREEP_REACH;
|
||||
Vector at = vector_make(std::cos(angle) * reach + npc.pos.x, std::sin(angle) * reach + npc.pos.y);
|
||||
Entity* creep = g_game->Spawn({.position = at, .spawner = &npc, .type = ENTITY_EFFECT, .variant = EFFECT_CREEP_WHITE, .seed = Random()});
|
||||
float growth = (float)npc.stateFrame * TRIACHNID_CREEP_GROWTH + 1;
|
||||
creep->sprite.scale = vector_make(growth, growth);
|
||||
creep->Update();
|
||||
}
|
||||
if (npc.sprite.GetFrame() == 0) npc.pos = vector_make(npc.GetPlayerTarget()->pos.x, npc.targetPosition.y);
|
||||
}
|
||||
|
||||
// Stomping: the body hovers over its target on each stomp's first frame, a leg waits out its delay first.
|
||||
static void dll_stomp(Entity_NPC& npc, int ticks)
|
||||
{
|
||||
if (npc.projectileDelay >= 1)
|
||||
{
|
||||
npc.projectileDelay -= ticks;
|
||||
if (npc.projectileDelay <= 0) npc.sprite.Play("StompArm", PLAY_FORCED);
|
||||
return;
|
||||
}
|
||||
|
||||
bool isDown = !npc.sprite.WasEventTriggered("Jump") && npc.sprite.WasEventTriggered("Land");
|
||||
npc.entityCollisionClass = isDown ? ENTCOLL_ALL : ENTCOLL_NONE;
|
||||
if (npc.i1 == 0)
|
||||
{
|
||||
if (npc.sprite.GetFrame() == 0) npc.pos = npc.GetPlayerTarget()->pos;
|
||||
return;
|
||||
}
|
||||
std::string_view animation = dll_stomp_animation(npc, std::min(npc.i2, DLL_STOMP_LIMB_LIMIT));
|
||||
npc.sprite.Play(animation);
|
||||
}
|
||||
|
||||
// One spider thrown out of the body to a free spot, its spot marked off for walkers.
|
||||
static void dll_spider_throw(Entity_NPC& npc)
|
||||
{
|
||||
Vector spot = room_free_pickup_position_find({.position = npc.pos, .step = DLL_SPIDER_REACH});
|
||||
auto* spider = static_cast<Entity_NPC*>(g_game->Spawn({.position = spot, .spawner = &npc, .type = ENTITY_SPIDER, .seed = Random()}));
|
||||
|
||||
Room& room = *g_game->room;
|
||||
int column = (int)((spot.x - GRID_ORIGIN_X) / GRID_CELL_SIZE + 0.5f);
|
||||
int row = (int)((spot.y - GRID_ORIGIN_Y) / GRID_CELL_SIZE + 0.5f);
|
||||
if (column >= 0 && column < room.gridWidth && row >= 0 && row < room.gridHeight)
|
||||
{
|
||||
int cell = row * room.gridWidth + column;
|
||||
if (cell < ROOM_GRID_CELLS && room.gridPaths[cell] < DLL_PATH_LIMIT) room.gridPaths[cell] = GRID_PATH_FREED;
|
||||
}
|
||||
|
||||
spider->targetPosition = spider->pos;
|
||||
spider->pos = npc.pos;
|
||||
spider->state = NPC_STATE_JUMP;
|
||||
spider->v2.y = DLL_SPIDER_ARC;
|
||||
spider->velocity = vector_scale(vector_sub(spider->targetPosition, npc.pos), DLL_SPIDER_PACE);
|
||||
spider->v1 = spider->velocity;
|
||||
spider->posOffset.y -= DLL_SPIDER_LIFT;
|
||||
}
|
||||
|
||||
// The spit: on Shoot a cloud, then spiders (Daddy Long Legs) or a hopping Trite (the Triachnid).
|
||||
static void dll_spit(Entity_NPC& npc)
|
||||
{
|
||||
npc.sprite.Play("Attack1");
|
||||
if (!npc.sprite.IsEventTriggered("Shoot")) return;
|
||||
|
||||
npc.PlaySound(SOUND_BOSS_SPIT_BLOB_BARF, 1, 2, false, 1);
|
||||
Entity_Effect* cloud = npc.MakeBloodCloud(npc.pos, DLL_CLOUD_COLOR, DLL_CLOUD_SCALE);
|
||||
cloud->posOffset = vector_make(0, DLL_CLOUD_LIFT);
|
||||
if (npc.variant == 0)
|
||||
{
|
||||
int count = (int)(Random() & 1) + DLL_SPIDERS;
|
||||
if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM))
|
||||
count = std::min(count, DLL_DELIRIUM_SPIDERS - npc.CountRelatedEntities(ENTITY_SPIDER, 0, nullptr));
|
||||
for (int i = 0; i < count; i++) dll_spider_throw(npc);
|
||||
return;
|
||||
}
|
||||
|
||||
if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM) &&
|
||||
(uint32_t)npc.CountRelatedEntities(ENTITY_HOPPER, TRITE_VARIANT, nullptr) >= DLL_DELIRIUM_SPIDERS)
|
||||
return;
|
||||
auto* trite = static_cast<Entity_NPC*>(g_game->Spawn({.position = npc.pos, .spawner = &npc, .type = ENTITY_HOPPER, .variant = TRITE_VARIANT, .seed = Random()}));
|
||||
trite->targetPosition = npc.GetPlayerTarget()->pos;
|
||||
trite->state = NPC_STATE_MOVE;
|
||||
trite->stateFrame = TRITE_SPIN_UP;
|
||||
npc_anim_restart(trite->sprite, "Hop");
|
||||
if (trite->sprite.animState.animData) trite->sprite.animState.SetFrameFloat(TRITE_SPIN_UP);
|
||||
}
|
||||
|
||||
// Where a leg falls: on its target's path for the chosen one, else near the target or anywhere around the body.
|
||||
static Vector dll_leg_spot(Entity_NPC& npc, bool isOnTarget)
|
||||
{
|
||||
Entity* target = npc.GetPlayerTarget();
|
||||
Vector spot{};
|
||||
if (isOnTarget)
|
||||
{
|
||||
Vector lead = vector_add(target->pos, vector_scale(target->velocity, random_unit() * LEG_LEAD_FRAMES));
|
||||
spot = room_free_pickup_position_find({.position = lead, .step = LEG_NEAR});
|
||||
float y = random_unit() * LEG_SCATTER - LEG_SCATTER / 2;
|
||||
return vector_make(random_unit() * LEG_SCATTER - LEG_SCATTER / 2 + spot.x, y + spot.y);
|
||||
}
|
||||
|
||||
bool isNearTarget = (Random() & 3) == 0;
|
||||
Vector result{};
|
||||
for (int pick = 0; pick < LEG_PICKS; pick++)
|
||||
{
|
||||
FreeSpotSearch search{.isAvoidActiveEntities = true};
|
||||
search.position = isNearTarget ? target->pos : npc.pos;
|
||||
search.step = isNearTarget ? random_unit() * LEG_TARGET_SPREAD + LEG_TARGET_MIN : random_unit() * LEG_BODY_SPREAD;
|
||||
spot = room_free_pickup_position_find(search);
|
||||
float y = random_unit() * LEG_SCATTER - LEG_SCATTER / 2;
|
||||
result = vector_make(random_unit() * LEG_SCATTER - LEG_SCATTER / 2 + spot.x, y + spot.y);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// The legs: on its first frame it sends 4 (the Triachnid 3) stomping copies down in turn, one on its target.
|
||||
static void dll_legs(Entity_NPC& npc)
|
||||
{
|
||||
npc.sprite.Play("Attack2");
|
||||
bool isDown = !npc.sprite.WasEventTriggered("Jump") || npc.sprite.WasEventTriggered("Land");
|
||||
npc.entityCollisionClass = isDown ? ENTCOLL_ALL : ENTCOLL_NONE;
|
||||
if (npc.stateFrame != 0) return;
|
||||
|
||||
npc.stateFrame = 1;
|
||||
int count = npc.variant == TRIACHNID ? TRIACHNID_STOMPS : DLL_STOMPS;
|
||||
int onTarget = random_below(count);
|
||||
int delay = LEG_FIRST_DELAY;
|
||||
for (int leg = 0; leg < count; leg++)
|
||||
{
|
||||
Vector spot = dll_leg_spot(npc, leg == onTarget);
|
||||
auto* copy = static_cast<Entity_NPC*>(g_game->Spawn({.position = spot, .spawner = &npc, .type = npc.type, .variant = npc.variant, .seed = Random()}));
|
||||
copy->AddEntityFlags(FLAG_DONT_COUNT_BOSS_HP);
|
||||
copy->i1 = DLL_LEG;
|
||||
copy->state = DLL_STOMP;
|
||||
copy->i2 = npc.i2++;
|
||||
copy->projectileDelay = delay;
|
||||
if (copy->sprite.SetAnimation("StompArm", SWITCH_KEEP_FRAME) && copy->sprite.animState.animData)
|
||||
{
|
||||
copy->sprite.animState.SetFrameFloat(0);
|
||||
copy->sprite.animState.isPlaying = false;
|
||||
}
|
||||
copy->entityCollisionClass = ENTCOLL_NONE;
|
||||
copy->SetSize(npc.config->collisionRadius * DLL_UP_WIDTH, vector_make(-1, -1), -1);
|
||||
delay += LEG_DELAY_STEP;
|
||||
}
|
||||
}
|
||||
|
||||
// 00468180 NpcAI::ENTITY_DADDYLONGLEGS: Daddy Long Legs and the Triachnid rest, rise and stomp down on their target,
|
||||
// send stomping legs, or spit spiders or Trites. Their own legs cannot hurt them.
|
||||
void boss_daddy_long_legs_update(Entity_NPC& npc)
|
||||
{
|
||||
if (npc.state == NPC_STATE_INIT)
|
||||
{
|
||||
npc.targetPosition = npc.pos;
|
||||
npc.state = NPC_STATE_IDLE;
|
||||
return;
|
||||
}
|
||||
|
||||
if (npc_anim_is_done(npc) && npc.projectileDelay < 1) dll_animation_end(npc);
|
||||
bool isLanding = npc.state == NPC_STATE_MOVE || npc.state == DLL_STOMP;
|
||||
if (isLanding && npc.sprite.animState.animData && npc.sprite.IsEventTriggered("Land")) dll_land(npc);
|
||||
|
||||
int ticks = npc_ticks_get(npc);
|
||||
npc.friction *= DLL_FRICTION;
|
||||
switch (npc.state)
|
||||
{
|
||||
case NPC_STATE_IDLE:
|
||||
dll_rest(npc);
|
||||
break;
|
||||
case NPC_STATE_MOVE:
|
||||
dll_drop(npc, ticks);
|
||||
break;
|
||||
case DLL_RISE:
|
||||
npc.entityCollisionClass = npc.sprite.WasEventTriggered("Jump") ? ENTCOLL_NONE : ENTCOLL_ALL;
|
||||
npc.sprite.Play("Up");
|
||||
break;
|
||||
case DLL_STOMP:
|
||||
dll_stomp(npc, ticks);
|
||||
break;
|
||||
case DLL_SPIT:
|
||||
dll_spit(npc);
|
||||
break;
|
||||
case DLL_LEGS:
|
||||
dll_legs(npc);
|
||||
break;
|
||||
}
|
||||
|
||||
if (npc.pendingDamage > 0)
|
||||
for (DamageEvent& event : npc.damageEvents)
|
||||
if (event.source.type == ENTITY_DADDYLONGLEGS) event.damage = 0;
|
||||
if (!npc.isDead || npc.i1 != 0) return;
|
||||
|
||||
Room& room = *g_game->room;
|
||||
room.bloodFromWallsDuration = DLL_DEATH_BLOOD_FRAMES;
|
||||
room.bloodFromWallsCount = DLL_DEATH_BLOOD_DROPS;
|
||||
}
|
||||
@@ -21,10 +21,6 @@
|
||||
#include <array>
|
||||
#include <cstdio>
|
||||
|
||||
constexpr int ENTITY_SLOTH = 46;
|
||||
constexpr int ENTITY_ENVY = 51;
|
||||
constexpr int ENTITY_PRIDE = 52;
|
||||
constexpr int ENTITY_FALLEN = 81;
|
||||
constexpr int VARIANT_SUPER = 1;
|
||||
constexpr int VARIANT_ULTRA_PRIDE = 2;
|
||||
constexpr int VARIANT_KRAMPUS = 1;
|
||||
|
||||
@@ -0,0 +1,340 @@
|
||||
#include "boss_ai.h"
|
||||
#include "entity_laser.h"
|
||||
#include "npc_caves.h"
|
||||
#include "sfx_manager.h"
|
||||
#include <cmath>
|
||||
|
||||
// The Fallen's moves (states): a spread of shots, a charge, a cross of beams, and Krampus's spinning cross.
|
||||
enum FallenState
|
||||
{
|
||||
FALLEN_SHOTS = NPC_STATE_ATTACK,
|
||||
FALLEN_CHARGE = NPC_STATE_ATTACK2,
|
||||
FALLEN_CROSS = NPC_STATE_ATTACK3,
|
||||
FALLEN_SPIN = NPC_STATE_ATTACK4,
|
||||
FALLEN_SPLIT = NPC_STATE_SUMMON
|
||||
};
|
||||
|
||||
constexpr int KRAMPUS = 1;
|
||||
constexpr float FALLEN_FRICTION = 0.8f;
|
||||
|
||||
// Walking about, it acts one frame in three (its halves every frame): a charge one roll in 80, Krampus's beams one in
|
||||
// 20 lined up within 20 and 400 of the target (or one in 200 anyway), else one in 20 the shots within 230.
|
||||
constexpr float WALK_SPEED = 1;
|
||||
constexpr float FALLEN_WALK_THRESHOLD = 3;
|
||||
constexpr int FALLEN_ACT_ODDS = 3;
|
||||
constexpr int CHARGE_ODDS = 80;
|
||||
constexpr int KRAMPUS_BEAM_ODDS = 20;
|
||||
constexpr int KRAMPUS_BEAM_ANYWAY_ODDS = 200;
|
||||
constexpr float KRAMPUS_LINE_UP = 20;
|
||||
constexpr float KRAMPUS_BEAM_REACH = 400;
|
||||
constexpr int SHOTS_ODDS = 20;
|
||||
constexpr float SHOTS_REACH = 230;
|
||||
|
||||
// The shots: three (four on Shoot2) at 8.2 toward the target 10 frames ahead. Krampus follows them with his beams one
|
||||
// time in three.
|
||||
constexpr float SHOT_LEAD_FRAMES = 10;
|
||||
constexpr float FALLEN_SHOT_SPEED = 8.2f;
|
||||
|
||||
// The charge: it chases the target's spot 10 frames ahead at 1.4, growling from frame 120, until an eighth of its
|
||||
// health is hurt away, when it turns to its beams.
|
||||
constexpr float CHARGE_LEAD_FRAMES = 10;
|
||||
constexpr float CHARGE_ACCEL = 1.4f;
|
||||
constexpr int CHARGE_GROWL_FRAMES = 119;
|
||||
constexpr int CHARGE_GROWL_ODDS = 60;
|
||||
constexpr int CHARGE_GROWL_DELAY = 120;
|
||||
constexpr float CHARGE_HURT_SHARE = 0.125f;
|
||||
|
||||
// The beams: four brimstone beams for 30 frames from 10 out (20 up), a diagonal cross for Krampus one time in two (and
|
||||
// in his first 60 frames), or his spin, which turns a quarter at 2 a frame after 30 frames for 50. Tracers show the
|
||||
// way 22 frames ahead (32 for Krampus). Between Shoot2 and its end it drifts to the target at 8 to 15 a frame.
|
||||
constexpr int BEAMS = 4;
|
||||
constexpr float BEAM_TURN = 90;
|
||||
constexpr float BEAM_DIAGONAL = 45;
|
||||
constexpr float BEAM_OUT = 10;
|
||||
constexpr float FALLEN_BEAM_RISE = 20;
|
||||
constexpr float FALLEN_BEAM_DEPTH = -10;
|
||||
constexpr int FALLEN_BEAM_TIMEOUT = 30;
|
||||
constexpr int SPIN_TIMEOUT = 50;
|
||||
constexpr int SPIN_DELAY = 30;
|
||||
constexpr float SPIN_TURN = 90;
|
||||
constexpr float SPIN_SPEED = 2;
|
||||
constexpr int YOUNG_FRAMES = 60;
|
||||
constexpr float TRACER_RISE = 40;
|
||||
constexpr float FALLEN_TRACER_SCALE = 4;
|
||||
constexpr int FALLEN_TRACER_TIMEOUT = 22;
|
||||
constexpr int TRACER_TIMEOUT_KRAMPUS = 32;
|
||||
constexpr ColorMod FALLEN_TRACER_COLOR = {{0.6f, 0.05f, 0, 0.8f}, {0, 0, 0, 0}, {0, 0, 0}};
|
||||
constexpr float DRIFT_MARGIN = 100;
|
||||
constexpr float DRIFT_SCALE = 0.05f;
|
||||
constexpr float DRIFT_MIN = 8;
|
||||
constexpr float DRIFT_MAX = 15;
|
||||
constexpr float DRIFT_DECAY = 0.2f;
|
||||
|
||||
// Below half health the Fallen (not its halves, nor Krampus) splits into two halves of three quarters, 30 to each side
|
||||
// and 20 up, each with half its health (20 as Delirium's form), with two black puffs.
|
||||
constexpr float SPLIT_HEALTH = 0.5f;
|
||||
constexpr float FALLEN_SPLIT_SCALE = 0.75f;
|
||||
constexpr float DELIRIUM_SPLIT_HEALTH = 20;
|
||||
constexpr float SPLIT_PUFF_TURN = 30;
|
||||
constexpr int SPLIT_PUFF_SIZE = 3;
|
||||
constexpr float SPLIT_VOLUME = 2;
|
||||
constexpr ColorMod SPLIT_PUFF_COLOR = {{0, 0, 0, 1}, {0, 0, 0, 0}, {0, 0, 0}};
|
||||
static const Vector SPLIT_SPOTS[] = {vector_make(30, -20), vector_make(-30, -20)};
|
||||
|
||||
// The wing beats' sounds, at the pitch its size gives.
|
||||
static void wing_sounds_play(Entity_NPC& npc)
|
||||
{
|
||||
if (!npc.sprite.animState.animData) return;
|
||||
if (npc.sprite.IsEventTriggered("FlapChase")) npc_sound_play(SOUND_FALLEN_FLAP_CHASE, 1, 2, champion_pitch_get(npc));
|
||||
if (npc.sprite.IsEventTriggered("Flap")) npc_sound_play(SOUND_FALLEN_FLAP, 1, 2, champion_pitch_get(npc));
|
||||
if (npc.sprite.IsEventTriggered("OpenWings")) npc_sound_play(SOUND_FALLEN_OPEN_WINGS, 1, 2, champion_pitch_get(npc));
|
||||
}
|
||||
|
||||
// The beams' tracers, showing where the cross will fire.
|
||||
static void tracers_spawn(Entity_NPC& npc)
|
||||
{
|
||||
int timeout = npc.variant == KRAMPUS ? TRACER_TIMEOUT_KRAMPUS : FALLEN_TRACER_TIMEOUT;
|
||||
float turn = npc.i1 ? BEAM_DIAGONAL : 0;
|
||||
for (int i = 0; i < BEAMS; i++)
|
||||
following_effect_spawn(npc, {.offset = vector_make(0, -TRACER_RISE),
|
||||
.targetPosition = vector_from_angle((float)i * BEAM_TURN + turn),
|
||||
.color = FALLEN_TRACER_COLOR,
|
||||
.scale = FALLEN_TRACER_SCALE,
|
||||
.timeout = timeout});
|
||||
}
|
||||
|
||||
// Whether Krampus's cross fires diagonally: one time in two, and always while he is young.
|
||||
static bool is_cross_diagonal(Entity_NPC& npc)
|
||||
{
|
||||
return npc.variant == KRAMPUS && npc.state == FALLEN_CROSS &&
|
||||
((Random() & 1) == 0 || g_game->frameCount - npc.spawnFrame < YOUNG_FRAMES);
|
||||
}
|
||||
|
||||
// Starts the beams with a yell: the cross, or for Krampus one time in four the spin.
|
||||
static void beams_start(Entity_NPC& npc)
|
||||
{
|
||||
npc.PlaySound(SOUND_MONSTER_YELL_B, 1, 2, false, 1);
|
||||
npc.state = FALLEN_CROSS;
|
||||
if (npc.variant == KRAMPUS && (Random() & 3) == 0) npc.state = FALLEN_SPIN;
|
||||
npc.i1 = is_cross_diagonal(npc);
|
||||
tracers_spawn(npc);
|
||||
npc.stateFrame = 0;
|
||||
npc.v1.x = 0;
|
||||
}
|
||||
|
||||
// Walking about at random, and now and then the charge, Krampus's beams or the shots.
|
||||
static void walk_update(Entity_NPC& npc)
|
||||
{
|
||||
npc.pathfinder.MoveRandomlyAxisAligned(WALK_SPEED, STATUS_OBEYED);
|
||||
npc.AnimWalkFrame("Walk", "Walk", FALLEN_WALK_THRESHOLD);
|
||||
if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM) && room_is_clear()) return;
|
||||
if (Random() % FALLEN_ACT_ODDS != 0 && npc.spawnerType != npc.type) return;
|
||||
|
||||
Vector toTarget = vector_sub(npc.GetPlayerTarget()->pos, npc.pos);
|
||||
if (Random() % CHARGE_ODDS == 0 && npc.variant == 0)
|
||||
{
|
||||
npc.PlaySound(SOUND_MONSTER_YELL_B, 1, 2, false, 1);
|
||||
npc.state = FALLEN_CHARGE;
|
||||
npc.stateFrame = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
bool isLinedUp = (std::abs(toTarget.x) < KRAMPUS_LINE_UP || std::abs(toTarget.y) < KRAMPUS_LINE_UP) &&
|
||||
vector_length(toTarget) < KRAMPUS_BEAM_REACH;
|
||||
bool isBeams = npc.variant == KRAMPUS &&
|
||||
((Random() % KRAMPUS_BEAM_ODDS == 0 && isLinedUp) || Random() % KRAMPUS_BEAM_ANYWAY_ODDS == 0);
|
||||
if (isBeams) return beams_start(npc);
|
||||
if (Random() % SHOTS_ODDS != 0 || vector_length(toTarget) >= SHOTS_REACH) return;
|
||||
|
||||
npc.sprite.isFlipX = toTarget.x < 0;
|
||||
npc.state = FALLEN_SHOTS;
|
||||
npc.stateFrame = 0;
|
||||
}
|
||||
|
||||
// The shots on Shoot (three) and Shoot2 (four), then walking on, or Krampus's beams one time in three.
|
||||
static void shots_update(Entity_NPC& npc)
|
||||
{
|
||||
npc.stateFrame++;
|
||||
npc.sprite.Play("Attack1");
|
||||
if (npc.sprite.animState.animData)
|
||||
{
|
||||
bool isShoot = npc.sprite.IsEventTriggered("Shoot");
|
||||
if (isShoot || npc.sprite.IsEventTriggered("Shoot2"))
|
||||
{
|
||||
npc.PlaySound(isShoot ? SOUND_MONSTER_GRUNT_2 : SOUND_MONSTER_GRUNT_1, 1, 2, false, 1);
|
||||
Entity& target = *npc.GetPlayerTarget();
|
||||
Vector aim = vector_sub(vector_add(vector_scale(target.velocity, SHOT_LEAD_FRAMES), target.pos), npc.pos);
|
||||
Vector velocity = vector_scale(vector_normalized(aim), FALLEN_SHOT_SPEED);
|
||||
npc.FireProjectiles(npc.pos, velocity, isShoot ? PROJECTILES_THREE : PROJECTILES_FOUR, ProjectileParams());
|
||||
return;
|
||||
}
|
||||
if (!npc_anim_is_done(npc)) return;
|
||||
}
|
||||
if (Random() % FALLEN_ACT_ODDS != 0 || npc.variant != KRAMPUS)
|
||||
{
|
||||
npc.state = NPC_STATE_MOVE;
|
||||
return;
|
||||
}
|
||||
beams_start(npc);
|
||||
}
|
||||
|
||||
// The charge: it chases its target, growling after a while, until hurt enough, then fires its cross.
|
||||
static void charge_update(Entity_NPC& npc)
|
||||
{
|
||||
if (npc.stateFrame == 0)
|
||||
{
|
||||
npc.sprite.Play("ChargeStart");
|
||||
npc.stateFrame++;
|
||||
}
|
||||
else if (npc_anim_is_done(npc)) npc.sprite.Play("Charge");
|
||||
if (!npc.sprite.IsPlaying("Charge")) return;
|
||||
|
||||
if (npc.stateFrame++ > CHARGE_GROWL_FRAMES && Random() % CHARGE_GROWL_ODDS != 0)
|
||||
npc.PlaySound(SOUND_FALLEN_GROWL, 1, CHARGE_GROWL_DELAY, false, 1);
|
||||
Vector aim = vector_add(npc.CalcTargetPosition(0), vector_scale(npc.GetPlayerTarget()->velocity, CHARGE_LEAD_FRAMES));
|
||||
Vector toAim = vector_sub(aim, npc.pos);
|
||||
npc_push(npc, vector_scale(vector_normalized(toAim), CHARGE_ACCEL));
|
||||
npc.v1.x += npc.pendingDamage;
|
||||
npc.sprite.isFlipX = toAim.x < 0;
|
||||
if (npc.v1.x <= npc.maxHitPoints * CHARGE_HURT_SHARE) return;
|
||||
|
||||
npc.state = FALLEN_CROSS;
|
||||
npc.stateFrame = 0;
|
||||
npc.v1.x = 0;
|
||||
npc.i1 = is_cross_diagonal(npc);
|
||||
tracers_spawn(npc);
|
||||
}
|
||||
|
||||
// An angle brought within -180 to 180, as the beams take it.
|
||||
static float angle_wrap(float degrees)
|
||||
{
|
||||
if (std::abs(degrees) > 360) degrees = std::fmod(degrees, 360.0f);
|
||||
if (degrees > 180) return degrees - 360;
|
||||
return degrees < -180 ? degrees + 360 : degrees;
|
||||
}
|
||||
|
||||
// The cross of four beams on Shoot, the spin's turning a quarter either way. From Shoot2 it drifts toward the target,
|
||||
// slowing to a stop.
|
||||
static void beams_update(Entity_NPC& npc)
|
||||
{
|
||||
bool isSpin = npc.state == FALLEN_SPIN;
|
||||
npc.sprite.Play(isSpin ? "Attack2Alt" : "Attack2");
|
||||
if (npc.sprite.animState.animData && npc.sprite.IsEventTriggered("Shoot2"))
|
||||
{
|
||||
Vector spot = g_game->room->GetClampedPositionImpl(npc.GetPlayerTarget()->pos, DRIFT_MARGIN, DRIFT_MARGIN,
|
||||
DRIFT_MARGIN, DRIFT_MARGIN);
|
||||
Vector drift = vector_scale(vector_sub(spot, npc.pos), DRIFT_SCALE);
|
||||
float speed = vector_length(drift);
|
||||
if (speed < DRIFT_MIN && speed > 0) drift = vector_scale(drift, DRIFT_MIN / speed);
|
||||
else if (speed > DRIFT_MAX) drift = vector_scale(drift, DRIFT_MAX / speed);
|
||||
npc.targetPosition = drift;
|
||||
npc.v1.y = 1;
|
||||
npc.sprite.isFlipX = drift.x < 0;
|
||||
}
|
||||
else if (npc.sprite.WasEventTriggered("Shoot2") && npc.v1.y > 0)
|
||||
{
|
||||
npc.velocity = vector_add(npc.velocity, vector_scale(npc.targetPosition, npc.v1.y * npc.speedMultiplier));
|
||||
npc.v1.y = std::max(npc.v1.y - npc.speedMultiplier * DRIFT_DECAY, 0.0f);
|
||||
}
|
||||
npc.stateFrame++;
|
||||
|
||||
if (npc.sprite.animState.animData)
|
||||
{
|
||||
if (npc.sprite.IsEventTriggered("Shoot"))
|
||||
{
|
||||
float spin = (Random() & 1) ? -1.0f : 1.0f;
|
||||
float turn = npc.variant == KRAMPUS && npc.state == FALLEN_CROSS && npc.i1 ? BEAM_DIAGONAL : 0;
|
||||
for (int i = 0; i < BEAMS; i++)
|
||||
{
|
||||
float angle = (float)i * BEAM_TURN + turn;
|
||||
Vector from = isSpin ? npc.pos : vector_add(npc.pos, vector_make(std::cos(angle * DEGREES_TO_RADIANS) * BEAM_OUT,
|
||||
std::sin(angle * DEGREES_TO_RADIANS) * BEAM_OUT - FALLEN_BEAM_RISE));
|
||||
Entity_Laser* laser = Entity_Laser::ShootAngle({.position = from,
|
||||
.posOffset = vector_make(0, -FALLEN_BEAM_RISE),
|
||||
.source = &npc,
|
||||
.angleDegrees = angle_wrap(angle),
|
||||
.timeout = isSpin ? SPIN_TIMEOUT : FALLEN_BEAM_TIMEOUT,
|
||||
.variant = LASER_THICK_RED});
|
||||
laser->renderDepthOffset = FALLEN_BEAM_DEPTH;
|
||||
if (isSpin)
|
||||
{
|
||||
laser->isActiveRotating = true;
|
||||
laser->rotationDelay = SPIN_DELAY;
|
||||
laser->rotationDegrees = spin * SPIN_TURN;
|
||||
laser->rotationSpd = spin * SPIN_SPEED;
|
||||
}
|
||||
laser->Update();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!npc_anim_is_done(npc)) return;
|
||||
}
|
||||
npc.state = NPC_STATE_MOVE;
|
||||
}
|
||||
|
||||
// The split: once its animation ends, two black puffs and two smaller halves take its place.
|
||||
static void split_update(Entity_NPC& npc)
|
||||
{
|
||||
npc.sprite.Play("Split");
|
||||
npc.stateFrame++;
|
||||
npc.entityCollisionClass = ENTCOLL_NONE;
|
||||
if (!npc_anim_is_done(npc)) return;
|
||||
|
||||
npc.PlaySound(SOUND_SUMMONSOUND, SPLIT_VOLUME, 2, false, 1);
|
||||
for (int i = -1; i <= 0; i++)
|
||||
{
|
||||
auto* puff = static_cast<Entity_Effect*>(g_game->Spawn({.position = npc.pos, .spawner = &npc,
|
||||
.subType = SPLIT_PUFF_SIZE, .type = ENTITY_EFFECT,
|
||||
.variant = EFFECT_POOF01, .seed = Random()}));
|
||||
puff->SetColor(SPLIT_PUFF_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true);
|
||||
puff->rotation = (float)i * SPLIT_PUFF_TURN;
|
||||
}
|
||||
for (const Vector& spot : SPLIT_SPOTS)
|
||||
{
|
||||
auto* half = static_cast<Entity_NPC*>(g_game->Spawn({.position = vector_add(npc.pos, spot), .spawner = &npc,
|
||||
.type = npc.type, .variant = npc.variant,
|
||||
.seed = Random()}));
|
||||
half->health *= SPLIT_HEALTH;
|
||||
if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM))
|
||||
{
|
||||
half->maxHitPoints = DELIRIUM_SPLIT_HEALTH;
|
||||
half->health = DELIRIUM_SPLIT_HEALTH;
|
||||
}
|
||||
half->scale = FALLEN_SPLIT_SCALE;
|
||||
half->sprite.scale = vector_make(half->shrinkStatus1 * FALLEN_SPLIT_SCALE, half->shrinkStatus1 * FALLEN_SPLIT_SCALE);
|
||||
}
|
||||
npc.Kill(EntityRef());
|
||||
}
|
||||
|
||||
// 0045b830 The Fallen (81) and Krampus (81.1): wanders and shoots, charges, fires crosses of beams, and the Fallen
|
||||
// splits in two below half health.
|
||||
void boss_fallen_update(Entity_NPC& npc)
|
||||
{
|
||||
if (npc.state == NPC_STATE_INIT)
|
||||
{
|
||||
npc.state = NPC_STATE_MOVE;
|
||||
return;
|
||||
}
|
||||
wing_sounds_play(npc);
|
||||
npc.friction *= FALLEN_FRICTION;
|
||||
|
||||
bool isWhole = npc.spawnerType != npc.type && npc.variant == 0;
|
||||
if (npc.health / npc.maxHitPoints < SPLIT_HEALTH && isWhole && npc.state != FALLEN_SPLIT)
|
||||
{
|
||||
npc.PlaySound(SOUND_MONSTER_ROAR_2, 1, 2, false, 1);
|
||||
npc.state = FALLEN_SPLIT;
|
||||
npc.stateFrame = 0;
|
||||
npc.health = std::max(npc.health, 1.0f);
|
||||
npc.isDead = false;
|
||||
}
|
||||
|
||||
switch (npc.state)
|
||||
{
|
||||
case NPC_STATE_MOVE: return walk_update(npc);
|
||||
case FALLEN_SHOTS: return shots_update(npc);
|
||||
case FALLEN_CHARGE: return charge_update(npc);
|
||||
case FALLEN_CROSS:
|
||||
case FALLEN_SPIN: return beams_update(npc);
|
||||
case FALLEN_SPLIT: return split_update(npc);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,586 @@
|
||||
#include "boss_ai.h"
|
||||
#include "entity_bomb.h"
|
||||
#include "entity_config.h"
|
||||
#include "entity_laser.h"
|
||||
#include "grid_entity_trap_door.h"
|
||||
#include "manager.h"
|
||||
#include "music_manager.h"
|
||||
#include "npc_caves.h"
|
||||
#include "room_grid.h"
|
||||
#include "sfx_manager.h"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
|
||||
// Satan's phases (his i1): the statue, waiting while the Fallen fights, the fight, his death, and the feet he leaves.
|
||||
enum SatanPhase
|
||||
{
|
||||
SATAN_STATUE,
|
||||
SATAN_AWAKENING,
|
||||
SATAN_FIGHT,
|
||||
SATAN_DYING,
|
||||
SATAN_FEET
|
||||
};
|
||||
|
||||
// His attacks (states): a spread of shots, a brimstone beam straight down, two sweeping beams, and two shot fans.
|
||||
enum SatanAttack
|
||||
{
|
||||
SATAN_SPREAD = NPC_STATE_ATTACK,
|
||||
SATAN_BEAM = NPC_STATE_ATTACK2,
|
||||
SATAN_SWEEP = NPC_STATE_ATTACK3,
|
||||
SATAN_FANS = NPC_STATE_ATTACK4
|
||||
};
|
||||
|
||||
constexpr int SATAN_FEET_VARIANT = 10;
|
||||
constexpr float SATAN_FRICTION = 0.8f;
|
||||
constexpr int KAMIKAZE_LEECH = 1;
|
||||
|
||||
// The statue sinks 80 into the floor, blocks its cell's path and wakes 130 frames in, calling the Fallen and two
|
||||
// kamikaze leeches 30 below it (50 to each side). Satan rises 25 frames after he is the last enemy left.
|
||||
constexpr float SATAN_STATUE_SINK = 80;
|
||||
constexpr int STATUE_PATH_BLOCKED = 2000;
|
||||
constexpr int STATUE_PATH_AWAKE = 1000;
|
||||
constexpr int STATUE_SOUND_FRAME = 2;
|
||||
constexpr int STATUE_WAKE_FRAMES = 130;
|
||||
constexpr float SUMMON_DROP = 30;
|
||||
constexpr float LEECH_SPREAD = 50;
|
||||
constexpr int RISE_FRAME = 25;
|
||||
constexpr float BOSS_MUSIC_FADE = 0.08f;
|
||||
|
||||
// The fight: Satan keeps below y 245 and 120 from the side walls, walks toward a spot 60 above his target (93% of its
|
||||
// height, at least 305), leading it by 25 frames of its speed, and steps at most 15 across and 7 down a frame.
|
||||
constexpr float FIGHT_TOP = 245;
|
||||
constexpr float WALK_TARGET_SCALE = 0.93f;
|
||||
constexpr float WALK_TARGET_MIN = 305;
|
||||
constexpr float WALK_TARGET_RISE = 60;
|
||||
constexpr float WALK_LEAD_FRAMES = 25;
|
||||
constexpr float WALK_STEP_X = 15;
|
||||
constexpr float WALK_STEP_Y = 7;
|
||||
constexpr float WALK_ACCEL = 0.1f;
|
||||
constexpr float SIDE_MARGIN = 120;
|
||||
|
||||
// The attack choices: a beam when the target crosses beneath him (above 70 over his aim), one roll in 15 for a spread
|
||||
// (3 in 10) or the fans, and the sweep for a target 40 to 200 to the side.
|
||||
constexpr float BEAM_REACH_UP = -70;
|
||||
constexpr int BEAM_REPEAT_ODDS = 10;
|
||||
constexpr float SWEEP_REPEAT_REACH = 40;
|
||||
constexpr int SWEEP_REPEAT_ODDS = 3;
|
||||
constexpr int SHOT_ODDS = 15;
|
||||
constexpr int SPREAD_ODDS = 10;
|
||||
constexpr int SPREAD_IN_TEN = 3;
|
||||
constexpr int ATTACK_ODDS = 3;
|
||||
constexpr float WALK_ONLY_REACH = 100;
|
||||
constexpr float SWEEP_REACH_MIN = 40;
|
||||
constexpr float SWEEP_LEAD_MAX = 200;
|
||||
|
||||
// The spread: big shots aimed 5 frames ahead, five (four on Shoot2) at 8.2 (10 past 300) times 0.85, again from frame
|
||||
// 10 unless the target is 300 away or one roll in 3.
|
||||
constexpr float SPREAD_LEAD_FRAMES = 5;
|
||||
constexpr float SPREAD_SCALE = 1.4f;
|
||||
constexpr float SPREAD_SPREAD = 1.15f;
|
||||
constexpr float SPREAD_FALL_ACCEL = -0.07f;
|
||||
constexpr float SPREAD_HEIGHT = -40;
|
||||
constexpr float SPREAD_FALL_SPEED = 5.5f;
|
||||
constexpr float SPREAD_FAR = 300;
|
||||
constexpr float SPREAD_SPEED = 8.2f;
|
||||
constexpr float SPREAD_SPEED_FAR = 10;
|
||||
constexpr float SPREAD_SPEED_SCALE = 0.85f;
|
||||
constexpr float SPREAD_REPEAT_FRAME = 10;
|
||||
|
||||
// The beams: a straight one 60 above him for 16 frames, 1.2 wide, and two that sweep 1.5 a frame from 40 to each side
|
||||
// of straight down, 100 out, for 14 frames. He shakes 10 (5 for the sweeps and fans) while they fire.
|
||||
constexpr float SATAN_BEAM_RISE = 60;
|
||||
constexpr float BEAM_ANGLE = 90;
|
||||
constexpr int SATAN_BEAM_TIMEOUT = 16;
|
||||
constexpr float BEAM_SCALE = 1.2f;
|
||||
constexpr float SATAN_BEAM_DEPTH = 3000;
|
||||
constexpr float BEAM_RECOIL = 5;
|
||||
constexpr float BEAM_SHAKE = 10;
|
||||
constexpr float SWEEP_SHAKE = 5;
|
||||
constexpr int SATAN_SWEEP_TIMEOUT = 14;
|
||||
constexpr float SWEEP_REACH = 100;
|
||||
constexpr float SWEEP_ROTATION = 40;
|
||||
constexpr float SATAN_SWEEP_SPEED = 1.5f;
|
||||
constexpr float SWEEP_ANGLE_LEFT = 120;
|
||||
constexpr float SWEEP_ANGLE_RIGHT = 60;
|
||||
constexpr float SWEEP_RECOIL = 2.5f;
|
||||
|
||||
// The fans: a ring each side, 100 out, of shots kept within their side's half turn.
|
||||
constexpr float FAN_REACH = 100;
|
||||
constexpr float FAN_HEIGHT = -40;
|
||||
constexpr float FAN_FALL_SPEED = 2.5f;
|
||||
constexpr float FAN_DOT_LIMIT = -0.38f;
|
||||
static const Vector FAN_VELOCITY = vector_make(7.5f, 14);
|
||||
|
||||
// His death: grey dust and a shake at Shoot, three red bursts about him at Shoot2, then the feet take over.
|
||||
constexpr ColorMod DEATH_DUST_COLOR = {{0.52f, 0.52f, 0.52f, 0.8f}, {0, 0, 0, 0}, {0, 0, 0}};
|
||||
constexpr ColorMod DEATH_BURST_COLOR = {{1, 0.05f, 0.05f, 0.8f}, {0, 0, 0, 0}, {0, 0, 0}};
|
||||
constexpr int DEATH_SHAKE = 12;
|
||||
constexpr int DEATH_BURST_SIZE = 2;
|
||||
constexpr float DEATH_BURST_REACH = 10;
|
||||
static const std::array<Vector, 3> DEATH_BURSTS = {vector_make(-40, -10), vector_make(40, -10), vector_make(0, 10)};
|
||||
|
||||
// The feet: hidden, each rolls one in 9 to stomp on its target, unless the other lifted less than 21 frames ago, kept
|
||||
// 111 from it. A stomp crushes 300 within 70 and ripples the room, and with fewer than 4 enemies one roll in 2 calls a
|
||||
// leech 200 out. A foot's death kills the other and hurts every enemy left by 100.
|
||||
constexpr int SATAN_STOMP_ODDS = 9;
|
||||
constexpr int STOMP_SETTLE_FRAMES = 21;
|
||||
constexpr float FEET_SPACING = 111;
|
||||
constexpr int STOMP_LEECH_CROWD = 4;
|
||||
constexpr float STOMP_LEECH_REACH = 200;
|
||||
constexpr float SATAN_STOMP_DAMAGE = 300;
|
||||
constexpr float SATAN_STOMP_RADIUS = 70;
|
||||
constexpr float SATAN_STOMP_RIPPLE_AMPLITUDE = 0.04f;
|
||||
constexpr float SATAN_STOMP_RIPPLE_SPEED = 0.025f;
|
||||
constexpr int SATAN_STOMP_RIPPLE_FRAMES = 13;
|
||||
constexpr ColorMod SATAN_STOMP_DUST_COLOR = {{0.62f, 0.62f, 0.62f, 0.8f}, {0, 0, 0, 0}, {0, 0, 0}};
|
||||
constexpr float FEET_DEATH_DAMAGE = 100;
|
||||
constexpr int FEET_DEATH_COUNTDOWN = 30;
|
||||
|
||||
// 007ebc40 Crossfades to the room's boss track as a boss fight starts.
|
||||
void boss_music_crossfade()
|
||||
{
|
||||
g_manager->musicManager.Crossfade(g_game->room->boss_music_get(), BOSS_MUSIC_FADE);
|
||||
}
|
||||
|
||||
// Explosions and crushes neither a player nor a familiar set off pass Satan by, his feet's stomps among them.
|
||||
static void stray_blasts_ignore(Entity_NPC& npc)
|
||||
{
|
||||
if (npc.pendingDamage <= 0) return;
|
||||
for (DamageEvent& event : npc.damageEvents)
|
||||
{
|
||||
bool isBlast = event.damageFlags & (DAMAGE_EXPLOSION | DAMAGE_CRUSH);
|
||||
bool isPlayers = event.source.type == ENTITY_PLAYER || event.source.spawnerType == ENTITY_PLAYER ||
|
||||
event.source.spawnerType == ENTITY_FAMILIAR;
|
||||
if (!isBlast || isPlayers) continue;
|
||||
npc.pendingDamage -= event.damage;
|
||||
event.damage = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// A blow that would kill him mid fight starts his death instead, at no health.
|
||||
static void death_start(Entity_NPC& npc)
|
||||
{
|
||||
npc.damageEvents.clear();
|
||||
npc.pendingDamage = 0;
|
||||
npc.pendingDamageFlags = 0;
|
||||
npc.stateFrame = 0;
|
||||
npc.health = 0;
|
||||
npc.state = NPC_STATE_MOVE;
|
||||
npc.isDead = false;
|
||||
npc.i1 = SATAN_DYING;
|
||||
npc_sound_play(SOUND_SATAN_HURT, 1, 2, champion_pitch_get(npc));
|
||||
npc_anim_restart(npc.sprite, "Death");
|
||||
npc.RemoveStatusEffects();
|
||||
}
|
||||
|
||||
// The first update: Satan sinks into his statue with no health to hurt, a foot hides with a stomp's sound.
|
||||
static void satan_init(Entity_NPC& npc)
|
||||
{
|
||||
npc.state = NPC_STATE_IDLE;
|
||||
npc.entityCollisionClass = ENTCOLL_NONE;
|
||||
if (npc.variant != SATAN_FEET_VARIANT)
|
||||
{
|
||||
npc.ClearEntityFlags(FLAG_APPEAR);
|
||||
npc.maxHitPoints = 0;
|
||||
npc.health = 0;
|
||||
npc.damageEvents.clear();
|
||||
npc.pendingDamage = 0;
|
||||
npc.pendingDamageFlags = 0;
|
||||
npc.shadowSize = 0;
|
||||
npc.pos.y += SATAN_STATUE_SINK;
|
||||
npc.targetPosition = npc.pos;
|
||||
return;
|
||||
}
|
||||
npc_sound_play(SOUND_SATAN_STOMP, 1, 4, champion_pitch_get(npc));
|
||||
npc.i1 = SATAN_FEET;
|
||||
npc.stateFrame = 0;
|
||||
npc.isVisible = false;
|
||||
npc.shadowSize = 0;
|
||||
}
|
||||
|
||||
// Spawns an entity from Satan and runs its first update at once.
|
||||
static void summon(Entity_NPC& npc, int type, int variant, Vector offset)
|
||||
{
|
||||
Entity* entity = g_game->Spawn({.position = vector_add(npc.pos, offset), .spawner = &npc, .type = type,
|
||||
.variant = variant, .seed = Random()});
|
||||
entity->Update();
|
||||
}
|
||||
|
||||
// The statue: it blocks its cell, then wakes with a blast, calls the Fallen and two leeches and starts the boss music.
|
||||
static void statue_update(Entity_NPC& npc, int ticks, int gridIndex)
|
||||
{
|
||||
npc.entityGridCollisionClass = GRIDCOLL_NONE;
|
||||
Room& room = *g_game->room;
|
||||
if (gridIndex >= 0) room.gridPaths[gridIndex] = STATUE_PATH_BLOCKED;
|
||||
for (; ticks > 0; ticks--)
|
||||
if (++npc.stateFrame == STATUE_SOUND_FRAME) npc_sound_play(SOUND_SATAN_APPEAR, 1, 2, champion_pitch_get(npc));
|
||||
|
||||
if (npc.stateFrame > STATUE_WAKE_FRAMES)
|
||||
{
|
||||
npc_sound_play(SOUND_SATAN_BLAST, 1, 2, champion_pitch_get(npc));
|
||||
npc_sound_play(SOUND_SUMMONSOUND, 2, 2, champion_pitch_get(npc));
|
||||
npc.stateFrame = 0;
|
||||
npc.i1++;
|
||||
summon(npc, ENTITY_FALLEN, 0, vector_make(0, SUMMON_DROP));
|
||||
summon(npc, ENTITY_LEECH, KAMIKAZE_LEECH, vector_make(LEECH_SPREAD, SUMMON_DROP));
|
||||
summon(npc, ENTITY_LEECH, KAMIKAZE_LEECH, vector_make(-LEECH_SPREAD, SUMMON_DROP));
|
||||
boss_music_crossfade();
|
||||
}
|
||||
|
||||
const AnimationData* anim = npc.sprite.animState.animData;
|
||||
bool isIdleDone = anim && !npc.sprite.animState.isPlaying && anim->name == "SmallIdle" && !anim->isLooping;
|
||||
if (!anim || (!npc.sprite.animState.isPlaying && !isIdleDone)) npc_anim_restart(npc.sprite, "SmallIdle");
|
||||
npc.pos = npc.targetPosition;
|
||||
npc.AddEntityFlags(FLAG_NO_PHYSICS_KNOCKBACK);
|
||||
}
|
||||
|
||||
// Waiting: once Satan is the last enemy he takes his full health, rises with his own music and joins the fight.
|
||||
static void awakening_update(Entity_NPC& npc, int ticks, int gridIndex)
|
||||
{
|
||||
Room& room = *g_game->room;
|
||||
if (gridIndex >= 0) room.gridPaths[gridIndex] = STATUE_PATH_AWAKE;
|
||||
if (room.GetAliveEnemiesCount() == 1)
|
||||
{
|
||||
for (; ticks > 0; ticks--)
|
||||
{
|
||||
if (++npc.stateFrame != RISE_FRAME) continue;
|
||||
room.entityList.bossMaxHealth = 0;
|
||||
npc.maxHitPoints = npc.config->baseHP;
|
||||
npc.health = npc.maxHitPoints;
|
||||
npc_sound_play(SOUND_SATAN_RISE_UP, 1, 2, champion_pitch_get(npc));
|
||||
npc_anim_restart(npc.sprite, "Change");
|
||||
npc.shadowSize = npc.config->shadowSize;
|
||||
g_manager->musicManager.Crossfade(MUSIC_SATAN_BOSS, BOSS_MUSIC_FADE);
|
||||
}
|
||||
if (npc.sprite.IsEventTriggered("Shoot")) npc.PlaySound(SOUND_SATAN_BLAST, 1, 2, false, 1);
|
||||
if (npc.stateFrame > RISE_FRAME && npc_anim_is_done(npc))
|
||||
{
|
||||
npc.i1++;
|
||||
npc.state = NPC_STATE_MOVE;
|
||||
npc.stateFrame = 0;
|
||||
if (gridIndex >= 0) room.gridPaths[gridIndex] = 0;
|
||||
npc.ClearEntityFlags(FLAG_NO_PHYSICS_KNOCKBACK);
|
||||
}
|
||||
}
|
||||
npc.pos = npc.targetPosition;
|
||||
}
|
||||
|
||||
// Picks a shot attack: a spread three times in ten, else the fans.
|
||||
static const char* shot_attack_pick(Entity_NPC& npc)
|
||||
{
|
||||
npc.stateFrame = 0;
|
||||
bool isSpread = Random() % SPREAD_ODDS < SPREAD_IN_TEN;
|
||||
npc.state = isSpread ? SATAN_SPREAD : SATAN_FANS;
|
||||
npc.i2 = npc.state;
|
||||
return isSpread ? "Attack01" : "Attack03";
|
||||
}
|
||||
|
||||
// Walking after the target, and choosing the next attack: the beam when it crosses beneath, now and then a shot attack
|
||||
// (never twice running), else the sweep when it is near enough to the side, else closing in.
|
||||
static void walk_update(Entity_NPC& npc, Entity& target)
|
||||
{
|
||||
npc.sprite.Play("Walk");
|
||||
float aimY = std::max(target.pos.y * WALK_TARGET_SCALE, WALK_TARGET_MIN);
|
||||
float leadX = target.velocity.x * 2 * WALK_LEAD_FRAMES + target.pos.x - npc.pos.x;
|
||||
float dx = target.pos.x - npc.pos.x;
|
||||
float dy = aimY - npc.pos.y - WALK_TARGET_RISE;
|
||||
const char* anim = nullptr;
|
||||
|
||||
bool isBeam =
|
||||
(leadX * dx < 0 && dy > BEAM_REACH_UP && (npc.i2 != SATAN_BEAM || Random() % BEAM_REPEAT_ODDS == 0)) ||
|
||||
(npc.i2 == SATAN_SWEEP && std::abs(dx) < SWEEP_REPEAT_REACH && Random() % SWEEP_REPEAT_ODDS == 0);
|
||||
if (isBeam)
|
||||
{
|
||||
npc.PlaySound(SOUND_SATAN_CHARGE_UP, 1, 2, false, 1);
|
||||
npc.stateFrame = 0;
|
||||
npc.state = SATAN_BEAM;
|
||||
npc.i2 = SATAN_BEAM;
|
||||
anim = "Attack02";
|
||||
}
|
||||
else if (Random() % SHOT_ODDS == 0) anim = shot_attack_pick(npc);
|
||||
else if (Random() % ATTACK_ODDS == 0 && npc.i2 != SATAN_SPREAD && npc.i2 != SATAN_FANS) anim = shot_attack_pick(npc);
|
||||
else if (std::abs(dx) > WALK_ONLY_REACH || dy < 0)
|
||||
npc_push(npc, vector_make(std::clamp(dx, -WALK_STEP_X, WALK_STEP_X) * WALK_ACCEL,
|
||||
std::clamp(dy, -WALK_STEP_Y, WALK_STEP_Y) * WALK_ACCEL));
|
||||
else if (std::abs(dx) > SWEEP_REACH_MIN && std::abs(leadX) < SWEEP_LEAD_MAX)
|
||||
{
|
||||
npc.PlaySound(SOUND_SATAN_CHARGE_UP, 1, 2, false, 1);
|
||||
npc.stateFrame = 0;
|
||||
npc.state = SATAN_SWEEP;
|
||||
npc.i2 = SATAN_SWEEP;
|
||||
anim = "Attack03";
|
||||
}
|
||||
if (anim) npc_anim_restart(npc.sprite, anim);
|
||||
|
||||
Vector next = g_game->room->GetClampedPositionImpl(vector_add(npc.pos, npc.velocity), 0, SIDE_MARGIN, 0,
|
||||
SIDE_MARGIN);
|
||||
npc.velocity = vector_sub(next, npc.pos);
|
||||
}
|
||||
|
||||
// The spread: shots at the target's lead on Shoot and Shoot2, repeated from frame 10 while it stays near.
|
||||
static void spread_update(Entity_NPC& npc, Entity& target)
|
||||
{
|
||||
Vector lead = vector_make(target.velocity.x * 2 * SPREAD_LEAD_FRAMES + target.pos.x - npc.pos.x,
|
||||
target.velocity.y * 2 * SPREAD_LEAD_FRAMES + target.pos.y - npc.pos.y);
|
||||
if (npc_anim_is_done(npc))
|
||||
{
|
||||
if (vector_length(lead) >= SPREAD_FAR || Random() % ATTACK_ODDS == 0) npc.state = NPC_STATE_MOVE;
|
||||
else
|
||||
{
|
||||
npc_anim_restart(npc.sprite, "Attack01");
|
||||
if (npc.sprite.animState.animData) npc.sprite.animState.SetFrameFloat(SPREAD_REPEAT_FRAME);
|
||||
}
|
||||
}
|
||||
|
||||
bool isShoot2 = npc.sprite.IsEventTriggered("Shoot2");
|
||||
if (!npc.sprite.IsEventTriggered("Shoot") && !isShoot2) return;
|
||||
|
||||
ProjectileParams params;
|
||||
params.scale = SPREAD_SCALE;
|
||||
params.spread = SPREAD_SPREAD;
|
||||
params.fallingAccelModifier = SPREAD_FALL_ACCEL;
|
||||
npc.PlaySound(SOUND_SATAN_SPIT, 1, 2, false, 1);
|
||||
if (!isShoot2)
|
||||
{
|
||||
params.heightModifier = SPREAD_HEIGHT;
|
||||
params.fallingSpeedModifier = SPREAD_FALL_SPEED;
|
||||
}
|
||||
float speed = (vector_length(lead) <= SPREAD_FAR ? SPREAD_SPEED : SPREAD_SPEED_FAR) * SPREAD_SPEED_SCALE;
|
||||
npc.FireProjectiles(npc.pos, vector_resized(lead, speed), isShoot2 ? PROJECTILES_FOUR : PROJECTILES_FIVE, params);
|
||||
}
|
||||
|
||||
// Satan shakes from side to side between an attack's Shoot and Shoot2, on frames he updates.
|
||||
static void attack_shake(Entity_NPC& npc, int ticks, float shake)
|
||||
{
|
||||
if (!npc.sprite.WasEventTriggered("Shoot") || npc.sprite.WasEventTriggered("Shoot2") || ticks <= 0) return;
|
||||
npc.pos.x += (int)npc.updateTime % 2 == 1 ? shake : -shake;
|
||||
}
|
||||
|
||||
// A brimstone beam of Satan's from a spot, at an angle, drawn over the room.
|
||||
static Entity_Laser* beam_fire(Entity_NPC& npc, Vector from, float angle, int timeout)
|
||||
{
|
||||
Entity_Laser* laser = Entity_Laser::ShootAngle(
|
||||
{.position = from, .source = &npc, .angleDegrees = angle, .timeout = timeout, .variant = LASER_THICK_RED});
|
||||
laser->renderDepthOffset = SATAN_BEAM_DEPTH;
|
||||
return laser;
|
||||
}
|
||||
|
||||
// The beam straight down from his mouth.
|
||||
static void beam_update(Entity_NPC& npc, int ticks)
|
||||
{
|
||||
if (npc.sprite.IsEventTriggered("Shoot"))
|
||||
{
|
||||
Entity_Laser* laser = beam_fire(npc, vector_make(npc.pos.x, npc.pos.y - SATAN_BEAM_RISE), BEAM_ANGLE, SATAN_BEAM_TIMEOUT);
|
||||
laser->scale = BEAM_SCALE;
|
||||
laser->ResetSpriteScale();
|
||||
laser->Update();
|
||||
npc.pos.x -= BEAM_RECOIL;
|
||||
}
|
||||
attack_shake(npc, ticks, BEAM_SHAKE);
|
||||
}
|
||||
|
||||
// The two sweeping beams, 100 to each side, turning toward each other.
|
||||
static void sweep_update(Entity_NPC& npc, int ticks)
|
||||
{
|
||||
if (!npc.sprite.IsEventTriggered("Shoot")) return attack_shake(npc, ticks, SWEEP_SHAKE);
|
||||
|
||||
for (int side = -1; side <= 1; side += 2)
|
||||
{
|
||||
float angle = side < 0 ? SWEEP_ANGLE_LEFT : SWEEP_ANGLE_RIGHT;
|
||||
Vector from = vector_make(npc.pos.x + side * SWEEP_REACH, npc.pos.y - SATAN_BEAM_RISE);
|
||||
Entity_Laser* laser = beam_fire(npc, from, angle, SATAN_SWEEP_TIMEOUT);
|
||||
laser->rotationDegrees = side * SWEEP_ROTATION;
|
||||
laser->isActiveRotating = true;
|
||||
laser->rotationDelay = 0;
|
||||
laser->rotationSpd = side * SATAN_SWEEP_SPEED;
|
||||
laser->Update();
|
||||
npc.pos.x -= SWEEP_RECOIL;
|
||||
}
|
||||
}
|
||||
|
||||
// The two fans of shots, 100 to each side, each kept to its own side.
|
||||
static void fans_update(Entity_NPC& npc, int ticks)
|
||||
{
|
||||
if (!npc.sprite.IsEventTriggered("Shoot")) return attack_shake(npc, ticks, SWEEP_SHAKE);
|
||||
|
||||
npc.PlaySound(SOUND_SATAN_SPIT, 1, 2, false, 1);
|
||||
for (int side = -1; side <= 1; side += 2)
|
||||
{
|
||||
ProjectileParams params;
|
||||
params.fireDirectionLimit = vector_make((float)side, 0);
|
||||
params.scale = SPREAD_SCALE;
|
||||
params.heightModifier = FAN_HEIGHT;
|
||||
params.fallingSpeedModifier = FAN_FALL_SPEED;
|
||||
params.dotProductLimit = FAN_DOT_LIMIT;
|
||||
npc.FireProjectiles(vector_make(npc.pos.x + side * FAN_REACH, npc.pos.y), FAN_VELOCITY, PROJECTILES_RING,
|
||||
params);
|
||||
npc.pos.x -= SWEEP_RECOIL;
|
||||
}
|
||||
}
|
||||
|
||||
// The fight: solid and kept low in the room, he walks and attacks, walking again when an attack's animation ends.
|
||||
static void fight_update(Entity_NPC& npc, int ticks)
|
||||
{
|
||||
npc.renderZOffset = 0;
|
||||
npc.entityCollisionClass = ENTCOLL_ALL;
|
||||
npc.entityGridCollisionClass = GRIDCOLL_WALLS_X;
|
||||
npc.pos.y = std::max(npc.pos.y, FIGHT_TOP);
|
||||
Entity& target = *npc.GetPlayerTarget();
|
||||
|
||||
switch (npc.state)
|
||||
{
|
||||
case NPC_STATE_MOVE: return walk_update(npc, target);
|
||||
case SATAN_SPREAD: return spread_update(npc, target);
|
||||
case SATAN_BEAM: beam_update(npc, ticks); break;
|
||||
case SATAN_SWEEP: sweep_update(npc, ticks); break;
|
||||
case SATAN_FANS: fans_update(npc, ticks); break;
|
||||
default: return;
|
||||
}
|
||||
if (npc_anim_is_done(npc)) npc.state = NPC_STATE_MOVE;
|
||||
}
|
||||
|
||||
// His death: he bleeds and bursts as it plays, then leaves two feet tied to each other and is gone.
|
||||
static void dying_update(Entity_NPC& npc)
|
||||
{
|
||||
npc.stateFrame++;
|
||||
npc.entityCollisionClass = ENTCOLL_NONE;
|
||||
npc.isInvincible = true;
|
||||
ANM2& sprite = npc.sprite;
|
||||
if (sprite.animState.animData)
|
||||
if (const NullFrame* guide = sprite.animState.GetNullFrame("BloodGuide")) npc.update_blood_guide_gibs(*guide);
|
||||
|
||||
if (sprite.animState.animData)
|
||||
{
|
||||
if (sprite.IsEventTriggered("Sound")) npc.PlaySound(SOUND_SATAN_GROW, 1, 2, false, 1);
|
||||
if (sprite.IsEventTriggered("Shoot"))
|
||||
{
|
||||
npc.MakeGroundPoof(npc.pos, DEATH_DUST_COLOR, 1);
|
||||
game_shake_screen(DEATH_SHAKE);
|
||||
}
|
||||
if (sprite.IsEventTriggered("Shoot2"))
|
||||
for (const Vector& spot : DEATH_BURSTS)
|
||||
{
|
||||
float angle = random_unit() * RANDOM_HALF_TURN * 2;
|
||||
uint32_t seed = Random();
|
||||
Vector position = vector_make(std::cos(angle) * DEATH_BURST_REACH + spot.x + npc.pos.x,
|
||||
std::sin(angle) * DEATH_BURST_REACH + spot.y + npc.pos.y);
|
||||
Entity* burst = g_game->Spawn({.position = position, .spawner = &npc, .subType = DEATH_BURST_SIZE,
|
||||
.type = ENTITY_EFFECT, .variant = EFFECT_POOF02, .seed = seed});
|
||||
burst->SetColor(DEATH_BURST_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true);
|
||||
burst->sprite.isFlipX = (Random() & 1) == 0;
|
||||
burst->Update();
|
||||
}
|
||||
if (!npc_anim_is_done(npc)) return;
|
||||
}
|
||||
|
||||
auto spawnFoot = [&] {
|
||||
return static_cast<Entity_NPC*>(g_game->Spawn({.spawner = &npc, .type = npc.type,
|
||||
.variant = npc.variant + SATAN_FEET_VARIANT,
|
||||
.seed = Random()}));
|
||||
};
|
||||
Entity_NPC* first = spawnFoot();
|
||||
Entity_NPC* second = spawnFoot();
|
||||
second->parent = first;
|
||||
first->child = second;
|
||||
second->state = NPC_STATE_INIT;
|
||||
first->state = NPC_STATE_INIT;
|
||||
first->Update();
|
||||
second->Update();
|
||||
npc.Remove();
|
||||
}
|
||||
|
||||
// Moves a foot to 111 from another that stands nearer.
|
||||
static void foot_space(Entity_NPC& foot, Entity_NPC& other)
|
||||
{
|
||||
Vector away = vector_sub(other.pos, foot.pos);
|
||||
float distance = vector_length(away);
|
||||
if (distance >= FEET_SPACING || distance <= 0) return;
|
||||
foot.pos = vector_sub(foot.pos, vector_scale(away, (FEET_SPACING - distance) / distance));
|
||||
}
|
||||
|
||||
// A hidden foot comes down on its target now and then, calling a leech when few enemies are left.
|
||||
static void foot_rest(Entity_NPC& npc)
|
||||
{
|
||||
npc.isVisible = false;
|
||||
npc.entityCollisionClass = ENTCOLL_NONE;
|
||||
npc.entityGridCollisionClass = GRIDCOLL_GROUND;
|
||||
if (Random() % SATAN_STOMP_ODDS != 0) return;
|
||||
if (npc.parent && npc.stateFrame != 0 && npc.ParentNPC()->stateFrame < STOMP_SETTLE_FRAMES) return;
|
||||
if (npc.child && npc.ChildNPC()->stateFrame < STOMP_SETTLE_FRAMES) return;
|
||||
|
||||
npc.state = NPC_STATE_STOMP;
|
||||
npc.stateFrame = 0;
|
||||
npc_anim_restart(npc.sprite, "Stomp");
|
||||
npc.isVisible = true;
|
||||
Entity& target = *npc.GetPlayerTarget();
|
||||
npc.pos = target.pos;
|
||||
if (npc.parent) foot_space(npc, *npc.ParentNPC());
|
||||
if (npc.child) foot_space(npc, *npc.ChildNPC());
|
||||
if (g_game->room->GetAliveEnemiesCount() >= STOMP_LEECH_CROWD || (Random() & 1) != 0) return;
|
||||
|
||||
Vector spot = room_free_pickup_position_find(
|
||||
{.position = target.pos, .step = STOMP_LEECH_REACH, .isAvoidActiveEntities = true});
|
||||
g_game->Spawn({.position = spot, .spawner = &npc, .type = ENTITY_LEECH, .variant = KAMIKAZE_LEECH, .seed = Random()});
|
||||
}
|
||||
|
||||
// A stomp: solid from the landing until it lifts, crushing and rippling where it lands. The feet share the lower
|
||||
// health, and one's death ends the other and hurts every enemy left.
|
||||
static void foot_update(Entity_NPC& npc)
|
||||
{
|
||||
if (npc.state == NPC_STATE_IDLE) return foot_rest(npc);
|
||||
|
||||
if (npc.state == NPC_STATE_STOMP)
|
||||
{
|
||||
npc.stateFrame++;
|
||||
bool isDown = npc.sprite.WasEventTriggered("Stomp") && !npc.sprite.WasEventTriggered("Lift");
|
||||
npc.entityCollisionClass = isDown ? ENTCOLL_ALL : ENTCOLL_NONE;
|
||||
if (npc.sprite.IsEventTriggered("Stomp"))
|
||||
{
|
||||
npc.PlaySound(SOUND_HELLBOSS_GROUNDPOUND, 1, 2, false, 1);
|
||||
explosion_damage({.position = npc.pos, .source = &npc, .damageFlags = DAMAGE_CRUSH,
|
||||
.damage = SATAN_STOMP_DAMAGE, .radius = SATAN_STOMP_RADIUS, .isLineCheck = false});
|
||||
shockwave_make(npc.pos, SATAN_STOMP_RIPPLE_AMPLITUDE, SATAN_STOMP_RIPPLE_SPEED, SATAN_STOMP_RIPPLE_FRAMES);
|
||||
npc.MakeGroundPoofAtSelf(SATAN_STOMP_DUST_COLOR, 1);
|
||||
}
|
||||
if (npc_anim_is_done(npc))
|
||||
{
|
||||
npc.isVisible = false;
|
||||
npc.state = NPC_STATE_IDLE;
|
||||
}
|
||||
}
|
||||
if (npc.parent)
|
||||
{
|
||||
Entity_NPC& other = *npc.ParentNPC();
|
||||
float health = std::min(npc.health, other.health);
|
||||
other.health = health;
|
||||
npc.health = health;
|
||||
}
|
||||
if (!npc.isDead) return;
|
||||
|
||||
if (npc.child) npc.child->Kill(EntityRef());
|
||||
if (npc.parent) npc.parent->Kill(EntityRef());
|
||||
for (Entity* entity : std::vector<Entity*>(g_game->room->entityList.updateEL))
|
||||
if (entity->CanShutDoors()) entity->TakeDamage(FEET_DEATH_DAMAGE, 0, EntityRef(), FEET_DEATH_COUNTDOWN);
|
||||
}
|
||||
|
||||
// 0047f640 Satan (84) and his feet (84.10): the statue that wakes to call the Fallen, the fight once it falls, his
|
||||
// death, and the feet stomping until they die.
|
||||
void boss_satan_update(Entity_NPC& npc)
|
||||
{
|
||||
stray_blasts_ignore(npc);
|
||||
if (npc.i1 == SATAN_FIGHT && npc.health - npc.pendingDamage < 0) death_start(npc);
|
||||
if (npc.state == NPC_STATE_INIT) return satan_init(npc);
|
||||
|
||||
npc.friction *= SATAN_FRICTION;
|
||||
int ticks = npc_ticks_get(npc);
|
||||
int gridIndex = g_game->room->GetGridIndex(vector_add(npc.pos, npc.posOffset));
|
||||
switch (npc.i1)
|
||||
{
|
||||
case SATAN_STATUE: return statue_update(npc, ticks, gridIndex);
|
||||
case SATAN_AWAKENING: return awakening_update(npc, ticks, gridIndex);
|
||||
case SATAN_FIGHT: return fight_update(npc, ticks);
|
||||
case SATAN_DYING: return dying_update(npc);
|
||||
case SATAN_FEET: return foot_update(npc);
|
||||
}
|
||||
}
|
||||
+19
-8
@@ -325,22 +325,33 @@ void Cutscene::VideoPart::Start()
|
||||
{
|
||||
subtitleFrame = 0;
|
||||
subtitleIndex = 0;
|
||||
player->play((uint8_t*)file.c_str(), music_volume_get() * VIDEO_VOLUME_SCALE);
|
||||
player->play(file, music_volume_get() * VIDEO_VOLUME_SCALE);
|
||||
if (!isKeepMusic) g_manager->musicManager.Fadeout(MUSIC_FADE_RATE);
|
||||
startTime = time_ms();
|
||||
}
|
||||
|
||||
void Cutscene::VideoPart::Update() { reconstruction_missing("Cutscene::VideoPart::Update 0095fbd0 (video clip)"); }
|
||||
void Cutscene::VideoPart::Render(Vector)
|
||||
// 0095fbd0 Moves the subtitles on to the part's frame (30 a second) every other frame. The clip plays itself.
|
||||
void Cutscene::VideoPart::Update()
|
||||
{
|
||||
reconstruction_missing("Cutscene::VideoPart::Render 0095fcd0 (video clip)");
|
||||
if (g_manager->framecount & 1) return;
|
||||
subtitles_advance((uint32_t)((time_ms() - startTime) * FRAMES_PER_SECOND / MS_PER_SECOND));
|
||||
}
|
||||
bool Cutscene::VideoPart::IsFinished()
|
||||
|
||||
// 0095fcd0 Draws the clip blended normally at the offset, then the subtitles.
|
||||
void Cutscene::VideoPart::Render(Vector offset)
|
||||
{
|
||||
reconstruction_missing("Cutscene::VideoPart::IsFinished 0095fd40 (video clip)");
|
||||
KAGE::Graphics::manager.blend_set(KAGE::Graphics::BLEND_NORMAL);
|
||||
player->render(offset);
|
||||
render_subtitles();
|
||||
}
|
||||
int Cutscene::VideoPart::GetWidth() { reconstruction_missing("Cutscene::VideoPart::GetWidth 0095c930 (video clip)"); }
|
||||
int Cutscene::VideoPart::GetHeight() { reconstruction_missing("Cutscene::VideoPart::GetHeight 0095c960 (video clip)"); }
|
||||
|
||||
// 0095fd40 Whether the clip played to its end, or none opened.
|
||||
bool Cutscene::VideoPart::IsFinished() { return player->is_finished(); }
|
||||
|
||||
// (0095c930, 0095c960) The canvas the clip is drawn for. With no clip open the original gives 0 by 0, which zeroes the
|
||||
// screen scale for the frame the part shows, so the default canvas stands in.
|
||||
int Cutscene::VideoPart::GetWidth() { return CANVAS_DEFAULT.width; }
|
||||
int Cutscene::VideoPart::GetHeight() { return CANVAS_DEFAULT.height; }
|
||||
|
||||
// 0095fd70 Loads the title and body fonts, as mods may replace them.
|
||||
void Cutscene::TemporaryPart::Load()
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "anm2.h"
|
||||
#include "font.h"
|
||||
#include "platform.h"
|
||||
#include "video_player.h"
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
+3
-1
@@ -16,12 +16,14 @@ constexpr std::string_view PARENT_FOLDER = "../";
|
||||
std::string dataDirectory = "resources/";
|
||||
std::string languageDirectory;
|
||||
|
||||
// A game path lowercased with forward slashes, as the game normalizes every path before a lookup.
|
||||
// A game path lowercased with forward slashes, as the game normalizes every path before a lookup. A path already under
|
||||
// the resources, which mods build from their script's path as the original's absolute ones, stays there.
|
||||
static std::string path_normalize(std::string_view path)
|
||||
{
|
||||
std::string normalized(path);
|
||||
for (char& letter : normalized) letter = letter == '\\' ? '/' : (char)std::tolower((unsigned char)letter);
|
||||
if (normalized.starts_with(MODS_FROM_RESOURCES)) normalized.erase(0, PARENT_FOLDER.size());
|
||||
else if (normalized.starts_with(dataDirectory)) normalized.erase(0, dataDirectory.size());
|
||||
return normalized;
|
||||
}
|
||||
|
||||
|
||||
+22
-3
@@ -1,5 +1,6 @@
|
||||
#include "entity.h"
|
||||
#include "entity_effect.h"
|
||||
#include "entity_familiar.h"
|
||||
#include "entity_list.h"
|
||||
#include "entity_npc.h"
|
||||
#include "entity_player.h"
|
||||
@@ -9,6 +10,7 @@
|
||||
#include "lua_engine.h"
|
||||
#include "manager.h"
|
||||
#include "room.h"
|
||||
#include "room_grid.h"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdarg>
|
||||
@@ -485,6 +487,14 @@ void Entity::CopyStatusEffects()
|
||||
}
|
||||
}
|
||||
|
||||
// Sorted insertion into a hit list, as the entities keep them.
|
||||
void hit_list_insert(std::vector<uint32_t>& hitList, Entity& entity)
|
||||
{
|
||||
uint32_t index = entity.GetHitListIndex();
|
||||
auto at = std::lower_bound(hitList.begin(), hitList.end(), index);
|
||||
if (at == hitList.end() || *at != index) hitList.insert(at, index);
|
||||
}
|
||||
|
||||
// 006b62b0 The index hits on it are recorded under: its body's for segmented bosses that share them.
|
||||
uint32_t Entity::GetHitListIndex()
|
||||
{
|
||||
@@ -592,10 +602,19 @@ bool Entity::CanDevolve()
|
||||
return config && !config->devolve.empty();
|
||||
}
|
||||
|
||||
// 006b9740
|
||||
bool Entity::IsPlayerInRadius(const Vector&, float)
|
||||
// 006b9740 Whether a player (or Isaac's Heart) is within radius of a position. A friendly entity never sees one.
|
||||
bool Entity::IsPlayerInRadius(const Vector& center, float radius)
|
||||
{
|
||||
reconstruction_missing("Entity::IsPlayerInRadius 006b9740");
|
||||
if (IsFriendly() || radius <= 0) return false;
|
||||
|
||||
for (Entity_Player* player : g_game->playerManager.playerList)
|
||||
{
|
||||
Vector delta = vector_make(center.x - player->pos.x, center.y - player->pos.y);
|
||||
if (delta.x * delta.x + delta.y * delta.y < radius * radius) return true;
|
||||
}
|
||||
for (Entity* entity : entity_query_radius(center, radius, QUERY_FAMILIARS))
|
||||
if (entity->type == ENTITY_FAMILIAR && entity->variant == Entity_Familiar::ISAACS_HEART) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// 007e9130 The boss id its config gives, 0 without one.
|
||||
|
||||
@@ -36,6 +36,7 @@ enum EntityType : int
|
||||
ENTITY_GLOBIN = 24,
|
||||
ENTITY_BOOMFLY = 25,
|
||||
ENTITY_MAW = 26,
|
||||
ENTITY_HOST = 27,
|
||||
ENTITY_CHUB = 28,
|
||||
ENTITY_HOPPER = 29,
|
||||
ENTITY_BOIL = 30,
|
||||
@@ -52,13 +53,20 @@ enum EntityType : int
|
||||
ENTITY_STONEHEAD = 42,
|
||||
ENTITY_POKY = 44,
|
||||
ENTITY_MOM = 45,
|
||||
ENTITY_SLOTH = 46,
|
||||
ENTITY_LUST = 47,
|
||||
ENTITY_WRATH = 48,
|
||||
ENTITY_GLUTTONY = 49,
|
||||
ENTITY_GREED = 50,
|
||||
ENTITY_ENVY = 51,
|
||||
ENTITY_PRIDE = 52,
|
||||
ENTITY_FLAMING_HOPPER = 54,
|
||||
ENTITY_LEECH = 55,
|
||||
ENTITY_LUMP = 56,
|
||||
ENTITY_MEMBRAIN = 57,
|
||||
ENTITY_PARA_BITE = 58,
|
||||
ENTITY_FRED = 59,
|
||||
ENTITY_EYE = 60,
|
||||
ENTITY_SUCKER = 61,
|
||||
ENTITY_PIN = 62,
|
||||
ENTITY_FAMINE = 63,
|
||||
@@ -72,8 +80,10 @@ enum EntityType : int
|
||||
ENTITY_MOMS_HEART = 78,
|
||||
ENTITY_GEMINI = 79,
|
||||
ENTITY_MOTER = 80,
|
||||
ENTITY_FALLEN = 81,
|
||||
ENTITY_SATAN = 84,
|
||||
ENTITY_SPIDER = 85,
|
||||
ENTITY_KEEPER = 86,
|
||||
ENTITY_BUTTLICKER = 89,
|
||||
ENTITY_HANGER = 90,
|
||||
ENTITY_HEART = 92,
|
||||
@@ -84,6 +94,7 @@ enum EntityType : int
|
||||
ENTITY_HEART_OF_INFAMY = 98,
|
||||
ENTITY_GURDY_JR = 99,
|
||||
ENTITY_WIDOW = 100,
|
||||
ENTITY_DADDYLONGLEGS = 101,
|
||||
ENTITY_ISAAC_BOSS = 102,
|
||||
ENTITY_BRIMSTONE_HEAD = 203,
|
||||
ENTITY_BABY_LONG_LEGS = 206,
|
||||
@@ -106,6 +117,9 @@ enum EntityType : int
|
||||
ENTITY_GURGLING = 237,
|
||||
ENTITY_SPLASHER = 238,
|
||||
ENTITY_GRUB = 239,
|
||||
ENTITY_WALL_CREEP = 240,
|
||||
ENTITY_RAGE_CREEP = 241,
|
||||
ENTITY_BLIND_CREEP = 242,
|
||||
ENTITY_CONJOINED_SPITTY = 243,
|
||||
ENTITY_ROUND_WORM = 244,
|
||||
ENTITY_POOP = 245,
|
||||
@@ -118,6 +132,7 @@ enum EntityType : int
|
||||
ENTITY_POLYCEPHALUS = 269,
|
||||
ENTITY_URIEL = 271,
|
||||
ENTITY_GABRIEL = 272,
|
||||
ENTITY_THE_LAMB = 273,
|
||||
ENTITY_MEGA_SATAN = 274,
|
||||
ENTITY_ROUNDY = 276,
|
||||
ENTITY_BLACK_BONY = 277,
|
||||
@@ -126,6 +141,7 @@ enum EntityType : int
|
||||
ENTITY_BLACK_GLOBIN_BODY = 280,
|
||||
ENTITY_FLESH_DEATHS_HEAD = 286,
|
||||
ENTITY_ULCER = 289,
|
||||
ENTITY_MEATBALL = 290,
|
||||
ENTITY_PITFALL = 291,
|
||||
ENTITY_MOVABLE_TNT = 292,
|
||||
ENTITY_CORN_MINE = 295,
|
||||
@@ -134,27 +150,43 @@ enum EntityType : int
|
||||
ENTITY_POISON_MIND = 301,
|
||||
ENTITY_STONEY = 302,
|
||||
ENTITY_BLISTER = 303,
|
||||
ENTITY_THE_THING = 304,
|
||||
ENTITY_PORTAL = 306,
|
||||
ENTITY_STAIN = 401,
|
||||
ENTITY_BROWNIE = 402,
|
||||
ENTITY_LITTLE_HORN = 404,
|
||||
ENTITY_RAG_MAN = 405,
|
||||
ENTITY_ULTRA_GREED = 406,
|
||||
ENTITY_HUSH = 407,
|
||||
ENTITY_RAG_MEGA = 409,
|
||||
ENTITY_SISTERS_VIS = 410,
|
||||
ENTITY_BIG_HORN = 411,
|
||||
ENTITY_DELIRIUM = 412,
|
||||
ENTITY_MATRIARCH = 413,
|
||||
ENTITY_BLOOD_PUPPY = 802,
|
||||
ENTITY_BISHOP = 805,
|
||||
ENTITY_WRAITH = 807,
|
||||
ENTITY_WILLO = 808,
|
||||
ENTITY_BOMB_GRIMACE = 809,
|
||||
ENTITY_SMALL_LEECH = 810,
|
||||
ENTITY_DEEP_GAPER = 811,
|
||||
ENTITY_BLURB = 813,
|
||||
ENTITY_STRIDER = 814,
|
||||
ENTITY_FISSURE = 815,
|
||||
ENTITY_POLTY = 816,
|
||||
ENTITY_ROCK_SPIDER = 818,
|
||||
ENTITY_FLY_BOMB = 819,
|
||||
ENTITY_BLASTER = 821,
|
||||
ENTITY_QUAKEY = 823,
|
||||
ENTITY_GYRO = 824,
|
||||
ENTITY_HARDY = 826,
|
||||
ENTITY_BIG_BONY = 830,
|
||||
ENTITY_GUTTED_FATTY = 831,
|
||||
ENTITY_PEEPER_FATTY = 835,
|
||||
ENTITY_SMALL_MAGGOT = 853,
|
||||
ENTITY_PUSTULE = 861,
|
||||
ENTITY_CYST = 862,
|
||||
ENTITY_EVIS = 865,
|
||||
ENTITY_DARK_ESAU = 866,
|
||||
ENTITY_DRIP = 870,
|
||||
ENTITY_SPLURT = 871,
|
||||
@@ -162,7 +194,9 @@ enum EntityType : int
|
||||
ENTITY_GRUDGE = 877,
|
||||
ENTITY_NEEDLE = 881,
|
||||
ENTITY_CULTIST = 885,
|
||||
ENTITY_VIS_FATTY = 886,
|
||||
ENTITY_BALL_AND_CHAIN = 893,
|
||||
ENTITY_REAP_CREEP = 900,
|
||||
ENTITY_VISAGE = 903,
|
||||
ENTITY_HERETIC = 905,
|
||||
ENTITY_HORNFEL = 906,
|
||||
@@ -178,6 +212,8 @@ enum EntityType : int
|
||||
ENTITY_COLOSTOMIA = 917,
|
||||
ENTITY_TURDLET = 918,
|
||||
ENTITY_RAGLICH = 919,
|
||||
ENTITY_HORNY_BOYS = 920,
|
||||
ENTITY_CLUTCH = 921,
|
||||
ENTITY_DOGMA = 950,
|
||||
ENTITY_BEAST = 951,
|
||||
ENTITY_GENERIC_PROP = 960,
|
||||
@@ -298,6 +334,8 @@ enum DamageFlag : uint64_t
|
||||
DAMAGE_SPAWN_RED_HEART = 1ull << 26,
|
||||
DAMAGE_SPAWN_COIN = 1ull << 27,
|
||||
DAMAGE_NO_PENALTIES = 1ull << 28,
|
||||
DAMAGE_CLONES = 1ull << 29,
|
||||
DAMAGE_SPAWN_TEMP_HEART = 1ull << 29,
|
||||
DAMAGE_IGNORE_ARMOR = 1ull << 30,
|
||||
DAMAGE_SPAWN_CARD = 1ull << 31,
|
||||
DAMAGE_SPAWN_RUNE = 1ull << 32,
|
||||
@@ -743,5 +781,6 @@ private:
|
||||
void magnet_pull_update();
|
||||
};
|
||||
|
||||
void hit_list_insert(std::vector<uint32_t>& hitList, Entity& entity);
|
||||
Vector render_position_get(const Vector& world, RenderSnap snap);
|
||||
int render_z_get(float depth);
|
||||
@@ -104,6 +104,7 @@ private:
|
||||
};
|
||||
|
||||
void explosion_damage(Explosion explosion);
|
||||
bool explosion_line_clear(const Vector& start, const Vector& end, bool isIgnoreWalls);
|
||||
void explosion_effects(const Explosion& explosion);
|
||||
void explosion_tear_flag_effects(const Explosion& explosion);
|
||||
Entity* bomb_crater_spawn(const Vector& position, Entity* spawner, float scale);
|
||||
@@ -17,7 +17,6 @@
|
||||
// What crushes rocks on contact: The Nail, Leo (worn or rolled by Zodiac), Thunder Thighs, Stompy and Mega Mush.
|
||||
constexpr int COLLECTIBLE_LEO = 302;
|
||||
constexpr int COLLECTIBLE_THUNDER_THIGHS = 314;
|
||||
constexpr int PLAYERFORM_STOMPY = 13;
|
||||
// A transformation counts once the player holds this many of its items.
|
||||
constexpr int PLAYER_FORM_ITEMS = 3;
|
||||
|
||||
@@ -224,7 +223,7 @@ bool Entity_Player::CanCrushRocks()
|
||||
{
|
||||
return temporaryEffects.HasCollectibleEffect(COLLECTIBLE_THE_NAIL) || HasCollectible(COLLECTIBLE_LEO) ||
|
||||
temporaryEffects.HasCollectibleEffect(COLLECTIBLE_LEO) || GetZodiacEffect() == COLLECTIBLE_LEO ||
|
||||
HasCollectible(COLLECTIBLE_THUNDER_THIGHS) || HasPlayerForm(PLAYERFORM_STOMPY) ||
|
||||
HasCollectible(COLLECTIBLE_THUNDER_THIGHS) || HasPlayerForm(PLAYER_FORM_STOMPY) ||
|
||||
temporaryEffects.HasCollectibleEffect(COLLECTIBLE_MEGA_MUSH);
|
||||
}
|
||||
|
||||
|
||||
+2
-12
@@ -61,10 +61,8 @@ constexpr int STATIC_OBSTACLE_EXTRA = 202;
|
||||
|
||||
// The items, trinkets and player kinds the combat code reads (Lua's ids).
|
||||
constexpr int COLLECTIBLE_MOMS_HEELS = 30;
|
||||
constexpr int COLLECTIBLE_MULLIGAN = 151;
|
||||
constexpr int COLLECTIBLE_ARIES = 300;
|
||||
constexpr int NULLITEM_TOOTH_AND_NAIL = 59;
|
||||
constexpr int PLAYER_FORM_GUPPY = 0;
|
||||
constexpr int PLAYER_FORM_COUNT_NEEDED = 3;
|
||||
constexpr int BABY_CROW = 12;
|
||||
constexpr int BLUE_FLY_MAX = 30;
|
||||
@@ -193,14 +191,6 @@ constexpr KColor BLOOD_BASE_COLOR = kcolor_rgba(0.61960787f, 0.043137256f, 0.058
|
||||
constexpr ColorMod POISON_GIB_TINT = {{1, 1, 1, 1}, {0.3f, 1.6f, 0, 1}, {0, 0, 0}};
|
||||
constexpr ColorMod TOOTH_COLOR = {{0.54902f, 0.482353f, 0.482353f, 1}, {0, 0, 0, 0}, {0, 0, 0}};
|
||||
|
||||
// Sorted insertion into a hit list, as the entities keep them.
|
||||
static void hit_list_add(std::vector<uint32_t>& hitList, Entity& entity)
|
||||
{
|
||||
uint32_t index = entity.GetHitListIndex();
|
||||
auto at = std::lower_bound(hitList.begin(), hitList.end(), index);
|
||||
if (at == hitList.end() || *at != index) hitList.insert(at, index);
|
||||
}
|
||||
|
||||
// Spawns an effect with a seed drawn by the caller.
|
||||
static Entity_Effect* effect_spawn(int variant, int subType, Vector position, Vector velocity, Entity* spawner,
|
||||
uint32_t seed)
|
||||
@@ -803,7 +793,7 @@ static TearContact tear_contact_get(Entity_Tear& tear, Entity& collider, Entity*
|
||||
{
|
||||
if (!EntityList::HitListContains(tear.hitList, collider))
|
||||
{
|
||||
hit_list_add(tear.hitList, collider);
|
||||
hit_list_insert(tear.hitList, collider);
|
||||
tear_push(tear, collider, TEAR_DEFLECTOR_MASS_SCALE);
|
||||
}
|
||||
return TEAR_CONTACT_PASS;
|
||||
@@ -953,7 +943,7 @@ bool Entity_Tear::HandleCollision(Entity* collider, bool isLow)
|
||||
tearFlags[TEAR_BOUNCE] || tearFlags[TEAR_LUDOVICO] || tearFlags[TEAR_BOOGER_FLAG] ||
|
||||
tearFlags[TEAR_STICKY] || tearFlags[TEAR_SPORE_FLAG] || tearFlags[TEAR_FETUS_FLAG];
|
||||
if (EntityList::HitListContains(hitList, *collider) && isPassing) return true;
|
||||
hit_list_add(hitList, *collider);
|
||||
hit_list_insert(hitList, *collider);
|
||||
bool isSticking = tearFlags[TEAR_STICKY] || tearFlags[TEAR_BOOGER_FLAG] || tearFlags[TEAR_SPORE_FLAG];
|
||||
if (collider->IsActiveEnemy(DEAD_EXCLUDED) && isSticking)
|
||||
reconstruction_missing("Entity_Tear::HandleCollision 00673660: a sticky tear sticking to an enemy");
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "entity_effect.h"
|
||||
#include "entity_effect_combat.h"
|
||||
#include "entity_effect_trail.h"
|
||||
#include "entity_list.h"
|
||||
#include "entity_player.h"
|
||||
#include "entity_player_forgotten.h"
|
||||
@@ -98,6 +99,7 @@ static const EffectBehaviour* behaviour_find(int variant)
|
||||
std::array<EffectBehaviour, EFFECT_VARIANT_LIMIT> table{};
|
||||
for (auto group : {ambient_effect_behaviours(), hazard_effect_behaviours(), floor_effect_behaviours(),
|
||||
beam_effect_behaviours(), player_effect_behaviours(), mines_effect_behaviours(),
|
||||
trail_effect_behaviours(), spike_effect_behaviours(),
|
||||
std::span<const EffectBehaviour>(TIMER_BEHAVIOURS)})
|
||||
for (const EffectBehaviour& behaviour : group) table[behaviour.variant] = behaviour;
|
||||
return table;
|
||||
|
||||
+21
-3
@@ -50,8 +50,10 @@ enum EffectVariant : int
|
||||
EFFECT_BULLET_POOF = 11,
|
||||
EFFECT_TEAR_POOF_A = 12,
|
||||
EFFECT_TEAR_POOF_B = 13,
|
||||
EFFECT_RIPPLE_POOF = 14,
|
||||
EFFECT_POOF01 = 15,
|
||||
EFFECT_POOF02 = 16,
|
||||
EFFECT_CRACK_THE_SKY = 19,
|
||||
EFFECT_TINY_BUG = 21,
|
||||
EFFECT_CREEP_RED = 22,
|
||||
EFFECT_CREEP_GREEN = 23,
|
||||
@@ -59,18 +61,23 @@ enum EffectVariant : int
|
||||
EFFECT_CREEP_WHITE = 25,
|
||||
EFFECT_CREEP_BLACK = 26,
|
||||
EFFECT_WOOD_PARTICLE = 27,
|
||||
EFFECT_PLAYER_CREEP_LEMON_MISHAP = 32,
|
||||
EFFECT_TINY_FLY = 33,
|
||||
EFFECT_FART = 34,
|
||||
EFFECT_TOOTH_PARTICLE = 35,
|
||||
EFFECT_PLAYER_CREEP_HOLYWATER = 37,
|
||||
EFFECT_SPIDER_EXPLOSION = 38,
|
||||
EFFECT_HEAVEN_LIGHT_DOOR = 39,
|
||||
EFFECT_WATER_DROPLET = 41,
|
||||
EFFECT_POOP_EXPLOSION = 43,
|
||||
EFFECT_PLAYER_CREEP_WHITE = 44,
|
||||
EFFECT_PLAYER_CREEP_BLACK = 45,
|
||||
EFFECT_PLAYER_CREEP_RED = 46,
|
||||
EFFECT_HEART = 49,
|
||||
EFFECT_LASER_IMPACT = 50,
|
||||
EFFECT_HOT_BOMB_FIRE = 51,
|
||||
EFFECT_PLAYER_CREEP_GREEN = 53,
|
||||
EFFECT_PLAYER_CREEP_HOLYWATER_TRAIL = 54,
|
||||
EFFECT_SPIKE = 55,
|
||||
EFFECT_CREEP_BROWN = 56,
|
||||
EFFECT_PULLING_EFFECT = 57,
|
||||
@@ -90,10 +97,14 @@ enum EffectVariant : int
|
||||
EFFECT_SHOCKWAVE_RANDOM = 73,
|
||||
EFFECT_ISAACS_CARPET = 74,
|
||||
EFFECT_DICE_FLOOR = 76,
|
||||
EFFECT_PLAYER_CREEP_LEMON_PARTY = 78,
|
||||
EFFECT_TEAR_POOF_SMALL = 79,
|
||||
EFFECT_TEAR_POOF_VERYSMALL = 80,
|
||||
EFFECT_EVIL_EYE = 84,
|
||||
EFFECT_FALLING_EMBER = 87,
|
||||
EFFECT_DARK_BALL_SMOKE_PARTICLE = 88,
|
||||
EFFECT_PLAYER_CREEP_PUDDLE_MILK = 90,
|
||||
EFFECT_PLAYER_CREEP_BLACKPOWDER = 92,
|
||||
EFFECT_PENTAGRAM_BLACKPOWDER = 93,
|
||||
EFFECT_CREEP_SLIPPERY_BROWN = 94,
|
||||
EFFECT_WATER_SPLASH = 99,
|
||||
@@ -103,8 +114,8 @@ enum EffectVariant : int
|
||||
EFFECT_BRIMSTONE_BALL = 113,
|
||||
EFFECT_FORGOTTEN_CHAIN = 114,
|
||||
EFFECT_BROKEN_SHOVEL_SHADOW = 115,
|
||||
EFFECT_FORGOTTEN_SOUL = 117,
|
||||
EFFECT_DIRT_PATCH = 116,
|
||||
EFFECT_FORGOTTEN_SOUL = 117,
|
||||
EFFECT_SMALL_ROCKET = 118,
|
||||
EFFECT_SPAWNER = 120,
|
||||
EFFECT_LIGHT = 121,
|
||||
@@ -114,7 +125,9 @@ enum EffectVariant : int
|
||||
EFFECT_BIG_HORN_HAND = 125,
|
||||
EFFECT_TECH_DOT = 126,
|
||||
EFFECT_BIG_SPLASH = 132,
|
||||
EFFECT_WATER_RIPPLE = 133,
|
||||
EFFECT_PEDESTAL_RIPPLE = 134,
|
||||
EFFECT_RAIN_DROP = 135,
|
||||
EFFECT_GRID_ENTITY_PROJECTILE_HELPER = 136,
|
||||
EFFECT_MINES_TRAPDOOR_COVER = 139,
|
||||
EFFECT_BACKDROP_DECORATION = 140,
|
||||
@@ -128,10 +141,14 @@ enum EffectVariant : int
|
||||
EFFECT_TALL_LADDER = 156,
|
||||
EFFECT_TADPOLE = 158,
|
||||
EFFECT_LIL_GHOST = 159,
|
||||
EFFECT_COLOSTOMIA_PUDDLE = 168,
|
||||
EFFECT_PORTAL_TELEPORT = 161,
|
||||
EFFECT_SPRITE_TRAIL = 166,
|
||||
EFFECT_COLOSTOMIA_PUDDLE = 168,
|
||||
EFFECT_CREEP_STATIC = 169,
|
||||
EFFECT_RIFT = 180,
|
||||
EFFECT_ANIMA_CHAIN = 193,
|
||||
EFFECT_GENERIC_TRACER = 198
|
||||
EFFECT_GENERIC_TRACER = 198,
|
||||
EFFECT_PLAYER_CREEP_YELLOW = 204
|
||||
};
|
||||
|
||||
// Construction and destruction (005cd9f0, 005cd960) are the defaults, the extra data shared with its other holders.
|
||||
@@ -199,6 +216,7 @@ std::span<const EffectBehaviour> ambient_effect_behaviours();
|
||||
std::span<const EffectBehaviour> hazard_effect_behaviours();
|
||||
std::span<const EffectBehaviour> floor_effect_behaviours();
|
||||
std::span<const EffectBehaviour> beam_effect_behaviours();
|
||||
std::span<const EffectBehaviour> spike_effect_behaviours();
|
||||
|
||||
// The frame the plain poofs share: the sprite turned by the effect's rotation (mirrored unless flipped), the effect
|
||||
// gone once its animation ends.
|
||||
|
||||
+20
-131
@@ -19,24 +19,6 @@
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include "stb_image.h"
|
||||
|
||||
// The ambient and environment variants (Lua's EffectVariant).
|
||||
enum AmbientVariant : int
|
||||
{
|
||||
EFFECT_WATER_RIPPLE = 133,
|
||||
EFFECT_RAIN_DROP = 135,
|
||||
EFFECT_PLAYER_CREEP_LEMON_MISHAP = 32,
|
||||
EFFECT_PLAYER_CREEP_HOLYWATER = 37,
|
||||
EFFECT_PLAYER_CREEP_WHITE = 44,
|
||||
EFFECT_PLAYER_CREEP_BLACK = 45,
|
||||
EFFECT_PLAYER_CREEP_HOLYWATER_TRAIL = 54,
|
||||
EFFECT_PLAYER_CREEP_LEMON_PARTY = 78,
|
||||
EFFECT_PLAYER_CREEP_PUDDLE_MILK = 90,
|
||||
EFFECT_PLAYER_CREEP_BLACKPOWDER = 92,
|
||||
EFFECT_CREEP_STATIC = 169,
|
||||
EFFECT_PLAYER_CREEP_YELLOW = 204
|
||||
};
|
||||
|
||||
constexpr int ROOM_BARREN_TYPE = 19;
|
||||
constexpr int SOUND_DROPLET_SPLASH = 397;
|
||||
@@ -1030,115 +1012,6 @@ static ColorMod color_make(std::array<float, 4> tint, std::array<float, 3> offse
|
||||
return {{tint[0], tint[1], tint[2], tint[3]}, {0, 0, 0, 0}, {offset[0], offset[1], offset[2]}};
|
||||
}
|
||||
|
||||
// A spritesheet's texels, read once from its file.
|
||||
struct Texels
|
||||
{
|
||||
std::vector<uint8_t> rgba;
|
||||
int height = 0;
|
||||
int width = 0;
|
||||
};
|
||||
|
||||
static const Texels& texels_get(const KAGE::Graphics::ImageBase& image)
|
||||
{
|
||||
static std::unordered_map<std::string, Texels> cache;
|
||||
auto [entry, isNew] = cache.try_emplace(image.path);
|
||||
if (!isNew) return entry->second;
|
||||
|
||||
int channels = 0;
|
||||
Texels& texels = entry->second;
|
||||
stbi_uc* data = stbi_load(resource_path(image.path).c_str(), &texels.width, &texels.height, &channels, STBI_rgb_alpha);
|
||||
if (data) texels.rgba.assign(data, data + (size_t)texels.width * texels.height * 4);
|
||||
stbi_image_free(data);
|
||||
return texels;
|
||||
}
|
||||
|
||||
// The texel at a spritesheet position, white off the image.
|
||||
static KColor texel_read(const KAGE::Graphics::ImageBase& image, int x, int y)
|
||||
{
|
||||
const Texels& texels = texels_get(image);
|
||||
if ((uint32_t)x >= (uint32_t)texels.width || (uint32_t)y >= (uint32_t)texels.height || texels.rgba.empty())
|
||||
return kcolor_rgba(1, 1, 1, 1);
|
||||
|
||||
const uint8_t* texel = &texels.rgba[((size_t)y * texels.width + x) * 4];
|
||||
return kcolor_rgba(texel[0] / 255.0f, texel[1] / 255.0f, texel[2] / 255.0f, texel[3] / 255.0f);
|
||||
}
|
||||
|
||||
// ANM2::GetTexel 0040b600: the color a sprite drawn at a place shows at a point, from the first layer (by track)
|
||||
// whose texel there is at least half opaque, tinted and offset by the sprite's, layer's and keyframe's colors. None is
|
||||
// clear. The original reads the texel back from the texture, this from the spritesheet's file.
|
||||
static KColor sprite_texel_get(ANM2& sprite, Vector point, Vector place)
|
||||
{
|
||||
const AnimationState& state = sprite.animState;
|
||||
if (!state.animData) return kcolor_rgba(0, 0, 0, 0);
|
||||
|
||||
for (size_t track = 0; track < state.animData->animLayers.size(); track++)
|
||||
{
|
||||
const AnimationLayer& animLayer = state.animData->animLayers[track];
|
||||
int frameIndex = state.layerFrames[track];
|
||||
LayerState* layer = sprite.GetLayer(animLayer.layerId);
|
||||
if (animLayer.frames.empty() || !layer || frameIndex < 0 || frameIndex >= (int)animLayer.frames.size()) continue;
|
||||
|
||||
const AnimationFrame& frame = animLayer.frames[frameIndex];
|
||||
if (!frame.isVisible || !layer->isVisible || !layer->spriteSheet) continue;
|
||||
|
||||
SourceQuad source = AnimationLayer::GetSourceQuad(frame, *layer, SpriteDraw{}, sprite);
|
||||
DestinationQuad screen = AnimationLayer::GetDestQuad(frame, *layer, SpriteDraw{place, {}, {}}, sprite);
|
||||
float layerTurn = frame.rotation + layer->rotation;
|
||||
float spriteTurn = sprite.rotation;
|
||||
if (spriteTurn != 0 || layerTurn != 0)
|
||||
{
|
||||
float scaleX = frame.scale.x * layer->size.x;
|
||||
float scaleY = frame.scale.y * layer->size.y;
|
||||
float spriteScaleY = sprite.isFlipY ? -sprite.scale.y : sprite.scale.y;
|
||||
if ((sprite.scale.x < 0) != (scaleX < 0))
|
||||
{
|
||||
if (sprite.scale.x < 0)
|
||||
{
|
||||
layerTurn = -layerTurn;
|
||||
spriteTurn = -spriteTurn;
|
||||
}
|
||||
if (scaleX < 0) layerTurn = -layerTurn;
|
||||
}
|
||||
if (layer->isFlipY) scaleY = -scaleY;
|
||||
if ((spriteScaleY < 0) != (scaleY < 0))
|
||||
{
|
||||
if (spriteScaleY < 0)
|
||||
{
|
||||
layerTurn = -layerTurn;
|
||||
spriteTurn = -spriteTurn;
|
||||
}
|
||||
if (scaleY < 0) layerTurn = -layerTurn;
|
||||
}
|
||||
|
||||
float angle = -(layerTurn + spriteTurn) * DEGREES_TO_RADIANS;
|
||||
float cosine = std::cos(angle);
|
||||
float sine = std::sin(angle);
|
||||
for (Vector* corner : {&screen._topLeft, &screen._topRight, &screen._bottomLeft, &screen._bottomRight})
|
||||
*corner = vector_make(corner->x * cosine - corner->y * sine, corner->y * cosine + corner->x * sine);
|
||||
point = vector_make(cosine * point.x - sine * point.y, cosine * point.y + sine * point.x);
|
||||
}
|
||||
|
||||
Vector topLeft = screen._topLeft;
|
||||
Vector bottomRight = screen._bottomRight;
|
||||
if (point.x <= topLeft.x || point.x >= bottomRight.x || point.y <= topLeft.y || point.y >= bottomRight.y) continue;
|
||||
|
||||
float u = std::clamp((point.x - topLeft.x) / (bottomRight.x - topLeft.x), 0.0f, 1.0f);
|
||||
float v = std::clamp((point.y - topLeft.y) / (bottomRight.y - topLeft.y), 0.0f, 1.0f);
|
||||
float x = (source._bottomRight.x - source._topLeft.x) * u + source._topLeft.x;
|
||||
float y = (source._bottomRight.y - source._topLeft.y) * v + source._topLeft.y;
|
||||
KColor texel = texel_read(*layer->spriteSheet, (int)x, (int)y);
|
||||
if (texel._alpha < CREEP_TEXEL_OPAQUE) continue;
|
||||
|
||||
std::array<float, 4> tint{};
|
||||
std::array<float, 3> offset{};
|
||||
for (int i = 0; i < 4; i++) tint[i] = frame.color._tint[i] * (layer->color._tint[i] * sprite.color._tint[i]);
|
||||
for (int i = 0; i < 3; i++) offset[i] = frame.color._offset[i] + (layer->color._offset[i] + sprite.color._offset[i]);
|
||||
return kcolor_rgba(tint[0] * texel._red + offset[0], tint[1] * texel._green + offset[1],
|
||||
tint[2] * texel._blue + offset[2], tint[3] * texel._alpha);
|
||||
}
|
||||
return kcolor_rgba(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
// Lost Cork's multiplier for a creep's owner, 1 to 3, or 0 for none.
|
||||
static int lost_cork_get(Entity* owner)
|
||||
{
|
||||
@@ -1244,7 +1117,8 @@ static void creep_players_touch(Entity_Effect& creep, void (*touch)(Entity_Effec
|
||||
if (distance >= creep.size * creep.sprite.scale.x + player->size) continue;
|
||||
|
||||
Vector point = vector_scale(player->pos, SCREEN_SCALE);
|
||||
KColor texel = sprite_texel_get(creep.sprite, point, vector_scale(creep.pos, SCREEN_SCALE));
|
||||
KColor texel = creep.sprite.GetTexel(
|
||||
{.renderPos = vector_scale(creep.pos, SCREEN_SCALE), .sample = point, .alphaThreshold = CREEP_TEXEL_OPAQUE});
|
||||
if (texel._alpha <= CREEP_TEXEL_OPAQUE) continue;
|
||||
touch(creep, *player);
|
||||
if (creep.variant != EFFECT_CREEP_STATIC) player->SetFootprintColor(texel, false);
|
||||
@@ -1825,6 +1699,22 @@ static void light_beam_update(Entity_Effect& beam)
|
||||
}
|
||||
}
|
||||
|
||||
// The heaven door's travel: the door draws over the player, who rises up the light to the next floor (the Cathedral
|
||||
// from the Womb), and past the Dark Room the floor's seed moves on so it is laid out anew.
|
||||
static void heaven_door_travel(Entity_Effect& door, Entity_Player& player)
|
||||
{
|
||||
Game& game = *g_game;
|
||||
door.renderDepthOffset = player.pos.y - door.pos.y + 1;
|
||||
game.stageTransition.start({});
|
||||
player.AnimateLightTravel();
|
||||
player.moveToTarget = door.pos;
|
||||
game.gameStateFlags |= 1ull << GAME_STATE_HEAVEN_PATH;
|
||||
if (game.stage < STAGE_DARK_ROOM) return;
|
||||
|
||||
bool isAltPath = game.stageType == STAGETYPE_REPENTANCE || game.stageType == STAGETYPE_REPENTANCE_B;
|
||||
game.seedEffects.ForgetStageSeed((int)game.stage + (isAltPath ? 1 : 0));
|
||||
}
|
||||
|
||||
// The heaven door: open while the room is clear (in Backasswards only in the starting room or Genesis's), it takes a
|
||||
// player standing in it once ready up to the next floor. A player stepping in too early closes it again.
|
||||
static void heaven_door_update(Entity_Effect& door)
|
||||
@@ -1849,9 +1739,8 @@ static void heaven_door_update(Entity_Effect& door)
|
||||
{
|
||||
if (player->variant != 0 || player->entityCollisionClass == ENTCOLL_NONE) continue;
|
||||
if (distance_squared(player->pos, door.pos) >= HEAVEN_DOOR_RANGE_SQUARED || !is_player_free(*player)) continue;
|
||||
if (door.state >= HEAVEN_DOOR_READY)
|
||||
reconstruction_missing("Entity_Effect::Update 005d4380: the heaven door's travel (StartStageTransition)");
|
||||
if (door.state < HEAVEN_DOOR_EARLY) door.state = HEAVEN_DOOR_RESET;
|
||||
if (door.state >= HEAVEN_DOOR_READY) heaven_door_travel(door, *player);
|
||||
else if (door.state < HEAVEN_DOOR_EARLY) door.state = HEAVEN_DOOR_RESET;
|
||||
npc_sound_play(SOUND_HEAVEN_DOOR, 1, 2, 1);
|
||||
isEntered = true;
|
||||
break;
|
||||
|
||||
@@ -212,7 +212,6 @@ constexpr float EXPLOSION_LARGE_SCALE = 1.4f;
|
||||
constexpr float EXPLOSION_SMALL_VOLUME = 0.95f;
|
||||
constexpr float EXPLOSION_LARGE_VOLUME = 1.1f;
|
||||
constexpr int ENTITY_DUKE_OF_FLIES = 67;
|
||||
constexpr int ENTITY_RAG_MEGA = 409;
|
||||
constexpr const char* GFUEL_EXPLOSION_ANM2 = "gfx/promo/gfuel/effects/explosion3.anm2";
|
||||
constexpr float SCISSORS_SCALE_DOUBLE = 0.75f;
|
||||
constexpr float SCISSORS_SCALE_TRIPLE = 0.5f;
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
#include "entity_effect.h"
|
||||
#include "entity_player.h"
|
||||
#include "game.h"
|
||||
#include "player_manager.h"
|
||||
|
||||
// A spike rising from the womb's floor (Mama Gurdy's): it hurts the walking players it touches for a heart, without
|
||||
// Callus or Socks, then sinks. Two Flat Files keep it down.
|
||||
constexpr int SPIKE_DAMAGE_COUNTDOWN = 30;
|
||||
constexpr int SPIKE_FLAT_FILES = 2;
|
||||
|
||||
// Where a spike is in its rise: rising, up and hurting, and sinking.
|
||||
enum SpikeState
|
||||
{
|
||||
SPIKE_RISING = 1,
|
||||
SPIKE_UP,
|
||||
SPIKE_SINKING
|
||||
};
|
||||
|
||||
// Part of 005cdb20 (Init's spike case) Starts rising for a heart's damage, or flattened by two Flat Files.
|
||||
static void spike_init(Entity_Effect& spike)
|
||||
{
|
||||
spike.state = SPIKE_RISING;
|
||||
spike.collisionDamage = 1;
|
||||
Entity_Player* owner = g_game->playerManager.FirstTrinketOwner(TRINKET_FLAT_FILE);
|
||||
bool isFlat = owner && owner->GetTrinketMultiplier(TRINKET_FLAT_FILE) >= SPIKE_FLAT_FILES;
|
||||
spike.sprite.Play(isFlat ? "SummonWombDisabled" : "SummonWomb");
|
||||
}
|
||||
|
||||
// 005f2dd5 (Update's spike case) Rises (or, flattened, goes), hurts the walking players within reach while up, then sinks
|
||||
// and goes.
|
||||
static void spike_update(Entity_Effect& spike)
|
||||
{
|
||||
if (spike.state == SPIKE_RISING && spike.sprite.IsFinished())
|
||||
{
|
||||
if (spike.sprite.IsFinished("SummonWombDisabled")) spike.Remove();
|
||||
else spike.state = SPIKE_UP;
|
||||
}
|
||||
else if (spike.state == SPIKE_UP)
|
||||
{
|
||||
PlayerManager& players = g_game->playerManager;
|
||||
for (int i = (int)players.playerList.size() - 1; i >= 0; i--)
|
||||
{
|
||||
Entity_Player& player = *players.playerList[i];
|
||||
float reach = player.size + spike.size;
|
||||
float dx = player.pos.x - spike.pos.x;
|
||||
float dy = player.pos.y - spike.pos.y;
|
||||
if (dx * dx + dy * dy >= reach * reach || player.IsFlying()) continue;
|
||||
if (player.HasTrinket(TRINKET_CALLUS) || player.HasCollectible(COLLECTIBLE_SOCKS)) continue;
|
||||
|
||||
player.TakeDamage(spike.collisionDamage, DAMAGE_SPIKES, EntityRef(&spike), SPIKE_DAMAGE_COUNTDOWN);
|
||||
}
|
||||
if (!spike.sprite.IsFinished()) return;
|
||||
|
||||
spike.sprite.Play("UnsummonWomb");
|
||||
spike.state = SPIKE_SINKING;
|
||||
}
|
||||
else if (spike.state == SPIKE_SINKING && spike.sprite.IsFinished()) spike.Remove();
|
||||
}
|
||||
|
||||
constexpr auto SPIKE_BEHAVIOURS = std::to_array<EffectBehaviour>({
|
||||
{EFFECT_SPIKE, spike_init, effect_finishing<spike_update>, nullptr},
|
||||
});
|
||||
|
||||
std::span<const EffectBehaviour> spike_effect_behaviours()
|
||||
{
|
||||
return SPIKE_BEHAVIOURS;
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
#include "entity_effect_trail.h"
|
||||
#include "beam_renderer.h"
|
||||
#include "npc_ai.h"
|
||||
#include <algorithm>
|
||||
#include <climits>
|
||||
|
||||
// A trail fades by its MinRadius each frame (scaled by the room's time), and Init starts it at this.
|
||||
constexpr float TRAIL_FADE_DEFAULT = 0.1f;
|
||||
// The most points a trail keeps, the oldest dropped first.
|
||||
constexpr size_t TRAIL_POINTS_MAX = 128;
|
||||
// A trail whose parent is gone has this state, and removes itself once its points have faded.
|
||||
constexpr int TRAIL_ORPHANED = 99;
|
||||
// Render skips a point closer to the last one drawn than this many of its widths.
|
||||
constexpr float TRAIL_POINT_SPACING = 0.4f;
|
||||
|
||||
// The trail's extra data, made when the effect has none of its kind.
|
||||
static SpriteTrailData& trail_data_get(Entity_Effect& trail)
|
||||
{
|
||||
auto* data = dynamic_cast<SpriteTrailData*>(trail.extraData.get());
|
||||
if (data) return *data;
|
||||
|
||||
trail.extraData = std::make_shared<SpriteTrailData>();
|
||||
return static_cast<SpriteTrailData&>(*trail.extraData);
|
||||
}
|
||||
|
||||
// 005cdb20 (Init's case 166) Draws first in its layer, additively, with a fresh trail fading by the default.
|
||||
static void trail_init(Entity_Effect& trail)
|
||||
{
|
||||
trail.renderZOffset = INT_MIN;
|
||||
trail.extraData = std::make_shared<SpriteTrailData>();
|
||||
trail.minRadius = TRAIL_FADE_DEFAULT;
|
||||
layer_additive_set(*trail.sprite.GetLayer(0));
|
||||
}
|
||||
|
||||
// 005dbcfd (Update's case 166) Lays a point where the effect is, as wide as its sprite's first layer, fades every
|
||||
// point, and drops faded points from the tail (keeping one before a live point) and any past the limit. Orphaned by a
|
||||
// spawner, it lays no more and goes once nothing is left.
|
||||
// The original reads a missing first layer keyframe. Here no point is laid without one.
|
||||
static void trail_update(Entity_Effect& trail)
|
||||
{
|
||||
SpriteTrailData& data = trail_data_get(trail);
|
||||
std::deque<TrailPoint>& points = data.points;
|
||||
if (trail.spawnerType != 0 && !trail.parent) trail.state = TRAIL_ORPHANED;
|
||||
|
||||
const AnimationFrame* keyframe = trail.state == 0 ? trail.sprite.animState.GetLayerFrame(0) : nullptr;
|
||||
if (keyframe)
|
||||
{
|
||||
TrailPoint point = {
|
||||
.color = trail.sprite.color, .pos = trail.pos, .width = trail.sprite.scale.x * keyframe->scale.x};
|
||||
if (!points.empty())
|
||||
point.coordinate = vector_length(vector_sub(points.back().pos, trail.pos)) + points.back().coordinate;
|
||||
points.push_back(point);
|
||||
}
|
||||
|
||||
for (TrailPoint& point : points) point.life = std::max(point.life - trail.minRadius * trail.speedMultiplier, 0.0f);
|
||||
while (!points.empty())
|
||||
{
|
||||
bool isTailFaded = points[0].life == 0 && (points.size() < 2 || points[1].life == 0);
|
||||
if (!isTailFaded && points.size() < TRAIL_POINTS_MAX) break;
|
||||
points.pop_front();
|
||||
}
|
||||
|
||||
if (trail.state == TRAIL_ORPHANED && points.empty()) trail.Remove();
|
||||
}
|
||||
|
||||
// 00607620 (Render's case 166) Draws its sprite's first layer along the points, newest first, skipping points
|
||||
// crowding the last drawn one, each as wide and as opaque as it has left.
|
||||
static void trail_render(Entity_Effect& trail, const Vector& offset)
|
||||
{
|
||||
auto* data = dynamic_cast<SpriteTrailData*>(trail.extraData.get());
|
||||
if (!trail.sprite.isLoaded || !data || data->points.size() < 2) return;
|
||||
|
||||
g_beamRenderer.Begin(trail.sprite, 0, BEAM_FRAME_MAIN, BEAM_COORDINATE_PIXELS);
|
||||
Vector last{};
|
||||
bool isFirst = true;
|
||||
for (auto point = data->points.rbegin(); point != data->points.rend(); ++point)
|
||||
{
|
||||
bool isCrowded = vector_length(vector_sub(point->pos, last)) < point->width * TRAIL_POINT_SPACING;
|
||||
if (!isFirst && isCrowded) continue;
|
||||
|
||||
BeamPoint beamPoint = {
|
||||
.color = point->color, .coordinate = point->coordinate, .width = point->width * point->life};
|
||||
beamPoint.color._tint[3] *= point->life;
|
||||
beamPoint.pos = vector_add(render_position_get(point->pos, RENDER_SNAPPED), offset);
|
||||
g_beamRenderer.Add(beamPoint);
|
||||
last = point->pos;
|
||||
isFirst = false;
|
||||
}
|
||||
g_beamRenderer.End();
|
||||
}
|
||||
|
||||
constexpr EffectBehaviour TRAIL_BEHAVIOURS[] = {
|
||||
{EFFECT_SPRITE_TRAIL, trail_init, effect_finishing<trail_update>, trail_render}};
|
||||
|
||||
std::span<const EffectBehaviour> trail_effect_behaviours()
|
||||
{
|
||||
return TRAIL_BEHAVIOURS;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include "entity_effect.h"
|
||||
#include <deque>
|
||||
#include <span>
|
||||
|
||||
// One point a sprite trail left: where its effect was, its color and width then, how far along the trail it lies, and
|
||||
// how much of it is left (1 when laid, fading to 0).
|
||||
struct TrailPoint
|
||||
{
|
||||
ColorMod color = COLOR_DEFAULT;
|
||||
Vector pos{};
|
||||
float coordinate = 0;
|
||||
float life = 1;
|
||||
float width = 0;
|
||||
};
|
||||
|
||||
// Construction (005d2270) and destruction (005d2370) are the defaults.
|
||||
// The extra data of a sprite trail (effect 166): the points it laid, the oldest first.
|
||||
struct SpriteTrailData : Entity_Effect::ExtraData
|
||||
{
|
||||
std::deque<TrailPoint> points;
|
||||
};
|
||||
|
||||
// The sprite trail, a strip of its sprite drawn along where it has been.
|
||||
std::span<const EffectBehaviour> trail_effect_behaviours();
|
||||
@@ -29,14 +29,11 @@ constexpr int SPAWN_STATUS_FRAMES = 90;
|
||||
|
||||
// The entity types, variants and boss ids spawning and layouts single out.
|
||||
constexpr int ENTITY_HORF = 12;
|
||||
constexpr int ENTITY_HOST = 27;
|
||||
constexpr int ENTITY_FLAMINGHOPPER = 54;
|
||||
constexpr int ENTITY_EYE = 60;
|
||||
constexpr int ENTITY_WALKINGBOIL = 88;
|
||||
constexpr int ENTITY_GREED_GAPER = 299;
|
||||
constexpr int ENTITY_MUSHROOM = 300;
|
||||
constexpr int ENTITY_SUB_HORF = 812;
|
||||
constexpr int ENTITY_GYRO = 824;
|
||||
constexpr int EFFECT_CRAWLSPACE_LADDER = 192;
|
||||
constexpr int BOSS_SATAN = 24;
|
||||
|
||||
@@ -44,17 +41,8 @@ constexpr int CARD_SPECIAL_CHANCE = 25;
|
||||
constexpr int CARD_RUNE_CHANCE = 10;
|
||||
constexpr int PICKUP_RANDOM_CARD = 301;
|
||||
|
||||
constexpr int SLOT_MACHINE = 1;
|
||||
constexpr int SLOT_BEGGAR = 4;
|
||||
constexpr int SLOT_DEVIL_BEGGAR = 5;
|
||||
constexpr int SLOT_KEY_MASTER = 7;
|
||||
constexpr int SLOT_SHELL_GAME = 6;
|
||||
constexpr int SLOT_DONATION = 8;
|
||||
constexpr int SLOT_CLOSET_TAINTED = 14;
|
||||
constexpr int SLOT_HELL_GAME = 15;
|
||||
constexpr int SLOT_CRANE_GAME = 16;
|
||||
constexpr int SLOT_CONFESSIONAL = 17;
|
||||
constexpr int SLOT_ROTTEN_BEGGAR = 18;
|
||||
constexpr int SHOPKEEPER_SPECIAL = 3;
|
||||
constexpr int SHOPKEEPER_SECRET_SPECIAL = 4;
|
||||
constexpr int EFFECT_VARIANT_TRAPDOOR_MARKER = 39;
|
||||
|
||||
+77
-1
@@ -124,6 +124,17 @@ constexpr int ORBIT_LAYER_WISPS = 8;
|
||||
constexpr int COLLECTIBLE_UNICORN_STUMP_ID = 298;
|
||||
constexpr int VERSUS_PUNCHING_INTERVAL = 16;
|
||||
|
||||
// How long a versus familiar leaves alone a target it chased too long.
|
||||
constexpr int VERSUS_GIVE_UP_FRAMES = -900;
|
||||
|
||||
// Headless Baby's blood and creep and Juicy Sack's creep: how often, and their sizes.
|
||||
constexpr int HEADLESS_SPLAT_INTERVAL = 3;
|
||||
constexpr int HEADLESS_CREEP_INTERVAL = 2;
|
||||
constexpr int HEADLESS_CREEP_ODDS = 5;
|
||||
constexpr int JUICY_SACK_CREEP_INTERVAL = 4;
|
||||
constexpr float TRAIL_SCALE_RANGE = 0.5f;
|
||||
constexpr float TRAIL_SCALE_MIN = 0.2f;
|
||||
|
||||
// How much bigger the familiars of BFFS! and Hive Mind look.
|
||||
constexpr float LOCUST_MULTIPLIED_SCALE = 1.1f;
|
||||
constexpr float MULTIPLIED_SCALE = 1.25f;
|
||||
@@ -161,6 +172,15 @@ std::vector<Entity_Familiar*> familiar_query(int queryVariant)
|
||||
return found;
|
||||
}
|
||||
|
||||
// In a versus match, a familiar that chased its target longer than its limit leaves it alone for a while.
|
||||
void familiar_chase_limit(Entity_Familiar& familiar, int chaseFrames)
|
||||
{
|
||||
if (!familiar_versus() || !familiar.target) return;
|
||||
|
||||
int& frames = familiar.targetFrames[familiar.target->index];
|
||||
if (frames > chaseFrames) frames = VERSUS_GIVE_UP_FRAMES;
|
||||
}
|
||||
|
||||
// Whether a versus match runs, where familiars fight each other.
|
||||
bool familiar_versus()
|
||||
{
|
||||
@@ -487,6 +507,30 @@ void Entity_Familiar::Update()
|
||||
update_tail();
|
||||
}
|
||||
|
||||
// A trail's size: a fifth to seven tenths of its own.
|
||||
static float trail_scale()
|
||||
{
|
||||
return random_unit() * TRAIL_SCALE_RANGE + TRAIL_SCALE_MIN;
|
||||
}
|
||||
|
||||
// Sizes a familiar's fresh splat or creep and runs its first frame.
|
||||
static void trail_finish(Entity& trail, float scale)
|
||||
{
|
||||
trail.sprite.scale = vector_make(scale, scale);
|
||||
trail.Update();
|
||||
}
|
||||
|
||||
// Leaves creep of a kind under a familiar (Headless Baby's red, Juicy Sack's white).
|
||||
static void creep_drop(Entity_Familiar& familiar, int creepVariant)
|
||||
{
|
||||
Entity* creep = g_game->Spawn({.position = familiar.pos,
|
||||
.spawner = &familiar,
|
||||
.type = ENTITY_EFFECT,
|
||||
.variant = creepVariant,
|
||||
.seed = Random()});
|
||||
trail_finish(*creep, trail_scale());
|
||||
}
|
||||
|
||||
// The behaviours of 0061da10 by variant. The familiars not reconstructed yet stop the game.
|
||||
void Entity_Familiar::variant_update()
|
||||
{
|
||||
@@ -510,9 +554,41 @@ void Entity_Familiar::variant_update()
|
||||
switch (variant)
|
||||
{
|
||||
case DEMON_BABY: return ai_auto_shooter();
|
||||
case BUM_FRIEND:
|
||||
case DARK_BUM:
|
||||
case KEY_BUM:
|
||||
case SUPER_BUM: return ai_pickup_sack();
|
||||
case HOLY_WATER:
|
||||
case BIG_CHUBBY: return ai_charger();
|
||||
case CUBE_OF_MEAT_3:
|
||||
case CUBE_OF_MEAT_4:
|
||||
case LEECH: return ai_walker();
|
||||
case BALL_OF_BANDAGES_3:
|
||||
case BALL_OF_BANDAGES_4:
|
||||
ai_walker();
|
||||
return Shoot();
|
||||
case HEADLESS_BABY:
|
||||
FollowParent();
|
||||
if (IsFrame(HEADLESS_SPLAT_INTERVAL, 0))
|
||||
{
|
||||
float scale = trail_scale();
|
||||
trail_finish(*g_game->Spawn({.position = pos, .type = ENTITY_EFFECT, .variant = EFFECT_BLOOD_SPLAT,
|
||||
.seed = Random()}),
|
||||
scale);
|
||||
}
|
||||
if (IsFrame(HEADLESS_CREEP_INTERVAL, 0) && random_below(HEADLESS_CREEP_ODDS) > 1)
|
||||
creep_drop(*this, EFFECT_PLAYER_CREEP_RED);
|
||||
return;
|
||||
case JUICY_SACK:
|
||||
sprite.Play("FloatDown");
|
||||
FollowParent();
|
||||
if (IsFrame(JUICY_SACK_CREEP_INTERVAL, 0)) creep_drop(*this, EFFECT_PLAYER_CREEP_WHITE);
|
||||
return;
|
||||
case LITTLE_CHUBBY:
|
||||
case BOBS_BRAIN: return ai_charger();
|
||||
case DEAD_BIRD: return ai_flying_bird();
|
||||
case DEAD_BIRD:
|
||||
case EVES_BIRD_FOOT:
|
||||
case LIL_HAUNT: return ai_flying_bird();
|
||||
case INCUBUS:
|
||||
FollowParent();
|
||||
return update_weapon(false);
|
||||
|
||||
@@ -102,6 +102,8 @@ struct Entity_Familiar : Entity
|
||||
JUICY_SACK = 52,
|
||||
ROBO_BABY_2 = 53,
|
||||
ROTTEN_BABY = 54,
|
||||
HEADLESS_BABY = 55,
|
||||
LEECH = 56,
|
||||
MYSTERY_SACK = 57,
|
||||
BBF = 58,
|
||||
BOBS_BRAIN = 59,
|
||||
@@ -426,6 +428,7 @@ template <typename List> bool familiar_listed(const List& list, int value)
|
||||
|
||||
std::vector<Entity_Familiar*> familiar_query(int queryVariant);
|
||||
bool familiar_versus();
|
||||
void familiar_chase_limit(Entity_Familiar& familiar, int chaseFrames);
|
||||
void familiar_sound_play(int sound, SoundPlay play = {});
|
||||
bool familiar_unicorn_active(Entity_Player& owner);
|
||||
Entity* spawn_dip_at(int subType, const Vector* position, Entity* spawner, const Vector* targetPosition);
|
||||
@@ -434,3 +437,4 @@ Vector direction_unit(int direction);
|
||||
void familiar_check(Entity_Player& player, const FamiliarCount& familiars);
|
||||
void familiars_evaluate(Entity_Player& player);
|
||||
int familiar_lullaby_delay(Entity_Familiar& familiar, int fireDelay);
|
||||
bool bum_pickup_collect(Entity_Familiar& bum, Entity_Pickup& pickup);
|
||||
+1500
-69
File diff suppressed because it is too large.
Load diff
+79
-10
@@ -4,13 +4,51 @@
|
||||
#include "homing_laser.h"
|
||||
#include <vector>
|
||||
|
||||
// The distances a knife has no use for yet: removed or shown once it flies past them.
|
||||
// The distances a knife has no use for yet: where it splits off its parent and where it shows up.
|
||||
constexpr float KNIFE_DISTANCE_NONE = -1;
|
||||
|
||||
// The knives (Lua's KnifeVariant): Mom's Knife, the Forgotten's swung weapons, Bloody Babylon's and the swords.
|
||||
enum KnifeVariant : int
|
||||
{
|
||||
KNIFE_MOMS_KNIFE,
|
||||
KNIFE_BONE_CLUB,
|
||||
KNIFE_BONE_SCYTHE,
|
||||
KNIFE_DONKEY_JAWBONE,
|
||||
KNIFE_BAG_OF_CRAFTING,
|
||||
KNIFE_SUMPTORIUM,
|
||||
KNIFE_BERSERK_CLUB = 8,
|
||||
KNIFE_NOTCHED_AXE = 9,
|
||||
KNIFE_SPIRIT_SWORD = 10,
|
||||
KNIFE_TECH_SWORD = 11
|
||||
};
|
||||
|
||||
// What a knife is by subtype: held or thrown, following a homing path, chained to its parent, or swung as an item.
|
||||
enum KnifeSubType : int
|
||||
{
|
||||
KNIFE_SUBTYPE_HELD,
|
||||
KNIFE_SUBTYPE_PATH,
|
||||
KNIFE_SUBTYPE_CHAINED = 3,
|
||||
KNIFE_SUBTYPE_HELD_ITEM = 4
|
||||
};
|
||||
|
||||
// Where apply_hit_effects lands its effects: the knife's point, the target and its size, the damage and its flags, and
|
||||
// whether the knife hit while thrown.
|
||||
struct KnifeHit
|
||||
{
|
||||
Vector position{};
|
||||
Vector targetPosition{};
|
||||
Entity* target = nullptr;
|
||||
uint64_t damageFlags = 0;
|
||||
float damage = 0;
|
||||
float targetSize = 0;
|
||||
bool isFlying = false;
|
||||
};
|
||||
|
||||
// Construction and destruction (00960b50, 00960a70) are the defaults.
|
||||
// Field accessors (004d7790, 004d77a0, 0060cf10, 0060cfb0, 0085de90, 0085deb0, 0085dec0) are the public fields.
|
||||
// A knife (Lua's EntityKnife): Mom's Knife and the swung weapons (bones, clubs, swords), with the tear effects they
|
||||
// carry, their charge and flight, and the path a homing knife follows.
|
||||
// carry, their charge and flight, and the path a homing knife follows. A knife split off its parent (Cricket's Body,
|
||||
// Angelic Prism) follows it out to splitDistance, then turns off by splitAngle and splitOffset.
|
||||
struct Entity_Knife : Entity
|
||||
{
|
||||
HomingLaser homingLaser;
|
||||
@@ -23,10 +61,12 @@ struct Entity_Knife : Entity
|
||||
EntityPtr techLaser;
|
||||
Vector anchorPosition{};
|
||||
Vector initPosition{};
|
||||
Vector splitOffset{};
|
||||
float basePosOffsetY = 0;
|
||||
float charge = 0;
|
||||
float displayRotation = 0;
|
||||
float fallingSpeed = 0;
|
||||
float flightAngle = 0;
|
||||
float height = 0;
|
||||
float knifeDepthOffset = 0;
|
||||
float knifeDistance = 0;
|
||||
@@ -36,18 +76,24 @@ struct Entity_Knife : Entity
|
||||
float pathOffset = 0;
|
||||
float pathProgress = 0;
|
||||
float rotation = 0;
|
||||
float removeDistance = KNIFE_DISTANCE_NONE;
|
||||
float rotationOffset = 0;
|
||||
float scale = 0;
|
||||
float showDistance = KNIFE_DISTANCE_NONE;
|
||||
float splitAngle = 0;
|
||||
float splitDistance = KNIFE_DISTANCE_NONE;
|
||||
int pathSegment = 0;
|
||||
short spinsLeft = 0;
|
||||
short swingEffects = 0;
|
||||
short swingTick = 0;
|
||||
bool isAttacking = false;
|
||||
bool isDeadEyeHit = false;
|
||||
bool isFlying = false;
|
||||
bool isMultidimensionalApplied = false;
|
||||
bool isPrimaryClub = false;
|
||||
bool isPrismApplied = false;
|
||||
bool isRecoiled = false;
|
||||
bool isSpinAttack = false;
|
||||
bool isSwingCharged = false;
|
||||
bool isSwinging = false;
|
||||
bool isUsingParentHitList = false;
|
||||
|
||||
@@ -61,19 +107,42 @@ struct Entity_Knife : Entity
|
||||
|
||||
int GetBaseVariant();
|
||||
std::vector<uint32_t>& GetHitEntities();
|
||||
void InitHomingPath(Vector direction, Entity* source, float pathOffset);
|
||||
void copy_parent_state(Entity_Knife* source);
|
||||
uint32_t spawn_child_knife();
|
||||
void InitHomingPath(Vector direction, Entity* source, float offset);
|
||||
void copy_parent_state(Entity_Knife& source);
|
||||
bool spawn_child_knife();
|
||||
Entity_Player* GetPlayer();
|
||||
Entity* GetRootParent();
|
||||
Entity_Knife* GetRootParent();
|
||||
void Shoot(float charge, float range);
|
||||
void UpdateHomingPath();
|
||||
void update_target(float* outAngle);
|
||||
void apply_wiggle(float*);
|
||||
void update_target(float& angle);
|
||||
void apply_wiggle(float& angle);
|
||||
void screen_wrap();
|
||||
void Reset();
|
||||
void SetAttackAnimation();
|
||||
void SpinAttack(short remainingSpins, int startFrame);
|
||||
uint8_t drain_notched_axe(int charge);
|
||||
bool drain_notched_axe(int charge);
|
||||
void UpdateSwingHits();
|
||||
void apply_hit_effects(const KnifeHit& hit);
|
||||
|
||||
private:
|
||||
bool held_update(Entity_Player* player);
|
||||
void ludovico_update();
|
||||
void path_update();
|
||||
void chained_update();
|
||||
void held_item_update();
|
||||
void hydrobounce_land();
|
||||
void hydrobounce_update();
|
||||
void lasers_update(Entity_Player* player);
|
||||
void grid_hit_update(Entity_Player* player);
|
||||
void sword_beam_fire(Entity_Player* player);
|
||||
void brimstone_knife_spawn(Entity_Player* player);
|
||||
void render_orbit_trail(const Vector& offset);
|
||||
};
|
||||
|
||||
bool is_swung_knife_variant(int variant);
|
||||
float bezier_closest_point(const Vector& point, const BezierPoint& start, const BezierPoint& end, float& outT);
|
||||
Vector room_screen_wrap(const Vector& position, float margin);
|
||||
void tear_flags_area_apply(const Vector& position, Entity* source, float radius, float damage,
|
||||
const TearFlags& flags);
|
||||
|
||||
extern Entity_Player* g_notchedAxePlayer;
|
||||
File diff suppressed because it is too large.
Load diff
+1
-122
@@ -32,7 +32,6 @@ constexpr int CHARGE_BAR_FRAMES = 100;
|
||||
constexpr int ENTITY_FEAR_IMMUNE = 205;
|
||||
constexpr int ENTITY_NO_DECOY_TYPE = 213;
|
||||
constexpr int ENTITY_MOMS_HEART_PLAYER_PICK = 53;
|
||||
constexpr int ENTITY_DEATH_REWARD_EXEMPT = 885;
|
||||
constexpr int ENTITY_UNREACHABLE_EXEMPT = 886;
|
||||
constexpr int ENTITY_FLICKER_TYPE = 252;
|
||||
constexpr int ENTITY_DEATH_SPARK_TYPE = 882;
|
||||
@@ -56,7 +55,6 @@ constexpr int DEATH_NO_BURST_FIRST = 74;
|
||||
constexpr int DEATH_NO_BURST_LAST = 76;
|
||||
constexpr int MULLIGAN_VARIANT_FLEEING = 2;
|
||||
constexpr int CHALLENGE_KILL_CHARGE = 33;
|
||||
constexpr int COLLECTIBLE_LIL_PORTAL_ID = 661;
|
||||
constexpr std::string_view BIG_HORN_SPIT_EVENT = "Item";
|
||||
constexpr std::string_view DIRT_LAYER = "dirt";
|
||||
constexpr std::string_view HOLE_LAYER = "Hole";
|
||||
@@ -97,10 +95,8 @@ constexpr float SHIELD_SECOND = 30;
|
||||
constexpr float SHIELD_BASE = 0.09f;
|
||||
constexpr float SHIELD_FALLOFF = 0.18f;
|
||||
constexpr uint32_t BLACK_HEART_CHANCE = 5;
|
||||
constexpr float EXORCIST_ROOM_MARGIN = -10;
|
||||
constexpr int SOUND_POOP_DEATH = 237;
|
||||
constexpr float POOP_DEATH_VOLUME = 0.9f;
|
||||
constexpr uint32_t DEBUG_HEALTH_VALUES = 1 << 6;
|
||||
constexpr uint64_t FLAG_FRIENDLY_BALL_DYING = 1ull << 60;
|
||||
|
||||
// The burst effects a dead NPC leaves besides blood (Lua's EffectVariant).
|
||||
@@ -120,16 +116,11 @@ constexpr int SHADOW_CHARGER_SUBTYPE = 1;
|
||||
constexpr int TYPE_NO_TICK_A = 274;
|
||||
constexpr int TYPE_NO_TICK_B = 275;
|
||||
|
||||
constexpr int ENTITY_KEY_TEAR_A = 43;
|
||||
constexpr int ENTITY_KEY_TEAR_B = 44;
|
||||
|
||||
// The items and seeds whose effects the NPC update reads, by Lua id.
|
||||
constexpr int COLLECTIBLE_HOURGLASS_ID = 66;
|
||||
constexpr int COLLECTIBLE_GAMEKID_ID = 93;
|
||||
constexpr int COLLECTIBLE_CHAMPION_BELT_ID = 208;
|
||||
constexpr int COLLECTIBLE_GIMPY_ID = 225;
|
||||
constexpr int COLLECTIBLE_STOP_WATCH_ID = 232;
|
||||
constexpr int COLLECTIBLE_INFESTATION_2_ID = 234;
|
||||
constexpr int COLLECTIBLE_SOUL_ID = 335;
|
||||
constexpr int COLLECTIBLE_TOXIC_SHOCK_ID = 350;
|
||||
constexpr int COLLECTIBLE_BETRAYAL_ID = 391;
|
||||
@@ -138,11 +129,7 @@ constexpr int COLLECTIBLE_MAW_OF_THE_VOID_ID = 408;
|
||||
constexpr int COLLECTIBLE_JAR_OF_FLIES_ID = 434;
|
||||
constexpr int COLLECTIBLE_CONTAGION_ID = 466;
|
||||
constexpr int COLLECTIBLE_BROKEN_MODEM_ID = 514;
|
||||
constexpr int COLLECTIBLE_SANGUINE_BOND_ID = 640;
|
||||
constexpr int COLLECTIBLE_VASCULITIS_ID = 657;
|
||||
constexpr int COLLECTIBLE_GUPPYS_EYE_ID = 665;
|
||||
constexpr int COLLECTIBLE_BONE_SPURS_ID = 683;
|
||||
constexpr int COLLECTIBLE_LIL_ABADDON_ID = 684;
|
||||
constexpr int COLLECTIBLE_SALVATION_ID = 696;
|
||||
constexpr int COLLECTIBLE_VANISHING_TWIN_ID = 697;
|
||||
constexpr int TRINKET_PURPLE_HEART_ID = 5;
|
||||
@@ -150,7 +137,6 @@ constexpr int TRINKET_TICK_ID = 53;
|
||||
constexpr int TRINKET_SUPER_MAGNET_ID = 68;
|
||||
constexpr int TRINKET_LIGHTER_ID = 135;
|
||||
constexpr int TRINKET_ICE_CUBE_ID = 188;
|
||||
constexpr int TRINKET_DEVILS_CROWN_ID = 185;
|
||||
constexpr int NULLITEM_DAMOCLES_WEAKNESS = 64;
|
||||
|
||||
constexpr int CHALLENGE_BEANS = 30;
|
||||
@@ -434,7 +420,7 @@ bool game_is_hard_mode()
|
||||
}
|
||||
|
||||
// 00703470 Remembers a boss as met this run, but for the ones the boss list leaves out.
|
||||
static void game_encountered_boss_add(int bossType, int bossVariant)
|
||||
void game_encountered_boss_add(int bossType, int bossVariant)
|
||||
{
|
||||
std::vector<BossId>& bosses = g_game->encounteredBosses;
|
||||
auto isSame = [&](const BossId& boss) {
|
||||
@@ -2451,61 +2437,6 @@ void Entity_NPC::fire_projectile_from_params(Entity_Projectile* projectile)
|
||||
projectile->apply_spawn_flags({this, flags, scale, isChampion ? championColorIdx : -1});
|
||||
}
|
||||
|
||||
// The NPC types with their own interpolation or drawing, which the generic steps below do not cover.
|
||||
constexpr std::array<int, 6> INTERPOLATE_SPECIAL_TYPES = {62, 815, 830, 831, 881, 915};
|
||||
constexpr std::array<int, 21> RENDER_SPECIAL_TYPES = {273, 411, 807, 810, 815, 816, 835, 865, 881, 886, 893,
|
||||
906, 909, 910, 912, 920, 921, 950, 951, 964, 965};
|
||||
|
||||
// 006d2b50 Moves it the interpolation's half step (Entity::Interpolate), runs its AI's interpolation call, and moves
|
||||
// the effect it aims with.
|
||||
void Entity_NPC::Interpolate()
|
||||
{
|
||||
if (pauseTimer != 0) return;
|
||||
if (type == ENTITY_MINECART) minecart_interpolate(*this);
|
||||
else Entity::Interpolate();
|
||||
if (aiCallFlags & AI_CALL_INTERPOLATE) ai_call(AI_PHASE_INTERPOLATE);
|
||||
UpdateChildEffectPosition(true);
|
||||
|
||||
bool isHeld = HasEntityFlags(FLAG_FREEZE | FLAG_HELD) || holdCountdown > 0;
|
||||
bool isStill = isHeld || state == NPC_STATE_APPEAR || state == NPC_STATE_DEATH || state == NPC_STATE_UNIQUE_DEATH;
|
||||
if (!isStill && std::ranges::find(INTERPOLATE_SPECIAL_TYPES, type) != INTERPOLATE_SPECIAL_TYPES.end())
|
||||
reconstruction_missing("Entity_NPC::Interpolate 006d2b50: a jumping enemy's height");
|
||||
if (type == ENTITY_HEART && variant == 1 && entityRef && entityRef->IsEnemy())
|
||||
{
|
||||
Entity* partner = entityRef;
|
||||
targetPosition = vector_sub(partner->pos, pos);
|
||||
partner->targetPosition = vector_scale(targetPosition, -1);
|
||||
}
|
||||
}
|
||||
|
||||
// 006d2e50 Draws it (Entity::Render) and, in the normal and above water passes, the status effect it suffers on its
|
||||
// OverlayEffect null.
|
||||
void Entity_NPC::Render(const Vector& offset)
|
||||
{
|
||||
if (type == ENTITY_MINECART && variant == 0 && child) return;
|
||||
bool isLinked = (type == ENTITY_LARRYJR && variant == 3 && child) || (type == ENTITY_POOP && entityRef);
|
||||
if (minecart || isLinked || std::ranges::find(RENDER_SPECIAL_TYPES, type) != RENDER_SPECIAL_TYPES.end())
|
||||
reconstruction_missing("Entity_NPC::Render 006d2e50: a special enemy's drawing");
|
||||
if (spawnerEntity && spawnerEntity->type == ENTITY_PLAYER && g_manager->netplayManager.is_online())
|
||||
reconstruction_missing("Entity_NPC::Render 006d2e50: a remote player's faded enemy");
|
||||
if (championColorIdx == CHAMPION_SIZE_PULSE)
|
||||
reconstruction_missing("Entity_NPC::Render 006d2e50: the size pulsing champion");
|
||||
|
||||
Entity::Render(offset);
|
||||
if (!isVisible)
|
||||
renderPosition = vector_add(render_position_get(vector_add(pos, posOffset), RENDER_SNAPPED), offset);
|
||||
lua_engine_get().PostNPCRender(this, offset);
|
||||
|
||||
RenderMode renderMode = g_game->room->entityList.renderMode;
|
||||
if (renderMode != RENDER_NORMAL && renderMode != RENDER_WATER_ABOVE) return;
|
||||
status_overlay_render(offset);
|
||||
if (g_game->playerManager.FirstCollectibleOwner(COLLECTIBLE_SPIDER_MOD_ID, LAZARUS_SHARE_CHECK) && isVisible &&
|
||||
IsActiveEnemy(DEAD_EXCLUDED))
|
||||
reconstruction_missing("Entity_NPC::Render 006d2e50: Spider Mod's health bar");
|
||||
if (HasEntityFlags(FLAG_PERSISTENT | FLAG_FRIENDLY_BALL_DYING) && (g_game->debugFlags & DEBUG_HEALTH_VALUES))
|
||||
reconstruction_missing("Entity_NPC::Render 006d2e50: the debug health text");
|
||||
}
|
||||
|
||||
// Part of 006d2e50: the status effect sprite drawn on the OverlayEffect null, once on a shared body.
|
||||
void Entity_NPC::status_overlay_render(const Vector& offset)
|
||||
{
|
||||
@@ -2645,52 +2576,6 @@ void Entity_NPC::trigger_kill_item_effects()
|
||||
lua_engine_get().PostNPCDeath(this);
|
||||
}
|
||||
|
||||
// 006bbdc0 The rewards a dead enemy gives its killers: the damage flags' and Gimpy's drops, the familiars' and
|
||||
// items' on-kill effects, Keeper's and the bosses' coins, the soul hearts of Sanguine Bond and the like. None of them
|
||||
// happens without its item or flag, which is all this covers yet.
|
||||
void Entity_NPC::trigger_death_rewards()
|
||||
{
|
||||
bool isRewarded = Entity::is_enemy_type(type) && type != ENTITY_FIREPLACE && type != ENTITY_SHOPKEEPER &&
|
||||
type != ENTITY_MOVABLE_TNT && !(type == ENTITY_DEATH_REWARD_EXEMPT && variant == 10) &&
|
||||
type != ENTITY_FROZEN_ENEMY && type != ENTITY_MINECART && type != ENTITY_POOP;
|
||||
if (!isRewarded) return;
|
||||
if (DoesEntityShareStatus() && parent && type != ENTITY_LARRYJR && type != ENTITY_BUTTLICKER) return;
|
||||
|
||||
PlayerManager& players = g_game->playerManager;
|
||||
auto isFamiliarKill = [](const DamageEvent& event) {
|
||||
return event.source.type == ENTITY_FAMILIAR || event.source.type == ENTITY_BLOOD_PUPPY ||
|
||||
(event.source.type == ENTITY_TEAR &&
|
||||
(event.source.variant == ENTITY_KEY_TEAR_A || event.source.variant == ENTITY_KEY_TEAR_B));
|
||||
};
|
||||
bool isRewardItem = players.FirstCollectibleOwner(COLLECTIBLE_GIMPY_ID, LAZARUS_SHARE_CHECK) ||
|
||||
(killDamageFlags & ((uint64_t)DAMAGE_SPAWN_RED_HEART | DAMAGE_SPAWN_COIN |
|
||||
DAMAGE_SPAWN_BLACK_HEART | DAMAGE_SPAWN_CARD | DAMAGE_SPAWN_RUNE)) ||
|
||||
std::ranges::any_of(killDamageEvents, isFamiliarKill) ||
|
||||
players.RandomCollectibleOwner(COLLECTIBLE_INFESTATION_2_ID, initSeed, nullptr) ||
|
||||
players.RandomCollectibleOwner(COLLECTIBLE_BONE_SPURS_ID, initSeed, nullptr) ||
|
||||
players.RandomCollectibleOwner(COLLECTIBLE_LIL_ABADDON_ID, initSeed, nullptr) ||
|
||||
players.RandomTrinketOwner(TRINKET_DEVILS_CROWN_ID, initSeed, nullptr) ||
|
||||
players.FirstCollectibleOwner(COLLECTIBLE_VASCULITIS_ID, LAZARUS_SHARE_CHECK);
|
||||
if (!HasEntityFlags(FLAG_NO_REWARD) && isRewardItem)
|
||||
reconstruction_missing("Entity_NPC::trigger_death_rewards 006bbdc0: the kill's item and flag rewards");
|
||||
if (!CanShutDoors()) return;
|
||||
|
||||
if (g_game->room->isExorcistActive && g_game->room->IsPositionInRoom(pos, EXORCIST_ROOM_MARGIN))
|
||||
reconstruction_missing("Entity_NPC::trigger_death_rewards 006bbdc0: the Exorcist's souls");
|
||||
if (g_game->room->IsPositionInRoom(pos, EXORCIST_ROOM_MARGIN))
|
||||
for (Entity_Player* player : players.playerList)
|
||||
if (player->variant == 0 && player->HasCollectible(COLLECTIBLE_LIL_PORTAL_ID))
|
||||
reconstruction_missing("Entity_NPC::trigger_death_rewards 006bbdc0: Lil Portal's growth");
|
||||
for (Entity_Player* player : players.playerList)
|
||||
{
|
||||
bool isLiving = player->variant == 0 && !player->isCoopGhost;
|
||||
if (isLiving && player->playerType == PLAYER_MAGDALENE_B)
|
||||
reconstruction_missing("Entity_NPC::trigger_death_rewards 006bbdc0: Tainted Magdalene's hearts");
|
||||
if (player->variant == 0 && player->HasCollectible(COLLECTIBLE_SANGUINE_BOND_ID))
|
||||
reconstruction_missing("Entity_NPC::trigger_death_rewards 006bbdc0: the soul drops");
|
||||
}
|
||||
}
|
||||
|
||||
// 00447770 Its parent, which only NPCs are.
|
||||
Entity_NPC* Entity_NPC::ParentNPC()
|
||||
{
|
||||
@@ -2816,12 +2701,6 @@ Entity_NPC* Entity_NPC::ThrowStrider(const Vector&, Entity*, const Vector&)
|
||||
reconstruction_missing("Entity_NPC::ThrowStrider 0055cef0");
|
||||
}
|
||||
|
||||
// 00565680
|
||||
void Entity_NPC::render_v1_layer_frames()
|
||||
{
|
||||
reconstruction_missing("Entity_NPC::render_v1_layer_frames 00565680");
|
||||
}
|
||||
|
||||
// 0059bed0
|
||||
void Entity_NPC::RenderSegmentLink(const Vector&, bool)
|
||||
{
|
||||
|
||||
@@ -383,6 +383,7 @@ bool any_player_flying();
|
||||
Entity* game_nearest_target_player(const Vector& position, Entity* source, bool isPlayersOnly, bool isTargetDecoys,
|
||||
float maxDistance);
|
||||
void game_shake_screen(int timeout);
|
||||
void game_encountered_boss_add(int bossType, int bossVariant);
|
||||
bool game_is_hard_mode();
|
||||
uint32_t room_grid_collision_at(const Vector& position);
|
||||
ColorMod champion_sprite_color_get(int championColor);
|
||||
|
||||
@@ -0,0 +1,453 @@
|
||||
#include "entity_npc.h"
|
||||
#include "entity_config.h"
|
||||
#include "entity_player.h"
|
||||
#include "game.h"
|
||||
#include "lua_engine.h"
|
||||
#include "manager.h"
|
||||
#include "mines.h"
|
||||
#include "npc_ai.h"
|
||||
#include "room.h"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
#include <map>
|
||||
|
||||
constexpr float NPC_SCREEN_SCALE = 0.65f;
|
||||
constexpr int NPC_DEBUG_HEALTH_FLAG = 1 << 6;
|
||||
constexpr int SPAWN_BAR_DELAY = 2;
|
||||
constexpr float HEALTH_BAR_DROP = 10;
|
||||
|
||||
// The variants with their own height or drawing: Wormwood, Big Bony's bone, Singe's ball, the Ultra Greed coin
|
||||
// pile's statue, the Shell and Dogma's body.
|
||||
constexpr int WORMWOOD = 3;
|
||||
constexpr int BIG_BONY_BONE = 10;
|
||||
constexpr int FESTERING_GUTS = 20;
|
||||
constexpr int SHELL = 3;
|
||||
constexpr int SCOURGE_CHAIN = 10;
|
||||
constexpr int RIDDEN_MINECART = 10;
|
||||
constexpr int SINGE_BALL_VARIANT = 1;
|
||||
constexpr int HEART_PAIRED = 1;
|
||||
|
||||
// The ghost wraith's faintness without water to reflect it.
|
||||
constexpr float WRAITH_DRY_ALPHA = 0.2f;
|
||||
|
||||
// The size pulsing champion's beat: its speed per room frame and how much it swells.
|
||||
constexpr float SIZE_PULSE_SPEED = 0.2f;
|
||||
constexpr float SIZE_PULSE_SWELL = 0.15f;
|
||||
|
||||
// The Lamb's dash: the afterimages it leaves, how far back they reach along its velocity, and the faint copy on top.
|
||||
constexpr int LAMB_DASH_STATE = NPC_STATE_ATTACK2;
|
||||
constexpr int LAMB_AFTERIMAGES = 7;
|
||||
constexpr float LAMB_AFTERIMAGE_REACH = 5;
|
||||
constexpr float LAMB_AFTERIMAGE_FADE = 0.9f;
|
||||
constexpr float LAMB_AFTERIMAGE_BASE = 0.1f;
|
||||
constexpr float LAMB_COPY_ALPHA = 0.2f;
|
||||
|
||||
// The small leech hides above water while it swims below this height.
|
||||
constexpr float SMALL_LEECH_SURFACE = -3;
|
||||
|
||||
// A pickup held at the Item null rides a little lower.
|
||||
constexpr float HELD_PICKUP_DROP = 6.5f;
|
||||
|
||||
// The Needle's two trailing segments, spaced along its trail, and the depth they sink out of sight at.
|
||||
constexpr int NEEDLE_SEGMENTS = 2;
|
||||
constexpr float NEEDLE_SEGMENT_SPACING = 15;
|
||||
constexpr float NEEDLE_HIDE_DEPTH = -6;
|
||||
constexpr float NEEDLE_HIDE_STEP = 3;
|
||||
|
||||
// The Fissure's head frames by its v1.x, its segments' sideways nudge, and the depths its layers fade over.
|
||||
constexpr float FISSURE_TURN = 4;
|
||||
constexpr float FISSURE_NUDGE = 3;
|
||||
constexpr float FISSURE_FADE_START = -2;
|
||||
constexpr float FISSURE_FADE_LENGTH = 18;
|
||||
constexpr float FISSURE_REFLECT_FADE_START = 2;
|
||||
constexpr float FISSURE_REFLECT_FADE_LENGTH = 78;
|
||||
|
||||
// The player's Spider Mod, whose health bars Render draws.
|
||||
constexpr int SPIDER_MOD_ITEM = 403;
|
||||
|
||||
static bool is_type(const Entity_NPC& npc, int type, int variant)
|
||||
{
|
||||
return npc.type == type && npc.variant == variant;
|
||||
}
|
||||
|
||||
// A world position's snapped place on screen, shifted by offset.
|
||||
static Vector npc_screen_position(const Vector& world, const Vector& offset)
|
||||
{
|
||||
return vector_add(render_position_get(world, RENDER_SNAPPED), offset);
|
||||
}
|
||||
|
||||
// The speed its jump height moves at for the half step, for the enemies whose AI keeps one: Wormwood's, Singe's ball's
|
||||
// and Big Bony's bone's in v1, and the Needle's, Fissure's and Festering Guts's while jumping.
|
||||
static const float* npc_height_speed(Entity_NPC& npc)
|
||||
{
|
||||
if (is_type(npc, ENTITY_PIN, WORMWOOD)) return &npc.v1.x;
|
||||
if (is_type(npc, ENTITY_SINGE, SINGE_BALL_VARIANT) || is_type(npc, ENTITY_BIG_BONY, BIG_BONY_BONE)) return &npc.v1.y;
|
||||
|
||||
bool isJumper = npc.type == ENTITY_NEEDLE || npc.type == ENTITY_FISSURE || is_type(npc, ENTITY_GUTTED_FATTY, FESTERING_GUTS);
|
||||
return isJumper && npc.state == NPC_STATE_JUMP ? &npc.v1.x : nullptr;
|
||||
}
|
||||
|
||||
// 006d2b50 Moves it the interpolation's half step (a minecart along its rail), runs its AI's interpolation call, moves
|
||||
// the effect it aims with, raises a jumping enemy by half its height speed, and points a paired Heart at its Mask.
|
||||
void Entity_NPC::Interpolate()
|
||||
{
|
||||
if (pauseTimer != 0) return;
|
||||
if (type == ENTITY_MINECART) minecart_interpolate(*this);
|
||||
else Entity::Interpolate();
|
||||
if (aiCallFlags & AI_CALL_INTERPOLATE) ai_call(AI_PHASE_INTERPOLATE);
|
||||
UpdateChildEffectPosition(true);
|
||||
|
||||
bool isHeld = HasEntityFlags(FLAG_FREEZE | FLAG_HELD) || holdCountdown > 0;
|
||||
bool isStill = isHeld || state == NPC_STATE_APPEAR || state == NPC_STATE_DEATH || state == NPC_STATE_UNIQUE_DEATH;
|
||||
const float* heightSpeed = isStill ? nullptr : npc_height_speed(*this);
|
||||
if (heightSpeed) posOffset.y = *heightSpeed * speedMultiplier / 2 + posOffset.y;
|
||||
|
||||
Entity* partner = entityRef;
|
||||
if (!is_type(*this, ENTITY_HEART, HEART_PAIRED) || !partner || !partner->IsEnemy()) return;
|
||||
targetPosition = vector_sub(partner->pos, pos);
|
||||
partner->targetPosition = vector_scale(targetPosition, -1);
|
||||
}
|
||||
|
||||
// 0054f670 NpcHelper::needle_render: while the Needle leaps, places its two trailing segments along its trail (a
|
||||
// point every 15 units, counting height) and hides each one sunk below the floor.
|
||||
static void needle_render(Entity_NPC& npc)
|
||||
{
|
||||
if (npc.state != NPC_STATE_JUMP || npc.sprite.layerStates.size() <= NEEDLE_SEGMENTS) return;
|
||||
|
||||
std::array<Vector, NEEDLE_SEGMENTS> points{};
|
||||
std::array<float, NEEDLE_SEGMENTS> heights{};
|
||||
Vector previous = npc.pos;
|
||||
float previousHeight = npc.v1.y;
|
||||
float spacing = NEEDLE_SEGMENT_SPACING;
|
||||
int count = 0;
|
||||
|
||||
for (size_t i = 0; i < npc.vectorDeque1.size() && count < NEEDLE_SEGMENTS;)
|
||||
{
|
||||
Vector delta = vector_sub(npc.vectorDeque1[i], previous);
|
||||
float rise = npc.vectorDeque2[i].y - previousHeight;
|
||||
float distance = std::sqrt(delta.x * delta.x + delta.y * delta.y + rise * rise);
|
||||
spacing -= distance;
|
||||
if (spacing > 0)
|
||||
{
|
||||
previous = npc.vectorDeque1[i];
|
||||
previousHeight = npc.vectorDeque2[i].y;
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
float t = (distance + spacing) / distance;
|
||||
previous = vector_add(previous, vector_scale(delta, t));
|
||||
previousHeight += rise * t;
|
||||
points[count] = previous;
|
||||
heights[count] = previousHeight;
|
||||
count++;
|
||||
spacing = NEEDLE_SEGMENT_SPACING;
|
||||
if (i == 0) i++;
|
||||
}
|
||||
for (; count < NEEDLE_SEGMENTS; count++)
|
||||
{
|
||||
points[count] = previous;
|
||||
heights[count] = previousHeight;
|
||||
}
|
||||
|
||||
bool isReflected = g_game->room->entityList.renderMode == RENDER_WATER_REFLECT;
|
||||
float lift = isReflected ? -npc.posOffset.y : npc.posOffset.y;
|
||||
for (int segment = 0; segment < NEEDLE_SEGMENTS; segment++)
|
||||
{
|
||||
LayerState* layer = npc.sprite.GetLayer(segment + 1);
|
||||
Vector shift = vector_make(points[segment].x - npc.pos.x, points[segment].y - npc.pos.y + heights[segment] - lift);
|
||||
layer->pos = vector_scale(shift, NPC_SCREEN_SCALE);
|
||||
layer->isVisible = heights[segment] <= NEEDLE_HIDE_DEPTH - (float)(segment + 1) * NEEDLE_HIDE_STEP;
|
||||
}
|
||||
}
|
||||
|
||||
// The wraith's alpha in the mirror world's Downpour II: seen only in the other pass than the one it lives in, faintly
|
||||
// where no water reflects it, brighter in lightning.
|
||||
static float wraith_alpha_get(RenderMode renderMode)
|
||||
{
|
||||
Game& game = *g_game;
|
||||
bool isMirrorStage = game.stage == STAGE_BASEMENT_II ||
|
||||
(game.stage == STAGE_BASEMENT_I && (game.GetCurses() & CURSE_OF_LABYRINTH));
|
||||
bool isMirror = game.currentDimensionIdx == 1 &&
|
||||
(game.stageType == STAGETYPE_REPENTANCE || game.stageType == STAGETYPE_REPENTANCE_B) && isMirrorStage;
|
||||
if ((renderMode != RENDER_WATER_REFLECT) == isMirror) return 1;
|
||||
|
||||
bool isDry = game.room->waterAmount <= 0 || !g_manager->optionsConfig.render.isWaterSurfaceEnabled;
|
||||
float alpha = isDry ? WRAITH_DRY_ALPHA : 0;
|
||||
if (game.lightningIntensity > 0) alpha = std::min(std::max(game.lightningIntensity + alpha, alpha), 1.0f);
|
||||
return alpha;
|
||||
}
|
||||
|
||||
// The Lamb's dash: afterimages trailing back along its velocity, fading out, then a faint copy over it.
|
||||
static void lamb_afterimages_render(Entity_NPC& npc, const Vector& offset)
|
||||
{
|
||||
Vector step = vector_scale(npc.velocity, -LAMB_AFTERIMAGE_REACH / LAMB_AFTERIMAGES);
|
||||
Vector at = npc.pos;
|
||||
ColorMod color = npc.sprite.color;
|
||||
|
||||
for (int i = LAMB_AFTERIMAGES - 1; i >= 0; i--)
|
||||
{
|
||||
float fade = (float)i * LAMB_AFTERIMAGE_FADE / LAMB_AFTERIMAGES + LAMB_AFTERIMAGE_BASE;
|
||||
npc.sprite.color = {{fade * color._tint[0], fade * color._tint[1], fade * color._tint[2],
|
||||
fade * color._tint[3] / 2},
|
||||
{},
|
||||
{}};
|
||||
npc.sprite.Render(SpriteDraw{npc_screen_position(vector_add(at, npc.posOffset), offset), {}, {}});
|
||||
at = vector_add(at, step);
|
||||
}
|
||||
|
||||
npc.sprite.color = {{color._tint[0], color._tint[1], color._tint[2], color._tint[3] * LAMB_COPY_ALPHA}, {}, {}};
|
||||
npc.sprite.Render(SpriteDraw{npc_screen_position(vector_add(npc.pos, npc.posOffset), offset), {}, {}});
|
||||
npc.sprite.color = color;
|
||||
}
|
||||
|
||||
// The players riding a minecart, nearest the back first, each drawn where it sits in the cart.
|
||||
static void minecart_riders_render(Entity_NPC& cart, const Vector& offset)
|
||||
{
|
||||
std::map<float, Entity_Player*> riders;
|
||||
|
||||
for (Entity_Player* player : g_game->playerManager.playerList)
|
||||
if (player->minecart == &cart) riders.emplace(player->minecartOffset.y, player);
|
||||
for (auto& [depth, player] : riders)
|
||||
{
|
||||
Vector standing = player->pos;
|
||||
player->pos = vector_add(cart.pos, player->minecartOffset);
|
||||
player->isVisible = true;
|
||||
player->Render(vector_add(offset, vector_scale(player->minecartOffset, NPC_SCREEN_SCALE)));
|
||||
player->pos = standing;
|
||||
player->isVisible = false;
|
||||
}
|
||||
}
|
||||
|
||||
// The entity a poop carries, drawn where the poop is.
|
||||
static void poop_rider_render(Entity_NPC& npc, const Vector& offset)
|
||||
{
|
||||
Entity* rider = npc.entityRef;
|
||||
Vector shift = vector_sub(vector_add(npc.pos, npc.posOffset), vector_add(rider->pos, rider->posOffset));
|
||||
|
||||
rider->isVisible = true;
|
||||
rider->Render(vector_add(offset, vector_scale(shift, NPC_SCREEN_SCALE)));
|
||||
rider->isVisible = false;
|
||||
}
|
||||
|
||||
// The entity Big Horn's hand or a Polty holds, drawn on its Item null.
|
||||
static void held_entity_render(Entity_NPC& npc)
|
||||
{
|
||||
Entity* held = npc.entityRef;
|
||||
const NullFrame* frame = npc.sprite.animState.animData ? npc.sprite.GetNullFrame("Item") : nullptr;
|
||||
if (!held || !frame || !frame->isVisible) return;
|
||||
|
||||
Vector savedOffset = held->sprite.offset;
|
||||
Vector savedScale = held->sprite.scale;
|
||||
float drop = held->type == ENTITY_PICKUP ? HELD_PICKUP_DROP : 0;
|
||||
held->sprite.offset = vector_make(frame->pos.x, drop + frame->pos.y);
|
||||
held->sprite.scale = vector_make(savedScale.x * frame->scale.x, savedScale.y * frame->scale.y);
|
||||
held->sprite.Render(SpriteDraw{npc.renderPosition, {}, {}});
|
||||
held->sprite.offset = savedOffset;
|
||||
held->sprite.scale = savedScale;
|
||||
}
|
||||
|
||||
// The drawing of the bosses and enemies with their own (Entity::Render for the rest), between the chain or link
|
||||
// drawn behind them and the one drawn in front.
|
||||
static void npc_body_render(Entity_NPC& npc, const Vector& offset)
|
||||
{
|
||||
bool isChained = npc.type == ENTITY_BALL_AND_CHAIN && !vector_is_zero(npc.targetPosition);
|
||||
if (npc.type == ENTITY_BALL_AND_CHAIN && !isChained) return npc.Entity::Render(offset);
|
||||
if (isChained && npc.pos.y > npc.targetPosition.y)
|
||||
reconstruction_missing("NpcHelper::ball_and_chain_render_chain 004f5f20");
|
||||
if (npc.type == ENTITY_POOP && npc.entityRef && npc.isVisible) poop_rider_render(npc, offset);
|
||||
|
||||
switch (npc.type)
|
||||
{
|
||||
case ENTITY_PEEPER_FATTY:
|
||||
return reconstruction_missing("Entity_NPC::Render 006d2e50: the Peeping Fatty's eyes (005579b0)");
|
||||
case ENTITY_EVIS:
|
||||
return reconstruction_missing("Entity_NPC::Render 006d2e50: Evis's cord (004e07a0)");
|
||||
case ENTITY_HORNFEL:
|
||||
return reconstruction_missing("Entity_NPC::Render 006d2e50: Hornfel's drawing");
|
||||
case ENTITY_SCOURGE:
|
||||
if (npc.variant != SCOURGE_CHAIN) return npc.Entity::Render(offset);
|
||||
return reconstruction_missing("Entity_NPC::Render 006d2e50: the Scourge's chain (00589de0)");
|
||||
case ENTITY_MOTHER:
|
||||
return reconstruction_missing("NpcHelper::mother_render 0056fcf0");
|
||||
case ENTITY_HORNY_BOYS:
|
||||
return reconstruction_missing("NpcHelper::horny_boys_render 004bcfd0");
|
||||
case ENTITY_CLUTCH:
|
||||
return reconstruction_missing("NpcHelper::clutch_render 00575a10");
|
||||
case ENTITY_BEAST:
|
||||
return reconstruction_missing("Entity_NPC::Render 006d2e50: the Beast's drawing (00598260)");
|
||||
case ENTITY_MINECART:
|
||||
if (npc.variant == RIDDEN_MINECART) return minecart_riders_render(npc, offset);
|
||||
return npc.Entity::Render(offset);
|
||||
default:
|
||||
return npc.Entity::Render(offset);
|
||||
}
|
||||
}
|
||||
|
||||
// The links and overlays drawn in front of its body: the Vis Fatty's overlay, the chain and the Shell's link when it
|
||||
// lies above them, and the Chimera's other half.
|
||||
static void npc_front_render(Entity_NPC& npc, const Vector& offset)
|
||||
{
|
||||
if (npc.type == ENTITY_VIS_FATTY) npc.render_overlay(offset, false);
|
||||
if (npc.type == ENTITY_BALL_AND_CHAIN && !vector_is_zero(npc.targetPosition) && npc.pos.y <= npc.targetPosition.y)
|
||||
reconstruction_missing("NpcHelper::ball_and_chain_render_chain 004f5f20");
|
||||
if (is_type(npc, ENTITY_LARRYJR, SHELL) && npc.child && npc.pos.y <= npc.child->pos.y)
|
||||
npc.RenderSegmentLink(offset, false);
|
||||
if (npc.type == ENTITY_CHIMERA) reconstruction_missing("NpcHelper::chimera_render_child 004a1000");
|
||||
}
|
||||
|
||||
// Whether a local player controls it.
|
||||
static bool npc_is_locally_controlled(Entity_NPC& npc)
|
||||
{
|
||||
NetplayManager& netplay = g_manager->netplayManager;
|
||||
return npc.controllerID != -1 && (!netplay.is_online() || netplay.IsIdxLocalPlayer(npc.controllerID));
|
||||
}
|
||||
|
||||
// Whether a health bar shows over it: Spider Mod's over a hurtable enemy with its OverlayEffect null shown, or the bar
|
||||
// of a local player's controlled enemy.
|
||||
static bool npc_is_health_bar_shown(Entity_NPC& npc)
|
||||
{
|
||||
bool isSpiderMod = g_game->playerManager.FirstCollectibleOwner(SPIDER_MOD_ITEM, LAZARUS_SHARE_CHECK) && npc.isVisible &&
|
||||
npc.IsActiveEnemy(DEAD_EXCLUDED) && !npc.HasEntityFlags(FLAG_NO_TARGET) &&
|
||||
npc.sprite.color._tint[3] > 0 && g_game->frameCount - npc.spawnFrame >= SPAWN_BAR_DELAY &&
|
||||
npc.health > 0 && npc.GetStatusEffectTarget() == &npc && !npc.HasEntityFlags(FLAG_HIDE_HP_BAR);
|
||||
if (isSpiderMod)
|
||||
{
|
||||
const NullFrame* frame = npc.sprite.GetNullFrame("OverlayEffect");
|
||||
return frame && frame->isVisible;
|
||||
}
|
||||
return npc_is_locally_controlled(npc);
|
||||
}
|
||||
|
||||
// 006d2e50 Draws it: hidden in the wrong pass or tinted, on its minecart, with a special body for some bosses, the
|
||||
// size pulse, the Lamb's afterimages, and the links in front, then what it holds, its status effect, a health bar
|
||||
// and its controller's charge bar.
|
||||
void Entity_NPC::Render(const Vector& offset)
|
||||
{
|
||||
if (is_type(*this, ENTITY_MINECART, 0) && child) return;
|
||||
|
||||
RenderMode renderMode = g_game->room->entityList.renderMode;
|
||||
Entity_NPC* cart = is_type(*this, ENTITY_MINECART, RIDDEN_MINECART) ? this : static_cast<Entity_NPC*>(minecart.get());
|
||||
Vector base = offset;
|
||||
Vector cartPosition{};
|
||||
float alpha = type == ENTITY_WRAITH && !is_type(*this, ENTITY_MINECART, RIDDEN_MINECART) ? wraith_alpha_get(renderMode) : 1;
|
||||
bool isHidden = alpha == 0;
|
||||
|
||||
if (type == ENTITY_NEEDLE) needle_render(*this);
|
||||
if (type == ENTITY_FISSURE) render_v1_layer_frames();
|
||||
if (type == ENTITY_NEEDLE || type == ENTITY_FISSURE) isHidden = !sprite.GetLayer(0)->isVisible;
|
||||
if (type == ENTITY_SMALL_LEECH && posOffset.y > SMALL_LEECH_SURFACE && !HasEntityFlags(FLAG_HELD) &&
|
||||
renderMode == RENDER_WATER_ABOVE)
|
||||
alpha = 0;
|
||||
|
||||
if (cart && isVisible)
|
||||
{
|
||||
const NullFrame* frame = cart->sprite.animState.animData ? cart->sprite.animState.GetNullFrameById(0) : nullptr;
|
||||
if (frame)
|
||||
{
|
||||
cartPosition = npc_screen_position(pos, offset);
|
||||
base = vector_add(base, frame->pos);
|
||||
cart->sprite.RenderLayer(0, SpriteDraw{cartPosition, {}, {}});
|
||||
}
|
||||
alpha *= cart->sprite.color._tint[3];
|
||||
}
|
||||
if (spawnerEntity && spawnerEntity->type == ENTITY_PLAYER && g_manager->netplayManager.is_online())
|
||||
reconstruction_missing("Entity_NPC::Render 006d2e50: a remote player's faded enemy");
|
||||
|
||||
Vector savedScale = sprite.scale;
|
||||
float savedAlpha = sprite.color._tint[3];
|
||||
if (alpha > 0)
|
||||
{
|
||||
sprite.color._tint[3] = savedAlpha * alpha;
|
||||
if (championColorIdx == CHAMPION_SIZE_PULSE)
|
||||
{
|
||||
float swell = std::clamp(std::sin((float)g_game->room->GetFrameCount() * SIZE_PULSE_SPEED), 0.0f, 1.0f);
|
||||
sprite.scale = vector_scale(savedScale, swell * SIZE_PULSE_SWELL + 1);
|
||||
}
|
||||
if (type == ENTITY_THE_LAMB && state == LAMB_DASH_STATE)
|
||||
{
|
||||
if (!isExists || !isVisible) return;
|
||||
lamb_afterimages_render(*this, base);
|
||||
}
|
||||
if (is_type(*this, ENTITY_LARRYJR, SHELL) && child && child->pos.y < pos.y) RenderSegmentLink(base, false);
|
||||
if (is_type(*this, ENTITY_DOGMA, 0)) render_overlay(base, false);
|
||||
npc_body_render(*this, base);
|
||||
npc_front_render(*this, base);
|
||||
}
|
||||
|
||||
if (!isVisible || alpha <= 0) renderPosition = npc_screen_position(vector_add(pos, posOffset), base);
|
||||
if ((type == ENTITY_BIG_HORN || type == ENTITY_POLTY) && entityRef) held_entity_render(*this);
|
||||
if (alpha > 0)
|
||||
{
|
||||
if (championColorIdx == CHAMPION_SIZE_PULSE) sprite.scale = savedScale;
|
||||
sprite.color._tint[3] = savedAlpha;
|
||||
}
|
||||
lua_engine_get().PostNPCRender(this, base);
|
||||
|
||||
bool isMainPass = renderMode == RENDER_NORMAL || renderMode == RENDER_WATER_ABOVE;
|
||||
if (isMainPass && !isHidden)
|
||||
{
|
||||
if (type == ENTITY_DUMMY) reconstruction_missing("Entity_NPC::Render 006d2e50: the dummy's damage text");
|
||||
status_overlay_render(base);
|
||||
if (npc_is_health_bar_shown(*this))
|
||||
{
|
||||
float barPosition[2] = {renderPosition.x, renderPosition.y + HEALTH_BAR_DROP};
|
||||
render_debug(barPosition, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (cart && isVisible)
|
||||
{
|
||||
cart->sprite.RenderLayer(1, SpriteDraw{cartPosition, {}, {}});
|
||||
if (type == ENTITY_HORNFEL) reconstruction_missing("NpcHelper::hornfel_render_minecart 004b7c30");
|
||||
}
|
||||
if (npc_is_locally_controlled(*this) && chargeBarSprite.isLoaded && chargeBarSprite.color._tint[3] > 0)
|
||||
{
|
||||
Vector at = vector_make(sprite.scale.y * 12 + renderPosition.x, renderPosition.y - sprite.scale.y * 35);
|
||||
chargeBarSprite.Render(SpriteDraw{at, {}, {}});
|
||||
}
|
||||
if (HasEntityFlags(FLAG_PERSISTENT | FLAG_DELIRIUM_FORM) && (g_game->debugFlags & NPC_DEBUG_HEALTH_FLAG))
|
||||
reconstruction_missing("Entity_NPC::Render 006d2e50: the debug health text");
|
||||
}
|
||||
|
||||
// The fade of a Fissure layer at a depth: gone above the floor, or below it in the reflection.
|
||||
static float fissure_alpha(float height, bool isReflected)
|
||||
{
|
||||
float start = isReflected ? FISSURE_REFLECT_FADE_START : FISSURE_FADE_START;
|
||||
float length = isReflected ? FISSURE_REFLECT_FADE_LENGTH : FISSURE_FADE_LENGTH;
|
||||
return 1 - std::clamp((height - start) / length, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
// 00565680 The Fissure's head frame by its turn (v1.x), its two segments raised to the heights its trail recorded,
|
||||
// the far one turned to its side, and each layer faded by its depth.
|
||||
void Entity_NPC::render_v1_layer_frames()
|
||||
{
|
||||
int frame = v1.x < 0 ? 1 : (v1.x <= FISSURE_TURN ? 0 : 2);
|
||||
if (sprite.animState.animData) sprite.animState.SetLayerFrame(0, frame);
|
||||
|
||||
float headHeight = posOffset.y;
|
||||
float nearHeight = headHeight;
|
||||
float farHeight = headHeight;
|
||||
LayerState* farLayer = sprite.GetLayer(2);
|
||||
if (vectorDeque1.size() > 1)
|
||||
{
|
||||
farLayer->pos = vector_make(0, (vectorDeque1[1].y - v1.y) * NPC_SCREEN_SCALE);
|
||||
sprite.GetLayer(1)->pos = farLayer->pos;
|
||||
nearHeight = vectorDeque1[1].y + posOffset.y - v1.y;
|
||||
farHeight = nearHeight;
|
||||
}
|
||||
if (vectorDeque1.size() > 2)
|
||||
{
|
||||
const Vector& far = vectorDeque1[2];
|
||||
farLayer->pos = vector_make(far.x <= 0 ? FISSURE_NUDGE : -FISSURE_NUDGE, (far.y - v1.y) * NPC_SCREEN_SCALE);
|
||||
farLayer->isFlipY = vectorDeque1[1].y < far.y;
|
||||
farLayer->isFlipX = far.x > 0;
|
||||
farHeight = far.y + posOffset.y - v1.y;
|
||||
}
|
||||
|
||||
bool isReflected = g_game->room->entityList.renderMode == RENDER_WATER_REFLECT;
|
||||
sprite.GetLayer(0)->color._tint[3] = fissure_alpha(headHeight, isReflected);
|
||||
sprite.GetLayer(1)->color._tint[3] = fissure_alpha(nearHeight, isReflected);
|
||||
farLayer->color._tint[3] = fissure_alpha(farHeight, isReflected);
|
||||
}
|
||||
@@ -0,0 +1,344 @@
|
||||
#include "boss_ai.h"
|
||||
#include "entity_effect_combat.h"
|
||||
#include "entity_familiar.h"
|
||||
#include "entity_pickup.h"
|
||||
#include "entity_player.h"
|
||||
#include "item_config.h"
|
||||
#include "item_pool.h"
|
||||
#include "manager.h"
|
||||
#include "room_descriptor.h"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
// The Cultist's variant that gives no kill rewards, as the fireplace, the shopkeeper, movable TNT, props, minecarts and
|
||||
// poop do not.
|
||||
constexpr int CULTIST_BLOOD_VARIANT = 10;
|
||||
constexpr int TEAR_SHARP_KEY = 43;
|
||||
constexpr int TEAR_SHARP_KEY_SPECTRAL = 44;
|
||||
|
||||
// Gimpy's half heart: one in a hundred kills of a weak enemy, one in twenty of a sturdier one, one in ten of a strong
|
||||
// one (twice as likely for a champion's reward), one in ten again under Daemon's Tail.
|
||||
constexpr float EXORCIST_ROOM_MARGIN = -10;
|
||||
constexpr int EFFECT_HUNGRY_SOUL = 186;
|
||||
constexpr float GIMPY_WEAK_HEALTH = 10;
|
||||
constexpr float GIMPY_STRONG_HEALTH = 30;
|
||||
constexpr uint32_t GIMPY_WEAK_ODDS = 100;
|
||||
constexpr uint32_t GIMPY_ODDS = 20;
|
||||
constexpr uint32_t GIMPY_STRONG_ODDS = 10;
|
||||
constexpr uint32_t GIMPY_DAEMONS_TAIL_ODDS = 10;
|
||||
|
||||
// Sharp Key's chest: one kill in ten by its keys opens one at once.
|
||||
constexpr std::array<uint32_t, 3> SHARP_KEY_SHIFTS = {2, 21, 9};
|
||||
constexpr uint32_t SHARP_KEY_ODDS = 10;
|
||||
constexpr int LEECH_HEAL = 1;
|
||||
constexpr float LEECH_HEART_RISE = -24;
|
||||
constexpr int GUPPYS_HAIRBALL_SIZES = 4;
|
||||
constexpr int BLOOD_PUPPY_BOSS_COINS = 4;
|
||||
|
||||
// Bone Spurs' spurs: two from a sturdy enemy half the time, thrown out at five, the second at three to five.
|
||||
constexpr std::array<uint32_t, 3> BONE_SPURS_SHIFTS = {6, 17, 9};
|
||||
constexpr float BONE_SPURS_HEALTH = 8;
|
||||
constexpr float BONE_SPUR_SPEED = 5;
|
||||
constexpr float BONE_SPUR_SPEED_MIN = 3;
|
||||
constexpr float BONE_SPUR_LEAD = 0.25f;
|
||||
constexpr int BONE_PARTICLE_VARIANT = 35;
|
||||
constexpr int BONE_SPUR_PARTICLES = 8;
|
||||
constexpr float BONE_PARTICLE_SPEED = 2;
|
||||
constexpr float BONE_PARTICLE_SPEED_RANGE = 3;
|
||||
constexpr float BONE_BREAK_VOLUME = 0.7f;
|
||||
constexpr float BONE_BREAK_PITCH_RANGE = 0.2f;
|
||||
|
||||
// Cantripped: one kill in five drops a card.
|
||||
constexpr uint32_t CANTRIPPED_ODDS = 5;
|
||||
constexpr float CANTRIPPED_CARD_SPEED = 3;
|
||||
|
||||
// Tainted Magdalene's (or a Yum Heart blessing's) half hearts and Tainted Keeper's coins: thrown at two to five, gone
|
||||
// in two seconds, three for a boss's coins. A champion gives two coins, a boss more by its health and the floor, a room
|
||||
// coming back fewer (one, ever less likely, up to ten).
|
||||
constexpr std::array<uint32_t, 3> MAGDALENE_HEART_SHIFTS = {7, 17, 21};
|
||||
constexpr std::array<uint32_t, 3> KEEPER_COIN_SHIFTS = {9, 11, 19};
|
||||
constexpr std::array<uint32_t, 3> KEEPER_REVISIT_SHIFTS = {13, 5, 19};
|
||||
constexpr int NULL_ITEM_TEMPORARY_HEARTS = 114;
|
||||
constexpr float DROP_SPEED_MIN = 2;
|
||||
constexpr float DROP_SPEED_RANGE = 3;
|
||||
constexpr int DROP_TIMEOUT = 60;
|
||||
constexpr int BOSS_COIN_TIMEOUT = 90;
|
||||
constexpr int KEEPER_ROOM_COINS = 8;
|
||||
constexpr int KEEPER_REVISIT_LIMIT = 9;
|
||||
constexpr float KEEPER_BOSS_HEALTH_BASE = 38;
|
||||
constexpr float KEEPER_BOSS_HEALTH_STEP = 10;
|
||||
|
||||
// The floor a boss's coins count by: one more on an alt floor.
|
||||
static int reward_stage_get()
|
||||
{
|
||||
Game& game = *g_game;
|
||||
bool isAlt = game.stageType == STAGETYPE_REPENTANCE || game.stageType == STAGETYPE_REPENTANCE_B;
|
||||
return (int)game.stage + (isAlt ? 1 : 0);
|
||||
}
|
||||
|
||||
// A pickup thrown out of the dead enemy in a random direction at two to five, gone after a while.
|
||||
static void reward_pickup_throw(Entity_NPC& npc, const EntitySpawn& spawn, int timeout)
|
||||
{
|
||||
float angle = random_unit() * RANDOM_HALF_TURN;
|
||||
angle += angle;
|
||||
float sine = std::sin(angle);
|
||||
float speed = random_unit() * DROP_SPEED_RANGE + DROP_SPEED_MIN;
|
||||
EntitySpawn thrown = spawn;
|
||||
thrown.position = npc.pos;
|
||||
thrown.velocity = vector_make(std::cos(angle) * speed, sine * speed);
|
||||
thrown.spawner = &npc;
|
||||
thrown.type = ENTITY_PICKUP;
|
||||
auto* pickup = static_cast<Entity_Pickup*>(g_game->Spawn(thrown));
|
||||
pickup->timeout = timeout;
|
||||
pickup->Update();
|
||||
}
|
||||
|
||||
// Whether a kill came from a familiar of a variant (or an effect, for Hungry Soul's soul).
|
||||
static bool is_killed_by(Entity_NPC& npc, int type, int variant)
|
||||
{
|
||||
return std::ranges::any_of(npc.killDamageEvents, [&](const DamageEvent& event)
|
||||
{ return event.source.type == type && event.source.variant == variant; });
|
||||
}
|
||||
|
||||
// What the damage flags of the killing hit drop: a red heart, a coin, a black heart, a card or a rune.
|
||||
static void kill_flag_drops(Entity_NPC& npc)
|
||||
{
|
||||
uint64_t flags = npc.killDamageFlags;
|
||||
auto drop = [&](int variant, int subType)
|
||||
{
|
||||
g_game->Spawn(
|
||||
{.position = npc.pos, .subType = subType, .type = ENTITY_PICKUP, .variant = variant, .seed = Random()});
|
||||
};
|
||||
if (flags & DAMAGE_SPAWN_RED_HEART) drop(PICKUP_HEART, HEART_FULL);
|
||||
if (flags & DAMAGE_SPAWN_COIN) drop(PICKUP_COIN, 0);
|
||||
if (flags & DAMAGE_SPAWN_BLACK_HEART) drop(PICKUP_HEART, HEART_BLACK);
|
||||
if (flags & DAMAGE_SPAWN_CARD) drop(PICKUP_TAROTCARD, ItemPool::GetCardEx((int)npc.dropRNG.Next(), 0, 0, 0, false));
|
||||
if (flags & DAMAGE_SPAWN_RUNE)
|
||||
drop(PICKUP_TAROTCARD, ItemPool::GetCardEx((int)npc.dropRNG.Next(), 0, -1, 0, false));
|
||||
}
|
||||
|
||||
// What the killing hits' sources do: a Leech heals its player, a Blood Puppy grows, Guppy's Hairball grows, and one
|
||||
// Sharp Key kill in ten opens a chest at once.
|
||||
static void kill_source_rewards(Entity_NPC& npc)
|
||||
{
|
||||
for (const DamageEvent& event : npc.killDamageEvents)
|
||||
{
|
||||
Entity* source = event.source.entity;
|
||||
if (event.source.type == ENTITY_FAMILIAR && source && source->type == ENTITY_FAMILIAR)
|
||||
{
|
||||
auto& familiar = static_cast<Entity_Familiar&>(*source);
|
||||
if (event.source.variant == Entity_Familiar::LEECH)
|
||||
{
|
||||
Entity_Player* player = familiar.player;
|
||||
if (g_game->deathmatchManager.is_active() || !player || player->isDead) continue;
|
||||
player->AddHearts(LEECH_HEAL, false, false);
|
||||
Entity* heart = g_game->Spawn(
|
||||
{.position = player->pos, .type = ENTITY_EFFECT, .variant = EFFECT_HEART, .seed = Random()});
|
||||
heart->sprite.offset = vector_make(0, LEECH_HEART_RISE);
|
||||
heart->renderDepthOffset = 1;
|
||||
}
|
||||
else if (event.source.variant == Entity_Familiar::BLOOD_PUPPY)
|
||||
familiar.AddCoins(npc.IsBoss() ? BLOOD_PUPPY_BOSS_COINS : 1);
|
||||
else if (event.source.variant == Entity_Familiar::GUPPYS_HAIRBALL)
|
||||
familiar.subtype = std::min(familiar.subtype + 1, GUPPYS_HAIRBALL_SIZES);
|
||||
continue;
|
||||
}
|
||||
if (event.source.type == ENTITY_BLOOD_PUPPY)
|
||||
reconstruction_missing("Entity_NPC::trigger_death_rewards 006bbdc0: a Blood Puppy's feeding");
|
||||
|
||||
bool isSharpKey = event.source.type == ENTITY_TEAR &&
|
||||
(event.source.variant == TEAR_SHARP_KEY || event.source.variant == TEAR_SHARP_KEY_SPECTRAL);
|
||||
if (!isSharpKey) continue;
|
||||
RNG rng = {npc.initSeed, SHARP_KEY_SHIFTS[0], SHARP_KEY_SHIFTS[1], SHARP_KEY_SHIFTS[2]};
|
||||
rng.Next();
|
||||
rng.Next();
|
||||
if (rng.Next() % SHARP_KEY_ODDS != 0 || !source) continue;
|
||||
|
||||
Entity* spawner = source->spawnerEntity;
|
||||
Entity_Player* player = spawner && spawner->type == ENTITY_PLAYER ? spawner->ToPlayer() : nullptr;
|
||||
auto* chest = static_cast<Entity_Pickup*>(
|
||||
g_game->Spawn({.position = npc.pos, .type = ENTITY_PICKUP, .variant = PICKUP_CHEST, .seed = rng.Next()}));
|
||||
chest->TryOpenChest(player);
|
||||
if (Entity_Pickup::IsChest(chest->variant)) chest->Remove();
|
||||
}
|
||||
}
|
||||
|
||||
// Bone Spurs' spurs fly out of a kill not made by a spur, with a burst of bone and a crack.
|
||||
static void bone_spurs_spawn(Entity_NPC& npc, Entity_Player& owner)
|
||||
{
|
||||
int count = 1;
|
||||
if (npc.maxHitPoints > BONE_SPURS_HEALTH)
|
||||
{
|
||||
RNG rng = {npc.initSeed, BONE_SPURS_SHIFTS[0], BONE_SPURS_SHIFTS[1], BONE_SPURS_SHIFTS[2]};
|
||||
if ((rng.Next() & 1) == 0) count = 2;
|
||||
}
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
float angle = random_unit() * RANDOM_HALF_TURN;
|
||||
angle += angle;
|
||||
float sine = std::sin(angle);
|
||||
float push = random_unit() + 1;
|
||||
Vector velocity = vector_make(std::cos(angle) * push + npc.velocity.x, push * sine + npc.velocity.y);
|
||||
float speed = i == 0 ? BONE_SPUR_SPEED : random_unit() * 2 + BONE_SPUR_SPEED_MIN;
|
||||
velocity = vector_resized(velocity, speed);
|
||||
Entity* spur = g_game->Spawn({.position = vector_add(vector_scale(velocity, BONE_SPUR_LEAD), npc.pos),
|
||||
.velocity = velocity,
|
||||
.spawner = &owner,
|
||||
.type = ENTITY_FAMILIAR,
|
||||
.variant = Entity_Familiar::BONE_SPUR,
|
||||
.seed = Random()});
|
||||
spur->ClearEntityFlags(FLAG_APPEAR);
|
||||
spur->Update();
|
||||
}
|
||||
game_particles_spawn({.position = npc.pos,
|
||||
.height = npc.posOffset.y,
|
||||
.speed = random_unit() * BONE_PARTICLE_SPEED_RANGE + BONE_PARTICLE_SPEED,
|
||||
.count = BONE_SPUR_PARTICLES,
|
||||
.variant = BONE_PARTICLE_VARIANT});
|
||||
npc_sound_play(SOUND_BONE_SNAP, BONE_BREAK_VOLUME, 2, random_unit() * BONE_BREAK_PITCH_RANGE + 1);
|
||||
}
|
||||
|
||||
// What the players' items and the run do with any kill: Gimpy's half hearts, the killing hit's drops and sources,
|
||||
// Infestation 2's spider, Bone Spurs' spurs, Hungry Soul's soul, Cricket's Leg and Cantripped's cards.
|
||||
static void kill_item_rewards(Entity_NPC& npc)
|
||||
{
|
||||
PlayerManager& players = g_game->playerManager;
|
||||
bool isChampionReward = npc.killDamageFlags & DAMAGE_CHAMPION_REWARD;
|
||||
uint32_t gimpyOdds = npc.maxHitPoints < GIMPY_WEAK_HEALTH ? GIMPY_WEAK_ODDS
|
||||
: npc.maxHitPoints < GIMPY_STRONG_HEALTH ? GIMPY_ODDS
|
||||
: GIMPY_STRONG_ODDS;
|
||||
if (isChampionReward) gimpyOdds /= 2;
|
||||
bool isGimpyHeart =
|
||||
players.FirstCollectibleOwner(COLLECTIBLE_GIMPY, LAZARUS_SHARE_CHECK) &&
|
||||
npc.dropRNG.RandomInt(gimpyOdds) == 0 &&
|
||||
(!players.AnyoneHasTrinket(TRINKET_DAEMONS_TAIL) || npc.dropRNG.RandomInt(GIMPY_DAEMONS_TAIL_ODDS) == 0);
|
||||
if (isGimpyHeart)
|
||||
g_game->Spawn({.position = npc.pos,
|
||||
.subType = HEART_HALF,
|
||||
.type = ENTITY_PICKUP,
|
||||
.variant = PICKUP_HEART,
|
||||
.seed = Random()});
|
||||
kill_flag_drops(npc);
|
||||
kill_source_rewards(npc);
|
||||
|
||||
if (players.RandomCollectibleOwner(COLLECTIBLE_INFESTATION_2, npc.initSeed, nullptr) &&
|
||||
!is_killed_by(npc, ENTITY_FAMILIAR, Entity_Familiar::BLUE_SPIDER))
|
||||
reconstruction_missing(
|
||||
"Entity_NPC::trigger_death_rewards 006bbdc0: Infestation 2 (spawn_blue_spider 00638e30)");
|
||||
Entity_Player* spurs = players.RandomCollectibleOwner(COLLECTIBLE_BONE_SPURS, npc.initSeed, nullptr);
|
||||
if (spurs && !is_killed_by(npc, ENTITY_FAMILIAR, Entity_Familiar::BONE_SPUR)) bone_spurs_spawn(npc, *spurs);
|
||||
if (players.RandomCollectibleOwner(COLLECTIBLE_HUNGRY_SOUL, npc.initSeed, nullptr) &&
|
||||
!is_killed_by(npc, ENTITY_EFFECT, EFFECT_HUNGRY_SOUL))
|
||||
reconstruction_missing("Entity_NPC::trigger_death_rewards 006bbdc0: Hungry Soul's soul");
|
||||
if (players.RandomTrinketOwner(TRINKET_CRICKET_LEG, npc.initSeed, nullptr))
|
||||
reconstruction_missing("Entity_NPC::trigger_death_rewards 006bbdc0: Cricket's Leg (SpawnTrinketRandomPickup)");
|
||||
|
||||
if (g_game->challenge == CHALLENGE_CANTRIPPED && npc.dropRNG.Next() % CANTRIPPED_ODDS == 0)
|
||||
{
|
||||
uint32_t seed = Random();
|
||||
float angle = random_unit() * RANDOM_HALF_TURN;
|
||||
angle += angle;
|
||||
Vector direction =
|
||||
vector_make(std::cos(angle) * CANTRIPPED_CARD_SPEED, std::sin(angle) * CANTRIPPED_CARD_SPEED);
|
||||
g_game->Spawn({.position = npc.pos,
|
||||
.velocity = vector_scale(direction, random_unit()),
|
||||
.subType = 1,
|
||||
.type = ENTITY_PICKUP,
|
||||
.variant = PICKUP_TAROTCARD,
|
||||
.seed = seed});
|
||||
}
|
||||
}
|
||||
|
||||
// Tainted Magdalene's (or a Yum Heart blessing's) half hearts: one kill in two, or every kill with the blessing or the
|
||||
// killing hit's temporary heart flag.
|
||||
static void magdalene_hearts_drop(Entity_NPC& npc)
|
||||
{
|
||||
PlayerManager& players = g_game->playerManager;
|
||||
bool isBlessed = players.HasTemporaryEffect(g_manager->itemConfig.GetNullItem(NULL_ITEM_TEMPORARY_HEARTS));
|
||||
bool isMagdalene = std::ranges::any_of(players.playerList,
|
||||
[](Entity_Player* player)
|
||||
{
|
||||
return player->variant == PLAYER_VARIANT_PLAYER &&
|
||||
!player->isCoopGhost && player->playerType == PLAYER_MAGDALENE_B;
|
||||
});
|
||||
if (!isMagdalene && !isBlessed) return;
|
||||
|
||||
RNG rng = {npc.initSeed, MAGDALENE_HEART_SHIFTS[0], MAGDALENE_HEART_SHIFTS[1], MAGDALENE_HEART_SHIFTS[2]};
|
||||
bool isDropped = (rng.Next() & 1) == 0 || (npc.killDamageFlags & DAMAGE_SPAWN_TEMP_HEART) || isBlessed;
|
||||
if (isDropped)
|
||||
reward_pickup_throw(npc, {.subType = HEART_HALF, .variant = PICKUP_HEART, .seed = rng.Next()}, DROP_TIMEOUT);
|
||||
}
|
||||
|
||||
// Tainted Keeper's coins: one from an enemy, two from a champion and more from a boss by its health, up to eight in a
|
||||
// room's first visit or ambush, else one at most and ever less often (ten per room). A champion's reward adds some.
|
||||
static void keeper_coins_drop(Entity_NPC& npc)
|
||||
{
|
||||
PlayerManager& players = g_game->playerManager;
|
||||
bool isKeeper = std::ranges::any_of(players.playerList,
|
||||
[](Entity_Player* player)
|
||||
{
|
||||
return player->variant == PLAYER_VARIANT_PLAYER && !player->isCoopGhost &&
|
||||
player->playerType == PLAYER_KEEPER_B;
|
||||
});
|
||||
if (!isKeeper) return;
|
||||
|
||||
RoomDescriptor& room = *g_game->room->descriptor;
|
||||
int limit = KEEPER_ROOM_COINS;
|
||||
if (npc.spawnGridIndex < 0 || (room.visitedCount != 1 && !npc.HasEntityFlags(FLAG_AMBUSH)))
|
||||
{
|
||||
if (room.tKeeperCoinSpawns > KEEPER_REVISIT_LIMIT) return;
|
||||
RNG revisit = {npc.initSeed, KEEPER_REVISIT_SHIFTS[0], KEEPER_REVISIT_SHIFTS[1], KEEPER_REVISIT_SHIFTS[2]};
|
||||
uint32_t odds = (uint32_t)room.tKeeperCoinSpawns + 1;
|
||||
if (revisit.Next() % odds != 0) return;
|
||||
room.tKeeperCoinSpawns++;
|
||||
limit = 1;
|
||||
}
|
||||
|
||||
int timeout = DROP_TIMEOUT;
|
||||
int count = npc.championColorIdx >= 0 ? 2 : 1;
|
||||
if (npc.IsBoss())
|
||||
{
|
||||
float health = (float)reward_stage_get() * KEEPER_BOSS_HEALTH_STEP + KEEPER_BOSS_HEALTH_BASE;
|
||||
count = std::max(1, (int)std::ceil(npc.maxHitPoints / health));
|
||||
timeout = BOSS_COIN_TIMEOUT;
|
||||
}
|
||||
count = std::min(count, limit);
|
||||
|
||||
RNG rng = {npc.initSeed, KEEPER_COIN_SHIFTS[0], KEEPER_COIN_SHIFTS[1], KEEPER_COIN_SHIFTS[2]};
|
||||
if (npc.killDamageFlags & DAMAGE_CHAMPION_REWARD) count += (int)(rng.Next() % (uint32_t)(count / 2 + 2));
|
||||
for (int i = 0; i < count; i++) reward_pickup_throw(npc, {.variant = PICKUP_COIN, .seed = rng.Next()}, timeout);
|
||||
}
|
||||
|
||||
// 006bbdc0 The rewards a dead enemy gives its killers: the damage flags' and items' drops and on-kill effects,
|
||||
// Vasculitis's tears, then
|
||||
// for an enemy that holds the doors Vade Retro's souls, Quints' familiars, Tainted Magdalene's hearts, Tainted
|
||||
// Keeper's coins and the Urn of Souls' souls.
|
||||
void Entity_NPC::trigger_death_rewards()
|
||||
{
|
||||
bool isVersusPlayer = g_game->deathmatchManager.is_active() && type == ENTITY_PLAYER;
|
||||
bool isRewarded = Entity::is_enemy_type(type) && type != ENTITY_FIREPLACE && type != ENTITY_SHOPKEEPER &&
|
||||
type != ENTITY_MOVABLE_TNT && !(type == ENTITY_CULTIST && variant == CULTIST_BLOOD_VARIANT) &&
|
||||
type != ENTITY_GENERIC_PROP && type != ENTITY_MINECART && type != ENTITY_POOP;
|
||||
if (!isRewarded && !isVersusPlayer) return;
|
||||
if (DoesEntityShareStatus() && parent && GetLastParent() != this && type != ENTITY_LARRYJR &&
|
||||
type != ENTITY_BUTTLICKER)
|
||||
return;
|
||||
|
||||
if (!HasEntityFlags(FLAG_NO_REWARD)) kill_item_rewards(*this);
|
||||
if (g_game->playerManager.FirstCollectibleOwner(COLLECTIBLE_VASCULITIS, LAZARUS_SHARE_CHECK))
|
||||
reconstruction_missing("Entity_NPC::trigger_death_rewards 006bbdc0: Vasculitis's tears");
|
||||
if (!CanShutDoors()) return;
|
||||
|
||||
Room& room = *g_game->room;
|
||||
if (room.isExorcistActive && room.IsPositionInRoom(pos, EXORCIST_ROOM_MARGIN))
|
||||
reconstruction_missing("Entity_NPC::trigger_death_rewards 006bbdc0: Vade Retro's souls");
|
||||
if (room.IsPositionInRoom(pos, EXORCIST_ROOM_MARGIN))
|
||||
for (Entity_Player* player : g_game->playerManager.playerList)
|
||||
if (player->variant == PLAYER_VARIANT_PLAYER && player->HasCollectible(COLLECTIBLE_QUINTS))
|
||||
reconstruction_missing("Entity_NPC::trigger_death_rewards 006bbdc0: Quints' familiars");
|
||||
magdalene_hearts_drop(*this);
|
||||
keeper_coins_drop(*this);
|
||||
for (Entity_Player* player : g_game->playerManager.playerList)
|
||||
if (player->variant == PLAYER_VARIANT_PLAYER && player->HasCollectible(COLLECTIBLE_URN_OF_SOULS))
|
||||
reconstruction_missing("Entity_NPC::trigger_death_rewards 006bbdc0: the Urn of Souls' souls");
|
||||
}
|
||||
+11
-26
@@ -28,25 +28,7 @@ constexpr std::array<int, 12> CHESTS = {PICKUP_CHEST, PICKUP_LOCKEDCHEST,
|
||||
// The coins a coin subtype is worth (penny, nickel, dime, double, lucky, sticky, golden), from subtype 1.
|
||||
constexpr std::array<int, 8> COIN_VALUES = {1, 1, 5, 10, 2, 1, 5, 1};
|
||||
|
||||
// The pickup subtypes the code tells apart, as Lua's HeartSubType, CoinSubType, KeySubType and BombSubType name them.
|
||||
// HeartKind (entity_player.h) holds the soul, black, golden, bone and rotten hearts.
|
||||
enum HeartSubType : int
|
||||
{
|
||||
HEART_FULL = 1,
|
||||
HEART_HALF = 2,
|
||||
HEART_ETERNAL = 4,
|
||||
HEART_DOUBLEPACK = 5,
|
||||
HEART_HALF_SOUL = 8,
|
||||
HEART_SCARED = 9,
|
||||
HEART_BLENDED = 10
|
||||
};
|
||||
enum KeySubType : int
|
||||
{
|
||||
KEY_NORMAL = 1,
|
||||
KEY_GOLDEN,
|
||||
KEY_DOUBLEPACK,
|
||||
KEY_CHARGED
|
||||
};
|
||||
// A bomb's subtypes the code tells apart, as Lua's BombSubType names them.
|
||||
enum BombSubType : int
|
||||
{
|
||||
BOMB_NORMAL = 1,
|
||||
@@ -76,7 +58,6 @@ constexpr int TRINKET_MOMS_PEARL = 38;
|
||||
constexpr int TRINKET_BLOODY_PENNY = 49;
|
||||
constexpr int TRINKET_FLAT_PENNY = 51;
|
||||
constexpr int TRINKET_SUPER_MAGNET = 68;
|
||||
constexpr int TRINKET_ROTTEN_PENNY = 126;
|
||||
constexpr int TRINKET_BLESSED_PENNY = 131;
|
||||
constexpr int TRINKET_APPLE_OF_SODOM = 140;
|
||||
constexpr int TRINKET_CHARGED_PENNY = 147;
|
||||
@@ -106,7 +87,6 @@ constexpr int ACHIEVEMENT_GOLDEN_PENNY = 613;
|
||||
constexpr int ACHIEVEMENT_GOLDEN_BATTERY = 615;
|
||||
|
||||
// The other entities and effects pickups spawn, meet and are saved with.
|
||||
constexpr int ENTITY_POLTY = 816;
|
||||
constexpr int FAMILIAR_BUM_FRIEND = 24;
|
||||
constexpr int FAMILIAR_DARK_BUM = 64;
|
||||
constexpr int FAMILIAR_BUMBO = 88;
|
||||
@@ -130,9 +110,7 @@ constexpr int POOF02_LAVA_SPLASH = 66;
|
||||
constexpr int WISP_HEALED_BY_HEARTS = 296;
|
||||
|
||||
// The sounds pickups play.
|
||||
constexpr int SOUND_CHEST_DROP = 21;
|
||||
constexpr int SOUND_KEYPICKUP_GAUNTLET = 58;
|
||||
constexpr int SOUND_KEY_DROP0 = 59;
|
||||
constexpr int SOUND_MEAT_FEET_SLOW0 = 68;
|
||||
constexpr int SOUND_DIMEDROP = 198;
|
||||
constexpr int SOUND_DIMEPICKUP = 199;
|
||||
@@ -143,7 +121,6 @@ constexpr int SOUND_NICKELDROP = 231;
|
||||
constexpr int SOUND_NICKELPICKUP = 232;
|
||||
constexpr int SOUND_PENNYDROP = 233;
|
||||
constexpr int SOUND_PENNYPICKUP = 234;
|
||||
constexpr int SOUND_SUPERHOLY = 266;
|
||||
constexpr int SOUND_PING_PONG = 458;
|
||||
constexpr int SOUND_BONE_HEART = 461;
|
||||
constexpr int SOUND_SHOVEL_DROP = 463;
|
||||
@@ -1350,7 +1327,15 @@ bool Entity_Pickup::HandleCollision(Entity* collider, bool isLow)
|
||||
variant);
|
||||
bool isGreed =
|
||||
(collider->type == ENTITY_ULTRA_GREED || collider->type == ENTITY_BUMBINO) && variant == PICKUP_COIN;
|
||||
if (isBum || isEater || isGreed)
|
||||
if (isBum && bum_pickup_collect(*static_cast<Entity_Familiar*>(collider), *this))
|
||||
{
|
||||
RemoveOtherOptions();
|
||||
g_game->scoreSheet.add_pickup_points(variant, subtype, pos);
|
||||
PlayPickupSound();
|
||||
collect_finish(nullptr);
|
||||
return true;
|
||||
}
|
||||
if (isEater || isGreed)
|
||||
reconstruction_missing("Entity_Pickup::HandleCollision 006e8ae0: a familiar or enemy collecting it");
|
||||
return g_game->room->roomType == ROOM_DUNGEON || collider->type == ENTITY_BOMB || price != 0;
|
||||
}
|
||||
@@ -1472,7 +1457,7 @@ bool Entity_Pickup::HandleCollision(Entity* collider, bool isLow)
|
||||
// and the run's note that a heart, bomb or coin was picked up.
|
||||
void Entity_Pickup::collect_finish(Entity_Player* player)
|
||||
{
|
||||
if (!player->proceduralItems.empty())
|
||||
if (player && !player->proceduralItems.empty())
|
||||
reconstruction_missing("Entity_Pickup::HandleCollision 006e8ae0: the procedural items' pickup trigger");
|
||||
|
||||
velocity = {};
|
||||
|
||||
@@ -86,6 +86,26 @@ enum CoinSubType : int
|
||||
COIN_GOLDEN
|
||||
};
|
||||
|
||||
// The heart and key subtypes the code tells apart, as Lua's HeartSubType and KeySubType name them. HeartKind
|
||||
// (entity_player.h) holds the soul, black, golden, bone and rotten hearts.
|
||||
enum HeartSubType : int
|
||||
{
|
||||
HEART_FULL = 1,
|
||||
HEART_HALF = 2,
|
||||
HEART_ETERNAL = 4,
|
||||
HEART_DOUBLEPACK = 5,
|
||||
HEART_HALF_SOUL = 8,
|
||||
HEART_SCARED = 9,
|
||||
HEART_BLENDED = 10
|
||||
};
|
||||
enum KeySubType : int
|
||||
{
|
||||
KEY_NORMAL = 1,
|
||||
KEY_GOLDEN,
|
||||
KEY_DOUBLEPACK,
|
||||
KEY_CHARGED
|
||||
};
|
||||
|
||||
// The game state bit set once a heart, bomb or coin is picked, and Daemon's Tail's 1 in 5 heart chance.
|
||||
constexpr int GAME_STATE_HEART_BOMB_COIN_PICKED = 41;
|
||||
constexpr int DAEMONS_TAIL_ODDS = 5;
|
||||
|
||||
+292
-18
@@ -1,4 +1,5 @@
|
||||
#include "entity_pickup.h"
|
||||
#include "entity_bomb.h"
|
||||
#include "entity_effect.h"
|
||||
#include "entity_npc.h"
|
||||
#include "entity_player.h"
|
||||
@@ -9,6 +10,8 @@
|
||||
#include "manager.h"
|
||||
#include "npc_ai.h"
|
||||
#include "room.h"
|
||||
#include "room_grid.h"
|
||||
#include "room_transition.h"
|
||||
#include "sfx_manager.h"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
@@ -24,7 +27,6 @@ constexpr float LOOT_ANGLE_SCALE = 3.14f;
|
||||
constexpr std::array<int, 3> LOCKED_CHESTS = {PICKUP_LOCKEDCHEST, PICKUP_ETERNALCHEST, PICKUP_OLDCHEST};
|
||||
constexpr std::array<int, 4> GOLDEN_CHESTS = {PICKUP_LOCKEDCHEST, PICKUP_BOMBCHEST, PICKUP_ETERNALCHEST,
|
||||
PICKUP_MEGACHEST};
|
||||
constexpr std::array<int, 4> UNWRITTEN_LOOT = {PICKUP_REDCHEST, PICKUP_MOMSCHEST, PICKUP_OLDCHEST, PICKUP_GRAB_BAG};
|
||||
constexpr int EVENT_LOCKED_CHESTS_OPENED = 198;
|
||||
constexpr float CHEST_VANISH_VOLUME = 0.7f;
|
||||
constexpr float SPIKED_CHEST_DAMAGE = 1;
|
||||
@@ -129,11 +131,61 @@ struct ChestDraw
|
||||
std::array<RNG, CHEST_TRINKETS.size()> trinketRngs{};
|
||||
std::array<bool, CHEST_TRINKETS.size()> isTrinketProc{};
|
||||
LootList loot;
|
||||
RNG daemonsTailRng{};
|
||||
RNG* rng = nullptr;
|
||||
Entity_Player* player = nullptr;
|
||||
uint32_t poolFlags = 0;
|
||||
bool isDaemonsTail = false;
|
||||
bool isPokerChip = false;
|
||||
bool isPokerDouble = false;
|
||||
};
|
||||
|
||||
// The outcomes of an old chest, a red chest and a sack. A sack's outcome is its pickup's subtype and variant.
|
||||
enum OldChestOutcome
|
||||
{
|
||||
OLD_OUTCOME_SOUL_HEARTS,
|
||||
OLD_OUTCOME_TRINKETS,
|
||||
OLD_OUTCOME_ITEM,
|
||||
OLD_OUTCOME_ANGEL_ITEM
|
||||
};
|
||||
enum RedChestOutcome
|
||||
{
|
||||
RED_OUTCOME_ITEM,
|
||||
RED_OUTCOME_TELEPORT,
|
||||
RED_OUTCOME_SPIDERS,
|
||||
RED_OUTCOME_TROLL_BOMB,
|
||||
RED_OUTCOME_FLIES,
|
||||
RED_OUTCOME_BLUE_SPIDERS,
|
||||
RED_OUTCOME_SOUL_HEARTS,
|
||||
RED_OUTCOME_BOMBS,
|
||||
RED_OUTCOME_PILLS
|
||||
};
|
||||
constexpr int SACK_OUTCOME_SHIFT = 16;
|
||||
constexpr int SACK_OUTCOME_MASK = 0xffff;
|
||||
constexpr int SACK_BLACK = 2;
|
||||
constexpr int SACK_BLACK_HEART = HEART_BLACK << SACK_OUTCOME_SHIFT | PICKUP_HEART;
|
||||
constexpr int SACK_BONE_HEART = HEART_BONE << SACK_OUTCOME_SHIFT | PICKUP_HEART;
|
||||
|
||||
// What an old, red or Mom's chest gives beyond its outcomes: three trinkets, Left Hand's extra pickup (from two
|
||||
// copies) or its spiders' ban (from three), the Red Key until Mom's chests' items are unlocked, the familiars and
|
||||
// entities a red chest lets out, and the Poker Chip's banned item qualities.
|
||||
constexpr int OLD_CHEST_TRINKETS = 3;
|
||||
constexpr int OLD_CHEST_SOUL_HEARTS = 3;
|
||||
constexpr int RED_CHEST_FAMILIARS = 3;
|
||||
constexpr int LEFT_HAND_EXTRA = 2;
|
||||
constexpr int LEFT_HAND_NO_SPIDERS = 3;
|
||||
constexpr int ACHIEVEMENT_MOMS_CHEST_ITEMS = 415;
|
||||
constexpr int FAMILIAR_BLUE_FLY = 43;
|
||||
constexpr int FAMILIAR_BLUE_SPIDER = 73;
|
||||
constexpr int RED_CHEST_TELEPORT = 1;
|
||||
constexpr int RED_CHEST_BOMB_SUBTYPE = 3;
|
||||
constexpr float RED_CHEST_SPIDER_STEP = 70;
|
||||
constexpr float RED_CHEST_SPIDER_HEIGHT = -30;
|
||||
constexpr uint32_t POKER_QUALITY_BANS = 0x1f0;
|
||||
constexpr int POKER_TOP_QUALITY = 2;
|
||||
constexpr std::array<uint32_t, 3> DAEMONS_TAIL_SHIFTS = {1, 5, 16};
|
||||
constexpr std::array<uint32_t, 3> POKER_CHIP_SHIFTS = {1, 21, 20};
|
||||
|
||||
// Adds weight to an outcome, never below zero, or adds the outcome (inlined in the original).
|
||||
void WeightedOutcomePicker::AddOutcomeWeight(int id, int weight)
|
||||
{
|
||||
@@ -184,6 +236,31 @@ static void loot_item_add(ChestDraw& draw, int pool)
|
||||
draw.loot.entries.push_back({.subType = item, .type = ENTITY_PICKUP, .variant = PICKUP_COLLECTIBLE, .seed = seed});
|
||||
}
|
||||
|
||||
// The Poker Chip's item (FUN_006ee640): a first draw (left in the pool) shows a quality, and the item drawn is of the
|
||||
// next quality up (a quality 3 or 4 its own), the first when none is.
|
||||
static void loot_poker_item_add(ChestDraw& draw, int pool, int fallbackPool)
|
||||
{
|
||||
uint32_t seed = draw.rng->Next();
|
||||
ItemPool& itemPool = g_game->itemPool;
|
||||
int first =
|
||||
itemPool.GetCollectible((ItemPoolType)pool, draw.rng->Next(), draw.poolFlags | POOL_FLAG_NO_DECREASE, 0, 0);
|
||||
int quality = g_manager->itemConfig.GetCollectible(first)->quality;
|
||||
int target = quality > POKER_TOP_QUALITY ? quality : quality + 1;
|
||||
uint32_t flags = ~(POOL_FLAG_BAN_QUALITY_0 << target) & (draw.poolFlags | POKER_QUALITY_BANS);
|
||||
int item = itemPool.GetCollectible((ItemPoolType)pool, draw.rng->Next(), flags, 0, fallbackPool);
|
||||
if (item == COLLECTIBLE_BREAKFAST) item = first;
|
||||
draw.loot.entries.push_back({.subType = item, .type = ENTITY_PICKUP, .variant = PICKUP_COLLECTIBLE, .seed = seed});
|
||||
}
|
||||
|
||||
// The Poker Chip doubles a chest's pickups, or half the time trades them for an attack fly.
|
||||
static int poker_chip_count(ChestDraw& draw, int count)
|
||||
{
|
||||
if (!draw.isPokerChip) return count;
|
||||
if (draw.isPokerDouble && count != 0) return count * 2;
|
||||
draw.loot.entries.push_back({.type = ENTITY_ATTACKFLY, .seed = draw.rng->Next()});
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Rolls each bonus trinket for the first player holding it (a Lazarus twin's own copy counts for globally shared
|
||||
// ones): one in five passes Child's Heart under Daemon's Tail, then one, two or three copies add their pickup a
|
||||
// third, two thirds or every time.
|
||||
@@ -240,16 +317,20 @@ static void chest_pickups_add(ChestDraw& draw, int count, bool isGilded)
|
||||
WeightedOutcomePicker picker;
|
||||
int heartWeight = draw.isDaemonsTail ? 4 : 20;
|
||||
if (isGilded)
|
||||
picker.outcomes = {{CHEST_PICKUP_COINS, 25}, {CHEST_PICKUP_HEART, heartWeight}, {CHEST_PICKUP_KEY, 10},
|
||||
{CHEST_PICKUP_BOMB, 20}, {CHEST_PICKUP_PILL, 5}, {CHEST_PICKUP_CARD, 5},
|
||||
{CHEST_PICKUP_RUNE, 5}, {CHEST_PICKUP_TRINKET, 5}, {CHEST_PICKUP_BATTERY, 5}};
|
||||
picker.outcomes = {{CHEST_PICKUP_COINS, 25}, {CHEST_PICKUP_HEART, heartWeight},
|
||||
{CHEST_PICKUP_KEY, 10}, {CHEST_PICKUP_BOMB, 20},
|
||||
{CHEST_PICKUP_PILL, 5}, {CHEST_PICKUP_CARD, 5},
|
||||
{CHEST_PICKUP_RUNE, 5}, {CHEST_PICKUP_TRINKET, 5},
|
||||
{CHEST_PICKUP_BATTERY, 5}};
|
||||
else
|
||||
picker.outcomes = {{CHEST_PICKUP_COINS, 35}, {CHEST_PICKUP_HEART, heartWeight}, {CHEST_PICKUP_KEY, 15},
|
||||
picker.outcomes = {{CHEST_PICKUP_COINS, 35},
|
||||
{CHEST_PICKUP_HEART, heartWeight},
|
||||
{CHEST_PICKUP_KEY, 15},
|
||||
{CHEST_PICKUP_BOMB, 30}};
|
||||
|
||||
constexpr std::array<int, 9> PICKUP_VARIANTS = {PICKUP_COIN, PICKUP_HEART, PICKUP_KEY,
|
||||
PICKUP_BOMB, PICKUP_PILL, PICKUP_TAROTCARD,
|
||||
PICKUP_TAROTCARD, PICKUP_TRINKET, PICKUP_LIL_BATTERY};
|
||||
constexpr std::array<int, 9> PICKUP_VARIANTS = {PICKUP_COIN, PICKUP_HEART, PICKUP_KEY,
|
||||
PICKUP_BOMB, PICKUP_PILL, PICKUP_TAROTCARD,
|
||||
PICKUP_TAROTCARD, PICKUP_TRINKET, PICKUP_LIL_BATTERY};
|
||||
for (; count > 0; count--)
|
||||
{
|
||||
int outcome = outcome_draw(picker, *draw.rng);
|
||||
@@ -325,14 +406,16 @@ static void chest_loot_draw(ChestDraw& draw, int variant)
|
||||
loot_add(draw, PICKUP_TAROTCARD);
|
||||
break;
|
||||
case CHEST_OUTCOME_ITEM:
|
||||
loot_item_add(draw, POOL_GOLDEN_CHEST);
|
||||
if (!draw.isPokerChip) loot_item_add(draw, POOL_GOLDEN_CHEST);
|
||||
else loot_poker_item_add(draw, POOL_GOLDEN_CHEST, variant == PICKUP_ETERNALCHEST ? POOL_ANGEL : 0);
|
||||
break;
|
||||
default:
|
||||
{
|
||||
int roll = isGolden ? GOLDEN_PICKUP_COUNT_ROLL : PICKUP_COUNT_ROLL;
|
||||
int count = std::max(PICKUP_COUNT_MIN, (int)draw.rng->RandomInt(roll));
|
||||
chest_trinket_pickup_add(draw, CHEST_TRINKET_PRECEDENCE.size());
|
||||
chest_pickups_add(draw, chest_pickup_count_grow(draw, count), outcome == CHEST_OUTCOME_GILDED_PICKUPS);
|
||||
count = poker_chip_count(draw, chest_pickup_count_grow(draw, count));
|
||||
chest_pickups_add(draw, count, outcome == CHEST_OUTCOME_GILDED_PICKUPS);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -351,23 +434,171 @@ static void wooden_chest_loot_draw(ChestDraw& draw)
|
||||
count++;
|
||||
chest_trinket_pickup_add(draw, WOODEN_CHEST_TRINKETS);
|
||||
if (g_game->playerManager.FirstCollectibleOwner(COLLECTIBLE_MOMS_KEY, LAZARUS_SHARE_CHECK)) count *= 2;
|
||||
if (draw.isPokerChip && poker_chip_count(draw, count) == 0) return;
|
||||
if (draw.isPokerChip) count *= 2;
|
||||
|
||||
int outcome = outcome_draw(picker, *draw.rng);
|
||||
if (outcome == WOODEN_OUTCOME_ITEM && draw.isPokerChip) return loot_poker_item_add(draw, POOL_WOODEN_CHEST, 0);
|
||||
if (outcome == WOODEN_OUTCOME_ITEM) return loot_item_add(draw, POOL_WOODEN_CHEST);
|
||||
for (; count > 0; count--) loot_add(draw, outcome == WOODEN_OUTCOME_CARDS ? PICKUP_TAROTCARD : PICKUP_PILL);
|
||||
}
|
||||
|
||||
// An old chest's loot: soul hearts, three trinkets, an old chest's item, or rarely an angel room's.
|
||||
static void old_chest_loot_draw(ChestDraw& draw)
|
||||
{
|
||||
WeightedOutcomePicker picker;
|
||||
picker.outcomes = {{OLD_OUTCOME_SOUL_HEARTS, draw.isDaemonsTail ? 9 : 43},
|
||||
{OLD_OUTCOME_TRINKETS, 42},
|
||||
{OLD_OUTCOME_ITEM, 10},
|
||||
{OLD_OUTCOME_ANGEL_ITEM, 5}};
|
||||
switch (outcome_draw(picker, *draw.rng))
|
||||
{
|
||||
case OLD_OUTCOME_SOUL_HEARTS:
|
||||
for (int i = (int)draw.rng->RandomInt(OLD_CHEST_SOUL_HEARTS) + 1; i > 0; i--)
|
||||
loot_add(draw, PICKUP_HEART, HEART_SOUL);
|
||||
break;
|
||||
case OLD_OUTCOME_TRINKETS:
|
||||
for (int i = 0; i < OLD_CHEST_TRINKETS; i++) loot_add(draw, PICKUP_TRINKET);
|
||||
break;
|
||||
case OLD_OUTCOME_ITEM:
|
||||
loot_item_add(draw, POOL_OLD_CHEST);
|
||||
break;
|
||||
case OLD_OUTCOME_ANGEL_ITEM:
|
||||
loot_item_add(draw, POOL_ANGEL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Adds an entity that is no pickup to a chest's loot, seeded by the next draw.
|
||||
static void loot_entity_add(ChestDraw& draw, int type, int variant)
|
||||
{
|
||||
draw.loot.entries.push_back({.type = type, .variant = variant, .seed = draw.rng->Next()});
|
||||
}
|
||||
|
||||
// A red chest's loot: a devil item on the Chest's first room, else a red chest's item, a teleport to the devil room
|
||||
// (not from the devil room or Genesis), spiders (unless three Left Hands), a Mega Troll Bomb, blue flies or spiders,
|
||||
// soul hearts, troll bombs or pills. Two Left Hands add a pill or a soul heart.
|
||||
static void red_chest_loot_draw(ChestDraw& draw, bool isChestFloor)
|
||||
{
|
||||
Game& game = *g_game;
|
||||
if (isChestFloor && game.startingRoomIdx == game.currentRoomIdx)
|
||||
{
|
||||
uint32_t seed = draw.rng->Next();
|
||||
int item = game.itemPool.GetCollectible(POOL_DEVIL, draw.rng->Next(),
|
||||
draw.poolFlags | POOL_FLAG_BAN_DEVIL_SACRIFICE, 0, 0);
|
||||
draw.loot.entries.push_back(
|
||||
{.subType = item, .type = ENTITY_PICKUP, .variant = PICKUP_COLLECTIBLE, .seed = seed});
|
||||
return;
|
||||
}
|
||||
|
||||
int leftHands = draw.player ? draw.player->GetTrinketMultiplier(TRINKET_LEFT_HAND) : 0;
|
||||
WeightedOutcomePicker picker;
|
||||
picker.outcomes = {{RED_OUTCOME_ITEM, 10}};
|
||||
if (game.currentRoomIdx != ROOM_DEVIL_IDX && game.currentRoomIdx != ROOM_GENESIS_IDX)
|
||||
picker.AddOutcomeWeight(RED_OUTCOME_TELEPORT, 5);
|
||||
if (!draw.player || leftHands < LEFT_HAND_NO_SPIDERS) picker.AddOutcomeWeight(RED_OUTCOME_SPIDERS, 13);
|
||||
picker.AddOutcomeWeight(RED_OUTCOME_TROLL_BOMB, 13);
|
||||
picker.AddOutcomeWeight(RED_OUTCOME_FLIES, 7);
|
||||
picker.AddOutcomeWeight(RED_OUTCOME_BLUE_SPIDERS, 7);
|
||||
picker.AddOutcomeWeight(RED_OUTCOME_SOUL_HEARTS, draw.isDaemonsTail ? 3 : 15);
|
||||
picker.AddOutcomeWeight(RED_OUTCOME_BOMBS, 15);
|
||||
picker.AddOutcomeWeight(RED_OUTCOME_PILLS, 15);
|
||||
|
||||
int outcome = outcome_draw(picker, *draw.rng);
|
||||
switch (outcome)
|
||||
{
|
||||
case RED_OUTCOME_ITEM:
|
||||
loot_item_add(draw, POOL_RED_CHEST);
|
||||
break;
|
||||
case RED_OUTCOME_TELEPORT:
|
||||
draw.loot.entries.push_back({.variant = RED_CHEST_TELEPORT});
|
||||
break;
|
||||
case RED_OUTCOME_SPIDERS:
|
||||
loot_entity_add(draw, ENTITY_SPIDER, 0);
|
||||
loot_entity_add(draw, ENTITY_SPIDER, 0);
|
||||
break;
|
||||
case RED_OUTCOME_TROLL_BOMB:
|
||||
loot_entity_add(draw, ENTITY_BOMB, BOMB_SUPERTROLL);
|
||||
break;
|
||||
case RED_OUTCOME_FLIES:
|
||||
case RED_OUTCOME_BLUE_SPIDERS:
|
||||
for (int i = 0; i < RED_CHEST_FAMILIARS; i++)
|
||||
loot_entity_add(draw, ENTITY_FAMILIAR,
|
||||
outcome == RED_OUTCOME_FLIES ? FAMILIAR_BLUE_FLY : FAMILIAR_BLUE_SPIDER);
|
||||
break;
|
||||
case RED_OUTCOME_SOUL_HEARTS:
|
||||
{
|
||||
loot_add(draw, PICKUP_HEART, HEART_SOUL);
|
||||
bool isSecond = draw.rng->RandomInt(2) == 0 &&
|
||||
(!draw.isDaemonsTail || draw.daemonsTailRng.RandomInt(DAEMONS_TAIL_ODDS) == 0);
|
||||
if (isSecond) loot_add(draw, PICKUP_HEART, HEART_SOUL);
|
||||
break;
|
||||
}
|
||||
case RED_OUTCOME_BOMBS:
|
||||
loot_add(draw, PICKUP_BOMB, RED_CHEST_BOMB_SUBTYPE);
|
||||
loot_add(draw, PICKUP_BOMB, RED_CHEST_BOMB_SUBTYPE);
|
||||
break;
|
||||
case RED_OUTCOME_PILLS:
|
||||
loot_add(draw, PICKUP_PILL);
|
||||
loot_add(draw, PICKUP_PILL);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!draw.player || leftHands < LEFT_HAND_EXTRA) return;
|
||||
bool isPill = (draw.rng->Next() & 1) == 0;
|
||||
loot_add(draw, isPill ? PICKUP_PILL : PICKUP_HEART, HEART_SOUL);
|
||||
}
|
||||
|
||||
// A sack's loot: two or three pickups, bombs, keys, coins, batteries or cards, or from a black sack bombs, pills and a
|
||||
// black or bone heart (one heart at most).
|
||||
static void sack_loot_draw(ChestDraw& draw, int subtype)
|
||||
{
|
||||
WeightedOutcomePicker picker;
|
||||
if (subtype == SACK_BLACK)
|
||||
picker.outcomes = {{PICKUP_BOMB, 15}, {SACK_BLACK_HEART, 10}, {SACK_BONE_HEART, 5}, {PICKUP_PILL, 15}};
|
||||
else
|
||||
picker.outcomes = {
|
||||
{PICKUP_BOMB, 15}, {PICKUP_KEY, 20}, {PICKUP_COIN, 15}, {PICKUP_LIL_BATTERY, 4}, {PICKUP_TAROTCARD, 4}};
|
||||
|
||||
for (int count = (int)draw.rng->RandomInt(2) + 2; count > 0; count--)
|
||||
{
|
||||
int outcome = outcome_draw(picker, *draw.rng);
|
||||
int variant = outcome & SACK_OUTCOME_MASK;
|
||||
draw.rng->Next();
|
||||
loot_add(draw, variant, outcome >> SACK_OUTCOME_SHIFT);
|
||||
if (subtype != SACK_BLACK || variant != PICKUP_HEART) continue;
|
||||
picker.AddOutcomeWeight(SACK_BLACK_HEART, -10);
|
||||
picker.AddOutcomeWeight(SACK_BONE_HEART, -5);
|
||||
}
|
||||
}
|
||||
|
||||
// Mom's chest's loot: a Mom's chest item, the Red Key until those are unlocked (outside a daily or debug run).
|
||||
static void moms_chest_loot_draw(ChestDraw& draw)
|
||||
{
|
||||
bool isLocked = !g_manager->persistentGameData.achievements[ACHIEVEMENT_MOMS_CHEST_ITEMS] &&
|
||||
(g_manager->state != MANAGER_STATE_GAME || (g_game->dailyChallenge._id == 0 && !g_game->isDebug));
|
||||
if (!isLocked) return loot_item_add(draw, POOL_MOMS_CHEST);
|
||||
|
||||
uint32_t seed = draw.rng->Next();
|
||||
draw.loot.entries.push_back(
|
||||
{.subType = COLLECTIBLE_RED_KEY, .type = ENTITY_PICKUP, .variant = PICKUP_COLLECTIBLE, .seed = seed});
|
||||
}
|
||||
|
||||
// 006dae40 What the chest gives, drawn from its RNG, or from a copy with POOL_DRAW_PEEK, which also leaves the items
|
||||
// in their pools. An eternal chest gives nothing a quarter of the time (and stays). Ace of Spades, Safety Cap,
|
||||
// Match Stick, Child's Heart and Rusted Key may add their pickups, and in the Chest every chest gives a treasure item.
|
||||
// Red, old and Mom's chests, sacks and Poker Chip stop the game until reached.
|
||||
// Old chests give hearts, trinkets or items, red chests also teleports and enemies, Mom's chests their item, sacks
|
||||
// pickups, and the Poker Chip doubles a chest's pickups or trades them for an attack fly, and raises its items'
|
||||
// quality.
|
||||
LootList Entity_Pickup::GetChestLoot(PoolDraw draw, Entity_Player* player)
|
||||
{
|
||||
ChestDraw chest;
|
||||
RNG peek = dropRNG;
|
||||
chest.rng = draw == POOL_DRAW_TAKE ? &dropRNG : &peek;
|
||||
chest.player = player;
|
||||
chest.poolFlags = draw == POOL_DRAW_TAKE ? 0 : POOL_FLAG_NO_DECREASE;
|
||||
chest.isDaemonsTail = g_game->playerManager.AnyoneHasTrinket(TRINKET_DAEMONS_TAIL);
|
||||
chest.daemonsTailRng = {dropRNG._seed, DAEMONS_TAIL_SHIFTS[0], DAEMONS_TAIL_SHIFTS[1], DAEMONS_TAIL_SHIFTS[2]};
|
||||
for (size_t index = 0; index < CHEST_TRINKETS.size(); index++)
|
||||
chest.trinketRngs[index].SetSeed(dropRNG._seed, CHEST_TRINKETS[index].shiftIndex);
|
||||
|
||||
@@ -380,11 +611,18 @@ LootList Entity_Pickup::GetChestLoot(PoolDraw draw, Entity_Player* player)
|
||||
bool isChestFloor = !game.IsGreedMode() && game.stage == STAGE_DARK_ROOM && !isDeathmatch;
|
||||
bool isPokerChip = isDeathmatch ? player && player->HasTrinket(TRINKET_POKER_CHIP)
|
||||
: game.playerManager.AnyoneHasTrinket(TRINKET_POKER_CHIP);
|
||||
if (isPokerChip) reconstruction_missing("Entity_Pickup::GetChestLoot 006dae40 (Poker Chip)");
|
||||
if (std::ranges::count(UNWRITTEN_LOOT, variant) > 0)
|
||||
reconstruction_missing("Entity_Pickup::GetChestLoot 006dae40 (red, old and Mom's chests and sacks)");
|
||||
if (isPokerChip)
|
||||
{
|
||||
RNG poker = {chest.rng->_seed, POKER_CHIP_SHIFTS[0], POKER_CHIP_SHIFTS[1], POKER_CHIP_SHIFTS[2]};
|
||||
chest.isPokerChip = true;
|
||||
chest.isPokerDouble = (poker.Next() & 1) == 0;
|
||||
}
|
||||
|
||||
if (variant == PICKUP_WOODENCHEST) wooden_chest_loot_draw(chest);
|
||||
else if (variant == PICKUP_REDCHEST) red_chest_loot_draw(chest, isChestFloor);
|
||||
else if (variant == PICKUP_MOMSCHEST) moms_chest_loot_draw(chest);
|
||||
else if (variant == PICKUP_OLDCHEST) old_chest_loot_draw(chest);
|
||||
else if (variant == PICKUP_GRAB_BAG) sack_loot_draw(chest, subtype);
|
||||
else if (!isChestFloor) chest_loot_draw(chest, variant);
|
||||
else
|
||||
{
|
||||
@@ -451,6 +689,40 @@ bool Entity_Pickup::TryOpenChest(Entity_Player* player)
|
||||
return true;
|
||||
}
|
||||
|
||||
// What a red chest lets out that is no ordinary spawn: a teleport to the devil room, spiders (the first thrown halfway
|
||||
// to the player), blue flies and blue spiders. Whether the entry was spawned here.
|
||||
static bool red_chest_entry_spawn(Entity_Pickup& chest, const LootEntry& entry, Entity_Player& player, bool isFirst)
|
||||
{
|
||||
if (entry.type == 0 && entry.variant == RED_CHEST_TELEPORT)
|
||||
{
|
||||
Game& game = *g_game;
|
||||
game.InitializeDevilAngelRoom(false, false);
|
||||
game.leaveDoor = -1;
|
||||
game.StartRoomTransition({.player = &player, .animation = TRANSITION_TELEPORT, .roomIndex = ROOM_DEVIL_IDX});
|
||||
return true;
|
||||
}
|
||||
if (entry.type == ENTITY_SPIDER)
|
||||
{
|
||||
Vector target{};
|
||||
if (isFirst)
|
||||
{
|
||||
// The player's NPC target fields (0x144c, 0x1450) are not known yet and taken as empty.
|
||||
Entity* aim = player.darkArtsLastSnare ? player.darkArtsLastSnare->GetLastParent() : &player;
|
||||
Vector halfway = vector_scale(vector_add(aim->pos, chest.pos), 0.5f);
|
||||
target = room_free_pickup_position_find({.position = halfway, .step = RED_CHEST_SPIDER_STEP});
|
||||
}
|
||||
Entity_NPC::ThrowSpider(chest.pos, &chest, target, false, RED_CHEST_SPIDER_HEIGHT);
|
||||
return true;
|
||||
}
|
||||
if (entry.type != ENTITY_FAMILIAR) return false;
|
||||
|
||||
if (entry.variant == FAMILIAR_BLUE_FLY) player.AddBlueFlies(1, chest.pos, nullptr);
|
||||
else if (entry.variant == FAMILIAR_BLUE_SPIDER)
|
||||
reconstruction_missing(
|
||||
"Entity_Pickup::TryOpenChest 006e6e40: a red chest's blue spiders (spawn_blue_spider 00638e30)");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Spawns what a chest gives: the first item turns the chest into its pedestal (a pay to play look for those) and
|
||||
// more stand beside it, pickups and enemies fly out from a spot beside the chest (a Mega Chest's slower at first),
|
||||
// enemies placed towards the player, and chests come out smaller. Red chests' spiders, flies and teleports stop the
|
||||
@@ -468,8 +740,10 @@ void Entity_Pickup::chest_loot_spawn(const LootList& loot, Entity_Player& player
|
||||
{
|
||||
Entity_Pickup* item = this;
|
||||
if (variant == PICKUP_COLLECTIBLE)
|
||||
item = static_cast<Entity_Pickup*>(g_game->Spawn({.position = pos, .subType = entry.subType,
|
||||
.type = ENTITY_PICKUP, .variant = PICKUP_COLLECTIBLE,
|
||||
item = static_cast<Entity_Pickup*>(g_game->Spawn({.position = pos,
|
||||
.subType = entry.subType,
|
||||
.type = ENTITY_PICKUP,
|
||||
.variant = PICKUP_COLLECTIBLE,
|
||||
.seed = entry.seed}));
|
||||
else Morph(ENTITY_PICKUP, PICKUP_COLLECTIBLE, entry.subType, false, false, false);
|
||||
if (item->variant == PICKUP_COLLECTIBLE)
|
||||
@@ -482,8 +756,8 @@ void Entity_Pickup::chest_loot_spawn(const LootList& loot, Entity_Player& player
|
||||
isPushing = true;
|
||||
continue;
|
||||
}
|
||||
if (entry.type != ENTITY_PICKUP)
|
||||
reconstruction_missing("Entity_Pickup::TryOpenChest 006e6e40 (a red chest's spiders, flies or teleport)");
|
||||
if (entry.type != ENTITY_PICKUP && red_chest_entry_spawn(*this, entry, player, &entry == &loot.entries.front()))
|
||||
continue;
|
||||
|
||||
float speed = variant == PICKUP_MEGACHEST
|
||||
? std::min(1.0f, (float)spawned * MEGA_CHEST_SPEED_STEP + MEGA_CHEST_SPEED_BASE)
|
||||
|
||||
+16
-11
@@ -3,6 +3,7 @@
|
||||
#include "entity_effect.h"
|
||||
#include "entity_familiar.h"
|
||||
#include "entity_npc.h"
|
||||
#include "entity_slot.h"
|
||||
#include "game.h"
|
||||
#include "log.h"
|
||||
#include "lua_engine.h"
|
||||
@@ -32,8 +33,6 @@ constexpr float GREED_START_SPOT_Y = 280;
|
||||
constexpr float BACKASSWARDS_START_OFFSET_Y = 100;
|
||||
constexpr int BETHANY_START_CHARGE = 4;
|
||||
constexpr int MAGDALENE_B_START_RED_HEARTS = 4;
|
||||
constexpr int PLAYERFORM_BOOK_WORM = 10;
|
||||
constexpr int PLAYERFORM_NECROMANCER = 15;
|
||||
constexpr float EDEN_SPEED_SPREAD = 0.3f;
|
||||
constexpr float EDEN_FIRE_DELAY_SPREAD = 1.5f;
|
||||
constexpr float EDEN_RANGE_SPREAD = 120;
|
||||
@@ -110,12 +109,6 @@ static int card_roll(uint32_t seed, int runeChance, bool isPlaying)
|
||||
return lua_engine_get().GetCard({.rng = &rng, .card = card, .isPlaying = isPlaying, .isRunes = isPlaying});
|
||||
}
|
||||
|
||||
// Room methods the room's takeover has not declared yet.
|
||||
static Vector room_random_pickup_position()
|
||||
{
|
||||
reconstruction_missing("Room::get_random_pickup_position 00813460");
|
||||
}
|
||||
|
||||
// A generator with a seed and the shift triple at an index of RNG's table.
|
||||
RNG rng_make(uint32_t seed, uint32_t shiftIndex)
|
||||
{
|
||||
@@ -616,7 +609,7 @@ void Entity_Player::InitPreLevelInitStats()
|
||||
}
|
||||
break;
|
||||
case PLAYER_BETHANY:
|
||||
if (HasCollectible(COLLECTIBLE_BOOK_OF_VIRTUES)) IncrementPlayerFormCounter(PLAYERFORM_BOOK_WORM, 1);
|
||||
if (HasCollectible(COLLECTIBLE_BOOK_OF_VIRTUES)) IncrementPlayerFormCounter(PLAYER_FORM_BOOKWORM, 1);
|
||||
break;
|
||||
case PLAYER_BETHANY_B:
|
||||
AddBloodCharge(redHearts);
|
||||
@@ -1103,7 +1096,7 @@ void Entity_Player::floor_items_recharge()
|
||||
}
|
||||
else if (active.item == COLLECTIBLE_ERASER) AddActiveCharge(1, slot, false, false, true);
|
||||
}
|
||||
if (!hasCurseMistEffect && !isCoopGhost && playerForms[PLAYERFORM_NECROMANCER] > 2)
|
||||
if (!hasCurseMistEffect && !isCoopGhost && playerForms[PLAYER_FORM_NECROMANCER] > 2)
|
||||
reconstruction_missing("Entity_Player::level_start 007a4ba0 (the Necronomicon transformation)");
|
||||
for (int i = HasTrinket(TRINKET_BETHS_FAITH) ? GetTrinketMultiplier(TRINKET_BETHS_FAITH) * 4 : 0; i > 0; i--)
|
||||
AddWisp(COLLECTIBLE_BOOK_OF_VIRTUES, pos, false, false);
|
||||
@@ -1125,7 +1118,7 @@ void Entity_Player::stem_cell_heal()
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
uint32_t seed = Random();
|
||||
g_game->Spawn({.position = room_random_pickup_position(),
|
||||
g_game->Spawn({.position = room_pickup_position_random(false, false),
|
||||
.type = ENTITY_PICKUP,
|
||||
.variant = PICKUP_HEART,
|
||||
.seed = seed});
|
||||
@@ -1422,6 +1415,18 @@ void Entity_Player::ClearReferences()
|
||||
release_weapons_and_effects(false);
|
||||
}
|
||||
|
||||
// 0065cf60 Whether the player is a co-op baby still blinking in after joining.
|
||||
bool Entity_Player::IsP2Appearing()
|
||||
{
|
||||
return variant == PLAYER_VARIANT_COOP_BABY && damageCooldown > 0;
|
||||
}
|
||||
|
||||
// 00782a60 Whether the head is free to turn, its last turn having run out.
|
||||
uint32_t Entity_Player::CanTurnHead()
|
||||
{
|
||||
return headDirectionTime < 0;
|
||||
}
|
||||
|
||||
// 00757ab0 Whether the player shuts the room's doors, as players do only in the deathmatch.
|
||||
bool Entity_Player::CanShutDoors()
|
||||
{
|
||||
|
||||
+50
-4
@@ -193,6 +193,19 @@ enum PlayerItemId : int
|
||||
COLLECTIBLE_COMPASS = 21,
|
||||
COLLECTIBLE_BREAKFAST = 25,
|
||||
COLLECTIBLE_BIBLE = 33,
|
||||
COLLECTIBLE_GIMPY = 225,
|
||||
COLLECTIBLE_INFESTATION_2 = 234,
|
||||
COLLECTIBLE_QUINTS = 661,
|
||||
COLLECTIBLE_BONE_SPURS = 683,
|
||||
COLLECTIBLE_HUNGRY_SOUL = 684,
|
||||
COLLECTIBLE_DOLLAR = 18,
|
||||
COLLECTIBLE_ROTTEN_MEAT = 26,
|
||||
COLLECTIBLE_BLOOD_BAG = 119,
|
||||
COLLECTIBLE_IV_BAG = 135,
|
||||
COLLECTIBLE_CRYSTAL_BALL = 158,
|
||||
COLLECTIBLE_PORTABLE_SLOT = 177,
|
||||
COLLECTIBLE_BUDDY_IN_A_BOX = 518,
|
||||
COLLECTIBLE_BATTERY_PACK = 603,
|
||||
COLLECTIBLE_BOOK_OF_BELIAL = 34,
|
||||
COLLECTIBLE_NECRONOMICON = 35,
|
||||
COLLECTIBLE_POOP = 36,
|
||||
@@ -236,6 +249,7 @@ enum PlayerItemId : int
|
||||
COLLECTIBLE_BOBS_CURSE = 140,
|
||||
COLLECTIBLE_NOTCHED_AXE = 147,
|
||||
COLLECTIBLE_IPECAC = 149,
|
||||
COLLECTIBLE_MULLIGAN = 151,
|
||||
COLLECTIBLE_MUTANT_SPIDER = 153,
|
||||
COLLECTIBLE_PEEPER = 155,
|
||||
COLLECTIBLE_BLOODY_LUST = 157,
|
||||
@@ -250,6 +264,7 @@ enum PlayerItemId : int
|
||||
COLLECTIBLE_GNAWED_LEAF = 210,
|
||||
COLLECTIBLE_BALL_OF_BANDAGES = 207,
|
||||
COLLECTIBLE_GUPPYS_COLLAR = 212,
|
||||
COLLECTIBLE_POLYPHEMUS = 169,
|
||||
COLLECTIBLE_ANEMIC = 214,
|
||||
COLLECTIBLE_ANTI_GRAVITY = 222,
|
||||
COLLECTIBLE_PYROMANIAC = 223,
|
||||
@@ -257,6 +272,7 @@ enum PlayerItemId : int
|
||||
COLLECTIBLE_MONSTROS_LUNG = 229,
|
||||
COLLECTIBLE_BALL_OF_TAR = 231,
|
||||
COLLECTIBLE_STOP_WATCH = 232,
|
||||
COLLECTIBLE_TINY_PLANET = 233,
|
||||
COLLECTIBLE_E_COLI = 236,
|
||||
COLLECTIBLE_KEY_PIECE_1 = 238,
|
||||
COLLECTIBLE_KEY_PIECE_2 = 239,
|
||||
@@ -312,6 +328,8 @@ enum PlayerItemId : int
|
||||
COLLECTIBLE_SERPENTS_KISS = 393,
|
||||
COLLECTIBLE_MARKED = 394,
|
||||
COLLECTIBLE_TECH_X = 395,
|
||||
COLLECTIBLE_TRACTOR_BEAM = 397,
|
||||
COLLECTIBLE_EVIL_EYE = 410,
|
||||
COLLECTIBLE_LUSTY_BLOOD = 411,
|
||||
COLLECTIBLE_CAMBION_CONCEPTION = 412,
|
||||
COLLECTIBLE_IMMACULATE_CONCEPTION = 413,
|
||||
@@ -361,6 +379,7 @@ enum PlayerItemId : int
|
||||
COLLECTIBLE_SOCKS = 571,
|
||||
COLLECTIBLE_EYE_OF_THE_OCCULT = 572,
|
||||
COLLECTIBLE_DIRTY_MIND = 576,
|
||||
COLLECTIBLE_DAMOCLES = 577,
|
||||
COLLECTIBLE_RED_KEY = 580,
|
||||
COLLECTIBLE_WAVY_CAP = 582,
|
||||
COLLECTIBLE_BOOK_OF_VIRTUES = 584,
|
||||
@@ -449,6 +468,14 @@ enum PlayerItemId : int
|
||||
TRINKET_SAFETY_CAP = 44,
|
||||
TRINKET_ACE_OF_SPADES = 45,
|
||||
TRINKET_POKER_CHIP = 76,
|
||||
TRINKET_CRICKET_LEG = 185,
|
||||
TRINKET_AAA_BATTERY = 3,
|
||||
TRINKET_FISH_HEAD = 29,
|
||||
TRINKET_BOBS_BLADDER = 71,
|
||||
TRINKET_KARMA = 85,
|
||||
TRINKET_PAY_TO_WIN = 112,
|
||||
TRINKET_ROTTEN_PENNY = 126,
|
||||
TRINKET_BETHS_ESSENCE = 182,
|
||||
TRINKET_SECOND_HAND = 78,
|
||||
TRINKET_MOMS_LOCKET = 87,
|
||||
TRINKET_CURSED_SKULL = 43,
|
||||
@@ -581,9 +608,8 @@ enum PlayerChallenge : int
|
||||
CHALLENGE_RED_REDEMPTION = 44
|
||||
};
|
||||
|
||||
// How far a held item's sprite rises over the head, and the Missing Pages form's index.
|
||||
// How far a held item's sprite rises over the head.
|
||||
constexpr float HELD_SPRITE_RISE = -4;
|
||||
constexpr int PLAYER_FORM_MISSING_PAGES = 15;
|
||||
|
||||
// One active item slot: the item, its charges and the data it keeps between uses.
|
||||
struct ActiveItemDesc
|
||||
@@ -687,6 +713,24 @@ struct History
|
||||
void remove_index_refs(int index);
|
||||
};
|
||||
|
||||
// A familiar as it follows its player into a saved run or through Curse of the Mist (FamiliarData).
|
||||
struct FamiliarData
|
||||
{
|
||||
Vector formationTargetOffset{};
|
||||
float health = 0;
|
||||
int coins = 0;
|
||||
int hearts = 0;
|
||||
int keys = 0;
|
||||
int roomClearCount = 0;
|
||||
int state = 0;
|
||||
int subtype = 0;
|
||||
int variant = 0;
|
||||
uint32_t dropSeed = 0;
|
||||
uint32_t initSeed = 0;
|
||||
bool isNotCountedAsFollower = false;
|
||||
bool isSubtype55555 = false;
|
||||
};
|
||||
|
||||
// Coins, keys, bombs and charges, as Curse of the Mist keeps them aside.
|
||||
struct ConsumableData
|
||||
{
|
||||
@@ -943,7 +987,7 @@ public:
|
||||
std::shared_ptr<PlayerHUD> playerHUD;
|
||||
std::vector<Entity*> contactHitList;
|
||||
std::vector<Entity*> darkArtsHitList;
|
||||
std::vector<Entity_Familiar*> curseMistFamiliars;
|
||||
std::vector<FamiliarData> curseMistFamiliars;
|
||||
std::vector<int> pendingWisps;
|
||||
std::deque<int> echoChamberItems;
|
||||
EntityDesc friendBallEnemy;
|
||||
@@ -1284,7 +1328,7 @@ public:
|
||||
void AddJarHearts(int amount);
|
||||
void AddGoldenKey();
|
||||
void RemoveGoldenKey();
|
||||
void restore_curse_mist_backup(int* backup);
|
||||
void restore_curse_mist_backup(const ConsumableData& backup);
|
||||
Entity* AddBlueFlies(int amount, Vector pos, Entity* target);
|
||||
void RemoveBlueFly();
|
||||
void AddLeprosy();
|
||||
@@ -1497,6 +1541,8 @@ public:
|
||||
bool try_end_astral_projection();
|
||||
void fire_saturnus_tears();
|
||||
int GetMaxInventorySize();
|
||||
Entity_Pickup* DropCollectible(int collectible, Entity_Pickup* existing, bool isRemoveFromForm);
|
||||
Entity_Pickup* DropCollectibleByHistoryIndex(int index, Entity_Pickup* existing);
|
||||
bool CanAddCollectibleToInventory(int id);
|
||||
void SetPocketActiveItem(int collectible, int slot, bool keepInPools);
|
||||
void get_salvation_scale();
|
||||
|
||||
@@ -126,7 +126,6 @@ constexpr int NINE_VOLT_RECHARGE_FRAMES = 450;
|
||||
constexpr int NECROMANCER_FORM_ITEMS = 3;
|
||||
constexpr int OVERLAY_DELAY = 3;
|
||||
constexpr int PERCENT = 100;
|
||||
constexpr int PLAYERFORM_NECROMANCER = 15;
|
||||
constexpr int REVELATIONS_SOUL_HEARTS = 2;
|
||||
constexpr int REVELATIONS_STATE_FLAG = 7;
|
||||
constexpr int SUPLEX_AIMING = 2;
|
||||
@@ -433,7 +432,7 @@ int Entity_Player::GetCollectibleMaxCharge(int collectibleId, int varData)
|
||||
if (varData < GLOWING_HOUR_GLASS_LIT_USES) return 0;
|
||||
break;
|
||||
case COLLECTIBLE_NECRONOMICON:
|
||||
if (HasPlayerForm(PLAYERFORM_NECROMANCER) && varData == 1) return NECRONOMICON_FORM_CHARGES;
|
||||
if (HasPlayerForm(PLAYER_FORM_NECROMANCER) && varData == 1) return NECRONOMICON_FORM_CHARGES;
|
||||
break;
|
||||
}
|
||||
ItemConfig_Item* item = g_manager->itemConfig.GetCollectible(collectibleId);
|
||||
@@ -462,7 +461,7 @@ int Entity_Player::GetActiveMinUsableCharge(int slot)
|
||||
if (active.item == COLLECTIBLE_LARYNX || active.item == COLLECTIBLE_EVERYTHING_JAR ||
|
||||
active.item == COLLECTIBLE_NOTCHED_AXE)
|
||||
return 1;
|
||||
if (active.item == COLLECTIBLE_NECRONOMICON && HasPlayerForm(PLAYERFORM_NECROMANCER) && active.varData == 1)
|
||||
if (active.item == COLLECTIBLE_NECRONOMICON && HasPlayerForm(PLAYER_FORM_NECROMANCER) && active.varData == 1)
|
||||
return 1;
|
||||
return GetCollectibleMaxCharge(active.item, active.varData);
|
||||
}
|
||||
@@ -473,7 +472,7 @@ ChargeType active_charge_type(Entity_Player& player, int slot)
|
||||
{
|
||||
ActiveItemDesc& active = player.activeItems[slot];
|
||||
bool isNecromancer = !player.hasCurseMistEffect && !player.isCoopGhost &&
|
||||
player.playerForms[PLAYERFORM_NECROMANCER] >= NECROMANCER_FORM_ITEMS;
|
||||
player.playerForms[PLAYER_FORM_NECROMANCER] >= NECROMANCER_FORM_ITEMS;
|
||||
bool isFilledNecronomicon = active.item == COLLECTIBLE_NECRONOMICON && isNecromancer && active.varData == 1;
|
||||
|
||||
if (active.item == 0 || isFilledNecronomicon) return CHARGE_SPECIAL;
|
||||
@@ -1442,7 +1441,7 @@ static void use_overlay_show(Entity_Player& player, int item, int slot)
|
||||
isSkipped = player.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_BOOK_OF_BELIAL);
|
||||
break;
|
||||
case COLLECTIBLE_NECRONOMICON:
|
||||
isSkipped = player.HasPlayerForm(PLAYERFORM_NECROMANCER) && varData != 0;
|
||||
isSkipped = player.HasPlayerForm(PLAYER_FORM_NECROMANCER) && varData != 0;
|
||||
break;
|
||||
case COLLECTIBLE_DEAD_SEA_SCROLLS:
|
||||
isSkipped = player.itemState != 0;
|
||||
|
||||
@@ -27,7 +27,6 @@ constexpr int COLLECTIBLE_ROCKET_IN_A_JAR = 583;
|
||||
constexpr int COLLECTIBLE_BLOOD_BOMBS = 614;
|
||||
constexpr int COLLECTIBLE_BRIMSTONE_BOMBS = 646;
|
||||
constexpr int COLLECTIBLE_GHOST_BOMBS = 727;
|
||||
constexpr int TRINKET_BOBS_BLADDER = 71;
|
||||
constexpr int TRINKET_SHORT_FUSE = 133;
|
||||
constexpr int TRINKET_RING_CAP = 164;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "entity_player_characters.h"
|
||||
#include "entity_effect.h"
|
||||
#include "entity_familiar.h"
|
||||
#include "entity_player_tainted.h"
|
||||
#include "game.h"
|
||||
#include "hud.h"
|
||||
#include "item_overlay.h"
|
||||
@@ -85,10 +86,28 @@ bool is_azazel(Entity_Player& player)
|
||||
player.temporaryEffects.HasTrinketEffect(TRINKET_AZAZELS_STUMP);
|
||||
}
|
||||
|
||||
// Whether the frame and the stat evaluation are reconstructed for the player's character: the normal ones.
|
||||
bool is_character_reconstructed(const Entity_Player& player)
|
||||
// Whether the frame and the stat evaluation are reconstructed for the player's character: the normal ones and the
|
||||
// tainted ones the frame (00782af0, 00794e50) has no branch for. Tainted Judas's and Tainted Keeper's Birthright have
|
||||
// one.
|
||||
bool is_character_reconstructed(Entity_Player& player)
|
||||
{
|
||||
return player.playerType >= PLAYER_ISAAC && player.playerType <= PLAYER_ESAU;
|
||||
switch (player.playerType)
|
||||
{
|
||||
case PLAYER_JUDAS_B:
|
||||
case PLAYER_KEEPER_B:
|
||||
return !player.HasCollectible(COLLECTIBLE_BIRTHRIGHT);
|
||||
case PLAYER_ISAAC_B:
|
||||
case PLAYER_CAIN_B:
|
||||
case PLAYER_EVE_B:
|
||||
case PLAYER_AZAZEL_B:
|
||||
case PLAYER_EDEN_B:
|
||||
case PLAYER_THELOST_B:
|
||||
case PLAYER_APOLLYON_B:
|
||||
case PLAYER_BETHANY_B:
|
||||
return true;
|
||||
default:
|
||||
return player.playerType >= PLAYER_ISAAC && player.playerType <= PLAYER_ESAU;
|
||||
}
|
||||
}
|
||||
|
||||
// The tears up or down a character adds to the items' before Binge Eater's: Samson's, the tainted ones', Azazel's (or
|
||||
@@ -736,8 +755,7 @@ void Entity_Player::player_type_change_prepare(int oldType)
|
||||
if (oldType == PLAYER_JACOB || oldType == PLAYER_THEFORGOTTEN_B) remove_twin();
|
||||
}
|
||||
if (oldType == PLAYER_LAZARUS_B || oldType == PLAYER_LAZARUS2_B) remove_twin();
|
||||
if (playerType == PLAYER_ISAAC_B)
|
||||
reconstruction_missing("Entity_Player::player_type_change_prepare 007cf610 (Tainted Isaac's inventory)");
|
||||
if (playerType == PLAYER_ISAAC_B) tainted_isaac_inventory_trim(*this);
|
||||
if ((playerType == PLAYER_JACOB_B || playerType == PLAYER_JACOB2_B) &&
|
||||
!temporaryEffects.HasNullEffect(NULLITEM_JACOBS_CURSE))
|
||||
reconstruction_missing("Entity_Player::player_type_change_prepare 007cf610 (Tainted Jacob's curse)");
|
||||
|
||||
@@ -26,7 +26,7 @@ bool is_character_slowed(Entity_Player& player);
|
||||
|
||||
bool is_eden(const Entity_Player& player);
|
||||
bool is_azazel(Entity_Player& player);
|
||||
bool is_character_reconstructed(const Entity_Player& player);
|
||||
bool is_character_reconstructed(Entity_Player& player);
|
||||
|
||||
// Eve's Whore of Babylon and Tainted Eve's last heart (007c9ea0).
|
||||
bool is_whore_of_babylon_awake(Entity_Player& player);
|
||||
|
||||
@@ -44,7 +44,6 @@ constexpr int EFFECT_END_ITEMS[] = {66, 77, 93, 117, 282, 298, 299, 409, 497, 58
|
||||
|
||||
constexpr int DEAD_CAT_LIVES_PER_COPY = 9;
|
||||
constexpr int HEARTBREAK_BROKEN_HEARTS = 3;
|
||||
constexpr int PLAYER_FORM_LEO = 13;
|
||||
|
||||
// 00721b70 Takes an item out of the history: the first entry of the same kind and id, Tainted Isaac's inventory
|
||||
// following. A locked history keeps its items. Whether one was removed.
|
||||
@@ -100,7 +99,7 @@ void Entity_Player::SwapActiveItems()
|
||||
void Entity_Player::TriggerCollectibleRemoved(int collectibleId)
|
||||
{
|
||||
if (collectibleId == REMOVAL_MAGIC_MUSHROOM || collectibleId == REMOVAL_LEO)
|
||||
IncrementPlayerFormCounter(PLAYER_FORM_LEO, -1);
|
||||
IncrementPlayerFormCounter(PLAYER_FORM_STOMPY, -1);
|
||||
else if (collectibleId == REMOVAL_DEAD_CAT)
|
||||
deadCatLives = (short)std::min<int>(deadCatLives, GetCollectibleNum(REMOVAL_DEAD_CAT) * DEAD_CAT_LIVES_PER_COPY);
|
||||
else if (collectibleId == REMOVAL_HEARTBREAK) AddBrokenHearts(-HEARTBREAK_BROKEN_HEARTS);
|
||||
@@ -108,7 +107,7 @@ void Entity_Player::TriggerCollectibleRemoved(int collectibleId)
|
||||
if (GetCollectibleNum(collectibleId) <= 0)
|
||||
{
|
||||
if (collectibleId == REMOVAL_NECRONOMICON || collectibleId == REMOVAL_MISSING_PAGE_2)
|
||||
IncrementPlayerFormCounter(PLAYER_FORM_MISSING_PAGES, -1);
|
||||
IncrementPlayerFormCounter(PLAYER_FORM_NECROMANCER, -1);
|
||||
if (std::ranges::find(REMOVAL_EFFECT_ITEMS, collectibleId) != std::end(REMOVAL_EFFECT_ITEMS))
|
||||
reconstruction_missing("Entity_Player::TriggerCollectibleRemoved 0078ff90 (an item that made room)");
|
||||
}
|
||||
|
||||
@@ -31,9 +31,6 @@ constexpr int TRINKET_WALNUT = 108;
|
||||
constexpr int NULLITEM_BOOMERANG = 30;
|
||||
constexpr int NULLITEM_DOUBLE_DAMAGE = 29;
|
||||
constexpr int NULLITEM_SHACKLES_GHOST = 101;
|
||||
constexpr int PLAYER_FORM_ADULT = 11;
|
||||
constexpr int PLAYER_FORM_BEELZEBUB = 13;
|
||||
constexpr int PLAYER_FORM_BOB = 4;
|
||||
constexpr int SAMSON_B_HIT_CHARGE = 10000;
|
||||
constexpr int BLEED_OUT_HEALTH = 600;
|
||||
|
||||
@@ -422,7 +419,7 @@ static void hit_items_check(Entity_Player& player, uint64_t damageFlags, bool is
|
||||
{
|
||||
bool isItemHit = std::ranges::any_of(HIT_COLLECTIBLES, [&](int item) { return player.HasCollectible(item); }) ||
|
||||
std::ranges::any_of(HIT_TRINKETS, [&](int trinket) { return player.HasTrinket(trinket); }) ||
|
||||
(isPenalized && player.HasTrinket(TRINKET_PERFECTION)) || player.HasPlayerForm(PLAYER_FORM_BEELZEBUB) ||
|
||||
(isPenalized && player.HasTrinket(TRINKET_PERFECTION)) || player.HasPlayerForm(PLAYER_FORM_STOMPY) ||
|
||||
(player.HasCollectible(CROWN_OF_LIGHT) && !g_game->deathmatchManager.is_active()) ||
|
||||
(player.HasCollectible(COLLECTIBLE_HYPERCOAGULATION) && !(damageFlags & HYPERCOAGULATION_IGNORED)) ||
|
||||
std::ranges::any_of(player.activeItems, [](const ActiveItemDesc& active) { return active.item == COLLECTIBLE_LARYNX; });
|
||||
|
||||
@@ -19,7 +19,6 @@ constexpr int COLLECTIBLE_CHARM_VAMPIRE = 62;
|
||||
constexpr int COLLECTIBLE_ANKH = 161;
|
||||
constexpr int COLLECTIBLE_JUDAS_SHADOW = 311;
|
||||
constexpr int COLLECTIBLE_POLYDACTYLY = 454;
|
||||
constexpr int TRINKET_AAA_BATTERY = 3;
|
||||
constexpr int TRINKET_BROKEN_ANKH = 28;
|
||||
constexpr int TRINKET_LOCUST_OF_WRATH = 113;
|
||||
constexpr int TRINKET_LOCUST_OF_CONQUEST = 117;
|
||||
@@ -416,9 +415,9 @@ void Entity_Player::ClearTemporaryEffects()
|
||||
SetPocketActiveItem(0, ACTIVE_SLOT_COUNT - 1, false);
|
||||
}
|
||||
|
||||
// 007d41d0 Puts an active item in a pocket slot (2 or 3), the one there before removed with its pocket.
|
||||
// Only emptying the slot is reconstructed: a new item stops the game.
|
||||
void Entity_Player::SetPocketActiveItem(int collectible, int slot, bool)
|
||||
// 007d41d0 Puts an active item in a pocket slot (2 or 3), the one there before removed with its pocket. The new item
|
||||
// takes a pocket and leaves the pools unless kept there (Wait What? takes Butter Bean with it), but not in Cantripped.
|
||||
void Entity_Player::SetPocketActiveItem(int collectible, int slot, bool keepInPools)
|
||||
{
|
||||
if (slot < POCKET_ACTIVE_FIRST_SLOT || slot >= ACTIVE_SLOT_COUNT) return;
|
||||
|
||||
@@ -429,8 +428,14 @@ void Entity_Player::SetPocketActiveItem(int collectible, int slot, bool)
|
||||
std::shift_left(pocketItems.begin() + i, pocketItems.end(), 1);
|
||||
pocketItems.back() = {0, POCKET_CARD};
|
||||
}
|
||||
if (collectible != 0 && g_manager->itemConfig.GetCollectible(collectible))
|
||||
reconstruction_missing("Entity_Player::SetPocketActiveItem 007d41d0 (a new pocket active)");
|
||||
if (collectible == 0 || !g_manager->itemConfig.GetCollectible(collectible)) return;
|
||||
|
||||
AddPocketItem(slot + 1, POCKET_ACTIVE);
|
||||
AddCollectible(collectible, -1, true, slot, 0);
|
||||
ItemPool& pool = g_game->itemPool;
|
||||
if (keepInPools || collectible < 0 || g_game->challenge == CHALLENGE_CANTRIPPED) return;
|
||||
if (collectible == COLLECTIBLE_WAIT_WHAT) pool.RemoveCollectible(COLLECTIBLE_BUTTER_BEAN, REMOVE_ANY, REMOVE_APPLY);
|
||||
if (collectible < (int)pool.removedCollectibles.size()) pool.removedCollectibles[collectible] = true;
|
||||
}
|
||||
|
||||
// 007ad440 How many pocket slots the player has: one, two with Starter Deck, Little Baggy or Polydactyly, and one
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "game.h"
|
||||
#include "lua_engine.h"
|
||||
#include "room.h"
|
||||
#include "room_path.h"
|
||||
#include "log.h"
|
||||
#include "manager.h"
|
||||
#include <algorithm>
|
||||
@@ -49,9 +50,6 @@ constexpr int PILL_LUCK_DOWN = 17;
|
||||
constexpr int PILL_LUCK_UP = 18;
|
||||
constexpr int PILL_SHOT_SPEED_DOWN = 47;
|
||||
constexpr int PILL_SHOT_SPEED_UP = 48;
|
||||
constexpr int PLAYER_FORM_SPUN = 5;
|
||||
constexpr int PLAYER_FORM_CONJOINED = 7;
|
||||
constexpr int PLAYER_FORM_LEVIATHAN = 14;
|
||||
constexpr int TRINKET_CRACKED_CROWN = 92;
|
||||
constexpr int FAMILIAR_ITEM_WISP = 206;
|
||||
constexpr int COLLECTIBLE_FORTUNE_COOKIE = 557;
|
||||
@@ -97,6 +95,7 @@ constexpr float BERSERK_CHARGE_FULL = 100000;
|
||||
constexpr float HOLOGRAM_ALPHA = 0.2f;
|
||||
constexpr float COLOR_OFFSET_UNIT = 0.003921569f;
|
||||
constexpr float HELD_THROW_SCALE = 0.1f;
|
||||
constexpr float TAINTED_BETHANY_STAT_SCALE = 0.75f;
|
||||
|
||||
// Whether the player owns any of the listed collectibles.
|
||||
static bool is_owning_any(Entity_Player& player, std::span<const int> collectibles)
|
||||
@@ -234,6 +233,7 @@ static void fire_delay_evaluate(Entity_Player& p, const StatBonuses& bonus, floa
|
||||
else if (p.HasWeaponType(WEAPON_BOMBS)) rate /= 2.5f;
|
||||
else if (p.HasWeaponType(WEAPON_BONE)) rate *= 0.5f;
|
||||
if (has(152)) rate /= 1.5f;
|
||||
if (p.playerType == PLAYER_EVE_B) rate *= 0.66f;
|
||||
if (has(310)) rate *= 0.66f;
|
||||
if (p.HasWeaponType(WEAPON_MONSTROS_LUNGS)) rate /= 4.3f;
|
||||
else if (p.HasWeaponType(WEAPON_TECH_X) && has(229)) rate /= 3.1f;
|
||||
@@ -519,7 +519,7 @@ static void speed_evaluate(Entity_Player& p, const StatBonuses& bonus, float cro
|
||||
if (p.coopBabyBuffTimers[COOP_BUFF_SPEED] > 0) p.moveSpeed = p.moveSpeed + 0.15f;
|
||||
if (has(230)) p.moveSpeed = p.moveSpeed + 0.2f;
|
||||
if (p.HasPlayerForm(PLAYER_FORM_SPUN)) p.moveSpeed = p.moveSpeed + 0.15f;
|
||||
if (p.HasPlayerForm(PLAYER_FORM_LEVIATHAN)) p.moveSpeed = p.moveSpeed + 0.2f;
|
||||
if (p.HasPlayerForm(PLAYER_FORM_FLIGHT)) p.moveSpeed = p.moveSpeed + 0.2f;
|
||||
if (has(130) || has(181)) p.moveSpeed = std::max(p.moveSpeed, 1.5f);
|
||||
if (has(COLLECTIBLE_TAURUS) || p.GetZodiacEffect() == COLLECTIBLE_TAURUS) p.moveSpeed = p.moveSpeed - 0.3f;
|
||||
if (has(300) || p.GetZodiacEffect() == 300) p.moveSpeed = p.moveSpeed + 0.25f;
|
||||
@@ -803,14 +803,14 @@ static bool is_flying(Entity_Player& p)
|
||||
TemporaryEffects& effects = p.temporaryEffects;
|
||||
int wings = effects.GetCollectibleEffectNum(20);
|
||||
for (int id : {185, 184, 181, 179, 159, 130, 82, 20}) wings += p.GetCollectibleNum(id);
|
||||
if (wings >= 1 || p.HasPlayerForm(0) || p.HasPlayerForm(1) || p.HasPlayerForm(8)) return true;
|
||||
if (wings >= 1 || p.HasPlayerForm(PLAYER_FORM_GUPPY) || p.HasPlayerForm(PLAYER_FORM_BEELZEBUB) || p.HasPlayerForm(PLAYER_FORM_LEVIATHAN)) return true;
|
||||
|
||||
bool isFlyingType = p.variant == PLAYER_VARIANT_COOP_BABY || p.playerType == PLAYER_THELOST ||
|
||||
p.playerType == PLAYER_THELOST_B || p.playerType == PLAYER_JACOB2_B ||
|
||||
p.playerType == PLAYER_THESOUL_B || p.playerType == PLAYER_AZAZEL ||
|
||||
p.playerType == PLAYER_THESOUL;
|
||||
return isFlyingType || p.HasPlayerForm(3) || effects.HasCollectibleEffect(33) || effects.HasCollectibleEffect(20) ||
|
||||
effects.HasCollectibleEffect(409) || effects.HasTrinketEffect(118) || p.HasPlayerForm(14) ||
|
||||
return isFlyingType || p.HasPlayerForm(PLAYER_FORM_SERAPHIM) || effects.HasCollectibleEffect(33) || effects.HasCollectibleEffect(20) ||
|
||||
effects.HasCollectibleEffect(409) || effects.HasTrinketEffect(118) || p.HasPlayerForm(PLAYER_FORM_FLIGHT) ||
|
||||
effects.GetCollectibleEffectNum(COLLECTIBLE_ASTRAL_PROJECTION) == 1 ||
|
||||
effects.HasNullEffect(NULLITEM_REVERSE_SUN) || effects.HasNullEffect(NULLITEM_REVERSE_DEVIL) ||
|
||||
effects.HasNullEffect(NULLITEM_ESAU_JR) || effects.HasNullEffect(NULLITEM_SPIRIT_SHACKLES_SOUL) ||
|
||||
@@ -819,16 +819,30 @@ static bool is_flying(Entity_Player& p)
|
||||
p.HasCollectible(633);
|
||||
}
|
||||
|
||||
// The flying section of 00763570: flight and the grid collision it gives. Losing flight asks whether the player can
|
||||
// walk back to the entrance (the original keeps it flying by a Transcendence effect if not), which stops the game.
|
||||
// 007d1810 Whether a player on the ground is stranded: one colliding with the floor that cannot walk to the entrance.
|
||||
static bool is_stranded_on_ground(Entity_Player& p)
|
||||
{
|
||||
int collision = p.entityGridCollisionClass;
|
||||
bool isGrounded = collision != GRIDCOLL_NONE && collision != GRIDCOLL_WALLS && collision != GRIDCOLL_WALLS_X &&
|
||||
collision != GRIDCOLL_WALLS_Y;
|
||||
return isGrounded && !is_reachable_from_player(*g_game->room, {p.pos, &p, REACH_ENTRANCE});
|
||||
}
|
||||
|
||||
// The flying section of 00763570: flight and the grid collision it gives. A player losing flight where it cannot walk
|
||||
// to the entrance keeps flying by a Bible effect.
|
||||
static void flying_evaluate(Entity_Player& p)
|
||||
{
|
||||
bool wasFlying = p.canFly;
|
||||
|
||||
p.canFly = is_flying(p);
|
||||
p.entityGridCollisionClass = p.canFly ? GRIDCOLL_WALLS : GRIDCOLL_GROUND;
|
||||
if (wasFlying && !p.canFly)
|
||||
reconstruction_missing("Entity_Player::EvaluateItems 00763570 (Room::is_reachable_from_player 00823be0)");
|
||||
if (wasFlying && !p.canFly && is_stranded_on_ground(p))
|
||||
{
|
||||
p.canFly = true;
|
||||
p.entityGridCollisionClass = GRIDCOLL_WALLS;
|
||||
if (!p.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_BIBLE))
|
||||
p.temporaryEffects.AddCollectibleEffect(COLLECTIBLE_BIBLE, true, 1);
|
||||
}
|
||||
static_cast<LuaEngine*>(g_luaEngine)->EvaluateItems(&p, CACHE_FLYING);
|
||||
p.entityGridCollisionClass = p.canFly ? GRIDCOLL_WALLS : GRIDCOLL_GROUND;
|
||||
if (p.canFly != wasFlying) p.UpdateCostumes();
|
||||
@@ -995,6 +1009,7 @@ void Entity_Player::EvaluateItems()
|
||||
|
||||
StatBonuses bonus = stat_bonuses_get(*this);
|
||||
float crownScale = (float)GetTrinketMultiplier(TRINKET_CRACKED_CROWN) * 0.2f + 1;
|
||||
if (playerType == PLAYER_BETHANY_B) crownScale *= TAINTED_BETHANY_STAT_SCALE;
|
||||
if (cacheFlags & CACHE_WEAPON) weapons_evaluate(*this);
|
||||
if (cacheFlags & CACHE_SHOTSPEED) cacheFlags |= CACHE_RANGE;
|
||||
if (cacheFlags & CACHE_FIREDELAY) fire_delay_evaluate(*this, bonus, crownScale);
|
||||
|
||||
@@ -20,8 +20,6 @@ constexpr int FORGOTTEN_SWAP_HOLD_COOLDOWN = 10;
|
||||
constexpr int D_INFINITY_FACES = 10;
|
||||
constexpr int D_INFINITY_FACE_SHIFT = 16;
|
||||
constexpr int D_INFINITY_FACE_MASK = 0xffff;
|
||||
constexpr int TAINTED_ISAAC_SLOTS = 8;
|
||||
constexpr int TAINTED_ISAAC_BIRTHRIGHT_SLOTS = 12;
|
||||
constexpr uint32_t DROP_HOLD_FRAMES = 120;
|
||||
constexpr uint32_t SPECIAL_DAILY_NO_DROP = 4;
|
||||
constexpr int ACTION_TRIGGER_DROP = 0x20;
|
||||
@@ -423,7 +421,7 @@ static void tainted_inventory_rotate(Entity_Player& player)
|
||||
|
||||
if (player.playerType == PLAYER_ISAAC_B)
|
||||
{
|
||||
int limit = player.HasCollectible(COLLECTIBLE_BIRTHRIGHT) ? TAINTED_ISAAC_BIRTHRIGHT_SLOTS : TAINTED_ISAAC_SLOTS;
|
||||
int limit = player.GetMaxInventorySize();
|
||||
auto end = std::find_if(player.inventory.begin(), player.inventory.begin() + limit, [](int entry) { return entry < 0; });
|
||||
if (end - player.inventory.begin() > 1)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
#include "entity_effect.h"
|
||||
#include "entity_pickup.h"
|
||||
#include "entity_player.h"
|
||||
#include "game.h"
|
||||
#include "hud.h"
|
||||
#include "item_overlay.h"
|
||||
#include "manager.h"
|
||||
#include "menu_options.h"
|
||||
#include "player_stats.h"
|
||||
#include "room_grid.h"
|
||||
#include "sfx_manager.h"
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
// The unlocks Guppy and Beelzebub give.
|
||||
constexpr int ACHIEVEMENT_GUPPYS_HAIRBALL = 65;
|
||||
constexpr int ACHIEVEMENT_LORD_OF_THE_FLIES = 178;
|
||||
constexpr int ACHIEVEMENT_ANGRY_FLY = 352;
|
||||
|
||||
// The health the transformations give the first time: Fun Guy's and Adult's heart, Seraphim's soul hearts and
|
||||
// Leviathan's black hearts, in halves.
|
||||
constexpr int FORM_HEART_HALVES = 2;
|
||||
constexpr int SERAPHIM_SOUL_HALVES = 6;
|
||||
constexpr int LEVIATHAN_BLACK_HALVES = 4;
|
||||
|
||||
// Where Spun's pill drops, and the poof a transformation shows under the player.
|
||||
constexpr float SPUN_PILL_STEP = 40;
|
||||
constexpr float FORM_POOF_OFFSET_Y = 5;
|
||||
constexpr int FORM_POOF_SUBTYPE = 2;
|
||||
|
||||
// Whether the player was given this transformation's reward already.
|
||||
static bool is_form_rewarded(Entity_Player& player, int form)
|
||||
{
|
||||
return player.playerFormsRewarded & (1u << form);
|
||||
}
|
||||
|
||||
// Announces the Necromancer: its sound and the Necronomicon's giant book.
|
||||
static void necromancer_announce()
|
||||
{
|
||||
sound_play(SOUND_NECROMANCER);
|
||||
g_game->itemOverlay.Show(GIANTBOOK_NECROMANCER, 3, nullptr);
|
||||
}
|
||||
|
||||
// The Necromancer's part of 0075e320: the first Necronomicon already turned stays the Necromancer's book (charged the
|
||||
// first time) and the others turn back. Gaining it with none turned turns the first held one.
|
||||
static void necronomicon_transform(Entity_Player& player, bool isActive)
|
||||
{
|
||||
bool isRewarded = is_form_rewarded(player, PLAYER_FORM_NECROMANCER);
|
||||
bool isFound = false;
|
||||
for (int slot = 0; slot < ACTIVE_SLOT_COUNT; slot++)
|
||||
{
|
||||
ActiveItemDesc& active = player.activeItems[slot];
|
||||
if (active.item != COLLECTIBLE_NECRONOMICON) continue;
|
||||
|
||||
if (isFound) active.varData = 0;
|
||||
else if (active.varData == 1)
|
||||
{
|
||||
if (!isRewarded) player.AddActiveCharge(player.GetActiveMaxCharge(slot), slot, false, false, true);
|
||||
if (isActive) necromancer_announce();
|
||||
isFound = true;
|
||||
}
|
||||
sound_play(SOUND_NECROMANCER);
|
||||
g_game->hud.InvalidateActiveItem(&player, slot);
|
||||
}
|
||||
if (isFound || !isActive) return;
|
||||
|
||||
int slot = player.GetActiveItemSlot(COLLECTIBLE_NECRONOMICON);
|
||||
if (slot < 0) return;
|
||||
|
||||
player.activeItems[slot].varData = !isRewarded;
|
||||
if (!isRewarded) player.AddActiveCharge(player.GetActiveMaxCharge(slot), slot, false, false, true);
|
||||
g_game->hud.InvalidateActiveItem(&player, slot);
|
||||
necromancer_announce();
|
||||
}
|
||||
|
||||
// What a transformation gives the first time it is gained: Guppy's and Beelzebub's unlocks (every time), health or
|
||||
// Spun's pill.
|
||||
static void form_reward(Entity_Player& player, int form)
|
||||
{
|
||||
PersistentGameData& save = g_manager->persistentGameData;
|
||||
bool isRewarded = is_form_rewarded(player, form);
|
||||
switch (form)
|
||||
{
|
||||
case PLAYER_FORM_GUPPY: save.TryUnlock(ACHIEVEMENT_GUPPYS_HAIRBALL); break;
|
||||
case PLAYER_FORM_BEELZEBUB:
|
||||
save.TryUnlock(ACHIEVEMENT_LORD_OF_THE_FLIES);
|
||||
save.TryUnlock(ACHIEVEMENT_ANGRY_FLY);
|
||||
break;
|
||||
case PLAYER_FORM_FUN_GUY:
|
||||
case PLAYER_FORM_ADULT:
|
||||
if (isRewarded) break;
|
||||
player.AddMaxHearts(FORM_HEART_HALVES, false);
|
||||
player.AddHearts(FORM_HEART_HALVES, false, false);
|
||||
break;
|
||||
case PLAYER_FORM_SERAPHIM:
|
||||
if (!isRewarded) player.AddSoulHearts(SERAPHIM_SOUL_HALVES, false);
|
||||
break;
|
||||
case PLAYER_FORM_SPUN:
|
||||
{
|
||||
if (isRewarded) break;
|
||||
uint32_t seed = player.GetCollectibleRNG(COLLECTIBLE_VIRUS).Next();
|
||||
g_game->Spawn({.position = room_free_pickup_position_find({.position = player.pos, .step = SPUN_PILL_STEP}),
|
||||
.spawner = &player,
|
||||
.type = ENTITY_PICKUP,
|
||||
.variant = PICKUP_PILL,
|
||||
.seed = seed});
|
||||
break;
|
||||
}
|
||||
case PLAYER_FORM_LEVIATHAN:
|
||||
if (!isRewarded) player.AddBlackHearts(LEVIATHAN_BLACK_HALVES);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 0075e320 Counts items towards a transformation (the Necromancer's from the Necronomicon, Missing Page 2 and the
|
||||
// Missing Page). Gaining one evaluates its stats, rewards it, dresses the player and announces it. Losing one takes its
|
||||
// costume off. A form outside the counters is ignored, where the original writes past them.
|
||||
void Entity_Player::IncrementPlayerFormCounter(int form, int num)
|
||||
{
|
||||
if (form < 0 || form >= PLAYER_FORM_SLOTS) return;
|
||||
|
||||
bool wasActive = HasPlayerForm(form);
|
||||
playerForms[form] = std::max(playerForms[form] + num, 0);
|
||||
if (form == PLAYER_FORM_NECROMANCER)
|
||||
playerForms[form] = (int)HasCollectible(COLLECTIBLE_NECRONOMICON) +
|
||||
(int)HasCollectible(COLLECTIBLE_MISSING_PAGE_2) + (int)HasTrinket(TRINKET_MISSING_PAGE);
|
||||
bool isActive = HasPlayerForm(form);
|
||||
if (isActive == wasActive) return;
|
||||
|
||||
if (isActive) Player_stats_add(g_game->onlinePlayerStats, ONLINE_STAT_TRANSFORMATIONS, this, 1);
|
||||
ItemConfig& items = g_manager->itemConfig;
|
||||
ItemConfig_PlayerForm* config = form < (int)items.playerForms.size() ? items.playerForms[form].get() : nullptr;
|
||||
if (config) cacheFlags |= config->cacheFlags;
|
||||
if (form == PLAYER_FORM_NECROMANCER) necronomicon_transform(*this, isActive);
|
||||
if (!isActive)
|
||||
{
|
||||
if (config && config->costume != -1) RemoveCostume(items.GetNullItem(config->costume));
|
||||
return;
|
||||
}
|
||||
|
||||
form_reward(*this, form);
|
||||
AddPlayerFormCostume(form);
|
||||
if (config)
|
||||
{
|
||||
std::string name(string_table_translate(g_manager->stringTable, config->name));
|
||||
g_game->hud.ShowStackedItemTextCustom(name.c_str(), "");
|
||||
}
|
||||
sound_play(SOUND_POWERUP_SPEWER);
|
||||
g_game->Spawn({.position = vector_make(pos.x, pos.y + FORM_POOF_OFFSET_Y),
|
||||
.spawner = this,
|
||||
.subType = FORM_POOF_SUBTYPE,
|
||||
.type = ENTITY_EFFECT,
|
||||
.variant = EFFECT_POOF01,
|
||||
.seed = Random()});
|
||||
playerFormsRewarded |= 1u << form;
|
||||
}
|
||||
|
||||
// 0075e9a0 Puts on a transformation's costume, if it has one.
|
||||
void Entity_Player::AddPlayerFormCostume(int form)
|
||||
{
|
||||
ItemConfig& items = g_manager->itemConfig;
|
||||
if (form < 0 || form >= (int)items.playerForms.size() || !items.playerForms[form]) return;
|
||||
|
||||
int costume = items.playerForms[form]->costume;
|
||||
if (costume != -1) AddCostume(items.GetNullItem(costume), false);
|
||||
}
|
||||
@@ -645,10 +645,9 @@ void Entity_Player::update_shooting()
|
||||
|
||||
// The temporary effects' part of 00782af0: Mars' dash, a pony's charge and Recall ignore knockback, the stats are
|
||||
// evaluated when the effects changed, and the timed ones count down. The items' frame (update_effects) is not reached
|
||||
// by a plain player.
|
||||
// by a plain player, but its closing PostPEffectUpdate callback is.
|
||||
static void temporary_effects_update(Entity_Player& player)
|
||||
{
|
||||
|
||||
TemporaryEffects& effects = player.temporaryEffects;
|
||||
bool isDashing = effects.HasCollectibleEffect(COLLECTIBLE_MARS) || player.ponyCharge >= 1 ||
|
||||
effects.HasCollectibleEffect(COLLECTIBLE_RECALL);
|
||||
@@ -660,7 +659,10 @@ static void temporary_effects_update(Entity_Player& player)
|
||||
player.EvaluateItems();
|
||||
}
|
||||
effects.isEvaluateCachePending = false;
|
||||
if (!player.HasEntityFlags(FLAG_INTERPOLATION_UPDATE)) effects.Update();
|
||||
if (player.HasEntityFlags(FLAG_INTERPOLATION_UPDATE)) return;
|
||||
|
||||
effects.Update();
|
||||
lua_engine_get().PostPEffectUpdate(&player);
|
||||
}
|
||||
|
||||
// 00782af0 The player's frame. Only the frame of a plain character is reconstructed: the base entity moves it, it walks
|
||||
|
||||
@@ -600,8 +600,6 @@ constexpr int SWARM_FLIES = 8;
|
||||
constexpr int EXPERIMENTAL_STATS = 7;
|
||||
constexpr int EXPERIMENTAL_CHANGES = 6;
|
||||
constexpr int EXPERIMENTAL_UPS = 4;
|
||||
constexpr int PLAYER_FORM_STOMPY = 13;
|
||||
constexpr int PLAYER_FORM_PAGES = 15;
|
||||
constexpr uint32_t CURSES_ALL = 0xffffffff;
|
||||
constexpr uint32_t CHAOS_PICKUP_MASK = 7;
|
||||
constexpr int CHAOS_PICKUP_MAX = 6;
|
||||
@@ -767,20 +765,6 @@ void Entity_Player::UpdateBookOfVirtues(bool isAddedBookOfVirtues)
|
||||
active.varData = 0;
|
||||
}
|
||||
|
||||
// 0075e320 Counts items towards a transformation (the Missing Pages' from its two books and trinket). Only the counting is
|
||||
// reconstructed: a transformation won or lost stops the game until reached.
|
||||
void Entity_Player::IncrementPlayerFormCounter(int ePlayerForm, int num)
|
||||
{
|
||||
|
||||
bool wasActive = HasPlayerForm(ePlayerForm);
|
||||
playerForms[ePlayerForm] = std::max(playerForms[ePlayerForm] + num, 0);
|
||||
if (ePlayerForm == PLAYER_FORM_MISSING_PAGES)
|
||||
playerForms[ePlayerForm] = (int)HasCollectible(COLLECTIBLE_NECRONOMICON) +
|
||||
(int)HasCollectible(COLLECTIBLE_MISSING_PAGE_2) + (int)HasTrinket(TRINKET_MISSING_PAGE);
|
||||
if (HasPlayerForm(ePlayerForm) != wasActive)
|
||||
reconstruction_missing("Entity_Player::IncrementPlayerFormCounter 0075e320 (a transformation)");
|
||||
}
|
||||
|
||||
// The run's unlocks for holding many items: the tag sets, Blood Clot's and Rubber Cement's counters, ten tears ups and
|
||||
// three star items.
|
||||
void Entity_Player::collectible_unlocks_check(int collectibleId, ItemConfig_Item& item)
|
||||
@@ -1092,7 +1076,7 @@ static void collectible_effect_apply(Entity_Player& p, const CollectibleGain& ga
|
||||
return;
|
||||
case 35:
|
||||
case 262:
|
||||
p.IncrementPlayerFormCounter(PLAYER_FORM_PAGES, 1);
|
||||
p.IncrementPlayerFormCounter(PLAYER_FORM_NECROMANCER, 1);
|
||||
return;
|
||||
case 54:
|
||||
game.ApplyMapEffect();
|
||||
@@ -1507,6 +1491,9 @@ void Entity_Player::costume_layers_map(SkinColors& colors)
|
||||
}
|
||||
}
|
||||
|
||||
// The color Black Judas and Tainted Judas darken a costume with when their folder has no sheet for it (00c5d090).
|
||||
constexpr ColorMod BLACK_JUDAS_COSTUME_TINT = {{0, 0, 0, 1}, {0, 0, 0, 0}, {0.0314f, 0, 0}};
|
||||
|
||||
// The UpdateCostumes part that dresses a mapped costume for the character: its sheets from the character's costume
|
||||
// folder and, for a costume with skin alts drawn for another skin, the skin color's sheets, darkened for Black Judas
|
||||
// when the folder has none, and its animation kept as it was. The dark tint is the one the original keeps in its data.
|
||||
@@ -1516,7 +1503,6 @@ void Entity_Player::costume_skin_apply(CostumeSpriteDesc& costume, int skinColor
|
||||
bool isAlt = costume.isHasSkinAlt && costume.defaultSkinColor != skinColor;
|
||||
bool isAnyFound = false;
|
||||
|
||||
if (isDark) reconstruction_missing("Entity_Player::UpdateCostumes 0075bf00 (Black Judas's costume tint)");
|
||||
std::string animation = costume.sprite.animState.animData ? costume.sprite.GetAnimation() : std::string();
|
||||
bool isPlaying = costume.sprite.animState.animData && costume.sprite.animState.isPlaying;
|
||||
int frame = (int)costume.sprite.animState.animFrame;
|
||||
@@ -1530,7 +1516,8 @@ void Entity_Player::costume_skin_apply(CostumeSpriteDesc& costume, int skinColor
|
||||
std::string skinned = costume_path_apply_skin_color(path, isAlt ? skinColor : -1, playerType,
|
||||
isAlt ? &isSkinFound : nullptr, &isCharacterFound);
|
||||
costume.sprite.ReplaceSpritesheet(layer, skinned);
|
||||
if (LayerState* recolored = costume.sprite.GetLayer(layer)) recolored->color = COLOR_DEFAULT;
|
||||
if (LayerState* recolored = costume.sprite.GetLayer(layer))
|
||||
recolored->color = isDark && !isCharacterFound ? BLACK_JUDAS_COSTUME_TINT : COLOR_DEFAULT;
|
||||
isAnyFound |= isSkinFound || isCharacterFound;
|
||||
}
|
||||
if (isAlt && !isAnyFound && !is_eden_hair(costume.item))
|
||||
|
||||
@@ -27,7 +27,6 @@ Entity_Familiar* Entity_Player::AddItemWisp(int, Vector, bool)
|
||||
}
|
||||
void Entity_Player::ResetDamageCooldown() { reconstruction_missing("Entity_Player::ResetDamageCooldown 0060d090"); }
|
||||
Vector Entity_Player::SpriteScale() { reconstruction_missing("Entity_Player::SpriteScale 0060d0a0"); }
|
||||
bool Entity_Player::IsP2Appearing() { reconstruction_missing("Entity_Player::IsP2Appearing 0065cf60"); }
|
||||
void Entity_Player::set_last_damage(uint64_t, const EntityRef&)
|
||||
{
|
||||
reconstruction_missing("Entity_Player::set_last_damage 006dad80");
|
||||
@@ -48,10 +47,6 @@ void Entity_Player::trigger_max_hearts_removed(int)
|
||||
void Entity_Player::RemoveBlackHeart(int) { reconstruction_missing("Entity_Player::RemoveBlackHeart 007591e0"); }
|
||||
void Entity_Player::AddGoldenKey() { reconstruction_missing("Entity_Player::AddGoldenKey 00759620"); }
|
||||
void Entity_Player::RemoveGoldenKey() { reconstruction_missing("Entity_Player::RemoveGoldenKey 00759660"); }
|
||||
void Entity_Player::restore_curse_mist_backup(int*)
|
||||
{
|
||||
reconstruction_missing("Entity_Player::restore_curse_mist_backup 00759950");
|
||||
}
|
||||
void Entity_Player::RemoveBlueFly() { reconstruction_missing("Entity_Player::RemoveBlueFly 00759b80"); }
|
||||
void Entity_Player::AddLeprosy() { reconstruction_missing("Entity_Player::AddLeprosy 00759b90"); }
|
||||
Entity* Entity_Player::AddBoneOrbital(Vector) { reconstruction_missing("Entity_Player::AddBoneOrbital 00759bc0"); }
|
||||
@@ -60,10 +55,6 @@ Entity* Entity_Player::AddSwarmFlyOrbital(Vector)
|
||||
reconstruction_missing("Entity_Player::AddSwarmFlyOrbital 00759bf0");
|
||||
}
|
||||
void Entity_Player::AddNullCostume(int) { reconstruction_missing("Entity_Player::AddNullCostume 0075d800"); }
|
||||
void Entity_Player::AddPlayerFormCostume(int)
|
||||
{
|
||||
reconstruction_missing("Entity_Player::AddPlayerFormCostume 0075e9a0");
|
||||
}
|
||||
void Entity_Player::SetItemState(int) { reconstruction_missing("Entity_Player::SetItemState 0075ea20"); }
|
||||
void Entity_Player::RespawnFamiliars() { reconstruction_missing("Entity_Player::RespawnFamiliars 00770600"); }
|
||||
void Entity_Player::GetNPCTarget() { reconstruction_missing("Entity_Player::GetNPCTarget 00770610"); }
|
||||
@@ -81,7 +72,6 @@ bool Entity_Player::TryRemoveSmeltedTrinket(uint32_t)
|
||||
reconstruction_missing("Entity_Player::TryRemoveSmeltedTrinket 00772260");
|
||||
}
|
||||
bool Entity_Player::replace_trinket() { reconstruction_missing("Entity_Player::replace_trinket 00772530"); }
|
||||
uint32_t Entity_Player::CanTurnHead() { reconstruction_missing("Entity_Player::CanTurnHead 00782a60"); }
|
||||
void Entity_Player::RemoveCollectibleByHistoryIndex(int, bool)
|
||||
{
|
||||
reconstruction_missing("Entity_Player::RemoveCollectibleByHistoryIndex 0078fec0");
|
||||
@@ -99,7 +89,8 @@ void Entity_Player::AnimateTrinket(int, std::string_view, std::string_view)
|
||||
reconstruction_missing("Entity_Player::AnimateTrinket 007ab550");
|
||||
}
|
||||
void Entity_Player::AnimateTrapdoor() { reconstruction_missing("Entity_Player::AnimateTrapdoor 007abc00"); }
|
||||
void Entity_Player::AnimateLightTravel() { reconstruction_missing("Entity_Player::AnimateLightTravel 007abc10"); }
|
||||
// 007abc10 Plays the rise up a beam of light.
|
||||
void Entity_Player::AnimateLightTravel() { PlayExtraAnimation("LightTravel"); }
|
||||
void Entity_Player::AnimateAppear() { reconstruction_missing("Entity_Player::AnimateAppear 007abcb0"); }
|
||||
void Entity_Player::AnimateTeleport(bool) { reconstruction_missing("Entity_Player::AnimateTeleport 007abcc0"); }
|
||||
void Entity_Player::AddPrettyFly() { reconstruction_missing("Entity_Player::AddPrettyFly 007abdf0"); }
|
||||
@@ -218,7 +209,6 @@ void Entity_Player::ThrowFriendlyDip(int, Vector, Vector)
|
||||
void Entity_Player::AddUrnSouls(uint32_t) { reconstruction_missing("Entity_Player::AddUrnSouls 007d3480"); }
|
||||
void Entity_Player::AddGigaBombs(int) { reconstruction_missing("Entity_Player::AddGigaBombs 007d34f0"); }
|
||||
void Entity_Player::fire_saturnus_tears() { reconstruction_missing("Entity_Player::fire_saturnus_tears 007d3e40"); }
|
||||
int Entity_Player::GetMaxInventorySize() { reconstruction_missing("Entity_Player::GetMaxInventorySize 007d4150"); }
|
||||
void Entity_Player::get_salvation_scale() { reconstruction_missing("Entity_Player::get_salvation_scale 007d4340"); }
|
||||
void Entity_Player::update_suplex() { reconstruction_missing("Entity_Player::update_suplex 007d4390"); }
|
||||
uint32_t Entity_Player::bag_of_crafting_collect(Entity_Pickup*)
|
||||
@@ -242,8 +232,6 @@ void Entity_Player::spawn_lil_clot_familiars()
|
||||
}
|
||||
void Entity_Player::creep_contact_add(int, int) { reconstruction_missing("Entity_Player::creep_contact_add 007d8740"); }
|
||||
bool Entity_Player::spawn_ghost_corpse() { reconstruction_missing("Entity_Player::spawn_ghost_corpse 007d87a0"); }
|
||||
void Entity_Player::AddCurseMistEffect() { reconstruction_missing("Entity_Player::AddCurseMistEffect 007d8980"); }
|
||||
void Entity_Player::RemoveCurseMistEffect() { reconstruction_missing("Entity_Player::RemoveCurseMistEffect 007d8d20"); }
|
||||
void Entity_Player::AttachMinecart(Entity_NPC*) { reconstruction_missing("Entity_Player::AttachMinecart 007d9180"); }
|
||||
void Entity_Player::add_samson_berserk_charge(int)
|
||||
{
|
||||
@@ -292,5 +280,4 @@ void Entity_Player::PlayCollectibleAnim(int, bool, std::string_view, int)
|
||||
{
|
||||
reconstruction_missing("Entity_Player::PlayCollectibleAnim 00759f50");
|
||||
}
|
||||
bool History::RemoveHistoryItemByIndex(int) { reconstruction_missing("History::RemoveHistoryItemByIndex 00721c00"); }
|
||||
void History::merge(History&) { reconstruction_missing("History::merge 00721c80"); }
|
||||
@@ -0,0 +1,150 @@
|
||||
#include "entity_player.h"
|
||||
#include "boss_ai.h"
|
||||
#include "entity_familiar.h"
|
||||
#include "game.h"
|
||||
#include "player_manager.h"
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
|
||||
// The caps Curse of the Mist's consumables come back under: 99 (999 coins with Deep Pockets, 29 poop mana with Tainted
|
||||
// ???'s Birthright, 9 without).
|
||||
constexpr int MIST_CONSUMABLE_CAP = 99;
|
||||
constexpr int MIST_DEEP_POCKETS_COIN_CAP = 999;
|
||||
constexpr int MIST_POOP_MANA_CAP = 9;
|
||||
constexpr int MIST_BIRTHRIGHT_POOP_MANA_CAP = 29;
|
||||
|
||||
// The familiars the mist keeps aside, which hold their own state: Bumbo, Damocles and the abyss locusts.
|
||||
static bool is_mist_kept_familiar(int variant)
|
||||
{
|
||||
return variant == Entity_Familiar::BUMBO || variant == Entity_Familiar::DAMOCLES ||
|
||||
variant == Entity_Familiar::ABYSS_LOCUST;
|
||||
}
|
||||
|
||||
// 00759950 Gives the player a set of consumables, and (a real player) tells the HUD they changed.
|
||||
void Entity_Player::restore_curse_mist_backup(const ConsumableData& backup)
|
||||
{
|
||||
numCoins = backup.coins;
|
||||
numKeys = backup.keys;
|
||||
numBombs = backup.bombs;
|
||||
hasGoldenKey = backup.isGoldenKey;
|
||||
hasGoldenBomb = backup.isGoldenBomb;
|
||||
numGigaBombs = backup.gigaBombs;
|
||||
effectiveSoulCharge = backup.soulCharges;
|
||||
effectiveBloodCharge = backup.bloodCharges;
|
||||
poopMana = backup.poopMana;
|
||||
if (isValid) ConsumableCountChanged(-1);
|
||||
}
|
||||
|
||||
// 007d8980 Puts the player under Curse of the Mist (the mineshaft's): it stops bleeding out and, a real player, sets its
|
||||
// consumables and its Bumbo, Damocles and locusts aside (the locusts leave) to start from nothing. Its pockets and
|
||||
// trinkets go aside too, then its stats are evaluated again. Keeper keeps his coin hearts aside.
|
||||
void Entity_Player::AddCurseMistEffect()
|
||||
{
|
||||
if (hasCurseMistEffect) return;
|
||||
|
||||
if (backupPlayer && isValid) backupPlayer->AddCurseMistEffect();
|
||||
ClearEntityFlags(FLAG_BLEED_OUT);
|
||||
cacheFlags |= CACHE_ALL;
|
||||
bleedOutHealth = 0;
|
||||
hasCurseMistEffect = true;
|
||||
UpdateCostumes();
|
||||
|
||||
if (isValid)
|
||||
{
|
||||
consumablesBackup = {.bloodCharges = effectiveBloodCharge,
|
||||
.bombs = numBombs,
|
||||
.coins = numCoins,
|
||||
.gigaBombs = numGigaBombs,
|
||||
.keys = numKeys,
|
||||
.poopMana = poopMana,
|
||||
.soulCharges = effectiveSoulCharge,
|
||||
.isGoldenBomb = hasGoldenBomb,
|
||||
.isGoldenKey = hasGoldenKey};
|
||||
restore_curse_mist_backup({});
|
||||
curseMistFamiliars.clear();
|
||||
for (Entity* entity : entity_query(ENTITY_FAMILIAR, -1))
|
||||
{
|
||||
if (!is_mist_kept_familiar(entity->variant)) continue;
|
||||
|
||||
static_cast<Entity_Familiar*>(entity)->store_backup(&curseMistFamiliars.emplace_back());
|
||||
if (entity->variant == Entity_Familiar::ABYSS_LOCUST) entity->Remove();
|
||||
}
|
||||
}
|
||||
|
||||
curseMistPocketItems = pocketItems;
|
||||
pocketItems.fill({});
|
||||
curseMistTrinkets = trinkets;
|
||||
trinkets.fill(0);
|
||||
EvaluateItems();
|
||||
if (playerType != PLAYER_KEEPER) return;
|
||||
|
||||
curseMistRedHearts = redHearts;
|
||||
AddMaxHearts(0, false);
|
||||
}
|
||||
|
||||
// 007d8d20 Lifts Curse of the Mist: a real player gets its consumables back with what it found added (under their
|
||||
// caps), and its kept familiars their state, the locusts spawned again, the nth kept one of a variant going to the nth
|
||||
// such familiar (the last when fewer). Its pockets and trinkets come back, and Keeper's coin hearts.
|
||||
void Entity_Player::RemoveCurseMistEffect()
|
||||
{
|
||||
if (!hasCurseMistEffect) return;
|
||||
|
||||
if (backupPlayer && isValid) backupPlayer->RemoveCurseMistEffect();
|
||||
cacheFlags |= CACHE_ALL;
|
||||
hasCurseMistEffect = false;
|
||||
UpdateCostumes();
|
||||
|
||||
PlayerManager& players = g_game->playerManager;
|
||||
ConsumableData& backup = consumablesBackup;
|
||||
if (isValid)
|
||||
{
|
||||
int coinCap = players.FirstCollectibleOwner(COLLECTIBLE_DEEP_POCKETS, LAZARUS_SHARE_CHECK)
|
||||
? MIST_DEEP_POCKETS_COIN_CAP
|
||||
: MIST_CONSUMABLE_CAP;
|
||||
int poopCap = players.FirstBirthrightOwner(PLAYER_BLUEBABY_B) ? MIST_BIRTHRIGHT_POOP_MANA_CAP
|
||||
: MIST_POOP_MANA_CAP;
|
||||
backup.coins = std::min(numCoins + backup.coins, coinCap);
|
||||
backup.keys = std::min(numKeys + backup.keys, MIST_CONSUMABLE_CAP);
|
||||
backup.bombs = std::min(backup.bombs + numBombs, MIST_CONSUMABLE_CAP);
|
||||
backup.isGoldenKey = backup.isGoldenKey || hasGoldenKey;
|
||||
backup.isGoldenBomb = backup.isGoldenBomb || hasGoldenBomb;
|
||||
backup.gigaBombs = std::min(backup.gigaBombs + numGigaBombs, backup.bombs);
|
||||
backup.soulCharges = std::min(effectiveSoulCharge + backup.soulCharges, MIST_CONSUMABLE_CAP);
|
||||
backup.bloodCharges = std::min(backup.bloodCharges + effectiveBloodCharge, MIST_CONSUMABLE_CAP);
|
||||
backup.poopMana = std::min(poopMana + backup.poopMana, poopCap);
|
||||
restore_curse_mist_backup(backup);
|
||||
}
|
||||
|
||||
pocketItems = curseMistPocketItems;
|
||||
trinkets = curseMistTrinkets;
|
||||
if (isValid) ConsumableCountChanged(-1);
|
||||
EvaluateItems();
|
||||
|
||||
std::map<int, size_t> restored;
|
||||
for (const FamiliarData& saved : curseMistFamiliars)
|
||||
{
|
||||
size_t index = restored[saved.variant];
|
||||
if (saved.variant == Entity_Familiar::ABYSS_LOCUST)
|
||||
g_game->Spawn({.position = pos,
|
||||
.spawner = this,
|
||||
.subType = saved.subtype,
|
||||
.type = ENTITY_FAMILIAR,
|
||||
.variant = Entity_Familiar::ABYSS_LOCUST,
|
||||
.seed = Random()});
|
||||
|
||||
std::vector<Entity*> familiars = entity_query(ENTITY_FAMILIAR, saved.variant);
|
||||
if (!familiars.empty())
|
||||
{
|
||||
auto& familiar = static_cast<Entity_Familiar&>(*familiars[std::min(index, familiars.size() - 1)]);
|
||||
familiar.RestoreState(saved);
|
||||
familiar.AddEntityFlags(FLAG_APPEAR);
|
||||
if (familiar.variant == Entity_Familiar::DAMOCLES) familiar.subtype = saved.subtype;
|
||||
}
|
||||
restored[saved.variant] = index + 1;
|
||||
}
|
||||
curseMistFamiliars.clear();
|
||||
if (playerType != PLAYER_KEEPER) return;
|
||||
|
||||
AddMaxHearts(GetHeartLimit(false) - maxHearts, false);
|
||||
redHearts = curseMistRedHearts;
|
||||
}
|
||||
@@ -11,7 +11,6 @@
|
||||
|
||||
constexpr int TRINKET_DOOR_STOP = 124;
|
||||
constexpr int TRINKET_LIL_CLOT = 176;
|
||||
constexpr int TRINKET_BETHS_ESSENCE = 182;
|
||||
constexpr int TRINKET_THE_TWINS = 183;
|
||||
constexpr int COLLECTIBLE_BROKEN_WATCH = 337;
|
||||
constexpr int COLLECTIBLE_DOG_TOOTH = 445;
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
#include "entity_player_tainted.h"
|
||||
#include "game.h"
|
||||
#include "grid_entity_door.h"
|
||||
#include "hud.h"
|
||||
#include "manager.h"
|
||||
#include "npc_ai.h"
|
||||
#include "room.h"
|
||||
#include "room_grid.h"
|
||||
#include <algorithm>
|
||||
|
||||
constexpr int INVENTORY_SLOTS = 8;
|
||||
constexpr int INVENTORY_BIRTHRIGHT_SLOTS = 12;
|
||||
constexpr float DROP_SEARCH_STEP = 40;
|
||||
constexpr float PEDESTAL_DOOR_REACH = 70;
|
||||
constexpr int DEAD_CAT_LIVES_MAX = 9;
|
||||
|
||||
// 007d4150 How many items Tainted Isaac's inventory holds: 8, 12 with Birthright.
|
||||
int Entity_Player::GetMaxInventorySize()
|
||||
{
|
||||
return HasCollectible(COLLECTIBLE_BIRTHRIGHT) ? INVENTORY_BIRTHRIGHT_SLOTS : INVENTORY_SLOTS;
|
||||
}
|
||||
|
||||
// 00790530 Drops an owned collectible (passive Damocles as the active) onto a pedestal given or a new one beside the
|
||||
// player, seeded by the item's generator. The pedestal takes the pool the item came from, an active's charge and data,
|
||||
// and Dead Cat's lives the loss took (9 at most). The item is removed with modifiers ignored, from the first slot.
|
||||
Entity_Pickup* Entity_Player::DropCollectible(int collectible, Entity_Pickup* existing, bool isRemoveFromForm)
|
||||
{
|
||||
int shown = collectible == COLLECTIBLE_PASSIVE_DAMOCLES ? COLLECTIBLE_DAMOCLES : collectible;
|
||||
|
||||
g_pickupIgnoreModifiers++;
|
||||
if (existing)
|
||||
{
|
||||
existing->Morph(existing->type, existing->variant, shown, false, true, true);
|
||||
existing->UpdateSprite(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t seed = GetCollectibleRNG(collectible).Next();
|
||||
Vector spot = room_free_pickup_position_find({pos, DROP_SEARCH_STEP});
|
||||
existing = static_cast<Entity_Pickup*>(g_game->Spawn({.position = spot, .spawner = this, .subType = shown,
|
||||
.type = ENTITY_PICKUP, .variant = PICKUP_COLLECTIBLE,
|
||||
.seed = seed}));
|
||||
}
|
||||
auto entry = std::ranges::find_if(history.historyItems, [&](HistoryItem& item)
|
||||
{ return !item.isTrinket && item.id == collectible; });
|
||||
g_pickupIgnoreModifiers--;
|
||||
existing->itemPoolType = entry != history.historyItems.end() ? entry->itemPoolType : 0;
|
||||
|
||||
auto active = std::ranges::find_if(activeItems, [&](ActiveItemDesc& slot) { return slot.item == collectible; });
|
||||
if (active != activeItems.end())
|
||||
{
|
||||
existing->charge = active->batteryCharge + active->charge;
|
||||
existing->varData = active->varData;
|
||||
}
|
||||
int lives = deadCatLives;
|
||||
existing->isTouched = true;
|
||||
RemoveCollectible(collectible, true, ACTIVE_SLOT_PRIMARY, isRemoveFromForm);
|
||||
if (collectible == COLLECTIBLE_DEAD_CAT && deadCatLives <= lives)
|
||||
existing->charge = std::min(lives - deadCatLives, DEAD_CAT_LIVES_MAX);
|
||||
return existing;
|
||||
}
|
||||
|
||||
// 007906f0 Drops the collectible at a history index, if the player still owns it, and takes it out of the history.
|
||||
// The original's unused flag is gone.
|
||||
Entity_Pickup* Entity_Player::DropCollectibleByHistoryIndex(int index, Entity_Pickup* existing)
|
||||
{
|
||||
if (index < 0 || index >= (int)history.historyItems.size()) return nullptr;
|
||||
HistoryItem& item = history.historyItems[index];
|
||||
if (item.isTrinket || item.id < 0 || collectibleCounts[item.id] <= 0) return nullptr;
|
||||
|
||||
bool wasLocked = history.isLocked;
|
||||
history.isLocked = true;
|
||||
Entity_Pickup* dropped = DropCollectible(item.id, existing, false);
|
||||
history.isLocked = wasLocked;
|
||||
history.RemoveHistoryItemByIndex(index);
|
||||
return dropped;
|
||||
}
|
||||
|
||||
// 00721c00 Takes the item at a history index out, Tainted Isaac's inventory following. A locked history keeps it.
|
||||
// Whether it was removed. The original erases at a negative index. Here that removes nothing.
|
||||
bool History::RemoveHistoryItemByIndex(int index)
|
||||
{
|
||||
if (isLocked || index < 0 || index >= (int)historyItems.size()) return false;
|
||||
|
||||
historyItems.erase(historyItems.begin() + index);
|
||||
remove_index_refs(index);
|
||||
g_game->hud.mark_all_slots_dirty(HISTORY_KEEP_ICONS, HISTORY_KEEP_ITEMS);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 00721eb0 Refills Tainted Isaac's inventory from the history: the first passives it can hold, in pickup order.
|
||||
void inventory_rebuild(History& history)
|
||||
{
|
||||
std::array<int, INVENTORY_SIZE>& inventory = history.player->inventory;
|
||||
int size = history.player->GetMaxInventorySize();
|
||||
int filled = 0;
|
||||
|
||||
inventory.fill(-1);
|
||||
for (int index = 0; index < (int)history.historyItems.size() && filled < size; index++)
|
||||
{
|
||||
HistoryItem& item = history.historyItems[index];
|
||||
if (!item.isTrinket && history.player->CanAddCollectibleToInventory(item.id)) inventory[filled++] = index;
|
||||
}
|
||||
}
|
||||
|
||||
// The Tainted Isaac part of 006e8ae0: with a full inventory, the item held up is added first, then the inventory's
|
||||
// first item goes onto the pedestal and the others move up a slot. A pedestal by a door moves off it. Whether the
|
||||
// items were exchanged.
|
||||
bool tainted_isaac_pedestal_swap(Entity_Pickup& pickup, Entity_Player& player)
|
||||
{
|
||||
std::array<int, INVENTORY_SIZE>& inventory = player.inventory;
|
||||
|
||||
player.FlushQueueItem();
|
||||
if (inventory[player.GetMaxInventorySize() - 1] < 0) return false;
|
||||
if (!player.DropCollectibleByHistoryIndex(inventory[0], &pickup)) return false;
|
||||
std::shift_right(inventory.begin(), inventory.end(), 1);
|
||||
inventory[0] = -1;
|
||||
|
||||
auto isNear = [&](GridEntity_Door* door)
|
||||
{ return door && vector_length_squared(vector_sub(door->Position(), player.pos)) < PEDESTAL_DOOR_REACH * PEDESTAL_DOOR_REACH; };
|
||||
if (std::ranges::any_of(g_game->room->doors, isNear)) pickup.gridRepositionState = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
// The Tainted Isaac part of 007cf610: a player becoming him keeps the first passives his inventory holds and loses
|
||||
// the later ones, then the inventory is rebuilt. The original reads the count of a procedural item before its list.
|
||||
// Here a procedural item is kept.
|
||||
void tainted_isaac_inventory_trim(Entity_Player& player)
|
||||
{
|
||||
History& history = player.history;
|
||||
int kept = player.GetMaxInventorySize();
|
||||
|
||||
history.isLocked = true;
|
||||
for (auto item = history.historyItems.begin(); item != history.historyItems.end();)
|
||||
{
|
||||
bool isHeld = !item->isTrinket && item->id >= 0 && player.CanAddCollectibleToInventory(item->id);
|
||||
if (!isHeld || kept > 0)
|
||||
{
|
||||
if (isHeld) kept--;
|
||||
item++;
|
||||
continue;
|
||||
}
|
||||
if (player.collectibleCounts[item->id] > 0) player.RemoveCollectible(item->id, true, ACTIVE_SLOT_PRIMARY, true);
|
||||
item = history.historyItems.erase(item);
|
||||
}
|
||||
history.isLocked = false;
|
||||
inventory_rebuild(history);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "entity_pickup.h"
|
||||
#include "entity_player.h"
|
||||
|
||||
// Tainted Isaac's inventory: the pedestal swap of a full inventory (006e8ae0), and the passives a new Tainted Isaac
|
||||
// keeps (007cf610) with the inventory rebuilt from the history (00721eb0).
|
||||
bool tainted_isaac_pedestal_swap(Entity_Pickup& pickup, Entity_Player& player);
|
||||
void tainted_isaac_inventory_trim(Entity_Player& player);
|
||||
void inventory_rebuild(History& history);
|
||||
@@ -77,13 +77,11 @@ constexpr float TECH_X_RING_LIFT = -20;
|
||||
constexpr int COLLECTIBLE_BRIMSTONE_WEAPON = 118;
|
||||
constexpr int COLLECTIBLE_CURSED_EYE_WEAPON = 316;
|
||||
constexpr int COLLECTIBLE_DEAD_TOOTH = 446;
|
||||
constexpr int COLLECTIBLE_EVIL_EYE = 410;
|
||||
constexpr int COLLECTIBLE_EYE_SORE = 558;
|
||||
constexpr int COLLECTIBLE_INNER_EYE = 2;
|
||||
constexpr int COLLECTIBLE_LARGE_ZIT = 502;
|
||||
constexpr int COLLECTIBLE_NEPTUNUS = 597;
|
||||
constexpr int COLLECTIBLE_THE_WIZ = 358;
|
||||
constexpr int COLLECTIBLE_TRACTOR_BEAM = 397;
|
||||
constexpr int NULLITEM_DARK_ARTS = 111;
|
||||
|
||||
// The items GetWeaponModifiers turns into modifier bits, in the order it asks.
|
||||
|
||||
+1933
-65
File diff suppressed because it is too large.
Load diff
@@ -2,6 +2,54 @@
|
||||
|
||||
#include "entity.h"
|
||||
|
||||
// Lua's SlotVariant: the machines and beggars.
|
||||
enum SlotVariant : int
|
||||
{
|
||||
SLOT_MACHINE = 1,
|
||||
SLOT_BLOOD_DONATION_MACHINE,
|
||||
SLOT_FORTUNE_TELLING_MACHINE,
|
||||
SLOT_BEGGAR,
|
||||
SLOT_DEVIL_BEGGAR,
|
||||
SLOT_SHELL_GAME,
|
||||
SLOT_KEY_MASTER,
|
||||
SLOT_DONATION_MACHINE,
|
||||
SLOT_BOMB_BUM,
|
||||
SLOT_SHOP_RESTOCK_MACHINE,
|
||||
SLOT_GREED_DONATION_MACHINE,
|
||||
SLOT_MOMS_DRESSER,
|
||||
SLOT_BATTERY_BUM,
|
||||
SLOT_ISAAC_SECRET,
|
||||
SLOT_HELL_GAME,
|
||||
SLOT_CRANE_GAME,
|
||||
SLOT_CONFESSIONAL,
|
||||
SLOT_ROTTEN_BEGGAR,
|
||||
SLOT_REVIVE_MACHINE
|
||||
};
|
||||
|
||||
// Where a slot is: appearing, waiting for a payment, paying out, broken (or jammed), leaving, and a shell game's pick
|
||||
// (or a bombed Bomb Bum).
|
||||
enum SlotState : int
|
||||
{
|
||||
SLOT_STATE_APPEAR,
|
||||
SLOT_STATE_IDLE,
|
||||
SLOT_STATE_REWARD,
|
||||
SLOT_STATE_BROKEN,
|
||||
SLOT_STATE_GONE,
|
||||
SLOT_STATE_PICK
|
||||
};
|
||||
|
||||
// What a slot throws out (the pickups Entity_Slot::HandleCollision 006657a0 overload spawns): count pickups of a
|
||||
// variant and subtype, thrown by its RNG unless a velocity is given, from an offset.
|
||||
struct SlotDrop
|
||||
{
|
||||
RNG* rng = nullptr;
|
||||
Vector offset{};
|
||||
Vector velocity{};
|
||||
int count = 1;
|
||||
int subType = 0;
|
||||
int variant = 0;
|
||||
};
|
||||
|
||||
// Construction and destruction (0065d130) are the defaults.
|
||||
// A slot machine, beggar or other paying machine (Lua's EntitySlot), which pays out a prize: its state, the prize it
|
||||
// shows and the save data its donations count into.
|
||||
@@ -32,4 +80,33 @@ struct Entity_Slot : Entity
|
||||
|
||||
private:
|
||||
void counter_show(int count);
|
||||
void drops_spawn(const SlotDrop& drop);
|
||||
void explode();
|
||||
void leave();
|
||||
bool appear_update();
|
||||
void movement_update();
|
||||
void slot_machine_roll(Entity_Player& player);
|
||||
void crane_game_update(Entity_Player& player);
|
||||
void confessional_update(Entity_Player& player);
|
||||
void idle_update();
|
||||
void payout(Entity_Player& player);
|
||||
void slot_machine_pay(Entity_Player& player, RNG& prizeRng, int count);
|
||||
void blood_donation_pay(Entity_Player& player, RNG& prizeRng, int count);
|
||||
void fortune_pay(Entity_Player& player, RNG& prizeRng, int count);
|
||||
void beggar_pay(Entity_Player& player, RNG& prizeRng, int count);
|
||||
void devil_beggar_pay(RNG& prizeRng, int count);
|
||||
void shell_game_pay(Entity_Player& player, RNG& prizeRng, int count);
|
||||
void key_master_pay(RNG& prizeRng);
|
||||
void donation_pay(Entity_Player& player);
|
||||
void bomb_bum_pay(Entity_Player& player, RNG& prizeRng, int count);
|
||||
void restock_pay(Entity_Player& player);
|
||||
void battery_bum_pay(Entity_Player& player, RNG& prizeRng, int count);
|
||||
void rotten_beggar_pay(Entity_Player& player, RNG& prizeRng, int count);
|
||||
bool is_payment_taken(Entity_Player& player);
|
||||
void payment_react(Entity_Player& player, Entity* collider);
|
||||
void shell_game_start(Entity_Player& player);
|
||||
void blood_trails_spawn();
|
||||
};
|
||||
|
||||
Vector room_pickup_position_random(bool isAvoidActiveEntities, bool isAllowPits);
|
||||
Vector collectible_spawn_position(Vector target);
|
||||
+37
-11
@@ -51,12 +51,18 @@ constexpr float BLUE_FLY_PULL_MAX = 2;
|
||||
constexpr float BLUE_FLY_FRICTION = 0.8f;
|
||||
constexpr float BLUE_FLY_STUN_FRICTION = 0.96f;
|
||||
|
||||
// The birds' chase.
|
||||
// The birds' chase (Bird Cage's further, slower and away from the player), and Lil Haunt's cry and fading.
|
||||
constexpr float BIRD_RANGE = 300;
|
||||
constexpr float BIRD_CAGE_RANGE = 360;
|
||||
constexpr int BIRD_TARGET_INTERVAL = 13;
|
||||
constexpr uint32_t BIRD_TARGET_FLAGS = TARGET_RETARGET | TARGET_PREFER_HEALTHY | TARGET_PREFER_WEAK;
|
||||
constexpr float BIRD_FRICTION = 0.9f;
|
||||
constexpr float BIRD_CAGE_PULL = 0.8f;
|
||||
constexpr float BIRD_RETURN_DISTANCE = 6400;
|
||||
constexpr int SOUND_LIL_HAUNT_CHASE = 859;
|
||||
constexpr int LIL_HAUNT_CRY_DELAY = 450;
|
||||
constexpr int LIL_HAUNT_VERSUS_CHASE_FRAMES = 599;
|
||||
constexpr float LIL_HAUNT_IDLE_ALPHA = 0.5f;
|
||||
constexpr float LIL_HAUNT_FADE = 0.15f;
|
||||
|
||||
// Demon Baby's shots.
|
||||
constexpr float AUTO_SHOOTER_RANGE = 150;
|
||||
@@ -226,27 +232,47 @@ void Entity_Familiar::ai_auto_shooter()
|
||||
if (variant != BUMBO) play_idle_anim();
|
||||
}
|
||||
|
||||
// 0061b8c0 Dead Bird and its kin: flies after enemies, back to the player when it strays with none, flapping. Bird Cage
|
||||
// and Lil Haunt hunt their own ways, which stops the game.
|
||||
// 0061b8c0 Dead Bird and its kin (Eve's Bird Foot, Best Bud, Lil Haunt, Bird Cage's bird): flies after enemies, back
|
||||
// to the player when it strays with none. Lil Haunt cries when it finds one and fades while it has none.
|
||||
void Entity_Familiar::ai_flying_bird()
|
||||
{
|
||||
if (variant == BIRD_CAGE || variant == LIL_HAUNT)
|
||||
return reconstruction_missing("Entity_Familiar::ai_flying_bird 0061b8c0 (Bird Cage and Lil Haunt)");
|
||||
float pull = 1;
|
||||
float birdFriction = BIRD_FRICTION;
|
||||
if (variant == BIRD_CAGE)
|
||||
{
|
||||
PickEnemyTarget(
|
||||
{.range = BIRD_CAGE_RANGE, .frameInterval = BIRD_TARGET_INTERVAL, .flags = TARGET_PREFER_HEALTHY});
|
||||
pull = BIRD_CAGE_PULL;
|
||||
birdFriction = BIRD_CAGE_PULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
bool hadTarget = target != nullptr;
|
||||
PickEnemyTarget({.range = BIRD_RANGE, .frameInterval = BIRD_TARGET_INTERVAL});
|
||||
if (!hadTarget && target && variant == LIL_HAUNT)
|
||||
familiar_sound_play(SOUND_LIL_HAUNT_CHASE, {.frameDelay = LIL_HAUNT_CRY_DELAY});
|
||||
}
|
||||
if (variant == LIL_HAUNT) familiar_chase_limit(*this, LIL_HAUNT_VERSUS_CHASE_FRAMES);
|
||||
|
||||
PickEnemyTarget({.range = BIRD_RANGE, .frameInterval = BIRD_TARGET_INTERVAL, .flags = BIRD_TARGET_FLAGS});
|
||||
if (target) velocity = vector_add(velocity, vector_normalized(vector_sub(target->pos, pos)));
|
||||
if (target) velocity = vector_add(velocity, vector_scale(vector_normalized(vector_sub(target->pos, pos)), pull));
|
||||
else
|
||||
{
|
||||
Vector home = vector_sub(player->pos, pos);
|
||||
if (vector_length_squared(home) > BIRD_RETURN_DISTANCE)
|
||||
velocity = vector_add(velocity, vector_normalized(home));
|
||||
velocity = vector_add(velocity, vector_scale(vector_normalized(home), pull));
|
||||
}
|
||||
|
||||
if (variant == DEAD_BIRD) sprite.Play("Flying");
|
||||
if (variant == DEAD_BIRD || variant == BIRD_CAGE) sprite.Play("Flying");
|
||||
else if (variant == EVES_BIRD_FOOT) sprite.Play("FlyingTransparent");
|
||||
else if (variant == BEST_BUD) sprite.Play("Idle");
|
||||
else if (variant == LIL_HAUNT)
|
||||
{
|
||||
sprite.Play(target ? "FloatChase" : "Float");
|
||||
float alpha = sprite.color._tint[3];
|
||||
sprite.color._tint[3] = ((target ? 1 : LIL_HAUNT_IDLE_ALPHA) - alpha) * LIL_HAUNT_FADE + alpha;
|
||||
}
|
||||
sprite.isFlipX = velocity.x > 0;
|
||||
velocity = vector_scale(velocity, BIRD_FRICTION);
|
||||
velocity = vector_scale(velocity, birdFriction);
|
||||
}
|
||||
|
||||
// 00615d80 A blue fly: stunned a moment after it spawns, then circles its parent (or player) until an enemy comes near,
|
||||
|
||||
@@ -0,0 +1,324 @@
|
||||
#include "entity_familiar.h"
|
||||
#include "entity_list.h"
|
||||
#include "entity_npc.h"
|
||||
#include "entity_pickup.h"
|
||||
#include "entity_player.h"
|
||||
#include "game.h"
|
||||
#include "item_pool.h"
|
||||
#include "npc_ai.h"
|
||||
#include "room_grid.h"
|
||||
#include <algorithm>
|
||||
|
||||
// How the bums trail: the player within this reach (or the bum ahead of them in line), pulled toward the one they
|
||||
// follow, and the reach of their pickup hunt.
|
||||
constexpr float BUM_PLAYER_REACH = 80;
|
||||
constexpr float BUM_LINE_REACH = 50;
|
||||
constexpr float BUM_FOLLOW_PULL = 0.8f;
|
||||
constexpr float BUM_CHASE_PULL = 1.1f;
|
||||
constexpr float BUM_TOUCH_DISTANCE_SQUARED = 100;
|
||||
constexpr float BUM_FRICTION = 0.8f;
|
||||
constexpr int BUM_SEARCH_INTERVAL = 5;
|
||||
constexpr float BUM_SEARCH_RADIUS = 200;
|
||||
constexpr float BUM_SEARCH_DISTANCE_SQUARED = 40000;
|
||||
constexpr float BUM_SPIDER_HEIGHT = -30;
|
||||
|
||||
// What fills a bum before it pays: Bum Friend's coins, Dark Bum's red hearts. Key Bum waits for more keys than its
|
||||
// state.
|
||||
constexpr int BUM_FRIEND_COINS = 5;
|
||||
constexpr int DARK_BUM_HEARTS = 2;
|
||||
|
||||
// Bum Friend's price (one more half the time without BFFS!), and its item once it holds ten coins.
|
||||
constexpr int BUM_FRIEND_PRICE = 3;
|
||||
constexpr int BUM_FRIEND_ITEM_PRICE = 10;
|
||||
constexpr int BUM_FRIEND_ITEM_CHANCE = 3;
|
||||
constexpr int BUM_FRIEND_RARE_ITEM_CHANCE = 100;
|
||||
constexpr int BUM_FRIEND_DROPS[] = {PICKUP_HEART, PICKUP_KEY, PICKUP_BOMB};
|
||||
|
||||
// Dark Bum's price and its occasional extra heart, and Key Bum's price and chests.
|
||||
constexpr int DARK_BUM_PRICE = 3;
|
||||
constexpr int DARK_BUM_EXTRA_HEART_CHANCE = 10;
|
||||
constexpr int DARK_BUM_DROP_KINDS = 5;
|
||||
constexpr int KEY_BUM_PRICE = 4;
|
||||
constexpr int KEY_BUM_BFFS_PRICE = 3;
|
||||
constexpr int KEY_BUM_DROPS[] = {PICKUP_CHEST, PICKUP_LOCKEDCHEST, PICKUP_REDCHEST};
|
||||
|
||||
// What a charged key leaves a Key Bum: a full battery.
|
||||
constexpr int CHARGED_KEY_BATTERY = 1;
|
||||
|
||||
// Bumbo grows with coins at its last size, and Lil Portal rounds its coins up to a hundred.
|
||||
constexpr int BUMBO_LAST_SIZE = 3;
|
||||
constexpr int BUMBO_GROWTH_ODDS = 5;
|
||||
constexpr int BUMBO_BFFS_GROWTH_ODDS = 4;
|
||||
constexpr int LIL_PORTAL_COIN_ROUND = 100;
|
||||
|
||||
// The bums that line up behind each other, and the red hearts Dark Bum hunts.
|
||||
constexpr int LINED_BUM_VARIANTS[] = {Entity_Familiar::BUM_FRIEND, Entity_Familiar::DARK_BUM, Entity_Familiar::KEY_BUM,
|
||||
Entity_Familiar::SUPER_BUM, Entity_Familiar::BUMBO};
|
||||
constexpr int RED_HEART_SUBTYPES[] = {HEART_FULL, HEART_HALF, HEART_DOUBLEPACK, HEART_SCARED};
|
||||
|
||||
// What the bums' payouts draw.
|
||||
enum BumDrop
|
||||
{
|
||||
BUM_DROP_SPIDER,
|
||||
BUM_DROP_PILL,
|
||||
BUM_DROP_CARD
|
||||
};
|
||||
|
||||
// Whether a bum hunts this pickup: coins for Bum Friend, red hearts for Dark Bum, keys but golden ones for Key Bum,
|
||||
// all of them for Super Bum.
|
||||
static bool is_bum_pickup(int bumVariant, Entity_Pickup& pickup)
|
||||
{
|
||||
bool isSuper = bumVariant == Entity_Familiar::SUPER_BUM;
|
||||
if (pickup.variant == PICKUP_COIN) return bumVariant == Entity_Familiar::BUM_FRIEND || isSuper;
|
||||
if (pickup.variant == PICKUP_HEART)
|
||||
return (bumVariant == Entity_Familiar::DARK_BUM || isSuper) &&
|
||||
familiar_listed(RED_HEART_SUBTYPES, pickup.subtype);
|
||||
if (pickup.variant == PICKUP_KEY)
|
||||
return (bumVariant == Entity_Familiar::KEY_BUM || isSuper) && pickup.subtype != KEY_GOLDEN;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Part of 006e8ae0: a bum (or Bumbo, for coins) touching a pickup it hunts counts it. A charged key also leaves a
|
||||
// battery. False when the bum does not take it.
|
||||
bool bum_pickup_collect(Entity_Familiar& bum, Entity_Pickup& pickup)
|
||||
{
|
||||
int hunter = bum.variant == Entity_Familiar::BUMBO ? (int)Entity_Familiar::BUM_FRIEND : bum.variant;
|
||||
if (!is_bum_pickup(hunter, pickup)) return false;
|
||||
|
||||
if (pickup.variant == PICKUP_COIN) bum.AddCoins(pickup.GetCoinValue());
|
||||
else if (pickup.variant == PICKUP_HEART)
|
||||
bum.hearts += pickup.subtype == HEART_HALF ? 1 : pickup.subtype == HEART_DOUBLEPACK ? 4 : 2;
|
||||
else
|
||||
{
|
||||
bum.keys += pickup.subtype == KEY_DOUBLEPACK ? 2 : 1;
|
||||
if (pickup.subtype == KEY_CHARGED)
|
||||
g_game
|
||||
->Spawn({.position = pickup.pos,
|
||||
.subType = CHARGED_KEY_BATTERY,
|
||||
.type = ENTITY_PICKUP,
|
||||
.variant = PICKUP_LIL_BATTERY,
|
||||
.seed = pickup.dropRNG.Next()})
|
||||
->Update();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// 0062a930 Counts coins a familiar collected. Lil Portal rounds its count up to a hundred and spits a blue fly, Bumbo
|
||||
// at its last size grows a little more with every coin.
|
||||
void Entity_Familiar::AddCoins(int count)
|
||||
{
|
||||
coins += count;
|
||||
if (variant == LIL_PORTAL)
|
||||
{
|
||||
int excess = coins % LIL_PORTAL_COIN_ROUND;
|
||||
if (excess > 0) coins += (LIL_PORTAL_COIN_ROUND - 1) * excess;
|
||||
player->AddBlueFlies(1, pos, nullptr);
|
||||
return;
|
||||
}
|
||||
if (variant != BUMBO || state != BUMBO_LAST_SIZE) return;
|
||||
|
||||
int odds = player->HasCollectible(COLLECTIBLE_BFFS) ? BUMBO_BFFS_GROWTH_ODDS : BUMBO_GROWTH_ODDS;
|
||||
for (; count > 0; count--)
|
||||
if (dropRNG.RandomInt(odds) == 0) counter++;
|
||||
}
|
||||
|
||||
// The free spot halfway between a bum and its player, where its payout drops.
|
||||
static Vector bum_drop_spot(Entity_Familiar& bum)
|
||||
{
|
||||
Vector half = vector_make(bum.pos.x * 0.5f + bum.player->pos.x * 0.5f, bum.pos.y * 0.5f + bum.player->pos.y * 0.5f);
|
||||
return room_free_pickup_position_find({.position = half});
|
||||
}
|
||||
|
||||
// Drops a bum's pickup at its spot, the drop generator seeding it.
|
||||
static void bum_drop(Entity_Familiar& bum, Entity* spawner, int pickupVariant, int subtype)
|
||||
{
|
||||
Vector spot = bum_drop_spot(bum);
|
||||
g_game->Spawn({.position = spot,
|
||||
.spawner = spawner,
|
||||
.subType = subtype,
|
||||
.type = ENTITY_PICKUP,
|
||||
.variant = pickupVariant,
|
||||
.seed = bum.dropRNG.Next()});
|
||||
}
|
||||
|
||||
// Bum Friend's payout: three or four coins for a heart, key, bomb, trinket, pill, card or battery (Daemon's Tail
|
||||
// mostly keeps the hearts away), or ten for a beggar's item, once a floor (rarely without the ten).
|
||||
static void bum_friend_pay(Entity_Familiar& bum, int drops)
|
||||
{
|
||||
RNG& rng = bum.dropRNG;
|
||||
int price = BUM_FRIEND_PRICE;
|
||||
if (!bum.player->HasCollectible(COLLECTIBLE_BFFS)) price += (int)rng.RandomInt(2);
|
||||
bool isItem = bum.coins >= BUM_FRIEND_ITEM_PRICE && bum.subtype == 0 && rng.RandomInt(BUM_FRIEND_ITEM_CHANCE) == 0;
|
||||
if (!isItem) isItem = rng.RandomInt(BUM_FRIEND_RARE_ITEM_CHANCE) == 0;
|
||||
|
||||
int pickupVariant = PICKUP_COLLECTIBLE;
|
||||
int subtype = 0;
|
||||
if (isItem)
|
||||
{
|
||||
subtype = g_game->itemPool.GetCollectible(POOL_BEGGAR, rng.Next(), 0, 0, 0);
|
||||
price = BUM_FRIEND_ITEM_PRICE;
|
||||
bum.subtype = 1;
|
||||
familiar_sound_play(SOUND_THUMBSUP);
|
||||
}
|
||||
else if (rng.RandomInt(2) == 0)
|
||||
{
|
||||
int kind = (int)rng.RandomInt(3);
|
||||
if (kind == 0 && bum.player->HasTrinket(TRINKET_DAEMONS_TAIL) && Random() % DAEMONS_TAIL_ODDS != 0)
|
||||
kind = (int)rng.RandomInt(2) + 1;
|
||||
pickupVariant = BUM_FRIEND_DROPS[kind];
|
||||
}
|
||||
else if (rng.RandomInt(3) == 0) pickupVariant = PICKUP_TRINKET;
|
||||
else
|
||||
{
|
||||
uint32_t kind = rng.RandomInt(4);
|
||||
pickupVariant = kind == 0 ? PICKUP_PILL : kind == 1 ? PICKUP_TAROTCARD : PICKUP_LIL_BATTERY;
|
||||
}
|
||||
|
||||
bum.coins = std::max(bum.coins - price, 0);
|
||||
for (; drops > 0; drops--) bum_drop(bum, &bum, pickupVariant, subtype);
|
||||
}
|
||||
|
||||
// Dark Bum's payout: three red hearts (sometimes four without BFFS!) for a pill, a card, black hearts or a spider,
|
||||
// blue or thrown.
|
||||
static void dark_bum_pay(Entity_Familiar& bum, int drops)
|
||||
{
|
||||
RNG& rng = bum.dropRNG;
|
||||
bum.hearts -= DARK_BUM_PRICE;
|
||||
if (rng.RandomInt(DARK_BUM_EXTRA_HEART_CHANCE) == 0 && !bum.player->HasCollectible(COLLECTIBLE_BFFS)) bum.hearts--;
|
||||
familiar_sound_play(SOUND_DARK_BUM_PAYOUT);
|
||||
|
||||
switch (rng.RandomInt(DARK_BUM_DROP_KINDS))
|
||||
{
|
||||
case BUM_DROP_PILL: return bum_drop(bum, &bum, PICKUP_PILL, 0);
|
||||
case BUM_DROP_CARD: return bum_drop(bum, &bum, PICKUP_TAROTCARD, 0);
|
||||
case BUM_DROP_SPIDER:
|
||||
{
|
||||
Vector spot = bum_drop_spot(bum);
|
||||
if (rng.RandomInt(2) != 0)
|
||||
{
|
||||
Entity_NPC::ThrowSpider(bum.pos, &bum, spot, false, BUM_SPIDER_HEIGHT);
|
||||
return;
|
||||
}
|
||||
Vector still{};
|
||||
bum.player->numBlueSpiders++;
|
||||
spawn_blue_spider(&spot, bum.player, &still);
|
||||
return;
|
||||
}
|
||||
default:
|
||||
for (; drops > 0; drops--) bum_drop(bum, &bum, PICKUP_HEART, HEART_BLACK);
|
||||
}
|
||||
}
|
||||
|
||||
// Key Bum's payout: four keys (three with BFFS!) for a chest, a locked chest or a red chest, and a new number of keys
|
||||
// to wait for.
|
||||
static void key_bum_pay(Entity_Familiar& bum, int drops)
|
||||
{
|
||||
RNG& rng = bum.dropRNG;
|
||||
int price = bum.player->HasCollectible(COLLECTIBLE_BFFS) ? KEY_BUM_BFFS_PRICE : KEY_BUM_PRICE;
|
||||
bum.state = (int)rng.RandomInt(price) + 2;
|
||||
bum.keys = std::max(bum.keys - price, 0);
|
||||
for (; drops > 0; drops--)
|
||||
{
|
||||
Vector spot = bum_drop_spot(bum);
|
||||
uint32_t seed = rng.Next();
|
||||
g_game->Spawn({.position = spot,
|
||||
.type = ENTITY_PICKUP,
|
||||
.variant = KEY_BUM_DROPS[rng.RandomInt(3)],
|
||||
.seed = seed});
|
||||
}
|
||||
}
|
||||
|
||||
// A bum without a pickup to chase trails the player, or the bum ahead of it, and readies its payout once full and
|
||||
// near the player.
|
||||
static void bum_follow(Entity_Familiar& bum)
|
||||
{
|
||||
Vector lead = bum.player->pos;
|
||||
float leadReach = BUM_PLAYER_REACH;
|
||||
for (Entity_Familiar* other : familiar_query(-1))
|
||||
{
|
||||
if (!other->isExists) continue;
|
||||
if (other == &bum) break;
|
||||
if (!familiar_listed(LINED_BUM_VARIANTS, other->variant)) continue;
|
||||
|
||||
lead = other->pos;
|
||||
leadReach = BUM_LINE_REACH;
|
||||
}
|
||||
|
||||
Vector toLead = vector_sub(lead, bum.pos);
|
||||
float leadDistance = vector_length(toLead);
|
||||
if (vector_length(vector_sub(bum.player->pos, bum.pos)) >= BUM_PLAYER_REACH)
|
||||
{
|
||||
if (leadReach < leadDistance)
|
||||
bum.velocity = vector_make(toLead.x / leadDistance * BUM_FOLLOW_PULL + bum.velocity.x,
|
||||
toLead.y / leadDistance * BUM_FOLLOW_PULL + bum.velocity.y);
|
||||
return;
|
||||
}
|
||||
bool isFull = bum.coins > BUM_FRIEND_COINS || bum.hearts > DARK_BUM_HEARTS || bum.state < bum.keys;
|
||||
if (isFull && bum.sprite.IsPlaying("FloatDown")) bum.sprite.Play("PreSpawn", PLAY_FORCED);
|
||||
}
|
||||
|
||||
// A bum reaching its pickup touches it. A sticky nickel cannot be taken and is struck off. True when the pickup is
|
||||
// gone, which sends the bum looking right away.
|
||||
static bool bum_chase(Entity_Familiar& bum)
|
||||
{
|
||||
Vector toward = vector_sub(bum.target->pos, bum.pos);
|
||||
if (vector_length_squared(toward) >= BUM_TOUCH_DISTANCE_SQUARED)
|
||||
{
|
||||
bum.velocity = vector_add(bum.velocity, vector_scale(vector_normalized(toward), BUM_CHASE_PULL));
|
||||
return false;
|
||||
}
|
||||
|
||||
bum.collide_with_entity(bum.target);
|
||||
if (!bum.target || bum.target->isDead)
|
||||
{
|
||||
bum.target = nullptr;
|
||||
return true;
|
||||
}
|
||||
if (bum.target->IsType(ENTITY_PICKUP, PICKUP_COIN, COIN_STICKYNICKEL))
|
||||
{
|
||||
hit_list_insert(bum.hitList, *bum.target);
|
||||
bum.target = nullptr;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// The nearest free pickup the bum hunts within reach, skipping the ones it struck off (but nickels).
|
||||
static void bum_target_pick(Entity_Familiar& bum)
|
||||
{
|
||||
float best = BUM_SEARCH_DISTANCE_SQUARED;
|
||||
for (Entity* entity : entity_query_radius(bum.pos, BUM_SEARCH_RADIUS, QUERY_PICKUPS))
|
||||
{
|
||||
if (entity->type != ENTITY_PICKUP) continue;
|
||||
|
||||
auto& pickup = static_cast<Entity_Pickup&>(*entity);
|
||||
bool isStruck = EntityList::HitListContains(bum.hitList, pickup) &&
|
||||
!(pickup.variant == PICKUP_COIN && pickup.subtype == COIN_NICKEL);
|
||||
float distance = vector_length_squared(vector_sub(pickup.pos, bum.pos));
|
||||
if (!is_bum_pickup(bum.variant, pickup) || pickup.isDead || pickup.price != 0 || isStruck || distance >= best)
|
||||
continue;
|
||||
|
||||
bum.target = &pickup;
|
||||
best = distance;
|
||||
}
|
||||
}
|
||||
|
||||
// 0061a4e0 Bum Friend, Dark Bum, Key Bum and Super Bum: chase the pickups they take, else trail the player in line,
|
||||
// and pay out once full and near the player, Super Bum paying its coins first, then its hearts, then its keys.
|
||||
void Entity_Familiar::ai_pickup_sack()
|
||||
{
|
||||
bool isSearchDue = false;
|
||||
if (target && !target->isDead) isSearchDue = bum_chase(*this);
|
||||
else bum_follow(*this);
|
||||
friction *= BUM_FRICTION;
|
||||
if ((isSearchDue || IsFrame(BUM_SEARCH_INTERVAL, 0)) && !target) bum_target_pick(*this);
|
||||
|
||||
if (sprite.IsFinished("Spawn")) return sprite.Play("FloatDown");
|
||||
if (!sprite.IsFinished("PreSpawn")) return;
|
||||
|
||||
sprite.Play("Spawn", PLAY_FORCED);
|
||||
bool isSuper = variant == SUPER_BUM;
|
||||
int drops = isSuper ? 2 : 1;
|
||||
if (variant == BUM_FRIEND || (isSuper && coins > BUM_FRIEND_COINS)) bum_friend_pay(*this, drops);
|
||||
else if (variant == DARK_BUM || (isSuper && hearts > DARK_BUM_HEARTS)) dark_bum_pay(*this, drops);
|
||||
else if (variant == KEY_BUM || isSuper) key_bum_pay(*this, drops);
|
||||
}
|
||||
@@ -36,8 +36,6 @@ constexpr int CHARGER_BUMP_RECOVER = 30;
|
||||
constexpr float SPIN_HIT_PUSH = 5;
|
||||
constexpr float SPIN_HIT_SCALE = 1.5f;
|
||||
constexpr float SPIN_HIT_BASE = 6;
|
||||
constexpr int PLAYERFORM_LORD_OF_THE_FLIES_ID = 1;
|
||||
constexpr int PLAYERFORM_SPIDERBABY_ID = 12;
|
||||
|
||||
// The blue flies' and spiders' pop, and the locusts' tear effects.
|
||||
constexpr int SOUND_INSECT_POP = 1015;
|
||||
@@ -80,14 +78,6 @@ enum LocustKind
|
||||
LOCUST_DEATH
|
||||
};
|
||||
|
||||
// Sorted insertion into a hit list, as the entities keep them.
|
||||
static void hit_list_add(std::vector<uint32_t>& hitList, Entity& entity)
|
||||
{
|
||||
uint32_t index = entity.GetHitListIndex();
|
||||
auto at = std::lower_bound(hitList.begin(), hitList.end(), index);
|
||||
if (at == hitList.end() || *at != index) hitList.insert(at, index);
|
||||
}
|
||||
|
||||
// A blue fly popping on what it hit: a puff, then its locust's effect (an explosion, poison, slowing or death).
|
||||
static void blue_fly_pop(Entity_Familiar& fly, Entity& collider, float damageMultiplier)
|
||||
{
|
||||
@@ -143,7 +133,7 @@ static void brain_explode(Entity_Familiar& brain, Entity& collider, float damage
|
||||
// blue fly or spider bounces off an enemy too fast for it, then the blue flies and spiders pop and the brains blow.
|
||||
bool Entity_Familiar::collision_contact(Entity& collider, float damageMultiplier, float damage)
|
||||
{
|
||||
hit_list_add(hitList, collider);
|
||||
hit_list_insert(hitList, collider);
|
||||
bool isIgnored = true;
|
||||
bool isSwatted = false;
|
||||
if (familiar_listed(CONTACT_VARIANTS, variant))
|
||||
@@ -233,7 +223,7 @@ bool Entity_Familiar::HandleCollision(Entity* collider, bool isLow)
|
||||
player->velocity = vector_sub(player->velocity, away);
|
||||
}
|
||||
collider->TakeDamage(collisionDamage * SPIN_HIT_SCALE + SPIN_HIT_BASE, 0, EntityRef(this), 0);
|
||||
hit_list_add(hitList, *collider);
|
||||
hit_list_insert(hitList, *collider);
|
||||
}
|
||||
|
||||
bool isOwnersFoe = !spawnerEntity || !spawnerEntity->IsDescendantOf(collider);
|
||||
@@ -248,8 +238,8 @@ bool Entity_Familiar::HandleCollision(Entity* collider, bool isLow)
|
||||
Entity_Player& touched = *static_cast<Entity_Player*>(collider);
|
||||
bool isFlyLord =
|
||||
touched.HasCollectible(COLLECTIBLE_SKATOLE) ||
|
||||
(touched.variant == PLAYER_VARIANT_PLAYER && touched.HasPlayerForm(PLAYERFORM_LORD_OF_THE_FLIES_ID));
|
||||
bool isSpiderLord = touched.variant == PLAYER_VARIANT_PLAYER && touched.HasPlayerForm(PLAYERFORM_SPIDERBABY_ID);
|
||||
(touched.variant == PLAYER_VARIANT_PLAYER && touched.HasPlayerForm(PLAYER_FORM_BEELZEBUB));
|
||||
bool isSpiderLord = touched.variant == PLAYER_VARIANT_PLAYER && touched.HasPlayerForm(PLAYER_FORM_SPIDER_BABY);
|
||||
if (isFlyLord && (variant == BLUE_FLY || variant == BLUE_SPIDER || variant == ABYSS_LOCUST)) return true;
|
||||
if (isSpiderLord && (variant == BLUE_SPIDER || variant == SPIDER_BABY)) return true;
|
||||
}
|
||||
|
||||
@@ -78,7 +78,6 @@ constexpr int TRINKET_ISAACS_HEAD = 54;
|
||||
constexpr int TRINKET_SOUL = 57;
|
||||
constexpr int TRINKET_FOUND_SOUL_ID = 180;
|
||||
constexpr int SOUL_TRINKET_CAP = 3;
|
||||
constexpr int PLAYERFORM_SPIDERBABY = 12;
|
||||
constexpr int FORM_RNG_SHIFT = 35;
|
||||
constexpr int FAMILIAR_ACHIEVEMENT_COUNT = 4;
|
||||
constexpr int ACHIEVEMENT_FAMILIARS = 355;
|
||||
@@ -254,7 +253,7 @@ void familiars_evaluate(Entity_Player& p)
|
||||
unwritten_familiars_check(p);
|
||||
|
||||
familiar_check(p, {.rng = &formRng,
|
||||
.count = p.HasPlayerForm(PLAYERFORM_SPIDERBABY) ? 1 : 0,
|
||||
.count = p.HasPlayerForm(PLAYER_FORM_SPIDER_BABY) ? 1 : 0,
|
||||
.variant = Entity_Familiar::SPIDER_BABY});
|
||||
trinket_check(p, TRINKET_ISAACS_HEAD, Entity_Familiar::ISAACS_HEAD, p.HasTrinket(TRINKET_ISAACS_HEAD) ? 1 : 0);
|
||||
trinket_check(p, TRINKET_SOUL, Entity_Familiar::BLUE_BABY_SOUL,
|
||||
|
||||
@@ -99,24 +99,12 @@ bool Entity_Familiar::CanPlayerFire()
|
||||
reconstruction_missing("Entity_Familiar::CanPlayerFire 0062a8f0");
|
||||
}
|
||||
|
||||
// 00616db0
|
||||
void Entity_Familiar::ai_walker()
|
||||
{
|
||||
reconstruction_missing("Entity_Familiar::ai_walker 00616db0");
|
||||
}
|
||||
|
||||
// 0061a240
|
||||
void Entity_Familiar::ai_blue_babys_only_friend()
|
||||
{
|
||||
reconstruction_missing("Entity_Familiar::ai_blue_babys_only_friend 0061a240");
|
||||
}
|
||||
|
||||
// 0061a4e0
|
||||
void Entity_Familiar::ai_pickup_sack()
|
||||
{
|
||||
reconstruction_missing("Entity_Familiar::ai_pickup_sack 0061a4e0");
|
||||
}
|
||||
|
||||
// 0061bd50
|
||||
void Entity_Familiar::ai_daddy_longlegs()
|
||||
{
|
||||
@@ -135,12 +123,6 @@ void Entity_Familiar::ai_key_full()
|
||||
reconstruction_missing("Entity_Familiar::ai_key_full 0061d6b0");
|
||||
}
|
||||
|
||||
// 0062a930
|
||||
void Entity_Familiar::AddCoins(int)
|
||||
{
|
||||
reconstruction_missing("Entity_Familiar::AddCoins 0062a930");
|
||||
}
|
||||
|
||||
// 0062c8d0
|
||||
void Entity_Familiar::farting_baby_fart()
|
||||
{
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
|
||||
// The items and trinkets the familiars' shots read.
|
||||
constexpr int COLLECTIBLE_HIVE_MIND = 248;
|
||||
constexpr int COLLECTIBLE_TINY_PLANET = 233;
|
||||
constexpr int TRINKET_FORGOTTEN_LULLABY = 141;
|
||||
constexpr int TRINKET_ISAACS_HEAD_ID = 54;
|
||||
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
#include "boss_ai.h"
|
||||
#include "entity_effect.h"
|
||||
#include "entity_familiar.h"
|
||||
#include "entity_player.h"
|
||||
#include "game.h"
|
||||
#include "npc_ai.h"
|
||||
#include <cmath>
|
||||
|
||||
// The walkers' hunt: their reach grows with their contact damage, and they head home once this far from the one
|
||||
// they follow.
|
||||
constexpr float WALKER_RANGE_PER_DAMAGE = 15;
|
||||
constexpr float WALKER_RANGE_BASE = 65;
|
||||
constexpr int WALKER_TARGET_INTERVAL = 8;
|
||||
constexpr float WALKER_HOME_DISTANCE_SQUARED = 6400;
|
||||
|
||||
// Their pace (faster for the last Cube of Meat and Leech, a little less in a versus match), as the path finder
|
||||
// takes it.
|
||||
constexpr float WALKER_SPEED = 1.8f;
|
||||
constexpr float WALKER_FAST_SPEED = 2.2f;
|
||||
constexpr float WALKER_VERSUS_SPEED = 2;
|
||||
constexpr float WALKER_PATH_SCALE = 0.83f;
|
||||
constexpr float WALKER_FRICTION = 0.85f;
|
||||
constexpr float WALKER_IDLE_SPEED = 2;
|
||||
|
||||
// The blood the bigger Cubes of Meat drip, one frame in four.
|
||||
constexpr int WALKER_DRIP_ODDS = 4;
|
||||
constexpr float WALKER_DRIP_SCALE = 0.3f;
|
||||
constexpr float WALKER_DRIP_SCALE_BASE = 0.1f;
|
||||
|
||||
// How long a versus walker chases one target before it gives up on it for a while.
|
||||
constexpr int WALKER_VERSUS_CHASE_FRAMES = 449;
|
||||
|
||||
// Leech joins the line of leeches: behind the last one following something, else behind the player.
|
||||
static Vector leech_lead_find(Entity_Familiar& leech)
|
||||
{
|
||||
if (leech.parent) return leech.parent->pos;
|
||||
|
||||
Vector lead = leech.player->pos;
|
||||
for (Entity* entity : entity_query(ENTITY_FAMILIAR, Entity_Familiar::LEECH))
|
||||
{
|
||||
if (!entity->isExists || !entity->parent || entity->child) continue;
|
||||
|
||||
leech.parent = entity;
|
||||
entity->child = &leech;
|
||||
lead = entity->pos;
|
||||
break;
|
||||
}
|
||||
if (!leech.parent) leech.parent = leech.player;
|
||||
return lead;
|
||||
}
|
||||
|
||||
// The animation a walker shows for its motion: Leech's moves and bites by direction, the Cubes of Meat and Balls of
|
||||
// Bandages walking sideways or up and down. Facing left flips the sideways ones.
|
||||
static void walker_animate(Entity_Familiar& walker, bool isChasing)
|
||||
{
|
||||
bool isLeech = walker.variant == Entity_Familiar::LEECH;
|
||||
Vector motion = walker.velocity;
|
||||
if (vector_length(motion) < WALKER_IDLE_SPEED)
|
||||
{
|
||||
if (!isLeech) walker.sprite.Play("Idle");
|
||||
else if (walker.sprite.animState.animData) walker.sprite.animState.SetFrameFloat(0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (std::fabs(motion.y) < std::fabs(motion.x))
|
||||
{
|
||||
walker.sprite.Play(!isLeech ? "WalkHori" : isChasing ? "Attack Hori" : "Move Hori");
|
||||
walker.sprite.isFlipX = motion.x < 0;
|
||||
}
|
||||
else if (!isLeech) walker.sprite.Play("WalkVert");
|
||||
else if (isChasing) walker.sprite.Play(motion.y > 0 ? "Attack Down" : "Attack Up");
|
||||
else walker.sprite.Play(motion.y > 0 ? "Move Down" : "Move Up");
|
||||
}
|
||||
|
||||
// 00616db0 The walkers (the bigger Cubes of Meat and Balls of Bandages, Leech): path to the nearest enemy in reach,
|
||||
// else home to the player (Leech to the leech ahead), the cubes dripping blood.
|
||||
void Entity_Familiar::ai_walker()
|
||||
{
|
||||
Vector home = variant == LEECH ? leech_lead_find(*this) : player->pos;
|
||||
familiar_chase_limit(*this, WALKER_VERSUS_CHASE_FRAMES);
|
||||
|
||||
PickEnemyTarget({.range = collisionDamage * WALKER_RANGE_PER_DAMAGE + WALKER_RANGE_BASE,
|
||||
.frameInterval = WALKER_TARGET_INTERVAL});
|
||||
Vector goal = target ? target->pos : home;
|
||||
float reach = target ? 0 : WALKER_HOME_DISTANCE_SQUARED;
|
||||
bool isChasing = false;
|
||||
if (vector_length_squared(vector_sub(goal, pos)) > reach)
|
||||
{
|
||||
float speed = variant == CUBE_OF_MEAT_4 || variant == LEECH ? WALKER_FAST_SPEED : WALKER_SPEED;
|
||||
if (familiar_versus() && variant == CUBE_OF_MEAT_4) speed = WALKER_VERSUS_SPEED;
|
||||
pathfinder.FindGridPath(goal, speed * WALKER_PATH_SCALE, 0, DIRECT_PATH_FAR);
|
||||
isChasing = target != nullptr;
|
||||
}
|
||||
|
||||
if ((variant == CUBE_OF_MEAT_3 || variant == CUBE_OF_MEAT_4) && Random() % WALKER_DRIP_ODDS == 0)
|
||||
{
|
||||
Entity* drip =
|
||||
g_game->Spawn({.position = pos, .type = ENTITY_EFFECT, .variant = EFFECT_BLOOD_SPLAT, .seed = Random()});
|
||||
float scale = random_unit() * WALKER_DRIP_SCALE + WALKER_DRIP_SCALE_BASE;
|
||||
drip->sprite.scale = vector_make(scale, scale);
|
||||
drip->Update();
|
||||
}
|
||||
|
||||
friction *= WALKER_FRICTION;
|
||||
walker_animate(*this, isChasing);
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,6 @@
|
||||
#include "fx_layers.h"
|
||||
#include "data.h"
|
||||
#include "entity_effect.h"
|
||||
#include "game.h"
|
||||
#include "log.h"
|
||||
#include "manager.h"
|
||||
@@ -56,7 +57,6 @@ constexpr int DELETE_THIS_STAGES = 11;
|
||||
constexpr int STAGE_TYPE_COUNT = 5;
|
||||
constexpr uint32_t CURSE_DARKNESS = 1;
|
||||
constexpr uint32_t CHALLENGE_DELETE_THIS = 45;
|
||||
constexpr uint32_t EFFECT_SPRITE_TRAIL = 166;
|
||||
|
||||
// A normal room shows its floor's light rays one time in RAY_ODDS (in RAY_ODDS_CHAPTER_ONE on the first chapter).
|
||||
constexpr uint32_t RAY_ODDS = 2;
|
||||
|
||||
@@ -317,6 +317,7 @@ public:
|
||||
void SetColorModifier(const ColorModState& color, bool isLerp, float rate);
|
||||
void save_rewind_state(int leaveDoor);
|
||||
void StartRoomTransition(RoomTransitionRequest request);
|
||||
void ChangeRoom(int roomIndex, int dimension);
|
||||
void ShowHallucination(int frames, int backdrop);
|
||||
void Fadeout(float speed, FadeOutTarget target, KColor color = kcolor_rgba(0, 0, 0, 1));
|
||||
void store_game_state(GameState& state);
|
||||
|
||||
@@ -606,8 +606,7 @@ void Entity_Player::RestoreGameState(GameStatePlayer& saved)
|
||||
isLevelStartPending = saved.isLevelStartPending;
|
||||
hasCurseMistEffect = saved.hasCurseMistEffect;
|
||||
consumablesBackup = saved.consumablesBackup;
|
||||
if (!saved.curseMistFamiliars.empty())
|
||||
reconstruction_missing("Entity_Player::RestoreGameState 007ae4b0: Curse of the Mist's familiars");
|
||||
curseMistFamiliars = saved.curseMistFamiliars;
|
||||
curseMistRedHearts = saved.curseMistRedHearts;
|
||||
curseMistPocketItems = saved.curseMistPocketItems;
|
||||
curseMistTrinkets = saved.curseMistTrinkets;
|
||||
|
||||
+1
-2
@@ -415,8 +415,7 @@ void Entity_Player::StoreGameState(GameStatePlayer* saveState, bool isSaveTempor
|
||||
state.isLevelStartPending = isLevelStartPending;
|
||||
state.hasCurseMistEffect = hasCurseMistEffect;
|
||||
state.consumablesBackup = consumablesBackup;
|
||||
state.curseMistFamiliars.clear();
|
||||
for (Entity_Familiar* familiar : curseMistFamiliars) familiar->store_backup(&state.curseMistFamiliars.emplace_back());
|
||||
state.curseMistFamiliars = curseMistFamiliars;
|
||||
state.curseMistRedHearts = curseMistRedHearts;
|
||||
state.curseMistPocketItems = curseMistPocketItems;
|
||||
state.curseMistTrinkets = curseMistTrinkets;
|
||||
|
||||
@@ -18,24 +18,6 @@ constexpr int SAVE_FORGOTTEN_BODY_ROOM_NONE = -100000;
|
||||
constexpr int SAVE_MONKEY_PAW_CHARGES = 3;
|
||||
constexpr float SAVE_ROCK_BOTTOM_LUCK_UNSET = -9999;
|
||||
|
||||
// A familiar as it follows its player into a saved run or through Curse of the Mist (FamiliarData).
|
||||
struct FamiliarData
|
||||
{
|
||||
Vector formationTargetOffset{};
|
||||
float health = 0;
|
||||
int coins = 0;
|
||||
int hearts = 0;
|
||||
int keys = 0;
|
||||
int roomClearCount = 0;
|
||||
int state = 0;
|
||||
int subtype = 0;
|
||||
int variant = 0;
|
||||
uint32_t dropSeed = 0;
|
||||
uint32_t initSeed = 0;
|
||||
bool isNotCountedAsFollower = false;
|
||||
bool isSubtype55555 = false;
|
||||
};
|
||||
|
||||
// A co-op baby or a sub player, by its character and health.
|
||||
struct CoPlayerState
|
||||
{
|
||||
|
||||
+1
-2
@@ -64,7 +64,6 @@ constexpr float SACRIFICE_LIKE_ITEM = 0.63f;
|
||||
constexpr float SACRIFICE_LIKE_FORM = 0.65f;
|
||||
constexpr int SACRIFICE_LIKE_COIN_COUNT = 6;
|
||||
constexpr int SACRIFICE_LIKE_FORM_STEPS = 3;
|
||||
constexpr int PLAYER_FORM_EVIL_ANGEL = 8;
|
||||
constexpr float SACRIFICE_BLESS_SMALL = 0.15f;
|
||||
constexpr float SACRIFICE_BLESS_LARGE = 0.5f;
|
||||
constexpr int SACRIFICE_ANGEL_DELAY = 35;
|
||||
@@ -382,7 +381,7 @@ static void sacrifice_like_reward(GridEntity& spikes, RNG& reward, Entity_Player
|
||||
else if (roll < SACRIFICE_LIKE_ITEM)
|
||||
sacrifice_pickups_spawn(reward, position, PICKUP_COLLECTIBLE, 0, 1);
|
||||
else if (roll < SACRIFICE_LIKE_FORM && rewardPlayer)
|
||||
rewardPlayer->IncrementPlayerFormCounter(PLAYER_FORM_EVIL_ANGEL, SACRIFICE_LIKE_FORM_STEPS);
|
||||
rewardPlayer->IncrementPlayerFormCounter(PLAYER_FORM_LEVIATHAN, SACRIFICE_LIKE_FORM_STEPS);
|
||||
}
|
||||
|
||||
// The sacrifice room's twelfth and later reward: half the time, unless the run ends before the Dark Room or Cathedral
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include "room_render.h"
|
||||
#include "seeds.h"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
|
||||
@@ -20,113 +19,6 @@ constexpr int DECORATION_ATTEMPTS = 20;
|
||||
|
||||
// A puddle stains a footprint with its texel under the player, any layer's that is not quite clear.
|
||||
constexpr float PUDDLE_ALPHA_THRESHOLD = 0.01f;
|
||||
constexpr int ANY_LAYER = -1;
|
||||
|
||||
// What Sprite::GetTexel samples: a screen position, where the sprite draws, the alpha a texel must reach and the
|
||||
// layer it looks in (any for -1).
|
||||
struct TexelQuery
|
||||
{
|
||||
Vector sample{};
|
||||
Vector renderPos{};
|
||||
float alphaThreshold = 0;
|
||||
int layerId = ANY_LAYER;
|
||||
};
|
||||
|
||||
// Turns a point about the origin, as KAGE's Quad::rotate turns a quad's corners.
|
||||
static Vector point_turn(Vector point, float cosine, float sine)
|
||||
{
|
||||
return vector_make(point.x * cosine - point.y * sine, point.y * cosine + point.x * sine);
|
||||
}
|
||||
|
||||
// 0040b600 (ANM2::GetTexel) The color an animation of a sprite shows at a screen position: the texel of the first
|
||||
// visible layer keyframe over it that reaches the alpha, in the sprite's, layer's and keyframe's tints and offsets
|
||||
// (colorize aside), else clear. A turned layer is turned back about the origin, sample and all.
|
||||
static KColor animation_texel_get(const ANM2& sprite, const AnimationState& animation, const TexelQuery& query)
|
||||
{
|
||||
if (!animation.animData) return {};
|
||||
|
||||
const std::vector<AnimationLayer>& tracks = animation.animData->animLayers;
|
||||
for (size_t track = 0; track < tracks.size(); track++)
|
||||
{
|
||||
const AnimationLayer& layer = tracks[track];
|
||||
int frameIndex = track < animation.layerFrames.size() ? animation.layerFrames[track] : -1;
|
||||
bool isLayerKnown = layer.layerId >= 0 && layer.layerId < (int)sprite.layerStates.size();
|
||||
if (layer.frames.empty() || (query.layerId >= 0 && layer.layerId != query.layerId) || !isLayerKnown) continue;
|
||||
if (frameIndex < 0 || frameIndex >= (int)layer.frames.size()) continue;
|
||||
|
||||
const AnimationFrame& frame = layer.frames[frameIndex];
|
||||
const LayerState& state = sprite.layerStates[layer.layerId];
|
||||
if (!frame.isVisible || !state.isVisible || !state.spriteSheet) continue;
|
||||
|
||||
SpriteDraw draw = {.position = query.renderPos};
|
||||
SourceQuad source = AnimationLayer::GetSourceQuad(frame, state, draw, sprite);
|
||||
DestinationQuad screen = AnimationLayer::GetDestQuad(frame, state, draw, sprite);
|
||||
Vector sample = query.sample;
|
||||
float layerTurn = frame.rotation + state.rotation;
|
||||
float spriteTurn = sprite.rotation;
|
||||
if (spriteTurn != 0 || layerTurn != 0)
|
||||
{
|
||||
float layerScaleX = frame.scale.x * state.size.x;
|
||||
float layerScaleY = state.isFlipY ? -(frame.scale.y * state.size.y) : frame.scale.y * state.size.y;
|
||||
float spriteScaleY = sprite.isFlipY ? -sprite.scale.y : sprite.scale.y;
|
||||
if ((sprite.scale.x < 0) != (layerScaleX < 0))
|
||||
{
|
||||
if (sprite.scale.x < 0)
|
||||
{
|
||||
layerTurn = -layerTurn;
|
||||
spriteTurn = -spriteTurn;
|
||||
}
|
||||
if (layerScaleX < 0) layerTurn = -layerTurn;
|
||||
}
|
||||
if ((spriteScaleY < 0) != (layerScaleY < 0))
|
||||
{
|
||||
if (spriteScaleY < 0)
|
||||
{
|
||||
layerTurn = -layerTurn;
|
||||
spriteTurn = -spriteTurn;
|
||||
}
|
||||
if (layerScaleY < 0) layerTurn = -layerTurn;
|
||||
}
|
||||
|
||||
float angle = -(layerTurn + spriteTurn) * DEGREES_TO_RADIANS;
|
||||
float cosine = std::cos(angle);
|
||||
float sine = std::sin(angle);
|
||||
for (Vector* corner : {&screen._topLeft, &screen._topRight, &screen._bottomLeft, &screen._bottomRight})
|
||||
*corner = point_turn(*corner, cosine, sine);
|
||||
sample = point_turn(sample, cosine, sine);
|
||||
}
|
||||
|
||||
Vector topLeft = screen._topLeft;
|
||||
Vector bottomRight = screen._bottomRight;
|
||||
bool isOverX = topLeft.x < sample.x && sample.x < bottomRight.x;
|
||||
if (!isOverX || topLeft.y >= sample.y || sample.y >= bottomRight.y) continue;
|
||||
|
||||
float across = std::clamp((sample.x - topLeft.x) / (bottomRight.x - topLeft.x), 0.0f, 1.0f);
|
||||
float down = std::clamp((sample.y - topLeft.y) / (bottomRight.y - topLeft.y), 0.0f, 1.0f);
|
||||
float texelX = (source._bottomRight.x - source._topLeft.x) * across + source._topLeft.x;
|
||||
float texelY = (source._bottomRight.y - source._topLeft.y) * down + source._topLeft.y;
|
||||
KColor texel = image_texel_get(*state.spriteSheet, (uint32_t)(int)texelX, (uint32_t)(int)texelY);
|
||||
if (texel._alpha < query.alphaThreshold) continue;
|
||||
|
||||
ColorMod color = sprite.color;
|
||||
color_multiply(color, state.color);
|
||||
color_multiply(color, frame.color);
|
||||
float red = color._tint[0] * texel._red + color._offset[0];
|
||||
float green = color._tint[1] * texel._green + color._offset[1];
|
||||
float blue = color._tint[2] * texel._blue + color._offset[2];
|
||||
return kcolor_rgba(red, green, blue, color._tint[3] * texel._alpha);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
// 0040b590 (Sprite::GetTexel) The color a sprite shows at a screen position: its overlay's, unless that falls short
|
||||
// of the alpha, then its main animation's.
|
||||
static KColor sprite_texel_get(const ANM2& sprite, const TexelQuery& query)
|
||||
{
|
||||
KColor texel = animation_texel_get(sprite, sprite.overlayAnimState, query);
|
||||
if (texel._alpha < query.alphaThreshold) texel = animation_texel_get(sprite, sprite.animState, query);
|
||||
return texel;
|
||||
}
|
||||
|
||||
// 0099acc0 Picks the prop: a crawlspace's ladder, Greed's props, or one of the backdrop's (G FUEL's on its seed) drawn
|
||||
// from the cell's decoration seed until it suits the backdrop and the room has no puddle yet. Counts the puddles.
|
||||
@@ -214,10 +106,10 @@ void GridEntity_Decoration::Update()
|
||||
if (player->entityGridCollisionClass != GRIDCOLL_GROUND)
|
||||
continue;
|
||||
|
||||
TexelQuery query = {.sample = render_position_get(player->pos, RENDER_SNAPPED),
|
||||
.renderPos = get_render_position(),
|
||||
TexelQuery query = {.renderPos = get_render_position(),
|
||||
.sample = render_position_get(player->pos, RENDER_SNAPPED),
|
||||
.alphaThreshold = PUDDLE_ALPHA_THRESHOLD};
|
||||
KColor texel = sprite_texel_get(sprite, query);
|
||||
KColor texel = sprite.GetTexel(query);
|
||||
if (texel._alpha > 0)
|
||||
player->SetFootprintColor(texel, true);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ constexpr int DOOR_TARGET_MIRROR = -100;
|
||||
constexpr int DOOR_TARGET_MINESHAFT = -101;
|
||||
|
||||
// The stage of the Blue Womb, the dimension of Downpour's mirror world and of Home's dark closet, and Home's stage.
|
||||
constexpr int DIMENSION_MIRROR = 1;
|
||||
constexpr int DIMENSION_DEATH_CERTIFICATE = 2;
|
||||
|
||||
// The secret exits get_secret_exit_kind tells apart, by the exit room's subtype, and the boss subtype of Mom's Heart's
|
||||
|
||||
@@ -100,7 +100,6 @@ constexpr int BLACK_POOP_CONFUSION = 60;
|
||||
constexpr ColorMod BLACK_POOP_CLOUD = {{0.01f, 0.01f, 0.01f, 1}, {0, 0, 0, 1}, {0, 0, 0}};
|
||||
constexpr float BROWN_CAP_DAMAGE = 100;
|
||||
constexpr float BROWN_CAP_RADIUS = 50;
|
||||
constexpr int PLAYER_FORM_POOP = 9;
|
||||
constexpr int OH_CRAP_FORM_COUNT = 3;
|
||||
|
||||
// The gibs: a third more of them per hit with Extra Blood, how fast they fly, and a rainbow gib's flatter throw.
|
||||
@@ -856,7 +855,7 @@ static void meconium_drop_try(const Vector& position, const EntityRef& source, R
|
||||
// Whether a player has the Oh Crap form and so heals on broken poop.
|
||||
static bool is_oh_crap(Entity_Player& player)
|
||||
{
|
||||
return !player.hasCurseMistEffect && !player.isCoopGhost && player.playerForms[PLAYER_FORM_POOP] >= OH_CRAP_FORM_COUNT;
|
||||
return !player.hasCurseMistEffect && !player.isCoopGhost && player.playerForms[PLAYER_FORM_OH_CRAP] >= OH_CRAP_FORM_COUNT;
|
||||
}
|
||||
|
||||
// Lil Larva's blue flies and Brown Cap's blast from a broken poop (the breaker's trinkets in versus).
|
||||
|
||||
+109
-8
@@ -1,5 +1,6 @@
|
||||
#include "homing_laser.h"
|
||||
#include "boss_ai.h"
|
||||
#include "entity_familiar.h"
|
||||
#include "entity_laser.h"
|
||||
#include "entity_player.h"
|
||||
#include "entity_tear.h"
|
||||
@@ -16,6 +17,15 @@ constexpr float SMOOTHING_FULL_LENGTH = 200;
|
||||
constexpr float PLAYER_CUT_DISTANCE_SQUARED = 100;
|
||||
constexpr uint32_t PLAYER_CUT_FIRST_SAMPLE = 2;
|
||||
constexpr float GRID_HALF_CELL = GRID_CELL_SIZE / 2;
|
||||
constexpr float OBSTACLE_MARGIN = 20;
|
||||
|
||||
// A hunting path: 40 long steps turned 0.3 toward the nearest target, up to 25 points, smoothed at 0.4. A path shorter
|
||||
// than 0.1 does not hunt.
|
||||
constexpr float HUNT_STEP = 40;
|
||||
constexpr float HUNT_TURN = 0.3f;
|
||||
constexpr size_t HUNT_MAX_POINTS = 25;
|
||||
constexpr float HUNT_TENSION = 0.4f;
|
||||
constexpr float HUNT_MIN_LENGTH_SQUARED = 0.01f;
|
||||
|
||||
// A point on the cubic curve from one bezier point to the next, t from 0 to 1.
|
||||
static Vector bezier_evaluate(const BezierPoint& from, const BezierPoint& to, float t)
|
||||
@@ -101,8 +111,63 @@ LineCheck room_line_check(const Vector& from, const Vector& to, int gridCollisio
|
||||
return {progress < 1 ? position : to, progress >= 1};
|
||||
}
|
||||
|
||||
// The entities a homing path bends toward: vulnerable enemies (of another type than the source for that path type),
|
||||
// a versus rival's punching bag, and the players too for a path that hits them.
|
||||
static std::vector<Entity*> homing_targets_get(BezierPathType pathType, Entity* source)
|
||||
{
|
||||
std::vector<Entity*> targets;
|
||||
for (Entity* entity : g_game->room->entityList.updateEL)
|
||||
{
|
||||
bool isTarget = entity->IsVulnerableEnemy(nullptr) && !entity->HasEntityFlags(FLAG_FRIENDLY | FLAG_NO_TARGET) &&
|
||||
entity != source && !(pathType == BEZIER_PATH_OTHER_TYPES && entity->type == source->type);
|
||||
bool isRivalBag = g_game->deathmatchManager.is_active() && entity->type == ENTITY_FAMILIAR &&
|
||||
entity->variant == Entity_Familiar::PUNCHING_BAG &&
|
||||
!entity->IsDescendantOf(source->spawnerEntity);
|
||||
if (isTarget || isRivalBag) targets.push_back(entity);
|
||||
if (pathType == BEZIER_PATH_WITH_PLAYERS && entity->type == ENTITY_PLAYER && entity != source)
|
||||
targets.push_back(entity);
|
||||
}
|
||||
return targets;
|
||||
}
|
||||
|
||||
// A path that hunts its way from its origin through the room: 40 long steps, each turned toward the nearest target
|
||||
// (more so the more it already faces it), until it leaves the room or has 25 points.
|
||||
static void homing_hunt(HomingLaser& path, const std::vector<Entity*>& targets)
|
||||
{
|
||||
Vector heading = vector_sub(path.bezier.back().point, path.bezier.front().point);
|
||||
if (vector_length_squared(heading) < HUNT_MIN_LENGTH_SQUARED) return;
|
||||
|
||||
path.bezier.pop_back();
|
||||
while (!targets.empty())
|
||||
{
|
||||
Vector last = path.bezier.back().point;
|
||||
Entity* nearest = nullptr;
|
||||
float best = INFINITY;
|
||||
for (Entity* target : targets)
|
||||
{
|
||||
float distance = vector_length_squared(vector_sub(last, target->pos));
|
||||
if (distance >= best) continue;
|
||||
nearest = target;
|
||||
best = distance;
|
||||
}
|
||||
if (!nearest) break;
|
||||
|
||||
Vector toward = vector_normalized(vector_sub(nearest->pos, last));
|
||||
float facing = (vector_dot(vector_normalized(heading), toward) + 1) * BEZIER_HALF;
|
||||
size_t count = path.bezier.size();
|
||||
if (count > 1) heading = vector_sub(path.bezier[count - 1].point, path.bezier[count - 2].point);
|
||||
heading = vector_normalized(vector_add(vector_normalized(heading), vector_scale(toward, HUNT_TURN * facing)));
|
||||
|
||||
Vector next = vector_add(last, vector_scale(heading, HUNT_STEP));
|
||||
path.bezier.push_back({next, {}, {}});
|
||||
if (!g_game->room->IsPositionInRoom(next, 0) || path.bezier.size() >= HUNT_MAX_POINTS) break;
|
||||
}
|
||||
path.compute_bezier_handles(HUNT_TENSION);
|
||||
}
|
||||
|
||||
// 0099c790 Lays out the path's bezier points: a straight one from the origin to the end unless some are already
|
||||
// there. The homing paths and Eye of the Occult's bend are not reconstructed yet.
|
||||
// there, then for a path that hits players one hunting its targets. Eye of the Occult's bend and the homing and
|
||||
// other types' bends toward their targets are not reconstructed yet.
|
||||
void HomingLaser::build_bezier_path(BezierPathType pathType, Entity* source)
|
||||
{
|
||||
if (bezier.empty())
|
||||
@@ -112,11 +177,14 @@ void HomingLaser::build_bezier_path(BezierPathType pathType, Entity* source)
|
||||
bezier.push_back({endPoint, middle, endPoint});
|
||||
}
|
||||
|
||||
std::vector<Entity*> targets;
|
||||
if (pathType != BEZIER_PATH_STRAIGHT) targets = homing_targets_get(pathType, source);
|
||||
Entity_Laser* laser = owner && owner->type == ENTITY_LASER ? static_cast<Entity_Laser*>(owner) : nullptr;
|
||||
if (laser && laser->tearFlags[TEAR_OCCULT])
|
||||
reconstruction_missing("HomingLaser::build_bezier_path 0099c790: Eye of the Occult's bend");
|
||||
if (pathType != BEZIER_PATH_STRAIGHT && source)
|
||||
if (pathType == BEZIER_PATH_HOMING || pathType == BEZIER_PATH_OTHER_TYPES)
|
||||
reconstruction_missing("HomingLaser::build_bezier_path 0099c790: a homing path");
|
||||
if (pathType == BEZIER_PATH_WITH_PLAYERS && bezier.size() == 2) homing_hunt(*this, targets);
|
||||
}
|
||||
|
||||
// 0099e360 Samples the bezier path evenly along its length, then eases the kept samples toward them: a ring all at
|
||||
@@ -301,10 +369,32 @@ void HomingLaser::compute_axis_bezier_handles()
|
||||
reconstruction_missing("HomingLaser::compute_axis_bezier_handles 0099dca0");
|
||||
}
|
||||
|
||||
// 0099e160
|
||||
void HomingLaser::compute_bezier_handles(float)
|
||||
// 0099e160 Smooths the path: each point's handles lie along the line from its neighbours, scaled by the tension
|
||||
// (halved between two neighbours). A path ending where it started (three points or more) wraps around.
|
||||
void HomingLaser::compute_bezier_handles(float tension)
|
||||
{
|
||||
reconstruction_missing("HomingLaser::compute_bezier_handles 0099e160");
|
||||
if (bezier.empty()) return;
|
||||
|
||||
size_t last = bezier.size() - 1;
|
||||
bool isClosed = vector_length_squared(vector_sub(bezier[last].point, bezier[0].point)) < HUNT_MIN_LENGTH_SQUARED &&
|
||||
bezier.size() >= 3;
|
||||
for (size_t i = 0; i <= last; i++)
|
||||
{
|
||||
Vector previous{};
|
||||
Vector next{};
|
||||
if (isClosed && i == 0) previous = vector_sub(bezier[0].point, bezier[last - 1].point);
|
||||
else
|
||||
{
|
||||
if (isClosed && i == last) next = vector_sub(bezier[1].point, bezier[i].point);
|
||||
if (i != 0) previous = vector_sub(bezier[i].point, bezier[i - 1].point);
|
||||
}
|
||||
if (i < last) next = vector_sub(bezier[i + 1].point, bezier[i].point);
|
||||
|
||||
Vector handle = vector_scale(vector_add(previous, next), tension);
|
||||
if (isClosed || (i != 0 && i < last)) handle = vector_scale(handle, BEZIER_HALF);
|
||||
bezier[i].handleIn = vector_sub(bezier[i].point, handle);
|
||||
bezier[i].handleOut = vector_add(bezier[i].point, handle);
|
||||
}
|
||||
}
|
||||
|
||||
// 0099ec00
|
||||
@@ -325,10 +415,21 @@ void HomingLaser::build_wiggle_bezier()
|
||||
reconstruction_missing("HomingLaser::build_wiggle_bezier 0099fed0");
|
||||
}
|
||||
|
||||
// 009a0c50
|
||||
void HomingLaser::truncate_samples_at_obstacle(const Vector&)
|
||||
// 009a0c50 Cuts the path at the first segment past the first that a wall or obstacle stops, the stop taking the
|
||||
// place of the segment's start.
|
||||
void HomingLaser::truncate_samples_at_obstacle(const Vector& offset)
|
||||
{
|
||||
reconstruction_missing("HomingLaser::truncate_samples_at_obstacle 009a0c50");
|
||||
for (size_t i = 1; i + 1 < samples.size(); i++)
|
||||
{
|
||||
Vector start = samples[i];
|
||||
Vector segment = vector_sub(samples[i + 1], start);
|
||||
Vector stop = Entity_Laser::CalculateEndPoint(start, vector_normalized(segment), offset, nullptr, OBSTACLE_MARGIN);
|
||||
if (vector_length_squared(vector_sub(start, stop)) >= vector_length_squared(segment)) continue;
|
||||
|
||||
samples[i] = stop;
|
||||
samples.resize(i + 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 009a0fa0
|
||||
|
||||
@@ -17,8 +17,6 @@ constexpr int DEFAULT_TRINKET_COUNT = 190;
|
||||
constexpr int DEFAULT_CARD_COUNT = 98;
|
||||
constexpr int DEFAULT_PILL_COUNT = 50;
|
||||
|
||||
// Necromancer's items, which count toward it without a tag.
|
||||
constexpr int PLAYER_FORM_NECROMANCER = 15;
|
||||
|
||||
// A group of info_display.xml: its element names and the kind of entry it fills.
|
||||
struct InfoDisplayGroup
|
||||
|
||||
@@ -26,6 +26,27 @@ constexpr int EXTRA_WISP_SLOTS = 19;
|
||||
constexpr int TAG_CACHE_SLOTS = 32;
|
||||
constexpr int LOCUST_QUALITY_COUNT = 5;
|
||||
|
||||
// Lua's PlayerForm: the transformations, by the slot of Entity_Player::playerForms that counts their items.
|
||||
enum PlayerForm : int
|
||||
{
|
||||
PLAYER_FORM_GUPPY,
|
||||
PLAYER_FORM_BEELZEBUB,
|
||||
PLAYER_FORM_FUN_GUY,
|
||||
PLAYER_FORM_SERAPHIM,
|
||||
PLAYER_FORM_BOB,
|
||||
PLAYER_FORM_SPUN,
|
||||
PLAYER_FORM_YES_MOTHER,
|
||||
PLAYER_FORM_CONJOINED,
|
||||
PLAYER_FORM_LEVIATHAN,
|
||||
PLAYER_FORM_OH_CRAP,
|
||||
PLAYER_FORM_BOOKWORM,
|
||||
PLAYER_FORM_ADULT,
|
||||
PLAYER_FORM_SPIDER_BABY,
|
||||
PLAYER_FORM_STOMPY,
|
||||
PLAYER_FORM_FLIGHT,
|
||||
PLAYER_FORM_NECROMANCER
|
||||
};
|
||||
|
||||
// What an ItemConfig_Item describes, by the XML element it came from.
|
||||
enum ItemType : int
|
||||
{
|
||||
|
||||
+2
-1
@@ -27,7 +27,8 @@ enum GiantbookOverlay : int
|
||||
GIANTBOOK_CLICKER = 39,
|
||||
GIANTBOOK_SLEEP_NIGHTMARE = 44,
|
||||
GIANTBOOK_MEGA_MUSH = 45,
|
||||
GIANTBOOK_ETERNAL_BLACK_HEART = 46
|
||||
GIANTBOOK_ETERNAL_BLACK_HEART = 46,
|
||||
GIANTBOOK_NECROMANCER = 47
|
||||
};
|
||||
|
||||
// Destruction (009abd80) is the default.
|
||||
|
||||
+23
-6
@@ -5,6 +5,7 @@
|
||||
#include "entity_pickup.h"
|
||||
#include "active_items.h"
|
||||
#include "entity_player.h"
|
||||
#include "entity_player_tainted.h"
|
||||
#include "game.h"
|
||||
#include "grid_entity.h"
|
||||
#include "item_pool.h"
|
||||
@@ -14,6 +15,8 @@
|
||||
#include "room_grid.h"
|
||||
#include "room_special.h"
|
||||
#include "seeds.h"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
// The items, characters, rooms and unlocks the pedestals ask about.
|
||||
constexpr int COLLECTIBLE_KEY_PIECE_A = 238;
|
||||
@@ -409,9 +412,9 @@ bool Entity_Pickup::collectible_collect(Entity_Player& player)
|
||||
else sprite.Play("Idle");
|
||||
player.AnimatePickup(&sprite, false, HasEntityFlags(FLAG_NO_DEATH_TRIGGER) ? "UseItem" : "Pickup");
|
||||
|
||||
bool isExchanged = item->type == ITEM_ACTIVE && active_pedestal_swap(*this, player);
|
||||
if (item->type != ITEM_ACTIVE && player.playerType == PLAYER_ISAAC_B && player.CanAddCollectibleToInventory(item->id))
|
||||
reconstruction_missing("Entity_Pickup::HandleCollision 006e8ae0: Tainted Isaac's inventory");
|
||||
bool isInventoryItem = player.playerType == PLAYER_ISAAC_B && player.CanAddCollectibleToInventory(item->id);
|
||||
bool isExchanged = item->type == ITEM_ACTIVE ? active_pedestal_swap(*this, player)
|
||||
: isInventoryItem && tainted_isaac_pedestal_swap(*this, player);
|
||||
if (game.deathmatchManager.is_active())
|
||||
reconstruction_missing("Entity_Pickup::HandleCollision 006e8ae0: the deathmatch's items");
|
||||
|
||||
@@ -503,8 +506,9 @@ void item_text_show(HUD& hud, Entity_Player* player, ItemConfig_Item* item)
|
||||
}
|
||||
|
||||
// 006edfa0 Turns a cycling pedestal to its next item every 30 frames (every 6 with four or more, every frame with
|
||||
// eight), every frame while paused, or at once when forced. An emptied pedestal stops cycling. Only the wait is
|
||||
// reconstructed: a turn stops the game until reached.
|
||||
// eight), every frame while paused, or at once when forced. The shown item goes to the back of the list and the first
|
||||
// one is shown, keeping its price, seed, wait and animation frame. An emptied pedestal stops cycling.
|
||||
// The original fills the list past its count with whatever its stack held. Here those entries keep their values.
|
||||
void Entity_Pickup::update_cycle_collectible(bool isForce)
|
||||
{
|
||||
constexpr int CYCLE_FRAMES_FEW = 30;
|
||||
@@ -521,5 +525,18 @@ void Entity_Pickup::update_cycle_collectible(bool isForce)
|
||||
return;
|
||||
}
|
||||
bool isTurn = isForce || (g_game->frameCount - spawnFrame >= 1 && IsFrame(frequency, 0)) || g_game->IsPaused();
|
||||
if (isTurn) reconstruction_missing("Entity_Pickup::update_cycle_collectible 006edfa0 (a turn)");
|
||||
if (!isTurn) return;
|
||||
|
||||
std::array<uint32_t, CYCLE_COLLECTIBLE_LIMIT> list = cycleCollectibleList;
|
||||
uint32_t count = cycleCollectibleCount;
|
||||
int heldWait = wait;
|
||||
float frame = sprite.animState.animData ? std::floor(sprite.animState.animFrame) : -1;
|
||||
std::shift_left(list.begin(), list.begin() + count, 1);
|
||||
list[count - 1] = (uint32_t)subtype;
|
||||
|
||||
Morph(type, variant, (int)cycleCollectibleList[0], true, true, true);
|
||||
if (sprite.animState.animData) sprite.animState.SetFrameFloat(frame);
|
||||
wait = heldWait;
|
||||
cycleCollectibleList = list;
|
||||
cycleCollectibleCount = count;
|
||||
}
|
||||
@@ -92,7 +92,6 @@ constexpr uint32_t DESCRIPTOR_DEVIL_TREASURE = 0x800;
|
||||
constexpr int BOSS_THE_FALLEN = 23;
|
||||
constexpr int HOME_CHEST_SUBTYPE = 2;
|
||||
|
||||
constexpr int COLLECTIBLE_ROTTEN_MEAT = 26;
|
||||
constexpr int COLLECTIBLE_ROSARY = 72;
|
||||
constexpr int COLLECTIBLE_VIRGO = 303;
|
||||
constexpr int COLLECTIBLE_CHAOS = 402;
|
||||
|
||||
@@ -89,18 +89,15 @@ constexpr int ACHIEVEMENT_STORE_UPGRADE_4 = 154;
|
||||
constexpr int ACHIEVEMENT_SOMETHING_WICKED = 346;
|
||||
constexpr int ACHIEVEMENT_SOMETHING_WICKED_PLUS = 347;
|
||||
constexpr int ACHIEVEMENT_THE_FORGOTTEN = 390;
|
||||
constexpr int ACHIEVEMENT_PLANETARIUMS = 406;
|
||||
constexpr int EVENT_COUNTER_SUPER_SINS_A = 24;
|
||||
constexpr int EVENT_COUNTER_SUPER_SINS_B = 25;
|
||||
constexpr int EVENT_COUNTER_CURSE_ODDS = 11;
|
||||
constexpr int COLLECTIBLE_XRAY_VISION = 76;
|
||||
constexpr int COLLECTIBLE_CRYSTAL_BALL = 158;
|
||||
constexpr int COLLECTIBLE_MAGIC_8_BALL = 194;
|
||||
constexpr int COLLECTIBLE_MOMS_SHOVEL = 552;
|
||||
constexpr int TRINKET_GOLDEN_HORSE_SHOE = 82;
|
||||
constexpr int TRINKET_FRAGMENTED_CARD = 102;
|
||||
constexpr int TRINKET_SILVER_DOLLAR = 110;
|
||||
constexpr int TRINKET_PAY_TO_WIN = 112;
|
||||
constexpr int TRINKET_TELESCOPE_LENS = 152;
|
||||
constexpr int COLLECTIBLE_VOODOO_HEAD = 599;
|
||||
constexpr int TRINKET_MYOSOTIS = 137;
|
||||
@@ -3011,36 +3008,6 @@ int Level::GetNeighborRoomIdx(int roomIdx, int doorSlot)
|
||||
return neighbor < 0 ? -2 : neighbor;
|
||||
}
|
||||
|
||||
// 0074c9e0 The slots a red room would open toward.
|
||||
uint32_t Level::get_red_room_neighbor_slots(int, int, int*)
|
||||
{
|
||||
reconstruction_missing("Level::get_red_room_neighbor_slots 0074c9e0");
|
||||
}
|
||||
|
||||
// 0074cb50 The layout room a red room door would make.
|
||||
LevelGenerator_Room Level::get_door_neighbor_room(int, int)
|
||||
{
|
||||
reconstruction_missing("Level::get_door_neighbor_room 0074cb50");
|
||||
}
|
||||
|
||||
// 0074cd70 Whether a Red Key outline shows on a door.
|
||||
bool Level::CanSpawnDoorOutline(int, int)
|
||||
{
|
||||
reconstruction_missing("Level::CanSpawnDoorOutline 0074cd70");
|
||||
}
|
||||
|
||||
// 0074cea0 A red room's type.
|
||||
int Level::roll_red_room_type()
|
||||
{
|
||||
reconstruction_missing("Level::roll_red_room_type 0074cea0");
|
||||
}
|
||||
|
||||
// 0074d010 Opens a red room through a door.
|
||||
bool Level::MakeRedRoomDoor(int, int)
|
||||
{
|
||||
reconstruction_missing("Level::MakeRedRoomDoor 0074d010");
|
||||
}
|
||||
|
||||
// 0074d780 Adds a second boss room.
|
||||
bool Level::TryInitializeExtraBossRoom(uint32_t)
|
||||
{
|
||||
|
||||
+5
-2
@@ -25,6 +25,9 @@ constexpr int PORTAL_ROOM_NONE = -99999;
|
||||
// The xorshift a level's RNGs start on before Level::Init seeds them (shift index 35).
|
||||
constexpr RNG LEVEL_RNG_DEFAULT = {RNG_SEED_DEFAULT, 5, 9, 7};
|
||||
|
||||
// The mirror world's dimension, the mineshaft's on a Mines floor.
|
||||
constexpr int DIMENSION_MIRROR = 1;
|
||||
|
||||
// The secret exit a floor's door leads to, also the exit room's layout subtype. Mom's Heart's leads to the Corpse
|
||||
// and the Ascent.
|
||||
enum SecretExitKind
|
||||
@@ -292,10 +295,10 @@ public:
|
||||
int GetTargetSlot(int roomIdx, int doorSlot);
|
||||
static XY get_door_neighbor_pos(XY gridPos, RoomShape shape, int doorSlot);
|
||||
int GetNeighborRoomIdx(int roomIdx, int doorSlot);
|
||||
static uint32_t get_red_room_neighbor_slots(int roomIdx, int doorSlot, int* outSlots);
|
||||
bool get_red_room_neighbor_slots(int roomIdx, int doorSlot, int* outSlot, int* outEntrySlot);
|
||||
LevelGenerator_Room get_door_neighbor_room(int roomIdx, int doorSlot);
|
||||
bool CanSpawnDoorOutline(int roomIdx, int doorSlot);
|
||||
static int roll_red_room_type();
|
||||
static int roll_red_room_type(RNG& rng);
|
||||
bool MakeRedRoomDoor(int roomIdx, int doorSlot);
|
||||
void UncoverHiddenDoor(int roomIdx, int doorSlot);
|
||||
bool prepare_blue_room(int currentRoomIdx, int targetRoomIdx, int direction);
|
||||
|
||||
@@ -0,0 +1,310 @@
|
||||
#include "game.h"
|
||||
#include "grid_entity_door.h"
|
||||
#include "level.h"
|
||||
#include "level_generator.h"
|
||||
#include "log.h"
|
||||
#include "manager.h"
|
||||
#include "npc_ai.h"
|
||||
#include "platform.h"
|
||||
#include "room.h"
|
||||
#include "room_config.h"
|
||||
#include "sfx_manager.h"
|
||||
#include <algorithm>
|
||||
|
||||
// The map's width and height in cells.
|
||||
constexpr int MAP_SIZE = 13;
|
||||
|
||||
// The Red Key's weighted room types (weights out of 512, the rest a normal room), and what it makes of a planetarium
|
||||
// before planetariums are unlocked.
|
||||
constexpr std::array<std::array<int, 2>, 16> RED_ROOM_TYPES = {{{2, ROOM_DEVIL},
|
||||
{2, ROOM_ANGEL},
|
||||
{3, ROOM_SECRET},
|
||||
{3, ROOM_SUPERSECRET},
|
||||
{6, ROOM_SHOP},
|
||||
{4, ROOM_TREASURE},
|
||||
{2, ROOM_PLANETARIUM},
|
||||
{9, ROOM_CURSE},
|
||||
{8, ROOM_SACRIFICE},
|
||||
{5, ROOM_ARCADE},
|
||||
{2, ROOM_CHEST},
|
||||
{2, ROOM_DICE},
|
||||
{4, ROOM_LIBRARY},
|
||||
{2, ROOM_ISAACS},
|
||||
{2, ROOM_BARREN},
|
||||
{7, ROOM_MINIBOSS}}};
|
||||
constexpr uint32_t RED_ROOM_ROLL_MASK = 0x1ff;
|
||||
|
||||
// The Red Key's room rng, and what a red room's config query asks: four doors, a devil or angel room's subtype and
|
||||
// variant limit (Number Magnet's devil rooms), a miniboss's difficulty by floor, and Home's own rooms.
|
||||
constexpr uint32_t RED_ROOM_ROW_SEED = 929;
|
||||
constexpr std::array<uint32_t, 3> RED_ROOM_SHIFTS = {4, 3, 27};
|
||||
constexpr uint32_t RED_ROOM_DOORS = 0xf;
|
||||
constexpr uint32_t RED_ROOM_SPECIAL_VARIANTS = 99;
|
||||
constexpr int RED_ROOM_DIFFICULTY_MAX = 15;
|
||||
constexpr int RED_ROOM_LATE_MINIBOSS = 10;
|
||||
constexpr int RED_ROOM_LATE_STAGE = 6;
|
||||
constexpr int HOME_STAGE_ID = 35;
|
||||
constexpr int HOME_ROOM_SUBTYPE = 11;
|
||||
constexpr int HOME_DIFFICULTY_MAX = 10;
|
||||
constexpr XY HOME_RED_ROOM_CELL = {3, 7};
|
||||
constexpr int NEXT_STAGE_ROOM = -2;
|
||||
constexpr int ROOM_IDX_MIN = -20;
|
||||
constexpr int ROOM_IDX_MAX = 168;
|
||||
constexpr int LAST_DOOR_SLOT = 7;
|
||||
|
||||
// The slot a door enters a neighbouring room by: the opposite side, its second door when the neighbour's origin lies
|
||||
// before the cell on that side.
|
||||
static int entry_slot_get(int slot, const RoomDescriptor& neighbor, int cell)
|
||||
{
|
||||
int entry = (slot + 2) % 4;
|
||||
bool isHorizontal = entry == DOOR_UP0 || entry == DOOR_DOWN0;
|
||||
if (isHorizontal ? neighbor.gridIndex % MAP_SIZE < cell % MAP_SIZE
|
||||
: neighbor.gridIndex / MAP_SIZE < cell / MAP_SIZE)
|
||||
entry += 4;
|
||||
return entry;
|
||||
}
|
||||
|
||||
// Whether a neighbouring room may get a door back toward a red room: its layout has the slot, it is not the last boss
|
||||
// room, nor the start room's bottom side on the Chest or Dark Room or with a photo door. Red Redemption allows all.
|
||||
static bool is_entry_allowed(Level& level, const RoomDescriptor& neighbor, int entry, int slot)
|
||||
{
|
||||
if (g_game->challenge == CHALLENGE_RED_REDEMPTION) return true;
|
||||
|
||||
bool isStartDown = slot == DOOR_DOWN0 && neighbor.gridIndex == level.startingRoomIdx;
|
||||
return (neighbor.data->doors & 1u << entry) && neighbor.listIndex != level.lastBossRoomListIdx &&
|
||||
(level.stage != STAGE_DARK_ROOM || !isStartDown) && (!level.HasPhotoDoor() || !isStartDown);
|
||||
}
|
||||
|
||||
// Room::open_red_room_doors 00827550: puts the room's new red doors in, leading to the red room (or the next floor),
|
||||
// unlocked, removes the slot's red outline and plays the unlock sound.
|
||||
static void red_doors_open(Room& room, int doorSlot, RoomDescriptor* target)
|
||||
{
|
||||
for (int slot = 0; slot < DOOR_SLOT_COUNT; slot++)
|
||||
{
|
||||
if (!(room.descriptor->allowedDoors & 1u << slot) || room.doors[slot]) continue;
|
||||
room.MakeDoor(slot);
|
||||
GridEntity_Door* door = room.doors[slot];
|
||||
if (!door) continue;
|
||||
|
||||
door->targetRoomIdx = target ? target->safeGridIndex : NEXT_STAGE_ROOM;
|
||||
door->SetRoomTypes(room.descriptor->data->type, target ? target->data->type : ROOM_DEFAULT);
|
||||
door->slot = slot;
|
||||
if (door->variant == DOOR_LOCKED || door->variant == DOOR_LOCKED_DOUBLE || door->variant == DOOR_LOCKED_CRACKED)
|
||||
{
|
||||
door->variant = DOOR_UNLOCKED;
|
||||
door->extraSprite.Reset();
|
||||
door->LoadSprite();
|
||||
}
|
||||
if (door->variant == DOOR_HIDDEN) door->variant = DOOR_UNLOCKED;
|
||||
door->UpdateAnimation();
|
||||
}
|
||||
|
||||
EntityPtr& outline = room.redDoorOutlines[doorSlot];
|
||||
if (outline)
|
||||
{
|
||||
outline->Remove();
|
||||
outline = nullptr;
|
||||
}
|
||||
npc_sound_play(SOUND_UNLOCK, 1, 2, 1);
|
||||
}
|
||||
|
||||
// 0074c9e0 The doors a red room at a cell would share with the room through a slot: its own slot and the neighbour's
|
||||
// entry slot (-1 each when there is no room there, or the entry is not allowed). False when the neighbour refuses.
|
||||
bool Level::get_red_room_neighbor_slots(int roomIdx, int doorSlot, int* outSlot, int* outEntrySlot)
|
||||
{
|
||||
int cell = GetNeighborRoomIdx(roomIdx, doorSlot);
|
||||
RoomDescriptor* neighbor = cell >= 0 && cell < MAP_SIZE * MAP_SIZE ? GetRoomByIdx(cell) : nullptr;
|
||||
if (!neighbor || !neighbor->data)
|
||||
{
|
||||
*outSlot = -1;
|
||||
*outEntrySlot = -1;
|
||||
return true;
|
||||
}
|
||||
|
||||
int entry = entry_slot_get(doorSlot, *neighbor, cell);
|
||||
*outSlot = doorSlot;
|
||||
bool isAllowed = is_entry_allowed(*this, *neighbor, entry, doorSlot);
|
||||
*outEntrySlot = isAllowed ? entry : -1;
|
||||
return isAllowed;
|
||||
}
|
||||
|
||||
// 0074cb50 The layout room a red room door would make: the empty cell beyond the slot when every room around it
|
||||
// accepts a door, the next floor (an invalid cell) off the map's edge, or none.
|
||||
LevelGenerator_Room Level::get_door_neighbor_room(int roomIdx, int doorSlot)
|
||||
{
|
||||
LevelGenerator_Room none;
|
||||
none.shape = ROOMSHAPE_NULL;
|
||||
int cell = GetNeighborRoomIdx(roomIdx, doorSlot);
|
||||
if (cell == NEXT_STAGE_ROOM)
|
||||
{
|
||||
bool isNextStage = g_game->challenge != CHALLENGE_RED_REDEMPTION && IsNextStageAvailable();
|
||||
none.shape = isNextStage ? ROOMSHAPE_1x1 : ROOMSHAPE_NULL;
|
||||
return none;
|
||||
}
|
||||
if (GetRoomByIdx(cell)->data) return none;
|
||||
|
||||
for (int slot = 0; slot < 4; slot++)
|
||||
{
|
||||
int around = GetNeighborRoomIdx(cell, slot);
|
||||
if (around < 0 || around >= MAP_SIZE * MAP_SIZE) continue;
|
||||
RoomDescriptor* other = GetRoomByIdx(around);
|
||||
if (other->data && !is_entry_allowed(*this, *other, entry_slot_get(slot, *other, around), slot)) return none;
|
||||
}
|
||||
|
||||
LevelGenerator_Room room;
|
||||
room.position = {cell % MAP_SIZE, cell / MAP_SIZE};
|
||||
room.shape = ROOMSHAPE_1x1;
|
||||
return room;
|
||||
}
|
||||
|
||||
// 0074cd70 Whether a Red Key outline shows on a door slot: the room's layout has the door, none stands there, it is
|
||||
// not the last boss room, and a red room could go there (at Home only the one cell), or a red room leads on to the
|
||||
// next floor.
|
||||
bool Level::CanSpawnDoorOutline(int roomIdx, int doorSlot)
|
||||
{
|
||||
RoomDescriptor* room = GetRoomByIdx(roomIdx);
|
||||
bool isLastBoss = room->data->type == ROOM_BOSS && room->listIndex == g_game->lastBossRoomListIdx;
|
||||
bool isDoorFree = doorSlot > LAST_DOOR_SLOT || !g_game->room->doors[doorSlot];
|
||||
if (isLastBoss || room->gridIndex < 0 || !(room->data->doors & 1u << doorSlot) || !isDoorFree) return false;
|
||||
|
||||
LevelGenerator_Room neighbor = get_door_neighbor_room(roomIdx, doorSlot);
|
||||
if (stage == STAGE_HOME && !(neighbor.position == HOME_RED_ROOM_CELL)) return false;
|
||||
return neighbor.shape > ROOMSHAPE_NULL &&
|
||||
(neighbor.position.x >= 0 || (room->flags & ROOM_DESCRIPTOR_FLAG_RED_ROOM));
|
||||
}
|
||||
|
||||
// 0074cea0 A red room's type from the Red Key's rng: mostly a normal room, else a special room by weight. A
|
||||
// planetarium is a treasure room until planetariums are unlocked (outside a daily or debug run), and an angel room a
|
||||
// devil room once a deal was taken.
|
||||
int Level::roll_red_room_type(RNG& rng)
|
||||
{
|
||||
int roll = (int)(rng.Next() & RED_ROOM_ROLL_MASK);
|
||||
int type = ROOM_DEFAULT;
|
||||
for (auto [weight, roomType] : RED_ROOM_TYPES)
|
||||
{
|
||||
if (roll < weight)
|
||||
{
|
||||
type = roomType;
|
||||
break;
|
||||
}
|
||||
roll -= weight;
|
||||
}
|
||||
|
||||
bool isPlanetariumLocked =
|
||||
!g_manager->persistentGameData.achievements[ACHIEVEMENT_PLANETARIUMS] &&
|
||||
(g_manager->state != MANAGER_STATE_GAME || (g_game->dailyChallenge._id == 0 && !g_game->isDebug));
|
||||
if (type == ROOM_PLANETARIUM && isPlanetariumLocked) return ROOM_TREASURE;
|
||||
if (type == ROOM_ANGEL && g_game->devilRoomDeals > 0) return ROOM_DEVIL;
|
||||
return type;
|
||||
}
|
||||
|
||||
// 0074d010 Opens a red room through a door slot (the Red Key, Cracked Key, Soul of Cain): picks a room for the empty
|
||||
// cell beyond from the cell's seed, places it with doors to every room around that takes one, or opens the way to the
|
||||
// next floor off the map's edge, and puts the new doors in if the slot's room is the current one.
|
||||
bool Level::MakeRedRoomDoor(int roomIdx, int doorSlot)
|
||||
{
|
||||
roomIdx = std::clamp(roomIdx, ROOM_IDX_MIN, ROOM_IDX_MAX);
|
||||
int slot = doorSlot < 0 ? LAST_DOOR_SLOT : std::min(doorSlot, LAST_DOOR_SLOT);
|
||||
RoomDescriptor* source = GetRoomByIdx(roomIdx);
|
||||
LevelGenerator_Room neighbor = get_door_neighbor_room(roomIdx, slot);
|
||||
if (neighbor.shape == ROOMSHAPE_NULL) return false;
|
||||
|
||||
RoomDescriptor* target = nullptr;
|
||||
if (neighbor.position.x < 0)
|
||||
{
|
||||
if (!IsNextStageAvailable()) return false;
|
||||
source->allowedDoors |= 1u << slot;
|
||||
source->doors[slot] = NEXT_STAGE_ROOM;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t seed = (dungeonPlacementSeed + neighbor.position.y * RED_ROOM_ROW_SEED) * (neighbor.position.x + 1);
|
||||
RNG rng = {seed, RED_ROOM_SHIFTS[0], RED_ROOM_SHIFTS[1], RED_ROOM_SHIFTS[2]};
|
||||
RoomConfig& config = g_game->roomConfig;
|
||||
RoomConfig_Room* data = nullptr;
|
||||
if (stage == STAGE_HOME)
|
||||
{
|
||||
RoomQuery query = {.shape = ROOMSHAPE_ANY,
|
||||
.maxDifficulty = HOME_DIFFICULTY_MAX,
|
||||
.minDifficulty = 1,
|
||||
.stageId = HOME_STAGE_ID,
|
||||
.subtype = HOME_ROOM_SUBTYPE};
|
||||
data = config.GetRandomRoom(rng.Next(), WEIGHT_KEEP, query);
|
||||
}
|
||||
else
|
||||
{
|
||||
int type = roll_red_room_type(rng);
|
||||
int stageId = g_game->GetStageID();
|
||||
if (g_game->challenge == CHALLENGE_RED_REDEMPTION)
|
||||
stageId = RoomConfig::GetStageID((int)stage, GetRoomStageType(neighbor.position.ToGridIdx()),
|
||||
ROOM_MODE_CURRENT);
|
||||
|
||||
RoomQuery query = {.requiredDoors = RED_ROOM_DOORS,
|
||||
.shape = ROOMSHAPE_1x1,
|
||||
.maxDifficulty = RED_ROOM_DIFFICULTY_MAX,
|
||||
.minDifficulty = 1,
|
||||
.stageId = stageId,
|
||||
.type = type};
|
||||
if (type == ROOM_ANGEL || type == ROOM_DEVIL)
|
||||
{
|
||||
query.maxVariant = RED_ROOM_SPECIAL_VARIANTS;
|
||||
query.subtype =
|
||||
type == ROOM_DEVIL && g_game->playerManager.AnyoneHasTrinket(TRINKET_NUMBER_MAGNET) ? 1 : 0;
|
||||
}
|
||||
else if (type == ROOM_CHALLENGE) query.subtype = 0;
|
||||
else if (type == ROOM_MINIBOSS)
|
||||
query.minDifficulty = query.maxDifficulty =
|
||||
(int)stage > RED_ROOM_LATE_STAGE ? RED_ROOM_LATE_MINIBOSS : 1;
|
||||
|
||||
data = config.GetRandomRoom(rng.Next(), WEIGHT_KEEP, query);
|
||||
if (!data && type != ROOM_DEFAULT)
|
||||
{
|
||||
query.stageId = 0;
|
||||
data = config.GetRandomRoom(rng.Next(), WEIGHT_KEEP, query);
|
||||
if (!data)
|
||||
{
|
||||
query = {.requiredDoors = RED_ROOM_DOORS,
|
||||
.shape = ROOMSHAPE_1x1,
|
||||
.maxDifficulty = RED_ROOM_DIFFICULTY_MAX,
|
||||
.minDifficulty = 1,
|
||||
.stageId = stageId,
|
||||
.subtype = query.subtype};
|
||||
data = config.GetRandomRoom(rng.Next(), WEIGHT_KEEP, query);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!data)
|
||||
{
|
||||
log_printf(LOG_INFO, "failed to generate room with red key!\n");
|
||||
return false;
|
||||
}
|
||||
if (!place_room(neighbor, data, rng._seed, nullptr))
|
||||
{
|
||||
log_printf(LOG_INFO, "failed to place room at (%d, %d)\n", neighbor.position.x, neighbor.position.y);
|
||||
return false;
|
||||
}
|
||||
|
||||
target = &roomList[nbRooms - 1];
|
||||
target->flags |= ROOM_DESCRIPTOR_FLAG_RED_ROOM;
|
||||
for (int side = 0; side < 4; side++)
|
||||
{
|
||||
int cell = GetNeighborRoomIdx(target->gridIndex, side);
|
||||
int ownSlot = -1;
|
||||
int entry = -1;
|
||||
get_red_room_neighbor_slots(target->gridIndex, side, &ownSlot, &entry);
|
||||
if (ownSlot >= 0)
|
||||
{
|
||||
target->allowedDoors = (target->allowedDoors | 1u << ownSlot) & target->data->doors;
|
||||
target->doors[ownSlot] = cell;
|
||||
}
|
||||
RoomDescriptor* other = entry >= 0 ? GetRoomByIdx(cell) : nullptr;
|
||||
if (!other || !other->data) continue;
|
||||
other->allowedDoors = (other->allowedDoors | 1u << entry) & other->data->doors;
|
||||
other->doors[entry] = target->gridIndex;
|
||||
}
|
||||
}
|
||||
|
||||
if (source == g_game->room->descriptor) red_doors_open(*g_game->room, slot, target);
|
||||
UpdateVisibility();
|
||||
return true;
|
||||
}
|
||||
+2
-2
@@ -95,6 +95,7 @@ void lua_object_push(lua_State* state, void* object, LuaClass luaClass)
|
||||
void* lua_object_check(lua_State* state, int index, LuaClass luaClass)
|
||||
{
|
||||
void** block = lua_type(state, index) == LUA_TUSERDATA ? (void**)lua_touserdata(state, index) : nullptr;
|
||||
const char* actual = luaL_typename(state, index);
|
||||
lua_rawgetp(state, LUA_REGISTRYINDEX, lua_class_key(luaClass));
|
||||
if (!block || !lua_getmetatable(state, index)) lua_pushnil(state);
|
||||
while (!lua_isnil(state, -1))
|
||||
@@ -109,8 +110,7 @@ void* lua_object_check(lua_State* state, int index, LuaClass luaClass)
|
||||
}
|
||||
|
||||
field_raw_get(state, -2, "__name");
|
||||
const char* expected = lua_pushfstring(state, "%s expected, got %s", lua_tostring(state, -1),
|
||||
luaL_typename(state, index));
|
||||
const char* expected = lua_pushfstring(state, "%s expected, got %s", lua_tostring(state, -1), actual);
|
||||
luaL_argerror(state, index, expected);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
+42
-8
@@ -21,8 +21,10 @@ extern "C"
|
||||
}
|
||||
#undef luaL_newstate
|
||||
|
||||
struct ActiveItemDesc;
|
||||
struct ColorMod;
|
||||
struct EntityPtr;
|
||||
struct EntityList_EL;
|
||||
struct EntityRef;
|
||||
struct Entity_Bomb;
|
||||
struct Entity_Effect;
|
||||
@@ -53,6 +55,7 @@ struct ItemConfig_Pill;
|
||||
struct KColor;
|
||||
struct ANM2;
|
||||
struct PathFinder;
|
||||
struct PosVel;
|
||||
struct ProjectileParams;
|
||||
struct QueueItemData;
|
||||
struct RoomConfig_Room;
|
||||
@@ -83,6 +86,11 @@ struct LuaIgnored
|
||||
{
|
||||
};
|
||||
|
||||
// A value the original pushes as a class it never registers: a userdata without a metatable, which scripts can only
|
||||
// hold or pass on.
|
||||
struct LuaOpaque
|
||||
{};
|
||||
|
||||
// An argument a script may leave out, which reads as Default when it is nil or missing.
|
||||
template <typename T, auto Default> struct LuaDefault
|
||||
{
|
||||
@@ -104,8 +112,8 @@ struct LuaRoomList
|
||||
// The Lua class each C++ type is pushed and checked as. TearFlags are Lua's BitSet128 and ColorMod is Lua's Color.
|
||||
template <typename T>
|
||||
constexpr LuaClass LUA_CLASS_OF = LUA_CLASS_COUNT;
|
||||
template <>
|
||||
inline constexpr LuaClass LUA_CLASS_OF<std::bitset<128>> = LUA_CLASS_BIT_SET128;
|
||||
template <> inline constexpr LuaClass LUA_CLASS_OF<ActiveItemDesc> = LUA_CLASS_ACTIVE_ITEM_DESC;
|
||||
template <> inline constexpr LuaClass LUA_CLASS_OF<std::bitset<128>> = LUA_CLASS_BIT_SET128;
|
||||
template <>
|
||||
inline constexpr LuaClass LUA_CLASS_OF<ColorMod> = LUA_CLASS_COLOR;
|
||||
template <>
|
||||
@@ -130,8 +138,8 @@ template <>
|
||||
inline constexpr LuaClass LUA_CLASS_OF<Entity_Projectile> = LUA_CLASS_PROJECTILE;
|
||||
template <>
|
||||
inline constexpr LuaClass LUA_CLASS_OF<Entity_Tear> = LUA_CLASS_TEAR;
|
||||
template <>
|
||||
inline constexpr LuaClass LUA_CLASS_OF<EntityPtr> = LUA_CLASS_ENTITY_PTR;
|
||||
template <> inline constexpr LuaClass LUA_CLASS_OF<EntityList_EL> = LUA_CLASS_ENTITY_LIST;
|
||||
template <> inline constexpr LuaClass LUA_CLASS_OF<EntityPtr> = LUA_CLASS_ENTITY_PTR;
|
||||
template <>
|
||||
inline constexpr LuaClass LUA_CLASS_OF<EntityRef> = LUA_CLASS_ENTITY_REF;
|
||||
template <>
|
||||
@@ -208,8 +216,8 @@ template <>
|
||||
inline constexpr LuaClass LUA_CLASS_OF<LuaRoomList> = LUA_CLASS_ROOM_LIST;
|
||||
template <>
|
||||
inline constexpr LuaClass LUA_CLASS_OF<PathFinder> = LUA_CLASS_PATH_FINDER;
|
||||
template <>
|
||||
inline constexpr LuaClass LUA_CLASS_OF<Seeds> = LUA_CLASS_SEEDS;
|
||||
template <> inline constexpr LuaClass LUA_CLASS_OF<PosVel> = LUA_CLASS_POS_VEL;
|
||||
template <> inline constexpr LuaClass LUA_CLASS_OF<Seeds> = LUA_CLASS_SEEDS;
|
||||
template <>
|
||||
inline constexpr LuaClass LUA_CLASS_OF<SFXManager> = LUA_CLASS_SFX_MANAGER;
|
||||
template <>
|
||||
@@ -218,10 +226,11 @@ template <>
|
||||
inline constexpr LuaClass LUA_CLASS_OF<TearParams> = LUA_CLASS_TEAR_PARAMS;
|
||||
template <>
|
||||
inline constexpr LuaClass LUA_CLASS_OF<TemporaryEffect> = LUA_CLASS_TEMPORARY_EFFECT;
|
||||
template <>
|
||||
inline constexpr LuaClass LUA_CLASS_OF<TemporaryEffects> = LUA_CLASS_TEMPORARY_EFFECTS;
|
||||
template <> inline constexpr LuaClass LUA_CLASS_OF<std::vector<TemporaryEffect>> = LUA_CLASS_EFFECT_LIST;
|
||||
template <> inline constexpr LuaClass LUA_CLASS_OF<TemporaryEffects> = LUA_CLASS_TEMPORARY_EFFECTS;
|
||||
template <>
|
||||
inline constexpr LuaClass LUA_CLASS_OF<Vector> = LUA_CLASS_VECTOR;
|
||||
template <> inline constexpr LuaClass LUA_CLASS_OF<std::vector<Vector>> = LUA_CLASS_VECTOR_LIST;
|
||||
|
||||
// The class and member type of a pointer to a data member, for decltype only.
|
||||
template <typename C, typename T>
|
||||
@@ -246,6 +255,7 @@ void lua_property_set(lua_State* state, const char* table, const char* name);
|
||||
|
||||
void lua_api_bit_set128_register(lua_State* state);
|
||||
void lua_api_color_register(lua_State* state);
|
||||
void lua_api_containers_register(lua_State* state);
|
||||
void lua_api_entity_register(lua_State* state);
|
||||
void lua_api_entities_register(lua_State* state);
|
||||
void lua_api_entity_player_register(lua_State* state);
|
||||
@@ -280,6 +290,8 @@ void lua_push(lua_State* state, const T& value)
|
||||
else if constexpr (std::is_floating_point_v<T>) lua_pushnumber(state, value);
|
||||
else if constexpr (IS_LUA_STRING<T>) lua_pushlstring(state, value.data(), value.size());
|
||||
else if constexpr (std::is_same_v<T, const char*>) lua_pushstring(state, value);
|
||||
else if constexpr (std::is_same_v<T, LuaOpaque>)
|
||||
lua_newuserdata(state, sizeof(void*));
|
||||
else if constexpr (std::is_pointer_v<T>)
|
||||
{
|
||||
static_assert(IS_LUA_CLASS<std::remove_cv_t<std::remove_pointer_t<T>>>);
|
||||
@@ -416,3 +428,25 @@ void lua_gc_set(lua_State* state)
|
||||
});
|
||||
lua_table_set(state, -2, "__gc");
|
||||
}
|
||||
|
||||
// The object a list element is pushed as: what a unique_ptr holds, else the element itself.
|
||||
template <typename T> auto* lua_list_element(T& element)
|
||||
{
|
||||
if constexpr (requires { element.get(); })
|
||||
return element.get();
|
||||
else
|
||||
return &element;
|
||||
}
|
||||
|
||||
// Registers a list a binding hands out (the original's CppContainer classes): its Size and length, and Get, nil past
|
||||
// the end where the original throws.
|
||||
template <typename List> void lua_list_register(lua_State* state, const char* name)
|
||||
{
|
||||
lua_class_begin(state, name, LUA_CLASS_OF<List>);
|
||||
lua_property(state, "Size", [](List& list) { return (int)list.size(); });
|
||||
lua_method(state, "__len", [](List& list) { return (int)list.size(); });
|
||||
lua_method(state, "Get", [](List& list, uint32_t index) {
|
||||
return index < list.size() ? lua_list_element(list[index]) : nullptr;
|
||||
});
|
||||
lua_class_end(state, LUA_SCOPE_NAMESPACE);
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
#include "classes.h"
|
||||
#include "entity_list.h"
|
||||
#include "entity_player.h"
|
||||
#include "lua_api.h"
|
||||
#include "temporary_effects.h"
|
||||
#include "weapon.h"
|
||||
#include <algorithm>
|
||||
|
||||
// (004176f0, 0085e0c0) Registers the CppContainer namespace: EntityList, the entities Room:GetEntities hands out,
|
||||
// whose Get clamps the index to the last entity (the NPC queries hand out copies), and the EffectList and VectorList
|
||||
// other bindings return.
|
||||
// The original reads before an empty EntityList. Here Get gives nil for one.
|
||||
static void containers_register(lua_State* state)
|
||||
{
|
||||
lua_namespace_begin(state, "CppContainer");
|
||||
lua_class_begin(state, "EntityList", LUA_CLASS_ENTITY_LIST);
|
||||
lua_gc_set<EntityList_EL>(state);
|
||||
lua_property(state, "Size", [](EntityList_EL& list) { return (int)list.size(); });
|
||||
lua_method(state, "__len", [](EntityList_EL& list) { return (int)list.size(); });
|
||||
lua_method(state, "Get", [](EntityList_EL& list, uint32_t index) {
|
||||
return list.empty() ? nullptr : list[std::min<size_t>(index, list.size() - 1)];
|
||||
});
|
||||
lua_class_end(state, LUA_SCOPE_NAMESPACE);
|
||||
|
||||
lua_list_register<std::vector<TemporaryEffect>>(state, "EffectList");
|
||||
lua_list_register<std::vector<Vector>>(state, "VectorList");
|
||||
lua_class_end(state);
|
||||
}
|
||||
|
||||
// Registers the PlayerTypes namespace: PosVel, a shot's start and speed, and ActiveItemDesc, an active item slot.
|
||||
static void player_types_register(lua_State* state)
|
||||
{
|
||||
lua_namespace_begin(state, "PlayerTypes");
|
||||
lua_class_begin(state, "PosVel", LUA_CLASS_POS_VEL);
|
||||
lua_field<&PosVel::position>(state, "Position");
|
||||
lua_field<&PosVel::velocity>(state, "Velocity");
|
||||
lua_class_end(state, LUA_SCOPE_NAMESPACE);
|
||||
|
||||
lua_class_begin(state, "ActiveItemDesc", LUA_CLASS_ACTIVE_ITEM_DESC);
|
||||
lua_field<&ActiveItemDesc::item>(state, "Item");
|
||||
lua_field<&ActiveItemDesc::charge>(state, "Charge");
|
||||
lua_field<&ActiveItemDesc::batteryCharge>(state, "BatteryCharge");
|
||||
lua_field<&ActiveItemDesc::subCharge>(state, "SubCharge");
|
||||
lua_field<&ActiveItemDesc::timeRechargeCooldown>(state, "TimedRechargeCooldown");
|
||||
lua_field<&ActiveItemDesc::partialCharge>(state, "PartialCharge");
|
||||
lua_field<&ActiveItemDesc::varData>(state, "VarData");
|
||||
lua_class_end(state, LUA_SCOPE_NAMESPACE);
|
||||
lua_class_end(state);
|
||||
}
|
||||
|
||||
void lua_api_containers_register(lua_State* state)
|
||||
{
|
||||
containers_register(state);
|
||||
player_types_register(state);
|
||||
}
|
||||
@@ -9,14 +9,43 @@
|
||||
#include "entity_player.h"
|
||||
#include "entity_projectile.h"
|
||||
#include "entity_tear.h"
|
||||
#include "boss_ai.h"
|
||||
#include "entity_list.h"
|
||||
#include "lua_api.h"
|
||||
#include "weapon.h"
|
||||
#include "path_finder.h"
|
||||
#include "weapon.h"
|
||||
#include <algorithm>
|
||||
|
||||
// The entities of a query as the EntityList Lua copies out.
|
||||
template <typename T> static EntityList_EL entity_list_make(const std::vector<T*>& entities)
|
||||
{
|
||||
EntityList_EL list;
|
||||
list.assign(entities.begin(), entities.end());
|
||||
return list;
|
||||
}
|
||||
|
||||
// The orbiters RecalculateOrbitOffset spaces, which the original returns: the familiars sharing the layer and the
|
||||
// orbit's centre, and this one when it joins.
|
||||
static int familiar_orbit_count(Entity_Familiar& familiar, int layer, bool isJoining)
|
||||
{
|
||||
if (familiar.isSubtype55555 || layer < 0) return 0;
|
||||
|
||||
Entity* centre = familiar.get_orbit_parent();
|
||||
auto isOrbiter = [&](Entity_Familiar* other) {
|
||||
return other->isExists && other != &familiar && other->orbitLayer == layer &&
|
||||
other->get_orbit_parent() == centre;
|
||||
};
|
||||
return (int)std::ranges::count_if(familiar_query(-1), isOrbiter) + isJoining;
|
||||
}
|
||||
|
||||
// Registers Lua's EntityTear and EntityProjectile, the shots of players and enemies.
|
||||
static void shots_register(lua_State* state)
|
||||
{
|
||||
lua_class_begin(state, "EntityTear", LUA_CLASS_TEAR, LUA_CLASS_ENTITY);
|
||||
lua_field<&Entity_Tear::stickTarget>(state, "StickTarget");
|
||||
lua_method(state, "SetDeadEyeIntensity",
|
||||
[](Entity_Tear& tear, float intensity) { tear.SetDeadEyeIntensity(intensity); });
|
||||
lua_method(state, "ResetSpriteScale", [](Entity_Tear& tear) { tear.ResetSpriteScale(); });
|
||||
lua_field<&Entity_Tear::height>(state, "Height");
|
||||
lua_field<&Entity_Tear::fallingSpeed>(state, "FallingSpeed");
|
||||
lua_field<&Entity_Tear::fallingAccel>(state, "FallingAcceleration");
|
||||
@@ -94,6 +123,7 @@ static void weapons_register(lua_State* state)
|
||||
lua_method(state, "GetKnifeDistance", [](Entity_Knife& knife) { return knife.knifeDistance; });
|
||||
lua_method(state, "GetKnifeVelocity", [](Entity_Knife& knife) { return knife.knifeVelocity; });
|
||||
lua_method(state, "SetPathFollowSpeed", [](Entity_Knife& knife, float speed) { knife.pathFollowSpeed = speed; });
|
||||
lua_method(state, "GetRenderZ", [](Entity_Knife& knife) { return knife.GetRenderZ(); });
|
||||
weapon_lua_knife_register(state);
|
||||
lua_class_end(state);
|
||||
|
||||
@@ -129,6 +159,17 @@ static void weapons_register(lua_State* state)
|
||||
[](Entity_Laser& laser, float chance) { laser.blackHpDropChance = chance; });
|
||||
lua_method(state, "IsCircleLaser", [](Entity_Laser& laser) { return laser.IsCircleLaser(); });
|
||||
lua_method(state, "IsSampleLaser", [](Entity_Laser& laser) { return laser.isSampleLaser; });
|
||||
lua_field<&Entity_Laser::rotationDelay>(state, "RotationDelay");
|
||||
lua_field<&Entity_Laser::bounceLaser>(state, "BounceLaser");
|
||||
lua_property(state, "HomingLaser", [](Entity_Laser&) { return LuaOpaque{}; });
|
||||
lua_method(state, "GetRenderZ", [](Entity_Laser& laser) { return laser.GetRenderZ(); });
|
||||
lua_method(state, "GetEndPoint", [](Entity_Laser& laser) -> Vector& { return laser.endPoint; });
|
||||
lua_method(state, "GetSamples",
|
||||
[](Entity_Laser& laser) -> std::vector<Vector>& { return laser.homingLaser.samples; });
|
||||
lua_method(state, "GetNonOptimizedSamples",
|
||||
[](Entity_Laser& laser) -> std::vector<Vector>& { return laser.homingLaser.nonOptimizedSamples; });
|
||||
lua_method(state, "SetMultidimensionalTouched",
|
||||
[](Entity_Laser& laser, bool isTouched) { laser.isMultidimensionalTouched = isTouched; });
|
||||
weapon_lua_laser_register(state);
|
||||
lua_class_end(state);
|
||||
}
|
||||
@@ -137,6 +178,23 @@ static void weapons_register(lua_State* state)
|
||||
static void companions_register(lua_State* state)
|
||||
{
|
||||
lua_class_begin(state, "EntityFamiliar", LUA_CLASS_FAMILIAR, LUA_CLASS_ENTITY);
|
||||
lua_method(state, "PickEnemyTarget",
|
||||
[](Entity_Familiar& familiar, float range, int frameInterval, uint32_t flags, Vector coneDirection,
|
||||
float coneAngle) {
|
||||
familiar.PickEnemyTarget({.coneDirection = coneDirection,
|
||||
.coneAngle = coneAngle,
|
||||
.range = range,
|
||||
.frameInterval = frameInterval,
|
||||
.flags = flags});
|
||||
});
|
||||
lua_method(state, "FireProjectile", [](Entity_Familiar& familiar, Vector direction, bool isExact) {
|
||||
return familiar.FireProjectile(direction, isExact ? FIRE_EXACT : FIRE_INHERIT_MOTION);
|
||||
});
|
||||
lua_method(state, "MoveDelayed", [](Entity_Familiar& familiar, int frames) { familiar.MoveDelayed(frames); });
|
||||
lua_method(state, "RecalculateOrbitOffset", [](Entity_Familiar& familiar, int layer, bool isJoining) {
|
||||
familiar.RecalculateOrbitOffset(layer, isJoining ? ORBIT_JOIN : ORBIT_LEAVE);
|
||||
return familiar_orbit_count(familiar, layer, isJoining);
|
||||
});
|
||||
lua_field<&Entity_Familiar::player>(state, "Player");
|
||||
lua_field<&Entity_Familiar::state>(state, "State");
|
||||
lua_field<&Entity_Familiar::coins>(state, "Coins");
|
||||
@@ -180,6 +238,7 @@ static void companions_register(lua_State* state)
|
||||
lua_class_end(state);
|
||||
|
||||
lua_class_begin(state, "EntityEffect", LUA_CLASS_EFFECT, LUA_CLASS_ENTITY);
|
||||
lua_static(state, "IsPlayerCreep", [](int variant) { return Entity_Effect::IsPlayerCreep(variant); });
|
||||
lua_field<&Entity_Effect::state>(state, "State");
|
||||
lua_field<&Entity_Effect::timeout>(state, "Timeout");
|
||||
lua_field<&Entity_Effect::lifespan>(state, "LifeSpan");
|
||||
@@ -206,6 +265,17 @@ static void companions_register(lua_State* state)
|
||||
static void npc_pickup_register(lua_State* state)
|
||||
{
|
||||
lua_class_begin(state, "EntityNPC", LUA_CLASS_NPC, LUA_CLASS_ENTITY);
|
||||
lua_method(state, "CanBeDamagedFromVelocity",
|
||||
[](Entity_NPC& npc, Vector velocity) { return npc.CanBeDamagedFromVelocity(velocity); });
|
||||
lua_method(state, "CanReroll", [](Entity_NPC& npc) { return npc.CanReroll(); });
|
||||
lua_method(state, "QueryNPCsType",
|
||||
[](Entity_NPC&, int type, int variant) { return entity_list_make(entity_query(type, variant)); });
|
||||
lua_method(state, "QueryNPCsSpawnerType", [](Entity_NPC&, int spawnerType, int type, bool isEnemiesOnly) {
|
||||
SpawnerQueryMode mode = isEnemiesOnly ? SPAWNER_QUERY_ENEMIES : SPAWNER_QUERY_ALL;
|
||||
return entity_list_make(npc_query_spawner_type(spawnerType, type, mode));
|
||||
});
|
||||
lua_method(state, "QueryNPCsGroup",
|
||||
[](Entity_NPC&, int group) { return entity_list_make(Entity_NPC::QueryNPCsGroup(group)); });
|
||||
lua_field<&Entity_NPC::state>(state, "State");
|
||||
lua_field<&Entity_NPC::stateFrame>(state, "StateFrame");
|
||||
lua_field<&Entity_NPC::i1>(state, "I1");
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
#include "classes.h"
|
||||
#include "active_items.h"
|
||||
#include "entity_effect.h"
|
||||
#include "entity_familiar.h"
|
||||
#include "entity_pickup.h"
|
||||
#include "entity_player.h"
|
||||
#include "entity_tear.h"
|
||||
#include "item_config.h"
|
||||
#include "log.h"
|
||||
#include "lua_api.h"
|
||||
#include "temporary_effects.h"
|
||||
#include "weapon.h"
|
||||
|
||||
// The QueueItemData flag Touched reads: the item was held before, so picking it up again gives no pickup effect.
|
||||
constexpr uint32_t QUEUE_ITEM_TOUCHED = 0x1;
|
||||
// The most charges Dead Eye stacks.
|
||||
constexpr uint32_t DEAD_EYE_CHARGES_MAX = 8;
|
||||
|
||||
// The weapon a player's fire delay belongs to: the override in slot 0, else the first.
|
||||
static Weapon* player_weapon_main(Entity_Player& player)
|
||||
@@ -370,7 +374,106 @@ static void player_stats_register(lua_State* state)
|
||||
lua_method(state, "SpriteScale", [](Entity_Player& player) { return player.SpriteScale(); });
|
||||
}
|
||||
|
||||
// Registers Lua's EntityPlayer, TemporaryEffects and TearParams.
|
||||
// (007e92a0, 004361a0, 004361b0, 0085e240, 005cd7d0, 0085e2c0, 00753c30, 0065cf60, 00782a60) Registers the player's
|
||||
// drawing and the state the rest of EntityPlayer reads: the body's turn, the melee damage, the held item state, the
|
||||
// range bonus, the tractor beam, the last action buttons and Curse Mist. The original pushes the pocket items, the
|
||||
// Friend Ball enemy and the multi shot parameters as unregistered classes.
|
||||
static void player_state_register(lua_State* state)
|
||||
{
|
||||
lua_method(state, "RenderGlow", [](Entity_Player& player, Vector position) { player.RenderGlow(position); });
|
||||
lua_method(state, "RenderBody", [](Entity_Player& player, Vector position) { player.RenderBody(position); });
|
||||
lua_method(state, "RenderHead", [](Entity_Player& player, Vector position) { player.RenderHead(position); });
|
||||
lua_method(state, "RenderTop", [](Entity_Player& player, Vector position) { player.RenderTop(position); });
|
||||
lua_method(state, "IsFullSpriteRendering", [](Entity_Player& player) { return player.IsFullSpriteRendering(); });
|
||||
lua_method(state, "IsP2Appearing", [](Entity_Player& player) { return player.IsP2Appearing(); });
|
||||
lua_method(state, "CanTurnHead", [](Entity_Player& player) { return player.CanTurnHead() != 0; });
|
||||
lua_method(state, "GetSmoothBodyRotation", [](Entity_Player& player) { return player.bodyAngle; });
|
||||
lua_method(state, "GetTearPoisonDamage", [](Entity_Player& player) { return player.meleeDamage; });
|
||||
lua_method(state, "GetItemState", [](Entity_Player& player) { return player.itemState; });
|
||||
lua_method(state, "ResetItemState", [](Entity_Player& player) { player.ResetItemState(); });
|
||||
lua_method(state, "GetTearRangeModifier", [](Entity_Player& player) { return player.tearRangeModifier; });
|
||||
lua_method(state, "GetTractorBeam", [](Entity_Player& player) -> Entity* {
|
||||
if (player.tractorBeam)
|
||||
reconstruction_missing("Entity_Player::GetTractorBeam 00665c10 (the beam is an int here)");
|
||||
return nullptr;
|
||||
});
|
||||
lua_method(state, "GetLastActionTriggers", [](Entity_Player& player) { return player.lastActionTriggers; });
|
||||
lua_field<&Entity_Player::blinkTime>(state, "HeadFrameDelay");
|
||||
lua_method(state, "GetNPCTarget", [](Entity_Player&) -> Entity* {
|
||||
reconstruction_missing("Entity_Player::GetNPCTarget 00770610");
|
||||
return nullptr;
|
||||
});
|
||||
lua_method(state, "HasCurseMistEffect", [](Entity_Player& player) { return player.hasCurseMistEffect; });
|
||||
lua_method(state, "AddCurseMistEffect", [](Entity_Player& player) { player.AddCurseMistEffect(); });
|
||||
lua_method(state, "RemoveCurseMistEffect", [](Entity_Player& player) { player.RemoveCurseMistEffect(); });
|
||||
lua_method(state, "GetPocketItem", [](Entity_Player&, int) { return LuaOpaque{}; });
|
||||
lua_method(state, "FriendBallEnemy", [](Entity_Player&) { return LuaOpaque{}; });
|
||||
lua_method(state, "GetMultiShotParams", [](Entity_Player&, int) { return LuaOpaque{}; });
|
||||
lua_method(state, "GetGreedDonationBreakChance",
|
||||
[](Entity_Player& player) { return player.GetGreedDonationBreakChance(); });
|
||||
lua_method(state, "GetLaserOffset", [](Entity_Player& player, int offsetId, Vector direction) {
|
||||
return player.GetLaserOffset(offsetId, direction);
|
||||
});
|
||||
lua_method(state, "GetTearMovementInheritance", [](Entity_Player& player, Vector direction, bool isAlways) {
|
||||
return player.GetTearMovementInheritance(direction, isAlways ? INHERIT_ALWAYS : INHERIT_CHECKED);
|
||||
});
|
||||
lua_method(state, "GetCostumeNullPos",
|
||||
[](Entity_Player& player, std::string_view name, bool isHeadScale, Vector direction) {
|
||||
return player.GetCostumeNullPos(name, isHeadScale, direction);
|
||||
});
|
||||
lua_method(state, "IsPosInSpotLight",
|
||||
[](Entity_Player& player, Vector position) { return player.IsPosInSpotLight(position); });
|
||||
lua_method(state, "GetBombFlags",
|
||||
[](Entity_Player& player, bool isRollChances) { return player.GetBombFlags(isRollChances); });
|
||||
lua_method(state, "GetBombVariant",
|
||||
[](Entity_Player&, TearFlags, bool) { return Entity_Player::GetBombVariant(); });
|
||||
}
|
||||
|
||||
// (0075e160, 0085e200, 007bf660, 0085e260, 007c78b0) Registers the player's actions the rest of EntityPlayer lacks:
|
||||
// queueing an item, the hearts check, blue spiders, controls, skins and costumes, Dead Eye, Maw of the Void, Dollar
|
||||
// Bill, Zit, Red Candle, the poop spells, Brimstone's delayed shot and whether an item can be picked up.
|
||||
static void player_actions_register(lua_State* state)
|
||||
{
|
||||
lua_method(state, "QueueItem",
|
||||
[](Entity_Player& player, ItemConfig_Item& item, int charge, int flags, int varData) {
|
||||
player.SetQueuedItem({.item = &item, .charge = charge, .flags = (uint8_t)flags, .varData = varData});
|
||||
});
|
||||
lua_method(state, "HasFullHeartsAndSoulHearts",
|
||||
[](Entity_Player& player) { return player.maxHearts <= player.soulHearts + player.redHearts; });
|
||||
lua_method(state, "RemoveBlueSpider", [](Entity_Player& player) { player.numBlueSpiders--; });
|
||||
lua_method(state, "AddControlsCooldown",
|
||||
[](Entity_Player& player, int frames) { player.controlsCooldown += frames; });
|
||||
lua_method(state, "AddDeadEyeCharge", [](Entity_Player& player) {
|
||||
if (player.deadEyeCharges < DEAD_EYE_CHARGES_MAX)
|
||||
{
|
||||
player.cacheFlags |= CACHE_DAMAGE;
|
||||
player.deadEyeCharges++;
|
||||
player.EvaluateItems();
|
||||
}
|
||||
player.deadEyeMisses = 0;
|
||||
});
|
||||
lua_method(state, "RemoveSkinCostume", [](Entity_Player& player) { player.RemoveSkinCostume(); });
|
||||
lua_method(state, "InitBabySkin", [](Entity_Player& player) { player.InitBabySkin(); });
|
||||
lua_method(state, "ReplaceCostumeSprite",
|
||||
[](Entity_Player& player, ItemConfig_Item& item, std::string_view path, int) {
|
||||
player.ReplaceCostumeSprite(&item, path);
|
||||
});
|
||||
lua_method(state, "CanPickupItem", [](Entity_Player& player) { return player.CanPickupItem(); });
|
||||
lua_method(state, "SpawnMawOfVoid",
|
||||
[](Entity_Player& player, int timeout) { return player.SpawnMawOfVoid(timeout); });
|
||||
lua_method(state, "AddDollarBillEffect", [](Entity_Player& player) { player.AddDollarBillEffect(); });
|
||||
lua_method(state, "DoZitEffect", [](Entity_Player& player, Vector direction) { player.DoZitEffect(direction); });
|
||||
lua_method(state, "ShootRedCandle", [](Entity_Player& player, Vector direction) {
|
||||
Entity* flame = player.ShootRedCandle(direction);
|
||||
return flame && flame->type == ENTITY_EFFECT ? static_cast<Entity_Effect*>(flame) : nullptr;
|
||||
});
|
||||
lua_method(state, "UsePoopSpell", [](Entity_Player& player, uint32_t spell) { player.UsePoopSpell(spell); });
|
||||
lua_method(state, "FireDelayedBrimstone", [](Entity_Player& player, float angle, Entity* parent) {
|
||||
return player.FireDelayedBrimstone(angle, parent);
|
||||
});
|
||||
}
|
||||
|
||||
// (007537a0) Registers Lua's EntityPlayer, TemporaryEffects and TearParams.
|
||||
void lua_api_entity_player_register(lua_State* state)
|
||||
{
|
||||
lua_class_begin(state, "EntityPlayer", LUA_CLASS_PLAYER, LUA_CLASS_ENTITY);
|
||||
@@ -378,13 +481,19 @@ void lua_api_entity_player_register(lua_State* state)
|
||||
player_items_register(state);
|
||||
player_misc_register(state);
|
||||
player_stats_register(state);
|
||||
player_state_register(state);
|
||||
player_actions_register(state);
|
||||
weapon_lua_player_register(state);
|
||||
lua_class_end(state);
|
||||
|
||||
lua_class_begin(state, "QueueItemData", LUA_CLASS_QUEUE_ITEM_DATA);
|
||||
lua_field<&QueueItemData::item>(state, "Item");
|
||||
lua_field<&QueueItemData::charge>(state, "Charge");
|
||||
lua_property(state, "Touched", [](QueueItemData& queued) { return (queued.flags & QUEUE_ITEM_TOUCHED) != 0; });
|
||||
lua_property(
|
||||
state, "Touched", [](QueueItemData& queued) { return (queued.flags & QUEUE_ITEM_TOUCHED) != 0; },
|
||||
[](QueueItemData& queued, bool isTouched) {
|
||||
queued.flags = isTouched ? queued.flags | QUEUE_ITEM_TOUCHED : queued.flags & ~QUEUE_ITEM_TOUCHED;
|
||||
});
|
||||
lua_class_end(state);
|
||||
|
||||
lua_class_begin(state, "TemporaryEffect", LUA_CLASS_TEMPORARY_EFFECT);
|
||||
@@ -394,6 +503,8 @@ void lua_api_entity_player_register(lua_State* state)
|
||||
lua_class_end(state);
|
||||
|
||||
lua_class_begin(state, "TemporaryEffects", LUA_CLASS_TEMPORARY_EFFECTS);
|
||||
lua_method(state, "GetEffectsList",
|
||||
[](TemporaryEffects& effects) -> std::vector<TemporaryEffect>& { return effects.effects; });
|
||||
lua_method(state, "GetCollectibleEffect",
|
||||
[](TemporaryEffects& effects, int id) { return effects.GetCollectibleEffect(id); });
|
||||
lua_method(state, "GetTrinketEffect",
|
||||
|
||||
@@ -1,21 +1,226 @@
|
||||
#include "classes.h"
|
||||
#include "boss_ai.h"
|
||||
#include "entity_bomb.h"
|
||||
#include "entity_effect_combat.h"
|
||||
#include "entity_npc.h"
|
||||
#include "entity_pickup.h"
|
||||
#include "entity_player.h"
|
||||
#include "game.h"
|
||||
#include "game_end.h"
|
||||
#include "grid_entity_trap_door.h"
|
||||
#include "hud.h"
|
||||
#include "item_pool.h"
|
||||
#include "lua_api.h"
|
||||
#include "manager.h"
|
||||
#include "music_manager.h"
|
||||
#include "npc_basement.h"
|
||||
#include "room.h"
|
||||
#include "room_special.h"
|
||||
#include "room_transition.h"
|
||||
#include "seeds.h"
|
||||
#include "sfx_manager.h"
|
||||
#include "stage_transition.h"
|
||||
#include <algorithm>
|
||||
|
||||
// The reach of a Fart a script leaves out.
|
||||
constexpr float FART_RADIUS = 85;
|
||||
// The last stage the run's stage counters keep.
|
||||
constexpr int STAGE_COUNTER_MAX = 13;
|
||||
// Making this many devil deals in one run unlocks Azazel.
|
||||
constexpr int AZAZEL_DEALS = 3;
|
||||
constexpr int ACHIEVEMENT_AZAZEL = 79;
|
||||
// A Greed run's waves, bosses and the devil's included (one more in Greedier).
|
||||
constexpr int GREED_WAVE_TOTAL = 11;
|
||||
// The argument past the last line HUD:ShowFortuneText reads.
|
||||
constexpr int FORTUNE_ARGUMENT_END = 34;
|
||||
|
||||
// 006fe2f0 Moves the players into a room of the floor at once: each leaves the room, the level changes room, the new
|
||||
// room updates once and the item pool takes the room's pool. A Random() is drawn and dropped on the way.
|
||||
void Game::ChangeRoom(int roomIndex, int dimension)
|
||||
{
|
||||
for (Entity_Player* player : playerManager.playerList) player->room_exit(false);
|
||||
Level::ChangeRoom(roomIndex, dimension);
|
||||
room->Update();
|
||||
|
||||
Random();
|
||||
int pool = itemPool.get_pool_from_room_entities(room->roomType, *room->descriptor, room->bossId);
|
||||
itemPool.lastPool = pool == POOL_NONE ? POOL_TREASURE : pool;
|
||||
}
|
||||
|
||||
// 00703850 A random player within a radius of a position, else the last of the shuffled players.
|
||||
// The original reads before an empty player list. Here there is no player then.
|
||||
static Entity_Player* game_random_player(Game& game, Vector position, float radius)
|
||||
{
|
||||
std::vector<Entity_Player*> players = game.playerManager.playerList;
|
||||
if (players.empty()) return nullptr;
|
||||
|
||||
for (size_t index = players.size() - 1; index > 0; index--)
|
||||
std::swap(players[index], players[Random() % (index + 1)]);
|
||||
for (Entity_Player* player : players)
|
||||
if (vector_length_squared(vector_sub(position, player->pos)) < radius * radius) return player;
|
||||
return players.back();
|
||||
}
|
||||
|
||||
// 00704b70 Rerolls the collectibles the floor's other rooms keep: each saved pedestal of an item that may be rerolled
|
||||
// becomes a fresh, untouched one.
|
||||
static void game_level_collectibles_reroll(Game& game)
|
||||
{
|
||||
for (int index = 0; index < game.nbRooms; index++)
|
||||
for (EntitySaveState& saved : game.roomList[index].savedEntities)
|
||||
{
|
||||
bool isRerollable = Entity_Pickup::CanRerollVariant(PICKUP_COLLECTIBLE, saved.subtype);
|
||||
if (saved.type != ENTITY_PICKUP || saved.variant != PICKUP_COLLECTIBLE || saved.subtype == 0 ||
|
||||
!isRerollable)
|
||||
continue;
|
||||
saved.subtype = 0;
|
||||
saved.boolStorage1 = false;
|
||||
}
|
||||
}
|
||||
|
||||
// (00704b10, 00704b30, 00704b40, 0065d000, 007e92c0, 00738310, 00738320, 007e9330, 007e9370, 0085e3c0, 0085e3d0,
|
||||
// 0085e3f0, 0085e400, 00753c50, 007e92d0, 00753c80, 00753cb0, 0085e370, 00703560) Registers Game's run counters: the
|
||||
// devil deals and donations, and the stages cleared without damage, hearts or half health.
|
||||
// The original pushes the last levels with damage or without half health as an unregistered class.
|
||||
static void game_counters_register(lua_State* state)
|
||||
{
|
||||
lua_method(state, "AddDevilRoomDeal", [](Game& game) {
|
||||
if (++game.devilRoomDeals >= AZAZEL_DEALS) g_manager->persistentGameData.TryUnlock(ACHIEVEMENT_AZAZEL);
|
||||
});
|
||||
lua_method(state, "DonateGreed", [](Game& game, int amount) { game.donationModGreed += amount; });
|
||||
lua_method(state, "DonateAngel", [](Game& game, int amount) { game.donationModAngel += amount; });
|
||||
lua_method(state, "GetDonationModGreed", [](Game& game) { return game.donationModGreed; });
|
||||
lua_method(state, "GetDonationModAngel", [](Game& game) { return game.donationModAngel; });
|
||||
lua_method(state, "ClearDonationModGreed", [](Game& game) { game.donationModGreed = 0; });
|
||||
lua_method(state, "ClearDonationModAngel", [](Game& game) { game.donationModAngel = 0; });
|
||||
lua_method(state, "SetLastDevilRoomStage",
|
||||
[](Game& game, int stage) { game.lastDevilRoomStage = std::clamp(stage, 0, STAGE_COUNTER_MAX); });
|
||||
lua_method(state, "AddTreasureRoomsVisited", [](Game& game) { game.treasureRoomsVisited++; });
|
||||
lua_method(state, "AddStageWithoutHeartsPicked", [](Game& game) { game.stagesWithoutHeartsPicked++; });
|
||||
lua_method(state, "ClearStagesWithoutHeartsPicked", [](Game& game) { game.stagesWithoutHeartsPicked = 0; });
|
||||
lua_method(state, "AddStageWithoutDamage", [](Game& game) { game.stagesWithoutDamage++; });
|
||||
lua_method(state, "ClearStagesWithoutDamage", [](Game& game) { game.stagesWithoutDamage = 0; });
|
||||
lua_method(state, "SetLastLevelWithDamage",
|
||||
[](Game& game, int stage) { game.lastLevelWithDamage = std::clamp(stage, 0, STAGE_COUNTER_MAX); });
|
||||
lua_method(state, "GetLastLevelWithDamage", [](Game&) { return LuaOpaque{}; });
|
||||
lua_method(state, "SetLastLevelWithoutHalfHp",
|
||||
[](Game& game, int stage) { game.lastLevelWithoutHalfHp = std::clamp(stage, 0, STAGE_COUNTER_MAX); });
|
||||
lua_method(state, "GetLastLevelWithoutHalfHp", [](Game&) { return LuaOpaque{}; });
|
||||
lua_method(state, "AddEncounteredBoss",
|
||||
[](Game&, int type, int variant) { game_encountered_boss_add(type, variant); });
|
||||
lua_method(state, "GetNumEncounteredBosses", [](Game& game) { return (int)game.encounteredBosses.size(); });
|
||||
lua_method(state, "GetGreedWavesNum",
|
||||
[](Game& game) { return GREED_WAVE_TOTAL + (game.difficulty == DIFFICULTY_GREEDIER); });
|
||||
}
|
||||
|
||||
// (00440ee0, 00440620, 00753cc0, 004a5d00, 00703460, 005b1860, 00456860, 0085e390) Registers Game's screen and world
|
||||
// effects: explosions, particles, shockwaves, darkness, pixelation, hallucinations, fades and the HUD font.
|
||||
// The original pushes the ambush and the item overlay as unregistered classes.
|
||||
static void game_effects_register(lua_State* state)
|
||||
{
|
||||
lua_method(state, "BombDamage",
|
||||
[](Game&, Vector position, float damage, float radius, bool isLineCheck, Entity* source, TearFlags flags,
|
||||
int64_t damageFlags, bool isDamageSource) {
|
||||
explosion_damage({.tearFlags = flags,
|
||||
.position = position,
|
||||
.source = source,
|
||||
.damageFlags = (uint64_t)damageFlags,
|
||||
.damage = damage,
|
||||
.radius = radius,
|
||||
.isDamageSource = isDamageSource,
|
||||
.isLineCheck = isLineCheck});
|
||||
});
|
||||
lua_method(state, "BombExplosionEffects",
|
||||
[](Game&, Vector position, float damage, TearFlags flags, const ColorMod& color, Entity* source,
|
||||
float radiusMultiplier, bool isLineCheck, int64_t damageFlags, bool isDamageSource) {
|
||||
explosion_effects({.tearFlags = flags,
|
||||
.color = color,
|
||||
.position = position,
|
||||
.source = source,
|
||||
.damageFlags = (uint64_t)damageFlags,
|
||||
.damage = damage,
|
||||
.radiusMultiplier = radiusMultiplier,
|
||||
.isDamageSource = isDamageSource,
|
||||
.isLineCheck = isLineCheck});
|
||||
});
|
||||
lua_method(state, "BombTearflagEffects",
|
||||
[](Game&, Vector position, float radius, TearFlags flags, Entity* source, float radiusMultiplier) {
|
||||
explosion_tear_flag_effects({.tearFlags = flags,
|
||||
.position = position,
|
||||
.source = source,
|
||||
.radius = radius,
|
||||
.radiusMultiplier = radiusMultiplier});
|
||||
});
|
||||
lua_method(state, "SpawnParticles",
|
||||
[](Game&, Vector position, int variant, int count, float speed, const ColorMod& color, float height,
|
||||
int subType) {
|
||||
game_particles_spawn({.color = color,
|
||||
.position = position,
|
||||
.height = height,
|
||||
.speed = speed,
|
||||
.count = count,
|
||||
.subType = subType,
|
||||
.variant = variant});
|
||||
});
|
||||
lua_method(state, "MakeShockwave", [](Game&, Vector position, float amplitude, float speed, int duration) {
|
||||
shockwave_make(position, amplitude, speed, duration);
|
||||
});
|
||||
lua_method(state, "UpdateStrangeAttractor",
|
||||
[](Game&, Vector, float, float) { reconstruction_missing("Game::AttractEntities 00705b90"); });
|
||||
lua_method(state, "CharmFart",
|
||||
[](Game&, Vector, float, Entity*) { reconstruction_missing("Game::CharmFart 00703f90"); });
|
||||
lua_method(state, "Darken", [](Game& game, float strength, int timeout) {
|
||||
game.darknessStrength = strength;
|
||||
game.darknessTimeout = timeout;
|
||||
});
|
||||
lua_method(state, "GetTargetDarkness", [](Game& game) { return game.darknessStrength; });
|
||||
lua_method(state, "AddPixelation", [](Game& game, int duration) {
|
||||
game.pixelationTimer = std::max(duration, game.pixelationTimer);
|
||||
game.pixelationDuration = game.pixelationTimer;
|
||||
});
|
||||
lua_method(state, "ShowHallucination",
|
||||
[](Game& game, int frames, int backdrop) { game.ShowHallucination(frames, backdrop); });
|
||||
lua_method(state, "HasHallucination", [](Game& game) { return game.hallucinationTimer > 0; });
|
||||
lua_method(state, "Fadein", [](Game& game, float speed, bool isShowIcon, KColor color) {
|
||||
game.Fadein(speed, isShowIcon ? FADE_ICON_SHOW : FADE_ICON_HIDE, color);
|
||||
});
|
||||
lua_method(state, "Fadeout",
|
||||
[](Game& game, float speed, FadeOutTarget target, KColor color) { game.Fadeout(speed, target, color); });
|
||||
lua_method(state, "GetFont", [](Game&) { return &g_manager->font2_TeamMeatEx12; });
|
||||
lua_method(state, "GetAmbush", [](Game&) { return LuaOpaque{}; });
|
||||
lua_method(state, "GetItemOverlay", [](Game&) { return LuaOpaque{}; });
|
||||
lua_method(state, "ShowFortune", [](Game&) { reconstruction_missing("Game::ShowFortuneText 009807a0"); });
|
||||
lua_method(state, "ShowRule", [](Game&) { reconstruction_missing("Game::ShowFortuneText 009807a0"); });
|
||||
}
|
||||
|
||||
// (00704f20, 006f9770) Registers how Game moves the run on: its frame and draw, room and floor changes, rerolls,
|
||||
// the ending and the next victory lap.
|
||||
// The original hands StartStageTransition a player from its stack. Here it has none.
|
||||
static void game_flow_register(lua_State* state)
|
||||
{
|
||||
lua_method(state, "Update", [](Game& game) { game.Update(); });
|
||||
lua_method(state, "Render", [](Game& game) { game.Render(); });
|
||||
lua_method(state, "ChangeRoom",
|
||||
[](Game& game, int roomIndex, int dimension) { game.ChangeRoom(roomIndex, dimension); });
|
||||
lua_method(state, "MoveToRandomRoom", [](Game& game, bool isErrorRoom, uint32_t seed, Entity_Player* player) {
|
||||
game_random_room_move(game, isErrorRoom, seed, player);
|
||||
});
|
||||
lua_method(state, "StartStageTransition", [](Game& game, bool isSameStage, StageTransitionType type) {
|
||||
game.stageTransition.start({.type = type, .isSameStage = isSameStage});
|
||||
});
|
||||
lua_method(state, "GetRandomPlayer", game_random_player);
|
||||
lua_method(state, "RerollLevelCollectibles", game_level_collectibles_reroll);
|
||||
lua_method(state, "RerollLevelPickups",
|
||||
[](Game&, uint32_t) { reconstruction_missing("Game::RerollLevelPickups 00704c50"); });
|
||||
lua_method(state, "RerollEnemy", [](Game&, Entity*, bool) {
|
||||
reconstruction_missing("Game::RerollEnemy 007050c0");
|
||||
return false;
|
||||
});
|
||||
lua_method(state, "SpawnEntityDesc",
|
||||
[](Game&, LuaIgnored, Vector, Entity*) { reconstruction_missing("Game::SpawnEntityDesc 006fece0"); });
|
||||
lua_method(state, "End", [](Game&, GameEnding ending) { game_end(ending); });
|
||||
lua_method(state, "FinishChallenge", [](Game&) { challenge_finish(); });
|
||||
lua_method(state, "NextVictoryLap", [](Game&) { reconstruction_missing("Game::NextVictoryLap 006f7ac0"); });
|
||||
}
|
||||
|
||||
// (00703510, 00703570) Registers Lua's Game: the run's level, room, players, pools, seeds and HUD, spawning, room
|
||||
// transitions and farts, and its state flags and counters. Game is also the Level it derives from.
|
||||
@@ -79,9 +284,23 @@ static void game_register(lua_State* state)
|
||||
lua_field<&Game::blueWombParTime>(state, "BlueWombParTime");
|
||||
lua_field<&Game::bossRushParTime>(state, "BossRushParTime");
|
||||
lua_field<&Game::screenShakeOffset>(state, "ScreenShakeOffset");
|
||||
game_counters_register(state);
|
||||
game_effects_register(state);
|
||||
game_flow_register(state);
|
||||
lua_class_end(state);
|
||||
}
|
||||
|
||||
// HUD:ShowFortuneText: the string arguments after the HUD, up to the first that is not one, as a fortune's lines.
|
||||
static int hud_fortune_text_show(lua_State* state)
|
||||
{
|
||||
HUD& hud = *static_cast<HUD*>(lua_object_check(state, 1, LUA_CLASS_HUD));
|
||||
std::vector<std::string> lines;
|
||||
for (int index = 2; index < FORTUNE_ARGUMENT_END && lua_type(state, index) == LUA_TSTRING; index++)
|
||||
lines.emplace_back(lua_tostring(state, index));
|
||||
hud.ShowFortuneText(lines);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Registers Lua's HUD, ItemPool and Seeds, the parts of a run Game hands out.
|
||||
static void game_parts_register(lua_State* state)
|
||||
{
|
||||
@@ -101,6 +320,8 @@ static void game_parts_register(lua_State* state)
|
||||
lua_method(state, "Update", [](HUD& hud) { hud.Update(); });
|
||||
lua_method(state, "PostUpdate", [](HUD& hud) { hud.PostUpdate(); });
|
||||
lua_method(state, "Render", [](HUD& hud) { hud.Render(); });
|
||||
lua_pushcfunction(state, hud_fortune_text_show);
|
||||
lua_table_set(state, -2, "ShowFortuneText");
|
||||
lua_class_end(state);
|
||||
|
||||
lua_class_begin(state, "ItemPool", LUA_CLASS_ITEM_POOL);
|
||||
@@ -136,6 +357,7 @@ static void game_parts_register(lua_State* state)
|
||||
lua_class_begin(state, "Seeds", LUA_CLASS_SEEDS);
|
||||
lua_method(state, "GetStartSeed", [](Seeds& seeds) { return seeds.GetStartSeed(); });
|
||||
lua_method(state, "IsCustomRun", [](Seeds& seeds) { return seeds.isCustomRun; });
|
||||
lua_method(state, "IsInitialized", [](Seeds& seeds) { return seeds.gameStartSeed != 0; });
|
||||
lua_method(state, "GetStartSeedString", [](Seeds& seeds) { return seeds.GetStartSeedString(); });
|
||||
lua_method(state, "GetNextSeed", [](Seeds& seeds) { return seeds.GetNextSeed(); });
|
||||
lua_method(state, "GetStageSeed", [](Seeds& seeds, int stage) { return seeds.GetStageSeed(stage); });
|
||||
|
||||
@@ -127,6 +127,7 @@ static void grid_entity_kinds_register(lua_State* state)
|
||||
|
||||
lua_class_begin(state, "GridEntityPoop", LUA_CLASS_GRID_ENTITY_POOP, LUA_CLASS_GRID_ENTITY);
|
||||
lua_method(state, "RespawnRedPoop", [](GridEntity_Poop& poop) { poop.RespawnRedPoop(); });
|
||||
lua_method(state, "ReduceSpawnRate", [](GridEntity_Poop& poop) { poop.varData = 1; });
|
||||
lua_field<&GridEntity_Poop::reviveTimer>(state, "ReviveTimer");
|
||||
lua_field<&GridEntity_Poop::stateAnimation>(state, "StateAnimation");
|
||||
lua_field<&GridEntity_Poop::isUnderPlayer>(state, "UnderPlayer");
|
||||
|
||||
@@ -2,18 +2,6 @@
|
||||
#include "item_config.h"
|
||||
#include "lua_api.h"
|
||||
|
||||
// Registers a list of configs Config hands out: its Size, and Get, nil past the end where the original reads on.
|
||||
template <typename T>
|
||||
static void config_list_register(lua_State* state, const char* name, LuaClass luaClass)
|
||||
{
|
||||
using List = std::vector<std::unique_ptr<T>>;
|
||||
lua_class_begin(state, name, luaClass);
|
||||
lua_property(state, "Size", [](List& list) { return (int)list.size(); });
|
||||
lua_method(state, "Get",
|
||||
[](List& list, uint32_t index) { return index < list.size() ? list[index].get() : nullptr; });
|
||||
lua_class_end(state, LUA_SCOPE_NAMESPACE);
|
||||
}
|
||||
|
||||
// Registers ItemConfig.Item, a collectible, trinket or null item, and ItemConfig.Costume.
|
||||
static void item_register(lua_State* state)
|
||||
{
|
||||
@@ -108,9 +96,9 @@ void lua_api_item_config_register(lua_State* state)
|
||||
lua_namespace_begin(state, "ItemConfig");
|
||||
item_register(state);
|
||||
pocket_items_register(state);
|
||||
config_list_register<ItemConfig_Item>(state, "ItemConfigList", LUA_CLASS_ITEM_CONFIG_ITEM_LIST);
|
||||
config_list_register<ItemConfig_Card>(state, "CardConfigList", LUA_CLASS_ITEM_CONFIG_CARD_LIST);
|
||||
config_list_register<ItemConfig_Pill>(state, "PillConfigList", LUA_CLASS_ITEM_CONFIG_PILL_LIST);
|
||||
lua_list_register<std::vector<std::unique_ptr<ItemConfig_Item>>>(state, "ItemConfigList");
|
||||
lua_list_register<std::vector<std::unique_ptr<ItemConfig_Card>>>(state, "CardConfigList");
|
||||
lua_list_register<std::vector<std::unique_ptr<ItemConfig_Pill>>>(state, "PillConfigList");
|
||||
|
||||
lua_class_begin(state, "Config", LUA_CLASS_ITEM_CONFIG);
|
||||
lua_method(state, "GetCollectible", [](ItemConfig& config, int id) { return config.GetCollectible(id); });
|
||||
|
||||
+94
-13
@@ -1,14 +1,19 @@
|
||||
#include "classes.h"
|
||||
#include "entity_knife.h"
|
||||
#include "entity_npc.h"
|
||||
#include "game.h"
|
||||
#include "item_pool.h"
|
||||
#include "grid_entity.h"
|
||||
#include "grid_entity_door.h"
|
||||
#include "level.h"
|
||||
#include "lua_api.h"
|
||||
#include "npc_basement.h"
|
||||
#include "room.h"
|
||||
#include "room_config.h"
|
||||
#include "room_descriptor.h"
|
||||
#include "room_clear.h"
|
||||
#include "room_grid.h"
|
||||
#include "room_special.h"
|
||||
|
||||
// The frames KeepDoorsClosed holds the room uncleared for.
|
||||
constexpr int ROOM_CLEAR_DELAY_KEPT = 10;
|
||||
@@ -22,17 +27,6 @@ static void descriptor_flag_add(lua_State* state, const char* name)
|
||||
[](RoomDescriptor& room, bool isSet) { room.flags = isSet ? room.flags | Flag : room.flags & ~Flag; });
|
||||
}
|
||||
|
||||
// Registers a list of a room config's spawns or entries: its Size, and Get, nil past the end.
|
||||
template <typename T>
|
||||
static void room_config_list_register(lua_State* state, const char* name, LuaClass luaClass)
|
||||
{
|
||||
using List = std::vector<T>;
|
||||
lua_class_begin(state, name, luaClass);
|
||||
lua_property(state, "Size", [](List& list) { return (int)list.size(); });
|
||||
lua_method(state, "Get", [](List& list, uint32_t index) { return index < list.size() ? &list[index] : nullptr; });
|
||||
lua_class_end(state, LUA_SCOPE_NAMESPACE);
|
||||
}
|
||||
|
||||
// Registers RoomConfig.Spawn, a cell of a layout and the entities it picks one of, RoomConfig.Entry, one of those, and
|
||||
// their lists, in the RoomConfig namespace begun before.
|
||||
static void room_config_spawns_register(lua_State* state)
|
||||
@@ -53,8 +47,8 @@ static void room_config_spawns_register(lua_State* state)
|
||||
lua_field_get<&RoomEntry::weight>(state, "Weight");
|
||||
lua_class_end(state, LUA_SCOPE_NAMESPACE);
|
||||
|
||||
room_config_list_register<RoomSpawn>(state, "SpawnList", LUA_CLASS_ROOM_CONFIG_SPAWN_LIST);
|
||||
room_config_list_register<RoomEntry>(state, "EntryList", LUA_CLASS_ROOM_CONFIG_ENTRY_LIST);
|
||||
lua_list_register<std::vector<RoomSpawn>>(state, "SpawnList");
|
||||
lua_list_register<std::vector<RoomEntry>>(state, "EntryList");
|
||||
}
|
||||
|
||||
// Registers Lua's Level, which Game is: the floor's stage, curses, rooms and maps.
|
||||
@@ -102,6 +96,7 @@ static void level_register(lua_State* state)
|
||||
lua_method(state, "GetRooms", [](Level& level) { return LuaRoomList{level.roomList.data(), level.nbRooms}; });
|
||||
lua_method(state, "GetNonCompleteRoomIndex", [](Level& level) { return level.GetNonCompleteRoomIndex(); });
|
||||
lua_method(state, "ChangeRoom", [](Level& level, int index, int dimension) { level.ChangeRoom(index, dimension); });
|
||||
lua_method(state, "Update", [](Level& level) { level.Update(); });
|
||||
lua_method(state, "GetEnterPosition", [](Level& level) { return level.GetEnterPosition(); });
|
||||
lua_field<&Level::enterDoor>(state, "EnterDoor");
|
||||
lua_field<&Level::leaveDoor>(state, "LeaveDoor");
|
||||
@@ -201,6 +196,90 @@ static void level_register(lua_State* state)
|
||||
lua_class_end(state);
|
||||
}
|
||||
|
||||
// (00812c10, 00813b60, 00813b30, 00813c40, 00813bf0, 00812de0) Registers Room's grid helpers: the path value under
|
||||
// a position, damaging and destroying grid entities, bridging pits and where a beam lands.
|
||||
static void room_grid_register(lua_State* state)
|
||||
{
|
||||
lua_method(state, "GetGridPathFromPos", [](Room& room, Vector position) {
|
||||
int column = (int)((position.x - GRID_ORIGIN_X) / GRID_CELL_SIZE + 0.5f);
|
||||
int row = (int)((position.y - GRID_ORIGIN_Y) / GRID_CELL_SIZE + 0.5f);
|
||||
bool isOnGrid = column >= 0 && column < room.gridWidth && row >= 0 && row < room.gridHeight;
|
||||
int index = row * room.gridWidth + column;
|
||||
return isOnGrid && index < ROOM_GRID_CELLS ? room.gridPaths[index] : 0;
|
||||
});
|
||||
lua_method(state, "GetClampedGridIndex",
|
||||
[](Room& room, Vector position) { return room_clamped_grid_index_get(room, position); });
|
||||
lua_method(state, "DamageGrid", [](Room& room, uint32_t index, int damage) {
|
||||
GridEntity* grid = room.GetGridEntity(index);
|
||||
return grid && grid->Hurt(damage, EntityRef{});
|
||||
});
|
||||
lua_method(state, "DamageGridWithSource", [](Room& room, uint32_t index, int damage, const EntityRef& source) {
|
||||
GridEntity* grid = room.GetGridEntity(index);
|
||||
return grid && grid->Hurt(damage, source);
|
||||
});
|
||||
lua_method(state, "DestroyGrid", [](Room&, int index, bool isImmediate, bool isDefuseBombRock) {
|
||||
return room_grid_destroy(
|
||||
{.gridIndex = index, .isImmediate = isImmediate, .isDefuseBombRock = isDefuseBombRock});
|
||||
});
|
||||
lua_method(state, "DestroyGridWithSource",
|
||||
[](Room&, int index, bool isImmediate, bool isDefuseBombRock, const EntityRef& source) {
|
||||
return room_grid_destroy({.source = source,
|
||||
.gridIndex = index,
|
||||
.isImmediate = isImmediate,
|
||||
.isDefuseBombRock = isDefuseBombRock});
|
||||
});
|
||||
lua_method(state, "TryMakeBridge",
|
||||
[](Room&, GridEntity* pit, GridEntity* rock) { return room_bridge_make(pit, rock); });
|
||||
lua_method(state, "GetLaserTarget",
|
||||
[](Room&, Vector position, Vector direction) { return room_laser_target_get(position, direction); });
|
||||
lua_method(state, "ScreenWrapPosition",
|
||||
[](Room&, Vector position, float margin) { return room_screen_wrap(position, margin); });
|
||||
}
|
||||
|
||||
// (007e91a0, 007537c0, 007537d0, 004566f0, 00820aa0, 006b8400, 007e91b0, 007e91f0, 007120c0, 005784d0, 005b16c0,
|
||||
// 0085e130, 00428a50) Registers Room's state: its entities, colors, rain and lava, the red heart damage taken, the
|
||||
// bleeding walls, the dungeon's rock and the shop and clear helpers. The original pushes the L room descriptions as
|
||||
// unregistered classes.
|
||||
static void room_state_register(lua_State* state)
|
||||
{
|
||||
lua_method(state, "GetEntities", [](Room& room) -> EntityList_EL& { return room.entityList.updateEL; });
|
||||
lua_method(state, "GetRedHeartDamage", [](Room& room) { return room.isRedHeartDamaged; });
|
||||
lua_method(state, "SetRedHeartDamage", [](Room& room) { room.isRedHeartDamaged = true; });
|
||||
lua_method(state, "SetCardAgainstHumanity", [](Room& room) { room.isCardAgainstHumanity = true; });
|
||||
lua_method(state, "EmitBloodFromWalls", [](Room& room, int duration, int count) {
|
||||
room.bloodFromWallsDuration = duration;
|
||||
room.bloodFromWallsCount = count;
|
||||
});
|
||||
lua_method(state, "GetDungeonRockIdx", [](Room& room) {
|
||||
return g_game->levelStateFlags & 1u << LEVEL_STATE_DUNGEON_ROCK_BROKEN ? -1 : room.dungeonRockIdx;
|
||||
});
|
||||
lua_method(state, "SetFirstEnemyDead", [](Room& room, bool isDead) { room.isFirstEnemyDead = isDead; });
|
||||
lua_method(state, "SetFloorColor", [](Room& room, const ColorMod& color) { room.floorColor = color; });
|
||||
lua_method(state, "SetWallColor", [](Room& room, const ColorMod& color) { room.wallColor = color; });
|
||||
lua_method(state, "GetLavaIntensity", [](Room& room) { return room.lavaIntensity; });
|
||||
lua_method(state, "StopRain", [](Room& room) { room.isRainStopped = true; });
|
||||
lua_method(state, "InvalidatePickupVision", [](Room& room) { room.isPickupVisionInvalid = true; });
|
||||
lua_method(state, "GetEnemyDamageInflicted", [](Room& room) { return room.entityList.enemyDamageInflicted; });
|
||||
lua_method(state, "GetLRoomAreaDesc", [](Room&) { return LuaOpaque{}; });
|
||||
lua_method(state, "GetLRoomTileDesc", [](Room&) { return LuaOpaque{}; });
|
||||
lua_method(state, "GetSeededCollectible", [](Room& room, uint32_t seed, bool isNoDecrease) {
|
||||
return g_game->itemPool.GetSeededCollectible(seed, isNoDecrease, *room.descriptor);
|
||||
});
|
||||
lua_method(state, "ShopRestockPartial", [](Room& room) { room_restock_partial(room); });
|
||||
lua_method(state, "ShopRestockFull", [](Room&) { reconstruction_missing("Room::ShopRestockFull 00815ae0"); });
|
||||
lua_method(state, "ShopReshuffle",
|
||||
[](Room&, bool, bool) { reconstruction_missing("Room::ShopReshuffle 00816000"); });
|
||||
lua_method(state, "SpawnClearAward", [](Room& room) { room_clear_award_spawn(room); });
|
||||
lua_method(state, "TriggerClear", [](Room& room, bool isSilent) {
|
||||
room_clear_trigger(room, isSilent ? CLEAR_SOUND_SILENT : CLEAR_SOUND_PLAY);
|
||||
});
|
||||
lua_method(state, "RespawnEnemies", [](Room&) { reconstruction_missing("Room::RespawnEnemies 0081fd60"); });
|
||||
lua_method(state, "MamaMegaExplosion",
|
||||
[](Room&, Vector, Entity_Player*) { reconstruction_missing("Room::MamaMegaExplosion 00820910"); });
|
||||
lua_method(state, "Update", [](Room& room) { room.Update(); });
|
||||
lua_method(state, "Render", [](Room& room) { room.Render(); });
|
||||
}
|
||||
|
||||
// (007f79d0, 0081e240, 00820c00) Registers Lua's Room: the current room's grid, entities, doors, clear state and the
|
||||
// doors it may spawn.
|
||||
static void room_register(lua_State* state)
|
||||
@@ -323,6 +402,8 @@ static void room_register(lua_State* state)
|
||||
return room.TrySpawnSecretExit(isAnimated, isForced);
|
||||
});
|
||||
lua_method(state, "TrySpawnSpecialQuestDoor", [](Room& room) { return room.TrySpawnSpecialQuestDoor(); });
|
||||
room_grid_register(state);
|
||||
room_state_register(state);
|
||||
lua_class_end(state);
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,9 @@ static void sprite_register(lua_State* state)
|
||||
[](ANM2& sprite) -> const std::string& { return sprite.GetDefaultAnimationName(); });
|
||||
lua_method(state, "GetDefaultAnimationName",
|
||||
[](ANM2& sprite) -> const std::string& { return sprite.GetDefaultAnimationName(); });
|
||||
lua_method(state, "GetTexel", [](ANM2& sprite, Vector sample, Vector renderPos, float alpha, int layerId) {
|
||||
return sprite.GetTexel({.renderPos = renderPos, .sample = sample, .alphaThreshold = alpha, .layerId = layerId});
|
||||
});
|
||||
|
||||
lua_method(state, "PlayOverlay", [](ANM2& sprite, std::string_view name, bool isForced) {
|
||||
sprite.PlayOverlay(name, isForced ? PLAY_FORCED : PLAY_UNFORCED);
|
||||
|
||||
+5
-4
@@ -178,10 +178,11 @@ void LuaEngine::Init(LuaMode luaMode)
|
||||
// SFXManager and MusicManager classes with the functions returning them.
|
||||
void LuaEngine::RegisterAPI()
|
||||
{
|
||||
for (auto registerPart : {lua_api_vector_register, lua_api_color_register, lua_api_rng_register,
|
||||
lua_api_bit_set128_register, lua_api_sprite_register, lua_api_entity_register,
|
||||
lua_api_entities_register, lua_api_entity_player_register, lua_api_game_register,
|
||||
lua_api_room_register, lua_api_item_config_register, lua_api_isaac_register})
|
||||
for (auto registerPart :
|
||||
{lua_api_vector_register, lua_api_color_register, lua_api_rng_register, lua_api_bit_set128_register,
|
||||
lua_api_containers_register, lua_api_sprite_register, lua_api_entity_register, lua_api_entities_register,
|
||||
lua_api_entity_player_register, lua_api_game_register, lua_api_room_register, lua_api_item_config_register,
|
||||
lua_api_isaac_register})
|
||||
registerPart(state);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ constexpr int LUA_REF_NONE = -2;
|
||||
// The game classes the API binds, each with the registry key of the metatable its objects get.
|
||||
enum LuaClass
|
||||
{
|
||||
LUA_CLASS_ACTIVE_ITEM_DESC,
|
||||
LUA_CLASS_BIT_SET128,
|
||||
LUA_CLASS_COLOR,
|
||||
LUA_CLASS_ENTITY,
|
||||
@@ -49,6 +50,8 @@ enum LuaClass
|
||||
LUA_CLASS_PLAYER,
|
||||
LUA_CLASS_PROJECTILE,
|
||||
LUA_CLASS_TEAR,
|
||||
LUA_CLASS_EFFECT_LIST,
|
||||
LUA_CLASS_ENTITY_LIST,
|
||||
LUA_CLASS_ENTITY_PTR,
|
||||
LUA_CLASS_ENTITY_REF,
|
||||
LUA_CLASS_FONT,
|
||||
@@ -77,6 +80,7 @@ enum LuaClass
|
||||
LUA_CLASS_LEVEL,
|
||||
LUA_CLASS_MUSIC_MANAGER,
|
||||
LUA_CLASS_PATH_FINDER,
|
||||
LUA_CLASS_POS_VEL,
|
||||
LUA_CLASS_PROJECTILE_PARAMS,
|
||||
LUA_CLASS_QUEUE_ITEM_DATA,
|
||||
LUA_CLASS_RNG,
|
||||
@@ -95,6 +99,7 @@ enum LuaClass
|
||||
LUA_CLASS_TEMPORARY_EFFECT,
|
||||
LUA_CLASS_TEMPORARY_EFFECTS,
|
||||
LUA_CLASS_VECTOR,
|
||||
LUA_CLASS_VECTOR_LIST,
|
||||
LUA_CLASS_COUNT
|
||||
};
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ enum MusicId : int
|
||||
MUSIC_MOM_BOSS = 20,
|
||||
MUSIC_MOMS_HEART_BOSS = 21,
|
||||
MUSIC_ISAAC_BOSS = 22,
|
||||
MUSIC_SATAN_BOSS = 23,
|
||||
MUSIC_DARK_ROOM_BOSS = 24,
|
||||
MUSIC_CHEST_BOSS = 25,
|
||||
MUSIC_BOSS2 = 26,
|
||||
|
||||
+15
-20
@@ -1,6 +1,6 @@
|
||||
#include "npc_ai.h"
|
||||
#include "boss_ai.h"
|
||||
#include "npc_depths.h"
|
||||
#include "npc_alt.h"
|
||||
#include "game.h"
|
||||
#include "manager.h"
|
||||
#include "npc_fireplace.h"
|
||||
@@ -166,7 +166,7 @@ static void npc_ai_routine_run(Entity_NPC& npc)
|
||||
case 39:
|
||||
case 49:
|
||||
case 836:
|
||||
return (void)NpcAI::ENTITY_VIS(&npc);
|
||||
return npc_vis_update(npc);
|
||||
case 40:
|
||||
case 218:
|
||||
case 862:
|
||||
@@ -185,17 +185,12 @@ static void npc_ai_routine_run(Entity_NPC& npc)
|
||||
case 45:
|
||||
return boss_mom_update(npc);
|
||||
case 46:
|
||||
return (void)NpcAI::ENTITY_SLOTH(&npc);
|
||||
case 47:
|
||||
return (void)NpcAI::ENTITY_LUST(&npc);
|
||||
case 48:
|
||||
return (void)NpcAI::ENTITY_WRATH(&npc);
|
||||
case 50:
|
||||
return (void)NpcAI::ENTITY_GREED(&npc);
|
||||
case 51:
|
||||
return (void)NpcAI::ENTITY_ENVY(&npc);
|
||||
case 52:
|
||||
return (void)NpcAI::ENTITY_PRIDE(&npc);
|
||||
return npc_sin_update(npc);
|
||||
case 53:
|
||||
return (void)NpcAI::ENTITY_DOPLE(&npc);
|
||||
case 56:
|
||||
@@ -206,9 +201,9 @@ static void npc_ai_routine_run(Entity_NPC& npc)
|
||||
case 58:
|
||||
return npc_para_bite_update(npc);
|
||||
case 59:
|
||||
return (void)NpcAI::ENTITY_FRED(&npc);
|
||||
return npc_fred_update(npc);
|
||||
case 60:
|
||||
return (void)NpcAI::ENTITY_EYE(&npc);
|
||||
return npc_eye_update(npc);
|
||||
case 62:
|
||||
return (void)NpcAI::ENTITY_PIN(&npc);
|
||||
case 63:
|
||||
@@ -240,12 +235,12 @@ static void npc_ai_routine_run(Entity_NPC& npc)
|
||||
case 79:
|
||||
return boss_gemini_update(npc);
|
||||
case 81:
|
||||
return (void)NpcAI::ENTITY_FALLEN(&npc);
|
||||
return boss_fallen_update(npc);
|
||||
case 82:
|
||||
case 83:
|
||||
return (void)NpcAI::ENTITY_HEADLESS_HORSEMAN(&npc);
|
||||
case 84:
|
||||
return (void)NpcAI::ENTITY_SATAN(&npc);
|
||||
return boss_satan_update(npc);
|
||||
case 85:
|
||||
case 94:
|
||||
case 215:
|
||||
@@ -279,7 +274,7 @@ static void npc_ai_routine_run(Entity_NPC& npc)
|
||||
case 100:
|
||||
return boss_widow_update(npc);
|
||||
case 101:
|
||||
return (void)NpcAI::ENTITY_DADDYLONGLEGS(&npc);
|
||||
return boss_daddy_long_legs_update(npc);
|
||||
case 102:
|
||||
return (void)NpcAI::ENTITY_ISAAC(&npc);
|
||||
case 201:
|
||||
@@ -336,7 +331,7 @@ static void npc_ai_routine_run(Entity_NPC& npc)
|
||||
case 241:
|
||||
case 242:
|
||||
case 304:
|
||||
return (void)NpcAI::ENTITY_WALL_CREEP(&npc);
|
||||
return npc_wall_creep_update(npc);
|
||||
case 244:
|
||||
case 255:
|
||||
case 276:
|
||||
@@ -387,7 +382,7 @@ static void npc_ai_routine_run(Entity_NPC& npc)
|
||||
case 288:
|
||||
return npc_dukie_update(npc);
|
||||
case 290:
|
||||
return (void)NpcAI::ENTITY_MEATBALL(&npc);
|
||||
return npc_meatball_update(npc);
|
||||
case 291:
|
||||
return npc_pitfall_update(npc);
|
||||
case 292:
|
||||
@@ -447,7 +442,7 @@ static void npc_ai_routine_run(Entity_NPC& npc)
|
||||
case 802:
|
||||
return (void)NpcAI::ENTITY_BLOOD_PUPPY(&npc);
|
||||
case 804:
|
||||
return (void)NpcAI::ENTITY_QUAKE_GRIMACE(&npc);
|
||||
return npc_quake_grimace_update(npc);
|
||||
case 805:
|
||||
return (void)NpcAI::ENTITY_BISHOP(&npc);
|
||||
case 806:
|
||||
@@ -455,7 +450,7 @@ static void npc_ai_routine_run(Entity_NPC& npc)
|
||||
case 808:
|
||||
return (void)NpcAI::ENTITY_WILLO(&npc);
|
||||
case 809:
|
||||
return (void)NpcAI::ENTITY_BOMB_GRIMACE(&npc);
|
||||
return npc_bomb_grimace_update(npc);
|
||||
case 810:
|
||||
return (void)NpcAI::ENTITY_SMALL_LEECH(&npc);
|
||||
case 811:
|
||||
@@ -475,17 +470,17 @@ static void npc_ai_routine_run(Entity_NPC& npc)
|
||||
case 820:
|
||||
return (void)NpcAI::ENTITY_DANNY(&npc);
|
||||
case 821:
|
||||
return (void)NpcAI::ENTITY_BLASTER(&npc);
|
||||
return npc_blaster_update(npc);
|
||||
case 822:
|
||||
return (void)NpcAI::ENTITY_BOUNCER(&npc);
|
||||
case 823:
|
||||
return (void)NpcAI::ENTITY_QUAKEY(&npc);
|
||||
return npc_quakey_update(npc);
|
||||
case 824:
|
||||
return (void)NpcAI::ENTITY_GYRO(&npc);
|
||||
case 825:
|
||||
return (void)NpcAI::ENTITY_FIRE_WORM(&npc);
|
||||
case 826:
|
||||
return (void)NpcAI::ENTITY_HARDY(&npc);
|
||||
return npc_hardy_update(npc);
|
||||
case 827:
|
||||
return (void)NpcAI::ENTITY_FACELESS(&npc);
|
||||
case 828:
|
||||
|
||||
@@ -109,6 +109,7 @@ void npc_fly_update(Entity_NPC& npc);
|
||||
void npc_gaper_update(Entity_NPC& npc);
|
||||
void npc_horf_update(Entity_NPC& npc);
|
||||
void npc_dip_update(Entity_NPC& npc);
|
||||
void npc_sin_update(Entity_NPC& npc);
|
||||
|
||||
// The corn dip's variant.
|
||||
constexpr int DIP_CORN = 1;
|
||||
Loaded 100 of 151 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user