Curation round 6: boot finished, the run starts; HUD, pause screen, minimap, preloads, floor generation
Six agents took over OnlineEmotes (emote wheel), OnlineStatsScreen's deeds, VictoryRunPrompt, RevivePlayerMenu, HUD, PauseScreen, Minimap, PreloadManager, ProceduralItemManager, Game::LoadBossRushXml, GameState's loading, the menu loose ends, Manager::StartNewGame, LevelGenerator and Level (Game now derives from Level). Integration: completion_widget.h breaks an include loop, call sites moved to the new APIs. --mute (main.cpp) keeps the mixer running at zero gain. build/isaac reaches the main menu by itself (input skips the intro); under gdb, picking a character calls StartNewGame and stops at Game::Start. 1611 functions taken over, boot path 287/615. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fed6918a10
commit
addd027977
94 files changed
+7453
-43389
No files matched your search
+1
-3
@@ -1186,15 +1186,13 @@ static void procedural_item_turn(SourceQuad& source, const AnimationFrame& frame
|
||||
const ANM2& animation)
|
||||
{
|
||||
RNG rng;
|
||||
void* renderTarget = nullptr;
|
||||
Vector center = vector_make(frame.width * HALF + frame.crop.x, frame.height * HALF + frame.crop.y);
|
||||
|
||||
rng._seed = (uint32_t)(uintptr_t)&animation;
|
||||
rng._shift1 = PROCEDURAL_SHIFTS[0];
|
||||
rng._shift2 = PROCEDURAL_SHIFTS[1];
|
||||
rng._shift3 = PROCEDURAL_SHIFTS[2];
|
||||
std::memcpy(&renderTarget, g_game->proceduralItemManager._renderTarget, sizeof(renderTarget));
|
||||
if (layer.spriteSheet.get() == renderTarget)
|
||||
if (layer.spriteSheet == g_game->proceduralItemManager.renderTarget)
|
||||
center = vector_make(center.x + layer.cropOffset.x, center.y + layer.cropOffset.y);
|
||||
|
||||
quad_rotate(source, center, (rng.RandomInt(2) == 0 ? GLITCH_TURN : -GLITCH_TURN) * RADIANS_PER_DEGREE);
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include "anm2.h"
|
||||
|
||||
// Whether the completion widget sits on the menus' paper or the pause screen's.
|
||||
enum CompletionStyle
|
||||
{
|
||||
COMPLETION_STYLE_MENU,
|
||||
COMPLETION_STYLE_PAUSE
|
||||
};
|
||||
|
||||
// A character's completion marks (CompletionWidget): the widget's sheet with a layer per mark, each on the frame of the
|
||||
// difficulty it was earned on, and how many are earned.
|
||||
struct CompletionWidget
|
||||
{
|
||||
ANM2 anm2;
|
||||
int characterId = 0;
|
||||
int markCount = 0;
|
||||
|
||||
void Load(CompletionStyle style);
|
||||
void Update();
|
||||
void Render(Vector position, Vector scale);
|
||||
};
|
||||
+1
-3
@@ -62,7 +62,6 @@ constexpr int STAGE_TYPE_COUNT = 5;
|
||||
constexpr uint32_t CURSE_DARKNESS = 1;
|
||||
constexpr uint32_t CHALLENGE_DELETE_THIS = 45;
|
||||
constexpr int SECRET_EXIT_CORPSE = 4;
|
||||
constexpr int ROOM_SECRET_EXIT_IDX = -10;
|
||||
constexpr uint32_t ROOM_DEFAULT = 1;
|
||||
constexpr uint32_t ROOM_BOSS = 5;
|
||||
constexpr int BACKDROP_PLANETARIUM = 35;
|
||||
@@ -750,8 +749,7 @@ static void rays_render(FXLayers& fx)
|
||||
void FXLayers::LoadConfig(std::string_view path, int levelStage, int levelStageType)
|
||||
{
|
||||
Room& room = *g_game->room;
|
||||
// Rebirth's Level is the front of Game, and Game declares none of its methods yet.
|
||||
Level& level = *reinterpret_cast<Level*>(g_game);
|
||||
Level& level = *g_game;
|
||||
|
||||
stage = levelStage;
|
||||
stageType = levelStageType;
|
||||
|
||||
+67
-14
@@ -3,6 +3,7 @@
|
||||
#include "log.h"
|
||||
#include "manager.h"
|
||||
#include "menu_manager.h"
|
||||
#include "victory_run_prompt.h"
|
||||
#include <optional>
|
||||
|
||||
constexpr const char* STAGES_XML = "stages.xml";
|
||||
@@ -12,6 +13,7 @@ constexpr const char* GIANTBOOK_XML = "giantbook.xml";
|
||||
constexpr const char* BOSS_OVERLAYS_XML = "bossoverlays.xml";
|
||||
constexpr const char* AMBUSH_XML = "ambush.xml";
|
||||
constexpr const char* PRELOAD_XML = "preload.xml";
|
||||
constexpr std::array<std::string_view, 4> PRELOAD_GROUPS = {"common", "enemy", "pickups", "icons"};
|
||||
constexpr const char* COMPLETION_WIDGET_ANM2 = "gfx/ui/completion_widget.anm2";
|
||||
constexpr const char* COMPLETION_WIDGET_ANIMATION = "Idle";
|
||||
constexpr const char* GIANTBOOK_CLICKER_PNG = "gfx/ui/giantbook/GiantBook_Clicker.png";
|
||||
@@ -134,23 +136,21 @@ void Game::LoadConfigXmls()
|
||||
// The original also zeroes GameOver's second int and the ints at Game+0x1d63c and Game+0x1d64c, not modeled yet.
|
||||
game.gameOver._state = 0;
|
||||
game.leaderboard.LoadAnm2();
|
||||
game.emotes.init();
|
||||
reconstruction_missing("OnlineStatsScreen's deeds widget 008ca2c0 (classes.h's CompletionWidget::Load) on Game's "
|
||||
"online stats screen: gfx/ui/DeedsMenu.anm2");
|
||||
reconstruction_missing("HUD's graphics reload 009a1970 on Game's HUD");
|
||||
game.emoteWheel.Init();
|
||||
game.onlineStatsScreen.Load();
|
||||
game.hud.graphics_reload();
|
||||
game.pauseScreen.Init();
|
||||
game.revivePlayerMenu.Init();
|
||||
game.minimap.Init();
|
||||
LoadBossRushXml(mods.TryRedirectPath(AMBUSH_XML));
|
||||
|
||||
std::string preloadPath = mods.TryRedirectPath(PRELOAD_XML);
|
||||
load_preloads_xml(&game.preloadManager, (uint8_t*)preloadPath.data());
|
||||
reconstruction_missing("PreloadManager::load_group 009c6c90 on Game's preloads: common, enemy, pickups, icons");
|
||||
init_procedural_item_surfaces(&game.proceduralItemManager);
|
||||
game.preloadManager.xml_load(mods.TryRedirectPath(PRELOAD_XML));
|
||||
for (std::string_view group : PRELOAD_GROUPS) game.preloadManager.group_load(group);
|
||||
game.proceduralItemManager.Init();
|
||||
game.bossRushParTime = BOSS_RUSH_PAR_TIME;
|
||||
game.blueWombParTime = BLUE_WOMB_PAR_TIME;
|
||||
game.genericPrompt.Initialize(PROMPT_LARGE);
|
||||
VictoryRunPrompt::Load();
|
||||
victory_run_prompt_load(game.genericPrompt);
|
||||
|
||||
game.completionWidgetSprite.Load(COMPLETION_WIDGET_ANM2, GRAPHICS_LOAD);
|
||||
game.completionWidgetSprite.SetFrame(COMPLETION_WIDGET_ANIMATION, 0);
|
||||
@@ -268,10 +268,63 @@ bool Game::load_bossoverlays_xml(std::string_view path)
|
||||
return true;
|
||||
}
|
||||
|
||||
// 00834680 Reads ambush.xml into the boss rush waves (its this is Ambush's wave list, which classes.h lost).
|
||||
void Game::LoadBossRushXml(std::string_view)
|
||||
// A boss a Boss Rush spawn slot holds: its type and variant, and the segments of a segmented boss.
|
||||
struct BossRushSpawn
|
||||
{
|
||||
reconstruction_missing("Game::LoadBossRushXml 00834680");
|
||||
int chunks = 1;
|
||||
int type = 0;
|
||||
int variant = 0;
|
||||
};
|
||||
|
||||
// ambush.xml's Boss Rush: the bosses of each spawn slot, how many waves it lasts and how many slots each wave draws.
|
||||
// The original keeps them in Ambush, which classes.h holds as bytes. They move there with its takeover.
|
||||
struct BossRushConfig
|
||||
{
|
||||
std::vector<std::vector<BossRushSpawn>> slots;
|
||||
int numWaves = 0;
|
||||
int spawnsPerWave = 0;
|
||||
};
|
||||
|
||||
static BossRushConfig bossRushConfig;
|
||||
|
||||
// 00834680 Reads ambush.xml's <bossrush> into the Boss Rush: its wave counts, then from its first <spawn> on, a slot
|
||||
// for each element, holding from its first <enemy> on each element's boss count times. A missing file changes nothing.
|
||||
// The original crashes on a file without <bossrush>. Here that leaves the Boss Rush empty.
|
||||
void Game::LoadBossRushXml(std::string_view path)
|
||||
{
|
||||
Data data;
|
||||
|
||||
data_load(data, path);
|
||||
if (!data.isLoaded) return;
|
||||
|
||||
bossRushConfig = {};
|
||||
std::optional<DataNode> root = root_find(data, "bossrush");
|
||||
if (!root) return;
|
||||
bossRushConfig.numWaves = std::atoi(node_attr(*root, "numWaves").data());
|
||||
bossRushConfig.spawnsPerWave = std::atoi(node_attr(*root, "spawnsPerWave").data());
|
||||
|
||||
bool isSlotStarted = false;
|
||||
for (DataNode slotNode : node_children(*root))
|
||||
{
|
||||
isSlotStarted = isSlotStarted || node_tag(slotNode) == "spawn";
|
||||
if (!isSlotStarted) continue;
|
||||
|
||||
std::vector<BossRushSpawn>& slot = bossRushConfig.slots.emplace_back();
|
||||
bool isEnemyStarted = false;
|
||||
for (DataNode enemyNode : node_children(slotNode))
|
||||
{
|
||||
isEnemyStarted = isEnemyStarted || node_tag(enemyNode) == "enemy";
|
||||
if (!isEnemyStarted) continue;
|
||||
|
||||
BossRushSpawn spawn;
|
||||
int count = 1;
|
||||
spawn.type = std::atoi(node_attr(enemyNode, "type").data());
|
||||
spawn.variant = std::atoi(node_attr(enemyNode, "variant").data());
|
||||
if (auto text = attr_find(enemyNode, "chunks")) spawn.chunks = std::atoi(text->data());
|
||||
if (auto text = attr_find(enemyNode, "count")) count = std::atoi(text->data());
|
||||
slot.insert(slot.end(), std::max(count, 0), spawn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 006f43b0 Clears the run back to a fresh one: counters, fades, debug flags, the daily, score sheet and screen effects.
|
||||
@@ -428,8 +481,8 @@ bool Game::IsPaused()
|
||||
if (console.state != CONSOLE_CLOSED && isOffline) return true;
|
||||
return freezeFrames > 0 || gameOver._state != 0 || leaderboard.displayState != LEADERBOARD_HIDDEN ||
|
||||
stageTransition._state != 0 || roomTransition._mode != 0 || itemOverlay._state == ITEM_OVERLAY_ACTIVE ||
|
||||
(pauseScreen._state != 0 && isOffline) || g_manager->state != MANAGER_STATE_GAME ||
|
||||
genericPrompt.IsActive() || onlineStatsScreen._isActive;
|
||||
(pauseScreen.is_pausing() && isOffline) || g_manager->state != MANAGER_STATE_GAME ||
|
||||
genericPrompt.IsActive() || onlineStatsScreen.isActive;
|
||||
}
|
||||
|
||||
// 006f8120 Whether the run plays Greed mode.
|
||||
|
||||
+19
-50
@@ -5,10 +5,19 @@
|
||||
#include "console.h"
|
||||
#include "deathmatch_manager.h"
|
||||
#include "generic_prompt.h"
|
||||
#include "hud.h"
|
||||
#include "item_pool.h"
|
||||
#include "kage_graphics.h"
|
||||
#include "leaderboard.h"
|
||||
#include "level.h"
|
||||
#include "minimap.h"
|
||||
#include "online_emotes.h"
|
||||
#include "online_stats_screen.h"
|
||||
#include "pause_screen.h"
|
||||
#include "player_manager.h"
|
||||
#include "preload_manager.h"
|
||||
#include "procedural_item_manager.h"
|
||||
#include "revive_player_menu.h"
|
||||
#include "room_config.h"
|
||||
#include "score_sheet.h"
|
||||
#include "seeds.h"
|
||||
@@ -19,10 +28,6 @@
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
constexpr int ROOM_GRID_SIZE = 507;
|
||||
constexpr int OFF_GRID_ROOM_COUNT = 20;
|
||||
constexpr int ROOM_LIST_SIZE = ROOM_GRID_SIZE + OFF_GRID_ROOM_COUNT;
|
||||
constexpr int GREED_WAVE_SLOTS = 12;
|
||||
constexpr int BACKWARDS_STAGE_COUNT = 7;
|
||||
constexpr int GLOWING_HOURGLASS_SLOTS = 2;
|
||||
constexpr int GIANTBOOK_ENTRY_COUNT = 48;
|
||||
@@ -132,66 +137,30 @@ struct ErasedEnemy
|
||||
int variant = 0;
|
||||
};
|
||||
|
||||
// The run (g_game): the floor and its rooms (the front of the class is Rebirth's Level), the configs and pools a run
|
||||
// The run (g_game): the floor and its rooms (Level, the front of the class), the configs and pools a run
|
||||
// draws from, the UI overlays and menus of a run, and the screen effects, counters and history of the run so far.
|
||||
// Members of classes not taken over yet keep their generated types and start zeroed.
|
||||
// The render surfaces were file globals of the original, created once by the first Game.
|
||||
// The giant book and boss overlay tables live in the item and boss overlays of the original, which classes.h holds as
|
||||
// bytes. They move there with those classes' takeovers.
|
||||
class Game
|
||||
class Game : public Level
|
||||
{
|
||||
public:
|
||||
std::array<RoomDescriptor, ROOM_LIST_SIZE> roomList{};
|
||||
std::array<int, ROOM_GRID_SIZE> roomMap{};
|
||||
std::array<uint32_t, GREED_WAVE_SLOTS> greedWaveSeeds{};
|
||||
std::array<BackwardsStageDesc, BACKWARDS_STAGE_COUNT> backwardsStages{};
|
||||
std::vector<EntitySaveState> myosotisPickups;
|
||||
std::unique_ptr<Room> room;
|
||||
int* currentRoomMap = nullptr;
|
||||
RNG devilAngelRoomRNG = RNG_DEFAULT;
|
||||
RNG generationRNG = RNG_DEFAULT;
|
||||
Vector dungeonReturnPosition{};
|
||||
Vector mamaMegaPosition{};
|
||||
float angelRoomChance = 0;
|
||||
int bombPickupsSpawned = 0;
|
||||
int currentDimensionIdx = 0;
|
||||
int currentRoomIdx = 0;
|
||||
int dungeonReturnRoomIndex = 0;
|
||||
int enterDoor = 0;
|
||||
int greedLastBeatenWave = 0;
|
||||
int greedLastPaidWave = 0;
|
||||
int greedModeWave = 0;
|
||||
int greedWavesClearedWithoutRedHeartDamage = 0;
|
||||
int lastBossRoomListIdx = 0;
|
||||
int lastRoomDimensionIdx = 0;
|
||||
int lastRoomIdx = 0;
|
||||
int leaveDoor = 0;
|
||||
int nbRooms = 0;
|
||||
int startingRoomIdx = 0;
|
||||
uint32_t curses = 0;
|
||||
uint32_t dungeonPlacementSeed = 0;
|
||||
uint32_t greedModeTreasureRoomIdx = 0;
|
||||
uint32_t levelStateFlags = 0;
|
||||
uint32_t stage = 0;
|
||||
uint32_t stageType = 0;
|
||||
bool isBossChallenge = false;
|
||||
bool isCanSeeEverything = false;
|
||||
bool isDevilRoomDisabled = false;
|
||||
bool isHeartPicked = false;
|
||||
bool isLevelGenerating = false;
|
||||
|
||||
RoomConfig roomConfig;
|
||||
ItemPool itemPool;
|
||||
Seeds seedEffects;
|
||||
Console console;
|
||||
std::unique_ptr<EntityFactory> entityFactory = std::make_unique<EntityFactory>();
|
||||
PreloadManager preloadManager{};
|
||||
PreloadManager preloadManager;
|
||||
BossPool bossPool{};
|
||||
PlayerManager playerManager{};
|
||||
Ambush ambush{};
|
||||
DeathmatchManager deathmatchManager{};
|
||||
DailyChallenge dailyChallenge{};
|
||||
ProceduralItemManager proceduralItemManager{};
|
||||
ProceduralItemManager proceduralItemManager;
|
||||
std::array<GlowingHourglassState, GLOWING_HOURGLASS_SLOTS> glowingHourglassStates{};
|
||||
std_vector onlinePlayerStats{};
|
||||
std::array<CoopAward, COOP_AWARD_COUNT> coopAwards;
|
||||
@@ -207,15 +176,15 @@ public:
|
||||
std::array<BossOverlayEntry, BOSS_OVERLAY_COUNT> bossOverlayEntries;
|
||||
GameOver gameOver{};
|
||||
Leaderboard leaderboard{};
|
||||
HUD hud{};
|
||||
PauseScreen pauseScreen{};
|
||||
RevivePlayerMenu revivePlayerMenu{};
|
||||
OnlineStatsScreen onlineStatsScreen{};
|
||||
Minimap minimap{};
|
||||
HUD hud;
|
||||
PauseScreen pauseScreen;
|
||||
RevivePlayerMenu revivePlayerMenu;
|
||||
OnlineStatsScreen onlineStatsScreen;
|
||||
Minimap minimap;
|
||||
ScoreSheet scoreSheet;
|
||||
GenericPrompt genericPrompt{};
|
||||
DebugRenderer debugRenderer{};
|
||||
OnlineEmotes emotes{};
|
||||
EmoteWheel emoteWheel;
|
||||
ANM2 completionWidgetSprite;
|
||||
|
||||
KAGE::Graphics::ImagePtr giantBookClickerImage;
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
#include "game_state.h"
|
||||
#include "log.h"
|
||||
#include "platform.h"
|
||||
#include <cstdio>
|
||||
|
||||
// 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)};
|
||||
}
|
||||
|
||||
// 009c8350 Removes the saved run's file, warning when there is none named, and empties the run.
|
||||
void GameState::Delete()
|
||||
{
|
||||
if (savePath.empty()) log_printf(LOG_INFO, "[warn] GameState::Delete: no filename specified.\n");
|
||||
std::remove(savePath.c_str());
|
||||
Clear();
|
||||
}
|
||||
|
||||
// 009c8410 Removes the rerun's file, keeping the run.
|
||||
// The original warns on an empty save file name here too, not on the rerun's.
|
||||
void GameState::DeleteRerun()
|
||||
{
|
||||
if (savePath.empty()) log_printf(LOG_INFO, "[warn] GameState::DeleteRerun: no filename specified.\n");
|
||||
std::remove(rerunPath.c_str());
|
||||
}
|
||||
|
||||
// Not reconstructed yet: each stops the game where it is reached.
|
||||
// Netplay is offline, so read always reads a run as this machine's own (the original's isLocalRun).
|
||||
bool GameState::read(std::span<const uint8_t>) { reconstruction_missing("GameState::read 009cc1a0"); }
|
||||
bool GameState::read_rerun(std::span<const uint8_t>) { reconstruction_missing("GameState::read_rerun 009d7d50"); }
|
||||
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include "seeds.h"
|
||||
#include <cstdint>
|
||||
#include <span>
|
||||
#include <string>
|
||||
|
||||
// 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.
|
||||
// Only what the menus and the run start read is modelled so far: the rooms, players, item pools and the rest of the
|
||||
// original's 0x1fe28 bytes come with read and write.
|
||||
// Construction and destruction (009c73c0, 009c7800) are the defaults.
|
||||
// Steam Cloud is offline, so the cloud file names are dropped.
|
||||
struct GameState
|
||||
{
|
||||
Seeds seeds{};
|
||||
std::string rerunPath;
|
||||
std::string savePath;
|
||||
int challenge = 0;
|
||||
int difficulty = 0;
|
||||
int playerType = 0;
|
||||
bool isModded = false;
|
||||
bool isRerunAvailable = false;
|
||||
bool isSaveAvailable = false;
|
||||
|
||||
void Clear();
|
||||
void Delete();
|
||||
void DeleteRerun();
|
||||
bool read(std::span<const uint8_t> file);
|
||||
bool read_rerun(std::span<const uint8_t> file);
|
||||
};
|
||||
+1677
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,353 @@
|
||||
#pragma once
|
||||
|
||||
#include "anm2.h"
|
||||
#include "font.h"
|
||||
#include "fx_layers.h"
|
||||
#include "kage_graphics.h"
|
||||
#include "rich_text.h"
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
constexpr int PLAYER_HUD_COUNT = 8;
|
||||
constexpr int MAIN_PLAYER_HUD_COUNT = 4;
|
||||
constexpr int PLAYER_HUD_HEART_COUNT = 24;
|
||||
constexpr int PLAYER_HUD_ACTIVE_COUNT = 4;
|
||||
constexpr int PLAYER_HUD_TRINKET_COUNT = 2;
|
||||
constexpr int PLAYER_HUD_POCKET_COUNT = 4;
|
||||
constexpr int MESSAGE_STACK_COUNT = 6;
|
||||
constexpr int HISTORY_PLAYER_COUNT = 2;
|
||||
constexpr int STAT_PLAYER_COUNT = 2;
|
||||
constexpr int STAT_TRACKER_COUNT = 10;
|
||||
constexpr int STAT_TRACKER_FINE_COUNT = 6;
|
||||
constexpr float STAT_THRESHOLD_FINE = 0.01f;
|
||||
constexpr float STAT_THRESHOLD_COARSE = 0.1f;
|
||||
constexpr float BOSS_BAR_HIDDEN = -1;
|
||||
constexpr int FLASH_OFF = -1;
|
||||
constexpr int ONLINE_HUD_OFFLINE = 3;
|
||||
constexpr float PLAYER_HUD_BOUNDS_FAR = 1e7f;
|
||||
|
||||
// REPENTOGON's HUD layouts of a player, and the spot an online player's status takes.
|
||||
enum PlayerHudLayout : int
|
||||
{
|
||||
HUD_LAYOUT_NORMAL,
|
||||
HUD_LAYOUT_JACOB_ESAU,
|
||||
HUD_LAYOUT_COMPACT,
|
||||
HUD_LAYOUT_JACOB_ESAU_COMPACT,
|
||||
HUD_LAYOUT_NET_STATUS
|
||||
};
|
||||
|
||||
// How much of the HUD a refresh request redraws. A full request is never downgraded by a lighter one.
|
||||
enum HudRefresh : int
|
||||
{
|
||||
HUD_REFRESH_NONE,
|
||||
HUD_REFRESH_PLAYER,
|
||||
HUD_REFRESH_FULL
|
||||
};
|
||||
|
||||
// Whether mark_all_slots_dirty has the recent items HUD rebuild its icons.
|
||||
enum HistoryRebuild
|
||||
{
|
||||
HISTORY_KEEP_ICONS,
|
||||
HISTORY_REBUILD_ICONS
|
||||
};
|
||||
|
||||
// Whether mark_all_slots_dirty empties the recent items HUD first.
|
||||
enum HistoryClear
|
||||
{
|
||||
HISTORY_KEEP_ITEMS,
|
||||
HISTORY_CLEAR_ITEMS
|
||||
};
|
||||
|
||||
// Construction (008405b0) and destruction (00840670) are the defaults.
|
||||
// A banner the HUD shows (stage names, item names, pill names): a streak animation with a title and subtitle drawn into
|
||||
// a text surface the streak's null 0 places. A text starting with character 1 is rich text drawn with icons.
|
||||
struct HUD_Message
|
||||
{
|
||||
ANM2 streakSprite;
|
||||
Font font;
|
||||
Font fontKR;
|
||||
KColor streakColor = kcolor_rgba(0, 0, 0, 1);
|
||||
KColor textColor = kcolor_rgba(1, 1, 1, 1);
|
||||
KAGE::Graphics::ImagePtr textImage;
|
||||
std::u16string text;
|
||||
std::u16string subtext;
|
||||
Vector position{};
|
||||
float scale = 1;
|
||||
bool isAutoHide = true;
|
||||
bool isCurseDisplay = false;
|
||||
bool isShowing = false;
|
||||
|
||||
void load_graphics();
|
||||
void free_text_buffers();
|
||||
void set_text_line(std::u16string_view line, int lineIndex);
|
||||
void Show(const char* title, const char* subtitle, bool isAutoHideOn, bool isCurse);
|
||||
void text_out();
|
||||
void Update();
|
||||
void UpdateTextImage();
|
||||
void Render(Vector at, float atScale);
|
||||
static void render_text_image(Font& textFont, std::u16string_view line, Vector at, KColor textColor);
|
||||
};
|
||||
|
||||
// REPENTOGON's PlayerHUDHeart: the animations a heart slot shows and how.
|
||||
struct PlayerHUDHeart
|
||||
{
|
||||
const char* spriteAnim = "";
|
||||
const char* spriteOverlayAnim = "";
|
||||
int8_t flashType = 0;
|
||||
bool isEternalHeartVisible = false;
|
||||
bool isFadeHeart = false;
|
||||
bool isGoldenHeartVisible = false;
|
||||
bool isVisible = false;
|
||||
};
|
||||
|
||||
// REPENTOGON's PlayerHUDActiveItem: the item an active slot shows, its book overlay and its charge bar flash.
|
||||
struct PlayerHUDActiveItem
|
||||
{
|
||||
KAGE::Graphics::ImagePtr bookImage;
|
||||
KAGE::Graphics::ImagePtr itemImage;
|
||||
int bookItemId = 0;
|
||||
int chargeBarFlash = 0;
|
||||
int id = 0;
|
||||
};
|
||||
|
||||
// REPENTOGON's PlayerHUDTrinket: the trinket a slot shows.
|
||||
struct PlayerHUDTrinket
|
||||
{
|
||||
KAGE::Graphics::ImagePtr image;
|
||||
int id = 0;
|
||||
int slot = 0;
|
||||
};
|
||||
|
||||
// A card, pill or pocket active slot: its sprite and what it shows.
|
||||
struct PlayerHUDPocketItem
|
||||
{
|
||||
ANM2 sprite;
|
||||
int id = 0;
|
||||
int kind = 0;
|
||||
};
|
||||
|
||||
// A crafting bag pickup icon.
|
||||
struct PlayerHUDIcon
|
||||
{
|
||||
KAGE::Graphics::ImagePtr image;
|
||||
int id = 0;
|
||||
};
|
||||
|
||||
// Construction (006efc70) and destruction (006efde0) are the defaults.
|
||||
// One player's corner of the HUD (REPENTOGON's PlayerHUD): hearts, actives, trinkets, pockets and the crafting bag, and
|
||||
// the box the drawn parts covered this frame.
|
||||
struct PlayerHUD
|
||||
{
|
||||
std::array<PlayerHUDHeart, PLAYER_HUD_HEART_COUNT> hearts{};
|
||||
std::array<PlayerHUDActiveItem, PLAYER_HUD_ACTIVE_COUNT> activeItems{};
|
||||
std::array<PlayerHUDTrinket, PLAYER_HUD_TRINKET_COUNT> trinkets{};
|
||||
std::array<PlayerHUDPocketItem, PLAYER_HUD_POCKET_COUNT> pocketItems{};
|
||||
std::vector<PlayerHUDIcon> craftingIcons;
|
||||
KAGE::Graphics::ImagePtr craftingBagImage;
|
||||
KAGE::Graphics::ImagePtr craftingResultImage;
|
||||
KAGE::Graphics::ImagePtr deathmatchHealthBarImage;
|
||||
Vector boundsMax = vector_make(-PLAYER_HUD_BOUNDS_FAR, -PLAYER_HUD_BOUNDS_FAR);
|
||||
Vector boundsMin = vector_make(PLAYER_HUD_BOUNDS_FAR, PLAYER_HUD_BOUNDS_FAR);
|
||||
Entity_Player* player = nullptr;
|
||||
HUD* hud = nullptr;
|
||||
float dropHoldFade = 0;
|
||||
int16_t lastHeartFlash = 0;
|
||||
int16_t playerHudIndex = 0;
|
||||
int8_t goldHeartFlashCountdown = 0;
|
||||
int8_t redHeartFlashCountdown = 0;
|
||||
int8_t soulHeartFlashCountdown = 0;
|
||||
bool isCraftingItemDirty = false;
|
||||
bool isDirty = false;
|
||||
|
||||
void reset();
|
||||
void bounds_reset();
|
||||
void Update();
|
||||
void UpdateHearts(PlayerHUDHeart& heart, int heartIndex);
|
||||
void set_active_charge_frame(int collectibleId);
|
||||
void RenderHearts(Vector& outExtent, ANM2& sprite, PlayerHudLayout layout, float heartScale, Vector at);
|
||||
void RenderActiveItem(int activeSlot, Vector at, PlayerHudLayout layout, float itemScale, float alpha);
|
||||
void RenderTrinket(int trinketSlot, Vector at, float trinketScale, bool isSmall);
|
||||
void RenderPocketItems(Vector at, PlayerHudLayout layout, float alpha, float pocketScale);
|
||||
void render_inventory(Vector at, float inventoryScale);
|
||||
void RenderCraftingTable(Vector at, float tableScale);
|
||||
void RenderSpellQueue(Vector at, float queueScale);
|
||||
Vector render_deathmatch_health_bar(Vector at);
|
||||
static std::shared_ptr<PlayerHUD> make_ref(HUD* owner, Entity_Player* shown);
|
||||
};
|
||||
|
||||
// A stat the stats HUD shows: its value, the value before its last change, the change shown and for how long, and the
|
||||
// smallest change worth showing.
|
||||
struct StatTracker
|
||||
{
|
||||
float change = 0;
|
||||
float previous = 0;
|
||||
float threshold = STAT_THRESHOLD_FINE;
|
||||
float value = 0;
|
||||
int changeTimer = 0;
|
||||
|
||||
void set(float newValue, bool isAnimated);
|
||||
};
|
||||
|
||||
// The stats one player shows.
|
||||
struct StatHUDPlayer
|
||||
{
|
||||
std::array<StatTracker, STAT_TRACKER_COUNT> stats{};
|
||||
Entity_Player* player = nullptr;
|
||||
};
|
||||
|
||||
// The stats HUD (REPENTOGON's StatHUD) under the pickups: speed, tears, damage, range, shot speed, luck and the room
|
||||
// chances, for up to two players.
|
||||
struct StatHUD
|
||||
{
|
||||
ANM2 sprite;
|
||||
std::array<StatHUDPlayer, STAT_PLAYER_COUNT> players{};
|
||||
bool isDualityOwned = false;
|
||||
|
||||
void reset();
|
||||
void Update();
|
||||
void Render(Vector at);
|
||||
void RecomputeStats(int playerId, uint32_t flags, bool isAnimated);
|
||||
void update_player(Entity_Player* oldPlayer, Entity_Player* newPlayer);
|
||||
};
|
||||
|
||||
// An item of the recent items list, with its icon.
|
||||
struct HistoryHUDItem
|
||||
{
|
||||
KAGE::Graphics::ImagePtr image;
|
||||
int id = 0;
|
||||
};
|
||||
|
||||
// The recent items of one player and whether they need recomputing.
|
||||
struct HistoryHUDPlayer
|
||||
{
|
||||
std::vector<HistoryHUDItem> items;
|
||||
Entity_Player* player = nullptr;
|
||||
bool isDirty = false;
|
||||
};
|
||||
|
||||
// The recent items HUD (REPENTOGON's HistoryHUD) under the minimap, for up to two players.
|
||||
struct HistoryHUD
|
||||
{
|
||||
std::array<HistoryHUDPlayer, HISTORY_PLAYER_COUNT> players{};
|
||||
bool isComputed = false;
|
||||
|
||||
void clear();
|
||||
void Render(Vector at, bool isMini);
|
||||
void Recompute(int playerIndex, bool isImmediate);
|
||||
void RecomputeAll(bool isImmediate);
|
||||
};
|
||||
|
||||
// The panel describing the item the player stands next to: its charge icon, map icons and rich text.
|
||||
struct ItemInfoHUD
|
||||
{
|
||||
ANM2 iconSprite;
|
||||
ANM2 chargeIconSprite;
|
||||
ANM2 mapIconsSprite;
|
||||
RichText text;
|
||||
KAGE::Graphics::ImagePtr itemImage;
|
||||
float iconScale = 0;
|
||||
int pickupIndex = -1;
|
||||
|
||||
void load_graphics();
|
||||
void Update();
|
||||
};
|
||||
|
||||
// The online HUD style option in effect, ONLINE_HUD_OFFLINE offline.
|
||||
int online_hud_mode();
|
||||
|
||||
// Construction and destruction (006f2060, 006f23d0) are the defaults.
|
||||
// The heads-up display of a run (g_game->hud): the player corners, the pickup counters and run icons, the stats,
|
||||
// recent items and item info panels, the banners, the fortune paper, the co-op join carousel and the boss bar.
|
||||
class HUD
|
||||
{
|
||||
public:
|
||||
std::array<PlayerHUD, PLAYER_HUD_COUNT> playerHUD{};
|
||||
std::array<HUD_Message, MESSAGE_STACK_COUNT> messageStack{};
|
||||
std::array<HUD_Message, MAIN_PLAYER_HUD_COUNT> messagePlayerHUD{};
|
||||
std::array<Vector, MAIN_PLAYER_HUD_COUNT> cornerOffsets{};
|
||||
std::array<Vector, PLAYER_HUD_COUNT> playerHudPositions{};
|
||||
HUD_Message messageMain;
|
||||
Font font;
|
||||
Font fontKR;
|
||||
ANM2 cardsPillsSprite;
|
||||
ANM2 chargeBarSmallSprite;
|
||||
ANM2 chargeBarSprite;
|
||||
ANM2 coopMenuSprite;
|
||||
ANM2 craftingTableSprite;
|
||||
ANM2 fortuneSprite;
|
||||
ANM2 heartsSprite;
|
||||
ANM2 inventorySprite;
|
||||
ANM2 pickupHUDSprite;
|
||||
ANM2 poopSpellsSprite;
|
||||
ANM2 statsSprite;
|
||||
StatHUD statHUD;
|
||||
HistoryHUD historyHUD;
|
||||
ItemInfoHUD itemInfoHUD;
|
||||
KAGE::Graphics::ImagePtr bossHealthBarImage;
|
||||
KAGE::Graphics::ImagePtr bossHealthBarMiniImage;
|
||||
KAGE::Graphics::ImagePtr bossHealthBarRushImage;
|
||||
KAGE::Graphics::ImagePtr bossHealthBarStaticImage;
|
||||
KAGE::Graphics::ImagePtr bossHealthBarStoneImage;
|
||||
KAGE::Graphics::ImagePtr coopMenuImage;
|
||||
KAGE::Graphics::ImagePtr fortuneTextImage;
|
||||
KAGE::Graphics::ImagePtr spiderModHealthBarImage;
|
||||
float bossBarOffset = 0;
|
||||
float bossHPBarFill = BOSS_BAR_HIDDEN;
|
||||
float hudScale = 0;
|
||||
float minimapOffset = 0;
|
||||
float statsOffset = 0;
|
||||
int bossHPBarDamageFlash = FLASH_OFF;
|
||||
int bossHPBarHealFlash = FLASH_OFF;
|
||||
int hudRefreshCountdown = 2;
|
||||
HudRefresh hudRefreshType = HUD_REFRESH_FULL;
|
||||
int16_t bossCounter = 0;
|
||||
int16_t bossCounterTotal = 0;
|
||||
bool isBossBarBottom = false;
|
||||
bool isGraphicsLoaded = false;
|
||||
bool isRefreshTick = false;
|
||||
bool isVisible = true;
|
||||
|
||||
void graphics_reload();
|
||||
void reset();
|
||||
void LoadGraphics();
|
||||
void unload_graphics();
|
||||
|
||||
void Update();
|
||||
void PostUpdate();
|
||||
void refresh_request(HudRefresh type);
|
||||
void FlashChargeBar(Entity_Player* player, int activeSlot);
|
||||
void InvalidateActiveItem(Entity_Player* player, int activeSlot);
|
||||
void InvalidateCraftingItem(Entity_Player* player);
|
||||
void mark_all_slots_dirty(HistoryRebuild rebuild, HistoryClear clearing);
|
||||
void SetVisible(bool isShown);
|
||||
bool IsVisible();
|
||||
|
||||
void ShowItemText(Entity_Player* player, ItemConfig_Item* item);
|
||||
static int lua_show_item_text(void* luaState);
|
||||
void show_pill_name(Entity_Player* player, const char* title, const char* subtitle);
|
||||
void ShowFortuneText(const std::vector<std::string>& lines);
|
||||
void show_fortune_line(const char* text);
|
||||
void show_fortune_text_impl(const char* text);
|
||||
void render_fortune_text(const std::vector<std::u16string>& lines);
|
||||
|
||||
void Render();
|
||||
void render_counters(Vector& cursor, Vector shake);
|
||||
void render_run_icons(Vector& cursor, Vector shake, float& statsX);
|
||||
void render_coop_carousel();
|
||||
void render_streak_texts();
|
||||
void render_player_hud(int playerHudIndex, PlayerHudLayout layout);
|
||||
void render_player_net_status(int playerHudIndex, Vector at);
|
||||
void render_boss_health_bar(Vector barPos);
|
||||
static void render_modded_coop_portrait(int playerType, Vector at, Vector portraitScale, const ColorMod& color);
|
||||
|
||||
void update_hud_offset();
|
||||
Vector get_player_hud_position(int hudIndex, PlayerHudLayout layout);
|
||||
int GetPlayerHudIndex(Entity_Player* player);
|
||||
PlayerHudLayout GetPlayerHUDLayout(int playerHudIndex, Entity_Player* player);
|
||||
int count_player_huds();
|
||||
void AssignPlayerHUDs();
|
||||
};
|
||||
+1
-2
@@ -1278,8 +1278,7 @@ ItemConfig_Item* ItemConfig::GetCollectible(int id)
|
||||
if (id >= 0) return id < (int)collectibles.size() ? collectibles[id].get() : nullptr;
|
||||
if (!g_game) return nullptr;
|
||||
|
||||
std_vector& procedural = g_game->proceduralItemManager._proceduralItems;
|
||||
auto items = std::span((ProceduralItem**)procedural._begin, (ProceduralItem**)procedural._end);
|
||||
auto& items = g_game->proceduralItemManager.proceduralItems;
|
||||
return (size_t)~id < items.size() ? items[~id]->item : nullptr;
|
||||
}
|
||||
|
||||
|
||||
+1
-7
@@ -529,7 +529,7 @@ int ItemPool::GetCollectible(ItemPoolType poolType, uint32_t drawSeed, uint32_t
|
||||
bool isDecrease = !(flags & POOL_FLAG_NO_DECREASE);
|
||||
if (players.AnyoneHasTrinket(TRINKET_NO)) flags |= POOL_FLAG_BAN_ACTIVES;
|
||||
bool isBanActives = flags & POOL_FLAG_BAN_ACTIVES;
|
||||
if (players.AnyoneHasCollectible(COLLECTIBLE_TMTRAINER)) return CreateGlitchedCollectible(drawSeed, 0);
|
||||
if (players.AnyoneHasCollectible(COLLECTIBLE_TMTRAINER)) return g_game->proceduralItemManager.CreateProceduralItem(drawSeed, 0);
|
||||
|
||||
RNG poolRng = rng_make(drawSeed, CHAOS_SHIFT);
|
||||
bool isChaos = players.AnyoneHasCollectible(COLLECTIBLE_CHAOS) ||
|
||||
@@ -796,12 +796,6 @@ bool ItemPool::should_force_magic_skin(uint32_t drawSeed)
|
||||
return rng.RandomInt((uint32_t)std::max(MAGIC_SKIN_ROLL_BASE - uses, 1)) == 0;
|
||||
}
|
||||
|
||||
// (009dcc70) A TMTRAINER glitched collectible, which ProceduralItemManager makes.
|
||||
int ItemPool::CreateGlitchedCollectible(uint32_t, uint32_t)
|
||||
{
|
||||
reconstruction_missing("ItemPool::CreateGlitchedCollectible 009dcc70");
|
||||
}
|
||||
|
||||
// Whether a trinket pool slot may be drawn: still in the pool, available, and its trinket may appear.
|
||||
static bool is_trinket_drawable(TrinketPoolItem& slot)
|
||||
{
|
||||
|
||||
@@ -175,7 +175,6 @@ public:
|
||||
void ResetRoomBlacklist();
|
||||
void AddBibleUpgrade(int add, int poolType);
|
||||
static bool should_force_magic_skin(uint32_t drawSeed);
|
||||
static int CreateGlitchedCollectible(uint32_t drawSeed, uint32_t flags);
|
||||
|
||||
uint32_t GetTrinket(TrinketDraw draw);
|
||||
bool RemoveTrinket(int trinketId);
|
||||
|
||||
@@ -101,6 +101,7 @@ static void SDLCALL output_feed(void*, SDL_AudioStream* stream, int additional,
|
||||
// (00a7d2a0, 00a9e4f0, 00a2afd0) Opens the default playback device with its voices and starts mixing. Logs and
|
||||
// returns false when there is none.
|
||||
// The OpenAL Soft system events and device pause extensions it looked up are SDL's own concern.
|
||||
// Muted (--mute), it still mixes, at a gain of 0.
|
||||
bool Manager::Init()
|
||||
{
|
||||
SDL_AudioSpec spec = {SDL_AUDIO_F32, OUTPUT_CHANNELS, OUTPUT_RATE};
|
||||
@@ -115,6 +116,7 @@ bool Manager::Init()
|
||||
deviceSpec = spec;
|
||||
for (Voice& voice : voices) voice.converter = SDL_CreateAudioStream(&spec, &spec);
|
||||
log_printf(LOG_INFO, "Audio driver: %s\n", SDL_GetCurrentAudioDriver());
|
||||
if (isMuted) SDL_SetAudioStreamGain(output, 0);
|
||||
SDL_ResumeAudioStreamDevice(output);
|
||||
isInitialized = true;
|
||||
return true;
|
||||
|
||||
@@ -73,6 +73,7 @@ public:
|
||||
SDL_AudioSpec deviceSpec = {};
|
||||
SDL_AudioStream* output = nullptr;
|
||||
bool isInitialized = false;
|
||||
bool isMuted = false;
|
||||
|
||||
~Manager();
|
||||
bool Init();
|
||||
|
||||
+1228
File diff suppressed because it is too large.
Load diff
+226
@@ -0,0 +1,226 @@
|
||||
#pragma once
|
||||
|
||||
#include "classes.h"
|
||||
#include "level_generator.h"
|
||||
#include "seeds.h"
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
constexpr int DIMENSION_COUNT = 3;
|
||||
constexpr int ROOM_MAP_CELLS = DIMENSION_COUNT * LEVEL_GRID_CELLS;
|
||||
constexpr int OFF_MAP_ROOM_COUNT = 20;
|
||||
constexpr int ROOM_DESCRIPTOR_COUNT = ROOM_MAP_CELLS + OFF_MAP_ROOM_COUNT;
|
||||
constexpr int GREED_WAVE_SEED_COUNT = 12;
|
||||
constexpr int VENTRICLE_RAZOR_PORTAL_COUNT = 2;
|
||||
constexpr int PORTAL_ROOM_NONE = -99999;
|
||||
|
||||
// The xorshift a level's RNGs start on before Level::Init seeds them (shift index 35).
|
||||
constexpr RNG LEVEL_RNG_DEFAULT = {RNG_SEED_DEFAULT, 5, 9, 7};
|
||||
|
||||
// The rooms off the 13x13 map, by their negative room index (Lua's GridRooms).
|
||||
enum OffMapRoom : int
|
||||
{
|
||||
ROOM_DEVIL_IDX = -1,
|
||||
ROOM_ERROR_IDX = -2,
|
||||
ROOM_MEGA_SATAN_IDX = -7,
|
||||
ROOM_SECRET_EXIT_IDX = -10,
|
||||
ROOM_LIL_PORTAL_IDX = -20
|
||||
};
|
||||
|
||||
// The floor's own state flags (Lua's LevelStateFlag) the curated code reads, by bit.
|
||||
enum LevelStateFlag : int
|
||||
{
|
||||
LEVEL_STATE_REDHEART_DAMAGED = 2,
|
||||
LEVEL_STATE_LAST = 25
|
||||
};
|
||||
|
||||
// The run's state flags (Lua's GameStateFlag) a floor checks, by bit: a book picked up, the per floor coin cap, the
|
||||
// Mausoleum heart's room and its kill, and the Ascent.
|
||||
enum LevelGameStateFlag : int
|
||||
{
|
||||
LEVEL_GAME_STATE_BOOK_PICKED_UP = 8,
|
||||
LEVEL_GAME_STATE_MAX_COINS_OBTAINED = 44,
|
||||
LEVEL_GAME_STATE_MAUSOLEUM_HEART_ROOM = 46,
|
||||
LEVEL_GAME_STATE_MAUSOLEUM_HEART_KILLED = 47,
|
||||
LEVEL_GAME_STATE_BACKWARDS_PATH = 48
|
||||
};
|
||||
|
||||
// A stage's variant (Lua's StageType): the original chapter, its two alternates, Greed's, and Repentance's two.
|
||||
enum StageType : uint32_t
|
||||
{
|
||||
STAGETYPE_ORIGINAL,
|
||||
STAGETYPE_WOTL,
|
||||
STAGETYPE_AFTERBIRTH,
|
||||
STAGETYPE_GREEDMODE,
|
||||
STAGETYPE_REPENTANCE,
|
||||
STAGETYPE_REPENTANCE_B
|
||||
};
|
||||
|
||||
// A Ventricle Razor portal: the room and grid cell it stands on (no room by default), and a flag its user passes.
|
||||
struct VentricleRazorPortal
|
||||
{
|
||||
int gridIndex = 0;
|
||||
int roomIndex = PORTAL_ROOM_NONE;
|
||||
bool isMarked = false;
|
||||
};
|
||||
|
||||
// The floor (Rebirth's Level, the front of Game, which Game::GetLevel hands out): its stage, curses and room
|
||||
// descriptors, the 13x13 maps of its three dimensions, the room the players are in, and the RNGs a floor is laid out
|
||||
// and its deals drawn with. Init lays a floor out from the run's stage seed.
|
||||
// The getters and setters of plain fields are the members themselves (00407480, 00435fb0, 004360e0, 004b70b0,
|
||||
// 004d3380, 00505c70, 0056ff80, 005b16d0, 005b16e0, 005cd680, 0060d000, 0065cf00, 006ef880, 0070c5b0, 00740df0,
|
||||
// 00753780, 007537f0, 007e9250, 007e9260, 007e9270, 0085e140, 0085e160, 0085e170).
|
||||
class Level
|
||||
{
|
||||
public:
|
||||
std::array<RoomDescriptor, ROOM_DESCRIPTOR_COUNT> roomList{};
|
||||
std::array<int, ROOM_MAP_CELLS> roomMap{};
|
||||
std::array<uint32_t, GREED_WAVE_SEED_COUNT> greedWaveSeeds{};
|
||||
std::array<VentricleRazorPortal, VENTRICLE_RAZOR_PORTAL_COUNT> ventricleRazorPortals{};
|
||||
std::vector<EntitySaveState> myosotisPickups;
|
||||
std::unique_ptr<Room> room;
|
||||
int* currentRoomMap = nullptr;
|
||||
RNG devilAngelRoomRNG = LEVEL_RNG_DEFAULT;
|
||||
RNG generationRNG = LEVEL_RNG_DEFAULT;
|
||||
Vector dungeonReturnPosition{};
|
||||
float angelRoomChance = 0;
|
||||
int bombPickupsSpawned = 0;
|
||||
int currentDimensionIdx = 0;
|
||||
int currentRoomIdx = 0;
|
||||
int dungeonReturnRoomIndex = 0;
|
||||
int enterDoor = 0;
|
||||
int firstBossRoomListIdx = -1;
|
||||
int greedLastBeatenWave = 0;
|
||||
int greedLastPaidWave = 0;
|
||||
int greedModeWave = 0;
|
||||
int greedWavesClearedWithoutRedHeartDamage = 0;
|
||||
int lastBossRoomListIdx = 0;
|
||||
int lastRoomDimensionIdx = 0;
|
||||
int lastRoomIdx = 0;
|
||||
int leaveDoor = 0;
|
||||
int nbRooms = 0;
|
||||
int startingRoomIdx = 0;
|
||||
uint32_t curses = 0;
|
||||
uint32_t dungeonPlacementSeed = 0;
|
||||
uint32_t greedModeTreasureRoomIdx = 0;
|
||||
uint32_t levelStateFlags = 0;
|
||||
uint32_t stage = 0;
|
||||
uint32_t stageType = 0;
|
||||
bool isBossChallenge = false;
|
||||
bool isCanSeeEverything = false;
|
||||
bool isDevilRoomDisabled = false;
|
||||
bool isHeartPicked = false;
|
||||
bool isLevelGenerating = false;
|
||||
|
||||
void Init(bool isResetLilPortalRoom);
|
||||
void reset_room_list(bool isResetLilPortalRoom);
|
||||
void lil_portal_room_init();
|
||||
void generate_dungeon(RNG& curseRng);
|
||||
bool place_special_rooms(LevelGenerator& generator, int minDifficulty, int maxDifficulty);
|
||||
bool place_room(const LevelGenerator_Room& slot, RoomConfig_Room* data, uint32_t seed, RoomDescriptor** outDesc);
|
||||
void generate_backwards();
|
||||
void generate_greed();
|
||||
void generate_home();
|
||||
void generate_home_level();
|
||||
void generate_random_layout();
|
||||
void generate_mirror_world();
|
||||
void generate_mineshaft();
|
||||
void generate_dark_closet();
|
||||
void enter_dark_closet();
|
||||
void InitStageSeeds();
|
||||
bool try_place_random_room(LevelGenerator& generator);
|
||||
static RoomConfig_Room* pick_boss_room_config(int bossId, uint32_t seed);
|
||||
std::set<int> get_secret_room_excluded_cells();
|
||||
static bool boss_count_adjust(int& stage, int& stageType);
|
||||
|
||||
void Update();
|
||||
void load_room();
|
||||
void ChangeRoom(int targetRoomIdx, int dimension);
|
||||
void DEBUG_goto_room(RoomConfig_Room* roomConfig);
|
||||
void update_all_room_doors();
|
||||
void update_room_doors(RoomDescriptor& room);
|
||||
void UpdateVisibility();
|
||||
void ApplyMapEffect();
|
||||
void ApplyBlueMapEffect();
|
||||
void ApplyCompassEffect(bool isPersistent);
|
||||
void RemoveCompassEffect();
|
||||
void ShowMap();
|
||||
void reveal_secret_room();
|
||||
|
||||
RoomDescriptor* GetRoomByIdx(int idx, int dimension = -1);
|
||||
RoomDescriptor* GetCurrentRoomDesc();
|
||||
RoomDescriptor* GetLastRoomDesc();
|
||||
int GetRandomRoomIndex(bool isErrorRoom, uint32_t seed);
|
||||
int GetNonCompleteRoomIndex();
|
||||
int QueryRoomTypeIndex(int roomType, bool isVisited, RNG& rng, bool isIgnoreGroup);
|
||||
int find_matching_room_idx(int roomIdx);
|
||||
bool maze_swap_rooms(int roomIdx, int otherRoomIdx);
|
||||
std::set<int> get_rooms_within_two_doors(int gridIndex);
|
||||
std::vector<int> get_door_neighbor_indices();
|
||||
int GetRoomStageType(int roomIdx);
|
||||
Vector GetEnterPosition();
|
||||
|
||||
static int get_door_slot(int shape, int doorSlot, bool isUnknown, int direction);
|
||||
int GetTargetSlot(int roomIdx, int doorSlot);
|
||||
static XY get_door_neighbor_pos(XY gridPos, RoomShape shape, int doorSlot);
|
||||
int GetNeighborRoomIdx(int roomIdx, int doorSlot);
|
||||
static uint32_t get_red_room_neighbor_slots(int roomIdx, int doorSlot, int* outSlots);
|
||||
LevelGenerator_Room get_door_neighbor_room(int roomIdx, int doorSlot);
|
||||
bool CanSpawnDoorOutline(int roomIdx, int doorSlot);
|
||||
static int roll_red_room_type();
|
||||
bool MakeRedRoomDoor(int roomIdx, int doorSlot);
|
||||
void UncoverHiddenDoor(int roomIdx, int doorSlot);
|
||||
bool prepare_blue_room(int currentRoomIdx, int targetRoomIdx, int direction);
|
||||
bool TryInitializeExtraBossRoom(uint32_t seed);
|
||||
static void update_treasure_room_doors_for_trinket();
|
||||
void init_rotgut_dungeon_room();
|
||||
void InitializeGenesisRoom();
|
||||
bool CanOpenChallengeRoom(int roomIdx);
|
||||
bool ForceHorsemanBoss(uint32_t seed);
|
||||
bool CanSpawnDevilRoom();
|
||||
void InitializeDevilAngelRoom(bool isForceAngel, bool isForceDevil);
|
||||
void StartMamaMega(Vector& position, Entity_Player* player);
|
||||
void raise_mineshaft_rail();
|
||||
|
||||
uint32_t GetCurses();
|
||||
uint32_t filter_curses(uint32_t mask);
|
||||
void AddCurse(uint32_t addedCurses, bool isShowName);
|
||||
void RemoveCurses(uint32_t removedCurses);
|
||||
static bool CanStageHaveCurseOfLabyrinth(uint32_t levelStage);
|
||||
bool GetStateFlag(int flag);
|
||||
void SetStateFlag(int flag, bool isSet);
|
||||
void SetRedHeartDamage();
|
||||
|
||||
void SetStage(int stageId, int alt);
|
||||
void SetNextStage();
|
||||
bool IsNextStageAvailable();
|
||||
static bool IsStageWithinEnd(int levelStage, bool isAltPath);
|
||||
bool UpdateBackwardsPathStages();
|
||||
static uint32_t GetStageID();
|
||||
int GetAbsoluteStage();
|
||||
bool IsAltStage();
|
||||
bool IsAltPath();
|
||||
bool IsAscent();
|
||||
bool IsPreAscent();
|
||||
bool IsMausoleumHeartStage();
|
||||
bool HasMirrorDimension();
|
||||
bool HasAbandonedMineshaft();
|
||||
bool HasPhotoDoor();
|
||||
bool CanSpawnTrapDoor();
|
||||
int get_secret_exit_kind();
|
||||
RoomDescriptor* get_secret_exit_room(int kind);
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
void room_descriptor_seeds_init(RoomDescriptor& room, RNG& rng);
|
||||
@@ -0,0 +1,833 @@
|
||||
#include "level_generator.h"
|
||||
#include "platform.h"
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <deque>
|
||||
|
||||
// A spot a candidate room may take beside a door: its top left cell and shape.
|
||||
struct ShapeSpot
|
||||
{
|
||||
XY position;
|
||||
RoomShape shape;
|
||||
};
|
||||
|
||||
constexpr uint32_t GENERATION_SHIFT_INDEX = 35;
|
||||
constexpr int SHAPE_SPOT_COUNT = 13;
|
||||
constexpr int RESIZE_SPOT_COUNT = SHAPE_SPOT_COUNT + 1;
|
||||
constexpr int START_BRANCHES_MIN = 2;
|
||||
constexpr int START_BRANCHES_ROLL_LIMIT = 16;
|
||||
constexpr int CROWDED_ROOM_ODDS = 10;
|
||||
constexpr int QUEUE_BACK_ODDS = 3;
|
||||
constexpr int DEAD_END_TRIES = 5;
|
||||
constexpr int XL_BOSS_STEPS = 3;
|
||||
constexpr int SECRET_SCORE_BASE = 10;
|
||||
constexpr int SECRET_SCORE_ROLL = 5;
|
||||
constexpr int SECRET_SCORE_BLOCKED = 100;
|
||||
constexpr int SECRET_SCORE_FEW_NEIGHBORS = 3;
|
||||
|
||||
// The cell offsets of each direction: left, up, right, down.
|
||||
constexpr std::array<XY, DIRECTION_COUNT> DIRECTIONS = {{{-1, 0}, {0, -1}, {1, 0}, {0, 1}}};
|
||||
|
||||
// A cell and the four around it, the area a placed boss room keeps free.
|
||||
constexpr std::array<XY, 5> CELL_AND_NEIGHBORS = {{{0, 0}, {-1, 0}, {1, 0}, {0, -1}, {0, 1}}};
|
||||
|
||||
// The cells two steps away, which an ultra secret room's red room neighbours stand on.
|
||||
constexpr std::array<XY, 8> TWO_STEP_OFFSETS = {{{-2, 0}, {-1, -1}, {0, -2}, {1, -1}, {2, 0}, {1, 1}, {0, 2}, {-1, 1}}};
|
||||
|
||||
// Each shape's width and height in cells.
|
||||
constexpr std::array<XY, ROOMSHAPE_ANY> SHAPE_SIZES = {
|
||||
{{0, 0}, {1, 1}, {1, 1}, {1, 1}, {1, 2}, {1, 2}, {2, 1}, {2, 1}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}}};
|
||||
|
||||
constexpr XY CELLS_1x1[] = {{0, 0}};
|
||||
constexpr XY CELLS_1x2[] = {{0, 0}, {0, 1}};
|
||||
constexpr XY CELLS_2x1[] = {{0, 0}, {1, 0}};
|
||||
constexpr XY CELLS_2x2[] = {{0, 0}, {1, 0}, {0, 1}, {1, 1}};
|
||||
constexpr XY CELLS_LTL[] = {{1, 0}, {0, 1}, {1, 1}};
|
||||
constexpr XY CELLS_LTR[] = {{0, 0}, {0, 1}, {1, 1}};
|
||||
constexpr XY CELLS_LBL[] = {{0, 0}, {1, 0}, {1, 1}};
|
||||
constexpr XY CELLS_LBR[] = {{0, 0}, {1, 0}, {0, 1}};
|
||||
|
||||
// The cells each shape covers from its top left cell, in the order the game walks them.
|
||||
constexpr std::array<std::span<const XY>, ROOMSHAPE_ANY> SHAPE_CELLS = {
|
||||
std::span<const XY>{}, CELLS_1x1, CELLS_1x1, CELLS_1x1, CELLS_1x2, CELLS_1x2, CELLS_2x1,
|
||||
CELLS_2x1, CELLS_2x2, CELLS_LTL, CELLS_LTR, CELLS_LBL, CELLS_LBR};
|
||||
|
||||
// The odds (1 in n) a candidate spot is kept while 1x1 rooms are allowed, by spot.
|
||||
constexpr std::array<uint32_t, SHAPE_SPOT_COUNT> SPOT_ODDS = {48, 24, 24, 24, 24, 72, 72, 36, 36, 36, 36, 24, 24};
|
||||
|
||||
// The L shapes a room growing toward each direction may take, in the game's spot order.
|
||||
constexpr std::array<std::array<RoomShape, 4>, DIRECTION_COUNT> L_SHAPES = {{
|
||||
{ROOMSHAPE_LBR, ROOMSHAPE_LTR, ROOMSHAPE_LBL, ROOMSHAPE_LTL},
|
||||
{ROOMSHAPE_LBR, ROOMSHAPE_LBL, ROOMSHAPE_LTR, ROOMSHAPE_LTL},
|
||||
{ROOMSHAPE_LBL, ROOMSHAPE_LTL, ROOMSHAPE_LTR, ROOMSHAPE_LBR},
|
||||
{ROOMSHAPE_LTR, ROOMSHAPE_LTL, ROOMSHAPE_LBL, ROOMSHAPE_LBR},
|
||||
}};
|
||||
|
||||
// Which resize spots face their parent through the far half of their side. The last spot's slot was read past the
|
||||
// game's table (its stack cookie), so that spot never matches a door here.
|
||||
constexpr std::array<bool, RESIZE_SPOT_COUNT> RESIZE_SPOT_FAR_SLOTS = {false, false, true, false, true, false, true,
|
||||
false, true, false, true, false, false, false};
|
||||
|
||||
int XY::ToGridIdx() const
|
||||
{
|
||||
return (uint32_t)x < LEVEL_GRID_WIDTH && (uint32_t)y < LEVEL_GRID_WIDTH ? y * LEVEL_GRID_WIDTH + x : -1;
|
||||
}
|
||||
|
||||
XY XY::NewFromGridIdx(int gridIdx)
|
||||
{
|
||||
return {gridIdx % LEVEL_GRID_WIDTH, gridIdx / LEVEL_GRID_WIDTH};
|
||||
}
|
||||
|
||||
// The side a room joined its parent through, as seen from the room.
|
||||
static int direction_opposite(int direction)
|
||||
{
|
||||
return (direction + 2) % DIRECTION_COUNT;
|
||||
}
|
||||
|
||||
// The thirteen spots a room entering through cell may take, growing away from its parent toward direction.
|
||||
static std::array<ShapeSpot, SHAPE_SPOT_COUNT> shape_spots_get(XY cell, int direction)
|
||||
{
|
||||
bool isHorizontal = direction == 0 || direction == 2;
|
||||
XY offset = direction == 0 || direction == 1 ? DIRECTIONS[direction] : XY{0, 0};
|
||||
XY across = isHorizontal ? XY{0, -1} : XY{-1, 0};
|
||||
RoomShape alongShape = isHorizontal ? ROOMSHAPE_2x1 : ROOMSHAPE_1x2;
|
||||
RoomShape acrossShape = isHorizontal ? ROOMSHAPE_1x2 : ROOMSHAPE_2x1;
|
||||
const std::array<RoomShape, 4>& lShapes = L_SHAPES[direction];
|
||||
XY grown = cell + offset;
|
||||
XY shifted = grown + across;
|
||||
|
||||
return {{{grown, alongShape},
|
||||
{cell, acrossShape},
|
||||
{cell + across, acrossShape},
|
||||
{grown, ROOMSHAPE_2x2},
|
||||
{shifted, ROOMSHAPE_2x2},
|
||||
{grown, lShapes[0]},
|
||||
{shifted, lShapes[1]},
|
||||
{grown, lShapes[2]},
|
||||
{shifted, lShapes[2]},
|
||||
{grown, lShapes[3]},
|
||||
{shifted, lShapes[3]},
|
||||
{cell, isHorizontal ? ROOMSHAPE_IH : ROOMSHAPE_IV},
|
||||
{grown, isHorizontal ? ROOMSHAPE_IIH : ROOMSHAPE_IIV}}};
|
||||
}
|
||||
|
||||
// Shuffles from the back, each element swapped with one at or before it, as RNG::Shuffle does.
|
||||
template <typename T> static void elements_shuffle(RNG& rng, std::vector<T>& elements)
|
||||
{
|
||||
for (size_t i = elements.size() - 1; i > 0 && i < elements.size(); i--)
|
||||
std::swap(elements[i], elements[rng.RandomInt((uint32_t)i + 1)]);
|
||||
}
|
||||
|
||||
// 009adaf0 Starts an empty layout: no rooms, no blocked cells, every shape allowed, the RNG on the seed.
|
||||
LevelGenerator::LevelGenerator(uint32_t seed)
|
||||
{
|
||||
roomMap.fill(-1);
|
||||
rng.SetSeed(seed, GENERATION_SHIFT_INDEX);
|
||||
}
|
||||
|
||||
// 009adbb0 Grows a layout of settings.roomCount rooms past the start, adds up to five dead ends while short of
|
||||
// settings.deadEndCount, then sorts the dead ends farthest from the start first (ties keep their order).
|
||||
void LevelGenerator::Generate(const GenerationSettings& settings, const LevelGenerator_Room& startRoom)
|
||||
{
|
||||
isXL = settings.isXL;
|
||||
isChapter6 = settings.isChapter6;
|
||||
isVoid = settings.isVoid;
|
||||
allowedShapes = settings.allowedShapes;
|
||||
roomMap.fill(-1);
|
||||
nextBossRoomIdx = -1;
|
||||
deadEnds.clear();
|
||||
nonDeadEnds.clear();
|
||||
numBossRooms = 0;
|
||||
rooms.clear();
|
||||
|
||||
generate_rooms(settings.roomCount, startRoom);
|
||||
update_dead_end_lists();
|
||||
for (int tries = DEAD_END_TRIES; (int)deadEnds.size() < settings.deadEndCount && tries > 0; tries--)
|
||||
{
|
||||
log_printf(LOG_INFO, "not enough dead ends, trying to make new one\n");
|
||||
add_dead_end();
|
||||
update_dead_end_lists();
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < deadEnds.size(); i++)
|
||||
{
|
||||
size_t farthest = i;
|
||||
|
||||
for (size_t j = i + 1; j < deadEnds.size(); j++)
|
||||
if (rooms[deadEnds[j]].distanceFromStart > rooms[deadEnds[farthest]].distanceFromStart) farthest = j;
|
||||
std::swap(deadEnds[i], deadEnds[farthest]);
|
||||
}
|
||||
}
|
||||
|
||||
// 009b04d0 Grows rooms breadth first from the start: each room taken from the queue offers its shuffled candidates,
|
||||
// the start branching two or three ways (every way on floors of 16 rooms or more) and any other room up to four coin
|
||||
// flips' worth. A room touching two others is refused, but for 1 in 10 on XL floors and the Void. A new room goes to
|
||||
// the back of the queue 1 in 3 times, else to its front.
|
||||
void LevelGenerator::generate_rooms(int roomCount, const LevelGenerator_Room& startRoom)
|
||||
{
|
||||
std::deque<int> queue;
|
||||
int startIdx = place_room(startRoom).generationIndex;
|
||||
int placedCount = 0;
|
||||
int loops = 0;
|
||||
|
||||
queue.push_front(startIdx);
|
||||
while (!queue.empty() && placedCount < roomCount)
|
||||
{
|
||||
int index = queue.front();
|
||||
std::vector<LevelGenerator_Room> candidates = get_neighbor_candidates(index, CANDIDATE_SHAPES_ROLLED);
|
||||
int branchLimit = (int)candidates.size();
|
||||
int branches = 0;
|
||||
|
||||
queue.pop_front();
|
||||
loops++;
|
||||
elements_shuffle(rng, candidates);
|
||||
if (index == startIdx)
|
||||
{
|
||||
if (roomCount < START_BRANCHES_ROLL_LIMIT) branchLimit = (int)(rng.Next() & 1) + START_BRANCHES_MIN;
|
||||
}
|
||||
else
|
||||
{
|
||||
int flips = 0;
|
||||
|
||||
for (int i = 0; i < 4; i++) flips += (int)(rng.Next() & 1);
|
||||
branchLimit = std::min(branchLimit, flips);
|
||||
}
|
||||
|
||||
for (const LevelGenerator_Room& candidate : candidates)
|
||||
{
|
||||
if (!can_place_room(candidate.position, candidate.shape)) continue;
|
||||
if (count_neighbor_rooms(candidate.linkPos) >= 2 &&
|
||||
(!(isXL || isVoid) || rng.Next() % CROWDED_ROOM_ODDS != 0))
|
||||
continue;
|
||||
if (!is_placement_valid(candidate.position, candidate.shape)) continue;
|
||||
|
||||
int newIndex = place_room(candidate).generationIndex;
|
||||
|
||||
if (rng.Next() % QUEUE_BACK_ODDS == 0) queue.push_back(newIndex);
|
||||
else queue.push_front(newIndex);
|
||||
branches++;
|
||||
placedCount++;
|
||||
if (branches >= branchLimit || placedCount >= roomCount) break;
|
||||
}
|
||||
}
|
||||
|
||||
if (placedCount >= roomCount) log_printf(LOG_INFO, "%d rooms in %d loops\n", placedCount, loops);
|
||||
else log_printf(LOG_INFO, "[LevelGenerator] fail %d/%d in %d loops\n", placedCount, roomCount, loops);
|
||||
}
|
||||
|
||||
// 009b0b00 The rooms that could join the room at generationIndex: for each of its doors leading to a free cell, a 1x1
|
||||
// there (when allowed), then the thirteen bigger spots around it, each kept at its odds (always when 1x1 rooms are not
|
||||
// allowed, or for any shape) when its shape is allowed and fits. Each spot draws from the RNG either way.
|
||||
std::vector<LevelGenerator_Room> LevelGenerator::get_neighbor_candidates(int generationIndex,
|
||||
CandidateShapes candidateShapes)
|
||||
{
|
||||
std::vector<LevelGenerator_Room> candidates;
|
||||
|
||||
if ((size_t)generationIndex >= rooms.size())
|
||||
{
|
||||
log_printf(LOG_ASSERT, "[LevelGenerator] get_neighbor_candidates: out of bounds\n");
|
||||
return candidates;
|
||||
}
|
||||
|
||||
const LevelGenerator_Room& source = rooms[generationIndex];
|
||||
auto candidate_add = [&](const ShapeSpot& spot, int doorSlot, XY cell)
|
||||
{
|
||||
LevelGenerator_Room& room = candidates.emplace_back();
|
||||
|
||||
room.position = spot.position;
|
||||
room.shape = spot.shape;
|
||||
room.connectDirection = doorSlot % DIRECTION_COUNT;
|
||||
room.connectDoorSlot = doorSlot;
|
||||
room.linkPos = cell;
|
||||
room.distanceFromStart = source.distanceFromStart + 1;
|
||||
};
|
||||
|
||||
for (int doorSlot = 0; doorSlot < DOOR_SLOT_COUNT; doorSlot++)
|
||||
{
|
||||
XY cell = get_door_target_position(source.position, source.shape, doorSlot, THIN_SHAPES_RESTRICTED);
|
||||
|
||||
if (cell.ToGridIdx() < 0 || !can_place_room(cell, ROOMSHAPE_1x1)) continue;
|
||||
|
||||
bool isSingleAllowed = allowedShapes >> ROOMSHAPE_1x1 & 1;
|
||||
std::array<ShapeSpot, SHAPE_SPOT_COUNT> spots = shape_spots_get(cell, doorSlot % DIRECTION_COUNT);
|
||||
|
||||
if (isSingleAllowed) candidate_add({cell, ROOMSHAPE_1x1}, doorSlot, cell);
|
||||
for (int i = 0; i < SHAPE_SPOT_COUNT; i++)
|
||||
{
|
||||
bool isRolled = rng.Next() % SPOT_ODDS[i] == 0;
|
||||
|
||||
isRolled = isRolled || !isSingleAllowed || candidateShapes == CANDIDATE_SHAPES_ANY;
|
||||
|
||||
if ((allowedShapes >> spots[i].shape & 1) && isRolled && can_place_room(spots[i].position, spots[i].shape))
|
||||
candidate_add(spots[i], doorSlot, cell);
|
||||
}
|
||||
}
|
||||
return candidates;
|
||||
}
|
||||
|
||||
// 009add30 Places a room the special generators (Greed, the Blue Womb, Home) lay by hand, then refreshes the dead ends.
|
||||
LevelGenerator_Room* LevelGenerator::CreateRoom(const LevelGenerator_Room& room)
|
||||
{
|
||||
int index = place_room(room).generationIndex;
|
||||
|
||||
update_dead_end_lists();
|
||||
return &rooms[index];
|
||||
}
|
||||
|
||||
// 009b0330 Adds a room to the layout under the next index and marks its cells. A cell off the grid is logged and
|
||||
// skipped (the original wrote it into the field before the grid).
|
||||
LevelGenerator_Room& LevelGenerator::place_room(const LevelGenerator_Room& room)
|
||||
{
|
||||
int index = (int)rooms.size();
|
||||
|
||||
rooms.push_back(room);
|
||||
rooms.back().generationIndex = index;
|
||||
if (room.shape != ROOMSHAPE_1x1) log_printf(LOG_INFO, "place_room: shape %d\n", room.shape);
|
||||
for (XY offset : get_room_placement_offsets(room.shape))
|
||||
{
|
||||
int cell = (room.position + offset).ToGridIdx();
|
||||
|
||||
if (cell < 0) log_printf(LOG_ASSERT, "[LevelGenerator] place_room: invalid room\n");
|
||||
else roomMap[cell] = index;
|
||||
}
|
||||
return rooms.back();
|
||||
}
|
||||
|
||||
// 009b0180 Whether every cell of shape at position is on the grid, free and not blocked, and on the Dark Room and
|
||||
// Chest's chapter not the cell above the start room.
|
||||
bool LevelGenerator::can_place_room(XY position, RoomShape shape)
|
||||
{
|
||||
int aboveStart = rooms.empty() ? -1 : (rooms[0].position + DIRECTIONS[1]).ToGridIdx();
|
||||
|
||||
for (XY offset : get_room_placement_offsets(shape))
|
||||
{
|
||||
int cell = (position + offset).ToGridIdx();
|
||||
|
||||
if ((isChapter6 && cell == aboveStart) || cell < 0 || roomMap[cell] >= 0 || blockedPositions[cell])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// 009b0240 Whether every room touching shape at position has a door slot leading into the cell it touches, and the
|
||||
// shape has a slot toward it (a corridor has none on its long sides).
|
||||
bool LevelGenerator::is_placement_valid(XY position, RoomShape shape)
|
||||
{
|
||||
for (int doorSlot = 0; doorSlot < DOOR_SLOT_COUNT; doorSlot++)
|
||||
{
|
||||
XY source = get_door_source_position(position, shape, doorSlot);
|
||||
int cell = get_door_target_position(position, shape, doorSlot, THIN_SHAPES_IGNORED).ToGridIdx();
|
||||
|
||||
if (cell < 0 || roomMap[cell] < 0) continue;
|
||||
if (source == XY_NONE) return false;
|
||||
|
||||
const LevelGenerator_Room& neighbor = rooms[roomMap[cell]];
|
||||
bool isLinked = false;
|
||||
|
||||
for (int slot = 0; slot < DOOR_SLOT_COUNT && !isLinked; slot++)
|
||||
isLinked =
|
||||
get_door_target_position(neighbor.position, neighbor.shape, slot, THIN_SHAPES_RESTRICTED) == source;
|
||||
if (!isLinked) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// 009b0440 How many cells beside position belong to rooms other than the one on it.
|
||||
int LevelGenerator::count_neighbor_rooms(XY position)
|
||||
{
|
||||
int cell = position.ToGridIdx();
|
||||
int self = cell < 0 ? -1 : roomMap[cell];
|
||||
int count = 0;
|
||||
|
||||
for (XY direction : DIRECTIONS)
|
||||
{
|
||||
int neighbor = (position + direction).ToGridIdx();
|
||||
|
||||
if (neighbor >= 0 && roomMap[neighbor] >= 0 && roomMap[neighbor] != self) count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
// 009af980 Recomputes a room's doors and neighbours from the rooms its door slots lead into.
|
||||
void LevelGenerator::update_room_neighbors(LevelGenerator_Room& room)
|
||||
{
|
||||
room.doors = 0;
|
||||
room.neighbors.clear();
|
||||
for (int doorSlot = 0; doorSlot < DOOR_SLOT_COUNT; doorSlot++)
|
||||
{
|
||||
int cell = get_door_target_position(room.position, room.shape, doorSlot, THIN_SHAPES_RESTRICTED).ToGridIdx();
|
||||
|
||||
if (cell < 0 || roomMap[cell] < 0) continue;
|
||||
room.doors |= 1u << doorSlot;
|
||||
room.neighbors.insert(roomMap[cell]);
|
||||
}
|
||||
}
|
||||
|
||||
// 009afb10 Marks every room but the start whose entry cell touches fewer than two other rooms as a dead end, then
|
||||
// unmarks every room another room joined through. A parent off the grid is logged and skipped (the original wrote
|
||||
// outside the room list).
|
||||
void LevelGenerator::mark_dead_ends()
|
||||
{
|
||||
for (size_t i = 1; i < rooms.size(); i++)
|
||||
if (count_neighbor_rooms(rooms[i].linkPos) < 2) rooms[i].isDeadEnd = true;
|
||||
|
||||
for (size_t i = 1; i < rooms.size(); i++)
|
||||
{
|
||||
if (rooms[i].linkPos == XY_NONE) continue;
|
||||
|
||||
int cell = (rooms[i].linkPos + DIRECTIONS[direction_opposite(rooms[i].connectDirection)]).ToGridIdx();
|
||||
int parent = cell < 0 ? -1 : roomMap[cell];
|
||||
|
||||
if (parent < 0) log_printf(LOG_ASSERT, "invalid connecting neighbor\n");
|
||||
else rooms[parent].isDeadEnd = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 009afc70 Refreshes the dead end marks and every room's doors, and lists the rooms in dead ends and the others.
|
||||
void LevelGenerator::update_dead_end_lists()
|
||||
{
|
||||
deadEnds.clear();
|
||||
nonDeadEnds.clear();
|
||||
mark_dead_ends();
|
||||
for (LevelGenerator_Room& room : rooms)
|
||||
{
|
||||
update_room_neighbors(room);
|
||||
(room.isDeadEnd ? deadEnds : nonDeadEnds).push_back((int)(&room - rooms.data()));
|
||||
}
|
||||
}
|
||||
|
||||
// 009af0e0 Every room, the ones that are not dead ends first.
|
||||
std::vector<LevelGenerator_Room*> LevelGenerator::get_all_rooms()
|
||||
{
|
||||
std::vector<LevelGenerator_Room*> all;
|
||||
|
||||
for (int index : nonDeadEnds) all.push_back(&rooms[index]);
|
||||
for (int index : deadEnds) all.push_back(&rooms[index]);
|
||||
return all;
|
||||
}
|
||||
|
||||
// 009af1e0 Places the first candidate of any shape, by room in order, that fits beside a single room.
|
||||
bool LevelGenerator::add_dead_end()
|
||||
{
|
||||
for (size_t i = 0; i < rooms.size(); i++)
|
||||
for (const LevelGenerator_Room& candidate :
|
||||
get_neighbor_candidates(rooms[i].generationIndex, CANDIDATE_SHAPES_ANY))
|
||||
{
|
||||
if (!can_place_room(candidate.position, candidate.shape) || count_neighbor_rooms(candidate.linkPos) >= 2)
|
||||
continue;
|
||||
place_room(candidate);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// 009addf0 Places a 1x1 dead end beside a single room, trying the rooms in a shuffled order, on a cell not in
|
||||
// excludedCells, then refreshes the dead ends.
|
||||
bool LevelGenerator::try_add_dead_end(const std::set<int>* excludedCells)
|
||||
{
|
||||
std::vector<int> order(rooms.size());
|
||||
|
||||
for (size_t i = 0; i < order.size(); i++) order[i] = (int)i;
|
||||
elements_shuffle(rng, order);
|
||||
|
||||
for (size_t i = 0; i < rooms.size(); i++)
|
||||
for (const LevelGenerator_Room& candidate : get_neighbor_candidates(rooms[order[i]].generationIndex,
|
||||
CANDIDATE_SHAPES_ANY))
|
||||
{
|
||||
if (candidate.shape != ROOMSHAPE_1x1 || !can_place_room(candidate.position, ROOMSHAPE_1x1) ||
|
||||
count_neighbor_rooms(candidate.linkPos) >= 2)
|
||||
continue;
|
||||
if (excludedCells && excludedCells->contains(candidate.position.ToGridIdx())) continue;
|
||||
place_room(candidate);
|
||||
update_dead_end_lists();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// 009b1220 Grows a dead end into shape on a spot around its entry cell: the first spot of that shape whose door
|
||||
// toward the parent is in possibleDoors, whose cells are free, whose other door slots all lead to rooms possibleDoors
|
||||
// has doors toward, and that touches at most one room besides secret rooms. Its neighbours' doors are refreshed.
|
||||
// A room with no entry cell or side is refused (the original read outside the grid and its tables).
|
||||
bool LevelGenerator::try_resize_room(LevelGenerator_Room& room, RoomShape shape, uint32_t possibleDoors)
|
||||
{
|
||||
int linkCell = room.linkPos.ToGridIdx();
|
||||
|
||||
if (linkCell < 0 || room.connectDirection < 0 || room.connectDirection >= DIRECTION_COUNT)
|
||||
{
|
||||
log_printf(LOG_ASSERT, "[LevelGenerator] try_resize_room: invalid room\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
int self = roomMap[linkCell];
|
||||
int parentSide = direction_opposite(room.connectDirection);
|
||||
std::array<ShapeSpot, SHAPE_SPOT_COUNT> spots = shape_spots_get(room.linkPos, room.connectDirection);
|
||||
|
||||
for (int i = 0; i < RESIZE_SPOT_COUNT - 1; i++)
|
||||
{
|
||||
ShapeSpot spot = i == 0 ? ShapeSpot{room.linkPos, ROOMSHAPE_1x1} : spots[i - 1];
|
||||
int parentSlot = parentSide + (RESIZE_SPOT_FAR_SLOTS[i] ? DIRECTION_COUNT : 0);
|
||||
bool isFits = true;
|
||||
int neighborCount = 0;
|
||||
|
||||
if (spot.shape != shape || !(possibleDoors >> parentSlot & 1)) continue;
|
||||
for (XY offset : get_room_placement_offsets(shape))
|
||||
{
|
||||
int cell = (spot.position + offset).ToGridIdx();
|
||||
|
||||
if (cell < 0 || (roomMap[cell] >= 0 && roomMap[cell] != self)) isFits = false;
|
||||
}
|
||||
for (int doorSlot = 0; doorSlot < DOOR_SLOT_COUNT; doorSlot++)
|
||||
{
|
||||
int cell = get_door_target_position(spot.position, shape, doorSlot, THIN_SHAPES_RESTRICTED).ToGridIdx();
|
||||
|
||||
if (cell < 0 || roomMap[cell] < 0 || roomMap[cell] == self) continue;
|
||||
if (!rooms[roomMap[cell]].isSecret) neighborCount++;
|
||||
if (!(possibleDoors >> doorSlot & 1)) isFits = false;
|
||||
}
|
||||
if (neighborCount >= 2 || !isFits) continue;
|
||||
|
||||
for (XY offset : get_room_placement_offsets(room.shape))
|
||||
{
|
||||
int cell = (room.position + offset).ToGridIdx();
|
||||
|
||||
if (cell < 0) log_printf(LOG_ASSERT, "[LevelGenerator] try_resize_endroom: invalid room\n");
|
||||
else roomMap[cell] = -1;
|
||||
}
|
||||
for (XY offset : get_room_placement_offsets(shape)) roomMap[(spot.position + offset).ToGridIdx()] = self;
|
||||
room.position = spot.position;
|
||||
room.shape = shape;
|
||||
for (int neighbor : room.neighbors) update_room_neighbors(rooms[neighbor]);
|
||||
update_room_neighbors(room);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// 009ae0e0 Grows the farthest dead end that fits shape and possibleDoors, and takes it off the dead end list.
|
||||
LevelGenerator_Room* LevelGenerator::GetNewEndRoom(RoomShape shape, uint32_t possibleDoors)
|
||||
{
|
||||
for (auto it = deadEnds.begin(); it != deadEnds.end(); ++it)
|
||||
{
|
||||
LevelGenerator_Room& room = rooms[*it];
|
||||
|
||||
if (!try_resize_room(room, shape, possibleDoors)) continue;
|
||||
deadEnds.erase(it);
|
||||
return &room;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// 009aed50 Picks the farthest dead end more than one step from the start that fits shape and possibleDoors as the next
|
||||
// boss room, taking it off the dead end list. On XL floors the three cells beyond its entry cell, away from its
|
||||
// parent, must be on the grid, free of other rooms and touch no other room, for the second boss room.
|
||||
void LevelGenerator::DetermineBossRoom(RoomShape shape, uint32_t possibleDoors)
|
||||
{
|
||||
for (auto it = deadEnds.begin(); it != deadEnds.end(); ++it)
|
||||
{
|
||||
int roomIndex = *it;
|
||||
LevelGenerator_Room& room = rooms[roomIndex];
|
||||
|
||||
if (room.distanceFromStart <= 1) continue;
|
||||
if (isXL)
|
||||
{
|
||||
XY position = room.linkPos;
|
||||
bool isValid = true;
|
||||
|
||||
for (int step = 0; step < XL_BOSS_STEPS; step++)
|
||||
{
|
||||
int cell = (position = position + DIRECTIONS[room.connectDirection]).ToGridIdx();
|
||||
bool isStepFree = cell >= 0 && isValid && (roomMap[cell] == roomIndex || roomMap[cell] < 0);
|
||||
int touching = 0;
|
||||
|
||||
for (XY direction : DIRECTIONS)
|
||||
{
|
||||
int neighbor = (position + direction).ToGridIdx();
|
||||
|
||||
if (neighbor >= 0 && roomMap[neighbor] >= 0 && roomMap[neighbor] != roomIndex) touching++;
|
||||
}
|
||||
isValid = touching < 1 && isStepFree;
|
||||
}
|
||||
if (!isValid) continue;
|
||||
}
|
||||
if (!try_resize_room(room, shape, possibleDoors)) continue;
|
||||
nextBossRoomIdx = roomIndex;
|
||||
deadEnds.erase(it);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 009aef10 Grows the next boss room into shape. On XL floors the first boss room also places the second beside it
|
||||
// (a shuffled candidate fitting beside one room, entered through a door possibleDoors has), as the next pick.
|
||||
LevelGenerator_Room* LevelGenerator::place_boss_room(RoomShape shape, uint32_t possibleDoors, BossRoomPick pick)
|
||||
{
|
||||
if (!isXL || numBossRooms < 1 || pick == BOSS_ROOM_DETERMINE) DetermineBossRoom(shape, possibleDoors);
|
||||
if (nextBossRoomIdx < 0 || !try_resize_room(rooms[nextBossRoomIdx], shape, possibleDoors)) return nullptr;
|
||||
|
||||
int bossRoomIdx = nextBossRoomIdx;
|
||||
|
||||
numBossRooms++;
|
||||
nextBossRoomIdx = -1;
|
||||
if (isXL && numBossRooms < 2)
|
||||
{
|
||||
std::vector<LevelGenerator_Room> candidates =
|
||||
get_neighbor_candidates(rooms[bossRoomIdx].generationIndex, CANDIDATE_SHAPES_ROLLED);
|
||||
|
||||
elements_shuffle(rng, candidates);
|
||||
for (const LevelGenerator_Room& candidate : candidates)
|
||||
{
|
||||
if (!can_place_room(candidate.position, candidate.shape) || count_neighbor_rooms(candidate.linkPos) >= 2 ||
|
||||
!(possibleDoors >> candidate.connectDoorSlot & 1))
|
||||
continue;
|
||||
|
||||
LevelGenerator_Room& second = place_room(candidate);
|
||||
|
||||
nextBossRoomIdx = second.generationIndex;
|
||||
second.isDeadEnd = true;
|
||||
update_room_neighbors(second);
|
||||
rooms[bossRoomIdx].doors |= 1u << second.connectDoorSlot;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return &rooms[bossRoomIdx];
|
||||
}
|
||||
|
||||
// 009ae170 Places a secret room on the best scoring empty cell, unblocked and not in excludedCells: 10 to 14, less 100
|
||||
// per room beside it without a door slot facing it, less 3 below three neighbours and 3 more below two. Ties are
|
||||
// drawn from.
|
||||
LevelGenerator_Room* LevelGenerator::place_secret_room(const std::set<int>& excludedCells)
|
||||
{
|
||||
std::vector<int> bestCells;
|
||||
int bestScore = 0;
|
||||
|
||||
for (int cell = 0; cell < LEVEL_GRID_CELLS; cell++)
|
||||
{
|
||||
if (roomMap[cell] >= 0 || excludedCells.contains(cell) || blockedPositions[cell]) continue;
|
||||
|
||||
XY position = XY::NewFromGridIdx(cell);
|
||||
int score = SECRET_SCORE_BASE + (int)(rng.Next() % SECRET_SCORE_ROLL);
|
||||
int neighborCount = 0;
|
||||
|
||||
for (int direction = 0; direction < DIRECTION_COUNT; direction++)
|
||||
{
|
||||
int neighbor = (position + DIRECTIONS[direction]).ToGridIdx();
|
||||
|
||||
if (neighbor < 0 || roomMap[neighbor] < 0) continue;
|
||||
|
||||
const LevelGenerator_Room& room = rooms[roomMap[neighbor]];
|
||||
|
||||
if (get_door_target_position(room.position, room.shape, direction_opposite(direction),
|
||||
THIN_SHAPES_RESTRICTED) == XY_NONE)
|
||||
score -= SECRET_SCORE_BLOCKED;
|
||||
else neighborCount++;
|
||||
}
|
||||
if (neighborCount == 0 || score < 0) continue;
|
||||
if (neighborCount < 3) score -= SECRET_SCORE_FEW_NEIGHBORS;
|
||||
if (neighborCount < 2) score -= SECRET_SCORE_FEW_NEIGHBORS;
|
||||
|
||||
if (score > bestScore) bestCells.clear();
|
||||
if (score >= bestScore)
|
||||
{
|
||||
bestScore = score;
|
||||
bestCells.push_back(cell);
|
||||
}
|
||||
}
|
||||
if (bestCells.empty()) return nullptr;
|
||||
|
||||
int cell = bestCells[rng.Next() % bestCells.size()];
|
||||
XY position = XY::NewFromGridIdx(cell);
|
||||
LevelGenerator_Room secret;
|
||||
|
||||
secret.position = position;
|
||||
secret.isSecret = true;
|
||||
place_room(secret);
|
||||
|
||||
LevelGenerator_Room& room = rooms[roomMap[cell]];
|
||||
|
||||
update_room_neighbors(room);
|
||||
for (XY direction : DIRECTIONS)
|
||||
{
|
||||
int neighbor = (position + direction).ToGridIdx();
|
||||
|
||||
if (neighbor >= 0 && roomMap[neighbor] >= 0) update_room_neighbors(rooms[roomMap[neighbor]]);
|
||||
}
|
||||
return &room;
|
||||
}
|
||||
|
||||
// 009ae640 Places the ultra secret room on the best scoring empty, unblocked cell outside doorCells with no room or
|
||||
// blocked cell beside it: 10 to 14, less 100 per room two steps away whose slot facing it leads off the grid or
|
||||
// outside doorCells, less 3 below three such rooms and 3 more below two. Ties are drawn from. Those rooms then get
|
||||
// door bits toward the empty cells beside it, the way a Red Key opens.
|
||||
LevelGenerator_Room* LevelGenerator::try_place_room(const std::set<int>* doorCells)
|
||||
{
|
||||
std::vector<int> bestCells;
|
||||
int bestScore = 0;
|
||||
|
||||
for (int cell = 0; cell < LEVEL_GRID_CELLS; cell++)
|
||||
{
|
||||
if (roomMap[cell] >= 0 || blockedPositions[cell] || (doorCells && doorCells->contains(cell))) continue;
|
||||
|
||||
XY position = XY::NewFromGridIdx(cell);
|
||||
int score = SECRET_SCORE_BASE + (int)(rng.Next() % SECRET_SCORE_ROLL);
|
||||
int roomCount = 0;
|
||||
|
||||
for (XY direction : DIRECTIONS)
|
||||
{
|
||||
int neighbor = (position + direction).ToGridIdx();
|
||||
|
||||
if (neighbor >= 0 && (roomMap[neighbor] >= 0 || blockedPositions[neighbor])) score -= SECRET_SCORE_BLOCKED;
|
||||
}
|
||||
for (size_t i = 0; i < TWO_STEP_OFFSETS.size() && score >= 0; i++)
|
||||
{
|
||||
XY offset = TWO_STEP_OFFSETS[i];
|
||||
int other = (position + offset).ToGridIdx();
|
||||
|
||||
if (other < 0 || roomMap[other] < 0) continue;
|
||||
|
||||
const LevelGenerator_Room& room = rooms[roomMap[other]];
|
||||
|
||||
for (int direction = 0; direction < DIRECTION_COUNT; direction++)
|
||||
{
|
||||
if (DIRECTIONS[direction].x * offset.x + DIRECTIONS[direction].y * offset.y <= 0) continue;
|
||||
|
||||
int target = get_door_target_position(room.position, room.shape, direction_opposite(direction),
|
||||
THIN_SHAPES_RESTRICTED)
|
||||
.ToGridIdx();
|
||||
|
||||
if (target >= 0 && (!doorCells || doorCells->contains(target))) continue;
|
||||
score -= SECRET_SCORE_BLOCKED;
|
||||
break;
|
||||
}
|
||||
roomCount++;
|
||||
}
|
||||
if (roomCount == 0 || score < 0) continue;
|
||||
if (roomCount < 3) score -= SECRET_SCORE_FEW_NEIGHBORS;
|
||||
if (roomCount < 2) score -= SECRET_SCORE_FEW_NEIGHBORS;
|
||||
|
||||
if (score > bestScore) bestCells.clear();
|
||||
if (score >= bestScore)
|
||||
{
|
||||
bestScore = score;
|
||||
bestCells.push_back(cell);
|
||||
}
|
||||
}
|
||||
if (bestCells.empty()) return nullptr;
|
||||
|
||||
int cell = bestCells[rng.Next() % bestCells.size()];
|
||||
XY position = XY::NewFromGridIdx(cell);
|
||||
LevelGenerator_Room ultraSecret;
|
||||
|
||||
ultraSecret.position = position;
|
||||
ultraSecret.isSecret = true;
|
||||
place_room(ultraSecret);
|
||||
|
||||
LevelGenerator_Room& room = rooms[roomMap[cell]];
|
||||
|
||||
update_room_neighbors(room);
|
||||
for (XY offset : TWO_STEP_OFFSETS)
|
||||
{
|
||||
int other = (position + offset).ToGridIdx();
|
||||
|
||||
if (other < 0 || roomMap[other] < 0) continue;
|
||||
|
||||
LevelGenerator_Room& neighbor = rooms[roomMap[other]];
|
||||
|
||||
for (int doorSlot = 0; doorSlot < DOOR_SLOT_COUNT; doorSlot++)
|
||||
{
|
||||
XY target = get_door_target_position(neighbor.position, neighbor.shape, doorSlot, THIN_SHAPES_RESTRICTED);
|
||||
XY distance = target - position;
|
||||
int targetCell = target.ToGridIdx();
|
||||
|
||||
if (targetCell >= 0 && roomMap[targetCell] < 0 && std::abs(distance.x) + std::abs(distance.y) == 1)
|
||||
neighbor.doors |= 1u << doorSlot;
|
||||
}
|
||||
}
|
||||
return &room;
|
||||
}
|
||||
|
||||
// 009b1910 Blocks a cell from taking rooms.
|
||||
void LevelGenerator::block_cell(XY position)
|
||||
{
|
||||
int cell = position.ToGridIdx();
|
||||
|
||||
if (cell >= 0) blockedPositions[cell] = true;
|
||||
}
|
||||
|
||||
// 009b1860 Blocks a room's cells and the cells beside them.
|
||||
void LevelGenerator::block_room_area(const LevelGenerator_Room& room)
|
||||
{
|
||||
for (XY offset : get_room_placement_offsets(room.shape))
|
||||
for (XY around : CELL_AND_NEIGHBORS) block_cell(room.position + offset + around);
|
||||
}
|
||||
|
||||
// 009b1950 Blocks every cell on or beside a room of another layout.
|
||||
void LevelGenerator::block_cells_near_rooms(const LevelGenerator& other)
|
||||
{
|
||||
for (int cell = 0; cell < LEVEL_GRID_CELLS; cell++)
|
||||
for (XY around : CELL_AND_NEIGHBORS)
|
||||
{
|
||||
int neighbor = (XY::NewFromGridIdx(cell) + around).ToGridIdx();
|
||||
|
||||
if (blockedPositions[cell]) break;
|
||||
if (neighbor >= 0 && other.roomMap[neighbor] >= 0) blockedPositions[cell] = true;
|
||||
}
|
||||
}
|
||||
|
||||
// 009b1a00 Blocks the cells a room's door slots outside doorMask lead to.
|
||||
void LevelGenerator::block_unused_door_cells(const LevelGenerator_Room& room, uint32_t doorMask)
|
||||
{
|
||||
for (int doorSlot = 0; doorSlot < DOOR_SLOT_COUNT; doorSlot++)
|
||||
if (!(doorMask >> doorSlot & 1))
|
||||
block_cell(get_door_target_position(room.position, room.shape, doorSlot, THIN_SHAPES_IGNORED));
|
||||
}
|
||||
|
||||
// 009af370 Whether a shape has a door slot: none on the far half of a side one cell long, and none on the long sides
|
||||
// of a corridor unless thin shapes are ignored.
|
||||
bool LevelGenerator::has_shape_slot(RoomShape shape, int doorSlot, ThinShapes thinShapes)
|
||||
{
|
||||
if (shape < 0 || shape >= ROOMSHAPE_ANY) return false;
|
||||
|
||||
XY size = SHAPE_SIZES[shape];
|
||||
bool isRestricted = thinShapes == THIN_SHAPES_RESTRICTED;
|
||||
bool isSideSlot = doorSlot % 2 == 0;
|
||||
|
||||
if (size.y == 1 && (doorSlot == DOOR_LEFT1 || doorSlot == DOOR_RIGHT1)) return false;
|
||||
if (size.x == 1 && (doorSlot == DOOR_UP1 || doorSlot == DOOR_DOWN1)) return false;
|
||||
if ((shape == ROOMSHAPE_IV || shape == ROOMSHAPE_IIV) && isRestricted && isSideSlot) return false;
|
||||
return !((shape == ROOMSHAPE_IH || shape == ROOMSHAPE_IIH) && isRestricted && !isSideSlot);
|
||||
}
|
||||
|
||||
// 009af620 The cell a door slot of shape at position leads into, or none when the shape lacks the slot. An L shape's
|
||||
// two slots beside its missing corner lead into that corner.
|
||||
XY LevelGenerator::get_door_target_position(XY position, RoomShape shape, int doorSlot, ThinShapes thinShapes)
|
||||
{
|
||||
if (!has_shape_slot(shape, doorSlot, thinShapes)) return XY_NONE;
|
||||
|
||||
XY size = SHAPE_SIZES[shape];
|
||||
std::array<XY, DOOR_SLOT_COUNT> targets = {
|
||||
{{-1, 0}, {0, -1}, {size.x, 0}, {0, size.y}, {-1, 1}, {1, -1}, {size.x, 1}, {1, size.y}}};
|
||||
XY missing = shape == ROOMSHAPE_LTL ? XY{0, 0}
|
||||
: shape == ROOMSHAPE_LTR ? XY{1, 0}
|
||||
: shape == ROOMSHAPE_LBL ? XY{0, 1}
|
||||
: XY{1, 1};
|
||||
bool isIntoMissing = (shape == ROOMSHAPE_LTL && (doorSlot == DOOR_LEFT0 || doorSlot == DOOR_UP0)) ||
|
||||
(shape == ROOMSHAPE_LTR && (doorSlot == DOOR_RIGHT0 || doorSlot == DOOR_UP1)) ||
|
||||
(shape == ROOMSHAPE_LBL && (doorSlot == DOOR_DOWN0 || doorSlot == DOOR_LEFT1)) ||
|
||||
(shape == ROOMSHAPE_LBR && (doorSlot == DOOR_RIGHT1 || doorSlot == DOOR_DOWN1));
|
||||
|
||||
return position + (isIntoMissing ? missing : targets[doorSlot]);
|
||||
}
|
||||
|
||||
// 009af3f0 The cell of shape at position that a door slot is on, or none when the shape lacks the slot.
|
||||
XY LevelGenerator::get_door_source_position(XY position, RoomShape shape, int doorSlot)
|
||||
{
|
||||
if (shape == ROOMSHAPE_NULL || !has_shape_slot(shape, doorSlot, THIN_SHAPES_RESTRICTED)) return XY_NONE;
|
||||
return get_door_target_position(position, shape, doorSlot, THIN_SHAPES_RESTRICTED) -
|
||||
DIRECTIONS[doorSlot % DIRECTION_COUNT];
|
||||
}
|
||||
|
||||
// 009afdb0 The cells a shape covers from its top left cell, none for a shape the game does not have.
|
||||
std::span<const XY> LevelGenerator::get_room_placement_offsets(RoomShape shape)
|
||||
{
|
||||
return shape >= 0 && shape < ROOMSHAPE_ANY ? SHAPE_CELLS[shape] : std::span<const XY>{};
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
#pragma once
|
||||
|
||||
#include "classes.h"
|
||||
#include "room_config.h"
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <set>
|
||||
#include <span>
|
||||
#include <vector>
|
||||
|
||||
constexpr int LEVEL_GRID_WIDTH = 13;
|
||||
constexpr int LEVEL_GRID_CELLS = LEVEL_GRID_WIDTH * LEVEL_GRID_WIDTH;
|
||||
constexpr int DIRECTION_COUNT = 4;
|
||||
constexpr uint32_t ROOM_SHAPES_ALL = (1 << ROOMSHAPE_ANY) - 1;
|
||||
|
||||
// The door slots of a room's door mask, the second of each side being the far half of a big room.
|
||||
enum DoorSlot : int
|
||||
{
|
||||
DOOR_NONE = -1,
|
||||
DOOR_LEFT0,
|
||||
DOOR_UP0,
|
||||
DOOR_RIGHT0,
|
||||
DOOR_DOWN0,
|
||||
DOOR_LEFT1,
|
||||
DOOR_UP1,
|
||||
DOOR_RIGHT1,
|
||||
DOOR_DOWN1,
|
||||
DOOR_SLOT_COUNT
|
||||
};
|
||||
|
||||
// Whether a door slot a corridor shape lacks still counts, as it does when a room checks what touches it.
|
||||
enum ThinShapes
|
||||
{
|
||||
THIN_SHAPES_RESTRICTED,
|
||||
THIN_SHAPES_IGNORED
|
||||
};
|
||||
|
||||
// Which shapes a candidate room may take: the floor's own shapes at their odds, or any allowed shape.
|
||||
enum CandidateShapes
|
||||
{
|
||||
CANDIDATE_SHAPES_ROLLED,
|
||||
CANDIDATE_SHAPES_ANY
|
||||
};
|
||||
|
||||
// Whether placing a boss room looks for a new dead end, or takes the room an XL floor's first boss room left beside it.
|
||||
enum BossRoomPick
|
||||
{
|
||||
BOSS_ROOM_NEXT,
|
||||
BOSS_ROOM_DETERMINE
|
||||
};
|
||||
|
||||
// A cell of the 13x13 floor grid, (-1, -1) for none.
|
||||
struct XY
|
||||
{
|
||||
int x = -1;
|
||||
int y = -1;
|
||||
|
||||
bool operator==(const XY&) const = default;
|
||||
XY operator+(XY other) const { return {x + other.x, y + other.y}; }
|
||||
XY operator-(XY other) const { return {x - other.x, y - other.y}; }
|
||||
int ToGridIdx() const;
|
||||
static XY NewFromGridIdx(int gridIdx);
|
||||
};
|
||||
|
||||
constexpr XY XY_NONE{};
|
||||
|
||||
// A room of a layout being grown: its top left cell and shape, the doors it has toward its neighbours, and how it
|
||||
// joined the layout (the parent's door slot and side, the cell it entered through and its distance from the start).
|
||||
// A secret room is never counted as a neighbour when an end room grows.
|
||||
// Construction (007381b0), copies and destruction (007507d0, 007527b0, 007529c0, 00752e40, 009b1e40, 009b1f00) are
|
||||
// the defaults.
|
||||
struct LevelGenerator_Room
|
||||
{
|
||||
std::set<int> neighbors;
|
||||
XY linkPos;
|
||||
XY position{0, 0};
|
||||
RoomShape shape = ROOMSHAPE_1x1;
|
||||
int connectDirection = -1;
|
||||
int connectDoorSlot = DOOR_NONE;
|
||||
int distanceFromStart = 0;
|
||||
int generationIndex = 0;
|
||||
uint32_t doors = 0;
|
||||
bool isDeadEnd = false;
|
||||
bool isSecret = false;
|
||||
};
|
||||
|
||||
// How a layout grows: the rooms to place past the start, the dead ends it must end with, the shapes the floor's rooms
|
||||
// come in, and the floor's kind (XL, the Dark Room and Chest's chapter, the Void).
|
||||
struct GenerationSettings
|
||||
{
|
||||
uint32_t allowedShapes = ROOM_SHAPES_ALL;
|
||||
int deadEndCount = 0;
|
||||
int roomCount = 0;
|
||||
bool isChapter6 = false;
|
||||
bool isVoid = false;
|
||||
bool isXL = false;
|
||||
};
|
||||
|
||||
// Grows a floor's layout on the 13x13 grid from the start room, deterministically from its seed: rooms branch out by
|
||||
// a queue of candidates, dead ends are sorted farthest first, then the special rooms take dead ends (grown to their
|
||||
// shapes) or the best empty cells.
|
||||
class LevelGenerator
|
||||
{
|
||||
public:
|
||||
std::array<int, LEVEL_GRID_CELLS> roomMap{};
|
||||
std::array<bool, LEVEL_GRID_CELLS> blockedPositions{};
|
||||
std::vector<LevelGenerator_Room> rooms;
|
||||
std::vector<int> deadEnds;
|
||||
std::vector<int> nonDeadEnds;
|
||||
RNG rng{};
|
||||
uint32_t allowedShapes = ROOM_SHAPES_ALL;
|
||||
int nextBossRoomIdx = -1;
|
||||
int numBossRooms = 0;
|
||||
bool isChapter6 = false;
|
||||
bool isVoid = false;
|
||||
bool isXL = false;
|
||||
|
||||
explicit LevelGenerator(uint32_t seed);
|
||||
|
||||
void Generate(const GenerationSettings& settings, const LevelGenerator_Room& startRoom);
|
||||
LevelGenerator_Room* CreateRoom(const LevelGenerator_Room& room);
|
||||
bool try_add_dead_end(const std::set<int>* excludedCells);
|
||||
bool add_dead_end();
|
||||
LevelGenerator_Room* GetNewEndRoom(RoomShape shape, uint32_t possibleDoors);
|
||||
void DetermineBossRoom(RoomShape shape, uint32_t possibleDoors);
|
||||
LevelGenerator_Room* place_boss_room(RoomShape shape, uint32_t possibleDoors, BossRoomPick pick);
|
||||
LevelGenerator_Room* place_secret_room(const std::set<int>& excludedCells);
|
||||
LevelGenerator_Room* try_place_room(const std::set<int>* doorCells);
|
||||
std::vector<LevelGenerator_Room*> get_all_rooms();
|
||||
|
||||
void block_cell(XY position);
|
||||
void block_room_area(const LevelGenerator_Room& room);
|
||||
void block_cells_near_rooms(const LevelGenerator& other);
|
||||
void block_unused_door_cells(const LevelGenerator_Room& room, uint32_t doorMask);
|
||||
|
||||
static bool has_shape_slot(RoomShape shape, int doorSlot, ThinShapes thinShapes);
|
||||
static XY get_door_source_position(XY position, RoomShape shape, int doorSlot);
|
||||
static XY get_door_target_position(XY position, RoomShape shape, int doorSlot, ThinShapes thinShapes);
|
||||
static std::span<const XY> get_room_placement_offsets(RoomShape shape);
|
||||
|
||||
private:
|
||||
void generate_rooms(int roomCount, const LevelGenerator_Room& startRoom);
|
||||
std::vector<LevelGenerator_Room> get_neighbor_candidates(int generationIndex, CandidateShapes candidateShapes);
|
||||
LevelGenerator_Room& place_room(const LevelGenerator_Room& room);
|
||||
bool can_place_room(XY position, RoomShape shape);
|
||||
bool is_placement_valid(XY position, RoomShape shape);
|
||||
int count_neighbor_rooms(XY position);
|
||||
bool try_resize_room(LevelGenerator_Room& room, RoomShape shape, uint32_t possibleDoors);
|
||||
void update_room_neighbors(LevelGenerator_Room& room);
|
||||
void mark_dead_ends();
|
||||
void update_dead_end_lists();
|
||||
};
|
||||
+10
-3
@@ -1,6 +1,7 @@
|
||||
#include "classes.h"
|
||||
#include "data.h"
|
||||
#include "gl.h"
|
||||
#include "kage_sound.h"
|
||||
#include "lua_engine.h"
|
||||
#include "manager.h"
|
||||
#include "platform.h"
|
||||
@@ -13,6 +14,7 @@
|
||||
constexpr const char* GAME_VERSION = "J460";
|
||||
constexpr const char* LOCALHOST_FLAG = "--localhost_match";
|
||||
constexpr const char* RESOURCES_FLAG = "--resources";
|
||||
constexpr const char* MUTE_FLAG = "--mute";
|
||||
constexpr const char* LOG_FILE = "log.txt";
|
||||
constexpr const char* LOCALHOST_LOG = "localhost/log_";
|
||||
constexpr const char* CLAMP_COLOR_EXTENSION = "GL_ARB_color_buffer_float";
|
||||
@@ -74,10 +76,15 @@ int IsaacMain(int argc, uint8_t** argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The Linux entry point: "--resources <dir>" says where the imported game files are, then the game's own main runs.
|
||||
// The Linux entry point: "--resources <dir>" says where the imported game files are, "--mute" plays nothing, then the
|
||||
// game's own main runs.
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
for (int i = 1; i + 1 < argc; i++)
|
||||
if (std::strcmp(argv[i], RESOURCES_FLAG) == 0) dataDirectory = std::string(argv[i + 1]) + "/";
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
if (std::strcmp(argv[i], MUTE_FLAG) == 0) KAGE::Sound::manager.isMuted = true;
|
||||
else if (std::strcmp(argv[i], RESOURCES_FLAG) == 0 && i + 1 < argc)
|
||||
dataDirectory = std::string(argv[i + 1]) + "/";
|
||||
}
|
||||
return IsaacMain(argc, (uint8_t**)argv);
|
||||
}
|
||||
+186
-9
@@ -188,6 +188,22 @@ constexpr const char* SCREENSHOTS_FOLDER = "screenshots";
|
||||
constexpr int MUSIC_TITLE_REPENTANCE = 63;
|
||||
// The stage bar's icon for a stage not reached.
|
||||
constexpr int STAGE_ICON_EMPTY = 17;
|
||||
// The rerun unlock, which keeps a slot's last run to play again.
|
||||
constexpr int ACHIEVEMENT_RERUN = 337;
|
||||
// The loading screen's image pairs, one per seed numbered from 1, with a set of its own for the greed modes.
|
||||
constexpr uint32_t LOAD_IMAGE_COUNT = 56;
|
||||
constexpr uint32_t LOAD_IMAGE_GREED_COUNT = 20;
|
||||
constexpr size_t LOAD_IMAGE_PATH_SIZE = 128;
|
||||
constexpr const char* LOAD_IMAGE_PATHS[] = {"gfx/ui/loadimages/loadimages-%03u.png",
|
||||
"gfx/ui/loadimages/loadimages-%03u_2.png"};
|
||||
constexpr const char* LOAD_IMAGE_GREED_PATHS[] = {"gfx/ui/loadimages/greedmode/loadimages-g%03u.png",
|
||||
"gfx/ui/loadimages/greedmode/loadimages-g%03u_2.png"};
|
||||
// The fart sounds seed's farts: the plain one, and one in twenty times the gurgling one, drawn from their own xorshift.
|
||||
constexpr int SOUND_FART = 37;
|
||||
constexpr int SOUND_FART_GURG = 301;
|
||||
constexpr uint32_t FART_GURG_CHANCE = 20;
|
||||
constexpr uint32_t FART_RNG_SEED = 0x69696969;
|
||||
constexpr uint32_t FART_RNG_SHIFT_INDEX = 11;
|
||||
// The popups drawn over everything else.
|
||||
constexpr int POPUP_LAYER_TOP = 3;
|
||||
constexpr int CONTROLLER_POPUP_PRIORITY = 3;
|
||||
@@ -487,6 +503,16 @@ static void shaders_load()
|
||||
log_printf(LOG_INFO, "%s", SHADER_BANNER);
|
||||
}
|
||||
|
||||
// Drops the daily challenge, so the run is not one.
|
||||
// Its rules (ChallengeParam::Reset) reset with DailyChallenge's takeover, as classes.h holds them as bytes.
|
||||
static void daily_challenge_clear(DailyChallenge& daily)
|
||||
{
|
||||
daily._id = 0;
|
||||
daily._seed = 0;
|
||||
daily._specialDailyId = 0;
|
||||
daily._isPractice = false;
|
||||
}
|
||||
|
||||
// 009aa040 Starts the game once the engine runs: creates the Lua engine, seeds the global random generator, listens to
|
||||
// the window, builds the shaders, then creates and initializes the manager and fits the view. The command line then
|
||||
// queues a debug run, or the intro cutscene plays.
|
||||
@@ -537,11 +563,7 @@ void IsaacStartup(int argc, uint8_t** argv)
|
||||
manager.isRerunAvailable = false;
|
||||
manager.isStartingFromRerun = false;
|
||||
manager.isDebugStart = true;
|
||||
// The daily challenge's rules reset with DailyChallenge's takeover, as classes.h holds them as bytes.
|
||||
manager.dailyChallenge._id = 0;
|
||||
manager.dailyChallenge._seed = 0;
|
||||
manager.dailyChallenge._specialDailyId = 0;
|
||||
manager.dailyChallenge._isPractice = false;
|
||||
daily_challenge_clear(manager.dailyChallenge);
|
||||
manager.startStage = arguments.stage;
|
||||
manager.startStageType = arguments.stageType;
|
||||
manager.startRoomPath = arguments.roomPath;
|
||||
@@ -1114,7 +1136,7 @@ void Manager::SetSaveSlot(uint32_t slot)
|
||||
if (persistentGameData.Load(platform.userDataDirectory + "persistentgamedata" + std::to_string(slot) + ".dat"))
|
||||
{
|
||||
optionsConfig.isTryImportSave = false;
|
||||
FUN_00959fa0();
|
||||
LoadGameState(slot);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1125,6 +1147,61 @@ void Manager::SetSaveSlot(uint32_t slot)
|
||||
currentSaveSlot = slot;
|
||||
}
|
||||
|
||||
// 00958aa0 Queues a new run on a character, challenge, seeds and difficulty: no saved run, rerun, debug run or daily.
|
||||
void Manager::StartNewGame(int playerType, int challenge, Seeds seeds, int difficulty)
|
||||
{
|
||||
startPlayerType = playerType;
|
||||
startChallenge = challenge;
|
||||
isRerunAvailable = false;
|
||||
isStartingFromRerun = false;
|
||||
isDebugStart = false;
|
||||
startSeeds = std::move(seeds);
|
||||
startDifficulty = difficulty;
|
||||
daily_challenge_clear(dailyChallenge);
|
||||
isStarting = true;
|
||||
isNetworkPlay = false;
|
||||
consecutiveResetCount = 0;
|
||||
}
|
||||
|
||||
// 00959fa0 Loads a save slot's saved run, or when there is none and reruns are unlocked (or a daily or debug run is
|
||||
// on) its rerun, deleting a file that does not read. A run saved with mods on (or off) only continues the same way.
|
||||
// Steam Cloud is offline, so the files are always the local ones. The mods message names the rerun file, as it did.
|
||||
void Manager::LoadGameState(uint32_t slot)
|
||||
{
|
||||
std::string rerunPath = platform.userDataDirectory + "rep+rerunstate" + std::to_string(slot) + ".dat";
|
||||
std::vector<uint8_t> file;
|
||||
|
||||
gamestate.Clear();
|
||||
log_printf(LOG_INFO, "Loading GameState %u from local folder!\n", slot);
|
||||
gamestate.savePath = platform.userDataDirectory + "gamestate" + std::to_string(slot) + ".dat";
|
||||
bool isSaveRead = file_load(gamestate.savePath, file);
|
||||
if (isSaveRead && gamestate.read(file))
|
||||
{
|
||||
gamestate.isSaveAvailable = true;
|
||||
gamestate.rerunPath = rerunPath;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isSaveRead) gamestate.Delete();
|
||||
bool isRerunKept = persistentGameData.achievements[ACHIEVEMENT_RERUN] ||
|
||||
(state == MANAGER_STATE_GAME && g_game && (g_game->dailyChallenge._id != 0 || g_game->isDebug));
|
||||
if (isRerunKept)
|
||||
{
|
||||
gamestate.rerunPath = rerunPath;
|
||||
if (file_load(rerunPath, file))
|
||||
{
|
||||
if (gamestate.read_rerun(file)) gamestate.isRerunAvailable = true;
|
||||
else gamestate.DeleteRerun();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool isModded = std::ranges::any_of(modManager.mods, [](auto& mod) { return mod->isLoaded; });
|
||||
if (gamestate.isModded == isModded) return;
|
||||
log_printf(LOG_INFO, "Cannot continue a game that doesn't have the same modding state (%s)!\n", rerunPath.c_str());
|
||||
gamestate.Clear();
|
||||
}
|
||||
|
||||
// 00959d00 Goes to the queued menu: unloads the current state, creates and starts the menus the first time, then shows
|
||||
// the menu with the queued fade in.
|
||||
// Netplay is offline, so there is no online run to leave or session to reset.
|
||||
@@ -1145,11 +1222,58 @@ void Manager::start_pending_menu()
|
||||
isMenuPending = false;
|
||||
}
|
||||
|
||||
// 00959720 Starts the queued run.
|
||||
// 00923450 Readies the nightmares for a new run: every stage icon empty and a new order.
|
||||
// The original also rewinds the next nightmare (+0x360), which NightmareScene does not name yet.
|
||||
static void nightmare_scene_restart(NightmareScene& scene)
|
||||
{
|
||||
scene.stageIcons.fill(STAGE_ICON_EMPTY);
|
||||
scene.order_shuffle();
|
||||
}
|
||||
|
||||
// 00959720 Starts the queued run on an even frame: unloads the menus, makes the game the first time, readies the
|
||||
// nightmares, then continues the saved run, starts the rerun, the daily, the debug run or a new run, and leaves the run
|
||||
// to save on exit.
|
||||
// Netplay is offline, so there is no lobby to trim and no online run to start.
|
||||
void Manager::start_pending_game()
|
||||
{
|
||||
if (!isStarting) return;
|
||||
reconstruction_missing("Manager::start_pending_game 00959720");
|
||||
|
||||
if (framecount & 1) framecount++;
|
||||
unload_state();
|
||||
if (!g_game)
|
||||
{
|
||||
g_game = new Game();
|
||||
Game::LoadConfigXmls();
|
||||
}
|
||||
state = MANAGER_STATE_GAME;
|
||||
nightmare_scene_restart(nightmareScene);
|
||||
|
||||
if (isRerunAvailable || isStartingFromRerun)
|
||||
{
|
||||
startPlayerType = gamestate.playerType;
|
||||
startChallenge = gamestate.challenge;
|
||||
startDifficulty = gamestate.difficulty;
|
||||
startSeeds = gamestate.seeds;
|
||||
if (isRerunAvailable)
|
||||
{
|
||||
isRerunAvailable = false;
|
||||
reconstruction_missing("Game::restore_game_state 006f8140, continuing the saved run");
|
||||
}
|
||||
else
|
||||
{
|
||||
isStartingFromRerun = false;
|
||||
reconstruction_missing("Game::StartFromRerunState 006f72f0");
|
||||
}
|
||||
}
|
||||
else if (dailyChallenge._id != 0)
|
||||
reconstruction_missing("Game::StartDailyChallenge 006f6dd0, on the daily's character DailyChallenge holds as bytes");
|
||||
else if (isDebugStart) reconstruction_missing("Game::StartDebug 006f7750");
|
||||
else reconstruction_missing("Game::Start 006f5320");
|
||||
|
||||
if ((int)framecount % 2 == 1) framecount++;
|
||||
isStarting = false;
|
||||
isSaveOnExit = true;
|
||||
isPersistentDataWritable = false;
|
||||
}
|
||||
|
||||
// Whether the cutscene or the nightmare the manager shows has ended.
|
||||
@@ -1378,11 +1502,64 @@ void Manager::Render()
|
||||
graphics.Present(KAGE::Graphics::PRESENT_FINISH);
|
||||
}
|
||||
|
||||
// 00954b40 Makes the first device with a button just pressed the active one, in a run also player one's and the
|
||||
// menus', true when there was one.
|
||||
bool input_poll_active_device()
|
||||
{
|
||||
KAGE::Input::Manager& input = KAGE::Input::manager;
|
||||
|
||||
for (int i = 0; i < input.get_device_count(); i++)
|
||||
{
|
||||
std::shared_ptr<KAGE::Input::InputDevice> device = input.get_device(i);
|
||||
if (!device || device->button_triggered_get() == KAGE::Input::BUTTON_NONE) continue;
|
||||
|
||||
g_manager->activeControllerIndex = device->id;
|
||||
if (g_manager->state == MANAGER_STATE_GAME)
|
||||
{
|
||||
g_game->playerManager.GetPlayer(0)->SetControllerIndex(device->id, 1);
|
||||
g_menuControllerIndex = device->id;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// 00951f60 Loads the loading screen's two images for a seed, from the greed modes' set in those, and notes when.
|
||||
void loading_images_load(uint32_t seed)
|
||||
{
|
||||
Manager& manager = *g_manager;
|
||||
bool isGreed = manager.selectedDifficulty == DIFFICULTY_GREED || manager.selectedDifficulty == DIFFICULTY_GREEDIER;
|
||||
uint32_t number = seed % (isGreed ? LOAD_IMAGE_GREED_COUNT : LOAD_IMAGE_COUNT) + 1;
|
||||
char path[LOAD_IMAGE_PATH_SIZE];
|
||||
|
||||
for (size_t i = 0; i < manager.loadImages.size(); i++)
|
||||
{
|
||||
std::snprintf(path, sizeof(path), isGreed ? LOAD_IMAGE_GREED_PATHS[i] : LOAD_IMAGE_PATHS[i], number);
|
||||
manager.loadImages[i] = nullptr;
|
||||
manager.loadImages[i] = Manager::LoadImage(path);
|
||||
}
|
||||
manager.loadImagesTime = GetTimeNs() / NS_PER_MS;
|
||||
}
|
||||
|
||||
// 00956780 Turns a sound into a fart in a run with the fart sounds seed, one in twenty times the gurgling one.
|
||||
void seed_fart_sound_override(int* soundId)
|
||||
{
|
||||
static RNG fartRng = []
|
||||
{
|
||||
RNG rng = {};
|
||||
rng.SetSeed(FART_RNG_SEED, FART_RNG_SHIFT_INDEX);
|
||||
return rng;
|
||||
}();
|
||||
|
||||
if (!g_game || !g_game->seedEffects.HasSeedEffect(SEED_FART_SOUNDS)) return;
|
||||
*soundId = SOUND_FART;
|
||||
if (fartRng.Next() % FART_GURG_CHANCE == 0) *soundId = SOUND_FART_GURG;
|
||||
}
|
||||
|
||||
// Not reconstructed yet: each stops the game where it is reached.
|
||||
Manager::~Manager() { reconstruction_missing("Manager::destructor 00951160"); }
|
||||
void Manager::update_ingame_input() { reconstruction_missing("Manager::update_ingame_input 006fa540"); }
|
||||
void Manager::render_button_sprite(int, Vector) { reconstruction_missing("Manager::render_button_sprite 0095ad30"); }
|
||||
void Manager::StartNewGame(int, int, Seeds, int) { reconstruction_missing("Manager::StartNewGame 00958aa0"); }
|
||||
void Manager::RestartGame() { reconstruction_missing("Manager::RestartGame 00958cb0"); }
|
||||
void Manager::save_game_state() { reconstruction_missing("Manager::save_game_state 00958ed0"); }
|
||||
void Manager::apply_device_key_config(int) { reconstruction_missing("Manager::apply_device_key_config 0095b180"); }
|
||||
+6
-1
@@ -5,6 +5,7 @@
|
||||
#include "cutscene.h"
|
||||
#include "entity_config.h"
|
||||
#include "font.h"
|
||||
#include "game_state.h"
|
||||
#include "info_display.h"
|
||||
#include "item_config.h"
|
||||
#include "kage_graphics.h"
|
||||
@@ -72,7 +73,7 @@ class Manager
|
||||
{
|
||||
public:
|
||||
PersistentGameData persistentGameData;
|
||||
GameState gamestate{};
|
||||
GameState gamestate;
|
||||
Cutscene cutsceneManager;
|
||||
NightmareScene nightmareScene;
|
||||
AchievementOverlay achievementOverlay{};
|
||||
@@ -197,6 +198,10 @@ public:
|
||||
void unload_state();
|
||||
static void save_game_state();
|
||||
void SetSaveSlot(uint32_t slot);
|
||||
void LoadGameState(uint32_t slot);
|
||||
};
|
||||
|
||||
void IsaacStartup(int argc, uint8_t** argv);
|
||||
bool input_poll_active_device();
|
||||
void loading_images_load(uint32_t seed);
|
||||
void seed_fart_sound_override(int* soundId);
|
||||
+4
-11
@@ -106,7 +106,7 @@ struct CompletionMarkLayer
|
||||
constexpr int COMPLETION_MARK_COUNT = 12;
|
||||
constexpr CompletionMarkLayer COMPLETION_MARK_LAYERS[COMPLETION_MARK_COUNT] = {
|
||||
{0, 1}, {1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6}, {6, 7}, {7, 8}, {9, 9}, {12, 0}, {13, 10}, {14, 11}};
|
||||
constexpr int COMPLETION_PLAYER_TYPE_MAX = 40;
|
||||
constexpr uint32_t COMPLETION_PLAYER_TYPE_MAX = COMPLETION_PLAYER_TYPE_COUNT - 1;
|
||||
constexpr int COMPLETION_TAINTED_MIN = 21;
|
||||
constexpr int COMPLETION_TAINTED_FRAMES = 5;
|
||||
constexpr int MARK_NORMAL = 1;
|
||||
@@ -333,13 +333,6 @@ bool Menu_Character_Entry::IsCharacterAvailable() const
|
||||
return is_player_available(playerType);
|
||||
}
|
||||
|
||||
// The event counter a completion mark of a character is kept in.
|
||||
static int completion_mark_counter([[maybe_unused]] int characterId, [[maybe_unused]] int completionType)
|
||||
{
|
||||
reconstruction_missing("CompletionWidget::Update 00425130: COMPLETION_MARKS, which persistent_game_data.cpp keeps "
|
||||
"to itself");
|
||||
}
|
||||
|
||||
// 00424ef0 Loads the widget, on the pause screen's sheet for that style, playing, with no marks counted.
|
||||
void CompletionWidget::Load(CompletionStyle style)
|
||||
{
|
||||
@@ -363,12 +356,12 @@ void CompletionWidget::Update()
|
||||
markCount = 0;
|
||||
for (const CompletionMarkLayer& mark : COMPLETION_MARK_LAYERS)
|
||||
{
|
||||
if (characterId > COMPLETION_PLAYER_TYPE_MAX)
|
||||
if ((uint32_t)characterId > COMPLETION_PLAYER_TYPE_MAX)
|
||||
{
|
||||
anm2.SetLayerFrame(mark.layer, 0);
|
||||
continue;
|
||||
}
|
||||
int flags = data.eventCounters[completion_mark_counter(characterId, mark.completionType)];
|
||||
int flags = data.eventCounters[COMPLETION_MARKS[characterId][mark.completionType].counter];
|
||||
int frame = flags & MARK_HARD ? 2 : flags & MARK_NORMAL;
|
||||
if (frame == 0) frame = flags & MARK_ONLINE_HARD ? 2 : flags & MARK_ONLINE_NORMAL ? 1 : 0;
|
||||
if (mark.layer == 0 && characterId >= COMPLETION_TAINTED_MIN) frame += COMPLETION_TAINTED_FRAMES;
|
||||
@@ -659,7 +652,7 @@ void Menu_Character::run_start()
|
||||
PersistentGameData& data = manager.persistentGameData;
|
||||
|
||||
if (selectedCharacterID == MENU_ID_EDEN) data.IncreaseEventCounter(EVENT_EDEN_TOKENS, -1);
|
||||
if (manager.gamestate._isSaveAvailable)
|
||||
if (manager.gamestate.isSaveAvailable)
|
||||
data.IncreaseEventCounter(EVENT_STREAK_COUNTER, -data.eventCounters[EVENT_STREAK_COUNTER]);
|
||||
progress_save();
|
||||
int playerType = GetPlayerTypeFromMenuID(selectedCharacterID, characterMenuShown);
|
||||
|
||||
+1
-20
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "anm2.h"
|
||||
#include "completion_widget.h"
|
||||
#include "game.h"
|
||||
#include "kage_graphics.h"
|
||||
#include <array>
|
||||
@@ -37,13 +38,6 @@ enum SeedUnlockPage : int
|
||||
SEED_UNLOCK_DISAPPEARING
|
||||
};
|
||||
|
||||
// Whether the completion widget sits on the menus' paper or the pause screen's.
|
||||
enum CompletionStyle
|
||||
{
|
||||
COMPLETION_STYLE_MENU,
|
||||
COMPLETION_STYLE_PAUSE
|
||||
};
|
||||
|
||||
// Whether the wheel draws its portraits, or only the page, as the page snapshot does.
|
||||
enum WheelPortraits
|
||||
{
|
||||
@@ -78,19 +72,6 @@ struct WheelPortrait
|
||||
int menuId;
|
||||
};
|
||||
|
||||
// A character's completion marks (CompletionWidget): the widget's sheet with a layer per mark, each on the frame of the
|
||||
// difficulty it was earned on, and how many are earned.
|
||||
struct CompletionWidget
|
||||
{
|
||||
ANM2 anm2;
|
||||
int characterId = 0;
|
||||
int markCount = 0;
|
||||
|
||||
void Load(CompletionStyle style);
|
||||
void Update();
|
||||
void Render(Vector position, Vector scale);
|
||||
};
|
||||
|
||||
// Construction and destruction (00946e70, 00947070) are the defaults.
|
||||
// The character select menu (Menu_Character): a wheel of portraits around the selected character's page, the
|
||||
// difficulty, the seed entry page beside it, the special seeds widget, and the page swap to the tainted characters.
|
||||
|
||||
+7
-7
@@ -31,7 +31,7 @@ constexpr uint32_t CLEAR_ARGB = 0;
|
||||
static bool is_continue_available()
|
||||
{
|
||||
GameState& state = g_manager->gamestate;
|
||||
return state._isSaveAvailable || state._isRerunAvailable;
|
||||
return state.isSaveAvailable || state.isRerunAvailable;
|
||||
}
|
||||
|
||||
// 00980c20 Loads the menu and its continue widget (hidden, on its last frame), makes the surface the saved run is drawn
|
||||
@@ -68,7 +68,7 @@ void Menu_Game::Reset()
|
||||
{
|
||||
gameMenuSprite.Play(ANIMATION_IDLE);
|
||||
selectedElement = GAME_NEW_RUN;
|
||||
if (g_manager->gamestate._isSaveAvailable)
|
||||
if (g_manager->gamestate.isSaveAvailable)
|
||||
{
|
||||
selectedElement = GAME_CONTINUE;
|
||||
PreRenderContinueImg();
|
||||
@@ -87,7 +87,7 @@ void Menu_Game::PreRenderContinueImg()
|
||||
void Menu_Game::run_start()
|
||||
{
|
||||
Manager& manager = *g_manager;
|
||||
bool isSaveAvailable = manager.gamestate._isSaveAvailable;
|
||||
bool isSaveAvailable = manager.gamestate.isSaveAvailable;
|
||||
|
||||
manager.isDebugStart = false;
|
||||
manager.isRerunAvailable = isSaveAvailable;
|
||||
@@ -124,8 +124,8 @@ void Menu_Game::selection_confirm()
|
||||
{
|
||||
case GAME_NEW_RUN: menus.push_menu(MENU_CHARACTER); break;
|
||||
case GAME_CONTINUE:
|
||||
manager.selectedDifficulty = manager.gamestate._difficulty;
|
||||
reconstruction_missing("Menu_Game::Update: the saved run's Seeds, which GameState holds as bytes");
|
||||
manager.selectedDifficulty = manager.gamestate.difficulty;
|
||||
menus.seedsObject = manager.gamestate.seeds;
|
||||
menus.start_game(kcolor_argb(BLACK_ARGB));
|
||||
break;
|
||||
case GAME_ONLINE:
|
||||
@@ -145,7 +145,7 @@ void Menu_Game::continue_widget_update()
|
||||
ANM2& widget = continueWidgetSprite;
|
||||
|
||||
if (selectedElement == GAME_CONTINUE && !is_continue_available()) selectedElement = GAME_NEW_RUN;
|
||||
else if (selectedElement == GAME_CONTINUE && !state._isRerunAvailable)
|
||||
else if (selectedElement == GAME_CONTINUE && !state.isRerunAvailable)
|
||||
{
|
||||
if (widget.IsFinished(ANIMATION_APPEAR)) widget.Play(ANIMATION_IDLE);
|
||||
else if (widget.IsFinished(ANIMATION_DISAPPEAR))
|
||||
@@ -203,7 +203,7 @@ void Menu_Game::Update()
|
||||
continue_widget_update();
|
||||
|
||||
GameState& state = manager.gamestate;
|
||||
int continueFrame = state._isSaveAvailable ? CONTINUE_SAVED : state._isRerunAvailable ? CONTINUE_RERUN : CONTINUE_EMPTY;
|
||||
int continueFrame = state.isSaveAvailable ? CONTINUE_SAVED : state.isRerunAvailable ? CONTINUE_RERUN : CONTINUE_EMPTY;
|
||||
gameMenuSprite.SetLayerFrame(CURSOR_LAYER, selectedElement);
|
||||
gameMenuSprite.SetLayerFrame(CONTINUE_LAYER, continueFrame);
|
||||
LayerState* modsKey = gameMenuSprite.GetLayer(MODS_KEY_LAYER);
|
||||
|
||||
+15
-2
@@ -333,7 +333,7 @@ void MenuManager::start_game(KColor fadeColor)
|
||||
manager.musicManager.Crossfade(isCharacterMenuShown ? MUSIC_JINGLE_GAME_START_ALT : MUSIC_JINGLE_GAME_START,
|
||||
MUSIC_FADE_RATE);
|
||||
if (seedsObject.gameStartSeed == 0) log_printf(LOG_ASSERT, "Error: Game Start Seed was not set.\n");
|
||||
loading_images_load();
|
||||
loading_images_load(seedsObject.gameStartSeed);
|
||||
}
|
||||
|
||||
// Eases the view toward the selected menu's place, a tenth of the way and at least a point each frame, snapping
|
||||
@@ -442,6 +442,19 @@ void MenuManager::menu_update()
|
||||
}
|
||||
}
|
||||
|
||||
// 006ef410 Moves each component toward the target's by at most the step's, landing on it once within reach.
|
||||
void ColorModState::move_toward(float* target, float* step)
|
||||
{
|
||||
float* components[] = {&_red, &_green, &_blue, &_amount, &_brightness, &_contrast};
|
||||
|
||||
for (size_t i = 0; i < std::size(components); i++)
|
||||
{
|
||||
float& value = *components[i];
|
||||
if (step[i] < std::fabs(value - target[i])) value += target[i] <= value ? -step[i] : step[i];
|
||||
else value = target[i];
|
||||
}
|
||||
}
|
||||
|
||||
// Eases the color modifier toward its target while asked to, stopping once it is there.
|
||||
void MenuManager::color_mod_update()
|
||||
{
|
||||
@@ -683,7 +696,7 @@ SeedsEntry MenuManager::transition_apply(MenuState previous, MenuState state)
|
||||
{
|
||||
reconstruction_missing("MenuManager::SetState 0098aa30: Menu_Mods' changed flag, inlined");
|
||||
g_manager->modManager.Reset();
|
||||
FUN_00959fa0();
|
||||
g_manager->LoadGameState(g_manager->currentSaveSlot);
|
||||
}
|
||||
else if (previous == MENU_SAVE && state == MENU_GAME)
|
||||
{
|
||||
|
||||
@@ -209,6 +209,7 @@ KColor kcolor_make(float red, float green, float blue, float alpha);
|
||||
KColor kcolor_argb(uint32_t argb);
|
||||
Vector vector_add(Vector a, Vector b);
|
||||
bool is_action(ButtonAction action, ActionTest test, int* deviceId = nullptr);
|
||||
bool is_controller_action(int deviceId, ButtonAction action, ActionTest test);
|
||||
bool is_key_repeat(int heldFrames);
|
||||
void menu_sound_play(int sound, int frameDelay);
|
||||
void shader_select(std::string_view shaderName);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "log.h"
|
||||
#include "lua_engine.h"
|
||||
#include "manager.h"
|
||||
#include "pause_screen.h"
|
||||
#include "menu_manager.h"
|
||||
#include "render_passes.h"
|
||||
#include "texture_cache.h"
|
||||
@@ -145,7 +146,7 @@ static bool is_device_action(int deviceId, ButtonAction action, ActionTest test)
|
||||
// The player the pause screen belongs to. Netplay is offline, so it is always a local one.
|
||||
static Entity_Player* pause_player_get()
|
||||
{
|
||||
return g_game->playerManager.GetPlayer(g_game->pauseScreen._playerIdx);
|
||||
return g_game->playerManager.GetPlayer(g_game->pauseScreen.playerIdx);
|
||||
}
|
||||
|
||||
// Lets the paused player choose a controller again: its device lets go of the confirm press, the player loses the
|
||||
@@ -456,7 +457,7 @@ void Menu_Options::option_change(int step)
|
||||
case OPTION_EXTRA_HUD:
|
||||
config.historyHudMode =
|
||||
(ExtraHudStyle)((config.historyHudMode + step + EXTRA_HUD_MODE_COUNT) % EXTRA_HUD_MODE_COUNT);
|
||||
if (is_paused()) HUD::mark_all_slots_dirty(&g_game->hud, 1, 0);
|
||||
if (is_paused()) g_game->hud.mark_all_slots_dirty(HISTORY_REBUILD_ICONS, HISTORY_KEEP_ITEMS);
|
||||
return;
|
||||
case OPTION_HUD_OFFSET:
|
||||
config.hudOffset = std::clamp(slide + config.hudOffset, 0.0f, 1.0f);
|
||||
@@ -527,7 +528,7 @@ void Menu_Options::language_reload()
|
||||
AnmCache::Clear();
|
||||
g_manager->validate_language();
|
||||
if (menus) menus->LoadGraphics();
|
||||
FUN_00954710();
|
||||
graphics_reload();
|
||||
mods.LoadShaders();
|
||||
Manager::unload_configs();
|
||||
mods.LoadModContent();
|
||||
|
||||
+492
@@ -0,0 +1,492 @@
|
||||
#include "minimap.h"
|
||||
#include "game.h"
|
||||
#include "hud.h"
|
||||
#include "level.h"
|
||||
#include "log.h"
|
||||
#include "manager.h"
|
||||
#include "menu_manager.h"
|
||||
#include "menu_options.h"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
|
||||
constexpr const char* SMALL_MAP_ANM2 = "gfx/ui/minimap1.anm2";
|
||||
constexpr const char* LARGE_MAP_ANM2 = "gfx/ui/minimap2.anm2";
|
||||
constexpr const char* ITEM_ICONS_ANM2 = "gfx/ui/mapitemicons.anm2";
|
||||
constexpr const char* HUD_PICKUPS_ANM2 = "gfx/ui/hudpickups.anm2";
|
||||
constexpr const char* ROOM_ICONS_ANM2 = "gfx/ui/minimap_icons.anm2";
|
||||
constexpr const char* QUESTION_MARK_PNG = "gfx/ui/minimap_questionmark.png";
|
||||
constexpr const char* SURFACE_NAME = "Minimap Surface";
|
||||
constexpr const char* ANIMATION_FRAME = "Frame";
|
||||
constexpr const char* ANIMATION_ICONS = "icons";
|
||||
constexpr const char* ANIMATION_CURSES = "curses";
|
||||
constexpr const char* TIME_LABEL = "#MINIMAP_TIME_LABEL";
|
||||
constexpr const char* SCORE_LABEL = "#MINIMAP_SCORE_LABEL";
|
||||
constexpr const char* TIME_WIDEST = " 00:00:00";
|
||||
constexpr const char* SCORE_WIDEST = " 000000";
|
||||
|
||||
constexpr const char* NO_PLAYERS = "PlayerManager::GetPlayer() : There are no players! \n";
|
||||
|
||||
// The two maps' layouts, by MinimapSize.
|
||||
struct MinimapLayout
|
||||
{
|
||||
float iconSize;
|
||||
float cellWidth;
|
||||
float cellHeight;
|
||||
float margin;
|
||||
float gap;
|
||||
int cells;
|
||||
int iconScale;
|
||||
};
|
||||
|
||||
constexpr MinimapLayout MINIMAP_LAYOUTS[MINIMAP_SIZE_COUNT] = {{16, 7, 6, 2, 1, 7, 1}, {32, 16, 14, 4, 1, 13, 4}};
|
||||
|
||||
constexpr float ALPHA_RISE = 0.1f;
|
||||
constexpr float ALPHA_FALL = 0.2f;
|
||||
constexpr float SMALL_FULL_ALPHA = 0.9f;
|
||||
constexpr float OPACITY_STEP = 0.1f;
|
||||
constexpr int TAP_FRAMES = 9;
|
||||
constexpr int SHOW_NAME_FRAMES = 10;
|
||||
constexpr float SHAKE_DIVISOR = 10;
|
||||
constexpr float SHAKE_KEEP = 0.5f;
|
||||
constexpr float RANDOM_SCALE = 2.3283064e-10f;
|
||||
constexpr float HALF_TURN = 3.14f;
|
||||
|
||||
constexpr float HUD_INSET_X = 24;
|
||||
constexpr float HUD_INSET_Y = -14;
|
||||
constexpr float SMALL_RIGHT = 80;
|
||||
constexpr float SMALL_TOP = 16;
|
||||
constexpr float QUESTION_MARK_INSET = 8;
|
||||
constexpr float SMALL_ICONS_X = 53 - 8;
|
||||
constexpr float SMALL_ICONS_Y = 47 + 8;
|
||||
constexpr float LARGE_RIGHT = 24;
|
||||
constexpr float LARGE_TOP = 14;
|
||||
constexpr float LARGE_ICONS_X = 32;
|
||||
constexpr float LARGE_ICONS_Y = 16 + 8;
|
||||
constexpr float DEFAULT_DISPLAYED_SIZE = 47;
|
||||
constexpr float SCORE_HISTORY_ALPHA = 0.5f;
|
||||
constexpr int HISTORY_HUD_ON = 1;
|
||||
constexpr uint32_t WHITE_ARGB = 0xffffffff;
|
||||
|
||||
constexpr int ICON_LIMIT = 7;
|
||||
constexpr int ICON_STACK_START = 4;
|
||||
constexpr float ICON_SPACING = -16;
|
||||
constexpr int CURSE_ICON_COUNT = 9;
|
||||
constexpr int ICON_COMPASS = 0;
|
||||
constexpr int ICON_BLUE_MAP = 1;
|
||||
constexpr int ICON_TREASURE_MAP = 2;
|
||||
constexpr int ICON_RESTOCK = 4;
|
||||
constexpr int ICON_MIND = 5;
|
||||
constexpr int COLLECTIBLE_COMPASS = 21;
|
||||
constexpr int COLLECTIBLE_TREASURE_MAP = 54;
|
||||
constexpr int COLLECTIBLE_BLUE_MAP = 246;
|
||||
constexpr int COLLECTIBLE_MIND = 333;
|
||||
constexpr int COLLECTIBLE_RESTOCK = 376;
|
||||
|
||||
constexpr int STAGE_HOME = 35;
|
||||
constexpr int ROOM_DUNGEON = 16;
|
||||
constexpr int CHALLENGE_SPEED = 22;
|
||||
constexpr int SPEED_TIME_LIMIT = 28800;
|
||||
constexpr int FRAMES_PER_SECOND = 30;
|
||||
constexpr int FRAMES_PER_MINUTE = FRAMES_PER_SECOND * 60;
|
||||
constexpr int FRAMES_PER_HOUR = FRAMES_PER_MINUTE * 60;
|
||||
constexpr int BLINK_PERIOD = 8;
|
||||
constexpr int BLINK_SHOWN = 4;
|
||||
constexpr float SPEED_TINT = 0.5f;
|
||||
constexpr float SCORE_WIDTH_GAP = 0.5f;
|
||||
constexpr float HEART_WIDTH = 6;
|
||||
constexpr float HEARTS_WIDTH_MAX = 72;
|
||||
constexpr float HEARTS_MARGIN = 60;
|
||||
constexpr float HEARTS_INSET = 20;
|
||||
constexpr float EXTRA_LIVES_WIDTH = 16;
|
||||
constexpr float TEXT_DROP = 24;
|
||||
constexpr float TEXT_DROP_INSET = 12;
|
||||
constexpr float TIME_Y = 30;
|
||||
constexpr float SCORE_Y = 46;
|
||||
|
||||
|
||||
// How far the HUD sits in from the screen's edges, from 0 at the edge to 1.
|
||||
static float hud_inset()
|
||||
{
|
||||
return 1 - g_manager->optionsConfig.hudOffset;
|
||||
}
|
||||
|
||||
// The curses the HUD shows: the floor's, the debug ones and those the seeds force, less those the seeds prevent.
|
||||
static uint32_t curses_get()
|
||||
{
|
||||
Game& game = *g_game;
|
||||
return ~Seeds::GetPreventedCurses() & (Seeds::GetForcedCurses() | game.debugCurses | game.curses);
|
||||
}
|
||||
|
||||
// A color that only sets the alpha.
|
||||
static ColorMod alpha_color(float alpha)
|
||||
{
|
||||
ColorMod color = COLOR_DEFAULT;
|
||||
color._tint[3] = alpha;
|
||||
return color;
|
||||
}
|
||||
|
||||
// The quad between four edges.
|
||||
static DestinationQuad quad_make(float left, float top, float right, float bottom)
|
||||
{
|
||||
DestinationQuad quad;
|
||||
quad._topLeft = vector_make(left, top);
|
||||
quad._topRight = vector_make(right, top);
|
||||
quad._bottomLeft = vector_make(left, bottom);
|
||||
quad._bottomRight = vector_make(right, bottom);
|
||||
return quad;
|
||||
}
|
||||
|
||||
// A quad's left and right corners swapped, to draw it mirrored.
|
||||
static void quad_mirror(DestinationQuad& quad)
|
||||
{
|
||||
std::swap(quad._topLeft, quad._topRight);
|
||||
std::swap(quad._bottomLeft, quad._bottomRight);
|
||||
}
|
||||
|
||||
// 0098b5e0 Draws the floor's rooms on the map's surface and measures their bounds.
|
||||
void MinimapConfig::refresh()
|
||||
{
|
||||
reconstruction_missing("Minimap::refresh_room_icons 0098b5e0 on a MinimapConfig, waiting on Level's takeover");
|
||||
}
|
||||
|
||||
// 0098d560 Loads both maps with their layouts and surfaces (sized to fit every cell), the item, pickup and room
|
||||
// icons and the question mark, with the small map showing.
|
||||
void Minimap::Init()
|
||||
{
|
||||
configs[MINIMAP_SIZE_SMALL].mapSprite.Load(SMALL_MAP_ANM2, GRAPHICS_LOAD);
|
||||
configs[MINIMAP_SIZE_LARGE].mapSprite.Load(LARGE_MAP_ANM2, GRAPHICS_LOAD);
|
||||
for (int size = 0; size < MINIMAP_SIZE_COUNT; size++)
|
||||
{
|
||||
MinimapConfig& map = configs[size];
|
||||
const MinimapLayout& layout = MINIMAP_LAYOUTS[size];
|
||||
map.iconSize = vector_make(layout.iconSize, layout.iconSize);
|
||||
map.cellSize = vector_make(layout.cellWidth, layout.cellHeight);
|
||||
map.margin = layout.margin;
|
||||
map.gap = layout.gap;
|
||||
map.columns = layout.cells;
|
||||
map.rows = layout.cells;
|
||||
map.iconScale = layout.iconScale;
|
||||
|
||||
int gap = (int)map.gap;
|
||||
int margins = (int)map.margin * 2;
|
||||
KAGE::Graphics::RenderTargetDesc desc;
|
||||
desc.name = SURFACE_NAME;
|
||||
desc.width = ((int)map.cellSize.x + gap) * map.columns + margins + gap;
|
||||
desc.height = ((int)map.cellSize.y + gap) * map.rows + margins + gap;
|
||||
map.surface = KAGE::Graphics::manager.render_target_create(desc);
|
||||
map.center = {};
|
||||
map.alpha = 0;
|
||||
}
|
||||
|
||||
itemIconsSprite.Load(ITEM_ICONS_ANM2, GRAPHICS_LOAD);
|
||||
hudPickupSprite.Load(HUD_PICKUPS_ANM2, GRAPHICS_LOAD);
|
||||
questionMarkImage = Manager::LoadImage(QUESTION_MARK_PNG);
|
||||
iconsSprite.Load(ROOM_ICONS_ANM2, GRAPHICS_LOAD);
|
||||
state = MINIMAP_SMALL;
|
||||
holdTime = 0;
|
||||
isPinned = false;
|
||||
largeMapScale = 1;
|
||||
shakeDuration = 0;
|
||||
shakeOffset = {};
|
||||
}
|
||||
|
||||
// 0098db50 Redraws both maps' rooms and refreshes the HUD.
|
||||
void Minimap::Refresh()
|
||||
{
|
||||
for (MinimapConfig& map : configs) map.refresh();
|
||||
g_game->hud.refresh_request(HUD_REFRESH_PLAYER);
|
||||
}
|
||||
|
||||
// 0098dba0 Counts how long any player holds the map button (showing the floor's name once held ten frames), settles
|
||||
// the shake, and fades between the maps: holding shows the large map, a tap leaves it open at the options' opacity
|
||||
// until the next tap. Each release lets the floor's name go.
|
||||
// Netplay is offline, so every player reads its own controller.
|
||||
void Minimap::Update()
|
||||
{
|
||||
std::vector<Entity_Player*>& players = g_game->playerManager.playerList;
|
||||
if (players.empty()) KAGE_LogMessage(LOG_ASSERT, (uint8_t*)NO_PLAYERS);
|
||||
|
||||
bool isHeld = std::ranges::any_of(players, [](Entity_Player* player) {
|
||||
return is_controller_action(player->_controllerIndex, ACTION_MAP, ACTION_PRESSED);
|
||||
});
|
||||
if (isHeld && ++holdTime == SHOW_NAME_FRAMES) g_game->ShowName(true);
|
||||
|
||||
if (shakeDuration > 0)
|
||||
{
|
||||
shakeDuration--;
|
||||
float angle = (float)Random() * RANDOM_SCALE * HALF_TURN * 2;
|
||||
float magnitude = (float)shakeDuration / SHAKE_DIVISOR;
|
||||
shakeOffset = vector_make(std::cos(angle) * magnitude + shakeOffset.x * SHAKE_KEEP,
|
||||
std::sin(angle) * magnitude + shakeOffset.y * SHAKE_KEEP);
|
||||
}
|
||||
|
||||
HUD_Message& stageName = g_game->hud.messageMain;
|
||||
if (state_update(isHeld))
|
||||
{
|
||||
holdTime = 0;
|
||||
if (!stageName.isAutoHide) stageName.text_out();
|
||||
}
|
||||
for (MinimapConfig& map : configs) map.alpha = std::clamp(map.alpha, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
// Steps the state and both maps' alphas. True when the button is released, as Update lets the floor's name go.
|
||||
bool Minimap::state_update(bool isHeld)
|
||||
{
|
||||
float& small = configs[MINIMAP_SIZE_SMALL].alpha;
|
||||
float& large = configs[MINIMAP_SIZE_LARGE].alpha;
|
||||
auto fade_out = [](float alpha) { return alpha <= ALPHA_FALL ? 0 : alpha - ALPHA_FALL; };
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case MINIMAP_SMALL:
|
||||
small = small >= SMALL_FULL_ALPHA ? 1 : small + ALPHA_RISE;
|
||||
large = fade_out(large);
|
||||
break;
|
||||
case MINIMAP_HELD:
|
||||
small = isPinned ? 0 : fade_out(small);
|
||||
if (holdTime >= TAP_FRAMES) large = 1;
|
||||
if (isHeld)
|
||||
{
|
||||
if (holdTime < TAP_FRAMES) large += ALPHA_RISE;
|
||||
return false;
|
||||
}
|
||||
state = (holdTime < TAP_FRAMES) != isPinned ? MINIMAP_PINNED : MINIMAP_SMALL;
|
||||
if (holdTime < TAP_FRAMES) isPinned = !isPinned;
|
||||
return true;
|
||||
case MINIMAP_PINNED:
|
||||
{
|
||||
holdTime = 0;
|
||||
small = fade_out(small);
|
||||
float opacity = g_manager->optionsConfig.mapOpacity;
|
||||
if (large > opacity + OPACITY_STEP) large -= OPACITY_STEP;
|
||||
else if (large < opacity - OPACITY_STEP) large += OPACITY_STEP;
|
||||
else large = opacity;
|
||||
break;
|
||||
}
|
||||
default: return !isHeld;
|
||||
}
|
||||
|
||||
if (!isHeld) return true;
|
||||
state = MINIMAP_HELD;
|
||||
return false;
|
||||
}
|
||||
|
||||
// 0098b570 The large map's size while it shows, else the small map's.
|
||||
Vector Minimap::GetDisplayedSize()
|
||||
{
|
||||
const MinimapConfig& map = configs[MINIMAP_SIZE_LARGE];
|
||||
if (g_game->roomTransition.get_hud_alpha() * map.alpha <= 0)
|
||||
return vector_make(DEFAULT_DISPLAYED_SIZE, DEFAULT_DISPLAYED_SIZE);
|
||||
return vector_make(map.boundsMax.x - map.boundsMin.x, map.boundsMax.y - map.boundsMin.y);
|
||||
}
|
||||
|
||||
// 0098e4d0 Draws the maps as far as they show through the room transition's HUD fade, then the time and score,
|
||||
// outside the no HUD seed. Home's dungeon shows only the time and score, and only in a daily run.
|
||||
void Minimap::Render()
|
||||
{
|
||||
Game& game = *g_game;
|
||||
if (!game.hud.isVisible || game.seedEffects.HasSeedEffect(SEED_NO_HUD)) return;
|
||||
|
||||
bool isLost = curses_get() & CURSE_OF_THE_LOST;
|
||||
float hudAlpha = game.roomTransition.get_hud_alpha();
|
||||
const RoomConfig_Room* room = game.room->_descriptor->Data;
|
||||
if (room && room->type == ROOM_DUNGEON && room->stageId == STAGE_HOME)
|
||||
{
|
||||
if (game.dailyChallenge._id != 0) render_score_time(1);
|
||||
return;
|
||||
}
|
||||
|
||||
float smallAlpha = hudAlpha * configs[MINIMAP_SIZE_SMALL].alpha;
|
||||
if (smallAlpha > 0) render_small(smallAlpha, isLost);
|
||||
float largeAlpha = hudAlpha * configs[MINIMAP_SIZE_LARGE].alpha;
|
||||
if (largeAlpha > 0) render_large(largeAlpha, isLost);
|
||||
|
||||
bool isHistoryShown = g_manager->optionsConfig.historyHudMode == HISTORY_HUD_ON;
|
||||
float scoreAlpha = isHistoryShown ? std::max(SCORE_HISTORY_ALPHA, hudAlpha) : hudAlpha;
|
||||
if (scoreAlpha > 0) render_score_time(scoreAlpha);
|
||||
}
|
||||
|
||||
// The small map in the top right corner: its frame, then the part of the surface around its center (mirrored in the
|
||||
// mirror world) or the curse of the lost's question mark, then the icons.
|
||||
void Minimap::render_small(float alpha, bool isLost)
|
||||
{
|
||||
MinimapConfig& map = configs[MINIMAP_SIZE_SMALL];
|
||||
Vector shake = g_game->screenShakeOffset;
|
||||
float inset = hud_inset();
|
||||
Vector position = vector_make(g_screenWidth - SMALL_RIGHT + shakeOffset.x + inset * HUD_INSET_X,
|
||||
shakeOffset.y + SMALL_TOP + inset * HUD_INSET_Y);
|
||||
|
||||
map.mapSprite.SetFrame(ANIMATION_FRAME, 0);
|
||||
map.mapSprite.color = alpha_color(alpha);
|
||||
map.mapSprite.Render({position});
|
||||
if (isLost && questionMarkImage)
|
||||
{
|
||||
Vector at = vector_make(position.x + QUESTION_MARK_INSET + shake.x, position.y + QUESTION_MARK_INSET + shake.y);
|
||||
questionMarkImage->Render(at, kcolor_argb(WHITE_ARGB));
|
||||
}
|
||||
else if (!isLost)
|
||||
{
|
||||
map.mapSprite.color = COLOR_DEFAULT;
|
||||
KAGE::Graphics::ImageBase& surface = *map.surface;
|
||||
float halfWidth = ((float)(map.columns - 1) * (map.gap + map.cellSize.x) + map.gap) * 0.5f;
|
||||
float halfHeight = ((float)(map.rows - 1) * (map.gap + map.cellSize.y) + map.gap) * 0.5f;
|
||||
float left = std::floor(map.center.x) - std::floor(halfWidth);
|
||||
float top = std::floor(map.center.y) - std::floor(halfHeight);
|
||||
float right = std::ceil(halfWidth) + std::floor(map.center.x);
|
||||
float bottom = std::ceil(halfHeight) + std::floor(map.center.y);
|
||||
float sourceLeft = std::max(left, 0.0f);
|
||||
float sourceTop = std::max(top, 0.0f);
|
||||
float sourceRight = std::min(right, (float)surface.width);
|
||||
float sourceBottom = std::min(bottom, (float)surface.height);
|
||||
|
||||
SourceQuad source;
|
||||
static_cast<DestinationQuad&>(source) = quad_make(sourceLeft, sourceTop, sourceRight, sourceBottom);
|
||||
source._coordinateSpace = KAGE::Graphics::COORDINATES_PIXEL;
|
||||
bool isMirrored = g_game->room->IsMirrorWorld();
|
||||
if (isMirrored) quad_mirror(source);
|
||||
float x = map.margin + position.x + (isMirrored ? right - sourceRight : sourceLeft - left) + shake.x;
|
||||
Vector at = vector_make(x, map.margin + position.y + (sourceTop - top) + shake.y);
|
||||
surface.Render(source, at, kcolor_make(1, 1, 1, alpha));
|
||||
}
|
||||
render_icons(vector_make(position.x + SMALL_ICONS_X, position.y + SMALL_ICONS_Y), alpha);
|
||||
}
|
||||
|
||||
// The large map under the top right corner, sized to the rooms drawn (mirrored in the mirror world), or nothing
|
||||
// under the curse of the lost, then the icons under it.
|
||||
void Minimap::render_large(float alpha, bool isLost)
|
||||
{
|
||||
MinimapConfig& map = configs[MINIMAP_SIZE_LARGE];
|
||||
Vector shake = g_game->screenShakeOffset;
|
||||
float inset = hud_inset();
|
||||
float offsetY = inset * HUD_INSET_Y;
|
||||
float rightEdge = inset * HUD_INSET_X + g_screenWidth;
|
||||
float height = map.boundsMax.y - map.boundsMin.y;
|
||||
|
||||
if (!isLost)
|
||||
{
|
||||
KAGE::Graphics::ImageBase& surface = *map.surface;
|
||||
float width = (float)surface.width;
|
||||
float surfaceHeight = (float)surface.height;
|
||||
float insetX = (width - width * largeMapScale) * 0.5f;
|
||||
float insetY = (surfaceHeight - surfaceHeight * largeMapScale) * 0.5f;
|
||||
bool isMirrored = g_game->room->IsMirrorWorld();
|
||||
float y = offsetY - map.boundsMin.y + LARGE_TOP + largeMapOffset.y + shakeOffset.y + shake.y;
|
||||
float shown = isMirrored ? width - map.boundsMin.x : map.boundsMax.x;
|
||||
float x = rightEdge - shown - LARGE_RIGHT + largeMapOffset.x + shakeOffset.x + shake.x;
|
||||
DestinationQuad corners = quad_make(insetX + x, y + insetY, width + x - insetX, surfaceHeight + y - insetY);
|
||||
KAGE::Graphics::ColorQuad quad(corners, kcolor_argb(WHITE_ARGB));
|
||||
KColor color = kcolor_make(1, 1, 1, alpha);
|
||||
|
||||
if (!isMirrored) surface.Render(quad, color);
|
||||
else
|
||||
{
|
||||
SourceQuad source;
|
||||
static_cast<DestinationQuad&>(source) = quad_make(0, 0, 1, 1);
|
||||
quad_mirror(source);
|
||||
source._coordinateSpace = KAGE::Graphics::COORDINATES_NORMALIZED;
|
||||
surface.Render(source, quad, color);
|
||||
}
|
||||
}
|
||||
render_icons(vector_make(rightEdge - LARGE_ICONS_X, height + LARGE_ICONS_Y + offsetY), alpha);
|
||||
}
|
||||
|
||||
// 0098e170 Draws a row of icons leftward from position: The Mind, or the compass and maps held, Restock, then each
|
||||
// curse, at most seven, squeezed together past three.
|
||||
void Minimap::render_icons(Vector position, float alpha)
|
||||
{
|
||||
PlayerManager& players = g_game->playerManager;
|
||||
std::array<int, ICON_LIMIT> frames{};
|
||||
int count = 0;
|
||||
auto icon_add = [&](bool isShown, int frame) {
|
||||
if (isShown && count < ICON_LIMIT) frames[count++] = frame;
|
||||
};
|
||||
|
||||
itemIconsSprite.color = alpha_color(alpha);
|
||||
if (players.FirstCollectibleOwner(COLLECTIBLE_MIND, LAZARUS_SHARE_CHECK)) icon_add(true, ICON_MIND);
|
||||
else
|
||||
{
|
||||
icon_add(players.FirstCollectibleOwner(COLLECTIBLE_COMPASS, LAZARUS_SHARE_CHECK), ICON_COMPASS);
|
||||
icon_add(players.FirstCollectibleOwner(COLLECTIBLE_BLUE_MAP, LAZARUS_SHARE_CHECK), ICON_BLUE_MAP);
|
||||
icon_add(players.FirstCollectibleOwner(COLLECTIBLE_TREASURE_MAP, LAZARUS_SHARE_CHECK), ICON_TREASURE_MAP);
|
||||
}
|
||||
icon_add(players.FirstCollectibleOwner(COLLECTIBLE_RESTOCK, LAZARUS_SHARE_CHECK), ICON_RESTOCK);
|
||||
uint32_t curses = curses_get();
|
||||
for (int curse = 0; curse < CURSE_ICON_COUNT; curse++) icon_add(curses & 1u << curse, ~curse);
|
||||
if (count == 0) return;
|
||||
|
||||
float spacing = count < ICON_STACK_START ? ICON_SPACING : (float)(count - 3) + ICON_SPACING;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (frames[i] < 0) itemIconsSprite.SetFrame(ANIMATION_CURSES, ~frames[i]);
|
||||
else itemIconsSprite.SetFrame(ANIMATION_ICONS, frames[i]);
|
||||
itemIconsSprite.Render({position});
|
||||
position.x += spacing;
|
||||
}
|
||||
}
|
||||
|
||||
// 0098ef30 Writes the run's time (the time left, reddened, in the Speed! challenge, blinking once it runs out) and in
|
||||
// a daily run outside Greed mode the score, centered at the top. When the large map would cover them, they move left
|
||||
// of it and, unless the curse of the unknown hides the hearts, down past the first player's hearts.
|
||||
void Minimap::render_score_time(float alpha)
|
||||
{
|
||||
Game& game = *g_game;
|
||||
if (!game.hud.isVisible || game.seedEffects.HasSeedEffect(SEED_NO_HUD)) return;
|
||||
|
||||
StringTable& strings = g_manager->stringTable;
|
||||
Font& font = strings.language == 0 ? g_manager->font1_TeamMeatEx10 : g_manager->font2_TeamMeatEx12;
|
||||
float inset = hud_inset();
|
||||
float textY = inset * -HUD_INSET_X;
|
||||
Vector shake = game.screenShakeOffset;
|
||||
float labelWidth = (float)font.GetStringWidth(string_table_translate(strings, TIME_LABEL));
|
||||
float width = std::max(labelWidth + (float)font.GetStringWidth(TIME_WIDEST),
|
||||
labelWidth + (float)font.GetStringWidth(SCORE_WIDEST));
|
||||
float left = (g_screenWidth - width) * SCORE_WIDTH_GAP;
|
||||
float right = width + left;
|
||||
|
||||
const MinimapConfig& map = configs[MINIMAP_SIZE_LARGE];
|
||||
float space = g_screenWidth - right;
|
||||
float mapWidth = map.boundsMax.x - map.boundsMin.x;
|
||||
bool isCovered = !(curses_get() & CURSE_OF_THE_LOST) && map.cellSize.x + mapWidth > space &&
|
||||
game.roomTransition.get_hud_alpha() * map.alpha > 0;
|
||||
if (isCovered)
|
||||
{
|
||||
float shift = space - mapWidth - map.cellSize.x - (1 - inset) * HUD_INSET_X;
|
||||
right += shift;
|
||||
left += shift;
|
||||
Entity_Player* player = game.GetPlayer(0);
|
||||
float lives = player->GetExtraLives() > 0 ? EXTRA_LIVES_WIDTH : 0;
|
||||
float hearts = (float)(player->GetEffectiveMaxHearts() + player->_soulHearts) * HEART_WIDTH;
|
||||
float heartsRight = std::min(hearts, HEARTS_WIDTH_MAX) + HEARTS_MARGIN - inset * HEARTS_INSET + lives;
|
||||
bool isUnknown = g_game->GetCurses() & CURSE_OF_THE_UNKNOWN;
|
||||
if (heartsRight >= left && !isUnknown) textY += TEXT_DROP - (1 - inset) * TEXT_DROP_INSET;
|
||||
}
|
||||
|
||||
bool isSpeed = game.challenge == CHALLENGE_SPEED;
|
||||
int time = isSpeed ? std::max(SPEED_TIME_LIMIT - game.timeCounter, 0) : game.timeCounter;
|
||||
KColor color = isSpeed ? kcolor_make(1, SPEED_TINT, SPEED_TINT, alpha) : kcolor_make(1, 1, 1, alpha);
|
||||
FontSettings settings;
|
||||
char text[64];
|
||||
left += shake.x;
|
||||
if (time > 0 || game.frameCount % BLINK_PERIOD < BLINK_SHOWN)
|
||||
{
|
||||
std::snprintf(text, sizeof(text), "%02d:%02d:%02d", time / FRAMES_PER_HOUR,
|
||||
time % FRAMES_PER_HOUR / FRAMES_PER_MINUTE, time % FRAMES_PER_MINUTE / FRAMES_PER_SECOND);
|
||||
float timeY = textY + TIME_Y + shake.y;
|
||||
font.DrawString(string_table_translate(strings, TIME_LABEL), vector_make(left, timeY), vector_make(1, 1), color,
|
||||
settings);
|
||||
font.DrawString(text, vector_make(right - (float)font.GetStringWidth(text) + shake.x, timeY),
|
||||
vector_make(1, 1), color, settings);
|
||||
}
|
||||
|
||||
if (game.IsGreedMode() || game.dailyChallenge._id == 0) return;
|
||||
|
||||
color = kcolor_make(1, 1, 1, alpha);
|
||||
float scoreY = textY + SCORE_Y + shake.y;
|
||||
font.DrawString(string_table_translate(strings, SCORE_LABEL), vector_make(left, scoreY), vector_make(1, 1), color,
|
||||
settings);
|
||||
game.scoreSheet.Calculate();
|
||||
std::snprintf(text, sizeof(text), "%d", game.scoreSheet.totalScore);
|
||||
font.DrawString(text, vector_make(right - (float)font.GetStringWidth(text) + shake.x, scoreY), vector_make(1, 1),
|
||||
color, settings);
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
#pragma once
|
||||
|
||||
#include "anm2.h"
|
||||
#include "kage_graphics.h"
|
||||
#include <array>
|
||||
|
||||
// How the map shows: the small one in the corner, the large one while the map button is held, or the large one left
|
||||
// open by a tap.
|
||||
enum MinimapState : int
|
||||
{
|
||||
MINIMAP_SMALL,
|
||||
MINIMAP_HELD,
|
||||
MINIMAP_PINNED
|
||||
};
|
||||
|
||||
// The two maps, by their index in Minimap::configs.
|
||||
enum MinimapSize : int
|
||||
{
|
||||
MINIMAP_SIZE_SMALL,
|
||||
MINIMAP_SIZE_LARGE,
|
||||
MINIMAP_SIZE_COUNT
|
||||
};
|
||||
|
||||
// Copies and destruction are the defaults.
|
||||
// One of the two maps (MinimapConfig): its frame sheet, the surface the rooms are drawn on, the room cell size and the
|
||||
// gap between cells, how many cells fit across and down, the margin around them, the room icons' size and scale, the
|
||||
// point of the surface the map centers on, the drawn rooms' bounds and its alpha.
|
||||
struct MinimapConfig
|
||||
{
|
||||
ANM2 mapSprite;
|
||||
KAGE::Graphics::ImagePtr surface;
|
||||
Vector boundsMax{};
|
||||
Vector boundsMin{};
|
||||
Vector cellSize{};
|
||||
Vector center{};
|
||||
Vector iconSize{};
|
||||
float alpha = 0;
|
||||
float gap = 0;
|
||||
float margin = 0;
|
||||
int columns = 0;
|
||||
int iconScale = 0;
|
||||
int rows = 0;
|
||||
|
||||
void refresh();
|
||||
};
|
||||
|
||||
// Destruction (0098b1d0) is the default.
|
||||
// The floor map (Minimap): the small and large maps, how long the map button is held, the item and curse icons beside
|
||||
// the map, the question mark the curse of the lost shows instead, the shake when it is hit, and the time and score
|
||||
// written under it. largeMapOffset and largeMapScale move and shrink the large map's surface.
|
||||
class Minimap
|
||||
{
|
||||
public:
|
||||
std::array<MinimapConfig, MINIMAP_SIZE_COUNT> configs;
|
||||
KAGE::Graphics::ImagePtr questionMarkImage;
|
||||
ANM2 hudPickupSprite;
|
||||
ANM2 iconsSprite;
|
||||
ANM2 itemIconsSprite;
|
||||
Vector largeMapOffset{};
|
||||
Vector shakeOffset{};
|
||||
MinimapState state = MINIMAP_SMALL;
|
||||
float largeMapScale = 1;
|
||||
int holdTime = 0;
|
||||
int shakeDuration = 0;
|
||||
bool isPinned = false;
|
||||
|
||||
void Init();
|
||||
void Refresh();
|
||||
void Update();
|
||||
void Render();
|
||||
Vector GetDisplayedSize();
|
||||
|
||||
private:
|
||||
bool state_update(bool isHeld);
|
||||
void render_small(float alpha, bool isLost);
|
||||
void render_large(float alpha, bool isLost);
|
||||
void render_icons(Vector position, float alpha);
|
||||
void render_score_time(float alpha);
|
||||
};
|
||||
+2
-1
@@ -5,6 +5,7 @@
|
||||
#include "lua_engine.h"
|
||||
#include "manager.h"
|
||||
#include "menu_manager.h"
|
||||
#include "pause_screen.h"
|
||||
#include "platform.h"
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
@@ -542,7 +543,7 @@ void ModManager::Reset()
|
||||
{
|
||||
pause_screen_unload_sprites();
|
||||
AnmCache::Clear();
|
||||
FUN_00954710();
|
||||
graphics_reload();
|
||||
g_menuManager->menuCharacter.Reset();
|
||||
g_menuManager->menuCollection.reset();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
#include "online_emotes.h"
|
||||
#include "log.h"
|
||||
#include "manager.h"
|
||||
#include "menu_manager.h"
|
||||
#include <array>
|
||||
#include <string_view>
|
||||
|
||||
constexpr std::array<std::string_view, EMOTE_TYPING> EMOTE_ANIMATIONS = {
|
||||
"Up", "Down", "Left", "Right", "Happy", "Sad", "ThumbsUp", "ThumbsDown", "Heart", "Bomb", "Coin",
|
||||
"Key", "TintedRock", "Angel", "Devil", "Poop", "RaiseHand", "QuestionMark", "D6", "D20", "Reset"};
|
||||
constexpr const char* ANIMATION_BUBBLE = "Bubble";
|
||||
constexpr const char* ANIMATION_D6_ROLL = "D6Roll";
|
||||
constexpr const char* ANIMATION_D6_RESULT = "D6Result";
|
||||
constexpr const char* ANIMATION_D20_ROLL = "D20Roll";
|
||||
constexpr const char* ANIMATION_D20_RESULT = "D20Result";
|
||||
constexpr const char* ANIMATION_NICALIS = "Nicalis";
|
||||
constexpr const char* TYPING_DOTS[] = {".", "..", "..."};
|
||||
constexpr int TYPING_CYCLE = 60;
|
||||
constexpr int TYPING_DOT_FRAMES = 20;
|
||||
constexpr float TYPING_OFFSET_X = -12;
|
||||
constexpr uint32_t TYPING_ARGB = 0xffffffff;
|
||||
|
||||
constexpr int WHEEL_SET_COUNT = 2;
|
||||
constexpr float FULL_TURN = 360;
|
||||
|
||||
// The animation an emote plays, none while typing.
|
||||
static std::string_view emote_animation(Emote emote)
|
||||
{
|
||||
if (emote < EMOTE_TYPING) return EMOTE_ANIMATIONS[emote];
|
||||
if (emote == EMOTE_TYPING) return {};
|
||||
if (emote < EMOTE_D20_ROLL) return ANIMATION_D6_ROLL;
|
||||
if (emote < EMOTE_NICALIS) return ANIMATION_D20_ROLL;
|
||||
return ANIMATION_NICALIS;
|
||||
}
|
||||
|
||||
// 0042fba0 Loads both sprites on the emotes sheet and floats the bubble.
|
||||
// The original also fills a table of animation names here, which emote_animation holds.
|
||||
void OnlineEmotes::Load()
|
||||
{
|
||||
emoteSprite.Load(ONLINE_EMOTES_ANM2, GRAPHICS_LOAD);
|
||||
bubbleSprite.Load(ONLINE_EMOTES_ANM2, GRAPHICS_LOAD);
|
||||
bubbleSprite.Play(ANIMATION_BUBBLE);
|
||||
}
|
||||
|
||||
// 00430750 Shows an emote for some frames, playing it from the start unless it is already shown.
|
||||
void OnlineEmotes::Play(Emote shown, int frames)
|
||||
{
|
||||
duration = frames;
|
||||
isActive = true;
|
||||
if (emote == shown) return;
|
||||
|
||||
emote = shown;
|
||||
timer = 0;
|
||||
if (shown == EMOTE_TYPING) return;
|
||||
|
||||
emoteSprite.Play(emote_animation(shown));
|
||||
emoteSprite.Update();
|
||||
}
|
||||
|
||||
// 004303e0 Steps the sprites, turns a finished die roll into its result held on the face rolled, and hides the emote
|
||||
// once its duration has passed.
|
||||
void OnlineEmotes::Update()
|
||||
{
|
||||
if (!isActive) return;
|
||||
|
||||
if (emote != EMOTE_TYPING)
|
||||
{
|
||||
emoteSprite.Update();
|
||||
bubbleSprite.Update();
|
||||
|
||||
int frame = -1;
|
||||
auto roll_settle = [&](std::string_view roll, std::string_view result, Emote first)
|
||||
{
|
||||
if (emoteSprite.IsFinished(roll)) emoteSprite.Play(result);
|
||||
if (emoteSprite.IsPlaying(result)) frame = emote - first;
|
||||
};
|
||||
if (emote >= EMOTE_D6_ROLL && emote < EMOTE_D20_ROLL)
|
||||
roll_settle(ANIMATION_D6_ROLL, ANIMATION_D6_RESULT, EMOTE_D6_ROLL);
|
||||
else if (emote >= EMOTE_D20_ROLL && emote < EMOTE_NICALIS)
|
||||
roll_settle(ANIMATION_D20_ROLL, ANIMATION_D20_RESULT, EMOTE_D20_ROLL);
|
||||
else if (emote >= EMOTE_NICALIS && emote < EMOTE_COUNT && emoteSprite.animState.animData)
|
||||
frame = emote - EMOTE_NICALIS;
|
||||
if (frame >= 0) emoteSprite.animState.SetFrameFloat((float)frame);
|
||||
}
|
||||
|
||||
timer++;
|
||||
if (duration == 0 || timer <= duration) return;
|
||||
|
||||
isActive = false;
|
||||
emote = EMOTE_NONE;
|
||||
timer = 0;
|
||||
duration = 0;
|
||||
}
|
||||
|
||||
// 004305c0 Draws the bubble and the emote at a position, or dots counting up while its player types.
|
||||
void OnlineEmotes::Render(Vector position)
|
||||
{
|
||||
if (!isActive) return;
|
||||
|
||||
if (emote != EMOTE_TYPING)
|
||||
{
|
||||
if (isBubbleShown) bubbleSprite.Render({position});
|
||||
emoteSprite.Render({position});
|
||||
return;
|
||||
}
|
||||
|
||||
FontSettings settings;
|
||||
std::string_view dots = TYPING_DOTS[timer % TYPING_CYCLE / TYPING_DOT_FRAMES];
|
||||
Vector textPosition = vector_make(position.x + TYPING_OFFSET_X, position.y);
|
||||
g_manager->font2_TeamMeatEx12.DrawString(dots, textPosition, vector_make(1, 1), kcolor_argb(TYPING_ARGB), settings);
|
||||
}
|
||||
|
||||
// 008d1d60 Closes the wheel and fills its two sets, the game's emotes and the Nicalis frames, adding to any already
|
||||
// there as the original does. Loads the wheel's emote without its bubble.
|
||||
void EmoteWheel::Init()
|
||||
{
|
||||
ringRadius = openProgress;
|
||||
selectionRadius = maxRadius;
|
||||
isInitialized = true;
|
||||
state = EMOTE_WHEEL_CLOSED;
|
||||
selection = -1;
|
||||
|
||||
emoteSets.resize(WHEEL_SET_COUNT);
|
||||
for (int emote = EMOTE_UP; emote <= EMOTE_D20; emote++) emoteSets[0].push_back((Emote)emote);
|
||||
for (int emote = EMOTE_NICALIS; emote < EMOTE_COUNT; emote++) emoteSets[1].push_back((Emote)emote);
|
||||
emoteSetIndex = 0;
|
||||
angle_step_update();
|
||||
|
||||
emote.Load();
|
||||
emote.isBubbleShown = false;
|
||||
}
|
||||
|
||||
// 008d26c0 Switches to another set of emotes, keeping the selection at about the same angle.
|
||||
void EmoteWheel::SetEmoteSet(int index)
|
||||
{
|
||||
if (index == emoteSetIndex) return;
|
||||
if (index < 0 || index >= (int)emoteSets.size())
|
||||
{
|
||||
log_printf(LOG_ERROR, "Invalid set index %d \n", index);
|
||||
return;
|
||||
}
|
||||
|
||||
emoteSetIndex = index;
|
||||
angle_step_update();
|
||||
}
|
||||
|
||||
// Spreads the current set's emotes evenly around the ring, rounding the selection to the same angle.
|
||||
void EmoteWheel::angle_step_update()
|
||||
{
|
||||
float previousStep = angleStep;
|
||||
angleStep = FULL_TURN / (float)emoteSets[emoteSetIndex].size();
|
||||
selection = (int)((float)selection * previousStep / angleStep + 0.5f);
|
||||
}
|
||||
|
||||
void EmoteWheel::Update() { reconstruction_missing("EmoteWheel::Update 008d1f20 (netplay only)"); }
|
||||
|
||||
// The closed wheel draws nothing. The open one only opens in netplay.
|
||||
void EmoteWheel::Render()
|
||||
{
|
||||
if (state != EMOTE_WHEEL_CLOSED) reconstruction_missing("EmoteWheel::Render 008d2450 (netplay only open wheel)");
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
#pragma once
|
||||
|
||||
#include "anm2.h"
|
||||
#include <vector>
|
||||
|
||||
constexpr const char* ONLINE_EMOTES_ANM2 = "gfx/OnlineEmotes.anm2";
|
||||
|
||||
// The emotes a player can show, by the animation each plays in OnlineEmotes.anm2.
|
||||
// The die rolls show their result on a frame of the result animation, each face its own emote.
|
||||
// Nicalis plays one of its frames the same way.
|
||||
enum Emote : int
|
||||
{
|
||||
EMOTE_UP,
|
||||
EMOTE_DOWN,
|
||||
EMOTE_LEFT,
|
||||
EMOTE_RIGHT,
|
||||
EMOTE_HAPPY,
|
||||
EMOTE_SAD,
|
||||
EMOTE_THUMBS_UP,
|
||||
EMOTE_THUMBS_DOWN,
|
||||
EMOTE_HEART,
|
||||
EMOTE_BOMB,
|
||||
EMOTE_COIN,
|
||||
EMOTE_KEY,
|
||||
EMOTE_TINTED_ROCK,
|
||||
EMOTE_ANGEL,
|
||||
EMOTE_DEVIL,
|
||||
EMOTE_POOP,
|
||||
EMOTE_RAISE_HAND,
|
||||
EMOTE_QUESTION_MARK,
|
||||
EMOTE_D6,
|
||||
EMOTE_D20,
|
||||
EMOTE_RESET,
|
||||
EMOTE_TYPING,
|
||||
EMOTE_D6_ROLL,
|
||||
EMOTE_D20_ROLL = EMOTE_D6_ROLL + 6,
|
||||
EMOTE_NICALIS = EMOTE_D20_ROLL + 20,
|
||||
EMOTE_COUNT = EMOTE_NICALIS + 11,
|
||||
EMOTE_NONE = 60
|
||||
};
|
||||
|
||||
// Where the emote wheel is in opening and closing.
|
||||
enum EmoteWheelState : int
|
||||
{
|
||||
EMOTE_WHEEL_CLOSED,
|
||||
EMOTE_WHEEL_OPENING,
|
||||
EMOTE_WHEEL_OPEN,
|
||||
EMOTE_WHEEL_CLOSING
|
||||
};
|
||||
|
||||
// Construction, copies and destruction (0042fa30, 0042fac0) are the defaults.
|
||||
// An emote shown over a player or on the wheel (OnlineEmotes): the emote in its bubble, or dots while its player types.
|
||||
// It plays for a duration in frames, or until replaced when that is 0.
|
||||
class OnlineEmotes
|
||||
{
|
||||
public:
|
||||
ANM2 bubbleSprite;
|
||||
ANM2 emoteSprite;
|
||||
Emote emote = EMOTE_NONE;
|
||||
int duration = 0;
|
||||
int timer = 0;
|
||||
bool isActive = false;
|
||||
bool isBubbleShown = true;
|
||||
|
||||
void Load();
|
||||
void Play(Emote shown, int frames);
|
||||
void Update();
|
||||
void Render(Vector position);
|
||||
};
|
||||
|
||||
// Construction and destruction (008d1d20) are the defaults.
|
||||
// The online emote wheel (EmoteWheel): two sets of emotes laid out around a ring that opens and closes from the
|
||||
// screen center, the emote the stick points at, and the emote drawing each one.
|
||||
// The ring radii are those of the ring and selection images the open wheel draws.
|
||||
class EmoteWheel
|
||||
{
|
||||
public:
|
||||
std::vector<std::vector<Emote>> emoteSets;
|
||||
OnlineEmotes emote;
|
||||
EmoteWheelState state = EMOTE_WHEEL_CLOSED;
|
||||
float angleStep = 0;
|
||||
float innerRadius = 70;
|
||||
float maxRadius = 110;
|
||||
float openProgress = 0;
|
||||
float ringRadius = 0;
|
||||
float selectionRadius = 0;
|
||||
int emoteSetIndex = 0;
|
||||
int selection = -1;
|
||||
bool isInitialized = false;
|
||||
|
||||
void Init();
|
||||
void SetEmoteSet(int index);
|
||||
void Update();
|
||||
void Render();
|
||||
|
||||
private:
|
||||
void angle_step_update();
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
#include "online_stats_screen.h"
|
||||
#include "menu_manager.h"
|
||||
|
||||
constexpr const char* DEEDS_ANM2 = "gfx/ui/DeedsMenu.anm2";
|
||||
constexpr const char* ANIMATION_PLAYER_CHARACTER = "PlayerCharacter";
|
||||
|
||||
// 008ca2c0 Hides the screen and loads the deeds sheet idling and each player's character sprite, all stepped once.
|
||||
void OnlineStatsScreen::Load()
|
||||
{
|
||||
isActive = false;
|
||||
deedsSprite.Load(DEEDS_ANM2, GRAPHICS_LOAD);
|
||||
deedsSprite.Play(ANIMATION_IDLE);
|
||||
deedsSprite.Update();
|
||||
|
||||
for (ANM2& sprite : characterSprites)
|
||||
{
|
||||
sprite.Load(DEEDS_ANM2, GRAPHICS_LOAD);
|
||||
sprite.Play(ANIMATION_PLAYER_CHARACTER);
|
||||
sprite.Update();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "anm2.h"
|
||||
#include <array>
|
||||
|
||||
constexpr int ONLINE_STATS_PLAYERS = 4;
|
||||
|
||||
// Destruction (008ca220, 008ca5b0) is the default.
|
||||
// The deeds screen an online run ends on (OnlineStatsScreen): the deeds sheet and a character sprite per player.
|
||||
// Netplay is offline, so it never shows, and the players it would list (online_stats_finalize) are left out.
|
||||
class OnlineStatsScreen
|
||||
{
|
||||
public:
|
||||
std::array<ANM2, ONLINE_STATS_PLAYERS> characterSprites;
|
||||
ANM2 deedsSprite;
|
||||
bool isActive = false;
|
||||
|
||||
void Load();
|
||||
};
|
||||
@@ -0,0 +1,439 @@
|
||||
#include "pause_screen.h"
|
||||
#include "game.h"
|
||||
#include "hud.h"
|
||||
#include "kage_input.h"
|
||||
#include "log.h"
|
||||
#include "manager.h"
|
||||
#include "menu_manager.h"
|
||||
#include "platform.h"
|
||||
#include <algorithm>
|
||||
|
||||
constexpr const char* PAUSE_ANM2 = "gfx/ui/PauseScreen_small.anm2";
|
||||
constexpr const char* MY_STUFF_ANM2 = "gfx/ui/PauseScreen_MyStuff.anm2";
|
||||
constexpr const char* DIARY_ANM2 = "gfx/ui/Death Screen.anm2";
|
||||
constexpr const char* CHARGE_ICONS_ANM2 = "gfx/ui/ui_charge_icons.anm2";
|
||||
constexpr const char* ROOM_ICONS_ANM2 = "gfx/ui/minimap_icons.anm2";
|
||||
constexpr const char* SECTION_CURSOR_PNG = "gfx/ui/MyStuff_SectionCursor.png";
|
||||
constexpr const char* DESCRIPTION_FONT = "font/TeamMeatEx/TeamMeatEx12.fnt";
|
||||
constexpr const char* ANIMATION_APPEAR = "Appear";
|
||||
constexpr const char* ANIMATION_DISAPPEAR = "Dissapear";
|
||||
constexpr const char* ANIMATION_CURSOR = "Cursor";
|
||||
constexpr const char* ANIMATION_DIARY = "Diary";
|
||||
constexpr const char* ANIMATION_CHARGE_ICON = "ChargeIcon";
|
||||
constexpr const char* LAYER_CURSOR = "Cursor";
|
||||
constexpr const char* LAYER_ITEMS = "Items";
|
||||
constexpr const char* LAYER_BACK_KEY = "BackKey";
|
||||
constexpr const char* LAYER_SEED_PAPER = "SeedPaper";
|
||||
constexpr const char* LAYER_MENU_TITLE = "Menu Title";
|
||||
constexpr const char* LAYER_BLOOD = "Blood";
|
||||
constexpr const char* NULL_SEED = "Seed";
|
||||
constexpr const char* NULL_COMPLETION_WIDGET = "CompletionWidget";
|
||||
constexpr const char* START_SEED_UNSET = "Error: Game Start Seed was not set.\n";
|
||||
// The layers only an online lobby shows.
|
||||
constexpr const char* LAYER_INVITE = "Invite";
|
||||
constexpr const char* LAYER_KICK = "Kick";
|
||||
constexpr const char* ONLINE_LAYERS[] = {LAYER_INVITE, LAYER_KICK, "InviteKey", "KickKey", "PasswordPaper",
|
||||
"ShowPassword", "ShowPasswordKey", "StuffArrow1", "StuffArrow2"};
|
||||
constexpr const char* QUIT_DAILY_LINES[] = {"#QUIT_DAILY_RUN_1", "#QUIT_DAILY_RUN_2", "#QUIT_DAILY_RUN_3",
|
||||
"#QUIT_DAILY_RUN_4"};
|
||||
|
||||
constexpr float DESCRIPTION_LINE_SPACING = 0.9f;
|
||||
constexpr float PAPER_X = 0.7f;
|
||||
constexpr float PAPER_BOTTOM_MARGIN = 0.025f;
|
||||
constexpr float SEED_LINE_HEIGHT = 15;
|
||||
constexpr size_t SEED_HALF_LENGTH = 4;
|
||||
constexpr size_t SEED_SECOND_HALF = 5;
|
||||
constexpr uint32_t PAPER_TEXT_ARGB = 0xff362f2d;
|
||||
constexpr uint32_t BLACK_ARGB = 0xff000000;
|
||||
constexpr float SOUND_VOLUME = 0.7f;
|
||||
constexpr int SOUND_PAPER_IN = 17;
|
||||
constexpr int SOUND_PAPER_OUT = 18;
|
||||
constexpr float FADE_SPEED = 0.08f;
|
||||
constexpr int FADE_TARGET_MENU = 2;
|
||||
constexpr int KEYBOARD = 0;
|
||||
constexpr int COLLECTIBLE_GLITCHED_CROWN = 689;
|
||||
constexpr unsigned int ENTITY_PICKUP = 5;
|
||||
constexpr unsigned int PICKUP_COLLECTIBLE = 100;
|
||||
|
||||
// Whether an action holds on one device, as KAGE's input manager asks.
|
||||
bool is_controller_action(int deviceId, ButtonAction action, ActionTest test)
|
||||
{
|
||||
std::shared_ptr<KAGE::Input::InputDevice> device = KAGE::Input::manager.device_find(deviceId);
|
||||
if (!device || !device->isConnected) return false;
|
||||
|
||||
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 false;
|
||||
return std::ranges::any_of(table[action], [&](int button) {
|
||||
if (button == KAGE::Input::BUTTON_NONE) return false;
|
||||
return test == ACTION_TRIGGERED ? device->is_button_triggered(button) : device->is_button_pressed(button);
|
||||
});
|
||||
}
|
||||
|
||||
// Shows or hides a layer of a sprite, if it has one of that name.
|
||||
static void layer_show(ANM2& sprite, std::string_view name, bool isVisible)
|
||||
{
|
||||
if (LayerState* layer = sprite.GetLayer(name)) layer->isVisible = isVisible;
|
||||
}
|
||||
|
||||
// Plays a pause screen sound at its volume, unless the seeds swap it for a fart.
|
||||
static void sound_play(int sound)
|
||||
{
|
||||
SoundPlay play;
|
||||
play.volume = SOUND_VOLUME;
|
||||
seed_fart_sound_override(&sound);
|
||||
g_manager->sfxManager.Play(sound, play);
|
||||
}
|
||||
|
||||
// Fades the run out to the menus.
|
||||
static void game_fade_out()
|
||||
{
|
||||
Game& game = *g_game;
|
||||
KColor black = kcolor_argb(BLACK_ARGB);
|
||||
|
||||
game.fadeSpeed = FADE_SPEED;
|
||||
game.fadeOutTarget = FADE_TARGET_MENU;
|
||||
game.fadeOutColor = kcolor_make(black._red, black._green, black._blue, game.fadeOutColor._alpha + FADE_SPEED);
|
||||
}
|
||||
|
||||
// 008d2ca0 Resets the page and loads its font, sheet (idle, cursor hidden), diary, charge icons, room icons and
|
||||
// section cursor.
|
||||
void PauseScreen_MyStuff::Init()
|
||||
{
|
||||
reset();
|
||||
descriptionText.load_font(DESCRIPTION_FONT);
|
||||
descriptionText.lineSpacing = DESCRIPTION_LINE_SPACING;
|
||||
|
||||
pageSprite.Load(MY_STUFF_ANM2, GRAPHICS_LOAD);
|
||||
pageSprite.Play(ANIMATION_IDLE);
|
||||
layer_show(pageSprite, LAYER_CURSOR, false);
|
||||
diary_load();
|
||||
chargeSprite.Load(CHARGE_ICONS_ANM2, GRAPHICS_LOAD);
|
||||
chargeSprite.Play(ANIMATION_CHARGE_ICON);
|
||||
iconsSprite.Load(ROOM_ICONS_ANM2, GRAPHICS_LOAD);
|
||||
sectionCursorImage = Manager::LoadImage(SECTION_CURSOR_PNG);
|
||||
}
|
||||
|
||||
// Loads the diary the page sits on, showing only its items layer.
|
||||
void PauseScreen_MyStuff::diary_load()
|
||||
{
|
||||
diarySprite.Load(DIARY_ANM2, GRAPHICS_LOAD);
|
||||
diarySprite.Play(ANIMATION_DIARY);
|
||||
for (LayerState& layer : diarySprite.layerStates) layer.isVisible = false;
|
||||
layer_show(diarySprite, LAYER_ITEMS, true);
|
||||
}
|
||||
|
||||
// 008d3250 Closes the page, hides its cursor and forgets the item images its descriptions loaded.
|
||||
// The item lists and selection it also clears belong to the page's update, not written yet.
|
||||
void PauseScreen_MyStuff::reset()
|
||||
{
|
||||
isOpen = false;
|
||||
if (pageSprite.isLoaded) layer_show(pageSprite, LAYER_CURSOR, false);
|
||||
if (descriptionText.icons) descriptionText.icons->images.clear();
|
||||
}
|
||||
|
||||
void PauseScreen_MyStuff::Update()
|
||||
{
|
||||
reconstruction_missing("PauseScreen_MyStuff::Update 008d3360 (with 008d3890, 008d4040, 008d42a0, 008d84f0)");
|
||||
}
|
||||
|
||||
void PauseScreen_MyStuff::Render()
|
||||
{
|
||||
reconstruction_missing("PauseScreen_MyStuff::Render 008d3640 (with render_entry 008d5990)");
|
||||
}
|
||||
|
||||
// 009b5840 Loads the options, My Stuff, the completion marks, the menu paper and the prompt, closed on Resume.
|
||||
void PauseScreen::Init()
|
||||
{
|
||||
menuOptions.Init({}, OPTIONS_PAUSE);
|
||||
myStuff.Init();
|
||||
completionWidget.Load(COMPLETION_STYLE_PAUSE);
|
||||
state = PAUSE_HIDDEN;
|
||||
selectedElement = PAUSE_ITEM_RESUME;
|
||||
menuSprite.Load(PAUSE_ANM2, GRAPHICS_LOAD);
|
||||
genericPrompt.Initialize(PROMPT_SMALL);
|
||||
}
|
||||
|
||||
// 009b7a20 Loads the paper, the prompt, the options sheet and My Stuff's diary again, as the graphics reload.
|
||||
void PauseScreen::load_graphics()
|
||||
{
|
||||
menuSprite.Load(PAUSE_ANM2, GRAPHICS_LOAD);
|
||||
genericPrompt.Initialize(PROMPT_SMALL);
|
||||
menuOptions.load_menu_anm2();
|
||||
myStuff.diary_load();
|
||||
}
|
||||
|
||||
// Drops the sprites load_graphics loads.
|
||||
void PauseScreen::unload_graphics()
|
||||
{
|
||||
menuSprite.Reset();
|
||||
genericPrompt.sprite.Reset();
|
||||
genericPrompt.isOnlineVote = false;
|
||||
menuOptions.optionsSprite.Reset();
|
||||
myStuff.diarySprite.Reset();
|
||||
}
|
||||
|
||||
// 00954690 Drops the pause screen's sprites while a run exists, as the mods reload.
|
||||
void pause_screen_unload_sprites()
|
||||
{
|
||||
if (g_game) g_game->pauseScreen.unload_graphics();
|
||||
}
|
||||
|
||||
// 00954710 Loads the pause screen's sprites (during a run), the button prompts, the fonts and the achievement popup
|
||||
// again.
|
||||
void graphics_reload()
|
||||
{
|
||||
Manager& manager = *g_manager;
|
||||
|
||||
if (g_game) g_game->pauseScreen.load_graphics();
|
||||
manager.popupButtons.load_graphics();
|
||||
manager.load_fonts();
|
||||
manager.achievementOverlay.load_graphics();
|
||||
}
|
||||
|
||||
// 009b7680 Opens the menu on Resume for the first player: the options set up for the pause screen, looping sounds
|
||||
// stopped, the paper appearing with the blood of hard mode and the player's completion marks.
|
||||
// The original also logs two profiling counters here, left out.
|
||||
void PauseScreen::Show()
|
||||
{
|
||||
menuOptions.Init({}, OPTIONS_PAUSE);
|
||||
playerIdx = 0;
|
||||
g_manager->sfxManager.StopLoopingSounds();
|
||||
state = PAUSE_MENU;
|
||||
selectedElement = PAUSE_ITEM_RESUME;
|
||||
menuSprite.Play(ANIMATION_APPEAR, PLAY_FORCED);
|
||||
completionWidget.characterId = g_game->GetPlayer(playerIdx)->_playerType;
|
||||
sound_play(SOUND_PAPER_IN);
|
||||
|
||||
layer_show(menuSprite, LAYER_INVITE, false);
|
||||
layer_show(menuSprite, LAYER_KICK, false);
|
||||
layer_show(menuSprite, LAYER_BLOOD, g_game->difficulty == DIFFICULTY_HARD);
|
||||
}
|
||||
|
||||
// 009b7500 Plays the paper away while open, unless it already is.
|
||||
void PauseScreen::hide()
|
||||
{
|
||||
if (state == PAUSE_HIDDEN || menuSprite.GetAnimation() == ANIMATION_DISAPPEAR) return;
|
||||
|
||||
sound_play(SOUND_PAPER_OUT);
|
||||
menuSprite.Play(ANIMATION_DISAPPEAR);
|
||||
menuSprite.overlayAnimState.SetAnimationData(nullptr);
|
||||
}
|
||||
|
||||
// 009b7650 Whether the screen is open and pauses the run, as it does offline.
|
||||
bool PauseScreen::is_pausing()
|
||||
{
|
||||
return state != PAUSE_HIDDEN;
|
||||
}
|
||||
|
||||
// The paused player's controller. Netplay is offline, so it is always a local player's.
|
||||
int PauseScreen::controller_get()
|
||||
{
|
||||
return g_game->GetPlayer(playerIdx)->_controllerIndex;
|
||||
}
|
||||
|
||||
// 009b5d20 Steps the open page, opens the menu on pause (or back on the keyboard, while no emote menu is up), runs the
|
||||
// menu or leaves the options on back, then the prompt. A quit prompt played out answered yes ends the run.
|
||||
// Nothing happens while a blocking popup is up.
|
||||
void PauseScreen::Update()
|
||||
{
|
||||
if (g_manager->popupQueue.is_blocking()) return;
|
||||
|
||||
if (state == PAUSE_OPTIONS) menuOptions.Update();
|
||||
else if (state == PAUSE_MY_STUFF)
|
||||
{
|
||||
myStuff.Update();
|
||||
if (!myStuff.isOpen)
|
||||
{
|
||||
state = PAUSE_MENU;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int controller = controller_get();
|
||||
if (state == PAUSE_HIDDEN)
|
||||
{
|
||||
bool isKeyboardBack = controller == KEYBOARD && g_game->emoteMenuState == 0 &&
|
||||
is_controller_action(KEYBOARD, ACTION_MENU_BACK, ACTION_TRIGGERED);
|
||||
if (is_controller_action(controller, ACTION_PAUSE, ACTION_TRIGGERED) || isKeyboardBack) Show();
|
||||
}
|
||||
else if (state == PAUSE_MENU)
|
||||
{
|
||||
if (is_controller_action(controller, ACTION_PAUSE, ACTION_TRIGGERED) ||
|
||||
is_controller_action(controller, ACTION_MENU_BACK, ACTION_TRIGGERED))
|
||||
{
|
||||
hide();
|
||||
g_manager->isWindowFocused = true;
|
||||
return;
|
||||
}
|
||||
if (menu_update(controller)) return;
|
||||
}
|
||||
else if (state == PAUSE_OPTIONS && is_controller_action(controller, ACTION_MENU_BACK, ACTION_TRIGGERED))
|
||||
state = PAUSE_MENU;
|
||||
|
||||
genericPrompt.Update(PROMPT_INPUT_READ);
|
||||
bool isPromptStopped = !genericPrompt.sprite.animState.animData || !genericPrompt.sprite.animState.isPlaying;
|
||||
if (!isPromptStopped || state != PAUSE_QUIT_PROMPT) return;
|
||||
|
||||
state = PAUSE_MENU;
|
||||
if (genericPrompt.submittedSelection == PROMPT_ANSWER_YES) reconstruction_missing("Game::End 006f9770");
|
||||
}
|
||||
|
||||
// Moves the cursor up and down the entries (wrapping) and confirms the one it is on. True once Resume is confirmed.
|
||||
bool PauseScreen::menu_update(int controller)
|
||||
{
|
||||
if (is_controller_action(controller, ACTION_MENU_UP, ACTION_TRIGGERED))
|
||||
selectedElement = selectedElement == 0 ? PAUSE_ITEM_COUNT - 1 : selectedElement - 1;
|
||||
else if (is_controller_action(controller, ACTION_MENU_DOWN, ACTION_TRIGGERED))
|
||||
selectedElement = selectedElement == PAUSE_ITEM_COUNT - 1 ? 0 : selectedElement + 1;
|
||||
|
||||
menuSprite.SetOverlayFrame(selectedElement);
|
||||
if (!is_controller_action(controller, ACTION_MENU_CONFIRM, ACTION_TRIGGERED)) return false;
|
||||
if (selectedElement == PAUSE_ITEM_RESUME)
|
||||
{
|
||||
hide();
|
||||
return true;
|
||||
}
|
||||
selection_confirm(controller);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Opens the options or My Stuff once the cursor shows, or quits: a daily run asks first, any other fades
|
||||
// out to the menus, forgetting the saved run when the first player is dead for good.
|
||||
void PauseScreen::selection_confirm(int controller)
|
||||
{
|
||||
bool isCursorShown = menuSprite.overlayAnimState.animData;
|
||||
|
||||
switch (selectedElement)
|
||||
{
|
||||
case PAUSE_ITEM_OPTIONS:
|
||||
if (!isCursorShown) break;
|
||||
state = PAUSE_OPTIONS;
|
||||
menuOptions.reload();
|
||||
break;
|
||||
case PAUSE_ITEM_MY_STUFF:
|
||||
if (!isCursorShown) break;
|
||||
state = PAUSE_MY_STUFF;
|
||||
myStuff.reset();
|
||||
layer_show(myStuff.pageSprite, LAYER_BACK_KEY, controller == KEYBOARD);
|
||||
myStuff.isOpen = true;
|
||||
break;
|
||||
case PAUSE_ITEM_EXIT:
|
||||
{
|
||||
if (g_game->dailyChallenge._id != 0)
|
||||
{
|
||||
std::array<std::string, PROMPT_LINES> lines;
|
||||
for (size_t i = 0; i < std::size(QUIT_DAILY_LINES); i++)
|
||||
lines[i] = string_table_translate(g_manager->stringTable, QUIT_DAILY_LINES[i]);
|
||||
genericPrompt.SetText(lines);
|
||||
genericPrompt.Show(PROMPT_LOCAL);
|
||||
state = PAUSE_QUIT_PROMPT;
|
||||
break;
|
||||
}
|
||||
|
||||
menuSprite.overlayAnimState.SetAnimationData(nullptr);
|
||||
Entity_Player* player = g_game->GetPlayer(0);
|
||||
if (player->_dead && player->GetExtraLives() < 1)
|
||||
reconstruction_missing("Game::DeleteSaveState 00959130: GameState::Delete on Manager's game state");
|
||||
game_fade_out();
|
||||
break;
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
// 009b6840 Each frame the screen is open outside a boss intro: cycles the items on the floor while a player holds
|
||||
// Glitched Crown, steps the completion marks, refreshes the HUD, plays the paper (idling with the cursor on the
|
||||
// selection once it appeared, closing once it disappeared) and hides the online lobby's layers.
|
||||
void PauseScreen::animation_update()
|
||||
{
|
||||
Game& game = *g_game;
|
||||
if (state == PAUSE_HIDDEN || (game.roomTransition._mode != 0 && game.roomTransition._bossIntroBossId != 0)) return;
|
||||
|
||||
if (game.playerManager.FirstCollectibleOwner(COLLECTIBLE_GLITCHED_CROWN, LAZARUS_SHARE_CHECK))
|
||||
{
|
||||
EntityList_EL& entities = reinterpret_cast<EntityList*>(game.room->_entityList)->_updateEL;
|
||||
for (uint32_t i = 0; i < entities._size; i++)
|
||||
{
|
||||
Entity* entity = entities._data[i];
|
||||
if (entity->_type == ENTITY_PICKUP && entity->_variant == PICKUP_COLLECTIBLE)
|
||||
static_cast<Entity_Pickup*>(entity)->update_cycle_collectible(0);
|
||||
}
|
||||
}
|
||||
completionWidget.Update();
|
||||
game.hud.refresh_request(HUD_REFRESH_PLAYER);
|
||||
|
||||
const AnimationState& animation = menuSprite.animState;
|
||||
bool isStopped = animation.animData && !animation.isPlaying;
|
||||
if (isStopped && menuSprite.GetAnimation() == ANIMATION_APPEAR)
|
||||
{
|
||||
menuSprite.Play(ANIMATION_IDLE);
|
||||
menuSprite.animState.isPlaying = false;
|
||||
menuSprite.SetOverlayAnimation(ANIMATION_CURSOR);
|
||||
menuSprite.SetOverlayFrame(selectedElement);
|
||||
}
|
||||
else if (isStopped && menuSprite.GetAnimation() == ANIMATION_DISAPPEAR) state = PAUSE_HIDDEN;
|
||||
|
||||
for (const char* layer : ONLINE_LAYERS) layer_show(menuSprite, layer, false);
|
||||
menuSprite.Update();
|
||||
}
|
||||
|
||||
// 009b7190 Draws the open page outside a boss intro: the paper at the bottom right with its seed and completion marks
|
||||
// (outside the no HUD seed, once marks are earned, in a run that can unlock), the options or My Stuff, then the prompt.
|
||||
void PauseScreen::Render()
|
||||
{
|
||||
Game& game = *g_game;
|
||||
if (game.roomTransition._mode != 0 && game.roomTransition._bossIntroBossId != 0) return;
|
||||
|
||||
layer_show(menuSprite, LAYER_MENU_TITLE, false);
|
||||
layer_show(menuSprite, LAYER_SEED_PAPER, game.dailyChallenge._id == 0);
|
||||
Vector position = vector_make(g_screenWidth * PAPER_X, g_screenHeight - g_screenHeight * PAPER_BOTTOM_MARGIN);
|
||||
switch (state)
|
||||
{
|
||||
case PAUSE_MENU:
|
||||
case PAUSE_QUIT_PROMPT:
|
||||
{
|
||||
menuSprite.Render({position});
|
||||
render_seed_paper(position);
|
||||
Seeds& seeds = game.seedEffects;
|
||||
bool isMarksShown = !seeds.HasSeedEffect(SEED_NO_HUD) && completionWidget.markCount > 0 &&
|
||||
!seeds.isCustomRun && !seeds.AchievementUnlocksDisallowed();
|
||||
const NullFrame* widget = isMarksShown && menuSprite.animState.animData
|
||||
? menuSprite.animState.GetNullFrame(NULL_COMPLETION_WIDGET)
|
||||
: nullptr;
|
||||
if (widget) completionWidget.Render(vector_add(position, widget->pos), widget->scale);
|
||||
break;
|
||||
}
|
||||
case PAUSE_OPTIONS: menuOptions.Render(); break;
|
||||
case PAUSE_MY_STUFF: myStuff.Render(); break;
|
||||
default: break;
|
||||
}
|
||||
genericPrompt.Render();
|
||||
}
|
||||
|
||||
// 009b8130 Shows the seed paper outside a daily run and writes the run's seed on it in two halves, a line apart.
|
||||
void PauseScreen::render_seed_paper(Vector position)
|
||||
{
|
||||
LayerState* paper = menuSprite.GetLayer(LAYER_SEED_PAPER);
|
||||
if (!paper) return;
|
||||
|
||||
paper->isVisible = g_game->dailyChallenge._id == 0;
|
||||
const NullFrame* seed = paper->isVisible ? menuSprite.animState.GetNullFrame(NULL_SEED) : nullptr;
|
||||
if (!seed) return;
|
||||
|
||||
Seeds& seeds = g_game->seedEffects;
|
||||
if (seeds.gameStartSeed == 0) KAGE_LogMessage(LOG_ASSERT, (uint8_t*)START_SEED_UNSET);
|
||||
std::string text = Seeds::Seed2String(seeds.gameStartSeed);
|
||||
std::string_view first = std::string_view(text).substr(0, SEED_HALF_LENGTH);
|
||||
std::string_view second = text.size() > SEED_SECOND_HALF
|
||||
? std::string_view(text).substr(SEED_SECOND_HALF, SEED_HALF_LENGTH)
|
||||
: std::string_view();
|
||||
Vector firstLine = vector_add(seed->pos, position);
|
||||
Vector secondLine = vector_make(firstLine.x, firstLine.y + SEED_LINE_HEIGHT);
|
||||
Font& font = g_manager->font2_TeamMeatEx12;
|
||||
FontSettings settings;
|
||||
|
||||
font.DrawString(first, firstLine, vector_make(1, 1), kcolor_argb(PAPER_TEXT_ARGB), settings);
|
||||
font.DrawString(second, secondLine, vector_make(1, 1), kcolor_argb(PAPER_TEXT_ARGB), settings);
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
#pragma once
|
||||
|
||||
#include "anm2.h"
|
||||
#include "completion_widget.h"
|
||||
#include "generic_prompt.h"
|
||||
#include "kage_graphics.h"
|
||||
#include "menu_options.h"
|
||||
#include "rich_text.h"
|
||||
|
||||
// What the pause screen shows. The invite and player info pages are online only.
|
||||
enum PauseState : int
|
||||
{
|
||||
PAUSE_HIDDEN,
|
||||
PAUSE_MENU,
|
||||
PAUSE_OPTIONS,
|
||||
PAUSE_MY_STUFF,
|
||||
PAUSE_QUIT_PROMPT,
|
||||
PAUSE_INVITE,
|
||||
PAUSE_PLAYER_INFO
|
||||
};
|
||||
|
||||
// The pause menu's entries, top to bottom, by the frame of its cursor overlay.
|
||||
enum PauseItem : int
|
||||
{
|
||||
PAUSE_ITEM_OPTIONS,
|
||||
PAUSE_ITEM_MY_STUFF,
|
||||
PAUSE_ITEM_RESUME,
|
||||
PAUSE_ITEM_EXIT,
|
||||
PAUSE_ITEM_COUNT
|
||||
};
|
||||
|
||||
// Destruction (008d2a30) is the default.
|
||||
// The pause screen's "My Stuff" page (PauseScreen_MyStuff): the paused player's items, trinkets and pocket items with
|
||||
// their descriptions, its page sheet, the diary it sits on, the charge and room icons and the section cursor.
|
||||
class PauseScreen_MyStuff
|
||||
{
|
||||
public:
|
||||
RichText descriptionText;
|
||||
KAGE::Graphics::ImagePtr sectionCursorImage;
|
||||
ANM2 chargeSprite;
|
||||
ANM2 diarySprite;
|
||||
ANM2 iconsSprite;
|
||||
ANM2 pageSprite;
|
||||
bool isOpen = false;
|
||||
|
||||
void Init();
|
||||
void diary_load();
|
||||
void reset();
|
||||
void Update();
|
||||
void Render();
|
||||
};
|
||||
|
||||
// Construction and destruction (009b5320, 009b5600) are the defaults.
|
||||
// The pause screen (PauseScreen): the menu paper with the seed, the completion marks and the four entries, the options
|
||||
// and My Stuff pages it opens, and the prompt asking to quit a daily run.
|
||||
// The original also keeps a full-size paper with stat bars and an item strip (PauseScreen.anm2, PauseScreenStats.anm2,
|
||||
// Death Screen.anm2, menu_mystuff.png and render_my_stuff 009b83a0). Show always picks the small paper before anything
|
||||
// draws, so that layout never shows and is left out, with the strip's scrolling in Update and its arrows (009b7f90).
|
||||
// Online only, left out: the drop player menu (008d0fd0, 008d12b0, 008d19a0) and the lobby buttons (009b8990).
|
||||
class PauseScreen
|
||||
{
|
||||
public:
|
||||
CompletionWidget completionWidget;
|
||||
GenericPrompt genericPrompt;
|
||||
Menu_Options menuOptions;
|
||||
PauseScreen_MyStuff myStuff;
|
||||
ANM2 menuSprite;
|
||||
PauseState state = PAUSE_HIDDEN;
|
||||
int playerIdx = 0;
|
||||
int selectedElement = PAUSE_ITEM_RESUME;
|
||||
|
||||
void Init();
|
||||
void load_graphics();
|
||||
void unload_graphics();
|
||||
void Show();
|
||||
void hide();
|
||||
bool is_pausing();
|
||||
void Update();
|
||||
void animation_update();
|
||||
void Render();
|
||||
|
||||
private:
|
||||
int controller_get();
|
||||
bool menu_update(int controller);
|
||||
void selection_confirm(int controller);
|
||||
void render_seed_paper(Vector position);
|
||||
};
|
||||
|
||||
void pause_screen_unload_sprites();
|
||||
void graphics_reload();
|
||||
@@ -101,118 +101,8 @@ struct ChunkName
|
||||
ChunkCount count = CHUNK_COUNT_AS_FILED;
|
||||
};
|
||||
|
||||
// The slots of a character's row in COMPLETION_MARKS, as REPENTOGON's CompletionType.
|
||||
// GREED_DONATION holds a counter only, HARD and the TAINTED ones an achievement only.
|
||||
enum CompletionType
|
||||
{
|
||||
COMPLETION_MOMS_HEART,
|
||||
COMPLETION_ISAAC,
|
||||
COMPLETION_SATAN,
|
||||
COMPLETION_BOSS_RUSH,
|
||||
COMPLETION_BLUE_BABY,
|
||||
COMPLETION_LAMB,
|
||||
COMPLETION_MEGA_SATAN,
|
||||
COMPLETION_ULTRA_GREED,
|
||||
COMPLETION_GREED_DONATION,
|
||||
COMPLETION_HUSH,
|
||||
COMPLETION_HARD,
|
||||
COMPLETION_ULTRA_GREEDIER,
|
||||
COMPLETION_DELIRIUM,
|
||||
COMPLETION_MOTHER,
|
||||
COMPLETION_BEAST,
|
||||
COMPLETION_TAINTED,
|
||||
COMPLETION_TAINTED_GROUP1,
|
||||
COMPLETION_TAINTED_GROUP2,
|
||||
COMPLETION_TYPE_COUNT
|
||||
};
|
||||
|
||||
// A completion mark: the event counter holding its difficulty bits and the achievement it unlocks.
|
||||
struct CompletionMark
|
||||
{
|
||||
int counter;
|
||||
int achievement;
|
||||
};
|
||||
|
||||
constexpr int COMPLETION_PLAYER_TYPE_COUNT = 41;
|
||||
// The bit of a completion mark set by a win on hard.
|
||||
constexpr int COMPLETION_HARD_BIT = 2;
|
||||
// Every character's completion marks, by player type (0c35ed0 in the exe).
|
||||
constexpr CompletionMark COMPLETION_MARKS[COMPLETION_PLAYER_TYPE_COUNT][COMPLETION_TYPE_COUNT] = {
|
||||
{{27, 167}, {41, 106}, {55, 43}, {69, 70}, {83, 49}, {97, 149}, {116, 205}, {130, 192}, {159, 0},
|
||||
{144, 179}, {0, 253}, {0, 296}, {173, 282}, {423, 440}, {457, 441}, {0, 474}, {0, 0}, {0, 0}},
|
||||
{{28, 168}, {42, 20}, {56, 45}, {70, 109}, {84, 50}, {98, 71}, {117, 206}, {131, 193}, {160, 0},
|
||||
{145, 180}, {0, 254}, {0, 297}, {174, 283}, {424, 442}, {458, 443}, {0, 475}, {0, 0}, {0, 0}},
|
||||
{{29, 171}, {43, 21}, {57, 46}, {71, 110}, {85, 75}, {99, 51}, {118, 207}, {132, 194}, {161, 0},
|
||||
{146, 181}, {0, 261}, {0, 298}, {175, 284}, {425, 444}, {459, 445}, {0, 476}, {0, 0}, {0, 0}},
|
||||
{{30, 170}, {44, 107}, {58, 72}, {72, 108}, {86, 77}, {100, 52}, {119, 208}, {133, 195}, {162, 0},
|
||||
{147, 182}, {0, 263}, {0, 299}, {176, 285}, {426, 446}, {460, 447}, {0, 477}, {0, 0}, {0, 0}},
|
||||
{{31, 174}, {45, 29}, {59, 48}, {73, 114}, {87, 113}, {101, 73}, {120, 209}, {134, 196}, {163, 0},
|
||||
{148, 183}, {0, 252}, {0, 300}, {177, 286}, {427, 448}, {461, 449}, {0, 478}, {0, 0}, {0, 0}},
|
||||
{{32, 169}, {46, 76}, {60, 44}, {74, 112}, {88, 53}, {102, 111}, {121, 210}, {135, 197}, {164, 0},
|
||||
{149, 184}, {0, 255}, {0, 302}, {178, 288}, {428, 450}, {462, 451}, {0, 479}, {0, 0}, {0, 0}},
|
||||
{{33, 177}, {47, 54}, {61, 56}, {75, 115}, {89, 55}, {103, 74}, {122, 211}, {136, 198}, {165, 0},
|
||||
{150, 185}, {0, 262}, {0, 301}, {179, 287}, {429, 452}, {463, 453}, {0, 480}, {0, 0}, {0, 0}},
|
||||
{{34, 173}, {48, 126}, {62, 127}, {76, 9}, {90, 128}, {104, 47}, {123, 212}, {137, 199}, {166, 0},
|
||||
{151, 186}, {0, 259}, {0, 304}, {180, 290}, {430, 454}, {464, 455}, {0, 481}, {0, 0}, {0, 0}},
|
||||
{{35, 172}, {49, 116}, {63, 117}, {77, 105}, {91, 118}, {105, 119}, {124, 213}, {138, 200}, {167, 0},
|
||||
{152, 187}, {0, 257}, {0, 305}, {181, 291}, {431, 456}, {465, 457}, {0, 482}, {0, 0}, {0, 0}},
|
||||
{{36, 176}, {50, 121}, {64, 122}, {78, 125}, {92, 123}, {106, 124}, {125, 214}, {139, 201}, {168, 0},
|
||||
{153, 188}, {0, 256}, {0, 303}, {182, 289}, {432, 458}, {466, 459}, {0, 483}, {0, 0}, {0, 0}},
|
||||
{{37, 175}, {51, 129}, {65, 130}, {79, 133}, {93, 131}, {107, 132}, {126, 215}, {140, 202}, {169, 0},
|
||||
{154, 189}, {0, 156}, {0, 307}, {183, 293}, {433, 460}, {467, 461}, {0, 484}, {0, 0}, {0, 0}},
|
||||
{},
|
||||
{},
|
||||
{{38, 223}, {52, 218}, {66, 220}, {80, 222}, {94, 219}, {108, 221}, {127, 216}, {141, 203}, {170, 0},
|
||||
{155, 190}, {0, 260}, {0, 306}, {184, 292}, {434, 462}, {468, 463}, {0, 485}, {0, 0}, {0, 0}},
|
||||
{{39, 241}, {53, 236}, {67, 237}, {81, 240}, {95, 238}, {109, 239}, {128, 217}, {142, 204}, {171, 0},
|
||||
{156, 191}, {0, 264}, {0, 308}, {185, 294}, {435, 464}, {469, 465}, {0, 486}, {0, 0}, {0, 0}},
|
||||
{{40, 318}, {54, 310}, {68, 311}, {82, 314}, {96, 312}, {110, 313}, {129, 317}, {143, 316}, {172, 0},
|
||||
{157, 315}, {0, 319}, {0, 309}, {186, 295}, {436, 466}, {470, 467}, {0, 487}, {0, 0}, {0, 0}},
|
||||
{{203, 392}, {204, 393}, {205, 394}, {206, 397}, {207, 395}, {208, 396}, {209, 403}, {210, 399}, {212, 0},
|
||||
{211, 398}, {0, 402}, {0, 400}, {213, 401}, {437, 468}, {471, 469}, {0, 488}, {0, 0}, {0, 0}},
|
||||
{},
|
||||
{{214, 416}, {233, 417}, {252, 418}, {271, 421}, {290, 419}, {309, 420}, {328, 427}, {347, 422}, {385, 0},
|
||||
{366, 423}, {0, 426}, {0, 424}, {404, 425}, {438, 470}, {472, 471}, {0, 489}, {0, 0}, {0, 0}},
|
||||
{{215, 428}, {234, 429}, {253, 430}, {272, 433}, {291, 431}, {310, 432}, {329, 439}, {348, 434}, {386, 0},
|
||||
{367, 435}, {0, 438}, {0, 436}, {405, 437}, {439, 472}, {473, 473}, {0, 490}, {0, 0}, {0, 0}},
|
||||
{},
|
||||
{{216, 0}, {235, 0}, {254, 0}, {273, 0}, {292, 0}, {311, 0}, {330, 601}, {349, 0}, {387, 0},
|
||||
{368, 0}, {0, 0}, {0, 541}, {406, 584}, {440, 549}, {474, 491}, {0, 0}, {0, 548}, {0, 618}},
|
||||
{{217, 0}, {236, 0}, {255, 0}, {274, 0}, {293, 0}, {312, 0}, {331, 602}, {350, 0}, {388, 0},
|
||||
{369, 0}, {0, 0}, {0, 530}, {407, 585}, {441, 551}, {475, 492}, {0, 0}, {0, 550}, {0, 619}},
|
||||
{{218, 0}, {237, 0}, {256, 0}, {275, 0}, {294, 0}, {313, 0}, {332, 603}, {351, 0}, {389, 0},
|
||||
{370, 0}, {0, 0}, {0, 534}, {408, 586}, {442, 553}, {476, 493}, {0, 0}, {0, 552}, {0, 620}},
|
||||
{{219, 0}, {238, 0}, {257, 0}, {276, 0}, {295, 0}, {314, 0}, {333, 604}, {352, 0}, {390, 0},
|
||||
{371, 0}, {0, 0}, {0, 525}, {409, 587}, {443, 555}, {477, 494}, {0, 0}, {0, 554}, {0, 621}},
|
||||
{{220, 0}, {239, 0}, {258, 0}, {277, 0}, {296, 0}, {315, 0}, {334, 605}, {353, 0}, {391, 0},
|
||||
{372, 0}, {0, 0}, {0, 528}, {410, 588}, {444, 557}, {478, 495}, {0, 0}, {0, 556}, {0, 622}},
|
||||
{{221, 0}, {240, 0}, {259, 0}, {278, 0}, {297, 0}, {316, 0}, {335, 606}, {354, 0}, {392, 0},
|
||||
{373, 0}, {0, 0}, {0, 527}, {411, 589}, {445, 559}, {479, 496}, {0, 0}, {0, 558}, {0, 623}},
|
||||
{{222, 0}, {241, 0}, {260, 0}, {279, 0}, {298, 0}, {317, 0}, {336, 607}, {355, 0}, {393, 0},
|
||||
{374, 0}, {0, 0}, {0, 535}, {412, 590}, {446, 561}, {480, 497}, {0, 0}, {0, 560}, {0, 624}},
|
||||
{{223, 0}, {242, 0}, {261, 0}, {280, 0}, {299, 0}, {318, 0}, {337, 608}, {356, 0}, {394, 0},
|
||||
{375, 0}, {0, 0}, {0, 539}, {413, 591}, {447, 563}, {481, 498}, {0, 0}, {0, 562}, {0, 625}},
|
||||
{{224, 0}, {243, 0}, {262, 0}, {281, 0}, {300, 0}, {319, 0}, {338, 609}, {357, 0}, {395, 0},
|
||||
{376, 0}, {0, 0}, {0, 543}, {414, 592}, {448, 565}, {482, 499}, {0, 0}, {0, 564}, {0, 626}},
|
||||
{{225, 0}, {244, 0}, {263, 0}, {282, 0}, {301, 0}, {320, 0}, {339, 610}, {358, 0}, {396, 0},
|
||||
{377, 0}, {0, 0}, {0, 544}, {415, 593}, {449, 567}, {483, 500}, {0, 0}, {0, 566}, {0, 627}},
|
||||
{{226, 0}, {245, 0}, {264, 0}, {283, 0}, {302, 0}, {321, 0}, {340, 611}, {359, 0}, {397, 0},
|
||||
{378, 0}, {0, 0}, {0, 524}, {416, 594}, {450, 569}, {484, 501}, {0, 0}, {0, 568}, {0, 628}},
|
||||
{{227, 0}, {246, 0}, {265, 0}, {284, 0}, {303, 0}, {322, 0}, {341, 612}, {360, 0}, {398, 0},
|
||||
{379, 0}, {0, 0}, {0, 526}, {417, 595}, {451, 571}, {485, 502}, {0, 0}, {0, 570}, {0, 629}},
|
||||
{{228, 0}, {247, 0}, {266, 0}, {285, 0}, {304, 0}, {323, 0}, {342, 613}, {361, 0}, {399, 0},
|
||||
{380, 0}, {0, 0}, {0, 536}, {418, 596}, {452, 573}, {486, 503}, {0, 0}, {0, 572}, {0, 630}},
|
||||
{{229, 0}, {248, 0}, {267, 0}, {286, 0}, {305, 0}, {324, 0}, {343, 614}, {362, 0}, {400, 0},
|
||||
{381, 0}, {0, 0}, {0, 540}, {419, 597}, {453, 575}, {487, 504}, {0, 0}, {0, 574}, {0, 631}},
|
||||
{{230, 0}, {249, 0}, {268, 0}, {287, 0}, {306, 0}, {325, 0}, {344, 615}, {363, 0}, {401, 0},
|
||||
{382, 0}, {0, 0}, {0, 537}, {420, 598}, {454, 577}, {488, 505}, {0, 0}, {0, 576}, {0, 632}},
|
||||
{{231, 0}, {250, 0}, {269, 0}, {288, 0}, {307, 0}, {326, 0}, {345, 616}, {364, 0}, {402, 0},
|
||||
{383, 0}, {0, 0}, {0, 529}, {421, 599}, {455, 579}, {489, 506}, {0, 0}, {0, 578}, {0, 633}},
|
||||
{{232, 0}, {251, 0}, {270, 0}, {289, 0}, {308, 0}, {327, 0}, {346, 617}, {365, 0}, {403, 0},
|
||||
{384, 0}, {0, 0}, {0, 542}, {422, 600}, {456, 581}, {490, 507}, {0, 0}, {0, 580}, {0, 634}},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
};
|
||||
|
||||
// The marks counted toward a character's full set, all twelve on hard for the HARD achievement.
|
||||
constexpr std::array<CompletionType, 12> COMPLETION_FULL_SET = {
|
||||
@@ -439,7 +329,7 @@ static void chunk_read(SaveReader& reader, uint32_t chunkSize, Entries& entries,
|
||||
}
|
||||
|
||||
// Loads a whole file, false when it cannot be opened.
|
||||
static bool file_load(std::string_view path, std::vector<uint8_t>& data)
|
||||
bool file_load(std::string_view path, std::vector<uint8_t>& data)
|
||||
{
|
||||
size_t size = 0;
|
||||
void* bytes = SDL_LoadFile(std::string(path).c_str(), &size);
|
||||
|
||||
@@ -39,6 +39,118 @@ struct Checksum
|
||||
uint32_t value_get();
|
||||
};
|
||||
|
||||
// The slots of a character's row in COMPLETION_MARKS, as REPENTOGON's CompletionType.
|
||||
// GREED_DONATION holds a counter only, HARD and the TAINTED ones an achievement only.
|
||||
enum CompletionType
|
||||
{
|
||||
COMPLETION_MOMS_HEART,
|
||||
COMPLETION_ISAAC,
|
||||
COMPLETION_SATAN,
|
||||
COMPLETION_BOSS_RUSH,
|
||||
COMPLETION_BLUE_BABY,
|
||||
COMPLETION_LAMB,
|
||||
COMPLETION_MEGA_SATAN,
|
||||
COMPLETION_ULTRA_GREED,
|
||||
COMPLETION_GREED_DONATION,
|
||||
COMPLETION_HUSH,
|
||||
COMPLETION_HARD,
|
||||
COMPLETION_ULTRA_GREEDIER,
|
||||
COMPLETION_DELIRIUM,
|
||||
COMPLETION_MOTHER,
|
||||
COMPLETION_BEAST,
|
||||
COMPLETION_TAINTED,
|
||||
COMPLETION_TAINTED_GROUP1,
|
||||
COMPLETION_TAINTED_GROUP2,
|
||||
COMPLETION_TYPE_COUNT
|
||||
};
|
||||
|
||||
// A completion mark: the event counter holding its difficulty bits and the achievement it unlocks.
|
||||
struct CompletionMark
|
||||
{
|
||||
int counter;
|
||||
int achievement;
|
||||
};
|
||||
|
||||
constexpr int COMPLETION_PLAYER_TYPE_COUNT = 41;
|
||||
// Every character's completion marks, by player type (0c35ed0 in the exe).
|
||||
inline constexpr CompletionMark COMPLETION_MARKS[COMPLETION_PLAYER_TYPE_COUNT][COMPLETION_TYPE_COUNT] = {
|
||||
{{27, 167}, {41, 106}, {55, 43}, {69, 70}, {83, 49}, {97, 149}, {116, 205}, {130, 192}, {159, 0},
|
||||
{144, 179}, {0, 253}, {0, 296}, {173, 282}, {423, 440}, {457, 441}, {0, 474}, {0, 0}, {0, 0}},
|
||||
{{28, 168}, {42, 20}, {56, 45}, {70, 109}, {84, 50}, {98, 71}, {117, 206}, {131, 193}, {160, 0},
|
||||
{145, 180}, {0, 254}, {0, 297}, {174, 283}, {424, 442}, {458, 443}, {0, 475}, {0, 0}, {0, 0}},
|
||||
{{29, 171}, {43, 21}, {57, 46}, {71, 110}, {85, 75}, {99, 51}, {118, 207}, {132, 194}, {161, 0},
|
||||
{146, 181}, {0, 261}, {0, 298}, {175, 284}, {425, 444}, {459, 445}, {0, 476}, {0, 0}, {0, 0}},
|
||||
{{30, 170}, {44, 107}, {58, 72}, {72, 108}, {86, 77}, {100, 52}, {119, 208}, {133, 195}, {162, 0},
|
||||
{147, 182}, {0, 263}, {0, 299}, {176, 285}, {426, 446}, {460, 447}, {0, 477}, {0, 0}, {0, 0}},
|
||||
{{31, 174}, {45, 29}, {59, 48}, {73, 114}, {87, 113}, {101, 73}, {120, 209}, {134, 196}, {163, 0},
|
||||
{148, 183}, {0, 252}, {0, 300}, {177, 286}, {427, 448}, {461, 449}, {0, 478}, {0, 0}, {0, 0}},
|
||||
{{32, 169}, {46, 76}, {60, 44}, {74, 112}, {88, 53}, {102, 111}, {121, 210}, {135, 197}, {164, 0},
|
||||
{149, 184}, {0, 255}, {0, 302}, {178, 288}, {428, 450}, {462, 451}, {0, 479}, {0, 0}, {0, 0}},
|
||||
{{33, 177}, {47, 54}, {61, 56}, {75, 115}, {89, 55}, {103, 74}, {122, 211}, {136, 198}, {165, 0},
|
||||
{150, 185}, {0, 262}, {0, 301}, {179, 287}, {429, 452}, {463, 453}, {0, 480}, {0, 0}, {0, 0}},
|
||||
{{34, 173}, {48, 126}, {62, 127}, {76, 9}, {90, 128}, {104, 47}, {123, 212}, {137, 199}, {166, 0},
|
||||
{151, 186}, {0, 259}, {0, 304}, {180, 290}, {430, 454}, {464, 455}, {0, 481}, {0, 0}, {0, 0}},
|
||||
{{35, 172}, {49, 116}, {63, 117}, {77, 105}, {91, 118}, {105, 119}, {124, 213}, {138, 200}, {167, 0},
|
||||
{152, 187}, {0, 257}, {0, 305}, {181, 291}, {431, 456}, {465, 457}, {0, 482}, {0, 0}, {0, 0}},
|
||||
{{36, 176}, {50, 121}, {64, 122}, {78, 125}, {92, 123}, {106, 124}, {125, 214}, {139, 201}, {168, 0},
|
||||
{153, 188}, {0, 256}, {0, 303}, {182, 289}, {432, 458}, {466, 459}, {0, 483}, {0, 0}, {0, 0}},
|
||||
{{37, 175}, {51, 129}, {65, 130}, {79, 133}, {93, 131}, {107, 132}, {126, 215}, {140, 202}, {169, 0},
|
||||
{154, 189}, {0, 156}, {0, 307}, {183, 293}, {433, 460}, {467, 461}, {0, 484}, {0, 0}, {0, 0}},
|
||||
{},
|
||||
{},
|
||||
{{38, 223}, {52, 218}, {66, 220}, {80, 222}, {94, 219}, {108, 221}, {127, 216}, {141, 203}, {170, 0},
|
||||
{155, 190}, {0, 260}, {0, 306}, {184, 292}, {434, 462}, {468, 463}, {0, 485}, {0, 0}, {0, 0}},
|
||||
{{39, 241}, {53, 236}, {67, 237}, {81, 240}, {95, 238}, {109, 239}, {128, 217}, {142, 204}, {171, 0},
|
||||
{156, 191}, {0, 264}, {0, 308}, {185, 294}, {435, 464}, {469, 465}, {0, 486}, {0, 0}, {0, 0}},
|
||||
{{40, 318}, {54, 310}, {68, 311}, {82, 314}, {96, 312}, {110, 313}, {129, 317}, {143, 316}, {172, 0},
|
||||
{157, 315}, {0, 319}, {0, 309}, {186, 295}, {436, 466}, {470, 467}, {0, 487}, {0, 0}, {0, 0}},
|
||||
{{203, 392}, {204, 393}, {205, 394}, {206, 397}, {207, 395}, {208, 396}, {209, 403}, {210, 399}, {212, 0},
|
||||
{211, 398}, {0, 402}, {0, 400}, {213, 401}, {437, 468}, {471, 469}, {0, 488}, {0, 0}, {0, 0}},
|
||||
{},
|
||||
{{214, 416}, {233, 417}, {252, 418}, {271, 421}, {290, 419}, {309, 420}, {328, 427}, {347, 422}, {385, 0},
|
||||
{366, 423}, {0, 426}, {0, 424}, {404, 425}, {438, 470}, {472, 471}, {0, 489}, {0, 0}, {0, 0}},
|
||||
{{215, 428}, {234, 429}, {253, 430}, {272, 433}, {291, 431}, {310, 432}, {329, 439}, {348, 434}, {386, 0},
|
||||
{367, 435}, {0, 438}, {0, 436}, {405, 437}, {439, 472}, {473, 473}, {0, 490}, {0, 0}, {0, 0}},
|
||||
{},
|
||||
{{216, 0}, {235, 0}, {254, 0}, {273, 0}, {292, 0}, {311, 0}, {330, 601}, {349, 0}, {387, 0},
|
||||
{368, 0}, {0, 0}, {0, 541}, {406, 584}, {440, 549}, {474, 491}, {0, 0}, {0, 548}, {0, 618}},
|
||||
{{217, 0}, {236, 0}, {255, 0}, {274, 0}, {293, 0}, {312, 0}, {331, 602}, {350, 0}, {388, 0},
|
||||
{369, 0}, {0, 0}, {0, 530}, {407, 585}, {441, 551}, {475, 492}, {0, 0}, {0, 550}, {0, 619}},
|
||||
{{218, 0}, {237, 0}, {256, 0}, {275, 0}, {294, 0}, {313, 0}, {332, 603}, {351, 0}, {389, 0},
|
||||
{370, 0}, {0, 0}, {0, 534}, {408, 586}, {442, 553}, {476, 493}, {0, 0}, {0, 552}, {0, 620}},
|
||||
{{219, 0}, {238, 0}, {257, 0}, {276, 0}, {295, 0}, {314, 0}, {333, 604}, {352, 0}, {390, 0},
|
||||
{371, 0}, {0, 0}, {0, 525}, {409, 587}, {443, 555}, {477, 494}, {0, 0}, {0, 554}, {0, 621}},
|
||||
{{220, 0}, {239, 0}, {258, 0}, {277, 0}, {296, 0}, {315, 0}, {334, 605}, {353, 0}, {391, 0},
|
||||
{372, 0}, {0, 0}, {0, 528}, {410, 588}, {444, 557}, {478, 495}, {0, 0}, {0, 556}, {0, 622}},
|
||||
{{221, 0}, {240, 0}, {259, 0}, {278, 0}, {297, 0}, {316, 0}, {335, 606}, {354, 0}, {392, 0},
|
||||
{373, 0}, {0, 0}, {0, 527}, {411, 589}, {445, 559}, {479, 496}, {0, 0}, {0, 558}, {0, 623}},
|
||||
{{222, 0}, {241, 0}, {260, 0}, {279, 0}, {298, 0}, {317, 0}, {336, 607}, {355, 0}, {393, 0},
|
||||
{374, 0}, {0, 0}, {0, 535}, {412, 590}, {446, 561}, {480, 497}, {0, 0}, {0, 560}, {0, 624}},
|
||||
{{223, 0}, {242, 0}, {261, 0}, {280, 0}, {299, 0}, {318, 0}, {337, 608}, {356, 0}, {394, 0},
|
||||
{375, 0}, {0, 0}, {0, 539}, {413, 591}, {447, 563}, {481, 498}, {0, 0}, {0, 562}, {0, 625}},
|
||||
{{224, 0}, {243, 0}, {262, 0}, {281, 0}, {300, 0}, {319, 0}, {338, 609}, {357, 0}, {395, 0},
|
||||
{376, 0}, {0, 0}, {0, 543}, {414, 592}, {448, 565}, {482, 499}, {0, 0}, {0, 564}, {0, 626}},
|
||||
{{225, 0}, {244, 0}, {263, 0}, {282, 0}, {301, 0}, {320, 0}, {339, 610}, {358, 0}, {396, 0},
|
||||
{377, 0}, {0, 0}, {0, 544}, {415, 593}, {449, 567}, {483, 500}, {0, 0}, {0, 566}, {0, 627}},
|
||||
{{226, 0}, {245, 0}, {264, 0}, {283, 0}, {302, 0}, {321, 0}, {340, 611}, {359, 0}, {397, 0},
|
||||
{378, 0}, {0, 0}, {0, 524}, {416, 594}, {450, 569}, {484, 501}, {0, 0}, {0, 568}, {0, 628}},
|
||||
{{227, 0}, {246, 0}, {265, 0}, {284, 0}, {303, 0}, {322, 0}, {341, 612}, {360, 0}, {398, 0},
|
||||
{379, 0}, {0, 0}, {0, 526}, {417, 595}, {451, 571}, {485, 502}, {0, 0}, {0, 570}, {0, 629}},
|
||||
{{228, 0}, {247, 0}, {266, 0}, {285, 0}, {304, 0}, {323, 0}, {342, 613}, {361, 0}, {399, 0},
|
||||
{380, 0}, {0, 0}, {0, 536}, {418, 596}, {452, 573}, {486, 503}, {0, 0}, {0, 572}, {0, 630}},
|
||||
{{229, 0}, {248, 0}, {267, 0}, {286, 0}, {305, 0}, {324, 0}, {343, 614}, {362, 0}, {400, 0},
|
||||
{381, 0}, {0, 0}, {0, 540}, {419, 597}, {453, 575}, {487, 504}, {0, 0}, {0, 574}, {0, 631}},
|
||||
{{230, 0}, {249, 0}, {268, 0}, {287, 0}, {306, 0}, {325, 0}, {344, 615}, {363, 0}, {401, 0},
|
||||
{382, 0}, {0, 0}, {0, 537}, {420, 598}, {454, 577}, {488, 505}, {0, 0}, {0, 576}, {0, 632}},
|
||||
{{231, 0}, {250, 0}, {269, 0}, {288, 0}, {307, 0}, {326, 0}, {345, 616}, {364, 0}, {402, 0},
|
||||
{383, 0}, {0, 0}, {0, 529}, {421, 599}, {455, 579}, {489, 506}, {0, 0}, {0, 578}, {0, 633}},
|
||||
{{232, 0}, {251, 0}, {270, 0}, {289, 0}, {308, 0}, {327, 0}, {346, 617}, {365, 0}, {403, 0},
|
||||
{384, 0}, {0, 0}, {0, 542}, {422, 600}, {456, 581}, {490, 507}, {0, 0}, {0, 580}, {0, 634}},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
};
|
||||
|
||||
// Whether Clear also restarts the count of saves written.
|
||||
enum ClearMode
|
||||
{
|
||||
@@ -120,3 +232,6 @@ private:
|
||||
void check_collection_set_unlocks();
|
||||
bool TryImportLocalSave(std::string_view path, const SaveImport& import);
|
||||
};
|
||||
|
||||
// Loads a whole file, false when it cannot be opened.
|
||||
bool file_load(std::string_view path, std::vector<uint8_t>& data);
|
||||
@@ -0,0 +1,72 @@
|
||||
#include "preload_manager.h"
|
||||
#include "data.h"
|
||||
#include "manager.h"
|
||||
#include "platform.h"
|
||||
#include "texture_cache.h"
|
||||
#include <optional>
|
||||
|
||||
constexpr std::string_view ROOT_TAG = "preloads";
|
||||
constexpr std::string_view GROUP_TAG = "preload";
|
||||
|
||||
// An attribute when the element has it, empty or not.
|
||||
static std::optional<std::string_view> attr_find(DataNode node, std::string_view name)
|
||||
{
|
||||
std::string_view value;
|
||||
if (node["attrs"][name].get(value) != simdjson::SUCCESS) return std::nullopt;
|
||||
return value;
|
||||
}
|
||||
|
||||
// The first element of a document with a tag, as rapidxml's first_node finds it.
|
||||
static std::optional<DataNode> root_find(const Data& data, std::string_view tag)
|
||||
{
|
||||
if (node_tag(data.root) == tag) return data.root;
|
||||
for (DataNode node : node_children(data.root))
|
||||
if (node_tag(node) == tag) return node;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// 009c6860 Reads preload.xml into the groups. Every element from the first <preload> on that has an id adds the path
|
||||
// of each of its children to the group of that id. False when the file is missing.
|
||||
// The original crashes on a file without its root element. Here that logs and reads as empty.
|
||||
bool PreloadManager::xml_load(std::string_view path)
|
||||
{
|
||||
Data data;
|
||||
|
||||
data_load(data, path);
|
||||
if (!data.isLoaded) return false;
|
||||
|
||||
std::optional<DataNode> root = root_find(data, ROOT_TAG);
|
||||
if (!root)
|
||||
{
|
||||
log_printf(LOG_ASSERT, "Could not find root node 'preloads' in %s\n", std::string(path).c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool isStarted = false;
|
||||
for (DataNode node : node_children(*root))
|
||||
{
|
||||
isStarted = isStarted || node_tag(node) == GROUP_TAG;
|
||||
std::optional<std::string_view> id = attr_find(node, "id");
|
||||
if (!isStarted || !id) continue;
|
||||
|
||||
PreloadGroup& group = groups[std::string(*id)];
|
||||
for (DataNode child : node_children(node))
|
||||
if (auto imagePath = attr_find(child, "path")) group.entries.push_back({std::string(*imagePath), nullptr});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// 009c6c90 Loads a group's images into the texture cache, the first time it is asked for. An unknown group loads
|
||||
// nothing.
|
||||
void PreloadManager::group_load(std::string_view name)
|
||||
{
|
||||
auto found = groups.find(std::string(name));
|
||||
if (found == groups.end() || found->second.isLoaded) return;
|
||||
|
||||
for (PreloadEntry& entry : found->second.entries)
|
||||
{
|
||||
entry.image = Manager::LoadImage(entry.path);
|
||||
TextureCache::Add(entry.image);
|
||||
}
|
||||
found->second.isLoaded = true;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include "kage_graphics.h"
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
// An image preload.xml lists, and the image once its group is loaded.
|
||||
struct PreloadEntry
|
||||
{
|
||||
std::string path;
|
||||
KAGE::Graphics::ImagePtr image;
|
||||
};
|
||||
|
||||
// The images of one preload.xml group, loaded together the first time the group is asked for.
|
||||
struct PreloadGroup
|
||||
{
|
||||
std::vector<PreloadEntry> entries;
|
||||
bool isLoaded = false;
|
||||
};
|
||||
|
||||
// Construction, destruction and the group map's insertion (009c6e10) are the defaults.
|
||||
// The preloads (Game's PreloadManager): preload.xml's image groups by id, each loaded once into the texture cache and
|
||||
// held there for the rest of the game.
|
||||
class PreloadManager
|
||||
{
|
||||
public:
|
||||
std::unordered_map<std::string, PreloadGroup> groups;
|
||||
|
||||
bool xml_load(std::string_view path);
|
||||
void group_load(std::string_view name);
|
||||
};
|
||||
@@ -0,0 +1,61 @@
|
||||
#include "procedural_item_manager.h"
|
||||
#include "game.h"
|
||||
#include "log.h"
|
||||
#include "manager.h"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
|
||||
constexpr const char* ITEM_SURFACE = "Procedural Item Surface";
|
||||
constexpr const char* COLLECTION_SURFACE = "Procedural Item Collection Surface";
|
||||
constexpr int ITEM_SURFACE_SIZE = 1024;
|
||||
constexpr int COLLECTION_SURFACE_SIZE = 512;
|
||||
|
||||
// The seed of the glitched item a G FUEL! run starts with.
|
||||
constexpr uint32_t G_FUEL_ITEM_SEED = 1;
|
||||
|
||||
// The actives a glitched item never uses: Forget Me Now, Pandora's Box, Diplopia, Plan C, Clicker, Mama Mega!,
|
||||
// Eden's Soul, Mystery Gift, Alabaster Box, Death Certificate and R Key.
|
||||
constexpr std::array<int, 11> UNUSABLE_ACTIVES = {127, 297, 347, 475, 482, 483, 490, 515, 585, 628, 636};
|
||||
|
||||
// Creates a square surface of that size, cleared to transparent, unless it exists.
|
||||
static void surface_create(KAGE::Graphics::ImagePtr& surface, const char* name, int size)
|
||||
{
|
||||
if (!surface) surface = KAGE::Graphics::manager.render_target_create({{}, name, size, size});
|
||||
}
|
||||
|
||||
// 009dc830 Starts over: creates the surfaces when missing, frees the glitched items, lists the actives their effects
|
||||
// may use, forgets the spawn triggers and clears both surfaces. A G FUEL! run then gets its glitched item.
|
||||
void ProceduralItemManager::Init()
|
||||
{
|
||||
KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager;
|
||||
|
||||
surface_create(renderTarget, ITEM_SURFACE, ITEM_SURFACE_SIZE);
|
||||
surface_create(collectionRenderTarget, COLLECTION_SURFACE, COLLECTION_SURFACE_SIZE);
|
||||
proceduralItems.clear();
|
||||
|
||||
usableActives.clear();
|
||||
for (std::unique_ptr<ItemConfig_Item>& item : g_manager->itemConfig.collectibles)
|
||||
if (item && item->type == ITEM_ACTIVE && std::ranges::count(UNUSABLE_ACTIVES, item->id) == 0)
|
||||
usableActives.push_back(item.get());
|
||||
spawnTriggerTargets.clear();
|
||||
|
||||
graphics.render_target_push(renderTarget.get(), KAGE::Graphics::TARGET_OWN_SIZE, KAGE::Graphics::PRESENT_FLUSH);
|
||||
graphics.Clear();
|
||||
graphics.SetRenderTarget(collectionRenderTarget.get(), KAGE::Graphics::TARGET_OWN_SIZE);
|
||||
graphics.Clear();
|
||||
graphics.render_target_pop(KAGE::Graphics::PRESENT_FLUSH);
|
||||
|
||||
if (g_game->seedEffects.HasSeedEffect(SEED_G_FUEL)) CreateProceduralItem(G_FUEL_ITEM_SEED, 0);
|
||||
}
|
||||
|
||||
// 009e0340 Starts over, then makes the glitched items of a saved run again from their seeds, in order.
|
||||
void ProceduralItemManager::items_restore(const std::vector<uint32_t>& seeds)
|
||||
{
|
||||
Init();
|
||||
for (uint32_t seed : seeds) CreateProceduralItem(seed, 0);
|
||||
}
|
||||
|
||||
int ProceduralItemManager::CreateProceduralItem(uint32_t, uint32_t)
|
||||
{
|
||||
reconstruction_missing("ProceduralItemManager::CreateProceduralItem 009dcc70");
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "kage_graphics.h"
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
// Destruction (009dc750) is the default.
|
||||
// The glitched items TMTRAINER makes (Game's ProceduralItemManager): the items by -1 - id, the render surfaces their
|
||||
// sprites are drawn into, the actives their effects may use, and the (type, variant) spawns some of them trigger on.
|
||||
class ProceduralItemManager
|
||||
{
|
||||
public:
|
||||
std::vector<std::unique_ptr<ProceduralItem>> proceduralItems;
|
||||
std::vector<ItemConfig_Item*> usableActives;
|
||||
std::set<std::pair<uint32_t, int>> spawnTriggerTargets;
|
||||
KAGE::Graphics::ImagePtr renderTarget;
|
||||
KAGE::Graphics::ImagePtr collectionRenderTarget;
|
||||
|
||||
void Init();
|
||||
void items_restore(const std::vector<uint32_t>& seeds);
|
||||
int CreateProceduralItem(uint32_t seed, uint32_t flags);
|
||||
};
|
||||
@@ -0,0 +1,170 @@
|
||||
#include "revive_player_menu.h"
|
||||
#include "game.h"
|
||||
#include "kage_input.h"
|
||||
#include "log.h"
|
||||
#include "manager.h"
|
||||
#include "menu_manager.h"
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
|
||||
constexpr const char* MENU_ANM2 = "gfx/ui/Menu_RevivePlayer.anm2";
|
||||
constexpr const char* SELECTOR_ANM2 = "gfx/ui/RevivePlayer_Selector.anm2";
|
||||
constexpr const char* ANIMATION_BACKGROUND = "Background";
|
||||
constexpr const char* ANIMATION_UPPER_SELECTOR = "UpperSelector";
|
||||
constexpr const char* ANIMATION_LOWER_SELECTOR = "LowerSelector";
|
||||
constexpr const char* TITLE_NULL = "Title";
|
||||
constexpr const char* TITLE_TEXT = "REVIVE PLAYER";
|
||||
constexpr uint32_t TITLE_ARGB = 0xffffffff;
|
||||
constexpr float SELECTOR_SCALE = 0.75f;
|
||||
constexpr float SELECTOR_ABOVE = 35;
|
||||
constexpr float SELECTOR_BELOW = 65;
|
||||
constexpr float SELECTOR_BELOW_COMPACT = 50;
|
||||
constexpr int CLOSE_FRAMES = 8;
|
||||
constexpr int SOUND_HOLY = 54;
|
||||
constexpr int SOUND_FRAME_DELAY = 2;
|
||||
constexpr uint32_t ONLINE_STAT_REVIVES = 12;
|
||||
constexpr uint32_t PLAYER_INDEX_NONE = UINT32_MAX;
|
||||
|
||||
// Whether an action was pressed this frame on one device, by its default bindings.
|
||||
static bool is_device_triggered(int deviceId, ButtonAction action)
|
||||
{
|
||||
std::shared_ptr<KAGE::Input::InputDevice> device = KAGE::Input::manager.device_find(deviceId);
|
||||
if (!device || !device->isConnected) return false;
|
||||
|
||||
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 false;
|
||||
return std::ranges::any_of(table[action], [&](int button)
|
||||
{ return button != KAGE::Input::BUTTON_NONE && device->is_button_triggered(button); });
|
||||
}
|
||||
|
||||
// The run's player a controller plays, if any.
|
||||
static Entity_Player* player_by_controller(int controller)
|
||||
{
|
||||
for (Entity_Player* player : g_game->playerManager.playerList)
|
||||
if (player->_controllerIndex == controller) return player;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Where the HUD of a player sits on screen in a HUD layout.
|
||||
static Vector player_hud_position(Entity_Player*, PlayerHudLayout)
|
||||
{
|
||||
reconstruction_missing("HUD's player HUD position 009a6320 (FUN_009a6320 in classes.h)");
|
||||
}
|
||||
|
||||
// 008ef560 Loads the menu sheet on its background and the selector sheet on its upper selector at three quarters size,
|
||||
// hidden with no controller and the first player selected.
|
||||
void RevivePlayerMenu::Init()
|
||||
{
|
||||
menuSprite.Load(MENU_ANM2, GRAPHICS_LOAD);
|
||||
menuSprite.Play(ANIMATION_BACKGROUND);
|
||||
selectorSprite.Load(SELECTOR_ANM2, GRAPHICS_LOAD);
|
||||
selectorSprite.Play(ANIMATION_UPPER_SELECTOR);
|
||||
selectorSprite.scale = vector_make(SELECTOR_SCALE, SELECTOR_SCALE);
|
||||
selectedPlayer = 0;
|
||||
controllerIndex = -1;
|
||||
state = REVIVE_MENU_HIDDEN;
|
||||
}
|
||||
|
||||
// 008ef840 Opens the menu for a controller on the first dead player from the last one selected.
|
||||
void RevivePlayerMenu::Open(int controller)
|
||||
{
|
||||
menuSprite.Play(ANIMATION_BACKGROUND);
|
||||
selectorSprite.Play(ANIMATION_UPPER_SELECTOR);
|
||||
controllerIndex = controller;
|
||||
selection_move(0, 1);
|
||||
state = REVIVE_MENU_OPEN;
|
||||
}
|
||||
|
||||
// Moves the selection by jump, wrapping around the main players, then on by skipStep past the living ones.
|
||||
void RevivePlayerMenu::selection_move(int jump, int skipStep)
|
||||
{
|
||||
PlayerManager& players = g_game->playerManager;
|
||||
auto wrap = [&](int index)
|
||||
{
|
||||
int count = players.count_main_players();
|
||||
return index < 0 ? index + count : index >= count ? index - count : index;
|
||||
};
|
||||
|
||||
if (jump != 0) selectedPlayer = wrap(selectedPlayer + jump);
|
||||
for (Entity_Player* player = players.get_main_player(selectedPlayer); player && !player->_isCoopGhost;
|
||||
player = players.get_main_player(selectedPlayer))
|
||||
selectedPlayer = wrap(selectedPlayer + skipStep);
|
||||
}
|
||||
|
||||
// 008ef990 While the HUD shows, the menu's controller moves between the dead players (up and down by two, as their
|
||||
// HUDs sit in two rows) and confirms or backs out to revive the one selected, counted for the controller's player.
|
||||
// The menu closes on either, or as soon as the controller leaves or no one is dead.
|
||||
// Netplay is offline, so the revive is always the local one.
|
||||
void RevivePlayerMenu::Update()
|
||||
{
|
||||
if (state == REVIVE_MENU_CLOSING)
|
||||
{
|
||||
if (closeTimer-- < 1) state = REVIVE_MENU_HIDDEN;
|
||||
return;
|
||||
}
|
||||
if (state != REVIVE_MENU_OPEN || !g_game->hud.isVisible) return;
|
||||
|
||||
PlayerManager& players = g_game->playerManager;
|
||||
int deadCount = players.GetNumCoopPlayers();
|
||||
if (KAGE::Input::manager.is_device_connected(controllerIndex) && deadCount != 0)
|
||||
{
|
||||
menuSprite.Update();
|
||||
selectorSprite.Update();
|
||||
if (!is_device_triggered(controllerIndex, ACTION_MENU_CONFIRM) &&
|
||||
!is_device_triggered(controllerIndex, ACTION_MENU_BACK))
|
||||
{
|
||||
if (deadCount < 2) return;
|
||||
|
||||
int previous = selectedPlayer;
|
||||
if (is_device_triggered(controllerIndex, ACTION_MENU_UP)) selection_move(-2, -1);
|
||||
else if (is_device_triggered(controllerIndex, ACTION_MENU_DOWN)) selection_move(2, 1);
|
||||
else if (is_device_triggered(controllerIndex, ACTION_MENU_LEFT)) selection_move(-1, -1);
|
||||
else if (is_device_triggered(controllerIndex, ACTION_MENU_RIGHT)) selection_move(1, 1);
|
||||
if (selectedPlayer != previous) menu_sound_play(SOUND_MENU_SCROLL, SOUND_FRAME_DELAY);
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<Entity_Player*>& list = players.playerList;
|
||||
auto revived = std::ranges::find(list, players.get_main_player(selectedPlayer));
|
||||
players.ReviveCoopPlayer(revived == list.end() ? PLAYER_INDEX_NONE : (uint32_t)(revived - list.begin()));
|
||||
Player_stats_add(&g_game->onlinePlayerStats, ONLINE_STAT_REVIVES, player_by_controller(controllerIndex), 1);
|
||||
menu_sound_play(SOUND_HOLY, SOUND_FRAME_DELAY);
|
||||
}
|
||||
|
||||
state = REVIVE_MENU_CLOSING;
|
||||
closeTimer = CLOSE_FRAMES;
|
||||
controllerIndex = -1;
|
||||
}
|
||||
|
||||
// 008efe10 While open with someone dead and the HUD shown, draws the menu at the screen center with its title on the
|
||||
// Title null, and the selector at the selected player's HUD: above it for a HUD in the lower half, else below it.
|
||||
// The original reads a missing Title null through a null pointer. The title is left out then.
|
||||
void RevivePlayerMenu::Render()
|
||||
{
|
||||
Game& game = *g_game;
|
||||
int deadCount = game.playerManager.GetNumCoopPlayers();
|
||||
if (state != REVIVE_MENU_OPEN || deadCount == 0 || !game.hud.isVisible) return;
|
||||
|
||||
Vector center = vector_make(g_screenWidth * 0.5f, g_screenHeight * 0.5f);
|
||||
menuSprite.Render({center});
|
||||
|
||||
Font& font = g_manager->font2_TeamMeatEx12;
|
||||
const NullFrame* title = menuSprite.animState.animData ? menuSprite.GetNullFrame(TITLE_NULL) : nullptr;
|
||||
if (title)
|
||||
{
|
||||
FontSettings settings;
|
||||
float width = (float)font.GetStringWidth(TITLE_TEXT);
|
||||
Vector position = vector_make(center.x + title->pos.x - width * 0.5f, center.y + title->pos.y);
|
||||
font.DrawString(TITLE_TEXT, position, vector_make(1, 1), kcolor_argb(TITLE_ARGB), settings);
|
||||
}
|
||||
|
||||
Entity_Player* player = game.playerManager.get_main_player(selectedPlayer);
|
||||
PlayerHudLayout layout = game.hud.GetPlayerHUDLayout(selectedPlayer, player);
|
||||
Vector position = player_hud_position(player, layout);
|
||||
bool isLowerHalf = position.y >= center.y;
|
||||
position.y += isLowerHalf ? -SELECTOR_ABOVE : layout == HUD_LAYOUT_COMPACT ? SELECTOR_BELOW_COMPACT : SELECTOR_BELOW;
|
||||
selectorSprite.Play(isLowerHalf ? ANIMATION_LOWER_SELECTOR : ANIMATION_UPPER_SELECTOR);
|
||||
selectorSprite.Render({position});
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include "anm2.h"
|
||||
|
||||
// Where the co-op revive menu is: hidden, open for a controller, or closing for a few frames.
|
||||
enum ReviveMenuState : int
|
||||
{
|
||||
REVIVE_MENU_HIDDEN,
|
||||
REVIVE_MENU_OPEN,
|
||||
REVIVE_MENU_CLOSING
|
||||
};
|
||||
|
||||
// Construction and destruction (008ef4b0) are the defaults.
|
||||
// The co-op revive menu (RevivePlayerMenu) a revive machine opens: the controller that used it picks a dead player,
|
||||
// marked by a selector at that player's HUD, and confirming brings the player back.
|
||||
class RevivePlayerMenu
|
||||
{
|
||||
public:
|
||||
ANM2 menuSprite;
|
||||
ANM2 selectorSprite;
|
||||
ReviveMenuState state = REVIVE_MENU_HIDDEN;
|
||||
int closeTimer = 0;
|
||||
int controllerIndex = -1;
|
||||
int selectedPlayer = 0;
|
||||
|
||||
void Init();
|
||||
void Open(int controller);
|
||||
void Update();
|
||||
void Render();
|
||||
|
||||
private:
|
||||
void selection_move(int jump, int skipStep);
|
||||
};
|
||||
@@ -11,21 +11,6 @@
|
||||
#include <iterator>
|
||||
#include <optional>
|
||||
|
||||
// The door slots of a room's door mask, the second of each side being the far half of a big room.
|
||||
enum DoorSlot : int
|
||||
{
|
||||
DOOR_NONE = -1,
|
||||
DOOR_LEFT0,
|
||||
DOOR_UP0,
|
||||
DOOR_RIGHT0,
|
||||
DOOR_DOWN0,
|
||||
DOOR_LEFT1,
|
||||
DOOR_UP1,
|
||||
DOOR_RIGHT1,
|
||||
DOOR_DOWN1,
|
||||
DOOR_SLOT_COUNT
|
||||
};
|
||||
|
||||
// One way the Curse of the Giant splits a big shape into two rooms: each part's shape, whether it sits a room width or
|
||||
// height into the big one, and the doors it starts with, which are the walls the two parts share.
|
||||
struct SplitPart
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#include "victory_run_prompt.h"
|
||||
#include "generic_prompt.h"
|
||||
|
||||
constexpr const char* VICTORY_RUN_PNG = "gfx/ui/Prompt_VictoryRun.png";
|
||||
constexpr int VICTORY_RUN_LAYER = 2;
|
||||
|
||||
// 00838380 Turns a prompt into the victory lap one (GenericPrompt::SetImageToVictoryRun): no body text, and the victory
|
||||
// lap picture on the sheet's third layer, shown.
|
||||
void victory_run_prompt_load(GenericPrompt& prompt)
|
||||
{
|
||||
ANM2& sprite = prompt.sprite;
|
||||
|
||||
prompt.bodyLines.fill({});
|
||||
sprite.ReplaceSpritesheet(VICTORY_RUN_LAYER, VICTORY_RUN_PNG);
|
||||
sprite.LoadGraphics();
|
||||
if ((int)sprite.layerStates.size() > VICTORY_RUN_LAYER) sprite.GetLayer(VICTORY_RUN_LAYER)->isVisible = true;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
class GenericPrompt;
|
||||
|
||||
void victory_run_prompt_load(GenericPrompt& prompt);
|
||||
Reference in new issue
Block a user