Curation round 22: every NpcAI below type 400, Repentance bosses and Rotgut, the player's last branches, clots and familiars, bomb tear effects and chain lightning, Mother and Home to Dogma, Greed and Greedier, the new Anm2Ed JSON loader, shared IDs folded (135 duplicates)
This commit is contained in:
1 parent
6a11163842
commit
b9405bfb31
198 files changed
+21859
-2999
No files matched your search
+757
@@ -0,0 +1,757 @@
|
||||
#include "ambush.h"
|
||||
#include "entity_config.h"
|
||||
#include "entity_effect_combat.h"
|
||||
#include "entity_factory.h"
|
||||
#include "entity_npc.h"
|
||||
#include "entity_pickup.h"
|
||||
#include "entity_player.h"
|
||||
#include "game.h"
|
||||
#include "grid_entity_door.h"
|
||||
#include "grid_entity_poop.h"
|
||||
#include "grid_entity_pressure_plate.h"
|
||||
#include "log.h"
|
||||
#include "music_manager.h"
|
||||
#include "npc_alt.h"
|
||||
#include "room_grid.h"
|
||||
#include "sfx_manager.h"
|
||||
#include "level.h"
|
||||
#include "manager.h"
|
||||
#include "persistent_game_data.h"
|
||||
#include "room.h"
|
||||
#include "room_config.h"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <array>
|
||||
#include <span>
|
||||
|
||||
// A room of a Greed floor's fixed layout: its cell, shape and type, and the cell and side it joins the layout through
|
||||
// (none for the start room).
|
||||
struct GreedRoom
|
||||
{
|
||||
XY position;
|
||||
RoomShape shape = ROOMSHAPE_1x1;
|
||||
int type = ROOM_DEFAULT;
|
||||
XY linkPos;
|
||||
int connectDirection = DIRECTION_NONE;
|
||||
};
|
||||
|
||||
// A Greed floor: the tall start room, the shop above, the two treasure rooms on the right (none on the shop floor),
|
||||
// the curse room on the left and the exit below. The lower treasure room is the floor's own, which Devil's Crown and
|
||||
// the item pools tell apart.
|
||||
constexpr std::array<GreedRoom, 6> GREED_ROOMS = {{
|
||||
{{6, 6}, ROOMSHAPE_1x2, ROOM_DEFAULT, XY_NONE, DIRECTION_NONE},
|
||||
{{5, 5}, ROOMSHAPE_2x1, ROOM_SHOP, {6, 5}, DIRECTION_UP},
|
||||
{{7, 7}, ROOMSHAPE_1x1, ROOM_TREASURE, {7, 7}, DIRECTION_RIGHT},
|
||||
{{7, 6}, ROOMSHAPE_1x1, ROOM_TREASURE, {7, 6}, DIRECTION_RIGHT},
|
||||
{{5, 6}, ROOMSHAPE_1x1, ROOM_CURSE, {5, 6}, DIRECTION_LEFT},
|
||||
{{6, 8}, ROOMSHAPE_1x1, ROOM_GREED_EXIT, {6, 8}, DIRECTION_DOWN},
|
||||
}};
|
||||
constexpr uint32_t GREED_TREASURE_ROOM_IDX = 6 * LEVEL_GRID_WIDTH + 7;
|
||||
|
||||
// Ultra Greed's floor: the start room, the room above it and the boss's tall room past that.
|
||||
constexpr std::array<GreedRoom, 3> ULTRA_GREED_ROOMS = {{
|
||||
{{6, 6}, ROOMSHAPE_1x1, ROOM_DEFAULT, XY_NONE, DIRECTION_NONE},
|
||||
{{6, 5}, ROOMSHAPE_1x1, ROOM_BOSS, {6, 5}, DIRECTION_UP},
|
||||
{{6, 3}, ROOMSHAPE_1x2, ROOM_BOSS, {6, 4}, DIRECTION_UP},
|
||||
}};
|
||||
constexpr uint32_t ULTRA_GREED_BOSS_VARIANT = 1000;
|
||||
constexpr uint32_t ULTRA_GREED_ANTEROOM_VARIANT_MAX = 999;
|
||||
|
||||
// A Greed treasure room's subtype: Pay to Win's, and 15 in 100 (raised by Golden Horse Shoe's multiplier) the more
|
||||
// options kind while someone holds the horse shoe.
|
||||
constexpr int GREED_TREASURE_OPTIONS = 1;
|
||||
constexpr int GREED_TREASURE_PAY_TO_WIN = 2;
|
||||
constexpr uint32_t GREED_HORSE_SHOE_ROLLS = 100;
|
||||
constexpr uint32_t GREED_HORSE_SHOE_HITS = 15;
|
||||
|
||||
// The difficulties every Greed room is drawn within.
|
||||
constexpr int GREED_DIFFICULTY_MIN = 1;
|
||||
constexpr int GREED_DIFFICULTY_MAX = 10;
|
||||
|
||||
// The angel shop's subtype.
|
||||
constexpr int ANGEL_SHOP_SUBTYPE = 1;
|
||||
|
||||
// A query for a Greed room of a type, a stage and a shape, with the doors its slot has.
|
||||
static RoomQuery greed_query(int stageId, int type, RoomShape shape, uint32_t doors)
|
||||
{
|
||||
return {.requiredDoors = doors,
|
||||
.shape = shape,
|
||||
.maxDifficulty = GREED_DIFFICULTY_MAX,
|
||||
.minDifficulty = GREED_DIFFICULTY_MIN,
|
||||
.stageId = stageId,
|
||||
.type = type};
|
||||
}
|
||||
|
||||
// A generator room for a room of the fixed layout.
|
||||
static LevelGenerator_Room greed_slot(const GreedRoom& room)
|
||||
{
|
||||
LevelGenerator_Room slot;
|
||||
|
||||
slot.position = room.position;
|
||||
slot.shape = room.shape;
|
||||
slot.linkPos = room.linkPos;
|
||||
slot.connectDirection = room.connectDirection;
|
||||
return slot;
|
||||
}
|
||||
|
||||
static int greed_treasure_subtype(RNG& rng)
|
||||
{
|
||||
PlayerManager& players = g_game->playerManager;
|
||||
int subtype = players.AnyoneHasTrinket(TRINKET_PAY_TO_WIN) ? GREED_TREASURE_PAY_TO_WIN : 0;
|
||||
uint32_t rolls =
|
||||
GREED_HORSE_SHOE_ROLLS / (uint32_t)std::max(1, players.GetTrinketMultiplier(TRINKET_GOLDEN_HORSE_SHOE));
|
||||
|
||||
if (rng.RandomInt(rolls) < GREED_HORSE_SHOE_HITS && players.AnyoneHasTrinket(TRINKET_GOLDEN_HORSE_SHOE))
|
||||
subtype =
|
||||
GREED_TREASURE_OPTIONS + (players.AnyoneHasTrinket(TRINKET_PAY_TO_WIN) ? GREED_TREASURE_PAY_TO_WIN : 0);
|
||||
return subtype;
|
||||
}
|
||||
|
||||
// Seeds a room off the map and draws its config from the normal special rooms.
|
||||
static void greed_off_map_room_init(Level& level, int idx, int type, int subtype)
|
||||
{
|
||||
RoomDescriptor& desc = *level.GetRoomByIdx(idx);
|
||||
RoomQuery query = greed_query(STAGE_ID_SPECIAL_ROOMS, type, ROOMSHAPE_ANY, 0);
|
||||
|
||||
query.subtype = subtype;
|
||||
query.mode = ROOM_MODE_NORMAL;
|
||||
desc.InitSeeds(level.generationRNG);
|
||||
desc.data = g_game->roomConfig.GetRandomRoom(level.generationRNG.Next(), WEIGHT_REDUCE, query);
|
||||
}
|
||||
|
||||
// Lays out a normal Greed floor and draws its twelve wave seeds. Its rooms come from the special rooms but for the
|
||||
// start room and the treasure rooms (falling back to the special rooms).
|
||||
static void greed_floor_generate(Level& level)
|
||||
{
|
||||
RoomConfig& roomConfig = g_game->roomConfig;
|
||||
RNG& rng = level.generationRNG;
|
||||
int stageId = RoomConfig::GetStageID((int)level.stage, (int)level.stageType, ROOM_MODE_CURRENT);
|
||||
LevelGenerator generator(rng.Next());
|
||||
std::vector<const GreedRoom*> rooms;
|
||||
|
||||
generator.rooms.reserve(GREED_ROOMS.size() + 1);
|
||||
for (const GreedRoom& room : GREED_ROOMS)
|
||||
{
|
||||
if (room.type == ROOM_TREASURE && level.stage == STAGE_GREED_SHOP) continue;
|
||||
rooms.push_back(&room);
|
||||
generator.CreateRoom(greed_slot(room));
|
||||
}
|
||||
level.lastBossRoomListIdx = generator.rooms[0].generationIndex;
|
||||
LevelGenerator_Room* superSecret = generator.try_add_dead_end(nullptr);
|
||||
|
||||
std::vector<RoomConfig_Room*> configs;
|
||||
for (size_t i = 0; i < rooms.size(); i++)
|
||||
{
|
||||
LevelGenerator_Room& slot = generator.rooms[i];
|
||||
int type = rooms[i]->type;
|
||||
RoomQuery query =
|
||||
greed_query(type == ROOM_DEFAULT ? stageId : STAGE_ID_SPECIAL_ROOMS, type, slot.shape, slot.doors);
|
||||
|
||||
if (type == ROOM_TREASURE)
|
||||
{
|
||||
query.stageId = stageId;
|
||||
query.subtype = greed_treasure_subtype(rng);
|
||||
configs.push_back(
|
||||
roomConfig.GetRandomRoomWithFallbackStage(rng.Next(), WEIGHT_REDUCE, query, STAGE_ID_SPECIAL_ROOMS));
|
||||
}
|
||||
else
|
||||
configs.push_back(roomConfig.GetRandomRoom(rng.Next(), WEIGHT_REDUCE, query));
|
||||
}
|
||||
|
||||
// The original reads a missing dead end's doors through a null pointer. Here it draws for no doors.
|
||||
RoomQuery superSecretQuery =
|
||||
greed_query(STAGE_ID_SPECIAL_ROOMS, ROOM_SUPERSECRET, ROOMSHAPE_1x1, superSecret ? superSecret->doors : 0);
|
||||
RoomConfig_Room* superSecretConfig = roomConfig.GetRandomRoom(rng.Next(), WEIGHT_REDUCE, superSecretQuery);
|
||||
|
||||
level.roomMap.fill(-1);
|
||||
level.nbRooms = 0;
|
||||
level.greedModeTreasureRoomIdx = GREED_TREASURE_ROOM_IDX;
|
||||
for (size_t i = 0; i < configs.size(); i++) level.place_room(generator.rooms[i], configs[i], rng.Next(), nullptr);
|
||||
if (superSecret) level.place_room(*superSecret, superSecretConfig, rng.Next(), nullptr);
|
||||
for (uint32_t& seed : level.greedWaveSeeds) seed = rng.Next();
|
||||
}
|
||||
|
||||
// Lays out Ultra Greed's floor from its fixed start and boss rooms and a drawn room between them.
|
||||
static void ultra_greed_floor_generate(Level& level)
|
||||
{
|
||||
RoomConfig& roomConfig = g_game->roomConfig;
|
||||
RNG& rng = level.generationRNG;
|
||||
LevelGenerator generator(rng.Next());
|
||||
|
||||
generator.rooms.reserve(ULTRA_GREED_ROOMS.size());
|
||||
for (const GreedRoom& room : ULTRA_GREED_ROOMS) generator.CreateRoom(greed_slot(room));
|
||||
|
||||
RoomQuery anteroomQuery = greed_query(STAGE_ID_ULTRA_GREED, ROOM_BOSS, ROOMSHAPE_1x1, generator.rooms[1].doors);
|
||||
anteroomQuery.maxVariant = ULTRA_GREED_ANTEROOM_VARIANT_MAX;
|
||||
|
||||
RoomConfig_Room* start =
|
||||
roomConfig.GetRoomByStageTypeAndVariant(STAGE_ID_ULTRA_GREED, ROOM_DEFAULT, 0, ROOM_MODE_CURRENT);
|
||||
RoomConfig_Room* anteroom = roomConfig.GetRandomRoom(rng.Next(), WEIGHT_REDUCE, anteroomQuery);
|
||||
RoomConfig_Room* boss = roomConfig.GetRoomByStageTypeAndVariant(STAGE_ID_ULTRA_GREED, ROOM_BOSS,
|
||||
ULTRA_GREED_BOSS_VARIANT, ROOM_MODE_CURRENT);
|
||||
|
||||
level.roomMap.fill(-1);
|
||||
level.nbRooms = 0;
|
||||
level.lastBossRoomListIdx = generator.rooms[2].generationIndex;
|
||||
std::array<RoomConfig_Room*, ULTRA_GREED_ROOMS.size()> configs = {start, anteroom, boss};
|
||||
for (size_t i = 0; i < configs.size(); i++) level.place_room(generator.rooms[i], configs[i], rng.Next(), nullptr);
|
||||
}
|
||||
|
||||
// (00743550, 0074378b, 00743fc3) Lays out a Greed floor (Ultra Greed's on the last), then the rooms off the map from
|
||||
// the normal special rooms: the error room, black market, crawl space, the Member Card's shop and the angel shop.
|
||||
void Level::generate_greed()
|
||||
{
|
||||
PersistentGameData& data = g_manager->persistentGameData;
|
||||
|
||||
if (stage < STAGE_ULTRA_GREED)
|
||||
greed_floor_generate(*this);
|
||||
else
|
||||
ultra_greed_floor_generate(*this);
|
||||
|
||||
greed_off_map_room_init(*this, ROOM_ERROR_IDX, ROOM_ERROR, -1);
|
||||
greed_off_map_room_init(*this, ROOM_BLACK_MARKET_IDX, ROOM_BLACK_MARKET, -1);
|
||||
greed_off_map_room_init(*this, ROOM_DUNGEON_IDX, ROOM_DUNGEON, -1);
|
||||
|
||||
RNG shopRng = {generationRNG.Next(), 3, 3, 26};
|
||||
uint32_t lowLevel =
|
||||
shopRng.RandomInt(1 + data.Unlocked(ACHIEVEMENT_STORE_UPGRADE_2) + data.Unlocked(ACHIEVEMENT_STORE_UPGRADE_4));
|
||||
uint32_t highLevel = shopRng.RandomInt(1 + data.Unlocked(ACHIEVEMENT_STORE_UPGRADE_3));
|
||||
|
||||
greed_off_map_room_init(*this, ROOM_SECRET_SHOP_IDX, ROOM_SHOP, (int)(lowLevel + highLevel));
|
||||
generationRNG.Next();
|
||||
greed_off_map_room_init(*this, ROOM_ANGEL_SHOP_IDX, ROOM_ANGEL, ANGEL_SHOP_SUBTYPE);
|
||||
}
|
||||
|
||||
// Greed's waves: twelve, the boss waves from the ninth (one later in Greedier), the last of them the devil wave the
|
||||
// button calls only once it shows the pentagram. A wave's timer counts frames, none while the button waits.
|
||||
constexpr uint32_t GREED_WAVE_LAST = GREED_WAVE_SEED_COUNT;
|
||||
constexpr uint32_t GREED_DEVIL_WAVE = 11;
|
||||
constexpr int WAVE_TIMER_FRAMES = 30;
|
||||
constexpr int WAVE_TIMER_NONE = -1;
|
||||
constexpr int WAVE_TIMER_CLEARED = 19;
|
||||
|
||||
// A normal wave's seconds by floor (more each wave), one less in Greed once Everything Is Terrible 2 is unlocked,
|
||||
// and a boss wave's from its base and its step per wave past the sixth. Greedier counts down faster.
|
||||
constexpr std::array<int, 5> GREED_WAVE_SECONDS = {0, 8, 8, 7, 6};
|
||||
constexpr std::array<int, 5> GREEDIER_WAVE_SECONDS = {0, 9, 7, 5, 4};
|
||||
constexpr int GREED_WAVE_SECONDS_LATE = 8;
|
||||
constexpr int GREEDIER_WAVE_SECONDS_LATE = 3;
|
||||
constexpr int GREED_BOSS_SECONDS = 28;
|
||||
constexpr int GREED_BOSS_SECONDS_FAST = 25;
|
||||
constexpr int GREED_BOSS_SECONDS_STEP = 3;
|
||||
constexpr int GREEDIER_BOSS_SECONDS = 15;
|
||||
constexpr int GREED_BOSS_STEP_FROM = 6;
|
||||
|
||||
// The coins a wave pays: two (one in Greedier) for a normal wave, two more for a boss wave, one more for Greedier's
|
||||
// first boss wave and three more for its last, none for the devil wave. One less after the button was pressed
|
||||
// against a running wave by someone it could not hurt, one more every third wave in a row cleared without red heart
|
||||
// damage.
|
||||
constexpr int GREED_WAVE_COINS = 2;
|
||||
constexpr int GREEDIER_WAVE_COINS = 1;
|
||||
constexpr int BOSS_WAVE_COINS = 2;
|
||||
constexpr int GREEDIER_LAST_BOSS_COINS = 3;
|
||||
constexpr int CLEAN_WAVE_STREAK = 3;
|
||||
|
||||
// The difficulty of the rooms a wave is drawn from by the waves before it, in Greed and in Greedier, any past them.
|
||||
constexpr std::array<int, 11> GREED_WAVE_DIFFICULTY = {1, 1, 1, 5, 5, 5, 10, 10, 1, 5, 10};
|
||||
constexpr std::array<int, 12> GREEDIER_WAVE_DIFFICULTY = {1, 1, 1, 5, 5, 5, 10, 10, 10, 1, 5, 10};
|
||||
|
||||
// The coins drop on the room's middle column four cells down, each in a poof of gold.
|
||||
constexpr int COIN_ROW = 4;
|
||||
constexpr float COIN_SPARKLE_SPEED_MIN = 2;
|
||||
constexpr float COIN_SPARKLE_SPEED_RANGE = 3;
|
||||
constexpr uint32_t COIN_SPARKLE_COUNT_MIN = 5;
|
||||
constexpr uint32_t COIN_SPARKLE_COUNT_RANGE = 3;
|
||||
|
||||
// A wave's pentagrams draw above the floor's decorations.
|
||||
constexpr int WAVE_PENTAGRAM_RENDER_Z = 1001;
|
||||
|
||||
static bool is_greedier()
|
||||
{
|
||||
return g_game->difficulty == DIFFICULTY_GREEDIER;
|
||||
}
|
||||
|
||||
// The first boss wave, and the devil wave.
|
||||
static uint32_t greed_boss_wave()
|
||||
{
|
||||
return GREED_BOSS_WAVE + is_greedier();
|
||||
}
|
||||
|
||||
static uint32_t greed_devil_wave()
|
||||
{
|
||||
return GREED_DEVIL_WAVE + is_greedier();
|
||||
}
|
||||
|
||||
// A called wave's timer: the frames until the next wave comes by itself, none for the last normal and the last boss
|
||||
// wave and the devil wave, which wait for the button.
|
||||
static int greed_wave_timer(uint32_t wave, int wavesBefore)
|
||||
{
|
||||
Game& game = *g_game;
|
||||
uint32_t greedier = is_greedier();
|
||||
bool isFast = !greedier && g_manager->persistentGameData.Unlocked(ACHIEVEMENT_EVERYTHING_IS_TERRIBLE_2);
|
||||
|
||||
if (wave == greed_boss_wave() - 1 || wave == greed_boss_wave() + 1 || wave >= greed_devil_wave())
|
||||
return WAVE_TIMER_NONE;
|
||||
if (wave >= greed_boss_wave())
|
||||
{
|
||||
if (greedier) return GREEDIER_BOSS_SECONDS * WAVE_TIMER_FRAMES;
|
||||
int seconds = isFast ? GREED_BOSS_SECONDS_FAST : GREED_BOSS_SECONDS;
|
||||
return ((wavesBefore - GREED_BOSS_STEP_FROM) * GREED_BOSS_SECONDS_STEP + seconds) * WAVE_TIMER_FRAMES;
|
||||
}
|
||||
|
||||
const std::array<int, 5>& table = greedier ? GREEDIER_WAVE_SECONDS : GREED_WAVE_SECONDS;
|
||||
int seconds = game.stage < table.size() ? table[game.stage]
|
||||
: (greedier ? GREEDIER_WAVE_SECONDS_LATE : GREED_WAVE_SECONDS_LATE);
|
||||
return (seconds - isFast + wavesBefore) * WAVE_TIMER_FRAMES;
|
||||
}
|
||||
|
||||
// The coins a called wave pays when it is the first time the wave is reached, before the penalty and the streak.
|
||||
static int greed_wave_coins(uint32_t wave)
|
||||
{
|
||||
bool isGreedier = is_greedier();
|
||||
int coins = isGreedier ? GREEDIER_WAVE_COINS : GREED_WAVE_COINS;
|
||||
|
||||
if (wave >= greed_boss_wave()) coins += BOSS_WAVE_COINS;
|
||||
if (isGreedier && wave == greed_boss_wave() - 1) coins++;
|
||||
if (isGreedier && wave == greed_devil_wave() - 1) coins += GREEDIER_LAST_BOSS_COINS;
|
||||
return wave == greed_devil_wave() ? 0 : coins;
|
||||
}
|
||||
|
||||
// The wave's music: the shop floor's challenge fight or the floor's layer for a normal wave, then the boss fight
|
||||
// (Satan's for the devil wave, the Repentance floors' own, or the room's alternate).
|
||||
static void greed_wave_music(Room& room, uint32_t wave, int stageId)
|
||||
{
|
||||
Game& game = *g_game;
|
||||
MusicManager& music = g_manager->musicManager;
|
||||
|
||||
if (wave < greed_boss_wave())
|
||||
{
|
||||
if (stageId == STAGE_ID_GREED_SHOP)
|
||||
music.Crossfade(MUSIC_CHALLENGE_FIGHT, MUSIC_FADE_RATE);
|
||||
else
|
||||
music.EnableLayer(0, LAYER_FADE);
|
||||
return;
|
||||
}
|
||||
bool isRepentance = game.stageType == STAGETYPE_REPENTANCE || game.stageType == STAGETYPE_REPENTANCE_B;
|
||||
bool isAltMusic = room.descriptor->flags & ROOM_DESCRIPTOR_FLAG_ALT_BOSS_MUSIC;
|
||||
int track = wave == greed_devil_wave() ? MUSIC_SATAN_BOSS
|
||||
: isRepentance ? MUSIC_BOSS3
|
||||
: isAltMusic ? MUSIC_BOSS2
|
||||
: MUSIC_BOSS;
|
||||
music.Crossfade(track, MUSIC_FADE_RATE);
|
||||
}
|
||||
|
||||
// The coins a wave pays drop in the room's middle, each with a poof of gold.
|
||||
static void greed_wave_pay(Room& room, int coins, RNG& rng)
|
||||
{
|
||||
int column = room.gridWidth / 2;
|
||||
int cell =
|
||||
column >= 0 && column < room.gridWidth && room.gridHeight > COIN_ROW ? column + room.gridWidth * COIN_ROW : -1;
|
||||
Vector center = room.GetGridPosition(cell);
|
||||
|
||||
for (int i = 0; i < coins; i++)
|
||||
{
|
||||
Vector position = room_free_pickup_position_find({.position = center});
|
||||
Entity* coin = g_game->Spawn({.position = position,
|
||||
.subType = COIN_PENNY,
|
||||
.type = ENTITY_PICKUP,
|
||||
.variant = PICKUP_COIN,
|
||||
.seed = rng.Next()});
|
||||
|
||||
if (auto* pickup = dynamic_cast<Entity_Pickup*>(coin)) pickup->AppearFast();
|
||||
float speed = random_unit() * COIN_SPARKLE_SPEED_RANGE + COIN_SPARKLE_SPEED_MIN;
|
||||
int count = (int)(Random() % COIN_SPARKLE_COUNT_RANGE + COIN_SPARKLE_COUNT_MIN);
|
||||
game_particles_spawn({.position = position, .speed = speed, .count = count, .variant = EFFECT_GOLD_PARTICLE});
|
||||
}
|
||||
}
|
||||
|
||||
// Where a wave's entry rises: its own cell, or the nearest free spot when the cell is off the grid, blocked, or on a
|
||||
// path. The dungeon of Home keeps its cells.
|
||||
static int greed_wave_cell(Room& room, int cell, Vector& position)
|
||||
{
|
||||
RoomConfig_Room* data = room.descriptor->data;
|
||||
bool isKept = data && data->type == ROOM_DUNGEON && data->stageId == STAGE_ID_HOME;
|
||||
GridEntity* grid = cell >= 0 ? room.gridEntities[cell] : nullptr;
|
||||
bool isBlocked =
|
||||
cell < 0 || (grid ? grid->collisionClass != COLLISION_NONE : room.gridPaths[cell] >= GRID_PATH_SOLID);
|
||||
|
||||
if (isKept || !isBlocked) return cell;
|
||||
position = room_free_pickup_position_find({.position = position});
|
||||
return room.GetGridIndex(position);
|
||||
}
|
||||
|
||||
// Spawns a wave's layout: each spawn breaks the grid entity on its cell, then rises from a pentagram (an enemy with
|
||||
// the ambush flag), appears as an effect at once, or is spawned as the room would.
|
||||
static void greed_wave_entries_spawn(Room& room, RoomConfig_Room& wave, RNG& rng)
|
||||
{
|
||||
if (room.gridWidth != wave.width + 2) log_printf(LOG_ASSERT, "Greed Mode wave does not match room size\n");
|
||||
|
||||
for (RoomSpawn& spawn : wave.spawns)
|
||||
{
|
||||
float roll = rng.RandomFloat();
|
||||
int cell = spawn.x + (spawn.y + 1) * room.gridWidth + 1;
|
||||
Vector position = room.GetGridPosition(cell);
|
||||
|
||||
if ((uint32_t)cell < ROOM_GRID_CELLS && room.gridEntities[cell]) room.gridEntities[cell]->Destroy(true, {});
|
||||
cell = greed_wave_cell(room, cell, position);
|
||||
if (spawn.entries.empty()) continue;
|
||||
|
||||
RoomEntry entry = *spawn.PickEntry(roll);
|
||||
uint32_t seed = rng.Next();
|
||||
room_entry_transform(room, entry, cell, seed);
|
||||
if (entry.type < 1) continue;
|
||||
if (entry.type >= ENTITY_EFFECT)
|
||||
{
|
||||
room_entry_spawn(room, entry, {.gridIndex = cell, .seed = seed});
|
||||
continue;
|
||||
}
|
||||
if (entry.type == WAVE_ENTRY_EFFECT)
|
||||
{
|
||||
Entity* effect = g_game->Spawn({.position = position,
|
||||
.subType = entry.subtype,
|
||||
.type = ENTITY_EFFECT,
|
||||
.variant = entry.variant,
|
||||
.seed = rng.Next()});
|
||||
effect->Update();
|
||||
effect->spawnGridIndex = cell;
|
||||
continue;
|
||||
}
|
||||
Entity_Effect* pentagram = pentagram_spawn({.position = position,
|
||||
.subType = entry.subtype,
|
||||
.type = (int)entry.type,
|
||||
.variant = entry.variant,
|
||||
.seed = rng.Next()},
|
||||
cell);
|
||||
bool isVersusPlayer = g_game->deathmatchManager.is_active() && entry.type == ENTITY_PLAYER;
|
||||
|
||||
pentagram->renderZOffset = WAVE_PENTAGRAM_RENDER_Z;
|
||||
if (isVersusPlayer || entry.type >= ENTITY_FIRST_ENEMY) pentagram->AddEntityFlags(FLAG_AMBUSH);
|
||||
}
|
||||
}
|
||||
|
||||
// Whether Greedier may make an entity a champion: an active enemy spawned this frame that is no boss.
|
||||
static Entity_NPC* greedier_champion_candidate(Entity& entity)
|
||||
{
|
||||
if (!entity.IsActiveEnemy(DEAD_EXCLUDED) || entity.IsBoss() || entity.spawnFrame != g_game->frameCount)
|
||||
return nullptr;
|
||||
|
||||
auto* npc = dynamic_cast<Entity_NPC*>(&entity);
|
||||
EntityConfig_Entity* config =
|
||||
npc ? g_manager->entityConfig.GetEntity(npc->type, npc->variant, npc->subtype) : nullptr;
|
||||
return config && config->isCanBeChampion ? npc : nullptr;
|
||||
}
|
||||
|
||||
// Greedier makes one of the wave's new enemies a champion unless one already is.
|
||||
static void greedier_champion_make(Room& room, RNG& rng)
|
||||
{
|
||||
std::vector<Entity_NPC*> candidates;
|
||||
|
||||
for (Entity* entity : room.entityList.updateEL)
|
||||
if (Entity_NPC* npc = greedier_champion_candidate(*entity))
|
||||
{
|
||||
if (npc->isChampion) return;
|
||||
candidates.push_back(npc);
|
||||
}
|
||||
if (candidates.empty()) return;
|
||||
|
||||
Entity_NPC* chosen = candidates[rng.Next() % candidates.size()];
|
||||
chosen->MakeChampion(rng.Next(), -1, false);
|
||||
}
|
||||
|
||||
// 00816910 Calls Greed's next wave: the room shuts, the wave's timer and music start, a wave reached the first time
|
||||
// pays its coins (and the players' locusts come), and its enemies rise from a challenge room of the floor drawn for
|
||||
// the wave (a boss room for the boss waves) by the wave's seed. Greedier makes one of them a champion.
|
||||
void Room::SpawnGreedModeWave()
|
||||
{
|
||||
Game& game = *g_game;
|
||||
int wavesBefore = game.greedModeWave;
|
||||
uint32_t wave = std::min<uint32_t>((uint32_t)wavesBefore + 1, GREED_WAVE_LAST);
|
||||
int stageId = RoomConfig::GetStageID((int)game.stage, (int)game.stageType, ROOM_MODE_CURRENT);
|
||||
RNG rng = {game.greedWaveSeeds[wave - 1], 1, 27, 27};
|
||||
|
||||
descriptor->flags &= ~ROOM_DESCRIPTOR_FLAG_CLEAR;
|
||||
for (GridEntity_Door* door : doors)
|
||||
{
|
||||
if (!door) continue;
|
||||
if (door->state != DOOR_STATE_CLOSED)
|
||||
{
|
||||
door->state = DOOR_STATE_CLOSED;
|
||||
door->UpdateAnimation();
|
||||
for (int type : {door->currentRoomType, door->targetRoomType})
|
||||
if (type == ROOM_SECRET || type == ROOM_SUPERSECRET || type == ROOM_ULTRASECRET)
|
||||
door->openAnimation = "Open";
|
||||
}
|
||||
if (door->variant == DOOR_UNLOCKED) door->Bar();
|
||||
}
|
||||
|
||||
game.greedModeWave = (int)wave;
|
||||
greedWaveTimer = greed_wave_timer(wave, wavesBefore);
|
||||
greed_wave_music(*this, wave, stageId);
|
||||
|
||||
int coins = greed_wave_coins(wave);
|
||||
if (coins && (game.levelStateFlags & 1u << LEVEL_STATE_GREED_LOST_PENALTY))
|
||||
{
|
||||
coins--;
|
||||
game.levelStateFlags &= ~(1u << LEVEL_STATE_GREED_LOST_PENALTY);
|
||||
}
|
||||
if (game.greedWavesClearedWithoutRedHeartDamage > 0 &&
|
||||
game.greedWavesClearedWithoutRedHeartDamage % CLEAN_WAVE_STREAK == 0)
|
||||
coins++;
|
||||
game.greedWavesClearedWithoutRedHeartDamage++;
|
||||
|
||||
int sound = SOUND_SUMMON_PENTA;
|
||||
seed_fart_sound_override(&sound);
|
||||
g_manager->sfxManager.Play(sound, {.frameDelay = 3});
|
||||
|
||||
size_t band = (size_t)wavesBefore;
|
||||
std::span<const int> bands = is_greedier() ? std::span<const int>(GREEDIER_WAVE_DIFFICULTY) : GREED_WAVE_DIFFICULTY;
|
||||
RoomQuery query = {.shape = descriptor->data->shape,
|
||||
.maxDifficulty = band < bands.size() ? bands[band] : GREED_DIFFICULTY_MAX,
|
||||
.minDifficulty = band < bands.size() ? bands[band] : GREED_DIFFICULTY_MIN,
|
||||
.stageId = stageId,
|
||||
.type = wave < greed_boss_wave() ? ROOM_CHALLENGE : ROOM_BOSS};
|
||||
RoomConfig_Room* waveRoom = game.roomConfig.GetRandomRoom(rng.Next(), WEIGHT_KEEP, query);
|
||||
|
||||
if (!waveRoom)
|
||||
{
|
||||
log_printf(LOG_INFO, "Did not find wave level %d (greed mode).\n", wave);
|
||||
return;
|
||||
}
|
||||
log_printf(LOG_INFO, "Spawning greed mode wave from room variant %d.\n", waveRoom->variant);
|
||||
if ((uint32_t)game.greedLastPaidWave < wave)
|
||||
{
|
||||
game.playerManager.trigger_room_clear();
|
||||
greed_wave_pay(*this, coins, rng);
|
||||
game.greedLastPaidWave = (int)wave;
|
||||
for (Entity_Player* player : game.playerManager.playerList) player->spawn_locusts();
|
||||
}
|
||||
|
||||
isInitialized = false;
|
||||
greed_wave_entries_spawn(*this, *waveRoom, rng);
|
||||
if (is_greedier()) greedier_champion_make(*this, rng);
|
||||
isInitialized = true;
|
||||
}
|
||||
|
||||
// Ultra Greed's room opens its fight once a player walks in past its doorway: Monstro drops on that player first in
|
||||
// the plain layout.
|
||||
constexpr float ULTRA_GREED_ENTRY_Y = 320;
|
||||
constexpr int MONSTRO_SUBTYPE_ANY = -1;
|
||||
|
||||
// The first player who walked into Ultra Greed's room, or none.
|
||||
static Entity_Player* ultra_greed_room_entrant()
|
||||
{
|
||||
for (Entity_Player* player : g_game->playerManager.playerList)
|
||||
if (player->pos.y < ULTRA_GREED_ENTRY_Y) return player;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// 00801ee0 Greed mode's waves: the timer runs down to the next wave, cut short to its last frames once the wave is
|
||||
// beaten, and Ultra Greed's room starts its fight (Monstro first, in the plain layout) once a player walks in.
|
||||
void Room::UpdateGreedWave()
|
||||
{
|
||||
Game& game = *g_game;
|
||||
|
||||
if (!game.IsGreedMode()) return;
|
||||
if (greedWaveTimer > 0)
|
||||
{
|
||||
greedWaveTimer--;
|
||||
if (GetAliveEnemiesCount() < 1 && greedWaveTimer > WAVE_TIMER_CLEARED)
|
||||
{
|
||||
game.greedLastBeatenWave = game.greedModeWave;
|
||||
greedWaveTimer = WAVE_TIMER_CLEARED;
|
||||
}
|
||||
else if (greedWaveTimer == 0)
|
||||
SpawnGreedModeWave();
|
||||
}
|
||||
|
||||
if (game.stage != STAGE_ULTRA_GREED || roomType != ROOM_BOSS) return;
|
||||
if (game.levelStateFlags & 1u << LEVEL_STATE_GREED_MONSTRO_SPAWNED) return;
|
||||
Entity_Player* entrant = ultra_greed_room_entrant();
|
||||
if (!entrant) return;
|
||||
|
||||
g_manager->musicManager.Play(MUSIC_BOSS, g_manager->optionsConfig.musicVolume);
|
||||
descriptor->flags &= ~ROOM_DESCRIPTOR_FLAG_ALT_BOSS_MUSIC;
|
||||
game.levelStateFlags |= 1u << LEVEL_STATE_GREED_MONSTRO_SPAWNED;
|
||||
if (descriptor->data->subtype == 0)
|
||||
{
|
||||
Entity* monstro = game.Spawn(
|
||||
{.position = entrant->pos, .subType = MONSTRO_SUBTYPE_ANY, .type = ENTITY_MONSTRO, .seed = Random()});
|
||||
monstro->ClearEntityFlags(FLAG_APPEAR);
|
||||
monstro->Update();
|
||||
}
|
||||
TriggerOutput(0);
|
||||
|
||||
int sound = SOUND_CASTLEPORTCULLIS;
|
||||
seed_fart_sound_override(&sound);
|
||||
g_manager->sfxManager.Play(sound);
|
||||
}
|
||||
|
||||
// Greed's button: a player this close presses it, and it stays pressed until every player is this far away.
|
||||
constexpr float GREED_BUTTON_PRESS_DISTANCE = 25;
|
||||
constexpr float GREED_BUTTON_LEAVE_DISTANCE = 30;
|
||||
constexpr float GREED_BUTTON_HURT = 1;
|
||||
constexpr int GREED_BUTTON_HURT_COUNTDOWN = 30;
|
||||
|
||||
// Calling a wave ends Taurus's charge: the player's speed bonus is lost and the charge starts over.
|
||||
static void taurus_restart(Entity_Player& player)
|
||||
{
|
||||
bool isTaurus = player.HasCollectible(COLLECTIBLE_TAURUS) || player.GetZodiacEffect() == COLLECTIBLE_TAURUS;
|
||||
|
||||
if (!isTaurus || player.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_TAURUS)) return;
|
||||
player.taurusSpeedBonus = 0;
|
||||
player.SetColor(COLOR_DEFAULT, -1, COLOR_PRIORITY_DEFAULT, false, true);
|
||||
if (ItemConfig_Item* taurus = g_manager->itemConfig.GetCollectible(COLLECTIBLE_TAURUS))
|
||||
player.temporaryEffects.AddEffect(TemporaryEffect(taurus), true, 1);
|
||||
}
|
||||
|
||||
// 009839f0 Runs Greed mode's wave button: a player stepping on it presses it (hurt for it while a wave runs, or
|
||||
// costing a coin of the next wave when it cannot hurt them), and once its switch animation ends it calls the next
|
||||
// wave, or stops the timer while one runs. It rises again once everyone stepped off, unless the waves are over or a
|
||||
// wave runs with the room still shut. A beaten wave holds it down until the next is called.
|
||||
void GridEntity_PressurePlate::update_greed_button()
|
||||
{
|
||||
Game& game = *g_game;
|
||||
Room& room = *game.room;
|
||||
bool isWaveRunning = room.greedWaveTimer > 0;
|
||||
bool isClear = room.descriptor->flags & ROOM_DESCRIPTOR_FLAG_CLEAR;
|
||||
Vector center = room.GetGridPosition(gridIndex);
|
||||
bool isNear = false;
|
||||
bool isEveryoneAway = true;
|
||||
|
||||
for (Entity_Player* player : game.playerManager.playerList)
|
||||
{
|
||||
if (player->variant != PLAYER_VARIANT_PLAYER || player->isCoopGhost) continue;
|
||||
|
||||
float distance = vector_length_squared(vector_sub(center, player->pos));
|
||||
isNear |= distance < GREED_BUTTON_PRESS_DISTANCE * GREED_BUTTON_PRESS_DISTANCE;
|
||||
isEveryoneAway &= !(distance <= GREED_BUTTON_LEAVE_DISTANCE * GREED_BUTTON_LEAVE_DISTANCE);
|
||||
if (distance >= GREED_BUTTON_PRESS_DISTANCE * GREED_BUTTON_PRESS_DISTANCE || state != PLATE_UNPRESSED) continue;
|
||||
|
||||
if (isWaveRunning)
|
||||
{
|
||||
if (player->GetHealthType() == HEALTH_COIN || player->HasInstantDeathCurse())
|
||||
game.levelStateFlags |= 1u << LEVEL_STATE_GREED_LOST_PENALTY;
|
||||
else
|
||||
player->TakeDamage(GREED_BUTTON_HURT, DAMAGE_SPIKES | DAMAGE_NO_PENALTIES, {},
|
||||
GREED_BUTTON_HURT_COUNTDOWN);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
GreedButtonColor color = isWaveRunning ? GREED_BUTTON_RED : GREED_BUTTON_NORMAL;
|
||||
if (state == PLATE_UNPRESSED && isNear)
|
||||
{
|
||||
state = PLATE_GREED_PRESSED;
|
||||
if (!sprite.IsPlaying() || sprite.GetAnimation() != "Switched")
|
||||
{
|
||||
int sound = SOUND_BUTTON_PRESS;
|
||||
seed_fart_sound_override(&sound);
|
||||
g_manager->sfxManager.Play(sound);
|
||||
}
|
||||
update_greed_button_anim(color);
|
||||
}
|
||||
if (!sprite.IsPlaying() && (state == PLATE_GREED_PRESSED || state == PLATE_GREED_HELD))
|
||||
{
|
||||
if (state == PLATE_GREED_PRESSED && !isWaveRunning)
|
||||
{
|
||||
room.SpawnGreedModeWave();
|
||||
for (Entity_Player* player : game.playerManager.playerList) taurus_restart(*player);
|
||||
}
|
||||
else if (state == PLATE_GREED_PRESSED)
|
||||
room.greedWaveTimer = WAVE_TIMER_NONE;
|
||||
state = PLATE_PRESSED;
|
||||
update_greed_button_anim(color);
|
||||
}
|
||||
|
||||
bool isTimerRunning = room.greedWaveTimer > 0;
|
||||
color = isTimerRunning ? GREED_BUTTON_RED : GREED_BUTTON_NORMAL;
|
||||
if (state == PLATE_PRESSED && isEveryoneAway && (uint32_t)game.greedModeWave < greed_devil_wave() &&
|
||||
(isTimerRunning || isClear))
|
||||
{
|
||||
state = PLATE_UNPRESSED;
|
||||
update_greed_button_anim(color);
|
||||
}
|
||||
else if (state == PLATE_UNPRESSED && !isTimerRunning && !isClear)
|
||||
{
|
||||
state = PLATE_GREED_HELD;
|
||||
update_greed_button_anim(color);
|
||||
}
|
||||
play_pending_animation();
|
||||
}
|
||||
|
||||
// The Greed donation machine's jam chance: certain for the characters past the table, else from the coins the
|
||||
// character has donated (e^(0.023 coins) - 1, at most 100), a fifth of it rounded, at most 1 in Greedier.
|
||||
constexpr float DONATION_JAM_UNKNOWN = 99.9f;
|
||||
constexpr float DONATION_JAM_GROWTH = 0.023f;
|
||||
constexpr float DONATION_JAM_MAX = 100;
|
||||
constexpr float DONATION_JAM_SHARE = 0.2f;
|
||||
constexpr float DONATION_JAM_GREEDIER_MAX = 1;
|
||||
|
||||
// 007cbb90 The chance in percent the Greed donation machine jams, from a save's donation counter.
|
||||
float Entity_Player::GetGreedDonationJamChance(PersistentGameData& data)
|
||||
{
|
||||
if ((uint32_t)playerType >= (uint32_t)COMPLETION_PLAYER_TYPE_COUNT) return DONATION_JAM_UNKNOWN;
|
||||
|
||||
uint32_t donated = data.eventCounters[COMPLETION_MARKS[playerType][COMPLETION_GREED_DONATION].counter];
|
||||
float chance = std::min(std::exp((float)donated * DONATION_JAM_GROWTH) - 1, DONATION_JAM_MAX);
|
||||
chance = std::floor(chance * DONATION_JAM_SHARE + HALF);
|
||||
return g_game->difficulty == DIFFICULTY_GREEDIER ? std::min(DONATION_JAM_GREEDIER_MAX, chance) : chance;
|
||||
}
|
||||
|
||||
// 007cbb70 The chance the machine breaks: its jam chance from the game's save.
|
||||
float Entity_Player::GetGreedDonationBreakChance()
|
||||
{
|
||||
return GetGreedDonationJamChance(g_manager->persistentGameData);
|
||||
}
|
||||
|
||||
// A gold room: the floor and walls washed gold, the grid entities a paler gold.
|
||||
constexpr ColorMod GOLD_ROOM_COLOR = {{1, 1, 1, 1}, {5, 3, 0, 0.8f}, {0, 0, 0}};
|
||||
constexpr ColorMod GOLD_GRID_COLOR = {{1, 1, 1, 1}, {3, 1.8f, 0, 0.8f}, {0, 0, 0}};
|
||||
|
||||
// 007ebd50 Room::SpawnGridEntityDesc: a grid entity spawned on a free cell (a flat one where nothing collides, any
|
||||
// other where the path is not blocked) from a saved description, replacing what stood there.
|
||||
static bool room_grid_desc_spawn(Room& room, int gridIndex, const GridEntityDesc& desc)
|
||||
{
|
||||
if ((uint32_t)gridIndex >= ROOM_GRID_CELLS)
|
||||
{
|
||||
log_printf(LOG_ASSERT, "SpawnGridEntity: Grid index invalid\n");
|
||||
return false;
|
||||
}
|
||||
bool isFlat = desc._type == GRID_TRAPDOOR || desc._type == GRID_STAIRS || desc._type == GRID_PRESSURE_PLATE ||
|
||||
desc._type == GRID_TELEPORTER;
|
||||
bool isFree =
|
||||
isFlat ? room.GetGridCollision(gridIndex) == COLLISION_NONE : room.gridPaths[gridIndex] <= GRID_PATH_FREED;
|
||||
GridEntity* grid = isFree ? CreateGridEntity((GridEntityType)desc._type, gridIndex) : nullptr;
|
||||
if (!grid) return false;
|
||||
|
||||
delete room.gridEntities[gridIndex];
|
||||
room.gridEntities[gridIndex] = grid;
|
||||
grid->desc_load(desc);
|
||||
grid->collisionClass = COLLISION_NONE;
|
||||
grid->subclass_init();
|
||||
grid->spawnCount++;
|
||||
grid->isInitialized = true;
|
||||
grid->spawnFrame = g_game->frameCount;
|
||||
return true;
|
||||
}
|
||||
|
||||
// 00820ac0 Turns the room gold (Ultra Greed's room once he turns): its floor and walls, every poop to gold poop and
|
||||
// every other grid entity's look.
|
||||
void Room::TurnGold()
|
||||
{
|
||||
floorColor = GOLD_ROOM_COLOR;
|
||||
wallColor = GOLD_ROOM_COLOR;
|
||||
for (int i = 0; i < ROOM_GRID_CELLS; i++)
|
||||
{
|
||||
GridEntity* grid = gridEntities[i];
|
||||
if (!grid) continue;
|
||||
if (grid->type != GRID_POOP)
|
||||
grid->sprite.color = GOLD_GRID_COLOR;
|
||||
else if (grid->variant != POOP_GOLDEN)
|
||||
{
|
||||
GridEntityDesc gold = grid->desc_save();
|
||||
gold._variant = POOP_GOLDEN;
|
||||
room_grid_desc_spawn(*this, i, gold);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user