#include "entity_slot.h" #include "entity_config.h" #include "entity_pickup.h" #include "game.h" #include "log.h" #include "manager.h" #include "room.h" #include // 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 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; constexpr int HELL_GAME_PRIZE_LAYER = 7; constexpr int CRANE_GAME_PRIZE_LAYER = 2; // 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. // 0065d950 void Entity_Slot::Update() { reconstruction_missing("Entity_Slot::Update 0065d950"); } // 00664560 bool Entity_Slot::TakeDamage(float, uint64_t, const EntityRef&, int) { reconstruction_missing("Entity_Slot::TakeDamage 00664560"); } // 006627e0 bool Entity_Slot::HandleCollision(Entity*, bool) { reconstruction_missing("Entity_Slot::HandleCollision 006627e0"); } // 00663aa0 void Entity_Slot::spawn_break_drops() { reconstruction_missing("Entity_Slot::spawn_break_drops 00663aa0"); } // 00665500 Sets the collectible a slot pays out, shown on the Hell Game's prize layer or the Crane Game's glass (a // question mark under Curse of the Blind). void Entity_Slot::SetPrizeType(int collectibleId) { prizeCollectible = collectibleId; bool isBlind = g_game->GetCurses() & CURSE_OF_BLIND; if (variant == SLOT_HELL_GAME) { Entity_Pickup::load_collectible_gfx(prizeAnm2, HELL_GAME_PRIZE_LAYER, prizeCollectible, dropRNG._seed, isBlind); prizeAnm2.LoadGraphics(); } else if (variant == SLOT_CRANE_GAME) { Entity_Pickup::load_collectible_gfx(sprite, CRANE_GAME_PRIZE_LAYER, prizeCollectible, dropRNG._seed, isBlind); sprite.LoadGraphics(); } }