Curation round 9: floors and walls, room transitions, collision, the first enemies, saving, damage, pickups
Seven agents took over the backdrop's floor and wall rendering, room transitions (StartRoomTransition, on_leave, room_enter), grid collision with tear hits and decal baking, Entity_NPC's core with the AI dispatch and the first enemies (flies, Gaper, Pooter, Clotty, Horf, Dip, Spider), the run's save, player damage, PlayerManager::Update, ShowName, pickups, slots and the common effects. Integration added LuaEngine::PostNewLevel/PostNewRoom, one shared lua_callback_check (4 copies merged) and the enemy type range the original checks. Under gdb a run draws its rooms with floors and walls, walks between rooms, fights Gapers with contact damage and the damage flash, and collects pickups. Next: tears hitting enemies, pathfinding, item pedestals, death. 2891 functions taken over. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
69a354f843
commit
48933cd312
59 files changed
+13387
-6056
No files matched your search
+235
-9
@@ -1,10 +1,13 @@
|
||||
#include "entity_effect.h"
|
||||
#include "entity_list.h"
|
||||
#include "entity_player.h"
|
||||
#include "entity_tear.h"
|
||||
#include "game.h"
|
||||
#include "log.h"
|
||||
#include "lua_engine.h"
|
||||
#include "manager.h"
|
||||
#include "room.h"
|
||||
#include "room_config.h"
|
||||
#include "sfx_manager.h"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
@@ -28,11 +31,56 @@ constexpr int EFFECT_TIMER = 119;
|
||||
constexpr int EFFECT_ENEMY_SOUL = 179;
|
||||
constexpr int EFFECT_ANIMA_CHAIN = 193;
|
||||
constexpr int EFFECT_REDEMPTION = 185;
|
||||
constexpr int EFFECT_BLOOD_EXPLOSION = 2;
|
||||
constexpr int EFFECT_POOF01 = 15;
|
||||
constexpr int EFFECT_POOF02 = 16;
|
||||
constexpr int EFFECT_TINY_FLY = 33;
|
||||
|
||||
// The variants whose Init, Update and Render are reconstructed: the tear poofs and the blood stains.
|
||||
constexpr std::array<int, 8> EFFECT_RECONSTRUCTED_VARIANTS = {
|
||||
// The variants whose Init, Update and Render are reconstructed: the tear poofs, the blood stains, the poofs and the
|
||||
// ambient tiny fly.
|
||||
constexpr std::array<int, 11> EFFECT_RECONSTRUCTED_VARIANTS = {
|
||||
EFFECT_BLOOD_SPLAT, EFFECT_BULLET_POOF, EFFECT_TEAR_POOF_A, EFFECT_TEAR_POOF_B,
|
||||
EFFECT_RIPPLE_POOF, EFFECT_TEAR_POOF_SMALL, EFFECT_TEAR_POOF_VERYSMALL, EFFECT_IMPACT};
|
||||
EFFECT_RIPPLE_POOF, EFFECT_TEAR_POOF_SMALL, EFFECT_TEAR_POOF_VERYSMALL, EFFECT_IMPACT,
|
||||
EFFECT_POOF01, EFFECT_POOF02, EFFECT_TINY_FLY};
|
||||
|
||||
// The animations a poof plays by its subtype: POOF01 from 1 to 3, POOF02's lava splash at random.
|
||||
constexpr std::array<const char*, 4> POOF01_ANIMATIONS = {"Poof2", "Poof_Small", "Poof", "Poof_Large"};
|
||||
constexpr std::array<const char*, 3> LAVA_SPLASH_ANIMATIONS = {"Poof0", "Poof1", "Poof2"};
|
||||
constexpr int POOF01_SUBTYPE_LAST = 3;
|
||||
constexpr int POOF02_LAVA_SPLASH = 66;
|
||||
constexpr int POOF02_LAVA_SPLASH_LARGE = 67;
|
||||
constexpr int POOF_RENDER_Z = 8000;
|
||||
constexpr uint32_t LAVA_SPLASH_SHIFT = 4;
|
||||
|
||||
// The tiny fly: white in the Cathedral, its own color in Dross, how it wanders, flees the nearest player within
|
||||
// range, dies to tears, knives and fires, and drops down in circles when dead.
|
||||
constexpr int STAGE_ID_CATHEDRAL = 15;
|
||||
constexpr int BACKDROP_DROSS = 45;
|
||||
constexpr int ENTITY_KNIFE_TYPE = 8;
|
||||
constexpr int FLY_WANDER_ODDS = 5;
|
||||
constexpr int FLY_JITTER_FRAMES = 5;
|
||||
constexpr float FLY_MASS = 1;
|
||||
constexpr float FLY_FRICTION = 0.98f;
|
||||
constexpr float FLY_DEAD_FRICTION = 0.8f;
|
||||
constexpr float FLY_PULL = 0.5f;
|
||||
constexpr float FLY_JITTER = 0.9f;
|
||||
constexpr float FLY_FLEE_RANGE = 60;
|
||||
constexpr float FLY_FLEE_PUSH = -0.2f;
|
||||
constexpr float FLY_HIT_RADIUS = 0.5f;
|
||||
constexpr float FLY_KNIFE_REACH = 1.5f;
|
||||
constexpr float FLY_FIRE_REACH = 2;
|
||||
constexpr float FLY_FALL_STEP = 0.25f;
|
||||
constexpr float FLY_FALL_HEIGHT = 16;
|
||||
constexpr float FLY_CIRCLE_SPEED = 15;
|
||||
constexpr float FLY_CIRCLE_RADIUS = 3;
|
||||
constexpr float FLY_CLAMP_MARGIN = 2;
|
||||
constexpr float FLY_SPLAT_SCALE = 0.1f;
|
||||
constexpr float FLY_BURST_SCALE = 0.3f;
|
||||
constexpr float FLY_BURST_RISE = -16;
|
||||
constexpr float MIN_DISTANCE = 0.01f;
|
||||
constexpr float RANDOM_UNIT = 2.3283064e-10f;
|
||||
constexpr float RANDOM_HALF_TURN = 3.14f;
|
||||
constexpr float DEGREES_TO_RADIANS = 0.017453292f;
|
||||
// The poofs that turn with their rotation.
|
||||
constexpr std::array<int, 5> EFFECT_TURNED_POOFS = {EFFECT_TEAR_POOF_A, EFFECT_TEAR_POOF_B, EFFECT_TEAR_POOF_SMALL,
|
||||
EFFECT_TEAR_POOF_VERYSMALL, EFFECT_IMPACT};
|
||||
@@ -60,12 +108,6 @@ constexpr int LUA_CALLBACK_POST_EFFECT_INIT = 54;
|
||||
constexpr int LUA_CALLBACK_POST_EFFECT_UPDATE = 55;
|
||||
constexpr int LUA_CALLBACK_POST_EFFECT_RENDER = 56;
|
||||
|
||||
// Stops where a mod has a function for one of the effect's Lua callbacks, which LuaEngine does not run yet.
|
||||
static void lua_callback_check(int callback, const char* name)
|
||||
{
|
||||
if (static_cast<LuaEngine*>(g_luaEngine)->enabledCallbacks[callback]) reconstruction_missing(name);
|
||||
}
|
||||
|
||||
template <size_t N>
|
||||
static bool is_listed(const std::array<int, N>& list, int value)
|
||||
{
|
||||
@@ -158,6 +200,8 @@ void Entity_Effect::Init(int entityType, int entityVariant, int entitySubType, u
|
||||
isUnknown176 = true;
|
||||
}
|
||||
if (variant == EFFECT_IMPACT) sprite.isFlipX = !(Random() & 1);
|
||||
if (variant == EFFECT_POOF01 || variant == EFFECT_POOF02) poof_init();
|
||||
if (variant == EFFECT_TINY_FLY) tiny_fly_init();
|
||||
|
||||
sprite.LoadGraphics();
|
||||
if (g_game->deathmatchManager.is_active())
|
||||
@@ -199,12 +243,194 @@ void Entity_Effect::Update()
|
||||
}
|
||||
|
||||
if (variant == EFFECT_BLOOD_SPLAT) stain_update();
|
||||
else if (variant == EFFECT_TINY_FLY) tiny_fly_update();
|
||||
else poof_update();
|
||||
if (timeout > 0 && --timeout < 1) isDead = true;
|
||||
pausePosition = pos;
|
||||
lua_callback_check(LUA_CALLBACK_POST_EFFECT_UPDATE, "LuaEngine::PostEffectUpdate 00861410");
|
||||
}
|
||||
|
||||
// A poof's animation by its subtype. POOF01 and POOF02's large kinds draw over everything, POOF02's small kinds lie
|
||||
// on the floor outside the crawl space, and its lava splashes face a seeded side.
|
||||
void Entity_Effect::poof_init()
|
||||
{
|
||||
if (variant == EFFECT_POOF01)
|
||||
{
|
||||
if (subtype >= 1 && subtype <= POOF01_SUBTYPE_LAST) sprite.Play(POOF01_ANIMATIONS[subtype]);
|
||||
renderZOffset = POOF_RENDER_Z;
|
||||
return;
|
||||
}
|
||||
|
||||
if (subtype == 1 || subtype == 3)
|
||||
{
|
||||
if (g_game->room->roomType != ROOM_DUNGEON) sortingLayer = SORTING_BACKGROUND;
|
||||
sprite.Play("Poof");
|
||||
}
|
||||
else if (subtype == 2 || subtype == 4 || subtype == 5)
|
||||
{
|
||||
renderZOffset = POOF_RENDER_Z;
|
||||
sprite.Play("Poof");
|
||||
}
|
||||
else if (subtype == POOF02_LAVA_SPLASH || subtype == POOF02_LAVA_SPLASH_LARGE)
|
||||
{
|
||||
RNG rng = rng_make(initSeed, LAVA_SPLASH_SHIFT);
|
||||
uint32_t roll = subtype == POOF02_LAVA_SPLASH ? rng.Next() % LAVA_SPLASH_ANIMATIONS.size() : 0;
|
||||
sprite.Play(subtype == POOF02_LAVA_SPLASH ? LAVA_SPLASH_ANIMATIONS[roll] : "PoofLarge");
|
||||
sprite.isFlipX = !(initSeed & 1);
|
||||
}
|
||||
}
|
||||
|
||||
// A tiny fly: white in the Cathedral, uncolored in Dross, light and colliding with everything.
|
||||
void Entity_Effect::tiny_fly_init()
|
||||
{
|
||||
if (RoomConfig::GetStageID((int)g_game->stage, (int)g_game->stageType, (RoomMode)-1) == STAGE_ID_CATHEDRAL)
|
||||
sprite.Play("White");
|
||||
mass = FLY_MASS;
|
||||
entityCollisionClass = ENTCOLL_ALL;
|
||||
isUnknown176 = true;
|
||||
if (g_game->room->backdropType == BACKDROP_DROSS) sprite.color = COLOR_DEFAULT;
|
||||
}
|
||||
|
||||
// The player nearest a position, the first one on a tie (Game::GetNearestPlayer 00703950, which Game does not
|
||||
// declare yet).
|
||||
static Entity_Player* nearest_player_get(const Vector& position)
|
||||
{
|
||||
Entity_Player* nearest = nullptr;
|
||||
float nearestDistance = 0;
|
||||
|
||||
for (Entity_Player* player : g_game->playerManager.playerList)
|
||||
{
|
||||
float dx = position.x - player->pos.x;
|
||||
float dy = position.y - player->pos.y;
|
||||
float distance = dy * dy + dx * dx;
|
||||
if (nearest && distance >= nearestDistance) continue;
|
||||
nearest = player;
|
||||
nearestDistance = distance;
|
||||
}
|
||||
return nearest;
|
||||
}
|
||||
|
||||
static float random_unit()
|
||||
{
|
||||
return (float)Random() * RANDOM_UNIT;
|
||||
}
|
||||
|
||||
static Vector vector_scaled(Vector v, float scale)
|
||||
{
|
||||
return vector_make(v.x * scale, v.y * scale);
|
||||
}
|
||||
|
||||
static float vector_length(Vector v)
|
||||
{
|
||||
return std::sqrt(v.x * v.x + v.y * v.y);
|
||||
}
|
||||
|
||||
// Whether an entity of the list stands within reach of a position, reach scaled from its size.
|
||||
static bool is_within_reach(Entity& entity, const Vector& position, float reach)
|
||||
{
|
||||
float dx = entity.pos.x - position.x;
|
||||
float dy = entity.pos.y - position.y;
|
||||
return dx * dx + dy * dy < reach * reach;
|
||||
}
|
||||
|
||||
// Bursts the fly into a small splash of its blood color.
|
||||
void Entity_Effect::tiny_fly_burst()
|
||||
{
|
||||
isDead = true;
|
||||
Entity* burst = g_game->Spawn({vector_make(pos.x, pos.y + FLY_BURST_RISE), {}, nullptr, 0, ENTITY_EFFECT,
|
||||
EFFECT_BLOOD_EXPLOSION, Random()});
|
||||
burst->SetColor(splatColor, -1, 255, false, true);
|
||||
burst->sprite.scale = vector_make(FLY_BURST_SCALE, FLY_BURST_SCALE);
|
||||
burst->Update();
|
||||
sprite.Stop();
|
||||
}
|
||||
|
||||
// A tiny fly's frame: alive it drifts at random, now and then toward its parent or the nearest player, and away
|
||||
// from a player close by, and bursts on a tear, knife or fire. Dead, it spirals down and splats. It faces its motion
|
||||
// and stays in the room.
|
||||
void Entity_Effect::tiny_fly_update()
|
||||
{
|
||||
Entity_Player* player = nearest_player_get(pos);
|
||||
Vector toPlayer = vector_make(player->pos.x - pos.x, player->pos.y - pos.y);
|
||||
float distance = vector_length(toPlayer);
|
||||
Vector direction = vector_scaled(toPlayer, 1 / (distance == 0 ? MIN_DISTANCE : distance));
|
||||
EntityList& entities = g_game->room->entityList;
|
||||
|
||||
friction *= FLY_FRICTION;
|
||||
if (isDead)
|
||||
{
|
||||
LayerState& layer = *sprite.GetLayer(0);
|
||||
if (layer.pos.y <= FLY_FALL_HEIGHT)
|
||||
{
|
||||
layer.pos.y += FLY_FALL_STEP;
|
||||
float side = (float)(index % 2) * 2 - 1;
|
||||
float angle = (float)g_game->frameCount * FLY_CIRCLE_SPEED * side * DEGREES_TO_RADIANS;
|
||||
Vector circle = vector_make(std::cos(angle), std::sin(angle));
|
||||
circle = vector_scaled(vector_scaled(circle, std::abs(layer.pos.y) / FLY_FALL_HEIGHT), FLY_CIRCLE_RADIUS);
|
||||
pos = vector_make(pos.x + circle.x, pos.y + circle.y);
|
||||
friction *= FLY_DEAD_FRICTION;
|
||||
}
|
||||
else
|
||||
{
|
||||
Entity* splat = g_game->Spawn({pos, {}, nullptr, 0, ENTITY_EFFECT, EFFECT_BLOOD_SPLAT, Random()});
|
||||
splat->SetColor(splatColor, -1, 255, false, true);
|
||||
splat->sprite.scale = vector_make(FLY_SPLAT_SCALE, FLY_SPLAT_SCALE);
|
||||
splat->Update();
|
||||
Remove();
|
||||
}
|
||||
}
|
||||
|
||||
if (!isDead)
|
||||
{
|
||||
if (Random() % FLY_WANDER_ODDS == 0)
|
||||
{
|
||||
Vector pull = direction;
|
||||
if (parent)
|
||||
{
|
||||
Vector toParent = vector_make(parent->pos.x - pos.x, parent->pos.y - pos.y);
|
||||
float length = vector_length(toParent);
|
||||
if (length > 0) toParent = vector_scaled(toParent, (length - parent->size) / length);
|
||||
float resized = vector_length(toParent);
|
||||
pull = resized > 0 ? vector_scaled(toParent, 1 / resized) : toParent;
|
||||
}
|
||||
AddVelocity_divided(vector_scaled(pull, random_unit() * FLY_PULL), false);
|
||||
}
|
||||
if (IsFrame(FLY_JITTER_FRAMES, (int)index))
|
||||
{
|
||||
float angle = random_unit() * RANDOM_HALF_TURN * 2;
|
||||
Vector jitter = vector_make(std::cos(angle), std::sin(angle));
|
||||
AddVelocity_divided(vector_scaled(jitter, random_unit() * FLY_JITTER), false);
|
||||
}
|
||||
if (distance < FLY_FLEE_RANGE)
|
||||
{
|
||||
float push = (1 - distance * distance / (FLY_FLEE_RANGE * FLY_FLEE_RANGE)) * FLY_FLEE_PUSH;
|
||||
AddVelocity_divided(vector_scaled(direction, push), false);
|
||||
}
|
||||
|
||||
EntityList_EL shots;
|
||||
entities.partitions[PARTITION_SHOTS].query_box(shots, pos, vector_make(FLY_HIT_RADIUS, FLY_HIT_RADIUS));
|
||||
bool isShot = std::any_of(shots.begin(), shots.end(), [this](Entity* shot) {
|
||||
return !shot->HasEntityFlags(FLAG_INTERPOLATION_UPDATE) && shot->type == ENTITY_TEAR &&
|
||||
is_within_reach(*shot, pos, FLY_HIT_RADIUS + shot->size);
|
||||
});
|
||||
if (isShot) tiny_fly_burst();
|
||||
|
||||
std::vector<Entity*> hazards(entities.updateEL);
|
||||
for (Entity* hazard : hazards)
|
||||
{
|
||||
bool isKnife =
|
||||
hazard->type == ENTITY_KNIFE_TYPE && is_within_reach(*hazard, pos, hazard->size * FLY_KNIFE_REACH);
|
||||
bool isFire =
|
||||
hazard->type == ENTITY_FIREPLACE && is_within_reach(*hazard, pos, hazard->size + FLY_FIRE_REACH);
|
||||
if (isKnife || isFire) tiny_fly_burst();
|
||||
}
|
||||
}
|
||||
|
||||
sprite.isFlipX = pos.x - targetPosition.x < 0;
|
||||
pos = g_game->room->GetClampedPosition(pos, FLY_CLAMP_MARGIN);
|
||||
targetPosition = pos;
|
||||
}
|
||||
|
||||
// Turns a poof by its rotation, mirrored unless flipped, and removes it once its animation ends. A ripple first
|
||||
// draws its small sizes larger with their own animations.
|
||||
void Entity_Effect::poof_update()
|
||||
|
||||
Reference in new issue
Block a user