Files
isaac-port/src/level/minimap.cpp
T

1045 lines
45 KiB
C++

#include "level/minimap.h"
#include "entity/pickup/pickup.h"
#include "entity/player/player.h"
#include "engine/fx_layers.h"
#include "game/game.h"
#include "ui/hud.h"
#include "level/level.h"
#include "engine/log.h"
#include "game/manager.h"
#include "ui/menu/manager.h"
#include "ui/menu/options.h"
#include "level/room.h"
#include "engine/seeds.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* ANIMATION_ROOM_OUTLINE = "RoomOutline";
constexpr const char* ANIMATION_ROOM_CURRENT = "RoomCurrent";
constexpr const char* ANIMATION_ROOM_VISITED = "RoomVisited";
constexpr const char* ANIMATION_ROOM_UNVISITED = "RoomUnvisited";
constexpr const char* ICON_LOCKED_ROOM = "IconLockedRoom";
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 iconLimit;
};
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 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 SCORE_HISTORY_ALPHA = 0.5f;
constexpr int HISTORY_HUD_ON = 1;
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 SPEED_TIME_LIMIT = 28800;
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;
constexpr RNG APRILS_FOOL_RNG = {0, 1, 5, 16};
constexpr int SUBTYPE_MINESHAFT_ENTRANCE = 10;
constexpr int SUBTYPE_MIRROR_ROOM = 34;
constexpr int SUBTYPE_BOSS_AMBUSH = 1;
constexpr int MAP_GRID_STAIRS = 18;
constexpr float RED_ROOM_TINT = 75.0f / 255;
constexpr float MAP_ICON_HALF = 6;
constexpr int MAP_ICON_SLOTS = 4;
// The doors of a Void boss room that tell which of its cells Delirium's room shows as, by the room's shape.
constexpr uint32_t VOID_DOORS_TALL_DOWN = 1 << DOOR_LEFT0 | 1 << DOOR_UP0 | 1 << DOOR_RIGHT0;
constexpr uint32_t VOID_DOORS_TALL_UP = 1 << DOOR_DOWN0 | 1 << DOOR_LEFT1 | 1 << DOOR_RIGHT1;
constexpr uint32_t VOID_DOORS_WIDE_RIGHT = 1 << DOOR_LEFT0 | 1 << DOOR_UP0 | 1 << DOOR_DOWN0;
constexpr uint32_t VOID_DOORS_WIDE_LEFT = 1 << DOOR_RIGHT0 | 1 << DOOR_UP1 | 1 << DOOR_DOWN1;
constexpr uint32_t VOID_DOORS_BIG_TOP_RIGHT = 1 << DOOR_LEFT0 | 1 << DOOR_UP0;
constexpr uint32_t VOID_DOORS_BIG_TOP_LEFT = 1 << DOOR_RIGHT0 | 1 << DOOR_UP1;
constexpr uint32_t VOID_DOORS_BIG_BOTTOM_RIGHT = 1 << DOOR_DOWN0 | 1 << DOOR_LEFT1;
constexpr uint32_t VOID_DOORS_BIG_BOTTOM_LEFT = 1 << DOOR_RIGHT1 | 1 << DOOR_DOWN1;
// The icons a room shows on the map, by type, for the types that always show the same one.
constexpr const char* ROOM_ICONS[] = {nullptr,
nullptr,
"IconShop",
nullptr,
nullptr,
"IconBoss",
"IconMiniboss",
"IconSecretRoom",
"IconSuperSecretRoom",
"IconArcade",
"IconCurseRoom",
nullptr,
"IconLibrary",
"IconSacrificeRoom",
"IconDevilRoom",
"IconAngelRoom",
nullptr,
nullptr,
"IconIsaacsRoom",
"IconBarrenRoom",
"IconChestRoom",
"IconDiceRoom",
nullptr,
nullptr,
"IconPlanetarium",
"IconTeleporterRoom",
"IconTeleporterRoom",
nullptr,
nullptr,
"IconUltraSecretRoom"};
// The pickups and objects a room's map cell shows icons for, in the order they take the cell's free icon slots.
// Each is a bit of RoomIcons::shown, and the animation of minimap_icons.anm2 it shows.
struct MapIcon
{
int bit;
const char* animation;
};
// The bits of RoomIcons::shown.
enum MapIconBit : int
{
MAP_ICON_HEART,
MAP_ICON_COIN,
MAP_ICON_POOP,
MAP_ICON_KEY,
MAP_ICON_BOMB,
MAP_ICON_CARD,
MAP_ICON_ITEM,
MAP_ICON_PILL,
MAP_ICON_BATTERY,
MAP_ICON_CHEST,
MAP_ICON_TRINKET,
MAP_ICON_SLOT,
MAP_ICON_RUNE,
MAP_ICON_BEGGAR,
MAP_ICON_LADDER,
MAP_ICON_PORTAL,
MAP_ICON_COUNT
};
constexpr MapIcon MAP_ICONS[] = {
{MAP_ICON_HEART, "IconHeart"}, {MAP_ICON_ITEM, "IconItem"}, {MAP_ICON_TRINKET, "IconTrinket"},
{MAP_ICON_CHEST, "IconChest"}, {MAP_ICON_RUNE, "IconRune"}, {MAP_ICON_CARD, "IconCard"},
{MAP_ICON_PILL, "IconPill"}, {MAP_ICON_KEY, "IconKey"}, {MAP_ICON_BOMB, "IconBomb"},
{MAP_ICON_POOP, "IconPoop"}, {MAP_ICON_COIN, "IconCoin"}, {MAP_ICON_BATTERY, "IconBattery"},
{MAP_ICON_BEGGAR, "IconBeggar"}, {MAP_ICON_SLOT, "IconSlot"}, {MAP_ICON_LADDER, "IconLadder"},
{MAP_ICON_PORTAL, "IconPortal"}};
// An icon and its frame, as a saved slot or beggar shows it.
struct SlotIcon
{
MapIconBit bit;
int frame;
};
// The frame of the icon a saved heart or coin shows, by subtype, and the icon a slot or beggar shows, by variant.
// A heart past its table shows the full heart's, a coin the penny's and a slot the first's.
constexpr int HEART_ICON_FRAMES[] = {1, 1, 0, 5, 9, 1, 6, 8, 3, 1, 4, 7, 2};
constexpr int COIN_ICON_FRAMES[] = {0, 0, 1, 2, 0, 0, 1, 3};
constexpr SlotIcon SLOT_ICONS[] = {
{MAP_ICON_SLOT, 2}, {MAP_ICON_SLOT, 2}, {MAP_ICON_SLOT, 3}, {MAP_ICON_SLOT, 4}, {MAP_ICON_BEGGAR, 0},
{MAP_ICON_BEGGAR, 2}, {MAP_ICON_BEGGAR, 0}, {MAP_ICON_BEGGAR, 3}, {MAP_ICON_SLOT, 1}, {MAP_ICON_BEGGAR, 4},
{MAP_ICON_SLOT, 6}, {MAP_ICON_SLOT, 1}, {MAP_ICON_SLOT, 0}, {MAP_ICON_BEGGAR, 5}, {MAP_ICON_SLOT, 2},
{MAP_ICON_BEGGAR, 2}, {MAP_ICON_SLOT, 5}, {MAP_ICON_SLOT, 7}, {MAP_ICON_BEGGAR, 1}, {MAP_ICON_SLOT, 8}};
constexpr int SLOT_VARIANT_NO_ICON = 14;
constexpr int EFFECT_PORTAL_VARIANT = 161;
constexpr int EFFECT_PORTAL_SUBTYPE = 980;
constexpr int GOLDEN_KEY_SUBTYPE = 2;
constexpr int CHARGED_KEY_SUBTYPE = 4;
constexpr int MEGA_BATTERY_SUBTYPE = 4;
constexpr int GOLD_PILL = 14;
constexpr int GRAB_BAG_SACK = 2;
// What refresh's passes share: the current room, the first cell drawn and the step from one cell to the next.
struct MapWindow
{
RoomDescriptor* current = nullptr;
float stepX = 0;
float stepY = 0;
int startColumn = 0;
int startRow = 0;
};
// The icons a room cell shows beside its room's: which are shown, and each one's frame.
struct RoomIcons
{
std::array<int, MAP_ICON_COUNT> frames{};
uint32_t shown = 0;
int count = 0;
};
// 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);
}
// Sets a sprite's tint, keeping its colorize and offset.
static void tint_set(ANM2& sprite, float red, float green, float blue)
{
sprite.color._tint[0] = red;
sprite.color._tint[1] = green;
sprite.color._tint[2] = blue;
sprite.color._tint[3] = 1;
}
// Whether a cell of the current dimension's map is in the grid and holds a room.
static bool is_room_at(int cell, int roomIndex)
{
return cell >= 0 && cell < LEVEL_GRID_CELLS && g_game->currentRoomMap[cell] == roomIndex;
}
// Whether a room is a big boss room of the Void, which the map shows as the one cell Delirium's doors lead to.
static bool is_void_boss(const RoomDescriptor& room)
{
return g_game->stage == STAGE_VOID && room.data->type == ROOM_BOSS;
}
// Whether a cell of a Void boss room shows its outline: the one cell its doors face, by its shape.
static bool is_void_outline_cell(const RoomDescriptor& room, int cell, int roomIndex)
{
uint32_t doors = room.allowedDoors;
bool isShown = true;
switch (room.data->shape)
{
case ROOMSHAPE_1x2:
if (doors & VOID_DOORS_TALL_DOWN) isShown = is_room_at(cell + LEVEL_GRID_WIDTH, roomIndex);
if (doors & VOID_DOORS_TALL_UP) isShown = is_room_at(cell - LEVEL_GRID_WIDTH, roomIndex);
return isShown;
case ROOMSHAPE_2x1:
if (doors & VOID_DOORS_WIDE_RIGHT) return is_room_at(cell + 1, roomIndex);
if (doors & VOID_DOORS_WIDE_LEFT) return is_room_at(cell - 1, roomIndex);
return true;
case ROOMSHAPE_2x2:
if (doors & VOID_DOORS_BIG_TOP_RIGHT)
return is_room_at(cell + 1, roomIndex) && is_room_at(cell + LEVEL_GRID_WIDTH, roomIndex);
if (doors & VOID_DOORS_BIG_TOP_LEFT)
return is_room_at(cell - 1, roomIndex) && is_room_at(cell + LEVEL_GRID_WIDTH, roomIndex);
if (doors & VOID_DOORS_BIG_BOTTOM_RIGHT)
return is_room_at(cell + 1, roomIndex) && is_room_at(cell - LEVEL_GRID_WIDTH, roomIndex);
if (doors & VOID_DOORS_BIG_BOTTOM_LEFT)
return is_room_at(cell - 1, roomIndex) && is_room_at(cell - LEVEL_GRID_WIDTH, roomIndex);
return true;
default: return true;
}
}
// How far a Void boss room's drawing moves from its grid index to the cell its doors face.
static Vector void_boss_shift(const RoomDescriptor& room, const MapWindow& window)
{
uint32_t doors = room.allowedDoors;
switch (room.data->shape)
{
case ROOMSHAPE_1x2: return vector_make(0, doors & VOID_DOORS_TALL_UP ? window.stepY : 0);
case ROOMSHAPE_2x1: return vector_make(doors & VOID_DOORS_WIDE_LEFT ? window.stepX : 0, 0);
case ROOMSHAPE_2x2:
if (doors & VOID_DOORS_BIG_TOP_LEFT) return vector_make(window.stepX, 0);
if (doors & VOID_DOORS_BIG_BOTTOM_RIGHT) return vector_make(0, window.stepY);
if (doors & VOID_DOORS_BIG_BOTTOM_LEFT) return vector_make(window.stepX, window.stepY);
return vector_make(0, 0);
default: return vector_make(0, 0);
}
}
// How many cells a room shape covers across and down, as the current room's center counts them. The L shape missing
// its top left cell counts none across.
static Vector shape_cells(int shape)
{
switch (shape)
{
case ROOMSHAPE_1x1:
case ROOMSHAPE_IH:
case ROOMSHAPE_IV: return vector_make(1, 1);
case ROOMSHAPE_1x2:
case ROOMSHAPE_IIV: return vector_make(1, 2);
case ROOMSHAPE_2x1:
case ROOMSHAPE_IIH: return vector_make(2, 1);
case ROOMSHAPE_2x2:
case ROOMSHAPE_LTR:
case ROOMSHAPE_LBL:
case ROOMSHAPE_LBR: return vector_make(2, 2);
case ROOMSHAPE_LTL: return vector_make(0, 2);
default:
log_printf(LOG_ERROR, "invalid room shape id: %d\n", shape);
return vector_make(1, 1);
}
}
// Whether a cell is where its room draws: its grid index, or the cell right of it for the L shape missing that one.
static bool is_room_anchor(const RoomDescriptor& room, int cell)
{
return room.gridIndex == cell || (room.gridIndex + 1 == cell && room.data->shape == ROOMSHAPE_LTL);
}
// Visits the window's cells in the grid, with where each draws on the surface. Pass isPadded to start a cell up and
// left of the window, for the rooms reaching into it.
template <class Visit>
static void cells_walk(const MinimapConfig& map, const MapWindow& window, bool isPadded, Visit visit)
{
int firstRow = isPadded ? std::max(window.startRow - 1, 0) : window.startRow;
int firstColumn = isPadded ? std::max(window.startColumn - 1, 0) : window.startColumn;
float left = firstColumn < window.startColumn ? 0 - window.stepX : 0;
float y = firstRow < window.startRow ? 0 - window.stepY : 0;
for (int row = firstRow; row < map.rows + window.startRow; row++, y += window.stepY)
{
float x = left;
for (int column = firstColumn; column < window.startColumn + map.columns; column++, x += window.stepX)
{
int cell = row * LEVEL_GRID_WIDTH + column;
if (cell >= 0 && cell < LEVEL_GRID_CELLS && g_game->currentRoomMap[cell] >= 0)
visit(cell, g_game->currentRoomMap[cell], vector_make(x, y));
}
}
}
// The icon a room shows: its type's, a visited mirror or mineshaft entrance room's, or a lock on a special room not
// visited yet.
static const char* room_icon_get(const RoomDescriptor& room)
{
const RoomConfig_Room* data = room.data;
Game& game = *g_game;
if (data && room.displayFlags & ROOM_DISPLAY_ICON)
{
bool isGreed = game.difficulty == DIFFICULTY_GREED || game.difficulty == DIFFICULTY_GREEDIER;
switch (data->type)
{
case ROOM_DEFAULT:
if (room.visitedCount == 0 || game.currentDimensionIdx == DIMENSION_DEATH_CERTIFICATE) break;
if (data->subtype == SUBTYPE_MIRROR_ROOM && game.HasMirrorDimension()) return "IconMirrorRoom";
if (data->subtype == SUBTYPE_MINESHAFT_ENTRANCE && game.HasAbandonedMineshaft())
return "IconMinecartRoom";
break;
case ROOM_TREASURE:
if (isGreed && game.greedModeTreasureRoomIdx != (uint32_t)room.gridIndex) return "IconTreasureRoomGreed";
return room.flags & ROOM_DESCRIPTOR_FLAG_DEVIL_TREASURE ? "IconTreasureRoomRed" : "IconTreasureRoom";
case ROOM_CHALLENGE: return data->subtype == SUBTYPE_BOSS_AMBUSH ? "IconBossAmbushRoom" : "IconAmbushRoom";
default:
if (data->type >= 0 && data->type < (int)std::size(ROOM_ICONS) && ROOM_ICONS[data->type])
return ROOM_ICONS[data->type];
}
}
if (!data || data->type == ROOM_DEFAULT || room.visitedCount != 0 || !(room.displayFlags & ROOM_DISPLAY_LOCK))
return nullptr;
switch (data->type)
{
case ROOM_SHOP:
case ROOM_ARCADE:
case ROOM_LIBRARY:
case ROOM_ISAACS:
case ROOM_BARREN:
case ROOM_CHEST:
case ROOM_DICE:
case ROOM_PLANETARIUM: return ICON_LOCKED_ROOM;
default: return nullptr;
}
}
// Shows an icon once, counting it.
static void room_icon_show(RoomIcons& icons, MapIconBit bit)
{
if (icons.shown & 1u << bit) return;
icons.shown |= 1u << bit;
icons.count++;
}
// Shows an icon, raising its frame to at least frame.
static void room_icon_raise(RoomIcons& icons, MapIconBit bit, int frame)
{
room_icon_show(icons, bit);
icons.frames[bit] = std::max(icons.frames[bit], frame);
}
// The chest icon's frame a chest or sack shows, or -1 for the spiked chest, which leaves it.
static int chest_icon_frame(const EntitySaveState& saved)
{
switch (saved.variant)
{
case PICKUP_BOMBCHEST: return 1;
case PICKUP_SPIKEDCHEST: return -1;
case PICKUP_ETERNALCHEST: return 7;
case PICKUP_WOODENCHEST: return 6;
case PICKUP_MEGACHEST: return 9;
case PICKUP_LOCKEDCHEST: return 8;
case PICKUP_GRAB_BAG: return saved.subtype == GRAB_BAG_SACK ? 3 : 2;
case PICKUP_REDCHEST: return 5;
default: return 4;
}
}
// The icon a saved pickup shows, by its variant: hearts, coins, keys, bombs, pills and batteries by the best one's
// frame, cards and runes, collectibles, trinkets and poop, and chests and sacks. A pickup another one holds or one
// saved at the origin shows none.
static void pickup_icon_add(RoomIcons& icons, const EntitySaveState& saved)
{
int subtype = saved.subtype;
if (saved.intStorage3 != 0 || (saved.targetPosition.x == 0 && saved.targetPosition.y == 0)) return;
switch (saved.variant)
{
case PICKUP_HEART:
{
bool isListed = subtype >= 0 && subtype < (int)std::size(HEART_ICON_FRAMES);
room_icon_raise(icons, MAP_ICON_HEART, isListed ? HEART_ICON_FRAMES[subtype] : 1);
return;
}
case PICKUP_COIN:
{
bool isListed = subtype >= 0 && subtype < (int)std::size(COIN_ICON_FRAMES);
room_icon_raise(icons, MAP_ICON_COIN, isListed ? COIN_ICON_FRAMES[subtype] : 0);
return;
}
case PICKUP_POOP: room_icon_show(icons, MAP_ICON_POOP); return;
case PICKUP_BOMB: room_icon_raise(icons, MAP_ICON_BOMB, subtype == BOMB_SUBTYPE_GOLDEN); return;
case PICKUP_KEY:
{
int frame = subtype == GOLDEN_KEY_SUBTYPE ? 1 : subtype == CHARGED_KEY_SUBTYPE ? 2 : 0;
room_icon_raise(icons, MAP_ICON_KEY, frame);
return;
}
case PICKUP_TAROTCARD:
{
ItemConfig_Card* card = g_manager->itemConfig.GetCard(subtype);
room_icon_show(icons, card && card->cardType == CARD_RUNE ? MAP_ICON_RUNE : MAP_ICON_CARD);
return;
}
case PICKUP_LIL_BATTERY: room_icon_raise(icons, MAP_ICON_BATTERY, subtype == MEGA_BATTERY_SUBTYPE); return;
case PICKUP_PILL: room_icon_raise(icons, MAP_ICON_PILL, (subtype & PILL_COLOR_MASK) == GOLD_PILL); return;
case PICKUP_COLLECTIBLE: room_icon_show(icons, MAP_ICON_ITEM); return;
case PICKUP_TRINKET: room_icon_show(icons, MAP_ICON_TRINKET); return;
default: break;
}
if (!Entity_Pickup::IsChest(saved.variant) && saved.variant != PICKUP_GRAB_BAG) return;
room_icon_show(icons, MAP_ICON_CHEST);
if (int frame = chest_icon_frame(saved); frame >= 0) room_icon_raise(icons, MAP_ICON_CHEST, frame);
}
// The pickups and objects a shown room holds, from what it saved when left (pickups, slots and beggars, and the
// portal of a Delirium room), and its crawlspace ladder.
static RoomIcons room_icons_find(const RoomDescriptor& room, int cell)
{
RoomIcons icons;
if (room.displayFlags == 0) return icons;
for (const EntitySaveState& saved : g_game->GetRoomByIdx(cell)->savedEntities)
{
if (saved.type == ENTITY_PICKUP) pickup_icon_add(icons, saved);
else if (saved.type == ENTITY_SLOT && saved.variant != SLOT_VARIANT_NO_ICON)
{
bool isListed = saved.variant >= 0 && saved.variant < (int)std::size(SLOT_ICONS);
SlotIcon icon = isListed ? SLOT_ICONS[saved.variant] : SLOT_ICONS[0];
room_icon_raise(icons, icon.bit, icon.frame);
}
else if (saved.type == ENTITY_EFFECT && saved.variant == EFFECT_PORTAL_VARIANT &&
saved.subtype == EFFECT_PORTAL_SUBTYPE)
room_icon_show(icons, MAP_ICON_PORTAL);
}
for (const GridEntityDesc& grid : room.savedGridEntities)
if (grid._type == MAP_GRID_STAIRS) room_icon_show(icons, MAP_ICON_LADDER);
return icons;
}
// Draws a room's icon and those of what it holds, spread over the cell's icon slots.
// The original lays more than four icons out as four, after logging it.
static void room_icons_draw(MinimapConfig& map, const RoomDescriptor& room, int cell, Vector at,
const MapWindow& window)
{
const char* roomIcon = room_icon_get(room);
RoomIcons icons = room_icons_find(room, cell);
float inset = map.margin + map.gap;
Vector offset = vector_make(inset, inset);
int shape = room.data->shape;
if (is_void_boss(room) && (shape == ROOMSHAPE_1x2 || shape == ROOMSHAPE_2x1 || shape == ROOMSHAPE_2x2))
{
Vector shift = void_boss_shift(room, window);
at = vector_make(at.x + shift.x, at.y + shift.y);
}
else
{
if (shape == ROOMSHAPE_2x1 || shape == ROOMSHAPE_2x2) offset.x += map.cellSize.x * 0.5f;
if (shape == ROOMSHAPE_1x2 || shape == ROOMSHAPE_2x2) offset.y += map.cellSize.y * 0.5f;
}
int count = std::min(icons.count + (roomIcon ? 1 : 0), map.iconLimit);
float left = map.cellSize.x * 0.25f + offset.x;
float right = map.cellSize.x * 0.75f + offset.x;
float middle = map.cellSize.y * 0.5f + offset.y;
std::array<Vector, MAP_ICON_SLOTS> slots = {vector_make(map.cellSize.x * 0.5f + offset.x, middle)};
if (count == 2) slots = {vector_make(left, middle), vector_make(right, middle)};
else if (count > 2)
{
if (count > MAP_ICON_SLOTS) log_printf(LOG_ERROR, "currently there are no more than 4 minimap icons supported\n");
float top = map.cellSize.y * 0.25f + offset.y;
float bottom = map.cellSize.y * 0.75f + offset.y;
slots = {vector_make(left, top), vector_make(right, top), vector_make(left, bottom), vector_make(right, bottom)};
}
ANM2& sprite = g_game->minimap.iconsSprite;
int slot = 0;
auto icon_draw = [&](const char* animation, int frame) {
sprite.SetFrame(animation, frame);
sprite.Render({vector_make(std::floor(at.x + slots[slot].x - MAP_ICON_HALF),
std::floor(at.y + slots[slot].y - MAP_ICON_HALF))});
slot++;
};
if (roomIcon) icon_draw(roomIcon, 0);
for (const MapIcon& icon : MAP_ICONS)
if (slot < count && icons.shown & 1u << icon.bit) icon_draw(icon.animation, icons.frames[icon.bit]);
}
// 0098b5e0 Redraws the map's surface around the current room (a random room's in the April Fool's challenge), at
// most 13 cells each way: the outlines of the shown rooms (whose cells give the drawn bounds), then each room's
// shape as current, visited or not (red rooms tinted, secret rooms not shown until visited), and their icons. The
// current room gives the center the small map shows. Sprites draw without the screen shake meanwhile.
// The original reads before the room list when the current cell holds no room, and reads a room's config without a
// check. Here no room is the current one, and a room without a config draws nothing.
void MinimapConfig::refresh()
{
Game& game = *g_game;
KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager;
DAT_00c33910 = 0;
graphics.render_target_push(surface.get(), KAGE::Graphics::TARGET_OWN_SIZE, KAGE::Graphics::PRESENT_FLUSH);
graphics.Clear();
graphics.blendMode.SetMode(KAGE::Graphics::BLEND_NORMAL);
if (game.currentRoomIdx < 0)
{
graphics.Present(KAGE::Graphics::PRESENT_FINISH);
graphics.render_target_pop(KAGE::Graphics::PRESENT_FLUSH);
DAT_00c33910 = 1;
return;
}
int currentCell = game.currentRoomIdx;
if (game.challenge == CHALLENGE_APRILS_FOOL)
{
RNG rng = APRILS_FOOL_RNG;
if (game.room->descriptor) rng._seed = game.room->descriptor->decorationSeed;
currentCell = game.roomList[rng.RandomInt(game.nbRooms)].safeGridIndex;
}
currentCell = std::clamp(currentCell, 0, LEVEL_GRID_CELLS);
columns = std::min(columns, LEVEL_GRID_WIDTH);
rows = std::min(rows, LEVEL_GRID_WIDTH);
MapWindow window;
int currentIndex = currentCell < LEVEL_GRID_CELLS ? game.currentRoomMap[currentCell] : -1;
window.current = currentIndex >= 0 ? &game.roomList[currentIndex] : nullptr;
window.startColumn = std::max(std::min(currentCell % LEVEL_GRID_WIDTH - columns / 2, LEVEL_GRID_WIDTH - columns), 0);
window.startRow = std::max(std::min(currentCell / LEVEL_GRID_WIDTH - rows / 2, LEVEL_GRID_WIDTH - rows), 0);
window.stepX = gap + cellSize.x;
window.stepY = gap + cellSize.y;
boundsMin = vector_make((float)surface->width, (float)surface->height);
boundsMax = vector_make(0, 0);
float border = (margin + gap) * 2;
cells_walk(*this, window, false, [&](int cell, int roomIndex, Vector at) {
RoomDescriptor& room = game.roomList[roomIndex];
if (!room.data || room.displayFlags == 0) return;
bool isOutlined = !is_void_boss(room) || is_void_outline_cell(room, cell, roomIndex);
boundsMin = vector_make(std::min(boundsMin.x, at.x), std::min(boundsMin.y, at.y));
boundsMax = vector_make(std::max(at.x + cellSize.x + border, boundsMax.x),
std::max(at.y + cellSize.y + border, boundsMax.y));
mapSprite.SetFrame(ANIMATION_ROOM_OUTLINE, 0);
if (isOutlined) mapSprite.Render({at});
});
cells_walk(*this, window, true, [&](int cell, int roomIndex, Vector at) {
RoomDescriptor& room = game.roomList[roomIndex];
if (!room.data || !is_room_anchor(room, cell)) return;
int shape = room.data->shape;
if (shape - 1 < 0) log_printf(LOG_ERROR, "invalid room shape id: %d\n", shape);
int frame = shape - 1;
Vector cells = shape_cells(shape);
Vector position = vector_make(shape == ROOMSHAPE_LTL ? at.x - window.stepX : at.x, at.y);
if (is_void_boss(room) && (shape == ROOMSHAPE_1x2 || shape == ROOMSHAPE_2x1 || shape == ROOMSHAPE_2x2))
{
Vector shift = void_boss_shift(room, window);
position = vector_make(position.x + shift.x, position.y + shift.y);
frame = 0;
cells = vector_make(1, 1);
}
bool isRed = room.flags & ROOM_DESCRIPTOR_FLAG_RED_ROOM;
if (isRed) tint_set(mapSprite, 1, RED_ROOM_TINT, RED_ROOM_TINT);
if (window.current && window.current->listIndex == room.listIndex)
{
mapSprite.SetFrame(ANIMATION_ROOM_CURRENT, frame);
mapSprite.Render({position});
float inset = margin + gap;
center = vector_make(cells.x * cellSize.x * 0.5f + at.x + inset, cells.y * cellSize.y * 0.5f + at.y + inset);
}
else
{
int type = room.data->type;
bool isBox = room.displayFlags & ROOM_DISPLAY_BOX;
bool isSecret = type == ROOM_SECRET || type == ROOM_SUPERSECRET || type == ROOM_ULTRASECRET;
const char* animation = nullptr;
if (room.flags & ROOM_DESCRIPTOR_FLAG_CLEAR && isBox) animation = ANIMATION_ROOM_VISITED;
else if (isBox && !isSecret) animation = ANIMATION_ROOM_UNVISITED;
if (animation)
{
mapSprite.SetFrame(animation, frame);
mapSprite.Render({position});
}
}
if (isRed) tint_set(mapSprite, 1, 1, 1);
});
cells_walk(*this, window, true, [&](int cell, int roomIndex, Vector at) {
RoomDescriptor& room = game.roomList[roomIndex];
if (room.data && is_room_anchor(room, cell)) room_icons_draw(*this, room, cell, at, window);
});
graphics.Present(KAGE::Graphics::PRESENT_FINISH);
graphics.render_target_pop(KAGE::Graphics::PRESENT_FLUSH);
DAT_00c33910 = 1;
}
// 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.iconLimit = layout.iconLimit;
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 = random_unit() * PI_ROUGH * 2;
float magnitude = (float)shakeDuration / SHAKE_DIVISOR;
shakeOffset = vector_make(cos_float(angle) * magnitude + shakeOffset.x * SHAKE_KEEP,
sin_float(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 as far
// as the large map shows (at least half shown under the extra HUD), 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_ID_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, largeAlpha) : largeAlpha;
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);
}