Curation round 20: player update, costumes and render, Missing No., the last actives and cards, familiars, Pin, the Frail, Wormwood and the Heretic, Dross to Gehenna, effects and the devil room purchase, champion colours, the quit path, save fields, shared vector helpers

This commit is contained in:
shweet committed 2026-11-22 00:33:35 -05:00
1 parent ee863e70e6
commit 8dbeb1bc4a
168 files changed
+15682 -2399

No files matched your search

+168 -60
View File
@@ -1,9 +1,11 @@
#include "entity_npc.h"
#include "active_items.h"
#include "boss_ai.h"
#include "boss_death.h"
#include "entity_bomb.h"
#include "entity_config.h"
#include "entity_effect.h"
#include "entity_factory.h"
#include "entity_familiar.h"
#include "entity_laser.h"
#include "entity_pickup.h"
@@ -13,6 +15,7 @@
#include "game.h"
#include "grid_entity.h"
#include "log.h"
#include "lua_engine.h"
#include "manager.h"
#include "npc_ai.h"
#include "npc_basement.h"
@@ -23,6 +26,7 @@
#include "room_descriptor.h"
#include "room_grid.h"
#include "sfx_manager.h"
#include "menu_manager.h"
#include "mines.h"
#include "npc_alt.h"
#include <algorithm>
@@ -40,7 +44,6 @@ constexpr uint32_t DOPLE_PICK_SHIFT = 11;
constexpr int ENTITY_UNREACHABLE_EXEMPT = 886;
constexpr int ENTITY_DEATH_SPARK_TYPE = 882;
constexpr int ENTITY_DAMAGE_NUMBERS_TYPE = 964;
constexpr int ENTITY_ERASE_EXEMPT = 950;
constexpr int APPEAR_OVERLAY_KEPT_TYPE = 266;
constexpr float BIG_HORN_APPEAR_VOLUME = 2;
constexpr std::array<int, 4> APPEAR_EVENT_TYPES = {404, 912, 913, 917};
@@ -92,6 +95,12 @@ constexpr float MIDAS_COIN_SPEED = 3;
constexpr float TOXIC_CREEP_SCALE = 0.05f;
constexpr int TOXIC_SHOCK_POISON = -40;
constexpr int MODEM_FRAMES = 50;
constexpr int MODEM_ODDS = 55;
constexpr int MODEM_MIN_ODDS = 38;
constexpr int SLOWED_TIME_COLOR_PRIORITY = 250;
constexpr ColorMod GAME_KID_COLOR = {{0.3f, 0.5f, 1.2f, 1}, {0, 0, 0, 0}, {0, 0, 0}};
constexpr ColorMod SLOWED_TIME_COLOR = {
{1, 1, 1.3f, 1}, {0, 0, 0, 0}, {40 * COLOR_OFFSET_UNIT, 40 * COLOR_OFFSET_UNIT, 40 * COLOR_OFFSET_UNIT}};
constexpr int PUPPY_HIT_FRAMES = 3;
constexpr int FORCED_TARGET_BOSS_COOLDOWN = 150;
constexpr int CONFUSION_RETARGET_FRAMES = 15;
@@ -154,7 +163,6 @@ enum DeathBurst : int
};
constexpr int ENTITY_SIREN_HELPER = 966;
constexpr int ENTITY_EXORCIST = 832;
constexpr int ENTITY_SHADOW_CHARGER = 23;
constexpr int ENTITY_ULTRA_GREED_DOOR = 889;
constexpr int SUCKER_VARIANT_BULB = 5;
@@ -208,14 +216,9 @@ constexpr float CHAMPION_CHANCE_LATE_SPAWN = 0.2f;
constexpr float CHAMPION_CHANCE_VICTORY_LAP = 0.25f;
constexpr float CHAMPION_CHANCE_PURPLE_HEART = 3;
// What a layer's bitflags say about it: drawn in the floor's dirt color, and wearing its champion sheet.
constexpr unsigned int LAYER_DIRT_COLORED = 1 << 0;
constexpr unsigned int LAYER_CHAMPION_SHEET = 1 << 4;
constexpr unsigned int SPRITE_UNKNOWN_FLAG_20 = 1 << 5;
constexpr unsigned int STATUS_SHARED = 1u << 31;
constexpr int TYPE_SPRITE_FLAG_A = 950;
constexpr int TYPE_SPRITE_FLAG_B = 960;
constexpr int VARIANT_SPRITE_FLAG_B = 4;
// Dogma and the generic prop's TV (960.4) draw with the static shader.
constexpr int GENERIC_PROP_TV = 4;
constexpr std::string_view STATUS_EFFECTS_ANM2 = "gfx/StatusEffects.anm2";
// The target search: how far enemies look for players, and what pushes a player back or pulls a twin forward.
@@ -353,6 +356,26 @@ Entity_Player* game_nearest_player(const Vector& position)
return nearest;
}
// (00703ab0) Game::GetNearestPlayerEx for the main players only: the nearest player itself (not a co-op ghost, baby,
// twin's hold or hologram) that collides with entities.
Entity_Player* main_player_nearest(const Vector& position)
{
Entity_Player* nearest = nullptr;
float best = 1e10f;
for (Entity_Player* player : g_game->playerManager.playerList)
{
float distance = vector_length_squared(vector_sub(position, player->pos));
if (distance >= best) continue;
if (player->variant != 0 || player->isCoopGhost || player->parent || player->IsHologram()) continue;
if (player->entityCollisionClass == ENTCOLL_NONE) continue;
nearest = player;
best = distance;
}
return nearest;
}
// The charge Bulb drains a player for: one per full active, else its charges.
static int active_charges_get(Entity_Player& player)
{
@@ -612,7 +635,7 @@ void Entity_NPC::Init(int entityType, int entityVariant, int entitySubType, uint
isDeathSoundAlt = false;
aiCallFlags = 0;
controllerID = -1;
unknownF2c = 0;
isControlSwapped = false;
controllerMovement = {};
aimTargetEffect = nullptr;
forwardVector = {};
@@ -829,23 +852,24 @@ void Entity_NPC::load_graphics(bool isReloadAnm2)
std::string name = layer.layerData ? layer.layerData->name : "";
if (name == DIRT_LAYER || name == HOLE_LAYER)
{
layer.bitflags |= LAYER_DIRT_COLORED;
layer.bitflags |= ANIM_RENDER_UNTINTED;
isDirtUsed = true;
}
if (name == HOLE2_LAYER) layer.bitflags |= LAYER_DIRT_COLORED;
if (name == HOLE2_LAYER) layer.bitflags |= ANIM_RENDER_UNTINTED;
bool isChampionSheet = false;
std::string sheet = layer.layerData ? layer.layerData->spriteSheetPath : "";
sprite.ReplaceSpritesheet(i, sheet_path_resolve(sheet, floorSuffix, championSuffix, isChampionSheet));
LayerState& replaced = sprite.layerStates[i];
replaced.bitflags =
isChampionSheet ? replaced.bitflags | LAYER_CHAMPION_SHEET : replaced.bitflags & ~LAYER_CHAMPION_SHEET;
replaced.bitflags &= ~ANIM_RENDER_COLOROFFSET_CHAMPION;
if (isChampionSheet) replaced.bitflags |= ANIM_RENDER_COLOROFFSET_CHAMPION;
isChampionSheetUsed = isChampionSheetUsed || isChampionSheet;
}
sprite.championColor = isChampionSheetUsed && championLook ? *championLook : ColorMod{};
bool isFlagged = type == TYPE_SPRITE_FLAG_A || (type == TYPE_SPRITE_FLAG_B && variant == VARIANT_SPRITE_FLAG_B);
sprite.bitflags = isFlagged ? sprite.bitflags | SPRITE_UNKNOWN_FLAG_20 : sprite.bitflags & ~SPRITE_UNKNOWN_FLAG_20;
bool isStatic = type == ENTITY_DOGMA || (type == ENTITY_GENERIC_PROP && variant == GENERIC_PROP_TV);
sprite.bitflags &= ~ANIM_RENDER_STATIC;
if (isStatic) sprite.bitflags |= ANIM_RENDER_STATIC;
sprite.LoadGraphics();
if (isDirtUsed) UpdateDirtColor(true);
}
@@ -1059,15 +1083,7 @@ void Entity_NPC::Morph(int entityType, int entityVariant, int entitySubType, int
pathfinder.Reset();
g_manager->persistentGameData.TryAddBestiaryEncounter(type, variant);
isBestiaryEncountered = true;
if (game_is_enemy_erased(*this)) Entity::RemoveWithPoof(this);
}
// 007078f0 Whether the run erased this kind of enemy (Eraser). A friendly enemy is never erased.
bool game_is_enemy_erased(Entity& entity)
{
if (entity.type == ENTITY_ERASE_EXEMPT || (Entity::is_enemy_type(entity.type) && entity.IsFriendly())) return false;
if (g_game->erasedEntities.empty()) return false;
reconstruction_missing("Game::ShouldEraseEnemy 007078f0: FixErasedEnemyID");
if (entity_is_erased(*this)) Entity::RemoveWithPoof(this);
}
// 006c4ac0 Remembers where it was, and keeps the Exorcist's room in its state while it lives.
@@ -1605,27 +1621,53 @@ void Entity_NPC::item_effects_update()
Entity_Player* targetPlayer = GetPlayerTarget()->ToPlayer();
if (targetPlayer && targetPlayer->IsInvisible()) AddConfusion(EntityRef(this), STATUS_REFRESH, false);
if (players.FirstCollectibleOwner(COLLECTIBLE_BROKEN_MODEM_ID, LAZARUS_SHARE_IGNORE))
reconstruction_missing("Entity_NPC::Update 006c4b30: Broken Modem's stalls");
{
int odds = std::max(MODEM_MIN_ODDS, MODEM_ODDS - (int)players.get_total_luck());
odds *= IsBoss() ? 3 : 2;
if (IsVulnerableEnemy(nullptr) && random_below(odds) == 0 && !isDead)
{
Entity& head = *GetStatusEffectTarget();
head.AddEntityFlags(FLAG_FREEZE);
head.CopyStatusEffects();
}
}
if (IsActiveEnemy(DEAD_EXCLUDED) && HasEntityFlags(FLAG_FREEZE) && freezeCountdown < 1 && IsFrame(MODEM_FRAMES, 0))
reconstruction_missing("Entity_NPC::Update 006c4b30: Broken Modem's release");
modem_release();
if (!HasEntityFlags(FLAG_NO_TARGET))
for (Entity_Player* player : players.playerList)
if (player->temporaryEffects.HasCollectibleEffect(COLLECTIBLE_GAMEKID_ID))
reconstruction_missing("Entity_NPC::Update 006c4b30: Game Kid's fear");
if (!HasEntityFlags(FLAG_NO_TARGET) && std::ranges::any_of(players.playerList, [](Entity_Player* player) {
return player->temporaryEffects.HasCollectibleEffect(COLLECTIBLE_GAMEKID_ID);
}))
{
SetColor(GAME_KID_COLOR, 2, 0, false, true);
AddFear(EntityRef(this), STATUS_REFRESH, false);
}
TemporaryEffects& roomEffects = g_game->room->temporaryEffects;
bool isTimeSlowed = roomEffects.HasCollectibleEffect(COLLECTIBLE_STOP_WATCH_ID) ||
roomEffects.HasCollectibleEffect(COLLECTIBLE_HOURGLASS_ID) ||
g_game->room->GetBrokenWatchState() == BROKEN_WATCH_SLOW;
bool isTimeImmune = (flags & (FLAG_FRIENDLY | FLAG_NO_STATUS_EFFECTS)) && type != ENTITY_DEATHS_HEAD;
if (isTimeSlowed && !isTimeImmune) reconstruction_missing("Entity_NPC::Update 006c4b30: the slowed time tint");
bool isTimeImmune = HasEntityFlags(FLAG_FRIENDLY | FLAG_NO_STATUS_EFFECTS) && type != ENTITY_DEATHS_HEAD;
if (isTimeSlowed && !isTimeImmune) SetColor(SLOWED_TIME_COLOR, 2, SLOWED_TIME_COLOR_PRIORITY, false, true);
}
// How much of a per-tick factor is left over a step of timeScale ticks (Math::timescale_factor).
static float timescale_factor(float factor, float timeScale)
// Part of 006c4b30: Broken Modem lets a stalled enemy go, and a moving one skips seven units each way at random, kept
// in the room when it was in it.
void Entity_NPC::modem_release()
{
return timeScale == 1 ? factor : factor / ((factor + timeScale) - factor * timeScale);
constexpr float MODEM_SKIP_STEP = 14;
constexpr float MODEM_SKIP_OFFSET = 21;
Entity& head = *GetStatusEffectTarget();
head.ClearEntityFlags(FLAG_FREEZE);
head.CopyStatusEffects();
if (vector_is_zero(velocity)) return;
float skipX = (float)(Random() % 2 + 1) * MODEM_SKIP_STEP - MODEM_SKIP_OFFSET;
float skipY = (float)(Random() % 2 + 1) * MODEM_SKIP_STEP - MODEM_SKIP_OFFSET;
Room& room = *g_game->room;
Vector clamped = room.GetClampedPosition(pos, 0);
bool isInRoom = clamped.x == pos.x && clamped.y == pos.y;
pos = vector_add(pos, vector_make(skipX, skipY));
if (isInRoom) pos = room.GetClampedPosition(pos, 0);
}
// Part of 006c4b30: a poof02 event puffs half-faded smoke at the NPC, placed and sized (a third) by the null of that
@@ -1929,8 +1971,9 @@ void Entity_NPC::ResetColor()
{
if (isChampion)
{
bool isChampionSheet = std::ranges::any_of(sprite.layerStates, [](const LayerState& layer)
{ return layer.bitflags & LAYER_CHAMPION_SHEET; });
bool isChampionSheet = std::ranges::any_of(sprite.layerStates, [](const LayerState& layer) {
return layer.bitflags & ANIM_RENDER_COLOROFFSET_CHAMPION;
});
if (championColorIdx >= 0 && championColorIdx < CHAMPION_COUNT)
sprite.color = isChampionSheet ? champion_look_get(championColorIdx).spriteColor
: champion_sprite_color_get(championColorIdx);
@@ -2196,9 +2239,9 @@ static void fan_velocities_add(std::vector<Vector>& shots, Vector velocity, floa
}
// 006cb2e0 Shoots projectiles of params' variant from a position in a mode's spread, then applies params to each:
// the fans also fall at once and take on part of its motion unless params keeps their fall.
void Entity_NPC::FireProjectiles(const Vector& position, const Vector& velocity, ProjectilesMode mode,
const ProjectileParams& params)
// the fans also fall at once and take on part of its motion unless params keeps their fall. The first shot, if any.
Entity_Projectile* Entity_NPC::fire_projectiles(const Vector& position, const Vector& velocity, ProjectilesMode mode,
const ProjectileParams& params)
{
std::vector<Vector> shots;
float speed = velocity.x;
@@ -2287,6 +2330,14 @@ void Entity_NPC::FireProjectiles(const Vector& position, const Vector& velocity,
}
for (Entity_Projectile* projectile : projectiles) projectile_params_apply(*projectile, params);
for (Entity_Projectile* projectile : projectiles) fire_projectile_from_params(projectile);
return projectiles.empty() ? nullptr : projectiles.front();
}
// FireProjectiles as the AIs call it, the shot left unused.
void Entity_NPC::FireProjectiles(const Vector& position, const Vector& velocity, ProjectilesMode mode,
const ProjectileParams& params)
{
fire_projectiles(position, velocity, mode, params);
}
// Part of 006cb2e0: what params set on a shot fired.
@@ -2600,33 +2651,96 @@ void Entity_NPC::hold_set(int countdown, const Vector& position)
holdPosition = position;
}
// 006d8260 Whether the controlling player holds an action, never without one.
bool Entity_NPC::IsControllerActionPressed(int)
// 009562d0 How far an action is pushed on a controller, or on the first device pushing it for -1, through the key
// configs. In a run a mod may answer first through MC_INPUT_ACTION. Netplay's remote devices are offline.
float input_action_value_get(ButtonAction action, int controllerIndex, Entity* entity)
{
if (controllerID == -1) return false;
reconstruction_missing("Entity_NPC::IsControllerActionPressed 006d8260");
if (g_manager->state == MANAGER_STATE_GAME && g_luaEngine)
if (std::optional<float> modValue = lua_engine_get().InputActionValue(entity, action)) return *modValue;
KAGE::Input::Manager& input = KAGE::Input::manager;
for (int i = 0; i < input.get_device_count(); i++)
{
std::shared_ptr<KAGE::Input::InputDevice> device = input.get_device(i);
if (!device || !device->isConnected || (controllerIndex != -1 && device->id != controllerIndex)) continue;
float value = 0;
for (int button : g_manager->keyConfigs.binding_get(*device, action))
if (button != KAGE::Input::BUTTON_NONE) value = std::max(value, device->button_value(button));
if (value != 0) return value;
}
return 0;
}
// The controlling player's movement actions (or its shooting ones) as a vector, read left, right, up, then down.
static Vector controller_axes_get(Entity_NPC& npc, ButtonAction leftAction)
{
float left = input_action_value_get(leftAction, npc.controllerID, &npc);
float right = input_action_value_get((ButtonAction)(leftAction + 1), npc.controllerID, &npc);
float up = input_action_value_get((ButtonAction)(leftAction + 2), npc.controllerID, &npc);
float down = input_action_value_get((ButtonAction)(leftAction + 3), npc.controllerID, &npc);
return vector_make(right - left, down - up);
}
// Finishes a controlling player's input: snapped to its main axis under the axis aligned seed, none below the
// deadzone, at most 1 long, and mirrored in the mirror world.
static Vector controller_input_finish(Vector input, float deadzone)
{
Game& game = *g_game;
if (game.seedEffects.HasSeedEffect(SEED_AXIS_ALIGNED_CONTROLS))
input = vector_scale(vector_cardinal(input), vector_length(input));
float length = vector_length(input);
if (deadzone > 0 && length < deadzone) return {};
if (length > 1) input = vector_make(input.x / length, input.y / length);
bool isAltStage = game.stageType == STAGETYPE_REPENTANCE || game.stageType == STAGETYPE_REPENTANCE_B;
bool isMirrored = game.stage == 2 || (game.stage == 1 && (game.GetCurses() & CURSE_OF_LABYRINTH));
if (game.currentDimensionIdx == 1 && isAltStage && isMirrored) input.x = -input.x;
return input;
}
// 006d8260 Whether the controlling player holds an action, never without one.
bool Entity_NPC::IsControllerActionPressed(int action)
{
return controllerID != -1 && input_is_action_pressed((ButtonAction)action, controllerID, this);
}
// 006d8290 Whether the controlling player pressed an action this frame, never without one.
bool Entity_NPC::IsControllerActionTriggered(int buttonAction)
{
if (controllerID == -1) return false;
(void)buttonAction;
reconstruction_missing("Entity_NPC::IsControllerActionTriggered 006d8290");
return controllerID != -1 && input_is_action_triggered((ButtonAction)buttonAction, controllerID, this);
}
// 006d82d0 The controlling player's shooting input, none without one.
Vector Entity_NPC::GetControllerInput(float)
// 006d82d0 The controlling player's walking input (its shooting one when the controls are swapped), reversed by the
// reversed controls seed. None without a player or below the deadzone.
Vector Entity_NPC::GetControllerInput(float deadzone)
{
if (controllerID == -1) return {};
reconstruction_missing("Entity_NPC::GetControllerInput 006d82d0");
Vector input = controller_axes_get(*this, isControlSwapped ? ACTION_SHOOT_LEFT : ACTION_LEFT);
if (g_game->seedEffects.HasSeedEffect(SEED_CONTROLS_REVERSED)) input = vector_make(-input.x, -input.y);
return controller_input_finish(input, deadzone);
}
// 006d85a0 The controlling player's movement input, none without one.
Vector Entity_NPC::GetControllerMovementInput(float)
// 006d85a0 The controlling player's shooting input (its walking one when the controls are swapped), or its walking
// input under the seeds that shoot with movement, reversed by the reversed controls seed. None without a player or
// below the deadzone.
Vector Entity_NPC::GetControllerMovementInput(float deadzone)
{
if (controllerID == -1) return {};
reconstruction_missing("Entity_NPC::GetControllerMovementInput 006d85a0");
Seeds& seeds = g_game->seedEffects;
Vector input{};
if (seeds.HasSeedEffect(SEED_SHOOT_IN_MOVEMENT_DIRECTION)) input = GetControllerInput(0);
else if (seeds.HasSeedEffect(SEED_SHOOT_OPPOSITE_MOVEMENT_DIRECTION))
input = vector_scale(GetControllerInput(0), -1);
else
{
input = controller_axes_get(*this, isControlSwapped ? ACTION_LEFT : ACTION_SHOOT_LEFT);
if (seeds.HasSeedEffect(SEED_CONTROLS_REVERSED)) input = vector_make(-input.x, -input.y);
}
return controller_input_finish(input, deadzone);
}
// 006d9050 Keeps the controlling player's last movement, or none without one.
@@ -2826,9 +2940,3 @@ void Entity_NPC::UpdatePickupGhosts()
if (pickupGhostsEntity) pickupGhostsEntity->Remove();
}
// 009a8b90
void Entity_NPC::render_debug(float*, int)
{
reconstruction_missing("Entity_NPC::render_debug 009a8b90");
}