diff --git a/generated-src/classes.h b/generated-src/classes.h index 54b2d37..2221354 100644 --- a/generated-src/classes.h +++ b/generated-src/classes.h @@ -6273,7 +6273,6 @@ uint32_t * FUN_007df0b0(uint32_t *param_1); // 007df0b0 void FUN_007df130(); // 007df130 void FUN_007df140(uint32_t *param_1); // 007df140 void FUN_007df1d0(); // 007df1d0 -void FUN_007df1e0(); // 007df1e0 void FUN_007e2630(); // 007e2630 void FUN_007e2740(); // 007e2740 void FUN_007e27a0(char *param_1, char *param_2); // 007e27a0 diff --git a/generated-src/stubs.cpp b/generated-src/stubs.cpp index b0c51ed..dd5da9f 100644 --- a/generated-src/stubs.cpp +++ b/generated-src/stubs.cpp @@ -10368,7 +10368,6 @@ uint32_t * FUN_007df0b0(uint32_t *param_1) { generated_stub("FUN_007df0b0 007df0 void FUN_007df130() { generated_stub("FUN_007df130 007df130"); } void FUN_007df140(uint32_t *param_1) { generated_stub("FUN_007df140 007df140"); } void FUN_007df1d0() { generated_stub("FUN_007df1d0 007df1d0"); } -void FUN_007df1e0() { generated_stub("FUN_007df1e0 007df1e0"); } void FUN_007e2630() { generated_stub("FUN_007e2630 007e2630"); } void FUN_007e2740() { generated_stub("FUN_007e2740 007e2740"); } void FUN_007e27a0(char *param_1, char *param_2) { generated_stub("FUN_007e27a0 007e27a0"); } diff --git a/src/anm2.h b/src/anm2.h index d99ce34..f199379 100644 --- a/src/anm2.h +++ b/src/anm2.h @@ -218,6 +218,24 @@ inline float timescale_factor(float factor, float timeScale) return timeScale == 1 ? factor : factor / ((factor + timeScale) - factor * timeScale); } +// pow 004e4690 (and pow_wrapper 00505b40): a float power taken in double precision and narrowed back. +inline float pow_float(float base, float exponent) +{ + return (float)std::pow((double)base, (double)exponent); +} + +// log_precise 006dac30: a float natural log taken in double precision and narrowed back. +inline float log_float(float value) +{ + return (float)std::log((double)value); +} + +// 007df1e0 A float exponential taken in double precision and narrowed back. +inline float exp_float(float value) +{ + return (float)std::exp((double)value); +} + // A value's place in one range carried onto another (assert_lerp_range's arguments), held inside it when clamped. struct LerpRange { diff --git a/src/boss_ai.h b/src/boss_ai.h index d147982..5fe5028 100644 --- a/src/boss_ai.h +++ b/src/boss_ai.h @@ -9,14 +9,14 @@ constexpr float BOSS_BLOOD_DEPTH = 10; -// EntityList::QuerySublist uncached: the updated entities of a type (and variant unless -1) a query may see. -inline std::vector entity_query(int type, int variant) +// EntityList::QuerySublist uncached: the updated entities of a type (and variant and subtype unless -1) a query may see. +inline std::vector entity_query(int type, int variant, int subType = -1) { std::vector found; for (Entity* entity : g_game->room->entityList.updateEL) if (entity->type == type && (variant < 0 || entity->variant == variant) && - !entity->HasEntityFlags(FLAG_NO_QUERY)) + (subType < 0 || entity->subtype == subType) && !entity->HasEntityFlags(FLAG_NO_QUERY)) found.push_back(entity); return found; } diff --git a/src/boss_big_horn.cpp b/src/boss_big_horn.cpp index 4e8050f..07a164c 100644 --- a/src/boss_big_horn.cpp +++ b/src/boss_big_horn.cpp @@ -1120,13 +1120,16 @@ void boss_big_horn_update(Entity_NPC& npc) big_hole_update(npc, isBusy); if (!npc.parent) return; } - else if (npc.state == NPC_STATE_INIT) + else if (npc.variant == 0) { - npc.sprite.Play("Appear"); - npc.state = HORN_REST; - return; + if (npc.state == NPC_STATE_INIT) + { + npc.sprite.Play("Appear"); + npc.state = HORN_REST; + return; + } + big_horn_head_update(npc, ticks, isBusy); } - else big_horn_head_update(npc, ticks, isBusy); if (npc.variant != BIG_HORN_HAND || npc.state != HAND_SLAP || npc.stateFrame < 1) npc.friction = 0; } diff --git a/src/boss_brownie.cpp b/src/boss_brownie.cpp index 14e83d2..d4640bf 100644 --- a/src/boss_brownie.cpp +++ b/src/boss_brownie.cpp @@ -412,8 +412,8 @@ static void brownie_volley(Entity_NPC& npc, BrownieFrame& frame) { Vector aim = vector_normalized(vector_sub(npc.GetPlayerTarget()->pos, npc.pos)); Vector scatter = random_direction(); - float reach = random_unit() * BROWNIE_VOLLEY_SCATTER; - aim = vector_add(aim, vector_scale(scatter, reach)); + float reach = random_unit(); + aim = vector_add(vector_scale(vector_scale(scatter, reach), BROWNIE_VOLLEY_SCATTER), aim); npc.FireProjectiles(npc.pos, vector_scale(aim, BROWNIE_VOLLEY_SPEED), PROJECTILES_SINGLE, brownie_shot_params(npc)); npc.v2.x *= BROWNIE_VOLLEY_SLOWDOWN; } @@ -461,8 +461,8 @@ static void brownie_steer(Entity_NPC& npc, BrownieFrame& frame) if (npc.state == BROWNIE_FAST_CHASE) npc.v2.x *= 0.5f; } float speed = npc.v2.x; - Vector pulled = vector_add(npc.velocity, vector_scale(vector_normalized(toward), speed * BROWNIE_STEER)); - pulled = vector_add(pulled, vector_scale(vector_normalized(npc.velocity), speed * BROWNIE_STEER)); + Vector pulled = vector_add(vector_scale(vector_scale(vector_normalized(toward), speed), BROWNIE_STEER), npc.velocity); + pulled = vector_add(vector_scale(vector_scale(vector_normalized(npc.velocity), speed), BROWNIE_STEER), pulled); Vector wanted = vector_resized(pulled, speed); float keep = timescale_factor(BROWNIE_STEER_KEEP, npc.speedMultiplier); npc.velocity = vector_add(vector_scale(vector_sub(wanted, npc.velocity), 1 - keep), npc.velocity); @@ -474,8 +474,8 @@ static void brownie_steer(Entity_NPC& npc, BrownieFrame& frame) { uint32_t seed = Random(); Vector around = random_direction(); - float reach = random_unit() * npc.size; - Vector spot = vector_add(npc.pos, vector_scale(around, reach)); + float reach = random_unit(); + Vector spot = vector_add(vector_scale(vector_scale(around, reach), npc.size), npc.pos); auto* mine = static_cast( g_game->Spawn({.position = spot, .spawner = &npc, .type = ENTITY_CORN_MINE, .seed = seed})); mine->SetBossColorIdx(npc.bosscoloridx, 0); diff --git a/src/boss_bumbino.cpp b/src/boss_bumbino.cpp index c2da70b..1a4d4db 100644 --- a/src/boss_bumbino.cpp +++ b/src/boss_bumbino.cpp @@ -174,13 +174,21 @@ constexpr float CELL_HALF_STEP = 0.5f; // Its leaving: an item from its list where items spawn, in a poof. constexpr float BUMBINO_LEAVE_FRICTION = 0.5f; +// How a trail cloud's drift adds to its share of Bumbino's speed: the swipe adds it twice in turn, the ram doubled. +enum TrailSum +{ + TRAIL_SWIPE, + TRAIL_RAM +}; + // A cloud of its trail behind it, every 2 frames. -static void bumbino_trail_spawn(Entity_NPC& npc) +static void bumbino_trail_spawn(Entity_NPC& npc, TrailSum sum) { if (!npc.GetIntervalTicks(DUST_EVERY, 0)) return; uint32_t seed = Random(); Vector drift = random_direction(); - Vector velocity = vector_add(vector_scale(npc.velocity, DUST_TRAIL_SHARE), vector_add(drift, drift)); + Vector trail = vector_scale(npc.velocity, DUST_TRAIL_SHARE); + Vector velocity = sum == TRAIL_SWIPE ? vector_add(vector_add(trail, drift), drift) : vector_add(vector_add(drift, drift), trail); auto* cloud = static_cast(g_game->Spawn( {.position = npc.pos, .velocity = velocity, .spawner = &npc, .type = ENTITY_EFFECT, .variant = EFFECT_DUST_CLOUD, .seed = seed})); cloud->rotation = random_between(DUST_SPIN_MIN, DUST_SPIN_RANGE); @@ -419,7 +427,7 @@ static bool bumbino_swipe_update(Entity_NPC& npc, bool& isWallImpact) bool isLunging = false; if (!vector_is_zero(npc.v1)) { - bumbino_trail_spawn(npc); + bumbino_trail_spawn(npc, TRAIL_SWIPE); npc.AddVelocity_divided(npc.v1, false); npc.v1 = vector_scale(npc.v1, timescale_factor(SWIPE_DRAG, npc.speedMultiplier)); if (std::abs(npc.v1.x) < SWIPE_STILL) npc.v1 = {}; @@ -520,7 +528,7 @@ static bool bumbino_ram_update(Entity_NPC& npc, bool& isWallImpact) return false; } if (npc.stateFrame != 1) return false; - bumbino_trail_spawn(npc); + bumbino_trail_spawn(npc, TRAIL_RAM); npc.AddVelocity_divided(npc.v1, false); isWallImpact = npc.isCollidesWithGrid; return true; diff --git a/src/boss_cage.cpp b/src/boss_cage.cpp index 2bedc1e..4dfa504 100644 --- a/src/boss_cage.cpp +++ b/src/boss_cage.cpp @@ -115,7 +115,10 @@ constexpr float CAGE_LASER_QUARTER = 90; constexpr float CAGE_LASER_DEPTH_UP = -10; constexpr float CAGE_LASER_DEPTH = 3000; +// The green Cage's creep every 30 frames: drawn 2.5 times as big, at 0.75 of its effect scale. constexpr int CAGE_CREEP_FRAMES = 30; +constexpr float CAGE_GREEN_CREEP_SIZE = 2.5f; +constexpr float CAGE_GREEN_CREEP_SCALE = 0.75f; // Starts an animation with its cry, unless it already shows. static void cage_anim_start(Entity_NPC& npc, std::string_view anim, int sound) @@ -452,11 +455,16 @@ void boss_cage_update(Entity_NPC& npc) bool isCreepFrame = (g_game->frameCount + npc.index) % CAGE_CREEP_FRAMES == 0; if (npc.subtype == CAGE_GREEN && !npc.HasEntityFlags(FLAG_INTERPOLATION_UPDATE) && !g_game->IsPaused() && isCreepFrame) - g_game->Spawn({.position = npc.pos, - .spawner = &npc, - .type = ENTITY_EFFECT, - .variant = EFFECT_CREEP_GREEN, - .seed = Random()}); + { + auto* creep = static_cast(g_game->Spawn({.position = npc.pos, + .spawner = &npc, + .type = ENTITY_EFFECT, + .variant = EFFECT_CREEP_GREEN, + .seed = Random()})); + creep->sprite.scale = vector_make(CAGE_GREEN_CREEP_SIZE, CAGE_GREEN_CREEP_SIZE); + creep->scale = CAGE_GREEN_CREEP_SCALE; + creep->Update(); + } if (npc.isDead) npc_sound_play(SOUND_CAGE_DEATH, 1, 2, 1); npc.friction *= CAGE_FRICTION; } diff --git a/src/boss_chimera.cpp b/src/boss_chimera.cpp index b6f04a0..3cac5d8 100644 --- a/src/boss_chimera.cpp +++ b/src/boss_chimera.cpp @@ -590,8 +590,12 @@ static void chimera_spit_fly_update(Entity_NPC& npc) if (npc.sprite.IsEventTriggered("Shoot")) { npc.PlaySound(SOUND_LITTLE_SPIT, 1, 2, false, 1); - auto* fly = static_cast( - g_game->Spawn({.position = npc.pos, .spawner = &npc, .type = ENTITY_BOOMFLY, .variant = DRAGON_FLY, .seed = Random()})); + auto* fly = static_cast(g_game->Spawn({.position = npc.pos, + .velocity = holdOffset, + .spawner = &npc, + .type = ENTITY_BOOMFLY, + .variant = DRAGON_FLY, + .seed = Random()})); fly->ClearEntityFlags(FLAG_APPEAR); fly->sprite.scale = vector_make(FLY_SCALE, FLY_SCALE); fly->entityCollisionClass = ENTCOLL_NONE; @@ -600,7 +604,7 @@ static void chimera_spit_fly_update(Entity_NPC& npc) fly->posOffset = vector_make(0, FLY_RAISE); fly->targetPosition = vector_add(npc.pos, holdOffset); npc.child = fly; - Entity* splat = blood_explosion_spawn(SPLAT_SUBTYPE, npc.pos, {}, CHIMERA_GREEN_COLOR, {}); + Entity* splat = blood_explosion_spawn(SPLAT_SUBTYPE, npc.pos, vector_make(0, HEAD_SPLAT_RAISE), CHIMERA_GREEN_COLOR, {}); static_cast(splat)->FollowParent(&npc); } if (Entity* fly = npc.child.get()) fly->targetPosition = vector_add(npc.pos, holdOffset); @@ -629,14 +633,15 @@ static void chimera_spray_fire(Entity_NPC& npc, float progress) float lead = vector_distance(npc.pos, target->pos) * (progress * CHIMERA_SPRAY_LEAD + 0); Vector aim = vector_sub(vector_add(target->pos, vector_scale(target->velocity, lead)), npc.pos); Vector landing = vector_add(vector_rotated(aim, progress * SPRAY_SWEEP - SPRAY_SWEEP_HALF), npc.pos); - Vector velocity = vector_scale(vector_sub(landing, npc.pos), 1 / (progress * CHIMERA_SPRAY_FRAMES + SPRAY_MIN_FRAMES)); + float frames = progress * CHIMERA_SPRAY_FRAMES + SPRAY_MIN_FRAMES; + Vector velocity = vector_div(vector_sub(landing, npc.pos), vector_make(frames, frames)); float speed = vector_length(velocity); if (speed > SPRAY_MAX_SPEED && speed > 0) velocity = vector_scale(velocity, SPRAY_MAX_SPEED / speed); auto* shot = static_cast(g_game->Spawn( {.position = npc.pos, .velocity = velocity, .spawner = &npc, .type = ENTITY_PROJECTILE, .seed = Random()})); float flight = vector_distance(npc.pos, landing) / vector_length(velocity); - float decay = (float)std::pow((double)SPRAY_DRAG, (double)flight); + float decay = pow_float(SPRAY_DRAG, flight); float drag = std::max((decay - 1) * SPRAY_DRAG_SUM, SPRAY_DRAG_MIN); shot->fallingAccel = SPRAY_ACCEL; shot->scale = CHIMERA_SPRAY_SCALE; @@ -797,7 +802,7 @@ static void chimera_head_catch(Entity_NPC& npc) auto* headNpc = static_cast(head); bool isCaught = npc.variant == CHIMERA_BODY && collider->type == ENTITY_CHIMERA && collider->variant == CHIMERA_HEAD && - head && chimera_body_is_waiting(npc) && headNpc->state == CHIMERA_HEAD_CHARGE && head_flag(*headNpc, HEAD_TO_BODY); + collider == head && head && chimera_body_is_waiting(npc) && headNpc->state == CHIMERA_HEAD_CHARGE && head_flag(*headNpc, HEAD_TO_BODY); if (isCaught) { npc.state = CHIMERA_THROW; @@ -922,8 +927,9 @@ static void chimera_head_rest_update(Entity_NPC& npc) return; } - Vector landing = npc.CalcTargetPosition(0); - if (!npc.HasEntityFlags(HEAD_PATH_BLOCK_FLAGS) && !room_check_line(npc.pos, target, LINE_MODE_GROUND, 0)) + Vector landing; + if (npc.HasEntityFlags(HEAD_PATH_BLOCK_FLAGS) || room_check_line(npc.pos, target, LINE_MODE_GROUND, 0)) landing = npc.CalcTargetPosition(0); + else { Vector position = npc.pos; Vector velocity = npc.velocity; @@ -1065,8 +1071,10 @@ static void chimera_head_motion_update(Entity_NPC& npc) if (vector_length(npc.targetPosition) < HEAD_STOPPED) npc.targetPosition = {}; if (head_flag(npc, HEAD_THROWN) && (Random() & HEAD_TRAIL_MASK) == 0) { + ProjectileParams params; Vector behind = vector_sub(npc.pos, vector_scale(npc.velocity, HEAD_TRAIL_BACK)); - npc.FireBossProjectiles((int)(Random() & 1) + 1, behind, 0, ProjectileParams()); + int count = (int)(Random() & 1) + 1; + npc.FireBossProjectiles(count, behind, 0, params); } if (Random() % HEAD_CREEP_ODDS != 0) return; Entity* creep = g_game->Spawn( diff --git a/src/boss_clog.cpp b/src/boss_clog.cpp index cd3fbea..7b63400 100644 --- a/src/boss_clog.cpp +++ b/src/boss_clog.cpp @@ -99,7 +99,9 @@ static void clog_spit(Entity_NPC& npc) uint32_t seed = Random(); auto* drip = static_cast(g_game->Spawn( {.position = vector_add(npc.pos, vector_scale(heading, CLOG_SPIT_REACH)), .spawner = &npc, .type = ENTITY_DRIP, .seed = seed})); - npc_push(*drip, vector_scale(heading, random_unit() * CLOG_SPIT_SPEED_RANGE + CLOG_SPIT_SPEED)); + float speed = random_unit() * CLOG_SPIT_SPEED_RANGE + CLOG_SPIT_SPEED; + if (drip->friction != 0) + drip->velocity = vector_add(vector_div(vector_scale(heading, drip->speedMultiplier * speed), vector_make(drip->friction, drip->friction)), drip->velocity); drip->ClearEntityFlags(FLAG_APPEAR); drip->state = DRIP_FLUNG; drip->Update(); @@ -153,7 +155,7 @@ static void clog_spin_update(Entity_NPC& npc) npc.sprite.Play(npc.i1 == 0 ? "SpinLoop" : "SpinLoop2"); npc.stateFrame++; if (npc.stateFrame == SPIN_WATER_SOUND_FRAME) - g_manager->sfxManager.Play(SOUND_BOSS2_WATERTHRASHING, {.frameDelay = SPIN_WATER_DELAY}); + npc_sound_play(SOUND_BOSS2_WATERTHRASHING, 1, SPIN_WATER_DELAY, 1); Vector fromCenter = vector_sub(npc.pos, Room::GetCenterPos()); if (vector_length(fromCenter) > SPIN_CENTER_SLACK) diff --git a/src/boss_clutch.cpp b/src/boss_clutch.cpp index 0fdf7bd..d319f92 100644 --- a/src/boss_clutch.cpp +++ b/src/boss_clutch.cpp @@ -387,9 +387,12 @@ static void clutch_stunned_update(Entity_NPC& npc) if (npc.stateFrame == 0) { npc.stateFrame = 1; - for (Entity_NPC* clack : clutch_clacks_get(npc)) + for (Entity* other : Entity_NPC::QueryNPCsType(ENTITY_CLICKETY_CLACK, -1)) { - if (clack->state != CLACK_PILE || clack->i2 != CLACK_FLAME) continue; + auto* clack = static_cast(other); + if (!Entity::is_enemy_type(clack->type) || clack->parent.get() != &npc || clack->state != CLACK_PILE || + clack->i2 != CLACK_FLAME) + continue; clack->i2 = 0; clack->sprite.Play("Collapse"); if (clack->sprite.animState.animData) clack->sprite.animState.AdvancePosition(clack->sprite.animState.animData->length - 1); @@ -592,7 +595,7 @@ static void clutch_trail_update(Entity_NPC& npc) Vector side = vector_rotated(npc.velocity, RIGHT_ANGLE_DEGREES); float swing = std::sin(npc.updateTime * PI_F * TRAIL_SWING_RATE); anchor = vector_add(anchor, vector_scale(side, swing)); - drift = vector_scale(side, TRAIL_SWING_SHARE * swing); + drift = vector_scale(vector_scale(side, TRAIL_SWING_SHARE), swing); } const NullFrame* null = npc.sprite.animState.animData ? npc.sprite.animState.GetNullFrame("Trail") : nullptr; @@ -606,15 +609,17 @@ static void clutch_trail_update(Entity_NPC& npc) position = vector_add(position, vector_scale(velocity, step)); velocity = vector_scale(velocity, timescale_factor(size.x * TRAIL_SIZE_DRAG + TRAIL_DRAG, step)); Vector shake = random_direction(); - float strength = size.x * random_unit() * TRAIL_SHAKE * step; - velocity = vector_add(velocity, vector_scale(shake, strength)); + float strength = random_unit(); + velocity.x += size.x * shake.x * strength * TRAIL_SHAKE * step; + velocity.y += size.x * shake.y * strength * TRAIL_SHAKE * step; size.x = std::max(size.x - step * CLUTCH_TRAIL_SHRINK, 0.0f); float distance = vector_distance(anchor, position); if (distance > TRAIL_REACH) { float kept = timescale_factor(TRAIL_PULL, step) * (distance - TRAIL_REACH) + TRAIL_REACH; - position = vector_add(anchor, vector_scale(vector_sub(position, anchor), kept / distance)); + position = vector_add(anchor, vector_div(vector_scale(vector_sub(position, anchor), kept), + vector_make(distance, distance))); } if (size.x > 0 || isInterpolated) i += TRAIL_POINT; else trail.erase(trail.begin() + (long)i, trail.begin() + (long)(i + TRAIL_POINT)); diff --git a/src/boss_colostomia.cpp b/src/boss_colostomia.cpp index de33494..299142e 100644 --- a/src/boss_colostomia.cpp +++ b/src/boss_colostomia.cpp @@ -180,7 +180,7 @@ static Vector colostomia_pick_target(Entity_NPC& npc, bool& isPlayer) { Room& room = *g_game->room; std::array clouds{}; - for (Entity* cloud : entity_query(ENTITY_EFFECT, EFFECT_SMOKE_CLOUD)) + for (Entity* cloud : entity_query(ENTITY_EFFECT, EFFECT_SMOKE_CLOUD, COLO_CLOUD_SUBTYPE)) for (Vector cover : COLO_CLOUD_COVER) { int index = room.GetGridIndex(vector_add(cloud->pos, cover)); @@ -397,7 +397,7 @@ static void colostomia_dive_update(Entity_NPC& npc) { npc.friction *= COLO_LEAP_FRICTION; npc.v2.x = std::clamp(npc.speedMultiplier * COLO_LEAP_PULL + npc.v2.x, 0.0f, 1.0f); - npc.velocity = vector_scale(vector_sub(npc.v1, npc.pos), npc.v2.x / npc.friction); + npc.velocity = vector_div(vector_scale(vector_sub(npc.v1, npc.pos), npc.v2.x), vector_make(npc.friction, npc.friction)); } if (npc.sprite.IsEventTriggered("Land")) { @@ -433,7 +433,7 @@ static void colostomia_charge_splash(Entity_NPC& npc) angle += angle; Vector reach = vector_make(std::cos(angle) * COLO_DROP_REACH_X, std::sin(angle) * COLO_DROP_REACH_Y); float speed = random_unit() * COLO_DROP_SPEED_RANGE + COLO_DROP_SPEED; - Vector velocity = vector_scale(reach, speed / COLO_DROP_REACH_X); + Vector velocity = vector_div(vector_scale(reach, speed), vector_make(COLO_DROP_REACH_X, COLO_DROP_REACH_X)); auto* drop = static_cast(g_game->Spawn({.position = vector_add(reach, npc.pos), .velocity = velocity, .subType = COLO_DROP_SUBTYPE, @@ -515,7 +515,7 @@ static void colostomia_charge_update(Entity_NPC& npc, float& frictionScale) if (npc.sprite.IsPlaying()) return; npc.state = COLO_IDLE; uint32_t odds = Random(); - size_t clouds = entity_query(ENTITY_EFFECT, EFFECT_SMOKE_CLOUD).size(); + size_t clouds = entity_query(ENTITY_EFFECT, EFFECT_SMOKE_CLOUD, COLO_CLOUD_SUBTYPE).size(); npc.projectileCooldown = 1; if (odds % COLO_SPIT_ODDS + COLO_SPIT_CLOUDS <= clouds) npc.i2 = 1; return; diff --git a/src/boss_death.cpp b/src/boss_death.cpp index 185d888..cb07712 100644 --- a/src/boss_death.cpp +++ b/src/boss_death.cpp @@ -49,7 +49,6 @@ constexpr int EFFECT_POOF04 = 17; constexpr int EFFECT_BLOOD_GUSH = 42; constexpr int COLLECTIBLE_FOREVER_ALONE = 128; -constexpr int NULL_ITEM_SOL = 56; constexpr int GIANTBOOK_SOL = 5; constexpr int BOMB_TROLL_SUBTYPE = 3; constexpr std::array HORNFEL_ITEMS = {256, 220, 19, 137, 646}; @@ -367,7 +366,7 @@ static void sol_trigger(Room& room, uint32_t seed) Entity_Player* player = game.GetPlayer((int)i); player->SetFullHearts(); player->FullCharge(-1, false, false); - ItemConfig_Item* sol = g_manager->itemConfig.GetNullItem(NULL_ITEM_SOL); + ItemConfig_Item* sol = g_manager->itemConfig.GetNullItem(NULLITEM_SOL); if (player->HasCollectible(COLLECTIBLE_SOL) && sol) player->temporaryEffects.AddEffect(TemporaryEffect(sol), true, 1); } @@ -697,7 +696,7 @@ void Entity_NPC::update_blood_guide_gibs(const NullFrame& guide) if (GetIntervalTicks(GUIDE_SHAKE_INTERVAL, 0)) game_shake_screen(GUIDE_SHAKE_FRAMES); if (GetIntervalTicks(GUIDE_GIB_INTERVAL, 0)) { - Vector offset = vector_scale(guideSpot(GUIDE_REACH), 1 / GUIDE_PERSPECTIVE); + Vector offset = vector_div(guideSpot(GUIDE_REACH), vector_make(GUIDE_PERSPECTIVE, GUIDE_PERSPECTIVE)); gibs_spawn({.color = splatColor, .position = vector_add(pos, offset), .spawner = this, diff --git a/src/boss_dingle.cpp b/src/boss_dingle.cpp index d3df57f..6e0e85d 100644 --- a/src/boss_dingle.cpp +++ b/src/boss_dingle.cpp @@ -47,7 +47,8 @@ constexpr float SLIDE_CREEP_SCALE = 0.75f; constexpr float SLIDE_CREEP_SCALE_SPREAD = 0.25f; constexpr float WALL_SPLAT_REACH = 200; -constexpr float WALL_SPLAT_MARGIN = -24; +constexpr float WALL_SPLAT_SPREAD = 40; +constexpr float WALL_SPLAT_INWARD = -0.6f; constexpr float WALL_SPLAT_SIZE = 1; constexpr float WALL_SPLAT_SIZE_SPREAD = 2; constexpr float WALL_SPLAT_TURN = 90; @@ -151,7 +152,7 @@ static void slide_wall_hit(Entity_NPC& npc) npc.targetPosition = room.GetRandomPosition(0); npc.PlaySound(SOUND_MEAT_JUMPS, 1, 2, false, 1); - float margin = random_unit() * WALL_SPLAT_MARGIN; + float margin = random_unit() * WALL_SPLAT_SPREAD * WALL_SPLAT_INWARD; Vector behind = vector_add(npc.pos, vector_scale(npc.gridCollisionNormal, WALL_SPLAT_REACH)); Vector spot = room.GetClampedPositionImpl(behind, margin, margin, margin, margin); GridEntity* wall = room_grid_entity_at(spot); @@ -182,9 +183,7 @@ static void dingle_slide(Entity_NPC& npc) npc.friction *= DINGLE_SLIDE_FRICTION; if (npc.sprite.WasEventTriggered("Slide")) { - Vector push = vector_resized(npc.velocity, npc.subtype == DINGLE_SPIDERS ? SPIDERS_SLIDE_PUSH : SLIDE_PUSH); - if (npc.friction != 0) - npc.velocity = vector_add(npc.velocity, vector_scale(push, npc.speedMultiplier / npc.friction)); + npc_push(npc, vector_resized(npc.velocity, npc.subtype == DINGLE_SPIDERS ? SPIDERS_SLIDE_PUSH : SLIDE_PUSH)); if (npc.variant == DANGLE) dangle_trail(npc); } npc.sprite.isFlipX = npc.velocity.x > 0; @@ -257,8 +256,7 @@ static void dangle_dip_spawn(Entity_NPC& npc) Vector spot = vector_add(vector_add(vector_scale(scatter, spread), vector_scale(aim, DANGLE_DIP_AHEAD)), npc.pos); auto* dip = static_cast(g_game->Spawn( {.position = spot, .spawner = &npc, .type = ENTITY_DIP, .variant = CORNY_DIP, .seed = seed})); - if (dip->friction != 0) - dip->velocity = vector_add(dip->velocity, vector_scale(aim, DANGLE_DIP_KICK * dip->speedMultiplier / dip->friction)); + npc_push(*dip, vector_scale(aim, DANGLE_DIP_KICK)); dip->ClearEntityFlags(FLAG_APPEAR); dip->Update(); dip->state = NPC_STATE_MOVE; diff --git a/src/boss_duke.cpp b/src/boss_duke.cpp index 2277463..35a6f9a 100644 --- a/src/boss_duke.cpp +++ b/src/boss_duke.cpp @@ -202,12 +202,11 @@ static void duke_burst(Entity_NPC& npc, const std::vector& group) } for (Entity* tinyFly : entity_query(ENTITY_EFFECT, EFFECT_TINY_FLY)) push_away(npc, *tinyFly, TINY_FLY_PUSH); - ProjectileParams params; if (npc.variant == HUSK) npc.FireProjectiles(vector_make(npc.pos.x, npc.pos.y - HUSK_RING_HEIGHT), - vector_make(HUSK_RING_SPEED, DUKE_RING_SHOTS), PROJECTILES_RING, params); + vector_make(HUSK_RING_SPEED, DUKE_RING_SHOTS), PROJECTILES_RING, ProjectileParams()); else if (npc.subtype == DUKE_MOTERS) - npc.FireProjectiles(npc.pos, vector_make(MOTER_RING_SPEED, DUKE_RING_SHOTS), PROJECTILES_RING, params); + npc.FireProjectiles(npc.pos, vector_make(MOTER_RING_SPEED, DUKE_RING_SHOTS), PROJECTILES_RING, ProjectileParams()); } // An attack fly coughed up into its group, at a spot below its mouth. @@ -324,14 +323,12 @@ static void death_fly_spawn(Entity_NPC& npc, RNG& rng, int kind, int variant) // flies for the boom Husks, red for the red one). static void duke_death(Entity_NPC& npc) { - uint32_t tinyFlies = 0; - do + for (uint32_t tinyFlies = 0; tinyFlies < Random() % DEATH_TINY_FLIES + DEATH_TINY_FLIES_MIN; tinyFlies++) { uint32_t seed = Random(); Vector spot = scatter_spot(npc.pos, DEATH_TINY_FLY_SCATTER); g_game->Spawn({.position = spot, .spawner = &npc, .type = ENTITY_EFFECT, .variant = EFFECT_TINY_FLY, .seed = seed}); - tinyFlies++; - } while (tinyFlies < Random() % DEATH_TINY_FLIES + DEATH_TINY_FLIES_MIN); + } RNG rng = {npc.initSeed, 5, 9, 7}; if (npc.variant != HUSK) diff --git a/src/boss_fallen.cpp b/src/boss_fallen.cpp index b56c8cc..6046cb1 100644 --- a/src/boss_fallen.cpp +++ b/src/boss_fallen.cpp @@ -119,7 +119,6 @@ static void beams_start(Entity_NPC& npc) 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. @@ -176,6 +175,7 @@ static void shots_update(Entity_NPC& npc) return; } beams_start(npc); + npc.v1.x = 0; } // The charge: it chases its target, growling after a while, until hurt enough, then fires its cross. @@ -193,7 +193,11 @@ static void charge_update(Entity_NPC& npc) 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)); + Vector heading = vector_normalized(toAim); + if (npc.friction != 0) + npc.velocity = vector_add(vector_div(vector_scale(vector_scale(heading, npc.speedMultiplier), CHARGE_ACCEL), + vector_make(npc.friction, npc.friction)), + npc.velocity); npc.v1.x += npc.pendingDamage; npc.sprite.isFlipX = toAim.x < 0; if (npc.v1.x <= npc.maxHitPoints * CHARGE_HURT_SHARE) return; @@ -225,7 +229,7 @@ static void beams_update(Entity_NPC& npc) } 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.velocity = vector_add(vector_scale(vector_scale(npc.targetPosition, npc.v1.y), npc.speedMultiplier), npc.velocity); npc.v1.y = std::max(npc.v1.y - npc.speedMultiplier * DRIFT_DECAY, 0.0f); } npc.stateFrame++; @@ -239,8 +243,8 @@ static void beams_update(Entity_NPC& npc) 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)); + Vector from = isSpin ? npc.pos : vector_make(std::cos(angle * DEGREES_TO_RADIANS) * BEAM_OUT + npc.pos.x, + std::sin(angle * DEGREES_TO_RADIANS) * BEAM_OUT + (npc.pos.y - FALLEN_BEAM_RISE)); Entity_Laser* laser = Entity_Laser::ShootAngle({.position = from, .posOffset = vector_make(0, -FALLEN_BEAM_RISE), .source = &npc, diff --git a/src/boss_famine.cpp b/src/boss_famine.cpp index 9a33c3e..0fc21f2 100644 --- a/src/boss_famine.cpp +++ b/src/boss_famine.cpp @@ -12,7 +12,6 @@ constexpr int FAMINE_DASH = NPC_STATE_ATTACK; constexpr int FAMINE_HEAD = NPC_STATE_ATTACK2; constexpr int FAMINE_SUMMON = NPC_STATE_SUMMON; -constexpr uint64_t FAMINE_DISTRACTED = FLAG_CONFUSION | FLAG_FEAR | FLAG_SHRINK; constexpr float FAMINE_CEILING = 170; constexpr float FAMINE_FRICTION = 0.8f; constexpr float FAMINE_HEAD_HEALTH = 0.33f; @@ -113,7 +112,7 @@ static void famine_float(Entity_NPC& npc, Vector toTarget) bool isInLine = std::abs(toTarget.y) < FAMINE_DASH_LINE || (npc.subtype == FAMINE_BLUE && Random() % FAMINE_BLUE_DASH_ODDS == 0); - if (!isInLine || Random() % FAMINE_DASH_ODDS != 0 || npc.HasEntityFlags(FAMINE_DISTRACTED)) return; + if (!isInLine || Random() % FAMINE_DASH_ODDS != 0 || npc.HasEntityFlags(FLAG_DISTRACTED)) return; npc.PlaySound(SOUND_MONSTER_YELL_A, 1, 2, false, 1); npc.sprite.isFlipX = toTarget.x < 0; diff --git a/src/boss_fistula.cpp b/src/boss_fistula.cpp index 4b41e21..1ca4952 100644 --- a/src/boss_fistula.cpp +++ b/src/boss_fistula.cpp @@ -190,7 +190,7 @@ static void fistula_split(Entity_NPC& npc) fistula_piece_spawn(npc, ENTITY_FISTULA_MEDIUM, vector_make(c + npc.pos.x, s + npc.pos.y), spread); fistula_piece_spawn(npc, ENTITY_FISTULA_MEDIUM, vector_make(npc.pos.x - c, npc.pos.y - s), back); if (npc.subtype == FISTULA_GREY || npc.variant == TERATOMA) - fistula_piece_spawn(npc, ENTITY_FISTULA_MEDIUM, vector_make(c + npc.pos.x, npc.pos.y - s), {}); + fistula_piece_spawn(npc, ENTITY_FISTULA_MEDIUM, vector_make(c + npc.pos.x, npc.pos.y - s), vector_make(0, 0)); else { fistula_piece_spawn(npc, ENTITY_FISTULA_MEDIUM, vector_make(c + npc.pos.x, npc.pos.y - s), diff --git a/src/boss_forsaken.cpp b/src/boss_forsaken.cpp index aced322..61b272e 100644 --- a/src/boss_forsaken.cpp +++ b/src/boss_forsaken.cpp @@ -46,11 +46,15 @@ constexpr int DEATHS_HEADS = 2; constexpr int DEATHS_HEAD_RED = 1; constexpr int MINIONS_FOR_BLAST = 3; -// The fade: it waits faded until its minions are gone or a player touches it, drifts to the room's center for at -// most 120 frames, and fades back in. +// The fade: it waits faded until its minions are gone or a player touches it, drifts to the room's center (an L +// room's inner corner cell) for at most 120 frames, and fades back in. constexpr float DRIFT_PUSH = 1.2f; constexpr float DRIFT_MAX_SPEED = 3.2f; constexpr int DRIFT_FRAMES = 120; +constexpr int L_ROOM_LBL_CENTER = 132; +constexpr int L_ROOM_LBR_CENTER = 119; +constexpr int L_ROOM_LTL_CENTER = 328; +constexpr int L_ROOM_LTR_CENTER = 315; constexpr float DRIFT_ARRIVE = 45; // The lasers: three (and the first again) from its hands 120 apart, turned a random 30 either way from its target's @@ -103,6 +107,24 @@ static int minion_type_get(const Entity_NPC& npc) return npc.subtype == FORSAKEN_BLACK ? ENTITY_BLACK_BONY : ENTITY_BONY; } +// Where it drifts while faded: the room's center, or the cell by an L room's inner corner. +static Vector forsaken_drift_center() +{ + Room& room = *g_game->room; + switch (room.GetRoomShape()) + { + case ROOMSHAPE_LBL: + return room.GetGridPosition(L_ROOM_LBL_CENTER); + case ROOMSHAPE_LBR: + return room.GetGridPosition(L_ROOM_LBR_CENTER); + case ROOMSHAPE_LTL: + return room.GetGridPosition(L_ROOM_LTL_CENTER); + case ROOMSHAPE_LTR: + return room.GetGridPosition(L_ROOM_LTR_CENTER); + } + return Room::GetCenterPos(); +} + static void fade_start(Entity_NPC& npc) { npc.stateFrame = 0; @@ -218,8 +240,13 @@ static void forsaken_fade(Entity_NPC& npc, const ForsakenCount& count) case FADE_DRIFT: { anim_keep(npc, "Faded"); - Vector center = Room::GetCenterPos(); - npc_push(npc, vector_scale(vector_normalized(vector_sub(center, npc.pos)), DRIFT_PUSH)); + Vector center = forsaken_drift_center(); + Vector toward = vector_normalized(vector_sub(center, npc.pos)); + if (npc.friction != 0) + { + npc.velocity.y = (npc.speedMultiplier * toward.y * DRIFT_PUSH) / npc.friction + npc.velocity.y; + npc.velocity.x = (npc.speedMultiplier * toward.x * DRIFT_PUSH) / npc.friction + npc.velocity.x; + } if (vector_length(npc.velocity) > DRIFT_MAX_SPEED) npc.velocity = vector_resized(npc.velocity, DRIFT_MAX_SPEED); if (npc.stateFrame <= DRIFT_FRAMES && vector_length(vector_sub(npc.pos, center)) >= DRIFT_ARRIVE) return; diff --git a/src/boss_gate.cpp b/src/boss_gate.cpp index 5fb57d1..6ade117 100644 --- a/src/boss_gate.cpp +++ b/src/boss_gate.cpp @@ -30,7 +30,6 @@ enum GatePattern GATE_PATTERN_HOMING }; -constexpr uint64_t GATE_DISTRACTED = FLAG_CONFUSION | FLAG_FEAR | FLAG_SHRINK; constexpr float GATE_LIFT = 40; constexpr float GATE_FRICTION = 0.8f; constexpr float GATE_HURT_HEALTH = 0.3f; @@ -129,7 +128,7 @@ static void gate_idle(Entity_NPC& npc) npc.i1 = GATE_CHARGING; } else if (npc.subtype != GATE_BLACK && enemies > GATE_LASER_CROWD && npc.IsFrame(period, 0) && - random_below(GATE_LASER_ODDS / enemies) == 0 && !npc.HasEntityFlags(GATE_DISTRACTED)) + random_below(GATE_LASER_ODDS / enemies) == 0 && !npc.HasEntityFlags(FLAG_DISTRACTED)) { npc.state = GATE_LASER; npc.i1 = GATE_CHARGING; diff --git a/src/boss_gurdy.cpp b/src/boss_gurdy.cpp index 08549c8..07c852e 100644 --- a/src/boss_gurdy.cpp +++ b/src/boss_gurdy.cpp @@ -96,11 +96,7 @@ static void gurdy_players_place(Entity_NPC& npc) // What it spawned: a Delirium form's dying boils die with it, and the rest are shoved away from it. static void gurdy_spawn_shove(Entity_NPC& npc) { - std::vector spawned; - for (Entity* entity : g_game->room->entityList.updateEL) - if (entity->spawnerType == npc.type) spawned.push_back(entity); - - for (Entity* entity : spawned) + for (Entity* entity : npc_query_spawner_type(npc.type, 0, SPAWNER_QUERY_ALL)) { auto* other = dynamic_cast(entity); if (!other || other == &npc) continue; diff --git a/src/boss_gurdy_jr.cpp b/src/boss_gurdy_jr.cpp index 17ca03e..4f13675 100644 --- a/src/boss_gurdy_jr.cpp +++ b/src/boss_gurdy_jr.cpp @@ -30,7 +30,6 @@ enum GurdyJrOrder GURDY_JR_ORDER_SUMMON }; -constexpr uint64_t GURDY_JR_DISTRACTED = FLAG_CONFUSION | FLAG_FEAR | FLAG_SHRINK; constexpr float GURDY_JR_FRICTION = 0.8f; constexpr float GURDY_JR_SLIDE_FRICTION = 0.97f; constexpr float GURDY_JR_SLIDE_START_FRICTION = 0.7f; @@ -89,7 +88,7 @@ static void gurdy_jr_idle(Entity_NPC& npc) int order = GURDY_JR_ORDER_NONE; if (npc.controllerID != -1) { - if (!npc.HasEntityFlags(GURDY_JR_DISTRACTED)) npc.SpawnControlTarget(0, -1); + if (!npc.HasEntityFlags(FLAG_DISTRACTED)) npc.SpawnControlTarget(0, -1); if (npc.is_controller_input_idle() && vector_length_squared(vector_sub(npc.pos, npc.GetAimTargetPosition())) > GURDY_JR_AIM_REACH_SQUARED) order = GURDY_JR_ORDER_SLIDE; @@ -129,7 +128,7 @@ static void gurdy_jr_idle(Entity_NPC& npc) npc.stateFrame = 0; return npc.ClearChild(); } - if (npc.HasEntityFlags(GURDY_JR_DISTRACTED)) return; + if (npc.HasEntityFlags(FLAG_DISTRACTED)) return; npc.state = GURDY_JR_SLIDE; npc.i2 = GURDY_JR_SLIDE_PUSH; @@ -150,10 +149,10 @@ static void gurdy_jr_idle(Entity_NPC& npc) // every five frames. static void gurdy_jr_slide(Entity_NPC& npc) { - if (npc_anim_is_done(npc) || npc.HasEntityFlags(GURDY_JR_DISTRACTED)) + if (npc_anim_is_done(npc) || npc.HasEntityFlags(FLAG_DISTRACTED)) { if (npc.i2 == GURDY_JR_SLIDE_PUSH) npc.i2 = GURDY_JR_SLIDE_GLIDE; - else if (npc.i2 == GURDY_JR_SLIDE_END) npc.state = NPC_STATE_IDLE; + else if (npc.i2 != GURDY_JR_SLIDE_GLIDE) npc.state = NPC_STATE_IDLE; else if (vector_length_squared(npc.velocity) <= GURDY_JR_SLIDE_STOP_SQUARED || npc.i1++ > GURDY_JR_SLIDE_FRAMES) { npc.i2 = GURDY_JR_SLIDE_END; @@ -290,5 +289,5 @@ void boss_gurdy_jr_update(Entity_NPC& npc) break; } if (npc.controllerID == -1 || steer <= 0) return; - npc.velocity = vector_add(npc.velocity, vector_scale(npc.GetControllerInput(0), steer * npc.speedMultiplier)); + npc.velocity = vector_add(vector_scale(vector_scale(npc.GetControllerInput(0), steer), npc.speedMultiplier), npc.velocity); } diff --git a/src/boss_headless_horseman.cpp b/src/boss_headless_horseman.cpp index efedd24..9ff3f3c 100644 --- a/src/boss_headless_horseman.cpp +++ b/src/boss_headless_horseman.cpp @@ -9,7 +9,6 @@ constexpr int HORSEMAN_ATTACK = NPC_STATE_ATTACK; constexpr int HEAD_CHARGE = NPC_STATE_ATTACK; constexpr int HEAD_SHOOT = NPC_STATE_ATTACK2; -constexpr uint64_t HORSEMAN_DISTRACTED = FLAG_CONFUSION | FLAG_FEAR | FLAG_SHRINK; constexpr float HORSEMAN_FRICTION = 0.8f; constexpr int HORSEMAN_ATTACK_FRAMES = 31; @@ -95,7 +94,7 @@ static void head_float(Entity_NPC& npc) } bool isCharge = Random() % HEAD_CHARGE_ODDS == 0 || (std::abs(toTarget.y) < HEAD_LINE_BAND && Random() % HEAD_LINE_CHARGE_ODDS == 0); - if (!isCharge || npc.HasEntityFlags(HORSEMAN_DISTRACTED)) return; + if (!isCharge || npc.HasEntityFlags(FLAG_DISTRACTED)) return; npc.PlaySound(SOUND_MONSTER_YELL_A, 1, 2, false, 1); npc.sprite.isFlipX = toTarget.x < 0; diff --git a/src/boss_heretic.cpp b/src/boss_heretic.cpp index ad60cb4..67420c3 100644 --- a/src/boss_heretic.cpp +++ b/src/boss_heretic.cpp @@ -704,7 +704,7 @@ static LobArc lob_arc_solve(Entity_Projectile& shot, float distance) for (int i = 0; i < LOB_TRIES; i++) { float time = distance / arc.speed; - float decay = (float)std::pow((double)LOB_DRAG, (double)time); + float decay = pow_float(LOB_DRAG, time); float drag = std::max((decay - 1) * LOB_DRAG_SCALE, LOB_TIME_MIN); arc.fallingSpeed = (lift - (time - drag) * accel) / drag; bool isPast = diff --git a/src/boss_lil_blub.cpp b/src/boss_lil_blub.cpp index 7a87fe7..05ad79d 100644 --- a/src/boss_lil_blub.cpp +++ b/src/boss_lil_blub.cpp @@ -412,6 +412,7 @@ void boss_lil_blub_update(Entity_NPC& npc) npc.targetPosition = {}; npc.splatColor = blub_is_sewage() ? SEWAGE_SPLASH_COLOR : WATER_SPLASH_COLOR; npc.projectileDelay = 0; + npc.stateFrame = 0; break; case BLUB_REST: blub_rest_update(npc, leeches, isHurt); diff --git a/src/boss_loki.cpp b/src/boss_loki.cpp index 17de7de..898da66 100644 --- a/src/boss_loki.cpp +++ b/src/boss_loki.cpp @@ -34,16 +34,6 @@ constexpr float LOKI_SHOT_SPEED = 12; constexpr int BLOOD_EXPLOSION_SMALL = 3; constexpr float LOKI_FRICTION = 0.8f; -// The cell a spot lies in, or -1 off the grid. -static int cell_get(const Vector& spot) -{ - 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) return -1; - return row * room.gridWidth + column; -} - // The first frame: Loki waits, and the first Lokii of a pair hides its twin. static void loki_init(Entity_NPC& npc) { @@ -116,7 +106,7 @@ static void loki_teleport(Entity_NPC& npc) Room& room = *g_game->room; for (int i = TELEPORT_TRIES - 1; i >= 0; i--) { - int cell = cell_get(room.GetRandomPosition(TELEPORT_MARGIN)); + int cell = room.GetGridIndex(room.GetRandomPosition(TELEPORT_MARGIN)); Vector spot = vector_make((float)(cell % room.gridWidth) * GRID_CELL_SIZE + GRID_ORIGIN_X, (float)(cell / room.gridWidth) * GRID_CELL_SIZE + GRID_ORIGIN_Y); Vector away = vector_sub(spot, game_nearest_player(spot)->pos); diff --git a/src/boss_mask_of_infamy.cpp b/src/boss_mask_of_infamy.cpp index aadd995..0fd8759 100644 --- a/src/boss_mask_of_infamy.cpp +++ b/src/boss_mask_of_infamy.cpp @@ -153,14 +153,14 @@ static void mask_heart_check(Entity_NPC& npc) npc.state = MASK_ANGRY; } -// Each time its heart is hurt it may lunge away from the target, one time in 2. -static void mask_lunge_check(Entity_NPC& npc) +// Each time its heart is hurt it may lunge away from the target, one time in 2, unless a player steers it. +static void mask_lunge_check(Entity_NPC& npc, bool isControlled) { if (npc.type != ENTITY_MASK_OF_INFAMY || npc.state == MASK_ANGRY || !npc.parent) return; if (npc.v2.x == npc.parent->health) return; npc.v2.x = npc.parent->health; - if ((Random() & 1) != 0) return; + if ((Random() & 1) != 0 || isControlled) return; Vector delta = mask_target_delta(npc, mask_cell_center(npc.pos)); npc.targetPosition = vector_scale(mask_axis_away(delta), MASK_LUNGE_PUSH); npc.i1 = MASK_DASH_LUNGE; @@ -283,7 +283,7 @@ void boss_mask_of_infamy_update(Entity_NPC& npc) Entity_NPC* controller = mask_controller_get(npc); if (npc.state == NPC_STATE_INIT) return mask_init(npc); mask_heart_check(npc); - mask_lunge_check(npc); + mask_lunge_check(npc, controller != nullptr); mask_face(npc); Vector cell = mask_cell_center(npc.pos); diff --git a/src/boss_pool.cpp b/src/boss_pool.cpp index 6de4453..49a1170 100644 --- a/src/boss_pool.cpp +++ b/src/boss_pool.cpp @@ -333,6 +333,7 @@ static BossPool_Entry* boss_after_find(BossPool& bossPool, BossPool_Pool& pool, // win (weighted, allowed, not met this run or floor). Else roll moves through that entry's share, up to nine times, // then the next boss around the pool that can be picked does. The pick joins the floor's blacklist. Null for an empty // or weightless pool, or when nothing can be picked. +// The original crashes on a roll past every entry's share. Here that finds nothing. BossPool_Entry* BossPool::PickBoss(BossPool_Pool& pool, float roll) { BossPool_Entry* picked = nullptr; diff --git a/src/boss_rag_man.cpp b/src/boss_rag_man.cpp index d3e0b8c..0140b26 100644 --- a/src/boss_rag_man.cpp +++ b/src/boss_rag_man.cpp @@ -398,8 +398,9 @@ static void rag_man_rebirth(Entity_NPC& npc, const std::vector& ragling npc_sound_play(SOUND_RAGMAN_2, 1, 2, 1); if (npc.subtype == RAG_MAN_SPIDERS) { + ProjectileParams params; Vector aim = game_random_player(*g_game, npc.pos, RAG_MAN_FAR)->pos; - npc.FireBossProjectiles(RAG_MAN_REVIVE_SHOTS, aim, RAG_MAN_REVIVE_SHOT_CURVE, ProjectileParams()); + npc.FireBossProjectiles(RAG_MAN_REVIVE_SHOTS, aim, RAG_MAN_REVIVE_SHOT_CURVE, params); } else for (Entity* ragling : raglings) @@ -545,8 +546,8 @@ static void rag_man_head_update(Entity_NPC& npc) float speed = HEAD_FAST_SPEED - slowdown * HEAD_SLOWDOWN; Vector toTarget = vector_normalized(vector_sub(npc.CalcTargetPosition(0), npc.pos)); Vector heading = vector_normalized(npc.velocity); - Vector steer = vector_add(vector_add(vector_scale(toTarget, speed * HEAD_STEER), npc.velocity), - vector_scale(heading, speed * HEAD_STEER)); + Vector steer = vector_make(speed * toTarget.x * HEAD_STEER + npc.velocity.x + speed * heading.x * HEAD_STEER, + speed * toTarget.y * HEAD_STEER + npc.velocity.y + speed * heading.y * HEAD_STEER); steer = vector_resized(steer, speed); float keep = timescale_factor(RAG_MAN_FRICTION, npc.speedMultiplier); npc.velocity = vector_add(vector_scale(vector_sub(steer, npc.velocity), 1 - keep), npc.velocity); @@ -655,8 +656,10 @@ static void mega_ball_trail(Entity_NPC& npc) smoke->velocity = vector_scale(npc.velocity, BALL_TRAIL_BACK); float angle = random_unit() * PI_ROUGH; angle += angle; - float scatter = random_unit() * vector_length(npc.velocity) * BALL_TRAIL_SCATTER; - npc_push(*smoke, vector_make(std::cos(angle) * scatter, std::sin(angle) * scatter)); + float scatter = random_unit(); + float speed = vector_length(npc.velocity); + npc_push(*smoke, vector_make(std::cos(angle) * scatter * speed * BALL_TRAIL_SCATTER, + std::sin(angle) * scatter * speed * BALL_TRAIL_SCATTER)); smoke->posOffset = vector_make(0, BALL_HEIGHT); } @@ -700,10 +703,10 @@ static void mega_pillar_update(Entity_NPC& npc) static void mega_drift(Entity_NPC& npc) { Room& room = *g_game->room; - Vector clamped = room.GetClampedPositionImpl(npc.pos, MEGA_WALL_MARGIN, 0, 0, 0); - npc.pos.y = clamped.y; - if (clamped.x == room.bottomRightPos.x) npc.velocity.x = -1; - if (clamped.x == room.topLeftPos.x) npc.velocity.x = 1; + npc.entityGridCollisionClass = GRIDCOLL_WALLS; + npc.pos = room.GetClampedPositionImpl(npc.pos, MEGA_WALL_MARGIN, 0, 0, 0); + if (npc.pos.x == room.bottomRightPos.x) npc.velocity.x = -1; + if (npc.pos.x == room.topLeftPos.x) npc.velocity.x = 1; if (npc.pos.y == room.bottomRightPos.y) npc.velocity.y = -1; if (npc.pos.y == room.topLeftPos.y + MEGA_WALL_MARGIN) npc.velocity.y = 1; diff --git a/src/boss_raglich.cpp b/src/boss_raglich.cpp index 8bd8d94..ed6e764 100644 --- a/src/boss_raglich.cpp +++ b/src/boss_raglich.cpp @@ -167,8 +167,8 @@ static void raglich_pick_target_pos(Entity_NPC& npc, float speed) Vector side = vector_from_direction(direction_turn(raglich_direction_get(npc), turn)); Vector facing = vector_from_direction(raglich_direction_get(npc)); Vector offEdge = vector_scale(facing, vector_dot(vector_sub(npc.pos, npc.targetPosition), facing)); - npc.velocity = vector_add(npc.velocity, vector_scale(vector_sub(vector_scale(side, speed), vector_scale(offEdge, WALK_EDGE_PULL)), - npc.v1.y * npc.speedMultiplier)); + npc.velocity.x = (side.x * speed - offEdge.x * WALK_EDGE_PULL) * npc.v1.y * npc.speedMultiplier + npc.velocity.x; + npc.velocity.y = (side.y * speed - offEdge.y * WALK_EDGE_PULL) * npc.v1.y * npc.speedMultiplier + npc.velocity.y; Vector clamped = room.GetClampedPositionImpl(vector_sub(npc.pos, offEdge), WALK_MARGIN, WALK_MARGIN, WALK_MARGIN, WALK_MARGIN); Vector ahead = vector_add(clamped, vector_scale(side, GRID_CELL_SIZE)); if (!room.IsPositionInRoom(ahead, 0)) @@ -215,9 +215,11 @@ static void raglich_slam_spawn_grid(Entity_NPC& arm) arm.PlaySound(SOUND_HELLBOSS_GROUNDPOUND, 1, 2, false, 1); game_shake_screen(ARM_SHAKE); } + // The original adds the left blast's offset to his position before the hit's. Vector slam = vector_add(arm.pos, hit); - for (float offset : {0.0f, -GRID_CELL_SIZE, GRID_CELL_SIZE}) - explosion_damage({.position = vector_add(slam, vector_make(offset, 0)), + Vector left = vector_make(hit.x + (arm.pos.x - GRID_CELL_SIZE), slam.y); + for (Vector blast : {slam, left, vector_make(slam.x + GRID_CELL_SIZE, slam.y)}) + explosion_damage({.position = blast, .source = &arm, .damageFlags = DAMAGE_CRUSH, .damage = ARM_BLAST_DAMAGE, @@ -369,6 +371,13 @@ static void raglich_dash_end(Entity_NPC& npc) npc.projectileCooldown = RAGLICH_DASH_COOLDOWN; } +// The dash's push along its axis at its speed. +static void raglich_dash_push(Entity_NPC& npc, Vector axis) +{ + npc.velocity.x = axis.x * npc.v1.y * npc.speedMultiplier + npc.velocity.x; + npc.velocity.y = axis.y * npc.v1.y * npc.speedMultiplier + npc.velocity.y; +} + // The dash across the room: building from 18 down to 8, heading for the far wall, then turning to walk back along it. // The alternate dash turns down into a slide that fires blue crosses, then dashes on. static bool raglich_dash_update(Entity_NPC& npc) @@ -423,7 +432,7 @@ static bool raglich_dash_update(Entity_NPC& npc) { case 1: { - npc.velocity = vector_add(npc.velocity, vector_scale(axis, npc.v1.y * npc.speedMultiplier)); + raglich_dash_push(npc, axis); npc.v1.y = std::max(npc.v1.y - npc.speedMultiplier * DASH_SLOW, DASH_MIN); bool isPastMiddle = npc.state == RAGLICH_DASH && npc.sprite.GetFrame() <= DASH_LATE_FRAME && vector_dot(vector_sub(npc.pos, Room::GetCenterPos()), axis) > 0; @@ -448,7 +457,7 @@ static bool raglich_dash_update(Entity_NPC& npc) break; } case 3: - npc.velocity = vector_add(npc.velocity, vector_scale(axis, npc.v1.y * npc.speedMultiplier)); + raglich_dash_push(npc, axis); npc.v1.y = std::max(npc.v1.y - 2 * npc.speedMultiplier, DASH_TURN_MIN); if (npc.sprite.IsFinished()) { @@ -457,7 +466,7 @@ static bool raglich_dash_update(Entity_NPC& npc) } break; case 4: - npc.velocity = vector_add(npc.velocity, vector_scale(axis, npc.v1.y * npc.speedMultiplier)); + raglich_dash_push(npc, axis); npc.v1.y = std::max(npc.v1.y - npc.speedMultiplier, DASH_SHOOT_MIN); if (npc.sprite.IsEventTriggered("Shoot")) raglich_fire_shots(npc, SOUND_MONSTER_GRUNT_0, PROJECTILES_CROSS); else if (npc.sprite.IsEventTriggered("Shoot2")) raglich_fire_shots(npc, SOUND_MONSTER_GRUNT_1, PROJECTILES_PLUS); diff --git a/src/boss_reap_creep.cpp b/src/boss_reap_creep.cpp index ba2c6bb..8a33912 100644 --- a/src/boss_reap_creep.cpp +++ b/src/boss_reap_creep.cpp @@ -308,7 +308,7 @@ static void reap_dash(Entity_NPC& npc, ReapFrame& frame) frame.friction = REAP_DASH_FRICTION; } -// The fountain: a minute of shots tossed up every other frame, falling around it, then a rest. +// The fountain: a minute of shots tossed up every other frame, falling around it, then the spray's longer rest. static void reap_fountain(Entity_NPC& npc, ReapFrame& frame) { if (npc.projectileCooldown == 0) @@ -324,7 +324,8 @@ static void reap_fountain(Entity_NPC& npc, ReapFrame& frame) if (npc.projectileCooldown < 1) { frame.strafe = 0; - return reap_rest_when_done(npc); + if (npc_anim_is_done(npc)) reap_rest(npc, REAP_SPRAY_REST_MIN, REAP_SPRAY_REST_RANGE); + return; } if ((npc.projectileCooldown & 1) == 0) @@ -337,8 +338,9 @@ static void reap_fountain(Entity_NPC& npc, ReapFrame& frame) params.scale = REAP_FOUNTAIN_SCALE - size * REAP_FOUNTAIN_SCALE_RANGE; params.fallingSpeedModifier = REAP_FOUNTAIN_FALL; Vector direction = random_direction(); - float reach = random_unit() * REAP_FOUNTAIN_SPREAD; - Vector from = vector_make(reach * direction.x + npc.pos.x, direction.y * reach + npc.pos.y + REAP_FOUNTAIN_DROP); + float reach = random_unit(); + Vector from = vector_make(reach * direction.x * REAP_FOUNTAIN_SPREAD + npc.pos.x, + direction.y * reach * REAP_FOUNTAIN_SPREAD + npc.pos.y + REAP_FOUNTAIN_DROP); npc.FireProjectiles(from, up, PROJECTILES_SINGLE, params); npc.PlaySound(SOUND_TEARS_FIRE, 1, 2, false, 1); } @@ -498,11 +500,11 @@ static Vector reap_wall_spot(Room& room, uint32_t& seed) float along = random_unit(); Vector topLeft = room.topLeftPos; Vector bottomRight = room.bottomRightPos; - if (wall >= REAP_WALL_SIDE_ODDS) - return vector_make((bottomRight.x - REAP_WALL_MARGIN - (topLeft.x + REAP_WALL_MARGIN)) * along + topLeft.x + REAP_WALL_MARGIN, - bottomRight.y); + float first = topLeft.x + REAP_WALL_MARGIN; + if (wall >= REAP_WALL_SIDE_ODDS) return vector_make((bottomRight.x - REAP_WALL_MARGIN - first) * along + first, bottomRight.y); - float y = (bottomRight.y - REAP_WALL_MARGIN - (topLeft.y + REAP_WALL_MARGIN)) * along + topLeft.y + REAP_WALL_MARGIN; + float top = topLeft.y + REAP_WALL_MARGIN; + float y = (bottomRight.y - REAP_WALL_MARGIN - top) * along + top; return vector_make(wall < REAP_WALL_LEFT_ODDS ? topLeft.x : bottomRight.x, y); } @@ -520,12 +522,21 @@ static void reap_wall_creep_summon(Entity_NPC& npc, ReapFrame& frame) npc.PlaySound(SOUND_SUMMONSOUND, 1, 2, false, 1); } -// A free tile at a random angle below it, within reach (beyond a minimum). -static Vector reap_summon_spot(Entity_NPC& npc, float reachMin, float reachRange) +// A free tile at a random angle below it, within reach: up to 200 for a spider, 100 to 300 for a Trite. +// The original scales a spider's reach after the angle and a Trite's before it. +static Vector reap_summon_spot(Entity_NPC& npc, bool isTrite) { float angle = (random_unit() * REAP_SUMMON_ARC + REAP_SUMMON_ARC_START) * DEGREES_TO_RADIANS; - float reach = random_unit() * reachRange + reachMin; - Vector spot = vector_make(std::cos(angle) * reach + npc.pos.x, std::sin(angle) * reach + npc.pos.y); + float reach = random_unit(); + Vector spot{}; + if (isTrite) + { + reach = reach * REAP_SPIDER_REACH + REAP_TRITE_REACH_MIN; + spot = vector_make(std::cos(angle) * reach + npc.pos.x, std::sin(angle) * reach + npc.pos.y); + } + else + spot = vector_make(std::cos(angle) * reach * REAP_SPIDER_REACH + npc.pos.x, + std::sin(angle) * reach * REAP_SPIDER_REACH + npc.pos.y); return room_free_tile_position_find(spot, REAP_FREE_TILE_REACH); } @@ -538,7 +549,7 @@ static void reap_spider_summon(Entity_NPC& npc, ReapFrame& frame) npc.PlaySound(SOUND_BOSS_SPIT_BLOB_BARF, 1, 2, false, 1); if ((Random() & 1) == 0) for (int i = 0; i < REAP_SUMMON_SPIDERS; i++) - Entity_NPC::ThrowSpider(npc.pos, &npc, reap_summon_spot(npc, 0, REAP_SPIDER_REACH), false, + Entity_NPC::ThrowSpider(npc.pos, &npc, reap_summon_spot(npc, false), false, REAP_SPIDER_HEIGHT); else { @@ -546,7 +557,7 @@ static void reap_spider_summon(Entity_NPC& npc, ReapFrame& frame) .type = ENTITY_HOPPER, .variant = HOPPER_TRITE, .seed = Random()})); - trite->targetPosition = reap_summon_spot(npc, REAP_TRITE_REACH_MIN, REAP_SPIDER_REACH); + trite->targetPosition = reap_summon_spot(npc, true); trite->state = NPC_STATE_MOVE; trite->stateFrame = REAP_TRITE_HOP_FRAME; trite->sprite.Play("Hop", PLAY_FORCED); diff --git a/src/boss_satan.cpp b/src/boss_satan.cpp index fa138f4..46c6ab3 100644 --- a/src/boss_satan.cpp +++ b/src/boss_satan.cpp @@ -347,7 +347,8 @@ static void spread_update(Entity_NPC& npc, Entity& target) 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); + npc.FireProjectiles(npc.pos, vector_scale(vector_normalized(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. diff --git a/src/boss_scourge.cpp b/src/boss_scourge.cpp index 204a1a8..f82093d 100644 --- a/src/boss_scourge.cpp +++ b/src/boss_scourge.cpp @@ -1005,7 +1005,8 @@ static void chain_tip_fly(Entity_NPC& npc, Entity_NPC& head) npc.mass = SCOURGE_TIP_MASS; if (vector_is_zero(npc.targetPosition)) return; - npc.velocity = vector_add(npc.velocity, vector_scale(npc.targetPosition, SCOURGE_TIP_THRUST * npc.speedMultiplier)); + npc.velocity = vector_make(npc.targetPosition.x * SCOURGE_TIP_THRUST * npc.speedMultiplier + npc.velocity.x, + npc.targetPosition.y * SCOURGE_TIP_THRUST * npc.speedMultiplier + npc.velocity.y); float speed = vector_length(npc.velocity); if (speed > SCOURGE_TIP_SPEED_MAX && speed > 0) npc.velocity = vector_scale(npc.velocity, SCOURGE_TIP_SPEED_MAX / speed); @@ -1195,15 +1196,14 @@ static void chain_health_share(Entity_NPC& npc, Entity_NPC& head) weakest = std::min(link->health - link->pendingDamage, weakest); float most = 0; - EntityRef source(&npc); for (Entity* link = &head; is_scourge_link(link); link = link->child.get()) { float left = link->health - link->pendingDamage; if (left <= weakest) continue; - link->TakeDamage(left - weakest, 0, source, SCOURGE_LINK_DAMAGE_COUNTDOWN); + link->TakeDamage(left - weakest, 0, EntityRef(&npc), SCOURGE_LINK_DAMAGE_COUNTDOWN); most = std::max(left - weakest, most); } - if (head.parent && most > 0) head.parent->TakeDamage(most * SCOURGE_SHARED_DAMAGE, 0, source, SCOURGE_LINK_DAMAGE_COUNTDOWN); + if (head.parent && most > 0) head.parent->TakeDamage(most * SCOURGE_SHARED_DAMAGE, 0, EntityRef(&npc), SCOURGE_LINK_DAMAGE_COUNTDOWN); } // A dead link lets go of its neighbours, checks what is left of its chain and shows its wall impact. @@ -1284,7 +1284,7 @@ static void scourge_chain_strip_render(Entity_NPC& npc, const Vector& offset) const AnimationFrame* frame = npc.sprite.animState.GetLayerFrame(0); if (!frame) return; - float halfWidth = frame->width * HALF * npc.sprite.scale.x * frame->scale.x; + float halfWidth = frame->width * HALF * npc.sprite.scale.x; float height = npc.subtype == SCOURGE_CHAIN_TRAP && tip.state == SCOURGE_LINK_LATCHED ? (frame->height - SCOURGE_STRIP_LATCHED_INSET) * npc.sprite.scale.y : npc.sprite.scale.y * frame->height; @@ -1300,14 +1300,15 @@ static void scourge_chain_strip_render(Entity_NPC& npc, const Vector& offset) { Vector to = vector_add(link->pos, link->posOffset); Vector direction = vector_normalized(vector_sub(to, from)); - Vector edge = vector_make(-direction.y * halfWidth, direction.x * halfWidth); + Vector edge = vector_make(halfWidth * frame->scale.x * -direction.y, direction.x * halfWidth * frame->scale.x); + float edgeBack = direction.y * halfWidth * frame->scale.x; Vector start = render_position_get(from, RENDER_SNAPPED); Vector end = render_position_get(to, RENDER_SNAPPED); DestinationQuad quad; quad._topLeft = vector_add(vector_add(start, edge), offset); - quad._topRight = vector_add(vector_sub(start, edge), offset); + quad._topRight = vector_add(vector_make(start.x + edgeBack, start.y - edge.y), offset); quad._bottomLeft = vector_add(vector_add(end, edge), offset); - quad._bottomRight = vector_add(vector_sub(end, edge), offset); + quad._bottomRight = vector_add(vector_make(end.x + edgeBack, end.y - edge.y), offset); quads.emplace_back(quad, kcolor_rgba(1, 1, 1, 1)); SourceQuad source; diff --git a/src/boss_singe.cpp b/src/boss_singe.cpp index 74a3e64..62a3098 100644 --- a/src/boss_singe.cpp +++ b/src/boss_singe.cpp @@ -88,14 +88,14 @@ static void singe_ball_blasts_update(Entity_NPC& npc) } } -// Its height: falling (and bouncing, or dropping into a pit) while up or popped. -static void singe_ball_fall_update(Entity_NPC& npc) +// Its height: falling (and bouncing, or dropping into a pit) while up or popped. Whether it sank out of the room. +static bool singe_ball_is_sunk(Entity_NPC& npc) { bool isAirborne = npc.v2.y < 0 || npc.v1.y < 0 || npc.entityGridCollisionClass == GRIDCOLL_PITSONLY; if (!isAirborne) { npc.posOffset.y = npc.v2.y; - return; + return false; } float fall = npc.v1.y; @@ -107,6 +107,7 @@ static void singe_ball_fall_update(Entity_NPC& npc) { g_game->Spawn({.position = npc.pos, .type = ENTITY_EFFECT, .variant = EFFECT_POOF01, .seed = Random()}); npc.Remove(); + return true; } } else if (npc.v2.y > 0) @@ -131,6 +132,7 @@ static void singe_ball_fall_update(Entity_NPC& npc) } } npc.posOffset.y = npc.v2.y; + return false; } // 0058d8b0 Singe's ball rolls about wherever it is knocked, bounced by blasts and turning with its roll, harmless @@ -172,7 +174,7 @@ void singe_ball_update(Entity_NPC& npc) npc.entityGridCollisionClass = npc.v2.y <= BALL_LIFTED || npc.v1.y < 0 ? GRIDCOLL_NOPITS : GRIDCOLL_GROUND; } singe_ball_blasts_update(npc); - singe_ball_fall_update(npc); + if (singe_ball_is_sunk(npc)) return; float speedSquared = vector_length_squared(npc.velocity); int axis = std::abs(npc.velocity.y) < std::abs(npc.velocity.x) ? BALL_ROLL_SIDEWAYS : 0; @@ -764,7 +766,7 @@ static void singe_smoke_update(Entity_NPC& npc) Vector offset = vector_rotated(local, sprite.rotation); if (sprite.isFlipX) offset.x *= -1; if (sprite.isFlipY) offset.y *= -1; - offset = vector_scale(offset, 1 / ROOM_SCREEN_SCALE); + offset = vector_make(offset.x / ROOM_SCREEN_SCALE, offset.y / ROOM_SCREEN_SCALE); int count = 1 - (int)(guide->scale.y * guide->scale.x / SINGE_SMOKE_AREA); bool isLeft = offset.x < 0; diff --git a/src/boss_siren.cpp b/src/boss_siren.cpp index b640134..1476632 100644 --- a/src/boss_siren.cpp +++ b/src/boss_siren.cpp @@ -106,12 +106,14 @@ constexpr float SIREN_LUNGE_NUDGE = 0.01f; constexpr float SIREN_SLASH_LEAD = 0.1f; constexpr float SIREN_CARRIER_SPEED = 10; -// The teleport: she sinks, trailing black creep, paths 10 above her target at 2.5 (for 30 to 90 frames) and rises. +// The teleport: she sinks, trailing black creep, paths 10 above her target at 2.5 (for 30 to 90 frames) and rises, +// owing a lunge for 30 frames. constexpr float SIREN_TELEPORT_SPEED = 2.5f; constexpr float SIREN_TELEPORT_RISE = 10; constexpr float SIREN_TELEPORT_MARGIN = 5; constexpr int SIREN_TELEPORT_MIN = 30; constexpr int SIREN_TELEPORT_MAX = 90; +constexpr int SIREN_TELEPORT_LUNGE = 30; constexpr float SIREN_TELEPORT_NEAR = 20; constexpr int SIREN_CREEP_FRAMES = 300; constexpr uint32_t SIREN_SINK_CREEP_ODDS = 3; @@ -362,12 +364,14 @@ static void siren_pick(Entity_NPC& npc) Vector topLeft = room.topLeftPos; Vector bottomRight = room.bottomRightPos; float middle = (bottomRight.y - topLeft.y) * HALF + topLeft.y; - float right = std::clamp((npc.pos.x - (bottomRight.x - SIREN_EDGE)) / SIREN_EDGE, 0.0f, 1.0f); - float left = std::clamp((npc.pos.x - (topLeft.x + SIREN_EDGE)) / -SIREN_EDGE, 0.0f, 1.0f); + float rightStart = bottomRight.x - SIREN_EDGE; + float leftStart = topLeft.x + SIREN_EDGE; + float right = std::clamp((npc.pos.x - rightStart) / (bottomRight.x - rightStart), 0.0f, 1.0f); + float left = std::clamp((npc.pos.x - leftStart) / (topLeft.x - leftStart), 0.0f, 1.0f); float bottom = std::clamp((npc.pos.y - middle) / (bottomRight.y - middle), 0.0f, 1.0f); add(SIREN_TELEPORT, (int)((bottom + 0 + left + 0 + right + 0) * SIREN_PICK_BASE)); } - if (!isTeleportWeighed || picker.outcomes.empty()) add(SIREN_IDLE, SIREN_PICK_BASE); + if (charmed > 0 || picker.outcomes.empty()) add(SIREN_IDLE, SIREN_PICK_BASE); RNG rng = RNG_DEFAULT; rng._seed = Random() | 1; @@ -540,7 +544,8 @@ static void siren_teleport_end_update(Entity_NPC& npc) if (!siren_is_anim_done(npc)) return; npc.state = SIREN_IDLE; npc.projectileCooldown = 0; - npc.stateFrame = SIREN_IDLE_FRAMES; + npc.stateFrame = 0; + npc.projectileDelay = SIREN_TELEPORT_LUNGE; siren_cooldown_set(npc, SIREN_COOLDOWN_TELEPORT, SIREN_TELEPORT_WAIT); } @@ -936,7 +941,7 @@ static void siren_remains_update(Entity_NPC& npc) } // The carrier: while it flies its charmed line pulses, and past 15 frames a familiar out of the room or a wall breaks -// it into a ring of shots that hurts the line. +// it into a ring of shots that hurts the line's helpers. static void siren_carrier_update(Entity_NPC& npc) { if (npc.state == NPC_STATE_INIT) @@ -949,23 +954,23 @@ static void siren_carrier_update(Entity_NPC& npc) auto* siren = static_cast(npc.parent.get()); if (!siren || !siren->IsType(ENTITY_SIREN, 0, -1)) return npc.Remove(); - std::vector line; + std::vector line; for (Entity* helper : Entity_NPC::QueryNPCsType(ENTITY_SIREN_HELPER, -1)) { if (helper->parent.get() != siren) continue; auto* familiar = static_cast(helper->target.get()); if (familiar && familiar->HasEntityFlags(FLAG_CHARM) && familiar->is_following() && familiar->player == siren->sirenPlayerEntity) - line.push_back(familiar); + line.push_back(helper); } if (line.empty()) return npc.Remove(); if (npc.GetIntervalTicks(SIREN_CARRY_PULSE_EVERY, 0) != 0) - for (Entity_Familiar* familiar : line) familiar->SetColor(SIREN_CARRY_PULSE, SIREN_CARRY_PULSE_EVERY, 0, true, true); + for (Entity* helper : line) helper->target->SetColor(SIREN_CARRY_PULSE, SIREN_CARRY_PULSE_EVERY, 0, true, true); Room& room = *g_game->room; if (npc.updateTime > SIREN_CARRY_ARMED) - for (Entity_Familiar* familiar : line) + for (Entity* helper : line) { - if (room.IsPositionInRoom(familiar->pos, SIREN_CARRY_MARGIN)) continue; + if (room.IsPositionInRoom(helper->target->pos, SIREN_CARRY_MARGIN)) continue; npc.isDead = true; break; } @@ -978,7 +983,7 @@ static void siren_carrier_update(Entity_NPC& npc) npc.FireProjectiles(clamped, vector_make(SIREN_CARRY_SHOT_SPEED, (float)(int)shots), PROJECTILES_RING, params); npc.pos = clamped; game_shake_screen(SIREN_CARRY_SHAKE); - for (Entity_Familiar* familiar : line) familiar->TakeDamage(SIREN_CARRY_DAMAGE, 0, EntityRef(), SIREN_CARRY_COUNTDOWN); + for (Entity* helper : line) helper->TakeDamage(SIREN_CARRY_DAMAGE, 0, EntityRef(), SIREN_CARRY_COUNTDOWN); siren->sirenPlayerEntity->ClearEntityFlags(FLAG_SPAWN_STICKY_SPIDERS); npc.Remove(); } @@ -1019,6 +1024,8 @@ void siren_helper_update(Entity_NPC& npc) npc.pos = familiar->pos; npc.velocity = familiar->velocity; npc.friction = familiar->friction; + npc.entityCollisionClass = familiar->entityCollisionClass != ENTCOLL_NONE ? ENTCOLL_PLAYEROBJECTS : ENTCOLL_NONE; + npc.entityGridCollisionClass = familiar->entityGridCollisionClass; if (familiar->charmedCountdown < SIREN_CHARM_FRAMES) { familiar->AddEntityFlags(FLAG_CHARM); diff --git a/src/boss_tuff_twins.cpp b/src/boss_tuff_twins.cpp index 6e8c28b..26513c1 100644 --- a/src/boss_tuff_twins.cpp +++ b/src/boss_tuff_twins.cpp @@ -361,15 +361,20 @@ static void shell_move(Entity_NPC& npc) bool isTrailing = npc.i2 == 0 && (!parent || parent->i2 == 0); if (isTrailing && !parent) shell_head_roll(npc); else if (!isTrailing && !parent && npc.child) - npc.pathfinder.FindGridPath(npc.CalcTargetPosition(0), random_unit() * SHELL_PATH_SPEED_RANGE + SHELL_PATH_SPEED_MIN, - SHELL_PATH_MARKER, DIRECT_PATH_FAR); + { + float speed = random_unit() * SHELL_PATH_SPEED_RANGE + SHELL_PATH_SPEED_MIN; + npc.pathfinder.FindGridPath(npc.CalcTargetPosition(0), speed, SHELL_PATH_MARKER, DIRECT_PATH_FAR); + } else if (!isTrailing && parent) { Vector away = vector_sub(npc.pos, parent->pos); float distance = vector_length(away); + Vector back = vector_normalized(away); if (distance > SHELL_SLACK) - npc.velocity = vector_sub(npc.velocity, vector_scale(vector_normalized(away), - (distance - SHELL_SLACK) * SHELL_SLACK_PULL * npc.speedMultiplier)); + { + npc.velocity.x = -back.x * (distance - SHELL_SLACK) * SHELL_SLACK_PULL * npc.speedMultiplier + npc.velocity.x; + npc.velocity.y = -back.y * (distance - SHELL_SLACK) * SHELL_SLACK_PULL * npc.speedMultiplier + npc.velocity.y; + } } segment_follow(npc, isTrailing ? SEGMENT_FOLLOW : SEGMENT_RECORD, TUFF_SEGMENT_GAP, npc.v1.x * SEGMENT_SPEED_SCALE); } @@ -515,8 +520,8 @@ static void twins_body_attack(Entity_NPC& npc) npc.PlaySound(SOUND_BLOODSHOOT, 1, 2, false, 1); Vector target = npc.GetPlayerTarget()->pos; if (vector_length(vector_sub(npc.pos, target)) > BODY_SHOT_REACH) target = {}; - npc.FireBossProjectiles((int)(Random() % BODY_SHOTS_RANGE) + BODY_SHOTS_MIN, target, BODY_SHOT_CURVE, - ProjectileParams()); + ProjectileParams params; + npc.FireBossProjectiles((int)(Random() % BODY_SHOTS_RANGE) + BODY_SHOTS_MIN, target, BODY_SHOT_CURVE, params); Entity* poof = g_game->Spawn({.position = npc.pos, .type = ENTITY_EFFECT, .variant = EFFECT_BULLET_POOF, .seed = Random()}); poof->sprite.offset = vector_make(0, BODY_SHOT_POOF_RISE); diff --git a/src/boss_turdlet.cpp b/src/boss_turdlet.cpp index ef179f1..cad5325 100644 --- a/src/boss_turdlet.cpp +++ b/src/boss_turdlet.cpp @@ -160,7 +160,7 @@ static void turdlet_init(Entity_NPC& npc) npc.splatColor = POOP_SPLAT_COLOR; npc.aiCallFlags = AI_CALL_PRE_UPDATE; npc.v2.y = npc.maxHitPoints * TURDLET_START_HEALTH; - if (npc.parent) static_cast(npc.parent.get())->vectorDeque1.push_back(npc.pos); + if (npc.parent) static_cast(npc.parent.get())->vectorDeque1.push_front(npc.pos); if (!npc.parent) for (Entity_NPC* segment = &npc; segment; segment = segment->ChildNPC()) segment->groupIdx = npc.index; for (auto* segment = static_cast(npc.GetLastParent()); segment; segment = segment->ChildNPC()) @@ -225,8 +225,8 @@ static void turdlet_wind_up(Entity_NPC& npc) int count = 0; for (Entity* segment = &npc; segment; segment = segment->child.get(), count++) middle = vector_add(middle, segment->pos); - middle = vector_scale(middle, 1 / (float)count); - Vector velocity = vector_resized(vector_sub(npc.CalcTargetPosition(0), middle), TURDLET_CHARGE_SPEED); + Vector mean = vector_div(middle, vector_make((float)count, (float)count)); + Vector velocity = vector_resized(vector_sub(npc.CalcTargetPosition(0), mean), TURDLET_CHARGE_SPEED); for (Entity_NPC* segment = &npc; segment; segment = segment->ChildNPC()) { segment->sprite.PlayOverlay("HeadChargeLoopOverlay"); @@ -244,9 +244,10 @@ static void turdlet_charge_follow(Entity_NPC& npc) Entity* child = npc.child.get(); if (parent && child) { - Vector middle = vector_scale(vector_add(vector_add(parent->prevPosition, parent->prevVelocity), - vector_add(child->prevPosition, child->prevVelocity)), - HALF); + Vector middle = vector_scale( + vector_add(vector_add(vector_add(parent->prevPosition, parent->prevVelocity), child->prevPosition), + child->prevVelocity), + HALF); npc.velocity = vector_add( vector_scale(vector_sub(vector_sub(middle, npc.pos), npc.velocity), TURDLET_FOLLOW_PULL), npc.velocity); return; @@ -271,7 +272,7 @@ static float turdlet_charge_carry(Entity_NPC& npc) int count = 0; for (Entity* segment = head; segment; segment = segment->child.get(), count++) middle = vector_add(middle, segment->prevPosition); - middle = vector_scale(middle, 1 / (float)count); + middle = vector_div(middle, vector_make((float)count, (float)count)); Vector push{}; float spin = 0; @@ -283,7 +284,7 @@ static float turdlet_charge_carry(Entity_NPC& npc) spin += vector_dot(vector_rotated(vector_normalized(arm), RIGHT_ANGLE_DEGREES), segment->prevVelocity); } spin /= (float)count; - push = vector_scale(push, 1 / (float)count); + push = vector_div(push, vector_make((float)count, (float)count)); float fade = 1 - std::clamp((npc.v2.x - TURDLET_CHARGE_FADE_START) / TURDLET_CHARGE_FADE_SPAN, 0.0f, 1.0f); float pushMax = fade * TURDLET_CHARGE_PUSH; @@ -300,7 +301,8 @@ static float turdlet_charge_carry(Entity_NPC& npc) { float turn = std::clamp((spin <= 0 ? -spinMax : spinMax) - spin, -TURDLET_SPIN_STEP, TURDLET_SPIN_STEP); Vector arm = vector_rotated(vector_sub(npc.prevPosition, middle), RIGHT_ANGLE_DEGREES); - npc.velocity = vector_add(vector_scale(arm, turn * TURDLET_SPIN_SHARE * npc.speedMultiplier), npc.velocity); + npc.velocity.x = arm.x * turn * TURDLET_SPIN_SHARE * npc.speedMultiplier + npc.velocity.x; + npc.velocity.y = arm.y * turn * TURDLET_SPIN_SHARE * npc.speedMultiplier + npc.velocity.y; } return speed; } diff --git a/src/boss_wormwood.cpp b/src/boss_wormwood.cpp index 802ab2d..e32fabe 100644 --- a/src/boss_wormwood.cpp +++ b/src/boss_wormwood.cpp @@ -60,7 +60,7 @@ constexpr size_t WORMWOOD_TRAIL_MAX = 60; constexpr float SWIM_TURN = 1.6f; constexpr float SWIM_PIT_TURN = 1.2f; constexpr float SWIM_SINK_TURN = 5; -constexpr float SWIM_SPEED_UP = 0.22f; +constexpr float SWIM_SPEED_UP = 0.22000001f; constexpr float CHASE_SPEED_UP = 0.4f; constexpr float ENRAGED_SPEED_UP = 3; constexpr float ENRAGED_TURN = 6; @@ -375,9 +375,16 @@ static void wormwood_animate(Entity_NPC& npc) if (!npc.sprite.animState.animData || !npc.sprite.animState.isPlaying) npc.i1 = HEAD_OPEN; } -// A segment's place along the trail its leader left, 20 behind it, sinking or rising with it. +// A segment's place along the trail its leader left, 20 behind it, sinking or rising with it. Without a trail it only +// keeps sinking or rising. static void segment_trail_follow(Entity_NPC& npc, Entity_NPC& leader) { + if (leader.vectorDeque1.empty()) + { + npc.v1.y = npc.v1.x * npc.speedMultiplier + npc.v1.y; + return; + } + Vector point = leader.pos; float pointDepth = leader.v1.y; float walked = 0; @@ -537,7 +544,9 @@ static void crossing_start(Entity_NPC& npc) float forward = random_unit() * DUST_SPEED; float across = random_unit() * DUST_SPEED - DUST_SPEED / 2; Vector velocity = vector_make(out * forward + across * 0.0f, -out * across + forward * 0.0f); - Vector place = vector_add(npc.targetPosition, vector_scale(random_direction(), random_unit() * DUST_SPREAD)); + Vector direction = random_direction(); + float spread = random_unit() * DUST_SPREAD; + Vector place = vector_add(npc.targetPosition, vector_scale(direction, spread)); dust_spawn({.origin = npc.pos, .side = vector_make(0, -out), .velocity = velocity}, seed, place); } game_particles_spawn({.position = npc.targetPosition, @@ -811,7 +820,7 @@ void boss_wormwood_update(Entity_NPC& npc) int ticks = npc_ticks_get(npc); if (npc.subtype != 0) { - if (!npc.parent) npc.Kill(EntityRef()); + if (!npc.parent) return npc.Kill(EntityRef()); if (npc.state != NPC_STATE_INIT) { wormwood_animate(npc); diff --git a/src/cutscene.cpp b/src/cutscene.cpp index d9700f6..0aec3eb 100644 --- a/src/cutscene.cpp +++ b/src/cutscene.cpp @@ -66,7 +66,6 @@ constexpr int TEMPORARY_PULSE_PERIOD = 60; constexpr int TEMPORARY_PULSE_PEAK = 31; constexpr float TEMPORARY_PULSE_SCALE = 300; constexpr float TEMPORARY_PULSE_BASE = 0.4f; -constexpr char WORD_SEPARATOR = ' '; // An ARGB color as KColor::SetFromARGB unpacks it. static KColor color_get(uint32_t argb) diff --git a/src/entity_effect_ambient.cpp b/src/entity_effect_ambient.cpp index eb71d69..968d95f 100644 --- a/src/entity_effect_ambient.cpp +++ b/src/entity_effect_ambient.cpp @@ -456,7 +456,10 @@ static void tiny_fly_update(Entity_Effect& fly) fly.AddVelocity_divided(vector_scale(pull, random_unit() * FLY_PULL), false); } if (fly.IsFrame(FLY_JITTER_FRAMES, (int)fly.index)) - fly.AddVelocity_divided(vector_scale(random_direction(), random_unit() * FLY_JITTER), false); + { + Vector direction = random_direction(); + fly.AddVelocity_divided(vector_scale(direction, random_unit() * FLY_JITTER), false); + } if (distance < FLY_FLEE_RANGE) { float push = (1 - distance * distance / (FLY_FLEE_RANGE * FLY_FLEE_RANGE)) * FLY_FLEE_PUSH; @@ -1374,7 +1377,8 @@ static void liquid_poop_puddle_update(Entity_Effect& puddle) { uint32_t seed = Random(); int subtype = random_below(2); - Vector drift = vector_scale(vector_scale(random_direction(), random_unit()), LIQUID_POOP_GAS_SPEED); + Vector direction = random_direction(); + Vector drift = vector_scale(vector_scale(direction, random_unit()), LIQUID_POOP_GAS_SPEED); auto* gas = static_cast(g_game->Spawn({.position = puddle.pos, .velocity = vector_add(puddle.velocity, drift), .subType = subtype, diff --git a/src/entity_effect_dogma.cpp b/src/entity_effect_dogma.cpp index 57461ee..4a86dd2 100644 --- a/src/entity_effect_dogma.cpp +++ b/src/entity_effect_dogma.cpp @@ -374,7 +374,7 @@ static void dogma_orb_render(Entity_Effect& spot, const Vector& offset) { float spent = std::clamp(((float)spot.timeout - SPOT_GUIDE_LAST_FRAMES) / ((float)spot.lifespan - SPOT_GUIDE_LAST_FRAMES), 0.0f, 1.0f); - float fade = std::sqrt(1 - spent); + float fade = pow_float(1 - spent, HALF); float fadeIn = std::min((float)(spot.lifespan - spot.timeout) / SPOT_GUIDE_FADE_IN, 1.0f); reach = fadeIn * fade * fade; } diff --git a/src/entity_effect_shots.cpp b/src/entity_effect_shots.cpp index f140380..837a5dd 100644 --- a/src/entity_effect_shots.cpp +++ b/src/entity_effect_shots.cpp @@ -234,7 +234,7 @@ static void tech_dot_render(Entity_Effect& dot, const Vector& offset) else { float spent = ((float)dot.timeout - DOT_GUIDE_FRAMES) / ((float)dot.lifespan - DOT_GUIDE_FRAMES); - fade = std::sqrt(1 - std::clamp(spent, 0.0f, 1.0f)); + fade = pow_float(1 - std::clamp(spent, 0.0f, 1.0f), HALF); } Vector start = vector_add(dot.pos, dot.posOffset); @@ -648,8 +648,8 @@ static void chain_lightning_update(Entity_Effect& chain) Entity* next = chain_next_find(chain); if (next || chain.state == 1) { - Vector jump = next ? vector_sub(next->pos, chain.pos) - : vector_scale(vector_scale(random_direction(), random_unit()), chain.minRadius); + Vector jump = next ? vector_sub(next->pos, chain.pos) : random_direction(); + if (!next) jump = vector_scale(vector_scale(jump, random_unit()), chain.minRadius); chain_laser_fire(chain, next, jump); } if (next) diff --git a/src/entity_knife.cpp b/src/entity_knife.cpp index 2d549f3..9be1140 100644 --- a/src/entity_knife.cpp +++ b/src/entity_knife.cpp @@ -1213,7 +1213,7 @@ bool Entity_Knife::held_update(Entity_Player* player) else { sprite.rotation = normalize_angle_degrees(vector_angle(vector_sub(tip, owner->pos)) - KNIFE_TURN_QUARTER); - if (const AnimationFrame* frame = sprite.animState.GetLayerFrame(0)) + if (const NullFrame* frame = sprite.GetNullFrameById(0)) { Vector facing = vector_from_angle(sprite.rotation); knifeDepthOffset = facing.x * frame->pos.y + facing.y * frame->pos.x; @@ -1506,7 +1506,7 @@ void Entity_Knife::held_item_update() velocity = vector_sub(vector_add(place, linkedKnife->pos), pos); displayRotation = rotation; sprite.rotation = rotation - KNIFE_TURN_QUARTER; - if (const AnimationFrame* frame = sprite.animState.GetLayerFrame(0)) + if (const NullFrame* frame = sprite.GetNullFrameById(0)) { Vector facing = vector_from_angle(sprite.rotation); knifeDepthOffset = facing.x * frame->pos.y + facing.y * frame->pos.x; @@ -1614,7 +1614,7 @@ void Entity_Knife::Render(const Vector& offset) if (GetBaseVariant() == KNIFE_BONE_CLUB && subtype != KNIFE_SUBTYPE_HELD_ITEM && player && player->deadEyeCharges > 0) { - const AnimationFrame* frame = sprite.animState.GetLayerFrame(0); + const NullFrame* frame = sprite.GetNullFrameById(0); ColorMod mark = COLOR_DEFAULT; mark._tint[3] = (float)std::min((int)player->deadEyeCharges, DEAD_EYE_LEVELS) / DEAD_EYE_LEVELS; deadEyeSprite.color = mark; diff --git a/src/entity_laser_hits.cpp b/src/entity_laser_hits.cpp index 56e5fe0..865bd84 100644 --- a/src/entity_laser_hits.cpp +++ b/src/entity_laser_hits.cpp @@ -170,7 +170,7 @@ void Entity_Laser::DoDamage(Entity* entity, float damage) roll._seed = entity->initSeed; if (roll.RandomFloat() < blackHpDropChance) damageFlags |= DAMAGE_SPAWN_BLACK_HEART; } - if (isVersus && tearFlags[TEAR_LASERSHOT]) damageFlags |= DAMAGE_LASER; + if (isVersus && tearFlags[TEAR_LASERSHOT]) damageFlags |= DAMAGE_THROUGH_COOLDOWN; entity->TakeDamage(damage, damageFlags, EntityRef(source), HIT_COUNTDOWN); } @@ -207,8 +207,9 @@ bool Entity_Laser::damage_grid_entity(int gridIndex, const Vector& direction) return grid->Hurt(1, EntityRef(this)); } -// 00970cb0 What the beam's path meets on the grid: the cells across its width (20 apart) it covers, hurt once each, -// and the room's edge, nearest along the path (beyond it the last point inside, for a beam that leaves the room). +// 00970cb0 What the beam's path meets on the grid: the cells of standing grid entities across its width (20 apart) +// it covers, hurt once each, the first stopping it, and the room's edge, nearest along the path (beyond it the last +// point inside, for a beam that leaves the room). // Every beam of the players' also hurts each grid entity within its width along its angle. void Entity_Laser::find_nearest_grid_hit(const Vector& offset) { @@ -225,24 +226,27 @@ void Entity_Laser::find_nearest_grid_hit(const Vector& offset) float travelled = 0; Vector last{}; - // Records a point across the beam: past the room's side it stops a Continuum beam, inside it marks its cell. - auto probe = [&](const Vector& point, const Vector& direction) { + // Records a point across the beam: past the room's side it stops a Continuum beam, inside it marks the cell of + // a standing grid entity, which stops the beam too. The stop is at the last sample, or on the far side at the + // point itself. + auto probe = [&](const Vector& point, const Vector& direction, const Vector& stop) { if (!room.IsPositionInRoom(point, ROOM_SIDE_MARGIN)) { - if (tearFlags[TEAR_CONTINUUM] && travelled < impactDistance) - { - impactDistance = travelled; - impactPosition = previous; - impactDirection = direction; - } - return; + if (!tearFlags[TEAR_CONTINUUM]) return; } - int column = (int)((point.x - GRID_ORIGIN_X) / GRID_CELL_SIZE + 0.5f); - int row = (int)((point.y - GRID_ORIGIN_Y) / GRID_CELL_SIZE + 0.5f); - int index = room.GetGridIndexByTile(column, row); - uint32_t collision = index >= 0 ? room.GetGridCollision(index) : COLLISION_NONE; - if (index >= 0 && collision != COLLISION_NONE && collision != COLLISION_PIT) + else + { + int column = (int)((point.x - GRID_ORIGIN_X) / GRID_CELL_SIZE + 0.5f); + int row = (int)((point.y - GRID_ORIGIN_Y) / GRID_CELL_SIZE + 0.5f); + int index = room.GetGridIndexByTile(column, row); + uint32_t collision = index >= 0 ? room.GetGridCollision(index) : COLLISION_NONE; + if (index < 0 || collision == COLLISION_NONE || collision == COLLISION_PIT) return; crossed.try_emplace(index, direction); + } + if (travelled >= impactDistance) return; + impactDistance = travelled; + impactPosition = stop; + impactDirection = direction; }; for (size_t i = 0; i <= count; i++) @@ -271,8 +275,9 @@ void Entity_Laser::find_nearest_grid_hit(const Vector& offset) } for (float width = 0; width < size; width += GRID_SWEEP_STEP) { - probe(vector_add(point, vector_scale(side, width)), direction); - if (width != 0) probe(vector_sub(point, vector_scale(side, width)), direction); + probe(vector_add(point, vector_scale(side, width)), direction, previous); + Vector far = vector_sub(point, vector_scale(side, width)); + if (width != 0) probe(far, direction, far); } travelled += length; previous = point; @@ -303,7 +308,8 @@ void Entity_Laser::find_nearest_grid_hit(const Vector& offset) (float)(index / room.gridWidth) * GRID_CELL_SIZE + GRID_ORIGIN_Y); Vector relative = vector_add(vector_sub(cell, pos), offset); float along = vector_dot(relative, direction); - float across = relative.y * direction.x - relative.x * direction.y; + // The original adds the cross terms, so off the axes it measures the width against the beam mirrored: kept. + float across = relative.y * direction.x + relative.x * direction.y; if (std::abs(across) < size + GRID_REACH_EXTRA && along > 0 && along <= reach) damage_grid_entity(index, direction); } diff --git a/src/entity_npc.cpp b/src/entity_npc.cpp index 969570c..7281c7c 100644 --- a/src/entity_npc.cpp +++ b/src/entity_npc.cpp @@ -187,14 +187,9 @@ constexpr int TYPE_NO_TICK_B = 275; // The items and seeds whose effects the NPC update reads, by Lua id. constexpr int COLLECTIBLE_CHAMPION_BELT_ID = 208; -constexpr int COLLECTIBLE_SOUL_ID = 335; -constexpr int COLLECTIBLE_BETRAYAL_ID = 391; constexpr int COLLECTIBLE_SPIDER_MOD_ID = 403; -constexpr int COLLECTIBLE_GUPPYS_EYE_ID = 665; -constexpr int TRINKET_SUPER_MAGNET_ID = 68; constexpr int TRINKET_ICE_CUBE_ID = 188; constexpr int ROOM_TRINKET_STATUS_FRAMES = -90; -constexpr int NULLITEM_DAMOCLES_WEAKNESS = 64; constexpr int ACHIEVEMENT_BOSS_COLORS = 3; constexpr int ACHIEVEMENT_MORE_BOSS_COLORS = 33; @@ -1638,7 +1633,8 @@ void Entity_NPC::midas_coins_spawn() for (int i = 0; i < coins; i++) { uint32_t seed = Random(); - Vector speed = vector_scale(random_direction(), random_unit() * MIDAS_COIN_SPEED); + Vector direction = random_direction(); + Vector speed = vector_scale(direction, random_unit() * MIDAS_COIN_SPEED); g_game->Spawn({.position = pos, .velocity = speed, .subType = COIN_PENNY, @@ -1672,9 +1668,6 @@ void Entity_NPC::player_aura_update() constexpr float AURA_REACH_SQUARED = 1e9f; constexpr float SUPER_MAGNET_PULL = 0.5f; constexpr int AURA_ODDS = 3; - constexpr float SALVATION_HALO_RADIUS = 70; - constexpr int SALVATION_BEAM_SUBTYPE = 3; - constexpr float SALVATION_BEAM_DAMAGE = 3.5f; if (state == NPC_STATE_DEATH || state == NPC_STATE_UNIQUE_DEATH || IsFriendly() || !IsVulnerableEnemy(nullptr)) return; @@ -1686,8 +1679,8 @@ void Entity_NPC::player_aura_update() float salvationDistance = AURA_REACH_SQUARED; for (Entity_Player* player : g_game->playerManager.playerList) { - bool isSoul = player->HasCollectible(COLLECTIBLE_SOUL_ID); - bool isMagnet = player->HasTrinket(TRINKET_SUPER_MAGNET_ID); + bool isSoul = player->HasCollectible(COLLECTIBLE_SOUL); + bool isMagnet = player->HasTrinket(TRINKET_SUPER_MAGNET); bool isSalvation = player->HasCollectible(COLLECTIBLE_SALVATION); if (!isSoul && !isMagnet && !isSalvation) continue; @@ -1867,7 +1860,7 @@ void Entity_NPC::Update() } if (HasEntityFlags(FLAG_ICE_FROZEN)) return update_frozen(); - bool isWeakened = g_game->room->temporaryEffects.HasNullEffect(NULLITEM_DAMOCLES_WEAKNESS); + bool isWeakened = g_game->room->temporaryEffects.HasNullEffect(NULLITEM_REVERSE_STRENGTH); if (IsFrame(WEAKNESS_FRAMES, 0) && !IsFriendly() && IsActiveEnemy(DEAD_EXCLUDED) && isWeakened) AddWeakness(EntityRef(nullptr), -3); if (salvationTarget && salvationTarget->target.get() == this) @@ -2219,7 +2212,7 @@ bool Entity_NPC::TakeDamage(float damage, uint64_t damageFlags, const EntityRef& if (!IsFriendly() && isPlayerSource) g_game->room->isPacifist = false; PlayerManager& players = g_game->playerManager; - if (source.entity && players.FirstCollectibleOwner(COLLECTIBLE_BETRAYAL_ID, LAZARUS_SHARE_CHECK)) betrayal_turn(source.entity); + if (source.entity && players.FirstCollectibleOwner(COLLECTIBLE_BETRAYAL, LAZARUS_SHARE_CHECK)) betrayal_turn(source.entity); if (players.FirstCollectibleOwner(COLLECTIBLE_JAR_OF_FLIES, LAZARUS_SHARE_CHECK)) { bool isBlueFly = source.type == ENTITY_FAMILIAR && source.variant == Entity_Familiar::BLUE_FLY; @@ -3684,7 +3677,7 @@ bool Entity_NPC::split(float damage, const EntityRef& source, bool isPlaySound) void Entity_NPC::UpdatePickupGhosts() { bool isLootHolder = (type == ENTITY_FIREPLACE && health > 1) || (type == ENTITY_SHOPKEEPER && !isDead); - if (isLootHolder && g_game->playerManager.FirstCollectibleOwner(COLLECTIBLE_GUPPYS_EYE_ID, LAZARUS_SHARE_CHECK)) + if (isLootHolder && g_game->playerManager.FirstCollectibleOwner(COLLECTIBLE_GUPPYS_EYE, LAZARUS_SHARE_CHECK)) { LootList loot = type == ENTITY_FIREPLACE ? fireplace_get_loot(false) : LootList{shopkeeper_loot_get(*this, false)}; if (!loot.entries.empty()) diff --git a/src/entity_npc_boss.cpp b/src/entity_npc_boss.cpp index fc59c56..4c699fb 100644 --- a/src/entity_npc_boss.cpp +++ b/src/entity_npc_boss.cpp @@ -207,13 +207,15 @@ void segment_follow(Entity_NPC& npc, SegmentMode mode, float distance, float max if (trail.size() > SEGMENT_HISTORY) trail.resize(SEGMENT_HISTORY); } -// 006d0dd0 The NPCs of a group, in update order. +// 006d0dd0 The NPCs of a group, in update order. A versus player passes the enemy check but is no NPC. std::vector Entity_NPC::QueryNPCsGroup(int groupIdx) { std::vector group; for (Entity* entity : g_game->room->entityList.updateEL) - if (Entity::is_enemy_type(entity->type) && static_cast(entity)->groupIdx == groupIdx) - group.push_back(static_cast(entity)); + { + auto* npc = Entity::is_enemy_type(entity->type) ? dynamic_cast(entity) : nullptr; + if (npc && npc->groupIdx == groupIdx) group.push_back(npc); + } return group; } diff --git a/src/entity_npc_render.cpp b/src/entity_npc_render.cpp index df67b9a..3b0ed58 100644 --- a/src/entity_npc_render.cpp +++ b/src/entity_npc_render.cpp @@ -50,7 +50,6 @@ constexpr int WORMWOOD = 3; constexpr int BIG_BONY_BONE = 10; constexpr int SHELL = 3; 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. @@ -104,7 +103,7 @@ static Vector npc_screen_position(const Vector& world, const Vector& offset) 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; + if (is_type(npc, ENTITY_SINGE, SINGE_BALL) || 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; @@ -178,7 +177,8 @@ static void needle_render(Entity_NPC& npc) 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); + 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; } @@ -204,7 +204,7 @@ static float wraith_alpha_get(RenderMode renderMode) // 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 step = vector_scale(vector_scale(npc.velocity, LAMB_AFTERIMAGE_REACH), -1.0f / LAMB_AFTERIMAGES); Vector at = npc.pos; ColorMod color = npc.sprite.color; @@ -246,7 +246,7 @@ static void minecart_riders_render(Entity_NPC& cart, const Vector& offset) 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)); + Vector shift = vector_sub(vector_sub(vector_add(npc.pos, npc.posOffset), rider->pos), rider->posOffset); rider->isVisible = true; rider->Render(vector_add(offset, vector_scale(shift, NPC_SCREEN_SCALE))); @@ -336,7 +336,7 @@ static void health_bar_render(Entity_NPC& npc, const Vector& position) float stage = (float)game.stage_depth_get(); float toughness = npc.maxHitPoints / (stage + stage + HEALTH_BAR_STAGE_BASE); - float width = std::floor((std::log10(toughness) + 1) * HEALTH_BAR_WIDTH_PER_DECADE + 0.5f); + float width = std::floor(((float)std::log10((double)toughness) + 1) * HEALTH_BAR_WIDTH_PER_DECADE + 0.5f); width = std::clamp(width, HEALTH_BAR_WIDTH_MIN, HEALTH_BAR_WIDTH_MAX); float left = position.x - width * 0.5f; float top = position.y - HEALTH_BAR_CAP; @@ -346,7 +346,8 @@ static void health_bar_render(Entity_NPC& npc, const Vector& position) image.Render(source, KAGE::Graphics::color_quad_rect(at, drawn, white), color); }; Vector capSize = vector_make(HEALTH_BAR_CAP, HEALTH_BAR_HEIGHT); - piece(vector_make(0, 0), capSize, vector_make(left - HEALTH_BAR_CAP, top), capSize, white); + Vector leftCap = vector_make(-width * 0.5f - HEALTH_BAR_CAP + position.x, top); + piece(vector_make(0, 0), capSize, leftCap, capSize, white); Vector rightCap = vector_make(HEALTH_BAR_CAP + HEALTH_BAR_MIDDLE, 0); piece(rightCap, capSize, vector_make(position.x + width * 0.5f, top), capSize, white); piece(vector_make(HEALTH_BAR_CAP, 0), vector_make(HEALTH_BAR_MIDDLE, HEALTH_BAR_HEIGHT), vector_make(left, top), @@ -566,8 +567,9 @@ static std::vector cord_points_get(Entity_NPC& npc, const Vector& off std::vector cord = {{screen.front(), 0}}; for (size_t i = 1; i + 1 < screen.size(); i++) { - Vector smoothed = vector_add(vector_scale(screen[i], CORD_SMOOTH_MIDDLE), - vector_scale(vector_add(screen[i - 1], screen[i + 1]), CORD_SMOOTH_SIDE)); + Vector smoothed = vector_make( + screen[i].x * CORD_SMOOTH_MIDDLE + screen[i - 1].x * CORD_SMOOTH_SIDE + screen[i + 1].x * CORD_SMOOTH_SIDE, + screen[i - 1].y * CORD_SMOOTH_SIDE + screen[i].y * CORD_SMOOTH_MIDDLE + screen[i + 1].y * CORD_SMOOTH_SIDE); cord.push_back({smoothed, cord.back().length + vector_length(vector_sub(cord.back().pos, smoothed))}); } cord.push_back({screen.back(), cord.back().length + vector_length(vector_sub(cord.back().pos, screen.back()))}); @@ -647,8 +649,10 @@ void Entity_NPC::RenderSegmentLink(const Vector& offset, bool isShadow) Vector start = vector_add(render_position_get(pos, RENDER_SNAPPED), offset); Vector end = vector_add(render_position_get(next->pos, RENDER_SNAPPED), offset); - start.y -= i2 == 0 ? LINK_INSET + LINK_SHELL_RAISE : LINK_INSET; - end.y -= next->i2 == 0 ? LINK_INSET + LINK_SHELL_RAISE : LINK_INSET; + start.y -= LINK_INSET; + end.y -= LINK_INSET; + if (i2 == 0) start.y -= LINK_SHELL_RAISE; + if (next->i2 == 0) end.y -= LINK_SHELL_RAISE; Vector span = vector_sub(end, start); float distance = vector_length(span); diff --git a/src/entity_npc_rewards.cpp b/src/entity_npc_rewards.cpp index 658c96f..c33cee6 100644 --- a/src/entity_npc_rewards.cpp +++ b/src/entity_npc_rewards.cpp @@ -90,7 +90,6 @@ constexpr float CANTRIPPED_CARD_SPEED = 3; constexpr std::array MAGDALENE_HEART_SHIFTS = {7, 17, 21}; constexpr std::array KEEPER_COIN_SHIFTS = {9, 11, 19}; constexpr std::array 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; @@ -499,7 +498,7 @@ static void kill_item_rewards(Entity_NPC& npc) 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 isBlessed = players.HasTemporaryEffect(g_manager->itemConfig.GetNullItem(NULLITEM_SOUL_MAGDALENE)); bool isMagdalene = std::ranges::any_of(players.playerList, [](Entity_Player* player) { diff --git a/src/entity_pickup.cpp b/src/entity_pickup.cpp index 2c0b10b..d984780 100644 --- a/src/entity_pickup.cpp +++ b/src/entity_pickup.cpp @@ -47,14 +47,11 @@ constexpr int COLLECTIBLE_MAGNETO = 53; constexpr int COLLECTIBLE_HUMBLEING_BUNDLE = 203; constexpr int COLLECTIBLE_BOGO_BOMBS = 250; constexpr int COLLECTIBLE_MAGGYS_BOW = 312; -constexpr int COLLECTIBLE_SACK_HEAD = 424; -constexpr int COLLECTIBLE_GUPPYS_EYE = 665; constexpr float OPTIONS_POOF_DROP = 10; constexpr int OPTIONS_ITEM_TIMEOUT = 4; constexpr int TRINKET_BROKEN_MAGNET = 6; constexpr int TRINKET_BIBLE_TRACT = 18; constexpr int TRINKET_MOMS_PEARL = 38; -constexpr int TRINKET_SUPER_MAGNET = 68; constexpr float VERSUS_CHEST_VOLUME = 0.7f; constexpr int TRINKET_APPLE_OF_SODOM = 140; constexpr int TRINKET_NUH_UH = 165; @@ -2119,8 +2116,8 @@ bool Entity_Pickup::HandleCollision(Entity* collider, bool isLow) // A golden penny taken comes back somewhere in the room, less likely each time (0.98 to the times it came back). static void golden_penny_return(Entity_Pickup& penny) { - constexpr double RETURN_DECAY = 0.98; - float chance = (float)std::pow(RETURN_DECAY, (double)penny.varData); + constexpr float RETURN_DECAY = 0.98f; + float chance = pow_float(RETURN_DECAY, (float)penny.varData); if (penny.dropRNG.RandomFloat() > chance) return; Room& room = *g_game->room; diff --git a/src/entity_player.cpp b/src/entity_player.cpp index ff1db99..519a3f9 100644 --- a/src/entity_player.cpp +++ b/src/entity_player.cpp @@ -334,6 +334,8 @@ void Entity_Player::stats_reset() markedTarget = nullptr; heldEntity = nullptr; tractorBeam = 0; + yesMotherKnife = nullptr; + circleOfProtection = nullptr; shootHeldFrames = 0; azazelsRageLaser = nullptr; shootDirectionHistory.clear(); @@ -1614,8 +1616,9 @@ template static void link_release(Link& link, bool isRemoveEntit link = nullptr; } -// 00757ac0 Lets go of the weapons, then of the effects the player spawned (removed when asked), the held entity (thrown -// on removal) and, unless it is being replaced, its stored helper players and its twin, removing its co-op players. +// 00757ac0 Lets go of the weapons, then of the effects the player spawned (removed when asked, all but Salvation's tether), +// the held entity (thrown on removal) and, unless it is being replaced, its stored helper players and its twin, +// removing its co-op players. The original also clears two links nothing sets (0x1420, 0x144c). void Entity_Player::release_weapons_and_effects(bool isRemoveEntities) { for (size_t slot = 1; slot <= weapons.size(); slot++) @@ -1625,31 +1628,33 @@ void Entity_Player::release_weapons_and_effects(bool isRemoveEntities) weapon.reset(); } link_release(ladder, isRemoveEntities); - link_release(azazelsRageLaser, isRemoveEntities); + link_release(trinityShield, isRemoveEntities); + link_release(spearOfDestiny, isRemoveEntities); link_release(tractorBeam, isRemoveEntities); + link_release(yesMotherKnife, isRemoveEntities); + link_release(babyFamiliar, isRemoveEntities); + link_release(deadToothRing, isRemoveEntities); link_release(dadsRingAura, isRemoveEntities); link_release(telekinesisHalo, isRemoveEntities); link_release(breathOfLifeEffect, isRemoveEntities); link_release(isaacsHeart, isRemoveEntities); - link_release(trinityShield, isRemoveEntities); - link_release(deadToothRing, isRemoveEntities); - link_release(redemptionEffect, isRemoveEntities); link_release(bestFriend, isRemoveEntities); + link_release(circleOfProtection, isRemoveEntities); link_release(megaBlastLaser, isRemoveEntities); link_release(markedTarget, isRemoveEntities); link_release(forgottenBody, isRemoveEntities); link_release(monstranceAura, isRemoveEntities); - link_release(babyFamiliar, isRemoveEntities); link_release(saturnusRing, isRemoveEntities); link_release(salvationEffect, isRemoveEntities); link_release(darkArtsAura, isRemoveEntities); - link_release(tetheredEffect, isRemoveEntities); link_release(astralProjectionBody, isRemoveEntities); + link_release(azazelsRageLaser, isRemoveEntities); link_release(montezumaLaser, isRemoveEntities); - link_release(spearOfDestiny, isRemoveEntities); + link_release(redemptionEffect, isRemoveEntities); link_release(divineShield, isRemoveEntities); link_release(darkArtsLastSnare, isRemoveEntities); link_release(darkEsau, isRemoveEntities); + tetheredEffect = nullptr; moveToTarget = {}; if (isRemoveEntities) ThrowHeldEntity(vector_make(velocity.x * HELD_RELEASE_SPEED, velocity.y * HELD_RELEASE_SPEED)); heldEntity = nullptr; diff --git a/src/entity_player.h b/src/entity_player.h index 8219be3..f688996 100644 --- a/src/entity_player.h +++ b/src/entity_player.h @@ -28,6 +28,8 @@ constexpr int COOP_BABY_BUFF_COUNT = 8; constexpr int DELAYED_SFX_FRAMES = 2; // The directions Ybab's aim axes are dealt from: right, left, down and up. constexpr int AIM_AXIS_COUNT = 4; +// The creep spots Black Powder's trail remembers, oldest first, to find a closed circle in. +constexpr int BLACK_POWDER_TRAIL_SIZE = 96; // The buffs the co-op baby skins Rage to Brown give every player (coopBabyBuffTimers), in skin order. enum CoopBabyBuff @@ -65,6 +67,10 @@ constexpr int DAEMONS_TAIL_HEART_ODDS = 5; constexpr uint32_t LUCKY_TOE_ODDS = 3; constexpr uint32_t CARD_ITEM_FLAG = 0x8000; constexpr int DEAD_CAT_LIVES = 9; +// Salvation's halo reach, and the Crack the Sky beam it holds over an enemy or a versus rival. +constexpr float SALVATION_HALO_RADIUS = 70; +constexpr int SALVATION_BEAM_SUBTYPE = 3; +constexpr float SALVATION_BEAM_DAMAGE = 3.5f; // Tainted Jacob's curse: its generator's shift, and the delays before Dark Esau charges, after a floor starts and // after becoming Tainted Jacob, in steps of a second after a least. @@ -797,6 +803,10 @@ enum PlayerItemId : int COLLECTIBLE_REMOTE_DETONATOR = 137, COLLECTIBLE_EVES_MASCARA = 310, COLLECTIBLE_SPIRIT_SWORD = 579, + COLLECTIBLE_BETRAYAL = 391, + COLLECTIBLE_SACK_HEAD = 424, + COLLECTIBLE_GUPPYS_EYE = 665, + COLLECTIBLE_GLASS_EYE = 730, TRINKET_POOL_SHIFT = 2, TRINKET_PETRIFIED_POOP = 2, TRINKET_PURPLE_HEART = 5, @@ -942,6 +952,11 @@ enum PlayerItemId : int TRINKET_TORN_CARD = 157, TRINKET_EXPANSION_PACK = 181, TRINKET_ENDLESS_NAMELESS = 79, + TRINKET_PINKY_EYE = 30, + TRINKET_PUSH_PIN = 31, + TRINKET_SUPER_MAGNET = 68, + TRINKET_DINGLE_BERRY = 163, + TRINKET_ISAACS_HEAD = 54, NULLITEM_EXPLOSIVE_DIARRHEA = 0, NULLITEM_STATUE = 4, @@ -1666,6 +1681,7 @@ public: EntityPtr babyFamiliar; EntityPtr bestFriend; EntityPtr breathOfLifeEffect; + EntityPtr circleOfProtection; EntityPtr dadsRingAura; EntityPtr darkArtsAura; EntityPtr divineShield; @@ -1682,6 +1698,7 @@ public: EntityPtr tractorBeam; EntityPtr trinityShield; EntityPtr twinPlayer; + EntityPtr yesMotherKnife; Entity_Player* backupPlayer = nullptr; Entity_Player* replacedPlayer = nullptr; Entity_Player* subPlayer = nullptr; @@ -1711,6 +1728,7 @@ public: bool isGlitchBaby = false; bool isHeldEntityVisible = false; + std::array blackPowderTrail; std::array coopBabyBuffTimers{}; std::array mirroredAimAxes{}; float darkArtsDamage = 0; @@ -1729,6 +1747,9 @@ public: uint32_t montezumaChargeTimer = 0; uint32_t revelationChargeTimer = 0; uint32_t vampireCharmKills = 0; + int blackPowderCooldown = 0; + int blackPowderHead = 0; + int blackPowderTail = 0; int bladderCharge = 0; int bleedOutHealth = 0; int cambionConceptionState = 0; diff --git a/src/entity_player_actives_rebirth.cpp b/src/entity_player_actives_rebirth.cpp index a7365ae..4a988f1 100644 --- a/src/entity_player_actives_rebirth.cpp +++ b/src/entity_player_actives_rebirth.cpp @@ -967,7 +967,8 @@ static void flush_npc(ItemUse& use, Entity_NPC& npc) for (int i = 0; i < dips; i++) { uint32_t seed = Random(); - Vector offset = vector_scale(vector_scale(random_direction(), random_unit()), npc.size); + Vector direction = random_direction(); + Vector offset = vector_scale(vector_scale(direction, random_unit()), npc.size); g_game->Spawn({.position = vector_add(npc.pos, offset), .spawner = &player, .type = ENTITY_DIP, .variant = isCorny ? DIP_CORNY : 0, .seed = seed}); } diff --git a/src/entity_player_actives_repentance.cpp b/src/entity_player_actives_repentance.cpp index f795a51..f99e1cf 100644 --- a/src/entity_player_actives_repentance.cpp +++ b/src/entity_player_actives_repentance.cpp @@ -1353,11 +1353,7 @@ static void r_key_restart(Entity_Effect*) game.playerManager.roomTransitionPlayer = nullptr; } } - for (Entity_Player* player : game.playerManager.playerList) - { - if (player->IsHoldingItem()) player->heldSprite.Reset(); - player->queuedItem = {}; - } + for (Entity_Player* player : game.playerManager.playerList) player->ClearQueueItem(); game.fadeInColor = kcolor_rgba(0, 0, 0, game.isInstantFadeIn ? INSTANT_FADE_ALPHA : 1); game.fadeSpeed = R_KEY_FADE_SPEED; game.isFadeInIconShown = true; diff --git a/src/entity_player_characters.cpp b/src/entity_player_characters.cpp index 99c31a6..de543ec 100644 --- a/src/entity_player_characters.cpp +++ b/src/entity_player_characters.cpp @@ -31,8 +31,6 @@ constexpr int BLOOD_CHARGE_CONSUMABLE = 0x100; constexpr int WHORE_OF_BABYLON_RED_HEARTS = 1; constexpr int EVE_WHORE_OF_BABYLON_RED_HEARTS = 2; constexpr int DEATHMATCH_WHORE_RED_HEARTS = 16; -constexpr int NULLITEM_SLOW_A = 62; -constexpr int NULLITEM_SLOW_B = 65; constexpr float AZAZELS_STUMP_DAMAGE_SCALE = 1.5f; // The shift Esau's share of Jacob's hearts and items is rolled with, from Clicker's seed. constexpr uint32_t ESAU_SPLIT_RNG_SHIFT = 59; @@ -259,7 +257,7 @@ bool is_character_slowed(Entity_Player& player) { TemporaryEffects& effects = player.temporaryEffects; bool isFaster = player.playerType >= PLAYER_TYPE_COUNT || speed_table_get(player) >= 0; - return isFaster && (effects.HasNullEffect(NULLITEM_SLOW_A) || effects.HasNullEffect(NULLITEM_SLOW_B)); + return isFaster && (effects.HasNullEffect(NULLITEM_REVERSE_EMPRESS) || effects.HasNullEffect(NULLITEM_REVERSE_HANGED_MAN)); } // The UpdateCostumes part (0075bf00) that redraws the player's head and body in the skin colors its costumes left it: @@ -1117,7 +1115,7 @@ static void maggy_health_drain(Entity_Player& player) // The bleeding part of 00794e50: with Anemic's effect, bleeding out from her own wound, or while Tainted Magdalene's // health drains, one frame in five drops a small spot of red creep. -static void blood_drip_update(Entity_Player& player) +void blood_drip_update(Entity_Player& player) { bool isBleeding = player.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_ANEMIC) || (player.HasEntityFlags(FLAG_BLEED_OUT) && player.bleedSource.entity == &player) || @@ -1172,7 +1170,7 @@ float damage_charge_scale() // The Berserk! charge part of 00794e50: out of Berserk!, the damage dealt this frame charges Tainted Samson's // berserk bar and any Berserk! held in an active slot. -static void berserk_charge_update(Entity_Player& player) +void berserk_charge_update(Entity_Player& player) { bool isCharging = player.HasCollectible(COLLECTIBLE_BERSERK) || player.playerType == PLAYER_SAMSON_B; if (!isCharging || player.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_BERSERK)) return; @@ -1186,14 +1184,11 @@ static void berserk_charge_update(Entity_Player& player) charge -= player.AddActiveCharge(charge, slot, false, false, true); } -// The characters' pieces of a whole frame the plain frame runs, with the items' frame (00794e50): Tainted Magdalene's -// drain and its drip, and the Berserk! charge. +// Tainted Magdalene's drain, the characters' piece of the whole frame the plain frame runs. Her drip, the Berserk! +// charge and Tainted ???'s poop charge run in the items' frame (items_frame_update). void character_frame_update(Entity_Player& player) { maggy_health_drain(player); - blood_drip_update(player); - berserk_charge_update(player); - blue_baby_poop_update(player); } // Tainted Magdalene's hug, part of 0078e1f0: touching a vulnerable enemy that is not a friend, with the last swing diff --git a/src/entity_player_characters.h b/src/entity_player_characters.h index 9d03f09..1c0cc83 100644 --- a/src/entity_player_characters.h +++ b/src/entity_player_characters.h @@ -72,6 +72,8 @@ bool is_maggy_draining(Entity_Player& player); // The characters' own parts of a whole frame (00782af0, 00794e50) and Tainted Magdalene's part of a touch (0078e1f0). void character_frame_update(Entity_Player& player); +void blood_drip_update(Entity_Player& player); +void berserk_charge_update(Entity_Player& player); void tainted_magdalene_hug(Entity_Player& player, Entity& collider); // Eden's rolled stat offsets, and Tainted Eden's glitch on a penalised hit (part of 007729d0). diff --git a/src/entity_player_collectibles.cpp b/src/entity_player_collectibles.cpp index f6dd729..b72210b 100644 --- a/src/entity_player_collectibles.cpp +++ b/src/entity_player_collectibles.cpp @@ -399,7 +399,7 @@ static void reverse_stars_end(Entity_Player& player) if (!player.bodySprite.IsPlaying("Pickup") && !player.bodySprite.IsPlaying("Pickup_Online")) return; player.heldSprite.Reset(); - const AnimationFrame* frame = player.bodySprite.animState.GetLayerFrame(0); + const NullFrame* frame = player.bodySprite.GetNullFrameById(0); if (!frame) return; Entity* poof = g_game->Spawn({.position = player.pos, .type = ENTITY_EFFECT, .variant = EFFECT_POOF01, .seed = Random()}); poof->sprite.offset = vector_make(player.sprite.scale.x * frame->pos.x, player.sprite.scale.y * frame->pos.y); diff --git a/src/entity_player_costumes.cpp b/src/entity_player_costumes.cpp index e4253c4..8e8e357 100644 --- a/src/entity_player_costumes.cpp +++ b/src/entity_player_costumes.cpp @@ -111,7 +111,7 @@ static void adrenaline_look_read(Entity_Player& player, LayerLook& look) int frame = g_game->frameCount; auto beat = [rate](int at) { float wave = (std::sin((float)at * rate) * 0.5f + 0.5f) * ADRENALINE_BEAT_SCALE; - return std::pow(wave, 2.0f) - ADRENALINE_BEAT_FLOOR; + return pow_float(wave, 2) - ADRENALINE_BEAT_FLOOR; }; float pulse = beat(frame) * swing + 1; @@ -224,7 +224,8 @@ static void hot_potato_explode(Entity_Player& player) .radiusMultiplier = HOT_POTATO_RADIUS, .isDamageSource = true}); player.velocity = {}; - Vector knock = vector_scale(random_direction(), random_unit() * HOT_POTATO_KNOCK_RANGE + HOT_POTATO_KNOCK_MIN); + Vector direction = random_direction(); + Vector knock = vector_scale(direction, random_unit() * HOT_POTATO_KNOCK_RANGE + HOT_POTATO_KNOCK_MIN); player.TryThrow(EntityRef(), knock, HOT_POTATO_KNOCK_HEIGHT); } diff --git a/src/entity_player_damage.cpp b/src/entity_player_damage.cpp index fe8606d..4a169f2 100644 --- a/src/entity_player_damage.cpp +++ b/src/entity_player_damage.cpp @@ -37,7 +37,6 @@ constexpr int TRINKET_CROW_HEART = 107; constexpr int TRINKET_FINGER_BONE = 128; constexpr int TRINKET_SWALLOWED_M80 = 178; constexpr int TRINKET_WALNUT = 108; -constexpr int NULLITEM_DOUBLE_DAMAGE = 29; constexpr int SAMSON_B_HIT_CHARGE = 10000; constexpr int SIREN_CHARM_SPARE_FRAMES = 29; @@ -113,8 +112,6 @@ constexpr float VOICE_PITCH_STEP = 0.2f; constexpr float VOICE_PITCH_MIN = 0.5f; constexpr float VOICE_PITCH_MAX = 2; constexpr float REMOTE_VOLUME_SCALE = 0.1f; -constexpr int PILL_EFFECT_PUBERTY = 33; -constexpr int PILL_EFFECT_HELIUM = 32; // The extra lives the HUD counts: 1up!, Ankh, Guppy's Collar, Judas' Shadow, Lazarus' Rags and Inner Child. constexpr int EXTRA_LIFE_ITEMS[] = {11, 161, 212, 311, 332, 688}; @@ -127,7 +124,6 @@ constexpr int EVIL_CHARM_GRID_VARIANT = 10000; // The temporary effects that make the player invincible to any hit: Gamekid, My Little Unicorn, Unicorn Stump and // Teleport. constexpr int INVINCIBLE_EFFECTS[] = {93, 77, 298, 44}; -constexpr int NULLITEM_INVINCIBLE_SHIELD = 59; constexpr int BLOOD_DONATION_VARIANT = 2; constexpr int BLOOD_BANK_VARIANT = 5; constexpr float GNAWED_LEAF_MASS = 1000; @@ -451,7 +447,7 @@ static int damage_amount_get(Entity_Player& player, float damage, uint64_t damag (player.HasCollectible(COLLECTIBLE_DOGMA) && !isHardMode); if (isHalved && amount > 1) amount = std::max((int)((float)amount * (isDeathmatch ? HALVED_DAMAGE_DEATHMATCH : HALVED_DAMAGE) + DAMAGE_ROUNDING), 1); - if (player.temporaryEffects.HasNullEffect(NULLITEM_DOUBLE_DAMAGE)) + if (player.temporaryEffects.HasNullEffect(NULLITEM_OVERDOSE)) amount = (int)((float)std::max(amount, 2) * (isDeathmatch ? DOUBLED_DAMAGE_DEATHMATCH : 1)); if (player.GetHealthType() == HEALTH_COIN) amount = 2; if (game.seedEffects.HasSeedEffect(SEED_ISAAC_TAKES_HIGH_DAMAGE)) amount = std::max(amount, 2); @@ -1239,7 +1235,7 @@ bool Entity_Player::HasInvincibility(uint64_t damageFlags, const EntityRef& sour isInvincible = std::ranges::any_of(INVINCIBLE_EFFECTS, [&](int item) { return effects.HasCollectibleEffect(item); }) || (HasCollectible(COLLECTIBLE_GNAWED_LEAF) && mass == GNAWED_LEAF_MASS && !isRedHit) || effects.HasCollectibleEffect(COLLECTIBLE_BREATH_OF_LIFE) || (taurus && taurus->cooldown != 0) || - (effects.HasNullEffect(NULLITEM_INVINCIBLE_SHIELD) && !isRedHit) || + (effects.HasNullEffect(NULLITEM_TOOTH_AND_NAIL_STATUE) && !isRedHit) || (effects.HasNullEffect(NULLITEM_REVERSE_CHARIOT) && !isRedHit) || ((effects.HasCollectibleEffect(COLLECTIBLE_DARK_ARTS) || isDarkArtsBlastPending) && !isRedHit) || (suplexState != 0 && !isRedHit) || effects.HasCollectibleEffect(COLLECTIBLE_MEGA_MUSH); @@ -1278,7 +1274,7 @@ float Entity_Player::get_voice_pitch() { float pitch = variant == PLAYER_VARIANT_PLAYER ? VOICE_PITCH_PLAYER : VOICE_PITCH_BABY; - pitch += (float)(pillEffectUses[PILL_EFFECT_PUBERTY] - pillEffectUses[PILL_EFFECT_HELIUM]) * VOICE_PITCH_PER_PILL; + pitch += (float)(pillEffectUses[PILLEFFECT_SMALLER] - pillEffectUses[PILLEFFECT_LARGER]) * VOICE_PITCH_PER_PILL; if (HasCollectible(COLLECTIBLE_PLUTO) || temporaryEffects.HasCollectibleEffect(COLLECTIBLE_INNER_CHILD)) pitch += VOICE_PITCH_PLUTO; if (HasCollectible(COLLECTIBLE_BINKY)) pitch += VOICE_PITCH_STEP; diff --git a/src/entity_player_effects.cpp b/src/entity_player_effects.cpp index 6c6c5cc..aef3df1 100644 --- a/src/entity_player_effects.cpp +++ b/src/entity_player_effects.cpp @@ -9,6 +9,13 @@ #include "entity_player.h" #include "entity_laser.h" #include "entity_player_characters.h" +#include "entity_player_passives.h" +#include "entity_player_trinkets.h" +#include "entity_knife.h" +#include "active_items.h" +#include "netplay_manager.h" +#include "platform.h" +#include "tainted_characters.h" #include "entity_projectile.h" #include "entity_tear.h" #include "entity_slot.h" @@ -49,6 +56,8 @@ constexpr int MEGA_BLAST_TAIL_FRAMES = 15; constexpr float MEGA_BLAST_DAMAGE_SCALE = 5; constexpr int RAGE_HEAD_SHOOT_FRAME = 15; constexpr int RAGE_HEAD_REWIND_FRAME = 8; +// Azazel's Rage's rooms gathered while its beam fires. +constexpr int RAGE_FIRING = 5; // The pit at a cell, or null off the grid or on any other grid entity. static GridEntity_Pit* pit_at(Room& room, int gridIndex) @@ -158,6 +167,8 @@ constexpr float VOLT_REACH = 60; constexpr float VOLT_DAMAGE = 0.75f; constexpr float MONSTRANCE_RADIUS = 90; constexpr float MONSTRANCE_PERIOD = 4; +constexpr float MONSTRANCE_VERSUS_PERIOD = 12; +constexpr float MONSTRANCE_VERSUS_SCALE = 2; constexpr LerpRange MONSTRANCE_FALLOFF = {.inMin = 30, .inMax = 90, .outMin = 0, .outMax = 0.4f}; constexpr float MONSTRANCE_STAGE_DAMAGE = 0.32f; constexpr float MONSTRANCE_BASE_DAMAGE = 3.6f; @@ -359,6 +370,27 @@ static void crack_the_sky_update(Entity_Player& player) beam->parent = &player; } +// Explosive Diarrhea drops a bomb (a butt bomb for Tainted ???) with the player's bomb effects every tenth frame it +// has left. Stacked, the bombs home and grow by half. +static void explosive_diarrhea_update(Entity_Player& player) +{ + constexpr int DIARRHEA_BOMB_PERIOD = 10; + constexpr float DIARRHEA_STACKED_SCALE = 1.5f; + TemporaryEffect* diarrhea = player.temporaryEffects.GetNullEffect(NULLITEM_EXPLOSIVE_DIARRHEA); + if (!diarrhea || diarrhea->cooldown % DIARRHEA_BOMB_PERIOD != 0) return; + + int variant = player.playerType == PLAYER_BLUEBABY_B ? BOMB_BUTT : BOMB_NORMAL; + Entity* spawned = g_game->Spawn({.position = player.pos, .spawner = &player, .type = ENTITY_BOMB, + .variant = variant, .seed = Random()}); + if (spawned->type != ENTITY_BOMB) return; + auto& bomb = *static_cast(spawned); + bomb.tearFlags = player.GetBombFlags(false); + bomb.isLoadCostumes = true; + if (diarrhea->count <= 1) return; + bomb.tearFlags.set(TEAR_HOMING); + bomb.scale = DIARRHEA_STACKED_SCALE; +} + // Relax: every other frame it lasts, a poop drops where the player stands on an empty, decorated or webbed cell // (not in a crawl space), with a fart and the candle Bird's Eye or Ghost Pepper fires. Hallowed Ground makes it holy // one time in three, Meconium black (33, 66 or 100 in 100 by its copies) and Midas' Touch golden (luck helps). @@ -502,8 +534,10 @@ static void breath_of_life_update(Entity_Player& player) } // Faded Polaroid every 300 frames, one time in five, fades the player for 3 to 7 seconds (times its multiplier). +// In a versus match the rivals are confused for 3 seconds. static void faded_polaroid_update(Entity_Player& player) { + constexpr int POLAROID_VERSUS_CONFUSION = 90; constexpr int POLAROID_PERIOD = 300; constexpr int POLAROID_ODDS = 5; constexpr int POLAROID_SECONDS_MIN = 3; @@ -516,6 +550,15 @@ static void faded_polaroid_update(Entity_Player& player) int multiplier = player.GetTrinketMultiplier(TRINKET_FADED_POLAROID); fade.cooldown = multiplier * (random_below(POLAROID_SECONDS_RANGE) + POLAROID_SECONDS_MIN) * FRAMES_PER_SECOND; effects.AddEffect(fade, true, 1); + if (!g_game->deathmatchManager.is_active()) return; + + PlayerManager& players = g_game->playerManager; + for (size_t i = 0; i < players.playerList.size(); i++) + { + Entity_Player* rival = players.GetPlayer((int)i); + if (rival != &player && rival != player.twinPlayer.get()) + rival->AddConfusion(EntityRef(&player), POLAROID_VERSUS_CONFUSION, false); + } } // Empty Vessel: without red hearts the player flies (with its costume), and while it flies a room still fighting @@ -763,13 +806,11 @@ static void azazels_rage_steer(Entity_Player& player) } // Azazel's Rage: on a room's third frame (or once its beam is spent) the rage ends with the item gone. With four -// rooms gathered, a room still fighting (an ambush not yet over) unleashes its beam. A spent beam's rage settles back -// into the item's costume. +// rooms gathered, a room still fighting (an ambush not yet over) unleashes its beam. static void azazels_rage_update(Entity_Player& player) { constexpr int RAGE_ROOM_FRAME = 3; constexpr int RAGE_READY = 4; - constexpr int RAGE_FIRING = 5; constexpr int RAGE_FIRED = 6; TemporaryEffects& effects = player.temporaryEffects; ItemConfig& config = g_manager->itemConfig; @@ -795,6 +836,13 @@ static void azazels_rage_update(Entity_Player& player) } } } +} + +// Azazel's Rage's spent beam settles the rage back into the item's costume, after the beam's steering. +static void azazels_rage_end_update(Entity_Player& player) +{ + TemporaryEffects& effects = player.temporaryEffects; + ItemConfig& config = g_manager->itemConfig; if (effects.GetCollectibleEffectNum(COLLECTIBLE_AZAZELS_RAGE) <= RAGE_FIRING || player.azazelsRageLaser) return; effects.RemoveCollectibleEffect(COLLECTIBLE_AZAZELS_RAGE, -1); player.RemoveCostume(config.GetNullItem(NULLITEM_AZAZELS_RAGE_4)); @@ -890,16 +938,19 @@ static void spooky_venus_update(Entity_Player& player) bool isVenus = player.HasCollectible(COLLECTIBLE_VENUS); if (!isSpooky && !isVenus) return; - for (Entity* enemy : entity_query_radius(player.pos, isVenus ? VENUS_RADIUS : SPOOKY_RADIUS, QUERY_ENEMIES)) + bool isVersus = g_game->deathmatchManager.is_active(); + float radius = isVenus && !isVersus ? VENUS_RADIUS : SPOOKY_RADIUS; + for (Entity* enemy : entity_query_radius(player.pos, radius, QUERY_ENEMIES)) { if (!enemy->IsVulnerableEnemy(nullptr) || enemy == &player) continue; bool isBoss = enemy->IsBoss(); + bool isRival = isVersus && enemy->is_player(); int charm = isBoss ? VENUS_CHARM_FRAMES : VENUS_CHARM_FRAMES - enemy->charmedCountdown; - if (isVenus && charm >= 1) enemy->AddCharmed(EntityRef(&player), charm, false, false); + if (isVenus && charm >= 1) enemy->AddCharmed(EntityRef(&player), charm, isRival && !isBoss, false); if (!isSpooky) continue; float distanceSquared = vector_length_squared(vector_sub(enemy->pos, player.pos)); if (isVenus && enemy->size + SPOOKY_FEAR_REACH < distanceSquared) continue; - enemy->AddFear(EntityRef(&player), isBoss ? SPOOKY_BOSS_FEAR_FRAMES : SPOOKY_FEAR_FRAMES, false); + enemy->AddFear(EntityRef(&player), isBoss ? SPOOKY_BOSS_FEAR_FRAMES : SPOOKY_FEAR_FRAMES, isRival && !isBoss); } } @@ -923,10 +974,12 @@ static void volt_120_update(Entity_Player& player) static void monstrance_update(Entity_Player& player) { bool isWorn = player.HasCollectible(COLLECTIBLE_MONSTRANCE) && !g_game->room->isPacifist; - if (isWorn && player.GetIntervalTicks(MONSTRANCE_PERIOD, 0) != 0) + bool isVersus = g_game->deathmatchManager.is_active(); + if (isWorn && player.GetIntervalTicks(isVersus ? MONSTRANCE_VERSUS_PERIOD : MONSTRANCE_PERIOD, 0) != 0) { LerpRange falloff = MONSTRANCE_FALLOFF; - falloff.outMin = (float)g_game->stage * MONSTRANCE_STAGE_DAMAGE + MONSTRANCE_BASE_DAMAGE; + float baseScale = isVersus ? MONSTRANCE_VERSUS_SCALE : 1; + falloff.outMin = (float)g_game->stage * MONSTRANCE_STAGE_DAMAGE + baseScale * MONSTRANCE_BASE_DAMAGE; for (Entity* enemy : entity_query_radius(player.pos, MONSTRANCE_RADIUS, QUERY_ENEMIES)) { if (!enemy->IsVulnerableEnemy(nullptr) || enemy == &player) continue; @@ -950,7 +1003,7 @@ static void mars_recharge_update(Entity_Player& player) if (!player.isMarsDashReady) { player.isMarsDashReady = true; - player.ClearEntityFlags(FLAG_NO_PHYSICS_KNOCKBACK); + player.ClearEntityFlags(FLAG_NO_DAMAGE_BLINK); player.SetMinDamageCooldown(MARS_READY_DAMAGE_COOLDOWN); } player.marsDashDirection = -1; @@ -1564,27 +1617,435 @@ static void volt_45_charge_update(Entity_Player& player) } } -// The written pieces of the items' frame (update_effects 00794e50) the plain path runs after its others, in their -// order there. +// In the Beast's crawlspace at Home, a Glowing Hour Glass with uses spent is filled back to three, fully charged. +static void beast_room_hourglass_update(Entity_Player& player) +{ + constexpr int BEAST_ROOM_HOURGLASS_USES = 3; + RoomConfig_Room* config = g_game->room->descriptor->data; + if (!config || config->type != ROOM_DUNGEON || config->stageId != STAGE_ID_HOME) return; + + for (int slot = 0; slot < ACTIVE_SLOT_COUNT; slot++) + { + ActiveItemDesc& active = player.activeItems[slot]; + if (active.item != COLLECTIBLE_GLOWING_HOUR_GLASS || active.varData >= BEAST_ROOM_HOURGLASS_USES) continue; + active.varData = BEAST_ROOM_HOURGLASS_USES; + player.FullCharge(slot, false, false); + } +} + +// Lazarus risen, once he holds Anemia, always bleeds. +static void lazarus_anemic_update(Entity_Player& player) +{ + TemporaryEffects& effects = player.temporaryEffects; + if (player.playerType != PLAYER_LAZARUS2 || + !g_manager->persistentGameData.Unlocked(ACHIEVEMENT_LAZARUS_HOLDS_ANEMIA) || + effects.HasCollectibleEffect(COLLECTIBLE_ANEMIC)) + return; + effects.AddCollectibleEffect(COLLECTIBLE_ANEMIC, true, 1); +} + +// The opacity of a player's shots: a remote online player's fade with the options, the rest are whole. +static float shot_alpha_get(Entity_Player& player) +{ + NetplayManager& netplay = g_manager->netplayManager; + if (!netplay.is_online() || netplay.IsIdxLocalPlayer(player.controllerIndex) || g_game->deathmatchManager.is_active()) + return 1; + return tear_remote_opacity_get(); +} + +// The transformations' pieces: Oh Crap! poops by itself now and then in a room still fighting, and Yes Mother? +// chains Mom's Knife to the player, with its tear look, effects and damage. +static void forms_frame_update(Entity_Player& player) +{ + constexpr int OH_CRAP_PERIOD = 1800; + constexpr int OH_CRAP_ODDS = 15; + constexpr float KNIFE_RISE = -10; + if (player.HasPlayerForm(PLAYER_FORM_OH_CRAP) && player.IsFrame(OH_CRAP_PERIOD, 0) && + random_below(OH_CRAP_ODDS) == 0 && !g_game->room->IsClear()) + player.UseActiveItem({.item = COLLECTIBLE_POOP, .flags = USE_NOANIM}); + if (!player.HasPlayerForm(PLAYER_FORM_YES_MOTHER) || player.yesMotherKnife) return; + + Entity* knife = g_game->Spawn({.position = player.pos, .spawner = &player, .subType = KNIFE_SUBTYPE_CHAINED, + .type = ENTITY_KNIFE, .variant = KNIFE_MOMS_KNIFE, .seed = Random()}); + knife->parent = &player; + knife->posOffset = vector_make(0, KNIFE_RISE); + ColorMod color = player.tearColor; + color._tint[3] *= shot_alpha_get(player); + knife->SetColor(color, -1, COLOR_PRIORITY_DEFAULT, false, true); + static_cast(knife)->tearFlags = player.tearFlags; + knife->SetCollisionDamage(player.damage); + knife->AddEntityFlags(FLAG_DONT_OVERWRITE); + player.yesMotherKnife = knife; + knife->Update(); +} + +// Bob's transformation leaves a spot of green creep every fifth frame. +static void bob_creep_update(Entity_Player& player) +{ + constexpr int BOB_CREEP_PERIOD = 5; + constexpr ColorMod BOB_GREEN = {{0, 1, 1, 1}, {0, 0, 0, 0}, {0, 100 * BYTE_TO_UNIT, 0}}; + if (!player.HasPlayerForm(PLAYER_FORM_BOB) || !player.IsFrame(BOB_CREEP_PERIOD, 0)) return; + + Entity* creep = creep_drop(player, EFFECT_PLAYER_CREEP_RED); + creep->SetColor(BOB_GREEN, -1, COLOR_PRIORITY_DEFAULT, false, true); + creep->Update(); +} + +// Night Light: enemies in its cone are slowed (a versus rival a frame less while already slowed), and the enemy +// shots and the others' tears crossing it are slowed to half speed once. +static void night_light_update(Entity_Player& player) +{ + constexpr float NIGHT_LIGHT_REACH = 200; + constexpr int NIGHT_LIGHT_SLOW_FRAMES = 2; + constexpr float NIGHT_LIGHT_SLOW = 0.9f; + constexpr float NIGHT_LIGHT_SHOT_SLOW = 0.5f; + constexpr float NIGHT_LIGHT_GLOW = 40 * BYTE_TO_UNIT; + constexpr ColorMod NIGHT_LIGHT_TINT = {{1, 1, 1.3f, 1}, {0, 0, 0, 0}, {NIGHT_LIGHT_GLOW, NIGHT_LIGHT_GLOW, NIGHT_LIGHT_GLOW}}; + if (!player.HasCollectible(COLLECTIBLE_NIGHT_LIGHT)) return; + + bool isVersus = g_game->deathmatchManager.is_active(); + uint32_t partitions = QUERY_ENEMIES | QUERY_PROJECTILES | (isVersus ? QUERY_TEARS : 0); + for (Entity* entity : entity_query_radius(player.pos, NIGHT_LIGHT_REACH, partitions)) + { + if (entity->IsVulnerableEnemy(nullptr) && player.IsPosInSpotLight(entity->pos)) + { + int frames = isVersus && entity->slowingCountdown != 0 ? NIGHT_LIGHT_SLOW_FRAMES - 1 : NIGHT_LIGHT_SLOW_FRAMES; + entity->AddSlowing(EntityRef(&player), frames, NIGHT_LIGHT_SLOW, NIGHT_LIGHT_TINT, isVersus); + } + else if (entity->type == ENTITY_PROJECTILE) + { + auto* shot = static_cast(entity); + if (!player.IsPosInSpotLight(shot->pos) || (shot->projectileFlags & PROJECTILE_SLOWED)) continue; + shot->velocity = vector_scale(shot->velocity, NIGHT_LIGHT_SHOT_SLOW); + shot->projectileFlags |= PROJECTILE_SLOWED; + } + else if (entity->type == ENTITY_TEAR && !entity->IsDescendantOf(&player) && player.IsPosInSpotLight(entity->pos)) + { + auto* tear = static_cast(entity); + if (tear->tearFlags[TEAR_GROW]) continue; + tear->velocity = vector_scale(tear->velocity, NIGHT_LIGHT_SHOT_SLOW); + TearFlags flags = tear->tearFlags; + flags.set(TEAR_GROW); + tear->SetTearFlags(flags); + } + } +} + +// Circle of Protection keeps a ring of light around the player, hurting with its laser damage each frame. Without the +// item the ring goes. +static void circle_of_protection_update(Entity_Player& player) +{ + constexpr float PROTECTION_RING_RISE = -20; + constexpr float PROTECTION_RING_DEPTH = 3000; + if (!player.HasCollectible(COLLECTIBLE_CIRCLE_OF_PROTECTION)) + { + if (Entity* ring = player.circleOfProtection.get()) ring->Remove(); + return; + } + Entity* ring = player.circleOfProtection.get(); + bool isSpawned = !ring; + if (isSpawned) + { + ring = g_game->Spawn({.position = player.pos, .spawner = &player, .subType = LASER_SUBTYPE_RING_FOLLOW_PARENT, + .type = ENTITY_LASER, .variant = LASER_LIGHT_RING, .seed = Random()}); + ring->posOffset = vector_make(0, PROTECTION_RING_RISE); + ring->parent = &player; + ring->spawnerEntity = &player; + ring->renderDepthOffset = PROTECTION_RING_DEPTH; + } + int displacement = random_below(2) * 2 - 1; + ring->SetCollisionDamage(player.GetTearHitParams(WEAPON_LASER, 1, displacement, nullptr).tearDamage); + if (!isSpawned) return; + ring->Update(); + player.circleOfProtection = ring; +} + +// Black Powder's sum over its trail from one spot to the newest: the farthest squared distance from the player (halved, +// the circle's squared radius) and the trail's middle. +struct PowderCircle +{ + Vector center{}; + float radiusSquared = 0; + int start = 0; +}; + +// Whether the trail from a spot closes a circle around the player: wide enough, and with at most a quarter of its +// spots near its middle. +static bool is_powder_circle(Entity_Player& player, PowderCircle& circle) +{ + constexpr float CIRCLE_MIN_SQUARED = 2500; + constexpr float CIRCLE_INNER_SHARE = 0.25f; + std::array& trail = player.blackPowderTrail; + int tail = player.blackPowderTail; + + circle.radiusSquared = 0; + for (int i = circle.start; i != tail; i = (i + 1) % BLACK_POWDER_TRAIL_SIZE) + if (Entity* spot = trail[i].get()) + circle.radiusSquared = std::max(circle.radiusSquared, vector_length_squared(vector_sub(spot->pos, player.pos))); + circle.radiusSquared *= HALF; + if (circle.radiusSquared < CIRCLE_MIN_SQUARED) return false; + + int count = tail - circle.start; + if (count < 0) count += BLACK_POWDER_TRAIL_SIZE; + circle.center = {}; + for (int i = circle.start; i != tail; i = (i + 1) % BLACK_POWDER_TRAIL_SIZE) + if (Entity* spot = trail[i].get()) circle.center = vector_add(circle.center, spot->pos); + circle.center = vector_scale(circle.center, 1.0f / (float)count); + + int inner = 0; + bool isClosed = true; + for (int i = circle.start; i != tail; i = (i + 1) % BLACK_POWDER_TRAIL_SIZE) + { + Entity* spot = trail[i].get(); + if (!spot || vector_length_squared(vector_sub(spot->pos, circle.center)) / circle.radiusSquared >= CIRCLE_INNER_SHARE) + continue; + if ((float)++inner > (float)count * CIRCLE_INNER_SHARE) isClosed = false; + } + return isClosed; +} + +// Black Powder: the player trails black powder (a spot when it moved 10 away from the last, 95 at most). Once the +// trail holds 12, a spot of its older half lit and near the player that starts a closed circle lights a pentagram +// over its middle, 45 frames before the trail goes on. +static void black_powder_update(Entity_Player& player) +{ + constexpr float POWDER_STEP_SQUARED = 100; + constexpr int POWDER_TRAIL_MAX = 95; + constexpr int POWDER_SPOT_FRAMES = 60; + constexpr int POWDER_CIRCLE_MIN = 12; + constexpr float POWDER_LIT_ALPHA = 0.5f; + constexpr float POWDER_START_SQUARED = 400; + constexpr int PENTAGRAM_COOLDOWN = 45; + if (!player.HasCollectible(COLLECTIBLE_BLACK_POWDER)) return; + if (player.blackPowderCooldown > 0) + { + player.blackPowderCooldown--; + return; + } + + std::array& trail = player.blackPowderTrail; + int& head = player.blackPowderHead; + int& tail = player.blackPowderTail; + while (!trail[head] && head != tail) head = (head + 1) % BLACK_POWDER_TRAIL_SIZE; + int count = tail - head; + if (count < 0) count += BLACK_POWDER_TRAIL_SIZE; + if (count >= POWDER_TRAIL_MAX) return; + Entity* last = count > 0 ? trail[(tail + POWDER_TRAIL_MAX) % BLACK_POWDER_TRAIL_SIZE].get() : nullptr; + if (last && !last->isDead && vector_length_squared(vector_sub(player.pos, last->pos)) < POWDER_STEP_SQUARED) return; + + auto* spot = static_cast(g_game->Spawn({.position = player.pos, .spawner = &player, + .type = ENTITY_EFFECT, + .variant = EFFECT_PLAYER_CREEP_BLACKPOWDER, .seed = Random()})); + spot->SetTimeout(POWDER_SPOT_FRAMES); + spot->Update(); + trail[tail] = spot; + tail = (tail + 1) % BLACK_POWDER_TRAIL_SIZE; + if (count < POWDER_CIRCLE_MIN) return; + + PowderCircle circle; + bool isFound = false; + for (int step = count / 2; step >= 0 && !isFound; step--) + { + circle.start = (head + step) % BLACK_POWDER_TRAIL_SIZE; + Entity* start = trail[circle.start].get(); + if (!start || start->sprite.color._tint[3] < POWDER_LIT_ALPHA || + vector_length_squared(vector_sub(start->pos, player.pos)) >= POWDER_START_SQUARED) + continue; + isFound = is_powder_circle(player, circle); + } + if (!isFound) return; + + float radius = std::sqrt(circle.radiusSquared); + auto* pentagram = static_cast(g_game->Spawn({.position = circle.center, .spawner = &player, + .type = ENTITY_EFFECT, + .variant = EFFECT_PENTAGRAM_BLACKPOWDER, .seed = Random()})); + pentagram->scale = radius; + pentagram->Update(); + player.blackPowderCooldown = PENTAGRAM_COOLDOWN; + log_printf(LOG_INFO, "closed black powder circle at %.2f, %.2f with radius %.2f\n", circle.center.x, circle.center.y, + radius); +} + +// Kidney Stone blocks the urethra again, for one to three seconds of bladder, once its burst is over and its time has +// come, while the weapon can pass the stone. Otherwise it stays open. +static void kidney_stone_update(Entity_Player& player) +{ + constexpr int BLADDER_SECONDS = 3; + Weapon* weapon = player.weapons[0] ? player.weapons[0].get() : player.weapons[1].get(); + if (!weapon || !player.HasCollectible(COLLECTIBLE_KIDNEY_STONE) || !weapon->CanTriggerKidneyStone()) + { + player.isUrethraBlocked = false; + return; + } + if (player.peeBurstCooldown >= 1 || player.isUrethraBlocked || player.nextUrethraBlockFrame > g_game->frameCount) return; + player.isUrethraBlocked = true; + player.maxBladderCharge = (random_below(BLADDER_SECONDS) + 1) * FRAMES_PER_SECOND; + player.bladderCharge = 0; +} + +// Dark Prince's Crown glows while its condition holds, and sits a little lower under a Crown of Light. +static void dark_princes_crown_update(Entity_Player& player) +{ + constexpr float UNDER_CROWN_OFFSET = -7; + if (!player.HasCollectible(COLLECTIBLE_DARK_PRINCES_CROWN)) return; + crown_glow_set(player, COLLECTIBLE_DARK_PRINCES_CROWN, player.darkPrincesCrownSprite, is_dark_prince_lit(player)); + player.darkPrincesCrownSprite.offset = + player.HasCollectible(COLLECTIBLE_CROWN_OF_LIGHT) ? vector_make(0, UNDER_CROWN_OFFSET) : Vector{}; +} + +// Bozo every fifth frame gives each enemy not the player's own one chance in 700 to be charmed or frightened for 220 +// frames. +static void bozo_update(Entity_Player& player) +{ + constexpr int BOZO_SPELL_PERIOD = 5; + constexpr int BOZO_SPELL_ODDS = 700; + constexpr int BOZO_SPELL_FRAMES = 220; + if (!player.HasCollectible(COLLECTIBLE_BOZO) || !player.IsFrame(BOZO_SPELL_PERIOD, 0)) return; + + EntityList_EL entities = g_game->room->entityList.updateEL; + for (Entity* entity : entities) + { + if (!entity->IsVulnerableEnemy(nullptr) || entity->IsDescendantOf(&player) || random_below(BOZO_SPELL_ODDS) != 0) + continue; + if (random_below(2) == 0) entity->AddCharmed(EntityRef(&player), BOZO_SPELL_FRAMES, false, false); + else entity->AddFear(EntityRef(&player), BOZO_SPELL_FRAMES, false); + } +} + +// Red Stew's damage runs down with the ticks passed, the stats evaluated each time it drops a step of 10. +static void red_stew_update(Entity_Player& player) +{ + constexpr int RED_STEW_STEP = 10; + int left = player.redStewBonusDuration; + if (left <= 0) return; + player.redStewBonusDuration = std::max(left - player.update_ticks_get(), 0); + if (player.redStewBonusDuration / RED_STEW_STEP >= left / RED_STEW_STEP) return; + player.temporaryEffects.isEvaluateCachePending = true; + player.temporaryEffects.cacheFlags |= CACHE_DAMAGE; +} + +// Stompy's transformation kicks up a cloud of dust every fifth frame it walks. +static void stompy_dust_update(Entity_Player& player) +{ + constexpr int STOMPY_DUST_PERIOD = 5; + constexpr float STOMPY_DUST_DRAG = 0.7f; + constexpr float STOMPY_DUST_SPREAD = 20; + constexpr float STOMPY_DUST_SPIN = 5; + constexpr int STOMPY_DUST_FRAMES = 15; + if (!player.HasPlayerForm(PLAYER_FORM_STOMPY) || vector_length_squared(player.velocity) <= 1 || + !player.IsFrame(STOMPY_DUST_PERIOD, 0)) + return; + + uint32_t seed = Random(); + Vector velocity = vector_scale(player.velocity, STOMPY_DUST_DRAG); + Vector spread = random_direction(); + Vector at = vector_add(player.pos, vector_scale(spread, random_unit() * STOMPY_DUST_SPREAD)); + auto* dust = static_cast(g_game->Spawn({.position = at, .velocity = velocity, + .type = ENTITY_EFFECT, .variant = EFFECT_DUST_CLOUD, + .seed = seed})); + float turn = random_below(2) == 0 ? 1.0f : -1.0f; + dust->rotation = random_unit() * STOMPY_DUST_SPIN * turn; + dust->SetTimeout(random_below(STOMPY_DUST_FRAMES) + STOMPY_DUST_FRAMES); + dust->Update(); +} + +// The versus pieces: Swarm adds a fly every 300 frames, the nearest rival Salvation's ring holds the player under its +// beam (lit while it lasts), and Dirty Mind calls a dip every 210 ticks. +static void versus_items_update(Entity_Player& player) +{ + constexpr int SWARM_PERIOD = 300; + constexpr float RIVAL_SALVATION_FAR = 1e9f; + constexpr float DIP_INTERVAL = 210; + constexpr std::array, 5> DIP_ROLLS = {{{30, 0}, {44, 1}, {58, 13}, {72, 3}, {86, 4}}}; + constexpr int DIP_LAST = 6; + Game& game = *g_game; + if (!game.deathmatchManager.is_active()) return; + + if (player.HasCollectible(COLLECTIBLE_SWARM) && player.IsFrame(SWARM_PERIOD, 0)) player.AddSwarmFlyOrbital(player.pos); + if (!player.isDead && player.variant == PLAYER_VARIANT_PLAYER && !player.isCoopGhost) + { + float nearest = RIVAL_SALVATION_FAR; + Entity_Player* saviour = nullptr; + for (int i = 0; i < (int)game.playerManager.playerList.size(); i++) + { + Entity_Player* other = game.GetPlayer(i); + if (other == &player || !other->HasCollectible(COLLECTIBLE_SALVATION)) continue; + float distance = vector_length_squared(vector_sub(other->pos, player.pos)); + if (distance >= nearest) continue; + double reach = other->get_salvation_scale() * SALVATION_HALO_RADIUS + player.size; + if ((double)distance >= reach * reach) continue; + nearest = distance; + saviour = other; + } + if (saviour && !player.tetheredEffect) + { + Entity* beam = game.Spawn({.position = player.pos, .spawner = saviour, .subType = SALVATION_BEAM_SUBTYPE, + .type = ENTITY_EFFECT, .variant = EFFECT_CRACK_THE_SKY, .seed = Random()}); + beam->target = &player; + beam->parent = saviour; + beam->SetCollisionDamage(SALVATION_BEAM_DAMAGE); + beam->Update(); + player.tetheredEffect = beam; + } + if (saviour && player.tetheredEffect) static_cast(player.tetheredEffect.get())->state = 1; + } + if (!player.HasCollectible(COLLECTIBLE_DIRTY_MIND) || !player.GetIntervalTicks(DIP_INTERVAL, 0)) return; + int roll = (int)player.GetCollectibleRNG(COLLECTIBLE_DIRTY_MIND).RandomInt(100); + int dip = DIP_LAST; + for (auto [below, subType] : DIP_ROLLS) + if (roll < below) + { + dip = subType; + break; + } + game.Spawn({.position = player.pos, .spawner = &player, .subType = dip, .type = ENTITY_FAMILIAR, + .variant = Entity_Familiar::DIP, .seed = Random()}); +} + +// The items' frame (00794e50, update_effects), after the effects count down: nothing runs during a stage transition +// or while the player falls through a trapdoor. Each item's piece in the original's order. void items_frame_update(Entity_Player& player) { TemporaryEffects& effects = player.temporaryEffects; + if (g_game->stageTransition.state != 0) return; + if (player.isPlayingExtraAnimation && player.sprite.IsPlaying("Trapdoor")) return; + player.UpdateBookOfVirtues(false); + beast_room_hourglass_update(player); + hairpin_frame_update(player); moms_foot_update(player); challenge_frame_update(player); + lazarus_anemic_update(player); anarchist_cookbook_update(player); crack_the_sky_update(player); + black_bean_update(player); + explosive_diarrhea_update(player); relax_poop_update(player); + invincible_effects_update(player); + blood_drip_update(player); breath_of_life_update(player); mirror_death_update(player); breath_of_life_fade_update(player); + passive_drops_update(player); faded_polaroid_update(player); + zodiac_frame_update(player); empty_vessel_update(player); - redemption_update(player); + forms_frame_update(player); + trinkets_frame_update(player); + bob_creep_update(player); + night_light_update(player); + circle_of_protection_update(player); + player.ClampGoldenHearts(false); + black_powder_update(player); + kidney_stone_update(player); + dark_princes_crown_update(player); + bozo_update(player); dads_ring_update(player); if (effects.HasCollectibleEffect(COLLECTIBLE_NOTCHED_AXE) && !player.HasCollectible(COLLECTIBLE_NOTCHED_AXE)) effects.RemoveCollectibleEffect(COLLECTIBLE_NOTCHED_AXE, -1); if (effects.GetNullEffect(NULLITEM_CAMO_BOOST)) effects.RemoveNullEffect(NULLITEM_CAMO_BOOST, 1); + tainted_frame_update(player); + red_stew_update(player); berserk_tick_update(player); if (effects.HasCollectibleEffect(COLLECTIBLE_URN_OF_SOULS) && !player.HasCollectible(COLLECTIBLE_URN_OF_SOULS)) effects.RemoveCollectibleEffect(COLLECTIBLE_URN_OF_SOULS, -1); @@ -1592,6 +2053,7 @@ void items_frame_update(Entity_Player& player) spooky_venus_update(player); volt_120_update(player); monstrance_update(player); + redemption_update(player); saturnus_update(player); dashes_frame_update(player); mars_recharge_update(player); @@ -1605,19 +2067,26 @@ void items_frame_update(Entity_Player& player) if (effects.HasNullEffect(NULLITEM_REVERSE_STARS) && player.IsExtraAnimationFinished()) effects.RemoveNullEffect(NULLITEM_REVERSE_STARS, 1); volt_45_charge_update(player); + berserk_charge_update(player); + blue_baby_poop_update(player); ibs_charge_update(player); - birthright_dead_bird_update(player); azazels_rage_update(player); + birthright_dead_bird_update(player); sumptorium_recall_update(player); purgatory_update(player); isaacs_heart_update(player); extension_cord_update(player); mega_blast_update(player); azazels_rage_steer(player); + azazels_rage_end_update(player); montezuma_aim_update(player); plan_c_update(player); + stompy_dust_update(player); linger_bean_update(player); + versus_items_update(player); im_excited_update(player); + if (player.rUaWizardTimer > 0 && --player.rUaWizardTimer == 0) + player.RemoveCostume(g_manager->itemConfig.GetNullItem(NULLITEM_WIZARD)); telekinesis_update(player); if (player.hallowedGroundCountdown > 0 && --player.hallowedGroundCountdown < 1) { diff --git a/src/entity_player_evaluate.cpp b/src/entity_player_evaluate.cpp index 1f23b81..a316042 100644 --- a/src/entity_player_evaluate.cpp +++ b/src/entity_player_evaluate.cpp @@ -40,20 +40,10 @@ constexpr float FALL_SPEED_MIN_SLOPE = 0.01f; constexpr float G_FUEL_SPEED = 0.2f; constexpr float DEBUG_DAMAGE_BONUS = 40; constexpr float DEBUG_LUCK_BONUS = 50; -constexpr int PILL_RANGE_DOWN = 11; -constexpr int PILL_RANGE_UP = 12; -constexpr int PILL_SPEED_DOWN = 13; -constexpr int PILL_SPEED_UP = 14; -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 TRINKET_CRACKED_CROWN = 92; constexpr int FAMILIAR_ITEM_WISP = 206; // The constants of the other sections: the collectibles, trinkets, null items and characters they ask about. -constexpr int PILL_LARGER = 32; -constexpr int PILL_SMALLER = 33; constexpr int SPRITE_SCALE_UNLOCK = 3; constexpr int ACHIEVEMENT_HUGE = 361; constexpr float SIZE_STEP = 0.322f; @@ -290,8 +280,10 @@ static void fire_delay_evaluate(Entity_Player& p, const StatBonuses& bonus) flat = e(COLLECTIBLE_WAVY_CAP) * 0.75f + flat; rate = (float)effects.GetNullEffectNum(NULLITEM_WAVY_CAP_1) * 0.3f + flat + rate; if (has(120) || effects.HasCollectibleEffect(120)) rate = (n(120) + e(120)) * 0.7f + 1 + rate; - // The original also counts Equality when a trinket slot only the constructor writes holds it, always empty. - if (effects.HasTrinketEffect(TRINKET_EQUALITY)) rate = trinket_num(p, TRINKET_EQUALITY) * 2 + rate; + bool isEqualityPreviewed = p.previewTrinket == TRINKET_EQUALITY && p.isPreviewAdded && p.numKeys == p.numBombs && + p.numBombs == p.numCoins; + if (effects.HasTrinketEffect(TRINKET_EQUALITY) || isEqualityPreviewed) + rate = trinket_num(p, TRINKET_EQUALITY) * 2 + rate; rate = n(554) * 0.5f + rate; if (!p.HasWeaponType(WEAPON_BRIMSTONE)) rate = n(222) + rate; rate = (float)p.g_fuel_count() * 0.5f + rate; @@ -523,7 +515,7 @@ static void damage_evaluate(Entity_Player& p, const StatBonuses& bonus) uint32_t empty = (uint32_t)((p.boneHearts * 2 - p.redHearts + p.maxHearts) / 2); if (g_game->deathmatchManager.is_active()) empty >>= 3; float hearts = (float)(int)empty; - damage = std::pow(hearts + hearts, ADRENALINE_POWER) * 0.1f + damage; + damage = pow_float(hearts + hearts, ADRENALINE_POWER) * 0.1f + damage; } if (has(157) && !effects.isDisabled) { @@ -584,7 +576,7 @@ static void damage_evaluate(Entity_Player& p, const StatBonuses& bonus) } if (p.damageMultiplierStacks > 0) { - float scale = std::pow(1.5f, (float)p.damageMultiplierStacks); + float scale = pow_float(1.5f, (float)p.damageMultiplierStacks); damage = scale * damage; melee = scale * melee; } @@ -624,7 +616,7 @@ static void shot_speed_evaluate(Entity_Player& p, const StatBonuses& bonus) TemporaryEffects& effects = p.temporaryEffects; float crownScale = bonus.crownScale; - float pills = bonus.isMistOrGhost ? 0 : (float)(int)(pill_uses(p, PILL_SHOT_SPEED_UP) - pill_uses(p, PILL_SHOT_SPEED_DOWN)); + float pills = bonus.isMistOrGhost ? 0 : (float)(int)(pill_uses(p, PILLEFFECT_SHOT_SPEED_UP) - pill_uses(p, PILLEFFECT_SHOT_SPEED_DOWN)); int occult = std::min(n(572), 1); int mascara = std::min(n(310), 1); float ups = (float)(n(176) + n(669) + (((n(183) - occult) - n(342)) - e(342)) + n(397) + n(341) + n(339) + n(194)) * @@ -674,7 +666,7 @@ static void range_evaluate(Entity_Player& p, const StatBonuses& bonus) p.tearFallingSpeed = 0; p.tearFallingAcceleration = 0; - float pills = pills_weigh(p, bonus, PILL_RANGE_UP, 0.5f, PILL_RANGE_DOWN, 0.4f); + float pills = pills_weigh(p, bonus, PILLEFFECT_RANGE_UP, 0.5f, PILLEFFECT_RANGE_DOWN, 0.4f); int modifier = modifier_get(bonus, p.tearRangeModifier); float ups = (float)(effects.GetCollectibleEffectNum(12) + modifier + p.GetCollectibleNum(71) + p.GetCollectibleNum(12) + effects.GetCollectibleEffectNum(71)) + bonus.range; @@ -779,7 +771,7 @@ static void speed_evaluate(Entity_Player& p, const StatBonuses& bonus) TemporaryEffects& effects = p.temporaryEffects; float crownScale = bonus.crownScale; - float pills = pills_weigh(p, bonus, PILL_SPEED_UP, 0.5f, PILL_SPEED_DOWN, 0.4f); + float pills = pills_weigh(p, bonus, PILLEFFECT_SPEED_UP, 0.5f, PILLEFFECT_SPEED_DOWN, 0.4f); int rollers = p.g_fuel_count() < 1 ? n(143) + e(143) : 0; int sharp = std::min(n(14) + e(14), 1); int slow = std::min(n(13) + e(13), 1); @@ -850,7 +842,7 @@ static void luck_evaluate(Entity_Player& p, const StatBonuses& bonus) { auto n = [&](int id) { return (float)p.GetCollectibleNum(id); }; - float pills = bonus.isMistOrGhost ? 0 : pill_uses(p, PILL_LUCK_UP) - pill_uses(p, PILL_LUCK_DOWN); + float pills = bonus.isMistOrGhost ? 0 : pill_uses(p, PILLEFFECT_LUCK_UP) - pill_uses(p, PILLEFFECT_LUCK_DOWN); float luck = (float)modifier_get(bonus, p.luckModifier) + bonus.luck + pills + (float)p.donateLuck + p.edenLuck + n(253); for (int id : {46, 343, 355, 439}) luck = n(id) + luck; luck = luck - n(5); @@ -883,7 +875,7 @@ static void luck_evaluate(Entity_Player& p, const StatBonuses& bonus) static float tear_fall_speed(float height, float range, float shotSpeed, float acceleration) { float flight = range / shotSpeed; - float slope = std::max((std::pow(FALL_SPEED_DECAY, flight) - 1) * FALL_SPEED_SLOPE, FALL_SPEED_MIN_SLOPE); + float slope = std::max((pow_float(FALL_SPEED_DECAY, flight) - 1) * FALL_SPEED_SLOPE, FALL_SPEED_MIN_SLOPE); return ((TEAR_HEIGHT_MAX - height) - (acceleration * FALL_SPEED_RANGE_SCALE + 1) * (flight - slope)) / slope; } @@ -1162,7 +1154,7 @@ static void flying_evaluate(Entity_Player& p) // The scale a size step gives: doubling each step up to two, then growing in a line. static float size_scale(float steps) { - return steps < SIZE_SCALE_KNEE ? std::pow(SIZE_SCALE_KNEE, steps) + return steps < SIZE_SCALE_KNEE ? pow_float(SIZE_SCALE_KNEE, steps) : (steps - SIZE_SCALE_KNEE) * SIZE_SCALE_SLOPE + SIZE_SCALE_AT_KNEE; } @@ -1174,7 +1166,7 @@ static void size_evaluate(Entity_Player& p) Game& game = *g_game; bool isMistOrGhost = p.hasCurseMistEffect || p.isCoopGhost; - int pills = isMistOrGhost ? 0 : (int)pill_uses(p, PILL_LARGER) - (int)pill_uses(p, PILL_SMALLER); + int pills = isMistOrGhost ? 0 : (int)pill_uses(p, PILLEFFECT_LARGER) - (int)pill_uses(p, PILLEFFECT_SMALLER); int steps = (int)(p.coopBabyBuffTimers[COOP_BUFF_LARGER] > 0) - (int)(p.coopBabyBuffTimers[COOP_BUFF_SMALLER] > 0) + pills - n(71) - effect(71); float body = (float)(n(12) + (steps - n(438)) + effect(12)) * SIZE_STEP + 0; @@ -1329,35 +1321,30 @@ static bool is_libra(Entity_Player& p) return p.HasCollectible(COLLECTIBLE_LIBRA) || p.GetZodiacEffect() == COLLECTIBLE_LIBRA; } -// A float power taken in double precision, as the original's wrapper does. -static float power_double(float base, float exponent) -{ - return (float)std::pow((double)base, (double)exponent); -} - // The Libra part of 00763570: the four stats meet at their average. static void libra_balance(Entity_Player& p) { float dps = p.damage * FIRE_RATE_FRAMES / (p.maxFireDelay + 1); - float dpsStat = power_double((float)std::sqrt((double)dps), LIBRA_DPS_POWER) * LIBRA_DPS_SCALE - LIBRA_OFFSET; + float dpsStat = pow_float((float)std::sqrt((double)dps), LIBRA_DPS_POWER) * LIBRA_DPS_SCALE - LIBRA_OFFSET; float speedStat = p.moveSpeed * LIBRA_SPEED_SCALE - LIBRA_OFFSET; float rangeStat = (p.tearRange - LIBRA_RANGE_BASE) / LIBRA_RANGE_SCALE + LIBRA_OFFSET; float average = (rangeStat + speedStat + (dpsStat + dpsStat)) * 0.25f; bool isPositive = average > -LIBRA_OFFSET; p.moveSpeed = (average + LIBRA_OFFSET) / LIBRA_SPEED_SCALE; - p.maxFireDelay = isPositive ? FIRE_RATE_FRAMES / power_double((average + LIBRA_OFFSET) * LIBRA_TEARS_SCALE, LIBRA_TEARS_POWER) - 1 + p.maxFireDelay = isPositive ? FIRE_RATE_FRAMES / pow_float((average + LIBRA_OFFSET) * LIBRA_TEARS_SCALE, LIBRA_TEARS_POWER) - 1 : LIBRA_SLOWEST_FIRE_DELAY; - p.damage = isPositive ? power_double((average + LIBRA_OFFSET) * LIBRA_DAMAGE_SCALE, LIBRA_DAMAGE_POWER) : 0; + p.damage = isPositive ? pow_float((average + LIBRA_OFFSET) * LIBRA_DAMAGE_SCALE, LIBRA_DAMAGE_POWER) : 0; p.tearRange = (average - LIBRA_OFFSET) * LIBRA_RANGE_SCALE + LIBRA_RANGE_BASE; p.cacheFlags |= LIBRA_CACHE; } -// Rock Bottom's part of 00763570: each stat the cache asks for never drops below its best, which it keeps. The -// original also skips it while a trinket slot only the constructor writes holds something, always empty. +// Rock Bottom's part of 00763570: each stat the cache asks for never drops below its best, which it keeps. An info +// panel's preview of an item or trinket skips it. static void rock_bottom_hold(Entity_Player& p) { if (!p.HasCollectible(COLLECTIBLE_ROCK_BOTTOM) || p.temporaryEffects.isDisabled) return; + if (p.previewCollectible != 0 || p.previewTrinket != 0) return; auto hold = [&](uint32_t flag, float& stat, float& best) { diff --git a/src/entity_player_items.cpp b/src/entity_player_items.cpp index 30fe723..ba9a9a9 100644 --- a/src/entity_player_items.cpp +++ b/src/entity_player_items.cpp @@ -700,11 +700,11 @@ void Entity_Player::PlayDelayedSFX(int sound, int soundDelay, int frameDelay, fl delayedSfxFrameDelay = frameDelay; } -// 0075e190 Forgets the queued item, and the held sprite while one is held up. +// 0075e190 Forgets the queued item, and the held sprite while one is held up. Its item pool type stays. void Entity_Player::ClearQueueItem() { if (IsHoldingItem()) heldSprite.Reset(); - queuedItem = {}; + queuedItem = {.itemPoolType = queuedItem.itemPoolType}; } // 0056ff90 Whether no item waits to be added. @@ -1203,12 +1203,6 @@ constexpr std::array CONSOLATION_DROPS = {{{PICKUP_COIN, 0, {PICKUP_HEART, HEART_SOUL, 1}, {PICKUP_HEART, HEART_FULL, 2}}}; -// Pow as the original's wrapper takes it, through doubles. -static float pow_float(float base, float exponent) -{ - return (float)std::pow((double)base, (double)exponent); -} - static void consolation_prize_gain(Entity_Player& p, RNG& rng) { std::array stats = {p.moveSpeed * 4.5f - 2, pow_float(30 / (p.maxFireDelay + 1), 0.75f), @@ -1681,15 +1675,12 @@ void Entity_Player::AddCollectible(int type, int charge, bool isFirstTime, int a // The costumes AddCostume swaps for a second copy of their item (Brimstone and two others): the null items worn // instead. Then the Intruder's pairing with Transcendence, Eden's hairs, Sack Head's daily and Holy Grail's challenge. -constexpr int COLLECTIBLE_DOUBLED_COSTUME_A = 665; -constexpr int COLLECTIBLE_DOUBLED_COSTUME_B = 730; constexpr int NULLITEM_BRIMSTONE_DOUBLE = 45; constexpr int NULLITEM_DOUBLED_COSTUME_A = 125; constexpr int NULLITEM_DOUBLED_COSTUME_B = 126; constexpr int NULLITEM_EDEN_HAIR = 12; constexpr int NULLITEM_EDEN_HAIR_B = 88; constexpr int NULLITEM_INTRUDER_TRANSCENDENCE = 132; -constexpr int COLLECTIBLE_SACK_HEAD_COSTUME = 424; constexpr int COLLECTIBLE_HOLY_GRAIL = 184; constexpr int DAILY_COSTUME_PRIORITY_BONUS = 3; @@ -1721,11 +1712,11 @@ static ItemConfig_Item* costume_item_get(Entity_Player& player, ItemConfig_Item* if (item->id == COLLECTIBLE_BRIMSTONE && player.GetCollectibleNum(COLLECTIBLE_BRIMSTONE) > 1) item = items.GetNullItem(NULLITEM_BRIMSTONE_DOUBLE); - if (item && item->type == ITEM_PASSIVE && item->id == COLLECTIBLE_DOUBLED_COSTUME_A && - player.GetCollectibleNum(COLLECTIBLE_DOUBLED_COSTUME_A) > 1) + if (item && item->type == ITEM_PASSIVE && item->id == COLLECTIBLE_GUPPYS_EYE && + player.GetCollectibleNum(COLLECTIBLE_GUPPYS_EYE) > 1) item = items.GetNullItem(NULLITEM_DOUBLED_COSTUME_A); - if (item && item->type == ITEM_PASSIVE && item->id == COLLECTIBLE_DOUBLED_COSTUME_B && - player.GetCollectibleNum(COLLECTIBLE_DOUBLED_COSTUME_B) > 1) + if (item && item->type == ITEM_PASSIVE && item->id == COLLECTIBLE_GLASS_EYE && + player.GetCollectibleNum(COLLECTIBLE_GLASS_EYE) > 1) item = items.GetNullItem(NULLITEM_DOUBLED_COSTUME_B); return item; } @@ -1763,7 +1754,7 @@ void Entity_Player::AddCostume(ItemConfig_Item* item, bool isItemStateOnly) costume.isItemStateOnly = isItemStateOnly; costume.playerType = -1; if (g_game->dailyChallenge.specialDailyId == SPECIAL_DAILY_HALLOWEEN && item->IsCollectible() && - item->id == COLLECTIBLE_SACK_HEAD_COSTUME) + item->id == COLLECTIBLE_SACK_HEAD) costume.priority += DAILY_COSTUME_PRIORITY_BONUS; costume.sprite.Load(item->costume.anm2Path, GRAPHICS_DEFER); if (is_eden_hair(item)) eden_hair_apply(costume.sprite); @@ -2015,8 +2006,6 @@ void Entity_Player::UpdateCostumes() // overlay animation. Costumes playing an item's own animation keep it. void Entity_Player::costume_heads_update(int blinkFrame) { - constexpr int HEAD_IDLE_BLINK_LIMIT = 9; - for (PlayerCostumeMap& map : playerCostumeMap) { if (map.index < 0 || map.isBodyLayer) continue; @@ -2027,7 +2016,7 @@ void Entity_Player::costume_heads_update(int blinkFrame) if (!head->isLooping) { std::string idle = headAnim + "_Idle"; - if (blinkTime < HEAD_IDLE_BLINK_LIMIT && costume.sprite.GetAnimationData(idle)) costume.sprite.Play(idle); + if (blinkFrame == 0 && costume.sprite.GetAnimationData(idle)) costume.sprite.Play(idle); else costume.sprite.SetFrame(headAnim, blinkFrame); } else diff --git a/src/entity_player_passives.cpp b/src/entity_player_passives.cpp index 59a704c..19d1b00 100644 --- a/src/entity_player_passives.cpp +++ b/src/entity_player_passives.cpp @@ -106,7 +106,7 @@ void Entity_Player::AddDollarBillEffect() } // The Black Bean's effect farts every fifth frame it has left, pushing enemies away under a smoke cloud. -static void black_bean_update(Entity_Player& player) +void black_bean_update(Entity_Player& player) { TemporaryEffect* bean = player.temporaryEffects.GetCollectibleEffect(COLLECTIBLE_BLACK_BEAN); if (!bean || bean->cooldown % BLACK_BEAN_FART_PERIOD != 0) return; @@ -150,7 +150,7 @@ static ColorMod invincible_flash_color() // The invincible effects (My Little Unicorn, a charging Taurus, the Gamekid, Unicorn Stump): the first one on races // the music (Unicorn Stump warbles it now and then), and the player flashes colours every fourth frame, then // flickers out over its last 30. -static void invincible_effects_update(Entity_Player& player) +void invincible_effects_update(Entity_Player& player) { TemporaryEffects& effects = player.temporaryEffects; MusicManager& music = g_manager->musicManager; @@ -205,7 +205,7 @@ static void placenta_update(Entity_Player& player) } // A spot of creep under the player, randomly sized, before its first update. -static Entity* creep_drop(Entity_Player& player, int variant) +Entity* creep_drop(Entity_Player& player, int variant) { uint32_t seed = Random(); Entity* creep = g_game->Spawn({.position = player.pos, .spawner = &player, .type = ENTITY_EFFECT, @@ -268,17 +268,20 @@ static void aquarius_update(Entity_Player& player) creep->Update(); } -// The pieces of the items' frame (update_effects 00794e50) for collectibles 1 to 366, in their order there: the Black -// Bean, the invincible effects, 3 Dollar Bill, Placenta, Ball of Tar, Taurus and Aquarius. -void passives_frame_update(Entity_Player& player) +// The pieces of the items' frame (update_effects 00794e50) for 3 Dollar Bill, Placenta and Ball of Tar, in their +// order there. +void passive_drops_update(Entity_Player& player) { - black_bean_update(player); - invincible_effects_update(player); if (player.HasCollectible(COLLECTIBLE_3_DOLLAR_BILL) && g_game->room->GetFrameCount() % DOLLAR_BILL_PERIOD == 0) player.AddDollarBillEffect(); placenta_update(player); if (player.HasCollectible(COLLECTIBLE_BALL_OF_TAR) && player.IsFrame(CREEP_PERIOD, 0) && random_below(TAR_ODDS) > 1) creep_drop(player, EFFECT_PLAYER_CREEP_BLACK)->Update(); +} + +// Taurus' and Aquarius' pieces of the items' frame, in their order there. +void zodiac_frame_update(Entity_Player& player) +{ taurus_update(player); aquarius_update(player); } diff --git a/src/entity_player_passives.h b/src/entity_player_passives.h index 996f7fb..f8acf7f 100644 --- a/src/entity_player_passives.h +++ b/src/entity_player_passives.h @@ -16,7 +16,11 @@ constexpr int ANEMIC_VERSUS_FRAMES = 300; // The passive collectibles' (1 to 366) pieces other files call: the effects the frame and stats are written for, the // items' frame, the walking items' costumes and the hit, Cursed Eye's teleport and the last heart's saves. -void passives_frame_update(Entity_Player& player); +void black_bean_update(Entity_Player& player); +void invincible_effects_update(Entity_Player& player); +void passive_drops_update(Entity_Player& player); +void zodiac_frame_update(Entity_Player& player); +Entity* creep_drop(Entity_Player& player, int variant); void walking_items_animate(Entity_Player& player); void book_of_belial_passive_update(Entity_Player& player); void gnawed_leaf_update(Entity_Player& player); diff --git a/src/entity_player_pockets.cpp b/src/entity_player_pockets.cpp index 7335a84..9b20e47 100644 --- a/src/entity_player_pockets.cpp +++ b/src/entity_player_pockets.cpp @@ -26,10 +26,6 @@ constexpr int CARD_ID_VANILLA_LAST = 97; constexpr float ENDLESS_NAMELESS_CHANCE = 0.25f; constexpr float ENDLESS_NAMELESS_CHANCE_DOUBLE = 0.33f; constexpr float ENDLESS_NAMELESS_CHANCE_TRIPLE = 0.5f; - -constexpr int PILL_ID_TEARS_UP = 16; -constexpr int PILL_ID_GULP = 43; -constexpr int PILL_ID_EXPERIMENTAL = 49; constexpr int PILL_ID_COUNT = 50; constexpr int ACHIEVEMENT_GULP = 386; constexpr int ANNOUNCER_FRAMES_RANDOM = 900; @@ -367,7 +363,7 @@ void Entity_Player::UseCard(int cardType, uint32_t useFlag) // 00763290 Unlocks the tears ups achievement once ten Tears Up pills and tears up items are taken. void tears_up_unlock_check(Entity_Player& player) { - int tearsUps = PILL_ID_TEARS_UP < (int)player.pillEffectUses.size() ? player.pillEffectUses[PILL_ID_TEARS_UP] : 0; + int tearsUps = PILLEFFECT_TEARS_UP < (int)player.pillEffectUses.size() ? player.pillEffectUses[PILLEFFECT_TEARS_UP] : 0; for (ItemConfig_Item* item : g_manager->itemConfig.GetTaggedItems(TAG_TEARS_UP)) if (item->IsCollectible()) tearsUps += player.collectibleCounts[item->id]; if (tearsUps >= TEARS_UP_UNLOCK_COUNT) g_manager->persistentGameData.TryUnlock(ACHIEVEMENT_TEARS_UP_ITEMS); @@ -417,11 +413,11 @@ void Entity_Player::UsePill(int pillEffect, int pillColor, uint32_t useFlags) name = string_scramble_seeded(name); description = string_scramble_seeded(description); } - if (!(useFlags & USE_NOHUD) && pillEffect != PILL_ID_EXPERIMENTAL) + if (!(useFlags & USE_NOHUD) && pillEffect != PILLEFFECT_EXPERIMENTAL) game.hud.show_pill_name(this, name.c_str(), description.c_str()); if (pillEffect >= 0 && pillEffect < (int)pillEffectUses.size()) pillEffectUses[pillEffect] += isHorse ? 2 : 1; tears_up_unlock_check(*this); - if (pillEffectUses.size() > PILL_ID_GULP && pillEffectUses[PILL_ID_GULP] > GULP_UNLOCK_USES) + if (pillEffectUses.size() > PILLEFFECT_GULP && pillEffectUses[PILLEFFECT_GULP] > GULP_UNLOCK_USES) g_manager->persistentGameData.TryUnlock(ACHIEVEMENT_GULP); int frames = announcer_frames(); diff --git a/src/entity_player_room.cpp b/src/entity_player_room.cpp index b511c3b..f144186 100644 --- a/src/entity_player_room.cpp +++ b/src/entity_player_room.cpp @@ -19,8 +19,6 @@ constexpr int COLLECTIBLE_BELIAL_PARTNER = 474; constexpr int COLLECTIBLE_BELIAL_EFFECT = 214; constexpr int COLLECTIBLE_POKE_GO = 505; constexpr int COLLECTIBLE_MERCURIUS = 590; -constexpr int NULL_ITEM_BELIAL = 123; -constexpr int NULL_ITEM_FORGOTTEN_CHALLENGE = 106; constexpr int BELIAL_NULL_COUNT = 4; constexpr int VERSUS_EFFECT_COOLDOWN = 300; constexpr int CHALLENGE_FORGOTTEN_COSTUME = 42; @@ -327,7 +325,7 @@ void Entity_Player::room_enter() AddCollectible(COLLECTIBLE_DOGMA, 0, true, 0, 0); if (playerType == PLAYER_THEFORGOTTEN_B && game.challenge == CHALLENGE_FORGOTTEN_COSTUME) { - ItemConfig_Item* costume = g_manager->itemConfig.GetNullItem(NULL_ITEM_FORGOTTEN_CHALLENGE); + ItemConfig_Item* costume = g_manager->itemConfig.GetNullItem(NULLITEM_FORGOTTEN_BOMB); for (PlayerCostumeMap& layer : playerCostumeMap) { if (layer.index < 0 || layer.isBodyLayer || costumeSpriteDescs[layer.index].item != costume) continue; @@ -348,7 +346,7 @@ void Entity_Player::room_enter() if (game.deathmatchManager.state >= DEATHMATCH_INTRO) effect.cooldown = VERSUS_EFFECT_COOLDOWN; temporaryEffects.AddEffect(effect, true, 1); } - temporaryEffects.AddNullEffect(NULL_ITEM_BELIAL, true, BELIAL_NULL_COUNT); + temporaryEffects.AddNullEffect(NULLITEM_JUDAS_BIRTHRIGHT, true, BELIAL_NULL_COUNT); } moveToTarget = vector_make(0, 0); diff --git a/src/entity_player_tears.cpp b/src/entity_player_tears.cpp index a7cfb6a..218adc9 100644 --- a/src/entity_player_tears.cpp +++ b/src/entity_player_tears.cpp @@ -145,8 +145,6 @@ constexpr int COLLECTIBLE_TERRA = 592; constexpr int COLLECTIBLE_OCULAR_RIFT = 606; constexpr int COLLECTIBLE_LODESTONE = 617; constexpr int COLLECTIBLE_TROPICAMIDE = 659; -constexpr int TRINKET_PINKY_EYE = 30; -constexpr int TRINKET_PUSH_PIN = 31; constexpr int TRINKET_BLISTER = 77; constexpr int TRINKET_BLACK_TOOTH = 95; constexpr int TRINKET_NOSE_GOBLIN = 98; @@ -527,8 +525,8 @@ static void look_items_apply(Entity_Player& player, TearParams& params, const Te { float roll = random_unit() * 2 - 1; params.tearVariant = TEAR_ROCK; - params.tearScale *= std::pow(2.0f, roll * TERRA_SCALE_EXPONENT); - params.tearDamage *= std::pow(2.0f, roll); + params.tearScale *= pow_float(2, roll * TERRA_SCALE_EXPONENT); + params.tearDamage *= pow_float(2, roll); } if (player.temporaryEffects.HasNullEffect(NULLITEM_REVERSE_HANGED_MAN)) flags.set(TEAR_COIN_DROP_DEATH); if (player.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_CROWN_OF_LIGHT)) params.tearVariant = TEAR_DIAMOND; @@ -900,7 +898,7 @@ TearParams Entity_Player::GetTearHitParams(WeaponType weaponType, float damageSc blood_baby_apply(*this, params, *state.familiar); mass_knockback_apply(*this, params); - float size = params.tearScale > 1 ? std::log(params.tearScale) + 1 : params.tearScale; + float size = params.tearScale > 1 ? log_float(params.tearScale) + 1 : params.tearScale; float baseDamage = state.baseDamage; params.tearScale = (std::sqrt(baseDamage) * TEAR_SCALE_ROOT + size * TEAR_SCALE_SIZE + baseDamage * TEAR_SCALE_DAMAGE) * diff --git a/src/entity_player_trinkets.cpp b/src/entity_player_trinkets.cpp index 7891a26..a277aa5 100644 --- a/src/entity_player_trinkets.cpp +++ b/src/entity_player_trinkets.cpp @@ -956,7 +956,7 @@ void purity_gain(Entity_Player& player) } // A crown's glow following its condition: the effect and the glowing float come on together, or go together. -static void crown_glow_set(Entity_Player& player, int crown, ANM2& sprite, bool isLit) +void crown_glow_set(Entity_Player& player, int crown, ANM2& sprite, bool isLit) { TemporaryEffects& effects = player.temporaryEffects; if (isLit == effects.HasCollectibleEffect(crown)) return; @@ -1108,11 +1108,16 @@ static void louse_update(Entity_Player& player) for (int i = player.GetTrinketMultiplier(TRINKET_LOUSE); i > 0; i--) player.ThrowBlueSpider(player.pos, {}); } -// The trinkets' part of the items' frame (00794e50), in their order there: Hairpin, Mysterious Candy, Louse and -// Rainbow Worm, whose tear effect changes every 90 frames. -void trinkets_frame_update(Entity_Player& player) +// Hairpin's piece of the items' frame (00794e50), at its start. +void hairpin_frame_update(Entity_Player& player) { if (player.HasTrinket(TRINKET_HAIRPIN)) hairpin_update(player); +} + +// The trinkets' block of the items' frame (00794e50), in its order there: Mysterious Candy, Louse and Rainbow Worm, +// whose tear effect changes every 90 frames. +void trinkets_frame_update(Entity_Player& player) +{ if (player.HasTrinket(TRINKET_MYSTERIOUS_CANDY) && player.variant == PLAYER_VARIANT_PLAYER) mysterious_candy_update(player); if (player.HasTrinket(TRINKET_LOUSE)) louse_update(player); if (player.HasTrinket(TRINKET_RAINBOW_WORM) && g_game->frameCount % RAINBOW_WORM_FRAMES == 0) @@ -1154,8 +1159,8 @@ void coin_trinkets_collect(Entity_Pickup& pickup, Entity_Player& player, int val constexpr float BUTT_FART_RADIUS = 85; constexpr float BUTT_BEAN_RADIUS = 120; constexpr int BURNT_PENNY_BOMB = 1; - float threshold = std::pow(0.75f, (float)value); - float doubling = std::pow(0.5f, (float)value); + float threshold = pow_float(0.75f, (float)value); + float doubling = pow_float(0.5f, (float)value); if (player.HasTrinket(TRINKET_BURNT_PENNY) && is_penny_rolled(player, TRINKET_BURNT_PENNY, threshold)) penny_drop(player, PICKUP_BOMB, BURNT_PENNY_BOMB); diff --git a/src/entity_player_trinkets.h b/src/entity_player_trinkets.h index e50b76a..6ff1200 100644 --- a/src/entity_player_trinkets.h +++ b/src/entity_player_trinkets.h @@ -52,6 +52,7 @@ void trinkets_smelt(Entity_Player& player); // The player's frame and the items' frame. void equality_update(Entity_Player& player); void trinket_teleports_update(Entity_Player& player); +void hairpin_frame_update(Entity_Player& player); void trinkets_frame_update(Entity_Player& player); // A new room, the hearts changing, a hit. @@ -61,6 +62,7 @@ void crowns_room_enter(Entity_Player& player); void dice_bag_room_enter(Entity_Player& player); void crowns_update(Entity_Player& player); bool is_dark_prince_lit(Entity_Player& player); +void crown_glow_set(Entity_Player& player, int crown, ANM2& sprite, bool isLit); bool late_items_hit_trigger(Entity_Player& player, const ItemsHit& hit, HitStep step); void cursed_skull_teleport(Entity_Player& player); diff --git a/src/entity_player_update.cpp b/src/entity_player_update.cpp index e13113d..cd81e6f 100644 --- a/src/entity_player_update.cpp +++ b/src/entity_player_update.cpp @@ -44,8 +44,6 @@ constexpr float LEADER_PUSH_MAX = 2; constexpr float SALVATION_HALO_SCALE = 1.2f; constexpr float SALVATION_HALO_RISE = -15; constexpr int SALVATION_TURN_FRAMES = 360; -constexpr float SALVATION_GROWTH = 0.1f; -constexpr float SALVATION_SCALE_MAX = 2; constexpr float LAZARUS_TWIN_SPREAD = 15; constexpr float BREATH_OF_LIFE_RISE = -15; constexpr float FX_POOF_DEPTH = -10; @@ -208,12 +206,10 @@ static void hud_update(Entity_Player& player) if (player.playerHUD) player.playerHUD->Update(); } -// 007d4340 Salvation's halo grows a tenth for each room its effect counts, up to twice, over its own 1.2. +// Salvation's halo is its size (get_salvation_scale) over its own 1.2. float salvation_halo_scale_get(Entity_Player& player) { - TemporaryEffect* effect = player.temporaryEffects.GetCollectibleEffect(COLLECTIBLE_SALVATION); - float count = effect ? (float)effect->count : 0; - return std::clamp(count * SALVATION_GROWTH + 1, 1.0f, SALVATION_SCALE_MAX) * SALVATION_HALO_SCALE; + return player.get_salvation_scale() * SALVATION_HALO_SCALE; } // Salvation's halo floats above the player at its size, turning a degree a frame. @@ -1064,8 +1060,8 @@ static void players_push_apart(Entity_Player& player) } // 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) runs only -// its written pieces, closed by the PostPEffectUpdate callback. +// evaluated when the effects changed, and the timed ones count down before the items' frame (update_effects), closed +// by the PostPEffectUpdate callback. static void temporary_effects_update(Entity_Player& player) { TemporaryEffects& effects = player.temporaryEffects; @@ -1081,11 +1077,8 @@ static void temporary_effects_update(Entity_Player& player) effects.isEvaluateCachePending = false; if (player.HasEntityFlags(FLAG_INTERPOLATION_UPDATE)) return; - tainted_frame_update(player); effects.Update(); character_frame_update(player); - passives_frame_update(player); - trinkets_frame_update(player); items_frame_update(player); lua_engine_get().PostPEffectUpdate(&player); } diff --git a/src/entity_projectile.cpp b/src/entity_projectile.cpp index e201105..264a602 100644 --- a/src/entity_projectile.cpp +++ b/src/entity_projectile.cpp @@ -364,8 +364,6 @@ constexpr int BONE_PARTICLE_SUBTYPE = 1; constexpr int SOUND_INFAMY_BLOCK = 863; constexpr int SOUND_PIN_GOO = 934; - -constexpr int COLLECTIBLE_BETRAYAL = 391; constexpr uint32_t CHALLENGE_BROKEN_WATCH = 22; // The familiars shots hurt (the two Infamy guards as the player does), and the subtype of the one that is spared. diff --git a/src/entity_tear_flags.cpp b/src/entity_tear_flags.cpp index b976520..b2430c3 100644 --- a/src/entity_tear_flags.cpp +++ b/src/entity_tear_flags.cpp @@ -867,7 +867,8 @@ void Entity_Tear::trail_spawn() if ((!isBomb && variant != TEAR_BALLOON && variant != TEAR_BALLOON_BRIMSTONE) || !IsFrame(2, 0)) return; uint32_t seed = Random(); - Vector spread = vector_scale(random_direction(), random_unit() * TRAIL_SPREAD * fScale); + Vector direction = random_direction(); + Vector spread = vector_scale(vector_scale(vector_scale(direction, random_unit()), TRAIL_SPREAD), fScale); Vector trailVelocity = vector_add(vector_scale(velocity, TRAIL_SPEED_SHARE), spread); Entity* trail = g_game->Spawn({.position = pos, .velocity = trailVelocity, .type = ENTITY_EFFECT, .variant = isBomb ? EFFECT_DARK_BALL_SMOKE_PARTICLE : EFFECT_HAEMO_TRAIL, .seed = seed}); diff --git a/src/familiar_dip.cpp b/src/familiar_dip.cpp index cd98925..d60bc84 100644 --- a/src/familiar_dip.cpp +++ b/src/familiar_dip.cpp @@ -223,7 +223,10 @@ static void dip_scoot(Entity_Familiar& dip, float speedScale) dip.friction = savedFriction; } else if (goal == dip.player) - destination = vector_add(destination, vector_scale(random_direction(), random_unit() * DIP_WANDER)); + { + Vector direction = random_direction(); + destination = vector_add(destination, vector_scale(direction, random_unit() * DIP_WANDER)); + } else if (dip.subtype == DIP_SUBTYPE_RED) speedScale = DIP_RED_CHARGE; Vector heading = vector_is_zero(vector_sub(destination, dip.pos)) diff --git a/src/familiar_evaluate.cpp b/src/familiar_evaluate.cpp index 604a174..75ca401 100644 --- a/src/familiar_evaluate.cpp +++ b/src/familiar_evaluate.cpp @@ -64,9 +64,7 @@ constexpr FamiliarSource FAMILIAR_SOURCES[] = { constexpr FamiliarSource LATE_FAMILIAR_SOURCES[] = {{565, 241}, {697, 242}}; // The familiars granted another way: items whose effect alone counts, the trinkets, and the counters. -constexpr int NULLITEM_SPIN_TO_WIN_FAMILIAR = 131; constexpr int FAMILIAR_SPIN_TO_WIN = 244; -constexpr int NULLITEM_HALO_FLY_LOSS = 107; constexpr int HALO_FLY_CAP = 10; constexpr int ACHIEVEMENT_CUBE_OF_MEAT_FULL = 144; constexpr int ACHIEVEMENT_BALL_OF_BANDAGES_FULL = 19; @@ -91,7 +89,6 @@ constexpr int GIANTBOOK_SUPER_BUM = 38; constexpr std::pair SUPER_BUM_PARTS[] = {{COLLECTIBLE_KEY_BUM, Entity_Familiar::KEY_BUM}, {COLLECTIBLE_DARK_BUM, Entity_Familiar::DARK_BUM}, {COLLECTIBLE_BUM_FRIEND, Entity_Familiar::BUM_FRIEND}}; -constexpr int TRINKET_ISAACS_HEAD = 54; constexpr int TRINKET_SOUL = 57; constexpr int SOUL_TRINKET_CAP = 3; constexpr int FORM_RNG_SHIFT = 35; @@ -478,7 +475,7 @@ void familiars_evaluate(Entity_Player& p) for (const FamiliarSource& source : LATE_FAMILIAR_SOURCES) source_check(p, source); familiar_check(p, {.item = g_manager->itemConfig.GetCollectible(COLLECTIBLE_ESAU_JR), .rng = &p.GetCollectibleRNG(COLLECTIBLE_ESAU_JR), - .count = p.temporaryEffects.GetNullEffectNum(NULLITEM_SPIN_TO_WIN_FAMILIAR), + .count = p.temporaryEffects.GetNullEffectNum(NULLITEM_ESAU_JR_FAMILIAR), .variant = FAMILIAR_SPIN_TO_WIN}); familiar_check(p, {.item = g_manager->itemConfig.GetCollectible(COLLECTIBLE_LEPROSY), .rng = &p.GetCollectibleRNG(COLLECTIBLE_LEPROSY), @@ -492,7 +489,7 @@ void familiars_evaluate(Entity_Player& p) int haloFlies = std::min(prettyFlies + p.GetCollectibleNum(COLLECTIBLE_HALO_OF_FLIES) * 2, HALO_FLY_CAP); familiar_check(p, {.item = g_manager->itemConfig.GetCollectible(COLLECTIBLE_HALO_OF_FLIES), .rng = &p.GetCollectibleRNG(COLLECTIBLE_HALO_OF_FLIES), - .count = haloFlies - p.temporaryEffects.GetNullEffectNum(NULLITEM_HALO_FLY_LOSS) * 2, + .count = haloFlies - p.temporaryEffects.GetNullEffectNum(NULLITEM_EXTRA_BIG_FAN) * 2, .variant = Entity_Familiar::FLY_ORBITAL}); source_check(p, {COLLECTIBLE_DEAD_CAT, Entity_Familiar::DEAD_CAT, COUNT_OWNED}); @@ -648,8 +645,8 @@ void Entity_Familiar::RemoveFromPlayer(uint8_t) isEvaluated = true; break; case BIG_FAN: - if (!owner.temporaryEffects.HasNullEffect(NULLITEM_HALO_FLY_LOSS)) break; - owner.temporaryEffects.RemoveNullEffect(NULLITEM_HALO_FLY_LOSS, 1); + if (!owner.temporaryEffects.HasNullEffect(NULLITEM_EXTRA_BIG_FAN)) break; + owner.temporaryEffects.RemoveNullEffect(NULLITEM_EXTRA_BIG_FAN, 1); return owner.AddCacheFlags(CACHE_FAMILIARS), owner.EvaluateItems(); case SUPER_BUM: { @@ -667,7 +664,7 @@ void Entity_Familiar::RemoveFromPlayer(uint8_t) owner.IncrementPlayerFormCounter(PLAYER_FORM_SPIDER_BABY, -owner.playerForms[PLAYER_FORM_SPIDER_BABY]); return; case ESAU_JR: - owner.temporaryEffects.RemoveNullEffect(NULLITEM_HALO_FLY_LOSS, 1); + owner.temporaryEffects.RemoveNullEffect(NULLITEM_EXTRA_BIG_FAN, 1); return owner.AddCacheFlags(CACHE_FAMILIARS), owner.EvaluateItems(); } diff --git a/src/familiar_repentance.cpp b/src/familiar_repentance.cpp index 87ad3eb..2bc908e 100644 --- a/src/familiar_repentance.cpp +++ b/src/familiar_repentance.cpp @@ -294,8 +294,8 @@ void intruder_player_hurt(Entity_Familiar& intruder, const DamageEvent& hit) // One of Boiled Baby's burst: a blood tear (an enemy shot for a charmed one) arcing up, small or big. static void boiled_shot_fire(Entity_Familiar& baby, float damage) { - Vector velocity = - vector_scale(random_direction(), BOILED_SPEED * (random_unit() * BOILED_SPEED_RANGE + BOILED_SPEED_MIN)); + Vector velocity = vector_scale(random_direction(), BOILED_SPEED); + velocity = vector_scale(velocity, random_unit() * BOILED_SPEED_RANGE + BOILED_SPEED_MIN); bool isCharmed = baby.HasEntityFlags(FLAG_CHARM); ColorMod color = COLOR_DEFAULT; if (!isCharmed && baby.isLilDelirium) std::ranges::copy(BOILED_DELIRIUM_COLORIZE, color._colorize); diff --git a/src/familiar_shoot.cpp b/src/familiar_shoot.cpp index 5b67dff..4a0baa9 100644 --- a/src/familiar_shoot.cpp +++ b/src/familiar_shoot.cpp @@ -13,7 +13,6 @@ #include // The items and trinkets the familiars' shots read. -constexpr int TRINKET_ISAACS_HEAD_ID = 54; // Fruity Plum's fruit tears: their damage, their two sizes (the tear scales of sizes 2 and 3), how much bigger, and // their slow fall. @@ -376,7 +375,7 @@ static void shot_variant_apply(Entity_Familiar& familiar, FamiliarShot& shot, in if (variant == Entity_Familiar::ISAACS_HEAD) { shot.flags.set(TEAR_PIERCING); - int heads = player.GetTrinketMultiplier(TRINKET_ISAACS_HEAD_ID); + int heads = player.GetTrinketMultiplier(TRINKET_ISAACS_HEAD); if (heads > 1) shot.damage = heads > 2 ? (float)((double)player.damage * 1.5) : player.damage; } else if (variant == Entity_Familiar::GHOST_BABY || rainbow == 1 || mimic == 6) diff --git a/src/familiar_variants.cpp b/src/familiar_variants.cpp index f8ffa01..108d230 100644 --- a/src/familiar_variants.cpp +++ b/src/familiar_variants.cpp @@ -1237,12 +1237,14 @@ void my_shadow_touch(Entity_Familiar& shadow, Entity& collider) if (!collider.IsVulnerableEnemy(shadow.player)) return; if (entity_query(ENTITY_CHARGER, 0).size() > MY_SHADOW_CHARGER_LIMIT) return; - Vector spot = vector_add(shadow.pos, vector_scale(random_direction(), MY_SHADOW_REACH * random_unit())); + Vector direction = random_direction(); + Vector spot = vector_add(shadow.pos, vector_scale(vector_scale(direction, MY_SHADOW_REACH), random_unit())); for (int i = 0; i < MY_SHADOW_TRIES && room_grid_collision_at(spot) != 0; i++) { float turn = random_unit() * PI_ROUGH * 2; - float reach = random_unit() * MY_SHADOW_REACH; - spot = vector_add(shadow.pos, vector_make(std::cos(turn) * reach, std::sin(turn) * reach)); + float share = random_unit(); + spot = vector_add(shadow.pos, vector_make(std::cos(turn) * MY_SHADOW_REACH * share, + std::sin(turn) * MY_SHADOW_REACH * share)); } if (room_grid_collision_at(spot) != 0) return; diff --git a/src/familiar_wisp_kinds.cpp b/src/familiar_wisp_kinds.cpp index 71e2b64..e694a2a 100644 --- a/src/familiar_wisp_kinds.cpp +++ b/src/familiar_wisp_kinds.cpp @@ -1179,7 +1179,7 @@ static void remote_wisp_lob(Entity_Familiar& wisp, WispTear& tear) tear.scale *= REMOTE_TEAR_SCALE; float frames = vector_length(vector_sub(wisp.pos, landing)) / vector_length(tear.velocity); - float fall = std::max((std::pow(REMOTE_FALL_DRAG, frames) - 1) * REMOTE_FALL_SPAN, REMOTE_FALL_MIN); + float fall = std::max((pow_float(REMOTE_FALL_DRAG, frames) - 1) * REMOTE_FALL_SPAN, REMOTE_FALL_MIN); tear.fallingSpeed = (REMOTE_LAUNCH_HEIGHT - (frames - fall) * REMOTE_LAUNCH_SLOPE) / fall; } diff --git a/src/game.h b/src/game.h index 070fc71..c4dd826 100644 --- a/src/game.h +++ b/src/game.h @@ -88,7 +88,7 @@ enum DebugFlag : uint32_t // The run's state flags (Lua's GameStateFlag) the curated code reads, by bit. enum GameStateFlag : int { - GAME_STATE_FAMINE_SPAWNED = 0, + GAME_STATE_FAMINE_SPAWNED = 0, // Lua's name, though the game sets it when an angel room's door first spawns GAME_STATE_DEVILROOM_SPAWNED = 5, GAME_STATE_DEVILROOM_VISITED = 6, GAME_STATE_BOOK_PICKED_UP = 8, diff --git a/src/greed.cpp b/src/greed.cpp index 429cd1d..6da9ce8 100644 --- a/src/greed.cpp +++ b/src/greed.cpp @@ -693,7 +693,7 @@ float Entity_Player::GetGreedDonationJamChance(PersistentGameData& data) if ((uint32_t)playerType >= (uint32_t)COMPLETION_PLAYER_TYPE_COUNT) return DONATION_JAM_UNKNOWN; uint32_t donated = data.eventCounters[COMPLETION_MARKS[playerType][COMPLETION_GREED_DONATION].counter]; - float chance = std::min(std::exp((float)donated * DONATION_JAM_GROWTH) - 1, DONATION_JAM_MAX); + float chance = std::min(exp_float((float)donated * DONATION_JAM_GROWTH) - 1, DONATION_JAM_MAX); chance = std::floor(chance * DONATION_JAM_SHARE + HALF); return g_game->difficulty == DIFFICULTY_GREEDIER ? std::min(DONATION_JAM_GREEDIER_MAX, chance) : chance; } diff --git a/src/grid_entity_door.cpp b/src/grid_entity_door.cpp index 2d63108..e6527d5 100644 --- a/src/grid_entity_door.cpp +++ b/src/grid_entity_door.cpp @@ -35,8 +35,8 @@ constexpr int GREED_EXIT_WAVE = 10; // The run state bits doors set and read: Mega Satan's door unlocked, and Mom's Heart's exit opened. constexpr uint64_t GAME_STATE_HEART_EXIT_OPENED = 1ull << 52; -// The items, trinkets and challenge doors answer to. -constexpr int FAMILIAR_KEY_FULL = 28; +// The state Mega Satan's opening door gives the familiars it signals. The original signals Star of Bethlehem +// (variant 236), not the full key (28). constexpr int FAMILIAR_STATE_KEY_DOOR = 1; // How far a door's sprite stands out from the wall. @@ -795,7 +795,7 @@ void GridEntity_Door::UpdateAnimation() sprite.Play(openAnimation); if (targetRoomIdx == ROOM_MEGA_SATAN_IDX) for (Entity* entity : g_game->room->entityList.updateEL) - if (entity->type == ENTITY_FAMILIAR && entity->variant == FAMILIAR_KEY_FULL) + if (entity->type == ENTITY_FAMILIAR && entity->variant == Entity_Familiar::STAR_OF_BETHLEHEM) static_cast(entity)->state = FAMILIAR_STATE_KEY_DOOR; } @@ -916,7 +916,7 @@ void GridEntity_Door::Update() continue; g_game->save_rewind_state(slot); - player->TakeDamage(1, DAMAGE_CURSED_DOOR | DAMAGE_NO_PENALTIES, EntityRef(), 0); + player->TakeDamage(1, DAMAGE_CURSED_DOOR | DAMAGE_NO_PENALTIES, EntityRef(), HIT_COUNTDOWN); } } diff --git a/src/grid_entity_poop.cpp b/src/grid_entity_poop.cpp index 8548a82..e47b490 100644 --- a/src/grid_entity_poop.cpp +++ b/src/grid_entity_poop.cpp @@ -3,10 +3,12 @@ #include "entity_config.h" #include "entity_effect_combat.h" #include "entity_familiar.h" +#include "entity_knife.h" #include "entity_npc.h" #include "entity_pickup.h" #include "entity_player.h" #include "game.h" +#include "grid_entity_rock.h" #include "log.h" #include "manager.h" #include "npc_ai.h" @@ -66,6 +68,8 @@ constexpr int HALLOWED_AURA_Z = 10000; // it drops: one in twenty its Petrified Poop, else a heart a quarter of the time (Daemon's Tail and Butt Penny take // some back) or a penny. constexpr float POOP_DROP_CHANCE = 0.1f; +constexpr float AXE_DROP_CHANCE = 0.2f; +constexpr float POOP_DROP_SPEED = 2; constexpr float GIGA_DROP_CHANCE = 0.25f; constexpr float LOW_DROP_CHANCE = 0.01f; constexpr float BUTT_PENNY_BASE = 0.2f; @@ -79,6 +83,7 @@ constexpr uint32_t BUTT_PENNY_HEART_ODDS = 3; // Meconium's black heart, per hundred by multiplier. constexpr uint32_t COUNTERFEIT_ODDS = 3; constexpr int GOLDEN_COINS_MIN = 5; +constexpr int AXE_GOLDEN_COINS_MIN = 2; constexpr uint32_t GOLDEN_COINS_RANGE = 3; constexpr int COIN_THROW_ATTEMPTS = 10; constexpr float COIN_THROW_SPEED = 5; @@ -141,6 +146,15 @@ struct PoopDrop uint32_t seed = 0; }; +// The generators of the trinkets and item a poop's drop roll asks: Daemon's Tail, Butt Penny and E. Coli, each of a +// random owner, or none. +struct PoopOwners +{ + RNG* buttPenny = nullptr; + RNG* eColi = nullptr; + RNG* tail = nullptr; +}; + // Whether a poop variant is a part of the giant poop. static bool is_giga(int variant) { @@ -682,31 +696,35 @@ static float drop_chance_get(float chance, bool isLowDropChance) return isLowDropChance ? LOW_DROP_CHANCE : chance; } -// The drop roll of a poop: the owners of Daemon's Tail, Butt Penny and E. Coli drawn from ownerRng, then from rng -// one in twenty the Petrified Poop (while in the pool), else a heart or a penny. E. Coli may still give a heart when -// nothing drops. -static PoopDrop poop_drop_roll(RNG& ownerRng, RNG& rng, float baseChance, bool isLowDropChance) +// The owners of Daemon's Tail, Butt Penny and E. Coli a poop's drop roll asks, drawn from a generator in that order. +static PoopOwners poop_owners_draw(RNG& ownerRng) { PlayerManager& players = g_game->playerManager; - RNG* tail = nullptr; - RNG* buttPenny = nullptr; - RNG* eColi = nullptr; - players.RandomTrinketOwner(TRINKET_DAEMONS_TAIL, ownerRng.Next(), &tail); - players.RandomTrinketOwner(TRINKET_BUTT_PENNY, ownerRng.Next(), &buttPenny); - players.RandomCollectibleOwner(COLLECTIBLE_E_COLI, ownerRng.Next(), &eColi); - float chance = drop_chance_get(baseChance, isLowDropChance); + PoopOwners owners; + players.RandomTrinketOwner(TRINKET_DAEMONS_TAIL, ownerRng.Next(), &owners.tail); + players.RandomTrinketOwner(TRINKET_BUTT_PENNY, ownerRng.Next(), &owners.buttPenny); + players.RandomCollectibleOwner(COLLECTIBLE_E_COLI, ownerRng.Next(), &owners.eColi); + return owners; +} +// The drop roll of a poop from rng: one in twenty the Petrified Poop (while in the pool), else a heart or a penny. +// E. Coli may still give a heart when nothing drops. +static PoopDrop poop_drop_roll(const PoopOwners& owners, RNG& rng, float baseChance, bool isLowDropChance) +{ + float chance = drop_chance_get(baseChance, isLowDropChance); if (chance <= rng.RandomFloat()) { - bool isHeart = eColi && eColi->RandomFloat() < chance && (rng.RandomFloat() < LOW_DROP_CHANCE || !isLowDropChance) && - rng.RandomFloat() < HEART_CHANCE && (!tail || tail->Next() % DAEMONS_TAIL_ODDS == 0); + bool isHeart = owners.eColi && owners.eColi->RandomFloat() < chance && + (rng.RandomFloat() < LOW_DROP_CHANCE || !isLowDropChance) && rng.RandomFloat() < HEART_CHANCE && + (!owners.tail || owners.tail->Next() % DAEMONS_TAIL_ODDS == 0); return isHeart ? PoopDrop{.variant = PICKUP_HEART, .seed = rng.Next()} : PoopDrop{}; } if (rng.Next() % PETRIFIED_ODDS == 0 && g_game->itemPool.RemoveTrinket(TRINKET_PETRIFIED_POOP)) return {.subType = TRINKET_PETRIFIED_POOP, .variant = PICKUP_TRINKET, .seed = Random()}; - bool isHeart = rng.RandomFloat() < HEART_CHANCE && (!tail || tail->Next() % DAEMONS_TAIL_ODDS == 0) && - (!buttPenny || buttPenny->Next() % BUTT_PENNY_HEART_ODDS == 0); + bool isHeart = rng.RandomFloat() < HEART_CHANCE && + (!owners.tail || owners.tail->Next() % DAEMONS_TAIL_ODDS == 0) && + (!owners.buttPenny || owners.buttPenny->Next() % BUTT_PENNY_HEART_ODDS == 0); return {.variant = isHeart ? PICKUP_HEART : PICKUP_COIN, .seed = rng.Next()}; } @@ -759,7 +777,7 @@ void GridEntity_Poop::spawn_rewards(const PoopHit& hit) RNG roll = {rng._seed, 7, 17, 21}; if ((roll.Next() & 1) != 0) continue; - PoopDrop drop = poop_drop_roll(roll, roll, GIGA_DROP_CHANCE, hit.isLowDropChance); + PoopDrop drop = poop_drop_roll(poop_owners_draw(roll), roll, GIGA_DROP_CHANCE, hit.isLowDropChance); Entity* pickup = drop.variant == PICKUP_NULL ? nullptr : g_game->Spawn({.position = position, .subType = drop.subType, .type = ENTITY_PICKUP, .variant = drop.variant, @@ -771,18 +789,20 @@ void GridEntity_Poop::spawn_rewards(const PoopHit& hit) } } -// The golden poop's drop: one time in three its Counterfeit Penny while in the pool, else five to seven pennies -// thrown where the way is clear. -static void golden_drops_spawn(const Vector& position, RNG& rng) +// The golden poop's drop: one time in three its Counterfeit Penny while in the pool, which ends the drops, else five +// to seven pennies (two or three on an axe's extra rolls) thrown where the way is clear. +static bool is_golden_drop_final(const Vector& position, RNG& rng, int rolls) { if (rng.Next() % COUNTERFEIT_ODDS == 0 && g_game->itemPool.RemoveTrinket(TRINKET_COUNTERFEIT_PENNY)) { g_game->Spawn({.position = position, .subType = TRINKET_COUNTERFEIT_PENNY, .type = ENTITY_PICKUP, .variant = PICKUP_TRINKET, .seed = rng.Next()}); - return; + return true; } - for (int coins = (int)(rng.Next() % GOLDEN_COINS_RANGE) + GOLDEN_COINS_MIN; coins > 0; coins--) + int coins = (int)(rng.Next() % GOLDEN_COINS_RANGE) + GOLDEN_COINS_MIN; + if (rolls > 1) coins = (int)(rng.Next() & 1) + AXE_GOLDEN_COINS_MIN; + for (; coins > 0; coins--) { Vector velocity{}; for (int attempt = 0; attempt < COIN_THROW_ATTEMPTS; attempt++) @@ -797,6 +817,7 @@ static void golden_drops_spawn(const Vector& position, RNG& rng) g_game->Spawn({.position = position, .velocity = velocity, .type = ENTITY_PICKUP, .variant = PICKUP_COIN, .seed = rng.Next()}); } + return false; } // The rainbow poop's reward: its giant book and fanfare, and full health for every living player (in versus, only the @@ -831,22 +852,20 @@ static void black_poop_blast(const EntityRef& source) } // Meconium's chance at a black heart from a black poop (by the breaker's in versus). -static void meconium_drop_try(const Vector& position, const EntityRef& source, RNG& rng) +static PoopDrop meconium_drop_roll(const EntityRef& source, RNG& rng) { Entity_Player* owner = g_game->playerManager.FirstTrinketOwner(TRINKET_MECONIUM); if (g_game->deathmatchManager.is_active()) { - if (!source.entity) return; + if (!source.entity) return {}; owner = source_player_get(source); } - if (!owner) return; + if (!owner) return {}; int multiplier = owner->GetTrinketMultiplier(TRINKET_MECONIUM); uint32_t odds = multiplier == 2 ? MECONIUM_ODDS_DOUBLE : multiplier == 3 ? MECONIUM_ODDS_TRIPLE : MECONIUM_ODDS; - if (rng.Next() % MECONIUM_ROLL >= odds) return; - g_game->Spawn({.position = position, .subType = HEART_BLACK, .type = ENTITY_PICKUP, .variant = PICKUP_HEART, - .seed = rng.Next()}); - Random(); + if (rng.Next() % MECONIUM_ROLL >= odds) return {}; + return {.subType = HEART_BLACK, .variant = PICKUP_HEART, .seed = rng.Next()}; } // Whether a player has the Oh Crap form and so heals on broken poop. @@ -881,40 +900,49 @@ static void trinket_effects_spawn(const Vector& position, const EntityRef& sourc .radius = BROWN_CAP_RADIUS, .isLineCheck = false}); } -// 007178c0 Spawns what a broken poop drops by kind: plain, corny and white poop roll a pickup, golden poop pays out, -// rainbow poop heals everyone, black poop blasts the room (with Meconium's black heart), then the Oh Crap form heals -// and Lil Larva and Brown Cap go off for all but red poop. -// The swinging player (set only by Entity_Knife::UpdateSwingHits, not curated) never rolls again or makes Book of -// Virtues wisps here. +// 007178c0 Spawns what a broken poop drops by kind, roll by roll (three for a Notched Axe swinger with Book of +// Belial): plain, corny and white poop roll a pickup, golden poop pays out (its Counterfeit Penny ends the rolls), +// black poop may give Meconium's black heart, and on the last roll rainbow poop heals everyone and black poop blasts +// the room. The pickups after the first fly off at a random angle. Then the Oh Crap form heals, Lil Larva and Brown +// Cap go off for all but red poop, and the swinger's Book of Virtues may make a wisp. void GridEntity_Poop::spawn_drops(const PoopHit& hit) { RNG ownerRng = {hit.seed, 2, 7, 7}; RNG rng = {hit.seed, 1, 5, 16}; - switch (hit.variant) + PoopOwners owners = poop_owners_draw(ownerRng); + Entity_Player* axe = g_notchedAxePlayer; + int rolls = axe && axe->HasCollectible(COLLECTIBLE_BOOK_OF_BELIAL_PASSIVE) ? AXE_ROLLS : 1; + Vector velocity{}; + + for (; rolls > 0; rolls--) { - case POOP_NORMAL: - case POOP_CORNY: - case POOP_WHITE: + PoopDrop drop; + switch (hit.variant) { - PoopDrop drop = poop_drop_roll(ownerRng, rng, POOP_DROP_CHANCE, hit.isLowDropChance); - if (drop.variant == PICKUP_NULL) break; - g_game->Spawn({.position = hit.position, .subType = drop.subType, .type = ENTITY_PICKUP, - .variant = drop.variant, .seed = drop.seed}); - if (drop.variant != PICKUP_TRINKET) Random(); - break; + case POOP_NORMAL: + case POOP_CORNY: + case POOP_WHITE: + drop = poop_drop_roll(owners, rng, rolls > 1 ? AXE_DROP_CHANCE : POOP_DROP_CHANCE, hit.isLowDropChance); + break; + case POOP_GOLDEN: + if (is_golden_drop_final(hit.position, rng, rolls)) rolls = 0; + break; + case POOP_RAINBOW: + if (rolls == 1) rainbow_heal(hit.source); + break; + case POOP_BLACK: + if (rolls == 1) black_poop_blast(hit.source); + drop = meconium_drop_roll(hit.source, rng); + break; + default: + break; } - case POOP_GOLDEN: - golden_drops_spawn(hit.position, rng); - break; - case POOP_RAINBOW: - rainbow_heal(hit.source); - break; - case POOP_BLACK: - black_poop_blast(hit.source); - meconium_drop_try(hit.position, hit.source, rng); - break; - default: - break; + if (drop.variant == PICKUP_NULL) continue; + + bool isTrinket = drop.variant == PICKUP_TRINKET; + g_game->Spawn({.position = hit.position, .velocity = isTrinket ? Vector{} : velocity, .subType = drop.subType, + .type = ENTITY_PICKUP, .variant = drop.variant, .seed = drop.seed}); + if (!isTrinket) velocity = vector_scale(random_direction(), POOP_DROP_SPEED); } bool isHealing = hit.variant == POOP_NORMAL || hit.variant == POOP_CORNY || hit.variant == POOP_GOLDEN || @@ -927,4 +955,9 @@ void GridEntity_Poop::spawn_drops(const PoopHit& hit) if (is_oh_crap(*player)) player->AddHearts(1, false, false); if (hit.variant != POOP_RED) trinket_effects_spawn(hit.position, hit.source); + if (hit.isNoWisp) return; + + RNG wispRng = {hit.seed, 7, 17, 21}; + if ((wispRng.Next() & 1) != 0 || !axe || !axe->HasCollectible(COLLECTIBLE_BOOK_OF_VIRTUES)) return; + axe->AddWisp(hit.variant == POOP_GOLDEN ? ROCK_WISP_GOLD : COLLECTIBLE_POOP, hit.position, false, false); } diff --git a/src/grid_entity_pressure_plate.cpp b/src/grid_entity_pressure_plate.cpp index d15cdab..8c24016 100644 --- a/src/grid_entity_pressure_plate.cpp +++ b/src/grid_entity_pressure_plate.cpp @@ -448,8 +448,9 @@ static void plate_ambush_spawn(GridEntity& plate, RNG& rng) Vector position = room_free_pickup_position_find({.position = positions[(size_t)i % positions.size()]}); float angle = random_unit() * PI_ROUGH; angle += angle; - float distance = random_unit() * AMBUSH_SCATTER; - position = vector_add(position, vector_make(std::cos(angle) * distance, std::sin(angle) * distance)); + float distance = random_unit(); + position = vector_add(position, vector_make(std::cos(angle) * distance * AMBUSH_SCATTER, + std::sin(angle) * distance * AMBUSH_SCATTER)); entity_spawn(enemy.type, enemy.variant, position, seed); } @@ -471,7 +472,7 @@ static void plate_ambush_spawn(GridEntity& plate, RNG& rng) } // 00983f30 pressure_plate_kill_enemies_timer_callback: each frame the kill button's timer strikes the room's -// door-shutting enemies, ten at most (none friendly, no Blood Puppy or Dark Esau), with 1000 damage from its presser +// door-shutting enemies (and the players in a versus match), ten at most (none friendly, no Blood Puppy or Dark Esau), with 1000 damage from its presser // (their health dropped to none first) or a plain kill at none, in red poofs on its first frame. Projectiles die while // the timer lives and moveable fires burn out. Five frames with nothing left end it. static void kill_button_tick(Entity_Effect* timer) @@ -485,7 +486,8 @@ static void kill_button_tick(Entity_Effect* timer) for (size_t i = 0; i < entities.size(); i++) { Entity& entity = *entities[i]; - bool isEnemy = is_npc_type(entity.type) && entity.CanShutDoors() && !entity.HasEntityFlags(FLAG_FRIENDLY) && + bool isVersusPlayer = game.deathmatchManager.is_active() && entity.type == ENTITY_PLAYER; + bool isEnemy = (isVersusPlayer || is_npc_type(entity.type)) && entity.CanShutDoors() && !entity.HasEntityFlags(FLAG_FRIENDLY) && entity.type != ENTITY_BLOOD_PUPPY && entity.type != ENTITY_DARK_ESAU; if (!isEnemy) { diff --git a/src/grid_entity_rock.cpp b/src/grid_entity_rock.cpp index c13e023..0dee152 100644 --- a/src/grid_entity_rock.cpp +++ b/src/grid_entity_rock.cpp @@ -165,14 +165,8 @@ constexpr float BUCKET_SLUDGE_SPEED_RANGE = 5; constexpr int BUCKET_SLUDGE_MIN = 4; constexpr uint32_t BUCKET_SLUDGE_RANGE = 5; -// Notched Axe's rolls with Book of Belial, and its Book of Virtues rock wisps: one roll in five, by chance below each. -constexpr int AXE_ROLLS = 3; +// Notched Axe's Book of Virtues rock wisps: one roll in five, by chance below each. constexpr uint32_t AXE_WISP_ODDS = 5; -constexpr int ROCK_WISP_COMMON = 0x10000; -constexpr int ROCK_WISP_UNCOMMON = 0x10001; -constexpr int ROCK_WISP_GOLD = 0x10002; -constexpr int ROCK_WISP_RAREST = 0x10003; -constexpr int ROCK_WISP_RARE = 0x10004; constexpr float ROCK_WISP_RAREST_CHANCE = 0.01f; constexpr float ROCK_WISP_GOLD_CHANCE = 0.04f; constexpr float ROCK_WISP_RARE_CHANCE = 0.08f; @@ -483,13 +477,13 @@ static void spikes_hurt(GridEntity_Rock& rock) // Keeper's Kin lets a blue spider out of a rock, on the free side of it nearest its owner. static void rock_spider_release(GridEntity_Rock& rock, Entity_Player& owner) { - constexpr std::array, 4> SIDES = { + constexpr std::array, 4> SPIDER_SIDES = { {{-SPIDER_SIDE, 0}, {SPIDER_SIDE, 0}, {0, -SPIDER_SIDE}, {0, SPIDER_SIDE}}}; Room& room = *g_game->room; Vector position = rock.Position(); Vector spot{}; float best = SPIDER_FAR; - for (const std::array& side : SIDES) + for (const std::array& side : SPIDER_SIDES) { Vector at = vector_make(position.x + side[0], position.y + side[1]); float dx = owner.pos.x - at.x; diff --git a/src/grid_entity_rock.h b/src/grid_entity_rock.h index 8ba4f40..140dea3 100644 --- a/src/grid_entity_rock.h +++ b/src/grid_entity_rock.h @@ -7,6 +7,15 @@ // The variant a big rock's frame is stored above. constexpr int BIG_ROCK_VARIANT = 1000; +// The rolls a Notched Axe swing gives a broken rock's or poop's drops with Book of Belial, and the Book of Virtues wisps +// it breaks out of them: common, uncommon, gold, rarest and rare. +constexpr int AXE_ROLLS = 3; +constexpr int ROCK_WISP_COMMON = 0x10000; +constexpr int ROCK_WISP_UNCOMMON = 0x10001; +constexpr int ROCK_WISP_GOLD = 0x10002; +constexpr int ROCK_WISP_RAREST = 0x10003; +constexpr int ROCK_WISP_RARE = 0x10004; + // A rock standing, broken, primed to blow (a bomb rock hit by an explosion) and cracked (a super secret rock). enum RockState : int { diff --git a/src/hud.cpp b/src/hud.cpp index a5f5c19..2d6a0e2 100644 --- a/src/hud.cpp +++ b/src/hud.cpp @@ -1156,8 +1156,6 @@ void HUD::render_counters(Vector& cursor, Vector shake) constexpr float ROW_HEIGHT = 12; constexpr float ROW_HEIGHT_TIGHT = 11; constexpr float JACOB_SHIFT = 14; - constexpr float TEXT_OFFSET_X = 16; - constexpr float TEXT_OFFSET_Y = 1; PlayerManager& players = g_game->playerManager; Entity_Player* player = players.playerList.empty() ? nullptr : players.playerList[0]; @@ -1181,7 +1179,7 @@ void HUD::render_counters(Vector& cursor, Vector shake) Vector at = at_make(shake.x + cursor.x, shake.y + cursor.y); std::snprintf(count, sizeof(count), format, value); - text_draw(font6, count, at_make(at.x + TEXT_OFFSET_X, at.y + TEXT_OFFSET_Y)); + text_draw(font6, count, at_make(at.x + HUD_TEXT_OFFSET_X, at.y + HUD_TEXT_OFFSET_Y)); cursor = at_make(at.x - shake.x, at.y - shake.y); }; diff --git a/src/item_config.cpp b/src/item_config.cpp index 204b365..7a6d4ba 100644 --- a/src/item_config.cpp +++ b/src/item_config.cpp @@ -13,7 +13,6 @@ constexpr int LOG_LINE_SIZE = 1024; constexpr std::string_view ITEMS_VERSION = "1"; -constexpr char WORD_SEPARATOR = ' '; constexpr std::string_view ITEMS_CATEGORY = "Items"; constexpr std::string_view POCKET_ITEMS_CATEGORY = "PocketItems"; constexpr const char* COLLECTIBLE_OUT_OF_BOUNDS = "Collectible ID out of bounds.\n"; diff --git a/src/item_pool.cpp b/src/item_pool.cpp index 49bfab8..4994bb6 100644 --- a/src/item_pool.cpp +++ b/src/item_pool.cpp @@ -104,7 +104,6 @@ constexpr int ONANS_STREAK_BANNED[] = {68, 118, 329, 52, 168, 114, 395, 394, 55, constexpr int PILL_COLORS = 13; constexpr int PILL_GOLD_ODDS = 140; constexpr int PILL_HORSE_ODDS = 70; -constexpr int PILL_EFFECT_NONE = -1; // The effect class each shuffled color slot must have, or -1 for any. constexpr int PILL_SLOT_CLASSES[PILL_COLOR_SLOTS - 1] = {3, 3, 3, 3, 2, 1, 0, -1, -1, 3, 2, 1, -1, -1}; // PHD's good side of a bad pill (0x00b6a240), and False PHD's bad side of a good one (its jump table at 0x00734c40). @@ -272,7 +271,7 @@ void ItemPool::Init(uint32_t startSeed, std::string_view path) effects.erase(effect); } - pillEffects[0] = PILL_EFFECT_NONE; + pillEffects[0] = PILLEFFECT_NULL; for (auto& card : config.cards) if (card) g_manager->sfxManager.Preload(card->announcerVoice); identifiedPillEffects = {}; @@ -894,7 +893,7 @@ static int effect_swap(std::span> pairs, int effect) int ItemPool::GetPillEffect(uint32_t pillColor, Entity_Player* player) { int color = (int)(pillColor & PILL_COLOR_MASK); - int effect = color < PILL_COLOR_SLOTS ? pillEffects[color] : PILL_EFFECT_NONE; + int effect = color < PILL_COLOR_SLOTS ? pillEffects[color] : PILLEFFECT_NULL; bool isFalsePhd = false; if (g_game->dailyChallenge.specialDailyId == SPECIAL_DAILY_AUGUST_16) return PILLEFFECT_EXPLOSIVE_DIARRHEA; diff --git a/src/level.cpp b/src/level.cpp index c345b51..a014cb4 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -250,7 +250,7 @@ constexpr uint32_t KRAMPUS_ODDS_VISITED = 1; constexpr uint32_t KRAMPUS_ODDS_DEAL = 3; constexpr uint32_t KRAMPUS_ODDS_DEALS_DAILY = 10; -// The angel chance starts at 1 (half after Famine or a visited devil room) and each item adds a quarter of what is +// The angel chance starts at 1 (half once an angel door spawned or a devil room was visited) and each item adds a quarter of what is // left, ten donations half, a beggar left a tenth. Eucharist sets it past 1. constexpr float ANGEL_CHANCE_HALVED = 0.5f; constexpr float ANGEL_ITEM_SHARE = 0.25f; @@ -4177,9 +4177,9 @@ bool Level::CanSpawnDevilRoom() return std::popcount(roomList[lastBossRoomListIdx].data->doors & 0xff) > 1; } -// 007f96f0 The chance the floor's deal room is an angel room: halved after Famine or a visited devil room, raised -// by the Key Pieces, Book of Virtues, donations and a killed evil beggar, moved a tenth by a beggar left or an evil -// one left, and scaled by the floor's own chance (none without it, unless no deal was taken since a devil room +// 007f96f0 The chance the floor's deal room is an angel room: halved after an angel door or a visited devil room, +// raised by the Key Pieces, Book of Virtues, donations and a killed evil beggar, moved a tenth by a beggar left or an +// evil one left, and scaled by the floor's own chance (none without it, unless no deal was taken since a devil room // spawned). Eucharist makes it sure. float get_angel_room_chance() { @@ -4187,10 +4187,10 @@ float get_angel_room_chance() PlayerManager& players = game.playerManager; auto isHeld = [&](int item) { return players.FirstCollectibleOwner(item, LAZARUS_SHARE_CHECK) != nullptr; }; auto raise = [](float chance, float share) { return chance + (1 - chance) * share; }; - bool isFamineOrVisited = game.gameStateFlags & (1ull << GAME_STATE_FAMINE_SPAWNED | 1ull << GAME_STATE_DEVILROOM_VISITED); + bool isHalved = game.gameStateFlags & (1ull << GAME_STATE_FAMINE_SPAWNED | 1ull << GAME_STATE_DEVILROOM_VISITED); bool isDevilSpawned = game.gameStateFlags & (1ull << GAME_STATE_DEVILROOM_SPAWNED); - float chance = isFamineOrVisited ? ANGEL_CHANCE_HALVED : 1; + float chance = isHalved ? ANGEL_CHANCE_HALVED : 1; if (isHeld(COLLECTIBLE_KEY_PIECE_1)) chance = raise(chance, ANGEL_ITEM_SHARE); if (isHeld(COLLECTIBLE_KEY_PIECE_2)) chance = raise(chance, ANGEL_ITEM_SHARE); if (isHeld(COLLECTIBLE_BOOK_OF_VIRTUES)) chance = raise(chance, ANGEL_ITEM_SHARE); diff --git a/src/level_red_room.cpp b/src/level_red_room.cpp index 77afd49..7fad227 100644 --- a/src/level_red_room.cpp +++ b/src/level_red_room.cpp @@ -201,6 +201,7 @@ int Level::roll_red_room_type(RNG& rng) // 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. +// A negative slot is taken as the last one, where the original passes -1 on into undefined shifts. bool Level::MakeRedRoomDoor(int roomIdx, int doorSlot) { roomIdx = std::clamp(roomIdx, ROOM_IDX_MIN, ROOM_IDX_MAX); diff --git a/src/music_manager.cpp b/src/music_manager.cpp index f98d09a..22c824b 100644 --- a/src/music_manager.cpp +++ b/src/music_manager.cpp @@ -327,13 +327,13 @@ void MusicManager::LoadConfig(std::string_view path, ModEntry* mod) } } -// A pitch bent up and down around itself by three slow sines at a time, by depth octaves at most. -static float pitch_wobble(float pitch, double time, float depth) +// A pitch bent up and down around itself by three slow sines at a time, by scale times depth octaves at most. +static float pitch_wobble(float pitch, double time, float scale, float depth) { float wave = 0; for (size_t i = 0; i < WOBBLE_FREQUENCIES.size(); i++) wave += (float)std::sin(time * WOBBLE_FREQUENCIES[i]) * WOBBLE_AMPLITUDES[i]; - return std::pow(2.0f, wave * depth + std::log(pitch) / std::log(2.0f)); + return pow_float(2, wave * scale * depth + log_float(pitch) / log_float(2)); } // Sets the pitch the run's music seeds give, then in a game the wobble of dizziness and of a red room. Whether any @@ -354,12 +354,12 @@ bool MusicManager::pitch_effects_apply() double frame = (int)g_manager->framecount; if (g_game->dizzyIntensity > 0) { - pitch = pitch_wobble(pitch, frame * DIZZY_WOBBLE_SPEED, g_game->dizzyIntensity * DIZZY_WOBBLE_DEPTH); + pitch = pitch_wobble(pitch, frame * DIZZY_WOBBLE_SPEED, g_game->dizzyIntensity, DIZZY_WOBBLE_DEPTH); isChanged = true; } if (g_game->room->descriptor->flags & ROOM_DESCRIPTOR_FLAG_RED_ROOM) { - pitch = pitch_wobble(pitch, frame * RED_ROOM_WOBBLE_SPEED, RED_ROOM_WOBBLE_DEPTH); + pitch = pitch_wobble(pitch, frame * RED_ROOM_WOBBLE_SPEED, 1, RED_ROOM_WOBBLE_DEPTH); isChanged = true; } return isChanged; diff --git a/src/npc_alt.h b/src/npc_alt.h index ef7d3ad..cf8d508 100644 --- a/src/npc_alt.h +++ b/src/npc_alt.h @@ -6,6 +6,9 @@ // The splat of the stone and lava enemies: black, lifted a little. constexpr ColorMod ROCK_SPLAT_COLOR = {{0, 0, 0, 1}, {0, 0, 0, 0}, {30 / 255.0f, 30 / 255.0f, 30 / 255.0f}}; +// The splat of the burning enemies (Coal Boy, the Fire Worm): glowing orange. +constexpr ColorMod EMBER_SPLAT_COLOR = {{0, 0, 0, 1.1f}, {0, 0, 0, 0}, {1, 0.514f, 0.004f}}; + // A cord's points sit in vectorDeque1 as triples: the point, its velocity, and its height with the height's speed. constexpr size_t CORD_STRIDE = 3; diff --git a/src/npc_army_fly.cpp b/src/npc_army_fly.cpp index 4cdd8ca..1dedd02 100644 --- a/src/npc_army_fly.cpp +++ b/src/npc_army_fly.cpp @@ -187,7 +187,7 @@ void npc_army_fly_update(Entity_NPC& npc) if (npc.controllerID != -1) army_fly_control_pass(npc); if (npc.state == NPC_STATE_INIT) army_fly_enlist(npc); - if (npc.state == NPC_STATE_MOVE) + else if (npc.state == NPC_STATE_MOVE) { npc.sprite.Play("Fly"); segment_follow(npc, SEGMENT_FOLLOW, ARMY_FLY_GAP, ARMY_FLY_FOLLOW_SPEED); diff --git a/src/npc_ball_and_chain.cpp b/src/npc_ball_and_chain.cpp index 00c6d2d..159a14f 100644 --- a/src/npc_ball_and_chain.cpp +++ b/src/npc_ball_and_chain.cpp @@ -92,7 +92,7 @@ static void ball_facing_show(Entity_NPC& npc, float degrees, float turn) npc.sprite.rotation = turn - (float)facing * BALL_FACING_STEP; } -// Its first frame: it hangs from the first rock beside it (above, below, left, right) at its chain's length, or drops +// Its first frame: it hangs from the last rock beside it (above, below, left, right) at its chain's length, or drops // free. It is untouchable and out of the players' control. static void ball_start(Entity_NPC& npc, float radius) { @@ -106,7 +106,6 @@ static void ball_start(Entity_NPC& npc, float radius) if (!chain_anchor_is_valid(grid)) continue; npc.targetPosition = room.GetGridPosition(grid->gridIndex); npc.i1 = grid->gridIndex; - break; } if (npc.sprite.SetOverlayAnimation("Chain") && npc.sprite.overlayAnimState.animData) diff --git a/src/npc_bomb_gagger.cpp b/src/npc_bomb_gagger.cpp index 57149e4..34784b8 100644 --- a/src/npc_bomb_gagger.cpp +++ b/src/npc_bomb_gagger.cpp @@ -130,8 +130,9 @@ void npc_bomb_gagger_update(Entity_NPC& npc) { npc.state = GAGGER_WANDER; npc.i2 = 0; + return; } - else if (npc.state == GAGGER_WANDER) gagger_wander_update(npc); + if (npc.state == GAGGER_WANDER) gagger_wander_update(npc); else if (npc.state == GAGGER_THROW) gagger_throw_update(npc); if (!npc.isDead || !npc.sprite.animState.animData) return; diff --git a/src/npc_bomb_grimace.cpp b/src/npc_bomb_grimace.cpp index d9c3f3e..4989108 100644 --- a/src/npc_bomb_grimace.cpp +++ b/src/npc_bomb_grimace.cpp @@ -103,7 +103,7 @@ void npc_bomb_grimace_update(Entity_NPC& npc) bool isInMineshaft = game.HasAbandonedMineshaft() && game.currentDimensionIdx == DIMENSION_MIRROR && !game.Level::GetStateFlag(LEVEL_STATE_MINESHAFT_ESCAPE); - if (npc.state == NPC_STATE_INIT) grimace_init(npc, isInMineshaft); + if (npc.state == NPC_STATE_INIT) return grimace_init(npc, isInMineshaft); if (npc.state == NPC_STATE_IDLE) { diff --git a/src/npc_cod_worm.cpp b/src/npc_cod_worm.cpp index c0de415..0321868 100644 --- a/src/npc_cod_worm.cpp +++ b/src/npc_cod_worm.cpp @@ -120,7 +120,8 @@ static void cod_worm_control_update(Entity_NPC& npc, bool isShielded) } float rate = npc.speedMultiplier / COD_WORM_CHARGE_FRAMES; - if (!isShielded) npc.v1.x = std::max(npc.v1.x - rate * COD_WORM_CHARGE_DRAIN, 0.0f); + if (!isShielded) + npc.v1.x = std::max(npc.v1.x - npc.speedMultiplier * COD_WORM_CHARGE_DRAIN / COD_WORM_CHARGE_FRAMES, 0.0f); else if (npc.IsPlayerInRadius(npc.pos, COD_WORM_CHARGE_REACH)) npc.v1.x = std::max(npc.v1.x - rate, 0.0f); else npc.v1.x = std::min(npc.v1.x + rate, 1.0f); } diff --git a/src/npc_collision.cpp b/src/npc_collision.cpp index fed1978..70cca52 100644 --- a/src/npc_collision.cpp +++ b/src/npc_collision.cpp @@ -902,7 +902,7 @@ static void contact_enemy(Entity_NPC& npc, Entity& other) return; hit_list_insert(npc.hitList, other); - damage = std::log((npc.maxHitPoints + CHARMED_DAMAGE_BASE) / CHARMED_DAMAGE_SCALE) * CHARMED_DAMAGE_LOG; + damage = log_float((npc.maxHitPoints + CHARMED_DAMAGE_BASE) / CHARMED_DAMAGE_SCALE) * CHARMED_DAMAGE_LOG; if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM) && g_game->deathmatchManager.is_active()) damage = npc.collisionDamage; if (npc.type == ENTITY_VIS && npc.variant == VIS_CHUBBER_VARIANT) damage = CHUBBER_DAMAGE; diff --git a/src/npc_danny.cpp b/src/npc_danny.cpp index 040ebdd..9dcbbeb 100644 --- a/src/npc_danny.cpp +++ b/src/npc_danny.cpp @@ -9,7 +9,6 @@ // pale grey and glowing orange. constexpr int DANNY_COAL_BOY = 1; constexpr ColorMod DANNY_SPLAT_COLOR = {{1, 1, 1, 1}, {1, 1, 1, 0.1f}, {0, 0, 0}}; -constexpr ColorMod COAL_BOY_SPLAT_COLOR = {{0, 0, 0, 1.1f}, {0, 0, 0, 0}, {1, 0.514f, 0.004f}}; // They walk at 0.6 and recharge over 150 frames (10 to 19 at first, twice as fast while hurt hard), then throw one // time in 60 a frame (one in 20 more while hurt hard): always within 200 of the target, one time in ten within 400. @@ -101,7 +100,7 @@ static void danny_throw(Entity_NPC& npc) if (npc.variant == DANNY_COAL_BOY) { - int lost = std::max(COAL_BOY_SPIDERS - kept, 0); + int lost = COAL_BOY_SPIDERS - kept; for (int thrown = 0; thrown < COAL_BOY_THROWS; thrown++) { Vector direction = throw_direction(aim); @@ -114,7 +113,8 @@ static void danny_throw(Entity_NPC& npc) return throw_grit_spray(npc, aim); } - int lost = std::max(DANNY_SPIDERS - kept, 0); + // The original clamps the lost count as unsigned, a no-op, so more spiders in its group than two add rocks. + int lost = DANNY_SPIDERS - kept; ProjectileParams params; params.variant = PROJECTILE_ROCK; npc.FireBossProjectiles(DANNY_ROCKS - lost, target, 1, params); @@ -197,7 +197,7 @@ void npc_danny_update(Entity_NPC& npc) case NPC_STATE_INIT: npc.state = DANNY_WALK; npc.sprite.Play("WalkVert"); - npc.splatColor = npc.variant == DANNY_COAL_BOY ? COAL_BOY_SPLAT_COLOR : DANNY_SPLAT_COLOR; + npc.splatColor = npc.variant == DANNY_COAL_BOY ? EMBER_SPLAT_COLOR : DANNY_SPLAT_COLOR; npc.stateFrame = npc.controllerID == -1 ? (int)(Random() % DANNY_FIRST_WAIT_RANGE) + DANNY_FIRST_WAIT : DANNY_FIRST_WAIT; break; diff --git a/src/npc_dip.cpp b/src/npc_dip.cpp index 38b6d10..d564c3f 100644 --- a/src/npc_dip.cpp +++ b/src/npc_dip.cpp @@ -10,7 +10,6 @@ constexpr int DIP_BIG_CORN = 3; constexpr int FAMILIAR_DIP_CORN = 2; constexpr int FAMILIAR_DIP_BROWNIE = 20; -constexpr int TRINKET_DIPPING_TRINKET_ID = 163; // How a Dip hops: one chance in ten a frame from rest, at a random speed (doubled for the corn dip), and how it // slows, splats and squeaks. @@ -80,11 +79,11 @@ void npc_dip_update(Entity_NPC& npc) bool isDrip = npc.type == ENTITY_DRIP; PlayerManager& players = g_game->playerManager; bool isTamed = players.FirstCollectibleOwner(COLLECTIBLE_DIRTY_MIND, LAZARUS_SHARE_CHECK) || - players.AnyoneHasTrinket(TRINKET_DIPPING_TRINKET_ID); + players.AnyoneHasTrinket(TRINKET_DINGLE_BERRY); if (!npc.isDead && isTamed) { Entity* owner = players.RandomCollectibleOwner(COLLECTIBLE_DIRTY_MIND, npc.initSeed, nullptr); - if (!owner) owner = players.RandomTrinketOwner(TRINKET_DIPPING_TRINKET_ID, npc.initSeed, nullptr); + if (!owner) owner = players.RandomTrinketOwner(TRINKET_DINGLE_BERRY, npc.initSeed, nullptr); if (owner) { npc.entityCollisionClass = ENTCOLL_NONE; @@ -132,7 +131,7 @@ void npc_dip_update(Entity_NPC& npc) ->SetColor(npc.splatColor, -1, COLOR_PRIORITY_DEFAULT, false, true); if (npc.pendingDamage > 0 && (Random() & 1) == 0) npc.PlaySound(SOUND_DIP_HURT, HURT_VOLUME, HURT_SOUND_DELAY, false, 1); - if (isBigCorn && npc.controllerID != -1 && input_is_action_pressed(ACTION_BOMB, npc.controllerID, &npc)) + if (isBigCorn && npc.controllerID != -1 && input_is_action_pressed(ACTION_ITEM, npc.controllerID, &npc)) npc.Kill(EntityRef()); if (npc.isDead && isBigCorn && !npc.HasEntityFlags(FLAG_SHRINK)) dip_corn_shoot(npc); } diff --git a/src/npc_evis.cpp b/src/npc_evis.cpp index ce21f76..4a115f1 100644 --- a/src/npc_evis.cpp +++ b/src/npc_evis.cpp @@ -143,7 +143,8 @@ static void evis_cord_init(Entity_NPC& cord, Entity& evis) cord.renderDepthOffset += EVIS_CORD_DEPTH; } -// Before its update the cord holds its catch, or catches the first player a stretch of it touches. +// Before its update the cord holds its catch, or catches the first player a stretch of it touches (past its first +// point, at Evis). static void evis_cord_catch(Entity_NPC& cord) { if (Entity* caught = cord.target.get()) @@ -151,7 +152,8 @@ static void evis_cord_catch(Entity_NPC& cord) cord.velocity = vector_sub(caught->pos, cord.pos); cord.posOffset.y = caught->IsFlying() ? HOLD_HEIGHT_FLYING : HOLD_HEIGHT; } - for (size_t i = 0; i < cord.vectorDeque1.size() && !cord.target; i += CORD_STRIDE) + for (size_t i = CORD_STRIDE; i < EVIS_CORD_POINTS * CORD_STRIDE && i < cord.vectorDeque1.size() && !cord.target; + i += CORD_STRIDE) { Capsule capsule = cord.GetCollisionCapsule(vector_sub(cord.vectorDeque1[i], cord.pos)); for (Entity* entity : entity_query_capsule(capsule, QUERY_PLAYERS)) @@ -207,7 +209,7 @@ static void evis_cord_flight(Entity_NPC& cord, bool isInterpolation) } // Evis' cord (variant 10): laid out on its first frame, it flies out and back until it catches a player. Without -// Evis it dies, and on dying it bursts into blood along its points. +// Evis it dies, and on dying it bursts into blood along its points past the first. static void evis_cord_update(Entity_NPC& cord) { bool isInterpolation = cord.aiCallPhase == AI_PHASE_INTERPOLATE; @@ -225,7 +227,7 @@ static void evis_cord_update(Entity_NPC& cord) } if (!cord.isDead) return; - for (size_t i = 0; i < EVIS_CORD_POINTS * CORD_STRIDE; i += CORD_STRIDE) + for (size_t i = CORD_STRIDE; i < EVIS_CORD_POINTS * CORD_STRIDE; i += CORD_STRIDE) if (i + 2 < cord.vectorDeque1.size()) blood_explosion_spawn(1, cord.vectorDeque1[i], vector_make(0, cord.vectorDeque1[i + 2].x), cord.splatColor, {}); } diff --git a/src/npc_fartigan.cpp b/src/npc_fartigan.cpp index 1f97ca9..87ac9bf 100644 --- a/src/npc_fartigan.cpp +++ b/src/npc_fartigan.cpp @@ -109,7 +109,11 @@ static void fartigan_death_spawn(Entity_NPC& npc, bool isDetonated) // 00561a20 The Fartigan's AI: it walks at its target farting gas clouds and blows itself up next to it. void npc_fartigan_update(Entity_NPC& npc) { - if (npc.state == NPC_STATE_INIT) npc.state = NPC_STATE_MOVE; + if (npc.state == NPC_STATE_INIT) + { + npc.state = NPC_STATE_MOVE; + return; + } Vector target = npc.CalcTargetPosition(0); bool isDetonated = false; if (npc.state == NPC_STATE_MOVE) isDetonated = fartigan_walk_update(npc, target); diff --git a/src/npc_fire_worm.cpp b/src/npc_fire_worm.cpp index 0a607fa..0382ade 100644 --- a/src/npc_fire_worm.cpp +++ b/src/npc_fire_worm.cpp @@ -152,7 +152,7 @@ void npc_fire_worm_update(Entity_NPC& npc) { npc.state = NPC_STATE_IDLE; npc.targetPosition = npc.pos; - npc.splatColor = ROCK_SPLAT_COLOR; + npc.splatColor = EMBER_SPLAT_COLOR; int pit = Entity_NPC::FindTargetPit(npc.pos, npc.pos, UINT32_MAX); if (pit < 0) npc.Remove(); else fire_worm_surface(npc, pit); diff --git a/src/npc_fly_trap.cpp b/src/npc_fly_trap.cpp index 820b992..f2b9add 100644 --- a/src/npc_fly_trap.cpp +++ b/src/npc_fly_trap.cpp @@ -121,7 +121,7 @@ static void fly_trap_walk_update(Entity_NPC& npc, size_t flyCount) if (npc.i1 > 0) return; bool isControlled = npc.controllerID != -1; - bool isFarting = isControlled ? input_is_action_pressed(ACTION_BOMB, npc.controllerID, &npc) + bool isFarting = isControlled ? input_is_action_pressed(ACTION_ITEM, npc.controllerID, &npc) : flyCount >= FLY_TRAP_FART_FLIES && Random() % FLY_TRAP_FART_ODDS == 0; if (isFarting) { diff --git a/src/npc_host.cpp b/src/npc_host.cpp index 3154e68..837ed70 100644 --- a/src/npc_host.cpp +++ b/src/npc_host.cpp @@ -151,10 +151,14 @@ static void host_rest_update(Entity_NPC& npc, bool isShelled) else { Vector target = npc.GetPlayerTarget()->pos; - int mode = npc.variant == HOST_HARD ? LINE_MODE_GROUND : LINE_MODE_PROJECTILE; + bool isHard = npc.variant == HOST_HARD; + LineQuery line = {.start = npc.pos, + .end = target, + .mode = isHard ? LINE_MODE_GROUND : LINE_MODE_PROJECTILE, + .gridPathThreshold = LINE_CHECK_THRESHOLD, + .isIgnoreCrushable = isHard}; bool isInRange = vector_length_squared(vector_sub(target, npc.pos)) < HOST_RANGE_SQUARED; - if (isInRange && (npc.championColorIdx == CHAMPION_TRANSPARENT || - room_check_line(npc.pos, target, mode, LINE_CHECK_THRESHOLD))) + if (isInRange && (npc.championColorIdx == CHAMPION_TRANSPARENT || room_check_line(line))) { npc.projectileCooldown = HOST_COOLDOWN; npc.state = NPC_STATE_ATTACK; diff --git a/src/npc_leper.cpp b/src/npc_leper.cpp index 8cd0252..946fc64 100644 --- a/src/npc_leper.cpp +++ b/src/npc_leper.cpp @@ -178,7 +178,7 @@ static void leper_shed(Entity_NPC& npc) .type = ENTITY_EFFECT, .variant = EFFECT_BLOOD_EXPLOSION, .seed = Random()}); - blood->SetColor(COLOR_DEFAULT, -1, COLOR_PRIORITY_DEFAULT, false, false); + blood->SetColor(COLOR_DEFAULT, -1, COLOR_PRIORITY_DEFAULT, false, true); blood->sprite.offset = vector_make(0, LEPER_SHED_BLOOD_HEIGHT); blood->renderDepthOffset = LEPER_SHED_BLOOD_DEPTH; } diff --git a/src/npc_maw.cpp b/src/npc_maw.cpp index cd55cae..4c3baad 100644 --- a/src/npc_maw.cpp +++ b/src/npc_maw.cpp @@ -72,10 +72,12 @@ static void maw_spit(Entity_NPC& npc) npc.FireProjectiles(npc.pos, aim, PROJECTILES_SINGLE, params); } -// Drifting: it idles, and starts spitting at a target in range (but for the red one), facing it. +// Drifting: it idles (over any animation that does not loop), and starts spitting at a target in range (but for +// the red one), facing it. static void maw_drift(Entity_NPC& npc, Vector toward) { - if (npc_anim_is_done(npc)) npc.sprite.Play("Idle"); + const AnimationData* shown = npc.sprite.animState.animData; + if (!shown || !shown->isLooping) npc.sprite.Play("Idle"); bool isReady = npc.variant != MAW_RED && npc.projectileCooldown < 1; if (isReady && npc.IsTargetInAttackRange(MAW_RANGE)) diff --git a/src/npc_mobile_host.cpp b/src/npc_mobile_host.cpp index e5d0f98..6a3474e 100644 --- a/src/npc_mobile_host.cpp +++ b/src/npc_mobile_host.cpp @@ -133,7 +133,7 @@ static void mobile_host_spit(Entity_NPC& npc) const NullFrame* poof = overlay.GetNullFrame("PoofPos"); Vector spot = poof ? poof->pos : Vector{}; - Vector at = vector_add(vector_scale(spot, 1 / MOBILE_HOST_POOF_SCALE), npc.pos); + Vector at = vector_make(spot.x / MOBILE_HOST_POOF_SCALE + npc.pos.x, spot.y / MOBILE_HOST_POOF_SCALE + npc.pos.y); Entity* blood = blood_explosion_spawn(1, at, vector_make(0, MOBILE_HOST_POOF_RAISE), COLOR_DEFAULT, {}); blood->sprite.scale = vector_make(MOBILE_HOST_POOF_SIZE, MOBILE_HOST_POOF_SIZE); blood->renderDepthOffset = MOBILE_HOST_POOF_DEPTH; diff --git a/src/npc_mole.cpp b/src/npc_mole.cpp index 688d0e4..68e0b3f 100644 --- a/src/npc_mole.cpp +++ b/src/npc_mole.cpp @@ -110,27 +110,30 @@ static void cell_mark(Room& room, int cell) if (cell >= 0 && cell < ROOM_GRID_CELLS) room.gridPaths[cell] = GRID_MARKED_PATH; } -// The poop it leaves, placed as Room::SpawnGridEntityDesc places a saved one unless the cell is taken. The poop rarely -// drops anything. +// The poop it leaves, placed as Room::SpawnGridEntityDesc places a saved one unless the cell is taken. A poop standing +// there afterwards rarely drops anything. static void dug_poop_spawn(Room& room, int cell) { if (cell < 0 || cell >= ROOM_GRID_CELLS) KAGE_LogMessage(LOG_ASSERT, (uint8_t*)"SpawnGridEntity: Grid index invalid\n"); - if (room.gridPaths[cell] > GRID_MARKED_PATH) return; - GridEntity* poop = CreateGridEntity(GRID_POOP, cell); - if (!poop) return; + GridEntity* poop = room.gridPaths[cell] <= GRID_MARKED_PATH ? CreateGridEntity(GRID_POOP, cell) : nullptr; + if (poop) + { + poop->state = (int)((Random() & 1) + 1) * POOP_HEALTH_STEP; + poop->spawnSeed = Random(); + poop->variableSeed = Random(); + delete room.gridEntities[cell]; + room.gridEntities[cell] = poop; + poop->collisionClass = COLLISION_NONE; + poop->subclass_init(); + poop->spawnCount++; + poop->isInitialized = true; + poop->spawnFrame = g_game->frameCount; + } - poop->state = (int)((Random() & 1) + 1) * POOP_HEALTH_STEP; - poop->spawnSeed = Random(); - poop->variableSeed = Random(); - delete room.gridEntities[cell]; - room.gridEntities[cell] = poop; - poop->collisionClass = COLLISION_NONE; - poop->subclass_init(); - poop->spawnCount++; - poop->isInitialized = true; - poop->spawnFrame = g_game->frameCount; - poop->varData = 1; - poop->PostInit(); + GridEntity* grid = cell < ROOM_GRID_CELLS ? room.gridEntities[cell] : nullptr; + if (!grid || grid->type != GRID_POOP) return; + grid->varData = 1; + grid->PostInit(); } // A spot to jump to on this try: its controller's way, its target 1 time in 4, or a random one 90 away. @@ -298,7 +301,7 @@ static void mole_burrow(Entity_NPC& npc, bool isDark) // controller's aim) it shoots. A controlled one not aiming jumps back under. static void mole_dig_out(Entity_NPC& npc, bool isDark) { - if (npc.controllerID != -1) npc.SpawnControlTarget(0, -1); + npc.SpawnControlTarget(0, -1); if (npc.sprite.animState.animData) { if (npc.sprite.IsEventTriggered("Shoot")) @@ -339,7 +342,7 @@ static void mole_dig_out(Entity_NPC& npc, bool isDark) // Its shots on Shoot at its target (or its controller's aim), the Tainted Mole firing up to three more volleys. static void mole_shoot(Entity_NPC& npc, bool isDark) { - if (npc.controllerID != -1) npc.SpawnControlTarget(0, -1); + npc.SpawnControlTarget(0, -1); npc.sprite.Play("Shoot"); if (npc.sprite.IsEventTriggered("Shoot")) { diff --git a/src/npc_movable_tnt.cpp b/src/npc_movable_tnt.cpp index 348109e..d7b4ff8 100644 --- a/src/npc_movable_tnt.cpp +++ b/src/npc_movable_tnt.cpp @@ -86,6 +86,7 @@ void npc_movable_tnt_update(Entity_NPC& npc) npc.flags = (npc.flags & ~FLAG_APPEAR) | FLAG_TNT_INERT; npc.state = npc.health > TNT_LAST_POINT ? NPC_STATE_IDLE : NPC_STATE_SPECIAL; if (!npc.minecart) npc.renderZOffset = TNT_DEPTH; + return; } if (npc.pendingDamage > 0) { diff --git a/src/npc_mr_maw.cpp b/src/npc_mr_maw.cpp index ccf79cb..b188601 100644 --- a/src/npc_mr_maw.cpp +++ b/src/npc_mr_maw.cpp @@ -56,10 +56,12 @@ constexpr float NECK_SAG_REACH = 100; constexpr float NECK_RISE = 31; constexpr float NECK_DROP = 5; -// A headless body carries on as a Gusher, lightened (reddened under the red head). -static void mr_maw_gusher_morph(Entity_NPC& body, int variant) +// A headless body carries on as a Gusher in the champion color of what parted it (its head, or itself), lightened +// (reddened when that is the red head). +static void mr_maw_gusher_morph(Entity_NPC& body, Entity_NPC& parter) { - body.Morph(ENTITY_GUSHER, 0, 0, body.championColorIdx); + int variant = parter.variant; + body.Morph(ENTITY_GUSHER, 0, 0, parter.championColorIdx); body.health = body.maxHitPoints; ColorMod& tint = body.sprite.GetLayer(0)->color; tint._tint[3] = 1; @@ -170,7 +172,7 @@ static void mr_maw_head_update(Entity_NPC& head) } if (!isKept && body) { - mr_maw_gusher_morph(*body, head.variant); + mr_maw_gusher_morph(*body, head); body->entityCollisionClass = ENTCOLL_ALL; } if (head.isDead && head.variant == MR_MAW_RED_HEAD) @@ -269,6 +271,6 @@ void npc_mr_maw_update(Entity_NPC& npc) if (!isBody) return; mr_maw_body_update(npc); - if (!npc.isDead && !npc.parent) mr_maw_gusher_morph(npc, npc.variant); + if (!npc.isDead && !npc.parent) mr_maw_gusher_morph(npc, npc); else if (npc.isDead && npc.parent) mr_maw_maw_morph(*npc.ParentNPC(), npc.variant != MR_MAW_BODY); } diff --git a/src/npc_mr_mine.cpp b/src/npc_mr_mine.cpp index 5839c91..0efc4f6 100644 --- a/src/npc_mr_mine.cpp +++ b/src/npc_mr_mine.cpp @@ -47,15 +47,15 @@ constexpr float MINE_DROPLET_SCALE_MIN = 1; constexpr float MINE_RING_SPEED = 8; constexpr float MINE_RING_SHOTS = 6; -// A neck segment sits along the line from the pit to the head's layer (in the 0.65 scaled sprite), its share along -// it set by its index, and fades in as the neck stretches. +// A neck segment sits along the line from the pit to the head's NeckPos null (in the 0.65 scaled sprite), its share +// along it set by its index, and fades in as the neck stretches. constexpr float NECK_SPRITE_SCALE = 0.65f; constexpr float NECK_LAST_INDEX = 7; constexpr float NECK_SHARE = 0.125f; constexpr float NECK_LIFT = 14; constexpr float NECK_DEPTH = -1000; constexpr float NECK_FADE = 0.025f; -constexpr int NECK_HEAD_LAYER = 1; +constexpr int NECK_HEAD_NULL = 1; // A splash of droplets where it breaks the water, the dive's a little bigger. static void mine_droplets_spawn(Entity_NPC& npc, bool isGrown) @@ -118,7 +118,7 @@ static void mine_neck_update(Entity_NPC& neck) Entity_NPC* mine = neck.ParentNPC(); if (!mine || mine->type != ENTITY_MR_MINE) return neck.Remove(); - const AnimationFrame* head = mine->sprite.animState.GetLayerFrame(NECK_HEAD_LAYER); + const NullFrame* head = mine->sprite.GetNullFrameById(NECK_HEAD_NULL); if (!head || !head->isVisible) { neck.pos = mine->targetPosition; diff --git a/src/npc_nerve_ending.cpp b/src/npc_nerve_ending.cpp index 2a8b5e4..4222a46 100644 --- a/src/npc_nerve_ending.cpp +++ b/src/npc_nerve_ending.cpp @@ -21,8 +21,8 @@ constexpr float NERVE_TEAR_DAMAGE = 3.5f; constexpr float NERVE_HIT_PITCH = 0.8f; // 006fefd0 The lash: everything collidable inside the box is hurt, players and familiars unless the lasher is friendly, -// enemies (with the tear effects) only when it is charmed or friendly. The box's bottom is cut at its right edge's x, -// as in the original. Deathmatch players are not told apart. +// enemies and versus players (with the tear effects) only when it is charmed or friendly. The box's bottom is cut at +// its right edge's x, as in the original. static void nerve_ending_lash(Entity_NPC& npc, Vector low, Vector high) { EntityRef source(&npc); @@ -38,9 +38,11 @@ static void nerve_ending_lash(Entity_NPC& npc, Vector low, Vector high) if (!isInside || entity->entityCollisionClass == ENTCOLL_NONE) continue; bool isPlayerSide = entity->type == ENTITY_PLAYER || entity->type == ENTITY_FAMILIAR; + bool isVersusPlayer = g_game->deathmatchManager.is_active() && entity->type == ENTITY_PLAYER; + bool isEnemy = entity->type >= ENTITY_FIRST_ENEMY && entity->type <= ENTITY_LAST_ENEMY; if (isPlayerSide && isHitPlayers) entity->TakeDamage(NERVE_DAMAGE < NERVE_PLAYER_THRESHOLD ? 1 : 2, 0, source, NERVE_DAMAGE_COUNTDOWN); - else if (entity->type >= ENTITY_FIRST_ENEMY && entity->type <= ENTITY_LAST_ENEMY && isHitEnemies) + else if ((isVersusPlayer || isEnemy) && isHitEnemies) { entity->TakeDamage(NERVE_DAMAGE, 0, source, NERVE_DAMAGE_COUNTDOWN); Entity_Tear::ApplyTearFlagEffects(entity, center, TearFlags{}, &npc, NERVE_TEAR_DAMAGE); diff --git a/src/npc_poot_mine.cpp b/src/npc_poot_mine.cpp index 845ec16..4ca041d 100644 --- a/src/npc_poot_mine.cpp +++ b/src/npc_poot_mine.cpp @@ -145,7 +145,7 @@ void npc_poot_mine_update(Entity_NPC& npc) { if (npc.controllerID != -1) { - if (input_is_action_pressed(ACTION_BOMB, npc.controllerID, &npc)) npc.Kill(EntityRef()); + if (input_is_action_pressed(ACTION_ITEM, npc.controllerID, &npc)) npc.Kill(EntityRef()); bool isSteered = !vector_is_zero(npc.GetControllerInput(POOT_STEER_DEADZONE)); if (isSteered && npc.pendingDamage <= 0 && npc.state == POOT_SITTING) npc.TakeDamage(POOT_STEER_DAMAGE, 0, EntityRef(), POOT_STEER_DAMAGE_COUNTDOWN); diff --git a/src/npc_portal.cpp b/src/npc_portal.cpp index 2039807..25ee892 100644 --- a/src/npc_portal.cpp +++ b/src/npc_portal.cpp @@ -75,7 +75,8 @@ constexpr std::array PORTAL_ENEMIES = { 55, 278, 258, 55, 10, 810, 814, 813, 817, 15, 806, 10, 810, 870, 813, 817, 872, 806}; constexpr int SWARMER_PORTAL_VARIANT = 10; -// The stage's chapter group of summons. The Void's rooms count as the chapter their layout comes from. +// The stage's chapter group of summons. The Void's rooms count as the chapter their layout comes from, the +// Basement's for a layout from none of them. static int portal_group_get() { Game& game = *g_game; @@ -84,8 +85,8 @@ static int portal_group_get() if (stage == STAGE_VOID) { int layout = game.room->GetRoomConfigStage(); - if (layout >= STAGE_ID_BASEMENT && layout <= STAGE_ID_BURNING_BASEMENT) stage = STAGE_BASEMENT_I; - else if (layout >= STAGE_ID_CAVES && layout <= STAGE_ID_FLOODED_CAVES) stage = STAGE_CAVES_I; + stage = STAGE_BASEMENT_I; + if (layout >= STAGE_ID_CAVES && layout <= STAGE_ID_FLOODED_CAVES) stage = STAGE_CAVES_I; else if (layout >= STAGE_ID_DEPTHS && layout <= STAGE_ID_DANK_DEPTHS) stage = STAGE_DEPTHS_I; else if (layout >= STAGE_ID_WOMB && layout <= STAGE_ID_SCARRED_WOMB) stage = STAGE_WOMB_I; else if (layout == STAGE_ID_CATHEDRAL || layout == STAGE_ID_SHEOL) diff --git a/src/npc_quakey.cpp b/src/npc_quakey.cpp index c04142b..cd0c7a6 100644 --- a/src/npc_quakey.cpp +++ b/src/npc_quakey.cpp @@ -52,12 +52,11 @@ constexpr float ROCK_FALL_SCALE_MIN = 0.8f; constexpr float ROCK_FALL_SCALE_RANGE = 0.4f; constexpr float ROCK_FALL_ACCELERATION = 0.95f; -// 004fd280 One step of the Quakey's rock fall: a rock dropping around the next point along its line. The timer's -// state holds the Quakey's champion color, and its first spare value the steps taken (the original reads the timer's -// own count). +// 004fd280 One step of the Quakey's rock fall: a rock dropping around the next point along its line, the steps taken +// read from the timer's count. The timer's state holds the Quakey's champion color. static void quakey_rock_fall(Entity_Effect* timer) { - float reach = (float)timer->varData[0]++ / QUAKEY_FALLS * QUAKEY_FALL_REACH; + float reach = (float)(QUAKEY_FALLS - timer_times_get(*timer)) / QUAKEY_FALLS * QUAKEY_FALL_REACH; Vector step = vector_make(reach * timer->targetPosition.x + timer->pos.x, reach * timer->targetPosition.y + timer->pos.y); Vector center = g_game->room->GetClampedPositionImpl(step, ROCK_FALL_MARGIN, ROCK_FALL_MARGIN, ROCK_FALL_MARGIN, diff --git a/src/npc_revenant.cpp b/src/npc_revenant.cpp index c4bef19..4496025 100644 --- a/src/npc_revenant.cpp +++ b/src/npc_revenant.cpp @@ -110,7 +110,7 @@ static void breath_puff(Entity_NPC& npc) .type = ENTITY_PROJECTILE, .variant = PROJECTILE_FIRE, .seed = Random()})); - shot->SetColor(color, -1, SHOT_COLOR_PRIORITY, false, false); + shot->SetColor(color, -1, SHOT_COLOR_PRIORITY, false, true); shot->fallingSpeed *= BREATH_FALL_SCALE; shot->parent = &npc; npc.fire_projectile_from_params(shot); @@ -204,7 +204,7 @@ static void head_animate(Entity_NPC& npc, RevenantHead look) if (look == HEAD_BREATHING) { int count = npc.variant == REVENANT_SPINNER ? SPINNER_BREATH_ANIMS : (int)HEAD_BREATH_ANIMS.size(); - int step = (int)std::floor((BREATH_ANIM_TOP - npc.v1.x) / BREATH_ANIM_STEP + 0.5f); + int step = (int)std::floor((BREATH_ANIM_TOP - npc.v1.x) * (1 / BREATH_ANIM_STEP) + 0.5f); int index = (step + (int)HEAD_BREATH_ANIMS.size()) % count; npc_overlay_loop(sprite, HEAD_BREATH_ANIMS[index < 0 ? index + count : index]); sprite.GetLayer(HEAD_SIDE_LAYER)->isFlipX = false; diff --git a/src/npc_rock_spider.cpp b/src/npc_rock_spider.cpp index 675379a..4c88f57 100644 --- a/src/npc_rock_spider.cpp +++ b/src/npc_rock_spider.cpp @@ -90,7 +90,7 @@ static void rock_spider_init(Entity_NPC& npc) if (!room.isInitialized || g_game->frameCount - room.enterFrame < 2) npc.ClearEntityFlags(FLAG_APPEAR); npc.state = NPC_STATE_SPECIAL; npc.sprite.Play("IdleRock"); - if (npc.type == ENTITY_FIREPLACE || npc.variant == SPIDER_THROW_COAL) npc.splatColor = ROCK_SPLAT_COLOR; + if (npc.type == ENTITY_FIREPLACE || npc.variant == SPIDER_THROW_COAL) npc.splatColor = EMBER_SPLAT_COLOR; else npc.splatColor = npc.variant == SPIDER_THROW_TINTED ? TINTED_SPIDER_SPLAT : ROCK_SPIDER_SPLAT; npc.v1.x = 0; if (npc.HasEntityFlags(FLAG_APPEAR)) diff --git a/src/npc_rotten_gaper.cpp b/src/npc_rotten_gaper.cpp index a6504c9..12789b9 100644 --- a/src/npc_rotten_gaper.cpp +++ b/src/npc_rotten_gaper.cpp @@ -167,8 +167,9 @@ static void mother_gaper_burst(Entity_NPC& npc) Vector spot = npc.GetPlayerTarget()->pos; float angle = random_unit() * MOTHER_GAPER_LOB_TURN; - float reach = random_unit() * MOTHER_GAPER_LOB_SPREAD; - Vector toSpot = vector_sub(vector_add(spot, vector_make(std::cos(angle) * reach, std::sin(angle) * reach)), npc.pos); + float reach = random_unit(); + Vector offset = vector_make(std::cos(angle) * MOTHER_GAPER_LOB_SPREAD * reach, std::sin(angle) * MOTHER_GAPER_LOB_SPREAD * reach); + Vector toSpot = vector_sub(vector_add(spot, offset), npc.pos); float distance = vector_length(toSpot); params.velocityMulti = 1; params.fallingAccelModifier = MOTHER_GAPER_LOB_FALL; @@ -179,7 +180,7 @@ static void mother_gaper_burst(Entity_NPC& npc) head->fallingAccel = HEAD_LOB_FALL_ACCEL; float time = distance / vector_length(head->velocity); - float drag = std::max((std::pow(HEAD_LOB_DRAG, time) - 1) * HEAD_LOB_DRAG_SPAN, HEAD_LOB_DRAG_FLOOR); + float drag = std::max((pow_float(HEAD_LOB_DRAG, time) - 1) * HEAD_LOB_DRAG_SPAN, HEAD_LOB_DRAG_FLOOR); head->fallingSpeed = (HEAD_LOB_LANDING - head->height - (time - drag) * HEAD_LOB_GRAVITY) / drag; } diff --git a/src/npc_skinny.cpp b/src/npc_skinny.cpp index c1337b3..d60e802 100644 --- a/src/npc_skinny.cpp +++ b/src/npc_skinny.cpp @@ -284,7 +284,7 @@ static void bony_throw(Entity_NPC& npc) if (!vector_is_zero(vector_sub(aim, npc.pos))) distance = std::clamp(vector_length(vector_sub(npc.pos, aim)), BONY_ARC_MIN, BONY_ARC_MAX); float frames = distance / BONY_ARC_STEP; - float reach = std::max((std::pow(BONY_ARC_DECAY, frames) - 1) * BONY_ARC_SCALE, BONY_ARC_FLOOR); + float reach = std::max((pow_float(BONY_ARC_DECAY, frames) - 1) * BONY_ARC_SCALE, BONY_ARC_FLOOR); params.bulletFlags = PROJECTILE_BLUE_FIRE_SPAWN; params.fallingAccelModifier = 1; params.fallingSpeedModifier = (random_unit() * BONY_ARC_JITTER + BONY_ARC_JITTER_MIN) * diff --git a/src/npc_small_leech.cpp b/src/npc_small_leech.cpp index 8c1d44b..785fbd7 100644 --- a/src/npc_small_leech.cpp +++ b/src/npc_small_leech.cpp @@ -31,6 +31,8 @@ constexpr float LEECH_ORBIT_SLACK = 30; constexpr float LEECH_TURN_MIN = 4; constexpr float LEECH_ORBIT_PULL = 20; constexpr float LEECH_ORBIT_FRICTION = 0.85f; +// The share of its old velocity it keeps circling, a hair over its top speed in the original. +constexpr float LEECH_ORBIT_KEEP = 0.35000002f; constexpr int LEECH_CONFUSION_SCALE = 1023; constexpr int LEECH_CONFUSION_DIVISOR = 4; @@ -162,9 +164,7 @@ static void leech_orbit(Entity_NPC& npc, Entity& parent) Vector spot = vector_add(parent.pos, vector_scale(vector_from_angle(npc.v2.x), npc.v1.y)); Vector pull = vector_sub(spot, npc.pos); if (vector_length(pull) > LEECH_ORBIT_PULL) pull = vector_resized(pull, LEECH_ORBIT_PULL); - float keep = LEECH_SWIM_SPEED; - float speed = npc.speedMultiplier; - if (speed != 1) keep = LEECH_SWIM_SPEED / ((speed + LEECH_SWIM_SPEED) - speed * LEECH_SWIM_SPEED); + float keep = timescale_factor(LEECH_ORBIT_KEEP, npc.speedMultiplier); npc.velocity = vector_add(npc.velocity, vector_scale(vector_sub(vector_add(pull, parent.velocity), npc.velocity), 1 - keep)); npc.friction *= LEECH_ORBIT_FRICTION; diff --git a/src/npc_stonehead.cpp b/src/npc_stonehead.cpp index c17dd6c..aaeef4d 100644 --- a/src/npc_stonehead.cpp +++ b/src/npc_stonehead.cpp @@ -59,7 +59,7 @@ constexpr float VOMIT_FALL_ACCEL = 0.92f; // A controlled vomiting grimace lobs its blob to land on its aim target: the frames the flight takes at 10 times its // speed share, the drag those frames add up to (at least 0.01), and the fall from 5 up clamped between -38 and -5. constexpr float VOMIT_LOB_STEP = 10; -constexpr double VOMIT_LOB_DECAY = 0.9; +constexpr float VOMIT_LOB_DECAY = 0.9f; constexpr float VOMIT_LOB_SPAN = -9.491221f; constexpr float VOMIT_LOB_FLOOR = 0.01f; constexpr float VOMIT_LOB_LIFT = 5; @@ -238,7 +238,7 @@ static void grimace_shoot(Entity_NPC& npc) if (npc.controllerID != -1) { float frames = vector_length(vector_sub(npc.pos, npc.GetAimTargetPosition())) / (params.velocityMulti * VOMIT_LOB_STEP); - float drag = std::max(((float)std::pow(VOMIT_LOB_DECAY, (double)frames) - 1) * VOMIT_LOB_SPAN, VOMIT_LOB_FLOOR); + float drag = std::max((pow_float(VOMIT_LOB_DECAY, frames) - 1) * VOMIT_LOB_SPAN, VOMIT_LOB_FLOOR); float fall = (VOMIT_LOB_LIFT - (frames - drag) * VOMIT_LOB_GRAVITY) / drag; params.fallingSpeedModifier = std::min(std::max(fall, VOMIT_LOB_FASTEST), VOMIT_LOB_SLOWEST); } diff --git a/src/npc_swarm_spider.cpp b/src/npc_swarm_spider.cpp index 5aa9855..ff34357 100644 --- a/src/npc_swarm_spider.cpp +++ b/src/npc_swarm_spider.cpp @@ -123,7 +123,8 @@ static void hop_pick(Entity_NPC& npc, bool isSackActive) npc.state = SWARM_SPIDER_HOP; } -// Hopping: it leaps at its jump event (flying over things until it lands) and rests once the hop ends, now and then. +// Hopping: it leaps at its jump event (flying over things until it lands) and rests once the hop ends, or now and +// then once it landed. static void hop_update(Entity_NPC& npc) { if (!npc.HasEntityFlags(FLAG_NO_PHYSICS_KNOCKBACK)) npc.friction *= SWARM_SPIDER_FRICTION; @@ -138,7 +139,9 @@ static void hop_update(Entity_NPC& npc) } else if (npc.sprite.animState.animData && npc.sprite.IsEventTriggered("Land")) npc.flags &= ~FLAG_NO_PHYSICS_KNOCKBACK; - if (!npc_anim_is_done(npc) || (Random() & (SWARM_SPIDER_REST_ODDS - 1)) != 0) return; + bool isPlaying = npc.sprite.animState.animData && npc.sprite.animState.isPlaying; + if (isPlaying && (!npc.sprite.animState.WasEventTriggered("Land") || (Random() & (SWARM_SPIDER_REST_ODDS - 1)) != 0)) + return; } npc_anim_loop(npc.sprite, "Idle"); npc.state = NPC_STATE_IDLE; diff --git a/src/npc_swarmer.cpp b/src/npc_swarmer.cpp index 0a5d13d..d58632f 100644 --- a/src/npc_swarmer.cpp +++ b/src/npc_swarmer.cpp @@ -192,20 +192,6 @@ static void swarmer_spit(Entity_NPC& npc, Vector aim) } } -// One shot as FireProjectiles fires it alone, kept to be sent into orbit. -static Entity_Projectile* planetoid_shot_fire(Entity_NPC& npc, Vector velocity, const ProjectileParams& params) -{ - auto* shot = static_cast(g_game->Spawn({.position = vector_add(npc.pos, params.positionOffset), - .velocity = velocity, - .spawner = &npc, - .type = ENTITY_PROJECTILE, - .variant = params.variant, - .seed = Random()})); - npc.projectile_params_apply(*shot, params); - npc.fire_projectile_from_params(shot); - return shot; -} - // The Planetoid's shot: one or two more shots sent into orbit, or with its Blow the whole orbit flung out in a fart. static void planetoid_shoot(Entity_NPC& npc) { @@ -238,7 +224,8 @@ static void planetoid_shoot(Entity_NPC& npc) params.targetPosition = npc.pos; for (int i = 0; i < count; i++, angle += step) { - Entity_Projectile* shot = planetoid_shot_fire(npc, vector_scale(vector_from_angle(angle), PLANETOID_SHOT_SPEED), params); + Vector velocity = vector_scale(vector_from_angle(angle), PLANETOID_SHOT_SPEED); + Entity_Projectile* shot = npc.fire_projectiles(npc.pos, velocity, PROJECTILES_SINGLE, params); shot->orbitDistance = PLANETOID_ORBIT; shot->fallingSpeed = 0; shot->fallingAccel = PLANETOID_ORBIT_FALL; diff --git a/src/npc_swinger.cpp b/src/npc_swinger.cpp index a6357c1..1ad6d7b 100644 --- a/src/npc_swinger.cpp +++ b/src/npc_swinger.cpp @@ -86,8 +86,8 @@ static void swinger_body_update(Entity_NPC& npc) static void swinger_head_update(Entity_NPC& npc) { Entity* body = npc.parent; - npc.friction = SWINGER_FRICTION; if (!body) return swinger_part_kill(npc, ENTITY_MAW); + npc.friction = SWINGER_FRICTION; float reach = std::min(npc.speedMultiplier * SWINGER_REACH / SWINGER_PAYOUT_FRAMES + npc.v2.y, SWINGER_REACH); npc.v2.y = reach; diff --git a/src/npc_tarboy.cpp b/src/npc_tarboy.cpp index 245d5ab..3af36e5 100644 --- a/src/npc_tarboy.cpp +++ b/src/npc_tarboy.cpp @@ -339,16 +339,15 @@ static void tarboy_bite(Entity_NPC& npc) tarboy_rest(npc, TARBOY_SPIT_REST_MIN); } -// Its creep where it stands, every eighth frame (not mid sink). +// Its creep where it stands, every eighth frame (not mid sink). A friendly one's turns to player creep on spawning. static void tarboy_creep_leave(Entity_NPC& npc) { if (npc.HasEntityFlags(FLAG_INTERPOLATION_UPDATE) || g_game->IsPaused()) return; if ((g_game->frameCount + (int)npc.index) % CREEP_EVERY != 0) return; if (npc.controllerID == -1 && npc.state == NPC_STATE_MOVE) return; - int variant = npc.HasEntityFlags(FLAG_FRIENDLY) ? EFFECT_PLAYER_CREEP_BLACK : EFFECT_CREEP_BLACK; - auto* creep = static_cast( - g_game->Spawn({.position = npc.targetPosition, .spawner = &npc, .type = ENTITY_EFFECT, .variant = variant, .seed = Random()})); + auto* creep = static_cast(g_game->Spawn( + {.position = npc.targetPosition, .spawner = &npc, .type = ENTITY_EFFECT, .variant = EFFECT_CREEP_BLACK, .seed = Random()})); creep->timeout = TARBOY_CREEP_FRAMES; creep->lifespan = TARBOY_CREEP_FRAMES; creep->sprite.scale = vector_make(TARBOY_CREEP_SCALE, TARBOY_CREEP_SCALE); diff --git a/src/npc_ultra_coin.cpp b/src/npc_ultra_coin.cpp index 637898b..13dad26 100644 --- a/src/npc_ultra_coin.cpp +++ b/src/npc_ultra_coin.cpp @@ -61,13 +61,13 @@ constexpr float CRUMBLE_PITCH_RANGE = 0.3f; constexpr int CRUMBLE_SOUND_DELAY = 30; // Ultra Greed's heal (UltraGreed_Heal): an eighth of a percent of its health per point, its heal count capped at 25, -// and a green flash. +// and a golden flash. constexpr int GREED_HEAL_CAP = 25; constexpr float GREED_HEAL_SHARE = 0.00125f; constexpr float GREED_HEAL_FLASH_POINTS = 3; constexpr int GREED_HEAL_FLASH_FRAMES = 4; constexpr int GREED_HEAL_FLASH_MAX = 15; -constexpr float GREED_HEAL_GREEN = 0.84f; +constexpr float GREED_HEAL_FLASH_GREEN = 0.84f; // Whether Ultra Greed's coins are tougher: Everything Is Terrible 2 is unlocked, or a daily or debug run is on. static bool ultra_coin_is_tough() @@ -77,13 +77,13 @@ static bool ultra_coin_is_tough() return g_game->dailyChallenge.id != 0 || g_game->isDebug; } -// 0059e2a0 NpcHelper::UltraGreed_Heal: Ultra Greed heals a share of its health and flashes green. +// 0059e2a0 NpcHelper::UltraGreed_Heal: Ultra Greed heals a share of its health and flashes gold. void ultra_greed_heal(Entity_NPC& greed, int amount) { greed.i2 = std::min(greed.i2 + amount, GREED_HEAL_CAP); greed.health = std::min(greed.maxHitPoints * GREED_HEAL_SHARE * (float)amount + greed.health, greed.maxHitPoints); float flash = std::min((float)amount / GREED_HEAL_FLASH_POINTS, 1.0f); - ColorMod color = {{1, 1, 1, 1}, {0, 0, 0, 0}, {0, flash * GREED_HEAL_GREEN, flash * 0}}; + ColorMod color = {{1, 1, 1, 1}, {0, 0, 0, 0}, {flash, flash * GREED_HEAL_FLASH_GREEN, flash * 0}}; greed.SetColor(color, std::min(amount * GREED_HEAL_FLASH_FRAMES, GREED_HEAL_FLASH_MAX), COLOR_PRIORITY_DEFAULT, true, true); } diff --git a/src/npc_willo_l2.cpp b/src/npc_willo_l2.cpp index bcb7a5f..55548a5 100644 --- a/src/npc_willo_l2.cpp +++ b/src/npc_willo_l2.cpp @@ -125,8 +125,9 @@ static void willo_l2_space(Entity_NPC& npc) Vector away = vector_sub(npc.pos, other->pos); float distance = vector_length(away); if (distance <= 0) continue; - float push = WILLO_L2_SPACING * npc.speedMultiplier / (distance * WILLO_L2_SPACING_SOFTEN + WILLO_L2_SPACING); - npc.velocity = vector_add(npc.velocity, vector_scale(away, push / distance)); + float soften = distance * WILLO_L2_SPACING_SOFTEN + WILLO_L2_SPACING; + npc.velocity.x += away.x / distance / soften * WILLO_L2_SPACING * npc.speedMultiplier; + npc.velocity.y += away.y / distance / soften * WILLO_L2_SPACING * npc.speedMultiplier; } } diff --git a/src/npc_wrinkly_baby.cpp b/src/npc_wrinkly_baby.cpp index a046f99..8420282 100644 --- a/src/npc_wrinkly_baby.cpp +++ b/src/npc_wrinkly_baby.cpp @@ -4,7 +4,7 @@ #include "menu_manager.h" #include "npc_basement.h" -// The Wrinkly Baby's states: drifting, the dash along a line at its target, and the double shot. +// The Wrinkly Baby's states: drifting, the dash along a line at its target, and the triple shot. constexpr int WRINKLY_DASH = NPC_STATE_STOMP; constexpr int WRINKLY_SHOOT = NPC_STATE_ATTACK; @@ -45,7 +45,7 @@ static void wrinkly_rest(Entity_NPC& npc, int rest) npc.state = NPC_STATE_MOVE; } -// Starts the double shot from its fourth frame. +// Starts the triple shot from its fourth frame. static void wrinkly_shoot_start(Entity_NPC& npc) { npc.sprite.Play("Attack"); @@ -149,7 +149,7 @@ static void wrinkly_dash(Entity_NPC& npc) wrinkly_rest(npc, WRINKLY_CONTROLLED_REST); } -// The double shot on its Shoot event at its target (controlled, along its input), then a rest. +// The triple shot on its Shoot event at its target (controlled, along its input), then a rest. static void wrinkly_shoot(Entity_NPC& npc) { npc.friction *= WRINKLY_FRICTION; @@ -169,7 +169,7 @@ static void wrinkly_shoot(Entity_NPC& npc) params.spread = WRINKLY_SHOT_SPREAD; float speed = game_is_hard_mode() ? WRINKLY_SHOT_SPEED_HARD : WRINKLY_SHOT_SPEED; npc.FireProjectiles(vector_add(npc.pos, vector_scale(aim, WRINKLY_SHOT_OFFSET)), vector_scale(aim, speed), - PROJECTILES_TWO, params); + PROJECTILES_THREE, params); } if (npc.sprite.animState.animData && npc.sprite.animState.isPlaying) return; } @@ -180,7 +180,7 @@ static void wrinkly_shoot(Entity_NPC& npc) wrinkly_rest(npc, rest); } -// 0054fa80 The Wrinkly Baby (38.3): drifts at a distance from its target, dashes in along a line and fires a double +// 0054fa80 The Wrinkly Baby (38.3): drifts at a distance from its target, dashes in along a line and fires a triple // shot. A controlled one shows its aim mark while aiming. void npc_wrinkly_baby_update(Entity_NPC& npc) { diff --git a/src/player_hud.cpp b/src/player_hud.cpp index 3443b7c..5fe48c4 100644 --- a/src/player_hud.cpp +++ b/src/player_hud.cpp @@ -105,7 +105,6 @@ constexpr uint8_t MANTLE_STACKS_MASK = 0xf; constexpr float MANTLE_SECOND_X = 6; constexpr float MANTLE_SECOND_RISE = 4; constexpr float MANTLE_SECOND_ALPHA = 0.5f; -constexpr int NULL_ITEM_HOLY_CARD = 46; // The extra lives text: its gap from the hearts, its rise, and the shift beside a shield or in the compact layout. constexpr float LIVES_GAP = 10; @@ -848,7 +847,7 @@ void PlayerHUD::RenderHearts(Vector& outExtent, ANM2& sprite, PlayerHudLayout la if (effects.HasCollectibleEffect(COLLECTIBLE_BLANKET)) shields[shieldCount++] = MANTLE_BLANKET; if (shown.HasCollectible(COLLECTIBLE_HOLY_MANTLE) && shown.holyMantleState == 0) shields[shieldCount++] = MANTLE_HOLY_MANTLE; - if (effects.HasNullEffect(NULL_ITEM_HOLY_CARD)) shields[shieldCount++] = MANTLE_HOLY_CARD; + if (effects.HasNullEffect(NULLITEM_HOLY_CARD)) shields[shieldCount++] = MANTLE_HOLY_CARD; for (; shieldCount < mantle->count && shieldCount < MANTLE_LIMIT; shieldCount++) shields[shieldCount] = MANTLE_HOLY_MANTLE; diff --git a/src/player_manager.cpp b/src/player_manager.cpp index 31c30bd..bc3f088 100644 --- a/src/player_manager.cpp +++ b/src/player_manager.cpp @@ -437,15 +437,14 @@ Entity_Player* PlayerManager::FirstCollectibleOwner(int collectibleId, LazarusSh return nullptr; } -// 009be6b0 The first player whose trinket multiplier for a trinket is positive, or one of them holding Mom's Box. -// The original's override at player+0x2ef8 is only ever written by the constructor, so it is gone. +// 009be6b0 The first player who has a trinket, or one of them holding Mom's Box. Entity_Player* PlayerManager::FirstTrinketOwner(int trinketId) { Entity_Player* firstOwner = nullptr; for (Entity_Player* player : playerList) { - if (player->GetTrinketMultiplier(trinketId) <= 0) continue; + if (!player->HasTrinket(trinketId)) continue; if (player->HasCollectible(COLLECTIBLE_MOMS_BOX)) return player; if (!firstOwner) firstOwner = player; } diff --git a/src/rng.cpp b/src/rng.cpp index 4218f46..fbd36c8 100644 --- a/src/rng.cpp +++ b/src/rng.cpp @@ -1,5 +1,6 @@ #include "classes.h" #include "log.h" +#include "seeds.h" // The xorshift triples a seed is paired with, by shift index. constexpr unsigned int SHIFT_COUNT = 81; @@ -19,8 +20,6 @@ constexpr unsigned int SHIFTS[SHIFT_COUNT][3] = { {13, 3, 27}, {13, 5, 19}, {13, 17, 15}, {14, 1, 15}, {14, 13, 15}, {15, 1, 29}, {17, 15, 20}, {17, 15, 23}, {17, 15, 26}, }; -// Just under 1 / 2^32, so a float drawn from any seed stays below 1. -constexpr float FLOAT_SCALE = 2.3283062e-10f; // 007e8fe0 Seeds the generator, clamping the shift index to the last triple. void RNG::SetSeed(uint32_t seed, uint32_t shiftIndex) @@ -62,7 +61,7 @@ uint32_t RNG::RandomInt(uint32_t max) // 007e9080 A number in [0, 1). float RNG::RandomFloat() { - return (float)Next() * FLOAT_SCALE; + return (float)Next() * RNG_FLOAT_SCALE; } // 005cc070 Shuffles [begin, end) in place, from the back, each element swapped with one at or before it. diff --git a/src/room.cpp b/src/room.cpp index 2a0d311..04a3bc6 100644 --- a/src/room.cpp +++ b/src/room.cpp @@ -191,8 +191,6 @@ constexpr int SOUND_ANGEL_DOOR_APPEAR = 23; constexpr int SOUND_DEVIL_DOOR_APPEAR = 320; constexpr int GREED_DEAL_DOOR_SLOT = 4; constexpr float MOM_DOOR_CLEARANCE = 50; -constexpr uint64_t GAME_STATE_ANGEL_DOOR_BITS = 1ull << 0; -constexpr uint64_t GAME_STATE_DEVILROOM_SPAWNED_BITS = 1ull << 5; // The dust a door throws as it appears: how many puffs at least, how fast and far, how they spin and how long they // last. @@ -3201,8 +3199,8 @@ bool Room::TrySpawnDevilRoomDoor(bool isAnimate, bool isForce) if (slot < 0) return false; int type = devilRoom.data->type; - if (type == ROOM_DEVIL) game.gameStateFlags |= GAME_STATE_DEVILROOM_SPAWNED_BITS; - else if (type == ROOM_ANGEL) game.gameStateFlags |= GAME_STATE_ANGEL_DOOR_BITS; + if (type == ROOM_DEVIL) game.gameStateFlags |= 1ull << GAME_STATE_DEVILROOM_SPAWNED; + else if (type == ROOM_ANGEL) game.gameStateFlags |= 1ull << GAME_STATE_FAMINE_SPAWNED; if (!doors[slot]) MakeDoor(slot); doors[slot]->SetRoomTypes(ROOM_DEFAULT, type); diff --git a/src/room_clear.cpp b/src/room_clear.cpp index 597bac6..723f1f5 100644 --- a/src/room_clear.cpp +++ b/src/room_clear.cpp @@ -38,7 +38,6 @@ constexpr int COLLECTIBLE_LITTLE_CHAD = 96; constexpr int COLLECTIBLE_LITTLE_GISH = 99; constexpr int COLLECTIBLE_STEVEN = 50; constexpr int TRINKET_ISAACS_FORK = 46; -constexpr int TRINKET_DINGLE_BERRY = 163; constexpr int TRINKET_POLISHED_BONE = 167; constexpr int TRINKET_CRYSTAL_KEY = 170; constexpr int TRINKET_TEMPORARY_TATTOO = 177; @@ -57,7 +56,6 @@ constexpr float OPTIONS_SPREAD = 15; // Ultra Greed's donation machine drops this far from the player, kept this far off the column below him. constexpr float GREED_MACHINE_REACH = 80; constexpr float GREED_MACHINE_CLEAR = 20; -constexpr int BOSS_MEGA_SATAN_ID = 55; // Mom's first kill unlocks the Womb, the Harbingers, A Cube of Meat and the Item Info, and the Void past the Dark // Room is open once unlocked. Her items are the Polaroid and the Negative, 80 below the room's center. @@ -460,6 +458,7 @@ struct ClearAward Vector reward{}; float itemRow = 0; int count = 1; + int shopItemId = -1; int trapdoorIndex = -1; int subType = 0; int variant = PICKUP_NULL; @@ -476,7 +475,7 @@ static void award_count_roll(Room& room, ClearAward& award) { award.count = players.GetNumCollectibles(COLLECTIBLE_CONTRACT_FROM_BELOW) + 1; float roll = award.rng.RandomFloat(); - if (roll < std::pow(CONTRACT_FAIL_BASE, (float)(award.count - 1)) * CONTRACT_FAIL_SCALE) award.count = 0; + if (roll < pow_float(CONTRACT_FAIL_BASE, (float)(award.count - 1)) * CONTRACT_FAIL_SCALE) award.count = 0; } if (g_game->difficulty == DIFFICULTY_HARD && award.variant == PICKUP_HEART && award.rng.RandomInt(100) >= (uint32_t)HARD_HEART_PERCENT) @@ -878,7 +877,7 @@ static void moms_items_spawn(Room& room, ClearAward& award) .type = ENTITY_PICKUP, .variant = PICKUP_COLLECTIBLE, .seed = award.rng.Next()})); - if (award.isShopItems) pickup->MakeShopItem(-2); + if (award.isShopItems) pickup->MakeShopItem(award.shopItemId); pickup->coopDuplicateIndex = 0; } } @@ -1042,9 +1041,10 @@ static Vector final_chest_spawn(Room& room, ClearAward& award, bool isContinuing return spot; } -// The secret exit's bosses: Mom in the Mausoleum or Gehenna marks Mom's Heart, Mother her own mark and her chest (or -// trophy), and after her first kill a Void portal below it on a run that may reach the Void. -static void secret_exit_award_spawn(Room& room, ClearAward& award, int stage, bool isContinuing) +// The secret exit's bosses: Mom in the Mausoleum or Gehenna marks Mom's Heart, Mother her own mark and her chest (a +// trophy in any challenge with a path, even one going on), and after her first kill a Void portal below it on a run +// that may reach the Void. +static void secret_exit_award_spawn(Room& room, ClearAward& award, int stage) { constexpr float MOTHER_PORTAL_DROP = 40; constexpr float MOTHER_PORTAL_SPREAD = 80; @@ -1058,10 +1058,11 @@ static void secret_exit_award_spawn(Room& room, ClearAward& award, int stage, bo } if (stage != STAGE_WOMB_II) return; + bool isChallenge = g_game->GetChallengeParams().isPathTypeSet; PlayerManager::unlock_completion_mark(COMPLETION_MOTHER); data.IncreaseEventCounter(EVENT_COUNTER_MOTHER_KILLS, 1); - Vector spot = final_chest_spawn(room, award, isContinuing); - if (!isContinuing || !is_void_reachable() || data.eventCounters[EVENT_COUNTER_MOTHER_KILLS] <= 1) return; + Vector spot = final_chest_spawn(room, award, !isChallenge); + if (isChallenge || !is_void_reachable() || data.eventCounters[EVENT_COUNTER_MOTHER_KILLS] <= 1) return; Vector below = vector_make(spot.x, spot.y + MOTHER_PORTAL_DROP); int gridIndex = room.GetGridIndex(room_free_pickup_position_find( @@ -1070,11 +1071,20 @@ static void secret_exit_award_spawn(Room& room, ClearAward& award, int stage, bo room.SpawnGridEntity(gridIndex, GRID_TRAPDOOR, 0, Random(), TRAPDOOR_VOID_PORTAL); } +// Whether this run may not unlock achievements: a custom seed, a seed or mod that blocks them, or a rerun (the inlined +// Game::AchievementUnlocksDisallowed). +static bool is_run_unlock_blocked() +{ + Game& game = *g_game; + return game.seedEffects.isCustomRun || game.seedEffects.AchievementUnlocksDisallowed() || + Manager::AchievementUnlocksDisallowed() || game.isRerun; +} + // Opens the save for a victory lap's unlock (unless achievements are off this run), then closes it again. static void victory_lap_unlock(int achievement) { PersistentGameData& data = g_manager->persistentGameData; - data.SetReadOnly(Manager::AchievementUnlocksDisallowed()); + data.SetReadOnly(is_run_unlock_blocked()); data.TryUnlock(achievement); data.SetReadOnly(true); } @@ -1200,7 +1210,7 @@ static void mega_satan_award_spawn(Room& room, ClearAward& award, bool isContinu { Game& game = *g_game; g_manager->persistentGameData.IncreaseEventCounter(EVENT_COUNTER_MEGA_SATAN_KILLS, 1); - g_manager->persistentGameData.AddBoss(BOSS_MEGA_SATAN_ID); + g_manager->persistentGameData.AddBoss(BOSS_MEGA_SATAN); PlayerManager::unlock_completion_mark(COMPLETION_MEGA_SATAN); if (game.GetChallengeParams().isMegaSatan) return (void)final_chest_spawn(room, award, false); if (!isContinuing || !is_void_reachable()) return game_end(ENDING_MEGA_SATAN); @@ -1280,17 +1290,17 @@ static void boss_award_spawn(Room& room, ClearAward& award) bool isMomsFloor = (stage == STAGE_WOMB_II || stage == STAGE_DEPTHS_II) && !isLastBoss; bool isBossRush = room.roomType == ROOM_BOSSRUSH || (game.challenge == CHALLENGE_RED_REDEMPTION && stage < STAGE_WOMB_II); - if (isSecretExitBoss) secret_exit_award_spawn(room, award, stage, isContinuing); + if (isSecretExitBoss) secret_exit_award_spawn(room, award, stage); else if (isPlainFloor || isBossRush) { if (isLastBoss) boss_exit_spawn(room, award, stage, isContinuing); boss_items_spawn(room, award); } else if (isMomsFloor) boss_items_spawn(room, award); - else if (stage == STAGE_DEPTHS_II && room.bossId != BOSS_MEGA_SATAN_ID) moms_award_spawn(room, award, isContinuing); - else if ((stage == STAGE_WOMB_II || stage == STAGE_BLUE_WOMB) && room.bossId != BOSS_MEGA_SATAN_ID) + else if (stage == STAGE_DEPTHS_II && room.bossId != BOSS_MEGA_SATAN) moms_award_spawn(room, award, isContinuing); + else if ((stage == STAGE_WOMB_II || stage == STAGE_BLUE_WOMB) && room.bossId != BOSS_MEGA_SATAN) womb_award_spawn(room, award, stage, isContinuing); - else if (room.bossId == BOSS_MEGA_SATAN_ID) mega_satan_award_spawn(room, award, isContinuing); + else if (room.bossId == BOSS_MEGA_SATAN) mega_satan_award_spawn(room, award, isContinuing); else if (stage == STAGE_SHEOL) sheol_award_spawn(room, award, isContinuing); else if (stage == STAGE_DARK_ROOM) dark_room_award_spawn(room, award, isContinuing); else if (stage == STAGE_VOID) void_award_spawn(room, award, isContinuing); @@ -1384,7 +1394,10 @@ void room_clear_award_spawn(Room& room) bool isBibleDeal = (game.levelStateFlags & (1u << LEVEL_STATE_SATANIC_BIBLE_USED)) && room.roomType == ROOM_BOSS; award.isShopItems = game.playerManager.FirstPlayerByType(PLAYER_KEEPER_B) || isBibleDeal; if (!game.playerManager.FirstPlayerByType(PLAYER_KEEPER_B) && isBibleDeal) + { award.itemRow = award.reward.y + AWARD_ITEM_DROP_DEAL; + award.shopItemId = -2; + } RoomConfig_Room* data = room.descriptor->data; bool isNormal = room.roomType != ROOM_BOSS && room.roomType != ROOM_BOSSRUSH; @@ -1411,9 +1424,7 @@ void room_clear_award_spawn(Room& room) static void shovel_quest_check(Room& room) { Game& game = *g_game; - bool isUnlocking = (!game.seedEffects.isCustomRun && !game.seedEffects.AchievementUnlocksDisallowed() && - !Manager::AchievementUnlocksDisallowed() && !game.isRerun) || - g_manager->netplayManager.is_online(); + bool isUnlocking = !is_run_unlock_blocked() || g_manager->netplayManager.is_online(); bool isQuestBoss = isUnlocking && g_manager->persistentGameData.eventCounters[EVENT_COUNTER_LAMB_KILLS] != 0 && !(game.levelStateFlags & (1u << LEVEL_STATE_SHOVEL_QUEST_TRIGGERED)) && Room::IsCurrentRoomLastBoss() && game.stage == 1 && diff --git a/src/room_grid.cpp b/src/room_grid.cpp index 1581d95..2094844 100644 --- a/src/room_grid.cpp +++ b/src/room_grid.cpp @@ -244,8 +244,10 @@ Vector room_free_pickup_position_find(const FreeSpotSearch& search) if (!door) continue; Vector doorCenter = room.GetGridPosition(door->gridIndex); - if (vector_length(vector_sub(doorCenter, spot)) >= DOOR_DISTANCE) continue; - for (int retry = 0; retry < DOOR_RETRIES && vector_length(vector_sub(doorCenter, spot)) < DOOR_DISTANCE; retry++) + if (vector_length_squared(vector_sub(doorCenter, spot)) >= DOOR_DISTANCE * DOOR_DISTANCE) continue; + for (int retry = 0; + retry < DOOR_RETRIES && vector_length_squared(vector_sub(doorCenter, spot)) < DOOR_DISTANCE * DOOR_DISTANCE; + retry++) spot = room_free_pickup_position_find({.position = spot, .step = DOOR_RETRY_STEP}); return spot; } diff --git a/src/room_lighting.cpp b/src/room_lighting.cpp index 589e1e1..031b69b 100644 --- a/src/room_lighting.cpp +++ b/src/room_lighting.cpp @@ -167,7 +167,7 @@ Vector RandomVector(uint32_t seed) seed ^= seed >> 3; seed ^= seed << 1; seed ^= seed >> 14; - float angle = (float)seed * RANDOM_UNIT_SCALE * PI_ROUGH; + float angle = (float)seed * RNG_FLOAT_SCALE * PI_ROUGH; angle += angle; return vector_make(std::cos(angle), std::sin(angle)); } @@ -293,10 +293,10 @@ static void player_light_render(Room& room, Entity_Player& player, Vector offset ItemConfig& items = g_manager->itemConfig; Vector position = vector_add(render_position_get(vector_add(player.pos, player.posOffset), RENDER_SNAPPED), offset); TemporaryEffect* aura = - player.temporaryEffects.isDisabled ? nullptr : player.temporaryEffects.GetNullEffect(NULL_EFFECT_SPIRIT_AURA); + player.temporaryEffects.isDisabled ? nullptr : player.temporaryEffects.GetNullEffect(NULLITEM_LUNA); float stacks = std::min(aura ? (float)aura->count : 0.0f, AURA_STACK_MAX); - if (player.temporaryEffects.HasNullEffect(NULL_EFFECT_SPIRIT_AURA)) + if (player.temporaryEffects.HasNullEffect(NULLITEM_LUNA)) { layer_blend_set(light, KAGE::Graphics::BLEND_ADDITIVE); light.color = LIGHT_AURA; @@ -313,7 +313,7 @@ static void player_light_render(Room& room, Entity_Player& player, Vector offset return player.IsItemCostumeVisible(items.GetCollectible(collectible), -1); }; bool isFlame = player.IsItemCostumeVisible(items.GetCollectible(COLLECTIBLE_FIRE_MIND_COSTUME), 0) || - isCostume(COLLECTIBLE_FIRE_MIND) || player.IsNullItemCostumeVisible(NULL_ITEM_BRIMSTONE_FLAME, 0); + isCostume(COLLECTIBLE_FIRE_MIND) || player.IsNullItemCostumeVisible(NULLITEM_SOL, 0); bool isGhostly = isCostume(COLLECTIBLE_SPIRIT_OF_THE_NIGHT) || isCostume(COLLECTIBLE_TELEPATHY_BOOK) || isCostume(COLLECTIBLE_EYE_OF_THE_OCCULT); if (isFlame || isGhostly) diff --git a/src/room_render.cpp b/src/room_render.cpp index 130c070..9e59cba 100644 --- a/src/room_render.cpp +++ b/src/room_render.cpp @@ -1208,9 +1208,9 @@ static void entity_glow_render(Room& room, Entity& entity, Vector offset) if (entity.type != ENTITY_PLAYER) return; Entity_Player& player = static_cast(entity); - if (player.temporaryEffects.HasNullEffect(NULL_EFFECT_SPIRIT_AURA)) + if (player.temporaryEffects.HasNullEffect(NULLITEM_LUNA)) { - float stacks = std::min((float)player.temporaryEffects.GetNullEffectNum(NULL_EFFECT_SPIRIT_AURA), GLOW_STACK_MAX); + float stacks = std::min((float)player.temporaryEffects.GetNullEffectNum(NULLITEM_LUNA), GLOW_STACK_MAX); ColorMod color = GLOW_COLOR; color._tint[3] = stacks * GLOW_ALPHA_STEP + GLOW_ALPHA; layer_blend_set(light, KAGE::Graphics::BLEND_ADDITIVE); @@ -1227,7 +1227,7 @@ static void entity_glow_render(Room& room, Entity& entity, Vector offset) ItemConfig& items = g_manager->itemConfig; bool isFireMind = player.IsItemCostumeVisible(items.GetCollectible(COLLECTIBLE_FIRE_MIND_COSTUME), 0) || player.HasCollectible(COLLECTIBLE_FIRE_MIND); - if (!isFireMind && !player.IsItemCostumeVisible(items.GetNullItem(NULL_ITEM_BRIMSTONE_FLAME), 0)) return; + if (!isFireMind && !player.IsItemCostumeVisible(items.GetNullItem(NULLITEM_SOL), 0)) return; Vector direction = RandomVector(rng.Next()); float distance = rng.RandomFloat() * FLAME_FLICKER; @@ -1416,7 +1416,7 @@ static void shockwave_surface_resolve(Room& room, Vector surfaceOffset) bool isRunning = wave.frame < wave.duration; Vector at = isRunning ? surface_texcoord_get(room, wave.position, surface) : vector_make(SHOCKWAVE_IDLE_X, 0); float time = room.isUnknown7220 ? wave.time + wave.speed * 0.5f : wave.time; - float fade = std::pow((float)wave.frame / (float)wave.duration, SHOCKWAVE_FADE_POWER); + float fade = pow_float((float)wave.frame / (float)wave.duration, SHOCKWAVE_FADE_POWER); waves[i] = {at.x, at.y, time, (1 - fade) * wave.amplitude}; } float pointsWide = g_screenPointScale * SHOCKWAVE_SCREEN_WIDTH; diff --git a/src/room_render.h b/src/room_render.h index 6bbcdb6..22a400c 100644 --- a/src/room_render.h +++ b/src/room_render.h @@ -6,10 +6,8 @@ constexpr int SHOCKWAVE_COUNT = 2; -// Night Light's cone angle and the null items whose costumes the player's light reads. +// Night Light's cone angle. constexpr float NIGHT_LIGHT_ANGLE = 90; -constexpr int NULL_EFFECT_SPIRIT_AURA = 74; -constexpr int NULL_ITEM_BRIMSTONE_FLAME = 56; // The surfaces and images rooms draw through, file globals of the original made once for every room. // shading is the room shape's shading image Room::LoadBackdropGraphics loads (DAT_00c797bc), drawn into shadingSurface. diff --git a/src/room_special.cpp b/src/room_special.cpp index be248e8..7a653f7 100644 --- a/src/room_special.cpp +++ b/src/room_special.cpp @@ -453,8 +453,9 @@ static HealthOnHand health_on_hand(Entity_Player* player) { Entity_Player& one = *g_game->GetPlayer(i); Entity_Player* twin = one.twin_get(); - bool isSecondTwin = one.isExists && (one.playerType == PLAYER_JACOB || one.playerType == PLAYER_ESAU) && twin && - twin->playerIndex != -1 && twin->playerIndex < one.playerIndex && twin != &one; + bool isLazarus = one.playerType == PLAYER_LAZARUS_B || one.playerType == PLAYER_LAZARUS2_B; + bool isSecondTwin = one.isExists && isLazarus && twin && twin->playerIndex != -1 && + twin->playerIndex < one.playerIndex && twin != &one; if (one.variant != 0 || one.isCoopGhost || isSecondTwin || one.parent) continue; int soulHearts = 1; @@ -1042,11 +1043,12 @@ void GridEntity_Door::SpawnDust() // when the forms point back at each other, here each player is asked once. static Entity_Player* photo_holder_find(Entity_Player* player, int& item) { - for (int i = 0; player && player->isValid && i < PHOTO_HOLDER_CHECKS; i++) + for (int i = 0; player && i < PHOTO_HOLDER_CHECKS; i++) { if (player->HasTrinket(TRINKET_FADED_POLAROID, ITEM_CHECK_OWNED)) return item = TRINKET_FADED_POLAROID, player; if (player->HasCollectible(COLLECTIBLE_POLAROID, ITEM_CHECK_OWNED)) return item = COLLECTIBLE_POLAROID, player; if (player->HasCollectible(COLLECTIBLE_NEGATIVE, ITEM_CHECK_OWNED)) return item = COLLECTIBLE_NEGATIVE, player; + if (!player->isValid) return nullptr; bool isLazarus = player->playerType == PLAYER_LAZARUS_B || player->playerType == PLAYER_LAZARUS2_B; Entity_Player* twin = player->GetMainTwin() == player ? player->twin_get() : nullptr; diff --git a/src/room_transition.cpp b/src/room_transition.cpp index 3022cb6..3aff3be 100644 --- a/src/room_transition.cpp +++ b/src/room_transition.cpp @@ -207,7 +207,7 @@ static void teleporter_arrival_place(Room& room, int target) } // Part of 00830950: the players come onto the Death Certificate's floor in the fourth row's eleventh cell, all but the -// first scattered 10 about it, appearing frozen. +// first scattered 10 about it, appearing frozen, and their blood babies with them. static void death_certificate_players_place(Room& room) { constexpr int ARRIVAL_COLUMN = 10; @@ -236,6 +236,7 @@ static void death_certificate_players_place(Room& room) if (player->sprite.animState.animData) player->sprite.animState.SetFrameFloat(APPEAR_FRAME); player->isControlsEnabled = false; } + for (Entity_Familiar* clot : familiar_query(Entity_Familiar::BLOOD_BABY)) clot->pos = arrival; } // Part of 00830950: the players jump out of a Ventricle Razor portal, the first on it and the others a step off it, diff --git a/src/room_update.cpp b/src/room_update.cpp index 7e08117..4202a29 100644 --- a/src/room_update.cpp +++ b/src/room_update.cpp @@ -56,8 +56,6 @@ constexpr float DUNGEON_LADDER_Y = 110; constexpr float DUNGEON_LADDER_LEFT = 100; constexpr float DUNGEON_LADDER_RIGHT = 140; constexpr uint32_t DUNGEON_BLACK_MARKET_DOOR = 1u << DIRECTION_RIGHT; -constexpr uint64_t GAME_STATE_ANGEL_ROOM_SPAWNED = 1ull << 0; -constexpr uint64_t GAME_STATE_DEVIL_ROOM_SPAWNED = 1ull << 5; // The weather a stage rains down: the drops' chances, and the Downpour's lightning flash and thunder. constexpr float WEATHER_DROP_Y = -10; @@ -205,7 +203,6 @@ struct CurrentSplash // The run, room and stage values Update tells apart. constexpr ColorMod POOP_FX_COLOR = {{1, 1, 1, 3}, {0.7f, 0.1f, 0.9f, 1}, {0, 0, 0}}; -constexpr int NULL_EFFECT_POOP_CLOUD = 64; constexpr int CHALLENGE_SEEING_DOUBLE = 40; constexpr int SOUND_THUNDER = 472; constexpr int SOUND_ALARM = 460; @@ -631,7 +628,7 @@ static void door_leave(Room& room, Entity_Player& player, int slot) { bool isAngel = door.targetRoomType == ROOM_ANGEL; game.InitializeDevilAngelRoom(isAngel, !isAngel); - game.gameStateFlags |= isAngel ? GAME_STATE_ANGEL_ROOM_SPAWNED : GAME_STATE_DEVIL_ROOM_SPAWNED; + game.gameStateFlags |= 1ull << (isAngel ? GAME_STATE_FAMINE_SPAWNED : GAME_STATE_DEVILROOM_SPAWNED); } request.roomIndex = door.targetRoomIdx; if (request.roomIndex <= ROOM_INDEX_OTHER_DIMENSION) @@ -1409,7 +1406,7 @@ void Room::Update() isExorcistActive = players.FirstCollectibleOwner(COLLECTIBLE_VADE_RETRO, LAZARUS_SHARE_CHECK) != nullptr; if (temporaryEffects.HasCollectibleEffect(COLLECTIBLE_ASTRAL_PROJECTION)) g_manager->musicManager.targetPitch = time_scale_update(); - if (!temporaryEffects.isDisabled && temporaryEffects.HasNullEffect(NULL_EFFECT_POOP_CLOUD)) + if (!temporaryEffects.isDisabled && temporaryEffects.HasNullEffect(NULLITEM_REVERSE_STRENGTH)) fxLayers.AddPoopFx(POOP_FX_COLOR); if (descriptor->gridIndex == ROOM_LIL_PORTAL_IDX) lil_portal_room_update(*this); std::vector doubled; diff --git a/src/score_sheet.cpp b/src/score_sheet.cpp index 8bd3b8d..e235219 100644 --- a/src/score_sheet.cpp +++ b/src/score_sheet.cpp @@ -175,7 +175,7 @@ void ScoreSheet::AddKilledEnemy(Entity& npc) bool isRedRoom = game.room->descriptor->flags & ROOM_DESCRIPTOR_RED_ROOM; if ((isRedRoom && isRedRoomBonusCapped) || game.isRoomRespawned) return; - float health = std::ceil(std::pow(npc.maxHitPoints, KILL_HEALTH_EXPONENT) * KILL_POINTS_FACTOR); + float health = std::ceil(pow_float(npc.maxHitPoints, KILL_HEALTH_EXPONENT) * KILL_POINTS_FACTOR); float points = stage_multiplier_get(stage_visit_current()) * (health * npc.scoreMultiplier); if (game.playerManager.GetGFuelCount() > 0 && points > 0) @@ -226,8 +226,8 @@ static std::vector score_players_get() // The penalty that grows from nothing toward 80% of a score as an amount passes its allowance, rounded up. static int penalty_get(float amount, float allowance, int score) { - float kept = std::exp(std::log(PENALTY_DECAY) * amount / allowance); - return (int)std::ceil((1 - kept) * ((float)score * PENALTY_DECAY)); + float kept = exp_float(log_float(PENALTY_DECAY) * amount / allowance); + return (int)std::ceil((1 - kept) * (float)score * PENALTY_DECAY); } // 009e5d90 Scores the run so far: the stages, the ending's bonus, the schwag (hearts, consumables and pickup points), diff --git a/src/seeds.h b/src/seeds.h index afd2fe0..5b8e616 100644 --- a/src/seeds.h +++ b/src/seeds.h @@ -157,6 +157,8 @@ struct Seeds uint32_t Random(); constexpr float RANDOM_UNIT_SCALE = 2.3283064e-10f; +// The scale RNG::RandomFloat and RandomVector draw a unit float with, a hair under RANDOM_UNIT_SCALE. +constexpr float RNG_FLOAT_SCALE = 2.3283062e-10f; // The shift triple most of the game's generators are seeded with. constexpr uint32_t DEFAULT_SHIFT_INDEX = 35; // A seed's text: two halves of four characters, the second starting at 5. diff --git a/src/sfx_manager.h b/src/sfx_manager.h index 898a9cd..d148d02 100644 --- a/src/sfx_manager.h +++ b/src/sfx_manager.h @@ -128,6 +128,7 @@ enum SoundId : int SOUND_REDLIGHTNING_ZAP = 133, SOUND_REDLIGHTNING_ZAP_WEAK = 134, SOUND_REDLIGHTNING_ZAP_STRONG = 135, + SOUND_REDLIGHTNING_ZAP_BURST = 136, SOUND_ROCK_CRUMBLE = 137, SOUND_SMB_LARGE_CHEWS_4 = 142, SOUND_SCARED_WHIMPER = 143, diff --git a/src/stat_hud.cpp b/src/stat_hud.cpp index 04b3e53..0681d98 100644 --- a/src/stat_hud.cpp +++ b/src/stat_hud.cpp @@ -23,8 +23,6 @@ constexpr float TEXT_RAISE = -1; constexpr float TEXT_RAISE_TWO_PLAYERS = -5; constexpr float PLAYER_COLUMN_SHIFT = 4; constexpr float PLAYER_ROW_SHIFT = 7; -constexpr float TEXT_OFFSET_X = 16; -constexpr float TEXT_OFFSET_Y = 1; constexpr float CHANGE_OFFSET_X = 30; constexpr float CHANGE_SLIDE = -20; constexpr float SECOND_PLAYER_SHADE = 0.8f; @@ -262,7 +260,7 @@ void StatHUD::Render(Vector at) bool isShared = i == STAT_DEVIL_CHANCE || i == STAT_ANGEL_CHANCE || (i == STAT_SPEED && isJacobOrEsau); if (isShared && playerIndex != 0) continue; float y = isShared ? rowY : (float)playerIndex * PLAYER_ROW_SHIFT + textRaise + rowY; - Vector textAt = vector_make(column + shake.x + TEXT_OFFSET_X, y + shake.y + TEXT_OFFSET_Y); + Vector textAt = vector_make(column + shake.x + HUD_TEXT_OFFSET_X, y + shake.y + HUD_TEXT_OFFSET_Y); stat_text_render(slot, i, textAt, playerIndex == 0 ? 1 : SECOND_PLAYER_SHADE); } } diff --git a/src/stat_hud.h b/src/stat_hud.h index 593b35f..8ec9670 100644 --- a/src/stat_hud.h +++ b/src/stat_hud.h @@ -8,6 +8,9 @@ constexpr int STAT_PLAYER_COUNT = 2; constexpr int STAT_TRACKER_COUNT = 10; constexpr float STAT_THRESHOLD_FINE = 0.01f; constexpr float STAT_THRESHOLD_COARSE = 0.1f; +// Where a HUD row's number sits, right of its icon. +constexpr float HUD_TEXT_OFFSET_X = 16; +constexpr float HUD_TEXT_OFFSET_Y = 1; // The stats the stats HUD tracks, in the order of hudstats2.anm2's frames. The last two are tracked but never shown. enum StatHudStat : int diff --git a/src/string_table.h b/src/string_table.h index 2ee125e..e80c89e 100644 --- a/src/string_table.h +++ b/src/string_table.h @@ -9,6 +9,8 @@ // The mark that opens a string table key in place of literal text, and the one between a key's category and name. constexpr char STRING_KEY_PREFIX = '#'; constexpr char CATEGORY_SEPARATOR = '/'; +// The mark between words, where long text wraps. +constexpr char WORD_SEPARATOR = ' '; // The languages the game checks by id (its language column order). enum Language : int diff --git a/src/tainted_characters.cpp b/src/tainted_characters.cpp index 17754a8..fe3bb7a 100644 --- a/src/tainted_characters.cpp +++ b/src/tainted_characters.cpp @@ -555,7 +555,8 @@ static EffectUpdateEnd anima_chain_peg_update(Entity_Effect& peg) { uint32_t seed = Random(); Vector at = vector_add(peg.pos, vector_scale(link, along)); - Vector fling = vector_scale(random_direction(), random_unit() * ANIMA_GIB_SPEED_RANGE + ANIMA_GIB_SPEED); + Vector direction = random_direction(); + Vector fling = vector_scale(direction, random_unit() * ANIMA_GIB_SPEED_RANGE + ANIMA_GIB_SPEED); Entity* gib = g_game->Spawn({at, fling, nullptr, 0, ENTITY_EFFECT, EFFECT_CHAIN_GIB, seed}); gib->sprite.color = ANIMA_GIB_COLOR; gib->Update(); diff --git a/src/weapon.cpp b/src/weapon.cpp index 3f2b961..ea69700 100644 --- a/src/weapon.cpp +++ b/src/weapon.cpp @@ -89,8 +89,8 @@ constexpr ColorMod TORN_CARD_COLOR = {{0.5f, 0.9f, 0.4f, 1}, {0, 0, 0, 0}, {0, 0 // The Dead co-op baby's tears now and then (1 in 50) let a blue fly out while enemies live. constexpr uint32_t DEAD_BABY_FLY_ODDS = 50; -constexpr int CANDLE_ODDS = 8; -constexpr int GHOST_PEPPER_ODDS = 12; +constexpr int CANDLE_ODDS = 12; +constexpr int CANDLE_ODDS_BOTH = 8; constexpr int CANDLE_ODDS_MIN = 2; constexpr float CANDLE_VERSUS_DAMAGE = 4; constexpr int GREED_PERIOD = 20; @@ -328,8 +328,8 @@ float Weapon::GetChargeBarAmount() return std::min(std::max(charge / maxCharge, 0.0f), CHARGE_BAR_FULL); } -// 009f3150 The entity the weapon fires as. The original reads the first field of the subclass, which for tears is -// Cursed Eye's charge count: plain weapons have none. +// 009f3140 The entity the weapon fires as: plain weapons have none. The weapons that fire as one read it from their +// first field (009f3150) in their own override. Entity* Weapon::GetMainEntity() { return nullptr; } // The player the weapon fires for: its owner, or the player of its owning familiar. @@ -569,14 +569,17 @@ static Entity_Tear* extra_tear_spawn(Weapon& weapon, Entity_Player& player, cons } // What every extra tear of an item shares once its flags are set: the player as its parent, a tear index of its -// own and no streak, then its first update and a step back so it leaves from where it was spawned. -static void extra_tear_finish(Entity_Tear& tear, Entity_Player& player, float fallingSpeed, float fallingAccel) +// own and no streak. +static void extra_tear_link(Entity_Tear& tear, Entity_Player& player) { tear.parent = &player; tear.tearIdx = (int)Random(); tear.isCanTriggerStreakEnd = false; - tear.fallingSpeed = fallingSpeed; - tear.fallingAccel = fallingAccel; +} + +// An extra tear's first update once its fall is set, then a step back so it leaves from where it was spawned. +static void extra_tear_launch(Entity_Tear& tear) +{ tear.Update(); tear.pos = vector_sub(tear.pos, tear.velocity); } @@ -585,8 +588,8 @@ static void extra_tear_finish(Entity_Tear& tear, Entity_Player& player, float fa // way the head faces in pale green. static void torn_card_fire(Weapon& weapon, Entity_Player& player) { + if (!player.HasTrinket(TRINKET_TORN_CARD)) return; int multiplier = player.GetTrinketMultiplier(TRINKET_TORN_CARD); - if (multiplier <= 0) return; uint32_t period = multiplier == 2 ? TORN_CARD_PERIOD_DOUBLE : multiplier == 3 ? TORN_CARD_PERIOD_TRIPLE : TORN_CARD_PERIOD; if ((uint32_t)weapon.numFired % period != 0) return; @@ -607,12 +610,14 @@ static void torn_card_fire(Weapon& weapon, Entity_Player& player) tear->fScale = tear->baseScale; tear->ResetSpriteScale(); tear->SetColor(TORN_CARD_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); - float slope = std::max(((float)std::pow(TORN_CARD_DRAG, TORN_CARD_FLIGHT) - 1) * TORN_CARD_SLOPE, TEAR_SCALE_MIN); - float fallingSpeed = ((TORN_CARD_FLOOR - tear->height) - (TORN_CARD_FLIGHT - slope) * TORN_CARD_ARC) / slope; - extra_tear_finish(*tear, player, fallingSpeed, TORN_CARD_FALL_ACCEL); + extra_tear_link(*tear, player); + float slope = std::max((pow_float(TORN_CARD_DRAG, TORN_CARD_FLIGHT) - 1) * TORN_CARD_SLOPE, TEAR_SCALE_MIN); + tear->fallingAccel = TORN_CARD_FALL_ACCEL; + tear->fallingSpeed = ((TORN_CARD_FLOOR - tear->height) - (TORN_CARD_FLIGHT - slope) * TORN_CARD_ARC) / slope; + extra_tear_launch(*tear); } -// Bird's Eye and Ghost Pepper: one tear in 8 (12 for Ghost Pepper alone, less with luck) throws a red or blue candle +// Bird's Eye and Ghost Pepper: one tear in 12 (8 with both, less with luck) throws a red or blue candle // flame along the aim, either with both. In versus a blue flame hits as hard as four tears. static void candle_fire(Entity_Player& player, const Vector& aim) { @@ -621,7 +626,7 @@ static void candle_fire(Entity_Player& player, const Vector& aim) if (!isBirdsEye && !isGhostPepper) return; bool isBoth = isBirdsEye && isGhostPepper; - int odds = isBirdsEye ? CANDLE_ODDS : GHOST_PEPPER_ODDS; + int odds = isBoth ? CANDLE_ODDS_BOTH : CANDLE_ODDS; int least = isBoth ? 1 : CANDLE_ODDS_MIN; int chance = odds - (int)player.luck; if (chance < least) chance = least; @@ -666,8 +671,10 @@ static void greed_coin_fire(Weapon& weapon, Entity_Player& player, const Vector& else tear->SetCollisionDamage(params.tearDamage); tear->SetTearFlags(flags); - float fallingSpeed = random_unit() * TEAR_FALL_SPREAD - player.tearFallingSpeed - IMMACULATE_LIFT; - extra_tear_finish(*tear, player, fallingSpeed, player.tearFallingAcceleration * IMMACULATE_FALL_SCALE); + extra_tear_link(*tear, player); + tear->fallingSpeed = random_unit() * TEAR_FALL_SPREAD - player.tearFallingSpeed - IMMACULATE_LIFT; + tear->fallingAccel = player.tearFallingAcceleration * IMMACULATE_FALL_SCALE; + extra_tear_launch(*tear); effect_sound_play(SOUND_CASH_REGISTER); } @@ -699,8 +706,10 @@ static void lead_pencil_fire(Weapon& weapon, Entity_Player& player) tear->fScale = tear->baseScale; tear->ResetSpriteScale(); tear->SetColor(params.tearColor, -1, COLOR_PRIORITY_DEFAULT, false, true); - float fallingSpeed = random_unit() * TEAR_FALL_SPREAD - player.tearFallingSpeed; - extra_tear_finish(*tear, player, fallingSpeed, player.tearFallingAcceleration); + extra_tear_link(*tear, player); + tear->fallingSpeed = random_unit() * TEAR_FALL_SPREAD - player.tearFallingSpeed; + tear->fallingAccel = player.tearFallingAcceleration; + extra_tear_launch(*tear); if (g_game->deathmatchManager.is_active()) { TearFlags flags = tear->tearFlags; @@ -819,9 +828,10 @@ bool Weapon::is_held_item(CostumeSpriteDesc& costume, std::string_view animName, return worn->id == COLLECTIBLE_BRIMSTONE; } -// The costume sprites of a player's head layers that belong to an item, in layer order. +// The costume sprites of a player's head layers that belong to an item (without one, that have the animation), in +// layer order. static std::vector item_costumes_get(Entity_Player& player, ItemConfig_Item* item, - CostumeLayers layers) + CostumeLayers layers, std::string_view animName = "") { std::vector costumes; @@ -830,7 +840,7 @@ static std::vector item_costumes_get(Entity_Player& player, if (map.index < 0 || (layers == COSTUME_LAYERS_HEAD && map.isBodyLayer)) continue; CostumeSpriteDesc& costume = player.costumeSpriteDescs[map.index]; - if (Weapon::is_held_item(costume, "", item)) costumes.push_back(&costume); + if (Weapon::is_held_item(costume, animName, item)) costumes.push_back(&costume); } return costumes; } @@ -842,7 +852,7 @@ void costume_item_anim_set(Entity_Player& player, ItemConfig_Item* item, std::st { std::string overlayName = std::string(animName) + "_Overlay"; - for (CostumeSpriteDesc* costume : item_costumes_get(player, item, COSTUME_LAYERS_HEAD)) + for (CostumeSpriteDesc* costume : item_costumes_get(player, item, COSTUME_LAYERS_HEAD, animName)) { costume->isItemAnimPlay = true; if (frame >= 0) costume->sprite.SetFrame(animName, frame); @@ -866,7 +876,7 @@ void costume_item_frame_set(Entity_Player& player, ItemConfig_Item* item, std::s { std::string overlayName = std::string(animName) + "_Overlay"; - for (CostumeSpriteDesc* costume : item_costumes_get(player, item, COSTUME_LAYERS_HEAD)) + for (CostumeSpriteDesc* costume : item_costumes_get(player, item, COSTUME_LAYERS_HEAD, animName)) { if (costume->sprite.IsPlaying(animName)) costume->sprite.SetFrame((float)frame); if (costume->isHasOverlay && costume->sprite.IsOverlayPlaying(overlayName) && @@ -1394,7 +1404,7 @@ void Weapon_Tears::Fire(const Vector& shootDirection, bool isShooting, bool isIn // The original divides by a zero full charge too. Here a zero fire delay leaves the rate alone. float fullCharge = maxFireDelay * NEPTUNUS_CHARGE; float ratio = fullCharge == 0 ? 0 : std::clamp(charge / fullCharge, 0.0f, 1.0f); - float boost = std::pow(ratio * NEPTUNUS_RATE_RISE + 1, 2.0f); + float boost = pow_float(ratio * NEPTUNUS_RATE_RISE + 1, 2); eyeMaxFireDelay = std::max((eyeMaxFireDelay + 1) / boost, NEPTUNUS_DELAY_MIN) - 1; } @@ -1461,7 +1471,6 @@ void Weapon_Tears::Fire(const Vector& shootDirection, bool isShooting, bool isIn } Vector firePos = owner ? owner->pos : Vector{}; - Vector ownerPos = firePos; Vector base = vector_add(vector_scale(shotDirection, SHOT_SPEED_BASE), get_tear_movement_inheritance(shotDirection)); if (player && player->HasCollectible(COLLECTIBLE_IPECAC)) @@ -1526,7 +1535,7 @@ void Weapon_Tears::Fire(const Vector& shootDirection, bool isShooting, bool isIn shot.velocity = vector_spread(shot.velocity, spreadAngle); fire_tear(shot, 0, damageMultiplier, positionStep); } - if (seededVariant != SEEDED_VARIANT_NONE) gfuel_shot_effects(*shooter, ownerPos, base); + if (seededVariant != SEEDED_VARIANT_NONE) gfuel_shot_effects(*shooter, firePos, base); positionStep -= eyeMaxFireDelay + 1; } } diff --git a/src/weapon_bombs.h b/src/weapon_bombs.h index c75c458..c488bb0 100644 --- a/src/weapon_bombs.h +++ b/src/weapon_bombs.h @@ -11,7 +11,11 @@ struct Weapon_Bombs : Weapon void Fire(const Vector& shootDirection, bool isShooting, bool isInterpolated) override; Entity* GetFocusEntity() override; + // 009f3150 Ludovico's bomb is what the weapon fires as. + Entity* GetMainEntity() override { return ludovicoBomb; } int GetMarkedTargetVariant() override; + // The bombs ride a Tractor Beam (the shared return of true). + bool SupportsTractorBeam() override { return true; } }; Weapon* weapon_bomb_make(WeaponType type); diff --git a/src/weapon_fetus.cpp b/src/weapon_fetus.cpp index e9f5c5e..cc24350 100644 --- a/src/weapon_fetus.cpp +++ b/src/weapon_fetus.cpp @@ -91,8 +91,9 @@ static void fetus_birth_splash(Entity_Tear& tear) puff->posOffset = vector_make(0, FETUS_BIRTH_PUFF_LIFT); puff->Update(); - int drops = (int)(Random() & 1) + 1; - int count = (int)(Random() & 1) + drops + FETUS_BIRTH_DROPLETS; + int dropRoll = (int)(Random() & 1); + int drops = dropRoll + 1; + int count = (int)(Random() & 1) + dropRoll + FETUS_BIRTH_DROPLETS; for (int i = 0; i < count; i++) { float turn = (random_unit() * FETUS_BIRTH_SPREAD - FETUS_BIRTH_SPREAD / 2) * DEGREES_TO_RADIANS; @@ -109,8 +110,9 @@ static void fetus_birth_splash(Entity_Tear& tear) // 009f6e60 Throws a fetus (a C Section tear) for the weapon's owner (or a given source): its player's fetus hit // params at three quarters of the damage, spectral, never held by Marked, the Tractor Beam or a laser, carrying the -// weapons its player's items give, skinned like its player and born in a splash of blood. It updates once, steps -// back a frame and runs MC_POST_FIRE_TEAR. A familiar throws for its player. The original reads a missing player's effects and type. This skips +// weapons its player's items give, with the hit params' mass and knockback and the player's next tear index, skinned +// like its player and born in a splash of blood. It updates once, steps back a frame and runs MC_POST_FIRE_TEAR. A +// familiar throws for its player. The original reads a missing player's effects, tear count and type. This skips // them. Entity_Tear* fire_fetus_tear(Weapon& weapon, const FetusShot& shot) { @@ -155,6 +157,12 @@ Entity_Tear* fire_fetus_tear(Weapon& weapon, const FetusShot& shot) { float glow = dead_eye_glow_get(*player); if (glow > 0) tear.SetDeadEyeIntensity(glow); + } + tear.mass *= params.massMultiplier; + tear.knockbackMultiplier = params.knockbackMultiplier; + if (player) + { + tear.tearIdx = player->firedTearCount++; fetus_skin_apply(tear, *player); } if (vector_length_squared(shot.velocity) > FETUS_BIRTH_SPEED_SQUARED) fetus_birth_splash(tear); @@ -166,7 +174,8 @@ Entity_Tear* fire_fetus_tear(Weapon& weapon, const FetusShot& shot) // Throws the fetuses of a full charge: the fire delay restarts at a third of the charge (a familiar blinks), the tear // effects trigger, and one fetus goes per shot of the volley with the backward, mirrored and random ones, all at the -// aim plus the owner's movement. The C Section costumes on a player's body play its throw, a familiar shoots. +// aim plus the owner's movement. The C Section costumes on a player's body play its throw, then the head shoots (a +// familiar's too). // The original's sideways fetuses mirror the throw on each axis instead of turning it: kept. void Weapon_Fetus::release(const Vector& shootDirection, const Vector& aim, float maxCharge, float shotSpeed) { @@ -202,7 +211,8 @@ void Weapon_Fetus::release(const Vector& shootDirection, const Vector& aim, floa fire(vector_add(from, lane.position), lane.velocity); } - update_c_section_charge_anim(HEAD_CHARGE_SHOOT, shootDirection, C_SECTION_FRAME_KEEP); + if (owner && owner->is_player()) update_c_section_charge_anim(HEAD_CHARGE_SHOOT, shootDirection, C_SECTION_FRAME_KEEP); + UpdateHeadChargeAnimation(COLLECTIBLE_C_SECTION, HEAD_CHARGE_SHOOT, shootDirection, C_SECTION_FRAME_KEEP); } // 00a036e0 C Section: while shooting the charge grows at the owner's speed (the head shows it, or its full charge), diff --git a/src/weapon_fetus.h b/src/weapon_fetus.h index 832696a..b20b3e1 100644 --- a/src/weapon_fetus.h +++ b/src/weapon_fetus.h @@ -21,6 +21,8 @@ struct Weapon_Fetus : Weapon void Fire(const Vector& shootDirection, bool isShooting, bool isInterpolated) override; float GetMaxCharge() override; int GetMarkedTargetVariant() override; + // Thrown fetuses set off Kidney Stone (the shared return of true). + bool CanTriggerKidneyStone() override { return true; } void release(const Vector& shootDirection, const Vector& aim, float maxCharge, float shotSpeed); }; diff --git a/src/weapon_knives.h b/src/weapon_knives.h index 95b3679..f1347ec 100644 --- a/src/weapon_knives.h +++ b/src/weapon_knives.h @@ -29,6 +29,8 @@ struct Weapon_Knife : Weapon void ClearReferences() override; float GetMaxCharge() override; Entity* GetFocusEntity() override; + // 009f3150 The main knife is what the weapon fires as. + Entity* GetMainEntity() override { return knives[0]; } void TriggerNewRoom() override; int GetMarkedTargetVariant() override; bool SupportsTractorBeam() override; @@ -100,6 +102,8 @@ struct Weapon_Bone : Weapon float GetMaxCharge() override; // 0085e1b0 The camera follows Epic Fetus' target. Entity* GetFocusEntity() override { return epicFetusTarget; } + // 009f3150 The main club is what the weapon fires as. + Entity* GetMainEntity() override { return knives[0]; } void TriggerNewRoom() override; bool CanTriggerCursedEyeTeleport() override; bool CanTriggerKidneyStone() override; diff --git a/src/weapon_lasers.cpp b/src/weapon_lasers.cpp index 606ed3a..4ea0462 100644 --- a/src/weapon_lasers.cpp +++ b/src/weapon_lasers.cpp @@ -177,11 +177,13 @@ static Entity_Player* weapon_player(Entity* owner) return owner->type == ENTITY_FAMILIAR ? static_cast(owner)->player : nullptr; } -// Marked's target, or Eye of the Occult's with it, or none. +// Eye of the Occult's target (even without Marked), Marked's, or none. A weapon without a player crashes in the +// original: here it places none. static int marked_variant_get(Entity_Player* player) { - if (!player || !player->HasCollectible(COLLECTIBLE_MARKED)) return 0; - return player->HasCollectible(COLLECTIBLE_EYE_OF_THE_OCCULT) ? OCCULT_TARGET_VARIANT : MARKED_TARGET_VARIANT; + if (!player) return 0; + if (player->HasCollectible(COLLECTIBLE_EYE_OF_THE_OCCULT)) return OCCULT_TARGET_VARIANT; + return player->HasCollectible(COLLECTIBLE_MARKED) ? MARKED_TARGET_VARIANT : 0; } // 009f3f60 The color the owner's lasers take: its player's laser color, purple for a familiar under Baby-Bender and @@ -345,12 +347,14 @@ Entity_Laser* Weapon::fire_brimstone_with_color(const Vector& shootDirection, fl // 009f6610 Fires a Technology laser: the player's own, or a familiar's from its eye in the laser color with its // player's flags (one of Tech.5's in twenty with a random flag of the first 64 only) and laser hit params (Technology -// 2's with the weapon's damage), drawn behind it when it fires up or away from the eye. Anything else fires a plain -// one from the owner. +// 2's with the weapon's damage), drawn behind it when it fires up or away from the eye. Anything else, or a laser +// not made, fires a plain one from the owner. Entity_Laser* Weapon::fire_laser(const TechLaserShot& shot) { - if (owner && owner->type == ENTITY_PLAYER) return owner->ToPlayer()->FireTechLaser(shot); - if (owner && owner->type == ENTITY_FAMILIAR) return familiar_laser_fire(shot); + Entity_Laser* laser = nullptr; + if (owner && owner->type == ENTITY_PLAYER) laser = owner->ToPlayer()->FireTechLaser(shot); + else if (owner && owner->type == ENTITY_FAMILIAR) laser = familiar_laser_fire(shot); + if (laser) return laser; return Entity_Laser::ShootAngle({.position = get_owner_position(), .source = owner, @@ -451,8 +455,9 @@ bool Weapon_Laser::CanTriggerCursedEyeTeleport() return charge > 0 && charge < GetMaxCharge(); } -// Lasers ride a Tractor Beam unless Ludovico holds them (Weapon_Knife::SupportsTractorBeam, which lasers share). -bool Weapon_Laser::SupportsTractorBeam() +// Lasers set off Kidney Stone unless Ludovico holds them (Weapon_Knife::SupportsTractorBeam, which lasers share in +// this slot). Lasers never ride a Tractor Beam. +bool Weapon_Laser::CanTriggerKidneyStone() { return !(modifiers & WEAPON_MOD_LUDOVICO_TECHNIQUE); } @@ -516,7 +521,7 @@ std::vector Weapon_Laser::fire_lasers(const LaserVolley& volley) laser->isDisableInitSound = volley.sprayCount > SPRAY_QUIET_COUNT; fired.push_back(laser); } - if (volley.sprayCount > SPRAY_QUIET_COUNT) npc_sound_play(SOUND_BLOOD_LASER_LARGE, 1, 2, 1); + if (volley.sprayCount > SPRAY_QUIET_COUNT) npc_sound_play(SOUND_REDLIGHTNING_ZAP_BURST, 1, 2, 1); } return fired; } @@ -1219,8 +1224,8 @@ static uint64_t sneeze_damage_flags(Entity& enemy, Entity_Player* player) return player->numBlueFlies < SNEEZE_BLUE_FLY_MAX ? DAMAGE_SPAWN_FLY : 0; } -// What a sneeze's burst does to an entity it reaches: an enemy is pushed (unless it never is), hurt and marked, and -// takes the shot's tear effects. A fire other than a moving one goes out, a frozen enemy shatters on the player, a +// What a sneeze's burst does to an entity it reaches: an enemy (or a player in versus) is pushed (unless it never +// is), hurt and marked, and takes the shot's tear effects. A fire other than a moving one goes out, a frozen enemy shatters on the player, a // shopkeeper is spared. Bombs (not the player's raised Dr. Fetus bomb), loose pickups and enemy shots are knocked // away, the player's Ludovico tear is flung. Whether an enemy was hurt. static bool sneeze_entity_hit(Entity& target, const SneezeHit& hit) @@ -1232,7 +1237,8 @@ static bool sneeze_entity_hit(Entity& target, const SneezeHit& hit) if (target.friction != 0) target.velocity = vector_add(target.velocity, vector_scale(away, strength * target.speedMultiplier / target.friction)); }; int type = target.type; - if (Entity::is_enemy_type(type)) + bool isVersusPlayer = type == ENTITY_PLAYER && g_game->deathmatchManager.is_active(); + if (isVersusPlayer || Entity::is_enemy_type(type)) { if (target.HasEntityFlags(FLAG_FRIENDLY) || type == ENTITY_SHOPKEEPER) return false; if (type == ENTITY_FIREPLACE && target.variant != FIRE_COAL) diff --git a/src/weapon_lasers.h b/src/weapon_lasers.h index 1defce5..6e06af4 100644 --- a/src/weapon_lasers.h +++ b/src/weapon_lasers.h @@ -28,9 +28,11 @@ struct Weapon_Laser : Weapon void ClearReferences() override; float GetMaxCharge() override; Entity* GetFocusEntity() override; + // 009f3150 Ludovico's ring is what the weapon fires as. + Entity* GetMainEntity() override { return ludovicoLaser; } int GetMarkedTargetVariant() override; bool CanTriggerCursedEyeTeleport() override; - bool SupportsTractorBeam() override; + bool CanTriggerKidneyStone() override; std::vector fire_lasers(const LaserVolley& volley); static void init_laser(Weapon& weapon, Entity_Laser& laser); @@ -85,6 +87,9 @@ struct Weapon_TechX : Weapon void Fire(const Vector& shootDirection, bool isShooting, bool isInterpolated) override; float GetMaxCharge() override; int GetMarkedTargetVariant() override; + // Tech X rings ride a Tractor Beam and set off Kidney Stone (the shared return of true). + bool SupportsTractorBeam() override { return true; } + bool CanTriggerKidneyStone() override { return true; } void fire_rings(const Vector& aim, float shotSpeed); }; diff --git a/src/weapon_monstros_lung.h b/src/weapon_monstros_lung.h index 2c424cb..12e6cb8 100644 --- a/src/weapon_monstros_lung.h +++ b/src/weapon_monstros_lung.h @@ -10,6 +10,8 @@ struct Weapon_MonstrosLung : Weapon void Fire(const Vector& shootDirection, bool isShooting, bool isInterpolated) override; float GetMaxCharge() override; int GetMarkedTargetVariant() override; + // The coughed tears ride a Tractor Beam (the shared return of true). + bool SupportsTractorBeam() override { return true; } void FireBurst(const Vector& velocity, int count, float damageMultiplier); }; diff --git a/src/weapon_umbilical_whip.h b/src/weapon_umbilical_whip.h index 53fdd4c..07f98f1 100644 --- a/src/weapon_umbilical_whip.h +++ b/src/weapon_umbilical_whip.h @@ -14,6 +14,8 @@ struct Weapon_UmbilicalWhip : Weapon void ClearReferences() override; // 009f3150 The whip is what the weapon fires as. Entity* GetMainEntity() override { return whip; } + // The whip rides a Tractor Beam (the shared return of true). + bool SupportsTractorBeam() override { return true; } void crack(const Vector& shootDirection); }; diff --git a/src/weapon_urn_of_souls.h b/src/weapon_urn_of_souls.h index 1492b35..03e18bc 100644 --- a/src/weapon_urn_of_souls.h +++ b/src/weapon_urn_of_souls.h @@ -18,6 +18,8 @@ struct Weapon_UrnOfSouls : Weapon void ClearReferences() override; // 009f3170 The urn is what the weapon fires as. Entity* GetMainEntity() override { return urn; } + // The flames ride a Tractor Beam (the shared return of true). + bool SupportsTractorBeam() override { return true; } Vector aim_get(const Vector& shootDirection); void urn_spawn(const Vector& aim, bool isBelial);