diff --git a/generated-src/capsule.cpp b/generated-src/capsule.cpp deleted file mode 100644 index 5ca1ee0..0000000 --- a/generated-src/capsule.cpp +++ /dev/null @@ -1,355 +0,0 @@ -#include "classes.h" - -// 00945190 -void Capsule::constructor(Vector *position, Vector *multiplier, float rotation, float size) -{ - float fVar1; - float fVar2; - float axisX; - float cosRotation; - float fVar3; - float scaledY; - - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[1])) + 0x1)))) = 0; - *GHIDRA_CAST(this) = 0; - *GHIDRA_CAST((this + 4)) = 0; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[2])) + 0x2)))) = 0; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[6])) + 0x2)))) = 0; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[5])) + 0x1)))) = 0; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[9])) + 0x1)))) = 0; - *GHIDRA_CAST((this + 8)) = 0; - *GHIDRA_CAST(this) = position->x; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[1])) + 0x1)))) = position->y; - fVar3 = size * multiplier->x; - scaledY = size * multiplier->y; - axisX = sin(rotation * 0.017453292); - cosRotation = cos(rotation * 0.017453292); - if (fVar3 <= scaledY) { - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[10])) + 0x2)))) = fVar3; - *GHIDRA_CAST((this + 0xc)) = scaledY - fVar3; - *GHIDRA_CAST((this + 8)) = axisX; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[9])) + 0x1)))) = cosRotation; - fVar3 = cosRotation; - cosRotation = axisX; - } - else { - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[10])) + 0x2)))) = scaledY; - *GHIDRA_CAST((this + 0xc)) = fVar3 - scaledY; - *GHIDRA_CAST((this + 8)) = cosRotation; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[9])) + 0x1)))) = axisX; - fVar3 = axisX; - } - fVar1 = *GHIDRA_CAST((this + 0xc)); - fVar2 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[1])) + 0x1)))); - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[2])) + 0x2)))) = *GHIDRA_CAST(this) - fVar1 * cosRotation; - *GHIDRA_CAST((this + 4)) = fVar2 - fVar1 * fVar3; - fVar3 = *GHIDRA_CAST((this + 0xc)); - fVar1 = *GHIDRA_CAST((this + 8)); - fVar2 = *GHIDRA_CAST(this); - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[6])) + 0x2)))) = fVar3 * *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[9])) + 0x1)))) + *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[1])) + 0x1)))) - ; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[5])) + 0x1)))) = fVar3 * fVar1 + fVar2; - return; -} - -// 009452e0 -void Capsule::constructor2(Vector *Position, Vector *TargetPosition, float size) -{ - float length; - float dirX; - float dy; - float dirY; - float dx; - - *GHIDRA_CAST((this + 4)) = 0; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[2])) + 0x2)))) = 0; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[6])) + 0x2)))) = 0; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[5])) + 0x1)))) = 0; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[1])) + 0x1)))) = 0; - *GHIDRA_CAST(this) = 0; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[9])) + 0x1)))) = 0; - *GHIDRA_CAST((this + 8)) = 0; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[2])) + 0x2)))) = Position->x; - *GHIDRA_CAST((this + 4)) = Position->y; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[5])) + 0x1)))) = TargetPosition->x; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[6])) + 0x2)))) = TargetPosition->y; - dy = TargetPosition->y - Position->y; - dx = TargetPosition->x - Position->x; - length = sqrtf(dy * dy + dx * dx); - if (length <= 0.0) { - dirX = g_vectorZero.x; - dirY = g_vectorZero.y; - } - else { - dirY = dy / length; - dirX = dx / length; - } - *GHIDRA_CAST((this + 8)) = dirX; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[9])) + 0x1)))) = dirY; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[10])) + 0x2)))) = size; - *GHIDRA_CAST((this + 0xc)) = length * 0.5; - length = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[6])) + 0x2)))); - *GHIDRA_CAST(this) = (*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[5])) + 0x1)))) + *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[2])) + 0x2))))) * 0.5; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[1])) + 0x1)))) = (*GHIDRA_CAST((this + 4)) + length) * 0.5; - return; -} - -// 00945400 -void Capsule::get_bounding_box(Vector *outMin, Vector *outMax) -{ - float extentY; - float extentX; - float centerY; - - extentX = ABS(*GHIDRA_CAST((this + 8))) * *GHIDRA_CAST((this + 0xc)) + *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[10])) + 0x2)))); - extentY = ABS(*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[9])) + 0x1))))) * *GHIDRA_CAST((this + 0xc)) + - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[10])) + 0x2)))); - centerY = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[1])) + 0x1)))); - outMin->x = *GHIDRA_CAST(this) - extentX; - outMin->y = centerY - extentY; - centerY = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(this[1])) + 0x1)))); - outMax->x = extentX + *GHIDRA_CAST(this); - outMax->y = extentY + centerY; - return; -} - -// 00945470 -uint8_t Capsule::Collide(Capsule *a, Capsule *b, Vector *outHit) -{ - float *closestToA; - float *closestToB; - float fVar1; - float fVar2; - float fVar3; - double dVar4; - float fVar5; - float fVar6; - float fVar7; - float separationY; - float separationX; - float aStartY; - float aEndX; - float bStartY; - float aEndY; - float bEndY; - float bEndX; - float local_3c; - float bStartToAY; - float aStartX; - float local_30; - float local_2c; - float aLengthSq; - float local_24; - float bEndToAY; - Capsule *local_1c; - float aEndToBX; - float aEndToBY; - float aStartToBX; - float aStartToBY; - - separationY = g_vectorZero.y; - separationX = g_vectorZero.x; - aEndX = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(a[5])) + 0x1)))); - aStartX = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(a[2])) + 0x2)))); - aStartY = *GHIDRA_CAST((a + 4)); - fVar1 = aEndX - aStartX; - bEndX = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(b[5])) + 0x1)))); - local_3c = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(b[2])) + 0x2)))); - aEndY = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(a[6])) + 0x2)))); - fVar2 = aEndY - aStartY; - bEndY = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(b[6])) + 0x2)))); - bStartY = *GHIDRA_CAST((b + 4)); - fVar5 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(b[6])) + 0x2)))) - bStartY; - fVar7 = (bEndX - local_3c) * fVar2 - fVar5 * fVar1; - local_1c = a; - if (fVar7 != 0.0) { - fVar3 = ((aStartX - local_3c) * fVar2 + (*GHIDRA_CAST((b + 4)) - aStartY) * fVar1) / fVar7; - local_2c = ((aStartY - *GHIDRA_CAST((b + 4))) * (bEndX - local_3c) + (local_3c - aStartX) * fVar5) / - -fVar7; - bEndX = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(b[5])) + 0x1)))); - if ((((0.0 <= fVar3) && (fVar3 <= 1.0)) && (aEndX = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(a[5])) + 0x1)))), 0.0 <= local_2c)) - && (local_2c <= 1.0)) { - fVar7 = fVar2 * fVar3 + aStartY; - fVar3 = fVar1 * fVar3 + aStartX; - separationX = fVar3 - aStartX; - separationY = fVar7 - aStartY; - fVar5 = fVar3 - aEndX; - fVar1 = separationY * separationY + separationX * separationX; - local_30 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(a[10])) + 0x2)))); - local_24 = fVar7 - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(a[6])) + 0x2)))); - fVar2 = local_24 * local_24 + fVar5 * fVar5; - if (fVar2 < fVar1) { - fVar1 = fVar2; - separationY = local_24; - separationX = fVar5; - } - fVar6 = local_3c - fVar3; - fVar5 = *GHIDRA_CAST((b + 4)) - fVar7; - fVar2 = fVar5 * fVar5 + fVar6 * fVar6; - if (fVar2 < fVar1) { - local_30 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(b[10])) + 0x2)))); - fVar1 = fVar2; - separationY = fVar5; - separationX = fVar6; - } - fVar3 = bEndX - fVar3; - fVar7 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(b[6])) + 0x2)))) - fVar7; - fVar2 = fVar7 * fVar7 + fVar3 * fVar3; - if (fVar2 < fVar1) { - local_30 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(b[10])) + 0x2)))); - fVar1 = fVar2; - separationY = fVar7; - separationX = fVar3; - } - dVar4 = (double)fVar1; - if (dVar4 < 0.0) { - libm_sse2_sqrt_precise(); - } - else { - dVar4 = SQRT(dVar4); - } - local_24 = (float)dVar4 + local_30; - fVar1 = sqrtf(separationY * separationY + separationX * separationX); - if (0.0 < fVar1) { - separationX = separationX * (1.0 / fVar1); - separationY = separationY * (1.0 / fVar1); - } - separationX = separationX * local_24; - separationY = separationY * local_24; - aStartX = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(a[2])) + 0x2)))); - aEndX = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(a[5])) + 0x1)))); - local_3c = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(b[2])) + 0x2)))); - bEndX = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(b[5])) + 0x1)))); - } - } - if ((separationX != g_vectorZero.x) || (separationY != g_vectorZero.y)) { - aEndY = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(a[6])) + 0x2)))) + separationY; - aEndX = aEndX + separationX; - local_3c = local_3c + separationX; - bEndX = bEndX + separationX; - aStartY = aStartY + separationY; - aStartX = aStartX + separationX; - bEndY = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(b[6])) + 0x2)))) + separationY; - bStartY = *GHIDRA_CAST((b + 4)) + separationY; - } - local_30 = bEndX - local_3c; - aStartToBY = aStartY - bStartY; - fVar2 = bEndY - bStartY; - fVar1 = fVar2 * fVar2 + local_30 * local_30; - aStartToBX = aStartX - local_3c; - if ((0.0001 <= ABS(fVar1)) && - (fVar5 = (fVar2 * aStartToBY + local_30 * aStartToBX) / fVar1, 0.0 <= fVar5)) { - if (fVar5 < 1.0) { - aStartToBX = aStartX - (local_30 * fVar5 + local_3c); - aStartToBY = aStartY - (fVar2 * fVar5 + bStartY); - } - else { - aStartToBY = aStartY - bEndY; - aStartToBX = aStartX - bEndX; - } - } - aStartToBX = -aStartToBX; - aEndToBX = aEndX - local_3c; - aEndToBY = aEndY - bStartY; - aStartToBY = -aStartToBY; - if ((0.0001 <= ABS(fVar1)) && - (fVar1 = (fVar2 * aEndToBY + local_30 * aEndToBX) / fVar1, 0.0 <= fVar1)) { - if (fVar1 < 1.0) { - aEndToBX = aEndX - (local_30 * fVar1 + local_3c); - aEndToBY = aEndY - (fVar2 * fVar1 + bStartY); - } - else { - aEndToBX = aEndX - bEndX; - aEndToBY = aEndY - bEndY; - } - } - aEndToBX = -aEndToBX; - fVar1 = aEndY - aStartY; - aEndToBY = -aEndToBY; - fVar2 = aEndX - aStartX; - aLengthSq = fVar1 * fVar1 + fVar2 * fVar2; - local_2c = ABS(aLengthSq); - fVar5 = local_3c - aStartX; - bStartToAY = bStartY - aStartY; - if ((0.0001 <= local_2c) && - (fVar7 = (fVar5 * fVar2 + fVar1 * bStartToAY) / aLengthSq, 0.0 <= fVar7)) { - if (fVar7 < 1.0) { - fVar5 = local_3c - (fVar2 * fVar7 + aStartX); - bStartToAY = bStartY - (fVar1 * fVar7 + aStartY); - } - else { - fVar5 = local_3c - aEndX; - bStartToAY = bStartY - aEndY; - } - } - local_24 = bEndX - aStartX; - bEndToAY = bEndY - aStartY; - local_3c = fVar5; - if (0.0001 <= local_2c) { - local_30 = fVar2 * local_24 + fVar1 * bEndToAY; - fVar7 = local_30 / aLengthSq; - if (0.0 <= fVar7) { - if (fVar7 < 1.0) { - local_24 = bEndX - (fVar2 * fVar7 + aStartX); - bEndToAY = bEndY - (fVar1 * fVar7 + aStartY); - } - else { - local_24 = bEndX - aEndX; - bEndToAY = bEndY - aEndY; - } - } - } - fVar1 = aStartToBY * aStartToBY + aStartToBX * aStartToBX; - fVar7 = aEndToBY * aEndToBY + aEndToBX * aEndToBX; - fVar5 = bStartToAY * bStartToAY + fVar5 * fVar5; - fVar2 = bEndToAY * bEndToAY + local_24 * local_24; - closestToB = &aStartToBX; - if (fVar7 <= fVar1) { - closestToB = &aEndToBX; - fVar1 = fVar7; - } - closestToA = &local_24; - if (fVar5 < fVar2) { - closestToA = &local_3c; - fVar2 = fVar5; - } - if (fVar2 <= fVar1) { - if (outHit == GHIDRA_CAST(0x0)) goto LAB_00945cf6; - outHit->x = *closestToA; - fVar1 = closestToA[1]; - } - else { - fVar2 = fVar1; - if (outHit == GHIDRA_CAST(0x0)) goto LAB_00945cf6; - outHit->x = *closestToB; - fVar1 = closestToB[1]; - } - outHit->y = fVar1; -LAB_00945cf6: - local_1c = GHIDRA_CAST((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(local_1c[10])) + 0x2)))) + *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(b[10])) + 0x2)))))); - if ((float)local_1c * (float)local_1c <= fVar2) { - return 0; - } - if (fVar2 == 0.0) { - if (outHit != GHIDRA_CAST(0x0)) { - outHit->x = separationX; - outHit->y = separationY; - return 1; - } - } - else { - dVar4 = (double)fVar2; - if (dVar4 < 0.0) { - libm_sse2_sqrt_precise(); - } - else { - dVar4 = SQRT(dVar4); - } - fVar1 = (float)dVar4; - if (outHit != GHIDRA_CAST(0x0)) { - outHit->x = (outHit->x / fVar1) * ((float)local_1c - fVar1) + separationX; - outHit->y = (outHit->y / fVar1) * ((float)local_1c - fVar1) + separationY; - } - } - return 1; -} diff --git a/generated-src/classes.h b/generated-src/classes.h index 34f7e4c..e0ded33 100644 --- a/generated-src/classes.h +++ b/generated-src/classes.h @@ -138,6 +138,7 @@ struct BackdropConfig; struct BackwardsStageDesc; struct BeamRenderer; struct BeastArena; +struct BezierPoint; struct BitSet128; struct BlendMode; struct BombCostumeRule; @@ -148,6 +149,7 @@ struct BossPool; struct BossPoolState; struct BossPool_Entry; struct BossPool_Pool; +struct BrimstoneShot; struct BufferedStream; struct ButterBeanFart; struct CLIENT_ID; @@ -205,8 +207,10 @@ struct DeathmatchTypeSumo; struct DeathmatchTypeSwordFight; struct DeathmatchTypeVenom; struct DebugRenderer; +struct DeliriousBoss; struct DestinationQuad; struct Devolve; +struct EffectBehaviour; struct EmoteWheel; struct Entity; struct EntityConfig; @@ -259,6 +263,7 @@ struct File; struct FileSymbolInfo; struct FileSystem; struct FireEmber; +struct FollowingEffect; struct Font; struct FontCharBlock; struct FontGlyph; @@ -372,6 +377,8 @@ struct KerningPair; struct KeyConfigs; struct LRoomAreaDesc; struct LRoomTileDesc; +struct LaserShot; +struct LaserVolley; struct LayerAnimation; struct LayerData; struct LayerState; @@ -380,6 +387,7 @@ struct Level; struct LevelGenerator; struct LevelGenerator_Room; struct LightSpawn; +struct LineCheck; struct Lobby; struct LobbyList; struct LobbyLocalhost; @@ -513,6 +521,7 @@ struct ProjectileShooter; struct Quad; struct QueueItemData; struct RNG; +struct RadiusDamage; struct RailManager; struct RainSpawner; struct RebirthSaveData; @@ -555,6 +564,7 @@ struct SavedRoom; struct ScoreRecord; struct ScoreSheet; struct Seeds; +struct SegmentProjection; struct Shader; struct Shape; struct SharedPtr; @@ -566,6 +576,7 @@ struct ShopOffer; struct ShopRestock; struct SimpleString; struct Size; +struct SkinColors; struct SmeltedTrinket; struct SoundEffect; struct SoundEffects; @@ -595,6 +606,7 @@ struct StringTableCategory; struct SubtitleCue; struct TargetSearch; struct TearParams; +struct TechLaserShot; struct TemporaryEffect; struct TemporaryEffects; struct TextMeasure; @@ -1019,14 +1031,6 @@ LAYOUT32(offsetof(CLIENT_ID, UniqueProcess) == 0x0); LAYOUT32(offsetof(CLIENT_ID, UniqueThread) == 0x4); LAYOUT32(sizeof(CLIENT_ID) == 0x8); -struct Capsule { - void constructor(Vector *position, Vector *multiplier, float rotation, float size); // 00945190 - void constructor2(Vector *Position, Vector *TargetPosition, float size); // 009452e0 - void get_bounding_box(Vector *outMin, Vector *outMax); // 00945400 - static uint8_t Collide(Capsule *a, Capsule *b, Vector *outHit); // 00945470 -}; - - struct Card { uint8_t IsCard(); // 005b1530 uint8_t IsRune(); // 005b1550 @@ -1549,36 +1553,6 @@ struct HallucinationOverlay { }; -struct HomingLaser { - HomingLaser * operator_assign(HomingLaser *other); // 0085e000 - HomingLaser(); // 0099c290 - void build_bezier_path(int homingType, Entity *source); // 0099c790 - void compute_axis_bezier_handles(); // 0099dca0 - void compute_bezier_handles(float tension); // 0099e160 - void CalculateSamples(float param_2); // 0099e360 - void apply_sine_offset(float amplitude, float phase); // 0099ec00 - void build_curl_path(float radius); // 0099fa60 - static void build_wiggle_bezier(); // 0099fed0 - uint8_t clip_samples_to_grid(Vector *pos, int gridCollisionClass); // 009a0520 - void truncate_samples_at_player(); // 009a0740 - void truncate_samples_at_obstacle(Vector *positionOffset); // 009a0c50 - void remove_collinear_samples(float tolerance); // 009a0de0 - void apply_sample_wiggle(float amplitude, float phase); // 009a0fa0 - static uint32_t find_targets(float *param_1, float *param_2, int param_3, uint32_t param_4, Entity *param_5); // 009a12b0 - uint8_t truncate_samples(float maxLength); // 009a1520 - - uint8_t _pad_0x0[0x1c]; - std_vector _samples; - std_vector _nonOptimizedSamples; - uint8_t _pad_0x34[0x10]; - float _totalLength; - uint8_t _bezier[0x4]; // std_vector -}; -LAYOUT32(offsetof(HomingLaser, _samples) == 0x1c); -LAYOUT32(offsetof(HomingLaser, _nonOptimizedSamples) == 0x28); -LAYOUT32(offsetof(HomingLaser, _totalLength) == 0x44); -LAYOUT32(offsetof(HomingLaser, _bezier) == 0x48); - struct ImageBase { uint8_t set_size(uint32_t width, uint32_t height, int unused); // 00a12d50 }; @@ -4089,34 +4063,6 @@ struct Weapon_Bone { }; LAYOUT32(sizeof(Weapon_Bone) == 0x60); -struct Weapon_Brimstone { - virtual ~Weapon_Brimstone(); // 009f9a20 slot 0 - virtual void Init(uint32_t param_2, uint32_t param_3); // 009f34d0 slot 1 Weapon::Init - virtual void Update(char param_2); // 009f34f0 slot 2 Weapon::Update - virtual void Fire(Vector *direction, uint8_t isShooting, uint8_t isInterpolated); // 009ff360 slot 3 - virtual void Reset(); // 009f3480 slot 4 Weapon::Reset - virtual void ClearReferences(); // 00a02790 slot 5 - virtual long double GetMaxCharge(); // 00a00f30 slot 6 - virtual long double GetChargeBarAmount(); // 009f4150 slot 7 Weapon::GetChargeBarAmount - virtual void vfunc_8(); // 009f3130 slot 8 Weapon::GetMaxCharge - virtual uint32_t GetFocusEntity(); // 00a02870 slot 9 - virtual uint32_t GetMainEntity(); // 009f3160 slot 10 - virtual void guard_check_icall(); // 0040c200 slot 11 ::guard_check_icall - virtual int GetMarkedTargetVariant(); // 00a02800 slot 12 - virtual uint8_t CanShutDoors(); // 005ccc00 slot 13 Entity::CanShutDoors - virtual uint8_t CanTriggerCursedEyeTeleport(); // 005ccc00 slot 14 Entity::CanShutDoors - virtual uint8_t CanTriggerKidneyStone(); // 005ccc00 slot 15 Entity::CanShutDoors - virtual uint8_t CanOverrideForgottenThrow(); // 005ccc00 slot 16 Entity::CanShutDoors - void fire_c_section_fetuses(); // 00a00d10 - void init_laser(Entity_Laser *laser); // 00a00f90 - void fire(float Speed, uint8_t IgnoreStatusEffects); // 00a02890 - - uint8_t _pad_0x4[0x44]; - uint8_t _mainLaser[0x4]; // EntityPtr -}; -LAYOUT32(offsetof(Weapon_Brimstone, _mainLaser) == 0x48); -LAYOUT32(sizeof(Weapon_Brimstone) == 0x4c); - struct Weapon_Deathmatch { virtual ~Weapon_Deathmatch(); // 009f3260 slot 0 virtual void Init(uint32_t param_2, uint32_t param_3); // 009f34d0 slot 1 Weapon::Init @@ -4187,30 +4133,6 @@ struct Weapon_Knife { }; LAYOUT32(sizeof(Weapon_Knife) == 0x54); -struct Weapon_Laser { - virtual ~Weapon_Laser(); // 009f9930 slot 0 - virtual void Init(uint32_t param_2, uint32_t param_3); // 009f34d0 slot 1 Weapon::Init - virtual void Update(char param_2); // 009f34f0 slot 2 Weapon::Update - virtual void Fire(Vector *param_1, uint8_t param_2, uint8_t param_3); // 00a052b0 slot 3 - virtual void Reset(); // 00a052a0 slot 4 - virtual void ClearReferences(); // 00a063b0 slot 5 - virtual long double GetMaxCharge(); // 00a06870 slot 6 - virtual long double GetChargeBarAmount(); // 009f4150 slot 7 Weapon::GetChargeBarAmount - virtual void vfunc_8(); // 009f3130 slot 8 Weapon::GetMaxCharge - virtual Entity * GetFocusEntity(); // 009fa190 slot 9 Weapon_Bombs::GetFocusEntity - virtual Entity * GetMainEntity(); // 009f3150 slot 10 Weapon::GetMainEntity - virtual void guard_check_icall(); // 0040c200 slot 11 ::guard_check_icall - virtual int GetMarkedTargetVariant(); // 00a02800 slot 12 Weapon_Brimstone::GetMarkedTargetVariant - virtual uint8_t CanShutDoors(); // 005ccc00 slot 13 Entity::CanShutDoors - virtual uint8_t CanTriggerCursedEyeTeleport(); // 00a068e0 slot 14 - virtual uint8_t SupportsTractorBeam(); // 00a05060 slot 15 Weapon_Knife::SupportsTractorBeam - virtual void vfunc_16(); // 005ccc00 slot 16 Entity::CanShutDoors - static void init_laser(Weapon *weapon, Entity_Laser *laser); // 00a06330 - - uint8_t _pad_0x4[0x4c]; -}; -LAYOUT32(sizeof(Weapon_Laser) == 0x50); - struct Weapon_Ludovico { virtual ~Weapon_Ludovico(); // 009f9880 slot 0 Weapon_Bombs::Free virtual void Init(uint32_t param_2, uint32_t param_3); // 009f34d0 slot 1 Weapon::Init @@ -4304,29 +4226,6 @@ struct Weapon_SpiritSword { }; LAYOUT32(sizeof(Weapon_SpiritSword) == 0x50); -struct Weapon_TechX { - virtual ~Weapon_TechX(); // 009f3260 slot 0 - virtual void Init(uint32_t param_2, uint32_t param_3); // 009f34d0 slot 1 Weapon::Init - virtual void Update(char param_2); // 009f34f0 slot 2 Weapon::Update - virtual void Fire(Vector *direction, uint8_t isShooting, uint8_t isInterpolated); // 00a0d9c0 slot 3 - virtual void Reset(); // 009f3480 slot 4 Weapon::Reset - virtual void ClearReferences(); // 009f3320 slot 5 Weapon::ClearReferences - virtual float GetMaxCharge(); // 00a0e260 slot 6 - virtual long double GetChargeBarAmount(); // 009f4150 slot 7 Weapon::GetChargeBarAmount - virtual void vfunc_8(); // 009f3130 slot 8 Weapon::GetMaxCharge - virtual uint32_t GetFocusEntity(); // 009f3140 slot 9 Weapon::GetFocusEntity - virtual void vfunc_10(); // 009f3140 slot 10 Weapon::GetFocusEntity - virtual void guard_check_icall(); // 0040c200 slot 11 ::guard_check_icall - virtual uint32_t GetMarkedTargetVariant(); // 00a08cd0 slot 12 Weapon_MonstrosLung::GetMarkedTargetVariant - virtual uint8_t CanTakeDamageFromTearEffects(); // 00709c30 slot 13 GridEntity::CanTakeDamageFromTearEffects - virtual uint8_t CanShutDoors(); // 005ccc00 slot 14 Entity::CanShutDoors - virtual void vfunc_15(); // 00709c30 slot 15 GridEntity::CanTakeDamageFromTearEffects - virtual void vfunc_16(); // 005ccc00 slot 16 Entity::CanShutDoors - - uint8_t _pad_0x4[0x40]; -}; -LAYOUT32(sizeof(Weapon_TechX) == 0x44); - struct Weapon_UmbilicalWhip { virtual ~Weapon_UmbilicalWhip(); // 009f9880 slot 0 Weapon_Bombs::Free virtual void Init(uint32_t param_2, uint32_t param_3); // 009f34d0 slot 1 Weapon::Init @@ -6226,8 +6125,6 @@ void FUN_004cdce0(); // 004cdce0 uint32_t FUN_004ce0f0(); // 004ce0f0 void FUN_004cf0f0(uint8_t param_1); // 004cf0f0 void FUN_004cf380(int *param_1); // 004cf380 -void FUN_004d2f50(int param_1); // 004d2f50 -void FUN_004d2fd0(int param_1); // 004d2fd0 void FUN_004d3050(); // 004d3050 void FUN_004d3230(uint32_t *param_1); // 004d3230 void FUN_004d4210(int param_1, char param_2); // 004d4210 @@ -6512,7 +6409,6 @@ void FUN_00631a00(float *param_1, uint32_t param_2, float *param_3); // 00631a0 void familiar_wisp_pick_tear_color(RNG *rng, int *outVariant, BitSet128 *outFlags); // 00633990 void FUN_00638e20(); // 00638e20 void spawn_blue_spider(Vector *position, Entity *spawner, Vector *target); // 00638e30 -Entity * spawn_dip_at(int subType, Vector *position, Entity *spawner, Vector *targetPosition); // 006393a0 void FUN_006395e0(Vector *param_1, int *param_2, int param_3, int param_4, int param_5, float param_6, int param_7, int param_8, Entity *param_9, int param_10); // 006395e0 void FUN_0063b240(); // 0063b240 void FUN_0063c060(int param_1); // 0063c060 @@ -6597,7 +6493,6 @@ uint8_t FUN_0067efd0(); // 0067efd0 float random_float(); // 0067efe0 uint32_t FUN_0067f030(); // 0067f030 void FUN_0067f2e0(); // 0067f2e0 -void * string_split(void *outTokens, std_string *text, uint8_t delimiter); // 0067f420 uint8_t string_to_bool(void *self); // 0067f600 void ResolveRelativePath(uint8_t *anmPath, uint8_t *relPath, uint8_t *outPath); // 0067f670 void ExtractAngleBracketText(); // 0067fdf0 @@ -6606,9 +6501,6 @@ void FUN_00682260(); // 00682260 void shader_stack_push(int shaderIndex); // 00682280 void FUN_00682350(); // 00682350 float normalize_angle_degrees(float angle); // 00682740 -float angle_difference(float from, float to); // 006827a0 -void FUN_00682a20(); // 00682a20 -float approach_angle(float current, float target, float maxStep); // 00682a50 uint32_t checksum_stream(void *stream, int offset, int trailingSize); // 00683580 void FUN_00683680(); // 00683680 void pop_render_target(); // 006836c0 @@ -6753,7 +6645,6 @@ void FUN_006a7ec0(); // 006a7ec0 void FUN_006a80d0(); // 006a80d0 void FUN_006a8180(uint32_t param_1); // 006a8180 void FUN_006a8210(int param_1); // 006a8210 -uint32_t FUN_006ae7a0(); // 006ae7a0 void FUN_006b5de0(); // 006b5de0 void FUN_006b5f40(); // 006b5f40 void play_sound_with_fart_seed(int soundId, float volume, int frameDelay, uint8_t isLoop, float pitch); // 006b6470 @@ -6859,7 +6750,6 @@ void FUN_00709850(); // 00709850 void FUN_007098c0(); // 007098c0 void FUN_00709930(); // 00709930 int FUN_00709bc0(); // 00709bc0 -bool FUN_0070be60(); // 0070be60 uint8_t FUN_0070bf60(); // 0070bf60 uint8_t is_grid_type_floor_special(int gridType); // 0070bf80 void FUN_0070bfa0(int param_1, int param_2, uint32_t param_3, float param_4); // 0070bfa0 @@ -7030,7 +6920,6 @@ void FUN_007c2e80(); // 007c2e80 uint8_t FUN_007c7b10(uint32_t param_1, int param_2); // 007c7b10 char FUN_007c9080(); // 007c9080 void FUN_007cb4f0(); // 007cb4f0 -void FUN_007cdee0(); // 007cdee0 uint8_t teleport_to_random_room_of_types(Entity_Player *player, void *roomTypes, uint8_t isPreferUnvisited); // 007cdf30 void FUN_007cf940(); // 007cf940 long double FUN_007cf9a0(float *param_1, KColor *param_2, uint32_t param_3); // 007cf9a0 @@ -7147,7 +7036,6 @@ void FUN_007e92e0(uint32_t param_1, uint32_t param_2); // 007e92e0 void FUN_007e93d0(int param_1); // 007e93d0 void FUN_007ea0c0(); // 007ea0c0 void FUN_007ebc40(); // 007ebc40 -float get_angel_room_chance(); // 007f96f0 void FUN_00812ea0(float *param_1, int *param_2, int *param_3); // 00812ea0 uint32_t FUN_00813420(int param_1, int param_2); // 00813420 uint32_t FUN_0081e220(); // 0081e220 @@ -7167,7 +7055,6 @@ void FUN_00828890(uint32_t *param_1, float *param_2); // 00828890 void FUN_00828a70(void *param_1, int param_2); // 00828a70 void FUN_00828ab0(); // 00828ab0 void FUN_00828b10(); // 00828b10 -uint8_t * FUN_008295c0(); // 008295c0 void FUN_00829920(uint32_t *param_1); // 00829920 uint32_t FUN_008299e0(short *param_1, short *param_2); // 008299e0 void FUN_0082a920(uint32_t *param_1); // 0082a920 @@ -7339,7 +7226,6 @@ uint8_t * Catch_00864e6d(); // 00864e6d uint32_t Catch_0086504e(); // 0086504e uint32_t Catch_0086512e(); // 0086512e uint8_t * Catch_008655b7(); // 008655b7 -char * FUN_00865660(char *param_1, uint32_t *param_2); // 00865660 void FUN_00865aad(); // 00865aad void FUN_00865c61(); // 00865c61 uint32_t Catch_00866364(); // 00866364 @@ -8039,37 +7925,6 @@ void FUN_00896690(uint32_t param_1, uint32_t param_2); // 00896690 void FUN_008966f0(uint32_t param_1, uint32_t param_2); // 008966f0 void FUN_00896750(uint32_t param_1, uint32_t param_2); // 00896750 void FUN_008967b0(); // 008967b0 -void FUN_00896820(float param_1); // 00896820 -uint32_t * FUN_008968b0(uint32_t param_1, uint32_t param_2, int param_3); // 008968b0 -void FUN_008969f0(float param_1); // 008969f0 -void FUN_00896a60(float param_1); // 00896a60 -void FUN_00896ac0(uint8_t param_1); // 00896ac0 -uint32_t * FUN_00896ae0(uint32_t param_1, uint32_t param_2, int param_3); // 00896ae0 -void FUN_00896c20(uint8_t param_1); // 00896c20 -void FUN_00896c50(float param_1); // 00896c50 -void FUN_00896cb0(int param_1); // 00896cb0 -uint32_t * FUN_00896cf0(uint32_t param_1, uint32_t param_2, int param_3); // 00896cf0 -void FUN_00896e30(int param_1); // 00896e30 -void FUN_00896e80(int param_1); // 00896e80 -void FUN_00896ed0(float param_1); // 00896ed0 -void FUN_00896f30(uint8_t param_1); // 00896f30 -void FUN_00896f60(uint8_t param_1); // 00896f60 -void FUN_00896f90(uint8_t param_1); // 00896f90 -void FUN_00896fc0(uint8_t param_1); // 00896fc0 -void FUN_00896ff0(uint32_t param_1); // 00896ff0 -void FUN_00897020(uint8_t param_1); // 00897020 -void FUN_00897050(uint8_t param_1); // 00897050 -void FUN_00897090(int param_1); // 00897090 -void FUN_008970e0(uint32_t param_1); // 008970e0 -uint32_t * FUN_00897120(uint32_t param_1, uint32_t param_2, int param_3); // 00897120 -void FUN_00897260(uint32_t param_1); // 00897260 -void FUN_008972b0(uint32_t param_1); // 008972b0 -void FUN_008972e0(uint8_t param_1); // 008972e0 -void FUN_00897310(uint8_t param_1); // 00897310 -void FUN_00897340(uint8_t param_1); // 00897340 -void FUN_00897370(uint8_t param_1); // 00897370 -void FUN_008973a0(int param_1); // 008973a0 -uint32_t * FUN_008973e0(); // 008973e0 uint32_t FUN_00897500(); // 00897500 void FUN_008975b0(uint32_t param_1, uint32_t param_2); // 008975b0 void FUN_00897620(int param_1); // 00897620 @@ -9450,8 +9305,6 @@ uint32_t FUN_0095fd40(); // 0095fd40 uint32_t * FUN_00960880(void *param_1, uint32_t *param_2); // 00960880 void FUN_00960bc0(); // 00960bc0 uint32_t FUN_00961ad0(); // 00961ad0 -int FUN_0096ce70(); // 0096ce70 -uint32_t FUN_0096cf40(); // 0096cf40 void FUN_0096d120(int *param_1); // 0096d120 uint32_t FUN_0097e7c0(); // 0097e7c0 void pressure_plate_kill_enemies_timer_callback(int *param_1); // 00983f30 @@ -9469,9 +9322,7 @@ uint32_t * FUN_009983f0(uint32_t *param_1); // 009983f0 void netplay_player_list_destructor(void *self); // 00998800 void FUN_0099a830(); // 0099a830 void FUN_0099c310(); // 0099c310 -void segment_project_point(Vector *point, Vector *start, Vector *end, float *outT); // 0099c340 float bezier_closest_point(Vector *point, void *segmentStart, void *segmentEnd, float *outT); // 0099c430 -void laser_sample_trace_entities(void *entity, int unused); // 0099f2c0 void ** vector_LaserSample_erase(void *self, void **outIter, void *where); // 009a1610 void FUN_009a1770(uint32_t *param_1); // 009a1770 void * vector_LaserSample_emplace_reallocate(void *self, void *where, void *value); // 009a17b0 @@ -9659,15 +9510,12 @@ Entity_Tear * fire_fetus_tear(void *self, Vector *position, Vector *velocity, in uint32_t * FUN_009f9080(); // 009f9080 uint32_t * FUN_009f90f0(); // 009f90f0 uint32_t * FUN_009f9170(); // 009f9170 -uint32_t * FUN_009f91f0(); // 009f91f0 uint32_t * FUN_009f92d0(); // 009f92d0 uint32_t * FUN_009f9350(); // 009f9350 uint32_t * FUN_009f93d0(); // 009f93d0 uint32_t * FUN_009f9440(); // 009f9440 -uint32_t * FUN_009f94c0(); // 009f94c0 uint32_t * FUN_009f9540(); // 009f9540 uint32_t * FUN_009f95d0(); // 009f95d0 -uint32_t * FUN_009f9640(); // 009f9640 uint32_t * FUN_009f96c0(); // 009f96c0 uint32_t * FUN_009f9740(); // 009f9740 uint32_t * FUN_00a06940(void *param_1, uint32_t *param_2); // 00a06940 @@ -21370,19 +21218,13 @@ void wisp_mine_crafter_update(Entity_Familiar *wisp); // 0043d850 Entity_Laser * sprinkler_fire_laser(Entity_Familiar *familiar, float angle, float distance); // 0063acf0 void fly_head_pathfind_move(Entity_Familiar *familiar); // 0063d570 } -namespace Input { -uint8_t IsMouseBtnPressed(int button); // 0086fdb0 -Vector * GetMousePosition(Vector *outPosition, uint8_t isGameCoords); // 0086fe50 -} namespace Isaac { void SwapANM2(ANM2 *left, ANM2 *right); // 00407ae0 ItemConfig * GetItemConfig(); // 0042ca00 void SpawnLocust(Entity_Player *player, int collectibleType, Vector *pos); // 005b35c0 int Random(int Max); // 0067f010 -Vector * GetAxisAlignedUnitVectorFromDir(Vector *outVector, int direction); // 0067f1d0 Vector * GetRandomPickupVelocity(Vector *outVelocity, Vector *position, uint32_t pickupVelType, RNG *rng); // 006ee440 Vector * GetCollectibleSpawnPosition(Vector *outPosition, Vector *target); // 006eeaa0 -void ScreenToWorld(float *param_1, float *param_2); // 00870160 void Shutdown(); // 009ab700 } namespace ItemInfo { @@ -21430,23 +21272,16 @@ void ENTITY_LIL_BLUB(Entity_NPC *npc); // 00450da0 void ENTITY_BIG_HORN_grab_bomb(Entity_NPC *npc); // 00452eb0 void ENTITY_BIG_HORN(Entity_NPC *npc); // 00453140 void ENTITY_FLY_isaac_spawned(Entity_NPC *npc); // 004568d0 -void ENTITY_FAMINE(Entity_NPC *npc); // 00456c40 -void ENTITY_PESTILENCE(Entity_NPC *npc); // 00457840 void ENTITY_WAR(Entity_NPC *npc); // 00458870 void ENTITY_DEATH(Entity_NPC *npc); // 00459d20 void ENTITY_FALLEN(Entity_NPC *npc); // 0045b830 void ENTITY_HEADLESS_HORSEMAN(Entity_NPC *npc); // 0045cd60 void ENTITY_DARK_ONE(Entity_NPC *npc); // 0045d7d0 void ENTITY_ADVERSARY(Entity_NPC *npc); // 0045e050 -void ENTITY_MEGA_MAW(Entity_NPC *npc); // 0045ef20 -void ENTITY_GATE(Entity_NPC *npc); // 0045fc00 void ENTITY_MEGA_FATTY(Entity_NPC *npc); // 00460780 void ENTITY_MASK_OF_INFAMY(Entity_NPC *npc); // 00461fc0 float ENTITY_ISAAC(Entity_NPC *npc); // 00463100 -void ENTITY_FISTULA_BIG(Entity_NPC *npc); // 00466600 -void ENTITY_LOKI(Entity_NPC *npc); // 00467670 void ENTITY_DADDYLONGLEGS(Entity_NPC *npc); // 00468180 -void ENTITY_WIDOW(Entity_NPC *npc); // 0046fbe0 void ENTITY_BLASTOCYST_BIG(Entity_NPC *npc); // 00472c40 void ENTITY_SLOTH(Entity_NPC *npc); // 004741f0 void ENTITY_LUST(Entity_NPC *npc); // 00474e00 @@ -21456,19 +21291,14 @@ void ENTITY_ENVY(Entity_NPC *npc); // 004760a0 void ENTITY_PIN(Entity_NPC *npc); // 00476860 void ENTITY_PRIDE(Entity_NPC *npc); // 00479d80 void ENTITY_CHUB(Entity_NPC *npc); // 0047a360 -void ENTITY_GURDY(Entity_NPC *npc); // 0047c850 -void ENTITY_PEEP(Entity_NPC *npc); // 0047d8a0 Entity_NPC * ENTITY_SATAN(Entity_NPC *npc); // 0047f640 -void ENTITY_THE_HAUNT(Entity_NPC *npc); // 00481410 void ENTITY_THE_LAMB(Entity_NPC *npc); // 00483710 void ENTITY_MR_FRED(Entity_NPC *npc); // 00486db0 void ENTITY_CAGE(Entity_NPC *npc); // 004878a0 -void ENTITY_POLYCEPHALUS(Entity_NPC *npc); // 00489ca0 void ENTITY_MAMA_GURDY(Entity_NPC *npc); // 0048ae30 void ENTITY_BROWNIE(Entity_NPC *npc); // 0048c3b0 void ENTITY_CORN_MINE(Entity_NPC *npc); // 0048ee30 void ENTITY_FORSAKEN(Entity_NPC *npc); // 0048f110 -void ENTITY_PITFALL(Entity_NPC *npc); // 00492550 void ENTITY_RAG_MAN(Entity_NPC *npc); // 00493200 void ENTITY_RAG_MEGA(Entity_NPC *npc); // 00495610 void ENTITY_SISTERS_VIS(Entity_NPC *npc); // 00496fb0 @@ -21497,7 +21327,6 @@ void ENTITY_MEGA_SATAN(Entity_NPC *npc); // 004c8090 void ENTITY_MEGA_SATAN_hand(Entity_NPC *npc); // 004cca10 void ENTITY_MINECART(Entity_NPC *npc); // 004ce8a0 void ENTITY_MIN_MIN(Entity_NPC *npc); // 004cf690 -void ENTITY_MOM(Entity_NPC *npc); // 004d1290 void ENTITY_MOMS_HEART(Entity_NPC *npc); // 004d48b0 void ENTITY_MOMS_HEART_mausoleum_death(Entity_NPC *npc); // 004d64f0 void ENTITY_SMALL_MAGGOT(Entity_NPC *npc); // 004d77b0 @@ -21507,7 +21336,6 @@ Entity_Effect * ENTITY_TWITCHY(Entity_NPC *npc); // 004db6a0 void ENTITY_SPIKEBALL(Entity_NPC *npc); // 004dc490 void ENTITY_UNBORN(Entity_NPC *npc); // 004dca90 void * ENTITY_GASBAG(Entity_NPC *npc); // 004dd7f0 -void ENTITY_PUSTULE(Entity_NPC *npc); // 004dea40 void ENTITY_EVIS(Entity_NPC *npc); // 004df3f0 void ENTITY_GUTTED_FATTY(Entity_NPC *npc); // 004e0dd0 uint32_t ENTITY_GAPER_L2(Entity_NPC *npc); // 004e2b40 @@ -21547,19 +21375,14 @@ void ENTITY_BIG_BONY(Entity_NPC *npc); // 005041d0 void ENTITY_DUSTY_DEATHS_HEAD(Entity_NPC *npc); // 00504a40 void ENTITY_NECRO(Entity_NPC *npc); // 005052a0 void ENTITY_STONE_EYE(Entity_NPC *npc); // 00505d00 -void ENTITY_CONSTANT_STONE_SHOOTER(Entity_NPC *npc); // 00506320 -void ENTITY_ETERNALFLY(Entity_NPC *npc); // 0050a8a0 void ENTITY_KNIGHT(Entity_NPC *npc); // 005135d0 uint32_t * ENTITY_GUTS(Entity_NPC *npc); // 005153b0 void ENTITY_MRMAW(Entity_NPC *npc); // 00517de0 void ENTITY_SWARMER(Entity_NPC *npc); // 00518e20 -void ENTITY_GURGLE(Entity_NPC *npc); // 0051aaa0 void ENTITY_MEMBRAIN(Entity_NPC *npc); // 0051c040 void ENTITY_HANGER(Entity_NPC *npc); // 0051cb30 -void ENTITY_GURDY_JR(Entity_NPC *npc); // 0051d300 void ENTITY_URIEL(Entity_NPC *npc); // 0051e0f0 void ENTITY_HEART(Entity_NPC *npc); // 0051f2f0 -void ENTITY_STONEHEAD(Entity_NPC *npc); // 00520c60 void ENTITY_POKY(Entity_NPC *npc); // 00521ab0 void ENTITY_LUMP(Entity_NPC *npc); // 00522430 void ENTITY_EYE(Entity_NPC *npc); // 00522ef0 @@ -21574,17 +21397,13 @@ void ENTITY_COD_WORM(Entity_NPC *npc); // 00531350 void ENTITY_MOBILE_HOST(Entity_NPC *npc); // 005321d0 void ENTITY_DEATHS_HEAD(Entity_NPC *npc); // 00532cf0 void ENTITY_MOMS_HAND(Entity_NPC *npc); // 00533b80 -Entity * ENTITY_SQUIRT(Entity_NPC *npc); // 00535280 void ENTITY_SWINGER(Entity_NPC *npc); // 00536d00 void ENTITY_WIZOOB(Entity_NPC *npc); // 005374a0 void ENTITY_NERVE_ENDING(Entity_NPC *npc); // 00537e20 -void ENTITY_SKINBALL(Entity_NPC *npc); // 005381c0 void ENTITY_HOMUNCULUS(Entity_NPC *npc); // 00539b90 void ENTITY_OOB(Entity_NPC *npc); // 0053ab40 void ENTITY_BLACK_MAW(Entity_NPC *npc); // 0053b2f0 void ENTITY_WALL_CREEP(Entity_NPC *npc); // 0053c0d0 -void ENTITY_FAT_BAT(Entity_NPC *npc); // 00540510 -void ENTITY_DUKIE(Entity_NPC *npc); // 00541810 Entity_Effect * ENTITY_MEATBALL(Entity_NPC *npc); // 00541ce0 float ENTITY_BLISTER(Entity_NPC *npc); // 005430d0 float ENTITY_TARBOY(Entity_NPC *npc); // 005442a0 @@ -21675,34 +21494,6 @@ void render_items(float *param_1); // 008d4940 namespace OnlineStats { void compute_awards(); // 004254b0 } -namespace Options { -long double MusicVolume(); // 00896810 -long double SFXVolume(); // 008969e0 -long double MapOpacity(); // 00896a50 -uint32_t Fullscreen(); // 00896ab0 -uint32_t Filter(); // 00896c10 -long double Gamma(); // 00896c40 -int DisplayPopups(); // 00896ca0 -int CameraStyle(); // 00896e20 -int ExtraHUDStyle(); // 00896e70 -long double HUDOffset(); // 00896ec0 -uint32_t FoundHUD(); // 00896f20 -uint32_t RumbleEnabled(); // 00896f50 -uint32_t ChargeBars(); // 00896f80 -uint32_t BulletVisibility(); // 00896fb0 -uint32_t VSync(); // 00896fe0 -uint32_t PauseOnFocusLost(); // 00897010 -uint32_t MouseControl(); // 00897040 -int AnnouncerVoiceMode(); // 00897080 -int MaxScale(); // 008970d0 -int MaxRenderScale(); // 00897250 -int ConsoleFont(); // 008972a0 -uint32_t FadedConsoleDisplay(); // 008972d0 -uint32_t SaveCommandHistory(); // 00897300 -uint32_t UseBorderlessFullscreen(); // 00897330 -uint32_t DebugConsoleEnabled(); // 00897360 -int JacobEsauControls(); // 00897390 -} namespace RemovePlayerMessage { void read(int param_1, int *param_2); // 009163b0 } diff --git a/generated-src/homing_laser.cpp b/generated-src/homing_laser.cpp deleted file mode 100644 index 75b3729..0000000 --- a/generated-src/homing_laser.cpp +++ /dev/null @@ -1,2295 +0,0 @@ -#include "classes.h" - -// 0085e000 -HomingLaser * HomingLaser::operator_assign(HomingLaser *other) -{ - *GHIDRA_CAST(this) = *GHIDRA_CAST(other); - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))) = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((other)) + 0x4)))); - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x8)))) = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((other)) + 0x8)))); - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0xc)))) = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((other)) + 0xc)))); - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x10)))) = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((other)) + 0x10)))); - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x14)))) = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((other)) + 0x14)))); - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x18)))) = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((other)) + 0x18)))); - if (&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x1c))) != &(*GHIDRA_CAST((GHIDRA_CAST((other)) + 0x1c)))) { - msvc::vector::assign - (*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((other)) + 0x1c)))),*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((other)) + 0x20)))),other); - } - if (&this->_nonOptimizedSamples != &other->_nonOptimizedSamples) { - msvc::vector::assign - ((other->_nonOptimizedSamples)._begin,(other->_nonOptimizedSamples)._end,other); - } - if (&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x34))) != &(*GHIDRA_CAST((GHIDRA_CAST((other)) + 0x34)))) { - msvc::vector::assign - (*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((other)) + 0x34)))),*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((other)) + 0x38)))),other); - } - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x40)))) = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((other)) + 0x40)))); - this->_totalLength = other->_totalLength; - if (&this->_bezier != &other->_bezier) { - FUN_008c2910((other->_bezier)._begin,(other->_bezier)._end,other); - } - return this; -} - -// 0099c290 -HomingLaser::HomingLaser() -{ - *GHIDRA_CAST(this) = 0; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x8)))) = 0; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))) = 0; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x10)))) = 0; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0xc)))) = 0; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x1c)))) = 0; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x20)))) = 0; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x24)))) = 0; - (this->_nonOptimizedSamples)._begin = (void *)0x0; - (this->_nonOptimizedSamples)._end = (void *)0x0; - (this->_nonOptimizedSamples)._capacity = (void *)0x0; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x34)))) = 0; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x38)))) = 0; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x3c)))) = 0; - (this->_bezier)._begin = (void *)0x0; - (this->_bezier)._end = (void *)0x0; - (this->_bezier)._capacity = (void *)0x0; - return; -} - -// 0099c790 -void HomingLaser::build_bezier_path(int homingType, Entity *source) -{ - HomingLaser *bezierVec = this; - uint8_t *puVar1; - uint8_t bVar2; - BitSet128 *maskedFlags; - uint32_t *puVar3; - Vector *endPoint; - float *sample; - int playerSpawner; - float *dstSlot; - int bezierByteSize; - void *pvVar4; - RNG *srcSlot; - uint32_t *puVar5; - uint32_t entityIndex; - std_vector *bezierVec; - Entity *candidateIndex; - float fVar6; - float fVar7; - float fVar8; - float fVar9; - float fVar10; - Entity *pEVar11; - float fVar12; - Entity *pEVar13; - uint8_t occultMaskResult [8]; - Vector local_c0; - float targetDirY; - float targetDirX; - Vector local_ac; - Vector local_a4; - Vector local_9c; - uint32_t *targetsCapacity; - uint8_t tearFlags [8]; - Vector VStack_88; - float straightSampleX; - float straightSampleY; - float straightHandleX; - int *piStack_70; - uint32_t *local_6c; - uint32_t *puStack_68; - Entity *local_64; - uint32_t *local_60; - Entity *newSampleX; - Entity *newSampleY; - Entity *newHandleInX; - Entity *newHandleInY; - Entity *newHandleOutX; - Entity *newHandleOutY; - Entity *local_44; - Entity *local_40; - Entity *local_3c; - Entity *local_38; - Entity *local_34; - HomingLaser *self; - Entity *local_2c; - char local_25; - Entity *local_24; - uint8_t *puStack_20; - void *local_1c; - uint8_t *puStack_18; - uint32_t local_14; - Entity *bezierEnd; - void **bezierEndRef; - Entity *candidate; - int *eraseAt; - bool isEnemyFamiliar; - - puStack_20 = GHIDRA_CAST((GHIDRA_INT(register0x00000010) + -4)); - local_14 = 0xffffffff; - puStack_18 = &LAB_00b0d97d; - local_1c = ExceptionList; - ExceptionList = &local_1c; - sample = (bezierVec->_bezier)._end; - bezierVec = &bezierVec->_bezier; - bezierByteSize = GHIDRA_INT(sample) - GHIDRA_INT(bezierVec->_begin); - playerSpawner = bezierByteSize >> 0x1f; - local_ac.y = (float)bezierVec; - self = bezierVec; - puVar1 = GHIDRA_CAST((GHIDRA_INT(register0x00000010) + -4)); - if (bezierByteSize / 0x18 + playerSpawner == playerSpawner) { - straightSampleX = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((bezierVec)) + 0x4)))); - straightSampleY = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((bezierVec)) + 0x8)))); - local_6c = GHIDRA_CAST(((straightSampleX + *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((bezierVec)) + 0xc))))) * 0.5)); - puStack_68 = GHIDRA_CAST(((straightSampleY + *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((bezierVec)) + 0x10))))) * 0.5)); - if (sample == (bezierVec->_bezier)._capacity) { - straightHandleX = straightSampleX; - piStack_70 = GHIDRA_CAST(straightSampleY); - vector_LaserSample_emplace_reallocate(bezierVec,sample,&straightSampleX); - } - else { - *sample = straightSampleX; - sample[1] = straightSampleY; - sample[2] = straightSampleX; - sample[3] = straightSampleY; - *GHIDRA_CAST((sample + 4)) = CONCAT44(puStack_68,local_6c); - bezierEndRef = &(bezierVec->_bezier)._end; - *bezierEndRef = (void *)(GHIDRA_INT(*bezierEndRef) + 0x18); - puStack_20 = GHIDRA_CAST((GHIDRA_INT(register0x00000010) + -4)); - } - straightSampleX = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((bezierVec)) + 0xc)))); - straightSampleY = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((bezierVec)) + 0x10)))); - sample = (bezierVec->_bezier)._end; - straightHandleX = (straightSampleX + *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((bezierVec)) + 0x4))))) * 0.5; - piStack_70 = GHIDRA_CAST(((straightSampleY + *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((bezierVec)) + 0x8))))) * 0.5)); - if (sample == (bezierVec->_bezier)._capacity) { - local_6c = GHIDRA_CAST(straightSampleX); - puStack_68 = GHIDRA_CAST(straightSampleY); - vector_LaserSample_emplace_reallocate(bezierVec,sample,&straightSampleX); - puVar1 = puStack_20; - } - else { - *sample = straightSampleX; - sample[1] = straightSampleY; - sample[2] = straightHandleX; - sample[3] = (float)piStack_70; - sample[4] = straightSampleX; - sample[5] = straightSampleY; - bezierEndRef = &(bezierVec->_bezier)._end; - *bezierEndRef = (void *)(GHIDRA_INT(*bezierEndRef) + 0x18); - puVar1 = puStack_20; - } - } - puStack_20 = puVar1; - puVar5 = GHIDRA_CAST(0x0); - piStack_70 = GHIDRA_CAST(0x0); - local_60 = GHIDRA_CAST(0x0); - local_6c = GHIDRA_CAST(0x0); - targetsCapacity = GHIDRA_CAST(0x0); - puStack_68 = GHIDRA_CAST(0x0); - local_14 = 0; - if (homingType != 0) { - local_2c = g_game->_room; - if (*GHIDRA_CAST((GHIDRA_CAST(local_2c) + 0x1264)) != 0) { - entityIndex = 0; - do { - local_44 = *GHIDRA_CAST((*GHIDRA_CAST((GHIDRA_CAST(local_2c) + 0x125c)) + entityIndex * 4)); - local_24 = local_44; - bVar2 = Entity::IsVulnerableEnemy(local_44,GHIDRA_CAST(0x0)); - if ((((bVar2 == 0) || ((local_44->_flags & 0x20000010) != 0)) || (local_44 == source)) || - ((homingType == 4 && (local_44->_type == source->_type)))) { - local_25 = '\0'; - } - else { - local_25 = '\x01'; - } - if (((*GHIDRA_CAST(&g_game->_deathmatchManager) < 2) || (local_44->_type != 3)) || - ((local_44->_variant != 0x43 || - (bVar2 = Entity::IsDescendantOf(local_44,GHIDRA_CAST(source->_spawnerEntity)), bVar2 != 0)) - )) { - isEnemyFamiliar = false; - } - else { - isEnemyFamiliar = true; - } - pEVar11 = local_44; - if ((local_25 != '\0') || (isEnemyFamiliar)) { - if (puVar5 == targetsCapacity) { - msvc::vector::_Emplace_reallocate(puVar5,&local_24); - targetsCapacity = puStack_68; - pEVar11 = local_24; - puVar5 = local_6c; - } - else { - *puVar5 = local_44; - local_6c = puVar5 + 1; - puVar5 = local_6c; - } - } - if (((homingType == 5) && (pEVar11->_type == 1)) && (pEVar11 != source)) { - if (puVar5 == targetsCapacity) { - msvc::vector::_Emplace_reallocate(puVar5,&local_24); - targetsCapacity = puStack_68; - puVar5 = local_6c; - } - else { - *puVar5 = pEVar11; - local_6c = puVar5 + 1; - puVar5 = local_6c; - } - } - entityIndex = entityIndex + 1; - } while (entityIndex < *GHIDRA_CAST((GHIDRA_CAST(local_2c) + 0x1264))); - bezierVec = GHIDRA_CAST(local_ac.y); - local_60 = puVar5; - } - } - puVar5 = local_60; - local_2c = *GHIDRA_CAST(self); - if (local_2c != GHIDRA_CAST(0x0)) { - (*GHIDRA_CAST((GHIDRA_CAST(&(tearFlags)) + 0x0))) = SUB84(local_2c[1]._pendingDamageFlags,0); - (*GHIDRA_CAST((GHIDRA_CAST(&(tearFlags)) + 0x4))) = *GHIDRA_CAST((GHIDRA_INT(&local_2c[1]._pendingDamageFlags) + 4)); - VStack_88.x = (float)local_2c[1]._index; - VStack_88.y = (float)local_2c[1]._collisionIndex; - maskedFlags = BitSet128::operator_and - (GHIDRA_CAST(occultMaskResult),GHIDRA_CAST(tearFlags),&g_tearFlagOccult) - ; - if ((GHIDRA_INT(maskedFlags->_l) != 0 || *GHIDRA_CAST((GHIDRA_INT(&maskedFlags->_l) + 4)) != 0) || - (GHIDRA_INT(maskedFlags->_h) != 0 || *GHIDRA_CAST((GHIDRA_INT(&maskedFlags->_h) + 4)) != 0)) { - local_3c = GHIDRA_CAST((local_2c->_targetPosition).x); - local_44 = GHIDRA_CAST((local_2c->_targetPosition).y); - playerSpawner = local_2c->_spawnerEntity; - if ((playerSpawner == 0) || (*GHIDRA_CAST((playerSpawner + 0x28)) != 1)) { - playerSpawner = 0; - } - else { - bezierByteSize = *GHIDRA_CAST((playerSpawner + 0x140c)); - if (bezierByteSize != 0) { - local_3c = *GHIDRA_CAST((bezierByteSize + 0x33c)); - local_44 = *GHIDRA_CAST((bezierByteSize + 0x340)); - } - } - local_c0.x = (float)local_3c; - local_c0.y = (float)local_44; - if (((float)local_3c != g_vectorZero.x) || ((float)local_44 != g_vectorZero.y)) { - if (playerSpawner == 0) { - local_24 = GHIDRA_CAST(((float)local_3c - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((self)) + 0x4)))))); - local_2c = GHIDRA_CAST((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((self)) + 0xc)))) - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((self)) + 0x4)))))); - VStack_88.y = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((self)) + 0x10)))) - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((self)) + 0x8)))); - local_38 = GHIDRA_CAST(((float)local_44 - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((self)) + 0x8)))))); - local_34 = GHIDRA_CAST(sqrtf(VStack_88.y * VStack_88.y + (float)local_2c * (float)local_2c)); - if (0.0 < (float)local_34) { - fVar6 = sqrtf((float)local_38 * (float)local_38 + (float)local_24 * (float)local_24); - local_2c = GHIDRA_CAST(((float)local_2c * (fVar6 / (float)local_34))); - VStack_88.y = VStack_88.y * (fVar6 / (float)local_34); - } - fVar6 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((self)) + 0x4)))); - fVar8 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((self)) + 0x8)))); - fVar10 = (fVar6 + (float)local_2c) - fVar6; - fVar12 = (fVar8 + VStack_88.y) - fVar8; - fVar7 = fVar10 * 0.333 + fVar6; - fVar9 = fVar12 * 0.333 + fVar8; - local_34 = GHIDRA_CAST(((((float)local_24 * 0.333 + fVar6) - fVar7) * 0.333 + fVar7)); - local_2c = GHIDRA_CAST(((((float)local_38 * 0.333 + fVar8) - fVar9) * 0.333 + fVar9)); - fVar7 = fVar10 * 0.666 + fVar6; - fVar9 = fVar12 * 0.666 + fVar8; - local_24 = GHIDRA_CAST(((((float)local_24 * 0.666 + fVar6) - fVar7) * 0.666 + fVar7)); - local_38 = GHIDRA_CAST(((((float)local_38 * 0.666 + fVar8) - fVar9) * 0.666 + fVar9)); - VStack_88.x = (float)local_3c - (float)local_24; - VStack_88.y = (float)local_44 - (float)local_38; - endPoint = Entity_Laser::CalculateEndPoint - (&local_a4,&local_c0,&VStack_88,&g_vectorZero,GHIDRA_CAST(0x0),20.0); - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((self)) + 0xc)))) = endPoint->x; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((self)) + 0x10)))) = endPoint->y; - puVar3 = bezierVec->_begin; - bezierVec->_end = puVar3; - newSampleY = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((self)) + 0x8)))); - newSampleX = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((self)) + 0x4)))); - newHandleOutX = local_34; - newHandleOutY = local_2c; - if (puVar3 == bezierVec->_capacity) { - newHandleInX = newSampleX; - newHandleInY = newSampleY; - vector_LaserSample_emplace_reallocate(bezierVec,puVar3,&newSampleX); - sample = (self->_bezier)._end; - } - else { - *puVar3 = newSampleX; - puVar3[1] = newSampleY; - puVar3[2] = newSampleX; - puVar3[3] = newSampleY; - *GHIDRA_CAST((puVar3 + 4)) = CONCAT44(local_2c,local_34); - bezierVec->_end = (void *)(GHIDRA_INT(bezierVec->_end) + 0x18); - sample = bezierVec->_end; - } - newHandleInX = local_24; - newSampleX = local_3c; - newHandleOutX = - GHIDRA_CAST(((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((self)) + 0xc)))) - (float)local_3c) * 0.333 + (float)local_3c)); - newSampleY = local_44; - newHandleInY = local_38; - newHandleOutY = - GHIDRA_CAST(((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((self)) + 0x10)))) - (float)local_44) * 0.333 + (float)local_44)) - ; - if (sample == bezierVec->_capacity) { - vector_LaserSample_emplace_reallocate(bezierVec,sample,&newSampleX); - } - else { - *sample = (float)local_3c; - sample[1] = (float)local_44; - sample[2] = (float)local_24; - sample[3] = (float)local_38; - *GHIDRA_CAST((sample + 4)) = CONCAT44(newHandleOutY,newHandleOutX); - bezierVec->_end = (void *)(GHIDRA_INT(bezierVec->_end) + 0x18); - } - newSampleX = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((self)) + 0xc)))); - newSampleY = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((self)) + 0x10)))); - newHandleInX = GHIDRA_CAST((((float)newSampleX - (float)local_3c) * 0.666 + (float)local_3c)) - ; - newHandleInY = GHIDRA_CAST((((float)newSampleY - (float)local_44) * 0.666 + (float)local_44)) - ; - newHandleOutX = newSampleX; - newHandleOutY = newSampleY; - FUN_009a1770(&newSampleX); - } - else { - local_9c.y = (float)((GHIDRA_INT(bezierVec->_end) - GHIDRA_INT(bezierVec->_begin)) / 0x18); - playerSpawner = GHIDRA_INT(local_9c.y) * 0x18; - if (GHIDRA_UINT(local_9c.y) < 2) { - local_38 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((self)) + 0x4)))); - local_24 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((self)) + 0x8)))); - if (local_9c.y == 0.0) { - puVar3 = GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((self)) + 0xc)))); - } - else { - puVar3 = GHIDRA_CAST((GHIDRA_INT(bezierVec->_begin) + playerSpawner + -0x18)); - } - } - else { - pvVar4 = bezierVec->_begin; - local_38 = *GHIDRA_CAST((GHIDRA_CAST(pvVar4) + playerSpawner + -0x30)); - local_24 = *GHIDRA_CAST((GHIDRA_CAST(pvVar4) + playerSpawner + -0x2c)); - puVar3 = GHIDRA_CAST((GHIDRA_INT(pvVar4) + playerSpawner + -0x18)); - } - local_c0.y = (float)*puVar3; - local_2c = GHIDRA_CAST(puVar3[1]); - targetDirX = (float)local_3c - (float)local_38; - targetDirY = (float)local_44 - (float)local_24; - fVar6 = sqrtf(targetDirX * targetDirX + targetDirY * targetDirY); - if (0.0 < fVar6) { - targetDirX = (1.0 / fVar6) * targetDirX; - targetDirY = targetDirY * (1.0 / fVar6); - } - local_a4.y = local_c0.y - (float)local_3c; - VStack_88.y = (float)local_2c - (float)local_44; - fVar6 = sqrtf(local_a4.y * local_a4.y + VStack_88.y * VStack_88.y); - if (0.0 < fVar6) { - local_a4.y = local_a4.y * (1.0 / fVar6); - VStack_88.y = VStack_88.y * (1.0 / fVar6); - } - local_64 = GHIDRA_CAST((local_c0.y - (float)local_38)); - local_40 = GHIDRA_CAST(((float)local_2c - (float)local_24)); - fVar6 = sqrtf((float)local_64 * (float)local_64 + (float)local_40 * (float)local_40); - if (0.0 < fVar6) { - local_64 = GHIDRA_CAST(((float)local_64 * (1.0 / fVar6))); - local_40 = GHIDRA_CAST(((float)local_40 * (1.0 / fVar6))); - } - if (1 < GHIDRA_UINT(local_9c.y)) { - bezierEndRef = &(self->_bezier)._end; - *bezierEndRef = (void *)(GHIDRA_INT(*bezierEndRef) + -0x18); - } - if (bezierVec->_begin == bezierVec->_end) { - local_9c.y = (float)local_64 * 50.0; - newHandleOutY = GHIDRA_CAST(((float)local_40 * 50.0 + (float)local_24)); - newSampleX = local_38; - newHandleOutX = GHIDRA_CAST((local_9c.y + (float)local_38)); - newSampleY = local_24; - newHandleInX = local_38; - newHandleInY = local_24; - FUN_009a1770(&newSampleX); - } - else { - local_9c.y = (float)local_64 * 50.0; - } - local_34 = GHIDRA_CAST(cos(1.5707964)); - fVar6 = sin(1.5707964); - sample = bezierVec->_end; - newSampleX = (Entity *) - (((float)local_34 * (float)local_64 - fVar6 * (float)local_40) + - (float)local_64 * 35.0 + (float)local_38); - newSampleY = (Entity *) - (fVar6 * (float)local_64 + (float)local_34 * (float)local_40 + - (float)local_40 * 35.0 + (float)local_24); - newHandleOutX = GHIDRA_CAST((targetDirX * 50.0 + (float)newSampleX)); - local_40 = GHIDRA_CAST(((float)local_40 * 50.0)); - newHandleOutY = GHIDRA_CAST((targetDirY * 50.0 + (float)newSampleY)); - newHandleInX = GHIDRA_CAST(((float)newSampleX - local_9c.y)); - newHandleInY = GHIDRA_CAST(((float)newSampleY - (float)local_40)); - if (sample == bezierVec->_capacity) { - vector_LaserSample_emplace_reallocate(bezierVec,sample,&newSampleX); - sample = (self->_bezier)._end; - } - else { - *sample = (float)newSampleX; - sample[1] = (float)newSampleY; - sample[2] = (float)newHandleInX; - sample[3] = (float)newHandleInY; - *GHIDRA_CAST((sample + 4)) = CONCAT44(newHandleOutY,newHandleOutX); - bezierVec->_end = (void *)(GHIDRA_INT(bezierVec->_end) + 0x18); - sample = bezierVec->_end; - } - newHandleOutY = GHIDRA_CAST(((float)local_40 + (float)local_44)); - newHandleOutX = GHIDRA_CAST((local_9c.y + (float)local_3c)); - newHandleInY = GHIDRA_CAST(((float)local_44 - (float)local_40)); - newSampleX = local_3c; - newHandleInX = GHIDRA_CAST(((float)local_3c - local_9c.y)); - newSampleY = local_44; - if (sample == bezierVec->_capacity) { - vector_LaserSample_emplace_reallocate(bezierVec,sample,&newSampleX); - puVar3 = (self->_bezier)._end; - } - else { - *sample = (float)local_3c; - sample[1] = (float)local_44; - sample[2] = (float)newHandleInX; - sample[3] = (float)newHandleInY; - *GHIDRA_CAST((sample + 4)) = CONCAT44(newHandleOutY,newHandleOutX); - bezierVec->_end = (void *)(GHIDRA_INT(bezierVec->_end) + 0x18); - puVar3 = bezierVec->_end; - } - newHandleInX = GHIDRA_CAST((local_c0.y - local_a4.y * 50.0)); - newSampleX = GHIDRA_CAST(local_c0.y); - newSampleY = local_2c; - newHandleInY = GHIDRA_CAST(((float)local_2c - VStack_88.y * 50.0)); - newHandleOutX = GHIDRA_CAST(local_c0.y); - newHandleOutY = local_2c; - if (puVar3 == bezierVec->_capacity) { - vector_LaserSample_emplace_reallocate(bezierVec,puVar3,&newSampleX); - compute_axis_bezier_handles(self); - } - else { - *puVar3 = local_c0.y; - puVar3[1] = local_2c; - puVar3[2] = newHandleInX; - puVar3[3] = newHandleInY; - puVar3[4] = local_c0.y; - puVar3[5] = local_2c; - bezierVec->_end = (void *)(GHIDRA_INT(bezierVec->_end) + 0x18); - compute_axis_bezier_handles(self); - } - } - } - } - } - if (homingType == 1) { - local_44 = bezierVec->_end; - local_24 = bezierVec->_begin; - if ((GHIDRA_INT(local_44) - GHIDRA_INT(local_24)) - 0x30U < 0x18) { - do { - VStack_88.y = 0.0; - local_25 = '\0'; - if ((GHIDRA_INT(local_44) - GHIDRA_INT(local_24)) / 0x18 == 1) break; - local_a4.y = 0.0; - do { - pEVar11 = GHIDRA_CAST(local_a4.y); - if (local_25 != '\0') goto LAB_0099d600; - fVar8 = *GHIDRA_CAST((GHIDRA_INT((GHIDRA_INT(local_a4.y) + 0x18)) + GHIDRA_INT(local_24))) - - *GHIDRA_CAST((GHIDRA_INT((&(local_24->_sprite)._filename + 5)) + - GHIDRA_INT((GHIDRA_CAST((GHIDRA_INT(local_a4.y) + 0x48)) + -1)) + 0xc)); - fVar6 = *GHIDRA_CAST((GHIDRA_CAST((GHIDRA_INT((GHIDRA_INT(local_a4.y) + 0x18)) + 4)) + GHIDRA_INT(local_24))) - - *GHIDRA_CAST((GHIDRA_CAST((GHIDRA_INT(local_a4.y) + 4)) + GHIDRA_INT(local_24))); - if (14400.0 <= fVar6 * fVar6 + fVar8 * fVar8) { - local_34 = GHIDRA_CAST((GHIDRA_INT(local_60) - GHIDRA_INT(piStack_70) >> 2)); - local_2c = GHIDRA_CAST(0x0); - if (local_34 != GHIDRA_CAST(0x0)) { -LAB_0099d384: - pvVar4 = (void *)(GHIDRA_INT(bezierVec->_begin) + - GHIDRA_INT((&(GHIDRA_CAST((GHIDRA_INT(pEVar11) + 0x48)))->_filename + -3))); - local_9c.x = *GHIDRA_CAST((piStack_70[GHIDRA_INT(local_2c)] + 0x33c)); - local_9c.y = *GHIDRA_CAST((piStack_70[GHIDRA_INT(local_2c)] + 0x340)); - fVar7 = bezier_closest_point - (&local_9c,pvVar4,(void *)(GHIDRA_INT(pvVar4) + 0x18),GHIDRA_CAST(0x0)); - fVar8 = g_vectorZero.y; - fVar6 = g_vectorZero.x; - if (*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((self)) + 0x14)))) * *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((self)) + 0x14)))) <= fVar7) - goto LAB_0099d46a; - pvVar4 = bezierVec->_begin; - fVar7 = *GHIDRA_CAST((GHIDRA_INT(pvVar4) + - GHIDRA_INT((&(GHIDRA_CAST((GHIDRA_INT(pEVar11) + 0x48)))->_filename + -3)) + 4)); - fVar9 = *GHIDRA_CAST((GHIDRA_INT(pvVar4) + - GHIDRA_INT((&(GHIDRA_CAST((GHIDRA_INT(pEVar11) + 0x48)))->_filename + -3)))); - if ((((*GHIDRA_CAST((GHIDRA_INT(pvVar4) + - GHIDRA_INT((&(GHIDRA_CAST((GHIDRA_INT(pEVar11) + 0x48)))->_filename + -3)) + 0x14)) - - fVar7) * (local_9c.y - fVar7) + - (local_9c.x - fVar9) * - (*GHIDRA_CAST((GHIDRA_INT(pvVar4) + - GHIDRA_INT((&(GHIDRA_CAST((GHIDRA_INT(pEVar11) + 0x48)))->_filename + -3)) + 0x10)) - - fVar9) <= 0.0) || - ((local_9c.y - fVar7) * (local_9c.y - fVar7) + - (local_9c.x - fVar9) * (local_9c.x - fVar9) <= 6400.0)) || - (fVar7 = local_9c.y - - *GHIDRA_CAST((GHIDRA_INT(pvVar4) + - GHIDRA_INT((&(GHIDRA_CAST((GHIDRA_INT(pEVar11) + 0x48)))->_filename + -2)) + 4)), - fVar9 = local_9c.x - - *GHIDRA_CAST((GHIDRA_INT(pvVar4) + - GHIDRA_INT((&(GHIDRA_CAST((GHIDRA_INT(pEVar11) + 0x48)))->_filename + -2)))), - fVar7 * fVar7 + fVar9 * fVar9 <= 6400.0)) goto LAB_0099d46a; - local_c0.y = (float)(GHIDRA_INT(pvVar4) + - GHIDRA_INT((&(GHIDRA_CAST((GHIDRA_INT(pEVar11) + 0x48)))->_filename + -2))); - pEVar13 = bezierVec->_end; - newSampleX = GHIDRA_CAST(local_9c.x); - newSampleY = GHIDRA_CAST(local_9c.y); - newHandleInX = GHIDRA_CAST(g_vectorZero.x); - newHandleInY = GHIDRA_CAST(g_vectorZero.y); - newHandleOutX = GHIDRA_CAST(g_vectorZero.x); - newHandleOutY = GHIDRA_CAST(g_vectorZero.y); - if (pEVar13 == bezierVec->_capacity) { - vector_LaserSample_emplace_reallocate(bezierVec,(void *)local_c0.y,&newSampleX); - } - else if (GHIDRA_CAST(local_c0.y) == pEVar13) { - *GHIDRA_CAST(pEVar13) = local_9c.x; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((pEVar13)) + 0x4)))) = local_9c.y; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((pEVar13)) + 0x8)))) = fVar6; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((pEVar13)) + 0xc)))) = fVar8; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((pEVar13)) + 0x10)))) = fVar6; - pEVar13->_pendingDamage = fVar8; - bezierVec->_end = (void *)(GHIDRA_INT(bezierVec->_end) + 0x18); - } - else { - playerSpawner = pEVar13[-1]._pitfallState; - bezierByteSize = pEVar13[-1]._pitfallTimer; - fVar7 = pEVar13[-1]._scoreMultiplier; - local_34 = GHIDRA_CAST(&pEVar13[-1]._holdPosition.y); - *GHIDRA_CAST(pEVar13) = pEVar13[-1]._holdPosition.y; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((pEVar13)) + 0x4)))) = playerSpawner; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((pEVar13)) + 0x8)))) = bezierByteSize; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((pEVar13)) + 0xc)))) = fVar7; - fVar7 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(pEVar13[-1])) + 0x40c)))); - *(void **)&(*GHIDRA_CAST((GHIDRA_CAST((pEVar13)) + 0x10))) = pEVar13[-1]._luaBridgeRef; - pEVar13->_pendingDamage = fVar7; - bezierVec->_end = (void *)(GHIDRA_INT(bezierVec->_end) + 0x18); - if (local_34 != GHIDRA_CAST(local_c0.y)) { - dstSlot = &pEVar13->_pendingDamage; - srcSlot = GHIDRA_CAST(&pEVar13[-1]._holdPosition); - sample = GHIDRA_CAST(local_34); - do { - dstSlot[-0xb] = (float)*GHIDRA_CAST((GHIDRA_CAST((srcSlot + -2)) + 0xc)); - sample = sample + -6; - dstSlot[-10] = (float)(GHIDRA_CAST((srcSlot + -1)))->_head; - dstSlot[-9] = (float)(GHIDRA_CAST((srcSlot + -1)))->_size; - dstSlot[-8] = (float)(GHIDRA_CAST((srcSlot + -1)))[1]._head; - dstSlot[-7] = (float)*(uint32_t *) - (GHIDRA_INT((GHIDRA_CAST((srcSlot + -1)) + 1)) + 4); - dstSlot[-6] = (float)srcSlot->_seed; - dstSlot = dstSlot + -6; - srcSlot = GHIDRA_CAST((GHIDRA_INT((srcSlot + -2)) + 8)); - } while (sample != GHIDRA_CAST(local_c0.y)); - pEVar11 = GHIDRA_CAST(local_a4.y); - bezierVec = GHIDRA_CAST(local_ac.y); - } - *GHIDRA_CAST(local_c0.y) = local_9c.x; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(((GHIDRA_CAST(local_c0.y)))) + 0x4)))) = local_9c.y; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(((GHIDRA_CAST(local_c0.y)))) + 0x8)))) = fVar6; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(((GHIDRA_CAST(local_c0.y)))) + 0xc)))) = fVar8; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(((GHIDRA_CAST(local_c0.y)))) + 0x10)))) = fVar6; - (GHIDRA_CAST(local_c0.y))->_pendingDamage = fVar8; - } - eraseAt = piStack_70 + GHIDRA_INT(local_2c); - memmove(eraseAt,eraseAt + 1,GHIDRA_INT(local_60) - GHIDRA_INT((eraseAt + 1))); - local_6c = local_60 + -1; - local_25 = '\x01'; - local_60 = local_6c; - compute_axis_bezier_handles(self); - } - } -LAB_0099d5b3: - local_24 = bezierVec->_begin; - local_a4.y = (float)&pEVar11->_pendingDamageFlags; - pEVar11 = bezierVec->_end; - VStack_88.y = (float)(GHIDRA_INT(VStack_88.y) + 1); - local_44 = bezierVec->_end; - local_34 = local_24; - } while (GHIDRA_UINT(VStack_88.y) < GHIDRA_CAST(((GHIDRA_INT(pEVar11) - GHIDRA_INT(local_24)) / 0x18 + -1))); - local_44 = pEVar11; - if (local_25 == '\0') break; -LAB_0099d600: - } while (GHIDRA_UINT(((GHIDRA_INT(local_44) - GHIDRA_INT(local_24)) / 0x18)) < 6); - } - else { - local_38 = GHIDRA_CAST(0x1); - VStack_88.y = -NAN; - if (1 < (GHIDRA_INT(local_44) - GHIDRA_INT(local_24)) / 0x18 - 1U) { - local_24 = GHIDRA_CAST(0x18); - do { - local_34 = GHIDRA_CAST((GHIDRA_INT(puVar5) - GHIDRA_INT(piStack_70) >> 2)); - local_2c = GHIDRA_CAST(0x0); - if (local_34 != GHIDRA_CAST(0x0)) { - do { - local_ac.x = *GHIDRA_CAST((piStack_70[GHIDRA_INT(local_2c)] + 0x33c)); - local_ac.y = *GHIDRA_CAST((piStack_70[GHIDRA_INT(local_2c)] + 0x340)); - pvVar4 = (void *)(GHIDRA_INT(bezierVec->_begin) + GHIDRA_INT((&(local_24->_sprite)._filename + -3))) - ; - fVar6 = bezier_closest_point - (&local_ac,pvVar4,(void *)(GHIDRA_INT(pvVar4) + 0x18),GHIDRA_CAST(0x0)); - if (fVar6 < *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((self)) + 0x14)))) * *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((self)) + 0x14))))) { - sample = GHIDRA_CAST((GHIDRA_INT(bezierVec->_begin) + - GHIDRA_INT((&(local_24->_sprite)._filename + -3)))); - *sample = local_ac.x; - sample[1] = local_ac.y; - eraseAt = piStack_70 + GHIDRA_INT(local_2c); - memmove(eraseAt,eraseAt + 1,GHIDRA_INT(puVar5) - GHIDRA_INT((eraseAt + 1))); - puVar5 = puVar5 + -1; - if (GHIDRA_CAST(VStack_88.y) == GHIDRA_CAST(0xffffffff)) { - VStack_88.y = (float)local_38; - } - local_6c = puVar5; - break; - } - local_2c = GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((local_2c)) + 0x1)))); - } while (local_2c < local_34); - } - local_38 = GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((local_38)) + 0x1)))); - local_24 = GHIDRA_CAST(&local_24->_pendingDamageFlags); - } while (local_38 < - GHIDRA_CAST(((GHIDRA_INT(bezierVec->_end) - GHIDRA_INT(bezierVec->_begin)) / 0x18 + -1))); - if (-1 < GHIDRA_INT(VStack_88.y)) { - compute_axis_bezier_handles(self); - } - } - } - } - else if (homingType == 4) { - if (GHIDRA_UINT((GHIDRA_INT(bezierVec->_end) + (-0x30 - GHIDRA_INT(bezierVec->_begin)))) < 0x18) { - if (GHIDRA_INT(puVar5) - GHIDRA_INT(piStack_70) >> 2 != 0) { - local_34 = GHIDRA_CAST((piStack_70 + 1)); - do { - newSampleX = *GHIDRA_CAST((*piStack_70 + 0x33c)); - newSampleY = *GHIDRA_CAST((*piStack_70 + 0x340)); - newHandleInX = GHIDRA_CAST(g_vectorZero.x); - newHandleInY = GHIDRA_CAST(g_vectorZero.y); - newHandleOutX = GHIDRA_CAST(g_vectorZero.x); - newHandleOutY = GHIDRA_CAST(g_vectorZero.y); - msvc::vector::insert - (&local_ac.y, - (void *)(GHIDRA_INT(bezierVec->_begin) + - (((GHIDRA_INT((self->_bezier)._end) - GHIDRA_INT(bezierVec->_begin)) / 0x18) * 3 + -3 - ) * 8),&newSampleX); - puVar5 = local_60; - memmove(piStack_70,local_34,GHIDRA_INT(local_60) - GHIDRA_INT(local_34)); - local_6c = puVar5 + -1; - local_60 = local_6c; - } while (GHIDRA_INT(local_6c) - GHIDRA_INT(piStack_70) >> 2 != 0); - } - compute_axis_bezier_handles(self); - } - } - else if (homingType == 5) { - sample = bezierVec->_begin; - if (GHIDRA_UINT((GHIDRA_INT(bezierVec->_end) + (-0x30 - GHIDRA_INT(sample)))) < 0x18) { - pvVar4 = (self->_bezier)._end; - pEVar11 = GHIDRA_CAST((*GHIDRA_CAST((GHIDRA_CAST(pvVar4) + -0x18)) - *sample)); - pEVar13 = GHIDRA_CAST((*GHIDRA_CAST((GHIDRA_CAST(pvVar4) + -0x14)) - sample[1])); - local_40 = pEVar13; - local_3c = pEVar11; - if (0.01 <= (float)pEVar13 * (float)pEVar13 + (float)pEVar11 * (float)pEVar11) { - vector_LaserSample_erase(bezierVec,&local_34,(void *)(GHIDRA_INT(pvVar4) + -0x18)); - local_60 = GHIDRA_CAST((GHIDRA_INT(puVar5) - GHIDRA_INT(piStack_70) >> 2)); - do { - fVar7 = local_ac.y; - fVar8 = INFINITY; - bezierEnd = (self->_bezier)._end; - local_34 = GHIDRA_CAST(0x0); - fVar6 = bezierEnd[-1]._holdPosition.y; - VStack_88.y = (float)bezierEnd; - if (local_60 == GHIDRA_CAST(0x0)) break; - local_2c = GHIDRA_CAST(0x0); - candidateIndex = local_2c; - do { - candidate = GHIDRA_CAST(piStack_70[GHIDRA_INT(candidateIndex)]); - fVar10 = (float)bezierEnd[-1]._pitfallState - (candidate->_pos).y; - fVar9 = fVar6 - (candidate->_pos).x; - fVar9 = fVar10 * fVar10 + fVar9 * fVar9; - if (fVar9 < fVar8) { - local_2c = candidate; - fVar8 = fVar9; - } - candidateIndex = GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((candidateIndex)) + 0x1)))); - } while (candidateIndex < local_60); - if (local_2c == GHIDRA_CAST(0x0)) break; - local_24 = GHIDRA_CAST(((local_2c->_pos).x - fVar6)); - local_38 = GHIDRA_CAST(((local_2c->_pos).y - (float)bezierEnd[-1]._pitfallState)); - local_64 = pEVar11; - local_2c = pEVar13; - fVar6 = sqrtf((float)pEVar11 * (float)pEVar11 + (float)pEVar13 * (float)pEVar13); - if (0.0 < fVar6) { - local_2c = GHIDRA_CAST(((1.0 / fVar6) * (float)local_40)); - local_64 = GHIDRA_CAST(((1.0 / fVar6) * (float)local_3c)); - } - local_34 = local_24; - VStack_88.y = (float)local_38; - local_c0.y = sqrtf((float)local_24 * (float)local_24 + (float)local_38 * (float)local_38); - if (local_c0.y <= 0.0) { - pEVar11 = local_34; - } - else { - VStack_88.y = (1.0 / local_c0.y) * (float)local_38; - pEVar11 = GHIDRA_CAST(((1.0 / local_c0.y) * (float)local_24)); - } - entityIndex = (GHIDRA_INT(*(void **)(GHIDRA_CAST(fVar7) + 4)) - GHIDRA_INT(*(void **))fVar7) / 0x18; - local_64 = (Entity *) - (((float)local_64 * (float)pEVar11 + (float)local_2c * VStack_88.y + 1.0) * 0.5 - ); - if (1 < entityIndex) { - pvVar4 = *(void **)fVar7; - local_3c = (Entity *) - (*GHIDRA_CAST((GHIDRA_CAST(pvVar4) + entityIndex * 0x18 + -0x18)) - - *GHIDRA_CAST((GHIDRA_CAST(pvVar4) + entityIndex * 0x18 + -0x30))); - local_40 = (Entity *) - (*GHIDRA_CAST((GHIDRA_CAST(pvVar4) + entityIndex * 0x18 + -0x14)) - - *GHIDRA_CAST((GHIDRA_CAST(pvVar4) + entityIndex * 0x18 + -0x2c))); - } - fVar6 = sqrtf((float)local_3c * (float)local_3c + (float)local_40 * (float)local_40); - if (0.0 < fVar6) { - local_40 = GHIDRA_CAST(((float)local_40 * (1.0 / fVar6))); - local_3c = GHIDRA_CAST(((float)local_3c * (1.0 / fVar6))); - } - if (local_c0.y <= 0.0) { - pEVar13 = local_38; - pEVar11 = local_24; - } - else { - pEVar13 = GHIDRA_CAST(((1.0 / local_c0.y) * (float)local_38)); - pEVar11 = GHIDRA_CAST(((1.0 / local_c0.y) * (float)local_24)); - } - local_40 = GHIDRA_CAST(((float)pEVar13 * 0.3 * (float)local_64 + (float)local_40)); - local_3c = GHIDRA_CAST(((float)local_3c + (float)pEVar11 * 0.3 * (float)local_64)); - fVar9 = sqrtf((float)local_40 * (float)local_40 + (float)local_3c * (float)local_3c); - fVar8 = g_vectorZero.y; - fVar6 = g_vectorZero.x; - if (0.0 < fVar9) { - local_3c = GHIDRA_CAST(((float)local_3c * (1.0 / fVar9))); - local_40 = GHIDRA_CAST(((float)local_40 * (1.0 / fVar9))); - } - puVar5 = *(void **)(GHIDRA_CAST(fVar7) + 4); - local_a4.x = (float)local_3c * 40.0 + bezierEnd[-1]._holdPosition.y; - local_a4.y = (float)local_40 * 40.0 + (float)bezierEnd[-1]._pitfallState; - newHandleInX = GHIDRA_CAST(g_vectorZero.x); - newHandleInY = GHIDRA_CAST(g_vectorZero.y); - newHandleOutX = GHIDRA_CAST(g_vectorZero.x); - newHandleOutY = GHIDRA_CAST(g_vectorZero.y); - newSampleX = GHIDRA_CAST(local_a4.x); - newSampleY = GHIDRA_CAST(local_a4.y); - if (puVar5 == *(void **)(GHIDRA_CAST(fVar7) + 8)) { - vector_LaserSample_emplace_reallocate((void *)fVar7,puVar5,&newSampleX); - } - else { - *puVar5 = local_a4.x; - puVar5[1] = local_a4.y; - puVar5[2] = fVar6; - puVar5[3] = fVar8; - *GHIDRA_CAST((puVar5 + 4)) = CONCAT44(fVar8,fVar6); - *(void **)(GHIDRA_CAST(fVar7) + 4) = (void *)(GHIDRA_INT(*(void **)(GHIDRA_CAST(fVar7) + 4)) + 0x18); - } - bVar2 = Room::IsPositionInRoom(g_game->_room,&local_a4,0.0); - if (bVar2 == 0) break; - pEVar11 = local_3c; - pEVar13 = local_40; - } while (GHIDRA_UINT(((GHIDRA_INT(*(void **)(GHIDRA_CAST(fVar7) + 4)) - GHIDRA_INT(*(void **))fVar7) / 0x18)) < 0x19); - compute_bezier_handles(self,0.4); - } - } - } - if (piStack_70 != GHIDRA_CAST(0x0)) { - deallocate(piStack_70,GHIDRA_INT(targetsCapacity) - GHIDRA_INT(piStack_70) >> 2); - } - ExceptionList = local_1c; - return; -LAB_0099d46a: - local_2c = GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((local_2c)) + 0x1)))); - if (local_34 <= local_2c) goto LAB_0099d5b3; - goto LAB_0099d384; -} - -// 0099dca0 -void HomingLaser::compute_axis_bezier_handles() -{ - float fVar1; - float *bezierPoint; - void *bezierBegin; - float fVar2; - float nextDistance; - float fVar3; - float fVar4; - float fVar5; - float axisX; - float nextDistance; - float prevDistanceSq; - uint8_t *puVar7; - float tangentX; - float handleX; - float axisY; - float local_30; - float local_2c; - uint32_t i; - int pointCount; - - bezierPoint = (this->_bezier)._begin; - if (GHIDRA_UINT(((GHIDRA_INT((this->_bezier)._end) - GHIDRA_INT(bezierPoint)) / 0x18)) < 2) { - return; - } - fVar1 = bezierPoint[1]; - fVar5 = bezierPoint[4] - *bezierPoint; - axisY = 1.0; - if (ABS(fVar5) <= ABS(bezierPoint[5] - fVar1)) { - axisX = 0.0; - if (bezierPoint[5] - fVar1 < 0.0) { - axisY = (float)&DAT_bf800000; - } - } - else { - if (0.0 <= fVar5) { - axisX = 1.0; - } - else { - axisX = (float)&DAT_bf800000; - } - axisY = 0.0; - } - fVar5 = bezierPoint[6] - *bezierPoint; - fVar5 = sqrtf((bezierPoint[7] - fVar1) * (bezierPoint[7] - fVar1) + fVar5 * fVar5); - nextDistance = axisX * fVar5 * 0.5; - fVar5 = axisY * fVar5 * 0.5; - bezierPoint[4] = nextDistance + *bezierPoint; - i = 1; - bezierPoint[5] = fVar5 + fVar1; - bezierPoint[9] = bezierPoint[7] - fVar5; - bezierPoint[8] = bezierPoint[6] - nextDistance; - if ((GHIDRA_INT((this->_bezier)._end) - GHIDRA_INT(bezierPoint)) / 0x18 - 1U < 2) { - bezierBegin = (this->_bezier)._begin; - } - else { - bezierPoint = GHIDRA_CAST((GHIDRA_INT((this->_bezier)._begin) + 4)); - do { - fVar1 = bezierPoint[5]; - fVar5 = bezierPoint[6]; - nextDistance = bezierPoint[-1] - fVar1; - local_2c = bezierPoint[0xc] - fVar5; - local_30 = bezierPoint[0xb] - fVar1; - fVar2 = *bezierPoint - fVar5; - nextDistance = sqrtf(local_2c * local_2c + local_30 * local_30); - if (0.0 < nextDistance) { - local_30 = (1.0 / nextDistance) * local_30; - local_2c = local_2c * (1.0 / nextDistance); - } - prevDistanceSq = fVar2 * fVar2 + nextDistance * nextDistance; - fVar3 = sqrtf(prevDistanceSq); - if (fVar3 <= 0.0) { - fVar4 = fVar2; - fVar3 = nextDistance; - } - else { - fVar4 = (1.0 / fVar3) * fVar2; - fVar3 = (1.0 / fVar3) * nextDistance; - } - if (ABS(local_30 + fVar3) <= ABS(local_2c + fVar4)) { - puVar7 = GHIDRA_CAST(0x0); - if (0.0 <= local_2c + fVar4) { - tangentX = 1.0; - handleX = 1.0; - } - else { - tangentX = (float)&DAT_bf800000; - handleX = (float)&DAT_bf800000; - } - } - else { - tangentX = 0.0; - handleX = 0.0; - if (0.0 <= local_30 + fVar3) { - puVar7 = GHIDRA_CAST(0x3f800000); - } - else { - puVar7 = &DAT_bf800000; - } - } - local_2c = -(float)puVar7; - if (nextDistance * tangentX + local_2c * fVar2 < 0.0) { - tangentX = (float)(GHIDRA_UINT(tangentX) ^ 0x80000000); - local_2c = -local_2c; - handleX = tangentX; - } - if ((bezierPoint[3] - bezierPoint[-1]) * (fVar1 - bezierPoint[-1]) + - (bezierPoint[4] - *bezierPoint) * (fVar5 - *bezierPoint) < 0.0) { - tangentX = tangentX + tangentX; - local_2c = local_2c + local_2c; - handleX = tangentX; - } - bezierPoint[10] = -nextDistance * local_2c * 0.5 + fVar5; - bezierPoint[9] = -nextDistance * tangentX * 0.5 + fVar1; - nextDistance = sqrtf(prevDistanceSq); - i = i + 1; - bezierPoint[7] = nextDistance * handleX * 0.5 + fVar1; - bezierPoint[8] = nextDistance * local_2c * 0.5 + fVar5; - bezierPoint = bezierPoint + 6; - bezierBegin = (this->_bezier)._begin; - } while (i < (GHIDRA_INT((this->_bezier)._end) - GHIDRA_INT(bezierBegin)) / 0x18 - 1U); - } - pointCount = (GHIDRA_INT((this->_bezier)._end) - GHIDRA_INT(bezierBegin)) / 0x18; - fVar1 = *GHIDRA_CAST((GHIDRA_CAST(bezierBegin) + pointCount * 0x18 + -0x18)); - fVar5 = *GHIDRA_CAST((GHIDRA_CAST(bezierBegin) + pointCount * 0x18 + -0x14)); - nextDistance = *GHIDRA_CAST((GHIDRA_CAST(bezierBegin) + pointCount * 0x18 + -0x30)) - fVar1; - fVar2 = *GHIDRA_CAST((GHIDRA_CAST(bezierBegin) + pointCount * 0x18 + -0x2c)) - fVar5; - if (ABS(nextDistance) <= ABS(fVar2)) { - nextDistance = 0.0; - } - else { - fVar2 = 0.0; - } - *GHIDRA_CAST((GHIDRA_CAST(bezierBegin) + pointCount * 0x18 + -0x10)) = nextDistance * 0.5 + fVar1; - *GHIDRA_CAST((GHIDRA_CAST(bezierBegin) + pointCount * 0x18 + -0xc)) = fVar2 * 0.5 + fVar5; - return; -} - -// 0099e160 -void HomingLaser::compute_bezier_handles(float tension) -{ - float *pfVar1; - int iVar2; - uint32_t uVar3; - void *pointsEnd; - float *pointsBegin; - uint32_t pointIndex; - float fVar4; - float fVar5; - float prevDx; - float prevDy; - bool isClosed; - bool isWrapFirst; - - pointsEnd = (this->_bezier)._end; - pfVar1 = (this->_bezier)._begin; - fVar4 = *GHIDRA_CAST((GHIDRA_CAST(pointsEnd) + -0x18)) - *pfVar1; - fVar5 = *GHIDRA_CAST((GHIDRA_CAST(pointsEnd) + -0x14)) - pfVar1[1]; - if ((0.01 <= fVar5 * fVar5 + fVar4 * fVar4) || (GHIDRA_UINT(((GHIDRA_INT(pointsEnd) - GHIDRA_INT(pfVar1)) / 0x18)) < 3) - ) { - isClosed = false; - iVar2 = GHIDRA_INT(pointsEnd) - GHIDRA_INT(pfVar1) >> 0x1f; - if ((GHIDRA_INT(pointsEnd) - GHIDRA_INT(pfVar1)) / 0x18 + iVar2 == iVar2) { - return; - } - isWrapFirst = false; - } - else { - isWrapFirst = true; - isClosed = true; - } - pointsBegin = pfVar1; - pointIndex = 0; - do { - fVar4 = g_vectorZero.x; - fVar5 = g_vectorZero.y; - if (isWrapFirst) { - iVar2 = (GHIDRA_INT(pointsEnd) - GHIDRA_INT(pointsBegin)) / 0x18; - if (pointIndex != 0) { - if (pointIndex == iVar2 - 1U) { - fVar4 = pointsBegin[6] - pointsBegin[pointIndex * 6]; - fVar5 = pointsBegin[7] - pointsBegin[pointIndex * 6 + 1]; - } - goto LAB_0099e26a; - } - prevDx = *pointsBegin - pointsBegin[iVar2 * 6 + -0xc]; - prevDy = pointsBegin[1] - pointsBegin[iVar2 * 6 + -0xb]; - } - else { -LAB_0099e26a: - prevDx = g_vectorZero.x; - prevDy = g_vectorZero.y; - if (pointIndex != 0) { - prevDx = pointsBegin[pointIndex * 6] - pointsBegin[pointIndex * 6 + -6]; - prevDy = pointsBegin[pointIndex * 6 + 1] - pointsBegin[pointIndex * 6 + -5]; - } - } - uVar3 = (GHIDRA_INT(pointsEnd) - GHIDRA_INT(pointsBegin)) / 0x18 - 1; - if (pointIndex < uVar3) { - fVar4 = pointsBegin[pointIndex * 6 + 6] - pointsBegin[pointIndex * 6]; - fVar5 = pointsBegin[pointIndex * 6 + 7] - pointsBegin[pointIndex * 6 + 1]; - } - fVar4 = (prevDx + fVar4) * tension; - fVar5 = (prevDy + fVar5) * tension; - if ((isClosed) || ((pointIndex != 0 && (pointIndex < uVar3)))) { - fVar4 = fVar4 * 0.5; - fVar5 = fVar5 * 0.5; - } - uVar3 = pointIndex + 1; - pfVar1[pointIndex * 6 + 2] = pfVar1[pointIndex * 6] - fVar4; - pfVar1[pointIndex * 6 + 3] = pfVar1[pointIndex * 6 + 1] - fVar5; - pfVar1[pointIndex * 6 + 4] = fVar4 + pfVar1[pointIndex * 6]; - pfVar1[pointIndex * 6 + 5] = fVar5 + pfVar1[pointIndex * 6 + 1]; - pointsEnd = (this->_bezier)._end; - pointsBegin = (this->_bezier)._begin; - pointIndex = uVar3; - isWrapFirst = isClosed; - if (GHIDRA_UINT(((GHIDRA_INT(pointsEnd) - GHIDRA_INT(pointsBegin)) / 0x18)) <= uVar3) { - return; - } - } while( true ); -} - -// 0099e360 -void HomingLaser::CalculateSamples(float param_2) -{ - float fVar1; - float fVar2; - uint32_t uVar3; - int iVar4; - uint32_t uVar5; - float *pfVar6; - void *ptr; - int segment; - uint32_t *puVar7; - float *pfVar8; - HomingLaser *pHVar9; - float fVar10; - float fVar11; - float nextWeight1; - float fVar12; - float nextWeight3; - float nextT; - float nextWeight1; - float nextWeight2; - void *newSamples; - float *newSamplesEnd; - float *newSamplesCapacitySlot; - float *lengthsBegin; - uint32_t *lengthsEnd; - uint32_t *lengthsCapacitySlot; - uint32_t *local_50; - float local_4c; - float local_48; - float nextWeight0; - uint32_t *local_40; - float local_3c; - float local_38; - float weight2; - float weight0; - float weight1; - HomingLaser *laser; - int local_24; - float *newSamplesCapacity; - float blend; - float *local_18; - uint32_t *lengthsCapacity; - void *savedExceptionList; - uint8_t *puStack_c; - uint32_t ehState; - uint32_t *lengthIdx; - uint8_t *oldSamples; - - ehState = 0xffffffff; - puStack_c = &LAB_00b0d9b5; - savedExceptionList = ExceptionList; - ExceptionList = &savedExceptionList; - laser = this; - blend = param_2; - if (GHIDRA_UINT(((GHIDRA_INT((this->_bezier)._end) - GHIDRA_INT((this->_bezier)._begin)) / 0x18)) < 2) { - KAGE_LogMessage(0x10,GHIDRA_CAST("Bezier Path Size is less than 2!\n")); - } - newSamples = (void *)0x0; - newSamplesEnd = GHIDRA_CAST(0x0); - newSamplesCapacity = GHIDRA_CAST(0x0); - newSamplesCapacitySlot = GHIDRA_CAST(0x0); - ehState = 0; - uVar5 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x18)))); - if (uVar5 != 0) { - if (0x1fffffff < uVar5) { - /* WARNING: Subroutine does not return */ - msvc::_Xlen(); - } - msvc::vector<8byte>::_Reallocate_exactly(uVar5); - newSamplesCapacity = newSamplesCapacitySlot; - } - this->_totalLength = 0.0; - local_18 = GHIDRA_CAST(0x0); - lengthsBegin = GHIDRA_CAST(0x0); - lengthsEnd = GHIDRA_CAST(0x0); - lengthsCapacity = GHIDRA_CAST(0x0); - lengthsCapacitySlot = GHIDRA_CAST(0x0); - ehState = CONCAT31((*GHIDRA_CAST((GHIDRA_CAST(&(ehState)) + 0x1))),1); - uVar5 = (GHIDRA_INT((this->_bezier)._end) - GHIDRA_INT((this->_bezier)._begin)) / 0x18; - newSamplesCapacitySlot = newSamplesCapacity; - if (uVar5 != 0) { - if (0x3fffffff < uVar5) { - /* WARNING: Subroutine does not return */ - msvc::_Xlen(); - } - msvc::vector::_Reallocate(uVar5); - lengthsCapacity = lengthsCapacitySlot; - local_18 = lengthsBegin; - } - local_40 = GHIDRA_CAST(0x0); - if (lengthsEnd == lengthsCapacity) { - lengthsBegin = local_18; - lengthsCapacitySlot = lengthsCapacity; - msvc::vector::_Emplace_reallocate(lengthsEnd,&local_40); - lengthsCapacity = lengthsCapacitySlot; - local_18 = lengthsBegin; - } - else { - *lengthsEnd = 0; - lengthsEnd = lengthsEnd + 1; - } - local_38 = 0.0; - puVar7 = lengthsEnd; - lengthsBegin = local_18; - lengthsCapacitySlot = lengthsCapacity; - if ((GHIDRA_INT((this->_bezier)._end) - GHIDRA_INT((this->_bezier)._begin)) / 0x18 != 1) { - local_24 = 0; - pfVar6 = local_18; - do { - local_40 = GHIDRA_CAST(0x0); - if (puVar7 == lengthsCapacity) { - msvc::vector::_Emplace_reallocate(puVar7,&local_40); - lengthsCapacity = lengthsCapacitySlot; - pfVar6 = lengthsBegin; - } - else { - *puVar7 = 0; - lengthsEnd = puVar7 + 1; - } - iVar4 = local_24; - fVar10 = local_38; - local_48 = 0.0; - local_50 = (this->_bezier)._begin; - local_3c = 1.4013e-45; - local_40 = lengthsEnd; - do { - fVar11 = 1.0 - local_48; - nextT = (float)((double)GHIDRA_INT(local_3c) + __uint_to_double_fixup[-(GHIDRA_INT(local_3c) >> 0x1f)]) / - 10.0; - weight0 = fVar11 * fVar11 * fVar11; - nextWeight1 = 1.0 - nextT; - weight2 = fVar11 * 3.0 * local_48 * local_48; - local_38 = local_48 * local_48 * local_48; - weight1 = fVar11 * fVar11 * 3.0 * local_48; - fVar11 = *GHIDRA_CAST((GHIDRA_CAST(local_50) + iVar4 + 0x20)); - nextWeight0 = nextWeight1 * nextWeight1 * nextWeight1; - nextWeight1 = nextWeight1 * nextWeight1 * 3.0 * nextT; - nextWeight2 = nextWeight1 * 3.0 * nextT * nextT; - nextWeight3 = nextT * nextT * nextT; - nextWeight1 = *GHIDRA_CAST((GHIDRA_CAST(local_50) + iVar4 + 0x18)); - local_18 = GHIDRA_CAST((*GHIDRA_CAST((GHIDRA_CAST(local_50) + iVar4 + 0x10)) * weight1 + - *GHIDRA_CAST((GHIDRA_CAST(local_50) + iVar4)) * weight0)); - fVar12 = *GHIDRA_CAST((GHIDRA_CAST(local_50) + iVar4 + 0x1c)); - fVar1 = *GHIDRA_CAST((GHIDRA_CAST(local_50) + iVar4 + 4)); - fVar2 = *GHIDRA_CAST((GHIDRA_CAST(local_50) + iVar4 + 0x24)); - nextWeight1 = (*GHIDRA_CAST((GHIDRA_CAST(local_50) + iVar4 + 0x10)) * nextWeight1 + - *GHIDRA_CAST((GHIDRA_CAST(local_50) + iVar4)) * nextWeight0 + fVar11 * nextWeight2 + - nextWeight1 * nextWeight3) - ((float)local_18 + fVar11 * weight2 + nextWeight1 * local_38); - fVar11 = (*GHIDRA_CAST((GHIDRA_CAST(local_50) + iVar4 + 0x14)) * nextWeight1 + fVar1 * nextWeight0 + - fVar2 * nextWeight2 + fVar12 * nextWeight3) - - (*GHIDRA_CAST((GHIDRA_CAST(local_50) + iVar4 + 0x14)) * weight1 + fVar1 * weight0 + - fVar2 * weight2 + fVar12 * local_38); - local_48 = nextT; - nextWeight1 = sqrtf(fVar11 * fVar11 + nextWeight1 * nextWeight1); - fVar11 = pfVar6[GHIDRA_INT(fVar10) + 1]; - local_3c = (float)(GHIDRA_INT(local_3c) + 1); - pfVar6[GHIDRA_INT(fVar10) + 1] = nextWeight1 + fVar11; - } while (GHIDRA_UINT(local_3c) < 0xb); - local_24 = local_24 + 0x18; - local_38 = (float)(GHIDRA_INT(fVar10) + 1); - laser->_totalLength = nextWeight1 + fVar11 + laser->_totalLength; - puVar7 = local_40; - this = laser; - } while (GHIDRA_UINT(local_38) < - (GHIDRA_INT((laser->_bezier)._end) - GHIDRA_INT((laser->_bezier)._begin)) / 0x18 - 1U); - local_18 = pfVar6; - } - pfVar6 = local_18; - if ((this->_totalLength != 0.0) && (uVar5 = GHIDRA_INT(puVar7) - GHIDRA_INT(local_18) >> 2, uVar5 != 0)) { - uVar3 = 1; - *local_18 = *local_18 / this->_totalLength; - if (1 < uVar5) { - do { - fVar10 = local_18[uVar3] / this->_totalLength; - local_18[uVar3] = fVar10; - local_18[uVar3] = fVar10 + local_18[uVar3 - 1]; - uVar3 = uVar3 + 1; - } while (uVar3 < uVar5); - } - } - local_40 = GHIDRA_CAST(0x0); - local_38 = 0.0; - local_50 = GHIDRA_CAST(((GHIDRA_INT(puVar7) - GHIDRA_INT(local_18) >> 2) - 1)); - uVar5 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x18)))); - do { - fVar10 = (float)((double)GHIDRA_INT(local_38) + __uint_to_double_fixup[-(GHIDRA_INT(local_38) >> 0x1f)]) / - (float)((double)GHIDRA_INT(uVar5) + __uint_to_double_fixup[-(GHIDRA_INT(uVar5) >> 0x1f)]); - local_3c = fVar10; - puVar7 = local_40; - while ((lengthIdx = puVar7, lengthIdx < local_50 && - (fVar11 = pfVar6[GHIDRA_INT(lengthIdx)], fVar11 < fVar10))) { - local_3c = ((fVar10 - fVar11) / (pfVar6[GHIDRA_INT(lengthIdx) + 1] - fVar11)) / - (float)((double)GHIDRA_INT(local_50) + __uint_to_double_fixup[-(GHIDRA_INT(local_50) >> 0x1f)]) + - (float)((double)GHIDRA_INT(lengthIdx) + __uint_to_double_fixup[-(GHIDRA_INT(lengthIdx) >> 0x1f)]) - / (float)((double)GHIDRA_INT(local_50) + __uint_to_double_fixup[-(GHIDRA_INT(local_50) >> 0x1f)]) - ; - local_40 = lengthIdx; - puVar7 = GHIDRA_CAST((GHIDRA_INT(lengthIdx) + 1)); - } - if (GHIDRA_UINT(((GHIDRA_INT((this->_bezier)._end) - GHIDRA_INT((this->_bezier)._begin)) / 0x18)) < 2) { - KAGE_LogMessage(0x10,GHIDRA_CAST("Bezier Path Size less than 2!\n")); - } - pfVar8 = (this->_bezier)._begin; - iVar4 = (GHIDRA_INT((this->_bezier)._end) - GHIDRA_INT(pfVar8)) / 0x18; - fVar10 = (float)((double)(iVar4 + -1) + __uint_to_double_fixup[-(iVar4 + -1 >> 0x1f)]) * - local_3c; - segment = GHIDRA_INT(fVar10); - fVar10 = fVar10 - (float)segment; - if (segment < 0) { - local_4c = *pfVar8; - local_48 = pfVar8[1]; - } - else if (segment < iVar4 + -1) { - nextWeight1 = 1.0 - fVar10; - fVar11 = nextWeight1 * nextWeight1 * nextWeight1; - fVar12 = nextWeight1 * nextWeight1 * 3.0 * fVar10; - nextWeight1 = nextWeight1 * 3.0 * fVar10 * fVar10; - fVar10 = fVar10 * fVar10 * fVar10; - local_4c = fVar11 * pfVar8[segment * 6] + fVar12 * pfVar8[segment * 6 + 4] + - nextWeight1 * pfVar8[segment * 6 + 8] + fVar10 * pfVar8[segment * 6 + 6]; - local_48 = fVar12 * pfVar8[segment * 6 + 5] + fVar11 * pfVar8[segment * 6 + 1] + - nextWeight1 * pfVar8[segment * 6 + 9] + fVar10 * pfVar8[segment * 6 + 7]; - } - else { - local_4c = pfVar8[iVar4 * 6 + -6]; - local_48 = pfVar8[iVar4 * 6 + -5]; - } - if (newSamplesEnd == newSamplesCapacity) { - msvc::vector::_Emplace_reallocate(newSamplesEnd,&local_4c); - newSamplesCapacity = newSamplesCapacitySlot; - } - else { - *newSamplesEnd = local_4c; - newSamplesEnd[1] = local_48; - newSamplesEnd = newSamplesEnd + 2; - } - uVar5 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x18)))); - local_38 = (float)(GHIDRA_INT(local_38) + 1); - } while (GHIDRA_UINT(local_38) <= uVar5); - local_40 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x34)))); - oldSamples = &(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x34))); - local_24 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x38)))) - GHIDRA_INT(local_40) >> 3; - pHVar9 = this; - if (local_24 == GHIDRA_INT(newSamplesEnd) - GHIDRA_INT(newSamples) >> 3) { - if (*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x40)))) == 1) { - if (local_24 != 0) { - local_50 = GHIDRA_CAST((GHIDRA_INT(newSamples) - GHIDRA_INT(local_40))); - uVar5 = 0; - pfVar6 = GHIDRA_CAST((local_40 + 1)); - do { - iVar4 = uVar5 * 8; - uVar5 = uVar5 + 1; - fVar10 = *GHIDRA_CAST((GHIDRA_CAST(local_50) + GHIDRA_INT(pfVar6))); - pfVar6[-1] = (*GHIDRA_CAST((GHIDRA_CAST(newSamples) + iVar4)) - pfVar6[-1]) * blend + pfVar6[-1]; - *pfVar6 = (fVar10 - *pfVar6) * blend + *pfVar6; - pfVar6 = pfVar6 + 2; - } while (uVar5 < GHIDRA_UINT((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x38)))) - *GHIDRA_CAST(oldSamples) >> 3))); - pfVar6 = local_18; - goto LAB_0099eb5f; - } - } - else { - fVar10 = this->_totalLength / 200.0; - uVar5 = 0; - if (fVar10 <= 0.0) { - fVar10 = 0.0; - } - if (1.0 <= fVar10) { - fVar10 = 1.0; - } - blend = (blend - 0.0) * fVar10 + 0.0; - if (local_24 != 0) { - do { - uVar3 = -GHIDRA_UINT((uVar5 != 0)) & uVar5; - iVar4 = (*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x38)))) - *GHIDRA_CAST(oldSamples) >> 3) + -1; - fVar10 = *GHIDRA_CAST((GHIDRA_CAST(newSamples) + uVar5 * 8 + 4)); - fVar11 = (float)local_40[uVar5 * 2 + 1]; - fVar12 = 1.0 - ((float)((double)GHIDRA_INT(uVar3) + __uint_to_double_fixup[-(GHIDRA_INT(uVar3) >> 0x1f)] - ) / - (float)((double)iVar4 + __uint_to_double_fixup[-(iVar4 >> 0x1f)])) * blend; - nextWeight1 = (float)local_40[uVar5 * 2 + 1]; - local_40[uVar5 * 2] = - (*GHIDRA_CAST((GHIDRA_CAST(newSamples) + uVar5 * 8)) - (float)local_40[uVar5 * 2]) * fVar12 + - (float)local_40[uVar5 * 2]; - local_40[uVar5 * 2 + 1] = (fVar10 - fVar11) * fVar12 + nextWeight1; - uVar5 = uVar5 + 1; - } while (uVar5 < GHIDRA_UINT((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x38)))) - *GHIDRA_CAST(oldSamples) >> 3))); -LAB_0099eb5f: - pHVar9 = laser; - } - } - } - else if ((void **)oldSamples != &newSamples) { - msvc::vector::assign(newSamples,newSamplesEnd,local_50); - } - if (&(*GHIDRA_CAST((GHIDRA_CAST((pHVar9)) + 0x1c))) != oldSamples) { - msvc::vector::assign(*GHIDRA_CAST(oldSamples),*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x38)))),local_50) - ; - } - if (pfVar6 != GHIDRA_CAST(0x0)) { - uVar5 = GHIDRA_INT(lengthsCapacity) - GHIDRA_INT(pfVar6) & 0xfffffffc; - pfVar8 = pfVar6; - if (0xfff < uVar5) { - pfVar8 = GHIDRA_CAST(pfVar6[-1]); - uVar5 = uVar5 + 0x23; - if (0x1f < GHIDRA_UINT((GHIDRA_INT(pfVar6) + (-4 - GHIDRA_INT(pfVar8))))) goto LAB_0099ebcf; - } - operator_delete(pfVar8,uVar5); - } - if (newSamples != (void *)0x0) { - uVar5 = GHIDRA_INT(newSamplesCapacity) - GHIDRA_INT(newSamples) & 0xfffffff8; - ptr = newSamples; - if (0xfff < uVar5) { - ptr = *(void **)(GHIDRA_CAST(newSamples) + -4); - uVar5 = uVar5 + 0x23; - if (0x1f < GHIDRA_UINT((GHIDRA_INT(newSamples) + (-4 - GHIDRA_INT(ptr))))) { -LAB_0099ebcf: - /* WARNING: Subroutine does not return */ - _invalid_parameter_noinfo_noreturn(); - } - } - operator_delete(ptr,uVar5); - } - ExceptionList = savedExceptionList; - return; -} - -// 0099ec00 -void HomingLaser::apply_sine_offset(float amplitude, float phase) -{ - int iVar1; - int iVar2; - uint32_t uVar3; - float fVar4; - float fVar5; - float fVar6; - float segDx; - float radialX; - float local_28; - float segDy; - int pointsBegin; - float *pointCursor; - - if (*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x40)))) == 1) { - iVar2 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x1c)))); - uVar3 = 0; - if (*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x20)))) - iVar2 >> 3 != 0) { - do { - radialX = *GHIDRA_CAST((iVar2 + uVar3 * 8)) - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))); - fVar5 = *GHIDRA_CAST((iVar2 + 4 + uVar3 * 8)); - local_28 = fVar5 - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x8)))); - fVar4 = sqrtf(radialX * radialX + local_28 * local_28); - if (0.0 < fVar4) { - radialX = radialX * (1.0 / fVar4); - local_28 = local_28 * (1.0 / fVar4); - } - iVar1 = (*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x20)))) - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x1c)))) >> 3) + -1; - fVar4 = sin((((float)((double)GHIDRA_INT(uVar3) + __uint_to_double_fixup[-(GHIDRA_INT(uVar3) >> 0x1f)]) * - 37.699112) / (float)((double)iVar1 + __uint_to_double_fixup[-(iVar1 >> 0x1f)]) - - (float)g_game->_frameCount * 0.1) - phase); - fVar4 = fVar4 * 10.0 * amplitude; - *GHIDRA_CAST((iVar2 + uVar3 * 8)) = radialX * fVar4 + *GHIDRA_CAST((iVar2 + uVar3 * 8)); - *GHIDRA_CAST((iVar2 + 4 + uVar3 * 8)) = local_28 * fVar4 + fVar5; - uVar3 = uVar3 + 1; - } while (uVar3 < GHIDRA_UINT((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x20)))) - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x1c)))) >> 3))); - return; - } - } - else { - fVar5 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x10)))) - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x8)))); - fVar4 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0xc)))) - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))); - fVar5 = sqrtf(fVar5 * fVar5 + fVar4 * fVar4); - uVar3 = 0; - iVar2 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x20)))); - pointsBegin = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x1c)))); - if (iVar2 - pointsBegin >> 3 != 1) { - pointCursor = GHIDRA_CAST((pointsBegin + 4)); - do { - fVar4 = *pointCursor; - segDy = pointCursor[2] - fVar4; - segDx = pointCursor[1] - pointCursor[-1]; - fVar6 = sqrtf(segDy * segDy + segDx * segDx); - if (0.0 < fVar6) { - segDy = segDy * (1.0 / fVar6); - segDx = segDx * (1.0 / fVar6); - } - if (uVar3 < 0x14) { - iVar2 = iVar2 - pointsBegin; - fVar6 = (float)((double)GHIDRA_INT(uVar3) + __uint_to_double_fixup[-(GHIDRA_INT(uVar3) >> 0x1f)]) / 20.0 - ; -LAB_0099eedf: - local_28 = fVar6 * amplitude * 20.0; - } - else { - iVar2 = iVar2 - pointsBegin; - local_28 = amplitude * 20.0; - if ((iVar2 >> 3) - 0x16U < uVar3) { - iVar1 = ((iVar2 >> 3) - uVar3) + 1; - fVar6 = (float)((double)iVar1 + __uint_to_double_fixup[-(iVar1 >> 0x1f)]) / 22.0; - goto LAB_0099eedf; - } - } - iVar2 = (iVar2 >> 3) + -2; - fVar6 = sin((((float)((double)GHIDRA_INT(uVar3) + __uint_to_double_fixup[-(GHIDRA_INT(uVar3) >> 0x1f)]) / - (float)((double)iVar2 + __uint_to_double_fixup[-(iVar2 >> 0x1f)])) * - (fVar5 / 200.0) * 15.0 - (float)g_game->_frameCount * 0.1) - phase); - uVar3 = uVar3 + 1; - pointCursor[-1] = segDy * fVar6 * local_28 + pointCursor[-1]; - *pointCursor = -segDx * fVar6 * local_28 + fVar4; - pointCursor = pointCursor + 2; - pointsBegin = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x1c)))); - iVar2 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x20)))); - } while (uVar3 < (iVar2 - pointsBegin >> 3) - 1U); - } - } - return; -} - -// 0099fa60 -void HomingLaser::build_curl_path(float radius) -{ - void **ppvVar1; - long double baseAngle; - float baseAngle; - float fVar3; - double dVar4; - double dVar5; - float fVar6; - float curlAngle; - float fVar7; - uint32_t uStack_48; - float local_30; - float fStack_2c; - float fStack_28; - float fStack_24; - float local_20; - float fStack_1c; - float *samplesEnd; - - fVar6 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0xc)))) - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))); - fVar7 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x10)))) - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x8)))); - baseAngle = sqrtf(fVar6 * fVar6 + fVar7 * fVar7); - if (0.0 < baseAngle) { - fVar7 = (1.0 / baseAngle) * fVar7; - fVar6 = fVar6 * (1.0 / baseAngle); - } - samplesEnd = (this->_bezier)._end; - local_30 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))); - local_20 = fVar6 * 50.0 + local_30; - fStack_2c = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x8)))); - fStack_1c = fVar7 * 50.0 + fStack_2c; - fStack_28 = local_30; - fStack_24 = fStack_2c; - if (samplesEnd == (this->_bezier)._capacity) { - vector_LaserSample_emplace_reallocate(&this->_bezier,samplesEnd,&local_30); - } - else { - *samplesEnd = local_30; - samplesEnd[1] = fStack_2c; - samplesEnd[2] = local_30; - samplesEnd[3] = fStack_2c; - *GHIDRA_CAST((samplesEnd + 4)) = CONCAT44(fStack_1c,local_20); - ppvVar1 = &(this->_bezier)._end; - *ppvVar1 = (void *)(GHIDRA_INT(*ppvVar1) + 0x18); - } - baseAngle = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x10)))) - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x8)))); - fVar7 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0xc)))) - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))); - baseAngle = (long double)_CIatan2(); - fVar6 = radius * 1.05; - uStack_48 = 0; - do { - curlAngle = ((float)baseAngle - 0.7) - - ((float)((double)GHIDRA_INT(uStack_48) + __uint_to_double_fixup[-(GHIDRA_INT(uStack_48) >> 0x1f)]) - / 5.0) * 3.1415927 * 6.0 * 0.25; - dVar4 = (double)(curlAngle + 0.25); - dVar5 = dVar4; - libm_sse2_cos_precise(); - fVar3 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))); - libm_sse2_sin_precise(); - fStack_24 = (float)dVar4 * fVar6 + *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x8)))); - dVar4 = (double)curlAngle; - fStack_28 = (float)dVar5 * fVar6 + fVar3; - libm_sse2_cos_precise(); - fVar3 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))); - dVar5 = (double)curlAngle; - libm_sse2_sin_precise(); - fStack_2c = (float)dVar5 * radius + *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x8)))); - dVar5 = (double)(curlAngle - 0.25); - local_30 = (float)dVar4 * radius + fVar3; - libm_sse2_cos_precise(); - fVar3 = (float)dVar5 * fVar6 + *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))); - dVar5 = (double)(curlAngle - 0.25); - libm_sse2_sin_precise(); - samplesEnd = (this->_bezier)._end; - fStack_1c = (float)dVar5 * fVar6 + *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x8)))); - local_20 = fVar3; - if (samplesEnd == (this->_bezier)._capacity) { - vector_LaserSample_emplace_reallocate(&this->_bezier,samplesEnd,&local_30); - } - else { - *samplesEnd = local_30; - samplesEnd[1] = fStack_2c; - samplesEnd[2] = fStack_28; - samplesEnd[3] = fStack_24; - *GHIDRA_CAST((samplesEnd + 4)) = CONCAT44(fStack_1c,fVar3); - ppvVar1 = &(this->_bezier)._end; - *ppvVar1 = (void *)(GHIDRA_INT(*ppvVar1) + 0x18); - } - samplesEnd = (this->_bezier)._end; - uStack_48 = uStack_48 + 1; - } while (uStack_48 < 6); - fStack_2c = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x10)))); - local_30 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0xc)))); - fStack_1c = fStack_2c - baseAngle * 0.25; - fStack_28 = local_30 - fVar7 * 0.75; - local_20 = local_30 - fVar7 * 0.25; - fStack_24 = fStack_2c - baseAngle * 0.75; - local_30 = local_30 - fVar7 * 0.5; - fStack_2c = fStack_2c - baseAngle * 0.5; - if (samplesEnd == (this->_bezier)._capacity) { - vector_LaserSample_emplace_reallocate(&this->_bezier,samplesEnd,&local_30); - } - else { - *samplesEnd = local_30; - samplesEnd[1] = fStack_2c; - samplesEnd[2] = fStack_28; - samplesEnd[3] = fStack_24; - *GHIDRA_CAST((samplesEnd + 4)) = CONCAT44(fStack_1c,local_20); - ppvVar1 = &(this->_bezier)._end; - *ppvVar1 = (void *)(GHIDRA_INT(*ppvVar1) + 0x18); - } - local_30 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0xc)))); - fStack_2c = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x10)))); - local_20 = local_30 + fVar7; - samplesEnd = (this->_bezier)._end; - fStack_1c = fStack_2c + baseAngle; - fStack_28 = local_30 - fVar7 * 0.25; - fStack_24 = fStack_2c - baseAngle * 0.25; - if (samplesEnd == (this->_bezier)._capacity) { - vector_LaserSample_emplace_reallocate(&this->_bezier,samplesEnd,&local_30); - return; - } - *samplesEnd = local_30; - samplesEnd[1] = fStack_2c; - samplesEnd[2] = fStack_28; - samplesEnd[3] = fStack_24; - *GHIDRA_CAST((samplesEnd + 4)) = CONCAT44(fStack_1c,local_20); - ppvVar1 = &(this->_bezier)._end; - *ppvVar1 = (void *)(GHIDRA_INT(*ppvVar1) + 0x18); - return; -} - -// 0099fed0 -void HomingLaser::build_wiggle_bezier() -{ - int iVar1; - Vector *endPoint; - uint32_t *in_ECX; - float fVar2; - float fVar3; - float in_XMM1_Da; - float fVar4; - float in_XMM2_Da; - float fVar5; - float in_XMM3_Da; - float handleOffsetX; - float handleOffsetY; - float dirX; - float dirY; - float startY; - void *erasedIt; - float local_5c; - float local_58; - float local_54; - float local_50; - Vector local_4c; - Vector local_44; - float maxLength; - Vector startPos; - float samplePosX; - float samplePosY; - float sampleCtrl1X; - float sampleCtrl1Y; - float sampleCtrl2X; - float sampleCtrl2Y; - float *sampleSlot; - - dirX = (float)in_ECX[3] - (float)in_ECX[1]; - startPos.x = (float)in_ECX[1]; - startY = (float)in_ECX[2]; - dirY = (float)in_ECX[4] - startY; - maxLength = in_XMM3_Da; - startPos.y = startY; - fVar2 = sqrtf(dirX * dirX + dirY * dirY); - if (0.0 < fVar2) { - dirX = dirX * (1.0 / fVar2); - dirY = dirY * (1.0 / fVar2); - } - fVar2 = cos(1.5707964); - fVar3 = sin(1.5707964); - local_54 = dirX * in_XMM1_Da; - local_50 = dirY * in_XMM1_Da; - handleOffsetX = local_54 * 0.2; - local_4c.x = (fVar2 * dirX - fVar3 * dirY) * in_XMM2_Da * 0.5; - local_44.x = (fVar3 * dirX + fVar2 * dirY) * in_XMM2_Da * 0.5; - handleOffsetY = local_50 * 0.2; - local_5c = local_54 * 0.5 - local_4c.x; - local_58 = local_50 * 0.5 - local_44.x; - iVar1 = GHIDRA_INT((in_ECX[0x13] - in_ECX[0x12])) >> 0x1f; - fVar5 = local_4c.x + local_54 * 0.5; - fVar4 = local_44.x + local_50 * 0.5; - fVar2 = handleOffsetX; - fVar3 = handleOffsetY; - if (GHIDRA_INT((in_ECX[0x13] - in_ECX[0x12])) / 0x18 + iVar1 == iVar1) { - sampleCtrl2X = handleOffsetX + startPos.x; - samplePosX = (float)in_ECX[1]; - samplePosY = (float)in_ECX[2]; - sampleCtrl2Y = startY + handleOffsetY; - sampleSlot = GHIDRA_CAST(in_ECX[0x13]); - if (sampleSlot == GHIDRA_CAST(in_ECX[0x14])) { - sampleCtrl1X = samplePosX; - sampleCtrl1Y = samplePosY; - vector_LaserSample_emplace_reallocate(in_ECX + 0x12,sampleSlot,&samplePosX); - } - else { - *sampleSlot = samplePosX; - sampleSlot[1] = samplePosY; - sampleSlot[2] = samplePosX; - sampleSlot[3] = samplePosY; - *GHIDRA_CAST((sampleSlot + 4)) = CONCAT44(sampleCtrl2Y,sampleCtrl2X); - in_ECX[0x13] = in_ECX[0x13] + 0x18; - } - } - else { - vector_LaserSample_erase(in_ECX + 0x12,&erasedIt,(void *)(in_ECX[0x13] + -0x18)); - iVar1 = in_ECX[0x13]; - startPos.x = *GHIDRA_CAST((iVar1 + -0x18)); - startY = *GHIDRA_CAST((iVar1 + -0x14)); - *GHIDRA_CAST((iVar1 + -8)) = fVar2 + startPos.x; - *GHIDRA_CAST((iVar1 + -4)) = startY + fVar3; - startPos.y = startY; - } - sampleSlot = GHIDRA_CAST(in_ECX[0x13]); - local_54 = startPos.x + local_54; - samplePosY = startY + local_58; - samplePosX = startPos.x + local_5c; - local_50 = startY + local_50; - sampleCtrl2X = fVar2 + samplePosX; - sampleCtrl1X = samplePosX - fVar2; - local_58 = startPos.x + fVar5; - sampleCtrl2Y = fVar3 + samplePosY; - local_5c = startY + fVar4; - sampleCtrl1Y = samplePosY - fVar3; - if (sampleSlot == GHIDRA_CAST(in_ECX[0x14])) { - vector_LaserSample_emplace_reallocate(in_ECX + 0x12,sampleSlot,&samplePosX); - } - else { - *sampleSlot = samplePosX; - sampleSlot[1] = samplePosY; - sampleSlot[2] = sampleCtrl1X; - sampleSlot[3] = sampleCtrl1Y; - *GHIDRA_CAST((sampleSlot + 4)) = CONCAT44(sampleCtrl2Y,sampleCtrl2X); - in_ECX[0x13] = in_ECX[0x13] + 0x18; - } - sampleCtrl2X = local_4c.x + local_54; - sampleCtrl1X = local_54 - local_4c.x; - sampleCtrl1Y = local_50 - local_44.x; - sampleSlot = GHIDRA_CAST(in_ECX[0x13]); - sampleCtrl2Y = local_44.x + local_50; - samplePosX = local_54; - samplePosY = local_50; - if (sampleSlot == GHIDRA_CAST(in_ECX[0x14])) { - vector_LaserSample_emplace_reallocate(in_ECX + 0x12,sampleSlot,&samplePosX); - } - else { - *sampleSlot = local_54; - sampleSlot[1] = local_50; - sampleSlot[2] = sampleCtrl1X; - sampleSlot[3] = sampleCtrl1Y; - *GHIDRA_CAST((sampleSlot + 4)) = CONCAT44(sampleCtrl2Y,sampleCtrl2X); - in_ECX[0x13] = in_ECX[0x13] + 0x18; - } - sampleCtrl2X = local_58 - handleOffsetX; - sampleSlot = GHIDRA_CAST(in_ECX[0x13]); - sampleCtrl2Y = local_5c - handleOffsetY; - sampleCtrl1X = handleOffsetX + local_58; - samplePosX = local_58; - sampleCtrl1Y = handleOffsetY + local_5c; - samplePosY = local_5c; - if (sampleSlot == GHIDRA_CAST(in_ECX[0x14])) { - vector_LaserSample_emplace_reallocate(in_ECX + 0x12,sampleSlot,&samplePosX); - } - else { - *sampleSlot = local_58; - sampleSlot[1] = local_5c; - sampleSlot[2] = sampleCtrl1X; - sampleSlot[3] = sampleCtrl1Y; - *GHIDRA_CAST((sampleSlot + 4)) = CONCAT44(sampleCtrl2Y,sampleCtrl2X); - in_ECX[0x13] = in_ECX[0x13] + 0x18; - } - fVar5 = fVar5 * 0.5; - sampleSlot = GHIDRA_CAST(in_ECX[0x13]); - fVar4 = fVar4 * 0.5; - sampleCtrl2X = startPos.x - fVar5; - sampleCtrl1X = fVar5 + startPos.x; - sampleCtrl2Y = startY - fVar4; - sampleCtrl1Y = startY + fVar4; - samplePosX = startPos.x; - samplePosY = startY; - if (sampleSlot == GHIDRA_CAST(in_ECX[0x14])) { - vector_LaserSample_emplace_reallocate(in_ECX + 0x12,sampleSlot,&samplePosX); - } - else { - *sampleSlot = startPos.x; - sampleSlot[1] = startY; - sampleSlot[2] = sampleCtrl1X; - sampleSlot[3] = sampleCtrl1Y; - *GHIDRA_CAST((sampleSlot + 4)) = CONCAT44(sampleCtrl2Y,sampleCtrl2X); - in_ECX[0x13] = in_ECX[0x13] + 0x18; - } - local_44.x = -dirX; - local_44.y = -dirY; - endPoint = Entity_Laser::calc_end_point(GHIDRA_CAST(*in_ECX),&local_4c,&startPos,&local_44); - fVar2 = endPoint->x; - in_ECX[3] = fVar2; - fVar3 = endPoint->y; - in_ECX[4] = fVar3; - fVar4 = sqrtf((fVar3 - startY) * (fVar3 - startY) + (fVar2 - startPos.x) * (fVar2 - startPos.x)); - if ((maxLength != 0.0) && (maxLength < fVar4)) { - fVar2 = startPos.x - dirX * maxLength; - fVar3 = startY - dirY * maxLength; - in_ECX[3] = fVar2; - in_ECX[4] = fVar3; - fVar4 = maxLength; - } - sampleSlot = GHIDRA_CAST(in_ECX[0x13]); - sampleCtrl1X = dirX * fVar4 * 0.5; - sampleCtrl1Y = dirY * fVar4 * 0.5; - sampleCtrl2X = fVar2 - sampleCtrl1X; - sampleCtrl1X = sampleCtrl1X + fVar2; - sampleCtrl2Y = fVar3 - sampleCtrl1Y; - sampleCtrl1Y = sampleCtrl1Y + fVar3; - if (sampleSlot == GHIDRA_CAST(in_ECX[0x14])) { - samplePosX = fVar2; - samplePosY = fVar3; - vector_LaserSample_emplace_reallocate(in_ECX + 0x12,sampleSlot,&samplePosX); - return; - } - *sampleSlot = fVar2; - sampleSlot[1] = fVar3; - sampleSlot[2] = sampleCtrl1X; - sampleSlot[3] = sampleCtrl1Y; - *GHIDRA_CAST((sampleSlot + 4)) = CONCAT44(sampleCtrl2Y,sampleCtrl2X); - in_ECX[0x13] = in_ECX[0x13] + 0x18; - return; -} - -// 009a0520 -uint8_t HomingLaser::clip_samples_to_grid(Vector *pos, int gridCollisionClass) -{ - uint8_t *puVar1; - char isBlocked; - int gridIndex; - uint32_t uVar2; - int samplesEnd; - float fVar3; - Vector local_24; - Vector local_1c; - float local_14; - Vector lineStart; - - if ((gridCollisionClass != 3) && (gridCollisionClass != 0)) { - samplesEnd = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x20)))); - puVar1 = &(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x1c))); - local_14 = *GHIDRA_CAST(puVar1); - uVar2 = 0; - if (samplesEnd - GHIDRA_INT(local_14) >> 3 != 0) { - local_24.x = (float)g_game->_room; - local_1c.x = (float)this; - do { - fVar3 = ((pos->x + *GHIDRA_CAST((GHIDRA_CAST(local_14) + uVar2 * 8))) - 40.0) / 40.0 + 0.5; - gridIndex = GHIDRA_INT(fVar3); - if ((((gridIndex < 0) || (*GHIDRA_CAST((GHIDRA_CAST(local_24.x) + 0xc)) <= gridIndex)) || - (gridIndex = GHIDRA_INT((((pos->y + *GHIDRA_CAST((GHIDRA_CAST(local_14) + 4 + uVar2 * 8))) - 120.0) / 40.0 - + 0.5)), gridIndex < 0)) || - (*GHIDRA_CAST((GHIDRA_CAST(local_24.x) + 0x10)) <= gridIndex)) { - gridIndex = -1; - } - else { - gridIndex = *GHIDRA_CAST((GHIDRA_CAST(local_24.x) + 0xc)) * gridIndex + GHIDRA_INT(fVar3); - } - Room::GetGridCollision(GHIDRA_CAST(local_24.x),gridIndex); - isBlocked = FUN_0070be60(); - fVar3 = local_1c.x; - if (isBlocked != '\0') { - if (uVar2 < 2) { - if (2 < GHIDRA_UINT((samplesEnd - GHIDRA_INT(local_14) >> 3))) { - msvc::vector::erase - (&local_14,GHIDRA_INT(local_14) + 0x10,*GHIDRA_CAST((GHIDRA_CAST(local_1c.x) + 0x20))); - } - if (uVar2 == 0) { - return 1; - } - } - else { - msvc::vector::erase - (&local_14,GHIDRA_INT(local_14) + uVar2 * 8,*GHIDRA_CAST((GHIDRA_CAST(local_1c.x) + 0x20))); - } - samplesEnd = *GHIDRA_CAST(puVar1); - uVar2 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x20)))) - samplesEnd >> 3; - if (1 < uVar2) { - local_1c.y = 0.0; - local_1c.x = 0.0; - local_24.x = pos->x + *GHIDRA_CAST((samplesEnd + -8 + uVar2 * 8)); - local_14 = pos->y; - local_24.y = local_14 + *GHIDRA_CAST((samplesEnd + -4 + uVar2 * 8)); - lineStart.x = pos->x + *GHIDRA_CAST((samplesEnd + -0x10 + uVar2 * 8)); - lineStart.y = local_14 + *GHIDRA_CAST((samplesEnd + -0xc + uVar2 * 8)); - Room::check_line_collision - (g_game->_room,&lineStart,&local_24,gridCollisionClass,1,samplesEnd,&local_1c) - ; - samplesEnd = *GHIDRA_CAST((GHIDRA_CAST(fVar3) + 0x20)); - *GHIDRA_CAST((samplesEnd + -8)) = local_1c.x - pos->x; - *GHIDRA_CAST((samplesEnd + -4)) = local_1c.y - local_14; - } - return 1; - } - samplesEnd = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x20)))); - uVar2 = uVar2 + 1; - local_14 = *GHIDRA_CAST(puVar1); - } while (uVar2 < GHIDRA_UINT((samplesEnd - GHIDRA_INT(local_14) >> 3))); - } - } - return 0; -} - -// 009a0740 -void HomingLaser::truncate_samples_at_player() -{ - int *playerSlot; - void *playerListEnd; - int iVar1; - Game *game; - uint32_t sampleIndex; - PlayerManager *playerManager; - uint32_t playerIndex; - float dx; - float dy; - - sampleIndex = 2; - iVar1 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x1c)))); - if (GHIDRA_UINT((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x20)))) - iVar1 >> 3)) < 3) { - return; - } - game = g_game; - do { - playerManager = &game->_playerManager; - playerIndex = 0; - if (GHIDRA_INT((game->_playerManager)._playerList._end) - GHIDRA_INT((playerManager->_playerList)._begin) >> 2 - != 0) { - do { - playerListEnd = (playerManager->_playerList)._end; - if (GHIDRA_INT(playerListEnd) - GHIDRA_INT((playerManager->_playerList)._begin) >> 2 == 0) { - KAGE_LogMessage(0x10,GHIDRA_CAST("PlayerManager::GetPlayer() : There are no players! \n")); - playerListEnd = (playerManager->_playerList)._end; - game = g_game; - } - playerSlot = (playerManager->_playerList)._begin; - if (playerIndex < GHIDRA_UINT((GHIDRA_INT(playerListEnd) - GHIDRA_INT(playerSlot) >> 2))) { - playerSlot = playerSlot + playerIndex; - } - iVar1 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x1c)))); - dx = *GHIDRA_CAST((*playerSlot + 0x33c)) - *GHIDRA_CAST((iVar1 + sampleIndex * 8)); - dy = *GHIDRA_CAST((*playerSlot + 0x340)) - *GHIDRA_CAST((iVar1 + 4 + sampleIndex * 8)); - if (dy * dy + dx * dx < 100.0) { - iVar1 = iVar1 + sampleIndex * 8; - if (iVar1 == *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x20))))) { - return; - } - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x20)))) = iVar1; - return; - } - playerManager = &game->_playerManager; - playerIndex = playerIndex + 1; - } while (playerIndex < - GHIDRA_UINT((GHIDRA_INT((game->_playerManager)._playerList._end) - - GHIDRA_INT((playerManager->_playerList)._begin) >> 2))); - } - sampleIndex = sampleIndex + 1; - if (GHIDRA_UINT((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x20)))) - iVar1 >> 3)) <= sampleIndex) { - return; - } - } while( true ); -} - -// 009a0c50 -void HomingLaser::truncate_samples_at_obstacle(Vector *positionOffset) -{ - int iVar1; - uint32_t uVar2; - float segLength; - float segDy; - float segDx; - float fVar3; - float fVar4; - Vector local_20; - Vector segStart; - Vector endPoint; - float segStartX; - float segStartY; - - iVar1 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x1c)))); - if ((iVar1 != *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x20))))) && - (uVar2 = 1, 1 < (*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x20)))) - iVar1 >> 3) - 1U)) { - while( true ) { - segStartX = *GHIDRA_CAST((iVar1 + uVar2 * 8)); - fVar4 = *GHIDRA_CAST((iVar1 + 8 + uVar2 * 8)); - segStartY = *GHIDRA_CAST((iVar1 + 4 + uVar2 * 8)); - fVar3 = *GHIDRA_CAST((iVar1 + 0xc + uVar2 * 8)); - segDx = fVar4 - segStartX; - segDy = fVar3 - segStartY; - local_20.x = segDx; - local_20.y = segDy; - segStart.x = segStartX; - segStart.y = segStartY; - segLength = sqrtf(segDy * segDy + segDx * segDx); - if (0.0 < segLength) { - local_20.x = segDx * (1.0 / segLength); - local_20.y = segDy * (1.0 / segLength); - } - Entity_Laser::CalculateEndPoint - (&endPoint,&segStart,&local_20,positionOffset,GHIDRA_CAST(0x0),20.0); - fVar3 = segStartY - fVar3; - fVar4 = segStartX - fVar4; - if ((segStartY - endPoint.y) * (segStartY - endPoint.y) + - (segStartX - endPoint.x) * (segStartX - endPoint.x) < fVar3 * fVar3 + fVar4 * fVar4) - break; - uVar2 = uVar2 + 1; - iVar1 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x1c)))); - if ((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x20)))) - iVar1 >> 3) - 1U <= uVar2) { - return; - } - } - iVar1 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x1c)))); - *GHIDRA_CAST((iVar1 + uVar2 * 8)) = endPoint.x; - *GHIDRA_CAST((iVar1 + 4 + uVar2 * 8)) = endPoint.y; - iVar1 = iVar1 + uVar2 * 8 + 8; - if (iVar1 != *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x20))))) { - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x20)))) = iVar1; - } - } - return; -} - -// 009a0de0 -void HomingLaser::remove_collinear_samples(float tolerance) -{ - uint8_t *puVar1; - int iVar2; - float *shiftCursor; - uint32_t i; - float length; - float outDirX; - float outDirY; - Vector inDir; - uint32_t lastIdx; - float *samplesEnd; - - puVar1 = &(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x1c))); - if (&this->_nonOptimizedSamples != GHIDRA_CAST(puVar1)) { - msvc::vector::assign(*GHIDRA_CAST(puVar1),*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x20)))),this); - } - iVar2 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x20)))) - *GHIDRA_CAST(puVar1) >> 3; - if (iVar2 != 0) { - lastIdx = iVar2 - 1; - i = 1; - if (1 < lastIdx) { - do { - iVar2 = *GHIDRA_CAST(puVar1); - inDir.x = *GHIDRA_CAST((iVar2 + i * 8)) - *GHIDRA_CAST((iVar2 + -8 + i * 8)); - inDir.y = *GHIDRA_CAST((iVar2 + 4 + i * 8)) - *GHIDRA_CAST((iVar2 + -4 + i * 8)); - length = sqrtf(inDir.x * inDir.x + inDir.y * inDir.y); - if (0.0 < length) { - inDir.x = inDir.x * (1.0 / length); - inDir.y = inDir.y * (1.0 / length); - } - iVar2 = iVar2 + i * 8; - shiftCursor = GHIDRA_CAST((iVar2 + 8)); - outDirX = *shiftCursor - *GHIDRA_CAST((*GHIDRA_CAST(puVar1) + i * 8)); - outDirY = *GHIDRA_CAST((iVar2 + 0xc)) - *GHIDRA_CAST((*GHIDRA_CAST(puVar1) + 4 + i * 8)); - length = sqrtf(outDirX * outDirX + outDirY * outDirY); - if (0.0 < length) { - outDirX = outDirX * (1.0 / length); - outDirY = outDirY * (1.0 / length); - } - if (ABS(1.0 - (inDir.x * outDirX + inDir.y * outDirY)) < tolerance) { - samplesEnd = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x20)))); - for (; shiftCursor != samplesEnd; shiftCursor = shiftCursor + 2) { - shiftCursor[-2] = *shiftCursor; - shiftCursor[-1] = shiftCursor[1]; - } - i = i - 1; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x20)))) = samplesEnd + -2; - lastIdx = lastIdx - 1; - } - i = i + 1; - } while (i < lastIdx); - } - } - return; -} - -// 009a0fa0 -void HomingLaser::apply_sample_wiggle(float amplitude, float phase) -{ - int samples; - int wavePeriod; - float *sampleY; - float fVar2; - float fVar3; - float segDx; - float radialX; - float local_24; - float local_20; - int samples; - - samples = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x1c)))); - if (samples != *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x20))))) { - samples = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x20)))) - samples >> 3; - if (*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x40)))) == 1) { - local_20 = 0.0; - if (samples != 0) { - do { - radialX = *GHIDRA_CAST((samples + GHIDRA_INT(local_20) * 8)) - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))); - fVar3 = *GHIDRA_CAST((samples + 4 + GHIDRA_INT(local_20) * 8)); - local_24 = fVar3 - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x8)))); - fVar2 = sqrtf(radialX * radialX + local_24 * local_24); - if (0.0 < fVar2) { - radialX = radialX * (1.0 / fVar2); - local_24 = local_24 * (1.0 / fVar2); - } - samples = (*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x20)))) - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x1c)))) >> 3) + -1; - fVar2 = sin(((float)((double)GHIDRA_INT(local_20) + - __uint_to_double_fixup[-(GHIDRA_INT(local_20) >> 0x1f)]) * 25.132742) / - (float)((double)samples + __uint_to_double_fixup[-(samples >> 0x1f)]) - - (float)g_game->_frameCount * 0.16); - *GHIDRA_CAST((samples + GHIDRA_INT(local_20) * 8)) = - radialX * fVar2 * 10.0 * amplitude + *GHIDRA_CAST((samples + GHIDRA_INT(local_20) * 8)); - *GHIDRA_CAST((samples + 4 + GHIDRA_INT(local_20) * 8)) = local_24 * fVar2 * 10.0 * amplitude + fVar3; - local_20 = (float)(GHIDRA_INT(local_20) + 1); - } while (GHIDRA_UINT(local_20) < GHIDRA_UINT((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x20)))) - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x1c)))) >> 3)) - ); - return; - } - } - else { - fVar3 = this->_totalLength / 500.0; - local_24 = 2.8026e-45; - if (fVar3 <= 0.0) { - fVar3 = 0.0; - } - if (1.0 <= fVar3) { - fVar3 = 1.0; - } - wavePeriod = GHIDRA_INT((15.0 - fVar3 * 11.0)); - if (2 < samples - 3U) { - sampleY = GHIDRA_CAST((samples + 0x14)); - do { - segDx = sampleY[1] - sampleY[-1]; - fVar3 = *sampleY; - local_20 = sampleY[2] - fVar3; - fVar2 = sqrtf(segDx * segDx + local_20 * local_20); - if (0.0 < fVar2) { - segDx = segDx * (1.0 / fVar2); - local_20 = local_20 * (1.0 / fVar2); - } - fVar2 = sin((float)g_game->_frameCount * 0.1 + phase); - fVar2 = fVar2 * 20.0 * amplitude; - if (GHIDRA_INT(local_24) % (wavePeriod * 2) < wavePeriod) { - fVar2 = -fVar2; - } - local_24 = (float)(GHIDRA_INT(local_24) + 1); - sampleY[-1] = local_20 * fVar2 + sampleY[-1]; - *sampleY = -segDx * fVar2 + fVar3; - sampleY = sampleY + 2; - } while (GHIDRA_UINT(local_24) < (*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x20)))) - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x1c)))) >> 3) - 3U) - ; - } - } - } - return; -} - -// 009a12b0 -uint32_t HomingLaser::find_targets(float *param_1, float *param_2, int param_3, uint32_t param_4, Entity *param_5) -{ - Vector *start; - uint64_t qVar1; - uint8_t bVar2; - Entity *ancestor; - int in_ECX; - uint32_t candidateCount; - uint32_t candidateIndex; - uint64_t *allocatedBytes; - int candidateData; - uint32_t hitEntity; - float in_XMM0_Da; - float fVar3; - float fVar4; - float fVar5; - EntityList_EL candidates; - Vector targetPosX; - float projT; - int homingLaser; - void *local_10; - uint8_t *puStack_c; - uint32_t local_8; - Entity *candidate; - float *nextSample; - int target; - - local_8 = 0xffffffff; - puStack_c = &LAB_00b0da3d; - local_10 = ExceptionList; - if (*GHIDRA_CAST((in_ECX + 0x1c)) == *GHIDRA_CAST((in_ECX + 0x20))) { - return 0; - } - ExceptionList = &local_10; - homingLaser = in_ECX; - EntityList::QuerySublist - (GHIDRA_CAST((GHIDRA_INT(g_game->_room) + 0x1218)),&candidates,param_3,param_4,-1,0,0); - local_8 = 0; - param_4 = 1; - if (1 < (*GHIDRA_CAST((in_ECX + 0x20)) - *GHIDRA_CAST((in_ECX + 0x1c)) >> 3) - 1U) { - candidateCount = candidates._size; - candidateData = (*GHIDRA_CAST((GHIDRA_CAST(&(candidates)) + 0x4))); - do { - candidateIndex = 0; - if (candidateCount != 0) { - do { - if (param_5 == GHIDRA_CAST(0x0)) { -LAB_009a1371: - candidateData = *GHIDRA_CAST((in_ECX + 0x1c)); - start = GHIDRA_CAST((candidateData + param_4 * 8)); - target = *GHIDRA_CAST(((*GHIDRA_CAST((GHIDRA_CAST(&(candidates)) + 0x4))) + candidateIndex * 4)); - targetPosX.x = *GHIDRA_CAST((target + 0x33c)); - targetPosX.y = *GHIDRA_CAST((target + 0x340)); - segment_project_point(&targetPosX,start,start + 1,&projT); - if (in_XMM0_Da < *GHIDRA_CAST((target + 0x370)) * *GHIDRA_CAST((target + 0x370))) { - fVar4 = *GHIDRA_CAST((candidateData + 8 + param_4 * 8)) - - *GHIDRA_CAST((candidateData + param_4 * 8)); - fVar5 = *GHIDRA_CAST((candidateData + 0xc + param_4 * 8)) - - *GHIDRA_CAST((candidateData + 4 + param_4 * 8)); - fVar3 = sqrtf(fVar4 * fVar4 + fVar5 * fVar5); - if (0.0 < fVar3) { - fVar4 = fVar4 * (1.0 / fVar3); - fVar5 = fVar5 * (1.0 / fVar3); - } - nextSample = GHIDRA_CAST((candidateData + (param_4 + 1) * 8)); - param_2[1] = fVar5; - *param_2 = fVar4; - fVar3 = *GHIDRA_CAST((candidateData + param_4 * 8)); - fVar4 = *GHIDRA_CAST((candidateData + 4 + param_4 * 8)); - fVar5 = nextSample[1]; - fVar3 = fVar3 + (*nextSample - fVar3) * projT; - *param_1 = fVar3; - param_1[1] = fVar4 + (fVar5 - fVar4) * projT; - *nextSample = fVar3; - nextSample[1] = param_1[1]; - if (nextSample != *GHIDRA_CAST((homingLaser + 0x20))) { - *GHIDRA_CAST((homingLaser + 0x20)) = nextSample; - } - hitEntity = *GHIDRA_CAST(((*GHIDRA_CAST((GHIDRA_CAST(&(candidates)) + 0x4))) + candidateIndex * 4)); - goto LAB_009a13e5; - } - candidateData = (*GHIDRA_CAST((GHIDRA_CAST(&(candidates)) + 0x4))); - } - else { - candidate = *GHIDRA_CAST((candidateData + candidateIndex * 4)); - ancestor = Entity::GetPlayerAncestor(param_5); - bVar2 = Entity::IsDescendantOf(candidate,ancestor); - if (bVar2 == 0) { - in_ECX = homingLaser; - goto LAB_009a1371; - } - } - candidateIndex = candidateIndex + 1; - candidateCount = candidates._size; - in_ECX = homingLaser; - } while (candidateIndex < GHIDRA_UINT(candidates._size)); - } - param_4 = param_4 + 1; - } while (param_4 < (*GHIDRA_CAST((in_ECX + 0x20)) - *GHIDRA_CAST((in_ECX + 0x1c)) >> 3) - 1U); - } - hitEntity = 0; -LAB_009a13e5: - if ((*GHIDRA_CAST((GHIDRA_CAST(&(candidates)) + 0x0))) == '\0') { - if (g_mainHeap == (void *)0x0) { - allocatedBytes = &g_allocatedBytesNoHeap; - } - else { - allocatedBytes = GHIDRA_CAST((GHIDRA_INT(g_mainHeap) + 0x30)); - } - if ((*GHIDRA_CAST((GHIDRA_CAST(&(candidates)) + 0x4))) != 0) { - candidateCount = *GHIDRA_CAST(((*GHIDRA_CAST((GHIDRA_CAST(&(candidates)) + 0x4))) + -4)); - qVar1 = *allocatedBytes; - *GHIDRA_CAST(allocatedBytes) = GHIDRA_UINT(*allocatedBytes) - candidateCount; - *GHIDRA_CAST((GHIDRA_CAST(allocatedBytes) + 4)) = - *GHIDRA_CAST((GHIDRA_CAST(allocatedBytes) + 4)) - GHIDRA_UINT((GHIDRA_UINT(qVar1) < candidateCount)); - free((void *)((*GHIDRA_CAST((GHIDRA_CAST(&(candidates)) + 0x4))) + -4)); - } - } - ExceptionList = local_10; - return hitEntity; -} - -// 009a1520 -uint8_t HomingLaser::truncate_samples(float maxLength) -{ - float *pfVar1; - int iVar2; - uint32_t uVar3; - float segmentLength; - float dy; - float dx; - float remainingLength; - float *sample; - float sampleY; - - sample = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x1c)))); - if (sample != *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x20))))) { - uVar3 = 0; - iVar2 = GHIDRA_INT(*(float **))&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x20))) - GHIDRA_INT(sample) >> 3; - if (iVar2 != 1) { - remainingLength = maxLength; - do { - sampleY = sample[1]; - dy = sample[3] - sampleY; - dx = sample[2] - *sample; - segmentLength = sqrtf(dy * dy + dx * dx); - if (remainingLength <= segmentLength) { - iVar2 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x1c)))) + uVar3 * 8; - pfVar1 = GHIDRA_CAST((iVar2 + 8)); - *pfVar1 = (dx * remainingLength) / segmentLength + *sample; - *GHIDRA_CAST((iVar2 + 0xc)) = (dy * remainingLength) / segmentLength + sampleY; - if (pfVar1 != *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x20))))) { - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x20)))) = pfVar1; - } - return 1; - } - remainingLength = remainingLength - segmentLength; - uVar3 = uVar3 + 1; - sample = sample + 2; - } while (uVar3 < iVar2 - 1U); - } - } - return 0; -} diff --git a/generated-src/npc_helper.cpp b/generated-src/npc_helper.cpp index 99c8918..54e3443 100644 --- a/generated-src/npc_helper.cpp +++ b/generated-src/npc_helper.cpp @@ -7458,171 +7458,6 @@ LAB_00548a4b: return; } -// 0054ccc0 -void NpcHelper::bulb_player_collision(Entity_NPC *npc, Entity *collider) -{ - EntityRef *sourceRef; - uint32_t uVar1; - int chargeChange; - Entity *effect; - uint32_t uVar2; - float proceduralIdx; - float fVar3; - Game *game; - bool bVar4; - float fVar5; - int itemConfig; - Vector local_3c; - Entity_NPC *npcLocal; - EntityRef damageSource; - Manager *manager; - - npcLocal = npc; - if (npc->_variant == 6) { - if ((collider->_type == 1) || (collider->_type == 3)) { - damageSource._position.x = (npc->_pos).x; - damageSource._position.y = (npc->_pos).y; - damageSource._type = npc->_type; - damageSource._spawnerType = npc->_spawnerType; - damageSource._spawnerVariant = npc->_spawnerVariant; - damageSource._velocity.x = (npc->_velocity).x; - damageSource._velocity.y = (npc->_velocity).y; - damageSource._variant = 6; - local_3c.x = (float)GHIDRA_UINT(((npc->_flags & 0x100) != 0)); - if ((npc->_flags & 0x20000000) == 0) { - uVar2 = 0; - } - else { - uVar2 = 2; - } - if ((npc->_flags & 0x40000000000000) == 0) { - uVar1 = 0; - } - else { - uVar1 = 4; - } - damageSource._flags = uVar1 | uVar2 | GHIDRA_UINT(local_3c.x); - damageSource._entity = npc; - (**(code **)(*GHIDRA_CAST(collider) + 0x20))(0x3f800000,0,0,&damageSource,0x1e); - } - else { - sourceRef = EntityRef::EntityRef(&damageSource); - (**(code **)(*GHIDRA_CAST(collider) + 0x20))(0x41200000,0,0,sourceRef,0x1e); - } - npc->_state = 6; - fVar5 = -(npc->_v1).x; - proceduralIdx = -(npc->_v1).y; - (npc->_v1).x = fVar5; - (npc->_v1).y = proceduralIdx; - npc->_stateFrame = 4; - fVar3 = (npc->_pos).y; - (npc->_targetPosition).x = fVar5 * 80.0 + (npc->_pos).x; - (npc->_targetPosition).y = proceduralIdx * 80.0 + fVar3; - fVar3 = (npc->_v1).y; - proceduralIdx = npc->_speedMultiplier; - (npc->_velocity).x = (npc->_v1).x * 16.0 * proceduralIdx + (npc->_velocity).x; - (npc->_velocity).y = fVar3 * 16.0 * proceduralIdx + (npc->_velocity).y; - return; - } - if ((collider == GHIDRA_CAST(0x0)) || (collider->_type != 1)) { - return; - } - npc->_state = 6; - proceduralIdx = -(npc->_v1).x; - fVar5 = -(npc->_v1).y; - npc->_stateFrame = 4; - (npc->_v1).x = proceduralIdx; - (npc->_v1).y = fVar5; - fVar3 = (npc->_pos).x; - (npc->_targetPosition).y = fVar5 * 80.0 + (npc->_pos).y; - (npc->_targetPosition).x = proceduralIdx * 80.0 + fVar3; - fVar3 = npc->_speedMultiplier; - (npc->_velocity).x = proceduralIdx * 16.0 * fVar3 + (npc->_velocity).x; - (npc->_velocity).y = fVar5 * 16.0 * fVar3 + (npc->_velocity).y; - Entity_Player::PlayExtraAnimation(GHIDRA_CAST(collider),&DAT_00b1d3b0); - Entity_Player::ResetItemState(GHIDRA_CAST(collider)); - uVar2 = 0; - game = g_game; - do { - fVar3 = collider[5]._sprite._championColor._colorize[uVar2 * 8 + 1]; - if (game == GHIDRA_CAST(0x0)) { - if (-1 < GHIDRA_INT(fVar3)) goto LAB_0054cfd6; -LAB_0054d012: - itemConfig = 0; - } - else if (GHIDRA_INT(fVar3) < 0) { - proceduralIdx = (float)~GHIDRA_UINT(fVar3); - bVar4 = -1 < GHIDRA_INT(fVar3); - fVar3 = proceduralIdx; - if ((bVar4) || - (GHIDRA_INT((game->_proceduralItemManager)._proceduralItems._end) - - GHIDRA_INT((game->_proceduralItemManager)._proceduralItems._begin) >> 2 <= GHIDRA_INT(proceduralIdx))) - goto LAB_0054d012; - itemConfig = **GHIDRA_CAST((GHIDRA_INT((game->_proceduralItemManager)._proceduralItems._begin) + - GHIDRA_INT(proceduralIdx) * 4)); - } - else { -LAB_0054cfd6: - if (GHIDRA_INT((g_manager->_itemConfig)._collectibles._end) - - GHIDRA_INT((g_manager->_itemConfig)._collectibles._begin) >> 2 <= GHIDRA_INT(fVar3)) goto LAB_0054d012; - itemConfig = *GHIDRA_CAST((GHIDRA_INT((g_manager->_itemConfig)._collectibles._begin) + GHIDRA_INT(fVar3) * 4)); - game = g_game; - } - if (uVar2 == 3) { - local_3c.x = 0.0; - } - else if (((uVar2 == 2) && - ((*GHIDRA_CAST((GHIDRA_CAST(&(chargeChange)) + 0x0))) = collider[5]._valid, (*GHIDRA_CAST((GHIDRA_CAST(&(chargeChange)) + 0x1))) = collider[5]._visible, - (*GHIDRA_CAST((GHIDRA_CAST(&(chargeChange)) + 0x2))) = collider[5]._exists, (*GHIDRA_CAST((GHIDRA_CAST(&(chargeChange)) + 0x3))) = collider[5]._dead, - chargeChange == 0x244)) && (game->_challenge == 0x2c)) { - local_3c.x = 0.0; - } - else { - local_3c.x = (float)Entity_Player::GetCollectibleMaxCharge - (GHIDRA_CAST(collider), - GHIDRA_INT(collider[5]._sprite._championColor._colorize) - [uVar2 * 8 + 1], - *GHIDRA_CAST((GHIDRA_INT((&collider[5]._sprite._championColor + 1)) + - uVar2 * 0x20 + 4)),GHIDRA_INT(fVar3)); - game = g_game; - } - if (((itemConfig != 0) && (0 < GHIDRA_INT(local_3c.x))) && - ((uVar2 < 4 && (0 < GHIDRA_INT(collider[5]._sprite._championColor._colorize[uVar2 * 8 + 3]))))) { - chargeChange = Entity_Player::GetActiveMaxCharge(GHIDRA_CAST(collider),uVar2); - if (chargeChange == 1) { - chargeChange = -1000; - } - else if (GHIDRA_INT(local_3c.x) < 0xd) { - chargeChange = -2; - } - else { - chargeChange = GHIDRA_INT(((uint64_t)((int64_t)GHIDRA_INT(local_3c.x) * 0x55555555) >> 0x20)) - - GHIDRA_INT(local_3c.x); - chargeChange = (chargeChange >> 1) - (chargeChange >> 0x1f); - } - Entity_Player::AddActiveCharge(GHIDRA_CAST(collider),chargeChange,uVar2,0,0,0); - HUD::FlashChargeBar(&g_game->_hud,GHIDRA_CAST(collider),uVar2); - manager = g_manager; - local_3c.x = 6.9084e-43; - seed_fart_sound_override(GHIDRA_CAST(&local_3c)); - (GHIDRA_CAST((&manager->_sfxManager)))->SoundEffects::Play(GHIDRA_INT(local_3c.x),1.0,2,0,1.0,0.0); - uVar2 = Random(); - local_3c.x = (collider->_pos).x; - local_3c.y = (collider->_pos).y; - effect = Game::SpawnEx(g_game,1000,0x31,&local_3c,&g_vectorZero,GHIDRA_CAST(0x0),3,uVar2,0); - (effect->_sprite)._offset.x = 0.0; - (effect->_sprite)._offset.y = -24.0; - effect->_renderDepthOffset = 1.0; - npcLocal->_projectileCooldown = npcLocal->_projectileCooldown + 1; - return; - } - uVar2 = uVar2 + 1; - if (3 < uVar2) { - return; - } - } while( true ); -} - // 0054f670 void NpcHelper::needle_render(Entity_NPC *npc) { diff --git a/generated-src/stubs.cpp b/generated-src/stubs.cpp index dc67d3e..739c795 100644 --- a/generated-src/stubs.cpp +++ b/generated-src/stubs.cpp @@ -8237,10 +8237,6 @@ BitSet128 * BitSet128::operator_or(BitSet128 *outResult, BitSet128 *a, BitSet128 uint8_t BitSet128::IsZero() { generated_stub("BitSet128::IsZero 00592230"); } void BossOverlay::update() { generated_stub("BossOverlay::update 004212c0"); } void BossOverlay::play(int overlayType) { generated_stub("BossOverlay::play 004214b0"); } -void Capsule::constructor(Vector *position, Vector *multiplier, float rotation, float size) { generated_stub("Capsule::constructor 00945190"); } -void Capsule::constructor2(Vector *Position, Vector *TargetPosition, float size) { generated_stub("Capsule::constructor2 009452e0"); } -void Capsule::get_bounding_box(Vector *outMin, Vector *outMax) { generated_stub("Capsule::get_bounding_box 00945400"); } -uint8_t Capsule::Collide(Capsule *a, Capsule *b, Vector *outHit) { generated_stub("Capsule::Collide 00945470"); } Color::Color() { generated_stub("Color::Color 00407170"); } ColorMod * Color::operator_assign(ColorMod *other) { generated_stub("Color::operator_assign 004071c0"); } float Color::R() { generated_stub("Color::R 00407240"); } @@ -8389,22 +8385,6 @@ FriendEntry::~FriendEntry() { generated_stub("FriendEntry::~FriendEntry 008e1f30 void * GlitchedCollectibleGfx::constructor() { generated_stub("GlitchedCollectibleGfx::constructor 009dc6e0"); } void GlitchedItemSet::recalculate() { generated_stub("GlitchedItemSet::recalculate 009e0500"); } void HallucinationOverlay::Render(Vector *offset) { generated_stub("HallucinationOverlay::Render 00839550"); } -HomingLaser * HomingLaser::operator_assign(HomingLaser *other) { generated_stub("HomingLaser::operator_assign 0085e000"); } -HomingLaser::HomingLaser() { generated_stub("HomingLaser::HomingLaser 0099c290"); } -void HomingLaser::build_bezier_path(int homingType, Entity *source) { generated_stub("HomingLaser::build_bezier_path 0099c790"); } -void HomingLaser::compute_axis_bezier_handles() { generated_stub("HomingLaser::compute_axis_bezier_handles 0099dca0"); } -void HomingLaser::compute_bezier_handles(float tension) { generated_stub("HomingLaser::compute_bezier_handles 0099e160"); } -void HomingLaser::CalculateSamples(float param_2) { generated_stub("HomingLaser::CalculateSamples 0099e360"); } -void HomingLaser::apply_sine_offset(float amplitude, float phase) { generated_stub("HomingLaser::apply_sine_offset 0099ec00"); } -void HomingLaser::build_curl_path(float radius) { generated_stub("HomingLaser::build_curl_path 0099fa60"); } -void HomingLaser::build_wiggle_bezier() { generated_stub("HomingLaser::build_wiggle_bezier 0099fed0"); } -uint8_t HomingLaser::clip_samples_to_grid(Vector *pos, int gridCollisionClass) { generated_stub("HomingLaser::clip_samples_to_grid 009a0520"); } -void HomingLaser::truncate_samples_at_player() { generated_stub("HomingLaser::truncate_samples_at_player 009a0740"); } -void HomingLaser::truncate_samples_at_obstacle(Vector *positionOffset) { generated_stub("HomingLaser::truncate_samples_at_obstacle 009a0c50"); } -void HomingLaser::remove_collinear_samples(float tolerance) { generated_stub("HomingLaser::remove_collinear_samples 009a0de0"); } -void HomingLaser::apply_sample_wiggle(float amplitude, float phase) { generated_stub("HomingLaser::apply_sample_wiggle 009a0fa0"); } -uint32_t HomingLaser::find_targets(float *param_1, float *param_2, int param_3, uint32_t param_4, Entity *param_5) { generated_stub("HomingLaser::find_targets 009a12b0"); } -uint8_t HomingLaser::truncate_samples(float maxLength) { generated_stub("HomingLaser::truncate_samples 009a1520"); } void * InputManager::GetDeviceByPlayerEntity(Entity_Player *player) { generated_stub("InputManager::GetDeviceByPlayerEntity 0090ac70"); } int InputManager::FirstLocalDeviceID() { generated_stub("InputManager::FirstLocalDeviceID 0090aeb0"); } float InputManager::GetActionValue(int action, int controllerIndex, Entity *entity, int unused) { generated_stub("InputManager::GetActionValue 009562d0"); } @@ -9296,7 +9276,6 @@ void NpcHelper::bouncer_death_gib(Entity_Effect *timer) { generated_stub("NpcHel void NpcHelper::migraine_timer_spawn(Entity *timer) { generated_stub("NpcHelper::migraine_timer_spawn 00528ec0"); } uint8_t NpcHelper::tarboy_is_creep_near(Entity_NPC *npc, Vector *position) { generated_stub("NpcHelper::tarboy_is_creep_near 005441e0"); } void NpcHelper::leper_flesh_ai(Entity_NPC *npc) { generated_stub("NpcHelper::leper_flesh_ai 00548720"); } -void NpcHelper::bulb_player_collision(Entity_NPC *npc, Entity *collider) { generated_stub("NpcHelper::bulb_player_collision 0054ccc0"); } void NpcHelper::needle_render(Entity_NPC *npc) { generated_stub("NpcHelper::needle_render 0054f670"); } Vector * NpcHelper::willo_slot(Entity_NPC *npc, Vector *outPos, int slot) { generated_stub("NpcHelper::willo_slot 00557f70"); } void NpcHelper::willo_get_target_pos(Entity_NPC *npc, Vector *outPos, float *outSpread) { generated_stub("NpcHelper::willo_get_target_pos 00558070"); } @@ -9475,26 +9454,6 @@ uint8_t Weapon_Bone::CanTriggerCursedEyeTeleport() { generated_stub("Weapon_Bone uint8_t Weapon_Bone::CanTriggerKidneyStone() { generated_stub("Weapon_Bone::CanTriggerKidneyStone 009ff210"); } uint8_t Weapon_Bone::CanOverrideForgottenThrow() { generated_stub("Weapon_Bone::CanOverrideForgottenThrow 009ff230"); } void Weapon_Bone::init_club(int *param_1) { generated_stub("Weapon_Bone::init_club 009ff0c0"); } -Weapon_Brimstone::~Weapon_Brimstone() { generated_stub("Weapon_Brimstone::~Weapon_Brimstone 009f9a20"); } -void Weapon_Brimstone::Init(uint32_t param_2, uint32_t param_3) { generated_stub("Weapon_Brimstone::Init 009f34d0"); } -void Weapon_Brimstone::Update(char param_2) { generated_stub("Weapon_Brimstone::Update 009f34f0"); } -void Weapon_Brimstone::Fire(Vector *direction, uint8_t isShooting, uint8_t isInterpolated) { generated_stub("Weapon_Brimstone::Fire 009ff360"); } -void Weapon_Brimstone::Reset() { generated_stub("Weapon_Brimstone::Reset 009f3480"); } -void Weapon_Brimstone::ClearReferences() { generated_stub("Weapon_Brimstone::ClearReferences 00a02790"); } -long double Weapon_Brimstone::GetMaxCharge() { generated_stub("Weapon_Brimstone::GetMaxCharge 00a00f30"); } -long double Weapon_Brimstone::GetChargeBarAmount() { generated_stub("Weapon_Brimstone::GetChargeBarAmount 009f4150"); } -void Weapon_Brimstone::vfunc_8() { generated_stub("Weapon_Brimstone::vfunc_8 009f3130"); } -uint32_t Weapon_Brimstone::GetFocusEntity() { generated_stub("Weapon_Brimstone::GetFocusEntity 00a02870"); } -uint32_t Weapon_Brimstone::GetMainEntity() { generated_stub("Weapon_Brimstone::GetMainEntity 009f3160"); } -void Weapon_Brimstone::guard_check_icall() { generated_stub("Weapon_Brimstone::guard_check_icall 0040c200"); } -int Weapon_Brimstone::GetMarkedTargetVariant() { generated_stub("Weapon_Brimstone::GetMarkedTargetVariant 00a02800"); } -uint8_t Weapon_Brimstone::CanShutDoors() { generated_stub("Weapon_Brimstone::CanShutDoors 005ccc00"); } -uint8_t Weapon_Brimstone::CanTriggerCursedEyeTeleport() { generated_stub("Weapon_Brimstone::CanTriggerCursedEyeTeleport 005ccc00"); } -uint8_t Weapon_Brimstone::CanTriggerKidneyStone() { generated_stub("Weapon_Brimstone::CanTriggerKidneyStone 005ccc00"); } -uint8_t Weapon_Brimstone::CanOverrideForgottenThrow() { generated_stub("Weapon_Brimstone::CanOverrideForgottenThrow 005ccc00"); } -void Weapon_Brimstone::fire_c_section_fetuses() { generated_stub("Weapon_Brimstone::fire_c_section_fetuses 00a00d10"); } -void Weapon_Brimstone::init_laser(Entity_Laser *laser) { generated_stub("Weapon_Brimstone::init_laser 00a00f90"); } -void Weapon_Brimstone::fire(float Speed, uint8_t IgnoreStatusEffects) { generated_stub("Weapon_Brimstone::fire 00a02890"); } Weapon_Deathmatch::~Weapon_Deathmatch() { generated_stub("Weapon_Deathmatch::~Weapon_Deathmatch 009f3260"); } void Weapon_Deathmatch::Init(uint32_t param_2, uint32_t param_3) { generated_stub("Weapon_Deathmatch::Init 009f34d0"); } void Weapon_Deathmatch::Update(char param_2) { generated_stub("Weapon_Deathmatch::Update 009f34f0"); } @@ -9547,24 +9506,6 @@ uint8_t Weapon_Knife::CanShutDoors() { generated_stub("Weapon_Knife::CanShutDoor void Weapon_Knife::vfunc_15() { generated_stub("Weapon_Knife::vfunc_15 005ccc00"); } void Weapon_Knife::vfunc_16() { generated_stub("Weapon_Knife::vfunc_16 005ccc00"); } void Weapon_Knife::init_knife(Entity_Knife *knife) { generated_stub("Weapon_Knife::init_knife 00a05070"); } -Weapon_Laser::~Weapon_Laser() { generated_stub("Weapon_Laser::~Weapon_Laser 009f9930"); } -void Weapon_Laser::Init(uint32_t param_2, uint32_t param_3) { generated_stub("Weapon_Laser::Init 009f34d0"); } -void Weapon_Laser::Update(char param_2) { generated_stub("Weapon_Laser::Update 009f34f0"); } -void Weapon_Laser::Fire(Vector *param_1, uint8_t param_2, uint8_t param_3) { generated_stub("Weapon_Laser::Fire 00a052b0"); } -void Weapon_Laser::Reset() { generated_stub("Weapon_Laser::Reset 00a052a0"); } -void Weapon_Laser::ClearReferences() { generated_stub("Weapon_Laser::ClearReferences 00a063b0"); } -long double Weapon_Laser::GetMaxCharge() { generated_stub("Weapon_Laser::GetMaxCharge 00a06870"); } -long double Weapon_Laser::GetChargeBarAmount() { generated_stub("Weapon_Laser::GetChargeBarAmount 009f4150"); } -void Weapon_Laser::vfunc_8() { generated_stub("Weapon_Laser::vfunc_8 009f3130"); } -Entity * Weapon_Laser::GetFocusEntity() { generated_stub("Weapon_Laser::GetFocusEntity 009fa190"); } -Entity * Weapon_Laser::GetMainEntity() { generated_stub("Weapon_Laser::GetMainEntity 009f3150"); } -void Weapon_Laser::guard_check_icall() { generated_stub("Weapon_Laser::guard_check_icall 0040c200"); } -int Weapon_Laser::GetMarkedTargetVariant() { generated_stub("Weapon_Laser::GetMarkedTargetVariant 00a02800"); } -uint8_t Weapon_Laser::CanShutDoors() { generated_stub("Weapon_Laser::CanShutDoors 005ccc00"); } -uint8_t Weapon_Laser::CanTriggerCursedEyeTeleport() { generated_stub("Weapon_Laser::CanTriggerCursedEyeTeleport 00a068e0"); } -uint8_t Weapon_Laser::SupportsTractorBeam() { generated_stub("Weapon_Laser::SupportsTractorBeam 00a05060"); } -void Weapon_Laser::vfunc_16() { generated_stub("Weapon_Laser::vfunc_16 005ccc00"); } -void Weapon_Laser::init_laser(Weapon *weapon, Entity_Laser *laser) { generated_stub("Weapon_Laser::init_laser 00a06330"); } Weapon_Ludovico::~Weapon_Ludovico() { generated_stub("Weapon_Ludovico::~Weapon_Ludovico 009f9880"); } void Weapon_Ludovico::Init(uint32_t param_2, uint32_t param_3) { generated_stub("Weapon_Ludovico::Init 009f34d0"); } void Weapon_Ludovico::Update(char param_2) { generated_stub("Weapon_Ludovico::Update 009f34f0"); } @@ -9634,23 +9575,6 @@ uint8_t Weapon_SpiritSword::CanShutDoors() { generated_stub("Weapon_SpiritSword: void Weapon_SpiritSword::vfunc_14() { generated_stub("Weapon_SpiritSword::vfunc_14 005ccc00"); } void Weapon_SpiritSword::vfunc_15() { generated_stub("Weapon_SpiritSword::vfunc_15 005ccc00"); } void Weapon_SpiritSword::vfunc_16() { generated_stub("Weapon_SpiritSword::vfunc_16 005ccc00"); } -Weapon_TechX::~Weapon_TechX() { generated_stub("Weapon_TechX::~Weapon_TechX 009f3260"); } -void Weapon_TechX::Init(uint32_t param_2, uint32_t param_3) { generated_stub("Weapon_TechX::Init 009f34d0"); } -void Weapon_TechX::Update(char param_2) { generated_stub("Weapon_TechX::Update 009f34f0"); } -void Weapon_TechX::Fire(Vector *direction, uint8_t isShooting, uint8_t isInterpolated) { generated_stub("Weapon_TechX::Fire 00a0d9c0"); } -void Weapon_TechX::Reset() { generated_stub("Weapon_TechX::Reset 009f3480"); } -void Weapon_TechX::ClearReferences() { generated_stub("Weapon_TechX::ClearReferences 009f3320"); } -float Weapon_TechX::GetMaxCharge() { generated_stub("Weapon_TechX::GetMaxCharge 00a0e260"); } -long double Weapon_TechX::GetChargeBarAmount() { generated_stub("Weapon_TechX::GetChargeBarAmount 009f4150"); } -void Weapon_TechX::vfunc_8() { generated_stub("Weapon_TechX::vfunc_8 009f3130"); } -uint32_t Weapon_TechX::GetFocusEntity() { generated_stub("Weapon_TechX::GetFocusEntity 009f3140"); } -void Weapon_TechX::vfunc_10() { generated_stub("Weapon_TechX::vfunc_10 009f3140"); } -void Weapon_TechX::guard_check_icall() { generated_stub("Weapon_TechX::guard_check_icall 0040c200"); } -uint32_t Weapon_TechX::GetMarkedTargetVariant() { generated_stub("Weapon_TechX::GetMarkedTargetVariant 00a08cd0"); } -uint8_t Weapon_TechX::CanTakeDamageFromTearEffects() { generated_stub("Weapon_TechX::CanTakeDamageFromTearEffects 00709c30"); } -uint8_t Weapon_TechX::CanShutDoors() { generated_stub("Weapon_TechX::CanShutDoors 005ccc00"); } -void Weapon_TechX::vfunc_15() { generated_stub("Weapon_TechX::vfunc_15 00709c30"); } -void Weapon_TechX::vfunc_16() { generated_stub("Weapon_TechX::vfunc_16 005ccc00"); } Weapon_UmbilicalWhip::~Weapon_UmbilicalWhip() { generated_stub("Weapon_UmbilicalWhip::~Weapon_UmbilicalWhip 009f9880"); } void Weapon_UmbilicalWhip::Init(uint32_t param_2, uint32_t param_3) { generated_stub("Weapon_UmbilicalWhip::Init 009f34d0"); } void Weapon_UmbilicalWhip::Update(char param_2) { generated_stub("Weapon_UmbilicalWhip::Update 009f34f0"); } @@ -10207,23 +10131,16 @@ void FUN_00456820() { generated_stub("FUN_00456820 00456820"); } void FUN_00456830(uint32_t param_1, uint32_t param_2, uint32_t param_3, uint32_t param_4) { generated_stub("FUN_00456830 00456830"); } int FUN_00456880() { generated_stub("FUN_00456880 00456880"); } void NpcAI::ENTITY_FLY_isaac_spawned(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_FLY_isaac_spawned 004568d0"); } -void NpcAI::ENTITY_FAMINE(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_FAMINE 00456c40"); } -void NpcAI::ENTITY_PESTILENCE(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_PESTILENCE 00457840"); } void NpcAI::ENTITY_WAR(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_WAR 00458870"); } void NpcAI::ENTITY_DEATH(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_DEATH 00459d20"); } void NpcAI::ENTITY_FALLEN(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_FALLEN 0045b830"); } void NpcAI::ENTITY_HEADLESS_HORSEMAN(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_HEADLESS_HORSEMAN 0045cd60"); } void NpcAI::ENTITY_DARK_ONE(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_DARK_ONE 0045d7d0"); } void NpcAI::ENTITY_ADVERSARY(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_ADVERSARY 0045e050"); } -void NpcAI::ENTITY_MEGA_MAW(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_MEGA_MAW 0045ef20"); } -void NpcAI::ENTITY_GATE(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_GATE 0045fc00"); } void NpcAI::ENTITY_MEGA_FATTY(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_MEGA_FATTY 00460780"); } void NpcAI::ENTITY_MASK_OF_INFAMY(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_MASK_OF_INFAMY 00461fc0"); } float NpcAI::ENTITY_ISAAC(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_ISAAC 00463100"); } -void NpcAI::ENTITY_FISTULA_BIG(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_FISTULA_BIG 00466600"); } -void NpcAI::ENTITY_LOKI(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_LOKI 00467670"); } void NpcAI::ENTITY_DADDYLONGLEGS(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_DADDYLONGLEGS 00468180"); } -void NpcAI::ENTITY_WIDOW(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_WIDOW 0046fbe0"); } void NpcAI::ENTITY_BLASTOCYST_BIG(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_BLASTOCYST_BIG 00472c40"); } void NpcAI::ENTITY_SLOTH(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_SLOTH 004741f0"); } void NpcAI::ENTITY_LUST(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_LUST 00474e00"); } @@ -10234,19 +10151,14 @@ void NpcAI::ENTITY_PIN(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_PIN 0047 void FUN_00479d50(uint32_t *param_1) { generated_stub("FUN_00479d50 00479d50"); } void NpcAI::ENTITY_PRIDE(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_PRIDE 00479d80"); } void NpcAI::ENTITY_CHUB(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_CHUB 0047a360"); } -void NpcAI::ENTITY_GURDY(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_GURDY 0047c850"); } -void NpcAI::ENTITY_PEEP(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_PEEP 0047d8a0"); } Entity_NPC * NpcAI::ENTITY_SATAN(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_SATAN 0047f640"); } -void NpcAI::ENTITY_THE_HAUNT(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_THE_HAUNT 00481410"); } void NpcAI::ENTITY_THE_LAMB(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_THE_LAMB 00483710"); } void NpcAI::ENTITY_MR_FRED(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_MR_FRED 00486db0"); } void NpcAI::ENTITY_CAGE(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_CAGE 004878a0"); } -void NpcAI::ENTITY_POLYCEPHALUS(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_POLYCEPHALUS 00489ca0"); } void NpcAI::ENTITY_MAMA_GURDY(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_MAMA_GURDY 0048ae30"); } void NpcAI::ENTITY_BROWNIE(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_BROWNIE 0048c3b0"); } void NpcAI::ENTITY_CORN_MINE(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_CORN_MINE 0048ee30"); } void NpcAI::ENTITY_FORSAKEN(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_FORSAKEN 0048f110"); } -void NpcAI::ENTITY_PITFALL(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_PITFALL 00492550"); } void NpcAI::ENTITY_RAG_MAN(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_RAG_MAN 00493200"); } void NpcAI::ENTITY_RAG_MEGA(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_RAG_MEGA 00495610"); } void NpcAI::ENTITY_SISTERS_VIS(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_SISTERS_VIS 00496fb0"); } @@ -10329,9 +10241,6 @@ void FUN_004cf0f0(uint8_t param_1) { generated_stub("FUN_004cf0f0 004cf0f0"); } void msvc::set::clear() { generated_stub("msvc::set::clear 004cf350"); } void FUN_004cf380(int *param_1) { generated_stub("FUN_004cf380 004cf380"); } void NpcAI::ENTITY_MIN_MIN(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_MIN_MIN 004cf690"); } -void NpcAI::ENTITY_MOM(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_MOM 004d1290"); } -void FUN_004d2f50(int param_1) { generated_stub("FUN_004d2f50 004d2f50"); } -void FUN_004d2fd0(int param_1) { generated_stub("FUN_004d2fd0 004d2fd0"); } void FUN_004d3050() { generated_stub("FUN_004d3050 004d3050"); } void FUN_004d3230(uint32_t *param_1) { generated_stub("FUN_004d3230 004d3230"); } void FUN_004d4210(int param_1, char param_2) { generated_stub("FUN_004d4210 004d4210"); } @@ -10361,7 +10270,6 @@ Entity_Effect * NpcAI::ENTITY_TWITCHY(Entity_NPC *npc) { generated_stub("NpcAI:: void NpcAI::ENTITY_SPIKEBALL(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_SPIKEBALL 004dc490"); } void NpcAI::ENTITY_UNBORN(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_UNBORN 004dca90"); } void * NpcAI::ENTITY_GASBAG(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_GASBAG 004dd7f0"); } -void NpcAI::ENTITY_PUSTULE(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_PUSTULE 004dea40"); } void NpcAI::ENTITY_EVIS(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_EVIS 004df3f0"); } void FUN_004e07a0(Vector *param_1) { generated_stub("FUN_004e07a0 004e07a0"); } void NpcAI::ENTITY_GUTTED_FATTY(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_GUTTED_FATTY 004e0dd0"); } @@ -10418,8 +10326,6 @@ void set_byte_0x101(void *self, uint8_t value) { generated_stub("set_byte_0x101 int FUN_00505ca0() { generated_stub("FUN_00505ca0 00505ca0"); } uint32_t * FUN_00505ce0() { generated_stub("FUN_00505ce0 00505ce0"); } void NpcAI::ENTITY_STONE_EYE(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_STONE_EYE 00505d00"); } -void NpcAI::ENTITY_CONSTANT_STONE_SHOOTER(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_CONSTANT_STONE_SHOOTER 00506320"); } -void NpcAI::ENTITY_ETERNALFLY(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_ETERNALFLY 0050a8a0"); } void NpcAI::ENTITY_KNIGHT(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_KNIGHT 005135d0"); } uint32_t FUN_00515010() { generated_stub("FUN_00515010 00515010"); } Vector * room_grid_line_direction(Vector *outDirection, Vector *from, Vector *to) { generated_stub("room_grid_line_direction 005150b0"); } @@ -10427,13 +10333,10 @@ long double FUN_00515290(Vector *param_1, uint32_t param_2, int param_3) { gener uint32_t * NpcAI::ENTITY_GUTS(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_GUTS 005153b0"); } void NpcAI::ENTITY_MRMAW(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_MRMAW 00517de0"); } void NpcAI::ENTITY_SWARMER(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_SWARMER 00518e20"); } -void NpcAI::ENTITY_GURGLE(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_GURGLE 0051aaa0"); } void NpcAI::ENTITY_MEMBRAIN(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_MEMBRAIN 0051c040"); } void NpcAI::ENTITY_HANGER(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_HANGER 0051cb30"); } -void NpcAI::ENTITY_GURDY_JR(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_GURDY_JR 0051d300"); } void NpcAI::ENTITY_URIEL(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_URIEL 0051e0f0"); } void NpcAI::ENTITY_HEART(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_HEART 0051f2f0"); } -void NpcAI::ENTITY_STONEHEAD(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_STONEHEAD 00520c60"); } void NpcAI::ENTITY_POKY(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_POKY 00521ab0"); } void NpcAI::ENTITY_LUMP(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_LUMP 00522430"); } void NpcAI::ENTITY_EYE(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_EYE 00522ef0"); } @@ -10448,17 +10351,13 @@ void NpcAI::ENTITY_COD_WORM(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_COD void NpcAI::ENTITY_MOBILE_HOST(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_MOBILE_HOST 005321d0"); } void NpcAI::ENTITY_DEATHS_HEAD(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_DEATHS_HEAD 00532cf0"); } void NpcAI::ENTITY_MOMS_HAND(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_MOMS_HAND 00533b80"); } -Entity * NpcAI::ENTITY_SQUIRT(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_SQUIRT 00535280"); } void NpcAI::ENTITY_SWINGER(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_SWINGER 00536d00"); } void NpcAI::ENTITY_WIZOOB(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_WIZOOB 005374a0"); } void NpcAI::ENTITY_NERVE_ENDING(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_NERVE_ENDING 00537e20"); } -void NpcAI::ENTITY_SKINBALL(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_SKINBALL 005381c0"); } void NpcAI::ENTITY_HOMUNCULUS(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_HOMUNCULUS 00539b90"); } void NpcAI::ENTITY_OOB(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_OOB 0053ab40"); } void NpcAI::ENTITY_BLACK_MAW(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_BLACK_MAW 0053b2f0"); } void NpcAI::ENTITY_WALL_CREEP(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_WALL_CREEP 0053c0d0"); } -void NpcAI::ENTITY_FAT_BAT(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_FAT_BAT 00540510"); } -void NpcAI::ENTITY_DUKIE(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_DUKIE 00541810"); } Entity_Effect * NpcAI::ENTITY_MEATBALL(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_MEATBALL 00541ce0"); } float NpcAI::ENTITY_BLISTER(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_BLISTER 005430d0"); } float NpcAI::ENTITY_TARBOY(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_TARBOY 005442a0"); } @@ -10800,7 +10699,6 @@ void FamiliarAI::mystery_egg(Entity_Familiar *familiar) { generated_stub("Famili void FamiliarAI::lil_spewer(Entity_Familiar *familiar) { generated_stub("FamiliarAI::lil_spewer 006384a0"); } void FUN_00638e20() { generated_stub("FUN_00638e20 00638e20"); } void spawn_blue_spider(Vector *position, Entity *spawner, Vector *target) { generated_stub("spawn_blue_spider 00638e30"); } -Entity * spawn_dip_at(int subType, Vector *position, Entity *spawner, Vector *targetPosition) { generated_stub("spawn_dip_at 006393a0"); } void FUN_006395e0(Vector *param_1, int *param_2, int param_3, int param_4, int param_5, float param_6, int param_7, int param_8, Entity *param_9, int param_10) { generated_stub("FUN_006395e0 006395e0"); } Entity_Laser * FamiliarHelper::sprinkler_fire_laser(Entity_Familiar *familiar, float angle, float distance) { generated_stub("FamiliarHelper::sprinkler_fire_laser 0063acf0"); } Entity_Knife * FamiliarAI::sprinkler_spawn_knife(Entity_Familiar *familiar) { generated_stub("FamiliarAI::sprinkler_spawn_knife 0063b070"); } @@ -10898,9 +10796,7 @@ uint8_t FUN_0067efd0() { generated_stub("FUN_0067efd0 0067efd0"); } float random_float() { generated_stub("random_float 0067efe0"); } int Isaac::Random(int Max) { generated_stub("Isaac::Random 0067f010"); } uint32_t FUN_0067f030() { generated_stub("FUN_0067f030 0067f030"); } -Vector * Isaac::GetAxisAlignedUnitVectorFromDir(Vector *outVector, int direction) { generated_stub("Isaac::GetAxisAlignedUnitVectorFromDir 0067f1d0"); } void FUN_0067f2e0() { generated_stub("FUN_0067f2e0 0067f2e0"); } -void * string_split(void *outTokens, std_string *text, uint8_t delimiter) { generated_stub("string_split 0067f420"); } uint8_t string_to_bool(void *self) { generated_stub("string_to_bool 0067f600"); } void ResolveRelativePath(uint8_t *anmPath, uint8_t *relPath, uint8_t *outPath) { generated_stub("ResolveRelativePath 0067f670"); } void ExtractAngleBracketText() { generated_stub("ExtractAngleBracketText 0067fdf0"); } @@ -10909,9 +10805,6 @@ void FUN_00682260() { generated_stub("FUN_00682260 00682260"); } void shader_stack_push(int shaderIndex) { generated_stub("shader_stack_push 00682280"); } void FUN_00682350() { generated_stub("FUN_00682350 00682350"); } float normalize_angle_degrees(float angle) { generated_stub("normalize_angle_degrees 00682740"); } -float angle_difference(float from, float to) { generated_stub("angle_difference 006827a0"); } -void FUN_00682a20() { generated_stub("FUN_00682a20 00682a20"); } -float approach_angle(float current, float target, float maxStep) { generated_stub("approach_angle 00682a50"); } uint32_t checksum_stream(void *stream, int offset, int trailingSize) { generated_stub("checksum_stream 00683580"); } void FUN_00683680() { generated_stub("FUN_00683680 00683680"); } void pop_render_target() { generated_stub("pop_render_target 006836c0"); } @@ -11057,7 +10950,6 @@ void FUN_006a7ec0() { generated_stub("FUN_006a7ec0 006a7ec0"); } void FUN_006a80d0() { generated_stub("FUN_006a80d0 006a80d0"); } void FUN_006a8180(uint32_t param_1) { generated_stub("FUN_006a8180 006a8180"); } void FUN_006a8210(int param_1) { generated_stub("FUN_006a8210 006a8210"); } -uint32_t FUN_006ae7a0() { generated_stub("FUN_006ae7a0 006ae7a0"); } void FUN_006b5de0() { generated_stub("FUN_006b5de0 006b5de0"); } void FUN_006b5f40() { generated_stub("FUN_006b5f40 006b5f40"); } void play_sound_with_fart_seed(int soundId, float volume, int frameDelay, uint8_t isLoop, float pitch) { generated_stub("play_sound_with_fart_seed 006b6470"); } @@ -11167,7 +11059,6 @@ void FUN_00709850() { generated_stub("FUN_00709850 00709850"); } void FUN_007098c0() { generated_stub("FUN_007098c0 007098c0"); } void FUN_00709930() { generated_stub("FUN_00709930 00709930"); } int FUN_00709bc0() { generated_stub("FUN_00709bc0 00709bc0"); } -bool FUN_0070be60() { generated_stub("FUN_0070be60 0070be60"); } uint8_t FUN_0070bf60() { generated_stub("FUN_0070bf60 0070bf60"); } uint8_t is_grid_type_floor_special(int gridType) { generated_stub("is_grid_type_floor_special 0070bf80"); } void FUN_0070bfa0(int param_1, int param_2, uint32_t param_3, float param_4) { generated_stub("FUN_0070bfa0 0070bfa0"); } @@ -11338,7 +11229,6 @@ void FUN_007c2e80() { generated_stub("FUN_007c2e80 007c2e80"); } uint8_t FUN_007c7b10(uint32_t param_1, int param_2) { generated_stub("FUN_007c7b10 007c7b10"); } char FUN_007c9080() { generated_stub("FUN_007c9080 007c9080"); } void FUN_007cb4f0() { generated_stub("FUN_007cb4f0 007cb4f0"); } -void FUN_007cdee0() { generated_stub("FUN_007cdee0 007cdee0"); } uint8_t teleport_to_random_room_of_types(Entity_Player *player, void *roomTypes, uint8_t isPreferUnvisited) { generated_stub("teleport_to_random_room_of_types 007cdf30"); } void FUN_007cf940() { generated_stub("FUN_007cf940 007cf940"); } long double FUN_007cf9a0(float *param_1, KColor *param_2, uint32_t param_3) { generated_stub("FUN_007cf9a0 007cf9a0"); } @@ -11456,7 +11346,6 @@ void FUN_007e92e0(uint32_t param_1, uint32_t param_2) { generated_stub("FUN_007e void FUN_007e93d0(int param_1) { generated_stub("FUN_007e93d0 007e93d0"); } void FUN_007ea0c0() { generated_stub("FUN_007ea0c0 007ea0c0"); } void FUN_007ebc40() { generated_stub("FUN_007ebc40 007ebc40"); } -float get_angel_room_chance() { generated_stub("get_angel_room_chance 007f96f0"); } void FUN_00812ea0(float *param_1, int *param_2, int *param_3) { generated_stub("FUN_00812ea0 00812ea0"); } uint32_t FUN_00813420(int param_1, int param_2) { generated_stub("FUN_00813420 00813420"); } uint32_t FUN_0081e220() { generated_stub("FUN_0081e220 0081e220"); } @@ -11476,7 +11365,6 @@ void FUN_00828890(uint32_t *param_1, float *param_2) { generated_stub("FUN_00828 void FUN_00828a70(void *param_1, int param_2) { generated_stub("FUN_00828a70 00828a70"); } void FUN_00828ab0() { generated_stub("FUN_00828ab0 00828ab0"); } void FUN_00828b10() { generated_stub("FUN_00828b10 00828b10"); } -uint8_t * FUN_008295c0() { generated_stub("FUN_008295c0 008295c0"); } void FUN_00829920(uint32_t *param_1) { generated_stub("FUN_00829920 00829920"); } uint32_t FUN_008299e0(short *param_1, short *param_2) { generated_stub("FUN_008299e0 008299e0"); } void FUN_0082a920(uint32_t *param_1) { generated_stub("FUN_0082a920 0082a920"); } @@ -11656,7 +11544,6 @@ uint8_t * Catch_00864e6d() { generated_stub("Catch_00864e6d 00864e6d"); } uint32_t Catch_0086504e() { generated_stub("Catch_0086504e 0086504e"); } uint32_t Catch_0086512e() { generated_stub("Catch_0086512e 0086512e"); } uint8_t * Catch_008655b7() { generated_stub("Catch_008655b7 008655b7"); } -char * FUN_00865660(char *param_1, uint32_t *param_2) { generated_stub("FUN_00865660 00865660"); } void FUN_00865aad() { generated_stub("FUN_00865aad 00865aad"); } void FUN_00865c61() { generated_stub("FUN_00865c61 00865c61"); } uint32_t Catch_00866364() { generated_stub("Catch_00866364 00866364"); } @@ -11665,9 +11552,6 @@ void FUN_00866474() { generated_stub("FUN_00866474 00866474"); } uint8_t * Catch_0086675e() { generated_stub("Catch_0086675e 0086675e"); } uint32_t Catch_008668e0() { generated_stub("Catch_008668e0 008668e0"); } void FUN_0086e4d0() { generated_stub("FUN_0086e4d0 0086e4d0"); } -uint8_t Input::IsMouseBtnPressed(int button) { generated_stub("Input::IsMouseBtnPressed 0086fdb0"); } -Vector * Input::GetMousePosition(Vector *outPosition, uint8_t isGameCoords) { generated_stub("Input::GetMousePosition 0086fe50"); } -void Isaac::ScreenToWorld(float *param_1, float *param_2) { generated_stub("Isaac::ScreenToWorld 00870160"); } void FUN_00870f21() { generated_stub("FUN_00870f21 00870f21"); } void FUN_00871eb0() { generated_stub("FUN_00871eb0 00871eb0"); } void FUN_00871f70(int *param_1, uint32_t param_2) { generated_stub("FUN_00871f70 00871f70"); } @@ -12359,63 +12243,6 @@ void FUN_00896690(uint32_t param_1, uint32_t param_2) { generated_stub("FUN_0089 void FUN_008966f0(uint32_t param_1, uint32_t param_2) { generated_stub("FUN_008966f0 008966f0"); } void FUN_00896750(uint32_t param_1, uint32_t param_2) { generated_stub("FUN_00896750 00896750"); } void FUN_008967b0() { generated_stub("FUN_008967b0 008967b0"); } -long double Options::MusicVolume() { generated_stub("Options::MusicVolume 00896810"); } -void FUN_00896820(float param_1) { generated_stub("FUN_00896820 00896820"); } -uint32_t * FUN_008968b0(uint32_t param_1, uint32_t param_2, int param_3) { generated_stub("FUN_008968b0 008968b0"); } -long double Options::SFXVolume() { generated_stub("Options::SFXVolume 008969e0"); } -void FUN_008969f0(float param_1) { generated_stub("FUN_008969f0 008969f0"); } -long double Options::MapOpacity() { generated_stub("Options::MapOpacity 00896a50"); } -void FUN_00896a60(float param_1) { generated_stub("FUN_00896a60 00896a60"); } -uint32_t Options::Fullscreen() { generated_stub("Options::Fullscreen 00896ab0"); } -void FUN_00896ac0(uint8_t param_1) { generated_stub("FUN_00896ac0 00896ac0"); } -uint32_t * FUN_00896ae0(uint32_t param_1, uint32_t param_2, int param_3) { generated_stub("FUN_00896ae0 00896ae0"); } -uint32_t Options::Filter() { generated_stub("Options::Filter 00896c10"); } -void FUN_00896c20(uint8_t param_1) { generated_stub("FUN_00896c20 00896c20"); } -long double Options::Gamma() { generated_stub("Options::Gamma 00896c40"); } -void FUN_00896c50(float param_1) { generated_stub("FUN_00896c50 00896c50"); } -int Options::DisplayPopups() { generated_stub("Options::DisplayPopups 00896ca0"); } -void FUN_00896cb0(int param_1) { generated_stub("FUN_00896cb0 00896cb0"); } -uint32_t * FUN_00896cf0(uint32_t param_1, uint32_t param_2, int param_3) { generated_stub("FUN_00896cf0 00896cf0"); } -int Options::CameraStyle() { generated_stub("Options::CameraStyle 00896e20"); } -void FUN_00896e30(int param_1) { generated_stub("FUN_00896e30 00896e30"); } -int Options::ExtraHUDStyle() { generated_stub("Options::ExtraHUDStyle 00896e70"); } -void FUN_00896e80(int param_1) { generated_stub("FUN_00896e80 00896e80"); } -long double Options::HUDOffset() { generated_stub("Options::HUDOffset 00896ec0"); } -void FUN_00896ed0(float param_1) { generated_stub("FUN_00896ed0 00896ed0"); } -uint32_t Options::FoundHUD() { generated_stub("Options::FoundHUD 00896f20"); } -void FUN_00896f30(uint8_t param_1) { generated_stub("FUN_00896f30 00896f30"); } -uint32_t Options::RumbleEnabled() { generated_stub("Options::RumbleEnabled 00896f50"); } -void FUN_00896f60(uint8_t param_1) { generated_stub("FUN_00896f60 00896f60"); } -uint32_t Options::ChargeBars() { generated_stub("Options::ChargeBars 00896f80"); } -void FUN_00896f90(uint8_t param_1) { generated_stub("FUN_00896f90 00896f90"); } -uint32_t Options::BulletVisibility() { generated_stub("Options::BulletVisibility 00896fb0"); } -void FUN_00896fc0(uint8_t param_1) { generated_stub("FUN_00896fc0 00896fc0"); } -uint32_t Options::VSync() { generated_stub("Options::VSync 00896fe0"); } -void FUN_00896ff0(uint32_t param_1) { generated_stub("FUN_00896ff0 00896ff0"); } -uint32_t Options::PauseOnFocusLost() { generated_stub("Options::PauseOnFocusLost 00897010"); } -void FUN_00897020(uint8_t param_1) { generated_stub("FUN_00897020 00897020"); } -uint32_t Options::MouseControl() { generated_stub("Options::MouseControl 00897040"); } -void FUN_00897050(uint8_t param_1) { generated_stub("FUN_00897050 00897050"); } -int Options::AnnouncerVoiceMode() { generated_stub("Options::AnnouncerVoiceMode 00897080"); } -void FUN_00897090(int param_1) { generated_stub("FUN_00897090 00897090"); } -int Options::MaxScale() { generated_stub("Options::MaxScale 008970d0"); } -void FUN_008970e0(uint32_t param_1) { generated_stub("FUN_008970e0 008970e0"); } -uint32_t * FUN_00897120(uint32_t param_1, uint32_t param_2, int param_3) { generated_stub("FUN_00897120 00897120"); } -int Options::MaxRenderScale() { generated_stub("Options::MaxRenderScale 00897250"); } -void FUN_00897260(uint32_t param_1) { generated_stub("FUN_00897260 00897260"); } -int Options::ConsoleFont() { generated_stub("Options::ConsoleFont 008972a0"); } -void FUN_008972b0(uint32_t param_1) { generated_stub("FUN_008972b0 008972b0"); } -uint32_t Options::FadedConsoleDisplay() { generated_stub("Options::FadedConsoleDisplay 008972d0"); } -void FUN_008972e0(uint8_t param_1) { generated_stub("FUN_008972e0 008972e0"); } -uint32_t Options::SaveCommandHistory() { generated_stub("Options::SaveCommandHistory 00897300"); } -void FUN_00897310(uint8_t param_1) { generated_stub("FUN_00897310 00897310"); } -uint32_t Options::UseBorderlessFullscreen() { generated_stub("Options::UseBorderlessFullscreen 00897330"); } -void FUN_00897340(uint8_t param_1) { generated_stub("FUN_00897340 00897340"); } -uint32_t Options::DebugConsoleEnabled() { generated_stub("Options::DebugConsoleEnabled 00897360"); } -void FUN_00897370(uint8_t param_1) { generated_stub("FUN_00897370 00897370"); } -int Options::JacobEsauControls() { generated_stub("Options::JacobEsauControls 00897390"); } -void FUN_008973a0(int param_1) { generated_stub("FUN_008973a0 008973a0"); } -uint32_t * FUN_008973e0() { generated_stub("FUN_008973e0 008973e0"); } uint32_t FUN_00897500() { generated_stub("FUN_00897500 00897500"); } void FUN_008975b0(uint32_t param_1, uint32_t param_2) { generated_stub("FUN_008975b0 008975b0"); } void FUN_00897620(int param_1) { generated_stub("FUN_00897620 00897620"); } @@ -13801,8 +13628,6 @@ uint32_t FUN_0095fd40() { generated_stub("FUN_0095fd40 0095fd40"); } uint32_t * FUN_00960880(void *param_1, uint32_t *param_2) { generated_stub("FUN_00960880 00960880"); } void FUN_00960bc0() { generated_stub("FUN_00960bc0 00960bc0"); } uint32_t FUN_00961ad0() { generated_stub("FUN_00961ad0 00961ad0"); } -int FUN_0096ce70() { generated_stub("FUN_0096ce70 0096ce70"); } -uint32_t FUN_0096cf40() { generated_stub("FUN_0096cf40 0096cf40"); } void FUN_0096d120(int *param_1) { generated_stub("FUN_0096d120 0096d120"); } uint32_t FUN_0097e7c0() { generated_stub("FUN_0097e7c0 0097e7c0"); } void pressure_plate_kill_enemies_timer_callback(int *param_1) { generated_stub("pressure_plate_kill_enemies_timer_callback 00983f30"); } @@ -13820,9 +13645,7 @@ uint32_t * FUN_009983f0(uint32_t *param_1) { generated_stub("FUN_009983f0 009983 void netplay_player_list_destructor(void *self) { generated_stub("netplay_player_list_destructor 00998800"); } void FUN_0099a830() { generated_stub("FUN_0099a830 0099a830"); } void FUN_0099c310() { generated_stub("FUN_0099c310 0099c310"); } -void segment_project_point(Vector *point, Vector *start, Vector *end, float *outT) { generated_stub("segment_project_point 0099c340"); } float bezier_closest_point(Vector *point, void *segmentStart, void *segmentEnd, float *outT) { generated_stub("bezier_closest_point 0099c430"); } -void laser_sample_trace_entities(void *entity, int unused) { generated_stub("laser_sample_trace_entities 0099f2c0"); } void ** vector_LaserSample_erase(void *self, void **outIter, void *where) { generated_stub("vector_LaserSample_erase 009a1610"); } void FUN_009a1770(uint32_t *param_1) { generated_stub("FUN_009a1770 009a1770"); } void * vector_LaserSample_emplace_reallocate(void *self, void *where, void *value) { generated_stub("vector_LaserSample_emplace_reallocate 009a17b0"); } @@ -14011,15 +13834,12 @@ Entity_Tear * fire_fetus_tear(void *self, Vector *position, Vector *velocity, in uint32_t * FUN_009f9080() { generated_stub("FUN_009f9080 009f9080"); } uint32_t * FUN_009f90f0() { generated_stub("FUN_009f90f0 009f90f0"); } uint32_t * FUN_009f9170() { generated_stub("FUN_009f9170 009f9170"); } -uint32_t * FUN_009f91f0() { generated_stub("FUN_009f91f0 009f91f0"); } uint32_t * FUN_009f92d0() { generated_stub("FUN_009f92d0 009f92d0"); } uint32_t * FUN_009f9350() { generated_stub("FUN_009f9350 009f9350"); } uint32_t * FUN_009f93d0() { generated_stub("FUN_009f93d0 009f93d0"); } uint32_t * FUN_009f9440() { generated_stub("FUN_009f9440 009f9440"); } -uint32_t * FUN_009f94c0() { generated_stub("FUN_009f94c0 009f94c0"); } uint32_t * FUN_009f9540() { generated_stub("FUN_009f9540 009f9540"); } uint32_t * FUN_009f95d0() { generated_stub("FUN_009f95d0 009f95d0"); } -uint32_t * FUN_009f9640() { generated_stub("FUN_009f9640 009f9640"); } uint32_t * FUN_009f96c0() { generated_stub("FUN_009f96c0 009f96c0"); } uint32_t * FUN_009f9740() { generated_stub("FUN_009f9740 009f9740"); } uint32_t * FUN_00a06940(void *param_1, uint32_t *param_2) { generated_stub("FUN_00a06940 00a06940"); } diff --git a/generated-src/weapon_brimstone.cpp b/generated-src/weapon_brimstone.cpp deleted file mode 100644 index b0c4b12..0000000 --- a/generated-src/weapon_brimstone.cpp +++ /dev/null @@ -1,1655 +0,0 @@ -#include "classes.h" - -// 009f3160 -uint32_t Weapon_Brimstone::GetMainEntity() -{ - return this->_mainLaser; -} - -// 009ff360 -void Weapon_Brimstone::Fire(Vector *direction, uint8_t isShooting, uint8_t isInterpolated) -{ - int *piVar1; - uint8_t bVar2; - uint8_t bVar3; - char cVar8; - undefined3 extraout_var; - float *pfVar4; - uint16_t uVar9; - uint32_t uVar5; - Vector *pVVar6; - uint32_t uVar7; - std_string *str; - Vector *aimDirection; - int ownerAsPlayer; - ItemConfig_Item *item; - Entity_Laser *laser; - float *extraout_EAX; - uint8_t *extraout_ECX; - Entity_Player *pEVar10; - uint3 uVar13; - uint32_t extraout_ECX_00; - int extraout_ECX_01; - int extraout_ECX_02; - int unused; - void *pvVar11; - int unusedCollectibleId; - int unusedCollectibleId_00; - int extraout_ECX_03; - int extraout_ECX_04; - int unusedCollectibleId_01; - int extraout_ECX_05; - int extraout_ECX_06; - int unusedCollectibleId_02; - int unused_00; - int unusedCollectibleId_03; - Entity_Player *ownerPlayer; - uint8_t *extraout_ECX_07; - uint8_t *puVar12; - int iVar14; - uint32_t uVar15; - ANM2 *sprite; - Entity *this_00; - bool bVar16; - long double fVar17; - float fVar18; - Entity_Player *pEVar19; - float fVar20; - uint32_t *puVar21; - uint32_t multiShotParams; - uint32_t uStack_d4; - uint32_t uStack_d0; - uint32_t uStack_cc; - uint32_t local_c8; - uint32_t uStack_c4; - uint32_t uStack_c0; - uint32_t uStack_bc; - uint32_t local_b8; - Vector local_b4; - Vector local_ac; - Vector local_a4; - Vector leftDirX; - uint32_t isCSection; - Vector local_90; - char isHasMarked; - Vector backDirX; - char isHasBrimstone; - uint32_t local_78; - Vector *shootDirection; - uint32_t local_70; - Entity_Player *local_6c; - uint8_t isChocolateMilk; - char local_65; - Entity_Player *local_64; - Vector local_60; - Vector local_58; - uint8_t local_4e; - char local_4d; - Entity_Player *local_4c; - char local_46; - char isFullyCharged; - char animSuffix [8]; - uint8_t local_3c [8]; - Vector local_34; - uint8_t local_2c [20]; - uint32_t tmpStringCapacity; - uint32_t local_14; - void *local_10; - uint8_t *puStack_c; - uint32_t local_8; - Entity_Player *owner; - - local_8 = 0xffffffff; - puStack_c = &LAB_00b1072e; - local_10 = ExceptionList; - local_14 = __security_cookie ^ GHIDRA_UINT((local_2c + 0x28)); - ExceptionList = &local_10; - shootDirection = direction; - local_70 = 0; - local_58.y = 0.0; - Weapon::Fire(GHIDRA_CAST(this),direction,isShooting,isInterpolated); - uVar15 = this->_modifiers; - local_b4.y = 1.0; - local_90.y = 1.0; - local_78 = uVar15 >> 4 & 0xffffff01; - local_a4.y = (float)(uVar15 >> 5 & 0xffffff01); - leftDirX.y = (float)(uVar15 >> 9 & 0xffffff01); - owner = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))); - isCSection = uVar15 >> 0xb & 0xffffff01; - if (owner == GHIDRA_CAST(0x0)) { - backDirX.y = g_vectorZero.x; - local_4c = GHIDRA_CAST(g_vectorZero.y); -LAB_009ff4b6: - ownerPlayer = GHIDRA_CAST(0x0); - local_64 = owner; - if (owner == GHIDRA_CAST(0x0)) { -LAB_009ff44f: - local_6c = ownerPlayer; - } - else { - local_6c = GHIDRA_CAST(0x0); - if (owner->_type == 1) { - local_b4.y = owner->_shotspeed; - goto LAB_009ff4eb; - } - } - ownerPlayer = local_6c; - if (owner != GHIDRA_CAST(0x0)) { - local_64 = GHIDRA_CAST(0x0); - if (owner->_type == 1) { -LAB_009ff48a: - local_64 = GHIDRA_CAST(0x0); - local_b4.y = owner->_shotspeed; - local_6c = ownerPlayer; - goto LAB_009ff4eb; - } - local_6c = ownerPlayer; - if (owner->_type == 3) { - owner = GHIDRA_CAST((GHIDRA_CAST(&owner->_isControlsEnabled))->x); - local_64 = GHIDRA_CAST(0x0); - if (owner != GHIDRA_CAST(0x0)) goto LAB_009ff48a; - } - } - local_64 = GHIDRA_CAST(0x0); - } - else { - backDirX.y = (float)(owner->_pos).x; - local_4c = GHIDRA_CAST((owner->_pos).y); - if (owner->_type != 1) { - if (owner->_type != 3) goto LAB_009ff4b6; - ownerPlayer = GHIDRA_CAST((GHIDRA_CAST(&owner->_isControlsEnabled))->x); - goto LAB_009ff44f; - } - local_b4.y = owner->_shotspeed; - local_6c = owner; - local_64 = owner; - ownerPlayer = owner; - } -LAB_009ff4eb: - puVar12 = &(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x10))); - local_ac.y = 0.001; - pfVar4 = &local_ac.y; - if (0.001 < *GHIDRA_CAST(puVar12) || *GHIDRA_CAST(puVar12) == 0.001) { - pfVar4 = GHIDRA_CAST(puVar12); - } - local_ac.y = *pfVar4; - local_58.y = (float)*pfVar4; - if (ownerPlayer == GHIDRA_CAST(0x0)) { -LAB_009ff534: - isHasBrimstone = '\0'; - } - else { - bVar2 = Entity_Player::HasCollectible(ownerPlayer,0x76,0); - pfVar4 = GHIDRA_CAST(CONCAT31(extraout_var,bVar2)); - isHasBrimstone = '\x01'; - puVar12 = extraout_ECX; - if (bVar2 == 0) goto LAB_009ff534; - } - owner = local_6c; - if ((char)local_78 == '\0') { - isChocolateMilk = (uint8_t)this->_modifiers & 1; - if (((GHIDRA_UINT(this->_modifiers) >> 7 & 1) != 0) || (*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x10)))) <= 1.0)) { - local_4e = 1; - local_46 = '\x01'; - if ((*GHIDRA_CAST((GHIDRA_CAST(&(local_a4.y)) + 0x0))) != '\0') goto LAB_009ff579; - } - else { - local_4e = 0; -LAB_009ff579: - local_46 = '\0'; - } - if ((ownerPlayer == GHIDRA_CAST(0x0)) || - ((bVar2 = Entity_Player::HasCollectible(ownerPlayer,0x18a,0), bVar2 == 0 && - (bVar2 = Entity_Player::HasCollectible(ownerPlayer,0x23c,0), bVar2 == 0)))) { - local_4d = '\0'; - if (ownerPlayer != GHIDRA_CAST(0x0)) goto LAB_009ff5b3; -LAB_009ff5cc: - isHasMarked = '\0'; - } - else { - local_4d = '\x01'; -LAB_009ff5b3: - bVar2 = Entity_Player::HasCollectible(ownerPlayer,0x18a,0); - isHasMarked = '\x01'; - if (bVar2 == 0) goto LAB_009ff5cc; - } - iVar14 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))); - if ((iVar14 == 0) || - ((*GHIDRA_CAST((iVar14 + 0x28)) != 1 && - ((*GHIDRA_CAST((iVar14 + 0x28)) != 3 || (iVar14 = *GHIDRA_CAST((iVar14 + 0x410)), iVar14 == 0)))))) { - iVar14 = 0; - } - else { - iVar14 = *GHIDRA_CAST((iVar14 + 0x140c)); - } - if ((local_4d == '\0') || (iVar14 == 0)) { - owner = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x28)))); - pEVar10 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x2c)))); - } - else { - owner = *GHIDRA_CAST((iVar14 + 0x33c)); - pEVar10 = *GHIDRA_CAST((iVar14 + 0x340)); - } - local_60.x = (float)owner; - local_60.y = (float)pEVar10; - uVar9 = (uint16_t)(GHIDRA_UINT(&local_60) >> 0x10); - bVar2 = (uint8_t)&local_60; - uVar5 = CONCAT22(uVar9,(uint16_t)bVar2); - uVar13 = (uint3)(GHIDRA_UINT(pEVar10) >> 8); - if (((float)owner == g_vectorZero.x) && - (uVar5 = CONCAT22(uVar9,(uint16_t)bVar2), (float)pEVar10 == g_vectorZero.y)) { - iVar14 = GHIDRA_UINT(uVar13) << 8; - } - else { - iVar14 = CONCAT31(uVar13,1); - } - local_4c = GHIDRA_CAST(CONCAT22((short)(GHIDRA_UINT(uVar5) >> 0x10),(uint16_t)(uint8_t)uVar5)); - local_78 = CONCAT31((int3)(GHIDRA_UINT(local_4c) >> 8),isShooting); - isFullyCharged = '\0'; - local_65 = (char)iVar14; - pEVar19 = local_4c; - if (local_4e != 0) { - if (local_ac.y <= *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x14))))) { -LAB_009ff696: - pEVar19 = GHIDRA_CAST(0x100); - isFullyCharged = '\x01'; - } - else if ((isShooting != 0) && (local_46 != '\0')) { - if ((this->_mainLaser != 0) && (4 < *GHIDRA_CAST((this->_mainLaser + 0x458)))) goto LAB_009ff696; - pEVar19 = GHIDRA_CAST(0x0); - } - } - cVar8 = (char)(GHIDRA_UINT(pEVar19) >> 8); - backDirX.y = (float)*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0xc)))); - if (((float)*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0xc)))) < 0.0) || - (local_4d = '\0', 0.0 < *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x14)))))) { - local_4d = '\x01'; - } - if (cVar8 == '\0') { - if (((isInterpolated == 0) && (isShooting != 0)) && ((char)iVar14 != '\0')) { - pEVar19 = GHIDRA_CAST(local_ac.y); - if (isChocolateMilk != 0) { - pVVar6 = Weapon::get_owner_position(GHIDRA_CAST(this),&local_34); - fVar18 = (float)pEVar10 - pVVar6->y; - fVar20 = (float)owner - pVVar6->x; - fVar18 = sqrtf(fVar18 * fVar18 + fVar20 * fVar20); - iVar14 = CONCAT31((int3)(GHIDRA_UINT(extraout_ECX_00) >> 8),local_65); - fVar18 = (fVar18 - 50.0) / 250.0; - if (fVar18 <= 0.0) { - fVar18 = 0.0; - } - if (1.0 <= fVar18) { - fVar18 = 1.0; - } - pEVar19 = (Entity_Player *) - ((local_ac.y * 2.5 - local_ac.y * 0.25) * fVar18 + local_ac.y * 0.25); - } - local_4c = GHIDRA_CAST(0x0); - local_78 = local_78 & 0xff; - if ((float)pEVar19 <= *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x14))))) { - local_78 = 0; - } - } - if ((((this->_mainLaser != 0) && - (ownerAsPlayer = *GHIDRA_CAST((this->_mainLaser + 0x3bc)), ownerAsPlayer != 0)) && - (*GHIDRA_CAST((ownerAsPlayer + 0x28)) != 1000)) && - (((ownerPlayer == GHIDRA_CAST(0x0) || ((char)iVar14 != '\0')) || - (ownerPlayer->_twinPlayer != 0)))) { - local_78 = local_78 & 0xffffff00; - } - cVar8 = isFullyCharged; - } - if ((*GHIDRA_CAST((GHIDRA_CAST(&(leftDirX.y)) + 0x0))) == '\0') { - if ((char)local_78 != '\0') { -LAB_009ffb5c: - if (cVar8 == '\0') goto LAB_009ffb64; - } -LAB_009ffebb: - local_4c = GHIDRA_CAST(0x3a83126f); - pfVar4 = GHIDRA_CAST(&local_4c); - if (0.001 <= local_ac.y) { - pfVar4 = &local_58.y; - } - owner = GHIDRA_CAST(*pfVar4); - if (isChocolateMilk != 0) { - local_58.y = 0.001; - local_4c = GHIDRA_CAST((local_ac.y * 0.25)); - pfVar4 = &local_58.y; - if (0.001 <= local_ac.y * 0.25) { - pfVar4 = GHIDRA_CAST(&local_4c); - } - owner = GHIDRA_CAST(*pfVar4); - } - if (*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x14)))) < (float)owner) { - if (this->_mainLaser == 0) { - iVar14 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))); - if (((iVar14 == 0) || (ownerAsPlayer = iVar14, *GHIDRA_CAST((iVar14 + 0x28)) != 1)) && - ((ownerAsPlayer = 0, iVar14 != 0 && (*GHIDRA_CAST((iVar14 + 0x28)) == 3)))) { - ownerAsPlayer = *GHIDRA_CAST((iVar14 + 0xd50)); -LAB_00a0049b: - if (1 < ownerAsPlayer) goto LAB_00a004a0; - } - else { - iVar14 = 0; - if (ownerAsPlayer != 0) { - ownerAsPlayer = *GHIDRA_CAST((ownerAsPlayer + 0x1338)); - goto LAB_00a0049b; - } - } -LAB_00a004ba: - Weapon::stop_costume_item_anim(GHIDRA_CAST(this),0x76); - iVar14 = extraout_ECX_06; - } - else { -LAB_00a004a0: - if ((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))) != 0) && (*GHIDRA_CAST((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))) + 0x28)) == 1)) { - bVar2 = Weapon::IsItemAnimFinished(GHIDRA_CAST(this),0x76); - iVar14 = extraout_ECX_05; - if (bVar2 != 0) goto LAB_00a004ba; - } - } - if ((((this->_mainLaser == 0) && (*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))) != 0)) && - (*GHIDRA_CAST((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))) + 0x28)) == 1)) && - (((char)isCSection != '\0' && - (bVar2 = Weapon::is_c_section_anim_finished(GHIDRA_CAST(this),iVar14), bVar2 != 0)))) { - Weapon::update_c_section_charge_anim - (GHIDRA_CAST(this),unusedCollectibleId_02,0,shootDirection,0.0); - } - } - else { - uVar15 = GHIDRA_UINT(local_4e) << 7 | 0x800; - if ((char)isCSection == '\0') { - uVar15 = GHIDRA_UINT(local_4e) << 7; - } - pVVar6 = shootDirection; - if ((char)iVar14 == '\0') { - pVVar6 = GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x20)))); - } - local_6c = GHIDRA_CAST(pVVar6->x); - local_64 = GHIDRA_CAST(pVVar6->y); - local_70 = uVar15; - local_60.x = (float)local_6c; - local_60.y = (float)local_64; - bVar2 = Weapon::IsAxisAligned(GHIDRA_CAST(this)); - if (bVar2 == 0) { - fVar18 = sqrtf((float)local_64 * (float)local_64 + (float)local_6c * (float)local_6c); - iVar14 = extraout_ECX_04; - if (0.0 < fVar18) { - local_64 = GHIDRA_CAST(((1.0 / fVar18) * (float)local_64)); - local_60.x = (1.0 / fVar18) * (float)local_6c; - goto LAB_009fffc8; - } - } - else { - pVVar6 = Vector::ToCardinal(&local_34,&local_60); - local_60.x = pVVar6->x; - local_64 = GHIDRA_CAST(pVVar6->y); - iVar14 = extraout_ECX_03; -LAB_009fffc8: - local_6c = GHIDRA_CAST(local_60.x); - local_60.y = (float)local_64; - } - if (local_46 == '\0') { - if (isChocolateMilk == 0) { - fVar18 = 1.0; - } - else { - fVar18 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x14)))) / local_ac.y; - if (fVar18 <= 0.1) { - fVar18 = 0.1; - } - if (2.5 <= fVar18) { - fVar18 = 2.5; - } - local_90.y = fVar18; - } - } - else { - fVar18 = (30.0 / (*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x10)))) + 1.0)) * 0.2; - local_90.y = fVar18; - if (isChocolateMilk != 0) { - fVar18 = fVar18 * 1.25; - local_90.y = fVar18; - } - } - if ((*GHIDRA_CAST((GHIDRA_CAST(&(leftDirX.y)) + 0x0))) != '\0') { - uVar15 = uVar15 | 0x200; - local_70 = uVar15; - if (isHasBrimstone == '\0') { - local_90.y = fVar18 * 0.5; - } - } - Weapon::GetMultiShotParams(GHIDRA_CAST(this),&multiShotParams,iVar14); - fVar18 = atan2f((float)local_64,(float)local_6c); - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x44)))) = fVar18 * 57.295776; - if ((char)isCSection == '\0') { - Weapon::UpdateHeadChargeAnimation(GHIDRA_CAST(this),0x76,2,&local_60,-1.0); - } - else { - Weapon::update_c_section_charge_anim - (GHIDRA_CAST(this),unusedCollectibleId_01,2,&local_60,-1.0); - } - local_64 = GHIDRA_CAST(0x0); - local_4c = GHIDRA_CAST(0x0); - if (0 < (short)multiShotParams) { - do { - FUN_009f4230(local_2c + 8,local_4c,2,local_60.x,local_60.y,local_b4.y,multiShotParams, - uStack_d4,uStack_d0,uStack_cc,local_c8,uStack_c4,uStack_c0,uStack_bc, - local_b8); - owner = (Entity_Player *) - Weapon::fire_brimstone_with_color - (GHIDRA_CAST(this),GHIDRA_CAST((local_2c + 0x10)),local_90.y,uVar15); - (**(code **)(*GHIDRA_CAST(owner) + 0xc))(); - if (local_64 == GHIDRA_CAST(0x0)) { - local_64 = owner; - if (GHIDRA_CAST(this->_mainLaser) != owner) { - if (GHIDRA_CAST(this->_mainLaser) != GHIDRA_CAST(0x0)) { - local_58.y = (float)&this->_mainLaser; - msvc::multiset::erase(&local_58.y); - } - puVar21 = &this->_mainLaser; - *puVar21 = owner; - goto LAB_00a001a4; - } - } - else { - puVar21 = &owner->_parent; - if (owner->_parent != 0) { - local_58.y = (float)puVar21; - msvc::multiset::erase(&local_58.y); - } - *puVar21 = local_64; -LAB_00a001a4: - msvc::multiset::insert(puVar21); - } - local_4c = GHIDRA_CAST((GHIDRA_INT(local_4c) + 1)); - uVar15 = local_70; - } while (GHIDRA_INT(local_4c) < GHIDRA_INT((short)multiShotParams)); - } - local_4c = GHIDRA_CAST((local_b8 & 0xffff)); - uVar7 = local_70; - while( true ) { - local_70 = uVar7; - if (local_4c == GHIDRA_CAST(0x0)) break; - uVar7 = Random(); - fVar18 = (float)((double)GHIDRA_INT(uVar7) + __uint_to_double_fixup[-(GHIDRA_INT(uVar7) >> 0x1f)]) * - 2.3283064e-10 * 3.14; - local_58.y = fVar18 + fVar18; - backDirX.y = sin(local_58.y); - local_b4.x = cos(local_58.y); - local_b4.y = backDirX.y; - leftDirX.y = (float)Weapon::fire_brimstone_with_color - (GHIDRA_CAST(this),&local_b4,local_90.y,uVar15); - backDirX.y = (float)this->_mainLaser; - puVar21 = &(GHIDRA_CAST(leftDirX.y))->_parent; - if (*puVar21 != 0) { - local_58.y = (float)puVar21; - msvc::multiset::erase(&local_58.y); - } - *puVar21 = backDirX.y; - if (GHIDRA_CAST(backDirX.y) != GHIDRA_CAST(0x0)) { - msvc::multiset::insert(puVar21); - } - (**(code **)(*GHIDRA_CAST(leftDirX.y) + 0xc))(); - local_4c = GHIDRA_CAST((GHIDRA_INT(local_4c) - 1)); - uVar15 = local_70; - uVar7 = local_70; - } - (*GHIDRA_CAST((GHIDRA_CAST(&(uStack_bc)) + 0x1))) = (char)(GHIDRA_UINT(uStack_bc) >> 8); - bVar16 = (*GHIDRA_CAST((GHIDRA_CAST(&(uStack_bc)) + 0x1))) != '\0'; - owner = GHIDRA_CAST(0x0); - if (bVar16) { - local_58.x = (float)(GHIDRA_UINT(local_60.x) ^ 0x80000000); - local_58.y = (float)(GHIDRA_UINT(local_60.y) ^ 0x80000000); - leftDirX.y = (float)Weapon::fire_brimstone_with_color - (GHIDRA_CAST(this),&local_58,local_90.y,uVar7); - backDirX.y = (float)this->_mainLaser; - local_4c = GHIDRA_CAST(&(GHIDRA_CAST(leftDirX.y))->_parent); - if ((GHIDRA_CAST(leftDirX.y))->_parent != 0) { - local_58.y = (float)local_4c; - msvc::multiset::erase(&local_58.y); - } - *GHIDRA_CAST(local_4c) = backDirX.y; - if (GHIDRA_CAST(backDirX.y) != GHIDRA_CAST(0x0)) { - msvc::multiset::insert(local_4c); - } - (**(code **)(*GHIDRA_CAST(leftDirX.y) + 0xc))(); - owner = local_4c; - } - local_4c = owner; - if ((*GHIDRA_CAST((GHIDRA_CAST(&(uStack_bc)) + 0x2))) != '\0') { - local_58.x = (float)(GHIDRA_UINT(local_60.y) ^ 0x80000000); - local_58.y = local_60.x; - leftDirX.y = (float)Weapon::fire_brimstone_with_color - (GHIDRA_CAST(this),&local_58,local_90.y,uVar7); - backDirX.y = (float)this->_mainLaser; - local_4c = GHIDRA_CAST(&(GHIDRA_CAST(leftDirX.y))->_parent); - if ((GHIDRA_CAST(leftDirX.y))->_parent != 0) { - local_58.y = (float)local_4c; - msvc::multiset::erase(&local_58.y); - } - *GHIDRA_CAST(local_4c) = backDirX.y; - if (backDirX.y != 0.0) { - msvc::multiset::insert(local_4c); - } - (**(code **)(*GHIDRA_CAST(leftDirX.y) + 0xc))(); - owner = GHIDRA_CAST((GHIDRA_UINT(local_60.x) ^ 0x80000000)); - local_60.x = local_60.y; - local_60.y = (float)owner; - backDirX.y = (float)Weapon::fire_brimstone_with_color - (GHIDRA_CAST(this),&local_60,local_90.y,uVar7); - local_4c = GHIDRA_CAST(this->_mainLaser); - puVar21 = &(GHIDRA_CAST(backDirX.y))->_parent; - if (*puVar21 != 0) { - local_58.y = (float)puVar21; - msvc::multiset::erase(&local_58.y); - } - *puVar21 = local_4c; - if (local_4c != GHIDRA_CAST(0x0)) { - msvc::multiset::insert(puVar21); - } - (**(code **)(*GHIDRA_CAST(backDirX.y) + 0xc))(); - } - if (((*GHIDRA_CAST((GHIDRA_CAST(&(local_a4.y)) + 0x0))) != '\0') && ((char)isCSection != '\0')) { - fire_c_section_fetuses(this); - } - } - if ((GHIDRA_CAST(this->_mainLaser) == GHIDRA_CAST(0x0)) || (isInterpolated != 0)) { -LAB_00a00882: - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x14)))) = 0; - } - else { - iVar14 = Entity::GetIntervalTicks(GHIDRA_CAST(this->_mainLaser),4.0,0.0); - Weapon::TriggerTearEffects(GHIDRA_CAST(this),shootDirection,iVar14); - if (((*GHIDRA_CAST((GHIDRA_CAST(&(local_a4.y)) + 0x0))) == '\0') && - ((iVar14 = Entity::GetIntervalTicks(GHIDRA_CAST(this->_mainLaser),4.0,0.0), iVar14 != 0 && - ((char)isCSection != '\0')))) { - fire_c_section_fetuses(this); - } - if ((isHasMarked != '\0') || ((local_46 != '\0' && (isFullyCharged != '\0')))) { - EntityList::QuerySublist - (GHIDRA_CAST((GHIDRA_INT(g_game->_room) + 0x1218)),GHIDRA_CAST(local_3c),7,-1,-1,0 - ,0); - local_8 = 0; - fVar18 = atan2f(shootDirection->y,shootDirection->x); - owner = GHIDRA_CAST((fVar18 * 57.295776)); - leftDirX.y = local_34.y; - local_4c = GHIDRA_CAST(0x0); - backDirX.y = (*GHIDRA_CAST((GHIDRA_CAST(&((float)local_3c)) + 0x4))); - local_64 = owner; - if (GHIDRA_CAST(local_34.y) != GHIDRA_CAST(0x0)) { - do { - iVar14 = *GHIDRA_CAST((GHIDRA_INT((&(GHIDRA_CAST((GHIDRA_INT(backDirX.y) + 0x48)))->_filename + -3)) + - GHIDRA_INT(local_4c) * 4)); - if ((iVar14 == this->_mainLaser) || (*GHIDRA_CAST((iVar14 + 0x3bc)) == this->_mainLaser)) { - local_58.y = *GHIDRA_CAST((iVar14 + 0x41c)); - fVar18 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x44)))); - *GHIDRA_CAST((iVar14 + 0x4c0)) = 1; - *GHIDRA_CAST((iVar14 + 0x4c4)) = 0; - fVar18 = angle_difference(local_58.y,(local_58.y - fVar18) + (float)owner); - *GHIDRA_CAST((iVar14 + 0x4c8)) = fVar18; - if (0.0 <= fVar18) { - uVar5 = 0x41000000; - } - else { - uVar5 = 0xc1000000; - } - *GHIDRA_CAST((iVar14 + 0x4cc)) = uVar5; - fVar18 = sin(local_58.y * 0.017453292); - if (fVar18 <= -0.5) { - uVar5 = 0xc1200000; - } - else { - uVar5 = 0x453b8000; - } - *GHIDRA_CAST((iVar14 + 0x358)) = uVar5; - if ((local_46 == '\0') || (isFullyCharged == '\0')) { - owner = local_64; - } - else { - Weapon::GetOwnerLaserOffset(GHIDRA_CAST(this),&local_60,4,shootDirection); - *GHIDRA_CAST((iVar14 + 0x34c)) = local_60.x; - *GHIDRA_CAST((iVar14 + 0x350)) = local_60.y; - owner = local_64; - if (*GHIDRA_CAST((iVar14 + 0x458)) < 8) { - *GHIDRA_CAST((iVar14 + 0x458)) = 8; - } - } - } - local_4c = GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((local_4c)) + 0x1)))); - } while (local_4c < GHIDRA_UINT(leftDirX.y)); - } - local_58.y = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x44)))); - fVar18 = angle_difference(local_58.y,(float)owner); - if (fVar18 <= -8.0) { - fVar18 = -8.0; - } - if (8.0 <= fVar18) { - fVar18 = 8.0; - } - fVar18 = local_58.y + fVar18; - if (360.0 < ABS(fVar18)) { - fVar18 = fmodf(fVar18,360.0); - } - if (fVar18 <= 180.0) { - if (fVar18 < -180.0) { - fVar18 = fVar18 + 360.0; - } - } - else { - fVar18 = fVar18 - 360.0; - } - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x44)))) = fVar18; - bVar2 = Weapon::IsItemAnimFinished(GHIDRA_CAST(this),0x76); - pVVar6 = shootDirection; - if (bVar2 == 0) { - if ((char)isCSection == '\0') { - Weapon::UpdateHeadChargeAnimation(GHIDRA_CAST(this),0x76,2,shootDirection,-2.0); - if (((isFullyCharged != '\0') && (local_46 != '\0')) && - ((((owner = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))), owner != GHIDRA_CAST(0x0) && - (ownerPlayer = owner, owner->_type == 1)) || - ((ownerPlayer = GHIDRA_CAST(0x0), owner == GHIDRA_CAST(0x0) || - (owner->_type != 3)))) && (ownerPlayer != GHIDRA_CAST(0x0))))) { - pvVar11 = (g_manager->_itemConfig)._collectibles._begin; - if (GHIDRA_INT((g_manager->_itemConfig)._collectibles._end) - GHIDRA_INT(pvVar11) >> 2 < 0x77) { - item = GHIDRA_CAST(0x0); - } - else { - item = *GHIDRA_CAST((GHIDRA_CAST(pvVar11) + 0x1d8)); - } - ownerAsPlayer = 0xa0083e; - iVar14 = Entity_Player::get_costume_anim_frame - (ownerPlayer,ownerPlayer,item,GHIDRA_INT(ownerPlayer)); - if (0xf < iVar14) { - Weapon::play_brimstone_costume_shoot - (GHIDRA_CAST(this),ownerAsPlayer,GHIDRA_INT(ownerPlayer),pVVar6,8.0); - } - } - } - else { - Weapon::update_c_section_charge_anim - (GHIDRA_CAST(this),unusedCollectibleId_03,2,shootDirection,0.0); - } - } - local_8 = 0xffffffff; - if (local_3c[0] == '\0') { - local_8 = 1; - tracked_alloc(1,(void *)backDirX.y,0); - local_8 = 0xffffffff; - } - goto LAB_00a00882; - } - Weapon::SetHeadLockTime(GHIDRA_CAST(this),2); - if ((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))) == 0) || (*GHIDRA_CAST((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))) + 0x28)) != 3)) - goto LAB_00a00882; - Weapon::SetBlinkTime(GHIDRA_CAST(this),10,unused_00); - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x14)))) = 0; - } - } - else { - if ((char)local_78 == '\0') goto LAB_009ffebb; - if (((isInterpolated != 0) || (0.0 < *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x14)))))) || (0.0 <= backDirX.y)) - goto LAB_009ffb5c; - if (cVar8 != '\0') goto LAB_009ffebb; - local_64 = GHIDRA_CAST((GHIDRA_UINT(local_4e) << 7)); - local_58.x = shootDirection->x; - local_58.y = shootDirection->y; - bVar2 = Weapon::IsAxisAligned(GHIDRA_CAST(this)); - if (bVar2 == 0) { - (GHIDRA_CAST((&local_58)))->Vector::Normalize(); - local_4c = GHIDRA_CAST(local_58.x); - iVar14 = extraout_ECX_02; - } - else { - pVVar6 = Vector::ToCardinal(&local_60,&local_58); - local_4c = GHIDRA_CAST(pVVar6->x); - local_58.y = pVVar6->y; - iVar14 = extraout_ECX_01; - } - backDirX.y = local_58.y; - local_58.x = (float)local_4c; - Weapon::GetMultiShotParams(GHIDRA_CAST(this),&multiShotParams,iVar14); - fVar18 = atan2f(backDirX.y,(float)local_4c); - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x44)))) = fVar18 * 57.295776; - Weapon::UpdateHeadChargeAnimation(GHIDRA_CAST(this),0x76,3,&local_58,-1.0); - Weapon::SetBlinkTime(GHIDRA_CAST(this),10,unused); - iVar14 = 0; - local_4e = 0; - if (0 < (short)multiShotParams) { - do { - FUN_009f4230(local_2c + 8,iVar14,10,local_58.x,local_58.y,local_b4.y,multiShotParams, - uStack_d4,uStack_d0,uStack_cc,local_c8,uStack_c4,uStack_c0,uStack_bc,local_b8 - ); - if (local_4e == 0) { - bVar2 = fire_hitscan(this,&g_vectorZero,GHIDRA_CAST((local_2c + 0x10)),GHIDRA_INT(local_64),1.0); - local_4e = 0; - if (bVar2 != 0) goto LAB_009ff93e; - } - else { -LAB_009ff93e: - local_4e = 1; - } - iVar14 = iVar14 + 1; - } while (iVar14 < (short)multiShotParams); - } - uVar15 = local_b8 & 0xffff; - owner = local_64; - bVar2 = local_4e; - while( true ) { - local_64 = owner; - if (uVar15 == 0) break; - if (bVar2 == 0) { - uVar7 = Random(); - fVar18 = (float)((double)GHIDRA_INT(uVar7) + __uint_to_double_fixup[-(GHIDRA_INT(uVar7) >> 0x1f)]) * - 2.3283064e-10 * 3.14; - local_4c = GHIDRA_CAST((fVar18 + fVar18)); - backDirX.y = sin((float)local_4c); - local_60.x = cos((float)local_4c); - local_60.y = backDirX.y; - bVar3 = fire_hitscan(this,&g_vectorZero,&local_60,GHIDRA_INT(local_64),1.0); - bVar2 = 0; - if (bVar3 != 0) goto LAB_009ff9ec; - } - else { -LAB_009ff9ec: - bVar2 = 1; - } - uVar15 = uVar15 - 1; - owner = local_64; - } - (*GHIDRA_CAST((GHIDRA_CAST(&(uStack_bc)) + 0x1))) = (char)(GHIDRA_UINT(uStack_bc) >> 8); - if ((*GHIDRA_CAST((GHIDRA_CAST(&(uStack_bc)) + 0x1))) == '\0') { - if (bVar2 != 0) goto LAB_009ffafb; -LAB_009ffa68: - if ((*GHIDRA_CAST((GHIDRA_CAST(&(uStack_bc)) + 0x2))) != '\0') { - leftDirX.x = -local_58.y; - leftDirX.y = local_58.x; - bVar2 = fire_hitscan(this,&g_vectorZero,&leftDirX,GHIDRA_INT(owner),1.0); - if (bVar2 == 0) { - ownerPlayer = GHIDRA_CAST((GHIDRA_UINT(local_58.x) ^ 0x80000000)); - local_58.x = local_58.y; - local_58.y = (float)ownerPlayer; - bVar2 = fire_hitscan(this,&g_vectorZero,&local_58,GHIDRA_INT(owner),1.0); - if (bVar2 == 0) goto LAB_009ffae1; - } - goto LAB_009ffafb; - } -LAB_009ffae1: - owner = local_6c; - if ((local_6c != GHIDRA_CAST(0x0)) && - (bVar2 = TemporaryEffects::HasNullEffect(&local_6c->_temporaryeffects,0x7f), bVar2 != 0)) - goto LAB_009ffafe; - } - else { - if (bVar2 == 0) { - backDirX.y = (float)(GHIDRA_UINT(local_58.y) ^ 0x80000000); - backDirX.x = -local_58.x; - bVar2 = fire_hitscan(this,&g_vectorZero,&backDirX,GHIDRA_INT(owner),1.0); - if (bVar2 == 0) goto LAB_009ffa68; - } -LAB_009ffafb: - owner = local_6c; -LAB_009ffafe: - fVar17 = (long double)this->GetMaxCharge(); - local_4c = GHIDRA_CAST((float)fVar17); - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x14)))) = - ((float)local_4c - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x14))))) * 0.5 + *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x14)))); - if (owner != GHIDRA_CAST(0x0)) { - TemporaryEffects::RemoveNullEffect(&owner->_temporaryeffects,0x7f,-1); - } - } - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0xc)))) = local_ac.y; - local_4d = '\x01'; -LAB_009ffb64: - piVar1 = GHIDRA_CAST(this->_mainLaser); - if (((piVar1 != GHIDRA_CAST(0x0)) && (piVar1[0xef] != 0)) && (*GHIDRA_CAST((piVar1[0xef] + 0x28)) != 1000) - ) { - (**(code **)(*piVar1 + 0x28))(); - } - local_a4.y = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))); - local_46 = '\0'; - if ((GHIDRA_CAST(local_a4.y) != GHIDRA_CAST(0x0)) && - ((GHIDRA_CAST(local_a4.y))->_type == 1)) { - pvVar11 = (g_manager->_itemConfig)._collectibles._begin; - if (GHIDRA_INT((g_manager->_itemConfig)._collectibles._end) - GHIDRA_INT(pvVar11) >> 2 < 0x77) { - local_4c = GHIDRA_CAST(0x0); - } - else { - local_4c = *GHIDRA_CAST((GHIDRA_CAST(pvVar11) + 0x1d8)); - } - leftDirX.y = (float)(GHIDRA_CAST(local_a4.y))->_playerCostumeMap; - backDirX.y = 0.0; - do { - if ((-1 < *GHIDRA_CAST(leftDirX.y)) && (*GHIDRA_CAST((GHIDRA_CAST(leftDirX.y) + 0xc)) == '\0')) { - (*GHIDRA_CAST((GHIDRA_CAST(&(local_2c)) + 0x10))) = 0; - sprite = GHIDRA_CAST((*GHIDRA_CAST(leftDirX.y) * 0x130 + - GHIDRA_INT((GHIDRA_CAST((GHIDRA_INT(local_a4.y) + 0x1220)))->_begin))); - tmpStringCapacity = 0xf; - (*GHIDRA_CAST((GHIDRA_CAST(&(local_2c)) + 0x0))) = (void *)0x0; - (GHIDRA_CAST((local_2c)))->msvc::string::assign(&s_empty,0); - local_70 = local_70 | 2; - bVar2 = Weapon::is_held_item(sprite,GHIDRA_CAST(local_2c),local_4c); - if ((bVar2 == 0) || - (((sprite->_animState)._animData == (void *)0x0 || - (local_65 = '\x01', (sprite->_animState)._isPlaying == 0)))) { - local_65 = '\0'; - } - local_8 = 0xffffffff; - if (((local_70 & 2) != 0) && (local_70 = local_70 & 0xfffffffd, 0xf < tmpStringCapacity) - ) { - uVar15 = tmpStringCapacity + 1; - pvVar11 = (*GHIDRA_CAST((GHIDRA_CAST(&((void *)local_2c)) + 0x0))); - if (0xfff < uVar15) { - pvVar11 = *(void **)((*GHIDRA_CAST((GHIDRA_CAST(&(local_2c)) + 0x0))) + -4); - uVar15 = tmpStringCapacity + 0x24; - if (0x1f < GHIDRA_UINT(((*GHIDRA_CAST((GHIDRA_CAST(&(local_2c)) + 0x0))) + (-4 - GHIDRA_INT(pvVar11))))) { - /* WARNING: Subroutine does not return */ - _invalid_parameter_noinfo_noreturn(); - } - } - operator_delete(pvVar11,uVar15); - } - if (local_65 != '\0') { - if ((sprite != GHIDRA_CAST(0x0)) && (bVar2 = ANM2::IsPlaying(sprite,&s_empty), bVar2 != 0)) - { - ANM2::GetAnimation(GHIDRA_CAST(&sprite->_animState),GHIDRA_CAST(local_2c)); - local_8 = 3; - if ((*GHIDRA_CAST((GHIDRA_CAST(&(GHIDRA_UINT(local_2c))) + 0x10))) < 8) { -LAB_009ffd27: - local_46 = '\0'; - } - else { - str = GHIDRA_CAST(FUN_00651a90(animSuffix,(*GHIDRA_CAST((GHIDRA_CAST(&(local_2c)) + 0x10))) - 8,0xffffffff)); - local_70 = local_70 | 1; - bVar2 = str_eq_cstr(str,GHIDRA_CAST("ShootAlt")); - local_46 = '\x01'; - if (bVar2 == 0) goto LAB_009ffd27; - } - if ((local_70 & 1) != 0) { - (GHIDRA_CAST((animSuffix)))->msvc::string::_Tidy_deallocate(); - } - local_8 = 0xffffffff; - (GHIDRA_CAST((local_2c)))->msvc::string::_Tidy_deallocate(); - } - break; - } - } - backDirX.y = (float)&(*GHIDRA_CAST((GHIDRA_CAST(((GHIDRA_CAST(backDirX.y)))) + 0x1))); - leftDirX.y = (float)&(*GHIDRA_CAST((GHIDRA_CAST(((GHIDRA_CAST(leftDirX.y)))) + 0x10))); - } while (GHIDRA_UINT(backDirX.y) < &DAT_0000000f); - } - if (local_4d == '\0') { -LAB_009ffde2: - pVVar6 = shootDirection; - } - else { - fVar17 = (long double)this->GetMaxCharge(); - pVVar6 = shootDirection; - local_4c = GHIDRA_CAST((float)fVar17); - if (*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x14)))) < (float)local_4c) { - owner = GHIDRA_CAST(((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x14)))) / (float)local_4c) * 18.0)); - local_4c = owner; - if ((char)isCSection == '\0') { - if (local_46 == '\0') { - Weapon::UpdateHeadChargeAnimation(GHIDRA_CAST(this),0x76,0,shootDirection,(float)owner); - } - } - else { - bVar2 = Weapon::is_c_section_anim_finished(GHIDRA_CAST(this),unusedCollectibleId); - if (bVar2 != 0) { - owner = local_4c; - Weapon::update_c_section_charge_anim - (GHIDRA_CAST(this),unusedCollectibleId_00,0,shootDirection,(float)local_4c); - } - } - if (isInterpolated == 0) { - FUN_009f4130(); - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x14)))) = (float)owner + *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x14)))); - } - goto LAB_009ffde2; - } - if ((char)isCSection == '\0') { - if (local_46 != '\0') goto LAB_009ffde2; - Weapon::UpdateHeadChargeAnimation(GHIDRA_CAST(this),0x76,1,shootDirection,-1.0); - } - else { - Weapon::update_c_section_charge_anim - (GHIDRA_CAST(this),unusedCollectibleId,1,shootDirection,-1.0); - } - } - bVar2 = Weapon::IsAxisAligned(GHIDRA_CAST(this)); - if (bVar2 == 0) { - aimDirection = Weapon::get_aim_direction(GHIDRA_CAST(this),&local_34,pVVar6); - } - else { - local_60.x = (float)pVVar6->x; - aimDirection = &local_60; - local_60.y = (float)pVVar6->y; - } - fVar18 = aimDirection->x; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x20)))) = fVar18; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x24)))) = aimDirection->y; - Weapon::SetBlinkTime(GHIDRA_CAST(this),1,GHIDRA_INT(fVar18)); - } - } - else { - local_90.y = 1.0; - this_00 = GHIDRA_CAST(this->_mainLaser); - local_a4.x = backDirX.y; - local_a4.y = (float)local_4c; - if (this_00 != GHIDRA_CAST(0x0)) { - local_a4.x = (this_00->_pos).x; - local_a4.y = (this_00->_pos).y; - } - if (isInterpolated == 0) { - bVar2 = Entity_Player::HasCollectible(local_6c,0x44,0); - local_70 = 1; - if (bVar2 != 0) { - local_70 = 9; - } - if (((*GHIDRA_CAST((GHIDRA_CAST(&(leftDirX.y)) + 0x0))) != '\0') && (isHasBrimstone == '\0')) { - local_90.y = 0.5; - } - iVar14 = Entity_Player::GetCollectibleNum(owner,0x76,0); - if (1 < iVar14) { - local_90.y = local_90.y + local_90.y; - } - if ((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))) != 0) && (*GHIDRA_CAST((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))) + 0x28)) == 3)) { - local_90.y = local_90.y * 0.5; - } - if (1.5 < local_90.y) { - bVar16 = local_70 == 9; - local_70 = 0xb; - local_90.y = local_90.y * 0.5; - if (bVar16) { - local_70 = 0xe; - } - } - this_00 = GHIDRA_CAST(this->_mainLaser); - pfVar4 = GHIDRA_CAST(&this->_mainLaser); - if ((this_00 != GHIDRA_CAST(0x0)) && - ((this_00->_subtype != 1 || (this_00->_variant != local_70)))) { - (**(code **)(*GHIDRA_CAST(this_00) + 0x28))(); - if (this->_mainLaser != 0) { - local_58.y = (float)&this->_mainLaser; - msvc::multiset::erase(&local_58.y); - this->_mainLaser = 0; - } -LAB_00a009e9: - uVar15 = Random(); - laser = (Entity_Laser *) - Game::Spawn(g_game,7,local_70,&local_a4,&g_vectorZero,*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))),1 - ,uVar15); - if ((laser == GHIDRA_CAST(0x0)) || (laser->_type != 7)) { - laser = GHIDRA_CAST(0x0); - } - (laser->_posOffset).x = 0.0; - (laser->_posOffset).y = -20.0; - Entity::SetParent(GHIDRA_CAST(laser),*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4))))); - laser->_renderDepthOffset = 3000.0; - laser->_scale = local_90.y; - Entity_Laser::ResetSpriteScale(laser); - init_laser(this,laser); - (**(code **)(*GHIDRA_CAST(laser) + 0xc))(); - EntityPtr::Set(GHIDRA_CAST(&this->_mainLaser),GHIDRA_CAST(laser)); - this_00 = GHIDRA_CAST(this->_mainLaser); - pfVar4 = extraout_EAX; - puVar12 = extraout_ECX_07; - goto LAB_00a00a7b; - } - if (this_00 == GHIDRA_CAST(0x0)) goto LAB_00a009e9; - } - else { -LAB_00a00a7b: - if (this_00 == GHIDRA_CAST(0x0)) { - uVar15 = CONCAT31((int3)(GHIDRA_UINT(puVar12) >> 8),isShooting); - goto LAB_009ffe67; - } - } - local_78 = CONCAT31((int3)(GHIDRA_UINT(pfVar4) >> 8),isShooting); - if (isShooting == 0) { - ownerAsPlayer = *GHIDRA_CAST((GHIDRA_CAST(g_game->_room) + 0x12c4)) + *GHIDRA_CAST((GHIDRA_CAST(g_game->_room) + 0x12c0)); - iVar14 = 0; - if (0 < ownerAsPlayer) { - iVar14 = ownerAsPlayer; - } - if (iVar14 < 1) { - fVar18 = backDirX.y - (this_00->_pos).x; - fVar20 = (float)local_4c - (this_00->_pos).y; - if (10000.0 < fVar20 * fVar20 + fVar18 * fVar18) { - local_60.x = fVar18; - local_60.y = fVar20; - pVVar6 = (GHIDRA_CAST((&local_60)))->Vector::Normalized(&local_34); - local_60.x = pVVar6->x * 0.3 * 0.5; - local_60.y = pVVar6->y * 0.3 * 0.5; - goto LAB_00a00bb9; - } - } - } - else { - local_60.x = shootDirection->x; - local_60.y = shootDirection->y; - if (1.0 < local_60.x * local_60.x + local_60.y * local_60.y) { - (GHIDRA_CAST((&local_60)))->Vector::Normalize(); - } - local_60.x = local_60.x * 2.0 * 0.5 * local_b4.y; - local_60.y = local_60.y * 2.0 * 0.5 * local_b4.y; -LAB_00a00bb9: - Entity::AddVelocity_divided(this_00,&local_60,0); - } - puVar21 = &this->_mainLaser; - if (isInterpolated == 0) { - init_laser(this,GHIDRA_CAST(*puVar21)); - laser = GHIDRA_CAST(*puVar21); - laser->_scale = local_90.y; - Entity_Laser::ResetSpriteScale(laser); - if ((local_64 != GHIDRA_CAST(0x0)) && - (iVar14 = Entity::GetIntervalTicks(GHIDRA_CAST(local_64),local_ac.y,0.0), iVar14 != 0)) { - iVar14 = *puVar21; - if (iVar14 != 0) { - local_58.x = *GHIDRA_CAST((iVar14 + 0x33c)); - local_58.y = *GHIDRA_CAST((iVar14 + 0x340)); - local_60.x = *GHIDRA_CAST((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))) + 0x33c)); - local_60.y = *GHIDRA_CAST((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))) + 0x340)); - bVar2 = (GHIDRA_CAST((&local_58)))->Vector::operator_ne(&local_60); - if (bVar2 != 0) { - local_60.x = *GHIDRA_CAST((*puVar21 + 0x33c)) - *GHIDRA_CAST((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))) + 0x33c)) - ; - local_60.y = *GHIDRA_CAST((*puVar21 + 0x340)) - *GHIDRA_CAST((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))) + 0x340)) - ; - pVVar6 = (GHIDRA_CAST((&local_60)))->Vector::Normalized(&local_ac); - Weapon::TriggerTearEffects(GHIDRA_CAST(this),pVVar6,1); - goto LAB_009ffe64; - } - } - pVVar6 = MusicManager::RandomVector(&local_90); - Weapon::TriggerTearEffects(GHIDRA_CAST(this),pVVar6,1); - } - } - } -LAB_009ffe64: - uVar15 = local_78; -LAB_009ffe67: - if ((char)isCSection != '\0') { - if (this->_mainLaser == 0) { - if (((char)uVar15 != '\0') || - (bVar2 = Weapon::is_c_section_anim_finished(GHIDRA_CAST(this),uVar15), bVar2 != 0)) { - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x3c)))) = shootDirection->x; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x40)))) = shootDirection->y; - } - } - else { - local_58.y = *GHIDRA_CAST((this->_mainLaser + 0x41c)) * 0.017453292; - local_4c = GHIDRA_CAST(cos(local_58.y)); - fVar18 = sin(local_58.y); - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x3c)))) = local_4c; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x40)))) = fVar18; - } - } - ExceptionList = local_10; - return; -} - -// 00a00d10 -void Weapon_Brimstone::fire_c_section_fetuses() -{ - Entity *source; - uint32_t rngResult; - Entity_Tear *tear; - int iVar1; - uint64_t *allocatedBytes; - uint32_t rngResult; - float jitterX; - int unused; - EntityList_EL lasers; - Vector laserPos; - Vector tearVelocity; - Weapon_Brimstone *weapon; - float dirX; - float jitterY; - float local_1c; - float shotSpeed; - float dirY; - void *local_10; - uint8_t *puStack_c; - uint32_t local_8; - uint64_t oldAllocated; - - local_8 = 0xffffffff; - puStack_c = &LAB_00b1076d; - local_10 = ExceptionList; - ExceptionList = &local_10; - iVar1 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))); - shotSpeed = 1.0; - if ((iVar1 != 0) && - ((*GHIDRA_CAST((iVar1 + 0x28)) == 1 || - ((*GHIDRA_CAST((iVar1 + 0x28)) == 3 && (iVar1 = *GHIDRA_CAST((iVar1 + 0x410)), iVar1 != 0)))))) { - shotSpeed = *GHIDRA_CAST((iVar1 + 0x1464)); - } - weapon = this; - EntityList::QuerySublist(GHIDRA_CAST((GHIDRA_INT(g_game->_room) + 0x1218)),&lasers,7,-1,-1,0,0); - rngResult = 0; - local_8 = 0; - if (lasers._size != 0) { - do { - iVar1 = *GHIDRA_CAST(((*GHIDRA_CAST((GHIDRA_CAST(&(lasers)) + 0x4))) + rngResult * 4)); - if ((iVar1 == this->_mainLaser) || (*GHIDRA_CAST((iVar1 + 0x3bc)) == this->_mainLaser)) { - local_1c = *GHIDRA_CAST((iVar1 + 0x41c)) * 0.017453292; - dirY = sin(local_1c); - source = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))); - dirX = cos(local_1c); - dirX = dirX * 10.0; - dirY = dirY * 10.0; - rngResult = Random(); - local_1c = (float)((double)GHIDRA_INT(rngResult) + - __uint_to_double_fixup[-(GHIDRA_INT(rngResult) >> 0x1f)]) * 2.3283064e-10 * 3.14; - local_1c = local_1c + local_1c; - jitterY = sin(local_1c); - unused = 0xa00e61; - jitterX = cos(local_1c); - this = weapon; - laserPos.x = *GHIDRA_CAST((iVar1 + 0x33c)); - laserPos.y = *GHIDRA_CAST((iVar1 + 0x340)); - tearVelocity.x = (jitterX * 3.0 + dirX) * shotSpeed; - tearVelocity.y = (jitterY * 3.0 + dirY) * shotSpeed; - tear = fire_fetus_tear(weapon,&laserPos,&tearVelocity,0,source,1.0,unused); - (**(code **)(*GHIDRA_CAST(tear) + 0xc))(); - } - rngResult = rngResult + 1; - } while (rngResult < GHIDRA_UINT(lasers._size)); - } - if ((*GHIDRA_CAST((GHIDRA_CAST(&(lasers)) + 0x0))) == '\0') { - if (g_mainHeap == (void *)0x0) { - allocatedBytes = &g_allocatedBytesNoHeap; - } - else { - allocatedBytes = GHIDRA_CAST((GHIDRA_INT(g_mainHeap) + 0x30)); - } - if ((*GHIDRA_CAST((GHIDRA_CAST(&(lasers)) + 0x4))) != 0) { - rngResult = *GHIDRA_CAST(((*GHIDRA_CAST((GHIDRA_CAST(&(lasers)) + 0x4))) + -4)); - oldAllocated = *allocatedBytes; - *GHIDRA_CAST(allocatedBytes) = GHIDRA_UINT(*allocatedBytes) - rngResult; - *GHIDRA_CAST((GHIDRA_CAST(allocatedBytes) + 4)) = - *GHIDRA_CAST((GHIDRA_CAST(allocatedBytes) + 4)) - GHIDRA_UINT((GHIDRA_UINT(oldAllocated) < rngResult)); - free(GHIDRA_CAST(((*GHIDRA_CAST((GHIDRA_CAST(&(lasers)) + 0x4))) + -4))); - } - } - ExceptionList = local_10; - return; -} - -// 00a00f30 -long double Weapon_Brimstone::GetMaxCharge() -{ - float baseCharge; - float chargeMultiplier; - - chargeMultiplier = 1.0; - if ((this->_modifiers & 1) != 0) { - chargeMultiplier = 2.5; - } - if ((GHIDRA_UINT(this->_modifiers) >> 4 & 1) != 0) { - return (long double)0.0; - } - baseCharge = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x10)))); - if (baseCharge < 0.001) { - baseCharge = 0.001; - } - return (long double)(baseCharge * chargeMultiplier); -} - -// 00a00f90 -void Weapon_Brimstone::init_laser(Entity_Laser *laser) -{ - int iVar1; - BitSet128 *tearFlags; - ColorMod *laserColor; - float damage; - int *piVar2; - uint8_t auStack_50 [4]; - Entity_Laser *local_4c; - BitSet128 tearFlagsResult; - ColorMod laserColorResult; - uint32_t local_c; - code *laserMethod; - uint64_t tearFlagsHigh; - uint32_t tearFlagsHighHigh; - uint32_t tearFlagsLowHigh; - - local_c = __security_cookie ^ GHIDRA_UINT(auStack_50); - local_4c = laser; - tearFlags = Weapon::get_owner_tear_flags(GHIDRA_CAST(this),&tearFlagsResult); - tearFlagsLowHigh = *GHIDRA_CAST((GHIDRA_INT(&tearFlags->_l) + 4)); - tearFlagsHigh = tearFlags->_h; - tearFlagsHighHigh = *GHIDRA_CAST((GHIDRA_INT(&tearFlags->_h) + 4)); - iVar1 = *GHIDRA_CAST(laser); - *GHIDRA_CAST(&(laser->_tearFlags)._l) = GHIDRA_INT(tearFlags->_l); - *GHIDRA_CAST((GHIDRA_INT(&(laser->_tearFlags)._l) + 4)) = tearFlagsLowHigh; - *GHIDRA_CAST(&(laser->_tearFlags)._h) = GHIDRA_INT(tearFlagsHigh); - *GHIDRA_CAST((GHIDRA_INT(&(laser->_tearFlags)._h) + 4)) = tearFlagsHighHigh; - laserMethod = *(code **)(iVar1 + 0x3c); - laserColor = Weapon::get_laser_color(GHIDRA_CAST(this),&laserColorResult); - piVar2 = GHIDRA_CAST(0x0); - (*laserMethod)(laserColor,0xffffffff,0xff,0,1); - laserMethod = *(code **)(*piVar2 + 0x40); - damage = Weapon::get_damage(GHIDRA_CAST(this)); - (*laserMethod)(damage); - return; -} - -// 00a02790 -void Weapon_Brimstone::ClearReferences() -{ - Weapon_Brimstone *local_8; - uint32_t *laserRef; - - laserRef = &this->_technology2Laser; - local_8 = this; - if (GHIDRA_CAST(this->_technology2Laser) != GHIDRA_CAST(0x0)) { - (**(code **)(*GHIDRA_CAST(this->_technology2Laser) + 0x28))(); - if (*laserRef != 0) { - local_8 = GHIDRA_CAST(laserRef); - msvc::multiset::erase(&local_8); - *laserRef = 0; - } - } - laserRef = &this->_mainLaser; - if (GHIDRA_CAST(this->_mainLaser) != GHIDRA_CAST(0x0)) { - (**(code **)(*GHIDRA_CAST(this->_mainLaser) + 0x28))(); - if (*laserRef != 0) { - local_8 = GHIDRA_CAST(laserRef); - msvc::multiset::erase(&local_8); - *laserRef = 0; - } - } - return; -} - -// 00a02800 -int Weapon_Brimstone::GetMarkedTargetVariant() -{ - uint8_t isHasItem; - Entity_Player *owner; - - if ((GHIDRA_UINT(this->_modifiers) >> 4 & 1) != 0) { - return 0; - } - owner = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))); - if (owner != GHIDRA_CAST(0x0)) { - if (owner->_type == 1) goto LAB_00a02830; - if (owner->_type == 3) { - owner = *GHIDRA_CAST(&owner->_isControlsEnabled); - goto LAB_00a02830; - } - } - owner = GHIDRA_CAST(0x0); -LAB_00a02830: - isHasItem = Entity_Player::HasCollectible(owner,0x23c,0); - if (isHasItem != 0) { - return 0x99; - } - isHasItem = Entity_Player::HasCollectible(owner,0x18a,0); - if (isHasItem == 0) { - return 0; - } - return 0x1e; -} - -// 00a02870 -uint32_t Weapon_Brimstone::GetFocusEntity() -{ - if ((GHIDRA_UINT(this->_modifiers) >> 4 & 1) == 0) { - return 0; - } - return this->_mainLaser; -} - -// 00a02890 -void Weapon_Brimstone::fire(float Speed, uint8_t IgnoreStatusEffects) -{ - void *pvVar1; - Entity *pEVar2; - Vector *pVVar3; - uint8_t isHitscanHit; - uint8_t isAnyHit; - uint32_t rngValue; - Entity_Laser *pEVar4; - ColorMod *laserColor; - int unused; - float extraout_ECX; - float extraout_ECX_00; - float extraout_ECX_01; - float extraout_ECX_02; - int iVar5; - uint32_t uVar6; - bool isShootingBackwards; - long double fVar7; - float fVar8; - float in_XMM2_Da; - int *piVar9; - int *piVar10; - uint8_t auStack_a8 [2]; - uint8_t auStack_a6 [2]; - uint8_t local_a4 [8]; - float local_9c; - float *local_98; - Vector VStack_94; - Entity_Laser *local_8c; - float damageMultiplier; - Vector *aimDir; - Vector local_80; - Vector local_78; - short multiShotParams [2]; - float fStack_6c; - float fStack_68; - float fStack_64; - float local_60; - int iStack_5c; - float fStack_58; - uint8_t auStack_54 [64]; - uint32_t stackCookie; - code *setColorFn; - - stackCookie = __security_cookie ^ GHIDRA_UINT(auStack_a8); - aimDir = GHIDRA_CAST(Speed); - damageMultiplier = in_XMM2_Da; - Weapon::GetMultiShotParams(GHIDRA_CAST(this),multiShotParams,GHIDRA_INT(this)); - iVar5 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))); - if (iVar5 == 0) { -LAB_00a02903: - local_8c = GHIDRA_CAST(0x0); - if (iVar5 != 0) { - local_8c = GHIDRA_CAST(0x0); - if (*GHIDRA_CAST((iVar5 + 0x28)) == 1) goto LAB_00a02934; - if (*GHIDRA_CAST((iVar5 + 0x28)) == 3) goto LAB_00a02924; - } -LAB_00a0293e: - (*GHIDRA_CAST((GHIDRA_CAST(&(local_a4)) + 0x0))) = GHIDRA_CAST(0x3f800000); - } - else if (*GHIDRA_CAST((iVar5 + 0x28)) == 1) { - (*GHIDRA_CAST((GHIDRA_CAST(&(local_a4)) + 0x0))) = *GHIDRA_CAST((iVar5 + 0x1464)); - local_8c = GHIDRA_CAST(iVar5); - } - else { - if (*GHIDRA_CAST((iVar5 + 0x28)) != 3) goto LAB_00a02903; - local_8c = *GHIDRA_CAST((iVar5 + 0x410)); -LAB_00a02924: - iVar5 = *GHIDRA_CAST((iVar5 + 0x410)); - if (iVar5 == 0) goto LAB_00a0293e; -LAB_00a02934: - (*GHIDRA_CAST((GHIDRA_CAST(&(local_a4)) + 0x0))) = *GHIDRA_CAST((iVar5 + 0x1464)); - } - if ((GHIDRA_UINT(this->_modifiers) >> 9 & 1) == 0) { - Weapon::UpdateHeadChargeAnimation(GHIDRA_CAST(this),0x76,2,GHIDRA_CAST(Speed),-1.0); - fVar8 = 0.0; - local_8c = GHIDRA_CAST(0x0); - local_98 = GHIDRA_CAST(0x0); - if (0 < multiShotParams[0]) { - do { - (*GHIDRA_CAST((GHIDRA_CAST(&(local_a4)) + 0x4))) = (GHIDRA_CAST(Speed))->x; - local_9c = (GHIDRA_CAST(Speed))->y; - Entity_Player::GetMultiShotPositionVelocity - (&local_80,GHIDRA_INT(local_98),2,*GHIDRA_CAST(Speed),(*GHIDRA_CAST((GHIDRA_CAST(&((float)local_a4)) + 0x0))), - multiShotParams[0],fStack_6c,fStack_68,fStack_64,local_60,iStack_5c,fStack_58, - auStack_54[0],(*GHIDRA_CAST((GHIDRA_CAST(&(auStack_54)) + 0x4)))); - pEVar4 = Weapon::fire_brimstone_with_color(GHIDRA_CAST(this),&local_78,damageMultiplier,0); - (**(code **)(*GHIDRA_CAST(pEVar4) + 0xc))(); - if (local_8c == GHIDRA_CAST(0x0)) { - local_8c = pEVar4; - if (GHIDRA_CAST(this->_mainLaser) != pEVar4) { - if (GHIDRA_CAST(this->_mainLaser) != GHIDRA_CAST(0x0)) { - VStack_94.y = (float)&this->_mainLaser; - msvc::multiset::erase(); - } - this->_mainLaser = pEVar4; - goto LAB_00a02da1; - } - } - else { - if (pEVar4->_parent != 0) { - VStack_94.y = (float)&pEVar4->_parent; - msvc::multiset::erase(); - } - pEVar4->_parent = local_8c; -LAB_00a02da1: - msvc::multiset::insert(); - } - fVar8 = (float)(GHIDRA_INT(local_98) + 1); - Speed = (float)aimDir; - local_98 = GHIDRA_CAST(fVar8); - } while (GHIDRA_INT(fVar8) < GHIDRA_INT(multiShotParams[0])); - } - for (local_98 = GHIDRA_CAST(((*GHIDRA_CAST((GHIDRA_CAST(&(auStack_54)) + 0x4))) & 0xffff)); local_98 != GHIDRA_CAST(0x0); - local_98 = GHIDRA_CAST((GHIDRA_INT(local_98) + -1))) { - uVar6 = Random(); - fVar8 = (float)((double)GHIDRA_INT(uVar6) + __uint_to_double_fixup[-(GHIDRA_INT(uVar6) >> 0x1f)]) * - 2.3283064e-10 * 3.14; - VStack_94.y = fVar8 + fVar8; - local_80.x = cos(VStack_94.y); - local_80.y = sin(VStack_94.y); - pEVar2 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))); - if (pEVar2 == GHIDRA_CAST(0x0)) { - local_9c = g_vectorZero.y; - (*GHIDRA_CAST((GHIDRA_CAST(&(local_a4)) + 0x4))) = g_vectorZero.x; - fVar8 = extraout_ECX; - } - else { - fVar8 = (pEVar2->_pos).y; - (*GHIDRA_CAST((GHIDRA_CAST(&(local_a4)) + 0x4))) = (pEVar2->_pos).x; - local_9c = fVar8; - } - (*GHIDRA_CAST((GHIDRA_CAST(&(local_a4)) + 0x0))) = - Weapon::FireBrimstone(pEVar2,GHIDRA_CAST((local_a4 + 4)),&local_80,damageMultiplier,fVar8,0) - ; - setColorFn = *(code **)(*(*GHIDRA_CAST((GHIDRA_CAST(&(GHIDRA_CAST(local_a4))) + 0x0))) + 0x3c); - laserColor = Weapon::get_laser_color(GHIDRA_CAST(this),GHIDRA_CAST((auStack_54 + 0x14))); - piVar9 = GHIDRA_CAST(0x0); - (*setColorFn)(laserColor,0xffffffff,0xff); - (*GHIDRA_CAST((GHIDRA_CAST(&(local_a4)) + 0x4))) = this->_mainLaser; - pEVar4 = GHIDRA_CAST((piVar9 + 0xef)); - if (*GHIDRA_CAST(pEVar4) != 0.0) { - (*GHIDRA_CAST((GHIDRA_CAST(&(local_a4)) + 0x0))) = pEVar4; - msvc::multiset::erase(local_a4); - } - *GHIDRA_CAST(pEVar4) = (*GHIDRA_CAST((GHIDRA_CAST(&(local_a4)) + 0x4))); - if ((*GHIDRA_CAST((GHIDRA_CAST(&((float)local_a4)) + 0x4))) != 0.0) { - msvc::multiset::insert(pEVar4); - } - (**(code **)(*piVar9 + 0xc))(); - fVar8 = extraout_ECX_00; - } - auStack_54[1] = (char)((*GHIDRA_CAST((GHIDRA_CAST(&(GHIDRA_UINT(auStack_54))) + 0x0))) >> 8); - isShootingBackwards = auStack_54[1] != '\0'; - if (isShootingBackwards) { - pEVar2 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))); - local_80.x = -aimDir->x; - local_80.y = -aimDir->y; - if (pEVar2 == GHIDRA_CAST(0x0)) { - (*GHIDRA_CAST((GHIDRA_CAST(&(local_a4)) + 0x4))) = g_vectorZero.x; - local_9c = g_vectorZero.y; - } - else { - fVar8 = (pEVar2->_pos).y; - (*GHIDRA_CAST((GHIDRA_CAST(&(local_a4)) + 0x4))) = (pEVar2->_pos).x; - local_9c = fVar8; - } - (*GHIDRA_CAST((GHIDRA_CAST(&(local_a4)) + 0x0))) = - Weapon::FireBrimstone(pEVar2,GHIDRA_CAST((local_a4 + 4)),&local_80,damageMultiplier,fVar8,0) - ; - setColorFn = *(code **)(*(*GHIDRA_CAST((GHIDRA_CAST(&(GHIDRA_CAST(local_a4))) + 0x0))) + 0x3c); - laserColor = Weapon::get_laser_color(GHIDRA_CAST(this),GHIDRA_CAST((auStack_54 + 0x14))); - piVar9 = GHIDRA_CAST(0x0); - (*setColorFn)(laserColor,0xffffffff,0xff); - fVar8 = (float)this->_mainLaser; - pEVar4 = GHIDRA_CAST((piVar9 + 0xef)); - if (*GHIDRA_CAST(pEVar4) != 0.0) { - (*GHIDRA_CAST((GHIDRA_CAST(&(local_a4)) + 0x0))) = pEVar4; - msvc::multiset::erase(local_a4); - } - *GHIDRA_CAST(pEVar4) = fVar8; - if (fVar8 != 0.0) { - msvc::multiset::insert(pEVar4); - } - (**(code **)(*piVar9 + 0xc))(); - fVar8 = extraout_ECX_01; - } - if (auStack_54[2] == '\0') { - return; - } - pEVar2 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))); - local_80.x = -aimDir->y; - local_80.y = aimDir->x; - if (pEVar2 == GHIDRA_CAST(0x0)) { - local_9c = g_vectorZero.y; - (*GHIDRA_CAST((GHIDRA_CAST(&(local_a4)) + 0x4))) = g_vectorZero.x; - } - else { - fVar8 = (pEVar2->_pos).y; - (*GHIDRA_CAST((GHIDRA_CAST(&(local_a4)) + 0x4))) = (pEVar2->_pos).x; - local_9c = fVar8; - } - (*GHIDRA_CAST((GHIDRA_CAST(&(local_a4)) + 0x0))) = - Weapon::FireBrimstone(pEVar2,GHIDRA_CAST((local_a4 + 4)),&local_80,damageMultiplier,fVar8,0); - setColorFn = *(code **)(*(*GHIDRA_CAST((GHIDRA_CAST(&(GHIDRA_CAST(local_a4))) + 0x0))) + 0x3c); - laserColor = Weapon::get_laser_color(GHIDRA_CAST(this),GHIDRA_CAST((auStack_54 + 0x14))); - piVar10 = GHIDRA_CAST(0x0); - piVar9 = GHIDRA_CAST(0xffffffff); - (*setColorFn)(laserColor,0xffffffff,0xff); - iVar5 = this->_mainLaser; - pEVar4 = GHIDRA_CAST((piVar10 + 0xef)); - if (*GHIDRA_CAST(pEVar4) != 0) { - (*GHIDRA_CAST((GHIDRA_CAST(&(local_a4)) + 0x0))) = pEVar4; - msvc::multiset::erase(local_a4); - } - *GHIDRA_CAST(pEVar4) = iVar5; - if (iVar5 != 0) { - msvc::multiset::insert(pEVar4); - } - (**(code **)(*piVar10 + 0xc))(); - pEVar2 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x4)))); - VStack_94.x = local_98[1]; - VStack_94.y = -*local_98; - if (pEVar2 == GHIDRA_CAST(0x0)) { - fVar8 = extraout_ECX_02; - } - else { - fVar8 = (pEVar2->_pos).y; - } - pEVar4 = Weapon::FireBrimstone(pEVar2,GHIDRA_CAST((auStack_a8 + -0xc)),&VStack_94,local_9c,fVar8,0) - ; - setColorFn = *(code **)(*GHIDRA_CAST(pEVar4) + 0x3c); - laserColor = Weapon::get_laser_color(GHIDRA_CAST(this),GHIDRA_CAST(auStack_54)); - (*setColorFn)(laserColor,0xffffffff,0xff,0,1); - iVar5 = this->_mainLaser; - piVar10 = piVar9 + 0xef; - if (*piVar10 != 0) { - msvc::multiset::erase(auStack_a8 + -0x10); - } - *piVar10 = iVar5; - if (iVar5 != 0) { - msvc::multiset::insert(piVar10); - } - (**(code **)(*piVar9 + 0xc))(); - return; - } - Weapon::UpdateHeadChargeAnimation(GHIDRA_CAST(this),0x76,3,GHIDRA_CAST(Speed),-1.0); - Weapon::SetBlinkTime(GHIDRA_CAST(this),10,unused); - isAnyHit = 0; - iVar5 = 0; - VStack_94.x = (float)(GHIDRA_UINT(VStack_94.x) & 0xffffff); - if (0 < multiShotParams[0]) { - do { - (*GHIDRA_CAST((GHIDRA_CAST(&(local_a4)) + 0x4))) = aimDir->x; - local_9c = aimDir->y; - Entity_Player::GetMultiShotPositionVelocity - (&local_80,iVar5,10,*aimDir,(*GHIDRA_CAST((GHIDRA_CAST(&((float)local_a4)) + 0x0))),multiShotParams[0],fStack_6c, - fStack_68,fStack_64,local_60,iStack_5c,fStack_58,auStack_54[0],(*GHIDRA_CAST((GHIDRA_CAST(&(auStack_54)) + 0x4)))); - if ((*GHIDRA_CAST((GHIDRA_CAST(&(VStack_94.x)) + 0x3))) == '\0') { - isHitscanHit = fire_hitscan(this,&g_vectorZero,&local_78,0,damageMultiplier); - isAnyHit = 0; - if (isHitscanHit != 0) goto LAB_00a02a08; - } - else { -LAB_00a02a08: - isAnyHit = 1; - } - iVar5 = iVar5 + 1; - VStack_94.x = (float)CONCAT13(isAnyHit,(*GHIDRA_CAST((GHIDRA_CAST(&(VStack_94.x)) + 0x0)))); - } while (iVar5 < multiShotParams[0]); - } - pVVar3 = aimDir; - fVar8 = (*GHIDRA_CAST((GHIDRA_CAST(&((float)auStack_54)) + 0x0))); - for (uVar6 = (*GHIDRA_CAST((GHIDRA_CAST(&(auStack_54)) + 0x4))) & 0xffff; aimDir = pVVar3, (*GHIDRA_CAST((GHIDRA_CAST(&(auStack_54)) + 0x0))) = fVar8, uVar6 != 0; - uVar6 = uVar6 - 1) { - if (isAnyHit == 0) { - rngValue = Random(); - fVar8 = (float)((double)GHIDRA_INT(rngValue) + __uint_to_double_fixup[-(GHIDRA_INT(rngValue) >> 0x1f)]) * - 2.3283064e-10 * 3.14; - local_98 = GHIDRA_CAST((fVar8 + fVar8)); - (*GHIDRA_CAST((GHIDRA_CAST(&(local_a4)) + 0x4))) = cos((float)local_98); - local_9c = sin((float)local_98); - isHitscanHit = fire_hitscan(this,&g_vectorZero,GHIDRA_CAST((local_a4 + 4)),0,damageMultiplier); - isAnyHit = 0; - if (isHitscanHit != 0) goto LAB_00a02aa9; - } - else { -LAB_00a02aa9: - isAnyHit = 1; - } - pVVar3 = aimDir; - fVar8 = (*GHIDRA_CAST((GHIDRA_CAST(&((float)auStack_54)) + 0x0))); - } - auStack_54[1] = (char)(GHIDRA_UINT(fVar8) >> 8); - if (auStack_54[1] != '\0') { - if (isAnyHit != 0) goto LAB_00a02bed; - (*GHIDRA_CAST((GHIDRA_CAST(&(local_a4)) + 0x4))) = -pVVar3->x; - local_9c = -pVVar3->y; - isAnyHit = fire_hitscan(this,&g_vectorZero,GHIDRA_CAST((local_a4 + 4)),0,damageMultiplier); - fVar8 = (*GHIDRA_CAST((GHIDRA_CAST(&((float)auStack_54)) + 0x0))); - } - if (isAnyHit != 0) goto LAB_00a02bed; - auStack_54[2] = (char)(GHIDRA_UINT(fVar8) >> 0x10); - if (auStack_54[2] != '\0') { - (*GHIDRA_CAST((GHIDRA_CAST(&(local_a4)) + 0x4))) = -pVVar3->y; - local_9c = pVVar3->x; - isAnyHit = fire_hitscan(this,&g_vectorZero,GHIDRA_CAST((local_a4 + 4)),0,damageMultiplier); - if (isAnyHit != 0) goto LAB_00a02bed; - (*GHIDRA_CAST((GHIDRA_CAST(&(local_a4)) + 0x4))) = pVVar3->y; - local_9c = -pVVar3->x; - isAnyHit = fire_hitscan(this,&g_vectorZero,GHIDRA_CAST((local_a4 + 4)),0,damageMultiplier); - if (isAnyHit != 0) goto LAB_00a02bed; - } - if (local_8c == GHIDRA_CAST(0x0)) { - return; - } - if (*GHIDRA_CAST((GHIDRA_CAST(local_8c) + 0x1519)) != '\0') { - return; - } - piVar9 = *GHIDRA_CAST((GHIDRA_CAST(local_8c) + 0x150c)); - if (piVar9 == *GHIDRA_CAST((GHIDRA_CAST(local_8c) + 0x1510))) { - return; - } - while ((*GHIDRA_CAST(*piVar9) != 0 || ((GHIDRA_CAST(*piVar9))[1] != 0x7f))) { - piVar9 = piVar9 + 4; - if (piVar9 == *GHIDRA_CAST((GHIDRA_CAST(local_8c) + 0x1510))) { - return; - } - } -LAB_00a02bed: - fVar7 = (long double)this->GetMaxCharge(); - local_98 = GHIDRA_CAST((float)fVar7); - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x14)))) = - ((float)local_98 - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x14))))) * 0.5 + *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((this)) + 0x14)))); - if (local_8c != GHIDRA_CAST(0x0)) { - pvVar1 = (g_manager->_itemConfig)._nullItems._begin; - if ((0x1fc < GHIDRA_INT((GHIDRA_INT((g_manager->_itemConfig)._nullItems._end) - GHIDRA_INT(pvVar1) & 0xfffffffcU))) - && (local_80.x = *GHIDRA_CAST((GHIDRA_CAST(pvVar1) + 0x1fc)), local_80.x != 0.0)) { - local_78.x = *GHIDRA_CAST((GHIDRA_CAST(local_80.x) + 0x78)); - local_80.y = 0.0; - local_78.y = 0.0; - TemporaryEffects::RemoveEffect(GHIDRA_CAST((GHIDRA_INT(local_8c) + 0x1508)),&local_80,-1); - return; - } - } - return; -} diff --git a/generated-src/weapon_laser.cpp b/generated-src/weapon_laser.cpp deleted file mode 100644 index 172c8a3..0000000 --- a/generated-src/weapon_laser.cpp +++ /dev/null @@ -1,733 +0,0 @@ -#include "classes.h" - -// 00a052a0 -void Weapon_Laser::Reset() -{ - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x4c)) = 0; - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x48)) = 0; - return; -} - -// 00a052b0 -void Weapon_Laser::Fire(Vector *param_1, uint8_t param_2, uint8_t param_3) -{ - uint8_t isMarkedAim; - Entity_Player *pEVar2; - uint32_t isCursedEye; - Vector *vecResult; - int *ludoLaser; - Entity_Laser *newLudoLaser; - int iVar3; - char isMonstrosLung; - Weapon *in_ECX; - uint32_t unused; - int unused_00; - int unusedArg; - int unused_01; - int extraout_ECX; - int unused_02; - int unused_03; - int extraout_ECX_00; - int extraout_ECX_01; - int extraout_ECX_02; - int extraout_ECX_03; - int extraout_ECX_04; - Entity_Player *ownerPlayer; - int iVar4; - int extraout_ECX_05; - int extraout_ECX_06; - uint8_t bVar5; - int ownerEntity; - uint32_t isCursedEye; - long double maxCharge; - float fVar7; - float fVar8; - float fVar9; - double dVar10; - uint8_t isFiring; - float fStack_60; - uint8_t local_5c [8]; - float fStack_54; - float local_50; - Vector local_4c; - Vector scratchVec; - Vector aimDirection; - Vector ownerPos; - uint8_t multiShotParams [29]; - char isFireBackward; - char isFireSideways; - uint16_t uStack_c; - bool isChargeWeapon; - bool isFireReady; - bool isMarkedAim; - - isFiring = param_2; - Weapon::Fire(in_ECX,param_1,param_2,param_3); - isCursedEye = in_ECX->_modifiers; - local_50 = (float)(isCursedEye >> 6 & 0xffffff01); - pEVar2 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x4)))); - (*GHIDRA_CAST((GHIDRA_CAST(&(local_5c)) + 0x4))) = pEVar2; - if (pEVar2 == GHIDRA_CAST(0x0)) { - ownerPos.x = g_vectorZero.x; - ownerPos.y = g_vectorZero.y; -LAB_00a0534f: - ownerPlayer = GHIDRA_CAST(0x0); - if ((pEVar2 == GHIDRA_CAST(0x0)) || (pEVar2->_type != 1)) { -LAB_00a05373: - if ((pEVar2 == GHIDRA_CAST(0x0)) || - ((pEVar2->_type != 1 && - ((pEVar2->_type != 3 || - (pEVar2 = *GHIDRA_CAST(&pEVar2->_isControlsEnabled), pEVar2 == GHIDRA_CAST(0x0)) - ))))) { - (*GHIDRA_CAST((GHIDRA_CAST(&(local_5c)) + 0x0))) = 1.0; - (*GHIDRA_CAST((GHIDRA_CAST(&(local_5c)) + 0x4))) = GHIDRA_CAST(0x0); - } - else { - (*GHIDRA_CAST((GHIDRA_CAST(&(local_5c)) + 0x4))) = GHIDRA_CAST(0x0); - (*GHIDRA_CAST((GHIDRA_CAST(&(local_5c)) + 0x0))) = pEVar2->_shotspeed; - } - } - else { - (*GHIDRA_CAST((GHIDRA_CAST(&(local_5c)) + 0x0))) = pEVar2->_shotspeed; - } - } - else { - ownerPos.x = (pEVar2->_pos).x; - ownerPos.y = (pEVar2->_pos).y; - if (pEVar2->_type != 1) { - if (pEVar2->_type != 3) goto LAB_00a0534f; - ownerPlayer = *GHIDRA_CAST(&pEVar2->_isControlsEnabled); - goto LAB_00a05373; - } - (*GHIDRA_CAST((GHIDRA_CAST(&(local_5c)) + 0x0))) = pEVar2->_shotspeed; - ownerPlayer = pEVar2; - } - if ((isCursedEye >> 4 & 1) != 0) { - if (param_3 == 0) { - ludoLaser = *GHIDRA_CAST((in_ECX + 1)); - if (ludoLaser == GHIDRA_CAST(0x0)) { -LAB_00a05f6a: - if (ludoLaser != GHIDRA_CAST(0x0)) goto LAB_00a05f6e; - } - else { - if ((ludoLaser[0xb] != 2) || (ludoLaser[0xc] != 1)) { - (**(code **)(*ludoLaser + 0x28))(); - ludoLaser = *GHIDRA_CAST((in_ECX + 1)); - goto LAB_00a05f6a; - } -LAB_00a05f6e: - if (*GHIDRA_CAST((GHIDRA_CAST(ludoLaser) + 0x173)) == '\0') goto LAB_00a06048; - } - isCursedEye = Random(); - newLudoLaser = (Entity_Laser *) - Game::SpawnEx(g_game,7,2,&ownerPos,&g_vectorZero,*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x4)))) - ,1,isCursedEye,0); - if ((newLudoLaser == GHIDRA_CAST(0x0)) || (newLudoLaser->_type != 7)) { - newLudoLaser = GHIDRA_CAST(0x0); - } - (newLudoLaser->_posOffset).x = 0.0; - (newLudoLaser->_posOffset).y = -20.0; - local_4c.x = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x4)))); - if (newLudoLaser->_parent != 0) { - scratchVec.x = (float)&newLudoLaser->_parent; - msvc::multiset::erase(); - } - newLudoLaser->_parent = local_4c.x; - if (local_4c.x != 0.0) { - msvc::multiset::insert(); - } - newLudoLaser->_renderDepthOffset = 3000.0; - init_laser(in_ECX,newLudoLaser); - (**(code **)(*GHIDRA_CAST(newLudoLaser) + 0xc))(); - if (*GHIDRA_CAST((in_ECX + 1)) != newLudoLaser) { - if (*GHIDRA_CAST((in_ECX + 1)) != GHIDRA_CAST(0x0)) { - scratchVec.x = (float)(in_ECX + 1); - msvc::multiset::erase(); - } - *GHIDRA_CAST((in_ECX + 1)) = newLudoLaser; - msvc::multiset::insert(); - } - } -LAB_00a06048: - ownerEntity = *GHIDRA_CAST((in_ECX + 1)); - if (ownerEntity == 0) { - return; - } - fVar9 = param_1->x; - fVar7 = param_1->y; - fVar8 = fVar7 * fVar7 + fVar9 * fVar9; - local_50 = fVar7; - local_4c.x = fVar9; - if (1.0 < fVar8) { - fVar8 = sqrtf(fVar8); - fVar9 = local_4c.x; - fVar7 = local_50; - if (0.0 < fVar8) { - fVar7 = local_50 * (1.0 / fVar8); - fVar9 = local_4c.x * (1.0 / fVar8); - } - } - if (param_2 == 0) { - iVar4 = *GHIDRA_CAST((GHIDRA_CAST(g_game->_room) + 0x12c4)) + *GHIDRA_CAST((GHIDRA_CAST(g_game->_room) + 0x12c0)); - iVar3 = 0; - if (0 < iVar4) { - iVar3 = iVar4; - } - if (0 < iVar3) goto LAB_00a06200; - fVar7 = ownerPos.x - *GHIDRA_CAST((ownerEntity + 0x33c)); - fVar9 = ownerPos.y - *GHIDRA_CAST((ownerEntity + 0x340)); - if (fVar9 * fVar9 + fVar7 * fVar7 <= 10000.0) goto LAB_00a06200; - aimDirection.x = ownerPos.x - *GHIDRA_CAST((ownerEntity + 0x33c)); - aimDirection.y = ownerPos.y - *GHIDRA_CAST((ownerEntity + 0x340)); - vecResult = (GHIDRA_CAST((&aimDirection)))->Vector::Normalized(&scratchVec); - fVar8 = *GHIDRA_CAST((ownerEntity + 0x36c)); - fVar9 = vecResult->x * 0.3 * 0.5; - fVar7 = vecResult->y * 0.3 * 0.5; - } - else { - fVar8 = *GHIDRA_CAST((ownerEntity + 0x36c)); - fVar9 = fVar9 * 2.0 * 0.5 * (*GHIDRA_CAST((GHIDRA_CAST(&((float)local_5c)) + 0x0))); - fVar7 = fVar7 * 2.0 * 0.5 * (*GHIDRA_CAST((GHIDRA_CAST(&((float)local_5c)) + 0x0))); - } - if (fVar8 != 0.0) { - *GHIDRA_CAST((ownerEntity + 0x364)) = - (fVar7 * *GHIDRA_CAST((ownerEntity + 0x39c))) / fVar8 + *GHIDRA_CAST((ownerEntity + 0x364)); - *GHIDRA_CAST((ownerEntity + 0x360)) = - (fVar9 * *GHIDRA_CAST((ownerEntity + 0x39c))) / fVar8 + *GHIDRA_CAST((ownerEntity + 0x360)); - } -LAB_00a06200: - if (param_3 != 0) { - return; - } - init_laser(in_ECX,*GHIDRA_CAST((in_ECX + 1))); - if ((*GHIDRA_CAST((GHIDRA_CAST(&(GHIDRA_CAST(local_5c))) + 0x4))) == GHIDRA_CAST(0x0)) { - return; - } - ownerEntity = Entity::GetIntervalTicks - ((*GHIDRA_CAST((GHIDRA_CAST(&(GHIDRA_CAST(local_5c))) + 0x4))),*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x10)))),0.0); - if (ownerEntity == 0) { - return; - } - ownerEntity = *GHIDRA_CAST((in_ECX + 1)); - if (ownerEntity != 0) { - scratchVec.x = *GHIDRA_CAST((ownerEntity + 0x33c)); - scratchVec.y = *GHIDRA_CAST((ownerEntity + 0x340)); - aimDirection.x = *GHIDRA_CAST((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x4)))) + 0x33c)); - aimDirection.y = *GHIDRA_CAST((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x4)))) + 0x340)); - bVar5 = (GHIDRA_CAST((&scratchVec)))->Vector::operator_ne(&aimDirection); - if (bVar5 != 0) { - aimDirection.x = - *GHIDRA_CAST((ownerEntity + 0x33c)) - *GHIDRA_CAST((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x4)))) + 0x33c)); - aimDirection.y = - *GHIDRA_CAST((ownerEntity + 0x340)) - *GHIDRA_CAST((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x4)))) + 0x340)); - vecResult = (GHIDRA_CAST((&aimDirection)))->Vector::Normalized(&scratchVec); - Weapon::TriggerTearEffects(in_ECX,vecResult,1); - return; - } - } - vecResult = MusicManager::RandomVector(&aimDirection); - Weapon::TriggerTearEffects(in_ECX,vecResult,1); - return; - } - isCursedEye = isCursedEye >> 1; - bVar5 = (uint8_t)in_ECX->_modifiers & 1; - unused = CONCAT31((uint3)(isCursedEye >> 0xb),(char)(isCursedEye >> 3)) & 0xffffff01; - if ((((isCursedEye >> 3 & 1) != 0) || (bVar5 != 0)) || (isChargeWeapon = false, (isCursedEye & 1) != 0)) - { - isChargeWeapon = true; - } - if ((ownerPlayer == GHIDRA_CAST(0x0)) || - ((isMarkedAim = Entity_Player::HasCollectible(ownerPlayer,0x18a,0), isMarkedAim == 0 && - (isMarkedAim = Entity_Player::HasCollectible(ownerPlayer,0x23c,0), isMarkedAim == 0)))) { - isMarkedAim = false; - } - else { - isMarkedAim = true; - } - if (((GHIDRA_UINT(in_ECX->_modifiers) >> 7 & 1) != 0) || - (isFireReady = false, *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x10)))) <= 0.0)) { - isFireReady = true; - } - maxCharge = (long double)(**(code **)(*GHIDRA_CAST(in_ECX) + 0x18))(); - (*GHIDRA_CAST((GHIDRA_CAST(&(local_5c)) + 0x0))) = (BADTYPE)maxCharge; - if ((isCursedEye & 1) != 0) { - (*GHIDRA_CAST((GHIDRA_CAST(&(local_5c)) + 0x0))) = (*GHIDRA_CAST((GHIDRA_CAST(&((float)local_5c)) + 0x0))) * 0.5; - } - ownerEntity = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x4)))); - isMonstrosLung = (char)unused; - if (((ownerEntity != 0) && (*GHIDRA_CAST((ownerEntity + 0x28)) == 1)) && - (0 < *GHIDRA_CAST((ownerEntity + 0x18f8)))) { - if ((isMonstrosLung == '\0') && (bVar5 == 0)) { -LAB_00a054d2: - if (((isCursedEye & 1) == 0) || (GHIDRA_INT(in_ECX[1]._technology2Laser) < 1)) goto LAB_00a054e1; - } - else { - local_4c.x = 5.0; - vecResult = GHIDRA_CAST(local_5c); - if (5.0 <= (*GHIDRA_CAST((GHIDRA_CAST(&((float)local_5c)) + 0x0)))) { - vecResult = &local_4c; - } - if (*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x14)))) < vecResult->x) goto LAB_00a054d2; - } - isFiring = 0; - } -LAB_00a054e1: - if ((((param_3 == 0) && (isFiring != 0)) && (isFireReady)) && - ((((isMonstrosLung != '\0' || (bVar5 != 0)) && - (fVar9 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x14)))), (*GHIDRA_CAST((GHIDRA_CAST(&((float)local_5c)) + 0x0))) <= fVar9)) || - (((isCursedEye & 1) != 0 && - (((fVar9 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x14)))), 0.0 < fVar9 && - (4 < GHIDRA_INT(in_ECX[1]._technology2Laser))) || - ((fVar9 <= 0.0 && (0 < GHIDRA_INT(in_ECX[1]._technology2Laser))))))))))) { - local_4c.x = 1e-05; - isFiring = 0; - vecResult = &local_4c; - if (1e-05 <= fVar9) { - vecResult = GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x14)))); - } - fVar9 = vecResult->x; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(in_ECX[1])) + 0x4)))) = fVar9; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x14)))) = fVar9; - } - if ((ownerEntity == 0) || - ((((*GHIDRA_CAST((ownerEntity + 0x28)) != 1 && - ((*GHIDRA_CAST((ownerEntity + 0x28)) != 3 || - (ownerEntity = *GHIDRA_CAST((ownerEntity + 0x410)), ownerEntity == 0)))) || - (ownerEntity = *GHIDRA_CAST((ownerEntity + 0x140c)), ownerEntity == 0)) || (!isMarkedAim)))) { - fVar9 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x28)))); - fVar7 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x2c)))); - } - else { - fVar9 = *GHIDRA_CAST((ownerEntity + 0x33c)); - fVar7 = *GHIDRA_CAST((ownerEntity + 0x340)); - } - if ((fVar9 == g_vectorZero.x) && (fVar7 == g_vectorZero.y)) { - isMarkedAim = false; - } - else { - isMarkedAim = true; - } - scratchVec.x = fVar9; - scratchVec.y = fVar7; - if (((param_3 == 0) && (isFiring != 0)) && (isMarkedAim)) { - vecResult = Weapon::get_owner_position(in_ECX,&scratchVec); - fVar7 = fVar7 - vecResult->y; - fVar9 = fVar9 - vecResult->x; - fVar7 = sqrtf(fVar7 * fVar7 + fVar9 * fVar9); - fVar9 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x14)))); - fVar7 = (fVar7 - 50.0) / 250.0; - if (fVar7 <= 0.0) { - fVar7 = 0.0; - } - if (1.0 <= fVar7) { - fVar7 = 1.0; - } - if (fVar9 <= 0.0) { - ownerEntity = 1; - } - else { - ownerEntity = GHIDRA_INT((fVar7 * 4.0 + 1.0)); - } - if (((bVar5 != 0) && ((((*GHIDRA_CAST((GHIDRA_CAST(&((float)local_5c)) + 0x0))) - 5.0) * fVar7 + 5.0) - 1.0 < fVar9)) || - ((isMonstrosLung != '\0' && ((*GHIDRA_CAST((GHIDRA_CAST(&((float)local_5c)) + 0x0))) < fVar9)))) { - isFiring = 0; - } - else if ((isCursedEye & 1) != 0) { - if (ownerEntity <= GHIDRA_INT(in_ECX[1]._technology2Laser)) { - isFiring = 0; - } - } - } - isCursedEye = 0; - local_4c.x = 1.4013e-45; - if (isChargeWeapon) { - if (isFiring == 0) { - if ((bVar5 == 0) || (*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x14)))) <= 0.0)) { - if ((isMonstrosLung == '\0') || (*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x14)))) < (*GHIDRA_CAST((GHIDRA_CAST(&((float)local_5c)) + 0x0))))) { - if ((isCursedEye & 1) != 0) { - if (0 < GHIDRA_INT(in_ECX[1]._technology2Laser)) { - isCursedEye = 1; - } - } - } - else { - isCursedEye = 1; - } - } - else { - isCursedEye = 1; - } - } - if (param_3 != 0) { - if (isCursedEye == 0) { - return; - } - Weapon::SetBlinkTime(in_ECX,1,unused); - return; - } - } - else if (isFiring != 0) { - if (param_3 != 0) { - return; - } - if (*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0xc)))) <= 0.0 && *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0xc)))) != 0.0) { - do { - if (7 < isCursedEye) break; - isCursedEye = isCursedEye + 1; - fVar9 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x10)))) + 1.0 + *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0xc)))); - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0xc)))) = fVar9; - } while (fVar9 < 0.0); - } - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(in_ECX[1])) + 0x4)))) = 0; - } - aimDirection.x = param_1->x; - aimDirection.y = param_1->y; - if (param_2 == 0) { - aimDirection.x = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x20)))); - aimDirection.y = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x24)))); - } - isMarkedAim = Weapon::IsAxisAligned(in_ECX); - fStack_60 = aimDirection.x; - if (isMarkedAim == 0) { - (*GHIDRA_CAST((GHIDRA_CAST(&(local_5c)) + 0x4))) = aimDirection.y; - fVar9 = sqrtf(aimDirection.y * aimDirection.y + aimDirection.x * aimDirection.x); - if (fVar9 <= 0.0) { - pEVar2 = (*GHIDRA_CAST((GHIDRA_CAST(&(GHIDRA_CAST(local_5c))) + 0x4))); - } - else { - aimDirection.y = (*GHIDRA_CAST((GHIDRA_CAST(&((float)local_5c)) + 0x4))) * (1.0 / fVar9); - fStack_60 = (1.0 / fVar9) * fStack_60; - pEVar2 = GHIDRA_CAST(aimDirection.y); - aimDirection.x = fStack_60; - } - } - else { - vecResult = Vector::ToCardinal(&scratchVec,&aimDirection); - fStack_60 = vecResult->x; - aimDirection.y = vecResult->y; - pEVar2 = GHIDRA_CAST(aimDirection.y); - aimDirection.x = fStack_60; - } - if (isCursedEye == 0) goto LAB_00a05c7f; - if (isMonstrosLung != '\0') { - Weapon::UpdateHeadChargeAnimation(in_ECX,0xe5,2,&aimDirection,-1.0); - fStack_60 = aimDirection.x; - pEVar2 = GHIDRA_CAST(aimDirection.y); - } - fStack_60 = fStack_60 * 10.0; - (*GHIDRA_CAST((GHIDRA_CAST(&(local_5c)) + 0x4))) = (float)pEVar2 * 10.0; - if ((*GHIDRA_CAST((GHIDRA_CAST(&(local_50)) + 0x0))) == '\0') { - vecResult = Weapon::get_tear_movement_inheritance(in_ECX,&scratchVec,&aimDirection); - (*GHIDRA_CAST((GHIDRA_CAST(&(local_5c)) + 0x4))) = vecResult->y * 0.4 + (*GHIDRA_CAST((GHIDRA_CAST(&((float)local_5c)) + 0x4))); - fStack_60 = vecResult->x * 0.4 + fStack_60; - } - fVar9 = sqrtf(fStack_60 * fStack_60 + (*GHIDRA_CAST((GHIDRA_CAST(&((float)local_5c)) + 0x4))) * (*GHIDRA_CAST((GHIDRA_CAST(&((float)local_5c)) + 0x4)))); - if (fVar9 <= 0.0) { - aimDirection.y = (*GHIDRA_CAST((GHIDRA_CAST(&((float)local_5c)) + 0x4))); - } - else { - fStack_60 = fStack_60 * (1.0 / fVar9); - aimDirection.y = (float)((*GHIDRA_CAST((GHIDRA_CAST(&((float)local_5c)) + 0x4))) * (1.0 / fVar9)); - } - aimDirection.x = fStack_60; - Weapon::SetBlinkTime(in_ECX,7 - GHIDRA_INT((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x10)))) * -0.45)),unused_00); - Weapon::TriggerTearEffects(in_ECX,&aimDirection,1); - Weapon::GetMultiShotParams(in_ECX,multiShotParams,unusedArg); - fVar9 = 0.0; - if (isMonstrosLung != '\0') { - fVar9 = 1.68156e-44; - } - if (bVar5 == 0) { - fStack_60 = 1.0; - if (isMonstrosLung != '\0') goto LAB_00a05a05; - } - else { - fVar7 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(in_ECX[1])) + 0x4)))) + 1.0; - if (isMonstrosLung == '\0') { - fStack_60 = (fVar7 * 4.0) / ((*GHIDRA_CAST((GHIDRA_CAST(&((float)local_5c)) + 0x0))) + 1.0); - if (fStack_60 <= 0.1) { - fStack_60 = 0.1; - } - if (4.0 <= fStack_60) { - fStack_60 = 4.0; - } - } - else { - fStack_60 = (fVar7 * 2.5) / ((*GHIDRA_CAST((GHIDRA_CAST(&((float)local_5c)) + 0x0))) + 1.0); - if (fStack_60 <= 0.02) { - fStack_60 = 0.02; - } - if (2.5 <= fStack_60) { - fStack_60 = 2.5; - } -LAB_00a05a05: - if (fStack_60 < 1.0) { - scratchVec.x = (float)GHIDRA_INT(fVar9); - (*GHIDRA_CAST((GHIDRA_CAST(&(local_5c)) + 0x4))) = scratchVec.x * fStack_60; - dVar10 = ceil((*GHIDRA_CAST((GHIDRA_CAST(&((double)(float)local_5c)) + 0x4)))); - (*GHIDRA_CAST((GHIDRA_CAST(&(local_5c)) + 0x4))) = (BADTYPE)dVar10; - fVar9 = local_4c.x; - if (1 < GHIDRA_INT(dVar10)) { - fVar9 = (float)GHIDRA_INT(dVar10); - } - fStack_60 = fStack_60 * (scratchVec.x / (float)GHIDRA_INT(fVar9)); - } - } - } - ownerEntity = *GHIDRA_CAST(ThreadLocalStoragePointer); - if (*GHIDRA_CAST((ownerEntity + 0xc)) < DAT_00c943b4) { - _Init_thread_header(); - ownerEntity = extraout_ECX_05; - if (DAT_00c943b4 == -1) { - _atexit(GHIDRA_CAST<_func_4879 *>(&LAB_00b16b00)); - _Init_thread_footer(); - ownerEntity = extraout_ECX_06; - } - } - DAT_00c943bc = DAT_00c943b8; - isCursedEye = 0; - if (isMonstrosLung != '\0') { - isCursedEye = 6; - } - fire_lasers(in_ECX,&ownerPos,&aimDirection,isCursedEye,fStack_60,multiShotParams,GHIDRA_INT(fVar9),ownerEntity) - ; - ownerEntity = unused_01; - if (isFireBackward != '\0') { - scratchVec.x = -aimDirection.x; - scratchVec.y = -aimDirection.y; - fire_lasers(in_ECX,&ownerPos,&scratchVec,5,fStack_60,(void *)0x0,GHIDRA_INT(fVar9),unused_01); - ownerEntity = extraout_ECX; - } - if (isFireSideways != '\0') { - scratchVec.x = aimDirection.y; - scratchVec.y = -aimDirection.x; - fire_lasers(in_ECX,&ownerPos,&scratchVec,5,fStack_60,(void *)0x0,GHIDRA_INT(fVar9),ownerEntity); - scratchVec.x = -aimDirection.y; - scratchVec.y = aimDirection.x; - fire_lasers(in_ECX,&ownerPos,&scratchVec,5,fStack_60,(void *)0x0,GHIDRA_INT(fVar9),unused_02); - } - for (local_4c.x = (float)GHIDRA_UINT(uStack_c); local_4c.x != 0.0; - local_4c.x = (float)(GHIDRA_INT(local_4c.x) - 1)) { - isCursedEye = Random(); - fVar7 = (float)((double)GHIDRA_INT(isCursedEye) + __uint_to_double_fixup[-(GHIDRA_INT(isCursedEye) >> 0x1f)]) * - 2.3283064e-10 * 3.14; - scratchVec.x = fVar7 + fVar7; - (*GHIDRA_CAST((GHIDRA_CAST(&(local_5c)) + 0x4))) = cos(scratchVec.x); - fStack_54 = sin(scratchVec.x); - fire_lasers(in_ECX,&ownerPos,GHIDRA_CAST((local_5c + 4)),5,fStack_60,(void *)0x0,GHIDRA_INT(fVar9), - unused_03); - } - isCursedEye = 0; - local_4c.x = 0.0; - if (DAT_00c943bc - DAT_00c943b8 >> 2 != 0) { - local_50 = (float)(GHIDRA_UINT(local_50) ^ 1); - do { - *GHIDRA_CAST((*GHIDRA_CAST((DAT_00c943b8 + isCursedEye * 4)) + 0x4e4)) = SUB41(local_50,0); - (**(code **)(**GHIDRA_CAST((DAT_00c943b8 + isCursedEye * 4)) + 0xc))(); - isCursedEye = isCursedEye + 1; - } while (isCursedEye < GHIDRA_UINT((DAT_00c943bc - DAT_00c943b8 >> 2))); - } -LAB_00a05c7f: - if (isChargeWeapon) { - if (isFiring == 0) { - if (0 < GHIDRA_INT(in_ECX[1]._technology2Laser)) { - in_ECX[1]._technology2Laser = in_ECX[1]._technology2Laser + -1; - } - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x14)))) = 0; - if ((isMonstrosLung == '\0') || (bVar5 = Weapon::IsItemAnimFinished(in_ECX,0xe5), bVar5 != 0)) - { - pEVar2 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x4)))); - if (((pEVar2 == GHIDRA_CAST(0x0)) || (ownerPlayer = pEVar2, pEVar2->_type != 1)) && - ((ownerPlayer = GHIDRA_CAST(0x0), pEVar2 != GHIDRA_CAST(0x0) && - (pEVar2->_type == 3)))) { - pEVar2->_chargeBarSprites[5]._numEvents = 0; - } - else if (ownerPlayer != GHIDRA_CAST(0x0)) { - Entity_Player::stop_costume_item_anims(ownerPlayer); - } - } - } - else { - pEVar2 = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x14)))); - (*GHIDRA_CAST((GHIDRA_CAST(&(local_5c)) + 0x4))) = pEVar2; - if ((bVar5 != 0) || (isMonstrosLung != '\0')) { - if ((*GHIDRA_CAST((GHIDRA_CAST(&((float)local_5c)) + 0x0))) <= (float)pEVar2) { - Weapon::UpdateHeadChargeAnimation(in_ECX,0xe5,1,&aimDirection,-1.0); - Weapon::UpdateHeadChargeAnimation(in_ECX,0x44,1,&aimDirection,-1.0); - ownerEntity = extraout_ECX_01; - } - else { - (*GHIDRA_CAST((GHIDRA_CAST(&(local_5c)) + 0x4))) = ((float)pEVar2 / (*GHIDRA_CAST((GHIDRA_CAST(&((float)local_5c)) + 0x0)))) * 18.0; - Weapon::UpdateHeadChargeAnimation(in_ECX,0xe5,0,&aimDirection,(*GHIDRA_CAST((GHIDRA_CAST(&((float)local_5c)) + 0x4)))); - Weapon::UpdateHeadChargeAnimation(in_ECX,0x44,0,&aimDirection,(*GHIDRA_CAST((GHIDRA_CAST(&((float)local_5c)) + 0x4)))); - ownerEntity = extraout_ECX_00; - if (*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x4)))) == 0) { - (*GHIDRA_CAST((GHIDRA_CAST(&(local_5c)) + 0x4))) = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x14)))) + 1.0; - } - else { - (*GHIDRA_CAST((GHIDRA_CAST(&(local_5c)) + 0x4))) = - *GHIDRA_CAST((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x4)))) + 0x39c)) + *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x14)))); - } - } - pEVar2 = (*GHIDRA_CAST((GHIDRA_CAST(&(GHIDRA_CAST(local_5c))) + 0x4))); - Weapon::SetBlinkTime(in_ECX,8,ownerEntity); - } - if ((isCursedEye & 1) != 0) { - maxCharge = (long double)(**(code **)(*GHIDRA_CAST(in_ECX) + 0x18))(); - local_4c.x = (float)maxCharge; - if (local_4c.x <= *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x14))))) { - Weapon::UpdateHeadChargeAnimation(in_ECX,0x44,1,&aimDirection,-1.0); - Weapon::UpdateHeadChargeAnimation(in_ECX,0x13c,1,&aimDirection,-1.0); - ownerEntity = extraout_ECX_04; - pEVar2 = (*GHIDRA_CAST((GHIDRA_CAST(&(GHIDRA_CAST(local_5c))) + 0x4))); - } - else { - ownerEntity = extraout_ECX_02; - if (*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x4)))) != 0) { - fVar9 = (*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x14)))) / local_4c.x) * 18.0; - if (*GHIDRA_CAST((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x4)))) + 0x28)) == 1) { - Weapon::UpdateHeadChargeAnimation(in_ECX,0x44,0,&aimDirection,fVar9); - fVar9 = 0.0; - } - Weapon::UpdateHeadChargeAnimation(in_ECX,0x13c,0,&aimDirection,fVar9); - ownerEntity = extraout_ECX_03; - } - if (*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x4)))) == 0) { - pEVar2 = GHIDRA_CAST((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x14)))) + 1.0)); - } - else { - pEVar2 = (Entity_Player *) - (*GHIDRA_CAST((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x4)))) + 0x39c)) + *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x14)))) - ); - } - } - Weapon::SetBlinkTime(in_ECX,1,ownerEntity); - in_ECX[1]._technology2Laser = GHIDRA_INT(((((float)pEVar2 + 1.0) * 5.0) / (local_4c.x + 1.0))); - } - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x14)))) = pEVar2; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&(in_ECX[1])) + 0x4)))) = pEVar2; - } - if (param_2 != 0) { - bVar5 = Weapon::IsAxisAligned(in_ECX); - if (bVar5 == 0) { - vecResult = Weapon::get_aim_direction(in_ECX,&local_4c,&aimDirection); - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x20)))) = vecResult->x; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x24)))) = vecResult->y; - return; - } - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x20)))) = aimDirection.x; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((in_ECX)) + 0x24)))) = aimDirection.y; - return; - } - } - return; -} - -// 00a06330 -void Weapon_Laser::init_laser(Weapon *weapon, Entity_Laser *laser) -{ - int iVar1; - BitSet128 *tearFlags; - ColorMod *laserColor; - float damage; - BitSet128 tearFlagsOut; - ColorMod laserColorOut; - uint32_t local_c; - uint8_t auStack_8 [4]; - uint64_t tearFlagsHigh; - uint32_t tearFlagsWord1; - uint32_t tearFlagsWord3; - code *virtualFn; - - local_c = __security_cookie ^ GHIDRA_UINT((auStack_8 + 4)); - tearFlags = Weapon::get_owner_tear_flags(weapon,&tearFlagsOut); - tearFlagsWord1 = *GHIDRA_CAST((GHIDRA_INT(&tearFlags->_l) + 4)); - tearFlagsHigh = tearFlags->_h; - tearFlagsWord3 = *GHIDRA_CAST((GHIDRA_INT(&tearFlags->_h) + 4)); - iVar1 = *GHIDRA_CAST(laser); - *GHIDRA_CAST(&(laser->_tearFlags)._l) = GHIDRA_INT(tearFlags->_l); - *GHIDRA_CAST((GHIDRA_INT(&(laser->_tearFlags)._l) + 4)) = tearFlagsWord1; - *GHIDRA_CAST(&(laser->_tearFlags)._h) = GHIDRA_INT(tearFlagsHigh); - *GHIDRA_CAST((GHIDRA_INT(&(laser->_tearFlags)._h) + 4)) = tearFlagsWord3; - virtualFn = *(code **)(iVar1 + 0x3c); - laserColor = Weapon::get_laser_color(weapon,&laserColorOut); - (*virtualFn)(laserColor,0xffffffff,0xff,0,1); - virtualFn = *(code **)(*GHIDRA_CAST(laser) + 0x40); - damage = Weapon::get_damage(weapon); - (*virtualFn)(damage); - return; -} - -// 00a063b0 -void Weapon_Laser::ClearReferences() -{ - int *eraseKey; - int *entityRef; - - entityRef = GHIDRA_CAST((GHIDRA_INT(this) + 8)); - eraseKey = this; - if (*GHIDRA_CAST((GHIDRA_CAST(this) + 8)) != GHIDRA_CAST(0x0)) { - (**(code **)(**GHIDRA_CAST((GHIDRA_CAST(this) + 8)) + 0x28))(); - if (*entityRef != 0) { - eraseKey = entityRef; - msvc::multiset::erase(&eraseKey); - *entityRef = 0; - } - } - entityRef = GHIDRA_CAST((GHIDRA_INT(this) + 0x44)); - if (*GHIDRA_CAST((GHIDRA_CAST(this) + 0x44)) != GHIDRA_CAST(0x0)) { - (**(code **)(**GHIDRA_CAST((GHIDRA_CAST(this) + 0x44)) + 0x28))(); - if (*entityRef != 0) { - eraseKey = entityRef; - msvc::multiset::erase(&eraseKey); - *entityRef = 0; - } - } - return; -} - -// 00a06870 -long double Weapon_Laser::GetMaxCharge() -{ - int in_ECX; - float chargeMultiplier; - uint32_t modifiers; - - modifiers = *GHIDRA_CAST((in_ECX + 0x34)); - chargeMultiplier = 1.0; - if ((modifiers >> 3 & 1) != 0) { - chargeMultiplier = 4.3; - } - if ((modifiers & 1) != 0) { - chargeMultiplier = chargeMultiplier * 2.5; - } - if ((modifiers >> 1 & 1) != 0) { - chargeMultiplier = chargeMultiplier + chargeMultiplier; - } - if (1.0 < chargeMultiplier) { - return (long double)((*GHIDRA_CAST((in_ECX + 0x10)) + 1.0) * chargeMultiplier - 1.0); - } - return (long double)0; -} - -// 00a068e0 -uint8_t Weapon_Laser::CanTriggerCursedEyeTeleport() -{ - int iVar1; - long double fVar2; - - iVar1 = *GHIDRA_CAST((GHIDRA_CAST(this) + 4)); - if ((iVar1 != 0) && (*GHIDRA_CAST((iVar1 + 0x28)) == 1)) { - if ((*GHIDRA_CAST((iVar1 + 0x140c)) != 0) && - (iVar1 = this->GetMarkedTargetVariant(), iVar1 != 0)) { - return 0; - } - if ((0.0 < *GHIDRA_CAST((GHIDRA_CAST(this) + 0x14))) && - (fVar2 = (long double)this->GetMaxCharge(), - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x14)) <= (float)fVar2 && (float)fVar2 != *GHIDRA_CAST((GHIDRA_CAST(this) + 0x14))) - ) { - return 1; - } - } - return 0; -} diff --git a/generated-src/weapon_tech_x.cpp b/generated-src/weapon_tech_x.cpp deleted file mode 100644 index 1ac68db..0000000 --- a/generated-src/weapon_tech_x.cpp +++ /dev/null @@ -1,297 +0,0 @@ -#include "classes.h" - -// 00a0d9c0 -void Weapon_TechX::Fire(Vector *direction, uint8_t isShooting, uint8_t isInterpolated) -{ - Vector shotDirection; - bool bVar1; - bool bVar2; - uint8_t bVar3; - uint8_t isAxisAligned; - int ownerPlayer; - Vector *pVVar4; - Entity_Laser *laser; - uint32_t rngResult; - Entity_Player *pEVar5; - int extraout_ECX; - int unusedArg; - Entity_Player *player; - int extraout_ECX_00; - int extraout_ECX_01; - uint32_t randomLasersLeft; - float fVar6; - float fVar7; - float cosAngle; - float fVar8; - float fVar9; - float fVar10; - float fVar11; - float releaseCharge; - Vector local_70; - Vector aimDirection; - Vector local_60; - Vector scratchVec; - float fStack_50; - float fStack_4c; - Vector VStack_48; - uint32_t local_40; - float fStack_3c; - float fStack_38; - float fStack_34; - float fStack_30; - int iStack_2c; - float fStack_28; - uint32_t uStack_24; - uint32_t uStack_20; - int ownerEntity; - - Weapon::Fire(this,direction,isShooting,isInterpolated); - if (isInterpolated != 0) { - return; - } - pEVar5 = *GHIDRA_CAST((GHIDRA_CAST(this) + 4)); - if (pEVar5 == GHIDRA_CAST(0x0)) { -LAB_00a0da10: - player = GHIDRA_CAST(0x0); - if (pEVar5 != GHIDRA_CAST(0x0)) { - if (pEVar5->_type == 1) goto LAB_00a0da2f; - if (pEVar5->_type == 3) goto LAB_00a0da23; - } -LAB_00a0da39: - fVar6 = 1.0; - } - else if (pEVar5->_type == 1) { - fVar6 = pEVar5->_shotspeed; - player = pEVar5; - } - else { - if (pEVar5->_type != 3) goto LAB_00a0da10; - player = *GHIDRA_CAST(&pEVar5->_isControlsEnabled); -LAB_00a0da23: - pEVar5 = *GHIDRA_CAST(&pEVar5->_isControlsEnabled); - if (pEVar5 == GHIDRA_CAST(0x0)) goto LAB_00a0da39; -LAB_00a0da2f: - fVar6 = pEVar5->_shotspeed; - } - if (player == GHIDRA_CAST(0x0)) { -LAB_00a0da62: - bVar1 = false; - } - else { - bVar3 = Entity_Player::HasCollectible(player,0x18a,0); - bVar1 = true; - if (bVar3 == 0) goto LAB_00a0da62; - } - if (((*GHIDRA_CAST((GHIDRA_CAST(this) + 0x34)) >> 7 & 1) != 0) || - (bVar2 = false, *GHIDRA_CAST((GHIDRA_CAST(this) + 0x10)) <= 0.0)) { - bVar2 = true; - } - ownerEntity = *GHIDRA_CAST((GHIDRA_CAST(this) + 4)); - releaseCharge = -1000.0; - if (ownerEntity == 0) { -LAB_00a0dae1: - fVar11 = *GHIDRA_CAST((GHIDRA_CAST(this) + 0x28)); - fVar8 = *GHIDRA_CAST((GHIDRA_CAST(this) + 0x2c)); - } - else { - if (*GHIDRA_CAST((ownerEntity + 0x28)) == 1) { - ownerPlayer = ownerEntity; - } - else if ((*GHIDRA_CAST((ownerEntity + 0x28)) != 3) || - (ownerPlayer = *GHIDRA_CAST((ownerEntity + 0x410)), ownerPlayer == 0)) goto LAB_00a0dae1; - ownerPlayer = *GHIDRA_CAST((ownerPlayer + 0x140c)); - if ((ownerPlayer == 0) || (!bVar1)) goto LAB_00a0dae1; - fVar11 = *GHIDRA_CAST((ownerPlayer + 0x33c)); - fVar8 = *GHIDRA_CAST((ownerPlayer + 0x340)); - } - if ((fVar11 == g_vectorZero.x) && (fVar8 == g_vectorZero.y)) { - bVar1 = false; - } - else { - bVar1 = true; - } - local_60.x = fVar11; - local_60.y = fVar8; - if (isShooting != 0) { - if (bVar2) { - releaseCharge = *GHIDRA_CAST((GHIDRA_CAST(this) + 0x10)) * 3.0; - } - else if (bVar1) { - pVVar4 = Weapon::get_owner_position(this,&scratchVec); - fVar8 = fVar8 - pVVar4->y; - fVar11 = fVar11 - pVVar4->x; - fVar11 = sqrtf(fVar8 * fVar8 + fVar11 * fVar11); - releaseCharge = *GHIDRA_CAST((GHIDRA_CAST(this) + 0x10)); - fVar11 = (fVar11 - 50.0) / 250.0; - if (fVar11 <= 0.0) { - fVar11 = 0.0; - } - if (1.0 <= fVar11) { - fVar11 = 1.0; - } - releaseCharge = (releaseCharge * 3.0 - releaseCharge) * fVar11 + releaseCharge; - } - } - if ((((ownerEntity != 0) && (*GHIDRA_CAST((ownerEntity + 0x28)) == 1)) && - (0 < *GHIDRA_CAST((ownerEntity + 0x18f8)))) && - (releaseCharge = *GHIDRA_CAST((GHIDRA_CAST(this) + 0x10)), releaseCharge < 1.0)) { - releaseCharge = 1.0; - } - bVar3 = isShooting; - if ((-1000.0 < releaseCharge) && (releaseCharge <= *GHIDRA_CAST((GHIDRA_CAST(this) + 0x14)))) { - bVar3 = 0; - } - aimDirection.x = direction->x; - aimDirection.y = direction->y; - if (isShooting == 0) { - aimDirection.x = *GHIDRA_CAST((GHIDRA_CAST(this) + 0x20)); - aimDirection.y = *GHIDRA_CAST((GHIDRA_CAST(this) + 0x24)); - } - isAxisAligned = Weapon::IsAxisAligned(this); - if (isAxisAligned == 0) { - fVar11 = sqrtf(aimDirection.x * aimDirection.x + aimDirection.y * aimDirection.y); - ownerEntity = extraout_ECX_00; - if (0.0 < fVar11) { - aimDirection.x = (1.0 / fVar11) * aimDirection.x; - aimDirection.y = aimDirection.y * (1.0 / fVar11); - } - } - else { - pVVar4 = Vector::ToCardinal(&scratchVec,&aimDirection); - aimDirection.x = pVVar4->x; - aimDirection.y = pVVar4->y; - ownerEntity = extraout_ECX; - } - fVar9 = 1.0; - fVar11 = *GHIDRA_CAST((GHIDRA_CAST(this) + 0x10)); - fVar8 = *GHIDRA_CAST((GHIDRA_CAST(this) + 0x14)); - if (bVar3 == 0) { - if (fVar11 < 1.0) { - fVar9 = 1.0; - } - else { - fVar9 = fVar11; - } - if ((fVar9 <= fVar8) || ((-1000.0 < releaseCharge && (releaseCharge <= fVar8)))) { - *GHIDRA_CAST((GHIDRA_CAST(this) + 0xc)) = fVar11; - ownerPlayer = 7 - GHIDRA_INT((fVar11 * -0.45)); - ownerEntity = 0xb; - if (0xb < ownerPlayer) { - ownerEntity = ownerPlayer; - } - Weapon::SetBlinkTime(this,ownerEntity,ownerPlayer); - Weapon::TriggerTearEffects(this,&aimDirection,1); - Weapon::get_owner_position(this,&local_60); - fVar8 = aimDirection.x * 10.0; - fVar9 = aimDirection.y * 10.0; - pVVar4 = Weapon::get_tear_movement_inheritance(this,&scratchVec,&aimDirection); - fVar10 = *GHIDRA_CAST((GHIDRA_CAST(this) + 0x10)) + 1.0; - fVar8 = fVar8 + pVVar4->x; - fVar11 = *GHIDRA_CAST((GHIDRA_CAST(this) + 0x14)) + 1.0; - fVar9 = fVar9 + pVVar4->y; - if (fVar10 * 3.0 <= fVar11) { - fVar11 = fVar10 * 3.0; - } - fVar10 = (fVar11 - fVar10) / (fVar10 + fVar10); - fVar11 = fVar10 * 45.0 + 15.0; - Weapon::GetMultiShotParams(this,&local_40,unusedArg); - fVar10 = fVar10 * 0.75 + 0.25; - if ((*GHIDRA_CAST((GHIDRA_CAST(&(uStack_24)) + 0x1))) != '\0') { - local_70.x = -fVar8 * fVar6; - local_70.y = -fVar9 * fVar6; - laser = Weapon::fire_tech_x_laser(this,&local_60,&local_70,fVar11,fVar10); - (**(code **)(*GHIDRA_CAST(laser) + 0xc))(); - } - if ((*GHIDRA_CAST((GHIDRA_CAST(&(uStack_24)) + 0x2))) != '\0') { - local_70.x = fVar8 * fVar6; - local_70.y = fVar6 * -fVar9; - laser = Weapon::fire_tech_x_laser(this,&local_60,&local_70,fVar11,fVar10); - (**(code **)(*GHIDRA_CAST(laser) + 0xc))(); - local_70.x = -fVar8 * fVar6; - local_70.y = fVar9 * fVar6; - laser = Weapon::fire_tech_x_laser(this,&local_60,&local_70,fVar11,fVar10); - (**(code **)(*GHIDRA_CAST(laser) + 0xc))(); - } - for (randomLasersLeft = uStack_20 & 0xffff; randomLasersLeft != 0; - randomLasersLeft = randomLasersLeft - 1) { - rngResult = Random(); - local_70.x = (float)((double)GHIDRA_INT(rngResult) + - __uint_to_double_fixup[-(GHIDRA_INT(rngResult) >> 0x1f)]) * 2.3283064e-10 * 0.5 - + 0.5; - rngResult = Random(); - fVar7 = ((float)((double)GHIDRA_INT(rngResult) + __uint_to_double_fixup[-(GHIDRA_INT(rngResult) >> 0x1f)]) - * 2.3283064e-10 * 50.0 - 25.0) * 0.017453292; - cosAngle = cos(fVar7); - fVar7 = sin(fVar7); - scratchVec.x = (fVar8 * cosAngle - fVar9 * fVar7) * fVar6; - scratchVec.y = (fVar9 * cosAngle + fVar8 * fVar7) * fVar6; - laser = Weapon::fire_tech_x_laser - (this,&local_60,&scratchVec,local_70.x * fVar11,local_70.x * fVar10); - (**(code **)(*GHIDRA_CAST(laser) + 0xc))(); - } - ownerEntity = 0; - if (0 < (short)local_40) { - local_70.x = fVar8; - local_70.y = fVar9; - do { - shotDirection.y = local_70.y; - shotDirection.x = local_70.x; - Entity_Player::GetMultiShotPositionVelocity - (&fStack_50,ownerEntity,9,shotDirection,fVar6,(short)local_40,fStack_3c, - fStack_38,fStack_34,fStack_30,iStack_2c,fStack_28,(uint8_t)uStack_24, - (short)uStack_20); - scratchVec.x = local_60.x + fStack_50; - scratchVec.y = fStack_4c + local_60.y; - laser = Weapon::fire_tech_x_laser(this,&scratchVec,&VStack_48,fVar11,fVar10); - (**(code **)(*GHIDRA_CAST(laser) + 0xc))(); - ownerEntity = ownerEntity + 1; - } while (ownerEntity < (short)local_40); - } - pEVar5 = *GHIDRA_CAST((GHIDRA_CAST(this) + 4)); - if ((((pEVar5 == GHIDRA_CAST(0x0)) || (player = pEVar5, pEVar5->_type != 1)) && - (player = GHIDRA_CAST(0x0), pEVar5 != GHIDRA_CAST(0x0))) && (pEVar5->_type == 3)) - { - pEVar5->_chargeBarSprites[5]._numEvents = 0; - } - else if (player != GHIDRA_CAST(0x0)) { - Entity_Player::stop_costume_item_anims(player); - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x14)) = 0; - goto LAB_00a0e1fe; - } - } - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x14)) = 0; - } - else { - if (fVar11 * 3.0 <= fVar8) { - Weapon::UpdateHeadChargeAnimation(this,0x18b,1,direction,-1.0); - ownerEntity = extraout_ECX_01; - } - else { - if (*GHIDRA_CAST((GHIDRA_CAST(this) + 4)) != 0) { - fVar9 = *GHIDRA_CAST((*GHIDRA_CAST((GHIDRA_CAST(this) + 4)) + 0x39c)); - } - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x14)) = fVar8 + fVar9; - } - Weapon::SetBlinkTime(this,1,ownerEntity); - } -LAB_00a0e1fe: - if (isShooting != 0) { - bVar3 = Weapon::IsAxisAligned(this); - if (bVar3 != 0) { - fVar6 = direction->y; - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x20)) = direction->x; - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x24)) = fVar6; - return; - } - pVVar4 = Weapon::get_aim_direction(this,&local_60,direction); - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x20)) = pVVar4->x; - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x24)) = pVVar4->y; - } - return; -} - -// 00a0e260 -float Weapon_TechX::GetMaxCharge() -{ - return *GHIDRA_CAST((GHIDRA_CAST(this) + 0x10)) * 3.0; -} diff --git a/src/anm2.cpp b/src/anm2.cpp index 2198cc1..859b210 100644 --- a/src/anm2.cpp +++ b/src/anm2.cpp @@ -477,7 +477,8 @@ static std::shared_ptr file_parse(const std::string& path) object document; array list; - if (parser.load(resource_path(path)).get(document) || document["anm2ed"].error()) + std::string redirected = g_manager ? g_manager->modManager.TryRedirectPath(path) : path; + if (parser.load(resource_path(redirected)).get(document) || document["anm2ed"].error()) { log_print(LOG_INFO, "ERROR Could not open %s\n", path.c_str()); return nullptr; diff --git a/src/boss_ai.h b/src/boss_ai.h index 66f1e54..3a1a74f 100644 --- a/src/boss_ai.h +++ b/src/boss_ai.h @@ -4,6 +4,7 @@ #include "game.h" #include "npc_ai.h" #include "room.h" +#include #include constexpr float BOSS_BLOOD_DEPTH = 10; @@ -49,6 +50,26 @@ inline bool room_is_clear() return g_game->room->descriptor->flags & ROOM_DESCRIPTOR_FLAG_CLEAR; } +// The pitch an NPC's cries take for its size: higher for a tiny champion, lower for a giant one. +inline float champion_pitch_get(const Entity_NPC& npc) +{ + if (npc.championColorIdx == CHAMPION_TINY) return 1.5f; + return npc.championColorIdx == CHAMPION_GIANT ? 0.5f : 1; +} + +// Entity::AddVelocity as the AIs inline it: a push scaled by the speed against the friction, none without friction. +inline void npc_push(Entity& entity, Vector push) +{ + if (entity.friction == 0) return; + entity.velocity.x = push.x * entity.speedMultiplier / entity.friction + entity.velocity.x; + entity.velocity.y = push.y * entity.speedMultiplier / entity.friction + entity.velocity.y; +} + +// Mega Satan's boss id, whose room keeps the horsemen low. +constexpr int BOSS_ID_MEGA_SATAN = 55; + +void horseman_mega_satan_hold(Entity_NPC& npc); + // Whether a segment follows its parent's trail, or only adds to its own. enum SegmentMode { @@ -72,15 +93,60 @@ struct Fart }; void game_fart(const Fart& fart); + +// A tracer following its parent (Entity::SpawnFollowingEffect198's arguments): where from it, the direction it +// points, its tint and size, and how long it lasts. +struct FollowingEffect +{ + Vector offset{}; + Vector targetPosition{}; + ColorMod color = COLOR_DEFAULT; + float scale = 1; + int timeout = 0; +}; + +Entity_Effect* following_effect_spawn(Entity& parent, const FollowingEffect& effect); + +std::string npc_sheet_path_get(Entity_NPC& npc, const std::string& path); bool players_is_falling(); +// A hurt dealt around a spot (Game::DamageRadius's arguments): its tear effects, where and from what, its flags and +// damage (players take 2 from one of the threshold or more, else 1), how far it reaches, and whether it hits both +// sides whatever its source. +struct RadiusDamage +{ + TearFlags tearFlags{}; + Vector position{}; + Entity* source = nullptr; + uint64_t damageFlags = 0; + float damage = 0; + float playerDamageThreshold = 0; + float radius = 0; + bool isHitAll = false; +}; + +void damage_radius(const RadiusDamage& hit); + void boss_baby_plum_update(Entity_NPC& npc); void boss_dingle_update(Entity_NPC& npc); void boss_duke_update(Entity_NPC& npc); +void boss_famine_update(Entity_NPC& npc); +void boss_fistula_update(Entity_NPC& npc); +void boss_gate_update(Entity_NPC& npc); void boss_gemini_update(Entity_NPC& npc); +void boss_gurdy_update(Entity_NPC& npc); +void boss_gurdy_jr_update(Entity_NPC& npc); +void boss_haunt_update(Entity_NPC& npc); void boss_larry_jr_update(Entity_NPC& npc); void boss_little_horn_update(Entity_NPC& npc); +void boss_loki_update(Entity_NPC& npc); +void boss_mega_maw_update(Entity_NPC& npc); +void boss_mom_update(Entity_NPC& npc); void boss_monstro_update(Entity_NPC& npc); +void boss_peep_update(Entity_NPC& npc); +void boss_pestilence_update(Entity_NPC& npc); +void boss_polycephalus_update(Entity_NPC& npc); +void boss_widow_update(Entity_NPC& npc); // Gemini's baby, the variant its twin is tied to. constexpr int GEMINI_BABY = 10; diff --git a/src/boss_death.cpp b/src/boss_death.cpp index a451050..d0ad4d8 100644 --- a/src/boss_death.cpp +++ b/src/boss_death.cpp @@ -25,7 +25,6 @@ constexpr int ENTITY_SLOTH = 46; constexpr int ENTITY_ENVY = 51; constexpr int ENTITY_PRIDE = 52; constexpr int ENTITY_FALLEN = 81; -constexpr int ENTITY_POLYCEPHALUS = 269; constexpr int VARIANT_SUPER = 1; constexpr int VARIANT_ULTRA_PRIDE = 2; constexpr int VARIANT_KRAMPUS = 1; diff --git a/src/boss_famine.cpp b/src/boss_famine.cpp new file mode 100644 index 0000000..42b69d3 --- /dev/null +++ b/src/boss_famine.cpp @@ -0,0 +1,226 @@ +#include "boss_ai.h" +#include "npc_caves.h" +#include "sfx_manager.h" +#include + +// Famine's blue subtype, which sprays where the plain one summons, and steers its dash. +constexpr int FAMINE_BLUE = 1; + +// Famine's states: floating about, the dash across the room, the summon, and its head alone once hurt enough. +constexpr int FAMINE_FLOAT = NPC_STATE_MOVE; +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; + +constexpr float FAMINE_SPLAT_SIZE = 0.3f; +constexpr float FAMINE_SPLAT_MIN = 0.3f; +constexpr float FAMINE_HEAD_AIM_TICKS = 7; +constexpr float FAMINE_HEAD_RANGE = 300; +constexpr int FAMINE_HEAD_COOLDOWN = 8; +constexpr int FAMINE_HEAD_BLUE_SHOTS = 10; +constexpr float FAMINE_HEAD_SHOT_SPEED = 10; +constexpr float FAMINE_HEAD_SPEED = 0.5f; + +constexpr uint32_t FAMINE_SUMMON_ODDS = 40; +constexpr int FAMINE_SUMMON_ENEMY_LIMIT = 3; +constexpr float FAMINE_DASH_LINE = 20; +constexpr uint32_t FAMINE_DASH_ODDS = 5; +constexpr uint32_t FAMINE_BLUE_DASH_ODDS = 4; + +constexpr float FAMINE_RING_SPEED = 8; +constexpr float FAMINE_RING_SHOTS = 6; +constexpr int FAMINE_POOTER_LIMIT = 3; +constexpr float FAMINE_SUMMON_VOLUME = 0.8f; +constexpr float FAMINE_POOTER_REACH = 50; + +constexpr float FAMINE_DASH_SPEED = 18; +constexpr float FAMINE_HARD_DASH = 1.25f; +constexpr float FAMINE_STEER_RANGE = 100; +constexpr float FAMINE_STEER_MAX = 0.4f; +constexpr float FAMINE_WRAP_REACH = 200; +constexpr float FAMINE_WRAP_ENTRY = 80; + +// Mega Satan's room holds a horseman below this line. +constexpr float HORSEMAN_MEGA_SATAN_FLOOR = 320; +constexpr float HORSEMAN_MEGA_SATAN_PULL = 0.5f; + +// Hurt below a third of its health, it loses its horse in a blood explosion and goes on as a head. +static void famine_head_start(Entity_NPC& npc) +{ + npc.state = FAMINE_HEAD; + g_game->Spawn({.position = npc.pos, + .spawner = &npc, + .type = ENTITY_EFFECT, + .variant = EFFECT_BLOOD_EXPLOSION, + .seed = Random()}); + npc.BloodExplode(); + npc.sprite.Play("HeadWalk"); + npc.sprite.PlayOverlay("Blood"); + npc.sprite.isOverlayRenderFirst = true; +} + +// The head bleeds, chases its target, and stops to shoot it when in range every seventh tick: a three-way shot, or a +// burst of ten for the blue one. +static void famine_head(Entity_NPC& npc, Vector toTarget) +{ + npc.pos = g_game->room->GetClampedPositionImpl(npc.pos, npc.size, npc.size, npc.size, npc.size); + npc.entityGridCollisionClass = GRIDCOLL_WALLS; + if (npc.sprite.overlayAnimState.IsEventTriggered("Shoot")) + npc.MakeSplat(random_unit() * FAMINE_SPLAT_SIZE + FAMINE_SPLAT_MIN); + + if (npc.GetIntervalTicks(FAMINE_HEAD_AIM_TICKS, (float)npc.index)) + { + if (npc.projectileCooldown >= 1) npc.projectileCooldown--; + else if (npc.IsTargetInAttackRange(FAMINE_HEAD_RANGE, 0, false)) + { + npc.projectileCooldown = FAMINE_HEAD_COOLDOWN; + npc_anim_restart(npc.sprite, "HeadAttack"); + } + } + + if (npc.sprite.animState.animData && npc.sprite.IsEventTriggered("Shoot")) + { + npc.PlaySound(SOUND_MONSTER_GRUNT_0, 1, 2, false, 1); + Vector target = npc.GetPlayerTarget()->pos; + if (npc.subtype == FAMINE_BLUE) npc.FireBossProjectiles(FAMINE_HEAD_BLUE_SHOTS, target, 0, ProjectileParams()); + else + npc.FireProjectiles(npc.pos, vector_resized(vector_sub(target, npc.pos), FAMINE_HEAD_SHOT_SPEED), + PROJECTILES_THREE, ProjectileParams()); + } + if (npc_anim_is_done(npc)) npc.sprite.Play("HeadWalk"); + + if (npc.projectileCooldown < 1) npc_push(npc, vector_scale(vector_normalized(toTarget), FAMINE_HEAD_SPEED)); +} + +// It floats about at random, and now and then summons while few enemies are left, or dashes across at a target in +// line with it (more often for the blue one). +static void famine_float(Entity_NPC& npc, Vector toTarget) +{ + npc.pathfinder.MoveRandomlyBoss(STATUS_OBEYED); + npc.AnimWalkFrame("FullFloat", "FullFloat", 1); + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM) && room_is_clear()) return; + + if (Random() % FAMINE_SUMMON_ODDS == 0 && g_game->room->GetAliveEnemiesCount() < FAMINE_SUMMON_ENEMY_LIMIT) + { + npc.state = FAMINE_SUMMON; + npc_anim_restart(npc.sprite, "Attack1"); + npc.stateFrame = 0; + return; + } + + 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; + + npc.PlaySound(SOUND_MONSTER_YELL_A, 1, 2, false, 1); + npc.sprite.isFlipX = toTarget.x < 0; + npc_anim_restart(npc.sprite, "AttackDashStart"); + npc.targetPosition = npc.pos; + npc.state = FAMINE_DASH; + npc.stateFrame = 0; +} + +// The summon: a Pooter a little way off (at most three for a Delirium form), or a ring of six shots for the blue +// one. Back to floating once it ends. +static void famine_summon(Entity_NPC& npc) +{ + if (npc.sprite.animState.animData && npc.sprite.IsEventTriggered("Shoot")) + { + npc.PlaySound(SOUND_MONSTER_GRUNT_5, 1, 2, false, 1); + Vector ring = vector_make(FAMINE_RING_SPEED, FAMINE_RING_SHOTS); + if (npc.subtype == FAMINE_BLUE) return npc.FireProjectiles(npc.pos, ring, PROJECTILES_RING, ProjectileParams()); + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM) && + npc.CountRelatedEntities(ENTITY_POOTER, 0, nullptr) >= FAMINE_POOTER_LIMIT) + return; + + npc.PlaySound(SOUND_SUMMONSOUND, FAMINE_SUMMON_VOLUME, 2, false, 1); + uint32_t seed = Random(); + Vector spot = vector_add(vector_scale(random_direction(), FAMINE_POOTER_REACH), npc.pos); + g_game->Spawn({.position = spot, .spawner = &npc, .type = ENTITY_POOTER, .seed = seed}); + return; + } + if (!npc_anim_is_done(npc)) return; + npc.state = FAMINE_FLOAT; +} + +// The dash: straight across the room once the start's Shoot passes (faster in hard mode, steered at the target's line +// by the blue one), wrapping round the far wall, until it passes where it set off. +static void famine_dash(Entity_NPC& npc, Vector toTarget) +{ + npc.entityGridCollisionClass = GRIDCOLL_WALLS_Y; + if (npc_anim_is_done(npc)) npc.sprite.Play("AttackDash"); + + if (npc.sprite.IsPlaying("AttackDash") || + (npc.sprite.IsPlaying("AttackDashStart") && npc.sprite.WasEventTriggered("Shoot"))) + { + float speed = npc.sprite.isFlipX ? -FAMINE_DASH_SPEED : FAMINE_DASH_SPEED; + npc.velocity.x = game_is_hard_mode() ? speed * FAMINE_HARD_DASH : speed; + if (npc.subtype == FAMINE_BLUE) + { + float steer = std::clamp(-toTarget.y / FAMINE_STEER_RANGE, -FAMINE_STEER_MAX, FAMINE_STEER_MAX); + npc.velocity.y -= npc.speedMultiplier * steer / npc.friction; + } + } + + Room& room = *g_game->room; + float vx = npc.velocity.x; + if (vx > 0 && npc.pos.x > room.bottomRightPos.x + FAMINE_WRAP_REACH) + { + npc.stateFrame++; + npc.pos.x = room.topLeftPos.x - FAMINE_WRAP_ENTRY; + } + else if (vx < 0 && npc.pos.x < room.topLeftPos.x - FAMINE_WRAP_REACH) + { + npc.stateFrame++; + npc.pos.x = room.bottomRightPos.x + FAMINE_WRAP_ENTRY; + } + if (npc.stateFrame < 1) return; + if ((vx < 0 && npc.targetPosition.x > npc.pos.x) || (vx > 0 && npc.pos.x > npc.targetPosition.x)) + npc.state = FAMINE_FLOAT; +} + +// 00456c40 NpcAI::ENTITY_FAMINE: Famine floats about, dashes across the room, and summons Pooters. Below a third of +// its health its head carries on alone, chasing and shooting. +void boss_famine_update(Entity_NPC& npc) +{ + npc.entityGridCollisionClass = GRIDCOLL_WALLS; + npc.pos.y = std::max(FAMINE_CEILING, npc.pos.y); + if (npc.state == NPC_STATE_INIT) + { + npc.state = FAMINE_FLOAT; + return; + } + + npc.friction *= FAMINE_FRICTION; + Vector toTarget = vector_sub(npc.GetPlayerTarget()->pos, npc.pos); + if (npc.health / npc.maxHitPoints < FAMINE_HEAD_HEALTH && npc.state != FAMINE_HEAD) famine_head_start(npc); + + switch (npc.state) + { + case FAMINE_HEAD: + famine_head(npc, toTarget); + break; + case FAMINE_FLOAT: + famine_float(npc, toTarget); + break; + case FAMINE_SUMMON: + famine_summon(npc); + break; + case FAMINE_DASH: + famine_dash(npc, toTarget); + break; + } + horseman_mega_satan_hold(npc); +} + +// Keeps a horseman in Mega Satan's room below his platform, easing it down. +void horseman_mega_satan_hold(Entity_NPC& npc) +{ + if (g_game->room->bossId != BOSS_ID_MEGA_SATAN || npc.pos.y >= HORSEMAN_MEGA_SATAN_FLOOR) return; + npc.velocity.y += (HORSEMAN_MEGA_SATAN_FLOOR - npc.pos.y - npc.velocity.y) * HORSEMAN_MEGA_SATAN_PULL; +} diff --git a/src/boss_fistula.cpp b/src/boss_fistula.cpp new file mode 100644 index 0000000..b5e871b --- /dev/null +++ b/src/boss_fistula.cpp @@ -0,0 +1,234 @@ +#include "boss_ai.h" +#include "grid_entity.h" +#include "npc_caves.h" +#include "room_grid.h" +#include "sfx_manager.h" +#include + +// Fistula (variant 0) and Teratoma (variant 1), and their grey subtype that splits into one more piece. +constexpr int TERATOMA = 1; +constexpr int FISTULA_GREY = 1; + +constexpr ColorMod TERATOMA_SPLAT_COLOR = {{0.15f, 0, 0, 1}, {0, 0, 0, 0}, {0.13f, 0.13f, 0.13f}}; +constexpr float FISTULA_FRICTION = 0.9f; +constexpr float FISTULA_BIG_SPEED = 0.2f; +constexpr float FISTULA_MEDIUM_SPEED = 0.38f; +constexpr float FISTULA_SMALL_SPEED = 0.56f; +constexpr int FISTULA_GROWL_WAIT = 120; +constexpr uint32_t FISTULA_GROWL_ODDS = 200; +constexpr int FISTULA_GROWL_DELAY = 60; +constexpr int FISTULA_BOUNCE_DELAY = 20; +constexpr float FISTULA_FLEE_REACH = 80; +constexpr float FISTULA_FLEE_STRENGTH = 0.02f; +constexpr float FISTULA_FLEE_MAX = 0.5f; + +constexpr float FISTULA_SPLIT_REACH = 20; +constexpr float FISTULA_SPLIT_SPEED = 0.2f; +constexpr float FISTULA_DELIRIUM_PIECE_HEALTH = 15; +constexpr float FISTULA_SUMMON_VOLUME = 0.8f; +constexpr float FISTULA_MAGGOT_HEALTH = 0.75f; +constexpr float FISTULA_DELIRIUM_FLY_HEALTH = 10; + +// A grid path value the smallest Fistula leaves nothing over, and the path Teratoma's spiders claim under them. +constexpr int FISTULA_NO_SPAWN_PATH = 3000; +constexpr int TERATOMA_SPIDER_PATH_LIMIT = 951; +constexpr int TERATOMA_SPIDERS = 2; +constexpr float TERATOMA_SPIDER_NEAR_REACH = 70; +constexpr float TERATOMA_SPIDER_FAR_REACH = 100; +constexpr float TERATOMA_SPIDER_LIFT = 10; +constexpr float TERATOMA_SPIDER_JUMP = -8; +constexpr float TERATOMA_SPIDER_SPEED = 0.04f; +constexpr float ROOM_GRID_ORIGIN_X = 40; +constexpr float ROOM_GRID_ORIGIN_Y = 120; +constexpr float ROOM_GRID_CELL = 40; + +// The growl one of the room's Fistulas lets out now and then, picked among their sizes. +static void fistula_growl(Entity_NPC& npc) +{ + if (++npc.i1 <= FISTULA_GROWL_WAIT || Random() % FISTULA_GROWL_ODDS != 0) return; + npc.i1 = 0; + + std::vector growls; + for (Entity* entity : g_game->room->entityList.updateEL) + { + if (entity->type == ENTITY_FISTULA_BIG) growls.push_back(SOUND_FISTULA_GROWL_LARGE); + else if (entity->type == ENTITY_FISTULA_MEDIUM) growls.push_back(SOUND_FISTULA_GROWL_MEDIUM); + else if (entity->type == ENTITY_FISTULA_SMALL) growls.push_back(SOUND_FISTULA_GROWL_SMALL); + } + if (growls.empty()) return; + npc.PlaySound(growls[Random() % growls.size()], 1, FISTULA_GROWL_DELAY, false, 1); +} + +// The bounce off a wall, by size. The big Fistula has its own, the others share Teratoma's. +static void fistula_bounce_sound(Entity_NPC& npc) +{ + if (npc.variant > TERATOMA) return; + int sound = npc.variant == TERATOMA ? SOUND_TERATOMA_BOUNCE_BIG : SOUND_FISTULA_BOUNCE_LARGE; + if (npc.type == ENTITY_FISTULA_MEDIUM) sound = SOUND_TERATOMA_BOUNCE_MEDIUM; + else if (npc.type == ENTITY_FISTULA_SMALL) sound = SOUND_TERATOMA_BOUNCE_SMALL; + else if (npc.type != ENTITY_FISTULA_BIG) return; + npc.PlaySound(sound, 1, FISTULA_BOUNCE_DELAY, false, 1); +} + +// It keeps bouncing on its diagonal, faster the smaller it is, and backs off its target while feared or shrunk. +// Confused, it wanders. +static void fistula_move(Entity_NPC& npc, float speed) +{ + if (npc.HasEntityFlags(FLAG_CONFUSION)) return (void)npc.pathfinder.MoveRandomly(STATUS_OBEYED); + + float push = speed * npc.speedMultiplier / npc.friction; + npc.velocity.x = npc.velocity.x <= 0 ? npc.velocity.x - push : push + npc.velocity.x; + npc.velocity.y = npc.velocity.y <= 0 ? npc.velocity.y - push : push + npc.velocity.y; + if (!npc.HasEntityFlags(FLAG_FEAR | FLAG_SHRINK)) return; + + Vector away = vector_sub(npc.pos, npc.GetPlayerTarget()->pos); + float distance = vector_length(away); + if (distance > 0) + { + float strength = std::max(0.0f, (npc.size + FISTULA_FLEE_REACH - distance) * FISTULA_FLEE_STRENGTH); + if (FISTULA_FLEE_MAX <= strength) strength = FISTULA_FLEE_MAX; + away = vector_scale(away, strength / distance); + } + if (npc.friction == 0) return; + npc.velocity.y = npc.speedMultiplier * away.y / npc.friction + npc.velocity.y; + npc.velocity.x = npc.speedMultiplier * away.x / npc.friction + npc.velocity.x; +} + +// A smaller piece it splits into, awake at once, keeping its boss health out of the bar, and sturdier for a +// Delirium form. +static void fistula_piece_spawn(Entity_NPC& npc, int type, const Vector& position, const Vector& velocity) +{ + uint32_t seed = Random(); + Entity* piece = g_game->Spawn({.position = position, + .velocity = velocity, + .spawner = &npc, + .subType = npc.subtype, + .type = type, + .variant = npc.variant, + .seed = seed}); + piece->ClearEntityFlags(FLAG_APPEAR); + if (npc.HasEntityFlags(FLAG_DONT_COUNT_BOSS_HP)) piece->AddEntityFlags(FLAG_DONT_COUNT_BOSS_HP); + if (!npc.HasEntityFlags(FLAG_DELIRIUM_FORM)) return; + piece->maxHitPoints = FISTULA_DELIRIUM_PIECE_HEALTH; + piece->health = FISTULA_DELIRIUM_PIECE_HEALTH; +} + +// Teratoma's smallest pieces burst into two spiders leaping out to free spots, the first between it and its target. +static void teratoma_spiders(Entity_NPC& npc) +{ + if (room_grid_collision_at(npc.pos) != 0) return; + Room& room = *g_game->room; + for (int i = 0; i < TERATOMA_SPIDERS; i++) + { + FreeSpotSearch search = {.position = npc.pos, .step = TERATOMA_SPIDER_FAR_REACH}; + if (i == 0) + { + Entity* target = npc.GetPlayerTarget(); + Vector between = vector_scale(vector_add(target->pos, npc.pos), 0.5f); + search = {.position = between, .step = TERATOMA_SPIDER_NEAR_REACH}; + } + Vector spot = room_free_pickup_position_find(search); + auto* spider = static_cast( + g_game->Spawn({.position = spot, .spawner = &npc, .type = ENTITY_SPIDER, .seed = Random()})); + + int column = (int)((spot.x - ROOM_GRID_ORIGIN_X) / ROOM_GRID_CELL + 0.5f); + int row = (int)((spot.y - ROOM_GRID_ORIGIN_Y) / ROOM_GRID_CELL + 0.5f); + int cell = room.gridWidth * row + column; + if (column >= 0 && column < room.gridWidth && row >= 0 && row < room.gridHeight && cell < ROOM_GRID_CELLS && + room.gridPaths[cell] < TERATOMA_SPIDER_PATH_LIMIT) + room.gridPaths[cell] = GRID_PATH_FREED; + + spider->targetPosition = spider->pos; + spider->pos = npc.pos; + spider->ClearEntityFlags(FLAG_APPEAR); + spider->state = NPC_STATE_JUMP; + spider->v2.y = TERATOMA_SPIDER_JUMP; + spider->posOffset.y -= TERATOMA_SPIDER_LIFT; + Vector leap = vector_scale(vector_sub(spider->targetPosition, npc.pos), TERATOMA_SPIDER_SPEED); + spider->velocity = leap; + spider->v1 = leap; + } +} + +// The smallest Fistula bursts into a Charger (a Boom Fly for the grey one), weakened, unless it sits on a pit. +static void fistula_maggot(Entity_NPC& npc) +{ + bool isGrey = npc.subtype == FISTULA_GREY; + if (!isGrey && room_grid_collision_at(npc.pos) != 0) return; + Entity* maggot = g_game->Spawn( + {.position = npc.pos, .spawner = &npc, .type = isGrey ? ENTITY_BOOMFLY : ENTITY_CHARGER, .seed = Random()}); + maggot->health *= FISTULA_MAGGOT_HEALTH; + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM) && isGrey) + { + maggot->health = FISTULA_DELIRIUM_FLY_HEALTH; + maggot->maxHitPoints = FISTULA_DELIRIUM_FLY_HEALTH; + } + maggot->ClearEntityFlags(FLAG_APPEAR); +} + +// Its death splits it: the big one into two or three medium pieces (four for the plain one), a medium one into two +// small ones, and a small one into its maggot or Teratoma's spiders. +static void fistula_split(Entity_NPC& npc) +{ + float angle = random_unit() * RANDOM_HALF_TURN; + angle += angle; + float c = std::cos(angle) * FISTULA_SPLIT_REACH; + float s = std::sin(angle) * FISTULA_SPLIT_REACH; + Vector spread = vector_make(c * FISTULA_SPLIT_SPEED, s * FISTULA_SPLIT_SPEED); + Vector back = vector_make(c * -FISTULA_SPLIT_SPEED, s * -FISTULA_SPLIT_SPEED); + + if (npc.type == ENTITY_FISTULA_MEDIUM) + { + fistula_piece_spawn(npc, ENTITY_FISTULA_SMALL, vector_make(c + npc.pos.x, s + npc.pos.y), spread); + fistula_piece_spawn(npc, ENTITY_FISTULA_SMALL, vector_make(npc.pos.x - c, npc.pos.y - s), back); + return; + } + if (npc.type != ENTITY_FISTULA_BIG) + { + npc.PlaySound(SOUND_SUMMONSOUND, FISTULA_SUMMON_VOLUME, 2, false, 1); + npc.pathfinder.UpdateGridIndex(); + int cell = npc.pathfinder.gridIndex; + int path = (uint32_t)cell < ROOM_GRID_CELLS ? g_game->room->gridPaths[cell] : 0; + if (npc.variant != TERATOMA && path == FISTULA_NO_SPAWN_PATH) return; + return npc.variant == TERATOMA ? teratoma_spiders(npc) : fistula_maggot(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), {}); + else + { + fistula_piece_spawn(npc, ENTITY_FISTULA_MEDIUM, vector_make(c + npc.pos.x, npc.pos.y - s), + vector_make(spread.x, back.y)); + fistula_piece_spawn(npc, ENTITY_FISTULA_MEDIUM, vector_make(npc.pos.x - c, s + npc.pos.y), + vector_make(back.x, spread.y)); + } + if (npc.variant == 0) npc.PlaySound(SOUND_FISTULA_BURST_LARGE, 1, FISTULA_BOUNCE_DELAY, false, 1); +} + +// 00466600 NpcAI::ENTITY_FISTULA_BIG: Fistula and Teratoma bounce about the room in three sizes, splitting into +// smaller pieces when they die, the smallest into a maggot or spiders. +void boss_fistula_update(Entity_NPC& npc) +{ + if (npc.state == NPC_STATE_INIT) + { + npc.state = NPC_STATE_MOVE; + npc.entityGridCollisionClass = GRIDCOLL_WALLS; + if (npc.variant == TERATOMA) npc.splatColor = TERATOMA_SPLAT_COLOR; + return; + } + + float friction = npc.friction; + if (npc.subtype == FISTULA_GREY) friction *= FISTULA_FRICTION; + float speed = FISTULA_BIG_SPEED; + if (npc.type == ENTITY_FISTULA_MEDIUM) speed = FISTULA_MEDIUM_SPEED; + else if (npc.type == ENTITY_FISTULA_SMALL) speed = FISTULA_SMALL_SPEED; + npc.friction = friction * FISTULA_FRICTION; + + if (npc.variant == 0) fistula_growl(npc); + if (npc.isCollidesWithGrid) fistula_bounce_sound(npc); + fistula_move(npc, speed); + if (npc.type != ENTITY_FISTULA_SMALL) npc.sprite.GetLayer(0)->rotation += 1; + if (npc.isDead && !npc.HasEntityFlags(FLAG_NO_SPLIT)) fistula_split(npc); +} diff --git a/src/boss_gate.cpp b/src/boss_gate.cpp new file mode 100644 index 0000000..5fb57d1 --- /dev/null +++ b/src/boss_gate.cpp @@ -0,0 +1,343 @@ +#include "boss_ai.h" +#include "entity_laser.h" +#include "npc_caves.h" +#include "room_grid.h" +#include "sfx_manager.h" +#include + +// The Gate's subtypes: the red one that fires patterns of shots, and the black one that throws big spiders. +constexpr int GATE_RED = 1; +constexpr int GATE_BLACK = 2; + +// The Gate's states: idle, the laser, the ring of shots, and the Leaper summon. +constexpr int GATE_LASER = NPC_STATE_ATTACK; +constexpr int GATE_RING = NPC_STATE_ATTACK2; +constexpr int GATE_SUMMON = NPC_STATE_SUMMON; + +// The attacks' phases (i1): charging, then shooting. +enum GateCharge +{ + GATE_CHARGING, + GATE_SHOOTING +}; + +// The red one's patterns (i2): triangles, curving shots, waving shots and homing shots. +enum GatePattern +{ + GATE_PATTERN_TRIANGLE, + GATE_PATTERN_CURVE, + GATE_PATTERN_WAVE, + 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; +constexpr int GATE_PERIOD = 20; +constexpr int GATE_HURT_PERIOD = 10; +constexpr int GATE_SUMMON_ENEMY_LIMIT = 5; +constexpr int GATE_DELIRIUM_LIMIT = 3; +constexpr int GATE_LASER_CROWD = 2; +constexpr int GATE_LASER_ODDS = 12; +constexpr float GATE_FULL_TURN = 360; +constexpr int GATE_RED_REST = 30; + +constexpr int GATE_SOUND_DELAY = 60; +constexpr float GATE_LASER_ANGLE = 90; +constexpr int GATE_LASER_TIMEOUT = 10; +constexpr float GATE_LASER_HEIGHT = -30; +constexpr float GATE_LASER_DEPTH = 100; +constexpr uint32_t GATE_LASER_HOMING_FREEZE = 1; + +constexpr float GATE_FIRE_HEIGHT = 18.5f; +constexpr float GATE_FIRE_ACCEL = -0.06f; +constexpr float GATE_FIRE_FALL = -2; +constexpr float GATE_FIRE_SPEEDUP = 1.05f; +constexpr float GATE_FIRE_SCALE = 1.8f; +constexpr float GATE_RING_SPEED = 10; +constexpr float GATE_RING_SHOTS = 9; +constexpr float GATE_RING_WIDE_SHOTS = 11; +constexpr float GATE_RING_PAIR_SHOTS = 6; +constexpr float GATE_RING_INNER_SPEED = 7; + +constexpr float GATE_PATTERN_SCALE = 1.75f; +constexpr int GATE_PATTERN_TICKS = 3; +constexpr int GATE_HOMING_TICKS = 10; +constexpr float GATE_PATTERN_SHOTS = 8; +constexpr float GATE_CURVE_ACCEL = -0.05f; +constexpr float GATE_WAVE_RATE = 0.15f; +constexpr float GATE_WAVE_SWING = 0.2f; +constexpr float GATE_WAVE_SPEED = 5; +constexpr float GATE_WAVE_SHOTS = 7; +constexpr float GATE_HOMING_SPEED = 5; +constexpr float GATE_HOMING_SHOTS = 5; +constexpr float GATE_HOMING_STRENGTH = 0.3f; +constexpr float GATE_HOMING_TURN = 1.5f; + +constexpr float GATE_SPIDER_DROP = 0.5f; +constexpr float GATE_SPIDER_HEIGHT = -100; +constexpr float GATE_LEAPER_HEIGHT = -60; +constexpr float GATE_LEAPER_REACH = 150; +constexpr int GATE_LEAPER_FRAME = 5; +constexpr int GATE_LEAPER_DEPTH = 100000; +constexpr float GATE_LEAPER_DELIRIUM_HEALTH = 10; + +// The chance of a summon on its beat, halving with each enemy past one, and none from six. +static float gate_summon_chance(int enemies) +{ + switch (enemies) + { + case 2: + return 0.5f; + case 3: + return 0.25f; + case 4: + return 0.125f; + case 5: + return 0.0625f; + case 6: + return 0; + default: + return 1; + } +} + +// Idle: on its beat (faster once hurt) a summon while few enemies are about, a laser more likely the more enemies +// there are (never for the black one), or a ring one time in two. The red one instead fires a new pattern once its +// rest runs out. +static void gate_idle(Entity_NPC& npc) +{ + npc.sprite.Play("Idle"); + bool isDelirium = npc.HasEntityFlags(FLAG_DELIRIUM_FORM); + if (isDelirium && room_is_clear()) return; + + int period = npc.health / npc.maxHitPoints < GATE_HURT_HEALTH ? GATE_HURT_PERIOD : GATE_PERIOD; + int enemies = g_game->room->GetAliveEnemiesCount(); + float chance = gate_summon_chance(enemies); + bool isSummon = enemies < GATE_SUMMON_ENEMY_LIMIT; + if (isDelirium && npc.subtype == GATE_BLACK) + isSummon = npc.CountRelatedEntities(ENTITY_STRIDER, 0, nullptr) + + npc.CountRelatedEntities(ENTITY_BIG_SPIDER, 0, nullptr) + + npc.CountRelatedEntities(ENTITY_SPIDER, 0, nullptr) < + GATE_DELIRIUM_LIMIT; + else if (isDelirium) isSummon = npc.CountRelatedEntities(ENTITY_LEAPER, 0, nullptr) < GATE_DELIRIUM_LIMIT; + + if (isSummon && npc.IsFrame(period, 0) && random_unit() < chance) + { + npc.state = GATE_SUMMON; + 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)) + { + npc.state = GATE_LASER; + npc.i1 = GATE_CHARGING; + } + else if (npc.IsFrame(period, 0) && (Random() & 1) == 0) + { + npc.state = GATE_RING; + npc.i1 = GATE_CHARGING; + } + if (npc.subtype != GATE_RED) return; + + npc.state = GATE_RING; + npc.i1 = GATE_CHARGING; + npc.i2 = (int)(Random() & 3); + npc.v1.x = random_unit() * GATE_FULL_TURN - GATE_FULL_TURN / 2; + npc.v1.y = (Random() & 1) ? 1.0f : -1.0f; + if (npc.stateFrame-- > 0) npc.state = NPC_STATE_IDLE; +} + +// The charge before an attack, its sound looping, then the shooting. +static void gate_charge(Entity_NPC& npc, SoundId sound) +{ + npc.sprite.Play("Charging"); + npc.PlaySound(sound, 1, GATE_SOUND_DELAY, false, 1); + if (npc_anim_is_done(npc)) npc.i1 = GATE_SHOOTING; +} + +// The laser: a freezing beam straight down from its mouth. +static void gate_laser(Entity_NPC& npc) +{ + if (npc.i1 == GATE_CHARGING) return gate_charge(npc, SOUND_MOUTH_FULL); + if (npc.i1 != GATE_SHOOTING) return; + + npc.sprite.Play("Shooting"); + if (npc.sprite.IsEventTriggered("Shoot")) + { + npc.PlaySound(SOUND_GHOST_ROAR, 1, 2, false, 1); + Entity_Laser* laser = Entity_Laser::ShootAngle({.position = npc.pos, + .posOffset = vector_make(0, GATE_LASER_HEIGHT), + .source = &npc, + .angleDegrees = GATE_LASER_ANGLE, + .timeout = GATE_LASER_TIMEOUT, + .variant = LASER_THICK_RED}); + laser->renderDepthOffset = GATE_LASER_DEPTH; + laser->homingType = GATE_LASER_HOMING_FREEZE; + laser->Update(); + } + if (npc_anim_is_done(npc)) npc.state = NPC_STATE_IDLE; +} + +// The fire ring: big shots rising and orbiting it one way, the other, or both in two rings, or a wider ring. +static void gate_fire_ring(Entity_NPC& npc) +{ + npc.PlaySound(SOUND_FIRE_RUSH, 1, 2, false, 1); + ProjectileParams params; + params.targetPosition = npc.pos; + params.bulletFlags |= PROJECTILE_HIT_ENEMIES | PROJECTILE_NO_WALL_COLLIDE; + params.heightModifier = GATE_FIRE_HEIGHT; + params.fallingAccelModifier = GATE_FIRE_ACCEL; + params.fallingSpeedModifier = GATE_FIRE_FALL; + params.isGridCollision = false; + params.velocityMulti = GATE_FIRE_SPEEDUP; + params.scale = GATE_FIRE_SCALE; + + Vector ring = vector_make(GATE_RING_SPEED, GATE_RING_SHOTS); + switch (Random() & 3) + { + case 0: + params.bulletFlags |= PROJECTILE_ORBIT_CW; + break; + case 1: + params.bulletFlags |= PROJECTILE_ORBIT_CCW; + break; + case 2: + params.bulletFlags |= PROJECTILE_ORBIT_CW; + npc.FireProjectiles(npc.pos, vector_make(GATE_RING_SPEED, GATE_RING_PAIR_SHOTS), PROJECTILES_RING, params); + params.bulletFlags |= PROJECTILE_ORBIT_CCW; + ring = vector_make(GATE_RING_INNER_SPEED, GATE_RING_PAIR_SHOTS); + break; + case 3: + ring.y = GATE_RING_WIDE_SHOTS; + break; + } + npc.FireProjectiles(npc.pos, ring, PROJECTILES_RING, params); +} + +// The red one's pattern, a ring every few ticks after Shoot: triangles, shots curving its spin's way, waving shots, or +// slow homing shots turning with time. +static void gate_pattern(Entity_NPC& npc) +{ + if (!npc.sprite.WasEventTriggered("Shoot")) return; + ProjectileParams params; + params.targetPosition = npc.pos; + params.heightModifier = GATE_FIRE_HEIGHT; + params.fallingAccelModifier = GATE_FIRE_ACCEL; + params.fallingSpeedModifier = GATE_FIRE_FALL; + params.scale = GATE_PATTERN_SCALE; + + Vector ring = vector_make(GATE_RING_SPEED, GATE_PATTERN_SHOTS); + float age = (float)(g_game->frameCount - npc.spawnFrame); + switch (npc.i2) + { + case GATE_PATTERN_TRIANGLE: + if (!npc.IsFrame(GATE_PATTERN_TICKS, npc.index)) return; + params.circleAngle = npc.v1.x; + params.bulletFlags = PROJECTILE_TRIANGLE; + break; + case GATE_PATTERN_CURVE: + if (!npc.IsFrame(GATE_PATTERN_TICKS, npc.index)) return; + params.circleAngle = npc.v1.x; + params.fallingAccelModifier = GATE_CURVE_ACCEL; + params.bulletFlags |= (npc.v1.y >= 0 ? PROJECTILE_CURVE_RIGHT : PROJECTILE_CURVE_LEFT) | + PROJECTILE_NO_WALL_COLLIDE; + break; + case GATE_PATTERN_WAVE: + if (!npc.IsFrame(GATE_PATTERN_TICKS, npc.index)) return; + params.bulletFlags |= PROJECTILE_CURVE_LEFT | PROJECTILE_SINE_VELOCITY; + params.circleAngle = std::sin(age * GATE_WAVE_RATE) * GATE_WAVE_SWING + npc.v1.x; + ring = vector_make(GATE_WAVE_SPEED, GATE_WAVE_SHOTS); + break; + case GATE_PATTERN_HOMING: + if (!npc.IsFrame(GATE_HOMING_TICKS, npc.index)) return; + ring = vector_make(GATE_HOMING_SPEED, GATE_HOMING_SHOTS); + params.bulletFlags |= PROJECTILE_SMART; + params.homingStrength = GATE_HOMING_STRENGTH; + params.circleAngle = age * GATE_HOMING_TURN + npc.v1.x; + break; + default: + return; + } + npc.FireProjectiles(npc.pos, ring, PROJECTILES_RING, params); +} + +// The ring: charged, then a fire ring on Shoot, or the red one's pattern. The red one rests a while after. +static void gate_ring(Entity_NPC& npc) +{ + if (npc.i1 == GATE_CHARGING) return gate_charge(npc, SOUND_LOW_INHALE); + if (npc.i1 != GATE_SHOOTING) return; + + npc.sprite.Play("Shooting"); + if (npc.subtype == GATE_RED) gate_pattern(npc); + else if (npc.sprite.IsEventTriggered("Shoot")) gate_fire_ring(npc); + if (!npc_anim_is_done(npc)) return; + npc.state = NPC_STATE_IDLE; + npc.stateFrame = GATE_RED_REST; +} + +// The summon: a Leaper leaping out over it to land nearby, or a big spider thrown at its target by the black one. +static void gate_summon(Entity_NPC& npc) +{ + npc.sprite.Play("Spawn"); + npc.PlaySound(SOUND_MONSTER_GRUNT_4, 1, GATE_SOUND_DELAY, false, 1); + if (npc.sprite.IsEventTriggered("Shoot")) + { + npc.PlaySound(SOUND_MONSTER_GRUNT_5, 1, 2, false, 1); + if (npc.subtype == GATE_BLACK) + { + Entity* target = npc.GetPlayerTarget(); + Vector mouth = vector_make(npc.pos.x, npc.pos.y + GATE_SPIDER_DROP); + Entity_NPC::ThrowSpider(mouth, &npc, target->pos, true, GATE_SPIDER_HEIGHT); + } + else + { + Vector mouth = vector_make(npc.pos.x, npc.pos.y + GATE_LEAPER_HEIGHT); + auto* leaper = static_cast( + g_game->Spawn({.position = mouth, .spawner = &npc, .type = ENTITY_LEAPER, .seed = Random()})); + leaper->targetPosition = room_free_pickup_position_find({.position = npc.pos, .step = GATE_LEAPER_REACH}); + leaper->state = NPC_STATE_JUMP; + leaper->stateFrame = GATE_LEAPER_FRAME; + npc_anim_restart(leaper->sprite, "BigJumpUp"); + if (leaper->sprite.animState.animData) leaper->sprite.animState.SetFrameFloat(GATE_LEAPER_FRAME); + leaper->renderZOffset = GATE_LEAPER_DEPTH; + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM)) + { + leaper->health = GATE_LEAPER_DELIRIUM_HEALTH; + leaper->maxHitPoints = GATE_LEAPER_DELIRIUM_HEALTH; + } + } + } + if (!npc_anim_is_done(npc)) return; + npc.state = NPC_STATE_IDLE; + npc.i1 = 0; +} + +// 0045fc00 NpcAI::ENTITY_GATE: the Gate hangs fixed on the wall, summons Leapers, fires a freezing laser down and +// rings of rising fire. The red one fires patterns of shots, and the black one throws big spiders. +void boss_gate_update(Entity_NPC& npc) +{ + if (npc.state == NPC_STATE_INIT) + { + npc.state = NPC_STATE_IDLE; + npc.stateFrame = 0; + if (npc.deliriumBossType == 0) npc.pos.y -= GATE_LIFT; + npc.targetPosition = npc.pos; + return; + } + + npc.friction *= GATE_FRICTION; + npc.velocity = vector_sub(npc.targetPosition, npc.pos); + switch (npc.state) + { + case NPC_STATE_IDLE: + return gate_idle(npc); + case GATE_LASER: + return gate_laser(npc); + case GATE_RING: + return gate_ring(npc); + case GATE_SUMMON: + return gate_summon(npc); + } +} diff --git a/src/boss_gemini.cpp b/src/boss_gemini.cpp index 38ef380..eb7b6de 100644 --- a/src/boss_gemini.cpp +++ b/src/boss_gemini.cpp @@ -80,6 +80,17 @@ constexpr int OVUM_BABY_RESET_FRAMES = 240; constexpr int OVUM_BABY_AIM_FRAMES = 40; constexpr float OVUM_BABY_LINE = 20; +// The Blighted Ovum baby's beam: a warning tracer above it, then a small thick red beam from just ahead of it. +constexpr ColorMod OVUM_BABY_WARNING_COLOR = {{0.6f, 0.05f, 0, 0.8f}, {0, 0, 0, 0}, {0, 0, 0}}; +constexpr float OVUM_BABY_WARNING_HEIGHT = -40; +constexpr float OVUM_BABY_WARNING_SCALE = 2; +constexpr int OVUM_BABY_WARNING_FRAMES = 18; +constexpr float OVUM_BABY_LASER_LEAD = 10; +constexpr float OVUM_BABY_LASER_HEIGHT = -20; +constexpr float OVUM_BABY_LASER_DEPTH = 3000; +constexpr float OVUM_BABY_LASER_SCALE = 0.8f; +constexpr int OVUM_BABY_LASER_TIMEOUT = 35; + constexpr int STEVEN_DEATH_SHOTS_SPEED = 8; constexpr int STEVEN_DEATH_BURST_SPEED = 4; constexpr int WALLACE_DEATH_SHOTS_SPEED = 10; @@ -87,7 +98,6 @@ constexpr float STEVEN_DEATH_FALL = -0.08f; constexpr float WALLACE_DEATH_FALL = -0.06f; constexpr float STEVEN_DEATH_SCALE = 2; -constexpr int SOUND_CUTE_GRUNT = 25; constexpr int SOUND_MONSTER_YELL_B = 122; constexpr int SOUND_STEVEN_DEATH_BIG = 961; constexpr int SOUND_STEVEN_DEATH_SMALL = 962; @@ -335,8 +345,12 @@ static void ovum_baby_update(Entity_NPC& npc, Vector toAim, Vector toTarget) npc.stateFrame = 0; npc.sprite.Play("Attack01", PLAY_FORCED); npc.sprite.isFlipX = npc.v1.x < 0; - reconstruction_missing("ENTITY_GEMINI_baby 00471cc0: Entity::SpawnFollowingEffect198 " - "0060b890's warning"); + float angle = std::atan2(npc.v1.y, npc.v1.x); + following_effect_spawn(npc, {.offset = vector_make(0, OVUM_BABY_WARNING_HEIGHT), + .targetPosition = vector_make(std::cos(angle), std::sin(angle)), + .color = OVUM_BABY_WARNING_COLOR, + .scale = OVUM_BABY_WARNING_SCALE, + .timeout = OVUM_BABY_WARNING_FRAMES}); npc.stateFrame++; return; } @@ -344,7 +358,22 @@ static void ovum_baby_update(Entity_NPC& npc, Vector toAim, Vector toTarget) else if (npc.state == NPC_STATE_ATTACK) { if (npc.sprite.animState.animData && npc.sprite.animState.IsEventTriggered("Shoot")) - return reconstruction_missing("ENTITY_GEMINI_baby 00471cc0: Entity_Laser::ShootAngle 0096f310"); + { + float angle = std::atan2(npc.v1.y, npc.v1.x) * RADIANS_TO_DEGREES; + Entity_Laser* laser = + Entity_Laser::ShootAngle({.position = vector_make(npc.v1.x * OVUM_BABY_LASER_LEAD + npc.pos.x, + npc.pos.y + OVUM_BABY_LASER_HEIGHT), + .posOffset = vector_make(0, OVUM_BABY_LASER_HEIGHT), + .source = &npc, + .angleDegrees = angle, + .timeout = OVUM_BABY_LASER_TIMEOUT, + .variant = LASER_THICK_RED}); + laser->renderDepthOffset = OVUM_BABY_LASER_DEPTH; + laser->set_scale(OVUM_BABY_LASER_SCALE); + laser->Update(); + npc.stateFrame++; + return; + } if (!npc.sprite.animState.animData || !npc.sprite.animState.isPlaying) { npc.state = NPC_STATE_MOVE; diff --git a/src/boss_gurdy.cpp b/src/boss_gurdy.cpp new file mode 100644 index 0000000..4b4bbb4 --- /dev/null +++ b/src/boss_gurdy.cpp @@ -0,0 +1,288 @@ +#include "boss_ai.h" +#include "entity_player.h" +#include "npc_caves.h" +#include "room_config.h" +#include "sfx_manager.h" +#include +#include +#include + +// Gurdy's green subtype, which never aims its shots. +constexpr int GURDY_GREEN = 1; + +// Gurdy's attacks (its "Attack%d" animations): the Attack Flies, a spray downward, the Pooter, a spray to the left or +// the right, and the boils. +enum GurdyAttack +{ + GURDY_NONE, + GURDY_FLIES, + GURDY_SPRAY_DOWN, + GURDY_POOTER, + GURDY_SPRAY_LEFT, + GURDY_SPRAY_RIGHT, + GURDY_BOILS +}; + +constexpr std::array GURDY_SUMMONS = {GURDY_POOTER, GURDY_FLIES, GURDY_BOILS}; + +constexpr float GURDY_PLAYER_ROW = 400; +constexpr float GURDY_PLAYER_SCATTER = 20; +constexpr float GURDY_DROP = 25; +constexpr float GURDY_FRICTION = 0.8f; +constexpr float GURDY_SHOVE_REACH = 80; +constexpr float GURDY_SHOVE_MIN = 0.01f; +constexpr float GURDY_SHOVE_STRENGTH = 0.03f; + +constexpr uint32_t GURDY_SUMMON_ODDS = 3; +constexpr float GURDY_AIM_LINE = 200; +constexpr int GURDY_SUMMON_ENEMY_LIMIT = 14; +constexpr int GURDY_AIM_ENEMY_LIMIT = 7; + +constexpr float GURDY_POOTER_VOLUME = 0.7f; +constexpr float GURDY_POOTER_MOUTH_X = 60; +constexpr float GURDY_POOTER_MOUTH_Y = -25; +constexpr float GURDY_POOTER_SPEED = 10; +constexpr int GURDY_DELIRIUM_LIMIT = 3; +constexpr int GURDY_SUMMON_PAIR = 2; +constexpr float GURDY_FLY_SIDE = 40; +constexpr float GURDY_FLY_HEIGHT = -65; +constexpr float GURDY_FLY_LIFT = -20; +constexpr float GURDY_FLY_HEALTH_LOSS = 2; +constexpr float GURDY_BOILS_VOLUME = 1.2f; +constexpr float GURDY_BOIL_SIDE = 42; +constexpr float GURDY_BOIL_DROP = 45; +constexpr float GURDY_BOIL_TAKEN_SQUARED = 400; + +constexpr float GURDY_SPRAY_HEIGHT = -20; +constexpr float GURDY_SPRAY_WIDTH = 30; +constexpr float GURDY_SPRAY_SPEED = 10; +constexpr float GURDY_SPRAY_SKEW = 3; +constexpr float GURDY_SIDE_MOUTH_X = 13; +constexpr float GURDY_SIDE_MOUTH_Y = -18; + +// The faces it pulls, each with its sound. +constexpr std::array, 4> GURDY_FACE_SOUNDS = { + {{"FaceAttackAppear", SOUND_GURDY_FACE_ATTACK_APPEAR}, + {"FaceAttackHide", SOUND_GURDY_FACE_ATTACK_HIDE}, + {"SmileAppear", SOUND_GURDY_FACE_SMILE_APPEAR}, + {"SmileHide", SOUND_GURDY_FACE_SMILE_HIDE}}}; + +// A shot's spread, a fraction rolled across a width and centered on 0. +static float gurdy_spread(float width) +{ + return random_unit() * width - width / 2; +} + +// In a 1x1 room the players are moved down in front of it as it appears, the first in line with it. +static void gurdy_players_place(Entity_NPC& npc) +{ + int count = (int)g_game->playerManager.playerList.size(); + for (int i = 0; i < count; i++) + { + Entity_Player& player = *g_game->GetPlayer(i); + if (i == 0) + { + player.Teleport(vector_make(npc.pos.x, GURDY_PLAYER_ROW), false, false); + continue; + } + float angle = random_unit() * RANDOM_HALF_TURN; + angle += angle; + player.Teleport(vector_make(std::cos(angle) * GURDY_PLAYER_SCATTER + npc.pos.x, + std::sin(angle) * GURDY_PLAYER_SCATTER + GURDY_PLAYER_ROW), + false, false); + } +} + +// 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) + { + auto* other = dynamic_cast(entity); + if (!other || other == &npc) continue; + if (other->type == ENTITY_BOIL) + { + if (npc.isDead && npc.HasEntityFlags(FLAG_DELIRIUM_FORM)) other->Kill(EntityRef()); + continue; + } + + Vector away = vector_sub(other->pos, npc.pos); + float distance = vector_length(away); + if (distance <= GURDY_SHOVE_MIN || distance >= GURDY_SHOVE_REACH || other->friction == 0) continue; + float strength = (GURDY_SHOVE_REACH - distance) * GURDY_SHOVE_STRENGTH / distance; + other->velocity.y = other->speedMultiplier * away.y * strength / other->friction + other->velocity.y; + other->velocity.x = other->speedMultiplier * away.x * strength / other->friction + other->velocity.x; + } +} + +// The next attack once its idle face ends: a summon at random while few enemies are about, else a spray at a target +// below or beside it (only summons for the green one, or when the target is high up, one time in three). +static int gurdy_attack_pick(Entity_NPC& npc, Entity& target) +{ + bool isSummon = Random() % GURDY_SUMMON_ODDS == 0 || target.pos.y <= GURDY_AIM_LINE; + int enemies = g_game->room->GetAliveEnemiesCount(); + if (!isSummon && enemies > GURDY_AIM_ENEMY_LIMIT) isSummon = true; + if (isSummon && enemies >= GURDY_SUMMON_ENEMY_LIMIT) return GURDY_NONE; + if (isSummon || npc.subtype == GURDY_GREEN) return GURDY_SUMMONS[Random() % GURDY_SUMMONS.size()]; + + float dy = npc.pos.y - target.pos.y; + float dx = npc.pos.x - target.pos.x; + if (std::abs(dy) >= std::abs(dx) && dy <= 0) return GURDY_SPRAY_DOWN; + return dx > 0 ? GURDY_SPRAY_LEFT : GURDY_SPRAY_RIGHT; +} + +// Idle: a face (Idle1 or Idle3, Idle2 once hurt), then the next attack. +static void gurdy_idle(Entity_NPC& npc, Entity& target) +{ + if (npc.stateFrame == 0) + { + int face = (int)(Random() & 1) * 2 + 1; + if (npc.v1.x > 0) + { + face = 2; + npc.v1.x = 0; + } + npc_anim_restart(npc.sprite, "Idle" + std::to_string(face)); + npc.stateFrame++; + return; + } + if (!npc_anim_is_done(npc)) return; + + npc.stateFrame = 0; + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM) && room_is_clear()) return; + int attack = gurdy_attack_pick(npc, target); + if (attack < 1) return; + + npc.state = NPC_STATE_ATTACK; + npc.sprite.Play("Attack" + std::to_string(attack)); + npc.i1 = attack; + npc.v1.x = 0; +} + +// How many a Delirium form summons: two, or what three leaves beside those of a type already about. +static int gurdy_summon_count(Entity_NPC& npc, int type) +{ + if (!npc.HasEntityFlags(FLAG_DELIRIUM_FORM)) return GURDY_SUMMON_PAIR; + int spare = GURDY_DELIRIUM_LIMIT - npc.CountRelatedEntities(type, 0, nullptr); + return spare < GURDY_DELIRIUM_LIMIT ? spare : GURDY_SUMMON_PAIR; +} + +// The boils: one at each side below it, or, where a boil already sits, that boil healed with a poof. +static void gurdy_boils(Entity_NPC& npc) +{ + npc.PlaySound(SOUND_SUMMONSOUND, GURDY_BOILS_VOLUME, 2, false, 1); + std::vector boils = entity_query(ENTITY_BOIL, -1); + int count = gurdy_summon_count(npc, ENTITY_BOIL); + for (int i = 0; i < count; i++) + { + float side = i == 0 ? GURDY_BOIL_SIDE : -GURDY_BOIL_SIDE; + Vector spot = vector_make(side + npc.pos.x, GURDY_BOIL_DROP + npc.pos.y); + bool isFree = true; + for (Entity* boil : boils) + { + if (vector_length_squared(vector_sub(spot, boil->pos)) >= GURDY_BOIL_TAKEN_SQUARED) continue; + isFree = false; + boil->health = boil->maxHitPoints; + g_game->Spawn({.position = spot, .type = ENTITY_EFFECT, .variant = EFFECT_POOF01, .seed = Random()}); + } + if (isFree) g_game->Spawn({.position = spot, .spawner = &npc, .type = ENTITY_BOIL, .seed = Random()}); + } +} + +// The attack's Shoot: the summon or the spray its animation shows. Back to idle once it ends. +static void gurdy_attack(Entity_NPC& npc) +{ + if (npc_anim_is_done(npc)) + { + npc.stateFrame = 0; + npc.state = NPC_STATE_IDLE; + return; + } + if (!npc.sprite.IsEventTriggered("Shoot")) return; + + ProjectileParams params; + switch (npc.i1) + { + case GURDY_POOTER: + npc.PlaySound(SOUND_SUMMONSOUND, GURDY_POOTER_VOLUME, 2, false, 1); + npc.PlaySound(SOUND_BOSS_BUG_HISS, 1, 2, false, 1); + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM) && + npc.CountRelatedEntities(ENTITY_POOTER, 0, nullptr) >= GURDY_DELIRIUM_LIMIT) + return; + g_game->Spawn({.position = vector_make(npc.pos.x + GURDY_POOTER_MOUTH_X, npc.pos.y + GURDY_POOTER_MOUTH_Y), + .velocity = vector_make(GURDY_POOTER_SPEED, 0), + .spawner = &npc, + .type = ENTITY_POOTER, + .seed = Random()}); + return; + case GURDY_FLIES: + { + npc.PlaySound(SOUND_SUMMONSOUND, 1, 2, false, 1); + npc.PlaySound(SOUND_BOSS_LITE_HISS, 1, 2, false, 1); + int count = gurdy_summon_count(npc, ENTITY_ATTACKFLY); + for (int i = 0; i < count; i++) + { + float side = i == 0 ? 1 : -1; + uint32_t seed = Random(); + Vector spot = vector_make(side * GURDY_FLY_SIDE + npc.pos.x, npc.pos.y + GURDY_FLY_HEIGHT); + Entity* fly = g_game->Spawn({.position = spot, + .velocity = vector_make(0, GURDY_FLY_LIFT), + .spawner = &npc, + .type = ENTITY_ATTACKFLY, + .seed = seed}); + fly->isKillOnTouch = true; + fly->health -= GURDY_FLY_HEALTH_LOSS; + } + return; + } + case GURDY_BOILS: + return gurdy_boils(npc); + case GURDY_SPRAY_DOWN: + { + npc.PlaySound(SOUND_BOSS_LITE_GURGLE, 1, 2, false, 1); + Vector mouth = vector_make(gurdy_spread(GURDY_SPRAY_WIDTH) + npc.pos.x, npc.pos.y + GURDY_SPRAY_HEIGHT); + Vector velocity = vector_make(gurdy_spread(GURDY_SPRAY_SKEW), GURDY_SPRAY_SPEED); + return npc.FireProjectiles(mouth, velocity, PROJECTILES_FIVE, params); + } + case GURDY_SPRAY_LEFT: + case GURDY_SPRAY_RIGHT: + { + npc.PlaySound(SOUND_BOSS_GURGLE_ROAR, 1, 2, false, 1); + bool isLeft = npc.i1 == GURDY_SPRAY_LEFT; + float x = isLeft ? npc.pos.x + GURDY_SIDE_MOUTH_X : npc.pos.x - GURDY_SIDE_MOUTH_X; + Vector mouth = vector_make(x, (GURDY_SIDE_MOUTH_Y - gurdy_spread(GURDY_SPRAY_WIDTH)) + npc.pos.y); + float skew = (random_unit() * GURDY_SPRAY_SKEW + 1) - GURDY_SPRAY_SKEW / 2; + Vector velocity = vector_make(isLeft ? -GURDY_SPRAY_SPEED : GURDY_SPRAY_SPEED, skew); + return npc.FireProjectiles(mouth, velocity, PROJECTILES_FIVE, params); + } + } +} + +// 0047c850 NpcAI::ENTITY_GURDY: Gurdy sits fixed to the floor, pulls faces, sprays shots at a target below or beside +// it, and summons Attack Flies, Pooters and boils, shoving its spawn off itself. +void boss_gurdy_update(Entity_NPC& npc) +{ + Entity& target = *npc.GetPlayerTarget(); + if (npc.state == NPC_STATE_INIT) + { + if (g_game->room->GetRoomShape() == ROOMSHAPE_1x1 && npc.spawnGridIndex >= 0) gurdy_players_place(npc); + npc.pos.y += GURDY_DROP; + npc.targetPosition = npc.pos; + npc.state = NPC_STATE_IDLE; + return; + } + + npc.velocity = vector_sub(npc.targetPosition, npc.pos); + npc.friction *= GURDY_FRICTION; + gurdy_spawn_shove(npc); + if (npc.state == NPC_STATE_IDLE) gurdy_idle(npc, target); + else if (npc.state == NPC_STATE_ATTACK) gurdy_attack(npc); + + if (!npc.sprite.animState.animData) return; + for (auto [event, sound] : GURDY_FACE_SOUNDS) + if (npc.sprite.IsEventTriggered(event)) npc_sound_play(sound, 1, 2, 1); +} diff --git a/src/boss_gurdy_jr.cpp b/src/boss_gurdy_jr.cpp new file mode 100644 index 0000000..17ca03e --- /dev/null +++ b/src/boss_gurdy_jr.cpp @@ -0,0 +1,294 @@ +#include "boss_ai.h" +#include "npc_caves.h" +#include "sfx_manager.h" + +// Gurdy Jr.'s subtypes: the twins, and the blue one that neither sprays nor summons. +constexpr int GURDY_JR_TWINS = 1; +constexpr int GURDY_JR_BLUE = 2; +constexpr float GURDY_JR_TWIN_OFFSET = 24; + +// Gurdy Jr.'s attacks, by state: a rest, the slide, the spray and the summon. +constexpr int GURDY_JR_REST = NPC_STATE_JUMP; +constexpr int GURDY_JR_SLIDE = NPC_STATE_ATTACK; +constexpr int GURDY_JR_SPRAY = NPC_STATE_ATTACK2; +constexpr int GURDY_JR_SUMMON = NPC_STATE_ATTACK3; + +// The slide's phases (i2): pushed while it winds up, sliding, and stopping. +enum GurdyJrSlide +{ + GURDY_JR_SLIDE_PUSH, + GURDY_JR_SLIDE_GLIDE, + GURDY_JR_SLIDE_END +}; + +// What a controlling player asks of it from the idle pose. +enum GurdyJrOrder +{ + GURDY_JR_ORDER_NONE = -1, + GURDY_JR_ORDER_SLIDE, + GURDY_JR_ORDER_SPRAY, + 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; +constexpr float GURDY_JR_SLIDE_TICKS = 5; +constexpr float GURDY_JR_STEER = 0.2f; +constexpr float GURDY_JR_SUMMON_STEER = 0.1f; +constexpr float GURDY_JR_AIM_REACH_SQUARED = 10; + +constexpr int GURDY_JR_CALM_TURNS = 3; +constexpr float GURDY_JR_SLIDE_HEALTH = 100; +constexpr float GURDY_JR_DELIRIUM_SLIDE_HEALTH = 8; +constexpr int GURDY_JR_SUMMON_ENEMY_LIMIT = 6; +constexpr int GURDY_JR_REST_FRAMES = 35; + +constexpr float GURDY_JR_SLIDE_SPEED = 4; +constexpr float GURDY_JR_TWIN_SLIDE = 0.7f; +constexpr float GURDY_JR_SLIDE_STOP_SQUARED = 4; +constexpr int GURDY_JR_SLIDE_FRAMES = 9; +constexpr float GURDY_JR_SPLAT_SIZE = 2; +constexpr float GURDY_JR_SPLAT_MIN = 0.4f; + +constexpr float GURDY_JR_SPRAY_SPEED = 10; +constexpr float GURDY_JR_HARD_SPRAY_SPEED = 12; +constexpr int GURDY_JR_POOF_FRONT = 3; +constexpr int GURDY_JR_POOF_SIDE = 4; +constexpr float GURDY_JR_POOF_SIDE_OFFSET = 50; +constexpr float GURDY_JR_POOF_SIDE_SCALE = 0.5f; + +constexpr int GURDY_JR_POOTER_LIMIT = 3; +constexpr float GURDY_JR_MOUTH_X = 30; +constexpr float GURDY_JR_MOUTH_Y = 35; +constexpr float GURDY_JR_POOTER_LIFT = -5; +constexpr float GURDY_JR_SUMMON_POOF_Y = 60; +constexpr float GURDY_JR_SUMMON_POOF_DEPTH = 4; +constexpr int GURDY_JR_DEATH_FRAMES = 2; + +constexpr float GURDY_JR_DEATH_VOLUME = 1.2f; + +// A poof of dust around it as it sprays, offset and shrunk for the side ones. +static Entity* gurdy_jr_poof_spawn(Entity_NPC& npc, int subType) +{ + return g_game->Spawn({.position = npc.pos, + .spawner = &npc, + .subType = subType, + .type = ENTITY_EFFECT, + .variant = EFFECT_POOF02, + .seed = Random()}); +} + +// The idle pose picks the next attack: while calm (three idle turns, health above 100, 8 for a Delirium form) a rest, +// a spray or a summon at random, else the slide. A controlled one does what its player asks. +static void gurdy_jr_idle(Entity_NPC& npc) +{ + npc.sprite.Play("Idle"); + + int order = GURDY_JR_ORDER_NONE; + if (npc.controllerID != -1) + { + if (!npc.HasEntityFlags(GURDY_JR_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; + else if (npc.IsControllerActionPressed(CONTROLLER_ACTION_SHOOT) && npc.subtype != GURDY_JR_TWINS && + npc.subtype != GURDY_JR_BLUE) + order = GURDY_JR_ORDER_SPRAY; + else if (npc.IsControllerActionPressed(CONTROLLER_ACTION_GROAN) && npc.subtype != GURDY_JR_TWINS) + order = GURDY_JR_ORDER_SUMMON; + } + if ((npc.HasEntityFlags(FLAG_DELIRIUM_FORM) && room_is_clear()) || + (npc.controllerID != -1 && order == GURDY_JR_ORDER_NONE)) + return; + + int turns = ++npc.projectileCooldown; + float slideHealth = npc.HasEntityFlags(FLAG_DELIRIUM_FORM) ? GURDY_JR_DELIRIUM_SLIDE_HEALTH : GURDY_JR_SLIDE_HEALTH; + if (npc.controllerID == -1 && turns < GURDY_JR_CALM_TURNS && npc.health >= slideHealth) + { + npc.stateFrame = 0; + if (npc.subtype == GURDY_JR_TWINS) + { + npc.state = NPC_STATE_IDLE; + return; + } + + std::vector attacks = {GURDY_JR_REST}; + if (npc.subtype != GURDY_JR_BLUE) attacks.push_back(GURDY_JR_SPRAY); + if (npc.GetAliveEnemyCount() < GURDY_JR_SUMMON_ENEMY_LIMIT) attacks.push_back(GURDY_JR_SUMMON); + npc.state = attacks[random_below((int)attacks.size())]; + npc.stateFrame = 0; + return; + } + + if (npc.controllerID != -1 && order != GURDY_JR_ORDER_SLIDE) + { + if (order == GURDY_JR_ORDER_SPRAY) npc.state = GURDY_JR_SPRAY; + else if (order == GURDY_JR_ORDER_SUMMON) npc.state = GURDY_JR_SUMMON; + npc.stateFrame = 0; + return npc.ClearChild(); + } + if (npc.HasEntityFlags(GURDY_JR_DISTRACTED)) return; + + npc.state = GURDY_JR_SLIDE; + npc.i2 = GURDY_JR_SLIDE_PUSH; + npc.projectileCooldown = 0; + Vector away = vector_sub(npc.pos, npc.GetPlayerTarget()->pos); + if (npc.controllerID != -1) away = vector_sub(npc.pos, npc.GetAimTargetPosition()); + float speed = GURDY_JR_SLIDE_SPEED / vector_length(away); + npc.friction *= GURDY_JR_SLIDE_START_FRICTION; + npc.sprite.Play("Attack03Start"); + if (npc.subtype == GURDY_JR_TWINS) speed *= GURDY_JR_TWIN_SLIDE; + npc.PlaySound(SOUND_MONSTER_ROAR_1, 1, 2, false, 1); + npc.targetPosition = vector_scale(away, -speed); + npc.i1 = 0; + npc.ClearChild(); +} + +// The slide at its target: pushed while it winds up, then sliding until it slows or ten turns pass, splatting blood +// every five frames. +static void gurdy_jr_slide(Entity_NPC& npc) +{ + if (npc_anim_is_done(npc) || npc.HasEntityFlags(GURDY_JR_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 (vector_length_squared(npc.velocity) <= GURDY_JR_SLIDE_STOP_SQUARED || npc.i1++ > GURDY_JR_SLIDE_FRAMES) + { + npc.i2 = GURDY_JR_SLIDE_END; + npc.sprite.Play("Attack03End"); + } + else npc_anim_restart(npc.sprite, "Slide"); + } + else if (npc.i2 == GURDY_JR_SLIDE_PUSH) + { + npc.friction *= GURDY_JR_FRICTION; + npc_push(npc, npc.targetPosition); + } + + if (!npc.GetIntervalTicks(GURDY_JR_SLIDE_TICKS, 0)) return; + float size = random_unit(); + Random(); + Random(); + npc.MakeSplat(size * GURDY_JR_SPLAT_SIZE + GURDY_JR_SPLAT_MIN); +} + +// The spray: a roar, then eight shots around it with a poof of dust in front and to each side. Steerable only between +// the roar and the shots. +static float gurdy_jr_spray(Entity_NPC& npc) +{ + float steer = npc.sprite.WasEventTriggered("Sound") && !npc.sprite.WasEventTriggered("Shoot") ? 1 : 0; + npc.sprite.Play("Attack02"); + if (npc.sprite.IsEventTriggered("Sound")) npc.PlaySound(SOUND_BOSS_LITE_ROAR, 1, 2, false, 1); + else if (npc.sprite.IsEventTriggered("Shoot")) + { + npc.PlaySound(SOUND_FORESTBOSS_STOMPS, 1, 2, false, 1); + npc.PlaySound(SOUND_BLOODSHOOT, 1, 2, false, 1); + float speed = game_is_hard_mode() ? GURDY_JR_HARD_SPRAY_SPEED : GURDY_JR_SPRAY_SPEED; + npc.FireProjectiles(npc.pos, vector_make(speed, 0), PROJECTILES_EIGHT, ProjectileParams()); + + Entity* front = gurdy_jr_poof_spawn(npc, GURDY_JR_POOF_FRONT); + front->sprite.isFlipX = (Random() & 1) == 0; + front->Update(); + for (float side : {GURDY_JR_POOF_SIDE_OFFSET, -GURDY_JR_POOF_SIDE_OFFSET}) + { + Entity* poof = gurdy_jr_poof_spawn(npc, GURDY_JR_POOF_SIDE); + poof->posOffset = vector_make(side, 0); + if (side > 0) poof->sprite.isFlipX = true; + poof->sprite.scale = vector_make(GURDY_JR_POOF_SIDE_SCALE, GURDY_JR_POOF_SIDE_SCALE); + poof->Update(); + } + } + if (npc_anim_is_done(npc)) npc.state = NPC_STATE_IDLE; + return steer; +} + +// The summon: a Pooter (a Super Pooter for the blue one) coughed up from its mouth, at most three for a Delirium form. +static void gurdy_jr_summon(Entity_NPC& npc) +{ + npc.sprite.Play("Attack01"); + if (npc.sprite.IsEventTriggered("Shoot")) + { + int variant = npc.subtype == GURDY_JR_BLUE ? 1 : 0; + if (!npc.HasEntityFlags(FLAG_DELIRIUM_FORM) || + npc.CountRelatedEntities(ENTITY_POOTER, variant, nullptr) < GURDY_JR_POOTER_LIMIT) + { + npc.PlaySound(SOUND_SUMMONSOUND, 1.1f, 2, false, 1); + Vector scale = npc.sprite.scale; + Vector mouth = vector_make(npc.pos.x - scale.x * GURDY_JR_MOUTH_X, npc.pos.y - scale.y * GURDY_JR_MOUTH_Y); + Entity* pooter = g_game->Spawn({.position = mouth, + .velocity = vector_make(0, GURDY_JR_POOTER_LIFT), + .spawner = &npc, + .type = ENTITY_POOTER, + .variant = variant, + .seed = Random()}); + pooter->ClearEntityFlags(FLAG_APPEAR); + + scale = npc.sprite.scale; + Entity* poof = g_game->Spawn({.position = npc.pos, + .subType = 1, + .type = ENTITY_EFFECT, + .variant = EFFECT_POOF01, + .seed = Random()}); + poof->SetColor(COLOR_DEFAULT, -1, COLOR_PRIORITY_DEFAULT, false, true); + poof->renderDepthOffset = GURDY_JR_SUMMON_POOF_DEPTH; + poof->posOffset = vector_make(scale.x * -GURDY_JR_MOUTH_X, scale.y * -GURDY_JR_SUMMON_POOF_Y); + poof->Update(); + } + } + if (npc_anim_is_done(npc)) npc.state = NPC_STATE_IDLE; +} + +// 0051d300 NpcAI::ENTITY_GURDY_JR: Gurdy Jr. rests, slides at its target splatting blood, sprays eight shots or +// coughs up Pooters. Twins (subtype 1) bring a brother and only slide. +void boss_gurdy_jr_update(Entity_NPC& npc) +{ + if (npc.state == NPC_STATE_INIT) + { + npc.state = NPC_STATE_IDLE; + npc.stateFrame = 0; + if (npc.subtype != GURDY_JR_TWINS || npc.spawnerType == npc.type) return; + + g_game->Spawn({.position = vector_make(npc.pos.x + GURDY_JR_TWIN_OFFSET, npc.pos.y), + .velocity = npc.velocity, + .spawner = &npc, + .subType = npc.subtype, + .type = npc.type, + .variant = npc.variant, + .seed = Random()}); + npc.pos.x -= GURDY_JR_TWIN_OFFSET; + return; + } + if (npc.isDead) + npc_sound_play(SOUND_MONSTER_ROAR_2, GURDY_JR_DEATH_VOLUME, GURDY_JR_DEATH_FRAMES, champion_pitch_get(npc)); + + if (npc.state != GURDY_JR_SLIDE) npc.friction *= GURDY_JR_FRICTION; + else if (npc.GetIntervalTicks(GURDY_JR_SLIDE_TICKS, 0)) npc.friction *= GURDY_JR_SLIDE_FRICTION; + + float steer = GURDY_JR_STEER; + switch (npc.state) + { + case NPC_STATE_IDLE: + gurdy_jr_idle(npc); + break; + case GURDY_JR_REST: + npc.sprite.Play("Idle"); + npc.stateFrame += npc_ticks_get(npc); + if (npc.stateFrame > GURDY_JR_REST_FRAMES) npc.state = NPC_STATE_IDLE; + break; + case GURDY_JR_SLIDE: + gurdy_jr_slide(npc); + steer = 0; + break; + case GURDY_JR_SPRAY: + steer = gurdy_jr_spray(npc); + break; + case GURDY_JR_SUMMON: + gurdy_jr_summon(npc); + steer = GURDY_JR_SUMMON_STEER; + break; + } + if (npc.controllerID == -1 || steer <= 0) return; + npc.velocity = vector_add(npc.velocity, vector_scale(npc.GetControllerInput(0), steer * npc.speedMultiplier)); +} diff --git a/src/boss_haunt.cpp b/src/boss_haunt.cpp new file mode 100644 index 0000000..a6035ee --- /dev/null +++ b/src/boss_haunt.cpp @@ -0,0 +1,529 @@ +#include "boss_ai.h" +#include "entity_laser.h" +#include "entity_tear.h" +#include "manager.h" +#include "npc_caves.h" +#include "room_grid.h" +#include "sfx_manager.h" +#include +#include + +// The Haunt (variant 0) and its Lil Haunts (variant 10), and its black and pale subtypes. +constexpr int HAUNT_LIL_VARIANT = 10; +constexpr int HAUNT_BLACK = 1; +constexpr int HAUNT_PALE = 2; + +// The Haunt's states: drifting along the top wall (3), skinned and shielded by its Lil Haunts (4), the spit, the +// laser, and shedding its skin. A Lil Haunt orbits it (3), then chases (4) and shoots (8). +constexpr int HAUNT_DRIFT = NPC_STATE_IDLE; +constexpr int HAUNT_SKINNED = NPC_STATE_MOVE; +constexpr int HAUNT_SPIT = NPC_STATE_ATTACK; +constexpr int HAUNT_LASER = NPC_STATE_ATTACK2; +constexpr int HAUNT_PEEL = NPC_STATE_SPECIAL; + +constexpr int HAUNT_LIL_COUNT = 3; +constexpr int HAUNT_BLACK_LIL_COUNT = 2; +constexpr int HAUNT_PALE_LIL_COUNT = 1; +constexpr float HAUNT_ORBIT_REACH = 50; +constexpr ColorMod HAUNT_GHOST_COLOR = {{1, 1, 1, 0.5f}, {0, 0, 0, 0}, {0, 0, 0}}; +constexpr ColorMod HAUNT_HIT_COLOR = {{1, 1, 1, 0.2f}, {0, 0, 0, 0}, {0, 0, 0}}; +constexpr ColorMod HAUNT_SPLAT_COLOR = {{0, 0, 0, 0.3f}, {0, 0, 0, 0}, {0.8f, 0.8f, 0.8f}}; +constexpr float HAUNT_GHOST_ALPHA = 0.5f; +constexpr float HAUNT_DRIFT_SPEED = 0.3f; +constexpr int HAUNT_HIT_FLASH_FRAMES = 10; +constexpr int HAUNT_HIT_FLASH_PRIORITY = 1; + +constexpr int LIL_HAUNT_CHARGE_FRAMES = 60; +constexpr int LIL_HAUNT_ORBIT_FRAMES = 90; +constexpr int LIL_HAUNT_ORBIT_SLOWING_FRAMES = 150; +constexpr float LIL_HAUNT_ORBIT_SLOTS = 3; +constexpr float LIL_HAUNT_ORBIT_SLOTS_LATE = 2; +constexpr float LIL_HAUNT_ORBIT_SLOWING = 60; +constexpr float LIL_HAUNT_ORBIT_TURN = 40; +constexpr float HAUNT_FULL_TURN = 360; +constexpr float LIL_HAUNT_FRICTION = 0.5f; +constexpr float LIL_HAUNT_CHASE_FRICTION = 0.95f; +constexpr float LIL_HAUNT_CHASE_SPEED = 0.5f; +constexpr float LIL_HAUNT_LEAD = 0.5f; +constexpr int LIL_HAUNT_SHOOT_WAIT = 90; +constexpr int LIL_HAUNT_CONTROLLED_SHOOT_WAIT = 60; +constexpr float LIL_HAUNT_SHOOT_REACH_SQUARED = 40000; +constexpr uint32_t LIL_HAUNT_SHOOT_ODDS = 50; +constexpr float LIL_HAUNT_CONTROLLED_RANGE = 1000; +constexpr float LIL_HAUNT_SHOT_PITCH = 1.2f; +constexpr float LIL_HAUNT_SHOT_PITCH_SPREAD = 0.1f; +constexpr float LIL_HAUNT_SPIT_HEIGHT = -12; +constexpr float LIL_HAUNT_SPIT_DEPTH = 4; +constexpr float LIL_HAUNT_SHOT_LEAD = 5; +constexpr float LIL_HAUNT_SHOT_SPEED = 10; +constexpr float LIL_HAUNT_WALL_PUSH_MIN = 0.02f; + +constexpr int HAUNT_COUNT_TICKS = 4; +constexpr float HAUNT_SKINNED_FRICTION = 0.9f; +constexpr float HAUNT_PEEL_FRICTION = 0.5f; +constexpr uint32_t HAUNT_ROAR_ODDS = 100; +constexpr int HAUNT_ROAR_DELAY = 100; +constexpr int HAUNT_PEEL_SOUND_DELAY = 600; +constexpr float HAUNT_PEEL_RISE = 20; +constexpr float HAUNT_CHARGE_LINE = 40; +constexpr uint32_t HAUNT_CHARGE_ODDS = 40; +constexpr float HAUNT_CHARGE_SPEED = 10; +constexpr float HAUNT_CHARGE_SPREAD = 5; +constexpr int HAUNT_ATTACK_WAIT = 60; +constexpr uint32_t HAUNT_ATTACK_ODDS = 60; +constexpr ColorMod HAUNT_TRACER_COLOR = {{0.6f, 0.05f, 0, 0.8f}, {0, 0, 0, 0}, {0, 0, 0}}; +constexpr int HAUNT_TRACER_TIMEOUT = 18; +constexpr float HAUNT_TRACER_SCALE = 4; +constexpr float HAUNT_TRACER_HEIGHT = -28; +constexpr float HAUNT_PALE_TRACER_HEIGHT = -46; + +constexpr float HAUNT_PALE_SHOT_ACCEL = -0.1f; +constexpr float HAUNT_PALE_SPRAY_STEP = 0.125f; +constexpr float HAUNT_PALE_SPRAY_ARC = 120; +constexpr float HAUNT_SPIT_SPEED = 10; +constexpr float HAUNT_LASER_HEIGHT = -50; +constexpr int HAUNT_LASER_TIMEOUT = 10; +constexpr float HAUNT_LASER_DEPTH = 3000; +constexpr float HAUNT_PALE_LASER_ANGLE = 135; +constexpr float HAUNT_LASER_ANGLE = 90; +constexpr float HAUNT_SPIDER_HEIGHT = -50; +constexpr float HAUNT_SPIDER_SCATTER = 50; +constexpr int HAUNT_DELIRIUM_SPIDER_LIMIT = 3; +constexpr float HAUNT_BOUNCE_NORMAL = 0.5f; +constexpr float HAUNT_BOUNCE_PUSH = 15; +constexpr float HAUNT_FRICTION = 0.96f; +constexpr float HAUNT_TOP_DEPTH = 30; + +// Sets every layer's alpha, as the Haunt fades its skin in and out. +static void layers_alpha_set(Entity_NPC& npc, float alpha) +{ + for (int i = 0; i < (int)npc.sprite.layerStates.size(); i++) npc.sprite.GetLayer(i)->color._tint[3] = alpha; +} + +// Drops the hits queued on it, which the Haunt and its orbiting Lil Haunts shrug off with a flash. +static void hits_clear(Entity_NPC& npc) +{ + npc.damageEvents.clear(); + npc.pendingDamage = 0; + npc.pendingDamageFlags = 0; +} + +// The first frame: the Haunt brings its ring of Lil Haunts and starts out see-through and shielded. A Lil Haunt keeps +// its health off the boss bar. Both bleed pale. +static void haunt_init(Entity_NPC& npc) +{ + npc.stateFrame = 0; + if (npc.variant == 0) + { + npc.entityCollisionClass = ENTCOLL_PLAYEROBJECTS; + npc.entityGridCollisionClass = GRIDCOLL_WALLS; + npc.i1 = npc.subtype == HAUNT_BLACK ? HAUNT_BLACK_LIL_COUNT + : npc.subtype == HAUNT_PALE ? HAUNT_PALE_LIL_COUNT + : HAUNT_LIL_COUNT; + for (int i = 0; i < npc.i1; i++) + { + uint32_t seed = Random(); + float angle = (float)i / (float)npc.i1 * HAUNT_FULL_TURN * DEGREES_TO_RADIANS; + Vector spot = vector_make(std::cos(angle) * HAUNT_ORBIT_REACH + npc.pos.x, + std::sin(angle) * HAUNT_ORBIT_REACH + npc.pos.y); + auto* lil = static_cast(g_game->Spawn( + {.position = spot, .spawner = &npc, .type = npc.type, .variant = HAUNT_LIL_VARIANT, .seed = seed})); + lil->parent = &npc; + lil->SetColor(HAUNT_GHOST_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); + lil->i1 = i; + lil->isInvincible = true; + } + npc.targetPosition = vector_make(HAUNT_DRIFT_SPEED, 0); + layers_alpha_set(npc, HAUNT_GHOST_ALPHA); + npc.AddEntityFlags(FLAG_NO_TARGET); + npc.state = HAUNT_SKINNED; + npc.isInvincible = true; + } + else + { + npc.AddEntityFlags(FLAG_DONT_COUNT_BOSS_HP); + npc.state = NPC_STATE_IDLE; + npc.entityGridCollisionClass = GRIDCOLL_NONE; + npc.entityCollisionClass = ENTCOLL_PLAYERONLY; + } + npc.splatColor = HAUNT_SPLAT_COLOR; +} + +// A Lil Haunt orbits the Haunt, spinning faster as its siblings leave, and breaks off to chase once its turn comes +// (or at once when it lost its Haunt, or a player controls it). Hits only make it flash. +static void lil_haunt_orbit(Entity_NPC& npc) +{ + npc.sprite.Play("Float"); + int siblings = 0; + float hauntSubtype = 0; + int age = g_game->frameCount - npc.spawnFrame; + if (npc.parent) + { + Entity_NPC& haunt = *npc.ParentNPC(); + siblings = haunt.i1; + hauntSubtype = (float)npc.ParentNPC()->subtype; + float slots = (float)siblings; + if (hauntSubtype == 0) + { + slots = LIL_HAUNT_ORBIT_SLOTS_LATE; + if (age <= LIL_HAUNT_ORBIT_FRAMES) slots = LIL_HAUNT_ORBIT_SLOTS; + else if (age < LIL_HAUNT_ORBIT_SLOWING_FRAMES) + slots = LIL_HAUNT_ORBIT_SLOTS - (float)(age - LIL_HAUNT_ORBIT_FRAMES) / LIL_HAUNT_ORBIT_SLOWING; + } + float spin = (float)g_game->room->GetFrameCount(); + float degrees = (float)npc.i1 / slots * HAUNT_FULL_TURN + spin + spin - LIL_HAUNT_ORBIT_TURN; + float angle = degrees * DEGREES_TO_RADIANS; + Vector center = npc.parent->pos; + npc.pos = vector_make(std::cos(angle) * HAUNT_ORBIT_REACH + center.x, + std::sin(angle) * HAUNT_ORBIT_REACH + center.y); + } + npc.friction *= LIL_HAUNT_FRICTION; + if (npc.pendingDamage > 0) + { + npc.SetColor(HAUNT_HIT_COLOR, HAUNT_HIT_FLASH_FRAMES, HAUNT_HIT_FLASH_PRIORITY, false, true); + hits_clear(npc); + } + + bool isTurn = (npc.i1 == 0 || hauntSubtype != 0) && age > LIL_HAUNT_ORBIT_FRAMES; + if (!isTurn && !(siblings < 3 && hauntSubtype == 0) && npc.controllerID == -1) return; + npc.state = NPC_STATE_MOVE; + npc.sprite.Play("FloatChase"); + npc.SetColor(COLOR_DEFAULT, -1, COLOR_PRIORITY_DEFAULT, false, true); + npc.entityCollisionClass = ENTCOLL_ALL; + npc.PlaySound(SOUND_HAUNT_RELEASE_LIL, 1, 2, false, 1); +} + +// The chase: toward where its target is heading, then a shot once it has chased a while and is near. +static void lil_haunt_chase(Entity_NPC& npc) +{ + Vector toTarget = vector_sub(npc.CalcTargetPosition(0), npc.pos); + if (npc_anim_is_done(npc)) npc.sprite.Play("FloatChase"); + float distanceSquared = vector_length_squared(toTarget); + float distance = std::sqrt(distanceSquared); + + Vector aim; + if (npc.controllerID == -1) + { + Entity* target = npc.GetPlayerTarget(); + aim = vector_normalized(vector_make(distance * target->velocity.x * LIL_HAUNT_LEAD + toTarget.x, + distance * target->velocity.y * LIL_HAUNT_LEAD + toTarget.y)); + } + else aim = npc.GetControllerInput(0); + npc_push(npc, vector_scale(aim, LIL_HAUNT_CHASE_SPEED)); + npc.sprite.isFlipX = npc.velocity.x > 0; + npc.friction *= LIL_HAUNT_CHASE_FRICTION; + + bool isShooting = npc.controllerID == -1 + ? npc.stateFrame > LIL_HAUNT_SHOOT_WAIT && distanceSquared < LIL_HAUNT_SHOOT_REACH_SQUARED && + Random() % LIL_HAUNT_SHOOT_ODDS == 0 + : npc.stateFrame > LIL_HAUNT_CONTROLLED_SHOOT_WAIT && + npc.IsTargetInAttackRange(LIL_HAUNT_CONTROLLED_RANGE, 0, true); + if (isShooting) + { + npc.UpdateControllerMovement(true); + npc.state = NPC_STATE_ATTACK; + } + npc.stateFrame += npc_ticks_get(npc); +} + +// The shot: a splash of pale blood and one shot where its target is heading, then back to the chase. +static void lil_haunt_shoot(Entity_NPC& npc) +{ + npc.UpdateControllerMovement(false); + npc.sprite.Play("Shoot"); + if (npc.sprite.IsEventTriggered("Shoot")) + { + float pitch = random_unit() * LIL_HAUNT_SHOT_PITCH_SPREAD + LIL_HAUNT_SHOT_PITCH; + npc.PlaySound(SOUND_WORM_SPIT, 1, 2, false, pitch); + auto* splash = static_cast( + blood_explosion_spawn(1, npc.pos, vector_make(0, LIL_HAUNT_SPIT_HEIGHT), npc.splatColor, {})); + splash->renderDepthOffset = LIL_HAUNT_SPIT_DEPTH; + splash->FollowParent(&npc); + + Vector targetPos = npc.GetPlayerTarget()->pos; + Vector lead = vector_scale(npc.GetPlayerTarget()->velocity, LIL_HAUNT_SHOT_LEAD); + Vector aim = vector_sub(vector_add(lead, targetPos), npc.pos); + if (npc.controllerID != -1) aim = npc.controllerMovement; + ProjectileParams params; + Vector velocity = vector_scale(vector_normalized(aim), LIL_HAUNT_SHOT_SPEED); + npc.FireProjectiles(npc.pos, velocity, PROJECTILES_SINGLE, params); + npc.state = NPC_STATE_MOVE; + } + npc.stateFrame = 0; + npc.friction *= LIL_HAUNT_FRICTION; +} + +// Pushes it back inside the room's walls, harder the faster it heads out. +static void lil_haunt_wall_keep(Entity_NPC& npc) +{ + Vector inside = g_game->room->GetClampedPositionImpl(npc.pos, 0, 0, 0, 0); + Vector back = vector_sub(inside, npc.pos); + if (vector_is_zero(back)) return; + back = vector_normalized(back); + float strength = std::clamp(-(back.y * npc.velocity.y + npc.velocity.x * back.x), LIL_HAUNT_WALL_PUSH_MIN, 1.0f); + npc.velocity.y = strength * back.y * npc.speedMultiplier + npc.velocity.y; + npc.velocity.x = strength * back.x * npc.speedMultiplier + npc.velocity.x; +} + +// A Lil Haunt: orbiting, chasing and shooting, kept in the room, and dying with its Haunt. +static void lil_haunt_update(Entity_NPC& npc) +{ + npc.UpdateChargeBar(0, LIL_HAUNT_CHARGE_FRAMES, (float)npc.stateFrame, true); + if (npc.state == NPC_STATE_MOVE) lil_haunt_chase(npc); + else if (npc.state == NPC_STATE_ATTACK) lil_haunt_shoot(npc); + else if (npc.state == NPC_STATE_IDLE) lil_haunt_orbit(npc); + + if (npc.state != NPC_STATE_IDLE) lil_haunt_wall_keep(npc); + if (npc.parent && npc.parent->isDead) npc.Kill(EntityRef()); +} + +// Shielded by its Lil Haunts it wanders, roaring now and then. With none left it peels off its skin, rising to the +// top wall, and the boss bar moves to the bottom. +static void haunt_skinned(Entity_NPC& npc) +{ + if (npc.i1 >= 1) + { + npc.sprite.Play("IdleSkin"); + npc.pathfinder.MoveRandomlyBoss(STATUS_OBEYED); + npc.friction *= HAUNT_SKINNED_FRICTION; + if (Random() % HAUNT_ROAR_ODDS == 0 && !g_manager->sfxManager.IsPlaying(SOUND_HAUNT_RELEASE_LIL)) + npc.PlaySound(SOUND_HAUNT_ROAR, 1, HAUNT_ROAR_DELAY, false, 1); + return; + } + + npc.ClearEntityFlags(FLAG_NO_TARGET); + npc.sprite.Play("AngrySkin"); + npc.PlaySound(SOUND_BOO_MAD, 1, HAUNT_PEEL_SOUND_DELAY, false, 1); + const AnimationData* animation = npc.sprite.animState.animData; + float progress = npc.sprite.animState.animFrame / (float)(animation ? animation->length : 0); + layers_alpha_set(npc, progress * 0.5f + 0.5f); + npc.pos.y = (g_game->room->topLeftPos.y + HAUNT_PEEL_RISE - npc.pos.y) * progress + npc.pos.y; + if (!(npc.HasEntityFlags(FLAG_DELIRIUM_FORM) && room_is_clear()) && npc_anim_is_done(npc)) + { + npc.sprite.Play("Peel"); + npc.PlaySound(SOUND_SKIN_PULL, 1, 2, false, 1); + npc.state = HAUNT_PEEL; + g_game->hud.isBossBarBottom = true; + } + npc.friction *= HAUNT_PEEL_FRICTION; +} + +// Drifting along the top wall it charges sideways at a target in line with it, and now and then spits or fires its +// laser after a warning. +static void haunt_drift(Entity_NPC& npc) +{ + if (npc_anim_is_done(npc)) npc.sprite.Play("IdleNoSkin"); + Vector target = npc.CalcTargetPosition(0); + float dx = target.x - npc.pos.x; + if (std::abs(target.y - npc.pos.y) < HAUNT_CHARGE_LINE && Random() % HAUNT_CHARGE_ODDS == 0) + { + float drift = std::abs(npc.targetPosition.x); + float speed = std::abs(npc.velocity.x); + if (dx >= 0) + { + npc.targetPosition.x = drift; + npc.velocity.x = speed; + npc.velocity.x = random_unit() * HAUNT_CHARGE_SPREAD + HAUNT_CHARGE_SPEED + npc.velocity.x; + } + else + { + npc.targetPosition.x = -drift; + npc.velocity.x = -speed; + npc.velocity.x = npc.velocity.x - (random_unit() * HAUNT_CHARGE_SPREAD + HAUNT_CHARGE_SPEED); + } + if (!npc.sprite.IsPlaying("AngryNoSkin")) + { + npc.sprite.Play("AngryNoSkin"); + npc.PlaySound(SOUND_HAUNT_CHARGE, 1, 2, false, 1); + } + } + + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM) && room_is_clear()) return; + if (npc.stateFrame++ <= HAUNT_ATTACK_WAIT || Random() % HAUNT_ATTACK_ODDS != 0) return; + if ((Random() & 1) == 0) + { + npc.state = HAUNT_SPIT; + npc.v2.x = 0; + return; + } + + npc.state = HAUNT_LASER; + if (npc.subtype == HAUNT_BLACK) return; + FollowingEffect tracer = { + .color = HAUNT_TRACER_COLOR, .scale = HAUNT_TRACER_SCALE, .timeout = HAUNT_TRACER_TIMEOUT}; + if (npc.subtype == HAUNT_PALE) + { + tracer.offset = vector_make(0, HAUNT_PALE_TRACER_HEIGHT); + tracer.targetPosition = vector_from_angle(HAUNT_PALE_LASER_ANGLE); + following_effect_spawn(npc, tracer); + tracer.targetPosition = vector_from_angle(HAUNT_PALE_LASER_ANGLE - HAUNT_LASER_ANGLE); + } + else + { + tracer.offset = vector_make(0, HAUNT_TRACER_HEIGHT); + tracer.targetPosition = vector_from_angle(HAUNT_LASER_ANGLE); + } + following_effect_spawn(npc, tracer); +} + +// The spit: five shots down, or for the pale one a sweeping stream from Shoot to Stop, every other tick. +static void haunt_spit(Entity_NPC& npc) +{ + npc.sprite.Play("SpitNoSkin"); + if (npc.subtype == HAUNT_PALE) + { + if (npc.sprite.animState.animData && npc.sprite.WasEventTriggered("Shoot") && + !npc.sprite.WasEventTriggered("Stop") && npc.IsFrame(2, 0)) + { + ProjectileParams params; + params.fallingAccelModifier = HAUNT_PALE_SHOT_ACCEL; + float side = npc.IsFrame(4, 0) ? 1.0f : -1.0f; + float sweep = npc.v2.x * 0.5f * side + 0.5f; + Vector aim = vector_resized(vector_sub(npc.CalcTargetPosition(0), npc.pos), HAUNT_SPIT_SPEED); + float angle = (sweep * HAUNT_PALE_SPRAY_ARC - HAUNT_PALE_SPRAY_ARC / 2) * DEGREES_TO_RADIANS; + float cosine = std::cos(angle); + float sine = std::sin(angle); + Vector velocity = vector_make(cosine * aim.x - aim.y * sine, sine * aim.x + aim.y * cosine); + npc.FireProjectiles(vector_add(npc.pos, npc.velocity), velocity, PROJECTILES_SINGLE, params); + npc.PlaySound(SOUND_GHOST_SHOOT, 1, 2, false, 1); + npc.v2.x += HAUNT_PALE_SPRAY_STEP; + } + } + else if (npc.sprite.animState.animData && npc.sprite.IsEventTriggered("Shoot")) + { + ProjectileParams params; + npc.FireProjectiles(vector_add(npc.velocity, npc.pos), vector_make(0, HAUNT_SPIT_SPEED), PROJECTILES_FIVE, + params); + npc.PlaySound(SOUND_GHOST_SHOOT, 1, 2, false, 1); + } +} + +// A spider the black one throws halfway to its target, scattered for the second one. +static void haunt_spider_throw(Entity_NPC& npc, float scatter) +{ + Room& room = *g_game->room; + Vector target = npc.GetPlayerTarget()->pos; + Vector halfway = vector_add(vector_scale(vector_sub(target, npc.pos), 0.5f), npc.pos); + if (scatter > 0) + { + Vector direction = random_direction(); + float reach = random_unit() * scatter; + halfway = vector_add(halfway, vector_scale(direction, reach)); + halfway = room.GetClampedPositionImpl(halfway, 0, 0, 0, 0); + } + Vector spot = room_free_pickup_position_find({.position = halfway}); + Entity_NPC::ThrowSpider(npc.pos, &npc, spot, false, HAUNT_SPIDER_HEIGHT); +} + +// The laser on Shoot: one straight down, two diagonal bouncing ones for the pale one, or spiders thrown by the black +// one. +static void haunt_laser(Entity_NPC& npc) +{ + npc.sprite.Play("LaserNoSkin"); + if (!npc.sprite.animState.animData || !npc.sprite.IsEventTriggered("Shoot")) return; + + if (npc.subtype == HAUNT_BLACK) + { + int spiders = 2; + bool isThrowing = true; + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM)) + { + int spare = HAUNT_DELIRIUM_SPIDER_LIMIT - npc.CountRelatedEntities(ENTITY_BIG_SPIDER, 0, nullptr) - + npc.CountRelatedEntities(ENTITY_SPIDER, 0, nullptr) - + npc.CountRelatedEntities(ENTITY_STRIDER, 0, nullptr); + if (spare <= 2) spiders = spare; + isThrowing = spare > 0; + } + if (isThrowing) haunt_spider_throw(npc, 0); + if (spiders > 1 && (Random() & 1) == 0) haunt_spider_throw(npc, HAUNT_SPIDER_SCATTER); + } + else + { + LaserShot shot = {.position = npc.pos, + .posOffset = vector_make(0, HAUNT_LASER_HEIGHT), + .source = &npc, + .angleDegrees = HAUNT_LASER_ANGLE, + .timeout = HAUNT_LASER_TIMEOUT, + .variant = LASER_THICK_RED}; + bool isPale = npc.subtype == HAUNT_PALE; + if (isPale) shot.angleDegrees = HAUNT_PALE_LASER_ANGLE; + for (int i = 0; i < (isPale ? 2 : 1); i++) + { + Entity_Laser* laser = Entity_Laser::ShootAngle(shot); + laser->renderDepthOffset = HAUNT_LASER_DEPTH; + if (isPale) laser->tearFlags = TearFlags().set(TEAR_BOUNCE); + laser->Update(); + shot.angleDegrees -= HAUNT_LASER_ANGLE; + } + } + npc_sound_play(SOUND_GHOST_ROAR, 1, 2, champion_pitch_get(npc)); +} + +// The Haunt: it counts its Lil Haunts every fourth tick, shrugs off hits while they shield it, and once skinless +// drifts along the top wall attacking. +static void haunt_update(Entity_NPC& npc) +{ + if (npc.i1 > 0 && !npc.HasEntityFlags(FLAG_INTERPOLATION_UPDATE) && !g_game->IsPaused() && + g_game->frameCount % HAUNT_COUNT_TICKS == 0) + { + npc.i1 = 0; + for (Entity* lil : entity_query(npc.type, HAUNT_LIL_VARIANT)) + if (lil->parent.get() == &npc) npc.i1++; + } + if ((npc.state == HAUNT_SKINNED || npc.state == HAUNT_PEEL) && npc.pendingDamage > 0) + { + if (npc.state == HAUNT_SKINNED && npc.i1 > 0) + { + ColorMod flash = npc.sprite.color; + flash._tint[3] = HAUNT_HIT_COLOR._tint[3]; + npc.SetColor(flash, HAUNT_HIT_FLASH_FRAMES, HAUNT_HIT_FLASH_PRIORITY, false, true); + } + hits_clear(npc); + } + + if (npc.state == HAUNT_SKINNED) haunt_skinned(npc); + else if (npc.state == HAUNT_PEEL) + { + layers_alpha_set(npc, 1); + if (npc_anim_is_done(npc)) + { + npc.state = HAUNT_DRIFT; + npc.stateFrame = 0; + npc.entityCollisionClass = ENTCOLL_PLAYEROBJECTS; + } + } + else if (npc.state == HAUNT_DRIFT) haunt_drift(npc); + + bool isAttacking = npc.state == HAUNT_SPIT || npc.state == HAUNT_LASER; + if (npc.state == HAUNT_SPIT) haunt_spit(npc); + else if (npc.state == HAUNT_LASER) haunt_laser(npc); + if (isAttacking && npc_anim_is_done(npc)) + { + npc.state = HAUNT_DRIFT; + npc.stateFrame = 0; + } + + if (npc.state == HAUNT_DRIFT || npc.state == HAUNT_SPIT || npc.state == HAUNT_LASER) + { + npc.velocity.x = npc.speedMultiplier * npc.targetPosition.x + npc.velocity.x; + npc.velocity.y = npc.targetPosition.y * npc.speedMultiplier + npc.velocity.y; + if (npc.isCollidesWithGrid && std::abs(npc.gridCollisionNormal.x) > HAUNT_BOUNCE_NORMAL) + { + npc.targetPosition = vector_scale(npc.targetPosition, -1); + npc.velocity = vector_add(vector_scale(npc.targetPosition, HAUNT_BOUNCE_PUSH), npc.velocity); + } + } + npc.friction *= HAUNT_FRICTION; + if (npc.state != HAUNT_SKINNED) npc.pos.y = g_game->room->topLeftPos.y + HAUNT_TOP_DEPTH; + if (npc.isDead) npc_sound_play(SOUND_HAUNT_DEATH, 1, 2, champion_pitch_get(npc)); +} + +// 00481410 NpcAI::ENTITY_THE_HAUNT: the Haunt hides behind its ring of Lil Haunts, which break off one by one to +// chase and shoot, then peels its skin and drifts along the top wall spitting, firing lasers or throwing spiders. +void boss_haunt_update(Entity_NPC& npc) +{ + if (npc.state == NPC_STATE_INIT) return haunt_init(npc); + npc.isInvincible = false; + if (npc.variant == 0) haunt_update(npc); + else if (npc.variant == HAUNT_LIL_VARIANT) lil_haunt_update(npc); +} diff --git a/src/boss_loki.cpp b/src/boss_loki.cpp new file mode 100644 index 0000000..8b987e1 --- /dev/null +++ b/src/boss_loki.cpp @@ -0,0 +1,192 @@ +#include "boss_ai.h" +#include "entity_player.h" +#include "npc_caves.h" +#include "sfx_manager.h" + +// Lokii, the twin Loki (its variant). The second of a pair starts hidden and mirrored (its i1 2). +constexpr int LOKII = 1; +constexpr int LOKII_HIDDEN_TWIN = 2; + +// Loki's next move from its walk: a teleport 1 in 40 with a player within 300, a ring of eight 1 in 140, a cross of +// bursts 1 in 100, and 1 in 70 a boom fly while fewer than 3 to 5 enemies are left (a Lokii 1 time in 3 of those). +constexpr float WALK_SPEED_SQUARED = 1; +constexpr uint32_t TELEPORT_ODDS = 40; +constexpr float TELEPORT_REACH_SQUARED = 90000; +constexpr uint32_t RING_ODDS = 140; +constexpr uint32_t BURSTS_ODDS = 100; +constexpr uint32_t LOKI_SUMMON_ODDS = 70; +constexpr uint32_t SUMMON_CROWD_MIN = 3; +constexpr uint32_t SUMMON_CROWD_SPREAD = 3; +constexpr uint32_t LOKII_SUMMON_ODDS = 3; +constexpr int DELIRIUM_FLIES_MAX = 2; +constexpr float DELIRIUM_FLY_HEALTH = 10; + +// A teleport lands on a random cell 20 in from the walls, 200 to 400 from the nearest player and not straight across +// from them closer than 400, off the paths enemies walk, trying 6 spots a frame while it vanishes. +constexpr float TELEPORT_MARGIN = 20; +constexpr int TELEPORT_TRIES = 6; +constexpr float TELEPORT_ALIGN = 20; +constexpr float TELEPORT_NEAR_SQUARED = 40000; +constexpr float TELEPORT_FAR_SQUARED = 160000; +constexpr int TELEPORT_PATH_MAX = 500; + +// Its shots: 12 fast, in a ring of eight, or three bursts of plus, cross and plus. +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) +{ + npc.targetPosition = vector_make(0, 0); + npc.AddEntityFlags(FLAG_NO_SPIKE_DAMAGE); + npc.state = NPC_STATE_IDLE; + if (npc.variant != LOKII || npc.i1 != 0) return; + + npc.i1 = 1; + Entity_NPC* twin = nullptr; + for (Entity* entity : entity_query(npc.type, LOKII)) + if (static_cast(entity)->i1 == 0) twin = static_cast(entity); + if (!twin) return; + + twin->i1 = LOKII_HIDDEN_TWIN; + twin->isVisible = false; + twin->sprite.isFlipX = true; +} + +// The walk: it wanders and rolls its next move. +static void loki_walk(Entity_NPC& npc) +{ + npc.pathfinder.MoveRandomly(STATUS_OBEYED); + npc.sprite.Play(vector_length_squared(npc.velocity) > WALK_SPEED_SQUARED ? "Walk" : "Idle"); + npc.stateFrame = 0; + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM) && room_is_clear()) return; + + Vector toTarget = vector_sub(npc.pos, npc.GetPlayerTarget()->pos); + if (Random() % TELEPORT_ODDS == 0 && vector_length_squared(toTarget) < TELEPORT_REACH_SQUARED) + { + npc.sprite.Play("TeleportUp"); + npc.targetPosition = vector_make(0, 0); + npc.state = NPC_STATE_JUMP; + return; + } + if (Random() % RING_ODDS == 0) + { + npc.sprite.Play("Attack03"); + npc.state = NPC_STATE_ATTACK2; + return; + } + if (Random() % BURSTS_ODDS == 0) + { + npc.sprite.Play("Attack01"); + npc.state = NPC_STATE_ATTACK3; + return; + } + if (Random() % LOKI_SUMMON_ODDS != 0) return; + + int enemies = g_game->room->GetAliveEnemiesCount(); + if (enemies < (int)(Random() % SUMMON_CROWD_SPREAD + SUMMON_CROWD_MIN) && + (Random() % LOKII_SUMMON_ODDS == 0 || npc.variant == 0)) + { + npc.sprite.Play("Attack02"); + npc.state = NPC_STATE_ATTACK; + } +} + +// While it vanishes it looks for where to land, and once gone it lands there. +static void loki_teleport(Entity_NPC& npc) +{ + if (npc_anim_is_done(npc)) + { + npc.sprite.Play("TeleportDown"); + npc.state = NPC_STATE_STOMP; + if (!vector_is_zero(npc.targetPosition)) npc.pos = npc.targetPosition; + return; + } + + Room& room = *g_game->room; + for (int i = TELEPORT_TRIES - 1; i >= 0; i--) + { + int cell = cell_get(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); + float distance = vector_length_squared(away); + bool isAligned = std::abs(away.x) < TELEPORT_ALIGN || std::abs(away.y) < TELEPORT_ALIGN; + bool isOffPath = (uint32_t)cell >= ROOM_GRID_CELLS || room.gridPaths[cell] < TELEPORT_PATH_MAX; + if ((!isAligned || distance >= TELEPORT_FAR_SQUARED) && distance >= TELEPORT_NEAR_SQUARED && isOffPath) + npc.targetPosition = spot; + if (i < 1 || npc.targetPosition.x != 0 || npc.targetPosition.y != 0) return; + } +} + +// A blast of blood and a spread of 12 fast shots. +static void loki_shoot(Entity_NPC& npc, int voice, ProjectilesMode mode) +{ + npc.PlaySound(SOUND_CUTE_GRUNT, 1, 2, false, 1); + npc.PlaySound(voice, 1, 2, false, 1); + blood_explosion_spawn(BLOOD_EXPLOSION_SMALL, npc.pos, vector_make(0, 0), COLOR_DEFAULT, vector_make(0, 0)); + npc.FireProjectiles(npc.pos, vector_make(LOKI_SHOT_SPEED, 0), mode, ProjectileParams()); +} + +// A boom fly of its own color, at most two more for a Delirium form, which gives them 10 health. +static void loki_summon(Entity_NPC& npc) +{ + bool isDelirium = npc.HasEntityFlags(FLAG_DELIRIUM_FORM); + if (isDelirium && npc.CountRelatedEntities(ENTITY_BOOMFLY, npc.variant, nullptr) > DELIRIUM_FLIES_MAX) return; + + npc.PlaySound(SOUND_SUMMONSOUND, 1, 2, false, 1); + Entity* fly = g_game->Spawn({.position = npc.pos, .spawner = &npc, .type = ENTITY_BOOMFLY, .variant = npc.variant, + .seed = Random()}); + if (!isDelirium) return; + + fly->health = DELIRIUM_FLY_HEALTH; + fly->maxHitPoints = DELIRIUM_FLY_HEALTH; +} + +// 00467670 NpcAI::ENTITY_LOKI: Loki and Lokii wander, teleport near a player, shoot rings and bursts and call boom +// flies, giggling and jumping out of sight to the sound of their events. +void boss_loki_update(Entity_NPC& npc) +{ + if (npc.state == NPC_STATE_INIT) return loki_init(npc); + + ANM2& sprite = npc.sprite; + if (sprite.animState.animData) + { + if (sprite.animState.IsEventTriggered("Giggle")) npc_sound_play(SOUND_LOKI_GIGGLE, 1, 2, 1); + if (sprite.animState.IsEventTriggered("Jump")) npc_sound_play(SOUND_LOKI_JUMP_OUT, 1, 2, 1); + if (sprite.animState.IsEventTriggered("JumpIn")) npc_sound_play(SOUND_LOKI_JUMP_IN, 1, 2, 1); + } + npc.friction *= LOKI_FRICTION; + if (npc_anim_is_done(npc) && npc.state != NPC_STATE_JUMP) npc.state = NPC_STATE_IDLE; + + switch (npc.state) + { + case NPC_STATE_IDLE: + return loki_walk(npc); + case NPC_STATE_JUMP: + return loki_teleport(npc); + case NPC_STATE_ATTACK: + if (sprite.IsEventTriggered("Shoot")) loki_summon(npc); + return; + case NPC_STATE_ATTACK2: + if (sprite.IsEventTriggered("Shoot")) loki_shoot(npc, SOUND_LOKI_SHOOT_8, PROJECTILES_EIGHT); + return; + case NPC_STATE_ATTACK3: + if (!sprite.IsEventTriggered("Shoot")) return; + if (npc.stateFrame <= 2) + loki_shoot(npc, SOUND_LOKI_SHOOT, npc.stateFrame == 1 ? PROJECTILES_CROSS : PROJECTILES_PLUS); + npc.stateFrame++; + return; + } +} diff --git a/src/boss_mega_maw.cpp b/src/boss_mega_maw.cpp new file mode 100644 index 0000000..a88d3b1 --- /dev/null +++ b/src/boss_mega_maw.cpp @@ -0,0 +1,303 @@ +#include "boss_ai.h" +#include "entity_familiar.h" +#include "npc_caves.h" +#include "room_grid.h" +#include "sfx_manager.h" +#include + +// Mega Maw's subtypes: the red one that only fires rings, and the black one that throws spiders. +constexpr int MEGA_MAW_RED = 1; +constexpr int MEGA_MAW_BLACK = 2; + +// Mega Maw's states: idle, the spit at its target, the ring of shots, and the summon. +constexpr int MEGA_MAW_SPIT = NPC_STATE_ATTACK; +constexpr int MEGA_MAW_RING = NPC_STATE_ATTACK2; +constexpr int MEGA_MAW_SUMMON = NPC_STATE_SUMMON; + +// The summon's phases (i1): the tell, then the summon itself. +enum MegaMawSummon +{ + MEGA_MAW_SUMMON_TELL, + MEGA_MAW_SUMMON_SPAWN +}; + +constexpr int MEGA_MAW_SUMMON_LIMIT = 4; +constexpr int MEGA_MAW_BLACK_SUMMON_LIMIT = 6; +constexpr int MEGA_MAW_DELIRIUM_SUMMON_LIMIT = 3; +constexpr float MEGA_MAW_LIFT = 60; +constexpr float MEGA_MAW_FRICTION = 0.8f; +constexpr float MEGA_MAW_HURT_HEALTH = 0.3f; +constexpr int MEGA_MAW_PERIOD = 20; +constexpr int MEGA_MAW_HURT_PERIOD = 10; +constexpr float MEGA_MAW_SPIT_REACH = 40; +constexpr uint32_t MEGA_MAW_RING_ODDS = 3; + +constexpr int MEGA_MAW_SOUND_DELAY = 60; +constexpr int MEGA_MAW_SPIT_SHOTS = 15; +constexpr float MEGA_MAW_SPIT_STEEP = 0.3f; +constexpr float MEGA_MAW_SPIT_DROP = 100; + +constexpr float MEGA_MAW_RED_SCALE = 1.5f; +constexpr float MEGA_MAW_RED_FALL = -1; +constexpr float MEGA_MAW_DELIRIUM_DAMAGE = 7; +constexpr float MEGA_MAW_RING_SHOTS = 10; +constexpr float MEGA_MAW_ORBIT_SPEED = 15; +constexpr float MEGA_MAW_ORBIT_SHOTS = 9; +constexpr float MEGA_MAW_FULL_TURN = 360; +constexpr float MEGA_MAW_FAN_MIN = 4; +constexpr float MEGA_MAW_FAN_MAX = 10; +constexpr int MEGA_MAW_FAN_WIGGLE = 2; +constexpr float MEGA_MAW_FAN_LIMIT = 0.3f; +constexpr float MEGA_MAW_CURVE_LIMIT = 0.25f; +constexpr float MEGA_MAW_CURVE_STRENGTH = 0.005f; +constexpr float MEGA_MAW_CURVE_FALL = -0.003f; +constexpr std::array MEGA_MAW_RING_SPEEDS = {12, 10, 8, 6}; + +constexpr ColorMod MEGA_MAW_FIRE_COLOR = {{1, 1, 1, 1}, {1.3f, 1, 2, 1}, {0, 0, 0}}; +constexpr float MEGA_MAW_FIRE_HEIGHT = 18.5f; +constexpr float MEGA_MAW_FIRE_ACCEL = -0.06f; +constexpr float MEGA_MAW_FIRE_FALL = -2; +constexpr float MEGA_MAW_FIRE_SPEEDUP = 1.05f; +constexpr float MEGA_MAW_FIRE_SPEED = 10; +constexpr float MEGA_MAW_FIRE_SHOTS = 9; +constexpr float MEGA_MAW_FIRE_INNER_SPEED = 7; +constexpr float MEGA_MAW_FIRE_PAIR_SHOTS = 5; + +constexpr float MEGA_MAW_HOPPER_DROP = 150; +constexpr float MEGA_MAW_HOPPER_REACH = 40; +constexpr int MEGA_MAW_HOPPER_FRAME = 5; +constexpr float MEGA_MAW_SPIDER_HEIGHT = -30; + +// The limit on enemies about it summons under: 4, 6 for the black one, 3 for a Delirium form. +static int mega_maw_summon_limit(Entity_NPC& npc) +{ + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM)) return MEGA_MAW_DELIRIUM_SUMMON_LIMIT; + return npc.subtype == MEGA_MAW_BLACK ? MEGA_MAW_BLACK_SUMMON_LIMIT : MEGA_MAW_SUMMON_LIMIT; +} + +// Idle: on its beat (faster once hurt) it spits at a target well below it one time in four, fires a ring one time in +// three (always for the red one, never for the black one), or one time in two on the double beat summons while the +// room has few enemies. +static void mega_maw_idle(Entity_NPC& npc) +{ + npc.sprite.Play("Idle"); + int period = npc.health / npc.maxHitPoints < MEGA_MAW_HURT_HEALTH ? MEGA_MAW_HURT_PERIOD : MEGA_MAW_PERIOD; + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM) && room_is_clear()) return; + + if (npc.subtype != MEGA_MAW_RED && npc.GetPlayerTarget()->pos.y - MEGA_MAW_SPIT_REACH > npc.pos.y && + npc.IsFrame(period, 0) && (Random() & 3) == 0) + npc.state = MEGA_MAW_SPIT; + else if (npc.subtype == MEGA_MAW_RED || + (npc.subtype != MEGA_MAW_BLACK && npc.IsFrame(period, 0) && Random() % MEGA_MAW_RING_ODDS == 0)) + npc.state = MEGA_MAW_RING; + else + { + int limit = mega_maw_summon_limit(npc); + if (g_game->room->GetAliveEnemiesCount() > limit || !npc.IsFrame(period * 2, 0) || (Random() & 1)) return; + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM)) + { + int minions = npc.subtype == MEGA_MAW_BLACK ? npc.CountRelatedEntities(ENTITY_STRIDER, 0, nullptr) + + npc.CountRelatedEntities(ENTITY_BIG_SPIDER, 0, nullptr) + + npc.CountRelatedEntities(ENTITY_SPIDER, 0, nullptr) + : npc.CountRelatedEntities(ENTITY_HOPPER, 0, nullptr); + if (minions >= limit) return; + } + npc.state = MEGA_MAW_SUMMON; + } + npc.i1 = 0; +} + +// The spit: fifteen shots lobbed at its target, or past it when the target is not well below. +static void mega_maw_spit(Entity_NPC& npc) +{ + npc.sprite.Play("Spit"); + npc.PlaySound(SOUND_LOW_INHALE, 1, MEGA_MAW_SOUND_DELAY, false, 1); + if (!npc.sprite.animState.animData) + { + npc.state = NPC_STATE_IDLE; + return; + } + + if (npc.sprite.IsEventTriggered("Shoot")) + { + Vector target = npc.GetPlayerTarget()->pos; + Vector aim = vector_normalized(vector_sub(target, npc.pos)); + if (aim.x * 0 + aim.y < MEGA_MAW_SPIT_STEEP) target.y += MEGA_MAW_SPIT_DROP; + npc.FireBossProjectiles(MEGA_MAW_SPIT_SHOTS, target, 0, ProjectileParams()); + npc.PlaySound(SOUND_MONSTER_GRUNT_5, 1, 2, false, 1); + } + if (npc_anim_is_done(npc)) npc.state = NPC_STATE_IDLE; +} + +// The red one's rings, one of four at random: an orbiting ring, nested boomerang rings, a fan of rings at its target, +// or nested curving rings, all bigger and slow to fall. +static void mega_maw_red_rings(Entity_NPC& npc) +{ + ProjectileParams params; + bool isDelirium = npc.HasEntityFlags(FLAG_DELIRIUM_FORM); + params.targetPosition = npc.pos; + params.scale *= MEGA_MAW_RED_SCALE; + params.fallingSpeedModifier = MEGA_MAW_RED_FALL; + + switch (Random() & 3) + { + case 0: + params.bulletFlags |= ((Random() & 1) ? PROJECTILE_ORBIT_CCW : PROJECTILE_ORBIT_CW) | + PROJECTILE_NO_WALL_COLLIDE; + if (isDelirium) params.damage = MEGA_MAW_DELIRIUM_DAMAGE; + return npc.FireProjectiles(npc.pos, vector_make(MEGA_MAW_ORBIT_SPEED, MEGA_MAW_ORBIT_SHOTS), + PROJECTILES_RING, params); + case 1: + params.bulletFlags |= PROJECTILE_BOOMERANG; + params.circleAngle = angle_wrap(random_unit() * MEGA_MAW_FULL_TURN); + break; + case 2: + params.bulletFlags |= PROJECTILE_MEGA_WIGGLE | PROJECTILE_NO_WALL_COLLIDE; + params.fireDirectionLimit = vector_normalized(vector_sub(npc.GetPlayerTarget()->pos, npc.pos)); + params.dotProductLimit = MEGA_MAW_FAN_LIMIT; + if (isDelirium) params.damage = MEGA_MAW_DELIRIUM_DAMAGE; + for (float speed = MEGA_MAW_FAN_MIN; speed <= MEGA_MAW_FAN_MAX; speed++) + { + npc.FireProjectiles(npc.pos, vector_make(speed, MEGA_MAW_RING_SHOTS), PROJECTILES_RING, params); + params.wiggleFrameOffset += MEGA_MAW_FAN_WIGGLE; + } + return; + case 3: + params.bulletFlags |= ((Random() & 1) ? PROJECTILE_CURVE_RIGHT : PROJECTILE_CURVE_LEFT) | + PROJECTILE_NO_WALL_COLLIDE; + params.fireDirectionLimit = vector_normalized(vector_sub(npc.GetPlayerTarget()->pos, npc.pos)); + params.dotProductLimit = MEGA_MAW_CURVE_LIMIT; + params.curvingStrength = MEGA_MAW_CURVE_STRENGTH; + params.fallingAccelModifier = MEGA_MAW_CURVE_FALL; + break; + } + if (isDelirium) params.damage = MEGA_MAW_DELIRIUM_DAMAGE; + for (float speed : MEGA_MAW_RING_SPEEDS) + npc.FireProjectiles(npc.pos, vector_make(speed, MEGA_MAW_RING_SHOTS), PROJECTILES_RING, params); +} + +// The fire ring: rising flames orbiting it one way, the other, or both in two rings. +static void mega_maw_fire_ring(Entity_NPC& npc) +{ + npc.PlaySound(SOUND_FIRE_RUSH, 1, 2, false, 1); + ProjectileParams params; + params.variant = PROJECTILE_FIRE; + params.color = MEGA_MAW_FIRE_COLOR; + params.targetPosition = npc.pos; + params.bulletFlags |= PROJECTILE_HIT_ENEMIES | PROJECTILE_NO_WALL_COLLIDE; + params.heightModifier = MEGA_MAW_FIRE_HEIGHT; + params.fallingAccelModifier = MEGA_MAW_FIRE_ACCEL; + params.fallingSpeedModifier = MEGA_MAW_FIRE_FALL; + params.isGridCollision = false; + params.velocityMulti = MEGA_MAW_FIRE_SPEEDUP; + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM)) params.damage = MEGA_MAW_DELIRIUM_DAMAGE; + + Vector ring = vector_make(MEGA_MAW_FIRE_SPEED, MEGA_MAW_FIRE_SHOTS); + switch (Random() & 3) + { + case 0: + params.bulletFlags |= PROJECTILE_ORBIT_CW; + break; + case 1: + params.bulletFlags |= PROJECTILE_ORBIT_CCW; + break; + case 2: + params.bulletFlags |= PROJECTILE_ORBIT_CW; + npc.FireProjectiles(npc.pos, vector_make(MEGA_MAW_FIRE_SPEED, MEGA_MAW_FIRE_PAIR_SHOTS), PROJECTILES_RING, + params); + params.bulletFlags |= PROJECTILE_ORBIT_CCW; + ring = vector_make(MEGA_MAW_FIRE_INNER_SPEED, MEGA_MAW_FIRE_PAIR_SHOTS); + break; + } + npc.FireProjectiles(npc.pos, ring, PROJECTILES_RING, params); +} + +// The ring attack on Shoot: the red one's rings, or a ring of fire. +static void mega_maw_ring(Entity_NPC& npc) +{ + npc.sprite.Play("FireRing"); + if (!npc.sprite.animState.animData) + { + npc.state = NPC_STATE_IDLE; + return; + } + + if (npc.sprite.IsEventTriggered("Shoot")) + { + if (npc.subtype == MEGA_MAW_RED) mega_maw_red_rings(npc); + else mega_maw_fire_ring(npc); + } + if (npc_anim_is_done(npc)) npc.state = NPC_STATE_IDLE; +} + +// The summon: after its tell, a Hopper lands below it, or the black one throws a spider at its target (two, one time +// in two). +static void mega_maw_summon(Entity_NPC& npc) +{ + if (npc.i1 == MEGA_MAW_SUMMON_TELL) + { + npc.sprite.Play("SummonTell"); + npc.PlaySound(SOUND_MOUTH_FULL, 1, MEGA_MAW_SOUND_DELAY, false, 1); + if (npc_anim_is_done(npc)) npc.i1 = MEGA_MAW_SUMMON_SPAWN; + return; + } + if (npc.i1 != MEGA_MAW_SUMMON_SPAWN) return; + + npc.sprite.Play("Summon"); + if (npc.sprite.IsEventTriggered("Shoot")) + { + if (npc.subtype == MEGA_MAW_BLACK) + { + Vector spot = room_free_pickup_position_find({.position = npc.GetPlayerTarget()->pos}); + Entity_NPC::ThrowSpider(npc.pos, &npc, spot, false, MEGA_MAW_SPIDER_HEIGHT); + if ((Random() & 1) == 0) + { + spot = room_free_pickup_position_find({.position = npc.GetPlayerTarget()->pos}); + Entity_NPC::ThrowSpider(npc.pos, &npc, spot, false, MEGA_MAW_SPIDER_HEIGHT); + } + } + else + { + auto* hopper = static_cast( + g_game->Spawn({.position = npc.pos, .spawner = &npc, .type = ENTITY_HOPPER, .seed = Random()})); + Vector below = vector_make(npc.pos.x, npc.pos.y + MEGA_MAW_HOPPER_DROP); + hopper->targetPosition = room_free_pickup_position_find({.position = below, .step = MEGA_MAW_HOPPER_REACH}); + hopper->state = NPC_STATE_MOVE; + hopper->stateFrame = MEGA_MAW_HOPPER_FRAME; + npc_anim_restart(hopper->sprite, "Hop"); + if (hopper->sprite.animState.animData) hopper->sprite.animState.SetFrameFloat(MEGA_MAW_HOPPER_FRAME); + } + npc.PlaySound(SOUND_MONSTER_GRUNT_5, 1, 2, false, 1); + } + if (!npc_anim_is_done(npc)) return; + npc.state = NPC_STATE_IDLE; + npc.i1 = 0; +} + +// 0045ef20 NpcAI::ENTITY_MEGA_MAW: Mega Maw hangs fixed above the floor, spits at a target below it, fires rings of +// fire (or the red one's rings of shots), and summons Hoppers or spiders. +void boss_mega_maw_update(Entity_NPC& npc) +{ + if (npc.state == NPC_STATE_INIT) + { + npc.state = NPC_STATE_IDLE; + npc.stateFrame = 0; + if (npc.deliriumBossType == 0) npc.pos.y -= MEGA_MAW_LIFT; + npc.targetPosition = npc.pos; + return; + } + + npc.friction *= MEGA_MAW_FRICTION; + npc.velocity = vector_sub(npc.targetPosition, npc.pos); + switch (npc.state) + { + case NPC_STATE_IDLE: + return mega_maw_idle(npc); + case MEGA_MAW_SPIT: + return mega_maw_spit(npc); + case MEGA_MAW_RING: + return mega_maw_ring(npc); + case MEGA_MAW_SUMMON: + return mega_maw_summon(npc); + } +} diff --git a/src/boss_mom.cpp b/src/boss_mom.cpp new file mode 100644 index 0000000..2ca61a9 --- /dev/null +++ b/src/boss_mom.cpp @@ -0,0 +1,675 @@ +#include "boss_ai.h" +#include "entity_bomb.h" +#include "entity_config.h" +#include "entity_laser.h" +#include "entity_player.h" +#include "grid_entity_trap_door.h" +#include "entity_tear.h" +#include "npc_caves.h" +#include "room_grid.h" +#include "sfx_manager.h" +#include + +// Mom's colors (her subtype): the plain one, the blue one that summons spiders, the red one that stomps fast and +// shoots from her eyes, and the Mausoleum's that fires lasers. +enum MomSubtype +{ + MOM_PLAIN, + MOM_BLUE, + MOM_RED, + MOM_MAUSOLEUM +}; + +// The foot stomping in the middle of the room (its variant). The parts in the doors keep variant 0. +constexpr int MOM_STOMP = 10; + +// Where Mom's parts look in through the doors: left, top, right and bottom, 15 into the room. +static const std::array MOM_DOOR_SPOTS = {vector_make(40, 280), vector_make(320, 120), + vector_make(600, 280), vector_make(320, 440)}; +constexpr float DOOR_SPOT_REACH = 50; +constexpr float DOOR_SPOT_INSET = 15; +constexpr float PLAYER_NEAR_DOOR = 70; + +// Where the players start: the first in front of the bottom door, the others 20 around it. +static const Vector MOM_PLAYER_START = vector_make(320, 370); +constexpr float MOM_PLAYER_SCATTER = 20; + +// The stomp: a crushing blast, a ripple and grey dust. Hard stomps come 1 in 15 instead of 1 in 40, every stomp in +// the first two seconds, and laughs instead one time in three or with a player near a door. +constexpr float STOMP_DAMAGE = 300; +constexpr float STOMP_RADIUS = 50; +constexpr float STOMP_RIPPLE_AMPLITUDE = 0.04f; +constexpr float STOMP_RIPPLE_SPEED = 0.25f; +constexpr int STOMP_RIPPLE_FRAMES = 13; +constexpr ColorMod STOMP_DUST_COLOR = {{0.62f, 0.62f, 0.62f, 0.8f}, {0, 0, 0, 0}, {0, 0, 0}}; +constexpr ColorMod QUICK_STOMP_FLASH = {{1, 1, 1, 1}, {0, 0, 0, 0}, {1, 0.2f, 0.2f}}; +constexpr int QUICK_STOMP_FLASH_FRAMES = 8; +constexpr int STOMP_ODDS = 40; +constexpr int STOMP_ODDS_RED = 15; +constexpr int ROOM_SETTLE_FRAMES = 6; +constexpr int ROOM_START_FRAMES = 60; +constexpr int STOMP_COOLDOWN = 80; +constexpr int STOMP_COOLDOWN_RED = 50; +constexpr int QUICK_STOMP_COOLDOWN = 180; +constexpr int QUICK_STOMPS = 2; +constexpr int LAUGH_COOLDOWN = 30; +constexpr int LAUGH_DELAY_MIN = 45; +constexpr uint32_t LAUGH_DELAY_SPREAD = 120; +constexpr float QUICK_STOMP_PULL = 0.2f; +constexpr int CRACKWAVES = 4; +constexpr int CRACKWAVE_MOM = 10; + +// The red Mom's stomp skips from frame 10, and again over frames 40 to 49. +constexpr float RED_STOMP_START = 10; +constexpr int RED_STOMP_SKIP_FROM = 39; +constexpr int RED_STOMP_SKIP_TO = 50; +constexpr int RED_STOMP_SKIP = 10; + +// The parts in the doors: an arm reaches for a player within 46 across and 90 out from the door (10 frames ahead), +// an eye looks one check in 100, a summon one in 50 (in 4 or 5 with few enemies). +constexpr int PART_CHECK_FRAMES = 4; +constexpr float ARM_REACH_ACROSS = 46; +constexpr float ARM_REACH_OUT = 90; +constexpr float PLAYER_LEAD_FRAMES = 10; +constexpr uint32_t ARM_ODDS_MASK = 7; +constexpr float ARM_SIZE_SCALE = 1.35f; +constexpr float ARM_SLAP_REACH = 45; +constexpr float ARM_SLAP_RADIUS = 35; +constexpr float ARM_SLAP_DAMAGE = 25; +constexpr float ARM_SLAP_STRONG = 50; +constexpr float ARM_VOLUME = 1.5f; +constexpr uint32_t EYE_ODDS = 100; +constexpr uint32_t MOM_SUMMON_ODDS = 50; +constexpr int SUMMON_CROWD = 7; +constexpr int SUMMON_CROWD_SOON = 5; +constexpr int SUMMON_COOLDOWN = 100; +constexpr float SUMMON_DOOR_DEPTH = 18; +constexpr float SUMMON_VOLUME_MIN = 0.8f; +constexpr float SUMMON_VOLUME_SPREAD = 0.4f; +constexpr int EYE_COOLDOWN_RED = 100; +constexpr int EYE_SHOT_SETTLE_FRAMES = 121; +constexpr float EYE_SHOT_SPEED = 10; + +// The Mausoleum's eye lasers: two beams that sweep 6 apart, then 12 the other way after 5 and back after 15 frames. +constexpr int EYE_LASER_VARIANT = 1; +constexpr int EYE_LASER_TIMEOUT = 20; +constexpr float EYE_LASER_SWEEP = 6; +constexpr float EYE_LASER_SWEEP_SPEED = 2; +constexpr float EYE_LASER_TURN = 12; +constexpr float EYE_LASER_DEPTH = 1000; +constexpr uint32_t EYE_LASER_TURN_FRAMES = 5; +constexpr uint32_t EYE_LASER_BACK_FRAMES = 15; + +// Mom's death: every enemy left takes 100, and blood runs down the walls. +constexpr float DEATH_DAMAGE = 100; +constexpr int DEATH_DAMAGE_COUNTDOWN = 30; +constexpr int DEATH_BLOOD_FRAMES = 20; +constexpr int DEATH_BLOOD_DROPS = 6; + +// Her voice when hurt by more than 10 to 29 at once, 25 to 54 frames later, higher for a tiny Mom, lower for a giant. +constexpr int HURT_VOICE_MIN = 10; +constexpr uint32_t HURT_VOICE_SPREAD = 20; +constexpr int HURT_VOICE_DELAY = 25; +constexpr uint32_t HURT_VOICE_DELAY_SPREAD = 30; +constexpr int LAUGH_START_DELAY = 45; +constexpr float MOM_TINY_PITCH = 1.5f; +constexpr float MOM_GIANT_PITCH = 0.5f; + +// The enemies each color calls through a door, as type and variant. +constexpr std::array, 12> MOM_SUMMONS = { + {{10, 0}, {11, 0}, {12, 0}, {14, 0}, {15, 0}, {16, 0}, {18, 0}, {21, 0}, {23, 0}, {24, 0}, {26, 0}, {26, 1}}}; +constexpr std::array, 5> MOM_SUMMONS_BLUE = {{{85, 0}, {94, 0}, {89, 0}, {86, 0}, {29, 1}}}; +constexpr std::array, 6> MOM_SUMMONS_MAUSOLEUM = { + {{18, 0}, {61, 0}, {248, 0}, {886, 1}, {246, 1}, {24, 3}}}; +constexpr std::pair CURSED_GLOBIN = {24, 3}; +constexpr int CURSED_GLOBINS_MAX = 2; +constexpr int ENTITY_ATTACK_FLY = 18; + +// DamageRadius hurts with a 30 frame countdown, and passes 3.5 to the tear effects. Enemies are types 10 to 999. +constexpr int RADIUS_DAMAGE_COUNTDOWN = 30; +constexpr float RADIUS_TEAR_DAMAGE = 3.5f; +constexpr int ENTITY_NPC_FIRST = 10; +constexpr int ENTITY_NPC_LAST = 999; + +// 006fed60 Game::DamageRadius: everything collidable within reach of a spot is hurt, players and familiars by 1 (2 +// for a hit of the threshold or more) unless a friendly enemy dealt it, enemies (with the tear effects) only when a +// player, a familiar, a charmed or friendly source or the caller asks. Poison spares a player immune to it. +void damage_radius(const RadiusDamage& hit) +{ + Entity* source = hit.source; + EntityRef sourceRef(source); + bool isPlayerSource = source && (source->type == ENTITY_PLAYER || + (source->type == ENTITY_FAMILIAR && !source->HasEntityFlags(FLAG_CHARM))); + bool isHitPlayers = isPlayerSource ? hit.isHitAll : !(source && source->HasEntityFlags(FLAG_FRIENDLY)); + bool isAllied = source && (isPlayerSource || source->HasEntityFlags(FLAG_CHARM) || + source->HasEntityFlags(FLAG_FRIENDLY)); + bool isDamageEnemies = isAllied || hit.isHitAll; + + for (Entity* entity : entity_query_radius(hit.position, hit.radius, QUERY_ALL)) + { + if (entity->entityCollisionClass == ENTCOLL_NONE) continue; + + bool isPlayerSide = entity->type == ENTITY_PLAYER || entity->type == ENTITY_FAMILIAR; + if (isPlayerSide && isHitPlayers) + { + bool isPoisonSpared = hit.tearFlags[TEAR_POISON] && entity->type == ENTITY_PLAYER && + static_cast(entity)->HasPoisonImmunity(); + if (isPoisonSpared) continue; + float damage = hit.damage < hit.playerDamageThreshold ? 1 : 2; + entity->TakeDamage(damage, hit.damageFlags, sourceRef, RADIUS_DAMAGE_COUNTDOWN); + } + else if (entity->type >= ENTITY_NPC_FIRST && entity->type <= ENTITY_NPC_LAST && isDamageEnemies) + { + entity->TakeDamage(hit.damage, hit.damageFlags, sourceRef, RADIUS_DAMAGE_COUNTDOWN); + Entity_Tear::ApplyTearFlagEffects(entity, hit.position, hit.tearFlags, source, RADIUS_TEAR_DAMAGE); + } + } +} + +// The frames since the room started, or -1 before it did. +static int room_frames_get() +{ + Room& room = *g_game->room; + return room.isInitialized ? g_game->frameCount - room.enterFrame : -1; +} + +// The pitch Mom's voice takes for her champion size. +static float voice_pitch_get(Entity_NPC& npc) +{ + if (npc.championColorIdx == CHAMPION_TINY) return MOM_TINY_PITCH; + if (npc.championColorIdx == CHAMPION_GIANT) return MOM_GIANT_PITCH; + return 1; +} + +// The Mausoleum's Mom wears the "_mausoleum" spritesheet on every layer but the shadow. +static void mausoleum_sheets_load(ANM2& sprite) +{ + for (int i = 0; i < (int)sprite.layerStates.size(); i++) + { + if (i == sprite.shadowLayerIndex) continue; + + const LayerData* data = sprite.GetLayer(i)->layerData; + // A layer with no sheet would trim past its empty path in the original. Here it is skipped. + if (!data || data->spriteSheetPath.size() < 4) continue; + std::string path = data->spriteSheetPath; + path.resize(path.size() - 4); + sprite.ReplaceSpritesheet(i, path + "_mausoleum.png"); + } + sprite.LoadGraphics(); +} + +// The foot takes every other part of Mom without a parent as its own, numbering them from 1 and giving them its color. +static void parts_gather(Entity_NPC& foot) +{ + int index = 1; + for (Entity* entity : entity_query(ENTITY_MOM, -1)) + { + auto* part = static_cast(entity); + if (part == &foot || part->parent) continue; + + part->Morph(part->type, part->variant, foot.subtype, -1); + part->health = part->maxHitPoints; + part->parent = &foot; + part->i1 = index++; + } +} + +// Every player stands in front of the bottom door: the first right there, the others scattered around it. +static void players_place() +{ + PlayerManager& players = g_game->playerManager; + for (size_t i = 0; i < players.playerList.size(); i++) + { + Vector spot = MOM_PLAYER_START; + if (i != 0) spot = vector_add(MOM_PLAYER_START, vector_scale(random_direction(), MOM_PLAYER_SCATTER)); + players.playerList[i]->Teleport(spot, false, false); + } +} + +// The first frame: a part placed in a door turns to face the room and sinks 15 into it. The one in the middle +// becomes the foot (unless spawned as a part of another), gathers the rest and puts the players at the bottom. +static void mom_init(Entity_NPC& npc) +{ + npc_sound_play(SOUND_MOM_VOX_ISAAC, 1, LAUGH_START_DELAY, voice_pitch_get(npc)); + npc.AddEntityFlags(FLAG_NO_DEATH_TRIGGER); + if (npc.variant == MOM_STOMP) + { + npc.health = npc.maxHitPoints; + npc.i1 = 0; + npc.projectileDelay = 0; + npc.targetPosition = npc.pos; + npc.state = NPC_STATE_IDLE; + npc.shadowSize = 0; + npc.entityCollisionClass = ENTCOLL_NONE; + npc.entityGridCollisionClass = GRIDCOLL_GROUND; + return; + } + + bool isFoot = true; + for (int i = 0; i < (int)MOM_DOOR_SPOTS.size(); i++) + { + Vector toSpot = vector_sub(MOM_DOOR_SPOTS[i], npc.pos); + if (vector_length_squared(toSpot) >= DOOR_SPOT_REACH * DOOR_SPOT_REACH) continue; + + float angle = (float)i * 90; + npc.sprite.rotation = angle - 90; + npc.entityGridCollisionClass = GRIDCOLL_NONE; + npc.pos = vector_add(MOM_DOOR_SPOTS[i], vector_scale(vector_from_angle(angle), DOOR_SPOT_INSET)); + npc.ClearEntityFlags(FLAG_APPEAR); + isFoot = false; + break; + } + npc.targetPosition = npc.pos; + + if (!npc.parent && isFoot) + { + npc.Morph(npc.type, MOM_STOMP, npc.subtype, -1); + npc.health = npc.maxHitPoints; + npc.i1 = 0; + npc.projectileDelay = 0; + parts_gather(npc); + } + if (npc.subtype == MOM_MAUSOLEUM) mausoleum_sheets_load(npc.sprite); + npc.shadowSize = 0; + npc.entityCollisionClass = ENTCOLL_NONE; + if (isFoot) + { + players_place(); + npc.entityGridCollisionClass = GRIDCOLL_GROUND; + } + npc.state = NPC_STATE_IDLE; +} + +// The stomp's landing: a crushing blast where the foot came down and a ripple through the room. +static void stomp_land(Entity_NPC& npc) +{ + npc.PlaySound(SOUND_HELLBOSS_GROUNDPOUND, 1, 2, false, 1); + explosion_damage({.position = npc.pos, + .source = &npc, + .damageFlags = DAMAGE_CRUSH, + .damage = STOMP_DAMAGE, + .radius = STOMP_RADIUS, + .isLineCheck = false}); + shockwave_make(npc.pos, STOMP_RIPPLE_AMPLITUDE, STOMP_RIPPLE_SPEED, STOMP_RIPPLE_FRAMES); +} + +// Whether a player stands within 70 of a door, where Mom's parts guard instead of the foot. +static bool is_player_near_door(Entity_NPC& npc) +{ + for (const Vector& spot : MOM_DOOR_SPOTS) + { + Vector toPlayer = vector_sub(npc.GetPlayerTarget()->pos, spot); + if (vector_length_squared(toPlayer) < PLAYER_NEAR_DOOR * PLAYER_NEAR_DOOR) return true; + } + return false; +} + +// The foot's next move from rest: a stomp on its target (one where it stands while the room starts), a run of quick +// stomps for the Mausoleum's, or a laugh when the roll or a player near a door says no. +static void stomp_start(Entity_NPC& npc) +{ + int roomFrames = room_frames_get(); + bool isStarting = roomFrames < ROOM_START_FRAMES; + bool isWanted = Random() % 3 == 0 || npc.subtype == MOM_RED || isStarting; + if (!isStarting && (!isWanted || is_player_near_door(npc))) + { + npc.PlaySound(SOUND_MOM_VOX_ISAAC, 1, LAUGH_DELAY_MIN + (int)(Random() % LAUGH_DELAY_SPREAD), false, 1); + npc.projectileCooldown = LAUGH_COOLDOWN; + return; + } + + npc.PlaySound(SOUND_MOM_VOX_GRUNT, 1, 2, false, 1); + npc.targetPosition = isStarting ? npc.pos : npc.GetPlayerTarget()->pos; + npc.pos = npc.targetPosition; + if (npc.subtype == MOM_MAUSOLEUM && !isStarting && npc.projectileDelay <= 0) + { + npc_anim_restart(npc.sprite, "QuickStompBegin"); + npc.state = NPC_STATE_JUMP; + npc.i2 = QUICK_STOMPS; + npc.projectileCooldown = QUICK_STOMP_COOLDOWN; + return; + } + + npc_anim_restart(npc.sprite, "Stomp"); + npc.state = NPC_STATE_STOMP; + npc.stateFrame = 0; + npc.projectileCooldown = STOMP_COOLDOWN; + if (npc.subtype != MOM_RED) return; + + if (npc.sprite.animState.animData) npc.sprite.animState.SetFrameFloat(RED_STOMP_START); + npc.stateFrame = (int)RED_STOMP_START; + npc.projectileCooldown = STOMP_COOLDOWN_RED; + npc.projectileDelay = 0; +} + +// A stomp: the foot is solid from its landing until it lifts, and the red Mom's skips ahead. +static void stomp_update(Entity_NPC& npc) +{ + ANM2& sprite = npc.sprite; + npc.pos = npc.targetPosition; + bool isDown = sprite.animState.animData && sprite.WasEventTriggered("Shoot") && !sprite.WasEventTriggered("Lift"); + npc.entityCollisionClass = isDown ? ENTCOLL_ALL : ENTCOLL_NONE; + if (sprite.animState.animData && sprite.IsEventTriggered("Shoot")) + { + stomp_land(npc); + npc.MakeGroundPoof(npc.pos, STOMP_DUST_COLOR, 1); + } + + npc.stateFrame += npc_ticks_get(npc); + int frame = sprite.GetFrame(); + if (npc.subtype != MOM_RED || frame <= RED_STOMP_SKIP_FROM || frame >= RED_STOMP_SKIP_TO) return; + + if (sprite.animState.animData) sprite.animState.SetFrameFloat(RED_STOMP_SKIP_TO); + npc.stateFrame += RED_STOMP_SKIP; +} + +// The next of the quick stomps, the last one's end, or rest once they are done. +static void quick_stomp_next(Entity_NPC& npc) +{ + if (npc.i2 < 1) + { + npc.state = NPC_STATE_IDLE; + return; + } + npc.i2--; + npc_anim_restart(npc.sprite, npc.i2 != 0 ? "QuickStomp" : "QuickStompEnd"); +} + +// The Mausoleum's quick stomps: each landing crushes, the last sends four crackwaves out, and between them the foot +// slides to its target, flashing red before the last. +static void quick_stomp_update(Entity_NPC& npc) +{ + ANM2& sprite = npc.sprite; + if (!sprite.animState.animData) quick_stomp_next(npc); + else + { + if (sprite.IsEventTriggered("Shoot")) + { + npc.entityCollisionClass = ENTCOLL_ALL; + stomp_land(npc); + npc.targetPosition = npc.pos; + if (npc.i2 == 0) + { + npc.MakeBloodPoof(npc.pos, COLOR_DEFAULT, 1); + for (int i = 0; i < CRACKWAVES; i++) + { + auto* wave = static_cast(g_game->Spawn({.position = npc.pos, + .spawner = &npc, + .subType = CRACKWAVE_MOM, + .type = ENTITY_EFFECT, + .variant = EFFECT_CRACKWAVE, + .seed = Random()})); + wave->parent = &npc; + wave->rotation = (float)i * 90; + } + } + else npc.MakeGroundPoof(npc.pos, STOMP_DUST_COLOR, 1); + } + if (sprite.IsEventTriggered("Lift")) + { + npc.entityCollisionClass = ENTCOLL_NONE; + if (npc.i2 > 0) + { + npc.targetPosition = npc.GetPlayerTarget()->pos; + if (npc.i2 == 1) npc.SetColor(QUICK_STOMP_FLASH, QUICK_STOMP_FLASH_FRAMES, 255, true, true); + } + } + if (npc_anim_is_done(npc)) quick_stomp_next(npc); + } + + if (npc.entityCollisionClass == ENTCOLL_NONE) + npc.velocity = vector_scale(vector_sub(npc.targetPosition, npc.pos), QUICK_STOMP_PULL); + else npc.pos = npc.targetPosition; +} + +// Mom's death: every enemy left in the room takes 100, blood runs down the walls, and the death counts again. +static void mom_death(Entity_NPC& npc) +{ + npc.PlaySound(SOUND_MOM_VOX_DEATH, 1, 2, false, 1); + Room& room = *g_game->room; + EntityList_EL& entities = room.entityList.updateEL; + for (size_t i = 0; i < entities.size(); i++) + if (entities[i]->CanShutDoors()) entities[i]->TakeDamage(DEATH_DAMAGE, 0, EntityRef(), DEATH_DAMAGE_COUNTDOWN); + room.bloodFromWallsDuration = DEATH_BLOOD_FRAMES; + room.bloodFromWallsCount = DEATH_BLOOD_DROPS; + npc.ClearEntityFlags(FLAG_NO_DEATH_TRIGGER); +} + +// The foot: from rest it stomps when its cooldown is out, then plays out the stomp. +static void foot_update(Entity_NPC& npc) +{ + int roomFrames = room_frames_get(); + int odds = npc.subtype == MOM_RED ? STOMP_ODDS_RED : STOMP_ODDS; + bool isReady = npc.projectileCooldown == 0 && roomFrames > ROOM_SETTLE_FRAMES && + (random_below(odds) == 0 || roomFrames < ROOM_START_FRAMES) && npc.state == NPC_STATE_IDLE; + if (isReady) stomp_start(npc); + + if (npc.state == NPC_STATE_STOMP) stomp_update(npc); + else if (npc.state == NPC_STATE_JUMP) quick_stomp_update(npc); + else + { + npc.pos = npc.targetPosition; + npc.shadowSize = 0; + npc.entityCollisionClass = ENTCOLL_NONE; + } + if (npc.isDead) mom_death(npc); +} + +// Sets an eye laser sweeping at once by an angle each frame at a speed, if it is still a laser. +static void eye_laser_sweep(Entity* entity, float degrees, float speed) +{ + if (!entity || entity->type != ENTITY_LASER) return; + + auto* laser = static_cast(entity); + laser->isActiveRotating = true; + laser->rotationDelay = 0; + laser->rotationDegrees = degrees; + laser->rotationSpd = speed; +} + +// 004d2f50 The eye lasers' first turn: the first sweeps back, the second on. +static void eye_lasers_turn(Entity_Effect* timer) +{ + eye_laser_sweep(timer->child, -EYE_LASER_TURN, -EYE_LASER_SWEEP_SPEED); + eye_laser_sweep(timer->target, EYE_LASER_TURN, EYE_LASER_SWEEP_SPEED); +} + +// 004d2fd0 The eye lasers' second turn, the other way. +static void eye_lasers_back(Entity_Effect* timer) +{ + eye_laser_sweep(timer->child, EYE_LASER_TURN, EYE_LASER_SWEEP_SPEED); + eye_laser_sweep(timer->target, -EYE_LASER_TURN, -EYE_LASER_SWEEP_SPEED); +} + +// Fires the Mausoleum's two eye lasers out of the door, sweeping apart, with timers to turn them. +static void eye_lasers_fire(Entity_NPC& npc) +{ + float angle = npc.sprite.rotation + 90; + float depth = std::sin(angle * DEGREES_TO_RADIANS) >= 0 ? EYE_LASER_DEPTH : 0; + std::array lasers{}; + for (int i = 0; i < 2; i++) + { + float side = i == 0 ? 1 : -1; + lasers[i] = Entity_Laser::ShootAngle({.position = npc.pos, + .source = &npc, + .angleDegrees = angle, + .timeout = EYE_LASER_TIMEOUT, + .variant = EYE_LASER_VARIANT}); + lasers[i]->renderDepthOffset = depth; + eye_laser_sweep(lasers[i], side * EYE_LASER_SWEEP, side * EYE_LASER_SWEEP_SPEED); + lasers[i]->Update(); + } + + Entity_Effect* turn = Entity_Effect::CreateTimer(reinterpret_cast(&eye_lasers_turn), EYE_LASER_TURN_FRAMES, + 0, false); + turn->child = lasers[0]; + turn->target = lasers[1]; + Entity_Effect* back = Entity_Effect::CreateTimer(reinterpret_cast(&eye_lasers_back), EYE_LASER_BACK_FRAMES, + 0, false); + back->child = lasers[0]; + back->target = lasers[1]; +} + +// A summon through the door: an enemy of the color's list 18 into the room, the Mausoleum's cursed Globins at most +// two (then an attack fly). +static void part_summon(Entity_NPC& npc) +{ + Vector inward = vector_resized(vector_sub(npc.pos, Room::GetCenterPos()), SUMMON_DOOR_DEPTH); + std::pair summon; + if (npc.subtype == MOM_MAUSOLEUM) + { + summon = MOM_SUMMONS_MAUSOLEUM[Random() % MOM_SUMMONS_MAUSOLEUM.size()]; + bool isCrowded = summon == CURSED_GLOBIN && + entity_query(CURSED_GLOBIN.first, CURSED_GLOBIN.second).size() >= CURSED_GLOBINS_MAX; + if (isCrowded) summon = {ENTITY_ATTACK_FLY, 0}; + } + else if (npc.subtype == MOM_BLUE) summon = MOM_SUMMONS_BLUE[Random() % MOM_SUMMONS_BLUE.size()]; + else summon = MOM_SUMMONS[Random() % MOM_SUMMONS.size()]; + + npc.PlaySound(SOUND_SUMMONSOUND, random_unit() * SUMMON_VOLUME_SPREAD + SUMMON_VOLUME_MIN, 2, false, 1); + g_game->Spawn({.position = vector_sub(npc.pos, inward), + .spawner = &npc, + .type = summon.first, + .variant = summon.second, + .seed = Random()}); + npc.projectileCooldown = SUMMON_COOLDOWN; +} + +// Whether a player (10 frames ahead) is in an arm's reach of the door, measured along the part's facing. +static bool is_player_in_arm_reach(Entity_NPC& npc) +{ + Entity* target = npc.GetPlayerTarget(); + Vector ahead = vector_add(target->pos, vector_scale(target->velocity, PLAYER_LEAD_FRAMES)); + Vector away = vector_sub(npc.pos, ahead); + float angle = -npc.sprite.rotation * DEGREES_TO_RADIANS; + float across = away.x * std::cos(angle) - away.y * std::sin(angle); + float out = away.y * std::cos(angle) + away.x * std::sin(angle); + return std::abs(across) <= ARM_REACH_ACROSS && std::abs(out) <= ARM_REACH_OUT; +} + +// Every 4 frames once the room has run a second, a part picks what to do from rest: an arm for a player in reach +// (1 in 8, never the Mausoleum's or while the foot stomps), else 1 in 100 an eye (a laser one for the Mausoleum's), +// else sometimes a summon. +static void part_choose(Entity_NPC& npc) +{ + Entity_NPC& foot = *npc.ParentNPC(); + int roomFrames = room_frames_get(); + bool isSettled = roomFrames > ROOM_START_FRAMES; + bool isArmReady = npc.state != NPC_STATE_ATTACK2 && npc.state != NPC_STATE_ATTACK4 && + foot.state != NPC_STATE_STOMP && foot.state != NPC_STATE_JUMP && npc.subtype != MOM_MAUSOLEUM; + if (is_player_in_arm_reach(npc) && isArmReady && (Random() & ARM_ODDS_MASK) == 0 && isSettled) + { + npc_anim_restart(npc.sprite, "ArmOpen"); + npc.state = NPC_STATE_ATTACK2; + npc.SetSize(npc.config->collisionRadius * ARM_SIZE_SCALE, npc.config->collisionRadiusMulti, + npc.config->gridCollisionPoints); + return; + } + + bool isEyeFree = npc.subtype == MOM_RED ? foot.projectileDelay < 1 && foot.projectileCooldown == 0 + : foot.projectileDelay < 2; + if (Random() % EYE_ODDS == 0 && npc.state == NPC_STATE_IDLE && isEyeFree) + { + bool isLaser = npc.subtype == MOM_MAUSOLEUM && foot.state != NPC_STATE_JUMP && isSettled; + npc_anim_restart(npc.sprite, isLaser ? "EyeLaser" : "Eye"); + foot.projectileDelay++; + npc.state = isLaser ? NPC_STATE_ATTACK4 : NPC_STATE_ATTACK; + if (npc.subtype == MOM_RED) foot.projectileCooldown = EYE_COOLDOWN_RED; + return; + } + + int enemies = g_game->room->GetAliveEnemiesCount(); + bool isSummonRolled = enemies <= SUMMON_CROWD && Random() % MOM_SUMMON_ODDS == 0; + if (!isSummonRolled && (enemies > SUMMON_CROWD_SOON || random_below(4 + (npc.subtype == MOM_MAUSOLEUM)) != 0)) + return; + bool isSummonFree = npc.projectileCooldown < 1 && npc.state != NPC_STATE_ATTACK4 && foot.projectileCooldown == 0; + if (isSummonFree && isSettled && npc.subtype != MOM_RED) + { + npc.sprite.Play(Random() & 1 ? "Fat02" : "Fat01"); + npc.state = NPC_STATE_ATTACK3; + } +} + +// A part in a door: it shares the foot's health, dies with it, and slaps, looks, shoots or summons from there. +static void part_update(Entity_NPC& npc, int prevState) +{ + Entity_NPC& foot = *npc.ParentNPC(); + npc.pos = npc.targetPosition; + if (foot.health > npc.health) foot.health = npc.health; + else npc.health = foot.health; + if (npc.isDead) foot.Kill(EntityRef()); + + ANM2& sprite = npc.sprite; + if (npc.state == NPC_STATE_ATTACK2 && sprite.animState.animData && sprite.IsEventTriggered("Appear")) + { + npc.PlaySound(SOUND_FORESTBOSS_STOMPS, ARM_VOLUME, 2, false, 1); + Vector reach = vector_scale(vector_from_angle(npc.sprite.rotation + 90), ARM_SLAP_REACH); + damage_radius({.position = vector_add(npc.pos, reach), + .source = &npc, + .damage = ARM_SLAP_DAMAGE, + .playerDamageThreshold = ARM_SLAP_STRONG, + .radius = ARM_SLAP_RADIUS}); + } + if (npc.state != NPC_STATE_ATTACK2 && npc.size > npc.config->collisionRadius) + npc.SetSize(npc.config->collisionRadius, npc.config->collisionRadiusMulti, npc.config->gridCollisionPoints); + + if (npc.IsFrame(PART_CHECK_FRAMES, (int)npc.index) && room_frames_get() > ROOM_START_FRAMES) part_choose(npc); + + if (npc.state == NPC_STATE_IDLE) npc.entityCollisionClass = ENTCOLL_NONE; + else + { + bool isOut = sprite.animState.animData && sprite.WasEventTriggered("Appear") && + !sprite.WasEventTriggered("Disappear"); + npc.entityCollisionClass = isOut ? ENTCOLL_ALL : ENTCOLL_NONE; + if (npc.state == NPC_STATE_ATTACK3 && sprite.animState.animData && sprite.IsEventTriggered("Shoot")) + part_summon(npc); + bool isEyeShot = npc.state == NPC_STATE_ATTACK && npc.subtype == MOM_RED && + room_frames_get() >= EYE_SHOT_SETTLE_FRAMES && sprite.IsEventTriggered("Shoot"); + if (isEyeShot) + { + Vector velocity = vector_resized(vector_sub(npc.GetPlayerTarget()->pos, npc.pos), EYE_SHOT_SPEED); + npc.FireProjectiles(vector_add(npc.pos, velocity), velocity, PROJECTILES_THREE, ProjectileParams()); + } + } + if (npc.state == NPC_STATE_ATTACK4 && sprite.IsEventTriggered("Shoot")) eye_lasers_fire(npc); + + bool isEyeDone = prevState != npc.state && (prevState == NPC_STATE_ATTACK || prevState == NPC_STATE_ATTACK4); + if (isEyeDone && npc.subtype != MOM_RED) foot.projectileDelay--; +} + +// 004d1290 NpcAI::ENTITY_MOM: Mom's foot stomping in the middle of the room and her eyes and arms in the doors. +// Big hits make her cry out, a part whose foot is gone dies, and her own blasts never hurt her. +void boss_mom_update(Entity_NPC& npc) +{ + if ((float)(Random() % HURT_VOICE_SPREAD + HURT_VOICE_MIN) < npc.pendingDamage) + { + int delay = (int)(Random() % HURT_VOICE_DELAY_SPREAD) + HURT_VOICE_DELAY; + npc_sound_play(SOUND_MOM_VOX_HURT, 1, delay, voice_pitch_get(npc)); + } + + int prevState = npc.state; + bool isFootGone = npc.i1 != 0 && (!npc.parent || npc.parent->isDead); + if (npc.state == NPC_STATE_INIT) + { + bool isFootSpawned = npc.variant == MOM_STOMP; + mom_init(npc); + if (isFootSpawned) return; + } + else if (isFootGone) npc.Kill(EntityRef()); + else + { + if (npc_anim_is_done(npc) && prevState != NPC_STATE_JUMP) npc.state = NPC_STATE_IDLE; + if (npc.i1 == 0) foot_update(npc); + else part_update(npc, prevState); + } + + if (prevState != NPC_STATE_INIT) + { + if (npc.projectileCooldown > 0) npc.projectileCooldown = std::max(npc.projectileCooldown - npc_ticks_get(npc), 0); + npc.friction *= 0.8f; + } + if (npc.pendingDamage <= 0) return; + + for (DamageEvent& event : npc.damageEvents) + if (event.source.type == ENTITY_MOM) event.damage = 0; +} diff --git a/src/boss_peep.cpp b/src/boss_peep.cpp new file mode 100644 index 0000000..352e4ff --- /dev/null +++ b/src/boss_peep.cpp @@ -0,0 +1,514 @@ +#include "boss_ai.h" +#include "entity_laser.h" +#include "entity_player.h" +#include "grid_entity_trap_door.h" +#include "manager.h" +#include "npc_caves.h" +#include "room_descriptor.h" +#include "room_grid.h" +#include "sfx_manager.h" +#include +#include + +// Peep (variant 0) and the Bloat (variant 1), their yellow/green subtype, and their eyes (variant + 10). An eye of +// subtype 99 lives on its own until the room is won. +constexpr int BLOAT = 1; +constexpr int PEEP_EYE_FIRST = 10; +constexpr int PEEP_YELLOW = 1; +constexpr int PEEP_LONE_EYE = 99; + +// Peep's states: walking, the jump up and its landing, the spit, the Bloat's two lasers, and the spray. +constexpr int PEEP_JUMP_UP = NPC_STATE_JUMP; +constexpr int PEEP_JUMP_DOWN = NPC_STATE_STOMP; +constexpr int PEEP_SPIT = NPC_STATE_ATTACK; +constexpr int BLOAT_LASER_DOWN = NPC_STATE_ATTACK2; +constexpr int BLOAT_LASER_SIDES = NPC_STATE_ATTACK3; +constexpr int PEEP_SPRAY = NPC_STATE_SUMMON; + +constexpr ColorMod PEEP_BLOOD_COLOR = {{1, 1, 1, 0.9f}, {3, 3, 0, 1}, {0, 0, 0}}; +constexpr ColorMod BLOAT_GREEN_BLOOD_COLOR = {{1, 1, 1, 0.9f}, {0.5f, 3, 0, 1}, {0, 0, 0}}; +constexpr ColorMod PEEP_SHOT_COLOR = {{1, 1, 1, 1}, {1.2f, 1.2f, 0.2f, 1}, {60 / 255.0f, 60 / 255.0f, 0}}; +constexpr ColorMod PEEP_BIG_SHOT_COLOR = {{1, 1, 1, 1}, {0.4f, 2, 0.5f, 1}, {0, 0, 0}}; +constexpr ColorMod PEEP_SPLAT_COLOR = {{0, 0, 0, 0.7f}, {0, 0, 0, 0}, {200 / 255.0f, 200 / 255.0f, 0}}; +constexpr ColorMod BLOAT_TRACER_COLOR = {{0.6f, 0.05f, 0, 0.8f}, {0, 0, 0, 0}, {0, 0, 0}}; +constexpr ColorMod BLOAT_GREEN_TRACER_COLOR = {{0.32941f, 0.33333f, 0.24313f, 0.8f}, {0, 0, 0, 0}, {0, 0, 0}}; + +constexpr float BLOAT_TWIN_REACH = 40; +constexpr float PEEP_FRICTION = 0.6f; +constexpr float PEEP_YELLOW_FRICTION = 0.8f; +constexpr int PEEP_CREEP_TICKS = 13; +constexpr float PEEP_CREEP_SCALE = 1.6f; +constexpr uint32_t PEEP_YELLOW_CALM_ODDS = 3; +constexpr uint32_t PEEP_JUMP_ODDS = 23; +constexpr uint32_t PEEP_ATTACK_ODDS = 20; +constexpr float PEEP_LEAD = 5; +constexpr float BLOAT_SIDE_LINE = 40; +constexpr float BLOAT_SIDE_REACH = 20; +constexpr float BLOAT_DOWN_REACH = 40; +constexpr int BLOAT_TRACER_TIMEOUT = 12; +constexpr float BLOAT_TRACER_SCALE = 4; +constexpr float BLOAT_SIDE_TRACER_X = 20; +constexpr float BLOAT_SIDE_TRACER_Y = -80; +constexpr float BLOAT_DOWN_TRACER_X = 15; +constexpr float BLOAT_DOWN_TRACER_Y = -40; + +constexpr float PEEP_JUMP_SPEED = 0.033f; +constexpr float PEEP_SHOCKWAVE_AMPLITUDE = 0.035f; +constexpr float PEEP_SHOCKWAVE_SPEED = 0.025f; +constexpr int PEEP_SHOCKWAVE_FRAMES = 10; +constexpr int BLOAT_LAND_CREEPS = 10; +constexpr float BLOAT_LAND_CREEP_REACH = 100; +constexpr float BLOAT_CREEP_SCALE = 2; +constexpr float PEEP_SHOT_SPEED = 10; +constexpr float PEEP_HARD_SHOT_SPEED = 12; +constexpr float PEEP_LAND_SHOTS = 12; +constexpr float PEEP_SPIT_SHOTS = 8; +constexpr float PEEP_SPIT_VOLUME = 0.8f; +constexpr int BLOAT_LAND_BIG_SHOTS = 3; +constexpr int BLOAT_SPIT_BIG_SHOTS = 2; +constexpr float PEEP_BIG_SHOT_ARC = 10; +constexpr float PEEP_BIG_SHOT_SCALE = 1.6f; +constexpr float PEEP_BIG_SHOT_ACCEL = 0.3f; +constexpr float PEEP_BIG_SHOT_SLOW = 0.7f; +constexpr float PEEP_BIG_SHOT_LIFT = 13; + +constexpr float BLOAT_LASER_SIDE_X = 15; +constexpr float BLOAT_LASER_WIDE_X = 20; +constexpr float BLOAT_LASER_Y = -40; +constexpr float BLOAT_LASER_DOWN_HEIGHT = -25; +constexpr float BLOAT_LASER_SIDE_HEIGHT = -35; +constexpr float BLOAT_LASER_DOWN_ANGLE = 90; +constexpr float BLOAT_LASER_LEFT_ANGLE = 180; +constexpr int BLOAT_LASER_TIMEOUT = 40; +constexpr float BLOAT_LASER_DEPTH = 3000; + +constexpr float PEEP_GUIDE_REACH = 10; +constexpr float PEEP_SPRAY_SPLASH = 0.35f; +constexpr float PEEP_SPRAY_DRIFT = 0.01f; +constexpr float PEEP_SPRAY_CREEP_SCALE = 2; +constexpr float BLOAT_SPRAY_CREEP_SCALE = 2.6f; +constexpr float BLOAT_CHARGER_REACH = 50; + +constexpr float PEEP_SPLAT_SIZE = 0.5f; +constexpr float PEEP_SPLAT_MIN = 0.2f; +constexpr float PEEP_SPLAT_SPREAD = 2; +constexpr float PEEP_SPLAT_DROP = 8; +constexpr float PEEP_EYES = 2; +constexpr float PEEP_EYE_REACH = 30; + +constexpr float PEEP_EYE_SPEED = 0.45f; +constexpr uint32_t PEEP_EYE_TURN_ODDS = 31; +constexpr int PEEP_EYE_TURN = 15; +constexpr uint32_t PEEP_EYE_SPLAT_ODDS = 4; +constexpr float PEEP_EYE_SPLAT_SIZE = 0.3f; +constexpr float PEEP_EYE_SPLAT_MIN = 0.3f; +constexpr float PEEP_EYE_FRICTION = 0.9f; +constexpr int PEEP_EYE_ROOM_CLEAR_DELAY = 8; +constexpr float QUARTER_TURN_RADIANS = 0.7853982f; + +// The eye: it dies with its body (or, alone, once the room is won), and bounces about on a diagonal it bends a little +// each time it turns back, bleeding as it goes. +static void peep_eye_update(Entity_NPC& npc) +{ + npc.sprite.Play("Walk"); + bool isAlive; + if (npc.subtype == PEEP_LONE_EYE) + { + RoomDescriptor* descriptor = g_game->GetRoomByIdx(g_game->currentRoomIdx, g_game->currentDimensionIdx); + isAlive = !(descriptor->flags & ROOM_DESCRIPTOR_FLAG_PRESSURE_PLATES_TRIGGERED) && + (npc.GetAliveEnemyCount() > 0 || g_game->room->roomClearDelay > PEEP_EYE_ROOM_CLEAR_DELAY); + } + else isAlive = npc.parent && !npc.parent->isDead; + if (!isAlive) npc.Kill(EntityRef()); + + if (Random() % PEEP_EYE_SPLAT_ODDS == 0) npc.MakeSplat(random_unit() * PEEP_EYE_SPLAT_SIZE + PEEP_EYE_SPLAT_MIN); + float speed = std::sqrt(2.0f) * PEEP_EYE_SPEED; + if ((npc.velocity.x > 0 && npc.v1.x <= 0) || (npc.velocity.y > 0 && npc.v1.y <= 0)) + npc.i2 = (int)(Random() % PEEP_EYE_TURN_ODDS) - PEEP_EYE_TURN; + + float angle = (float)npc.i2 * PI_F / 180 + QUARTER_TURN_RADIANS; + float sine = std::sin(angle); + if (npc.velocity.y <= 0) sine = -sine; + sine *= speed; + float cosine = std::cos(angle); + if (npc.velocity.x <= 0) cosine = -cosine; + npc.friction *= PEEP_EYE_FRICTION; + if (npc.friction != 0) + { + npc.velocity.x = speed * cosine * npc.speedMultiplier / npc.friction + npc.velocity.x; + npc.velocity.y = sine * npc.speedMultiplier / npc.friction + npc.velocity.y; + } + npc.v1 = npc.velocity; +} + +// The first frame: an eye cannot be hurt and hides its health, and in April Fool's Bloat boss room the Bloat brings a +// twin. +static void peep_init(Entity_NPC& npc) +{ + npc.state = NPC_STATE_MOVE; + if (npc.variant >= PEEP_EYE_FIRST) + { + npc.AddEntityFlags(FLAG_NO_STATUS_EFFECTS | FLAG_HIDE_HP_BAR); + npc.isInvincible = true; + npc.entityGridCollisionClass = GRIDCOLL_WALLS; + if (npc.subtype == PEEP_LONE_EYE) npc.isCanShutDoors = false; + return; + } + if (npc.variant != BLOAT || g_game->challenge != CHALLENGE_APRILS_FOOL || g_game->stage != STAGE_DEPTHS_II || + g_game->room->roomType != ROOM_BOSS || npc.spawnerType == npc.type) + return; + + uint32_t seed = Random(); + Vector spot = vector_add(vector_scale(random_direction(), BLOAT_TWIN_REACH), npc.pos); + g_game->Spawn({.position = spot, + .velocity = npc.velocity, + .spawner = &npc, + .subType = npc.subtype, + .type = npc.type, + .variant = npc.variant, + .seed = seed}); +} + +// Walking: now and then a jump, a spit or a spray. The Bloat also fires its lasers at a target in line with it, +// beside it or below it, after a warning. +static void peep_walk(Entity_NPC& npc, Vector target, Vector lead) +{ + npc.pathfinder.MoveRandomlyBoss(STATUS_OBEYED); + npc.sprite.Play("Walk"); + npc.stateFrame = 0; + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM) && room_is_clear()) return; + if (npc.variant == 0 && npc.subtype == PEEP_YELLOW && Random() % PEEP_YELLOW_CALM_ODDS == 0) return; + + if (Random() % PEEP_JUMP_ODDS == 0) npc.state = PEEP_JUMP_UP; + if (Random() % PEEP_ATTACK_ODDS == 0) npc.state = (Random() & 1) ? PEEP_SPRAY : PEEP_SPIT; + if (npc.variant != BLOAT) return; + + FollowingEffect tracer = { + .color = npc.subtype == PEEP_YELLOW ? BLOAT_GREEN_TRACER_COLOR : BLOAT_TRACER_COLOR, + .scale = BLOAT_TRACER_SCALE, + .timeout = BLOAT_TRACER_TIMEOUT}; + if (std::abs(npc.pos.y - target.y - BLOAT_SIDE_LINE - lead.y * PEEP_LEAD) < BLOAT_SIDE_REACH && + npc.size * npc.scale < std::abs(npc.pos.x - target.x)) + { + npc.state = BLOAT_LASER_SIDES; + for (float side : {1.0f, -1.0f}) + { + tracer.offset = vector_make(side * BLOAT_SIDE_TRACER_X, BLOAT_SIDE_TRACER_Y); + tracer.targetPosition = side > 0 ? vector_make(std::cos(0.0f), std::sin(0.0f)) + : vector_make(std::cos(PI_F), std::sin(PI_F)); + following_effect_spawn(npc, tracer); + } + } + if (std::abs(npc.pos.x - target.x - lead.x * PEEP_LEAD) < BLOAT_DOWN_REACH && npc.pos.y < target.y) + { + npc.state = BLOAT_LASER_DOWN; + tracer.targetPosition = vector_make(std::cos(PI_F / 2), std::sin(PI_F / 2)); + for (float side : {1.0f, -1.0f}) + { + tracer.offset = vector_make(side * BLOAT_DOWN_TRACER_X, BLOAT_DOWN_TRACER_Y); + following_effect_spawn(npc, tracer); + } + } +} + +// The Bloat's big bursting shot, lobbed at its target or straight up. +static void bloat_big_shot(Entity_NPC& npc, const Vector& target) +{ + ProjectileParams params; + Entity_Projectile* shot = npc.FireBossProjectiles(1, target, PEEP_BIG_SHOT_ARC, params); + shot->projectileFlags |= PROJECTILE_EXPLODE; + shot->scale = PEEP_BIG_SHOT_SCALE; + shot->fallingAccel -= PEEP_BIG_SHOT_ACCEL; + shot->fallingSpeed = shot->fallingSpeed * PEEP_BIG_SHOT_SLOW - PEEP_BIG_SHOT_LIFT; + shot->SetColor(PEEP_BIG_SHOT_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); +} + +// The spit's shots: eight for the plain Bloat, big bursting shots straight up for the green one, a yellow ring +// for Peep. +static void peep_shots(Entity_NPC& npc, float ringShots, int bigShots) +{ + ProjectileParams params; + float speed = game_is_hard_mode() ? PEEP_HARD_SHOT_SPEED : PEEP_SHOT_SPEED; + if (npc.variant != BLOAT) + { + params.color = PEEP_SHOT_COLOR; + return npc.FireProjectiles(npc.pos, vector_make(speed, ringShots), PROJECTILES_RING, params); + } + if (npc.subtype == 0) return npc.FireProjectiles(npc.pos, vector_make(speed, 0), PROJECTILES_EIGHT, params); + for (int i = 0; i < bigShots; i++) bloat_big_shot(npc, {}); +} + +// The jump up: it leaps at its target on Jump, out of reach until it lands. +static void peep_jump_up(Entity_NPC& npc, Vector target) +{ + if (npc.stateFrame == 0) + { + npc_anim_restart(npc.sprite, "JumpUp"); + npc.PlaySound(SOUND_BOSS_LITE_SLOPPY_ROAR, 1, 2, false, 1); + } + npc.stateFrame++; + if (npc.sprite.IsEventTriggered("Jump")) npc.velocity = vector_scale(vector_sub(target, npc.pos), PEEP_JUMP_SPEED); + if (npc.sprite.WasEventTriggered("Jump")) + { + npc.entityCollisionClass = ENTCOLL_NONE; + npc.entityGridCollisionClass = GRIDCOLL_WALLS; + } + if (!npc_anim_is_done(npc)) return; + npc.stateFrame = 0; + npc.state = PEEP_JUMP_DOWN; +} + +// The landing: a shockwave and a shot burst, the Bloat spilling creep all about. +static void peep_jump_down(Entity_NPC& npc, const ColorMod& bloodColor) +{ + if (npc.stateFrame == 0) npc_anim_restart(npc.sprite, "JumpDown"); + npc.stateFrame++; + if (npc_anim_is_done(npc)) npc.state = NPC_STATE_MOVE; + if (npc.sprite.WasEventTriggered("Shoot")) + { + npc.entityCollisionClass = ENTCOLL_ALL; + npc.entityGridCollisionClass = GRIDCOLL_GROUND; + } + if (!npc.sprite.IsEventTriggered("Shoot")) return; + + shockwave_make(npc.pos, PEEP_SHOCKWAVE_AMPLITUDE, PEEP_SHOCKWAVE_SPEED, PEEP_SHOCKWAVE_FRAMES); + npc.PlaySound(SOUND_FORESTBOSS_STOMPS, 1, 2, false, 1); + if (npc.variant == BLOAT) + { + ProjectileParams params; + for (int i = 0; i < BLOAT_LAND_CREEPS; i++) + { + uint32_t seed = Random(); + float angle = random_unit() * RANDOM_HALF_TURN; + angle += angle; + float reach = random_unit() * BLOAT_LAND_CREEP_REACH; + Vector spot = vector_make(std::cos(angle) * reach + npc.pos.x, std::sin(angle) * reach + npc.pos.y); + int creep = npc.subtype == PEEP_YELLOW ? EFFECT_CREEP_GREEN : EFFECT_CREEP_RED; + Entity* puddle = g_game->Spawn( + {.position = spot, .spawner = &npc, .type = ENTITY_EFFECT, .variant = creep, .seed = seed}); + puddle->sprite.scale = vector_make(BLOAT_CREEP_SCALE, BLOAT_CREEP_SCALE); + } + float speed = game_is_hard_mode() ? PEEP_HARD_SHOT_SPEED : PEEP_SHOT_SPEED; + if (npc.subtype == 0) npc.FireProjectiles(npc.pos, vector_make(speed, 0), PROJECTILES_EIGHT, params); + else + for (int i = 0; i < BLOAT_LAND_BIG_SHOTS; i++) + bloat_big_shot(npc, i == 0 ? npc.GetPlayerTarget()->pos : Vector{}); + } + else peep_shots(npc, PEEP_LAND_SHOTS, 0); + npc.MakeBloodPoof(npc.pos, bloodColor, 1); +} + +// The spit: a shot burst on Shoot. +static void peep_spit(Entity_NPC& npc, const ColorMod& bloodColor) +{ + if (npc.stateFrame == 0) + { + npc_anim_restart(npc.sprite, "Attack01"); + npc.PlaySound(SOUND_BOSS_LITE_SLOPPY_ROAR, 1, 2, false, 1); + } + npc.stateFrame++; + if (npc_anim_is_done(npc)) npc.state = NPC_STATE_MOVE; + if (!npc.sprite.IsEventTriggered("Shoot")) return; + + npc.PlaySound(SOUND_FORESTBOSS_STOMPS, PEEP_SPIT_VOLUME, 2, false, 1); + peep_shots(npc, PEEP_SPIT_SHOTS, BLOAT_SPIT_BIG_SHOTS); + npc.MakeBloodPoof(npc.pos, bloodColor, 1); +} + +// The Bloat's lasers: a pair down from its eyes, or one to each side. +static void bloat_lasers(Entity_NPC& npc, bool isSides) +{ + if (npc.stateFrame == 0) npc.sprite.Play(isSides ? "AttackAlt02" : "AttackAlt01", PLAY_FORCED); + npc.stateFrame++; + if (npc_anim_is_done(npc)) npc.state = NPC_STATE_MOVE; + if (!npc.sprite.IsEventTriggered("Shoot")) return; + + float x = isSides ? BLOAT_LASER_WIDE_X : BLOAT_LASER_SIDE_X; + Vector offset = vector_make(0, isSides ? BLOAT_LASER_SIDE_HEIGHT : BLOAT_LASER_DOWN_HEIGHT); + LaserShot shot = {.position = vector_make(npc.pos.x - x, npc.pos.y + BLOAT_LASER_Y), + .posOffset = offset, + .source = &npc, + .angleDegrees = isSides ? BLOAT_LASER_LEFT_ANGLE : BLOAT_LASER_DOWN_ANGLE, + .timeout = BLOAT_LASER_TIMEOUT, + .variant = LASER_THICK_RED}; + Entity_Laser* left = Entity_Laser::ShootAngle(shot); + shot.position = vector_make(npc.pos.x + x, npc.pos.y + BLOAT_LASER_Y); + shot.angleDegrees = isSides ? 0 : BLOAT_LASER_DOWN_ANGLE; + Entity_Laser* right = Entity_Laser::ShootAngle(shot); + left->renderDepthOffset = BLOAT_LASER_DEPTH; + right->renderDepthOffset = BLOAT_LASER_DEPTH; + left->Update(); + right->Update(); +} + +// The spray: a poof on Jump, then creep and blood flung along its BloodGuide each tick, the green Bloat also +// summoning two Chargers on Shoot. +static void peep_spray(Entity_NPC& npc, const ColorMod& bloodColor) +{ + if (npc.stateFrame == 0) npc_anim_restart(npc.sprite, "Attack02"); + npc.stateFrame++; + if (npc.sprite.IsEventTriggered("Jump")) + { + npc.PlaySound(SOUND_SINK_DRAIN_GURGLE, 1, 2, false, 1); + Entity* poof = g_game->Spawn({.position = npc.pos, + .spawner = &npc, + .subType = 3, + .type = ENTITY_EFFECT, + .variant = EFFECT_POOF02, + .seed = Random()}); + poof->SetColor(bloodColor, -1, COLOR_PRIORITY_DEFAULT, false, true); + poof->sprite.isFlipX = (Random() & 1) == 0; + poof->Update(); + } + if (npc_anim_is_done(npc)) npc.state = NPC_STATE_MOVE; + + int ticks = npc_ticks_get(npc); + for (int i = 0; i < ticks; i++) + { + if (!npc.sprite.animState.animData) continue; + const NullFrame* guide = npc.sprite.animState.GetNullFrame("BloodGuide"); + if (!guide || !guide->isVisible) continue; + + float angle = random_unit() * RANDOM_HALF_TURN; + angle += angle; + Vector fling = vector_make(std::cos(angle) * guide->scale.x * PEEP_GUIDE_REACH, + std::sin(angle) * guide->scale.y * PEEP_GUIDE_REACH); + fling = vector_scale(fling, random_unit()); + if (npc.variant == BLOAT && npc.subtype == PEEP_YELLOW && npc.sprite.animState.animData && + npc.sprite.IsEventTriggered("Shoot") && i == 0) + for (int charger = 0; charger < 2; charger++) + { + Vector spot = room_free_pickup_position_find({.position = npc.pos, .step = BLOAT_CHARGER_REACH}); + g_game->Spawn({.position = spot, .spawner = &npc, .type = ENTITY_CHARGER, .seed = Random()}); + } + + int creepVariant = EFFECT_CREEP_YELLOW; + float creepScale = PEEP_SPRAY_CREEP_SCALE; + if (npc.variant == BLOAT) + { + creepScale = BLOAT_SPRAY_CREEP_SCALE; + creepVariant = npc.subtype == PEEP_YELLOW ? EFFECT_CREEP_GREEN : EFFECT_CREEP_RED; + } + Entity* creep = g_game->Spawn({.position = vector_add(fling, npc.pos), + .spawner = &npc, + .type = ENTITY_EFFECT, + .variant = creepVariant, + .seed = Random()}); + creep->sprite.scale = vector_make(creepScale, creepScale); + creep->Update(); + + Vector splash = vector_add(vector_scale(fling, PEEP_SPRAY_SPLASH), npc.pos); + Entity* blood = g_game->Spawn({.position = splash, + .velocity = vector_scale(fling, PEEP_SPRAY_DRIFT), + .subType = 3, + .type = ENTITY_EFFECT, + .variant = EFFECT_BLOOD_EXPLOSION, + .seed = Random()}); + blood->SetColor(bloodColor, -1, COLOR_PRIORITY_DEFAULT, false, true); + blood->sprite.offset = {}; + blood->renderDepthOffset = BOSS_BLOOD_DEPTH; + } +} + +// Its sheet once it loses an eye (_b), then both (_c): the sheet path with that suffix, colored as the NPC is. +static void peep_sheet_swap(Entity_NPC& npc, std::string_view suffix) +{ + std::string sheet = npc.sprite.GetLayer(0)->spriteSheetPath; + sheet = sheet.substr(0, sheet.size() - SHEET_EXTENSION_SIZE) + std::string(suffix); + npc.sprite.ReplaceSpritesheet(0, npc_sheet_path_get(npc, sheet)); + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM)) ANM2::LoadDeliriumForm(npc.sprite, npc.type, npc.variant, false); + npc.sprite.LoadGraphics(); +} + +// It bleeds where it walks, and hurt to two thirds and to a third of its health pops out an eye each time (the +// Bloat both at once), changing its sheet. +static void peep_bleed(Entity_NPC& npc) +{ + Entity_Effect* splat = npc.MakeSplat(random_unit() * PEEP_SPLAT_SIZE + PEEP_SPLAT_MIN); + float angle = random_unit() * RANDOM_HALF_TURN; + angle += angle; + float sine = std::sin(angle); + float cosine = std::cos(angle); + splat->pos = vector_make(cosine * PEEP_SPLAT_SPREAD + npc.pos.x, + sine * PEEP_SPLAT_SPREAD + npc.pos.y + PEEP_SPLAT_DROP); + if (npc.variant == 0) splat->SetColor(PEEP_SPLAT_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); + + int eyes = std::min(2 - (int)(npc.health * 3 / npc.maxHitPoints), (int)PEEP_EYES); + if (npc.variant == BLOAT || npc.subtype == 2) eyes = (int)PEEP_EYES; + if (npc.i1 >= eyes) return; + if (eyes == 1 && npc.variant == 0) peep_sheet_swap(npc, "_b.png"); + if (eyes == 2) + { + if (npc.variant == 0) peep_sheet_swap(npc, "_c.png"); + if (npc.i1 > 1) return; + } + + do + { + npc_sound_play(SOUND_PLOP, 1, 2, champion_pitch_get(npc)); + npc.i1++; + uint32_t seed = Random(); + float turn = random_unit() * RANDOM_HALF_TURN; + turn += turn; + Vector spot = vector_make(std::cos(turn) * PEEP_EYE_REACH + npc.pos.x, + std::sin(turn) * PEEP_EYE_REACH + npc.pos.y); + auto* eye = static_cast(g_game->Spawn({.position = spot, + .spawner = &npc, + .type = npc.type, + .variant = npc.variant + PEEP_EYE_FIRST, + .seed = seed})); + eye->SetBossColorIdx(npc.bosscoloridx, 0); + eye->parent = &npc; + } while (npc.i1 < eyes); +} + +// 0047d8a0 NpcAI::ENTITY_PEEP: Peep and the Bloat walk about bleeding creep, jump on their target, spit shots and +// spray creep, the Bloat firing lasers. Hurt, they pop out eyes that bounce about until they die. +void boss_peep_update(Entity_NPC& npc) +{ + if (npc.state == NPC_STATE_INIT) return peep_init(npc); + + Vector target = npc.CalcTargetPosition(0); + Vector lead = vector_scale(npc.GetPlayerTarget()->velocity, 2); + if (npc.variant >= PEEP_EYE_FIRST) return peep_eye_update(npc); + + const ColorMod& bloodColor = npc.variant != BLOAT ? PEEP_BLOOD_COLOR + : npc.subtype == PEEP_YELLOW ? BLOAT_GREEN_BLOOD_COLOR + : COLOR_DEFAULT; + if (npc.entityCollisionClass != ENTCOLL_NONE) + npc.friction *= npc.variant == 0 && npc.subtype == PEEP_YELLOW ? PEEP_YELLOW_FRICTION : PEEP_FRICTION; + if (npc.variant == 0 && npc.subtype == PEEP_YELLOW && g_game->room->GetFrameCount() % PEEP_CREEP_TICKS == 0) + { + Entity* creep = g_game->Spawn({.position = npc.pos, + .spawner = &npc, + .type = ENTITY_EFFECT, + .variant = EFFECT_CREEP_YELLOW, + .seed = Random()}); + creep->sprite.scale = vector_make(PEEP_CREEP_SCALE, PEEP_CREEP_SCALE); + creep->Update(); + } + + switch (npc.state) + { + case NPC_STATE_MOVE: + peep_walk(npc, target, lead); + break; + case PEEP_JUMP_UP: + peep_jump_up(npc, target); + break; + case PEEP_JUMP_DOWN: + peep_jump_down(npc, bloodColor); + break; + case PEEP_SPIT: + peep_spit(npc, bloodColor); + break; + case BLOAT_LASER_DOWN: + case BLOAT_LASER_SIDES: + bloat_lasers(npc, npc.state == BLOAT_LASER_SIDES); + break; + case PEEP_SPRAY: + peep_spray(npc, bloodColor); + break; + } + peep_bleed(npc); +} diff --git a/src/boss_pestilence.cpp b/src/boss_pestilence.cpp new file mode 100644 index 0000000..576df86 --- /dev/null +++ b/src/boss_pestilence.cpp @@ -0,0 +1,312 @@ +#include "boss_ai.h" +#include "npc_caves.h" +#include "room_grid.h" +#include "sfx_manager.h" +#include + +// Pestilence's grey subtype, which summons Trites and spiders and fires rings. +constexpr int PESTILENCE_GREY = 1; + +// Pestilence's states: walking, the spit, and the summon. +constexpr int PESTILENCE_SPIT = NPC_STATE_ATTACK; +constexpr int PESTILENCE_SUMMON = NPC_STATE_SUMMON; + +// Its form (i1): on its horse, or headless once hurt to half its health. +enum PestilenceForm +{ + PESTILENCE_MOUNTED, + PESTILENCE_HEADLESS +}; + +constexpr ColorMod PESTILENCE_GREY_SPLAT = { + {0.5f, 0.5f, 0.5f, 1}, {0, 0, 0, 0}, {-50 / 255.0f, 130 / 255.0f, 50 / 255.0f}}; +constexpr float PESTILENCE_FRICTION = 0.8f; +constexpr int PESTILENCE_SPLAT_TICKS = 3; +constexpr float PESTILENCE_SPLAT_SIZE = 0.5f; +constexpr float PESTILENCE_SPLAT_MIN = 0.4f; +constexpr float PESTILENCE_SPLAT_REACH = 20; +constexpr float PESTILENCE_HEADLESS_HEALTH = 0.5f; +constexpr int PESTILENCE_HEAD_LAYER = 1; +constexpr int PESTILENCE_CREEP_TICKS = 7; +constexpr float PESTILENCE_CREEP_SCALE = 2; + +constexpr int PESTILENCE_MINION_LIMIT = 4; +constexpr int PESTILENCE_DELIRIUM_MINION_LIMIT = 3; +constexpr float PESTILENCE_WALK_SPEED = 1; +constexpr float PESTILENCE_WALK_THRESHOLD = 3; +constexpr uint32_t PESTILENCE_SUMMON_ODDS = 40; +constexpr uint32_t PESTILENCE_SPIT_ODDS = 20; +constexpr float PESTILENCE_SPIT_REACH = 230; + +constexpr int PESTILENCE_SUMMON_FRAME = 25; +constexpr int PESTILENCE_SUMMON_END = 57; +constexpr float PESTILENCE_SUMMON_VOLUME = 1.2f; +constexpr float PESTILENCE_SUMMON_REACH = 10; +constexpr int PESTILENCE_SUMMON_PAIR = 2; +constexpr int PESTILENCE_SPIT_FRAME = 22; +constexpr int PESTILENCE_SPIT_END = 40; +constexpr int PESTILENCE_HEADLESS_SPIT_FRAME = 9; +constexpr int PESTILENCE_HEADLESS_SPIT_END = 29; +constexpr int PESTILENCE_HEADLESS_SPIDER_FRAME = 19; + +constexpr float PESTILENCE_BIG_SHOT_ARC = 10; +constexpr float PESTILENCE_BIG_SHOT_SCALE = 1.6f; +constexpr float PESTILENCE_BIG_SHOT_ACCEL = 0.3f; +constexpr float PESTILENCE_BIG_SHOT_SLOW = 0.7f; +constexpr float PESTILENCE_BIG_SHOT_LIFT = 13; +constexpr ColorMod PESTILENCE_BIG_SHOT_COLOR = {{1, 1, 1, 1}, {0.4f, 2, 0.5f, 1}, {0, 0, 0}}; +constexpr ColorMod PESTILENCE_RING_COLOR = {{1, 1, 1, 1}, {3, 3, 3, 1}, {50 / 255.0f, 50 / 255.0f, 50 / 255.0f}}; +constexpr float PESTILENCE_RING_HEIGHT = -30; +constexpr float PESTILENCE_RING_SPEED = 8; +constexpr float PESTILENCE_RING_SHOTS = 6; + +constexpr float PESTILENCE_COUGH_SIDE = 40; +constexpr float PESTILENCE_SPIDER_REACH = 70; +constexpr float PESTILENCE_SPIDER_HEIGHT = -30; + +// The plain one's trail: a splat about it every third tick. +static void pestilence_splat(Entity_NPC& npc) +{ + if (npc.IsFrame(PESTILENCE_SPLAT_TICKS, 0) && npc.subtype == 0) + { + float scale = random_unit() * PESTILENCE_SPLAT_SIZE + PESTILENCE_SPLAT_MIN; + uint32_t seed = Random(); + float angle = random_unit() * RANDOM_HALF_TURN; + angle += angle; + Vector spot = vector_make(std::cos(angle) * PESTILENCE_SPLAT_REACH + npc.pos.x, + std::sin(angle) * PESTILENCE_SPLAT_REACH + npc.pos.y); + Entity* splat = g_game->Spawn( + {.position = spot, .spawner = &npc, .type = ENTITY_EFFECT, .variant = EFFECT_BLOOD_SPLAT, .seed = seed}); + splat->sprite.scale = vector_make(scale, scale); + splat->SetColor(npc.splatColor, -1, COLOR_PRIORITY_DEFAULT, false, true); + splat->Update(); + } +} + +// Creep under it every seventh tick, white for the grey one. +static void pestilence_creep(Entity_NPC& npc) +{ + if (!npc.IsFrame(PESTILENCE_CREEP_TICKS, 0)) return; + Entity* creep = g_game->Spawn({.position = npc.pos, + .spawner = &npc, + .type = ENTITY_EFFECT, + .variant = npc.subtype != 0 ? EFFECT_CREEP_WHITE : EFFECT_CREEP_GREEN, + .seed = Random()}); + creep->sprite.scale = vector_make(PESTILENCE_CREEP_SCALE, PESTILENCE_CREEP_SCALE); + creep->Update(); +} + +// Hurt to half its health, its head bursts in a tinted explosion and it goes on headless. +static void pestilence_behead(Entity_NPC& npc) +{ + npc.i1 = PESTILENCE_HEADLESS; + uint32_t seed = Random(); + Vector spot = vector_add(npc.pos, npc.sprite.GetLayer(PESTILENCE_HEAD_LAYER)->pos); + Entity* burst = g_game->Spawn( + {.position = spot, .spawner = &npc, .type = ENTITY_EFFECT, .variant = EFFECT_BOMB_EXPLOSION, .seed = seed}); + npc.BloodExplode(); + npc.sprite.GetLayer(PESTILENCE_HEAD_LAYER)->isVisible = false; + burst->SetColor(npc.splatColor, -1, COLOR_PRIORITY_DEFAULT, false, true); + npc.pathfinder.movementTarget = {}; + npc.pathfinder.moveDirection = {}; +} + +// The spit: a big bursting green shot lobbed at its target, or a pale ring for the grey one. +static void pestilence_spit_fire(Entity_NPC& npc) +{ + npc_sound_play(SOUND_MONSTER_GRUNT_0, 1, 2, champion_pitch_get(npc)); + if (npc.subtype == 0) + { + ProjectileParams params; + Vector target = npc.GetPlayerTarget()->pos; + Entity_Projectile* shot = npc.FireBossProjectiles(1, target, PESTILENCE_BIG_SHOT_ARC, params); + shot->projectileFlags |= PROJECTILE_EXPLODE | PROJECTILE_ACID_GREEN; + shot->scale = PESTILENCE_BIG_SHOT_SCALE; + shot->fallingAccel -= PESTILENCE_BIG_SHOT_ACCEL; + shot->fallingSpeed = shot->fallingSpeed * PESTILENCE_BIG_SHOT_SLOW - PESTILENCE_BIG_SHOT_LIFT; + shot->SetColor(PESTILENCE_BIG_SHOT_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); + return; + } + + ProjectileParams params; + params.color = PESTILENCE_RING_COLOR; + Vector mouth = vector_make(npc.pos.x, npc.pos.y + PESTILENCE_RING_HEIGHT); + npc.FireProjectiles(mouth, vector_make(PESTILENCE_RING_SPEED, PESTILENCE_RING_SHOTS), PROJECTILES_RING, params); +} + +// The minions it counts before summoning: every enemy in the room, or a Delirium form's own Chargers, Spitties and +// Trites. +static int pestilence_minion_count(Entity_NPC& npc) +{ + if (!npc.HasEntityFlags(FLAG_DELIRIUM_FORM)) return g_game->room->GetAliveEnemiesCount(); + return npc.CountRelatedEntities(ENTITY_SPITTY, 0, nullptr) + + npc.CountRelatedEntities(ENTITY_HOPPER, HOPPER_TRITE, nullptr) + + npc.CountRelatedEntities(ENTITY_CHARGER, 0, nullptr); +} + +// Walking: now and then a summon while few minions are about, or a spit at a target in reach. +static void pestilence_walk(Entity_NPC& npc, int limit, Vector toTarget) +{ + bool isMounted = npc.i1 == PESTILENCE_MOUNTED; + if (isMounted) + { + npc.pathfinder.MoveRandomlyAxisAligned(PESTILENCE_WALK_SPEED, STATUS_OBEYED); + npc.AnimWalkFrame("Walk", "Walk", PESTILENCE_WALK_THRESHOLD); + } + else npc.pathfinder.MoveRandomlyBoss(STATUS_OBEYED); + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM) && room_is_clear()) return; + + bool isUnderCap; + if (isMounted) isUnderCap = pestilence_minion_count(npc) < limit; + else + { + isUnderCap = g_game->room->GetAliveEnemiesCount() < limit; + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM) && npc.subtype == 0) + isUnderCap = npc.CountRelatedEntities(ENTITY_ATTACKFLY, 0, nullptr) < limit; + else if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM) && npc.subtype == PESTILENCE_GREY) + isUnderCap = npc.CountRelatedEntities(ENTITY_STRIDER, 0, nullptr) + + npc.CountRelatedEntities(ENTITY_BIG_SPIDER, 0, nullptr) + + npc.CountRelatedEntities(ENTITY_SPIDER, 0, nullptr) < + limit; + } + + const char* animation = isMounted ? "Attack2" : "HeadlessAttack2"; + if (Random() % PESTILENCE_SUMMON_ODDS == 0 && isUnderCap) npc.state = PESTILENCE_SUMMON; + else + { + if (Random() % PESTILENCE_SPIT_ODDS != 0 || vector_length(toTarget) >= PESTILENCE_SPIT_REACH) return; + npc.state = PESTILENCE_SPIT; + animation = isMounted ? "Attack1" : "HeadlessAttack1"; + if (isMounted) npc.sprite.isFlipX = toTarget.x < 0; + } + npc.stateFrame = 0; + npc_anim_restart(npc.sprite, animation); +} + +// How many a Delirium form summons: two, or what the limit leaves beside its minions already about. +static int pestilence_summon_count(Entity_NPC& npc, int spare) +{ + if (!npc.HasEntityFlags(FLAG_DELIRIUM_FORM)) return PESTILENCE_SUMMON_PAIR; + return spare < PESTILENCE_DELIRIUM_MINION_LIMIT ? spare : PESTILENCE_SUMMON_PAIR; +} + +// The mounted summon: a pair of Chargers or Spitties on either side of it, or a Trite for the grey one. +static void pestilence_mounted_summon(Entity_NPC& npc, int limit) +{ + npc.PlaySound(SOUND_MONSTER_GRUNT_5, 1, 2, false, 1); + npc.PlaySound(SOUND_SUMMONSOUND, PESTILENCE_SUMMON_VOLUME, 2, false, 1); + Vector offset = vector_scale(random_direction(), PESTILENCE_SUMMON_REACH); + int count = PESTILENCE_SUMMON_PAIR; + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM)) + { + int spare = limit - npc.CountRelatedEntities(ENTITY_CHARGER, 0, nullptr); + spare -= npc.CountRelatedEntities(ENTITY_SPITTY, 0, nullptr); + count = pestilence_summon_count(npc, spare - npc.CountRelatedEntities(ENTITY_HOPPER, HOPPER_TRITE, nullptr)); + } + + if (npc.subtype != 0) + { + if (count > 0) + g_game->Spawn({.position = vector_add(offset, npc.pos), + .spawner = &npc, + .type = ENTITY_HOPPER, + .variant = HOPPER_TRITE, + .seed = Random()}); + return; + } + + int type = (Random() & 1) ? ENTITY_SPITTY : ENTITY_CHARGER; + if (count > 0) + g_game->Spawn({.position = vector_add(offset, npc.pos), .spawner = &npc, .type = type, .seed = Random()}); + if (count > 1) + g_game->Spawn({.position = vector_sub(npc.pos, offset), .spawner = &npc, .type = type, .seed = Random()}); +} + +// The headless cough: a pair of Attack Flies to its front, already awake and dying on touch. +static void pestilence_headless_flies(Entity_NPC& npc, int limit) +{ + int count = PESTILENCE_SUMMON_PAIR; + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM)) + count = pestilence_summon_count(npc, limit - npc.CountRelatedEntities(ENTITY_ATTACKFLY, 0, nullptr)); + npc.PlaySound(SOUND_WHEEZY_COUGH, 1, 2, false, 1); + + Vector front = vector_make(npc.sprite.isFlipX ? -PESTILENCE_COUGH_SIDE : PESTILENCE_COUGH_SIDE, 0); + Vector offset = vector_add(vector_scale(random_direction(), PESTILENCE_SUMMON_REACH), front); + for (int i = 0; i < count; i++) + { + float side = i == 0 ? 1.0f : -1.0f; + uint32_t seed = Random(); + Vector spot = vector_make(offset.x * side + npc.pos.x, offset.y * side + npc.pos.y); + Entity* fly = g_game->Spawn({.position = spot, .spawner = &npc, .type = ENTITY_ATTACKFLY, .seed = seed}); + fly->ClearEntityFlags(FLAG_APPEAR); + fly->isKillOnTouch = true; + } +} + +// The headless grey one's spider, thrown at a free spot near it. +static void pestilence_headless_spider(Entity_NPC& npc) +{ + npc.PlaySound(SOUND_WHEEZY_COUGH, 1, 2, false, 1); + Vector spot = room_free_pickup_position_find({.position = npc.pos, .step = PESTILENCE_SPIDER_REACH}); + Vector direction = random_direction(); + float reach = random_unit(); + Vector target = vector_make(reach * direction.x * PESTILENCE_SUMMON_REACH + spot.x, + reach * direction.y * PESTILENCE_SUMMON_REACH + spot.y); + Entity_NPC::ThrowSpider(npc.pos, &npc, target, false, PESTILENCE_SPIDER_HEIGHT); +} + +// The summon, on its frame: minions while mounted, flies or a spider when headless. Back to walking once it ends. +static void pestilence_summon(Entity_NPC& npc, int limit) +{ + int frame = npc.stateFrame++; + bool isMounted = npc.i1 == PESTILENCE_MOUNTED; + if (isMounted && frame == PESTILENCE_SUMMON_FRAME) return pestilence_mounted_summon(npc, limit); + if (!isMounted && frame == PESTILENCE_SUMMON_FRAME && npc.subtype == 0) + return pestilence_headless_flies(npc, limit); + if (!isMounted && npc.stateFrame == PESTILENCE_HEADLESS_SPIDER_FRAME && npc.subtype == PESTILENCE_GREY) + return pestilence_headless_spider(npc); + if (npc.stateFrame > PESTILENCE_SUMMON_END) npc.state = NPC_STATE_MOVE; +} + +// The spit, on its frame, then back to walking. +static void pestilence_spit(Entity_NPC& npc) +{ + bool isMounted = npc.i1 == PESTILENCE_MOUNTED; + int frame = npc.stateFrame++; + if (frame == (isMounted ? PESTILENCE_SPIT_FRAME : PESTILENCE_HEADLESS_SPIT_FRAME)) return pestilence_spit_fire(npc); + if (npc.stateFrame > (isMounted ? PESTILENCE_SPIT_END : PESTILENCE_HEADLESS_SPIT_END)) npc.state = NPC_STATE_MOVE; +} + +// 00457840 NpcAI::ENTITY_PESTILENCE: Pestilence rides about leaving creep, spits a bursting shot at its target and +// summons Chargers and Spitties. Hurt to half its health, it loses its head and coughs flies instead. +void boss_pestilence_update(Entity_NPC& npc) +{ + if (npc.state == NPC_STATE_INIT) + { + npc.state = NPC_STATE_MOVE; + if (npc.subtype == PESTILENCE_GREY) npc.splatColor = PESTILENCE_GREY_SPLAT; + return; + } + + npc.friction *= PESTILENCE_FRICTION; + pestilence_splat(npc); + if (npc.i1 == PESTILENCE_MOUNTED && npc.health / npc.maxHitPoints < PESTILENCE_HEADLESS_HEALTH) + pestilence_behead(npc); + pestilence_creep(npc); + int limit = npc.HasEntityFlags(FLAG_DELIRIUM_FORM) ? PESTILENCE_DELIRIUM_MINION_LIMIT : PESTILENCE_MINION_LIMIT; + Vector toTarget = vector_sub(npc.GetPlayerTarget()->pos, npc.pos); + + switch (npc.state) + { + case NPC_STATE_MOVE: + pestilence_walk(npc, limit, toTarget); + break; + case PESTILENCE_SUMMON: + pestilence_summon(npc, limit); + break; + case PESTILENCE_SPIT: + pestilence_spit(npc); + break; + } + horseman_mega_satan_hold(npc); +} diff --git a/src/boss_polycephalus.cpp b/src/boss_polycephalus.cpp new file mode 100644 index 0000000..6c8b7b7 --- /dev/null +++ b/src/boss_polycephalus.cpp @@ -0,0 +1,397 @@ +#include "boss_ai.h" +#include "npc_caves.h" +#include "room_grid.h" +#include "sfx_manager.h" +#include + +// Polycephalus's subtypes (the red one, and the pair) and the Stain's grey one. Variant 1 is the Pile. +constexpr int POLYCEPHALUS_RED = 1; +constexpr int POLYCEPHALUS_PAIR = 2; +constexpr int STAIN_GREY = 1; +constexpr int POLYCEPHALUS_PILE = 1; + +// Their states once surfaced: the shot burst, the stream (the Stain's spin), the summon (Polycephalus) and the +// Stain's summon. +constexpr int POLYCEPHALUS_SHOOT = NPC_STATE_ATTACK; +constexpr int POLYCEPHALUS_STREAM = NPC_STATE_ATTACK2; +constexpr int POLYCEPHALUS_SUMMON = NPC_STATE_ATTACK3; +constexpr int STAIN_SUMMON = NPC_STATE_SUMMON; + +// The burrow's phases (i1): going under, waiting for that to end, and moving underground. +enum PolycephalusBurrow +{ + BURROW_START, + BURROW_SINKING, + BURROW_MOVING +}; + +// The Stain's spin phases (i1) after it surfaces: two rounds of shooting and stopping, then going under. +enum StainSpin +{ + STAIN_SPIN_SHOOT = 1, + STAIN_SPIN_STOP = 2, + STAIN_SPIN_START = 3, + STAIN_SPIN_SHOOT_FAST = 4, + STAIN_SPIN_STOP_FAST = 5, + STAIN_SPIN_UNDER = 6 +}; + +constexpr float POLYCEPHALUS_TWIN_REACH = 40; +constexpr uint32_t POLYCEPHALUS_BURROW_ODDS = 30; +constexpr float POLYCEPHALUS_FRICTION = 0.8f; +constexpr int POLYCEPHALUS_SHRINK_FRAMES = 50; +constexpr float POLYCEPHALUS_WANDER = 100; +constexpr float POLYCEPHALUS_WALL_MARGIN = 20; +constexpr float POLYCEPHALUS_DIG_SPEED = 1; +constexpr int POLYCEPHALUS_PATH_MARKER = 100; +constexpr float POLYCEPHALUS_SURFACE_REACH_SQUARED = 22500; +constexpr uint32_t POLYCEPHALUS_SURFACE_ODDS = 15; +constexpr int POLYCEPHALUS_STATUS_ENDING = 5; +constexpr int POLYCEPHALUS_ENEMY_LIMIT = 3; +constexpr uint32_t POLYCEPHALUS_SUMMON_ODDS = 5; + +constexpr int POLYCEPHALUS_SOUND_DELAY = 60; +constexpr float POLYCEPHALUS_SURFACE_VOLUME = 0.8f; +constexpr float POLYCEPHALUS_LEAD = 10; +constexpr float POLYCEPHALUS_SHOOT_VOLUME = 1.5f; +constexpr float POLYCEPHALUS_SHOT_SPEED = 10; +constexpr float POLYCEPHALUS_RED_SHOTS = 6; +constexpr float POLYCEPHALUS_STREAM_ARC = 1; +constexpr float POLYCEPHALUS_WORM_REACH = 60; + +constexpr float STAIN_CREEP_STEP = 0.125f; +constexpr float STAIN_CREEP_REACH = 120; +constexpr float STAIN_CREEP_GROWTH = 0.56f; +constexpr float STAIN_CREEP_MIN = 0.3f; +constexpr float STAIN_CREEP_CENTER = 1.84f; +constexpr int STAIN_CREEP_TIMEOUT = 70; +constexpr int STAIN_SPIN_FRAMES = 90; +constexpr int STAIN_STOP_FRAMES = 31; +constexpr float STAIN_SPIN_ACCEL = -0.06f; +constexpr float STAIN_SPIN_FALL = -2; +constexpr float STAIN_SPIN_TURN = 0.118f; +constexpr float STAIN_SPIN_SLOWDOWN = 0.985f; +constexpr float STAIN_SPIN_SPEED = 6; +constexpr float STAIN_SPIN_SHOTS = 3; +constexpr float STAIN_SPIN_FAST_TURN = 0.12f; +constexpr float STAIN_SPIN_SPEEDUP = 1.025f; +constexpr float STAIN_SPIN_FAST_SPEED = 3.2f; +constexpr float STAIN_SPIN_FAST_SHOTS = 4; +constexpr int STAIN_SUMMON_PAIR = 2; +constexpr float STAIN_SUMMON_REACH = 60; + +// Whether its minions are few enough to summon more: three enemies, or a Delirium form's own of a type. +static bool polycephalus_is_under_cap(Entity_NPC& npc, int type) +{ + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM)) + return npc.CountRelatedEntities(type, 0, nullptr) < POLYCEPHALUS_ENEMY_LIMIT; + return g_game->room->GetAliveEnemiesCount() < POLYCEPHALUS_ENEMY_LIMIT; +} + +// Its full size back as it surfaces, under its shrink. +static void polycephalus_size_reset(Entity_NPC& npc, float scale) +{ + npc.scale = scale; + npc.sprite.scale = vector_scale(vector_make(1, 1), scale * npc.shrinkStatus1); +} + +// Underground it shrinks into its dirt and digs toward a spot near its target, surfacing to attack when near it one +// time in fifteen, or as its confusion or fear wears off. +static void polycephalus_dig(Entity_NPC& npc, bool isGrey) +{ + if (npc.stateFrame++ < POLYCEPHALUS_SHRINK_FRAMES) + polycephalus_size_reset(npc, 1 - (float)npc.stateFrame / POLYCEPHALUS_SHRINK_FRAMES); + npc.sprite.Play("Dirt"); + + Vector target = npc.CalcTargetPosition(0); + Vector direction = random_direction(); + float reach = random_unit() * POLYCEPHALUS_WANDER; + Vector spot = vector_make(reach * direction.x + target.x, reach * direction.y + target.y); + float margin = POLYCEPHALUS_WALL_MARGIN; + spot = g_game->room->GetClampedPositionImpl(spot, margin, margin, margin, margin); + npc.pathfinder.FindGridPath(spot, POLYCEPHALUS_DIG_SPEED, POLYCEPHALUS_PATH_MARKER, DIRECT_PATH_FAR); + npc.entityCollisionClass = ENTCOLL_NONE; + + Vector away = vector_sub(npc.pos, npc.GetPlayerTarget()->pos); + bool isSurfacing = (vector_length_squared(away) < POLYCEPHALUS_SURFACE_REACH_SQUARED && + Random() % POLYCEPHALUS_SURFACE_ODDS == 0) || + (npc.HasEntityFlags(FLAG_CONFUSION) && npc.confusionCountdown < POLYCEPHALUS_STATUS_ENDING) || + (npc.HasEntityFlags(FLAG_FEAR | FLAG_SHRINK) && npc.fearCountdown < POLYCEPHALUS_STATUS_ENDING); + if (!isSurfacing) return; + + if (npc.type == ENTITY_POLYCEPHALUS) + { + int minion = npc.subtype == POLYCEPHALUS_RED ? ENTITY_PARA_BITE : ENTITY_ROUND_WORM; + bool isUnderCap = polycephalus_is_under_cap(npc, minion); + npc.state = (int)(Random() & 1) | POLYCEPHALUS_SHOOT; + if (npc.subtype == POLYCEPHALUS_RED) npc.state = POLYCEPHALUS_SHOOT; + if (Random() % POLYCEPHALUS_SUMMON_ODDS == 0 && isUnderCap && npc.subtype != POLYCEPHALUS_PAIR) + npc.state = POLYCEPHALUS_SUMMON; + } + else if (npc.type == ENTITY_STAIN) + { + npc.state = (Random() & 1) == 0 || isGrey ? POLYCEPHALUS_SHOOT : POLYCEPHALUS_STREAM; + bool isUnderCap = polycephalus_is_under_cap(npc, isGrey ? ENTITY_ROUND_WORM : ENTITY_CHARGER); + if ((Random() % POLYCEPHALUS_SUMMON_ODDS == 0 || isGrey) && isUnderCap) npc.state = STAIN_SUMMON; + npc.stateFrame = 0; + } + npc.i1 = 0; + npc.i2 = 0; + npc.entityCollisionClass = ENTCOLL_ALL; + polycephalus_size_reset(npc, 1); + npc.UpdateDirtColor(true); +} + +// The burrow: it goes under, then digs about until it surfaces. +static void polycephalus_burrow(Entity_NPC& npc, bool isGrey) +{ + npc.UpdateDirtColor(false); + if (npc.i1 == BURROW_START) + { + npc.sprite.Play("GoUnder"); + npc.i1 = BURROW_SINKING; + npc.i2 = 0; + npc.stateFrame = 0; + npc_sound_play(SOUND_MAGGOT_ENTER_GROUND, 1, 2, 1); + } + else if (npc.i1 == BURROW_SINKING && npc_anim_is_done(npc)) + { + npc.i1 = BURROW_MOVING; + npc.i2 = 0; + npc.stateFrame = 0; + } + else if (npc.i1 == BURROW_MOVING) polycephalus_dig(npc, isGrey); +} + +// Polycephalus's attacks once surfaced: a burst of shots (a ring for the red one), a stream lobbed where its target +// is heading, or a worm (a Para-Bite for the red one) summoned beside it. +static void polycephalus_attack(Entity_NPC& npc) +{ + if (npc.state == POLYCEPHALUS_SHOOT) + { + npc.sprite.Play("Attack1"); + if (!npc.sprite.IsEventTriggered("Shoot")) return; + Entity* target = npc.GetPlayerTarget(); + Vector lead = vector_scale(npc.GetPlayerTarget()->velocity, POLYCEPHALUS_LEAD); + Vector aim = vector_sub(vector_add(lead, target->pos), npc.pos); + npc.PlaySound(SOUND_CHILD_ANGRY_ROAR, POLYCEPHALUS_SHOOT_VOLUME, POLYCEPHALUS_SOUND_DELAY, false, 1); + if (npc.subtype == POLYCEPHALUS_RED) + return npc.FireProjectiles(npc.pos, vector_make(POLYCEPHALUS_SHOT_SPEED, POLYCEPHALUS_RED_SHOTS), + PROJECTILES_RING, ProjectileParams()); + if ((Random() & 1) == 0) + { + ProjectileParams params; + Vector velocity = vector_scale(vector_normalized(aim), POLYCEPHALUS_SHOT_SPEED); + return npc.FireProjectiles(npc.pos, velocity, PROJECTILES_THREE_WIDE, params); + } + return npc.FireProjectiles(npc.pos, vector_make(POLYCEPHALUS_SHOT_SPEED, 0), PROJECTILES_EIGHT, + ProjectileParams()); + } + + if (npc.state == POLYCEPHALUS_STREAM) + { + npc.sprite.Play("Attack2"); + npc.PlaySound(SOUND_WEIRD_WORM_SPIT, 1, POLYCEPHALUS_SOUND_DELAY, false, 1); + if (!npc.sprite.WasEventTriggered("Shoot") || npc.sprite.WasEventTriggered("StopShooting")) return; + ProjectileParams params; + Entity* target = npc.GetPlayerTarget(); + Vector lead = vector_scale(npc.GetPlayerTarget()->velocity, POLYCEPHALUS_LEAD); + npc.FireBossProjectiles(1, vector_add(lead, target->pos), POLYCEPHALUS_STREAM_ARC, params); + return; + } + + npc.sprite.Play("Attack3"); + if (!npc.sprite.IsEventTriggered("Shoot")) return; + npc.PlaySound(SOUND_SHAKEY_KID_ROAR, 1, POLYCEPHALUS_SOUND_DELAY, false, 1); + uint32_t seed = Random(); + Vector spot = vector_add(vector_scale(random_direction(), POLYCEPHALUS_WORM_REACH), npc.pos); + int type = npc.subtype == POLYCEPHALUS_RED ? ENTITY_PARA_BITE : ENTITY_ROUND_WORM; + g_game->Spawn({.position = spot, .spawner = &npc, .type = type, .seed = seed})->Update(); +} + +// The Stain's creep: a line of red puddles across it, biggest in the middle. +static void stain_creep_spread(Entity_NPC& npc) +{ + npc_sound_play(SOUND_WEIRD_WORM_SPIT, 1, 2, 1); + for (float k = -1; k <= 1; k += STAIN_CREEP_STEP) + { + uint32_t seed = Random(); + Vector spot = vector_make(k * STAIN_CREEP_REACH + npc.pos.x, k * 0 + npc.pos.y); + auto* creep = static_cast(g_game->Spawn( + {.position = spot, .spawner = &npc, .type = ENTITY_EFFECT, .variant = EFFECT_CREEP_RED, .seed = seed})); + float scale = k == 0 ? STAIN_CREEP_CENTER : std::abs(k) * STAIN_CREEP_GROWTH + STAIN_CREEP_MIN; + creep->timeout = STAIN_CREEP_TIMEOUT; + creep->lifespan = STAIN_CREEP_TIMEOUT; + creep->sprite.scale = vector_make(scale, scale); + creep->Update(); + } +} + +// One round of the Stain's spin: rings of accelerating shots turning with each, slower then faster. +static void stain_spin_shoot(Entity_NPC& npc) +{ + if (!npc.sprite.IsPlaying("Attack2Shooting")) + { + npc.sprite.Play("Attack2Shooting"); + npc_sound_play(SOUND_STAIN_ATTACK_VOX, 1, 2, 1); + } + npc.stateFrame++; + if (npc.sprite.IsEventTriggered("Shoot")) + { + bool isFast = npc.i1 == STAIN_SPIN_SHOOT_FAST; + ProjectileParams params; + params.bulletFlags |= PROJECTILE_ACCELERATE; + params.fallingAccelModifier = STAIN_SPIN_ACCEL; + params.circleAngle = (float)npc.stateFrame * (isFast ? STAIN_SPIN_FAST_TURN : STAIN_SPIN_TURN); + params.fallingSpeedModifier = STAIN_SPIN_FALL; + params.acceleration = isFast ? STAIN_SPIN_SPEEDUP : STAIN_SPIN_SLOWDOWN; + Vector ring = isFast ? vector_make(STAIN_SPIN_FAST_SPEED, STAIN_SPIN_FAST_SHOTS) + : vector_make(STAIN_SPIN_SPEED, STAIN_SPIN_SHOTS); + npc.FireProjectiles(npc.pos, ring, PROJECTILES_RING, params); + } + if (npc.stateFrame < STAIN_SPIN_FRAMES) return; + npc.i1++; + npc.i2 = 0; + npc.stateFrame = 0; +} + +// The Stain's spin: shooting, stopping, starting again faster, stopping, then going back under. +static void stain_spin(Entity_NPC& npc) +{ + switch (npc.i1) + { + case STAIN_SPIN_START: + npc.sprite.Play("Attack2Start"); + if (!npc_anim_is_done(npc)) return; + npc.i1++; + npc.i2 = 0; + return npc_sound_play(SOUND_THE_STAIN_BURST, 1, 2, 1); + case STAIN_SPIN_SHOOT: + case STAIN_SPIN_SHOOT_FAST: + return stain_spin_shoot(npc); + case STAIN_SPIN_STOP: + case STAIN_SPIN_STOP_FAST: + npc.sprite.Play("Attack2End"); + npc.stateFrame++; + if (!npc_anim_is_done(npc) || npc.stateFrame < STAIN_STOP_FRAMES) return; + npc.i1++; + npc.i2 = 0; + npc.stateFrame = 0; + return; + case STAIN_SPIN_UNDER: + npc.sprite.Play("GoUnder2"); + if (npc.i2 == 1) npc_sound_play(SOUND_MAGGOT_ENTER_GROUND, 1, 2, 1); + if (!npc_anim_is_done(npc)) return; + npc.state = NPC_STATE_MOVE; + npc.i1 = BURROW_SINKING; + npc.i2 = 0; + npc.stateFrame = 0; + return; + } +} + +// The Stain's summon: two Chargers (Round Worms for the grey one) at free spots near it, fewer for a Delirium form. +static void stain_summon(Entity_NPC& npc, bool isGrey) +{ + npc.sprite.Play("Summon"); + if (!npc.sprite.IsEventTriggered("Summon")) return; + npc_sound_play(SOUND_SUMMONSOUND, 1, 2, 1); + + int count = STAIN_SUMMON_PAIR; + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM)) + { + int spare = POLYCEPHALUS_ENEMY_LIMIT - npc.CountRelatedEntities(ENTITY_ROUND_WORM, 0, nullptr) - + npc.CountRelatedEntities(ENTITY_CHARGER, 0, nullptr); + if (spare < POLYCEPHALUS_ENEMY_LIMIT) count = spare; + } + for (int i = 0; i < count; i++) + { + uint32_t seed = Random(); + Vector spot = room_free_pickup_position_find({.position = npc.pos, .step = STAIN_SUMMON_REACH}); + g_game->Spawn( + {.position = spot, .spawner = &npc, .type = isGrey ? ENTITY_ROUND_WORM : ENTITY_CHARGER, .seed = seed}); + } +} + +// Surfacing (ComeUp, the Stain's spin from ComeUp2), then its attack, back to idle once that ends. +static void polycephalus_surface(Entity_NPC& npc, bool isGrey) +{ + bool isStain = npc.type == ENTITY_STAIN; + if (npc.i1 == 0) + { + if (isStain) + { + npc.sprite.Play(npc.state == POLYCEPHALUS_STREAM ? "ComeUp2" : "ComeUp"); + if (npc.i2 == 1) + { + npc_sound_play(SOUND_MAGGOT_BURST_OUT, 1, 2, 1); + npc_sound_play(SOUND_THE_STAIN_BURST, 1, 2, 1); + } + } + else + { + npc.sprite.Play("ComeUp"); + npc.PlaySound(SOUND_MULTI_SCREAM, POLYCEPHALUS_SURFACE_VOLUME, POLYCEPHALUS_SOUND_DELAY, false, 1); + } + if (!npc_anim_is_done(npc)) return; + npc.i1 = 1; + npc.i2 = 0; + return; + } + + if (isStain && npc.state == POLYCEPHALUS_STREAM) return stain_spin(npc); + if (isStain && npc.state == POLYCEPHALUS_SHOOT) + { + npc.sprite.Play("Attack1"); + if (npc.sprite.IsEventTriggered("Shoot")) stain_creep_spread(npc); + } + else if (isStain) stain_summon(npc, isGrey); + else polycephalus_attack(npc); + if (npc_anim_is_done(npc)) npc.state = NPC_STATE_IDLE; +} + +// 00489ca0 NpcAI::ENTITY_POLYCEPHALUS: Polycephalus and the Stain burrow about and surface near their target to +// shoot, spray creep, spin rings of shots or summon. The Pile (variant 1) has its own AI. +void boss_polycephalus_update(Entity_NPC& npc) +{ + if (npc.variant == POLYCEPHALUS_PILE) return (void)NpcAI::ENTITY_POLYCEPHALUS_the_pile(&npc); + bool isGrey = npc.type == ENTITY_STAIN && npc.subtype == STAIN_GREY; + npc.i2++; + + if (npc.state == NPC_STATE_INIT) + { + npc.state = NPC_STATE_IDLE; + bool isTwin = npc.spawnerType == ENTITY_POLYCEPHALUS; + if (npc.subtype == POLYCEPHALUS_PAIR && npc.type == ENTITY_POLYCEPHALUS && !isTwin) + { + uint32_t seed = Random(); + Vector spot = vector_add(vector_scale(random_direction(), POLYCEPHALUS_TWIN_REACH), npc.pos); + g_game->Spawn({.position = spot, + .velocity = npc.velocity, + .spawner = &npc, + .subType = npc.subtype, + .type = npc.type, + .variant = npc.variant, + .seed = seed}); + } + return npc.UpdateDirtColor(true); + } + + bool isSurfaced = npc.state == POLYCEPHALUS_SHOOT || npc.state == POLYCEPHALUS_STREAM || + (npc.type == ENTITY_POLYCEPHALUS ? npc.state == POLYCEPHALUS_SUMMON : npc.state == STAIN_SUMMON); + if (npc.state == NPC_STATE_IDLE) + { + npc.sprite.Play("Idle"); + if (!(npc.HasEntityFlags(FLAG_DELIRIUM_FORM) && room_is_clear()) && Random() % POLYCEPHALUS_BURROW_ODDS == 0) + { + npc.state = NPC_STATE_MOVE; + npc.i1 = BURROW_START; + npc.i2 = 0; + } + } + else if (npc.state == NPC_STATE_MOVE) polycephalus_burrow(npc, isGrey); + else if (isSurfaced) polycephalus_surface(npc, isGrey); + + npc.friction *= POLYCEPHALUS_FRICTION; + if (npc.isDead) polycephalus_size_reset(npc, 1); +} diff --git a/src/boss_pool.cpp b/src/boss_pool.cpp index 42f25ba..0e1263d 100644 --- a/src/boss_pool.cpp +++ b/src/boss_pool.cpp @@ -1,5 +1,6 @@ #include "boss_pool.h" #include "data.h" +#include "entity_player.h" #include "game.h" #include "log.h" #include "manager.h" @@ -50,7 +51,6 @@ constexpr int SPECIAL_DAILY_DARK_BOSSES = 13; constexpr std::array SPECIAL_DAILY_BOSSES = {0, 60, 43, 50, 23, 51, 0, 15}; constexpr int ACHIEVEMENT_HARBINGERS = 5; -constexpr int ACHIEVEMENT_IT_LIVES = 34; constexpr int ACHIEVEMENT_FORGOTTEN_HORSEMAN = 66; constexpr int STAGE_CHAPTER_1 = 1; @@ -59,8 +59,6 @@ constexpr int STAGE_CHAPTER_2_END = 4; constexpr int STAGE_CHAPTER_3 = 5; constexpr int STAGE_CHAPTER_4 = 7; -constexpr int CHALLENGE_APRILS_FOOL = 32; -constexpr int CHALLENGE_ULTRA_HARD = 34; constexpr int CHALLENGE_SCAT_MAN = 36; // A pool element's name and the stage id (StbType) whose pool it fills. diff --git a/src/boss_widow.cpp b/src/boss_widow.cpp new file mode 100644 index 0000000..de3d72c --- /dev/null +++ b/src/boss_widow.cpp @@ -0,0 +1,372 @@ +#include "boss_ai.h" +#include "entity_effect.h" +#include "npc_caves.h" +#include "room_grid.h" +#include "sfx_manager.h" +#include + +// The Widow (variant 0) and the Wretched (variant 1), and the Widow's black and pale subtypes. +constexpr int WRETCHED = 1; +constexpr int WIDOW_BLACK = 1; +constexpr int WIDOW_PALE = 2; + +// The Widow's states: idle, the leap, the egg sac and its creep, and the spider cough. +constexpr int WIDOW_JUMP = NPC_STATE_JUMP; +constexpr int WIDOW_EGGS = NPC_STATE_ATTACK; +constexpr int WIDOW_COUGH = NPC_STATE_ATTACK2; + +// The Widow's sacs: a Sack, a Boil for the pale one, a Big Spider for the black one. +constexpr int WIDOW_SACK = 2; + +constexpr float WIDOW_FRICTION = 0.8f; +constexpr float WIDOW_JUMP_FRICTION = 0.9f; +constexpr float WIDOW_LEAP_FRICTION = 0.7f; +constexpr uint32_t WIDOW_LEAP_ODDS = 3; +constexpr float WIDOW_LEAP_REACH = 100; +constexpr float WIDOW_LEAP_SPEED = 7; +constexpr int WIDOW_CROWD = 5; +constexpr int WIDOW_SUMMON_ENEMY_LIMIT = 6; +constexpr int WIDOW_DELIRIUM_MINION_LIMIT = 3; +constexpr float WIDOW_PALE_PLAYBACK = 1.4f; + +constexpr float WIDOW_LAND_DUST_HEIGHT = 15; +constexpr float WIDOW_LAND_DUST_WIDTH = 1.3f; +constexpr float WIDOW_CRUSH_RADIUS = 60; +constexpr float WIDOW_CRUSH_DAMAGE = 100; +constexpr int WIDOW_CRUSH_COUNTDOWN = 30; +constexpr ColorMod WIDOW_DUST_COLOR = {{0.8f, 0.8f, 0.8f, 0.7f}, {0, 0, 0, 0}, {0, 0, 0}}; + +constexpr float WRETCHED_SHOT_OFFSET = 140 / 255.0f; +constexpr ColorMod WRETCHED_SHOT_COLOR = { + {0.3f, 0.8f, 0.8f, 1}, {0, 0, 0, 0}, {WRETCHED_SHOT_OFFSET, WRETCHED_SHOT_OFFSET, WRETCHED_SHOT_OFFSET}}; +constexpr float WRETCHED_SHOT_SPEED = 10; +constexpr int WIDOW_SAC_LIMIT = 3; +constexpr int WIDOW_DELIRIUM_SAC_LIMIT = 2; +constexpr float WIDOW_SAC_DROP = 30; +constexpr float WIDOW_SAC_HEALTH = 10; + +constexpr float WIDOW_CREEP_SPREAD = 3; +constexpr float WIDOW_CREEP_GROWTH = 0.2f; +constexpr float WIDOW_CREEP_VOLUME = 1.5f; +constexpr float WIDOW_SPLASH_REACH = 6; +constexpr ColorMod WIDOW_BLACK_CREEP_COLOR = {{1, 1, 1, 1}, {0.4f, 0.43f, 0.45f, 1}, {0, 0, 0}}; +constexpr ColorMod WIDOW_CREEP_COLOR = {{0, 0, 0, 1}, {0, 0, 0, 0}, {1, 1, 1}}; + +constexpr float WIDOW_COUGH_VOLUME = 1.6f; +constexpr ColorMod WIDOW_CLOUD_COLOR = {{0, 0, 0, 0.55f}, {0, 0, 0, 0}, {0.4f, 0.38f, 0.34f}}; +constexpr float WIDOW_CLOUD_SCALE = 0.75f; +constexpr float WIDOW_CLOUD_HEIGHT = -40; +constexpr int WIDOW_SPIDERS = 2; +constexpr uint32_t WRETCHED_TRITE_ODDS = 3; +constexpr float WRETCHED_TRITE_REACH = 50; +constexpr int WRETCHED_TRITE_FRAME = 5; +constexpr int WRETCHED_SPIDER_ENEMY_LIMIT = 5; +constexpr float WIDOW_SPIDER_REACH = 100; +constexpr float WIDOW_SPIDER_HEIGHT = -30; +constexpr float WIDOW_FLY_SPEED = 13; +constexpr float WIDOW_FLY_SPREAD = 0.4f; +constexpr float WIDOW_RING_HEIGHT = -15; +constexpr float WIDOW_RING_SPEED = 8; +constexpr float WIDOW_RING_SHOTS = 6; +constexpr int WRETCHED_DEATH_SPIDERS = 3; + +// The minions a Delirium form counts before summoning more: Striders, spiders, and Attack Flies (Trites for the +// Wretched). +static int widow_minion_count(Entity_NPC& npc) +{ + int related = npc.CountRelatedEntities(ENTITY_STRIDER, 0, nullptr) + + npc.CountRelatedEntities(ENTITY_BIG_SPIDER, 0, nullptr) + + npc.CountRelatedEntities(ENTITY_SPIDER, 0, nullptr); + if (npc.variant == WRETCHED) return related + npc.CountRelatedEntities(ENTITY_HOPPER, HOPPER_TRITE, nullptr); + return related + npc.CountRelatedEntities(ENTITY_ATTACKFLY, 0, nullptr); +} + +// A free spot near a position, which the spiders are thrown at. +static Vector widow_spot_find(const Vector& position, float step) +{ + return room_free_pickup_position_find({.position = position, .step = step}); +} + +// Idle: a leap at its target when far (one time in three) or the room is crowded, else a pause, the egg sac or a +// spider cough at random. A Widow that laid a sac leaps next. +static void widow_idle(Entity_NPC& npc, Vector toTarget) +{ + npc.sprite.Play("Idle"); + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM) && room_is_clear()) return; + + bool isLeap = Random() % WIDOW_LEAP_ODDS == 0 && vector_length(toTarget) > WIDOW_LEAP_REACH; + if (!isLeap && npc.variant == 0 && g_game->room->GetAliveEnemiesCount() > WIDOW_CROWD) isLeap = true; + if (!isLeap && npc.i1 < 1) + { + std::vector moves = {NPC_STATE_MOVE, WIDOW_EGGS}; + bool isSummon = g_game->room->GetAliveEnemiesCount() < WIDOW_SUMMON_ENEMY_LIMIT || npc.variant == 0; + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM)) isSummon = widow_minion_count(npc) < WIDOW_DELIRIUM_MINION_LIMIT; + if (isSummon) moves.push_back(WIDOW_COUGH); + npc.stateFrame = 0; + npc.state = moves[random_below((int)moves.size())]; + return; + } + + npc.i1 = 0; + npc.stateFrame = 0; + npc.state = WIDOW_JUMP; + npc.friction *= WIDOW_LEAP_FRICTION; + npc.v1 = vector_scale(vector_normalized(toTarget), WIDOW_LEAP_SPEED); +} + +// The leap: airborne between Jump and Land, then a puff of dust where it lands that crushes the other enemies near it. +static void widow_jump(Entity_NPC& npc) +{ + npc.sprite.Play("Jump"); + if (npc.subtype == WIDOW_PALE) npc.sprite.playbackSpeed = WIDOW_PALE_PLAYBACK; + + if (npc.sprite.animState.animData) + { + if (npc.sprite.IsEventTriggered("Jump")) npc.PlaySound(SOUND_BOSS_LITE_ROAR, 1, 2, false, 1); + else if (npc.sprite.IsEventTriggered("Land")) + { + npc.PlaySound(SOUND_FORESTBOSS_STOMPS, 1, 2, false, 1); + auto* dust = static_cast(g_game->Spawn({.position = npc.pos, + .spawner = &npc, + .subType = 2, + .type = ENTITY_EFFECT, + .variant = EFFECT_POOF02, + .seed = Random()})); + dust->sprite.isFlipX = (Random() & 1) == 0; + dust->sprite.offset = vector_make(0, WIDOW_LAND_DUST_HEIGHT); + dust->sprite.scale = vector_make(WIDOW_LAND_DUST_WIDTH, 1); + dust->SetColor(WIDOW_DUST_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); + dust->FollowParent(&npc); + dust->Update(); + for (Entity* entity : entity_query_radius(npc.pos, WIDOW_CRUSH_RADIUS, QUERY_ALL)) + if (entity->type >= ENTITY_FIRST_ENEMY && entity->type != npc.type) + entity->TakeDamage(WIDOW_CRUSH_DAMAGE, 0, EntityRef(&npc), WIDOW_CRUSH_COUNTDOWN); + } + + if (npc.sprite.WasEventTriggered("Jump") && !npc.sprite.WasEventTriggered("Land")) + { + npc.entityCollisionClass = ENTCOLL_NONE; + npc.entityGridCollisionClass = GRIDCOLL_WALLS; + npc_push(npc, npc.v1); + } + if (!npc_anim_is_done(npc)) + { + npc.friction *= WIDOW_JUMP_FRICTION; + return; + } + } + npc.state = NPC_STATE_MOVE; + npc.sprite.playbackSpeed = 1; +} + +// The egg sac's creep: from Shoot to Jump, one puddle a tick in a widening ring, each bigger, with a splash. +static void widow_creep_spread(Entity_NPC& npc) +{ + bool isBlack = npc.subtype == WIDOW_BLACK; + const ColorMod& color = isBlack ? WIDOW_BLACK_CREEP_COLOR : WIDOW_CREEP_COLOR; + for (int ticks = npc_ticks_get(npc); ticks > 0; ticks--) + { + float angle = random_unit() * RANDOM_HALF_TURN; + angle += angle; + float reach = (float)npc.stateFrame * WIDOW_CREEP_SPREAD; + Vector spot = vector_make(std::cos(angle) * reach + npc.pos.x, std::sin(angle) * reach + npc.pos.y); + + Entity* creep = g_game->Spawn({.position = spot, + .spawner = &npc, + .type = ENTITY_EFFECT, + .variant = isBlack ? EFFECT_CREEP_BLACK : EFFECT_CREEP_WHITE, + .seed = Random()}); + creep->sprite.scale = vector_scale(vector_make(1, 1), (float)npc.stateFrame * WIDOW_CREEP_GROWTH + 1); + creep->Update(); + npc_sound_play(SOUND_BOSS2_BUBBLES, WIDOW_CREEP_VOLUME, 2, champion_pitch_get(npc)); + + Vector splashOffset = vector_scale(vector_normalized(vector_sub(spot, npc.pos)), WIDOW_SPLASH_REACH); + blood_explosion_spawn(2, spot, splashOffset, color, {}); + npc.stateFrame++; + } +} + +// The egg sac: on Shoot a sac drops beneath it (at most three about, two for a Delirium form), or the Wretched shoots +// eight tinted shots. Then its creep spreads until Jump. +static void widow_eggs(Entity_NPC& npc) +{ + npc.sprite.Play("Attack01"); + if (npc.sprite.animState.animData && npc.sprite.IsEventTriggered("Shoot")) + { + if (npc.variant == WRETCHED) + { + ProjectileParams params; + params.color = WRETCHED_SHOT_COLOR; + npc.FireProjectiles(npc.pos, vector_make(WRETCHED_SHOT_SPEED, 0), PROJECTILES_EIGHT, params); + } + else + { + int type = npc.subtype == WIDOW_BLACK ? ENTITY_BIG_SPIDER : ENTITY_BOIL; + int variant = npc.subtype == WIDOW_BLACK || npc.subtype == WIDOW_PALE ? 0 : WIDOW_SACK; + size_t sacs = entity_query(type, variant).size(); + if (sacs < WIDOW_SAC_LIMIT && (!npc.HasEntityFlags(FLAG_DELIRIUM_FORM) || sacs < WIDOW_DELIRIUM_SAC_LIMIT)) + { + Entity* sac = g_game->Spawn({.position = vector_make(npc.pos.x, npc.pos.y + WIDOW_SAC_DROP), + .spawner = &npc, + .type = type, + .variant = variant, + .seed = Random()}); + sac->health = WIDOW_SAC_HEALTH; + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM)) + { + sac->Update(); + sac->health = 1; + sac->maxHitPoints = 1; + } + } + npc.i1++; + } + npc.stateFrame = 0; + } + if (!npc.sprite.animState.animData) + { + npc.state = NPC_STATE_MOVE; + return; + } + + if (npc.sprite.WasEventTriggered("Shoot") && !npc.sprite.WasEventTriggered("Jump")) widow_creep_spread(npc); + if (npc_anim_is_done(npc)) npc.state = NPC_STATE_MOVE; +} + +// The Wretched's cough: a Trite hopping at its target one time in three, else (one time in two, while few enemies +// are about) a few spiders, else a big spider. +static void wretched_cough(Entity_NPC& npc, int spiders) +{ + if (Random() % WRETCHED_TRITE_ODDS == 0) + { + auto* trite = static_cast(g_game->Spawn({.position = npc.pos, + .spawner = &npc, + .type = ENTITY_HOPPER, + .variant = HOPPER_TRITE, + .seed = Random()})); + trite->targetPosition = widow_spot_find(npc.GetPlayerTarget()->pos, WRETCHED_TRITE_REACH); + trite->state = NPC_STATE_MOVE; + trite->stateFrame = WRETCHED_TRITE_FRAME; + npc_anim_restart(trite->sprite, "Hop"); + if (trite->sprite.animState.animData) trite->sprite.animState.SetFrameFloat(WRETCHED_TRITE_FRAME); + return; + } + + if ((Random() & 1) == 0 && g_game->room->GetAliveEnemiesCount() < WRETCHED_SPIDER_ENEMY_LIMIT) + { + for (; spiders > 0; spiders--) + Entity_NPC::ThrowSpider(npc.pos, &npc, widow_spot_find(npc.pos, WIDOW_SPIDER_REACH), false, + WIDOW_SPIDER_HEIGHT); + return; + } + Entity_NPC::ThrowSpider(npc.pos, &npc, widow_spot_find(npc.pos, WIDOW_SPIDER_REACH), true, WIDOW_SPIDER_HEIGHT); +} + +// An Attack Fly the pale Widow coughs, already awake and dying on touch. +static void widow_fly_spawn(Entity_NPC& npc, uint32_t seed, Vector velocity) +{ + Entity* fly = g_game->Spawn( + {.position = npc.pos, .velocity = velocity, .spawner = &npc, .type = ENTITY_ATTACKFLY, .seed = seed}); + fly->ClearEntityFlags(FLAG_APPEAR); + fly->isKillOnTouch = true; +} + +// The cough: a cloud of dust, then a spider thrown nearby, two Attack Flies at its target for the pale one, a ring of +// six shots for the black one, or the Wretched's own. A Delirium form throws fewer while its minions are about. +static void widow_cough(Entity_NPC& npc, Vector toTarget) +{ + npc.sprite.Play("Attack02"); + npc.stateFrame++; + if (npc.sprite.IsEventTriggered("Jump")) npc.PlaySound(SOUND_WHEEZY_COUGH, WIDOW_COUGH_VOLUME, 2, false, 1); + if (!npc.sprite.IsEventTriggered("Shoot")) + { + if (npc_anim_is_done(npc)) npc.state = NPC_STATE_MOVE; + return; + } + + Entity_Effect* cloud = npc.MakeBloodCloud(npc.pos, WIDOW_CLOUD_COLOR, WIDOW_CLOUD_SCALE); + cloud->posOffset = vector_make(0, WIDOW_CLOUD_HEIGHT); + int spiders = WIDOW_SPIDERS; + if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM)) + { + int spare = WIDOW_DELIRIUM_MINION_LIMIT - widow_minion_count(npc); + if (spare < WIDOW_DELIRIUM_MINION_LIMIT) spiders = spare; + } + + if (npc.variant == WRETCHED) return wretched_cough(npc, spiders); + if (npc.subtype == WIDOW_PALE) + { + Vector aim = vector_scale(vector_normalized(toTarget), WIDOW_FLY_SPEED); + Vector spread = vector_scale(vector_make(aim.y, aim.x), WIDOW_FLY_SPREAD); + uint32_t seed = Random(); + widow_fly_spawn(npc, seed, vector_make(aim.x + spread.x, spread.y + aim.y)); + if (spiders > 1) + { + seed = Random(); + widow_fly_spawn(npc, seed, vector_make(aim.x - spread.x, aim.y - spread.y)); + } + return; + } + if (npc.subtype == WIDOW_BLACK) + { + npc.PlaySound(SOUND_BLOODSHOOT, 1, 2, false, 1); + Vector mouth = vector_make(npc.pos.x, npc.pos.y + WIDOW_RING_HEIGHT); + Vector ring = vector_make(WIDOW_RING_SPEED, WIDOW_RING_SHOTS); + npc.FireProjectiles(mouth, ring, PROJECTILES_RING, ProjectileParams()); + return; + } + Entity_NPC::ThrowSpider(npc.pos, &npc, widow_spot_find(npc.pos, WIDOW_SPIDER_REACH), false, WIDOW_SPIDER_HEIGHT); +} + +// Its death: the Wretched throws three spiders, and a Delirium form kills the sacs it laid. +static void widow_death(Entity_NPC& npc) +{ + if (npc.variant == WRETCHED) + for (int i = 0; i < WRETCHED_DEATH_SPIDERS; i++) + { + widow_spot_find(npc.pos, WIDOW_SPIDER_REACH); + Entity_NPC::ThrowSpider(npc.pos, &npc, {}, false, WIDOW_SPIDER_HEIGHT); + } + if (!npc.HasEntityFlags(FLAG_DELIRIUM_FORM)) return; + + std::vector laid; + for (Entity* entity : g_game->room->entityList.updateEL) + if (entity->spawnerType == npc.type) laid.push_back(entity); + for (Entity* entity : laid) + if (entity != &npc && dynamic_cast(entity) && entity->type == ENTITY_BOIL) + entity->Kill(EntityRef()); +} + +// 0046fbe0 NpcAI::ENTITY_WIDOW: the Widow and the Wretched leap at their target crushing what they land by, lay egg +// sacs in spreading creep, and cough spiders. +void boss_widow_update(Entity_NPC& npc) +{ + if (npc.state == NPC_STATE_INIT) + { + npc.state = NPC_STATE_MOVE; + return; + } + + npc.friction *= WIDOW_FRICTION; + Vector toCalc = vector_sub(npc.CalcTargetPosition(0), npc.pos); + Vector toTarget = vector_sub(npc.GetPlayerTarget()->pos, npc.pos); + npc.entityCollisionClass = ENTCOLL_PLAYEROBJECTS; + npc.entityGridCollisionClass = GRIDCOLL_GROUND; + + switch (npc.state) + { + case NPC_STATE_MOVE: + widow_idle(npc, toCalc); + break; + case WIDOW_JUMP: + widow_jump(npc); + break; + case WIDOW_EGGS: + widow_eggs(npc); + break; + case WIDOW_COUGH: + widow_cough(npc, toTarget); + break; + } + if (npc.isDead) widow_death(npc); +} diff --git a/src/camera.cpp b/src/camera.cpp index ddf4fc5..39ebf88 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -1,5 +1,6 @@ #include "camera.h" #include "entity_knife.h" +#include "entity_laser.h" #include "entity_list.h" #include "entity_player.h" #include "game.h" @@ -64,8 +65,6 @@ constexpr float FOLLOW_NEAR = 338; constexpr float NET_VIEW_HALF_WIDTH = 369.23077f; constexpr float NET_VIEW_HALF_HEIGHT = 207.6923f; -constexpr int LASER_VARIANT_THICK_RED = 1; -constexpr int LASER_VARIANT_THICKER_RED = 3; constexpr int ITEM_STATE_LUDOVICO_CHARGE = 49; constexpr int COLLECTIBLE_LUDOVICO_TECHNIQUE = 329; @@ -329,7 +328,7 @@ void Camera::update_focus_position(bool isSkipFocusBuffer) for (Entity* laser : room->entityList.updateEL) { if (laser->type != ENTITY_LASER) continue; - bool isThick = laser->variant == LASER_VARIANT_THICK_RED || laser->variant == LASER_VARIANT_THICKER_RED; + bool isThick = laser->variant == LASER_THICK_RED || laser->variant == LASER_SHOOP; if (isThick && laser->spawnerType == ENTITY_PLAYER && laser->spawnerVariant == 0) aim = vector_make(lead * player->lastDirection.x, lead * player->lastDirection.y); } diff --git a/src/capsule.cpp b/src/capsule.cpp new file mode 100644 index 0000000..c763241 --- /dev/null +++ b/src/capsule.cpp @@ -0,0 +1,140 @@ +#include "capsule.h" +#include "npc_ai.h" +#include + +// Below this squared length a segment counts as a point. +constexpr float SEGMENT_MIN_LENGTH_SQUARED = 0.0001f; + +// 00945190 A capsule around a position for an entity's size, stretched along its longer axis and turned by rotation +// degrees. The shorter axis gives the radius. +Capsule::Capsule(const Vector& position, const Vector& sizeMulti, float rotation, float size) +{ + float width = size * sizeMulti.x; + float height = size * sizeMulti.y; + float sine = std::sin(rotation * DEGREES_TO_RADIANS); + float cosine = std::cos(rotation * DEGREES_TO_RADIANS); + + center = position; + radius = std::min(width, height); + halfLength = std::max(width, height) - radius; + direction = width <= height ? vector_make(sine, cosine) : vector_make(cosine, sine); + start = vector_make(center.x - halfLength * direction.x, center.y - halfLength * direction.y); + end = vector_make(halfLength * direction.x + center.x, halfLength * direction.y + center.y); +} + +// 009452e0 A capsule of a radius along the segment between two points. +Capsule::Capsule(const Vector& from, const Vector& to, float size) +{ + Vector delta = vector_sub(to, from); + float length = std::sqrt(delta.y * delta.y + delta.x * delta.x); + + start = from; + end = to; + direction = length <= 0 ? Vector{} : vector_make(delta.x / length, delta.y / length); + radius = size; + halfLength = length * 0.5f; + center = vector_make((end.x + start.x) * 0.5f, (start.y + end.y) * 0.5f); +} + +// 00945400 The box around the capsule. +void Capsule::get_bounding_box(Vector& outMin, Vector& outMax) const +{ + Vector extent = vector_make(std::fabs(direction.x) * halfLength + radius, + std::fabs(direction.y) * halfLength + radius); + + outMin = vector_sub(center, extent); + outMax = vector_make(extent.x + center.x, extent.y + center.y); +} + +// The offset from the segment's closest point to a point. +static Vector segment_offset(Vector point, Vector from, Vector to) +{ + Vector delta = vector_sub(to, from); + Vector offset = vector_sub(point, from); + float lengthSquared = delta.y * delta.y + delta.x * delta.x; + if (std::fabs(lengthSquared) < SEGMENT_MIN_LENGTH_SQUARED) return offset; + + float t = (delta.y * offset.y + delta.x * offset.x) / lengthSquared; + if (t < 0) return offset; + if (t >= 1) return vector_sub(point, to); + return vector_make(point.x - (delta.x * t + from.x), point.y - (delta.y * t + from.y)); +} + +// How far apart crossing segments must move: from where they cross to the nearest end, plus that end's radius. +static Vector crossing_separation(const Capsule& a, const Capsule& b) +{ + Vector alongA = vector_sub(a.end, a.start); + Vector alongB = vector_sub(b.end, b.start); + float denominator = alongB.x * alongA.y - alongB.y * alongA.x; + if (denominator == 0) return {}; + + float t = ((a.start.x - b.start.x) * alongA.y + (b.start.y - a.start.y) * alongA.x) / denominator; + float u = ((a.start.y - b.start.y) * alongB.x + (b.start.x - a.start.x) * alongB.y) / -denominator; + if (!(t >= 0 && t <= 1 && u >= 0 && u <= 1)) return {}; + + Vector crossing = vector_make(alongA.x * t + a.start.x, alongA.y * t + a.start.y); + Vector candidates[] = {vector_sub(crossing, a.start), vector_sub(crossing, a.end), vector_sub(b.start, crossing), + vector_sub(b.end, crossing)}; + Vector separation = candidates[0]; + float best = vector_length_squared(separation); + float radius = a.radius; + for (int i = 1; i < 4; i++) + { + float distance = vector_length_squared(candidates[i]); + if (distance >= best) continue; + + best = distance; + separation = candidates[i]; + if (i >= 2) radius = b.radius; + } + return vector_scale(vector_normalized(separation), std::sqrt(best) + radius); +} + +// 00945470 Whether two capsules overlap, and the push that moves b out of a (left as the nearest offset when they +// do not). Crossing segments are first parted by their crossing's separation, which all four ends move by. +bool Capsule::Collide(const Capsule& a, const Capsule& b, Vector* outHit) +{ + Vector separation = crossing_separation(a, b); + Capsule movedA = a; + Capsule movedB = b; + if (!vector_is_zero(separation)) + for (Vector* point : {&movedA.start, &movedA.end, &movedB.start, &movedB.end}) + *point = vector_add(*point, separation); + + Vector startToB = vector_scale(segment_offset(movedA.start, movedB.start, movedB.end), -1); + Vector endToB = vector_scale(segment_offset(movedA.end, movedB.start, movedB.end), -1); + Vector fromStartOfA = segment_offset(movedB.start, movedA.start, movedA.end); + Vector fromEndOfA = segment_offset(movedB.end, movedA.start, movedA.end); + + float toBDistance = vector_length_squared(startToB); + Vector toB = startToB; + if (vector_length_squared(endToB) <= toBDistance) + { + toBDistance = vector_length_squared(endToB); + toB = endToB; + } + float fromADistance = vector_length_squared(fromEndOfA); + Vector fromA = fromEndOfA; + if (vector_length_squared(fromStartOfA) < fromADistance) + { + fromADistance = vector_length_squared(fromStartOfA); + fromA = fromStartOfA; + } + + float distanceSquared = fromADistance <= toBDistance ? fromADistance : toBDistance; + Vector hit = fromADistance <= toBDistance ? fromA : toB; + float reach = a.radius + b.radius; + if (outHit) *outHit = hit; + if (reach * reach <= distanceSquared) return false; + if (!outHit) return true; + if (distanceSquared == 0) + { + *outHit = separation; + return true; + } + + float distance = std::sqrt(distanceSquared); + *outHit = vector_make(hit.x / distance * (reach - distance) + separation.x, + hit.y / distance * (reach - distance) + separation.y); + return true; +} diff --git a/src/capsule.h b/src/capsule.h new file mode 100644 index 0000000..6a95024 --- /dev/null +++ b/src/capsule.h @@ -0,0 +1,22 @@ +#pragma once + +#include "classes.h" + +// A stretched circle (Capsule): a segment from start to end around center, along direction, widened by radius. +// Entities that are not round collide as one. +struct Capsule +{ + Vector center{}; + Vector direction{}; + Vector end{}; + Vector start{}; + float halfLength = 0; + float radius = 0; + + Capsule() = default; + Capsule(const Vector& position, const Vector& sizeMulti, float rotation, float size); + Capsule(const Vector& from, const Vector& to, float size); + + void get_bounding_box(Vector& outMin, Vector& outMax) const; + static bool Collide(const Capsule& a, const Capsule& b, Vector* outHit = nullptr); +}; diff --git a/src/console.cpp b/src/console.cpp index cd1beb5..2aa8ddc 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -361,12 +361,6 @@ void Console::print_format(uint32_t color, const char* format, ...) Print(text, color); } -// 0068cdc0 Runs a command, printing its output into output when given, for a player when given. -void Console::RunCommand(std::string_view, std::string*, Entity_Player*) -{ - reconstruction_missing("Console::RunCommand 0068cdc0"); -} - // 00686910 The view at the newest line: past an empty newest line onto the last one written. ConsoleScroll Console::scroll_min_get() { @@ -659,7 +653,7 @@ void Console::input_submit() input.clear(); inputBreaks.clear(); cursor = 0; - RunCommand(command, nullptr, nullptr); + RunCommand(command); scroll = scroll_min_get(); } diff --git a/src/console.h b/src/console.h index 14658a7..34c9415 100644 --- a/src/console.h +++ b/src/console.h @@ -17,6 +17,7 @@ constexpr uint32_t CONSOLE_ECHO = 0xff808080; // How many frames a printed line stays on the faded display. constexpr int CONSOLE_FADE_FRAMES = 150; constexpr int CONSOLE_SUGGESTION_COUNT = 6; +constexpr int DELIRIOUS_BOSS_COUNT = 59; // Where the console is in sliding open and closed. Nothing known sets CONSOLE_REOPEN, which snaps back to open. enum ConsoleState : int @@ -42,6 +43,32 @@ enum HistoryFade HISTORY_FADED }; +// A boss Delirious and the delirious command spawn as a friend, as Entity_Player::console_spawn reads it: its health +// and how many come. +struct DeliriousBoss +{ + int type = 0; + int variant = 0; + float health = 0; + int count = 1; +}; + +// The bosses Delirious picks from (0x00c33d80). +inline constexpr DeliriousBoss DELIRIOUS_BOSSES[DELIRIOUS_BOSS_COUNT] = { + {268, 0, 100, 1}, {74, 0, 40, 1}, {411, 0, 100, 1}, {79, 2, 100, 1}, {68, 1, 100, 1}, {402, 0, 100, 1}, + {265, 0, 100, 1}, {28, 2, 100, 3}, {28, 1, 100, 3}, {28, 0, 100, 3}, {65, 1, 100, 1}, {101, 0, 100, 1}, + {261, 1, 100, 1}, {267, 0, 100, 1}, {66, 0, 100, 1}, {261, 0, 100, 1}, {67, 0, 100, 1}, {81, 0, 100, 1}, + {63, 0, 100, 1}, {71, 0, 25, 1}, {403, 0, 100, 1}, {62, 2, 100, 1}, {79, 0, 100, 1}, {43, 1, 100, 1}, + {36, 0, 100, 1}, {99, 0, 100, 1}, {237, 1, 100, 1}, {82, 0, 100, 1}, {19, 1, 100, 3}, {407, 0, 180, 1}, + {67, 1, 100, 1}, {19, 0, 100, 3}, {404, 0, 100, 1}, {69, 0, 100, 1}, {69, 1, 100, 1}, {97, 0, 100, 1}, + {264, 0, 100, 1}, {262, 0, 100, 1}, {20, 0, 100, 1}, {43, 0, 100, 1}, {270, 0, 100, 1}, {68, 0, 100, 1}, + {64, 0, 100, 1}, {62, 0, 100, 1}, {269, 0, 100, 1}, {405, 0, 100, 1}, {409, 0, 100, 1}, {62, 1, 100, 1}, + {410, 0, 100, 1}, {401, 0, 100, 1}, {79, 1, 100, 1}, {71, 1, 25, 1}, {263, 0, 100, 1}, {260, 0, 100, 1}, + {101, 1, 100, 1}, {237, 2, 100, 1}, {65, 0, 100, 1}, {100, 0, 100, 1}, {100, 1, 100, 1}}; + +// The collectible the metro command makes the Metronome become, 0 for a random one (0x00c7166c). +extern int g_metronomeItem; + // The console's font for the ConsoleFont option, with its row height and how far its glyphs sit from their row. struct ConsoleText { @@ -104,7 +131,7 @@ struct Console void Print(std::string_view text, uint32_t color = CONSOLE_WHITE, int fadeFrames = CONSOLE_FADE_FRAMES); void PrintError(std::string_view error); void print_format(uint32_t color, const char* format, ...) __attribute__((format(printf, 3, 4))); - void RunCommand(std::string_view command, std::string* output, Entity_Player* player); + void RunCommand(std::string_view command, std::string* output = nullptr, Entity_Player* player = nullptr); bool update_state(); void Update(); @@ -132,3 +159,5 @@ private: }; ConsoleText console_text_get(); +std::vector text_split(std::string_view text, char delimiter); +std::string lua_code_run(std::string_view code); diff --git a/src/console_commands.cpp b/src/console_commands.cpp new file mode 100644 index 0000000..7cc9ac3 --- /dev/null +++ b/src/console_commands.cpp @@ -0,0 +1,1066 @@ +#include "anm2.h" +#include "console.h" +#include "entity_config.h" +#include "entity_factory.h" +#include "entity_familiar.h" +#include "entity_list.h" +#include "entity_npc.h" +#include "entity_pickup.h" +#include "entity_player.h" +#include "game.h" +#include "grid_entity.h" +#include "hud.h" +#include "item_config.h" +#include "item_pool.h" +#include "kage_input.h" +#include "level.h" +#include "level_generator.h" +#include "lua_api.h" +#include "manager.h" +#include "mod_manager.h" +#include "npc_ai.h" +#include "persistent_game_data.h" +#include "platform.h" +#include "player_manager.h" +#include "room.h" +#include "room_config.h" +#include "room_grid.h" +#include "seeds.h" +#include "sfx_manager.h" +#include "texture_cache.h" +#include +#include +#include +#include +#include +#include + +constexpr std::string_view COMMAND_REPEAT = "repeat"; +constexpr const char* LUA_CHUNK_NAME = "=lua"; +constexpr const char* WIRELESS_DEVICE = "Wireless"; +constexpr int CONSOLE_DEBUG_FLAG_COUNT = 14; +constexpr int CONSOLE_STAGE_MAX = 14; +constexpr int COMBO_POOL_COUNT = 31; +constexpr int COSTUME_TEST_MIN = 2; +constexpr int COSTUME_TEST_RANGE = 5; +constexpr int COSTUME_TEST_ITEMS = 733; +constexpr int CUTSCENE_LAST = 26; +constexpr int DEBUG_FLAG_DAMAGE = 3; +constexpr int DEBUG_FLAG_LUCK = 8; +constexpr int TIME_FRAME_RATE = 30; +constexpr int GRID_PATH_SPAWN = 900; +constexpr int GRID_INDEX_COUNT = 448; +constexpr int NAME_LANGUAGE_ENGLISH = 0; +constexpr int REPEAT_MAX = 10000; +constexpr int TIME_MINUTE_SECONDS = 60; +constexpr int TEST_BOSS_POOL_DRAWS = 10000; +constexpr float CO_PLAYER_SPAWN_SPREAD = 10; +constexpr char TAG_CHARMED = 'f'; +constexpr char TAG_CONTROLLED = 'p'; + +// The fixed macros: a name and the commands it runs in order. +struct ConsoleMacro +{ + std::string_view name; + std::vector commands; +}; + +const ConsoleMacro MACROS[] = { + {"fc", {"debug 3", "debug 8", "debug 9", "giveitem Soy", "giveitem Bar", "giveitem Pad"}}, + {"ms", {"goto s.boss.5000"}}, + {"mss", {"goto s.boss.5000", "giveitem Soy", "giveitem Mutant", "debug 3", "debug 4"}}, + {"ug", {"stage 11a", "goto s.boss.6000"}}, + {"ugg", + {"stage 11a", "goto s.boss.6000", "giveitem Sad Onion", "giveitem Sad Onion", "giveitem Torn", "giveitem Torn", + "giveitem Mutant", "giveitem A Dollar", "giveitem Pyro", "debug 3"}}, + {"mom", {"stage 6", "g Bible", "g k5", "debug 3", "debug 4"}}, + {"momh", {"stage 8", "g Bible", "g k5", "debug 3", "debug 4"}}, + {"bigchest", + {"stage 10a", "g Polaroid", "g Negative", "debug 3", "debug 4", "g Mutant", "g Soy", "giveitem Belt", "repeat 5", + "giveitem Lord of the Pit", "debug 10", "g k5"}}, + {"hush", {"stage 9", "g k5", "combo 0.8", "combo 2.8", "combo 1.3", "combo 4.3"}}, + {"delirium", {"combo 0.12", "combo 2.12", "combo 1.3", "combo 4.3", "debug 3", "goto s.boss.3414"}}, + {"beast", {"stage 13", "goto x.itemdungeon.666", "combo 0.8", "combo 2.8", "combo 1.3", "combo 4.3", "debug 3"}}, + {"hud", + {"giveitem Dead Cat", "repeat 2", "giveitem Guppy's Collar", "giveitem Holy Mantle", "giveitem Schoolbag", + "giveitem MEAT!", "repeat 12", "giveitem Compass", "giveitem Blue Map", "giveitem Treasure Map", + "giveitem Baggy", "giveitem p2", "giveitem p3", "giveitem Purse", "giveitem Paper Clip", "giveitem Petrified", + "giveitem My Little Unicorn"}}, + {"qk", + {"giveitem Belt", "repeat 5", "giveitem Lord of the Pit", "giveitem Treasure Map", "giveitem Blue Map", + "giveitem Compass", "giveitem Black Candle", "giveitem X-Ray", "giveitem We Need to Go Deeper", "debug 8", + "giveitem Dollar", "giveitem Pyro", "giveitem Skeleton Key", "debug 3", "debug 10"}}, + {"roar", + {"giveitem Belt", "giveitem Lord of the Pit", "giveitem Treasure Map", "giveitem Blue Map", "giveitem Compass", + "debug 3"}}, + {"twitch", {"debug 16", "twitch_init"}}}; + +// The room forceroom asks for. Nothing in this version reads it. +struct ForcedRoom +{ + int stageId = -1; + int type = 1; + int variant = 0; +}; + +// A command being run: its words, the console it prints to and the player it acts for. +struct ConsoleCommand +{ + std::vector words; + Console* console = nullptr; + Entity_Player* player = nullptr; +}; + +// Whether a giveitem command gives items or takes them away. +enum GiveMode +{ + GIVE_ADD, + GIVE_REMOVE +}; + +int g_metronomeItem = 0; +static ForcedRoom forcedRoom; + +// (0067f420, 0067f580) Splits text at each delimiter, keeping empty words between two delimiters but not after the last. +std::vector text_split(std::string_view text, char delimiter) +{ + std::vector words; + std::istringstream stream{std::string(text)}; + + for (std::string word; std::getline(stream, word, delimiter);) words.push_back(word); + return words; +} + +// 00865660 Runs Lua code, returning what it gives back as text, or the error it raised. +std::string lua_code_run(std::string_view code) +{ + lua_State* state = lua_engine_get().state; + std::string result; + + if (luaL_loadbufferx(state, code.data(), code.size(), LUA_CHUNK_NAME, nullptr) == LUA_OK && + lua_pcall(state, 0, 1, 0) == LUA_OK) + { + if (lua_type(state, -1) != LUA_TNIL) result = luaL_tolstring(state, -1, nullptr); + } + else + { + result = lua_tostring(state, -1); + lua_settop(state, -2); + } + lua_settop(state, 0); + return result; +} + +static std::string text_lower(std::string text) +{ + std::ranges::transform(text, text.begin(), [](unsigned char c) { return (char)std::tolower(c); }); + return text; +} + +// The words from first on, joined by spaces. +static std::string words_join(ConsoleCommand& command, size_t first) +{ + std::string text = command.words[first]; + + for (size_t i = first + 1; i < command.words.size(); i++) text += " " + command.words[i]; + return text; +} + +static int word_int(ConsoleCommand& command, size_t index) +{ + return std::atoi(command.words[index].c_str()); +} + +static void command_print(ConsoleCommand& command, std::string_view text) +{ + command.console->Print(text); +} + +// What follows a one letter item tag ("c12", "k5"), or -1 when no digit follows. +static int tag_id_get(std::string_view word) +{ + return word.size() > 1 && std::isdigit((unsigned char)word[1]) ? std::atoi(word.data() + 1) : -1; +} + +// The query a name search matches: the words from the first argument on, lowercased, with underscores as spaces. +static std::string name_query_get(ConsoleCommand& command) +{ + std::string query = text_lower(words_join(command, 1)); + + std::ranges::replace(query, '_', ' '); + return query; +} + +// Gives a collectible as the console does: an item card in Cantripped, else replacing the first active item when a +// new active has no free slot. +static void collectible_give(Entity_Player& player, int id) +{ + ItemConfig& itemConfig = g_manager->itemConfig; + + if (g_game->challenge == CHALLENGE_CANTRIPPED) + { + player.AddItemCard(id); + return; + } + + int active = player.GetActiveItem(0); + bool isSlotFree = player.HasCollectible(COLLECTIBLE_SCHOOLBAG) && player.GetActiveItem(1) == 0; + if (active != 0 && !isSlotFree && itemConfig.GetCollectible(id)->type == ITEM_ACTIVE) + { + ItemConfig_Item* current = itemConfig.GetCollectible(active); + if (current && current->type == ITEM_ACTIVE) player.RemoveCollectible(active, false, 0, true); + } + player.AddCollectible(id, -1, true, 0, 0); +} + +// Gives a trinket, dropping the first one when every trinket slot is full. +static void trinket_give(Entity_Player& player, int id) +{ + if (player.GetTrinket(player.GetMaxTrinkets() - 1) != 0) player.TryRemoveTrinket(player.GetTrinket(0)); + player.AddTrinket(id, true); +} + +// Spawns an entity where the spawn command puts it. +static Entity* entity_spawn(int type, int variant, int subType, Vector position) +{ + return g_game->Spawn({.position = position, .subType = subType, .type = type, .variant = variant, .seed = Random()}); +} + +// The spawn command's name search: the first entity in the config whose English name holds the query. Cards are +// skipped, so a card's name spawns nothing. +static Entity* entity_spawn_by_name(ConsoleCommand& command, Vector position) +{ + std::string query = text_lower(words_join(command, 1)); + + for (auto& [key, entity] : g_manager->entityConfig.entities) + { + if (entity.id == ENTITY_PICKUP && entity.variant == PICKUP_TAROTCARD && entity.subtype != 0) continue; + if (text_lower(entity.GetName(NAME_LANGUAGE_ENGLISH)).find(query) == std::string::npos) continue; + + Entity* spawned = entity_spawn(entity.id, entity.variant, entity.subtype, position); + command_print(command, "Spawned entity.\n"); + return spawned; + } + return nullptr; +} + +// spawn type.variant.subtype.[f][p]champion, or spawn name: spawns by id at a free spot by the room's center, a +// co-op baby for type 1. f charms it and p hands it to the player's controller. +// The original sets the controller of a spawn that is no NPC through a null pointer. Here it is skipped. +static void spawn_run(ConsoleCommand& command) +{ + if (command.words.size() < 2) return; + + std::vector parts = text_split(command.words[1], '.'); + Room& room = *g_game->room; + int type = parts.size() > 0 ? std::atoi(parts[0].c_str()) : 0; + int variant = parts.size() > 1 ? std::atoi(parts[1].c_str()) : 0; + int subType = parts.size() > 2 ? std::atoi(parts[2].c_str()) : 0; + int champion = -1; + bool isCharmed = false; + bool isControlled = false; + + if (parts.size() > 3) + { + size_t i = 0; + for (; parts[3][i] == TAG_CHARMED || parts[3][i] == TAG_CONTROLLED; i++) + (parts[3][i] == TAG_CHARMED ? isCharmed : isControlled) = true; + if (i < parts[3].size()) champion = std::atoi(parts[3].c_str() + i); + } + + Vector position = room_free_pickup_position_find({.position = Room::GetCenterPos()}); + int gridIndex = room.GetGridIndex(position); + if ((uint32_t)gridIndex < GRID_INDEX_COUNT) room.gridPaths[gridIndex] = GRID_PATH_SPAWN; + + Entity* spawned = nullptr; + if (type == ENTITY_PLAYER) + { + spawned = g_game->playerManager.SpawnCoPlayerBaby(subType - 1); + spawned->ToPlayer()->apply_coop_baby_spawn_bonus(); + g_game->hud.AssignPlayerHUDs(); + } + else if (type != ENTITY_NULL) + spawned = entity_spawn(type, variant, subType, position); + + Entity_NPC* npc = dynamic_cast(spawned); + if (npc && champion >= 0) npc->Morph(npc->type, npc->variant, npc->subtype, champion); + if (npc && isControlled) npc->controllerID = command.player ? command.player->controllerIndex : 0; + + if (spawned && spawned->type != ENTITY_NULL) + command_print(command, "Spawned entity.\n"); + else if (Entity* named = entity_spawn_by_name(command, position)) + spawned = named; + else + command_print(command, "Error spawning entity.\n"); + + if (spawned && isCharmed) spawned->AddCharmed(EntityRef(nullptr), -1, false, false); +} + +// delirious [kill | id | name]: spawns a friendly boss from Delirious's list, the first whose "type.variant" starts with +// the argument or whose name holds it, else a random one. kill removes the friends spawned before. +static void delirious_run(ConsoleCommand& command) +{ + Entity_Player* player = g_game->playerManager.GetPlayer(0); + DeliriousBoss kill{.count = 1}; + + if (command.words.size() > 1 && command.words[1] == "kill") + { + player->console_spawn(kill, true); + return; + } + + const DeliriousBoss* boss = &DELIRIOUS_BOSSES[Random() % DELIRIOUS_BOSS_COUNT]; + if (command.words.size() > 1) + { + std::string query = text_lower(words_join(command, 1)); + for (const DeliriousBoss& candidate : DELIRIOUS_BOSSES) + { + EntityConfig_Entity* entity = g_manager->entityConfig.GetEntity(candidate.type, candidate.variant, 0); + std::string id = std::to_string(candidate.type) + "." + std::to_string(candidate.variant); + std::string name = text_lower(entity ? entity->GetName(NAME_LANGUAGE_ENGLISH) : "unknown"); + + if (id.find(command.words[1]) != 0 && name.find(query) == std::string::npos) continue; + boss = &candidate; + break; + } + } + + player->console_spawn(*boss, true); + command_print(command, "Spawned delirious boss.\n"); +} + +// A room config a goto or forceroom target names: s.type.variant for a special room, x.type.variant for one of this +// stage, d.variant for a default room of this stage. +static RoomConfig_Room* room_target_find(std::string_view target, ForcedRoom& room) +{ + std::string rest(target.substr(2)); + std::vector parts = text_split(rest, '.'); + + if (target[0] == 'd') + room = {.stageId = g_game->GetStageID(), .type = ROOM_DEFAULT, .variant = std::atoi(rest.c_str())}; + else + room = {.stageId = target[0] == 'x' ? g_game->GetStageID() : STAGE_ID_SPECIAL_ROOMS, + .type = RoomConfig::room_type_find(parts.empty() ? "" : parts[0]), + .variant = parts.size() > 1 && !parts[1].empty() ? std::atoi(parts[1].c_str()) : 0}; + return g_game->roomConfig.GetRoomByStageTypeAndVariant(room.stageId, room.type, room.variant, + ROOM_MODE_CURRENT); +} + +// Whether a word is a goto or forceroom target: a room kind letter, a dot, then the rest. +static bool is_room_target(std::string_view word) +{ + return word.size() > 1 && word[1] == '.' && (word[0] == 's' || word[0] == 'x' || word[0] == 'd'); +} + +// goto x y [dimension] walks to a room of the map, goto s.type.variant, x.type.variant or d.variant enters a room +// config. Without a dimension the map form always fails, as in the original. +static void goto_run(ConsoleCommand& command) +{ + size_t count = command.words.size(); + + if (count > 2) + { + uint32_t x = word_int(command, 1); + uint32_t y = word_int(command, 2); + uint32_t dimension = count > 3 ? word_int(command, 3) : -1; + int roomIndex = x + y * LEVEL_GRID_WIDTH; + bool isValid = x < LEVEL_GRID_WIDTH && y < LEVEL_GRID_WIDTH && dimension < DIMENSION_COUNT && + g_game->GetRoomByIdx(roomIndex, dimension)->data; + + if (isValid) + g_game->StartRoomTransition({.player = command.player, .animation = TRANSITION_FADE, + .dimension = (int)dimension, .roomIndex = roomIndex}); + command_print(command, isValid ? "Changed room.\n" : "Error changing room.\n"); + return; + } + if (count != 2 || command.words[1].size() < 2 || command.words[1][1] != '.') return; + + ForcedRoom target; + RoomConfig_Room* config = is_room_target(command.words[1]) ? room_target_find(command.words[1], target) : nullptr; + if (config) g_game->DEBUG_goto_room(config); + command_print(command, config ? "Changed room.\n" : "Error changing room.\n"); +} + +// forceroom target sets the room forced into floors, forceroom alone clears it. +// The original names the stage of a cleared forced room past the stage list. Here the name is empty. +static void forceroom_run(ConsoleCommand& command) +{ + if (command.words.size() < 2) + { + command_print(command, "Cleared forced room.\n"); + forcedRoom = {}; + return; + } + if (command.words[1].size() < 2 || command.words[1][1] != '.') return; + + if (is_room_target(command.words[1])) room_target_find(command.words[1], forcedRoom); + + std::string stageName = forcedRoom.stageId < 0 ? "" : g_game->roomConfig.GetStageDisplayName(forcedRoom.stageId, 0); + command.console->print_format(CONSOLE_WHITE, "Set forced room to %s, %s, %d.\n", stageName.c_str(), + std::string(room_type_name(forcedRoom.type)).c_str(), forcedRoom.variant); +} + +// gridspawn type.variant [index]: spawns a grid entity on a cell, a random one by default, replacing what is there. +static void gridspawn_run(ConsoleCommand& command) +{ + if (command.words.size() < 2) return; + + std::vector parts = text_split(command.words[1], '.'); + Room& room = *g_game->room; + RoomEntry entry{.type = parts.size() > 0 ? (uint32_t)std::atoi(parts[0].c_str()) : 0, + .variant = (uint16_t)(parts.size() > 1 ? std::atoi(parts[1].c_str()) : 0)}; + int gridIndex = room.GetRandomTileIndex(Random()); + + if (command.words.size() > 2) + { + gridIndex = word_int(command, 2); + reconstruction_missing("Room::RemoveGridEntity 0081e930"); + } + room_entry_spawn(room, entry, {.gridIndex = gridIndex, .seed = Random()}); + if (GridEntity* grid = room.GetGridEntity(gridIndex)) grid->PostInit(); +} + +// stage number[a|b|c|d]: moves to a stage and its alt type, building the floor anew. +static void stage_run(ConsoleCommand& command) +{ + if (command.words.size() != 2) return; + + std::string& word = command.words[1]; + constexpr std::pair SUFFIXES[] = {{'a', STAGETYPE_WOTL}, {'b', STAGETYPE_AFTERBIRTH}, + {'c', STAGETYPE_REPENTANCE}, {'d', STAGETYPE_REPENTANCE_B}}; + int stageType = STAGETYPE_ORIGINAL; + + for (auto [suffix, type] : SUFFIXES) + { + if (word.back() != suffix) continue; + word.pop_back(); + stageType = type; + break; + } + + int stage = std::atoi(word.c_str()); + if ((uint32_t)(stage - 1) >= CONSOLE_STAGE_MAX) return; + + g_game->SetStage(stage, stageType); + g_game->Init(false); + g_game->Level::Update(); + g_game->playerManager.trigger_new_room_effects(); + command_print(command, "Changed stage.\n"); +} + +// debug n: toggles debug flag n. Flags 4 (high damage) and 9 (high luck) take effect on every player at once. +static void debug_run(ConsoleCommand& command) +{ + if (command.words.size() != 2) return; + + uint32_t flag = word_int(command, 1) - 1; + if (flag < CONSOLE_DEBUG_FLAG_COUNT) + { + g_game->debugFlags ^= 1u << flag; + command_print(command, g_game->debugFlags >> flag & 1 ? "Enabled debug flag.\n" : "Disabled debug flag.\n"); + } + if (flag != DEBUG_FLAG_LUCK && flag != DEBUG_FLAG_DAMAGE) return; + + for (Entity_Player* player : g_game->playerManager.playerList) + { + player->AddCacheFlags(flag == DEBUG_FLAG_LUCK ? CACHE_LUCK : CACHE_DAMAGE); + player->EvaluateItems(); + } +} + +// remove * takes every collectible and trinket away. Giving everything is refused. +static void items_all_remove(ConsoleCommand& command, Entity_Player& player, GiveMode mode) +{ + if (mode == GIVE_ADD) + { + command_print(command, "What are you trying to do?\n"); + return; + } + + ItemConfig& itemConfig = g_manager->itemConfig; + command_print(command, "Restoring player to zero collectibles/trinkets.\n"); + for (size_t id = 1; id < itemConfig.collectibles.size(); id++) + if (ItemConfig::IsValidCollectible(id)) player.RemoveCollectible(id, false, 0, true); + for (size_t id = 1; id < itemConfig.trinkets.size(); id++) player.TryRemoveTrinket(id); +} + +// The id forms of giveitem: c collectible, t trinket (T golden), k card, p pill (P horse). Whether one applied. +static bool item_by_id_give(ConsoleCommand& command, Entity_Player& player, GiveMode mode) +{ + ItemConfig& itemConfig = g_manager->itemConfig; + char tag = command.words[1][0]; + uint32_t id = tag_id_get(command.words[1]); + + if (tag == 'c' && id != 0 && id < itemConfig.collectibles.size()) + { + if (!itemConfig.GetCollectible(id)) return true; + if (mode == GIVE_REMOVE) player.RemoveCollectible(id, false, 0, true); + else collectible_give(player, id); + return true; + } + if ((tag == 't' || tag == 'T') && id != 0 && id < itemConfig.trinkets.size()) + { + if (!itemConfig.GetTrinket(id)) return true; + if (mode == GIVE_REMOVE) player.TryRemoveTrinket(id); + else trinket_give(player, tag == 'T' ? id | TRINKET_GOLDEN_FLAG : id); + return true; + } + if (tag == 'k' && id != 0 && id < itemConfig.cards.size()) + { + if (mode == GIVE_REMOVE) command_print(command, "Removing cards has not been implemented.\n"); + else player.AddCard(id); + return true; + } + if ((tag == 'p' || tag == 'P') && id < itemConfig.pillEffects.size()) + { + if (mode == GIVE_REMOVE) + { + command_print(command, "Removing pills has not been implemented.\n"); + return true; + } + int pillColor = g_game->itemPool.ForceAddPillEffect(id); + player.AddPill(tag == 'P' ? pillColor | PILL_HORSE_FLAG : pillColor); + return true; + } + return false; +} + +// The name form of giveitem: the first collectible, else trinket, whose English name holds the query. +static void item_by_name_give(ConsoleCommand& command, Entity_Player& player, GiveMode mode) +{ + ItemConfig& itemConfig = g_manager->itemConfig; + std::string query = name_query_get(command); + + for (size_t id = 0; id < itemConfig.collectibles.size(); id++) + { + ItemConfig_Item* item = itemConfig.GetCollectible(id); + if (!item || text_lower(item->GetLocalizedName(NAME_LANGUAGE_ENGLISH)).find(query) == std::string::npos) continue; + + if (mode == GIVE_REMOVE) player.RemoveCollectible(id, false, 0, true); + else collectible_give(player, id); + return; + } + for (size_t id = 0; id < itemConfig.trinkets.size(); id++) + { + ItemConfig_Item* item = itemConfig.GetTrinket(id); + if (!item || text_lower(item->GetLocalizedName(NAME_LANGUAGE_ENGLISH)).find(query) == std::string::npos) continue; + + if (mode == GIVE_REMOVE) player.TryRemoveTrinket(id); + else trinket_give(player, id); + return; + } +} + +// giveitem/g and remove/r item: gives or takes an item by tagged id or by name. The forms ending in 2 act for the +// player's twin. remove * empties the player, and a name search follows the * forms, as in the original. +static void giveitem_run(ConsoleCommand& command) +{ + if (command.words.size() < 2) return; + + std::string_view verb = command.words[0]; + GiveMode mode = verb.starts_with('r') ? GIVE_REMOVE : GIVE_ADD; + Entity_Player* player = command.player; + + if (verb.back() == '2' && player->twin_get()) player = player->twin_get(); + if (command.words[1][0] == '*') items_all_remove(command, *player, mode); + else if (item_by_id_give(command, *player, mode)) return; + item_by_name_give(command, *player, mode); +} + +// metro item: makes the Metronome become a collectible, by c id or by name. +static void metro_run(ConsoleCommand& command) +{ + if (command.words.size() != 2) return; + + ItemConfig& itemConfig = g_manager->itemConfig; + uint32_t id = tag_id_get(command.words[1]); + if (command.words[1][0] == 'c' && id < itemConfig.collectibles.size()) + { + g_metronomeItem = id; + return; + } + + std::string query = name_query_get(command); + for (size_t i = 0; i < itemConfig.collectibles.size(); i++) + { + ItemConfig_Item* item = itemConfig.GetCollectible(i); + if (!item || text_lower(item->GetLocalizedName(NAME_LANGUAGE_ENGLISH)).find(query) == std::string::npos) continue; + g_metronomeItem = i; + return; + } +} + +// costumetest [count]: dresses the player in random passive items' costumes, 2 to 6 by default. +static void costumetest_run(ConsoleCommand& command) +{ + int count = random_below(COSTUME_TEST_RANGE) + COSTUME_TEST_MIN; + + if (command.words.size() == 2) count = word_int(command, 1); + command.player->ClearCostumes(); + for (int i = 0; i < count; i++) + { + ItemConfig_Item* item = nullptr; + while (!item || item->type != ITEM_PASSIVE) + item = g_manager->itemConfig.GetCollectible(random_below(COSTUME_TEST_ITEMS)); + command.player->AddCostume(item, false); + } + command.console->print_format(CONSOLE_WHITE, "%d random costumes added.\n", count); +} + +// time: prints the run's time. +static void time_run(ConsoleCommand& command) +{ + int frames = g_game->timeCounter; + int seconds = frames / TIME_FRAME_RATE; + + command.console->print_format(CONSOLE_WHITE, "Total time: %02d:%02d.%02d\n", seconds / TIME_MINUTE_SECONDS, + seconds % TIME_MINUTE_SECONDS, frames % TIME_FRAME_RATE * 100 / TIME_FRAME_RATE); +} + +// restart [character]: restarts the run on its seeds, as another character when given one that exists. +static void restart_run(ConsoleCommand& command) +{ + if (command.words.size() == 2 && !command.words[1].empty()) + { + int playerType = word_int(command, 1); + bool isKnown = playerType >= 0 && playerType < (int)g_manager->entityConfig.players.size(); + g_manager->startPlayerType = isKnown ? playerType : 0; + } + Manager::RestartGame(); +} + +// listcollectibles: prints the player's collectibles with their counts. +static void listcollectibles_run(ConsoleCommand& command) +{ + ItemConfig& itemConfig = g_manager->itemConfig; + bool isFirst = true; + + for (size_t id = 1; id < itemConfig.collectibles.size(); id++) + { + if (!command.player->HasCollectible(id)) continue; + if (!isFirst) command_print(command, ","); + command.console->print_format(CONSOLE_WHITE, "%s:%d", + itemConfig.GetCollectible(id)->GetLocalizedName(NAME_LANGUAGE_ENGLISH).c_str(), + command.player->GetCollectibleNum(id)); + isFirst = false; + } + command_print(command, "\n"); +} + +// repeat n: runs the newest earlier command that is no repeat n times, at most 10000. +static void repeat_run(ConsoleCommand& command) +{ + if (command.words.size() != 2) return; + + int count = word_int(command, 1); + std::deque& history = command.console->commandHistory; + size_t i = 1; + + if (count < 1) return; + count = std::min(count, REPEAT_MAX); + while (i < history.size() && history[i].find(COMMAND_REPEAT) != std::string::npos) i++; + if (i >= history.size()) + { + command_print(command, "Nothing to repeat.\n"); + return; + } + + std::string repeated = history[i]; + command.console->print_format(CONSOLE_WHITE, ">%s (x%d)\n", repeated.c_str(), count); + for (int n = 0; n < count; n++) command.console->RunCommand(repeated, nullptr, command.player); +} + +// seed [code]: prints the run's seed, restarts on another, or adds or removes a special seed. +static void seed_run(ConsoleCommand& command) +{ + Seeds& seeds = g_game->seedEffects; + + if (command.words.size() < 2) + { + command_print(command, seeds.GetStartSeedString()); + command_print(command, "\n"); + return; + } + + std::string code = command.words.size() > 2 ? command.words[1] + " " + command.words[2] : command.words[1]; + if (!Seeds::IsStringValidSeed(code)) + command_print(command, "Invalid seed.\n"); + else if (!Seeds::IsSpecialSeed(code)) + { + seeds.SetStartSeed(code); + seeds.isCustomRun = true; + Manager::RestartGame(); + } + else if (seeds.CanAddSeedEffect(code)) + { + seeds.AddSeedEffect(Seeds::GetSeedEffect(code)); + command_print(command, "Added special seed.\n"); + } + else if (seeds.HasSeedEffect(code)) + { + seeds.RemoveSeedEffect(Seeds::GetSeedEffect(code)); + command_print(command, "Removed special seed.\n"); + } + else + command_print(command, "Special seed conflicts with the current stack.\n"); +} + +static void clearseeds_run(ConsoleCommand&) +{ + g_game->seedEffects.ClearSeedEffects(); +} + +// challenge id: restarts the run as a challenge, with its character and difficulty. +static void challenge_run(ConsoleCommand& command) +{ + int challenge = command.words.size() == 2 && !command.words[1].empty() ? word_int(command, 1) : -1; + + if (challenge < 0 || challenge > (int)g_manager->challengeParams.size()) + { + command_print(command, "Invalid challenge ID.\n"); + return; + } + + ChallengeParam& params = g_manager->GetChallengeParams(challenge); + g_manager->startChallenge = challenge; + g_manager->startPlayerType = params.playerType; + g_manager->startDifficulty = params.difficulty; + Manager::RestartGame(); +} + +// combo pool.count: gives count collectibles drawn from a pool, one by default. +static void combo_run(ConsoleCommand& command) +{ + if (command.words.size() != 2) return; + + std::vector parts = text_split(command.words[1], '.'); + int pool = parts.size() > 0 && !parts[0].empty() ? std::atoi(parts[0].c_str()) : 0; + int count = parts.size() > 1 && !parts[1].empty() ? std::atoi(parts[1].c_str()) : 1; + + if (pool < 0 || pool >= COMBO_POOL_COUNT) pool = 0; + for (int i = 0; i < count; i++) + command.player->AddCollectible(g_game->itemPool.GetCollectible((ItemPoolType)pool, Random(), 0, 0, 0), -1, + true, 0, 0); +} + +// cutscene id: plays a cutscene. +static void cutscene_run(ConsoleCommand& command) +{ + if (command.words.size() != 2) return; + + uint32_t cutscene = word_int(command, 1); + if (cutscene <= CUTSCENE_LAST) g_manager->ShowCutscene(cutscene, CUTSCENE_KEEP_STATE, 1); + else command_print(command, "Invalid cutscene ID.\n"); +} + +static void restock_run(ConsoleCommand& command) +{ + reconstruction_missing("Room::ShopRestockFull 00815ae0"); + command_print(command, "Shop is fully restocked.\n"); +} + +static void clearcache_run(ConsoleCommand&) +{ + AnmCache::Clear(); + TextureCache::Purge(); +} + +// macro name, or m name: runs a fixed list of commands. lp enters the Lil Portal room, sg stage room goes to a stage +// and a default room, gb variant to a boss room and g variant to a default room. +static void macro_run(ConsoleCommand& command) +{ + if (command.words.size() < 2) return; + + std::string_view name = command.words[1]; + size_t count = command.words.size(); + Console& console = *command.console; + + if (name == "lp") reconstruction_missing("Game::ChangeRoom 006fe2f0"); + for (const ConsoleMacro& macro : MACROS) + { + if (macro.name != name) continue; + for (std::string_view line : macro.commands) console.RunCommand(line); + return; + } + if (name == "sg" && count > 3) + { + console.RunCommand("stage " + command.words[2]); + console.RunCommand("goto d." + command.words[3]); + } + else if (name == "gb" && count > 2) + console.RunCommand("goto s.boss." + command.words[2]); + else if (name == "g" && count > 2) + console.RunCommand("goto d." + command.words[2]); +} + +// playsfx id [pitch]: plays a sound. +static void playsfx_run(ConsoleCommand& command) +{ + if (command.words.size() < 2) return; + + float pitch = command.words.size() > 2 ? (float)std::atof(command.words[2].c_str()) : 1; + int sound = word_int(command, 1); + + seed_fart_sound_override(&sound); + g_manager->sfxManager.Play(sound, {.pitch = pitch}); +} + +// curse flags...: sets the curses debugging forces on floors, the flags of every argument together. +static void curse_run(ConsoleCommand& command) +{ + uint32_t curses = 0; + + if (command.words.size() < 2) return; + for (size_t i = 1; i < command.words.size(); i++) curses |= word_int(command, i); + g_game->debugCurses = curses; +} + +// reseed: builds the floor anew on a new seed. +static void reseed_run(ConsoleCommand& command) +{ + bool isAltPath = g_game->stageType == STAGETYPE_REPENTANCE || g_game->stageType == STAGETYPE_REPENTANCE_B; + + g_game->seedEffects.ForgetStageSeed(g_game->stage + isAltPath); + g_game->Init(true); + g_game->Level::Update(); + g_game->playerManager.trigger_new_room_effects(); + command_print(command, "Changed stage.\n"); +} + +// eggs: unlocks every special seed in the main menu. +static void eggs_run(ConsoleCommand& command) +{ + PersistentGameData& data = g_manager->persistentGameData; + + for (int seed = 0; seed < SPECIAL_SEED_COUNT; seed++) + { + if (data.isReadOnly) continue; + data.specialSeeds[seed] = true; + data.specialSeeds[0] = false; + data.isChangesMade = true; + log_printf(LOG_INFO, "Seed %d added to SaveState\n", seed); + } + command_print(command, "All easter eggs unlocked in main menu.\n"); + command_print(command, "On the easter eggs menu press Q+E+Tab\n"); + command_print(command, "or LB+RB+X to remove one from the list.\n"); +} + +// copy n: copies the n commands before this one to the clipboard, oldest first. +static void copy_run(ConsoleCommand& command) +{ + if (command.words.size() != 2) return; + + std::deque& history = command.console->commandHistory; + std::string text; + + for (int i = std::min(word_int(command, 1), (int)history.size() - 1); i >= 1; i--) text += history[i] + "\n"; + SDL_SetClipboardText(text.c_str()); + command_print(command, "Copied.\n"); +} + +// luarun path: runs a script file. +static void luarun_run(ConsoleCommand& command) +{ + if (command.words.size() == 2) lua_engine_get().RunScript(command.words[1]); +} + +// lua code, or l code: runs Lua code, printing what it returns or raises in red. +static void lua_run(ConsoleCommand& command) +{ + if (command.words.size() < 2) return; + + std::string result = lua_code_run(words_join(command, 1)); + if (!result.empty()) command.console->PrintError(result); +} + +// luamod name: reloads a mod by its folder name. +static void luamod_run(ConsoleCommand& command) +{ + if (command.words.size() < 2) return; + + bool isRun = lua_engine_get().LuamodCMD(text_lower(words_join(command, 1))); + command_print(command, isRun ? "Success!\n" : "Failed to run mod!\n"); +} + +// luamem: prints the memory Lua uses. +static void luamem_run(ConsoleCommand& command) +{ + lua_State* state = lua_engine_get().state; + int bytes = lua_gc(state, LUA_GCCOUNTB, 0); + int kilobytes = lua_gc(state, LUA_GCCOUNT, 0); + + command.console->print_format(CONSOLE_WHITE, "Lua mem usage: %d KB and %d bytes\n", kilobytes, bytes); +} + +static void reloadshaders_run(ConsoleCommand&) +{ + g_manager->modManager.TriggerResize(); +} + +// testbosspool: draws this floor's boss 10000 times and prints how often each came up. +// The original reads past the boss list for an unknown id. Here it prints the id instead. +static void testbosspool_run(ConsoleCommand& command) +{ + std::map counts; + std::vector& bosses = g_manager->entityConfig.bosses; + + for (int i = 0; i < TEST_BOSS_POOL_DRAWS; i++) + { + g_game->bossPool.init(Random()); + counts[g_game->bossPool.GetBossId(g_game->stage, g_game->stageType)]++; + } + for (auto [bossId, count] : counts) + { + if (bossId >= 0 && bossId < (int)bosses.size()) + command.console->print_format(CONSOLE_WHITE, "%s: %d\n", bosses[bossId].name.c_str(), count); + else + command.console->print_format(CONSOLE_WHITE, "%d: %d\n", bossId < 0 ? -bossId : bossId, count); + } +} + +// The first device no player uses and that is not a wireless adapter, the keyboard when none. +static int free_controller_find() +{ + uint64_t used = 0; + + for (Entity_Player* player : g_game->playerManager.playerList) used |= 1ull << (player->controllerIndex & 63); + for (int i = 0; i < KAGE::Input::manager.get_device_count(); i++) + { + std::shared_ptr device = KAGE::Input::manager.get_device(i); + if (device && !(used >> (i & 63) & 1) && !device->name.starts_with(WIRELESS_DEVICE)) return device->id; + } + return 0; +} + +// addplayer [character] [controller]: adds a co-op player on a controller, the first free one by default. +static void addplayer_run(ConsoleCommand& command) +{ + int playerType = command.words.size() > 1 ? word_int(command, 1) : 0; + int controller = command.words.size() > 2 ? word_int(command, 2) : -1; + + if (controller < 0) controller = free_controller_find(); + if (std::shared_ptr device = KAGE::Input::manager.device_find(controller)) + command.console->print_format(CONSOLE_WHITE, "controller id %d %s\n", controller, device->name.c_str()); + + Entity_Player* player = g_game->playerManager.SpawnCoPlayer2(playerType); + Vector origin = g_game->GetPlayer(0)->pos; + Vector offset = random_direction(); + + player->SetControllerIndex(controller, false); + player->pos = vector_make(origin.x + offset.x * CO_PLAYER_SPAWN_SPREAD, + origin.y + offset.y * CO_PLAYER_SPAWN_SPREAD); + g_game->hud.AssignPlayerHUDs(); + player->InitPostLevelInitStats(); +} + +static void reloadfx_run(ConsoleCommand&) +{ + reconstruction_missing("Room::reload_backdrop 007f2070"); +} + +// reloadwisps: reloads wisps.xml and locusts.xml and inits the room's wisps and locusts again. +static void reloadwisps_run(ConsoleCommand&) +{ + ItemConfig& itemConfig = g_manager->itemConfig; + + itemConfig.LoadWispConfig(g_manager->modManager.TryRedirectPath("wisps.xml"), nullptr); + itemConfig.LoadLocustConfig(g_manager->modManager.TryRedirectPath("locusts.xml"), nullptr); + for (Entity* entity : g_game->room->entityList.updateEL) + if (entity->IsType(ENTITY_FAMILIAR, Entity_Familiar::WISP, -1) || + entity->IsType(ENTITY_FAMILIAR, Entity_Familiar::ABYSS_LOCUST, -1)) + entity->Init(entity->type, entity->variant, entity->subtype, entity->initSeed); +} + +// rewind: restarts the run from the state the Glowing Hourglass keeps, without fading in. +static void rewind_run(ConsoleCommand&) +{ + reconstruction_missing("Game::rewind 00706020"); +} + +static void clear_run(ConsoleCommand& command) +{ + command.console->history_clear(); +} + +// fix_rng_history_log path: rewrites a desync dump's history log. +static void fix_rng_history_log_run(ConsoleCommand& command) +{ + if (command.words.size() != 2) + { + command.console->print_format(CONSOLE_WHITE, "Invalid number of parameters: expected 1, found %d.\n", + (int)command.words.size() - 1); + return; + } + reconstruction_missing("write_desync_dump 009036b0"); +} + +// Every command by name, as RunCommand tries them. +const std::pair COMMANDS[] = { + {"spawn", spawn_run}, + {"delirious", delirious_run}, + {"goto", goto_run}, + {"forceroom", forceroom_run}, + {"gridspawn", gridspawn_run}, + {"stage", stage_run}, + {"debug", debug_run}, + {"giveitem", giveitem_run}, + {"g", giveitem_run}, + {"remove", giveitem_run}, + {"r", giveitem_run}, + {"giveitem2", giveitem_run}, + {"g2", giveitem_run}, + {"remove2", giveitem_run}, + {"r2", giveitem_run}, + {"metro", metro_run}, + {"costumetest", costumetest_run}, + {"time", time_run}, + {"restart", restart_run}, + {"listcollectibles", listcollectibles_run}, + {"repeat", repeat_run}, + {"seed", seed_run}, + {"clearseeds", clearseeds_run}, + {"challenge", challenge_run}, + {"combo", combo_run}, + {"cutscene", cutscene_run}, + {"restock", restock_run}, + {"clearcache", clearcache_run}, + {"macro", macro_run}, + {"m", macro_run}, + {"playsfx", playsfx_run}, + {"curse", curse_run}, + {"reseed", reseed_run}, + {"eggs", eggs_run}, + {"copy", copy_run}, + {"luarun", luarun_run}, + {"lua", lua_run}, + {"l", lua_run}, + {"luamod", luamod_run}, + {"luamem", luamem_run}, + {"reloadshaders", reloadshaders_run}, + {"testbosspool", testbosspool_run}, + {"addplayer", addplayer_run}, + {"reloadfx", reloadfx_run}, + {"reloadwisps", reloadwisps_run}, + {"rewind", rewind_run}, + {"clear", clear_run}, + {"fix_rng_history_log", fix_rng_history_log_run}}; + +// 0068cdc0 Runs a command for a player, the first by default. Its words are split at spaces and the first picks the +// command. The output goes into output when given, as Isaac.ExecuteCommand captures it, else to the console. +void Console::RunCommand(std::string_view text, std::string* output, Entity_Player* player) +{ + ConsoleCommand command{.words = text_split(text, ' '), .console = this, .player = player}; + std::string* outer = capture; + + // An empty command does nothing. The original reads its first word past an empty list. + if (command.words.empty()) return; + if (!command.player) command.player = g_game->playerManager.GetPlayer(0); + if (output) capture = output; + for (auto [name, run] : COMMANDS) + { + if (name != command.words[0]) continue; + run(command); + break; + } + capture = outer; +} diff --git a/src/data.cpp b/src/data.cpp index b3d033e..1df3baa 100644 --- a/src/data.cpp +++ b/src/data.cpp @@ -9,6 +9,9 @@ constexpr std::string_view EMPTY_TEXT = ""; constexpr std::string_view JSON_EXTENSION = ".json"; // Where the import tool puts a language archive's files (the original's resources. mount). constexpr std::string_view LANGUAGE_FOLDER = "lang/"; +// Mods reach their own files from resources/ through "../mods/", and here the mods live in resources/mods/. +constexpr std::string_view MODS_FROM_RESOURCES = "../mods/"; +constexpr std::string_view PARENT_FOLDER = "../"; std::string dataDirectory = "resources/"; std::string languageDirectory; @@ -18,6 +21,7 @@ static std::string path_normalize(std::string_view path) { std::string normalized(path); for (char& letter : normalized) letter = letter == '\\' ? '/' : (char)std::tolower((unsigned char)letter); + if (normalized.starts_with(MODS_FROM_RESOURCES)) normalized.erase(0, PARENT_FOLDER.size()); return normalized; } diff --git a/src/entity.cpp b/src/entity.cpp index 41330d4..798e845 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -44,9 +44,8 @@ constexpr float RENDER_Z_NORMAL_MIN = 10000; constexpr float RENDER_Z_DEPTH_SCALE = 100; constexpr float RENDER_Z_DEPTH_BASE = 10030; -// The defaults Init and LoadEntityConfig give: status tick damage, slowing, the shadow without a config, and the -// update clock's start just before zero. -constexpr float STATUS_TICK_DAMAGE_DEFAULT = 2; +// The defaults Init and LoadEntityConfig give: slowing, the shadow without a config, and the update clock's start +// just before zero. constexpr float SLOWING_AMOUNT_DEFAULT = 0.9f; constexpr float SHADOW_SIZE_DEFAULT = 0.015625f; constexpr float UPDATE_TIME_START = -1e-05f; @@ -75,12 +74,7 @@ constexpr int FLICKER_COLORS = 6; constexpr int STATUS_DAMAGE_INTERVAL = 20; constexpr int STATUS_DAMAGE_PHASE = 1; constexpr float BLEED_FLICKER_SCALE = 0.02f; -constexpr int STATUS_COLOR_PRIORITY = 255; constexpr int STATUS_COLOR_FRAMES = 2; -// How long a boss shrugs off status effects after one, and the trinket that doubles their durations. -constexpr int BOSS_STATUS_COOLDOWN = 240; -constexpr int SLOW_BRIEF_FRAMES = 2; -constexpr int TRINKET_SECOND_HAND = 78; // A hit flashes the entity for a third of its damage in frames, from one to six. constexpr int HIT_FLASH_DIVISOR = 3; constexpr int HIT_FLASH_MIN = 1; @@ -309,12 +303,6 @@ void Entity::SetSize(float newSize, Vector newSizeMulti, int gridCollisionPoints } } -// 006a9ba0 -void Entity::GetCollisionCapsule(Capsule&, const Vector&) -{ - reconstruction_missing("Entity::GetCollisionCapsule 006a9ba0"); -} - // 006a8990 The top of its parent chain. Entity* Entity::GetLastParent() { @@ -991,7 +979,7 @@ void Entity::damage_events_update() pendingDamageFlags = 0; } -// Poisons and burns an enemy every twentieth frame of the effect, then bleeds it and pulls it in when magnetized. +// Poisons and burns an enemy every twentieth frame of the effect and bleeds it, then a magnetized one pulls things in. void Entity::status_damage_update() { if (is_enemy_type(type)) @@ -1006,11 +994,9 @@ void Entity::status_damage_update() SetColor(BURN_COLOR, STATUS_COLOR_FRAMES, STATUS_COLOR_PRIORITY, false, true); TakeDamage(burnTickDamage, DAMAGE_POISON_BURN, EntityRef(), 0); } - if (HasEntityFlags(FLAG_BLEED_OUT) && !IsDescendantOf(bleedSource.entity)) - reconstruction_missing("Entity::Update 006ae820: the bleeding of Mom's Razor and the creep it leaves"); + if (HasEntityFlags(FLAG_BLEED_OUT) && !IsDescendantOf(bleedSource.entity)) bleed_update(); } - if (!isDead && HasEntityFlags(FLAG_MAGNETIZED)) - reconstruction_missing("Entity::Update 006ae820: the pull of a magnetized entity"); + if (!isDead && HasEntityFlags(FLAG_MAGNETIZED)) magnet_pull_update(); } // 006b0eb0 Moves it half a step for the in-between frame and resolves the grid, unless told to skip one. @@ -1233,110 +1219,6 @@ void Entity::convert_shot_for_enemy_owner(Entity*) reconstruction_missing("Entity::convert_shot_for_enemy_owner 0064bb70"); } -// 006ad350 A status effect's duration, twice per copy of Second Hand the player behind its source holds. A player is -// only affected so in versus. -int Entity::apply_second_hand_duration(int duration, const EntityRef& source) -{ - if ((type == ENTITY_PLAYER && !g_game->deathmatchManager.is_active()) || !source.entity) return duration; - - Entity* root = source.entity; - while (root->spawnerEntity) root = root->spawnerEntity; - if (root->type != ENTITY_PLAYER) return duration; - Entity_Player& player = *static_cast(root); - if (!player.HasTrinket(TRINKET_SECOND_HAND)) return duration; - return player.GetTrinketMultiplier(TRINKET_SECOND_HAND) * duration * 2; -} - -// 006ad3c0 -void Entity::AddFreeze(const EntityRef&, int, bool) -{ - reconstruction_missing("Entity::AddFreeze 006ad3c0"); -} - -// 006ad500 -void Entity::AddPoison(const EntityRef&, int, float, bool) -{ - reconstruction_missing("Entity::AddPoison 006ad500"); -} - -// 006ad750 Slows the entity (the head of a body sharing its status) unless a friend did it: a negative duration for -// two frames, a positive one added up and tinted, then bosses shrug status off for a while. The amount is set either -// way, and the segments copy it. -void Entity::AddSlowing(const EntityRef& source, int duration, float amount, ColorMod slowColor, - bool isIgnoreBossCooldown) -{ - if (IsDamageSourceFriendly(source)) return; - duration = apply_second_hand_duration(duration, source); - Entity* head = this; - if (DoesEntityShareStatus()) - while (head->parent) head = head->parent; - - bool isImmune = head->HasEntityFlags(FLAG_NO_STATUS_EFFECTS); - if (duration < 0 && !isImmune) - { - head->slowingCountdown = SLOW_BRIEF_FRAMES; - head->AddEntityFlags(FLAG_SLOW); - } - else if (duration > 0 && !isImmune && (head->bossStatusEffectCooldown < 1 || isIgnoreBossCooldown)) - { - head->slowingCountdown += duration; - head->AddEntityFlags(FLAG_SLOW); - head->SetColor(slowColor, duration, STATUS_COLOR_PRIORITY, false, true); - bool isBossLike = head->IsBoss() || (g_game->deathmatchManager.is_active() && head->type == ENTITY_PLAYER); - if (!isIgnoreBossCooldown && isBossLike) head->bossStatusEffectCooldown = BOSS_STATUS_COOLDOWN; - } - head->slowingAmount = amount; - head->CopyStatusEffects(); -} - -// 006ad870 -void Entity::AddCharmed(const EntityRef&, int, bool, bool) -{ - reconstruction_missing("Entity::AddCharmed 006ad870"); -} - -// 006add70 -void Entity::AddConfusion(const EntityRef&, int, bool) -{ - reconstruction_missing("Entity::AddConfusion 006add70"); -} - -// 006adf40 -void Entity::AddMidasFreeze(const EntityRef&, int, bool) -{ - reconstruction_missing("Entity::AddMidasFreeze 006adf40"); -} - -// 006ae0a0 -void Entity::AddFear(const EntityRef&, int, bool) -{ - reconstruction_missing("Entity::AddFear 006ae0a0"); -} - -// 006ae280 -void Entity::AddBurn(const EntityRef&, int, float, bool) -{ - reconstruction_missing("Entity::AddBurn 006ae280"); -} - -// 006ae420 -void Entity::AddBleeding(const EntityRef&, int) -{ - reconstruction_missing("Entity::AddBleeding 006ae420"); -} - -// 006ae630 -void Entity::RemoveStatusEffects() -{ - reconstruction_missing("Entity::RemoveStatusEffects 006ae630"); -} - -// 006b5c10 -void Entity::AddShrink(const EntityRef&, int, bool) -{ - reconstruction_missing("Entity::AddShrink 006b5c10"); -} - // 006b5e60 void* Entity::GetData(void*) { @@ -1349,18 +1231,6 @@ void* Entity::GetDebugShape(bool) reconstruction_missing("Entity::GetDebugShape 006b5f10"); } -// 006b6550 -Entity_Effect* Entity::MakeGroundPoof(const Vector&, const ColorMod&, float) -{ - reconstruction_missing("Entity::MakeGroundPoof 006b6550"); -} - -// 006b66a0 -Entity_Effect* Entity::MakeGroundPoofAtSelf(const ColorMod&, float) -{ - reconstruction_missing("Entity::MakeGroundPoofAtSelf 006b66a0"); -} - // 006b6c20 void Entity::GetNullCapsule(Capsule&, std::string_view) { @@ -1373,36 +1243,6 @@ int Entity::get_water_splash_variant() reconstruction_missing("Entity::get_water_splash_variant 006b6ed0"); } -// 006b7280 -void Entity::AddMagnetized(const EntityRef&, int) -{ - reconstruction_missing("Entity::AddMagnetized 006b7280"); -} - -// 006b7560 -void Entity::AddBaited(const EntityRef&, int) -{ - reconstruction_missing("Entity::AddBaited 006b7560"); -} - -// 006b77d0 -void Entity::AddWeakness(const EntityRef&, int) -{ - reconstruction_missing("Entity::AddWeakness 006b77d0"); -} - -// 006b78d0 -void Entity::AddBrimstoneMark(const EntityRef&, int) -{ - reconstruction_missing("Entity::AddBrimstoneMark 006b78d0"); -} - -// 006b79d0 -void Entity::AddIce(const EntityRef&, int) -{ - reconstruction_missing("Entity::AddIce 006b79d0"); -} - // 006b7be0 Entity_NPC* Entity::GiveMinecart(const Vector&, const Vector&) { diff --git a/src/entity.h b/src/entity.h index 323c101..2a10d08 100644 --- a/src/entity.h +++ b/src/entity.h @@ -48,20 +48,26 @@ enum EntityType : int ENTITY_VIS = 39, ENTITY_GUTS = 40, ENTITY_KNIGHT = 41, + ENTITY_STONEHEAD = 42, ENTITY_POKY = 44, ENTITY_MOM = 45, ENTITY_GREED = 50, ENTITY_FLAMING_HOPPER = 54, ENTITY_LEECH = 55, + ENTITY_PARA_BITE = 58, ENTITY_SUCKER = 61, ENTITY_PIN = 62, ENTITY_FAMINE = 63, + ENTITY_FISTULA_BIG = 71, + ENTITY_FISTULA_MEDIUM = 72, + ENTITY_FISTULA_SMALL = 73, ENTITY_MOMS_HEART = 78, ENTITY_GEMINI = 79, ENTITY_MOTER = 80, ENTITY_SATAN = 84, ENTITY_SPIDER = 85, ENTITY_BUTTLICKER = 89, + ENTITY_HANGER = 90, ENTITY_HEART = 92, ENTITY_MASK = 93, ENTITY_BIG_SPIDER = 94, @@ -69,7 +75,9 @@ enum EntityType : int ENTITY_MASK_OF_INFAMY = 97, ENTITY_HEART_OF_INFAMY = 98, ENTITY_GURDY_JR = 99, + ENTITY_WIDOW = 100, ENTITY_ISAAC_BOSS = 102, + ENTITY_BRIMSTONE_HEAD = 203, ENTITY_BABY_LONG_LEGS = 206, ENTITY_CRAZY_LONG_LEGS = 207, ENTITY_FATTY = 208, @@ -82,7 +90,10 @@ enum EntityType : int ENTITY_RING_OF_FLIES = 222, ENTITY_SKINNY = 226, ENTITY_BONY = 227, + ENTITY_GAPING_MAW = 235, + ENTITY_BROKEN_GAPING_MAW = 236, ENTITY_GURGLING = 237, + ENTITY_SPLASHER = 238, ENTITY_GRUB = 239, ENTITY_CONJOINED_SPITTY = 243, ENTITY_ROUND_WORM = 244, @@ -90,6 +101,8 @@ enum EntityType : int ENTITY_NIGHT_CRAWLER = 255, ENTITY_DART_FLY = 256, ENTITY_GATE = 263, + ENTITY_MEGA_FATTY = 264, + ENTITY_POLYCEPHALUS = 269, ENTITY_URIEL = 271, ENTITY_GABRIEL = 272, ENTITY_MEGA_SATAN = 274, @@ -103,6 +116,7 @@ enum EntityType : int ENTITY_MOVABLE_TNT = 292, ENTITY_CORN_MINE = 295, ENTITY_HUSH_FLY = 296, + ENTITY_HUSH_GAPER = 297, ENTITY_POISON_MIND = 301, ENTITY_STONEY = 302, ENTITY_STAIN = 401, @@ -115,13 +129,17 @@ enum EntityType : int ENTITY_BISHOP = 805, ENTITY_WILLO = 808, ENTITY_SMALL_LEECH = 810, + ENTITY_STRIDER = 814, ENTITY_ROCK_SPIDER = 818, ENTITY_FLY_BOMB = 819, ENTITY_SMALL_MAGGOT = 853, ENTITY_PUSTULE = 861, ENTITY_DARK_ESAU = 866, + ENTITY_DRIP = 870, + ENTITY_SPLURT = 871, ENTITY_ORBIT_SPAWNER = 873, ENTITY_GRUDGE = 877, + ENTITY_NEEDLE = 881, ENTITY_CULTIST = 885, ENTITY_BALL_AND_CHAIN = 893, ENTITY_VISAGE = 903, @@ -215,7 +233,8 @@ enum EntityFlag : uint64_t FLAG_HELD = 1ull << 57, FLAG_THROWN = 1ull << 58, FLAG_FRIENDLY_BALL = 1ull << 59, - FLAG_DELIRIUM_FORM = 1ull << 60 + FLAG_DELIRIUM_FORM = 1ull << 60, + FLAG_NO_SPLIT = 1ull << 61 }; // Lua's DamageFlag: what kind of damage a hit deals. @@ -224,12 +243,14 @@ enum DamageFlag : uint64_t DAMAGE_NOKILL = 1ull << 0, DAMAGE_FIRE = 1ull << 1, DAMAGE_EXPLOSION = 1ull << 2, + DAMAGE_LASER = 1ull << 3, DAMAGE_ACID = 1ull << 4, DAMAGE_RED_HEARTS = 1ull << 5, DAMAGE_COUNTDOWN = 1ull << 6, DAMAGE_SPIKES = 1ull << 7, DAMAGE_POOP = 1ull << 9, DAMAGE_DEVIL = 1ull << 10, + DAMAGE_ISAAC_HURT = 1ull << 11, DAMAGE_TNT = 1ull << 12, DAMAGE_INVINCIBLE = 1ull << 13, DAMAGE_SPAWN_FLY = 1ull << 14, @@ -238,6 +259,7 @@ enum DamageFlag : uint64_t DAMAGE_CHEST = 1ull << 20, DAMAGE_BOOGER = 1ull << 22, DAMAGE_SPAWN_BLACK_HEART = 1ull << 23, + DAMAGE_CRUSH = 1ull << 24, DAMAGE_SPAWN_RED_HEART = 1ull << 26, DAMAGE_SPAWN_COIN = 1ull << 27, DAMAGE_NO_PENALTIES = 1ull << 28, @@ -320,6 +342,9 @@ struct lua_State; // The priority SetColor gives a color nothing outranks. constexpr int COLOR_PRIORITY_DEFAULT = 255; +// The priority status effects' colors show at, and the damage a poison or burn ticks for without a source's. +constexpr int STATUS_COLOR_PRIORITY = 255; +constexpr float STATUS_TICK_DAMAGE_DEFAULT = 2; // Reading and clearing (0040c3a0, 00a0fe80) are the pointer's own. // A pointer to an entity that the entity clears when it goes away (REPENTOGON's EntityPtr). It registers itself with @@ -594,7 +619,7 @@ struct Entity int GetIntervalTicks(float interval, float offset); int get_velocity_direction(); void SetSize(float newSize, Vector newSizeMulti, int gridCollisionPoints); - void GetCollisionCapsule(Capsule& outCapsule, const Vector& offset); + Capsule GetCollisionCapsule(const Vector& offset); Entity* GetLastParent(); Entity* GetLastChild(); @@ -631,7 +656,7 @@ struct Entity void AddFear(const EntityRef& source, int duration, bool isIgnoreBossCooldown); void AddBurn(const EntityRef& source, int duration, float damage, bool isIgnoreBossCooldown); void AddBleeding(const EntityRef& source, int duration); - void AddShrink(const EntityRef& source, int duration, bool isIgnoreBossCooldown); + void AddShrink(const EntityRef& source, int duration, bool isIgnoreBossCooldown, bool isForced = false); void AddMagnetized(const EntityRef& source, int duration); void AddBaited(const EntityRef& source, int duration); void AddWeakness(const EntityRef& source, int duration); @@ -678,6 +703,8 @@ private: void status_effects_update(); void damage_events_update(); void status_damage_update(); + void bleed_update(); + void magnet_pull_update(); }; Vector render_position_get(const Vector& world, RenderSnap snap); diff --git a/src/entity_collision.cpp b/src/entity_collision.cpp index 5fdebcc..244900c 100644 --- a/src/entity_collision.cpp +++ b/src/entity_collision.cpp @@ -1,3 +1,4 @@ +#include "capsule.h" #include "entity_collision.h" #include "entity_familiar.h" #include "entity_npc.h" @@ -726,10 +727,35 @@ bool Entity::push_apart_circle(Entity* other) return true; } -// 006b25b0 Pushes a stretched entity and another apart along where their capsules overlap. Capsule is not written yet. -void Entity::push_apart_capsule(Entity*) +// 006a9ba0 Its collision ellipse as a capsule, shifted by offset. +Capsule Entity::GetCollisionCapsule(const Vector& offset) { - reconstruction_missing("Entity::push_apart_capsule 006b25b0 (Capsule::Collide 00945470)"); + return Capsule(vector_make(offset.x + pos.x, pos.y + offset.y), sizeMulti, sprite.rotation, size); +} + +// 006b25b0 Pushes a stretched entity and another apart where their capsules overlap and they may meet, the lower type +// first, by the other's share of their weights. Their velocities trade along the push. +void Entity::push_apart_capsule(Entity* other) +{ + bool isVersusTearHit = g_game->deathmatchManager.is_active() && type == ENTITY_TEAR && other->type == ENTITY_PLAYER; + bool isSwapped = !isVersusTearHit && other->type < type; + Entity& first = isSwapped ? *other : *this; + Entity& second = isSwapped ? *this : *other; + + Vector hit{}; + if (!Capsule::Collide(first.GetCollisionCapsule({}), second.GetCollisionCapsule({}), &hit)) return; + if (is_collision_ignored(first, second) || (hit.x == 0 && hit.y == 0)) return; + + float firstWeight = first.collision_mass_get(&second); + float secondShare = firstWeight / (second.collision_mass_get(&first) + firstWeight); + float firstShare = 1 - secondShare; + float relativeSpeed = vector_length( + vector_make(second.velocity.x - first.velocity.x, second.velocity.y - first.velocity.y)); + float hitLength = vector_length(hit); + Vector impulse = vector_make(hit.x / hitLength * relativeSpeed, hit.y / hitLength * relativeSpeed); + + push_apply(first, {vector_make(-hit.x, -hit.y), vector_make(-impulse.x, -impulse.y), 1, firstShare}); + push_apply(second, {hit, impulse, 1, secondShare}); } // 006b2ee0 Pushes the entity and another apart: as circles when neither is stretched, as capsules otherwise. diff --git a/src/entity_combat.cpp b/src/entity_combat.cpp index 03a6709..9e3a8a9 100644 --- a/src/entity_combat.cpp +++ b/src/entity_combat.cpp @@ -70,9 +70,6 @@ constexpr int BABY_CROW = 12; constexpr int BLUE_FLY_MAX = 30; constexpr int MAGGY_SWING_READY = 3; -// Lua's DamageFlag bits beyond entity.h's. -constexpr uint64_t DAMAGE_CRUSH = 1ull << 24; - // The effects the combat code spawns (Lua's EffectVariant). constexpr int EFFECT_BISHOP_SHIELD = 160; constexpr int EFFECT_CHAIN_GIB = 163; diff --git a/src/entity_effect.cpp b/src/entity_effect.cpp index 9c20a99..ee4ff21 100644 --- a/src/entity_effect.cpp +++ b/src/entity_effect.cpp @@ -1,9 +1,9 @@ #include "entity_effect.h" -#include "entity_effect_ambient.h" #include "entity_effect_combat.h" #include "entity_list.h" #include "entity_player.h" #include "game.h" +#include "kage_graphics.h" #include "log.h" #include "lua_engine.h" #include "manager.h" @@ -11,6 +11,7 @@ #include "sfx_manager.h" #include #include +#include // The creep variants the players leave (holy water trail, black, red, white, holy water, green, Lemon Mishap, Lemon // Party, 204, Black Powder, milk, Black Powder's pentagram). @@ -41,12 +42,72 @@ constexpr int SOUND_BOOMERANG_LOOP = 837; constexpr int SOUND_PORTAL_ENTITY_LOOP = 846; constexpr int SOUND_CHAIN_LOOP = 503; +// The variants the behaviour tables can index, up to the last vanilla one. +constexpr int EFFECT_VARIANT_LIMIT = 256; + template static bool is_listed(const std::array& list, int value) { return std::find(list.begin(), list.end(), value) != list.end(); } +// The behaviour of a variant one of the groups hands out, indexed once by variant, or none. +static const EffectBehaviour* behaviour_find(int variant) +{ + static const std::array TABLE = [] { + std::array table{}; + for (auto group : {ambient_effect_behaviours(), hazard_effect_behaviours(), floor_effect_behaviours(), + beam_effect_behaviours()}) + for (const EffectBehaviour& behaviour : group) table[behaviour.variant] = behaviour; + return table; + }(); + if (variant < 0 || variant >= EFFECT_VARIANT_LIMIT || TABLE[variant].variant != variant) return nullptr; + return &TABLE[variant]; +} + +// 005d4b7a (Update's shared poof case) Turns the sprite by the effect's rotation and removes the effect once its +// animation ends. +EffectUpdateEnd effect_poof_update(Entity_Effect& effect) +{ + effect.sprite.rotation = effect.sprite.isFlipX ? effect.rotation : -effect.rotation; + if (effect.sprite.IsFinished()) effect.Remove(); + return EFFECT_UPDATE_FINISH; +} + +// An angle in degrees wrapped into -180 to 180, as approach_angle wraps it. +static float angle_wrapped(float angle) +{ + if (std::fabs(angle) > DEGREES_PER_TURN) angle = std::fmod(angle, DEGREES_PER_TURN); + if (angle > DEGREES_PER_TURN / 2) return angle - DEGREES_PER_TURN; + if (angle < -DEGREES_PER_TURN / 2) return angle + DEGREES_PER_TURN; + return angle; +} + +// 00682a50 An angle in degrees turned toward a target by at most a step, reaching it when within the step. +float angle_approach(float current, float target, float maxStep) +{ + float delta = angle_wrapped(target - current); + if (std::fabs(delta) <= maxStep) return target; + return angle_wrapped(delta > 0 ? current + maxStep : current - maxStep); +} + +// 00a15640 (assert_lerp_range, always clamped here) A value's place between two inputs, carried onto two outputs. +float lerp_clamped(float value, float inFirst, float inLast, float outFirst, float outLast) +{ + float t = (value - inFirst) / (inLast - inFirst); + if (t <= 0) t = 0; + if (t >= 1) t = 1; + return (outLast - outFirst) * t + outFirst; +} + +// BlendMode::SetMode 2 on a layer. +void layer_additive_set(LayerState& layer) +{ + KAGE::Graphics::BlendMode mode; + mode.SetMode(KAGE::Graphics::BLEND_ADDITIVE); + layer.blendMode = {mode.equation, mode.rgbSource, mode.rgbDest, mode.alphaSource, mode.alphaDest}; +} + // 0060c400 Only a boss spawn pentagram holds the doors shut. bool Entity_Effect::CanShutDoors() { @@ -119,7 +180,10 @@ void Entity_Effect::Init(int entityType, int entityVariant, int entitySubType, u entityGridCollisionClass = variant == EFFECT_BLOOD_PARTICLE ? GRIDCOLL_WALLS : GRIDCOLL_NONE; entityCollisionClass = ENTCOLL_NONE; - if (is_ambient_effect(variant)) ambient_effect_init(*this); + if (const EffectBehaviour* behaviour = behaviour_find(variant)) + { + if (behaviour->init) behaviour->init(*this); + } else if (is_combat_effect(variant)) combat_effect_init(*this); else reconstruction_missing("Entity_Effect::Init 005cdb20: this effect variant"); if (!isExists) return; @@ -137,11 +201,9 @@ void Entity_Effect::Update() speedMultiplier = g_game->room->GetTimeScale(this); if (variant == EFFECT_HUSH_LASER || variant == EFFECT_HUSH_LASER_UP) { - if (TemporaryEffect* hourglass = g_game->room->temporaryEffects.GetCollectibleEffect(COLLECTIBLE_HOURGLASS)) - { - float t = std::clamp((float)hourglass->cooldown / HOURGLASS_COOLDOWN_SPAN, 0.0f, 1.0f); - speedMultiplier *= (HOURGLASS_SLOWEST - 1) * t + 1; - } + TemporaryEffect* hourglass = g_game->room->temporaryEffects.GetCollectibleEffect(COLLECTIBLE_HOURGLASS); + if (hourglass) + speedMultiplier *= lerp_clamped((float)hourglass->cooldown, 0, HOURGLASS_COOLDOWN_SPAN, 1, HOURGLASS_SLOWEST); } if (variant == EFFECT_BLACK_POWDER) pauseTimer = 0; if (pauseTimer != 0) @@ -174,7 +236,10 @@ void Entity_Effect::Update() } EffectUpdateEnd end = EFFECT_UPDATE_FINISH; - if (is_ambient_effect(variant)) end = ambient_effect_update(*this); + if (const EffectBehaviour* behaviour = behaviour_find(variant)) + { + if (behaviour->update) end = behaviour->update(*this); + } else if (is_combat_effect(variant)) end = combat_effect_update(*this); else reconstruction_missing("Entity_Effect::Update 005d4380: this effect variant"); if (end == EFFECT_UPDATE_RETURN) return; @@ -204,7 +269,8 @@ void Entity_Effect::Render(const Vector& offset) Vector screen = render_position_get(vector_make(pos.x + posOffset.x, pos.y + posOffset.y), RENDER_SNAPPED); renderPosition = vector_make(screen.x + offset.x, screen.y + offset.y); - if (is_ambient_effect(variant)) ambient_effect_render(*this, offset); + const EffectBehaviour* behaviour = behaviour_find(variant); + if (behaviour && behaviour->render) behaviour->render(*this, offset); else sprite.Render(SpriteDraw{renderPosition, {}, {}}); lua_engine_get().PostEffectRender(this, offset); } diff --git a/src/entity_effect.h b/src/entity_effect.h index dcfa93a..7fc0f4d 100644 --- a/src/entity_effect.h +++ b/src/entity_effect.h @@ -3,6 +3,7 @@ #include "entity.h" #include #include +#include #include // The effect variant that spawns a boss, which counts as the boss until it does. @@ -16,6 +17,25 @@ enum EffectUpdateEnd EFFECT_UPDATE_RETURN }; +struct Entity_Effect; + +// What a variant runs beside Entity_Effect's shared Init, Update and Render: its part of Init (after the shared start, +// before LoadGraphics), its frame (between Update's shared start and end) and its draw. A missing one keeps the default. +struct EffectBehaviour +{ + int variant = -1; + void (*init)(Entity_Effect&) = nullptr; + EffectUpdateEnd (*update)(Entity_Effect&) = nullptr; + void (*render)(Entity_Effect&, const Vector&) = nullptr; +}; + +// An update that always goes on to Update's shared end. +template EffectUpdateEnd effect_finishing(Entity_Effect& effect) +{ + UPDATE(effect); + return EFFECT_UPDATE_FINISH; +} + // The effect variants several files name (Lua's EffectVariant). enum EffectVariant : int { @@ -24,7 +44,9 @@ enum EffectVariant : int EFFECT_FLY_EXPLOSION = 3, EFFECT_ROCK_PARTICLE = 4, EFFECT_BLOOD_PARTICLE = 5, + EFFECT_DEVIL = 6, EFFECT_BLOOD_SPLAT = 7, + EFFECT_ANGEL = 9, EFFECT_BULLET_POOF = 11, EFFECT_TEAR_POOF_A = 12, EFFECT_TEAR_POOF_B = 13, @@ -33,6 +55,7 @@ enum EffectVariant : int EFFECT_TINY_BUG = 21, EFFECT_CREEP_RED = 22, EFFECT_CREEP_GREEN = 23, + EFFECT_CREEP_YELLOW = 24, EFFECT_CREEP_WHITE = 25, EFFECT_CREEP_BLACK = 26, EFFECT_WOOD_PARTICLE = 27, @@ -45,17 +68,25 @@ enum EffectVariant : int EFFECT_POOP_EXPLOSION = 43, EFFECT_PLAYER_CREEP_RED = 46, EFFECT_HEART = 49, + EFFECT_LASER_IMPACT = 50, EFFECT_HOT_BOMB_FIRE = 51, EFFECT_PLAYER_CREEP_GREEN = 53, EFFECT_CREEP_BROWN = 56, + EFFECT_PULLING_EFFECT = 57, EFFECT_POOP_PARTICLE = 58, EFFECT_DUST_CLOUD = 59, EFFECT_SHOCKWAVE = 61, + EFFECT_ROCK_EXPLOSION = 62, EFFECT_WORM = 63, EFFECT_BEETLE = 64, EFFECT_WISP = 65, EFFECT_EMBER_PARTICLE = 66, + EFFECT_SHOCKWAVE_DIRECTIONAL = 67, EFFECT_WALL_BUG = 68, + EFFECT_BLOOD_DROP = 70, + EFFECT_BRIMSTONE_SWIRL = 71, + EFFECT_CRACKWAVE = 72, + EFFECT_SHOCKWAVE_RANDOM = 73, EFFECT_ISAACS_CARPET = 74, EFFECT_DICE_FLOOR = 76, EFFECT_TEAR_POOF_SMALL = 79, @@ -65,31 +96,47 @@ enum EffectVariant : int EFFECT_PENTAGRAM_BLACKPOWDER = 93, EFFECT_CREEP_SLIPPERY_BROWN = 94, EFFECT_WATER_SPLASH = 99, + EFFECT_ENEMY_BRIMSTONE_SWIRL = 110, + EFFECT_HAEMO_TRAIL = 111, EFFECT_HALLOWED_GROUND = 112, EFFECT_BRIMSTONE_BALL = 113, + EFFECT_FORGOTTEN_CHAIN = 114, EFFECT_BROKEN_SHOVEL_SHADOW = 115, + EFFECT_FORGOTTEN_SOUL = 117, + EFFECT_DIRT_PATCH = 116, EFFECT_SMALL_ROCKET = 118, EFFECT_SPAWNER = 120, EFFECT_LIGHT = 121, + EFFECT_BIG_HORN_HOLE_HELPER = 122, EFFECT_TAR_BUBBLE = 124, + EFFECT_BIG_HORN_HAND = 125, + EFFECT_TECH_DOT = 126, + EFFECT_BIG_SPLASH = 132, + EFFECT_PEDESTAL_RIPPLE = 134, EFFECT_GRID_ENTITY_PROJECTILE_HELPER = 136, EFFECT_BACKDROP_DECORATION = 140, EFFECT_SMOKE_CLOUD = 141, + EFFECT_ENEMY_GHOST = 144, + EFFECT_ROCK_POOF = 145, + EFFECT_DIRT_PILE = 146, EFFECT_FIRE_JET = 147, EFFECT_DOOR_OUTLINE = 154, + EFFECT_CREEP_SLIPPERY_BROWN_GROWING = 155, EFFECT_TALL_LADDER = 156, EFFECT_TADPOLE = 158, EFFECT_LIL_GHOST = 159, + EFFECT_COLOSTOMIA_PUDDLE = 168, EFFECT_PORTAL_TELEPORT = 161, - EFFECT_ANIMA_CHAIN = 193 + EFFECT_ANIMA_CHAIN = 193, + EFFECT_GENERIC_TRACER = 198 }; // Construction and destruction (005cd9f0, 005cd960) are the defaults, the extra data shared with its other holders. // Field accessors (00435e60, 00435eb0, 004d7770, 005784c0, 0060ce20) are the public fields. // An effect (Lua's EntityEffect): a visual or a hazard such as creep, a poof or a light beam, with its timeout, its // fall, the per-variant data it keeps and the extra data some variants share. -// Init, Update and Render run the shared parts here and hand each variant to entity_effect_ambient.h (ambient and -// environment effects, creep) or entity_effect_combat.h (blood, gibs, poofs, explosions). Any other variant stops. +// Init, Update and Render run the shared parts here and hand each variant to its group's behaviour table (the ambient, +// hazard, floor and beam files) or to entity_effect_combat.h (blood, gibs, poofs, explosions). Any other variant stops. struct Entity_Effect : Entity { @@ -143,3 +190,28 @@ struct Entity_Effect : Entity static Entity_Effect* CreateLootPreview(void* lootlist, const Vector& pos, Entity* owner, Entity_Effect* effect); void setup_loot_preview(void* lootQueue); }; + +// The groups of variants Entity_Effect hands out by table (entity_effect_.cpp). +std::span ambient_effect_behaviours(); +std::span hazard_effect_behaviours(); +std::span floor_effect_behaviours(); +std::span beam_effect_behaviours(); + +// The frame the plain poofs share: the sprite turned by the effect's rotation (mirrored unless flipped), the effect +// gone once its animation ends. +EffectUpdateEnd effect_poof_update(Entity_Effect& effect); + +// Sets a layer to draw additively (BlendMode::SetMode 2). +void layer_additive_set(LayerState& layer); + +// The degrees of a full turn. +constexpr float DEGREES_PER_TURN = 360; + +float angle_approach(float current, float target, float maxStep); +float lerp_clamped(float value, float inFirst, float inLast, float outFirst, float outLast); + +// A color tinted, with no colorize or offset (Color::Reset and SetTint). +constexpr ColorMod tint_color_make(float red, float green, float blue, float alpha) +{ + return {{red, green, blue, alpha}, {0, 0, 0, 0}, {0, 0, 0}}; +} diff --git a/src/entity_effect_ambient.cpp b/src/entity_effect_ambient.cpp index 076449e..46941b4 100644 --- a/src/entity_effect_ambient.cpp +++ b/src/entity_effect_ambient.cpp @@ -1,4 +1,4 @@ -#include "entity_effect_ambient.h" +#include "entity_effect.h" #include "data.h" #include "deathmatch_manager.h" #include "entity_tear.h" @@ -26,7 +26,6 @@ enum AmbientVariant : int { EFFECT_WATER_RIPPLE = 133, EFFECT_RAIN_DROP = 135, - EFFECT_CREEP_YELLOW = 24, EFFECT_PLAYER_CREEP_LEMON_MISHAP = 32, EFFECT_PLAYER_CREEP_HOLYWATER = 37, EFFECT_PLAYER_CREEP_WHITE = 44, @@ -39,22 +38,6 @@ enum AmbientVariant : int EFFECT_PLAYER_CREEP_YELLOW = 204 }; -// What an ambient variant runs: its part of Init, its frame and its draw. A missing one keeps the shared default. -struct AmbientBehaviour -{ - int variant = -1; - void (*init)(Entity_Effect&) = nullptr; - EffectUpdateEnd (*update)(Entity_Effect&) = nullptr; - void (*render)(Entity_Effect&, const Vector&) = nullptr; -}; - -// An update that always goes on to Update's shared end. -template EffectUpdateEnd finishing(Entity_Effect& effect) -{ - UPDATE(effect); - return EFFECT_UPDATE_FINISH; -} - constexpr int ROOM_BARREN_TYPE = 19; constexpr int SOUND_DROPLET_SPLASH = 397; constexpr int SOUND_SPAWNER_SUMMON = 265; @@ -272,20 +255,6 @@ static EntityList_EL entities_near(Vector position, float radius, uint32_t mask) return found; } -// Sets a layer to draw additively (BlendMode::SetMode 2). -static void layer_additive_set(LayerState& layer) -{ - KAGE::Graphics::BlendMode mode; - mode.SetMode(KAGE::Graphics::BLEND_ADDITIVE); - layer.blendMode = {mode.equation, mode.rgbSource, mode.rgbDest, mode.alphaSource, mode.alphaDest}; -} - -// A color tinted, with no colorize or offset (Color::Reset and SetTint). -static ColorMod tint_make(float red, float green, float blue, float alpha) -{ - return {{red, green, blue, alpha}, {0, 0, 0, 0}, {0, 0, 0}}; -} - // Spawns a blood splat of a bug's blood color where it died, at a scale, onto the floor or the wall. static void bug_splat(Entity_Effect& bug, uint64_t addedFlags) { @@ -611,18 +580,18 @@ static void wisp_init(Entity_Effect& wisp) if (is_listed(WISP_YELLOW_STAGES, stageId)) { wisp.sprite.Play("White"); - wisp.sprite.color = tint_make(1, 0.8f, 0, 1); - splat = tint_make(1, 1, 0.5f, 1); + wisp.sprite.color = tint_color_make(1, 0.8f, 0, 1); + splat = tint_color_make(1, 1, 0.5f, 1); } else if (is_listed(WISP_RED_STAGES, stageId)) { wisp.sprite.Play("Red"); - splat = tint_make(1, 0.5f, 0.5f, 1); + splat = tint_color_make(1, 0.5f, 0.5f, 1); } else if (stageId == WISP_ORANGE_STAGE) { wisp.sprite.Play("White"); - wisp.sprite.color = tint_make(1, 0.02f, 0, 1); + wisp.sprite.color = tint_color_make(1, 0.02f, 0, 1); } else wisp.sprite.Play("Blue"); wisp.splatColor = splat; @@ -1192,7 +1161,7 @@ static void creep_init(Entity_Effect& creep) creep.timeout = isLasting ? LASTING_CREEP_FRAMES : CREEP_FRAMES; creep.isUnknown176 = true; if (creep.variant == EFFECT_CREEP_RED && g_game->room->backdropType == BACKDROP_WOMB) - creep.sprite.color = tint_make(0.5f, 0.5f, 0.5f, 1); + creep.sprite.color = tint_color_make(0.5f, 0.5f, 0.5f, 1); if (creep.variant == EFFECT_CREEP_STATIC) creep.sprite.bitflags |= CREEP_STATIC_RENDER_FLAG; if (creep.variant == EFFECT_PLAYER_CREEP_GREEN) creep.timeout = GREEN_CREEP_FRAMES; if (creep.variant == EFFECT_PLAYER_CREEP_LEMON_MISHAP && creep.spawnerEntity && creep.spawnerEntity->is_player()) @@ -1310,6 +1279,51 @@ static void creep_slip(Entity_Effect&, Entity_Player& player) player.AddEntityFlags(FLAG_SLIPPERY_PHYSICS); } +// Dump's growing slippery creep: from a tenth of its size it grows by its scale a frame (to 1.25) while its +// parent lives, and shrinks and fades by 3.3 percent a frame once it dies. Fully opaque, it makes players slide. +constexpr float GROWING_CREEP_START = 0.1f; +constexpr float GROWING_CREEP_FULL = 1.25f; +constexpr float GROWING_CREEP_GROWTH = 0.033f; +constexpr float GROWING_CREEP_SHRINK = 0.033f; +constexpr int GROWING_CREEP_FRAMES = 60; +constexpr int GROWING_CREEP_RENDER_Z = 2000; + +static void growing_creep_init(Entity_Effect& creep) +{ + creep.sortingLayer = SORTING_BACKGROUND; + creep.renderZOffset = GROWING_CREEP_RENDER_Z; + creep.isUnknown176 = true; + creep.scale = GROWING_CREEP_GROWTH; +} + +// 005da27e (Update's growing slippery creep case) Grows from small while its parent lives, shrinks and fades away +// once dead, lasts 60 frames without a parent, and makes the players on it slide once fully shown. +static void growing_creep_update(Entity_Effect& creep) +{ + ANM2& sprite = creep.sprite; + if (creep.state == 0) + { + sprite.scale = vector_make(GROWING_CREEP_START, GROWING_CREEP_START); + sprite.color = COLOR_DEFAULT; + creep.state++; + } + + if (!creep.isDead) + { + float size = std::min(sprite.scale.x + creep.scale, GROWING_CREEP_FULL); + if (creep.parent) sprite.scale = vector_make(size, size); + } + else + { + float size = std::max(sprite.scale.x - GROWING_CREEP_SHRINK, 0.0f); + sprite.scale = vector_make(size, size); + sprite.color._tint[3] = std::max(sprite.color._tint[3] - GROWING_CREEP_SHRINK, 0.0f); + if (sprite.scale.x <= 0) creep.Remove(); + } + if (creep.timeout < 0 && !creep.parent) creep.timeout = GROWING_CREEP_FRAMES; + if (sprite.color._tint[3] >= 1) creep_players_touch(creep, creep_slip); +} + // Whether the players' creep reaches an entity: a vulnerable enemy on the ground that did not spawn it, within the // creep's radius squashed into a floor ellipse. A player counts unless creep cannot touch them. static bool is_creep_victim(Entity_Effect& creep, Entity& entity, float radius) @@ -1662,7 +1676,7 @@ static void lil_ghost_init(Entity_Effect& ghost) ghost.sprite.scale = vector_make(size, size); ghost.sprite.isFlipX = ghost.dropRNG.RandomInt(2) != 0; ghost.sprite.playbackSpeed = ghost.dropRNG.RandomFloat() * GHOST_SPEED_SPAN + 1; - if (is_listed(GHOST_PALE_BACKDROPS, g_game->room->backdropType)) ghost.sprite.color = tint_make(0.96f, 0.9f, 1, 1); + if (is_listed(GHOST_PALE_BACKDROPS, g_game->room->backdropType)) ghost.sprite.color = tint_color_make(0.96f, 0.9f, 1, 1); ghost.sprite.color._tint[3] = ghost.dropRNG.RandomFloat() * GHOST_ALPHA_SPAN + GHOST_ALPHA_MIN; ghost.isUnknown176 = true; } @@ -2061,82 +2075,52 @@ static void beetle_update(Entity_Effect& beetle) } // The ambient variants by their Init, Update and Render. -constexpr auto AMBIENT_BEHAVIOURS = std::to_array({ - {EFFECT_TINY_BUG, tiny_bug_init, finishing, nullptr}, - {EFFECT_TINY_FLY, tiny_fly_init, finishing, nullptr}, +constexpr auto AMBIENT_BEHAVIOURS = std::to_array({ + {EFFECT_TINY_BUG, tiny_bug_init, effect_finishing, nullptr}, + {EFFECT_TINY_FLY, tiny_fly_init, effect_finishing, nullptr}, {EFFECT_WATER_DROPLET, water_droplet_init, water_droplet_update, nullptr}, - {EFFECT_WISP, wisp_init, finishing, nullptr}, - {EFFECT_EMBER_PARTICLE, nullptr, finishing, nullptr}, - {EFFECT_WALL_BUG, wall_bug_init, finishing, nullptr}, - {EFFECT_ISAACS_CARPET, carpet_init, finishing, nullptr}, - {EFFECT_DICE_FLOOR, dice_floor_init, finishing, nullptr}, - {EFFECT_FALLING_EMBER, falling_ember_init, finishing, nullptr}, - {EFFECT_BROKEN_SHOVEL_SHADOW, shovel_shadow_init, finishing, nullptr}, - {EFFECT_SPAWNER, spawner_init, finishing, nullptr}, + {EFFECT_WISP, wisp_init, effect_finishing, nullptr}, + {EFFECT_EMBER_PARTICLE, nullptr, effect_finishing, nullptr}, + {EFFECT_WALL_BUG, wall_bug_init, effect_finishing, nullptr}, + {EFFECT_ISAACS_CARPET, carpet_init, effect_finishing, nullptr}, + {EFFECT_DICE_FLOOR, dice_floor_init, effect_finishing, nullptr}, + {EFFECT_FALLING_EMBER, falling_ember_init, effect_finishing, nullptr}, + {EFFECT_BROKEN_SHOVEL_SHADOW, shovel_shadow_init, effect_finishing, nullptr}, + {EFFECT_SPAWNER, spawner_init, effect_finishing, nullptr}, {EFFECT_LIGHT, light_init, light_update, nullptr}, - {EFFECT_WATER_RIPPLE, nullptr, finishing, nullptr}, - {EFFECT_RAIN_DROP, rain_drop_init, finishing, nullptr}, + {EFFECT_WATER_RIPPLE, nullptr, effect_finishing, nullptr}, + {EFFECT_RAIN_DROP, rain_drop_init, effect_finishing, nullptr}, {EFFECT_BACKDROP_DECORATION, kept_init, backdrop_decoration_update, nullptr}, {EFFECT_DOOR_OUTLINE, kept_init, nullptr, nullptr}, - {EFFECT_TALL_LADDER, kept_init, finishing, nullptr}, - {EFFECT_HEAVEN_LIGHT_DOOR, heaven_door_init, finishing, heaven_door_render}, - {EFFECT_TADPOLE, tadpole_init, finishing, nullptr}, - {EFFECT_BEETLE, beetle_init, finishing, nullptr}, - {EFFECT_LIL_GHOST, lil_ghost_init, finishing, nullptr}, - {EFFECT_CREEP_RED, creep_init, finishing, nullptr}, - {EFFECT_CREEP_GREEN, creep_init, finishing, nullptr}, - {EFFECT_CREEP_YELLOW, creep_init, finishing, nullptr}, - {EFFECT_CREEP_WHITE, creep_init, finishing, nullptr}, - {EFFECT_CREEP_BLACK, creep_init, finishing, nullptr}, - {EFFECT_PLAYER_CREEP_WHITE, creep_init, finishing, nullptr}, - {EFFECT_PLAYER_CREEP_BLACK, creep_init, finishing, nullptr}, - {EFFECT_PLAYER_CREEP_RED, creep_init, finishing, nullptr}, - {EFFECT_PLAYER_CREEP_GREEN, creep_init, finishing, nullptr}, - {EFFECT_PLAYER_CREEP_HOLYWATER_TRAIL, creep_init, finishing, nullptr}, - {EFFECT_CREEP_BROWN, creep_init, finishing, nullptr}, - {EFFECT_PLAYER_CREEP_BLACKPOWDER, creep_init, finishing, nullptr}, - {EFFECT_CREEP_SLIPPERY_BROWN, creep_init, finishing, nullptr}, - {EFFECT_CREEP_STATIC, creep_init, finishing, nullptr}, - {EFFECT_PLAYER_CREEP_YELLOW, creep_init, finishing, nullptr}, - {EFFECT_PLAYER_CREEP_LEMON_MISHAP, creep_init, finishing, nullptr}, - {EFFECT_PLAYER_CREEP_HOLYWATER, creep_init, finishing, nullptr}, - {EFFECT_PLAYER_CREEP_LEMON_PARTY, creep_init, finishing, nullptr}, - {EFFECT_PLAYER_CREEP_PUDDLE_MILK, creep_init, finishing, nullptr}, - {EFFECT_PENTAGRAM_BLACKPOWDER, creep_init, finishing, nullptr}, + {EFFECT_TALL_LADDER, kept_init, effect_finishing, nullptr}, + {EFFECT_HEAVEN_LIGHT_DOOR, heaven_door_init, effect_finishing, heaven_door_render}, + {EFFECT_TADPOLE, tadpole_init, effect_finishing, nullptr}, + {EFFECT_BEETLE, beetle_init, effect_finishing, nullptr}, + {EFFECT_LIL_GHOST, lil_ghost_init, effect_finishing, nullptr}, + {EFFECT_CREEP_RED, creep_init, effect_finishing, nullptr}, + {EFFECT_CREEP_GREEN, creep_init, effect_finishing, nullptr}, + {EFFECT_CREEP_YELLOW, creep_init, effect_finishing, nullptr}, + {EFFECT_CREEP_WHITE, creep_init, effect_finishing, nullptr}, + {EFFECT_CREEP_BLACK, creep_init, effect_finishing, nullptr}, + {EFFECT_PLAYER_CREEP_WHITE, creep_init, effect_finishing, nullptr}, + {EFFECT_PLAYER_CREEP_BLACK, creep_init, effect_finishing, nullptr}, + {EFFECT_PLAYER_CREEP_RED, creep_init, effect_finishing, nullptr}, + {EFFECT_PLAYER_CREEP_GREEN, creep_init, effect_finishing, nullptr}, + {EFFECT_PLAYER_CREEP_HOLYWATER_TRAIL, creep_init, effect_finishing, nullptr}, + {EFFECT_CREEP_BROWN, creep_init, effect_finishing, nullptr}, + {EFFECT_PLAYER_CREEP_BLACKPOWDER, creep_init, effect_finishing, nullptr}, + {EFFECT_CREEP_SLIPPERY_BROWN, creep_init, effect_finishing, nullptr}, + {EFFECT_CREEP_STATIC, creep_init, effect_finishing, nullptr}, + {EFFECT_PLAYER_CREEP_YELLOW, creep_init, effect_finishing, nullptr}, + {EFFECT_PLAYER_CREEP_LEMON_MISHAP, creep_init, effect_finishing, nullptr}, + {EFFECT_PLAYER_CREEP_HOLYWATER, creep_init, effect_finishing, nullptr}, + {EFFECT_PLAYER_CREEP_LEMON_PARTY, creep_init, effect_finishing, nullptr}, + {EFFECT_PLAYER_CREEP_PUDDLE_MILK, creep_init, effect_finishing, nullptr}, + {EFFECT_PENTAGRAM_BLACKPOWDER, creep_init, effect_finishing, nullptr}, + {EFFECT_CREEP_SLIPPERY_BROWN_GROWING, growing_creep_init, effect_finishing, nullptr}, }); -// The behaviours indexed by variant, for the variants up to the last vanilla one. -constexpr int AMBIENT_VARIANT_LIMIT = 256; -constexpr std::array AMBIENT_TABLE = [] { - std::array table{}; - for (const AmbientBehaviour& behaviour : AMBIENT_BEHAVIOURS) - if (behaviour.variant >= 0) table[behaviour.variant] = behaviour; - return table; -}(); - -static const AmbientBehaviour& behaviour_get(int variant) +std::span ambient_effect_behaviours() { - return AMBIENT_TABLE[variant]; -} - -bool is_ambient_effect(int variant) -{ - return variant >= 0 && variant < AMBIENT_VARIANT_LIMIT && AMBIENT_TABLE[variant].variant == variant; -} - -void ambient_effect_init(Entity_Effect& effect) -{ - if (auto init = behaviour_get(effect.variant).init) init(effect); -} - -EffectUpdateEnd ambient_effect_update(Entity_Effect& effect) -{ - auto update = behaviour_get(effect.variant).update; - return update ? update(effect) : EFFECT_UPDATE_FINISH; -} - -void ambient_effect_render(Entity_Effect& effect, const Vector& offset) -{ - if (auto render = behaviour_get(effect.variant).render) return render(effect, offset); - effect.sprite.Render(SpriteDraw{effect.renderPosition, {}, {}}); + return AMBIENT_BEHAVIOURS; } diff --git a/src/entity_effect_ambient.h b/src/entity_effect_ambient.h deleted file mode 100644 index 90c6444..0000000 --- a/src/entity_effect_ambient.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include "entity_effect.h" - -// The ambient and environment effects: the bugs, flies, wisps, drops and embers rooms scatter, the floor pieces -// rooms place (carpets, the dice floor, lights, decorations, ladders) and the creep and puddles enemies and players -// leave. Entity_Effect's Init, Update and Render hand these variants here. - -// Whether the variant is one of the ambient effects. -bool is_ambient_effect(int variant); - -// Starts an ambient effect after Init's shared start and before its LoadGraphics. -void ambient_effect_init(Entity_Effect& effect); - -// Runs an ambient effect's own frame, between Update's shared start (time scale, pause, parent) and its shared end. -[[nodiscard]] EffectUpdateEnd ambient_effect_update(Entity_Effect& effect); - -// Draws an ambient effect at its place on screen. -void ambient_effect_render(Entity_Effect& effect, const Vector& offset); diff --git a/src/entity_effect_beam.cpp b/src/entity_effect_beam.cpp new file mode 100644 index 0000000..b107740 --- /dev/null +++ b/src/entity_effect_beam.cpp @@ -0,0 +1,112 @@ +#include "entity_effect.h" +#include "entity_laser.h" +#include "entity_list.h" +#include "game.h" +#include "npc_ai.h" +#include "room.h" +#include + +// The beam effects: where a laser hits, the enemies' brimstone swirls that fire four beams, and the dark ball's +// smoke. + +// The enemies' brimstone swirl fires four thick beams a quarter turn apart, for 25 frames. +constexpr int SWIRL_BEAMS = 4; +constexpr float SWIRL_BEAM_TURN = 90; +constexpr int SWIRL_BEAM_FRAMES = 25; +constexpr int TEXTURE_FILTER_LINEAR = 1; + +// The dark ball's smoke: purple for subtype 1, drawn under what stands near. Subtype 2 fades back to a plain color by +// 2 percent a frame. +constexpr int DARK_SMOKE_PURPLE = 1; +constexpr int DARK_SMOKE_FADING = 2; +constexpr int DARK_SMOKE_RENDER_Z = -1000; +constexpr float DARK_SMOKE_FADE = 0.02f; + +// 00682a20 A value stepped toward a target by at most a step, reaching it when within the step. +static float value_approach(float value, float target, float step) +{ + if (std::fabs(value - target) <= step) return target; + return value < target ? value + step : value - step; +} + +// 005e951a (Update's laser impact case) Loops once its start ends, and dies with its laser. +static void laser_impact_update(Entity_Effect& impact) +{ + ANM2& sprite = impact.sprite; + const AnimationData* data = sprite.animState.animData; + if (data && data->name.starts_with('S') && sprite.IsFinished()) sprite.Play("Loop"); + if (impact.isDead) impact.Remove(); + if (!impact.parent) impact.isDead = true; +} + +// Draws a laser impact, upside down in the water's reflection. +// The original fades another online player's impacts, which offline never happens. +static void laser_impact_render(Entity_Effect& impact, const Vector&) +{ + ANM2& sprite = impact.sprite; + bool isReflected = g_game->room->entityList.renderMode == RENDER_WATER_REFLECT; + + if (isReflected) sprite.isFlipY = !sprite.isFlipY; + sprite.Render(SpriteDraw{impact.renderPosition, {}, {}}); + if (isReflected) sprite.isFlipY = !sprite.isFlipY; +} + +// The enemies' brimstone swirl: its glow filtered smoothly, spinning quickly. +static void enemy_swirl_init(Entity_Effect& swirl) +{ + LayerState* glow = swirl.sprite.GetLayer(1); + glow->minFilterMode = TEXTURE_FILTER_LINEAR; + glow->magFilterMode = TEXTURE_FILTER_LINEAR; + swirl.sprite.Play("IdleQuick"); +} + +// 00602bd3 (Update's enemy brimstone swirl case) Fires four beams a quarter turn apart on its Shoot event. +static void enemy_swirl_update(Entity_Effect& swirl) +{ + if (!swirl.sprite.IsEventTriggered("Shoot")) return; + + for (int i = 0; i < SWIRL_BEAMS; i++) + { + Entity_Laser::ShootAngle({.position = swirl.pos, + .posOffset = swirl.posOffset, + .source = &swirl, + .angleDegrees = (float)i * SWIRL_BEAM_TURN, + .timeout = SWIRL_BEAM_FRAMES, + .variant = LASER_THICK_RED}); + } +} + +// A puff of the dark ball's smoke: purple for subtype 1, one of its puffs, mirrored at random, drawn underneath. +static void dark_smoke_init(Entity_Effect& smoke) +{ + if (smoke.subtype == DARK_SMOKE_PURPLE) smoke.sprite.ReplaceSpritesheet(0, "gfx/Effects/Effect_088_PurpleBall.png"); + smoke.sprite.PlayRandom(Random()); + smoke.sprite.isFlipX = random_below(2) == 0; + smoke.renderZOffset = DARK_SMOKE_RENDER_Z; +} + +// 005ff870 (Update's dark ball smoke case) Fading smoke eases its tint to white and its colorize and offset away, at +// the room's time scale. The smoke goes once its animation ends. +static void dark_smoke_update(Entity_Effect& smoke) +{ + if (smoke.subtype == DARK_SMOKE_FADING) + { + ColorMod& color = smoke.sprite.color; + float step = smoke.speedMultiplier * DARK_SMOKE_FADE; + for (int i = 0; i < 3; i++) color._tint[i] = value_approach(color._tint[i], 1, step); + for (float& colorize : color._colorize) colorize = value_approach(colorize, 0, step); + for (float& offset : color._offset) offset = value_approach(offset, 0, step); + } + if (smoke.sprite.IsFinished()) smoke.Remove(); +} + +constexpr auto BEAM_BEHAVIOURS = std::to_array({ + {EFFECT_LASER_IMPACT, nullptr, effect_finishing, laser_impact_render}, + {EFFECT_DARK_BALL_SMOKE_PARTICLE, dark_smoke_init, effect_finishing, nullptr}, + {EFFECT_ENEMY_BRIMSTONE_SWIRL, enemy_swirl_init, effect_finishing, nullptr}, +}); + +std::span beam_effect_behaviours() +{ + return BEAM_BEHAVIOURS; +} diff --git a/src/entity_effect_floor.cpp b/src/entity_effect_floor.cpp new file mode 100644 index 0000000..a7b9f99 --- /dev/null +++ b/src/entity_effect_floor.cpp @@ -0,0 +1,560 @@ +#include "backdrop.h" +#include "capsule.h" +#include "entity_effect.h" +#include "fx_layers.h" +#include "game.h" +#include "npc_ai.h" +#include "npc_basement.h" +#include "room.h" +#include "room_grid.h" +#include "sfx_manager.h" +#include +#include + +// The floor effects: splashes and ripples on the room's water, the tar's bubbles, the dirt piles and patches +// shovels and diggers leave, and the haemolacria trail's drops. + +// A water splash: subtype 0 splashes where it lands, any other is a drop thrown up that falls back. +constexpr float SPLASH_ALPHA_MIN = 0.05f; +constexpr float SPLASH_ALPHA_SPAN = 0.15f; +constexpr float SPLASH_SCALE_MIN = 0.5f; +constexpr float SPLASH_SCALE_SPAN = 0.2f; +constexpr float SPLASH_VOLUME_MIN = 0.5f; +constexpr float SPLASH_VOLUME_SPAN = 0.5f; +constexpr float SPLASH_PITCH_MIN = 1; +constexpr float SPLASH_PITCH_SPAN = 2; +constexpr float SPLASH_FRICTION = 0.9f; +constexpr float SPLASH_DROP_GRAVITY = 0.5f; +constexpr float SPLASH_DROP_HEIGHT = -10; +constexpr float SPLASH_DROP_RISE_MIN = -1; +constexpr float SPLASH_DROP_RISE_SPAN = 2; +constexpr float SPLASH_DROP_SCALE_MIN = 0.5f; +constexpr float SPLASH_DROP_SCALE_SPAN = 0.5f; +constexpr float SPLASH_DROP_ALPHA_MIN = 0.1f; +constexpr float SPLASH_DROP_ALPHA_SPAN = 0.3f; +constexpr float SPLASH_DROP_DRAG = 0.9f; +constexpr float SPLASH_DROP_PULL = 0.1f; +constexpr float SPLASH_DROP_LANDED_HEIGHT = -5; + +// The big splash's subtypes 1 and 2 do not move with the game's time. +constexpr int BIG_SPLASH_STATIC_FIRST = 1; +constexpr int BIG_SPLASH_STATIC_LAST = 2; + +// The haemolacria trail's drops jitter by up to 2 units a frame. +constexpr float HAEMO_JITTER = 2; + +// A tar bubble plays one of three bubbles. +constexpr std::array BUBBLE_ANIMATIONS = {"Bubble1", "Bubble2", "Bubble3"}; + +// A dirt pile lasts 30 frames and takes the floor's color, brightened, unless its subtype says otherwise. +constexpr int DIRT_PILE_FRAMES = 30; +constexpr int DIRT_PILE_PLAIN = 0; +constexpr float DIRT_PILE_BRIGHTEN = 2; + +// A dirt patch: idle while buried (state 0), dug up (1) or dug up with bones (2). Digging it raises 2 to 4 dust +// clouds and 3 to 6 rocks, and the bones raise a lost soul. +enum DirtPatchState : int +{ + DIRT_PATCH_BURIED, + DIRT_PATCH_DUG, + DIRT_PATCH_BONES +}; +constexpr int DIRT_CLOUDS_MIN = 2; +constexpr int DIRT_CLOUDS_SPAN = 3; +constexpr float DIRT_CLOUD_SPEED = 5; +constexpr float DIRT_CLOUD_SPREAD = 20; +constexpr float DIRT_CLOUD_SPIN_MIN = 2; +constexpr float DIRT_CLOUD_SPIN_SPAN = 10; +constexpr int DIRT_CLOUD_FRAMES_MIN = 15; +constexpr int DIRT_CLOUD_FRAMES_SPAN = 15; +constexpr float DIRT_CLOUD_ALPHA_MIN = 0.2f; +constexpr float DIRT_CLOUD_ALPHA_SPAN = 0.5f; +constexpr int DIRT_ROCKS_MIN = 3; +constexpr int DIRT_ROCKS_SPAN = 4; +constexpr float DIRT_ROCK_SPREAD = 0.5f; +constexpr float DIRT_ROCK_SPEED_MIN = 2; +constexpr float DIRT_ROCK_SPEED_SPAN = 4; +constexpr float DIRT_ROCK_FLATTEN = 0.5f; +constexpr int ROCK_PARTICLE_THROWN = 1; + +// Big Horn's hand: it rises from a small hole, grabs (2) or slaps (3) its target, then sinks back (3) and goes. +// Its hole is drawn by a helper effect at the floor's depth, in the floor's brightened color. +enum BigHornHandState : int +{ + HAND_RISING, + HAND_GRABBING, + HAND_SLAPPING, + HAND_SINKING +}; +constexpr float HAND_HOLE_DEPTH = -5; +constexpr int HAND_RISEN_FRAME = 4; +constexpr float HAND_GRAB_DAMAGE = 20; +constexpr float HAND_GRAB_BOSS_DAMAGE = 60; +constexpr float HAND_CRUSH_DAMAGE = 20; +constexpr float HAND_CRUSH_BOSS_DAMAGE = 50; +constexpr float HAND_CRUSH_REACH = 20; +constexpr int HAND_CRUSH_NEW_FRAMES = 3; +constexpr int HAND_GRAB_SHAKE = 15; +constexpr float HAND_GRAB_SLAMS = 5; +constexpr float HAND_SLAP_FRICTION = 0.7f; +constexpr float HAND_SLAP_RISE = -30; +constexpr float HAND_SLAP_MARGIN = 10; +constexpr float HAND_SLAP_PULL = 0.04f; +constexpr float HAND_SLAP_SPEED = 4; +constexpr float HAND_SLAP_KNOCKBACK = 5; +constexpr float HAND_SLAP_DAMAGE = 12; +constexpr int HAND_SLAP_SHAKE = 6; +constexpr float HAND_SLAP_POOF_SIZE = 0.5f; +constexpr ColorMod HAND_SLAP_POOF_COLOR = {{1, 1, 1, 0.6f}, {0.7f, 0.7f, 0.7f, 1}, {0, 0, 0}}; +constexpr int HAND_DAMAGE_COUNTDOWN = 30; + +// The water a hand throws up in a flooded room: 8 to 13 drops where it slaps, 12 to 21 where it pops up, in an +// ellipse 60 by 40 wide. +constexpr float HAND_WATER_LEVEL = 0.2f; +constexpr float HAND_SPLASH_SPREAD_X = 60; +constexpr float HAND_SPLASH_SPREAD_Y = 40; +constexpr int HAND_SLAP_SPLASHES_MIN = 8; +constexpr int HAND_SLAP_SPLASHES_SPAN = 6; +constexpr int HAND_POP_SPLASHES_MIN = 12; +constexpr int HAND_POP_SPLASHES_SPAN = 10; +constexpr float HAND_SPLASH_SPEED_MIN = 3; +constexpr float HAND_SPLASH_SPEED_SPAN = 5; +constexpr float HAND_SPLASH_GROWTH = 2; +constexpr float HAND_SPLASH_RISE_MIN = -4; +constexpr float HAND_SPLASH_RISE_SPAN = 8; +constexpr float HAND_SPLASH_GRAVITY = 1.5f; +constexpr int SPLASH_DROP = 1; + +// A water effect in the room's water color, faded to an alpha. +static void water_color_set(Entity_Effect& effect, float alpha) +{ + effect.sprite.color = g_game->room->fxLayers.fxParams.waterEffectColor; + effect.sprite.color._tint[3] = alpha; +} + +// A water splash: a splash of the room's water, heard, or a drop of it thrown up. +static void water_splash_init(Entity_Effect& splash) +{ + ANM2& sprite = splash.sprite; + if (splash.subtype == 0) + { + water_color_set(splash, random_unit() * SPLASH_ALPHA_SPAN + SPLASH_ALPHA_MIN); + sprite.isFlipX = random_below(2) == 0; + float scale = random_unit() * SPLASH_SCALE_SPAN + SPLASH_SCALE_MIN; + sprite.scale = vector_make(scale, scale); + float pitch = random_unit() * SPLASH_PITCH_SPAN + SPLASH_PITCH_MIN; + npc_sound_play(SOUND_WET_FEET, random_unit() * SPLASH_VOLUME_SPAN + SPLASH_VOLUME_MIN, 2, pitch); + return; + } + + splash.fallingAcceleration = SPLASH_DROP_GRAVITY; + splash.height = SPLASH_DROP_HEIGHT; + splash.fallingSpeed = SPLASH_DROP_RISE_MIN - random_unit() * SPLASH_DROP_RISE_SPAN; + float scale = random_unit() * SPLASH_DROP_SCALE_SPAN + SPLASH_DROP_SCALE_MIN; + sprite.scale = vector_make(scale, scale); + water_color_set(splash, random_unit() * SPLASH_DROP_ALPHA_SPAN + SPLASH_DROP_ALPHA_MIN); +} + +// 005ffe30 (Update's water splash case) A splash slows and goes once it ends. A drop falls back and goes once it +// lands and its animation ends. +static void water_splash_update(Entity_Effect& splash) +{ + ANM2& sprite = splash.sprite; + if (splash.subtype == 0) + { + sprite.Play("Splash"); + if (sprite.IsFinished()) splash.Remove(); + splash.friction *= SPLASH_FRICTION; + return; + } + + sprite.Play("Particle"); + splash.fallingSpeed = splash.fallingSpeed * SPLASH_DROP_DRAG + SPLASH_DROP_PULL + splash.fallingAcceleration; + splash.height += splash.fallingSpeed; + splash.posOffset.y = splash.height; + if (splash.height > SPLASH_DROP_LANDED_HEIGHT && sprite.IsFinished()) splash.Remove(); +} + +// A big splash: static for subtypes 1 and 2, otherwise in the room's water color. +static void big_splash_init(Entity_Effect& splash) +{ + if (splash.subtype >= BIG_SPLASH_STATIC_FIRST && splash.subtype <= BIG_SPLASH_STATIC_LAST) + splash.sprite.bitflags |= ANIM_RENDER_STATIC; + else splash.sprite.color = g_game->room->fxLayers.fxParams.waterEffectColor; +} + +// A pedestal's ripple, in the room's water color. +static void pedestal_ripple_init(Entity_Effect& ripple) +{ + ripple.sprite.color = g_game->room->fxLayers.fxParams.waterEffectColor; +} + +// A rock's poof, mirrored by its own seed. +static void rock_poof_init(Entity_Effect& poof) +{ + poof.isUnknown176 = true; + poof.sprite.isFlipX = poof.dropRNG.RandomInt(2) != 0; +} + +static void haemo_trail_init(Entity_Effect& drop) +{ + drop.sprite.Play("Poof"); +} + +// 00602c78 (Update's haemolacria trail case) A drop jitters about and goes once its animation ends. +static void haemo_trail_update(Entity_Effect& drop) +{ + Vector direction = random_direction(); + drop.velocity = vector_add(drop.velocity, vector_scale(vector_scale(direction, random_unit()), HAEMO_JITTER)); + if (drop.sprite.IsFinished()) drop.Remove(); +} + +// A tar bubble: one of its three bubbles, mirrored at random. +static void tar_bubble_init(Entity_Effect& bubble) +{ + bubble.sprite.Play(BUBBLE_ANIMATIONS[random_below((int)BUBBLE_ANIMATIONS.size())]); + bubble.sprite.isFlipX = random_below(2) == 0; +} + +// 005d4b7a (Update's shared poof case, tar bubble part) A tar bubble takes the color of its parent's first layer, +// then goes like a poof. +static EffectUpdateEnd tar_bubble_update(Entity_Effect& bubble) +{ + if (bubble.parent && bubble.parent->sprite.animState.animData) + { + const AnimationFrame* frame = bubble.parent->sprite.animState.GetLayerFrame(0); + if (frame) bubble.sprite.color = frame->color; + } + return effect_poof_update(bubble); +} + +// A dirt pile: mirrored by its own seed, lasting 30 frames, in the floor's brightened color unless its subtype says. +static void dirt_pile_init(Entity_Effect& pile) +{ + pile.isUnknown176 = true; + pile.sprite.isFlipX = pile.dropRNG.RandomInt(2) != 0; + pile.SetTimeout(DIRT_PILE_FRAMES); + pile.sprite.Play("Appear"); + if (pile.subtype != DIRT_PILE_PLAIN) return; + + KColor floor = room_floor_color_get(*g_game->room, pile.pos, pile.size); + pile.sprite.color = tint_color_make(floor._red * DIRT_PILE_BRIGHTEN, floor._green * DIRT_PILE_BRIGHTEN, + floor._blue * DIRT_PILE_BRIGHTEN, 1); +} + +// 005d8e78 (Update's dirt pile case) Gone at once over a solid cell, and once it has sunk back when its time is up. +static void dirt_pile_update(Entity_Effect& pile) +{ + if (room_grid_collision_at(pile.pos) > 0) pile.Remove(); + if (!pile.isDead) return; + + pile.sprite.Play("Disappear"); + if (pile.sprite.IsFinished()) pile.Remove(); +} + +// A dirt patch: buried and kept, dark in the Dark Room. +static void dirt_patch_init(Entity_Effect& patch) +{ + patch.sprite.Play("Idle"); + patch.sortingLayer = SORTING_BACKGROUND; + patch.state = DIRT_PATCH_BURIED; + patch.damageSource = 0; + patch.AddEntityFlags(FLAG_DONT_OVERWRITE); + if (g_game->room->backdropType != BACKDROP_DARK_ROOM) return; + + patch.sprite.ReplaceSpritesheet(0, "gfx/Effects/dirtpatch_darkroom.png"); + patch.sprite.LoadGraphics(); +} + +// The dust a dug patch raises, spinning away from where it was thrown. +static void dirt_cloud_raise(Entity_Effect& patch) +{ + Vector heading = random_direction(); + Vector velocity = vector_scale(heading, random_unit() * DIRT_CLOUD_SPEED); + uint32_t seed = Random(); + Vector direction = random_direction(); + Vector position = vector_add(patch.pos, vector_scale(direction, random_unit() * DIRT_CLOUD_SPREAD)); + auto* cloud = static_cast(g_game->Spawn({.position = position, + .velocity = velocity, + .spawner = &patch, + .type = ENTITY_EFFECT, + .variant = EFFECT_DUST_CLOUD, + .seed = seed})); + + float side = vector_dot(vector_sub(cloud->pos, patch.pos), vector_make(velocity.y, -velocity.x)) < 0 ? -1 : 1; + cloud->rotation = (random_unit() * DIRT_CLOUD_SPIN_SPAN + DIRT_CLOUD_SPIN_MIN) * side; + cloud->SetTimeout(random_below(DIRT_CLOUD_FRAMES_SPAN) + DIRT_CLOUD_FRAMES_MIN); + cloud->SetColor(tint_color_make(1, 1, 1, random_unit() * DIRT_CLOUD_ALPHA_SPAN + DIRT_CLOUD_ALPHA_MIN), -1, + COLOR_PRIORITY_DEFAULT, false, true); + cloud->Update(); +} + +// A rock a dug patch throws: a piece of rubble of the Dark Room's or the caves' rocks. +static void dirt_rock_throw(Entity_Effect& patch) +{ + Vector direction = random_direction(); + Vector spread = vector_scale(vector_scale(direction, random_unit()), DIRT_ROCK_SPREAD); + Vector position = vector_add(patch.pos, vector_scale(spread, patch.size)); + Vector heading = random_direction(); + Vector velocity = vector_scale(heading, random_unit() * DIRT_ROCK_SPEED_SPAN + DIRT_ROCK_SPEED_MIN); + velocity.y *= DIRT_ROCK_FLATTEN; + auto* rock = static_cast(g_game->Spawn( + {.position = position, .velocity = velocity, .type = ENTITY_EFFECT, .variant = EFFECT_ROCK_PARTICLE, + .seed = Random()})); + + ANM2& sprite = rock->sprite; + sprite.Load("gfx/grid/grid_rock.anm2", GRAPHICS_DEFER); + bool isDarkRoom = g_game->room->backdropType == BACKDROP_DARK_ROOM; + sprite.ReplaceSpritesheet(0, isDarkRoom ? "gfx/grid/rocks_sheol.png" : "gfx/grid/rocks_caves.png"); + sprite.LoadGraphics(); + if (const AnimationData* rubble = sprite.GetAnimationData("rubble")) + sprite.SetFrame("rubble", random_below(rubble->length)); + rock->state = ROCK_PARTICLE_THROWN; + rock->Update(); +} + +// 006048ba (Update's dirt patch case) Shows its state, and the first time it changes after the patch's first frame +// it is dug up: dust and rocks fly, a shovel digs, and bones raise a lost soul. +static void dirt_patch_update(Entity_Effect& patch) +{ + if (patch.damageSource != patch.state) + { + if (patch.FrameCount() > 1 && patch.damageSource == 0) + { + for (int i = random_below(DIRT_CLOUDS_SPAN) + DIRT_CLOUDS_MIN; i > 0; i--) dirt_cloud_raise(patch); + for (int i = random_below(DIRT_ROCKS_SPAN) + DIRT_ROCKS_MIN; i > 0; i--) dirt_rock_throw(patch); + npc_sound_play(SOUND_SHOVEL_DIG, 1, 2, 1); + if (patch.state == DIRT_PATCH_BONES) + { + Entity* soul = g_game->Spawn({.position = patch.pos, .type = ENTITY_EFFECT, + .variant = EFFECT_FORGOTTEN_SOUL, .seed = Random()}); + soul->parent = &patch; + patch.child = soul; + soul->Update(); + } + } + patch.damageSource = patch.state; + } + + if (patch.state == DIRT_PATCH_BURIED) patch.sprite.Play("Idle"); + else patch.sprite.Play(patch.state == DIRT_PATCH_BONES ? "DugUpBones" : "DugUp"); +} + +// Big Horn's hand rising from its small hole, its hole handed to a helper drawn at the floor's depth in the floor's +// brightened color. +static void big_horn_hand_init(Entity_Effect& hand) +{ + hand.sprite.Play("SmallHoleOpen"); + hand.state = HAND_RISING; + hand.renderDepthOffset = HAND_HOLE_DEPTH; + LayerState* hole = hand.sprite.GetLayer("Hole"); + if (!hole) return; + + Entity* helper = g_game->Spawn({.position = hand.pos, .spawner = &hand, .type = ENTITY_EFFECT, + .variant = EFFECT_BIG_HORN_HOLE_HELPER, .seed = Random()}); + helper->parent = &hand; + static_cast(helper)->state = hole->layerData ? hole->layerData->id : -1; + hand.child = helper; + hole->isVisible = false; + + KColor floor = room_floor_color_get(*g_game->room, hand.pos, hand.size); + hole->color = tint_color_make(floor._red * DIRT_PILE_BRIGHTEN, floor._green * DIRT_PILE_BRIGHTEN, + floor._blue * DIRT_PILE_BRIGHTEN, 1); +} + +// The hand hurts what it lands on: a boss takes a heavy hit, a player a crushing one, anything else dies. +static void hand_crush(Entity_Effect& hand, Entity& victim, float damage, float bossDamage) +{ + EntityRef source(&hand); + if (victim.IsBoss()) victim.TakeDamage(bossDamage, DAMAGE_CRUSH, source, HAND_DAMAGE_COUNTDOWN); + else if (victim.is_player()) victim.TakeDamage(damage, DAMAGE_CRUSH, source, HAND_DAMAGE_COUNTDOWN); + else victim.Kill(source); +} + +// The drops of water a hand throws up around a place in a flooded room. +static void hand_water_splash(Vector place, int count) +{ + if (g_game->room->waterAmount <= HAND_WATER_LEVEL) return; + + for (int i = 0; i < count; i++) + { + Vector direction = random_direction(); + Vector offset = vector_make(HAND_SPLASH_SPREAD_X * direction.x, HAND_SPLASH_SPREAD_Y * direction.y); + float speed = random_unit() * HAND_SPLASH_SPEED_SPAN + HAND_SPLASH_SPEED_MIN; + Vector velocity = vector_make(offset.x * speed / HAND_SPLASH_SPREAD_X, offset.y * speed / HAND_SPLASH_SPREAD_Y); + auto* drop = static_cast(g_game->Spawn({.position = vector_add(place, offset), + .velocity = velocity, + .subType = SPLASH_DROP, + .type = ENTITY_EFFECT, + .variant = EFFECT_WATER_SPLASH, + .seed = Random()})); + drop->sprite.scale = vector_scale(drop->sprite.scale, HAND_SPLASH_GROWTH); + drop->fallingSpeed = HAND_SPLASH_RISE_MIN - random_unit() * HAND_SPLASH_RISE_SPAN; + drop->fallingAcceleration = HAND_SPLASH_GRAVITY; + drop->Update(); + } +} + +// The hand rising: gone if it rose for nothing, then grabbing an enemy target (slapping a boss), or sinking back. +static void big_horn_hand_rise(Entity_Effect& hand) +{ + Entity* target = hand.target; + if (!hand.sprite.IsFinished()) return; + + if (target && target->IsEnemy()) + { + hand.sprite.Play(target->IsBoss() ? "HandSlap" : "HandGrab"); + hand.state = target->IsBoss() ? HAND_SLAPPING : HAND_GRABBING; + return; + } + hand.sprite.Play("SmallHoleClose"); + hand.state = HAND_SINKING; +} + +// The hand grabbing: its slam crushes the target and shakes the room, then for five frames it kills what it holds +// and crushes what has just appeared under it. +static void big_horn_hand_grab(Entity_Effect& hand) +{ + ANM2& sprite = hand.sprite; + Entity* target = hand.target; + + if (sprite.IsEventTriggered("Slam")) + { + if (target) hand_crush(hand, *target, HAND_GRAB_DAMAGE, HAND_GRAB_BOSS_DAMAGE); + game_shake_screen(HAND_GRAB_SHAKE); + hand.scale = HAND_GRAB_SLAMS; + } + if (sprite.WasEventTriggered("Slam") && hand.scale > 0) + { + hand.scale -= 1; + if (target && !target->IsBoss() && !target->isDead && !target->is_player()) target->Kill(EntityRef(&hand)); + for (Entity* entity : entity_query_radius(hand.pos, HAND_CRUSH_REACH, QUERY_ALL)) + { + if (entity->entityCollisionClass == ENTCOLL_NONE || !entity->IsEnemy()) continue; + if (hand.IsDescendantOf(entity)) continue; + if (entity->HasEntityFlags(FLAG_FRIENDLY) || entity->FrameCount() >= HAND_CRUSH_NEW_FRAMES) continue; + hand_crush(hand, *entity, HAND_CRUSH_DAMAGE, HAND_CRUSH_BOSS_DAMAGE); + } + } + if (!sprite.IsFinished()) return; + + sprite.Play("SmallHoleClose"); + hand.state = HAND_SINKING; +} + +// The hand slapping: it drifts over its target between its Move and Stop events, and its slam knocks back and hurts +// what its Slam null reaches (but players, familiars and charmed enemies), raising dust, water and a thud. +static void big_horn_hand_slap(Entity_Effect& hand) +{ + ANM2& sprite = hand.sprite; + Entity* target = hand.target; + + hand.friction = HAND_SLAP_FRICTION; + if (target && sprite.WasEventTriggered("Move") && !sprite.WasEventTriggered("Stop")) + { + Vector above = g_game->room->GetClampedPosition(vector_add(target->pos, vector_make(0, HAND_SLAP_RISE)), + HAND_SLAP_MARGIN); + Vector pull = vector_scale(vector_sub(above, hand.pos), HAND_SLAP_PULL); + if (vector_length(pull) > HAND_SLAP_SPEED) pull = vector_resized(pull, HAND_SLAP_SPEED); + hand.AddVelocity(pull, false); + } + if (sprite.IsEventTriggered("Slam")) + { + Capsule slam; + hand.GetNullCapsule(slam, "Slam"); + if (slam.radius > 0) + { + for (Entity* entity : entity_query_radius(slam.center, slam.radius + slam.halfLength, QUERY_ALL)) + { + if (entity->entityCollisionClass == ENTCOLL_NONE || entity->entityGridCollisionClass == GRIDCOLL_BULLET) + continue; + if (entity == &hand || entity->is_player() || entity->IsFamiliar()) continue; + if (entity->IsEnemy() && entity->HasEntityFlags(FLAG_CHARM)) continue; + if (!Capsule::Collide(slam, entity->GetCollisionCapsule({}))) continue; + + Vector away = vector_normalized(vector_sub(entity->pos, hand.pos)); + entity->AddVelocity(vector_scale(away, HAND_SLAP_KNOCKBACK), true); + entity->TakeDamage(HAND_SLAP_DAMAGE, 0, EntityRef(&hand), HAND_DAMAGE_COUNTDOWN); + } + } + hand.MakeGroundPoof(slam.center, HAND_SLAP_POOF_COLOR, HAND_SLAP_POOF_SIZE); + hand_water_splash(slam.center, random_below(HAND_SLAP_SPLASHES_SPAN) + HAND_SLAP_SPLASHES_MIN); + game_shake_screen(HAND_SLAP_SHAKE); + npc_sound_play(SOUND_FORESTBOSS_STOMPS, 1, 2, 1); + } + if (!sprite.IsFinished()) return; + + sprite.Play("SmallHoleClose"); + hand.state = HAND_SINKING; +} + +// 005d52bd (Update's Big Horn hand case) Rises, grabs or slaps, sinks and goes. Water splashes where it pops up, and +// an enemy it holds is pulled along with it. +static EffectUpdateEnd big_horn_hand_update(Entity_Effect& hand) +{ + switch (hand.state) + { + case HAND_RISING: + if (!hand.target && hand.sprite.GetFrame() < HAND_RISEN_FRAME) + { + hand.Remove(); + return EFFECT_UPDATE_RETURN; + } + big_horn_hand_rise(hand); + break; + case HAND_GRABBING: big_horn_hand_grab(hand); break; + case HAND_SLAPPING: big_horn_hand_slap(hand); break; + default: + if (!hand.sprite.IsFinished()) break; + hand.Remove(); + return EFFECT_UPDATE_RETURN; + } + + if (hand.sprite.IsEventTriggered("Poof")) + hand_water_splash(hand.pos, random_below(HAND_POP_SPLASHES_SPAN) + HAND_POP_SPLASHES_MIN); + Entity* target = hand.target; + if (hand.state < HAND_SINKING && target && target->IsEnemy() && !target->isDead && !target->IsBoss() && + !target->is_player()) + target->velocity = vector_sub(hand.pos, target->pos); + return EFFECT_UPDATE_FINISH; +} + +// 005d510e (Update's Big Horn hole helper case) Stays on its hand on the floor, and goes with it. +static void hole_helper_update(Entity_Effect& helper) +{ + helper.sortingLayer = SORTING_BACKGROUND; + if (!helper.parent) return helper.Remove(); + helper.pos = helper.parent->pos; + helper.velocity = {}; +} + +// Draws the hand's hole layer (the helper's state) at the hand's place, shown only for this draw. +static void hole_helper_render(Entity_Effect& helper, const Vector& offset) +{ + Entity* hand = helper.parent; + if (!hand) return; + + LayerState* hole = hand->sprite.GetLayer(helper.state); + Vector screen = render_position_get(vector_add(hand->pos, hand->posOffset), RENDER_SNAPPED); + hole->isVisible = true; + hand->sprite.RenderLayer(helper.state, SpriteDraw{vector_add(screen, offset), {}, {}}); + hole->isVisible = false; +} + +constexpr auto FLOOR_BEHAVIOURS = std::to_array({ + {EFFECT_WATER_SPLASH, water_splash_init, effect_finishing, nullptr}, + {EFFECT_HAEMO_TRAIL, haemo_trail_init, effect_finishing, nullptr}, + {EFFECT_DIRT_PATCH, dirt_patch_init, effect_finishing, nullptr}, + {EFFECT_TAR_BUBBLE, tar_bubble_init, tar_bubble_update, nullptr}, + {EFFECT_BIG_SPLASH, big_splash_init, effect_poof_update, nullptr}, + {EFFECT_PEDESTAL_RIPPLE, pedestal_ripple_init, effect_poof_update, nullptr}, + {EFFECT_ROCK_POOF, rock_poof_init, effect_poof_update, nullptr}, + {EFFECT_DIRT_PILE, dirt_pile_init, effect_finishing, nullptr}, + {EFFECT_BIG_HORN_HOLE_HELPER, nullptr, effect_finishing, hole_helper_render}, + {EFFECT_BIG_HORN_HAND, big_horn_hand_init, big_horn_hand_update, nullptr}, +}); + +std::span floor_effect_behaviours() +{ + return FLOOR_BEHAVIOURS; +} diff --git a/src/entity_effect_hazard.cpp b/src/entity_effect_hazard.cpp new file mode 100644 index 0000000..be70145 --- /dev/null +++ b/src/entity_effect_hazard.cpp @@ -0,0 +1,430 @@ +#include "entity_bomb.h" +#include "entity_effect.h" +#include "entity_player.h" +#include "entity_projectile.h" +#include "game.h" +#include "grid_entity_poop.h" +#include "log.h" +#include "npc_ai.h" +#include "room.h" +#include "room_grid.h" +#include "sfx_manager.h" +#include + +// The hazard effects: the farts, the shockwaves and crackwaves that break the floor and crush what stands there, the +// white poop's hallowed ground and the statues' dying flash. + +// A fart: red for subtype 1, quiet from subtype 10 and from Mega Fatty, drawn over what stands near. +constexpr int FART_RED = 1; +constexpr int FART_QUIET = 10; +constexpr int FART_SOUND_DELAY = 20; +constexpr int FART_RENDER_Z = 1000; + +// How long a wave runs and the radius it grows between: the plain and directional shockwaves, the random one. +constexpr int SHOCKWAVE_PLAIN_FRAMES = 20; +constexpr float SHOCKWAVE_MIN_RADIUS = 20; +constexpr float SHOCKWAVE_MAX_RADIUS = 95; +constexpr int SHOCKWAVE_DIRECTIONAL_FRAMES = 50; +constexpr float SHOCKWAVE_DIRECTIONAL_MIN_RADIUS = 45; +constexpr float SHOCKWAVE_DIRECTIONAL_MAX_RADIUS = 320; +constexpr int SHOCKWAVE_RANDOM_FRAMES = 8; + +// A shockwave cracks its ring every 5 frames, a crack each 30 units around it, 15 units deep at random. The +// directional one cracks only within an arc around straight down, narrowing from a half turn to a tenth. +constexpr int SHOCKWAVE_PERIOD = 5; +constexpr float SHOCKWAVE_CRACK_SPACING = 30; +constexpr float SHOCKWAVE_CRACK_DEPTH = 15; +constexpr float SHOCKWAVE_ARC_WIDEST = PI_F / 2; +constexpr float SHOCKWAVE_ARC_NARROWEST = PI_F / 20; + +// A random shockwave cracks every 3 frames, 30 units further out each time, at angles 30 to 210 degrees apart. +constexpr int SHOCKWAVE_RANDOM_PERIOD = 3; +constexpr float SHOCKWAVE_RANDOM_SPACING = 30; +constexpr float SHOCKWAVE_RANDOM_STEP_MIN = 30; +constexpr float SHOCKWAVE_RANDOM_STEP_SPAN = 180; + +// A crack's crush: its damage (more in versus mode) and reach, and the sound of a ring breaking. +constexpr float CRACK_DAMAGE = 10; +constexpr float CRACK_VERSUS_DAMAGE = 70; +constexpr float CRACK_RADIUS = 20; +constexpr float CRACK_VOLUME = 0.4f; + +// A crackwave's crawl: 30 units a step every 2 frames (60 every 4 for the Beast's subtype 10), wobbling up to 75 +// degrees either way. Subtype 0 starts straight, subtype 1 never wobbles, subtype 2 wobbles more over 20 frames and +// subtype 3 homes on the grid cell in its state, turning harder near it, for 150 frames at most. +constexpr int CRACKWAVE_WOBBLE = 0; +constexpr int CRACKWAVE_GROWING = 2; +constexpr int CRACKWAVE_HOMING = 3; +constexpr int CRACKWAVE_BEAST = 10; +constexpr int CRACKWAVE_FRAMES = 240; +constexpr int CRACKWAVE_PERIOD = 2; +constexpr int CRACKWAVE_BEAST_PERIOD = 4; +constexpr float CRACKWAVE_STEP = 30; +constexpr float CRACKWAVE_BEAST_STEP = 60; +constexpr float CRACKWAVE_WOBBLE_SPAN = 150; +constexpr int CRACKWAVE_START_FRAMES = 6; +constexpr float CRACKWAVE_GROWTH_FRAMES = 20; +constexpr int CRACKWAVE_HOMING_FRAMES = 150; +constexpr float CRACKWAVE_HOMING_NEAR = 80; +constexpr float CRACKWAVE_HOMING_FAR = 400; +constexpr float CRACKWAVE_HOMING_TURN_NEAR = 40; +constexpr float CRACKWAVE_HOMING_TURN_FAR = 5; +constexpr float CRACKWAVE_UNHOMED_DISTANCE = 1000; +constexpr uint32_t CRACKWAVE_BEAST_COLLISION = 3; + +// The Beast's crackwave: the ghostly burst it leaves and its sound and shake. +constexpr int CRACKWAVE_BEAST_SHAKE = 6; +constexpr float CRACKWAVE_BEAST_VOLUME = 0.8f; +constexpr float CRACKWAVE_BEAST_PITCH_MIN = 0.9f; +constexpr float CRACKWAVE_BEAST_PITCH_SPAN = 0.2f; +constexpr int ENEMY_GHOST_BURST = 1; + +// A crackwave from an entity with sticky spiders throws three rocks 1 time in 4, each larger and further on. +constexpr int CRACKWAVE_ROCK_ODDS = 4; +constexpr int CRACKWAVE_ROCK_COUNT = 3; +constexpr float CRACKWAVE_ROCK_SPEED = 6; +constexpr float CRACKWAVE_ROCK_GRAVITY = 0.5f; +constexpr float CRACKWAVE_ROCK_RISE_MIN = -5; +constexpr float CRACKWAVE_ROCK_RISE_SPAN = 25; +constexpr float CRACKWAVE_ROCK_HEIGHT = -10; +constexpr float CRACKWAVE_ROCK_SCALE_MIN = 0.6f; +constexpr float CRACKWAVE_ROCK_SCALE_SPAN = 0.2f; +constexpr float CRACKWAVE_ROCK_GROWTH = 1.2f; +constexpr float CRACKWAVE_ROCK_DRAG = 0.9f; +constexpr float CRACKWAVE_ROCK_PULL = 0.1f; +constexpr ColorMod ROCK_PROJECTILE_COLOR = {{1, 1, 1, 1}, {4, 3.5f, 3.2f, 1}, {0, 0, 0}}; + +// The hallowed ground: -1 until it finds the white poop under it, 9999 while it follows a parent, -2 once it fades. +// Its glow breathes by up to 2 percent. +constexpr int HALLOWED_UNPLACED = -1; +constexpr int HALLOWED_FADING = -2; +constexpr int HALLOWED_FOLLOWING = 9999; +constexpr float HALLOWED_BREATH_MIN = 0.98f; +constexpr float HALLOWED_BREATH_SPAN = 0.04f; + +// A statue sinks 18 units into its cell when it appears, and from state 10 (its dying flash) plays a death cry. +constexpr int STATUE_DYING = 10; +constexpr float STATUE_SINK = 18; + +// Whether a wave can crack the floor at a point: inside the room and not over a pit or a wall. +static bool is_crackable(Vector point) +{ + Vector clamped = g_game->room->GetClampedPosition(point, 0); + if (point.x != clamped.x || point.y != clamped.y) return false; + + GridEntity* grid = room_grid_entity_at(point); + return !grid || (grid->type != GRID_PIT && grid->type != GRID_WALL); +} + +// Breaks the floor at a point and crushes what stands there, for a source. +static Entity* floor_crack(Vector point, Entity* source, float damage, float radius) +{ + Entity* rock = + g_game->Spawn({.position = point, .type = ENTITY_EFFECT, .variant = EFFECT_ROCK_EXPLOSION, .seed = Random()}); + explosion_damage( + {.position = point, .source = source, .damageFlags = DAMAGE_CRUSH, .damage = damage, .radius = radius, + .isLineCheck = false}); + return rock; +} + +// A fart: red for subtype 1, mirrored at random, heard unless quiet, drawn in front. +static void fart_init(Entity_Effect& fart) +{ + if (fart.subtype == FART_RED) + { + fart.sprite.ReplaceSpritesheet(0, "gfx/Effects/Effect_Fart_Red.png"); + fart.sprite.LoadGraphics(); + } + fart.sprite.isFlipX = !(Random() & 1); + + Entity* spawner = fart.spawnerEntity; + if ((uint32_t)fart.subtype < FART_QUIET && (!spawner || spawner->type != ENTITY_MEGA_FATTY)) + npc_sound_play(SOUND_FART, 1, FART_SOUND_DELAY, 1); + fart.renderZOffset = FART_RENDER_Z; +} + +// A shockwave is unseen: only its cracks show. +static void shockwave_init(Entity_Effect& wave) +{ + wave.isVisible = false; + wave.timeout = SHOCKWAVE_PLAIN_FRAMES; + wave.SetRadii(SHOCKWAVE_MIN_RADIUS, SHOCKWAVE_MAX_RADIUS); +} + +static void shockwave_directional_init(Entity_Effect& wave) +{ + wave.isVisible = false; + wave.timeout = SHOCKWAVE_DIRECTIONAL_FRAMES; + wave.SetRadii(SHOCKWAVE_DIRECTIONAL_MIN_RADIUS, SHOCKWAVE_DIRECTIONAL_MAX_RADIUS); +} + +static void shockwave_random_init(Entity_Effect& wave) +{ + wave.isVisible = false; + wave.timeout = SHOCKWAVE_RANDOM_FRAMES; +} + +static void crackwave_init(Entity_Effect& wave) +{ + wave.isVisible = false; + wave.timeout = CRACKWAVE_FRAMES; + wave.targetPosition = {}; +} + +// A ring of cracks growing from the minimum radius to the maximum as the timeout runs out, its first timeout kept +// in its state. The directional wave keeps to its narrowing arc. +static void shockwave_update(Entity_Effect& wave) +{ + if (wave.state < wave.timeout) wave.state = wave.timeout; + float timeout = (float)wave.timeout; + float radius = lerp_clamped(timeout, (float)wave.state, 0, wave.minRadius, wave.maxRadius); + float arc = lerp_clamped(timeout * timeout, (float)(wave.state * wave.state), 0, SHOCKWAVE_ARC_WIDEST, + SHOCKWAVE_ARC_NARROWEST); + + if (wave.timeout % SHOCKWAVE_PERIOD == 0) + { + int count = (int)(radius * PI_F * 2 / SHOCKWAVE_CRACK_SPACING); + float damage = g_game->deathmatchManager.is_active() ? CRACK_VERSUS_DAMAGE : CRACK_DAMAGE; + + for (int i = 0; i < count; i++) + { + float angle = (float)i / (float)count * (PI_F * 2); + if (wave.variant != EFFECT_SHOCKWAVE && std::fabs(angle - PI_F / 2) >= arc) continue; + + Vector direction = vector_make(std::cos(angle), std::sin(angle)); + float reach = random_unit() * SHOCKWAVE_CRACK_DEPTH + radius; + Vector point = vector_add(vector_scale(direction, reach), wave.pos); + if (is_crackable(point)) floor_crack(point, wave.parent, damage, CRACK_RADIUS); + } + npc_sound_play(SOUND_ROCK_CRUMBLE, CRACK_VOLUME, 2, 1); + } + if (wave.isDead) wave.Remove(); +} + +// Cracks every 3 frames at random angles around the effect, 30 units further out each time. +static void shockwave_random_update(Entity_Effect& wave) +{ + int frame = wave.FrameCount(); + if (frame % SHOCKWAVE_RANDOM_PERIOD == 0) + { + float start = random_unit() * DEGREES_PER_TURN; + float rings = (float)(frame / SHOCKWAVE_RANDOM_PERIOD); + + for (float angle = start; angle < start + DEGREES_PER_TURN;) + { + Vector step = vector_scale(vector_from_angle(angle), SHOCKWAVE_RANDOM_SPACING); + Vector point = vector_add(wave.pos, vector_scale(step, rings)); + if (is_crackable(point)) floor_crack(point, wave.spawnerEntity, CRACK_DAMAGE, CRACK_RADIUS); + npc_sound_play(SOUND_ROCK_CRUMBLE, CRACK_VOLUME, 2, 1); + angle += random_unit() * SHOCKWAVE_RANDOM_STEP_SPAN + SHOCKWAVE_RANDOM_STEP_MIN; + } + } + if (wave.isDead) wave.Remove(); +} + +// How far a crackwave strays from its heading this step, by its subtype. The homing one turns toward its cell. +static float crackwave_wobble(Entity_Effect& wave, int frame) +{ + switch (wave.subtype) + { + case CRACKWAVE_WOBBLE: + { + float wobble = random_unit() * CRACKWAVE_WOBBLE_SPAN - CRACKWAVE_WOBBLE_SPAN / 2; + return frame < CRACKWAVE_START_FRAMES ? wobble * (float)(frame % 2) / 4 : wobble; + } + case CRACKWAVE_GROWING: + { + if (frame <= CRACKWAVE_START_FRAMES) return 0; + float growth = std::min((float)(frame - CRACKWAVE_START_FRAMES) / CRACKWAVE_GROWTH_FRAMES, 1.0f); + return (random_unit() - 0.5f) * CRACKWAVE_WOBBLE_SPAN * growth; + } + case CRACKWAVE_HOMING: + { + float distance = CRACKWAVE_UNHOMED_DISTANCE; + if (wave.state > 0) + { + Vector cell = g_game->room->GetGridPosition(wave.state); + distance = vector_length(vector_sub(cell, wave.targetPosition)); + float turn = lerp_clamped(distance, CRACKWAVE_HOMING_NEAR, CRACKWAVE_HOMING_FAR, + CRACKWAVE_HOMING_TURN_NEAR, CRACKWAVE_HOMING_TURN_FAR); + wave.rotation = + angle_approach(wave.rotation, vector_angle(vector_sub(cell, wave.targetPosition)), turn); + if (room_grid_collision_at(cell) == 0 || wave.FrameCount() > CRACKWAVE_HOMING_FRAMES) + wave.state = -1; + } + if (wave.FrameCount() <= CRACKWAVE_START_FRAMES) return 0; + float wobble = random_unit() - 0.5f; + return lerp_clamped(distance, CRACKWAVE_HOMING_NEAR, CRACKWAVE_HOMING_FAR, 0, 1) * CRACKWAVE_WOBBLE_SPAN * + wobble; + } + default: return 0; + } +} + +// Three rocks thrown from where a crackwave broke the floor, each larger and further along its arc. +static void crackwave_rocks_throw(Entity_Effect& wave) +{ + Vector position = wave.targetPosition; + Vector heading = random_direction(); + Vector velocity = vector_scale(vector_scale(heading, random_unit()), CRACKWAVE_ROCK_SPEED); + float fallingSpeed = CRACKWAVE_ROCK_RISE_MIN - random_unit() * CRACKWAVE_ROCK_RISE_SPAN; + float height = CRACKWAVE_ROCK_HEIGHT; + float scale = random_unit() * CRACKWAVE_ROCK_SCALE_SPAN + CRACKWAVE_ROCK_SCALE_MIN; + + for (int i = 0; i < CRACKWAVE_ROCK_COUNT; i++) + { + auto* rock = static_cast(g_game->Spawn({.position = position, + .velocity = velocity, + .spawner = wave.spawnerEntity, + .type = ENTITY_PROJECTILE, + .seed = Random()})); + rock->fallingAccel = CRACKWAVE_ROCK_GRAVITY; + rock->fallingSpeed = fallingSpeed; + rock->height = height; + rock->SetColor(ROCK_PROJECTILE_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); + rock->scale = scale; + + position = vector_add(position, velocity); + fallingSpeed = CRACKWAVE_ROCK_GRAVITY + CRACKWAVE_ROCK_DRAG * fallingSpeed + CRACKWAVE_ROCK_PULL; + height += fallingSpeed; + scale *= CRACKWAVE_ROCK_GROWTH; + } +} + +// A crackwave's step: it crawls on from its last crack, gone once it leaves the room or meets a pit, a wall or a +// solid cell, cracking and crushing where it lands. +static void crackwave_step(Entity_Effect& wave, int frame) +{ + bool isBeast = wave.subtype == CRACKWAVE_BEAST; + + if (vector_is_zero(wave.targetPosition)) wave.targetPosition = wave.pos; + float wobble = crackwave_wobble(wave, frame); + float step = isBeast ? CRACKWAVE_BEAST_STEP : CRACKWAVE_STEP; + Vector heading = vector_from_angle(wave.rotation + wobble); + wave.targetPosition = vector_add(wave.targetPosition, vector_scale(heading, step)); + if (!is_crackable(wave.targetPosition)) return wave.Remove(); + + if (room_grid_collision_at(wave.targetPosition) > (isBeast ? CRACKWAVE_BEAST_COLLISION : 0)) wave.Remove(); + else if (isBeast) + { + npc_sound_play(SOUND_DEMON_HIT, CRACKWAVE_BEAST_VOLUME, + 2, random_unit() * CRACKWAVE_BEAST_PITCH_SPAN + CRACKWAVE_BEAST_PITCH_MIN); + game_shake_screen(CRACKWAVE_BEAST_SHAKE); + Entity* ghost = g_game->Spawn({.position = wave.targetPosition, .spawner = wave.spawnerEntity, + .subType = ENEMY_GHOST_BURST, .type = ENTITY_EFFECT, + .variant = EFFECT_ENEMY_GHOST, .seed = Random()}); + ghost->sprite.rotation = random_unit() * DEGREES_PER_TURN; + ghost->SetCollisionDamage(0); + ghost->Update(); + } + else + { + Entity* rock = floor_crack(wave.targetPosition, wave.spawnerEntity, CRACK_DAMAGE, + wave.sprite.scale.x * CRACK_RADIUS); + rock->sprite.scale = wave.sprite.scale; + } + if (isBeast) + reconstruction_missing("Entity_Effect::Update 005d4380: the Beast's crackwave damage (Game::DamageRadius)"); + + if (wave.HasEntityFlags(FLAG_SPAWN_STICKY_SPIDERS) && random_below(CRACKWAVE_ROCK_ODDS) == 0) + crackwave_rocks_throw(wave); +} + +// 005fbe1a (Update's crackwave case) A line of cracks crawling across the room every few frames. +static void crackwave_update(Entity_Effect& wave) +{ + int frame = wave.FrameCount(); + int period = wave.subtype == CRACKWAVE_BEAST ? CRACKWAVE_BEAST_PERIOD : CRACKWAVE_PERIOD; + if (frame % period == 0) + { + crackwave_step(wave, frame); + if (wave.subtype != CRACKWAVE_BEAST) npc_sound_play(SOUND_ROCK_CRUMBLE, CRACK_VOLUME, 2, 1); + } + if (wave.isDead) wave.Remove(); +} + +// The hallowed ground glows additively as it appears. +static void hallowed_ground_init(Entity_Effect& ground) +{ + layer_additive_set(*ground.sprite.GetLayer(0)); + ground.sprite.Play("Appear"); + ground.state = HALLOWED_UNPLACED; +} + +// Whether the white poop under the hallowed ground still stands. +static bool is_hallowed_poop_whole(Entity_Effect& ground) +{ + GridEntity* poop = g_game->room->GetGridEntity((uint32_t)ground.state); + return poop && poop->type == GRID_POOP && poop->variant == POOP_WHITE && poop->state != POOP_STATE_BROKEN; +} + +// 00602d32 (Update's hallowed ground case) Settles on the cell it stands on, or on its parent, breathes while it +// idles and fades once its white poop breaks or its parent goes. +static EffectUpdateEnd hallowed_ground_update(Entity_Effect& ground) +{ + if (ground.state == HALLOWED_UNPLACED) + { + if (ground.parent) ground.state = HALLOWED_FOLLOWING; + else + { + ground.state = g_game->room->GetGridIndex(ground.pos); + if (ground.state < 0) + { + ground.Remove(); + return EFFECT_UPDATE_RETURN; + } + } + } + if (ground.parent) ground.posOffset = ground.parent->posOffset; + + ANM2& sprite = ground.sprite; + if (ground.state < 0) + { + if (sprite.IsFinished()) ground.Remove(); + return EFFECT_UPDATE_FINISH; + } + + if (sprite.IsFinished()) sprite.Play("Idle"); + if (sprite.animState.IsLoopingAnimation()) + { + float breath = random_unit() * HALLOWED_BREATH_SPAN + HALLOWED_BREATH_MIN; + sprite.GetLayer(0)->size = vector_make(breath, breath); + } + bool isFading = ground.state == HALLOWED_FOLLOWING ? !ground.parent : !is_hallowed_poop_whole(ground); + if (!isFading) return EFFECT_UPDATE_FINISH; + + sprite.Play("Disappear"); + ground.state = HALLOWED_FADING; + return EFFECT_UPDATE_FINISH; +} + +// 005efb10 (Update's statue case) Sinks into its cell on its first frame. Dying, it cries in its player's voice. +static void statue_update(Entity_Effect& statue) +{ + if (statue.state == 0) + { + statue.pos.y += STATUE_SINK; + statue.state++; + } + if (statue.state != STATUE_DYING || !statue.sprite.IsEventTriggered("DeathSound")) return; + + Entity* spawner = statue.spawnerEntity; + Entity_Player* player = spawner ? spawner->ToPlayer() : nullptr; + npc_sound_play(SOUND_ISAACDIES, 1, 2, player ? player->get_voice_pitch() : 1); +} + +constexpr auto HAZARD_BEHAVIOURS = std::to_array({ + {EFFECT_DEVIL, nullptr, effect_finishing, nullptr}, + {EFFECT_ANGEL, nullptr, effect_finishing, nullptr}, + {EFFECT_FART, fart_init, effect_poof_update, nullptr}, + {EFFECT_SHOCKWAVE, shockwave_init, effect_finishing, nullptr}, + {EFFECT_SHOCKWAVE_DIRECTIONAL, shockwave_directional_init, effect_finishing, nullptr}, + {EFFECT_CRACKWAVE, crackwave_init, effect_finishing, nullptr}, + {EFFECT_SHOCKWAVE_RANDOM, shockwave_random_init, effect_finishing, nullptr}, + {EFFECT_HALLOWED_GROUND, hallowed_ground_init, hallowed_ground_update, nullptr}, +}); + +std::span hazard_effect_behaviours() +{ + return HAZARD_BEHAVIOURS; +} diff --git a/src/entity_factory.cpp b/src/entity_factory.cpp index 665f90a..86f9ae3 100644 --- a/src/entity_factory.cpp +++ b/src/entity_factory.cpp @@ -31,18 +31,14 @@ constexpr int SPAWN_STATUS_FRAMES = 90; constexpr int ENTITY_HORF = 12; constexpr int ENTITY_MAW = 26; constexpr int ENTITY_HOST = 27; -constexpr int ENTITY_STONEHEAD = 42; constexpr int ENTITY_FLAMINGHOPPER = 54; constexpr int ENTITY_MEMBRAIN = 57; -constexpr int ENTITY_PARA_BITE = 58; constexpr int ENTITY_EYE = 60; constexpr int ENTITY_WALKINGBOIL = 88; constexpr int ENTITY_NERVE_ENDING = 231; -constexpr int ENTITY_HUSH_GAPER = 297; constexpr int ENTITY_GREED_GAPER = 299; constexpr int ENTITY_MUSHROOM = 300; constexpr int ENTITY_SUB_HORF = 812; -constexpr int ENTITY_STRIDER = 814; constexpr int ENTITY_GYRO = 824; constexpr int EFFECT_CRAWLSPACE_LADDER = 192; constexpr int BOSS_SATAN = 24; @@ -741,7 +737,7 @@ void room_entry_transform(Room& room, RoomEntry& entry, int gridIndex, uint32_t entry.variant = entry.type == ENTRY_FIREPLACE_RED || rng.Next() % FIREPLACE_RED_ODDS == 0; entry.type = ENTITY_FIREPLACE; } - lua_callback_check(MC_PRE_ROOM_ENTITY_SPAWN, "LuaEngine::PreRoomEntitySpawn 00866490"); + bool isScripted = lua_engine_get().PreRoomEntitySpawn(entry, gridIndex, seed); if (entry.type == ENTITY_PICKUP && entry.variant == PICKUP_RANDOM_CARD) { entry.variant = PICKUP_TAROTCARD; @@ -750,6 +746,8 @@ void room_entry_transform(Room& room, RoomEntry& entry, int gridIndex, uint32_t RNG cardRng = {cardSeed, ENTRY_RNG._shift1, ENTRY_RNG._shift2, ENTRY_RNG._shift3}; entry.subtype = lua_engine_get().GetCard({.rng = &cardRng, .card = card, .isOnlyRunes = true, .isRunes = true}); } + if (isScripted) return; + entry_locked_replace(entry, rng); int stage = stage_effective(); diff --git a/src/entity_familiar.cpp b/src/entity_familiar.cpp index e00c2d3..5c95eba 100644 --- a/src/entity_familiar.cpp +++ b/src/entity_familiar.cpp @@ -189,7 +189,7 @@ bool familiar_unicorn_active(Entity_Player& owner) owner.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_UNICORN_STUMP_ID); } -// Isaac::GetAxisAlignedUnitVectorFromDir 0067f1d0: the unit step of a direction, none for no direction. +// 0067f1d0 Isaac::GetAxisAlignedUnitVectorFromDir: the unit step of a direction, none for no direction. Vector direction_unit(int direction) { constexpr float STEPS[][2] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}}; @@ -511,6 +511,9 @@ void Entity_Familiar::variant_update() case LITTLE_CHUBBY: case BOBS_BRAIN: return ai_charger(); case DEAD_BIRD: return ai_flying_bird(); + case INCUBUS: + FollowParent(); + return update_weapon(false); case BLUE_FLY: return ai_blue_fly(); default: reconstruction_missing("Entity_Familiar::Update 0061da10 (this familiar's behaviour)"); } @@ -573,14 +576,13 @@ void Entity_Familiar::update_tail() } } -// 00624a80 Moves between frames: the orbit's spin carried for the move only. The variants that act on interpolation -// stop the game. +// 00624a80 Moves between frames: the orbit's spin carried for the move only. Incubus aims and fires between frames too, +// the other variants that act on interpolation stop the game. void Entity_Familiar::Interpolate() { - if (variant == LIL_BRIMSTONE || variant == INCUBUS || variant == DAMOCLES || variant == BLOOD_BABY || - variant == UMBILICAL_BABY) - reconstruction_missing("Entity_Familiar::Interpolate 00624a80 (this " - "familiar's interpolation)"); + if (variant == LIL_BRIMSTONE || variant == DAMOCLES || variant == BLOOD_BABY || variant == UMBILICAL_BABY) + reconstruction_missing("Entity_Familiar::Interpolate 00624a80 (this familiar's interpolation)"); + if (variant == INCUBUS) update_weapon(true); float savedAngle = orbitAngleOffset; if (orbitLayer >= 0) diff --git a/src/entity_familiar.h b/src/entity_familiar.h index b5615a4..6c6e1cf 100644 --- a/src/entity_familiar.h +++ b/src/entity_familiar.h @@ -428,6 +428,7 @@ std::vector familiar_query(int queryVariant); bool familiar_versus(); void familiar_sound_play(int sound, SoundPlay play = {}); bool familiar_unicorn_active(Entity_Player& owner); +Entity* spawn_dip_at(int subType, const Vector* position, Entity* spawner, const Vector* targetPosition); float angle_wrap(float angle); Vector direction_unit(int direction); void familiar_check(Entity_Player& player, const FamiliarCount& familiars); diff --git a/src/entity_knife.h b/src/entity_knife.h index a35543d..ff9ba99 100644 --- a/src/entity_knife.h +++ b/src/entity_knife.h @@ -1,17 +1,16 @@ #pragma once #include "entity.h" -#include +#include "homing_laser.h" #include -// Construction and destruction (00960b50, 00960a70) are the defaults. The homing path waits for HomingLaser's -// takeover. +// Construction and destruction (00960b50, 00960a70) are the defaults. // Field accessors (004d7790, 004d77a0, 0060cf10, 0060cfb0, 0085de90, 0085deb0, 0085dec0) are the public fields. // A knife (Lua's EntityKnife): Mom's Knife and the swung weapons (bones, clubs, swords), with the tear effects they // carry, their charge and flight, and the path a homing knife follows. struct Entity_Knife : Entity { - std::unique_ptr homingLaser; + HomingLaser homingLaser; std::vector hitList; TearFlags tearFlags; TearFlags usedTearFlags; diff --git a/src/entity_laser.cpp b/src/entity_laser.cpp index 539c3e8..3e90fd4 100644 --- a/src/entity_laser.cpp +++ b/src/entity_laser.cpp @@ -1,9 +1,225 @@ #include "entity_laser.h" +#include "boss_ai.h" +#include "entity_effect.h" +#include "entity_factory.h" +#include "entity_familiar.h" +#include "entity_player.h" +#include "entity_tear.h" +#include "fx_layers.h" +#include "game.h" #include "log.h" +#include "lua_engine.h" +#include "manager.h" +#include "npc_ai.h" +#include "npc_basement.h" +#include "room.h" +#include "room_config.h" +#include "sfx_manager.h" +#include +#include -// The laser subtypes that draw a ring. -constexpr int LASER_SUBTYPE_RING_FIRST = 1; -constexpr int LASER_SUBTYPE_RING_LAST = 3; +constexpr float THIN_SCALE_THRESHOLDS[] = {1.15f, 2.2f, 4.2f}; +constexpr float THIN_SCALE_DIVISORS[] = {1, 2, 4, 6}; +constexpr float BEAM_REACH = 1200; +constexpr float BEAM_FAR = 10000; +constexpr float BEAM_UNBLOCKED = 1000; +constexpr float BEAM_BACKSTEP = 4; +constexpr float BEAM_MARGIN = 20; +constexpr float BEAM_MARGIN_CONTINUUM = 140; +constexpr float BEAM_MARGIN_OCCULT = 100; +constexpr float BEAM_GIANT_EXTRA = 100; +constexpr float BEAM_GIANT_MINIMUM = 88; +constexpr float BEAM_START_NUDGE = 0.1f; +constexpr float BEAM_GIANT_TIP_GAP = 50; +constexpr float PRIDE_LENGTH = 300; +constexpr float RING_RADIUS = 80; +constexpr float AXIS_SNAP = 0.0001f; +constexpr float SPRITE_ROTATION_OFFSET = 90; +constexpr float ANGLE_FULL_TURN = 360; +constexpr float ANGLE_HALF_TURN = 180; +constexpr float ROTATION_STEP_SCALE = 0.5f; +constexpr float SCALE_SMALL = 0.75f; +constexpr float SCALE_LARGE = 1.45f; +constexpr float ZAP_PITCH_MIN = 0.85f; +constexpr float ZAP_VOLUME_WEAK = 0.5f; +constexpr float RING_VOLUME_WEAK = 0.85f; +constexpr float ZAP_VOLUME_STRONG = 1.1f; +constexpr float ZAP_PITCH_RANGE = 0.3f; +constexpr float ELECTRIC_PITCH_MIN = 0.9f; +constexpr float ELECTRIC_PITCH_RANGE = 0.2f; +constexpr float ELECTRIC_VOLUME = 0.6f; +constexpr float RING_SOUND_VOLUME = 0.6f; +constexpr float OWNER_ZAP_VOLUME = 0.9f; +constexpr float BABY_ZAP_VOLUME = 0.4f; +constexpr float SHRINK_RATE = 0.895f; +constexpr int SHRINK_TIMEOUT_END = -19; +constexpr int SHAKE_GIANT = 4; +constexpr int SHAKE_STRONG = 10; +constexpr int LASER_WAIT_FRAMES = 2; +constexpr float WAIT_SCALE_THICKER = 2; +constexpr float WAIT_SCALE_GIANT = 3; +constexpr float WAIT_SCALE_BEAST = 5; +constexpr float RAINBOW_FRAMES = 30; +constexpr float RAINBOW_SATURATION = 0.9f; +constexpr float RAINBOW_STRENGTH = 4; +constexpr int CONTINUUM_PHASES = 8; +constexpr float CONTINUUM_COLORIZE = 2.5f; +constexpr float CONTINUUM_GREEN_STEP = 0.625f; +constexpr float IMPACT_DEPTH = 5; +constexpr float IMPACT_DEPTH_FOLLOW = -5; +constexpr float IMPACT_SCALE_MIN = 0.04f; +constexpr float IMPACT_SCALE_KEPT = 0.75f; +constexpr float IMPACT_SCALE_BASE = 0.25f; +constexpr float IMPACT_SCALE_GIANT = 1.5f; +constexpr float TEAR_TINT_RED = 0.85f; +constexpr float TEAR_TINT_GREEN = 0.9f; +constexpr float TEAR_COLOR_HALF = 0.5f; +constexpr float LUMINANCE_RED = 0.212671f; +constexpr float LUMINANCE_GREEN = 0.71516f; +constexpr float LUMINANCE_BLUE = 0.072169f; +constexpr float L_ROOM_ARM_WIDTH = 520; +constexpr float L_ROOM_ARM_HEIGHT = 280; +constexpr float GRID_HIT_OFFSET_SCALE = 0.4f; +constexpr float VERSUS_RING_DAMAGE = 0.5f; +constexpr int SPAWNER_CAGE = 265; +constexpr int SPAWNER_FORSAKEN = 403; +constexpr int SPAWNER_MEGA_SATAN = 274; +constexpr int SPAWNER_DOGMA = 950; +constexpr int SPAWNER_MONSTRO_2 = 43; +constexpr int SPAWNER_MOMS_HEART_LASER = 49; +constexpr int SPAWNER_EYE = 60; +constexpr int SPAWNER_PIN = 62; +constexpr int SPAWNER_VIS = 39; +constexpr int SPAWNER_PEEP = 68; +constexpr int SPAWNER_BABY = 201; +constexpr int SPAWNER_PATH_KEEPER_1 = 263; +constexpr int SPAWNER_PATH_KEEPER_2 = 268; +constexpr int SPAWNER_PATH_KEEPER_3 = 410; +constexpr int SPAWNER_RING_KEEPER = 260; +constexpr int EFFECT_SAMPLE_PARENT = 178; +constexpr int FAMILIAR_ANGELIC_PRISM = 123; +constexpr int WISP_DAMAGED_SUBTYPE = 427; +constexpr int EFFECT_LASER_MIRROR = 188; +constexpr int IMPACT_SUBTYPE_THIN = 0; +constexpr int IMPACT_SUBTYPE_THICK = 1; +constexpr int IMPACT_SUBTYPE_SHOOP = 2; +constexpr int IMPACT_SUBTYPE_CAGE = 3; +constexpr int IMPACT_SUBTYPE_RING = 5; +constexpr int IMPACT_SUBTYPE_GIANT = 6; +constexpr int IMPACT_SUBTYPE_BROWN = 7; +constexpr int IMPACT_SUBTYPE_GIANT_END = 4; +constexpr const char* STATIC_LASER_ANM2 = "gfx/007.001_Static Laser.anm2"; +constexpr const char* CAGE_VIS_LASER_ANM2 = "gfx/007.006_CageVisLaser.anm2"; +constexpr const char* STATIC_IMPACT_ANM2 = "gfx/1000.050_brimstoneimpact_static.anm2"; + +// Whether a tear flag set has any of some bits. +bool tear_flags_any(const TearFlags& flags, std::initializer_list bits) +{ + return std::any_of(bits.begin(), bits.end(), [&](int bit) { return flags[(size_t)bit]; }); +} + +// A random fraction of one as the game draws it. +static float random_fraction() +{ + return random_unit(); +} + +// A colorize from a hue in degrees, a saturation and a value at a strength, as hsv_to_rgb makes the color. +static ColorMod colorize_from_hue(float hue, float saturation, float value, float strength) +{ + float chroma = saturation * value; + float second = (1 - std::abs(std::fmod(hue / 60, 2.0f) - 1)) * chroma; + float red = 0; + float green = 0; + float blue = 0; + switch ((int)(hue / 60) % 6) + { + case 0: + red = chroma; + green = second; + break; + case 1: + red = second; + green = chroma; + break; + case 2: + green = chroma; + blue = second; + break; + case 3: + green = second; + blue = chroma; + break; + case 4: + red = second; + blue = chroma; + break; + case 5: + red = chroma; + blue = second; + break; + default: + break; + } + float base = value - chroma; + return {{1, 1, 1, 1}, {(red + base) * strength, (green + base) * strength, (blue + base) * strength, 1}, {0, 0, 0}}; +} + +// The player a laser's tears come from: its spawner, or the player of a familiar that fires the player's lasers. +static Entity_Player* laser_owner_player(Entity* spawner) +{ + if (!spawner) return nullptr; + if (spawner->type == ENTITY_PLAYER) return spawner->ToPlayer(); + if (spawner->type != ENTITY_FAMILIAR) return nullptr; + + int familiar = spawner->variant; + bool isFiring = familiar == Entity_Familiar::INCUBUS || familiar == Entity_Familiar::TWISTED_BABY || + familiar == Entity_Familiar::UMBILICAL_BABY || familiar == Entity_Familiar::BLOOD_BABY; + return isFiring ? static_cast(spawner)->player : nullptr; +} + +// Plays a sound through the fart seeds. +static void laser_sound_play(int sound, SoundPlay play) +{ + seed_fart_sound_override(&sound); + g_manager->sfxManager.Play(sound, play); +} + +// A color's tint, colorize and offset applied to a KColor, as Color::apply_to_kcolor does. +static KColor color_apply(const ColorMod& color, const KColor& input) +{ + float red = color._tint[0] * input._red; + float green = color._tint[1] * input._green; + float blue = color._tint[2] * input._blue; + if (color._colorize[3] != 0) + { + float luminance = green * LUMINANCE_GREEN + red * LUMINANCE_RED + blue * LUMINANCE_BLUE; + red += (luminance * color._colorize[0] - red) * color._colorize[3]; + green += (luminance * color._colorize[1] - green) * color._colorize[3]; + blue += (luminance * color._colorize[2] - blue) * color._colorize[3]; + } + return kcolor_rgba(red + color._offset[0], green + color._offset[1], blue + color._offset[2], + color._tint[3] * input._alpha); +} + +// 006827a0 The shortest signed turn from one angle to another, in degrees. +float angle_difference(float from, float to) +{ + from = angle_wrap(from); + to = angle_wrap(to); + if (std::abs(to - from) > ANGLE_HALF_TURN) + { + if (from < to) return to - (from + ANGLE_FULL_TURN); + to += ANGLE_FULL_TURN; + } + return to - from; +} + +// 0096cb60 Points the laser's path at it. +Entity_Laser::Entity_Laser() +{ + homingLaser.owner = this; +} // 0096ced0 Sorts by its depth, ignoring the sorting layer. int Entity_Laser::GetRenderZ() @@ -26,205 +242,1355 @@ bool Entity_Laser::HandleCollision(Entity*, bool) // 00435f50 Whether it is a ring laser (Tech X and the like). bool Entity_Laser::IsCircleLaser() { - return subtype >= LASER_SUBTYPE_RING_FIRST && subtype <= LASER_SUBTYPE_RING_LAST; + return subtype >= LASER_SUBTYPE_RING_LUDOVICO && subtype <= LASER_SUBTYPE_RING_FOLLOW_PARENT; } -// The rest of Entity_Laser is not reconstructed yet. - -// 0096f590 -void Entity_Laser::Init(int, int, int, uint32_t) -{ - reconstruction_missing("Entity_Laser::Init 0096f590"); -} - -// 00977cc0 -void Entity_Laser::Update() -{ - reconstruction_missing("Entity_Laser::Update 00977cc0"); -} - -// 0097e6f0 -void Entity_Laser::Interpolate() -{ - reconstruction_missing("Entity_Laser::Interpolate 0097e6f0"); -} - -// 009785d0 -void Entity_Laser::Render(const Vector&) -{ - reconstruction_missing("Entity_Laser::Render 009785d0"); -} - -// 0097ca90 -bool Entity_Laser::RenderShadowLayer(const Vector&) -{ - reconstruction_missing("Entity_Laser::RenderShadowLayer 0097ca90"); -} - -// 0097eb50 -void Entity_Laser::PostRender() -{ - reconstruction_missing("Entity_Laser::PostRender 0097eb50"); -} - -// 0097ea30 -void Entity_Laser::Remove() -{ - reconstruction_missing("Entity_Laser::Remove 0097ea30"); -} - -// 0097e800 -void Entity_Laser::ClearReferences() -{ - reconstruction_missing("Entity_Laser::ClearReferences 0097e800"); -} - -// 0096ce30 +// 0096ce30 Whether it is one of the thick beams (Brimstone's and the bosses'). bool Entity_Laser::is_thick_variant() { - reconstruction_missing("Entity_Laser::is_thick_variant 0096ce30"); + switch (variant) + { + case LASER_THICK_RED: + case LASER_SHOOP: + case LASER_GIANT_RED: + case LASER_BRIM_TECH: + case LASER_THICKER_RED: + case LASER_THICK_BROWN: + case LASER_BEAST: + case LASER_THICKER_BRIM_TECH: + case LASER_GIANT_BRIM_TECH: + return true; + default: + return false; + } } -// 0096cf80 -bool Entity_Laser::CanDamageEntity(Entity*) +// The first laser of the chain this one was split from. +Entity_Laser* Entity_Laser::root_laser_get() { - reconstruction_missing("Entity_Laser::CanDamageEntity 0096cf80"); + Entity_Laser* root = this; + while (root->parentLaser) root = static_cast(root->parentLaser.get()); + return root; } -// 0096d3f0 -void Entity_Laser::impact_tear_flag_effects(const Vector&, const Vector&) +// 0096ce70 The hit list the laser shares with the chain it was split from: its first laser's. +std::vector& Entity_Laser::hit_list_get() { - reconstruction_missing("Entity_Laser::impact_tear_flag_effects 0096d3f0"); + return root_laser_get()->hitList; } -// 0096ee00 -ColorMod* Entity_Laser::get_tear_spawn_color(const ColorMod&) +// 0096cf40 Whether the laser is the players': its parent is a player, a familiar or one of their tears or effects, +// or it was spawned by one. +bool Entity_Laser::is_players_laser() { - reconstruction_missing("Entity_Laser::get_tear_spawn_color 0096ee00"); + Entity* owner = parent; + if (owner) + { + bool isShot = owner->type == ENTITY_TEAR || owner->type == ENTITY_EFFECT; + if (isShot && owner->spawnerType == ENTITY_PLAYER) return true; + if (owner->type == ENTITY_PLAYER || owner->type == ENTITY_FAMILIAR) return true; + } + return spawnerType == ENTITY_PLAYER || spawnerType == ENTITY_FAMILIAR; } -// 0096f070 -void Entity_Laser::copy_from_parent(Entity_Laser*, bool) +// 0096cf80 Whether the laser may hurt an entity this frame: a live one that collides and has health (or a familiar +// lasers hurt), not its parent, not of its parent's kind outside a versus match, and not hit yet. The players' +// lasers hurt enemies that are not friendly and the fireplaces, poops and movable TNT. The others hurt players, +// enemies and those familiars. +bool Entity_Laser::CanDamageEntity(Entity* entity) { - reconstruction_missing("Entity_Laser::copy_from_parent 0096f070"); + if (entity->type == ENTITY_SHOPKEEPER) return false; + + Entity* owner = parent; + int parentType = owner ? owner->type : 0; + bool isCharmedParent = owner && owner->HasEntityFlags(FLAG_CHARM); + bool isVersus = g_game->deathmatchManager.is_active(); + bool isDamagedFamiliar = + entity->type == ENTITY_FAMILIAR && + (entity->variant == Entity_Familiar::ISAACS_HEART || entity->variant == Entity_Familiar::PUNCHING_BAG || + entity->variant == Entity_Familiar::LOST_SOUL || entity->variant == Entity_Familiar::MILK || + (entity->variant == Entity_Familiar::WISP && entity->subtype == WISP_DAMAGED_SUBTYPE)); + bool isHittable = + entity != owner && !entity->isDead && entity->entityCollisionClass != ENTCOLL_NONE && entity->maxHitPoints > 0; + bool isOtherKind = (parentType == ENTITY_PLAYER && isVersus) || parentType != entity->type || isCharmedParent; + if (!(isHittable || isDamagedFamiliar) || !isOtherKind) return false; + if (EntityList::HitListContains(hit_list_get(), *entity)) return false; + + bool isPlayers = is_players_laser() && !(parentType == ENTITY_FAMILIAR && isCharmedParent); + bool isEnemy = entity->IsEnemy(); + bool isTarget = isEnemy || (isVersus && entity->type == ENTITY_PLAYER); + if (!isPlayers) return entity->type == ENTITY_PLAYER || isEnemy || isDamagedFamiliar; + + if (isTarget && !entity->HasEntityFlags(FLAG_FRIENDLY)) return true; + bool isBreakable = + entity->type == ENTITY_FIREPLACE || entity->type == ENTITY_MOVABLE_TNT || entity->type == ENTITY_POOP; + return entity->entityCollisionClass != ENTCOLL_NONE && isBreakable; } -// 0096f470 -void Entity_Laser::RotateToAngle(float, float) +// 0096f310 Spawns a laser of a variant at an angle from a position, with its timeout and offset. A source becomes +// its spawner and parent, which it keeps its offset from. +Entity_Laser* Entity_Laser::ShootAngle(const LaserShot& shot) { - reconstruction_missing("Entity_Laser::RotateToAngle 0096f470"); + uint32_t seed = Random(); + Entity* entity = game_spawn({.position = shot.position, + .spawner = shot.source, + .type = ENTITY_LASER, + .variant = shot.variant, + .seed = seed}, + shot.isPoolKept ? POOL_KEEP : POOL_OVERWRITE); + if (!entity) return nullptr; + + Entity_Laser* laser = static_cast(entity); + laser->angleDegrees = shot.angleDegrees; + laser->startAngleDegrees = shot.angleDegrees; + laser->timeout = shot.timeout; + laser->posOffset = shot.posOffset; + if (shot.source) + { + laser->spawnerEntity = shot.source; + laser->parent = shot.source; + laser->parentOffset = vector_sub(laser->pos, shot.source->pos); + } + return laser; } -// 0096f4e0 +// 0096f420 Turns the laser by an angle at a speed after a delay, its timeout lasting the turn when asked. +void Entity_Laser::SetActiveRotation(int delay, float angle, float speed, bool isTimeoutComplete) +{ + isActiveRotating = true; + rotationDelay = (uint32_t)delay; + rotationDegrees = angle; + rotationSpd = speed; + if (isTimeoutComplete) timeout = (int)(uint32_t)(angle / speed) + 1 + delay; +} + +// 0096f470 Turns the laser toward an angle at a speed, the short way round. +void Entity_Laser::RotateToAngle(float angle, float speed) +{ + isActiveRotating = true; + rotationDelay = 0; + rotationDegrees = angle_difference(angleDegrees, angle); + rotationSpd = rotationDegrees < 0 ? -speed : speed; +} + +// Points the beam at an angle, keeping the angle it had. The original's 0096ce90, which the database names +// Entity_NPC::SetAimAngle. +void Entity_Laser::set_aim_angle(float angle) +{ + lastAngleDegrees = angleDegrees; + startAngleDegrees = angle; + angleDegrees = angle; + sprite.rotation = angle - SPRITE_ROTATION_OFFSET; +} + +// 0096f4e0 Forgets the path, and sets it up again for a ring (which ignores the grid) or a line, or a homing one. void Entity_Laser::ClearLaserSamples() { - reconstruction_missing("Entity_Laser::ClearLaserSamples 0096f4e0"); + homingLaser.bezier.clear(); + homingLaser.samples.clear(); + homingLaser.smoothedSamples.clear(); + homingLaser.nonOptimizedSamples.clear(); + homingLaser.isRing = IsCircleLaser(); + if (homingLaser.isRing) entityGridCollisionClass = GRIDCOLL_NONE; + homingLaser.sampleNum = HOMING_LASER_SAMPLES; + homingLaser.reach = homingLaser.isRing ? HOMING_LASER_RING_REACH : HOMING_LASER_REACH; + if (homingType == LASER_HOMING_FREEZE) homingLaser.reach = HOMING_LASER_HOMING_REACH; } -// 0096f880 +// 0096f590 Starts the laser: its sprite on its default animation, and every setting back to a plain beam. +void Entity_Laser::Init(int initType, int initVariant, int initSubType, uint32_t seed) +{ + Entity::Init(initType, initVariant, initSubType, seed); + if (config) + { + sprite.Load(config->anm2Path, GRAPHICS_LOAD); + sprite.Play(sprite.GetDefaultAnimationName()); + } + + isPlayerParams = false; + isDisableInitSound = false; + damageMultiplier = 1; + waitFrames = 0; + parentOffset = {}; + scale = 1; + angleDegrees = 0; + startAngleDegrees = 0; + lastAngleDegrees = 0; + renderDepthOffset = 0; + tearFlags.reset(); + activeTearFlags.reset(); + heldTearFlags.reset(); + multidimensionalLasers = {}; + timeout = 0; + isFirstUpdate = true; + sampleMode = SAMPLE_UNDECIDED; + isSampleLaser = false; + entityGridCollisionClass = GRIDCOLL_WALLS; + laserLength = 0; + curveStrength = 0; + isShrink = false; + isActiveRotating = false; + homingType = 0; + maxDistance = 0; + radius = RING_RADIUS; + isDisableFollowParent = false; + bounceLaser = nullptr; + isMultidimensionalTouched = false; + isPrismTouched = false; + isOneHit = false; + childLaser = nullptr; + prismLasers = {}; + hitList.clear(); + homingLaser.bezier.clear(); + homingLaser.samples.clear(); + homingLaser.smoothedSamples.clear(); + homingLaser.nonOptimizedSamples.clear(); + blackHpDropChance = 0; + impactDistance = INFINITY; + subLaserDistance = INFINITY; + subLaserAngle = 0; + chainedLasers = 0; + lua_engine_get().PostLaserInit(this); +} + +// 0096f880 Plays the sound the beam starts with, unless it is quiet, split from another laser or hidden. A beam's +// sound grows with its scale, and some bosses' beams have their own. void Entity_Laser::PlayInitSound() { - reconstruction_missing("Entity_Laser::PlayInitSound 0096f880"); + if (isDisableInitSound || (parent && parent->type == ENTITY_LASER) || !isVisible) return; + + int spawner = spawnerEntity ? spawnerEntity->type : 0; + bool isSmall = scale < SCALE_SMALL; + switch (variant) + { + case LASER_THICK_RED: + case LASER_LIGHT_RING: + case LASER_BRIM_TECH: + if (!spawnerEntity) return laser_sound_play(SOUND_BLOOD_LASER, {}); + if (spawner == SPAWNER_EYE) return laser_sound_play(SOUND_REDLIGHTNING_ZAP_STRONG, {}); + if (spawner == SPAWNER_MONSTRO_2 || spawner == SPAWNER_MOMS_HEART_LASER) + return laser_sound_play(SOUND_BLOOD_LASER_LARGE, {}); + if (spawner == ENTITY_SATAN) return laser_sound_play(SOUND_SATAN_HAND_LASER, {}); + if (spawner == SPAWNER_FORSAKEN) return laser_sound_play(SOUND_FORSAKEN_LASER, {.loop = SOUND_LOOP}); + if (subtype == LASER_SUBTYPE_LINEAR) + return npc_sound_play(isSmall ? SOUND_BLOOD_LASER_SMALL : SOUND_BLOOD_LASER, 1, 2, 1); + if (subtype == LASER_SUBTYPE_RING_PROJECTILE) + { + npc_sound_play(isSmall ? SOUND_BLOOD_LASER_SMALL : SOUND_BLOOD_LASER, RING_SOUND_VOLUME, 2, 1); + npc_sound_play(isSmall ? SOUND_LASERRING : SOUND_LASERRING_STRONG, 1, 2, 1); + } + return; + case LASER_THIN_RED: + { + float pitch = random_fraction() * ZAP_PITCH_RANGE + ZAP_PITCH_MIN; + bool isRing = subtype == LASER_SUBTYPE_RING_PROJECTILE; + int sound = isRing ? SOUND_LASERRING : SOUND_REDLIGHTNING_ZAP; + float volume = 1; + if (scale < SCALE_SMALL) + { + sound = isRing ? SOUND_LASERRING_WEAK : SOUND_REDLIGHTNING_ZAP_WEAK; + volume = isRing ? RING_VOLUME_WEAK : ZAP_VOLUME_WEAK; + } + else if (scale > SCALE_LARGE) + { + sound = isRing ? SOUND_LASERRING_STRONG : SOUND_REDLIGHTNING_ZAP_STRONG; + volume = ZAP_VOLUME_STRONG; + } + if (spawner == ENTITY_PLAYER || spawner == ENTITY_FAMILIAR) + volume *= OWNER_ZAP_VOLUME; + else if (spawner == SPAWNER_BABY) + volume *= BABY_ZAP_VOLUME; + return npc_sound_play(sound, volume, 1, pitch); + } + case LASER_SHOOP: + return laser_sound_play(SOUND_BLOOD_LASER, {}); + case LASER_LIGHT_BEAM: + return laser_sound_play(SOUND_ANGEL_BEAM, {}); + case LASER_GIANT_RED: + case LASER_GIANT_BRIM_TECH: + return laser_sound_play(SOUND_MEGA_BLAST_START, {}); + case LASER_ELECTRIC: + return npc_sound_play(SOUND_REDLIGHTNING_ZAP_WEAK, ELECTRIC_VOLUME, 2, + random_fraction() * ELECTRIC_PITCH_RANGE + ELECTRIC_PITCH_MIN); + case LASER_THICKER_RED: + case LASER_THICKER_BRIM_TECH: + if (subtype == LASER_SUBTYPE_RING_PROJECTILE) + { + laser_sound_play(SOUND_BLOOD_LASER_LARGER, {.volume = RING_SOUND_VOLUME}); + return laser_sound_play(SOUND_LASERRING_STRONG, {}); + } + if (subtype != LASER_SUBTYPE_RING_LUDOVICO) laser_sound_play(SOUND_BLOOD_LASER_LARGER, {}); + return; + case LASER_THICK_BROWN: + return laser_sound_play(SOUND_POOP_LASER, {}); + default: + return; + } } -// 0096fc70 -Vector Entity_Laser::calc_end_point(const Vector&, const Vector&) -{ - reconstruction_missing("Entity_Laser::calc_end_point 0096fc70"); -} - -// 009704a0 -void Entity_Laser::update_first_frame() -{ - reconstruction_missing("Entity_Laser::update_first_frame 009704a0"); -} - -// 00970cb0 -void Entity_Laser::find_nearest_grid_hit(int, const Vector&) -{ - reconstruction_missing("Entity_Laser::find_nearest_grid_hit 00970cb0"); -} - -// 00971590 -uint8_t Entity_Laser::damage_grid_entity(int, int, const Vector&) -{ - reconstruction_missing("Entity_Laser::damage_grid_entity 00971590"); -} - -// 00971810 -void Entity_Laser::update_line_hits() -{ - reconstruction_missing("Entity_Laser::update_line_hits 00971810"); -} - -// 009737b0 -void Entity_Laser::update_endpoint_and_hits() -{ - reconstruction_missing("Entity_Laser::update_endpoint_and_hits 009737b0"); -} - -// 00973a50 -void Entity_Laser::refresh_tear_params() -{ - reconstruction_missing("Entity_Laser::refresh_tear_params 00973a50"); -} - -// 00973c60 -void Entity_Laser::update_laser() -{ - reconstruction_missing("Entity_Laser::update_laser 00973c60"); -} - -// 0097baa0 -void Entity_Laser::UpdateHits() -{ - reconstruction_missing("Entity_Laser::UpdateHits 0097baa0"); -} - -// 0097e3b0 -void* Entity_Laser::GetSamples() -{ - reconstruction_missing("Entity_Laser::GetSamples 0097e3b0"); -} - -// 0097e3c0 -void Entity_Laser::damage_entity(Entity*) -{ - reconstruction_missing("Entity_Laser::damage_entity 0097e3c0"); -} - -// 0097e6e0 -void* Entity_Laser::GetNonOptimizedSamples() -{ - reconstruction_missing("Entity_Laser::GetNonOptimizedSamples 0097e6e0"); -} - -// 0097f820 -void Entity_Laser::spawn_impact_effect(int) -{ - reconstruction_missing("Entity_Laser::spawn_impact_effect 0097f820"); -} - -// 0097fc10 +// 0097fc10 Sizes the sprite and collision to the laser's scale. A thin beam picks its thickness animation for the +// scale and draws it at the remaining part, starting on a frame from its seed. void Entity_Laser::ResetSpriteScale() { - reconstruction_missing("Entity_Laser::ResetSpriteScale 0097fc10"); + size = scale * config->collisionRadius; + if (variant != LASER_THIN_RED) + { + sprite.scale = vector_make(scale, scale); + return; + } + + int thickness = 0; + while (thickness < 3 && scale >= THIN_SCALE_THRESHOLDS[thickness]) thickness++; + std::string animation = "Laser" + std::to_string(thickness); + float divisor = THIN_SCALE_DIVISORS[thickness]; + sprite.scale = vector_make(scale / divisor, scale / divisor); + if (sprite.animState.animData && sprite.animState.isPlaying && sprite.GetAnimation() == animation) return; + + sprite.Play(animation); + uint32_t seed = initSeed; + if (seed == 0) + { + KAGE_LogMessage(LOG_ASSERT, (uint8_t*)"RNG Seed is zero!\n"); + return; + } + seed ^= seed >> 4; + seed ^= seed << 3; + seed ^= seed >> 27; + int length = sprite.animState.GetAnimationLength(); + if (sprite.animState.animData) sprite.animState.SetFrameFloat((float)(length == 0 ? 0 : seed % (uint32_t)length)); } -// 0097fe50 -void Entity_Laser::set_scale(float) +// 0097fe50 Sets the laser's scale and sizes it to it. +void Entity_Laser::set_scale(float newScale) { - reconstruction_missing("Entity_Laser::set_scale 0097fe50"); + scale = newScale; + ResetSpriteScale(); } -// 0097fe60 -void Entity_Laser::update_sample_points(char) +// 0096ee00 The color a tear the laser fires takes: half its color's brightness as colorize and offset, from its +// own color for the shoop and electric beams, a red tint of it for a thin beam, a reddened one otherwise. +ColorMod Entity_Laser::CalculateTearColor() { - reconstruction_missing("Entity_Laser::update_sample_points 0097fe60"); + const ColorMod& color = sprite.color; + float red = 0; + float green = 0; + float blue = 0; + float alpha = 0; + if (variant == LASER_SHOOP || variant == LASER_ELECTRIC) + { + red = color._tint[0] * TEAR_TINT_RED; + green = color._tint[1] * TEAR_TINT_GREEN; + blue = color._tint[2]; + alpha = color._tint[3]; + if (color._colorize[3] != 0) + { + float luminance = red * LUMINANCE_RED + green * LUMINANCE_GREEN + blue * LUMINANCE_BLUE; + red += (luminance * color._colorize[0] - red) * color._colorize[3]; + green += (luminance * color._colorize[1] - green) * color._colorize[3]; + blue += (luminance * color._colorize[2] - blue) * color._colorize[3]; + } + red += color._offset[0]; + green += color._offset[1]; + blue += color._offset[2]; + } + else + { + ColorMod tinted = color; + KColor multiplier = kcolor_rgba(TEAR_TINT_RED, TEAR_TINT_GREEN, 1, 1); + if (variant == LASER_THIN_RED) + multiplier = kcolor_rgba(1, 0, 0, 1); + else + color_multiply(tinted, {{1, 0, 0, 1}, {0, 0, 0, 0}, {0, 0, 0}}); + KColor result = color_apply(tinted, multiplier); + red = result._red; + green = result._green; + blue = result._blue; + alpha = result._alpha; + } + + float halfRed = red * TEAR_COLOR_HALF; + float halfGreen = green * TEAR_COLOR_HALF; + float halfBlue = blue * TEAR_COLOR_HALF; + return {{1, 1, 1, alpha}, {halfRed, halfGreen, halfBlue, 1}, {halfRed, halfGreen, halfBlue}}; } -// 0099efc0 -void Entity_Laser::update_wiggle_path(void*, float, float) +// 0096f070 Takes a parent laser's look, damage, reach and flags (but its splitting and turning ones), and its spawn +// data (seed, homing, spawner, scale and chain) when asked. Its timeout comes along unless the laser hits once. +void Entity_Laser::copy_from_parent(Entity_Laser& source, LaserCopy copy) +{ + if (copy == LASER_COPY_SPAWN) + { + dropRNG = DROP_RNG_SAVED; + dropRNG._seed = source.dropRNG._seed; + homingType = source.homingType; + spawnerType = source.spawnerType; + spawnerVariant = source.spawnerVariant; + spawnerEntity = source.spawnerEntity; + isOneHit = source.isOneHit; + isMultidimensionalTouched = source.isMultidimensionalTouched; + isPrismTouched = source.isPrismTouched; + scale = source.scale; + ResetSpriteScale(); + chainedLasers = source.chainedLasers; + } + + SetColor(source.sprite.color, -1, COLOR_PRIORITY_DEFAULT, false, true); + tearFlags = source.activeTearFlags; + for (int bit : {TEAR_POP, TEAR_ABSORB, TEAR_SPLIT, TEAR_TURN_HORIZONTAL}) tearFlags.reset((size_t)bit); + SetCollisionDamage(source.collisionDamage); + blackHpDropChance = source.blackHpDropChance; + maxDistance = source.maxDistance; + isVisible = source.isVisible; + renderDepthOffset = source.renderDepthOffset; + entityGridCollisionClass = source.entityGridCollisionClass; + entityCollisionClass = source.entityCollisionClass; + mass = source.mass; + if (copy == LASER_COPY_SPAWN || !isOneHit) + { + timeout = source.timeout; + isShrink = source.isShrink; + } +} + +// 0096fd60 Where a beam from a start along a direction ends: 1200 away, cut by the room's edge (pushed out by a margin +// and the beam's offset, none for an infinite one) and the missing corner of an L-shaped room. In Challenge #30 an +// enemy's beam also stops at the nearest player within the margin of its line. +Vector Entity_Laser::CalculateEndPoint(const Vector& start, const Vector& direction, const Vector& positionOffset, + Entity* parent, float margin) +{ + Room& room = *g_game->room; + float left = room.topLeftPos.x - positionOffset.x - margin; + float top = room.topLeftPos.y - positionOffset.y - margin; + float right = room.bottomRightPos.x - positionOffset.x + margin; + float bottom = room.bottomRightPos.y - positionOffset.y + margin; + Vector end = vector_add(start, vector_scale(direction, BEAM_REACH)); + + bool isPlayersParent = parent && (parent->type == ENTITY_PLAYER || parent->type == ENTITY_FAMILIAR); + if (g_game->challenge == CHALLENGE_PONG && !isPlayersParent) + { + float nearest = BEAM_REACH; + for (Entity_Player* player : g_game->playerManager.playerList) + { + Vector offset = vector_sub(player->pos, start); + float along = vector_dot(offset, direction); + float across = offset.x * direction.y - offset.y * direction.x; + if (std::abs(across) >= margin || along <= 0 || along >= nearest) continue; + + end = vector_add(start, vector_scale(direction, along)); + nearest = along; + } + } + if (!std::isfinite(margin)) return end; + + // Shortens the beam so it stops at a boundary it crosses on one axis. + Vector beam = vector_sub(end, start); + auto clip = [&beam](float limit, float startValue, bool isX) { + float reach = limit - startValue; + float projected = (isX ? beam.x : beam.y) * reach; + if (reach * reach <= projected) beam = vector_scale(beam, reach * reach / projected); + }; + if (left < start.x) clip(left, start.x, true); + if (start.x < right) clip(right, start.x, true); + if (top < start.y) clip(top, start.y, false); + if (start.y < bottom) clip(bottom, start.y, false); + end = vector_add(start, beam); + + int shape = room.GetRoomShape(); + if (shape < ROOMSHAPE_LTL || shape > ROOMSHAPE_LBR) return end; + + Vector back = vector_sub(start, end); + auto cut = [&back](float limit, float endValue, bool isX) { + float reach = limit - endValue; + float projected = (isX ? back.x : back.y) * reach; + if (reach * reach <= projected) back = vector_scale(back, reach * reach / projected); + }; + switch (shape) + { + case ROOMSHAPE_LTL: + if (end.x < left + L_ROOM_ARM_WIDTH && end.y < top + L_ROOM_ARM_HEIGHT) + { + cut(left + L_ROOM_ARM_WIDTH, end.x, true); + cut(top + L_ROOM_ARM_HEIGHT, end.y, false); + } + break; + case ROOMSHAPE_LTR: + if (end.x > right - L_ROOM_ARM_WIDTH && end.y < top + L_ROOM_ARM_HEIGHT) + { + cut(right - L_ROOM_ARM_WIDTH, end.x, true); + cut(top + L_ROOM_ARM_HEIGHT, end.y, false); + } + break; + case ROOMSHAPE_LBL: + if (end.x < left + L_ROOM_ARM_WIDTH && end.y > bottom - L_ROOM_ARM_HEIGHT) + { + cut(left + L_ROOM_ARM_WIDTH, end.x, true); + cut(bottom - L_ROOM_ARM_HEIGHT, end.y, false); + } + break; + default: + if (end.x > right - L_ROOM_ARM_WIDTH && end.y > bottom - L_ROOM_ARM_HEIGHT) + { + cut(right - L_ROOM_ARM_WIDTH, end.x, true); + cut(bottom - L_ROOM_ARM_HEIGHT, end.y, false); + } + break; + } + Vector cutEnd = vector_add(back, end); + return vector_length_squared(vector_sub(start, cutEnd)) > 0.01f ? cutEnd : end; +} + +// 0096fc70 Where the laser's beam from a start ends, past the room's edge by 20, by 140 for Continuum, and without an +// edge in a room whose descriptor bit 15 is set or for a light beam (100 under Eye of the Occult). +Vector Entity_Laser::calc_end_point(const Vector& start, const Vector& direction) +{ + float margin = tearFlags[TEAR_CONTINUUM] ? BEAM_MARGIN_CONTINUUM : BEAM_MARGIN; + bool isBoundless = (g_game->room->descriptor->flags & ROOM_DESCRIPTOR_FLAG_NO_WALLS) || variant == LASER_LIGHT_BEAM; + if (isBoundless) margin = tearFlags[TEAR_OCCULT] ? BEAM_MARGIN_OCCULT : INFINITY; + return CalculateEndPoint(start, direction, posOffset, parent, margin); +} + +// 0096d160 Where along the path a distance falls, and the path's direction there: at its end for a farther or +// infinite distance, at its start for none. Without a path, the laser's position along its angle. Whether the +// distance fell inside the path. +// The original measures the point from the last sample before it with the sub laser distance rather than the +// distance asked, which callers always pass as that. That is kept. +bool Entity_Laser::get_segment_start_dir(float distance, Vector& outPosition, Vector& outDirection) +{ + std::vector& samples = homingLaser.samples; + if (samples.size() < 2) + { + outPosition = pos; + outDirection = vector_from_angle(angleDegrees); + return false; + } + if (distance <= 0) + { + outPosition = samples[0]; + outDirection = vector_normalized(vector_sub(samples[1], samples[0])); + return false; + } + + if (std::isfinite(distance)) + { + float travelled = 0; + for (size_t i = 0; i + 1 < samples.size(); i++) + { + Vector segment = vector_sub(samples[i + 1], samples[i]); + float length = vector_length(segment); + if (distance < length + travelled) + { + float along = subLaserDistance - travelled; + outPosition = vector_add(samples[i], vector_scale(segment, along / length)); + outDirection = vector_scale(segment, 1 / length); + return true; + } + travelled += length; + } + } + outPosition = samples.back(); + outDirection = vector_normalized(vector_sub(samples.back(), samples[samples.size() - 2])); + return false; +} + +// 00973a50 Every other tick (and on the first), a laser fired with the player's stats takes the player's laser hit +// params again: its tear flags (but the waiting and held ones, and explosions for a lasting beam) and damage. +void Entity_Laser::refresh_tear_params() +{ + if (!isPlayerParams || isOneHit || isInterpolating) return; + if (!isFirstUpdate && GetIntervalTicks(2, 0) == 0) return; + + Entity* spawner = spawnerEntity; + Entity_Player* player = laser_owner_player(spawner); + if (!player) return; + + int displacement = (int)(Random() & 1) * 2 - 1; + TearParams params = player->GetTearHitParams(WEAPON_LASER, damageMultiplier, displacement, spawner); + tearFlags = params.tearFlags; + tearFlags.reset(TEAR_WAIT); + if (timeout < 0) tearFlags.reset(TEAR_EXPLOSIVE); + tearFlags &= ~heldTearFlags; + float versusScale = + g_game->deathmatchManager.is_active() && subtype == LASER_SUBTYPE_RING_PROJECTILE ? VERSUS_RING_DAMAGE : 1; + collisionDamage = params.tearDamage * versusScale; +} + +// 0097f820 Puts the right impact effect at the beam's end: none, the thin beam's, or the thick beams' of their kind +// (Dogma's static one, the Cage's Vis's). A different one in place is removed first, and the new one comes the next +// time. +void Entity_Laser::spawn_impact_effect() +{ + if (!isExists) return; + + int impact = -1; + if (variant == LASER_THIN_RED && subtype != LASER_SUBTYPE_NO_IMPACT) + impact = subtype != LASER_SUBTYPE_LINEAR ? IMPACT_SUBTYPE_RING : IMPACT_SUBTYPE_THIN; + else if (is_thick_variant() && spawnerType != SPAWNER_MEGA_SATAN && subtype == LASER_SUBTYPE_LINEAR) + { + Entity* owner = parent; + bool isCageVis = owner && ((owner->type == SPAWNER_VIS && owner->spawnerType == SPAWNER_CAGE) || + (owner->type == SPAWNER_PEEP && owner->variant == 1 && owner->subtype == 1)); + impact = IMPACT_SUBTYPE_THICK; + if (variant == LASER_SHOOP) + impact = IMPACT_SUBTYPE_SHOOP; + else if (isCageVis) + impact = IMPACT_SUBTYPE_CAGE; + else if (variant == LASER_THICKER_RED || variant == LASER_GIANT_RED || variant == LASER_THICKER_BRIM_TECH || + variant == LASER_GIANT_BRIM_TECH) + impact = IMPACT_SUBTYPE_GIANT; + else if (variant == LASER_THICK_BROWN) + impact = IMPACT_SUBTYPE_BROWN; + } + + if (child) + { + if (child->subtype == impact) return; + child->Remove(); + if (child) return; + } + if (impact < 0) return; + + Entity* effect = g_game->Spawn({.position = pos, + .spawner = this, + .subType = impact, + .type = ENTITY_EFFECT, + .variant = EFFECT_LASER_IMPACT, + .seed = Random()}); + child = effect; + effect->parent = this; + if (impact == IMPACT_SUBTYPE_THIN || impact == IMPACT_SUBTYPE_RING) + { + if (subtype == LASER_SUBTYPE_RING_FOLLOW_PARENT) effect->renderDepthOffset = IMPACT_DEPTH_FOLLOW; + } + else + { + if (impact == IMPACT_SUBTYPE_THICK && spawnerType == SPAWNER_DOGMA) + { + effect->sprite.Load(STATIC_IMPACT_ANM2, GRAPHICS_LOAD); + effect->sprite.Play(effect->sprite.GetDefaultAnimationName()); + effect->sprite.bitflags |= ANIM_RENDER_STATIC; + } + effect->renderDepthOffset = renderDepthOffset + IMPACT_DEPTH; + } + effect->SetColor(sprite.color, -1, COLOR_PRIORITY_DEFAULT, false, true); + effect->isVisible = isVisible; + effect->Update(); +} + +// 0097fe60 Keeps the impact effect at the beam's end, turned along it and colored like the laser it ends (its bounce +// when it bounced). A thick beam's grows with the laser's width and hides when it is gone. At a bounce below, it +// sits at the bounce. +void Entity_Laser::update_impact_effect(bool isHidden) +{ + Entity* effect = child; + if (!effect || effect->type != ENTITY_EFFECT) return; + + effect->isVisible = isVisible && !isHidden; + Entity* colorSource = bounceLaser ? bounceLaser.get() : this; + effect->SetColor(colorSource->sprite.color, -1, COLOR_PRIORITY_DEFAULT, false, true); + + std::vector& samples = homingLaser.samples; + bool isPath = samples.size() >= 2; + Vector back = isPath ? vector_normalized(vector_sub(samples[samples.size() - 2], samples.back())) : Vector{}; + Vector end = isPath ? samples.back() : vector_add(pos, vector_scale(vector_from_angle(angleDegrees), laserLength)); + float rotation = 0; + if (effect->subtype == IMPACT_SUBTYPE_THIN) + rotation = + isPath ? angle_wrap(vector_angle(back) + SPRITE_ROTATION_OFFSET) : angleDegrees - SPRITE_ROTATION_OFFSET; + else + { + float scaleX = sprite.scale.x; + float scaleY = sprite.scale.y; + if (scaleX <= IMPACT_SCALE_MIN) + effect->isVisible = false; + else + { + scaleX = scaleX * IMPACT_SCALE_KEPT + IMPACT_SCALE_BASE; + bool isGiant = variant == LASER_GIANT_RED || variant == LASER_GIANT_BRIM_TECH; + if (isGiant && effect->subtype == IMPACT_SUBTYPE_GIANT_END) + scaleY = scaleX; + else if (isGiant) + scaleX *= IMPACT_SCALE_GIANT; + effect->isVisible = isVisible; + effect->sprite.scale = vector_make(scaleX, scaleY); + } + + Entity* bounce = bounceLaser; + if (bounce && pos.y < bounce->pos.y) + { + effect->pos = bounce->pos; + effect->posOffset = posOffset; + effect->renderDepthOffset = bounce->renderDepthOffset + IMPACT_DEPTH; + effect->sprite.rotation = isPath ? angle_wrap(vector_angle(back) - SPRITE_ROTATION_OFFSET) + : angleDegrees + SPRITE_ROTATION_OFFSET; + return; + } + rotation = + isPath ? angle_wrap(vector_angle(back) - SPRITE_ROTATION_OFFSET) : angleDegrees + SPRITE_ROTATION_OFFSET; + } + effect->pos = end; + effect->posOffset = posOffset; + effect->sprite.rotation = rotation; + effect->renderDepthOffset = renderDepthOffset + IMPACT_DEPTH + pos.y - effect->pos.y; +} + +// Anti-Gravity: the beam waits as a swirl (or a dot for a thin one) of its size until the swirl lets it go, taking +// its flags off it meanwhile. +void Entity_Laser::tear_wait_start() +{ + tearFlags.reset(TEAR_WAIT); + heldTearFlags.set(TEAR_WAIT); + float effectScale = scale; + if (variant == LASER_THICKER_RED || variant == LASER_THICKER_BRIM_TECH) + effectScale *= WAIT_SCALE_THICKER; + else if (variant == LASER_GIANT_RED || variant == LASER_GIANT_BRIM_TECH) + effectScale *= WAIT_SCALE_GIANT; + else if (variant == LASER_BEAST) + effectScale *= WAIT_SCALE_BEAST; + + int effectVariant = is_thick_variant() ? EFFECT_BRIMSTONE_SWIRL : EFFECT_TECH_DOT; + Entity* effect = g_game->Spawn( + {.position = pos, .spawner = spawnerEntity, .type = ENTITY_EFFECT, .variant = effectVariant, .seed = initSeed}); + tearWaitEffect = effect; + Entity_Effect& swirl = *static_cast(tearWaitEffect.get()); + swirl.child = this; + swirl.posOffset = posOffset; + swirl.sprite.scale = vector_make(effectScale, effectScale); + swirl.SetColor(color, -1, COLOR_PRIORITY_DEFAULT, false, true); + swirl.SetCollisionDamage(collisionDamage); + for (size_t bit = 0; bit < tearFlags.size(); bit++) + if (tearFlags[bit]) swirl.varData[bit / 32] |= 1u << (bit % 32); + if (parent && parent->type == ENTITY_LASER) swirl.isVisible = false; + swirl.Update(); + + parent = &swirl; + waitFrames = LASER_WAIT_FRAMES; + isVisible = false; + isDisableFollowParent = true; +} + +// Rainbow and Continuum beams cycle colors: a hue round every 30 frames, or a pink pulse every 8 steps of two frames. +void Entity_Laser::color_cycle_update() +{ + Entity_Laser* root = root_laser_get(); + ColorMod cycle = COLOR_DEFAULT; + if (root->tearFlags[TEAR_RAINBOW]) + cycle = colorize_from_hue((float)(g_game->frameCount % (int)RAINBOW_FRAMES) * ANGLE_FULL_TURN / RAINBOW_FRAMES, + RAINBOW_SATURATION, 1, RAINBOW_STRENGTH); + else if (root->tearFlags[TEAR_CONTINUUM]) + { + int phase = (g_game->frameCount - spawnFrame) / 2 % CONTINUUM_PHASES; + int step = phase <= CONTINUUM_PHASES / 2 ? phase : CONTINUUM_PHASES - phase; + cycle._colorize[0] = CONTINUUM_COLORIZE; + cycle._colorize[1] = (float)step * CONTINUUM_GREEN_STEP; + cycle._colorize[2] = CONTINUUM_COLORIZE; + cycle._colorize[3] = 1; + } + else + return; + + SetColor(cycle, -1, COLOR_PRIORITY_DEFAULT, false, true); + if (child) child->SetColor(cycle, -1, COLOR_PRIORITY_DEFAULT, false, true); + if (tearWaitEffect) tearWaitEffect->SetColor(cycle, -1, COLOR_PRIORITY_DEFAULT, false, true); +} + +// 00977cc0 Waits out Anti-Gravity, cycles its colors, then runs the ring's or the beam's update (and The Forsaken's +// loop). Its first update sets it up instead: a static beam for Dogma, the Cage's Vis's own sprite. +void Entity_Laser::Update() +{ + if (tearFlags[TEAR_WAIT] && !IsCircleLaser() && timeout > 0) tear_wait_start(); + Entity* swirl = tearWaitEffect; + if (swirl && static_cast(swirl)->state == 0 && waitFrames < LASER_WAIT_FRAMES) + waitFrames = LASER_WAIT_FRAMES; + color_cycle_update(); + + if (waitFrames > 0) + { + if (--waitFrames > 0) return; + isVisible = true; + } + + if (!isFirstUpdate) + { + if (IsCircleLaser()) + UpdateHits(); + else + update_laser(); + if (variant == LASER_THICK_RED && spawnerEntity && spawnerEntity->type == SPAWNER_FORSAKEN) + { + if (isDead) + g_manager->sfxManager.Stop(SOUND_FORSAKEN_LASER); + else if (!g_manager->sfxManager.IsPlaying(SOUND_FORSAKEN_LASER)) + laser_sound_play(SOUND_FORSAKEN_LASER, {.loop = SOUND_LOOP}); + } + Entity::Update(); + lua_engine_get().PostLaserUpdate(this); + return; + } + + Entity* owner = parent; + bool isCageVis = spawnerType == SPAWNER_VIS && owner && owner->spawnerType == SPAWNER_CAGE; + bool isCagePeep = spawnerType == SPAWNER_PEEP && owner && owner->type == SPAWNER_PEEP && owner->variant == 1 && + owner->subtype == 1; + if (isCageVis || isCagePeep) + { + sprite.Load(CAGE_VIS_LASER_ANM2, GRAPHICS_LOAD); + sprite.Play(sprite.GetDefaultAnimationName()); + } + else if (spawnerType == SPAWNER_DOGMA && variant == LASER_THICK_RED) + { + sprite.Load(STATIC_LASER_ANM2, GRAPHICS_LOAD); + sprite.Play(sprite.GetDefaultAnimationName()); + sprite.bitflags |= ANIM_RENDER_STATIC; + } + update_first_frame(); + isFirstUpdate = false; +} + +// Whether a laser's parent makes it follow a sampled path: the player's beams and a few familiars' and bosses', and +// any turning, ring or Eye of the Occult beam. The tractor beam never does. +static bool is_path_laser(Entity_Laser& laser) +{ + Entity* owner = laser.parent; + if (!owner) return false; + + int type = owner->type; + bool isPathParent = + type == ENTITY_PLAYER || laser.spawnerType == ENTITY_PLAYER || type == SPAWNER_PIN || + (type == ENTITY_EFFECT && owner->variant == EFFECT_SAMPLE_PARENT) || type == SPAWNER_PATH_KEEPER_1 || + type == SPAWNER_PATH_KEEPER_2 || type == SPAWNER_PATH_KEEPER_3 || + (type == SPAWNER_RING_KEEPER && owner->subtype == 2) || + (type == ENTITY_FAMILIAR && (owner->variant == Entity_Familiar::INCUBUS || + owner->variant == Entity_Familiar::SPRINKLER || laser.tearFlags[TEAR_HOMING])); + bool isShaped = laser.isActiveRotating || laser.IsCircleLaser() || laser.tearFlags[TEAR_OCCULT]; + return (isPathParent || isShaped) && laser.variant != LASER_TRACTOR_BEAM; +} + +// 009704a0 The laser's first frame: its sound, flip and size, its impact effect, and whether it follows a path. A +// straight beam finds its end (through grid entities for a ground beam) within its reach and is drawn turned along +// its angle. A pride beam is a fixed 300 long. +void Entity_Laser::update_first_frame() +{ + PlayInitSound(); + if (variant == LASER_PRIDE) + { + sprite.rotation = angleDegrees; + laserLength = PRIDE_LENGTH; + endPoint = vector_add(vector_add(pos, posOffset), vector_scale(vector_from_angle(angleDegrees), PRIDE_LENGTH)); + sampleMode = SAMPLE_STRAIGHT; + isSampleLaser = false; + return; + } + + Vector direction = vector_from_angle(angleDegrees); + if (std::abs(direction.x) < AXIS_SNAP) direction.x = 0; + if (std::abs(direction.y) < AXIS_SNAP) direction.y = 0; + sprite.isFlipX = (initSeed >> 8) & 1; + ResetSpriteScale(); + spawn_impact_effect(); + + if (sampleMode == SAMPLE_UNDECIDED) sampleMode = is_path_laser(*this) ? SAMPLE_PATH : SAMPLE_STRAIGHT; + isSampleLaser = sampleMode == SAMPLE_PATH; + if (isSampleLaser) + { + ClearLaserSamples(); + if (IsCircleLaser()) return UpdateHits(); + return update_laser(); + } + + Vector start = vector_add(pos, posOffset); + if (entityGridCollisionClass == GRIDCOLL_NOPITS) + { + Vector from = vector_sub(start, vector_scale(direction, BEAM_BACKSTEP)); + LineCheck check = + room_line_check(from, vector_add(start, vector_scale(direction, BEAM_FAR)), GRIDCOLL_NOPITS, true); + endPoint = check.isClear ? vector_add(calc_end_point(start, direction), posOffset) : check.hit; + } + else if (entityGridCollisionClass == GRIDCOLL_WALLS) + endPoint = vector_add(calc_end_point(start, direction), posOffset); + else + endPoint = vector_add(start, vector_scale(direction, BEAM_UNBLOCKED)); + + if (maxDistance > 0 && vector_length_squared(vector_sub(start, endPoint)) > maxDistance * maxDistance) + endPoint = vector_add(start, vector_resized(vector_sub(endPoint, start), maxDistance)); + laserLength = vector_length(vector_sub(endPoint, start)); + if (variant == LASER_GIANT_RED || variant == LASER_GIANT_BRIM_TECH) + laserLength = spawnerType == SPAWNER_PATH_KEEPER_3 ? std::max(BEAM_GIANT_MINIMUM, laserLength) + : laserLength + BEAM_GIANT_EXTRA; + sprite.rotation = angleDegrees - SPRITE_ROTATION_OFFSET; + update_laser(); +} + +// 00973c60 The beam's frame: it takes the player's params again, clears its hits every other tick, follows its +// parent, shakes the screen for the big beams, turns, finds its end (a sampled path for the path lasers), hits what +// it crosses, and shrinks or dies at its timeout. +void Entity_Laser::update_laser() +{ + refresh_tear_params(); + bool isFirst = isFirstUpdate; + if (isFirst || !isOneHit) activeTearFlags = tearFlags; + + bool isHitFrame = + variant != LASER_TRACTOR_BEAM && !isInterpolating && !isDead && (isFirst || GetIntervalTicks(2, 0) != 0); + if (isHitFrame && !parentLaser && !isOneHit) hitList.clear(); + + Entity* owner = parent; + if (owner && !isDisableFollowParent) + { + Vector followed = owner->pos; + if (owner->type == ENTITY_PLAYER) + followed = vector_add(vector_add(followed, parentOffset), owner->ToPlayer()->tearsOffset); + else if (spawnerType != ENTITY_PLAYER) + followed = vector_add(followed, parentOffset); + pos = followed; + } + + if (!isInterpolating && timeout != 0) + { + bool isThickerStart = (variant == LASER_THICKER_RED || variant == LASER_THICKER_BRIM_TECH) && + g_game->frameCount - spawnFrame == 1; + if (variant == LASER_GIANT_RED || variant == LASER_GIANT_BRIM_TECH) + game_shake_screen(SHAKE_GIANT); + else if (isThickerStart || variant == LASER_BEAST) + game_shake_screen(SHAKE_STRONG); + } + + if (isActiveRotating) + { + if (rotationDelay != 0) + rotationDelay--; + else + { + float step = rotationSpd * ROTATION_STEP_SCALE; + float turn = rotationDegrees >= 0 ? std::min(rotationDegrees, step) : std::max(rotationDegrees, step); + if (rotationDegrees != 0) + { + angleDegrees += turn; + rotationDegrees -= turn; + sprite.rotation = angle_wrap(angleDegrees - SPRITE_ROTATION_OFFSET); + } + if (rotationDegrees == 0 || (rotationDegrees > 0) != (turn > 0)) isActiveRotating = false; + } + } + + bool isSamplesRebuilt = false; + bool isRedirected = false; + bool isCut = false; + if (!isSampleLaser) + straight_update(isRedirected); + else if ((homingType != LASER_HOMING_FREEZE && !isOneHit) || isFirstUpdate) + { + isSamplesRebuilt = true; + path_update(isRedirected, isCut); + } + + death_update(); + if (isSamplesRebuilt) homingLaser.remove_collinear_samples(0.001f); + if (isHitFrame) update_endpoint_and_hits(); + if (isSampleLaser && isExists) + { + ends_update(isSamplesRebuilt, isHitFrame, isRedirected, isCut); + chain_fire(); + } + + if (timeout > 0 && !isInterpolating && --timeout < 1) + { + bool isGiant = variant == LASER_GIANT_RED || variant == LASER_GIANT_BRIM_TECH; + if (isGiant && !isShrink && !isDead) npc_sound_play(SOUND_MEGA_BLAST_END, 1, 2, 1); + bool isFading = is_thick_variant() && variant != LASER_BEAST && (!isGiant || spawnerType == ENTITY_PLAYER); + if (isFading) + { + isShrink = true; + timeout = 0; + } + else + isDead = true; + } + lastAngleDegrees = angleDegrees; +} + +// A straight beam's end: along its angle to the grid or the room's edge within its reach. A beam not the players' +// bounces off a mirror it meets. +void Entity_Laser::straight_update(bool& isRedirected) +{ + isGridHit = false; + bool isDrawnStraight = is_thick_variant() || variant == LASER_THIN_RED || variant == LASER_ELECTRIC || + variant == LASER_LIGHT_BEAM || variant == LASER_TRACTOR_BEAM || variant == LASER_LIGHT_RING; + if (!isDrawnStraight) return; + + Vector start = vector_add(pos, posOffset); + Vector direction = vector_from_angle(angleDegrees); + if (entityGridCollisionClass == GRIDCOLL_NOPITS) + endPoint = room_laser_target_get(vector_sub(start, vector_scale(direction, BEAM_BACKSTEP)), direction); + else if (entityGridCollisionClass == GRIDCOLL_WALLS) + endPoint = vector_add(calc_end_point(pos, direction), posOffset); + else + endPoint = vector_add(start, vector_scale(direction, BEAM_UNBLOCKED)); + if (maxDistance > 0 && vector_length_squared(vector_sub(endPoint, start)) > maxDistance * maxDistance) + endPoint = vector_add(start, vector_resized(vector_sub(endPoint, start), maxDistance)); + + bool isGiantKeeper = + (variant == LASER_GIANT_RED || variant == LASER_GIANT_BRIM_TECH) && spawnerType == SPAWNER_MEGA_SATAN; + if (isGiantKeeper || variant == LASER_BEAST) + endPoint = vector_add(endPoint, vector_resized(vector_sub(endPoint, start), BEAM_GIANT_EXTRA)); + + if (spawnerType != ENTITY_PLAYER && spawnerType != ENTITY_FAMILIAR) + { + if (!entity_query(ENTITY_EFFECT, EFFECT_LASER_MIRROR).empty()) + reconstruction_missing("Entity_Laser::update_laser 00973c60: a beam off a mirror"); + if (bounceLaser) bounceLaser->Remove(); + } + laserLength = vector_length(vector_sub(endPoint, start)); + update_impact_effect(isRedirected); +} + +// A path laser's samples: from the tip of its start sprite to its end, along a straight path (homing and shaped by +// its tear flags), cut by the grid, then split by Multidimensional Baby and Angelic Prism, bounced by a mirror, +// wrapped by Continuum, or bounced by Rubber Cement. +void Entity_Laser::path_update(bool& isRedirected, bool& isCut) +{ + isGridHit = false; + bool isAimChanged = angleDegrees != lastAngleDegrees && !is_thick_variant() && variant != LASER_LIGHT_BEAM; + if (isAimChanged) + { + homingLaser.bezier.clear(); + homingLaser.samples.clear(); + homingLaser.smoothedSamples.clear(); + homingLaser.nonOptimizedSamples.clear(); + } + + Vector direction = + vector_make(std::cos(angleDegrees * DEGREES_TO_RADIANS), std::sin(angleDegrees * DEGREES_TO_RADIANS)); + Vector tip{}; + const AnimationFrame* tipFrame = sprite.layerStates.size() > 1 ? sprite.animState.GetLayerFrame(0) : nullptr; + if (tipFrame) tip = vector_scale(direction, (tipFrame->height + tipFrame->pos.y) * sprite.scale.y); + Vector start = vector_add(pos, tip); + Entity_Player* player = spawnerEntity && spawnerEntity->type == ENTITY_PLAYER ? spawnerEntity->ToPlayer() : nullptr; + + endPoint = calc_end_point(start, direction); + if (maxDistance > 0 && vector_length_squared(vector_sub(start, endPoint)) > maxDistance * maxDistance) + endPoint = vector_add(start, vector_resized(vector_sub(endPoint, start), maxDistance)); + homingLaser.bezier.clear(); + + bool isGiantPlayer = + (variant == LASER_GIANT_RED || variant == LASER_GIANT_BRIM_TECH) && spawnerType == ENTITY_PLAYER; + Vector reach = vector_sub(endPoint, start); + if (isGiantPlayer) reach = vector_sub(reach, vector_scale(direction, BEAM_GIANT_TIP_GAP)); + if (vector_dot(reach, tip) < 0) + { + float tipLength = vector_length(tip); + Vector nudge = tipLength > 0 ? vector_scale(tip, BEAM_START_NUDGE / tipLength) : tip; + Vector base = isGiantPlayer ? vector_add(start, tip) : start; + endPoint = vector_add(base, nudge); + } + + homingLaser.origin = start; + homingLaser.endPoint = endPoint; + if (tearFlags[TEAR_ORBIT]) homingLaser.build_curl_path(HOMING_LASER_RING_REACH); + if (tearFlags[TEAR_BOOMERANG]) + { + homingLaser.build_wiggle_bezier(); + if (!homingLaser.bezier.empty()) endPoint = homingLaser.bezier.back().point; + } + if (tearFlags[TEAR_TURN_HORIZONTAL]) + { + homingLaser.trace_entities(TEAR_TURN_HORIZONTAL); + if (!homingLaser.bezier.empty()) endPoint = homingLaser.bezier.back().point; + } + + BezierPathType pathType = BEZIER_PATH_STRAIGHT; + if (tearFlags[TEAR_HOMING]) + pathType = BEZIER_PATH_HOMING; + else if (homingType == LASER_HOMING_FREEZE) + pathType = BEZIER_PATH_OTHER_TYPES; + else if (homingType == LASER_HOMING_PLAYER) + pathType = BEZIER_PATH_WITH_PLAYERS; + homingLaser.build_bezier_path(pathType, parent); + + float blend = 0.63f; + if (variant == LASER_THIN_RED || variant == LASER_ELECTRIC) + blend = 0.7f; + else if (homingType == LASER_HOMING_PLAYER) + blend = 1; + else if (maxDistance <= 0) + blend = 0.9f; + homingLaser.CalculateSamples(blend); + + float phase = (float)index; + if (tearFlags[TEAR_SQUARE] && !tearFlags[TEAR_ORBIT]) + homingLaser.apply_sample_wiggle(player ? worm_multiplier_get(player, TEAR_SQUARE) : 1, phase); + if (tearFlags[TEAR_WIGGLE]) + homingLaser.apply_sine_offset(player ? worm_multiplier_get(player, TEAR_WIGGLE) : 1, phase); + if (tearFlags[TEAR_BIG_SPIRAL]) + update_wiggle_path(player ? worm_multiplier_get(player, TEAR_BIG_SPIRAL) * 3 : 3, phase); + else if (tearFlags[TEAR_SPIRAL]) + update_wiggle_path(player ? worm_multiplier_get(player, TEAR_SPIRAL) : 1, phase); + if (tear_flags_any(tearFlags, {TEAR_POP, TEAR_ABSORB})) isCut = homingLaser.truncate_samples(HOMING_LASER_REACH); + + if (entityGridCollisionClass != GRIDCOLL_NONE && !tearFlags[TEAR_SPECTRAL]) + { + isGridHit = + homingLaser.clip_samples_to_grid(vector_scale(posOffset, GRID_HIT_OFFSET_SCALE), entityGridCollisionClass); + if (isGridHit) isCut = false; + if (homingType == LASER_HOMING_PLAYER) homingLaser.truncate_samples_at_obstacle(posOffset); + } + bool isPlayersParent = parent && (parent->type == ENTITY_PLAYER || parent->type == ENTITY_FAMILIAR); + if (g_game->challenge == CHALLENGE_PONG && !isPlayersParent) homingLaser.truncate_samples_at_player(); + + bool isMirrored = false; + path_redirects_update(isRedirected, isCut, isMirrored); + + if (!isMirrored) + { + if (tearFlags[TEAR_BOUNCE] && !isRedirected) + reconstruction_missing("Entity_Laser::update_laser 00973c60: Rubber Cement's bounce"); + if (bounceLaser) bounceLaser->Remove(); + spawn_impact_effect(); + } + if (!isGridHit) + isCut = isCut || chainedLasers > 0; + else + chainedLasers = 0; + update_impact_effect(isCut); + + Entity* follow = child; + int endCollision = follow ? (int)g_game->room->GetGridCollision( + g_game->room->GetGridIndex(vector_add(follow->pos, follow->posOffset))) + : 0; + bool isDroppingVariant = variant == LASER_THICK_RED || variant == LASER_GIANT_RED || variant == LASER_BRIM_TECH || + variant == LASER_THICKER_RED || variant == LASER_THICK_BROWN || + variant == LASER_THICKER_BRIM_TECH || variant == LASER_GIANT_BRIM_TECH; + bool isBlockedEnd = maxDistance == 0 || (endCollision != COLLISION_NONE && endCollision != COLLISION_PIT); + if (isDroppingVariant && sprite.scale.x > 0.5f && spawnerType == ENTITY_PLAYER && isBlockedEnd && + !isInterpolating && !HasEntityFlags(FLAG_INTERPOLATION_UPDATE) && homingLaser.samples.size() > 1) + { + std::vector& samples = homingLaser.samples; + float back = vector_angle(vector_sub(samples[samples.size() - 2], samples.back())); + float angle = angle_wrap(random_fraction() * ANGLE_HALF_TURN + back - SPRITE_ROTATION_OFFSET); + uint32_t seed = Random(); + Vector velocity = vector_scale(vector_from_angle(angle), random_fraction() * 10 + 1); + Vector position = vector_add(samples.back(), vector_scale(random_direction(), random_fraction() * 20)); + Entity* drop = g_game->Spawn({.position = position, + .velocity = velocity, + .type = ENTITY_EFFECT, + .variant = EFFECT_BLOOD_DROP, + .seed = seed}); + if (child) + { + drop->sprite = child->sprite; + drop->sprite.SetFrame("Droplets", random_below(3)); + } + drop->posOffset = posOffset; + drop->SetColor(sprite.color, -1, COLOR_PRIORITY_DEFAULT, false, true); + drop->Update(); + } + + if (tearFlags[TEAR_MYSTERIOUS_LIQUID_CREEP] && IsFrame(5, (int)index)) + reconstruction_missing("Entity_Laser::update_laser 00973c60: Mysterious Liquid's creep at the beam's end"); +} + +// The splits a path laser meets: Multidimensional Baby doubles the players' beams through it, a mirror bounces the +// others, Angelic Prism splits the players' into four, and Continuum carries a beam on from the opposite wall. Each +// one met marks the beam redirected. +void Entity_Laser::path_redirects_update(bool& isRedirected, bool& isCut, bool& isMirrored) +{ + Vector hitPosition{}; + Vector hitDirection{}; + bool isPlayers = + spawnerType == ENTITY_PLAYER || (spawnerType == ENTITY_FAMILIAR && spawnerVariant != FAMILIAR_ANGELIC_PRISM); + if (isPlayers && !isMultidimensionalTouched) + { + if (homingLaser.find_targets(hitPosition, hitDirection, ENTITY_FAMILIAR, Entity_Familiar::MULTIDIMENSIONAL_BABY, + nullptr)) + reconstruction_missing("Entity_Laser::update_laser 00973c60: Multidimensional Baby's beams"); + for (EntityPtr& split : multidimensionalLasers) + if (split) split->Remove(); + impact_effect_refresh(); + } + + bool isOthers = + (spawnerType != ENTITY_PLAYER && spawnerType != ENTITY_FAMILIAR) || g_game->deathmatchManager.is_active(); + if (isOthers) + { + Entity* mirror = homingLaser.find_targets(hitPosition, hitDirection, ENTITY_EFFECT, EFFECT_LASER_MIRROR, this); + isMirrored = mirror != nullptr; + if (isMirrored) reconstruction_missing("Entity_Laser::update_laser 00973c60: a beam off a mirror"); + Entity* bounce = bounceLaser; + if (bounce && bounce->parent && bounce->parent->type == ENTITY_PLAYER) bounce->Remove(); + } + + bool isPrismable = spawnerType == ENTITY_PLAYER || + (spawnerType == ENTITY_FAMILIAR && spawnerVariant != Entity_Familiar::MULTIDIMENSIONAL_BABY); + if (isPrismable && !isPrismTouched) + { + if (homingLaser.find_targets(hitPosition, hitDirection, ENTITY_FAMILIAR, FAMILIAR_ANGELIC_PRISM, nullptr)) + reconstruction_missing("Entity_Laser::update_laser 00973c60: Angelic Prism's beams"); + for (EntityPtr& split : prismLasers) + if (split) split->Remove(); + impact_effect_refresh(); + } + + if (!tearFlags[TEAR_CONTINUUM] || isRedirected || isGridHit) + { + if (continuumLaser) continuumLaser->Remove(); + } + else + reconstruction_missing("Entity_Laser::update_laser 00973c60: Continuum's beam from the far wall"); + (void)isCut; +} + +// After splits that met nothing, a missing impact effect is put back, and a giant beam's renewed after a bounce. +void Entity_Laser::impact_effect_refresh() +{ + Entity* effect = child; + if (effect) + { + bool isGiant = variant == LASER_GIANT_RED || variant == LASER_GIANT_BRIM_TECH; + bool isStale = bounceLaser && effect->type == ENTITY_EFFECT && effect->variant == EFFECT_LASER_IMPACT && + effect->subtype != IMPACT_SUBTYPE_GIANT_END && isGiant; + if (!isStale) return; + effect->Remove(); + } + spawn_impact_effect(); +} + +// A parent that died takes its laser along (removing it at once when the parent is a laser already gone). A dying or +// shrinking beam fades: a thin beam plays its fade animation, the thick ones narrow over 19 frames. +void Entity_Laser::death_update() +{ + Entity* owner = parent; + if (owner && owner->isDead && owner->type != ENTITY_EFFECT) + { + isDead = true; + if (owner->type == type && !owner->isExists) Remove(); + } + if (!isDead && !isShrink) return; + + if (variant == LASER_THIN_RED) + { + if (sprite.animState.IsLoopingAnimation()) + { + sprite.Play(sprite.GetAnimation() + "Fade"); + if (child) child->sprite.Play("End"); + if (initSeed & 0x1000) sprite.SetFrame(1); + } + if (!sprite.IsFinished()) return; + } + else if (variant != LASER_ELECTRIC && variant != LASER_PRIDE) + { + timeout--; + sprite.scale.x *= SHRINK_RATE; + if (timeout > SHRINK_TIMEOUT_END) return; + } + Remove(); +} + +// After the hits: on a hit frame the beam's end (or wherever it was stopped) sets off its tear effects, and Pop and +// Absorb drop a tear there. The split beams of Cricket's Body follow the impact. +void Entity_Laser::ends_update(bool isSamplesRebuilt, bool isHitFrame, bool isRedirected, bool isCut) +{ + bool isImpact = false; + if (isSamplesRebuilt) + { + isImpact = std::isfinite(impactDistance) || isGridHit || !(isCut || (parent && parent->type == ENTITY_TEAR)); + if (isHitFrame && isImpact) impact_tear_flag_effects(impactPosition, impactDirection); + bool isEnded = std::isfinite(impactDistance) || isGridHit || chainedLasers == 0; + bool isPopped = tear_flags_any(activeTearFlags, {TEAR_POP, TEAR_ABSORB}) && !isRedirected && !isGridHit; + if (isHitFrame && isEnded && isPopped) + reconstruction_missing("Entity_Laser::update_laser 00973c60: Pop's and Absorb's tear at the beam's end"); + } + + if (isImpact && activeTearFlags[TEAR_SPLIT]) + reconstruction_missing("Entity_Laser::update_laser 00973c60: the split beams of Cricket's Body"); + for (EntityPtr& split : subLasers) + if (split) split->Remove(); + subLaserDistance = INFINITY; +} + +// Past its second frame a beam of a spread fires the next of its chain from its end. +void Entity_Laser::chain_fire() +{ + if (g_game->frameCount - spawnFrame <= 1 || chainedLasers <= 0) return; + if (homingLaser.samples.size() > 1) + reconstruction_missing("Entity_Laser::update_laser 00973c60: the chained beams of a spread"); + chainedLasers = 0; +} + +// 009737b0 Finds what the beam hits: its end and direction there first, the grid along its path, then the entities +// crossing it. +void Entity_Laser::update_endpoint_and_hits() +{ + impactDistance = INFINITY; + std::vector& samples = homingLaser.samples; + if (samples.size() > 1) + { + impactPosition = samples.back(); + impactDirection = vector_normalized(vector_sub(samples.back(), samples[samples.size() - 2])); + } + if (!isOneHit || isFirstUpdate) find_nearest_grid_hit(vector_scale(posOffset, GRID_HIT_OFFSET_SCALE)); + update_line_hits(collisionDamage); +} + +// 0097e6f0 Between updates, a beam finds its path again, and a ring moves on (Ludovico's and the flying ones by half +// their velocity) and hits. +void Entity_Laser::Interpolate() +{ + if (waitFrames >= 1 || isFirstUpdate) return; + + isInterpolating = true; + preInterpolatePos = pos; + if (!IsCircleLaser()) return update_laser(); + + if (subtype != LASER_SUBTYPE_RING_FOLLOW_PARENT) + pos = vector_add(pos, vector_scale(velocity, friction * ROTATION_STEP_SCALE)); + UpdateHits(); +} + +// 0097e800 Lets go of the lasers it split into, bounced into or chained (removing them first when the factory took it +// back), and of its parent laser and Anti-Gravity swirl. +void Entity_Laser::ClearReferences() +{ + Entity::ClearReferences(); + auto release = [this](EntityPtr& laser) { + if (isRemovedByFactory && laser) + { + laser->Remove(); + laser->ClearReferences(); + } + laser = nullptr; + }; + for (EntityPtr& laser : multidimensionalLasers) release(laser); + for (EntityPtr& laser : prismLasers) release(laser); + release(bounceLaser); + release(childLaser); + parentLaser = nullptr; + for (EntityPtr& laser : subLasers) release(laser); + release(continuumLaser); + tearWaitEffect = nullptr; +} + +// 0097ea30 Removes the laser with the lasers it split into, and unless it hits once the ones it bounced into or +// chained, and its impact effect. The Forsaken's beam stops its loop. +void Entity_Laser::Remove() +{ + Entity::Remove(); + auto remove = [](EntityPtr& laser) { + if (laser && laser->isExists) laser->Remove(); + }; + for (EntityPtr& laser : multidimensionalLasers) remove(laser); + for (EntityPtr& laser : prismLasers) remove(laser); + if (!isOneHit) + { + remove(bounceLaser); + remove(childLaser); + for (EntityPtr& laser : subLasers) remove(laser); + remove(continuumLaser); + } + remove(child); + if (variant == LASER_THICK_RED && spawnerType == SPAWNER_FORSAKEN) g_manager->sfxManager.Stop(SOUND_FORSAKEN_LASER); +} + +// 0099efc0 Big Spiral's and Ring Worm's path turns are not reconstructed yet. +void Entity_Laser::update_wiggle_path(float, float) { reconstruction_missing("Entity_Laser::update_wiggle_path 0099efc0"); } diff --git a/src/entity_laser.h b/src/entity_laser.h index 5e3db18..99659db 100644 --- a/src/entity_laser.h +++ b/src/entity_laser.h @@ -1,31 +1,98 @@ #pragma once #include "entity.h" +#include "homing_laser.h" #include -#include +#include #include -// Construction and destruction (0096ccf0, 0096cb60, 0096cd20) are the defaults. The homing path waits for -// HomingLaser's takeover. +// What a Technology laser fires with: its timeout, the depths it draws at in front of or behind the head, and how far +// an aim leans before it counts as away. C Section's lasers leave above it. World units shrink by this on screen. +constexpr int TECH_LASER_TIMEOUT = 3; +constexpr float TECH_LASER_FRONT_DEPTH = 3000; +constexpr float TECH_LASER_BACK_DEPTH = -10; +constexpr float TECH_LASER_FACING = 0.5f; +constexpr float C_SECTION_LASER_LIFT = -6; +constexpr float LASER_SCREEN_SCALE = 0.65f; + +// The beams (Lua's LaserVariant). +enum LaserVariant : int +{ + LASER_THICK_RED = 1, + LASER_THIN_RED = 2, + LASER_SHOOP = 3, + LASER_PRIDE = 4, + LASER_LIGHT_BEAM = 5, + LASER_GIANT_RED = 6, + LASER_TRACTOR_BEAM = 7, + LASER_LIGHT_RING = 8, + LASER_BRIM_TECH = 9, + LASER_ELECTRIC = 10, + LASER_THICKER_RED = 11, + LASER_THICK_BROWN = 12, + LASER_BEAST = 13, + LASER_THICKER_BRIM_TECH = 14, + LASER_GIANT_BRIM_TECH = 15 +}; + +// What shape a laser takes (Lua's LaserSubType): a line, or a ring that is Ludovico's, flies, or follows its parent. +enum LaserSubType : int +{ + LASER_SUBTYPE_LINEAR, + LASER_SUBTYPE_RING_LUDOVICO, + LASER_SUBTYPE_RING_PROJECTILE, + LASER_SUBTYPE_RING_FOLLOW_PARENT, + LASER_SUBTYPE_NO_IMPACT +}; + +// Whether a laser follows the samples of its path, or has not decided yet (the original's -1). +enum SampleMode : int8_t +{ + SAMPLE_UNDECIDED = -1, + SAMPLE_STRAIGHT, + SAMPLE_PATH +}; + +// Whether copy_from_parent also takes the parent's spawn data (seed, spawner, scale and chain) or only its look and +// flags. +enum LaserCopy +{ + LASER_COPY_STATE, + LASER_COPY_SPAWN +}; + +// What ShootAngle spawns: a laser of a variant from a position at an angle, its timeout and offset, from a source. +struct LaserShot +{ + Vector position{}; + Vector posOffset{}; + Entity* source = nullptr; + float angleDegrees = 0; + int timeout = 0; + int variant = 0; + bool isPoolKept = false; +}; + +// Construction and destruction (0096cb60, 0096ccf0, 0096cd20) are the defaults. // Field accessors (00435f20, 00435f30, 00456850, 004aaed0, 005cd580, 005cd590, 0060cea0, 0060ceb0, 007e9230, -// 007e9240) are the public fields. -// A laser (Lua's EntityLaser): a beam from its parent at an angle, its length, timeout and tear effects, the curve a -// homing one follows, and the lasers it splits into. +// 007e9240, 0097e3b0, 0097e6e0, 008c5cf7) are the public fields. +// A laser (Lua's EntityLaser): a beam from its parent at an angle, or a ring, with its length, timeout and tear +// effects, the path its samples follow, and the lasers it splits into, bounces into and chains. struct Entity_Laser : Entity { + HomingLaser homingLaser; + std::vector hitList; std::array prismLasers; std::array multidimensionalLasers; std::array subLasers; - std::unique_ptr homingLaser; - std::vector hitList; TearFlags activeTearFlags; TearFlags heldTearFlags; TearFlags tearFlags; + EntityPtr bounceLaser; EntityPtr childLaser; EntityPtr continuumLaser; EntityPtr parentLaser; EntityPtr tearWaitEffect; - Entity* bounceLaser = nullptr; Vector endPoint{}; Vector impactDirection{}; Vector impactPosition{}; @@ -33,23 +100,24 @@ struct Entity_Laser : Entity float angleDegrees = 0; float blackHpDropChance = 0; float curveStrength = 0; - float damageMultiplier = 0; - float impactDistance = 0; + float damageMultiplier = 1; + float impactDistance = INFINITY; float laserLength = 0; float lastAngleDegrees = 0; float maxDistance = 0; float radius = 0; float rotationDegrees = 0; float rotationSpd = 0; - float scale = 0; + float scale = 1; float startAngleDegrees = 0; float subLaserAngle = 0; - float subLaserDistance = 0; + float subLaserDistance = INFINITY; int chainedLasers = 0; int timeout = 0; int waitFrames = 0; uint32_t homingType = 0; uint32_t rotationDelay = 0; + SampleMode sampleMode = SAMPLE_UNDECIDED; bool isActiveRotating = false; bool isDisableFollowParent = false; bool isDisableInitSound = false; @@ -57,10 +125,13 @@ struct Entity_Laser : Entity bool isGridHit = false; bool isMultidimensionalTouched = false; bool isOneHit = false; + bool isPlayerParams = false; bool isPrismTouched = false; bool isSampleLaser = false; bool isShrink = false; + Entity_Laser(); + void Init(int type, int variant, int subType, uint32_t initSeed) override; void Update() override; void Interpolate() override; @@ -73,30 +144,55 @@ struct Entity_Laser : Entity void ClearReferences() override; bool HandleCollision(Entity* collider, bool isLow) override; - bool IsCircleLaser(); - bool is_thick_variant(); - bool CanDamageEntity(Entity* entity); - void impact_tear_flag_effects(const Vector& position, const Vector& direction); - ColorMod* get_tear_spawn_color(const ColorMod& outColor); - void copy_from_parent(Entity_Laser* parent, bool isCopySpawnData); + static Entity_Laser* ShootAngle(const LaserShot& shot); + static Vector CalculateEndPoint(const Vector& start, const Vector& direction, const Vector& positionOffset, + Entity* parent, float margin); + void SetActiveRotation(int delay, float angle, float speed, bool isTimeoutComplete); void RotateToAngle(float angle, float speed); void ClearLaserSamples(); void PlayInitSound(); - Vector calc_end_point(const Vector& start, const Vector& direction); + void ResetSpriteScale(); + void set_scale(float newScale); + void set_aim_angle(float angle); + bool IsCircleLaser(); + bool is_players_laser(); + bool is_thick_variant(); + bool CanDamageEntity(Entity* entity); + void DoDamage(Entity* entity, float damage); + ColorMod CalculateTearColor(); + void copy_from_parent(Entity_Laser& parent, LaserCopy copy); + std::vector& hit_list_get(); + Entity_Laser* root_laser_get(); + void update_first_frame(); - void find_nearest_grid_hit(int unusedFlag, const Vector& offset); - uint8_t damage_grid_entity(int gridIndex, int unused, const Vector& direction); - void update_line_hits(); - void update_endpoint_and_hits(); - void refresh_tear_params(); void update_laser(); void UpdateHits(); - void* GetSamples(); - void damage_entity(Entity*); - void* GetNonOptimizedSamples(); - void spawn_impact_effect(int unused); - void ResetSpriteScale(); - void set_scale(float scale); - void update_sample_points(char); - static void update_wiggle_path(void* samples, float amplitude, float phase); + void update_endpoint_and_hits(); + void refresh_tear_params(); + void update_impact_effect(bool isHidden); + void spawn_impact_effect(); + Vector calc_end_point(const Vector& start, const Vector& direction); + bool get_segment_start_dir(float distance, Vector& outPosition, Vector& outDirection); + void find_nearest_grid_hit(const Vector& offset); + bool damage_grid_entity(int gridIndex, const Vector& direction); + void update_line_hits(float damage); + void impact_tear_flag_effects(const Vector& position, const Vector& direction); + void update_wiggle_path(float amplitude, float phase); + +private: + void tear_wait_start(); + void color_cycle_update(); + void straight_update(bool& isRedirected); + void path_update(bool& isRedirected, bool& isCut); + void path_redirects_update(bool& isRedirected, bool& isCut, bool& isMirrored); + void ends_update(bool isSamplesRebuilt, bool isHitFrame, bool isRedirected, bool isCut); + void chain_fire(); + void death_update(); + void splash_spawn(const Vector& center, const Vector& along, float from, float to, Entity& target); + void impact_effect_refresh(); + void render_path(const Vector& offset, bool isShadow); + void render_straight(const Vector& offset, bool isShadow); }; + +float angle_difference(float from, float to); +bool tear_flags_any(const TearFlags& flags, std::initializer_list bits); diff --git a/src/entity_laser_hits.cpp b/src/entity_laser_hits.cpp new file mode 100644 index 0000000..923f1fa --- /dev/null +++ b/src/entity_laser_hits.cpp @@ -0,0 +1,471 @@ +#include "boss_ai.h" +#include "entity_combat.h" +#include "entity_effect.h" +#include "entity_familiar.h" +#include "entity_laser.h" +#include "entity_pickup.h" +#include "entity_player.h" +#include "entity_projectile.h" +#include "entity_tear.h" +#include "game.h" +#include "grid_entity.h" +#include "log.h" +#include "manager.h" +#include "npc_ai.h" +#include "room.h" +#include "room_grid.h" +#include "sfx_manager.h" +#include +#include +#include + +constexpr float LASER_KNOCKBACK = 1.8f; +constexpr float OWNER_KNOCKBACK_SCALE = 0.2f; +constexpr float GROW_RANGE = 1000; +constexpr float GROW_GAIN = 5; +constexpr float SHRINK_RANGE = 300; +constexpr float MINIMUM_DAMAGE = 0.1f; +constexpr float THICK_BACK_REACH = 16; +constexpr float PATH_END_REACH = 40; +constexpr float RING_REACH_SCALE = 0.1f; +constexpr float GRID_SWEEP_STEP = 20; +constexpr float ROOM_SIDE_MARGIN = -8; +constexpr float GRID_REACH_EXTRA = 15; +constexpr float SPLASH_EDGE = 2; +constexpr float SPLASH_SPEED_MIN = 4; +constexpr float SPLASH_SPEED_RANGE = 6; +constexpr float SPLASH_SPREAD = 3; +constexpr float SPLASH_SCALE = 2; +constexpr float SPLASH_HALF_TURN = 3.14f; +constexpr float MARKED_SPLASH_SPEED_MIN = 2; +constexpr float MARKED_SPLASH_SPEED_RANGE = 2; +constexpr float MARKED_TINT_RED = 2; +constexpr float MARKED_ROTATION_RANGE = 360; +constexpr float MARKED_SOUND_VOLUME = 0.7f; +constexpr int MARKED_SOUND_DELAY = 8; +constexpr float MARKED_DAMAGE_EXTRA = 3; +constexpr float PLAYER_HIT_DAMAGE = 1; +constexpr int LASER_HIT_COUNTDOWN = 30; +constexpr int GRID_HURT_CHANCE_MASK = 3; +constexpr int SHIELD_RING_CHANCE = 50; +constexpr int SHIELD_CHANCE = 5; +constexpr int CHALLENGE_PONG_HITS = 30; +constexpr int MARKED_SPRAY_SUBTYPE = 2; +constexpr RNG BLACK_HEART_RNG = {0, 1, 5, 19}; +constexpr int PULLED_EFFECTS[] = {EFFECT_TINY_BUG, EFFECT_TINY_FLY, EFFECT_WORM, EFFECT_BEETLE, EFFECT_LIL_GHOST}; + +// Whether a laser's knockback moves an entity: a bomb with knockback off only from a player's laser, a player not +// from a friendly spawner's. +static bool is_knocked_back(Entity_Laser& laser, Entity& entity) +{ + Entity* spawner = laser.spawnerEntity; + if (entity.HasEntityFlags(FLAG_NO_KNOCKBACK)) + return entity.type == ENTITY_BOMB && spawner && spawner->type == ENTITY_PLAYER; + return entity.type != ENTITY_PLAYER || !spawner || !spawner->HasEntityFlags(FLAG_FRIENDLY); +} + +// Pushes an entity along a direction by the laser's mass, divided by the entity's weight, weaker on players and +// familiars, twice as strong under Knockback. +static void laser_push(Entity_Laser& laser, Entity& entity, Vector direction, float weight) +{ + if (weight > 0) direction = vector_scale(direction, 1 / weight); + float strength = laser.mass * LASER_KNOCKBACK; + if (entity.type == ENTITY_PLAYER || entity.type == ENTITY_FAMILIAR) strength *= OWNER_KNOCKBACK_SCALE; + if (laser.tearFlags[TEAR_KNOCKBACK]) strength += strength; + if (entity.friction == 0) return; + entity.velocity = + vector_add(entity.velocity, vector_scale(direction, strength * entity.speedMultiplier / entity.friction)); +} + +// 0097e3c0 Hits an entity: it joins the hit list, then takes the laser's damage and tear effects from its spawner. A +// player outside a versus match (and the familiars that take a player's hits) takes one heart's hit. Bombs are +// spared. A Brimstone-marked entity takes a thick beam's hit harder, and Black Hp drops are rolled from its seed. +void Entity_Laser::DoDamage(Entity* entity, float damage) +{ + std::vector& hits = hit_list_get(); + uint32_t hitIndex = entity->GetHitListIndex(); + auto slot = std::lower_bound(hits.begin(), hits.end(), hitIndex); + if (slot == hits.end() || *slot != hitIndex) hits.insert(slot, hitIndex); + if (entity->type == ENTITY_BOMB) return; + + Entity* source = spawnerEntity ? spawnerEntity.get() : this; + bool isVersus = g_game->deathmatchManager.is_active(); + if (entity->type == ENTITY_PLAYER) + { + if (!isVersus) + { + entity->TakeDamage(PLAYER_HIT_DAMAGE, DAMAGE_LASER, EntityRef(source), LASER_HIT_COUNTDOWN); + return; + } + if (IsDescendantOf(entity)) return; + } + else if (entity->type == ENTITY_FAMILIAR && !isVersus && + (entity->variant == Entity_Familiar::ISAACS_HEART || + (g_game->challenge == CHALLENGE_PONG_HITS && entity->variant == Entity_Familiar::PUNCHING_BAG))) + { + Entity_Player* player = static_cast(entity)->player; + player->TakeDamage(PLAYER_HIT_DAMAGE, DAMAGE_LASER | DAMAGE_ISAAC_HURT, EntityRef(source), LASER_HIT_COUNTDOWN); + return; + } + + uint64_t damageFlags = DAMAGE_LASER | tear_damage_flags_get(tearFlags, this); + Entity_Tear::ApplyTearFlagEffects(entity, pos, tearFlags, this, damage); + if (entity->HasEntityFlags(FLAG_BRIMSTONE_MARKED) && is_thick_variant()) + { + int sound = SOUND_MEAT_IMPACTS; + seed_fart_sound_override(&sound); + g_manager->sfxManager.Play(sound, {.volume = MARKED_SOUND_VOLUME, .frameDelay = MARKED_SOUND_DELAY}); + entity->AddEntityFlags(FLAG_EXTRA_GORE); + damage = damage + damage + MARKED_DAMAGE_EXTRA; + } + if (blackHpDropChance > 0 && entity->IsActiveEnemy(DEAD_EXCLUDED)) + { + RNG roll = BLACK_HEART_RNG; + roll._seed = entity->initSeed; + if (roll.RandomFloat() < blackHpDropChance) damageFlags |= DAMAGE_SPAWN_BLACK_HEART; + } + if (isVersus && tearFlags[TEAR_LASERSHOT]) damageFlags |= DAMAGE_LASER; + entity->TakeDamage(damage, damageFlags, EntityRef(source), LASER_HIT_COUNTDOWN); +} + +// 00971590 Hurts the grid entity in a cell the beam crosses. One time in four a standing one is broken by an Acid or +// Rocks laser (bridging the pit beyond it). Whether the hurt took. +bool Entity_Laser::damage_grid_entity(int gridIndex, const Vector& direction) +{ + if (gridIndex < 0 || gridIndex >= ROOM_GRID_CELLS) return false; + Room& room = *g_game->room; + GridEntity* grid = room.GetGridEntity((uint32_t)gridIndex); + if (!grid) return false; + + bool isStanding = grid->collisionClass != COLLISION_NONE && grid->collisionClass != COLLISION_PIT; + if (isStanding && (Random() & GRID_HURT_CHANCE_MASK) == 0) + { + TearFlags flags = tearFlags; + Entity* spawner = spawnerEntity; + Entity_Player* player = spawner && spawner->type == ENTITY_PLAYER ? spawner->ToPlayer() : nullptr; + if (spawner && spawner->type == ENTITY_FAMILIAR && spawner->variant == Entity_Familiar::INCUBUS) + player = static_cast(spawner)->player; + if (player) flags |= player->GetTearHitParams(WEAPON_LASER, 1, 0, spawner).tearFlags; + + bool isBreaking = flags[TEAR_ACID] || flags[TEAR_ROCK_FLAG]; + if (isBreaking && grid->CanTakeDamageFromTearEffects() && grid->Destroy(false, EntityRef(this))) + { + Vector step = vector_cardinal(direction); + if (!vector_is_zero(step)) + { + int beyond = room.GetGridIndex(vector_add(grid->Position(), vector_scale(step, GRID_CELL_SIZE))); + if (beyond >= 0) room_bridge_make(room.GetGridEntity((uint32_t)beyond), grid); + } + } + } + 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). +// 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) +{ + Room& room = *g_game->room; + if (isSampleLaser && homingLaser.nonOptimizedSamples.size() > 1) + { + const std::vector& samples = homingLaser.nonOptimizedSamples; + size_t count = samples.size(); + std::map crossed; + Vector previous = vector_add(samples[0], offset); + Vector lastInRoom = previous; + Vector lastInRoomDirection{}; + float lastInRoomDistance = 0; + 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) { + if (!room.IsPositionInRoom(point, ROOM_SIDE_MARGIN)) + { + if (tearFlags[TEAR_CONTINUUM] && travelled < impactDistance) + { + impactDistance = travelled; + impactPosition = previous; + impactDirection = direction; + } + 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) + crossed.try_emplace(index, direction); + }; + + for (size_t i = 0; i <= count; i++) + { + Vector point{}; + Vector segment{}; + if (i < count) + { + point = vector_add(samples[i], offset); + segment = + i < count - 1 ? vector_sub(samples[i + 1], samples[i]) : vector_sub(samples[i], samples[i - 1]); + } + else + { + segment = vector_sub(samples[count - 1], samples[count - 2]); + point = vector_add(vector_add(samples[count - 1], segment), offset); + } + float length = vector_length(segment); + Vector direction = vector_scale(segment, 1 / length); + Vector side = vector_make(direction.y, -direction.x); + if (room.IsPositionInRoom(point, 0)) + { + lastInRoomDistance = travelled; + lastInRoom = point; + lastInRoomDirection = direction; + } + 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); + } + travelled += length; + previous = point; + last = point; + } + for (auto& [index, direction] : crossed) damage_grid_entity(index, direction); + + if (!room.IsPositionInRoom(last, 0) && lastInRoomDistance < impactDistance && !IsCircleLaser()) + { + impactDistance = lastInRoomDistance; + impactPosition = lastInRoom; + impactDirection = lastInRoomDirection; + } + } + + Vector direction = vector_from_angle(angleDegrees); + Entity* owner = parent; + bool isPlayersParent = owner && (owner->type == ENTITY_PLAYER || owner->type == ENTITY_FAMILIAR || + owner->spawnerType == ENTITY_PLAYER); + if (!isPlayersParent && spawnerType != ENTITY_PLAYER && spawnerType != ENTITY_FAMILIAR) return; + + float reach = maxDistance > 0 ? size + maxDistance : INFINITY; + int cells = room.gridHeight * room.gridWidth; + for (int index = 0; index < cells && index < ROOM_GRID_CELLS; index++) + { + if (!room.gridEntities[(size_t)index]) continue; + Vector cell = vector_make((float)(index % room.gridWidth) * GRID_CELL_SIZE + GRID_ORIGIN_X, + (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; + if (std::abs(across) < size + GRID_REACH_EXTRA && along > 0 && along <= reach) + damage_grid_entity(index, direction); + } +} + +// Splashes a thick beam throws off what it hits: up to three drops across the part of the beam's width the entity +// covers, in the beam's sprite color, and a red spray off a Brimstone-marked one. +void Entity_Laser::splash_spawn(const Vector& center, const Vector& along, float from, float to, Entity& target) +{ + const AnimationFrame* frame = sprite.animState.GetLayerFrame(0); + LayerState* layer = sprite.GetLayer(0); + ColorMod splash = sprite.color; + if (layer) color_multiply(splash, layer->color); + if (frame) color_multiply(splash, frame->color); + Vector side = vector_make(along.y, -along.x); + float height = posOffset.y; + + int drops = (int)(Random() & 3); + for (int i = 0; i < drops; i++) + { + uint32_t seed = Random(); + float speed = random_unit() * SPLASH_SPEED_RANGE + SPLASH_SPEED_MIN; + float angle = random_unit() * SPLASH_HALF_TURN * 2; + Vector velocity = vector_add(vector_make(std::cos(angle), std::sin(angle)), vector_scale(along, speed)); + float across = (to - from) * random_unit() + from; + Vector position = vector_add(vector_add(center, vector_scale(side, across)), + vector_scale(along, SPLASH_SPREAD * random_unit())); + Entity* drop = g_game->Spawn({.position = position, + .velocity = velocity, + .subType = 1, + .type = ENTITY_EFFECT, + .variant = EFFECT_WATER_SPLASH, + .seed = seed}); + drop->sprite.scale = vector_scale(drop->sprite.scale, SPLASH_SCALE); + drop->SetColor(splash, -1, COLOR_PRIORITY_DEFAULT, false, true); + drop->posOffset = vector_make(0, height); + drop->Update(); + } + if (!target.HasEntityFlags(FLAG_BRIMSTONE_MARKED)) return; + + ColorMod marked = {{MARKED_TINT_RED, 1, 1, 1}, {0, 0, 0, 0}, {0, 0, 0}}; + color_multiply(marked, sprite.color); + uint32_t seed = Random(); + float speed = random_unit() * MARKED_SPLASH_SPEED_RANGE + MARKED_SPLASH_SPEED_MIN; + float angle = random_unit() * SPLASH_HALF_TURN * 2; + Vector velocity = vector_add(vector_make(std::cos(angle), std::sin(angle)), vector_scale(along, speed)); + float across = (to - from) * random_unit() + from; + Entity* spray = g_game->Spawn({.position = vector_add(center, vector_scale(side, across)), + .velocity = velocity, + .subType = MARKED_SPRAY_SUBTYPE, + .type = ENTITY_EFFECT, + .variant = EFFECT_BLOOD_EXPLOSION, + .seed = seed}); + spray->SetColor(marked, -1, COLOR_PRIORITY_DEFAULT, false, true); + spray->posOffset = vector_make(0, height); + spray->sprite.rotation = random_unit() * MARKED_ROTATION_RANGE; + spray->Update(); +} + +// 00971810 Hits what the beam crosses, for a damage. A straight beam hits what lies within its width along its +// angle and length. A path beam takes the entities it may hurt (with the small critters it kills, the players' +// bombs it pushes, and a projectile Lost Contact catches now and then), finds where each crosses its segments, and +// marks the nearest as where it stops. Its hits grow with distance under Lump of Coal and fade under Proptosis. +void Entity_Laser::update_line_hits(float damage) +{ + Room& room = *g_game->room; + if (!isSampleLaser) + { + Vector direction = vector_from_angle(angleDegrees); + for (size_t i = 0; i < room.entityList.updateEL.size(); i++) + { + Entity* entity = room.entityList.updateEL[i]; + if (!CanDamageEntity(entity)) continue; + + Vector relative = vector_sub(entity->pos, pos); + float along = vector_dot(relative, direction); + float across = std::abs(direction.y * relative.x - direction.x * relative.y); + float reach = variant == LASER_PRIDE ? vector_length(relative) * RING_REACH_SCALE : entity->size + size; + if (across >= reach || along <= 0 || along >= std::abs(posOffset.y) + laserLength) continue; + + DoDamage(entity, damage); + if (is_knocked_back(*this, *entity)) laser_push(*this, *entity, direction, entity->mass); + if (!is_thick_variant()) continue; + + Vector center = vector_add(pos, vector_scale(direction, along)); + float offset = vector_dot(vector_sub(entity->pos, center), vector_make(direction.y, -direction.x)); + float from = std::max(offset - entity->size, -size); + float to = std::min(offset + entity->size, size); + if (from + SPLASH_EDGE < to) splash_spawn(center, direction, from, to, *entity); + } + return; + } + + std::vector candidates; + candidates.reserve(10); + bool isShielded = tearFlags[TEAR_SHIELDED]; + for (size_t i = 0; i < room.entityList.updateEL.size(); i++) + { + Entity* entity = room.entityList.updateEL[i]; + bool isCritter = entity->type == ENTITY_EFFECT && + std::find(std::begin(PULLED_EFFECTS), std::end(PULLED_EFFECTS), entity->variant) != + std::end(PULLED_EFFECTS); + bool isCandidate = isCritter || CanDamageEntity(entity); + if (!isCandidate && entity->type == ENTITY_BOMB) + isCandidate = is_players_laser(); + else if (!isCandidate && isShielded && entity->type == ENTITY_PROJECTILE && + !(static_cast(entity)->projectileFlags & PROJECTILE_CANT_HIT_PLAYER)) + isCandidate = (IsCircleLaser() && Random() % SHIELD_RING_CHANCE == 0) || Random() % SHIELD_CHANCE == 0; + if (isCandidate) candidates.push_back(entity); + + bool isPulled = entity->IsVulnerableEnemy(nullptr) || entity->type == ENTITY_PICKUP; + if (tearFlags[TEAR_ATTRACTOR] && isPulled) + reconstruction_missing("Entity_Laser::update_line_hits 00971810: Strange Attractor's pull"); + } + + const std::vector& samples = homingLaser.samples; + for (Entity* entity : candidates) + { + float travelled = 0; + for (size_t i = 0; i + 1 < samples.size(); i++) + { + Vector end = samples[i + 1]; + bool isLastSegment = i == samples.size() - 2; + if (!IsCircleLaser() && isLastSegment && !isGridHit && maxDistance <= 0) + end = vector_add(end, vector_resized(vector_sub(end, samples[i]), PATH_END_REACH)); + + SegmentProjection projection = segment_project_point(entity->pos, samples[i], end); + float length = vector_length(vector_sub(end, samples[i])); + if (i == 0 && is_thick_variant()) + { + Vector behind = vector_sub(samples[0], vector_scale(vector_from_angle(angleDegrees), THICK_BACK_REACH)); + float behindSquared = vector_length_squared(vector_sub(entity->pos, behind)); + if (behindSquared < projection.distanceSquared) projection = {behindSquared, 0}; + } + float reach = entity->size + size; + if (reach * reach <= projection.distanceSquared) + { + travelled += length; + continue; + } + + if (entity->type == ENTITY_PROJECTILE) + { + static_cast(entity)->projectileFlags = 0; + entity->isDead = true; + break; + } + if (entity->type == ENTITY_EFFECT) + { + entity->isDead = true; + break; + } + + float gap = std::sqrt(projection.distanceSquared) - size; + float sizeSquared = entity->size * entity->size; + float depth = sizeSquared > gap * gap ? std::sqrt(sizeSquared - gap * gap) : 0; + Vector direction = vector_scale(vector_sub(end, samples[i]), 1 / length); + float distance = length * projection.t + travelled; + if (distance - depth < impactDistance) + { + impactDistance = distance - depth; + impactPosition = vector_add(samples[i], vector_scale(direction, length * projection.t - depth)); + impactDirection = direction; + } + + bool isSticky = tear_flags_any(tearFlags, {TEAR_STICKY, TEAR_BOOGER_FLAG, TEAR_SPORE_FLAG}); + if (tearFlags[TEAR_MYSTERIOUS_LIQUID_CREEP] || (isSticky && !entity->isDead && entity->IsEnemy())) + reconstruction_missing( + "Entity_Laser::update_line_hits 00971810: the creep and sticking tears of a hit"); + + float hitDamage = damage; + if (!IsCircleLaser()) + { + if (tearFlags[TEAR_GROW]) hitDamage *= std::min(distance, GROW_RANGE) * GROW_GAIN / GROW_RANGE + 1; + if (tearFlags[TEAR_SHRINK]) hitDamage *= (1 - std::min(distance, SHRINK_RANGE) / SHRINK_RANGE) * 2; + hitDamage = std::max(hitDamage, MINIMUM_DAMAGE); + } + DoDamage(entity, hitDamage); + + if ((!IsCircleLaser() || subtype == LASER_SUBTYPE_RING_PROJECTILE) && is_knocked_back(*this, *entity)) + { + Vector push = subtype == LASER_SUBTYPE_RING_PROJECTILE ? vector_normalized(velocity) : direction; + laser_push(*this, *entity, push, entity->collision_mass_get(this)); + } + if (is_thick_variant()) + { + Vector center = + vector_add(samples[i], vector_scale(vector_sub(samples[i + 1], samples[i]), projection.t)); + float offset = vector_dot(vector_sub(entity->pos, center), vector_make(-direction.y, direction.x)); + float from = std::max(offset - entity->size, -size); + float to = std::min(offset + entity->size, size); + if (from + SPLASH_EDGE < to) splash_spawn(center, direction, from, to, *entity); + } + break; + } + } +} + +// 0096d3f0 What the beam's tear flags do where it ends: explosions, split and quad split tears, Rift, Jacob's +// Ladder's arcs. None of them is reconstructed yet. +void Entity_Laser::impact_tear_flag_effects(const Vector&, const Vector&) +{ + if (tear_flags_any(tearFlags, {TEAR_EXPLOSIVE, TEAR_SPLIT, TEAR_QUADSPLIT, TEAR_RIFT, TEAR_JACOBS})) + reconstruction_missing("Entity_Laser::impact_tear_flag_effects 0096d3f0"); +} + +// 0097baa0 The rings' frame (Tech X, the ring bosses' and Ludovico's lasers) is not reconstructed yet. +void Entity_Laser::UpdateHits() +{ + reconstruction_missing("Entity_Laser::UpdateHits 0097baa0"); +} diff --git a/src/entity_laser_render.cpp b/src/entity_laser_render.cpp new file mode 100644 index 0000000..b8d9e71 --- /dev/null +++ b/src/entity_laser_render.cpp @@ -0,0 +1,277 @@ +#include "entity_laser.h" +#include "entity_tear.h" +#include "game.h" +#include "kage_graphics.h" +#include "log.h" +#include "lua_engine.h" +#include "npc_ai.h" +#include "render_passes.h" +#include +#include + +constexpr float TIP_STEP = 0.025f; +constexpr float TIP_TOP_INSET = 0.01f; +constexpr float BEAM_SHADOW_ALPHA = 0.5f; +constexpr float BEAM_STATIC_STEPS = 256; +constexpr float STRAIGHT_TIP_MINIMUM = 15; +constexpr float GROW_RENDER_RANGE = 1000; +constexpr float GROW_RENDER_GAIN = 1.5f; +constexpr float SHRINK_RENDER_RANGE = 300; +constexpr float SHRINK_RENDER_LOSS = 0.5f; +constexpr float RING_SCROLL_SPEED = 5; + +// What one beam draw needs: where it lands on screen, its spritesheet and colors, and whether it is the shadow. +struct BeamDraw +{ + ColorMod color = COLOR_DEFAULT; + Vector offset{}; + KAGE::Graphics::ImageBase* image = nullptr; + LayerState* layer = nullptr; + bool isShadow = false; +}; + +// A world point on screen, snapped to the screen's pixels. +static Vector screen_point(const Vector& world) +{ + return render_position_get(world, RENDER_SNAPPED); +} + +// Draws one textured quad of the beam with the layer's blending and the sprite shader colored for it. +static void beam_quad_draw(const BeamDraw& draw, const SourceQuad& source, const DestinationQuad& dest) +{ + namespace Graphics = KAGE::Graphics; + using Factor = Graphics::BlendFactor; + const std::array& mode = draw.layer->blendMode; + Graphics::BlendMode saved = Graphics::manager.blendMode; + if (!draw.isShadow) + Graphics::manager.blendMode = {(Graphics::BlendEquation)mode[BLEND_EQUATION], (Factor)mode[BLEND_RGB_SOURCE], + (Factor)mode[BLEND_RGB_DEST], (Factor)mode[BLEND_ALPHA_SOURCE], + (Factor)mode[BLEND_ALPHA_DEST]}; + if (draw.image->wrapS != 0 || draw.image->wrapT != 0) draw.image->wrap_set(0, 0); + + KColor tint = kcolor_rgba(draw.color._tint[0], draw.color._tint[1], draw.color._tint[2], draw.color._tint[3]); + apply_sprite_shader_params(draw.color, SPRITE_SHADER_COLOR_APPLY, *draw.image); + DestinationQuad shifted = dest; + for (Vector* corner : {&shifted._topLeft, &shifted._topRight, &shifted._bottomLeft, &shifted._bottomRight}) + *corner = vector_add(*corner, draw.offset); + draw.image->Render(source, Graphics::ColorQuad(shifted, tint), tint); + Graphics::manager.blendMode = saved; + Graphics::manager.shader_default_set(); +} + +// A spritesheet rectangle from a frame's crop, flipped across when asked, from one height to another. +static SourceQuad beam_source(const AnimationFrame& frame, float top, float bottom, bool isFlipX) +{ + float left = isFlipX ? frame.crop.x + frame.width : frame.crop.x; + float right = isFlipX ? frame.crop.x : frame.crop.x + frame.width; + SourceQuad source; + source._topLeft = vector_make(left, top); + source._topRight = vector_make(right, top); + source._bottomLeft = vector_make(left, bottom); + source._bottomRight = vector_make(right, bottom); + source._coordinateSpace = KAGE::Graphics::COORDINATES_PIXEL; + return source; +} + +// Widens a beam quad about the middles of its two ends, each by its own scale. +static void quad_widen(DestinationQuad& quad, const Vector& startMiddle, const Vector& endMiddle, float startScale, + float endScale) +{ + quad._topLeft = vector_add(startMiddle, vector_scale(vector_sub(quad._topLeft, startMiddle), startScale)); + quad._topRight = vector_add(startMiddle, vector_scale(vector_sub(quad._topRight, startMiddle), startScale)); + quad._bottomLeft = vector_add(endMiddle, vector_scale(vector_sub(quad._bottomLeft, endMiddle), endScale)); + quad._bottomRight = vector_add(endMiddle, vector_scale(vector_sub(quad._bottomRight, endMiddle), endScale)); +} + +// The color a beam layer draws in: the sprite's times the frame's, the static shimmer's step for Dogma's, or black at +// half for the shadow. +static ColorMod beam_color(Entity_Laser& laser, const AnimationFrame& frame, bool isShadow) +{ + if (isShadow) return {{0, 0, 0, BEAM_SHADOW_ALPHA}, {0, 0, 0, 0}, {0, 0, 0}}; + + ColorMod color = laser.sprite.color; + color_multiply(color, frame.color); + if (laser.sprite.bitflags & ANIM_RENDER_STATIC) + color._colorize[3] = (float)(g_game->frameCount % (int)BEAM_STATIC_STEPS) / BEAM_STATIC_STEPS; + return color; +} + +// The beam along the path: one quad per segment, joined at their middles, scrolling the beam's texture along its +// length (and with time for a ring). Lump of Coal widens it with distance, Proptosis narrows it. A line laser then +// draws its start sprite from its position to the beam. +void Entity_Laser::render_path(const Vector& offset, bool isShadow) +{ + const std::vector& samples = homingLaser.samples; + int bodyLayer = sprite.layerStates.size() > 1 ? 1 : 0; + const AnimationFrame* frame = sprite.animState.GetLayerFrame(bodyLayer); + if (!frame) + { + KAGE_LogMessage(LOG_INFO, (uint8_t*)"[warn] Laser::Render current laser frame is NULL\n"); + return; + } + if (samples.size() < 2 || !sprite.layerStates[0].spriteSheet) return; + + BeamDraw draw = {beam_color(*this, *frame, isShadow), offset, sprite.layerStates[0].spriteSheet.get(), + &sprite.layerStates[(size_t)bodyLayer], isShadow}; + draw.offset = vector_add( + draw.offset, vector_make(posOffset.x * LASER_SCREEN_SCALE, isShadow ? 0 : posOffset.y * LASER_SCREEN_SCALE)); + if (!isShadow) draw.offset = vector_add(draw.offset, g_game->screenShakeOffset); + float width = frame->scale.x * draw.layer->size.x * sprite.scale.x * frame->width * 0.5f; + + std::vector quads; + for (size_t i = 0; i + 1 < samples.size(); i++) + { + Vector direction = vector_normalized(vector_sub(samples[i + 1], samples[i])); + Vector side = vector_scale(vector_make(direction.y, -direction.x), width); + Vector from = screen_point(samples[i]); + Vector to = screen_point(samples[i + 1]); + quads.push_back({vector_sub(from, side), vector_add(from, side), vector_sub(to, side), vector_add(to, side)}); + } + if (IsCircleLaser()) reconstruction_missing("Entity_Laser::Render 009785d0: a ring's closing segment"); + + bool isScaled = !IsCircleLaser(); + float along = IsCircleLaser() ? (float)(g_game->frameCount - spawnFrame) * RING_SCROLL_SPEED : 0; + for (size_t i = 0; i < quads.size(); i++) + { + DestinationQuad& quad = quads[i]; + if (i + 1 < quads.size()) + { + quad._bottomLeft = vector_scale(vector_add(quad._bottomLeft, quads[i + 1]._topLeft), 0.5f); + quad._bottomRight = vector_scale(vector_add(quad._bottomRight, quads[i + 1]._topRight), 0.5f); + } + if (i > 0) + { + quad._topLeft = quads[i - 1]._bottomLeft; + quad._topRight = quads[i - 1]._bottomRight; + } + + Vector startMiddle = vector_scale(vector_add(quad._topLeft, quad._topRight), 0.5f); + Vector endMiddle = vector_scale(vector_add(quad._bottomLeft, quad._bottomRight), 0.5f); + float length = vector_length(vector_sub(endMiddle, startMiddle)); + DestinationQuad shown = quad; + if (isScaled && tearFlags[TEAR_GROW]) + quad_widen(shown, startMiddle, endMiddle, std::min(along / GROW_RENDER_RANGE, 1.0f) * GROW_RENDER_GAIN + 1, + std::min((length + along) / GROW_RENDER_RANGE, 1.0f) * GROW_RENDER_GAIN + 1); + if (isScaled && tearFlags[TEAR_SHRINK]) + quad_widen(shown, startMiddle, endMiddle, + 1 - std::min(along / SHRINK_RENDER_RANGE, 1.0f) * SHRINK_RENDER_LOSS, + 1 - std::min((length + along) / SHRINK_RENDER_RANGE, 1.0f) * SHRINK_RENDER_LOSS); + beam_quad_draw(draw, beam_source(*frame, along, along + length, sprite.isFlipX), shown); + along += length; + } + + if (sprite.layerStates.size() < 2 || subtype != LASER_SUBTYPE_LINEAR) return; + const AnimationFrame* tipFrame = sprite.animState.GetLayerFrame(0); + if (!tipFrame) + { + KAGE_LogMessage(LOG_INFO, (uint8_t*)"[warn] Laser::Render current frame is NULL\n"); + return; + } + LayerState& tipLayer = sprite.layerStates[0]; + Vector direction = vector_normalized(vector_sub(samples[0], pos)); + float tipWidth = tipFrame->scale.x * tipLayer.size.x * sprite.scale.x * tipFrame->width * 0.5f; + Vector side = vector_scale(vector_make(direction.y, -direction.x), tipWidth); + Vector base = screen_point(vector_add(pos, vector_scale(direction, tipFrame->pos.y))); + Vector nudge = vector_scale(direction, TIP_STEP); + DestinationQuad tip = {vector_sub(base, side), vector_add(base, side), vector_add(quads[0]._topLeft, nudge), + vector_add(quads[0]._topRight, nudge)}; + BeamDraw tipDraw = {beam_color(*this, *tipFrame, isShadow), draw.offset, draw.image, &tipLayer, isShadow}; + float top = tipFrame->crop.y + TIP_TOP_INSET; + beam_quad_draw(tipDraw, beam_source(*tipFrame, top, tipFrame->crop.y + tipFrame->height, sprite.isFlipX), tip); +} + +// A straight beam: the thin, electric and tractor beams as one quad scrolled along their length, the thick ones as +// their start sprite and a body quad past it, the others as their sprite. +void Entity_Laser::render_straight(const Vector& offset, bool isShadow) +{ + Vector direction = vector_from_angle(angleDegrees); + Vector start = vector_add(pos, posOffset); + bool isThick = sprite.layerStates.size() >= 2 && (is_thick_variant() || variant == LASER_THIN_RED || + variant == LASER_LIGHT_BEAM || variant == LASER_LIGHT_RING); + BeamDraw draw = {COLOR_DEFAULT, vector_add(offset, g_game->screenShakeOffset), nullptr, nullptr, isShadow}; + + if (!isThick) + { + bool isQuad = variant == LASER_THIN_RED || variant == LASER_ELECTRIC || variant == LASER_TRACTOR_BEAM; + const AnimationFrame* frame = sprite.animState.GetLayerFrame(0); + if (!isQuad || !frame || !sprite.layerStates[0].spriteSheet) + { + sprite.Render({.position = renderPosition}); + return; + } + draw.color = beam_color(*this, *frame, isShadow); + draw.image = sprite.layerStates[0].spriteSheet.get(); + draw.layer = &sprite.layerStates[0]; + Vector side = vector_scale(vector_make(direction.y, -direction.x), frame->width * 0.5f); + Vector from = screen_point(start); + Vector to = screen_point(vector_add(start, vector_scale(direction, laserLength))); + float top = frame->crop.y; + beam_quad_draw(draw, beam_source(*frame, top, top + laserLength * LASER_SCREEN_SCALE, sprite.isFlipX), + {vector_sub(from, side), vector_add(from, side), vector_sub(to, side), vector_add(to, side)}); + return; + } + + float rotation = sprite.rotation; + if (sprite.isFlipX) sprite.rotation = -rotation; + sprite.RenderLayer(0, {.position = renderPosition}); + sprite.rotation = rotation; + if (laserLength <= STRAIGHT_TIP_MINIMUM) return; + + const AnimationFrame* tipFrame = sprite.animState.GetLayerFrame(0); + const AnimationFrame* frame = sprite.animState.GetLayerFrame(1); + if (!tipFrame || !frame || !sprite.layerStates[0].spriteSheet) + { + KAGE_LogMessage(LOG_INFO, (uint8_t*)"[warn] Laser::Render current frame is NULL\n"); + return; + } + LayerState& bodyLayer = sprite.layerStates[1]; + draw.color = beam_color(*this, *frame, isShadow); + draw.image = sprite.layerStates[0].spriteSheet.get(); + draw.layer = &bodyLayer; + float width = frame->scale.x * bodyLayer.size.x * sprite.scale.x * frame->width * 0.5f; + float height = frame->scale.y * bodyLayer.size.y * sprite.scale.y * frame->height; + Vector tipShift = vector_scale(direction, (tipFrame->pos.y + tipFrame->height) * sprite.scale.y); + float bodyLength = laserLength - tipFrame->height / LASER_SCREEN_SCALE * 0.5f; + Vector side = vector_scale(vector_make(direction.y, -direction.x), width); + Vector from = vector_add(screen_point(start), tipShift); + Vector to = vector_add(screen_point(vector_add(start, vector_scale(direction, bodyLength))), tipShift); + float top = frame->crop.y; + beam_quad_draw(draw, beam_source(*frame, top, top + laserLength / height * LASER_SCREEN_SCALE, sprite.isFlipX), + {vector_sub(from, side), vector_add(from, side), vector_sub(to, side), vector_add(to, side)}); +} + +// 009785d0 Draws the laser where it is on screen, its path or its straight beam, then runs the render callback. +void Entity_Laser::Render(const Vector& offset) +{ + if (!isVisible || sampleMode == SAMPLE_UNDECIDED || !sprite.isLoaded) return; + + renderPosition = vector_add(screen_point(vector_add(pos, posOffset)), offset); + if (!sprite.layerStates.empty() && !sprite.layerStates[0].spriteSheet) + { + KAGE_LogMessage(LOG_INFO, (uint8_t*)"[warn] Laser::Render sprite sheet is not loaded\n"); + return; + } + if (isSampleLaser) + render_path(offset, false); + else + render_straight(offset, false); + lua_engine_get().PostLaserRender(this, offset); +} + +// 0097ca90 A path laser's shadow: its beam in black at half on the floor. The original also clips it at the room's +// bottom wall. +bool Entity_Laser::RenderShadowLayer(const Vector& offset) +{ + if (!isVisible || !isSampleLaser) return false; + render_path(offset, true); + return true; +} + +// 0097eb50 The debug display of the laser's hit area (debug flag 6) is not reconstructed yet. +void Entity_Laser::PostRender() +{ + constexpr uint32_t DEBUG_HIT_AREA = 1 << 5; + if ((g_game->debugFlags & DEBUG_HIT_AREA) && size > 0 && entityCollisionClass != ENTCOLL_NONE && + sampleMode != SAMPLE_UNDECIDED) + reconstruction_missing("Entity_Laser::PostRender 0097eb50: the hit area's debug lines"); +} diff --git a/src/entity_npc.cpp b/src/entity_npc.cpp index c658eea..9fea327 100644 --- a/src/entity_npc.cpp +++ b/src/entity_npc.cpp @@ -152,7 +152,6 @@ constexpr int TRINKET_ICE_CUBE_ID = 188; constexpr int TRINKET_DEVILS_CROWN_ID = 185; constexpr int NULLITEM_DAMOCLES_WEAKNESS = 64; -constexpr int CHALLENGE_ULTRA_HARD = 34; constexpr int CHALLENGE_BEANS = 30; constexpr int CHALLENGE_SLOW = 22; constexpr int ACHIEVEMENT_BOSS_COLORS = 3; @@ -186,9 +185,7 @@ constexpr unsigned int STATUS_SHARED = 1u << 31; constexpr int TYPE_SPRITE_FLAG_A = 950; constexpr int TYPE_SPRITE_FLAG_B = 960; constexpr int VARIANT_SPRITE_FLAG_B = 4; -constexpr std::string_view CHAMPION_SUFFIX = "_champion"; constexpr std::string_view STATUS_EFFECTS_ANM2 = "gfx/StatusEffects.anm2"; -constexpr size_t SHEET_EXTENSION_SIZE = 4; // The target search: how far enemies look for players, and what pushes a player back or pulls a twin forward. constexpr float TARGET_RANGE = 5000; @@ -229,9 +226,6 @@ constexpr float SPEED_HALF = 0.5f; constexpr float SPEED_WEAKENED = 0.65f; constexpr float SPEED_VANISHING_TWIN = 0.75f; -// The champion color looks, sprite color, HP multiplier and scale, that the exe keeps at 00c354c0. -const ColorMod* champion_color_get(int championColor); - // 0043ef30 Shoots one plain shot at a random circle angle. ProjectileParams::ProjectileParams() : circleAngle(random_unit() * PI_F) {} @@ -679,8 +673,8 @@ void Entity_NPC::LoadEntityConfig() // 006b9c10 A layer's sheet with the champion suffix and the stage's floor suffix put before its extension, the first // of (both, champion only, floor only) a mod or the resources hold, else the sheet itself. isChampionSheet says // whether the one found has the champion suffix. -static std::string sheet_path_resolve(const std::string& path, std::string_view floorSuffix, - std::string_view championSuffix, bool& isChampionSheet) +std::string sheet_path_resolve(const std::string& path, std::string_view floorSuffix, std::string_view championSuffix, + bool& isChampionSheet) { isChampionSheet = false; if (path.size() < SHEET_EXTENSION_SIZE || (floorSuffix.empty() && championSuffix.empty())) return path; @@ -2933,11 +2927,6 @@ void Entity_NPC::UpdatePickupGhosts() if (pickupGhostsEntity) pickupGhostsEntity->Remove(); } -// 0096ce90 -void Entity_NPC::SetAimAngle(float) -{ - reconstruction_missing("Entity_NPC::SetAimAngle 0096ce90"); -} // 009a8b90 void Entity_NPC::render_debug(float*, int) diff --git a/src/entity_npc.h b/src/entity_npc.h index 3974cec..befe81d 100644 --- a/src/entity_npc.h +++ b/src/entity_npc.h @@ -342,7 +342,6 @@ struct Entity_NPC : Entity void TransferControl(Entity_NPC* target); void SpawnControlTarget(int inputMode, float rotation); Vector GetAimTargetPosition(); - void SetAimAngle(float angle); void UpdateChargeBar(float start, float end, float value, bool isHideWhenFull); void UpdatePickupGhosts(); @@ -385,4 +384,11 @@ void game_shake_screen(int timeout); bool game_is_hard_mode(); uint32_t room_grid_collision_at(const Vector& position); ColorMod champion_sprite_color_get(int championColor); +const ColorMod* champion_color_get(int championColor); + +// A sheet's ".png", which the champion and floor suffixes go before, and the version of a sheet with them that exists. +constexpr size_t SHEET_EXTENSION_SIZE = 4; +constexpr std::string_view CHAMPION_SUFFIX = "_champion"; +std::string sheet_path_resolve(const std::string& path, std::string_view floorSuffix, std::string_view championSuffix, + bool& isChampionSheet); bool room_check_line(const Vector& start, const Vector& end, int mode, int gridPathThreshold); diff --git a/src/entity_npc_boss.cpp b/src/entity_npc_boss.cpp index 8e81477..dcfc6d1 100644 --- a/src/entity_npc_boss.cpp +++ b/src/entity_npc_boss.cpp @@ -5,6 +5,9 @@ #include "manager.h" #include "room_grid.h" #include "sfx_manager.h" +#include "data.h" +#include "room_config.h" +#include "room_descriptor.h" #include constexpr float BOSS_SHOT_SPEED = 7; @@ -19,6 +22,8 @@ constexpr float BOSS_SHOT_SCALE_SPREAD = 0.05f; constexpr float WEAKNESS_SHOT_SCALE = 0.8f; constexpr int SHRINKING_SHOT_DURATION = -150; +constexpr int GROUND_POOF_SUBTYPE = 1; +constexpr int GROUND_POOF_CLOUD_SUBTYPE = 2; constexpr int BLOOD_POOF_SUBTYPE = 3; constexpr int BLOOD_POOF_SPRAY_SUBTYPE = 4; constexpr int BLOOD_CLOUD_SUBTYPE = 5; @@ -43,6 +48,25 @@ static Entity_Effect* tinted_poof_spawn(Entity* spawner, int subType, const Vect return effect; } +// 006b6550 A ground poof at a position with its dust cloud above, the cloud its child. Returns the poof. +Entity_Effect* Entity::MakeGroundPoof(const Vector& position, const ColorMod& poofColor, float poofSize) +{ + Entity_Effect* poof = tinted_poof_spawn(this, GROUND_POOF_SUBTYPE, position, poofColor, poofSize); + poof->Update(); + + Entity_Effect* cloud = tinted_poof_spawn(this, GROUND_POOF_CLOUD_SUBTYPE, position, poofColor, poofSize); + cloud->posOffset = vector_make(0, poofSize * BLOOD_POOF_SPRAY_HEIGHT); + cloud->Update(); + poof->child = cloud; + return poof; +} + +// 006b66a0 A ground poof where it stands. +Entity_Effect* Entity::MakeGroundPoofAtSelf(const ColorMod& poofColor, float poofSize) +{ + return MakeGroundPoof(pos, poofColor, poofSize); +} + // 006b66c0 A blood poof at a position with its spray above, the spray its child. Returns the poof. Entity_Effect* Entity::MakeBloodPoof(const Vector& position, const ColorMod& poofColor, float scale) { @@ -305,3 +329,40 @@ void boss_appear_events(Entity_NPC& npc) return; } } + +// 0060b890 Entity::SpawnFollowingEffect198: a tracer following its parent, only in an online session and outside the +// 1x1 and narrow rooms. Null when it spawns none. +Entity_Effect* following_effect_spawn(Entity& parent, const FollowingEffect& effect) +{ + int shape = g_game->room->GetRoomShape(); + if (!g_manager->netplayManager.is_online() || !g_game->room->descriptor || !g_game->room->descriptor->data || + shape == ROOMSHAPE_1x1 || shape == ROOMSHAPE_IH || shape == ROOMSHAPE_IV) + return nullptr; + + auto* tracer = static_cast(g_game->Spawn({.position = vector_add(parent.pos, effect.offset), + .type = ENTITY_EFFECT, + .variant = EFFECT_GENERIC_TRACER, + .seed = Random()})); + if (!tracer) return nullptr; + tracer->FollowParent(&parent); + tracer->sprite.color = effect.color; + tracer->sprite.scale = vector_make(effect.scale, effect.scale); + tracer->timeout = effect.timeout; + tracer->lifespan = effect.timeout; + tracer->targetPosition = effect.targetPosition; + tracer->Update(); + return tracer; +} + +// 006ba840 A sheet path with its boss color's (else its floor's) suffix and its champion suffix put before the +// extension: the first of both, the champion one and the floor one that exists, else the path itself. +std::string npc_sheet_path_get(Entity_NPC& npc, const std::string& path) +{ + std::string floorSuffix; + int color = npc.bosscoloridx; + if (color >= 0 && color < (int)npc.config->bossColors.size()) floorSuffix = npc.config->bossColors[color].suffix; + else if (npc.config->isHasFloorAlts) floorSuffix = g_game->roomConfig.stages[Level::GetStageID()].suffix; + std::string_view championSuffix = npc.isChampion && champion_color_get(npc.championColorIdx) ? CHAMPION_SUFFIX : ""; + bool isChampionSheet = false; + return sheet_path_resolve(path, floorSuffix, championSuffix, isChampionSheet); +} diff --git a/src/entity_pickup.cpp b/src/entity_pickup.cpp index b6e6c7b..d386c3a 100644 --- a/src/entity_pickup.cpp +++ b/src/entity_pickup.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include // The chest variants (chest, locked, red, bomb, eternal, spiked, mimic, mom's, old, wooden, mega, haunted). @@ -85,8 +86,6 @@ constexpr int COLLECTIBLE_MITRE = 173; constexpr std::array PENNY_TRINKETS = {TRINKET_BLOODY_PENNY, TRINKET_BURNT_PENNY, TRINKET_FLAT_PENNY, TRINKET_COUNTERFEIT_PENNY, TRINKET_BLESSED_PENNY, TRINKET_CHARGED_PENNY, TRINKET_CURSED_PENNY, (int)TRINKET_BUTT_PENNY, TRINKET_ROTTEN_PENNY}; -constexpr int CHALLENGE_APRILS_FOOL = 32; -constexpr int CHALLENGE_ULTRA_HARD = 34; constexpr int SPECIAL_DAILY_NICKELS = 7; // Achievement 33 unlocks both the half soul heart and the micro battery. constexpr int ACHIEVEMENT_HALF_SOUL_HEART = 33; @@ -184,6 +183,17 @@ constexpr uint32_t ROLL_SHIFT = 7; constexpr uint32_t DAEMONS_TAIL_SHIFT = 47; constexpr uint32_t KEEPER_FLIES_SHIFT = 19; +// Nuh Uh!'s reroll weights (nothing for a coin, a bomb or heart, a pill or card, a trinket or battery), and the +// percent chance per extra copy that its heart or bomb comes doubled. +constexpr int NUH_UH_COMMON_WEIGHT = 8; +constexpr int NUH_UH_POCKET_WEIGHT = 5; +constexpr int NUH_UH_RARE_WEIGHT = 2; +constexpr int NUH_UH_DOUBLE_PERCENT = 10; +constexpr int NUH_UH_MAX_MULTIPLIER = 3; +constexpr uint32_t NUH_UH_ROLL = 100; +// A card subtype Cantripped keeps as it is. +constexpr int CANTRIPPED_KEPT_FLAG = 0x8000; + // The chance denominators of the pickup subtypes, as "one in N". constexpr int ODDS_HALF_HEART = 2; constexpr int ODDS_DOUBLE_HEART = 20; @@ -390,6 +400,24 @@ static void random_variant_pick(PickupChoice& choice, uint32_t firstSeed) } // A heart's kind, each later chance overriding the earlier ones, and the one a super secret room layout holds. +// The heart a super secret room's layout (its subtype) gives, Greed mode's rooms their own, or 0 to keep the one +// drawn. The Rotten Heart's room gives one once it is unlocked. +static int super_secret_heart_get() +{ + using LayoutHeart = std::pair; + constexpr LayoutHeart HEARTS[] = {{0, HEART_FULL}, {1, HEART_ETERNAL}, {6, HEART_BLACK}, {12, HEART_SOUL}, + {13, HEART_BLACK}, {16, HEART_ETERNAL}, {23, HEART_ROTTEN}}; + constexpr LayoutHeart GREED_HEARTS[] = { + {0, HEART_FULL}, {4, HEART_SOUL}, {5, HEART_BLACK}, {24, HEART_ETERNAL}, {25, HEART_HALF}}; + + bool isGreed = g_game->IsGreedMode(); + int layout = g_game->GetCurrentRoomDesc()->data->subtype; + std::span hearts = isGreed ? std::span(GREED_HEARTS) : HEARTS; + for (auto [room, heart] : hearts) + if (room == layout) return heart == HEART_ROTTEN && !is_unlocked(ACHIEVEMENT_ROTTEN_HEART) ? 0 : heart; + return 0; +} + static void heart_subtype_pick(PickupChoice& choice, RNG& rng) { PlayerManager& players = g_game->playerManager; @@ -439,8 +467,9 @@ static void heart_subtype_pick(PickupChoice& choice, RNG& rng) kind = HEART_BLACK; } - if (g_game->room->roomType == ROOM_SUPERSECRET) - reconstruction_missing("Pickup_PickVariant 006ddcd0: a super secret room's heart"); + int secretHeart = g_game->room->roomType == ROOM_SUPERSECRET ? super_secret_heart_get() : 0; + if (secretHeart) choice.subType = secretHeart; + if (secretHeart && secretHeart != HEART_HALF) return; if (choice.subType == HEART_HALF && players.AnyoneHasTrinket(TRINKET_MOMS_LOCKET)) choice.subType = HEART_FULL; } @@ -561,10 +590,43 @@ static void battery_subtype_pick(PickupChoice& choice, RNG& rng) else if (rng_chance(rng, ODDS_GOLDEN_BATTERY) && is_unlocked(ACHIEVEMENT_GOLDEN_BATTERY)) choice.subType = 4; } +// DELETE THIS turns items (but quest items) into trinkets, or cards or pills once the trinkets run out, and +// Cantripped turns them into cards. Cantripped's pills, batteries and cards are cards it picks itself. +static void challenge_pickups_apply(PickupChoice& choice, RNG& rng, bool isLittleBaggy) +{ + int& variant = choice.variant; + int& kind = choice.subType; + int challenge = g_game->challenge; + bool isItem = !g_pickupIgnoreModifiers && variant == PICKUP_COLLECTIBLE && !ItemConfig::IsQuestItem(kind); + + if (challenge == CHALLENGE_PICA_RUN && isItem) + { + variant = PICKUP_TRINKET; + kind = (int)g_game->itemPool.GetTrinket(choice.draw == POOL_DRAW_TAKE ? TRINKET_DRAW_TAKE : TRINKET_DRAW_PEEK); + if (kind != 0) return; + + variant = PICKUP_TAROTCARD; + kind = card_draw(rng); + if (!isLittleBaggy) return; + variant = PICKUP_PILL; + kind = ItemPool::GetPill(rng.Next()); + return; + } + if (challenge != CHALLENGE_CANTRIPPED) return; + + if (isItem) + { + variant = PICKUP_TAROTCARD; + kind = 0; + } + if (variant == PICKUP_TAROTCARD && !(kind & CANTRIPPED_KEPT_FLAG)) kind = 0; + if (is_listed({PICKUP_TAROTCARD, PICKUP_PILL, PICKUP_LIL_BATTERY}, variant)) variant = PICKUP_TAROTCARD; +} + // What the run's items and challenges change in the kind: Humbleing Bundle and BOGO Bombs double, Scat Man turns // hearts into coins, Cantripped and DELETE THIS turn pocket items and items into cards and trinkets, and Tainted // ???'s bombs are poops. -static void choice_modifiers_apply(PickupChoice& choice) +static void choice_modifiers_apply(PickupChoice& choice, RNG& rng, bool isLittleBaggy) { int& variant = choice.variant; int& kind = choice.subType; @@ -586,8 +648,7 @@ static void choice_modifiers_apply(PickupChoice& choice) variant = PICKUP_COIN; kind = kind == HEART_FULL ? COIN_DOUBLEPACK : kind == HEART_DOUBLEPACK ? COIN_NICKEL : COIN_PENNY; } - if (g_game->challenge == CHALLENGE_PICA_RUN || g_game->challenge == CHALLENGE_CANTRIPPED) - reconstruction_missing("Pickup_PickVariant 006ddcd0: DELETE THIS and Cantripped's pickups"); + challenge_pickups_apply(choice, rng, isLittleBaggy); bool isPoopBomb = variant == PICKUP_BOMB && g_game->playerManager.are_all_players_tainted_blue_baby() && !is_listed({BOMB_TROLL, BOMB_SUPERTROLL, BOMB_GOLDENTROLL}, kind); @@ -598,6 +659,41 @@ static void choice_modifiers_apply(PickupChoice& choice) } } +// Nuh Uh!'s reroll of a coin or key: a bomb, heart, pill, card, trinket or battery, or for a coin nothing (which +// a shop keeps as variant 0). A gold or doubled Nuh Uh! may double the heart or bomb. The new pickup is chosen from +// the next seed. Whether anything is left. +static bool nuh_uh_reroll(PickupChoice& choice, RNG& rng) +{ + int nothingWeight = choice.variant == PICKUP_COIN ? NUH_UH_COMMON_WEIGHT : 0; + choice.variant = weighted_pick({{0, nothingWeight}, + {PICKUP_BOMB, NUH_UH_COMMON_WEIGHT}, + {PICKUP_HEART, NUH_UH_COMMON_WEIGHT}, + {PICKUP_PILL, NUH_UH_POCKET_WEIGHT}, + {PICKUP_TAROTCARD, NUH_UH_POCKET_WEIGHT}, + {PICKUP_TRINKET, NUH_UH_RARE_WEIGHT}, + {PICKUP_LIL_BATTERY, NUH_UH_RARE_WEIGHT}}, + rng_make(rng.Next(), PICKUP_RNG_SHIFT)); + if (choice.variant == 0) return choice.sale == PICKUP_FOR_SALE; + + choice.subType = 0; + Entity_Player* owner = g_game->playerManager.FirstTrinketOwner(TRINKET_NUH_UH); + int multiplier = owner ? owner->GetTrinketMultiplier(TRINKET_NUH_UH) : 0; + bool isDoubling = multiplier > 1 && multiplier <= NUH_UH_MAX_MULTIPLIER; + int doubleChance = (multiplier - 1) * NUH_UH_DOUBLE_PERCENT; + if (isDoubling && (int)owner->GetTrinketRNG(TRINKET_NUH_UH).RandomInt(NUH_UH_ROLL) < doubleChance) + { + if (choice.variant == PICKUP_HEART) choice.subType = HEART_DOUBLEPACK; + else if (choice.variant == PICKUP_BOMB) choice.subType = BOMB_DOUBLEPACK; + } + + PickupChoice reroll = choice; + reroll.seed = rng.Next(); + pickup_variant_pick(reroll); + choice.variant = reroll.variant; + choice.subType = reroll.subType; + return true; +} + // 006ddcd0 Chooses a pickup's variant and subtype where they are 0: a random variant by weight, then a subtype per // variant, then the run's modifiers. A sale for a party of Keepers swaps hearts for keys or bombs. bool pickup_variant_pick(PickupChoice& choice) @@ -695,13 +791,17 @@ bool pickup_variant_pick(PickupChoice& choice) log_printf(LOG_INFO, "[warn] Pickup variant %d not implemented yet!\n", choice.variant); break; } - choice_modifiers_apply(choice); + choice_modifiers_apply(choice, rng, isLittleBaggy); bool isNuhUhVariant = choice.variant == PICKUP_COIN || choice.variant == PICKUP_KEY; bool isGreed = g_game->difficulty == DIFFICULTY_GREED || g_game->difficulty == DIFFICULTY_GREEDIER; if (isNuhUhVariant && !isGreed && g_game->stage >= 7 && !g_pickupIgnoreModifiers && pickDepth <= 1 && - anyone_has_trinket(TRINKET_NUH_UH)) - reconstruction_missing("Pickup_PickVariant 006ddcd0: Nuh Uh!'s reroll"); + anyone_has_trinket(TRINKET_NUH_UH) && !nuh_uh_reroll(choice, rng)) + { + pickDepth--; + choice.variant = -1; + return false; + } if (choice.sale == PICKUP_FOR_SALE) { diff --git a/src/entity_player.cpp b/src/entity_player.cpp index 5e1e252..323bfa8 100644 --- a/src/entity_player.cpp +++ b/src/entity_player.cpp @@ -18,7 +18,6 @@ constexpr float PLAYER_START_TEAR_FALLING_SPEED = 0.2f; constexpr float PLAYER_START_TEAR_RANGE = 260; constexpr float ROCK_BOTTOM_LUCK_UNSET = -9999; constexpr int COSTUME_RESERVE = 32; -constexpr int FORGOTTEN_BODY_ROOM_NONE = -99999; constexpr int MAX_PEE_BURST_COOLDOWN = 30; constexpr int MONKEY_PAW_USES = 3; constexpr int PLAYER_RENDER_Z_OFFSET = 5; @@ -696,6 +695,44 @@ void Entity_Player::eden_stats_roll(RNG& rng) edenLuck = rng.RandomFloat() * 2 - 1; } +// The part of 007bc740 that rolls Eden's starting pickups and items: a trinket on a third of the rolls, else maybe a +// card or a pill, then the first active and the first passive among 100 random collectibles Eden may start with. +void Entity_Player::eden_items_roll(RNG& rng) +{ + constexpr int EDEN_ITEM_ROLLS = 100; + constexpr std::array REMOVED_COLLECTIBLES = {235, 43, 61}; + ItemConfig& items = g_manager->itemConfig; + ItemPool& pool = g_game->itemPool; + + if (rng.Next() % 3 == 0) AddTrinket((int)pool.GetTrinket(TRINKET_DRAW_TAKE), true); + else if ((rng.Next() & 1) == 0) + { + if ((rng.Next() & 1) == 0) AddPocketItem(card_roll(rng.Next(), 0, false), POCKET_CARD); + else AddPocketItem(ItemPool::GetPill(rng.Next()), POCKET_PILL); + } + + int active = 0; + int passive = 0; + uint32_t range = (uint32_t)items.collectibles.size() - 1; + for (int roll = 0; roll < EDEN_ITEM_ROLLS; roll++) + { + uint32_t next = rng.Next(); + int id = (int)(range == 0 ? 0 : next % range) + 1; + ItemConfig_Item* item = items.GetCollectible(id); + if (std::ranges::find(REMOVED_COLLECTIBLES, id) != REMOVED_COLLECTIBLES.end() || !item || item->HasTags(TAG_NO_EDEN) || + !item->IsAvailableEx(AVAILABLE_ALL)) + continue; + int& kept = item->type == ITEM_ACTIVE ? active : passive; + if (kept == 0) kept = id; + } + for (int id : {active, passive}) + if (id != 0) + { + AddCollectible(id, -1, true, 0, 0); + pool.RemoveCollectible(id, REMOVE_ANY, REMOVE_APPLY); + } +} + // Gives the player a starting collectible, as the run's start does: added as picked up, out of the pools, and its // temporary effect gone. void Entity_Player::starting_collectible_add(int id) @@ -744,7 +781,7 @@ void Entity_Player::InitPostLevelInitStats() else if (playerConfig->pill > 0) AddPocketItem(playerConfig->pill, POCKET_PILL); else if (playerConfig->pill < 0) AddPocketItem(ItemPool::GetPill(initSeed), POCKET_PILL); else if (playerType == PLAYER_MAGDALENE && is_run_unlocked(ACHIEVEMENT_MAGDALENE_HOLDS_A_PILL)) - reconstruction_missing("Entity_Player::InitPostLevelInitStats 007bc740 (Magdalene's starting pill)"); + magdalene_pill_add(); std::vector items = playerConfig->collectibles; if (game.challenge == 0) @@ -782,7 +819,7 @@ void Entity_Player::InitPostLevelInitStats() if ((playerConfig->id == PLAYER_EDEN || playerConfig->id == TAINTED_EDEN_PLAYER_ID) && !game.deathmatchManager.is_active()) - reconstruction_missing("Entity_Player::InitPostLevelInitStats 007bc740 (Eden's rolled items)"); + eden_items_roll(rng); if (challenge.isMegaSatan) { starting_collectible_add(COLLECTIBLE_KEY_PIECE_1); diff --git a/src/entity_player.h b/src/entity_player.h index 013fe94..451f106 100644 --- a/src/entity_player.h +++ b/src/entity_player.h @@ -17,18 +17,22 @@ #include #include +struct DeliriousBoss; + constexpr int ACTIVE_SLOT_COUNT = 4; constexpr int BAG_OF_CRAFTING_SIZE = 8; constexpr int CHARGE_BAR_COUNT = 7; constexpr int COLLECTIBLE_VANILLA_COUNT = 733; constexpr int COOP_BABY_BUFF_COUNT = 8; constexpr int COSTUME_LAYER_COUNT = 15; +constexpr int FORGOTTEN_BODY_ROOM_NONE = -99999; constexpr int HUD_HEART_FLASH_FRAMES = 4; constexpr int INVENTORY_SIZE = 16; constexpr int POCKET_SLOT_COUNT = 4; constexpr int POOP_SPELL_QUEUE_SIZE = 6; constexpr int TRINKET_SLOT_COUNT = 2; constexpr int WEAPON_SLOT_COUNT = 5; +constexpr uint32_t QUEUED_TOUCHED = 0x1; constexpr uint32_t QUEUED_GOLDEN = 0x2; constexpr uint32_t TRINKET_GOLDEN_FLAG = 0x8000; constexpr uint8_t WILD_CARD_NONE = 0xff; @@ -233,6 +237,7 @@ enum PlayerItemId : int COLLECTIBLE_HOLY_WATER = 178, COLLECTIBLE_WHITE_PONY = 181, COLLECTIBLE_SACRED_HEART = 182, + COLLECTIBLE_BLOOD_RIGHTS = 186, COLLECTIBLE_3_DOLLAR_BILL = 191, COLLECTIBLE_MOMS_KEY = 199, COLLECTIBLE_MIDAS_TOUCH = 202, @@ -250,6 +255,7 @@ enum PlayerItemId : int COLLECTIBLE_KEY_PIECE_1 = 238, COLLECTIBLE_KEY_PIECE_2 = 239, COLLECTIBLE_INFAMY = 242, + COLLECTIBLE_20_20 = 245, COLLECTIBLE_BLUE_MAP = 246, COLLECTIBLE_BFFS = 247, COLLECTIBLE_STARTER_DECK = 251, @@ -280,6 +286,7 @@ enum PlayerItemId : int COLLECTIBLE_NEGATIVE = 328, COLLECTIBLE_LUDOVICO = 329, COLLECTIBLE_SOY_MILK = 330, + COLLECTIBLE_LAZARUS_RAGS = 332, COLLECTIBLE_MIND = 333, COLLECTIBLE_BOOMERANG = 338, COLLECTIBLE_WOODEN_NICKEL = 349, @@ -321,7 +328,9 @@ enum PlayerItemId : int COLLECTIBLE_WAIT_WHAT = 484, COLLECTIBLE_METRONOME = 488, COLLECTIBLE_DEEP_POCKETS = 416, + COLLECTIBLE_PLAN_C = 475, COLLECTIBLE_DUALITY = 498, + COLLECTIBLE_EUCHARIST = 499, COLLECTIBLE_GREEDS_GULLET = 501, COLLECTIBLE_LITTLE_HORN = 503, COLLECTIBLE_BROKEN_MODEM = 514, @@ -347,6 +356,7 @@ enum PlayerItemId : int COLLECTIBLE_SOL = 588, COLLECTIBLE_LUNA = 589, COLLECTIBLE_URANUS = 596, + COLLECTIBLE_ACT_OF_CONTRITION = 601, COLLECTIBLE_MOMS_BRACELET = 604, COLLECTIBLE_ETERNAL_D6 = 609, COLLECTIBLE_LARYNX = 611, @@ -424,6 +434,7 @@ enum PlayerItemId : int TRINKET_SAFETY_CAP = 44, TRINKET_ACE_OF_SPADES = 45, TRINKET_POKER_CHIP = 76, + TRINKET_SECOND_HAND = 78, TRINKET_MOMS_LOCKET = 87, TRINKET_CURSED_SKULL = 43, TRINKET_MISSING_PAGE = 48, @@ -475,6 +486,7 @@ enum PlayerItemId : int TRINKET_MODELING_CLAY = 166, TRINKET_HOLLOW_HEART = 168, TRINKET_YOUR_SOUL = 173, + TRINKET_NUMBER_MAGNET = 174, TRINKET_STRANGE_KEY = 175, TRINKET_RC_REMOTE = 179, TRINKET_FOUND_SOUL = 180, @@ -484,6 +496,7 @@ enum PlayerItemId : int NULLITEM_BLINDFOLD = 14, NULLITEM_BLANKFACE = 15, NULLITEM_CHRISTMAS = 16, + NULLITEM_LAZARUS_BOOST = 49, NULLITEM_SPIN_TO_WIN = 50, NULLITEM_INTRUDER = 55, NULLITEM_TOOTH_AND_NAIL_STATUE = 59, @@ -504,6 +517,8 @@ enum PlayerItemId : int NULLITEM_SOUL_JACOB = 121, NULLITEM_JUDAS_BIRTHRIGHT_STAGE = 129, + PILLEFFECT_FULL_HEALTH = 5, + PILLEFFECT_HEALTH_UP = 7, PILLEFFECT_TELEPILLS = 19 }; @@ -524,6 +539,7 @@ enum PlayerAchievement : int ACHIEVEMENT_MAGDALENE_HOLDS_A_PILL = 332, ACHIEVEMENT_SAMSON_HOLDS_CHILDS_HEART = 334, ACHIEVEMENT_TEARS_UP_ITEMS = 378, + ACHIEVEMENT_MYSTERY_EGG = 387, ACHIEVEMENT_GOLDEN_RAZOR = 583 }; @@ -534,6 +550,8 @@ enum PlayerChallenge : int CHALLENGE_GUARDIAN = 30, CHALLENGE_PONG = 30, CHALLENGE_BACKASSWARDS = 31, + CHALLENGE_APRILS_FOOL = 32, + CHALLENGE_ULTRA_HARD = 34, CHALLENGE_BLOODY_MARY = 37, CHALLENGE_BAPTISM_BY_FIRE = 38, CHALLENGE_PICA_RUN = 41, @@ -609,6 +627,13 @@ struct CostumeSpriteDesc bool isOverwriteColor = false; }; +// The skin colors the worn costumes leave the player's head and body. +struct SkinColors +{ + int body = -1; + int head = -1; +}; + // The copies of a trinket smelted into the player, plain and golden. struct SmeltedTrinket { @@ -1098,6 +1123,10 @@ public: static PosVel GetMultiShotPositionVelocity(int loopIndex, WeaponType weaponType, const Vector& shotDirection, float shotSpeed, const Weapon_MultiShotParams& params); Vector GetTearMovementInheritance(const Vector& shotDirection, InheritMode mode); + Vector GetCostumeNullPos(std::string_view nullName, bool isHeadScale, const Vector& direction); + Vector GetLaserOffset(int laserOffsetId, const Vector& direction); + Entity_Laser* FireTechLaser(const TechLaserShot& shot); + Entity_Laser* FireBrimstone(const Vector& direction, Entity* source, float damageMultiplier); Vector delayed_shoot_direction(); void ClearReferences() override; @@ -1120,8 +1149,13 @@ public: void costume_layers_update(); float body_costumes_walk(const CostumeWalk& walk); void body_costumes_speed_set(float speed); - void costume_layers_map(int skinColor); + void costume_layers_map(SkinColors& colors); void costume_skin_apply(CostumeSpriteDesc& costume, int skinColor); + void skin_recolor(const SkinColors& colors); + void eden_hair_apply(ANM2& hair); + void coop_indicator_render(); + void collectible_revive(int collectible, bool isOwner); + void forgotten_halves_hearts_move(); int AddActiveCharge(int charge, int slot, bool isFlashHud, bool isOvercharge, bool isForce); void RemoveCollectible(int type, bool isIgnoreModifiers, int activeSlot, bool isRemoveFromForm); Entity_Familiar* AddWisp(int collectible, Vector position, bool isAdjustOrbitLayer, bool isDontUpdate); @@ -1137,6 +1171,8 @@ private: void sprites_load(); void links_reset(); void eden_stats_roll(RNG& rng); + void eden_items_roll(RNG& rng); + void magdalene_pill_add(); std::optional collectible_lent(int collectibleType, ItemConfig_Item& item); std::optional trinket_lent(uint32_t id, int multiplier); int trinket_bonus(uint32_t id, int multiplier); @@ -1197,7 +1233,7 @@ public: Entity_Familiar* AddItemWisp(int collectibleId, Vector position, bool isAdjustOrbitLayer); void trigger_book_of_belial_passive(int activeId, int charges); void TriggerBookOfVirtues(int collectibleId, int charge); - void console_spawn(int* spawnSpec, bool isAddWisp); + void console_spawn(const DeliriousBoss& boss, bool isAddWisp); void update_mini_mush_costume(); void ResetDamageCooldown(); Vector SpriteScale(); @@ -1318,6 +1354,7 @@ public: void AnimatePitfallOut(); void AnimateAppear(); void AnimateTeleport(bool isUp); + void Teleport(const Vector& position, bool isDoEffects, bool isTeleportTwinPlayers); void AnimateHappy(); void AnimateSad(); void AddPrettyFly(); diff --git a/src/entity_player_actives.cpp b/src/entity_player_actives.cpp index 0b0ab2e..eadc794 100644 --- a/src/entity_player_actives.cpp +++ b/src/entity_player_actives.cpp @@ -1,4 +1,5 @@ #include "entity_player.h" +#include "entity_player_characters.h" #include "active_items.h" #include "entity_bomb.h" #include "entity_pickup.h" @@ -102,7 +103,6 @@ enum BatterySubType : int // The kinds of poop The Poop drops (Lua's GridPoopVariant). constexpr int ACHIEVEMENT_HALO = 27; -constexpr int CHALLENGE_APRILS_FOOL = 32; constexpr int ACTIVE_PICKUP_HOLD_FRAMES = 30; constexpr int BATTERY_CHARGE = 6; constexpr int BATTERY_MICRO_CHARGE = 2; @@ -1276,13 +1276,10 @@ static void active_trigger(Entity_Player& player, int slot) void Entity_Player::ControlActiveItem(int slot) { if (variant == PLAYER_VARIANT_COOP_BABY || isCoopGhost || IsHologram() || playerType == PLAYER_THESOUL_B) return; - if (playerType == PLAYER_JACOB || playerType == PLAYER_ESAU) - reconstruction_missing("Entity_Player::ControlActiveItem 00791a40 (Jacob and Esau's shared item button)"); - - ButtonAction action = slot != ACTIVE_SLOT_PRIMARY ? ACTION_PILL_CARD : ACTION_ITEM; + ButtonAction action = slot != ACTIVE_SLOT_PRIMARY ? ACTION_PILL_CARD : twin_button_action(*this, TWIN_BUTTON_ITEM); bool isPressed = input_is_action_pressed(action, controllerIndex, this); bool isTriggered = input_is_action_triggered(action, controllerIndex, this); - if (HasEntityFlags(FLAG_FEAR) || hasCurseMistEffect || isCoopGhost) + if (is_twin_button_blocked(*this, TWIN_BUTTON_ITEM) || HasEntityFlags(FLAG_FEAR) || hasCurseMistEffect || isCoopGhost) { isPressed = false; isTriggered = false; @@ -1314,8 +1311,9 @@ void Entity_Player::ControlActiveItem(int slot) if (slot == ACTIVE_SLOT_PRIMARY) bulbs_update(*this, chargeBefore, slot); } -// The actives whose temporary effect the plain frame, stats and tears are written for: the first floor's actives that -// leave one. Book of Belial and Razor Blade change the damage and tears, which are not written for effects yet. +// The temporary effects the plain frame, stats and tears are written for: the first floor's actives that leave one, +// Whore of Babylon and Tainted Eve's, Dead Bird, Bloody Lust and Bloody Gust, and Lazarus' boost. Book of Belial and +// Razor Blade change the damage and tears, which are not written for effects yet. bool is_temporary_effect_plain(const TemporaryEffect& effect) { constexpr int PLAIN_EFFECT_ITEMS[] = {COLLECTIBLE_BIBLE, @@ -1330,8 +1328,14 @@ bool is_temporary_effect_plain(const TemporaryEffect& effect) COLLECTIBLE_BOOK_OF_REVELATIONS, COLLECTIBLE_D6, COLLECTIBLE_SPIDER_BUTT, - COLLECTIBLE_ETERNAL_D6}; + COLLECTIBLE_ETERNAL_D6, + COLLECTIBLE_WHORE_OF_BABYLON, + COLLECTIBLE_DEAD_BIRD, + COLLECTIBLE_BLOODY_LUST, + COLLECTIBLE_BLOODY_GUST}; + if (effect.item->type == ITEM_NULL) + return effect.item->id == NULLITEM_LAZARUS_BOOST || effect.item->id == NULLITEM_BLOODY_BABYLON; return effect.item->IsCollectible() && std::ranges::find(PLAIN_EFFECT_ITEMS, effect.item->id) != std::end(PLAIN_EFFECT_ITEMS); } diff --git a/src/entity_player_characters.cpp b/src/entity_player_characters.cpp new file mode 100644 index 0000000..c007f71 --- /dev/null +++ b/src/entity_player_characters.cpp @@ -0,0 +1,1007 @@ +#include "entity_player_characters.h" +#include "entity_effect.h" +#include "entity_familiar.h" +#include "game.h" +#include "hud.h" +#include "item_overlay.h" +#include "item_pool.h" +#include "manager.h" +#include "menu_manager.h" +#include "npc_ai.h" +#include "player_manager.h" +#include "room.h" +#include "room_config.h" +#include "room_descriptor.h" +#include "room_grid.h" +#include +#include +#include + +constexpr uint32_t CACHE_TWIN_SPEED = 0x80000000; +constexpr int CHARGE_STORE_MAX = 99; +constexpr int SOUL_CHARGE_CONSUMABLE = 0x20; +constexpr int BLOOD_CHARGE_CONSUMABLE = 0x100; +constexpr int BLOOD_CLOT_SUBTYPE_SPENT = 7; +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; +constexpr float TWIN_SPEED_MAX = 2; +constexpr float TWIN_SPEED_MIN = 0.1f; +constexpr float TWIN_SPAWN_OFFSET = 20; +constexpr float SAFE_SPAWN_LOOKAHEAD = 45; +constexpr float SAFE_SPAWN_FAR_ENOUGH = 14400; +constexpr float SAFE_SPAWN_NEAREST_START = 1e8f; +constexpr int SAFE_SPAWN_RADIUS_MIN = 30; +constexpr int SAFE_SPAWN_RADIUS_STEP = 3; +constexpr int SAFE_SPAWN_TRIES = 150; +constexpr int NPC_TYPE_FIRST = 10; +constexpr int NPC_TYPE_LAST = 999; +constexpr int ROOM_IDX_DEBUG = -16; +constexpr int DIMENSION_ROOM_COUNT = 169; +constexpr float FORGOTTEN_CHAIN_SCALE = 120; +constexpr int MAGDALENE_PILL_TRIES = 10; +constexpr int REVIVE_DAMAGE_COOLDOWN = 90; +constexpr int COOP_REVIVE_DAMAGE_COOLDOWN = 150; +constexpr int LAZARUS_RISEN_MAX_HEARTS = 2; +constexpr int LAZARUS_BIRTHRIGHT_STEW_FRAMES = 1800; +constexpr int POOF_LARGE_SUBTYPE = 3; +constexpr int COLLECTIBLE_GUPPYS_COLLAR_RNG = 212; +constexpr int TRINKET_BROKEN_ANKH_RNG = 28; +constexpr int SOUL_CHARGE_HEART_CONTAINERS = 2; +constexpr int KEEPER_START_COIN_HEARTS = 4; +constexpr float INDICATOR_SCREEN_WIDTH = 338; +constexpr float INDICATOR_SCREEN_HEIGHT = 182; +constexpr float INDICATOR_ORIGIN_X = 60; +constexpr float INDICATOR_ORIGIN_Y = 140; +constexpr float INDICATOR_SCALE = 0.65f; +constexpr float INDICATOR_BOTTOM_MARGIN = 10; +constexpr float INDICATOR_FADE_START = 10; +constexpr float INDICATOR_FADE_LENGTH = 140; +constexpr std::string_view FORGOTTEN_BOMB_SHEET = "gfx/characters/costumes/character_016b_theforgotten_bomb.png"; + +// The damage each character type adds as a share of its damage (the exe's table at 00b6bce8). +constexpr std::array CHARACTER_DAMAGE_SHARES = { + 0, 0, 0.2f, 0.35f, 0.05f, -0.25f, 0, 0.5f, 0, 0, 0, 0.4f, 1, 0, 0.2f, 0, 0.5f, 0, 0, 0, 0, + 0, -0.25f, 0.2f, 0, 0, 0.2f, 0, 0.5f, 0, 0, 0.3f, 0, 0, 0, 0.5f, 0, 0, 0.5f, 0, 0}; + +// The speed each character type adds (the exe's table at 00c5c3b0, whose Eden entries the evaluation overwrites with +// Eden's rolled speed). +constexpr std::array CHARACTER_SPEEDS = { + 0, -0.15f, 0.3f, 0, 0.1f, 0.23f, 0.1f, 0.25f, 0, 0, 0, 0.25f, 0.1f, 0, -0.1f, 0, 0, 0.3f, 0, 0, 0, + 0, 0, 0.3f, 0.23f, -0.1f, 0, 0, 0, 0, 0, 0, -0.15f, 0, 0, 0, 0, 0, -0.1f, 0, 0}; + +// Whether the player is Eden or Tainted Eden, whose stats carry their rolled offsets. +bool is_eden(const Entity_Player& player) +{ + return player.playerType == PLAYER_EDEN || player.playerType == PLAYER_EDEN_B; +} + +// Whether the player is Azazel, its tainted form, or holds Azazel's Stump's effect. +bool is_azazel(Entity_Player& player) +{ + return player.playerType == PLAYER_AZAZEL || player.playerType == PLAYER_AZAZEL_B || + player.temporaryEffects.HasTrinketEffect(TRINKET_AZAZELS_STUMP); +} + +// Whether the frame and the stat evaluation are reconstructed for the player's character: the normal ones. +bool is_character_reconstructed(const Entity_Player& player) +{ + return player.playerType >= PLAYER_ISAAC && player.playerType <= PLAYER_ESAU; +} + +// The tears up or down a character adds to the items' before Binge Eater's: Samson's, the tainted ones', Azazel's (or +// its stump's) and the twins'. +float character_tears_get(Entity_Player& player) +{ + switch (player.playerType) + { + case PLAYER_SAMSON: + case PLAYER_SAMSON_B: + return -0.1f; + case PLAYER_BLUEBABY_B: + return -0.35f; + case PLAYER_APOLLYON_B: + case PLAYER_EVE_B: + return -0.5f; + case PLAYER_AZAZEL: + return 0.5f; + default: + break; + } + if (player.temporaryEffects.HasTrinketEffect(TRINKET_AZAZELS_STUMP)) return 0.5f; + if (player.playerType == PLAYER_JACOB || player.playerType == PLAYER_JACOB_B || player.playerType == PLAYER_JACOB2_B) + return 0.27777f; + if (player.playerType == PLAYER_ESAU || player.playerType == PLAYER_LAZARUS2_B) return -0.099649f; + return 0; +} + +// The tears the Keepers lose after Binge Eater's, unless 20/20 holds them up. +float character_tears_penalty_get(Entity_Player& player) +{ + if (player.HasCollectible(COLLECTIBLE_20_20)) return 0; + if (player.playerType == PLAYER_KEEPER) return 1.9f; + return player.playerType == PLAYER_KEEPER_B ? 2.2f : 0; +} + +// What a character multiplies its damage by: its share plus one, Azazel's Stump's 1.5, and nothing for Eve and Tainted +// Eve while their Whore of Babylon is on. +float character_damage_scale_get(Entity_Player& player) +{ + TemporaryEffects& effects = player.temporaryEffects; + + if (effects.HasTrinketEffect(TRINKET_AZAZELS_STUMP)) return AZAZELS_STUMP_DAMAGE_SCALE; + if (player.playerType == PLAYER_EVE && effects.HasCollectibleEffect(COLLECTIBLE_WHORE_OF_BABYLON)) return 1; + if (player.playerType == PLAYER_EVE_B && effects.HasNullEffect(NULLITEM_BLOODY_BABYLON)) return 1; + if (player.playerType < 0 || player.playerType >= PLAYER_TYPE_COUNT) return 1; + return CHARACTER_DAMAGE_SHARES[player.playerType] + 1; +} + +// The damage a character adds after its multiplier: Eden's roll, Jacob's loss and Esau's gain. +float character_damage_get(Entity_Player& player) +{ + if (is_eden(player)) return player.edenDamage; + if (player.playerType == PLAYER_JACOB) return -0.75f; + return player.playerType == PLAYER_ESAU ? 0.25f : 0; +} + +// The shot speed a character adds: Samson's, Eden's roll and the twins'. +float character_shot_speed_get(Entity_Player& player) +{ + if (player.playerType == PLAYER_SAMSON) return 0.31f; + if (is_eden(player)) return player.edenShotSpeed; + if (player.playerType == PLAYER_JACOB) return 0.15f; + return player.playerType == PLAYER_ESAU ? -0.15f : 0; +} + +// The range a character adds to the base 260: the short ranged ones (and Azazel's Stump) lose 80, Samson and Jacob 60, +// Esau gains 60 and Eden its roll. +float character_range_get(Entity_Player& player) +{ + switch (player.playerType) + { + case PLAYER_CAIN: + case PLAYER_LAZARUS: + case PLAYER_AZAZEL: + case PLAYER_CAIN_B: + case PLAYER_JUDAS_B: + case PLAYER_LAZARUS_B: + return -80; + default: + break; + } + if (player.temporaryEffects.HasTrinketEffect(TRINKET_AZAZELS_STUMP)) return -80; + if (player.playerType == PLAYER_SAMSON || player.playerType == PLAYER_SAMSON_B || player.playerType == PLAYER_JACOB) + return -60; + if (is_eden(player)) return player.edenTearRange; + return player.playerType == PLAYER_ESAU ? 60 : 0; +} + +// The speed table's entry for the player's type, Eden's roll for the Edens. +static float speed_table_get(Entity_Player& player) +{ + if (is_eden(player)) return player.edenSpeed; + if (player.playerType < 0 || player.playerType >= PLAYER_TYPE_COUNT) return 0; + return CHARACTER_SPEEDS[player.playerType]; +} + +// The speed a character adds, Azazel's for its stump. +float character_speed_get(Entity_Player& player) +{ + if (player.temporaryEffects.HasTrinketEffect(TRINKET_AZAZELS_STUMP)) return CHARACTER_SPEEDS[PLAYER_AZAZEL]; + return speed_table_get(player); +} + +// The luck a character adds: Cain's Birthright, Lazarus' and Esau's loss, the Keepers' and Tainted Lazarus' dead +// form's, and Jacob's gain. +float character_luck_get(Entity_Player& player) +{ + float luck = player.playerType == PLAYER_CAIN && player.HasCollectible(COLLECTIBLE_BIRTHRIGHT) ? 1.0f : 0.0f; + + switch (player.playerType) + { + case PLAYER_LAZARUS: + case PLAYER_ESAU: + return luck - 1; + case PLAYER_KEEPER: + case PLAYER_KEEPER_B: + case PLAYER_LAZARUS2_B: + return luck - 2; + case PLAYER_JACOB: + return luck + 1; + default: + return luck; + } +} + +// The speed part of 00763570's end: a twin's speed is evaluated too, then Jacob and Esau share their average and other +// pairs the leading twin's, clamped to 0.1 to 2. The twin evaluated here skips its own share. +void twins_speed_share(Entity_Player& player) +{ + Entity_Player* twin = player.twin_get(); + + if ((player.cacheFlags & (CACHE_TWIN_SPEED | CACHE_SPEED)) != CACHE_SPEED || !twin) return; + twin->cacheFlags |= CACHE_TWIN_SPEED | CACHE_SPEED; + twin->EvaluateItems(); + + bool isJacobAndEsau = player.playerType == PLAYER_JACOB || player.playerType == PLAYER_ESAU; + float speed = player.moveSpeed; + if (isJacobAndEsau) speed = (player.moveSpeed + twin->moveSpeed) * 0.5f; + else if (player.GetMainTwin() != &player) speed = twin->moveSpeed; + speed = std::max(std::min(speed, TWIN_SPEED_MAX), TWIN_SPEED_MIN); + player.moveSpeed = speed; + twin->moveSpeed = speed; +} + +// The speed the slowing null effects take, only from characters not already slower than Isaac. +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)); +} + +// The UpdateCostumes part (0075bf00) that redraws the player's head and body in the skin colors its costumes left it: +// the character's skin sheet in each changed color on every layer but the ghost, or Tainted Forgotten's bomb sheet in +// Hot Potato. +void Entity_Player::skin_recolor(const SkinColors& colors) +{ + EntityConfig_Player* config = g_manager->entityConfig.GetPlayer(playerType); + + if (g_game->challenge == CHALLENGE_HOT_POTATO && playerType == PLAYER_THEFORGOTTEN_B) + for (int layer = 0; layer < COSTUME_LAYER_COUNT; layer++) sprite.ReplaceSpritesheet(layer, FORGOTTEN_BOMB_SHEET); + else if (config && !config->skinPath.empty()) + { + auto sheet_get = [&](int applied, int color) + { + if (applied == color) return std::string(); + return costume_path_apply_skin_color(config->skinPath, color, -1, nullptr, nullptr); + }; + std::string headSheet = sheet_get(headColor, colors.head); + std::string bodySheet = sheet_get(bodyColor, colors.body); + for (int layer = 0; layer < COSTUME_LAYER_COUNT; layer++) + { + const std::string& sheet = is_body_layer(layer) ? bodySheet : headSheet; + if (layer != PLAYER_LAYER_GHOST && !sheet.empty()) sprite.ReplaceSpritesheet(layer, sheet); + } + } + sprite.LoadGraphics(); + headColor = colors.head; + bodyColor = colors.body; +} + +// Whether Whore of Babylon wakes for the player's red hearts: at one or less (16 in the deathmatch), Eve's at two, or +// always with her Birthright, hers only once the room has run a frame. +bool is_whore_of_babylon_awake(Entity_Player& player) +{ + Game& game = *g_game; + bool isDeathmatch = game.deathmatchManager.is_active(); + + if (player.redHearts <= (isDeathmatch ? DEATHMATCH_WHORE_RED_HEARTS : WHORE_OF_BABYLON_RED_HEARTS)) return true; + if (player.playerType != PLAYER_EVE) return false; + int eveRedHearts = isDeathmatch ? DEATHMATCH_WHORE_RED_HEARTS : EVE_WHORE_OF_BABYLON_RED_HEARTS; + if (player.redHearts > eveRedHearts && !player.HasCollectible(COLLECTIBLE_BIRTHRIGHT)) + return false; + return game.room->isInitialized && game.frameCount - game.room->enterFrame > 1; +} + +// Tainted Eve down to her last heart with no clots left: her own Whore of Babylon wakes, once the room has run a frame. +void tainted_eve_babylon_try(Entity_Player& player) +{ + Game& game = *g_game; + Room& room = *game.room; + + if (!room.isInitialized || game.frameCount - room.enterFrame <= 1) return; + if (player.temporaryEffects.HasNullEffect(NULLITEM_BLOODY_BABYLON)) return; + for (Entity* entity : room.entityList.persistentEL) + if (entity && entity->type == ENTITY_FAMILIAR && static_cast(entity)->player == &player && + entity->variant == Entity_Familiar::BLOOD_BABY && entity->subtype != BLOOD_CLOT_SUBTYPE_SPENT && + !entity->isDead) + return; + game.itemOverlay.Show(GIANTBOOK_WHORE_OF_BABYLON, 3, nullptr); + player.temporaryEffects.AddNullEffect(NULLITEM_BLOODY_BABYLON, true, 1); +} + +// 007d2ad0 Adds soul charges, kept within 0 to 99: the actives they charge flash, the twin shares them and the HUD +// redraws. +void Entity_Player::AddSoulCharge(int count) +{ + int oldSoulCharge = effectiveSoulCharge; + + effectiveSoulCharge = std::clamp(count + oldSoulCharge, 0, CHARGE_STORE_MAX); + apply_soul_charge_to_actives(oldSoulCharge); + ConsumableCountChanged(SOUL_CHARGE_CONSUMABLE); + g_game->hud.refresh_request(HUD_REFRESH_PLAYER); +} + +// 007d2b50 The soul charges Bethany can spend, none for other characters. +int Entity_Player::GetEffectiveSoulCharge() +{ + return playerType == PLAYER_BETHANY ? effectiveSoulCharge : 0; +} + +// 006f0020 Sets the soul charges as they are. +void Entity_Player::SetSoulCharge(int amount) +{ + effectiveSoulCharge = amount; +} + +// 007d2d40 Adds blood charges, kept within 0 to 99, as AddSoulCharge does for Tainted Bethany. +void Entity_Player::AddBloodCharge(int amount) +{ + int oldBloodCharge = effectiveBloodCharge; + + effectiveBloodCharge = std::clamp(amount + oldBloodCharge, 0, CHARGE_STORE_MAX); + blood_charge_changed(oldBloodCharge); + ConsumableCountChanged(BLOOD_CHARGE_CONSUMABLE); + g_game->hud.refresh_request(HUD_REFRESH_PLAYER); +} + +// 007d2dd0 The blood charges Tainted Bethany can spend, none for other characters. +int Entity_Player::GetEffectiveBloodCharge() +{ + return playerType == PLAYER_BETHANY_B ? effectiveBloodCharge : 0; +} + +// 006f0030 Sets the blood charges as they are. +void Entity_Player::SetBloodCharge(int amount) +{ + effectiveBloodCharge = amount; +} + +// 009bc280 A spot for a player to appear near a position, away from the room's enemies and shots and where they head +// (and the other players in the deathmatch): up to 50 random spots on circles growing from 30, each moved to a free +// tile, until one is 120 away from all of them, else the farthest found. +Vector PlayerManager::find_safe_spawn_position(Vector position) +{ + Game& game = *g_game; + Room& room = *game.room; + std::vector dangers; + Vector best{}; + float bestDistance = 0; + + for (Entity* entity : room.entityList.updateEL) + { + bool isPlayer = game.deathmatchManager.is_active() && entity->type == ENTITY_PLAYER; + bool isEnemy = entity->type >= NPC_TYPE_FIRST && entity->type <= NPC_TYPE_LAST; + if (!isPlayer && !isEnemy && entity->type != ENTITY_PROJECTILE) continue; + dangers.push_back(entity->pos); + dangers.push_back(vector_make(entity->velocity.x * SAFE_SPAWN_LOOKAHEAD + entity->pos.x, + entity->velocity.y * SAFE_SPAWN_LOOKAHEAD + entity->pos.y)); + } + for (int radius = 0; radius < SAFE_SPAWN_TRIES && bestDistance <= SAFE_SPAWN_FAR_ENOUGH; + radius += SAFE_SPAWN_RADIUS_STEP) + { + float angle = random_unit() * 3.14f; + angle = angle + angle; + float distance = (float)radius + SAFE_SPAWN_RADIUS_MIN; + Vector spot = vector_make(std::cos(angle) * distance + position.x, std::sin(angle) * distance + position.y); + spot = room_free_pickup_position_find({.position = room.GetClampedPositionImpl(spot, 0, 0, 0, 0), + .isAvoidActiveEntities = true}); + float nearest = SAFE_SPAWN_NEAREST_START; + for (const Vector& danger : dangers) + { + float dx = spot.x - danger.x; + float dy = spot.y - danger.y; + nearest = std::min(nearest, dy * dy + dx * dx); + } + if (bestDistance >= nearest) continue; + best = spot; + bestDistance = nearest; + } + return best; +} + +// 007d2000 Spawns a twin of a character type as a co-player that shares this player's controller and stands 20 to its +// right, this player moving 20 to the left, and gives both their HUDs. +Entity_Player* Entity_Player::InitTwin(int twinType) +{ + Game& game = *g_game; + Entity_Player* twin = game.playerManager.SpawnCoPlayer2(twinType); + + twin->twinPlayer = this; + twinPlayer = twin; + twin->SetControllerIndex(controllerIndex, false); + twin->pos = PlayerManager::find_safe_spawn_position(pos); + twin->pos = vector_make(pos.x + TWIN_SPAWN_OFFSET, pos.y + 0); + pos = vector_make(pos.x - TWIN_SPAWN_OFFSET, pos.y + 0); + game.hud.AssignPlayerHUDs(); + return twin; +} + +// Lets go of the sub player: unlinks and deletes it. +static void sub_player_free(Entity_Player& player) +{ + player.subPlayer->ClearReferences(); + delete player.subPlayer; + player.subPlayer = nullptr; +} + +// Takes a companion out of the room with a poof where it stood. +static void companion_poof(Entity* companion) +{ + g_game->Spawn({.position = companion->pos, + .spawner = companion, + .type = ENTITY_EFFECT, + .variant = EFFECT_POOF01, + .seed = Random()}); + companion->Remove(); +} + +// 007cbcd0 Gives The Forgotten and The Soul their other half as a sub player (unless the soul has left the body), and +// takes it away from other characters, with the Forgotten's body and Dark Esau, which leave with a poof. Only players +// of the run have halves. +void Entity_Player::init_forgotten_twin() +{ + if (playerIndex < 0) return; + + if (playerType == PLAYER_THEFORGOTTEN || playerType == PLAYER_THESOUL) + { + if (temporaryEffects.HasNullEffect(NULLITEM_SOUL_FORGOTTEN)) + { + if (subPlayer) sub_player_free(*this); + } + else if (!subPlayer) + { + subPlayer = new Entity_Player(); + subPlayer->Init(type, variant, playerType == PLAYER_THEFORGOTTEN ? PLAYER_THESOUL : PLAYER_THEFORGOTTEN, + initSeed); + } + return; + } + if (subPlayer && !subPlayer->isValid) sub_player_free(*this); + if (forgottenBody) + { + companion_poof(forgottenBody); + forgottenBody = nullptr; + } + if (darkEsau && playerType != PLAYER_JACOB_B && playerType != PLAYER_JACOB2_B) companion_poof(darkEsau); +} + +// 007cbef0 Lays the Forgotten's body where the Soul leaves it (where it was last left, with the Soul's Birthright, +// unless that is another room of this dimension), sized, scaled and tinted as the player, with the chain binding it to +// the Soul. A body left by a replaced player stays. The room it lies in is remembered. +Entity* Entity_Player::spawn_forgotten_body() +{ + Game& game = *g_game; + + if (forgottenBody) + { + if (replacedPlayer) return forgottenBody; + forgottenBody->Remove(); + forgottenBody = nullptr; + } + bool isBirthrightBody = HasCollectible(COLLECTIBLE_BIRTHRIGHT) && playerType == PLAYER_THESOUL; + bool isBodyLeft = isBirthrightBody && forgottenBodyRoomIdx != FORGOTTEN_BODY_ROOM_NONE; + int roomIdx = forgottenBodyRoomIdx >= 0 ? forgottenBodyRoomIdx % DIMENSION_ROOM_COUNT : forgottenBodyRoomIdx; + int dimension = forgottenBodyRoomIdx >= 0 ? forgottenBodyRoomIdx / DIMENSION_ROOM_COUNT : 0; + if (isBirthrightBody && roomIdx != FORGOTTEN_BODY_ROOM_NONE) + { + RoomConfig_Room* data = game.room->descriptor->data; + bool isHome = data && data->type == ROOM_DUNGEON && data->stageId == STAGE_ID_HOME; + if (!isHome && dimension == game.currentDimensionIdx && + game.GetRoomByIdx(roomIdx, dimension) != game.room->descriptor) + return nullptr; + } + + Vector spawnPos = isBodyLeft ? forgottenBodyPos : pos; + auto* body = static_cast(game.Spawn( + {.position = spawnPos, .type = ENTITY_FAMILIAR, .variant = Entity_Familiar::FORGOTTEN_BODY, .seed = Random()})); + body->pos = spawnPos; + body->SetSize(size, sizeMulti, -1); + body->sprite.scale = playerSpriteScale; + body->sprite.color = colorOverride; + body->ClearEntityFlags(FLAG_APPEAR); + forgottenBody = body; + if (game.currentRoomIdx != ROOM_IDX_DEBUG) + { + forgottenBodyRoomIdx = game.currentRoomIdx >= 0 + ? game.currentDimensionIdx * DIMENSION_ROOM_COUNT + game.currentRoomIdx + : game.currentRoomIdx; + forgottenBodyPos = spawnPos; + } + if (isBirthrightBody) return body; + + Entity* chain = + game.Spawn({.position = pos, .type = ENTITY_EFFECT, .variant = EFFECT_FORGOTTEN_CHAIN, .seed = Random()}); + chain->child = body; + chain->target = this; + static_cast(chain)->scale = FORGOTTEN_CHAIN_SCALE; + chain->Update(); + return body; +} + +// The part of 007bc740 that hands Magdalene her starting pill: Full Health, told apart from Health Up's color (up to +// ten tries), already identified. +void Entity_Player::magdalene_pill_add() +{ + ItemPool& pool = g_game->itemPool; + int pill = pool.ForceAddPillEffect(PILLEFFECT_FULL_HEALTH); + + for (int i = 0; i < MAGDALENE_PILL_TRIES; i++) + { + int healthUp = pool.ForceAddPillEffect(PILLEFFECT_HEALTH_UP); + if (pill != healthUp) break; + pill = pool.ForceAddPillEffect(PILLEFFECT_FULL_HEALTH); + if (pill != healthUp) break; + } + AddPocketItem(pill, POCKET_PILL); + pool.IdentifyPill((uint32_t)pill); +} + +// Whether the player is Jacob or Esau, who share their item and pocket buttons. +static bool is_jacob_or_esau(Entity_Player& player) +{ + return player.playerType == PLAYER_JACOB || player.playerType == PLAYER_ESAU; +} + +// Whether Jacob and Esau play with the classic controls, where Jacob's item button is Esau's pocket button and drop +// switches the pocket button between them. +static bool is_twin_classic_controls() +{ + return g_manager->optionsConfig.jacobEsauControls == 0; +} + +// The button a twin reads for its item (Esau's is the pocket button) or its pocket (Jacob's is the item button) with +// the classic controls. Any other player reads its own. +ButtonAction twin_button_action(Entity_Player& player, TwinButton button) +{ + if (is_jacob_or_esau(player) && is_twin_classic_controls()) + return player.GetMainTwin() == &player ? ACTION_ITEM : ACTION_PILL_CARD; + return button == TWIN_BUTTON_ITEM ? ACTION_ITEM : ACTION_PILL_CARD; +} + +// Whether the drop button keeps a twin from its item or pocket button this frame. With the classic controls drop held +// takes the item button away and drop released the pocket button, while the pair stands together. Otherwise drop +// held hands both buttons from Jacob to Esau. +bool is_twin_button_blocked(Entity_Player& player, TwinButton button) +{ + if (!is_jacob_or_esau(player)) return false; + bool isDropHeld = input_is_action_pressed(ACTION_DROP, player.controllerIndex, &player); + if (is_twin_classic_controls()) + return player.twin_get() && (button == TWIN_BUTTON_ITEM ? isDropHeld : !isDropHeld); + if (player.GetMainTwin() == &player) return isDropHeld; + return !isDropHeld; +} + +// The Render part (0078ca00) that points at a co-op player outside the screen: its character's icon at the screen's +// edge, faded in over 140 past the edge. The icon is HUD::render_player_type_icon, which stops the game when shown. +void Entity_Player::coop_indicator_render() +{ + Room& room = *g_game->room; + if (g_game->playerManager.GetPlayerSlotFromController(controllerIndex) < 0) return; + + float scale = g_displayPixelRatio * g_screenPointScale; + float x = ((g_screenWidth - INDICATOR_SCREEN_WIDTH) * 0.5f + (pos.x - INDICATOR_ORIGIN_X) * INDICATOR_SCALE) * scale; + float y = ((pos.y - INDICATOR_ORIGIN_Y) * INDICATOR_SCALE + (g_screenHeight - INDICATOR_SCREEN_HEIGHT) * 0.5f) * scale; + x = (float)std::floor(x + 0.5f) / scale + room.renderScrollOffset.x; + y = (float)std::floor(y + 0.5f) / scale + room.renderScrollOffset.y; + float edgeX = std::min(std::max(x, 0.0f), g_screenWidth); + float edgeY = std::min(std::max(y, 0.0f), g_screenHeight + INDICATOR_BOTTOM_MARGIN); + float distance = std::sqrt((y - edgeY) * (y - edgeY) + (x - edgeX) * (x - edgeX)); + if (std::clamp((distance - INDICATOR_FADE_START) / INDICATOR_FADE_LENGTH, 0.0f, 1.0f) > 0) + reconstruction_missing("HUD::render_player_type_icon 009a6660 (the co-op player indicator)"); +} + +// 007c3620 Takes off the costume the character's config dresses it in. +void Entity_Player::RemoveSkinCostume() +{ + EntityConfig_Player* config = g_manager->entityConfig.GetPlayer(playerType); + if (config && config->costumeID != -1) RemoveCostume(g_manager->itemConfig.GetNullItem(config->costumeID)); +} + +// 007a2220 Brings a dead player back with half a red heart (half a soul heart without containers or bone hearts), +// one broken heart fewer when they fill every container. A co-op ghost or baby appears again somewhere safe, and +// Tainted Forgotten is dropped by its soul and gets its weapons back. The extra layer shows again. +void Entity_Player::Revive() +{ + if (!isDead) return; + + isDead = false; + damageCooldown = 1; + if (GetHeartLimit(false) < 1) brokenHearts = std::max(brokenHearts - 1, 0); + if (maxHearts >= 1) + { + redHearts = 1; + soulHearts = 0; + } + else if (boneHearts < 1) + { + redHearts = 0; + soulHearts = 1; + } + if (variant == PLAYER_VARIANT_COOP_BABY || isCoopGhost) + { + PlayExtraAnimation("Appear", false); + pos = PlayerManager::find_safe_spawn_position(pos); + damageCooldown = COOP_REVIVE_DAMAGE_COOLDOWN; + } + if (playerType == PLAYER_THEFORGOTTEN_B) + { + Entity_Player* soul = twin_get(); + if (soul && soul->heldEntity == this) + { + soul->heldEntity = nullptr; + ClearEntityFlags(FLAG_HELD | FLAG_THROWN); + } + cacheFlags = CACHE_ALL; + weaponTypes.fill(false); + EvaluateItems(); + } + if (LayerState* extra = sprite.GetLayer(PLAYER_LAYER_EXTRA)) extra->isVisible = true; +} + +// 007a23a0 Revives the player by a collectible's rule, the owner of the collectible playing its part. Only Lazarus' +// Rags (Lazarus' own rising) is reconstructed: the player is dressed as Lazarus Risen (unless already Lazarus), +// keeps a container fewer (two at least) filled with a red heart, rises as Lazarus Risen (the tainted Lazaruses stay +// themselves) with Lazarus' boost, Red Stew's effect with his Birthright, and a poof. It stays vulnerable for 90 frames +// at least. +void Entity_Player::collectible_revive(int collectible, bool isOwner) +{ + Game& game = *g_game; + ItemConfig& items = g_manager->itemConfig; + + if (playerIndex >= 0) Revive(); + if (collectible != COLLECTIBLE_LAZARUS_RAGS) + reconstruction_missing(("Entity_Player::collectible_revive 007a23a0 (collectible " + std::to_string(collectible) + + (isOwner ? ", owner)" : ")")) + .c_str()); + + if (playerType != PLAYER_LAZARUS) + { + if (playerType != PLAYER_THEFORGOTTEN_B) RemoveSkinCostume(); + AddCostume(items.GetCollectible(COLLECTIBLE_LAZARUS_RAGS), false); + } + soulHearts = 0; + blackHearts = 0; + eternalHearts = 0; + maxHearts = std::max(maxHearts - 2, LAZARUS_RISEN_MAX_HEARTS); + boneHeartsMask = 0; + boneHearts = 0; + redHearts = std::min(maxHearts, LAZARUS_RISEN_MAX_HEARTS); + rottenHearts = 0; + if (HasCollectible(COLLECTIBLE_BIRTHRIGHT) && playerType == PLAYER_LAZARUS) + redStewBonusDuration = LAZARUS_BIRTHRIGHT_STEW_FRAMES; + if (playerType != PLAYER_LAZARUS_B && playerType != PLAYER_LAZARUS2_B) playerType = PLAYER_LAZARUS2; + cacheFlags |= CACHE_ALL; + temporaryEffects.AddNullEffect(NULLITEM_LAZARUS_BOOST, true, 1); + update_player_skin(); + EvaluateItems(); + if (forgottenBody) pos = forgottenBody->pos; + Entity* poof = game.Spawn({.position = pos, + .spawner = this, + .subType = POOF_LARGE_SUBTYPE, + .type = ENTITY_EFFECT, + .variant = EFFECT_POOF01, + .seed = Random()}); + poof->renderDepthOffset = posOffset.y + 1; + + isVisible = true; + damageCooldown = std::max(damageCooldown, REVIVE_DAMAGE_COOLDOWN); + UpdateHeartDependentEffects(); + if (game.deathmatchManager.is_active() || isDead || goldenHearts <= 0) return; + int holders = (std::min(redHearts, maxHearts) + 1) / 2 + (soulHearts + 1) / 2 + boneHearts; + if (holders >= goldenHearts) return; + BreakGoldenHearts(goldenHearts - holders); + goldenHearts = holders; +} + +// The end of 007a1090 once the first of the pair lives again: Judas' Birthright makes a Judas saved by Plan C Black +// Judas, the first player's old character lets go of what it brought, and each player rolls Guppy's Collar's and Broken +// Ankh's generators, gets its Forgotten half back and settles whether it can shoot and its color. +void revived_players_settle(std::vector& players, int oldType) +{ + Entity_Player& first = *players[0]; + + if (oldType == PLAYER_JUDAS && first.playerType != PLAYER_BLACKJUDAS && first.HasCollectible(COLLECTIBLE_BIRTHRIGHT) && + first.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_PLAN_C)) + { + if (ItemConfig_Item* planC = g_manager->itemConfig.GetCollectible(COLLECTIBLE_PLAN_C)) + first.temporaryEffects.RemoveEffect(planC, -1); + first.maxHearts = 0; + first.redHearts = 0; + first.playerType = PLAYER_BLACKJUDAS; + first.cacheFlags |= CACHE_ALL; + first.update_player_skin(); + first.EvaluateItems(); + first.TryPreventDeath(); + } + first.player_type_change_prepare(oldType); + for (Entity_Player* player : players) + { + player->GetCollectibleRNG(COLLECTIBLE_GUPPYS_COLLAR_RNG).Next(); + player->GetTrinketRNG(TRINKET_BROKEN_ANKH_RNG).Next(); + player->init_forgotten_twin(); + player->UpdateCanShoot(); + player->ResetColor(); + } +} + +// 007cf610 Lets go of what the old character brought once the player became another: a twin it had (Jacob's Esau, +// Tainted Forgotten's soul, Tainted Lazarus' other form) unless the twin is that character, Tainted Isaac's inventory +// and Tainted Jacob's curse (not reconstructed yet), Tainted Forgotten's flight, and its pocket active for the new +// one's. +void Entity_Player::player_type_change_prepare(int oldType) +{ + if (oldType == playerType) return; + bool isJacobPair = (playerType == PLAYER_JACOB_B && oldType == PLAYER_JACOB2_B) || + (playerType == PLAYER_JACOB2_B && oldType == PLAYER_JACOB_B); + if (isJacobPair) return; + + Entity_Player* twin = twin_get(); + if (twin) + { + if (twin->playerType == oldType) return; + if (oldType == PLAYER_JACOB || oldType == PLAYER_THEFORGOTTEN_B) remove_twin(); + } + if (oldType == PLAYER_LAZARUS_B || oldType == PLAYER_LAZARUS2_B) remove_twin(); + if (playerType == PLAYER_ISAAC_B) + reconstruction_missing("Entity_Player::player_type_change_prepare 007cf610 (Tainted Isaac's inventory)"); + if ((playerType == PLAYER_JACOB_B || playerType == PLAYER_JACOB2_B) && + !temporaryEffects.HasNullEffect(NULLITEM_JACOBS_CURSE)) + reconstruction_missing("Entity_Player::player_type_change_prepare 007cf610 (Tainted Jacob's curse)"); + if (oldType == PLAYER_THEFORGOTTEN_B) + { + cacheFlags |= CACHE_FLYING; + canFly = true; + EvaluateItems(); + } + EntityConfig_Player* config = g_manager->entityConfig.GetPlayer(playerType); + SetPocketActiveItem(config ? config->pocketActiveID : 0, ACTIVE_SLOT_POCKET, false); + g_game->hud.mark_all_slots_dirty(HISTORY_REBUILD_ICONS, HISTORY_CLEAR_ITEMS); +} + +// The ChangePlayerType part that hands Bethany's soul charges back as soul hearts, shared among the Bethanies (one at +// least), when she becomes another character. +static int bethany_soul_share_get(Entity_Player& player) +{ + PlayerManager& players = g_game->playerManager; + + if (player.playerType != PLAYER_BETHANY || player.effectiveSoulCharge <= 0) return 0; + int bethanies = (int)std::ranges::count_if(players.playerList, [](Entity_Player* each) + { return each->playerType == PLAYER_BETHANY; }); + return std::max(player.effectiveSoulCharge / bethanies, 1); +} + +// The ChangePlayerType part that takes the hearts of the player's other half (The Forgotten's or The Soul's) back, +// then splits them again for the new halves: soul hearts go to a soul half, bone and red hearts to a bone half, and +// an eternal heart beyond the first. +void Entity_Player::forgotten_halves_hearts_move() +{ + if (Entity_Player* half = subPlayer) + { + int shift = (soulHearts + 1) / 2; + int oldBoneHearts = boneHearts; + maxHearts += half->maxHearts; + redHearts += half->redHearts; + soulHearts = half->soulHearts + soulHearts; + boneHearts = half->boneHearts + oldBoneHearts; + blackHearts |= half->blackHearts << (shift & 31); + boneHeartsMask |= half->boneHeartsMask << ((oldBoneHearts + shift) & 31); + eternalHearts += half->eternalHearts; + rottenHearts += half->rottenHearts; + goldenHearts += half->goldenHearts; + } + init_forgotten_twin(); + Entity_Player* half = subPlayer; + if (!half) return; + + HealthType health = half->GetHealthType(); + if (health == HEALTH_SOUL) + { + half->soulHearts = soulHearts; + half->blackHearts = blackHearts; + soulHearts = 0; + blackHearts = 0; + } + else if (health == HEALTH_BONE) + { + half->AddBoneHearts(boneHearts); + half->redHearts = redHearts; + redHearts = 0; + boneHearts = 0; + boneHeartsMask = 0; + } + if (eternalHearts > 1) + { + eternalHearts--; + half->eternalHearts++; + } + half->update_bone_hearts(); +} + +// The ChangePlayerType part that reshapes the hearts for how the new character counts health: none keeps half a soul +// heart, coins become two coin hearts and one broken heart at most, soul hearts lose the red ones, and bone hearts +// turn the containers into bone hearts. +static void health_type_apply(Entity_Player& player, HealthType health) +{ + switch (health) + { + case HEALTH_NO_HEALTH: + player.rottenHearts = 0; + player.boneHeartsMask = 0; + player.boneHearts = 0; + player.eternalHearts = 0; + player.maxHearts = 0; + player.redHearts = 0; + player.soulHearts = 1; + player.blackHearts = 0; + break; + case HEALTH_COIN: + player.brokenHearts = std::min(player.brokenHearts, 1); + player.AddMaxHearts(KEEPER_START_COIN_HEARTS, false); + player.rottenHearts = 0; + player.boneHeartsMask = 0; + player.boneHearts = 0; + player.soulHearts = 0; + player.blackHearts = 0; + break; + case HEALTH_SOUL: + player.rottenHearts = 0; + player.maxHearts = 0; + player.redHearts = 0; + break; + case HEALTH_BONE: + { + int bones = player.maxHearts / 2; + player.maxHearts = 0; + if (bones > 0) player.AddBoneHearts(bones); + player.redHearts = std::min(player.redHearts, player.GetEffectiveMaxHearts()); + player.soulHearts = 0; + player.blackHearts = 0; + break; + } + default: + break; + } +} + +// The ChangePlayerType part that takes a twin's hearts into the player that no longer needs it: the most broken hearts, +// then its containers, bone, eternal, red, soul and golden hearts, its black ones after the player's soul hearts, and +// its rotten ones as far as the red hearts hold them. +static void twin_hearts_take(Entity_Player& player, Entity_Player& twin) +{ + int oldSoulHearts = player.soulHearts; + + player.brokenHearts = std::max(player.brokenHearts, twin.brokenHearts); + player.AddMaxHearts(twin.maxHearts, false); + player.AddBoneHearts(twin.boneHearts); + player.AddEternalHearts(twin.eternalHearts); + player.AddHearts(twin.redHearts, true, false); + player.AddSoulHearts(twin.soulHearts, false); + player.AddGoldenHearts(twin.goldenHearts, false); + player.blackHearts |= twin.blackHearts << ((oldSoulHearts / 2) & 31); + player.rottenHearts = std::min(player.rottenHearts + twin.rottenHearts, (player.redHearts + 1) / 2); + player.UpdateBlackHeartMask(); +} + +// The ChangePlayerType part that keeps the sprite's animation, frame and playing state through a reload. +static void animation_restore(ANM2& sprite, const std::string& animation, bool isPlaying, float frame) +{ + if (animation.empty()) return; + if (!isPlaying) + { + sprite.SetFrame(animation, (int)frame); + return; + } + const AnimationState& state = sprite.animState; + bool isStopped = state.animData && state.animData->isLooping && !state.isPlaying; + if (!state.animData || sprite.GetAnimation() != animation || isStopped) sprite.Play(animation, PLAY_FORCED); + if (sprite.animState.animData) sprite.animState.SetFrameFloat(frame); +} + +// 007ce6e0 Turns the player into another character: The Forgotten and The Soul only swap forms when isKeepState, Bethany +// hands her soul charges back, the costume, hearts, halves and twin follow the new character, the sprite reloads with +// the animation kept, and the stats, innate items and costumes are redone. Tainted Forgotten gets its soul and Tainted +// Lazarus its other form unless isKeepState. Becoming Jacob, who splits his hearts with a new Esau, is not +// reconstructed yet. +void Entity_Player::ChangePlayerType(int newType, bool isKeepState) +{ + EntityConfig& configs = g_manager->entityConfig; + if (newType < 0) return; + + bool isForgottenSwap = (newType == PLAYER_THEFORGOTTEN && playerType == PLAYER_THESOUL) || + (newType == PLAYER_THESOUL && playerType == PLAYER_THEFORGOTTEN); + if (isKeepState && isForgottenSwap) + { + SwapForgottenForm(true, true); + return; + } + int soulShare = isKeepState ? 0 : bethany_soul_share_get(*this); + RemoveSkinCostume(); + int oldType = playerType; + if (oldType == PLAYER_LAZARUS2) + { + EntityConfig_Player* lazarus = configs.GetPlayer(PLAYER_LAZARUS); + if (lazarus && lazarus->costumeID != -1) RemoveCostume(g_manager->itemConfig.GetNullItem(lazarus->costumeID)); + } + playerType = newType; + if (soulShare > 0) + { + AddSoulCharge(-soulShare); + AddSoulHearts(soulShare, false); + } + if (oldType == PLAYER_THEFORGOTTEN_B) + { + if (Entity_Player* soul = twin_get()) Teleport(soul->pos, false, false); + ClearEntityFlags(FLAG_THROWN); + posOffset.y = 0; + heightVelocity = 0; + } + + HealthType health = GetHealthType(); + forgotten_halves_hearts_move(); + health_type_apply(*this, health); + if (!isCoopGhost) TryPreventDeath(); + update_bone_hearts(); + UpdateHeartDependentEffects(); + UpdateCanShoot(); + AddEternalHearts(0); + if (playerType == PLAYER_JACOB) + { + if (!isKeepState) + reconstruction_missing("Entity_Player::ChangePlayerType 007ce6e0 (Jacob splitting his hearts with Esau)"); + } + else if (Entity_Player* twin = twin_get(); twin && !isKeepState) twin_hearts_take(*this, *twin); + if (playerType == PLAYER_BETHANY && soulHearts > 0) + { + AddSoulCharge(soulHearts); + soulHearts = 0; + if (!g_game->deathmatchManager.is_active()) blackHearts = 0; + HealthType bethanyHealth = GetHealthType(); + bool isBoneless = bethanyHealth == HEALTH_SOUL || bethanyHealth == HEALTH_NO_HEALTH; + if ((isBoneless ? maxHearts : maxHearts + boneHearts * 2) < 1) + { + maxHearts = SOUL_CHARGE_HEART_CONTAINERS; + redHearts = SOUL_CHARGE_HEART_CONTAINERS; + } + } + if (playerType == PLAYER_BLUEBABY_B) poop_spell_roll(); + + if (!config) KAGE_LogMessage(LOG_ASSERT, (uint8_t*)"Player Config invalid!\n"); + std::string animation = sprite.animState.animData ? sprite.GetAnimation() : std::string(); + bool isPlaying = sprite.animState.isPlaying; + float frame = sprite.animState.animFrame; + if (config) sprite.Load(config->anm2Path, GRAPHICS_DEFER); + update_player_skin(); + ResetColor(); + player_type_change_prepare(oldType); + animation_restore(sprite, animation, isPlaying, frame); + + if (!isKeepState && playerType == PLAYER_THEFORGOTTEN_B) InitTwin(PLAYER_THESOUL_B)->InitPostLevelInitStats(); + else if (!isKeepState && playerType == PLAYER_LAZARUS_B && !backupPlayer) + { + backupPlayer = new Entity_Player(); + backupPlayer->Init(type, variant, PLAYER_LAZARUS2_B, initSeed); + backupPlayer->backupPlayer = this; + } + cacheFlags = CACHE_ALL; + EvaluateItems(); + apply_innate_collectibles(); + UpdateCostumes(); +} + +// The TakeDamage part (007729d0) for the items Eve and Samson start with: Dead Bird's effect wakes (and its costume +// goes), and Bloody Lust, Bloody Gust and Blood Rights count the hit, Bloody Lust's and Bloody Gust's effects waking +// (Samson's Bloody Lust without its costume). The deathmatch's timed Dead Bird is not reconstructed yet. +void character_items_hit(Entity_Player& player) +{ + TemporaryEffects& effects = player.temporaryEffects; + + if (player.HasCollectible(COLLECTIBLE_DEAD_BIRD)) + { + if (g_game->deathmatchManager.is_active()) + reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Dead Bird's deathmatch cooldown)"); + ItemConfig_Item* deadBird = g_manager->itemConfig.GetCollectible(COLLECTIBLE_DEAD_BIRD); + effects.AddEffect(TemporaryEffect(deadBird), true, 1); + player.RemoveCostume(deadBird); + } + bool isLust = player.HasCollectible(COLLECTIBLE_BLOODY_LUST); + bool isGust = player.HasCollectible(COLLECTIBLE_BLOODY_GUST); + if (!isLust && !isGust && !player.HasCollectible(COLLECTIBLE_BLOOD_RIGHTS)) return; + if (isLust) effects.AddCollectibleEffect(COLLECTIBLE_BLOODY_LUST, player.playerType != PLAYER_SAMSON, 1); + if (isGust) effects.AddCollectibleEffect(COLLECTIBLE_BLOODY_GUST, true, 1); + player.bloodLustCounter++; +} diff --git a/src/entity_player_characters.h b/src/entity_player_characters.h new file mode 100644 index 0000000..25f15d9 --- /dev/null +++ b/src/entity_player_characters.h @@ -0,0 +1,43 @@ +#pragma once + +#include "entity_player.h" +#include + +constexpr int GIANTBOOK_WHORE_OF_BABYLON = 3; + +// The buttons Jacob and Esau share: the item button and the pocket button. +enum TwinButton +{ + TWIN_BUTTON_ITEM, + TWIN_BUTTON_POCKET +}; + +// What a character's type adds to each section of the stat evaluation (00763570). +float character_tears_get(Entity_Player& player); +float character_tears_penalty_get(Entity_Player& player); +float character_damage_scale_get(Entity_Player& player); +float character_damage_get(Entity_Player& player); +float character_shot_speed_get(Entity_Player& player); +float character_range_get(Entity_Player& player); +float character_speed_get(Entity_Player& player); +float character_luck_get(Entity_Player& player); +void twins_speed_share(Entity_Player& player); +bool is_character_slowed(Entity_Player& player); + +bool is_eden(const Entity_Player& player); +bool is_azazel(Entity_Player& player); +bool is_character_reconstructed(const Entity_Player& player); + +// Eve's Whore of Babylon and Tainted Eve's last heart (007c9ea0). +bool is_whore_of_babylon_awake(Entity_Player& player); +void tainted_eve_babylon_try(Entity_Player& player); + +// Jacob and Esau's shared buttons (00791a40, 007a3d30). +ButtonAction twin_button_action(Entity_Player& player, TwinButton button); +bool is_twin_button_blocked(Entity_Player& player, TwinButton button); + +// The end of a death that revived the first of the pair (007a1090). +void revived_players_settle(std::vector& players, int oldType); + +// Eve's Dead Bird and Samson's Bloody Lust answering a hit (007729d0). +void character_items_hit(Entity_Player& player); diff --git a/src/entity_player_damage.cpp b/src/entity_player_damage.cpp index e5ff349..2d1479c 100644 --- a/src/entity_player_damage.cpp +++ b/src/entity_player_damage.cpp @@ -1,6 +1,7 @@ #include "entity_familiar.h" #include "entity_npc.h" #include "entity_player.h" +#include "entity_player_characters.h" #include "game.h" #include "level.h" #include "log.h" @@ -34,8 +35,8 @@ constexpr int SAMSON_B_HIT_CHARGE = 10000; constexpr int BLEED_OUT_HEALTH = 600; // The items and trinkets a landed hit sets off, by id, from Infestation's flies to Tonsil and Pinking Shears. -constexpr int HIT_COLLECTIBLES[] = {148, 525, 658, 696, 162, 117, 610, 274, 156, 180, 214, 204, 219, 225, 227, 211, 262, - 301, 303, 392, 157, 695, 186, 371, 407, 412, 448, 452, 560, 675, 702, 502, 513}; +constexpr int HIT_COLLECTIBLES[] = {148, 525, 658, 696, 162, 610, 274, 156, 180, 214, 204, 219, 225, 227, 211, 262, + 301, 303, 392, 371, 407, 412, 448, 452, 560, 675, 702, 502, 513}; constexpr int HIT_TRINKETS[] = {40, 48, 29, 1, 8, 67, 158, 97, 105, 33, 104, 122}; constexpr int CROWN_OF_LIGHT = 415; constexpr int HYPERCOAGULATION_IGNORED = 0x10040000; @@ -323,7 +324,8 @@ static void hearts_remove(Entity_Player& player, int amount, uint64_t damageFlag if (player.goldenHearts < golden) player.BreakGoldenHearts(golden - player.goldenHearts); } -// The items a landed hit sets off, none written yet, then Tainted Samson's rage. Bleeding out restarts its timer. +// The items a landed hit sets off, Eve's Dead Bird and Samson's Bloody Lust the only ones written yet, then Tainted +// Samson's rage. Bleeding out restarts its timer. static void hit_items_check(Entity_Player& player, uint64_t damageFlags, bool isPenalized) { bool isItemHit = std::ranges::any_of(HIT_COLLECTIBLES, [&](int item) { return player.HasCollectible(item); }) || @@ -333,6 +335,7 @@ static void hit_items_check(Entity_Player& player, uint64_t damageFlags, bool is (player.HasCollectible(COLLECTIBLE_HYPERCOAGULATION) && !(damageFlags & HYPERCOAGULATION_IGNORED)) || std::ranges::any_of(player.activeItems, [](const ActiveItemDesc& active) { return active.item == COLLECTIBLE_LARYNX; }); if (isItemHit) reconstruction_missing("Entity_Player::TakeDamage 007729d0 (the items and trinkets a hit sets off)"); + character_items_hit(player); if (player.playerType == PLAYER_SAMSON_B && (player.redHearts > 0 || player.soulHearts > 0 || player.boneHearts > 0)) player.add_samson_berserk_charge(SAMSON_B_HIT_CHARGE); diff --git a/src/entity_player_death.cpp b/src/entity_player_death.cpp index fe0ee63..39b56df 100644 --- a/src/entity_player_death.cpp +++ b/src/entity_player_death.cpp @@ -2,6 +2,7 @@ #include "entity_familiar.h" #include "entity_list.h" #include "entity_player.h" +#include "entity_player_characters.h" #include "game.h" #include "item_config.h" #include "log.h" @@ -9,6 +10,7 @@ #include "platform.h" #include "player_manager.h" #include "room.h" +#include "sfx_manager.h" #include #include #include @@ -16,7 +18,6 @@ constexpr int COLLECTIBLE_CHARM_VAMPIRE = 62; constexpr int COLLECTIBLE_ANKH = 161; constexpr int COLLECTIBLE_JUDAS_SHADOW = 311; -constexpr int COLLECTIBLE_LAZARUS_RAGS = 332; constexpr int COLLECTIBLE_POLYDACTYLY = 454; constexpr int TRINKET_AAA_BATTERY = 3; constexpr int TRINKET_BROKEN_ANKH = 28; @@ -30,13 +31,7 @@ constexpr int ACHIEVEMENT_THE_LOST = 82; constexpr int BABY_FOUND_SOUL = 59; constexpr int CLOT_SUBTYPE_UNCOUNTED = 7; constexpr int SPECIAL_DAILY_SHUFFLED_ITEMS = 7; -constexpr uint32_t QUEUED_TOUCHED = 0x1; -constexpr int SOUND_BLOOD_LASER = 5; -constexpr int SOUND_BLOOD_LASER_LARGE = 7; -constexpr int SOUND_MONSTER_YELL_A = 119; -constexpr int SOUND_REDLIGHTNING_ZAP = 133; -constexpr int SOUND_ISAACDIES = 217; constexpr int SOUND_ITEMRECHARGE = 218; constexpr float DEATH_FRICTION = 0.6f; @@ -90,6 +85,8 @@ static bool is_missing_poster_unlocked() return manager.persistentGameData.achievements[ACHIEVEMENT_THE_LOST] || isExemptRun; } +constexpr const char* LAZARUS_RISING = "Lazarus rising"; + // What revives a dying player and its twin, in the order the game tries them, or null. Broken Ankh's roll draws from // its RNG even when the death is only checked. A Missing Poster still locked ends the search. static const char* revival_find(Entity_Player& player, std::vector& players) @@ -104,7 +101,7 @@ static const char* revival_find(Entity_Player& player, std::vectorpersistentGameData.TryUnlock(ACHIEVEMENT_THE_LOST); + int firstType = players[0]->playerType; const char* revival = revival_find(*this, players); if (isCheckOnly) return revival || (trinket_holder_find(players, TRINKET_MISSING_POSTER) && isSacrificeRoom); - if (revival) reconstruction_missing(revival); + if (revival == LAZARUS_RISING) players[0]->collectible_revive(COLLECTIBLE_LAZARUS_RAGS, true); + else if (revival) reconstruction_missing(revival); for (Entity_Player* player : players) { @@ -166,7 +166,11 @@ bool Entity_Player::TriggerDeath(bool isCheckOnly) if (first.isDead && !first.parent && playerManager.IsCoopPlay() && playerManager.GetNumAlivePlayers() > 1 && !first.isCoopGhost) for (Entity_Player* player : players) player->MorphToCoopGhost(); - if (!first.isDead) reconstruction_missing("Entity_Player::TriggerDeath 007a1090 (a co-op ghost's return)"); + if (!first.isDead) + { + revived_players_settle(players, firstType); + return true; + } if (first.parent && first.variant == PLAYER_VARIANT_PLAYER && first.parent->is_player()) reconstruction_missing("Entity_Player::TriggerDeath 007a1090 (a helper player's death)"); diff --git a/src/entity_player_evaluate.cpp b/src/entity_player_evaluate.cpp index 48ce093..555c936 100644 --- a/src/entity_player_evaluate.cpp +++ b/src/entity_player_evaluate.cpp @@ -1,6 +1,7 @@ #include "entity_player.h" #include "active_items.h" #include "entity_familiar.h" +#include "entity_player_characters.h" #include "entity_tear.h" #include "game.h" #include "lua_engine.h" @@ -66,8 +67,8 @@ constexpr int COOP_BUFF_LUCK = 4; // Berserk!, Jupiter, Dogma, Purity. constexpr std::array EVALUATION_UNHANDLED_ITEMS = {671, 686, 240, 304, 562, 493, 654, 407, 625, 704, 594, 633, 556}; // The weapon items, which the frame does not handle yet: Ludovico, Tech X, Spirit Sword, C Section, Dr. Fetus, -// Technology, Mom's Knife, Brimstone, Epic Fetus, Monstro's Lung. -constexpr std::array WEAPON_ITEMS = {329, 395, 579, 678, 52, 68, 114, 118, 168, 229}; +// Mom's Knife, Brimstone, Epic Fetus, Monstro's Lung. +constexpr std::array WEAPON_ITEMS = {329, 395, 579, 678, 52, 114, 118, 168, 229}; // The constants of the other sections: the collectibles, trinkets, null items and characters they ask about. constexpr int PILL_TEARS_UP = 16; @@ -118,7 +119,7 @@ bool Entity_Player::is_character_plain() { Game& game = *g_game; bool isSmelted = std::ranges::any_of(smeltedTrinkets, [](SmeltedTrinket& t) { return t.count || t.goldenCount; }); - return playerType == PLAYER_ISAAC && variant == PLAYER_VARIANT_PLAYER && !isCoopGhost && !hasCurseMistEffect && + return is_character_reconstructed(*this) && variant == PLAYER_VARIANT_PLAYER && !isCoopGhost && !hasCurseMistEffect && game.challenge == 0 && game.dailyChallenge._id == 0 && game.seedEffects.CountSeedEffects() == 0 && !game.deathmatchManager.is_active() && std::ranges::all_of(temporaryEffects.effects, is_temporary_effect_plain) && @@ -179,9 +180,11 @@ static void fire_delay_evaluate(Entity_Player& p, const StatBonuses& bonus, floa tears = n(438) * 0.75f + tears; tears = n(443) * 0.3f + tears; tears = n(465) * 0.35f + tears; - float bonusTears = bonus.tears * 0.5f; + tears = tears + character_tears_get(p); + float bonusTears = is_eden(p) ? bonus.tears * 0.5f + p.edenFireDelay : bonus.tears * 0.5f; if (bonusTears < 0) bonusTears *= NEGATIVE_TEARS_SCALE; tears = bonusTears + tears; + tears = tears - character_tears_penalty_get(p); if (p.HasPlayerForm(PLAYER_FORM_CONJOINED)) tears = tears - 0.3f; if (p.coopBabyBuffTimers[COOP_BUFF_TEARS] > 0) tears = tears + 1; @@ -224,7 +227,13 @@ static void fire_delay_evaluate(Entity_Player& p, const StatBonuses& bonus, floa if (p.HasWeaponType(WEAPON_MONSTROS_LUNGS)) charge *= 0.5f; rate = rate - charge * rate / (FIRE_RATE_FRAMES / rate + charge); } - if (p.HasWeaponType(WEAPON_BRIMSTONE)) rate /= 3; + if (p.HasWeaponType(WEAPON_BRIMSTONE)) + { + rate /= 3; + if ((p.playerType == PLAYER_AZAZEL || p.temporaryEffects.HasTrinketEffect(TRINKET_AZAZELS_STUMP)) && + !has(COLLECTIBLE_BRIMSTONE)) + rate /= 1.25f; + } else if (p.HasWeaponType(WEAPON_BOMBS)) rate /= 2.5f; else if (p.HasWeaponType(WEAPON_BONE)) rate *= 0.5f; if (has(152)) rate /= 1.5f; @@ -263,6 +272,9 @@ static void damage_evaluate(Entity_Player& p, const StatBonuses& bonus, float cr if (p.redStewBonusDuration > 0 && !p.temporaryEffects.isDisabled) damage = (float)(p.redStewBonusDuration / 10) * 0.04f + damage; if (has(716)) damage = (float)((p.keepersSackBonus / 3 + 2) / 3) * 0.5f + damage; + for (TemporaryEffect* babylon : {p.temporaryEffects.GetCollectibleEffect(COLLECTIBLE_WHORE_OF_BABYLON), + p.temporaryEffects.GetNullEffect(NULLITEM_BLOODY_BABYLON)}) + if (babylon) damage = (float)(babylon->count * babylon->count) * 1.5f + damage; if (p.grantedCollectibleCountdown > 0) damage = damage + 1; int ups = n(708) + n(592) + n(572) + n(531) + n(345) + n(328) + n(259) + n(208) + n(206) + n(165) + n(121) + @@ -278,11 +290,17 @@ static void damage_evaluate(Entity_Player& p, const StatBonuses& bonus, float cr if (has(694)) damage = (float)p.brokenHearts * 0.25f + damage; if (has(120)) damage = damage * 0.9f - 0.4f; if (p.coopBabyBuffTimers[COOP_BUFF_DAMAGE] > 0) damage = damage + 2; + if (TemporaryEffect* boost = p.temporaryEffects.GetNullEffect(NULLITEM_LAZARUS_BOOST)) + damage = (float)boost->count * 0.5f + damage; damage = std::sqrt(std::max(damage * DAMAGE_CURVE_SCALE + 1, 0.0f)) * DAMAGE_BASE; if (has(169)) damage = !has(2) && !has(153) && !p.HasWeaponType(WEAPON_FETUS) && !has(245) ? damage + 4 + damage + 4 : damage + 5; + damage = damage * character_damage_scale_get(p); + damage = damage + character_damage_get(p); + if (p.playerType == PLAYER_THEFORGOTTEN && p.temporaryEffects.HasNullEffect(NULLITEM_SOUL_FORGOTTEN)) + damage = (damage + 2) * 3; damage = (float)(p.potatoPeelerBandageCounter + p.potatoPeelerCounter) * 0.2f + damage; damage = std::max((float)p.damageModifier + bonus.damage + damage, DAMAGE_MIN); if (has(513)) damage = damage + 0.1f; @@ -296,6 +314,14 @@ static void damage_evaluate(Entity_Player& p, const StatBonuses& bonus, float cr float lust = std::clamp((float)p.bloodLustCounter, 0.0f, cap); damage = lust * 0.1f * lust + lust * 0.4f + damage; } + if (is_azazel(p) && !has(COLLECTIBLE_BRIMSTONE)) + { + if (p.HasWeaponType(WEAPON_BRIMSTONE) && has(COLLECTIBLE_LUDOVICO)) damage = damage * 0.5f; + else if (p.HasWeaponType(WEAPON_TECH_X)) damage = damage * 0.65f; + } + bool isTechBrimstone = p.HasWeaponType(WEAPON_TECH_X) && has(COLLECTIBLE_BRIMSTONE); + if (p.HasWeaponType(WEAPON_BRIMSTONE) && n(COLLECTIBLE_BRIMSTONE) >= 2) damage = damage * 1.2f; + else if ((p.HasWeaponType(WEAPON_BRIMSTONE) || isTechBrimstone) && has(COLLECTIBLE_TECHNOLOGY)) damage = damage * 1.5f; if (has(531)) damage = damage * 1.5f; float melee = damage; @@ -381,6 +407,7 @@ static void shot_speed_evaluate(Entity_Player& p, const StatBonuses& bonus, floa speed = speed - (float)mascara * 0.5f; speed = speed - (float)n(336) * 0.4f; speed = speed - (float)n(331) * 0.3f; + speed = speed + character_shot_speed_get(p); speed = ((float)p.shotSpeedModifier + bonus.shotSpeed) * 0.2f + (float)n(329) * 0.2f + speed; if (p.coopBabyBuffTimers[COOP_BUFF_RANGE] > 0) speed = speed + 0.5f; speed = (float)n(554) * 0.2f + speed; @@ -399,7 +426,7 @@ static void range_evaluate(Entity_Player& p, const StatBonuses& bonus, float cro auto n = [&](int id) { return (float)p.GetCollectibleNum(id); }; auto has = [&](int id) { return p.HasCollectible(id); }; - p.tearRange = RANGE_BASE; + p.tearRange = RANGE_BASE + character_range_get(p); p.tearHeight = TEAR_HEIGHT_BASE; p.tearFallingSpeed = 0; p.tearFallingAcceleration = 0; @@ -469,7 +496,9 @@ static void speed_evaluate(Entity_Player& p, const StatBonuses& bonus, float cro float pills = pill_uses(p, PILL_SPEED_UP) * 0.5f - pill_uses(p, PILL_SPEED_DOWN) * 0.4f; int rollers = p.g_fuel_count() < 1 ? n(143) : 0; float ups = (float)(n(232) + n(119) + n(28) + n(27)) + pills; - for (int id : {340, 12, 71, 101, 120}) ups = (float)n(id) + ups; + for (int id : {340, 12, 71, 101}) ups = (float)n(id) + ups; + ups = (float)p.temporaryEffects.GetCollectibleEffectNum(COLLECTIBLE_WHORE_OF_BABYLON) + ups; + ups = (float)n(120) + ups; ups = ups + (float)rollers; ups = (float)n(82) + ups; ups = (float)n(571) + ups; @@ -480,8 +509,9 @@ static void speed_evaluate(Entity_Player& p, const StatBonuses& bonus, float cro int sharp = std::min(n(14), 1); int slow = std::min(n(13), 1); float speed = (float)((((slow - n(90)) - n(129)) - n(121)) + n(669) + n(189) + n(79)) * 0.2f + - (float)sharp * 0.3f + 1 + steady + quick; + (float)sharp * 0.3f + character_speed_get(p) + 1 + steady + quick; p.moveSpeed = ((float)p.speedModifier + bonus.speed) * 0.2f + (float)n(445) * 0.1f + speed; + if (is_character_slowed(p)) p.moveSpeed = p.moveSpeed - 0.1f; if (has(695) && !p.temporaryEffects.isDisabled) { @@ -517,6 +547,7 @@ static void luck_evaluate(Entity_Player& p, const StatBonuses& bonus) luck = n(669) + luck; luck = (float)(p.GetCollectibleNum(632) * 2) + luck; p.luck = n(730) + luck; + p.luck = p.luck + character_luck_get(p); int wisps = 0; for (Entity* entity : g_game->room->entityList.updateEL) @@ -982,6 +1013,7 @@ void Entity_Player::EvaluateItems() if ((cacheFlags & CACHE_SIZE) && variant == PLAYER_VARIANT_PLAYER) size_evaluate(*this); if (cacheFlags & CACHE_COLOR) color_evaluate(*this); + twins_speed_share(*this); if ((cacheFlags & CACHE_SPEED) && std::ranges::any_of(g_game->playerManager.playerList, [this](Entity_Player* other) { return other->parent == this; })) reconstruction_missing("Entity_Player::EvaluateItems 00763570 (the speed of a player's helpers)"); diff --git a/src/entity_player_footprints.cpp b/src/entity_player_footprints.cpp new file mode 100644 index 0000000..f0d0ad3 --- /dev/null +++ b/src/entity_player_footprints.cpp @@ -0,0 +1,48 @@ +#include "entity_player.h" +#include "game.h" +#include "item_config.h" + +// Without a costume that steps, a player steps every 6 frames, with the left foot every 12. +constexpr int FOOTSTEP_PERIOD = 6; +constexpr int LEFT_FOOTSTEP_PERIOD = 12; + +// The feet is_footstep_triggered asks about. +constexpr int FOOT_ANY = -1; +constexpr int FOOT_LEFT = 0; + +// 007b9940 Whether the player stepped this frame, with any foot or the left one. Mega Mush's body costume steps on its +// animation's events, any other player on a steady cadence while walking on the ground and the game runs. +bool Entity_Player::is_footstep_triggered(int foot) +{ + int index = playerCostumeMap[PLAYER_LAYER_BODY].index; + if (index >= 0) + { + ANM2& costume = costumeSpriteDescs[index].sprite; + ItemConfig_Item* item = costumeSpriteDescs[index].item; + if (item && item->type == ITEM_ACTIVE && item->id == COLLECTIBLE_MEGA_MUSH) + { + if (foot == FOOT_LEFT) return costume.IsEventTriggered("LeftFootstep"); + if (foot != FOOT_ANY) return false; + return costume.IsEventTriggered("LeftFootstep") || costume.IsEventTriggered("RightFootstep"); + } + } + + Game& game = *g_game; + bool isStepping = !HasEntityFlags(FLAG_INTERPOLATION_UPDATE) && !game.IsPaused() && + game.frameCount % FOOTSTEP_PERIOD == 0 && !canFly; + bool isLeftStepping = isStepping && !game.IsPaused() && game.frameCount % LEFT_FOOTSTEP_PERIOD == 0; + if (foot == FOOT_ANY) return isStepping; + return foot == FOOT_LEFT && isLeftStepping; +} + +// 007b98c0 Stains the footprint of the foot stepping now (or of the next step, when isAnyFrame) in a color, for a +// player walking on the ground. +void Entity_Player::SetFootprintColor(KColor footColor, bool isAnyFrame) +{ + if ((!is_footstep_triggered(FOOT_ANY) && !isAnyFrame) || canFly) return; + + ColorMod& footprint = is_footstep_triggered(FOOT_LEFT) ? footprintColor2 : footprintColor1; + footprint._offset[0] = footColor._red; + footprint._offset[1] = footColor._green; + footprint._offset[2] = footColor._blue; +} diff --git a/src/entity_player_frame.cpp b/src/entity_player_frame.cpp index 6e85e43..ac3c354 100644 --- a/src/entity_player_frame.cpp +++ b/src/entity_player_frame.cpp @@ -271,9 +271,13 @@ void Entity_Player::update_body_animations() if ((playerType == PLAYER_THEFORGOTTEN_B && !isCoopGhost) || suplexState != 0 || isDarkArtsBlastPending) reconstruction_missing( "Entity_Player::update_body_animations 00779b40 (Tainted Forgotten, suplexes and Dark Arts)"); - if (playerType == PLAYER_JACOB || playerType == PLAYER_ESAU || playerType == PLAYER_LAZARUS_B || - playerType == PLAYER_LAZARUS2_B || playerType == PLAYER_EVE_B) - reconstruction_missing("Entity_Player::update_body_animations 00779b40 (twins and Tainted Eve)"); + bool isPair = playerType == PLAYER_JACOB || playerType == PLAYER_ESAU || playerType == PLAYER_LAZARUS_B || + playerType == PLAYER_LAZARUS2_B; + if ((isPair && twin_get()) || playerType == PLAYER_EVE_B) + { + Vector leaderInput = GetMainTwin()->GetMovementJoystick(); + if (leaderInput.x != 0 || leaderInput.y != 0) actionHoldDrop = 0; + } if (temporaryEffects.HasNullEffect(NULLITEM_REVERSE_CHARIOT) || ponyCharge > 0) reconstruction_missing("Entity_Player::update_body_animations 00779b40 (the Chariot and pony dashes)"); reverseChariotMoveCooldown = 0; @@ -739,7 +743,7 @@ void Entity_Player::Render(const Vector& offset) if (playerHUD) reconstruction_missing("Entity_Player::Render 0078ca00 (the player's HUD bubble)"); if (g_game->playerManager.playerList.size() > 1 && g_game->roomTransition.mode == TRANSITION_NONE) - reconstruction_missing("Entity_Player::Render 0078ca00 (the co-op player indicator)"); + coop_indicator_render(); if (!isDead) { render_charge_bars(renderPosition); diff --git a/src/entity_player_health.cpp b/src/entity_player_health.cpp index dce2298..5300f0f 100644 --- a/src/entity_player_health.cpp +++ b/src/entity_player_health.cpp @@ -2,6 +2,7 @@ #include "game.h" #include "entity_effect.h" #include "entity_pickup.h" +#include "entity_player_characters.h" #include "item_overlay.h" #include "manager.h" #include "room_grid.h" @@ -355,6 +356,31 @@ void Entity_Player::hud_heart_flash() } } +// 007791f0 Fills the red hearts (The Soul fills The Forgotten's), the bone hearts too unless the character keeps +// soul hearts or none. The HUD flashes unless hearts were lost, and golden hearts left without a heart break. +void Entity_Player::SetFullHearts() +{ + Entity_Player* owner = this; + while (owner->playerType == PLAYER_THESOUL && owner->subPlayer) owner = owner->subPlayer; + + int oldRedHearts = owner->redHearts; + HealthType health = owner->GetHealthType(); + bool isBoneless = health == HEALTH_SOUL || health == HEALTH_NO_HEALTH; + owner->redHearts = isBoneless ? owner->maxHearts : owner->maxHearts + owner->boneHearts * 2; + if (owner->redHearts >= oldRedHearts) owner->hud_heart_flash(); + owner->UpdateHeartDependentEffects(); + if (!g_game->deathmatchManager.is_active() && !owner->isDead && owner->goldenHearts > 0) + { + int holders = owner->golden_holders_count(); + if (holders < owner->goldenHearts) + { + owner->BreakGoldenHearts(owner->goldenHearts - holders); + owner->goldenHearts = holders; + } + } + owner->update_bone_hearts(); +} + // 00758f90 Adds black hearts as soul hearts marked black, or flies for Keeper. Near the limit it turns the existing // soul hearts black from the last one back instead. Golden hearts left without a heart to sit on break. void Entity_Player::AddBlackHearts(int amount) @@ -573,15 +599,14 @@ void Entity_Player::UpdateHeartDependentEffects() update_greeds_gullet(); if (!isDead && playerType == PLAYER_EVE_B && boneHearts + goldenHearts + soulHearts + eternalHearts + redHearts == 1) - reconstruction_missing("Entity_Player::UpdateHeartDependentEffects 007c9ea0 (Tainted Eve's last heart)"); - - int lowRed = isDeathmatch ? 16 : 1; - if (!isDead && redHearts <= lowRed) + tainted_eve_babylon_try(*this); + if (!isDead && is_whore_of_babylon_awake(*this)) if (HasCollectible(COLLECTIBLE_WHORE_OF_BABYLON) && !temporaryEffects.HasCollectibleEffect(COLLECTIBLE_WHORE_OF_BABYLON)) - reconstruction_missing("Entity_Player::UpdateHeartDependentEffects 007c9ea0 (Whore of Babylon)"); - if (!isDead && playerType == PLAYER_EVE && redHearts > lowRed) - reconstruction_missing("Entity_Player::UpdateHeartDependentEffects 007c9ea0 (Eve's Whore of Babylon)"); + { + if (isPostLevelInitFinished) game.itemOverlay.Show(GIANTBOOK_WHORE_OF_BABYLON, 3, nullptr); + temporaryEffects.AddCollectibleEffect(COLLECTIBLE_WHORE_OF_BABYLON, true, 1); + } if (HasCollectible(COLLECTIBLE_CROWN_OF_LIGHT) || HasCollectible(COLLECTIBLE_DARK_PRINCES_CROWN)) reconstruction_missing("Entity_Player::UpdateHeartDependentEffects 007c9ea0 (the crowns)"); diff --git a/src/entity_player_items.cpp b/src/entity_player_items.cpp index a082215..3b2a5b2 100644 --- a/src/entity_player_items.cpp +++ b/src/entity_player_items.cpp @@ -493,14 +493,14 @@ int Entity_Player::GetZodiacEffect() return ZODIAC_SIGNS[((seed >> ROLL_SHIFTS[2]) ^ seed) % ZODIAC_SIGNS.size()]; } -// 007a8350 The effects a new room gives back: Holy Mantle's shield (and the Blanket's in a boss room), the shields -// Holy Mantle stacks and Holy Card keep, Camo Undies, and the effects of the items that last the floor. A shield -// broken in the last room is taken away first. The other items and trinkets with room effects stop the game until -// reached. +// 007a8350 The effects a new room gives back: Holy Mantle's shield (and the Blanket's in a boss room), Whore of +// Babylon at one red heart (Eve's at two, or always with her Birthright), the shields Holy Mantle stacks and Holy Card +// keep, Camo Undies, and the effects of the items that last the floor. A shield broken in the last room is taken away +// first. The other items and trinkets with room effects stop the game until reached. void Entity_Player::TriggerNewRoom_TemporaryEffects() { - // Redemption, Taurus, Whore of Babylon, Empty Vessel, Scapular, Purity, the crowns and Sol. - constexpr int ROOM_ITEMS[] = {673, 299, 122, 409, 142, 407, 415, 442, 588}; + // Redemption, Taurus, Empty Vessel, Scapular, Purity, the crowns and Sol. + constexpr int ROOM_ITEMS[] = {673, 299, 409, 142, 407, 415, 442, 588}; // Liberty Cap, Broken Syringe, Mom's Lock, Modeling Clay, Umbilical Cord and Dice Bag. constexpr int ROOM_TRINKETS[] = {32, 132, 153, 166, 33, 154}; constexpr int BLANKET = 535; @@ -535,6 +535,12 @@ void Entity_Player::TriggerNewRoom_TemporaryEffects() temporaryEffects.isDisabled ? nullptr : temporaryEffects.GetCollectibleEffect(COLLECTIBLE_HOLY_MANTLE); if (!shield || shield->count < 1) RemoveCostume(mantle); } + if (HasCollectible(COLLECTIBLE_WHORE_OF_BABYLON) && !temporaryEffects.HasCollectibleEffect(COLLECTIBLE_WHORE_OF_BABYLON)) + { + TryRemoveCollectibleCostume(COLLECTIBLE_WHORE_OF_BABYLON, false); + bool isEveAwake = playerType == PLAYER_EVE && (redHearts < 3 || HasCollectible(COLLECTIBLE_BIRTHRIGHT)); + if (redHearts < 2 || isEveAwake) temporaryEffects.AddCollectibleEffect(COLLECTIBLE_WHORE_OF_BABYLON, true, 1); + } for (int i = 0; mantle && i < holyMantleStacks >> 4; i++) temporaryEffects.AddEffect(TemporaryEffect(mantle), true, 1); @@ -1347,6 +1353,26 @@ constexpr int COLLECTIBLE_HOLY_GRAIL = 184; constexpr int SPECIAL_DAILY_COSTUME_PRIORITY = 13; constexpr int DAILY_COSTUME_PRIORITY_BONUS = 3; +// Whether a costume is one of Eden's hairs, whose sheet the hair roll picked. +static bool is_eden_hair(const ItemConfig_Item* item) +{ + return item && item->type == ITEM_NULL && (item->id == NULLITEM_EDEN_HAIR || item->id == NULLITEM_EDEN_HAIR_B); +} + +// Gives Eden's hair costume the hairstyle its init seed picks among those the config lists. With none listed the +// original divides by zero, the costume keeps its own sheet here. +void Entity_Player::eden_hair_apply(ANM2& hair) +{ + std::vector& hairs = g_manager->entityConfig.edenHair; + + if (hairs.empty()) + { + KAGE_LogMessage(LOG_ASSERT, (uint8_t*)"Eden has no hair!\n"); + return; + } + hair.ReplaceSpritesheet(0, hairs[initSeed % hairs.size()]); +} + // The costume an item puts on for its copies: a second Brimstone and the two doubled collectibles wear a null item's. static ItemConfig_Item* costume_item_get(Entity_Player& player, ItemConfig_Item* item) { @@ -1400,8 +1426,7 @@ void Entity_Player::AddCostume(ItemConfig_Item* item, bool isItemStateOnly) item->id == COLLECTIBLE_SACK_HEAD_COSTUME) costume.priority += DAILY_COSTUME_PRIORITY_BONUS; costume.sprite.Load(item->costume.anm2Path, GRAPHICS_DEFER); - bool isEdenHair = item->type == ITEM_NULL && (item->id == NULLITEM_EDEN_HAIR || item->id == NULLITEM_EDEN_HAIR_B); - if (isEdenHair) reconstruction_missing("Entity_Player::AddCostume 0075d1d0 (Eden's hair)"); + if (is_eden_hair(item)) eden_hair_apply(costume.sprite); costume.sprite.LoadGraphics(); bool isHead = false; @@ -1422,10 +1447,20 @@ void Entity_Player::AddCostume(ItemConfig_Item* item, bool isItemStateOnly) } // The UpdateCostumes part that hands the player's layers to the worn costumes of highest priority (a costume covering -// head and body uses its two copies), skipping body layers a flying player does not show of a walking costume. -// Whether the head or body color would change, which is not reconstructed yet. -void Entity_Player::costume_layers_map(int skinColor) +// head and body uses its two copies), skipping body layers a flying player does not show of a walking costume. A +// costume that overwrites the skin color gives its own to the head or body it covers, or to those its item forces, +// the costume of highest priority winning. +void Entity_Player::costume_layers_map(SkinColors& colors) { + int headPriority = -1; + int bodyPriority = -1; + auto color_take = [](const CostumeSpriteDesc& costume, int& color, int& priority) + { + if (costume.priority < priority) return; + color = costume.defaultSkinColor; + priority = costume.priority; + }; + for (int index = 0; index < (int)costumeSpriteDescs.size(); index++) { CostumeSpriteDesc& costume = costumeSpriteDescs[index]; @@ -1441,7 +1476,14 @@ void Entity_Player::costume_layers_map(int skinColor) std::string_view layerName = own && own->layerData ? std::string_view(own->layerData->name) : ""; LayerState* worn = costume.sprite.GetLayer(layerName); if (!worn) continue; - if (costume.priority < map.priority || (canFly && !costume.isFlying && map.isBodyLayer)) continue; + bool isColorTaken = costume.isOverwriteColor && (layer == PLAYER_LAYER_HEAD || layer == PLAYER_LAYER_BODY); + int& color = layer == PLAYER_LAYER_HEAD ? colors.head : colors.body; + int& priority = layer == PLAYER_LAYER_HEAD ? headPriority : bodyPriority; + if (costume.priority < map.priority || (canFly && !costume.isFlying && map.isBodyLayer)) + { + if (isColorTaken) color_take(costume, color, priority); + continue; + } if (matched != 0 && bodyIndex == headIndex && layer != 0 && map.isBodyLayer != wasBody) { @@ -1453,11 +1495,15 @@ void Entity_Player::costume_layers_map(int skinColor) map.layerId = worn->layerData ? worn->layerData->id : -1; map.priority = costume.priority; matched++; - if (costume.defaultSkinColor != skinColor && (layer == PLAYER_LAYER_HEAD || layer == PLAYER_LAYER_BODY)) - reconstruction_missing("Entity_Player::UpdateCostumes 0075bf00 (a costume's skin color)"); + if (!isColorTaken) continue; + color = costume.defaultSkinColor; + color_take(costume, color, priority); + } + if (costume.isOverwriteColor && costume.item) + { + if (costume.item->costume.isForceHeadColor) color_take(costume, colors.head, headPriority); + if (costume.item->costume.isForceBodyColor) color_take(costume, colors.body, bodyPriority); } - if (costume.item && (costume.item->costume.isForceHeadColor || costume.item->costume.isForceBodyColor)) - reconstruction_missing("Entity_Player::UpdateCostumes 0075bf00 (a costume forcing the skin color)"); index = std::max(bodyIndex, headIndex); } } @@ -1476,7 +1522,7 @@ void Entity_Player::costume_skin_apply(CostumeSpriteDesc& costume, int skinColor bool isPlaying = costume.sprite.animState.animData && costume.sprite.animState.isPlaying; int frame = (int)costume.sprite.animState.animFrame; - for (int layer = 0; layer < (int)costume.sprite.layerStates.size(); layer++) + for (int layer = 0; layer < (int)costume.sprite.layerStates.size() && !is_eden_hair(costume.item); layer++) { LayerState* state = costume.sprite.GetLayer(layer); std::string path = state && state->layerData ? state->layerData->spriteSheetPath : std::string(); @@ -1488,7 +1534,7 @@ void Entity_Player::costume_skin_apply(CostumeSpriteDesc& costume, int skinColor if (LayerState* recolored = costume.sprite.GetLayer(layer)) recolored->color = COLOR_DEFAULT; isAnyFound |= isSkinFound || isCharacterFound; } - if (isAlt && !isAnyFound) + if (isAlt && !isAnyFound && !is_eden_hair(costume.item)) log_printf(LOG_INFO, "Costume %s supports skin color alts but no alt spritesheet could be found! (skin color %d)\n", costume.sprite.filename.c_str(), skinColor); costume.skinColor = skinColor; @@ -1531,22 +1577,22 @@ void Entity_Player::UpdateCostumes() EntityConfig_Player* playerConfig = g_manager->entityConfig.GetPlayer(playerType); if (!playerConfig) log_printf(LOG_ASSERT, "Could not load config for player type %d\n", playerType); int skinColor = playerConfig ? playerConfig->skinColor : -1; + SkinColors colors{skinColor, skinColor}; costume_map_reset(-1); - if (!isCoopGhost) costume_layers_map(skinColor); + if (!isCoopGhost) costume_layers_map(colors); for (int layer = 0; layer < COSTUME_LAYER_COUNT; layer++) { int index = playerCostumeMap[layer].index; if (index < 0) continue; CostumeSpriteDesc& costume = costumeSpriteDescs[index]; - bool isDressed = (!costume.isHasSkinAlt || costume.skinColor == skinColor) && costume.playerType == playerType; - if (costume.item && costume.item->type == ITEM_NULL && - (costume.item->id == NULLITEM_EDEN_HAIR || costume.item->id == NULLITEM_EDEN_HAIR_B)) - reconstruction_missing("Entity_Player::UpdateCostumes 0075bf00 (Eden's hair)"); - if (!isDressed) costume_skin_apply(costume, skinColor); + bool isBody = playerCostumeMap[layer].isBodyLayer; + bool isColored = (costume.skinColor == colors.head || isBody) && (costume.skinColor == colors.body || !isBody); + bool isDressed = (!costume.isHasSkinAlt || isColored) && costume.playerType == playerType; + int color = costume.skinColor != colors.body && isBody ? colors.body : colors.head; + if (!isDressed) costume_skin_apply(costume, color); } - if (headColor != skinColor || bodyColor != skinColor) - reconstruction_missing("Entity_Player::UpdateCostumes 0075bf00 (recoloring the skin)"); + if (headColor != colors.head || bodyColor != colors.body) skin_recolor(colors); for (PlayerCostumeMap& map : playerCostumeMap) { diff --git a/src/entity_player_missing.cpp b/src/entity_player_missing.cpp index 056e408..d5d03e4 100644 --- a/src/entity_player_missing.cpp +++ b/src/entity_player_missing.cpp @@ -25,20 +25,14 @@ Entity_Familiar* Entity_Player::AddItemWisp(int, Vector, bool) { reconstruction_missing("Entity_Player::AddItemWisp 005c96f0"); } -void Entity_Player::console_spawn(int*, bool) { reconstruction_missing("Entity_Player::console_spawn 005caa70"); } +void Entity_Player::console_spawn(const DeliriousBoss&, bool) { reconstruction_missing("Entity_Player::console_spawn 005caa70"); } void Entity_Player::ResetDamageCooldown() { reconstruction_missing("Entity_Player::ResetDamageCooldown 0060d090"); } Vector Entity_Player::SpriteScale() { reconstruction_missing("Entity_Player::SpriteScale 0060d0a0"); } bool Entity_Player::IsP2Appearing() { reconstruction_missing("Entity_Player::IsP2Appearing 0065cf60"); } -ColorMod Entity_Player::get_laser_color_copy() -{ - reconstruction_missing("Entity_Player::get_laser_color_copy 00665c20"); -} void Entity_Player::set_last_damage(uint64_t, const EntityRef&) { reconstruction_missing("Entity_Player::set_last_damage 006dad80"); } -void Entity_Player::SetSoulCharge(int) { reconstruction_missing("Entity_Player::SetSoulCharge 006f0020"); } -void Entity_Player::SetBloodCharge(int) { reconstruction_missing("Entity_Player::SetBloodCharge 006f0030"); } PocketItem& Entity_Player::GetPocketItem(int) { reconstruction_missing("Entity_Player::GetPocketItem 00753900"); } void Entity_Player::QueueExtraAnimation(std::string_view) { @@ -92,7 +86,6 @@ bool Entity_Player::TryRemoveSmeltedTrinket(uint32_t) reconstruction_missing("Entity_Player::TryRemoveSmeltedTrinket 00772260"); } bool Entity_Player::replace_trinket() { reconstruction_missing("Entity_Player::replace_trinket 00772530"); } -void Entity_Player::SetFullHearts() { reconstruction_missing("Entity_Player::SetFullHearts 007791f0"); } uint32_t Entity_Player::CanTurnHead() { reconstruction_missing("Entity_Player::CanTurnHead 00782a60"); } void Entity_Player::RemoveCollectibleByHistoryIndex(int, bool) { @@ -104,7 +97,6 @@ Entity_Bomb* Entity_Player::FireBomb(Vector, Vector, Entity*) { reconstruction_missing("Entity_Player::FireBomb 007a0970"); } -void Entity_Player::Revive() { reconstruction_missing("Entity_Player::Revive 007a2220"); } void Entity_Player::ReviveFromTrinket(uint32_t) { reconstruction_missing("Entity_Player::ReviveFromTrinket 007a3430"); } void Entity_Player::remove_twin() { reconstruction_missing("Entity_Player::remove_twin 007a37c0"); } void Entity_Player::AddCard(int) { reconstruction_missing("Entity_Player::AddCard 007a3c10"); } @@ -154,14 +146,6 @@ void Entity_Player::TriggerTrinketRemoved(uint32_t) } void Entity_Player::DonateLuck(int) { reconstruction_missing("Entity_Player::DonateLuck 007b2200"); } void Entity_Player::update_footprints() { reconstruction_missing("Entity_Player::update_footprints 007b8cb0"); } -void Entity_Player::SetFootprintColor(KColor, bool) -{ - reconstruction_missing("Entity_Player::SetFootprintColor 007b98c0"); -} -bool Entity_Player::is_footstep_triggered(int) -{ - reconstruction_missing("Entity_Player::is_footstep_triggered 007b9940"); -} void Entity_Player::update_pitfall() { reconstruction_missing("Entity_Player::update_pitfall 007b9b50"); } void Entity_Player::TryDecreaseGlowingHourglassUses(int, bool) { @@ -190,7 +174,6 @@ uint32_t Entity_Player::GetGlitchBabySubType() { reconstruction_missing("Entity_Player::GetGlitchBabySubType 007c2e90"); } -void Entity_Player::RemoveSkinCostume() { reconstruction_missing("Entity_Player::RemoveSkinCostume 007c3620"); } void Entity_Player::SetShootingCooldown(int) { reconstruction_missing("Entity_Player::SetShootingCooldown 007c37f0"); } void Entity_Player::add_random_stat_up(RNG*) { reconstruction_missing("Entity_Player::add_random_stat_up 007c3980"); } bool Entity_Player::CanUsePill(int) { reconstruction_missing("Entity_Player::CanUsePill 007c40e0"); } @@ -234,11 +217,6 @@ float Entity_Player::GetGreedDonationJamChance(PersistentGameData&) } void Entity_Player::hallowed_ground_add(int) { reconstruction_missing("Entity_Player::hallowed_ground_add 007cbc60"); } void Entity_Player::resolve_tainted_soul() { reconstruction_missing("Entity_Player::resolve_tainted_soul 007cbcb0"); } -void Entity_Player::init_forgotten_twin() { reconstruction_missing("Entity_Player::init_forgotten_twin 007cbcd0"); } -Entity* Entity_Player::spawn_forgotten_body() -{ - reconstruction_missing("Entity_Player::spawn_forgotten_body 007cbef0"); -} bool Entity_Player::SwapForgottenForm(bool, bool) { reconstruction_missing("Entity_Player::SwapForgottenForm 007cc200"); @@ -247,11 +225,6 @@ bool Entity_Player::CanRerollCollectible(int, bool) { reconstruction_missing("Entity_Player::CanRerollCollectible 007ce2a0"); } -void Entity_Player::ChangePlayerType(int, bool) { reconstruction_missing("Entity_Player::ChangePlayerType 007ce6e0"); } -void Entity_Player::player_type_change_prepare(int) -{ - reconstruction_missing("Entity_Player::player_type_change_prepare 007cf610"); -} void Entity_Player::GetGlyphOfBalanceDrop(int*, int*) { reconstruction_missing("Entity_Player::GetGlyphOfBalanceDrop 007d12c0"); @@ -260,23 +233,12 @@ Entity_Familiar* Entity_Player::AddMinisaac(Vector, bool) { reconstruction_missing("Entity_Player::AddMinisaac 007d1860"); } -Entity_Player* Entity_Player::InitTwin(int) { reconstruction_missing("Entity_Player::InitTwin 007d2000"); } bool Entity_Player::TryHoldEntity(Entity*) { reconstruction_missing("Entity_Player::TryHoldEntity 007d2170"); } void Entity_Player::AddFriendlyDip(int, Vector) { reconstruction_missing("Entity_Player::AddFriendlyDip 007d2a00"); } void Entity_Player::ThrowFriendlyDip(int, Vector, Vector) { reconstruction_missing("Entity_Player::ThrowFriendlyDip 007d2a20"); } -void Entity_Player::AddSoulCharge(int) { reconstruction_missing("Entity_Player::AddSoulCharge 007d2ad0"); } -int Entity_Player::GetEffectiveSoulCharge() -{ - reconstruction_missing("Entity_Player::GetEffectiveSoulCharge 007d2b50"); -} -void Entity_Player::AddBloodCharge(int) { reconstruction_missing("Entity_Player::AddBloodCharge 007d2d40"); } -int Entity_Player::GetEffectiveBloodCharge() -{ - reconstruction_missing("Entity_Player::GetEffectiveBloodCharge 007d2dd0"); -} void Entity_Player::AddUrnSouls(uint32_t) { reconstruction_missing("Entity_Player::AddUrnSouls 007d3480"); } void Entity_Player::AddGigaBombs(int) { reconstruction_missing("Entity_Player::AddGigaBombs 007d34f0"); } void Entity_Player::fire_saturnus_tears() { reconstruction_missing("Entity_Player::fire_saturnus_tears 007d3e40"); } diff --git a/src/entity_player_pockets.cpp b/src/entity_player_pockets.cpp index 141efb0..13cf099 100644 --- a/src/entity_player_pockets.cpp +++ b/src/entity_player_pockets.cpp @@ -1,4 +1,5 @@ #include "entity_player.h" +#include "entity_player_characters.h" #include "active_items.h" #include "entity_config.h" #include "entity_familiar.h" @@ -617,7 +618,7 @@ static void pockets_shift(Entity_Player& player) // 007a3d30 Reads the pocket button: a pocket active is used through its slot, else (when the controls allow and no // item is being used) the first card or pill is used and leaves the pockets (a golden pill only now and then), saving -// the rewind state first. The player's familiars may fart for a pill. Jacob and Esau's shared button and Endless +// the rewind state first. The player's familiars may fart for a pill. Jacob and Esau share their buttons. Endless // Nameless' copies are not written yet. void Entity_Player::pocket_use_input() { @@ -634,10 +635,8 @@ void Entity_Player::pocket_use_input() Game& game = *g_game; if (game.stageTransition.state != STAGE_TRANSITION_NONE || game.roomTransition.is_active() || IsHologram()) return; - if (playerType == PLAYER_JACOB || playerType == PLAYER_ESAU) - reconstruction_missing("Entity_Player::pocket_use_input 007a3d30 (Jacob and Esau's shared button)"); - - bool isTriggered = input_is_action_triggered(ACTION_PILL_CARD, controllerIndex, this); + bool isTriggered = input_is_action_triggered(twin_button_action(*this, TWIN_BUTTON_POCKET), controllerIndex, this); + if (is_twin_button_blocked(*this, TWIN_BUTTON_POCKET)) isTriggered = false; if (HasEntityFlags(FLAG_FEAR) || isCoopGhost) isTriggered = false; if (pocketItems[0].type == POCKET_ACTIVE && pocketItems[0].id > 0) return ControlActiveItem(pocketItems[0].id - 1); diff --git a/src/entity_player_room.cpp b/src/entity_player_room.cpp index 1677a6e..cd34c18 100644 --- a/src/entity_player_room.cpp +++ b/src/entity_player_room.cpp @@ -1,4 +1,7 @@ #include "entity_player.h" +#include "boss_ai.h" +#include "entity_familiar.h" +#include "room_grid.h" #include "game.h" #include "grid_entity_door.h" #include "log.h" @@ -22,7 +25,6 @@ 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 PLAYER_THE_FORGOTTEN = 16; constexpr int PLAYER_THE_FORGOTTEN_B = 35; constexpr int PLAYER_NO_DOGMA = 40; constexpr int CHALLENGE_FORGOTTEN_COSTUME = 42; @@ -328,6 +330,90 @@ void Entity_Player::room_enter() !game.isRestoringGlowingHourglassState) for (int i = GetTrinketMultiplier(TRINKET_USED_DIAPER); i > 0; i--) AddBlueFlies(1, pos, nullptr); if (HasTrinket(TRINKET_LIL_CLOT)) spawn_lil_clot_familiars(); - if (playerType == PLAYER_THE_FORGOTTEN) spawn_forgotten_body(); + if (playerType == PLAYER_THESOUL) spawn_forgotten_body(); preload_item_sounds(); } + +// A teleport takes a twin within 52 along, 10 beyond the spot. Its poof shows the player's layer 12 rising, and the +// arrival plays from frame 10 with the controls held 3 frames, a portal sound now and another 6 frames later. +constexpr float TWIN_TELEPORT_REACH = 52; +constexpr float TWIN_TELEPORT_GAP = 10; +constexpr int TELEPORT_LAYER = 12; +constexpr float TELEPORT_ARRIVE_FRAME = 10; +constexpr int TELEPORT_CONTROLS_COOLDOWN = 3; +constexpr float TELEPORT_LEAVE_VOLUME = 0.5f; +constexpr float TELEPORT_ARRIVE_VOLUME = 0.75f; +constexpr int TELEPORT_SOUND_DELAY = 10; +constexpr uint32_t TELEPORT_SOUND_TIMER = 6; + +// The poof a teleport leaves: a copy of the player's sprite showing only its teleport layer, rising. +static void teleport_poof_spawn(Entity_Player& player) +{ + Entity* poof = g_game->Spawn({.position = player.pos, .type = ENTITY_EFFECT, .variant = EFFECT_POOF01, + .seed = Random()}); + poof->sprite = player.sprite; + for (int i = 0; i < (int)poof->sprite.layerStates.size(); i++) poof->sprite.GetLayer(i)->isVisible = i == TELEPORT_LAYER; + + const AnimationData* shown = poof->sprite.animState.animData; + bool isShowing = shown && shown->name == "TeleportUp" && (!shown->isLooping || poof->sprite.animState.isPlaying); + if (!isShowing && poof->sprite.SetAnimation("TeleportUp", SWITCH_KEEP_FRAME)) + { + poof->sprite.animState.Rewind(); + poof->sprite.animState.isPlaying = true; + } + poof->Update(); +} + +// 007cdee0 The teleport's second sound, six frames after it. +static void teleport_sound_play(Entity_Effect*) +{ + grid_sound_play(SOUND_HELL_PORTAL2, {.volume = TELEPORT_ARRIVE_VOLUME, .frameDelay = TELEPORT_SOUND_DELAY}); +} + +// 007cd950 Moves the player to a position at rest, a close twin 10 beyond it, its familiars to their places in line +// (the Forgotten's body to the spot or a free one near it), with a poof and the arrival animation when shown. +void Entity_Player::Teleport(const Vector& position, bool isDoEffects, bool isTeleportTwinPlayers) +{ + Entity_Player* twin = twin_get(); + if (isTeleportTwinPlayers && twin && vector_length(vector_sub(pos, twin->pos)) <= TWIN_TELEPORT_REACH) + twin->Teleport(vector_add(position, vector_scale(vector_normalized(vector_sub(twin->pos, pos)), TWIN_TELEPORT_GAP)), + isDoEffects, false); + if (isDoEffects) teleport_poof_spawn(*this); + + pos = position; + velocity = vector_make(0, 0); + Room& room = *g_game->room; + for (Entity* entity : entity_query(ENTITY_FAMILIAR, -1)) + { + auto* familiar = static_cast(entity); + if (familiar->player != this) continue; + + bool isFree = !familiar->is_following() && familiar->orbitLayer < 0 && familiar->variant != Entity_Familiar::ISAACS_HEART; + if (!isFree) familiar->pos = familiar->GetFollowTargetPosition(FOLLOW_EXACT); + else if (familiar->variant == Entity_Familiar::FORGOTTEN_BODY) + { + Vector spot = position; + if (room.GetGridCollision(room.GetGridIndex(position)) != 0) + spot = room_free_pickup_position_find({.position = position, .isAvoidActiveEntities = true}); + familiar->pos = spot; + familiar->targetPosition = spot; + } + } + if (!isDoEffects) return; + + isPlayingItemAnimation = false; + bodySprite.Reset(); + sprite.playbackSpeed = 1; + sprite.overlayAnimState.SetAnimationData(nullptr); + if (sprite.SetAnimation("TeleportDown", SWITCH_KEEP_FRAME)) + { + sprite.animState.Rewind(); + sprite.animState.isPlaying = true; + } + isPlayingExtraAnimation = true; + isPlayingItemAnimation = false; + if (sprite.animState.animData) sprite.animState.SetFrameFloat(TELEPORT_ARRIVE_FRAME); + controlsCooldown = TELEPORT_CONTROLS_COOLDOWN; + grid_sound_play(SOUND_HELL_PORTAL1, {.volume = TELEPORT_LEAVE_VOLUME, .frameDelay = TELEPORT_SOUND_DELAY}); + Entity_Effect::CreateTimer(reinterpret_cast(&teleport_sound_play), TELEPORT_SOUND_TIMER, 0, false); +} diff --git a/src/entity_player_weapons.cpp b/src/entity_player_weapons.cpp index 7fc70a4..3d51dab 100644 --- a/src/entity_player_weapons.cpp +++ b/src/entity_player_weapons.cpp @@ -1,4 +1,5 @@ #include "entity_effect.h" +#include "entity_laser.h" #include "entity_player.h" #include "entity_tear.h" #include "game.h" @@ -10,6 +11,13 @@ #include #include +constexpr int TECH5_FLAG_CHANCE = 5; +constexpr int TECH5_FLAG_ROLL = 100; +constexpr int TECH5_FLAG_COUNT = 84; +constexpr float HEAD_PIVOT_LIFT = -5; +constexpr int PLAYER_HEAD_LAYER = 4; +constexpr const char* NULL_OFFSET_NAMES[] = {"LeftEye", "RightEye", "Forehead", "Mouth", "Mouth", "MomsEye", "Tractor"}; + constexpr float CROSS_EYED_ANGLE = 0.7853982f; constexpr float DEAD_EYE_STEP = 0.125f; constexpr float DEGREES_TO_RADIANS = 0.017453292f; @@ -61,7 +69,6 @@ constexpr int PLAYERFORM_BOOKWORM = 10; constexpr int TRANSFORMATION_COUNT = 3; constexpr int TEAR_COLOR_PRIORITY = 255; -constexpr int COLLECTIBLE_20_20 = 245; constexpr int COLLECTIBLE_BRIMSTONE_WEAPON = 118; constexpr int COLLECTIBLE_CURSED_EYE_WEAPON = 316; constexpr int COLLECTIBLE_DEAD_TOOTH = 446; @@ -414,3 +421,130 @@ Entity_Tear* Entity_Player::FireTear(const PosVel& shot, uint32_t fireFlags, Ent reconstruction_missing("Entity_Player::FireTear 00790af0 (Evil Eye)"); return tear; } + +// 0075af10 Where a null sits on the player, under its head's facing for a direction (its costumes' null overriding +// the body's), else on its current animations: scaled by the sprite, and by the head's size about the head's pivot. +Vector Entity_Player::GetCostumeNullPos(std::string_view nullName, bool isHeadScale, const Vector& direction) +{ + const NullFrame* frame = nullptr; + bool isCostumed = variant == PLAYER_VARIANT_PLAYER && !isCoopGhost; + if (direction.x != 0 || direction.y != 0) + { + std::string headAnimation = std::abs(direction.x) <= std::abs(direction.y) ? (direction.y >= 0 ? "HeadDown" : "HeadUp") + : (direction.x >= 0 ? "HeadRight" : "HeadLeft"); + frame = sprite.GetNullFrame(headAnimation, nullName, 1); + if (!frame && sprite.overlayAnimState.animData) frame = sprite.GetNullFrame(headAnimation + "_Overlay", nullName, 1); + if (isCostumed) + for (PlayerCostumeMap& costume : playerCostumeMap) + if (costume.index >= 0) + if (const NullFrame* worn = costumeSpriteDescs[(size_t)costume.index].sprite.GetNullFrame(headAnimation, nullName, 1)) + frame = worn; + } + if (!frame) + { + frame = sprite.animState.animData ? sprite.animState.GetNullFrame(nullName) : nullptr; + if (!frame && sprite.overlayAnimState.animData) frame = sprite.overlayAnimState.GetNullFrame(nullName); + if (isCostumed) + for (PlayerCostumeMap& costume : playerCostumeMap) + { + if (costume.index < 0) continue; + AnimationState& worn = costumeSpriteDescs[(size_t)costume.index].sprite.animState; + if (const NullFrame* found = worn.animData ? worn.GetNullFrame(nullName) : nullptr) frame = found; + } + if (!frame) return {}; + } + + Vector position = vector_make(sprite.scale.x * frame->pos.x, sprite.scale.y * frame->pos.y); + if (!isHeadScale) return position; + Vector pivot = vector_make(0, sprite.scale.y * HEAD_PIVOT_LIFT); + position = vector_make(position.x - pivot.x, position.y - pivot.y); + if (isCostumed) + { + LayerState* head = sprite.GetLayer(PLAYER_HEAD_LAYER); + position = vector_make(position.x * head->size.x, position.y * head->size.y); + } + return vector_add(position, pivot); +} + +// 007aa850 Where a laser of an offset leaves the player: the null of its eye, forehead, mouth, Mom's Eye (facing back) +// or Tractor Beam, in world units, lifted while it flies. C Section's lasers leave above it instead. +Vector Entity_Player::GetLaserOffset(int laserOffsetId, const Vector& shootDirection) +{ + if (laserOffsetId == LASER_OFFSET_NONE) return {}; + if (laserOffsetId == LASER_OFFSET_BRIMSTONE && HasCollectible(COLLECTIBLE_C_SECTION)) + return vector_make(0, sprite.scale.y * C_SECTION_LASER_LIFT); + + Vector offset{}; + if (laserOffsetId >= LASER_OFFSET_TECH1 && laserOffsetId <= LASER_OFFSET_TRACTOR_BEAM) + { + Vector facing = shootDirection; + if (laserOffsetId == LASER_OFFSET_MOMS_EYE) facing = vector_make(-shootDirection.x, -shootDirection.y); + if (laserOffsetId == LASER_OFFSET_SHOOP || laserOffsetId == LASER_OFFSET_BRIMSTONE || + laserOffsetId == LASER_OFFSET_TRACTOR_BEAM) + facing = Vector{}; + offset = vector_scale(GetCostumeNullPos(NULL_OFFSET_NAMES[laserOffsetId], true, facing), 1 / LASER_SCREEN_SCALE); + } + if (canFly) offset = vector_add(offset, vector_scale(GetFlyingOffset(), 1 / LASER_SCREEN_SCALE)); + return offset; +} + +// 007aab70 Fires a Technology laser from the player: from an eye's offset along a direction, lasting three frames, +// in the player's laser color with its laser hit params (Technology 2's with the player's damage, one of Tech.5's in +// twenty with a random flag of its own), drawn behind the head when it fires up or away from the eye. +Entity_Laser* Entity_Player::FireTechLaser(const TechLaserShot& shot) +{ + Vector offset = GetLaserOffset(shot.offsetId, shot.direction); + Entity_Laser* laser = Entity_Laser::ShootAngle({.position = vector_make(shot.position.x + offset.x, shot.position.y), + .posOffset = vector_make(0, offset.y), + .source = shot.source ? shot.source : this, + .angleDegrees = std::atan2(shot.direction.y, shot.direction.x) * DEGREES_PER_RADIAN, + .timeout = TECH_LASER_TIMEOUT, + .variant = LASER_THIN_RED}); + laser->parentOffset = vector_make(offset.x, 0); + laser->isOneHit = shot.isOneHit; + laser->isDisableFollowParent = true; + laser->pos = vector_add(vector_add(tearsOffset, shot.position), vector_make(offset.x, 0)); + + TearFlags flags = tearFlags; + if (shot.offsetId == LASER_OFFSET_TECH5 && Random() % TECH5_FLAG_ROLL < TECH5_FLAG_CHANCE) + { + flags.reset(); + flags.set(Random() % TECH5_FLAG_COUNT); + } + laser->tearFlags = flags; + laser->SetColor(laserColor, -1, COLOR_PRIORITY_DEFAULT, false, true); + if (shot.offsetId == LASER_OFFSET_TECH2) laser->SetCollisionDamage(damage); + else + { + int displacement = (int)(Random() & 1) * 2 - 1; + TearParams params = GetTearHitParams(WEAPON_LASER, shot.damageScale, displacement, nullptr); + laser->SetCollisionDamage(params.tearDamage); + laser->tearFlags |= params.tearFlags; + laser->damageMultiplier = shot.damageScale; + laser->set_scale(params.tearScale); + laser->mass *= params.massMultiplier; + } + laser->entityGridCollisionClass = GRIDCOLL_NOPITS; + + const Vector& aim = shot.direction; + bool isBehind = shot.isLeftEye ? (aim.y < -TECH_LASER_FACING || aim.x > TECH_LASER_FACING) + : (aim.y <= -TECH_LASER_FACING || aim.x <= -TECH_LASER_FACING); + laser->renderDepthOffset = isBehind ? TECH_LASER_BACK_DEPTH : TECH_LASER_FRONT_DEPTH; + laser->isPlayerParams = true; + return laser; +} + +// 007a0f50 Fires a Brimstone beam from the player in its laser color (Lua's FireBrimstone). +Entity_Laser* Entity_Player::FireBrimstone(const Vector& direction, Entity*, float damageMultiplier) +{ + Entity_Laser* laser = Weapon::FireBrimstone({.direction = direction, .position = pos, .entity = this, + .damageMultiplier = damageMultiplier}); + laser->SetColor(laserColor, -1, COLOR_PRIORITY_DEFAULT, false, true); + return laser; +} + +// 00665c20 The player's laser color. +ColorMod Entity_Player::get_laser_color_copy() +{ + return laserColor; +} diff --git a/src/entity_status.cpp b/src/entity_status.cpp new file mode 100644 index 0000000..2bd6dcc --- /dev/null +++ b/src/entity_status.cpp @@ -0,0 +1,637 @@ +#include "entity.h" +#include "entity_effect.h" +#include "entity_list.h" +#include "entity_npc.h" +#include "entity_pickup.h" +#include "entity_player.h" +#include "entity_projectile.h" +#include "entity_tear.h" +#include "game.h" +#include "manager.h" +#include "npc_ai.h" +#include "room.h" +#include +#include + +// How long each status effect can add up to. +constexpr int STATUS_MAX_FRAMES = 120; +constexpr int BURN_MAX_FRAMES = 160; +constexpr int SHRINK_MAX_FRAMES = 150; +constexpr int MARK_MAX_FRAMES = 300; +// How long a boss shrugs off status effects after one, and after a player's fear in the Guardian challenge. +constexpr int BOSS_STATUS_COOLDOWN = 240; +constexpr int GUARDIAN_FEAR_COOLDOWN = 90; +// A negative slowing lasts two frames, weakness always the three frames its callers pass. +constexpr int SLOW_BRIEF_FRAMES = 2; +constexpr int WEAKNESS_DURATION = -3; +// A shrunk entity eases toward a third of its size. +constexpr float SHRINK_SCALE = 0.333f; +// Poison fades from green toward its floor as it adds up. +constexpr float POISON_FADE_FRAMES = 200; +constexpr float POISON_FADE_OFFSET = 0.1f; +constexpr float POISON_TINT_MIN = 0.6f; +constexpr float POISON_GLOW = 90; +constexpr float COLOR_STEP = 0.003921569f; +constexpr float HALF_SIZE = 0.5f; +// Three permanently charmed enemies in a room unlock the Mystery Egg. +constexpr int MYSTERY_EGG_CHARMED = 3; +// My Shadow's charger, which a permanent charm does not make persistent, and the poop Midas' Touch turns a poop into. +constexpr int MY_SHADOW_CHARGER_SUBTYPE = 1; +constexpr int MIDAS_POOP_VARIANT = 1; + +// Bleeding: the ground covered that costs a point, the damage per point (more on later floors, one in versus), the +// most points a frame, the hit's countdown, and the creep's random size and the blood drops' speed. +constexpr float BLEED_PER_DISTANCE = 0.02f; +constexpr float BLEED_DAMAGE_PER_STAGE = 0.3f; +constexpr float BLEED_DAMAGE_BASE = 2.8f; +constexpr float BLEED_POINTS_MAX = 10; +constexpr int BLEED_DAMAGE_COUNTDOWN = 30; +constexpr float BLEED_CREEP_SCALE = 0.5f; +constexpr float BLEED_CREEP_SCALE_MIN = 0.2f; +constexpr float BLEED_DROP_SPEED = 5; +constexpr float BLEED_DROP_FLATTEN = 0.5f; +constexpr uint32_t BLEED_DROP_SUBTYPES = 3; +// A magnetized entity's pull: its reach, its strength on most things and on enemies, tears and bombs, the distance +// inside which it falls off, how a close enemy or bomb slows the magnet, and how shots slow and give in. +constexpr float MAGNET_REACH_SQUARED = 65536; +constexpr float MAGNET_PULL = 32; +constexpr float MAGNET_PULL_STRONG = 80; +constexpr float MAGNET_NEAR = 8; +constexpr float MAGNET_NEAR_FALLOFF = 0.015625f; +constexpr float MAGNET_CONTACT_MARGIN = 16; +constexpr float MAGNET_CONTACT_DAMP = 0.8f; +constexpr float MAGNET_SHOT_DAMP_MIN = 0.5f; +constexpr float MAGNET_SHOT_AGE_FRAMES = 30; +constexpr float MAGNET_SHOT_DROP = 0.3f; +constexpr int MAGNET_SHOT_CATCH_FRAMES = 15; +constexpr float MAGNET_SHOT_CATCH_HEIGHT = -50; + +constexpr float STATUS_GLOW = 0.15686275f; +constexpr ColorMod FREEZE_COLOR = {{0.22f, 0.22f, 0.22f, 1}, {0, 0, 0, 0}, {STATUS_GLOW, STATUS_GLOW, STATUS_GLOW}}; +constexpr ColorMod STATUS_CHARM_COLOR = {{1, 0, 0.8f, 1}, {0, 0, 0, 0}, {STATUS_GLOW, STATUS_GLOW, STATUS_GLOW}}; +constexpr ColorMod CONFUSION_COLOR = {{0.5f, 0.5f, 0.5f, 1}, {0, 0, 0, 0}, {STATUS_GLOW, STATUS_GLOW, STATUS_GLOW}}; +constexpr ColorMod MIDAS_COLOR = {{1.5f, 1.5f, 0.3f, 1}, {0, 0, 0, 0}, {STATUS_GLOW, STATUS_GLOW, STATUS_GLOW}}; +constexpr ColorMod FEAR_COLOR = {{0.5f, 0.1f, 0.5f, 1}, {0, 0, 0, 0}, {0, 0, 0}}; +constexpr ColorMod MAGNET_COLOR = {{0.6f, 0.6f, 0.6f, 1}, {1, 1, 1, 0.9f}, {0, 0, 0}}; +constexpr ColorMod BAIT_COLOR = {{0.7f, 0.14f, 0.1f, 1}, {0, 0, 0, 0}, {0.3f, 0, 0}}; +constexpr ColorMod WEAKNESS_COLOR = {{1, 1, 1, 1}, {1.3f, 0.9f, 1.5f, 0.6f}, {0, 0, 0}}; +constexpr ColorMod BRIMSTONE_MARK_COLOR = {{1, 1, 1, 1}, {1, 0, 0, 0.2f}, {0, 0, 0}}; + +// A countdown after adding a duration: a positive one adds up to the cap, a negative one lasts at least its length. +static int countdown_add(int countdown, int duration, int cap) +{ + return duration > 0 ? std::min(countdown + duration, cap) : std::max(countdown, -duration); +} + +// 006ae7a0 Whether an entity counts as a boss for the status cooldown: a boss, or a player in versus. +static bool is_boss_like(Entity& entity) +{ + return entity.IsBoss() || (g_game->deathmatchManager.is_active() && entity.type == ENTITY_PLAYER); +} + +// Whether a status effect of a duration takes hold: statuses allowed and no boss cooldown running unless ignored. +static bool is_status_taken(Entity& head, int duration, bool isIgnoreBossCooldown) +{ + return duration != 0 && !head.HasEntityFlags(FLAG_NO_STATUS_EFFECTS) && + (head.bossStatusEffectCooldown < 1 || isIgnoreBossCooldown); +} + +// Starts the boss cooldown after a status effect unless the cooldown was ignored. +static void boss_cooldown_start(Entity& head, bool isIgnoreBossCooldown) +{ + if (!isIgnoreBossCooldown && is_boss_like(head)) head.bossStatusEffectCooldown = BOSS_STATUS_COOLDOWN; +} + +// Whether Evil Charm keeps a player safe from poison, burns, confusion and fear. +static bool is_evil_charmed(Entity& entity) +{ + if (entity.type != ENTITY_PLAYER) return false; + Entity_Player& player = static_cast(entity); + return player.HasCollectible(COLLECTIBLE_EVIL_CHARM) || + player.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_EVIL_CHARM); +} + +// A poison or burn's damage per tick: the one given, else the melee damage of the player behind the source. +static float tick_damage_get(Entity& entity, const EntityRef& source, float damage) +{ + if (damage > 0) return damage; + if (entity.type == ENTITY_PLAYER || !source.entity) return STATUS_TICK_DAMAGE_DEFAULT; + + Entity* root = source.entity->GetLastSpawner(); + return root->type == ENTITY_PLAYER ? static_cast(root)->meleeDamage : STATUS_TICK_DAMAGE_DEFAULT; +} + +// The source a status effect remembers: whatever first spawned it. +static EntityRef root_source_get(const EntityRef& source) +{ + return EntityRef(source.entity ? source.entity->GetLastSpawner() : nullptr); +} + +// Sends an enemy that just started fleeing or stumbling on a new path. +static void path_reset(Entity& head) +{ + if (!head.IsEnemy()) return; + if (Entity_NPC* npc = dynamic_cast(&head)) npc->ResetPathFinderTarget(); +} + +// 006ad350 A status effect's duration, twice per copy of Second Hand the player behind its source holds. A player is +// only affected so in versus. +int Entity::apply_second_hand_duration(int duration, const EntityRef& source) +{ + if ((type == ENTITY_PLAYER && !g_game->deathmatchManager.is_active()) || !source.entity) return duration; + + Entity* root = source.entity->GetLastSpawner(); + if (root->type != ENTITY_PLAYER) return duration; + Entity_Player& player = *static_cast(root); + if (!player.HasTrinket(TRINKET_SECOND_HAND)) return duration; + return player.GetTrinketMultiplier(TRINKET_SECOND_HAND) * duration * 2; +} + +// 006ad3c0 Freezes the entity (the head of a body sharing its status) unless a friend did it, tinted grey. +void Entity::AddFreeze(const EntityRef& source, int duration, bool isIgnoreBossCooldown) +{ + if (IsDamageSourceFriendly(source)) return; + duration = apply_second_hand_duration(duration, source); + Entity& head = *GetStatusEffectTarget(); + if (!is_status_taken(head, duration, isIgnoreBossCooldown)) return; + + head.freezeCountdown = countdown_add(head.freezeCountdown, duration, STATUS_MAX_FRAMES); + head.AddEntityFlags(FLAG_FREEZE); + head.SetColor(FREEZE_COLOR, head.freezeCountdown, STATUS_COLOR_PRIORITY, false, true); + boss_cooldown_start(head, isIgnoreBossCooldown); + head.CopyStatusEffects(); +} + +// 006ad500 Poisons the entity unless a friend did it or Evil Charm guards it, ticking for the strongest damage so far +// (the source's player's melee damage without one). It turns greener the longer it lasts. +void Entity::AddPoison(const EntityRef& source, int duration, float damage, bool isIgnoreBossCooldown) +{ + if (IsDamageSourceFriendly(source) || is_evil_charmed(*this)) return; + duration = apply_second_hand_duration(duration, source); + damage = tick_damage_get(*this, source, damage); + Entity& head = *GetStatusEffectTarget(); + if (!is_status_taken(head, duration, isIgnoreBossCooldown)) return; + + head.poisonCountdown = countdown_add(head.poisonCountdown, duration, STATUS_MAX_FRAMES); + if (!head.HasEntityFlags(FLAG_POISON)) head.poisonDamageTimer = 0; + head.poisonTickDamage = std::max(head.poisonTickDamage, damage); + head.AddEntityFlags(FLAG_POISON); + + float tint = std::max((POISON_FADE_FRAMES - (float)head.poisonCountdown) / POISON_FADE_FRAMES - POISON_FADE_OFFSET, + POISON_TINT_MIN); + float glow = (float)(int)((1 - tint) * POISON_GLOW) * COLOR_STEP; + head.SetColor({{tint, 1, tint, 1}, {0, 0, 0, 0}, {0, glow, 0}}, head.poisonCountdown, STATUS_COLOR_PRIORITY, false, + true); + boss_cooldown_start(head, isIgnoreBossCooldown); + head.CopyStatusEffects(); +} + +// 006ad750 Slows the entity (the head of a body sharing its status) unless a friend did it: a negative duration for +// two frames, a positive one added up and tinted, then bosses shrug status off for a while. The amount is set either +// way, and the segments copy it. +void Entity::AddSlowing(const EntityRef& source, int duration, float amount, ColorMod slowColor, + bool isIgnoreBossCooldown) +{ + if (IsDamageSourceFriendly(source)) return; + duration = apply_second_hand_duration(duration, source); + Entity& head = *GetStatusEffectTarget(); + + bool isImmune = head.HasEntityFlags(FLAG_NO_STATUS_EFFECTS); + if (duration < 0 && !isImmune) + { + head.slowingCountdown = SLOW_BRIEF_FRAMES; + head.AddEntityFlags(FLAG_SLOW); + } + else if (duration > 0 && is_status_taken(head, duration, isIgnoreBossCooldown)) + { + head.slowingCountdown += duration; + head.AddEntityFlags(FLAG_SLOW); + head.SetColor(slowColor, duration, STATUS_COLOR_PRIORITY, false, true); + boss_cooldown_start(head, isIgnoreBossCooldown); + } + head.slowingAmount = amount; + head.CopyStatusEffects(); +} + +// A permanent charm: the head turns friendly for good, scoring the kill once, and an active enemy stays with the +// players between rooms. Three such enemies at once unlock the Mystery Egg. +static void charm_permanent(Entity& entity, Entity& head, bool isCharmed, bool isAddEnemyKillScore) +{ + Game& game = *g_game; + Room& room = *game.room; + + if (entity.IsEnemy() && !isCharmed && isAddEnemyKillScore) game.scoreSheet.AddKilledEnemy(entity); + head.AddEntityFlags(FLAG_CHARM | FLAG_FRIENDLY); + head.charmedCountdown = 0; + bool isShadowCharger = entity.IsType(ENTITY_CHARGER, 0, MY_SHADOW_CHARGER_SUBTYPE); + if (!entity.IsBoss() && entity.IsActiveEnemy(DEAD_EXCLUDED) && !isShadowCharger && + !entity.HasEntityFlags(FLAG_DELIRIUM_FORM)) + room.entityList.AddPersistentEntity(&entity); + + PersistentGameData& save = g_manager->persistentGameData; + bool isAllowed = !game.seedEffects.isCustomRun && !game.seedEffects.AchievementUnlocksDisallowed() && + !Manager::AchievementUnlocksDisallowed() && !game.isRerun && + !save.Unlocked(ACHIEVEMENT_MYSTERY_EGG); + if (isAllowed) + { + int charmed = (int)std::ranges::count_if(room.entityList.updateEL, [](Entity* entity) { + return entity->IsEnemy() && entity->HasEntityFlags(FLAG_FRIENDLY) && + (!entity->DoesEntityShareStatus() || !entity->parent); + }); + if (charmed >= MYSTERY_EGG_CHARMED) save.TryUnlock(ACHIEVEMENT_MYSTERY_EGG); + } + if (head.IsEnemy()) head.ResetColor(); +} + +// 006ad870 Charms the entity (the head of a body sharing its status) unless it is friendly: for good with a negative +// duration, else for the longer of its charm and the duration, tinted pink. It remembers whatever first spawned the +// source, and an enemy just charmed finds a new path. +void Entity::AddCharmed(const EntityRef& source, int duration, bool isIgnoreBossCooldown, bool isAddEnemyKillScore) +{ + if (HasEntityFlags(FLAG_FRIENDLY)) return; + duration = apply_second_hand_duration(duration, source); + Entity& head = *GetStatusEffectTarget(); + bool isCharmed = head.HasEntityFlags(FLAG_CHARM | FLAG_FRIENDLY); + + if (duration < 0) charm_permanent(*this, head, isCharmed, isAddEnemyKillScore); + else if (duration > 0 && is_status_taken(head, duration, isIgnoreBossCooldown)) + { + head.charmedCountdown = std::max(head.charmedCountdown, duration); + head.AddEntityFlags(FLAG_CHARM); + head.SetColor(STATUS_CHARM_COLOR, head.charmedCountdown, STATUS_COLOR_PRIORITY, false, true); + boss_cooldown_start(head, isIgnoreBossCooldown); + } + charmSource = root_source_get(source); + head.CopyStatusEffects(); + if (head.charmedCountdown != 0 && !isCharmed) path_reset(head); +} + +// 006add70 Confuses the entity unless a friend did it or Evil Charm guards it, for at least its confusion so far, +// tinted grey. An enemy just confused finds a new path. +void Entity::AddConfusion(const EntityRef& source, int duration, bool isIgnoreBossCooldown) +{ + if (IsDamageSourceFriendly(source) || is_evil_charmed(*this)) return; + duration = apply_second_hand_duration(duration, source); + Entity& head = *GetStatusEffectTarget(); + bool wasConfused = head.HasEntityFlags(FLAG_CONFUSION); + + if (is_status_taken(head, duration, isIgnoreBossCooldown)) + { + head.confusionCountdown = std::max(head.confusionCountdown, + countdown_add(head.confusionCountdown, duration, STATUS_MAX_FRAMES)); + head.AddEntityFlags(FLAG_CONFUSION); + head.SetColor(CONFUSION_COLOR, head.confusionCountdown, STATUS_COLOR_PRIORITY, false, true); + boss_cooldown_start(head, isIgnoreBossCooldown); + } + head.CopyStatusEffects(); + if (head.confusionCountdown > 0 && !wasConfused) path_reset(head); +} + +// 006adf40 Turns the entity to gold for a while unless a friend did it or it already is: frozen and tinted gold. +// A poop turns golden instead. +void Entity::AddMidasFreeze(const EntityRef& source, int duration, bool isIgnoreBossCooldown) +{ + if (IsDamageSourceFriendly(source)) return; + duration = apply_second_hand_duration(duration, source); + Entity& head = *GetStatusEffectTarget(); + + bool isTaken = duration > 0 && head.midasFreezeCountdown == 0 && + (head.bossStatusEffectCooldown < 1 || isIgnoreBossCooldown); + if (isTaken && head.type == ENTITY_POOP) + { + head.variant = MIDAS_POOP_VARIANT; + return; + } + if (isTaken && !head.HasEntityFlags(FLAG_NO_STATUS_EFFECTS)) + { + head.AddEntityFlags(FLAG_FREEZE | FLAG_MIDAS_FREEZE); + head.midasFreezeCountdown = duration; + head.freezeCountdown = duration; + head.SetColor(MIDAS_COLOR, duration, STATUS_COLOR_PRIORITY, false, true); + boss_cooldown_start(head, isIgnoreBossCooldown); + } + head.CopyStatusEffects(); +} + +// 006ae0a0 Frightens the entity unless a friend did it or Evil Charm guards it, tinted purple. In the Guardian +// challenge a boss frightened by the player shrugs status off sooner. An enemy just frightened (or shrunk) flees anew. +void Entity::AddFear(const EntityRef& source, int duration, bool isIgnoreBossCooldown) +{ + if (IsDamageSourceFriendly(source) || is_evil_charmed(*this)) return; + duration = apply_second_hand_duration(duration, source); + Entity& head = *GetStatusEffectTarget(); + if (!is_status_taken(head, duration, isIgnoreBossCooldown)) return; + + bool wasFleeing = head.HasEntityFlags(FLAG_FEAR | FLAG_SHRINK); + head.fearCountdown = countdown_add(head.fearCountdown, duration, STATUS_MAX_FRAMES); + head.SetColor(FEAR_COLOR, head.fearCountdown, STATUS_COLOR_PRIORITY, false, true); + head.AddEntityFlags(FLAG_FEAR); + if (!isIgnoreBossCooldown && is_boss_like(head)) + { + bool isGuardianPlayer = g_game->challenge == CHALLENGE_GUARDIAN && source.type == ENTITY_PLAYER && + source.variant == 0; + head.bossStatusEffectCooldown = isGuardianPlayer ? GUARDIAN_FEAR_COOLDOWN : BOSS_STATUS_COOLDOWN; + } + head.CopyStatusEffects(); + if (head.fearCountdown > 0 && !wasFleeing) path_reset(head); +} + +// 006ae280 Burns the entity unless a friend did it or Evil Charm guards it, ticking for the strongest damage so far +// (the source's player's melee damage without one). Its flicker comes from Update. +void Entity::AddBurn(const EntityRef& source, int duration, float damage, bool isIgnoreBossCooldown) +{ + if (IsDamageSourceFriendly(source) || is_evil_charmed(*this)) return; + duration = apply_second_hand_duration(duration, source); + damage = tick_damage_get(*this, source, damage); + Entity& head = *GetStatusEffectTarget(); + if (!is_status_taken(head, duration, isIgnoreBossCooldown)) return; + + head.burnCountdown = countdown_add(head.burnCountdown, duration, BURN_MAX_FRAMES); + if (!head.HasEntityFlags(FLAG_BURN)) head.burnDamageTimer = 0; + head.burnTickDamage = std::max(head.burnTickDamage, damage); + head.AddEntityFlags(FLAG_BURN); + boss_cooldown_start(head, isIgnoreBossCooldown); + head.CopyStatusEffects(); +} + +// 006ae420 Makes the entity bleed unless a friend did it, remembering whatever first spawned the source. Its flicker +// and damage come from Update. +void Entity::AddBleeding(const EntityRef& source, int duration) +{ + if (IsDamageSourceFriendly(source)) return; + duration = apply_second_hand_duration(duration, source); + Entity& head = *GetStatusEffectTarget(); + if (!is_status_taken(head, duration, false)) return; + + head.bleedingCountdown = countdown_add(head.bleedingCountdown, duration, STATUS_MAX_FRAMES); + head.AddEntityFlags(FLAG_BLEED_OUT); + bleedSource = root_source_get(source); + boss_cooldown_start(head, false); + head.CopyStatusEffects(); +} + +// 006ae630 Clears every status effect, the timed colors and friendship, and gives back the entity's own size. +void Entity::RemoveStatusEffects() +{ + colorParams.clear(); + ClearEntityFlags(FLAG_FREEZE | FLAG_POISON | FLAG_SLOW | FLAG_CHARM | FLAG_CONFUSION | FLAG_MIDAS_FREEZE | + FLAG_FEAR | FLAG_BURN | FLAG_SHRINK | FLAG_FRIENDLY); + freezeCountdown = 0; + poisonCountdown = 0; + slowingCountdown = 0; + charmedCountdown = 0; + confusionCountdown = 0; + midasFreezeCountdown = 0; + fearCountdown = 0; + burnCountdown = 0; + shrinkCountdown = 0; + SetSize(config->collisionRadius, vector_make(-1, -1), -1); + + ClearEntityFlags(FLAG_BLEED_OUT | FLAG_KNOCKED_BACK | FLAG_APPLY_IMPACT_DAMAGE | FLAG_ICE | FLAG_MAGNETIZED | + FLAG_BAITED | FLAG_WEAKNESS | FLAG_BRIMSTONE_MARKED); + shrinkStatus2 = 1; + bleedingCountdown = 0; + bleedDamageAccumulator = 0; + magnetizedCountdown = 0; + baitedCountdown = 0; + knockbackCountdown = 0; + iceCountdown = 0; + weaknessCountdown = 0; + brimstoneMarkCountdown = 0; + poisonTickDamage = STATUS_TICK_DAMAGE_DEFAULT; + burnTickDamage = STATUS_TICK_DAMAGE_DEFAULT; + ResetColor(); + CopyStatusEffects(); +} + +// 006b5c10 Shrinks the entity (never a boss) unless a friend did it, which a forced shrink skips along with the +// status checks: its collision shrinks with its size, and an enemy just shrunk (or frightened) flees anew. +void Entity::AddShrink(const EntityRef& source, int duration, bool isIgnoreBossCooldown, bool isForced) +{ + if ((!isForced && IsDamageSourceFriendly(source)) || IsBoss()) return; + duration = apply_second_hand_duration(duration, source); + Entity& head = *GetStatusEffectTarget(); + bool wasFleeing = head.HasEntityFlags(FLAG_FEAR | FLAG_SHRINK); + if (!isForced && !is_status_taken(head, duration, isIgnoreBossCooldown)) return; + + head.shrinkCountdown = countdown_add(head.shrinkCountdown, duration, SHRINK_MAX_FRAMES); + if (!head.HasEntityFlags(FLAG_SHRINK)) + { + head.AddEntityFlags(FLAG_SHRINK); + head.shrinkStatus2 = SHRINK_SCALE; + SetSize(config->collisionRadius * shrinkStatus1, vector_make(-1, -1), -1); + } + boss_cooldown_start(head, isIgnoreBossCooldown); + head.CopyStatusEffects(); + if (head.shrinkCountdown > 0 && !wasFleeing) path_reset(head); +} + +// 006b7280 Magnetizes the entity unless a friend did it, tinted grey with a pulling effect over it, remembering +// whatever first spawned the source. +void Entity::AddMagnetized(const EntityRef& source, int duration) +{ + if (IsDamageSourceFriendly(source)) return; + duration = apply_second_hand_duration(duration, source); + Entity& head = *GetStatusEffectTarget(); + if (!is_status_taken(head, duration, false)) return; + + head.magnetizedCountdown = countdown_add(head.magnetizedCountdown, duration, MARK_MAX_FRAMES); + head.SetColor(MAGNET_COLOR, head.magnetizedCountdown, STATUS_COLOR_PRIORITY, false, true); + head.AddEntityFlags(FLAG_MAGNETIZED); + boss_cooldown_start(head, false); + head.CopyStatusEffects(); + if (!head.magnetizedEffect) + { + Entity* effect = g_game->Spawn( + {.position = head.pos, .type = ENTITY_EFFECT, .variant = EFFECT_PULLING_EFFECT, .seed = Random()}); + head.magnetizedEffect = effect; + effect->parent = &head; + } + magnetizedSource = root_source_get(source); +} + +// 006b7560 Baits the entity unless a friend did it, tinted red, so enemies turn on it. It remembers whatever first +// spawned the source. +void Entity::AddBaited(const EntityRef& source, int duration) +{ + if (IsDamageSourceFriendly(source)) return; + duration = apply_second_hand_duration(duration, source); + Entity& head = *GetStatusEffectTarget(); + if (!is_status_taken(head, duration, false)) return; + + head.baitedCountdown = countdown_add(head.baitedCountdown, duration, MARK_MAX_FRAMES); + head.SetColor(BAIT_COLOR, head.baitedCountdown, STATUS_COLOR_PRIORITY, false, true); + head.AddEntityFlags(FLAG_BAITED); + boss_cooldown_start(head, false); + head.CopyStatusEffects(); + baitedSource = root_source_get(source); +} + +// 006b77d0 Weakens the entity unless a friend did it, tinted purple, whatever its status guards. +// The original ignores the duration it is given and always weakens for three frames or more. +void Entity::AddWeakness(const EntityRef& source, int) +{ + if (IsDamageSourceFriendly(source)) return; + int duration = apply_second_hand_duration(WEAKNESS_DURATION, source); + Entity& head = *GetStatusEffectTarget(); + if (duration == 0) return; + + head.weaknessCountdown = countdown_add(head.weaknessCountdown, duration, MARK_MAX_FRAMES); + head.SetColor(WEAKNESS_COLOR, head.weaknessCountdown, STATUS_COLOR_PRIORITY, false, true); + head.AddEntityFlags(FLAG_WEAKNESS); + head.CopyStatusEffects(); +} + +// 006b78d0 Marks the entity for Brimstone's bombs unless a friend did it, tinted red, whatever its status guards. +void Entity::AddBrimstoneMark(const EntityRef& source, int duration) +{ + if (IsDamageSourceFriendly(source)) return; + duration = apply_second_hand_duration(duration, source); + Entity& head = *GetStatusEffectTarget(); + if (duration == 0) return; + + head.brimstoneMarkCountdown = countdown_add(head.brimstoneMarkCountdown, duration, MARK_MAX_FRAMES); + head.SetColor(BRIMSTONE_MARK_COLOR, head.brimstoneMarkCountdown, STATUS_COLOR_PRIORITY, false, true); + head.AddEntityFlags(FLAG_BRIMSTONE_MARKED); + head.CopyStatusEffects(); +} + +// 006b79d0 Ices the entity (never a boss) unless a friend did it, so it freezes solid when it dies. +void Entity::AddIce(const EntityRef& source, int duration) +{ + if (IsDamageSourceFriendly(source) || IsBoss()) return; + duration = apply_second_hand_duration(duration, source); + Entity& head = *GetStatusEffectTarget(); + + head.iceCountdown = countdown_add(head.iceCountdown, duration, MARK_MAX_FRAMES); + head.AddEntityFlags(FLAG_ICE); + head.CopyStatusEffects(); +} + +// The bleeding of Mom's Razor (part of 006ae820): the ground the enemy covers adds up to whole points of damage, harder +// on later floors, and each point leaves red creep, a blood splat and a drop of blood along the way. +void Entity::bleed_update() +{ + Game& game = *g_game; + float moved = std::sqrt((pos.y - prevPosition.y) * (pos.y - prevPosition.y) + + (pos.x - prevPosition.x) * (pos.x - prevPosition.x)); + float accumulated = moved * speedMultiplier * BLEED_PER_DISTANCE + bleedDamageAccumulator; + bool isAltPath = game.stageType == STAGETYPE_REPENTANCE || game.stageType == STAGETYPE_REPENTANCE_B; + float perPoint = (float)(isAltPath ? game.stage + 1 : game.stage) * BLEED_DAMAGE_PER_STAGE + BLEED_DAMAGE_BASE; + float points = std::floor(accumulated); + if (game.deathmatchManager.is_active()) perPoint = 1; + bleedDamageAccumulator = accumulated - points; + + float damage = std::min(points, BLEED_POINTS_MAX) * perPoint; + if (!(damage > 0)) return; + TakeDamage(damage, 0, bleedSource, BLEED_DAMAGE_COUNTDOWN); + for (float i = 0; i < points; i++) + { + Vector at = vector_make((prevPosition.x - pos.x) * i / points + pos.x, + (prevPosition.y - pos.y) * i / points + pos.y); + auto creep = static_cast( + game.Spawn({.position = at, .type = ENTITY_EFFECT, .variant = EFFECT_PLAYER_CREEP_RED, .seed = Random()})); + uint32_t hitIndex = GetHitListIndex(); + auto slot = std::lower_bound(creep->hitList.begin(), creep->hitList.end(), hitIndex); + if (slot == creep->hitList.end() || *slot != hitIndex) creep->hitList.insert(slot, hitIndex); + float scale = random_unit() * BLEED_CREEP_SCALE + BLEED_CREEP_SCALE_MIN; + creep->sprite.scale = vector_make(scale, scale); + creep->Update(); + game.Spawn({.position = at, .type = ENTITY_EFFECT, .variant = EFFECT_BLOOD_SPLAT, .seed = Random()})->Update(); + + uint32_t seed = Random(); + uint32_t kind = Random(); + Vector direction = random_direction(); + Vector velocity = + vector_make(direction.x * BLEED_DROP_SPEED, direction.y * BLEED_DROP_FLATTEN * BLEED_DROP_SPEED); + Vector around = random_direction(); + Vector dropAt = vector_make(around.x * HALF_SIZE * size + pos.x, around.y * HALF_SIZE * size + pos.y); + game.Spawn({.position = dropAt, + .velocity = velocity, + .spawner = this, + .subType = (int)(kind % BLEED_DROP_SUBTYPES), + .type = ENTITY_EFFECT, + .variant = EFFECT_BLOOD_PARTICLE, + .seed = seed}) + ->Update(); + } +} + +// Whether a magnetized entity pulls another: a vulnerable enemy, a shot, a bomb or a free pickup (a chest only while +// closed), never itself or a segment of its own body, and in versus nothing its own player made. +static bool is_magnet_target(Entity& magnet, Entity& other) +{ + if (magnet.GetStatusEffectTarget() == other.GetStatusEffectTarget()) return false; + if (g_game->deathmatchManager.is_active() && other.IsDescendantOf(magnet.magnetizedSource.entity)) return false; + + bool isPickup = other.type == ENTITY_PICKUP && static_cast(other).price == 0 && + (!Entity_Pickup::IsChest(other.variant) || other.subtype != 0); + bool isPulled = other.IsVulnerableEnemy(nullptr) || other.type == ENTITY_PROJECTILE || other.type == ENTITY_TEAR || + other.type == ENTITY_BOMB || isPickup; + return isPulled && &other != &magnet; +} + +// Slows a shot caught by the pull, the more the closer: to half its speed at most. +static void magnet_shot_slow(Entity& shot, float pull) +{ + float damp = std::max(1 - (pull + pull), MAGNET_SHOT_DAMP_MIN); + shot.velocity.y = damp * shot.velocity.y; + shot.velocity.x = damp * shot.velocity.x; +} + +// A magnetized entity's pull (part of 006ae820): only the head of a body pulls, everything it may pull within 256 is +// drawn toward it (enemies, tears and bombs harder), shots slowing and enemy shots caught at its middle, and an enemy +// or bomb touching it holds it back. +void Entity::magnet_pull_update() +{ + if (DoesEntityShareStatus() && parent && GetLastParent() != this) return; + + float selfDamp = 1; + for (Entity* other : g_game->room->entityList.updateEL) + { + if (!is_magnet_target(*this, *other)) continue; + bool isApart = other->pos.x != pos.x || other->pos.y != pos.y; + if (!isApart || other->friction == 0) continue; + + Vector toward = vector_make(pos.x - other->pos.x, pos.y - other->pos.y); + float distanceSquared = toward.y * toward.y + toward.x * toward.x; + if (distanceSquared >= MAGNET_REACH_SQUARED) continue; + + float distance = std::sqrt(distanceSquared); + if (distance > 0) toward = vector_scale(toward, 1 / distance); + bool isHeavy = other->IsEnemy() || other->type == ENTITY_BOMB; + float strength = isHeavy || other->type == ENTITY_TEAR ? MAGNET_PULL_STRONG : MAGNET_PULL; + if (isHeavy && distance < other->size + size + MAGNET_CONTACT_MARGIN) selfDamp *= MAGNET_CONTACT_DAMP; + float falloff = distance >= MAGNET_NEAR ? 1 / distance : distance * MAGNET_NEAR_FALLOFF; + + float pull = strength * falloff / other->friction; + if (other->type == ENTITY_PROJECTILE) + { + Entity_Projectile& shot = static_cast(*other); + int age = g_game->frameCount - shot.spawnFrame; + float scaled = std::min((float)age / MAGNET_SHOT_AGE_FRAMES, 1.0f) * falloff; + pull = strength * scaled / shot.friction; + magnet_shot_slow(shot, scaled); + if (scaled > MAGNET_SHOT_DROP && shot.fallingAccel < 0) shot.fallingAccel = 0; + bool isCaught = distanceSquared < size * size && age > MAGNET_SHOT_CATCH_FRAMES && + shot.height > MAGNET_SHOT_CATCH_HEIGHT; + if (!shot.isDead && isCaught) shot.isDead = true; + } + else if (other->type == ENTITY_TEAR) + { + Entity_Tear& tear = static_cast(*other); + magnet_shot_slow(tear, falloff); + bool isSlow = tear.velocity.y * tear.velocity.y + tear.velocity.x * tear.velocity.x < 1; + if (tear.tearFlags[TEAR_ORBIT] && isSlow) + { + TearFlags flags = tear.tearFlags; + flags[TEAR_ORBIT] = false; + tear.SetTearFlags(flags); + } + } + other->velocity.x = toward.x * pull + other->velocity.x; + other->velocity.y = toward.y * pull + other->velocity.y; + } + velocity.y = selfDamp * velocity.y; + velocity.x = selfDamp * velocity.x; +} diff --git a/src/familiar_dip.cpp b/src/familiar_dip.cpp new file mode 100644 index 0000000..43a3bf7 --- /dev/null +++ b/src/familiar_dip.cpp @@ -0,0 +1,107 @@ +#include "entity_familiar.h" +#include "entity_player.h" +#include "game.h" +#include "grid_entity_poop.h" +#include "npc_ai.h" +#include "platform.h" +#include "room_grid.h" + +// A player keeps at most this many Dips, the first dip subtype a thrown poop turns into a plain Dip, and the last. +constexpr int DIP_OWNED_LIMIT = 32; +constexpr int DIP_PLAIN_FROM = POOP_GIGA_TOP_LEFT; +constexpr int DIP_PLAIN_TO = POOP_CHARMING; +// How much a Dip is worth keeping by subtype, above how long it has lived: corn first to go, the rarer ones last. +constexpr float DIP_KEEP_SCORES[] = {0, 10000, -200, 20000, 20000, 10000, 20000, 0, 0, 0, 0, 0, 10000, 10000, 10000}; +constexpr float DIP_KEEP_SCORE_MAX = 1e10f; +// A Dip thrown toward a spot: how far around a free spot it lands, its speed toward it and its lift. +constexpr float DIP_SPOT_DISTANCE = 80; +constexpr float DIP_LANDING_SPREAD = 20; +constexpr float DIP_THROW_SPEED = 0.04f; +constexpr float DIP_THROW_LIFT = -8; +constexpr int DIP_THROWN_STATE = 2; +// The share of a versus player's color a Dip's glow takes, and the color slot of a player without one. +constexpr float DIP_VERSUS_GLOW = 0.25f; +constexpr int DIP_VERSUS_NO_SLOT = 5; + +// 00639000 Spawns a Dip of a subtype for its owner (the poop variants without a Dip of their own give a plain one), +// first killing the owner's least worth keeping while it has more than 32. In versus it takes its player's color. +Entity* Entity_Familiar::ThrowDip(int subType, const Vector& position, Entity* spawner) +{ + while (true) + { + Entity_Familiar* worst = nullptr; + float worstScore = DIP_KEEP_SCORE_MAX; + int count = 0; + for (Entity_Familiar* dip : familiar_query(DIP)) + { + if (dip->isDead || dip->player != spawner) continue; + + float score = dip->subtype >= 0 && dip->subtype < (int)std::size(DIP_KEEP_SCORES) + ? DIP_KEEP_SCORES[dip->subtype] + : 0; + score -= (float)(g_game->frameCount - dip->spawnFrame); + if (score < worstScore) + { + worst = dip; + worstScore = score; + } + count++; + } + if (count <= DIP_OWNED_LIMIT) break; + if (!worst) + { + log_printf(LOG_WARN, "Entity_Familiar::ThrowDip: couldn't find a candidate for removal, remaining: %d\n", + count); + break; + } + worst->Kill(EntityRef()); + } + + bool isPlain = subType >= DIP_PLAIN_FROM && subType <= DIP_PLAIN_TO; + Entity* dip = g_game->Spawn({.position = position, + .spawner = spawner, + .subType = isPlain ? 0 : subType, + .type = ENTITY_FAMILIAR, + .variant = DIP, + .seed = Random()}); + dip->ClearEntityFlags(FLAG_APPEAR); + if (!g_game->deathmatchManager.is_active() || !spawner || spawner->type != ENTITY_PLAYER) return dip; + + std::array& slots = g_game->playerManager.colorControllers; + auto slot = std::ranges::find(slots, static_cast(spawner)->controllerIndex); + int colorSlot = slot == slots.end() ? DIP_VERSUS_NO_SLOT : (int)(slot - slots.begin()); + KColor color = PlayerManager::GetPlayerColorValue(colorSlot); + dip->sprite.color = {{color._red, color._green, color._blue, 1}, + {0, 0, 0, 0}, + {color._red * DIP_VERSUS_GLOW, color._green * DIP_VERSUS_GLOW, color._blue * DIP_VERSUS_GLOW}}; + return dip; +} + +// 006393a0 Throws a Dip from a position to a target, or without one to a random spot near a free one 80 away. It +// arcs there, as thrown Dips do. +Entity* spawn_dip_at(int subType, const Vector* position, Entity* spawner, const Vector* targetPosition) +{ + Vector target = *targetPosition; + if (vector_is_zero(target)) + { + Vector direction = random_direction(); + Vector probe = vector_make(direction.x * DIP_SPOT_DISTANCE + position->x, + direction.y * DIP_SPOT_DISTANCE + position->y); + Vector spot = room_free_pickup_position_find( + {.position = probe, .step = DIP_SPOT_DISTANCE, .isAvoidActiveEntities = true}); + Vector landing = random_direction(); + float spread = random_unit(); + target = vector_make(landing.x * spread * DIP_LANDING_SPREAD + spot.x, + landing.y * spread * DIP_LANDING_SPREAD + spot.y); + } + + Vector velocity = + vector_make((target.x - position->x) * DIP_THROW_SPEED, (target.y - position->y) * DIP_THROW_SPEED); + Entity_Familiar& dip = *static_cast(Entity_Familiar::ThrowDip(subType, *position, spawner)); + dip.targetPosition = target; + dip.velocity = velocity; + dip.orbitSpeed = DIP_THROW_LIFT; + dip.orbitDistance = velocity; + dip.state = DIP_THROWN_STATE; + return &dip; +} diff --git a/src/familiar_missing.cpp b/src/familiar_missing.cpp index a034baa..74a3f47 100644 --- a/src/familiar_missing.cpp +++ b/src/familiar_missing.cpp @@ -153,12 +153,6 @@ void Entity_Familiar::ai_samsons_chains() reconstruction_missing("Entity_Familiar::ai_samsons_chains 0062e120"); } -// 0062e620 -void Entity_Familiar::update_weapon(bool) -{ - reconstruction_missing("Entity_Familiar::update_weapon 0062e620"); -} - // 0062ee30 void Entity_Familiar::ai_lil_gurdy() { @@ -237,12 +231,6 @@ Entity_Laser* Entity_Familiar::FireBrimstone(const Vector&, uint8_t) reconstruction_missing("Entity_Familiar::FireBrimstone 00638c10"); } -// 00639000 -Entity* Entity_Familiar::ThrowDip(int, const Vector&, Entity*) -{ - reconstruction_missing("Entity_Familiar::ThrowDip 00639000"); -} - // 0063aef0 Entity_Laser* Entity_Familiar::sprinkler_shoot_laser(float, float) { diff --git a/src/familiar_shoot.cpp b/src/familiar_shoot.cpp index 1edadc3..6dba89b 100644 --- a/src/familiar_shoot.cpp +++ b/src/familiar_shoot.cpp @@ -555,3 +555,67 @@ Entity_Laser* Entity_Familiar::fire_robo_baby_laser(const Vector&) reconstruction_missing("Entity_Familiar::fire_robo_baby_laser 00613c20 " "(Entity_Laser::ShootAngle 0096f310)"); } + +// 0062e620 Keeps a copying familiar's weapon (Incubus' and the like) the kind its player's is, then aims and fires it +// as the player shoots, unless the player is busy or cannot move: at the player's mark, at random for Cain's Other Eye, +// with the player's fire delay (halved by Forgotten Lullaby) and a fixed aim. The head turns to the shot, and the +// counters count down on real frames. +void Entity_Familiar::update_weapon(bool isInterpolated) +{ + Game& game = *g_game; + if (player->isDead) return; + + Weapon* playerWeapon = player->weapons[1].get(); + if (!isInterpolated && !playerWeapon) weapon.reset(); + else if (!isInterpolated && (!weapon || weapon->weaponType != playerWeapon->weaponType)) + { + weapon.reset(); + weapon = weapon_create(playerWeapon->weaponType, this); + } + bool isPlayerBusy = player->isPlayingExtraAnimation || player->isPlayingItemAnimation || + game.stageTransition.state != STAGE_TRANSITION_NONE || !player->isControlsEnabled || + player->controlsCooldown > 0; + if (isPlayerBusy) return; + + Vector aim = player->aimDirection; + int direction = player->fireDirection; + bool isShooting = player->fireDirection != DIRECTION_NONE; + Vector markedAim{}; + if (playerWeapon && weapon) TryAimAtMarkedTarget(aim, direction, &markedAim); + if (variant == CAINS_OTHER_EYE) + { + float angle = random_unit() * 3.14f; + angle = angle + angle; + aim = vector_make(std::cos(angle), std::sin(angle)); + if (std::abs(aim.x) <= std::abs(aim.y)) direction = aim.y >= 0 ? DIRECTION_DOWN : DIRECTION_UP; + else direction = aim.x < 0 ? DIRECTION_LEFT : DIRECTION_RIGHT; + } + if (counter < 1) + { + if (direction == DIRECTION_NONE && (headFrameDelay < 1 || (direction = shootDirection) == DIRECTION_NONE)) + direction = DIRECTION_DOWN; + if (Entity* focus = weapon ? weapon->GetFocusEntity() : nullptr) + direction = vector_to_direction(vector_sub(focus->pos, pos)); + shootDirection = direction; + } + bool isLullaby = player->HasTrinket(TRINKET_FORGOTTEN_LULLABY); + if (playerWeapon && weapon) + { + weapon->fixedDirection = markedAim; + weapon->maxFireDelay = isLullaby ? playerWeapon->maxFireDelay * 0.5f : playerWeapon->maxFireDelay; + weapon->modifiers = playerWeapon->modifiers | WEAPON_MOD_FIXED_AIM; + weapon->Update(isInterpolated); + weapon->Fire(aim, isShooting, isInterpolated); + } + if (isInterpolated) return; + + if (fireCooldown == 0) + { + if (headFrameDelay <= HEAD_FLOAT_FRAME) PlayFloatAnim(shootDirection); + else PlayShootAnim(shootDirection); + } + if (counter > 0) counter--; + if (headFrameDelay > 0) headFrameDelay--; + if (fireCooldown > 0) fireCooldown--; + if (isLullaby && fireCooldown > 0) fireCooldown--; +} diff --git a/src/game.h b/src/game.h index cde1e17..996264e 100644 --- a/src/game.h +++ b/src/game.h @@ -61,8 +61,11 @@ enum Difficulty : 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_DEVILROOM_SPAWNED = 5, GAME_STATE_DEVILROOM_VISITED = 6, GAME_STATE_HEAVEN_PATH = 19, + GAME_STATE_KRAMPUS_SPAWNED = 29, GAME_STATE_BOSSRUSH_DONE = 33, GAME_STATE_BOSSRUSH_DOOR_SPAWNED = 38, GAME_STATE_BLUEWOMB_DOOR_SPAWNED = 39, diff --git a/src/game_over.h b/src/game_over.h index d1c1c90..c1fc383 100644 --- a/src/game_over.h +++ b/src/game_over.h @@ -14,6 +14,7 @@ enum GameOverState : int enum GameEnding : int { ENDING_DEATH = 1, + ENDING_MOM = 2, ENDING_LAST = 14 }; diff --git a/src/grid_entity_poop.cpp b/src/grid_entity_poop.cpp index d5b5d05..f994ccd 100644 --- a/src/grid_entity_poop.cpp +++ b/src/grid_entity_poop.cpp @@ -2,6 +2,7 @@ #include "entity_bomb.h" #include "entity_config.h" #include "entity_effect_combat.h" +#include "entity_familiar.h" #include "entity_npc.h" #include "entity_pickup.h" #include "entity_player.h" diff --git a/src/grid_entity_pressure_plate.cpp b/src/grid_entity_pressure_plate.cpp index 8d73e89..8d56c5a 100644 --- a/src/grid_entity_pressure_plate.cpp +++ b/src/grid_entity_pressure_plate.cpp @@ -38,8 +38,7 @@ constexpr float TIMER_TEXT_DROP = 13; constexpr KColor TIMER_WHITE = kcolor_rgba(1, 1, 1, 1); constexpr KColor TIMER_GREY = kcolor_rgba(0.3f, 0.3f, 0.3f, 1); -// The waves Greed's button shows a boss's skull and the last boss's pentagram from, one later in Greedier. -constexpr uint32_t GREED_BOSS_WAVE = 9; +// The wave Greed's button shows the last boss's pentagram from, one later in Greedier. constexpr uint32_t GREED_FINAL_BOSS_WAVE = 11; // What a reward plate's roll out of 100 gives below each bound, the most of a pickup it drops at once, and the diff --git a/src/grid_entity_statue.cpp b/src/grid_entity_statue.cpp index b42a26f..6207317 100644 --- a/src/grid_entity_statue.cpp +++ b/src/grid_entity_statue.cpp @@ -8,11 +8,9 @@ #include "music_manager.h" #include "room.h" -// The statue kinds and the effects that draw them, and the grid path a standing statue claims. +// The statue kinds. constexpr int STATUE_DEVIL = 0; constexpr int STATUE_ANGEL = 1; -constexpr int EFFECT_DEVIL_STATUE = 6; -constexpr int EFFECT_ANGEL_STATUE = 9; // The run's flags for each angel once spawned, the achievement that lets angel statues break into them, the // alternate floors' boss music and the music fade. @@ -30,7 +28,7 @@ void GridEntity_Statue::subclass_init() if (state == STATUE_STATE_STANDING && isKnown) { uint32_t seed = Random(); - int effect = variant == STATUE_DEVIL ? EFFECT_DEVIL_STATUE : EFFECT_ANGEL_STATUE; + int effect = variant == STATUE_DEVIL ? EFFECT_DEVIL : EFFECT_ANGEL; statueEffect = g_game->Spawn({.position = Position(), .type = ENTITY_EFFECT, .variant = effect, .seed = seed}); } path_set(state == STATUE_STATE_STANDING ? GRID_PATH_SOLID : 0); diff --git a/src/homing_laser.cpp b/src/homing_laser.cpp new file mode 100644 index 0000000..8f7806b --- /dev/null +++ b/src/homing_laser.cpp @@ -0,0 +1,348 @@ +#include "homing_laser.h" +#include "boss_ai.h" +#include "entity_laser.h" +#include "entity_player.h" +#include "entity_tear.h" +#include "log.h" +#include "player_manager.h" +#include +#include + +constexpr float BEZIER_HALF = 0.5f; +constexpr int BEZIER_LENGTH_STEPS = 10; +constexpr float SMOOTHING_FULL_LENGTH = 200; +constexpr float PLAYER_CUT_DISTANCE_SQUARED = 100; +constexpr uint32_t PLAYER_CUT_FIRST_SAMPLE = 2; +constexpr float GRID_HALF_CELL = GRID_CELL_SIZE / 2; + +// A point on the cubic curve from one bezier point to the next, t from 0 to 1. +static Vector bezier_evaluate(const BezierPoint& from, const BezierPoint& to, float t) +{ + float u = 1 - t; + float weight0 = u * u * u; + float weight1 = u * u * 3 * t; + float weight2 = u * 3 * t * t; + float weight3 = t * t * t; + return vector_make( + weight0 * from.point.x + weight1 * from.handleOut.x + weight2 * to.handleIn.x + weight3 * to.point.x, + weight0 * from.point.y + weight1 * from.handleOut.y + weight2 * to.handleIn.y + weight3 * to.point.y); +} + +// 0099c340 Where a point lands on a segment, clamped to it (0 for a segment of no length), and how far from there. +SegmentProjection segment_project_point(const Vector& point, const Vector& start, const Vector& end) +{ + Vector segment = vector_sub(end, start); + float lengthSquared = vector_length_squared(segment); + float t = 0; + if (lengthSquared != 0) t = std::clamp(vector_dot(segment, vector_sub(point, start)) / lengthSquared, 0.0f, 1.0f); + + Vector offset = vector_sub(point, vector_add(start, vector_scale(segment, t))); + return {vector_length_squared(offset), t}; +} + +// 0070be60 Whether a cell of a grid collision blocks an entity of a grid collision class. +bool grid_collision_blocks(int gridCollisionClass, int collision) +{ + bool isWall = collision == COLLISION_WALL || collision == COLLISION_WALL_EXCEPT_PLAYER; + bool isStanding = collision == COLLISION_OBJECT || collision == COLLISION_SOLID || isWall; + switch (gridCollisionClass) + { + case GRIDCOLL_WALLS_X: + case GRIDCOLL_WALLS_Y: + case GRIDCOLL_WALLS: + return isWall; + case GRIDCOLL_GROUND: + return collision == COLLISION_PIT || isStanding; + case GRIDCOLL_BULLET: + case GRIDCOLL_NOPITS: + return isStanding; + case GRIDCOLL_PITSONLY: + return collision != COLLISION_PIT; + default: + return false; + } +} + +// 007f0870 Room::check_line_collision: walks a line cell by cell to the first cell that blocks the grid collision +// class. Walls and doors may be passed through, for the beams that the room's edge stops instead. +LineCheck room_line_check(const Vector& from, const Vector& to, int gridCollisionClass, bool isWallsIgnored) +{ + Room& room = *g_game->room; + Vector delta = vector_sub(to, from); + Vector position = from; + int column = (int)((from.x - GRID_ORIGIN_X) / GRID_CELL_SIZE + BEZIER_HALF); + int row = (int)((from.y - GRID_ORIGIN_Y) / GRID_CELL_SIZE + BEZIER_HALF); + int stepX = delta.x > 0 ? 1 : -1; + int stepY = delta.y > 0 ? 1 : -1; + float progress = 0; + + if (!vector_is_zero(delta)) + while (true) + { + int index = room.GetGridIndexByTile(column, row); + GridEntity* grid = index >= 0 ? room.GetGridEntity(index) : nullptr; + bool isPassedWall = isWallsIgnored && grid && (grid->type == GRID_WALL || grid->type == GRID_DOOR); + if (grid_collision_blocks(gridCollisionClass, (int)room.GetGridCollision(index)) && !isPassedWall) break; + + float edgeX = (float)column * GRID_CELL_SIZE + GRID_ORIGIN_X + (float)stepX * GRID_HALF_CELL; + float edgeY = (float)row * GRID_CELL_SIZE + GRID_ORIGIN_Y + (float)stepY * GRID_HALF_CELL; + float toX = delta.x == 0 ? INFINITY : (edgeX - position.x) / delta.x; + float toY = delta.y == 0 ? INFINITY : (edgeY - position.y) / delta.y; + if (toY <= toX) + row += stepY; + else + column += stepX; + progress += std::min(toX, toY); + position = vector_add(from, vector_scale(delta, progress)); + if (progress >= 1) break; + } + return {progress < 1 ? position : to, progress >= 1}; +} + +// 0099c790 Lays out the path's bezier points: a straight one from the origin to the end unless some are already +// there. The homing paths and Eye of the Occult's bend are not reconstructed yet. +void HomingLaser::build_bezier_path(BezierPathType pathType, Entity* source) +{ + if (bezier.empty()) + { + Vector middle = vector_scale(vector_add(origin, endPoint), BEZIER_HALF); + bezier.push_back({origin, origin, middle}); + bezier.push_back({endPoint, middle, endPoint}); + } + + Entity_Laser* laser = owner && owner->type == ENTITY_LASER ? static_cast(owner) : nullptr; + if (laser && laser->tearFlags[TEAR_OCCULT]) + reconstruction_missing("HomingLaser::build_bezier_path 0099c790: Eye of the Occult's bend"); + if (pathType != BEZIER_PATH_STRAIGHT && source) + reconstruction_missing("HomingLaser::build_bezier_path 0099c790: a homing path"); +} + +// 0099e360 Samples the bezier path evenly along its length, then eases the kept samples toward them: a ring all at +// once by blend, a line less toward its end the longer it is. +void HomingLaser::CalculateSamples(float blend) +{ + if (bezier.size() < 2) KAGE_LogMessage(LOG_ASSERT, (uint8_t*)"Bezier Path Size is less than 2!\n"); + + std::vector lengths = {0}; + totalLength = 0; + for (size_t segment = 0; segment + 1 < bezier.size(); segment++) + { + float length = 0; + Vector previous = bezier_evaluate(bezier[segment], bezier[segment + 1], 0); + for (int step = 1; step <= BEZIER_LENGTH_STEPS; step++) + { + Vector next = bezier_evaluate(bezier[segment], bezier[segment + 1], (float)step / BEZIER_LENGTH_STEPS); + length += vector_length(vector_sub(next, previous)); + previous = next; + } + lengths.push_back(length); + totalLength += length; + } + if (totalLength != 0) + { + lengths[0] /= totalLength; + for (size_t i = 1; i < lengths.size(); i++) lengths[i] = lengths[i] / totalLength + lengths[i - 1]; + } + + std::vector fresh; + uint32_t segmentCount = (uint32_t)lengths.size() - 1; + uint32_t lengthIndex = 0; + for (uint32_t i = 0; i <= sampleNum; i++) + { + float fraction = (float)i / (float)sampleNum; + float along = fraction; + for (uint32_t j = lengthIndex; j < segmentCount && lengths[j] < fraction; j++) + { + along = (fraction - lengths[j]) / (lengths[j + 1] - lengths[j]) / (float)segmentCount + + (float)j / (float)segmentCount; + lengthIndex = j; + } + + if (bezier.size() < 2) KAGE_LogMessage(LOG_ASSERT, (uint8_t*)"Bezier Path Size less than 2!\n"); + int lastSegment = (int)bezier.size() - 1; + float position = (float)lastSegment * along; + int segment = (int)position; + if (segment < 0) + fresh.push_back(bezier.front().point); + else if (segment < lastSegment) + fresh.push_back(bezier_evaluate(bezier[segment], bezier[segment + 1], position - (float)segment)); + else + fresh.push_back(bezier.back().point); + } + + if (smoothedSamples.size() != fresh.size()) + smoothedSamples = fresh; + else if (isRing) + for (size_t i = 0; i < fresh.size(); i++) + smoothedSamples[i] = + vector_add(smoothedSamples[i], vector_scale(vector_sub(fresh[i], smoothedSamples[i]), blend)); + else + { + float lineBlend = blend * std::clamp(totalLength / SMOOTHING_FULL_LENGTH, 0.0f, 1.0f); + float last = (float)(smoothedSamples.size() - 1); + for (size_t i = 0; i < fresh.size(); i++) + { + float weight = 1 - (float)i / last * lineBlend; + smoothedSamples[i] = + vector_add(smoothedSamples[i], vector_scale(vector_sub(fresh[i], smoothedSamples[i]), weight)); + } + } + samples = smoothedSamples; +} + +// 009a0520 Cuts the samples at the first one in a cell that blocks the grid collision class (keeping two), ending +// them where the last segment meets that cell. A first sample already blocked keeps them as they are. Whether one +// was blocked. +bool HomingLaser::clip_samples_to_grid(const Vector& offset, int gridCollisionClass) +{ + if (gridCollisionClass == GRIDCOLL_WALLS || gridCollisionClass == GRIDCOLL_NONE) return false; + + Room& room = *g_game->room; + for (size_t i = 0; i < samples.size(); i++) + { + Vector position = vector_add(offset, samples[i]); + int column = (int)((position.x - GRID_ORIGIN_X) / GRID_CELL_SIZE + BEZIER_HALF); + int row = (int)((position.y - GRID_ORIGIN_Y) / GRID_CELL_SIZE + BEZIER_HALF); + if (!grid_collision_blocks(gridCollisionClass, + (int)room.GetGridCollision(room.GetGridIndexByTile(column, row)))) + continue; + + samples.resize(std::min(samples.size(), std::max(i, 2))); + if (i == 0 || samples.size() < 2) return true; + + Vector from = vector_add(offset, samples[samples.size() - 2]); + Vector to = vector_add(offset, samples.back()); + samples.back() = vector_sub(room_line_check(from, to, gridCollisionClass, true).hit, offset); + return true; + } + return false; +} + +// 009a0740 Cuts the samples, from the third on, at the first one within 10 of a player (Challenge #30's lasers). +void HomingLaser::truncate_samples_at_player() +{ + for (uint32_t i = PLAYER_CUT_FIRST_SAMPLE; i < samples.size(); i++) + for (Entity_Player* player : g_game->playerManager.playerList) + if (i < samples.size() && + vector_length_squared(vector_sub(player->pos, samples[i])) < PLAYER_CUT_DISTANCE_SQUARED) + samples.resize(i); +} + +// 009a0de0 Keeps the samples as they are as the non-optimized ones, then drops each inner sample its neighbours +// already line up through. +void HomingLaser::remove_collinear_samples(float tolerance) +{ + nonOptimizedSamples = samples; + if (samples.empty()) return; + + size_t last = samples.size() - 1; + for (size_t i = 1; i < last; i++) + { + Vector in = vector_normalized(vector_sub(samples[i], samples[i - 1])); + Vector out = vector_normalized(vector_sub(samples[i + 1], samples[i])); + if (std::abs(1 - vector_dot(in, out)) >= tolerance) continue; + + samples.erase(samples.begin() + (long)i); + i--; + last--; + } +} + +// 009a1520 Cuts the path where it reaches a length along it. Whether it cut it. +// The original works out the point on the segment reaching that length, then ends the path before it, at the +// segment's start. That is kept. +bool HomingLaser::truncate_samples(float maxLength) +{ + float remaining = maxLength; + for (size_t i = 0; i + 1 < samples.size(); i++) + { + float length = vector_length(vector_sub(samples[i + 1], samples[i])); + if (remaining <= length) + { + samples.resize(i + 1); + return true; + } + remaining -= length; + } + return false; +} + +// 009a12b0 The first entity of a type and variant the path runs through, from the second segment on, skipping the +// ones the source's player owns. The path stops on it, where and in which direction it gets there. +Entity* HomingLaser::find_targets(Vector& outPosition, Vector& outDirection, int type, int variant, Entity* source) +{ + if (samples.empty()) return nullptr; + + std::vector candidates = entity_query(type, variant); + for (size_t i = 1; i + 1 < samples.size(); i++) + for (Entity* candidate : candidates) + { + if (source && candidate->IsDescendantOf(source->GetPlayerAncestor())) continue; + + SegmentProjection projection = segment_project_point(candidate->pos, samples[i], samples[i + 1]); + if (projection.distanceSquared >= candidate->size * candidate->size) continue; + + outDirection = vector_normalized(vector_sub(samples[i + 1], samples[i])); + outPosition = vector_add(samples[i], vector_scale(vector_sub(samples[i + 1], samples[i]), projection.t)); + samples[i + 1] = outPosition; + samples.resize(i + 2); + return candidate; + } + return nullptr; +} + +// The path shapes of the tear flags and homing are not reconstructed yet. + +// 0099dca0 +void HomingLaser::compute_axis_bezier_handles() +{ + reconstruction_missing("HomingLaser::compute_axis_bezier_handles 0099dca0"); +} + +// 0099e160 +void HomingLaser::compute_bezier_handles(float) +{ + reconstruction_missing("HomingLaser::compute_bezier_handles 0099e160"); +} + +// 0099ec00 +void HomingLaser::apply_sine_offset(float, float) +{ + reconstruction_missing("HomingLaser::apply_sine_offset 0099ec00"); +} + +// 0099fa60 +void HomingLaser::build_curl_path(float) +{ + reconstruction_missing("HomingLaser::build_curl_path 0099fa60"); +} + +// 0099fed0 +void HomingLaser::build_wiggle_bezier() +{ + reconstruction_missing("HomingLaser::build_wiggle_bezier 0099fed0"); +} + +// 009a0c50 +void HomingLaser::truncate_samples_at_obstacle(const Vector&) +{ + reconstruction_missing("HomingLaser::truncate_samples_at_obstacle 009a0c50"); +} + +// 009a0fa0 +void HomingLaser::apply_sample_wiggle(float, float) +{ + reconstruction_missing("HomingLaser::apply_sample_wiggle 009a0fa0"); +} + +// 009a0850 +void HomingLaser::build_ring_bezier() +{ + reconstruction_missing("HomingLaser::build_ring_bezier 009a0850"); +} + +// 0099f2c0 +void HomingLaser::trace_entities(uint32_t) +{ + reconstruction_missing("laser_sample_trace_entities 0099f2c0"); +} diff --git a/src/homing_laser.h b/src/homing_laser.h new file mode 100644 index 0000000..669c3ab --- /dev/null +++ b/src/homing_laser.h @@ -0,0 +1,92 @@ +#pragma once + +#include "entity.h" +#include + +// The samples a laser path takes along its curves, and the length one straight laser's are spaced for. +constexpr uint32_t HOMING_LASER_SAMPLES = 50; +constexpr float HOMING_LASER_REACH = 120; +constexpr float HOMING_LASER_RING_REACH = 60; +constexpr float HOMING_LASER_HOMING_REACH = 400; + +// How a laser homes (Lua's LaserHomingType). +enum LaserHomingType : int +{ + LASER_HOMING_NORMAL, + LASER_HOMING_FREEZE, + LASER_HOMING_PLAYER +}; + +// What build_bezier_path bends a path toward: nothing, enemies, enemies of another type than the source, or players +// too. +enum BezierPathType : int +{ + BEZIER_PATH_STRAIGHT = 0, + BEZIER_PATH_HOMING = 1, + BEZIER_PATH_OTHER_TYPES = 4, + BEZIER_PATH_WITH_PLAYERS = 5 +}; + +// One point of a laser's path with the handles of the curves into and out of it (HomingLaser_Bezier). +struct BezierPoint +{ + Vector point{}; + Vector handleIn{}; + Vector handleOut{}; +}; + +// Construction, copies and destruction (0099c290, 0085e000, and the vectors' 009a1610, 009a1680, 009a17b0) are the +// defaults. +// The path a laser or knife follows (REPENTOGON's HomingLaser): bezier points from an origin to an end, bent toward +// targets for a homing one, sampled evenly along their length. smoothedSamples eases the samples toward each new +// path so the beam sweeps instead of jumping. +struct HomingLaser +{ + std::vector bezier; + std::vector nonOptimizedSamples; + std::vector samples; + std::vector smoothedSamples; + Entity* owner = nullptr; + Vector endPoint{}; + Vector origin{}; + float reach = 0; + float totalLength = 0; + uint32_t sampleNum = 0; + bool isRing = false; + + void build_bezier_path(BezierPathType pathType, Entity* source); + void CalculateSamples(float blend); + bool clip_samples_to_grid(const Vector& offset, int gridCollisionClass); + void truncate_samples_at_player(); + void remove_collinear_samples(float tolerance); + bool truncate_samples(float maxLength); + Entity* find_targets(Vector& outPosition, Vector& outDirection, int type, int variant, Entity* source); + + void compute_axis_bezier_handles(); + void compute_bezier_handles(float tension); + void apply_sine_offset(float amplitude, float phase); + void build_curl_path(float radius); + void build_wiggle_bezier(); + void truncate_samples_at_obstacle(const Vector& offset); + void apply_sample_wiggle(float amplitude, float phase); + void build_ring_bezier(); + void trace_entities(uint32_t turnFlags); +}; + +// Where a point lands on a segment, as a fraction of it clamped to the segment, with its squared distance to there. +struct SegmentProjection +{ + float distanceSquared = 0; + float t = 0; +}; + +// The first cell blocking a line for a grid collision class, and whether there was none before its end. +struct LineCheck +{ + Vector hit{}; + bool isClear = false; +}; + +SegmentProjection segment_project_point(const Vector& point, const Vector& start, const Vector& end); +bool grid_collision_blocks(int gridCollisionClass, int collision); +LineCheck room_line_check(const Vector& from, const Vector& to, int gridCollisionClass, bool isWallsIgnored); diff --git a/src/item_info_hud.cpp b/src/item_info_hud.cpp index cec358c..cc1c9ac 100644 --- a/src/item_info_hud.cpp +++ b/src/item_info_hud.cpp @@ -1,4 +1,5 @@ #include "item_info_hud.h" +#include "entity_player.h" #include "game.h" #include "log.h" #include "manager.h" @@ -11,7 +12,6 @@ constexpr const char* ANIMATION_CHARGE_ICON = "ChargeIcon"; constexpr float ITEM_INFO_LINE_SPACING = 0.9f; constexpr float ITEM_INFO_ICON_SCALE = 4; constexpr int ACHIEVEMENT_ITEM_INFO = 641; -constexpr uint32_t CHALLENGE_APRILS_FOOL = 32; // 0083c5f0 Loads the panel's font (without redirection), charge icon and map icons. void ItemInfoHUD::load_graphics() diff --git a/src/item_pickup.cpp b/src/item_pickup.cpp index c8002ea..5b6ff42 100644 --- a/src/item_pickup.cpp +++ b/src/item_pickup.cpp @@ -30,7 +30,6 @@ constexpr int COLLECTIBLE_GLITCHED_GFUEL = -1; constexpr int ACHIEVEMENT_GLITCHED_ITEMS = 593; constexpr int DIMENSION_DEATH_CERTIFICATE = 2; constexpr int EVENT_ANGEL_ITEMS_TAKEN = 15; -constexpr uint32_t QUEUED_TOUCHED = 0x1; constexpr uint32_t MONSTER_MANUEL_ODDS = 3; // The pedestals Alternates frames that change the pickup's size: Mom's Chest's, and the two halves of a Mega Chest's. @@ -60,7 +59,6 @@ constexpr uint32_t GLITCH_SECRET_ODDS = 60; constexpr uint32_t PICKUP_RNG_SHIFT_COLLECTIBLE = 35; constexpr uint32_t ITEM_LAYER_UNFILTERED = 0x20; constexpr int COLLECTIBLE_UNFILTERED_GFX = 633; -constexpr int CHALLENGE_APRILS_FOOL = 32; // The sounds an item makes when taken, by the room it was in. constexpr int SOUND_1UP = 1; diff --git a/src/item_pool.cpp b/src/item_pool.cpp index 5a0bdd3..aeee2eb 100644 --- a/src/item_pool.cpp +++ b/src/item_pool.cpp @@ -58,6 +58,21 @@ constexpr uint32_t ERROR_ROOM_SHIFT = 7; constexpr uint32_t MAGIC_SKIN_SHIFT = 55; constexpr uint32_t GOLDEN_SHIFT = 19; constexpr uint32_t PILL_SHIFT = 12; +// GetCard's odds of a special card, a rune and a playing card, and the shifts of GetCardEx's and Tainted Lost's draws. +constexpr int CARD_SPECIAL_ODDS = 25; +constexpr int CARD_RUNE_ODDS = 10; +constexpr int CARD_SUIT_ODDS = 10; +constexpr uint32_t CARD_DRAW_SHIFT = 21; +constexpr uint32_t HOLY_CARD_RNG_SHIFT = 47; +// The rune pool's least size, the odds of a blank giving a Rune Shard, and the cards GetCardEx tells apart. +constexpr size_t RUNE_POOL_MIN = 6; +constexpr uint32_t RUNE_SHARD_ODDS = 5; +constexpr int CARD_RUNE_SHARD = 55; +constexpr int HOLY_CARD = 51; +constexpr uint32_t HOLY_CARD_ODDS = 10; +constexpr int CARD_TAROT_LAST = 22; +constexpr int REVERSED_TAROT_OFFSET = 55; +constexpr uint32_t REVERSED_TAROT_ODDS = 7; constexpr float CHAOS_WEIGHT_SCALE = 100; constexpr float MAGIC_SKIN_CHANCE_PER_USE = 0.01f; constexpr int MAGIC_SKIN_ROLL_BASE = 4; @@ -113,9 +128,7 @@ constexpr int PILL_HORSE_ODDS = 70; constexpr int PILL_EFFECT_NONE = -1; constexpr int PILLEFFECT_BAD_TRIP = 1; constexpr int PILLEFFECT_EXPLOSIVE_DIARRHEA = 4; -constexpr int PILLEFFECT_FULL_HEALTH = 5; constexpr int PILLEFFECT_HEALTH_DOWN = 6; -constexpr int PILLEFFECT_HEALTH_UP = 7; constexpr int PILLEFFECT_I_FOUND_PILLS = 8; // 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}; @@ -961,14 +974,90 @@ void ItemPool::remove_deathmatch_pill_effects() reconstruction_missing("ItemPool::remove_deathmatch_pill_effects 00734cc0"); } -// (00734870) A card from a seed. -int ItemPool::GetCard(uint32_t, bool, bool, bool) +// 00734870 A card from a seed as MC_GET_CARD leaves it: special cards one in 25 unless only runes, runes one in ten +// (always when only runes), and playing cards one in ten. +int ItemPool::GetCard(uint32_t drawSeed, bool isPlaying, bool isRunes, bool isOnlyRunes) { - reconstruction_missing("ItemPool::GetCard 00734870"); + int suitChance = isPlaying ? CARD_SUIT_ODDS : 0; + int runeChance = isOnlyRunes ? 1 : isRunes ? CARD_RUNE_ODDS : 0; + int card = GetCardEx((int)drawSeed, isOnlyRunes ? 0 : CARD_SPECIAL_ODDS, runeChance, suitChance, true); + RNG rng = rng_make(drawSeed, POOL_SHIFT); + return lua_engine_get().GetCard( + {.rng = &rng, .card = card, .isOnlyRunes = isOnlyRunes, .isPlaying = isPlaying, .isRunes = isRunes}); } -// (00734180) A card, rune or special card from a seed, by the chances given. -int ItemPool::GetCardEx(int, int, int, int, bool) +// Whether a card id is an unlocked card. +static bool is_card_available(int id) { - reconstruction_missing("ItemPool::GetCardEx 00734180"); + ItemConfig_Card* card = g_manager->itemConfig.GetCard(id); + return card && card->IsAvailable(); +} + +// One of a pool's cards when the generator rolls one in odds, or 0. +static int card_pool_draw(RNG& rng, int odds, const std::vector& pool) +{ + if (rng.Next() % (uint32_t)odds != 0 || pool.empty()) return 0; + return pool[rng.RandomInt((uint32_t)pool.size())]; +} + +// 00734180 A card from a seed, one in each chance from its pool: a special card (with objects when allowed), a rune +// (the pool padded with blanks to six, a blank giving a Rune Shard when runes are certain or one in five times), a +// playing card, else a tarot card, reversed one in seven times when unlocked. Tainted Lost turns a tenth of the draws +// with special cards into Holy Cards. A chance of 0 leaves its pool out, a rune chance of -1 always draws a rune. +int ItemPool::GetCardEx(int drawSeed, int specialChance, int runeChance, int suitChance, bool isNonCardsAllowed) +{ + std::vector special; + std::vector runes; + std::vector suits; + std::vector tarots; + for (int id = 1; id < (int)g_manager->itemConfig.cards.size(); id++) + { + if (!is_card_available(id) || id == CARD_RUNE_SHARD) continue; + switch (g_manager->itemConfig.GetCard(id)->cardType) + { + case CARD_TAROT: tarots.push_back(id); break; + case CARD_SUIT: + if (suitChance) suits.push_back(id); + break; + case CARD_RUNE: + if (runeChance) runes.push_back(id); + break; + case CARD_OBJECT: + if (isNonCardsAllowed && specialChance) special.push_back(id); + break; + case CARD_SPECIAL: + if (specialChance) special.push_back(id); + break; + default: break; + } + } + if (!runes.empty() || runeChance == -1) runes.resize(std::max(runes.size(), RUNE_POOL_MIN), 0); + + RNG rng = rng_make((uint32_t)drawSeed, CARD_DRAW_SHIFT); + int runeOdds = runeChance == -1 ? 1 : runeChance; + int card = specialChance ? card_pool_draw(rng, specialChance, special) : 0; + bool isRuneShard = false; + if (!card && runeOdds && rng.Next() % (uint32_t)runeOdds == 0 && !runes.empty()) + { + card = runes[rng.RandomInt((uint32_t)runes.size())]; + isRuneShard = !card && (runeOdds == 1 || rng.RandomInt(RUNE_SHARD_ODDS) == 0); + } + if (isRuneShard) card = CARD_RUNE_SHARD; + else + { + if (!card && suitChance) card = card_pool_draw(rng, suitChance, suits); + if (!card && !tarots.empty()) card = tarots[rng.RandomInt((uint32_t)tarots.size())]; + bool isReversible = card > 0 && card <= CARD_TAROT_LAST; + if (isReversible && rng.Next() % REVERSED_TAROT_ODDS == 0 && is_card_available(card + REVERSED_TAROT_OFFSET)) + card += REVERSED_TAROT_OFFSET; + if (card == 0) log_printf(LOG_ASSERT, "No unlocked cards/runes to pick from!\n"); + } + if (!specialChance) return card; + + for (Entity_Player* player : g_game->playerManager.playerList) + { + if (player->variant != 0 || player->isCoopGhost || player->playerType != PLAYER_THELOST_B) continue; + return rng_make(rng._seed, HOLY_CARD_RNG_SHIFT).Next() % HOLY_CARD_ODDS == 0 ? HOLY_CARD : card; + } + return card; } diff --git a/src/level.cpp b/src/level.cpp index e3414e2..3890e78 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -1,5 +1,6 @@ #include "level.h" #include "boss_pool.h" +#include "entity_familiar.h" #include "entity_player.h" #include "game.h" #include "grid_entity_door.h" @@ -73,7 +74,6 @@ constexpr uint32_t SPECIAL_DAILY_DEALS = 17; constexpr uint32_t SPECIAL_DAILY_CURSED = 37; constexpr uint32_t SPECIAL_DAILY_CURSES = CURSE_OF_THE_LOST | CURSE_OF_THE_UNKNOWN | CURSE_OF_BLIND; -constexpr int ACHIEVEMENT_THE_WOMB = 4; constexpr int ACHIEVEMENT_EVERYTHING_IS_TERRIBLE = 33; constexpr int ACHIEVEMENT_STRANGE_DOOR = 635; constexpr int ACHIEVEMENT_SOMETHING_FROM_THE_FUTURE = 16; @@ -84,7 +84,6 @@ constexpr int ACHIEVEMENT_STORE_UPGRADE_1 = 151; constexpr int ACHIEVEMENT_STORE_UPGRADE_2 = 152; constexpr int ACHIEVEMENT_STORE_UPGRADE_3 = 153; constexpr int ACHIEVEMENT_STORE_UPGRADE_4 = 154; -constexpr int ACHIEVEMENT_THE_VOID = 320; constexpr int ACHIEVEMENT_SOMETHING_WICKED = 346; constexpr int ACHIEVEMENT_SOMETHING_WICKED_PLUS = 347; constexpr int ACHIEVEMENT_THE_FORGOTTEN = 390; @@ -226,6 +225,25 @@ constexpr std::array DOUBLE_TROUBLE_LOCKS = {{{ACHIEVEMENT {ACHIEVEMENT_SOMETHING_WICKED_PLUS, 67, 72}}}; constexpr int DEVILS_CROWN_TRIES = 10; + +// The deal room draws ten times among the first 100 variants (the Womb's special one is 100). Krampus waits in 1 in +// 20 devil rooms after a visited one, 3 with a deal taken, 10 more on the deals daily. +constexpr int DEAL_ROOM_TRIES = 10; +constexpr uint32_t DEAL_VARIANT_LAST = 99; +constexpr uint32_t DEAL_VARIANT_WOMB = 100; +constexpr uint32_t KRAMPUS_ROLL = 20; +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 +// 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; +constexpr float ANGEL_DONATION_SHARE = 0.5f; +constexpr float ANGEL_BEGGAR_SHARE = 0.1f; +constexpr int ANGEL_DONATIONS = 10; +constexpr float ANGEL_CHANCE_EUCHARIST = 77; constexpr uint32_t DEVILS_CROWN_VARIANT_LAST = 99; constexpr int GREED_SUBTYPE = 4; constexpr int GREED_SUBTYPE_SUPER = 11; @@ -2385,11 +2403,9 @@ static void corpse_door_splats_spawn(Level& level) if (!(target.flags & ROOM_DESCRIPTOR_FLAG_USE_ALTERNATE_BACKDROP)) continue; RNG rng = {target.decorationSeed, 2, 15, 17}; - Vector direction{}; + Vector direction = direction_unit(door->direction); int gridIndex = (int)door->gridIndex; - Isaac::GetAxisAlignedUnitVectorFromDir(&direction, door->direction); - Vector out = {-direction.x, -direction.y}; Vector across = {out.x * rotationCos - out.y * rotationSin, out.x * rotationSin + out.y * rotationCos}; float baseX = out.x * SPLAT_DOOR_OFFSET + (float)(gridIndex % room.gridWidth) * GRID_CELL_SIZE + GRID_ORIGIN_X; @@ -2663,9 +2679,25 @@ bool Level::boss_count_adjust(int&, int&) } // 0073fa20 Enters a room config directly, for debugging. -void Level::DEBUG_goto_room(RoomConfig_Room*) +void Level::DEBUG_goto_room(RoomConfig_Room* roomConfig) { - reconstruction_missing("Level::DEBUG_goto_room 0073fa20"); + RoomDescriptor& debug = *GetRoomByIdx(ROOM_DEBUG_IDX); + + for (GridEntityDesc& grid : debug.savedGridEntities) grid._type = 0; + debug.flags &= ~ROOM_DESCRIPTOR_FLAG_CLEAR; + debug.visitedCount = 0; + debug.savedEntities.clear(); + debug.restrictedGridIndexes.clear(); + debug.savedEffects.clear(); + debug.allowedDoors = roomConfig->doors; + debug.data = roomConfig; + debug.spawnSeed = Random(); + debug.decorationSeed = Random(); + debug.awardSeed = Random(); + debug.bossDeathSeed = Random(); + debug.shopItemDiscountIdx = -1; + debug.shopItemIdx = -1; + g_game->StartRoomTransition({.animation = TRANSITION_WALK, .roomIndex = ROOM_DEBUG_IDX}); } // The floor's state flags the map effects keep, by bit, so they apply again. @@ -2945,10 +2977,95 @@ bool Level::CanSpawnDevilRoom() return std::popcount(roomList[lastBossRoomListIdx].data->doors & 0xff) > 1; } -// 007499a0 Picks the deal room. -void Level::InitializeDevilAngelRoom(bool, bool) +// 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 +// spawned). Eucharist makes it sure. +float get_angel_room_chance() { - reconstruction_missing("Level::InitializeDevilAngelRoom 007499a0"); + Game& game = *g_game; + 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 isDevilSpawned = game.gameStateFlags & (1ull << GAME_STATE_DEVILROOM_SPAWNED); + + float chance = isFamineOrVisited ? 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); + if (game.donationModAngel >= ANGEL_DONATIONS) chance = raise(chance, ANGEL_DONATION_SHARE); + + uint32_t flags = game.levelStateFlags; + bool isBumLeft = flags & (1u << LEVEL_STATE_BUM_LEFT); + bool isEvilBumLeft = flags & (1u << LEVEL_STATE_EVIL_BUM_LEFT); + if (flags & (1u << LEVEL_STATE_EVIL_BUM_KILLED)) chance = raise(chance, ANGEL_ITEM_SHARE); + if (isBumLeft != isEvilBumLeft) chance = raise(chance, isBumLeft ? ANGEL_BEGGAR_SHARE : -ANGEL_BEGGAR_SHARE); + + bool isScaled = game.angelRoomChance > 0 || (isHeld(COLLECTIBLE_ACT_OF_CONTRITION) && isDevilSpawned) || + isHeld(COLLECTIBLE_BOOK_OF_VIRTUES); + if (isScaled) chance = raise(chance, game.angelRoomChance); + else if (!isDevilSpawned || game.devilRoomDeals != 0) chance = 0; + if (isHeld(COLLECTIBLE_EUCHARIST)) chance = ANGEL_CHANCE_EUCHARIST; + return std::clamp(chance, 0.0f, 1.0f); +} + +// How many of a boss room's doors could lead to a deal room: a slot the boss room has whose side the deal room has. +static int deal_door_matches(uint32_t bossDoors, uint32_t dealDoors, int startSlot) +{ + int matches = 0; + for (int i = 0; i < DOOR_SLOT_COUNT; i++) + { + int slot = (startSlot + i) & (DOOR_SLOT_COUNT - 1); + if ((bossDoors & (1u << slot)) && (dealDoors & (1u << ((slot - 2) & 3)))) matches++; + } + return matches; +} + +// 007499a0 Picks the floor's deal room once: an angel room on the angel roll (or when forced), else a devil room +// (Number Magnet's kind with one). The Womb's first deal is the special one until It Lives! is unlocked. Up to ten +// draws look for one that fits two of the last boss room's doors. Krampus may wait in a devil room once unlocked: +// 1 in 20 after a visited devil room, 3 with a deal taken (10 more on the deals daily). +void Level::InitializeDevilAngelRoom(bool isForceAngel, bool isForceDevil) +{ + RoomDescriptor& desc = *GetRoomByIdx(ROOM_DEVIL_IDX); + if (desc.data) return; + + float angelChance = get_angel_room_chance(); + bool isAngelRoll = devilAngelRoomRNG.RandomFloat() < angelChance; + int effectiveStage = (int)stage + (filter_curses(CURSE_OF_LABYRINTH) ? 1 : 0); + RoomQuery query = room_query(STAGE_ID_SPECIAL_ROOMS, ROOM_DEVIL, 0); + query.maxVariant = DEAL_VARIANT_LAST; + if (effectiveStage == (int)STAGE_WOMB_II && IsStageWithinEnd(STAGE_SHEOL, isAngelRoll) && + !is_unlocked(ACHIEVEMENT_IT_LIVES)) + query.minVariant = query.maxVariant = DEAL_VARIANT_WOMB; + if (isAngelRoll || isForceAngel) query.type = ROOM_ANGEL; + if (isForceDevil) query.type = ROOM_DEVIL; + if (query.type == ROOM_DEVIL) query.subtype = g_game->playerManager.AnyoneHasTrinket(TRINKET_NUMBER_MAGNET) ? 1 : 0; + + desc.InitSeeds(devilAngelRoomRNG); + for (int tries = DEAL_ROOM_TRIES; tries > 0; tries--) + { + desc.data = random_room_get(devilAngelRoomRNG.Next(), query, WEIGHT_KEEP); + if (!CanSpawnDevilRoom()) break; + + int startSlot = (int)(Random() & (DOOR_SLOT_COUNT - 1)); + if (deal_door_matches(roomList[lastBossRoomListIdx].data->doors, desc.data->doors, startSlot) >= 2) break; + } + + Game& game = *g_game; + bool isKrampusFree = is_unlocked(ACHIEVEMENT_KRAMPUS) && !(game.gameStateFlags & (1ull << GAME_STATE_KRAMPUS_SPAWNED)); + if (query.type != ROOM_DEVIL || !isKrampusFree || query.subtype != 0) return; + + uint32_t odds = 0; + if (game.gameStateFlags & (1ull << GAME_STATE_DEVILROOM_VISITED | 1ull << GAME_STATE_KRAMPUS_SPAWNED)) + odds = game.devilRoomDeals > 0 ? KRAMPUS_ODDS_DEAL : KRAMPUS_ODDS_VISITED; + bool isDealsDaily = game.dailyChallenge._specialDailyId == SPECIAL_DAILY_DEALS; + if (isDealsDaily) odds += KRAMPUS_ODDS_DEALS_DAILY; + if (devilAngelRoomRNG.Next() % KRAMPUS_ROLL >= odds || query.minVariant >= DEAL_VARIANT_WOMB) return; + + desc.flags |= ROOM_DESCRIPTOR_FLAG_SURPRISE_MINIBOSS; + if (!isDealsDaily) game.gameStateFlags |= 1ull << GAME_STATE_KRAMPUS_SPAWNED; } // 0074ba00 Starts Mama Mega's explosion. @@ -3042,7 +3159,9 @@ bool Level::UpdateBackwardsPathStages() // 0074b960 The stage counted as in normal runs. int Level::GetAbsoluteStage() { - reconstruction_missing("Level::GetAbsoluteStage 0074b960"); + if (g_game->difficulty != DIFFICULTY_GREED && g_game->difficulty != DIFFICULTY_GREEDIER) return (int)stage; + if (stage < STAGE_GREED_SHEOL) return (int)stage * 2 - 1; + return stage == STAGE_GREED_SHEOL ? STAGE_SHEOL : 0; } // 0074bae0 The secret exit the floor's depth calls for, an XL floor counting as its second stage and the alternate path diff --git a/src/level.h b/src/level.h index c7760a0..45fce5f 100644 --- a/src/level.h +++ b/src/level.h @@ -17,6 +17,8 @@ constexpr int ROOM_MAP_CELLS = DIMENSION_COUNT * LEVEL_GRID_CELLS; constexpr int OFF_MAP_ROOM_COUNT = 20; constexpr int ROOM_DESCRIPTOR_COUNT = ROOM_MAP_CELLS + OFF_MAP_ROOM_COUNT; constexpr int GREED_WAVE_SEED_COUNT = 12; +// Greed mode's boss wave, one later in Greedier. +constexpr int GREED_BOSS_WAVE = 9; constexpr int VENTRICLE_RAZOR_PORTAL_COUNT = 2; constexpr int PORTAL_ROOM_NONE = -99999; @@ -60,7 +62,10 @@ enum OffMapRoom : int enum LevelStateFlag : int { LEVEL_STATE_BUM_KILLED = 0, + LEVEL_STATE_EVIL_BUM_KILLED = 1, LEVEL_STATE_REDHEART_DAMAGED = 2, + LEVEL_STATE_BUM_LEFT = 3, + LEVEL_STATE_EVIL_BUM_LEFT = 4, LEVEL_STATE_DAMAGED = 5, LEVEL_STATE_SHOPKEEPER_KILLED = 6, LEVEL_STATE_GREED_MONSTRO_SPAWNED = 12, @@ -341,3 +346,5 @@ public: void RestoreGameState(GameState& state); void store_game_state(GameState& state); }; + +float get_angel_room_chance(); diff --git a/src/lua_api.h b/src/lua_api.h index aea57de..0c0d369 100644 --- a/src/lua_api.h +++ b/src/lua_api.h @@ -37,6 +37,14 @@ struct Entity_Tear; struct Font; struct FontSettings; struct GridEntity; +struct GridEntityDesc; +struct GridEntity_Door; +struct GridEntity_Pit; +struct GridEntity_Poop; +struct GridEntity_PressurePlate; +struct GridEntity_Rock; +struct GridEntity_Spikes; +struct GridEntity_TNT; struct ItemConfig; struct ItemConfig_Card; struct ItemConfig_Costume; @@ -45,10 +53,14 @@ struct ItemConfig_Pill; struct KColor; struct ANM2; struct ProjectileParams; +struct QueueItemData; struct RoomConfig_Room; +struct RoomEntry; +struct RoomSpawn; struct RoomDescriptor; struct Seeds; struct TearParams; +struct TemporaryEffect; struct TemporaryEffects; class Game; class HUD; @@ -70,6 +82,17 @@ struct LuaIgnored { }; +// An argument a script may leave out, which reads as Default when it is nil or missing. +template struct LuaDefault +{ + T value = Default; +}; + +template +constexpr bool IS_LUA_DEFAULT = false; +template +constexpr bool IS_LUA_DEFAULT> = true; + // The rooms of a floor as Level:GetRooms hands them out: the room list and how many rooms it has. struct LuaRoomList { @@ -119,6 +142,22 @@ inline constexpr LuaClass LUA_CLASS_OF = LUA_CLASS_GAME; template <> inline constexpr LuaClass LUA_CLASS_OF = LUA_CLASS_GRID_ENTITY; template <> +inline constexpr LuaClass LUA_CLASS_OF = LUA_CLASS_GRID_ENTITY_DESC; +template <> +inline constexpr LuaClass LUA_CLASS_OF = LUA_CLASS_GRID_ENTITY_DOOR; +template <> +inline constexpr LuaClass LUA_CLASS_OF = LUA_CLASS_GRID_ENTITY_PIT; +template <> +inline constexpr LuaClass LUA_CLASS_OF = LUA_CLASS_GRID_ENTITY_POOP; +template <> +inline constexpr LuaClass LUA_CLASS_OF = LUA_CLASS_GRID_ENTITY_PRESSURE_PLATE; +template <> +inline constexpr LuaClass LUA_CLASS_OF = LUA_CLASS_GRID_ENTITY_ROCK; +template <> +inline constexpr LuaClass LUA_CLASS_OF = LUA_CLASS_GRID_ENTITY_SPIKES; +template <> +inline constexpr LuaClass LUA_CLASS_OF = LUA_CLASS_GRID_ENTITY_TNT; +template <> inline constexpr LuaClass LUA_CLASS_OF = LUA_CLASS_HUD; template <> inline constexpr LuaClass LUA_CLASS_OF = LUA_CLASS_ITEM_CONFIG; @@ -147,12 +186,22 @@ inline constexpr LuaClass LUA_CLASS_OF = LUA_CLASS_MUSIC_MANAGER; template <> inline constexpr LuaClass LUA_CLASS_OF = LUA_CLASS_PROJECTILE_PARAMS; template <> +inline constexpr LuaClass LUA_CLASS_OF = LUA_CLASS_QUEUE_ITEM_DATA; +template <> inline constexpr LuaClass LUA_CLASS_OF = LUA_CLASS_RNG; template <> inline constexpr LuaClass LUA_CLASS_OF = LUA_CLASS_ROOM; template <> +inline constexpr LuaClass LUA_CLASS_OF = LUA_CLASS_ROOM_CONFIG_ENTRY; +template <> +inline constexpr LuaClass LUA_CLASS_OF> = LUA_CLASS_ROOM_CONFIG_ENTRY_LIST; +template <> inline constexpr LuaClass LUA_CLASS_OF = LUA_CLASS_ROOM_CONFIG_ROOM; template <> +inline constexpr LuaClass LUA_CLASS_OF = LUA_CLASS_ROOM_CONFIG_SPAWN; +template <> +inline constexpr LuaClass LUA_CLASS_OF> = LUA_CLASS_ROOM_CONFIG_SPAWN_LIST; +template <> inline constexpr LuaClass LUA_CLASS_OF = LUA_CLASS_ROOM_DESCRIPTOR; template <> inline constexpr LuaClass LUA_CLASS_OF = LUA_CLASS_ROOM_LIST; @@ -165,6 +214,8 @@ inline constexpr LuaClass LUA_CLASS_OF = LUA_CLASS_SPRITE; template <> inline constexpr LuaClass LUA_CLASS_OF = LUA_CLASS_TEAR_PARAMS; template <> +inline constexpr LuaClass LUA_CLASS_OF = LUA_CLASS_TEMPORARY_EFFECT; +template <> inline constexpr LuaClass LUA_CLASS_OF = LUA_CLASS_TEMPORARY_EFFECTS; template <> inline constexpr LuaClass LUA_CLASS_OF = LUA_CLASS_VECTOR; @@ -196,6 +247,7 @@ void lua_api_entity_register(lua_State* state); void lua_api_entities_register(lua_State* state); void lua_api_entity_player_register(lua_State* state); void lua_api_game_register(lua_State* state); +void lua_api_grid_entity_register(lua_State* state); void lua_api_isaac_register(lua_State* state); void lua_api_item_config_register(lua_State* state); void lua_api_rng_register(lua_State* state); @@ -238,12 +290,14 @@ void lua_push(lua_State* state, const T& value) } // Reads argument index as a T: numbers are checked, booleans are truthiness, objects are checked against their class -// (nil only for a pointer), and a class value is copied unless T is a reference. +// (nil only for a pointer), a class value is copied unless T is a reference, and a LuaDefault may be left out. template T lua_get(lua_State* state, int index) { using V = std::remove_cvref_t; if constexpr (std::is_same_v) return {}; + else if constexpr (IS_LUA_DEFAULT) + return lua_isnoneornil(state, index) ? V{} : V{lua_get(state, index)}; else if constexpr (std::is_same_v) return lua_toboolean(state, index); else if constexpr (std::is_integral_v || std::is_enum_v) return (V)luaL_checkinteger(state, index); else if constexpr (std::is_floating_point_v) return (V)luaL_checknumber(state, index); diff --git a/src/lua_api_entities.cpp b/src/lua_api_entities.cpp index 071706a..0e404c7 100644 --- a/src/lua_api_entities.cpp +++ b/src/lua_api_entities.cpp @@ -239,6 +239,20 @@ static void npc_pickup_register(lua_State* state) }); lua_method(state, "MakeSplat", [](Entity_NPC& npc, float size) { return npc.MakeSplat(size); }); lua_method(state, "KillUnique", [](Entity_NPC& npc) { npc.KillUnique(); }); + lua_method(state, "ResetPathFinderTarget", [](Entity_NPC& npc) { npc.ResetPathFinderTarget(); }); + lua_method(state, "GetAliveEnemyCount", [](Entity_NPC& npc) { return npc.GetAliveEnemyCount(); }); + lua_method(state, "FireProjectiles", [](Entity_NPC& npc, Vector position, Vector velocity, ProjectilesMode mode, + const ProjectileParams& params) { + npc.FireProjectiles(position, velocity, mode, params); + }); + lua_method(state, "FireBossProjectiles", [](Entity_NPC& npc, int count, Vector target, float trajectory, + const ProjectileParams& params) { + return npc.FireBossProjectiles(count, target, trajectory, params); + }); + lua_method(state, "ThrowSpider", [](Entity_NPC&, Vector position, Entity* spawner, Vector target, bool isBig, + float yOffset) { + return Entity_NPC::ThrowSpider(position, spawner, target, isBig, yOffset); + }); lua_class_end(state); lua_class_begin(state, "EntityPickup", LUA_CLASS_PICKUP, LUA_CLASS_ENTITY); @@ -267,8 +281,40 @@ static void npc_pickup_register(lua_State* state) lua_class_end(state); } +// Registers Lua's ProjectileParams, how FireProjectiles shoots, which scripts construct. +static void projectile_params_register(lua_State* state) +{ + lua_class_begin(state, "ProjectileParams", LUA_CLASS_PROJECTILE_PARAMS); + lua_static(state, "__call", [](LuaIgnored) { return ProjectileParams(); }); + lua_field<&ProjectileParams::isGridCollision>(state, "GridCollision"); + lua_field<&ProjectileParams::heightModifier>(state, "HeightModifier"); + lua_field<&ProjectileParams::fallingSpeedModifier>(state, "FallingSpeedModifier"); + lua_field<&ProjectileParams::fallingAccelModifier>(state, "FallingAccelModifier"); + lua_field<&ProjectileParams::velocityMulti>(state, "VelocityMulti"); + lua_field<&ProjectileParams::scale>(state, "Scale"); + lua_field<&ProjectileParams::circleAngle>(state, "CircleAngle"); + lua_field<&ProjectileParams::homingStrength>(state, "HomingStrength"); + lua_field<&ProjectileParams::curvingStrength>(state, "CurvingStrength"); + lua_field<&ProjectileParams::acceleration>(state, "Acceleration"); + lua_field<&ProjectileParams::spread>(state, "Spread"); + lua_field<&ProjectileParams::color>(state, "Color"); + lua_field<&ProjectileParams::bulletFlags>(state, "BulletFlags"); + lua_field<&ProjectileParams::positionOffset>(state, "PositionOffset"); + lua_field<&ProjectileParams::targetPosition>(state, "TargetPosition"); + lua_field<&ProjectileParams::fireDirectionLimit>(state, "FireDirectionLimit"); + lua_field<&ProjectileParams::dotProductLimit>(state, "DotProductLimit"); + lua_field<&ProjectileParams::wiggleFrameOffset>(state, "WiggleFrameOffset"); + lua_field<&ProjectileParams::changeFlags>(state, "ChangeFlags"); + lua_field<&ProjectileParams::changeVelocity>(state, "ChangeVelocity"); + lua_field<&ProjectileParams::changeTimeout>(state, "ChangeTimeout"); + lua_field<&ProjectileParams::depthOffset>(state, "DepthOffset"); + lua_field<&ProjectileParams::variant>(state, "Variant"); + lua_class_end(state); +} + void lua_api_entities_register(lua_State* state) { + projectile_params_register(state); shots_register(state); weapons_register(state); companions_register(state); diff --git a/src/lua_api_entity_player.cpp b/src/lua_api_entity_player.cpp index 887b414..935c47d 100644 --- a/src/lua_api_entity_player.cpp +++ b/src/lua_api_entity_player.cpp @@ -9,6 +9,9 @@ #include "temporary_effects.h" #include "weapon.h" +// The QueueItemData flag Touched reads: the item was held before, so picking it up again gives no pickup effect. +constexpr uint32_t QUEUE_ITEM_TOUCHED = 0x1; + // The weapon a player's fire delay belongs to: the override in slot 0, else the first. static Weapon* player_weapon_main(Entity_Player& player) { @@ -67,6 +70,12 @@ static void player_health_register(lua_State* state) lua_method(state, "SetBloodCharge", [](Entity_Player& player, int amount) { player.SetBloodCharge(amount); }); lua_method(state, "GetEffectiveBloodCharge", [](Entity_Player& player) { return player.GetEffectiveBloodCharge(); }); + lua_method(state, "GetSoulCharge", [](Entity_Player& player) { return player.effectiveSoulCharge; }); + lua_method(state, "GetBloodCharge", [](Entity_Player& player) { return player.effectiveBloodCharge; }); + lua_method(state, "GetPoopMana", [](Entity_Player& player) { return player.poopMana; }); + lua_method(state, "GetMaxPoopMana", [](Entity_Player&) { return Entity_Player::GetMaxPoopMana(); }); + lua_method(state, "AddPoopMana", [](Entity_Player& player, int amount) { player.AddPoopMana(amount); }); + lua_method(state, "GetPoopSpell", [](Entity_Player& player, int position) { return player.GetPoopSpell(position); }); lua_method(state, "HasInvincibility", [](Entity_Player& player, uint64_t flags, const EntityRef& source) { return player.HasInvincibility(flags, source); }); @@ -201,6 +210,18 @@ static void player_items_register(lua_State* state) // Registers the player's animations, controls and the rest of the EntityPlayer methods. static void player_misc_register(lua_State* state) { + lua_field<&Entity_Player::queuedItem>(state, "QueuedItem"); + lua_method(state, "GetBabySkin", [](Entity_Player& player) { return player.babySkin; }); + lua_method(state, "GetModelingClayEffect", [](Entity_Player& player) { return player.modelingClayEffect; }); + lua_method(state, "ClearDeadEyeCharge", [](Entity_Player& player) { player.ClearDeadEyeCharge(); }); + lua_method(state, "SetShootingCooldown", [](Entity_Player& player, int cooldown) { player.SetShootingCooldown(cooldown); }); + lua_method(state, "GetMovementInput", [](Entity_Player& player) { return player.GetMovementJoystick(); }); + lua_method(state, "GetShootingInput", [](Entity_Player& player) { return player.GetShootingJoystick(); }); + lua_method(state, "CheckFamiliar", + [](Entity_Player& player, int variant, int count, RNG& rng, ItemConfig_Item* item, int subtype) { + familiar_check(player, {.item = item, .rng = &rng, .count = count, .subtype = subtype, + .variant = variant}); + }); lua_method(state, "GetName", [](Entity_Player& player) -> const std::string& { return player.name; }); lua_method(state, "GetPlayerType", [](Entity_Player& player) { return player.playerType; }); lua_method(state, "ChangePlayerType", @@ -359,7 +380,24 @@ void lua_api_entity_player_register(lua_State* state) player_stats_register(state); lua_class_end(state); + lua_class_begin(state, "QueueItemData", LUA_CLASS_QUEUE_ITEM_DATA); + lua_field<&QueueItemData::item>(state, "Item"); + lua_field<&QueueItemData::charge>(state, "Charge"); + lua_property(state, "Touched", [](QueueItemData& queued) { return (queued.flags & QUEUE_ITEM_TOUCHED) != 0; }); + lua_class_end(state); + + lua_class_begin(state, "TemporaryEffect", LUA_CLASS_TEMPORARY_EFFECT); + lua_field<&TemporaryEffect::item>(state, "Item"); + lua_field<&TemporaryEffect::count>(state, "Count"); + lua_field<&TemporaryEffect::cooldown>(state, "Cooldown"); + lua_class_end(state); + lua_class_begin(state, "TemporaryEffects", LUA_CLASS_TEMPORARY_EFFECTS); + lua_method(state, "GetCollectibleEffect", + [](TemporaryEffects& effects, int id) { return effects.GetCollectibleEffect(id); }); + lua_method(state, "GetTrinketEffect", + [](TemporaryEffects& effects, int id) { return effects.GetTrinketEffect(id); }); + lua_method(state, "GetNullEffect", [](TemporaryEffects& effects, int id) { return effects.GetNullEffect(id); }); lua_method(state, "AddCollectibleEffect", [](TemporaryEffects& effects, int id, bool isAddCostume, int count) { effects.AddCollectibleEffect(id, isAddCostume, count); }); diff --git a/src/lua_api_game.cpp b/src/lua_api_game.cpp index 5dc8649..0cdb64e 100644 --- a/src/lua_api_game.cpp +++ b/src/lua_api_game.cpp @@ -1,4 +1,5 @@ #include "classes.h" +#include "boss_ai.h" #include "entity_npc.h" #include "entity_player.h" #include "game.h" @@ -7,11 +8,17 @@ #include "lua_api.h" #include "manager.h" #include "music_manager.h" +#include "npc_basement.h" +#include "room_transition.h" #include "seeds.h" #include "sfx_manager.h" +#include -// Registers Lua's Game: the run's level, room, players, pools, seeds and HUD, spawning, and its state flags and -// counters. Game is also the Level it derives from. +// The reach of a Fart a script leaves out. +constexpr float FART_RADIUS = 85; + +// (00703510, 00703570) Registers Lua's Game: the run's level, room, players, pools, seeds and HUD, spawning, room +// transitions and farts, and its state flags and counters. Game is also the Level it derives from. static void game_register(lua_State* state) { lua_class_begin(state, "Game", LUA_CLASS_GAME); @@ -35,6 +42,29 @@ static void game_register(lua_State* state) int subType, uint32_t seed) { return game.Spawn({position, velocity, spawner, subType, type, variant, seed}); }); + lua_method(state, "StartRoomTransition", + [](Game& game, int roomIndex, Direction direction, LuaDefault animation, + Entity_Player* player, LuaDefault dimension) { + game.StartRoomTransition({.player = player, .animation = (RoomTransitionAnim)animation.value, + .direction = direction, .dimension = dimension.value, + .roomIndex = roomIndex}); + }); + lua_method(state, "HasEncounteredBoss", [](Game& game, int type, int variant) { + return std::ranges::any_of(game.encounteredBosses, + [&](BossId& boss) { return boss.type == type && boss.variant == variant; }); + }); + lua_method(state, "GetGreedBossWaveNum", + [](Game& game) { return GREED_BOSS_WAVE + (game.difficulty == DIFFICULTY_GREEDIER); }); + lua_method(state, "Fart", [](Game&, Vector position, LuaDefault radius, Entity* source, + LuaDefault scale, LuaDefault subType, ColorMod* color) { + game_fart({.position = position, .source = source, .color = color ? *color : COLOR_DEFAULT, + .radius = radius.value, .scale = scale.value, .subType = subType.value}); + }); + lua_method(state, "ButterBeanFart", [](Game&, Vector position, float radius, Entity* source, + LuaDefault isShowEffect, bool isSuperKnockback) { + game_butter_bean_fart({.position = position, .source = source, .radius = radius, + .isShowEffect = isShowEffect.value, .isSuperKnockback = isSuperKnockback}); + }); lua_method(state, "GetVictoryLap", [](Game& game) { return game.victoryLap; }); lua_method(state, "GetDevilRoomDeals", [](Game& game) { return game.devilRoomDeals; }); lua_method(state, "GetLastDevilRoomStage", [](Game& game) { return game.lastDevilRoomStage; }); @@ -67,6 +97,10 @@ static void game_parts_register(lua_State* state) lua_method(state, "ShowItemText", [](HUD& hud, Entity_Player* player, ItemConfig_Item* item) { hud.ShowItemText(player, item); }); + lua_method(state, "AssignPlayerHUDs", [](HUD& hud) { hud.AssignPlayerHUDs(); }); + lua_method(state, "Update", [](HUD& hud) { hud.Update(); }); + lua_method(state, "PostUpdate", [](HUD& hud) { hud.PostUpdate(); }); + lua_method(state, "Render", [](HUD& hud) { hud.Render(); }); lua_class_end(state); lua_class_begin(state, "ItemPool", LUA_CLASS_ITEM_POOL); @@ -110,6 +144,19 @@ static void game_parts_register(lua_State* state) lua_method(state, "AddSeedEffect", [](Seeds& seeds, int effect) { seeds.AddSeedEffect(effect); }); lua_method(state, "RemoveSeedEffect", [](Seeds& seeds, int effect) { seeds.RemoveSeedEffect(effect); }); lua_method(state, "CanAddSeedEffect", [](Seeds& seeds, uint32_t effect) { return seeds.CanAddSeedEffect(effect); }); + lua_method(state, "SetStartSeed", [](Seeds& seeds, std::string_view seed) { seeds.SetStartSeed(seed); }); + lua_method(state, "ClearStartSeed", [](Seeds& seeds) { seeds.ClearStartSeed(); }); + lua_method(state, "Reset", [](Seeds& seeds) { seeds.Reset(); }); + lua_method(state, "Restart", [](Seeds& seeds, int challenge) { seeds.Restart(challenge); }); + lua_method(state, "ForgetStageSeed", [](Seeds& seeds, int stage) { seeds.ForgetStageSeed(stage); }); + lua_method(state, "RemoveBlockingSeedEffects", [](Seeds& seeds, int effect) { seeds.RemoveBlockingSeedEffects(effect); }); + lua_method(state, "ClearSeedEffects", [](Seeds& seeds) { seeds.ClearSeedEffects(); }); + lua_method(state, "CountSeedEffects", [](Seeds& seeds) { return seeds.CountSeedEffects(); }); + lua_static(state, "GetSeedEffect", [](std::string_view seed) { return Seeds::GetSeedEffect(seed); }); + lua_static(state, "IsSpecialSeed", [](std::string_view seed) { return Seeds::IsSpecialSeed(seed); }); + lua_static(state, "IsSeedComboBanned", [](int effectA, int effectB) { return Seeds::IsSeedComboBanned(effectA, effectB); }); + lua_static(state, "InitSeedInfo", []() { Seeds::InitSeedInfo(); }); + lua_static(state, "CountUnlockedSeedEffects", []() { return Seeds::CountUnlockedSeedEffects(); }); lua_static(state, "Seed2String", [](uint32_t seed) { return Seeds::Seed2String(seed); }); lua_static(state, "String2Seed", [](std::string_view seed) { return Seeds::String2Seed(seed); }); lua_static(state, "IsStringValidSeed", [](std::string_view seed) { return Seeds::IsStringValidSeed(seed); }); diff --git a/src/lua_api_grid_entity.cpp b/src/lua_api_grid_entity.cpp new file mode 100644 index 0000000..d0fab51 --- /dev/null +++ b/src/lua_api_grid_entity.cpp @@ -0,0 +1,168 @@ +#include "classes.h" +#include "grid_entity.h" +#include "grid_entity_door.h" +#include "grid_entity_pit.h" +#include "grid_entity_poop.h" +#include "grid_entity_pressure_plate.h" +#include "grid_entity_rock.h" +#include "grid_entity_spikes.h" +#include "grid_entity_tnt.h" +#include "lua_api.h" + +// Adds a To method casting a grid entity to a subclass, nil when it is not one. +template +static void grid_cast_add(lua_State* state, const char* name) +{ + lua_method(state, name, [](GridEntity* grid) { return dynamic_cast(grid); }); +} + +// Registers Lua's GridEntityDesc, a cell's saved state. GridEntity.Desc hands out a copy of the entity's. +static void grid_entity_desc_register(lua_State* state) +{ + lua_class_begin(state, "GridEntityDesc", LUA_CLASS_GRID_ENTITY_DESC); + lua_field<&GridEntityDesc::_type>(state, "Type"); + lua_field<&GridEntityDesc::_variant>(state, "Variant"); + lua_field<&GridEntityDesc::_state>(state, "State"); + lua_field<&GridEntityDesc::_spawnCount>(state, "SpawnCount"); + lua_field<&GridEntityDesc::_spawnSeed>(state, "SpawnSeed"); + lua_field<&GridEntityDesc::_varData>(state, "VarData"); + lua_field<&GridEntityDesc::_initialized>(state, "Initialized"); + lua_field<&GridEntityDesc::_variableSeed>(state, "VariableSeed"); + lua_class_end(state); +} + +// Registers Lua's GridEntity, the base of rocks, pits, doors and the other tiles of a room. +static void grid_entity_base_register(lua_State* state) +{ + lua_class_begin(state, "GridEntity", LUA_CLASS_GRID_ENTITY); + lua_method(state, "GetType", [](GridEntity& grid) { return grid.type; }); + lua_method(state, "GetVariant", [](GridEntity& grid) { return grid.variant; }); + lua_method(state, "SetType", [](GridEntity& grid, GridEntityType type) { grid.type = type; }); + lua_method(state, "SetVariant", [](GridEntity& grid, int variant) { grid.variant = variant; }); + lua_method(state, "GetGridIndex", [](GridEntity& grid) { return grid.gridIndex; }); + lua_method(state, "GetSprite", [](GridEntity& grid) -> ANM2& { return grid.sprite; }); + lua_method(state, "GetRNG", [](GridEntity& grid) -> RNG& { return grid.rng; }); + lua_method(state, "GetSaveState", [](GridEntity& grid) { return grid.desc_save(); }); + lua_method(state, "Init", [](GridEntity& grid, uint32_t seed) { grid.Init(seed); }); + lua_method(state, "Update", [](GridEntity& grid) { grid.Update(); }); + lua_method(state, "Render", [](GridEntity& grid, Vector offset) { grid.Render(offset); }); + lua_method(state, "PostInit", [](GridEntity& grid) { grid.PostInit(); }); + lua_method(state, "Hurt", [](GridEntity& grid, int damage) { return grid.Hurt(damage, EntityRef()); }); + lua_method(state, "HurtWithSource", + [](GridEntity& grid, int damage, const EntityRef& source) { return grid.Hurt(damage, source); }); + lua_method(state, "Destroy", + [](GridEntity& grid, bool isImmediate) { return grid.Destroy(isImmediate, EntityRef()); }); + lua_method(state, "DestroyWithSource", [](GridEntity& grid, bool isImmediate, const EntityRef& source) { + return grid.Destroy(isImmediate, source); + }); + lua_property(state, "Position", [](GridEntity& grid) { return grid.Position(); }); + lua_property(state, "Desc", [](GridEntity& grid) { return grid.desc_save(); }); + lua_field<&GridEntity::state>(state, "State"); + lua_field<&GridEntity::varData>(state, "VarData"); + lua_field<&GridEntity::collisionClass>(state, "CollisionClass"); + grid_cast_add(state, "ToDoor"); + grid_cast_add(state, "ToPit"); + grid_cast_add(state, "ToPoop"); + grid_cast_add(state, "ToPressurePlate"); + grid_cast_add(state, "ToRock"); + grid_cast_add(state, "ToSpikes"); + grid_cast_add(state, "ToTNT"); + lua_class_end(state); +} + +// Registers Lua's GridEntityDoor: the rooms it joins, its locks and its animations. +static void grid_entity_door_register(lua_State* state) +{ + lua_class_begin(state, "GridEntityDoor", LUA_CLASS_GRID_ENTITY_DOOR, LUA_CLASS_GRID_ENTITY); + lua_method(state, "SetRoomTypes", + [](GridEntity_Door& door, int current, int target) { door.SetRoomTypes(current, target); }); + lua_method(state, "Open", [](GridEntity_Door& door) { door.Open(); }); + lua_method(state, "Close", [](GridEntity_Door& door, bool isForce) { door.Close(isForce); }); + lua_method(state, "Bar", [](GridEntity_Door& door) { door.Bar(); }); + lua_method(state, "SpawnDust", [](GridEntity_Door& door) { door.SpawnDust(); }); + lua_method(state, "CanBlowOpen", [](GridEntity_Door& door) { return door.CanBlowOpen(); }); + lua_method(state, "TryBlowOpen", [](GridEntity_Door& door, bool isFromExplosion, Entity* source) { + return door.TryBlowOpen(isFromExplosion, source); + }); + lua_method(state, "TryUnlock", [](GridEntity_Door& door, Entity_Player& player, bool isForce) { + return door.TryUnlock(player, isForce); + }); + lua_method(state, "IsOpen", [](GridEntity_Door& door) { return door.IsOpen(); }); + lua_method(state, "IsKeyFamiliarTarget", [](GridEntity_Door& door) { return door.IsKeyFamiliarTarget(); }); + lua_method(state, "SetLocked", [](GridEntity_Door& door, bool isLocked) { door.SetLocked(isLocked); }); + lua_method(state, "IsLocked", [](GridEntity_Door& door) { return door.IsLocked(); }); + lua_method(state, "IsBusted", [](GridEntity_Door& door) { return door.isBusted; }); + lua_method(state, "IsRoomType", [](GridEntity_Door& door, int roomType) { return door.IsRoomType(roomType); }); + lua_method(state, "IsTargetRoomArcade", [](GridEntity_Door& door) { return door.IsTargetRoomArcade(); }); + lua_method(state, "GetSpriteOffset", [](GridEntity_Door& door) -> Vector& { return door.sprite.offset; }); + lua_field<&GridEntity_Door::slot>(state, "Slot"); + lua_field<&GridEntity_Door::direction>(state, "Direction"); + lua_field<&GridEntity_Door::currentRoomType>(state, "CurrentRoomType"); + lua_field<&GridEntity_Door::targetRoomType>(state, "TargetRoomType"); + lua_field<&GridEntity_Door::targetRoomIdx>(state, "TargetRoomIndex"); + lua_field<&GridEntity_Door::previousState>(state, "PreviousState"); + lua_field<&GridEntity_Door::previousVariant>(state, "PreviousVariant"); + lua_field<&GridEntity_Door::isBusted>(state, "Busted"); + lua_field<&GridEntity_Door::isExtraVisible>(state, "ExtraVisible"); + lua_property(state, "ExtraSprite", [](GridEntity_Door& door) -> ANM2& { return door.extraSprite; }); + lua_field<&GridEntity_Door::openAnimation>(state, "OpenAnimation"); + lua_field<&GridEntity_Door::closeAnimation>(state, "CloseAnimation"); + lua_field<&GridEntity_Door::lockedAnimation>(state, "LockedAnimation"); + lua_field<&GridEntity_Door::openLockedAnimation>(state, "OpenLockedAnimation"); + lua_class_end(state); +} + +// Registers Lua's GridEntityPit, GridEntityPoop, GridEntityPressurePlate, GridEntityRock, GridEntitySpikes and +// GridEntityTNT. +static void grid_entity_kinds_register(lua_State* state) +{ + lua_class_begin(state, "GridEntityPit", LUA_CLASS_GRID_ENTITY_PIT, LUA_CLASS_GRID_ENTITY); + lua_method(state, "MakeBridge", [](GridEntity_Pit& pit, GridEntity* building) { + pit.MakeBridge(dynamic_cast(building), 0); + }); + lua_method(state, "SetLadder", [](GridEntity_Pit& pit, bool isLadder) { pit.SetLadder(isLadder); }); + lua_method(state, "UpdateCollision", [](GridEntity_Pit& pit) { pit.UpdateCollision(); }); + lua_field<&GridEntity_Pit::hasLadder>(state, "HasLadder"); + lua_class_end(state); + + lua_class_begin(state, "GridEntityPoop", LUA_CLASS_GRID_ENTITY_POOP, LUA_CLASS_GRID_ENTITY); + lua_method(state, "RespawnRedPoop", [](GridEntity_Poop& poop) { poop.RespawnRedPoop(); }); + lua_field<&GridEntity_Poop::reviveTimer>(state, "ReviveTimer"); + lua_field<&GridEntity_Poop::stateAnimation>(state, "StateAnimation"); + lua_field<&GridEntity_Poop::isUnderPlayer>(state, "UnderPlayer"); + lua_class_end(state); + + lua_class_begin(state, "GridEntityPressurePlate", LUA_CLASS_GRID_ENTITY_PRESSURE_PLATE, LUA_CLASS_GRID_ENTITY); + lua_method(state, "Reward", [](GridEntity_PressurePlate& plate) { plate.Reward(); }); + lua_property(state, "TimerPlate", [](GridEntity_PressurePlate& plate) -> ANM2& { return plate.timerPlate; }); + lua_field_get<&GridEntity_PressurePlate::nextGreedAnimation>(state, "NextGreedAnimation"); + lua_property(state, "GreedModeRNG", [](GridEntity_PressurePlate& plate) -> RNG& { return plate.greedModeRNG; }); + lua_class_end(state); + + lua_class_begin(state, "GridEntityRock", LUA_CLASS_GRID_ENTITY_ROCK, LUA_CLASS_GRID_ENTITY); + lua_method(state, "GetRubbleAnim", [](GridEntity_Rock& rock) { return rock.rubbleAnim; }); + lua_method(state, "SetBigRockFrame", [](GridEntity_Rock& rock, int frame) { rock.SetBigRockFrame(frame); }); + lua_method(state, "GetBigRockFrame", [](GridEntity_Rock& rock) { return rock.GetBigRockFrame(); }); + lua_method(state, "UpdateAnimFrame", [](GridEntity_Rock& rock) { rock.UpdateAnimFrame(); }); + lua_field<&GridEntity_Rock::anim>(state, "Anim"); + lua_field<&GridEntity_Rock::rubbleAnim>(state, "RubbleAnim"); + lua_field<&GridEntity_Rock::fuseFrames>(state, "FrameCnt"); + lua_class_end(state); + + lua_class_begin(state, "GridEntitySpikes", LUA_CLASS_GRID_ENTITY_SPIKES, LUA_CLASS_GRID_ENTITY); + lua_field<&GridEntity_Spikes::timeout>(state, "Timeout"); + lua_class_end(state); + + lua_class_begin(state, "GridEntityTNT", LUA_CLASS_GRID_ENTITY_TNT, LUA_CLASS_GRID_ENTITY); + lua_field<&GridEntity_TNT::fuseFrames>(state, "FrameCnt"); + lua_class_end(state); +} + +// Registers the grid entity classes, the base before the kinds that name it as their parent. +void lua_api_grid_entity_register(lua_State* state) +{ + grid_entity_desc_register(state); + grid_entity_base_register(state); + grid_entity_door_register(state); + grid_entity_kinds_register(state); +} diff --git a/src/lua_api_isaac.cpp b/src/lua_api_isaac.cpp index 65d26ac..e358bc1 100644 --- a/src/lua_api_isaac.cpp +++ b/src/lua_api_isaac.cpp @@ -17,6 +17,9 @@ #include "platform.h" #include "room.h" #include "room_grid.h" +#include +#include +#include #include #include #include @@ -34,6 +37,11 @@ constexpr float GRID_ROUNDING = 0.5f; constexpr float SCREEN_DISTANCE_SCALE = 0.65f; constexpr int GRID_INDEX_LIMIT = 448; constexpr int LUA_TYPE_NONE = 0; +constexpr float OPTION_GAMMA_MAX = 1.5f; +constexpr float OPTION_GAMMA_MIN = 0.5f; +constexpr float OPTION_RATIO_MAX = 0.01f; +constexpr int MOUSE_BUTTON_LAST = 7; +constexpr int OPTION_SCALE_MAX = 99; constexpr int SAVE_SLOT_DEFAULT = 1; constexpr uint32_t PARTITIONS_ALL = 0xffffffff; @@ -276,13 +284,15 @@ static int mod_data_remove(lua_State* state) } // 0085f0f0 The file a module name is in: dots become folders and .lua is added, searched in resources/scripts/, the -// running script's folder, and that folder under the mods folder. Empty when none exists, with tried listing them. +// running script's folder, and that folder under the mods folder. The name is lowercased, as the import tool lowercases +// every path a mod ships. Empty when none exists, with tried listing them. static std::string module_path_find(std::string_view name, std::string& tried) { std::string module(name); bool isLuaFile = module.ends_with(LUA_EXTENSION); if (isLuaFile) module.resize(module.size() - std::strlen(LUA_EXTENSION)); std::ranges::replace(module, '.', '/'); + std::ranges::transform(module, module.begin(), [](unsigned char c) { return (char)std::tolower(c); }); module += LUA_EXTENSION; std::string scriptPath = lua_engine_get().scriptPath; @@ -376,6 +386,32 @@ static int pointer_hash_get(lua_State* state) return 1; } +// 00870160 The world position under a point of the screen, given in the window's pixels: the inverse of WorldToScreen +// without the screen shake, as the point scale and the room's scroll undo. +static Vector screen_to_world(Vector screen) +{ + Vector origin = render_position_get(vector_make(0, 0), RENDER_UNSNAPPED); + Vector scroll = g_game->room->renderScrollOffset; + + return vector_make((screen.x / g_screenPointScale - scroll.x - origin.x) / SCREEN_DISTANCE_SCALE, + (screen.y / g_screenPointScale - scroll.y - origin.y) / SCREEN_DISTANCE_SCALE); +} + +// 0086fe50 Where the mouse is in the window, or in the world when asked for game coordinates. +static Vector mouse_position_get(bool isGameCoords) +{ + Vector position = {}; + + SDL_GetMouseState(&position.x, &position.y); + return isGameCoords ? screen_to_world(position) : position; +} + +// 0086fdb0 Whether a mouse button (0 left, 1 right, 2 middle, up to 7) is held. +static bool is_mouse_button_pressed(int button) +{ + return button >= 0 && button <= MOUSE_BUTTON_LAST && SDL_GetMouseState(nullptr, nullptr) & SDL_BUTTON_MASK(button + 1); +} + // Text drawn with the console font, as RenderText and RenderScaledText draw it. static void text_render(std::string_view text, Vector position, Vector scale, KColor color) { @@ -472,6 +508,7 @@ static void isaac_register(lua_State* state) Vector screen = vector_add(render_position_get(position, RENDER_SNAPPED), g_game->room->renderScrollOffset); return vector_add(screen, g_game->screenShakeOffset); }); + lua_method(state, "ScreenToWorld", [](Vector position) { return g_game ? screen_to_world(position) : position; }); lua_method(state, "WorldToRenderPosition", [](Vector position) { return render_position_get(position, RENDER_SNAPPED); }); lua_method(state, "WorldToScreenDistance", @@ -548,7 +585,7 @@ static void isaac_register(lua_State* state) } // (0086fc70, 0086fca0, 0086fcd0, 0086fd10, 0086fd40, 0086fd70) Registers the Input namespace: buttons and actions -// on one controller. Action values are 1 or 0, as the analog values are not read yet. +// on one controller, and the mouse. Action values are 1 or 0, as the analog values are not read yet. static void input_register(lua_State* state) { lua_namespace_begin(state, "Input"); @@ -573,45 +610,87 @@ static void input_register(lua_State* state) lua_method(state, "GetActionValue", [](ButtonAction action, int controller) { return is_controller_action(controller, action, ACTION_PRESSED) ? 1.0f : 0.0f; }); + lua_method(state, "GetMousePosition", mouse_position_get); + lua_method(state, "IsMouseBtnPressed", is_mouse_button_pressed); lua_class_end(state); } -// Registers the Options namespace, read-only for now: the original's setters clamp and apply each option. +// Adds an option the Options namespace reads and writes as it is. +template +static void option_add(lua_State* state, const char* name) +{ + using T = decltype(lua_member_type(Member)); + lua_property( + state, name, [](LuaIgnored) { return g_manager->optionsConfig.*Member; }, + [](LuaIgnored, T value) { g_manager->optionsConfig.*Member = value; }); +} + +// Adds an option the Options namespace keeps between low and high when written. +template +static void option_clamped_add(lua_State* state, const char* name) +{ + using T = decltype(lua_member_type(Member)); + lua_property( + state, name, [](LuaIgnored) { return g_manager->optionsConfig.*Member; }, + [](LuaIgnored, T value) { g_manager->optionsConfig.*Member = std::clamp(value, (T)Low, (T)High); }); +} + +// (00896810 to 008973e0) Registers the Options namespace. Setters keep each option in its range and apply the volumes, +// the fullscreen, vsync and the cursor. The volumes, the map opacity and the HUD offset stop at 0.01, as the +// original's do. static void options_register(lua_State* state) { lua_namespace_begin(state, "Options"); - lua_property(state, "MusicVolume", [](LuaIgnored) { return g_manager->optionsConfig.musicVolume; }); - lua_property(state, "SFXVolume", [](LuaIgnored) { return g_manager->optionsConfig.sfxVolume; }); - lua_property(state, "MapOpacity", [](LuaIgnored) { return g_manager->optionsConfig.mapOpacity; }); - lua_property(state, "Fullscreen", [](LuaIgnored) { return g_manager->optionsConfig.isFullscreen; }); - lua_property(state, "Filter", [](LuaIgnored) { return g_manager->optionsConfig.isFilterEnabled; }); - lua_property(state, "Gamma", [](LuaIgnored) { return g_manager->optionsConfig.gamma; }); - lua_property(state, "DisplayPopups", [](LuaIgnored) { return g_manager->optionsConfig.popupsMode; }); - lua_property(state, "CameraStyle", [](LuaIgnored) { return g_manager->optionsConfig.cameraStyle; }); - lua_property(state, "ExtraHUDStyle", [](LuaIgnored) { return g_manager->optionsConfig.historyHudMode; }); - lua_property(state, "HUDOffset", [](LuaIgnored) { return g_manager->optionsConfig.hudOffset; }); - lua_property(state, "FoundHUD", [](LuaIgnored) { return g_manager->optionsConfig.isFoundHudEnabled; }); - lua_property(state, "RumbleEnabled", [](LuaIgnored) { return g_manager->optionsConfig.isRumbleEnabled; }); - lua_property(state, "ChargeBars", [](LuaIgnored) { return g_manager->optionsConfig.isChargeBarsEnabled; }); - lua_property(state, "BulletVisibility", - [](LuaIgnored) { return g_manager->optionsConfig.isBulletVisibilityEnabled; }); - lua_property(state, "VSync", [](LuaIgnored) { return g_manager->optionsConfig.isVsyncEnabled; }); - lua_property(state, "PauseOnFocusLost", - [](LuaIgnored) { return g_manager->optionsConfig.isPauseOnFocusLostEnabled; }); - lua_property(state, "MouseControl", [](LuaIgnored) { return g_manager->optionsConfig.isMouseControlEnabled; }); - lua_property(state, "AnnouncerVoiceMode", [](LuaIgnored) { return g_manager->optionsConfig.announcerVoiceMode; }); - lua_property(state, "MaxScale", [](LuaIgnored) { return g_manager->optionsConfig.maxScale; }); - lua_property(state, "MaxRenderScale", [](LuaIgnored) { return g_manager->optionsConfig.maxRenderScale; }); - lua_property(state, "ConsoleFont", [](LuaIgnored) { return g_manager->optionsConfig.consoleFont; }); - lua_property(state, "FadedConsoleDisplay", - [](LuaIgnored) { return g_manager->optionsConfig.isFadedConsoleDisplayEnabled; }); - lua_property(state, "SaveCommandHistory", - [](LuaIgnored) { return g_manager->optionsConfig.isSaveCommandHistoryEnabled; }); - lua_property(state, "UseBorderlessFullscreen", - [](LuaIgnored) { return !g_manager->optionsConfig.isExclusiveFullscreen; }); - lua_property(state, "DebugConsoleEnabled", - [](LuaIgnored) { return g_manager->optionsConfig.isDebugConsoleEnabled; }); - lua_property(state, "JacobEsauControls", [](LuaIgnored) { return g_manager->optionsConfig.jacobEsauControls; }); + lua_property( + state, "MusicVolume", [](LuaIgnored) { return g_manager->optionsConfig.musicVolume; }, + [](LuaIgnored, float volume) { g_manager->optionsConfig.SetMusicVolume(std::clamp(volume, 0.0f, OPTION_RATIO_MAX)); }); + lua_property( + state, "SFXVolume", [](LuaIgnored) { return g_manager->optionsConfig.sfxVolume; }, + [](LuaIgnored, float volume) { + g_manager->optionsConfig.sfxVolume = std::clamp(volume, 0.0f, OPTION_RATIO_MAX); + g_manager->sfxManager.ClearVolumeModifier(); + }); + lua_property( + state, "MapOpacity", [](LuaIgnored) { return g_manager->optionsConfig.mapOpacity; }, + [](LuaIgnored, float opacity) { g_manager->optionsConfig.mapOpacity = std::clamp(opacity, 0.0f, OPTION_RATIO_MAX); }); + lua_property( + state, "HUDOffset", [](LuaIgnored) { return g_manager->optionsConfig.hudOffset; }, + [](LuaIgnored, float offset) { g_manager->optionsConfig.hudOffset = std::clamp(offset, 0.0f, OPTION_RATIO_MAX); }); + lua_property( + state, "Gamma", [](LuaIgnored) { return g_manager->optionsConfig.gamma; }, + [](LuaIgnored, float gamma) { g_manager->optionsConfig.gamma = std::clamp(gamma, OPTION_GAMMA_MIN, OPTION_GAMMA_MAX); }); + lua_property( + state, "Fullscreen", [](LuaIgnored) { return g_manager->optionsConfig.isFullscreen; }, + [](LuaIgnored, bool isEnabled) { g_manager->optionsConfig.SetFullScreen(isEnabled); }); + lua_property( + state, "VSync", [](LuaIgnored) { return g_manager->optionsConfig.isVsyncEnabled; }, + [](LuaIgnored, bool isEnabled) { g_manager->optionsConfig.vsync_set(isEnabled); }); + lua_property( + state, "MouseControl", [](LuaIgnored) { return g_manager->optionsConfig.isMouseControlEnabled; }, + [](LuaIgnored, bool isEnabled) { + g_manager->optionsConfig.isMouseControlEnabled = isEnabled; + isEnabled ? SDL_HideCursor() : SDL_ShowCursor(); + }); + lua_property( + state, "UseBorderlessFullscreen", [](LuaIgnored) { return !g_manager->optionsConfig.isExclusiveFullscreen; }, + [](LuaIgnored, bool isBorderless) { g_manager->optionsConfig.isExclusiveFullscreen = !isBorderless; }); + option_add<&OptionsConfig::isFilterEnabled>(state, "Filter"); + option_add<&OptionsConfig::isFoundHudEnabled>(state, "FoundHUD"); + option_add<&OptionsConfig::isRumbleEnabled>(state, "RumbleEnabled"); + option_add<&OptionsConfig::isChargeBarsEnabled>(state, "ChargeBars"); + option_add<&OptionsConfig::isBulletVisibilityEnabled>(state, "BulletVisibility"); + option_add<&OptionsConfig::isPauseOnFocusLostEnabled>(state, "PauseOnFocusLost"); + option_add<&OptionsConfig::isFadedConsoleDisplayEnabled>(state, "FadedConsoleDisplay"); + option_add<&OptionsConfig::isSaveCommandHistoryEnabled>(state, "SaveCommandHistory"); + option_add<&OptionsConfig::isDebugConsoleEnabled>(state, "DebugConsoleEnabled"); + option_clamped_add<&OptionsConfig::popupsMode, 0, 2>(state, "DisplayPopups"); + option_clamped_add<&OptionsConfig::cameraStyle, 1, 2>(state, "CameraStyle"); + option_clamped_add<&OptionsConfig::historyHudMode, 0, 2>(state, "ExtraHUDStyle"); + option_clamped_add<&OptionsConfig::announcerVoiceMode, 0, 2>(state, "AnnouncerVoiceMode"); + option_clamped_add<&OptionsConfig::maxScale, 1, OPTION_SCALE_MAX>(state, "MaxScale"); + option_clamped_add<&OptionsConfig::maxRenderScale, 1, OPTION_SCALE_MAX>(state, "MaxRenderScale"); + option_clamped_add<&OptionsConfig::consoleFont, 0, 2>(state, "ConsoleFont"); + option_clamped_add<&OptionsConfig::jacobEsauControls, 0, 1>(state, "JacobEsauControls"); lua_property(state, "Language", [](LuaIgnored) { return std::string(Manager::GetLanguage()); }); lua_class_end(state); } diff --git a/src/lua_api_room.cpp b/src/lua_api_room.cpp index 56ba20f..a03837d 100644 --- a/src/lua_api_room.cpp +++ b/src/lua_api_room.cpp @@ -10,6 +10,53 @@ #include "room_descriptor.h" #include "room_grid.h" +// The frames KeepDoorsClosed holds the room uncleared for. +constexpr int ROOM_CLEAR_DELAY_KEPT = 10; + +// Adds a property for one of a room descriptor's flags. +template +static void descriptor_flag_add(lua_State* state, const char* name) +{ + lua_property( + state, name, [](RoomDescriptor& room) { return (room.flags & Flag) != 0; }, + [](RoomDescriptor& room, bool isSet) { room.flags = isSet ? room.flags | Flag : room.flags & ~Flag; }); +} + +// Registers a list of a room config's spawns or entries: its Size, and Get, nil past the end. +template +static void room_config_list_register(lua_State* state, const char* name, LuaClass luaClass) +{ + using List = std::vector; + lua_class_begin(state, name, luaClass); + lua_property(state, "Size", [](List& list) { return (int)list.size(); }); + lua_method(state, "Get", [](List& list, uint32_t index) { return index < list.size() ? &list[index] : nullptr; }); + lua_class_end(state, LUA_SCOPE_NAMESPACE); +} + +// Registers RoomConfig.Spawn, a cell of a layout and the entities it picks one of, RoomConfig.Entry, one of those, and +// their lists, in the RoomConfig namespace begun before. +static void room_config_spawns_register(lua_State* state) +{ + lua_class_begin(state, "Spawn", LUA_CLASS_ROOM_CONFIG_SPAWN); + lua_field_get<&RoomSpawn::x>(state, "X"); + lua_field_get<&RoomSpawn::y>(state, "Y"); + lua_field_get<&RoomSpawn::sumWeights>(state, "SumWeights"); + lua_property(state, "EntryCount", [](RoomSpawn& spawn) { return (int)spawn.entries.size(); }); + lua_property(state, "Entries", [](RoomSpawn& spawn) -> std::vector& { return spawn.entries; }); + lua_method(state, "PickEntry", [](RoomSpawn& spawn, float value) { return spawn.PickEntry(value); }); + lua_class_end(state, LUA_SCOPE_NAMESPACE); + + lua_class_begin(state, "Entry", LUA_CLASS_ROOM_CONFIG_ENTRY); + lua_field_get<&RoomEntry::type>(state, "Type"); + lua_field_get<&RoomEntry::variant>(state, "Variant"); + lua_field_get<&RoomEntry::subtype>(state, "Subtype"); + lua_field_get<&RoomEntry::weight>(state, "Weight"); + lua_class_end(state, LUA_SCOPE_NAMESPACE); + + room_config_list_register(state, "SpawnList", LUA_CLASS_ROOM_CONFIG_SPAWN_LIST); + room_config_list_register(state, "EntryList", LUA_CLASS_ROOM_CONFIG_ENTRY_LIST); +} + // Registers Lua's Level, which Game is: the floor's stage, curses, rooms and maps. static void level_register(lua_State* state) { @@ -39,6 +86,7 @@ static void level_register(lua_State* state) lua_method(state, "GetCurrentRoomIndex", [](Level& level) { return level.currentRoomIdx; }); lua_method(state, "GetPreviousRoomIndex", [](Level& level) { return level.lastRoomIdx; }); lua_method(state, "GetStartingRoomIndex", [](Level& level) { return level.startingRoomIdx; }); + lua_method(state, "GetLastBossRoomListIndex", [](Level& level) { return level.lastBossRoomListIdx; }); lua_method(state, "GetRoomCount", [](Level& level) { return level.nbRooms; }); lua_method(state, "GetCurrentRoomDesc", [](Level& level) { return level.GetCurrentRoomDesc(); }); lua_method(state, "GetLastRoomDesc", [](Level& level) { return level.GetLastRoomDesc(); }); @@ -119,7 +167,9 @@ static void level_register(lua_State* state) lua_field_get<&RoomConfig_Room::width>(state, "Width"); lua_field_get<&RoomConfig_Room::height>(state, "Height"); lua_field_get<&RoomConfig_Room::shape>(state, "Shape"); + lua_property(state, "Spawns", [](RoomConfig_Room& room) -> std::vector& { return room.spawns; }); lua_class_end(state, LUA_SCOPE_NAMESPACE); + room_config_spawns_register(state); lua_class_end(state); lua_class_begin(state, "RoomDescriptor", LUA_CLASS_ROOM_DESCRIPTOR); @@ -141,42 +191,18 @@ static void level_register(lua_State* state) lua_field<&RoomDescriptor::shopItemIdx>(state, "ShopItemIdx"); lua_field<&RoomDescriptor::shopItemDiscountIdx>(state, "ShopItemDiscountIdx"); lua_field<&RoomDescriptor::deliriumDistance>(state, "DeliriumDistance"); - lua_property( - state, "Clear", [](RoomDescriptor& room) { return (bool)(room.flags & ROOM_DESCRIPTOR_FLAG_CLEAR); }, - [](RoomDescriptor& room, bool isClear) { - room.flags = isClear ? room.flags | ROOM_DESCRIPTOR_FLAG_CLEAR : room.flags & ~ROOM_DESCRIPTOR_FLAG_CLEAR; - }); + descriptor_flag_add(state, "Clear"); + descriptor_flag_add(state, "PressurePlatesTriggered"); + descriptor_flag_add(state, "SacrificeDone"); + descriptor_flag_add(state, "ChallengeDone"); + descriptor_flag_add(state, "SurpriseMiniboss"); + descriptor_flag_add(state, "HasWater"); + descriptor_flag_add(state, "NoReward"); lua_class_end(state); } -// Registers Lua's GridEntity, the base of rocks, pits, doors and the other tiles of a room. -static void grid_entity_register(lua_State* state) -{ - lua_class_begin(state, "GridEntity", LUA_CLASS_GRID_ENTITY); - lua_method(state, "GetType", [](GridEntity& grid) { return grid.type; }); - lua_method(state, "GetVariant", [](GridEntity& grid) { return grid.variant; }); - lua_method(state, "GetGridIndex", [](GridEntity& grid) { return grid.gridIndex; }); - lua_method(state, "GetSprite", [](GridEntity& grid) -> ANM2& { return grid.sprite; }); - lua_method(state, "GetRNG", [](GridEntity& grid) -> RNG& { return grid.rng; }); - lua_method(state, "Update", [](GridEntity& grid) { grid.Update(); }); - lua_method(state, "Render", [](GridEntity& grid, Vector offset) { grid.Render(offset); }); - lua_method(state, "PostInit", [](GridEntity& grid) { grid.PostInit(); }); - lua_method(state, "Hurt", [](GridEntity& grid, int damage) { return grid.Hurt(damage, EntityRef()); }); - lua_method(state, "HurtWithSource", - [](GridEntity& grid, int damage, const EntityRef& source) { return grid.Hurt(damage, source); }); - lua_method(state, "Destroy", - [](GridEntity& grid, bool isImmediate) { return grid.Destroy(isImmediate, EntityRef()); }); - lua_method(state, "DestroyWithSource", [](GridEntity& grid, bool isImmediate, const EntityRef& source) { - return grid.Destroy(isImmediate, source); - }); - lua_property(state, "Position", [](GridEntity& grid) { return grid.Position(); }); - lua_field<&GridEntity::state>(state, "State"); - lua_field<&GridEntity::varData>(state, "VarData"); - lua_field<&GridEntity::collisionClass>(state, "CollisionClass"); - lua_class_end(state); -} - -// Registers Lua's Room: the current room's grid, entities, doors, clear state and the doors it may spawn. +// (007f79d0, 0081e240, 00820c00) Registers Lua's Room: the current room's grid, entities, doors, clear state and the +// doors it may spawn. static void room_register(lua_State* state) { lua_class_begin(state, "Room", LUA_CLASS_ROOM); @@ -217,6 +243,11 @@ static void room_register(lua_State* state) lua_method(state, "IsMirrorWorld", [](Room&) { return Room::IsMirrorWorld(); }); lua_method(state, "IsCurrentRoomLastBoss", [](Room&) { return Room::IsCurrentRoomLastBoss(); }); lua_method(state, "IsLShapedRoom", [](Room& room) { return room.IsLShapedRoom(); }); + lua_method(state, "IsAmbushActive", [](Room&) { return g_game->ambush._isActive; }); + lua_method(state, "HasTriggerPressurePlates", [](Room& room) { return room.isTriggerPressurePlates; }); + lua_method(state, "GetTintedRockIdx", [](Room& room) { return room.tintedRockIdx; }); + lua_method(state, "GetRenderMode", [](Room& room) { return room.entityList.renderMode; }); + lua_method(state, "KeepDoorsClosed", [](Room& room) { room.roomClearDelay = ROOM_CLEAR_DELAY_KEPT; }); lua_method(state, "TurnGold", [](Room& room) { room.TurnGold(); }); lua_method(state, "PlayMusic", [](Room& room) { room.PlayMusic(); }); @@ -237,6 +268,17 @@ static void room_register(lua_State* state) return room_free_pickup_position_find( {.position = position, .step = step, .isAvoidActiveEntities = isAvoidActive, .isAllowPits = isAllowPits}); }); + lua_method(state, "FindFreeTilePosition", [](Room&, Vector position, float distanceThreshold) { + return room_free_tile_position_find(position, distanceThreshold); + }); + lua_method(state, "GetDoorSlotPosition", [](Room& room, int slot) { + return (uint32_t)slot < DOOR_SLOT_COUNT ? room.GetGridPosition(room.doorGridPositions[slot]) : vector_make(0, 0); + }); + lua_method(state, "WorldToScreenPosition", [](Room& room, Vector position) { + Vector screen = render_position_get(position, RENDER_SNAPPED); + return vector_make(screen.x + room.renderScrollOffset.x + g_game->screenShakeOffset.x, + screen.y + room.renderScrollOffset.y + g_game->screenShakeOffset.y); + }); lua_method(state, "CheckLine", [](Room&, Vector start, Vector end, int mode, int threshold) { return room_check_line(start, end, mode, threshold); }); @@ -256,7 +298,7 @@ static void room_register(lua_State* state) [](Room& room, int index, GridEntityType type, int variant, uint32_t seed, int varData) { return room.SpawnGridEntity(index, type, variant, seed, varData); }); - lua_method(state, "GetDoor", [](Room& room, int slot) -> GridEntity* { return room.GetDoor(slot); }); + lua_method(state, "GetDoor", [](Room& room, int slot) { return room.GetDoor(slot); }); lua_method(state, "IsDoorSlotAllowed", [](Room& room, int slot) { return room.IsDoorSlotAllowed(slot); }); lua_method(state, "RemoveDoor", [](Room& room, int slot) { room.RemoveDoor(slot); }); lua_method(state, "TrySpawnDevilRoomDoor", [](Room& room, bool isAnimated, bool isForced) { @@ -284,6 +326,6 @@ static void room_register(lua_State* state) void lua_api_room_register(lua_State* state) { level_register(state); - grid_entity_register(state); + lua_api_grid_entity_register(state); room_register(state); } diff --git a/src/lua_callbacks.cpp b/src/lua_callbacks.cpp index d3691cd..a2be448 100644 --- a/src/lua_callbacks.cpp +++ b/src/lua_callbacks.cpp @@ -13,6 +13,7 @@ #include "game.h" #include "log.h" #include "lua_api.h" +#include "room_config.h" constexpr int CALLBACK_PARAM_NONE = -1; constexpr int PILL_EFFECT_UNCHANGED = -1; @@ -112,25 +113,28 @@ static void field_read(lua_State* state, const char* key, bool& value) lua_pop(state, 1); } -// Sets value to an element of the table on top of the stack, when the element is not nil. +// Sets value to an element of the table on top of the stack, when the element is not nil. Whether it was not. // The original aborts on an element that is not an integer. This keeps the value instead. template -static void element_read(lua_State* state, int key, T& value) +static bool element_read(lua_State* state, int key, T& value) { int isInteger = 0; - lua_geti(state, -1, key); + bool isSet = lua_geti(state, -1, key) != LUA_TNIL; lua_Integer element = lua_tointegerx(state, -1, &isInteger); if (isInteger) value = (T)element; lua_pop(state, 1); + return isSet; } -// Pops a callback's result, and when it is a table sets values in order to its elements 1, 2 ... +// Pops a callback's result, and when it is a table sets values in order to its elements 1, 2 ... Whether any was set. template -static void elements_pop(lua_State* state, T&... values) +static bool elements_pop(lua_State* state, T&... values) { int key = 1; - if (lua_istable(state, -1)) (element_read(state, key++, values), ...); + bool isChanged = false; + if (lua_istable(state, -1)) ((isChanged |= element_read(state, key++, values)), ...); lua_pop(state, 1); + return isChanged; } // 00862250 Runs MC_PRE_BOMB_COLLISION, filtered by the bomb's variant. @@ -301,6 +305,17 @@ void LuaEngine::Callback_PreEntitySpawn(EntitySpawn& spawn) elements_pop(state, spawn.type, spawn.variant, spawn.subType, spawn.seed); } +// 00866490 Runs MC_PRE_ROOM_ENTITY_SPAWN for a layout entry about to spawn, filtered by its subtype as the original +// passes it. A table result replaces its type, variant and subtype, in that order, with each element that is not nil. +// Whether any was replaced. +bool LuaEngine::PreRoomEntitySpawn(RoomEntry& entry, int gridIndex, uint32_t seed) +{ + CallbackRun run = {"PreRoomEntitySpawn", MC_PRE_ROOM_ENTITY_SPAWN, entry.subtype}; + if (!callback_run(*this, run, (int)entry.type, (int)entry.variant, (int)entry.subtype, gridIndex, seed)) + return false; + return elements_pop(state, entry.type, entry.variant, entry.subtype); +} + // 00863340 Runs MC_POST_PICKUP_SELECTION for the kind a pickup was given. A table result replaces its variant and // subtype, in that order, with each element that is not nil. void LuaEngine::PostPickupSelection(Entity_Pickup* pickup, int& variant, int& subType) diff --git a/src/lua_engine.h b/src/lua_engine.h index 713137c..67909bc 100644 --- a/src/lua_engine.h +++ b/src/lua_engine.h @@ -23,6 +23,7 @@ struct Entity_Tear; struct EntityRef; struct EntitySpawn; struct RNG; +struct RoomEntry; struct Vector; struct lua_State; @@ -54,6 +55,14 @@ enum LuaClass LUA_CLASS_FONT_SETTINGS, LUA_CLASS_GAME, LUA_CLASS_GRID_ENTITY, + LUA_CLASS_GRID_ENTITY_DESC, + LUA_CLASS_GRID_ENTITY_DOOR, + LUA_CLASS_GRID_ENTITY_PIT, + LUA_CLASS_GRID_ENTITY_POOP, + LUA_CLASS_GRID_ENTITY_PRESSURE_PLATE, + LUA_CLASS_GRID_ENTITY_ROCK, + LUA_CLASS_GRID_ENTITY_SPIKES, + LUA_CLASS_GRID_ENTITY_TNT, LUA_CLASS_HUD, LUA_CLASS_ITEM_CONFIG, LUA_CLASS_ITEM_CONFIG_CARD, @@ -68,15 +77,21 @@ enum LuaClass LUA_CLASS_LEVEL, LUA_CLASS_MUSIC_MANAGER, LUA_CLASS_PROJECTILE_PARAMS, + LUA_CLASS_QUEUE_ITEM_DATA, LUA_CLASS_RNG, LUA_CLASS_ROOM, + LUA_CLASS_ROOM_CONFIG_ENTRY, + LUA_CLASS_ROOM_CONFIG_ENTRY_LIST, LUA_CLASS_ROOM_CONFIG_ROOM, + LUA_CLASS_ROOM_CONFIG_SPAWN, + LUA_CLASS_ROOM_CONFIG_SPAWN_LIST, LUA_CLASS_ROOM_DESCRIPTOR, LUA_CLASS_ROOM_LIST, LUA_CLASS_SEEDS, LUA_CLASS_SFX_MANAGER, LUA_CLASS_SPRITE, LUA_CLASS_TEAR_PARAMS, + LUA_CLASS_TEMPORARY_EFFECT, LUA_CLASS_TEMPORARY_EFFECTS, LUA_CLASS_VECTOR, LUA_CLASS_COUNT @@ -155,6 +170,7 @@ struct LuaEngine bool PreSpawnCleanAward(const RNG& rng, const Vector& position); bool PreUseItem(const LuaItemUse& use); void Callback_PreEntitySpawn(EntitySpawn& spawn); + bool PreRoomEntitySpawn(RoomEntry& entry, int gridIndex, uint32_t seed); void PostPickupSelection(Entity_Pickup* pickup, int& variant, int& subType); bool UseItem(LuaItemUse& use); diff --git a/src/manager.cpp b/src/manager.cpp index 411cdda..1fe559a 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -222,7 +222,6 @@ constexpr int LOADING_BLINK_HALF = 8; constexpr int SAVE_RESTORE_HELD_KEY = 342; constexpr int SAVE_RESTORE_KEY = 291; // Mods or the console disallow achievements unless this one is unlocked, as the original reads it. -constexpr int ACHIEVEMENT_THE_WOMB = 4; // What the command line asks of the run IsaacStartup sets up, by the debug flags it reads. struct StartupArguments diff --git a/src/minimap.cpp b/src/minimap.cpp index 13a4e9b..a0d1959 100644 --- a/src/minimap.cpp +++ b/src/minimap.cpp @@ -105,7 +105,6 @@ constexpr float TEXT_DROP_INSET = 12; constexpr float TIME_Y = 30; constexpr float SCORE_Y = 46; -constexpr int CHALLENGE_APRILS_FOOL = 32; constexpr RNG APRILS_FOOL_RNG = {0, 1, 5, 16}; constexpr int DIMENSION_DEATH_CERTIFICATE = 2; constexpr int SUBTYPE_MINESHAFT_ENTRANCE = 10; diff --git a/src/npc_ai.cpp b/src/npc_ai.cpp index 2aa128f..583cbb3 100644 --- a/src/npc_ai.cpp +++ b/src/npc_ai.cpp @@ -158,7 +158,7 @@ static void npc_ai_routine_run(Entity_NPC& npc) case 35: return (void)NpcAI::ENTITY_MRMAW(&npc); case 36: - return (void)NpcAI::ENTITY_GURDY(&npc); + return boss_gurdy_update(npc); case 38: case 259: return (void)NpcAI::ENTITY_BABY(&npc); @@ -178,11 +178,11 @@ static void npc_ai_routine_run(Entity_NPC& npc) case 203: case 235: case 236: - return (void)NpcAI::ENTITY_STONEHEAD(&npc); + return npc_stonehead_update(npc); case 44: return (void)NpcAI::ENTITY_POKY(&npc); case 45: - return (void)NpcAI::ENTITY_MOM(&npc); + return boss_mom_update(npc); case 46: return (void)NpcAI::ENTITY_SLOTH(&npc); case 47: @@ -211,9 +211,9 @@ static void npc_ai_routine_run(Entity_NPC& npc) case 62: return (void)NpcAI::ENTITY_PIN(&npc); case 63: - return (void)NpcAI::ENTITY_FAMINE(&npc); + return boss_famine_update(npc); case 64: - return (void)NpcAI::ENTITY_PESTILENCE(&npc); + return boss_pestilence_update(npc); case 65: return (void)NpcAI::ENTITY_WAR(&npc); case 66: @@ -221,13 +221,13 @@ static void npc_ai_routine_run(Entity_NPC& npc) case 67: return boss_duke_update(npc); case 68: - return (void)NpcAI::ENTITY_PEEP(&npc); + return boss_peep_update(npc); case 69: - return (void)NpcAI::ENTITY_LOKI(&npc); + return boss_loki_update(npc); case 71: case 72: case 73: - return (void)NpcAI::ENTITY_FISTULA_BIG(&npc); + return boss_fistula_update(npc); case 74: case 75: case 76: @@ -252,7 +252,7 @@ static void npc_ai_routine_run(Entity_NPC& npc) case 869: return npc_spider_update(npc); case 87: - return (void)NpcAI::ENTITY_GURGLE(&npc); + return npc_gurgle_update(npc); case 88: return npc_walking_boil_update(npc); case 90: @@ -267,16 +267,16 @@ static void npc_ai_routine_run(Entity_NPC& npc) case 93: reconstruction_missing("npc_ai_update 006c2990: Mask pairing with its Heart"); case 96: - return (void)NpcAI::ENTITY_ETERNALFLY(&npc); + return npc_eternal_fly_update(npc); case 97: return (void)NpcAI::ENTITY_MASK_OF_INFAMY(&npc); case 98: if (npc.state == NPC_STATE_INIT) npc.state = NPC_STATE_MOVE; return; case 99: - return (void)NpcAI::ENTITY_GURDY_JR(&npc); + return boss_gurdy_jr_update(npc); case 100: - return (void)NpcAI::ENTITY_WIDOW(&npc); + return boss_widow_update(npc); case 101: return (void)NpcAI::ENTITY_DADDYLONGLEGS(&npc); case 102: @@ -284,7 +284,7 @@ static void npc_ai_routine_run(Entity_NPC& npc) case 201: return (void)NpcAI::ENTITY_STONE_EYE(&npc); case 202: - return (void)NpcAI::ENTITY_CONSTANT_STONE_SHOOTER(&npc); + return npc_stone_shooter_update(npc); case 204: case 247: return (void)NpcAI::ENTITY_MOBILE_HOST(&npc); @@ -309,7 +309,7 @@ static void npc_ai_routine_run(Entity_NPC& npc) return (void)NpcAI::ENTITY_WIZOOB(&npc); case 220: case 871: - return (void)NpcAI::ENTITY_SQUIRT(&npc); + return npc_squirt_update(npc); case 221: return (void)NpcAI::ENTITY_COD_WORM(&npc); case 222: @@ -330,7 +330,7 @@ static void npc_ai_routine_run(Entity_NPC& npc) return (void)NpcAI::ENTITY_NERVE_ENDING(&npc); case 232: case 234: - return (void)NpcAI::ENTITY_SKINBALL(&npc); + return npc_one_tooth_update(npc); case 240: case 241: case 242: @@ -346,15 +346,15 @@ static void npc_ai_routine_run(Entity_NPC& npc) case 256: return npc_dart_fly_update(npc); case 258: - return (void)NpcAI::ENTITY_FAT_BAT(&npc); + return npc_fat_bat_update(npc); case 260: - return (void)NpcAI::ENTITY_THE_HAUNT(&npc); + return boss_haunt_update(npc); case 261: return boss_dingle_update(npc); case 262: - return (void)NpcAI::ENTITY_MEGA_MAW(&npc); + return boss_mega_maw_update(npc); case 263: - return (void)NpcAI::ENTITY_GATE(&npc); + return boss_gate_update(npc); case 264: return (void)NpcAI::ENTITY_MEGA_FATTY(&npc); case 265: @@ -367,7 +367,7 @@ static void npc_ai_routine_run(Entity_NPC& npc) return (void)NpcAI::ENTITY_ADVERSARY(&npc); case 269: case 401: - return (void)NpcAI::ENTITY_POLYCEPHALUS(&npc); + return boss_polycephalus_update(npc); case 270: return (void)NpcAI::ENTITY_MR_FRED(&npc); case 271: @@ -384,11 +384,11 @@ static void npc_ai_routine_run(Entity_NPC& npc) case 281: return npc_swarm_update(npc); case 288: - return (void)NpcAI::ENTITY_DUKIE(&npc); + return npc_dukie_update(npc); case 290: return (void)NpcAI::ENTITY_MEATBALL(&npc); case 291: - return (void)NpcAI::ENTITY_PITFALL(&npc); + return npc_pitfall_update(npc); case 292: return npc_movable_tnt_update(npc); case 293: @@ -530,7 +530,7 @@ static void npc_ai_routine_run(Entity_NPC& npc) case 860: return (void)NpcAI::ENTITY_UNBORN(&npc); case 861: - return (void)NpcAI::ENTITY_PUSTULE(&npc); + return npc_pustule_update(npc); case 863: return (void)NpcAI::ENTITY_MORNINGSTAR(&npc); case 864: diff --git a/src/npc_ai.h b/src/npc_ai.h index b3d0c18..732ea20 100644 --- a/src/npc_ai.h +++ b/src/npc_ai.h @@ -17,10 +17,8 @@ constexpr float RADIANS_TO_DEGREES = 57.295776f; enum NpcSound : int { SOUND_BOSS1_EXPLOSIONS = 28, - SOUND_INSECT_SWARM_LOOP = 52, SOUND_MEAT_IMPACTS = 77, SOUND_ZOMBIE_WALKER_KID = 165, - SOUND_MONSTER_GRUNT_0 = 167, SOUND_SUMMON_POOF = 286, SOUND_SUMMON_WAVE = 872 }; diff --git a/src/npc_basement.h b/src/npc_basement.h index f590709..791a450 100644 --- a/src/npc_basement.h +++ b/src/npc_basement.h @@ -2,6 +2,9 @@ #include "npc_ai.h" +// The Hopper's Trite variant, which several bosses summon. +constexpr int HOPPER_TRITE = 1; + // The basement enemies' AIs the dispatcher (npc_ai_update) runs by type. void npc_gusher_update(Entity_NPC& npc); void npc_clotty_update(Entity_NPC& npc); @@ -26,6 +29,12 @@ void npc_walking_boil_update(Entity_NPC& npc); void npc_baby_long_legs_update(Entity_NPC& npc); void npc_movable_tnt_update(Entity_NPC& npc); +// Cancels an enemy's pending damage of the given kinds, but the players' own, friendly ones' and TNT's. +void npc_hostile_damage_ignore(Entity_NPC& npc, uint64_t damageFlags); + +// NpcHelper::bulb_player_collision: an attacking Bulb touching a player bounces off and drains its charge. +void bulb_player_collision(Entity_NPC& npc, Entity& collider); + // spawn_small_maggot_jump: a small maggot leaping from a position, a height up, onto a spot it keeps clear. Entity_NPC* small_maggot_jump_spawn(const Vector& position, float height, const Vector& spot); diff --git a/src/npc_boom_fly.cpp b/src/npc_boom_fly.cpp index d4fba51..16343fc 100644 --- a/src/npc_boom_fly.cpp +++ b/src/npc_boom_fly.cpp @@ -105,7 +105,6 @@ constexpr int TAINTED_WAVES = 4; constexpr int TAINTED_BLOOM_FRAMES = 6; constexpr float TAINTED_FRICTION = 0.6f; constexpr int EFFECT_EXPLOSION_WAVE = 187; -constexpr int EFFECT_GENERIC_TRACER = 198; constexpr float TAINTED_WAVE_TURN = 90; constexpr ColorMod DRAGON_SPLAT_COLOR = {{0, 0, 0, 1.1f}, {0, 0, 0, 0}, {1, 0.5137255f, 0.003921569f}}; diff --git a/src/npc_bulb.cpp b/src/npc_bulb.cpp index a713c4d..5368adf 100644 --- a/src/npc_bulb.cpp +++ b/src/npc_bulb.cpp @@ -1,9 +1,12 @@ #include "npc_basement.h" +#include "active_items.h" +#include "entity_effect.h" #include "entity_player.h" #include "game.h" #include "item_config.h" #include "manager.h" #include "room.h" +#include "sfx_manager.h" // The Bulb, and the Black Bulb that always attacks and bursts into a plus of shots. constexpr int BULB_BLACK = 6; @@ -229,3 +232,72 @@ void npc_bulb_update(Entity_NPC& npc) ProjectileParams params; npc.FireProjectiles(npc.pos, vector_make(BLACK_BULB_SHOT_SPEED, 0), PROJECTILES_PLUS, params); } + +// A Bulb that touches a player while attacking bounces back 80 the way it came, pushed at 16. The Bulb drains the first +// active slot with charge: all of a timed item, 2 charges of a small one (12 or fewer), else a third of its charges. +constexpr float BULB_BOUNCE_REACH = 80; +constexpr float BULB_BOUNCE_PUSH = 16; +constexpr int BULB_BOUNCE_FRAMES = 4; +constexpr float BLACK_BULB_BITE = 1; +constexpr float BLACK_BULB_HIT = 10; +constexpr int BULB_HIT_COOLDOWN = 30; +constexpr int BULB_DRAIN_ALL = -1000; +constexpr int BULB_DRAIN_SMALL = -2; +constexpr int BULB_SMALL_CHARGES = 12; +constexpr int BULB_DRAIN_SHARE = 3; +constexpr int BULB_SPARK_SUBTYPE = 3; +constexpr float BULB_SPARK_RISE = -24; + +// The bounce back off what it hit. +static void bulb_bounce(Entity_NPC& npc) +{ + npc.state = NPC_STATE_JUMP; + npc.v1 = vector_scale(npc.v1, -1); + npc.stateFrame = BULB_BOUNCE_FRAMES; + npc.targetPosition = vector_add(vector_scale(npc.v1, BULB_BOUNCE_REACH), npc.pos); + npc.velocity.x += npc.v1.x * BULB_BOUNCE_PUSH * npc.speedMultiplier; + npc.velocity.y += npc.v1.y * BULB_BOUNCE_PUSH * npc.speedMultiplier; +} + +// 0054ccc0 An attacking Bulb touching a player: it bounces off and drains its first charged active slot, with a flash +// of the charge bar and a spark. The Black Bulb bites a player or familiar for 1 (anything else for 10) instead. +void bulb_player_collision(Entity_NPC& npc, Entity& collider) +{ + if (npc.variant == BULB_BLACK) + { + bool isPlayerSide = collider.type == ENTITY_PLAYER || collider.type == ENTITY_FAMILIAR; + if (isPlayerSide) collider.TakeDamage(BLACK_BULB_BITE, 0, EntityRef(&npc), BULB_HIT_COOLDOWN); + else collider.TakeDamage(BLACK_BULB_HIT, 0, EntityRef(), BULB_HIT_COOLDOWN); + bulb_bounce(npc); + return; + } + if (collider.type != ENTITY_PLAYER) return; + + bulb_bounce(npc); + Entity_Player& player = *collider.ToPlayer(); + player.PlayExtraAnimation("Hit"); + player.ResetItemState(); + for (int slot = 0; slot < ACTIVE_SLOT_COUNT; slot++) + { + int maxCharge = player.GetActiveMaxCharge(slot); + bool isCharged = g_manager->itemConfig.GetCollectible(player.activeItems[slot].item) && maxCharge > 0 && + player.activeItems[slot].charge > 0; + if (!isCharged) continue; + + int drain = maxCharge <= BULB_SMALL_CHARGES ? BULB_DRAIN_SMALL : -(maxCharge / BULB_DRAIN_SHARE); + if (active_charge_type(player, slot) == CHARGE_TIMED) drain = BULB_DRAIN_ALL; + player.AddActiveCharge(drain, slot, false, false, false); + g_game->hud.FlashChargeBar(&player, slot); + npc_sound_play(SOUND_BATTERYDISCHARGE, 1, 2, 1); + + Entity* spark = g_game->Spawn({.position = player.pos, + .subType = BULB_SPARK_SUBTYPE, + .type = ENTITY_EFFECT, + .variant = EFFECT_HEART, + .seed = Random()}); + spark->sprite.offset = vector_make(0, BULB_SPARK_RISE); + spark->renderDepthOffset = 1; + npc.projectileCooldown++; + return; + } +} diff --git a/src/npc_caves.h b/src/npc_caves.h index 056744d..b78471a 100644 --- a/src/npc_caves.h +++ b/src/npc_caves.h @@ -9,6 +9,18 @@ void npc_globin_update(Entity_NPC& npc); void npc_host_update(Entity_NPC& npc); void npc_maggot_update(Entity_NPC& npc); void npc_mushroom_update(Entity_NPC& npc); +void npc_stonehead_update(Entity_NPC& npc); +void npc_squirt_update(Entity_NPC& npc); +void npc_stone_shooter_update(Entity_NPC& npc); +void npc_one_tooth_update(Entity_NPC& npc); +void npc_fat_bat_update(Entity_NPC& npc); +void npc_dukie_update(Entity_NPC& npc); +void npc_gurgle_update(Entity_NPC& npc); + +// The other enemies' AIs the dispatcher runs: the eternal fly, Pitfall and Pustule. +void npc_eternal_fly_update(Entity_NPC& npc); +void npc_pitfall_update(Entity_NPC& npc); +void npc_pustule_update(Entity_NPC& npc); // Pushes a bouncer (the Boom Fly, the floating Host) along its diagonal, steered by its controller. False when a // confused one wanders instead. diff --git a/src/npc_collision.cpp b/src/npc_collision.cpp index 3656738..e34550e 100644 --- a/src/npc_collision.cpp +++ b/src/npc_collision.cpp @@ -34,9 +34,7 @@ constexpr int ENTITY_BLASTER = 821; constexpr int ENTITY_BOUNCER = 822; constexpr int ENTITY_GASBAG = 856; constexpr int ENTITY_ARMYFLY = 868; -constexpr int ENTITY_DRIP = 870; constexpr int ENTITY_BUTT_SLICKER = 878; -constexpr int ENTITY_NEEDLE = 881; constexpr int ENTITY_CLICKETY_CLACK = 889; constexpr int ENTITY_NERVE_ENDING_2 = 964; @@ -588,9 +586,10 @@ static Verdict contact_player(Contact& contact, Entity_Player& player) if (npc.isKillOnTouch) npc.Kill(EntityRef()); bool isBulb = npc.type == ENTITY_SUCKER && npc.variant >= SUCKER_BULB_FIRST && npc.variant <= SUCKER_BULB_LAST; - if (isBulb && npc.state == NPC_STATE_ATTACK) - reconstruction_missing("Entity_NPC::HandleCollision 006cd410: a Bulb draining a player"); - return std::nullopt; + if (!isBulb || npc.state != NPC_STATE_ATTACK) return std::nullopt; + + bulb_player_collision(npc, player); + return true; } // The rams of bosses into enemies: Famine, Chub biting chargers and spiders, Gurdy Jr. eating Pooters, the Cage diff --git a/src/npc_dukie.cpp b/src/npc_dukie.cpp new file mode 100644 index 0000000..b70a9bf --- /dev/null +++ b/src/npc_dukie.cpp @@ -0,0 +1,105 @@ +#include "npc_caves.h" +#include "game.h" +#include "sfx_manager.h" + +// Dukie bounces about at 0.3 a frame along each axis it moves on (steered by up to half that by its controller). Its +// bar empties over 90 frames, then one time in ten (while the room holds 7 enemies or fewer) it coughs up a dart fly +// 40 below it, a second one time in three, thrown at 3.5. It waits 90 to 119 frames after (90 when controlled). +constexpr float DUKIE_PUSH = 0.3f; +constexpr float DUKIE_STEER_SHARE = 0.5f; +constexpr float DUKIE_FRICTION = 0.9f; +constexpr int DUKIE_FIRST_COUGH = 60; +constexpr float DUKIE_COUGH_BAR = 90; +constexpr int DUKIE_COOLDOWN = 90; +constexpr uint32_t DUKIE_COOLDOWN_RANGE = 30; +constexpr uint32_t DUKIE_COUGH_ODDS = 10; +constexpr int DUKIE_CROWD = 7; +constexpr uint32_t DUKIE_SECOND_FLY_ODDS = 3; +constexpr float DUKIE_FLY_DROP = 40; +constexpr float DUKIE_FLY_THROW = 3.5f; +constexpr float DUKIE_CONTROLLED_RANGE = 1000; +constexpr int DUKIE_RANGE_FRAMES = 7; + +// A dart fly coughed out below it. +static void dukie_fly_spawn(Entity_NPC& npc) +{ + uint32_t seed = Random(); + Vector velocity = vector_add(vector_scale(random_direction(), DUKIE_FLY_THROW), npc.velocity); + Vector position = vector_make(npc.pos.x, npc.pos.y + DUKIE_FLY_DROP); + Entity* fly = g_game->Spawn( + {.position = position, .velocity = velocity, .spawner = &npc, .type = ENTITY_DART_FLY, .seed = seed}); + fly->ClearEntityFlags(FLAG_APPEAR); +} + +// Whether it starts coughing: a chance while the room is not crowded, or its controller in range or shooting. +static bool dukie_is_coughing(Entity_NPC& npc) +{ + if (npc.projectileCooldown >= 1) return false; + bool isReady = npc.controllerID == -1 + ? Random() % DUKIE_COUGH_ODDS == 0 && npc.GetAliveEnemyCount() <= DUKIE_CROWD + : npc.IsTargetInAttackRange(DUKIE_CONTROLLED_RANGE, DUKIE_RANGE_FRAMES, false) || + npc.IsControllerActionPressed(CONTROLLER_ACTION_SHOOT); + return isReady && !npc.HasEntityFlags(FLAG_CONFUSION); +} + +// Coughing: dart flies on the Shoot event, then back to bouncing with a fresh wait. +static void dukie_cough(Entity_NPC& npc) +{ + npc.sprite.Play("Cough"); + if (npc.sprite.animState.animData) + { + if (npc.sprite.animState.IsEventTriggered("Shoot")) + { + npc.PlaySound(SOUND_WORM_SPIT, 1, 2, false, 1); + dukie_fly_spawn(npc); + if (Random() % DUKIE_SECOND_FLY_ODDS == 0) dukie_fly_spawn(npc); + } + if (!npc_anim_is_done(npc)) return; + } + + npc.state = NPC_STATE_MOVE; + npc.projectileCooldown = + npc.controllerID == -1 ? (int)(Random() % DUKIE_COOLDOWN_RANGE) + DUKIE_COOLDOWN : DUKIE_COOLDOWN; +} + +// 00541810 Dukie's AI: it bounces about the room and now and then coughs up dart flies. Confused, it wanders. +void npc_dukie_update(Entity_NPC& npc) +{ + if (npc.state == NPC_STATE_INIT) + { + npc.state = NPC_STATE_MOVE; + npc.entityGridCollisionClass = GRIDCOLL_WALLS; + npc.velocity = random_direction(); + npc.projectileCooldown = DUKIE_FIRST_COUGH; + return; + } + + npc.UpdateChargeBar(DUKIE_COUGH_BAR, 0, (float)npc.projectileCooldown, true); + npc.friction *= DUKIE_FRICTION; + if (npc.state == NPC_STATE_MOVE) + { + npc.sprite.Play("Idle"); + if (dukie_is_coughing(npc)) npc.state = NPC_STATE_ATTACK; + } + else if (npc.state == NPC_STATE_ATTACK) dukie_cough(npc); + + if (npc.projectileCooldown > 0) npc.projectileCooldown -= npc_ticks_get(npc); + if (npc.HasEntityFlags(FLAG_CONFUSION) && npc.controllerID == -1) + { + npc.pathfinder.MoveRandomly(STATUS_OBEYED); + return; + } + + Vector push = + vector_make(npc.velocity.x < 0 ? -DUKIE_PUSH : DUKIE_PUSH, npc.velocity.y < 0 ? -DUKIE_PUSH : DUKIE_PUSH); + if (npc.controllerID != -1) + { + Vector input = npc.GetControllerInput(0); + float steer = vector_length(push); + push = vector_make(steer * DUKIE_STEER_SHARE * input.x + push.x, push.y + steer * DUKIE_STEER_SHARE * input.y); + } + if (npc.friction == 0) return; + + npc.velocity.y += npc.speedMultiplier * push.y / npc.friction; + npc.velocity.x += npc.speedMultiplier * push.x / npc.friction; +} diff --git a/src/npc_eternal_fly.cpp b/src/npc_eternal_fly.cpp new file mode 100644 index 0000000..7d31df8 --- /dev/null +++ b/src/npc_eternal_fly.cpp @@ -0,0 +1,147 @@ +#include "npc_caves.h" +#include "entity_config.h" +#include "game.h" +#include "room.h" + +// An eternal fly orbits its spot: 25 by 20 around a parent at 0.04 turns of a half circle a frame, else 60 by 50 at +// 0.02. Its orbit widens over 90 frames (30 around a Keeper's Hanger) and it eases halfway there each frame (all the +// way around Isaac). +constexpr float ORBIT_RADIUS_X = 25; +constexpr float ORBIT_RADIUS_Y = 20; +constexpr float ORBIT_SPEED = 0.04f; +constexpr float WIDE_ORBIT_RADIUS_X = 60; +constexpr float WIDE_ORBIT_RADIUS_Y = 50; +constexpr float WIDE_ORBIT_SPEED = 0.02f; +constexpr int ORBIT_GROW_FRAMES = 90; +constexpr int HANGER_ORBIT_GROW_FRAMES = 30; +constexpr int ORBIT_PHASES = 10; +constexpr float ORBIT_EASE = 0.5f; +constexpr float ORBIT_FRICTION = 0.9f; +constexpr float FREED_ROOM_MARGIN = -10; + +// It hides (teleports out) while its parent shows no OverlayEffect. +static bool eternal_fly_is_hidden(Entity* parent) +{ + if (!parent) return false; + + const NullFrame* frame = parent->sprite.GetNullFrame("OverlayEffect"); + return !frame || !frame->isVisible; +} + +// Whether it is set free: its parent died or is gone, or (with none from the start) the grid entity at its spot broke. +static bool eternal_fly_is_freed(Entity_NPC& npc) +{ + Entity* parent = npc.parent; + if (parent) + { + npc.targetPosition = parent->pos; + npc.projectileDelay = 1; + return npc.state == NPC_STATE_SPECIAL || parent->isDead; + } + if (npc.state == NPC_STATE_SPECIAL || npc.projectileDelay == 1) return true; + + Room& room = *g_game->room; + int cell = room.GetGridIndex(npc.targetPosition); + if (cell < 0) return false; + + GridEntity* grid = room.GetGridEntity(cell); + return !grid || (grid->type == GRID_POOP && grid->collisionClass == COLLISION_NONE); +} + +// Set free, it becomes an attack fly, or vanishes when it never orbited or its spot left the room. +static void eternal_fly_free(Entity_NPC& npc) +{ + if (npc.i1 < 1 || !g_game->room->IsPositionInRoom(npc.targetPosition, FREED_ROOM_MARGIN)) return npc.Remove(); + + npc.entityGridCollisionClass = GRIDCOLL_WALLS; + npc.Morph(ENTITY_ATTACKFLY, 0, 0, -1); + npc.parent = nullptr; + npc.ClearEntityFlags(FLAG_NO_STATUS_EFFECTS | FLAG_HIDE_HP_BAR); + npc.isInvincible = false; + npc.entityCollisionClass = ENTCOLL_ALL; +} + +// Orbiting its spot, half of them the other way round, its orbit growing in from the spot. +static void eternal_fly_orbit(Entity_NPC& npc) +{ + Entity* parent = npc.parent; + bool isWide = !parent || parent->type == ENTITY_HANGER; + float speed = isWide ? WIDE_ORBIT_SPEED : ORBIT_SPEED; + float angle = (float)g_game->frameCount * speed * PI_F + (float)npc.stateFrame * PI_F / ORBIT_PHASES; + if ((npc.stateFrame & 1) == 0) angle = -angle; + + int growFrames = parent && parent->type == ENTITY_HANGER ? HANGER_ORBIT_GROW_FRAMES : ORBIT_GROW_FRAMES; + float growth = (float)std::min(npc.i1, growFrames) / (float)growFrames; + npc.i1++; + float ease = parent && parent->type == ENTITY_ISAAC_BOSS ? 1 : ORBIT_EASE; + float radiusX = isWide ? WIDE_ORBIT_RADIUS_X : ORBIT_RADIUS_X; + float radiusY = isWide ? WIDE_ORBIT_RADIUS_Y : ORBIT_RADIUS_Y; + Vector spot = vector_make(std::cos(angle) * radiusX * growth + npc.targetPosition.x, + std::sin(angle) * radiusY * growth + npc.targetPosition.y); + npc.pos = vector_add(vector_scale(vector_sub(spot, npc.pos), ease), npc.pos); +} + +// 0050a8a0 The eternal fly's AI: an invincible fly orbiting its parent, or the grid entity it was placed on, and hiding +// while the parent hides its OverlayEffect. It becomes an attack fly once its parent dies or its spot breaks. +void npc_eternal_fly_update(Entity_NPC& npc) +{ + if (npc.state == NPC_STATE_INIT) + { + npc.AddEntityFlags(FLAG_NO_STATUS_EFFECTS | FLAG_HIDE_HP_BAR); + npc.entityCollisionClass = ENTCOLL_PLAYEROBJECTS; + npc.entityGridCollisionClass = GRIDCOLL_NONE; + npc.isInvincible = true; + npc.state = NPC_STATE_MOVE; + npc.i1 = 0; + npc.projectileDelay = 0; + npc.i2 = 0; + npc.stateFrame = (int)(Random() % ORBIT_PHASES); + npc.targetPosition = npc.pos; + npc.ClearEntityFlags(FLAG_APPEAR); + } + + Entity* parent = npc.parent; + if (parent && parent->HasEntityFlags(FLAG_SHRINK) && !npc.HasEntityFlags(FLAG_SHRINK)) + { + npc.AddShrink(EntityRef(parent), parent->shrinkCountdown, true); + if (npc.shrinkCountdown > 0) + { + npc.AddEntityFlags(FLAG_SHRINK); + npc.shrinkStatus1 = npc.shrinkStatus2; + } + } + if (eternal_fly_is_freed(npc)) return eternal_fly_free(npc); + + bool isHidden = eternal_fly_is_hidden(npc.parent); + if (npc.state == NPC_STATE_MOVE) + { + npc.sprite.Play("Fly"); + if (isHidden) + { + npc.entityCollisionClass = ENTCOLL_NONE; + npc.state = NPC_STATE_JUMP; + npc.i1 = 0; + } + else eternal_fly_orbit(npc); + npc.friction *= ORBIT_FRICTION; + } + else if (npc.state == NPC_STATE_JUMP) + { + npc.sprite.Play("TeleportOut"); + npc.pos = npc.targetPosition; + if (npc_anim_is_done(npc)) npc.shadowSize = 0; + if (isHidden) return; + + npc.state = NPC_STATE_STOMP; + npc.shadowSize = npc.config->shadowSize; + } + else if (npc.state == NPC_STATE_STOMP) + { + npc.sprite.Play("TeleportIn"); + npc.pos = npc.targetPosition; + if (!npc_anim_is_done(npc)) return; + + npc.entityCollisionClass = ENTCOLL_PLAYEROBJECTS; + npc.state = NPC_STATE_MOVE; + } +} diff --git a/src/npc_fat_bat.cpp b/src/npc_fat_bat.cpp new file mode 100644 index 0000000..10d93f8 --- /dev/null +++ b/src/npc_fat_bat.cpp @@ -0,0 +1,138 @@ +#include "npc_caves.h" +#include "game.h" +#include "room_grid.h" +#include "sfx_manager.h" +#include + +// The Fat Bat flies 30 up, drifting at 0.45 a frame toward a line through its target along the diagonal it lies most +// along. Within 40 of that line and 750 of its target it shoots, one time in 15, every 30 frames at most. +constexpr float FAT_BAT_HEIGHT = -30; +constexpr float FAT_BAT_DRIFT = 0.45f; +constexpr float FAT_BAT_LINE_SHARE = 0.8f; +constexpr float FAT_BAT_AXIS_MIN = -50; +constexpr float FAT_BAT_FRICTION = 0.8f; +constexpr float FAT_BAT_LINED_UP_SQUARED = 1600; +constexpr float FAT_BAT_RANGE_SQUARED = 562500; +constexpr uint32_t FAT_BAT_SHOT_ODDS = 15; +constexpr int FAT_BAT_COOLDOWN = 30; +constexpr float FAT_BAT_SHOT_SPEED = 10; +constexpr float FAT_BAT_CONTROLLED_RANGE = 1000; +constexpr int FAT_BAT_RANGE_FRAMES = 7; +constexpr float FAT_BAT_DIAGONAL = 0.7071f; +constexpr std::array, 4> FAT_BAT_AXES = {{{-FAT_BAT_DIAGONAL, -FAT_BAT_DIAGONAL}, + {FAT_BAT_DIAGONAL, -FAT_BAT_DIAGONAL}, + {FAT_BAT_DIAGONAL, FAT_BAT_DIAGONAL}, + {-FAT_BAT_DIAGONAL, FAT_BAT_DIAGONAL}}}; + +// It dodges sideways from the tears within 100 flying toward it, more the nearer they are and the farther its +// target is (full strength from 100 out). Against a wall it bounces off twice as hard, one time in two. +constexpr float FAT_BAT_AVOID_RANGE = 100; +constexpr float FAT_BAT_AVOID_RANGE_SQUARED = 10000; +constexpr float FAT_BAT_AVOID_SHARE = 0.5f; + +// Dodging the tears heading at it. +static void fat_bat_avoid(Entity_NPC& npc, Vector toward) +{ + EntityList_EL nearby = entity_query_radius(npc.pos, FAT_BAT_AVOID_RANGE, QUERY_TEARS); + float targetShare = std::min(std::max(vector_length_squared(toward), 0.0f), FAT_BAT_AVOID_RANGE_SQUARED) / + FAT_BAT_AVOID_RANGE_SQUARED; + Vector avoid{}; + int count = 0; + for (Entity* other : nearby) + { + Vector away = vector_sub(npc.pos, other->pos); + if (vector_dot(other->velocity, away) <= 0) continue; + + float nearness = 1 - vector_length_squared(away) / FAT_BAT_AVOID_RANGE_SQUARED; + Vector side = vector_make(other->velocity.y, -other->velocity.x); + if (vector_dot(side, away) < 0) side = vector_scale(side, -1); + float length = vector_length(side); + if (length > 0) side = vector_scale(side, nearness * FAT_BAT_AVOID_SHARE * targetShare / length); + avoid = vector_add(side, avoid); + count++; + } + if (count == 0) return; + + Vector push = vector_make(avoid.x / (float)count, avoid.y / (float)count); + if (npc.isCollidesWithGrid && (Random() & 1) == 0) push = vector_make(-push.x + -push.x, -push.y + -push.y); + npc.velocity = vector_add(vector_scale(push, npc.speedMultiplier), npc.velocity); +} + +// Drifting toward its line along the diagonal its target lies most along, shooting once lined up. +static void fat_bat_drift(Entity_NPC& npc, Vector spot, Vector toward) +{ + size_t axis = 0; + float best = FAT_BAT_AXIS_MIN; + for (size_t i = 0; i < FAT_BAT_AXES.size(); i++) + { + float along = toward.y * FAT_BAT_AXES[i][1] + toward.x * FAT_BAT_AXES[i][0]; + if (along <= best) continue; + best = along; + axis = i; + } + + float along = FAT_BAT_AXES[axis][0] * toward.x + FAT_BAT_AXES[axis][1] * toward.y; + Vector line = vector_make(-(FAT_BAT_AXES[axis][0] * along), -(FAT_BAT_AXES[axis][1] * along)); + bool isLinedUp = npc.projectileCooldown == 0 && Random() % FAT_BAT_SHOT_ODDS == 0 && + vector_length_squared(vector_sub(vector_add(spot, line), npc.pos)) < FAT_BAT_LINED_UP_SQUARED && + vector_length_squared(toward) < FAT_BAT_RANGE_SQUARED; + if (isLinedUp) + { + npc.state = NPC_STATE_ATTACK; + npc.projectileCooldown = FAT_BAT_COOLDOWN; + } + + Vector move = vector_sub(vector_add(spot, vector_scale(line, FAT_BAT_LINE_SHARE)), npc.pos); + npc.velocity = vector_add(vector_scale(vector_resized(move, FAT_BAT_DRIFT), npc.speedMultiplier), npc.velocity); + fat_bat_avoid(npc, toward); +} + +// 00540510 The Fat Bat's AI: it hovers about its target along a diagonal and shoots at it once lined up. Controlled, +// it flies where steered and shoots in range. +void npc_fat_bat_update(Entity_NPC& npc) +{ + if (npc.state == NPC_STATE_INIT) + { + npc.state = NPC_STATE_MOVE; + npc.posOffset = vector_make(0, FAT_BAT_HEIGHT); + return; + } + + Vector spot = npc.CalcTargetPosition(0); + Vector toward = vector_sub(spot, npc.pos); + if (npc.state == NPC_STATE_MOVE) + { + npc.sprite.Play("Idle"); + if (npc.controllerID == -1) fat_bat_drift(npc, spot, toward); + else + { + Vector input = npc.GetControllerInput(0); + npc.velocity.x += input.x * FAT_BAT_DRIFT * npc.speedMultiplier; + npc.velocity.y += input.y * FAT_BAT_DRIFT * npc.speedMultiplier; + bool isInRange = npc.projectileCooldown == 0 && + npc.IsTargetInAttackRange(FAT_BAT_CONTROLLED_RANGE, FAT_BAT_RANGE_FRAMES, false); + if (isInRange) + { + npc.UpdateControllerMovement(true); + npc.state = NPC_STATE_ATTACK; + npc.projectileCooldown = FAT_BAT_COOLDOWN; + } + } + } + else if (npc.state == NPC_STATE_ATTACK) + { + npc.sprite.Play("Shooting"); + npc.UpdateControllerMovement(false); + if (npc.sprite.animState.animData && npc.sprite.animState.IsEventTriggered("Shoot")) + { + npc.state = NPC_STATE_MOVE; + Vector aim = vector_is_zero(npc.controllerMovement) ? toward : npc.controllerMovement; + ProjectileParams params; + npc.FireProjectiles(npc.pos, vector_resized(aim, FAT_BAT_SHOT_SPEED), PROJECTILES_SINGLE, params); + npc.PlaySound(SOUND_SHAKEY_KID_ROAR, 1, 2, false, 1); + } + } + + npc.friction *= FAT_BAT_FRICTION; + if (npc.projectileCooldown > 0) npc.projectileCooldown -= npc_ticks_get(npc); +} diff --git a/src/npc_gaper.cpp b/src/npc_gaper.cpp index b81c7ff..a5636d6 100644 --- a/src/npc_gaper.cpp +++ b/src/npc_gaper.cpp @@ -27,8 +27,6 @@ constexpr int FIREPLACE_MOVING = 10; constexpr int BLOOD_EXPLOSION_BEAM = 2; constexpr int SOUND_STONE_WALKER = 50; -constexpr int SOUND_MONSTER_ROAR_2 = 116; -constexpr int SOUND_STONESHOOT = 262; constexpr int LAYER_STONEY_CROSS = 1; constexpr int NULL_STONEY_CROSS = 2; @@ -508,7 +506,7 @@ static float gaper_speed_get(Entity_NPC& npc) // Its groan: a fatty's roar, a walking Stoney's grind at a random pitch (the Cross Stoney is silent), else the gaper's. static void gaper_groan(Entity_NPC& npc) { - if (is_fatty(npc)) npc.PlaySound(SOUND_MONSTER_ROAR_2, 1, GROAN_DELAY_LONG, false, 1); + if (is_fatty(npc)) npc.PlaySound(SOUND_MONSTER_ROAR_1, 1, GROAN_DELAY_LONG, false, 1); else if (npc.type != ENTITY_STONEY) npc.PlaySound(SOUND_ZOMBIE_WALKER_KID, 1, GROAN_DELAY, false, 1); else if (npc.state != NPC_STATE_SPECIAL && npc.variant != STONEY_CROSS) npc.PlaySound(SOUND_STONE_WALKER, 1, GROAN_DELAY_LONG, false, diff --git a/src/npc_gurgle.cpp b/src/npc_gurgle.cpp new file mode 100644 index 0000000..3a00b08 --- /dev/null +++ b/src/npc_gurgle.cpp @@ -0,0 +1,163 @@ +#include "npc_caves.h" +#include "boss_ai.h" +#include "entity_projectile.h" +#include "manager.h" +#include "sfx_manager.h" + +// The Gurgle's variants: the plain one, which may rise again as a Splasher, and the Crackle. +constexpr int GURGLE_CRACKLE = 1; +constexpr ColorMod GURGLE_SPLAT = {{0.5f, 0.5f, 0.5f, 1}, {0, 0, 0, 0}, {-0.19607845f, 0.50980395f, 0.19607845f}}; +constexpr ColorMod CRACKLE_SPLAT = {{0, 0, 0, 1.1f}, {0, 0, 0, 0}, {1, 0.5137255f, 0.003921569f}}; +constexpr ColorMod GURGLE_PUDDLE = {{0, 1, 0, 1}, {0, 0, 0, 0}, {0, 0.5f, 0}}; +constexpr ColorMod GURGLE_SHOT = {{1, 1, 1, 1}, {0.4f, 2, 0.5f, 1}, {0, 0, 0}}; +constexpr ColorMod CRACKLE_SHOT = {{1, 1, 1, 1}, {0, 0, 0, 0}, {1, 0.3f, 0}}; + +// Dying (unless blown apart past 25 overkill), a plain Gurgle rises again as a Splasher 15 times in 100, waiting 20 +// to 39 frames. Fire and blasts from its own side cannot hurt it. +constexpr float GURGLE_GIBBED_HEALTH = -25; +constexpr uint32_t GURGLE_RISE_ODDS = 100; +constexpr uint32_t GURGLE_RISE_CHANCE = 15; +constexpr int GURGLE_RISE_WAIT = 20; +constexpr uint64_t GURGLE_HARMLESS_DAMAGE = DAMAGE_FIRE | DAMAGE_EXPLOSION; + +// It walks its grid path at 0.6, dripping a puddle 0.2 to 0.7 big one time in ten, and groans now and then while it +// sees its target. One time in 60, within 130 of its target, it spits a big lobbed shot at 10. +constexpr uint32_t GURGLE_PUDDLE_ODDS = 10; +constexpr float GURGLE_PUDDLE_SIZE = 0.2f; +constexpr float GURGLE_PUDDLE_RANGE = 0.5f; +constexpr float GURGLE_PATH_SPEED = 0.6f; +constexpr float GURGLE_WALK_THRESHOLD = 0.1f; +constexpr float GURGLE_FEAR_FRICTION = 0.8f; +constexpr uint32_t GURGLE_GROAN_ODDS = 3; +constexpr int GURGLE_GROAN_DELAY = 40; +constexpr int CRACKLE_GROAN_DELAY = 120; +constexpr uint32_t GURGLE_SPIT_ODDS = 60; +constexpr float GURGLE_SPIT_RANGE_SQUARED = 16900; +constexpr float GURGLE_CONTROLLED_RANGE = 1000; +constexpr int GURGLE_RANGE_FRAMES = 7; +constexpr float GURGLE_DEADZONE = 0.1f; +constexpr float GURGLE_CONTROLLED_REACH = 150; +constexpr float GURGLE_SHOT_SPEED = 10; +constexpr float GURGLE_SHOT_SCALE = 1.6f; +constexpr float GURGLE_SHOT_SLOW = 0.55f; +constexpr float GURGLE_SHOT_ACCEL = 0.6f; +constexpr float GURGLE_SHOT_FALL_SHARE = 0.7f; +constexpr float GURGLE_SHOT_LIFT = 3; +constexpr float GURGLE_SPIT_SIDE = 8; +constexpr float GURGLE_SPIT_RISE = -15; +constexpr float GURGLE_SPIT_DROP = 2; +constexpr int GURGLE_SPIT_SUBTYPE = 2; +constexpr float GURGLE_ATTACK_FRICTION = 0.7f; + +// Walking: it drips, follows its grid path (or flees), groans, and starts its spit once its target is near. +static void gurgle_walk(Entity_NPC& npc) +{ + if (Random() % GURGLE_PUDDLE_ODDS == 0) + { + float size = random_unit() * GURGLE_PUDDLE_RANGE + GURGLE_PUDDLE_SIZE; + Entity* puddle = g_game->Spawn({.position = vector_make(npc.pos.x, npc.pos.y + 1), + .spawner = &npc, + .type = ENTITY_EFFECT, + .variant = EFFECT_BLOOD_SPLAT, + .seed = Random()}); + puddle->sprite.scale = vector_make(size, size); + puddle->SetColor(npc.variant == 0 ? GURGLE_PUDDLE : npc.splatColor, -1, COLOR_PRIORITY_DEFAULT, false, true); + puddle->Update(); + } + npc.AnimWalkFrame("WalkHori", "WalkHori", GURGLE_WALK_THRESHOLD); + + bool isControlled = npc.controllerID != -1; + if (!npc.HasEntityFlags(FLAG_FEAR | FLAG_SHRINK) || isControlled) + npc.pathfinder.FindGridPath(npc.CalcTargetPosition(0), GURGLE_PATH_SPEED, 0, DIRECT_PATH_FAR); + else + { + npc.pathfinder.EvadeTarget(npc.GetPlayerTarget()->pos, STATUS_OBEYED); + npc.friction *= GURGLE_FEAR_FRICTION; + } + + bool isGroaning = isControlled ? npc.IsControllerActionTriggered(CONTROLLER_ACTION_GROAN) + : npc.IsHostileTo(npc.GetPlayerTarget()) && npc.pathfinder.hasDirectPath && + Random() % GURGLE_GROAN_ODDS == 0; + if (isGroaning && npc.variant == 0) npc.PlaySound(SOUND_ZOMBIE_WALKER_KID, 1, GURGLE_GROAN_DELAY, false, 1); + else if (isGroaning && npc.variant == GURGLE_CRACKLE && Random() % GURGLE_GROAN_ODDS == 0) + npc.PlaySound(SOUND_ANGRY_GURGLE, 1, CRACKLE_GROAN_DELAY, false, 1); + npc.sprite.isFlipX = npc.velocity.x < 0; + + bool isReady = isControlled ? npc.IsTargetInAttackRange(GURGLE_CONTROLLED_RANGE, GURGLE_RANGE_FRAMES, false) + : Random() % GURGLE_SPIT_ODDS == 0; + if (!isReady || npc.spawnerType == ENTITY_HORNFEL || npc.HasEntityFlags(FLAG_DISTRACTED)) return; + + npc.UpdateControllerMovement(true); + Vector away = vector_sub(npc.pos, npc.GetPlayerTarget()->pos); + if (isControlled) away = npc.controllerMovement; + if (vector_length_squared(away) >= GURGLE_SPIT_RANGE_SQUARED) return; + + npc.stateFrame = 0; + npc.state = NPC_STATE_ATTACK; + npc_anim_restart(npc.sprite, "Attack"); + npc.sprite.isFlipX = away.x > 0; +} + +// The spit: a big lobbed shot at its target (or where its controller steers), a green one, or the Crackle's fiery one, +// with a burst at its mouth. +static void gurgle_spit(Entity_NPC& npc) +{ + Vector target = npc.GetPlayerTarget()->pos; + if (npc.controllerID != -1 && !vector_is_zero(npc.controllerMovement)) + target = vector_add(vector_scale(npc.controllerMovement, GURGLE_CONTROLLED_REACH), npc.pos); + npc.PlaySound(SOUND_HEARTOUT, 0.7f, 2, false, 1); + + ProjectileParams params; + Entity_Projectile* shot = npc.FireBossProjectiles(1, target, GURGLE_SHOT_SPEED, params); + shot->scale = GURGLE_SHOT_SCALE; + bool isCrackle = npc.variant == GURGLE_CRACKLE; + shot->projectileFlags |= isCrackle ? PROJECTILE_FIRE_WAVE : PROJECTILE_EXPLODE; + shot->SetColor(isCrackle ? CRACKLE_SHOT : GURGLE_SHOT, -1, COLOR_PRIORITY_DEFAULT, false, true); + + Vector mouth = vector_make(npc.sprite.isFlipX ? -GURGLE_SPIT_SIDE : GURGLE_SPIT_SIDE, GURGLE_SPIT_RISE); + const ColorMod& burst = isCrackle ? shot->sprite.color : GURGLE_SHOT; + blood_explosion_spawn(GURGLE_SPIT_SUBTYPE, vector_make(npc.pos.x, npc.pos.y + GURGLE_SPIT_DROP), mouth, burst, {}); + shot->fallingAccel -= GURGLE_SHOT_ACCEL; + shot->velocity = vector_scale(shot->velocity, GURGLE_SHOT_SLOW); + shot->fallingSpeed = shot->fallingSpeed * GURGLE_SHOT_FALL_SHARE - GURGLE_SHOT_LIFT; +} + +// 0051aaa0 The Gurgle's AI, for the Gurgle and the Crackle: it walks toward its target dripping puddles and spits a +// big lobbed shot when near. Its own side's fire and blasts spare it, and a Gurgle may rise again as it dies. +void npc_gurgle_update(Entity_NPC& npc) +{ + if (npc.state == NPC_STATE_INIT) + { + npc.state = NPC_STATE_MOVE; + npc.splatColor = npc.variant == GURGLE_CRACKLE ? CRACKLE_SPLAT : GURGLE_SPLAT; + return; + } + if (npc.isDead) + { + if (npc.health <= GURGLE_GIBBED_HEALTH || Random() % GURGLE_RISE_ODDS >= GURGLE_RISE_CHANCE) return; + if (npc.variant != 0) return; + + npc.Morph(ENTITY_SPLASHER, 0, 0, -1); + npc.isDead = false; + npc.health = npc.maxHitPoints; + npc.projectileCooldown = (int)(Random() % GURGLE_RISE_WAIT) + GURGLE_RISE_WAIT; + return; + } + + if (npc.pendingDamage > 0) npc_hostile_damage_ignore(npc, GURGLE_HARMLESS_DAMAGE); + if (npc.state == NPC_STATE_MOVE) return gurgle_walk(npc); + + if (npc.controllerID == -1) npc.controllerMovement = {}; + else + { + Vector input = npc.GetControllerMovementInput(GURGLE_DEADZONE); + if (!vector_is_zero(input)) npc.controllerMovement = input; + } + if (npc.sprite.animState.animData && npc.sprite.animState.IsEventTriggered("Shoot")) gurgle_spit(npc); + + npc.friction *= GURGLE_ATTACK_FRICTION; + if (!npc_anim_is_done(npc)) return; + + npc.state = NPC_STATE_MOVE; + npc_anim_loop(npc.sprite, "Idle"); +} diff --git a/src/npc_gusher.cpp b/src/npc_gusher.cpp index cc7a03a..1dc4484 100644 --- a/src/npc_gusher.cpp +++ b/src/npc_gusher.cpp @@ -6,7 +6,6 @@ // The headless enemies this AI runs: the Gusher and Pacer, Blubber and Half Sack, Splasher and the Black Globin's body. constexpr int ENTITY_HALF_SACK = 211; -constexpr int ENTITY_SPLASHER = 238; constexpr int SOUND_BLOBBY_WIGGLE = 3; constexpr float WALK_THRESHOLD_GUSHER = 0.1f; @@ -75,14 +74,14 @@ static void gusher_init(Entity_NPC& npc) if (is_bleeding_gusher(npc)) npc.sprite.PlayOverlay("Blood"); } -// A Splasher ignores explosions but the players' own, friendly ones' and TNT's. -static void splasher_explosions_ignore(Entity_NPC& npc) +// Cancels the pending damage of the given kinds, but the players' own, friendly ones' and TNT's. +void npc_hostile_damage_ignore(Entity_NPC& npc, uint64_t damageFlags) { for (DamageEvent& event : npc.damageEvents) { bool isPlayerMade = event.source.type == ENTITY_PLAYER || event.source.spawnerType == ENTITY_PLAYER || event.source.spawnerType == ENTITY_FAMILIAR; - if ((event.damageFlags & DAMAGE_EXPLOSION) && !(event.source.flags & ENTITY_REF_FRIENDLY) && !isPlayerMade && + if ((event.damageFlags & damageFlags) && !(event.source.flags & ENTITY_REF_FRIENDLY) && !isPlayerMade && !(event.damageFlags & DAMAGE_TNT)) event.damage = 0; } @@ -235,7 +234,7 @@ void npc_gusher_update(Entity_NPC& npc) npc.health = npc.maxHitPoints; return; } - if (npc.type == ENTITY_SPLASHER && npc.pendingDamage > 0) splasher_explosions_ignore(npc); + if (npc.type == ENTITY_SPLASHER && npc.pendingDamage > 0) npc_hostile_damage_ignore(npc, DAMAGE_EXPLOSION); npc.AnimWalkFrame("WalkHori", "WalkVert", WALK_THRESHOLD_GUSHER); if (is_bleeding_gusher(npc)) diff --git a/src/npc_hopper.cpp b/src/npc_hopper.cpp index 9d15297..39e8ccb 100644 --- a/src/npc_hopper.cpp +++ b/src/npc_hopper.cpp @@ -8,7 +8,6 @@ constexpr int ENTITY_KEEPER = 86; constexpr int ENTITY_RAGLING = 246; constexpr int ENTITY_MINISTRO = 305; constexpr int ENTITY_PON = 840; -constexpr int HOPPER_TRITE = 1; constexpr int HOPPER_EGGY = 2; constexpr int HOPPER_TAINTED = 3; constexpr int RAGLING_RAG_MAN = 1; diff --git a/src/npc_host.cpp b/src/npc_host.cpp index 31ef157..49293bf 100644 --- a/src/npc_host.cpp +++ b/src/npc_host.cpp @@ -55,7 +55,6 @@ constexpr float HOST_FRICTION = 0.7f; // The hard Host's slam: a crack wave toward its target, tooth shards, a shake, and a shove for players within 120. constexpr int SLAM_SOUND_DELAY = 10; -constexpr int EFFECT_CRACKWAVE = 72; constexpr int CRACKWAVE_SUBTYPE = 2; constexpr float CRACKWAVE_REACH = 20; constexpr int EFFECT_SHARD = 35; diff --git a/src/npc_one_tooth.cpp b/src/npc_one_tooth.cpp new file mode 100644 index 0000000..4e9efb2 --- /dev/null +++ b/src/npc_one_tooth.cpp @@ -0,0 +1,143 @@ +#include "npc_caves.h" +#include "game.h" +#include "room.h" +#include "sfx_manager.h" + +// One Tooth flies 20 up, circling its target at 0.85 of its distance (aimed 20 frames ahead) on a heading it turns +// every 20 frames, eased in at a tenth a frame (0.3 when controlled) toward 3 a frame. +constexpr float ONE_TOOTH_HEIGHT = -20; +constexpr uint32_t ONE_TOOTH_WAIT = 30; +constexpr int ONE_TOOTH_TURN_FRAMES = 20; +constexpr float ONE_TOOTH_ORBIT_SHARE = 0.85f; +constexpr float ONE_TOOTH_LEAD = 20; +constexpr float ONE_TOOTH_SPEED = 3; +constexpr float ONE_TOOTH_EASE = 0.1f; +constexpr float CONTROLLED_ONE_TOOTH_EASE = 0.3f; +constexpr float ONE_TOOTH_FACE_TURN = 40; +constexpr float ONE_TOOTH_CONTROL_REACH = 100; +constexpr float ONE_TOOTH_DEADZONE = 0.1f; + +// Its charge bar fills over 100 frames. Then, 80 to 160 from its target and every third frame one time in two, it +// dashes when its target lies within 0.98 of a diagonal 2 across by 1 down, for 20 frames pushed at 3.5. Tiny ones +// shriek higher and giant ones lower. +constexpr float ONE_TOOTH_CHARGE_FRAMES = 100; +constexpr float DASH_RANGE_MIN = 80; +constexpr float DASH_RANGE_MAX = 160; +constexpr int DASH_CHECK_FRAMES = 3; +constexpr float DASH_AIM_DOT = 0.98f; +constexpr float DASH_DIAGONAL_X = 100; +constexpr float DASH_DIAGONAL_Y = 50; +constexpr int DASH_FRAMES = 20; +constexpr float DASH_PUSH = 3.5f; +constexpr float DASH_FRICTION = 0.6f; +constexpr float TINY_SHRIEK_PITCH = 1.5f; +constexpr float GIANT_SHRIEK_PITCH = 0.5f; + +// Whether the dash direction lies along one of the four diagonals. +static bool one_tooth_is_aimed(Vector charge) +{ + Vector down = vector_normalized(vector_make(DASH_DIAGONAL_X, DASH_DIAGONAL_Y)); + Vector up = vector_make(down.x, -down.y); + return vector_dot(down, charge) > DASH_AIM_DOT || vector_dot(up, charge) > DASH_AIM_DOT || + -down.y * charge.y - down.x * charge.x > DASH_AIM_DOT || -up.y * charge.y - up.x * charge.x > DASH_AIM_DOT; +} + +// Whether it starts a dash: a lined-up target at the right range, or its controller's shot input. +static bool one_tooth_is_dashing(Entity_NPC& npc, Vector spot, Vector charge) +{ + if (npc.stateFrame <= ONE_TOOTH_CHARGE_FRAMES) return false; + if (npc.controllerID != -1) + { + return npc.IsControllerActionPressed(CONTROLLER_ACTION_SHOOT) && + !vector_is_zero(npc.GetControllerInput(ONE_TOOTH_DEADZONE)); + } + + float distance = vector_length(vector_sub(npc.pos, spot)); + return distance > DASH_RANGE_MIN && distance < DASH_RANGE_MAX && npc.stateFrame % DASH_CHECK_FRAMES == 0 && + (Random() & 1) != 0 && one_tooth_is_aimed(charge); +} + +// Circling: it turns its heading now and then, dashes once charged and lined up, and flies round its target facing +// the way it goes. +static void one_tooth_circle(Entity_NPC& npc, int ticks) +{ + npc.sprite.Play("Idle"); + for (int tick = 0; tick < ticks; tick++) + { + if (npc.stateFrame % ONE_TOOTH_TURN_FRAMES == 0) npc.v1 = random_direction(); + npc.stateFrame++; + } + npc.UpdateChargeBar(0, ONE_TOOTH_CHARGE_FRAMES, (float)npc.stateFrame, false); + + float orbit = vector_length(vector_sub(npc.pos, npc.GetPlayerTarget()->pos)) * ONE_TOOTH_ORBIT_SHARE; + Vector spot = npc.CalcTargetPosition(0); + Vector lead = vector_scale(npc.GetPlayerTarget()->velocity, ONE_TOOTH_LEAD); + Vector charge = vector_normalized(vector_sub(vector_add(lead, spot), npc.pos)); + if (npc.controllerID != -1) charge = vector_normalized(npc.GetControllerInput(ONE_TOOTH_DEADZONE)); + if (one_tooth_is_dashing(npc, spot, charge)) + { + float pitch = npc.championColorIdx == CHAMPION_TINY ? TINY_SHRIEK_PITCH + : npc.championColorIdx == CHAMPION_GIANT ? GIANT_SHRIEK_PITCH + : 1; + npc_sound_play(SOUND_SHAKEY_KID_ROAR, 1, 2, pitch); + npc.state = NPC_STATE_ATTACK; + npc.stateFrame = DASH_FRAMES; + npc.v2 = charge; + } + + lead = vector_scale(npc.GetPlayerTarget()->velocity, ONE_TOOTH_LEAD); + Vector move = vector_sub(vector_add(vector_add(lead, spot), vector_scale(npc.v1, orbit)), npc.pos); + if (npc.controllerID != -1) move = vector_scale(npc.GetControllerInput(0), ONE_TOOTH_CONTROL_REACH); + if (npc.sprite.isFlipX ? move.x > ONE_TOOTH_FACE_TURN : move.x < -ONE_TOOTH_FACE_TURN) + npc.sprite.isFlipX = !npc.sprite.isFlipX; + + // The original clamps the heading's x into the facing, which always lands on it. + Vector heading = vector_normalized(move); + heading.x = npc.sprite.isFlipX ? -1 : 1; + float ease = npc_friction_scaled(1 - (npc.controllerID == -1 ? ONE_TOOTH_EASE : CONTROLLED_ONE_TOOTH_EASE), + npc.speedMultiplier); + npc.velocity.x = (heading.x * ONE_TOOTH_SPEED - npc.velocity.x) * (1 - ease) + npc.velocity.x; + npc.velocity.y = (heading.y * ONE_TOOTH_SPEED - npc.velocity.y) * (1 - ease) + npc.velocity.y; +} + +// 005381c0 One Tooth's AI (the original's ENTITY_SKINBALL): it circles its target and, charged and lined up along a +// diagonal, dashes at it. Leaving the room's floor turns it round. +void npc_one_tooth_update(Entity_NPC& npc) +{ + int ticks = npc_ticks_get(npc); + int wait = (int)(Random() % ONE_TOOTH_WAIT); + if (npc.state == NPC_STATE_INIT) + { + npc.state = NPC_STATE_MOVE; + npc.entityGridCollisionClass = GRIDCOLL_NONE; + npc.posOffset = vector_make(0, ONE_TOOTH_HEIGHT); + npc.v1 = random_direction(); + npc.stateFrame = wait; + return; + } + + Room& room = *g_game->room; + Vector clamped = room.GetClampedPositionImpl(npc.pos, 0, 0, 0, 0); + if (clamped.x != npc.pos.x || clamped.y != npc.pos.y) + { + npc.stateFrame = wait; + npc.v1 = random_direction(); + npc.state = NPC_STATE_MOVE; + } + npc.pos = room.GetClampedPositionImpl(npc.pos, 0, 0, 0, 0); + if (npc.state == NPC_STATE_MOVE) return one_tooth_circle(npc, ticks); + if (npc.state != NPC_STATE_ATTACK) return; + + npc.sprite.Play("Dash"); + npc.friction *= DASH_FRICTION; + if (npc.friction != 0) + { + npc.velocity.y += npc.speedMultiplier * npc.v2.y * DASH_PUSH / npc.friction; + npc.velocity.x += npc.speedMultiplier * npc.v2.x * DASH_PUSH / npc.friction; + } + npc.stateFrame -= ticks; + if (npc.stateFrame >= 1) return; + + npc.state = NPC_STATE_MOVE; + npc.stateFrame = wait; +} diff --git a/src/npc_pitfall.cpp b/src/npc_pitfall.cpp new file mode 100644 index 0000000..3b2f036 --- /dev/null +++ b/src/npc_pitfall.cpp @@ -0,0 +1,210 @@ +#include "npc_caves.h" +#include "entity_config.h" +#include "entity_player.h" +#include "game.h" +#include "room.h" +#include "room_grid.h" + +// The Pitfall's variants: the plain one, the one sucking things in, the one dropping a player elsewhere in the room, +// and Hush's, which brings a Hush Gaper and sucks more gently. +enum PitfallVariant : int +{ + PITFALL_PLAIN, + PITFALL_SUCTION, + PITFALL_TELEPORT, + PITFALL_HUSH +}; + +// It lies on the floor, below everything, at half height. Its cell's grid path reads 900 unless already past 950. +constexpr int PITFALL_RENDER_Z = 3100; +constexpr float PITFALL_HEIGHT_SHARE = 0.5f; +constexpr int PITFALL_PATH_LIMIT = 951; +constexpr float HUSH_PITFALL_SUCTION = 0.55f; + +// The suction pulls players (at 0.6) and tears and shots (at 0.9), weakening to none 300 away. Twins within 52 are +// pulled from between them. +constexpr float SUCTION_PLAYER_PULL = 0.6f; +constexpr float SUCTION_SHOT_PULL = 0.9f; +constexpr float SUCTION_RANGE = 300; +constexpr float SUCTION_TWIN_RANGE_SQUARED = 2704; + +// A trapped player is drawn in at a tenth of the distance a frame. Pressed plates close it 5 frames on. +constexpr float TRAP_PULL = 0.1f; +constexpr float TRAP_FRICTION = 0.8f; +constexpr int PLATES_CLOSE_FRAMES = 5; + +// The first frame: it settles on the floor, kept off the walls, tinted like the floor. +static void pitfall_init(Entity_NPC& npc) +{ + npc.state = NPC_STATE_APPEAR_CUSTOM; + npc.entityCollisionClass = ENTCOLL_NONE; + npc.entityGridCollisionClass = GRIDCOLL_WALLS; + npc.sortingLayer = SORTING_BACKGROUND; + npc.renderZOffset = PITFALL_RENDER_Z; + npc.SetSize(npc.size, vector_make(1, PITFALL_HEIGHT_SHARE), npc.config->gridCollisionPoints); + npc.AddEntityFlags(FLAG_NO_STATUS_EFFECTS | FLAG_NO_TARGET | FLAG_NO_KNOCKBACK); + npc.pos = g_game->room->GetClampedPositionImpl(npc.pos, npc.size * 0.5f, npc.size, npc.size * 0.5f, npc.size); + npc.v1.x = 1; + npc.UpdateDirtColor(true); +} + +// Players walking over it (not flying) fall in, unless a Mega Mush holds them up. It keeps the last one trapped. +static void pitfall_trap(Entity_NPC& npc) +{ + PlayerManager& players = g_game->playerManager; + for (size_t i = 0; i < players.playerList.size(); i++) + { + Entity_Player& player = *players.GetPlayer((int)i); + float dx = player.pos.x / npc.sizeMulti.x - npc.pos.x / npc.sizeMulti.x; + float dy = player.pos.y / npc.sizeMulti.y - npc.pos.y / npc.sizeMulti.y; + int grid = player.entityGridCollisionClass; + bool isWalking = + grid != GRIDCOLL_NONE && grid != GRIDCOLL_WALLS && grid != GRIDCOLL_WALLS_X && grid != GRIDCOLL_WALLS_Y; + if (dy * dy + dx * dx >= npc.size * npc.size || !isWalking || player.pitfallState != 0) continue; + + if (!player.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_MEGA_MUSH)) + { + player.PlayExtraAnimation("FallIn"); + player.isControlsEnabled = false; + player.entityCollisionClass = ENTCOLL_NONE; + player.pitfallState = 1; + player.pitfallTimer = 0; + } + npc.state = NPC_STATE_SPECIAL; + npc.parent = &player; + npc.stateFrame = 0; + } +} + +// The suction: players, tears and enemy shots drift toward it, more strongly the nearer they are. +static void pitfall_suck(Entity_NPC& npc) +{ + for (Entity* entity : g_game->room->entityList.updateEL) + { + bool isPlayer = entity->type == ENTITY_PLAYER; + if (!isPlayer && entity->type != ENTITY_TEAR && entity->type != ENTITY_PROJECTILE) continue; + + Vector from = entity->pos; + Entity* twin = isPlayer ? static_cast(entity)->twinPlayer.get() : nullptr; + if (twin && vector_length_squared(vector_sub(from, twin->pos)) < SUCTION_TWIN_RANGE_SQUARED) + from = vector_make((from.x + twin->pos.x) * 0.5f, (from.y + twin->pos.y) * 0.5f); + + Vector pull = vector_normalized(vector_sub(npc.pos, from)); + float strength = (isPlayer ? SUCTION_PLAYER_PULL : SUCTION_SHOT_PULL) * npc.v1.x; + float distance = vector_length(vector_sub(npc.pos, entity->pos)); + float push = std::min(std::max((SUCTION_RANGE - distance) * strength / SUCTION_RANGE, 0.0f), strength); + if (entity->friction == 0) continue; + + entity->velocity.x += push * pull.x * entity->speedMultiplier / entity->friction; + entity->velocity.y += entity->speedMultiplier * push * pull.y / entity->friction; + } +} + +// Open: it traps players, sucks, and closes once it hits a wall, or 5 frames after the room's plates were pressed. +static void pitfall_open_update(Entity_NPC& npc) +{ + if (npc.variant != PITFALL_HUSH && npc.state == NPC_STATE_IDLE && !npc.HasEntityFlags(FLAG_FRIENDLY)) + pitfall_trap(npc); + if (npc.variant == PITFALL_SUCTION) pitfall_suck(npc); + if (npc.state != NPC_STATE_APPEAR_CUSTOM && npc.state != NPC_STATE_IDLE) return; + + if (npc.isCollidesWithGrid) npc.state = NPC_STATE_SUICIDE; + if (npc.stateFrame > 0) + { + if (--npc.stateFrame == 0) npc.state = NPC_STATE_SUICIDE; + } + else if (npc.stateFrame == 0 && + (g_game->GetCurrentRoomDesc()->flags & ROOM_DESCRIPTOR_FLAG_PRESSURE_PLATES_TRIGGERED)) + npc.stateFrame = PLATES_CLOSE_FRAMES; +} + +// A teleport pitfall closes over its player, moves to a free spot in the room, drops the player there and opens. +// Whether it goes on to check its player. +static bool pitfall_teleport_update(Entity_NPC& npc, Entity_Player* player) +{ + std::string_view animation = npc.sprite.animState.animData->name; + if (npc.sprite.animState.isPlaying) + { + if (animation == "Idle" && player && player->pitfallState == 2) npc_anim_loop(npc.sprite, "Disappear"); + return player; + } + + if (animation != "Disappear") return player; + if (!player) return false; + if (player->isDead) return true; + + Room& room = *g_game->room; + Vector spot = + room_free_pickup_position_find({.position = room.GetRandomPosition(0), .isAvoidActiveEntities = true}); + spot = room.GetClampedPositionImpl(spot, npc.size * 0.5f, npc.size, npc.size * 0.5f, npc.size); + npc.pos = spot; + player->Teleport(spot, false, false); + npc.velocity = {}; + npc_anim_loop(npc.sprite, "Appear"); + return true; +} + +// Holding a player: it draws the player in until the fall ends, then closes (a teleport pitfall once it reopened, or it +// hits a wall). +static void pitfall_hold_update(Entity_NPC& npc) +{ + npc.friction *= TRAP_FRICTION; + Entity_Player* player = npc.parent ? npc.parent->ToPlayer() : nullptr; + bool isTeleport = npc.variant == PITFALL_TELEPORT && npc.sprite.animState.animData; + if (isTeleport ? !pitfall_teleport_update(npc, player) : !player) return; + + if (player->pitfallState != 3 && player->pitfallState != 0 && !player->isDead) + { + player->velocity = vector_scale(vector_sub(npc.pos, player->pos), TRAP_PULL); + return; + } + if (npc.variant == PITFALL_TELEPORT) + { + bool isReopened = npc.sprite.animState.animData && !npc.sprite.animState.isPlaying && + npc.sprite.animState.animData->name == "Appear"; + if (!isReopened && !npc.isCollidesWithGrid) return; + } + npc.state = NPC_STATE_SUICIDE; +} + +// 00492550 The Pitfall's AI: a hole that opens in the floor and swallows players walking over it, sucking things in or +// dropping its player elsewhere by variant, and closes (removing itself) once it is done. +void npc_pitfall_update(Entity_NPC& npc) +{ + if (npc.state == NPC_STATE_INIT) pitfall_init(npc); + + Room& room = *g_game->room; + int cell = room.GetGridIndex(npc.pos); + if (cell >= 0 && room.GetGridPath(cell) < PITFALL_PATH_LIMIT) room.SetGridPath(cell, GRID_PATH_FREED); + + if (npc.state == NPC_STATE_APPEAR_CUSTOM) + { + npc_anim_loop(npc.sprite, "Appear"); + if (npc_anim_is_done(npc)) + { + npc.state = NPC_STATE_IDLE; + npc.entityCollisionClass = ENTCOLL_ENEMIES; + } + } + + if (npc.state == NPC_STATE_APPEAR_CUSTOM) pitfall_open_update(npc); + else if (npc.state == NPC_STATE_IDLE) + { + if (npc.variant == PITFALL_PLAIN || npc.variant == PITFALL_TELEPORT) npc_anim_loop(npc.sprite, "Idle"); + else if (npc.variant == PITFALL_SUCTION) npc_anim_loop(npc.sprite, "Suction"); + else if (npc.variant == PITFALL_HUSH) + { + npc.sprite.Play("Idle"); + g_game->Spawn({.position = npc.pos, .spawner = &npc, .type = ENTITY_HUSH_GAPER, .seed = Random()}); + npc.variant = PITFALL_SUCTION; + npc.v1.x = HUSH_PITFALL_SUCTION; + } + pitfall_open_update(npc); + } + else if (npc.state == NPC_STATE_SPECIAL) pitfall_hold_update(npc); + if (npc.state != NPC_STATE_SUICIDE) return; + + npc.friction *= TRAP_FRICTION; + npc_anim_loop(npc.sprite, "Disappear"); + if (npc_anim_is_done(npc)) npc.Remove(); +} diff --git a/src/npc_pustule.cpp b/src/npc_pustule.cpp new file mode 100644 index 0000000..99e012f --- /dev/null +++ b/src/npc_pustule.cpp @@ -0,0 +1,149 @@ +#include "npc_caves.h" +#include "boss_ai.h" +#include "room_grid.h" +#include + +// A Pustule swells through five stages, each a transition and then the next idle, once its counter passes 35 (one a +// tick, two one time in three). After the fifth it pops by itself. +constexpr int PUSTULE_STAGES = 5; +constexpr int PUSTULE_POPPED = 6; +constexpr int PUSTULE_SWELL_FRAMES = 35; +constexpr uint32_t PUSTULE_DOUBLE_ODDS = 3; +constexpr float PUSTULE_FRICTION = 0.7f; +constexpr std::array PUSTULE_IDLES = {"Idle1", "Idle2", "Idle3", "Idle4", "Idle5"}; +constexpr std::array PUSTULE_TRANSITIONS = { + "Transition0", "Transition1", "Transition2", "Transition3", "Transition4"}; + +// Its burst by stage: creep 1.4 to 1.7 times its scale lasting its frames, under a blood splat half to all its size, +// small maggots leaping up to 80 away (a blocked spot moves to a free cell within 64, give or take 19), and from the +// fourth stage a blood explosion 10 to 70 up. A popped one leaves a Bloodfly. +constexpr std::array PUSTULE_CREEP_SCALES = {0, 0, 0.2f, 0.3f, 0.3f, 0.3f, 1}; +constexpr std::array PUSTULE_CREEP_FRAMES = {0, 0, 50, 50, 70, 90, 125}; +constexpr std::array PUSTULE_MAGGOTS = {0, 0, 0, 0, 1, 1, 0}; +constexpr float PUSTULE_CREEP_SCALE_MIN = 1.4f; +constexpr float PUSTULE_CREEP_SCALE_RANGE = 0.3f; +constexpr float PUSTULE_SPLAT_SCALE_MIN = 0.5f; +constexpr float PUSTULE_SPLAT_SCALE_RANGE = 0.5f; +constexpr size_t PUSTULE_MAGGOT_CAP = 32; +constexpr float PUSTULE_MAGGOT_REACH = 80; +constexpr float PUSTULE_MAGGOT_FREE_RANGE = 64; +constexpr float PUSTULE_MAGGOT_SCATTER = 38; +constexpr float PUSTULE_MAGGOT_HEIGHT_MIN = -30; +constexpr float PUSTULE_MAGGOT_HEIGHT_RANGE = 15; +constexpr float PUSTULE_MAGGOT_START_RANGE = 15; +constexpr int PUSTULE_BURST_STAGE = 3; +constexpr float PUSTULE_BURST_RISE_MIN = -10; +constexpr float PUSTULE_BURST_RISE_RANGE = 60; +constexpr int PUSTULE_BURST_SUBTYPE = 3; +constexpr int PUSTULE_BLOODFLY = 6; + +// Swelling: once a transition ends it idles at the next stage (or pops after the last), and its counter starts the +// next transition. +static void pustule_swell(Entity_NPC& npc) +{ + if (npc_anim_is_done(npc)) + { + if (npc.i1 == PUSTULE_STAGES) + { + npc.i1 = PUSTULE_POPPED; + npc.Kill(EntityRef()); + return; + } + npc_anim_loop(npc.sprite, PUSTULE_IDLES[npc.i1++]); + } + + for (int tick = 0; tick < npc_ticks_get(npc); tick++) + { + npc.stateFrame++; + if (Random() % PUSTULE_DOUBLE_ODDS == 0) npc.stateFrame++; + if (npc.stateFrame <= PUSTULE_SWELL_FRAMES || npc.i1 >= PUSTULE_STAGES) continue; + + npc.stateFrame = 0; + npc_anim_loop(npc.sprite, PUSTULE_TRANSITIONS[npc.i1]); + return; + } +} + +// Its creep and blood splat. +static void pustule_creep_spawn(Entity_NPC& npc) +{ + float scale = PUSTULE_CREEP_SCALES[npc.i1] * (random_unit() * PUSTULE_CREEP_SCALE_RANGE + PUSTULE_CREEP_SCALE_MIN); + auto* creep = static_cast(g_game->Spawn( + {.position = npc.pos, .spawner = &npc, .type = ENTITY_EFFECT, .variant = EFFECT_CREEP_RED, .seed = Random()})); + creep->sprite.scale = vector_make(scale, scale); + creep->timeout = PUSTULE_CREEP_FRAMES[npc.i1]; + creep->lifespan = PUSTULE_CREEP_FRAMES[npc.i1]; + + Entity* splat = + g_game->Spawn({.position = npc.pos, .type = ENTITY_EFFECT, .variant = EFFECT_BLOOD_SPLAT, .seed = Random()}); + float splatScale = random_unit() * PUSTULE_SPLAT_SCALE_RANGE + PUSTULE_SPLAT_SCALE_MIN; + splat->sprite.scale = vector_make(splatScale * scale, splatScale * scale); + splat->Update(); +} + +// A small maggot leaping out to a random spot nearby, unless the room holds 32 already. Whether one leapt. +static bool pustule_maggot_spawn(Entity_NPC& npc) +{ + if (entity_query(ENTITY_SMALL_MAGGOT, -1).size() >= PUSTULE_MAGGOT_CAP) return false; + + Room& room = *g_game->room; + float angle = random_unit() * RANDOM_HALF_TURN; + angle += angle; + float reach = random_unit(); + Vector spot = vector_make(std::cos(angle) * reach * PUSTULE_MAGGOT_REACH + npc.pos.x, + std::sin(angle) * reach * PUSTULE_MAGGOT_REACH + npc.pos.y); + if (room.GetGridCollision(room.GetGridIndex(spot)) != 0) + { + Vector free = room_free_tile_position_find(spot, PUSTULE_MAGGOT_FREE_RANGE); + float offsetY = random_unit() * PUSTULE_MAGGOT_SCATTER - PUSTULE_MAGGOT_SCATTER / 2; + float offsetX = random_unit() * PUSTULE_MAGGOT_SCATTER - PUSTULE_MAGGOT_SCATTER / 2; + spot = vector_make(offsetX + free.x, offsetY + free.y); + } + + Vector direction = vector_normalized(vector_sub(spot, npc.pos)); + float height = random_unit() * PUSTULE_MAGGOT_HEIGHT_RANGE + PUSTULE_MAGGOT_HEIGHT_MIN; + float start = random_unit() * PUSTULE_MAGGOT_START_RANGE; + small_maggot_jump_spawn(vector_add(vector_scale(direction, start), npc.pos), height, spot); + return true; +} + +// Its burst as it dies, by the stage it reached. +static void pustule_burst(Entity_NPC& npc) +{ + if (PUSTULE_CREEP_SCALES[npc.i1] > 0 && !npc.HasEntityFlags(FLAG_SHRINK)) pustule_creep_spawn(npc); + for (int i = 0; i < PUSTULE_MAGGOTS[npc.i1]; i++) + if (!pustule_maggot_spawn(npc)) break; + if (npc.i1 <= PUSTULE_BURST_STAGE) return; + + float rise = PUSTULE_BURST_RISE_MIN - random_unit() * PUSTULE_BURST_RISE_RANGE; + int subType = (int)((Random() & 1) ^ 1) + PUSTULE_BURST_SUBTYPE; + blood_explosion_spawn(subType, npc.pos, vector_make(0, rise), npc.splatColor, {}); + if (npc.i1 != PUSTULE_POPPED) return; + + Entity* fly = g_game->Spawn( + {.position = npc.pos, .spawner = &npc, .type = ENTITY_SUCKER, .variant = PUSTULE_BLOODFLY, .seed = Random()}); + fly->ClearEntityFlags(FLAG_APPEAR); + fly->AddEntityFlags(FLAG_NO_REWARD); + fly->Update(); +} + +// 004dea40 The Pustule's AI: it sits still and swells through five stages until it pops. Dying, it bursts by its stage +// into creep, small maggots, blood and at last a Bloodfly. +void npc_pustule_update(Entity_NPC& npc) +{ + if (npc.state == NPC_STATE_INIT) + { + npc.i1 = 0; + npc.stateFrame = 0; + npc.state = NPC_STATE_IDLE; + npc.targetPosition = npc.pos; + npc_anim_loop(npc.sprite, "Idle0"); + npc.splatColor = COLOR_GREEN_SPLAT; + npc.ClearEntityFlags(FLAG_APPEAR); + } + else if (npc.state == NPC_STATE_IDLE) pustule_swell(npc); + + npc.friction *= PUSTULE_FRICTION; + npc.velocity = vector_sub(npc.targetPosition, npc.pos); + if (npc.isDead) pustule_burst(npc); +} diff --git a/src/npc_squirt.cpp b/src/npc_squirt.cpp new file mode 100644 index 0000000..1ee850f --- /dev/null +++ b/src/npc_squirt.cpp @@ -0,0 +1,224 @@ +#include "npc_caves.h" +#include "entity_effect.h" +#include "game.h" +#include "room.h" +#include "sfx_manager.h" + +// The Squirt's variants: the brown one that splits into dips, and the dank one that splits into clots, leaving black +// creep as it slides. +constexpr int SQUIRT_DANK = 1; +constexpr int CLOTTY_CLOT = 1; +constexpr ColorMod SQUIRT_SPLAT = {{0, 0, 0, 1}, {0, 0, 0, 0}, {0.25490198f, 0.16078432f, 0.13725491f}}; +constexpr ColorMod DANK_SQUIRT_SPLAT = {{0, 0, 0, 1}, {0, 0, 0, 0}, {0, 0, 0}}; + +// Idle, it waits for one of its frames of every 5 (one time in five) or its controller's input. +constexpr uint32_t SQUIRT_WAKE_ODDS = 5; +constexpr int SQUIRT_WAKE_FRAMES = 5; +constexpr float SQUIRT_DEADZONE = 0.1f; +constexpr float SQUIRT_FRICTION = 0.95f; +constexpr float SQUIRT_IDLE_FRICTION = 0.7f; + +// Its lunge on the Slide event at 20, then a slide pushed at half a unit a frame for 10 frames. A slide slower than 1 +// stops (and brakes under 3). A slide that hit walls five times, or the Splurt's past 40 frames (8 while aiming its +// second lunge), brakes harder. +constexpr float SQUIRT_LUNGE = 20; +constexpr float SQUIRT_SLIDE_PUSH = 0.5f; +constexpr float SQUIRT_SLIDE_FRAMES = 10; +constexpr float SQUIRT_STOP_SPEED_SQUARED = 1; +constexpr float SQUIRT_SLOW_SPEED_SQUARED = 9; +constexpr float SQUIRT_SLOW_FRICTION = 0.8f; +constexpr float SQUIRT_BRAKE_FRICTION = 0.85f; +constexpr int SQUIRT_WALL_HITS = 5; +constexpr float SPLURT_SLIDE_LIMIT = 40; +constexpr float SPLURT_AIM_LIMIT = 8; + +// It bleeds now and then. Dying, it splits in two 10 to each side, and the Splurt throws two drips 10 out at 4 to 6. +constexpr uint32_t SQUIRT_SPLAT_ODDS = 10; +constexpr float SQUIRT_SPLAT_SIZE = 0.2f; +constexpr float SQUIRT_SPLAT_RANGE = 0.5f; +constexpr float SQUIRT_SPLIT_OFFSET = 10; +constexpr float SPLURT_DRIP_SPEED = 4; +constexpr float SPLURT_DRIP_SPEED_RANGE = 2; + +// The dank one's black creep, every third frame of a slide, lasting 60. +constexpr int DANK_CREEP_FRAMES = 3; +constexpr int DANK_CREEP_TIMEOUT = 60; + +// Its split as it dies: two dips, two clots for the dank one, or two drips thrown out by the Splurt. +static void squirt_split(Entity_NPC& npc) +{ + if (npc.type == ENTITY_SPLURT) + { + for (int i = 0; i < 2; i++) + { + Vector direction = random_direction(); + Vector position = vector_add(vector_scale(direction, SQUIRT_SPLIT_OFFSET), npc.pos); + Entity* drip = + g_game->Spawn({.position = position, .spawner = &npc, .type = ENTITY_DRIP, .seed = Random()}); + float speed = random_unit() * SPLURT_DRIP_SPEED_RANGE + SPLURT_DRIP_SPEED; + if (drip->friction != 0) + { + drip->velocity.y += drip->speedMultiplier * direction.y * speed / drip->friction; + drip->velocity.x += drip->speedMultiplier * direction.x * speed / drip->friction; + } + drip->ClearEntityFlags(FLAG_APPEAR); + static_cast(drip)->state = NPC_STATE_MOVE; + drip->Update(); + } + return; + } + + bool isDank = npc.variant == SQUIRT_DANK; + for (float side : {SQUIRT_SPLIT_OFFSET, -SQUIRT_SPLIT_OFFSET}) + g_game->Spawn({.position = vector_make(npc.pos.x + side, npc.pos.y), + .spawner = &npc, + .type = isDank ? ENTITY_CLOTTY : ENTITY_DIP, + .variant = isDank ? CLOTTY_CLOT : 0, + .seed = Random()}); +} + +// Idle: once it wakes it lunges, or slides off at random when confused, or flees when feared. +static void squirt_idle_update(Entity_NPC& npc) +{ + npc.sprite.Play("Idle"); + bool isAwake = npc.controllerID == -1 + ? Random() % SQUIRT_WAKE_ODDS == 0 && npc.IsFrame(SQUIRT_WAKE_FRAMES, npc.index) + : !vector_is_zero(npc.GetControllerInput(SQUIRT_DEADZONE)); + if (isAwake) + { + bool isControlled = npc.controllerID != -1; + npc.i1 = 0; + if (!isControlled && npc.HasEntityFlags(FLAG_FEAR | FLAG_SHRINK)) + { + npc.v1.x = 0; + npc.state = NPC_STATE_MOVE; + npc.velocity = vector_sub(npc.CalcTargetPosition(1), npc.pos); + } + else if (!isControlled && npc.HasEntityFlags(FLAG_CONFUSION)) + { + npc.v1.x = 0; + npc.state = NPC_STATE_MOVE; + npc.velocity = random_direction(); + } + else npc.state = NPC_STATE_ATTACK; + } + npc.friction *= SQUIRT_IDLE_FRICTION; +} + +// Sliding: pushed along for 10 frames (v1.x counts them by its speed), then stopping once slow. The Splurt slides on +// into its second lunge. +static void squirt_slide_update(Entity_NPC& npc) +{ + npc.sprite.Play("Slide"); + bool isSplurt = npc.type == ENTITY_SPLURT; + if (isSplurt && npc.state == NPC_STATE_JUMP) npc.SpawnControlTarget(1, -1); + + float speedMultiplier = npc.speedMultiplier; + npc.v1.x += speedMultiplier; + if (npc.v1.x < SQUIRT_SLIDE_FRAMES) + { + Vector push = vector_resized(npc.velocity, SQUIRT_SLIDE_PUSH); + if (npc.friction != 0) + { + npc.velocity.x += speedMultiplier * push.x / npc.friction; + npc.velocity.y += speedMultiplier * push.y / npc.friction; + } + } + else + { + float speedSquared = vector_length_squared(npc.velocity); + if (isSplurt && speedSquared < SQUIRT_SLOW_SPEED_SQUARED) + npc.state = npc.state == NPC_STATE_JUMP ? NPC_STATE_ATTACK2 : NPC_STATE_IDLE; + else if (!isSplurt && speedSquared < SQUIRT_STOP_SPEED_SQUARED) npc.state = NPC_STATE_IDLE; + else if (!isSplurt && speedSquared < SQUIRT_SLOW_SPEED_SQUARED) npc.friction *= SQUIRT_SLOW_FRICTION; + } + + if (isSplurt) + { + float limit = npc.state == NPC_STATE_JUMP ? SPLURT_AIM_LIMIT : SPLURT_SLIDE_LIMIT; + if (npc.v1.x > limit) npc.friction *= SQUIRT_BRAKE_FRICTION; + return; + } + if (npc.isCollidesWithGrid) npc.i1++; + if (npc.i1 >= SQUIRT_WALL_HITS) npc.friction *= SQUIRT_BRAKE_FRICTION; +} + +// Lunging: on the Slide event it shoves itself at its target (or where its controller aims) and shouts. It slides +// once the animation ends. The second lunge's shove skips a frictionless Splurt. +static void squirt_lunge_update(Entity_NPC& npc, std::string_view animation, int slideState) +{ + npc.sprite.Play(animation); + npc.SpawnControlTarget(1, -1); + if (npc.sprite.IsEventTriggered("Slide")) + { + Vector direction = vector_normalized(vector_sub(npc.GetPlayerTarget()->pos, npc.pos)); + if (npc.controllerID != -1) + { + Vector aim = npc.GetAimTargetPosition(); + if (aim.x != npc.pos.x || aim.y != npc.pos.y) direction = vector_normalized(vector_sub(aim, npc.pos)); + } + if (npc.friction != 0 || npc.state == NPC_STATE_ATTACK) + { + npc.velocity.y += direction.y * SQUIRT_LUNGE / npc.friction; + npc.velocity.x += direction.x * SQUIRT_LUNGE / npc.friction; + } + npc.PlaySound(SOUND_CHILD_ANGRY_ROAR, 1, 100, false, 1); + } + if (!npc_anim_is_done(npc)) return; + + npc.v1.x = 0; + npc.state = slideState; +} + +// The dank one leaves black creep every third frame while sliding, or lunging once it left the ground. +static void dank_squirt_creep_update(Entity_NPC& npc) +{ + if (npc.HasEntityFlags(FLAG_INTERPOLATION_UPDATE) || g_game->IsPaused() || + g_game->frameCount % DANK_CREEP_FRAMES != 0) + return; + bool isSliding = + npc.state == NPC_STATE_MOVE || (npc.state == NPC_STATE_ATTACK && npc.sprite.WasEventTriggered("Slide")); + if (!isSliding) return; + + auto* creep = static_cast(g_game->Spawn({.position = npc.pos, + .spawner = &npc, + .type = ENTITY_EFFECT, + .variant = EFFECT_CREEP_BLACK, + .seed = Random()})); + creep->parent = &npc; + creep->sprite.scale = vector_make(1, 1); + creep->timeout = DANK_CREEP_TIMEOUT; + creep->lifespan = DANK_CREEP_TIMEOUT; + creep->Update(); +} + +// 00535280 The Squirt's AI, for the Squirt and the Splurt: it idles, then lunges at its target and slides along, +// splitting into two dips (clots for the dank one, drips for the Splurt) as it dies. The Splurt lunges twice. +void npc_squirt_update(Entity_NPC& npc) +{ + if (npc.state == NPC_STATE_INIT) + { + npc.state = NPC_STATE_IDLE; + npc.splatColor = npc.variant == SQUIRT_DANK ? DANK_SQUIRT_SPLAT : SQUIRT_SPLAT; + return; + } + + bool isOverWater = npc.type == ENTITY_SPLURT && g_game->room->waterAmount > 0; + npc.entityGridCollisionClass = isOverWater ? GRIDCOLL_NOPITS : GRIDCOLL_GROUND; + if (npc.isDead && npc.championRegenCount == 0) return squirt_split(npc); + + npc.friction *= SQUIRT_FRICTION; + int slideState = npc.type == ENTITY_SPLURT ? NPC_STATE_JUMP : NPC_STATE_MOVE; + if (npc.state == NPC_STATE_IDLE) squirt_idle_update(npc); + else if (npc.state == NPC_STATE_MOVE || npc.state == NPC_STATE_JUMP) squirt_slide_update(npc); + else if (npc.state == NPC_STATE_ATTACK) squirt_lunge_update(npc, "Attack01", slideState); + else if (npc.state == NPC_STATE_ATTACK2) squirt_lunge_update(npc, "Attack02", NPC_STATE_MOVE); + + if (Random() % SQUIRT_SPLAT_ODDS == 0) + npc.MakeSplat(random_unit() * SQUIRT_SPLAT_RANGE + SQUIRT_SPLAT_SIZE) + ->SetColor(npc.splatColor, -1, COLOR_PRIORITY_DEFAULT, false, true); + npc.sprite.isFlipX = npc.velocity.x < 0; + if (npc.state == NPC_STATE_ATTACK2 && npc.controllerID == -1) + npc.sprite.isFlipX = npc.GetPlayerTarget()->pos.x < npc.pos.x; + if (npc.variant == SQUIRT_DANK) dank_squirt_creep_update(npc); +} diff --git a/src/npc_stone_shooter.cpp b/src/npc_stone_shooter.cpp new file mode 100644 index 0000000..687328e --- /dev/null +++ b/src/npc_stone_shooter.cpp @@ -0,0 +1,178 @@ +#include "npc_caves.h" +#include "room_descriptor.h" +#include "game.h" +#include "room.h" +#include "sfx_manager.h" + +// The stone shooters: the one firing a stone along its facing (its subtype: left, up, right or down), and the cross +// ones turning between a plus and a cross of shots (their subtype the next), one shutting once the room's enemies are +// gone and one always on. +constexpr int CROSS_SHOOTER = 10; +constexpr int CROSS_SHOOTER_ALWAYS = 11; + +// A stone shooter fills its cell and wakes every 20 frames (22 for the cross ones). Its stones fly at 7 from its +// Bullet null, 13 up and arcing, a little faster. The cross ones fire at 10. +constexpr int STONE_SHOOTER_PATH = 3999; +constexpr int STONE_SHOOTER_COOLDOWN = 20; +constexpr int CROSS_SHOOTER_COOLDOWN = 22; +constexpr float STONE_SPEED = 7; +constexpr float STONE_HEIGHT = 13; +constexpr float STONE_FALL_ACCEL = 0.101f; +constexpr float STONE_VELOCITY_SCALE = 1.07f; +constexpr float BULLET_NULL_SCALE = 0.65f; +constexpr float CROSS_SHOT_SPEED = 10; +constexpr ColorMod STONE_SHOOTER_SPLAT = {{1, 1, 1, 1}, {1, 1, 1, 1}, {0, 0, 0}}; + +constexpr std::array STONE_SHOTS = {"ShootLeft", "ShootUp", "ShootRight", + "ShootDown"}; +constexpr std::array STONE_IDLES = {"IdleLeft", "IdleUp", "IdleRight", + "IdleDown"}; + +// The idle it rests in after a shot. The original swaps the horizontal and vertical ones, kept here. +constexpr std::array STONE_REST_IDLES = {"IdleDown", "IdleUp", "IdleLeft", + "IdleRight"}; + +// Whether a cross shooter shuts: the room's plates were pressed, or (unless always on) the fight is over. +static bool cross_shooter_is_done(Entity_NPC& npc) +{ + if (g_game->GetCurrentRoomDesc()->flags & ROOM_DESCRIPTOR_FLAG_PRESSURE_PLATES_TRIGGERED) return true; + return npc.variant == CROSS_SHOOTER && npc.GetAliveEnemyCount() < 1 && g_game->room->roomClearDelay < 1; +} + +// A cross shooter's animation for its next shot pattern (1 the plus, 2 the cross), played anew. +static void cross_shooter_play(Entity_NPC& npc, std::string_view name) +{ + npc_anim_restart(npc.sprite, std::string(name) + (npc.subtype != 0 ? "2" : "1")); +} + +// The first frame: it sits invincible in its cell, faces its subtype and waits, shut already where the room says so. +static void stone_shooter_init(Entity_NPC& npc) +{ + npc.pathfinder.UpdateGridIndex(); + npc.isInvincible = true; + npc.aiCallFlags = AI_CALL_PRE_UPDATE; + npc.targetPosition = g_game->room->GetGridPosition(npc.pathfinder.gridIndex); + npc.AddEntityFlags(FLAG_NO_STATUS_EFFECTS | FLAG_NO_PHYSICS_KNOCKBACK | FLAG_HIDE_HP_BAR | FLAG_NO_PLAYER_CONTROL); + if (npc.subtype >= 0 && npc.subtype < PATH_DIRECTION_COUNT) npc.v1 = vector_from_direction(npc.subtype); + npc.state = NPC_STATE_IDLE; + + bool isCross = npc.variant == CROSS_SHOOTER || npc.variant == CROSS_SHOOTER_ALWAYS; + npc.projectileCooldown = isCross ? CROSS_SHOOTER_COOLDOWN : STONE_SHOOTER_COOLDOWN; + bool isShut = isCross ? cross_shooter_is_done(npc) + : (g_game->GetCurrentRoomDesc()->flags & ROOM_DESCRIPTOR_FLAG_PRESSURE_PLATES_TRIGGERED); + if (isShut) + { + if (isCross) cross_shooter_play(npc, "ClosedEyes"); + else npc.sprite.Play("ClosedEyes"); + npc.ClearEntityFlags(FLAG_APPEAR); + npc.state = NPC_STATE_SPECIAL; + } + npc.splatColor = STONE_SHOOTER_SPLAT; +} + +// Waiting: it idles until its cooldown runs out, then shoots. +static void stone_shooter_idle(Entity_NPC& npc) +{ + if (npc.variant == CROSS_SHOOTER || npc.variant == CROSS_SHOOTER_ALWAYS) + { + npc_anim_loop(npc.sprite, npc.subtype != 0 ? "Idle2" : "Idle1"); + if (npc.projectileCooldown < 1) + { + npc.state = NPC_STATE_ATTACK; + cross_shooter_play(npc, "ShootAndRotate"); + } + } + else + { + bool isFacing = npc.subtype >= 0 && npc.subtype < PATH_DIRECTION_COUNT; + if (npc_anim_is_done(npc) && isFacing) npc.sprite.Play(STONE_IDLES[npc.subtype]); + if (npc.projectileCooldown < 1) + { + npc.state = NPC_STATE_ATTACK; + if (isFacing) npc.sprite.Play(STONE_SHOTS[npc.subtype]); + } + } + if (npc.projectileCooldown > 0) npc.projectileCooldown -= npc_ticks_get(npc); +} + +// A cross shooter's volley: a plus or cross of shots on the Shoot event, turning to the other pattern once done, and +// shutting once it is done for good. +static void cross_shooter_attack(Entity_NPC& npc) +{ + bool isOver = !npc.sprite.animState.animData; + if (!isOver) + { + if (npc.sprite.animState.IsEventTriggered("Shoot")) + { + npc.PlaySound(SOUND_STONESHOOT, 1, 0, false, 1); + ProjectileParams params; + ProjectilesMode mode = npc.subtype != 0 ? PROJECTILES_CROSS : PROJECTILES_PLUS; + npc.FireProjectiles(npc.pos, vector_make(CROSS_SHOT_SPEED, 0), mode, params); + } + isOver = npc_anim_is_done(npc); + } + if (isOver) + { + npc.state = NPC_STATE_IDLE; + npc.subtype = npc.subtype == 0; + } + if (!cross_shooter_is_done(npc)) return; + + cross_shooter_play(npc, "CloseEyes"); + npc.state = NPC_STATE_SPECIAL; +} + +// A stone shooter's shot: an arcing stone along its facing on the Shoot event, idling again once done, and shutting +// once the room's plates are pressed. +static void stone_shooter_attack(Entity_NPC& npc) +{ + ProjectileParams params; + params.fallingAccelModifier -= STONE_FALL_ACCEL; + params.heightModifier = STONE_HEIGHT; + params.velocityMulti *= STONE_VELOCITY_SCALE; + if (npc.sprite.IsEventTriggered("Shoot")) + { + const NullFrame* bullet = npc.sprite.GetNullFrame("Bullet"); + Vector offset = + bullet ? vector_make(bullet->pos.x / BULLET_NULL_SCALE, bullet->pos.y / BULLET_NULL_SCALE) : Vector{}; + npc.FireProjectiles(vector_add(offset, npc.pos), vector_scale(npc.v1, STONE_SPEED), PROJECTILES_SINGLE, params); + npc.PlaySound(SOUND_STONESHOOT, 1, 2, false, 1); + } + if (npc_anim_is_done(npc)) + { + npc.state = NPC_STATE_IDLE; + if (npc.subtype >= 0 && npc.subtype < PATH_DIRECTION_COUNT) npc.sprite.Play(STONE_REST_IDLES[npc.subtype]); + } + if (!(g_game->GetCurrentRoomDesc()->flags & ROOM_DESCRIPTOR_FLAG_PRESSURE_PLATES_TRIGGERED)) return; + + npc.sprite.Play("CloseEyes"); + npc.state = NPC_STATE_SPECIAL; +} + +// 00506320 The stone shooter's AI: a block in the wall's line firing stones along its facing, or turning between +// a plus and a cross of shots, until the room's plates are pressed (or the fight ends). It keeps its cell blocked and +// its spot fixed, and dying, it keeps its cell from spawning again. +void npc_stone_shooter_update(Entity_NPC& npc) +{ + if (npc.aiCallPhase == AI_PHASE_PRE_UPDATE) + { + if (!npc.minecart && !npc.isDead && npc.pathfinder.gridIndex >= 0) + g_game->room->SetGridPath(npc.pathfinder.gridIndex, STONE_SHOOTER_PATH); + return; + } + + bool isCross = npc.variant == CROSS_SHOOTER || npc.variant == CROSS_SHOOTER_ALWAYS; + if (npc.state == NPC_STATE_INIT) stone_shooter_init(npc); + else if (npc.state == NPC_STATE_IDLE) stone_shooter_idle(npc); + else if (npc.state == NPC_STATE_ATTACK && isCross) cross_shooter_attack(npc); + else if (npc.state == NPC_STATE_ATTACK) stone_shooter_attack(npc); + else if (npc.state == NPC_STATE_SPECIAL && npc_anim_is_done(npc)) + { + if (isCross) cross_shooter_play(npc, "ClosedEyes"); + else npc.sprite.Play("ClosedEyes"); + } + + if (npc.isDead && npc.spawnGridIndex >= 0) + g_game->GetRoomByIdx(g_game->currentRoomIdx, -1)->restrictedGridIndexes.insert(npc.spawnGridIndex); + npc.velocity = vector_sub(npc.targetPosition, npc.pos); +} diff --git a/src/npc_stonehead.cpp b/src/npc_stonehead.cpp new file mode 100644 index 0000000..b3b605c --- /dev/null +++ b/src/npc_stonehead.cpp @@ -0,0 +1,281 @@ +#include "boss_ai.h" +#include "entity_projectile.h" +#include "entity_laser.h" +#include "entity_player.h" +#include "npc_caves.h" +#include "room_descriptor.h" +#include "sfx_manager.h" +#include +#include + +// The Stone Grimace's vomiting and triple variants. +constexpr int GRIMACE_VOMIT = 1; +constexpr int GRIMACE_TRIPLE = 2; + +// A face holds its cell for the paths (3999) and stays shut once it closes (state 16). +constexpr int STONEHEAD_GRID_PATH = 3999; +constexpr int STONEHEAD_SHUT = NPC_STATE_SPECIAL; + +// The Broken Gaping Maw breathes in for 150 frames of every 240. +constexpr int BROKEN_MAW_CYCLE = 240; +constexpr int BROKEN_MAW_BREATH = 150; + +// A Gaping Maw pulls players (0.6 at most), tears and shots (0.9) within 300, harder the closer, and a close twin +// pulls the player from between them. +constexpr float SUCK_REACH = 300; +constexpr float SUCK_PLAYER = 0.6f; +constexpr float SUCK_SHOT = 0.9f; +constexpr float TWIN_REACH_SQUARED = 2704; + +// A Brimstone Head fires a 15 frame beam its way every 90 frames once the room ran a second, after a red warning. +constexpr std::array BRIMSTONE_IDLE = {"IdleLeft", "IdleUp", "IdleRight", "IdleDown"}; +constexpr std::array BRIMSTONE_SHOOT = {"ShootLeft", "ShootUp", "ShootRight", "ShootDown"}; +constexpr uint32_t BRIMSTONE_DIRECTIONS_LAST = 3; +constexpr int BRIMSTONE_SETTLE_FRAMES = 30; +constexpr int BRIMSTONE_PERIOD = 90; +constexpr int BRIMSTONE_LASER_VARIANT = 1; +constexpr int BRIMSTONE_LASER_TIMEOUT = 15; +constexpr float BRIMSTONE_NULL_SCALE = 0.65f; +constexpr float BRIMSTONE_DEPTH = 10; +constexpr ColorMod BRIMSTONE_WARNING_COLOR = {{0.6f, 0.05f, 0, 0.8f}, {0, 0, 0, 0}, {0, 0, 0}}; +constexpr float BRIMSTONE_WARNING_HEIGHT = -6; +constexpr int BRIMSTONE_WARNING_FRAMES = 26; +constexpr float BRIMSTONE_WARNING_SCALE = 4; + +// A Stone Grimace shoots a target within 200 every 84 frames, 7 fast (10 in hard mode), lobbed a little; the vomiting +// one lobs a big green explosive shot, the triple one fans three. +constexpr float GRIMACE_RANGE = 200; +constexpr int GRIMACE_COOLDOWN = 84; +constexpr float GRIMACE_SHOT_SPEED = 7; +constexpr float GRIMACE_SHOT_SPEED_HARD = 10; +constexpr float GRIMACE_SHOT_HEIGHT = 13; +constexpr float GRIMACE_SHOT_FALL = 0.101f; +constexpr float VOMIT_SPEED_SCALE = 0.55f; +constexpr float VOMIT_SCALE = 1.6f; +constexpr float VOMIT_FALL_SPEED = -30.5f; +constexpr float VOMIT_FALL_ACCEL = 0.92f; +// The grey a face splats, and the vomit's green. +constexpr ColorMod STONEHEAD_SPLAT_COLOR = {{1, 1, 1, 1}, {1, 1, 1, 1}, {0, 0, 0}}; +constexpr std::array VOMIT_COLORIZE = {0.4f, 2, 0.5f, 1}; + +// The cell a face sits in, centered. +static Vector cell_center_get(int gridIndex) +{ + int width = g_game->room->gridWidth; + return vector_make((float)(gridIndex % width) * GRID_CELL_SIZE + GRID_ORIGIN_X, + (float)(gridIndex / width) * GRID_CELL_SIZE + GRID_ORIGIN_Y); +} + +// The first frame: it takes its cell, cannot be hurt, keeps its spot and splats grey. A Gaping Maw starts breathing in. +static void stonehead_init(Entity_NPC& npc) +{ + npc.pathfinder.UpdateGridIndex(); + npc.isInvincible = true; + npc.aiCallFlags = 1; + npc.targetPosition = cell_center_get(npc.pathfinder.gridIndex); + npc.AddEntityFlags(FLAG_NO_STATUS_EFFECTS | FLAG_NO_PHYSICS_KNOCKBACK | FLAG_HIDE_HP_BAR); + if (npc.type != ENTITY_STONEHEAD) npc.AddEntityFlags(FLAG_NO_PLAYER_CONTROL); + npc.state = NPC_STATE_IDLE; + if (npc.type == ENTITY_GAPING_MAW) + { + npc.sprite.Play("Effect"); + npc.sprite.PlayOverlay("Sucking"); + } + npc.splatColor = STONEHEAD_SPLAT_COLOR; +} + +// Shuts the face for good with an animation, shown at its end when it was shut from the start. +static void stonehead_shut(Entity_NPC& npc, std::string_view animation, bool isFirstFrame) +{ + npc.state = STONEHEAD_SHUT; + npc.sprite.overlayAnimState.SetAnimationData(nullptr); + npc.sprite.Play(animation); + if (!isFirstFrame) return; + + npc.ClearEntityFlags(FLAG_APPEAR); + npc.sprite.SetLastFrame(); +} + +// Whether the face works this frame. A Gaping Maw stops for the pressure plates, a Broken one breathes on its cycle, +// and the others close their eyes once the room is clear or the plates are pressed (a Brimstone Head only for the +// plates). +static bool stonehead_is_active(Entity_NPC& npc, bool isPressed, bool isFirstFrame) +{ + if (npc.type == ENTITY_GAPING_MAW) + { + if (!isPressed) return true; + if (npc.state != STONEHEAD_SHUT) stonehead_shut(npc, "TurnOff", isFirstFrame); + return false; + } + if (npc.type == ENTITY_BROKEN_GAPING_MAW) + { + int cycle = npc.stateFrame % BROKEN_MAW_CYCLE; + bool isTurnOff = isPressed || (cycle == BROKEN_MAW_BREATH); + if (cycle == 0 && !isPressed) npc.sprite.Play("TurnOn"); + else if (isTurnOff && npc.state != STONEHEAD_SHUT) + { + if (isPressed) npc.state = STONEHEAD_SHUT; + npc.sprite.overlayAnimState.SetAnimationData(nullptr); + npc.sprite.Play("TurnOff"); + if (isFirstFrame) + { + npc.ClearEntityFlags(FLAG_APPEAR); + npc.sprite.SetLastFrame(); + } + } + const AnimationData* shown = npc.sprite.animState.animData; + if (shown && !npc.sprite.animState.isPlaying && shown->name == "TurnOn") + { + npc.sprite.Play("Effect"); + npc.sprite.PlayOverlay("Sucking"); + } + const AnimationData* overlay = npc.sprite.overlayAnimState.animData; + return overlay && npc.sprite.overlayAnimState.isPlaying && overlay->name == "Sucking"; + } + + if (npc.type != ENTITY_BRIMSTONE_HEAD && npc.state == STONEHEAD_SHUT) return false; + + bool isWorking = npc.type == ENTITY_BRIMSTONE_HEAD || npc.GetAliveEnemyCount() > 0 || + g_game->room->roomClearDelay > 0; + if (isWorking && !isPressed) return true; + if (npc.state != STONEHEAD_SHUT) stonehead_shut(npc, "CloseEyes", isFirstFrame); + return false; +} + +// A Gaping Maw draws players, tears and enemy shots toward it. +static void gaping_maw_suck(Entity_NPC& npc) +{ + EntityList_EL& entities = g_game->room->entityList.updateEL; + for (size_t i = 0; i < entities.size(); i++) + { + Entity& entity = *entities[i]; + bool isPulled = entity.type == ENTITY_PLAYER || entity.type == ENTITY_TEAR || entity.type == ENTITY_PROJECTILE; + if (entity.isDead || !isPulled) continue; + + Vector from = entity.pos; + Entity_Player* twin = entity.type == ENTITY_PLAYER ? static_cast(entity).twin_get() : nullptr; + if (twin && vector_length_squared(vector_sub(from, twin->pos)) < TWIN_REACH_SQUARED) + from = vector_scale(vector_add(from, twin->pos), 0.5f); + Vector toMaw = vector_normalized(vector_sub(npc.pos, from)); + float strength = entity.type == ENTITY_PLAYER ? SUCK_PLAYER : SUCK_SHOT; + float distance = vector_length(vector_sub(npc.pos, entity.pos)); + float pull = std::clamp((SUCK_REACH - distance) * strength / SUCK_REACH, 0.0f, strength); + if (entity.friction != 0) + entity.velocity = vector_add(entity.velocity, vector_scale(toMaw, entity.speedMultiplier * pull / entity.friction)); + } +} + +// A Brimstone Head looks its way, and every 90 frames warns and fires its beam, kept as its target until it ends. +static void brimstone_head_update(Entity_NPC& npc) +{ + if ((uint32_t)npc.subtype > BRIMSTONE_DIRECTIONS_LAST) + KAGE_LogMessage(LOG_ASSERT, (uint8_t*)"Brimstone Head can only have 0-3 subtypes!"); + uint32_t direction = std::min((uint32_t)npc.subtype, BRIMSTONE_DIRECTIONS_LAST); + float angle = (float)npc.subtype * 90 - 180; + + if (npc.state == NPC_STATE_IDLE) + { + npc.sprite.Play(BRIMSTONE_IDLE[direction]); + Room& room = *g_game->room; + int frames = g_game->frameCount - room.enterFrame; + if (!room.isInitialized || frames <= BRIMSTONE_SETTLE_FRAMES || frames % BRIMSTONE_PERIOD != 0) return; + + npc.state = NPC_STATE_ATTACK; + following_effect_spawn(npc, {.offset = vector_make(0, BRIMSTONE_WARNING_HEIGHT), + .targetPosition = vector_from_angle(angle), + .color = BRIMSTONE_WARNING_COLOR, + .scale = BRIMSTONE_WARNING_SCALE, + .timeout = BRIMSTONE_WARNING_FRAMES}); + return; + } + if (npc.state != NPC_STATE_ATTACK) return; + + npc.sprite.Play(BRIMSTONE_SHOOT[direction]); + if (npc.sprite.IsEventTriggered("Shoot")) + { + const NullFrame* laserPos = npc.sprite.GetNullFrame("LaserPos"); + Vector offset = vector_scale(laserPos->pos, 1 / BRIMSTONE_NULL_SCALE); + Entity_Laser* laser = Entity_Laser::ShootAngle({.position = npc.pos, + .posOffset = offset, + .source = &npc, + .angleDegrees = angle, + .timeout = BRIMSTONE_LASER_TIMEOUT, + .variant = BRIMSTONE_LASER_VARIANT}); + laser->renderDepthOffset = npc.subtype == 1 ? -BRIMSTONE_DEPTH : BRIMSTONE_DEPTH; + laser->Update(); + npc.target = laser; + } + if (npc_anim_is_done(npc) && !npc.target) npc.state = NPC_STATE_IDLE; +} + +// A Stone Grimace's shot at its target: a vomiting one lobs a big green explosive blob, a triple one fans three. +static void grimace_shoot(Entity_NPC& npc) +{ + npc.PlaySound(SOUND_STONESHOOT, 1, 2, false, 1); + ProjectileParams params; + params.fallingAccelModifier -= GRIMACE_SHOT_FALL; + params.heightModifier = GRIMACE_SHOT_HEIGHT; + if (npc.variant == GRIMACE_VOMIT) + { + params.velocityMulti *= VOMIT_SPEED_SCALE; + params.bulletFlags |= PROJECTILE_EXPLODE; + params.scale = VOMIT_SCALE; + params.fallingSpeedModifier = VOMIT_FALL_SPEED; + params.fallingAccelModifier = VOMIT_FALL_ACCEL; + std::copy(VOMIT_COLORIZE.begin(), VOMIT_COLORIZE.end(), params.color._colorize); + if (npc.controllerID != -1) reconstruction_missing("NpcAI::ENTITY_STONEHEAD 00520c60: a controlled vomit's aim"); + } + if (npc.controllerID != -1) reconstruction_missing("NpcAI::ENTITY_STONEHEAD 00520c60: a controlled grimace's aim"); + + Vector aim = vector_sub(npc.GetPlayerTarget()->pos, npc.pos); + float speed = game_is_hard_mode() ? GRIMACE_SHOT_SPEED_HARD : GRIMACE_SHOT_SPEED; + ProjectilesMode mode = npc.variant == GRIMACE_TRIPLE ? PROJECTILES_THREE_WIDE : PROJECTILES_SINGLE; + npc.FireProjectiles(npc.pos, vector_resized(aim, speed), mode, params); +} + +// A Stone Grimace shoots a target in range when its cooldown is out. +static void grimace_update(Entity_NPC& npc) +{ + if (npc.projectileCooldown > 0) npc.projectileCooldown -= npc_ticks_get(npc); + if (npc.controllerID != -1) reconstruction_missing("NpcAI::ENTITY_STONEHEAD 00520c60: Entity_NPC::SpawnControlTarget"); + if (npc.projectileCooldown < 1 && npc.IsTargetInAttackRange(GRIMACE_RANGE, 0, true)) + { + npc.projectileCooldown = GRIMACE_COOLDOWN; + npc_anim_restart(npc.sprite, "Shoot"); + } + if (npc.sprite.animState.animData && npc.sprite.animState.IsEventTriggered("Shoot")) grimace_shoot(npc); + if (npc_anim_is_done(npc)) npc.sprite.Play("Idle"); +} + +// 00520c60 NpcAI::ENTITY_STONEHEAD: the faces set in the grid (the Stone Grimace, Brimstone Head, Gaping Maw and +// Broken Gaping Maw). They hold their cell, never move, close for good once the room is clear or its pressure plates +// are pressed, and a dead one keeps its cell from spawning again. +void npc_stonehead_update(Entity_NPC& npc) +{ + if (npc.aiCallPhase == AI_PHASE_PRE_UPDATE) + { + if (!npc.minecart && !npc.isDead && npc.pathfinder.gridIndex >= 0) + g_game->room->SetGridPath(npc.pathfinder.gridIndex, STONEHEAD_GRID_PATH); + return; + } + + bool isFirstFrame = npc.state == NPC_STATE_INIT; + if (isFirstFrame) stonehead_init(npc); + RoomDescriptor& desc = *g_game->GetRoomByIdx(g_game->currentRoomIdx); + bool isPressed = desc.flags & ROOM_DESCRIPTOR_FLAG_PRESSURE_PLATES_TRIGGERED; + bool isActive = stonehead_is_active(npc, isPressed, isFirstFrame); + if (isFirstFrame) return; + + npc.velocity = vector_sub(npc.targetPosition, npc.pos); + if (npc.isDead && npc.spawnGridIndex >= 0) + g_game->GetRoomByIdx(g_game->currentRoomIdx)->restrictedGridIndexes.insert(npc.spawnGridIndex); + + if (!isActive) + { + if (npc.type == ENTITY_BRIMSTONE_HEAD && isPressed) npc.sprite.Play("CloseEyes"); + } + else if (npc.type == ENTITY_STONEHEAD) grimace_update(npc); + else if (npc.type == ENTITY_BRIMSTONE_HEAD) brimstone_head_update(npc); + else gaping_maw_suck(npc); + npc.stateFrame++; +} diff --git a/src/path_finder.cpp b/src/path_finder.cpp index 85dac45..8d01866 100644 --- a/src/path_finder.cpp +++ b/src/path_finder.cpp @@ -1,4 +1,5 @@ #include "path_finder.h" +#include "boss_ai.h" #include "game.h" #include "npc_ai.h" #include "npc_basement.h" @@ -20,6 +21,28 @@ constexpr float WANDER_STALL_SPEED_SQUARED = 0.1f; constexpr int WANDER_GIVE_UP_ODDS = 10; constexpr float WANDER_FRIENDLY_SPEED = 0.5f; +// How an owner wanders along the axes: up to 10 tries a call at a run of up to 11 cells (1 to 4 while it flees) that +// ends before a cell felt over 300 (998 on the last try, 800 while fleeing). A cell marked 999 is never a spot. +constexpr int AXIS_ATTEMPTS = 10; +constexpr uint32_t AXIS_RUN_CELLS = 12; +constexpr int AXIS_BLOCKING_PATH = 300; +constexpr int AXIS_LAST_TRY_BLOCKING_PATH = 998; +constexpr int AXIS_FLEE_BLOCKING_PATH = 800; +constexpr int AXIS_AVOIDED_PATH = 999; +constexpr int AXIS_SIDE_OPEN_PATH = 200; +constexpr uint32_t AXIS_SIDE_ODDS = 10; +constexpr uint32_t AXIS_SHORT_ODDS = 10; +constexpr uint32_t AXIS_TURN_BACK_ODDS = 5; +constexpr float AXIS_FLEE_AWAY_DOT = 0.95f; +constexpr float AXIS_ARRIVED = 5; +constexpr float AXIS_STALL_SPEED = 0.6f; +constexpr int AXIS_STALL_CHECKS = 10; +constexpr int AXIS_HAZARD_PATH = 700; +constexpr float AXIS_HAZARD_SPEED = 3; +constexpr int AXIS_HAZARD_CHECKS = 2; +constexpr float AXIS_FOLLOW_NEAR_SQUARED = 1600; +constexpr float AXIS_FOLLOW_FRICTION = 0.8f; + // How an owner evades: within 250 of its target (170 when the target cannot walk to it) it keeps fleeing for three // checks of every 14 frames, pushing away at 1.5 and trying up to 7 random cells 30 to 480 past a point 30 away // (fewer as the evasion widens toward 20) that lie farther from the target than it by 100 and a third of their reach. @@ -124,7 +147,7 @@ void PathFinder::Reset() visitedGridIndices.clear(); direction = PATH_DIRECTION_NONE; directionTimer = 0; - targetGridIndex = -1; + lastMoveFrame = -1; canCrushRocks = false; movementTarget = {}; moveDirection = {}; @@ -553,10 +576,177 @@ bool PathFinder::MoveRandomly(StatusMode mode) return false; } -// 007e5340 -void PathFinder::MoveRandomlyAxisAligned(float, StatusMode) +// A run of cells straight from the owner in a direction: how far it reaches before a cell it would not cross (none past +// the room's box), and none when both cells beside its end are blocked, unless one time in ten. +static int axis_run_get(PathFinder& finder, int direction, int attemptsLeft) { - reconstruction_missing("PathFinder::MoveRandomlyAxisAligned 007e5340"); + Entity* entity = finder.entity; + Room& room = *g_game->room; + int cells = (int)(Random() % AXIS_RUN_CELLS); + bool isFleeing = entity->HasEntityFlags(FLAG_FEAR | FLAG_SHRINK); + if (isFleeing) cells = (int)(Random() & 3) + 1; + + Vector axis = vector_from_direction(direction); + Vector end = vector_add(entity->pos, vector_scale(axis, (float)cells * GRID_CELL_SIZE)); + bool isInside = end.x <= room.bottomRightPos.x && end.x >= room.topLeftPos.x && end.y <= room.bottomRightPos.y && + end.y >= room.topLeftPos.y; + if (!isInside || vector_is_zero(end)) return 0; + + for (int step = 1; step < cells; step++) + { + Vector cell = vector_add(entity->pos, vector_scale(axis, (float)step * GRID_CELL_SIZE)); + int path = finder.grid_path_felt(room.GetGridPath(room.GetGridIndex(cell))); + bool isBlocked = path > AXIS_BLOCKING_PATH && (attemptsLeft > 0 || path > AXIS_LAST_TRY_BLOCKING_PATH) && + (!isFleeing || path > AXIS_FLEE_BLOCKING_PATH); + if (!isBlocked) continue; + + cells = step - 1; + break; + } + + end = vector_add(entity->pos, vector_scale(axis, (float)cells * GRID_CELL_SIZE)); + bool isOpen = false; + for (int side : {direction + 3, direction + 1}) + { + Vector step = vector_scale(vector_from_direction(side % PATH_DIRECTION_COUNT), GRID_CELL_SIZE); + Vector beside = vector_add(end, step); + isOpen = isOpen || finder.grid_path_felt(room.GetGridPath(room.GetGridIndex(beside))) < AXIS_SIDE_OPEN_PATH; + } + return isOpen || Random() % AXIS_SIDE_ODDS == 0 ? cells : 0; +} + +// The direction of the longest run, looked over from a random start. A fleeing NPC takes the longest run away from its +// target, else across it. best is the run's length. +static int axis_direction_pick(PathFinder& finder, const std::array& runs, int& best) +{ + Entity* entity = finder.entity; + auto* npc = dynamic_cast(entity); + int chosen = PATH_DIRECTION_NONE; + int start = (int)(Random() & 3); + auto longest_take = [&](int direction) { + if (runs[direction] <= best) return; + best = runs[direction]; + chosen = direction; + }; + + if (npc && entity->HasEntityFlags(FLAG_FEAR | FLAG_SHRINK)) + { + Vector toward = vector_sub(npc->GetPlayerTarget()->pos, entity->pos); + for (int i = start; i < start + PATH_DIRECTION_COUNT; i++) + if (vector_dot(toward, vector_from_direction(i & 3)) <= 0) longest_take(i & 3); + int across = std::abs(toward.y) <= std::abs(toward.x) ? PATH_DIRECTION_UP : PATH_DIRECTION_LEFT; + if (best == 0) + for (int direction = across; direction < PATH_DIRECTION_COUNT; direction += 2) longest_take(direction); + if (best != 0) return chosen; + } + + for (int i = start; i < start + PATH_DIRECTION_COUNT; i++) longest_take(i & 3); + return chosen; +} + +// One try at a run to wander: the longest, though one under two cells only one time in ten and a turn back only one +// time in five (a fleeing NPC takes either, but no run within 0.95 of straight at its target). Its end cell becomes +// the spot to reach unless marked avoided or not free, and the owner stops across the run's axis. +static void axis_run_try(PathFinder& finder, int attemptsLeft) +{ + Entity* entity = finder.entity; + Room& room = *g_game->room; + std::array runs{}; + for (int direction = 0; direction < PATH_DIRECTION_COUNT; direction++) + runs[direction] = axis_run_get(finder, direction, attemptsLeft); + + int best = 0; + int chosen = axis_direction_pick(finder, runs, best); + bool isFleeing = entity->HasEntityFlags(FLAG_FEAR | FLAG_SHRINK); + if (best < 2 && Random() % AXIS_SHORT_ODDS != 0 && !isFleeing) chosen = PATH_DIRECTION_NONE; + bool isTaken = std::abs(finder.direction - chosen) != 2 || Random() % AXIS_TURN_BACK_ODDS == 0 || isFleeing; + finder.directionTimer = 0; + if (!isTaken || chosen < 0) return; + + Vector axis = vector_from_direction(chosen); + if (isFleeing) + { + Vector toward = vector_sub(static_cast(entity)->GetPlayerTarget()->pos, entity->pos); + if (vector_dot(vector_normalized(toward), axis) > AXIS_FLEE_AWAY_DOT) return; + } + + Vector end = vector_add(entity->pos, vector_scale(axis, (float)best * GRID_CELL_SIZE)); + Vector center = room.GetGridPosition(room.GetGridIndex(end)); + int cell = room.GetGridIndex(center); + if (room.GetGridPath(cell) == AXIS_AVOIDED_PATH) return; + + finder.direction = chosen; + auto collision = (GridCollision)room.GetGridCollision(cell); + bool isFree = collision == COLLISION_NONE || + (entity->entityGridCollisionClass == GRIDCOLL_WALLS && collision != COLLISION_WALL); + if (!isFree) return; + + finder.movementTarget = center; + if (std::abs(axis.x) <= std::abs(axis.y)) entity->velocity.x = 0; + else entity->velocity.y = 0; +} + +// Drives toward the spot to reach, kept in the room's box. It drops the spot after a skipped frame, once within 5, +// once slower than 0.6 for over 10 checks, or once heading at over 3 into a cell it feels over 700 for over 2 checks. +static void axis_steer(PathFinder& finder, float speed, int elapsed) +{ + Entity* entity = finder.entity; + Room& room = *g_game->room; + Vector& target = finder.movementTarget; + if (elapsed > 1) + { + target = {}; + return; + } + + target.x = std::min(std::max(target.x, room.topLeftPos.x), room.bottomRightPos.x); + target.y = std::min(std::max(target.y, room.topLeftPos.y), room.bottomRightPos.y); + Vector away = vector_sub(vector_add(entity->pos, entity->velocity), target); + if (vector_length(away) < AXIS_ARRIVED) target = {}; + else if (vector_length(entity->velocity) < AXIS_STALL_SPEED && ++finder.directionTimer > AXIS_STALL_CHECKS) + target = {}; + + away = vector_normalized(away); + if (entity->friction != 0) + { + entity->velocity.y += entity->speedMultiplier * -away.y * speed / entity->friction; + entity->velocity.x += entity->speedMultiplier * -away.x * speed / entity->friction; + } + + Vector ahead = vector_add(entity->pos, vector_scale(vector_normalized(entity->velocity), GRID_CELL_SIZE)); + int felt = finder.grid_path_felt(room.GetGridPath(room.GetGridIndex(ahead))); + if (felt > AXIS_HAZARD_PATH && vector_length(entity->velocity) > AXIS_HAZARD_SPEED && + ++finder.directionTimer > AXIS_HAZARD_CHECKS) + target = {}; +} + +// 007e5340 Wanders along the axes: up to 10 tries a call at a run of cells left, up, right or down to a free cell, +// then drives there at speed. A friendly owner paths to its target instead, sliding along the axis it leans on most, +// and holds still near a player it follows. +void PathFinder::MoveRandomlyAxisAligned(float speed, StatusMode mode) +{ + if (entity->minecart) return; + if (mode == STATUS_OBEYED && is_entity_friendly()) + { + auto* npc = static_cast(entity); + Vector target = npc->CalcTargetPosition(0); + bool isNear = npc->HasEntityFlags(FLAG_FRIENDLY) && npc->GetPlayerTarget()->type == ENTITY_PLAYER && + vector_length_squared(vector_sub(npc->pos, target)) < AXIS_FOLLOW_NEAR_SQUARED; + if (isNear) + { + npc->friction *= AXIS_FOLLOW_FRICTION; + return; + } + FindGridPath(npc->CalcTargetPosition(0), speed, 0, DIRECT_PATH_FAR); + npc->velocity = vector_scale(vector_cardinal(npc->velocity), vector_length(npc->velocity)); + return; + } + + int elapsed = g_game->frameCount - lastMoveFrame; + lastMoveFrame = g_game->frameCount; + for (int attempts = AXIS_ATTEMPTS; vector_is_zero(movementTarget) && attempts > 0; attempts--) + axis_run_try(*this, attempts - 1); + if (!vector_is_zero(movementTarget)) axis_steer(*this, speed, elapsed); } // 007e6650 diff --git a/src/path_finder.h b/src/path_finder.h index b2eb8ad..3f1a5fb 100644 --- a/src/path_finder.h +++ b/src/path_finder.h @@ -47,6 +47,7 @@ struct PathNode // How an NPC finds its way around the room (Lua's PathFinder, the original's NPCAI_Pathfinder): the cost map it floods // from a target and walks down, the spot it wanders to, and the evasion it keeps up. // gridIndex is the cell it counts itself in, which follows its owner only after gridIndexDelay runs out. +// An axis-aligned wander heads in direction, notes the frame it last moved on and counts its stalls in directionTimer. struct PathFinder { std::array gridCosts{}; @@ -63,7 +64,7 @@ struct PathFinder int gridIndex = -1; int gridIndexDelay = 0; int moveCountdown = 0; - int targetGridIndex = -1; + int lastMoveFrame = -1; bool canCrushRocks = false; bool hasDirectPath = false; bool isPathFound = false; diff --git a/src/persistent_game_data.h b/src/persistent_game_data.h index c229993..efb6aa0 100644 --- a/src/persistent_game_data.h +++ b/src/persistent_game_data.h @@ -9,6 +9,14 @@ #include constexpr int ACHIEVEMENT_COUNT = 642; + +// The achievements the game checks by id. +constexpr int ACHIEVEMENT_THE_WOMB = 4; +constexpr int ACHIEVEMENT_IT_LIVES = 34; +constexpr int ACHIEVEMENT_THE_POLAROID = 57; +constexpr int ACHIEVEMENT_THE_NEGATIVE = 78; +constexpr int ACHIEVEMENT_KRAMPUS = 142; +constexpr int ACHIEVEMENT_THE_VOID = 320; constexpr int BOSS_COUNT = 104; constexpr int CHALLENGE_COUNT = 46; constexpr int COLLECTIBLE_SEEN_COUNT = 733; diff --git a/src/player_manager.cpp b/src/player_manager.cpp index 1da0d3c..33b1e58 100644 --- a/src/player_manager.cpp +++ b/src/player_manager.cpp @@ -1012,10 +1012,6 @@ void PlayerManager::Update() sfx.AdjustPitch(SOUND_STATIC_BUILDUP, 1); } -Vector PlayerManager::find_safe_spawn_position(Vector) -{ - reconstruction_missing("PlayerManager::find_safe_spawn_position 009bc280"); -} void PlayerManager::unlock_completion_mark(int) { reconstruction_missing("PlayerManager::unlock_completion_mark 0095a7b0"); diff --git a/src/room.cpp b/src/room.cpp index 2d71213..e88a91f 100644 --- a/src/room.cpp +++ b/src/room.cpp @@ -3,6 +3,7 @@ #include "entity_player.h" #include "entity_effect.h" #include "entity_factory.h" +#include "entity_familiar.h" #include "entity_npc.h" #include "game.h" #include "grid_entity_door.h" @@ -155,14 +156,10 @@ constexpr float DEAL_LAST_SCALE = 0.5f; constexpr uint32_t GREED_DEAL_WAVE = 11; constexpr int COLLECTIBLE_PENTAGRAM = 51; constexpr int COLLECTIBLE_GOAT_HEAD = 215; -constexpr int COLLECTIBLE_EUCHARIST = 499; -constexpr int COLLECTIBLE_ACT_OF_CONTRITION = 601; -constexpr int TRINKET_NUMBER_MAGNET = 174; // The doors of a cleared boss room: what unlocks them and the stages they open on, the secret exit kinds, the deal // door's jingles and Greed's deal door slot, Mom's parts the Boss Rush door clears, and the run flags they set. constexpr int ACHIEVEMENT_BLUE_WOMB = 234; -constexpr int ACHIEVEMENT_THE_VOID = 320; constexpr int ACHIEVEMENT_SECRET_EXIT = 407; constexpr int ACHIEVEMENT_STRANGE_DOOR = 635; constexpr int SOUND_ANGEL_DOOR_APPEAR = 23; @@ -2698,8 +2695,7 @@ struct DoorDust // Five to eight puffs of dust thrown out of a door as it appears, spread around it and spinning away from it. static void door_dust_spawn(Room& room, GridEntity_Door& door, const DoorDust& dust) { - Vector direction{}; - Isaac::GetAxisAlignedUnitVectorFromDir(&direction, door.slot & 3); + Vector direction = direction_unit(door.slot & 3); Vector out = vector_make(-direction.x, -direction.y); Vector across = vector_make(out.x * std::cos(QUARTER_TURN) - out.y * std::sin(QUARTER_TURN), out.x * std::sin(QUARTER_TURN) + out.y * std::cos(QUARTER_TURN)); @@ -3181,10 +3177,24 @@ bool Room::spawn_sanguine_bond_spikes(bool) reconstruction_missing("Room::spawn_sanguine_bond_spikes 00827bf0"); } -// 008167e0 Removes the door in a slot. -void Room::RemoveDoor(int) +// 008167e0 Removes the door in a slot and walls its cell up. +void Room::RemoveDoor(int slot) { - reconstruction_missing("Room::RemoveDoor 008167e0"); + if (slot < 0 || slot >= DOOR_SLOT_COUNT || !doors[slot]) return; + + int gridIndex = doorGridPositions[slot]; + if (gridIndex < 0) log_printf(LOG_ASSERT, "invalid GridIndex while removing door (slot %d)", slot); + gridIndex = std::clamp(gridIndex, 0, ROOM_GRID_CELLS - 1); + if (dynamic_cast(gridEntities[gridIndex])) + { + delete gridEntities[gridIndex]; + gridEntities[gridIndex] = nullptr; + } + doors[slot] = nullptr; + + GridEntity* wall = CreateGridEntity(GRID_WALL, gridIndex); + gridEntities[gridIndex] = wall; + wall->Init(Random()); } // 007fe220 Fills the room with the Card Against Humanity's poop. diff --git a/src/room_clear.cpp b/src/room_clear.cpp index eb8f5c6..d1802ea 100644 --- a/src/room_clear.cpp +++ b/src/room_clear.cpp @@ -5,9 +5,11 @@ #include "entity_list.h" #include "entity_pickup.h" #include "entity_player.h" +#include "game_over.h" #include "game.h" #include "grid_entity_door.h" #include "grid_entity_pit.h" +#include "grid_entity_trap_door.h" #include "item_config.h" #include "item_pool.h" #include "lua_engine.h" @@ -62,6 +64,18 @@ constexpr int EVENT_COUNTER_BOSSRUSHS_CLEARED = 111; constexpr int ULTRA_GREED_BOSS = 62; constexpr int BABY_PLUM_BOSS = 84; constexpr int GREED_WAVES = 10; +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. +constexpr std::array MOM_UNLOCKS = {ACHIEVEMENT_THE_WOMB, 5, 6, 641}; +static const Vector MOMS_ITEM_SPOT = vector_make(320, 360); + +// A Void portal (a trapdoor with varData 1) opens after one Mom kill in 20, with 20 items or more than 100 damage. +constexpr uint32_t VOID_PORTAL_ODDS = 20; +constexpr int VOID_PORTAL_ITEMS = 20; +constexpr float VOID_PORTAL_DAMAGE = 100; +constexpr float VOID_PORTAL_SPREAD = 80; constexpr int ACHIEVEMENT_MONSTROS_LUNG = 13; constexpr int ACHIEVEMENT_LIL_CHUBBY = 14; constexpr int ACHIEVEMENT_STEVEN = 16; @@ -748,6 +762,130 @@ static void boss_exit_spawn(Room& room, ClearAward& award, int stage, bool isCon room.SpawnGridEntity(award.trapdoorIndex, GRID_TRAPDOOR, 0, Random(), 0); } +// Whether the run may go on to the Void: never in Greed mode or on a Home path, else when the challenge's end stage +// (or the run's own: the Void once unlocked outside challenges, else the Dark Room) lies past the eleventh floor. +static bool is_void_reachable() +{ + Game& game = *g_game; + if (game.IsGreedMode()) return false; + + ChallengeParam& params = game.GetChallengeParams(); + bool isOpen = params.endStage == STAGE_VOID || + (game.challenge == 0 && game.dailyChallenge._id == 0 && + g_manager->persistentGameData.Unlocked(ACHIEVEMENT_THE_VOID)); + int endStage = isOpen ? STAGE_VOID : STAGE_DARK_ROOM; + if (params.isPathTypeSet) + { + if (params.pathType == PATH_TYPE_HOME) return false; + if (params.endStage != 0) endStage = params.endStage; + } + return endStage > STAGE_DARK_ROOM; +} + +// The Polaroid or the Negative (by the path they lead down), free and gone from the pools. +static Entity_Pickup* moms_photo_spawn(Room& room, ClearAward& award, Vector spot, int item) +{ + reward_spot_clear(room, spot); + auto* photo = static_cast(g_game->Spawn({.position = spot, .subType = item, + .type = ENTITY_PICKUP, + .variant = PICKUP_COLLECTIBLE, + .seed = award.rng.Next()})); + g_game->itemPool.RemoveCollectible(item, REMOVE_ANY, REMOVE_APPLY); + photo->cycleCollectibleCount = 0; + photo->coopDuplicateIndex = 0; + return photo; +} + +// Mom's items: the Polaroid where the Cathedral lies ahead and the Negative where Sheol does (a choice of both, or both +// on a Home path), else a boss item from the room's pool. +static void moms_items_spawn(Room& room, ClearAward& award) +{ + Game& game = *g_game; + PersistentGameData& data = g_manager->persistentGameData; + ChallengeParam& params = game.GetChallengeParams(); + bool isHome = params.pathType == PATH_TYPE_HOME; + bool isPolaroid = isHome || (data.Unlocked(ACHIEVEMENT_THE_POLAROID) && Level::IsStageWithinEnd(STAGE_SHEOL, true)); + bool isNegative = isHome || (data.Unlocked(ACHIEVEMENT_THE_NEGATIVE) && Level::IsStageWithinEnd(STAGE_SHEOL, false)); + Vector center = MOMS_ITEM_SPOT; + + if (isPolaroid && isNegative) + { + float row = award.reward.y + AWARD_ITEM_DROP; + Entity_Pickup* polaroid = moms_photo_spawn(room, award, vector_make(award.reward.x - AWARD_ITEM_SPACING, row), + COLLECTIBLE_POLAROID); + int optionsIndex = polaroid->AssignOptionsIndex(); + Entity_Pickup* negative = moms_photo_spawn(room, award, vector_make(award.reward.x + AWARD_ITEM_SPACING, row), + COLLECTIBLE_NEGATIVE); + negative->optionsPickupIndex = optionsIndex; + } + else if (isPolaroid || isNegative) moms_photo_spawn(room, award, center, isPolaroid ? COLLECTIBLE_POLAROID : COLLECTIBLE_NEGATIVE); + else + { + int item = game.itemPool.GetSeededCollectible(award.rng.Next(), 0, *room.descriptor); + reward_spot_clear(room, center); + auto* pickup = static_cast(game.Spawn({.position = center, .subType = item, + .type = ENTITY_PICKUP, + .variant = PICKUP_COLLECTIBLE, + .seed = award.rng.Next()})); + if (award.isShopItems) pickup->MakeShopItem(-2); + pickup->coopDuplicateIndex = 0; + } +} + +// One Mom kill in 20 opens a Void portal beside the reward, on a run that may reach the Void with 20 items or 100 +// damage on a main player. +static void moms_void_portal_roll(Room& room, ClearAward& award) +{ + int items = 0; + float damage = 0; + for (Entity_Player* player : g_game->playerManager.playerList) + { + if (player->variant != 0) continue; + for (int count : player->collectibleCounts) items += count; + damage = std::max(player->damage, damage); + } + if (award.rng.RandomInt(VOID_PORTAL_ODDS) != 0 || (items < VOID_PORTAL_ITEMS && damage <= VOID_PORTAL_DAMAGE)) + return; + + int gridIndex = room.GetGridIndex(room_free_pickup_position_find({.position = award.reward, + .step = VOID_PORTAL_SPREAD, + .isAvoidActiveEntities = true})); + room_spawn_cell_clear(room, gridIndex); + room.SpawnGridEntity(gridIndex, GRID_TRAPDOOR, 0, Random(), TRAPDOOR_VOID_PORTAL); +} + +// Mom's floor's last boss: her first kill ends the run with her ending and unlocks the Womb (unless a challenge goes +// on). After that the trapdoor down (a trophy at a challenge's end), her items, sometimes a Void portal, and the +// unlocks are checked again. +static void moms_award_spawn(Room& room, ClearAward& award, bool isContinuing) +{ + PersistentGameData& data = g_manager->persistentGameData; + ChallengeParam& params = g_game->GetChallengeParams(); + bool isChallengeGoingOn = params.isPathTypeSet && (!isContinuing || params.isMegaSatan || + params.endStage > STAGE_DEPTHS_II); + if (!data.Unlocked(ACHIEVEMENT_THE_WOMB) && !isChallengeGoingOn) + { + for (int achievement : MOM_UNLOCKS) data.TryUnlock(achievement); + return game_end(ENDING_MOM); + } + + if (!isContinuing) + { + Vector spot = award.reward; + reward_spot_clear(room, spot); + g_game->Spawn({.position = spot, .type = ENTITY_PICKUP, .variant = PICKUP_TROPHY, .seed = Random()}); + } + else if (!params.isPathTypeSet || params.pathType != PATH_TYPE_HOME) + { + room_spawn_cell_clear(room, award.trapdoorIndex); + room.SpawnGridEntity(award.trapdoorIndex, GRID_TRAPDOOR, 0, Random(), 0); + } + + moms_items_spawn(room, award); + if (isContinuing && is_void_reachable()) moms_void_portal_roll(room, award); + for (int achievement : MOM_UNLOCKS) data.TryUnlock(achievement); +} + // The kill records a boss clear keeps: each floor's boss kills (Steven, Chad and Gish at 40 Basement, 30 Caves and // 20 Depths kills), the first Monstro's Lung, Lil Chubby and angel unlocks, and the no-damage runs to a last boss. static void boss_kill_records(int stage, bool isLastBoss) @@ -826,6 +964,7 @@ static void boss_award_spawn(Room& room, ClearAward& award) 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 reconstruction_missing("Room::SpawnClearAward 007fb250: the final bosses' endings and chests"); boss_kill_records(stage, isLastBoss); } diff --git a/src/room_config.cpp b/src/room_config.cpp index dd93086..b42dbbf 100644 --- a/src/room_config.cpp +++ b/src/room_config.cpp @@ -52,7 +52,6 @@ constexpr float EXACT_DOORS_BIAS = 9.99f; constexpr float PICKED_WEIGHT_SCALE = 0.1f; constexpr float PICKED_WEIGHT_MIN = 1e-7f; constexpr uint32_t ENTITY_CONSTANT_STONE_SHOOTER = 202; -constexpr uint32_t ENTITY_BRIMSTONE_HEAD = 203; constexpr uint32_t ENTITY_QUAKE_GRIMACE = 804; constexpr uint32_t ENTITY_SPIKEBALL = 852; constexpr uint32_t ENTITY_CYST = 862; @@ -78,7 +77,8 @@ constexpr uint16_t RAIL_RIGHT = 0x20; constexpr uint32_t GRID_RAIL = 6000; // The room types by the names the game knows them by (0x00b1fd50). -constexpr std::string_view ROOM_TYPE_NAMES[] = { +constexpr int ROOM_TYPE_COUNT = 30; +constexpr std::string_view ROOM_TYPE_NAMES[ROOM_TYPE_COUNT] = { "null", "default", "shop", "error", "treasure", "boss", "miniboss", "secret", "supersecret", "arcade", "curse", "challenge", "library", "sacrifice", "devil", "angel", "itemdungeon", "bossrush", "isaacs", "barren", "chest", @@ -865,6 +865,12 @@ int RoomConfig::GetStageID(int levelStage, int stageType, RoomMode mode) return (int)(type + 1 + chapter * 3); } +// (008295c0) A room type's name, empty for none. +std::string_view room_type_name(int type) +{ + return type < 0 || type >= ROOM_TYPE_COUNT ? std::string_view() : ROOM_TYPE_NAMES[type]; +} + // 0082d100 A room type by its name in the game's list ("shop", "treasure" ...), or 0 for none. int RoomConfig::room_type_find(std::string_view name) { diff --git a/src/room_config.h b/src/room_config.h index 6775a11..023828a 100644 --- a/src/room_config.h +++ b/src/room_config.h @@ -211,3 +211,5 @@ public: static int room_type_find(std::string_view name); static int get_door_from_position(short x, short y, RoomShape shape); }; + +std::string_view room_type_name(int type); diff --git a/src/room_lighting.cpp b/src/room_lighting.cpp index c52be3e..9a3fa5d 100644 --- a/src/room_lighting.cpp +++ b/src/room_lighting.cpp @@ -98,25 +98,13 @@ constexpr const char* NULL_LIGHT = "Light"; constexpr const char* LAYER_SPARKS = "sparks"; constexpr const char* LAYER_FLAME = "flame"; -// The laser variants by their light's color, and the effect variants with lights (Lua's EffectVariant). +// The effect variants with lights that EffectVariant does not name yet. enum LightVariant : int { - LASER_THIN_RED = 2, - LASER_SHOOP = 3, - LASER_PRIDE = 4, - LASER_LIGHT_BEAM = 5, - LASER_TRACTOR_BEAM = 7, - LASER_LIGHT_RING = 8, - LASER_ELECTRIC = 10, EFFECT_BLUE_FLAME = 10, EFFECT_TARGET = 30, EFFECT_RED_CANDLE_FLAME = 52, - EFFECT_BLOOD_DROP = 70, - EFFECT_BRIMSTONE_SWIRL = 71, EFFECT_FIREWORKS = 104, - EFFECT_ENEMY_BRIMSTONE_SWIRL = 110, - EFFECT_HAEMO_TRAIL = 111, - EFFECT_TECH_DOT = 126, EFFECT_OCCULT_TARGET = 153, EFFECT_KINETI_BEAM = 175, EFFECT_REVERSE_EXPLOSION = 177 @@ -164,6 +152,7 @@ constexpr float WISP_LAYER_DARKER = 0.25f; // Lasers draw their light along their length in this many steps, and room-wide lights fade in over their first frames. constexpr int LASER_LIGHT_STEPS = 20; +constexpr float LASER_LIGHT_LIFT = 0.65f; constexpr int LIGHT_FADE_IN_FRAMES = 10; constexpr float DARK_ROOM_ALPHA = 0.5f; @@ -208,11 +197,6 @@ static Vector vector_rotated(Vector v, float degrees) return vector_make(v.x * cos - v.y * sin, v.y * cos + v.x * sin); } -static ColorMod tint_make(float red, float green, float blue, float alpha) -{ - return {{red, green, blue, alpha}, {0, 0, 0, 0}, {0, 0, 0}}; -} - // A light color multiplied by an entity's sprite color. static ColorMod color_through(ColorMod color, const ColorMod& other) { @@ -300,7 +284,7 @@ static void sprite_lights_render(LightPass& pass) if (sprite.isFlipY) at.y = -at.y; KColor color = kcolor_apply(color_through(sprite.color, frame->color), kcolor_rgba(1, 1, 1, 1)); - light.color = tint_make(color._red, color._green, color._blue, color._alpha); + light.color = tint_color_make(color._red, color._green, color._blue, color._alpha); light.scale = vector_make(frame->scale.x * sprite.scale.x, frame->scale.y * sprite.scale.y); light.rotation = sprite.rotation + frame->rotation; light.Render({vector_add(position, at)}); @@ -506,7 +490,7 @@ static ColorMod wisp_light_color(Entity& wisp) lumas[i] = colors[i]._green * LUMA_GREEN + colors[i]._red * LUMA_RED + colors[i]._blue * LUMA_BLUE; } KColor color = lumas[0] > lumas[1] - WISP_LAYER_DARKER ? colors[0] : colors[1]; - return tint_make(color._red, color._green, color._blue, 1); + return tint_color_make(color._red, color._green, color._blue, 1); } // A familiar's light: Isaac's Heart glows pink and wisps in their own color, both with the small light. @@ -584,7 +568,8 @@ static ColorMod laser_light_color(Entity& laser) } // A laser's light along its length: from its sprite's Light null, else by variant (thin lasers smaller), in twenty -// steps from the laser to its end (Pride's widening along it). A laser with samples lights at every few of them. +// steps from the laser to its end (Pride's widening along it). A laser with samples lights at every few of them and +// at its end, lifted by its offset. // The original skips a step whose distance from the last drawn one is negative, which never happens. static void laser_light_render(LightPass& pass) { @@ -608,7 +593,14 @@ static void laser_light_render(LightPass& pass) } if (laser.isSampleLaser) - reconstruction_missing("Room::render_entity_light 00806c20: a sample laser's light"); + { + const std::vector& samples = laser.homingLaser.nonOptimizedSamples; + Vector lift = vector_scale(laser.posOffset, LASER_LIGHT_LIFT); + size_t step = std::max(1, samples.size() / LASER_LIGHT_STEPS); + for (size_t i = 0; i < samples.size(); i += step) light.Render({vector_add(screen_position(pass, samples[i]), lift)}); + if (!samples.empty()) light.Render({vector_add(screen_position(pass, samples.back()), lift)}); + return; + } Vector start = vector_add(laser.pos, laser.posOffset); for (int step = 0; step < LASER_LIGHT_STEPS; step++) { @@ -747,7 +739,7 @@ static void effect_light_render(LightPass& pass) if (!frame) return; const float* tint = frame->color._tint; - light_draw(pass, {tint_make(tint[0], tint[1], tint[2], tint[3]), {}, uniform(1.5f)}); + light_draw(pass, {tint_color_make(tint[0], tint[1], tint[2], tint[3]), {}, uniform(1.5f)}); return; } case EFFECT_WISP: @@ -795,7 +787,7 @@ static void effect_light_render(LightPass& pass) float animFrame = sprite.animState.animData ? sprite.animState.animFrame : -1; float left = 1 - animFrame / (float)sprite.animState.GetAnimationLength(); KColor red = kcolor_apply(sprite.color, HAEMO_TRAIL_RED); - light_draw(pass, {tint_make(red._red, red._green, red._blue, red._alpha * left), + light_draw(pass, {tint_color_make(red._red, red._green, red._blue, red._alpha * left), {}, vector_scale(sprite.scale, 0.5f), 0, @@ -821,7 +813,7 @@ static void effect_light_render(LightPass& pass) float darkness = pass.room.GetLightingAlpha(); if (darkness <= DARK_ROOM_ALPHA) return; - light_draw(pass, {tint_make(1, 1, 1, (darkness - DARK_ROOM_ALPHA) * 2), {}, uniform(4), 0, 0, true}); + light_draw(pass, {tint_color_make(1, 1, 1, (darkness - DARK_ROOM_ALPHA) * 2), {}, uniform(4), 0, 0, true}); return; } case EFFECT_LIGHT: diff --git a/src/room_render.cpp b/src/room_render.cpp index 122cb99..12ac739 100644 --- a/src/room_render.cpp +++ b/src/room_render.cpp @@ -30,6 +30,16 @@ constexpr int ROOM_SURFACE_HEIGHT = 468; // The game shader Render's shadows and lighting overlay draw with (the original's shader table entry 0). constexpr const char* COLOR_OFFSET_SHADER = "ColorOffset"; +constexpr const char* SHOCKWAVE_SHADER = "Shockwave"; + +// The Shockwave shader's ripple scale for a 520 by 280 screen, the fade of a wave's strength over its duration, and +// the place it gives a wave that is not running. +constexpr float SHOCKWAVE_RATIO_X = 0.66015625f; +constexpr float SHOCKWAVE_RATIO_Y = 0.35546875f; +constexpr float SHOCKWAVE_SCREEN_WIDTH = 520; +constexpr float SHOCKWAVE_SCREEN_HEIGHT = 280; +constexpr float SHOCKWAVE_FADE_POWER = 0.4f; +constexpr float SHOCKWAVE_IDLE_X = -150; // A grid cell on screen: the room's floor sits two cells in from the render surface's corner. constexpr float GRID_SCREEN_CELL = 26; @@ -805,12 +815,81 @@ static void entity_glow_render(Room& room, Entity& entity, Vector offset) sprite_draw(light, vector_make(position.x + distance * direction.x, position.y + distance * direction.y)); } +// 0081df80 (Room::compute_overlay_texcoords) A world position's place on a surface the size of the screen, in the +// surface texture's units, scrolled and shaken with the room. +static Vector surface_texcoord_get(Room& room, Vector world, const KAGE::Graphics::ImageBase& surface) +{ + Vector screen = vector_add(vector_add(render_position_get(world, RENDER_SNAPPED), g_game->screenShakeOffset), + room.renderScrollOffset); + return vector_make((float)surface.width / g_screenWidth * screen.x / (float)surface.textureWidth, + (float)surface.height / g_screenHeight * screen.y / (float)surface.textureHeight); +} + +// Draws the room into its shockwave surface until shockwave_surface_resolve. +static void shockwave_surface_begin() +{ + KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager; + graphics.render_target_push(roomSurfaces.shockwave.get(), KAGE::Graphics::TARGET_SCREEN_SIZE, + KAGE::Graphics::PRESENT_FLUSH); + graphics.Clear(); +} + +// Draws the shockwave surface back over the cleared screen through the Shockwave shader, rippling at the room's two +// shockwaves (between updates, half a step further on). The Greed shop's floor and an uncleared room's Satan radial +// sprites go under it. +static void shockwave_surface_resolve(Room& room, Vector surfaceOffset) +{ + KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager; + KAGE::Graphics::ImageBase& surface = *roomSurfaces.shockwave; + + graphics.Present(KAGE::Graphics::PRESENT_FINISH); + graphics.render_target_pop(KAGE::Graphics::PRESENT_FLUSH); + graphics.Clear(); + graphics.blend_set(KAGE::Graphics::BLEND_NORMAL); + if (room.backdropType == BACKDROP_GREED_SHOP) + { + floor_quad_render(room, surfaceOffset); + if (g_manager->optionsConfig.render.isLightingEnabled) + reconstruction_missing("Room::Render 0080f200: the Greed shop's light under a shockwave"); + } + if (!room.IsClear()) shockwaves_radial_render(room, room.renderScrollOffset); + + std::array, SHOCKWAVE_COUNT> waves{}; + for (int i = 0; i < SHOCKWAVE_COUNT; i++) + { + const Shockwave& wave = roomShockwaves[i]; + 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); + waves[i] = {at.x, at.y, time, (1 - fade) * wave.amplitude}; + } + float pointsWide = g_screenPointScale * SHOCKWAVE_SCREEN_WIDTH; + float pointsHigh = g_screenPointScale * SHOCKWAVE_SCREEN_HEIGHT; + std::array ratio = {SHOCKWAVE_RATIO_X / (pointsWide / (float)surface.textureWidth), + SHOCKWAVE_RATIO_Y / (pointsHigh / (float)surface.textureHeight)}; + + shader_select(SHOCKWAVE_SHADER); + if (KAGE::Graphics::Shader* shader = graphics.currentShader) + { + shader->set_uniform("Shockwave1", KAGE::Graphics::UNIFORM_VEC4, waves[0].data()); + shader->set_uniform("Shockwave2", KAGE::Graphics::UNIFORM_VEC4, waves[1].data()); + shader->set_uniform("Ratio", KAGE::Graphics::UNIFORM_VEC2, ratio.data()); + } + SourceQuad whole = KAGE::Graphics::source_quad_rect({}, vector_make(1, 1)); + whole._coordinateSpace = KAGE::Graphics::COORDINATES_NORMALIZED; + Vector screenSize = vector_make(g_screenWidth, g_screenHeight); + surface.Render(whole, KAGE::Graphics::color_quad_rect({}, screenSize, WHITE), WHITE); + graphics.blend_set(KAGE::Graphics::BLEND_NORMAL); +} + // 0080f200 Draws the room: the behind layers, the floor with its entities, the walls, rails and flat grid entities, // the doors, shading and shadows, the players' glows, the grid entities and entities by depth, the players' extra // bodies and Night Lights, the lighting overlay, the foreground and overlay layers, and the Ashpit's dust. Retro // Vision or the game's pixelation timer pixelate the sprites meanwhile, and Dataminer garbles them. -// The effect surfaces the room draws through (the mirror world's, dizziness, shockwaves, Utero's water overlay and the -// Beast's heat wave), the water surface and the debug overlays are not reconstructed yet. +// With shockwaves running the room draws through the shockwave surface, rippled back onto the screen. The other effect +// surfaces (the mirror world's, dizziness, Utero's water overlay and the Beast's heat wave), the water surface and the +// debug overlays are not reconstructed yet. void Room::Render() { KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager; @@ -828,13 +907,14 @@ void Room::Render() spriteShaderParams.pixelationAmount = pixelation_amount(game); if (isDataminer) DAT_00c7977f = 1; - if (isMirrorWorld || game.dizzyIntensity > 0 || isShockwaveSurface || isUteroSurface || isHeatWave) - reconstruction_missing("Room::Render 0080f200: the mirror, dizzy, shockwave and water overlay surfaces"); + if (isMirrorWorld || game.dizzyIntensity > 0 || isUteroSurface || isHeatWave) + reconstruction_missing("Room::Render 0080f200: the mirror, dizzy and water overlay surfaces"); + if (isShockwaveSurface) shockwave_surface_begin(); if (backdropType == BACKDROP_DUNGEON_BEAST) render_beast_arena_background(&beastArena, BEAST_PASS_BACKGROUND); graphics.blend_set(KAGE::Graphics::BLEND_NORMAL); fxLayers.behind_layers_render(); - floor_quad_render(*this, surfaceOffset); + if (!isShockwaveSurface) floor_quad_render(*this, surfaceOffset); if (!render.isShockwaveEnabled && !IsClear()) shockwaves_radial_render(*this, renderScrollOffset); KAGE::Graphics::BlendMode floorBlend = graphics.blendMode; @@ -858,6 +938,7 @@ void Room::Render() if (backdropType == BACKDROP_DUNGEON_BEAST) render_beast_arena_background(&beastArena, BEAST_PASS_FOREGROUND); fxLayers.Render(); if (is_ashpit_rays()) dust_render(); + if (isShockwaveSurface) shockwave_surface_resolve(*this, surfaceOffset); if (isDataminer) DAT_00c7977f = 0; fxLayers.overlay_layers_render(); diff --git a/src/room_state.cpp b/src/room_state.cpp index 81d0ae4..0c22cd3 100644 --- a/src/room_state.cpp +++ b/src/room_state.cpp @@ -23,7 +23,6 @@ constexpr int GRID_PATH_RESET = 900; // The effects, slots and enemies whose saves keep more than the common fields. constexpr int EFFECT_BUTTERFLY = 69; -constexpr int EFFECT_DIRT_PATCH = 116; constexpr int HEAVEN_LIGHT_MOONLIGHT = 1; constexpr int GIDEON_TYPE = 907; constexpr int SLOT_DONATION_MACHINE = 8; diff --git a/src/room_transition.cpp b/src/room_transition.cpp index 98816a8..36772f9 100644 --- a/src/room_transition.cpp +++ b/src/room_transition.cpp @@ -215,7 +215,10 @@ void RoomTransition::arrival_place() if (player->variant == PLAYER_VARIANT_PLAYER && !(player->flags & FLAG_HELD)) player->isVisible = true; if (animation == TRANSITION_FORGOTTEN_TELEPORT && game.playerManager.roomTransitionPlayer) - reconstruction_missing("RoomTransition::ChangeRoom 00830950: Entity_Player::Teleport 007cd950 to the body"); + { + Entity_Player& player = *game.playerManager.roomTransitionPlayer; + player.Teleport(player.forgottenBodyPos, false, false); + } else if (animation == TRANSITION_DEATH_CERTIFICATE && game.currentDimensionIdx == DEATH_CERTIFICATE_DIMENSION) reconstruction_missing("RoomTransition::ChangeRoom 00830950: the players placed on the Death Certificate floor"); else if (animation == TRANSITION_DEATH_CERTIFICATE) diff --git a/src/room_update.cpp b/src/room_update.cpp index dbf8c52..d8680c0 100644 --- a/src/room_update.cpp +++ b/src/room_update.cpp @@ -127,7 +127,6 @@ constexpr int BEAST_FLY_VARIANTS[] = {11, 21}; constexpr int DOGMA_ANGEL = 2; constexpr int DOGMA_ANGEL_STATE = 10; constexpr int LASER_LOOP_VARIANTS[] = {6, 15}; -constexpr int EFFECT_COLOSTOMIA_PUDDLE = 168; constexpr int EFFECT_DOGMA_BLACKHOLE = 171; constexpr int EFFECT_URN_OF_SOULS = 178; constexpr int EFFECT_RIFT = 180; diff --git a/src/sfx_manager.h b/src/sfx_manager.h index 4721c7a..e091fe1 100644 --- a/src/sfx_manager.h +++ b/src/sfx_manager.h @@ -24,10 +24,20 @@ enum SoundLoop // The sounds several files play (Lua's SoundEffect). enum SoundId : int { + SOUND_BLOOD_LASER = 5, + SOUND_BLOOD_LASER_SMALL = 6, + SOUND_BLOOD_LASER_LARGE = 7, SOUND_BOOK_PAGE_TURN_12 = 8, + SOUND_BOSS_BUG_HISS = 9, + SOUND_BLOOD_LASER_LARGER = 10, + SOUND_BOSS_GURGLE_ROAR = 11, + SOUND_BOSS_LITE_GURGLE = 12, + SOUND_BOSS_LITE_HISS = 13, SOUND_BOSS_LITE_ROAR = 14, + SOUND_BOSS_LITE_SLOPPY_ROAR = 15, SOUND_BOSS_SPIT_BLOB_BARF = 16, SOUND_CHEST_OPEN = 22, + SOUND_CUTE_GRUNT = 25, SOUND_DEATH_BURST_LARGE = 28, SOUND_DEATH_REVERSE = 29, SOUND_FART = 37, @@ -40,20 +50,35 @@ enum SoundId : int SOUND_ISAAC_HURT_GRUNT = 55, SOUND_CHILD_ANGRY_ROAR = 57, SOUND_DIP_HURT = 60, + SOUND_MAGGOT_BURST_OUT = 64, + SOUND_MAGGOT_ENTER_GROUND = 66, SOUND_MEAT_JUMPS = 72, + SOUND_MOM_VOX_DEATH = 82, + SOUND_MOM_VOX_GRUNT = 93, + SOUND_MOM_VOX_HURT = 97, + SOUND_MOM_VOX_ISAAC = 101, + SOUND_MONSTER_GRUNT_0 = 104, SOUND_MONSTER_GRUNT_1 = 106, SOUND_MONSTER_GRUNT_2 = 108, SOUND_MONSTER_GRUNT_4 = 112, + SOUND_MONSTER_GRUNT_5 = 114, SOUND_MONSTER_ROAR_0 = 115, SOUND_MONSTER_ROAR_1 = 116, + SOUND_MONSTER_ROAR_2 = 117, + SOUND_MONSTER_YELL_A = 119, SOUND_POWERUP1 = 128, SOUND_POWERUP_SPEWER = 132, + SOUND_REDLIGHTNING_ZAP = 133, + SOUND_REDLIGHTNING_ZAP_WEAK = 134, + SOUND_REDLIGHTNING_ZAP_STRONG = 135, SOUND_ROCK_CRUMBLE = 137, SOUND_SHAKEY_KID_ROAR = 146, + SOUND_SINK_DRAIN_GURGLE = 149, SOUND_TEAR_IMPACTS = 150, SOUND_TEARS_FIRE = 153, SOUND_UNLOCK = 156, SOUND_VAMP_GULP = 157, + SOUND_WHEEZY_COUGH = 158, SOUND_SPIDER_COUGH = 159, SOUND_ANGRY_GURGLE = 167, SOUND_BATTERYCHARGE = 170, @@ -62,9 +87,12 @@ enum SoundId : int SOUND_BOIL_HATCH = 181, SOUND_BOSS2_BUBBLES = 185, SOUND_ERROR_BUZZ = 187, + SOUND_SATAN_HAND_LASER = 211, SOUND_HEARTIN = 212, SOUND_HEARTOUT = 213, + SOUND_HELL_PORTAL1 = 214, SOUND_HELL_PORTAL2 = 215, + SOUND_ISAACDIES = 217, SOUND_LEECH = 221, SOUND_MAGGOTCHARGE = 224, SOUND_METAL_BLOCKBREAK = 229, @@ -72,36 +100,81 @@ enum SoundId : int SOUND_SCAMPER = 249, SOUND_SHELLGAME = 252, SOUND_SPLATTER = 258, + SOUND_STONESHOOT = 262, + SOUND_WEIRD_WORM_SPIT = 263, SOUND_SUMMONSOUND = 265, SOUND_THUMBS_DOWN = 267, SOUND_THUMBSUP = 268, SOUND_HAPPY_RAINBOW = 270, + SOUND_LASERRING = 271, + SOUND_LASERRING_WEAK = 272, + SOUND_LASERRING_STRONG = 273, + SOUND_ANGEL_BEAM = 276, + SOUND_MEGA_BLAST_START = 278, + SOUND_MEGA_BLAST_END = 280, + SOUND_BOO_MAD = 300, SOUND_FART_GURG = 301, SOUND_FAT_WIGGLE = 303, + SOUND_FIRE_RUSH = 304, + SOUND_GHOST_ROAR = 305, + SOUND_GHOST_SHOOT = 306, + SOUND_LOW_INHALE = 310, + SOUND_MOUTH_FULL = 312, + SOUND_MULTI_SCREAM = 313, + SOUND_SKIN_PULL = 314, SOUND_WHISTLE = 315, SOUND_WORM_SPIT = 318, SOUND_LITTLE_SPIT = 319, + SOUND_WET_FEET = 398, SOUND_DANGLE_WHISTLE = 413, SOUND_LITTLE_HORN_COUGH = 414, SOUND_LITTLE_HORN_GRUNT_1 = 415, SOUND_LITTLE_HORN_GRUNT_2 = 416, + SOUND_THE_STAIN_BURST = 419, + SOUND_SHOVEL_DIG = 464, SOUND_GOLD_HEART_DROP = 466, + SOUND_DEMON_HIT = 477, SOUND_FLAME_BURST = 483, + SOUND_BATTERYDISCHARGE = 493, SOUND_FREEZE = 496, SOUND_FREEZE_SHATTER = 498, + SOUND_POOP_LASER = 589, SOUND_MOM_AND_DAD_1 = 598, SOUND_MOM_AND_DAD_2 = 599, SOUND_MOM_AND_DAD_3 = 600, SOUND_MOM_AND_DAD_4 = 601, SOUND_VAMP_DOUBLE = 614, SOUND_POOP_THROW = 865, + SOUND_GURDY_FACE_ATTACK_APPEAR = 939, + SOUND_GURDY_FACE_ATTACK_HIDE = 940, + SOUND_GURDY_FACE_SMILE_APPEAR = 941, + SOUND_GURDY_FACE_SMILE_HIDE = 942, SOUND_GURGLING_ATTACK = 943, SOUND_LITTLE_HORN_DEATH = 944, SOUND_LITTLE_HORN_BOMB_DROP = 945, SOUND_LITTLE_HORN_DIVE = 946, SOUND_LITTLE_HORN_HOLE_OPEN = 947, SOUND_LITTLE_HORN_HOLE_EXIT = 948, + SOUND_LOKI_GIGGLE = 949, + SOUND_LOKI_JUMP_OUT = 950, + SOUND_LOKI_JUMP_IN = 951, + SOUND_LOKI_SHOOT = 952, + SOUND_LOKI_SHOOT_8 = 953, + SOUND_STAIN_ATTACK_VOX = 959, + SOUND_TERATOMA_BOUNCE_BIG = 968, + SOUND_TERATOMA_BOUNCE_MEDIUM = 969, + SOUND_TERATOMA_BOUNCE_SMALL = 970, + SOUND_FORSAKEN_LASER = 971, + SOUND_FISTULA_BOUNCE_LARGE = 974, + SOUND_FISTULA_BURST_LARGE = 977, + SOUND_FISTULA_GROWL_LARGE = 978, + SOUND_FISTULA_GROWL_MEDIUM = 979, + SOUND_FISTULA_GROWL_SMALL = 980, SOUND_POOP_DROP = 990, + SOUND_HAUNT_CHARGE = 995, + SOUND_HAUNT_DEATH = 996, + SOUND_HAUNT_ROAR = 997, + SOUND_HAUNT_RELEASE_LIL = 998, SOUND_LARRY_JR_DEATH_1 = 999, SOUND_LARRY_JR_DEATH_2 = 1000, SOUND_LARRY_JR_ROAR = 1001, diff --git a/src/weapon.cpp b/src/weapon.cpp index 2265198..037e146 100644 --- a/src/weapon.cpp +++ b/src/weapon.cpp @@ -1,4 +1,5 @@ #include "weapon.h" +#include "weapon_lasers.h" #include "entity_familiar.h" #include "entity_player.h" #include "entity_tear.h" @@ -72,12 +73,13 @@ static Vector vector_scale(Vector v, float scale) { return vector_make(v.x * sca static bool is_zero(Vector v) { return v.x == 0 && v.y == 0; } -// 009f9020 Makes the weapon of a type for an owner through the type's maker, written only for tears (009f9260). +// 009f9020 Makes the weapon of a type for an owner through the type's maker, written for tears (009f9260) and the +// lasers (weapon_laser_make). WeaponPtr weapon_create(WeaponType type, Entity* owner) { - if (type != WEAPON_TEARS) reconstruction_missing("Isaac::CreateWeapon 009f9020 (weapons other than tears)"); + WeaponPtr weapon(type == WEAPON_TEARS ? new Weapon_Tears() : weapon_laser_make(type)); + if (!weapon) reconstruction_missing("Isaac::CreateWeapon 009f9020 (weapons other than tears and lasers)"); - WeaponPtr weapon(new Weapon_Tears()); weapon->Init(type, owner); return weapon; } @@ -192,7 +194,6 @@ Vector Weapon::get_owner_position() { return owner ? owner->pos : Vector{}; } float Weapon::get_damage() { reconstruction_missing("Weapon::get_damage 009f3c80"); } TearFlags Weapon::get_owner_tear_flags() { reconstruction_missing("Weapon::get_owner_tear_flags 009f3d00"); } ColorMod Weapon::get_tear_color() { reconstruction_missing("Weapon::get_tear_color 009f3db0"); } -ColorMod Weapon::get_laser_color() { reconstruction_missing("Weapon::get_laser_color 009f3f60"); } // 009f41c0 How the owner's volley spreads, or a volley of none without a player. Weapon_MultiShotParams Weapon::GetMultiShotParams() @@ -350,19 +351,7 @@ bool Weapon::is_held_item(ANM2&, std::string_view, void*) { reconstruction_missi void Weapon::stop_costume_item_anim(int) { reconstruction_missing("Weapon::stop_costume_item_anim 009f4ff0"); } bool Weapon::IsItemAnimFinished(int) { reconstruction_missing("Weapon::IsItemAnimFinished 009f50f0"); } bool Weapon::is_c_section_anim_finished() { reconstruction_missing("Weapon::is_c_section_anim_finished 009f5510"); } -Vector Weapon::GetOwnerLaserOffset(int, const Vector&) -{ - reconstruction_missing("Weapon::GetOwnerLaserOffset 009f5a30"); -} Entity_Bomb* Weapon::fire_bomb(Weapon&, const PosVel&) { reconstruction_missing("Weapon::fire_bomb 009f5d60"); } -Entity_Laser* Weapon::fire_brimstone_with_color(const Vector&, float, uint32_t) -{ - reconstruction_missing("Weapon::fire_brimstone_with_color 009f6570"); -} -Entity_Laser* Weapon::fire_laser(const Vector&, int, const Vector&, bool, bool, float) -{ - reconstruction_missing("Weapon::fire_laser 009f6610"); -} Entity_Knife* Weapon::fire_knife(Entity*, int, bool, float) { reconstruction_missing("Weapon::fire_knife 009f6a60"); } Entity_Knife* Weapon::FireSword(Entity*, int, float, bool, bool, int, Entity*) { diff --git a/src/weapon.h b/src/weapon.h index 16acfbd..f2dc545 100644 --- a/src/weapon.h +++ b/src/weapon.h @@ -64,6 +64,53 @@ enum InheritMode INHERIT_ALWAYS }; +// Where a player's laser leaves from (Lua's LaserOffset): an eye, the forehead, the mouth, Mom's Eye or the Tractor +// Beam's null. +enum LaserOffset : int +{ + LASER_OFFSET_NONE = -1, + LASER_OFFSET_TECH1, + LASER_OFFSET_TECH2, + LASER_OFFSET_TECH5, + LASER_OFFSET_SHOOP, + LASER_OFFSET_BRIMSTONE, + LASER_OFFSET_MOMS_EYE, + LASER_OFFSET_TRACTOR_BEAM +}; + +// How FireBrimstone fires a beam: weakened, as a burst of a charge-free beam, or as a short double one. +enum BrimstoneFireFlag : uint32_t +{ + BRIMSTONE_FIRE_WEAK = 1 << 7, + BRIMSTONE_FIRE_BURST = 1 << 9, + BRIMSTONE_FIRE_SHORT = 1 << 10, + BRIMSTONE_FIRE_C_SECTION = 1 << 11 +}; + +// A Technology laser to fire (Entity_Player::FireTechLaser's arguments): from a position along a direction, from an +// eye or another offset, once or lasting, and its damage scale. A source other than the player spawns it. +struct TechLaserShot +{ + Vector direction{}; + Vector position{}; + Entity* source = nullptr; + float damageScale = 1; + int offsetId = LASER_OFFSET_TECH1; + bool isLeftEye = false; + bool isOneHit = false; +}; + +// A Brimstone beam to fire (Weapon::FireBrimstone's arguments): from an entity at a position along a direction, its +// damage multiplier and BrimstoneFireFlags. +struct BrimstoneShot +{ + Vector direction{}; + Vector position{}; + Entity* entity = nullptr; + float damageMultiplier = 1; + uint32_t fireFlags = 0; +}; + // Construction (005cd690), assignment (006075a0) and copies (0065b490) are the defaults. // What a tear is fired with (REPENTOGON's TearParams): its look, flags and damage, and how its mass, knockback, speed // and side of the face scale. @@ -172,9 +219,9 @@ struct Weapon bool is_c_section_anim_finished(); Vector GetOwnerLaserOffset(int laserOffsetId, const Vector& shootDirection); static Entity_Bomb* fire_bomb(Weapon& weapon, const PosVel& shot); - Entity_Laser* fire_brimstone_with_color(const Vector& shootDirection, float damageMultiplier, uint32_t unknown); - Entity_Laser* fire_laser(const Vector& position, int offsetId, const Vector& shootDirection, bool isLeftEye, - bool isOneHit, float damageScale); + static Entity_Laser* FireBrimstone(const BrimstoneShot& shot); + Entity_Laser* fire_brimstone_with_color(const Vector& shootDirection, float damageMultiplier, uint32_t fireFlags); + Entity_Laser* fire_laser(const TechLaserShot& shot); Entity_Knife* fire_knife(Entity* knifeParent, int knifeVariant, bool isCantOverwrite, float rotationOffset); Entity_Knife* FireSword(Entity* swordParent, int swordVariant, float rotationOffset, bool isUnknown1, bool isUnknown2, int unknown3, Entity* unknown4); diff --git a/src/weapon_lasers.cpp b/src/weapon_lasers.cpp new file mode 100644 index 0000000..84d97ac --- /dev/null +++ b/src/weapon_lasers.cpp @@ -0,0 +1,481 @@ +#include "weapon_lasers.h" +#include "boss_ai.h" +#include "entity_familiar.h" +#include "entity_laser.h" +#include "entity_player.h" +#include "entity_tear.h" +#include "game.h" +#include "log.h" +#include "manager.h" +#include "npc_ai.h" +#include "sfx_manager.h" +#include + +constexpr float LASER_INHERIT_SCALE = 0.4f; +constexpr float LASER_AIM_SPEED = 10; +constexpr float LASER_BLINK_SCALE = -0.45f; +constexpr int LASER_BLINK_BASE = 7; +constexpr int LASER_SHOTS_PER_FRAME = 8; +constexpr float SPRAY_REACH = 70; +constexpr float SPRAY_SCATTER = 50; +constexpr float LUNG_SPRAY_SCALE_STEP = 0.4f; +constexpr float SPRAY_SCALE_MIN = 0.9f; +constexpr float SPRAY_SCALE_RANGE = 0.05f; +constexpr int SPRAY_CHAIN_MIN = 3; +constexpr int SPRAY_QUIET_COUNT = 5; +constexpr float LUNG_CHARGE = 4.3f; +constexpr float LASER_CHOCOLATE_CHARGE = 2.5f; +constexpr float CHARGE_MINIMUM = 0.001f; +constexpr float TECH_X_CHARGE = 3; +constexpr int MARKED_TARGET_VARIANT = 30; +constexpr int OCCULT_TARGET_VARIANT = 153; +constexpr float BRIMSTONE_WEAK_SCALE = 0.75f; +constexpr float BRIMSTONE_THICKER_SCALE = 1.5f; +constexpr int BRIMSTONE_TIMEOUT = 9; +constexpr int BRIMSTONE_BURST_TIMEOUT = 3; +constexpr float BRIMSTONE_SHORT_REACH = 30; +constexpr float BRIMSTONE_RANGE_SCALE = 0.25f; +constexpr float BRIMSTONE_RANGE_BASE = 32; +constexpr float BRIMSTONE_RANGE_MINIMUM = 60; +constexpr float FAMILIAR_BRIMSTONE_REACH = 10; +constexpr float FAMILIAR_BRIMSTONE_LIFT = 4; +constexpr float FAMILIAR_BRIMSTONE_HEIGHT = 23; +constexpr const char* NULL_MOUTH = "Mouth"; + +// 009f9020's makers for the laser weapons (009f94c0, 009f9640, 009f91f0): a fresh weapon of the type, or none for the +// other types. +Weapon* weapon_laser_make(WeaponType type) +{ + switch (type) + { + case WEAPON_LASER: + return new Weapon_Laser(); + case WEAPON_BRIMSTONE: + return new Weapon_Brimstone(); + case WEAPON_TECH_X: + return new Weapon_TechX(); + default: + return nullptr; + } +} + +// The player a weapon's owner fires for: the owner, or its familiar's player. +static Entity_Player* weapon_player(Entity* owner) +{ + if (!owner) return nullptr; + if (owner->type == ENTITY_PLAYER) return owner->ToPlayer(); + return owner->type == ENTITY_FAMILIAR ? static_cast(owner)->player : nullptr; +} + +// Marked's target, or Eye of the Occult's with it, or none. +static int marked_variant_get(Entity_Player* player) +{ + if (!player || !player->HasCollectible(COLLECTIBLE_MARKED)) return 0; + return player->HasCollectible(COLLECTIBLE_EYE_OF_THE_OCCULT) ? OCCULT_TARGET_VARIANT : MARKED_TARGET_VARIANT; +} + +// 009f3f60 The color the owner's lasers take: its player's laser color. A familiar's lasers are recolored by +// Baby-Bender, which is not reconstructed yet. Online, another player's lasers fade with the opacity option, which +// this offline build has no use for. +ColorMod Weapon::get_laser_color() +{ + Entity_Player* player = weapon_player(owner); + if (!player) return COLOR_DEFAULT; + if (owner->type == ENTITY_FAMILIAR) + reconstruction_missing("Weapon::get_laser_color 009f3f60 (a familiar's lasers)"); + return player->laserColor; +} + +// 009f5a30 Where the owner's laser of an offset leaves from: its player's eye or mouth. A familiar's are not +// reconstructed yet. +Vector Weapon::GetOwnerLaserOffset(int laserOffsetId, const Vector& shootDirection) +{ + if (!owner) return {}; + if (owner->type == ENTITY_PLAYER) return owner->ToPlayer()->GetLaserOffset(laserOffsetId, shootDirection); + if (owner->type == ENTITY_FAMILIAR) reconstruction_missing("Weapon::GetOwnerLaserOffset 009f5a30 (00631a00)"); + return {}; +} + +// 009f5f40 Fires a Brimstone beam: thicker with the damage, Technology's red-blue beam with it, doubled by a second +// Brimstone and by Azazel's Birthright or Stump, halved for a familiar or a burst (without Brimstone), the thicker +// variant past one and a half. It leaves the player's mouth (or a familiar's front) and takes the player's hit +// params. Azazel's short beam reaches by range. +Entity_Laser* Weapon::FireBrimstone(const BrimstoneShot& shot) +{ + Entity* entity = shot.entity; + Entity_Familiar* familiar = + entity && entity->type == ENTITY_FAMILIAR ? static_cast(entity) : nullptr; + Entity_Player* player = + familiar ? familiar->player : (entity && entity->type == ENTITY_PLAYER ? entity->ToPlayer() : nullptr); + bool isBurst = shot.fireFlags & BRIMSTONE_FIRE_BURST; + bool hasBrimstone = player && player->HasCollectible(COLLECTIBLE_BRIMSTONE); + + float scale = std::sqrt(shot.damageMultiplier); + if (shot.fireFlags & BRIMSTONE_FIRE_WEAK) scale *= BRIMSTONE_WEAK_SCALE; + if (familiar) scale *= 0.5f; + int variant = LASER_THICK_RED; + if (player) + { + if (player->HasCollectible(COLLECTIBLE_TECHNOLOGY)) variant = LASER_BRIM_TECH; + if (player->GetCollectibleNum(COLLECTIBLE_BRIMSTONE) > 1) scale += scale; + } + if (!isBurst || hasBrimstone) + { + if (shot.fireFlags & BRIMSTONE_FIRE_SHORT) scale += scale; + } + else + scale *= 0.5f; + bool isAzazelBeam = player && (player->playerType == PLAYER_AZAZEL || + player->temporaryEffects.HasTrinketEffect(TRINKET_AZAZELS_STUMP)); + if (player && player->playerType == PLAYER_AZAZEL && + (player->HasCollectible(COLLECTIBLE_BIRTHRIGHT) || + player->temporaryEffects.HasTrinketEffect(TRINKET_AZAZELS_STUMP))) + scale += scale; + if (scale > BRIMSTONE_THICKER_SCALE) + { + variant = variant == LASER_BRIM_TECH ? LASER_THICKER_BRIM_TECH : LASER_THICKER_RED; + scale *= 0.5f; + } + + Vector offset{}; + if (familiar) + offset = vector_make(shot.direction.x * FAMILIAR_BRIMSTONE_REACH, + FAMILIAR_BRIMSTONE_LIFT - std::abs(shot.direction.x) * FAMILIAR_BRIMSTONE_LIFT - + FAMILIAR_BRIMSTONE_HEIGHT); + else if (player && player->HasCollectible(COLLECTIBLE_C_SECTION)) + offset = vector_make(0, player->sprite.scale.y * C_SECTION_LASER_LIFT); + else if (player) + { + offset = vector_scale(player->GetCostumeNullPos(NULL_MOUTH, true, Vector{}), 1 / LASER_SCREEN_SCALE); + if (player->canFly) + offset = vector_add(offset, vector_scale(player->GetFlyingOffset(), 1 / LASER_SCREEN_SCALE)); + } + + bool isBurstBeam = + (shot.fireFlags & (BRIMSTONE_FIRE_BURST | BRIMSTONE_FIRE_WEAK)) == BRIMSTONE_FIRE_BURST && !hasBrimstone; + Entity_Laser* laser = + Entity_Laser::ShootAngle({.position = shot.position, + .posOffset = offset, + .source = entity, + .angleDegrees = vector_angle(shot.direction), + .timeout = isBurstBeam ? BRIMSTONE_BURST_TIMEOUT : BRIMSTONE_TIMEOUT, + .variant = variant}); + laser->damageMultiplier = shot.damageMultiplier; + laser->set_scale(scale); + + TearParams params; + if (player) + { + int displacement = (int)(Random() & 1) * 2 - 1; + params = player->GetTearHitParams(WEAPON_BRIMSTONE, shot.damageMultiplier, displacement, entity); + } + laser->SetCollisionDamage(params.tearDamage); + laser->renderDepthOffset = shot.direction.y <= -TECH_LASER_FACING ? TECH_LASER_BACK_DEPTH : TECH_LASER_FRONT_DEPTH; + if (isAzazelBeam && !hasBrimstone) + laser->maxDistance = + std::max(player->tearRange * BRIMSTONE_RANGE_SCALE + BRIMSTONE_RANGE_BASE, BRIMSTONE_RANGE_MINIMUM); + else if (shot.fireFlags & BRIMSTONE_FIRE_SHORT) + laser->maxDistance = BRIMSTONE_SHORT_REACH; + + float massMultiplier = params.massMultiplier; + if (isBurst && !hasBrimstone) massMultiplier *= 0.5f; + laser->isPlayerParams = true; + laser->mass *= massMultiplier; + laser->tearFlags = params.tearFlags; + return laser; +} + +// 009f6570 Fires a Brimstone beam from the owner in the owner's laser color. +Entity_Laser* Weapon::fire_brimstone_with_color(const Vector& shootDirection, float damageMultiplier, + uint32_t fireFlags) +{ + Entity_Laser* laser = FireBrimstone({.direction = shootDirection, + .position = get_owner_position(), + .entity = owner, + .damageMultiplier = damageMultiplier, + .fireFlags = fireFlags}); + laser->SetColor(get_laser_color(), -1, COLOR_PRIORITY_DEFAULT, false, true); + return laser; +} + +// 009f6610 Fires a Technology laser: the player's own, a familiar's (not reconstructed yet), or a plain one from the +// owner. +Entity_Laser* Weapon::fire_laser(const TechLaserShot& shot) +{ + if (owner && owner->type == ENTITY_PLAYER) return owner->ToPlayer()->FireTechLaser(shot); + if (owner && owner->type == ENTITY_FAMILIAR) + reconstruction_missing("Weapon::fire_laser 009f6610 (a familiar's laser)"); + + return Entity_Laser::ShootAngle({.position = get_owner_position(), + .source = owner, + .angleDegrees = vector_angle(shot.direction), + .timeout = TECH_LASER_TIMEOUT, + .variant = LASER_THIN_RED}); +} + +// 00a052a0 Forgets the charges. The base's reset does not run. +void Weapon_Laser::Reset() +{ + cursedEyeCharges = 0; + chargeAtRelease = 0; +} + +// 00a063b0 Removes Technology 2's laser and Ludovico's ring, and forgets them. +void Weapon_Laser::ClearReferences() +{ + for (EntityPtr* laser : {&technology2Laser, &ludovicoLaser}) + { + if (!*laser) continue; + (*laser)->Remove(); + *laser = nullptr; + } +} + +// 00a06870 The charge a full shot takes: Monstro's Lung's, Chocolate Milk's and Cursed Eye's, none without them. +float Weapon_Laser::GetMaxCharge() +{ + float multiplier = 1; + if (modifiers & WEAPON_MOD_MONSTROS_LUNG) multiplier = LUNG_CHARGE; + if (modifiers & WEAPON_MOD_CHOCOLATE_MILK) multiplier *= LASER_CHOCOLATE_CHARGE; + if (modifiers & WEAPON_MOD_CURSED_EYE) multiplier += multiplier; + return multiplier > 1 ? (maxFireDelay + 1) * multiplier - 1 : 0; +} + +// Ludovico's ring is what the camera follows (Weapon_Bombs::GetFocusEntity, which lasers share). +Entity* Weapon_Laser::GetFocusEntity() +{ + return (modifiers & WEAPON_MOD_LUDOVICO_TECHNIQUE) ? ludovicoLaser.get() : nullptr; +} + +// Marked's target, as Brimstone's (Weapon_Brimstone::GetMarkedTargetVariant, which lasers share). +int Weapon_Laser::GetMarkedTargetVariant() +{ + return (modifiers & WEAPON_MOD_LUDOVICO_TECHNIQUE) ? 0 : marked_variant_get(weapon_player(owner)); +} + +// 00a068e0 Whether a half charged shot lets Cursed Eye teleport the player: not while Marked aims. +bool Weapon_Laser::CanTriggerCursedEyeTeleport() +{ + if (!owner || owner->type != ENTITY_PLAYER) return false; + if (owner->ToPlayer()->markedTarget && GetMarkedTargetVariant()) return false; + return charge > 0 && charge < GetMaxCharge(); +} + +// Lasers ride a Tractor Beam unless Ludovico holds them (Weapon_Knife::SupportsTractorBeam, which lasers share). +bool Weapon_Laser::SupportsTractorBeam() +{ + return !(modifiers & WEAPON_MOD_LUDOVICO_TECHNIQUE); +} + +// 00a06330 Gives a laser the owner's tear flags, laser color and damage. +void Weapon_Laser::init_laser(Weapon& weapon, Entity_Laser& laser) +{ + laser.tearFlags = weapon.get_owner_tear_flags(); + laser.SetColor(weapon.get_laser_color(), -1, COLOR_PRIORITY_DEFAULT, false, true); + laser.SetCollisionDamage(weapon.get_damage()); +} + +// 00a06420 Fires a volley: one laser per shot of the volley, offset and turned by it, or a spray of shorter lasers +// around the direction, each scaled at random and chaining three or four more (the spray's sound plays for a big +// one). +std::vector Weapon_Laser::fire_lasers(const LaserVolley& volley) +{ + std::vector fired; + int shots = volley.params ? volley.params->numTears : 1; + Entity_Player* player = weapon_player(owner); + float shotSpeed = player ? player->shotSpeed : 1; + + for (int i = 0; i < shots; i++) + { + Vector position = volley.position; + Vector direction = volley.direction; + if (volley.params) + { + PosVel shot = Entity_Player::GetMultiShotPositionVelocity(i, WEAPON_LASER, volley.direction, shotSpeed, + *volley.params); + position = vector_add(position, shot.position); + direction = shot.velocity; + } + TechLaserShot laserShot = {.direction = direction, + .position = position, + .damageScale = volley.damageScale, + .offsetId = volley.offsetId, + .isLeftEye = true, + .isOneHit = true}; + if (volley.sprayCount < 1) + { + fired.push_back(fire_laser(laserShot)); + continue; + } + + Vector reach = vector_scale(direction, SPRAY_REACH); + for (int spray = 0; spray < volley.sprayCount; spray++) + { + float angle = random_unit() * RANDOM_HALF_TURN * 2; + float scatter = random_unit(); + Vector aim = vector_add(reach, vector_make(std::cos(angle) * SPRAY_SCATTER * scatter, + std::sin(angle) * SPRAY_SCATTER * scatter)); + laserShot.direction = vector_normalized(aim); + Entity_Laser* laser = fire_laser(laserShot); + laser->maxDistance = vector_length(aim); + float growth = (float)(Random() & 1) * LUNG_SPRAY_SCALE_STEP + SPRAY_SCALE_MIN; + laser->scale *= growth + random_unit() * SPRAY_SCALE_RANGE; + laser->ResetSpriteScale(); + laser->chainedLasers = (int)(Random() & 1) + SPRAY_CHAIN_MIN; + laser->isDisableInitSound = volley.sprayCount > SPRAY_QUIET_COUNT; + fired.push_back(laser); + } + if (volley.sprayCount > SPRAY_QUIET_COUNT) npc_sound_play(SOUND_BLOOD_LASER_LARGE, 1, 2, 1); + } + return fired; +} + +// 00a052b0 Fires Technology's lasers: one volley per fire delay passed this frame (at most eight), from the eye with +// the volley's extra backward, sideways and random lasers, carrying a share of the owner's movement unless a +// Tractor Beam holds them. Ludovico's ring and the charged shots (Monstro's Lung, Chocolate Milk, Cursed Eye) are +// not reconstructed yet. +void Weapon_Laser::Fire(const Vector& shootDirection, bool isShooting, bool isInterpolated) +{ + Weapon::Fire(shootDirection, isShooting, isInterpolated); + if (modifiers & WEAPON_MOD_LUDOVICO_TECHNIQUE) + reconstruction_missing("Weapon_Laser::Fire 00a052b0 (Ludovico's ring)"); + if (modifiers & (WEAPON_MOD_MONSTROS_LUNG | WEAPON_MOD_CHOCOLATE_MILK | WEAPON_MOD_CURSED_EYE)) + reconstruction_missing("Weapon_Laser::Fire 00a052b0 (charged lasers)"); + + int shots = 0; + if (isShooting) + { + if (isInterpolated) return; + while (fireDelay < 0 && shots < LASER_SHOTS_PER_FRAME) + { + shots++; + fireDelay += maxFireDelay + 1; + } + chargeAtRelease = 0; + } + + Vector aim = isShooting ? shootDirection : direction; + aim = IsAxisAligned() ? vector_cardinal(aim) : vector_normalized(aim); + if (shots > 0) + { + bool isTractorBeam = modifiers & WEAPON_MOD_TRACTOR_BEAM; + Vector velocity = vector_scale(aim, LASER_AIM_SPEED); + if (!isTractorBeam) + velocity = vector_add(velocity, vector_scale(get_tear_movement_inheritance(aim), LASER_INHERIT_SCALE)); + aim = vector_normalized(velocity); + SetBlinkTime(LASER_BLINK_BASE - (int)(maxFireDelay * LASER_BLINK_SCALE)); + TriggerTearEffects(aim, 1); + + Weapon_MultiShotParams params = GetMultiShotParams(); + LaserVolley volley = {.direction = aim, .position = get_owner_position(), .params = ¶ms}; + std::vector fired = fire_lasers(volley); + volley.params = nullptr; + volley.offsetId = LASER_OFFSET_MOMS_EYE; + auto fire_more = [&](Vector extra) { + volley.direction = extra; + std::vector more = fire_lasers(volley); + fired.insert(fired.end(), more.begin(), more.end()); + }; + if (params.isShootingBackwards) fire_more(vector_make(-aim.x, -aim.y)); + if (params.isShootingSideways) + { + fire_more(vector_make(aim.y, -aim.x)); + fire_more(vector_make(-aim.y, aim.x)); + } + for (int i = 0; i < params.numRandomDirTears; i++) fire_more(random_direction()); + for (Entity_Laser* laser : fired) + { + laser->isDisableFollowParent = !isTractorBeam; + laser->Update(); + } + } + + if (isShooting) direction = IsAxisAligned() ? aim : get_aim_direction(aim); +} + +// 00a00f30 The charge a full beam takes: the fire delay (Chocolate Milk's two and a half of it), none under Ludovico. +float Weapon_Brimstone::GetMaxCharge() +{ + if (modifiers & WEAPON_MOD_LUDOVICO_TECHNIQUE) return 0; + float multiplier = (modifiers & WEAPON_MOD_CHOCOLATE_MILK) ? LASER_CHOCOLATE_CHARGE : 1; + return std::max(maxFireDelay, CHARGE_MINIMUM) * multiplier; +} + +// 00a02790 Removes Technology 2's laser and the main beam, and forgets them. +void Weapon_Brimstone::ClearReferences() +{ + for (EntityPtr* laser : {&technology2Laser, &mainLaser}) + { + if (!*laser) continue; + (*laser)->Remove(); + *laser = nullptr; + } +} + +// 00a02870 The camera follows Ludovico's beam. +Entity* Weapon_Brimstone::GetFocusEntity() +{ + return (modifiers & WEAPON_MOD_LUDOVICO_TECHNIQUE) ? mainLaser.get() : nullptr; +} + +// 009f3160 The beam it fires as. +Entity* Weapon_Brimstone::GetMainEntity() +{ + return mainLaser; +} + +// 00a02800 Marked's target, Eye of the Occult's with it, none under Ludovico. +int Weapon_Brimstone::GetMarkedTargetVariant() +{ + return (modifiers & WEAPON_MOD_LUDOVICO_TECHNIQUE) ? 0 : marked_variant_get(weapon_player(owner)); +} + +// The charging and firing of Brimstone are not reconstructed yet. + +// 009ff360 +void Weapon_Brimstone::Fire(const Vector&, bool, bool) +{ + reconstruction_missing("Weapon_Brimstone::Fire 009ff360"); +} + +// 00a00d10 +void Weapon_Brimstone::fire_c_section_fetuses() +{ + reconstruction_missing("Weapon_Brimstone::fire_c_section_fetuses 00a00d10"); +} + +// 00a00f90 +void Weapon_Brimstone::init_laser(Entity_Laser&) +{ + reconstruction_missing("Weapon_Brimstone::init_laser 00a00f90"); +} + +// 00a01020 +void Weapon_Brimstone::fire_hitscan() +{ + reconstruction_missing("Weapon_Brimstone::fire_hitscan 00a01020"); +} + +// 00a02890 +void Weapon_Brimstone::fire(float, bool) +{ + reconstruction_missing("Weapon_Brimstone::fire 00a02890"); +} + +// 00a0e260 The charge a full ring takes: three fire delays. +float Weapon_TechX::GetMaxCharge() +{ + return maxFireDelay * TECH_X_CHARGE; +} + +// Marked's target, as Monstro's Lung picks it, which Tech X shares. +int Weapon_TechX::GetMarkedTargetVariant() +{ + return marked_variant_get(weapon_player(owner)); +} + +// 00a0d9c0 The charging and firing of Tech X's rings are not reconstructed yet. +void Weapon_TechX::Fire(const Vector&, bool, bool) +{ + reconstruction_missing("Weapon_TechX::Fire 00a0d9c0"); +} diff --git a/src/weapon_lasers.h b/src/weapon_lasers.h new file mode 100644 index 0000000..2a8d94a --- /dev/null +++ b/src/weapon_lasers.h @@ -0,0 +1,68 @@ +#pragma once + +#include "weapon.h" +#include + +// A volley of lasers Weapon_Laser::fire_lasers fires: from a position along a direction, from an offset, at a +// damage scale, spread by the volley's params (one laser without them), or as a spray of shorter chained lasers. +struct LaserVolley +{ + Vector direction{}; + Vector position{}; + const Weapon_MultiShotParams* params = nullptr; + float damageScale = 1; + int offsetId = LASER_OFFSET_TECH1; + int sprayCount = 0; +}; + +// Destruction (009f9930) is the default. +// The weapon that fires Technology's lasers, Monstro's Lung's spray of them, and Ludovico's laser ring. +struct Weapon_Laser : Weapon +{ + EntityPtr ludovicoLaser; + float chargeAtRelease = 0; + int cursedEyeCharges = 0; + + void Fire(const Vector& shootDirection, bool isShooting, bool isInterpolated) override; + void Reset() override; + void ClearReferences() override; + float GetMaxCharge() override; + Entity* GetFocusEntity() override; + int GetMarkedTargetVariant() override; + bool CanTriggerCursedEyeTeleport() override; + bool SupportsTractorBeam() override; + + std::vector fire_lasers(const LaserVolley& volley); + static void init_laser(Weapon& weapon, Entity_Laser& laser); +}; + +// Destruction (009f9a20) is the default. +// The weapon that charges and fires Brimstone's beams. +struct Weapon_Brimstone : Weapon +{ + EntityPtr mainLaser; + float aimAngle = 0; + + void Fire(const Vector& shootDirection, bool isShooting, bool isInterpolated) override; + void ClearReferences() override; + float GetMaxCharge() override; + Entity* GetFocusEntity() override; + Entity* GetMainEntity() override; + int GetMarkedTargetVariant() override; + + void fire_c_section_fetuses(); + void init_laser(Entity_Laser& laser); + void fire_hitscan(); + void fire(float speed, bool isStatusIgnored); +}; + +// Destruction (009f3260) is the base's. +// The weapon that charges and fires Tech X's rings. +struct Weapon_TechX : Weapon +{ + void Fire(const Vector& shootDirection, bool isShooting, bool isInterpolated) override; + float GetMaxCharge() override; + int GetMarkedTargetVariant() override; +}; + +Weapon* weapon_laser_make(WeaponType type);