Curation round 9: floors and walls, room transitions, collision, the first enemies, saving, damage, pickups
Seven agents took over the backdrop's floor and wall rendering, room transitions (StartRoomTransition, on_leave, room_enter), grid collision with tear hits and decal baking, Entity_NPC's core with the AI dispatch and the first enemies (flies, Gaper, Pooter, Clotty, Horf, Dip, Spider), the run's save, player damage, PlayerManager::Update, ShowName, pickups, slots and the common effects. Integration added LuaEngine::PostNewLevel/PostNewRoom, one shared lua_callback_check (4 copies merged) and the enemy type range the original checks. Under gdb a run draws its rooms with floors and walls, walks between rooms, fights Gapers with contact damage and the damage flash, and collects pickups. Next: tears hitting enemies, pathfinding, item pedestals, death. 2891 functions taken over. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
69a354f843
commit
48933cd312
59 files changed
+13387
-6056
No files matched your search
+1963
-67
File diff suppressed because it is too large.
Load diff
+66
-9
@@ -6,10 +6,30 @@
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
// backdrops.xml fills ids 1 to 62. Id 0 is the default the others start from.
|
||||
constexpr int BACKDROP_COUNT = 63;
|
||||
|
||||
// How a piece of a backdrop sheet is mirrored as it is drawn, by bit.
|
||||
enum Flip
|
||||
{
|
||||
FLIP_NONE,
|
||||
FLIP_X,
|
||||
FLIP_Y,
|
||||
FLIP_XY
|
||||
};
|
||||
|
||||
// Which walls a wall detail sprite shows its layers on, by bit: the layers named h... on the top and bottom walls, the
|
||||
// layers named v... on the side walls.
|
||||
enum WallSides
|
||||
{
|
||||
WALL_SIDES_NONE,
|
||||
WALL_SIDES_HORIZONTAL,
|
||||
WALL_SIDES_VERTICAL,
|
||||
WALL_SIDES_ALL
|
||||
};
|
||||
|
||||
// Construction, copies, assignment and destruction (00931de0, 00934600, 00934430, 009324f0) are the defaults.
|
||||
// A room background of backdrops.xml: its wall and floor sheet and how many walls and floors it cuts into, the floor
|
||||
// overlays, the water, and the grid graphics (rocks, pits, doors ...) rooms of it use. Paths are under resources/.
|
||||
@@ -37,6 +57,38 @@ struct BackdropConfig
|
||||
bool isReverseWaterGfx = false;
|
||||
};
|
||||
|
||||
// A cell of wall drawn into the wall surface, for the effects its backdrop adds there: where it was drawn, its place on
|
||||
// the sheet's block (slotX along the top wall, slotY down the side wall), the sheet's wall row and its variant.
|
||||
struct WallSlot
|
||||
{
|
||||
DestinationQuad quad{};
|
||||
int slotX = 0;
|
||||
int slotY = 0;
|
||||
int variant = 0;
|
||||
int wallRow = 0;
|
||||
Flip flip = FLIP_NONE;
|
||||
};
|
||||
|
||||
// A corner of the room's walls a wall detail sprite is drawn at, and how likely each of its layers shows.
|
||||
struct WallDetail
|
||||
{
|
||||
Vector position{};
|
||||
float chance = 0;
|
||||
Flip flip = FLIP_NONE;
|
||||
WallSides sides = WALL_SIDES_NONE;
|
||||
};
|
||||
|
||||
// One row of the start room's control icons, laid out from the left: each icon's button frame and position, the
|
||||
// cursor the icons are drawn from, and the controller whose bindings they show.
|
||||
struct ControlRow
|
||||
{
|
||||
std::vector<int> frames;
|
||||
std::vector<float> positions;
|
||||
float cursorX = 0;
|
||||
float x = 0;
|
||||
int controllerIndex = 0;
|
||||
};
|
||||
|
||||
// Destruction (00932570) is the default.
|
||||
// A room's background (Room's backdrop): the configs of backdrops.xml, and the walls, floor and water of the
|
||||
// room's backdrop, drawn once into surfaces the room renders from.
|
||||
@@ -65,20 +117,25 @@ struct Backdrop
|
||||
bool LoadConfig(std::string_view path);
|
||||
void Init(uint32_t id, bool isLoadGraphics);
|
||||
uint32_t get_random_floor_variant();
|
||||
KAGE::Graphics::ColorQuad render_grid_rect(int x, int y, int width, int height);
|
||||
DestinationQuad render_grid_rect(int x, int y, int width, int height);
|
||||
|
||||
void load_details();
|
||||
void pre_render_walls();
|
||||
void PreRenderControls();
|
||||
void render_control_icon();
|
||||
void render_ashpit_ash();
|
||||
void render_floor_to_target();
|
||||
void spawn_detail_effects(Vector offset, bool isFlipX, bool isFlipY);
|
||||
void spawn_wall_details();
|
||||
void render_wall_detail();
|
||||
void render_wall_borders(Vector roomTopLeftPos, Vector roomSize);
|
||||
void render_floor_to_target(uint32_t variant, const KAGE::Graphics::ImagePtr& sheet,
|
||||
const KAGE::Graphics::ImagePtr& alternate);
|
||||
void PreRenderControls();
|
||||
void render_control_icon(ControlRow& row, int action);
|
||||
void pre_render_walls();
|
||||
void spawn_wall_details(const WallSlot& slot);
|
||||
void render_wall_detail(const WallDetail& detail);
|
||||
|
||||
void RenderFloor(Vector renderOffset, ColorMod color);
|
||||
void render_floor_surface(Vector renderOffset, ColorMod color);
|
||||
void RenderWalls(Vector renderOffset, ColorMod color);
|
||||
void render_wall_borders(Vector roomTopLeftPos, Vector roomSize);
|
||||
void RenderWater(Vector renderOffset);
|
||||
};
|
||||
|
||||
int controller_button_to_glyph_frame(int button);
|
||||
Vector backdrop_detail_to_world_pos(Vector position);
|
||||
Vector backdrop_wall_normal(int slotX, Flip flip);
|
||||
@@ -1284,18 +1284,6 @@ void Entity::convert_shot_for_enemy_owner(Entity*)
|
||||
reconstruction_missing("Entity::convert_shot_for_enemy_owner 0064bb70");
|
||||
}
|
||||
|
||||
// 006a9c90
|
||||
void Entity::CollideWithGrid(GridCollisionMode)
|
||||
{
|
||||
reconstruction_missing("Entity::CollideWithGrid 006a9c90");
|
||||
}
|
||||
|
||||
// 006ab240
|
||||
bool Entity::is_grid_collision_at(const Vector&)
|
||||
{
|
||||
reconstruction_missing("Entity::is_grid_collision_at 006ab240");
|
||||
}
|
||||
|
||||
// 006ace60
|
||||
bool Entity::TakeDamage(float, uint64_t, const EntityRef&, int)
|
||||
{
|
||||
@@ -1368,36 +1356,6 @@ void Entity::RemoveStatusEffects()
|
||||
reconstruction_missing("Entity::RemoveStatusEffects 006ae630");
|
||||
}
|
||||
|
||||
// 006b2210
|
||||
float Entity::collision_mass_get(Entity*)
|
||||
{
|
||||
reconstruction_missing("Entity::collision_mass_get 006b2210");
|
||||
}
|
||||
|
||||
// 006b25b0
|
||||
void Entity::push_apart_capsule(Entity*)
|
||||
{
|
||||
reconstruction_missing("Entity::push_apart_capsule 006b25b0");
|
||||
}
|
||||
|
||||
// 006b2940
|
||||
bool Entity::push_apart_circle(Entity*)
|
||||
{
|
||||
reconstruction_missing("Entity::push_apart_circle 006b2940");
|
||||
}
|
||||
|
||||
// 006b2ee0
|
||||
void Entity::collide_with_entity(Entity*)
|
||||
{
|
||||
reconstruction_missing("Entity::collide_with_entity 006b2ee0");
|
||||
}
|
||||
|
||||
// 006b2f50
|
||||
bool Entity::ForceCollide(Entity*, Entity*, bool)
|
||||
{
|
||||
reconstruction_missing("Entity::ForceCollide 006b2f50");
|
||||
}
|
||||
|
||||
// 006b45c0
|
||||
void Entity::BloodExplode()
|
||||
{
|
||||
|
||||
+1
-1
@@ -58,7 +58,7 @@ enum EntityType : int
|
||||
|
||||
// The types an enemy can have, both ends included.
|
||||
constexpr int ENTITY_FIRST_ENEMY = 10;
|
||||
constexpr int ENTITY_LAST_ENEMY = 997;
|
||||
constexpr int ENTITY_LAST_ENEMY = 999;
|
||||
|
||||
// Lua's EntityFlag: the state and status effects an entity carries.
|
||||
enum EntityFlag : uint64_t
|
||||
|
||||
+579
-63
@@ -1,8 +1,13 @@
|
||||
#include "entity_collision.h"
|
||||
#include "entity_player.h"
|
||||
#include "entity_projectile.h"
|
||||
#include "game.h"
|
||||
#include "grid_entity_door.h"
|
||||
#include "log.h"
|
||||
#include "manager.h"
|
||||
#include "room.h"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
|
||||
// What crushes rocks on contact: The Nail, Leo (worn or rolled by Zodiac), Thunder Thighs, Stompy and Mega Mush.
|
||||
@@ -10,6 +15,8 @@ constexpr int COLLECTIBLE_THE_NAIL = 83;
|
||||
constexpr int COLLECTIBLE_LEO = 302;
|
||||
constexpr int COLLECTIBLE_THUNDER_THIGHS = 314;
|
||||
constexpr int PLAYERFORM_STOMPY = 13;
|
||||
// A transformation counts once the player holds this many of its items.
|
||||
constexpr int PLAYER_FORM_ITEMS = 3;
|
||||
|
||||
// A poop's reach for a player's collision: a giga poop's quarter from its shared center, any other from its cell's.
|
||||
constexpr int POOP_GIGA_FIRST = 7;
|
||||
@@ -22,37 +29,163 @@ constexpr std::array<float, 4> POOP_GIGA_CENTER_X = {POOP_GIGA_QUARTER, -POOP_GI
|
||||
constexpr std::array<float, 4> POOP_GIGA_CENTER_Y = {POOP_GIGA_QUARTER, POOP_GIGA_QUARTER, -POOP_GIGA_QUARTER,
|
||||
-POOP_GIGA_QUARTER};
|
||||
|
||||
// The grid collision a player passes, through the Lost's mirror door or past a wall it is pushed out of.
|
||||
constexpr uint32_t GRID_COLLISION_WALL_EXCEPT_PLAYER = 5;
|
||||
// The Lost passes the mirror door in the mirror world.
|
||||
constexpr int MIRROR_DIMENSION = 1;
|
||||
|
||||
// The Beast's dungeon keeps players this far above its floor's center line.
|
||||
constexpr float BEAST_DUNGEON_OFFSET_Y = 20;
|
||||
// A wall hit keeps this much of the speed into it, and pushes back this much more.
|
||||
// A player's wall hit keeps this much of the speed into it, any other entity's turns it back this much, and both
|
||||
// push back a little more. Entities then lose up to half their speed against the wall.
|
||||
constexpr float WALL_BOUNCE = 0.9f;
|
||||
constexpr float WALL_REBOUND = 1.8f;
|
||||
constexpr float WALL_PUSH = 0.1f;
|
||||
constexpr float WALL_FRICTION = 0.5f;
|
||||
constexpr float NORMAL_EPSILON = 0.001f;
|
||||
constexpr float PUSH_OUT_MIN_SPEED = 2;
|
||||
constexpr int PUSH_OUT_STEPS_GROUND = 12;
|
||||
constexpr int PUSH_OUT_STEPS = 6;
|
||||
constexpr float HALF_CELL = GRID_CELL_SIZE / 2;
|
||||
|
||||
// The enemies that bounce harder off walls, with the sounds some make.
|
||||
constexpr int ENTITY_GURDY_JR = 99;
|
||||
constexpr int ENTITY_DIP = 217;
|
||||
constexpr int ENTITY_SQUIRT = 220;
|
||||
constexpr int ENTITY_BALL_AND_CHAIN = 893;
|
||||
constexpr int ENTITY_SINGE = 915;
|
||||
constexpr int SINGE_BALL = 1;
|
||||
constexpr float REBOUND_GURDY_JR = 1.4f;
|
||||
constexpr float REBOUND_BOUNCER = 1.2f;
|
||||
constexpr int SOUND_DEATH_BURST_LARGE = 28;
|
||||
constexpr int SOUND_STONE_IMPACT = 487;
|
||||
constexpr int SOUND_BALL_AND_CHAIN_HIT = 581;
|
||||
constexpr float BOUNCE_VOLUME_SCALE = 0.05f;
|
||||
constexpr float BOUNCE_VOLUME_BASE = 0.2f;
|
||||
constexpr float BOUNCE_VOLUME_MAX = 1.2f;
|
||||
constexpr float BOUNCE_PITCH_BASE = 0.9f;
|
||||
constexpr float BOUNCE_PITCH_SPREAD = 0.2f;
|
||||
constexpr float RANDOM_UNIT_SCALE = 2.3283064e-10f;
|
||||
|
||||
// Samson's Chains' ball breaks rocks it hits faster than this.
|
||||
constexpr int FAMILIAR_SAMSONS_CHAINS = 75;
|
||||
constexpr float CHAINS_CRUSH_SPEED_SQUARED = 25;
|
||||
|
||||
// Mega Satan's room lets shots leave through its walls.
|
||||
constexpr int BOSS_MEGA_SATAN = 55;
|
||||
|
||||
// The room types whose doors Notched Axe hacks open.
|
||||
constexpr int ROOM_TYPE_SECRET = 7;
|
||||
constexpr int ROOM_TYPE_SUPERSECRET = 8;
|
||||
|
||||
// A world position's cell index in the room, or -1 off its grid.
|
||||
static int grid_index_at(Room& room, Vector position)
|
||||
// What weighs an entity down as it collides: a magnet against enemies, Mega Mush and the Cube Baby for a player,
|
||||
// enemies that shots barely move, and what makes a player shrug off projectiles.
|
||||
constexpr float MASS_HEAVY = 10;
|
||||
constexpr float MASS_ANCHORED = 100;
|
||||
constexpr float MASS_PROJECTILE_PROOF = 20;
|
||||
constexpr int FAMILIAR_CUBE_BABY = 239;
|
||||
constexpr int COLLECTIBLE_ISAACS_HEART = 276;
|
||||
constexpr int NULL_TOOTH_AND_NAIL = 59;
|
||||
// Charger, Boom Fly, Knight, Leech, Pin, Swarmer, Floating Knight, Bone Knight, Poop and Movable TNT.
|
||||
constexpr std::array<int, 10> SHOT_ANCHORED_TYPES = {23, 25, 41, 55, 62, 91, 254, 283, 245, 292};
|
||||
|
||||
// Two entities closer than this are not pushed apart. A player or the Punching Bag is not pushed into a wall.
|
||||
constexpr float PUSH_MIN_DISTANCE = 0.0001f;
|
||||
constexpr int FAMILIAR_PUNCHING_BAG = 67;
|
||||
constexpr float PLAYER_PUSH_SHARE = 0.5f;
|
||||
constexpr float BEAST_PUSH_DAMPING = 0.25f;
|
||||
|
||||
// One side of a push apart: the direction it moves along, the impulse its velocity takes, the overlap and its share.
|
||||
struct EntityPush
|
||||
{
|
||||
int column = (int)((position.x - GRID_ORIGIN_X) / GRID_CELL_SIZE + 0.5f);
|
||||
int row = (int)((position.y - GRID_ORIGIN_Y) / GRID_CELL_SIZE + 0.5f);
|
||||
if (column < 0 || column >= room.gridWidth || row < 0 || row >= room.gridHeight) return -1;
|
||||
return room.gridWidth * row + column;
|
||||
Vector direction{};
|
||||
Vector impulse{};
|
||||
float overlap = 0;
|
||||
float share = 0;
|
||||
};
|
||||
|
||||
static float vector_length(Vector v)
|
||||
{
|
||||
return std::sqrt(v.x * v.x + v.y * v.y);
|
||||
}
|
||||
|
||||
// The grid entity on a cell, or none past the grid.
|
||||
static GridEntity* grid_entity_at(Room& room, int gridIndex)
|
||||
// A vector scaled to length one, or as it is with no length (Vector::Normalized).
|
||||
static Vector vector_normalized(Vector v)
|
||||
{
|
||||
return gridIndex >= 0 && gridIndex < ROOM_GRID_CELLS ? room.gridEntities[gridIndex] : nullptr;
|
||||
float length = vector_length(v);
|
||||
if (length > 0) return vector_make(v.x * (1 / length), v.y * (1 / length));
|
||||
return v;
|
||||
}
|
||||
|
||||
static bool is_unit_size(const Entity& entity)
|
||||
{
|
||||
return entity.sizeMulti.x == 1 && entity.sizeMulti.y == 1;
|
||||
}
|
||||
|
||||
static bool is_wall(uint32_t collision)
|
||||
{
|
||||
return collision == COLLISION_WALL || collision == COLLISION_WALL_EXCEPT_PLAYER;
|
||||
}
|
||||
|
||||
static bool is_singe_ball(const Entity& entity)
|
||||
{
|
||||
return entity.type == ENTITY_SINGE && entity.variant == SINGE_BALL;
|
||||
}
|
||||
|
||||
// Plays a sound through the fart seeds.
|
||||
static void sound_play(int sound, float volume, float pitch)
|
||||
{
|
||||
seed_fart_sound_override(&sound);
|
||||
g_manager->sfxManager.Play(sound, {.volume = volume, .pitch = pitch});
|
||||
}
|
||||
|
||||
// The knock of a heavy ball, louder the faster it goes, at a slightly random pitch.
|
||||
static void bounce_sound_play(int sound, float speed)
|
||||
{
|
||||
float pitch = (float)Random() * RANDOM_UNIT_SCALE * BOUNCE_PITCH_SPREAD + BOUNCE_PITCH_BASE;
|
||||
sound_play(sound, std::min(speed * BOUNCE_VOLUME_SCALE + BOUNCE_VOLUME_BASE, BOUNCE_VOLUME_MAX), pitch);
|
||||
}
|
||||
|
||||
// Moves an entity back along a wall's normal out of what blocks it, bisecting for steps tries between its depth into
|
||||
// the wall and that depth less its speed (at least two).
|
||||
template <typename IsFreeAt>
|
||||
static void grid_push_out(Entity& entity, Vector normal, int steps, IsFreeAt isFreeAt)
|
||||
{
|
||||
float depth = std::sqrt(normal.y * entity.sizeMulti.y * (normal.y * entity.sizeMulti.y) +
|
||||
normal.x * entity.sizeMulti.x * (normal.x * entity.sizeMulti.x)) *
|
||||
entity.size;
|
||||
float freeDepth = depth - std::max(vector_length(entity.velocity), PUSH_OUT_MIN_SPEED);
|
||||
float blockedDepth = depth;
|
||||
for (int step = 0; step < steps; step++)
|
||||
{
|
||||
float middle = (blockedDepth - freeDepth) * 0.5f + freeDepth;
|
||||
Vector at = vector_make(normal.x * middle + entity.pos.x, normal.y * middle + entity.pos.y);
|
||||
(isFreeAt(at) ? freeDepth : blockedDepth) = middle;
|
||||
}
|
||||
entity.pos.x += normal.x * (freeDepth - depth);
|
||||
entity.pos.y += normal.y * (freeDepth - depth);
|
||||
}
|
||||
|
||||
// A crushed rock bridges the pit beyond it, on the axis its crusher came along.
|
||||
static void crush_bridge(Room& room, Entity& crusher, GridEntity& rock)
|
||||
{
|
||||
Vector center = room.GetGridPosition(rock.gridIndex);
|
||||
float dx = center.x - crusher.pos.x;
|
||||
float dy = center.y - crusher.pos.y;
|
||||
float directionX = 0;
|
||||
float directionY = 0;
|
||||
if (std::abs(dx) > std::abs(dy)) directionX = dx < 0 ? -1 : 1;
|
||||
else directionY = dy < 0 ? -1 : 1;
|
||||
|
||||
int beyond = room.GetGridIndex(
|
||||
vector_make(center.x + directionX * GRID_CELL_SIZE, center.y + directionY * GRID_CELL_SIZE));
|
||||
GridEntity* pit = room.GetGridEntity(beyond);
|
||||
if (pit && pit->type == GRID_PIT) reconstruction_missing("Room::TryMakeBridge 0081e6e0");
|
||||
}
|
||||
|
||||
// 007aa7c0 Whether the player has a transformation: three items of its set, out of the cursed mist and alive.
|
||||
bool Entity_Player::HasPlayerForm(int playerForm)
|
||||
{
|
||||
if (hasCurseMistEffect || isCoopGhost || playerForm < 0 || playerForm >= PLAYER_FORM_SLOTS) return false;
|
||||
return playerForms[playerForm] >= PLAYER_FORM_ITEMS;
|
||||
}
|
||||
|
||||
// 006b5fd0 The grid collision a player meets at a position: a poop only within its reach, the Lost's way through a
|
||||
@@ -60,9 +193,9 @@ static GridEntity* grid_entity_at(Room& room, int gridIndex)
|
||||
uint32_t Entity_Player::get_grid_collision_at(Vector position)
|
||||
{
|
||||
Room& room = *g_game->room;
|
||||
int gridIndex = grid_index_at(room, position);
|
||||
int gridIndex = room.GetGridIndex(position);
|
||||
uint32_t collision = room.GetGridCollision(gridIndex);
|
||||
GridEntity* grid = grid_entity_at(room, gridIndex);
|
||||
GridEntity* grid = room.GetGridEntity(gridIndex);
|
||||
if (collision == COLLISION_SOLID && grid && grid->type == GRID_POOP)
|
||||
{
|
||||
bool isGiga = grid->variant >= POOP_GIGA_FIRST && grid->variant <= POOP_GIGA_LAST;
|
||||
@@ -85,9 +218,9 @@ uint32_t Entity_Player::get_grid_collision_at(Vector position)
|
||||
if (!(door.doorFlags & DOOR_FLAG_MIRROR) || door.state == DOOR_STATE_OPEN) return COLLISION_WALL;
|
||||
bool isSpirit = GetHealthType() == HEALTH_NO_HEALTH || HasInstantDeathCurse();
|
||||
if (!isSpirit && g_game->currentDimensionIdx != MIRROR_DIMENSION) return COLLISION_WALL;
|
||||
collision = GRID_COLLISION_WALL_EXCEPT_PLAYER;
|
||||
collision = COLLISION_WALL_EXCEPT_PLAYER;
|
||||
}
|
||||
else if (collision != GRID_COLLISION_WALL_EXCEPT_PLAYER) return collision;
|
||||
else if (collision != COLLISION_WALL_EXCEPT_PLAYER) return collision;
|
||||
|
||||
// The original reads a non-player's fields here. A non-player meets the wall.
|
||||
if (type != ENTITY_PLAYER || variant != 0 || isCoopGhost || parent || IsHologram()) return COLLISION_WALL;
|
||||
@@ -127,24 +260,6 @@ static void mega_mush_crush(Room& room, Entity& player, GridEntity& grid, int gr
|
||||
if (room.gridEntities[gridIndex]) room.gridEntities[gridIndex]->Destroy(false, EntityRef(&player));
|
||||
}
|
||||
|
||||
// A crushed rock bridges the pit beyond it, on the axis the player came along.
|
||||
static void crush_bridge(Room& room, Entity& player, GridEntity& rock)
|
||||
{
|
||||
Vector center = room.GetGridPosition(rock.gridIndex);
|
||||
float dx = center.x - player.pos.x;
|
||||
float dy = center.y - player.pos.y;
|
||||
float directionX = 0;
|
||||
float directionY = 0;
|
||||
if (std::abs(dx) > std::abs(dy)) directionX = dx < 0 ? -1 : 1;
|
||||
else directionY = dy < 0 ? -1 : 1;
|
||||
|
||||
int beyond = grid_index_at(
|
||||
room, vector_make(center.x + directionX * GRID_CELL_SIZE, center.y + directionY * GRID_CELL_SIZE));
|
||||
if (beyond < 0) return;
|
||||
GridEntity* pit = grid_entity_at(room, beyond);
|
||||
if (pit && pit->type == GRID_PIT) reconstruction_missing("Room::TryMakeBridge 0081e6e0");
|
||||
}
|
||||
|
||||
// What a player does to the grid entity at one of its collision points: Mega Mush stomps blocks and kicks doors and
|
||||
// webs, rock crushers break what they touch, Notched Axe opens secret doors. Returns whether the point is spent on it.
|
||||
static bool player_grid_act(Room& room, Entity_Player& player, GridEntity* grid, int gridIndex, uint32_t collision)
|
||||
@@ -182,7 +297,7 @@ static bool player_grid_act(Room& room, Entity_Player& player, GridEntity* grid,
|
||||
bool isSecret = door.currentRoomType == ROOM_TYPE_SECRET || door.targetRoomType == ROOM_TYPE_SECRET ||
|
||||
door.currentRoomType == ROOM_TYPE_SUPERSECRET || door.targetRoomType == ROOM_TYPE_SUPERSECRET;
|
||||
if (!isSecret) return false;
|
||||
if (GridEntity* target = grid_entity_at(room, gridIndex)) target->Destroy(false, EntityRef(&player));
|
||||
if (GridEntity* target = room.GetGridEntity(gridIndex)) target->Destroy(false, EntityRef(&player));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -232,14 +347,14 @@ void Entity::PlayerCollideWithGrid(GridCollisionMode mode)
|
||||
for (const Vector& point : collisionPoints)
|
||||
{
|
||||
Vector position = vector_make(pos.x + point.x, pos.y + point.y);
|
||||
int gridIndex = grid_index_at(room, position);
|
||||
int gridIndex = room.GetGridIndex(position);
|
||||
if (gridIndex < 0) continue;
|
||||
GridEntity* grid = grid_entity_at(room, gridIndex);
|
||||
GridEntity* grid = room.GetGridEntity(gridIndex);
|
||||
uint32_t collision = player->get_grid_collision_at(position);
|
||||
if (!isSimulated && player_grid_act(room, *player, grid, gridIndex, collision)) continue;
|
||||
|
||||
bool isWall = collision == COLLISION_WALL || (collision == COLLISION_SOLID && grid && grid->type == GRID_DOOR);
|
||||
bool isBlocked = collision != COLLISION_NONE && collision != GRID_COLLISION_WALL_EXCEPT_PLAYER;
|
||||
bool isBlocked = collision != COLLISION_NONE && collision != COLLISION_WALL_EXCEPT_PLAYER;
|
||||
if ((entityGridCollisionClass == GRIDCOLL_WALLS && isWall) ||
|
||||
(entityGridCollisionClass == GRIDCOLL_GROUND && isBlocked))
|
||||
{
|
||||
@@ -248,18 +363,12 @@ void Entity::PlayerCollideWithGrid(GridCollisionMode mode)
|
||||
}
|
||||
}
|
||||
|
||||
float lengthSquared = normal.x * normal.x + normal.y * normal.y;
|
||||
if (lengthSquared < NORMAL_EPSILON)
|
||||
if (normal.x * normal.x + normal.y * normal.y < NORMAL_EPSILON)
|
||||
{
|
||||
if (!isSimulated) gridCollisionNormal = {};
|
||||
return;
|
||||
}
|
||||
float length = std::sqrt(lengthSquared);
|
||||
if (length > 0)
|
||||
{
|
||||
normal.x *= 1 / length;
|
||||
normal.y *= 1 / length;
|
||||
}
|
||||
normal = vector_normalized(normal);
|
||||
if (!isSimulated) gridCollisionNormal = normal;
|
||||
|
||||
float approach = -normal.x * velocity.x - normal.y * velocity.y;
|
||||
@@ -272,22 +381,429 @@ void Entity::PlayerCollideWithGrid(GridCollisionMode mode)
|
||||
velocity.y += push * gridCollisionNormal.y;
|
||||
}
|
||||
|
||||
float depth = std::sqrt(normal.y * sizeMulti.y * (normal.y * sizeMulti.y) +
|
||||
normal.x * sizeMulti.x * (normal.x * sizeMulti.x)) *
|
||||
size;
|
||||
float speed = std::sqrt(velocity.x * velocity.x + velocity.y * velocity.y);
|
||||
float freeDepth = depth - std::max(speed, PUSH_OUT_MIN_SPEED);
|
||||
float blockedDepth = depth;
|
||||
bool isGround = entityGridCollisionClass == GRIDCOLL_GROUND;
|
||||
for (int step = 0; step < (isGround ? PUSH_OUT_STEPS_GROUND : PUSH_OUT_STEPS); step++)
|
||||
{
|
||||
float middle = (blockedDepth - freeDepth) * 0.5f + freeDepth;
|
||||
uint32_t collision =
|
||||
player->get_grid_collision_at(vector_make(normal.x * middle + pos.x, normal.y * middle + pos.y));
|
||||
bool isFree = isGround ? collision == COLLISION_NONE || collision == GRID_COLLISION_WALL_EXCEPT_PLAYER
|
||||
: collision != COLLISION_WALL;
|
||||
(isFree ? freeDepth : blockedDepth) = middle;
|
||||
}
|
||||
pos.x += normal.x * (freeDepth - depth);
|
||||
pos.y += normal.y * (freeDepth - depth);
|
||||
grid_push_out(*this, normal, isGround ? PUSH_OUT_STEPS_GROUND : PUSH_OUT_STEPS,
|
||||
[player, isGround](Vector at)
|
||||
{
|
||||
uint32_t collision = player->get_grid_collision_at(at);
|
||||
return isGround ? collision == COLLISION_NONE || collision == COLLISION_WALL_EXCEPT_PLAYER
|
||||
: collision != COLLISION_WALL;
|
||||
});
|
||||
}
|
||||
|
||||
// Clamps a wall-bound entity into the room along its one axis, noting the hit with a normal back into the room.
|
||||
static void axis_clamp(Entity& entity, Vector clamped, bool isAxisX, bool isSimulated)
|
||||
{
|
||||
float& coordinate = isAxisX ? entity.pos.x : entity.pos.y;
|
||||
float target = isAxisX ? clamped.x : clamped.y;
|
||||
if (!isSimulated && coordinate != target)
|
||||
{
|
||||
entity.isCollidesWithGrid = true;
|
||||
entity.gridCollisionVelocity = entity.velocity;
|
||||
float direction = coordinate <= target ? 1.0f : -1.0f;
|
||||
entity.gridCollisionNormal = isAxisX ? vector_make(direction, 0) : vector_make(0, direction);
|
||||
}
|
||||
coordinate = target;
|
||||
}
|
||||
|
||||
// Clamps an entity into the room. Applied, the hit is noted, and the returned normal points out of the room along
|
||||
// each axis it was clamped on.
|
||||
static Vector room_clamp(Entity& entity, Vector clamped, bool isSimulated)
|
||||
{
|
||||
Vector normal{};
|
||||
if (!isSimulated && (entity.pos.x != clamped.x || entity.pos.y != clamped.y))
|
||||
{
|
||||
entity.isCollidesWithGrid = true;
|
||||
entity.gridCollisionVelocity = entity.velocity;
|
||||
if (entity.pos.x != clamped.x) normal.x = entity.pos.x <= clamped.x ? -1 : 1;
|
||||
if (entity.pos.y != clamped.y) normal.y = entity.pos.y <= clamped.y ? -1 : 1;
|
||||
}
|
||||
entity.pos = clamped;
|
||||
return normal;
|
||||
}
|
||||
|
||||
// A shot only notes where it stands in what stops it: a wall it does not fly back from (Mega Satan's room and rooms
|
||||
// without walls let it leave), a rock or other solid, and for a tear an object too. Pits stop nothing.
|
||||
static void shot_grid_collide(Entity& shot, Room& room)
|
||||
{
|
||||
bool isOpen = room.bossId == BOSS_MEGA_SATAN ||
|
||||
(room.descriptor && (room.descriptor->flags & ROOM_DESCRIPTOR_FLAG_NO_WALLS));
|
||||
int gridIndex = room.GetGridIndex(shot.pos);
|
||||
uint32_t collision = room.GetGridCollision(gridIndex);
|
||||
if (is_wall(collision))
|
||||
{
|
||||
Vector clamped = room.GetClampedPositionImpl(shot.pos, 0, 0, 0, 0);
|
||||
bool isOutside = clamped.x != shot.pos.x || clamped.y != shot.pos.y;
|
||||
float inward = (clamped.y - shot.pos.y) * shot.velocity.y + (clamped.x - shot.pos.x) * shot.velocity.x;
|
||||
if (isOutside && (isOpen || inward >= 0)) return;
|
||||
}
|
||||
else if (collision != COLLISION_SOLID && (shot.type != ENTITY_TEAR || collision != COLLISION_OBJECT)) return;
|
||||
|
||||
GridEntity* grid = room.GetGridEntity(gridIndex);
|
||||
if (!grid || grid->type == GRID_PIT) return;
|
||||
shot.isCollidesWithGrid = true;
|
||||
shot.gridCollisionVelocity = shot.velocity;
|
||||
}
|
||||
|
||||
// Whether a cell blocks an entity of a grid collision class: anything for ground, all but pits for pits only, what
|
||||
// stands for no pits, and walls outside crawlspaces for walls.
|
||||
static bool is_cell_blocked(int gridClass, uint32_t collision, GridEntity* grid)
|
||||
{
|
||||
switch (gridClass)
|
||||
{
|
||||
case GRIDCOLL_GROUND: return collision != COLLISION_NONE;
|
||||
case GRIDCOLL_PITSONLY: return collision != COLLISION_PIT;
|
||||
case GRIDCOLL_NOPITS:
|
||||
return collision != COLLISION_NONE && collision != COLLISION_PIT && (!grid || grid->type != GRID_PIT);
|
||||
default: return is_wall(collision) && g_game->room->roomType != ROOM_DUNGEON;
|
||||
}
|
||||
}
|
||||
|
||||
// Whether the push out of a wall stops at a cell for a grid collision class.
|
||||
static bool is_cell_free(int gridClass, uint32_t collision)
|
||||
{
|
||||
switch (gridClass)
|
||||
{
|
||||
case GRIDCOLL_GROUND: return collision == COLLISION_NONE;
|
||||
case GRIDCOLL_PITSONLY: return collision == COLLISION_PIT;
|
||||
case GRIDCOLL_NOPITS: return collision == COLLISION_NONE || collision == COLLISION_PIT;
|
||||
default: return !is_wall(collision);
|
||||
}
|
||||
}
|
||||
|
||||
// Samson's Chains' ball breaks a rock it hits fast enough, bridging the pit beyond. Whether it broke one.
|
||||
static bool chains_crush(Entity& ball, Room& room, GridEntity& grid)
|
||||
{
|
||||
float speedSquared = ball.velocity.x * ball.velocity.x + ball.velocity.y * ball.velocity.y;
|
||||
if (speedSquared <= CHAINS_CRUSH_SPEED_SQUARED || grid.collisionClass != COLLISION_SOLID) return false;
|
||||
if (!grid.Destroy(false, EntityRef(&ball))) return false;
|
||||
|
||||
crush_bridge(room, ball, grid);
|
||||
return true;
|
||||
}
|
||||
|
||||
// The sum of the collision points in cells that block the entity. Samson's Chains' ball that meets a rock without
|
||||
// breaking it starts the sum over.
|
||||
static Vector blocked_points_sum(Entity& entity, Room& room, int gridClass, bool isSimulated)
|
||||
{
|
||||
bool isChains = !isSimulated && entity.type == ENTITY_FAMILIAR && entity.variant == FAMILIAR_SAMSONS_CHAINS &&
|
||||
gridClass == GRIDCOLL_NOPITS;
|
||||
Vector sum{};
|
||||
for (const Vector& point : entity.collisionPoints)
|
||||
{
|
||||
int gridIndex = room.GetGridIndex(vector_make(entity.pos.x + point.x, entity.pos.y + point.y));
|
||||
uint32_t collision = room.GetGridCollision(gridIndex);
|
||||
GridEntity* grid = room.GetGridEntity(gridIndex);
|
||||
if (is_cell_blocked(gridClass, collision, grid))
|
||||
{
|
||||
sum.x += point.x;
|
||||
sum.y += point.y;
|
||||
}
|
||||
|
||||
bool isHit = collision == COLLISION_SOLID || collision == COLLISION_OBJECT;
|
||||
if (isChains && isHit && grid && !chains_crush(entity, room, *grid)) sum = {};
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
// A tear whose collision points cancel out takes its normal from where it sits in its cell: back along the axis it is
|
||||
// nearer the cell's edge on, when it reaches past one.
|
||||
static Vector tear_cell_normal(Entity& tear, Room& room, Vector normal)
|
||||
{
|
||||
Vector center = room.GetGridPosition(room.GetGridIndex(tear.pos));
|
||||
float halfWidth = tear.size * tear.sizeMulti.x;
|
||||
float offsetX = tear.pos.x - center.x;
|
||||
float offsetY = tear.pos.y - center.y;
|
||||
if (std::abs(offsetX) + halfWidth >= HALF_CELL && std::abs(offsetY) + tear.size * tear.sizeMulti.y >= HALF_CELL)
|
||||
return normal;
|
||||
|
||||
if (std::abs(tear.sizeMulti.x * offsetX) > std::abs(tear.sizeMulti.y * offsetY))
|
||||
return vector_make(offsetX > 0 ? -halfWidth : halfWidth, 0);
|
||||
float halfHeight = tear.sizeMulti.y * tear.size;
|
||||
return vector_make(0, offsetY > 0 ? -halfHeight : halfHeight);
|
||||
}
|
||||
|
||||
// Turns an entity back from a wall it runs into, harder for Gurdy Jr., Dips, Squirts and the heavy balls, which
|
||||
// knock.
|
||||
static void wall_bounce(Entity& entity, float approach)
|
||||
{
|
||||
entity.gridCollisionVelocity = entity.velocity;
|
||||
entity.isCollidesWithGrid = true;
|
||||
float push = approach * WALL_REBOUND - WALL_PUSH;
|
||||
if (entity.type == ENTITY_GURDY_JR)
|
||||
{
|
||||
sound_play(SOUND_DEATH_BURST_LARGE, std::min(-approach * BOUNCE_VOLUME_SCALE, BOUNCE_VOLUME_MAX), 1);
|
||||
push *= REBOUND_GURDY_JR;
|
||||
}
|
||||
else if (entity.type == ENTITY_DIP || entity.type == ENTITY_SQUIRT) push *= REBOUND_BOUNCER;
|
||||
else if (is_singe_ball(entity) || entity.type == ENTITY_BALL_AND_CHAIN)
|
||||
{
|
||||
bool isChain = entity.type == ENTITY_BALL_AND_CHAIN;
|
||||
bounce_sound_play(isChain ? SOUND_BALL_AND_CHAIN_HIT : SOUND_STONE_IMPACT, vector_length(entity.velocity));
|
||||
push *= REBOUND_BOUNCER;
|
||||
}
|
||||
entity.velocity.x += push * entity.gridCollisionNormal.x;
|
||||
entity.velocity.y += push * entity.gridCollisionNormal.y;
|
||||
}
|
||||
|
||||
// 006a9c90 An entity's collision with the room's grid by its grid collision class: clamped into the room along one
|
||||
// axis or both, a shot only noting what stops it, the rest pushed out along the normal of the cells their collision
|
||||
// points are blocked in, bouncing off and slowed. Simulating (Interpolate's prediction) only moves the position.
|
||||
// A projectile in a crawlspace flies over pits rather than stopping at walls only.
|
||||
void Entity::CollideWithGrid(GridCollisionMode mode)
|
||||
{
|
||||
bool isSimulated = mode == GRID_COLLISION_SIMULATE;
|
||||
if (!isSimulated) isCollidesWithGrid = false;
|
||||
if (minecart || entityGridCollisionClass == GRIDCOLL_NONE) return;
|
||||
|
||||
Room& room = *g_game->room;
|
||||
int gridClass = entityGridCollisionClass;
|
||||
if (type == ENTITY_PROJECTILE && gridClass == GRIDCOLL_BULLET && room.roomType == ROOM_DUNGEON)
|
||||
gridClass = GRIDCOLL_NOPITS;
|
||||
|
||||
Vector clamped = room.GetClampedPositionImpl(pos, 0, 0, 0, 0);
|
||||
if (gridClass == GRIDCOLL_WALLS_X || gridClass == GRIDCOLL_WALLS_Y)
|
||||
return axis_clamp(*this, clamped, gridClass == GRIDCOLL_WALLS_X, isSimulated);
|
||||
if (gridClass == GRIDCOLL_BULLET)
|
||||
{
|
||||
if (!isSimulated) shot_grid_collide(*this, room);
|
||||
return;
|
||||
}
|
||||
|
||||
Vector clampNormal = room_clamp(*this, clamped, isSimulated);
|
||||
if (collisionPoints.empty()) return;
|
||||
Vector normal = blocked_points_sum(*this, room, gridClass, isSimulated);
|
||||
if (normal.x == 0 && normal.y == 0)
|
||||
{
|
||||
if (!isSimulated) gridCollisionNormal = clampNormal;
|
||||
return;
|
||||
}
|
||||
|
||||
bool isCancelled = normal.y * normal.y + normal.x * normal.x < NORMAL_EPSILON;
|
||||
if (type == ENTITY_TEAR && isCancelled) normal = tear_cell_normal(*this, room, normal);
|
||||
else if (IsEnemy() && gridClass == GRIDCOLL_GROUND && isCancelled)
|
||||
reconstruction_missing("Room::FindFreeTilePosition 0081e520");
|
||||
normal = vector_normalized(normal);
|
||||
if (!isSimulated) gridCollisionNormal = normal;
|
||||
|
||||
float approach = -normal.x * velocity.x - velocity.y * normal.y;
|
||||
if (approach >= 0) return;
|
||||
if (!isSimulated) wall_bounce(*this, approach);
|
||||
|
||||
float speed = vector_length(velocity);
|
||||
int steps = gridClass == GRIDCOLL_GROUND ? PUSH_OUT_STEPS_GROUND : PUSH_OUT_STEPS;
|
||||
auto isFreeAt = [&room, gridClass](Vector at)
|
||||
{ return is_cell_free(gridClass, room.GetGridCollision(room.GetGridIndex(at))); };
|
||||
if (speed > 0) grid_push_out(*this, normal, steps, isFreeAt);
|
||||
if (isSimulated) return;
|
||||
|
||||
float slowdown = 1 - (-approach / speed) * WALL_FRICTION;
|
||||
velocity.y *= slowdown;
|
||||
velocity.x *= slowdown;
|
||||
}
|
||||
|
||||
// 006ab240 Whether the entity's collision points, moved by an offset, meet walls (or a solid door) for a walls class,
|
||||
// or anything but a players' wall for a ground class.
|
||||
bool Entity::is_grid_collision_at(const Vector& offset)
|
||||
{
|
||||
if (entityGridCollisionClass == GRIDCOLL_NONE) return false;
|
||||
|
||||
Room& room = *g_game->room;
|
||||
Vector sum{};
|
||||
for (const Vector& point : collisionPoints)
|
||||
{
|
||||
int gridIndex = room.GetGridIndex(vector_make(point.x + offset.x + pos.x, point.y + pos.y + offset.y));
|
||||
if (gridIndex < 0) continue;
|
||||
|
||||
uint32_t collision = room.GetGridCollision(gridIndex);
|
||||
GridEntity* grid = room.GetGridEntity(gridIndex);
|
||||
bool isWall = collision == COLLISION_WALL || (collision == COLLISION_SOLID && grid && grid->type == GRID_DOOR);
|
||||
bool isBlocked = collision != COLLISION_NONE && collision != COLLISION_WALL_EXCEPT_PLAYER;
|
||||
if ((entityGridCollisionClass == GRIDCOLL_WALLS && isWall) ||
|
||||
(entityGridCollisionClass == GRIDCOLL_GROUND && isBlocked))
|
||||
{
|
||||
sum.x += point.x;
|
||||
sum.y += point.y;
|
||||
}
|
||||
}
|
||||
return sum.x != 0 || sum.y != 0;
|
||||
}
|
||||
|
||||
// 006b2210 How much the entity weighs against another as they push apart: heavier when magnetized against enemies,
|
||||
// as a player against the Cube Baby or under Mega Mush, as an enemy shots barely move, and as a player whom
|
||||
// projectiles do not move (Isaac's Heart, Tooth and Nail, the Forgotten's soul).
|
||||
float Entity::collision_mass_get(Entity* other)
|
||||
{
|
||||
float weight = mass;
|
||||
if (HasEntityFlags(FLAG_MAGNETIZED) && is_enemy_type(other->type)) weight *= MASS_HEAVY;
|
||||
if (type == ENTITY_PLAYER)
|
||||
{
|
||||
if (other->type == ENTITY_FAMILIAR && other->variant == FAMILIAR_CUBE_BABY) weight *= MASS_HEAVY;
|
||||
if (static_cast<Entity_Player*>(this)->temporaryEffects.HasCollectibleEffect(COLLECTIBLE_MEGA_MUSH))
|
||||
weight *= MASS_HEAVY;
|
||||
}
|
||||
|
||||
bool isShot = other->type == ENTITY_TEAR || other->type == ENTITY_LASER;
|
||||
bool isAnchored = std::ranges::find(SHOT_ANCHORED_TYPES, type) != SHOT_ANCHORED_TYPES.end();
|
||||
if (is_enemy_type(type) && isShot && isAnchored) weight *= MASS_ANCHORED;
|
||||
if (type != ENTITY_PLAYER || other->type != ENTITY_PROJECTILE) return weight;
|
||||
|
||||
Entity_Player& player = static_cast<Entity_Player&>(*this);
|
||||
bool isProof = player.HasCollectible(COLLECTIBLE_ISAACS_HEART) ||
|
||||
player.temporaryEffects.HasNullEffect(NULL_TOOTH_AND_NAIL) ||
|
||||
player.playerType == PLAYER_THEFORGOTTEN_B;
|
||||
return isProof ? weight * MASS_PROJECTILE_PROOF : weight;
|
||||
}
|
||||
|
||||
// Moves an entity by its share of a push and changes its velocity by its share of the impulse. In the Beast's dungeon
|
||||
// a player only slows, a quarter as much. An entity without physics knockback stays.
|
||||
static void push_apply(Entity& entity, const EntityPush& push)
|
||||
{
|
||||
if (entity.HasEntityFlags(FLAG_NO_PHYSICS_KNOCKBACK)) return;
|
||||
|
||||
Vector impulse = push.impulse;
|
||||
if (g_game->room->IsBeastDungeon() && entity.type == ENTITY_PLAYER)
|
||||
impulse = vector_make(impulse.x * BEAST_PUSH_DAMPING, impulse.y * BEAST_PUSH_DAMPING);
|
||||
else
|
||||
{
|
||||
entity.pos.x += push.direction.x * push.share * push.overlap;
|
||||
entity.pos.y += push.direction.y * push.share * push.overlap;
|
||||
}
|
||||
entity.velocity.x += impulse.x * push.share;
|
||||
entity.velocity.y += impulse.y * push.share;
|
||||
}
|
||||
|
||||
// 006b2940 Pushes the entity and another apart as circles when they overlap and may meet, the lower type first.
|
||||
// Each moves by the other's share of their weights (a player half as far, and not into a wall) and their velocities
|
||||
// trade along the line between them. Whether they met.
|
||||
bool Entity::push_apart_circle(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 delta = vector_make(second.pos.x - first.pos.x, second.pos.y - first.pos.y);
|
||||
float reach = first.size + second.size;
|
||||
float distanceSquared = delta.y * delta.y + delta.x * delta.x;
|
||||
if (!(distanceSquared < reach * reach) || is_collision_ignored(first, second)) return false;
|
||||
|
||||
first.isCollidesWithEntity = second.type != ENTITY_TEAR;
|
||||
second.isCollidesWithEntity = first.type != ENTITY_TEAR;
|
||||
float distance = std::sqrt(distanceSquared);
|
||||
if (distance < PUSH_MIN_DISTANCE) return true;
|
||||
|
||||
Vector relative = vector_make(first.velocity.x - second.velocity.x, first.velocity.y - second.velocity.y);
|
||||
if (reach * 0.5f < vector_length(relative) && delta.y * relative.y + delta.x * relative.x < 0)
|
||||
{
|
||||
Vector relativeDirection = vector_normalized(relative);
|
||||
Vector deltaDirection = vector_normalized(delta);
|
||||
float dot = relativeDirection.y * deltaDirection.y + relativeDirection.x * deltaDirection.x;
|
||||
delta.y = dot * delta.y + dot * delta.y + delta.y;
|
||||
delta.x = delta.x + dot * delta.x + dot * delta.x;
|
||||
distance = std::sqrt(delta.y * delta.y + delta.x * delta.x);
|
||||
}
|
||||
|
||||
float firstWeight = first.collision_mass_get(&second);
|
||||
float secondShare = firstWeight / (second.collision_mass_get(&first) + firstWeight);
|
||||
float firstShare = 1 - secondShare;
|
||||
float overlap = (reach - distance) / distance;
|
||||
bool isWallBound = first.type == ENTITY_PLAYER ||
|
||||
(first.type == ENTITY_FAMILIAR && first.variant == FAMILIAR_PUNCHING_BAG);
|
||||
if (isWallBound &&
|
||||
first.is_grid_collision_at(vector_make(-delta.x * firstShare * overlap, -delta.y * firstShare * overlap)))
|
||||
{
|
||||
secondShare = 1;
|
||||
firstShare = 0;
|
||||
}
|
||||
if (first.type == ENTITY_PLAYER) firstShare *= PLAYER_PUSH_SHARE;
|
||||
|
||||
float relativeSpeed = vector_length(
|
||||
vector_make(second.velocity.x - first.velocity.x, second.velocity.y - first.velocity.y));
|
||||
Vector impulse = vector_make(delta.x / distance * relativeSpeed, delta.y / distance * relativeSpeed);
|
||||
if (is_singe_ball(first) && is_singe_ball(second)) bounce_sound_play(SOUND_STONE_IMPACT, relativeSpeed);
|
||||
|
||||
push_apply(first, {vector_make(-delta.x, -delta.y), vector_make(-impulse.x, -impulse.y), overlap, firstShare});
|
||||
push_apply(second, {delta, impulse, overlap, secondShare});
|
||||
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*)
|
||||
{
|
||||
reconstruction_missing("Entity::push_apart_capsule 006b25b0 (Capsule::Collide 00945470)");
|
||||
}
|
||||
|
||||
// 006b2ee0 Pushes the entity and another apart: as circles when neither is stretched, as capsules otherwise.
|
||||
void Entity::collide_with_entity(Entity* other)
|
||||
{
|
||||
if (is_unit_size(*this) && is_unit_size(*other)) push_apart_circle(other);
|
||||
else push_apart_capsule(other);
|
||||
}
|
||||
|
||||
// 006b2f50 Makes two entities meet wherever they are: through their collision classes, or when low straight through
|
||||
// both HandleCollision calls. Whether the collision is ignored.
|
||||
bool Entity::ForceCollide(Entity* first, Entity* second, bool isLow)
|
||||
{
|
||||
g_forceCollideDepth++;
|
||||
bool isIgnored = false;
|
||||
if (!isLow) isIgnored = is_collision_ignored(*first, *second);
|
||||
else
|
||||
{
|
||||
bool isFirstIgnoring = first->HandleCollision(second, true);
|
||||
bool isSecondIgnoring = second->HandleCollision(first, false);
|
||||
isIgnored = isFirstIgnoring || isSecondIgnoring;
|
||||
}
|
||||
g_forceCollideDepth--;
|
||||
return isIgnored;
|
||||
}
|
||||
|
||||
// 006b2390 Whether an entity is on the players' side, as ENTCOLL_PLAYEROBJECTS meets it: a player, tear, familiar,
|
||||
// knife or bomb, a charmed or friendly enemy, the Blood Puppy, Dark Esau and poop, or a projectile that hits enemies.
|
||||
bool is_player_object(Entity& entity)
|
||||
{
|
||||
switch (entity.type)
|
||||
{
|
||||
case ENTITY_PLAYER:
|
||||
case ENTITY_TEAR:
|
||||
case ENTITY_FAMILIAR:
|
||||
case ENTITY_BOMB:
|
||||
case ENTITY_KNIFE: return true;
|
||||
default: break;
|
||||
}
|
||||
|
||||
bool isAlly = entity.HasEntityFlags(FLAG_CHARM | FLAG_FRIENDLY) || entity.type == ENTITY_BLOOD_PUPPY ||
|
||||
entity.type == ENTITY_DARK_ESAU || entity.type == ENTITY_POOP;
|
||||
if (entity.IsEnemy() && isAlly) return true;
|
||||
return entity.type == ENTITY_PROJECTILE &&
|
||||
(static_cast<Entity_Projectile&>(entity).projectileFlags & PROJECTILE_HIT_ENEMIES);
|
||||
}
|
||||
|
||||
// An entity's collision class, a charmed or friendly enemy's player-side class meeting all.
|
||||
static int collision_class_get(Entity& entity)
|
||||
{
|
||||
int collisionClass = entity.entityCollisionClass;
|
||||
bool isPlayerSide = collisionClass == ENTCOLL_PLAYERONLY || collisionClass == ENTCOLL_PLAYEROBJECTS;
|
||||
bool isAlly = Entity::is_enemy_type(entity.type) && entity.HasEntityFlags(FLAG_CHARM | FLAG_FRIENDLY);
|
||||
return isPlayerSide && isAlly ? ENTCOLL_ALL : collisionClass;
|
||||
}
|
||||
|
||||
// 006b2410 Whether two entities pass through each other: by their collision classes (the first's player-only class
|
||||
// meets nothing), either being dead, or else either's HandleCollision ignoring the other.
|
||||
bool is_collision_ignored(Entity& first, Entity& second)
|
||||
{
|
||||
int firstClass = collision_class_get(first);
|
||||
int secondClass = collision_class_get(second);
|
||||
bool isNone = firstClass == ENTCOLL_NONE || secondClass == ENTCOLL_NONE;
|
||||
bool isNotPlayerObject = (firstClass == ENTCOLL_PLAYEROBJECTS && !is_player_object(second)) ||
|
||||
(secondClass == ENTCOLL_PLAYEROBJECTS && !is_player_object(first));
|
||||
bool isNotPlayer = firstClass == ENTCOLL_PLAYERONLY ||
|
||||
(secondClass == ENTCOLL_PLAYERONLY && first.type != ENTITY_PLAYER);
|
||||
bool isNotEnemy = (firstClass == ENTCOLL_ENEMIES && !Entity::is_enemy_type(second.type)) ||
|
||||
(secondClass == ENTCOLL_ENEMIES && !Entity::is_enemy_type(first.type));
|
||||
if (first.isDead || second.isDead || isNone || isNotPlayerObject || isNotPlayer || isNotEnemy) return true;
|
||||
|
||||
bool isFirstIgnoring = first.HandleCollision(&second, true);
|
||||
bool isSecondIgnoring = second.HandleCollision(&first, false);
|
||||
return isFirstIgnoring || isSecondIgnoring;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "entity.h"
|
||||
|
||||
bool is_player_object(Entity& entity);
|
||||
bool is_collision_ignored(Entity& first, Entity& second);
|
||||
+235
-9
@@ -1,10 +1,13 @@
|
||||
#include "entity_effect.h"
|
||||
#include "entity_list.h"
|
||||
#include "entity_player.h"
|
||||
#include "entity_tear.h"
|
||||
#include "game.h"
|
||||
#include "log.h"
|
||||
#include "lua_engine.h"
|
||||
#include "manager.h"
|
||||
#include "room.h"
|
||||
#include "room_config.h"
|
||||
#include "sfx_manager.h"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
@@ -28,11 +31,56 @@ constexpr int EFFECT_TIMER = 119;
|
||||
constexpr int EFFECT_ENEMY_SOUL = 179;
|
||||
constexpr int EFFECT_ANIMA_CHAIN = 193;
|
||||
constexpr int EFFECT_REDEMPTION = 185;
|
||||
constexpr int EFFECT_BLOOD_EXPLOSION = 2;
|
||||
constexpr int EFFECT_POOF01 = 15;
|
||||
constexpr int EFFECT_POOF02 = 16;
|
||||
constexpr int EFFECT_TINY_FLY = 33;
|
||||
|
||||
// The variants whose Init, Update and Render are reconstructed: the tear poofs and the blood stains.
|
||||
constexpr std::array<int, 8> EFFECT_RECONSTRUCTED_VARIANTS = {
|
||||
// The variants whose Init, Update and Render are reconstructed: the tear poofs, the blood stains, the poofs and the
|
||||
// ambient tiny fly.
|
||||
constexpr std::array<int, 11> EFFECT_RECONSTRUCTED_VARIANTS = {
|
||||
EFFECT_BLOOD_SPLAT, EFFECT_BULLET_POOF, EFFECT_TEAR_POOF_A, EFFECT_TEAR_POOF_B,
|
||||
EFFECT_RIPPLE_POOF, EFFECT_TEAR_POOF_SMALL, EFFECT_TEAR_POOF_VERYSMALL, EFFECT_IMPACT};
|
||||
EFFECT_RIPPLE_POOF, EFFECT_TEAR_POOF_SMALL, EFFECT_TEAR_POOF_VERYSMALL, EFFECT_IMPACT,
|
||||
EFFECT_POOF01, EFFECT_POOF02, EFFECT_TINY_FLY};
|
||||
|
||||
// The animations a poof plays by its subtype: POOF01 from 1 to 3, POOF02's lava splash at random.
|
||||
constexpr std::array<const char*, 4> POOF01_ANIMATIONS = {"Poof2", "Poof_Small", "Poof", "Poof_Large"};
|
||||
constexpr std::array<const char*, 3> LAVA_SPLASH_ANIMATIONS = {"Poof0", "Poof1", "Poof2"};
|
||||
constexpr int POOF01_SUBTYPE_LAST = 3;
|
||||
constexpr int POOF02_LAVA_SPLASH = 66;
|
||||
constexpr int POOF02_LAVA_SPLASH_LARGE = 67;
|
||||
constexpr int POOF_RENDER_Z = 8000;
|
||||
constexpr uint32_t LAVA_SPLASH_SHIFT = 4;
|
||||
|
||||
// The tiny fly: white in the Cathedral, its own color in Dross, how it wanders, flees the nearest player within
|
||||
// range, dies to tears, knives and fires, and drops down in circles when dead.
|
||||
constexpr int STAGE_ID_CATHEDRAL = 15;
|
||||
constexpr int BACKDROP_DROSS = 45;
|
||||
constexpr int ENTITY_KNIFE_TYPE = 8;
|
||||
constexpr int FLY_WANDER_ODDS = 5;
|
||||
constexpr int FLY_JITTER_FRAMES = 5;
|
||||
constexpr float FLY_MASS = 1;
|
||||
constexpr float FLY_FRICTION = 0.98f;
|
||||
constexpr float FLY_DEAD_FRICTION = 0.8f;
|
||||
constexpr float FLY_PULL = 0.5f;
|
||||
constexpr float FLY_JITTER = 0.9f;
|
||||
constexpr float FLY_FLEE_RANGE = 60;
|
||||
constexpr float FLY_FLEE_PUSH = -0.2f;
|
||||
constexpr float FLY_HIT_RADIUS = 0.5f;
|
||||
constexpr float FLY_KNIFE_REACH = 1.5f;
|
||||
constexpr float FLY_FIRE_REACH = 2;
|
||||
constexpr float FLY_FALL_STEP = 0.25f;
|
||||
constexpr float FLY_FALL_HEIGHT = 16;
|
||||
constexpr float FLY_CIRCLE_SPEED = 15;
|
||||
constexpr float FLY_CIRCLE_RADIUS = 3;
|
||||
constexpr float FLY_CLAMP_MARGIN = 2;
|
||||
constexpr float FLY_SPLAT_SCALE = 0.1f;
|
||||
constexpr float FLY_BURST_SCALE = 0.3f;
|
||||
constexpr float FLY_BURST_RISE = -16;
|
||||
constexpr float MIN_DISTANCE = 0.01f;
|
||||
constexpr float RANDOM_UNIT = 2.3283064e-10f;
|
||||
constexpr float RANDOM_HALF_TURN = 3.14f;
|
||||
constexpr float DEGREES_TO_RADIANS = 0.017453292f;
|
||||
// The poofs that turn with their rotation.
|
||||
constexpr std::array<int, 5> EFFECT_TURNED_POOFS = {EFFECT_TEAR_POOF_A, EFFECT_TEAR_POOF_B, EFFECT_TEAR_POOF_SMALL,
|
||||
EFFECT_TEAR_POOF_VERYSMALL, EFFECT_IMPACT};
|
||||
@@ -60,12 +108,6 @@ constexpr int LUA_CALLBACK_POST_EFFECT_INIT = 54;
|
||||
constexpr int LUA_CALLBACK_POST_EFFECT_UPDATE = 55;
|
||||
constexpr int LUA_CALLBACK_POST_EFFECT_RENDER = 56;
|
||||
|
||||
// Stops where a mod has a function for one of the effect's Lua callbacks, which LuaEngine does not run yet.
|
||||
static void lua_callback_check(int callback, const char* name)
|
||||
{
|
||||
if (static_cast<LuaEngine*>(g_luaEngine)->enabledCallbacks[callback]) reconstruction_missing(name);
|
||||
}
|
||||
|
||||
template <size_t N>
|
||||
static bool is_listed(const std::array<int, N>& list, int value)
|
||||
{
|
||||
@@ -158,6 +200,8 @@ void Entity_Effect::Init(int entityType, int entityVariant, int entitySubType, u
|
||||
isUnknown176 = true;
|
||||
}
|
||||
if (variant == EFFECT_IMPACT) sprite.isFlipX = !(Random() & 1);
|
||||
if (variant == EFFECT_POOF01 || variant == EFFECT_POOF02) poof_init();
|
||||
if (variant == EFFECT_TINY_FLY) tiny_fly_init();
|
||||
|
||||
sprite.LoadGraphics();
|
||||
if (g_game->deathmatchManager.is_active())
|
||||
@@ -199,12 +243,194 @@ void Entity_Effect::Update()
|
||||
}
|
||||
|
||||
if (variant == EFFECT_BLOOD_SPLAT) stain_update();
|
||||
else if (variant == EFFECT_TINY_FLY) tiny_fly_update();
|
||||
else poof_update();
|
||||
if (timeout > 0 && --timeout < 1) isDead = true;
|
||||
pausePosition = pos;
|
||||
lua_callback_check(LUA_CALLBACK_POST_EFFECT_UPDATE, "LuaEngine::PostEffectUpdate 00861410");
|
||||
}
|
||||
|
||||
// A poof's animation by its subtype. POOF01 and POOF02's large kinds draw over everything, POOF02's small kinds lie
|
||||
// on the floor outside the crawl space, and its lava splashes face a seeded side.
|
||||
void Entity_Effect::poof_init()
|
||||
{
|
||||
if (variant == EFFECT_POOF01)
|
||||
{
|
||||
if (subtype >= 1 && subtype <= POOF01_SUBTYPE_LAST) sprite.Play(POOF01_ANIMATIONS[subtype]);
|
||||
renderZOffset = POOF_RENDER_Z;
|
||||
return;
|
||||
}
|
||||
|
||||
if (subtype == 1 || subtype == 3)
|
||||
{
|
||||
if (g_game->room->roomType != ROOM_DUNGEON) sortingLayer = SORTING_BACKGROUND;
|
||||
sprite.Play("Poof");
|
||||
}
|
||||
else if (subtype == 2 || subtype == 4 || subtype == 5)
|
||||
{
|
||||
renderZOffset = POOF_RENDER_Z;
|
||||
sprite.Play("Poof");
|
||||
}
|
||||
else if (subtype == POOF02_LAVA_SPLASH || subtype == POOF02_LAVA_SPLASH_LARGE)
|
||||
{
|
||||
RNG rng = rng_make(initSeed, LAVA_SPLASH_SHIFT);
|
||||
uint32_t roll = subtype == POOF02_LAVA_SPLASH ? rng.Next() % LAVA_SPLASH_ANIMATIONS.size() : 0;
|
||||
sprite.Play(subtype == POOF02_LAVA_SPLASH ? LAVA_SPLASH_ANIMATIONS[roll] : "PoofLarge");
|
||||
sprite.isFlipX = !(initSeed & 1);
|
||||
}
|
||||
}
|
||||
|
||||
// A tiny fly: white in the Cathedral, uncolored in Dross, light and colliding with everything.
|
||||
void Entity_Effect::tiny_fly_init()
|
||||
{
|
||||
if (RoomConfig::GetStageID((int)g_game->stage, (int)g_game->stageType, (RoomMode)-1) == STAGE_ID_CATHEDRAL)
|
||||
sprite.Play("White");
|
||||
mass = FLY_MASS;
|
||||
entityCollisionClass = ENTCOLL_ALL;
|
||||
isUnknown176 = true;
|
||||
if (g_game->room->backdropType == BACKDROP_DROSS) sprite.color = COLOR_DEFAULT;
|
||||
}
|
||||
|
||||
// The player nearest a position, the first one on a tie (Game::GetNearestPlayer 00703950, which Game does not
|
||||
// declare yet).
|
||||
static Entity_Player* nearest_player_get(const Vector& position)
|
||||
{
|
||||
Entity_Player* nearest = nullptr;
|
||||
float nearestDistance = 0;
|
||||
|
||||
for (Entity_Player* player : g_game->playerManager.playerList)
|
||||
{
|
||||
float dx = position.x - player->pos.x;
|
||||
float dy = position.y - player->pos.y;
|
||||
float distance = dy * dy + dx * dx;
|
||||
if (nearest && distance >= nearestDistance) continue;
|
||||
nearest = player;
|
||||
nearestDistance = distance;
|
||||
}
|
||||
return nearest;
|
||||
}
|
||||
|
||||
static float random_unit()
|
||||
{
|
||||
return (float)Random() * RANDOM_UNIT;
|
||||
}
|
||||
|
||||
static Vector vector_scaled(Vector v, float scale)
|
||||
{
|
||||
return vector_make(v.x * scale, v.y * scale);
|
||||
}
|
||||
|
||||
static float vector_length(Vector v)
|
||||
{
|
||||
return std::sqrt(v.x * v.x + v.y * v.y);
|
||||
}
|
||||
|
||||
// Whether an entity of the list stands within reach of a position, reach scaled from its size.
|
||||
static bool is_within_reach(Entity& entity, const Vector& position, float reach)
|
||||
{
|
||||
float dx = entity.pos.x - position.x;
|
||||
float dy = entity.pos.y - position.y;
|
||||
return dx * dx + dy * dy < reach * reach;
|
||||
}
|
||||
|
||||
// Bursts the fly into a small splash of its blood color.
|
||||
void Entity_Effect::tiny_fly_burst()
|
||||
{
|
||||
isDead = true;
|
||||
Entity* burst = g_game->Spawn({vector_make(pos.x, pos.y + FLY_BURST_RISE), {}, nullptr, 0, ENTITY_EFFECT,
|
||||
EFFECT_BLOOD_EXPLOSION, Random()});
|
||||
burst->SetColor(splatColor, -1, 255, false, true);
|
||||
burst->sprite.scale = vector_make(FLY_BURST_SCALE, FLY_BURST_SCALE);
|
||||
burst->Update();
|
||||
sprite.Stop();
|
||||
}
|
||||
|
||||
// A tiny fly's frame: alive it drifts at random, now and then toward its parent or the nearest player, and away
|
||||
// from a player close by, and bursts on a tear, knife or fire. Dead, it spirals down and splats. It faces its motion
|
||||
// and stays in the room.
|
||||
void Entity_Effect::tiny_fly_update()
|
||||
{
|
||||
Entity_Player* player = nearest_player_get(pos);
|
||||
Vector toPlayer = vector_make(player->pos.x - pos.x, player->pos.y - pos.y);
|
||||
float distance = vector_length(toPlayer);
|
||||
Vector direction = vector_scaled(toPlayer, 1 / (distance == 0 ? MIN_DISTANCE : distance));
|
||||
EntityList& entities = g_game->room->entityList;
|
||||
|
||||
friction *= FLY_FRICTION;
|
||||
if (isDead)
|
||||
{
|
||||
LayerState& layer = *sprite.GetLayer(0);
|
||||
if (layer.pos.y <= FLY_FALL_HEIGHT)
|
||||
{
|
||||
layer.pos.y += FLY_FALL_STEP;
|
||||
float side = (float)(index % 2) * 2 - 1;
|
||||
float angle = (float)g_game->frameCount * FLY_CIRCLE_SPEED * side * DEGREES_TO_RADIANS;
|
||||
Vector circle = vector_make(std::cos(angle), std::sin(angle));
|
||||
circle = vector_scaled(vector_scaled(circle, std::abs(layer.pos.y) / FLY_FALL_HEIGHT), FLY_CIRCLE_RADIUS);
|
||||
pos = vector_make(pos.x + circle.x, pos.y + circle.y);
|
||||
friction *= FLY_DEAD_FRICTION;
|
||||
}
|
||||
else
|
||||
{
|
||||
Entity* splat = g_game->Spawn({pos, {}, nullptr, 0, ENTITY_EFFECT, EFFECT_BLOOD_SPLAT, Random()});
|
||||
splat->SetColor(splatColor, -1, 255, false, true);
|
||||
splat->sprite.scale = vector_make(FLY_SPLAT_SCALE, FLY_SPLAT_SCALE);
|
||||
splat->Update();
|
||||
Remove();
|
||||
}
|
||||
}
|
||||
|
||||
if (!isDead)
|
||||
{
|
||||
if (Random() % FLY_WANDER_ODDS == 0)
|
||||
{
|
||||
Vector pull = direction;
|
||||
if (parent)
|
||||
{
|
||||
Vector toParent = vector_make(parent->pos.x - pos.x, parent->pos.y - pos.y);
|
||||
float length = vector_length(toParent);
|
||||
if (length > 0) toParent = vector_scaled(toParent, (length - parent->size) / length);
|
||||
float resized = vector_length(toParent);
|
||||
pull = resized > 0 ? vector_scaled(toParent, 1 / resized) : toParent;
|
||||
}
|
||||
AddVelocity_divided(vector_scaled(pull, random_unit() * FLY_PULL), false);
|
||||
}
|
||||
if (IsFrame(FLY_JITTER_FRAMES, (int)index))
|
||||
{
|
||||
float angle = random_unit() * RANDOM_HALF_TURN * 2;
|
||||
Vector jitter = vector_make(std::cos(angle), std::sin(angle));
|
||||
AddVelocity_divided(vector_scaled(jitter, random_unit() * FLY_JITTER), false);
|
||||
}
|
||||
if (distance < FLY_FLEE_RANGE)
|
||||
{
|
||||
float push = (1 - distance * distance / (FLY_FLEE_RANGE * FLY_FLEE_RANGE)) * FLY_FLEE_PUSH;
|
||||
AddVelocity_divided(vector_scaled(direction, push), false);
|
||||
}
|
||||
|
||||
EntityList_EL shots;
|
||||
entities.partitions[PARTITION_SHOTS].query_box(shots, pos, vector_make(FLY_HIT_RADIUS, FLY_HIT_RADIUS));
|
||||
bool isShot = std::any_of(shots.begin(), shots.end(), [this](Entity* shot) {
|
||||
return !shot->HasEntityFlags(FLAG_INTERPOLATION_UPDATE) && shot->type == ENTITY_TEAR &&
|
||||
is_within_reach(*shot, pos, FLY_HIT_RADIUS + shot->size);
|
||||
});
|
||||
if (isShot) tiny_fly_burst();
|
||||
|
||||
std::vector<Entity*> hazards(entities.updateEL);
|
||||
for (Entity* hazard : hazards)
|
||||
{
|
||||
bool isKnife =
|
||||
hazard->type == ENTITY_KNIFE_TYPE && is_within_reach(*hazard, pos, hazard->size * FLY_KNIFE_REACH);
|
||||
bool isFire =
|
||||
hazard->type == ENTITY_FIREPLACE && is_within_reach(*hazard, pos, hazard->size + FLY_FIRE_REACH);
|
||||
if (isKnife || isFire) tiny_fly_burst();
|
||||
}
|
||||
}
|
||||
|
||||
sprite.isFlipX = pos.x - targetPosition.x < 0;
|
||||
pos = g_game->room->GetClampedPosition(pos, FLY_CLAMP_MARGIN);
|
||||
targetPosition = pos;
|
||||
}
|
||||
|
||||
// Turns a poof by its rotation, mirrored unless flipped, and removes it once its animation ends. A ripple first
|
||||
// draws its small sizes larger with their own animations.
|
||||
void Entity_Effect::poof_update()
|
||||
|
||||
+6
-1
@@ -12,7 +12,8 @@ constexpr int EFFECT_SPAWN_PENTAGRAM = 203;
|
||||
// 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.
|
||||
// Only the tear poofs and the blood stains are reconstructed yet: Init stops at any other variant.
|
||||
// Only the tear poofs, the blood stains, the poofs and the tiny fly are reconstructed yet: Init stops at any other
|
||||
// variant.
|
||||
struct Entity_Effect : Entity
|
||||
{
|
||||
// The base of the extra data some variants keep (MrMeData, PickupGhostData, SpriteTrailData).
|
||||
@@ -66,6 +67,10 @@ struct Entity_Effect : Entity
|
||||
void setup_loot_preview(void* lootQueue);
|
||||
|
||||
private:
|
||||
void poof_init();
|
||||
void tiny_fly_init();
|
||||
void poof_update();
|
||||
void stain_update();
|
||||
void tiny_fly_update();
|
||||
void tiny_fly_burst();
|
||||
};
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
#include "entity.h"
|
||||
#include "anm2.h"
|
||||
#include "path_finder.h"
|
||||
#include "weapon.h"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
// Construction and destruction (0060d3d0, 0060d200) are the defaults, but for the pathfinder's owner the constructor
|
||||
// sets. PathFinder::Init's reset waits for PathFinder's takeover.
|
||||
// Construction and destruction (0060d3d0, 0060d200) are the defaults, with the familiar owning its pathfinder.
|
||||
// Field accessors (004361f0, 00505cf0, 0060d0e0, 0060d100) are the public fields.
|
||||
// A familiar (Lua's EntityFamiliar): its player, its place in the following line or an orbit, the consumables it
|
||||
// collects, its weapon, and the extra data some variants keep.
|
||||
@@ -20,7 +20,7 @@ struct Entity_Familiar : Entity
|
||||
};
|
||||
|
||||
ANM2 chargeBarSprite;
|
||||
NPCAI_Pathfinder pathfinder{};
|
||||
PathFinder pathfinder{this};
|
||||
std::unique_ptr<ExtraData> extraData;
|
||||
std::vector<uint32_t> hitList;
|
||||
ColorMod dirtColor = COLOR_DEFAULT;
|
||||
@@ -61,8 +61,6 @@ struct Entity_Familiar : Entity
|
||||
bool isNotCountedAsFollower = false;
|
||||
bool isSubtype55555 = false;
|
||||
|
||||
Entity_Familiar() { pathfinder._entity = this; }
|
||||
|
||||
void Init(int type, int variant, int subType, uint32_t initSeed) override;
|
||||
void Update() override;
|
||||
void Interpolate() override;
|
||||
|
||||
+71
-19
@@ -30,6 +30,21 @@ constexpr uint32_t RENDER_Z_NORMAL_START = 10000;
|
||||
constexpr int RENDER_LIST_CAPACITY = 0x4000;
|
||||
constexpr int RENDER_SORT_SWAP_BUDGET = (RENDER_LIST_CAPACITY >> 4) + 1;
|
||||
|
||||
// The room's render surface, its size and margin, centered on the screen.
|
||||
constexpr float ROOM_SURFACE_WIDTH = 338;
|
||||
constexpr float ROOM_SURFACE_HEIGHT = 182;
|
||||
constexpr float ROOM_SURFACE_MARGIN = 52;
|
||||
|
||||
// A surface surfaces_bake draws into: the flag of the entities drawn there, the flags that keep them, and whether any
|
||||
// is to be drawn.
|
||||
struct SurfacePass
|
||||
{
|
||||
KAGE::Graphics::ImageBase* surface = nullptr;
|
||||
uint64_t flag = 0;
|
||||
uint64_t keptFlags = 0;
|
||||
bool isUsed = false;
|
||||
};
|
||||
|
||||
// Formats a message for KAGE_LogMessage, whose declaration takes nothing to format with.
|
||||
[[gnu::format(printf, 2, 3)]] static void log_format(uint32_t level, const char* format, ...)
|
||||
{
|
||||
@@ -47,13 +62,6 @@ static bool is_unit_size(const Entity& entity)
|
||||
return entity.sizeMulti.x == 1 && entity.sizeMulti.y == 1;
|
||||
}
|
||||
|
||||
// Pushes one entity off another: as circles when neither is stretched, as capsules otherwise.
|
||||
static void entity_push_apart(Entity& pusher, Entity& other)
|
||||
{
|
||||
if (is_unit_size(pusher) && is_unit_size(other)) pusher.push_apart_circle(&other);
|
||||
else pusher.push_apart_capsule(&other);
|
||||
}
|
||||
|
||||
// 00417670 Drops every occurrence of the entity.
|
||||
void EntityList_EL::remove(Entity* entity)
|
||||
{
|
||||
@@ -150,7 +158,7 @@ void CellSpace::collide_entity(Entity& entity)
|
||||
{
|
||||
Entity& other = *cell->entities[i];
|
||||
if (&other == &entity || !owner->is_pair_new(other, entity)) continue;
|
||||
entity_push_apart(other, entity);
|
||||
other.collide_with_entity(&entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -170,7 +178,7 @@ void CellSpace::collide(CellSpace& other)
|
||||
{
|
||||
Entity& first = *cells[c].entities[i];
|
||||
Entity& second = *other.cells[c].entities[j];
|
||||
if (&first != &second && owner->is_pair_new(first, second)) entity_push_apart(first, second);
|
||||
if (&first != &second && owner->is_pair_new(first, second)) first.collide_with_entity(&second);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -187,7 +195,7 @@ void CellSpace::collide_self()
|
||||
{
|
||||
Entity& first = *cell.entities[i];
|
||||
Entity& second = *cell.entities[j];
|
||||
if (&first != &second && owner->is_pair_new(first, second)) entity_push_apart(first, second);
|
||||
if (&first != &second && owner->is_pair_new(first, second)) first.collide_with_entity(&second);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -320,6 +328,53 @@ void EntityList::AddPersistentEntity(Entity* entity)
|
||||
if (!isListed) persistentEL.push_back(entity);
|
||||
}
|
||||
|
||||
// Draws the entities flagged to render into the floor or the walls into the backdrop's surfaces, at the room
|
||||
// surface's corner on screen snapped to the display's pixels, and removes them. One drawn into both stays for the
|
||||
// walls, and one with FLAG_NO_REMOVE_ON_TEX_RENDER stays. Whether any was removed.
|
||||
static bool surfaces_bake(EntityList_EL& renderEL)
|
||||
{
|
||||
Backdrop& backdrop = g_game->room->backdrop;
|
||||
std::array<SurfacePass, 2> passes = {{
|
||||
{backdrop.floorBuffer.get(), FLAG_RENDER_FLOOR, FLAG_RENDER_WALL | FLAG_NO_REMOVE_ON_TEX_RENDER},
|
||||
{backdrop.wallsBuffer.get(), FLAG_RENDER_WALL, FLAG_NO_REMOVE_ON_TEX_RENDER},
|
||||
}};
|
||||
auto isDrawn = [](Entity* entity, uint64_t flag) { return entity->isExists && entity->HasEntityFlags(flag); };
|
||||
for (SurfacePass& pass : passes)
|
||||
pass.isUsed = std::any_of(renderEL.begin(), renderEL.end(),
|
||||
[&pass, &isDrawn](Entity* entity) { return isDrawn(entity, pass.flag); });
|
||||
if (!passes[0].isUsed && !passes[1].isUsed) return false;
|
||||
|
||||
KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager;
|
||||
float pixelScale = g_displayPixelRatio * g_screenPointScale;
|
||||
auto corner = [pixelScale](float screen, float surface)
|
||||
{ return -(std::floor(pixelScale * ((screen - surface) * 0.5f - ROOM_SURFACE_MARGIN) + 0.5f) / pixelScale); };
|
||||
Vector offset = vector_make(corner(g_screenWidth, ROOM_SURFACE_WIDTH), corner(g_screenHeight, ROOM_SURFACE_HEIGHT));
|
||||
auto size = graphics.isScreenTarget ? KAGE::Graphics::TARGET_SCREEN_SIZE : KAGE::Graphics::TARGET_OWN_SIZE;
|
||||
graphics.render_target_push(graphics.renderTarget, size, KAGE::Graphics::PRESENT_FLUSH);
|
||||
graphics.isCullOffscreen = false;
|
||||
graphics.blend_set(KAGE::Graphics::BLEND_NORMAL);
|
||||
|
||||
bool isRemoved = false;
|
||||
for (SurfacePass& pass : passes)
|
||||
{
|
||||
if (!pass.isUsed) continue;
|
||||
graphics.SetRenderTarget(pass.surface, KAGE::Graphics::TARGET_OWN_SIZE);
|
||||
for (size_t i = 0; i < renderEL.size(); i++)
|
||||
{
|
||||
Entity* entity = renderEL[i];
|
||||
if (!isDrawn(entity, pass.flag)) continue;
|
||||
entity->Render(offset);
|
||||
if (entity->HasEntityFlags(pass.keptFlags)) continue;
|
||||
entity->Remove();
|
||||
isRemoved = true;
|
||||
}
|
||||
graphics.Present(KAGE::Graphics::PRESENT_FINISH);
|
||||
}
|
||||
graphics.isCullOffscreen = true;
|
||||
graphics.render_target_pop(KAGE::Graphics::PRESENT_FLUSH);
|
||||
return isRemoved;
|
||||
}
|
||||
|
||||
// 004186c0 One frame of the room's entities: pre-updates and updates (only those that update in transitions during
|
||||
// one), the players' in-between updates without interpolation, the enemy and boss counts and the boss bar, the
|
||||
// removal of the entities that stopped existing, then the collisions and the draw order.
|
||||
@@ -341,13 +396,8 @@ void EntityList::Update(UpdateMode mode)
|
||||
isAnyBaited = tally.isAnyBaited;
|
||||
boss_bar_update(tally);
|
||||
enemyDamageInflicted = tally.damageInflicted;
|
||||
for (Entity* entity : renderEL)
|
||||
{
|
||||
if (entity->isExists && entity->HasEntityFlags(FLAG_RENDER_FLOOR | FLAG_RENDER_WALL))
|
||||
reconstruction_missing("EntityList::Update 004186c0: drawing entities into the floor and wall surfaces");
|
||||
}
|
||||
|
||||
if (tally.isAnyRemoved) removed_drop();
|
||||
bool isBakedAway = surfaces_bake(renderEL);
|
||||
if (tally.isAnyRemoved || isBakedAway) removed_drop();
|
||||
if (mode == UPDATE_NORMAL) rebuild_sublists();
|
||||
sort_by_render_z();
|
||||
}
|
||||
@@ -614,8 +664,10 @@ void EntityList::twins_push_apart()
|
||||
if (twin->playerIndex != -1 && player->playerIndex > twin->playerIndex && twin != player) continue;
|
||||
|
||||
bool isEvenFrame = (g_game->frameCount & 1) == 0;
|
||||
entity_push_apart(isEvenFrame ? *player : *twin, isEvenFrame ? *twin : *player);
|
||||
entity_push_apart(isEvenFrame ? *twin : *player, isEvenFrame ? *player : *twin);
|
||||
Entity_Player* first = isEvenFrame ? player : twin;
|
||||
Entity_Player* second = isEvenFrame ? twin : player;
|
||||
first->collide_with_entity(second);
|
||||
second->collide_with_entity(first);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2506
-260
File diff suppressed because it is too large.
Load diff
+263
-79
@@ -2,71 +2,202 @@
|
||||
|
||||
#include "entity.h"
|
||||
#include "anm2.h"
|
||||
#include "path_finder.h"
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
// Construction and destruction (006b88e0, 006b8590) are the defaults, but for the pathfinder's owner the constructor
|
||||
// sets. PathFinder::Init's reset waits for PathFinder's takeover.
|
||||
// Field accessors (004567a0, 006a8230, 006b8480, 007e92b0) are the public fields.
|
||||
// Lua's NpcState: where an NPC's AI is in its routine. State 1 holds the AI while the NPC appears.
|
||||
enum NpcState : int
|
||||
{
|
||||
NPC_STATE_INIT = 0,
|
||||
NPC_STATE_APPEAR = 1,
|
||||
NPC_STATE_APPEAR_CUSTOM = 2,
|
||||
NPC_STATE_IDLE = 3,
|
||||
NPC_STATE_MOVE = 4,
|
||||
NPC_STATE_SUICIDE = 5,
|
||||
NPC_STATE_JUMP = 6,
|
||||
NPC_STATE_STOMP = 7,
|
||||
NPC_STATE_ATTACK = 8,
|
||||
NPC_STATE_ATTACK2 = 9,
|
||||
NPC_STATE_ATTACK3 = 10,
|
||||
NPC_STATE_ATTACK4 = 11,
|
||||
NPC_STATE_ATTACK5 = 12,
|
||||
NPC_STATE_SUMMON = 13,
|
||||
NPC_STATE_SUMMON2 = 14,
|
||||
NPC_STATE_SUMMON3 = 15,
|
||||
NPC_STATE_SPECIAL = 16,
|
||||
NPC_STATE_UNIQUE_DEATH = 17,
|
||||
NPC_STATE_DEATH = 18
|
||||
};
|
||||
|
||||
// Which extra AI calls an NPC asks for (_aiCallFlags), and the phase (_aiCallPhase) the AI sees in each.
|
||||
enum AiCall : uint32_t
|
||||
{
|
||||
AI_CALL_PRE_UPDATE = 1 << 0,
|
||||
AI_CALL_INTERPOLATE = 1 << 1,
|
||||
AI_CALL_COLLISION = 1 << 2,
|
||||
AI_CALL_POST_UPDATE = 1 << 3
|
||||
};
|
||||
|
||||
enum AiPhase : int
|
||||
{
|
||||
AI_PHASE_UPDATE = 0,
|
||||
AI_PHASE_PRE_UPDATE = 1,
|
||||
AI_PHASE_INTERPOLATE = 2,
|
||||
AI_PHASE_COLLISION = 3,
|
||||
AI_PHASE_POST_UPDATE = 4
|
||||
};
|
||||
|
||||
// The spreads FireProjectiles shoots (Lua's ProjectilesMode): fans of one to five shots along the velocity, plus and
|
||||
// cross shapes and their union at the velocity's x, and a ring of round(velocity.y) shots at the velocity's x.
|
||||
enum ProjectilesMode : int
|
||||
{
|
||||
PROJECTILES_SINGLE,
|
||||
PROJECTILES_TWO,
|
||||
PROJECTILES_THREE,
|
||||
PROJECTILES_THREE_WIDE,
|
||||
PROJECTILES_FOUR,
|
||||
PROJECTILES_FIVE,
|
||||
PROJECTILES_PLUS,
|
||||
PROJECTILES_CROSS,
|
||||
PROJECTILES_EIGHT,
|
||||
PROJECTILES_RING
|
||||
};
|
||||
|
||||
// Lua's ChampionColor values the NPC code tests.
|
||||
enum ChampionColor : int
|
||||
{
|
||||
CHAMPION_NONE = -1,
|
||||
CHAMPION_RED = 0,
|
||||
CHAMPION_YELLOW = 1,
|
||||
CHAMPION_GREEN = 2,
|
||||
CHAMPION_ORANGE = 3,
|
||||
CHAMPION_DARK_BLUE = 4,
|
||||
CHAMPION_DARK_GREEN = 5,
|
||||
CHAMPION_WHITE = 6,
|
||||
CHAMPION_GREY = 7,
|
||||
CHAMPION_TRANSPARENT = 8,
|
||||
CHAMPION_FLICKER = 9,
|
||||
CHAMPION_PINK = 10,
|
||||
CHAMPION_PURPLE = 11,
|
||||
CHAMPION_DARK_RED = 12,
|
||||
CHAMPION_LIGHT_BLUE = 13,
|
||||
CHAMPION_CAMO = 14,
|
||||
CHAMPION_PULSE_GREEN = 15,
|
||||
CHAMPION_PULSE_GREY = 16,
|
||||
CHAMPION_FLY_PROTECTED = 17,
|
||||
CHAMPION_TINY = 18,
|
||||
CHAMPION_GIANT = 19,
|
||||
CHAMPION_PULSE_RED = 20,
|
||||
CHAMPION_SIZE_PULSE = 21,
|
||||
CHAMPION_KING = 22,
|
||||
CHAMPION_DEATH = 23,
|
||||
CHAMPION_BROWN = 24,
|
||||
CHAMPION_RAINBOW = 25,
|
||||
CHAMPION_COUNT = 26
|
||||
};
|
||||
|
||||
// Construction (0043ef30) is the default, but for the circle angle it draws at random.
|
||||
// How FireProjectiles shoots (Lua's ProjectileParams): the shots' variant, look, fall, homing and change, and the
|
||||
// spread they leave in.
|
||||
struct ProjectileParams
|
||||
{
|
||||
ColorMod color = COLOR_DEFAULT;
|
||||
Vector fireDirectionLimit{};
|
||||
Vector positionOffset{};
|
||||
Vector targetPosition{};
|
||||
uint64_t bulletFlags = 0;
|
||||
uint64_t changeFlags = 0;
|
||||
float acceleration = 1.01f;
|
||||
float changeVelocity = 0;
|
||||
float circleAngle;
|
||||
float curvingStrength = 0.005f;
|
||||
float damage = -1;
|
||||
float depthOffset = 0;
|
||||
float dotProductLimit = -1000;
|
||||
float fallingAccelModifier = 0;
|
||||
float fallingSpeedModifier = 0;
|
||||
float heightModifier = 0;
|
||||
float homingStrength = 1;
|
||||
float scale = 1;
|
||||
float spread = 1;
|
||||
float unknownA0 = 0;
|
||||
float velocityMulti = 1;
|
||||
int changeTimeout = 30;
|
||||
int variant = 0;
|
||||
int wiggleFrameOffset = 0;
|
||||
bool isGridCollision = true;
|
||||
bool isFallingKept = false;
|
||||
bool isRenderedAtGround = false;
|
||||
|
||||
ProjectileParams();
|
||||
};
|
||||
|
||||
// Construction and destruction (006b88e0, 006b8590, 006b8910) are the defaults.
|
||||
// Field accessors (004567a0, 006a8230, 006b8480, 007e92b0, 004e4850) are the public fields.
|
||||
// An enemy or other non-player character (Lua's EntityNPC): its AI state and counters, pathfinder, champion and boss
|
||||
// colors, shields, Delirium's forms, and the player controlling it with Siren or a friendly ball.
|
||||
struct Entity_NPC : Entity
|
||||
{
|
||||
ANM2 chargeBarSprite;
|
||||
ANM2 statusEffectSprite;
|
||||
NPCAI_Pathfinder pathfinder{};
|
||||
PathFinder pathfinder{this};
|
||||
std::deque<EntityPtr> entityDeque;
|
||||
std::deque<Vector> vectorDeque1;
|
||||
std::deque<Vector> vectorDeque2;
|
||||
std::deque<float> damageHistory;
|
||||
std::vector<DamageEvent> killDamageEvents;
|
||||
std::vector<uint32_t> hitList;
|
||||
std::vector<uint32_t> secondaryHitList;
|
||||
ColorMod dirtColor = COLOR_DEFAULT;
|
||||
ColorMod floorColor = COLOR_DEFAULT;
|
||||
EntityPtr aimTargetEffect;
|
||||
EntityPtr entityRef;
|
||||
EntityPtr forcedTarget;
|
||||
EntityPtr pickupGhostsEntity;
|
||||
EntityPtr salvationTarget;
|
||||
EntityPtr unknownF54;
|
||||
Entity* collisionEntity = nullptr;
|
||||
Entity* deliriumEntity = nullptr;
|
||||
Entity_Effect* pickupGhostsEntity = nullptr;
|
||||
Entity_Player* sirenPlayerEntity = nullptr;
|
||||
void* aimTargetEffect = nullptr;
|
||||
uint64_t killDamageFlags = 0;
|
||||
Vector confusionTargetPos{};
|
||||
Vector controllerMovement{};
|
||||
Vector forwardVector{};
|
||||
Vector v1{};
|
||||
Vector v2{};
|
||||
float aiFloat = 0;
|
||||
float championSpeed = 0;
|
||||
float flickerAlpha = 0;
|
||||
float hitPointsMulti = 0;
|
||||
float aiFloat = 1;
|
||||
float championSpeed = 1;
|
||||
float flickerAlpha = 1;
|
||||
float hitPointsMulti = 1;
|
||||
float killDamage = 0;
|
||||
float scale = 0;
|
||||
float scaleMulti = 0;
|
||||
float scale = 1;
|
||||
float scaleMulti = 1;
|
||||
float shieldStrength = 0;
|
||||
float totalDamageTaken = 0;
|
||||
int aiCallPhase = 0;
|
||||
int aiCallPhase = AI_PHASE_UPDATE;
|
||||
int aiCounter = 0;
|
||||
int appearFrames = 0;
|
||||
int bosscoloridx = 0;
|
||||
int championColorIdx = 0;
|
||||
int bosscoloridx = -1;
|
||||
int championColorIdx = CHAMPION_NONE;
|
||||
int championTimer = 0;
|
||||
int collisionResult = 0;
|
||||
int controllerID = 0;
|
||||
int controllerID = -1;
|
||||
int decoyTargetTimer = 0;
|
||||
int flickerState = 0;
|
||||
int flickerTimer = 0;
|
||||
int forcedTargetTimer = 0;
|
||||
int groupIdx = 0;
|
||||
int groupIdx = -1;
|
||||
int i1 = 0;
|
||||
int i2 = 0;
|
||||
int lastGridIndex = 0;
|
||||
int lastGridIndex = -1;
|
||||
int projectileCooldown = 0;
|
||||
int projectileDelay = 0;
|
||||
int projectileDelay = -1;
|
||||
int savedState = 0;
|
||||
int shieldFrames = 0;
|
||||
int state = 0;
|
||||
int state = NPC_STATE_INIT;
|
||||
int stateFrame = 0;
|
||||
int unknownF2c = 0;
|
||||
uint32_t aiCallFlags = 0;
|
||||
uint32_t deliriumAttackID = 0;
|
||||
uint32_t deliriumBossType = 0;
|
||||
@@ -84,10 +215,11 @@ struct Entity_NPC : Entity
|
||||
bool isCanShutDoors = false;
|
||||
bool isChampion = false;
|
||||
bool isCollisionIsLow = false;
|
||||
bool isDeathSoundAlt = false;
|
||||
bool isUnknownC61 = false;
|
||||
bool isUnknownC62 = false;
|
||||
bool isUnreachableOnce = false;
|
||||
|
||||
Entity_NPC() { pathfinder._entity = this; }
|
||||
|
||||
void Init(int type, int variant, int subType, uint32_t initSeed) override;
|
||||
void PreUpdate() override;
|
||||
void Update() override;
|
||||
@@ -106,75 +238,127 @@ struct Entity_NPC : Entity
|
||||
void ResetColor() override;
|
||||
void LoadEntityConfig() override;
|
||||
|
||||
Entity_NPC* ParentNPC();
|
||||
Entity_NPC* ChildNPC();
|
||||
void Hornfel_UpdateAI();
|
||||
void Hornfel_UpdateFrame();
|
||||
void update_physics();
|
||||
void apply_velocity(char);
|
||||
void update_move_direction_anim();
|
||||
void SetMinecartPosVel(const Vector& pos, const Vector& vel);
|
||||
void MinecartUpdateChild(Entity* child);
|
||||
void UpdateCordChain(bool isHalfScale);
|
||||
void render_overlay(const Vector& offset, bool isShadow);
|
||||
static int FindTargetPit(const Vector& pos1, const Vector& pos2, uint32_t pitIndex);
|
||||
static Entity_NPC* ThrowStrider(const Vector& pos, Entity* spawner, const Vector& targetPos);
|
||||
void render_v1_layer_frames();
|
||||
void RenderSegmentLink(const Vector& offset, bool isShadow);
|
||||
void CreateBling();
|
||||
void CreateGoldParticles(uint32_t count);
|
||||
void set_entity_ptr_f54(Entity* entity);
|
||||
void ResetPathFinderTarget();
|
||||
void hold_set(int countdown, const Vector& position);
|
||||
Entity_Effect* MakeSplat(float size);
|
||||
Entity_Effect* MakeBloodCloud(const Vector& pos, const ColorMod& color);
|
||||
bool TryForceTarget(Entity* target, int duration);
|
||||
float compute_speed_multiplier();
|
||||
void load_graphics(uint8_t);
|
||||
void KillUnique();
|
||||
Entity* GetPlayerTarget();
|
||||
Vector CalcTargetPosition(float distanceLimit);
|
||||
void UpdateDirtColor(uint8_t immediate);
|
||||
static uint8_t Redirect(int* entityType, int* variant);
|
||||
void Morph(int entityType, int variant, int subType, int championid);
|
||||
void* shopkeeper_get_loot(void* outLoot, bool isShouldAdvance);
|
||||
static Entity_NPC* ThrowSpider(const Vector& position, Entity* spawner, Vector targetPos, bool isBig,
|
||||
float yOffset);
|
||||
void update_frozen();
|
||||
void fire_projectile_from_params(Entity_Projectile* projectile);
|
||||
void SetBossColorIdx(int bossColorIdx, int unused);
|
||||
void load_graphics(bool isReloadAnm2);
|
||||
void boss_color_roll();
|
||||
static bool Redirect(int* entityType, int* variant);
|
||||
void Morph(int entityType, int variant, int subType, int championId);
|
||||
void MakeChampion(uint32_t seed, int championColor, bool isInit);
|
||||
void SetRef_bec(Entity* entity);
|
||||
static void* QueryNPCsType(void* outList, int type, int variant);
|
||||
static EntityList* QueryNPCsGroup(EntityList* outList, int groupIdx);
|
||||
void* fireplace_get_loot(void* outLoot, bool isShouldAdvance);
|
||||
bool CanBeDamagedFromVelocity(Vector velocity);
|
||||
bool CanReroll();
|
||||
void PlayDeathEffects();
|
||||
void trigger_kill_item_effects();
|
||||
void SetBossColorIdx(int bossColorIdx, int unused);
|
||||
void SetScale(float newScale);
|
||||
void PlaySound(int id, float volume, int framedelay, uint8_t loop, float pitch);
|
||||
int GetAliveEnemyCount();
|
||||
uint32_t on_player_damaged();
|
||||
void UpdateDirtColor(bool isImmediate);
|
||||
void room_enter();
|
||||
|
||||
float compute_speed_multiplier();
|
||||
void ai_call(AiPhase phase);
|
||||
void status_overlay_update();
|
||||
bool paused_update();
|
||||
void appear_update();
|
||||
void appear_init();
|
||||
void death_animation_update();
|
||||
void death_animation_start();
|
||||
void decoy_update();
|
||||
void champion_update();
|
||||
void unreachable_update();
|
||||
void dead_update();
|
||||
void midas_coins_spawn();
|
||||
void toxic_shock_creep_spawn();
|
||||
void player_aura_update();
|
||||
void item_effects_update();
|
||||
void poof02_spawn();
|
||||
void ripple_spawn();
|
||||
void seed_effects_update();
|
||||
void type_update();
|
||||
void forced_target_update();
|
||||
void update_frozen();
|
||||
void update_physics();
|
||||
void apply_velocity(char isInterpolated);
|
||||
void update_move_direction_anim();
|
||||
void update_blood_guide_gibs(float* nullFrame);
|
||||
void spawn_damage_numbers();
|
||||
void update_damage_history();
|
||||
void update_blood_guide_gibs(float* nullFrame);
|
||||
void status_overlay_render(const Vector& offset);
|
||||
void Hornfel_UpdateAI();
|
||||
void Hornfel_UpdateFrame();
|
||||
|
||||
Entity* GetPlayerTarget();
|
||||
Vector CalcTargetPosition(float distanceLimit);
|
||||
bool TryForceTarget(Entity* target, int duration);
|
||||
void ResetPathFinderTarget();
|
||||
bool IsTargetInAttackRange(float range, int frameInterval, bool isPredictVelocity);
|
||||
int GetAliveEnemyCount();
|
||||
void AnimWalkFrame(std::string_view horizontalAnim, std::string_view verticalAnim, float speedThreshold);
|
||||
void PlaySound(int id, float volume, int frameDelay, bool isLoop, float pitch);
|
||||
void FireProjectiles(const Vector& position, const Vector& velocity, ProjectilesMode mode,
|
||||
const ProjectileParams& params);
|
||||
void FireBossProjectiles(int count, const Vector& targetPos, float trajectoryModifier,
|
||||
const ProjectileParams& params);
|
||||
void projectile_params_apply(Entity_Projectile& projectile, const ProjectileParams& params);
|
||||
void fire_projectile_from_params(Entity_Projectile* projectile);
|
||||
Entity_Effect* MakeSplat(float size);
|
||||
Entity_Effect* MakeBloodCloud(const Vector& pos, const ColorMod& color);
|
||||
static Entity_NPC* ThrowSpider(const Vector& position, Entity* spawner, Vector targetPos, bool isBig,
|
||||
float yOffset);
|
||||
|
||||
void player_contact(Entity_Player& player);
|
||||
void enemy_contact(Entity& other);
|
||||
void PlayDeathEffects();
|
||||
int death_burst_get();
|
||||
void trigger_kill_item_effects();
|
||||
void trigger_death_rewards();
|
||||
void KillUnique();
|
||||
bool CanBeDamagedFromVelocity(Vector velocity);
|
||||
bool CanReroll();
|
||||
uint8_t split(float damage, const EntityRef& source, bool isPlaySound);
|
||||
|
||||
Entity_NPC* ParentNPC();
|
||||
Entity_NPC* ChildNPC();
|
||||
void ClearChild();
|
||||
void ClearDequeRefs();
|
||||
void set_entity_ptr_f54(Entity* entity);
|
||||
void SetRef_bec(Entity* entity);
|
||||
void hold_set(int countdown, const Vector& position);
|
||||
|
||||
bool IsControllerActionPressed(int action);
|
||||
bool IsControllerActionTriggered(int buttonAction);
|
||||
Vector GetControllerInput(float deadzone);
|
||||
Vector GetControllerMovementInput(float deadzone);
|
||||
void TransferControl(Entity_NPC* target);
|
||||
void SpawnControlTarget(int inputMode, float rotation);
|
||||
void ClearChild();
|
||||
Vector GetAimTargetPosition();
|
||||
bool is_controller_input_idle();
|
||||
void UpdateChargeBar(float start, float end, float value, bool isHideWhenFull);
|
||||
void UpdateControllerMovement(bool isForceUpdate);
|
||||
void UpdateChildEffectPosition(bool isPredictMovement);
|
||||
uint8_t split(float damage, const EntityRef& source, bool isPlaySound);
|
||||
void UpdatePickupGhosts();
|
||||
void TransferControl(Entity_NPC* target);
|
||||
void SpawnControlTarget(int inputMode, float rotation);
|
||||
Vector GetAimTargetPosition();
|
||||
void SetAimAngle(float angle);
|
||||
static void render_debug(float*, int);
|
||||
void UpdateChargeBar(float start, float end, float value, bool isHideWhenFull);
|
||||
void UpdatePickupGhosts();
|
||||
|
||||
void SetMinecartPosVel(const Vector& pos, const Vector& vel);
|
||||
void MinecartUpdateChild(Entity* child);
|
||||
void UpdateCordChain(bool isHalfScale);
|
||||
void render_overlay(const Vector& offset, bool isShadow);
|
||||
void render_v1_layer_frames();
|
||||
void RenderSegmentLink(const Vector& offset, bool isShadow);
|
||||
void CreateBling();
|
||||
void CreateGoldParticles(uint32_t count);
|
||||
void* shopkeeper_get_loot(void* outLoot, bool isShouldAdvance);
|
||||
void* fireplace_get_loot(void* outLoot, bool isShouldAdvance);
|
||||
uint32_t on_player_damaged();
|
||||
static int FindTargetPit(const Vector& pos1, const Vector& pos2, uint32_t pitIndex);
|
||||
static Entity_NPC* ThrowStrider(const Vector& pos, Entity* spawner, const Vector& targetPos);
|
||||
static void* QueryNPCsType(void* outList, int type, int variant);
|
||||
static EntityList* QueryNPCsGroup(EntityList* outList, int groupIdx);
|
||||
static void render_debug(float* position, int unused);
|
||||
};
|
||||
|
||||
extern bool g_isChampionRollSkipped;
|
||||
|
||||
// Game's, Room's and PlayerManager's queries the enemies need, until those classes carry them.
|
||||
Entity_Player* game_nearest_player(const Vector& position);
|
||||
bool game_is_enemy_erased(Entity& entity);
|
||||
bool any_player_flying();
|
||||
Entity* game_nearest_target_player(const Vector& position, Entity* source, bool isPlayersOnly, bool isTargetDecoys,
|
||||
float maxDistance);
|
||||
void game_shake_screen(int timeout);
|
||||
bool game_is_hard_mode();
|
||||
uint32_t room_grid_collision_at(const Vector& position);
|
||||
bool room_check_line(const Vector& start, const Vector& end, int mode, int gridPathThreshold);
|
||||
+1812
-109
File diff suppressed because it is too large.
Load diff
+49
-7
@@ -8,21 +8,48 @@
|
||||
// The most items a glitched pedestal cycles through.
|
||||
constexpr int CYCLE_COLLECTIBLE_LIMIT = 8;
|
||||
|
||||
// Construction and destruction (006e0130, 006e0010) are the defaults.
|
||||
// Whether pickup_variant_pick draws its trinkets and items for good, or only looks at what a draw would give.
|
||||
enum PoolDraw
|
||||
{
|
||||
POOL_DRAW_PEEK,
|
||||
POOL_DRAW_TAKE
|
||||
};
|
||||
|
||||
// Whether pickup_variant_pick chooses for a shop's wares, which Keeper-only parties never buy hearts for.
|
||||
enum PickupSale
|
||||
{
|
||||
PICKUP_FREE,
|
||||
PICKUP_FOR_SALE
|
||||
};
|
||||
|
||||
// A pickup kind to choose (Pickup_PickVariant): a variant and subtype where 0 asks for a random one, the seed the
|
||||
// choice comes from, and how it draws from the pools.
|
||||
struct PickupChoice
|
||||
{
|
||||
int subType = 0;
|
||||
int variant = 0;
|
||||
uint32_t seed = 0;
|
||||
PoolDraw draw = POOL_DRAW_TAKE;
|
||||
PickupSale sale = PICKUP_FREE;
|
||||
};
|
||||
|
||||
// Construction and destruction (006e0130, 006e0010, 006e0160) are the defaults.
|
||||
// Field accessors (00431740, 005b1940, 005b1980, 007e9390, 007e93a0, 007e93b0, 007e93c0, 0085e440) are the public
|
||||
// fields.
|
||||
// A pickup (Lua's EntityPickup): coins, hearts, keys, chests, cards, items on pedestals and the like, with the price
|
||||
// a shop sets, its timeout, and the items a glitched pedestal cycles through.
|
||||
// a shop sets, its timeout, the height a thrown chest flies at, and the items a glitched pedestal cycles through.
|
||||
struct Entity_Pickup : Entity
|
||||
{
|
||||
ANM2 altPedestalANM2;
|
||||
ANM2 priceANM2;
|
||||
std::array<Entity_Pickup*, 2> megaChestCollectible{};
|
||||
std::array<EntityPtr, 2> megaChestCollectible;
|
||||
std::array<uint32_t, CYCLE_COLLECTIBLE_LIMIT> cycleCollectibleList{};
|
||||
std::shared_ptr<EntitySaveState> flipSaveState;
|
||||
ColorMod colorMod = COLOR_DEFAULT;
|
||||
EntityPtr pickupGhost;
|
||||
EntityPtr unkEntityRef;
|
||||
Entity_Effect* pickupGhost = nullptr;
|
||||
float height = 0;
|
||||
float heightVelocity = 0;
|
||||
int charge = 0;
|
||||
int chestReCloseTimer = 0;
|
||||
int collisionCooldown = 0;
|
||||
@@ -43,6 +70,7 @@ struct Entity_Pickup : Entity
|
||||
bool isForceBlind = false;
|
||||
bool isPayToPlay = false;
|
||||
bool isTouched = false;
|
||||
bool isUnknown52d = false;
|
||||
|
||||
void Init(int type, int variant, int subType, uint32_t initSeed) override;
|
||||
void Update() override;
|
||||
@@ -63,7 +91,7 @@ struct Entity_Pickup : Entity
|
||||
int GetAlternatePedestal();
|
||||
void SetForceBlind(uint8_t setBlind);
|
||||
void UpdateSprite(bool isIgnoreBlind);
|
||||
void update_price_sprite(int price);
|
||||
void update_price_sprite(int newPrice);
|
||||
void AppearFast();
|
||||
bool TryOpenChest(Entity_Player* player);
|
||||
void PlayDropSound();
|
||||
@@ -77,10 +105,24 @@ struct Entity_Pickup : Entity
|
||||
bool CanReroll();
|
||||
static bool CanRerollVariant(int variant, int subType);
|
||||
static bool IsChest(int pickupVariant);
|
||||
bool CanBePickedUp(bool ignorePrice);
|
||||
bool CanBePickedUp(bool isIgnorePrice);
|
||||
bool CanJeraDuplicate();
|
||||
static void RemoveOtherOptions();
|
||||
void RemoveOtherOptions();
|
||||
void MakeShopItem(int shopId);
|
||||
int AssignOptionsIndex();
|
||||
static void RestoreState(Room* room, Entity_Pickup* entity, void* saveState);
|
||||
|
||||
private:
|
||||
void appear_start();
|
||||
bool keeper_flies_update();
|
||||
void target_position_update();
|
||||
void appear_update();
|
||||
bool heart_collect(Entity_Player& player);
|
||||
void coin_collect(Entity_Player& player);
|
||||
bool key_collect(Entity_Player& player);
|
||||
bool bomb_collect(Entity_Player& player);
|
||||
void collect_finish(Entity_Player* player);
|
||||
};
|
||||
|
||||
bool pickup_variant_pick(PickupChoice& choice);
|
||||
bool entity_type_is_saved(int type, int variant, uint32_t subType, int spawnerType, bool isRoomEntry);
|
||||
@@ -691,6 +691,7 @@ public:
|
||||
uint8_t holyMantleStacks = 0;
|
||||
uint8_t holyMantleState = 0;
|
||||
bool isHurtPending = false;
|
||||
bool isHurtThisRoom = false;
|
||||
|
||||
std::shared_ptr<PlayerHUD> playerHUD;
|
||||
std::vector<Entity*> contactHitList;
|
||||
@@ -762,6 +763,7 @@ public:
|
||||
int eveSumptoriumCharge = 0;
|
||||
int forgottenSwapFormCooldown = 0;
|
||||
int gnawedLeafTimer = 0;
|
||||
int evilCharmHazardFrames = 0;
|
||||
int hallowedGroundCountdown = 0;
|
||||
int immaculateConceptionState = 0;
|
||||
int keepersSackBonus = 0;
|
||||
@@ -801,6 +803,7 @@ public:
|
||||
short tonsilCounter = 0;
|
||||
bool isBrokenRemotePending = false;
|
||||
bool isDarkArtsBlastPending = false;
|
||||
bool isInEvilCharmHazard = false;
|
||||
bool isLevelStartPending = false;
|
||||
bool isMarsDashReady = true;
|
||||
bool isPostLevelInitFinished = false;
|
||||
@@ -1010,6 +1013,7 @@ public:
|
||||
bool TryUseKey();
|
||||
void AddCostume(ItemConfig_Item* item, bool isItemStateOnly);
|
||||
void AddNullCostume(int costumeid);
|
||||
bool IsItemCostumeVisible(ItemConfig_Item* item, int playerSpriteLayerID);
|
||||
bool IsNullItemCostumeVisible(int nullItemID, int playerSpriteLayerID);
|
||||
void ClearQueueItem();
|
||||
bool FlushQueueItem();
|
||||
@@ -1038,6 +1042,8 @@ public:
|
||||
void update_bomb_input();
|
||||
void trigger_fire_item_effects(Vector direction, bool isShotFired);
|
||||
const char* GetDeathAnimName();
|
||||
void death_count(const EntityRef& source, uint64_t damageFlags);
|
||||
void death_update();
|
||||
Entity* GetActiveWeaponEntity();
|
||||
uint32_t CanTurnHead();
|
||||
float FireDelay();
|
||||
@@ -1182,6 +1188,7 @@ public:
|
||||
void ChangePlayerType(int playerType, bool isUnknown);
|
||||
void player_type_change_prepare(int newPlayerType);
|
||||
bool IsLocalPlayer();
|
||||
float local_volume_get();
|
||||
void GetGlyphOfBalanceDrop(int* variant, int* subtype);
|
||||
Vector GetEnterPosition();
|
||||
Entity_Familiar* AddMinisaac(Vector position, bool isPlayAnim);
|
||||
|
||||
@@ -0,0 +1,861 @@
|
||||
#include "entity_familiar.h"
|
||||
#include "entity_npc.h"
|
||||
#include "entity_player.h"
|
||||
#include "game.h"
|
||||
#include "level.h"
|
||||
#include "log.h"
|
||||
#include "lua_engine.h"
|
||||
#include "manager.h"
|
||||
#include "room.h"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
constexpr int COLLECTIBLE_BINKY = 438;
|
||||
constexpr int COLLECTIBLE_BOBS_CURSE = 140;
|
||||
constexpr int COLLECTIBLE_BOOMERANG = 338;
|
||||
constexpr int COLLECTIBLE_CONE_HEAD = 457;
|
||||
constexpr int COLLECTIBLE_DOGMA = 633;
|
||||
constexpr int COLLECTIBLE_DULL_RAZOR = 486;
|
||||
constexpr int COLLECTIBLE_EVIL_CHARM = 632;
|
||||
constexpr int COLLECTIBLE_GLASS_CANNON = 352;
|
||||
constexpr int COLLECTIBLE_HOST_HAT = 375;
|
||||
constexpr int COLLECTIBLE_HOT_BOMBS = 256;
|
||||
constexpr int COLLECTIBLE_HYPERCOAGULATION = 724;
|
||||
constexpr int COLLECTIBLE_INNER_CHILD = 688;
|
||||
constexpr int COLLECTIBLE_IPECAC = 149;
|
||||
constexpr int COLLECTIBLE_ISAACS_HEART = 276;
|
||||
constexpr int COLLECTIBLE_JELLY_BELLY = 690;
|
||||
constexpr int COLLECTIBLE_LARYNX = 611;
|
||||
constexpr int COLLECTIBLE_MARBLES = 538;
|
||||
constexpr int COLLECTIBLE_METAL_PLATE = 449;
|
||||
constexpr int COLLECTIBLE_MOMS_BRACELET = 604;
|
||||
constexpr int COLLECTIBLE_PLUTO = 598;
|
||||
constexpr int COLLECTIBLE_PYROMANIAC = 223;
|
||||
constexpr int COLLECTIBLE_SCAPULAR = 142;
|
||||
constexpr int COLLECTIBLE_SHOOP_DA_WHOOP = 49;
|
||||
constexpr int COLLECTIBLE_SPIRIT_SHACKLES = 674;
|
||||
constexpr int COLLECTIBLE_ASTRAL_PROJECTION = 677;
|
||||
constexpr int COLLECTIBLE_BERSERK = 704;
|
||||
constexpr int COLLECTIBLE_BLACK_CANDLE = 260;
|
||||
constexpr int COLLECTIBLE_THE_NAIL = 83;
|
||||
constexpr int TRINKET_BLIND_RAGE = 81;
|
||||
constexpr int TRINKET_CALLUS = 14;
|
||||
constexpr int TRINKET_CROW_HEART = 107;
|
||||
constexpr int TRINKET_FINGER_BONE = 128;
|
||||
constexpr int TRINKET_MONKEY_PAW = 20;
|
||||
constexpr int TRINKET_PERFECTION = 145;
|
||||
constexpr int TRINKET_SWALLOWED_M80 = 178;
|
||||
constexpr int TRINKET_WALNUT = 108;
|
||||
constexpr int NULLITEM_BOOMERANG = 30;
|
||||
constexpr int NULLITEM_DOUBLE_DAMAGE = 29;
|
||||
constexpr int NULLITEM_SHACKLES_GHOST = 101;
|
||||
constexpr int PLAYER_FORM_ADULT = 11;
|
||||
constexpr int PLAYER_FORM_BEELZEBUB = 13;
|
||||
constexpr int PLAYER_FORM_BOB = 4;
|
||||
constexpr int SAMSON_B_HIT_CHARGE = 10000;
|
||||
constexpr int BLEED_OUT_HEALTH = 600;
|
||||
|
||||
// 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_TRINKETS[] = {40, 48, 29, 1, 8, 67, 158, 97, 105, 33, 104, 122};
|
||||
constexpr int CROWN_OF_LIGHT = 415;
|
||||
constexpr int HYPERCOAGULATION_IGNORED = 0x10040000;
|
||||
|
||||
constexpr int ENTITY_MOM = 45;
|
||||
constexpr int ENTITY_MOMS_HEART = 78;
|
||||
constexpr int ENTITY_BISHOP = 805;
|
||||
constexpr int ENTITY_SEGMENTED_WORM = 903;
|
||||
constexpr int ENTITY_DAMAGE_RELAY = 966;
|
||||
constexpr int SEGMENTED_WORM_VARIANT = 10;
|
||||
constexpr int WHITE_FIRE_VARIANT = 4;
|
||||
constexpr int EFFECT_SELF_DAMAGE = 19;
|
||||
constexpr int EFFECT_POISON_CLOUD = 123;
|
||||
constexpr int FAMILIAR_WISP = 206;
|
||||
constexpr int ITEM_STATE_HOLD_STILL = 47;
|
||||
constexpr int ENEMY_TYPE_FIRST = 10;
|
||||
constexpr int ENEMY_TYPE_LAST = 999;
|
||||
constexpr int BABY_GHOST = 59;
|
||||
constexpr int BABY_HALO = 24;
|
||||
constexpr int BABY_SHIELD = 11;
|
||||
constexpr int BABY_BOMB = 20;
|
||||
constexpr int BABY_FART = 17;
|
||||
constexpr int BABY_BOOK = 44;
|
||||
|
||||
// The thieves that knock a coin loose: Greed and its likes by their hits or shots, the Ultra Greeds also by what they
|
||||
// spawn.
|
||||
constexpr int COIN_THIEF_TYPES[] = {50, 86, 90, 294, 299, 406};
|
||||
constexpr int COIN_SHOOTER_TYPES[] = {50, 86, 90};
|
||||
constexpr int ULTRA_GREED = 406;
|
||||
constexpr int ULTRA_GREED_DOOR = 294;
|
||||
constexpr uint32_t CHALLENGE_PAY_TO_PLAY = 24;
|
||||
|
||||
constexpr int SOUND_FIREDEATH_HISS = 43;
|
||||
constexpr int SOUND_ISAAC_HURT_GRUNT = 55;
|
||||
constexpr int SOUND_NAIL_HURT_1 = 104;
|
||||
constexpr int SOUND_NAIL_HURT_2 = 106;
|
||||
constexpr int SOUND_MOM_VOX = 84;
|
||||
constexpr int SOUND_HEARTBEAT = 86;
|
||||
constexpr int SOUND_BOSS_DELAY_RANDOM = 130;
|
||||
constexpr int SOUND_BOSS_DELAY_MIN = 50;
|
||||
constexpr int SOUND_FRAME_DELAY = 2;
|
||||
|
||||
constexpr uint64_t DAMAGE_RED_HEARTS = 1ull << 5;
|
||||
constexpr uint64_t DAMAGE_INVINCIBLE_IGNORED = 1ull << 13;
|
||||
constexpr uint64_t DAMAGE_SPAWN_FLY = 1ull << 14;
|
||||
constexpr uint64_t DAMAGE_FAKE = 1ull << 21;
|
||||
constexpr uint64_t DAMAGE_NO_MODIFIERS = 1ull << 25;
|
||||
constexpr uint64_t DAMAGE_NO_PENALTIES = 1ull << 28;
|
||||
constexpr uint64_t DAMAGE_IGNORED = 1ull << 34;
|
||||
constexpr uint64_t DAMAGE_THROUGH_COOLDOWN = 1ull << 35;
|
||||
constexpr uint64_t DAMAGE_NO_HURT_EFFECTS = 0x100d0400;
|
||||
constexpr uint64_t DAMAGE_ISAACS_HEART_PIERCE = 0x2820;
|
||||
constexpr uint64_t DAMAGE_UNPENALIZED = DAMAGE_NO_PENALTIES | DAMAGE_RED_HEARTS;
|
||||
|
||||
constexpr int LEVEL_STATE_DAMAGED = 5;
|
||||
constexpr int LAST_DAMAGE_STAGE_MAX = 13;
|
||||
constexpr int HURT_FRAMES_PER_HEART = 60;
|
||||
constexpr int HURT_HEARTS_MAX = 2;
|
||||
constexpr int HIT_COOLDOWN = 4;
|
||||
constexpr int MC_ENTITY_TAKE_DMG = 11;
|
||||
constexpr uint32_t DEBUG_INFINITE_HP = 1 << 2;
|
||||
constexpr uint32_t DEBUG_DAMAGE_VALUES = 1 << 6;
|
||||
constexpr uint32_t STAGE_FULL_HEART_DAMAGE = 7;
|
||||
constexpr int MASSIVE_DAMAGE = 24;
|
||||
constexpr int EVIL_CHARM_GRACE_FRAMES = 30;
|
||||
constexpr int COOLDOWN_SCALE_MIN = 16;
|
||||
constexpr int COOLDOWN_SCALE_SHIFT = 3;
|
||||
constexpr int CROW_HEART_KEEP_2 = 25;
|
||||
constexpr int CROW_HEART_KEEP_3 = 50;
|
||||
constexpr float DAMAGE_ROUNDING = 0.5f;
|
||||
constexpr float HALVED_DAMAGE = 0.5f;
|
||||
constexpr float HALVED_DAMAGE_DEATHMATCH = 0.75f;
|
||||
constexpr float DOUBLED_DAMAGE_DEATHMATCH = 1.25f;
|
||||
constexpr float VOICE_PITCH_PLAYER = 1;
|
||||
constexpr float VOICE_PITCH_BABY = 1.5f;
|
||||
constexpr float VOICE_PITCH_PER_PILL = 0.1f;
|
||||
constexpr float VOICE_PITCH_PLUTO = 0.5f;
|
||||
constexpr float VOICE_PITCH_STEP = 0.2f;
|
||||
constexpr float VOICE_PITCH_MIN = 0.5f;
|
||||
constexpr float VOICE_PITCH_MAX = 2;
|
||||
constexpr float REMOTE_VOLUME_SCALE = 0.1f;
|
||||
constexpr int PILL_EFFECT_PUBERTY = 33;
|
||||
constexpr int PILL_EFFECT_HELIUM = 32;
|
||||
|
||||
// The extra lives the HUD counts: 1up!, Ankh, Guppy's Collar, Judas' Shadow, Lazarus' Rags and Inner Child.
|
||||
constexpr int EXTRA_LIFE_ITEMS[] = {11, 161, 212, 311, 332, 688};
|
||||
constexpr int TAINTED_LOST_BIRTHRIGHT = 619;
|
||||
|
||||
// The hazards Evil Charm protects from: fires, creep, and the effects that hurt on contact.
|
||||
constexpr int EVIL_CHARM_EFFECTS[] = {22, 23, 24, 25, 26, 32, 37, 44, 45, 46, 53, 54, 56, 78, 90, 94, 141, 147, 155, 169, 204};
|
||||
constexpr int EVIL_CHARM_GRID_VARIANT = 10000;
|
||||
|
||||
// The temporary effects that make the player invincible to any hit: Gamekid, My Little Unicorn, Unicorn Stump and
|
||||
// Teleport.
|
||||
constexpr int INVINCIBLE_EFFECTS[] = {93, 77, 298, 44};
|
||||
constexpr int COLLECTIBLE_BREATH_OF_LIFE = 326;
|
||||
constexpr int COLLECTIBLE_DARK_ARTS = 705;
|
||||
constexpr int COLLECTIBLE_GNAWED_LEAF = 210;
|
||||
constexpr int NULLITEM_INVINCIBLE_SHIELD = 59;
|
||||
constexpr int BLOOD_DONATION_VARIANT = 2;
|
||||
constexpr int BLOOD_BANK_VARIANT = 5;
|
||||
constexpr float GNAWED_LEAF_MASS = 1000;
|
||||
constexpr int BREATH_OF_LIFE_WINDOW = 5;
|
||||
|
||||
// Whether a hit passes the player by: its own self damage, friendly sources, another's Dark Esau, a dead player,
|
||||
// Isaac's Heart, Evil Charm's hazards, and a co-op baby still appearing.
|
||||
static bool is_damage_ignored(Entity_Player& player, const EntityRef& source, uint64_t damageFlags)
|
||||
{
|
||||
Game& game = *g_game;
|
||||
Entity* entity = source.entity;
|
||||
|
||||
if (source.type == ENTITY_EFFECT && source.variant == EFFECT_SELF_DAMAGE && source.spawnerType == ENTITY_PLAYER)
|
||||
return true;
|
||||
if (source.IsFriendly() && !game.deathmatchManager.is_active()) return true;
|
||||
if (source.IsFriendly()) reconstruction_missing("Entity_Player::TakeDamage 007729d0 (friendly fire in versus)");
|
||||
if (damageFlags & DAMAGE_IGNORED) return true;
|
||||
|
||||
Entity* darkEsau = player.darkEsau.get();
|
||||
bool isOtherEsau = entity && entity->type == ENTITY_DARK_ESAU && entity != darkEsau &&
|
||||
(entity->parent.get() != darkEsau || !darkEsau) && (entity->child.get() != darkEsau || !darkEsau) &&
|
||||
entity->spawnerEntity.get() != &player && entity->spawnerEntity.get() != darkEsau;
|
||||
if (isOtherEsau || player.isDead) return true;
|
||||
|
||||
Entity_Player* heartOwner = player.playerType == PLAYER_THESOUL_B && player.twin_get() ? player.twin_get() : &player;
|
||||
bool isHeartProtected = heartOwner->HasCollectible(COLLECTIBLE_ISAACS_HEART) || player.playerType == PLAYER_THEFORGOTTEN_B;
|
||||
if (isHeartProtected && !(damageFlags & DAMAGE_ISAACS_HEART_PIERCE)) return true;
|
||||
if (player.is_evil_charm_immune(source)) return true;
|
||||
|
||||
bool isAppearing = player.sprite.IsPlaying("Appear") || player.sprite.IsPlaying("Glitch");
|
||||
if ((player.variant == PLAYER_VARIANT_COOP_BABY || player.isCoopGhost) && isAppearing) return true;
|
||||
if (source.type == ENTITY_SEGMENTED_WORM && source.variant == SEGMENTED_WORM_VARIANT && entity)
|
||||
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (a worm segment of the player's own)");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Whether a Bishop the player charmed stands in the room to take the hit (find_nearest_enemy 004e7d10).
|
||||
static bool is_bishop_present()
|
||||
{
|
||||
return std::ranges::any_of(g_game->room->entityList.updateEL, [](Entity* entity)
|
||||
{ return entity->type == ENTITY_BISHOP && entity->HasEntityFlags(FLAG_CHARM); });
|
||||
}
|
||||
|
||||
// Whether a wisp of the player's could take the hit (FUN_007c7b10).
|
||||
static bool is_wisp_shield_present(Entity_Player& player)
|
||||
{
|
||||
return std::ranges::any_of(g_game->room->entityList.updateEL, [&](Entity* entity)
|
||||
{
|
||||
return !entity->isDead && entity->IsFamiliar() && entity->variant == FAMILIAR_WISP &&
|
||||
entity->subtype == COLLECTIBLE_DULL_RAZOR &&
|
||||
static_cast<Entity_Familiar*>(entity)->player == &player;
|
||||
});
|
||||
}
|
||||
|
||||
// The items that answer a hit before it lands, each stopping or turning it, none written yet.
|
||||
static void damage_reactions_check(Entity_Player& player, uint64_t damageFlags)
|
||||
{
|
||||
bool isExplosion = damageFlags & DAMAGE_EXPLOSION;
|
||||
bool isFire = damageFlags & DAMAGE_FIRE;
|
||||
|
||||
if (is_bishop_present()) reconstruction_missing("Entity_Player::TakeDamage 007729d0 (a charmed Bishop's shield)");
|
||||
if (player.HasTrinket(TRINKET_WALNUT) && isExplosion)
|
||||
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Walnut)");
|
||||
if (player.HasCollectible(COLLECTIBLE_PYROMANIAC) && (isFire || isExplosion))
|
||||
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Pyromaniac)");
|
||||
if (player.HasCollectible(COLLECTIBLE_HOST_HAT))
|
||||
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Host Hat)");
|
||||
bool isFetus = player.HasWeaponType(WEAPON_BOMBS) || player.HasWeaponType(WEAPON_BONE);
|
||||
if (isFetus && player.HasCollectible(COLLECTIBLE_IPECAC) && isExplosion)
|
||||
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Ipecac with Dr. Fetus)");
|
||||
if (player.HasCollectible(COLLECTIBLE_HOT_BOMBS) && isFire)
|
||||
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Hot Bombs)");
|
||||
if (player.variant == PLAYER_VARIANT_COOP_BABY && player.babySkin == BABY_BOMB && isExplosion)
|
||||
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (the bomb baby)");
|
||||
if (player.HasCollectible(COLLECTIBLE_JELLY_BELLY) && !(damageFlags & (DAMAGE_NO_MODIFIERS | DAMAGE_FAKE)))
|
||||
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Jelly Belly)");
|
||||
if (player.HasCollectible(COLLECTIBLE_METAL_PLATE) || player.HasCollectible(COLLECTIBLE_CONE_HEAD))
|
||||
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Metal Plate and Cone Head)");
|
||||
}
|
||||
|
||||
// Whether a list of ids has one.
|
||||
template <size_t N> static bool is_listed(const int (&ids)[N], int id)
|
||||
{
|
||||
return std::ranges::find(ids, id) != std::end(ids);
|
||||
}
|
||||
|
||||
// A random number below max, or 0 for none (Isaac::Random 0067f010).
|
||||
static int random_below(int max)
|
||||
{
|
||||
return max == 0 ? 0 : (int)(Random() % (uint32_t)max);
|
||||
}
|
||||
|
||||
// 007db330 A damage cooldown in frames, scaled down in versus.
|
||||
static int damage_cooldown_scale(int frames)
|
||||
{
|
||||
if (!g_game->deathmatchManager.is_active()) return frames;
|
||||
return frames > COOLDOWN_SCALE_MIN - 1 ? frames >> COOLDOWN_SCALE_SHIFT : 1;
|
||||
}
|
||||
|
||||
// The bestiary count an enemy adds to, unless the save is frozen or the enemy has no page.
|
||||
static void bestiary_count_add(std::map<int, int>& counts, int type, int variant)
|
||||
{
|
||||
PersistentGameData& data = g_manager->persistentGameData;
|
||||
EntityConfig_Entity* entity = data.isReadOnly ? nullptr : g_manager->entityConfig.GetBestiaryConfig(type, variant);
|
||||
if (entity && entity->isBestiary) counts[entity->id << 20 | entity->variant << 8]++;
|
||||
}
|
||||
|
||||
// Plays one of the player's sounds at a volume and pitch, unless the seeds swap it for a fart.
|
||||
static void voice_play(int sound, float volume, int frameDelay, float pitch)
|
||||
{
|
||||
seed_fart_sound_override(&sound);
|
||||
g_manager->sfxManager.Play(sound, {.volume = volume, .frameDelay = frameDelay, .pitch = pitch});
|
||||
}
|
||||
|
||||
// The damage a hit deals in half hearts: rounded, two from the Womb on or on a victory lap, halved by the Wafer and
|
||||
// its likes, doubled by the double damage effect, and set by the seeds that hurt more.
|
||||
static int damage_amount_get(Entity_Player& player, float damage, uint64_t damageFlags, const EntityRef& source)
|
||||
{
|
||||
Game& game = *g_game;
|
||||
bool isDeathmatch = game.deathmatchManager.is_active();
|
||||
int amount = (int)(damage + DAMAGE_ROUNDING);
|
||||
|
||||
if (isDeathmatch && amount == 0 && damage > 0) amount = 1;
|
||||
if (damageFlags & DAMAGE_NO_MODIFIERS) return amount;
|
||||
|
||||
if (!game.IsGreedMode() && (game.stage >= STAGE_FULL_HEART_DAMAGE || game.victoryLap >= 1 || game.IsAscent()))
|
||||
amount = std::max(amount, 2);
|
||||
|
||||
bool isHardMode = game.difficulty == DIFFICULTY_HARD || game.difficulty == DIFFICULTY_GREEDIER;
|
||||
bool isHalved = player.HasCollectible(COLLECTIBLE_WAFER) ||
|
||||
player.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_WAFER) ||
|
||||
player.GetTrinketMultiplier(TRINKET_CALLUS) > 2 || (source.flags & ENTITY_REF_WEAKNESS) ||
|
||||
(player.HasCollectible(COLLECTIBLE_DOGMA) && !isHardMode);
|
||||
if (isHalved && amount > 1)
|
||||
amount = std::max((int)((float)amount * (isDeathmatch ? HALVED_DAMAGE_DEATHMATCH : HALVED_DAMAGE) + DAMAGE_ROUNDING), 1);
|
||||
if (player.temporaryEffects.HasNullEffect(NULLITEM_DOUBLE_DAMAGE))
|
||||
amount = (int)((float)std::max(amount, 2) * (isDeathmatch ? DOUBLED_DAMAGE_DEATHMATCH : 1));
|
||||
if (player.GetHealthType() == HEALTH_COIN) amount = 2;
|
||||
if (game.seedEffects.HasSeedEffect(SEED_ISAAC_TAKES_HIGH_DAMAGE)) amount = std::max(amount, 2);
|
||||
if (game.seedEffects.HasSeedEffect(SEED_ISAAC_TAKES_MASSIVE_DAMAGE)) amount = std::max(amount, MASSIVE_DAMAGE);
|
||||
return amount;
|
||||
}
|
||||
|
||||
// Takes a hit's half hearts from soul hearts first, then red ones, marking the floor as hurt for the red heart deals.
|
||||
// Bone hearts, Crow Heart and red heart hits are not written yet.
|
||||
static void hearts_remove(Entity_Player& player, int amount, uint64_t damageFlags, bool isPenalized)
|
||||
{
|
||||
if (player.boneHearts > 0) reconstruction_missing("Entity_Player::TakeDamage 007729d0 (bone hearts)");
|
||||
if ((damageFlags & DAMAGE_RED_HEARTS) || player.HasTrinket(TRINKET_CROW_HEART))
|
||||
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (hits that take red hearts first)");
|
||||
|
||||
int soulBoneCount = (player.soulHearts + 1) / 2 + player.boneHearts;
|
||||
int filledCount = (std::min(player.redHearts, player.maxHearts) + 1) / 2;
|
||||
|
||||
if (player.soulHearts > 0)
|
||||
{
|
||||
amount = std::min(amount, player.soulHearts);
|
||||
for (int heart = player.soulHearts; heart > player.soulHearts - amount; heart--)
|
||||
if (player.IsBlackHeart(heart)) reconstruction_missing("Entity_Player::TakeDamage 007729d0 (black hearts)");
|
||||
if (player.eternalHearts > 0 && player.redHearts < 1 && player.boneHearts < 1 && player.soulHearts - amount < 1)
|
||||
{
|
||||
amount = std::max(amount - player.eternalHearts, 0);
|
||||
player.eternalHearts = 0;
|
||||
}
|
||||
if (amount > 0) player.soulHearts -= std::min(player.soulHearts, amount);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (player.rottenHearts > 0 && player.eternalHearts < 1) amount += std::min(player.rottenHearts, amount);
|
||||
if (player.eternalHearts > 0)
|
||||
{
|
||||
amount = std::max(amount - player.eternalHearts, 0);
|
||||
player.eternalHearts = 0;
|
||||
}
|
||||
|
||||
bool isRedLost = amount > player.rottenHearts * 2;
|
||||
player.rottenHearts = std::max(player.rottenHearts - (amount + 1) / 2, 0);
|
||||
player.AddHearts(-amount, false, false);
|
||||
|
||||
bool isKeeper = player.playerType == PLAYER_KEEPER || player.playerType == PLAYER_KEEPER_B;
|
||||
if (player.playerType == PLAYER_MAGDALENE_B)
|
||||
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Tainted Magdalene's red heart damage)");
|
||||
if (isRedLost && !isKeeper && !player.parent && isPenalized && amount > 0 && player.redHearts < player.maxHearts)
|
||||
{
|
||||
int multiplier = player.GetTrinketMultiplier(TRINKET_CROW_HEART);
|
||||
uint32_t keptChance = multiplier == 2 ? CROW_HEART_KEEP_2 : multiplier >= 3 ? CROW_HEART_KEEP_3 : 0;
|
||||
if (player.GetTrinketRNG(TRINKET_CROW_HEART).RandomInt(100) >= keptChance)
|
||||
{
|
||||
g_game->SetRedHeartDamage();
|
||||
g_game->room->isRedHeartDamaged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
player.update_greeds_gullet();
|
||||
int golden = player.goldenHearts;
|
||||
int newSoulBoneCount = (player.soulHearts + 1) / 2 + player.boneHearts;
|
||||
int newFilledCount = (std::min(player.redHearts, player.maxHearts) + 1) / 2;
|
||||
for (; soulBoneCount > newSoulBoneCount && player.goldenHearts > 0; soulBoneCount--) player.goldenHearts--;
|
||||
for (; filledCount > newFilledCount && player.goldenHearts > 0; filledCount--) player.goldenHearts--;
|
||||
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.
|
||||
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); }) ||
|
||||
std::ranges::any_of(HIT_TRINKETS, [&](int trinket) { return player.HasTrinket(trinket); }) ||
|
||||
(isPenalized && player.HasTrinket(TRINKET_PERFECTION)) || player.HasPlayerForm(PLAYER_FORM_BEELZEBUB) ||
|
||||
(player.HasCollectible(CROWN_OF_LIGHT) && !g_game->deathmatchManager.is_active()) ||
|
||||
(player.HasCollectible(COLLECTIBLE_HYPERCOAGULATION) && !(damageFlags & HYPERCOAGULATION_IGNORED)) ||
|
||||
std::ranges::any_of(player.activeItems, [](const ActiveItemDesc& active) { return active.item == COLLECTIBLE_LARYNX; });
|
||||
if (isItemHit) reconstruction_missing("Entity_Player::TakeDamage 007729d0 (the items and trinkets a hit sets off)");
|
||||
if (player.playerType == PLAYER_SAMSON_B && (player.redHearts > 0 || player.soulHearts > 0 || player.boneHearts > 0))
|
||||
player.add_samson_berserk_charge(SAMSON_B_HIT_CHARGE);
|
||||
|
||||
if (player.HasEntityFlags(FLAG_BLEED_OUT) && player.bleedSource.entity == &player && player.bleedOutHealth > 0)
|
||||
player.bleedOutHealth = BLEED_OUT_HEALTH;
|
||||
if (!player.proceduralItems.empty())
|
||||
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (glitched items, trigger_set_dispatch)");
|
||||
}
|
||||
|
||||
// 007729d0 The player takes a hit: the hit is ignored or turned by many items, then costs its hearts, plays the hurt
|
||||
// grunt and the Hit animation, starts the invincibility frames, and kills the player out of hearts. True when it hurt.
|
||||
bool Entity_Player::TakeDamage(float damage, uint64_t damageFlags, const EntityRef& source, int damageCountdown)
|
||||
{
|
||||
Game& game = *g_game;
|
||||
Entity_Player* twin = twin_get();
|
||||
|
||||
if (playerType == PLAYER_THESOUL_B && twin && !twin->HasCollectible(COLLECTIBLE_ISAACS_HEART))
|
||||
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (the Forgotten's soul passing the hit on)");
|
||||
if (source.entity && (source.type == ENTITY_DAMAGE_RELAY || source.type == ENTITY_FAMILIAR))
|
||||
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (a familiar or relay source)");
|
||||
if (is_wisp_shield_present(*this)) reconstruction_missing("Entity_Player::TakeDamage 007729d0 (wisp shields)");
|
||||
if (source.type == ENTITY_FIREPLACE && source.variant == WHITE_FIRE_VARIANT)
|
||||
{
|
||||
bool isGhost = playerType == PLAYER_THELOST || playerType == PLAYER_THELOST_B || playerType == PLAYER_THESOUL_B;
|
||||
if (isGhost || HasInstantDeathCurse() || isDead) return false;
|
||||
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (white fire's lost curse)");
|
||||
}
|
||||
if (IsHologram() || is_damage_ignored(*this, source, damageFlags)) return false;
|
||||
damage_reactions_check(*this, damageFlags);
|
||||
|
||||
if (!(damageFlags & DAMAGE_NO_HURT_EFFECTS)) play_hurt_effects();
|
||||
bool isSeedProtected = game.seedEffects.HasSeedEffect(SEED_INVINCIBLE) ||
|
||||
(variant == PLAYER_VARIANT_COOP_BABY && game.seedEffects.HasSeedEffect(SEED_KIDS_MODE)) ||
|
||||
(game.deathmatchManager.is_active() && isInvincible);
|
||||
if (isSeedProtected)
|
||||
{
|
||||
damageCooldown = std::min((int)(damage + DAMAGE_ROUNDING), HURT_HEARTS_MAX) * HURT_FRAMES_PER_HEART;
|
||||
return false;
|
||||
}
|
||||
bool isPoisonImmune = HasPoisonImmunity() && !(source.type == ENTITY_EFFECT && source.variant == EFFECT_POISON_CLOUD);
|
||||
if (damage <= 0 && (damageFlags & DAMAGE_POISON_BURN) && !isPoisonImmune)
|
||||
{
|
||||
damageEvents.push_back({.source = source, .damage = damage, .damageFlags = damageFlags});
|
||||
pendingDamageFlags |= damageFlags;
|
||||
pendingDamage += damage;
|
||||
}
|
||||
|
||||
int hurtFrames = (int)(damage + DAMAGE_ROUNDING);
|
||||
int amount = damage_amount_get(*this, damage, damageFlags, source);
|
||||
bool isFake = damageFlags & DAMAGE_FAKE;
|
||||
if (isFake) amount = 0;
|
||||
if (damageFlags & DAMAGE_SPAWN_FLY) reconstruction_missing("Entity_Player::TakeDamage 007729d0 (a fly for the hit)");
|
||||
|
||||
bool isInvincibleNow = HasInvincibility(damageFlags, source);
|
||||
bool isPenalized = !(damageFlags & DAMAGE_UNPENALIZED);
|
||||
if (variant == PLAYER_VARIANT_COOP_BABY && babySkin == BABY_SHIELD && hasBabyRoomShield)
|
||||
{
|
||||
isInvincibleNow = true;
|
||||
hasBabyRoomShield = false;
|
||||
}
|
||||
bool isBlocked = (damageCooldown > 0 && !(damageFlags & DAMAGE_THROUGH_COOLDOWN)) || damage <= 0 || isInvincibleNow;
|
||||
if (isBlocked && !isFake) return false;
|
||||
|
||||
if (temporaryEffects.HasCollectibleEffect(COLLECTIBLE_HOLY_MANTLE) && !(damageFlags & DAMAGE_RED_HEARTS))
|
||||
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Holy Mantle's shield)");
|
||||
if (hallowedGroundCountdown > 0 && !(damageFlags & DAMAGE_NO_MODIFIERS))
|
||||
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Hallowed Ground)");
|
||||
if (static_cast<LuaEngine*>(g_luaEngine)->enabledCallbacks.test(MC_ENTITY_TAKE_DMG))
|
||||
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (LuaEngine::EntityTakeDamage 00864560)");
|
||||
(void)damageCountdown;
|
||||
if (try_end_astral_projection()) return false;
|
||||
if (playerType == PLAYER_JACOB_B && source.type == ENTITY_DARK_ESAU)
|
||||
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Tainted Jacob's ghost form)");
|
||||
|
||||
// The online stats tally (Player_stats_add 00425ac0) is not written yet: only the online stats screen shows it.
|
||||
lastDamageSource = source;
|
||||
lastDamageFlags = damageFlags;
|
||||
isHurtThisRoom = true;
|
||||
maggyHealthDrainCooldown = 0;
|
||||
damageCooldown = HIT_COOLDOWN;
|
||||
float volume = local_volume_get();
|
||||
if (isPenalized)
|
||||
{
|
||||
roomDamageTaken += amount;
|
||||
if (playerType == PLAYER_MAGDALENE_B)
|
||||
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Tainted Magdalene's damage taken)");
|
||||
totalDamageTaken += amount;
|
||||
}
|
||||
if (source.type >= ENEMY_TYPE_FIRST && source.type <= ENEMY_TYPE_LAST)
|
||||
bestiary_count_add(g_manager->persistentGameData.bestiary.hits, source.type, source.variant);
|
||||
if (game.debugFlags & DEBUG_DAMAGE_VALUES)
|
||||
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (spawn_debug_damage_text)");
|
||||
if ((damageFlags & (DAMAGE_FIRE | DAMAGE_POOP)) && !(damageFlags & DAMAGE_EXPLOSION))
|
||||
voice_play(SOUND_FIREDEATH_HISS, 1, SOUND_FRAME_DELAY, 1);
|
||||
|
||||
bool isThief = is_listed(COIN_THIEF_TYPES, source.type) || source.spawnerType == ULTRA_GREED ||
|
||||
source.spawnerType == ULTRA_GREED_DOOR ||
|
||||
(source.type == ENTITY_PROJECTILE && is_listed(COIN_SHOOTER_TYPES, source.spawnerType));
|
||||
if ((isThief || game.challenge == CHALLENGE_PAY_TO_PLAY) && numCoins > 0)
|
||||
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (dropping coins to Greed)");
|
||||
if (variant == PLAYER_VARIANT_COOP_BABY && (babySkin == BABY_FART || babySkin == BABY_BOMB || babySkin == BABY_BOOK))
|
||||
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (the co-op babies that answer hits)");
|
||||
if (HasCollectible(COLLECTIBLE_MARBLES) && (trinkets[0] != 0 || queuedItem.item))
|
||||
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Marbles)");
|
||||
|
||||
float pitch = get_voice_pitch();
|
||||
int grunt = SOUND_ISAAC_HURT_GRUNT;
|
||||
if (temporaryEffects.HasCollectibleEffect(COLLECTIBLE_THE_NAIL)) grunt = random_below(2) ? SOUND_NAIL_HURT_1 : SOUND_NAIL_HURT_2;
|
||||
voice_play(grunt, volume, SOUND_FRAME_DELAY, pitch);
|
||||
if (source.type == ENTITY_MOM || source.type == ENTITY_MOMS_HEART)
|
||||
voice_play(source.type == ENTITY_MOM ? SOUND_MOM_VOX : SOUND_HEARTBEAT, 1,
|
||||
random_below(SOUND_BOSS_DELAY_RANDOM) + SOUND_BOSS_DELAY_MIN, 1);
|
||||
|
||||
hit_items_check(*this, damageFlags, isPenalized);
|
||||
for (size_t i = 0; i < game.room->entityList.updateEL.size(); i++)
|
||||
{
|
||||
Entity* entity = game.room->entityList.updateEL[i];
|
||||
if (entity->IsFamiliar() && static_cast<Entity_Familiar*>(entity)->player == this)
|
||||
reconstruction_missing("Entity_Familiar::trigger_player_damage 0062b750");
|
||||
else if (!entity->IsFamiliar() && entity->IsEnemy())
|
||||
static_cast<Entity_NPC*>(entity)->on_player_damaged();
|
||||
}
|
||||
if (isPenalized && !parent)
|
||||
{
|
||||
game.SetStateFlag(LEVEL_STATE_DAMAGED, true);
|
||||
game.lastLevelWithDamage = std::clamp((int)game.stage, 0, LAST_DAMAGE_STAGE_MAX);
|
||||
}
|
||||
|
||||
if (game.debugFlags & DEBUG_INFINITE_HP) amount = 0;
|
||||
else if (amount > 0 && game.deathmatchManager.is_active())
|
||||
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (versus hearts)");
|
||||
else if (amount > 0) hearts_remove(*this, amount, damageFlags, isPenalized);
|
||||
|
||||
bool isAstral = HasCollectible(COLLECTIBLE_ASTRAL_PROJECTION) && !game.room->IsClear() &&
|
||||
!temporaryEffects.HasCollectibleEffect(COLLECTIBLE_ASTRAL_PROJECTION) && !astralProjectionBody;
|
||||
bool isInstantDeath = HasInstantDeathCurse() && amount > 0;
|
||||
bool isDeathSkipped = isAstral || temporaryEffects.HasCollectibleEffect(COLLECTIBLE_BERSERK);
|
||||
bool isHurt = true;
|
||||
|
||||
if ((redHearts < 1 && soulHearts < 1 && boneHearts < 1) || isInstantDeath)
|
||||
{
|
||||
if (HasCollectible(COLLECTIBLE_HEARTBREAK)) reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Heartbreak)");
|
||||
if (damageFlags & DAMAGE_NOKILL) TryPreventDeath();
|
||||
else
|
||||
{
|
||||
if (isInstantDeath)
|
||||
{
|
||||
redHearts = 0;
|
||||
soulHearts = 0;
|
||||
blackHearts = 0;
|
||||
boneHearts = 0;
|
||||
eternalHearts = 0;
|
||||
rottenHearts = 0;
|
||||
}
|
||||
if (!isDeathSkipped)
|
||||
{
|
||||
if (isInstantDeath) Kill(EntityRef());
|
||||
bool isKilled = try_trigger_astral_projection();
|
||||
lastDamageSource = source;
|
||||
if (isKilled && game.deathmatchManager.is_active())
|
||||
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (a versus kill, trigger_npc_death)");
|
||||
if (isDead) death_count(source, damageFlags);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isDead && HasCollectible(COLLECTIBLE_CURSED_EYE) && !HasCollectible(COLLECTIBLE_BLACK_CANDLE) && weapons[1])
|
||||
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Cursed Eye's teleport)");
|
||||
|
||||
bool isHitAnimated = pitfallState == 0 && isHurt;
|
||||
if (HasTrinket(TRINKET_CURSED_SKULL) && !isDead)
|
||||
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Cursed Skull)");
|
||||
if (redHearts <= scale_for_hard_difficulty(1))
|
||||
{
|
||||
if (HasCollectible(COLLECTIBLE_POLAROID) || HasCollectible(COLLECTIBLE_NEGATIVE))
|
||||
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (the Polaroid and the Negative)");
|
||||
bool isLastHeart = soulHearts < 1 || (redHearts < 1 && soulHearts == scale_for_hard_difficulty(1));
|
||||
if (isLastHeart && (HasCollectible(COLLECTIBLE_SCAPULAR) || (HasTrinket(TRINKET_MONKEY_PAW) && variant == PLAYER_VARIANT_PLAYER)))
|
||||
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Scapular and Monkey Paw)");
|
||||
}
|
||||
|
||||
damageCooldown = damage_cooldown_scale(std::min(hurtFrames, HURT_HEARTS_MAX) * HURT_FRAMES_PER_HEART);
|
||||
flags &= ~FLAG_NO_DAMAGE_BLINK;
|
||||
if (isAstral) reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Astral Projection)");
|
||||
if (HasTrinket(TRINKET_BLIND_RAGE) || HasTrinket(TRINKET_FINGER_BONE))
|
||||
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Blind Rage and Finger Bone)");
|
||||
if (isPenalized && HasCollectible(COLLECTIBLE_GLASS_CANNON)) reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Glass Cannon)");
|
||||
|
||||
if (isHitAnimated)
|
||||
{
|
||||
if (twin && twin->playerType == PLAYER_THESOUL_B) twin->PlayExtraAnimation("Hit");
|
||||
else if (game.challenge != CHALLENGE_GUARDIAN) PlayExtraAnimation("Hit");
|
||||
if (itemState != ITEM_STATE_HOLD_STILL) ResetItemState();
|
||||
}
|
||||
isHurtPending = true;
|
||||
// Rumble is not wired to the controllers here.
|
||||
|
||||
ClampGoldenHearts(false);
|
||||
update_bone_hearts();
|
||||
if (damageCooldown > 0 && !isDead && twin && twin->damageCooldown < damageCooldown && !twin->isDead)
|
||||
twin->damageCooldown = damageCooldown;
|
||||
if (HasTrinket(TRINKET_SWALLOWED_M80) && !(damageFlags & DAMAGE_NO_PENALTIES))
|
||||
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Swallowed M80)");
|
||||
bool isGlitching = isPlayingExtraAnimation && sprite.IsPlaying("Glitch");
|
||||
if (!isDead && playerType == PLAYER_EDEN_B && isPenalized && !isGlitching)
|
||||
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Tainted Eden's reroll)");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Counts the player's death in the bestiary of the enemy behind the hit. Dying to one's own Ipecac unlocks an
|
||||
// achievement that is not written yet.
|
||||
void Entity_Player::death_count(const EntityRef& source, uint64_t damageFlags)
|
||||
{
|
||||
PersistentGameData_Bestiary& bestiary = g_manager->persistentGameData.bestiary;
|
||||
|
||||
if (source.type >= ENEMY_TYPE_FIRST && source.type <= ENEMY_TYPE_LAST)
|
||||
bestiary_count_add(bestiary.deaths, source.type, source.variant);
|
||||
else if (source.spawnerType >= ENEMY_TYPE_FIRST && source.spawnerType <= ENEMY_TYPE_LAST)
|
||||
bestiary_count_add(bestiary.deaths, source.spawnerType, (int)source.spawnerVariant);
|
||||
if ((damageFlags & DAMAGE_EXPLOSION) && source.type == ENTITY_TEAR && source.entity)
|
||||
reconstruction_missing("Entity_Player::TakeDamage 007729d0 (the achievement for dying to Ipecac)");
|
||||
}
|
||||
|
||||
// 007db6b0 Whether a hit kills at once: the Lost's curse, or Tainted Jacob's ghost.
|
||||
bool Entity_Player::HasInstantDeathCurse()
|
||||
{
|
||||
return (!temporaryEffects.isDisabled &&
|
||||
std::ranges::any_of(temporaryEffects.effects, [](const TemporaryEffect& effect)
|
||||
{ return effect.item->type == ITEM_NULL && effect.item->id == NULLITEM_LOST_CURSE; })) ||
|
||||
playerType == PLAYER_JACOB2_B;
|
||||
}
|
||||
|
||||
// 007bf670 The lives the HUD counts: Dead Cat's and the items that revive, Lazarus's own and Tainted Lost's Birthright.
|
||||
int Entity_Player::GetExtraLives()
|
||||
{
|
||||
int lives = deadCatLives;
|
||||
|
||||
for (int item : EXTRA_LIFE_ITEMS) lives += collectibleCounts[item];
|
||||
if (playerType == PLAYER_THELOST_B) lives += collectibleCounts[TAINTED_LOST_BIRTHRIGHT];
|
||||
return lives + (playerType == PLAYER_LAZARUS);
|
||||
}
|
||||
|
||||
// 0075d900 Whether an item's costume shows on a layer of the player's sprite, or on any layer for a negative one.
|
||||
bool Entity_Player::IsItemCostumeVisible(ItemConfig_Item* item, int playerSpriteLayerID)
|
||||
{
|
||||
int first = std::max(playerSpriteLayerID, 0);
|
||||
int end = playerSpriteLayerID < 0 ? COSTUME_LAYER_COUNT : playerSpriteLayerID + 1;
|
||||
|
||||
for (int layer = first; layer < end; layer++)
|
||||
if (playerCostumeMap[layer].index >= 0 && costumeSpriteDescs[playerCostumeMap[layer].index].item == item)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// 0075d980 Whether a null item's costume shows on a layer, as IsItemCostumeVisible for an id out of range asks of none.
|
||||
bool Entity_Player::IsNullItemCostumeVisible(int nullItemID, int playerSpriteLayerID)
|
||||
{
|
||||
std::vector<std::unique_ptr<ItemConfig_Item>>& nullItems = g_manager->itemConfig.nullItems;
|
||||
bool isKnown = nullItemID >= 0 && nullItemID < (int)nullItems.size();
|
||||
return IsItemCostumeVisible(isKnown ? nullItems[nullItemID].get() : nullptr, playerSpriteLayerID);
|
||||
}
|
||||
|
||||
// 007c3100 Whether a hit passes the player by: the invincibility items' effects, Gnawed Leaf's statue, Breath of Life,
|
||||
// Taurus's charge, the shields red heart hits still pass, the halo baby and a co-op ghost. Book of Shadows lets a blood
|
||||
// donation hurt.
|
||||
bool Entity_Player::HasInvincibility(uint64_t damageFlags, const EntityRef& source)
|
||||
{
|
||||
if (damageFlags & DAMAGE_INVINCIBLE_IGNORED) return false;
|
||||
|
||||
TemporaryEffects& effects = temporaryEffects;
|
||||
bool isRedHit = damageFlags & DAMAGE_RED_HEARTS;
|
||||
bool isInvincible = effects.HasCollectibleEffect(COLLECTIBLE_BOOK_OF_SHADOWS);
|
||||
if (isInvincible)
|
||||
{
|
||||
bool isBloodSlot = source.type == ENTITY_SLOT && (source.variant == BLOOD_DONATION_VARIANT || source.variant == BLOOD_BANK_VARIANT);
|
||||
if (isBloodSlot && effects.GetCollectibleEffect(COLLECTIBLE_BOOK_OF_SHADOWS)->unknown != 0) isInvincible = false;
|
||||
}
|
||||
if (!isInvincible)
|
||||
{
|
||||
TemporaryEffect* taurus = effects.HasCollectibleEffect(COLLECTIBLE_TAURUS) ? effects.GetCollectibleEffect(COLLECTIBLE_TAURUS) : nullptr;
|
||||
isInvincible = std::ranges::any_of(INVINCIBLE_EFFECTS, [&](int item) { return effects.HasCollectibleEffect(item); }) ||
|
||||
(HasCollectible(COLLECTIBLE_GNAWED_LEAF) && mass == GNAWED_LEAF_MASS && !isRedHit) ||
|
||||
effects.HasCollectibleEffect(COLLECTIBLE_BREATH_OF_LIFE) || (taurus && taurus->cooldown != 0) ||
|
||||
(effects.HasNullEffect(NULLITEM_INVINCIBLE_SHIELD) && !isRedHit) ||
|
||||
(effects.HasNullEffect(NULLITEM_REVERSE_CHARIOT) && !isRedHit) ||
|
||||
((effects.HasCollectibleEffect(COLLECTIBLE_DARK_ARTS) || isDarkArtsBlastPending) && !isRedHit) ||
|
||||
(suplexState != 0 && !isRedHit) || effects.HasCollectibleEffect(COLLECTIBLE_MEGA_MUSH);
|
||||
}
|
||||
return isInvincible || (variant == PLAYER_VARIANT_COOP_BABY && babySkin == BABY_HALO) || isCoopGhost;
|
||||
}
|
||||
|
||||
// 007c3320 Whether poison passes the player by: Jupiter, Bob's Curse and the Bob transformation.
|
||||
bool Entity_Player::HasPoisonImmunity()
|
||||
{
|
||||
return HasCollectible(COLLECTIBLE_JUPITER) || HasCollectible(COLLECTIBLE_BOBS_CURSE) || HasPlayerForm(PLAYER_FORM_BOB);
|
||||
}
|
||||
|
||||
// 007dba30 Whether Evil Charm keeps a hazard off the player: fireplaces always, creep and the like only for their
|
||||
// first frames on it.
|
||||
bool Entity_Player::is_evil_charm_immune(EntityRef source)
|
||||
{
|
||||
if (!HasCollectible(COLLECTIBLE_EVIL_CHARM) && !temporaryEffects.HasCollectibleEffect(COLLECTIBLE_EVIL_CHARM)) return false;
|
||||
if (source.type == ENTITY_FIREPLACE) return true;
|
||||
|
||||
bool isHazard = (source.type == 0 && source.variant == EVIL_CHARM_GRID_VARIANT) ||
|
||||
(source.type == ENTITY_PROJECTILE && source.variant == 2) ||
|
||||
(source.type == ENTITY_EFFECT && is_listed(EVIL_CHARM_EFFECTS, source.variant));
|
||||
if (!isInEvilCharmHazard && !isHazard)
|
||||
{
|
||||
isInEvilCharmHazard = false;
|
||||
return false;
|
||||
}
|
||||
isInEvilCharmHazard = true;
|
||||
return isHazard && evilCharmHazardFrames < EVIL_CHARM_GRACE_FRAMES;
|
||||
}
|
||||
|
||||
// 007c9ad0 The pitch of the player's voice: higher for babies, Pluto, Inner Child, Binky and Helium pills, lower
|
||||
// for Puberty pills and the Adult transformation.
|
||||
float Entity_Player::get_voice_pitch()
|
||||
{
|
||||
float pitch = variant == PLAYER_VARIANT_PLAYER ? VOICE_PITCH_PLAYER : VOICE_PITCH_BABY;
|
||||
|
||||
pitch += (float)(pillEffectUses[PILL_EFFECT_PUBERTY] - pillEffectUses[PILL_EFFECT_HELIUM]) * VOICE_PITCH_PER_PILL;
|
||||
if (HasCollectible(COLLECTIBLE_PLUTO) || temporaryEffects.HasCollectibleEffect(COLLECTIBLE_INNER_CHILD))
|
||||
pitch += VOICE_PITCH_PLUTO;
|
||||
if (HasCollectible(COLLECTIBLE_BINKY)) pitch += VOICE_PITCH_STEP;
|
||||
if (HasPlayerForm(PLAYER_FORM_ADULT)) pitch -= VOICE_PITCH_STEP;
|
||||
return std::clamp(pitch, VOICE_PITCH_MIN, VOICE_PITCH_MAX);
|
||||
}
|
||||
|
||||
// 007cf8c0 Whether the player plays on this machine: every one does offline.
|
||||
bool Entity_Player::IsLocalPlayer()
|
||||
{
|
||||
return !g_manager->netplayManager.is_online() || g_manager->netplayManager.IsIdxLocalPlayer(controllerIndex);
|
||||
}
|
||||
|
||||
// 007cf8f0 The volume of the player's sounds: full for a local player, the remote players' option for others.
|
||||
float Entity_Player::local_volume_get()
|
||||
{
|
||||
if (IsLocalPlayer()) return 1;
|
||||
return (float)g_manager->optionsConfig.onlinePlayerVolume * REMOTE_VOLUME_SCALE;
|
||||
}
|
||||
|
||||
// 007d1c10 Breath of Life's holy light when the player is hit as it runs out, not written yet. True when it shines.
|
||||
uint32_t Entity_Player::play_hurt_effects()
|
||||
{
|
||||
TemporaryEffect* effect = temporaryEffects.GetCollectibleEffect(COLLECTIBLE_BREATH_OF_LIFE);
|
||||
bool isBlocked = damageCooldown > 0 && !HasEntityFlags(FLAG_NO_DAMAGE_BLINK);
|
||||
if (isBlocked || !effect || effect->count != 2) return 0;
|
||||
if (effect->cooldown < g_manager->itemConfig.GetCollectible(COLLECTIBLE_BREATH_OF_LIFE)->maxCooldown - BREATH_OF_LIFE_WINDOW)
|
||||
return 0;
|
||||
reconstruction_missing("Entity_Player::play_hurt_effects 007d1c10 (Breath of Life)");
|
||||
}
|
||||
|
||||
// 007caaa0 Whether a heart container is a bone heart.
|
||||
bool Entity_Player::IsBoneHeart(int heart)
|
||||
{
|
||||
return boneHearts > 0 && (boneHeartsMask & 1 << heart);
|
||||
}
|
||||
|
||||
// 00759220 Whether a soul heart, counted in halves from 1, is the first half of a black heart.
|
||||
bool Entity_Player::IsBlackHeart(int heart)
|
||||
{
|
||||
return heart <= soulHearts && heart >= 1 && (heart & 1) && (blackHearts & 1 << ((heart - 1) / 2));
|
||||
}
|
||||
|
||||
// 007caad0 Leaves a player a last half heart of its kind when a hit was not to kill. True when it did.
|
||||
bool Entity_Player::TryPreventDeath()
|
||||
{
|
||||
if (boneHearts + redHearts + soulHearts != 0) return false;
|
||||
|
||||
switch (GetHealthType())
|
||||
{
|
||||
case HEALTH_DEFAULT:
|
||||
if (playerType == PLAYER_BETHANY)
|
||||
{
|
||||
if (maxHearts < 2) AddMaxHearts(2, false);
|
||||
AddHearts(1, true, false);
|
||||
return true;
|
||||
}
|
||||
if (maxHearts <= 0) break;
|
||||
AddHearts(scale_for_hard_difficulty(1), true, false);
|
||||
return true;
|
||||
case HEALTH_COIN:
|
||||
if (maxHearts < 2) AddMaxHearts(2, false);
|
||||
AddHearts(2, true, false);
|
||||
return true;
|
||||
case HEALTH_BONE:
|
||||
AddBoneHearts(1);
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
soulHearts = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
// 007afc20 Kills the player out of hearts and starts the death sequence, unless it is dead, a ghost, berserk or
|
||||
// projected. Spirit Shackles' second chance is not written yet. True when it killed.
|
||||
bool Entity_Player::try_trigger_astral_projection()
|
||||
{
|
||||
bool isOutOfHearts = redHearts < 1 && soulHearts < 1 && boneHearts < 1;
|
||||
if (g_game->deathmatchManager.is_active() && isOutOfHearts && blackHearts > 0) isOutOfHearts = false;
|
||||
if (isDead || !isOutOfHearts || isCoopGhost) return false;
|
||||
|
||||
TemporaryEffect* astral = temporaryEffects.isDisabled ? nullptr : temporaryEffects.GetCollectibleEffect(COLLECTIBLE_ASTRAL_PROJECTION);
|
||||
int astralState = astral ? astral->count : 0;
|
||||
if (astralState == 1 || temporaryEffects.HasCollectibleEffect(COLLECTIBLE_BERSERK)) return false;
|
||||
if (astralState != 2)
|
||||
{
|
||||
bool isShackled = HasCollectible(COLLECTIBLE_SPIRIT_SHACKLES) &&
|
||||
temporaryEffects.GetNullEffectNum(NULLITEM_SPIRIT_SHACKLES_DISABLED) == 0 &&
|
||||
temporaryEffects.GetNullEffectNum(NULLITEM_SHACKLES_GHOST) == 0;
|
||||
if (isShackled) reconstruction_missing("Entity_Player::try_trigger_astral_projection 007afc20 (Spirit Shackles)");
|
||||
// The online stats tally of deaths to spikes (Player_stats_add 00425ac0) is not written yet.
|
||||
lastDamageSource = EntityRef();
|
||||
}
|
||||
Kill(EntityRef());
|
||||
return true;
|
||||
}
|
||||
|
||||
// 007d35b0 Ends Astral Projection's spirit form when the spirit is hit, not written yet. True when it ended.
|
||||
bool Entity_Player::try_end_astral_projection()
|
||||
{
|
||||
TemporaryEffect* astral = temporaryEffects.isDisabled ? nullptr : temporaryEffects.GetCollectibleEffect(COLLECTIBLE_ASTRAL_PROJECTION);
|
||||
if (!astral || astral->count != 1) return false;
|
||||
reconstruction_missing("Entity_Player::try_end_astral_projection 007d35b0");
|
||||
}
|
||||
|
||||
// 007828f0 The animation the player dies with: the Lost's for ghosts and the cursed, Forgotten's, or falling in a hole.
|
||||
const char* Entity_Player::GetDeathAnimName()
|
||||
{
|
||||
bool isGhost = playerType == PLAYER_THELOST || playerType == PLAYER_THELOST_B || playerType == PLAYER_JACOB2_B ||
|
||||
playerType == PLAYER_THESOUL_B || playerType == PLAYER_THESOUL ||
|
||||
temporaryEffects.GetCollectibleEffectNum(COLLECTIBLE_ASTRAL_PROJECTION) == 1 ||
|
||||
temporaryEffects.GetNullEffectNum(NULLITEM_SHACKLES_GHOST) == 1 ||
|
||||
temporaryEffects.HasNullEffect(NULLITEM_LOST_CURSE) ||
|
||||
(variant == PLAYER_VARIANT_COOP_BABY && babySkin == BABY_GHOST) || isCoopGhost;
|
||||
if (isGhost) return "LostDeath";
|
||||
if (playerType == PLAYER_THEFORGOTTEN_B) return "ForgottenDeath";
|
||||
return pitfallState == 0 ? "Death" : "HoleDeath";
|
||||
}
|
||||
|
||||
// 007abe20 Plays an animation on the whole sprite, over the body and head, until it ends.
|
||||
void Entity_Player::PlayExtraAnimation(std::string_view animName)
|
||||
{
|
||||
isPlayingItemAnimation = false;
|
||||
bodySprite.Reset();
|
||||
sprite.playbackSpeed = 1;
|
||||
sprite.overlayAnimState.SetAnimationData(nullptr);
|
||||
if (sprite.SetAnimation(animName))
|
||||
{
|
||||
sprite.animState.Rewind();
|
||||
sprite.animState.isPlaying = true;
|
||||
}
|
||||
isPlayingItemAnimation = false;
|
||||
isPlayingExtraAnimation = true;
|
||||
}
|
||||
|
||||
// 007abe90 Plays an animation of the player's sprite on its body sprite, as picking items up does.
|
||||
void Entity_Player::PlayExtraAnimation(std::string_view animation, bool)
|
||||
{
|
||||
bodySprite = sprite;
|
||||
bodySprite.playbackSpeed = 1;
|
||||
if (bodySprite.SetAnimation(animation))
|
||||
{
|
||||
bodySprite.animState.Rewind();
|
||||
bodySprite.animState.isPlaying = true;
|
||||
}
|
||||
isPlayingExtraAnimation = false;
|
||||
isPlayingItemAnimation = true;
|
||||
}
|
||||
|
||||
// 007c36b0 Puts away what the player holds up for an item: its costumes for the hold, and the item over its head.
|
||||
void Entity_Player::ResetItemState()
|
||||
{
|
||||
if (itemState == COLLECTIBLE_SHOOP_DA_WHOOP)
|
||||
reconstruction_missing("Entity_Player::ResetItemState 007c36b0 (TryRemoveCollectibleCostume)");
|
||||
else if (itemState == COLLECTIBLE_BOOMERANG)
|
||||
RemoveCostume(g_manager->itemConfig.GetNullItem(NULLITEM_BOOMERANG));
|
||||
if (variant == PLAYER_VARIANT_PLAYER && !isCoopGhost)
|
||||
{
|
||||
std::erase_if(costumeSpriteDescs, [](const CostumeSpriteDesc& desc) { return desc.isItemStateOnly; });
|
||||
UpdateCostumes();
|
||||
}
|
||||
bool isHiding = bodySprite.animState.animData && bodySprite.animState.isPlaying && bodySprite.GetAnimation() == "HideItem";
|
||||
if ((isPlayingExtraAnimation || isPlayingItemAnimation) && !isHiding && itemState == COLLECTIBLE_MOMS_BRACELET)
|
||||
PlayExtraAnimation("HideItem");
|
||||
itemState = 0;
|
||||
}
|
||||
@@ -22,6 +22,9 @@ constexpr float WALK_FASTEST_SPEED = 10;
|
||||
constexpr float WALK_SLOW_SPEED = 2.3f;
|
||||
constexpr int DAMAGE_BLINK_PERIOD = 6;
|
||||
constexpr int DAMAGE_BLINK_HIDDEN = 3;
|
||||
constexpr int COLLECTIBLE_INTRUDER = 575;
|
||||
constexpr int BABY_FOUND_SOUL = 59;
|
||||
constexpr float DEATH_FRICTION = 0.6f;
|
||||
constexpr float EMOTE_HEIGHT = 52;
|
||||
constexpr float EMOTE_MOVING_SPEED = 0.1f;
|
||||
constexpr float GRAVITY_PULL = 0.225f;
|
||||
@@ -618,8 +621,16 @@ void Entity_Player::update_shooting()
|
||||
// item, pocket and drop actions stop the game until reached.
|
||||
void Entity_Player::Update()
|
||||
{
|
||||
if (!is_evaluation_plain() || isPlayingExtraAnimation || isPlayingItemAnimation || heldEntity || queuedItem.item)
|
||||
reconstruction_missing("Entity_Player::Update 00782af0 (items, effects and extra animations)");
|
||||
if (isPlayingExtraAnimation && sprite.IsFinished()) isPlayingExtraAnimation = false;
|
||||
if (isHurtPending && !isPlayingExtraAnimation)
|
||||
{
|
||||
isHurtPending = false;
|
||||
if (HasCollectible(COLLECTIBLE_INTRUDER) && !temporaryEffects.HasNullEffect(NULLITEM_INTRUDER))
|
||||
reconstruction_missing("Entity_Player::Update 00782af0 (the spiders a hurt sets loose)");
|
||||
}
|
||||
if (isDead) return death_update();
|
||||
if (!is_evaluation_plain() || isPlayingItemAnimation || heldEntity || queuedItem.item)
|
||||
reconstruction_missing("Entity_Player::Update 00782af0 (items, effects and item animations)");
|
||||
for (ButtonAction action : {ACTION_BOMB, ACTION_ITEM, ACTION_PILL_CARD, ACTION_DROP})
|
||||
if (isControlsEnabled && action_value(action, controllerIndex) > 0)
|
||||
reconstruction_missing("Entity_Player::Update 00782af0 (bombs, items, pockets and drop)");
|
||||
@@ -628,6 +639,30 @@ void Entity_Player::Update()
|
||||
update_body_animations();
|
||||
update_shooting();
|
||||
walk_animation_update();
|
||||
if (damageCooldown > 0) damageCooldown--;
|
||||
}
|
||||
|
||||
// The death sequence part of 00782af0: the player plays its death animation once, stops, and slows to a halt. Whether
|
||||
// it revives, and the save deletion of a run lost, are WillPlayerRevive's (not written yet).
|
||||
void Entity_Player::death_update()
|
||||
{
|
||||
std::string_view animation = GetDeathAnimName();
|
||||
|
||||
if (g_game->roomTransition.mode == TRANSITION_NONE && sprite.GetAnimation() != animation)
|
||||
{
|
||||
isVisible = true;
|
||||
PlayExtraAnimation(animation);
|
||||
if (GetTrinketMultiplier(TRINKET_MYSTERIOUS_PAPER) > 0)
|
||||
reconstruction_missing("Entity_Player::Update 00782af0 (Mysterious Paper's revival chance)");
|
||||
if (heldEntity) ThrowHeldEntity(Vector{});
|
||||
if (LayerState* ghost = sprite.GetLayer("ghost")) ghost->isVisible = true;
|
||||
if (!parent && variant == PLAYER_VARIANT_PLAYER && !isCoopGhost && !WillPlayerRevive())
|
||||
reconstruction_missing("Entity_Player::Update 00782af0 (the save deletion of a lost run)");
|
||||
if (variant == PLAYER_VARIANT_COOP_BABY && babySkin == BABY_FOUND_SOUL && parent && parent->is_player())
|
||||
parent->ToPlayer()->temporaryEffects.AddTrinketEffect(TRINKET_FOUND_SOUL, true, 1);
|
||||
velocity = Vector{};
|
||||
}
|
||||
friction *= DEATH_FRICTION;
|
||||
}
|
||||
|
||||
// 0078ca00 Draws the player at its place, lifted by its flight and its offset: blinking while hurt, the held entity
|
||||
@@ -694,7 +729,17 @@ void Entity_Player::render_pass(const Vector& offset, RenderPass pass)
|
||||
if (const NullFrame* held = bodySprite.animState.GetNullFrameById(0);
|
||||
held && held->isVisible && playerType == PLAYER_LILITH_B)
|
||||
reconstruction_missing("Entity_Player::render_pass 0078b640 (Tainted Lilith's held item)");
|
||||
if (IsFullSpriteRendering()) reconstruction_missing("Entity_Player::render_pass 0078b640 (the whole sprite)");
|
||||
if (IsFullSpriteRendering())
|
||||
{
|
||||
Vector heldOffset = posOffset;
|
||||
posOffset = {};
|
||||
sprite.overlayAnimState.SetAnimationData(nullptr);
|
||||
Entity::Render(offset);
|
||||
if (pass == RENDER_PASS_MAIN && IsHoldingItem())
|
||||
reconstruction_missing("Entity_Player::render_pass 0078b640 (the held item over the whole sprite)");
|
||||
posOffset = heldOffset;
|
||||
return;
|
||||
}
|
||||
|
||||
renderPosition = vector_add(render_position_get(pos, RENDER_SNAPPED), offset);
|
||||
bool isHeaded = !IsHeadless();
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
#include "entity_player.h"
|
||||
#include "log.h"
|
||||
|
||||
bool Entity_Player::TakeDamage(float, uint64_t, const EntityRef&, int)
|
||||
{
|
||||
reconstruction_missing("Entity_Player::TakeDamage 007729d0");
|
||||
}
|
||||
bool Entity_Player::TryThrow(const EntityRef&, const Vector&, float)
|
||||
{
|
||||
reconstruction_missing("Entity_Player::TryThrow 007d2930");
|
||||
@@ -107,7 +103,6 @@ void Entity_Player::trigger_max_hearts_removed(int)
|
||||
}
|
||||
void Entity_Player::AddEternalHearts(int) { reconstruction_missing("Entity_Player::AddEternalHearts 00758c20"); }
|
||||
void Entity_Player::RemoveBlackHeart(int) { reconstruction_missing("Entity_Player::RemoveBlackHeart 007591e0"); }
|
||||
bool Entity_Player::IsBlackHeart(int) { reconstruction_missing("Entity_Player::IsBlackHeart 00759220"); }
|
||||
void Entity_Player::AddJarHearts(int) { reconstruction_missing("Entity_Player::AddJarHearts 00759390"); }
|
||||
void Entity_Player::AddGoldenKey() { reconstruction_missing("Entity_Player::AddGoldenKey 00759620"); }
|
||||
void Entity_Player::RemoveGoldenKey() { reconstruction_missing("Entity_Player::RemoveGoldenKey 00759660"); }
|
||||
@@ -129,10 +124,6 @@ Entity* Entity_Player::AddSwarmFlyOrbital(Vector)
|
||||
bool Entity_Player::TryUseKey() { reconstruction_missing("Entity_Player::TryUseKey 00759e20"); }
|
||||
void Entity_Player::AddCostume(ItemConfig_Item*, bool) { reconstruction_missing("Entity_Player::AddCostume 0075d1d0"); }
|
||||
void Entity_Player::AddNullCostume(int) { reconstruction_missing("Entity_Player::AddNullCostume 0075d800"); }
|
||||
bool Entity_Player::IsNullItemCostumeVisible(int, int)
|
||||
{
|
||||
reconstruction_missing("Entity_Player::IsNullItemCostumeVisible 0075d980");
|
||||
}
|
||||
void Entity_Player::ClearQueueItem() { reconstruction_missing("Entity_Player::ClearQueueItem 0075e190"); }
|
||||
bool Entity_Player::FlushQueueItem() { reconstruction_missing("Entity_Player::FlushQueueItem 0075e1d0"); }
|
||||
void Entity_Player::IncrementPlayerFormCounter(int, int)
|
||||
@@ -169,7 +160,6 @@ TearFlags Entity_Player::check_bomb_tearflags(const TearFlags&)
|
||||
reconstruction_missing("Entity_Player::check_bomb_tearflags 00780ec0");
|
||||
}
|
||||
void Entity_Player::update_bomb_input() { reconstruction_missing("Entity_Player::update_bomb_input 00780f40"); }
|
||||
const char* Entity_Player::GetDeathAnimName() { reconstruction_missing("Entity_Player::GetDeathAnimName 007828f0"); }
|
||||
uint32_t Entity_Player::CanTurnHead() { reconstruction_missing("Entity_Player::CanTurnHead 00782a60"); }
|
||||
void Entity_Player::RemoveCollectibleByHistoryIndex(int, bool)
|
||||
{
|
||||
@@ -216,9 +206,7 @@ void Entity_Player::DropPocketItem(int, Vector) { reconstruction_missing("Entity
|
||||
void Entity_Player::ShootCandle(Vector) { reconstruction_missing("Entity_Player::ShootCandle 007a6300"); }
|
||||
int Entity_Player::GetTrinket(uint32_t) { reconstruction_missing("Entity_Player::GetTrinket 007a6430"); }
|
||||
void Entity_Player::room_exit(bool) { reconstruction_missing("Entity_Player::room_exit 007a6680"); }
|
||||
void Entity_Player::room_enter() { reconstruction_missing("Entity_Player::room_enter 007a6c50"); }
|
||||
void Entity_Player::TriggerRoomClear() { reconstruction_missing("Entity_Player::TriggerRoomClear 007a8fd0"); }
|
||||
bool Entity_Player::HasPlayerForm(int) { reconstruction_missing("Entity_Player::HasPlayerForm 007aa7c0"); }
|
||||
bool Entity_Player::CanAddCollectible(int) { reconstruction_missing("Entity_Player::CanAddCollectible 007aa800"); }
|
||||
void Entity_Player::AnimatePickup(ANM2*, bool, std::string_view)
|
||||
{
|
||||
@@ -249,10 +237,6 @@ void Entity_Player::AnimateTeleport(bool) { reconstruction_missing("Entity_Playe
|
||||
void Entity_Player::AnimateHappy() { reconstruction_missing("Entity_Player::AnimateHappy 007abd30"); }
|
||||
void Entity_Player::AnimateSad() { reconstruction_missing("Entity_Player::AnimateSad 007abd90"); }
|
||||
void Entity_Player::AddPrettyFly() { reconstruction_missing("Entity_Player::AddPrettyFly 007abdf0"); }
|
||||
void Entity_Player::PlayExtraAnimation(std::string_view)
|
||||
{
|
||||
reconstruction_missing("Entity_Player::PlayExtraAnimation 007abe20");
|
||||
}
|
||||
void Entity_Player::active_used_post(int, bool, int)
|
||||
{
|
||||
reconstruction_missing("Entity_Player::active_used_post 007abf80");
|
||||
@@ -290,10 +274,6 @@ void Entity_Player::RestoreGameState(GameStatePlayer*)
|
||||
{
|
||||
reconstruction_missing("Entity_Player::RestoreGameState 007ae4b0");
|
||||
}
|
||||
bool Entity_Player::try_trigger_astral_projection()
|
||||
{
|
||||
reconstruction_missing("Entity_Player::try_trigger_astral_projection 007afc20");
|
||||
}
|
||||
void Entity_Player::spawn_dark_esau(void*) { reconstruction_missing("Entity_Player::spawn_dark_esau 007b0070"); }
|
||||
void Entity_Player::DonateLuck(int) { reconstruction_missing("Entity_Player::DonateLuck 007b2200"); }
|
||||
void Entity_Player::UseCard(int, uint32_t) { reconstruction_missing("Entity_Player::UseCard 007b2230"); }
|
||||
@@ -332,21 +312,14 @@ Entity_Familiar* Entity_Player::ThrowBlueSpider(Vector, Vector)
|
||||
reconstruction_missing("Entity_Player::ThrowBlueSpider 007bf640");
|
||||
}
|
||||
void Entity_Player::RemoveBlueSpider() { reconstruction_missing("Entity_Player::RemoveBlueSpider 007bf660"); }
|
||||
int Entity_Player::GetExtraLives() { reconstruction_missing("Entity_Player::GetExtraLives 007bf670"); }
|
||||
uint32_t Entity_Player::GetGlitchBabySubType()
|
||||
{
|
||||
reconstruction_missing("Entity_Player::GetGlitchBabySubType 007c2e90");
|
||||
}
|
||||
bool Entity_Player::HasInvincibility(uint64_t, const EntityRef&)
|
||||
{
|
||||
reconstruction_missing("Entity_Player::HasInvincibility 007c3100");
|
||||
}
|
||||
bool Entity_Player::HasPoisonImmunity() { reconstruction_missing("Entity_Player::HasPoisonImmunity 007c3320"); }
|
||||
bool Entity_Player::CanPickRedHearts() { reconstruction_missing("Entity_Player::CanPickRedHearts 007c3410"); }
|
||||
bool Entity_Player::CanPickSoulHearts() { reconstruction_missing("Entity_Player::CanPickSoulHearts 007c3460"); }
|
||||
bool Entity_Player::CanPickBlackHearts() { reconstruction_missing("Entity_Player::CanPickBlackHearts 007c3550"); }
|
||||
void Entity_Player::RemoveSkinCostume() { reconstruction_missing("Entity_Player::RemoveSkinCostume 007c3620"); }
|
||||
void Entity_Player::ResetItemState() { reconstruction_missing("Entity_Player::ResetItemState 007c36b0"); }
|
||||
void Entity_Player::SetShootingCooldown(int) { reconstruction_missing("Entity_Player::SetShootingCooldown 007c37f0"); }
|
||||
bool Entity_Player::NeedsCharge(int) { reconstruction_missing("Entity_Player::NeedsCharge 007c3810"); }
|
||||
bool Entity_Player::FullCharge(int, bool, bool) { reconstruction_missing("Entity_Player::FullCharge 007c38c0"); }
|
||||
@@ -382,7 +355,6 @@ void Entity_Player::apply_victory_lap_penalty(uint32_t)
|
||||
{
|
||||
reconstruction_missing("Entity_Player::apply_victory_lap_penalty 007c97f0");
|
||||
}
|
||||
float Entity_Player::get_voice_pitch() { reconstruction_missing("Entity_Player::get_voice_pitch 007c9ad0"); }
|
||||
void Entity_Player::AddJarFlies(int) { reconstruction_missing("Entity_Player::AddJarFlies 007c9bb0"); }
|
||||
bool Entity_Player::IsPosInSpotLight(Vector) { reconstruction_missing("Entity_Player::IsPosInSpotLight 007c9c00"); }
|
||||
void Entity_Player::AddGoldenHearts(int, bool) { reconstruction_missing("Entity_Player::AddGoldenHearts 007c9d10"); }
|
||||
@@ -390,8 +362,6 @@ bool Entity_Player::CanPickGoldenHearts() { reconstruction_missing("Entity_Playe
|
||||
void Entity_Player::BreakGoldenHearts(int) { reconstruction_missing("Entity_Player::BreakGoldenHearts 007ca2d0"); }
|
||||
void Entity_Player::AddBoneHearts(int) { reconstruction_missing("Entity_Player::AddBoneHearts 007ca840"); }
|
||||
bool Entity_Player::CanPickBoneHearts() { reconstruction_missing("Entity_Player::CanPickBoneHearts 007caa00"); }
|
||||
bool Entity_Player::IsBoneHeart(int) { reconstruction_missing("Entity_Player::IsBoneHeart 007caaa0"); }
|
||||
bool Entity_Player::TryPreventDeath() { reconstruction_missing("Entity_Player::TryPreventDeath 007caad0"); }
|
||||
void Entity_Player::apply_coop_baby_spawn_bonus()
|
||||
{
|
||||
reconstruction_missing("Entity_Player::apply_coop_baby_spawn_bonus 007cb090");
|
||||
@@ -425,17 +395,14 @@ void Entity_Player::player_type_change_prepare(int)
|
||||
{
|
||||
reconstruction_missing("Entity_Player::player_type_change_prepare 007cf610");
|
||||
}
|
||||
bool Entity_Player::IsLocalPlayer() { reconstruction_missing("Entity_Player::IsLocalPlayer 007cf8c0"); }
|
||||
void Entity_Player::GetGlyphOfBalanceDrop(int*, int*)
|
||||
{
|
||||
reconstruction_missing("Entity_Player::GetGlyphOfBalanceDrop 007d12c0");
|
||||
}
|
||||
Vector Entity_Player::GetEnterPosition() { reconstruction_missing("Entity_Player::GetEnterPosition 007d1620"); }
|
||||
Entity_Familiar* Entity_Player::AddMinisaac(Vector, bool)
|
||||
{
|
||||
reconstruction_missing("Entity_Player::AddMinisaac 007d1860");
|
||||
}
|
||||
uint32_t Entity_Player::play_hurt_effects() { reconstruction_missing("Entity_Player::play_hurt_effects 007d1c10"); }
|
||||
Entity_Player* Entity_Player::InitTwin(int) { reconstruction_missing("Entity_Player::InitTwin 007d2000"); }
|
||||
bool Entity_Player::TryHoldEntity(Entity*) { reconstruction_missing("Entity_Player::TryHoldEntity 007d2170"); }
|
||||
Entity* Entity_Player::ThrowHeldEntity(Vector) { reconstruction_missing("Entity_Player::ThrowHeldEntity 007d2470"); }
|
||||
@@ -463,10 +430,6 @@ void Entity_Player::trigger_vampire_charm_kill()
|
||||
}
|
||||
void Entity_Player::AddUrnSouls(uint32_t) { reconstruction_missing("Entity_Player::AddUrnSouls 007d3480"); }
|
||||
void Entity_Player::AddGigaBombs(int) { reconstruction_missing("Entity_Player::AddGigaBombs 007d34f0"); }
|
||||
bool Entity_Player::try_end_astral_projection()
|
||||
{
|
||||
reconstruction_missing("Entity_Player::try_end_astral_projection 007d35b0");
|
||||
}
|
||||
void Entity_Player::fire_saturnus_tears() { reconstruction_missing("Entity_Player::fire_saturnus_tears 007d3e40"); }
|
||||
int Entity_Player::GetMaxInventorySize() { reconstruction_missing("Entity_Player::GetMaxInventorySize 007d4150"); }
|
||||
bool Entity_Player::CanAddCollectibleToInventory(int)
|
||||
@@ -523,15 +486,10 @@ void Entity_Player::remove_wooden_cross_mantles()
|
||||
{
|
||||
reconstruction_missing("Entity_Player::remove_wooden_cross_mantles 007db160");
|
||||
}
|
||||
bool Entity_Player::HasInstantDeathCurse() { reconstruction_missing("Entity_Player::HasInstantDeathCurse 007db6b0"); }
|
||||
void Entity_Player::TriggerEchoChamber(uint32_t, int)
|
||||
{
|
||||
reconstruction_missing("Entity_Player::TriggerEchoChamber 007db740");
|
||||
}
|
||||
bool Entity_Player::is_evil_charm_immune(EntityRef)
|
||||
{
|
||||
reconstruction_missing("Entity_Player::is_evil_charm_immune 007dba30");
|
||||
}
|
||||
void Entity_Player::add_random_drug_item_effect()
|
||||
{
|
||||
reconstruction_missing("Entity_Player::add_random_drug_item_effect 007dbba0");
|
||||
@@ -559,18 +517,10 @@ void Entity_Player::CheckPoopSpellQueue(Vector)
|
||||
{
|
||||
reconstruction_missing("Entity_Player::CheckPoopSpellQueue 0095ffb0");
|
||||
}
|
||||
void Entity_Player::StoreGameState(GameStatePlayer*, bool)
|
||||
{
|
||||
reconstruction_missing("Entity_Player::StoreGameState 007b0be0");
|
||||
}
|
||||
void Entity_Player::PlayCollectibleAnim(int, bool, std::string_view, int)
|
||||
{
|
||||
reconstruction_missing("Entity_Player::PlayCollectibleAnim 00759f50");
|
||||
}
|
||||
void Entity_Player::PlayExtraAnimation(std::string_view, bool)
|
||||
{
|
||||
reconstruction_missing("Entity_Player::PlayExtraAnimation 007abe90");
|
||||
}
|
||||
void History::AddHistoryItem(const HistoryItem&) { reconstruction_missing("History::AddHistoryItem 00721a70"); }
|
||||
bool History::RemoveHistoryItemByIndex(int) { reconstruction_missing("History::RemoveHistoryItemByIndex 00721c00"); }
|
||||
void History::merge(History&) { reconstruction_missing("History::merge 00721c80"); }
|
||||
|
||||
@@ -0,0 +1,340 @@
|
||||
#include "entity_player.h"
|
||||
#include "game.h"
|
||||
#include "grid_entity_door.h"
|
||||
#include "log.h"
|
||||
#include "manager.h"
|
||||
#include "room.h"
|
||||
#include <algorithm>
|
||||
|
||||
constexpr int TRINKET_TICK = 53;
|
||||
constexpr int TRINKET_DOOR_STOP = 124;
|
||||
constexpr int TRINKET_MODELING_CLAY = 166;
|
||||
constexpr int TRINKET_LIL_CLOT = 176;
|
||||
constexpr int TRINKET_BETHS_ESSENCE = 182;
|
||||
constexpr int TRINKET_THE_TWINS = 183;
|
||||
constexpr int COLLECTIBLE_BROKEN_WATCH = 337;
|
||||
constexpr int COLLECTIBLE_TOXIC_SHOCK = 350;
|
||||
constexpr int COLLECTIBLE_DOG_TOOTH = 445;
|
||||
constexpr int COLLECTIBLE_BELIAL_PARTNER = 474;
|
||||
constexpr int COLLECTIBLE_BELIAL_EFFECT = 214;
|
||||
constexpr int COLLECTIBLE_POKE_GO = 505;
|
||||
constexpr int COLLECTIBLE_MERCURIUS = 590;
|
||||
constexpr int COLLECTIBLE_SATURNUS = 595;
|
||||
constexpr int COLLECTIBLE_DOGMA = 633;
|
||||
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;
|
||||
constexpr int BABY_SKIN_WITH_FOLLOWER = 58;
|
||||
constexpr int STAGE_ID_HOME = 35;
|
||||
constexpr int STAGE_MOMS_FLOOR = 6;
|
||||
constexpr int ENTITY_ROTGUT = 911;
|
||||
constexpr int BETHS_ESSENCE_WISPS = 5;
|
||||
constexpr int BETHS_ESSENCE_CHANCE_DOUBLE = 50;
|
||||
constexpr int BETHS_ESSENCE_CHANCE_TRIPLE = 100;
|
||||
constexpr int PERCENT = 100;
|
||||
constexpr int SOUND_BETHS_ESSENCE = 471;
|
||||
constexpr int SOUND_DOG_TOOTH_SECRET = 442;
|
||||
constexpr int SOUND_DOG_TOOTH_ROCK = 441;
|
||||
constexpr int DOG_TOOTH_SECRET_DELAY = 30;
|
||||
constexpr int DOG_TOOTH_ROCK_DELAY = 60;
|
||||
constexpr int DELAYED_SOUND_FRAMES = 2;
|
||||
constexpr int POKE_GO_CHANCE = 5;
|
||||
constexpr int GREED_WAVE_MAX = 12;
|
||||
constexpr int DOOR_STOP_UNLOCK_COPIES = 3;
|
||||
constexpr int DOOR_STOP_BOSS_RUSH_COPIES = 2;
|
||||
constexpr float DOOR_STOP_REACH_SQUARED = 10000;
|
||||
constexpr uint32_t LEVEL_STATE_DUNGEON_ROCK_BROKEN = 1u << 13;
|
||||
constexpr float DOOR_ENTER_OFFSET = 40;
|
||||
constexpr uint32_t DOOR_SIDES = 4;
|
||||
constexpr int ROCK_STATE_BROKEN = 2;
|
||||
constexpr ColorMod TOXIC_SHOCK_COLOR = {{1, 1, 1, 1}, {0, 1, 0, 1}, {0, 0, 0}};
|
||||
|
||||
// The grid entities Dog Tooth howls at when the floor's crawlspace rock hides there.
|
||||
constexpr GridEntityType DOG_TOOTH_ROCKS[] = {GRID_ROCK, GRID_ROCKT, GRID_ROCK_BOMB,
|
||||
GRID_ROCK_ALT, GRID_ROCK_SS, GRID_ROCK_SPIKED,
|
||||
GRID_ROCK_ALT2, GRID_ROCK_GOLD};
|
||||
|
||||
// 007d1620 Where the player comes into the room: Level's spot for rooms entered without a door, else a cell inside the
|
||||
// door the players come in by (one of the layout's doors from a random slot when none is set).
|
||||
Vector Entity_Player::GetEnterPosition()
|
||||
{
|
||||
Game& game = *g_game;
|
||||
Room& room = *game.room;
|
||||
uint32_t enterDoor = (uint32_t)game.enterDoor;
|
||||
|
||||
if (game.enterDoor == DOOR_NONE)
|
||||
{
|
||||
enterDoor = Random() & (DOOR_SLOT_COUNT - 1);
|
||||
for (int i = 0; i < DOOR_SLOT_COUNT && !(enterDoor < DOOR_SLOT_COUNT && room.descriptor->data->doors >> enterDoor & 1); i++)
|
||||
enterDoor = (enterDoor + 1) % DOOR_SLOT_COUNT;
|
||||
}
|
||||
|
||||
Vector enter = game.GetEnterPosition();
|
||||
if (enter.x != 0 || enter.y != 0) return enter;
|
||||
|
||||
Vector door = enterDoor < DOOR_SLOT_COUNT ? room.GetGridPosition(room.doorGridPositions[enterDoor]) : Vector{};
|
||||
switch (enterDoor % DOOR_SIDES)
|
||||
{
|
||||
case DIRECTION_LEFT:
|
||||
return vector_make(door.x + DOOR_ENTER_OFFSET, door.y);
|
||||
case DIRECTION_UP:
|
||||
return vector_make(door.x, door.y + DOOR_ENTER_OFFSET);
|
||||
case DIRECTION_RIGHT:
|
||||
return vector_make(door.x - DOOR_ENTER_OFFSET, door.y);
|
||||
default:
|
||||
return vector_make(door.x, door.y - DOOR_ENTER_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
// Plays the player's pending delayed sound at once and queues another, as Entity_Player::PlayDelayedSFX (007cb5d0).
|
||||
static void delayed_sound_queue(Entity_Player& player, int sound, int delay)
|
||||
{
|
||||
if (player.delayedSfxId != 0 && player.delayedSfxDelay > 0)
|
||||
{
|
||||
int pending = player.delayedSfxId;
|
||||
seed_fart_sound_override(&pending);
|
||||
g_manager->sfxManager.Play(pending, {.volume = player.delayedSfxVolume, .frameDelay = player.delayedSfxFrameDelay});
|
||||
}
|
||||
player.delayedSfxId = sound;
|
||||
player.delayedSfxVolume = 1;
|
||||
player.delayedSfxDelay = delay;
|
||||
player.delayedSfxFrameDelay = DELAYED_SOUND_FRAMES;
|
||||
}
|
||||
|
||||
// Beth's Essence in an angel room's first visit: five wisps, of the Book of Virtues or (half the time with two copies,
|
||||
// always with three) a random active item.
|
||||
static void beths_essence_wisps_add(Entity_Player& player)
|
||||
{
|
||||
int multiplier = player.GetTrinketMultiplier(TRINKET_BETHS_ESSENCE);
|
||||
int chance = multiplier == 2 ? BETHS_ESSENCE_CHANCE_DOUBLE : multiplier == 3 ? BETHS_ESSENCE_CHANCE_TRIPLE : 0;
|
||||
|
||||
for (int i = 0; i < BETHS_ESSENCE_WISPS; i++)
|
||||
{
|
||||
if (chance == 0 || (int)player.trinketRNGs[TRINKET_BETHS_ESSENCE].RandomInt(PERCENT) >= chance)
|
||||
player.AddWisp(COLLECTIBLE_BOOK_OF_VIRTUES, player.pos, true, false);
|
||||
else
|
||||
reconstruction_missing("Entity_Player::room_enter 007a6c50: Beth's Essence's random active item wisps "
|
||||
"(the actives with a wisp, ItemConfig_Item +0x190)");
|
||||
}
|
||||
sound_play(SOUND_BETHS_ESSENCE);
|
||||
}
|
||||
|
||||
// Door Stop: the door the player came in by (or, entering without one, the first within reach, if any) opens, and with
|
||||
// three copies its ambush lock opens too. With two or more copies, coming back from the boss rush keeps its door.
|
||||
static void door_stop_apply(Entity_Player& player)
|
||||
{
|
||||
Game& game = *g_game;
|
||||
Room& room = *game.room;
|
||||
int slot = game.enterDoor;
|
||||
|
||||
if (slot == DOOR_NONE)
|
||||
for (slot = 0; slot < DOOR_SLOT_COUNT; slot++)
|
||||
{
|
||||
GridEntity_Door* door = room.doors[slot];
|
||||
if (!door) continue;
|
||||
|
||||
Vector position = room.GetGridPosition(door->gridIndex);
|
||||
float dx = player.pos.x - position.x;
|
||||
float dy = player.pos.y - position.y;
|
||||
if (dy * dy + dx * dx < DOOR_STOP_REACH_SQUARED) break;
|
||||
}
|
||||
if (slot < 0 || (game.enterDoor == DOOR_NONE && slot == DOOR_SLOT_COUNT)) return;
|
||||
|
||||
int multiplier = player.GetTrinketMultiplier(TRINKET_DOOR_STOP);
|
||||
GridEntity_Door* door = slot < DOOR_SLOT_COUNT ? room.doors[slot] : nullptr;
|
||||
if (door) door->Open();
|
||||
if (door && multiplier >= DOOR_STOP_UNLOCK_COPIES)
|
||||
{
|
||||
if (door->doorFlags & DOOR_FLAG_AMBUSH) door->TryUnlock(player, true);
|
||||
}
|
||||
else if (multiplier < DOOR_STOP_BOSS_RUSH_COPIES) return;
|
||||
if (game.lastRoomIdx == ROOM_BOSSRUSH_IDX) room.TrySpawnBossRushDoor(true, true);
|
||||
}
|
||||
|
||||
// Dog Tooth howls once at an unvisited secret room behind a closed door, and growls at the floor's crawlspace rock.
|
||||
static void dog_tooth_apply(Entity_Player& player)
|
||||
{
|
||||
Game& game = *g_game;
|
||||
Room& room = *game.room;
|
||||
|
||||
for (GridEntity_Door* door : room.doors)
|
||||
{
|
||||
bool isSecret = door && (door->targetRoomType == ROOM_SECRET || door->targetRoomType == ROOM_SUPERSECRET);
|
||||
if (!isSecret || door->state == DOOR_STATE_OPEN || game.GetRoomByIdx(door->targetRoomIdx)->visitedCount != 0)
|
||||
continue;
|
||||
delayed_sound_queue(player, SOUND_DOG_TOOTH_SECRET, DOG_TOOTH_SECRET_DELAY);
|
||||
break;
|
||||
}
|
||||
|
||||
int rockIdx = room.dungeonRockIdx;
|
||||
GridEntity* rock = rockIdx >= 0 && rockIdx < ROOM_GRID_CELLS ? room.gridEntities[rockIdx] : nullptr;
|
||||
bool isRock = rock && std::ranges::find(DOG_TOOTH_ROCKS, rock->type) != std::end(DOG_TOOTH_ROCKS);
|
||||
if (!(game.levelStateFlags & LEVEL_STATE_DUNGEON_ROCK_BROKEN) && isRock && rock->state != ROCK_STATE_BROKEN)
|
||||
delayed_sound_queue(player, SOUND_DOG_TOOTH_ROCK, DOG_TOOTH_ROCK_DELAY);
|
||||
}
|
||||
|
||||
// What the player's items do on entering a room after it is placed: Toxic Shock's clouds, Poke Go's charmed enemy,
|
||||
// Dog Tooth's sounds, the locusts, a co-op baby's shield, the Broken Watch, the weapons' new room reset and the
|
||||
// poop under the player.
|
||||
static void room_items_apply(Entity_Player& player)
|
||||
{
|
||||
Game& game = *g_game;
|
||||
Room& room = *game.room;
|
||||
bool isFresh = room.isFirstVisit && !room.IsClear();
|
||||
|
||||
if (!game.isLevelGenerating) player.spawn_low_health_blood_splat();
|
||||
if (player.HasCollectible(COLLECTIBLE_TOXIC_SHOCK) && !room.IsClear()) room.fxLayers.AddPoopFx(TOXIC_SHOCK_COLOR);
|
||||
if (player.HasCollectible(COLLECTIBLE_POKE_GO) && isFresh &&
|
||||
player.collectibleRNGs[COLLECTIBLE_POKE_GO].RandomInt(POKE_GO_CHANCE) == 0)
|
||||
reconstruction_missing("Entity_Player::room_enter 007a6c50: Poke Go's charmed enemy (Entity::SetVisibleFlag, "
|
||||
"HUD::show_fortune_line with #POKE_GO_APPEAR_NOTIFY)");
|
||||
if (player.HasCollectible(COLLECTIBLE_DOG_TOOTH)) dog_tooth_apply(player);
|
||||
if (isFresh) player.spawn_locusts();
|
||||
|
||||
if (player.variant == PLAYER_VARIANT_COOP_BABY)
|
||||
{
|
||||
player.hasBabyRoomShield = true;
|
||||
if (player.babySkin == BABY_SKIN_WITH_FOLLOWER)
|
||||
reconstruction_missing("Entity_Player::room_enter 007a6c50: the co-op baby's follower effect 1000.114");
|
||||
}
|
||||
else if (player.variant == PLAYER_VARIANT_PLAYER && room.isFirstVisit && player.HasCollectible(COLLECTIBLE_BROKEN_WATCH))
|
||||
reconstruction_missing("Entity_Player::room_enter 007a6c50: the Broken Watch's rooms counter (Entity_Player +0x1820)");
|
||||
|
||||
Entity* parent = player.parent.get();
|
||||
if (player.variant == PLAYER_VARIANT_COOP_BABY && parent &&
|
||||
game.GetRoomByIdx(game.currentRoomIdx)->listIndex == game.lastBossRoomListIdx && game.stage == STAGE_MOMS_FLOOR)
|
||||
player.pos = parent->pos;
|
||||
for (int slot = 1; slot < WEAPON_SLOT_COUNT; slot++)
|
||||
if (player.weapons[slot]) player.weapons[slot]->TriggerNewRoom();
|
||||
if (player.weapons[0]) player.weapons[0]->TriggerNewRoom();
|
||||
|
||||
int column = (int)((player.pos.x - GRID_ORIGIN_X) / GRID_CELL_SIZE + 0.5f);
|
||||
int row = (int)((player.pos.y - GRID_ORIGIN_Y) / GRID_CELL_SIZE + 0.5f);
|
||||
bool isInside = column >= 0 && column < room.gridWidth && row >= 0 && row < room.gridHeight;
|
||||
int cell = room.gridWidth * row + column;
|
||||
GridEntity* poop = isInside && cell < ROOM_GRID_CELLS ? room.gridEntities[cell] : nullptr;
|
||||
if (poop && poop->type == GRID_POOP && !player.canFly)
|
||||
reconstruction_missing("Entity_Player::room_enter 007a6c50: Room::RemoveGridEntity 0081e930 on the poop entered on");
|
||||
else if (poop && poop->type == GRID_POOP && poop->variant == 1)
|
||||
reconstruction_missing("Entity_Player::room_enter 007a6c50: the red poop flown over drops to its last state");
|
||||
}
|
||||
|
||||
// 007a6c50 Sets the player up in the room just entered (after the floor's start): the cursed mist, Beth's Essence,
|
||||
// Dogma in the living room, the Twins and Judas's Belial, then the player stands at its entry with its motion, held
|
||||
// throw and pit fall reset, and its items react to the room. Friendly enemies follow it in, and Used Diaper, Lil Clot,
|
||||
// the Forgotten's body and the item sounds come last.
|
||||
// The original also clears the list at +0x1b34 and the words at +0x1c54..+0x1c60, which this player does not have.
|
||||
void Entity_Player::room_enter()
|
||||
{
|
||||
Game& game = *g_game;
|
||||
Room& room = *game.room;
|
||||
RoomConfig_Room* data = room.descriptor->data;
|
||||
if (!isPostLevelInitFinished) return;
|
||||
|
||||
if (room.descriptor->flags & ROOM_DESCRIPTOR_FLAG_CURSED_MIST) AddCurseMistEffect();
|
||||
if (room.roomType == ROOM_ANGEL && room.descriptor->visitedCount == 1 && HasTrinket(TRINKET_BETHS_ESSENCE))
|
||||
beths_essence_wisps_add(*this);
|
||||
bool isDogmaRoom = data && data->type == ROOM_DUNGEON && data->stageId == STAGE_ID_HOME;
|
||||
if (isDogmaRoom && collectibleCounts[COLLECTIBLE_DOGMA] < 1 && playerType != PLAYER_NO_DOGMA)
|
||||
AddCollectible(COLLECTIBLE_DOGMA, 0, true, 0, 0);
|
||||
if (playerType == PLAYER_THE_FORGOTTEN_B && game.challenge == CHALLENGE_FORGOTTEN_COSTUME)
|
||||
{
|
||||
ItemConfig_Item* costume = g_manager->itemConfig.GetNullItem(NULL_ITEM_FORGOTTEN_CHALLENGE);
|
||||
for (PlayerCostumeMap& layer : playerCostumeMap)
|
||||
{
|
||||
if (layer.index < 0 || layer.isBodyLayer || costumeSpriteDescs[layer.index].item != costume) continue;
|
||||
AnimationState& state = costumeSpriteDescs[layer.index].sprite.animState;
|
||||
if (state.animData) state.SetFrameFloat(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (HasTrinket(TRINKET_THE_TWINS))
|
||||
twins_duplicate_familiars(
|
||||
(int)trinketRNGs[TRINKET_THE_TWINS].RandomInt(GetTrinketMultiplier(TRINKET_THE_TWINS) + 1));
|
||||
if (HasCollectible(COLLECTIBLE_BOOK_OF_BELIAL_PASSIVE) && HasCollectible(COLLECTIBLE_BELIAL_PARTNER))
|
||||
{
|
||||
if (!temporaryEffects.HasCollectibleEffect(COLLECTIBLE_BELIAL_EFFECT))
|
||||
if (ItemConfig_Item* item = g_manager->itemConfig.GetCollectible(COLLECTIBLE_BELIAL_EFFECT))
|
||||
{
|
||||
TemporaryEffect effect(item);
|
||||
if (game.deathmatchManager.state >= DEATHMATCH_INTRO) effect.cooldown = VERSUS_EFFECT_COOLDOWN;
|
||||
temporaryEffects.AddEffect(effect, true, 1);
|
||||
}
|
||||
temporaryEffects.AddNullEffect(NULL_ITEM_BELIAL, true, BELIAL_NULL_COUNT);
|
||||
}
|
||||
|
||||
moveToTarget = vector_make(0, 0);
|
||||
Vector enter = GetEnterPosition();
|
||||
if (game.IsGreedMode() && (uint32_t)game.greedLastBeatenWave < (uint32_t)game.greedModeWave)
|
||||
game.greedModeWave = std::min(game.greedLastBeatenWave, GREED_WAVE_MAX);
|
||||
pos = enter;
|
||||
velocity = vector_make(0, 0);
|
||||
strengthMaxHearts = 0;
|
||||
heightVelocity = 0;
|
||||
posOffset.y = 0;
|
||||
if (flags & FLAG_THROWN)
|
||||
{
|
||||
flags &= ~FLAG_THROWN;
|
||||
isControlsEnabled = true;
|
||||
}
|
||||
|
||||
RoomConfig_Room* lastData = game.GetRoomByIdx(game.lastRoomIdx, game.lastRoomDimensionIdx)->data;
|
||||
bool isOutOfRotgut = lastData && lastData->type == ROOM_DUNGEON &&
|
||||
(room.descriptor->flags & ROOM_DESCRIPTOR_FLAG_ROTGUT_CLEARED);
|
||||
if (isOutOfRotgut)
|
||||
for (Entity* entity : room.entityList.updateEL)
|
||||
if (entity->type == ENTITY_ROTGUT && entity->variant == 0)
|
||||
{
|
||||
reconstruction_missing("Entity_Player::room_enter 007a6c50: thrown out of Rotgut (Entity_Player::TryThrow)");
|
||||
break;
|
||||
}
|
||||
if (HasCollectible(COLLECTIBLE_SATURNUS)) fire_saturnus_tears();
|
||||
if (pitfallState != 0 && !isDead)
|
||||
{
|
||||
pitfallTimer = 0;
|
||||
pitfallState = 0;
|
||||
isPlayingExtraAnimation = false;
|
||||
isPlayingItemAnimation = false;
|
||||
isControlsEnabled = true;
|
||||
entityCollisionClass = ENTCOLL_ALL;
|
||||
}
|
||||
if (!(flags & FLAG_HELD)) entityCollisionClass = ENTCOLL_ALL;
|
||||
if (HasTrinket(TRINKET_ERROR) || HasTrinket(TRINKET_MODELING_CLAY))
|
||||
{
|
||||
cacheFlags |= CACHE_ALL;
|
||||
EvaluateItems();
|
||||
game.hud.mark_all_slots_dirty(HISTORY_KEEP_ICONS, HISTORY_KEEP_ITEMS);
|
||||
}
|
||||
if (HasTrinket(TRINKET_TICK) && room.roomType == ROOM_BOSS && room.isFirstVisit)
|
||||
AddHearts(GetTrinketMultiplier(TRINKET_TICK) * 2, false, false);
|
||||
if (HasCollectible(COLLECTIBLE_MERCURIUS) && room.roomType == ROOM_DEFAULT)
|
||||
for (GridEntity_Door* door : room.doors)
|
||||
if (door && door->targetRoomType == ROOM_DEFAULT) door->Open();
|
||||
if (HasTrinket(TRINKET_DOOR_STOP)) door_stop_apply(*this);
|
||||
room_items_apply(*this);
|
||||
|
||||
for (Entity* entity : room.entityList.updateEL)
|
||||
{
|
||||
if (game.isRestoringGlowingHourglassState && entity->type == ENTITY_BLOOD_PUPPY)
|
||||
{
|
||||
entity->Remove();
|
||||
continue;
|
||||
}
|
||||
bool isFollower = (game.deathmatchManager.state >= DEATHMATCH_INTRO && entity->type == ENTITY_PLAYER) ||
|
||||
(entity->type >= ENTITY_FIRST_ENEMY && entity->type < ENTITY_EFFECT);
|
||||
if ((entity->flags & FLAG_FRIENDLY) && isFollower)
|
||||
reconstruction_missing("Entity_Player::room_enter 007a6c50: a friendly enemy following the player in "
|
||||
"(Entity_NPC +0x418, +0x420)");
|
||||
}
|
||||
if (HasTrinket(TRINKET_USED_DIAPER) && room.isFirstVisit && !room.IsClear() && room.GetAliveEnemiesCount() > 0 &&
|
||||
!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();
|
||||
preload_item_sounds();
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include "classes.h"
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
constexpr int ENTITY_SAVE_EXTRA_SIZE = 32;
|
||||
|
||||
// The bytes a saved entity may carry for a mod.
|
||||
using EntitySaveExtraData = std::array<uint8_t, ENTITY_SAVE_EXTRA_SIZE>;
|
||||
|
||||
// An entity kept while nobody is in its room (a room's saved entities and effects, a Moving Box, Flip's other item):
|
||||
// its kind and seeds, the storage fields its class saves into, a mod's extra bytes, and a second saved entity it carries.
|
||||
// Construction (004d3080) and copies (004d3130) are the defaults.
|
||||
struct EntitySaveState
|
||||
{
|
||||
std::optional<EntitySaveExtraData> extraData;
|
||||
std::shared_ptr<EntitySaveState> child;
|
||||
Vector targetPosition{};
|
||||
float floatStorage1 = 60;
|
||||
float floatStorage2 = 1;
|
||||
float floatStorage3 = 1;
|
||||
int64_t int64Storage = -1;
|
||||
int intStorage4 = -1;
|
||||
int intStorage5 = -1;
|
||||
int spawnerType = 0;
|
||||
int spawnerVariant = 0;
|
||||
int subtype = 0;
|
||||
int type = 0;
|
||||
int variant = 0;
|
||||
uint32_t dropSeed = 0;
|
||||
uint32_t initSeed = 0;
|
||||
uint32_t intStorage1 = 0;
|
||||
uint32_t intStorage2 = 0;
|
||||
uint32_t intStorage3 = 0;
|
||||
uint32_t intStorage6 = 0;
|
||||
uint32_t intStorage7 = 0;
|
||||
uint32_t intStorage8 = 0;
|
||||
int16_t gridSpawnIdx = 0;
|
||||
uint8_t byteStorage = 1;
|
||||
bool boolStorage1 = false;
|
||||
bool boolStorage2 = false;
|
||||
};
|
||||
+189
-12
@@ -1,26 +1,203 @@
|
||||
#include "entity_slot.h"
|
||||
#include "entity_config.h"
|
||||
#include "game.h"
|
||||
#include "log.h"
|
||||
#include "manager.h"
|
||||
#include "room.h"
|
||||
#include <array>
|
||||
|
||||
// Lua's SlotVariant: the machines and beggars.
|
||||
enum SlotVariant : int
|
||||
{
|
||||
SLOT_MACHINE = 1,
|
||||
SLOT_BLOOD_DONATION_MACHINE,
|
||||
SLOT_FORTUNE_TELLING_MACHINE,
|
||||
SLOT_BEGGAR,
|
||||
SLOT_DEVIL_BEGGAR,
|
||||
SLOT_SHELL_GAME,
|
||||
SLOT_KEY_MASTER,
|
||||
SLOT_DONATION_MACHINE,
|
||||
SLOT_BOMB_BUM,
|
||||
SLOT_SHOP_RESTOCK_MACHINE,
|
||||
SLOT_GREED_DONATION_MACHINE,
|
||||
SLOT_MOMS_DRESSER,
|
||||
SLOT_BATTERY_BUM,
|
||||
SLOT_ISAAC_SECRET,
|
||||
SLOT_HELL_GAME,
|
||||
SLOT_CRANE_GAME,
|
||||
SLOT_CONFESSIONAL,
|
||||
SLOT_ROTTEN_BEGGAR,
|
||||
SLOT_REVIVE_MACHINE
|
||||
};
|
||||
|
||||
// The event counters the donation machines show (DONATION_MACHINE_COUNTER, GREED_DONATION_MACHINE_COUNTER).
|
||||
constexpr int EVENT_DONATION_MACHINE = 20;
|
||||
constexpr int EVENT_GREED_DONATION_MACHINE = 115;
|
||||
|
||||
// The run's state flags of a broken or jammed donation machine.
|
||||
constexpr int GAME_STATE_DONATION_SLOT_BROKEN = 17;
|
||||
constexpr int GAME_STATE_DONATION_SLOT_JAMMED = 18;
|
||||
constexpr int GAME_STATE_GREED_SLOT_JAMMED = 34;
|
||||
|
||||
// The animations a jammed donation machine plays, one at random.
|
||||
constexpr std::array<const char*, 4> COIN_JAM_ANIMATIONS = {"CoinJam", "CoinJam2", "CoinJam3", "CoinJam4"};
|
||||
|
||||
constexpr int SLOT_STATE_IDLE = 1;
|
||||
constexpr int SLOT_STATE_JAMMED = 3;
|
||||
constexpr int REVIVE_MACHINE_EXCLUDED_ROOM = -20;
|
||||
constexpr int DIGIT_BASE = 10;
|
||||
constexpr int HUNDREDS = 100;
|
||||
constexpr float MACHINE_OFFSET_Y = -8;
|
||||
constexpr float BEGGAR_OFFSET_Y = 8;
|
||||
constexpr float BLOOD_MACHINE_OFFSET_X = -5;
|
||||
constexpr float MACHINE_WIDTH = 1.5f;
|
||||
constexpr float SHELL_GAME_WIDTH = 3;
|
||||
constexpr float MACHINE_DEPTH = 0.75f;
|
||||
|
||||
// Whether the run counts toward achievements (Game::AchievementUnlocksDisallowed 00705080, which Game does not declare
|
||||
// yet): not on a custom seed, a seed or mod that blocks them, or a rerun.
|
||||
static bool achievements_disallowed()
|
||||
{
|
||||
Game& game = *g_game;
|
||||
return game.seedEffects.isCustomRun || game.seedEffects.AchievementUnlocksDisallowed() ||
|
||||
Manager::AchievementUnlocksDisallowed() || game.isRerun;
|
||||
}
|
||||
|
||||
// 0065d200 Starts a slot from its config's sprite, sized and offset for its kind. The donation machines show their
|
||||
// save's count and break or jam as the run left them, the dresser appears on a first visit, and the Revive Machine
|
||||
// only stays in co-op. In Greed mode the blood donation machine is a devil beggar.
|
||||
// Isaac's secret closet and the Revive Machine's setup are not reconstructed yet.
|
||||
void Entity_Slot::Init(int entityType, int entityVariant, int entitySubType, uint32_t seed)
|
||||
{
|
||||
bool isGreed = g_game->difficulty == DIFFICULTY_GREED || g_game->difficulty == DIFFICULTY_GREEDIER;
|
||||
int kind = isGreed && entityVariant == SLOT_BLOOD_DONATION_MACHINE ? SLOT_DEVIL_BEGGAR : entityVariant;
|
||||
|
||||
persistentData = &g_manager->persistentGameData;
|
||||
Entity::Init(entityType, kind, entitySubType, seed);
|
||||
if (config)
|
||||
{
|
||||
sprite.Load(config->anm2Path, GRAPHICS_LOAD);
|
||||
sprite.Play(sprite.GetDefaultAnimationName());
|
||||
}
|
||||
|
||||
targetPosition = {};
|
||||
posOffset = {};
|
||||
sizeMulti = vector_make(1, 1);
|
||||
donationValue = 0;
|
||||
triggerTimer = 0;
|
||||
unkShort1 = 0;
|
||||
touch = 0;
|
||||
isUnknown544 = false;
|
||||
isUnknown418 = false;
|
||||
state = SLOT_STATE_IDLE;
|
||||
prizeAnm2.Reset();
|
||||
prizeCollectible = 0;
|
||||
|
||||
switch (kind)
|
||||
{
|
||||
case SLOT_MACHINE:
|
||||
case SLOT_BLOOD_DONATION_MACHINE:
|
||||
case SLOT_FORTUNE_TELLING_MACHINE:
|
||||
case SLOT_CRANE_GAME:
|
||||
case SLOT_CONFESSIONAL:
|
||||
posOffset.y = MACHINE_OFFSET_Y;
|
||||
sizeMulti = vector_make(MACHINE_WIDTH, MACHINE_DEPTH);
|
||||
if (kind == SLOT_BLOOD_DONATION_MACHINE) posOffset.x = BLOOD_MACHINE_OFFSET_X;
|
||||
break;
|
||||
case SLOT_SHELL_GAME:
|
||||
case SLOT_HELL_GAME:
|
||||
posOffset.y = MACHINE_OFFSET_Y;
|
||||
sizeMulti = vector_make(SHELL_GAME_WIDTH, MACHINE_DEPTH);
|
||||
prizeAnm2 = sprite;
|
||||
break;
|
||||
case SLOT_BEGGAR:
|
||||
case SLOT_DEVIL_BEGGAR:
|
||||
case SLOT_KEY_MASTER:
|
||||
case SLOT_BOMB_BUM:
|
||||
case SLOT_BATTERY_BUM:
|
||||
case SLOT_ROTTEN_BEGGAR:
|
||||
posOffset.y = BEGGAR_OFFSET_Y;
|
||||
break;
|
||||
case SLOT_DONATION_MACHINE:
|
||||
{
|
||||
posOffset.y = MACHINE_OFFSET_Y;
|
||||
sizeMulti = vector_make(MACHINE_WIDTH, MACHINE_DEPTH);
|
||||
counter_show(persistentData->eventCounters[EVENT_DONATION_MACHINE]);
|
||||
bool isOnline = g_manager->netplayManager.is_online();
|
||||
bool isBroken = g_game->GetStateFlag((GameStateFlag)GAME_STATE_DONATION_SLOT_BROKEN) ||
|
||||
(isOnline ? g_game->challenge != 0 || g_game->dailyChallenge._id != 0
|
||||
: achievements_disallowed());
|
||||
if (isBroken) Remove();
|
||||
if (g_game->GetStateFlag((GameStateFlag)GAME_STATE_DONATION_SLOT_JAMMED))
|
||||
{
|
||||
sprite.Play(COIN_JAM_ANIMATIONS[Random() & 3]);
|
||||
state = SLOT_STATE_JAMMED;
|
||||
}
|
||||
AddEntityFlags(FLAG_NO_KNOCKBACK);
|
||||
break;
|
||||
}
|
||||
case SLOT_GREED_DONATION_MACHINE:
|
||||
posOffset.y = MACHINE_OFFSET_Y;
|
||||
sizeMulti = vector_make(MACHINE_WIDTH, MACHINE_DEPTH);
|
||||
counter_show(persistentData->eventCounters[EVENT_GREED_DONATION_MACHINE]);
|
||||
if (achievements_disallowed() && !g_manager->netplayManager.is_online()) Remove();
|
||||
if (g_game->GetStateFlag((GameStateFlag)GAME_STATE_GREED_SLOT_JAMMED))
|
||||
{
|
||||
sprite.Play(COIN_JAM_ANIMATIONS[Random() & 3]);
|
||||
state = SLOT_STATE_JAMMED;
|
||||
}
|
||||
break;
|
||||
case SLOT_SHOP_RESTOCK_MACHINE:
|
||||
posOffset.y = MACHINE_OFFSET_Y;
|
||||
sizeMulti = vector_make(MACHINE_WIDTH, MACHINE_DEPTH);
|
||||
AddEntityFlags(FLAG_NO_KNOCKBACK);
|
||||
break;
|
||||
case SLOT_MOMS_DRESSER:
|
||||
sizeMulti = vector_make(MACHINE_WIDTH, MACHINE_DEPTH);
|
||||
if (!g_game->room->isFirstVisit) sprite.Play("Idle");
|
||||
else
|
||||
{
|
||||
sprite.Play("Appear");
|
||||
isVisible = false;
|
||||
}
|
||||
break;
|
||||
case SLOT_ISAAC_SECRET:
|
||||
reconstruction_missing("Entity_Slot::Init 0065d200: Isaac's secret closet");
|
||||
case SLOT_REVIVE_MACHINE:
|
||||
if (!g_game->playerManager.IsCoopPlay() || g_game->currentRoomIdx == REVIVE_MACHINE_EXCLUDED_ROOM) Remove();
|
||||
else reconstruction_missing("Entity_Slot::Init 0065d200: the Revive Machine in co-op (FUN_006655e0)");
|
||||
break;
|
||||
}
|
||||
entityGridCollisionClass = GRIDCOLL_NONE;
|
||||
timeout = 0;
|
||||
}
|
||||
|
||||
// Shows a donation count on the machine's three digit layers.
|
||||
void Entity_Slot::counter_show(int count)
|
||||
{
|
||||
sprite.SetFrame("Prize", 0);
|
||||
sprite.SetLayerFrame(1, count / HUNDREDS % DIGIT_BASE);
|
||||
sprite.SetLayerFrame(2, count / DIGIT_BASE % DIGIT_BASE);
|
||||
sprite.SetLayerFrame(3, count % DIGIT_BASE);
|
||||
}
|
||||
|
||||
// 00665370 Draws the slot, and a shell game's prize while it plays.
|
||||
void Entity_Slot::Render(const Vector& offset)
|
||||
{
|
||||
Entity::Render(offset);
|
||||
bool isShellGame = variant == SLOT_SHELL_GAME || variant == SLOT_HELL_GAME;
|
||||
if (isShellGame && prizeAnm2.animState.animData && prizeAnm2.animState.isPlaying)
|
||||
prizeAnm2.Render(SpriteDraw{renderPosition, {}, {}});
|
||||
}
|
||||
|
||||
// The rest of Entity_Slot is not reconstructed yet.
|
||||
|
||||
// 0065d200
|
||||
void Entity_Slot::Init(int, int, int, uint32_t)
|
||||
{
|
||||
reconstruction_missing("Entity_Slot::Init 0065d200");
|
||||
}
|
||||
|
||||
// 0065d950
|
||||
void Entity_Slot::Update()
|
||||
{
|
||||
reconstruction_missing("Entity_Slot::Update 0065d950");
|
||||
}
|
||||
|
||||
// 00665370
|
||||
void Entity_Slot::Render(const Vector&)
|
||||
{
|
||||
reconstruction_missing("Entity_Slot::Render 00665370");
|
||||
}
|
||||
|
||||
// 00664560
|
||||
bool Entity_Slot::TakeDamage(float, uint64_t, const EntityRef&, int)
|
||||
{
|
||||
|
||||
+19
-1
@@ -3,9 +3,24 @@
|
||||
#include "entity.h"
|
||||
|
||||
// Construction and destruction (0065d130) are the defaults.
|
||||
// A slot machine, beggar or other paying machine (Lua's EntitySlot), which pays out a prize.
|
||||
// A slot machine, beggar or other paying machine (Lua's EntitySlot), which pays out a prize: its state, the prize it
|
||||
// shows and the save data its donations count into.
|
||||
struct Entity_Slot : Entity
|
||||
{
|
||||
ANM2 prizeAnm2;
|
||||
PersistentGameData* persistentData = nullptr;
|
||||
int donationValue = 0;
|
||||
int prizeCollectible = 0;
|
||||
int prizeType = 0;
|
||||
int state = 0;
|
||||
uint32_t triggerTimer = 0;
|
||||
int16_t shellGameAnimationIndex = 0;
|
||||
int16_t timeout = 0;
|
||||
int16_t unkShort1 = 0;
|
||||
uint16_t touch = 0;
|
||||
bool isUnknown418 = false;
|
||||
bool isUnknown544 = false;
|
||||
|
||||
void Init(int type, int variant, int subType, uint32_t initSeed) override;
|
||||
void Update() override;
|
||||
void Render(const Vector& offset) override;
|
||||
@@ -14,4 +29,7 @@ struct Entity_Slot : Entity
|
||||
|
||||
void spawn_break_drops();
|
||||
void SetPrizeType(int prizeType);
|
||||
|
||||
private:
|
||||
void counter_show(int count);
|
||||
};
|
||||
+65
-12
@@ -146,6 +146,30 @@ constexpr std::array<int, 6> BLOOD_ANIMATION_VARIANTS = {TEAR_BLOOD, TE
|
||||
constexpr std::array<int, 6> STONE_ANIMATION_VARIANTS = {TEAR_STONE, TEAR_BOOGER, TEAR_EGG,
|
||||
TEAR_RAZOR, TEAR_BONE, TEAR_SPORE};
|
||||
|
||||
// The halo of a glowing tear, and the tear effects in the order SetTearFlags picks them: the flag that shows each and
|
||||
// its sprite. Rift's tears show Little Horn's effect tinted.
|
||||
constexpr const char* TEAR_HALO_ANM2 = "gfx/TearHalo.anm2";
|
||||
constexpr ColorMod RIFT_EFFECT_COLOR = {{1, 0.7f, 0.7f, 1}, {0, 0, 0, 0}, {0, 0, 0}};
|
||||
// A render flag the creep, fire and dark matter effects and their first layer carry, read by nothing written yet.
|
||||
constexpr unsigned int TEAR_EFFECT_LAYERED = 1 << 12;
|
||||
|
||||
// A tear effect: the flag that shows it and its sprite.
|
||||
struct TearEffect
|
||||
{
|
||||
int flag = 0;
|
||||
const char* anm2 = nullptr;
|
||||
};
|
||||
|
||||
constexpr std::array<TearEffect, 7> TEAR_EFFECTS = {{
|
||||
{TEAR_HORN, "gfx/LittleHornTearEffect.anm2"},
|
||||
{TEAR_RIFT, "gfx/LittleHornTearEffect.anm2"},
|
||||
{TEAR_LIGHT_FROM_HEAVEN, "gfx/HolyLightTearEffect.anm2"},
|
||||
{TEAR_JACOBS, "gfx/JacobsLadderTearEffect.anm2"},
|
||||
{TEAR_MYSTERIOUS_LIQUID_CREEP, "gfx/MysteriousTearEffect.anm2"},
|
||||
{TEAR_BURN, "gfx/FireMindTearEffect.anm2"},
|
||||
{TEAR_DARK_MATTER_FLAG, "gfx/DarkMatterTearEffect.anm2"},
|
||||
}};
|
||||
|
||||
// The splash a dying tear leaves: its poof and its sound.
|
||||
struct TearSplash
|
||||
{
|
||||
@@ -209,12 +233,6 @@ static bool is_crawlspace()
|
||||
return g_game->room->roomType == ROOM_DUNGEON;
|
||||
}
|
||||
|
||||
// Stops where a mod has a function for one of the tear's Lua callbacks, which LuaEngine does not run yet.
|
||||
static void lua_callback_check(int callback, const char* name)
|
||||
{
|
||||
if (static_cast<LuaEngine*>(g_luaEngine)->enabledCallbacks[callback]) reconstruction_missing(name);
|
||||
}
|
||||
|
||||
// Whether the player is another machine's in an online game, whose shots the game fades.
|
||||
static bool is_remote_player(Entity_Player* player)
|
||||
{
|
||||
@@ -726,6 +744,47 @@ void Entity_Tear::SetScale(float scale)
|
||||
ResetSpriteScale();
|
||||
}
|
||||
|
||||
// Loads the tear effect the first of its flags calls for and plays it: Little Horn's additive (tinted for Rift's
|
||||
// tears), Holy Light's and Jacob's Ladder's first layer additive, and the creep, fire and dark matter drawn behind.
|
||||
static void tear_effect_load(ANM2& effect, const TearFlags& flags)
|
||||
{
|
||||
auto shown = std::find_if(TEAR_EFFECTS.begin(), TEAR_EFFECTS.end(),
|
||||
[&flags](const TearEffect& candidate) { return flags[candidate.flag]; });
|
||||
if (shown == TEAR_EFFECTS.end()) return;
|
||||
|
||||
effect.Load(shown->anm2, GRAPHICS_LOAD);
|
||||
switch (shown->flag)
|
||||
{
|
||||
case TEAR_HORN:
|
||||
case TEAR_RIFT:
|
||||
for (int i = 0; i < (int)effect.layerStates.size(); i++)
|
||||
{
|
||||
layer_additive_set(effect, i);
|
||||
if (shown->flag == TEAR_RIFT) effect.GetLayer(i)->color = RIFT_EFFECT_COLOR;
|
||||
}
|
||||
break;
|
||||
case TEAR_LIGHT_FROM_HEAVEN:
|
||||
case TEAR_JACOBS: layer_additive_set(effect, 0); break;
|
||||
default:
|
||||
effect.bitflags |= TEAR_EFFECT_LAYERED | TEAR_EFFECT_BEHIND;
|
||||
effect.GetLayer(0)->bitflags = TEAR_EFFECT_LAYERED;
|
||||
if (shown->flag == TEAR_MYSTERIOUS_LIQUID_CREEP) layer_additive_set(effect, 1);
|
||||
}
|
||||
effect.Play("Idle");
|
||||
}
|
||||
|
||||
// 00676150 Sets the tear flags, loading what they show the first time: a glowing tear's halo, and its one effect.
|
||||
void Entity_Tear::SetTearFlags(TearFlags flags)
|
||||
{
|
||||
if (flags[TEAR_GLOW] && !tearHaloANM2.isLoaded)
|
||||
{
|
||||
tearHaloANM2.Load(TEAR_HALO_ANM2, GRAPHICS_LOAD);
|
||||
tearHaloANM2.Play("Idle");
|
||||
}
|
||||
if (!tearEffectANM2.isLoaded) tear_effect_load(tearEffectANM2, flags);
|
||||
tearFlags = flags;
|
||||
}
|
||||
|
||||
// 00676be0 Applies what its flags do when it dies, splitting it or chaining lightning. A tear without flags does
|
||||
// nothing.
|
||||
void Entity_Tear::apply_death_flag_effects(Entity*)
|
||||
@@ -902,12 +961,6 @@ void Entity_Tear::update_wiggle()
|
||||
reconstruction_missing("Entity_Tear::update_wiggle 00666ba0");
|
||||
}
|
||||
|
||||
// 00676150
|
||||
void Entity_Tear::SetTearFlags(TearFlags)
|
||||
{
|
||||
reconstruction_missing("Entity_Tear::SetTearFlags 00676150");
|
||||
}
|
||||
|
||||
// 00678080
|
||||
void Entity_Tear::fire_split_projectiles(bool)
|
||||
{
|
||||
|
||||
@@ -11,10 +11,17 @@ enum TearFlagBit : int
|
||||
TEAR_EXPLOSIVE = 12,
|
||||
TEAR_WAIT = 17,
|
||||
TEAR_QUADSPLIT = 18,
|
||||
TEAR_BURN = 22,
|
||||
TEAR_GLOW = 31,
|
||||
TEAR_MYSTERIOUS_LIQUID_CREEP = 33,
|
||||
TEAR_SHIELDED = 34,
|
||||
TEAR_LIGHT_FROM_HEAVEN = 39,
|
||||
TEAR_TRACTOR_BEAM = 42,
|
||||
TEAR_JACOBS = 55,
|
||||
TEAR_HORN = 56,
|
||||
TEAR_POP = 58,
|
||||
TEAR_RIFT = 76,
|
||||
TEAR_DARK_MATTER_FLAG = 124,
|
||||
TEAR_LUDOVICO = 127
|
||||
};
|
||||
|
||||
|
||||
+4
-69
@@ -407,9 +407,9 @@ void Game::ResetState()
|
||||
|
||||
for (BackwardsStageDesc& backwards : backwardsStages)
|
||||
{
|
||||
backwards._isXL = false;
|
||||
backwards._bossRoomsCount = 0;
|
||||
backwards._treasureRoomsCount = 0;
|
||||
backwards.isXL = false;
|
||||
backwards.bossRooms.clear();
|
||||
backwards.treasureRooms.clear();
|
||||
}
|
||||
|
||||
deathCertificateExitTimer = 0;
|
||||
@@ -425,7 +425,7 @@ void Game::ResetState()
|
||||
isRestoringGlowingHourglassState = false;
|
||||
currentGlowingHourglassSlot = -1;
|
||||
rewindsThisFloor = 0;
|
||||
for (GlowingHourglassState& state : glowingHourglassStates) state._isUsable = false;
|
||||
for (GlowingHourglassState& state : glowingHourglassStates) state.isUsable = false;
|
||||
isPocketItemRewindSaved = false;
|
||||
reviveMachineUses = 0;
|
||||
reviveMachineCoinsLeft = REVIVE_MACHINE_COINS;
|
||||
@@ -537,66 +537,6 @@ void Game::Fadein(float speed, FadeIcon icon, KColor color)
|
||||
for (Entity_Player* player : playerManager.playerList) player->isControlsEnabled = false;
|
||||
}
|
||||
|
||||
// 006f9000 Copies the run into a game state to save: its rules and seeds, the counters and histories of the run, the
|
||||
// item and boss pools, the TMTRAINER seeds, the floor (after leaving the room), the players, the Ascent's saved
|
||||
// stages, the nightmare stage bar, the ambush wave, the score and the versus rules.
|
||||
// The saved flags are the first 53 of the run's state flags.
|
||||
void Game::store_game_state(GameState& state)
|
||||
{
|
||||
state.Clear();
|
||||
state.seeds = seedEffects;
|
||||
state.playerManagerSeed = playerManager.rng._seed;
|
||||
state.fortuneSeed = fortuneRNG._seed;
|
||||
state.challenge = (int)challenge;
|
||||
state.isRerun = isRerun;
|
||||
state.isConsoleUsedThisRun = isConsoleUsedThisRun;
|
||||
state.difficulty = difficulty;
|
||||
state.gameStateFlags = std::bitset<SAVED_GAME_STATE_FLAG_COUNT>(gameStateFlags);
|
||||
|
||||
state.lastDevilRoomStage = lastDevilRoomStage;
|
||||
state.treasureRoomsVisited = treasureRoomsVisited;
|
||||
state.planetariumsVisited = planetariumsVisited;
|
||||
state.stagesWithoutHeartsPicked = stagesWithoutHeartsPicked;
|
||||
state.stagesWithoutDamage = stagesWithoutDamage;
|
||||
state.devilRoomDeals = devilRoomDeals;
|
||||
state.shopVisits = shopVisits;
|
||||
state.donationModGreed = donationModGreed;
|
||||
state.donationModAngel = donationModAngel;
|
||||
state.reviveMachineCoinsLeft = reviveMachineCoinsLeft;
|
||||
state.reviveMachineUses = reviveMachineUses;
|
||||
state.bossRushParTime = bossRushParTime;
|
||||
state.blueWombParTime = blueWombParTime;
|
||||
state.frameCount = frameCount;
|
||||
state.timeCounter = timeCounter;
|
||||
state.stageNameNumeral = stageNameNumeral;
|
||||
state.victoryLap = victoryLap;
|
||||
state.lastLevelWithoutHalfHp = lastLevelWithoutHalfHp;
|
||||
state.lastLevelWithDamage = lastLevelWithDamage;
|
||||
state.encounteredBosses = encounteredBosses;
|
||||
state.pixelationTimer = pixelationTimer;
|
||||
state.pixelationDuration = pixelationDuration;
|
||||
state.magicSkinUses = magicSkinUses;
|
||||
state.erasedEntities = erasedEntities;
|
||||
itemPool.StoreGameState(state.itemPool);
|
||||
bossPool.store_game_state(state.bossPool);
|
||||
if (!proceduralItemManager.proceduralItems.empty())
|
||||
reconstruction_missing("Game::store_game_state 006f9000: the TMTRAINER items' seeds (ProceduralItem +0x8)");
|
||||
|
||||
reconstruction_missing("Game::store_game_state 006f9000: Room::on_leave 007efa50");
|
||||
Level::store_game_state(state);
|
||||
playerManager.store_game_state(&state);
|
||||
|
||||
state.isAscent = ascentTimer > 0;
|
||||
state.backwardsStages = backwardsStages;
|
||||
state.deathCertificateExitTimer = deathCertificateExitTimer;
|
||||
state.nightmareStageIcons = g_manager->nightmareScene.stageIcons;
|
||||
state.isAmbushActive = ambush._isActive;
|
||||
state.ambushWave = ambush._currentWave > 0 ? ambush._currentWave - 1 : ambush._currentWave;
|
||||
scoreSheet.store_state(state.scoreSheet);
|
||||
reconstruction_missing("Game::store_game_state 006f9000: the versus rules (DeathmatchTypeBase slot 1 and its "
|
||||
"StoreGameState)");
|
||||
}
|
||||
|
||||
// 009b5cb0 Closes the pause screen for a new run on Resume, with its paper's animation stopped, the options listed
|
||||
// again, My Stuff closed and the quit prompt reset.
|
||||
// The original also stops the full-size paper and resets fields of it, which pause_screen.h leaves out.
|
||||
@@ -615,11 +555,6 @@ void Game::Exit(bool)
|
||||
reconstruction_missing("Game::Exit 006fa0c0");
|
||||
}
|
||||
|
||||
void Game::save_rewind_state(int)
|
||||
{
|
||||
reconstruction_missing("Game::save_rewind_state 00705ee0");
|
||||
}
|
||||
|
||||
constexpr const char* BLOOM_SHADER = "Bloom";
|
||||
constexpr const char* COLOR_MOD_SHADER = "ColorMod";
|
||||
constexpr const char* COLOR_OFFSET_SHADER = "ColorOffset";
|
||||
|
||||
@@ -301,6 +301,7 @@ public:
|
||||
void Fadein(float speed, FadeIcon icon, KColor color);
|
||||
void SetColorModifier(const ColorModState& color, bool isLerp, float rate);
|
||||
void save_rewind_state(int leaveDoor);
|
||||
void StartRoomTransition(RoomTransitionRequest request);
|
||||
void Fadeout(float speed, FadeOutTarget target, KColor color = kcolor_rgba(0, 0, 0, 1));
|
||||
void store_game_state(GameState& state);
|
||||
static void Exit(bool isSaving);
|
||||
|
||||
@@ -0,0 +1,528 @@
|
||||
#include "game.h"
|
||||
#include "game_state_player.h"
|
||||
#include "entity_familiar.h"
|
||||
#include "entity_npc.h"
|
||||
#include "log.h"
|
||||
#include "manager.h"
|
||||
#include "platform.h"
|
||||
#include "room.h"
|
||||
#include <typeinfo>
|
||||
|
||||
constexpr int CHALLENGE_SPEED = 22;
|
||||
constexpr int ENTITY_CHARGER = 23;
|
||||
constexpr int CHARGER_MY_SHADOW = 1;
|
||||
constexpr int FAMILIAR_WISP = 206;
|
||||
constexpr int FAMILIAR_UMBILICAL_BABY = 240;
|
||||
constexpr int FAMILIAR_FORGOTTEN_BODY = 900;
|
||||
constexpr int COLLECTIBLE_VENTRICLE_RAZOR = 396;
|
||||
constexpr int REWIND_DOOR_FRAMES = 15;
|
||||
constexpr int ROOM_REF_MODE_SHIFT = 16;
|
||||
constexpr int ROOM_REF_HALF_SHIFT = 16;
|
||||
constexpr uint32_t ROOM_FLAG_SAVED = 0x40;
|
||||
constexpr uint32_t ROOM_REF_FLAGGED = 0x20000000;
|
||||
constexpr uint32_t ROOM_REF_MIRRORED = 0x40000000;
|
||||
constexpr uint32_t ROOM_REF_MERGED = 0x80000000;
|
||||
|
||||
// The versus rules each kind of match plays, as its slot 1 answers.
|
||||
static const std::array<std::pair<const std::type_info*, DeathmatchRules>, DEATHMATCH_VENOM> DEATHMATCH_TYPE_RULES = {{
|
||||
{&typeid(DeathmatchTypeNormal), DEATHMATCH_NORMAL},
|
||||
{&typeid(DeathmatchTypeIpecac), DEATHMATCH_IPECAC},
|
||||
{&typeid(DeathmatchTypeBomberman), DEATHMATCH_BOMBERMAN},
|
||||
{&typeid(DeathmatchTypeLudovico), DEATHMATCH_LUDOVICO},
|
||||
{&typeid(DeathmatchTypeSumo), DEATHMATCH_SUMO},
|
||||
{&typeid(DeathmatchTypeKnockout), DEATHMATCH_KNOCKOUT},
|
||||
{&typeid(DeathmatchTypeSwordFight), DEATHMATCH_SWORD_FIGHT},
|
||||
{&typeid(DeathmatchTypeMachineGun), DEATHMATCH_MACHINE_GUN},
|
||||
{&typeid(DeathmatchTypeIndigestion), DEATHMATCH_INDIGESTION},
|
||||
{&typeid(DeathmatchTypeKnifeFight), DEATHMATCH_KNIFE_FIGHT},
|
||||
{&typeid(DeathmatchTypeVenom), DEATHMATCH_VENOM},
|
||||
}};
|
||||
|
||||
// Saves the versus rules as DeathmatchTypeBase::StoreGameState does: which kind of match the run drew (each type's
|
||||
// slot 1) and its players.
|
||||
// Offline no player ever joins a match, so its player set stays empty. A run without rules saves none.
|
||||
static void versus_store(DeathmatchManager& manager, GameState& state)
|
||||
{
|
||||
state.versusPlayers.clear();
|
||||
if (!manager.type) return;
|
||||
|
||||
DeathmatchTypeBase* type = manager.type.get();
|
||||
const std::type_info& drawn = typeid(*type);
|
||||
for (auto [info, rules] : DEATHMATCH_TYPE_RULES)
|
||||
if (*info == drawn) state.versusRules = (uint8_t)rules;
|
||||
}
|
||||
|
||||
// 006f9000 Copies the run into a game state to save: its rules and seeds, the counters and histories of the run, the
|
||||
// item and boss pools, the TMTRAINER seeds, the floor (after leaving the room), the players, the Ascent's saved
|
||||
// stages, the nightmare stage bar, the ambush wave, the score and the versus rules.
|
||||
// The saved flags are the first 53 of the run's state flags.
|
||||
void Game::store_game_state(GameState& state)
|
||||
{
|
||||
state.Clear();
|
||||
state.seeds = seedEffects;
|
||||
state.playerManagerSeed = playerManager.rng._seed;
|
||||
state.fortuneSeed = fortuneRNG._seed;
|
||||
state.challenge = (int)challenge;
|
||||
state.isRerun = isRerun;
|
||||
state.isConsoleUsedThisRun = isConsoleUsedThisRun;
|
||||
state.difficulty = difficulty;
|
||||
state.gameStateFlags = std::bitset<SAVED_GAME_STATE_FLAG_COUNT>(gameStateFlags);
|
||||
|
||||
state.lastDevilRoomStage = lastDevilRoomStage;
|
||||
state.treasureRoomsVisited = treasureRoomsVisited;
|
||||
state.planetariumsVisited = planetariumsVisited;
|
||||
state.stagesWithoutHeartsPicked = stagesWithoutHeartsPicked;
|
||||
state.stagesWithoutDamage = stagesWithoutDamage;
|
||||
state.devilRoomDeals = devilRoomDeals;
|
||||
state.shopVisits = shopVisits;
|
||||
state.donationModGreed = donationModGreed;
|
||||
state.donationModAngel = donationModAngel;
|
||||
state.reviveMachineCoinsLeft = reviveMachineCoinsLeft;
|
||||
state.reviveMachineUses = reviveMachineUses;
|
||||
state.bossRushParTime = bossRushParTime;
|
||||
state.blueWombParTime = blueWombParTime;
|
||||
state.frameCount = frameCount;
|
||||
state.timeCounter = timeCounter;
|
||||
state.stageNameNumeral = stageNameNumeral;
|
||||
state.victoryLap = victoryLap;
|
||||
state.lastLevelWithoutHalfHp = lastLevelWithoutHalfHp;
|
||||
state.lastLevelWithDamage = lastLevelWithDamage;
|
||||
state.encounteredBosses = encounteredBosses;
|
||||
state.pixelationTimer = pixelationTimer;
|
||||
state.pixelationDuration = pixelationDuration;
|
||||
state.magicSkinUses = magicSkinUses;
|
||||
state.erasedEntities = erasedEntities;
|
||||
itemPool.StoreGameState(state.itemPool);
|
||||
bossPool.store_game_state(state.bossPool);
|
||||
if (!proceduralItemManager.proceduralItems.empty())
|
||||
reconstruction_missing("Game::store_game_state 006f9000: the TMTRAINER items' seeds (ProceduralItem +0x8)");
|
||||
|
||||
room->on_leave();
|
||||
Level::store_game_state(state);
|
||||
playerManager.store_game_state(&state);
|
||||
|
||||
state.isAscent = ascentTimer > 0;
|
||||
state.backwardsStages = backwardsStages;
|
||||
state.deathCertificateExitTimer = deathCertificateExitTimer;
|
||||
state.nightmareStageIcons = g_manager->nightmareScene.stageIcons;
|
||||
state.isAmbushActive = ambush._isActive;
|
||||
state.ambushWave = ambush._currentWave > 0 ? ambush._currentWave - 1 : ambush._currentWave;
|
||||
scoreSheet.store_state(state.scoreSheet);
|
||||
versus_store(deathmatchManager, state);
|
||||
}
|
||||
|
||||
// 00705ee0 Saves the run for the Glowing Hourglass as the players enter a room, by the door they leave it through.
|
||||
// A door left again within 15 frames of entering (or the same door) keeps the saved state. Saving the room again keeps
|
||||
// its devil deal stage, and a new room flips to the other slot, the old one remembering the door it was left by.
|
||||
void Game::save_rewind_state(int leaveDoorSlot)
|
||||
{
|
||||
if (isStoringGlowingHourglassState || isRestoringGlowingHourglassState || isPocketItemRewindSaved) return;
|
||||
|
||||
int slot = 0;
|
||||
bool isSameRoom = false;
|
||||
if (currentGlowingHourglassSlot >= 0 && glowingHourglassStates[currentGlowingHourglassSlot].isUsable)
|
||||
{
|
||||
GlowingHourglassState& current = glowingHourglassStates[currentGlowingHourglassSlot];
|
||||
isSameRoom = current.gameState.currentRoomIdx == currentRoomIdx && current.gameState.stage == stage;
|
||||
slot = isSameRoom ? currentGlowingHourglassSlot : 1 - currentGlowingHourglassSlot;
|
||||
if (!isSameRoom) current.gameState.enterDoor = leaveDoor;
|
||||
if (isSameRoom && leaveDoorSlot >= 0)
|
||||
{
|
||||
bool isRecent = (uint32_t)(frameCount - current.timeCounter) < REWIND_DOOR_FRAMES;
|
||||
if (leaveDoorSlot == current.leaveDoor || (current.leaveDoor >= 0 && isRecent)) return;
|
||||
}
|
||||
}
|
||||
|
||||
currentGlowingHourglassSlot = slot;
|
||||
isStoringGlowingHourglassState = true;
|
||||
GlowingHourglassState& state = glowingHourglassStates[slot];
|
||||
int keptDevilRoomStage = state.gameState.lastDevilRoomStage;
|
||||
store_game_state(state.gameState);
|
||||
if (isSameRoom) state.gameState.lastDevilRoomStage = keptDevilRoomStage;
|
||||
|
||||
state.isUsable = true;
|
||||
state.leaveDoor = leaveDoorSlot;
|
||||
state.timeCounter = frameCount;
|
||||
state.eventCounters = g_manager->persistentGameData.eventCounters;
|
||||
isStoringGlowingHourglassState = false;
|
||||
}
|
||||
|
||||
// 00747360 Names a room's config for a saved run: its stage, mode, mirroring and flag 0x40 packed with its type and
|
||||
// variant, or for a merged room its shape, with its halves appended to the merged configs. Without that list a merged
|
||||
// room is left as it was.
|
||||
void room_config_ref_save(RoomConfig_Room& config, RoomConfigRef& ref, std::vector<RoomConfigRef>* mergedConfigs)
|
||||
{
|
||||
if (!(config.flags & ROOM_FLAG_MERGED))
|
||||
{
|
||||
ref.packed = (uint32_t)(uint8_t)config.mode << ROOM_REF_MODE_SHIFT | (uint32_t)config.stageId;
|
||||
if (config.flags & ROOM_FLAG_MIRRORED) ref.packed |= ROOM_REF_MIRRORED;
|
||||
if (config.flags & ROOM_FLAG_SAVED) ref.packed |= ROOM_REF_FLAGGED;
|
||||
ref.type = config.type;
|
||||
ref.variant = config.variant;
|
||||
return;
|
||||
}
|
||||
if (!mergedConfigs) return;
|
||||
|
||||
ref.packed = ROOM_REF_MERGED;
|
||||
ref.type = config.shape;
|
||||
ref.variant = 0;
|
||||
for (size_t i = 0; i < config.mergedData.size(); i++)
|
||||
{
|
||||
size_t index = mergedConfigs->size();
|
||||
RoomConfigRef half;
|
||||
|
||||
ref.variant |= (uint32_t)(uint16_t)index << (ROOM_REF_HALF_SHIFT * i);
|
||||
mergedConfigs->push_back({});
|
||||
room_config_ref_save(*config.mergedData[i], half, mergedConfigs);
|
||||
(*mergedConfigs)[index] = half;
|
||||
}
|
||||
}
|
||||
|
||||
// 00747e10 Copies the floor into a game state: its stage, curses, flags and Greed waves, its seeds, the 13x13 maps, every
|
||||
// room descriptor (006f8d60, a plain copy) with its config named apart (its config pointer cleared), the rooms the
|
||||
// players are in and came from, the room's watch speed and slowdown, the Ventricle Razor portals and bombs spawned.
|
||||
// The Speed! challenge saves the watch as fast.
|
||||
void Level::store_game_state(GameState& state)
|
||||
{
|
||||
state.stage = stage;
|
||||
state.stageType = stageType;
|
||||
state.startingRoomIdx = startingRoomIdx;
|
||||
state.lastBossRoomListIdx = lastBossRoomListIdx;
|
||||
state.curses = curses;
|
||||
state.isBossChallenge = isBossChallenge;
|
||||
state.levelStateFlags = std::bitset<LEVEL_STATE_FLAG_COUNT>(levelStateFlags);
|
||||
state.greedModeWave = greedModeWave;
|
||||
state.greedWaveSeeds = greedWaveSeeds;
|
||||
state.greedModeTreasureRoomIdx = greedModeTreasureRoomIdx;
|
||||
state.greedLastBeatenWave = greedLastBeatenWave;
|
||||
state.greedLastPaidWave = greedLastPaidWave;
|
||||
state.isHeartPicked = isHeartPicked;
|
||||
state.isDevilRoomDisabled = isDevilRoomDisabled;
|
||||
state.isCanSeeEverything = isCanSeeEverything;
|
||||
state.dungeonPlacementSeed = dungeonPlacementSeed;
|
||||
state.devilAngelRoomSeed = devilAngelRoomRNG._seed;
|
||||
state.angelRoomChance = angelRoomChance;
|
||||
state.bombPickupsSpawned = bombPickupsSpawned;
|
||||
state.roomMap = roomMap;
|
||||
|
||||
state.mergedRoomConfigs.clear();
|
||||
state.roomCount = nbRooms;
|
||||
state.rooms.resize(ROOM_DESCRIPTOR_COUNT);
|
||||
for (int i = 0; i < ROOM_DESCRIPTOR_COUNT; i++)
|
||||
{
|
||||
SavedRoom& saved = state.rooms[i];
|
||||
if (roomList[i].data) room_config_ref_save(*roomList[i].data, saved.config, &state.mergedRoomConfigs);
|
||||
saved.desc = roomList[i];
|
||||
saved.desc.data = nullptr;
|
||||
}
|
||||
|
||||
state.currentRoomIdx = currentRoomIdx;
|
||||
state.lastRoomIdx = lastRoomIdx;
|
||||
state.brokenWatchState = g_game->challenge == CHALLENGE_SPEED ? BROKEN_WATCH_FAST : room->brokenWatchState;
|
||||
state.slowdownDuration = room->slowdownDuration;
|
||||
state.currentDimensionIdx = (uint8_t)currentDimensionIdx;
|
||||
state.lastRoomDimensionIdx = (uint8_t)lastRoomDimensionIdx;
|
||||
state.dungeonReturnPosition = dungeonReturnPosition;
|
||||
state.dungeonReturnRoomIndex = dungeonReturnRoomIndex;
|
||||
state.enterDoor = enterDoor;
|
||||
state.ventricleRazorPortals = ventricleRazorPortals;
|
||||
}
|
||||
|
||||
// 009bd150 Copies the players into a game state, each leaving the room first unless the Glowing Hourglass saves:
|
||||
// every main player, then its backup player (marked as one), up to 8, then the Esau Jr. players. The first player
|
||||
// also keeps the glitched baby seed and the random babies. Each player learns its place in the save.
|
||||
// A player that leaving the room removed from the list is skipped.
|
||||
void PlayerManager::store_game_state(GameState* state)
|
||||
{
|
||||
bool isRewind = g_game->isStoringGlowingHourglassState;
|
||||
std::vector<GameStatePlayer>& players = state->players;
|
||||
|
||||
// Whether every place is taken, which the original logs.
|
||||
auto is_full = [&]()
|
||||
{
|
||||
bool isFull = players.size() >= GAME_STATE_PLAYER_LIMIT;
|
||||
if (isFull) log_printf(LOG_WARN, "Number of players exceeds supported player limit (%d)!\n", GAME_STATE_PLAYER_LIMIT);
|
||||
return isFull;
|
||||
};
|
||||
// Saves a player into the next place.
|
||||
auto player_store = [&](Entity_Player& player)
|
||||
{
|
||||
player.glowingHourglassIndex = (int)players.size();
|
||||
player.StoreGameState(&players.emplace_back(), true);
|
||||
};
|
||||
|
||||
players.clear();
|
||||
for (size_t i = 0; i < playerList.size(); i++)
|
||||
{
|
||||
Entity_Player* player = playerList[i];
|
||||
size_t count = playerList.size();
|
||||
if (player->variant != PLAYER_VARIANT_PLAYER) continue;
|
||||
if (is_full()) break;
|
||||
|
||||
if (!isRewind) player->room_exit(true);
|
||||
if (playerList.size() < count)
|
||||
{
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
player_store(*player);
|
||||
|
||||
Entity_Player* backup = player->backupPlayer;
|
||||
if (!backup) continue;
|
||||
if (is_full()) break;
|
||||
if (!isRewind) backup->room_exit(true);
|
||||
player_store(*backup);
|
||||
players.back().isBackupPlayer = true;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < esauJrState.size(); i++)
|
||||
{
|
||||
GameStatePlayer& slot = state->esauJrStates[i];
|
||||
if (esauJrState[i]) esauJrState[i]->StoreGameState(&slot, true);
|
||||
else slot.playerType = -1;
|
||||
}
|
||||
|
||||
if (players.empty()) return;
|
||||
GameStatePlayer& first = players.front();
|
||||
first.glitchBabySeed = (int)glitchBabyRng._seed;
|
||||
first.randomBabies = randomBabies;
|
||||
first.randomBabyCount = randomBabyCount;
|
||||
}
|
||||
|
||||
// 007b0b40 A co-op baby's or sub player's character (a baby's skin) and hearts, a baby without eternal hearts.
|
||||
static CoPlayerState co_player_save(Entity_Player& player)
|
||||
{
|
||||
bool isBaby = player.variant == PLAYER_VARIANT_COOP_BABY;
|
||||
return {.blackHearts = player.blackHearts,
|
||||
.boneHearts = player.boneHearts,
|
||||
.boneHeartsMask = player.boneHeartsMask,
|
||||
.brokenHearts = player.brokenHearts,
|
||||
.eternalHearts = isBaby ? 0 : player.eternalHearts,
|
||||
.goldenHearts = player.goldenHearts,
|
||||
.maxHearts = player.maxHearts,
|
||||
.playerType = isBaby ? player.babySkin : player.playerType,
|
||||
.redHearts = player.redHearts,
|
||||
.rottenHearts = player.rottenHearts,
|
||||
.soulHearts = player.soulHearts};
|
||||
}
|
||||
|
||||
// 006d0370 A charmed enemy as a player keeps it: its kind, champion and health, and whether a player controls it.
|
||||
static EntityDesc charmed_enemy_save(Entity_NPC& npc)
|
||||
{
|
||||
return {.health = npc.health,
|
||||
.maxHealth = npc.maxHitPoints,
|
||||
.subtype = (uint32_t)npc.subtype,
|
||||
.type = (uint32_t)npc.type,
|
||||
.variant = (uint32_t)npc.variant,
|
||||
.championId = npc.championColorIdx,
|
||||
.isPlayerControlled = npc.IsFriendly() && npc.controllerID != -1};
|
||||
}
|
||||
|
||||
// The seeds of a player's item RNGs.
|
||||
static void rng_seeds_save(std::vector<RNG>& rngs, std::vector<uint32_t>& seeds)
|
||||
{
|
||||
seeds.clear();
|
||||
for (RNG& rng : rngs) seeds.push_back(rng._seed);
|
||||
}
|
||||
|
||||
// Whether a familiar follows its player into a saved run: not the Forgotten's body, Ventricle Razor's wisp or the
|
||||
// Umbilical Baby, and a temporary one only when those are saved.
|
||||
static bool is_familiar_saved(Entity_Familiar& familiar, bool isSaveTemporaryFamiliars)
|
||||
{
|
||||
bool isRazorWisp = familiar.variant == FAMILIAR_WISP && familiar.subtype == COLLECTIBLE_VENTRICLE_RAZOR;
|
||||
if (familiar.variant == FAMILIAR_FORGOTTEN_BODY || isRazorWisp || familiar.variant == FAMILIAR_UMBILICAL_BABY)
|
||||
return false;
|
||||
return isSaveTemporaryFamiliars || !familiar.isNotCountedAsFollower;
|
||||
}
|
||||
|
||||
// 007b0be0 Copies the player into a saved player: its character, health and consumables, its sub player and the co-op
|
||||
// babies that belong to the first player, history, stats and counters, items, pockets and their RNGs, costumes, the
|
||||
// Moving Box, the friendly enemies it charmed (up to 10, the first twin only), its familiars and persistent effects.
|
||||
// The fields the curated player does not have yet keep their defaults: the candy heart and soul locket stat ups, the
|
||||
// soul charge, the last pill color, the kill counter, the crafting pool, the later poop spells and their counters,
|
||||
// the last collectible frame and the unknown fields. Its Echo Chamber items are saved without their kind, and its
|
||||
// voided passives without their second word. The unlisted restore state is never set, so familiars come from the room.
|
||||
void Entity_Player::StoreGameState(GameStatePlayer* saveState, bool isSaveTemporaryFamiliars)
|
||||
{
|
||||
GameStatePlayer& state = *saveState;
|
||||
Game& game = *g_game;
|
||||
PlayerManager& players = game.playerManager;
|
||||
|
||||
state.controllerIndex = controllerIndex;
|
||||
state.isHolyMantle = holyMantleState != 0;
|
||||
state.playerType = playerType;
|
||||
state.redHearts = redHearts;
|
||||
state.maxHearts = maxHearts;
|
||||
state.soulHearts = soulHearts;
|
||||
state.blackHearts = blackHearts;
|
||||
state.boneHearts = boneHearts;
|
||||
state.boneHeartsMask = boneHeartsMask;
|
||||
state.eternalHearts = eternalHearts;
|
||||
state.subPlayer.reset();
|
||||
if (subPlayer) state.subPlayer = co_player_save(*subPlayer);
|
||||
|
||||
state.coopBabies.clear();
|
||||
for (Entity_Player* baby : players.playerList)
|
||||
{
|
||||
bool isOwnBaby = baby->variant == PLAYER_VARIANT_COOP_BABY && !baby->parent.get() && players.GetPlayer(0) == this;
|
||||
if (isOwnBaby) state.coopBabies.push_back(co_player_save(*baby));
|
||||
}
|
||||
state.history = history.historyItems;
|
||||
state.inventory = inventory;
|
||||
|
||||
state.jarHearts = jarHearts;
|
||||
state.jarFlies = jarFlies;
|
||||
state.numCoins = numCoins;
|
||||
state.numKeys = numKeys;
|
||||
state.numBombs = numBombs;
|
||||
state.hasGoldenKey = hasGoldenKey;
|
||||
state.hasGoldenBomb = hasGoldenBomb;
|
||||
state.monkeyPawCounter = (int16_t)monkeyPawCounter;
|
||||
state.totalDamageTaken = (int16_t)totalDamageTaken;
|
||||
state.speedModifier = speedModifier;
|
||||
state.fireDelayModifier = fireDelayModifier;
|
||||
state.damageModifier = damageModifier;
|
||||
state.tearRangeModifier = tearRangeModifier;
|
||||
state.shotSpeedModifier = shotSpeedModifier;
|
||||
state.luckModifier = luckModifier;
|
||||
state.donateLuck = donateLuck;
|
||||
state.potatoPeelerCounter = potatoPeelerCounter;
|
||||
state.potatoPeelerBandageCounter = potatoPeelerBandageCounter;
|
||||
state.brittleBonesUpgrades = brittleBonesUpgrades;
|
||||
state.redStewBonusDuration = redStewBonusDuration;
|
||||
state.brokenHearts = brokenHearts;
|
||||
state.rottenHearts = rottenHearts;
|
||||
state.effectiveSoulCharge = effectiveSoulCharge;
|
||||
state.urnSouls = urnSouls;
|
||||
state.numGigaBombs = numGigaBombs;
|
||||
state.rockBottomDamage = rockBottomDamage;
|
||||
state.rockBottomMaxFireDelay = rockBottomMaxFireDelay;
|
||||
state.rockBottomLuck = rockBottomLuck;
|
||||
state.rockBottomTearRange = rockBottomTearRange;
|
||||
state.rockBottomMoveSpeed = rockBottomMoveSpeed;
|
||||
state.rockBottomShotSpeed = rockBottomShotSpeed;
|
||||
state.reverseEmpressMaxHearts = reverseEmpressMaxHearts;
|
||||
state.reverseSunBoneHearts = reverseSunBoneHearts;
|
||||
state.forgottenBodyRoomIdx = forgottenBodyRoomIdx;
|
||||
state.forgottenBodyPos = forgottenBodyPos;
|
||||
state.maggyHealthDrainCooldown = maggyHealthDrainCooldown;
|
||||
state.echoChamberItems.clear();
|
||||
for (int item : echoChamberItems) state.echoChamberItems.push_back({.id = item});
|
||||
std::copy(bagOfCraftingContent.begin(), bagOfCraftingContent.end(), state.bagOfCraftingContent.begin());
|
||||
std::copy(poopSpellQueue.begin(), poopSpellQueue.end(), state.poopSpellQueue.begin());
|
||||
state.poopMana = poopMana;
|
||||
state.effectiveBloodCharge = effectiveBloodCharge;
|
||||
state.itemCards = itemCards;
|
||||
state.modelingClayEffect = modelingClayEffect;
|
||||
state.keepersSackBonus = keepersSackBonus;
|
||||
state.isLevelStartPending = isLevelStartPending;
|
||||
state.hasCurseMistEffect = hasCurseMistEffect;
|
||||
state.consumablesBackup = consumablesBackup;
|
||||
state.curseMistFamiliars.clear();
|
||||
for (Entity_Familiar* familiar : curseMistFamiliars) familiar->store_backup(&state.curseMistFamiliars.emplace_back());
|
||||
state.curseMistRedHearts = curseMistRedHearts;
|
||||
state.curseMistPocketItems = curseMistPocketItems;
|
||||
state.curseMistTrinkets = curseMistTrinkets;
|
||||
state.isCoopGhost = isCoopGhost;
|
||||
state.ghostPocketItems = ghostPocketItems;
|
||||
state.ghostTrinkets = ghostTrinkets;
|
||||
state.wildCardItemType = wildCardItemType;
|
||||
state.wildCardItem = wildCardItem;
|
||||
state.wildCardVarData = wildCardVarData;
|
||||
state.samsonBerserkCharge = samsonBerserkCharge;
|
||||
state.ibsCharge = ibsCharge;
|
||||
|
||||
Entity* owner = parent.get();
|
||||
if (owner && owner->type == ENTITY_PLAYER) state.parentIndex = static_cast<Entity_Player*>(owner)->glowingHourglassIndex;
|
||||
Entity* esau = darkEsau.get();
|
||||
state.darkEsauHealth = !esau || esau->health <= 0 ? 0 : esau->health;
|
||||
state.proceduralItems = proceduralItems;
|
||||
|
||||
state.edenSpeed = edenSpeed;
|
||||
state.edenFireDelay = edenFireDelay;
|
||||
state.edenDamage = edenDamage;
|
||||
state.edenTearRange = edenTearRange;
|
||||
state.edenShotSpeed = edenShotSpeed;
|
||||
state.edenLuck = edenLuck;
|
||||
state.vampireCharmKills = vampireCharmKills;
|
||||
state.activeItems = activeItems;
|
||||
state.tonsilCounter = tonsilCounter;
|
||||
state.tonsilCount = tonsilCount;
|
||||
state.numLeprosy = numLeprosy;
|
||||
state.playerSpriteScale = playerSpriteScale;
|
||||
if (variant == PLAYER_VARIANT_PLAYER && !isCoopGhost)
|
||||
{
|
||||
state.headScale = headScale;
|
||||
state.bodyScale = bodyScale;
|
||||
}
|
||||
state.pocketItems = pocketItems;
|
||||
state.playerForms = playerForms;
|
||||
state.playerFormsRewarded = playerFormsRewarded;
|
||||
state.collectibleCounts = collectibleCounts;
|
||||
state.voidedCollectibles = voidedCollectibles;
|
||||
state.voidedPassives.clear();
|
||||
for (int passive : voidedPassives) state.voidedPassives.push_back({.id = passive});
|
||||
state.trinkets = trinkets;
|
||||
state.costumes.clear();
|
||||
for (CostumeSpriteDesc& costume : costumeSpriteDescs) state.costumes.push_back({costume.item->id, costume.item->type});
|
||||
state.movingBoxContents = movingBoxContents;
|
||||
rng_seeds_save(collectibleRNGs, state.collectibleRngSeeds);
|
||||
rng_seeds_save(trinketRNGs, state.trinketRngSeeds);
|
||||
rng_seeds_save(pillRNGs, state.pillRngSeeds);
|
||||
rng_seeds_save(cardRNGs, state.cardRngSeeds);
|
||||
state.pillEffectUses = pillEffectUses;
|
||||
state.rUaWizardTimer = rUaWizardTimer;
|
||||
state.bloodLustCounter = bloodLustCounter;
|
||||
state.deadCatLives = deadCatLives;
|
||||
state.friendBallEnemy = friendBallEnemy;
|
||||
state.purityState = purityState;
|
||||
state.immaculateConceptionState = immaculateConceptionState;
|
||||
state.cambionConceptionState = cambionConceptionState;
|
||||
state.conceptionFamiliarFlags = conceptionFamiliarFlags;
|
||||
state.d8DamageModifier = d8DamageModifier;
|
||||
state.d8SpeedModifier = d8SpeedModifier;
|
||||
state.d8RangeModifier = d8RangeModifier;
|
||||
state.d8FireDelayModifier = d8FireDelayModifier;
|
||||
state.goldenHearts = goldenHearts;
|
||||
state.planCKillCountdown = planCKillCountdown;
|
||||
state.imExcitedSpeedupCountdown = imExcitedSpeedupCountdown;
|
||||
|
||||
std::vector<Entity*>& entities = game.room->entityList.updateEL;
|
||||
Entity_Player* twin = static_cast<Entity_Player*>(twinPlayer.get());
|
||||
bool isFirstTwin = !twin || twin->playerIndex == -1 || playerIndex <= twin->playerIndex || twin == this;
|
||||
state.charmedEnemies.clear();
|
||||
for (size_t i = 0; !replacedPlayer && isFirstTwin && i < entities.size(); i++)
|
||||
{
|
||||
if (state.charmedEnemies.size() >= SAVED_CHARMED_ENEMY_LIMIT) break;
|
||||
Entity_NPC* npc = dynamic_cast<Entity_NPC*>(entities[i]);
|
||||
if (!npc || !npc->IsFriendly() || npc->IsBoss()) continue;
|
||||
if (npc->type == ENTITY_CHARGER && npc->variant == 0 && npc->subtype == CHARGER_MY_SHADOW) continue;
|
||||
|
||||
bool isMine = npc->controllerID == -1 ? playerIndex == 0 : controllerIndex == npc->controllerID;
|
||||
if (isMine) state.charmedEnemies.push_back(charmed_enemy_save(*npc));
|
||||
}
|
||||
|
||||
state.familiars.clear();
|
||||
for (Entity* entity : entities)
|
||||
{
|
||||
if (entity->type != ENTITY_FAMILIAR) continue;
|
||||
Entity_Familiar& familiar = *static_cast<Entity_Familiar*>(entity);
|
||||
if (familiar.player == this && is_familiar_saved(familiar, isSaveTemporaryFamiliars))
|
||||
familiar.store_backup(&state.familiars.emplace_back());
|
||||
}
|
||||
state.levelEffectItems = levelEffectItems;
|
||||
bool isBleedingOut = (flags & FLAG_BLEED_OUT) && bleedSource.entity == this;
|
||||
state.bleedOutHealth = isBleedingOut ? bleedOutHealth : 0;
|
||||
state.greedsGulletHearts = greedsGulletHearts;
|
||||
state.greedsGulletOverflow = greedsGulletOverflow;
|
||||
|
||||
state.persistentEffects.clear();
|
||||
for (TemporaryEffect& effect : temporaryEffects.effects)
|
||||
if (effect.item && effect.item->isPersistentEffect)
|
||||
state.persistentEffects.push_back({effect.cooldown, effect.count, effect.item->id, (int)effect.item->type});
|
||||
state.holyMantleStacks = holyMantleStacks;
|
||||
state.ductTapeMode = (uint8_t)ductTapeMode;
|
||||
state.queuedItem = queuedItem;
|
||||
state.temporaryEffects = temporaryEffects.effects;
|
||||
state.strengthMaxHearts = strengthMaxHearts;
|
||||
}
|
||||
+594
-10
@@ -1,17 +1,53 @@
|
||||
#include "game_state.h"
|
||||
#include "game_state_player.h"
|
||||
#include "log.h"
|
||||
#include "persistent_game_data.h"
|
||||
#include "platform.h"
|
||||
#include <algorithm>
|
||||
#include <bit>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
||||
// The header a saved run starts with (version 169, with its terminator), and the key its checksum is scrambled with.
|
||||
constexpr char SAVE_HEADER[] = "ISAACNG_GSR0169";
|
||||
constexpr uint32_t CHECKSUM_KEY = 0x96696996;
|
||||
|
||||
constexpr int ERASED_ENEMY_LIMIT = 255;
|
||||
constexpr int SAVED_COUNTER_MAX = 255;
|
||||
constexpr int SEED_STRING_LENGTH = 9;
|
||||
constexpr int SPECIAL_SEED_BYTES = SPECIAL_SEED_COUNT / 8;
|
||||
constexpr uint16_t ROOM_MAP_EMPTY_RUN = 0x8000;
|
||||
constexpr uint32_t HISTORY_TRINKET = 0x1000000;
|
||||
constexpr uint32_t HISTORY_NEGATIVE = 0x2000000;
|
||||
constexpr uint8_t WRITE_HAS_EXTRA_DATA = 1;
|
||||
constexpr uint8_t WRITE_HAS_CHILD = 2;
|
||||
constexpr uint8_t WRITE_GOLDEN_KEY = 1;
|
||||
constexpr uint8_t WRITE_GOLDEN_BOMB = 2;
|
||||
constexpr uint8_t WRITE_LEVEL_START_PENDING = 2;
|
||||
constexpr uint8_t WRITE_CURSE_MIST = 4;
|
||||
constexpr int ROOM_UNSET_WORDS = 8;
|
||||
|
||||
// An Esau Jr. slot without a player.
|
||||
static GameStatePlayer esau_jr_empty()
|
||||
{
|
||||
GameStatePlayer player;
|
||||
player.playerType = -1;
|
||||
return player;
|
||||
}
|
||||
|
||||
GameState::GameState() : esauJrStates(ESAU_JR_STATE_COUNT, esau_jr_empty()) {}
|
||||
GameState::GameState(const GameState& other) = default;
|
||||
GameState::GameState(GameState&& other) noexcept = default;
|
||||
GameState& GameState::operator=(const GameState& other) = default;
|
||||
GameState& GameState::operator=(GameState&& other) noexcept = default;
|
||||
GameState::~GameState() = default;
|
||||
|
||||
// 009c79a0 Empties the saved run and drops both availabilities, keeping the files it is saved to.
|
||||
void GameState::Clear()
|
||||
{
|
||||
*this = {.rerunPath = std::move(rerunPath), .savePath = std::move(savePath)};
|
||||
GameState cleared;
|
||||
cleared.rerunPath = std::move(rerunPath);
|
||||
cleared.savePath = std::move(savePath);
|
||||
*this = std::move(cleared);
|
||||
}
|
||||
|
||||
// 009c8350 Removes the saved run's file, warning when there is none named, and empties the run.
|
||||
@@ -31,28 +67,479 @@ void GameState::DeleteRerun()
|
||||
}
|
||||
|
||||
// A saved run as it is written: its bytes, and the checksum (CRC-32 from Checksum's seed) over all of them after the
|
||||
// header.
|
||||
// header. Each part of the run has its writer, in the original's order and widths.
|
||||
// The checksum folds bytes one at a time, so a block written at once sums as its values written one by one.
|
||||
struct StateWriter
|
||||
{
|
||||
std::vector<uint8_t> bytes;
|
||||
Checksum checksum;
|
||||
|
||||
void write_bytes(std::span<const uint8_t> data)
|
||||
// Appends bytes and folds them into the checksum.
|
||||
void bytes_write(std::span<const uint8_t> data)
|
||||
{
|
||||
bytes.insert(bytes.end(), data.begin(), data.end());
|
||||
checksum.Update(data);
|
||||
}
|
||||
|
||||
template <typename Value> void write(Value value) { write_bytes({(const uint8_t*)&value, sizeof(Value)}); }
|
||||
// Appends a value as its bytes.
|
||||
template <typename Value> void write(Value value) { bytes_write({(const uint8_t*)&value, sizeof(Value)}); }
|
||||
|
||||
// Appends each value of a list as a type of the original's width.
|
||||
template <typename Width, typename List> void each_write(const List& values)
|
||||
{
|
||||
for (auto value : values) write((Width)value);
|
||||
}
|
||||
|
||||
// 009d84d0 Appends a list's length and its values as 32-bit words.
|
||||
template <typename List> void list_write(const List& values)
|
||||
{
|
||||
write((uint32_t)values.size());
|
||||
each_write<uint32_t>(values);
|
||||
}
|
||||
|
||||
// 009c85d0 Appends a bit list's length (16 bits), then its bits eight to a byte from the lowest.
|
||||
template <typename Bits> void bits_write(const Bits& bits)
|
||||
{
|
||||
uint16_t count = (uint16_t)bits.size();
|
||||
uint8_t packed = 0;
|
||||
|
||||
write(count);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (bits[i]) packed |= 1 << (i % 8);
|
||||
if (i % 8 < 7) continue;
|
||||
write(packed);
|
||||
packed = 0;
|
||||
}
|
||||
if (count % 8) write(packed);
|
||||
}
|
||||
|
||||
void entity_write(const EntitySaveState& entity);
|
||||
void room_write(const SavedRoom& room);
|
||||
void co_player_write(const CoPlayerState& player);
|
||||
void consumables_write(const ConsumableData& data);
|
||||
void familiars_write(const std::vector<FamiliarData>& familiars);
|
||||
void pockets_write(const std::array<PocketItem, POCKET_SLOT_COUNT>& pockets);
|
||||
void player_write(const GameStatePlayer& player);
|
||||
void item_pool_write(const GameStateItemPool& pool);
|
||||
void score_write(const ScoreRecord& score);
|
||||
};
|
||||
|
||||
// 009c88e0 Writes a saved entity: its kind, storage fields and seeds, then which of the extra bytes and the carried
|
||||
// entity follow, and those.
|
||||
void StateWriter::entity_write(const EntitySaveState& entity)
|
||||
{
|
||||
for (uint32_t value : {(uint32_t)entity.type, (uint32_t)entity.variant, (uint32_t)entity.subtype,
|
||||
entity.intStorage1, entity.intStorage2, entity.intStorage3})
|
||||
write(value);
|
||||
write(entity.byteStorage);
|
||||
write(entity.intStorage4);
|
||||
write(entity.intStorage5);
|
||||
write((uint8_t)entity.boolStorage1);
|
||||
for (uint32_t value : {entity.intStorage6, std::bit_cast<uint32_t>(entity.targetPosition.x),
|
||||
std::bit_cast<uint32_t>(entity.targetPosition.y), entity.intStorage7, entity.initSeed,
|
||||
entity.dropSeed, (uint32_t)entity.spawnerType, (uint32_t)entity.spawnerVariant})
|
||||
write(value);
|
||||
write(entity.int64Storage);
|
||||
write((uint8_t)entity.boolStorage2);
|
||||
write(entity.floatStorage1);
|
||||
write(entity.floatStorage2);
|
||||
write(entity.gridSpawnIdx);
|
||||
write(entity.floatStorage3);
|
||||
write(entity.intStorage8);
|
||||
|
||||
write((uint8_t)((entity.extraData ? WRITE_HAS_EXTRA_DATA : 0) | (entity.child ? WRITE_HAS_CHILD : 0)));
|
||||
if (entity.extraData) bytes_write(*entity.extraData);
|
||||
if (entity.child) entity_write(*entity.child);
|
||||
}
|
||||
|
||||
// 009c8d20 Writes a saved room: its config (009c87e0), its place on the map and doors, what happened in it, its seeds,
|
||||
// its grid cells (with the details of the ones holding something), its saved entities, restricted cells and effects,
|
||||
// its shop indices, group and Tainted Keeper's coin count.
|
||||
// A merged config's two 16-bit indices are the bytes of its variant word, so every config is three words.
|
||||
// The original's words at 0x94..0xab are never set, so they are written as zeros.
|
||||
void StateWriter::room_write(const SavedRoom& room)
|
||||
{
|
||||
const RoomDescriptor& desc = room.desc;
|
||||
|
||||
for (uint32_t value : {room.config.packed, room.config.type, room.config.variant}) write(value);
|
||||
for (int value : {desc.gridIndex, desc.safeGridIndex, desc.listIndex}) write((uint16_t)value);
|
||||
write((uint8_t)desc.dimension);
|
||||
write(desc.allowedDoors);
|
||||
each_write<uint32_t>(desc.doors);
|
||||
for (uint32_t value : {desc.displayFlags, (uint32_t)desc.visitedCount, desc.flags}) write(value);
|
||||
write(desc.clearCount);
|
||||
write(desc.totalMoneySpent);
|
||||
for (uint32_t value : {(uint32_t)desc.greedSubType, (uint32_t)desc.pitsCount, desc.decorationSeed, desc.spawnSeed,
|
||||
desc.awardSeed, desc.bossDeathSeed})
|
||||
write(value);
|
||||
|
||||
for (const GridEntityDesc& cell : desc.savedGridEntities)
|
||||
{
|
||||
write((uint16_t)cell._type);
|
||||
if (!cell._type) continue;
|
||||
write(cell._variant);
|
||||
write(cell._state);
|
||||
write((uint16_t)cell._spawnCount);
|
||||
write(cell._spawnSeed);
|
||||
write(cell._variableSeed);
|
||||
write(cell._varData);
|
||||
}
|
||||
|
||||
write((uint32_t)desc.savedEntities.size());
|
||||
for (const EntitySaveState& entity : desc.savedEntities) entity_write(entity);
|
||||
list_write(desc.restrictedGridIndexes);
|
||||
write((uint32_t)desc.savedEffects.size());
|
||||
for (const EntitySaveState& entity : desc.savedEffects) entity_write(entity);
|
||||
|
||||
write(desc.shopItemDiscountIdx);
|
||||
write(desc.shopItemIdx);
|
||||
each_write<uint16_t>(std::array<uint16_t, ROOM_UNSET_WORDS>{});
|
||||
each_write<uint8_t>(std::array<uint8_t, ROOM_UNSET_WORDS>{});
|
||||
write(desc.group);
|
||||
write(desc.tKeeperCoinSpawns);
|
||||
}
|
||||
|
||||
// 009d0100 Writes a co-op baby or sub player: its character and hearts (16 bits each), then its black hearts and bone
|
||||
// heart mask, then its broken and rotten hearts.
|
||||
void StateWriter::co_player_write(const CoPlayerState& player)
|
||||
{
|
||||
for (int value : {player.playerType, player.redHearts, player.maxHearts, player.soulHearts, player.eternalHearts,
|
||||
player.goldenHearts, 0, player.boneHearts})
|
||||
write((uint16_t)value);
|
||||
write(player.blackHearts);
|
||||
write(player.boneHeartsMask);
|
||||
write((uint16_t)player.brokenHearts);
|
||||
write((uint16_t)player.rottenHearts);
|
||||
}
|
||||
|
||||
// 009d0440 Writes the consumables Curse of the Mist set aside (16 bits each) and the golden key and bomb.
|
||||
// The original loses the golden key's bit when the golden bomb is set too, which this keeps.
|
||||
void StateWriter::consumables_write(const ConsumableData& data)
|
||||
{
|
||||
for (int value : {data.coins, data.keys, data.bombs}) write((uint16_t)value);
|
||||
write((uint8_t)(data.isGoldenBomb ? WRITE_GOLDEN_BOMB : data.isGoldenKey ? WRITE_GOLDEN_KEY : 0));
|
||||
for (int value : {data.soulCharges, data.gigaBombs, data.poopMana, data.bloodCharges}) write((uint16_t)value);
|
||||
}
|
||||
|
||||
// Writes a list of familiars, each with its seeds, kind, counters, offset and health.
|
||||
void StateWriter::familiars_write(const std::vector<FamiliarData>& familiars)
|
||||
{
|
||||
write((uint32_t)familiars.size());
|
||||
for (const FamiliarData& familiar : familiars)
|
||||
{
|
||||
for (int value : {(int)familiar.initSeed, familiar.variant, familiar.subtype, familiar.coins, familiar.hearts,
|
||||
familiar.keys, familiar.state, familiar.roomClearCount})
|
||||
write(value);
|
||||
write(familiar.formationTargetOffset.x);
|
||||
write(familiar.formationTargetOffset.y);
|
||||
write(familiar.health);
|
||||
write(familiar.dropSeed);
|
||||
write((uint8_t)familiar.isNotCountedAsFollower);
|
||||
write((uint8_t)familiar.isSubtype55555);
|
||||
}
|
||||
}
|
||||
|
||||
// Writes pocket slots, each as its kind (a byte) and id.
|
||||
void StateWriter::pockets_write(const std::array<PocketItem, POCKET_SLOT_COUNT>& pockets)
|
||||
{
|
||||
for (const PocketItem& pocket : pockets)
|
||||
{
|
||||
write((uint8_t)pocket.type);
|
||||
write(pocket.id);
|
||||
}
|
||||
}
|
||||
|
||||
// The bits of a history entry: a trinket's flag and a negative id's, over the id's magnitude.
|
||||
static uint32_t history_id_pack(const HistoryItem& item)
|
||||
{
|
||||
uint32_t flags = (item.isTrinket ? HISTORY_TRINKET : 0) | (item.id < 0 ? HISTORY_NEGATIVE : 0);
|
||||
return (uint32_t)std::abs(item.id) | flags;
|
||||
}
|
||||
|
||||
// A count the original saves as a byte, clamped to one.
|
||||
static uint8_t counter_byte(int value)
|
||||
{
|
||||
return (uint8_t)std::clamp(value, 0, SAVED_COUNTER_MAX);
|
||||
}
|
||||
|
||||
// 009d45c0 Writes a saved player in the original's order: health and consumables, stats, items and their charges,
|
||||
// pockets, forms, item lists and RNGs, PlayerManager's babies, charmed enemies and boxed entities, familiars and co-op
|
||||
// babies, counters, persistent effects, crafting and spells, Curse of the Mist and ghost backups, history, inventory and
|
||||
// the Echo Chamber's items (twice, the second time as words).
|
||||
// The Echo Chamber's type is written as a word whose padding the original leaves unset. It is zero here.
|
||||
void StateWriter::player_write(const GameStatePlayer& player)
|
||||
{
|
||||
for (int value : {player.playerType, player.redHearts, player.maxHearts, player.soulHearts, player.blackHearts,
|
||||
player.eternalHearts, player.jarHearts, player.jarFlies, player.numCoins, player.numKeys,
|
||||
player.numBombs})
|
||||
write(value);
|
||||
write((uint8_t)player.hasGoldenKey);
|
||||
write((uint8_t)player.hasGoldenBomb);
|
||||
write(player.monkeyPawCounter);
|
||||
write(player.totalDamageTaken);
|
||||
write((uint8_t)(player.isHolyMantle | (player.isLevelStartPending ? WRITE_LEVEL_START_PENDING : 0) |
|
||||
(player.hasCurseMistEffect ? WRITE_CURSE_MIST : 0)));
|
||||
for (int16_t value : {player.tonsilCounter, player.tonsilCount, player.numLeprosy}) write(value);
|
||||
for (int value : {player.planCKillCountdown, (int)player.imExcitedSpeedupCountdown, player.lastPillColor,
|
||||
player.boneHearts, player.boneHeartsMask, player.speedModifier, player.fireDelayModifier,
|
||||
player.damageModifier, player.tearRangeModifier, player.shotSpeedModifier, player.luckModifier,
|
||||
player.donateLuck, player.potatoPeelerCounter, player.potatoPeelerBandageCounter})
|
||||
write(value);
|
||||
for (float value : {player.edenSpeed, player.edenFireDelay, player.edenDamage, player.edenTearRange,
|
||||
player.edenShotSpeed, player.edenLuck})
|
||||
write(value);
|
||||
write(player.vampireCharmKills);
|
||||
write(player.killCounter);
|
||||
|
||||
for (const ActiveItemDesc& active : player.activeItems)
|
||||
for (int value : {active.item, active.unknown, active.charge, active.batteryCharge, active.partialCharge,
|
||||
active.varData})
|
||||
write(value);
|
||||
for (float value : {player.playerSpriteScale.x, player.playerSpriteScale.y, player.headScale.x,
|
||||
player.headScale.y, player.bodyScale.x, player.bodyScale.y})
|
||||
write(value);
|
||||
pockets_write(player.pocketItems);
|
||||
each_write<int>(player.playerForms);
|
||||
write(player.playerFormsRewarded);
|
||||
list_write(player.collectibleCounts);
|
||||
list_write(player.voidedCollectibles);
|
||||
write((uint32_t)player.voidedPassives.size());
|
||||
for (const VoidedPassive& passive : player.voidedPassives)
|
||||
{
|
||||
write((uint16_t)passive.id);
|
||||
write((uint16_t)passive.value);
|
||||
}
|
||||
each_write<uint32_t>(player.trinkets);
|
||||
write((uint32_t)player.costumes.size());
|
||||
for (const CostumeItem& costume : player.costumes)
|
||||
{
|
||||
write(costume.type);
|
||||
write(costume.id);
|
||||
}
|
||||
for (auto* seeds : {&player.collectibleRngSeeds, &player.trinketRngSeeds, &player.pillRngSeeds,
|
||||
&player.cardRngSeeds})
|
||||
list_write(*seeds);
|
||||
list_write(player.pillEffectUses);
|
||||
|
||||
write(player.glitchBabySeed);
|
||||
write(player.randomBabyCount);
|
||||
each_write<int>(player.randomBabies);
|
||||
write(player.rUaWizardTimer);
|
||||
write(player.bloodLustCounter);
|
||||
write(player.deadCatLives);
|
||||
const EntityDesc& ball = player.friendBallEnemy;
|
||||
for (uint32_t value : {ball.type, ball.variant, ball.subtype, (uint32_t)ball.championId}) write(value);
|
||||
write(ball.health);
|
||||
write(ball.maxHealth);
|
||||
write((uint32_t)player.charmedEnemies.size());
|
||||
for (const EntityDesc& enemy : player.charmedEnemies)
|
||||
{
|
||||
for (uint32_t value : {enemy.type, enemy.variant, enemy.subtype, (uint32_t)enemy.championId}) write(value);
|
||||
write(enemy.health);
|
||||
write(enemy.maxHealth);
|
||||
write((uint8_t)enemy.isPlayerControlled);
|
||||
}
|
||||
write((uint32_t)player.movingBoxContents.size());
|
||||
for (const EntitySaveState& entity : player.movingBoxContents) entity_write(entity);
|
||||
|
||||
for (int value : {player.purityState, player.immaculateConceptionState, player.cambionConceptionState,
|
||||
(int)player.conceptionFamiliarFlags})
|
||||
write(value);
|
||||
for (float value : {player.d8DamageModifier, player.d8SpeedModifier, player.d8RangeModifier,
|
||||
player.d8FireDelayModifier})
|
||||
write(value);
|
||||
for (int value : {player.goldenHearts, 0, 0}) write(value);
|
||||
familiars_write(player.familiars);
|
||||
write((uint8_t)player.coopBabies.size());
|
||||
for (const CoPlayerState& baby : player.coopBabies) co_player_write(baby);
|
||||
write((uint8_t)player.subPlayer.has_value());
|
||||
if (player.subPlayer) co_player_write(*player.subPlayer);
|
||||
|
||||
write(player.brittleBonesUpgrades);
|
||||
write(player.bleedOutHealth);
|
||||
write((uint16_t)player.greedsGulletHearts);
|
||||
write(player.greedsGulletOverflow);
|
||||
for (int value : {player.redStewBonusDuration, player.brokenHearts, player.rottenHearts,
|
||||
player.effectiveSoulCharge})
|
||||
write(value);
|
||||
each_write<int16_t>(player.candyHeartStatUps);
|
||||
each_write<int16_t>(player.soulLocketStatUps);
|
||||
write(player.unknownCounter);
|
||||
for (int value : {player.soulCharge, player.numGigaBombs, (int)player.urnSouls}) write(counter_byte(value));
|
||||
for (float value : {player.rockBottomMoveSpeed, player.rockBottomMaxFireDelay, player.rockBottomDamage,
|
||||
player.rockBottomTearRange, player.rockBottomShotSpeed, player.rockBottomLuck})
|
||||
write(value);
|
||||
write(player.reverseEmpressMaxHearts);
|
||||
write((uint16_t)player.persistentEffects.size());
|
||||
for (const PersistentEffect& effect : player.persistentEffects)
|
||||
for (int value : {effect.type, effect.id, effect.count, effect.cooldown}) write(value);
|
||||
write(player.reverseSunBoneHearts);
|
||||
write(player.unknownTimer);
|
||||
write((uint16_t)player.unknownValue);
|
||||
write(player.forgottenBodyRoomIdx);
|
||||
write(player.forgottenBodyPos.x);
|
||||
write(player.forgottenBodyPos.y);
|
||||
write(player.lastCollectibleFrame);
|
||||
write(player.maggyHealthDrainCooldown);
|
||||
|
||||
uint8_t echoCount = (uint8_t)player.echoChamberItems.size();
|
||||
write(echoCount);
|
||||
for (int i = 0; i < echoCount; i++)
|
||||
{
|
||||
write((uint8_t)player.echoChamberItems[i].type);
|
||||
write(player.echoChamberItems[i].id);
|
||||
}
|
||||
each_write<uint8_t>(player.bagOfCraftingContent);
|
||||
write(player.bagOfCraftingOutput);
|
||||
write(player.bagOfCraftingPool);
|
||||
std::span<const uint8_t> spells = player.poopSpellQueue;
|
||||
bytes_write(spells.first(POOP_SPELL_QUEUE_SIZE));
|
||||
write((uint8_t)(POOP_SPELL_SLOTS - POOP_SPELL_QUEUE_SIZE));
|
||||
bytes_write(spells.subspan(POOP_SPELL_QUEUE_SIZE));
|
||||
write(player.poopSpellCounter);
|
||||
write(player.poopMana);
|
||||
write(player.poopSpellFloat);
|
||||
write(player.effectiveBloodCharge);
|
||||
for (int value : {player.isBackupPlayer ? -1 : 0, player.parentIndex, 0}) write(value);
|
||||
write(player.darkEsauHealth);
|
||||
|
||||
consumables_write(player.consumablesBackup);
|
||||
familiars_write(player.curseMistFamiliars);
|
||||
write(player.curseMistRedHearts);
|
||||
pockets_write(player.curseMistPocketItems);
|
||||
each_write<uint32_t>(player.curseMistTrinkets);
|
||||
write((uint8_t)player.isCoopGhost);
|
||||
pockets_write(player.ghostPocketItems);
|
||||
each_write<uint32_t>(player.ghostTrinkets);
|
||||
write(player.samsonBerserkCharge);
|
||||
write(player.ibsCharge);
|
||||
write(player.holyMantleStacks);
|
||||
write(player.ductTapeMode);
|
||||
write(player.controllerIndex);
|
||||
write((uint8_t)player.itemCards.size());
|
||||
each_write<int>(std::span(player.itemCards).first((uint8_t)player.itemCards.size()));
|
||||
write(player.modelingClayEffect);
|
||||
write(player.keepersSackBonus);
|
||||
write(player.wildCardItemType);
|
||||
if (player.wildCardItemType != WILD_CARD_NONE)
|
||||
{
|
||||
write(player.wildCardItem);
|
||||
write(player.wildCardVarData);
|
||||
}
|
||||
|
||||
write((uint32_t)player.history.size());
|
||||
for (const HistoryItem& item : player.history)
|
||||
for (uint32_t value : {history_id_pack(item), (uint32_t)item.levelStage, (uint32_t)item.stageType,
|
||||
(uint32_t)item.roomType, (uint32_t)item.itemPoolType, (uint32_t)item.time})
|
||||
write(value);
|
||||
auto last = std::find_if(player.inventory.rbegin(), player.inventory.rend(), [](int id) { return id >= 0; });
|
||||
uint8_t inventoryCount = (uint8_t)(player.inventory.rend() - last);
|
||||
write(inventoryCount);
|
||||
each_write<uint16_t>(std::span(player.inventory).first(inventoryCount));
|
||||
write((uint8_t)player.levelEffectItems.size());
|
||||
each_write<int>(std::span(player.levelEffectItems).first((uint8_t)player.levelEffectItems.size()));
|
||||
write((uint32_t)player.proceduralItems.size());
|
||||
for (auto [key, value] : player.proceduralItems)
|
||||
{
|
||||
write((uint16_t)key);
|
||||
write((uint16_t)value);
|
||||
}
|
||||
write((uint32_t)player.echoChamberItems.size());
|
||||
for (const PocketItem& item : player.echoChamberItems)
|
||||
{
|
||||
write(item.id);
|
||||
write((uint32_t)item.type);
|
||||
}
|
||||
}
|
||||
|
||||
// 009cec80 Writes the item pools: each pool's weights, the Bible's chances, the seeds and the last pool, the removed
|
||||
// collectibles and the trinkets still in the pool (a byte each), the pill colors and the Genesis counts.
|
||||
void StateWriter::item_pool_write(const GameStateItemPool& pool)
|
||||
{
|
||||
for (const std::vector<float>& weights : pool.poolsItemWeights)
|
||||
{
|
||||
write((uint32_t)weights.size());
|
||||
each_write<float>(weights);
|
||||
}
|
||||
each_write<int>(pool.bibleUpgrades);
|
||||
for (uint32_t value : {pool.seed, (uint32_t)pool.lastPool, pool.itemPoolRNGseed, pool.trinketPoolRNGseed})
|
||||
write(value);
|
||||
write(pool.unkFloat674);
|
||||
write(pool.unkFloat678);
|
||||
for (const std::vector<bool>* bits : {&pool.removedCollectibles, &pool.trinketPoolItems})
|
||||
{
|
||||
write((uint32_t)bits->size());
|
||||
each_write<uint8_t>(*bits);
|
||||
}
|
||||
each_write<int>(pool.pillEffects);
|
||||
each_write<uint8_t>(pool.identifiedPillEffects);
|
||||
each_write<uint16_t>(pool.remainingGenesisItems);
|
||||
}
|
||||
|
||||
// 009d77e0 Writes the score's record: the furthest floor and its time, the points, the ending, the rooms entered and
|
||||
// cleared, the boss challenges and angels, and the floors finished and played again.
|
||||
void StateWriter::score_write(const ScoreRecord& score)
|
||||
{
|
||||
for (int value : {score.runTimeLevel, score.runTimeLevelType, score.runTime, score.pickupPoints, score.enemyPoints,
|
||||
(int)score.runEnding})
|
||||
write(value);
|
||||
for (const std::vector<RoomScore>* rooms : {&score.visitedRooms, &score.clearedRooms})
|
||||
{
|
||||
write((uint32_t)rooms->size());
|
||||
for (const RoomScore& room : *rooms)
|
||||
{
|
||||
write(room.type);
|
||||
write((uint8_t)room.isRedRoom);
|
||||
write(room.multiplier);
|
||||
}
|
||||
}
|
||||
write(score.bossChallengesCleared);
|
||||
write(score.angelsKilled);
|
||||
for (const std::vector<StageVisit>* stages : {&score.finishedStages, &score.replayedStages})
|
||||
{
|
||||
write((uint32_t)stages->size());
|
||||
for (const StageVisit& visit : *stages)
|
||||
{
|
||||
write(visit.stage);
|
||||
write(visit.stageType);
|
||||
write((uint8_t)visit.isAscent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The map's cells packed for saving: each room index, and each run of empty cells as its length minus one over
|
||||
// ROOM_MAP_EMPTY_RUN.
|
||||
static std::vector<uint16_t> room_map_pack(const std::array<int, ROOM_MAP_CELLS>& roomMap)
|
||||
{
|
||||
std::vector<uint16_t> packed;
|
||||
uint16_t emptyRun = 0;
|
||||
|
||||
for (int roomIdx : roomMap)
|
||||
{
|
||||
if (roomIdx < 0)
|
||||
{
|
||||
emptyRun++;
|
||||
continue;
|
||||
}
|
||||
if (emptyRun) packed.push_back((emptyRun - 1) | ROOM_MAP_EMPTY_RUN);
|
||||
emptyRun = 0;
|
||||
packed.push_back((uint16_t)roomIdx);
|
||||
}
|
||||
if (emptyRun) packed.push_back((emptyRun - 1) | ROOM_MAP_EMPTY_RUN);
|
||||
return packed;
|
||||
}
|
||||
|
||||
// 009c9340 Writes the saved run in the original's format: the unchecked header, then the run's rules, flags and
|
||||
// counters, the ambush and the score, the floor, the players, the pools, the seeds, the histories, the Ascent's stages
|
||||
// and the versus rules, closed by the checksum of everything after the header, scrambled.
|
||||
// The format is written up to the score sheet so far. The rest waits for the floor's and the players' states.
|
||||
// counters, the ambush and the score, the floor and its rooms, the players and the Esau Jr. players, the pools, the seed
|
||||
// and the special seeds, the histories, the Ascent's stages and the versus rules, closed by the checksum of everything
|
||||
// after the header, scrambled. More than 255 erased enemies are cut to 255, as the original does.
|
||||
// The Death Certificate floor's way back, which Game does not keep yet, is written as the original's defaults.
|
||||
// The original's rooms are a fixed array, so a state Level never stored writes default rooms.
|
||||
std::vector<uint8_t> GameState::write()
|
||||
{
|
||||
StateWriter writer;
|
||||
rooms.resize(ROOM_DESCRIPTOR_COUNT);
|
||||
writer.bytes.assign(SAVE_HEADER, SAVE_HEADER + sizeof(SAVE_HEADER));
|
||||
|
||||
writer.write(challenge);
|
||||
@@ -62,7 +549,6 @@ std::vector<uint8_t> GameState::write()
|
||||
writer.write(difficulty);
|
||||
writer.write((uint16_t)gameStateFlags.size());
|
||||
for (size_t i = 0; i < gameStateFlags.size(); i++) writer.write((uint8_t)gameStateFlags[i]);
|
||||
|
||||
for (int counter : {lastDevilRoomStage, treasureRoomsVisited, planetariumsVisited, stagesWithoutHeartsPicked,
|
||||
stagesWithoutDamage, devilRoomDeals, shopVisits, donationModGreed, donationModAngel,
|
||||
reviveMachineCoinsLeft, reviveMachineUses, bossRushParTime, blueWombParTime, frameCount,
|
||||
@@ -70,7 +556,105 @@ std::vector<uint8_t> GameState::write()
|
||||
writer.write(counter);
|
||||
writer.write((uint8_t)isAmbushActive);
|
||||
writer.write(ambushWave);
|
||||
reconstruction_missing("GameState::write 009c9340: the score sheet (write_score_sheet 009d77e0) and on");
|
||||
writer.score_write(scoreSheet);
|
||||
|
||||
for (uint32_t value : {stage, stageType, (uint32_t)startingRoomIdx, (uint32_t)lastBossRoomListIdx, curses,
|
||||
dungeonPlacementSeed, devilAngelRoomSeed, std::bit_cast<uint32_t>(angelRoomChance)})
|
||||
writer.write(value);
|
||||
for (bool flag : {isHeartPicked, isDevilRoomDisabled, isCanSeeEverything, isBossChallenge})
|
||||
writer.write((uint8_t)flag);
|
||||
writer.write((uint16_t)levelStateFlags.size());
|
||||
for (size_t i = 0; i < levelStateFlags.size(); i++) writer.write((uint8_t)levelStateFlags[i]);
|
||||
writer.write(greedModeWave);
|
||||
writer.each_write<uint32_t>(greedWaveSeeds);
|
||||
for (int value : {(int)greedModeTreasureRoomIdx, greedLastBeatenWave, greedLastPaidWave}) writer.write(value);
|
||||
writer.each_write<int>(nightmareStageIcons);
|
||||
|
||||
writer.write((uint32_t)mergedRoomConfigs.size());
|
||||
for (const RoomConfigRef& config : mergedRoomConfigs)
|
||||
for (uint32_t value : {config.packed, config.type, config.variant}) writer.write(value);
|
||||
writer.write(roomCount);
|
||||
for (int i = 0; i < roomCount; i++) writer.room_write(rooms[i]);
|
||||
for (int i = ROOM_MAP_CELLS; i < ROOM_DESCRIPTOR_COUNT; i++) writer.room_write(rooms[i]);
|
||||
std::vector<uint16_t> packedMap = room_map_pack(roomMap);
|
||||
writer.write((uint16_t)packedMap.size());
|
||||
writer.each_write<uint16_t>(packedMap);
|
||||
|
||||
writer.write(currentRoomIdx);
|
||||
writer.write(currentDimensionIdx);
|
||||
writer.write(lastRoomDimensionIdx);
|
||||
writer.write(lastRoomIdx);
|
||||
writer.write(brokenWatchState);
|
||||
writer.write(slowdownDuration);
|
||||
writer.write(dungeonReturnPosition.x);
|
||||
writer.write(dungeonReturnPosition.y);
|
||||
for (int value : {dungeonReturnRoomIndex, -1, 0, 0}) writer.write(value);
|
||||
writer.write((uint8_t)0);
|
||||
writer.write((uint8_t)0);
|
||||
writer.write(enterDoor);
|
||||
for (const VentricleRazorPortal& portal : ventricleRazorPortals)
|
||||
{
|
||||
writer.write(portal.roomIndex);
|
||||
writer.write(portal.gridIndex);
|
||||
writer.write((uint8_t)portal.isMarked);
|
||||
}
|
||||
writer.write(bombPickupsSpawned);
|
||||
writer.write(0);
|
||||
writer.write((uint8_t)0);
|
||||
|
||||
writer.write((uint8_t)players.size());
|
||||
for (const GameStatePlayer& player : players) writer.player_write(player);
|
||||
writer.write((uint8_t)esauJrStates.size());
|
||||
for (const GameStatePlayer& player : esauJrStates)
|
||||
{
|
||||
writer.write((uint8_t)(player.playerType != -1));
|
||||
if (player.playerType != -1) writer.player_write(player);
|
||||
}
|
||||
writer.item_pool_write(itemPool);
|
||||
|
||||
if (!seeds.gameStartSeed) log_printf(LOG_ASSERT, "Error: Game Start Seed was not set.\n");
|
||||
std::string seedString = Seeds::Seed2String(seeds.gameStartSeed);
|
||||
seedString.resize(SEED_STRING_LENGTH);
|
||||
writer.bytes_write({(const uint8_t*)seedString.data(), seedString.size()});
|
||||
std::array<uint8_t, SPECIAL_SEED_BYTES> specialSeeds{};
|
||||
for (int i = 0; i < SPECIAL_SEED_COUNT; i++)
|
||||
if (seeds.HasSeedEffect(i)) specialSeeds[i / 8] |= 1 << (i % 8);
|
||||
writer.write((uint8_t)specialSeeds.size());
|
||||
writer.bytes_write(specialSeeds);
|
||||
for (uint32_t value : {playerManagerSeed, fortuneSeed, (uint32_t)lastLevelWithDamage}) writer.write(value);
|
||||
|
||||
writer.write((uint32_t)encounteredBosses.size());
|
||||
for (const BossId& boss : encounteredBosses)
|
||||
{
|
||||
writer.write(boss.type);
|
||||
writer.write(boss.variant);
|
||||
}
|
||||
writer.bits_write(bossPool.removedBosses);
|
||||
writer.write((uint16_t)bossPool.rngSeeds.size());
|
||||
writer.each_write<uint32_t>(bossPool.rngSeeds);
|
||||
writer.write(magicSkinUses);
|
||||
if (erasedEntities.size() > ERASED_ENEMY_LIMIT) erasedEntities.resize(ERASED_ENEMY_LIMIT);
|
||||
writer.write((uint8_t)erasedEntities.size());
|
||||
for (const ErasedEnemy& enemy : erasedEntities)
|
||||
for (int value : {enemy.type, enemy.variant, enemy.subtype}) writer.write(value);
|
||||
writer.write((uint16_t)pixelationTimer);
|
||||
writer.write((uint16_t)pixelationDuration);
|
||||
writer.write((uint8_t)isAscent);
|
||||
|
||||
for (const BackwardsStageDesc& backwards : backwardsStages)
|
||||
{
|
||||
writer.write((uint8_t)backwards.stageType);
|
||||
for (const std::vector<SavedRoom>* stageRooms : {&backwards.bossRooms, &backwards.treasureRooms})
|
||||
{
|
||||
writer.write((uint8_t)stageRooms->size());
|
||||
for (const SavedRoom& room : *stageRooms) writer.room_write(room);
|
||||
}
|
||||
writer.write((uint8_t)backwards.isXL);
|
||||
}
|
||||
writer.write((uint16_t)deathCertificateExitTimer);
|
||||
writer.list_write(proceduralItemSeeds);
|
||||
writer.write(versusRules);
|
||||
writer.list_write(versusPlayers);
|
||||
|
||||
checksum = writer.checksum.value_get();
|
||||
uint32_t sealed = checksum ^ CHECKSUM_KEY;
|
||||
|
||||
+98
-7
@@ -1,8 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "boss_pool.h"
|
||||
#include "entity_save_state.h"
|
||||
#include "item_pool.h"
|
||||
#include "level.h"
|
||||
#include "nightmare_scene.h"
|
||||
#include "persistent_game_data.h"
|
||||
#include "score_sheet.h"
|
||||
#include "seeds.h"
|
||||
#include <array>
|
||||
@@ -13,6 +16,8 @@
|
||||
#include <vector>
|
||||
|
||||
constexpr int BACKWARDS_STAGE_COUNT = 7;
|
||||
constexpr int ESAU_JR_STATE_COUNT = 4;
|
||||
constexpr int LEVEL_STATE_FLAG_COUNT = 26;
|
||||
// How many of the run's state flags a saved run keeps.
|
||||
constexpr int SAVED_GAME_STATE_FLAG_COUNT = 53;
|
||||
|
||||
@@ -31,12 +36,41 @@ struct ErasedEnemy
|
||||
int variant = 0;
|
||||
};
|
||||
|
||||
// A room config as a saved run names it (GameStateRoomConfig): its stage and mode packed with two of its flags, then
|
||||
// its type and variant. A merged room is a flag with its shape, and its halves' indices among the merged configs packed
|
||||
// in the last word.
|
||||
struct RoomConfigRef
|
||||
{
|
||||
uint32_t packed = 0;
|
||||
uint32_t type = 0;
|
||||
uint32_t variant = 0;
|
||||
};
|
||||
|
||||
// A saved room: its descriptor and the config it was laid out from.
|
||||
struct SavedRoom
|
||||
{
|
||||
RoomDescriptor desc;
|
||||
RoomConfigRef config;
|
||||
};
|
||||
|
||||
// The rooms a Backwards Path stage keeps for the Ascent: its boss and treasure rooms with their configs, its stage type
|
||||
// and whether it was XL. Copies (006f8a40) are the defaults.
|
||||
struct BackwardsStageDesc
|
||||
{
|
||||
std::vector<SavedRoom> bossRooms;
|
||||
std::vector<SavedRoom> treasureRooms;
|
||||
uint32_t stageType = 0;
|
||||
bool isXL = false;
|
||||
};
|
||||
|
||||
// A save slot's saved run (gamestate<slot>.dat), to continue from the menus, and its rerun (rep+rerunstate<slot>.dat),
|
||||
// the last run's character and seed to play again.
|
||||
// Modelled so far: what the menus read and what Game::store_game_state copies itself (the run's rules, seeds,
|
||||
// counters and histories, the boss pools, the Ascent's saved stages). The floor's rooms and the players come with
|
||||
// Level's and PlayerManager's stores, and the file format with read and write.
|
||||
// Construction and destruction (009c73c0, 009c7800) are the defaults.
|
||||
// It keeps the run's rules, seeds, counters and histories, the floor and its rooms, the players, the pools, the
|
||||
// Ascent's saved stages and the versus rules, as Game::store_game_state copies them, and write saves them in the
|
||||
// original's format.
|
||||
// Its rooms are every room descriptor of the floor once Level stored them. The Esau Jr. players are always four, a
|
||||
// player type of -1 for an empty one.
|
||||
// Construction and destruction (009c73c0, 009c7800) are the defaults, defined where GameStatePlayer is complete.
|
||||
// Steam Cloud is offline, so the cloud file names are dropped.
|
||||
struct GameState
|
||||
{
|
||||
@@ -45,27 +79,47 @@ struct GameState
|
||||
GameStateItemPool itemPool{};
|
||||
ScoreRecord scoreSheet{};
|
||||
std::array<BackwardsStageDesc, BACKWARDS_STAGE_COUNT> backwardsStages{};
|
||||
std::array<VentricleRazorPortal, VENTRICLE_RAZOR_PORTAL_COUNT> ventricleRazorPortals{};
|
||||
std::array<int, ROOM_MAP_CELLS> roomMap{};
|
||||
std::array<int, STAGE_ICON_COUNT> nightmareStageIcons{};
|
||||
std::array<uint32_t, GREED_WAVE_SEED_COUNT> greedWaveSeeds{};
|
||||
std::bitset<SAVED_GAME_STATE_FLAG_COUNT> gameStateFlags{};
|
||||
std::vector<BossId> encounteredBosses{};
|
||||
std::vector<ErasedEnemy> erasedEntities{};
|
||||
std::vector<uint32_t> proceduralItemSeeds{};
|
||||
std::bitset<LEVEL_STATE_FLAG_COUNT> levelStateFlags{};
|
||||
std::vector<GameStatePlayer> esauJrStates;
|
||||
std::vector<GameStatePlayer> players;
|
||||
std::vector<SavedRoom> rooms;
|
||||
std::vector<RoomConfigRef> mergedRoomConfigs;
|
||||
std::vector<BossId> encounteredBosses;
|
||||
std::vector<ErasedEnemy> erasedEntities;
|
||||
std::vector<uint32_t> proceduralItemSeeds;
|
||||
std::vector<uint32_t> versusPlayers;
|
||||
std::string rerunPath;
|
||||
std::string savePath;
|
||||
|
||||
Vector dungeonReturnPosition{};
|
||||
float angelRoomChance = 0;
|
||||
int ambushWave = 0;
|
||||
int blueWombParTime = 0;
|
||||
int bombPickupsSpawned = 0;
|
||||
int bossRushParTime = 0;
|
||||
int challenge = 0;
|
||||
int currentRoomIdx = 0;
|
||||
int deathCertificateExitTimer = 0;
|
||||
int devilRoomDeals = 0;
|
||||
int difficulty = 0;
|
||||
int donationModAngel = 0;
|
||||
int donationModGreed = 0;
|
||||
int dungeonReturnRoomIndex = 0;
|
||||
int enterDoor = 0;
|
||||
int frameCount = 0;
|
||||
int greedLastBeatenWave = 0;
|
||||
int greedLastPaidWave = 0;
|
||||
int greedModeWave = 0;
|
||||
int lastBossRoomListIdx = 0;
|
||||
int lastDevilRoomStage = 0;
|
||||
int lastLevelWithDamage = 0;
|
||||
int lastLevelWithoutHalfHp = 0;
|
||||
int lastRoomIdx = 0;
|
||||
int magicSkinUses = 0;
|
||||
int pixelationDuration = 0;
|
||||
int pixelationTimer = 0;
|
||||
@@ -73,25 +127,49 @@ struct GameState
|
||||
int playerType = 0;
|
||||
int reviveMachineCoinsLeft = 0;
|
||||
int reviveMachineUses = 0;
|
||||
int roomCount = 0;
|
||||
int shopVisits = 0;
|
||||
int slowdownDuration = 0;
|
||||
int stageNameNumeral = 0;
|
||||
int stagesWithoutDamage = 0;
|
||||
int stagesWithoutHeartsPicked = 0;
|
||||
int startingRoomIdx = 0;
|
||||
int timeCounter = 0;
|
||||
int treasureRoomsVisited = 0;
|
||||
int victoryLap = 0;
|
||||
uint32_t checksum = 0;
|
||||
uint32_t curses = 0;
|
||||
uint32_t devilAngelRoomSeed = 0;
|
||||
uint32_t dungeonPlacementSeed = 0;
|
||||
uint32_t fortuneSeed = 0;
|
||||
uint32_t greedModeTreasureRoomIdx = 0;
|
||||
uint32_t playerManagerSeed = 0;
|
||||
uint32_t stage = 0;
|
||||
uint32_t stageType = 0;
|
||||
uint8_t brokenWatchState = 0;
|
||||
uint8_t currentDimensionIdx = 0;
|
||||
uint8_t lastRoomDimensionIdx = 0;
|
||||
uint8_t versusRules = 0;
|
||||
|
||||
bool isAmbushActive = false;
|
||||
bool isAscent = false;
|
||||
bool isBossChallenge = false;
|
||||
bool isCanSeeEverything = false;
|
||||
bool isConsoleUsedThisRun = false;
|
||||
bool isDevilRoomDisabled = false;
|
||||
bool isHeartPicked = false;
|
||||
bool isModded = false;
|
||||
bool isRerun = false;
|
||||
bool isRerunAvailable = false;
|
||||
bool isSaveAvailable = false;
|
||||
|
||||
GameState();
|
||||
GameState(const GameState& other);
|
||||
GameState(GameState&& other) noexcept;
|
||||
GameState& operator=(const GameState& other);
|
||||
GameState& operator=(GameState&& other) noexcept;
|
||||
~GameState();
|
||||
|
||||
void Clear();
|
||||
void Delete();
|
||||
void DeleteRerun();
|
||||
@@ -99,3 +177,16 @@ struct GameState
|
||||
bool read_rerun(std::span<const uint8_t> file);
|
||||
std::vector<uint8_t> write();
|
||||
};
|
||||
|
||||
// The run as the Glowing Hourglass can rewind it: the game state as the players entered a room, the door they left
|
||||
// the room before by, the frame it was saved on and the event counters then.
|
||||
struct GlowingHourglassState
|
||||
{
|
||||
GameState gameState;
|
||||
std::array<int, EVENT_COUNTER_COUNT> eventCounters{};
|
||||
int leaveDoor = 0;
|
||||
int timeCounter = 0;
|
||||
bool isUsable = false;
|
||||
};
|
||||
|
||||
void room_config_ref_save(RoomConfig_Room& config, RoomConfigRef& ref, std::vector<RoomConfigRef>* mergedConfigs);
|
||||
@@ -0,0 +1,236 @@
|
||||
#pragma once
|
||||
|
||||
#include "anm2.h"
|
||||
#include "entity_player.h"
|
||||
#include "entity_save_state.h"
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
constexpr int CANDY_HEART_STATS = 6;
|
||||
constexpr int GAME_STATE_PLAYER_LIMIT = 8;
|
||||
constexpr int POOP_SPELL_SLOTS = 26;
|
||||
constexpr int SAVED_CHARMED_ENEMY_LIMIT = 10;
|
||||
constexpr int SAVED_RANDOM_BABIES = 5;
|
||||
constexpr int SAVE_FORGOTTEN_BODY_ROOM_NONE = -100000;
|
||||
constexpr int SAVE_MONKEY_PAW_CHARGES = 3;
|
||||
constexpr float SAVE_ROCK_BOTTOM_LUCK_UNSET = -9999;
|
||||
|
||||
// A familiar as it follows its player into a saved run or through Curse of the Mist (FamiliarData).
|
||||
struct FamiliarData
|
||||
{
|
||||
Vector formationTargetOffset{};
|
||||
float health = 0;
|
||||
int coins = 0;
|
||||
int hearts = 0;
|
||||
int keys = 0;
|
||||
int roomClearCount = 0;
|
||||
int state = 0;
|
||||
int subtype = 0;
|
||||
int variant = 0;
|
||||
uint32_t dropSeed = 0;
|
||||
uint32_t initSeed = 0;
|
||||
bool isNotCountedAsFollower = false;
|
||||
bool isSubtype55555 = false;
|
||||
};
|
||||
|
||||
// A co-op baby or a sub player, by its character and health.
|
||||
struct CoPlayerState
|
||||
{
|
||||
int blackHearts = 0;
|
||||
int boneHearts = 0;
|
||||
int boneHeartsMask = 0;
|
||||
int brokenHearts = 0;
|
||||
int eternalHearts = 0;
|
||||
int goldenHearts = 0;
|
||||
int maxHearts = 0;
|
||||
int playerType = 0;
|
||||
int redHearts = 0;
|
||||
int rottenHearts = 0;
|
||||
int soulHearts = 0;
|
||||
};
|
||||
|
||||
// A temporary effect that lasts the run, by its item's type and id.
|
||||
struct PersistentEffect
|
||||
{
|
||||
int cooldown = 0;
|
||||
int count = 0;
|
||||
int id = 0;
|
||||
int type = 0;
|
||||
};
|
||||
|
||||
// An item a costume shows, by its type and id.
|
||||
struct CostumeItem
|
||||
{
|
||||
int id = 0;
|
||||
int type = 0;
|
||||
};
|
||||
|
||||
// A passive the Void absorbed. Its second word is only ever copied.
|
||||
struct VoidedPassive
|
||||
{
|
||||
int id = 0;
|
||||
int value = 0;
|
||||
};
|
||||
|
||||
// A player as a saved run keeps it (GameStatePlayer): its character, health and consumables, its items and their RNGs,
|
||||
// stats and the counters items keep, the familiars and charmed enemies that follow it, and its co-op babies.
|
||||
// The first player also keeps PlayerManager's glitched baby seed and random babies.
|
||||
// Init (009cf050) is the defaults, as are copies and destruction (00754d90).
|
||||
// The words at 0x36c, 0x370 and 0x514 of the original are saved but never set, so they are written as 0.
|
||||
// The unknown fields are saved and restored, but what the original keeps in them is not known yet.
|
||||
struct GameStatePlayer
|
||||
{
|
||||
std::vector<HistoryItem> history;
|
||||
std::vector<CoPlayerState> coopBabies;
|
||||
std::vector<CostumeItem> costumes;
|
||||
std::vector<EntityDesc> charmedEnemies;
|
||||
std::vector<EntitySaveState> movingBoxContents;
|
||||
std::vector<FamiliarData> curseMistFamiliars;
|
||||
std::vector<FamiliarData> familiars;
|
||||
std::vector<PersistentEffect> persistentEffects;
|
||||
std::vector<PocketItem> echoChamberItems;
|
||||
std::vector<TemporaryEffect> temporaryEffects;
|
||||
std::vector<VoidedPassive> voidedPassives;
|
||||
std::vector<int> collectibleCounts;
|
||||
std::vector<int> itemCards;
|
||||
std::vector<int> levelEffectItems;
|
||||
std::vector<int> pillEffectUses;
|
||||
std::vector<int> voidedCollectibles;
|
||||
std::vector<uint32_t> cardRngSeeds;
|
||||
std::vector<uint32_t> collectibleRngSeeds;
|
||||
std::vector<uint32_t> pillRngSeeds;
|
||||
std::vector<uint32_t> trinketRngSeeds;
|
||||
std::map<int, int> proceduralItems;
|
||||
std::optional<CoPlayerState> subPlayer;
|
||||
|
||||
std::array<ActiveItemDesc, ACTIVE_SLOT_COUNT> activeItems{};
|
||||
std::array<PocketItem, POCKET_SLOT_COUNT> curseMistPocketItems{};
|
||||
std::array<PocketItem, POCKET_SLOT_COUNT> ghostPocketItems{};
|
||||
std::array<PocketItem, POCKET_SLOT_COUNT> pocketItems{};
|
||||
std::array<int, INVENTORY_SIZE> inventory{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
|
||||
std::array<int, PLAYER_FORM_SLOTS> playerForms{};
|
||||
std::array<int, SAVED_RANDOM_BABIES> randomBabies{};
|
||||
std::array<uint32_t, TRINKET_SLOT_COUNT> curseMistTrinkets{};
|
||||
std::array<uint32_t, TRINKET_SLOT_COUNT> ghostTrinkets{};
|
||||
std::array<uint32_t, TRINKET_SLOT_COUNT> trinkets{};
|
||||
std::array<int16_t, CANDY_HEART_STATS> candyHeartStatUps{};
|
||||
std::array<int16_t, CANDY_HEART_STATS> soulLocketStatUps{};
|
||||
std::array<uint8_t, BAG_OF_CRAFTING_SIZE> bagOfCraftingContent{};
|
||||
std::array<uint8_t, POOP_SPELL_SLOTS> poopSpellQueue{};
|
||||
ConsumableData consumablesBackup;
|
||||
EntityDesc friendBallEnemy;
|
||||
QueueItemData queuedItem;
|
||||
|
||||
Vector bodyScale = vector_make(1, 1);
|
||||
Vector forgottenBodyPos{};
|
||||
Vector headScale = vector_make(1, 1);
|
||||
Vector playerSpriteScale = vector_make(1, 1);
|
||||
float d8DamageModifier = 1;
|
||||
float d8FireDelayModifier = 1;
|
||||
float d8RangeModifier = 1;
|
||||
float d8SpeedModifier = 1;
|
||||
float darkEsauHealth = 0;
|
||||
float edenDamage = 0;
|
||||
float edenFireDelay = 0;
|
||||
float edenLuck = 0;
|
||||
float edenShotSpeed = 0;
|
||||
float edenSpeed = 0;
|
||||
float edenTearRange = 0;
|
||||
float ibsCharge = 0;
|
||||
float poopSpellFloat = 0;
|
||||
float rockBottomDamage = 0;
|
||||
float rockBottomLuck = SAVE_ROCK_BOTTOM_LUCK_UNSET;
|
||||
float rockBottomMaxFireDelay = 0;
|
||||
float rockBottomMoveSpeed = 0;
|
||||
float rockBottomShotSpeed = 0;
|
||||
float rockBottomTearRange = 0;
|
||||
int bagOfCraftingOutput = 0;
|
||||
int bagOfCraftingPool = -1;
|
||||
int blackHearts = 0;
|
||||
int bleedOutHealth = 0;
|
||||
int boneHearts = 0;
|
||||
int boneHeartsMask = 0;
|
||||
int brokenHearts = 0;
|
||||
int cambionConceptionState = 0;
|
||||
int controllerIndex = 0;
|
||||
int curseMistRedHearts = 0;
|
||||
int damageModifier = 0;
|
||||
int donateLuck = 0;
|
||||
int effectiveBloodCharge = 0;
|
||||
int effectiveSoulCharge = 0;
|
||||
int eternalHearts = 0;
|
||||
int fireDelayModifier = 0;
|
||||
int forgottenBodyRoomIdx = SAVE_FORGOTTEN_BODY_ROOM_NONE;
|
||||
int glitchBabySeed = 0;
|
||||
int goldenHearts = 0;
|
||||
int greedsGulletHearts = 0;
|
||||
int immaculateConceptionState = 0;
|
||||
int jarFlies = 0;
|
||||
int jarHearts = 0;
|
||||
int keepersSackBonus = 0;
|
||||
int killCounter = 0;
|
||||
int lastCollectibleFrame = -1;
|
||||
int lastPillColor = 0;
|
||||
int luckModifier = 0;
|
||||
int maxHearts = 0;
|
||||
int modelingClayEffect = 0;
|
||||
int numBombs = 0;
|
||||
int numCoins = 0;
|
||||
int numGigaBombs = 0;
|
||||
int numKeys = 0;
|
||||
int parentIndex = -1;
|
||||
int planCKillCountdown = 0;
|
||||
int playerType = 0;
|
||||
int poopMana = 0;
|
||||
int potatoPeelerBandageCounter = 0;
|
||||
int potatoPeelerCounter = 0;
|
||||
int purityState = 0;
|
||||
int rUaWizardTimer = 0;
|
||||
int randomBabyCount = 0;
|
||||
int redHearts = 0;
|
||||
int redStewBonusDuration = 0;
|
||||
int reverseEmpressMaxHearts = 0;
|
||||
int reverseSunBoneHearts = 0;
|
||||
int rottenHearts = 0;
|
||||
int samsonBerserkCharge = 0;
|
||||
int shotSpeedModifier = 0;
|
||||
int soulCharge = 0;
|
||||
int soulHearts = 0;
|
||||
int speedModifier = 0;
|
||||
int strengthMaxHearts = 0;
|
||||
int tearRangeModifier = 0;
|
||||
int unknownCounter = 0;
|
||||
int unknownTimer = -1;
|
||||
int unknownValue = 0;
|
||||
int wildCardItem = 0;
|
||||
int wildCardVarData = 0;
|
||||
uint32_t conceptionFamiliarFlags = 0;
|
||||
uint32_t imExcitedSpeedupCountdown = 0;
|
||||
uint32_t maggyHealthDrainCooldown = 0;
|
||||
uint32_t playerFormsRewarded = 0;
|
||||
uint32_t urnSouls = 0;
|
||||
uint32_t vampireCharmKills = 0;
|
||||
int16_t bloodLustCounter = 0;
|
||||
int16_t brittleBonesUpgrades = 0;
|
||||
int16_t deadCatLives = 0;
|
||||
int16_t greedsGulletOverflow = 0;
|
||||
int16_t monkeyPawCounter = SAVE_MONKEY_PAW_CHARGES;
|
||||
int16_t numLeprosy = 0;
|
||||
int16_t tonsilCount = 0;
|
||||
int16_t tonsilCounter = 0;
|
||||
int16_t totalDamageTaken = 0;
|
||||
uint8_t ductTapeMode = 0;
|
||||
uint8_t holyMantleStacks = 0;
|
||||
uint8_t poopSpellCounter = 0;
|
||||
uint8_t wildCardItemType = WILD_CARD_NONE;
|
||||
bool hasCurseMistEffect = false;
|
||||
bool hasGoldenBomb = false;
|
||||
bool hasGoldenKey = false;
|
||||
bool isBackupPlayer = false;
|
||||
bool isCoopGhost = false;
|
||||
bool isHolyMantle = false;
|
||||
bool isLevelStartPending = false;
|
||||
};
|
||||
@@ -0,0 +1,432 @@
|
||||
#include "entity_player.h"
|
||||
#include "game.h"
|
||||
#include "grid_entity_door.h"
|
||||
#include "log.h"
|
||||
#include "manager.h"
|
||||
#include "platform.h"
|
||||
#include "room.h"
|
||||
#include "seeds.h"
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
|
||||
constexpr int ROOM_INDEX_MIN = -20;
|
||||
constexpr int ROOM_INDEX_MAX = LEVEL_GRID_CELLS - 1;
|
||||
constexpr int DIMENSION_MAX = 2;
|
||||
constexpr int DEATH_CERTIFICATE_DIMENSION = 2;
|
||||
constexpr int MIRROR_DIMENSION = 1;
|
||||
constexpr int DOOR_SIDES = 4;
|
||||
constexpr int SIDE_ACROSS = 2;
|
||||
constexpr int STAGE_ID_HOME = 35;
|
||||
constexpr int STAGE_ID_SPECIAL_ROOMS = 0;
|
||||
constexpr uint32_t STAGE_CAVES_I = 3;
|
||||
constexpr uint32_t STAGE_CAVES_II = 4;
|
||||
constexpr int MINESHAFT_ENTRANCE_SUBTYPE = 10;
|
||||
constexpr int MAZE_MOVE_CHANCE = 10;
|
||||
constexpr int MAZE_SWAP_CHANCE = 5;
|
||||
constexpr int MAZE_SHAKE_FRAMES = 30;
|
||||
constexpr int SOUND_MAZE = 22;
|
||||
constexpr float SOUND_MAZE_VOLUME = 0.5f;
|
||||
constexpr int SOUND_ERROR_BUZZ = 187;
|
||||
constexpr int SOUND_TELEPORT_UP = 215;
|
||||
constexpr int ONLINE_STAT_ESCAPES = 9;
|
||||
constexpr const char* ANIMATION_TELEPORT_UP = "TeleportUp";
|
||||
constexpr const char* ANIMATION_OPEN = "Open";
|
||||
constexpr uint32_t ROOM_DESCRIPTOR_FLAG_BLUE_REDIRECT = 1u << 18;
|
||||
constexpr uint64_t GAME_STATE_BOSSPOOL_SWITCHED = 1ull << 4;
|
||||
constexpr uint64_t GAME_STATE_KEY_FAMILIAR_DOOR_PASSED = 1ull << 49;
|
||||
constexpr int BACKWARDS_FIRST_STAGE = 1;
|
||||
constexpr int BACKWARDS_LAST_STAGE = 6;
|
||||
constexpr uint32_t BLUE_ROOM_DOORS_ACROSS = 1u << DIRECTION_LEFT | 1u << DIRECTION_RIGHT;
|
||||
constexpr uint32_t BLUE_ROOM_DOORS_DOWN = 1u << DIRECTION_UP | 1u << DIRECTION_DOWN;
|
||||
constexpr int BLUE_ROOM_LONG_CHANCE = 4;
|
||||
constexpr int BLUE_ROOM_DIFFICULTY_MAX = 10;
|
||||
constexpr RNG BLUE_ROOM_RNG = {0, 5, 27, 28};
|
||||
|
||||
// The room indices the players leave without becoming the room they came from: the ones off the map that only lead on.
|
||||
constexpr int ROOM_PASSAGE_IDX = -14;
|
||||
constexpr int ROOM_PASSAGE_EXIT_IDX = -15;
|
||||
|
||||
// Whether a room type hides behind a secret door.
|
||||
static bool is_secret_type(int type)
|
||||
{
|
||||
return type == ROOM_SECRET || type == ROOM_SUPERSECRET;
|
||||
}
|
||||
|
||||
// Shuffles room indices, a random swap from the back as the original's own shuffle does.
|
||||
static void room_indices_shuffle(std::vector<int>& indices)
|
||||
{
|
||||
for (int i = (int)indices.size() - 1; i > 0; i--) std::swap(indices[i], indices[Random() % (uint32_t)(i + 1)]);
|
||||
}
|
||||
|
||||
// 006fd7c0 Checks a room transition and starts it. A versus match's fight only buzzes. The Glowing Hourglass on the
|
||||
// first floor's untouched start room goes back to the menu's stage transition (in Greed, teleports to the error room).
|
||||
// A teleport in the Beast's dungeon only moves the player. Leaving saves the rewind state (a teleport out of an
|
||||
// uncleared challenge, a curse or the error room counts as an escape), and a walk into a Blue Key door's room enters
|
||||
// the blue room in between.
|
||||
void Game::StartRoomTransition(RoomTransitionRequest request)
|
||||
{
|
||||
Entity_Player* player = request.player;
|
||||
RoomTransitionAnim& animation = request.animation;
|
||||
bool isStartRoom = currentRoomIdx == startingRoomIdx && room->isFirstVisit;
|
||||
bool isSaved = false;
|
||||
|
||||
if (request.roomIndex < ROOM_INDEX_MIN || request.roomIndex > ROOM_INDEX_MAX)
|
||||
return log_printf(LOG_ERROR, "Invalid room index passed to Game::StartRoomTransition()\n");
|
||||
if ((uint32_t)animation > TRANSITION_TRAPDOOR)
|
||||
return log_printf(LOG_ERROR, "Invalid animation passed to Game::StartRoomTransition()\n");
|
||||
if (request.dimension > DIMENSION_MAX)
|
||||
return log_printf(LOG_ERROR, "Invalid dimension passed to Game::StartRoomTransition()\n");
|
||||
if (deathmatchManager.state == DEATHMATCH_FIGHT) return sound_play(SOUND_ERROR_BUZZ);
|
||||
|
||||
if (animation == TRANSITION_GLOWING_HOURGLASS && stage == 1 && !IsAltPath() && isStartRoom)
|
||||
{
|
||||
if (!IsGreedMode())
|
||||
{
|
||||
reconstruction_missing("Game::StartStageTransition 006fdc10, the Glowing Hourglass back to the stage start");
|
||||
if (!player) return;
|
||||
player->PlayExtraAnimation(ANIMATION_TELEPORT_UP);
|
||||
return sound_play(SOUND_TELEPORT_UP);
|
||||
}
|
||||
request.roomIndex = ROOM_ERROR_IDX;
|
||||
animation = TRANSITION_TELEPORT;
|
||||
}
|
||||
if (request.roomIndex == ROOM_ERROR_IDX) request.dimension = 0;
|
||||
|
||||
if (player && (animation == TRANSITION_TELEPORT || animation == TRANSITION_GLOWING_HOURGLASS))
|
||||
{
|
||||
if (room->IsBeastDungeon())
|
||||
reconstruction_missing("Game::StartRoomTransition 006fd7c0: a teleport in the Beast's dungeon "
|
||||
"(Room::GetRandomPosition, Entity_Player::Teleport 007cd950)");
|
||||
if (animation == TRANSITION_TELEPORT)
|
||||
{
|
||||
int type = room->roomType;
|
||||
bool isGuarded = type == ROOM_CHALLENGE || type == ROOM_BOSSRUSH;
|
||||
bool isEscape = isGuarded ? !room->IsClear() : type == ROOM_CURSE || type == ROOM_ERROR;
|
||||
|
||||
if (isEscape) Player_stats_add(&onlinePlayerStats, ONLINE_STAT_ESCAPES, player, 1);
|
||||
isSaved = true;
|
||||
}
|
||||
}
|
||||
else if (!player && animation == TRANSITION_TELEPORT) isSaved = true;
|
||||
|
||||
bool isStarted = false;
|
||||
if (!isSaved && animation == TRANSITION_PORTAL_TELEPORT) isSaved = true;
|
||||
else if (!isSaved && isStartRoom)
|
||||
{
|
||||
isStarted = animation == TRANSITION_GLOWING_HOURGLASS;
|
||||
isSaved = !isStarted;
|
||||
}
|
||||
if (isSaved) save_rewind_state(DOOR_NONE);
|
||||
|
||||
bool isSameDimension = request.dimension < 0 || request.dimension == currentDimensionIdx;
|
||||
if (!isStarted && animation == TRANSITION_WALK && isSameDimension &&
|
||||
prepare_blue_room(currentRoomIdx, request.roomIndex, request.direction))
|
||||
request.roomIndex = ROOM_BLUE_ROOM_IDX;
|
||||
|
||||
roomTransition.start(request);
|
||||
if (roomTransition.is_versus_screen()) framesSinceRoomTransition = 0;
|
||||
isRoomRespawned = false;
|
||||
}
|
||||
|
||||
// 0073d9b0 The slot a door side takes in a room, by the cell of the room it is seen from: the second row's side doors
|
||||
// and the second column's top and bottom ones are 4 further. Checked, -1 when the room's layout has no such door.
|
||||
int Level::get_door_slot(int roomIdx, int doorSlot, bool isChecked, int dimension)
|
||||
{
|
||||
RoomDescriptor& desc = *g_game->GetRoomByIdx(roomIdx, dimension);
|
||||
int offset = roomIdx < 0 ? 0 : roomIdx - desc.gridIndex;
|
||||
bool isVertical = doorSlot == DIRECTION_UP || doorSlot == DIRECTION_DOWN;
|
||||
bool isSide = doorSlot == DIRECTION_LEFT || doorSlot == DIRECTION_RIGHT;
|
||||
|
||||
if ((isVertical && offset % LEVEL_GRID_WIDTH > 0) || (isSide && offset / LEVEL_GRID_WIDTH > 0)) doorSlot += DOOR_SIDES;
|
||||
if (isChecked && !((desc.data->doors | desc.data->questDoors) >> doorSlot & 1)) return DOOR_NONE;
|
||||
return doorSlot;
|
||||
}
|
||||
|
||||
// 0073da40 The slot the players come in by on a door side of a room: that side's door for the cell, else the first
|
||||
// slot from the side across (going round) that the layout has a door or a quest door at.
|
||||
int Level::GetTargetSlot(int roomIdx, int doorSlot)
|
||||
{
|
||||
int slot = get_door_slot(roomIdx, doorSlot, true, -1);
|
||||
if (slot != DOOR_NONE) return slot;
|
||||
|
||||
RoomConfig_Room& data = *GetRoomByIdx(roomIdx)->data;
|
||||
slot = doorSlot + DOOR_SIDES;
|
||||
for (int attempt = 0; attempt < DOOR_SLOT_COUNT && !((data.doors | data.questDoors) >> slot & 1); attempt++)
|
||||
slot = (slot + 1) % DOOR_SLOT_COUNT;
|
||||
if (roomIdx >= 0 && !(data.doors >> slot & 1))
|
||||
log_printf(LOG_ASSERT, "Level::get_target_slot: Could not find a valid door slot for room idx %d\n", roomIdx);
|
||||
return slot;
|
||||
}
|
||||
|
||||
// 0074d4a0 Readies the blue room a walk from a room on the map through a door into a room a Blue Key opened leads to
|
||||
// first: a fresh descriptor seeded from the target's decoration seed, a blue room layout of the door's axis (one in
|
||||
// four the long one, else any shape), with doors back to the room left and on to the target. False when no layout fits.
|
||||
bool Level::prepare_blue_room(int fromRoomIdx, int targetRoomIdx, int direction)
|
||||
{
|
||||
if (direction == DIRECTION_NONE || fromRoomIdx < 0) return false;
|
||||
|
||||
RoomDescriptor& target = *GetRoomByIdx(targetRoomIdx);
|
||||
if (!(target.flags & ROOM_DESCRIPTOR_FLAG_BLUE_REDIRECT)) return false;
|
||||
|
||||
RoomDescriptor& blue = *GetRoomByIdx(ROOM_BLUE_ROOM_IDX);
|
||||
RNG rng = BLUE_ROOM_RNG;
|
||||
int listIndex = blue.listIndex;
|
||||
bool isAcross = direction == DIRECTION_LEFT || direction == DIRECTION_RIGHT;
|
||||
|
||||
rng._seed = target.decorationSeed;
|
||||
blue = RoomDescriptor{};
|
||||
blue.listIndex = listIndex;
|
||||
blue.gridIndex = ROOM_BLUE_ROOM_IDX;
|
||||
blue.InitSeeds(rng);
|
||||
|
||||
bool isLong = rng.RandomInt(BLUE_ROOM_LONG_CHANCE) == 0;
|
||||
RoomQuery query = {.requiredDoors = isAcross ? BLUE_ROOM_DOORS_ACROSS : BLUE_ROOM_DOORS_DOWN,
|
||||
.shape = isAcross ? (isLong ? ROOMSHAPE_IIH : ROOMSHAPE_2x1) : (isLong ? ROOMSHAPE_IIV : ROOMSHAPE_1x2),
|
||||
.maxDifficulty = BLUE_ROOM_DIFFICULTY_MAX,
|
||||
.minDifficulty = 1,
|
||||
.stageId = STAGE_ID_SPECIAL_ROOMS,
|
||||
.type = ROOM_BLUE};
|
||||
|
||||
blue.data = g_game->roomConfig.GetRandomRoom(rng.Next(), WEIGHT_KEEP, query);
|
||||
if (!blue.data)
|
||||
{
|
||||
query.shape = ROOMSHAPE_ANY;
|
||||
blue.data = g_game->roomConfig.GetRandomRoom(rng.Next(), WEIGHT_KEEP, query);
|
||||
if (!blue.data) return false;
|
||||
}
|
||||
blue.allowedDoors = query.requiredDoors;
|
||||
blue.doors[direction] = targetRoomIdx;
|
||||
blue.doors[(direction + SIDE_ACROSS) % DOOR_SIDES] = fromRoomIdx;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Under the Curse of the Maze, one leave in ten lands in a random room within two doors of the target (not a secret
|
||||
// or curse room) that has a door back toward the side left through to a room that is not secret. Returns whether it
|
||||
// did, and the side the players then come in from. One leave in five swaps a visited room with a matching one.
|
||||
static bool maze_move(Level& level, int& newRoomIdx, int& enterSide)
|
||||
{
|
||||
bool isMoved = false;
|
||||
|
||||
if (Random() % MAZE_MOVE_CHANCE == 0)
|
||||
{
|
||||
std::set<int> nearby = level.get_rooms_within_two_doors(newRoomIdx);
|
||||
std::vector<int> candidates(nearby.begin(), nearby.end());
|
||||
|
||||
room_indices_shuffle(candidates);
|
||||
for (int candidate : candidates)
|
||||
{
|
||||
RoomDescriptor& desc = *level.GetRoomByIdx(candidate);
|
||||
int type = desc.data->type;
|
||||
if (is_secret_type(type) || type == ROOM_CURSE || desc.gridIndex < 0) continue;
|
||||
if (level.leaveDoor < 0)
|
||||
{
|
||||
level.currentRoomIdx = newRoomIdx = candidate;
|
||||
log_printf(LOG_INFO, "Found a candidate without leave door\n");
|
||||
isMoved = true;
|
||||
break;
|
||||
}
|
||||
|
||||
enterSide = (level.leaveDoor + SIDE_ACROSS) % DOOR_SIDES;
|
||||
int slot = level.GetTargetSlot(candidate, enterSide);
|
||||
if (slot % DOOR_SIDES != enterSide || !(desc.allowedDoors >> slot & 1)) continue;
|
||||
if (is_secret_type(level.GetRoomByIdx(desc.doors[slot])->data->type)) continue;
|
||||
|
||||
level.currentRoomIdx = newRoomIdx = candidate;
|
||||
level.lastRoomIdx = desc.doors[slot];
|
||||
log_printf(LOG_INFO, "Found a candidate\n");
|
||||
isMoved = true;
|
||||
break;
|
||||
}
|
||||
if (isMoved && g_game->roomTransition.animation == TRANSITION_WALK)
|
||||
{
|
||||
g_game->roomTransition.animation = TRANSITION_MAZE;
|
||||
g_game->minimap.shakeDuration = MAZE_SHAKE_FRAMES;
|
||||
int sound = SOUND_MAZE;
|
||||
seed_fart_sound_override(&sound);
|
||||
g_manager->sfxManager.Play(sound, {.volume = SOUND_MAZE_VOLUME});
|
||||
}
|
||||
}
|
||||
if (Random() % MAZE_SWAP_CHANCE == 0)
|
||||
{
|
||||
std::vector<int> order;
|
||||
for (int i = 0; i < level.nbRooms; i++) order.push_back(i);
|
||||
room_indices_shuffle(order);
|
||||
for (int i : order)
|
||||
{
|
||||
RoomDescriptor& desc = level.roomList[i];
|
||||
if (desc.visitedCount == 0) continue;
|
||||
|
||||
int match = level.find_matching_room_idx(desc.safeGridIndex);
|
||||
if (match == -1) continue;
|
||||
level.maze_swap_rooms(desc.safeGridIndex, match);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return isMoved;
|
||||
}
|
||||
|
||||
// The side the players come in from without a door to go by: random for a room off the map, else facing the way from
|
||||
// the room left, across or down by the larger step between their cells.
|
||||
static int enter_side_guess(Level& level, int newRoomIdx)
|
||||
{
|
||||
if (newRoomIdx < 0) return (int)(Random() & (DOOR_SIDES - 1));
|
||||
|
||||
int columns = level.currentRoomIdx % LEVEL_GRID_WIDTH - level.lastRoomIdx % LEVEL_GRID_WIDTH;
|
||||
int rows = level.currentRoomIdx / LEVEL_GRID_WIDTH - level.lastRoomIdx / LEVEL_GRID_WIDTH;
|
||||
if (std::abs(rows) < std::abs(columns)) return columns > 0 ? DIRECTION_LEFT : DIRECTION_RIGHT;
|
||||
return rows < 1 ? DIRECTION_DOWN : DIRECTION_UP;
|
||||
}
|
||||
|
||||
// The door the players come in by in the room just loaded: the one they entered through, else (or when a secret room's
|
||||
// leads to a red room) the first door of a normal room from a random slot, else the last door seen there. None found,
|
||||
// none. A secret door blows open from either side and closes again in a room not cleared, and a door back the way
|
||||
// they came opens for good unless barred.
|
||||
static void enter_door_open(Level& level, int previousType)
|
||||
{
|
||||
Room& room = *level.room;
|
||||
bool isSecret = is_secret_type(room.roomType);
|
||||
auto isLeadingToRed = [&](GridEntity_Door* door)
|
||||
{
|
||||
RoomDescriptor* target = level.GetRoomByIdx(door->targetRoomIdx);
|
||||
return target && (target->flags & ROOM_DESCRIPTOR_FLAG_RED_ROOM);
|
||||
};
|
||||
// The original reads the cell before the doors (the room's last grid cell) for no entry door. Here there is none.
|
||||
GridEntity_Door* door = level.enterDoor >= 0 && level.enterDoor < DOOR_SLOT_COUNT ? room.doors[level.enterDoor] : nullptr;
|
||||
|
||||
if (!door || (isSecret && isLeadingToRed(door)))
|
||||
{
|
||||
GridEntity_Door* fallback = nullptr;
|
||||
uint32_t start = Random() & (DOOR_SLOT_COUNT - 1);
|
||||
|
||||
door = nullptr;
|
||||
for (int i = 0; i < DOOR_SLOT_COUNT; i++)
|
||||
{
|
||||
level.enterDoor = (int)((start + i) % DOOR_SLOT_COUNT);
|
||||
door = room.doors[level.enterDoor];
|
||||
if (door && isSecret && isLeadingToRed(door)) door = nullptr;
|
||||
if (!door) continue;
|
||||
if (door->targetRoomType == ROOM_DEFAULT) break;
|
||||
fallback = door;
|
||||
}
|
||||
if (!door) door = fallback;
|
||||
if (!door) return;
|
||||
}
|
||||
|
||||
RoomDescriptor& current = *level.GetRoomByIdx(level.currentRoomIdx);
|
||||
bool isFromSecret = door->targetRoomIdx == level.lastRoomIdx && is_secret_type(previousType);
|
||||
if (isSecret || isFromSecret)
|
||||
{
|
||||
door->TryBlowOpen(false, nullptr);
|
||||
if (!(current.flags & ROOM_DESCRIPTOR_FLAG_CLEAR) && door->state != DOOR_STATE_CLOSED)
|
||||
{
|
||||
door->state = DOOR_STATE_CLOSED;
|
||||
door->UpdateAnimation();
|
||||
bool isHidden = is_secret_type(door->currentRoomType) || is_secret_type(door->targetRoomType) ||
|
||||
door->currentRoomType == ROOM_ULTRASECRET || door->targetRoomType == ROOM_ULTRASECRET;
|
||||
if (isHidden) door->openAnimation = ANIMATION_OPEN;
|
||||
}
|
||||
}
|
||||
if (current.visitedCount == 0 || door->targetRoomIdx != level.lastRoomIdx || door->variant == DOOR_LOCKED_BARRED) return;
|
||||
if (door->variant == DOOR_LOCKED_KEYFAMILIAR) g_game->gameStateFlags |= GAME_STATE_KEY_FAMILIAR_DOOR_PASSED;
|
||||
door->variant = DOOR_UNLOCKED;
|
||||
door->UpdateAnimation();
|
||||
}
|
||||
|
||||
// 0073fc80 Leaves the room for another (clamped to the room indices and dimensions): the room left is stored, the save
|
||||
// file written when it changed, and the room left recorded unless it only led on. The Curse of the Maze may move the
|
||||
// players elsewhere. The door they come in by is the one across from the door left, else guessed from the rooms'
|
||||
// cells, or the same door going between the mirror worlds. Blue Key redirects behind the old room's doors are
|
||||
// dropped, a mineshaft entrance marks its descent, the new room loads and its entry door opens, then the map updates.
|
||||
void Level::ChangeRoom(int targetRoomIdx, int dimension)
|
||||
{
|
||||
Game& game = *g_game;
|
||||
PersistentGameData& persistent = g_manager->persistentGameData;
|
||||
int newRoomIdx = std::clamp(targetRoomIdx, ROOM_INDEX_MIN, ROOM_INDEX_MAX);
|
||||
|
||||
dimension = dimension < 0 ? -1 : std::min(dimension, DIMENSION_MAX);
|
||||
room->on_leave();
|
||||
game.gameStateFlags |= GAME_STATE_BOSSPOOL_SWITCHED;
|
||||
if (persistent.isChangesMade && persistent.isFileLoaded)
|
||||
{
|
||||
persistent.isChangesMade = false;
|
||||
persistent.BackupSaveFile();
|
||||
persistent.Save();
|
||||
}
|
||||
if (dimension < 0) dimension = currentDimensionIdx;
|
||||
if (currentDimensionIdx == DEATH_CERTIFICATE_DIMENSION && dimension != DEATH_CERTIFICATE_DIMENSION)
|
||||
reconstruction_missing("Level::ChangeRoom 0073fc80: the way back from the Death Certificate floor (Game "
|
||||
"+0x18900..+0x18914 hold the room, dimension and door left)");
|
||||
|
||||
RoomDescriptor& target = *GetRoomByIdx(newRoomIdx, dimension);
|
||||
bool isHomeDungeon = target.data && target.data->type == ROOM_DUNGEON && target.data->stageId == STAGE_ID_HOME;
|
||||
if (currentDimensionIdx != dimension || isHomeDungeon)
|
||||
for (VentricleRazorPortal& portal : ventricleRazorPortals) portal.roomIndex = PORTAL_ROOM_NONE;
|
||||
|
||||
int oldRoomIdx = currentRoomIdx;
|
||||
lastRoomDimensionIdx = currentDimensionIdx;
|
||||
if (newRoomIdx == oldRoomIdx && dimension == currentDimensionIdx)
|
||||
log_printf(LOG_INFO, "[warn] ChangeRoom() called with current room index\n");
|
||||
else
|
||||
{
|
||||
int previousIdx = lastRoomIdx;
|
||||
bool isOldKept = oldRoomIdx >= 0 || oldRoomIdx == ROOM_DUNGEON_IDX || oldRoomIdx == ROOM_DEBUG_IDX ||
|
||||
oldRoomIdx == ROOM_GIDEON_DUNGEON_IDX || oldRoomIdx == ROOM_SECRET_SHOP_IDX;
|
||||
bool isOldPassage = oldRoomIdx == ROOM_PASSAGE_IDX || oldRoomIdx == ROOM_PASSAGE_EXIT_IDX;
|
||||
|
||||
if (newRoomIdx >= 0 ? !isOldPassage : isOldKept) lastRoomIdx = oldRoomIdx;
|
||||
if (newRoomIdx == ROOM_PASSAGE_IDX) lastRoomIdx = previousIdx;
|
||||
currentDimensionIdx = dimension;
|
||||
currentRoomIdx = newRoomIdx;
|
||||
currentRoomMap = &roomMap[dimension * LEVEL_GRID_CELLS];
|
||||
}
|
||||
|
||||
bool isMazeMoved = false;
|
||||
int enterSide = DIRECTION_NONE;
|
||||
bool isMazeFloor = currentDimensionIdx != MIRROR_DIMENSION || !HasAbandonedMineshaft();
|
||||
if ((GetCurses() & CURSE_OF_MAZE) && currentRoomIdx >= 0 && lastRoomIdx >= 0 &&
|
||||
currentDimensionIdx == lastRoomDimensionIdx && isMazeFloor)
|
||||
isMazeMoved = maze_move(*this, newRoomIdx, enterSide);
|
||||
|
||||
int slotRoomIdx = newRoomIdx;
|
||||
if (leaveDoor < 0 || (currentRoomIdx == lastRoomIdx && currentDimensionIdx == lastRoomDimensionIdx))
|
||||
enterSide = enter_side_guess(*this, newRoomIdx);
|
||||
else if (enterSide == DIRECTION_NONE)
|
||||
{
|
||||
enterSide = (leaveDoor % DOOR_SIDES + SIDE_ACROSS) % DOOR_SIDES;
|
||||
RoomDescriptor* previous = lastRoomIdx >= 0 ? GetRoomByIdx(lastRoomIdx, lastRoomDimensionIdx) : nullptr;
|
||||
int neighbor = previous && (previous->data->doors >> leaveDoor & 1) ? previous->doors[leaveDoor] : -1;
|
||||
|
||||
if (neighbor >= 0 && currentDimensionIdx == lastRoomDimensionIdx)
|
||||
{
|
||||
constexpr int CELL_STEPS[DOOR_SIDES] = {-1, -LEVEL_GRID_WIDTH, 1, LEVEL_GRID_WIDTH};
|
||||
lastRoomIdx = neighbor + CELL_STEPS[enterSide];
|
||||
if (currentRoomIdx >= 0 && (previous->allowedDoors >> leaveDoor & 1)) slotRoomIdx = currentRoomIdx = neighbor;
|
||||
}
|
||||
}
|
||||
enterDoor = GetTargetSlot(slotRoomIdx, enterSide);
|
||||
if (currentRoomIdx == lastRoomIdx && currentDimensionIdx != lastRoomDimensionIdx && HasMirrorDimension())
|
||||
enterDoor = leaveDoor;
|
||||
|
||||
// The original reads the room left's layout unchecked. A room without one counts as no type here.
|
||||
RoomConfig_Room* previousData = GetRoomByIdx(lastRoomIdx, lastRoomDimensionIdx)->data;
|
||||
int previousType = previousData ? previousData->type : ROOM_NULL;
|
||||
for (GridEntity_Door* door : room->doors)
|
||||
if (door) GetRoomByIdx(door->targetRoomIdx)->flags &= ~ROOM_DESCRIPTOR_FLAG_BLUE_REDIRECT;
|
||||
|
||||
bool isBackwards = stage >= BACKWARDS_FIRST_STAGE && stage <= BACKWARDS_LAST_STAGE &&
|
||||
game.GetStateFlag(GAME_STATE_BACKWARDS_PATH);
|
||||
bool isAltStage = stageType == STAGETYPE_REPENTANCE || stageType == STAGETYPE_REPENTANCE_B;
|
||||
bool isMineshaftFloor =
|
||||
stage == STAGE_CAVES_II || (stage == STAGE_CAVES_I && (GetCurses() & CURSE_OF_LABYRINTH));
|
||||
RoomConfig_Room* leftData = room->descriptor->data;
|
||||
bool isEntrance = leftData && room->roomType == ROOM_DEFAULT && leftData->subtype == MINESHAFT_ENTRANCE_SUBTYPE;
|
||||
if (!game.IsGreedMode() && !isBackwards && isAltStage && isMineshaftFloor && lastRoomDimensionIdx == 0 &&
|
||||
currentDimensionIdx == MIRROR_DIMENSION && isEntrance)
|
||||
room->descriptor->flags |= ROOM_DESCRIPTOR_FLAG_SACRIFICE_DONE;
|
||||
|
||||
load_room();
|
||||
game.playerManager.trigger_new_room_effects();
|
||||
if (currentRoomIdx >= 0 && !isMazeMoved) enter_door_open(*this, previousType);
|
||||
UpdateVisibility();
|
||||
}
|
||||
+180
-47
@@ -4,6 +4,9 @@
|
||||
#include "game.h"
|
||||
#include "grid_entity_door.h"
|
||||
#include "hud.h"
|
||||
#include "lua_engine.h"
|
||||
#include "menu_special_seeds.h"
|
||||
#include "music_manager.h"
|
||||
#include "manager.h"
|
||||
#include "platform.h"
|
||||
#include "room.h"
|
||||
@@ -62,6 +65,38 @@ constexpr int STAGE_ID_DROSS = 28;
|
||||
constexpr int STAGE_ID_VOID = 26;
|
||||
|
||||
constexpr uint32_t CHALLENGE_XXXXXXXXL = 21;
|
||||
|
||||
// The Ascent's music: the alternate path's stages take the layers past the chapters'.
|
||||
constexpr int ALT_PATH_LAYER_FIRST = 3;
|
||||
constexpr int STAGE_ID_HOME = 35;
|
||||
constexpr int DIMENSION_MINESHAFT = 2;
|
||||
constexpr int ENEMY_TYPE_FIRST = 10;
|
||||
constexpr int ENEMY_TYPE_LAST = 999;
|
||||
constexpr int COLLECTIBLE_BERSERK = 704;
|
||||
|
||||
// The enemies' health that makes a room's music intense, growing with the floor (a Greed floor counting as two).
|
||||
constexpr float INTENSE_HEALTH_BASE = 40;
|
||||
constexpr float INTENSE_HEALTH_PER_STAGE = 14;
|
||||
constexpr float INTENSE_HEALTH_ALWAYS = 10000;
|
||||
constexpr float MINESHAFT_HEALTH_PER_PIT = 3;
|
||||
constexpr int GREED_STAGE_LAST_PAIRED = 4;
|
||||
constexpr int GREED_STAGE_SHOP = 5;
|
||||
constexpr int GREED_DEPTH_SHOP = 10;
|
||||
|
||||
// The endless basement's floor number as roman numerals, and the counts its jokes start at.
|
||||
struct RomanNumeral
|
||||
{
|
||||
int value;
|
||||
const char* text;
|
||||
};
|
||||
constexpr RomanNumeral ROMAN_NUMERALS[] = {{1000, "M"}, {900, "CM"}, {500, "D"}, {400, "CD"}, {100, "C"}, {90, "XC"},
|
||||
{50, "L"}, {40, "XL"}, {10, "X"}, {9, "IX"}, {5, "V"}, {4, "IV"},
|
||||
{1, "I"}};
|
||||
constexpr uint32_t NUMERAL_QUESTION = 3;
|
||||
constexpr uint32_t NUMERAL_EXCLAIM = 4;
|
||||
constexpr uint32_t NUMERAL_ELLIPSIS = 5;
|
||||
constexpr uint32_t NUMERAL_SPIKES = 1001;
|
||||
constexpr std::string_view DEATHMATCH_NAME_KEY = "Online/DEATHMATCH_NAME";
|
||||
constexpr uint32_t SPECIAL_DAILY_NO_CURSES = 18;
|
||||
constexpr uint32_t SPECIAL_DAILY_DEALS = 17;
|
||||
constexpr uint32_t SPECIAL_DAILY_CURSED = 37;
|
||||
@@ -532,7 +567,7 @@ void Level::Init(bool isResetLilPortalRoom)
|
||||
room->camera->position_center();
|
||||
room->camera->DoUpdate(false);
|
||||
TextureCache::Purge();
|
||||
FUN_00865260();
|
||||
static_cast<LuaEngine*>(g_luaEngine)->PostNewLevel();
|
||||
isLevelGenerating = false;
|
||||
}
|
||||
|
||||
@@ -2464,7 +2499,7 @@ void Level::load_room()
|
||||
|
||||
if (isUpdated && game.frameCount == entity.spawnFrame) entity.Update();
|
||||
}
|
||||
FUN_00865180();
|
||||
static_cast<LuaEngine*>(g_luaEngine)->PostNewRoom();
|
||||
if (!game.deathmatchManager.is_active()) return;
|
||||
game.deathmatchManager.type->Init();
|
||||
game.dizzyTargetIntensity = 0;
|
||||
@@ -2620,12 +2655,6 @@ bool Level::boss_count_adjust(int&, int&)
|
||||
reconstruction_missing("Level::boss_count_adjust 007523e0");
|
||||
}
|
||||
|
||||
// 0073fc80 Moves to another room.
|
||||
void Level::ChangeRoom(int, int)
|
||||
{
|
||||
reconstruction_missing("Level::ChangeRoom 0073fc80");
|
||||
}
|
||||
|
||||
// 0073fa20 Enters a room config directly, for debugging.
|
||||
void Level::DEBUG_goto_room(RoomConfig_Room*)
|
||||
{
|
||||
@@ -2727,18 +2756,6 @@ Vector Level::GetEnterPosition()
|
||||
return g_vectorZero;
|
||||
}
|
||||
|
||||
// 0073d9b0 A door slot as another shape sees it.
|
||||
int Level::get_door_slot(int, int, bool, int)
|
||||
{
|
||||
reconstruction_missing("Level::get_door_slot 0073d9b0");
|
||||
}
|
||||
|
||||
// 0073da40 The slot a door leads into.
|
||||
int Level::GetTargetSlot(int, int)
|
||||
{
|
||||
reconstruction_missing("Level::GetTargetSlot 0073da40");
|
||||
}
|
||||
|
||||
// 0074c160 The cell a door leads to.
|
||||
XY Level::get_door_neighbor_pos(XY, RoomShape, int)
|
||||
{
|
||||
@@ -2787,12 +2804,6 @@ void Level::UncoverHiddenDoor(int, int)
|
||||
reconstruction_missing("Level::UncoverHiddenDoor 0074a1b0");
|
||||
}
|
||||
|
||||
// 0074d4a0 Prepares a Blue Key room.
|
||||
bool Level::prepare_blue_room(int, int, int)
|
||||
{
|
||||
reconstruction_missing("Level::prepare_blue_room 0074d4a0");
|
||||
}
|
||||
|
||||
// 0074d780 Adds a second boss room.
|
||||
bool Level::TryInitializeExtraBossRoom(uint32_t)
|
||||
{
|
||||
@@ -2884,10 +2895,80 @@ void Level::RemoveCurses(uint32_t)
|
||||
reconstruction_missing("Level::RemoveCurses 00748bc0");
|
||||
}
|
||||
|
||||
// 007eb870 Updates the Ascent's stages.
|
||||
// The music layer the Ascent turns on for a stage it climbs through: one per chapter, the alternate paths' past them.
|
||||
static int backwards_layer_get(int ascentStage)
|
||||
{
|
||||
uint32_t stageType = g_game->backwardsStages[ascentStage - 1].stageType;
|
||||
bool isAltPath = stageType == STAGETYPE_REPENTANCE || stageType == STAGETYPE_REPENTANCE_B;
|
||||
return isAltPath ? (ascentStage - 2) / 2 + ALT_PATH_LAYER_FIRST : (ascentStage - 1) / 2;
|
||||
}
|
||||
|
||||
// 007eb870 Sets the current track's layers for the room the players are in (the original's this is the room). On the
|
||||
// Ascent each layer is a stage climbed through outside its boss room. Elsewhere the intense layer plays while the
|
||||
// room's enemies have health enough for the floor (always from the Blue Womb on, and with Berserk), the Mines' chase
|
||||
// counting its pits. Nothing changes in the Home's dungeon or in Home's alternate. True when a layer plays.
|
||||
bool Level::UpdateBackwardsPathStages()
|
||||
{
|
||||
reconstruction_missing("Level::UpdateBackwardsPathStages 007eb870");
|
||||
Game& game = *g_game;
|
||||
MusicManager& music = g_manager->musicManager;
|
||||
RoomDescriptor* descriptor = room->descriptor;
|
||||
RoomConfig_Room* data = descriptor->data;
|
||||
|
||||
if (data && data->type == ROOM_DUNGEON && data->stageId == STAGE_ID_HOME) return false;
|
||||
int floor = (int)game.stage;
|
||||
bool isAscentFloor = floor >= (int)LEVEL_STAGE_BASEMENT_I && floor <= (int)ASCENT_LAST_STAGE;
|
||||
if (isAscentFloor && (game.gameStateFlags >> LEVEL_GAME_STATE_BACKWARDS_PATH & 1))
|
||||
{
|
||||
bool isAltPath = game.stageType == STAGETYPE_REPENTANCE || game.stageType == STAGETYPE_REPENTANCE_B;
|
||||
int first = floor + (isAltPath ? 1 : 0);
|
||||
uint32_t layers = 0;
|
||||
for (int ascentStage = first; ascentStage <= BACKWARDS_STAGE_COUNT; ascentStage++)
|
||||
if (ascentStage != first || game.room->descriptor->listIndex != game.lastBossRoomListIdx)
|
||||
layers |= 1u << backwards_layer_get(ascentStage);
|
||||
for (int layer = 0; layer < MUSIC_LAYER_COUNT; layer++)
|
||||
layers >> layer & 1 ? music.EnableLayer(layer, LAYER_FADE) : music.DisableLayer(layer);
|
||||
return layers != 0;
|
||||
}
|
||||
if (!isAscentFloor && floor == (int)LEVEL_STAGE_HOME && game.stageType == STAGETYPE_WOTL) return true;
|
||||
|
||||
int depth = floor;
|
||||
if (game.IsGreedMode()) depth = floor <= GREED_STAGE_LAST_PAIRED ? floor * 2 - 1 : floor == GREED_STAGE_SHOP ? GREED_DEPTH_SHOP : 0;
|
||||
float threshold = (float)depth * INTENSE_HEALTH_PER_STAGE + INTENSE_HEALTH_BASE;
|
||||
float health = 0;
|
||||
for (size_t i = 0; i < game.playerManager.playerList.size(); i++)
|
||||
if (game.GetPlayer((int)i)->temporaryEffects.HasCollectibleEffect(COLLECTIBLE_BERSERK))
|
||||
{
|
||||
health = INTENSE_HEALTH_ALWAYS;
|
||||
break;
|
||||
}
|
||||
|
||||
if (floor < (int)LEVEL_STAGE_BLUE_WOMB)
|
||||
{
|
||||
for (Entity* entity : room->entityList.updateEL)
|
||||
{
|
||||
bool isCounted = (game.deathmatchManager.is_active() && entity->type == ENTITY_PLAYER) ||
|
||||
(entity->type >= ENEMY_TYPE_FIRST && entity->type <= ENEMY_TYPE_LAST);
|
||||
if (isCounted && entity->CanShutDoors() && !entity->isDead && !entity->HasEntityFlags(FLAG_NO_TARGET))
|
||||
health += entity->health;
|
||||
}
|
||||
if (health > 0)
|
||||
{
|
||||
bool isMineshaft = false;
|
||||
if (game.challenge == CHALLENGE_RED_REDEMPTION)
|
||||
isMineshaft = RoomConfig::GetStageID(floor, GetRoomStageType(currentRoomIdx), ROOM_MODE_CURRENT) == STAGE_ID_MINES;
|
||||
else if (game.currentDimensionIdx != DIMENSION_MINESHAFT)
|
||||
isMineshaft = RoomConfig::GetStageID(floor, (int)game.stageType, ROOM_MODE_CURRENT) == STAGE_ID_MINES;
|
||||
uint32_t flags = descriptor->flags;
|
||||
bool isChase = isMineshaft && !(flags & ROOM_DESCRIPTOR_FLAG_CLEAR) && (flags & ROOM_DESCRIPTOR_FLAG_HAS_WATER) &&
|
||||
!(flags & ROOM_DESCRIPTOR_FLAG_FLOODED);
|
||||
if (isChase) health += (float)descriptor->pitsCount * MINESHAFT_HEALTH_PER_PIT;
|
||||
}
|
||||
}
|
||||
else if (!(descriptor->flags & ROOM_DESCRIPTOR_FLAG_CLEAR)) health += INTENSE_HEALTH_ALWAYS;
|
||||
|
||||
bool isIntense = health >= threshold;
|
||||
isIntense ? music.EnableLayer(0, LAYER_FADE) : music.DisableLayer(0);
|
||||
return isIntense;
|
||||
}
|
||||
|
||||
// 0074b960 The stage counted as in normal runs.
|
||||
@@ -2926,22 +3007,86 @@ RoomDescriptor* Level::get_secret_exit_room(int)
|
||||
reconstruction_missing("Level::get_secret_exit_room 0074bba0");
|
||||
}
|
||||
|
||||
// 007460b0 The floor's name.
|
||||
// 00745ca0 A stage's display name in the current language: stages.xml's, then the endless basement's roman numeral and
|
||||
// its jokes, then " I" or " II" for a chapter's floor or " XL" for a labyrinth, scrambled for dyslexia. Greed and Red
|
||||
// Redemption add no floor number. Empty for no stage.
|
||||
std::string Level::get_stage_display_name(const StageNameQuery& query)
|
||||
{
|
||||
if (query.stage == 0) return "";
|
||||
|
||||
Game& game = *g_game;
|
||||
RoomMode mode = query.mode;
|
||||
if (mode == ROOM_MODE_CURRENT) mode = g_game && g_game->IsGreedMode() ? ROOM_MODE_GREED : ROOM_MODE_NORMAL;
|
||||
int stageId = RoomConfig::GetStageID(query.stage, query.stageType, mode);
|
||||
std::string name = game.roomConfig.stages[stageId].GetDisplayName(LANGUAGE_CURRENT);
|
||||
|
||||
if (query.numeral > 0)
|
||||
{
|
||||
name += ' ';
|
||||
int remaining = query.numeral;
|
||||
for (const RomanNumeral& numeral : ROMAN_NUMERALS)
|
||||
for (; remaining >= numeral.value; remaining -= numeral.value) name += numeral.text;
|
||||
|
||||
uint32_t count = (uint32_t)game.stageNameNumeral;
|
||||
if (count == NUMERAL_QUESTION) name += "?";
|
||||
if (count == NUMERAL_EXCLAIM) name += "?!";
|
||||
if (count == NUMERAL_ELLIPSIS) name += "...";
|
||||
if (count == NUMERAL_SPIKES) name += " Spikes";
|
||||
if (count % 1000 == 0) name += "... Please stop.";
|
||||
else if (count % 500 == 0) name += "!V";
|
||||
else if (count % 100 == 0) name += "!!!";
|
||||
else if (count % 50 == 0) name += "!!";
|
||||
else if (count % 10 == 0) name += "!";
|
||||
}
|
||||
|
||||
bool isNumbered = mode != ROOM_MODE_GREED && game.challenge != CHALLENGE_RED_REDEMPTION;
|
||||
if (isNumbered && (query.curses & CURSE_OF_LABYRINTH)) name += " XL";
|
||||
else if (isNumbered && query.numeral == 0 && query.stage >= 1 && query.stage <= (int)LEVEL_STAGE_WOMB_II)
|
||||
name += query.stage & 1 ? " I" : " II";
|
||||
return query.isScrambled ? string_scramble_seeded(name) : name;
|
||||
}
|
||||
|
||||
// 007460b0 The floor's name, with Red Redemption's room stage type, the endless basement's numeral and dyslexia.
|
||||
std::string Level::GetName()
|
||||
{
|
||||
reconstruction_missing("Level::GetName 007460b0");
|
||||
Game& game = *g_game;
|
||||
bool isRedRedemption = game.challenge == CHALLENGE_RED_REDEMPTION;
|
||||
|
||||
return get_stage_display_name({.stage = (int)stage,
|
||||
.stageType = isRedRedemption ? GetRoomStageType(currentRoomIdx) : (int)stageType,
|
||||
.curses = GetCurses(),
|
||||
.numeral = game.seedEffects.HasSeedEffect(SEED_INFINITE_BASEMENT) ? game.stageNameNumeral : 0,
|
||||
.isScrambled = game.seedEffects.HasSeedEffect(SEED_DYSLEXIA),
|
||||
.mode = ROOM_MODE_CURRENT});
|
||||
}
|
||||
|
||||
// 00746260 The floor's curse's name.
|
||||
// 00746260 The name of the floor's first curse, scrambled for dyslexia. Empty for none.
|
||||
std::string Level::GetCurseName()
|
||||
{
|
||||
reconstruction_missing("Level::GetCurseName 00746260");
|
||||
Game& game = *g_game;
|
||||
std::string name;
|
||||
|
||||
for (uint32_t curse = 0; curse < game.roomConfig.curses.size(); curse++)
|
||||
if (GetCurses() & 1u << curse)
|
||||
{
|
||||
name = game.roomConfig.GetCurseName(curse + 1);
|
||||
break;
|
||||
}
|
||||
return game.seedEffects.HasSeedEffect(SEED_DYSLEXIA) ? string_scramble_seeded(name) : name;
|
||||
}
|
||||
|
||||
// 00746560 Shows the floor's name.
|
||||
void Level::ShowName(bool)
|
||||
// 00746560 Shows the floor's name and curse in the HUD's banner, hiding by itself unless sticky. Versus shows its own.
|
||||
void Level::ShowName(bool isSticky)
|
||||
{
|
||||
reconstruction_missing("Level::ShowName 00746560");
|
||||
std::string name = GetName();
|
||||
std::string curse = GetCurseName();
|
||||
|
||||
if (g_game->deathmatchManager.is_active())
|
||||
{
|
||||
name = g_manager->stringTable.translate(DEATHMATCH_NAME_KEY);
|
||||
curse.clear();
|
||||
}
|
||||
g_game->hud.messageMain.Show(name.c_str(), curse.c_str(), !isSticky, !curse.empty());
|
||||
}
|
||||
|
||||
// 007475b0 Restores the floor from a save.
|
||||
@@ -2950,18 +3095,6 @@ void Level::RestoreGameState(GameState&)
|
||||
reconstruction_missing("Level::RestoreGameState 007475b0");
|
||||
}
|
||||
|
||||
// 00747e10 Saves the floor.
|
||||
void Level::store_game_state(GameState&)
|
||||
{
|
||||
reconstruction_missing("Level::store_game_state 00747e10");
|
||||
}
|
||||
|
||||
// 00747360 Saves a room config's id.
|
||||
void Level::write_room_config(RoomConfig_Room*, void*, void*)
|
||||
{
|
||||
reconstruction_missing("Level::write_room_config 00747360");
|
||||
}
|
||||
|
||||
// 007474a0 The room config a saved id names.
|
||||
RoomConfig_Room* Level::get_room_config_from_saved_id(uint32_t*, void*)
|
||||
{
|
||||
|
||||
+14
-1
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "classes.h"
|
||||
#include "entity_save_state.h"
|
||||
#include "level_generator.h"
|
||||
#include "room_descriptor.h"
|
||||
#include "seeds.h"
|
||||
@@ -84,6 +85,18 @@ enum StageType : uint32_t
|
||||
STAGETYPE_REPENTANCE_B
|
||||
};
|
||||
|
||||
// What get_stage_display_name names: a stage and its type, the curses (a labyrinth's XL), the endless basement's
|
||||
// numeral, dyslexia's scrambling, and the mode to number it in (the game's by default).
|
||||
struct StageNameQuery
|
||||
{
|
||||
int stage = 0;
|
||||
int stageType = 0;
|
||||
uint32_t curses = 0;
|
||||
int numeral = 0;
|
||||
bool isScrambled = false;
|
||||
RoomMode mode = ROOM_MODE_CURRENT;
|
||||
};
|
||||
|
||||
// A Ventricle Razor portal: the room and grid cell it stands on (no room by default), and a flag its user passes.
|
||||
struct VentricleRazorPortal
|
||||
{
|
||||
@@ -240,11 +253,11 @@ public:
|
||||
int get_secret_exit_kind();
|
||||
RoomDescriptor* get_secret_exit_room(int kind);
|
||||
|
||||
static std::string get_stage_display_name(const StageNameQuery& query);
|
||||
std::string GetName();
|
||||
std::string GetCurseName();
|
||||
void ShowName(bool isSticky);
|
||||
void RestoreGameState(GameState& state);
|
||||
void store_game_state(GameState& state);
|
||||
static void write_room_config(RoomConfig_Room* roomConfig, void* gameStateRoom, void* deque);
|
||||
static RoomConfig_Room* get_room_config_from_saved_id(uint32_t* savedId, void* mergeTable);
|
||||
};
|
||||
+2
-2
@@ -82,8 +82,8 @@ static void ascent_stage_set(Level& level)
|
||||
|
||||
auto& stages = g_game->backwardsStages;
|
||||
int next = floor - 1;
|
||||
if (next > 1 && stages[next - 2]._isXL) next--;
|
||||
if (is_repentance_type(stages[next - 1]._stageType)) return level.SetStage(next - 1, STAGETYPE_REPENTANCE);
|
||||
if (next > 1 && stages[next - 2].isXL) next--;
|
||||
if (is_repentance_type(stages[next - 1].stageType)) return level.SetStage(next - 1, STAGETYPE_REPENTANCE);
|
||||
level.SetStage(next, STAGETYPE_ORIGINAL);
|
||||
}
|
||||
|
||||
|
||||
@@ -81,6 +81,12 @@ const void* lua_class_key(LuaClass luaClass)
|
||||
return &classKeys[luaClass];
|
||||
}
|
||||
|
||||
// Stops where a mod has a function for a callback LuaEngine does not run yet.
|
||||
void lua_callback_check(int callback, const char* name)
|
||||
{
|
||||
if (static_cast<LuaEngine*>(g_luaEngine)->enabledCallbacks[callback]) reconstruction_missing(name);
|
||||
}
|
||||
|
||||
// Pushes a callback argument: integers and booleans as themselves.
|
||||
static void value_push(lua_State* state, int value)
|
||||
{
|
||||
@@ -507,6 +513,18 @@ void LuaEngine::PostKnifeInit(Entity_Knife* knife)
|
||||
LuaObject{knife, LUA_CLASS_KNIFE});
|
||||
}
|
||||
|
||||
// 00865260 Runs MC_POST_NEW_LEVEL once a floor is generated and its first room entered.
|
||||
void LuaEngine::PostNewLevel()
|
||||
{
|
||||
callback_notify(*this, {"PostNewLevel", MC_POST_NEW_LEVEL});
|
||||
}
|
||||
|
||||
// 00865180 Runs MC_POST_NEW_ROOM once a room is loaded.
|
||||
void LuaEngine::PostNewRoom()
|
||||
{
|
||||
callback_notify(*this, {"PostNewRoom", MC_POST_NEW_ROOM});
|
||||
}
|
||||
|
||||
// 00864050 Runs MC_POST_PLAYER_INIT, filtered by the player's variant.
|
||||
void LuaEngine::PostPlayerInit(Entity_Player* player)
|
||||
{
|
||||
|
||||
@@ -35,6 +35,8 @@ enum LuaCallback
|
||||
MC_POST_PLAYER_INIT = 9,
|
||||
MC_USE_PILL = 10,
|
||||
MC_POST_GAME_STARTED = 15,
|
||||
MC_POST_NEW_LEVEL = 18,
|
||||
MC_POST_NEW_ROOM = 19,
|
||||
MC_PRE_FAMILIAR_COLLISION = 26,
|
||||
MC_PRE_NPC_COLLISION = 30,
|
||||
MC_PRE_PLAYER_COLLISION = 33,
|
||||
@@ -149,6 +151,8 @@ struct LuaEngine
|
||||
void PostEntityKill(Entity* entity);
|
||||
void PostGameStart(bool isContinued);
|
||||
void PostKnifeInit(Entity_Knife* knife);
|
||||
void PostNewLevel();
|
||||
void PostNewRoom();
|
||||
void PostPlayerInit(Entity_Player* player);
|
||||
void PostRender();
|
||||
bool UseItem(LuaItemUse& use);
|
||||
@@ -156,3 +160,4 @@ struct LuaEngine
|
||||
};
|
||||
|
||||
const void* lua_class_key(LuaClass luaClass);
|
||||
void lua_callback_check(int callback, const char* name);
|
||||
+665
@@ -0,0 +1,665 @@
|
||||
#include "npc_ai.h"
|
||||
#include "game.h"
|
||||
#include "manager.h"
|
||||
#include "sfx_manager.h"
|
||||
|
||||
// The Beast's forms, by variant: its stalactites, rocks and soul, the four ultra horsemen and their summons, and
|
||||
// the background beasts.
|
||||
static void beast_update(Entity_NPC& npc)
|
||||
{
|
||||
switch (npc.variant)
|
||||
{
|
||||
case 1:
|
||||
return NpcAI::ENTITY_BEAST_stalactite(&npc);
|
||||
case 2:
|
||||
return NpcAI::ENTITY_BEAST_rock_projectile(&npc);
|
||||
case 3:
|
||||
return NpcAI::ENTITY_BEAST_soul(&npc);
|
||||
case 10:
|
||||
return NpcAI::ENTITY_BEAST_ultra_famine(&npc);
|
||||
case 11:
|
||||
return NpcAI::ENTITY_BEAST_ultra_famine_fly(&npc);
|
||||
case 20:
|
||||
return NpcAI::ENTITY_BEAST_ultra_pestilence(&npc);
|
||||
case 21:
|
||||
return NpcAI::ENTITY_BEAST_pestilence_fly(&npc);
|
||||
case 22:
|
||||
return NpcAI::ENTITY_BEAST_ultra_pestilence_maggot(&npc);
|
||||
case 23:
|
||||
return NpcAI::ENTITY_BEAST_ultra_pestilence_fly_ball(&npc);
|
||||
case 30:
|
||||
return NpcAI::ENTITY_BEAST_ultra_war(&npc);
|
||||
case 31:
|
||||
return NpcAI::ENTITY_BEAST_ultra_war_bomb(&npc);
|
||||
case 40:
|
||||
return NpcAI::ENTITY_BEAST_ultra_death(&npc);
|
||||
case 41:
|
||||
return NpcAI::ENTITY_BEAST_ultra_death_scythe(&npc);
|
||||
case 42:
|
||||
return NpcAI::ENTITY_BEAST_ultra_death_head(&npc);
|
||||
case 100:
|
||||
case 101:
|
||||
case 102:
|
||||
case 103:
|
||||
case 104:
|
||||
return NpcAI::ENTITY_BEAST_background(&npc);
|
||||
default:
|
||||
return NpcAI::ENTITY_BEAST(&npc);
|
||||
}
|
||||
}
|
||||
|
||||
// Mother's forms, by variant: her two phases, her rotten gapers, worms and balls.
|
||||
static void mother_update(Entity_NPC& npc)
|
||||
{
|
||||
switch (npc.variant)
|
||||
{
|
||||
case 0:
|
||||
return NpcAI::ENTITY_MOTHER(&npc);
|
||||
case 10:
|
||||
return NpcAI::ENTITY_MOTHER_2(&npc);
|
||||
case 20:
|
||||
return NpcAI::ENTITY_ROTTEN_GAPER(&npc);
|
||||
case 30:
|
||||
return NpcAI::ENTITY_MOTHER_worm(&npc);
|
||||
case 100:
|
||||
return NpcAI::ENTITY_MOTHER_ball(&npc);
|
||||
}
|
||||
}
|
||||
|
||||
// The AI routine of each NPC type. Types it does not list (the ones the game left without an AI) do nothing.
|
||||
static void npc_ai_routine_run(Entity_NPC& npc)
|
||||
{
|
||||
switch (npc.type)
|
||||
{
|
||||
case 10:
|
||||
case 208:
|
||||
case 252:
|
||||
case 257:
|
||||
case 284:
|
||||
case 302:
|
||||
case 807:
|
||||
return npc_gaper_update(npc);
|
||||
case 11:
|
||||
case 210:
|
||||
case 211:
|
||||
case 238:
|
||||
case 280:
|
||||
return (void)NpcAI::ENTITY_GUSHER(&npc);
|
||||
case 12:
|
||||
case 248:
|
||||
return npc_horf_update(npc);
|
||||
case 13:
|
||||
case 14:
|
||||
case 18:
|
||||
case 61:
|
||||
case 80:
|
||||
case 214:
|
||||
case 249:
|
||||
case 819:
|
||||
return npc_fly_update(npc);
|
||||
case 15:
|
||||
case 282:
|
||||
case 872:
|
||||
return (void)NpcAI::ENTITY_CLOTTY(&npc);
|
||||
case 16:
|
||||
return (void)NpcAI::ENTITY_MULLIGAN(&npc);
|
||||
case 17:
|
||||
return (void)NpcAI::ENTITY_SHOPKEEPER(&npc);
|
||||
case 19:
|
||||
case 89:
|
||||
case 239:
|
||||
return (void)NpcAI::ENTITY_LARRYJR(&npc);
|
||||
case 20:
|
||||
case 43:
|
||||
return (void)NpcAI::ENTITY_MONSTRO(&npc);
|
||||
case 21:
|
||||
case 23:
|
||||
case 31:
|
||||
case 55:
|
||||
case 237:
|
||||
case 243:
|
||||
return (void)NpcAI::ENTITY_MAGGOT(&npc);
|
||||
case 22:
|
||||
case 205:
|
||||
case 817:
|
||||
return (void)NpcAI::ENTITY_HIVE(&npc);
|
||||
case 24:
|
||||
case 278:
|
||||
return (void)NpcAI::ENTITY_GLOBIN(&npc);
|
||||
case 25:
|
||||
return (void)NpcAI::ENTITY_BOOMFLY(&npc);
|
||||
case 26:
|
||||
return (void)NpcAI::ENTITY_MAW(&npc);
|
||||
case 27:
|
||||
case 859:
|
||||
return (void)NpcAI::ENTITY_HOST(&npc);
|
||||
case 28:
|
||||
return (void)NpcAI::ENTITY_CHUB(&npc);
|
||||
case 29:
|
||||
case 34:
|
||||
case 54:
|
||||
case 86:
|
||||
case 246:
|
||||
case 305:
|
||||
case 840:
|
||||
return (void)NpcAI::ENTITY_HOPPER(&npc);
|
||||
case 30:
|
||||
return (void)NpcAI::ENTITY_BOIL(&npc);
|
||||
case 32:
|
||||
case 279:
|
||||
case 301:
|
||||
return (void)NpcAI::ENTITY_BRAIN(&npc);
|
||||
case 33:
|
||||
return (void)NpcAI::ENTITY_FIREPLACE(&npc);
|
||||
case 35:
|
||||
return (void)NpcAI::ENTITY_MRMAW(&npc);
|
||||
case 36:
|
||||
return (void)NpcAI::ENTITY_GURDY(&npc);
|
||||
case 38:
|
||||
case 259:
|
||||
return (void)NpcAI::ENTITY_BABY(&npc);
|
||||
case 39:
|
||||
case 49:
|
||||
case 836:
|
||||
return (void)NpcAI::ENTITY_VIS(&npc);
|
||||
case 40:
|
||||
case 218:
|
||||
case 862:
|
||||
return (void)NpcAI::ENTITY_GUTS(&npc);
|
||||
case 41:
|
||||
case 254:
|
||||
case 283:
|
||||
return (void)NpcAI::ENTITY_KNIGHT(&npc);
|
||||
case 42:
|
||||
case 203:
|
||||
case 235:
|
||||
case 236:
|
||||
return (void)NpcAI::ENTITY_STONEHEAD(&npc);
|
||||
case 44:
|
||||
return (void)NpcAI::ENTITY_POKY(&npc);
|
||||
case 45:
|
||||
return (void)NpcAI::ENTITY_MOM(&npc);
|
||||
case 46:
|
||||
return (void)NpcAI::ENTITY_SLOTH(&npc);
|
||||
case 47:
|
||||
return (void)NpcAI::ENTITY_LUST(&npc);
|
||||
case 48:
|
||||
return (void)NpcAI::ENTITY_WRATH(&npc);
|
||||
case 50:
|
||||
return (void)NpcAI::ENTITY_GREED(&npc);
|
||||
case 51:
|
||||
return (void)NpcAI::ENTITY_ENVY(&npc);
|
||||
case 52:
|
||||
return (void)NpcAI::ENTITY_PRIDE(&npc);
|
||||
case 53:
|
||||
return (void)NpcAI::ENTITY_DOPLE(&npc);
|
||||
case 56:
|
||||
return (void)NpcAI::ENTITY_LUMP(&npc);
|
||||
case 57:
|
||||
case 223:
|
||||
return (void)NpcAI::ENTITY_MEMBRAIN(&npc);
|
||||
case 58:
|
||||
return (void)NpcAI::ENTITY_PARA_BITE(&npc);
|
||||
case 59:
|
||||
return (void)NpcAI::ENTITY_FRED(&npc);
|
||||
case 60:
|
||||
return (void)NpcAI::ENTITY_EYE(&npc);
|
||||
case 62:
|
||||
return (void)NpcAI::ENTITY_PIN(&npc);
|
||||
case 63:
|
||||
return (void)NpcAI::ENTITY_FAMINE(&npc);
|
||||
case 64:
|
||||
return (void)NpcAI::ENTITY_PESTILENCE(&npc);
|
||||
case 65:
|
||||
return (void)NpcAI::ENTITY_WAR(&npc);
|
||||
case 66:
|
||||
return (void)NpcAI::ENTITY_DEATH(&npc);
|
||||
case 67:
|
||||
return (void)NpcAI::ENTITY_DUKE(&npc);
|
||||
case 68:
|
||||
return (void)NpcAI::ENTITY_PEEP(&npc);
|
||||
case 69:
|
||||
return (void)NpcAI::ENTITY_LOKI(&npc);
|
||||
case 71:
|
||||
case 72:
|
||||
case 73:
|
||||
return (void)NpcAI::ENTITY_FISTULA_BIG(&npc);
|
||||
case 74:
|
||||
case 75:
|
||||
case 76:
|
||||
return (void)NpcAI::ENTITY_BLASTOCYST_BIG(&npc);
|
||||
case 77:
|
||||
return (void)NpcAI::ENTITY_EMBRYO(&npc);
|
||||
case 78:
|
||||
return (void)NpcAI::ENTITY_MOMS_HEART(&npc);
|
||||
case 79:
|
||||
reconstruction_missing("npc_ai_update 006c2990: Gemini's parts and death shots");
|
||||
case 81:
|
||||
return (void)NpcAI::ENTITY_FALLEN(&npc);
|
||||
case 82:
|
||||
case 83:
|
||||
return (void)NpcAI::ENTITY_HEADLESS_HORSEMAN(&npc);
|
||||
case 84:
|
||||
return (void)NpcAI::ENTITY_SATAN(&npc);
|
||||
case 85:
|
||||
case 94:
|
||||
case 215:
|
||||
case 250:
|
||||
case 869:
|
||||
return (void)NpcAI::ENTITY_SPIDER(&npc);
|
||||
case 87:
|
||||
return (void)NpcAI::ENTITY_GURGLE(&npc);
|
||||
case 88:
|
||||
return (void)NpcAI::ENTITY_WALKINGBOIL(&npc);
|
||||
case 90:
|
||||
return (void)NpcAI::ENTITY_HANGER(&npc);
|
||||
case 91:
|
||||
case 229:
|
||||
case 230:
|
||||
case 253:
|
||||
return (void)NpcAI::ENTITY_SWARMER(&npc);
|
||||
case 92:
|
||||
return (void)NpcAI::ENTITY_HEART(&npc);
|
||||
case 93:
|
||||
reconstruction_missing("npc_ai_update 006c2990: Mask pairing with its Heart");
|
||||
case 96:
|
||||
return (void)NpcAI::ENTITY_ETERNALFLY(&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);
|
||||
case 100:
|
||||
return (void)NpcAI::ENTITY_WIDOW(&npc);
|
||||
case 101:
|
||||
return (void)NpcAI::ENTITY_DADDYLONGLEGS(&npc);
|
||||
case 102:
|
||||
return (void)NpcAI::ENTITY_ISAAC(&npc);
|
||||
case 201:
|
||||
return (void)NpcAI::ENTITY_STONE_EYE(&npc);
|
||||
case 202:
|
||||
return (void)NpcAI::ENTITY_CONSTANT_STONE_SHOOTER(&npc);
|
||||
case 204:
|
||||
case 247:
|
||||
return (void)NpcAI::ENTITY_MOBILE_HOST(&npc);
|
||||
case 206:
|
||||
case 207:
|
||||
return (void)NpcAI::ENTITY_BABY_LONG_LEGS(&npc);
|
||||
case 209:
|
||||
return (void)NpcAI::ENTITY_FAT_SACK(&npc);
|
||||
case 212:
|
||||
case 286:
|
||||
return (void)NpcAI::ENTITY_DEATHS_HEAD(&npc);
|
||||
case 213:
|
||||
case 287:
|
||||
return (void)NpcAI::ENTITY_MOMS_HAND(&npc);
|
||||
case 216:
|
||||
return (void)NpcAI::ENTITY_SWINGER(&npc);
|
||||
case 217:
|
||||
case 870:
|
||||
return npc_dip_update(npc);
|
||||
case 219:
|
||||
case 285:
|
||||
return (void)NpcAI::ENTITY_WIZOOB(&npc);
|
||||
case 220:
|
||||
case 871:
|
||||
return (void)NpcAI::ENTITY_SQUIRT(&npc);
|
||||
case 221:
|
||||
return (void)NpcAI::ENTITY_COD_WORM(&npc);
|
||||
case 222:
|
||||
return (void)NpcAI::ENTITY_RING_OF_FLIES(&npc);
|
||||
case 224:
|
||||
return (void)NpcAI::ENTITY_OOB(&npc);
|
||||
case 225:
|
||||
return (void)NpcAI::ENTITY_BLACK_MAW(&npc);
|
||||
case 226:
|
||||
case 227:
|
||||
case 277:
|
||||
return (void)NpcAI::ENTITY_SKINNY(&npc);
|
||||
case 228:
|
||||
case 251:
|
||||
return (void)NpcAI::ENTITY_HOMUNCULUS(&npc);
|
||||
case 231:
|
||||
case 964:
|
||||
return (void)NpcAI::ENTITY_NERVE_ENDING(&npc);
|
||||
case 232:
|
||||
case 234:
|
||||
return (void)NpcAI::ENTITY_SKINBALL(&npc);
|
||||
case 240:
|
||||
case 241:
|
||||
case 242:
|
||||
case 304:
|
||||
return (void)NpcAI::ENTITY_WALL_CREEP(&npc);
|
||||
case 244:
|
||||
case 255:
|
||||
case 276:
|
||||
case 289:
|
||||
return (void)NpcAI::ENTITY_ROUND_WORM(&npc);
|
||||
case 245:
|
||||
return (void)NpcAI::ENTITY_POOP(&npc);
|
||||
case 256:
|
||||
return (void)NpcAI::ENTITY_DART_FLY(&npc);
|
||||
case 258:
|
||||
return (void)NpcAI::ENTITY_FAT_BAT(&npc);
|
||||
case 260:
|
||||
return (void)NpcAI::ENTITY_THE_HAUNT(&npc);
|
||||
case 261:
|
||||
return (void)NpcAI::ENTITY_DINGLE(&npc);
|
||||
case 262:
|
||||
return (void)NpcAI::ENTITY_MEGA_MAW(&npc);
|
||||
case 263:
|
||||
return (void)NpcAI::ENTITY_GATE(&npc);
|
||||
case 264:
|
||||
return (void)NpcAI::ENTITY_MEGA_FATTY(&npc);
|
||||
case 265:
|
||||
return (void)NpcAI::ENTITY_CAGE(&npc);
|
||||
case 266:
|
||||
return (void)NpcAI::ENTITY_MAMA_GURDY(&npc);
|
||||
case 267:
|
||||
return (void)NpcAI::ENTITY_DARK_ONE(&npc);
|
||||
case 268:
|
||||
return (void)NpcAI::ENTITY_ADVERSARY(&npc);
|
||||
case 269:
|
||||
case 401:
|
||||
return (void)NpcAI::ENTITY_POLYCEPHALUS(&npc);
|
||||
case 270:
|
||||
return (void)NpcAI::ENTITY_MR_FRED(&npc);
|
||||
case 271:
|
||||
case 272:
|
||||
return (void)NpcAI::ENTITY_URIEL(&npc);
|
||||
case 273:
|
||||
return (void)NpcAI::ENTITY_THE_LAMB(&npc);
|
||||
case 274:
|
||||
case 275:
|
||||
if (npc.variant != 0) return NpcAI::ENTITY_MEGA_SATAN_hand(&npc);
|
||||
NpcAI::ENTITY_MEGA_SATAN(&npc);
|
||||
if (npc.isDead) npc.ClearEntityFlags(FLAG_NO_DEATH_TRIGGER);
|
||||
return;
|
||||
case 281:
|
||||
return (void)NpcAI::ENTITY_SWARM(&npc);
|
||||
case 288:
|
||||
return (void)NpcAI::ENTITY_DUKIE(&npc);
|
||||
case 290:
|
||||
return (void)NpcAI::ENTITY_MEATBALL(&npc);
|
||||
case 291:
|
||||
return (void)NpcAI::ENTITY_PITFALL(&npc);
|
||||
case 292:
|
||||
return (void)NpcAI::ENTITY_MOVABLE_TNT(&npc);
|
||||
case 293:
|
||||
return (void)NpcAI::ENTITY_ULTRA_COIN(&npc);
|
||||
case 294:
|
||||
return (void)NpcAI::ENTITY_ULTRA_DOOR(&npc);
|
||||
case 295:
|
||||
return (void)NpcAI::ENTITY_CORN_MINE(&npc);
|
||||
case 296:
|
||||
return (void)NpcAI::ENTITY_HUSH_FLY(&npc);
|
||||
case 297:
|
||||
return (void)NpcAI::ENTITY_HUSH_GAPER(&npc);
|
||||
case 298:
|
||||
return (void)NpcAI::ENTITY_HUSH_BOIL(&npc);
|
||||
case 299:
|
||||
return (void)NpcAI::ENTITY_GREED_GAPER(&npc);
|
||||
case 300:
|
||||
return (void)NpcAI::ENTITY_MUSHROOM(&npc);
|
||||
case 303:
|
||||
return (void)NpcAI::ENTITY_BLISTER(&npc);
|
||||
case 306:
|
||||
return (void)NpcAI::ENTITY_PORTAL(&npc);
|
||||
case 307:
|
||||
return (void)NpcAI::ENTITY_TARBOY(&npc);
|
||||
case 308:
|
||||
return (void)NpcAI::ENTITY_FISTULOID(&npc);
|
||||
case 309:
|
||||
return (void)NpcAI::ENTITY_GUSH(&npc);
|
||||
case 310:
|
||||
return (void)NpcAI::ENTITY_LEPER(&npc);
|
||||
case 311:
|
||||
return (void)NpcAI::ENTITY_MR_MINE(&npc);
|
||||
case 402:
|
||||
return (void)NpcAI::ENTITY_BROWNIE(&npc);
|
||||
case 403:
|
||||
return (void)NpcAI::ENTITY_FORSAKEN(&npc);
|
||||
case 404:
|
||||
return (void)NpcAI::ENTITY_LITTLE_HORN(&npc);
|
||||
case 405:
|
||||
return (void)NpcAI::ENTITY_RAG_MAN(&npc);
|
||||
case 406:
|
||||
return (void)NpcAI::ENTITY_ULTRA_GREED(&npc);
|
||||
case 407:
|
||||
return (void)NpcAI::ENTITY_HUSH(&npc);
|
||||
case 409:
|
||||
return (void)NpcAI::ENTITY_RAG_MEGA(&npc);
|
||||
case 410:
|
||||
return (void)NpcAI::ENTITY_SISTERS_VIS(&npc);
|
||||
case 411:
|
||||
return (void)NpcAI::ENTITY_BIG_HORN(&npc);
|
||||
case 412:
|
||||
return (void)NpcAI::ENTITY_DELIRIUM(&npc);
|
||||
case 413:
|
||||
return (void)NpcAI::ENTITY_MATRIARCH(&npc);
|
||||
case 802:
|
||||
return (void)NpcAI::ENTITY_BLOOD_PUPPY(&npc);
|
||||
case 804:
|
||||
return (void)NpcAI::ENTITY_QUAKE_GRIMACE(&npc);
|
||||
case 805:
|
||||
return (void)NpcAI::ENTITY_BISHOP(&npc);
|
||||
case 806:
|
||||
return (void)NpcAI::ENTITY_BUBBLES(&npc);
|
||||
case 808:
|
||||
return (void)NpcAI::ENTITY_WILLO(&npc);
|
||||
case 809:
|
||||
return (void)NpcAI::ENTITY_BOMB_GRIMACE(&npc);
|
||||
case 810:
|
||||
return (void)NpcAI::ENTITY_SMALL_LEECH(&npc);
|
||||
case 811:
|
||||
return (void)NpcAI::ENTITY_DEEP_GAPER(&npc);
|
||||
case 812:
|
||||
return (void)NpcAI::ENTITY_SUB_HORF(&npc);
|
||||
case 813:
|
||||
return (void)NpcAI::ENTITY_BLURB(&npc);
|
||||
case 814:
|
||||
return (void)NpcAI::ENTITY_STRIDER(&npc);
|
||||
case 815:
|
||||
return (void)NpcAI::ENTITY_FISSURE(&npc);
|
||||
case 816:
|
||||
return (void)NpcAI::ENTITY_POLTY(&npc);
|
||||
case 818:
|
||||
return (void)NpcAI::ENTITY_ROCK_SPIDER(&npc);
|
||||
case 820:
|
||||
return (void)NpcAI::ENTITY_DANNY(&npc);
|
||||
case 821:
|
||||
return (void)NpcAI::ENTITY_BLASTER(&npc);
|
||||
case 822:
|
||||
return (void)NpcAI::ENTITY_BOUNCER(&npc);
|
||||
case 823:
|
||||
return (void)NpcAI::ENTITY_QUAKEY(&npc);
|
||||
case 824:
|
||||
return (void)NpcAI::ENTITY_GYRO(&npc);
|
||||
case 825:
|
||||
return (void)NpcAI::ENTITY_FIRE_WORM(&npc);
|
||||
case 826:
|
||||
return (void)NpcAI::ENTITY_HARDY(&npc);
|
||||
case 827:
|
||||
return (void)NpcAI::ENTITY_FACELESS(&npc);
|
||||
case 828:
|
||||
return (void)NpcAI::ENTITY_NECRO(&npc);
|
||||
case 829:
|
||||
return (void)NpcAI::ENTITY_MOLE(&npc);
|
||||
case 830:
|
||||
return (void)NpcAI::ENTITY_BIG_BONY(&npc);
|
||||
case 831:
|
||||
return (void)NpcAI::ENTITY_GUTTED_FATTY(&npc);
|
||||
case 832:
|
||||
return (void)NpcAI::ENTITY_EXORCIST(&npc);
|
||||
case 833:
|
||||
return (void)NpcAI::ENTITY_CANDLER(&npc);
|
||||
case 834:
|
||||
return (void)NpcAI::ENTITY_WHIPPER(&npc);
|
||||
case 835:
|
||||
return (void)NpcAI::ENTITY_PEEPER_FATTY(&npc);
|
||||
case 837:
|
||||
return (void)NpcAI::ENTITY_HENRY(&npc);
|
||||
case 838:
|
||||
return (void)NpcAI::ENTITY_WILLO_L2(&npc);
|
||||
case 841:
|
||||
return (void)NpcAI::ENTITY_REVENANT(&npc);
|
||||
case 844:
|
||||
return (void)NpcAI::ENTITY_BOMBGAGGER(&npc);
|
||||
case 850:
|
||||
return (void)NpcAI::ENTITY_GAPER_L2(&npc);
|
||||
case 851:
|
||||
return (void)NpcAI::ENTITY_TWITCHY(&npc);
|
||||
case 852:
|
||||
return (void)NpcAI::ENTITY_SPIKEBALL(&npc);
|
||||
case 853:
|
||||
return (void)NpcAI::ENTITY_SMALL_MAGGOT(&npc);
|
||||
case 854:
|
||||
return (void)NpcAI::ENTITY_ADULT_LEECH(&npc);
|
||||
case 855:
|
||||
return (void)NpcAI::ENTITY_CHARGER_L2(&npc);
|
||||
case 856:
|
||||
return (void)NpcAI::ENTITY_GASBAG(&npc);
|
||||
case 857:
|
||||
return (void)NpcAI::ENTITY_COHORT(&npc);
|
||||
case 860:
|
||||
return (void)NpcAI::ENTITY_UNBORN(&npc);
|
||||
case 861:
|
||||
return (void)NpcAI::ENTITY_PUSTULE(&npc);
|
||||
case 863:
|
||||
return (void)NpcAI::ENTITY_MORNINGSTAR(&npc);
|
||||
case 864:
|
||||
return (void)NpcAI::ENTITY_MOCKULUS(&npc);
|
||||
case 865:
|
||||
return (void)NpcAI::ENTITY_EVIS(&npc);
|
||||
case 866:
|
||||
return (void)NpcAI::ENTITY_DARK_ESAU(&npc);
|
||||
case 867:
|
||||
return (void)NpcAI::ENTITY_MOTHERS_SHADOW(&npc);
|
||||
case 868:
|
||||
return (void)NpcAI::ENTITY_ARMYFLY(&npc);
|
||||
case 873:
|
||||
return (void)NpcAI::ENTITY_FLY_TRAP(&npc);
|
||||
case 874:
|
||||
return (void)NpcAI::ENTITY_FARTIGAN(&npc);
|
||||
case 875:
|
||||
return (void)NpcAI::ENTITY_POOT_MINE(&npc);
|
||||
case 876:
|
||||
return (void)NpcAI::ENTITY_DUMP(&npc);
|
||||
case 877:
|
||||
return (void)NpcAI::ENTITY_GRUDGE(&npc);
|
||||
case 878:
|
||||
return (void)NpcAI::ENTITY_BUTT_SLICKER(&npc);
|
||||
case 879:
|
||||
return (void)NpcAI::ENTITY_BLOATY(&npc);
|
||||
case 880:
|
||||
return (void)NpcAI::ENTITY_FLESH_MAIDEN(&npc);
|
||||
case 881:
|
||||
return (void)NpcAI::ENTITY_NEEDLE(&npc);
|
||||
case 882:
|
||||
return (void)NpcAI::ENTITY_DUST(&npc);
|
||||
case 883:
|
||||
return (void)NpcAI::ENTITY_BABY_BEGOTTEN(&npc);
|
||||
case 884:
|
||||
return (void)NpcAI::ENTITY_SWARM_SPIDER(&npc);
|
||||
case 885:
|
||||
return (void)NpcAI::ENTITY_CULTIST(&npc);
|
||||
case 886:
|
||||
return (void)NpcAI::ENTITY_VIS_FATTY(&npc);
|
||||
case 887:
|
||||
return (void)NpcAI::ENTITY_DUSTY_DEATHS_HEAD(&npc);
|
||||
case 888:
|
||||
return (void)NpcAI::ENTITY_SHADY(&npc);
|
||||
case 889:
|
||||
return (void)NpcAI::ENTITY_CLICKETY_CLACK(&npc);
|
||||
case 890:
|
||||
return (void)NpcAI::ENTITY_MAZE_ROAMER(&npc);
|
||||
case 891:
|
||||
return (void)NpcAI::ENTITY_GOAT(&npc);
|
||||
case 892:
|
||||
return (void)NpcAI::ENTITY_POOFER(&npc);
|
||||
case 893:
|
||||
return (void)NpcAI::ENTITY_BALL_AND_CHAIN(&npc);
|
||||
case 900:
|
||||
return (void)NpcAI::ENTITY_REAP_CREEP(&npc);
|
||||
case 901:
|
||||
return (void)NpcAI::ENTITY_LIL_BLUB(&npc);
|
||||
case 902:
|
||||
return (void)NpcAI::ENTITY_RAINMAKER(&npc);
|
||||
case 903:
|
||||
if (npc.variant == 0) return NpcAI::ENTITY_VISAGE(&npc);
|
||||
if (npc.variant == 1) return NpcAI::ENTITY_VISAGE_mask(&npc);
|
||||
if (npc.variant == 10) return NpcAI::ENTITY_VISAGE_chain(&npc);
|
||||
if (npc.variant == 20) return NpcAI::ENTITY_VISAGE_plasma(&npc);
|
||||
return;
|
||||
case 904:
|
||||
return (void)NpcAI::ENTITY_SIREN(&npc);
|
||||
case 905:
|
||||
return (void)NpcAI::ENTITY_HERETIC(&npc);
|
||||
case 906:
|
||||
return npc.Hornfel_UpdateAI();
|
||||
case 907:
|
||||
return (void)NpcAI::ENTITY_GIDEON(&npc);
|
||||
case 908:
|
||||
return (void)NpcAI::ENTITY_BABY_PLUM(&npc);
|
||||
case 909:
|
||||
return npc.variant == 10 ? NpcAI::ENTITY_SCOURGE_chain(&npc) : NpcAI::ENTITY_SCOURGE(&npc);
|
||||
case 910:
|
||||
return npc.variant == 2 ? (void)NpcAI::ENTITY_CHIMERA(&npc) : NpcAI::ENTITY_CHIMERA_body(&npc);
|
||||
case 911:
|
||||
if (npc.variant == 2) return NpcAI::ENTITY_ROTGUT(&npc);
|
||||
return npc.variant == 1 ? NpcAI::ENTITY_ROTGUT_maggot(&npc) : NpcAI::ENTITY_ROTGUT_face(&npc);
|
||||
case 912:
|
||||
return mother_update(npc);
|
||||
case 913:
|
||||
return (void)NpcAI::ENTITY_MIN_MIN(&npc);
|
||||
case 914:
|
||||
return (void)NpcAI::ENTITY_CLOG(&npc);
|
||||
case 915:
|
||||
return npc.variant == 1 ? NpcAI::ENTITY_SINGE_ball(&npc) : NpcAI::ENTITY_SINGE_body(&npc);
|
||||
case 916:
|
||||
return (void)NpcAI::ENTITY_BUMBINO(&npc);
|
||||
case 917:
|
||||
return (void)NpcAI::ENTITY_COLOSTOMIA(&npc);
|
||||
case 918:
|
||||
return (void)NpcAI::ENTITY_TURDLET(&npc);
|
||||
case 919:
|
||||
return (void)NpcAI::ENTITY_RAGLICH(&npc);
|
||||
case 920:
|
||||
return (void)NpcAI::ENTITY_HORNY_BOYS(&npc);
|
||||
case 921:
|
||||
if (npc.variant == 0) return NpcAI::ENTITY_CLUTCH(&npc);
|
||||
reconstruction_missing("npc_ai_update 006c2990: Clutch's orbitals");
|
||||
case 922:
|
||||
reconstruction_missing("npc_ai_update 006c2990: Cadavra's green splat");
|
||||
case 950:
|
||||
if (npc.variant == 1) return NpcAI::ENTITY_DOGMA_tv(&npc);
|
||||
if (npc.variant == 2) return NpcAI::ENTITY_DOGMA_angel(&npc);
|
||||
if (npc.variant == 10) return (void)NpcAI::ENTITY_DOGMA_angel_baby(&npc);
|
||||
return NpcAI::ENTITY_DOGMA(&npc);
|
||||
case 951:
|
||||
return beast_update(npc);
|
||||
case 960:
|
||||
return (void)NpcAI::ENTITY_GENERIC_PROP(&npc);
|
||||
case 965:
|
||||
return (void)NpcAI::ENTITY_MINECART(&npc);
|
||||
case 966:
|
||||
return (void)NpcAI::ENTITY_SIREN_HELPER(&npc);
|
||||
case 967:
|
||||
return NpcAI::ENTITY_HORNFEL_DOOR(&npc);
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 006c2990 Runs the NPC's AI for its type, in whatever phase (aiCallPhase) the caller set, with the mods' NPC
|
||||
// update callbacks around the update phase.
|
||||
void npc_ai_update(Entity_NPC& npc)
|
||||
{
|
||||
if (npc.aiCallPhase == AI_PHASE_UPDATE)
|
||||
lua_callback_check(CALLBACK_PRE_NPC_UPDATE, "npc_ai_update 006c2990: MC_PRE_NPC_UPDATE");
|
||||
npc_ai_routine_run(npc);
|
||||
if (npc.aiCallPhase == AI_PHASE_UPDATE)
|
||||
lua_callback_check(CALLBACK_NPC_UPDATE, "npc_ai_update 006c2990: MC_NPC_UPDATE");
|
||||
}
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
#pragma once
|
||||
|
||||
#include "entity_npc.h"
|
||||
#include "log.h"
|
||||
#include "lua_engine.h"
|
||||
#include "seeds.h"
|
||||
#include <cmath>
|
||||
#include <string_view>
|
||||
|
||||
constexpr float PI_F = 3.1415927f;
|
||||
constexpr float RANDOM_UNIT_SCALE = 2.3283064e-10f;
|
||||
constexpr float RANDOM_HALF_TURN = 3.14f;
|
||||
constexpr float DEGREES_TO_RADIANS = 0.017453292f;
|
||||
|
||||
// The mod callbacks the NPC code runs, by their ModCallbacks ids.
|
||||
constexpr int CALLBACK_NPC_UPDATE = 0;
|
||||
constexpr int CALLBACK_POST_NPC_INIT = 27;
|
||||
constexpr int CALLBACK_POST_NPC_RENDER = 28;
|
||||
constexpr int CALLBACK_POST_NPC_DEATH = 29;
|
||||
constexpr int CALLBACK_PRE_NPC_UPDATE = 69;
|
||||
|
||||
// The sound ids the common enemies play (Lua's SoundEffect).
|
||||
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_SUMMONSOUND = 286,
|
||||
SOUND_SUMMON_POOF = 872
|
||||
};
|
||||
|
||||
inline Vector vector_add(Vector a, Vector b)
|
||||
{
|
||||
return vector_make(a.x + b.x, a.y + b.y);
|
||||
}
|
||||
|
||||
inline Vector vector_sub(Vector a, Vector b)
|
||||
{
|
||||
return vector_make(a.x - b.x, a.y - b.y);
|
||||
}
|
||||
|
||||
inline Vector vector_scale(Vector v, float scale)
|
||||
{
|
||||
return vector_make(v.x * scale, v.y * scale);
|
||||
}
|
||||
|
||||
inline float vector_dot(Vector a, Vector b)
|
||||
{
|
||||
return a.x * b.x + a.y * b.y;
|
||||
}
|
||||
|
||||
inline float vector_length_squared(Vector v)
|
||||
{
|
||||
return v.x * v.x + v.y * v.y;
|
||||
}
|
||||
|
||||
inline float vector_length(Vector v)
|
||||
{
|
||||
return std::sqrt(v.x * v.x + v.y * v.y);
|
||||
}
|
||||
|
||||
inline bool vector_is_zero(Vector v)
|
||||
{
|
||||
return v.x == 0 && v.y == 0;
|
||||
}
|
||||
|
||||
// Vector::Normalized: a unit vector along v, or v when it has no length.
|
||||
inline Vector vector_normalized(Vector v)
|
||||
{
|
||||
float length = vector_length(v);
|
||||
return length > 0 ? vector_scale(v, 1 / length) : v;
|
||||
}
|
||||
|
||||
// Vector::Resized: v at a length, or v when it has none.
|
||||
inline Vector vector_resized(Vector v, float length)
|
||||
{
|
||||
float current = vector_length(v);
|
||||
return current > 0 ? vector_scale(v, length / current) : v;
|
||||
}
|
||||
|
||||
// random_float: a random fraction of one from the global generator.
|
||||
inline float random_unit()
|
||||
{
|
||||
return (float)Random() * RANDOM_UNIT_SCALE;
|
||||
}
|
||||
|
||||
// Isaac::Random: a random number below max, or 0 for none.
|
||||
inline int random_below(int max)
|
||||
{
|
||||
return max == 0 ? 0 : (int)(Random() % (uint32_t)max);
|
||||
}
|
||||
|
||||
// MusicManager::RandomVector: a random unit direction.
|
||||
inline Vector random_direction()
|
||||
{
|
||||
float angle = random_unit() * RANDOM_HALF_TURN;
|
||||
angle += angle;
|
||||
return vector_make(std::cos(angle), std::sin(angle));
|
||||
}
|
||||
|
||||
// Plays a sound through the fart seeds, the way the AIs play the ones that are not the NPC's own.
|
||||
void npc_sound_play(int sound, float volume, int frameDelay, float pitch);
|
||||
|
||||
// The ticks the NPC moved on this update, which its timers count down by.
|
||||
inline int npc_ticks_get(Entity_NPC& npc)
|
||||
{
|
||||
return (int)npc.updateTime - (int)npc.prevUpdateTime;
|
||||
}
|
||||
|
||||
void npc_ai_update(Entity_NPC& npc);
|
||||
void npc_fly_update(Entity_NPC& npc);
|
||||
void npc_gaper_update(Entity_NPC& npc);
|
||||
void npc_horf_update(Entity_NPC& npc);
|
||||
void npc_dip_update(Entity_NPC& npc);
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
#include "npc_ai.h"
|
||||
#include "entity_effect.h"
|
||||
#include "entity_familiar.h"
|
||||
#include "entity_player.h"
|
||||
#include "game.h"
|
||||
#include "room.h"
|
||||
|
||||
constexpr int ENTITY_DIP = 217;
|
||||
constexpr int DIP_CORN = 1;
|
||||
constexpr int DIP_BROWNIE = 2;
|
||||
constexpr int DIP_BIG_CORN = 3;
|
||||
constexpr int FAMILIAR_DIP_CORN = 2;
|
||||
constexpr int FAMILIAR_DIP_BROWNIE = 20;
|
||||
constexpr int COLLECTIBLE_DIRTY_MIND_ID = 576;
|
||||
constexpr int TRINKET_DIPPING_TRINKET_ID = 163;
|
||||
constexpr int PROJECTILE_CORN = 5;
|
||||
constexpr int SOUND_DIP_HURT = 60;
|
||||
constexpr int COLOR_PRIORITY_DEFAULT = 255;
|
||||
|
||||
// How a Dip hops: one chance in ten a frame from rest, at a random speed (doubled for the corn dip), and how it
|
||||
// slows, splats and squeaks.
|
||||
constexpr int HOP_ODDS = 10;
|
||||
constexpr float HOP_SPEED_MIN = 5;
|
||||
constexpr float HOP_SPEED_RANGE = 5;
|
||||
constexpr float HOP_FRICTION = 0.8f;
|
||||
constexpr float SLIDE_FRICTION = 0.95f;
|
||||
constexpr float SPLAT_SIZE_MIN = 0.2f;
|
||||
constexpr float SPLAT_SIZE_RANGE = 0.5f;
|
||||
constexpr int SPLAT_ODDS = 10;
|
||||
constexpr float HURT_VOLUME = 0.8f;
|
||||
constexpr int HURT_SOUND_DELAY = 15;
|
||||
constexpr float CORN_AIM_LEAD = 0.1f;
|
||||
constexpr float CORN_SHOT_SPEED = 10;
|
||||
constexpr float CONTROLLER_DEADZONE = 0.1f;
|
||||
constexpr ColorMod DIP_SPLAT = {{0, 0, 0, 1}, {0, 0, 0, 0}, {0.25490198f, 0.16078432f, 0.13725491f}};
|
||||
constexpr ColorMod BROWNIE_SPLAT = {{0, 0, 0, 1}, {0, 0, 0, 0}, {0.6f, 0.4f, 0}};
|
||||
|
||||
// A hop: a random way (away from its target while it fears it), faster for the corn dips.
|
||||
static void dip_hop(Entity_NPC& npc)
|
||||
{
|
||||
npc.state = NPC_STATE_MOVE;
|
||||
bool isFleeing = npc.HasEntityFlags(FLAG_FEAR | FLAG_SHRINK) && npc.controllerID == -1;
|
||||
Vector direction;
|
||||
if (isFleeing) direction = vector_normalized(vector_sub(npc.pos, npc.GetPlayerTarget()->pos));
|
||||
else
|
||||
{
|
||||
direction = random_direction();
|
||||
if (npc.controllerID != -1) direction = npc.GetControllerInput(0);
|
||||
}
|
||||
|
||||
float speed = random_unit() * HOP_SPEED_RANGE + HOP_SPEED_MIN;
|
||||
bool isDoubled = npc.variant == DIP_CORN || (isFleeing && npc.variant == DIP_BROWNIE);
|
||||
Vector hop = vector_scale(direction, isDoubled ? speed * 2 : speed);
|
||||
if (npc.friction != 0)
|
||||
npc.velocity = vector_add(npc.velocity, vector_scale(hop, npc.speedMultiplier / npc.friction));
|
||||
}
|
||||
|
||||
// The big corn dip's dying shot, aimed where its target is heading.
|
||||
static void dip_corn_shoot(Entity_NPC& npc)
|
||||
{
|
||||
Entity* target = npc.GetPlayerTarget();
|
||||
float distance = vector_length(vector_sub(npc.pos, target->pos));
|
||||
Vector lead = vector_add(target->pos, vector_scale(target->velocity, CORN_AIM_LEAD * distance));
|
||||
ProjectileParams params;
|
||||
params.variant = PROJECTILE_CORN;
|
||||
npc.FireProjectiles(npc.pos, vector_scale(vector_normalized(vector_sub(lead, npc.pos)), CORN_SHOT_SPEED),
|
||||
PROJECTILES_SINGLE, params);
|
||||
}
|
||||
|
||||
// 00534860 The Dip's AI: it rests, hops about (fleeing what it fears), slides to a stop and leaves poop splats. Dirty
|
||||
// Mind and the Dipping trinket turn it into the players' own dip.
|
||||
void npc_dip_update(Entity_NPC& npc)
|
||||
{
|
||||
if (npc.type != ENTITY_DIP) reconstruction_missing("npc_dip_update 00534860: the other dip kin");
|
||||
|
||||
PlayerManager& players = g_game->playerManager;
|
||||
bool isTamed = players.FirstCollectibleOwner(COLLECTIBLE_DIRTY_MIND_ID, LAZARUS_SHARE_CHECK) ||
|
||||
players.AnyoneHasTrinket(TRINKET_DIPPING_TRINKET_ID);
|
||||
if (!npc.isDead && isTamed)
|
||||
{
|
||||
Entity* owner = players.RandomCollectibleOwner(COLLECTIBLE_DIRTY_MIND_ID, npc.initSeed, nullptr);
|
||||
if (!owner) owner = players.RandomTrinketOwner(TRINKET_DIPPING_TRINKET_ID, npc.initSeed, nullptr);
|
||||
if (owner)
|
||||
{
|
||||
npc.entityCollisionClass = ENTCOLL_NONE;
|
||||
npc.Remove();
|
||||
bool isCorn = npc.variant == DIP_CORN || npc.variant == DIP_BIG_CORN;
|
||||
int dip = npc.variant == DIP_BROWNIE ? FAMILIAR_DIP_BROWNIE : isCorn ? FAMILIAR_DIP_CORN : 0;
|
||||
Entity_Familiar::ThrowDip(dip, npc.pos, owner);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (npc.state == NPC_STATE_INIT)
|
||||
{
|
||||
npc.state = NPC_STATE_IDLE;
|
||||
npc.splatColor = npc.variant == DIP_BROWNIE ? BROWNIE_SPLAT : DIP_SPLAT;
|
||||
return;
|
||||
}
|
||||
bool isFloating = npc.variant == DIP_BIG_CORN && g_game->room->waterAmount > 0;
|
||||
npc.entityGridCollisionClass = isFloating ? GRIDCOLL_NOPITS : GRIDCOLL_GROUND;
|
||||
|
||||
if (npc.state == NPC_STATE_IDLE || npc.state == NPC_STATE_SPECIAL)
|
||||
{
|
||||
npc.sprite.Play("Idle");
|
||||
bool isHopping = npc.state == NPC_STATE_SPECIAL ||
|
||||
(npc.controllerID == -1 ? Random() % HOP_ODDS == 0
|
||||
: !vector_is_zero(npc.GetControllerInput(CONTROLLER_DEADZONE)));
|
||||
if (isHopping) dip_hop(npc);
|
||||
npc.friction *= HOP_FRICTION;
|
||||
}
|
||||
else if (npc.state == NPC_STATE_MOVE)
|
||||
{
|
||||
npc.sprite.Play("Move");
|
||||
npc.friction *= SLIDE_FRICTION;
|
||||
if (vector_length_squared(npc.velocity) < 1) npc.state = NPC_STATE_IDLE;
|
||||
}
|
||||
|
||||
npc.sprite.isFlipX = npc.velocity.x < 0;
|
||||
if (Random() % SPLAT_ODDS == 0)
|
||||
npc.MakeSplat(random_unit() * SPLAT_SIZE_RANGE + SPLAT_SIZE_MIN)
|
||||
->SetColor(npc.splatColor, -1, COLOR_PRIORITY_DEFAULT, false, true);
|
||||
if (npc.pendingDamage > 0 && (Random() & 1) == 0)
|
||||
npc.PlaySound(SOUND_DIP_HURT, HURT_VOLUME, HURT_SOUND_DELAY, false, 1);
|
||||
if (npc.variant == DIP_BIG_CORN && npc.controllerID != -1)
|
||||
reconstruction_missing("npc_dip_update 00534860: a controlled corn dip bursting");
|
||||
if (npc.isDead && npc.variant == DIP_BIG_CORN && !npc.HasEntityFlags(FLAG_SHRINK)) dip_corn_shoot(npc);
|
||||
}
|
||||
+319
@@ -0,0 +1,319 @@
|
||||
#include "npc_ai.h"
|
||||
#include "entity_player.h"
|
||||
#include "game.h"
|
||||
#include "grid_entity.h"
|
||||
#include "room.h"
|
||||
#include "score_sheet.h"
|
||||
|
||||
constexpr int ENTITY_ISAAC_BOSS = 102;
|
||||
constexpr int ENTITY_ORBIT_SPAWNER = 873;
|
||||
constexpr int SPAWNER_UNBOUNDED = 67;
|
||||
constexpr int COLLECTIBLE_SKATOLE_ID = 9;
|
||||
constexpr int POOTER_TRIPLE_VARIANT = 2;
|
||||
constexpr int POOTER_TWO_SHOT_VARIANT = 1;
|
||||
|
||||
// The fly types this file covers: the fly, the Pooter and the attack fly.
|
||||
constexpr int ENTITY_FLY = 13;
|
||||
constexpr int ENTITY_POOTER = 14;
|
||||
constexpr int ENTITY_ATTACKFLY = 18;
|
||||
|
||||
// How a Pooter shoots: when its target is in range (checked every 7 frames), its cooldowns, and its shot.
|
||||
constexpr float POOTER_RANGE = 200;
|
||||
constexpr int POOTER_RANGE_FRAMES = 7;
|
||||
constexpr int POOTER_COOLDOWN = 35;
|
||||
constexpr int POOTER_TRIPLE_COOLDOWN = 63;
|
||||
constexpr float POOTER_SHOT_SPEED = 7;
|
||||
constexpr float POOTER_HARD_SHOT_SPEED = 10;
|
||||
constexpr float POOTER_FRICTION = 0.8f;
|
||||
constexpr float POOTER_DRIFT_DECAY = 0.7f;
|
||||
constexpr int SOUND_POOTER_SHOOT = 178;
|
||||
constexpr uint64_t PROJECTILE_FLAG_54 = 1ull << 54;
|
||||
|
||||
// The super Pooter's shot.
|
||||
constexpr float SUPER_POOTER_SCALE = 1.4f;
|
||||
constexpr float SUPER_POOTER_FALL_ACCEL = -0.15f;
|
||||
constexpr float SUPER_POOTER_FALL_SPEED = 1;
|
||||
constexpr float SUPER_POOTER_SPREAD = 1.2f;
|
||||
|
||||
// How a fly wanders: the spot it eyes (and a poop or fireplace there), its drift and the bounds it stays within.
|
||||
constexpr int FLY_RETARGET_FRAMES = 3;
|
||||
constexpr float FLY_WANDER = 240;
|
||||
constexpr int FLY_FIREPLACE_ODDS = 100;
|
||||
constexpr int FLY_POOP_ODDS = 1000;
|
||||
constexpr int FLY_CHASE_ODDS = 5;
|
||||
constexpr float FLY_CHASE_SPEED = 0.7f;
|
||||
constexpr float FLY_DRIFT_KEEP = 0.4f;
|
||||
constexpr float FLY_DRIFT_NEW = 0.6f;
|
||||
constexpr float FLY_DRIFT_STEP = 0.06f;
|
||||
constexpr float FLY_TOP = 230;
|
||||
constexpr float FLY_BOTTOM = 420;
|
||||
constexpr float FLY_LEFT = 80;
|
||||
constexpr float FLY_RIGHT = 540;
|
||||
constexpr float FLY_FRICTION = 0.6f;
|
||||
constexpr int FLY_DRIFT_PERIOD = 4;
|
||||
constexpr int FLY_STEER_PERIOD = 3;
|
||||
|
||||
// How a fly flees what it fears: within 400 (at full distance under 200), aimed in a random arc around away.
|
||||
constexpr float FLEE_RANGE = 400;
|
||||
constexpr float FLEE_NEAR = 200;
|
||||
constexpr float FLEE_DISTANCE = 100;
|
||||
constexpr float FLEE_ARC = 220;
|
||||
constexpr float FLEE_ARC_BLOCKED = 360;
|
||||
constexpr uint64_t FLEE_BLOCKERS = FLAG_FREEZE | FLAG_CHARM | FLAG_CONFUSION | FLAG_MIDAS_FREEZE;
|
||||
|
||||
// How it flies to its target: how near it stops (an attack fly nearer), and how hard it pulls.
|
||||
constexpr float TARGET_REACH = 30;
|
||||
constexpr float TARGET_REACH_ATTACK = 25;
|
||||
constexpr float TARGET_REACH_BIG = 15;
|
||||
constexpr float TARGET_PULL = 0.08f;
|
||||
constexpr float TARGET_PULL_MAX = 1.2f;
|
||||
constexpr float TARGET_Y_SHARE = 0.5f;
|
||||
constexpr float TARGET_PARENT_SHARE = 0.2f;
|
||||
constexpr float BIG_FLY_SCALE = 1.1f;
|
||||
constexpr float KILL_ON_TOUCH_FRICTION = 0.9f;
|
||||
constexpr float CHARGE_INTERVAL = 2;
|
||||
constexpr float REGENERATION_FRAMES = 60;
|
||||
constexpr uint32_t GRID_COLLISION_WALL = 4;
|
||||
|
||||
// The fly's sprite: Fly while it flies (restarted when it stopped), the Pooter's back to Fly after its attack.
|
||||
static void fly_animation_update(Entity_NPC& npc)
|
||||
{
|
||||
if (npc.type == ENTITY_POOTER)
|
||||
{
|
||||
bool isAttackDone = !npc.sprite.animState.animData || !npc.sprite.animState.isPlaying;
|
||||
if (npc.state < NPC_STATE_SUICIDE) npc.sprite.Play("Fly");
|
||||
else if (npc.state == NPC_STATE_ATTACK && isAttackDone) npc.state = NPC_STATE_MOVE;
|
||||
return;
|
||||
}
|
||||
|
||||
const AnimationData* current = npc.sprite.animState.animData;
|
||||
bool isFlying = current && current->name == "Fly" && (!current->isLooping || npc.sprite.animState.isPlaying);
|
||||
if (!isFlying && npc.sprite.SetAnimation("Fly", SWITCH_KEEP_FRAME))
|
||||
{
|
||||
npc.sprite.animState.Rewind();
|
||||
npc.sprite.animState.isPlaying = true;
|
||||
}
|
||||
}
|
||||
|
||||
// A fly that crosses a poop (one chance in a thousand a frame) eats it and becomes a Pooter.
|
||||
static void fly_poop_eat(Entity_NPC& npc)
|
||||
{
|
||||
if (npc.type != ENTITY_FLY || Random() % FLY_POOP_ODDS != 0) return;
|
||||
|
||||
Room& room = *g_game->room;
|
||||
int gridIndex = room.GetGridIndex(npc.pos);
|
||||
GridEntity* grid = gridIndex >= 0 ? room.GetGridEntity(gridIndex) : nullptr;
|
||||
if (grid && grid->type == GRID_POOP) reconstruction_missing("npc_fly_update 00506bd0: a fly eating poop");
|
||||
}
|
||||
|
||||
// A Pooter in range of its target turns to it and shoots on its Shoot event: a single shot, two for the twin
|
||||
// shooter, three heavy ones for the super Pooter.
|
||||
static void pooter_attack_update(Entity_NPC& npc)
|
||||
{
|
||||
if (npc.projectileCooldown < 1 && npc.IsTargetInAttackRange(POOTER_RANGE, POOTER_RANGE_FRAMES, false))
|
||||
{
|
||||
npc.projectileCooldown = npc.variant == POOTER_TRIPLE_VARIANT ? POOTER_TRIPLE_COOLDOWN : POOTER_COOLDOWN;
|
||||
npc.sprite.Play("Attack");
|
||||
npc.state = NPC_STATE_ATTACK;
|
||||
npc.UpdateControllerMovement(true);
|
||||
float facing = vector_is_zero(npc.controllerMovement) ? npc.GetPlayerTarget()->pos.x - npc.pos.x
|
||||
: npc.controllerMovement.x;
|
||||
npc.sprite.isFlipX = facing < 0;
|
||||
}
|
||||
|
||||
if (npc.state == NPC_STATE_ATTACK)
|
||||
{
|
||||
npc.UpdateControllerMovement(false);
|
||||
if (npc.sprite.animState.animData && npc.sprite.animState.IsEventTriggered("Shoot"))
|
||||
{
|
||||
Vector aim = vector_is_zero(npc.controllerMovement) ? vector_sub(npc.GetPlayerTarget()->pos, npc.pos)
|
||||
: npc.controllerMovement;
|
||||
ProjectileParams params;
|
||||
ProjectilesMode mode = npc.variant == POOTER_TWO_SHOT_VARIANT ? PROJECTILES_TWO : PROJECTILES_SINGLE;
|
||||
float speed = game_is_hard_mode() ? POOTER_HARD_SHOT_SPEED : POOTER_SHOT_SPEED;
|
||||
if (npc.variant == POOTER_TRIPLE_VARIANT)
|
||||
{
|
||||
params.scale = SUPER_POOTER_SCALE;
|
||||
params.fallingAccelModifier = SUPER_POOTER_FALL_ACCEL;
|
||||
params.fallingSpeedModifier = SUPER_POOTER_FALL_SPEED;
|
||||
params.spread = SUPER_POOTER_SPREAD;
|
||||
params.bulletFlags = PROJECTILE_FLAG_54;
|
||||
params.isFallingKept = true;
|
||||
mode = PROJECTILES_FOUR;
|
||||
speed = POOTER_SHOT_SPEED;
|
||||
}
|
||||
npc.FireProjectiles(npc.pos, vector_resized(aim, speed), mode, params);
|
||||
npc.PlaySound(SOUND_POOTER_SHOOT, 1, 2, false, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (npc.projectileCooldown > 0)
|
||||
{
|
||||
npc.friction *= POOTER_FRICTION;
|
||||
npc.projectileCooldown -= npc_ticks_get(npc);
|
||||
npc.v1 = vector_scale(npc.v1, POOTER_DRIFT_DECAY);
|
||||
}
|
||||
}
|
||||
|
||||
// Every third frame a fly picks where it heads: an attack fly (or any under Skatole) its target, a plain fly or
|
||||
// Pooter eyes a random spot and its poop, or now and then a fireplace, though it heads nowhere in the end.
|
||||
static void fly_target_pick(Entity_NPC& npc, bool isSkatoleActive)
|
||||
{
|
||||
if (!npc.IsFrame(FLY_RETARGET_FRAMES, 0)) return;
|
||||
if (npc.type == ENTITY_ATTACKFLY && npc.parent && npc.controllerID == -1)
|
||||
reconstruction_missing("npc_fly_update 00506bd0: an attack fly circling its parent");
|
||||
|
||||
if (npc.type != ENTITY_ATTACKFLY && !isSkatoleActive)
|
||||
{
|
||||
Room& room = *g_game->room;
|
||||
Vector direction = random_direction();
|
||||
float scaleFirst = random_unit();
|
||||
float distance = random_unit() * scaleFirst * FLY_WANDER;
|
||||
int gridIndex = room.GetGridIndex(vector_add(npc.pos, vector_scale(direction, distance)));
|
||||
GridEntity* grid = gridIndex >= 0 ? room.GetGridEntity(gridIndex) : nullptr;
|
||||
if (grid && grid->type == GRID_POOP) npc.targetPosition = room.GetGridPosition(gridIndex);
|
||||
if (Random() % FLY_FIREPLACE_ODDS == 0)
|
||||
{
|
||||
std::vector<Entity*> fireplaces;
|
||||
for (Entity* entity : room.entityList.mainEL)
|
||||
if (entity->type == ENTITY_FIREPLACE) fireplaces.push_back(entity);
|
||||
if (!fireplaces.empty()) npc.targetPosition = fireplaces[random_below((int)fireplaces.size())]->pos;
|
||||
}
|
||||
return;
|
||||
}
|
||||
npc.targetPosition = npc.CalcTargetPosition(0);
|
||||
}
|
||||
|
||||
// A feared or shrunk fly within 400 of its target heads off to a random spot in an arc away from it, wider when it
|
||||
// touches a wall.
|
||||
static void fly_flee_update(Entity_NPC& npc)
|
||||
{
|
||||
if (!npc.HasEntityFlags(FLAG_FEAR | FLAG_SHRINK) || npc.HasEntityFlags(FLEE_BLOCKERS) || npc.controllerID != -1)
|
||||
return;
|
||||
|
||||
float distance = vector_length(vector_sub(npc.pos, npc.GetPlayerTarget()->pos));
|
||||
if (distance >= FLEE_RANGE) return;
|
||||
|
||||
float reach =
|
||||
distance > FLEE_NEAR ? FLEE_DISTANCE - (distance - FLEE_NEAR) / FLEE_NEAR * FLEE_DISTANCE : FLEE_DISTANCE;
|
||||
float arc = npc.isCollidesWithGrid ? FLEE_ARC_BLOCKED : FLEE_ARC;
|
||||
Vector away = vector_sub(npc.pos, npc.GetPlayerTarget()->pos);
|
||||
float angle = (random_unit() * arc - arc * 0.5f) * DEGREES_TO_RADIANS;
|
||||
Vector turned = vector_make(std::cos(angle) * away.x - away.y * std::sin(angle),
|
||||
away.y * std::cos(angle) + std::sin(angle) * away.x);
|
||||
npc.targetPosition = vector_add(vector_resized(turned, reach), npc.pos);
|
||||
npc.v1 = vector_scale(npc.v1, 0.5f);
|
||||
}
|
||||
|
||||
// Every other tick a fly with a target pulls toward it once farther than its reach, harder the farther.
|
||||
static void fly_target_follow(Entity_NPC& npc)
|
||||
{
|
||||
if (vector_is_zero(npc.targetPosition) || npc.GetIntervalTicks(CHARGE_INTERVAL, 0) == 0) return;
|
||||
|
||||
float reach = npc.type == ENTITY_ATTACKFLY ? TARGET_REACH_ATTACK : TARGET_REACH;
|
||||
if (npc.sprite.scale.x > BIG_FLY_SCALE) reach = TARGET_REACH_BIG;
|
||||
|
||||
Vector toward = vector_sub(npc.targetPosition, npc.pos);
|
||||
if (npc.controllerID == -1)
|
||||
{
|
||||
toward.y *= TARGET_Y_SHARE;
|
||||
if (npc.parent) toward = vector_scale(toward, TARGET_PARENT_SHARE);
|
||||
}
|
||||
else toward = vector_scale(npc.GetControllerInput(0), FLEE_DISTANCE);
|
||||
|
||||
float distance = vector_length(toward);
|
||||
Vector direction = distance > 0 ? vector_scale(toward, 1 / distance) : toward;
|
||||
if (npc.isKillOnTouch) npc.friction *= KILL_ON_TOUCH_FRICTION;
|
||||
if (npc.type != ENTITY_ATTACKFLY) npc.v1 = vector_scale(npc.v1, POOTER_DRIFT_DECAY);
|
||||
if (distance > reach)
|
||||
npc.AddVelocity_divided(vector_scale(direction, std::min((distance - reach) * TARGET_PULL, TARGET_PULL_MAX)),
|
||||
false);
|
||||
}
|
||||
|
||||
// A fly's buzzing: without a target it now and then darts toward its player, every fourth frame its drift turns,
|
||||
// every third it drifts back inside the room's middle and its drift moves it.
|
||||
static void fly_drift_update(Entity_NPC& npc)
|
||||
{
|
||||
if (vector_is_zero(npc.targetPosition))
|
||||
{
|
||||
if (npc.controllerID != -1) reconstruction_missing("npc_fly_update 00506bd0: a controlled fly's steering");
|
||||
if (Random() % FLY_CHASE_ODDS == 0)
|
||||
{
|
||||
Vector toward = vector_normalized(vector_sub(npc.GetPlayerTarget()->pos, npc.pos));
|
||||
npc.velocity = vector_add(npc.velocity, vector_scale(toward, FLY_CHASE_SPEED * npc.speedMultiplier));
|
||||
}
|
||||
}
|
||||
|
||||
if (g_game->frameCount % FLY_DRIFT_PERIOD == 1)
|
||||
npc.v1 = vector_scale(vector_add(vector_scale(random_direction(), FLY_DRIFT_NEW), npc.v1), FLY_DRIFT_KEEP);
|
||||
if (g_game->frameCount % FLY_STEER_PERIOD != 2) return;
|
||||
|
||||
if (npc.spawnerType != SPAWNER_UNBOUNDED)
|
||||
{
|
||||
if (npc.pos.y < FLY_TOP) npc.v1.y += FLY_DRIFT_STEP;
|
||||
else if (npc.pos.y > FLY_BOTTOM) npc.v1.y -= FLY_DRIFT_STEP;
|
||||
if (npc.pos.x > FLY_RIGHT) npc.v1.x -= FLY_DRIFT_STEP;
|
||||
else if (npc.pos.x < FLY_LEFT) npc.v1.x += FLY_DRIFT_STEP;
|
||||
}
|
||||
if (npc.friction != 0)
|
||||
npc.velocity = vector_add(npc.velocity, vector_scale(npc.v1, 2 * npc.speedMultiplier / npc.friction));
|
||||
npc.friction *= FLY_FRICTION;
|
||||
}
|
||||
|
||||
// 00506bd0 The flies' AI (the fly, Pooter and attack fly, with Moter, Sucker and their kin left to come): Skatole
|
||||
// befriends them, Lord of the Flies turns them blue, they buzz about drifting, the attack fly chases its target and
|
||||
// the Pooter shoots at it.
|
||||
void npc_fly_update(Entity_NPC& npc)
|
||||
{
|
||||
bool isCovered = npc.type == ENTITY_FLY || npc.type == ENTITY_POOTER || npc.type == ENTITY_ATTACKFLY;
|
||||
if (!isCovered) reconstruction_missing("npc_fly_update 00506bd0: the Sucker, Moter and the other fly kin");
|
||||
|
||||
if (npc.state == NPC_STATE_INIT)
|
||||
{
|
||||
npc.entityGridCollisionClass = GRIDCOLL_WALLS;
|
||||
npc.v2 = {};
|
||||
npc.state = NPC_STATE_IDLE;
|
||||
npc.i1 = 0;
|
||||
}
|
||||
|
||||
PlayerManager& players = g_game->playerManager;
|
||||
bool isSkatoleActive =
|
||||
players.FirstCollectibleOwner(COLLECTIBLE_SKATOLE_ID, LAZARUS_SHARE_CHECK) && !npc.IsFriendly();
|
||||
if (isSkatoleActive && npc.type == ENTITY_ATTACKFLY) npc.Morph(ENTITY_FLY, 0, 0, -1);
|
||||
|
||||
Entity_Player* beelzebub = players.GetRandomPlayer(npc.initSeed);
|
||||
if (beelzebub && !npc.isDead)
|
||||
{
|
||||
if (npc.type == ENTITY_ATTACKFLY || npc.type == ENTITY_FLY)
|
||||
{
|
||||
g_game->scoreSheet.AddKilledEnemy(npc);
|
||||
npc.Remove();
|
||||
beelzebub->AddBlueFlies(1, npc.pos, nullptr);
|
||||
}
|
||||
else if (!npc.IsBoss() && !npc.IsFriendly()) npc.AddCharmed(EntityRef(beelzebub), -1, true, false);
|
||||
}
|
||||
|
||||
if (npc.i1 > 0)
|
||||
{
|
||||
npc.health = std::min(npc.health + npc.maxHitPoints / REGENERATION_FRAMES, npc.maxHitPoints);
|
||||
npc.i1--;
|
||||
}
|
||||
|
||||
fly_animation_update(npc);
|
||||
fly_poop_eat(npc);
|
||||
if (npc.type == ENTITY_POOTER && !isSkatoleActive) pooter_attack_update(npc);
|
||||
|
||||
bool isIsaacsFly = npc.spawnerType == ENTITY_ISAAC_BOSS && npc.subtype != 0;
|
||||
if (isIsaacsFly) NpcAI::ENTITY_FLY_isaac_spawned(&npc);
|
||||
else if (npc.spawnerType == ENTITY_ORBIT_SPAWNER) return NpcAI::ENTITY_FLY_orbit_parent(&npc);
|
||||
else fly_target_pick(npc, isSkatoleActive);
|
||||
|
||||
if ((npc.type == ENTITY_FLY || npc.type == ENTITY_POOTER) && !isIsaacsFly) npc.targetPosition = {};
|
||||
fly_flee_update(npc);
|
||||
if (!isIsaacsFly) fly_target_follow(npc);
|
||||
|
||||
if (npc.entityGridCollisionClass == GRIDCOLL_NONE && g_game->room->IsPositionInRoom(npc.pos, npc.size) &&
|
||||
room_grid_collision_at(npc.pos) < GRID_COLLISION_WALL)
|
||||
npc.entityGridCollisionClass = GRIDCOLL_WALLS;
|
||||
fly_drift_update(npc);
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
#include "npc_ai.h"
|
||||
#include "game.h"
|
||||
|
||||
constexpr int ENTITY_GAPER = 10;
|
||||
constexpr int ENTITY_GUSHER = 11;
|
||||
constexpr int GAPER_FROWNING = 1;
|
||||
constexpr int GAPER_FLAMING = 2;
|
||||
constexpr int GAPER_ROTTEN = 3;
|
||||
constexpr int GUSHER_PACER = 1;
|
||||
constexpr int GAPER_SOUND_DELAY = 40;
|
||||
constexpr int GAPER_SOUND_ODDS = 3;
|
||||
constexpr int GUSHER_ODDS = 3;
|
||||
constexpr int GUSHER_COOLDOWN_MIN = 20;
|
||||
constexpr int GUSHER_COOLDOWN_RANGE = 20;
|
||||
constexpr float GAPER_OVERKILL = -25;
|
||||
constexpr int GAPER_PATH_MARKER = 900;
|
||||
constexpr float WALK_THRESHOLD = 0.1f;
|
||||
constexpr float FLEE_FRICTION = 0.8f;
|
||||
constexpr int CONTROLLER_ACTION_GROAN = 10;
|
||||
|
||||
// How fast each gaper walks: a plain one, faster once its head is up, the frowning and flaming ones.
|
||||
constexpr float GAPER_SPEED = 0.6f;
|
||||
constexpr float GAPER_SPEED_HEAD_UP = 0.72f;
|
||||
constexpr float GAPER_SPEED_FROWNING = 0.498f;
|
||||
constexpr float GAPER_SPEED_FLAMING = 0.5478f;
|
||||
|
||||
// A gaper's first frame: walking, with its head on the first frame of its overlay (a flaming one's head plays).
|
||||
static void gaper_init(Entity_NPC& npc)
|
||||
{
|
||||
npc.state = NPC_STATE_MOVE;
|
||||
npc.stateFrame = 0;
|
||||
if (npc.variant == GAPER_FLAMING) npc.sprite.PlayOverlay("Head");
|
||||
else if (npc.sprite.SetOverlayAnimation("Head", SWITCH_KEEP_FRAME) && npc.sprite.overlayAnimState.animData)
|
||||
npc.sprite.overlayAnimState.SetFrameFloat(0);
|
||||
|
||||
if (npc.sprite.SetAnimation("WalkVert", SWITCH_KEEP_FRAME) && npc.sprite.animState.animData)
|
||||
{
|
||||
npc.sprite.animState.SetFrameFloat(0);
|
||||
npc.sprite.animState.isPlaying = false;
|
||||
}
|
||||
}
|
||||
|
||||
// A dying gaper that was not torn apart may get up as a Gusher (a pacer one time in three).
|
||||
static void gaper_death_update(Entity_NPC& npc)
|
||||
{
|
||||
if (npc.health <= GAPER_OVERKILL || (Random() & 1) != 0) return;
|
||||
|
||||
bool isPacer = Random() % GUSHER_ODDS == 0 && npc.variant != GAPER_FLAMING;
|
||||
npc.Morph(ENTITY_GUSHER, isPacer ? GUSHER_PACER : 0, 0, -1);
|
||||
npc.isDead = false;
|
||||
uint32_t cooldown = Random();
|
||||
npc.health = npc.maxHitPoints;
|
||||
npc.projectileCooldown = (int)(cooldown % GUSHER_COOLDOWN_RANGE) + GUSHER_COOLDOWN_MIN;
|
||||
}
|
||||
|
||||
// The speed a gaper walks its path at.
|
||||
static float gaper_speed_get(Entity_NPC& npc)
|
||||
{
|
||||
if (npc.variant == GAPER_FROWNING) return GAPER_SPEED_FROWNING;
|
||||
if (npc.variant == GAPER_FLAMING)
|
||||
{
|
||||
npc.sprite.PlayOverlay("Head");
|
||||
return GAPER_SPEED_FLAMING;
|
||||
}
|
||||
return npc.sprite.GetOverlayFrame() > 0 ? GAPER_SPEED_HEAD_UP : GAPER_SPEED;
|
||||
}
|
||||
|
||||
// 00508f40 The gaper's AI (with the rotten gaper's own, and Fatty and the rest of its kin left to come): it walks
|
||||
// its path to its target, groans now and then when it sees it, lifts its head, and its kin do not hurt it.
|
||||
void npc_gaper_update(Entity_NPC& npc)
|
||||
{
|
||||
if (npc.type == ENTITY_GAPER && npc.variant == GAPER_ROTTEN) return NpcAI::ENTITY_ROTTEN_GAPER(&npc);
|
||||
if (npc.type != ENTITY_GAPER) reconstruction_missing("npc_gaper_update 00508f40: Fatty and the gaper's kin");
|
||||
|
||||
if (npc.pendingDamage > 0)
|
||||
for (DamageEvent& event : npc.damageEvents)
|
||||
if (event.source.spawnerType == npc.type) event.damage = 0;
|
||||
if (npc.state == NPC_STATE_INIT) gaper_init(npc);
|
||||
if (npc.isDead) return gaper_death_update(npc);
|
||||
|
||||
npc.AnimWalkFrame("WalkHori", "WalkVert", WALK_THRESHOLD);
|
||||
npc.aiFloat = gaper_speed_get(npc);
|
||||
if (!npc.HasEntityFlags(FLAG_SHRINK | FLAG_FEAR))
|
||||
npc.pathfinder.FindGridPath(npc.CalcTargetPosition(0), npc.aiFloat, GAPER_PATH_MARKER, true);
|
||||
else
|
||||
{
|
||||
npc.pathfinder.EvadeTarget(npc.GetPlayerTarget()->pos, STATUS_OBEYED);
|
||||
npc.friction *= FLEE_FRICTION;
|
||||
}
|
||||
|
||||
bool isGroaning = npc.controllerID == -1 ? npc.IsHostileTo(npc.GetPlayerTarget()) && npc.pathfinder.hasDirectPath &&
|
||||
Random() % GAPER_SOUND_ODDS == 0
|
||||
: npc.IsControllerActionTriggered(CONTROLLER_ACTION_GROAN);
|
||||
if (isGroaning) npc.PlaySound(SOUND_ZOMBIE_WALKER_KID, 1, GAPER_SOUND_DELAY, false, 1);
|
||||
if (npc.variant == 0 && npc.pathfinder.hasDirectPath && npc.sprite.GetOverlayFrame() < 1)
|
||||
npc.sprite.PlayOverlay("Head", PLAY_FORCED);
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
#include "npc_ai.h"
|
||||
#include "entity_effect.h"
|
||||
#include "game.h"
|
||||
|
||||
constexpr int ENTITY_PSY_HORF = 248;
|
||||
constexpr int EFFECT_BLOOD_EXPLOSION = 2;
|
||||
constexpr int BLOOD_EXPLOSION_SPIT = 5;
|
||||
constexpr int SOUND_HORF_SHOOT = 146;
|
||||
constexpr float HORF_FRICTION = 0.7f;
|
||||
constexpr float HORF_RANGE = 200;
|
||||
constexpr int HORF_RANGE_FRAMES = 7;
|
||||
constexpr int HORF_COOLDOWN = 28;
|
||||
constexpr int HORF_HARD_COOLDOWN = 14;
|
||||
constexpr float HORF_SHOT_SPEED = 7;
|
||||
constexpr float HORF_HARD_SHOT_SPEED = 10;
|
||||
constexpr float MOVEMENT_DEADZONE = 0.1f;
|
||||
constexpr float SPIT_OFFSET_Y = -10;
|
||||
constexpr float SPIT_DEPTH = 1;
|
||||
constexpr float PITCH_TINY = 1.5f;
|
||||
constexpr float PITCH_GIANT = 0.5f;
|
||||
constexpr int COLOR_PRIORITY_DEFAULT = 255;
|
||||
constexpr ColorMod SPIT_COLOR = {{1, 1, 1, 0.4f}, {0, 0, 0, 0}, {0.6f, 0.1f, 0.1f}};
|
||||
constexpr ColorMod PSY_SPIT_COLOR = {{1, 1, 1, 0.6f}, {0.8f, 0.15f, 1, 1}, {0.26f, 0.05f, 0.4f}};
|
||||
constexpr uint64_t PROJECTILE_SMART = 1;
|
||||
|
||||
// The movement its controlling player steers, none without one, kept while the stick rests.
|
||||
static void horf_controller_update(Entity_NPC& npc, bool isKeptAtRest)
|
||||
{
|
||||
if (npc.controllerID == -1)
|
||||
{
|
||||
npc.controllerMovement = {};
|
||||
return;
|
||||
}
|
||||
Vector input = npc.GetControllerMovementInput(MOVEMENT_DEADZONE);
|
||||
if (!isKeptAtRest || !vector_is_zero(input)) npc.controllerMovement = input;
|
||||
}
|
||||
|
||||
// A Horf's spit: a blood burst in its mouth and a shot at its target (a homing one for the Psy Horf).
|
||||
static void horf_shoot(Entity_NPC& npc)
|
||||
{
|
||||
Vector aim = vector_sub(npc.GetPlayerTarget()->pos, npc.pos);
|
||||
if (npc.controllerID != -1 && !vector_is_zero(npc.controllerMovement)) aim = npc.controllerMovement;
|
||||
aim = vector_resized(aim, game_is_hard_mode() ? HORF_HARD_SHOT_SPEED : HORF_SHOT_SPEED);
|
||||
|
||||
Entity_Effect* spit = static_cast<Entity_Effect*>(g_game->Spawn({.position = npc.pos,
|
||||
.subType = BLOOD_EXPLOSION_SPIT,
|
||||
.type = ENTITY_EFFECT,
|
||||
.variant = EFFECT_BLOOD_EXPLOSION,
|
||||
.seed = Random()}));
|
||||
spit->SetColor(COLOR_DEFAULT, -1, COLOR_PRIORITY_DEFAULT, false, true);
|
||||
spit->sprite.offset = vector_make(0, SPIT_OFFSET_Y);
|
||||
spit->renderDepthOffset = SPIT_DEPTH;
|
||||
spit->parent = &npc;
|
||||
spit->parentOffset = vector_sub(spit->pos, npc.pos);
|
||||
spit->sprite.isFlipX = true;
|
||||
spit->isFollowing = true;
|
||||
spit->SetColor(SPIT_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true);
|
||||
|
||||
ProjectileParams params;
|
||||
if (npc.type == ENTITY_PSY_HORF)
|
||||
{
|
||||
params.bulletFlags |= PROJECTILE_SMART;
|
||||
spit->SetColor(PSY_SPIT_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true);
|
||||
}
|
||||
npc.FireProjectiles(npc.pos, aim, PROJECTILES_SINGLE, params);
|
||||
|
||||
float pitch = npc.championColorIdx == CHAMPION_TINY ? PITCH_TINY
|
||||
: npc.championColorIdx == CHAMPION_GIANT ? PITCH_GIANT
|
||||
: 1;
|
||||
npc_sound_play(SOUND_HORF_SHOOT, 1, 2, pitch);
|
||||
}
|
||||
|
||||
// 00513080 The Horf's AI: it stays put shaking, and spits at its target in range (twice as often on Hard).
|
||||
void npc_horf_update(Entity_NPC& npc)
|
||||
{
|
||||
npc.friction *= HORF_FRICTION;
|
||||
if (npc.projectileCooldown > 0)
|
||||
{
|
||||
npc.projectileCooldown -= npc_ticks_get(npc);
|
||||
horf_controller_update(npc, true);
|
||||
}
|
||||
if (npc.projectileCooldown < 1 && npc.IsTargetInAttackRange(HORF_RANGE, HORF_RANGE_FRAMES, false))
|
||||
{
|
||||
npc.projectileCooldown = game_is_hard_mode() ? HORF_HARD_COOLDOWN : HORF_COOLDOWN;
|
||||
npc.sprite.Play("Attack");
|
||||
horf_controller_update(npc, false);
|
||||
}
|
||||
|
||||
AnimationState& animation = npc.sprite.animState;
|
||||
if (animation.animData)
|
||||
{
|
||||
if (animation.IsEventTriggered("Shoot")) horf_shoot(npc);
|
||||
if (animation.animData && animation.isPlaying) return;
|
||||
}
|
||||
|
||||
bool isShaking = animation.animData && animation.animData->name == "Shake" &&
|
||||
(!animation.animData->isLooping || animation.isPlaying);
|
||||
if (!isShaking && npc.sprite.SetAnimation("Shake", SWITCH_KEEP_FRAME))
|
||||
{
|
||||
animation.Rewind();
|
||||
animation.isPlaying = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
#include "path_finder.h"
|
||||
#include "entity_npc.h"
|
||||
#include "game.h"
|
||||
#include "log.h"
|
||||
#include "room.h"
|
||||
|
||||
constexpr float GRID_CELL = 40;
|
||||
constexpr float GRID_TOP = 120;
|
||||
constexpr float HALF = 0.5f;
|
||||
constexpr int PATH_ENEMY_TYPE_LAST = 999;
|
||||
|
||||
// 007e3260 Forgets every path, target and evasion, and its grid cell.
|
||||
void PathFinder::Reset()
|
||||
{
|
||||
gridIndex = -1;
|
||||
pathStep = 0;
|
||||
moveCountdown = 0;
|
||||
hasDirectPath = false;
|
||||
isPathFound = false;
|
||||
gridPathTarget = {};
|
||||
evadeMovementCountdown = 0;
|
||||
evadeDistance = 0;
|
||||
stuckFrames = 0;
|
||||
visitedGridIndices.clear();
|
||||
direction = PATH_DIRECTION_NONE;
|
||||
directionTimer = 0;
|
||||
targetGridIndex = -1;
|
||||
canCrushRocks = false;
|
||||
movementTarget = {};
|
||||
moveDirection = {};
|
||||
}
|
||||
|
||||
// 007e6fa0 Forgets the spot it wanders to.
|
||||
void PathFinder::ResetMovementTarget()
|
||||
{
|
||||
movementTarget = {};
|
||||
moveDirection = {};
|
||||
}
|
||||
|
||||
// 007e6ff0 Notes the grid cell its owner stands in, or -1 outside the grid.
|
||||
void PathFinder::UpdateGridIndex()
|
||||
{
|
||||
Room& room = *g_game->room;
|
||||
int column = (int)((entity->pos.x - GRID_CELL) / GRID_CELL + HALF);
|
||||
int row = (int)((entity->pos.y - GRID_TOP) / GRID_CELL + HALF);
|
||||
bool isInside = column >= 0 && column < room.gridWidth && row >= 0 && row < room.gridHeight;
|
||||
gridIndex = isInside ? room.gridWidth * row + column : -1;
|
||||
}
|
||||
|
||||
// 007e3340 Whether its owner paths as the players' side: charmed, the Blood Puppy, after a baited target, or an
|
||||
// enemy under a player's control or forced onto a target.
|
||||
bool PathFinder::is_entity_friendly()
|
||||
{
|
||||
if (!entity) return false;
|
||||
if (entity->HasEntityFlags(FLAG_CHARM) || entity->type == ENTITY_BLOOD_PUPPY) return true;
|
||||
if (entity->target && entity->target->HasEntityFlags(FLAG_BAITED)) return true;
|
||||
if (entity->type < ENTITY_FIRST_ENEMY || entity->type > PATH_ENEMY_TYPE_LAST) return false;
|
||||
|
||||
Entity_NPC* npc = static_cast<Entity_NPC*>(entity);
|
||||
return npc->controllerID != -1 || npc->forcedTarget;
|
||||
}
|
||||
|
||||
// 007e33c0
|
||||
void PathFinder::FindGridPath(const Vector&, float, int, bool)
|
||||
{
|
||||
reconstruction_missing("PathFinder::FindGridPath 007e33c0");
|
||||
}
|
||||
|
||||
// 007e4940
|
||||
void PathFinder::EvadeTarget(const Vector&, StatusMode)
|
||||
{
|
||||
reconstruction_missing("PathFinder::EvadeTarget 007e4940");
|
||||
}
|
||||
|
||||
// 007e6300
|
||||
bool PathFinder::MoveRandomly(StatusMode)
|
||||
{
|
||||
reconstruction_missing("PathFinder::MoveRandomly 007e6300");
|
||||
}
|
||||
|
||||
// 007e5340
|
||||
void PathFinder::MoveRandomlyAxisAligned(float, StatusMode)
|
||||
{
|
||||
reconstruction_missing("PathFinder::MoveRandomlyAxisAligned 007e5340");
|
||||
}
|
||||
|
||||
// 007e6650
|
||||
void PathFinder::MoveRandomlyBoss(StatusMode)
|
||||
{
|
||||
reconstruction_missing("PathFinder::MoveRandomlyBoss 007e6650");
|
||||
}
|
||||
|
||||
// 007e6b90
|
||||
void PathFinder::update_chase_movement()
|
||||
{
|
||||
reconstruction_missing("PathFinder::update_chase_movement 007e6b90");
|
||||
}
|
||||
|
||||
// 007e7070
|
||||
bool PathFinder::HasPathToPos(const Vector&, bool)
|
||||
{
|
||||
reconstruction_missing("PathFinder::HasPathToPos 007e7070");
|
||||
}
|
||||
|
||||
// 007e8010
|
||||
void PathFinder::SimulatePlayerMovement(float*)
|
||||
{
|
||||
reconstruction_missing("PathFinder::SimulatePlayerMovement 007e8010");
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
#pragma once
|
||||
|
||||
#include "classes.h"
|
||||
#include <set>
|
||||
|
||||
struct Entity;
|
||||
|
||||
// Lua's Direction, the way SimulatePlayerMovement reads a movement.
|
||||
enum PathDirection : int
|
||||
{
|
||||
PATH_DIRECTION_NONE = -1,
|
||||
PATH_DIRECTION_LEFT,
|
||||
PATH_DIRECTION_UP,
|
||||
PATH_DIRECTION_RIGHT,
|
||||
PATH_DIRECTION_DOWN
|
||||
};
|
||||
|
||||
// Whether a movement call steers even while its owner is feared, confused or charmed.
|
||||
enum StatusMode
|
||||
{
|
||||
STATUS_OBEYED,
|
||||
STATUS_IGNORED
|
||||
};
|
||||
|
||||
// Construction (007e31a0) is the default, with the owner given by its holder.
|
||||
// Field accessors (00456370, 00456740, 00499dc0, 004be6e0) are the public fields.
|
||||
// How an NPC finds its way around the room (Lua's PathFinder, the original's NPCAI_Pathfinder): the grid path it
|
||||
// follows to a target, the spot it wanders to, and the evasion it keeps up.
|
||||
struct PathFinder
|
||||
{
|
||||
std::set<int> visitedGridIndices;
|
||||
Entity* entity = nullptr;
|
||||
Vector gridPathTarget{};
|
||||
Vector moveDirection{};
|
||||
Vector movementTarget{};
|
||||
float evadeDistance = 0;
|
||||
int direction = PATH_DIRECTION_NONE;
|
||||
int directionTimer = 0;
|
||||
int evadeMovementCountdown = 0;
|
||||
int gridIndex = -1;
|
||||
int moveCountdown = 0;
|
||||
int pathLength = 0;
|
||||
int pathStep = 0;
|
||||
int stuckFrames = 0;
|
||||
int targetGridIndex = -1;
|
||||
bool canCrushRocks = false;
|
||||
bool hasDirectPath = false;
|
||||
bool isPathFound = false;
|
||||
|
||||
explicit PathFinder(Entity* owner) : entity(owner) {}
|
||||
|
||||
void Reset();
|
||||
void ResetMovementTarget();
|
||||
void UpdateGridIndex();
|
||||
bool is_entity_friendly();
|
||||
void FindGridPath(const Vector& position, float speed, int pathMarker, bool isUseDirectPath);
|
||||
void EvadeTarget(const Vector& targetPos, StatusMode mode);
|
||||
bool MoveRandomly(StatusMode mode);
|
||||
void MoveRandomlyAxisAligned(float speed, StatusMode mode);
|
||||
void MoveRandomlyBoss(StatusMode mode);
|
||||
void update_chase_movement();
|
||||
bool HasPathToPos(const Vector& position, bool isIgnorePoop);
|
||||
void SimulatePlayerMovement(float* inputs);
|
||||
};
|
||||
+216
-3
@@ -4,8 +4,10 @@
|
||||
#include "entity_player.h"
|
||||
#include "game.h"
|
||||
#include "item_config.h"
|
||||
#include "kage_input.h"
|
||||
#include "log.h"
|
||||
#include "manager.h"
|
||||
#include "menu_manager.h"
|
||||
#include "platform.h"
|
||||
#include "popups.h"
|
||||
#include "preload_manager.h"
|
||||
@@ -28,6 +30,25 @@ constexpr float PLAYER_START_X = 320;
|
||||
constexpr float PLAYER_START_Y = 400;
|
||||
constexpr int HOURGLASS_INDEX_LAST = 3;
|
||||
|
||||
// The join carousel: the frames a joined player cannot act, its minimum invincibility, how far from the first player it
|
||||
// appears, and how far over a leaving baby's poof shows.
|
||||
constexpr int JOIN_CONTROLS_COOLDOWN = 15;
|
||||
constexpr int JOIN_DAMAGE_COOLDOWN = 45;
|
||||
constexpr float JOIN_SPAWN_DISTANCE = 10;
|
||||
constexpr float LEAVE_POOF_HEIGHT = 10;
|
||||
constexpr float JOIN_MENU_POSITION = 1;
|
||||
constexpr int COOP_BABY_MIN_HEARTS = 3;
|
||||
constexpr int EFFECT_POOF01 = 15;
|
||||
constexpr int SOUND_JOIN_REFUSED = 187;
|
||||
constexpr int SOUND_CAROUSEL_LEFT = 194;
|
||||
constexpr int SOUND_CAROUSEL_RIGHT = 195;
|
||||
constexpr float JOIN_REFUSED_VOLUME = 0.5f;
|
||||
|
||||
// The static buildup the poisoned players' rising damage plays, louder as it builds.
|
||||
constexpr int SOUND_STATIC_BUILDUP = 508;
|
||||
constexpr float STATIC_BUILDUP_FRAMES = 20;
|
||||
constexpr float STATIC_BUILDUP_MIN_VOLUME = 0.01f;
|
||||
|
||||
// How far apart get_player_start_position spreads the players, and the rows past two players.
|
||||
constexpr float START_SPACING = 48;
|
||||
constexpr float START_ROW_OFFSET = 24;
|
||||
@@ -796,12 +817,205 @@ void PlayerManager::restore_controller_assignment()
|
||||
{
|
||||
reconstruction_missing("PlayerManager::restore_controller_assignment 009bf530");
|
||||
}
|
||||
void PlayerManager::handle_coop_join() { reconstruction_missing("PlayerManager::handle_coop_join 009bac40"); }
|
||||
void PlayerManager::spawn_coop_baby_for_join(int)
|
||||
{
|
||||
reconstruction_missing("PlayerManager::spawn_coop_baby_for_join 009bd3b0");
|
||||
}
|
||||
void PlayerManager::Update() { reconstruction_missing("PlayerManager::Update 009bb5d0"); }
|
||||
// Plays a sound at a volume, unless the seeds swap it for a fart.
|
||||
static void manager_sound_play(int sound, SoundPlay play = {})
|
||||
{
|
||||
seed_fart_sound_override(&sound);
|
||||
g_manager->sfxManager.Play(sound, play);
|
||||
}
|
||||
|
||||
// Takes an action's buttons on a device as used this frame, so they do not trigger again until released.
|
||||
static void device_action_consume(KAGE::Input::InputDevice& device, ButtonAction action)
|
||||
{
|
||||
const InputBindings& bindings = platform.bindings;
|
||||
const std::vector<ActionBinding>& table =
|
||||
device.type == KAGE::Input::DEVICE_KEYBOARD ? bindings.keyboard : bindings.controller;
|
||||
|
||||
if (action >= (int)table.size()) return;
|
||||
for (int button : table[action])
|
||||
if (button != KAGE::Input::BUTTON_NONE) device.button_consume(button);
|
||||
}
|
||||
|
||||
// Whether a controller is a player's, a kept extra player's, or an open seat's.
|
||||
static bool is_controller_joined(PlayerManager& players, int controller, Entity_Player** joined)
|
||||
{
|
||||
bool isJoined = false;
|
||||
|
||||
for (Entity_Player* player : players.playerList)
|
||||
if (player->controllerIndex == controller)
|
||||
{
|
||||
isJoined = true;
|
||||
*joined = player;
|
||||
}
|
||||
for (Entity_Player* extra : players.extraPlayers) isJoined = isJoined || extra->controllerIndex == controller;
|
||||
for (CoopJoinSlot& seat : players.coopSlots) isJoined = isJoined || (seat.controllerIndex == controller && seat.state >= 0);
|
||||
return isJoined;
|
||||
}
|
||||
|
||||
// A controller's join input: joining opens a seat on the carousel, or a co-op baby when only babies may join, refused
|
||||
// in dailies. Pressing join again takes a co-op baby out. Joining with bomb and pill held spawns a possessor.
|
||||
static void controller_join_update(PlayerManager& players, KAGE::Input::InputDevice& device)
|
||||
{
|
||||
Game& game = *g_game;
|
||||
int controller = device.id;
|
||||
Entity_Player* joined = nullptr;
|
||||
bool isJoined = is_controller_joined(players, controller, &joined);
|
||||
|
||||
bool isPossessor = !isJoined && is_controller_action(controller, ACTION_JOIN_MULTIPLAYER, ACTION_TRIGGERED) &&
|
||||
is_controller_action(controller, ACTION_BOMB, ACTION_PRESSED) &&
|
||||
is_controller_action(controller, ACTION_PILL_CARD, ACTION_PRESSED);
|
||||
if (isPossessor)
|
||||
{
|
||||
game.console.print_format(CONSOLE_WHITE, "Joining as possessor\n");
|
||||
players.SpawnCoPlayer2(-1)->SetControllerIndex(controller, true);
|
||||
return;
|
||||
}
|
||||
|
||||
bool isJoinAllowed = !PlayerManager::CoopBabiesOnly() ||
|
||||
players.GetPlayer(0)->soulHearts + players.GetPlayer(0)->redHearts >= COOP_BABY_MIN_HEARTS;
|
||||
if (game.dailyChallenge._id == 0 && isJoinAllowed && players.playerList.size() < MAX_PLAYERS && !isJoined)
|
||||
{
|
||||
int slot = is_controller_action(controller, ACTION_JOIN_MULTIPLAYER, ACTION_TRIGGERED)
|
||||
? players.GetPlayerSlotFromController(controller) : -1;
|
||||
if (slot < 0) return;
|
||||
if (PlayerManager::CoopBabiesOnly()) return players.spawn_coop_baby_for_join(controller);
|
||||
|
||||
CoopJoinSlot& seat = players.coopSlots[slot];
|
||||
bool isForced = game.challenge != 0 || game.dailyChallenge._id != 0;
|
||||
if (!isForced) device_action_consume(device, ACTION_JOIN_MULTIPLAYER);
|
||||
seat.playerType = isForced ? game.GetChallengeParams().playerType : 0;
|
||||
seat.state = 1;
|
||||
seat.menuPosition = JOIN_MENU_POSITION;
|
||||
seat.isPlayerTypeForced = isForced;
|
||||
return;
|
||||
}
|
||||
if (game.dailyChallenge._id != 0 && !isJoined)
|
||||
{
|
||||
if (is_controller_action(controller, ACTION_JOIN_MULTIPLAYER, ACTION_TRIGGERED))
|
||||
manager_sound_play(SOUND_JOIN_REFUSED, {.volume = JOIN_REFUSED_VOLUME});
|
||||
return;
|
||||
}
|
||||
if (!isJoined || !joined || joined->parent) return;
|
||||
if (!is_controller_action(controller, ACTION_JOIN_MULTIPLAYER, ACTION_TRIGGERED) || joined->variant == PLAYER_VARIANT_PLAYER)
|
||||
return;
|
||||
if (joined->sprite.animState.animData && joined->sprite.animState.isPlaying && joined->sprite.GetAnimation() == "Appear")
|
||||
return;
|
||||
|
||||
Entity_Player* first = players.GetPlayer(0);
|
||||
if (first->isPlayingExtraAnimation || first->isPlayingItemAnimation) return;
|
||||
uint32_t seed = Random();
|
||||
game.Spawn({.position = vector_make(joined->pos.x, joined->pos.y - LEAVE_POOF_HEIGHT), .type = ENTITY_EFFECT,
|
||||
.variant = EFFECT_POOF01, .seed = seed});
|
||||
players.RemoveCoPlayer(joined);
|
||||
}
|
||||
|
||||
// A seat of the join carousel: left and right pick a character, confirming (or a forced character) spawns the player
|
||||
// beside the first one, and backing out closes the seat. Only co-op babies may join closes it at once.
|
||||
static void coop_seat_update(PlayerManager& players, CoopJoinSlot& seat)
|
||||
{
|
||||
if (seat.controllerIndex < 0 || seat.state < 0) return;
|
||||
if (PlayerManager::CoopBabiesOnly())
|
||||
{
|
||||
seat.state = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<int>& types = players.coopPlayerTypes;
|
||||
int carousel = (int)types.size();
|
||||
if (is_controller_action(seat.controllerIndex, ACTION_MENU_LEFT, ACTION_TRIGGERED))
|
||||
{
|
||||
if (--seat.state < 0) seat.state = carousel - 1;
|
||||
seat.playerType = types[seat.state];
|
||||
return manager_sound_play(SOUND_CAROUSEL_LEFT);
|
||||
}
|
||||
if (is_controller_action(seat.controllerIndex, ACTION_MENU_RIGHT, ACTION_TRIGGERED))
|
||||
{
|
||||
if (++seat.state >= carousel) seat.state = 0;
|
||||
seat.playerType = types[seat.state];
|
||||
return manager_sound_play(SOUND_CAROUSEL_RIGHT);
|
||||
}
|
||||
|
||||
bool isConfirmed = is_controller_action(seat.controllerIndex, ACTION_MENU_CONFIRM, ACTION_TRIGGERED) || seat.isPlayerTypeForced;
|
||||
if (!isConfirmed)
|
||||
{
|
||||
if (is_controller_action(seat.controllerIndex, ACTION_MENU_BACK, ACTION_TRIGGERED)) seat.state = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
// A carousel of the random pick alone picks past its end in the original, so it picks the random pick here.
|
||||
int playerType = seat.playerType;
|
||||
seat.isPlayerTypeForced = false;
|
||||
if (playerType == COOP_CHARACTER_RANDOM)
|
||||
playerType = carousel > 1 ? types[1 + Random() % (uint32_t)(carousel - 1)] : types[0];
|
||||
|
||||
Game& game = *g_game;
|
||||
Entity_Player* player = game.playerManager.SpawnCoPlayer2(playerType);
|
||||
player->SetControllerIndex(seat.controllerIndex, true);
|
||||
Vector first = game.playerManager.GetPlayer(0)->pos;
|
||||
float angle = (float)Random() * RANDOM_SCALE * HALF_TURN;
|
||||
angle += angle;
|
||||
player->pos = vector_make(std::cos(angle) * JOIN_SPAWN_DISTANCE + first.x, std::sin(angle) * JOIN_SPAWN_DISTANCE + first.y);
|
||||
game.hud.AssignPlayerHUDs();
|
||||
player->InitPostLevelInitStats();
|
||||
player->controlsCooldown = JOIN_CONTROLS_COOLDOWN;
|
||||
game.Spawn({.position = player->pos, .type = ENTITY_EFFECT, .variant = EFFECT_POOF01, .seed = Random()});
|
||||
player->damageCooldown = std::max(player->damageCooldown, JOIN_DAMAGE_COOLDOWN);
|
||||
seat.state = -1;
|
||||
}
|
||||
|
||||
// 009bac40 Co-op joining each frame, offline only: every controller's join input, then the join carousel's seats, then
|
||||
// the extra players' spectated target.
|
||||
void PlayerManager::handle_coop_join()
|
||||
{
|
||||
if (!g_manager->netplayManager.is_online())
|
||||
{
|
||||
for (int i = 0; i < KAGE::Input::manager.get_device_count(); i++)
|
||||
if (std::shared_ptr<KAGE::Input::InputDevice> device = KAGE::Input::manager.get_device(i))
|
||||
controller_join_update(*this, *device);
|
||||
for (CoopJoinSlot& seat : coopSlots) coop_seat_update(*this, seat);
|
||||
}
|
||||
for (size_t i = 0; i < extraPlayers.size(); i++) extraPlayers[i]->cycle_spectate_target();
|
||||
}
|
||||
|
||||
// 009bb5d0 The players each frame: those dead whose death animation (and their twin's) has ended trigger their death
|
||||
// outside transitions, and the static buildup plays as loud as the most poisoned player's.
|
||||
void PlayerManager::Update()
|
||||
{
|
||||
Game& game = *g_game;
|
||||
|
||||
if (game.roomTransition.mode == TRANSITION_NONE && game.stageTransition._state == 0)
|
||||
for (size_t i = 0; i < game.playerManager.playerList.size(); i++)
|
||||
{
|
||||
Entity_Player* player = GetPlayer((int)i);
|
||||
Entity_Player* twin = player->twin_get();
|
||||
bool isAnimating = player->sprite.animState.animData && player->sprite.animState.isPlaying;
|
||||
bool isTwinAnimating = twin && twin->sprite.animState.animData && twin->sprite.animState.isPlaying;
|
||||
if (player->isDead && !isAnimating && !isTwinAnimating) player->TriggerDeath(false);
|
||||
}
|
||||
|
||||
float volume = 0;
|
||||
for (size_t i = 0; i < game.playerManager.playerList.size(); i++)
|
||||
{
|
||||
Entity_Player* player = GetPlayer((int)i);
|
||||
if (player->poisonDamageFrames > 0 && !player->HasEntityFlags(FLAG_POISON) && !player->isDead)
|
||||
volume = std::max(volume, std::clamp((float)player->poisonDamageFrames / STATIC_BUILDUP_FRAMES, 0.0f, 1.0f));
|
||||
}
|
||||
|
||||
SFXManager& sfx = g_manager->sfxManager;
|
||||
if (volume <= STATIC_BUILDUP_MIN_VOLUME)
|
||||
{
|
||||
if (sfx.IsPlaying(SOUND_STATIC_BUILDUP)) sfx.Stop(SOUND_STATIC_BUILDUP);
|
||||
return;
|
||||
}
|
||||
if (!sfx.IsPlaying(SOUND_STATIC_BUILDUP)) return manager_sound_play(SOUND_STATIC_BUILDUP, {.volume = volume, .loop = SOUND_LOOP});
|
||||
sfx.AdjustVolume(SOUND_STATIC_BUILDUP, volume);
|
||||
sfx.AdjustPitch(SOUND_STATIC_BUILDUP, 1);
|
||||
}
|
||||
|
||||
void PlayerManager::trigger_room_clear() { reconstruction_missing("PlayerManager::trigger_room_clear 009bb840"); }
|
||||
void PlayerManager::trigger_coop_baby_death(Entity_Player*)
|
||||
{
|
||||
@@ -824,7 +1038,6 @@ void PlayerManager::RestoreGameState_PostLevelInit(GameState*)
|
||||
{
|
||||
reconstruction_missing("PlayerManager::RestoreGameState_PostLevelInit 009bd010");
|
||||
}
|
||||
void PlayerManager::store_game_state(GameState*) { reconstruction_missing("PlayerManager::store_game_state 009bd150"); }
|
||||
int* PlayerManager::match_saved_players(int*, int, bool)
|
||||
{
|
||||
reconstruction_missing("PlayerManager::match_saved_players 009bc790");
|
||||
|
||||
@@ -3374,3 +3374,54 @@ void Room::card_against_humanity_fill()
|
||||
{
|
||||
reconstruction_missing("Room::card_against_humanity_fill 007fe220");
|
||||
}
|
||||
|
||||
// The last frames of a clear's delay that leaving the room still counts the clear in.
|
||||
constexpr int ROOM_CLEAR_DELAY_PENDING = 8;
|
||||
|
||||
// Whether the room keeps an entity when the players leave, as Entity_Pickup::CanFlip (007eeeb0) checks before saving
|
||||
// it: alive, not persistent, off any minecart (unless it rides the one saved with it), and of a kept type.
|
||||
static bool is_entity_kept(Room& room, Entity& entity, bool isRiding)
|
||||
{
|
||||
if (entity.isDead || (entity.flags & FLAG_PERSISTENT) || (entity.minecart && !isRiding)) return false;
|
||||
return entity_type_is_saved(entity.type, entity.variant, (uint32_t)entity.subtype, entity.spawnerType, room.IsClear());
|
||||
}
|
||||
|
||||
// 007efa50 Stores the room in its descriptor as the players leave: a partial shop restock comes due, and a clear still
|
||||
// pending counts (the score, the players' room clear, the award and Greed's wave). Then, outside the debug room and
|
||||
// once visited, its grid cells and the entities it keeps (a minecart only with its rider) are saved.
|
||||
void Room::on_leave()
|
||||
{
|
||||
Game& game = *g_game;
|
||||
|
||||
if (shopRestockTimer > 0)
|
||||
{
|
||||
shopRestockTimer = -1;
|
||||
reconstruction_missing("Room::ShopRestockPartial 008158a0");
|
||||
}
|
||||
if (game.currentRoomIdx == ROOM_DEBUG_IDX || descriptor->visitedCount == 0) return;
|
||||
if (roomClearDelay >= 1 && roomClearDelay <= ROOM_CLEAR_DELAY_PENDING && !IsClear())
|
||||
{
|
||||
bool isGreedWave = game.IsGreedMode() && roomType == ROOM_DEFAULT;
|
||||
|
||||
roomClearDelay = 0;
|
||||
descriptor->flags |= ROOM_DESCRIPTOR_FLAG_CLEAR;
|
||||
descriptor->clearCount++;
|
||||
game.scoreSheet.add_cleared_room({descriptor->clearCount, descriptor->data->shape, roomType,
|
||||
(descriptor->flags & ROOM_DESCRIPTOR_FLAG_RED_ROOM) != 0});
|
||||
if (!isGreedWave) game.playerManager.trigger_room_clear();
|
||||
reconstruction_missing("Room::SpawnClearAward 007fb250");
|
||||
if (isGreedWave) game.greedLastBeatenWave = game.greedModeWave;
|
||||
}
|
||||
|
||||
descriptor->savedEntities.clear();
|
||||
for (int i = 0; i < gridWidth * gridHeight; i++)
|
||||
descriptor->savedGridEntities[i] = gridEntities[i] ? gridEntities[i]->desc_save() : GRID_SAVE_EMPTY;
|
||||
for (Entity* entity : entityList.updateEL)
|
||||
{
|
||||
bool isCart = entity->type == ENTITY_MINECART && entity->variant == 0;
|
||||
Entity* rider = entity->child.get();
|
||||
bool isKept = isCart ? rider && is_entity_kept(*this, *rider, true) && is_entity_kept(*this, *entity, false)
|
||||
: is_entity_kept(*this, *entity, false);
|
||||
if (isKept) reconstruction_missing("Room::on_leave 007efa50: saving an entity (EntitySaveState has no layout yet)");
|
||||
}
|
||||
}
|
||||
@@ -308,6 +308,7 @@ public:
|
||||
void PlayMusic();
|
||||
|
||||
void Update();
|
||||
void on_leave();
|
||||
void update_ambient_sounds();
|
||||
void first_frame_update();
|
||||
void grid_paths_decay();
|
||||
|
||||
+160
-10
@@ -4,6 +4,7 @@
|
||||
#include "fx_layers.h"
|
||||
#include "game.h"
|
||||
#include "grid_entity_door.h"
|
||||
#include "level.h"
|
||||
#include "log.h"
|
||||
#include "manager.h"
|
||||
#include "platform.h"
|
||||
@@ -46,6 +47,15 @@ constexpr int MINECART_RIDDEN = 10;
|
||||
constexpr int NPC_STATE_MINECART_MOVING = 4;
|
||||
constexpr int COLLECTIBLE_GLOWING_HOURGLASS = 422;
|
||||
constexpr int COLLECTIBLE_D7 = 437;
|
||||
constexpr const char* ANIMATION_APPEAR = "Appear";
|
||||
constexpr float APPEAR_FRAME = 2;
|
||||
constexpr float SCREEN_CELL_SIZE = 26;
|
||||
constexpr int ROOM_CELLS_ACROSS = 13;
|
||||
constexpr int ROOM_CELLS_DOWN = 7;
|
||||
constexpr int DEATH_CERTIFICATE_DIMENSION = 2;
|
||||
constexpr int STAGE_ID_HOME = 35;
|
||||
constexpr int DOGMA_ROOM_VARIANT = 1000;
|
||||
constexpr uint32_t BOSS_DOGMA = 99;
|
||||
|
||||
// The items whose pickup animation an extra life plays once the player is back, from the Ankh to Lazarus' Rags: Ankh,
|
||||
// Dead Cat, 1up!, Guppy's Collar, Judas' Shadow and Lazarus' Rags.
|
||||
@@ -130,9 +140,137 @@ void RoomTransition::StartBossIntro(uint32_t, uint32_t)
|
||||
reconstruction_missing("RoomTransition::StartBossIntro 0082f1c0");
|
||||
}
|
||||
|
||||
// The distance between two rooms in screen pixels, mirrored in the mirror world: from their map cells when both lie on
|
||||
// the map of one dimension, else the size of the room on the side left through (the target's for left and up).
|
||||
static Vector room_distance_get(RoomDescriptor& current, RoomDescriptor& target, bool isOnMap, Direction direction)
|
||||
{
|
||||
Vector distance{};
|
||||
|
||||
if (isOnMap)
|
||||
{
|
||||
int columns = target.gridIndex % LEVEL_GRID_WIDTH - current.gridIndex % LEVEL_GRID_WIDTH;
|
||||
int rows = target.gridIndex / LEVEL_GRID_WIDTH - current.gridIndex / LEVEL_GRID_WIDTH;
|
||||
distance = vector_make((float)(columns * ROOM_CELLS_ACROSS) * SCREEN_CELL_SIZE,
|
||||
(float)(rows * ROOM_CELLS_DOWN) * SCREEN_CELL_SIZE);
|
||||
}
|
||||
else switch (direction)
|
||||
{
|
||||
case DIRECTION_LEFT:
|
||||
distance.x = -(float)target.data->width * SCREEN_CELL_SIZE;
|
||||
break;
|
||||
case DIRECTION_UP:
|
||||
distance.y = -(float)target.data->height * SCREEN_CELL_SIZE;
|
||||
break;
|
||||
case DIRECTION_RIGHT:
|
||||
distance.x = (float)current.data->width * SCREEN_CELL_SIZE;
|
||||
break;
|
||||
case DIRECTION_DOWN:
|
||||
distance.y = (float)current.data->height * SCREEN_CELL_SIZE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (Room::IsMirrorWorld()) distance.x = -distance.x;
|
||||
return distance;
|
||||
}
|
||||
|
||||
// How far past a screen the rooms slide through a door: the rooms' distance less the camera's change between them,
|
||||
// across mirrored in the mirror world.
|
||||
void RoomTransition::slide_offset_set(Vector distance, Vector oldScroll)
|
||||
{
|
||||
Vector newScroll = g_game->room->renderScrollOffset;
|
||||
float across = Room::IsMirrorWorld() ? oldScroll.x - newScroll.x : newScroll.x - oldScroll.x;
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
case DIRECTION_LEFT:
|
||||
slideOffset.x = across - g_screenWidth - distance.x;
|
||||
break;
|
||||
case DIRECTION_UP:
|
||||
slideOffset.y = newScroll.y - oldScroll.y - g_screenHeight - distance.y;
|
||||
break;
|
||||
case DIRECTION_RIGHT:
|
||||
slideOffset.x = -across - g_screenWidth + distance.x;
|
||||
break;
|
||||
case DIRECTION_DOWN:
|
||||
slideOffset.y = oldScroll.y - newScroll.y - g_screenHeight + distance.y;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Puts the players in the new room. A teleport keeps them hidden, else the main players not held show. The Forgotten's
|
||||
// body, the Death Certificate's floor, a teleporter's pad and the Ventricle Razor's portals place them.
|
||||
void RoomTransition::arrival_place()
|
||||
{
|
||||
Game& game = *g_game;
|
||||
Room& room = *game.room;
|
||||
bool isTeleporterRoom = room.roomType == ROOM_TELEPORTER || room.roomType == ROOM_TELEPORTER_EXIT;
|
||||
|
||||
if (animation == TRANSITION_WOMB_TELEPORT)
|
||||
{
|
||||
for (VentricleRazorPortal& portal : game.ventricleRazorPortals)
|
||||
if (portal.roomIndex == game.currentRoomIdx)
|
||||
reconstruction_missing("RoomTransition::ChangeRoom 00830950: the players jumping out of a Ventricle "
|
||||
"Razor portal (Entity_Player +0x14c, +0x98)");
|
||||
return;
|
||||
}
|
||||
if (!is_teleport())
|
||||
for (Entity_Player* player : game.playerManager.playerList)
|
||||
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");
|
||||
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)
|
||||
for (Entity_Player* player : game.playerManager.playerList)
|
||||
{
|
||||
if (!player) continue;
|
||||
player->PlayExtraAnimation(ANIMATION_APPEAR);
|
||||
if (player->sprite.animState.animData) player->sprite.animState.SetFrameFloat(APPEAR_FRAME);
|
||||
player->isControlsEnabled = false;
|
||||
}
|
||||
else if (animation == TRANSITION_TELEPORT && teleporterTarget > 0 && isTeleporterRoom)
|
||||
reconstruction_missing("RoomTransition::ChangeRoom 00830950: Entity_Player::Teleport 007cd950 to a teleporter");
|
||||
}
|
||||
|
||||
// 00830950 Takes the players into the target room (the Glowing Hourglass rewinds the room instead), their controls on
|
||||
// while it loads, and works out how far a walk through a door slides. The new room's boss gets its versus screen
|
||||
// (Dogma's living room too), else the room plays its music. The players are placed and the new room is captured.
|
||||
void RoomTransition::ChangeRoom()
|
||||
{
|
||||
reconstruction_missing("RoomTransition::ChangeRoom 00830950");
|
||||
Game& game = *g_game;
|
||||
std::vector<Entity_Player*>& players = game.playerManager.playerList;
|
||||
RoomDescriptor& current = *game.GetRoomByIdx(game.currentRoomIdx, game.currentDimensionIdx);
|
||||
RoomDescriptor& target = *game.GetRoomByIdx(roomIndex, roomDimension);
|
||||
bool isOnMap = roomIndex >= 0 && game.currentRoomIdx >= 0 && current.dimension == target.dimension;
|
||||
Vector distance = room_distance_get(current, target, isOnMap, direction);
|
||||
Vector oldScroll = game.room->renderScrollOffset;
|
||||
|
||||
if (game.deathmatchManager.state < DEATHMATCH_INTRO)
|
||||
for (Entity_Player* player : players) player->isControlsEnabled = true;
|
||||
if (animation == TRANSITION_GLOWING_HOURGLASS) reconstruction_missing("Game::rewind 00706020");
|
||||
else
|
||||
{
|
||||
if (direction == DIRECTION_NONE) game.leaveDoor = DOOR_NONE;
|
||||
game.ChangeRoom(roomIndex, roomDimension);
|
||||
}
|
||||
for (Entity_Player* player : players) player->isControlsEnabled = false;
|
||||
if (animation == TRANSITION_WALK) slide_offset_set(distance, oldScroll);
|
||||
|
||||
Room& room = *game.room;
|
||||
RoomConfig_Room* data = room.descriptor->data;
|
||||
bool isDogmaRoom = data && data->stageId == STAGE_ID_HOME && data->type == ROOM_DEFAULT &&
|
||||
data->variant == DOGMA_ROOM_VARIANT && !room.IsClear();
|
||||
|
||||
if (room.bossId != 0 && room.GetAliveBossesCount() >= 1) StartBossIntro(room.bossId, room.secondBossId);
|
||||
else if (isDogmaRoom) StartBossIntro(BOSS_DOGMA, 0);
|
||||
else if (game.deathmatchManager.state < DEATHMATCH_INTRO) room.PlayMusic();
|
||||
|
||||
arrival_place();
|
||||
room_capture(newRoomSurface);
|
||||
}
|
||||
|
||||
// Whether a player plays an extra or item animation that holds the transition: one not looping.
|
||||
@@ -248,12 +386,25 @@ void RoomTransition::start_update(Entity_NPC* minecartNpc)
|
||||
old_room_capture();
|
||||
}
|
||||
|
||||
// Renders the room as it stands, lit, into a surface.
|
||||
void RoomTransition::room_capture(KAGE::Graphics::ImagePtr& surface)
|
||||
{
|
||||
KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager;
|
||||
|
||||
g_game->room->render_lighting();
|
||||
graphics.render_target_push(surface.get(), KAGE::Graphics::TARGET_SCREEN_SIZE, KAGE::Graphics::PRESENT_FLUSH);
|
||||
graphics.Clear();
|
||||
graphics.blendMode.SetMode(KAGE::Graphics::BLEND_NORMAL);
|
||||
g_game->room->Render();
|
||||
graphics.Present(KAGE::Graphics::PRESENT_FINISH);
|
||||
graphics.render_target_pop(KAGE::Graphics::PRESENT_FLUSH);
|
||||
}
|
||||
|
||||
// Hides the players leaving (all of them, but only the one who walked out through a door or pixelated) and renders
|
||||
// the room into the old room surface. A fade shows it going out, a forced boss or arena transition changing room at
|
||||
// once, and anything else changes room and comes in.
|
||||
void RoomTransition::old_room_capture()
|
||||
{
|
||||
KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager;
|
||||
Game& game = *g_game;
|
||||
bool isWalking = animation == TRANSITION_WALK || animation == TRANSITION_PIXELATION;
|
||||
|
||||
@@ -264,14 +415,7 @@ void RoomTransition::old_room_capture()
|
||||
(!isWalking || direction == DIRECTION_NONE || player == game.playerManager.roomTransitionPlayer))
|
||||
player->isVisible = false;
|
||||
|
||||
game.room->render_lighting();
|
||||
graphics.render_target_push(oldRoomSurface.get(), KAGE::Graphics::TARGET_SCREEN_SIZE,
|
||||
KAGE::Graphics::PRESENT_FLUSH);
|
||||
graphics.Clear();
|
||||
graphics.blendMode.SetMode(KAGE::Graphics::BLEND_NORMAL);
|
||||
game.room->Render();
|
||||
graphics.Present(KAGE::Graphics::PRESENT_FINISH);
|
||||
graphics.render_target_pop(KAGE::Graphics::PRESENT_FLUSH);
|
||||
room_capture(oldRoomSurface);
|
||||
|
||||
bool isChangedAtOnce = animation == TRANSITION_BOSS_FORCED || animation == TRANSITION_ARENA;
|
||||
if (is_fade() || isChangedAtOnce)
|
||||
@@ -547,6 +691,12 @@ bool RoomTransition::is_active()
|
||||
return mode != TRANSITION_NONE;
|
||||
}
|
||||
|
||||
// 006f0070 Whether a transition shows a boss's versus screen.
|
||||
bool RoomTransition::is_versus_screen()
|
||||
{
|
||||
return mode != TRANSITION_NONE && bossIntroBossId != 0;
|
||||
}
|
||||
|
||||
// 0082eb90 Whether the players teleport out: a teleport, a womb teleport, the Glowing Hourglass or the D7.
|
||||
bool RoomTransition::is_teleport()
|
||||
{
|
||||
|
||||
@@ -20,7 +20,7 @@ enum RoomTransitionMode : int
|
||||
};
|
||||
|
||||
// How the players leave the room (Lua's RoomTransitionAnim). The extra lives play their item's pickup animation once
|
||||
// in the new room, and ARENA enters the versus mode's arena.
|
||||
// in the new room, ARENA enters the versus mode's arena and TRAPDOOR is a trap door's way into a secret exit.
|
||||
enum RoomTransitionAnim : int
|
||||
{
|
||||
TRANSITION_WALK,
|
||||
@@ -44,16 +44,17 @@ enum RoomTransitionAnim : int
|
||||
TRANSITION_FADE_MIRROR,
|
||||
TRANSITION_MINECART,
|
||||
TRANSITION_DEATH_CERTIFICATE,
|
||||
TRANSITION_ARENA
|
||||
TRANSITION_ARENA,
|
||||
TRANSITION_TRAPDOOR
|
||||
};
|
||||
|
||||
// What Game::StartRoomTransition asks for: the room and dimension (negative for the current one), the door side left
|
||||
// through (DIRECTION_NONE for none), the animation and the player who started it.
|
||||
// through (none by default), the animation and the player who started it.
|
||||
struct RoomTransitionRequest
|
||||
{
|
||||
Entity_Player* player = nullptr;
|
||||
RoomTransitionAnim animation = TRANSITION_WALK;
|
||||
Direction direction{};
|
||||
Direction direction = static_cast<Direction>(-1);
|
||||
int dimension = -1;
|
||||
int roomIndex = 0;
|
||||
};
|
||||
@@ -91,6 +92,7 @@ public:
|
||||
void Render();
|
||||
|
||||
bool is_active();
|
||||
bool is_versus_screen();
|
||||
bool is_teleport();
|
||||
bool is_fade();
|
||||
float get_hud_alpha();
|
||||
@@ -99,6 +101,9 @@ public:
|
||||
private:
|
||||
void start_update(Entity_NPC* minecartNpc);
|
||||
void old_room_capture();
|
||||
void room_capture(KAGE::Graphics::ImagePtr& surface);
|
||||
void slide_offset_set(Vector distance, Vector oldScroll);
|
||||
void arrival_place();
|
||||
void versus_screen_update();
|
||||
void arrival_update();
|
||||
void landing_update();
|
||||
|
||||
+79
-13
@@ -36,6 +36,15 @@ constexpr float DOOR_PUSH_SPEED_SQUARED = 4;
|
||||
constexpr float DOOR_PUSH_FRAMES = 2;
|
||||
constexpr int DOOR_SLOT_SIDES = 4;
|
||||
constexpr float DUNGEON_EXIT_MARGIN = 20;
|
||||
constexpr float DUNGEON_LADDER_Y = 110;
|
||||
constexpr float DUNGEON_LADDER_LEFT = 100;
|
||||
constexpr float DUNGEON_LADDER_RIGHT = 140;
|
||||
constexpr uint32_t DUNGEON_BLACK_MARKET_DOOR = 1u << DIRECTION_RIGHT;
|
||||
constexpr int ROOM_PASSAGE_IDX = -14;
|
||||
constexpr int ROOM_PASSAGE_EXIT_IDX = -15;
|
||||
constexpr int ROOM_INDEX_OTHER_DIMENSION = -100;
|
||||
constexpr uint64_t GAME_STATE_ANGEL_ROOM_SPAWNED = 1ull << 0;
|
||||
constexpr uint64_t GAME_STATE_DEVIL_ROOM_SPAWNED = 1ull << 5;
|
||||
|
||||
// The weather a stage rains down: the drops' chances, and the Downpour's lightning flash and thunder.
|
||||
constexpr float WEATHER_DROP_Y = -10;
|
||||
@@ -365,7 +374,10 @@ static void clear_update(Room& room)
|
||||
}
|
||||
if (isDungeon && dungeonKind == DUNGEON_ROTGUT) return;
|
||||
if (isDungeon && dungeonKind == DUNGEON_ROTGUT_HEART)
|
||||
reconstruction_missing("Room::Update 00802980: Game::StartRoomTransition 006fd7c0 out of Rotgut's heart");
|
||||
{
|
||||
game.enterDoor = DOOR_NONE;
|
||||
game.StartRoomTransition({.roomIndex = game.dungeonReturnRoomIndex});
|
||||
}
|
||||
|
||||
bool isBackwards = game.stage >= 1 && game.stage <= 6 && game.GetStateFlag(GAME_STATE_BACKWARDS_PATH);
|
||||
if (game.stage != STAGE_HOME && !isBackwards) g_manager->musicManager.DisableLayer(0);
|
||||
@@ -407,10 +419,73 @@ static void pressure_plates_update(Room& room)
|
||||
reconstruction_missing("Room::update_pressure_plates 008024f0: the fireplaces' morph");
|
||||
}
|
||||
|
||||
// Leaves through a door slot: the rewind state is saved and the door left recorded, a devil or angel room is made the
|
||||
// first time its door is used, and a door to another dimension's room (below -99) goes there, by a mirror's fade for
|
||||
// the other world's twin.
|
||||
static void door_leave(Room& room, Entity_Player& player, int slot)
|
||||
{
|
||||
Game& game = *g_game;
|
||||
GridEntity_Door& door = *room.doors[slot];
|
||||
RoomTransitionRequest request = {.player = &player, .direction = (Direction)(slot % DOOR_SLOT_SIDES)};
|
||||
|
||||
game.save_rewind_state(slot);
|
||||
game.leaveDoor = slot;
|
||||
if (door.targetRoomIdx == ROOM_DEVIL_IDX && !game.GetRoomByIdx(ROOM_DEVIL_IDX)->data)
|
||||
{
|
||||
bool isAngel = door.targetRoomType == ROOM_ANGEL;
|
||||
game.InitializeDevilAngelRoom(isAngel, !isAngel);
|
||||
game.gameStateFlags |= isAngel ? GAME_STATE_ANGEL_ROOM_SPAWNED : GAME_STATE_DEVIL_ROOM_SPAWNED;
|
||||
}
|
||||
request.roomIndex = door.targetRoomIdx;
|
||||
if (request.roomIndex <= ROOM_INDEX_OTHER_DIMENSION)
|
||||
{
|
||||
RoomDescriptor& target = *game.GetRoomByIdx(request.roomIndex);
|
||||
if (door.targetRoomIdx == ROOM_INDEX_OTHER_DIMENSION) request.animation = TRANSITION_FADE_MIRROR;
|
||||
request.dimension = target.dimension;
|
||||
request.roomIndex = target.gridIndex;
|
||||
}
|
||||
game.StartRoomTransition(request);
|
||||
game.isPocketItemRewindSaved = false;
|
||||
}
|
||||
|
||||
// A crawlspace's exits: up its ladder back to the room it was entered from by a pixelation, or walking out past its
|
||||
// right edge (to the error room, the black market from a crawlspace with one, or on from the passage room), its left
|
||||
// edge or its bottom (to the error room). Returns whether the player left.
|
||||
static bool dungeon_exit(Room& room, Entity_Player& player)
|
||||
{
|
||||
Game& game = *g_game;
|
||||
Vector position = player.pos;
|
||||
bool isUp = position.y < GRID_ORIGIN_Y || (position.y < DUNGEON_LADDER_Y && position.x > DUNGEON_LADDER_LEFT &&
|
||||
position.x < DUNGEON_LADDER_RIGHT);
|
||||
RoomTransitionRequest request = {.player = &player, .roomIndex = ROOM_ERROR_IDX};
|
||||
|
||||
if (isUp)
|
||||
{
|
||||
request.animation = TRANSITION_PIXELATION;
|
||||
request.direction = (Direction)game.enterDoor;
|
||||
request.roomIndex = game.dungeonReturnRoomIndex;
|
||||
game.StartRoomTransition(request);
|
||||
return true;
|
||||
}
|
||||
if (room.bottomRightPos.x + DUNGEON_EXIT_MARGIN < position.x)
|
||||
{
|
||||
bool isBlackMarket = room.descriptor->data->doors & DUNGEON_BLACK_MARKET_DOOR;
|
||||
request.direction = DIRECTION_RIGHT;
|
||||
if (room.descriptor->gridIndex == ROOM_PASSAGE_IDX) request.roomIndex = ROOM_PASSAGE_EXIT_IDX;
|
||||
else if (isBlackMarket) request.roomIndex = ROOM_BLACK_MARKET_IDX;
|
||||
}
|
||||
else if (position.x < 0) request.direction = DIRECTION_LEFT;
|
||||
else if (room.bottomRightPos.y + DUNGEON_EXIT_MARGIN < position.y) request.direction = DIRECTION_DOWN;
|
||||
else return false;
|
||||
|
||||
game.leaveDoor = request.direction;
|
||||
game.StartRoomTransition(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 007f01c0 Takes the players through the doors: a player standing at an open door's edge (a mirror door's closed
|
||||
// edge) leaves through it, and one pushing into a locked door of a cleared room tries to unlock it. Tainted Forgotten
|
||||
// pushes by its speed. A crawlspace's exits lead back up or out to its neighbours.
|
||||
// Leaving a room (Game::save_rewind_state, Game::StartRoomTransition) is not reconstructed yet.
|
||||
static void door_transitions_update(Room& room)
|
||||
{
|
||||
Game& game = *g_game;
|
||||
@@ -449,20 +524,11 @@ static void door_transitions_update(Room& room)
|
||||
|
||||
bool isOpen = door->state == DOOR_STATE_OPEN;
|
||||
bool isPassable = door->doorFlags & DOOR_FLAG_MIRROR ? !isOpen : isOpen;
|
||||
if (isPassable && distance < DOOR_ENTER_DISTANCE)
|
||||
reconstruction_missing("Room::update_door_transitions 007f01c0: leaving through a door "
|
||||
"(Game::StartRoomTransition 006fd7c0)");
|
||||
if (isPassable && distance < DOOR_ENTER_DISTANCE) return door_leave(room, player, slot);
|
||||
if (isLockedKind && room.IsClear() && distance < DOOR_UNLOCK_DISTANCE && direction == side)
|
||||
door->TryUnlock(player, false);
|
||||
}
|
||||
if (room.roomType != ROOM_DUNGEON) continue;
|
||||
|
||||
bool isUp = position.y < GRID_ORIGIN_Y;
|
||||
bool isOut = room.bottomRightPos.x + DUNGEON_EXIT_MARGIN < position.x || position.x < 0 ||
|
||||
room.bottomRightPos.y + DUNGEON_EXIT_MARGIN < position.y;
|
||||
if (isUp || isOut)
|
||||
reconstruction_missing("Room::update_door_transitions 007f01c0: a crawlspace's exits "
|
||||
"(Game::StartRoomTransition 006fd7c0)");
|
||||
if (room.roomType == ROOM_DUNGEON && dungeon_exit(room, player)) return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user