From 5c89798773b3b456ae9e3167fc9fb618fa0955b2 Mon Sep 17 00:00:00 2001 From: shweet Date: Mon, 23 Nov 2026 07:35:21 -0500 Subject: [PATCH] Curation round 25 (code only): the ultra horsemen and the Beast's background, the Scourge and Polty, the player's last gaps with the frame gate removed, game core, debug and daily, local co-op and player-controlled enemies, TMTRAINER, local versus, the vanilla Lua API, the special-daily fix, shared constants folded (60 duplicates, 10 offline gaps) --- .../afterbirth_persistent_game_data.cpp | 332 -- generated-src/classes.h | 434 +- generated-src/deathmatch_type_base.cpp | 716 ---- generated-src/glitched_collectible_gfx.cpp | 21 - generated-src/glitched_item_set.cpp | 77 - generated-src/npc_helper.cpp | 363 -- generated-src/procedural_effect.cpp | 623 --- generated-src/rebirth_save_data.cpp | 346 -- generated-src/spawn.cpp | 9 - generated-src/sprite.cpp | 112 - generated-src/stubs.cpp | 387 -- generated-src/vector.cpp | 54 - src/active_items.h | 1 - src/ambush.cpp | 5 +- src/anm2.cpp | 25 +- src/anm2.h | 13 + src/backdrop.cpp | 5 +- src/beam_renderer.cpp | 5 +- src/bomb_explosion.cpp | 40 +- src/boss_beast.cpp | 30 +- src/boss_beast_horsemen.cpp | 3773 +++++++++++++++++ src/boss_big_horn.cpp | 2 +- src/boss_bumbino.cpp | 22 +- src/boss_cage.cpp | 7 +- src/boss_colostomia.cpp | 4 +- src/boss_daddy_long_legs.cpp | 2 +- src/boss_death.cpp | 67 +- src/boss_dogma.cpp | 5 +- src/boss_final.h | 2 + src/boss_fistula.cpp | 12 +- src/boss_forsaken.cpp | 2 +- src/boss_gideon.cpp | 6 +- src/boss_gurdy.cpp | 2 +- src/boss_horny_boys.cpp | 2 +- src/boss_intro.cpp | 1 - src/boss_isaac.cpp | 2 +- src/boss_larry_jr.cpp | 79 +- src/boss_lil_blub.cpp | 2 +- src/boss_mask_of_infamy.cpp | 53 +- src/boss_matriarch.cpp | 3 +- src/boss_mega_fatty.cpp | 4 +- src/boss_min_min.cpp | 7 +- src/boss_monstro.cpp | 2 +- src/boss_mother.cpp | 21 +- src/boss_mothers_shadow.cpp | 4 +- src/boss_peep.cpp | 8 +- src/boss_pestilence.cpp | 2 +- src/boss_pin.cpp | 7 +- src/boss_polycephalus.cpp | 2 +- src/boss_pool.cpp | 3 +- src/boss_rag_man.cpp | 2 +- src/boss_repentance.h | 23 + src/boss_rotgut.cpp | 8 +- src/boss_satan.cpp | 2 +- src/boss_scourge.cpp | 1349 ++++++ src/boss_sisters_vis.cpp | 2 +- src/boss_visage.cpp | 7 +- src/boss_widow.cpp | 2 +- src/boss_wormwood.cpp | 13 +- src/camera.cpp | 4 +- src/cutscene.cpp | 19 +- src/daily_challenge.cpp | 92 +- src/daily_challenge.h | 41 + src/deathmatch_manager.cpp | 1022 ++++- src/deathmatch_manager.h | 200 +- src/entity.cpp | 117 +- src/entity.h | 10 +- src/entity_bomb.cpp | 8 +- src/entity_bomb.h | 1 - src/entity_collision.cpp | 1 - src/entity_combat.cpp | 135 +- src/entity_dummy.cpp | 20 +- src/entity_effect.cpp | 3 +- src/entity_effect.h | 4 + src/entity_effect_ambient.cpp | 11 +- src/entity_effect_blast.cpp | 11 +- src/entity_effect_boss.cpp | 8 +- src/entity_effect_combat.cpp | 9 +- src/entity_effect_dogma.cpp | 3 +- src/entity_effect_floor.cpp | 3 +- src/entity_effect_helpers.cpp | 3 +- src/entity_effect_items.cpp | 14 +- src/entity_effect_portal.cpp | 5 +- src/entity_effect_shots.cpp | 7 +- src/entity_effect_souls.cpp | 5 +- src/entity_effect_vortex.cpp | 11 +- src/entity_factory.cpp | 13 +- src/entity_familiar.cpp | 2 +- src/entity_knife.cpp | 5 +- src/entity_knife_hits.cpp | 5 +- src/entity_laser_hits.cpp | 22 +- src/entity_list.cpp | 5 +- src/entity_npc.cpp | 153 +- src/entity_npc.h | 42 +- src/entity_npc_drop.cpp | 1 - src/entity_npc_render.cpp | 9 +- src/entity_npc_rewards.cpp | 6 +- src/entity_pickup.cpp | 62 +- src/entity_pickup.h | 2 +- src/entity_pickup_chest.cpp | 3 +- src/entity_pickup_morph.cpp | 2 +- src/entity_pickup_shop.cpp | 3 +- src/entity_player.cpp | 87 +- src/entity_player.h | 122 +- src/entity_player_actives.cpp | 319 +- src/entity_player_actives_rebirth.cpp | 44 +- src/entity_player_actives_repentance.cpp | 3 +- src/entity_player_bombs.cpp | 16 +- src/entity_player_cards.cpp | 39 +- src/entity_player_characters.cpp | 68 +- src/entity_player_characters.h | 2 +- src/entity_player_collectibles.cpp | 254 +- src/entity_player_coop.cpp | 712 ++++ src/entity_player_crafting.cpp | 3 +- src/entity_player_damage.cpp | 114 +- src/entity_player_dashes.cpp | 607 +++ src/entity_player_death.cpp | 19 +- src/entity_player_effects.cpp | 308 +- src/entity_player_effects.h | 2 + src/entity_player_evaluate.cpp | 122 +- src/entity_player_familiars.cpp | 5 +- src/entity_player_forgotten.cpp | 19 +- src/entity_player_frame.cpp | 98 +- src/entity_player_hits.cpp | 70 +- src/entity_player_hold.cpp | 89 +- src/entity_player_items.cpp | 124 +- src/entity_player_kills.cpp | 15 +- src/entity_player_passives.cpp | 100 +- src/entity_player_passives.h | 1 - src/entity_player_pills.cpp | 14 +- src/entity_player_pockets.cpp | 45 +- src/entity_player_poop_spells.cpp | 8 +- src/entity_player_room.cpp | 44 +- src/entity_player_tears.cpp | 49 +- src/entity_player_trinkets.cpp | 194 +- src/entity_player_update.cpp | 256 +- src/entity_player_weapons.cpp | 19 +- src/entity_projectile.cpp | 8 - src/entity_projectile.h | 11 + src/entity_slot.cpp | 39 +- src/entity_slot.h | 1 + src/entity_status.cpp | 3 +- src/entity_tear.cpp | 47 +- src/entity_tear_death.cpp | 5 +- src/entity_tear_flags.cpp | 16 +- src/familiar_babies.cpp | 7 +- src/familiar_clot.cpp | 3 +- src/familiar_collision.cpp | 11 +- src/familiar_dip.cpp | 2 +- src/familiar_follow.cpp | 12 +- src/familiar_gello.cpp | 5 +- src/familiar_locust.cpp | 7 +- src/familiar_repentance.cpp | 13 +- src/familiar_shoot.cpp | 2 +- src/familiar_sprinkler.cpp | 4 +- src/familiar_variants.cpp | 11 +- src/familiar_walker.cpp | 2 +- src/familiar_wisp_kinds.cpp | 9 +- src/fx_layers.cpp | 10 +- src/fx_layers.h | 1 + src/game.cpp | 206 +- src/game.h | 13 +- src/game_end.cpp | 46 +- src/game_over.cpp | 17 +- src/game_restore.cpp | 42 +- src/game_save.cpp | 54 +- src/game_state.cpp | 8 +- src/game_state.h | 2 +- src/game_state_player.h | 2 +- src/game_update.cpp | 11 +- src/generic_prompt.cpp | 3 +- src/grid_entity.h | 5 +- src/grid_entity_door.cpp | 6 +- src/grid_entity_door.h | 2 + src/grid_entity_pit.cpp | 4 +- src/grid_entity_poop.cpp | 8 +- src/grid_entity_poop.h | 3 +- src/grid_entity_pressure_plate.cpp | 5 +- src/grid_entity_pressure_plate.h | 2 +- src/item_config.cpp | 21 +- src/item_pickup.cpp | 27 +- src/item_pool.cpp | 62 +- src/item_pool.h | 2 +- src/leaderboard.cpp | 109 +- src/level.cpp | 18 +- src/level.h | 8 +- src/lua_api.cpp | 21 +- src/lua_api.h | 2 +- src/lua_api_bit_set128.cpp | 4 +- src/lua_api_color.cpp | 3 +- src/lua_api_entities.cpp | 47 +- src/lua_api_entity.cpp | 19 +- src/lua_api_entity_player.cpp | 60 +- src/lua_api_game.cpp | 45 +- src/lua_api_grid_entity.cpp | 34 +- src/lua_api_item_config.cpp | 4 +- src/lua_api_rng.cpp | 4 +- src/lua_api_room.cpp | 69 +- src/lua_api_sprite.cpp | 8 +- src/lua_api_vector.cpp | 3 +- src/lua_callbacks.cpp | 14 +- src/lua_engine.cpp | 5 +- src/manager.cpp | 24 +- src/menu_character.cpp | 10 +- src/mines.cpp | 4 +- src/minimap.cpp | 3 +- src/mod_manager.cpp | 3 +- src/music_manager.h | 3 +- src/npc_ai.cpp | 4 +- src/npc_ai.h | 5 +- src/npc_ball_and_chain.cpp | 4 +- src/npc_boom_fly.cpp | 6 +- src/npc_clotty.cpp | 5 +- src/npc_cultist.cpp | 2 +- src/npc_dark_esau.cpp | 7 +- src/npc_fat_sack.cpp | 5 +- src/npc_fistuloid.cpp | 5 +- src/npc_fly.cpp | 26 +- src/npc_gaper.cpp | 1 - src/npc_grudge.cpp | 4 +- src/npc_gusher.cpp | 1 - src/npc_guts.cpp | 24 +- src/npc_heart.cpp | 2 +- src/npc_hive.cpp | 35 +- src/npc_hopper.cpp | 107 +- src/npc_maggot.cpp | 4 +- src/npc_mama_fly.cpp | 4 +- src/npc_mole.cpp | 11 +- src/npc_polty.cpp | 802 ++++ src/npc_poofer.cpp | 8 +- src/npc_poop.cpp | 29 +- src/npc_pustule.cpp | 2 +- src/npc_render_parts.cpp | 18 +- src/npc_rock_spider.cpp | 2 +- src/npc_rotten_gaper.cpp | 2 +- src/npc_round_worm.cpp | 4 +- src/npc_small_maggot.cpp | 2 +- src/npc_spider.cpp | 47 +- src/npc_stonehead.cpp | 37 +- src/npc_sub_horf.cpp | 2 +- src/npc_swarm.cpp | 2 +- src/npc_swarmer.cpp | 4 +- src/npc_swinger.cpp | 3 +- src/npc_ultra_greed.cpp | 15 +- src/npc_vis_fatty.cpp | 5 +- src/path_finder.cpp | 4 +- src/pause_screen.cpp | 9 +- src/persistent_game_data.cpp | 296 +- src/persistent_game_data.h | 10 + src/player_hud.cpp | 215 +- src/player_hud.h | 3 +- src/player_manager.cpp | 156 +- src/player_manager.h | 10 +- src/popups.cpp | 3 +- src/procedural_item_manager.cpp | 1043 ++++- src/procedural_item_manager.h | 119 + src/revive_player_menu.cpp | 5 +- src/room.cpp | 36 +- src/room.h | 1 + src/room_clear.cpp | 8 +- src/room_config.cpp | 180 +- src/room_lighting.cpp | 2 +- src/room_render.cpp | 72 +- src/room_special.cpp | 6 +- src/room_transition.cpp | 6 +- src/room_update.cpp | 10 +- src/score_sheet.cpp | 43 +- src/score_sheet.h | 23 +- src/seeds.h | 3 +- src/sfx_manager.h | 62 + src/stage_transition.cpp | 3 +- src/stat_hud.cpp | 3 +- src/tainted_characters.cpp | 38 +- src/weapon.cpp | 26 +- src/weapon_fetus.cpp | 6 +- src/weapon_lasers.cpp | 10 +- src/weapon_lua.cpp | 39 +- src/weapon_ludovico.cpp | 2 +- src/weapon_monstros_lung.cpp | 2 +- src/weapon_rockets.cpp | 2 +- 280 files changed, 14904 insertions(+), 5309 deletions(-) delete mode 100644 generated-src/afterbirth_persistent_game_data.cpp delete mode 100644 generated-src/deathmatch_type_base.cpp delete mode 100644 generated-src/glitched_collectible_gfx.cpp delete mode 100644 generated-src/glitched_item_set.cpp delete mode 100644 generated-src/procedural_effect.cpp delete mode 100644 generated-src/rebirth_save_data.cpp delete mode 100644 generated-src/spawn.cpp create mode 100644 src/boss_beast_horsemen.cpp create mode 100644 src/boss_scourge.cpp create mode 100644 src/entity_player_coop.cpp create mode 100644 src/entity_player_dashes.cpp create mode 100644 src/npc_polty.cpp diff --git a/generated-src/afterbirth_persistent_game_data.cpp b/generated-src/afterbirth_persistent_game_data.cpp deleted file mode 100644 index c39e79d..0000000 --- a/generated-src/afterbirth_persistent_game_data.cpp +++ /dev/null @@ -1,332 +0,0 @@ -#include "classes.h" - -// 0041d670 -uint8_t AfterbirthPersistentGameData::check_header(void *stream) -{ - char isEof; - uint32_t uVar1; - int *expectedHeader; - int *headerPtr; - void *data; - uint32_t uVar2; - bool bVar3; - uint32_t settingValue; - uint32_t cutsceneValue; - uint32_t counter3Value; - uint32_t counterValue; - uint32_t storedChecksum; - int sectionId; - int sectionCount; - char specialSeedByte; - char challengeByte; - char bossByte; - char minibossByte; - char collectibleByte; - char achievementByte; - uint32_t sectionSize; - void *saveData; - uint32_t entryCount; - int local_1c [4]; - uint32_t local_c; - uint8_t auStack_8 [4]; - - local_c = __security_cookie ^ GHIDRA_UINT((auStack_8 + 4)); - saveData = this; - (**(code **)(*GHIDRA_CAST(stream) + 0x14))(local_1c,1,0x10); - expectedHeader = &DAT_00b1b98c; - headerPtr = local_1c; - uVar2 = 0xc; - do { - if (*expectedHeader != *headerPtr) { - expectedHeader = &DAT_00b1b9a0; - headerPtr = local_1c; - uVar2 = 0xc; - goto LAB_0041d6d1; - } - expectedHeader = expectedHeader + 1; - headerPtr = headerPtr + 1; - bVar3 = 3 < uVar2; - uVar2 = uVar2 - 4; - } while (bVar3); - uVar2 = 6; - sectionCount = 9; - goto LAB_0041d717; -LAB_0041d6d1: - if (*expectedHeader == *headerPtr) goto code_r0x0041d6d7; - expectedHeader = &DAT_00b1b9b4; - headerPtr = local_1c; - uVar2 = 0xc; - do { - if (*expectedHeader != *headerPtr) { - KAGE_LogMessage(1,GHIDRA_CAST("AfterbirthPersistentGameData wrong file header (%.16s)\n")); - return 0; - } - expectedHeader = expectedHeader + 1; - headerPtr = headerPtr + 1; - bVar3 = 3 < uVar2; - uVar2 = uVar2 - 4; - } while (bVar3); - uVar2 = 8; - goto LAB_0041d710; -code_r0x0041d6d7: - expectedHeader = expectedHeader + 1; - headerPtr = headerPtr + 1; - bVar3 = uVar2 < 4; - uVar2 = uVar2 - 4; - if (bVar3) goto code_r0x0041d6e2; - goto LAB_0041d6d1; -code_r0x0041d6e2: - uVar2 = 7; -LAB_0041d710: - sectionCount = 10; -LAB_0041d717: - uVar1 = checksum_stream(stream,0x10,4); - (**(code **)(*GHIDRA_CAST(stream) + 0xc))(0xfffffffc,2); - storedChecksum = 0; - (**(code **)(*GHIDRA_CAST(stream) + 0x14))(&storedChecksum,4,1); - if ((7 < uVar2) && (storedChecksum != uVar1)) { - KAGE_LogMessage(1,GHIDRA_CAST("[warn] AfterbirthPersistentGameData checksum invalid!\n")); - return 0; - } - (**(code **)(*GHIDRA_CAST(stream) + 0xc))(0x10,0); - data = saveData; - (**(code **)(*GHIDRA_CAST(stream) + 0x14))(GHIDRA_INT(saveData) + 0x6dc,4,1); - sectionId = 0; - isEof = (**(code **)(*GHIDRA_CAST(stream) + 0x10))(); -joined_r0x0041d798: - if (((isEof != '\0') || (sectionId < 0)) || (sectionCount <= sectionId)) { - (**(code **)(*GHIDRA_CAST(stream) + 0x14))(GHIDRA_INT(data) + 0x6e0,4,1); - return 1; - } - (**(code **)(*GHIDRA_CAST(stream) + 0x14))(§ionId,4,1); - sectionSize = 0; - (**(code **)(*GHIDRA_CAST(stream) + 0x14))(§ionSize,4,1); - if (sectionSize == 0) goto switchD_0041d7f3_default; - switch(sectionId) { - case 1: - entryCount = 0; - (**(code **)(*GHIDRA_CAST(stream) + 0x14))(&entryCount,4,1); - bVar3 = entryCount == 0x115; - if (!bVar3) { - KAGE_LogMessage(1,GHIDRA_CAST("Different number of achievements %d/%d\n")); - bVar3 = entryCount == 0x115; - } - if (0x114 < entryCount && !bVar3) { - entryCount = 0x115; - } - uVar2 = 0; - if (entryCount != 0) { - do { - if (sectionSize <= uVar2) break; - (**(code **)(*GHIDRA_CAST(stream) + 0x14))(&achievementByte,1,1); - *GHIDRA_CAST((GHIDRA_CAST(data) + uVar2 + 0x38)) = '\0' < achievementByte; - uVar2 = uVar2 + 1; - } while (uVar2 < entryCount); - } - break; - case 2: - entryCount = 0; - (**(code **)(*GHIDRA_CAST(stream) + 0x14))(&entryCount,4,1); - bVar3 = entryCount == 0xa2; - if (!bVar3) { - KAGE_LogMessage(1,GHIDRA_CAST("Different number of counters %d/%d\n")); - bVar3 = entryCount == 0xa2; - } - if (0xa1 < entryCount && !bVar3) { - entryCount = 0xa2; - } - uVar2 = 0; - if (entryCount != 0) { - uVar1 = 0; - do { - if (sectionSize <= uVar1) goto LAB_0041dd41; - (**(code **)(*GHIDRA_CAST(stream) + 0x14))(&counterValue,4,1); - uVar2 = uVar2 + 1; - *GHIDRA_CAST((GHIDRA_CAST(saveData) + uVar1 + 0x150)) = counterValue; - uVar1 = uVar1 + 4; - } while (uVar2 < entryCount); - goto LAB_0041d8fe; - } -LAB_0041dd49: - data = saveData; - break; - case 3: - entryCount = 0; - (**(code **)(*GHIDRA_CAST(stream) + 0x14))(&entryCount,4,1); - bVar3 = entryCount == 0xc; - if (!bVar3) { - KAGE_LogMessage(1,GHIDRA_CAST("Different number of counters %d/%d\n")); - bVar3 = entryCount == 0xc; - } - if (0xb < entryCount && !bVar3) { - entryCount = 0xc; - } - uVar2 = 0; - if (entryCount == 0) goto LAB_0041dd49; - uVar1 = 0; - do { - if (sectionSize <= uVar1) goto LAB_0041dd41; - (**(code **)(*GHIDRA_CAST(stream) + 0x14))(&counter3Value,4,1); - uVar2 = uVar2 + 1; - *GHIDRA_CAST((GHIDRA_CAST(saveData) + uVar1 + 0x594)) = counter3Value; - uVar1 = uVar1 + 4; - } while (uVar2 < entryCount); - goto LAB_0041d8fe; - case 4: - entryCount = 0; - (**(code **)(*GHIDRA_CAST(stream) + 0x14))(&entryCount,4,1); - bVar3 = entryCount == 0x1ba; - if (!bVar3) { - KAGE_LogMessage(1,GHIDRA_CAST("Different number of collectibles in collection %d/%d\n")); - bVar3 = entryCount == 0x1ba; - } - if (0x1b9 < entryCount && !bVar3) { - entryCount = 0x1ba; - } - uVar2 = 0; - if (entryCount != 0) { - do { - if (sectionSize <= uVar2) break; - (**(code **)(*GHIDRA_CAST(stream) + 0x14))(&collectibleByte,1,1); - *GHIDRA_CAST((GHIDRA_CAST(data) + uVar2 + 0x3d8)) = '\0' < collectibleByte; - uVar2 = uVar2 + 1; - } while (uVar2 < entryCount); - } - break; - case 5: - entryCount = 0; - (**(code **)(*GHIDRA_CAST(stream) + 0x14))(&entryCount,4,1); - bVar3 = entryCount == 7; - if (!bVar3) { - KAGE_LogMessage(1,GHIDRA_CAST("Different number of minibosses %d/%d\n")); - bVar3 = entryCount == 7; - } - if (6 < entryCount && !bVar3) { - entryCount = 7; - } - uVar2 = 0; - if (entryCount != 0) { - do { - if (sectionSize <= uVar2) break; - (**(code **)(*GHIDRA_CAST(stream) + 0x14))(&minibossByte,1,1); - *GHIDRA_CAST((GHIDRA_CAST(data) + uVar2 + 0x5c4)) = '\0' < minibossByte; - uVar2 = uVar2 + 1; - } while (uVar2 < entryCount); - } - break; - case 6: - entryCount = 0; - (**(code **)(*GHIDRA_CAST(stream) + 0x14))(&entryCount,4,1); - bVar3 = entryCount == 0x43; - if (!bVar3) { - KAGE_LogMessage(1,GHIDRA_CAST("Different number of minibosses %d/%d\n")); - bVar3 = entryCount == 0x43; - } - if (0x42 < entryCount && !bVar3) { - entryCount = 0x43; - } - uVar2 = 0; - if (entryCount != 0) { - do { - if (sectionSize <= uVar2) break; - (**(code **)(*GHIDRA_CAST(stream) + 0x14))(&bossByte,1,1); - *GHIDRA_CAST((GHIDRA_CAST(data) + uVar2 + 0x5cb)) = '\0' < bossByte; - uVar2 = uVar2 + 1; - } while (uVar2 < entryCount); - } - break; - case 7: - entryCount = 0; - (**(code **)(*GHIDRA_CAST(stream) + 0x14))(&entryCount,4,1); - bVar3 = entryCount == 0x1f; - if (!bVar3) { - KAGE_LogMessage(1,GHIDRA_CAST("Different number of challenges %d/%d\n")); - bVar3 = entryCount == 0x1f; - } - if (0x1e < entryCount && !bVar3) { - entryCount = 0x1f; - } - uVar2 = 0; - if (entryCount != 0) { - do { - if (sectionSize <= uVar2) break; - (**(code **)(*GHIDRA_CAST(stream) + 0x14))(&challengeByte,1,1); - *GHIDRA_CAST((GHIDRA_CAST(data) + uVar2 + 0x60e)) = '\0' < challengeByte; - uVar2 = uVar2 + 1; - } while (uVar2 < entryCount); - } - break; - case 8: - entryCount = 0; - (**(code **)(*GHIDRA_CAST(stream) + 0x14))(&entryCount,4,1); - bVar3 = entryCount == 0x16; - if (!bVar3) { - KAGE_LogMessage(1,GHIDRA_CAST("Different number of cutscenes %d/%d\n")); - bVar3 = entryCount == 0x16; - } - if (0x15 < entryCount && !bVar3) { - entryCount = 0x16; - } - uVar2 = 0; - if (entryCount == 0) goto LAB_0041dd49; - uVar1 = 0; - do { - if (sectionSize <= uVar1) goto LAB_0041dd41; - (**(code **)(*GHIDRA_CAST(stream) + 0x14))(&cutsceneValue,4,1); - uVar2 = uVar2 + 1; - *GHIDRA_CAST((GHIDRA_CAST(saveData) + uVar1 + 0x630)) = cutsceneValue; - uVar1 = uVar1 + 4; - } while (uVar2 < entryCount); - goto LAB_0041d8fe; - case 9: - entryCount = 0; - (**(code **)(*GHIDRA_CAST(stream) + 0x14))(&entryCount,4,1); - bVar3 = entryCount == 1; - if (!bVar3) { - KAGE_LogMessage(1,GHIDRA_CAST("Different number of settings %d/%d\n")); - bVar3 = entryCount == 1; - } - if (entryCount != 0 && !bVar3) { - entryCount = 1; - } - uVar2 = 0; - if (entryCount == 0) goto LAB_0041dd49; - uVar1 = 0; - do { - if (sectionSize <= uVar1) goto LAB_0041dd41; - (**(code **)(*GHIDRA_CAST(stream) + 0x14))(&settingValue,4,1); - uVar2 = uVar2 + 1; - *GHIDRA_CAST((GHIDRA_CAST(saveData) + uVar1 + 0x688)) = settingValue; - uVar1 = uVar1 + 4; - } while (uVar2 < entryCount); -LAB_0041d8fe: - data = saveData; - break; - case 10: - entryCount = 0; - (**(code **)(*GHIDRA_CAST(stream) + 0x14))(&entryCount,4,1); - bVar3 = entryCount == 0x4d; - if (!bVar3) { - KAGE_LogMessage(1,GHIDRA_CAST("Different number of special seeds %d/%d\n")); - bVar3 = entryCount == 0x4d; - } - if (0x4c < entryCount && !bVar3) { - entryCount = 0x4d; - } - uVar2 = 0; - if (entryCount != 0) { - do { - if (sectionSize <= uVar2) break; - (**(code **)(*GHIDRA_CAST(stream) + 0x14))(&specialSeedByte,1,1); - *GHIDRA_CAST((GHIDRA_CAST(data) + uVar2 + 0x68c)) = '\0' < specialSeedByte; - uVar2 = uVar2 + 1; - } while (uVar2 < entryCount); - } - } - goto switchD_0041d7f3_default; -LAB_0041dd41: - data = saveData; -switchD_0041d7f3_default: - isEof = (**(code **)(*GHIDRA_CAST(stream) + 0x10))(); - goto joined_r0x0041d798; -} diff --git a/generated-src/classes.h b/generated-src/classes.h index 32eebe4..c63695c 100644 --- a/generated-src/classes.h +++ b/generated-src/classes.h @@ -124,6 +124,7 @@ struct ActionGlyph; struct ActiveGain; struct ActiveItemDesc; struct ActiveUse; +struct AfterImageFrame; struct AfterbirthPersistentGameData; struct Ambush; struct AnimationData; @@ -347,6 +348,7 @@ struct HUD; struct HUD_Message; struct HWND__; struct HallucinationOverlay; +struct HeartGain; struct History; struct HistoryHUD; struct HistoryHUDItem; @@ -417,6 +419,7 @@ struct LevelGenerator; struct LevelGenerator_Room; struct LightSpawn; struct LineCheck; +struct LineQuery; struct Lobby; struct LobbyList; struct LobbyLocalhost; @@ -551,6 +554,7 @@ struct PreloadManager; struct ProceduralEffect; struct ProceduralItem; struct ProceduralItemManager; +struct ProceduralTrigger; struct ProjectileParams; struct ProjectileShooter; struct Quad; @@ -668,6 +672,7 @@ struct VariantRange; struct Vector; struct VectorRing; struct VentricleRazorPortal; +struct VersusPacing; struct VideoPlayer; struct VoidedPassive; struct WalkAnims; @@ -1135,138 +1140,6 @@ struct DateTime { }; -struct DeathmatchTypeBase { - virtual ~DeathmatchTypeBase(); // 0042a430 slot 0 ::FUN_0042a430 - virtual void vfunc_1(); // 00af05d3 slot 1 - virtual uint8_t Init(); // 0042a4d0 slot 2 - virtual void guard_check_icall(); // 0040c200 slot 3 ::guard_check_icall - virtual void Update(); // 0042a8b0 slot 4 - virtual void vfunc_5(); // 0040c200 slot 5 ::guard_check_icall - virtual void FUN_0042aca0(); // 0042aca0 slot 6 ::FUN_0042aca0 - virtual bool FUN_0042ae90(); // 0042ae90 slot 7 ::FUN_0042ae90 - virtual uint64_t FUN_0042af00(); // 0042af00 slot 8 ::FUN_0042af00 - virtual uint32_t FUN_0042b480(uint32_t param_1); // 0042b480 slot 9 ::FUN_0042b480 - virtual uint32_t FUN_0042b430(uint32_t param_1); // 0042b430 slot 10 ::FUN_0042b430 - virtual uint32_t FUN_0042b340(uint32_t param_1); // 0042b340 slot 11 ::FUN_0042b340 - virtual uint32_t FUN_0042b020(int param_1); // 0042b020 slot 12 ::FUN_0042b020 - virtual uint32_t FUN_0042b520(); // 0042b520 slot 13 ::FUN_0042b520 - virtual Entity * FUN_0042b7c0(Vector *param_1, float param_2); // 0042b7c0 slot 14 ::FUN_0042b7c0 - virtual void FUN_0042b770(); // 0042b770 slot 15 ::FUN_0042b770 - virtual void FUN_0042b940(int param_1); // 0042b940 slot 16 ::FUN_0042b940 - virtual void FUN_0042b9a0(int *param_1); // 0042b9a0 slot 17 ::FUN_0042b9a0 - virtual uint8_t FUN_0042bc00(); // 0042bc00 slot 18 ::FUN_0042bc00 - virtual long double FUN_0042bc10(); // 0042bc10 slot 19 ::FUN_0042bc10 - virtual void vfunc_20(); // 0042bc00 slot 20 ::FUN_0042bc00 - virtual bool is_player_jelly_belly(uint32_t param_1, Entity_Player *param_2); // 0042bc20 slot 21 ::is_player_jelly_belly - virtual void FUN_0042bc40(Entity *param_1); // 0042bc40 slot 22 ::FUN_0042bc40 - virtual void FUN_0042bc90(); // 0042bc90 slot 23 ::FUN_0042bc90 - virtual void FUN_0042bca0(Entity_Player *param_1); // 0042bca0 slot 24 ::FUN_0042bca0 - virtual void vfunc_25(); // 0042bc90 slot 25 ::FUN_0042bc90 - virtual void vfunc_26(); // 0042bc90 slot 26 ::FUN_0042bc90 - virtual void vfunc_27(); // 0042bc90 slot 27 ::FUN_0042bc90 - virtual void StoreGameState(void *gameState); // 0042bd70 slot 28 - virtual void RestoreGameState(int param_1); // 0042bdf0 slot 29 - virtual void FUN_0042c070(Entity_Player *param_1, uint64_t *param_2); // 0042c070 slot 30 ::FUN_0042c070 - virtual uint32_t FUN_0042c160(); // 0042c160 slot 31 ::FUN_0042c160 - virtual Entity * spawn_random_pickup(); // 0042c170 slot 32 - virtual int * FUN_0042c540(char param_1); // 0042c540 slot 33 ::FUN_0042c540 - virtual void FUN_0042c6a0(uint32_t param_1, uint32_t param_2); // 0042c6a0 slot 34 ::FUN_0042c6a0 - - uint8_t _pad_0x4[0x28]; -}; -LAYOUT32(sizeof(DeathmatchTypeBase) == 0x2c); - -struct DeathmatchTypeBomberman : DeathmatchTypeBase { - void vfunc_1() override; // 0042ca10 slot 1 ::FUN_0042ca10 - uint32_t FUN_0042b520() override; // 0042ca20 slot 13 ::FUN_0042ca20 - uint8_t FUN_0042bc00() override; // 0042ca30 slot 18 ::FUN_0042ca30 - void FUN_0042c070(Entity_Player *param_1, uint64_t *param_2) override; // 0042ca40 slot 30 ::FUN_0042ca40 -}; -LAYOUT32(sizeof(DeathmatchTypeBomberman) == 0x2c); - -struct DeathmatchTypeIndigestion : DeathmatchTypeBase { - void vfunc_1() override; // 0042cb70 slot 1 ::FUN_0042cb70 - void vfunc_20() override; // 0042cb80 slot 20 ::FUN_0042cb80 - void FUN_0042c070(Entity_Player *param_1, uint64_t *param_2) override; // 0042cb90 slot 30 ::FUN_0042cb90 -}; -LAYOUT32(sizeof(DeathmatchTypeIndigestion) == 0x2c); - -struct DeathmatchTypeIpecac : DeathmatchTypeBase { - void vfunc_1() override; // 0042cc80 slot 1 ::FUN_0042cc80 - void FUN_0042bc40(Entity *param_1) override; // 0042cc90 slot 22 ::FUN_0042cc90 - void FUN_0042bca0(Entity_Player *param_1) override; // 0042cdf0 slot 24 GridEntity_Statue::Render - void vfunc_25() override; // 0042ce00 slot 25 ::FUN_0042ce00 - void vfunc_26() override; // 0042ce00 slot 26 ::FUN_0042ce00 - void vfunc_27() override; // 0042ce30 slot 27 ::FUN_0042ce30 - void FUN_0042c070(Entity_Player *param_1, uint64_t *param_2) override; // 0042ce60 slot 30 ::FUN_0042ce60 -}; -LAYOUT32(sizeof(DeathmatchTypeIpecac) == 0x2c); - -struct DeathmatchTypeKnifeFight : DeathmatchTypeBase { - void vfunc_1() override; // 0042cea0 slot 1 ::FUN_0042cea0 - void FUN_0042c070(Entity_Player *param_1, uint64_t *param_2) override; // 0042ceb0 slot 30 ::FUN_0042ceb0 -}; -LAYOUT32(sizeof(DeathmatchTypeKnifeFight) == 0x2c); - -struct DeathmatchTypeKnockout : DeathmatchTypeBase { - void vfunc_1() override; // 0042cef0 slot 1 ::FUN_0042cef0 - long double FUN_0042bc10() override; // 0042cf00 slot 19 ::FUN_0042cf00 - void FUN_0042c070(Entity_Player *param_1, uint64_t *param_2) override; // 0042cf10 slot 30 ::FUN_0042cf10 -}; -LAYOUT32(sizeof(DeathmatchTypeKnockout) == 0x2c); - -struct DeathmatchTypeLudovico : DeathmatchTypeBase { - virtual ~DeathmatchTypeLudovico(); // 0042d0f0 slot 0 ::FUN_0042d0f0 - void vfunc_1() override; // 0042d1b0 slot 1 ::FUN_0042d1b0 - void vfunc_20() override; // 0042cb80 slot 20 ::FUN_0042cb80 - void FUN_0042bc90() override; // 0042d1c0 slot 23 - void FUN_0042c070(Entity_Player *param_1, uint64_t *param_2) override; // 0042d5f0 slot 30 ::FUN_0042d5f0 - - uint8_t _pad_0x2c[0x8]; -}; -LAYOUT32(sizeof(DeathmatchTypeLudovico) == 0x34); - -struct DeathmatchTypeMachineGun : DeathmatchTypeBase { - void vfunc_1() override; // 0042d660 slot 1 ::FUN_0042d660 - long double FUN_0042bc10() override; // 0042d670 slot 19 ::FUN_0042d670 - void FUN_0042c070(Entity_Player *param_1, uint64_t *param_2) override; // 0042d680 slot 30 ::FUN_0042d680 -}; -LAYOUT32(sizeof(DeathmatchTypeMachineGun) == 0x2c); - -struct DeathmatchTypeNormal : DeathmatchTypeBase { - virtual ~DeathmatchTypeNormal(); // 0042d780 slot 0 ::FUN_0042d780 - void vfunc_1() override; // 0042d7e0 slot 1 ::FUN_0042d7e0 - uint8_t Init() override; // 0042d7f0 slot 2 ::FUN_0042d7f0 - void Update() override; // 0042d850 slot 4 ::FUN_0042d850 - - int _spawnTimer; - int _spawnPhase; -}; -LAYOUT32(offsetof(DeathmatchTypeNormal, _spawnTimer) == 0x2c); -LAYOUT32(offsetof(DeathmatchTypeNormal, _spawnPhase) == 0x30); -LAYOUT32(sizeof(DeathmatchTypeNormal) == 0x34); - -struct DeathmatchTypeSumo : DeathmatchTypeBase { - void vfunc_1() override; // 0042d8a0 slot 1 ::FUN_0042d8a0 - uint8_t FUN_0042bc00() override; // 0042ca30 slot 18 ::FUN_0042ca30 - void FUN_0042c070(Entity_Player *param_1, uint64_t *param_2) override; // 0042d8b0 slot 30 ::FUN_0042d8b0 -}; -LAYOUT32(sizeof(DeathmatchTypeSumo) == 0x2c); - -struct DeathmatchTypeSwordFight : DeathmatchTypeBase { - void vfunc_1() override; // 0042d950 slot 1 ::FUN_0042d950 - void FUN_0042c070(Entity_Player *param_1, uint64_t *param_2) override; // 0042d960 slot 30 ::FUN_0042d960 -}; -LAYOUT32(sizeof(DeathmatchTypeSwordFight) == 0x2c); - -struct DeathmatchTypeVenom : DeathmatchTypeBase { - void vfunc_1() override; // 0042d9d0 slot 1 ::FUN_0042d9d0 - void vfunc_20() override; // 0042cb80 slot 20 ::FUN_0042cb80 - void FUN_0042bc40(Entity *param_1) override; // 0042d9e0 slot 22 ::FUN_0042d9e0 - void FUN_0042c070(Entity_Player *param_1, uint64_t *param_2) override; // 0042db40 slot 30 ::FUN_0042db40 -}; -LAYOUT32(sizeof(DeathmatchTypeVenom) == 0x2c); - struct DebugRenderer { void Render(); // 0042dbb0 void * Get(int Index, uint8_t Unk); // 0042eb10 @@ -3617,18 +3490,6 @@ struct PopupWindow { }; -struct ProceduralEffect { - static uint8_t roll_trigger_target(uint32_t *outTarget, float *outChance, RNG *rng); // 009e0700 - static uint8_t roll_spawn_target(uint32_t *outTarget, float *outChance, RNG *rng); // 009e0ad0 - void roll_params(int conditionType, int actionType, uint32_t seed); // 009e0f60 -}; - - -struct ProceduralItem { - ItemConfig_Item* item; -}; -LAYOUT32(offsetof(ProceduralItem, item) == 0x0); - struct Quad { void rotate(Vector *pivot, float angle); // 00a10760 void scale(Vector *pivot, Vector *scale); // 00a10950 @@ -5506,7 +5367,6 @@ void FUN_0041d4b0(); // 0041d4b0 uint8_t * FUN_0041d4c0(); // 0041d4c0 int FUN_0041d4d0(); // 0041d4d0 void FUN_0041d560(); // 0041d560 -int afterbirth_save_index_remap(int oldIndex); // 0041ddb0 int sprintf_s(uint8_t *buffer, uint32_t size, uint8_t *format); // 0041e420 void FUN_0041e440(uint32_t *param_1); // 0041e440 int FUN_0041e470(); // 0041e470 @@ -5556,7 +5416,6 @@ StageTransition * FUN_00428b50(); // 00428b50 void FUN_00428b60(void *param_1, uint32_t param_2); // 00428b60 void FUN_00428ce0(); // 00428ce0 uint32_t FUN_00428d30(uint32_t param_1); // 00428d30 -void FUN_00429810(uint32_t param_1); // 00429810 void FUN_00429f20(); // 00429f20 int FUN_00429f30(uint32_t param_1); // 00429f30 void FUN_00429f50(); // 00429f50 @@ -5567,29 +5426,7 @@ void FUN_0042a210(); // 0042a210 void FUN_0042a230(); // 0042a230 void FUN_0042a350(); // 0042a350 void FUN_0042a490(); // 0042a490 -void FUN_0042aca0(); // 0042aca0 -bool FUN_0042ae90(); // 0042ae90 -uint64_t FUN_0042af00(); // 0042af00 -uint32_t FUN_0042b020(int param_1); // 0042b020 -uint32_t FUN_0042b340(uint32_t param_1); // 0042b340 -uint32_t FUN_0042b430(uint32_t param_1); // 0042b430 -uint32_t FUN_0042b480(uint32_t param_1); // 0042b480 -uint32_t FUN_0042b520(); // 0042b520 int FUN_0042b550(); // 0042b550 -void FUN_0042b770(); // 0042b770 -Entity * FUN_0042b7c0(Vector *param_1, float param_2); // 0042b7c0 -void FUN_0042b940(int param_1); // 0042b940 -void FUN_0042b9a0(int *param_1); // 0042b9a0 -uint8_t FUN_0042bc00(); // 0042bc00 -long double FUN_0042bc10(); // 0042bc10 -bool is_player_jelly_belly(uint32_t param_1, Entity_Player *param_2); // 0042bc20 -void FUN_0042bc40(Entity *param_1); // 0042bc40 -void FUN_0042bc90(); // 0042bc90 -void FUN_0042bca0(Entity_Player *param_1); // 0042bca0 -void FUN_0042c070(Entity_Player *param_1, uint64_t *param_2); // 0042c070 -uint32_t FUN_0042c160(); // 0042c160 -int * FUN_0042c540(char param_1); // 0042c540 -void FUN_0042c6a0(uint32_t param_1, uint32_t param_2); // 0042c6a0 void FUN_0042c6e0(uint32_t *param_1); // 0042c6e0 int FUN_0042c700(); // 0042c700 bool FUN_0042c710(int *param_1); // 0042c710 @@ -5600,39 +5437,7 @@ void FUN_0042c7c0(); // 0042c7c0 int FUN_0042c7f0(); // 0042c7f0 int FUN_0042c810(int param_1); // 0042c810 void FUN_0042c820(uint32_t param_1); // 0042c820 -uint32_t FUN_0042ca10(); // 0042ca10 -uint32_t FUN_0042ca20(); // 0042ca20 -uint8_t FUN_0042ca30(int param_1); // 0042ca30 -void FUN_0042ca40(Entity_Player *param_1, uint32_t param_2); // 0042ca40 -uint32_t FUN_0042cb70(); // 0042cb70 -uint8_t FUN_0042cb80(); // 0042cb80 -void FUN_0042cb90(Entity_Player *param_1, uint32_t param_2); // 0042cb90 -uint32_t FUN_0042cc80(); // 0042cc80 -void FUN_0042cc90(Entity *param_1); // 0042cc90 -void FUN_0042ce00(int param_1, float *param_2); // 0042ce00 -void FUN_0042ce30(int param_1, float *param_2); // 0042ce30 -void FUN_0042ce60(Entity_Player *param_1, uint32_t param_2); // 0042ce60 -uint32_t FUN_0042cea0(); // 0042cea0 -void FUN_0042ceb0(Entity_Player *param_1, uint32_t param_2); // 0042ceb0 -uint32_t FUN_0042cef0(); // 0042cef0 -long double FUN_0042cf00(); // 0042cf00 -void FUN_0042cf10(Entity_Player *param_1, uint32_t param_2); // 0042cf10 int FUN_0042d040(); // 0042d040 -uint32_t FUN_0042d1b0(); // 0042d1b0 -void FUN_0042d5f0(Entity_Player *param_1, uint32_t param_2); // 0042d5f0 -uint32_t FUN_0042d660(); // 0042d660 -long double FUN_0042d670(); // 0042d670 -void FUN_0042d680(Entity_Player *param_1, uint32_t param_2); // 0042d680 -uint32_t FUN_0042d7e0(); // 0042d7e0 -uint8_t FUN_0042d7f0(); // 0042d7f0 -void FUN_0042d850(); // 0042d850 -uint32_t FUN_0042d8a0(); // 0042d8a0 -void FUN_0042d8b0(Entity_Player *param_1, uint32_t param_2); // 0042d8b0 -uint32_t FUN_0042d950(); // 0042d950 -void FUN_0042d960(Entity_Player *param_1, uint32_t param_2); // 0042d960 -uint32_t FUN_0042d9d0(); // 0042d9d0 -void FUN_0042d9e0(Entity *param_1); // 0042d9e0 -void FUN_0042db40(Entity_Player *param_1, uint32_t param_2); // 0042db40 void FUN_0042edb0(); // 0042edb0 void FUN_0042ede0(uint32_t *param_1); // 0042ede0 void push_shape_points(void *self, Capsule *capsule); // 0042eef0 @@ -5673,7 +5478,6 @@ void FUN_00435910(); // 00435910 void FUN_00435bc0(uint32_t param_1, uint32_t param_2); // 00435bc0 void FUN_00435cd0(uint32_t param_1); // 00435cd0 void set_field_358(void *self, float value); // 00435cf0 -void FUN_00435d40(uint32_t param_1); // 00435d40 void FUN_00435d90(uint32_t param_1); // 00435d90 int FUN_00435de0(); // 00435de0 int FUN_00435df0(); // 00435df0 @@ -5688,7 +5492,6 @@ int _get_index_plus_one_if_kind_4_5(); // 004360f0 int FUN_00436120(int param_1); // 00436120 void FUN_00436190(); // 00436190 void FUN_00436200(uint32_t param_1); // 00436200 -void FUN_00436210(uint32_t param_1); // 00436210 void FUN_00436fb0(); // 00436fb0 void FUN_0043e990(RNG *param_1); // 0043e990 void FUN_0043ed20(uint32_t *param_1, int *param_2); // 0043ed20 @@ -5700,7 +5503,6 @@ void set_PlaybackSpeed(ANM2 *sprite, float speed); // 00440e50 bool FUN_00440e70(); // 00440e70 void FUN_00440e80(Vector *param_1); // 00440e80 void FUN_00440e90(uint32_t param_1); // 00440e90 -void FUN_00440ea0(uint8_t param_1); // 00440ea0 int FUN_00440ec0(); // 00440ec0 void FUN_00440ed0(uint32_t param_1); // 00440ed0 void FUN_00444c70(uint32_t param_1); // 00444c70 @@ -5720,7 +5522,6 @@ void FUN_004561f0(uint8_t *param_1); // 004561f0 void FUN_00456230(); // 00456230 char * FUN_004562f0(char *param_1); // 004562f0 void FUN_004563c0(uint32_t *param_1); // 004563c0 -void FUN_004563e0(uint32_t *param_1); // 004563e0 void FUN_00456400(); // 00456400 int FUN_00456540(); // 00456540 uint32_t FUN_004565b0(); // 004565b0 @@ -5747,14 +5548,11 @@ void FUN_004aad00(); // 004aad00 void FUN_004aad10(); // 004aad10 void FUN_004aad20(); // 004aad20 int FUN_004aad40(); // 004aad40 -void FUN_004aad50(uint32_t param_1); // 004aad50 void FUN_004aad70(uint32_t param_1); // 004aad70 void FUN_004aad90(uint32_t param_1, uint32_t param_2); // 004aad90 void FUN_004aadb0(uint32_t param_1); // 004aadb0 void FUN_004aadd0(uint32_t param_1); // 004aadd0 void FUN_004aadf0(uint32_t param_1, uint32_t param_2, uint32_t param_3); // 004aadf0 -void FUN_004aae30(char param_1); // 004aae30 -void FUN_004aae50(char param_1); // 004aae50 int FUN_004aae70(); // 004aae70 void FUN_004b3950(); // 004b3950 void FUN_004b6b20(int *param_1, int param_2, int param_3); // 004b6b20 @@ -5810,7 +5608,6 @@ int FUN_0054d1b0(int param_1); // 0054d1b0 void FUN_00557b50(uint32_t param_1); // 00557b50 void FUN_00557b70(uint8_t *param_1); // 00557b70 bool FUN_00557bb0(int *param_1); // 00557bb0 -void FUN_00565dd0(uint32_t param_1); // 00565dd0 void FUN_00565de0(uint32_t param_1); // 00565de0 void FUN_00568980(char param_1); // 00568980 void FUN_0056ff00(uint32_t *param_1, uint32_t param_2, uint32_t param_3); // 0056ff00 @@ -5820,18 +5617,6 @@ void FUN_00571230(void *param_1, int param_2); // 00571230 uint32_t * FUN_00575fe0(int *param_1, uint32_t param_2, uint32_t param_3, uint32_t param_4, uint32_t param_5, uint32_t param_6, int *param_7, uint32_t param_8, uint32_t param_9); // 00575fe0 void FUN_00579700(); // 00579700 uint32_t FUN_00579760(); // 00579760 -void FUN_0057be30(uint32_t param_1); // 0057be30 -void FUN_0057be60(uint32_t param_1, uint32_t param_2); // 0057be60 -int FUN_00582a60(); // 00582a60 -int FUN_00582a80(); // 00582a80 -void FUN_00582aa0(); // 00582aa0 -uint32_t FUN_00582ad0(); // 00582ad0 -void FUN_00582b00(uint32_t *param_1); // 00582b00 -int FUN_00582b40(); // 00582b40 -void FUN_005830e0(); // 005830e0 -void FUN_00583110(char param_1); // 00583110 -void FUN_00583170(); // 00583170 -void FUN_00586b50(float *param_1, float param_2); // 00586b50 uint32_t FUN_0058ab60(); // 0058ab60 uint8_t FUN_0058e210(); // 0058e210 void FUN_0058e240(uint32_t param_1); // 0058e240 @@ -5845,25 +5630,19 @@ void FUN_005b1560(); // 005b1560 void FUN_005b15a0(uint32_t param_1); // 005b15a0 void FUN_005b15d0(uint32_t param_1); // 005b15d0 void FUN_005b15f0(float *param_1); // 005b15f0 -void FUN_005b1690(char param_1); // 005b1690 void FUN_005b16f0(uint8_t param_1); // 005b16f0 uint32_t FUN_005b1720(int param_1); // 005b1720 -void FUN_005b17a0(uint8_t param_1); // 005b17a0 -void FUN_005b17b0(uint32_t param_1); // 005b17b0 int FUN_005b1820(); // 005b1820 void FUN_005b1830(uint32_t param_1); // 005b1830 bool FUN_005b1840(); // 005b1840 int FUN_005b18a0(); // 005b18a0 void FUN_005b18b0(int param_1); // 005b18b0 -void FUN_005b18d0(uint32_t param_1); // 005b18d0 uint8_t FUN_005b18e0(); // 005b18e0 void FUN_005b18f0(uint8_t param_1); // 005b18f0 void FUN_005b1900(); // 005b1900 void FUN_005b1910(uint32_t param_1); // 005b1910 void FUN_005b1920(uint32_t param_1); // 005b1920 -void FUN_005b1950(uint8_t param_1); // 005b1950 uint32_t FUN_005b1960(); // 005b1960 -void FUN_005b1970(uint32_t param_1); // 005b1970 void FUN_005b1990(uint32_t param_1); // 005b1990 uint32_t FUN_005b19a0(); // 005b19a0 void FUN_005b19d0(); // 005b19d0 @@ -5920,9 +5699,6 @@ void FUN_005cd370(uint32_t param_1); // 005cd370 void FUN_005cd380(uint32_t param_1); // 005cd380 void FUN_005cd3a0(uint32_t param_1); // 005cd3a0 void FUN_005cd3c0(); // 005cd3c0 -void FUN_005cd3d0(uint32_t param_1); // 005cd3d0 -void FUN_005cd3f0(uint32_t param_1); // 005cd3f0 -void FUN_005cd410(uint32_t param_1); // 005cd410 void FUN_005cd430(uint32_t *param_1); // 005cd430 int FUN_005cd470(); // 005cd470 int FUN_005cd490(int param_1); // 005cd490 @@ -5939,7 +5715,6 @@ void FUN_005cd750(); // 005cd750 void FUN_005cd760(); // 005cd760 void FUN_005cd770(); // 005cd770 void FUN_005cd780(uint32_t *param_1); // 005cd780 -void FUN_005cd7a0(uint32_t *param_1); // 005cd7a0 Vector * FUN_005cd7e0(Vector *param_1); // 005cd7e0 void FUN_005cd800(); // 005cd800 AchievementOverlay * FUN_005cd810(); // 005cd810 @@ -5999,8 +5774,6 @@ void FUN_0060d040(); // 0060d040 void FUN_0060d060(); // 0060d060 void FUN_0060d070(); // 0060d070 void FUN_0060d0c0(); // 0060d0c0 -void FUN_0060d0d0(uint32_t param_1); // 0060d0d0 -void FUN_0060d0f0(uint32_t param_1); // 0060d0f0 uint32_t FUN_0060d110(); // 0060d110 bool FUN_0060d1c0(uint32_t param_1); // 0060d1c0 uint32_t FUN_0060d1e0(); // 0060d1e0 @@ -6042,12 +5815,7 @@ void FUN_00652a70(); // 00652a70 bool _has_flag_0x110(uint32_t param_1); // 00652a90 int FUN_00652ae0(); // 00652ae0 bool FUN_0065cfe0(uint32_t param_1); // 0065cfe0 -int FUN_0065d010(); // 0065d010 -void FUN_0065d020(); // 0065d020 -void FUN_0065d040(); // 0065d040 -uint32_t * FUN_0065d060(); // 0065d060 void FUN_0065d070(); // 0065d070 -std_vector * FUN_0065d090(); // 0065d090 void FUN_0065d0a0(); // 0065d0a0 void FUN_0065d0c0(); // 0065d0c0 void FUN_0065d160(); // 0065d160 @@ -6221,7 +5989,6 @@ void FUN_006a6910(uint32_t param_1, uint32_t param_2, uint32_t param_3, uint32_t void FUN_006a6930(); // 006a6930 void FUN_006a7ec0(); // 006a7ec0 void FUN_006a80d0(); // 006a80d0 -void FUN_006a8180(uint32_t param_1); // 006a8180 void FUN_006a8210(int param_1); // 006a8210 void FUN_006b5de0(); // 006b5de0 void FUN_006b5f40(); // 006b5f40 @@ -6252,7 +6019,6 @@ void FUN_006dac00(uint32_t *param_1, uint32_t param_2); // 006dac00 float log_precise(float value); // 006dac30 void FUN_006daca0(uint32_t param_1); // 006daca0 uint32_t FUN_006e1910(uint32_t param_1); // 006e1910 -void FUN_006e2ff0(int param_1); // 006e2ff0 void FUN_006ee330(); // 006ee330 int FUN_006ee640(int param_1, int param_2, uint32_t *param_3, uint32_t param_4); // 006ee640 uint32_t FUN_006eeeb0(); // 006eeeb0 @@ -6286,13 +6052,9 @@ void FUN_006f2fb0(); // 006f2fb0 void FUN_006f3000(); // 006f3000 void FUN_006f4170(); // 006f4170 void FUN_006f5850(int *param_1, int *param_2, int param_3, uint32_t param_4, int param_5); // 006f5850 -void daily_challenge_params_assign(void *self, void *other); // 006f6260 uint8_t FUN_006f9730(); // 006f9730 -void FUN_006f9f20(int param_1); // 006f9f20 void FUN_007008b0(int *param_1); // 007008b0 void FUN_00703140(); // 00703140 -void FUN_00704b50(); // 00704b50 -void FUN_007068f0(int param_1); // 007068f0 uint32_t FUN_00708350(); // 00708350 void FUN_00708380(); // 00708380 void FUN_00708430(uint32_t param_1, uint32_t param_2, int param_3); // 00708430 @@ -6329,10 +6091,7 @@ uint32_t FUN_00710370(); // 00710370 uint32_t FUN_007103a0(); // 007103a0 Entity_Player * FUN_007103c0(uint32_t *param_1); // 007103c0 uint32_t FUN_00710f70(int param_1); // 00710f70 -void FUN_00711530(int param_1); // 00711530 uint32_t FUN_00711740(); // 00711740 -void FUN_00718ed0(uint32_t param_1); // 00718ed0 -void FUN_0071df70(uint8_t param_1); // 0071df70 void FUN_00721e60(int param_1, int param_2, int param_3, int param_4, int param_5, int param_6); // 00721e60 void FUN_00722020(int param_1); // 00722020 void FUN_007221a0(uint32_t *param_1); // 007221a0 @@ -6375,13 +6134,9 @@ void FUN_00737e50(); // 00737e50 void FUN_00737e80(uint32_t param_1, uint32_t param_2); // 00737e80 int * FUN_00738040(uint32_t *param_1, int param_2, uint32_t param_3); // 00738040 void Catch_All_0073811e(); // 0073811e -void FUN_00738150(uint32_t param_1); // 00738150 -void FUN_00738160(uint32_t param_1); // 00738160 -void FUN_00738190(char param_1); // 00738190 void FUN_00738260(); // 00738260 uint32_t FUN_00738330(); // 00738330 Minimap * FUN_00738380(); // 00738380 -void FUN_00738390(uint32_t param_1); // 00738390 void FUN_007383b0(); // 007383b0 int FUN_00738620(uint32_t param_1, uint32_t param_2); // 00738620 void FUN_00741cc0(); // 00741cc0 @@ -6440,14 +6195,7 @@ void FUN_00753750(uint32_t *param_1); // 00753750 void FUN_00753770(uint8_t param_1); // 00753770 void FUN_00753790(); // 00753790 void FUN_007537b0(); // 007537b0 -void FUN_00753800(uint32_t param_1); // 00753800 void FUN_00753830(uint32_t *param_1, uint32_t *param_2, uint32_t param_3, uint32_t param_4, uint32_t param_5, uint32_t param_6); // 00753830 -void FUN_00753870(); // 00753870 -void FUN_00753880(); // 00753880 -void FUN_00753890(); // 00753890 -void FUN_007538a0(); // 007538a0 -void FUN_007538b0(); // 007538b0 -void FUN_007538c0(); // 007538c0 uint8_t FUN_007538d0(); // 007538d0 uint32_t FUN_007538e0(); // 007538e0 void FUN_007539a0(); // 007539a0 @@ -6457,7 +6205,6 @@ uint8_t FUN_00753d20(); // 00753d20 uint32_t FUN_00753d30(); // 00753d30 void FUN_00753d40(uint32_t param_1); // 00753d40 uint32_t FUN_00753d50(); // 00753d50 -uint32_t FUN_00753d60(uint32_t *param_1); // 00753d60 void input_state_reset(void *self); // 00754980 void FUN_00757980(uint32_t *param_1); // 00757980 void FUN_00757a10(); // 00757a10 @@ -6466,8 +6213,6 @@ int FUN_00759260(); // 00759260 void FUN_00770640(float *param_1); // 00770640 void FUN_007792f0(uint32_t param_1, uint32_t param_2); // 007792f0 uint32_t FUN_007826c0(); // 007826c0 -void FUN_007829a0(); // 007829a0 -void FUN_00782ab0(uint32_t param_1); // 00782ab0 void FUN_0078b330(uint32_t *param_1); // 0078b330 int FUN_007919c0(); // 007919c0 Entity_Player * FUN_007a0fe0(); // 007a0fe0 @@ -6575,10 +6320,6 @@ void Catch_All_007e8a8b(); // 007e8a8b void FUN_007e8b50(uint32_t param_1, uint32_t *param_2); // 007e8b50 void FUN_007e8d00(uint32_t *param_1); // 007e8d00 void FUN_007e8f70(); // 007e8f70 -void FUN_007e9150(char param_1); // 007e9150 -void FUN_007e9170(char param_1); // 007e9170 -void FUN_007e92e0(uint32_t param_1, uint32_t param_2); // 007e92e0 -void FUN_007e93d0(int param_1); // 007e93d0 void FUN_007ea0c0(); // 007ea0c0 void FUN_00812ea0(float *param_1, int *param_2, int *param_3); // 00812ea0 uint32_t FUN_00813420(int param_1, int param_2); // 00813420 @@ -6608,7 +6349,6 @@ void FUN_0082e290(int param_1, int param_2, int param_3); // 0082e290 void Catch_All_0082e7ec(); // 0082e7ec void FUN_0082ea50(uint32_t param_1, uint32_t *param_2, code *param_3); // 0082ea50 void FUN_0082eb20(uint32_t *param_1, code *param_2); // 0082eb20 -void FUN_008332a0(char param_1); // 008332a0 uint64_t * FUN_00834c60(uint64_t *param_1, uint64_t *param_2); // 00834c60 void Catch_All_00834f6f(); // 00834f6f void FUN_00834fa0(int param_1, int param_2, int param_3); // 00834fa0 @@ -6652,7 +6392,6 @@ void FUN_0083c320(int *param_1, int *param_2); // 0083c320 void FUN_0083c480(); // 0083c480 char * FUN_00840510(); // 00840510 std_string * int_to_string(std_string *outString, int value); // 00840540 -void FUN_0084abc0(uint32_t *param_1, float *param_2, uint32_t *param_3, uint32_t *param_4); // 0084abc0 void FUN_0084bba0(); // 0084bba0 void FUN_0084bbc0(uint32_t *param_1); // 0084bbc0 void FUN_0084bc00(uint32_t *param_1); // 0084bc00 @@ -6677,8 +6416,6 @@ uint8_t date_is_within_week(void *leaderboard); // 00857c90 uint8_t date_is_after(void *dateRange); // 00857e40 uint32_t FUN_00857ff0(); // 00857ff0 int FUN_00858370(); // 00858370 -uint8_t * FUN_00858870(int param_1); // 00858870 -void leaderboard_render_label_value(Vector *pos, uint8_t *label, int value); // 00859100 void FUN_0085a8b0(); // 0085a8b0 void FUN_0085a8f0(int *param_1, int *param_2); // 0085a8f0 void FUN_0085a9d0(int *param_1, int *param_2); // 0085a9d0 @@ -6694,139 +6431,11 @@ void FUN_0085b790(); // 0085b790 void lobby_password_render(void *password, Vector *position, float scale); // 0085b7f0 uint8_t FUN_0085bd40(uint32_t param_1, int *param_2, int *param_3); // 0085bd40 void FUN_0085be70(); // 0085be70 -void FUN_0085bf50(uint32_t param_1); // 0085bf50 -void FUN_0085bf90(); // 0085bf90 -void FUN_0085c010(); // 0085c010 -void FUN_0085c030(); // 0085c030 -void FUN_0085c050(); // 0085c050 -void FUN_0085c1d0(); // 0085c1d0 -int * FUN_0085c200(); // 0085c200 -void FUN_0085c210(uint8_t param_1); // 0085c210 -void FUN_0085c250(); // 0085c250 -bool FUN_0085c2d0(); // 0085c2d0 -bool FUN_0085c300(); // 0085c300 -bool FUN_0085c340(); // 0085c340 -uint8_t FUN_0085c390(); // 0085c390 -uint32_t FUN_0085c3e0(); // 0085c3e0 -void FUN_0085c7e0(uint8_t param_1); // 0085c7e0 -uint32_t FUN_0085c810(uint32_t param_1); // 0085c810 -uint32_t FUN_0085c970(uint32_t param_1); // 0085c970 -void FUN_0085cce0(uint32_t param_1); // 0085cce0 -uint32_t FUN_0085cd40(uint32_t param_1); // 0085cd40 -uint32_t FUN_0085cf30(uint32_t param_1); // 0085cf30 -void FUN_0085d500(uint32_t param_1); // 0085d500 void FUN_0085d6f0(); // 0085d6f0 -uint32_t * FUN_0085d730(uint32_t param_1, uint32_t *param_2); // 0085d730 -void FUN_0085d910(uint32_t *param_1); // 0085d910 -uint32_t FUN_0085da00(uint32_t param_1, uint32_t param_2); // 0085da00 -void FUN_0085da20(uint32_t param_1, uint32_t param_2); // 0085da20 -void FUN_0085da70(int param_1); // 0085da70 -void FUN_0085dab0(); // 0085dab0 -void FUN_0085dae0(uint32_t *param_1); // 0085dae0 -void FUN_0085dbf0(char param_1); // 0085dbf0 -void FUN_0085dc10(char param_1); // 0085dc10 uint32_t * FUN_0085ded0(uint32_t *param_1); // 0085ded0 -void FUN_0085e1d0(char param_1); // 0085e1d0 -void FUN_0085e2a0(uint32_t *param_1); // 0085e2a0 -void FUN_0085e340(uint32_t param_1); // 0085e340 -void FUN_0085e3b0(uint32_t param_1); // 0085e3b0 -uint32_t Catch_00860f8b(); // 00860f8b -uint32_t Catch_00861076(); // 00861076 -uint32_t Catch_0086166f(); // 0086166f -uint32_t Catch_0086174f(); // 0086174f -uint32_t Catch_00861837(); // 00861837 -uint32_t Catch_008619ff(); // 008619ff -uint32_t Catch_00861b88(); // 00861b88 -void FUN_00861bda(); // 00861bda -void FUN_00861c23(); // 00861c23 -uint32_t Catch_00861f2f(); // 00861f2f -uint32_t Catch_0086200f(); // 0086200f -uint32_t Catch_00862198(); // 00862198 -void FUN_008621ea(); // 008621ea -void FUN_00862233(); // 00862233 -uint32_t Catch_0086253f(); // 0086253f -uint32_t Catch_0086261f(); // 0086261f -uint32_t Catch_00862707(); // 00862707 -void FUN_00862d0a(); // 00862d0a -void FUN_00862d53(); // 00862d53 -uint32_t Catch_0086362b(); // 0086362b -uint32_t Catch_00863879(); // 00863879 -uint32_t Catch_00863c6e(); // 00863c6e -uint32_t Catch_00863d4e(); // 00863d4e -uint32_t Catch_008641bb(); // 008641bb -uint32_t Catch_008642a4(); // 008642a4 -uint32_t Catch_00864682(); // 00864682 -uint8_t * Catch_00864e6d(); // 00864e6d -uint32_t Catch_0086504e(); // 0086504e -uint32_t Catch_0086512e(); // 0086512e -uint8_t * Catch_008655b7(); // 008655b7 -void FUN_00865aad(); // 00865aad -void FUN_00865c61(); // 00865c61 -uint32_t Catch_00866364(); // 00866364 -uint8_t FUN_008663b6(); // 008663b6 -void FUN_00866474(); // 00866474 -uint8_t * Catch_0086675e(); // 0086675e -uint32_t Catch_008668e0(); // 008668e0 -void FUN_0086e4d0(); // 0086e4d0 void FUN_00870f21(); // 00870f21 void FUN_00871eb0(); // 00871eb0 -void FUN_00871f70(int *param_1, uint32_t param_2); // 00871f70 -void FUN_00871fa0(Entity *param_1, float param_2); // 00871fa0 -void render_debug_lua_memory(); // 00872090 -uint32_t FUN_00872510(uint32_t param_1); // 00872510 -void FUN_00872530(uint32_t param_1, uint32_t param_2); // 00872530 -void FUN_00872590(); // 00872590 int std_set_int_erase_key(void *self, int *key); // 008725f0 -void FUN_00872730(void *param_1); // 00872730 -void FUN_00872780(void *param_1); // 00872780 -bool FUN_00872820(); // 00872820 -char * FUN_00872860(char *param_1); // 00872860 -void FUN_00872a0c(); // 00872a0c -void FUN_00872af1(); // 00872af1 -void FUN_00872c43(); // 00872c43 -void FUN_00872d80(); // 00872d80 -uint32_t * FUN_00872da0(uint32_t *param_1, uint32_t param_2, int param_3); // 00872da0 -void FUN_00872e71(); // 00872e71 -int * FUN_00872e90(int *param_1, uint32_t param_2, int param_3, uint32_t param_4, uint32_t param_5); // 00872e90 -void FUN_00872fc3(); // 00872fc3 -void FUN_008730c1(); // 008730c1 -void FUN_00873213(); // 00873213 -uint32_t * FUN_00873230(uint32_t *param_1, uint32_t param_2, int param_3); // 00873230 -void FUN_00873301(); // 00873301 -int * FUN_00873320(int *param_1, uint32_t param_2, int param_3, uint32_t param_4, uint32_t param_5); // 00873320 -void FUN_00873453(); // 00873453 -void FUN_00873541(); // 00873541 -uint32_t * FUN_00873560(uint32_t *param_1, uint32_t param_2, int param_3); // 00873560 -void FUN_00873631(); // 00873631 -uint32_t * FUN_00873650(uint32_t *param_1, uint32_t param_2, int param_3); // 00873650 -void FUN_00873721(); // 00873721 -int * FUN_00873740(int *param_1, uint32_t param_2, int param_3, uint32_t param_4, uint32_t param_5); // 00873740 -void FUN_00873873(); // 00873873 -void FUN_00873961(); // 00873961 -void FUN_00873aa0(); // 00873aa0 -void FUN_00873b91(); // 00873b91 -void FUN_00873ce3(); // 00873ce3 -void FUN_00873e20(); // 00873e20 -void FUN_00873f26(); // 00873f26 -void FUN_00874103(); // 00874103 -void FUN_008741f1(); // 008741f1 -void FUN_008742f7(); // 008742f7 -void FUN_008743eb(); // 008743eb -int * FUN_00874400(int *param_1, uint32_t param_2, int param_3, uint32_t param_4, uint32_t param_5); // 00874400 -void FUN_00874533(); // 00874533 -int * FUN_00874550(int *param_1, uint32_t param_2, int param_3, float param_4, uint32_t param_5, uint32_t param_6, int param_7); // 00874550 -void FUN_0087469a(); // 0087469a -void FUN_00874846(); // 00874846 -void FUN_008748f6(); // 008748f6 -void FUN_008749f7(); // 008749f7 -void FUN_00874aa8(); // 00874aa8 -void FUN_00874bbb(); // 00874bbb -uint32_t * FUN_00874bd0(uint32_t *param_1, uint32_t param_2, void *param_3); // 00874bd0 -void FUN_00874d0a(); // 00874d0a -void FUN_00874db6(); // 00874db6 -void FUN_00874e7e(); // 00874e7e -void FUN_00874f4a(); // 00874f4a -uint32_t * FUN_00875050(uint32_t *param_1, uint32_t param_2, uint32_t param_3, uint16_t param_4, uint16_t param_5, uint32_t param_6); // 00875050 void FUN_00875116(); // 00875116 uint32_t * FUN_00875130(); // 00875130 uint32_t * FUN_00875230(uint32_t param_1, uint32_t param_2); // 00875230 @@ -7063,7 +6672,6 @@ void FUN_00882c90(); // 00882c90 void FUN_00882cf0(uint32_t param_1, uint32_t param_2); // 00882cf0 void FUN_00882ed0(); // 00882ed0 void FUN_00882f30(); // 00882f30 -void FUN_00882f90(); // 00882f90 uint32_t * FUN_00882ff0(); // 00882ff0 uint32_t * FUN_00883220(); // 00883220 void FUN_00883320(); // 00883320 @@ -8855,7 +8463,6 @@ void Catch_All_009b1d88(); // 009b1d88 int FUN_009b1dc0(int param_1, int param_2, int param_3); // 009b1dc0 int FUN_009b5800(); // 009b5800 uint32_t FUN_009b9450(int param_1); // 009b9450 -void FUN_009ba9a0(); // 009ba9a0 void FUN_009baa10(char param_1); // 009baa10 int FUN_009bac00(int param_1); // 009bac00 void entity_vector_set_flag_410(void *self, uint8_t value); // 009bea10 @@ -8910,16 +8517,6 @@ void FUN_009d88a0(uint32_t param_1); // 009d88a0 void FUN_009d8a20(uint32_t param_1, uint8_t *param_2); // 009d8a20 void FUN_009db250(uint32_t param_1, uint8_t param_2, int *param_3); // 009db250 void FUN_009dc5a0(char param_1, int param_2); // 009dc5a0 -uint32_t utf8_string_writer_write(int param_1, int param_2); // 009dcbb0 -uint32_t FUN_009e0150(uint32_t param_1); // 009e0150 -uint32_t FUN_009e0180(uint32_t param_1); // 009e0180 -void FUN_009e0390(); // 009e0390 -void FUN_009e03d0(int param_1); // 009e03d0 -void FUN_009e0450(int param_1); // 009e0450 -uint8_t collectible_set_has(void *self, int collectibleId); // 009e04b0 -uint8_t FUN_009e0650(int param_1); // 009e0650 -void trigger_set_dispatch(void *self, int triggerType, Entity *entity, Vector *position, Vector *velocity); // 009e0680 -void FUN_009e24f0(uint32_t *param_1, uint32_t param_2); // 009e24f0 void FUN_009e2520(void *param_1); // 009e2520 void FUN_009e2580(int *param_1, uint32_t *param_2); // 009e2580 int * FUN_009e2760(int *param_1, uint32_t *param_2); // 009e2760 @@ -20669,25 +20266,7 @@ namespace NetLogging { void format_callstack(uint32_t param_1, uint32_t param_2); // 00904a60 } namespace NpcAI { -void ENTITY_BEAST_background(Entity_NPC *npc); // 00440630 -void ENTITY_BEAST_ultra_death(Entity_NPC *npc); // 00440f00 -void ENTITY_BEAST_ultra_death_scythe(Entity_NPC *npc); // 00443e50 -void ENTITY_BEAST_ultra_death_head(Entity_NPC *npc); // 00444900 -void ENTITY_BEAST_ultra_famine(Entity_NPC *npc); // 00444cc0 -void ENTITY_BEAST_ultra_famine_fly(Entity_NPC *npc); // 00447180 -void ENTITY_BEAST_ultra_pestilence(Entity_NPC *npc); // 004477b0 -void ENTITY_BEAST_pestilence_fly(Entity_NPC *npc); // 0044a040 -void ENTITY_BEAST_ultra_pestilence_fly_ball(Entity_NPC *npc); // 0044aad0 -void ENTITY_BEAST_ultra_pestilence_maggot(Entity_NPC *npc); // 0044b6f0 -void ENTITY_BEAST_ultra_war(Entity_NPC *npc); // 0044c070 -void ENTITY_BEAST_ultra_war_fire_burst(Entity_NPC *npc); // 0044ee60 -void ENTITY_BEAST_ultra_war_bomb(Entity_NPC *npc); // 0044f2b0 void ENTITY_BUTT_SLICKER(Entity_NPC *npc); // 0054d250 -uint32_t ENTITY_POLTY(Entity_NPC *npc); // 0055d230 -void ENTITY_SCOURGE_chain(Entity_NPC *npc); // 00584140 -void ENTITY_SCOURGE_main(Entity_NPC *npc); // 005864b0 -void ENTITY_SCOURGE_projectile_attack(Entity_NPC *npc); // 00586c40 -void ENTITY_SCOURGE(Entity_NPC *npc); // 00587aa0 void ENTITY_SINGE_body(Entity_NPC *npc); // 0058aed0 void ENTITY_SIREN_main(Entity_NPC *npc); // 0058ec70 void siren_release_stolen_items(Entity_NPC *npc); // 005911b0 @@ -20715,9 +20294,6 @@ uint32_t _seekPage(int param_1, char param_2); // 00a8e1b0 namespace _Entity { int GetAncestorField(uint32_t param_1); // 006b7d20 } -namespace luabridge::CFunc { -uint32_t readOnlyError(uint32_t param_1); // 0085cad0 -} namespace miniz { void tdefl_start_dynamic_block(void *compressor); // 00a87970 } diff --git a/generated-src/deathmatch_type_base.cpp b/generated-src/deathmatch_type_base.cpp deleted file mode 100644 index a30facb..0000000 --- a/generated-src/deathmatch_type_base.cpp +++ /dev/null @@ -1,716 +0,0 @@ -#include "classes.h" - -// 0042a4d0 -uint8_t DeathmatchTypeBase::Init() -{ - void *camera = this; - Entity_Player *pEVar1; - void *playerListEnd; - int lobbyMembersBytes; - uint32_t uVar2; - int *piVar3; - int lobbyMembersBytes; - uint32_t uVar5; - uint32_t uVar6; - int iStack_24; - Manager *pMStack_20; - int *local_1c; - uint32_t memberIdHigh; - uint64_t uStack_14; - code *assignPlayerFn; - Camera *camera; - Game *game; - - *GHIDRA_CAST((GHIDRA_CAST(camera) + 8)) = 0xa8c; - local_1c = camera; - ItemPool::remove_deathmatch_pill_effects(); - uVar2 = 0; - if (GHIDRA_INT((g_game->_playerManager)._playerList._end) - - GHIDRA_INT((g_game->_playerManager)._playerList._begin) >> 2 != 0) { - do { - game = g_game; - playerListEnd = (g_game->_playerManager)._playerList._end; - if (GHIDRA_INT(playerListEnd) - GHIDRA_INT((g_game->_playerManager)._playerList._begin) >> 2 == 0) { - KAGE_LogMessage(0x10,GHIDRA_CAST("PlayerManager::GetPlayer() : There are no players! \n")); - playerListEnd = (game->_playerManager)._playerList._end; - } - piVar3 = (game->_playerManager)._playerList._begin; - if (uVar2 < GHIDRA_UINT((GHIDRA_INT(playerListEnd) - GHIDRA_INT(piVar3) >> 2))) { - piVar3 = piVar3 + uVar2; - } - lobbyMembersBytes = 4; - piVar3 = GHIDRA_CAST((*piVar3 + 0x13e0)); - do { - if (GHIDRA_CAST(*piVar3) != GHIDRA_CAST(0x0)) { - (**(code **)(*GHIDRA_CAST(*piVar3) + 0x14))(); - } - piVar3 = piVar3 + 1; - lobbyMembersBytes = lobbyMembersBytes + -1; - } while (lobbyMembersBytes != 0); - uVar2 = uVar2 + 1; - } while (uVar2 < GHIDRA_UINT((GHIDRA_INT((g_game->_playerManager)._playerList._end) - - GHIDRA_INT((g_game->_playerManager)._playerList._begin) >> 2))); - } - FUN_009b9150(); - piVar3 = local_1c; - uVar2 = 0; - pMStack_20 = g_manager; - lobbyMembersBytes = GHIDRA_INT((g_manager->_lobbyMembers)._end) - GHIDRA_INT((g_manager->_lobbyMembers)._begin); - lobbyMembersBytes = lobbyMembersBytes >> 0x1f; - if (lobbyMembersBytes / 0x14 + lobbyMembersBytes != lobbyMembersBytes) { - do { - pMStack_20 = (Manager *) - (**(code **)(*piVar3 + 0x7c)) - (*(uint32_t *) - (GHIDRA_INT((pMStack_20->_lobbyMembers)._begin) + uVar2 * 0x14 + 0xc)); - game = g_game; - lobbyMembersBytes = *GHIDRA_CAST((*GHIDRA_CAST((iStack_24 + 0x4b278)) + 4 + uVar2 * 0x14)); - if (lobbyMembersBytes == 0) { - uStack_14 = 0; - (*GHIDRA_CAST((GHIDRA_CAST(&(uStack_14)) + 0x4))) = 0; - (*GHIDRA_CAST((GHIDRA_CAST(&(uStack_14)) + 0x0))) = GHIDRA_CAST(0x0); - memberIdHigh = (*GHIDRA_CAST((GHIDRA_CAST(&(uStack_14)) + 0x4))); - local_1c = GHIDRA_CAST(uStack_14); - } - else { - memberIdHigh = *GHIDRA_CAST((lobbyMembersBytes + 0xc)); - local_1c = *GHIDRA_CAST((lobbyMembersBytes + 8)); - } - if (uVar2 == 0) { - if (*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&((g_game->_seedEffects))) + 0x4)))) == 0) { - KAGE_LogMessage(0x10,GHIDRA_CAST("Error: Game Start Seed was not set.\n")); - } - PlayerManager::init_main_player - (&game->_playerManager,GHIDRA_INT(pMStack_20),(game->_seedEffects)._playerInitSeed); - game = g_game; - pMStack_20 = *GHIDRA_CAST((*piVar3 + 0x78)); - if (GHIDRA_INT((g_game->_playerManager)._playerList._end) - - GHIDRA_INT((g_game->_playerManager)._playerList._begin) >> 2 == 0) { - KAGE_LogMessage(0x10,GHIDRA_CAST("PlayerManager::GetPlayer() : There are no players! \n")); - } - (*(code *)pMStack_20)(*GHIDRA_CAST((game->_playerManager)._playerList._begin),&local_1c); - } - else { - assignPlayerFn = *(code **)(*piVar3 + 0x78); - pEVar1 = PlayerManager::SpawnCoPlayer2(&g_game->_playerManager,GHIDRA_INT(pMStack_20)); - (*assignPlayerFn)(pEVar1,&local_1c); - } - uVar2 = uVar2 + 1; - } while (uVar2 < GHIDRA_UINT(((GHIDRA_INT((pMStack_20->_lobbyMembers)._end) - - GHIDRA_INT((pMStack_20->_lobbyMembers)._begin)) / 0x14))); - } - game = g_game; - (g_game->_playerManager)._coopSlots[0]._controllerIndex = -1; - (game->_playerManager)._coopSlots[1]._controllerIndex = -1; - (game->_playerManager)._coopSlots[0]._state = -1; - (game->_playerManager)._coopSlots[0]._menuPosition = 0.0; - (game->_playerManager)._coopSlots[0]._playerType = 0; - (game->_playerManager)._coopSlots[1]._state = -1; - (game->_playerManager)._coopSlots[1]._menuPosition = 0.0; - (game->_playerManager)._coopSlots[1]._playerType = 0; - (game->_playerManager)._coopSlots[2]._controllerIndex = -1; - (game->_playerManager)._coopSlots[2]._state = -1; - (game->_playerManager)._coopSlots[2]._menuPosition = 0.0; - (game->_playerManager)._coopSlots[2]._playerType = 0; - (game->_playerManager)._coopSlots[3]._controllerIndex = -1; - (game->_playerManager)._coopSlots[3]._state = -1; - (game->_playerManager)._coopSlots[3]._menuPosition = 0.0; - (game->_playerManager)._coopSlots[3]._playerType = 0; - HUD::AssignPlayerHUDs(&game->_hud); - FUN_00943830(); - camera = *GHIDRA_CAST((GHIDRA_CAST(g_game->_room) + 0x11f8)); - lobbyMembersBytes = (g_manager->_optionsConfig)._cameraStyle; - if ((lobbyMembersBytes == 1) || (lobbyMembersBytes != 2)) { - Camera::update_focus_position(camera,0); - camera->_shouldOverride = 0; - } - else { - Camera::update_follow(camera); - } - uVar5 = 1; - HUD::mark_all_slots_dirty(&g_game->_hud,1,1); - uVar6 = 0x42a832; - text_image_cache_reset(&(g_game->_hud)._statHUD); - FUN_009a8a40(uVar5,uVar6); - lobbyMembersBytes = *GHIDRA_CAST((GHIDRA_CAST(g_game->_room) + 4)); - if (((lobbyMembersBytes == 0) || (lobbyMembersBytes = *GHIDRA_CAST((lobbyMembersBytes + 0x10)), lobbyMembersBytes == 0)) || - (((lobbyMembersBytes = *GHIDRA_CAST((lobbyMembersBytes + 0x48)), lobbyMembersBytes != 8 && - (((lobbyMembersBytes != 0xb && (lobbyMembersBytes != 0xc)) && (lobbyMembersBytes != 9)))) && (lobbyMembersBytes != 10)))) { - uVar2 = Random(); - lobbyMembersBytes = uVar2 % 5 + 8; - } - else { - uVar2 = Random(); - lobbyMembersBytes = uVar2 % 6 + 5; - } - piVar3[10] = lobbyMembersBytes * 0x1e; - return 1; -} - -// 0042a8b0 -void DeathmatchTypeBase::Update() -{ - void *room = this; - uint32_t uVar1; - uint32_t uVar2; - Vector *tilePos; - int *piVar3; - GridEntity *spikes; - void *pvVar4; - int gridX; - Game *game; - int iVar5; - PlayerManager *playerManager; - float dy; - float fVar6; - float dx; - float tileY; - Vector freeTilePos; - Vector randomTilePos; - Vector flyBombPos; - GridEntity *local_20; - float savedTileY; - float local_18; - int *self; - void *local_10; - uint8_t *puStack_c; - uint32_t local_8; - uint32_t *oldGridEntity; - Room *room; - - local_8 = 0xffffffff; - puStack_c = &LAB_00af1d27; - local_10 = ExceptionList; - uVar1 = __security_cookie ^ GHIDRA_INT(register0x00000010) - 4U; - ExceptionList = &local_10; - iVar5 = *GHIDRA_CAST((GHIDRA_CAST(room) + 8)) + -1; - *GHIDRA_CAST((GHIDRA_CAST(room) + 8)) = iVar5; - if (*GHIDRA_CAST((GHIDRA_CAST(room) + 0xc)) < 1.0) { - *GHIDRA_CAST((GHIDRA_CAST(room) + 0xc)) = *GHIDRA_CAST((GHIDRA_CAST(room) + 0xc)) + 0.033333335; - } - self = room; - if (iVar5 < 0) { - if (iVar5 % 0x1e == 0) { - iVar5 = GHIDRA_INT(((uint64_t)((int64_t)iVar5 * 0x77777777) >> 0x20)) - iVar5; - uVar2 = Random(); - tilePos = Room::GetRandomPosition(g_game->_room,&flyBombPos,0.0); - Game::SpawnEx(g_game,0x333,0,tilePos,&g_vectorZero,GHIDRA_CAST(0x0),0,uVar2,0); - uVar2 = (iVar5 >> 4) - (iVar5 >> 0x1f) & 0x80000003; - if (GHIDRA_INT(uVar2) < 0) { - uVar2 = (uVar2 - 1 | 0xfffffffc) + 1; - } - if (uVar2 == 0) { - local_20 = GHIDRA_CAST(0xa); - game = g_game; - do { - room = game->_room; - local_20 = GHIDRA_CAST((GHIDRA_INT(&local_20[-1]._sprite._bitflags) + 3)); - tilePos = Room::GetRandomPosition(room,&randomTilePos,0.0); - tilePos = Room::FindFreeTilePosition(room,&freeTilePos,tilePos,0.0); - uVar2 = 0; - playerManager = &g_game->_playerManager; - fVar6 = tilePos->x; - tileY = tilePos->y; - game = g_game; - savedTileY = tileY; - local_18 = fVar6; - if (GHIDRA_INT((g_game->_playerManager)._playerList._end) - - GHIDRA_INT((playerManager->_playerList)._begin) >> 2 == 0) { -LAB_0042aa81: - pvVar4 = game->_room; - iVar5 = GHIDRA_INT(((tileY - 120.0) / 40.0 + 0.5)); - gridX = GHIDRA_INT(((fVar6 - 40.0) / 40.0 + 0.5)); - if ((((gridX < 0) || (*GHIDRA_CAST((GHIDRA_CAST(pvVar4) + 0xc)) <= gridX)) || (iVar5 < 0)) || - (*GHIDRA_CAST((GHIDRA_CAST(pvVar4) + 0x10)) <= iVar5)) { - uVar2 = 0xffffffff; - local_18 = (float)Random(); -LAB_0042ab07: - KAGE_LogMessage(0x10,GHIDRA_CAST("SpawnGridEntity: Grid index invalid\n")); - } - else { - uVar2 = *GHIDRA_CAST((GHIDRA_CAST(pvVar4) + 0xc)) * iVar5 + gridX; - local_18 = (float)Random(); - if ((GHIDRA_INT(uVar2) < 0) || (0x1bf < GHIDRA_INT(uVar2))) goto LAB_0042ab07; - } - room = self; - if ((uVar2 < 0x1c0) && (*GHIDRA_CAST((GHIDRA_CAST(pvVar4) + uVar2 * 4 + 0x76c)) < 0x385)) { - spikes = operator_new(0x158); - local_8 = 0xd; - local_20 = spikes; - if (spikes == GHIDRA_CAST(0x0)) { - spikes = GHIDRA_CAST(0x0); - } - else { - GridEntity::GridEntity(spikes); - *GHIDRA_CAST(spikes) = IsaacRepentancePlus::GridEntity_Spikes::vftable; - } - local_8 = 0xffffffff; - room = self; - if (spikes != GHIDRA_CAST(0x0)) { - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((spikes)) + 0x4)))) = 9; - spikes->_gridIndex = uVar2; - oldGridEntity = *GHIDRA_CAST((GHIDRA_CAST(pvVar4) + uVar2 * 4 + 0x24)); - if (oldGridEntity != GHIDRA_CAST(0x0)) { - (**(code **)*oldGridEntity)(1); - } - *GHIDRA_CAST((GHIDRA_CAST(pvVar4) + uVar2 * 4 + 0x24)) = spikes; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((spikes)) + 0x14)))) = local_18; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((spikes)) + 0x8)))) = 0; - spikes->_varData = 0; - spikes->_collisionClass = 0; - (**(code **)(*GHIDRA_CAST(spikes) + 0x20))(); - game = g_game; - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((spikes)) + 0x10)))) = *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST((spikes)) + 0x10)))) + 1; - (*GHIDRA_CAST((GHIDRA_CAST((spikes)) + 0x1c))) = 1; - spikes->_spawnFrame = game->_frameCount; - room = self; - } - } - break; - } - while( true ) { - pvVar4 = (playerManager->_playerList)._end; - if (GHIDRA_INT(pvVar4) - GHIDRA_INT((playerManager->_playerList)._begin) >> 2 == 0) { - KAGE_LogMessage(0x10,GHIDRA_CAST("PlayerManager::GetPlayer() : There are no players! \n")); - pvVar4 = (playerManager->_playerList)._end; - game = g_game; - fVar6 = local_18; - tileY = savedTileY; - } - piVar3 = (playerManager->_playerList)._begin; - if (uVar2 < GHIDRA_UINT((GHIDRA_INT(pvVar4) - GHIDRA_INT(piVar3) >> 2))) { - piVar3 = piVar3 + uVar2; - } - dx = fVar6 - *GHIDRA_CAST((*piVar3 + 0x33c)); - dy = tileY - *GHIDRA_CAST((*piVar3 + 0x340)); - if (dy * dy + dx * dx < 144.0) break; - playerManager = &game->_playerManager; - uVar2 = uVar2 + 1; - if (GHIDRA_UINT((GHIDRA_INT((game->_playerManager)._playerList._end) - - GHIDRA_INT((playerManager->_playerList)._begin) >> 2)) <= uVar2) goto LAB_0042aa81; - } - } while (local_20 != GHIDRA_CAST(0x0)); - } - } - iVar5 = *GHIDRA_CAST((GHIDRA_CAST(room) + 8)); - fVar6 = (float)(-iVar5 % 0xf) / 15.0; - iVar5 = GHIDRA_INT(((uint64_t)((int64_t)iVar5 * 0x77777777) >> 0x20)) - iVar5; - *GHIDRA_CAST((GHIDRA_CAST(room) + 0xc)) = fVar6; - if ((~((char)(iVar5 >> 3) - (char)(iVar5 >> 0x1f)) & 1U) != 0) { - *GHIDRA_CAST((GHIDRA_CAST(room) + 0xc)) = 1.0 - fVar6; - } - } - if ((*GHIDRA_CAST((GHIDRA_CAST(room) + 4)) & 1) != 0) { - piVar3 = GHIDRA_CAST((GHIDRA_INT(room) + 0x28)); - *piVar3 = *piVar3 + -1; - if (*piVar3 == 0) { - (**(code **)(*GHIDRA_CAST(room) + 0x80))(uVar1); - iVar5 = *GHIDRA_CAST((GHIDRA_CAST(g_game->_room) + 4)); - if (((iVar5 == 0) || (iVar5 = *GHIDRA_CAST((iVar5 + 0x10)), iVar5 == 0)) || - (((iVar5 = *GHIDRA_CAST((iVar5 + 0x48)), iVar5 != 8 && - (((iVar5 != 0xb && (iVar5 != 0xc)) && (iVar5 != 9)))) && (iVar5 != 10)))) { - uVar1 = Random(); - iVar5 = uVar1 % 5 + 8; - } - else { - uVar1 = Random(); - iVar5 = uVar1 % 6 + 5; - } - *GHIDRA_CAST((GHIDRA_CAST(room) + 0x28)) = iVar5 * 0x1e; - } - } - ExceptionList = local_10; - return; -} - -// 0042bd70 -void DeathmatchTypeBase::StoreGameState(void *gameState) -{ - void *gameStateLocal; - uint32_t *storedEnd; - - gameStateLocal = gameState; - *GHIDRA_CAST((GHIDRA_CAST(gameState) + 0x1fde4)) = *GHIDRA_CAST((GHIDRA_CAST(gameState) + 0x1fde0)); - gameState = (void *)**GHIDRA_CAST((GHIDRA_CAST(this) + 0x20)); - if (gameState != *GHIDRA_CAST((GHIDRA_CAST(this) + 0x20))) { - do { - storedEnd = *GHIDRA_CAST((GHIDRA_CAST(gameStateLocal) + 0x1fde4)); - if (storedEnd == *GHIDRA_CAST((GHIDRA_CAST(gameStateLocal) + 0x1fde8))) { - msvc::vector::_Emplace_reallocate - (storedEnd,GHIDRA_CAST((GHIDRA_INT(gameState) + 0x10))); - } - else { - *storedEnd = *GHIDRA_CAST((GHIDRA_CAST(gameState) + 0x10)); - *GHIDRA_CAST((GHIDRA_CAST(gameStateLocal) + 0x1fde4)) = *GHIDRA_CAST((GHIDRA_CAST(gameStateLocal) + 0x1fde4)) + 4; - } - msvc:: - _Tree_unchecked_const_iterator_>,msvc::_Iterator_base0> - ::operator++((_Tree_unchecked_const_iterator_>,msvc::_Iterator_base0> - *)&gameState); - } while (gameState != *(void **)(GHIDRA_CAST(this) + 0x20)); - } - return; -} - -// 0042bdf0 -void DeathmatchTypeBase::RestoreGameState(int param_1) -{ - int iVar1; - uint32_t uVar2; - int *node; - int in_ECX; - int *piVar3; - int *node; - int *fixNode; - int *idSet; - int *insertParent; - int isInsertLeft; - int *boundNode; - int *local_24; - uint32_t local_20; - int *treeHead; - int *savedIdCursor; - int *idSetSaved; - void *local_10; - uint8_t *puStack_c; - uint32_t local_8; - int *rotateParent; - - local_8 = 0xffffffff; - puStack_c = &LAB_00af1dcd; - local_10 = ExceptionList; - uVar2 = __security_cookie ^ GHIDRA_INT(register0x00000010) - 4U; - ExceptionList = &local_10; - iVar1 = *GHIDRA_CAST((in_ECX + 0x20)); - idSet = GHIDRA_CAST((in_ECX + 0x20)); - idSetSaved = idSet; - FID_conflict__Erase_tree_>_> - (idSet,(fuzzer_allocator_> *)idSet, - *(_Tree_node **)(iVar1 + 4)); - *GHIDRA_CAST((iVar1 + 4)) = iVar1; - *GHIDRA_CAST(iVar1) = iVar1; - *GHIDRA_CAST((iVar1 + 8)) = iVar1; - *GHIDRA_CAST((in_ECX + 0x24)) = 0; - savedIdCursor = *GHIDRA_CAST((param_1 + 0x1fde0)); - if (savedIdCursor != *GHIDRA_CAST((param_1 + 0x1fde4))) { - do { - node = savedIdCursor; - msvc::set::find_node(&insertParent,savedIdCursor); - if ((*GHIDRA_CAST((GHIDRA_CAST(boundNode) + 0xd)) != '\0') || (node = boundNode, *node < boundNode[4])) { - if (idSet[1] == 0xaaaaaaa) { - /* WARNING: Subroutine does not return */ - FUN_004170d0(uVar2); - } - iVar1 = *idSet; - local_24 = idSetSaved; - local_8 = 0; - local_20 = 0; - node = operator_new(0x18); - idSet = idSetSaved; - local_8 = 0xffffffff; - local_20 = 0; - node[4] = *node; - *GHIDRA_CAST((node + 5)) = 0; - *node = iVar1; - node[1] = iVar1; - node[2] = iVar1; - *GHIDRA_CAST((node + 3)) = 0; - treeHead = GHIDRA_CAST(*idSetSaved); - idSetSaved[1] = idSetSaved[1] + 1; - node[1] = GHIDRA_INT(insertParent); - if (insertParent == treeHead) { - *treeHead = GHIDRA_INT(node); - treeHead[1] = GHIDRA_INT(node); - treeHead[2] = GHIDRA_INT(node); - *GHIDRA_CAST((node + 3)) = 1; - } - else { - if (isInsertLeft == 0) { - insertParent[2] = GHIDRA_INT(node); - if (insertParent == GHIDRA_CAST(treeHead[2])) { - treeHead[2] = GHIDRA_INT(node); - } - } - else { - *insertParent = GHIDRA_INT(node); - if (insertParent == GHIDRA_CAST(*treeHead)) { - *treeHead = GHIDRA_INT(node); - } - } - fixNode = node; - if (*GHIDRA_CAST((node[1] + 0xc)) == '\0') { - do { - node = GHIDRA_CAST(fixNode[1]); - piVar3 = *GHIDRA_CAST(node[1]); - if (node == piVar3) { - piVar3 = GHIDRA_CAST((GHIDRA_CAST(node[1]))[2]); - if ((char)piVar3[3] == '\0') goto LAB_0042bfa6; - if (fixNode == GHIDRA_CAST(node[2])) { - FUN_00415fe0(node); - fixNode = node; - } - *GHIDRA_CAST((fixNode[1] + 0xc)) = 1; - *GHIDRA_CAST((*GHIDRA_CAST((fixNode[1] + 4)) + 0xc)) = 0; - node = *GHIDRA_CAST((fixNode[1] + 4)); - piVar3 = GHIDRA_CAST(*node); - *node = piVar3[2]; - if (*GHIDRA_CAST((piVar3[2] + 0xd)) == '\0') { - *GHIDRA_CAST((piVar3[2] + 4)) = node; - } - piVar3[1] = node[1]; - iVar1 = *idSet; - if (node == *GHIDRA_CAST((iVar1 + 4))) { - *GHIDRA_CAST((iVar1 + 4)) = piVar3; - piVar3[2] = GHIDRA_INT(node); - } - else { - rotateParent = GHIDRA_CAST(node[1]); - if (node == GHIDRA_CAST(rotateParent[2])) { - rotateParent[2] = GHIDRA_INT(piVar3); - piVar3[2] = GHIDRA_INT(node); - } - else { - *rotateParent = GHIDRA_INT(piVar3); - piVar3[2] = GHIDRA_INT(node); - } - } -LAB_0042c01a: - node[1] = GHIDRA_INT(piVar3); - } - else { - if ((char)piVar3[3] != '\0') { - if (fixNode == GHIDRA_CAST(*node)) { - FUN_00415f80(node); - fixNode = node; - } - *GHIDRA_CAST((fixNode[1] + 0xc)) = 1; - *GHIDRA_CAST((*GHIDRA_CAST((fixNode[1] + 4)) + 0xc)) = 0; - node = *GHIDRA_CAST((fixNode[1] + 4)); - piVar3 = GHIDRA_CAST(node[2]); - node[2] = *piVar3; - if (*GHIDRA_CAST((*piVar3 + 0xd)) == '\0') { - *GHIDRA_CAST((*piVar3 + 4)) = node; - } - piVar3[1] = node[1]; - iVar1 = *idSet; - if (node == *GHIDRA_CAST((iVar1 + 4))) { - *GHIDRA_CAST((iVar1 + 4)) = piVar3; - } - else { - rotateParent = GHIDRA_CAST(node[1]); - if (node == GHIDRA_CAST(*rotateParent)) { - *rotateParent = GHIDRA_INT(piVar3); - } - else { - rotateParent[2] = GHIDRA_INT(piVar3); - } - } - *piVar3 = GHIDRA_INT(node); - goto LAB_0042c01a; - } -LAB_0042bfa6: - *GHIDRA_CAST((node + 3)) = 1; - *GHIDRA_CAST((piVar3 + 3)) = 1; - *GHIDRA_CAST((*GHIDRA_CAST((fixNode[1] + 4)) + 0xc)) = 0; - fixNode = *GHIDRA_CAST((fixNode[1] + 4)); - } - } while (*GHIDRA_CAST((fixNode[1] + 0xc)) == '\0'); - node = savedIdCursor; - } - *GHIDRA_CAST((treeHead[1] + 0xc)) = 1; - idSet = idSetSaved; - } - } - savedIdCursor = node + 1; - *GHIDRA_CAST((node + 5)) = 1; - } while (savedIdCursor != *GHIDRA_CAST((param_1 + 0x1fde4))); - } - ExceptionList = local_10; - return; -} - -// 0042c170 -Entity * DeathmatchTypeBase::spawn_random_pickup() -{ - Room *this_00; - uint32_t uVar1; - int roomShape; - uint32_t modeValue; - int *playerSlot; - uint32_t uVar3; - Entity *pickup; - void *playerListEnd; - uint32_t uVar4; - uint64_t *allocCounter; - Game *game; - PlayerManager *playerManager; - Vector spawnPos; - uint8_t local_24 [8]; - Vector local_1c; - float roomHeight; - void *local_10; - uint8_t *puStack_c; - uint32_t local_8; - float maxDimension; - uint64_t oldBytes; - int roomShape; - - local_8 = 0xffffffff; - puStack_c = &LAB_00af1df0; - local_10 = ExceptionList; - uVar1 = __security_cookie ^ GHIDRA_UINT((local_24 + 0x20)); - ExceptionList = &local_10; - EntityList::QuerySublist - (GHIDRA_CAST((GHIDRA_INT(g_game->_room) + 0x1218)),GHIDRA_CAST(local_24),5,-1,-1,0,0); - uVar4 = 0; - maxDimension = 0.0; - uVar3 = uVar4; - if (local_1c.y != 0.0) { - do { - uVar4 = uVar3 + 1; - if (*GHIDRA_CAST((*GHIDRA_CAST(((*GHIDRA_CAST((GHIDRA_CAST(&(local_24)) + 0x4))) + GHIDRA_INT(maxDimension) * 4)) + 0x2c)) == 100) { - uVar4 = uVar3; - } - maxDimension = (float)(GHIDRA_INT(maxDimension) + 1); - uVar3 = uVar4; - } while (GHIDRA_UINT(maxDimension) < GHIDRA_UINT(local_1c.y)); - } - roomShape = *GHIDRA_CAST((GHIDRA_CAST(g_game->_room) + 4)); - if (roomShape != 0) { - if (*GHIDRA_CAST((roomShape + 0x10)) == 0) { -LAB_0042c228: - roomShape = *GHIDRA_CAST((roomShape + 0x10)); - if (roomShape == 0) goto LAB_0042c24b; - } - else { - roomShape = *GHIDRA_CAST((*GHIDRA_CAST((roomShape + 0x10)) + 0x48)); - if ((((roomShape == 8) || (roomShape == 0xb)) || (roomShape == 0xc)) || - ((roomShape == 9 || (roomShape == 10)))) { - if (9 < uVar4) goto LAB_0042c250; - if (roomShape == 0) goto LAB_0042c24b; - goto LAB_0042c228; - } - roomShape = *GHIDRA_CAST((roomShape + 0x10)); - } - roomShape = *GHIDRA_CAST((roomShape + 0x48)); - if (((roomShape == 8) || (roomShape == 0xb)) || ((roomShape == 0xc || ((roomShape == 9 || (roomShape == 10)))))) - goto LAB_0042c281; - } -LAB_0042c24b: - if (4 < uVar4) { -LAB_0042c250: - if (local_24[0] == '\0') { - local_8 = 0; - tracked_alloc(1,(*GHIDRA_CAST((GHIDRA_CAST(&((void *)local_24)) + 0x4))),0); - } - ExceptionList = local_10; - return GHIDRA_CAST(0x0); - } -LAB_0042c281: - if (local_24[0] == '\0') { - if (g_mainHeap == (void *)0x0) { - allocCounter = &g_allocatedBytesNoHeap; - } - else { - allocCounter = GHIDRA_CAST((GHIDRA_INT(g_mainHeap) + 0x30)); - } - if ((*GHIDRA_CAST((GHIDRA_CAST(&((void *)local_24)) + 0x4))) != (void *)0x0) { - uVar4 = *GHIDRA_CAST(((*GHIDRA_CAST((GHIDRA_CAST(&(local_24)) + 0x4))) + -4)); - oldBytes = *allocCounter; - *GHIDRA_CAST(allocCounter) = GHIDRA_UINT(*allocCounter) - uVar4; - *GHIDRA_CAST((GHIDRA_CAST(allocCounter) + 4)) = - *GHIDRA_CAST((GHIDRA_CAST(allocCounter) + 4)) - GHIDRA_UINT((GHIDRA_UINT(oldBytes) < uVar4)); - free((void *)((*GHIDRA_CAST((GHIDRA_CAST(&(local_24)) + 0x4))) + -4)); - } - local_8 = 0xffffffff; - } - uVar4 = 10; - roomShape = this->FUN_0042c6a0(this,3,0x32,0x14,0x18,uVar1); - if (roomShape == 0) { - modeValue = this->FUN_0042c6a0(this,4,0x1e,10,10,0x32); - switch(modeValue) { - case 1: - uVar4 = 0x14; - break; - case 2: - uVar4 = 0x1e; - break; - case 3: - uVar4 = 0x28; - } - } - else if (roomShape == 1) { - roomShape = this->FUN_0042c6a0(this,3,0x21,0x21,0x22); - if (roomShape == 0) { - uVar4 = 0x45; - } - else if (roomShape == 1) { - uVar4 = 0x46; - } - else if (roomShape == 2) { - uVar4 = 0; - playerManager = &g_game->_playerManager; - game = g_game; - if (GHIDRA_INT((g_game->_playerManager)._playerList._end) - GHIDRA_INT((playerManager->_playerList)._begin) - >> 2 != 0) { - do { - playerListEnd = (playerManager->_playerList)._end; - if (GHIDRA_INT(playerListEnd) - GHIDRA_INT((playerManager->_playerList)._begin) >> 2 == 0) { - KAGE_LogMessage(0x10,GHIDRA_CAST("PlayerManager::GetPlayer() : There are no players! \n")); - playerListEnd = (playerManager->_playerList)._end; - game = g_game; - } - playerSlot = (playerManager->_playerList)._begin; - if (uVar4 < GHIDRA_UINT((GHIDRA_INT(playerListEnd) - GHIDRA_INT(playerSlot) >> 2))) { - playerSlot = playerSlot + uVar4; - } - if (*GHIDRA_CAST((*playerSlot + 0x1580)) != 0) { - uVar4 = 0x5a; - goto LAB_0042c436; - } - playerManager = &game->_playerManager; - uVar4 = uVar4 + 1; - } while (uVar4 < GHIDRA_UINT((GHIDRA_INT((game->_playerManager)._playerList._end) - - GHIDRA_INT((playerManager->_playerList)._begin) >> 2))); - } - uVar4 = Random(); - uVar4 = 0x46 - ((uVar4 & 1) != 0); - } - } - else if (roomShape == 2) { - modeValue = this->FUN_0042c6a0(this,4,0x28,10,10,0x28); - switch(modeValue) { - case 0: - uVar4 = 0x32; - break; - case 1: - uVar4 = 0x33; - break; - case 2: - uVar4 = 0x34; - break; - case 3: - uVar4 = 0x168; - } - } -LAB_0042c436: - uVar3 = Random(); - this_00 = g_game->_room; - local_1c.y = (this_00->_bottomRightPos).x - (this_00->_topLeftPos).x; - roomHeight = (this_00->_bottomRightPos).y - (this_00->_topLeftPos).y; - uVar1 = Random(); - maxDimension = roomHeight; - if (roomHeight <= local_1c.y) { - maxDimension = local_1c.y; - } - local_1c.x = local_1c.y * 0.5; - local_1c.y = roomHeight * 0.5 + (this_00->_topLeftPos).y; - local_1c.x = local_1c.x + (this_00->_topLeftPos).x; - Room::FindFreePickupSpawnPosition - (this_00,&spawnPos,&local_1c, - (float)((double)GHIDRA_INT(uVar1) + __uint_to_double_fixup[-(GHIDRA_INT(uVar1) >> 0x1f)]) * - 2.3283064e-10 * maxDimension,0,0,0); - pickup = Game::SpawnEx(g_game,5,uVar4,&spawnPos,&g_vectorZero,GHIDRA_CAST(0x0),0,uVar3,0); - ExceptionList = local_10; - return pickup; -} diff --git a/generated-src/glitched_collectible_gfx.cpp b/generated-src/glitched_collectible_gfx.cpp deleted file mode 100644 index 763e412..0000000 --- a/generated-src/glitched_collectible_gfx.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "classes.h" - -// 009dc6e0 -void * GlitchedCollectibleGfx::constructor() -{ - *GHIDRA_CAST(this) = 0; - *GHIDRA_CAST((GHIDRA_CAST(this) + 4)) = 0; - *GHIDRA_CAST((GHIDRA_CAST(this) + 8)) = 0x12345678; - *GHIDRA_CAST((GHIDRA_CAST(this) + 0xc)) = 0; - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x10)) = 0; - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x2c)) = 0; - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x30)) = 0; - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x34)) = 0; - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x14)) = 0; - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x18)) = 0; - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x1c)) = 0; - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x20)) = 0; - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x24)) = 0; - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x28)) = 0; - return this; -} diff --git a/generated-src/glitched_item_set.cpp b/generated-src/glitched_item_set.cpp deleted file mode 100644 index b1c0e4a..0000000 --- a/generated-src/glitched_item_set.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include "classes.h" - -// 009e0500 -void GlitchedItemSet::recalculate() -{ - uint32_t uVar1; - int countArray; - int node; - int *countInfo; - Game *game; - int proceduralItem; - void *proceduralItems; - - uVar1 = 0; - if (*GHIDRA_CAST((GHIDRA_CAST(this) + 0x10)) != *GHIDRA_CAST((GHIDRA_CAST(this) + 0xc))) { - do { - *GHIDRA_CAST((uVar1 + *GHIDRA_CAST((GHIDRA_CAST(this) + 0xc)))) = 0; - uVar1 = uVar1 + 1; - } while (uVar1 < GHIDRA_UINT((*GHIDRA_CAST((GHIDRA_CAST(this) + 0x10)) - *GHIDRA_CAST((GHIDRA_CAST(this) + 0xc))))); - } - uVar1 = 0; - if (*GHIDRA_CAST((GHIDRA_CAST(this) + 0x1c)) != *GHIDRA_CAST((GHIDRA_CAST(this) + 0x18))) { - do { - *GHIDRA_CAST((uVar1 + *GHIDRA_CAST((GHIDRA_CAST(this) + 0x18)))) = 0; - uVar1 = uVar1 + 1; - } while (uVar1 < GHIDRA_UINT((*GHIDRA_CAST((GHIDRA_CAST(this) + 0x1c)) - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x18))))); - } - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x24)) = 0; - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x28)) = 0; - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x2c)) = 0; - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x30)) = 0; - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x34)) = 0; - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x38)) = 0; - game = g_game; - node = **GHIDRA_CAST((GHIDRA_CAST(this) + 4)); - if (GHIDRA_CAST(node) != *GHIDRA_CAST((GHIDRA_CAST(this) + 4))) { - do { - uVar1 = ~*GHIDRA_CAST((node + 0x10)); - if (((GHIDRA_INT(*GHIDRA_CAST((node + 0x10))) < 0) && - (proceduralItems = (game->_proceduralItemManager)._proceduralItems._begin, - GHIDRA_INT(uVar1) < - GHIDRA_INT((game->_proceduralItemManager)._proceduralItems._end) - GHIDRA_INT(proceduralItems) >> 2)) && - (proceduralItem = *GHIDRA_CAST((GHIDRA_CAST(proceduralItems) + uVar1 * 4)), proceduralItem != 0)) { - countInfo = *GHIDRA_CAST((proceduralItem + 0x10)); - if (countInfo != GHIDRA_CAST(0x0)) { - if (*countInfo == 2) { - countArray = *GHIDRA_CAST((GHIDRA_CAST(this) + 0x18)); - } - else { - if (*countInfo == 0) goto LAB_009e05d4; - countArray = *GHIDRA_CAST((GHIDRA_CAST(this) + 0xc)); - } - *GHIDRA_CAST((countInfo[1] + countArray)) = - *GHIDRA_CAST((countInfo[1] + countArray)) + *GHIDRA_CAST((node + 0x14)); - } -LAB_009e05d4: - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x24)) = - *GHIDRA_CAST((proceduralItem + 0x14)) + *GHIDRA_CAST((GHIDRA_CAST(this) + 0x24)); - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x28)) = - *GHIDRA_CAST((proceduralItem + 0x18)) + *GHIDRA_CAST((GHIDRA_CAST(this) + 0x28)); - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x2c)) = - *GHIDRA_CAST((proceduralItem + 0x1c)) + *GHIDRA_CAST((GHIDRA_CAST(this) + 0x2c)); - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x30)) = - *GHIDRA_CAST((proceduralItem + 0x20)) + *GHIDRA_CAST((GHIDRA_CAST(this) + 0x30)); - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x34)) = - *GHIDRA_CAST((proceduralItem + 0x24)) + *GHIDRA_CAST((GHIDRA_CAST(this) + 0x34)); - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x38)) = - *GHIDRA_CAST((proceduralItem + 0x28)) + *GHIDRA_CAST((GHIDRA_CAST(this) + 0x38)); - } - msvc:: - _Tree_unchecked_const_iterator_>,msvc::_Iterator_base0> - ::operator++((_Tree_unchecked_const_iterator_>,msvc::_Iterator_base0> - *)&node); - } while (node != *GHIDRA_CAST((GHIDRA_CAST(this) + 4))); - } - return; -} diff --git a/generated-src/npc_helper.cpp b/generated-src/npc_helper.cpp index b7b7392..c5fb89a 100644 --- a/generated-src/npc_helper.cpp +++ b/generated-src/npc_helper.cpp @@ -104,78 +104,6 @@ LAB_00499c40: goto LAB_00499ba3; } -// 0055d070 -uint8_t NpcHelper::polty_target_set(int gridIndex) -{ - if (((gridIndex < 0) || (0x1bf < gridIndex)) || - (*GHIDRA_CAST((GHIDRA_CAST(g_game->_room) + gridIndex * 2 + 0xe6c)) < 1)) { - *GHIDRA_CAST((GHIDRA_CAST(this) + 0xbc4)) = gridIndex; - return 1; - } - return 0; -} - -// 0055d0b0 -uint8_t NpcHelper::polty_is_target_liftable(Entity_NPC *npc) -{ - uint8_t local_AL_113; - int extraout_EDX; - float snapY; - int gridWidth; - Room *room; - - gridWidth = npc->_spawnerEntity; - if ((gridWidth == 0) || (*GHIDRA_CAST((gridWidth + 0x28)) != 5)) { - if (npc->_i2 < 0) { - return 0; - } - room = g_game->_room; - local_AL_113 = Room::CanPickupGridEntity(room,npc->_i2); - if (local_AL_113 == 0) { - return 0; - } - if (npc->_variant == 1) { - return 1; - } - gridWidth = room->_gridWidth; - snapY = (float)(extraout_EDX / gridWidth) * 40.0 + 120.0; - (npc->_pos).x = (float)(extraout_EDX % gridWidth) * 40.0 + 40.0; - } - else { - snapY = *GHIDRA_CAST((gridWidth + 0x340)); - (npc->_pos).x = *GHIDRA_CAST((gridWidth + 0x33c)); - } - (npc->_pos).y = snapY; - (npc->_velocity).x = g_vectorZero.x; - (npc->_velocity).y = g_vectorZero.y; - return 1; -} - -// 0055d180 -uint8_t NpcHelper::polty_is_pot_cell(Entity_NPC *npc, int gridIndex) -{ - uint8_t bVar1; - Game *game; - int gridWidth; - - game = g_game; - if (GHIDRA_UINT(gridIndex) < 0x1c0) { - gridWidth = *GHIDRA_CAST((GHIDRA_CAST(g_game->_room) + gridIndex * 4 + 0x24)); - if ((gridWidth != 0) && - (((*GHIDRA_CAST((gridWidth + 4)) == 6 || (*GHIDRA_CAST((gridWidth + 4)) == 0x1a)) && - (*GHIDRA_CAST((gridWidth + 0xc)) == 1)))) { - bVar1 = polty_target_set(npc,gridIndex); - if (bVar1 != 0) { - gridWidth = *GHIDRA_CAST((GHIDRA_CAST(game->_room) + 0xc)); - (npc->_pos).x = (float)(gridIndex % gridWidth) * 40.0 + 40.0; - (npc->_pos).y = (float)(gridIndex / gridWidth) * 40.0 + 120.0; - return 1; - } - } - } - return 0; -} - // 005688c0 void NpcHelper::mother_set_collision_class(Entity_NPC *npc, int collisionClass) { @@ -209,297 +137,6 @@ void NpcHelper::mother_set_collision_class(Entity_NPC *npc, int collisionClass) return; } -// 00582f60 -void NpcHelper::scourge_whip(Entity_NPC *npc) -{ - uint8_t bVar1; - uint8_t *animNameCursor; - uint32_t uVar2; - Entity_NPC *segment; - uint8_t *targetNameCursor; - uint8_t *anim; - bool isLess; - Entity_NPC *local_c; - float pitch; - uint8_t *animData; - Manager *manager; - Entity_NPC *nextSegment; - - segment = npc; - while (((nextSegment = GHIDRA_CAST(segment->_child), nextSegment != GHIDRA_CAST(0x0) && - (nextSegment->_type == 0x38d)) && (nextSegment->_variant == 10))) { - segment = nextSegment; - } - segment->_state = 7; - (segment->_targetPosition).x = g_vectorZero.x; - (segment->_targetPosition).y = g_vectorZero.y; - segment = npc; - while (((nextSegment = GHIDRA_CAST(segment->_parent), nextSegment != GHIDRA_CAST(0x0) && - (nextSegment->_type == 0x38d)) && (nextSegment->_variant == 10))) { - segment = nextSegment; - } - animData = (segment->_sprite)._animState._animData; - anim = &DAT_00b62058; - if (npc->_subtype == 0) { - anim = &DAT_00b6208c; - } - local_c = npc; - if (animData != GHIDRA_CAST(0x0)) { - animNameCursor = animData; - if (0xf < *GHIDRA_CAST((animData + 0x14))) { - animNameCursor = *GHIDRA_CAST(animData); - } - targetNameCursor = anim; - do { - bVar1 = *animNameCursor; - isLess = bVar1 < *targetNameCursor; - if (bVar1 != *targetNameCursor) { -LAB_00583024: - uVar2 = -GHIDRA_UINT(isLess) | 1; - goto LAB_00583029; - } - if (bVar1 == 0) break; - bVar1 = animNameCursor[1]; - isLess = bVar1 < targetNameCursor[1]; - if (bVar1 != targetNameCursor[1]) goto LAB_00583024; - animNameCursor = animNameCursor + 2; - targetNameCursor = targetNameCursor + 2; - } while (bVar1 != 0); - uVar2 = 0; -LAB_00583029: - if ((uVar2 == 0) && ((animData[0x34] == 0 || ((segment->_sprite)._animState._isPlaying != 0)))) - goto LAB_00583051; - } - bVar1 = ANM2::SetAnimation(&segment->_sprite,anim,1); - if (bVar1 != 0) { - AnimationState::Rewind(&(segment->_sprite)._animState); - (segment->_sprite)._animState._isPlaying = 1; - } -LAB_00583051: - manager = g_manager; - pitch = 1.0; - if (local_c->_championColorIdx == 0x12) { - pitch = 1.5; - } - else if (local_c->_championColorIdx == 0x13) { - pitch = 0.5; - } - local_c = GHIDRA_CAST(0x48); - seed_fart_sound_override(GHIDRA_CAST(&local_c)); - (GHIDRA_CAST((&manager->_sfxManager)))->SoundEffects::Play(GHIDRA_INT(local_c),1.0,2,0,pitch,0.0); - return; -} - -// 00587480 -void NpcHelper::scourge_chain_shoot() -{ - Entity *pEVar1; - uint32_t rngResult; - Entity_NPC *in_ECX; - int chainEnd; - float fVar2; - float fVar3; - float fVar4; - float fVar5; - Vector effectPos; - Vector projVelocity; - float local_ec; - float local_e8; - Vector shootPos; - float local_dc; - float soundPitch; - float childChainOffsetY; - float childChainOffsetX; - float local_cc; - float local_c8; - float local_c4; - uint8_t projParams [4]; - float fStack_bc; - float fStack_b8; - float fStack_b4; - float fStack_b0; - float fStack_ac; - float fStack_a8; - float fStack_a4; - float fStack_a0; - float fStack_9c; - float fStack_98; - float fStack_94; - float fStack_90; - float fStack_8c; - float fStack_88; - float fStack_84; - float fStack_80; - float fStack_7c; - float fStack_78; - float afStack_74 [2]; - float fStack_6c; - uint32_t uStack_68; - uint32_t uStack_64; - float fStack_60; - float fStack_5c; - float fStack_58; - float fStack_54; - float fStack_50; - float fStack_4c; - float fStack_48; - int iStack_44; - uint64_t qStack_40; - float fStack_38; - int iStack_34; - float fStack_30; - int iStack_2c; - uint8_t local_28; - uint8_t *local_24; - uint32_t local_20; - uint8_t local_1c; - float local_14; - Manager *manager; - int nextSegment; - - local_14 = (float)(__security_cookie ^ GHIDRA_UINT((afStack_74 + 0x19))); - chainEnd = in_ECX->_child; - while (((nextSegment = *GHIDRA_CAST((chainEnd + 0x3c0)), nextSegment != 0 && - (*GHIDRA_CAST((nextSegment + 0x28)) == 0x38d)) && (*GHIDRA_CAST((nextSegment + 0x2c)) == 10))) { - chainEnd = nextSegment; - } - local_e8 = (in_ECX->_pos).x; - local_ec = (in_ECX->_pos).y; - childChainOffsetX = *GHIDRA_CAST((chainEnd + 0x33c)) - local_e8; - childChainOffsetY = *GHIDRA_CAST((chainEnd + 0x340)) - local_ec; - chainEnd = in_ECX->_entityRef; - while (((nextSegment = *GHIDRA_CAST((chainEnd + 0x3c0)), nextSegment != 0 && - (*GHIDRA_CAST((nextSegment + 0x28)) == 0x38d)) && (*GHIDRA_CAST((nextSegment + 0x2c)) == 10))) { - chainEnd = nextSegment; - } - local_e8 = *GHIDRA_CAST((chainEnd + 0x33c)) - local_e8; - local_ec = *GHIDRA_CAST((chainEnd + 0x340)) - local_ec; - pEVar1 = Entity_NPC::GetPlayerTarget(in_ECX); - local_c8 = local_e8 - childChainOffsetX; - local_cc = (pEVar1->_pos).y - (in_ECX->_pos).y; - local_dc = (pEVar1->_pos).x - (in_ECX->_pos).x; - local_c4 = local_ec - childChainOffsetY; - fVar2 = sqrtf(local_c4 * local_c4 + local_c8 * local_c8); - soundPitch = 1.0; - fVar3 = local_c8; - fVar4 = local_c4; - if (0.0 < fVar2) { - fVar3 = local_c8 * (1.0 / fVar2); - fVar4 = local_c4 * (1.0 / fVar2); - } - fVar2 = -childChainOffsetY * fVar4 - childChainOffsetX * fVar3; - fVar4 = fVar2 * fVar4 + childChainOffsetY; - fVar3 = fVar2 * fVar3 + childChainOffsetX; - fVar2 = fVar4 * local_cc; - local_cc = 0.0; - local_dc = (fVar2 + fVar3 * local_dc) / (fVar4 * fVar4 + fVar3 * fVar3); - do { - fVar3 = local_cc; - rngResult = Random(); - if (rngResult % 5 == 0) { - fVar4 = local_dc; - } - else { - rngResult = Random(); - fVar4 = (float)((double)GHIDRA_INT(rngResult) + __uint_to_double_fixup[-(GHIDRA_INT(rngResult) >> 0x1f)]) * - 2.3283064e-10; - } - shootPos.x = (in_ECX->_pos).x; - shootPos.y = (in_ECX->_pos).y; - fVar2 = childChainOffsetX * fVar4 + shootPos.x; - fVar5 = childChainOffsetY * fVar4 + shootPos.y; - shootPos.x = local_e8 * fVar4 + shootPos.x; - shootPos.y = local_ec * fVar4 + shootPos.y; - if (fVar3 == 0.0) { - local_c4 = fVar2 - shootPos.x; - local_c8 = fVar5 - shootPos.y; - } - else { - local_c4 = shootPos.x - fVar2; - local_c8 = shootPos.y - fVar5; - shootPos.x = fVar2; - shootPos.y = fVar5; - } - fVar3 = sqrtf(local_c4 * local_c4 + local_c8 * local_c8); - if (0.0 < fVar3) { - local_c4 = (1.0 / fVar3) * local_c4; - local_c8 = local_c8 * (1.0 / fVar3); - } - projParams[0] = 1; - fStack_bc = 0.0; - fStack_b8 = 0.0; - fStack_b4 = 0.0; - fStack_b0 = 1.0; - fStack_ac = 1.0; - rngResult = Random(); - fStack_60 = g_vectorZero.x; - fStack_58 = g_vectorZero.x; - fStack_50 = g_vectorZero.x; - fStack_48 = -1000.0; - iStack_44 = 0; - fStack_38 = 0.0; - iStack_34 = 0x1e; - fStack_5c = g_vectorZero.y; - fStack_54 = g_vectorZero.y; - fStack_4c = g_vectorZero.y; - fStack_30 = 0.0; - iStack_2c = 0; - local_28 = 0; - local_24 = &DAT_bf800000; - local_20 = 0; - local_1c = 0; - fStack_6c = DAT_00c34cf0; - uStack_68 = 0x2000; - fStack_a8 = (float)((double)GHIDRA_INT(rngResult) + __uint_to_double_fixup[-(GHIDRA_INT(rngResult) >> 0x1f)]) - * 2.3283064e-10 * 3.1415927; - uStack_64 = 0; - fStack_a4 = 1.0; - fStack_a0 = 0.005; - fStack_9c = 1.01; - fStack_98 = 1.0; - qStack_40 = 0; - fStack_bc = fStack_bc + 10.0; - fStack_b4 = fStack_b4 - 0.14; - fStack_94 = _DAT_00c34cc8; - fStack_90 = fRam00c34ccc; - fStack_8c = fRam00c34cd0; - fStack_88 = fRam00c34cd4; - fStack_84 = _DAT_00c34cd8; - fStack_80 = fRam00c34cdc; - fStack_7c = fRam00c34ce0; - fStack_78 = fRam00c34ce4; - afStack_74[0] = (float)DAT_00c34ce8; - afStack_74[1] = (*GHIDRA_CAST((GHIDRA_CAST(&(DAT_00c34ce8)) + 0x4))); - rngResult = Random(); - projVelocity.x = - (float)((double)GHIDRA_INT(rngResult) + __uint_to_double_fixup[-(GHIDRA_INT(rngResult) >> 0x1f)]) * - 2.3283064e-10 + 5.0; - projVelocity.y = projVelocity.x * local_c8; - projVelocity.x = projVelocity.x * local_c4; - Entity_NPC::FireProjectiles(in_ECX,&shootPos,&projVelocity,0,GHIDRA_CAST(projParams)); - effectPos.x = local_c4 * 4.0 + shootPos.x; - effectPos.y = local_c8 * 4.0 + shootPos.y; - rngResult = Random(); - pEVar1 = Game::Spawn(g_game,1000,2,&effectPos,&g_vectorZero,GHIDRA_CAST(0x0),1,rngResult); - (**(code **)(*GHIDRA_CAST(pEVar1) + 0x3c))(&g_colorGreenSplat,0xffffffff,0xff,0,1); - (pEVar1->_sprite)._offset.x = 0.0; - (pEVar1->_sprite)._offset.y = -20.0; - pEVar1->_renderDepthOffset = 10.0; - manager = g_manager; - local_cc = (float)(GHIDRA_INT(local_cc) + 1); - } while (GHIDRA_INT(local_cc) < 2); - if (in_ECX->_championColorIdx == 0x12) { - soundPitch = 1.5; - } - else if (in_ECX->_championColorIdx == 0x13) { - soundPitch = 0.5; - } - local_cc = 2.49431e-43; - seed_fart_sound_override(GHIDRA_CAST(&local_cc)); - (GHIDRA_CAST((&manager->_sfxManager)))->SoundEffects::Play(GHIDRA_INT(local_cc),1.0,2,0,soundPitch,0.0); - return; -} - // 0058ac10 void NpcHelper::singe_explode_at(Entity_NPC *npc, Vector *position) { diff --git a/generated-src/procedural_effect.cpp b/generated-src/procedural_effect.cpp deleted file mode 100644 index 9f22854..0000000 --- a/generated-src/procedural_effect.cpp +++ /dev/null @@ -1,623 +0,0 @@ -#include "classes.h" - -// 009e0700 -uint8_t ProceduralEffect::roll_trigger_target(uint32_t *outTarget, float *outChance, RNG *rng) -{ - code *pcVar1; - uint8_t bVar2; - uint32_t uVar3; - uint32_t rngValue; - EntityConfig *entityConfig; - void *foundNode; - int iVar4; - void *entitiesHead; - uint32_t rngValue; - uint16_t entryId; - int anyEntriesBegin; - int anyEntriesEnd; - int local_34; - int entriesEnd; - void *lowerBoundNode; - float *outChanceLocal; - uint32_t *outTargetLocal; - uint32_t fallbackCategory; - uint32_t entityType; - uint32_t entityKey; - uint32_t lookupKey; - void *local_10; - uint8_t *puStack_c; - uint32_t local_8; - RNG *rngLocal; - - rngLocal = rng; - local_8 = 0xffffffff; - puStack_c = &LAB_00b0f765; - local_10 = ExceptionList; - uVar3 = __security_cookie ^ GHIDRA_INT(register0x00000010) - 4U; - ExceptionList = &local_10; - rngValue = 0; - entryId = 0xffff; - rng = GHIDRA_CAST(0x0); - rngValue = rngLocal->_seed; - outChanceLocal = outChance; - outTargetLocal = outTarget; - if (rngValue == 0) { - KAGE_LogMessage(0x10,GHIDRA_CAST("RNG Seed is zero!\n")); - rngValue = rngLocal->_seed; - if (rngValue == 0) { - pcVar1 = (code *)swi(3); - bVar2 = (*pcVar1)(); - return bVar2; - } - } - rngValue = rngValue >> ((uint8_t)rngLocal->_shift1 & 0x1f) ^ rngValue; - rngValue = rngValue << ((uint8_t)rngLocal->_shift2 & 0x1f) ^ rngValue; - rngValue = rngValue >> ((uint8_t)rngLocal->_shift3 & 0x1f) ^ rngValue; - rngLocal->_seed = rngValue; - switch(rngValue % 6) { - case 0: - rngValue = 2; - rng = GHIDRA_CAST(0x3c23d70a); - rngValue = (GHIDRA_CAST((rngLocal)))->RNG::RandomInt(3); - if (rngValue != 0) { -LAB_009e0a8b: - rng = GHIDRA_CAST(0x3c23d70a); - goto LAB_009e080a; - } - FUN_00694f00(&local_34,2); - local_8 = 0; - iVar4 = GHIDRA_INT(((uint64_t)((int64_t)(entriesEnd - local_34) * 0xb60b60b7) >> 0x20)); - break; - case 1: - rngValue = 9; - rng = GHIDRA_CAST(0x3c23d70a); - rngValue = (GHIDRA_CAST((rngLocal)))->RNG::RandomInt(3); - if (rngValue != 0) goto LAB_009e0a8b; - FUN_00694f00(&local_34,9); - local_8 = 1; - iVar4 = GHIDRA_INT(((uint64_t)((int64_t)(entriesEnd - local_34) * 0xb60b60b7) >> 0x20)); - break; - case 2: - rngValue = 5; - rng = GHIDRA_CAST(0x3f800000); - rngValue = (GHIDRA_CAST((rngLocal)))->RNG::RandomInt(4); - if (rngValue == 0) { - rng = GHIDRA_CAST(0x3f800000); - goto LAB_009e080a; - } - FUN_00694f00(&local_34,5); - local_8 = 2; - iVar4 = GHIDRA_INT(((uint64_t)((int64_t)(entriesEnd - local_34) * 0xb60b60b7) >> 0x20)); - break; - case 3: - rng = GHIDRA_CAST(0x3ca3d70a); - rngValue = 4; - goto LAB_009e080a; - case 4: - fallbackCategory = 999; - rngValue = (GHIDRA_CAST((rngLocal)))->RNG::RandomInt(4); - if (rngValue == 0) { - rngValue = rngLocal->_seed; - rngValue = 0; - do { - if (rngValue == 0) { - KAGE_LogMessage(0x10,GHIDRA_CAST("RNG Seed is zero!\n")); - rngValue = rngLocal->_seed; - if (rngValue == 0) { - pcVar1 = (code *)swi(3); - bVar2 = (*pcVar1)(); - return bVar2; - } - } - rngValue = rngValue >> ((uint8_t)rngLocal->_shift1 & 0x1f) ^ rngValue; - rngValue = rngValue << ((uint8_t)rngLocal->_shift2 & 0x1f) ^ rngValue; - rngValue = rngValue >> ((uint8_t)rngLocal->_shift3 & 0x1f) ^ rngValue; - rngLocal->_seed = rngValue; - entityConfig = &g_manager->_entityConfig; - entityType = rngValue % 0x3de + 10; - entityKey = entityType * 0x100000; - lookupKey = entityKey; - _Find_lower_bound<>(&local_34,&lookupKey); - if ((*GHIDRA_CAST((GHIDRA_CAST(lowerBoundNode) + 0xd)) == '\0') && - (*GHIDRA_CAST((GHIDRA_CAST(lowerBoundNode) + 0x10)) <= entityKey)) { - foundNode = lowerBoundNode; - entitiesHead = (entityConfig->_entities)._head; - } - else { - foundNode = (entityConfig->_entities)._head; - entitiesHead = foundNode; - } - iVar4 = GHIDRA_INT(foundNode) + 0x18; - if (foundNode == entitiesHead) { - iVar4 = 0; - } - if ((iVar4 != 0) && (*GHIDRA_CAST((iVar4 + 0x2c)) == '\0')) { - entryId = 0xffff; - rng = GHIDRA_CAST(0x3ca3d70a); - rngValue = entityType & 0xffff; - goto LAB_009e080a; - } - rngValue = rngValue + 1; - } while (rngValue < 100); - entryId = 0xffff; - rng = GHIDRA_CAST(0x3ca3d70a); - rngValue = fallbackCategory; - } - else { - rng = GHIDRA_CAST(0x3ca3d70a); - rngValue = 999; - entryId = 0xffff; - } - goto LAB_009e080a; - case 5: - FUN_00694f00(&anyEntriesBegin,1000); - local_8 = 3; - rngValue = (GHIDRA_CAST((rngLocal)))->RNG::RandomInt((anyEntriesEnd - anyEntriesBegin) / 0x168); - entryId = *GHIDRA_CAST((rngValue * 0x168 + 4 + anyEntriesBegin)); - msvc::vector::_Tidy(uVar3); - rng = GHIDRA_CAST(0x3ca3d70a); - rngValue = 1000; - goto LAB_009e080a; - default: - goto switchD_009e0787_default; - } - rngValue = (GHIDRA_CAST((rngLocal)))->RNG::RandomInt((iVar4 >> 8) - (iVar4 >> 0x1f)); - entryId = *GHIDRA_CAST((rngValue * 0x168 + 4 + local_34)); - msvc::vector::_Tidy(); -switchD_009e0787_default: -LAB_009e080a: - *outTargetLocal = rngValue << 0x10 | GHIDRA_UINT(entryId); - *outChanceLocal = (float)rng; - if ((float)rng == 0.0) { - ExceptionList = local_10; - return 0; - } - ExceptionList = local_10; - return 1; -} - -// 009e0ad0 -uint8_t ProceduralEffect::roll_spawn_target(uint32_t *outTarget, float *outChance, RNG *rng) -{ - uint8_t bVar1; - uint32_t uVar2; - uint32_t uVar3; - uint32_t configNode; - EntityConfig *entityConfig; - void *foundNode; - int iVar4; - void *endNode; - int iStack_38; - int iStack_34; - void *pvStack_30; - float *outChanceRef; - uint32_t *outTargetRef; - uint32_t local_24; - uint32_t local_20; - uint32_t local_1c; - uint32_t entityType; - float local_14; - void *local_10; - uint8_t *puStack_c; - uint32_t uStack_8; - code *debugBreak; - Manager *manager; - - uStack_8 = 0xffffffff; - puStack_c = &LAB_00b0f7ad; - local_10 = ExceptionList; - uVar2 = __security_cookie ^ GHIDRA_INT(register0x00000010) - 4U; - ExceptionList = &local_10; - entityType = 0; - local_24 = 0; - local_14 = 0.0; - uVar3 = rng->_seed; - outChanceRef = outChance; - outTargetRef = outTarget; - if (uVar3 == 0) { - KAGE_LogMessage(0x10,GHIDRA_CAST("RNG Seed is zero!\n")); - uVar3 = rng->_seed; - if (uVar3 == 0) { - debugBreak = (code *)swi(3); - bVar1 = (*debugBreak)(); - return bVar1; - } - } - uVar3 = uVar3 >> ((uint8_t)rng->_shift1 & 0x1f) ^ uVar3; - uVar3 = uVar3 << ((uint8_t)rng->_shift2 & 0x1f) ^ uVar3; - uVar3 = uVar3 >> ((uint8_t)rng->_shift3 & 0x1f) ^ uVar3; - rng->_seed = uVar3; - manager = g_manager; - if ((uVar3 & 7) == 0) { - local_20 = 10; - do { - uVar2 = rng->_seed; - uVar3 = (manager->_entityConfig)._entities._size; - if (uVar2 == 0) { - KAGE_LogMessage(0x10,GHIDRA_CAST("RNG Seed is zero!\n")); - uVar2 = rng->_seed; - if (uVar2 == 0) { - debugBreak = (code *)swi(3); - bVar1 = (*debugBreak)(); - return bVar1; - } - } - uVar2 = uVar2 >> ((uint8_t)rng->_shift1 & 0x1f) ^ uVar2; - uVar2 = uVar2 << ((uint8_t)rng->_shift2 & 0x1f) ^ uVar2; - uVar2 = uVar2 >> ((uint8_t)rng->_shift3 & 0x1f) ^ uVar2; - rng->_seed = uVar2; - if (uVar3 == 0) { - configNode = *GHIDRA_CAST((manager->_entityConfig)._entities._head); - } - else { - uVar3 = uVar2 % uVar3; - local_1c = *GHIDRA_CAST((manager->_entityConfig)._entities._head); - configNode = local_1c; - if (uVar3 != 0) { - do { - msvc:: - _Tree_unchecked_const_iterator_>,msvc::_Iterator_base0> - ::operator++((_Tree_unchecked_const_iterator_>,msvc::_Iterator_base0> - *)&local_1c); - uVar3 = uVar3 - 1; - } while (uVar3 != 0); - configNode = local_1c; - } - } - uVar3 = *GHIDRA_CAST((configNode + 0x18)) & 0xffff; - if ((*GHIDRA_CAST((configNode + 0x18)) != 1) && (*GHIDRA_CAST((configNode + 0x44)) == '\0')) { - local_24 = GHIDRA_UINT(*GHIDRA_CAST((configNode + 0x1c))); - entityType = uVar3; - if (uVar2 == 0) { - KAGE_LogMessage(0x10,GHIDRA_CAST("RNG Seed is zero!\n")); - uVar2 = rng->_seed; - if (uVar2 == 0) { - debugBreak = (code *)swi(3); - bVar1 = (*debugBreak)(); - return bVar1; - } - } - uVar2 = uVar2 >> ((uint8_t)rng->_shift1 & 0x1f) ^ uVar2; - uVar2 = uVar2 << ((uint8_t)rng->_shift2 & 0x1f) ^ uVar2; - uVar2 = uVar2 >> ((uint8_t)rng->_shift3 & 0x1f) ^ uVar2; - rng->_seed = uVar2; - local_14 = (float)((double)GHIDRA_INT(uVar2) + __uint_to_double_fixup[-(GHIDRA_INT(uVar2) >> 0x1f)]) * - 2.3283062e-10 + 0.1; - } - local_20 = local_20 + -1; - } while (local_20 != 0); - uVar3 = local_24; - } - else { - if (uVar3 == 0) { - KAGE_LogMessage(0x10,GHIDRA_CAST("RNG Seed is zero!\n")); - uVar3 = rng->_seed; - if (uVar3 == 0) { - debugBreak = (code *)swi(3); - bVar1 = (*debugBreak)(); - return bVar1; - } - } - uVar3 = uVar3 >> ((uint8_t)rng->_shift1 & 0x1f) ^ uVar3; - uVar3 = uVar3 << ((uint8_t)rng->_shift2 & 0x1f) ^ uVar3; - uVar3 = uVar3 >> ((uint8_t)rng->_shift3 & 0x1f) ^ uVar3; - rng->_seed = uVar3; - switch(uVar3 & 3) { - case 0: - FUN_00694f00(&iStack_38,2); - uStack_8 = 0; - uVar3 = (GHIDRA_CAST((rng)))->RNG::RandomInt((iStack_34 - iStack_38) / 0x168); - uVar3 = GHIDRA_UINT(*GHIDRA_CAST((uVar3 * 0x168 + 4 + iStack_38))); - msvc::vector::_Tidy(uVar2); - local_14 = 0.01; - entityType = 2; - break; - case 1: - local_14 = 1.0; - entityType = 5; - uVar3 = 0; - uVar2 = (GHIDRA_CAST((rng)))->RNG::RandomInt(4); - if (uVar2 == 0) { - local_14 = 1.0; - entityType = 5; - } - else { - FUN_00694f00(&iStack_38,5); - uStack_8 = 1; - uVar3 = (GHIDRA_CAST((rng)))->RNG::RandomInt((iStack_34 - iStack_38) / 0x168); - uVar3 = GHIDRA_UINT(*GHIDRA_CAST((uVar3 * 0x168 + 4 + iStack_38))); - msvc::vector::_Tidy(); - } - break; - case 2: - FUN_00694f00(&iStack_38,4); - uStack_8 = 2; - uVar3 = (GHIDRA_CAST((rng)))->RNG::RandomInt((iStack_34 - iStack_38) / 0x168); - uVar3 = GHIDRA_UINT(*GHIDRA_CAST((uVar3 * 0x168 + 4 + iStack_38))); - msvc::vector::_Tidy(); - local_14 = 0.02; - entityType = 4; - break; - case 3: - uVar2 = 0; - entityType = 10; - local_14 = 0.02; - do { - if (uVar3 == 0) { - KAGE_LogMessage(0x10,GHIDRA_CAST("RNG Seed is zero!\n")); - uVar3 = rng->_seed; - if (uVar3 == 0) { - debugBreak = (code *)swi(3); - bVar1 = (*debugBreak)(); - return bVar1; - } - } - uVar3 = uVar3 >> ((uint8_t)rng->_shift1 & 0x1f) ^ uVar3; - uVar3 = uVar3 << ((uint8_t)rng->_shift2 & 0x1f) ^ uVar3; - uVar3 = uVar3 >> ((uint8_t)rng->_shift3 & 0x1f) ^ uVar3; - rng->_seed = uVar3; - entityConfig = &g_manager->_entityConfig; - local_1c = uVar3 % 0x3de + 10; - local_24 = local_1c * 0x100000; - local_20 = local_24; - _Find_lower_bound<>(&iStack_38,&local_24); - if ((*GHIDRA_CAST((GHIDRA_CAST(pvStack_30) + 0xd)) == '\0') && - (*GHIDRA_CAST((GHIDRA_CAST(pvStack_30) + 0x10)) <= local_20)) { - foundNode = pvStack_30; - endNode = (entityConfig->_entities)._head; - } - else { - foundNode = (entityConfig->_entities)._head; - endNode = foundNode; - } - iVar4 = GHIDRA_INT(foundNode) + 0x18; - if (foundNode == endNode) { - iVar4 = 0; - } - if ((iVar4 != 0) && (*GHIDRA_CAST((iVar4 + 0x2c)) == '\0')) { - uVar3 = 0; - entityType = local_1c & 0xffff; - goto LAB_009e0eea; - } - uVar2 = uVar2 + 1; - } while (uVar2 < 10); - uVar3 = 0; - } - } -LAB_009e0eea: - *outTargetRef = entityType << 0x10 | uVar3 & 0xffff; - *outChanceRef = local_14; - if (local_14 == 0.0) { - ExceptionList = local_10; - return 0; - } - ExceptionList = local_10; - return 1; -} - -// 009e0f60 -void ProceduralEffect::roll_params(int conditionType, int actionType, uint32_t seed) -{ - code *pcVar1; - ItemConfig_Item *collectibleConfig; - uint32_t uVar2; - BitSet128 *nonLudovicoFlags; - uint32_t uVar3; - int iVar4; - uint32_t uVar5; - uint32_t uVar6; - uint32_t uVar7; - float fVar8; - ColorMod randomColor; - BitSet128 nonLudovicoFlagsBuf; - RNG rng; - float local_24; - float offsetBlue; - float offsetGreen; - float offsetRed; - float colorizeAmount; - float colorizeBlue; - float colorizeGreen; - Game *game; - int proceduralItem; - - uVar3 = seed; - rng._seed = seed; - rng._shift1 = 0xd; - rng._shift2 = 3; - *GHIDRA_CAST(this) = conditionType; - *GHIDRA_CAST((GHIDRA_CAST(this) + 4)) = actionType; - *GHIDRA_CAST((GHIDRA_CAST(this) + 8)) = seed; - rng._shift3 = 0x11; - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x60)) = 0; - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x10)) = 0; - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x14)) = 0; - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x18)) = 0; - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x1c)) = 0; - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x20)) = 0; - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x24)) = 0; - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x28)) = 0; - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x2c)) = 0; - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x30)) = 0x3f800000; - game = g_game; - switch(actionType) { - case 0: - uVar3 = (GHIDRA_CAST((&rng)))->RNG::RandomInt(*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&((g_game->_proceduralItemManager))) + 0x20)))) - - *GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&((g_game->_proceduralItemManager))) + 0x1c)))) >> 2); - proceduralItem = *GHIDRA_CAST((*GHIDRA_CAST(&(*GHIDRA_CAST((GHIDRA_CAST(&((game->_proceduralItemManager))) + 0x1c)))) + uVar3 * 4)); - if (*GHIDRA_CAST((proceduralItem + 0xac)) == 1) { - fVar8 = (float)*GHIDRA_CAST((proceduralItem + 0xc0)); -LAB_009e1045: - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x60)) = fVar8; - } - else if (*GHIDRA_CAST((proceduralItem + 0xac)) == 0) { - fVar8 = (float)*GHIDRA_CAST((proceduralItem + 0x74)) * 0.5 + 1.0; - goto LAB_009e1045; - } - iVar4 = *GHIDRA_CAST((proceduralItem + 4)); - if (iVar4 == 0x2c0) { - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x60)) = *GHIDRA_CAST((GHIDRA_CAST(this) + 0x60)) + 6.0; - iVar4 = *GHIDRA_CAST((proceduralItem + 4)); - } - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x10)) = iVar4; - break; - case 1: - seed = 0; - do { - uVar7 = GHIDRA_INT((g_manager->_itemConfig)._collectibles._end) - - GHIDRA_INT((g_manager->_itemConfig)._collectibles._begin) >> 2; - if (uVar3 == 0) { - KAGE_LogMessage(0x10,GHIDRA_CAST("RNG Seed is zero!\n")); - pcVar1 = (code *)swi(3); - (*pcVar1)(); - return; - } - rng._seed = GHIDRA_UINT(rng._seed) >> ((uint8_t)rng._shift1 & 0x1f) ^ rng._seed; - rng._seed = rng._seed << ((uint8_t)rng._shift2 & 0x1f) ^ rng._seed; - uVar3 = GHIDRA_UINT(rng._seed) >> ((uint8_t)rng._shift3 & 0x1f) ^ rng._seed; - uVar6 = 0; - if (uVar7 != 0) { - uVar6 = uVar3 % uVar7; - } - rng._seed = uVar3; - collectibleConfig = ItemConfig::GetCollectible(&g_manager->_itemConfig,uVar6); - if (collectibleConfig != GHIDRA_CAST(0x0)) { - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x10)) = uVar6; - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x60)) = 0x3f800000; - break; - } - seed = seed + 1; - } while (GHIDRA_INT(seed) < 10); - break; - case 2: - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x18)) = 0x447a0000; - roll_trigger_target(GHIDRA_CAST((GHIDRA_INT(this) + 0x10)),GHIDRA_CAST(&seed),&rng); - roll_spawn_target(GHIDRA_CAST((GHIDRA_INT(this) + 0x14)),GHIDRA_CAST(&conditionType),&rng); - if (0.0 < (float)seed) { - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x60)) = (float)conditionType / (float)seed; - } - else { - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x60)) = 0x461c4000; - } - break; - case 3: - seed = GHIDRA_UINT((GHIDRA_CAST((&rng)))->RNG)::RandomFloat(); - fVar8 = (GHIDRA_CAST((&rng)))->RNG::RandomFloat(); - conditionType = GHIDRA_INT((fVar8 * (float)seed)); - seed = GHIDRA_UINT((GHIDRA_CAST((&rng)))->RNG)::RandomFloat(); - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x18)) = (float)seed * (float)conditionType * 8000.0 + 30.0; - fVar8 = (GHIDRA_CAST((&rng)))->RNG::RandomFloat(); - seed = GHIDRA_UINT((fVar8 - 0.2)); - fVar8 = (GHIDRA_CAST((&rng)))->RNG::RandomFloat(); - seed = GHIDRA_UINT((fVar8 * (float)seed * 80.0)); - fVar8 = (float)seed; - if ((float)seed <= 0.0) { - fVar8 = 0.0; - } - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x1c)) = fVar8; - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x60)) = fVar8 * 0.1; - if ((fVar8 < 0.0) || (uVar3 = (GHIDRA_CAST((&rng)))->RNG::RandomInt(3), uVar3 == 0)) { - seed = 100; - if (*GHIDRA_CAST((GHIDRA_CAST(this) + 0x1c)) <= 5.0 && *GHIDRA_CAST((GHIDRA_CAST(this) + 0x1c)) != 5.0) { - seed = 0x14; - } - uVar7 = 0; - uVar3 = rng._seed; - do { - if (uVar3 == 0) { - KAGE_LogMessage(0x10,GHIDRA_CAST("RNG Seed is zero!\n")); - pcVar1 = (code *)swi(3); - (*pcVar1)(); - return; - } - uVar3 = uVar3 >> ((uint8_t)rng._shift1 & 0x1f) ^ uVar3; - uVar3 = uVar3 << ((uint8_t)rng._shift2 & 0x1f) ^ uVar3; - uVar3 = uVar3 >> ((uint8_t)rng._shift3 & 0x1f) ^ uVar3; - if (uVar3 % seed == 0) { - if (uVar7 < 0x40) { - uVar6 = 1 << (uVar7 & 0x1f); - uVar2 = 0; - if (0x1f < uVar7) { - uVar2 = uVar6; - } - uVar6 = uVar6 ^ uVar2; - if (0x3f < uVar7) { - uVar2 = uVar6; - } - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x20)) = *GHIDRA_CAST((GHIDRA_CAST(this) + 0x20)) | uVar6; - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x24)) = *GHIDRA_CAST((GHIDRA_CAST(this) + 0x24)) | uVar2; - } - else { - uVar6 = uVar7 - 0x40; - uVar2 = 1 << (uVar6 & 0x1f); - uVar5 = 0; - if (0x1f < uVar6) { - uVar5 = uVar2; - } - uVar2 = uVar2 ^ uVar5; - if (0x3f < uVar6) { - uVar5 = uVar2; - } - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x28)) = *GHIDRA_CAST((GHIDRA_CAST(this) + 0x28)) | uVar2; - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x2c)) = *GHIDRA_CAST((GHIDRA_CAST(this) + 0x2c)) | uVar5; - } - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x60)) = *GHIDRA_CAST((GHIDRA_CAST(this) + 0x60)) + 0.4; - } - uVar7 = uVar7 + 1; - } while (uVar7 < 0x80); - rng._seed = uVar3; - nonLudovicoFlags = (GHIDRA_CAST((&g_tearFlagLudovico)))->BitSet128::__bnot(&nonLudovicoFlagsBuf); - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x20)) = *GHIDRA_CAST((GHIDRA_CAST(this) + 0x20)) & GHIDRA_UINT(nonLudovicoFlags->_l); - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x24)) = - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x24)) & *GHIDRA_CAST((GHIDRA_INT(&nonLudovicoFlags->_l) + 4)); - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x28)) = *GHIDRA_CAST((GHIDRA_CAST(this) + 0x28)) & GHIDRA_UINT(nonLudovicoFlags->_h); - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x2c)) = - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x2c)) & *GHIDRA_CAST((GHIDRA_INT(&nonLudovicoFlags->_h) + 4)); - } - break; - case 4: - roll_spawn_target(GHIDRA_CAST((GHIDRA_INT(this) + 0x10)),GHIDRA_CAST(&actionType),&rng); - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x60)) = (float)actionType * 100.0; - break; - case 5: - fVar8 = (GHIDRA_CAST((&rng)))->RNG::RandomFloat(); - seed = GHIDRA_UINT((fVar8 * 10.0 + 5.0)); - fVar8 = (GHIDRA_CAST((&rng)))->RNG::RandomFloat(); - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x60)) = 0x3f800000; - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x1c)) = fVar8 * 10.0 + (float)seed; - uVar3 = (GHIDRA_CAST((&rng)))->RNG::RandomInt(10); - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x10)) = uVar3; - uVar3 = (GHIDRA_CAST((&rng)))->RNG::RandomInt(4); - if (uVar3 == 0) { - offsetBlue = (GHIDRA_CAST((&rng)))->RNG::RandomFloat(); - offsetGreen = (GHIDRA_CAST((&rng)))->RNG::RandomFloat(); - offsetRed = (GHIDRA_CAST((&rng)))->RNG::RandomFloat(); - colorizeAmount = (GHIDRA_CAST((&rng)))->RNG::RandomFloat(); - colorizeBlue = (GHIDRA_CAST((&rng)))->RNG::RandomFloat(); - colorizeGreen = (GHIDRA_CAST((&rng)))->RNG::RandomFloat(); - actionType = GHIDRA_INT((GHIDRA_CAST((&rng)))->RNG)::RandomFloat(); - conditionType = GHIDRA_INT((GHIDRA_CAST((&rng)))->RNG)::RandomFloat(); - seed = GHIDRA_UINT((GHIDRA_CAST((&rng)))->RNG)::RandomFloat(); - randomColor._tint[0] = (GHIDRA_CAST((&rng)))->RNG::RandomFloat(); - randomColor._tint[1] = (float)seed; - randomColor._tint[2] = (float)conditionType; - randomColor._colorize[0] = (float)actionType; - randomColor._colorize[1] = colorizeGreen; - randomColor._colorize[2] = colorizeBlue; - randomColor._colorize[3] = colorizeAmount; - randomColor._offset[0] = offsetRed; - randomColor._offset[1] = offsetGreen; - randomColor._tint[3] = 1.0; - randomColor._offset[2] = offsetBlue; - (GHIDRA_CAST((GHIDRA_CAST((GHIDRA_INT(this) + 0x34)))))->Color::operator_assign(&randomColor); - } - } - if ((*GHIDRA_CAST(this) == 6) && - (roll_trigger_target(GHIDRA_CAST((GHIDRA_INT(this) + 0xc)),&local_24,&rng), 0.0 < local_24)) { - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x60)) = *GHIDRA_CAST((GHIDRA_CAST(this) + 0x60)) / local_24; - } - if (*GHIDRA_CAST(this) == 1) { - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x60)) = *GHIDRA_CAST((GHIDRA_CAST(this) + 0x60)) * 10.0; - } - return; -} diff --git a/generated-src/rebirth_save_data.cpp b/generated-src/rebirth_save_data.cpp deleted file mode 100644 index 0a68e4d..0000000 --- a/generated-src/rebirth_save_data.cpp +++ /dev/null @@ -1,346 +0,0 @@ -#include "classes.h" - -// 009e3dc0 -void RebirthSaveData::Clear() -{ - uint16_t *in_ECX; - int wordsLeft; - uint32_t *clearPtr; - - *GHIDRA_CAST((in_ECX + 0x250)) = 0; - *GHIDRA_CAST((in_ECX + 0x252)) = 0; - memset(in_ECX + 0x1c,0,0xb3); - memset(in_ECX + 0x134,0,0x15b); - clearPtr = GHIDRA_CAST((in_ECX + 0x76)); - for (wordsLeft = 0x5f; wordsLeft != 0; wordsLeft = wordsLeft + -1) { - *clearPtr = 0; - clearPtr = clearPtr + 1; - } - *GHIDRA_CAST((in_ECX + 0x1e2)) = 0; - *GHIDRA_CAST((in_ECX + 0x1e4)) = 0; - *GHIDRA_CAST((in_ECX + 0x1e6)) = 0; - *GHIDRA_CAST((in_ECX + 0x1e8)) = 0; - *GHIDRA_CAST((in_ECX + 0x1ea)) = 0; - *GHIDRA_CAST((in_ECX + 0x1ec)) = 0; - *GHIDRA_CAST((in_ECX + 0x1ee)) = 0; - *GHIDRA_CAST((in_ECX + 0x1f0)) = 0; - *GHIDRA_CAST((in_ECX + 0x1f2)) = 0; - *GHIDRA_CAST((in_ECX + 500)) = 0; - *GHIDRA_CAST((in_ECX + 0x1f6)) = 0; - *GHIDRA_CAST((in_ECX + 0x1f8)) = 0; - *GHIDRA_CAST((in_ECX + 0x1fa)) = 0; - in_ECX[0x1fc] = 0; - *GHIDRA_CAST((in_ECX + 0x1fd)) = 0; - memset((void *)(GHIDRA_INT(in_ECX) + 0x3fb),0,0x39); - *GHIDRA_CAST((in_ECX + 0x21a)) = 0; - *GHIDRA_CAST((in_ECX + 0x21c)) = 0; - *GHIDRA_CAST((in_ECX + 0x21e)) = 0; - *GHIDRA_CAST((in_ECX + 0x220)) = 0; - *GHIDRA_CAST((in_ECX + 0x222)) = 0; - *GHIDRA_CAST((in_ECX + 0x224)) = 0; - *GHIDRA_CAST((in_ECX + 0x226)) = 0; - *GHIDRA_CAST((in_ECX + 0x228)) = 0; - *GHIDRA_CAST((in_ECX + 0x22a)) = 0; - *GHIDRA_CAST((in_ECX + 0x22c)) = 0; - *GHIDRA_CAST((in_ECX + 0x22e)) = 0; - *GHIDRA_CAST((in_ECX + 0x230)) = 0; - *GHIDRA_CAST((in_ECX + 0x232)) = 0; - *GHIDRA_CAST((in_ECX + 0x234)) = 0; - *GHIDRA_CAST((in_ECX + 0x236)) = 0; - *GHIDRA_CAST((in_ECX + 0x238)) = 0; - *GHIDRA_CAST((in_ECX + 0x23a)) = 0; - *GHIDRA_CAST((in_ECX + 0x23c)) = 0; - *GHIDRA_CAST((in_ECX + 0x23e)) = 0; - *GHIDRA_CAST((in_ECX + 0x240)) = 0; - *GHIDRA_CAST((in_ECX + 0x242)) = 0; - *GHIDRA_CAST((in_ECX + 0x244)) = 0; - *GHIDRA_CAST((in_ECX + 0x246)) = 0; - *GHIDRA_CAST((in_ECX + 0x248)) = 0; - *GHIDRA_CAST((in_ECX + 0x24a)) = 0; - *GHIDRA_CAST((in_ECX + 0x24c)) = 0; - *GHIDRA_CAST((in_ECX + 0x24e)) = 0; - *in_ECX = 0; - return; -} - -// 009e4af0 -void RebirthSaveData::repair_counters() -{ - int *piVar1; - int *piVar2; - int minValue; - int clampedValue; - int progressCount; - - progressCount = *GHIDRA_CAST((GHIDRA_CAST(this) + 0xf0)); - if (*GHIDRA_CAST((GHIDRA_CAST(this) + 0x3c)) != '\0') { - minValue = 1; - piVar1 = &minValue; - if (1 < *GHIDRA_CAST((GHIDRA_CAST(this) + 0x458))) { - piVar1 = GHIDRA_CAST((GHIDRA_INT(this) + 0x458)); - } - piVar2 = GHIDRA_CAST((GHIDRA_INT(this) + 0x454)); - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x458)) = *piVar1; - minValue = 1; - piVar1 = &minValue; - if (1 < *piVar2) { - piVar1 = piVar2; - } - clampedValue = *piVar1; - *piVar2 = clampedValue; - piVar1 = &minValue; - if (1 < clampedValue) { - piVar1 = piVar2; - } - minValue = 1; - clampedValue = *piVar1; - *piVar2 = clampedValue; - piVar1 = &minValue; - if (1 < clampedValue) { - piVar1 = piVar2; - } - minValue = 1; - *piVar2 = *piVar1; - } - if (0 < progressCount) { - minValue = 1; - piVar1 = &minValue; - if (1 < *GHIDRA_CAST((GHIDRA_CAST(this) + 0x45c))) { - piVar1 = GHIDRA_CAST((GHIDRA_INT(this) + 0x45c)); - } - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x45c)) = *piVar1; - piVar1 = GHIDRA_CAST((GHIDRA_INT(this) + 0x454)); - minValue = 1; - piVar2 = &minValue; - if (1 < *piVar1) { - piVar2 = piVar1; - } - *piVar1 = *piVar2; - if (1 < progressCount) { - minValue = 1; - piVar1 = &minValue; - if (1 < *GHIDRA_CAST((GHIDRA_CAST(this) + 0x460))) { - piVar1 = GHIDRA_CAST((GHIDRA_INT(this) + 0x460)); - } - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x460)) = *piVar1; - piVar1 = GHIDRA_CAST((GHIDRA_INT(this) + 0x454)); - minValue = 1; - piVar2 = &minValue; - if (1 < *piVar1) { - piVar2 = piVar1; - } - *piVar1 = *piVar2; - if (2 < progressCount) { - minValue = 1; - piVar1 = &minValue; - if (1 < *GHIDRA_CAST((GHIDRA_CAST(this) + 0x464))) { - piVar1 = GHIDRA_CAST((GHIDRA_INT(this) + 0x464)); - } - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x464)) = *piVar1; - piVar1 = GHIDRA_CAST((GHIDRA_INT(this) + 0x454)); - minValue = 1; - piVar2 = &minValue; - if (1 < *piVar1) { - piVar2 = piVar1; - } - *piVar1 = *piVar2; - if (3 < progressCount) { - minValue = 1; - piVar1 = &minValue; - if (1 < *GHIDRA_CAST((GHIDRA_CAST(this) + 0x468))) { - piVar1 = GHIDRA_CAST((GHIDRA_INT(this) + 0x468)); - } - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x468)) = *piVar1; - piVar1 = GHIDRA_CAST((GHIDRA_INT(this) + 0x454)); - minValue = 1; - piVar2 = &minValue; - if (1 < *piVar1) { - piVar2 = piVar1; - } - *piVar1 = *piVar2; - if (4 < progressCount) { - minValue = 1; - piVar1 = &minValue; - if (1 < *GHIDRA_CAST((GHIDRA_CAST(this) + 0x46c))) { - piVar1 = GHIDRA_CAST((GHIDRA_INT(this) + 0x46c)); - } - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x46c)) = *piVar1; - piVar1 = GHIDRA_CAST((GHIDRA_INT(this) + 0x454)); - minValue = 1; - piVar2 = &minValue; - if (1 < *piVar1) { - piVar2 = piVar1; - } - *piVar1 = *piVar2; - if (5 < progressCount) { - minValue = 1; - piVar1 = &minValue; - if (1 < *GHIDRA_CAST((GHIDRA_CAST(this) + 0x470))) { - piVar1 = GHIDRA_CAST((GHIDRA_INT(this) + 0x470)); - } - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x470)) = *piVar1; - piVar1 = GHIDRA_CAST((GHIDRA_INT(this) + 0x454)); - minValue = 1; - piVar2 = &minValue; - if (1 < *piVar1) { - piVar2 = piVar1; - } - *piVar1 = *piVar2; - if (6 < progressCount) { - minValue = 1; - piVar1 = &minValue; - if (1 < *GHIDRA_CAST((GHIDRA_CAST(this) + 0x474))) { - piVar1 = GHIDRA_CAST((GHIDRA_INT(this) + 0x474)); - } - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x474)) = *piVar1; - piVar1 = GHIDRA_CAST((GHIDRA_INT(this) + 0x454)); - minValue = 1; - piVar2 = &minValue; - if (1 < *piVar1) { - piVar2 = piVar1; - } - *piVar1 = *piVar2; - if (7 < progressCount) { - minValue = 1; - piVar1 = &minValue; - if (1 < *GHIDRA_CAST((GHIDRA_CAST(this) + 0x478))) { - piVar1 = GHIDRA_CAST((GHIDRA_INT(this) + 0x478)); - } - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x478)) = *piVar1; - piVar1 = GHIDRA_CAST((GHIDRA_INT(this) + 0x454)); - minValue = 1; - piVar2 = &minValue; - if (1 < *piVar1) { - piVar2 = piVar1; - } - *piVar1 = *piVar2; - if (8 < progressCount) { - minValue = 1; - piVar1 = &minValue; - if (1 < *GHIDRA_CAST((GHIDRA_CAST(this) + 0x47c))) { - piVar1 = GHIDRA_CAST((GHIDRA_INT(this) + 0x47c)); - } - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x47c)) = *piVar1; - piVar1 = GHIDRA_CAST((GHIDRA_INT(this) + 0x454)); - minValue = 1; - piVar2 = &minValue; - if (1 < *piVar1) { - piVar2 = piVar1; - } - *piVar1 = *piVar2; - if (9 < progressCount) { - minValue = 1; - piVar1 = &minValue; - if (1 < *GHIDRA_CAST((GHIDRA_CAST(this) + 0x480))) { - piVar1 = GHIDRA_CAST((GHIDRA_INT(this) + 0x480)); - } - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x480)) = *piVar1; - piVar1 = GHIDRA_CAST((GHIDRA_INT(this) + 0x454)); - minValue = 1; - piVar2 = &minValue; - if (1 < *piVar1) { - piVar2 = piVar1; - } - *piVar1 = *piVar2; - if (10 < progressCount) { - minValue = 1; - piVar1 = &minValue; - if (1 < *GHIDRA_CAST((GHIDRA_CAST(this) + 0x484))) { - piVar1 = GHIDRA_CAST((GHIDRA_INT(this) + 0x484)); - } - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x484)) = *piVar1; - piVar1 = GHIDRA_CAST((GHIDRA_INT(this) + 0x454)); - minValue = 1; - piVar2 = &minValue; - if (1 < *piVar1) { - piVar2 = piVar1; - } - *piVar1 = *piVar2; - } - } - } - } - } - } - } - } - } - } - } - if (0 < *GHIDRA_CAST((GHIDRA_CAST(this) + 0x11c))) { - minValue = 1; - piVar1 = &minValue; - if (1 < *GHIDRA_CAST((GHIDRA_CAST(this) + 0x488))) { - piVar1 = GHIDRA_CAST((GHIDRA_INT(this) + 0x488)); - } - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x488)) = *piVar1; - piVar1 = GHIDRA_CAST((GHIDRA_INT(this) + 0x454)); - minValue = 1; - piVar2 = &minValue; - if (1 < *piVar1) { - piVar2 = piVar1; - } - *piVar1 = *piVar2; - } - if (0 < *GHIDRA_CAST((GHIDRA_CAST(this) + 0x114))) { - minValue = 1; - piVar1 = &minValue; - if (1 < *GHIDRA_CAST((GHIDRA_CAST(this) + 0x48c))) { - piVar1 = GHIDRA_CAST((GHIDRA_INT(this) + 0x48c)); - } - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x48c)) = *piVar1; - piVar1 = GHIDRA_CAST((GHIDRA_INT(this) + 0x454)); - minValue = 1; - piVar2 = &minValue; - if (1 < *piVar1) { - piVar2 = piVar1; - } - *piVar1 = *piVar2; - } - if (0 < *GHIDRA_CAST((GHIDRA_CAST(this) + 0x14c))) { - minValue = 1; - piVar1 = &minValue; - if (1 < *GHIDRA_CAST((GHIDRA_CAST(this) + 0x494))) { - piVar1 = GHIDRA_CAST((GHIDRA_INT(this) + 0x494)); - } - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x494)) = *piVar1; - piVar1 = GHIDRA_CAST((GHIDRA_INT(this) + 0x454)); - minValue = 1; - piVar2 = &minValue; - if (1 < *piVar1) { - piVar2 = piVar1; - } - *piVar1 = *piVar2; - } - if (0 < *GHIDRA_CAST((GHIDRA_CAST(this) + 0x148))) { - minValue = 1; - piVar1 = &minValue; - if (1 < *GHIDRA_CAST((GHIDRA_CAST(this) + 0x490))) { - piVar1 = GHIDRA_CAST((GHIDRA_INT(this) + 0x490)); - } - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x490)) = *piVar1; - piVar1 = GHIDRA_CAST((GHIDRA_INT(this) + 0x454)); - minValue = 1; - piVar2 = &minValue; - if (1 < *piVar1) { - piVar2 = piVar1; - } - *piVar1 = *piVar2; - } - if (0 < *GHIDRA_CAST((GHIDRA_CAST(this) + 0x150))) { - minValue = 1; - piVar1 = &minValue; - if (1 < *GHIDRA_CAST((GHIDRA_CAST(this) + 0x498))) { - piVar1 = GHIDRA_CAST((GHIDRA_INT(this) + 0x498)); - } - *GHIDRA_CAST((GHIDRA_CAST(this) + 0x498)) = *piVar1; - piVar1 = GHIDRA_CAST((GHIDRA_INT(this) + 0x454)); - minValue = 1; - piVar2 = &minValue; - if (1 < *piVar1) { - piVar2 = piVar1; - } - *piVar1 = *piVar2; - } - return; -} diff --git a/generated-src/spawn.cpp b/generated-src/spawn.cpp deleted file mode 100644 index ae12ff0..0000000 --- a/generated-src/spawn.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "classes.h" - -// 00872000 -void Spawn::Entries(uint32_t *param_1, int param_2) -{ - *param_1 = GHIDRA_UINT(*GHIDRA_CAST((param_2 + 8))); - param_1[1] = *GHIDRA_CAST((param_2 + 4)); - return; -} diff --git a/generated-src/sprite.cpp b/generated-src/sprite.cpp index 1e02a35..c6067dd 100644 --- a/generated-src/sprite.cpp +++ b/generated-src/sprite.cpp @@ -50,42 +50,6 @@ void Sprite::Play(std_string *animName, uint8_t isForce) return; } -// 0040a4b0 -void Sprite::IsPlaying(uint8_t *param_1) -{ - ANM2 *in_ECX; - - if (0xf < *GHIDRA_CAST((param_1 + 0x14))) { - param_1 = *GHIDRA_CAST(param_1); - } - ANM2::IsPlaying(in_ECX,param_1); - return; -} - -// 0040a530 -uint8_t Sprite::IsFinished(std_string *animName) -{ - uint8_t bVar1; - - if (0xf < animName->_capacity) { - animName = *GHIDRA_CAST(animName->_buf); - } - bVar1 = ANM2::IsFinishedImpl(GHIDRA_CAST(this),GHIDRA_CAST(animName)); - return bVar1; -} - -// 0040a5b0 -uint8_t Sprite::SetAnimation(std_string *name, uint8_t isReset) -{ - uint8_t bVar1; - - if (0xf < name->_capacity) { - name = *GHIDRA_CAST(name->_buf); - } - bVar1 = ANM2::SetAnimation(GHIDRA_CAST(this),GHIDRA_CAST(name),isReset); - return bVar1; -} - // 0040a720 void Sprite::SetFrame_1(int frame) { @@ -107,32 +71,6 @@ void Sprite::PlayOverlay(uint8_t *param_1, uint8_t param_2) return; } -// 0040a9d0 -void Sprite::IsOverlayPlaying() -{ - FUN_0040a9f0(); - return; -} - -// 0040aa50 -void Sprite::IsOverlayFinished() -{ - FUN_0040aa70(); - return; -} - -// 0040aad0 -uint8_t Sprite::SetOverlayAnimation(std_string *animName, uint8_t isReset) -{ - uint8_t bVar1; - - if (0xf < animName->_capacity) { - animName = *GHIDRA_CAST(animName->_buf); - } - bVar1 = ANM2::SetOverlayAnimation(GHIDRA_CAST(this),GHIDRA_CAST(animName),isReset); - return bVar1; -} - // 0040abb0 void Sprite::SetOverlayFrame(std_string *animName, int frame) { @@ -148,36 +86,6 @@ void Sprite::SetOverlayFrame(std_string *animName, int frame) return; } -// 0040b000 -uint8_t Sprite::IsEventTriggered(void *eventName) -{ - uint8_t isTriggered; - - if (0xf < *GHIDRA_CAST((GHIDRA_CAST(eventName) + 0x14))) { - eventName = *(void **)eventName; - } - if ((this->_animState)._animData == (void *)0x0) { - return 0; - } - isTriggered = AnimationState::IsEventTriggered(&this->_animState,eventName); - return isTriggered; -} - -// 0040b060 -uint8_t Sprite::WasEventTriggered(std_string *eventName) -{ - uint8_t local_AL_32; - - if (0xf < eventName->_capacity) { - eventName = *GHIDRA_CAST(eventName->_buf); - } - if ((this->_animState)._animData == (void *)0x0) { - return 0; - } - local_AL_32 = AnimationState::WasEventTriggered(&this->_animState,GHIDRA_CAST(eventName)); - return local_AL_32; -} - // 0040b200 LayerState * Sprite::GetLayer(uint8_t *layerName) { @@ -220,20 +128,6 @@ void Sprite::SetScale(Vector *scale) return; } -// 004312e0 -std_string * Sprite::GetFilename(std_string *outName) -{ - (GHIDRA_CAST((outName->_buf)))->msvc::string::string(this); - return outName; -} - -// 00431300 -void Sprite::SetOverlayRenderPriority(uint8_t param_2) -{ - this->_overlayRenderFirst = param_2; - return; -} - // 0043ee80 void Sprite::SetRotation(float rotation) { @@ -260,9 +154,3 @@ long double Sprite::PlaybackSpeed() { return (long double)this->_playbackSpeed; } - -// 0049cb40 -Vector * Sprite::Offset() -{ - return &this->_offset; -} diff --git a/generated-src/stubs.cpp b/generated-src/stubs.cpp index 88b087e..78e7015 100644 --- a/generated-src/stubs.cpp +++ b/generated-src/stubs.cpp @@ -8220,7 +8220,6 @@ uint32_t _DAT_e76476a4{}; uint32_t register0x00000010{}; uint32_t register0x0000001e{}; -uint8_t AfterbirthPersistentGameData::check_header(void *stream) { generated_stub("AfterbirthPersistentGameData::check_header 0041d670"); } BitSet128 * BitSet128::operator_and(BitSet128 *outResult, BitSet128 *a, BitSet128 *b) { generated_stub("BitSet128::operator_and 00417170"); } uint8_t BitSet128::IsNonZero() { generated_stub("BitSet128::IsNonZero 004171b0"); } BitSet128 * BitSet128::operator__(BitSet128 *other) { generated_stub("BitSet128::operator__ 00435bf0"); } @@ -8251,78 +8250,6 @@ void CommandThread::post_command(void *command) { generated_stub("CommandThread: DamageInfo::DamageInfo() { generated_stub("DamageInfo::DamageInfo 006a8190"); } void DateTime::set_from_yyyymmdd(void *dateTime, int yyyymmdd) { generated_stub("DateTime::set_from_yyyymmdd 0085af30"); } void DateTime::constructor(uint8_t isNow) { generated_stub("DateTime::constructor 00a24270"); } -void DeathmatchTypeBase::vfunc_1() { generated_stub("DeathmatchTypeBase::vfunc_1 00af05d3"); } -uint8_t DeathmatchTypeBase::Init() { generated_stub("DeathmatchTypeBase::Init 0042a4d0"); } -void DeathmatchTypeBase::guard_check_icall() { generated_stub("DeathmatchTypeBase::guard_check_icall 0040c200"); } -void DeathmatchTypeBase::Update() { generated_stub("DeathmatchTypeBase::Update 0042a8b0"); } -void DeathmatchTypeBase::vfunc_5() { generated_stub("DeathmatchTypeBase::vfunc_5 0040c200"); } -void DeathmatchTypeBase::FUN_0042aca0() { generated_stub("DeathmatchTypeBase::FUN_0042aca0 0042aca0"); } -bool DeathmatchTypeBase::FUN_0042ae90() { generated_stub("DeathmatchTypeBase::FUN_0042ae90 0042ae90"); } -uint64_t DeathmatchTypeBase::FUN_0042af00() { generated_stub("DeathmatchTypeBase::FUN_0042af00 0042af00"); } -uint32_t DeathmatchTypeBase::FUN_0042b480(uint32_t param_1) { generated_stub("DeathmatchTypeBase::FUN_0042b480 0042b480"); } -uint32_t DeathmatchTypeBase::FUN_0042b430(uint32_t param_1) { generated_stub("DeathmatchTypeBase::FUN_0042b430 0042b430"); } -uint32_t DeathmatchTypeBase::FUN_0042b340(uint32_t param_1) { generated_stub("DeathmatchTypeBase::FUN_0042b340 0042b340"); } -uint32_t DeathmatchTypeBase::FUN_0042b020(int param_1) { generated_stub("DeathmatchTypeBase::FUN_0042b020 0042b020"); } -uint32_t DeathmatchTypeBase::FUN_0042b520() { generated_stub("DeathmatchTypeBase::FUN_0042b520 0042b520"); } -Entity * DeathmatchTypeBase::FUN_0042b7c0(Vector *param_1, float param_2) { generated_stub("DeathmatchTypeBase::FUN_0042b7c0 0042b7c0"); } -void DeathmatchTypeBase::FUN_0042b770() { generated_stub("DeathmatchTypeBase::FUN_0042b770 0042b770"); } -void DeathmatchTypeBase::FUN_0042b940(int param_1) { generated_stub("DeathmatchTypeBase::FUN_0042b940 0042b940"); } -void DeathmatchTypeBase::FUN_0042b9a0(int *param_1) { generated_stub("DeathmatchTypeBase::FUN_0042b9a0 0042b9a0"); } -uint8_t DeathmatchTypeBase::FUN_0042bc00() { generated_stub("DeathmatchTypeBase::FUN_0042bc00 0042bc00"); } -long double DeathmatchTypeBase::FUN_0042bc10() { generated_stub("DeathmatchTypeBase::FUN_0042bc10 0042bc10"); } -void DeathmatchTypeBase::vfunc_20() { generated_stub("DeathmatchTypeBase::vfunc_20 0042bc00"); } -bool DeathmatchTypeBase::is_player_jelly_belly(uint32_t param_1, Entity_Player *param_2) { generated_stub("DeathmatchTypeBase::is_player_jelly_belly 0042bc20"); } -void DeathmatchTypeBase::FUN_0042bc40(Entity *param_1) { generated_stub("DeathmatchTypeBase::FUN_0042bc40 0042bc40"); } -void DeathmatchTypeBase::FUN_0042bc90() { generated_stub("DeathmatchTypeBase::FUN_0042bc90 0042bc90"); } -void DeathmatchTypeBase::FUN_0042bca0(Entity_Player *param_1) { generated_stub("DeathmatchTypeBase::FUN_0042bca0 0042bca0"); } -void DeathmatchTypeBase::vfunc_25() { generated_stub("DeathmatchTypeBase::vfunc_25 0042bc90"); } -void DeathmatchTypeBase::vfunc_26() { generated_stub("DeathmatchTypeBase::vfunc_26 0042bc90"); } -void DeathmatchTypeBase::vfunc_27() { generated_stub("DeathmatchTypeBase::vfunc_27 0042bc90"); } -void DeathmatchTypeBase::StoreGameState(void *gameState) { generated_stub("DeathmatchTypeBase::StoreGameState 0042bd70"); } -void DeathmatchTypeBase::RestoreGameState(int param_1) { generated_stub("DeathmatchTypeBase::RestoreGameState 0042bdf0"); } -void DeathmatchTypeBase::FUN_0042c070(Entity_Player *param_1, uint64_t *param_2) { generated_stub("DeathmatchTypeBase::FUN_0042c070 0042c070"); } -uint32_t DeathmatchTypeBase::FUN_0042c160() { generated_stub("DeathmatchTypeBase::FUN_0042c160 0042c160"); } -Entity * DeathmatchTypeBase::spawn_random_pickup() { generated_stub("DeathmatchTypeBase::spawn_random_pickup 0042c170"); } -int * DeathmatchTypeBase::FUN_0042c540(char param_1) { generated_stub("DeathmatchTypeBase::FUN_0042c540 0042c540"); } -void DeathmatchTypeBase::FUN_0042c6a0(uint32_t param_1, uint32_t param_2) { generated_stub("DeathmatchTypeBase::FUN_0042c6a0 0042c6a0"); } -void DeathmatchTypeBomberman::vfunc_1() { generated_stub("DeathmatchTypeBomberman::vfunc_1 0042ca10"); } -uint32_t DeathmatchTypeBomberman::FUN_0042b520() { generated_stub("DeathmatchTypeBomberman::FUN_0042b520 0042ca20"); } -uint8_t DeathmatchTypeBomberman::FUN_0042bc00() { generated_stub("DeathmatchTypeBomberman::FUN_0042bc00 0042ca30"); } -void DeathmatchTypeBomberman::FUN_0042c070(Entity_Player *param_1, uint64_t *param_2) { generated_stub("DeathmatchTypeBomberman::FUN_0042c070 0042ca40"); } -void DeathmatchTypeIndigestion::vfunc_1() { generated_stub("DeathmatchTypeIndigestion::vfunc_1 0042cb70"); } -void DeathmatchTypeIndigestion::vfunc_20() { generated_stub("DeathmatchTypeIndigestion::vfunc_20 0042cb80"); } -void DeathmatchTypeIndigestion::FUN_0042c070(Entity_Player *param_1, uint64_t *param_2) { generated_stub("DeathmatchTypeIndigestion::FUN_0042c070 0042cb90"); } -void DeathmatchTypeIpecac::vfunc_1() { generated_stub("DeathmatchTypeIpecac::vfunc_1 0042cc80"); } -void DeathmatchTypeIpecac::FUN_0042bc40(Entity *param_1) { generated_stub("DeathmatchTypeIpecac::FUN_0042bc40 0042cc90"); } -void DeathmatchTypeIpecac::FUN_0042bca0(Entity_Player *param_1) { generated_stub("DeathmatchTypeIpecac::FUN_0042bca0 0042cdf0"); } -void DeathmatchTypeIpecac::vfunc_25() { generated_stub("DeathmatchTypeIpecac::vfunc_25 0042ce00"); } -void DeathmatchTypeIpecac::vfunc_26() { generated_stub("DeathmatchTypeIpecac::vfunc_26 0042ce00"); } -void DeathmatchTypeIpecac::vfunc_27() { generated_stub("DeathmatchTypeIpecac::vfunc_27 0042ce30"); } -void DeathmatchTypeIpecac::FUN_0042c070(Entity_Player *param_1, uint64_t *param_2) { generated_stub("DeathmatchTypeIpecac::FUN_0042c070 0042ce60"); } -void DeathmatchTypeKnifeFight::vfunc_1() { generated_stub("DeathmatchTypeKnifeFight::vfunc_1 0042cea0"); } -void DeathmatchTypeKnifeFight::FUN_0042c070(Entity_Player *param_1, uint64_t *param_2) { generated_stub("DeathmatchTypeKnifeFight::FUN_0042c070 0042ceb0"); } -void DeathmatchTypeKnockout::vfunc_1() { generated_stub("DeathmatchTypeKnockout::vfunc_1 0042cef0"); } -long double DeathmatchTypeKnockout::FUN_0042bc10() { generated_stub("DeathmatchTypeKnockout::FUN_0042bc10 0042cf00"); } -void DeathmatchTypeKnockout::FUN_0042c070(Entity_Player *param_1, uint64_t *param_2) { generated_stub("DeathmatchTypeKnockout::FUN_0042c070 0042cf10"); } -void DeathmatchTypeLudovico::vfunc_1() { generated_stub("DeathmatchTypeLudovico::vfunc_1 0042d1b0"); } -void DeathmatchTypeLudovico::vfunc_20() { generated_stub("DeathmatchTypeLudovico::vfunc_20 0042cb80"); } -void DeathmatchTypeLudovico::FUN_0042bc90() { generated_stub("DeathmatchTypeLudovico::FUN_0042bc90 0042d1c0"); } -void DeathmatchTypeLudovico::FUN_0042c070(Entity_Player *param_1, uint64_t *param_2) { generated_stub("DeathmatchTypeLudovico::FUN_0042c070 0042d5f0"); } -void DeathmatchTypeMachineGun::vfunc_1() { generated_stub("DeathmatchTypeMachineGun::vfunc_1 0042d660"); } -long double DeathmatchTypeMachineGun::FUN_0042bc10() { generated_stub("DeathmatchTypeMachineGun::FUN_0042bc10 0042d670"); } -void DeathmatchTypeMachineGun::FUN_0042c070(Entity_Player *param_1, uint64_t *param_2) { generated_stub("DeathmatchTypeMachineGun::FUN_0042c070 0042d680"); } -void DeathmatchTypeNormal::vfunc_1() { generated_stub("DeathmatchTypeNormal::vfunc_1 0042d7e0"); } -uint8_t DeathmatchTypeNormal::Init() { generated_stub("DeathmatchTypeNormal::Init 0042d7f0"); } -void DeathmatchTypeNormal::Update() { generated_stub("DeathmatchTypeNormal::Update 0042d850"); } -void DeathmatchTypeSumo::vfunc_1() { generated_stub("DeathmatchTypeSumo::vfunc_1 0042d8a0"); } -uint8_t DeathmatchTypeSumo::FUN_0042bc00() { generated_stub("DeathmatchTypeSumo::FUN_0042bc00 0042ca30"); } -void DeathmatchTypeSumo::FUN_0042c070(Entity_Player *param_1, uint64_t *param_2) { generated_stub("DeathmatchTypeSumo::FUN_0042c070 0042d8b0"); } -void DeathmatchTypeSwordFight::vfunc_1() { generated_stub("DeathmatchTypeSwordFight::vfunc_1 0042d950"); } -void DeathmatchTypeSwordFight::FUN_0042c070(Entity_Player *param_1, uint64_t *param_2) { generated_stub("DeathmatchTypeSwordFight::FUN_0042c070 0042d960"); } -void DeathmatchTypeVenom::vfunc_1() { generated_stub("DeathmatchTypeVenom::vfunc_1 0042d9d0"); } -void DeathmatchTypeVenom::vfunc_20() { generated_stub("DeathmatchTypeVenom::vfunc_20 0042cb80"); } -void DeathmatchTypeVenom::FUN_0042bc40(Entity *param_1) { generated_stub("DeathmatchTypeVenom::FUN_0042bc40 0042d9e0"); } -void DeathmatchTypeVenom::FUN_0042c070(Entity_Player *param_1, uint64_t *param_2) { generated_stub("DeathmatchTypeVenom::FUN_0042c070 0042db40"); } void DebugRenderer::Render() { generated_stub("DebugRenderer::Render 0042dbb0"); } void * DebugRenderer::Get(int Index, uint8_t Unk) { generated_stub("DebugRenderer::Get 0042eb10"); } Vector * Vector::operator_mul(Vector *outResult, float *scalar, Vector *vector) { generated_stub("Vector::operator_mul 004171d0"); } @@ -8339,13 +8266,10 @@ Vector * Vector::Normalized(Vector *outResult) { generated_stub("Vector::Normali void Vector::Resize(float length) { generated_stub("Vector::Resize 00a100b0"); } Vector * Vector::Resized(Vector *outVec, float length) { generated_stub("Vector::Resized 00a10100"); } float Vector::Dot(Vector *other) { generated_stub("Vector::Dot 00a10180"); } -float Vector::Cross(Vector *other) { generated_stub("Vector::Cross 00a101a0"); } void Vector::Rotate(float angleDegrees) { generated_stub("Vector::Rotate 00a10270"); } Vector * Vector::Rotated(Vector *outVec, float angleDegrees) { generated_stub("Vector::Rotated 00a102e0"); } Vector * Vector::FromAngle(Vector *outVec, float angleDegrees) { generated_stub("Vector::FromAngle 00a10350"); } float Vector::GetAngleDegrees() { generated_stub("Vector::GetAngleDegrees 00a10390"); } -void Vector::Clamp(float minX, float minY, float maxX, float maxY) { generated_stub("Vector::Clamp 00a103c0"); } -Vector * Vector::Clamped(Vector *outResult, float minX, float minY, float maxX, float maxY) { generated_stub("Vector::Clamped 00a103f0"); } Vector * Vector::__add(Vector *outVec, Vector *other) { generated_stub("Vector::__add 00a10420"); } Vector * Vector::operator_add_assign(Vector *other) { generated_stub("Vector::operator_add_assign 00a10450"); } Vector * Vector::__sub(Vector *outResult, Vector *other) { generated_stub("Vector::__sub 00a10480"); } @@ -8369,8 +8293,6 @@ uint8_t FileSystem::open_disk_file(uint8_t *path, void **outFile) { generated_st uint8_t FileSystem::open_archive_file(uint8_t *path, void **outFile) { generated_stub("FileSystem::open_archive_file 00a17f40"); } void FrameQueue::setSize(int count) { generated_stub("FrameQueue::setSize 00aaa500"); } FriendEntry::~FriendEntry() { generated_stub("FriendEntry::~FriendEntry 008e1f30"); } -void * GlitchedCollectibleGfx::constructor() { generated_stub("GlitchedCollectibleGfx::constructor 009dc6e0"); } -void GlitchedItemSet::recalculate() { generated_stub("GlitchedItemSet::recalculate 009e0500"); } void HallucinationOverlay::Render(Vector *offset) { generated_stub("HallucinationOverlay::Render 00839550"); } void * InputManager::GetDeviceByPlayerEntity(Entity_Player *player) { generated_stub("InputManager::GetDeviceByPlayerEntity 0090ac70"); } int InputManager::FirstLocalDeviceID() { generated_stub("InputManager::FirstLocalDeviceID 0090aeb0"); } @@ -9207,12 +9129,7 @@ void * NetworkManager::receive_message(void *outMessage, uint8_t channel, uint8_ void NetworkManager::receive_packet(uint64_t *sender, void *buffer, int size) { generated_stub("NetworkManager::receive_packet 00a78a10"); } void * NetworkManager::get_peer(void *outPeer, uint64_t *userId) { generated_stub("NetworkManager::get_peer 00a790b0"); } int * NpcHelper::chub_nearest_segment(int *param_1, int param_2) { generated_stub("NpcHelper::chub_nearest_segment 00499a50"); } -uint8_t NpcHelper::polty_target_set(int gridIndex) { generated_stub("NpcHelper::polty_target_set 0055d070"); } -uint8_t NpcHelper::polty_is_target_liftable(Entity_NPC *npc) { generated_stub("NpcHelper::polty_is_target_liftable 0055d0b0"); } -uint8_t NpcHelper::polty_is_pot_cell(Entity_NPC *npc, int gridIndex) { generated_stub("NpcHelper::polty_is_pot_cell 0055d180"); } void NpcHelper::mother_set_collision_class(Entity_NPC *npc, int collisionClass) { generated_stub("NpcHelper::mother_set_collision_class 005688c0"); } -void NpcHelper::scourge_whip(Entity_NPC *npc) { generated_stub("NpcHelper::scourge_whip 00582f60"); } -void NpcHelper::scourge_chain_shoot() { generated_stub("NpcHelper::scourge_chain_shoot 00587480"); } void NpcHelper::singe_explode_at(Entity_NPC *npc, Vector *position) { generated_stub("NpcHelper::singe_explode_at 0058ac10"); } void NpcHelper::siren_charm_familiar(Entity_NPC *npc, Entity_Familiar *familiar) { generated_stub("NpcHelper::siren_charm_familiar 0058e260"); } void NpcHelper::siren_familiar_counts(int *outFreeCount, int *outCharmedCount, int *outTotalCount) { generated_stub("NpcHelper::siren_familiar_counts 0058e490"); } @@ -9230,13 +9147,8 @@ void * PersistentGameDataWriter::compress(uint32_t *outSize) { generated_stub("P void PersistentGameDataWriter::write(PersistentGameData *data, void *header) { generated_stub("PersistentGameDataWriter::write 0091b130"); } void PngWriter::write_end() { generated_stub("PngWriter::write_end 009e8d40"); } void PngWriter::write_info() { generated_stub("PngWriter::write_info 009e8ee0"); } -uint8_t ProceduralEffect::roll_trigger_target(uint32_t *outTarget, float *outChance, RNG *rng) { generated_stub("ProceduralEffect::roll_trigger_target 009e0700"); } -uint8_t ProceduralEffect::roll_spawn_target(uint32_t *outTarget, float *outChance, RNG *rng) { generated_stub("ProceduralEffect::roll_spawn_target 009e0ad0"); } -void ProceduralEffect::roll_params(int conditionType, int actionType, uint32_t seed) { generated_stub("ProceduralEffect::roll_params 009e0f60"); } void Quad::rotate(Vector *pivot, float angle) { generated_stub("Quad::rotate 00a10760"); } void Quad::scale(Vector *pivot, Vector *scale) { generated_stub("Quad::scale 00a10950"); } -void RebirthSaveData::Clear() { generated_stub("RebirthSaveData::Clear 009e3dc0"); } -void RebirthSaveData::repair_counters() { generated_stub("RebirthSaveData::repair_counters 009e4af0"); } ReferenceCountBase::~ReferenceCountBase() { generated_stub("ReferenceCountBase::~ReferenceCountBase 0040cbb0"); } void ReferenceCountBase::vfunc_1() { generated_stub("ReferenceCountBase::vfunc_1 00af05d3"); } void ReferenceCountBase::vfunc_2() { generated_stub("ReferenceCountBase::vfunc_2 00af05d3"); } @@ -9252,35 +9164,23 @@ void SharedPtrPair::constructor() { generated_stub("SharedPtrPair::constructor 0 SharedPtrPair::~SharedPtrPair() { generated_stub("SharedPtrPair::~SharedPtrPair 00424cd0"); } ShockwaveParams::ShockwaveParams() { generated_stub("ShockwaveParams::ShockwaveParams 00456570"); } SourceQuad::SourceQuad(void *source) { generated_stub("SourceQuad::SourceQuad 00a11210"); } -void Spawn::Entries(uint32_t *param_1, int param_2) { generated_stub("Spawn::Entries 00872000"); } void Sprite::SetColor(ColorMod *color) { generated_stub("Sprite::SetColor 004073d0"); } uint8_t Sprite::FlipX() { generated_stub("Sprite::FlipX 00407420"); } uint8_t Sprite::FlipY() { generated_stub("Sprite::FlipY 00407430"); } void Sprite::Play(std_string *animName, uint8_t isForce) { generated_stub("Sprite::Play 0040a360"); } -void Sprite::IsPlaying(uint8_t *param_1) { generated_stub("Sprite::IsPlaying 0040a4b0"); } -uint8_t Sprite::IsFinished(std_string *animName) { generated_stub("Sprite::IsFinished 0040a530"); } -uint8_t Sprite::SetAnimation(std_string *name, uint8_t isReset) { generated_stub("Sprite::SetAnimation 0040a5b0"); } void Sprite::SetFrame_1(int frame) { generated_stub("Sprite::SetFrame_1 0040a720"); } void Sprite::PlayOverlay(uint8_t *param_1, uint8_t param_2) { generated_stub("Sprite::PlayOverlay 0040a920"); } -void Sprite::IsOverlayPlaying() { generated_stub("Sprite::IsOverlayPlaying 0040a9d0"); } -void Sprite::IsOverlayFinished() { generated_stub("Sprite::IsOverlayFinished 0040aa50"); } -uint8_t Sprite::SetOverlayAnimation(std_string *animName, uint8_t isReset) { generated_stub("Sprite::SetOverlayAnimation 0040aad0"); } void Sprite::SetOverlayFrame(std_string *animName, int frame) { generated_stub("Sprite::SetOverlayFrame 0040abb0"); } -uint8_t Sprite::IsEventTriggered(void *eventName) { generated_stub("Sprite::IsEventTriggered 0040b000"); } -uint8_t Sprite::WasEventTriggered(std_string *eventName) { generated_stub("Sprite::WasEventTriggered 0040b060"); } LayerState * Sprite::GetLayer(uint8_t *layerName) { generated_stub("Sprite::GetLayer 0040b200"); } void Sprite::LoadGraphics() { generated_stub("Sprite::LoadGraphics 0040bff0"); } Vector * Sprite::Scale() { generated_stub("Sprite::Scale 00417200"); } long double Sprite::Rotation() { generated_stub("Sprite::Rotation 00417210"); } uint8_t Sprite::IsLoaded() { generated_stub("Sprite::IsLoaded 00420160"); } void Sprite::SetScale(Vector *scale) { generated_stub("Sprite::SetScale 00420170"); } -std_string * Sprite::GetFilename(std_string *outName) { generated_stub("Sprite::GetFilename 004312e0"); } -void Sprite::SetOverlayRenderPriority(uint8_t param_2) { generated_stub("Sprite::SetOverlayRenderPriority 00431300"); } void Sprite::SetRotation(float rotation) { generated_stub("Sprite::SetRotation 0043ee80"); } int Sprite::GetLayerCount() { generated_stub("Sprite::GetLayerCount 00440e40"); } void Sprite::set_offset(Vector *offset) { generated_stub("Sprite::set_offset 00456340"); } long double Sprite::PlaybackSpeed() { generated_stub("Sprite::PlaybackSpeed 00456360"); } -Vector * Sprite::Offset() { generated_stub("Sprite::Offset 0049cb40"); } SteamCloudFile::~SteamCloudFile() { generated_stub("SteamCloudFile::~SteamCloudFile 00683710"); } void SteamCloudFile::vfunc_1() { generated_stub("SteamCloudFile::vfunc_1 0067efb0"); } void SteamCloudFile::vfunc_2() { generated_stub("SteamCloudFile::vfunc_2 0067efc0"); } @@ -9299,11 +9199,7 @@ msvc::exception::~exception() { generated_stub("msvc::exception::~exception 0040 char * msvc::exception::FUN_0040d0d0() { generated_stub("msvc::exception::FUN_0040d0d0 0040d0d0"); } luabridge::LuaException::~LuaException() { generated_stub("luabridge::LuaException::~LuaException 0085c210"); } char * luabridge::LuaException::FUN_0040d0d0() { generated_stub("luabridge::LuaException::FUN_0040d0d0 0085c200"); } -luabridge::Namespace::~Namespace() { generated_stub("luabridge::Namespace::~Namespace 0085d980"); } -void luabridge::Namespace::ClassBase::createConstTable(uint8_t *name) { generated_stub("luabridge::Namespace::ClassBase::createConstTable 0085d040"); } -void luabridge::Namespace::ClassBase::createClassTable(uint8_t *name) { generated_stub("luabridge::Namespace::ClassBase::createClassTable 0085d2c0"); } luabridge::Userdata::~Userdata() { generated_stub("luabridge::Userdata::~Userdata 0085c7e0"); } -void * luabridge::Userdata::getClass(void *luaState, int index, void *registryClassKey, uint8_t isCanBeConst) { generated_stub("luabridge::Userdata::getClass 0085c590"); } void rapidxml::xml_document::parse(uint8_t *text) { generated_stub("rapidxml::xml_document::parse 004155d0"); } int * rapidxml::xml_document::parse_node(int *param_1) { generated_stub("rapidxml::xml_document::parse_node 00416040"); } void shared_ptr::assign(void *other) { generated_stub("shared_ptr::assign 0041c770"); } @@ -9555,7 +9451,6 @@ uint8_t * FUN_0041d4c0() { generated_stub("FUN_0041d4c0 0041d4c0"); } int FUN_0041d4d0() { generated_stub("FUN_0041d4d0 0041d4d0"); } void Math::abs() { generated_stub("Math::abs 0041d510"); } void FUN_0041d560() { generated_stub("FUN_0041d560 0041d560"); } -int afterbirth_save_index_remap(int oldIndex) { generated_stub("afterbirth_save_index_remap 0041ddb0"); } int sprintf_s(uint8_t *buffer, uint32_t size, uint8_t *format) { generated_stub("sprintf_s 0041e420"); } void FUN_0041e440(uint32_t *param_1) { generated_stub("FUN_0041e440 0041e440"); } int FUN_0041e470() { generated_stub("FUN_0041e470 0041e470"); } @@ -9606,7 +9501,6 @@ StageTransition * FUN_00428b50() { generated_stub("FUN_00428b50 00428b50"); } void FUN_00428b60(void *param_1, uint32_t param_2) { generated_stub("FUN_00428b60 00428b60"); } void FUN_00428ce0() { generated_stub("FUN_00428ce0 00428ce0"); } uint32_t FUN_00428d30(uint32_t param_1) { generated_stub("FUN_00428d30 00428d30"); } -void FUN_00429810(uint32_t param_1) { generated_stub("FUN_00429810 00429810"); } void FUN_00429f20() { generated_stub("FUN_00429f20 00429f20"); } int FUN_00429f30(uint32_t param_1) { generated_stub("FUN_00429f30 00429f30"); } void FUN_00429f50() { generated_stub("FUN_00429f50 00429f50"); } @@ -9618,29 +9512,7 @@ void FUN_0042a210() { generated_stub("FUN_0042a210 0042a210"); } void FUN_0042a230() { generated_stub("FUN_0042a230 0042a230"); } void FUN_0042a350() { generated_stub("FUN_0042a350 0042a350"); } void FUN_0042a490() { generated_stub("FUN_0042a490 0042a490"); } -void FUN_0042aca0() { generated_stub("FUN_0042aca0 0042aca0"); } -bool FUN_0042ae90() { generated_stub("FUN_0042ae90 0042ae90"); } -uint64_t FUN_0042af00() { generated_stub("FUN_0042af00 0042af00"); } -uint32_t FUN_0042b020(int param_1) { generated_stub("FUN_0042b020 0042b020"); } -uint32_t FUN_0042b340(uint32_t param_1) { generated_stub("FUN_0042b340 0042b340"); } -uint32_t FUN_0042b430(uint32_t param_1) { generated_stub("FUN_0042b430 0042b430"); } -uint32_t FUN_0042b480(uint32_t param_1) { generated_stub("FUN_0042b480 0042b480"); } -uint32_t FUN_0042b520() { generated_stub("FUN_0042b520 0042b520"); } int FUN_0042b550() { generated_stub("FUN_0042b550 0042b550"); } -void FUN_0042b770() { generated_stub("FUN_0042b770 0042b770"); } -Entity * FUN_0042b7c0(Vector *param_1, float param_2) { generated_stub("FUN_0042b7c0 0042b7c0"); } -void FUN_0042b940(int param_1) { generated_stub("FUN_0042b940 0042b940"); } -void FUN_0042b9a0(int *param_1) { generated_stub("FUN_0042b9a0 0042b9a0"); } -uint8_t FUN_0042bc00() { generated_stub("FUN_0042bc00 0042bc00"); } -long double FUN_0042bc10() { generated_stub("FUN_0042bc10 0042bc10"); } -bool is_player_jelly_belly(uint32_t param_1, Entity_Player *param_2) { generated_stub("is_player_jelly_belly 0042bc20"); } -void FUN_0042bc40(Entity *param_1) { generated_stub("FUN_0042bc40 0042bc40"); } -void FUN_0042bc90() { generated_stub("FUN_0042bc90 0042bc90"); } -void FUN_0042bca0(Entity_Player *param_1) { generated_stub("FUN_0042bca0 0042bca0"); } -void FUN_0042c070(Entity_Player *param_1, uint64_t *param_2) { generated_stub("FUN_0042c070 0042c070"); } -uint32_t FUN_0042c160() { generated_stub("FUN_0042c160 0042c160"); } -int * FUN_0042c540(char param_1) { generated_stub("FUN_0042c540 0042c540"); } -void FUN_0042c6a0(uint32_t param_1, uint32_t param_2) { generated_stub("FUN_0042c6a0 0042c6a0"); } void FUN_0042c6e0(uint32_t *param_1) { generated_stub("FUN_0042c6e0 0042c6e0"); } int FUN_0042c700() { generated_stub("FUN_0042c700 0042c700"); } bool FUN_0042c710(int *param_1) { generated_stub("FUN_0042c710 0042c710"); } @@ -9652,39 +9524,7 @@ int FUN_0042c7f0() { generated_stub("FUN_0042c7f0 0042c7f0"); } int FUN_0042c810(int param_1) { generated_stub("FUN_0042c810 0042c810"); } void FUN_0042c820(uint32_t param_1) { generated_stub("FUN_0042c820 0042c820"); } ItemConfig * Isaac::GetItemConfig() { generated_stub("Isaac::GetItemConfig 0042ca00"); } -uint32_t FUN_0042ca10() { generated_stub("FUN_0042ca10 0042ca10"); } -uint32_t FUN_0042ca20() { generated_stub("FUN_0042ca20 0042ca20"); } -uint8_t FUN_0042ca30(int param_1) { generated_stub("FUN_0042ca30 0042ca30"); } -void FUN_0042ca40(Entity_Player *param_1, uint32_t param_2) { generated_stub("FUN_0042ca40 0042ca40"); } -uint32_t FUN_0042cb70() { generated_stub("FUN_0042cb70 0042cb70"); } -uint8_t FUN_0042cb80() { generated_stub("FUN_0042cb80 0042cb80"); } -void FUN_0042cb90(Entity_Player *param_1, uint32_t param_2) { generated_stub("FUN_0042cb90 0042cb90"); } -uint32_t FUN_0042cc80() { generated_stub("FUN_0042cc80 0042cc80"); } -void FUN_0042cc90(Entity *param_1) { generated_stub("FUN_0042cc90 0042cc90"); } -void FUN_0042ce00(int param_1, float *param_2) { generated_stub("FUN_0042ce00 0042ce00"); } -void FUN_0042ce30(int param_1, float *param_2) { generated_stub("FUN_0042ce30 0042ce30"); } -void FUN_0042ce60(Entity_Player *param_1, uint32_t param_2) { generated_stub("FUN_0042ce60 0042ce60"); } -uint32_t FUN_0042cea0() { generated_stub("FUN_0042cea0 0042cea0"); } -void FUN_0042ceb0(Entity_Player *param_1, uint32_t param_2) { generated_stub("FUN_0042ceb0 0042ceb0"); } -uint32_t FUN_0042cef0() { generated_stub("FUN_0042cef0 0042cef0"); } -long double FUN_0042cf00() { generated_stub("FUN_0042cf00 0042cf00"); } -void FUN_0042cf10(Entity_Player *param_1, uint32_t param_2) { generated_stub("FUN_0042cf10 0042cf10"); } int FUN_0042d040() { generated_stub("FUN_0042d040 0042d040"); } -uint32_t FUN_0042d1b0() { generated_stub("FUN_0042d1b0 0042d1b0"); } -void FUN_0042d5f0(Entity_Player *param_1, uint32_t param_2) { generated_stub("FUN_0042d5f0 0042d5f0"); } -uint32_t FUN_0042d660() { generated_stub("FUN_0042d660 0042d660"); } -long double FUN_0042d670() { generated_stub("FUN_0042d670 0042d670"); } -void FUN_0042d680(Entity_Player *param_1, uint32_t param_2) { generated_stub("FUN_0042d680 0042d680"); } -uint32_t FUN_0042d7e0() { generated_stub("FUN_0042d7e0 0042d7e0"); } -uint8_t FUN_0042d7f0() { generated_stub("FUN_0042d7f0 0042d7f0"); } -void FUN_0042d850() { generated_stub("FUN_0042d850 0042d850"); } -uint32_t FUN_0042d8a0() { generated_stub("FUN_0042d8a0 0042d8a0"); } -void FUN_0042d8b0(Entity_Player *param_1, uint32_t param_2) { generated_stub("FUN_0042d8b0 0042d8b0"); } -uint32_t FUN_0042d950() { generated_stub("FUN_0042d950 0042d950"); } -void FUN_0042d960(Entity_Player *param_1, uint32_t param_2) { generated_stub("FUN_0042d960 0042d960"); } -uint32_t FUN_0042d9d0() { generated_stub("FUN_0042d9d0 0042d9d0"); } -void FUN_0042d9e0(Entity *param_1) { generated_stub("FUN_0042d9e0 0042d9e0"); } -void FUN_0042db40(Entity_Player *param_1, uint32_t param_2) { generated_stub("FUN_0042db40 0042db40"); } void FUN_0042edb0() { generated_stub("FUN_0042edb0 0042edb0"); } void FUN_0042ede0(uint32_t *param_1) { generated_stub("FUN_0042ede0 0042ede0"); } void push_shape_points(void *self, Capsule *capsule) { generated_stub("push_shape_points 0042eef0"); } @@ -9726,7 +9566,6 @@ void FUN_00435910() { generated_stub("FUN_00435910 00435910"); } void FUN_00435bc0(uint32_t param_1, uint32_t param_2) { generated_stub("FUN_00435bc0 00435bc0"); } void FUN_00435cd0(uint32_t param_1) { generated_stub("FUN_00435cd0 00435cd0"); } void set_field_358(void *self, float value) { generated_stub("set_field_358 00435cf0"); } -void FUN_00435d40(uint32_t param_1) { generated_stub("FUN_00435d40 00435d40"); } void FUN_00435d90(uint32_t param_1) { generated_stub("FUN_00435d90 00435d90"); } int FUN_00435de0() { generated_stub("FUN_00435de0 00435de0"); } int FUN_00435df0() { generated_stub("FUN_00435df0 00435df0"); } @@ -9741,7 +9580,6 @@ int _get_index_plus_one_if_kind_4_5() { generated_stub("_get_index_plus_one_if_k int FUN_00436120(int param_1) { generated_stub("FUN_00436120 00436120"); } void FUN_00436190() { generated_stub("FUN_00436190 00436190"); } void FUN_00436200(uint32_t param_1) { generated_stub("FUN_00436200 00436200"); } -void FUN_00436210(uint32_t param_1) { generated_stub("FUN_00436210 00436210"); } void FUN_00436fb0() { generated_stub("FUN_00436fb0 00436fb0"); } void FUN_0043e990(RNG *param_1) { generated_stub("FUN_0043e990 0043e990"); } void FUN_0043ed20(uint32_t *param_1, int *param_2) { generated_stub("FUN_0043ed20 0043ed20"); } @@ -9749,33 +9587,19 @@ void FUN_0043edf0(uint32_t param_1, uint32_t param_2, uint32_t *param_3) { gener void FUN_0043eea0(uint32_t param_1) { generated_stub("FUN_0043eea0 0043eea0"); } void FUN_0043eed0(float *param_1) { generated_stub("FUN_0043eed0 0043eed0"); } void FUN_004405e0() { generated_stub("FUN_004405e0 004405e0"); } -void NpcAI::ENTITY_BEAST_background(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_BEAST_background 00440630"); } void set_PlaybackSpeed(ANM2 *sprite, float speed) { generated_stub("set_PlaybackSpeed 00440e50"); } bool FUN_00440e70() { generated_stub("FUN_00440e70 00440e70"); } void FUN_00440e80(Vector *param_1) { generated_stub("FUN_00440e80 00440e80"); } void FUN_00440e90(uint32_t param_1) { generated_stub("FUN_00440e90 00440e90"); } -void FUN_00440ea0(uint8_t param_1) { generated_stub("FUN_00440ea0 00440ea0"); } int FUN_00440ec0() { generated_stub("FUN_00440ec0 00440ec0"); } void FUN_00440ed0(uint32_t param_1) { generated_stub("FUN_00440ed0 00440ed0"); } -void NpcAI::ENTITY_BEAST_ultra_death(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_BEAST_ultra_death 00440f00"); } -void NpcAI::ENTITY_BEAST_ultra_death_scythe(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_BEAST_ultra_death_scythe 00443e50"); } -void NpcAI::ENTITY_BEAST_ultra_death_head(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_BEAST_ultra_death_head 00444900"); } void FUN_00444c70(uint32_t param_1) { generated_stub("FUN_00444c70 00444c70"); } void FUN_00444cb0(uint32_t param_1) { generated_stub("FUN_00444cb0 00444cb0"); } -void NpcAI::ENTITY_BEAST_ultra_famine(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_BEAST_ultra_famine 00444cc0"); } -void NpcAI::ENTITY_BEAST_ultra_famine_fly(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_BEAST_ultra_famine_fly 00447180"); } void set_field_0x37c(uint32_t param_1) { generated_stub("set_field_0x37c 00447720"); } uint32_t FUN_00447760() { generated_stub("FUN_00447760 00447760"); } -void NpcAI::ENTITY_BEAST_ultra_pestilence(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_BEAST_ultra_pestilence 004477b0"); } -void NpcAI::ENTITY_BEAST_pestilence_fly(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_BEAST_pestilence_fly 0044a040"); } -void NpcAI::ENTITY_BEAST_ultra_pestilence_fly_ball(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_BEAST_ultra_pestilence_fly_ball 0044aad0"); } -void NpcAI::ENTITY_BEAST_ultra_pestilence_maggot(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_BEAST_ultra_pestilence_maggot 0044b6f0"); } int FUN_0044bc90(int param_1) { generated_stub("FUN_0044bc90 0044bc90"); } void FUN_0044bf90(uint8_t param_1) { generated_stub("FUN_0044bf90 0044bf90"); } void FUN_0044bfa0(uint32_t param_1) { generated_stub("FUN_0044bfa0 0044bfa0"); } -void NpcAI::ENTITY_BEAST_ultra_war(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_BEAST_ultra_war 0044c070"); } -void NpcAI::ENTITY_BEAST_ultra_war_fire_burst(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_BEAST_ultra_war_fire_burst 0044ee60"); } -void NpcAI::ENTITY_BEAST_ultra_war_bomb(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_BEAST_ultra_war_bomb 0044f2b0"); } void FUN_00450880(uint32_t param_1) { generated_stub("FUN_00450880 00450880"); } void FUN_004508a0(uint32_t param_1) { generated_stub("FUN_004508a0 004508a0"); } uint32_t _ptr_deref_or_minus1() { generated_stub("_ptr_deref_or_minus1 00452be0"); } @@ -9787,7 +9611,6 @@ void FUN_004561f0(uint8_t *param_1) { generated_stub("FUN_004561f0 004561f0"); } void FUN_00456230() { generated_stub("FUN_00456230 00456230"); } char * FUN_004562f0(char *param_1) { generated_stub("FUN_004562f0 004562f0"); } void FUN_004563c0(uint32_t *param_1) { generated_stub("FUN_004563c0 004563c0"); } -void FUN_004563e0(uint32_t *param_1) { generated_stub("FUN_004563e0 004563e0"); } void FUN_00456400() { generated_stub("FUN_00456400 00456400"); } int FUN_00456540() { generated_stub("FUN_00456540 00456540"); } uint32_t FUN_004565b0() { generated_stub("FUN_004565b0 004565b0"); } @@ -9814,14 +9637,11 @@ void FUN_004aad00() { generated_stub("FUN_004aad00 004aad00"); } void FUN_004aad10() { generated_stub("FUN_004aad10 004aad10"); } void FUN_004aad20() { generated_stub("FUN_004aad20 004aad20"); } int FUN_004aad40() { generated_stub("FUN_004aad40 004aad40"); } -void FUN_004aad50(uint32_t param_1) { generated_stub("FUN_004aad50 004aad50"); } void FUN_004aad70(uint32_t param_1) { generated_stub("FUN_004aad70 004aad70"); } void FUN_004aad90(uint32_t param_1, uint32_t param_2) { generated_stub("FUN_004aad90 004aad90"); } void FUN_004aadb0(uint32_t param_1) { generated_stub("FUN_004aadb0 004aadb0"); } void FUN_004aadd0(uint32_t param_1) { generated_stub("FUN_004aadd0 004aadd0"); } void FUN_004aadf0(uint32_t param_1, uint32_t param_2, uint32_t param_3) { generated_stub("FUN_004aadf0 004aadf0"); } -void FUN_004aae30(char param_1) { generated_stub("FUN_004aae30 004aae30"); } -void FUN_004aae50(char param_1) { generated_stub("FUN_004aae50 004aae50"); } int FUN_004aae70() { generated_stub("FUN_004aae70 004aae70"); } void FUN_004b3950() { generated_stub("FUN_004b3950 004b3950"); } void FUN_004b6b20(int *param_1, int param_2, int param_3) { generated_stub("FUN_004b6b20 004b6b20"); } @@ -9879,8 +9699,6 @@ void NpcAI::ENTITY_BUTT_SLICKER(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY void FUN_00557b50(uint32_t param_1) { generated_stub("FUN_00557b50 00557b50"); } void FUN_00557b70(uint8_t *param_1) { generated_stub("FUN_00557b70 00557b70"); } bool FUN_00557bb0(int *param_1) { generated_stub("FUN_00557bb0 00557bb0"); } -uint32_t NpcAI::ENTITY_POLTY(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_POLTY 0055d230"); } -void FUN_00565dd0(uint32_t param_1) { generated_stub("FUN_00565dd0 00565dd0"); } void FUN_00565de0(uint32_t param_1) { generated_stub("FUN_00565de0 00565de0"); } void FUN_00568980(char param_1) { generated_stub("FUN_00568980 00568980"); } void FUN_0056ff00(uint32_t *param_1, uint32_t param_2, uint32_t param_3) { generated_stub("FUN_0056ff00 0056ff00"); } @@ -9890,22 +9708,6 @@ void FUN_00571230(void *param_1, int param_2) { generated_stub("FUN_00571230 005 uint32_t * FUN_00575fe0(int *param_1, uint32_t param_2, uint32_t param_3, uint32_t param_4, uint32_t param_5, uint32_t param_6, int *param_7, uint32_t param_8, uint32_t param_9) { generated_stub("FUN_00575fe0 00575fe0"); } void FUN_00579700() { generated_stub("FUN_00579700 00579700"); } uint32_t FUN_00579760() { generated_stub("FUN_00579760 00579760"); } -void FUN_0057be30(uint32_t param_1) { generated_stub("FUN_0057be30 0057be30"); } -void FUN_0057be60(uint32_t param_1, uint32_t param_2) { generated_stub("FUN_0057be60 0057be60"); } -int FUN_00582a60() { generated_stub("FUN_00582a60 00582a60"); } -int FUN_00582a80() { generated_stub("FUN_00582a80 00582a80"); } -void FUN_00582aa0() { generated_stub("FUN_00582aa0 00582aa0"); } -uint32_t FUN_00582ad0() { generated_stub("FUN_00582ad0 00582ad0"); } -void FUN_00582b00(uint32_t *param_1) { generated_stub("FUN_00582b00 00582b00"); } -int FUN_00582b40() { generated_stub("FUN_00582b40 00582b40"); } -void FUN_005830e0() { generated_stub("FUN_005830e0 005830e0"); } -void FUN_00583110(char param_1) { generated_stub("FUN_00583110 00583110"); } -void FUN_00583170() { generated_stub("FUN_00583170 00583170"); } -void NpcAI::ENTITY_SCOURGE_chain(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_SCOURGE_chain 00584140"); } -void NpcAI::ENTITY_SCOURGE_main(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_SCOURGE_main 005864b0"); } -void FUN_00586b50(float *param_1, float param_2) { generated_stub("FUN_00586b50 00586b50"); } -void NpcAI::ENTITY_SCOURGE_projectile_attack(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_SCOURGE_projectile_attack 00586c40"); } -void NpcAI::ENTITY_SCOURGE(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_SCOURGE 00587aa0"); } uint32_t FUN_0058ab60() { generated_stub("FUN_0058ab60 0058ab60"); } void NpcAI::ENTITY_SINGE_body(Entity_NPC *npc) { generated_stub("NpcAI::ENTITY_SINGE_body 0058aed0"); } uint8_t FUN_0058e210() { generated_stub("FUN_0058e210 0058e210"); } @@ -9924,25 +9726,19 @@ void FUN_005b1560() { generated_stub("FUN_005b1560 005b1560"); } void FUN_005b15a0(uint32_t param_1) { generated_stub("FUN_005b15a0 005b15a0"); } void FUN_005b15d0(uint32_t param_1) { generated_stub("FUN_005b15d0 005b15d0"); } void FUN_005b15f0(float *param_1) { generated_stub("FUN_005b15f0 005b15f0"); } -void FUN_005b1690(char param_1) { generated_stub("FUN_005b1690 005b1690"); } void FUN_005b16f0(uint8_t param_1) { generated_stub("FUN_005b16f0 005b16f0"); } uint32_t FUN_005b1720(int param_1) { generated_stub("FUN_005b1720 005b1720"); } -void FUN_005b17a0(uint8_t param_1) { generated_stub("FUN_005b17a0 005b17a0"); } -void FUN_005b17b0(uint32_t param_1) { generated_stub("FUN_005b17b0 005b17b0"); } int FUN_005b1820() { generated_stub("FUN_005b1820 005b1820"); } void FUN_005b1830(uint32_t param_1) { generated_stub("FUN_005b1830 005b1830"); } bool FUN_005b1840() { generated_stub("FUN_005b1840 005b1840"); } int FUN_005b18a0() { generated_stub("FUN_005b18a0 005b18a0"); } void FUN_005b18b0(int param_1) { generated_stub("FUN_005b18b0 005b18b0"); } -void FUN_005b18d0(uint32_t param_1) { generated_stub("FUN_005b18d0 005b18d0"); } uint8_t FUN_005b18e0() { generated_stub("FUN_005b18e0 005b18e0"); } void FUN_005b18f0(uint8_t param_1) { generated_stub("FUN_005b18f0 005b18f0"); } void FUN_005b1900() { generated_stub("FUN_005b1900 005b1900"); } void FUN_005b1910(uint32_t param_1) { generated_stub("FUN_005b1910 005b1910"); } void FUN_005b1920(uint32_t param_1) { generated_stub("FUN_005b1920 005b1920"); } -void FUN_005b1950(uint8_t param_1) { generated_stub("FUN_005b1950 005b1950"); } uint32_t FUN_005b1960() { generated_stub("FUN_005b1960 005b1960"); } -void FUN_005b1970(uint32_t param_1) { generated_stub("FUN_005b1970 005b1970"); } void FUN_005b1990(uint32_t param_1) { generated_stub("FUN_005b1990 005b1990"); } uint32_t FUN_005b19a0() { generated_stub("FUN_005b19a0 005b19a0"); } void FUN_005b19d0() { generated_stub("FUN_005b19d0 005b19d0"); } @@ -9999,9 +9795,6 @@ void FUN_005cd370(uint32_t param_1) { generated_stub("FUN_005cd370 005cd370"); } void FUN_005cd380(uint32_t param_1) { generated_stub("FUN_005cd380 005cd380"); } void FUN_005cd3a0(uint32_t param_1) { generated_stub("FUN_005cd3a0 005cd3a0"); } void FUN_005cd3c0() { generated_stub("FUN_005cd3c0 005cd3c0"); } -void FUN_005cd3d0(uint32_t param_1) { generated_stub("FUN_005cd3d0 005cd3d0"); } -void FUN_005cd3f0(uint32_t param_1) { generated_stub("FUN_005cd3f0 005cd3f0"); } -void FUN_005cd410(uint32_t param_1) { generated_stub("FUN_005cd410 005cd410"); } void FUN_005cd430(uint32_t *param_1) { generated_stub("FUN_005cd430 005cd430"); } int FUN_005cd470() { generated_stub("FUN_005cd470 005cd470"); } int FUN_005cd490(int param_1) { generated_stub("FUN_005cd490 005cd490"); } @@ -10018,7 +9811,6 @@ void FUN_005cd750() { generated_stub("FUN_005cd750 005cd750"); } void FUN_005cd760() { generated_stub("FUN_005cd760 005cd760"); } void FUN_005cd770() { generated_stub("FUN_005cd770 005cd770"); } void FUN_005cd780(uint32_t *param_1) { generated_stub("FUN_005cd780 005cd780"); } -void FUN_005cd7a0(uint32_t *param_1) { generated_stub("FUN_005cd7a0 005cd7a0"); } Vector * FUN_005cd7e0(Vector *param_1) { generated_stub("FUN_005cd7e0 005cd7e0"); } void FUN_005cd800() { generated_stub("FUN_005cd800 005cd800"); } AchievementOverlay * FUN_005cd810() { generated_stub("FUN_005cd810 005cd810"); } @@ -10078,8 +9870,6 @@ void FUN_0060d040() { generated_stub("FUN_0060d040 0060d040"); } void FUN_0060d060() { generated_stub("FUN_0060d060 0060d060"); } void FUN_0060d070() { generated_stub("FUN_0060d070 0060d070"); } void FUN_0060d0c0() { generated_stub("FUN_0060d0c0 0060d0c0"); } -void FUN_0060d0d0(uint32_t param_1) { generated_stub("FUN_0060d0d0 0060d0d0"); } -void FUN_0060d0f0(uint32_t param_1) { generated_stub("FUN_0060d0f0 0060d0f0"); } uint32_t FUN_0060d110() { generated_stub("FUN_0060d110 0060d110"); } bool FUN_0060d1c0(uint32_t param_1) { generated_stub("FUN_0060d1c0 0060d1c0"); } uint32_t FUN_0060d1e0() { generated_stub("FUN_0060d1e0 0060d1e0"); } @@ -10121,12 +9911,7 @@ void FUN_00652a70() { generated_stub("FUN_00652a70 00652a70"); } bool _has_flag_0x110(uint32_t param_1) { generated_stub("_has_flag_0x110 00652a90"); } int FUN_00652ae0() { generated_stub("FUN_00652ae0 00652ae0"); } bool FUN_0065cfe0(uint32_t param_1) { generated_stub("FUN_0065cfe0 0065cfe0"); } -int FUN_0065d010() { generated_stub("FUN_0065d010 0065d010"); } -void FUN_0065d020() { generated_stub("FUN_0065d020 0065d020"); } -void FUN_0065d040() { generated_stub("FUN_0065d040 0065d040"); } -uint32_t * FUN_0065d060() { generated_stub("FUN_0065d060 0065d060"); } void FUN_0065d070() { generated_stub("FUN_0065d070 0065d070"); } -std_vector * FUN_0065d090() { generated_stub("FUN_0065d090 0065d090"); } void FUN_0065d0a0() { generated_stub("FUN_0065d0a0 0065d0a0"); } void FUN_0065d0c0() { generated_stub("FUN_0065d0c0 0065d0c0"); } void FUN_0065d160() { generated_stub("FUN_0065d160 0065d160"); } @@ -10302,7 +10087,6 @@ void FUN_006a6910(uint32_t param_1, uint32_t param_2, uint32_t param_3, uint32_t void FUN_006a6930() { generated_stub("FUN_006a6930 006a6930"); } void FUN_006a7ec0() { generated_stub("FUN_006a7ec0 006a7ec0"); } void FUN_006a80d0() { generated_stub("FUN_006a80d0 006a80d0"); } -void FUN_006a8180(uint32_t param_1) { generated_stub("FUN_006a8180 006a8180"); } void FUN_006a8210(int param_1) { generated_stub("FUN_006a8210 006a8210"); } void FUN_006b5de0() { generated_stub("FUN_006b5de0 006b5de0"); } void FUN_006b5f40() { generated_stub("FUN_006b5f40 006b5f40"); } @@ -10334,7 +10118,6 @@ void FUN_006dac00(uint32_t *param_1, uint32_t param_2) { generated_stub("FUN_006 float log_precise(float value) { generated_stub("log_precise 006dac30"); } void FUN_006daca0(uint32_t param_1) { generated_stub("FUN_006daca0 006daca0"); } uint32_t FUN_006e1910(uint32_t param_1) { generated_stub("FUN_006e1910 006e1910"); } -void FUN_006e2ff0(int param_1) { generated_stub("FUN_006e2ff0 006e2ff0"); } void FUN_006ee330() { generated_stub("FUN_006ee330 006ee330"); } Vector * Isaac::GetRandomPickupVelocity(Vector *outVelocity, Vector *position, uint32_t pickupVelType, RNG *rng) { generated_stub("Isaac::GetRandomPickupVelocity 006ee440"); } int FUN_006ee640(int param_1, int param_2, uint32_t *param_3, uint32_t param_4) { generated_stub("FUN_006ee640 006ee640"); } @@ -10369,13 +10152,9 @@ void FUN_006f2fb0() { generated_stub("FUN_006f2fb0 006f2fb0"); } void FUN_006f3000() { generated_stub("FUN_006f3000 006f3000"); } void FUN_006f4170() { generated_stub("FUN_006f4170 006f4170"); } void FUN_006f5850(int *param_1, int *param_2, int param_3, uint32_t param_4, int param_5) { generated_stub("FUN_006f5850 006f5850"); } -void daily_challenge_params_assign(void *self, void *other) { generated_stub("daily_challenge_params_assign 006f6260"); } uint8_t FUN_006f9730() { generated_stub("FUN_006f9730 006f9730"); } -void FUN_006f9f20(int param_1) { generated_stub("FUN_006f9f20 006f9f20"); } void FUN_007008b0(int *param_1) { generated_stub("FUN_007008b0 007008b0"); } void FUN_00703140() { generated_stub("FUN_00703140 00703140"); } -void FUN_00704b50() { generated_stub("FUN_00704b50 00704b50"); } -void FUN_007068f0(int param_1) { generated_stub("FUN_007068f0 007068f0"); } uint32_t FUN_00708350() { generated_stub("FUN_00708350 00708350"); } void FUN_00708380() { generated_stub("FUN_00708380 00708380"); } void FUN_00708430(uint32_t param_1, uint32_t param_2, int param_3) { generated_stub("FUN_00708430 00708430"); } @@ -10412,10 +10191,7 @@ uint32_t FUN_00710370() { generated_stub("FUN_00710370 00710370"); } uint32_t FUN_007103a0() { generated_stub("FUN_007103a0 007103a0"); } Entity_Player * FUN_007103c0(uint32_t *param_1) { generated_stub("FUN_007103c0 007103c0"); } uint32_t FUN_00710f70(int param_1) { generated_stub("FUN_00710f70 00710f70"); } -void FUN_00711530(int param_1) { generated_stub("FUN_00711530 00711530"); } uint32_t FUN_00711740() { generated_stub("FUN_00711740 00711740"); } -void FUN_00718ed0(uint32_t param_1) { generated_stub("FUN_00718ed0 00718ed0"); } -void FUN_0071df70(uint8_t param_1) { generated_stub("FUN_0071df70 0071df70"); } void FUN_00721e60(int param_1, int param_2, int param_3, int param_4, int param_5, int param_6) { generated_stub("FUN_00721e60 00721e60"); } void FUN_00722020(int param_1) { generated_stub("FUN_00722020 00722020"); } void FUN_007221a0(uint32_t *param_1) { generated_stub("FUN_007221a0 007221a0"); } @@ -10458,13 +10234,9 @@ void FUN_00737e50() { generated_stub("FUN_00737e50 00737e50"); } void FUN_00737e80(uint32_t param_1, uint32_t param_2) { generated_stub("FUN_00737e80 00737e80"); } int * FUN_00738040(uint32_t *param_1, int param_2, uint32_t param_3) { generated_stub("FUN_00738040 00738040"); } void Catch_All_0073811e() { generated_stub("Catch_All_0073811e 0073811e"); } -void FUN_00738150(uint32_t param_1) { generated_stub("FUN_00738150 00738150"); } -void FUN_00738160(uint32_t param_1) { generated_stub("FUN_00738160 00738160"); } -void FUN_00738190(char param_1) { generated_stub("FUN_00738190 00738190"); } void FUN_00738260() { generated_stub("FUN_00738260 00738260"); } uint32_t FUN_00738330() { generated_stub("FUN_00738330 00738330"); } Minimap * FUN_00738380() { generated_stub("FUN_00738380 00738380"); } -void FUN_00738390(uint32_t param_1) { generated_stub("FUN_00738390 00738390"); } void FUN_007383b0() { generated_stub("FUN_007383b0 007383b0"); } int FUN_00738620(uint32_t param_1, uint32_t param_2) { generated_stub("FUN_00738620 00738620"); } void FUN_00741cc0() { generated_stub("FUN_00741cc0 00741cc0"); } @@ -10523,14 +10295,7 @@ void FUN_00753750(uint32_t *param_1) { generated_stub("FUN_00753750 00753750"); void FUN_00753770(uint8_t param_1) { generated_stub("FUN_00753770 00753770"); } void FUN_00753790() { generated_stub("FUN_00753790 00753790"); } void FUN_007537b0() { generated_stub("FUN_007537b0 007537b0"); } -void FUN_00753800(uint32_t param_1) { generated_stub("FUN_00753800 00753800"); } void FUN_00753830(uint32_t *param_1, uint32_t *param_2, uint32_t param_3, uint32_t param_4, uint32_t param_5, uint32_t param_6) { generated_stub("FUN_00753830 00753830"); } -void FUN_00753870() { generated_stub("FUN_00753870 00753870"); } -void FUN_00753880() { generated_stub("FUN_00753880 00753880"); } -void FUN_00753890() { generated_stub("FUN_00753890 00753890"); } -void FUN_007538a0() { generated_stub("FUN_007538a0 007538a0"); } -void FUN_007538b0() { generated_stub("FUN_007538b0 007538b0"); } -void FUN_007538c0() { generated_stub("FUN_007538c0 007538c0"); } uint8_t FUN_007538d0() { generated_stub("FUN_007538d0 007538d0"); } uint32_t FUN_007538e0() { generated_stub("FUN_007538e0 007538e0"); } void FUN_007539a0() { generated_stub("FUN_007539a0 007539a0"); } @@ -10540,7 +10305,6 @@ uint8_t FUN_00753d20() { generated_stub("FUN_00753d20 00753d20"); } uint32_t FUN_00753d30() { generated_stub("FUN_00753d30 00753d30"); } void FUN_00753d40(uint32_t param_1) { generated_stub("FUN_00753d40 00753d40"); } uint32_t FUN_00753d50() { generated_stub("FUN_00753d50 00753d50"); } -uint32_t FUN_00753d60(uint32_t *param_1) { generated_stub("FUN_00753d60 00753d60"); } void input_state_reset(void *self) { generated_stub("input_state_reset 00754980"); } void FUN_00757980(uint32_t *param_1) { generated_stub("FUN_00757980 00757980"); } void FUN_00757a10() { generated_stub("FUN_00757a10 00757a10"); } @@ -10549,8 +10313,6 @@ int FUN_00759260() { generated_stub("FUN_00759260 00759260"); } void FUN_00770640(float *param_1) { generated_stub("FUN_00770640 00770640"); } void FUN_007792f0(uint32_t param_1, uint32_t param_2) { generated_stub("FUN_007792f0 007792f0"); } uint32_t FUN_007826c0() { generated_stub("FUN_007826c0 007826c0"); } -void FUN_007829a0() { generated_stub("FUN_007829a0 007829a0"); } -void FUN_00782ab0(uint32_t param_1) { generated_stub("FUN_00782ab0 00782ab0"); } void FUN_0078b330(uint32_t *param_1) { generated_stub("FUN_0078b330 0078b330"); } int FUN_007919c0() { generated_stub("FUN_007919c0 007919c0"); } Entity_Player * FUN_007a0fe0() { generated_stub("FUN_007a0fe0 007a0fe0"); } @@ -10658,10 +10420,6 @@ void Catch_All_007e8a8b() { generated_stub("Catch_All_007e8a8b 007e8a8b"); } void FUN_007e8b50(uint32_t param_1, uint32_t *param_2) { generated_stub("FUN_007e8b50 007e8b50"); } void FUN_007e8d00(uint32_t *param_1) { generated_stub("FUN_007e8d00 007e8d00"); } void FUN_007e8f70() { generated_stub("FUN_007e8f70 007e8f70"); } -void FUN_007e9150(char param_1) { generated_stub("FUN_007e9150 007e9150"); } -void FUN_007e9170(char param_1) { generated_stub("FUN_007e9170 007e9170"); } -void FUN_007e92e0(uint32_t param_1, uint32_t param_2) { generated_stub("FUN_007e92e0 007e92e0"); } -void FUN_007e93d0(int param_1) { generated_stub("FUN_007e93d0 007e93d0"); } void FUN_007ea0c0() { generated_stub("FUN_007ea0c0 007ea0c0"); } void FUN_00812ea0(float *param_1, int *param_2, int *param_3) { generated_stub("FUN_00812ea0 00812ea0"); } uint32_t FUN_00813420(int param_1, int param_2) { generated_stub("FUN_00813420 00813420"); } @@ -10691,7 +10449,6 @@ void FUN_0082e290(int param_1, int param_2, int param_3) { generated_stub("FUN_0 void Catch_All_0082e7ec() { generated_stub("Catch_All_0082e7ec 0082e7ec"); } void FUN_0082ea50(uint32_t param_1, uint32_t *param_2, code *param_3) { generated_stub("FUN_0082ea50 0082ea50"); } void FUN_0082eb20(uint32_t *param_1, code *param_2) { generated_stub("FUN_0082eb20 0082eb20"); } -void FUN_008332a0(char param_1) { generated_stub("FUN_008332a0 008332a0"); } uint64_t * FUN_00834c60(uint64_t *param_1, uint64_t *param_2) { generated_stub("FUN_00834c60 00834c60"); } void Catch_All_00834f6f() { generated_stub("Catch_All_00834f6f 00834f6f"); } void FUN_00834fa0(int param_1, int param_2, int param_3) { generated_stub("FUN_00834fa0 00834fa0"); } @@ -10736,7 +10493,6 @@ void FUN_0083c320(int *param_1, int *param_2) { generated_stub("FUN_0083c320 008 void FUN_0083c480() { generated_stub("FUN_0083c480 0083c480"); } char * FUN_00840510() { generated_stub("FUN_00840510 00840510"); } std_string * int_to_string(std_string *outString, int value) { generated_stub("int_to_string 00840540"); } -void FUN_0084abc0(uint32_t *param_1, float *param_2, uint32_t *param_3, uint32_t *param_4) { generated_stub("FUN_0084abc0 0084abc0"); } void FUN_0084bba0() { generated_stub("FUN_0084bba0 0084bba0"); } void FUN_0084bbc0(uint32_t *param_1) { generated_stub("FUN_0084bbc0 0084bbc0"); } void FUN_0084bc00(uint32_t *param_1) { generated_stub("FUN_0084bc00 0084bc00"); } @@ -10761,8 +10517,6 @@ uint8_t date_is_within_week(void *leaderboard) { generated_stub("date_is_within_ uint8_t date_is_after(void *dateRange) { generated_stub("date_is_after 00857e40"); } uint32_t FUN_00857ff0() { generated_stub("FUN_00857ff0 00857ff0"); } int FUN_00858370() { generated_stub("FUN_00858370 00858370"); } -uint8_t * FUN_00858870(int param_1) { generated_stub("FUN_00858870 00858870"); } -void leaderboard_render_label_value(Vector *pos, uint8_t *label, int value) { generated_stub("leaderboard_render_label_value 00859100"); } void FUN_0085a8b0() { generated_stub("FUN_0085a8b0 0085a8b0"); } void FUN_0085a8f0(int *param_1, int *param_2) { generated_stub("FUN_0085a8f0 0085a8f0"); } void FUN_0085a9d0(int *param_1, int *param_2) { generated_stub("FUN_0085a9d0 0085a9d0"); } @@ -10778,140 +10532,11 @@ void FUN_0085b790() { generated_stub("FUN_0085b790 0085b790"); } void lobby_password_render(void *password, Vector *position, float scale) { generated_stub("lobby_password_render 0085b7f0"); } uint8_t FUN_0085bd40(uint32_t param_1, int *param_2, int *param_3) { generated_stub("FUN_0085bd40 0085bd40"); } void FUN_0085be70() { generated_stub("FUN_0085be70 0085be70"); } -void FUN_0085bf50(uint32_t param_1) { generated_stub("FUN_0085bf50 0085bf50"); } -void FUN_0085bf90() { generated_stub("FUN_0085bf90 0085bf90"); } -void FUN_0085c010() { generated_stub("FUN_0085c010 0085c010"); } -void FUN_0085c030() { generated_stub("FUN_0085c030 0085c030"); } -void FUN_0085c050() { generated_stub("FUN_0085c050 0085c050"); } -void FUN_0085c1d0() { generated_stub("FUN_0085c1d0 0085c1d0"); } -int * FUN_0085c200() { generated_stub("FUN_0085c200 0085c200"); } -void FUN_0085c210(uint8_t param_1) { generated_stub("FUN_0085c210 0085c210"); } -void FUN_0085c250() { generated_stub("FUN_0085c250 0085c250"); } -bool FUN_0085c2d0() { generated_stub("FUN_0085c2d0 0085c2d0"); } -bool FUN_0085c300() { generated_stub("FUN_0085c300 0085c300"); } -bool FUN_0085c340() { generated_stub("FUN_0085c340 0085c340"); } -uint8_t FUN_0085c390() { generated_stub("FUN_0085c390 0085c390"); } -uint32_t FUN_0085c3e0() { generated_stub("FUN_0085c3e0 0085c3e0"); } -void FUN_0085c7e0(uint8_t param_1) { generated_stub("FUN_0085c7e0 0085c7e0"); } -uint32_t FUN_0085c810(uint32_t param_1) { generated_stub("FUN_0085c810 0085c810"); } -uint32_t FUN_0085c970(uint32_t param_1) { generated_stub("FUN_0085c970 0085c970"); } -uint32_t luabridge::CFunc::readOnlyError(uint32_t param_1) { generated_stub("luabridge::CFunc::readOnlyError 0085cad0"); } -void FUN_0085cce0(uint32_t param_1) { generated_stub("FUN_0085cce0 0085cce0"); } -uint32_t FUN_0085cd40(uint32_t param_1) { generated_stub("FUN_0085cd40 0085cd40"); } -uint32_t FUN_0085cf30(uint32_t param_1) { generated_stub("FUN_0085cf30 0085cf30"); } -void FUN_0085d500(uint32_t param_1) { generated_stub("FUN_0085d500 0085d500"); } void FUN_0085d6f0() { generated_stub("FUN_0085d6f0 0085d6f0"); } -uint32_t * FUN_0085d730(uint32_t param_1, uint32_t *param_2) { generated_stub("FUN_0085d730 0085d730"); } -void FUN_0085d910(uint32_t *param_1) { generated_stub("FUN_0085d910 0085d910"); } -uint32_t FUN_0085da00(uint32_t param_1, uint32_t param_2) { generated_stub("FUN_0085da00 0085da00"); } -void FUN_0085da20(uint32_t param_1, uint32_t param_2) { generated_stub("FUN_0085da20 0085da20"); } -void FUN_0085da70(int param_1) { generated_stub("FUN_0085da70 0085da70"); } -void FUN_0085dab0() { generated_stub("FUN_0085dab0 0085dab0"); } -void FUN_0085dae0(uint32_t *param_1) { generated_stub("FUN_0085dae0 0085dae0"); } -void FUN_0085dbf0(char param_1) { generated_stub("FUN_0085dbf0 0085dbf0"); } -void FUN_0085dc10(char param_1) { generated_stub("FUN_0085dc10 0085dc10"); } uint32_t * FUN_0085ded0(uint32_t *param_1) { generated_stub("FUN_0085ded0 0085ded0"); } -void FUN_0085e1d0(char param_1) { generated_stub("FUN_0085e1d0 0085e1d0"); } -void FUN_0085e2a0(uint32_t *param_1) { generated_stub("FUN_0085e2a0 0085e2a0"); } -void FUN_0085e340(uint32_t param_1) { generated_stub("FUN_0085e340 0085e340"); } -void FUN_0085e3b0(uint32_t param_1) { generated_stub("FUN_0085e3b0 0085e3b0"); } -uint32_t Catch_00860f8b() { generated_stub("Catch_00860f8b 00860f8b"); } -uint32_t Catch_00861076() { generated_stub("Catch_00861076 00861076"); } -uint32_t Catch_0086166f() { generated_stub("Catch_0086166f 0086166f"); } -uint32_t Catch_0086174f() { generated_stub("Catch_0086174f 0086174f"); } -uint32_t Catch_00861837() { generated_stub("Catch_00861837 00861837"); } -uint32_t Catch_008619ff() { generated_stub("Catch_008619ff 008619ff"); } -uint32_t Catch_00861b88() { generated_stub("Catch_00861b88 00861b88"); } -void FUN_00861bda() { generated_stub("FUN_00861bda 00861bda"); } -void FUN_00861c23() { generated_stub("FUN_00861c23 00861c23"); } -uint32_t Catch_00861f2f() { generated_stub("Catch_00861f2f 00861f2f"); } -uint32_t Catch_0086200f() { generated_stub("Catch_0086200f 0086200f"); } -uint32_t Catch_00862198() { generated_stub("Catch_00862198 00862198"); } -void FUN_008621ea() { generated_stub("FUN_008621ea 008621ea"); } -void FUN_00862233() { generated_stub("FUN_00862233 00862233"); } -uint32_t Catch_0086253f() { generated_stub("Catch_0086253f 0086253f"); } -uint32_t Catch_0086261f() { generated_stub("Catch_0086261f 0086261f"); } -uint32_t Catch_00862707() { generated_stub("Catch_00862707 00862707"); } -void FUN_00862d0a() { generated_stub("FUN_00862d0a 00862d0a"); } -void FUN_00862d53() { generated_stub("FUN_00862d53 00862d53"); } -uint32_t Catch_0086362b() { generated_stub("Catch_0086362b 0086362b"); } -uint32_t Catch_00863879() { generated_stub("Catch_00863879 00863879"); } -uint32_t Catch_00863c6e() { generated_stub("Catch_00863c6e 00863c6e"); } -uint32_t Catch_00863d4e() { generated_stub("Catch_00863d4e 00863d4e"); } -uint32_t Catch_008641bb() { generated_stub("Catch_008641bb 008641bb"); } -uint32_t Catch_008642a4() { generated_stub("Catch_008642a4 008642a4"); } -uint32_t Catch_00864682() { generated_stub("Catch_00864682 00864682"); } -uint8_t * Catch_00864e6d() { generated_stub("Catch_00864e6d 00864e6d"); } -uint32_t Catch_0086504e() { generated_stub("Catch_0086504e 0086504e"); } -uint32_t Catch_0086512e() { generated_stub("Catch_0086512e 0086512e"); } -uint8_t * Catch_008655b7() { generated_stub("Catch_008655b7 008655b7"); } -void FUN_00865aad() { generated_stub("FUN_00865aad 00865aad"); } -void FUN_00865c61() { generated_stub("FUN_00865c61 00865c61"); } -uint32_t Catch_00866364() { generated_stub("Catch_00866364 00866364"); } -uint8_t FUN_008663b6() { generated_stub("FUN_008663b6 008663b6"); } -void FUN_00866474() { generated_stub("FUN_00866474 00866474"); } -uint8_t * Catch_0086675e() { generated_stub("Catch_0086675e 0086675e"); } -uint32_t Catch_008668e0() { generated_stub("Catch_008668e0 008668e0"); } -void FUN_0086e4d0() { generated_stub("FUN_0086e4d0 0086e4d0"); } void FUN_00870f21() { generated_stub("FUN_00870f21 00870f21"); } void FUN_00871eb0() { generated_stub("FUN_00871eb0 00871eb0"); } -void FUN_00871f70(int *param_1, uint32_t param_2) { generated_stub("FUN_00871f70 00871f70"); } -void FUN_00871fa0(Entity *param_1, float param_2) { generated_stub("FUN_00871fa0 00871fa0"); } -void render_debug_lua_memory() { generated_stub("render_debug_lua_memory 00872090"); } -uint32_t FUN_00872510(uint32_t param_1) { generated_stub("FUN_00872510 00872510"); } -void FUN_00872530(uint32_t param_1, uint32_t param_2) { generated_stub("FUN_00872530 00872530"); } -void FUN_00872590() { generated_stub("FUN_00872590 00872590"); } int std_set_int_erase_key(void *self, int *key) { generated_stub("std_set_int_erase_key 008725f0"); } -void FUN_00872730(void *param_1) { generated_stub("FUN_00872730 00872730"); } -void FUN_00872780(void *param_1) { generated_stub("FUN_00872780 00872780"); } -bool FUN_00872820() { generated_stub("FUN_00872820 00872820"); } -char * FUN_00872860(char *param_1) { generated_stub("FUN_00872860 00872860"); } -void FUN_00872a0c() { generated_stub("FUN_00872a0c 00872a0c"); } -void FUN_00872af1() { generated_stub("FUN_00872af1 00872af1"); } -void FUN_00872c43() { generated_stub("FUN_00872c43 00872c43"); } -void FUN_00872d80() { generated_stub("FUN_00872d80 00872d80"); } -uint32_t * FUN_00872da0(uint32_t *param_1, uint32_t param_2, int param_3) { generated_stub("FUN_00872da0 00872da0"); } -void FUN_00872e71() { generated_stub("FUN_00872e71 00872e71"); } -int * FUN_00872e90(int *param_1, uint32_t param_2, int param_3, uint32_t param_4, uint32_t param_5) { generated_stub("FUN_00872e90 00872e90"); } -void FUN_00872fc3() { generated_stub("FUN_00872fc3 00872fc3"); } -void FUN_008730c1() { generated_stub("FUN_008730c1 008730c1"); } -void FUN_00873213() { generated_stub("FUN_00873213 00873213"); } -uint32_t * FUN_00873230(uint32_t *param_1, uint32_t param_2, int param_3) { generated_stub("FUN_00873230 00873230"); } -void FUN_00873301() { generated_stub("FUN_00873301 00873301"); } -int * FUN_00873320(int *param_1, uint32_t param_2, int param_3, uint32_t param_4, uint32_t param_5) { generated_stub("FUN_00873320 00873320"); } -void FUN_00873453() { generated_stub("FUN_00873453 00873453"); } -void FUN_00873541() { generated_stub("FUN_00873541 00873541"); } -uint32_t * FUN_00873560(uint32_t *param_1, uint32_t param_2, int param_3) { generated_stub("FUN_00873560 00873560"); } -void FUN_00873631() { generated_stub("FUN_00873631 00873631"); } -uint32_t * FUN_00873650(uint32_t *param_1, uint32_t param_2, int param_3) { generated_stub("FUN_00873650 00873650"); } -void FUN_00873721() { generated_stub("FUN_00873721 00873721"); } -int * FUN_00873740(int *param_1, uint32_t param_2, int param_3, uint32_t param_4, uint32_t param_5) { generated_stub("FUN_00873740 00873740"); } -void FUN_00873873() { generated_stub("FUN_00873873 00873873"); } -void FUN_00873961() { generated_stub("FUN_00873961 00873961"); } -void FUN_00873aa0() { generated_stub("FUN_00873aa0 00873aa0"); } -void FUN_00873b91() { generated_stub("FUN_00873b91 00873b91"); } -void FUN_00873ce3() { generated_stub("FUN_00873ce3 00873ce3"); } -void FUN_00873e20() { generated_stub("FUN_00873e20 00873e20"); } -void FUN_00873f26() { generated_stub("FUN_00873f26 00873f26"); } -void FUN_00874103() { generated_stub("FUN_00874103 00874103"); } -void FUN_008741f1() { generated_stub("FUN_008741f1 008741f1"); } -void FUN_008742f7() { generated_stub("FUN_008742f7 008742f7"); } -void FUN_008743eb() { generated_stub("FUN_008743eb 008743eb"); } -int * FUN_00874400(int *param_1, uint32_t param_2, int param_3, uint32_t param_4, uint32_t param_5) { generated_stub("FUN_00874400 00874400"); } -void FUN_00874533() { generated_stub("FUN_00874533 00874533"); } -int * FUN_00874550(int *param_1, uint32_t param_2, int param_3, float param_4, uint32_t param_5, uint32_t param_6, int param_7) { generated_stub("FUN_00874550 00874550"); } -void FUN_0087469a() { generated_stub("FUN_0087469a 0087469a"); } -void FUN_00874846() { generated_stub("FUN_00874846 00874846"); } -void FUN_008748f6() { generated_stub("FUN_008748f6 008748f6"); } -void FUN_008749f7() { generated_stub("FUN_008749f7 008749f7"); } -void FUN_00874aa8() { generated_stub("FUN_00874aa8 00874aa8"); } -void FUN_00874bbb() { generated_stub("FUN_00874bbb 00874bbb"); } -uint32_t * FUN_00874bd0(uint32_t *param_1, uint32_t param_2, void *param_3) { generated_stub("FUN_00874bd0 00874bd0"); } -void FUN_00874d0a() { generated_stub("FUN_00874d0a 00874d0a"); } -void FUN_00874db6() { generated_stub("FUN_00874db6 00874db6"); } -void FUN_00874e7e() { generated_stub("FUN_00874e7e 00874e7e"); } -void FUN_00874f4a() { generated_stub("FUN_00874f4a 00874f4a"); } -uint32_t * FUN_00875050(uint32_t *param_1, uint32_t param_2, uint32_t param_3, uint16_t param_4, uint16_t param_5, uint32_t param_6) { generated_stub("FUN_00875050 00875050"); } void FUN_00875116() { generated_stub("FUN_00875116 00875116"); } uint32_t * FUN_00875130() { generated_stub("FUN_00875130 00875130"); } uint32_t * FUN_00875230(uint32_t param_1, uint32_t param_2) { generated_stub("FUN_00875230 00875230"); } @@ -11148,7 +10773,6 @@ void FUN_00882c90() { generated_stub("FUN_00882c90 00882c90"); } void FUN_00882cf0(uint32_t param_1, uint32_t param_2) { generated_stub("FUN_00882cf0 00882cf0"); } void FUN_00882ed0() { generated_stub("FUN_00882ed0 00882ed0"); } void FUN_00882f30() { generated_stub("FUN_00882f30 00882f30"); } -void FUN_00882f90() { generated_stub("FUN_00882f90 00882f90"); } uint32_t * FUN_00882ff0() { generated_stub("FUN_00882ff0 00882ff0"); } uint32_t * FUN_00883220() { generated_stub("FUN_00883220 00883220"); } void FUN_00883320() { generated_stub("FUN_00883320 00883320"); } @@ -12944,7 +12568,6 @@ void Catch_All_009b1d88() { generated_stub("Catch_All_009b1d88 009b1d88"); } int FUN_009b1dc0(int param_1, int param_2, int param_3) { generated_stub("FUN_009b1dc0 009b1dc0"); } int FUN_009b5800() { generated_stub("FUN_009b5800 009b5800"); } uint32_t FUN_009b9450(int param_1) { generated_stub("FUN_009b9450 009b9450"); } -void FUN_009ba9a0() { generated_stub("FUN_009ba9a0 009ba9a0"); } void FUN_009baa10(char param_1) { generated_stub("FUN_009baa10 009baa10"); } int FUN_009bac00(int param_1) { generated_stub("FUN_009bac00 009bac00"); } void entity_vector_set_flag_410(void *self, uint8_t value) { generated_stub("entity_vector_set_flag_410 009bea10"); } @@ -12999,16 +12622,6 @@ void FUN_009d88a0(uint32_t param_1) { generated_stub("FUN_009d88a0 009d88a0"); } void FUN_009d8a20(uint32_t param_1, uint8_t *param_2) { generated_stub("FUN_009d8a20 009d8a20"); } void FUN_009db250(uint32_t param_1, uint8_t param_2, int *param_3) { generated_stub("FUN_009db250 009db250"); } void FUN_009dc5a0(char param_1, int param_2) { generated_stub("FUN_009dc5a0 009dc5a0"); } -uint32_t utf8_string_writer_write(int param_1, int param_2) { generated_stub("utf8_string_writer_write 009dcbb0"); } -uint32_t FUN_009e0150(uint32_t param_1) { generated_stub("FUN_009e0150 009e0150"); } -uint32_t FUN_009e0180(uint32_t param_1) { generated_stub("FUN_009e0180 009e0180"); } -void FUN_009e0390() { generated_stub("FUN_009e0390 009e0390"); } -void FUN_009e03d0(int param_1) { generated_stub("FUN_009e03d0 009e03d0"); } -void FUN_009e0450(int param_1) { generated_stub("FUN_009e0450 009e0450"); } -uint8_t collectible_set_has(void *self, int collectibleId) { generated_stub("collectible_set_has 009e04b0"); } -uint8_t FUN_009e0650(int param_1) { generated_stub("FUN_009e0650 009e0650"); } -void trigger_set_dispatch(void *self, int triggerType, Entity *entity, Vector *position, Vector *velocity) { generated_stub("trigger_set_dispatch 009e0680"); } -void FUN_009e24f0(uint32_t *param_1, uint32_t param_2) { generated_stub("FUN_009e24f0 009e24f0"); } void FUN_009e2520(void *param_1) { generated_stub("FUN_009e2520 009e2520"); } void FUN_009e2580(int *param_1, uint32_t *param_2) { generated_stub("FUN_009e2580 009e2580"); } int * FUN_009e2760(int *param_1, uint32_t *param_2) { generated_stub("FUN_009e2760 009e2760"); } diff --git a/generated-src/vector.cpp b/generated-src/vector.cpp index 7fdbe7c..09d85e5 100644 --- a/generated-src/vector.cpp +++ b/generated-src/vector.cpp @@ -176,12 +176,6 @@ float Vector::Dot(Vector *other) return other->x * this->x + other->y * this->y; } -// 00a101a0 -float Vector::Cross(Vector *other) -{ - return other->y * this->x - this->y * other->x; -} - // 00a10270 void Vector::Rotate(float angleDegrees) { @@ -235,54 +229,6 @@ float Vector::GetAngleDegrees() return angleRadians * 57.295776; } -// 00a103c0 -void Vector::Clamp(float minX, float minY, float maxX, float maxY) -{ - float clamped; - - clamped = this->x; - if (this->x <= minX) { - clamped = minX; - } - if (maxX <= clamped) { - clamped = maxX; - } - this->x = clamped; - clamped = this->y; - if (this->y <= minY) { - clamped = minY; - } - if (maxY <= clamped) { - clamped = maxY; - } - this->y = clamped; - return; -} - -// 00a103f0 -Vector * Vector::Clamped(Vector *outResult, float minX, float minY, float maxX, float maxY) -{ - float clamped; - - clamped = this->x; - if (this->x <= minX) { - clamped = minX; - } - if (maxX <= clamped) { - clamped = maxX; - } - outResult->x = clamped; - clamped = this->y; - if (this->y <= minY) { - clamped = minY; - } - if (maxY <= clamped) { - clamped = maxY; - } - outResult->y = clamped; - return outResult; -} - // 00a10420 Vector * Vector::__add(Vector *outVec, Vector *other) { diff --git a/src/active_items.h b/src/active_items.h index 638cdc8..5829013 100644 --- a/src/active_items.h +++ b/src/active_items.h @@ -131,7 +131,6 @@ bool is_active_slot_kept(Entity_Player& player, int slot); void active_collectible_add(Entity_Player& player, ItemConfig_Item& item, const ActiveGain& gain); bool active_pedestal_swap(Entity_Pickup& pickup, Entity_Player& player); bool battery_collect(Entity_Pickup& battery, Entity_Player& player); -bool is_temporary_effect_plain(const TemporaryEffect& effect); bool history_item_remove(History& history, const HistoryItem& item); bool pocket_item_collect(Entity_Pickup& pocket, Entity_Player& player); void tears_up_unlock_check(Entity_Player& player); diff --git a/src/ambush.cpp b/src/ambush.cpp index d152aa7..c9defd2 100644 --- a/src/ambush.cpp +++ b/src/ambush.cpp @@ -41,7 +41,6 @@ constexpr int DOOR_STOP_CHALLENGE = 3; // The Boss Rush's bosses rise round an ellipse 200 by 180 about the room's centre, Gurdy 80 and Mega Maw 160 below the // top, at least 40 from a player (stepping 60 away), the segments of a boss 20 apart. Gurdy clears three cells round. -constexpr float BOSS_RUSH_FULL_TURN = 6.2831855f; constexpr float BOSS_RUSH_RING_X = 200; constexpr float BOSS_RUSH_RING_Y = 180; constexpr float BOSS_RUSH_GURDY_DROP = 80; @@ -216,7 +215,7 @@ static Vector boss_rush_spot_find(int type, float angle) Entity_Player* player = game_nearest_player(spot); if (player && vector_length_squared(vector_sub(spot, player->pos)) < BOSS_RUSH_PLAYER_CLEAR * BOSS_RUSH_PLAYER_CLEAR) { - float away = random_unit() * RANDOM_HALF_TURN * 2; + float away = random_unit() * PI_ROUGH * 2; spot = vector_add(spot, vector_scale(vector_make(std::cos(away), std::sin(away)), BOSS_RUSH_PLAYER_STEP)); } return room_free_pickup_position_find({.position = spot}); @@ -258,7 +257,7 @@ void Ambush::SpawnBossrushWave() if (bosses.empty()) KAGE_LogMessage(LOG_ASSERT, (uint8_t*)"Wave has no entries!"); float angle = 0; - float angleStep = BOSS_RUSH_FULL_TURN / (float)bosses.size(); + float angleStep = TAU / (float)bosses.size(); for (const BossRushEntry& boss : bosses) { Vector spot = boss_rush_spot_find(boss.type, angle); diff --git a/src/anm2.cpp b/src/anm2.cpp index 953a93e..d438b48 100644 --- a/src/anm2.cpp +++ b/src/anm2.cpp @@ -35,12 +35,7 @@ constexpr int LOG_MESSAGE_SIZE = 1024; constexpr int FRAME_INDEX_UNSET = -1; constexpr uint32_t EVENT_BIT_MASK = 31; constexpr float CHANNEL = 255; -constexpr float PERCENT = 100; -constexpr float DEGREES_HALF_TURN = 180; -constexpr float DEGREES_TURN = 360; -constexpr float RADIANS_PER_DEGREE = 0.017453292f; constexpr float GLITCH_TURN = 90; -constexpr int SHIMMER_STEPS = 256; constexpr std::string_view SHADOW_LAYER_NAME = "shadow"; constexpr std::string_view APPEAR_ANIMATION = "Appear"; constexpr std::string_view IDLE_ANIMATION = "Idle"; @@ -148,9 +143,9 @@ void color_multiply(ColorMod& color, const ColorMod& other) // An angle brought into [-180, 180] degrees. static float angle_wrap(float angle) { - if (std::fabs(angle) > DEGREES_TURN) angle = (float)std::fmod((double)angle, (double)DEGREES_TURN); - if (angle > DEGREES_HALF_TURN) return angle - DEGREES_TURN; - if (angle < -DEGREES_HALF_TURN) return angle + DEGREES_TURN; + if (std::fabs(angle) > FULL_TURN_DEGREES) angle = (float)std::fmod((double)angle, (double)FULL_TURN_DEGREES); + if (angle > HALF_TURN_DEGREES) return angle - FULL_TURN_DEGREES; + if (angle < -HALF_TURN_DEGREES) return angle + FULL_TURN_DEGREES; return angle; } @@ -159,10 +154,10 @@ float angle_lerp(float from, float to, float t) { from = angle_wrap(from); to = angle_wrap(to); - if (std::fabs(to - from) > DEGREES_HALF_TURN) + if (std::fabs(to - from) > HALF_TURN_DEGREES) { - if (to > from) from += DEGREES_TURN; - else to += DEGREES_TURN; + if (to > from) from += FULL_TURN_DEGREES; + else to += FULL_TURN_DEGREES; } return angle_wrap((to - from) * t + from); } @@ -1164,8 +1159,8 @@ DestinationQuad AnimationLayer::GetDestQuad(const AnimationFrame& frame, const L (top + frame.height) - draw.bottomRightClamp.y / layerScale.y); quad_scale(quad, layerOrigin, layerScale); quad_scale(quad, spriteOrigin, spriteScale); - quad_rotate(quad, layerOrigin, layerRotation * RADIANS_PER_DEGREE); - quad_rotate(quad, spriteOrigin, spriteRotation * RADIANS_PER_DEGREE); + quad_rotate(quad, layerOrigin, layerRotation * DEGREES_TO_RADIANS); + quad_rotate(quad, spriteOrigin, spriteRotation * DEGREES_TO_RADIANS); return quad; } @@ -1207,7 +1202,7 @@ static void procedural_item_turn(SourceQuad& source, const AnimationFrame& frame 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); + quad_rotate(source, center, (rng.RandomInt(2) == 0 ? GLITCH_TURN : -GLITCH_TURN) * DEGREES_TO_RADIANS); if (rng.RandomInt(2) != 0) quad_columns_swap(source); } @@ -1263,7 +1258,7 @@ void AnimationLayer::RenderFrame(const SpriteDraw& draw, int frameIndex, const A { bool isGameTime = !(flags & ANIM_RENDER_IGNORE_GAME_TIME); int frameCount = isGameTime ? g_game->frameCount : (int)(g_manager->framecount / 2); - color._colorize[3] = (float)(frameCount % SHIMMER_STEPS) / SHIMMER_STEPS; + color._colorize[3] = (float)(frameCount % GOLD_SHIMMER_STEPS) / GOLD_SHIMMER_STEPS; } KColor tint; diff --git a/src/anm2.h b/src/anm2.h index ecacefd..be26e98 100644 --- a/src/anm2.h +++ b/src/anm2.h @@ -120,6 +120,13 @@ constexpr float HALF_TURN_DEGREES = 180; constexpr float RIGHT_ANGLE_DEGREES = 90; constexpr float DIAGONAL = 0.70710677f; constexpr float HALF = 0.5f; +// A quarter turn in radians, the original's rough half turn (3.14), a hundred percent, and a color byte as a unit. +constexpr float QUARTER_TURN = PI_F / 2; +constexpr float PI_ROUGH = 3.14f; +constexpr int PERCENT = 100; +constexpr float BYTE_TO_UNIT = 1 / 255.0f; +// The steps of a golden or static sprite's shimmer. +constexpr int GOLD_SHIMMER_STEPS = 256; inline Vector vector_add(Vector a, Vector b) { @@ -168,6 +175,12 @@ inline float vector_distance(Vector a, Vector b) return vector_length(vector_sub(a, b)); } +// Vector::operator==: whether two vectors match, never for one holding a NaN. +inline bool vector_equal(Vector a, Vector b) +{ + return a.x == b.x && a.y == b.y; +} + inline bool vector_is_zero(Vector v) { return v.x == 0 && v.y == 0; diff --git a/src/backdrop.cpp b/src/backdrop.cpp index 86ed15f..1ce7ad6 100644 --- a/src/backdrop.cpp +++ b/src/backdrop.cpp @@ -190,7 +190,6 @@ constexpr float TAR_OUT_MIN = 20; constexpr float TAR_OUT_RANGE = 40; constexpr float TAR_SHIFT_RANGE = 10; constexpr float TAR_SCALE_RANGE = 4; -constexpr float HALF_TURN = 1.5707964f; constexpr int DROSS_LIGHT_FIRST = 3; constexpr int DROSS_LIGHT_ODDS = 40; constexpr float DROSS_LIGHT_SCALE = 0.5f; @@ -1599,8 +1598,8 @@ static void dank_details_spawn(Backdrop& backdrop, const WallSlot& slot) Vector center = wall_center(slot.quad); float out = backdrop.rng.RandomFloat() * TAR_OUT_RANGE + TAR_OUT_MIN; Vector position = vector_make(normal.x * out + center.x, normal.y * out + center.y); - float cosine = std::cos(HALF_TURN); - float sine = std::sin(HALF_TURN); + float cosine = std::cos(QUARTER_TURN); + float sine = std::sin(QUARTER_TURN); Vector along = vector_make(normal.x * cosine - normal.y * sine, normal.y * cosine + normal.x * sine); float shift = backdrop.rng.RandomFloat() * TAR_SHIFT_RANGE - TAR_SHIFT_RANGE; position.x += shift * along.x; diff --git a/src/beam_renderer.cpp b/src/beam_renderer.cpp index cb97e6f..c78891f 100644 --- a/src/beam_renderer.cpp +++ b/src/beam_renderer.cpp @@ -6,7 +6,6 @@ #include // A point's edges spread along its direction turned a quarter, and a joint's normal is never shortened past this. -constexpr float BEAM_NORMAL_TURN = 1.5707964f; constexpr float JOINT_DOT_MIN = 0.4f; constexpr float HALF_WIDTH = 0.5f; @@ -17,8 +16,8 @@ BeamRenderer g_beamRenderer; static Vector normal_get(Vector from, Vector to) { Vector direction = vector_normalized(vector_sub(to, from)); - float cosine = std::cos(BEAM_NORMAL_TURN); - float sine = std::sin(BEAM_NORMAL_TURN); + float cosine = std::cos(QUARTER_TURN); + float sine = std::sin(QUARTER_TURN); return vector_make(direction.x * cosine - direction.y * sine, sine * direction.x + cosine * direction.y); } diff --git a/src/bomb_explosion.cpp b/src/bomb_explosion.cpp index 6fe2f8f..ee3d1ae 100644 --- a/src/bomb_explosion.cpp +++ b/src/bomb_explosion.cpp @@ -86,7 +86,6 @@ constexpr float POISON_CLOUD_FLATTEN = 0.4f; constexpr int POISON_CLOUD_SUBTYPE = 4; constexpr std::array EFFECTS_BLOWN_AWAY = {21, 33, 63, 64, 158, 159}; constexpr int BOMB_EXPLOSION_EFFECT = 1; -constexpr int SPECIAL_DAILY_FIREWORKS = 12; constexpr size_t SAVED_EFFECTS_MAX = 128; // Butt Bombs heal poop enemies by a quarter, and hurt and confuse the rest for two seconds. @@ -153,8 +152,6 @@ constexpr int GIGA_DUSTS = 15; constexpr float GIGA_DUST_SPEED_MIN = 15; constexpr float GIGA_DUST_SPEED_RANGE = 5; constexpr float GIGA_DUST_FLATTEN = 0.85f; -constexpr float GIGA_DUST_SPIN_MIN = 2; -constexpr float GIGA_DUST_SPIN_RANGE = 10; constexpr float GIGA_DUST_SCALE_RANGE = 0.6f; constexpr int GIGA_DUST_FRAMES = 40; constexpr ColorMod GIGA_DUST_COLOR = {{0.45f, 0.45f, 0.46f, 0.75f}, {0, 0, 0, 0}, {0, 0, 0}}; @@ -188,33 +185,6 @@ static bool is_scissored(Entity* source) return !source || (source->type != ENTITY_PLAYER && !source->GetPlayerAncestor()); } -// Room::CheckLine's explosion mode (2): the line walked in steps, cell by cell. A metal block stops it, and so does a -// wall, unless it is a door, a wall the check ignores, or a lock Broken Padlock lets the blast through. -bool explosion_line_clear(const Vector& start, const Vector& end, bool isIgnoreWalls) -{ - Room& room = *g_game->room; - Vector step = vector_sub(start, end); - float length = vector_length(step); - if (length <= 0) return true; - - step = vector_scale(step, LINE_STEP / length); - Vector at = start; - for (float walked = 0; walked < length; walked += LINE_STEP) - { - at = vector_sub(at, step); - int gridIndex = room.GetGridIndex(at); - uint32_t collision = room.GetGridCollision(gridIndex); - GridEntity* grid = gridIndex >= 0 ? room.GetGridEntity((uint32_t)gridIndex) : nullptr; - if (grid && collision != COLLISION_NONE && grid->type == GRID_ROCKB) return false; - if (collision != COLLISION_WALL) continue; - - bool isPadlock = grid && grid->type == GRID_LOCK && g_game->playerManager.AnyoneHasTrinket(TRINKET_BROKEN_PADLOCK); - bool isOpening = grid && (grid->type == GRID_DOOR || (grid->type == GRID_WALL && isIgnoreWalls)); - if (!isPadlock && !isOpening) return false; - } - return true; -} - // Pushes an entity away from an explosion, harder the deeper inside it is, a heavy one half as far and with Knockback // twice as far. A player keeps its push and half its speed, at most so fast. // Past a mass of 20 the original's further tiers (30, 50, 150) are never reached. They are left out. @@ -338,7 +308,7 @@ static void explosion_grid_break(const Explosion& explosion) for (int gridIndex : explosion_cells_get(explosion)) { Vector cell = room.GetGridPosition(gridIndex); - if (!explosion_line_clear(explosion.position, cell, false)) continue; + if (!room_check_line(explosion.position, cell, LINE_MODE_EXPLOSION, 0)) continue; uint32_t collision = room.GetGridCollision(gridIndex); GridEntity* grid = room.GetGridEntity((uint32_t)gridIndex); @@ -382,7 +352,7 @@ void explosion_damage(Explosion explosion) Vector away = vector_sub(entity->pos, explosion.position); float distance = vector_length(away); - if (explosion.isLineCheck && !explosion_line_clear(explosion.position, entity->pos, true)) continue; + if (explosion.isLineCheck && !room_check_line({.start = explosion.position, .end = entity->pos, .mode = LINE_MODE_EXPLOSION, .isIgnoreWalls = true})) continue; if (source && source->type == ENTITY_BOMB) flags |= static_cast(source)->tearFlags; bool isPlayerSpared = type == ENTITY_PLAYER && (entity->mass == IMMOVABLE_MASS || (source && source->IsFriendly()) || @@ -753,7 +723,7 @@ static void giga_bomb_crater(const Explosion& explosion) auto* dust = static_cast(game.Spawn({.position = explosion.position, .velocity = velocity, .type = ENTITY_EFFECT, .variant = EFFECT_DUST_CLOUD, .seed = Random()})); float spin = Random() & 1 ? 1 : -1; - dust->rotation = (random_unit() * GIGA_DUST_SPIN_RANGE + GIGA_DUST_SPIN_MIN) * spin; + dust->rotation = (random_between(DUST_SPIN_MIN, DUST_SPIN_RANGE)) * spin; float scale = random_unit() * GIGA_DUST_SCALE_RANGE + 1; dust->sprite.scale = vector_make(scale, scale); dust->SetTimeout((int)(Random() % GIGA_DUST_FRAMES) + GIGA_DUST_FRAMES); @@ -865,7 +835,7 @@ static void cross_bomb_spread(const Explosion& explosion) arm.isDamageSource = false; arm.isLineCheck = true; DeathmatchManager& versus = g_game->deathmatchManager; - bool isBomberman = versus.is_active() && dynamic_cast(versus.type.get()); + bool isBomberman = versus.is_active() && versus.type->rules() == DEATHMATCH_BOMBERMAN; float scale = isBomberman ? CROSS_SCALE_VERSUS : CROSS_SCALE; arm.radiusMultiplier = scale * explosion.radiusMultiplier; @@ -926,7 +896,7 @@ void explosion_effects(const Explosion& explosion) else if (flags[TEAR_GIGA_BOMB]) blast->sprite.scale = vector_make(explosion.radiusMultiplier * 2, explosion.radiusMultiplier * 2); bool isFetusBomb = source && source->type == ENTITY_BOMB && static_cast(source)->isFetus; - if (g_game->dailyChallenge.specialDailyId == SPECIAL_DAILY_FIREWORKS && isFetusBomb) + if (g_game->dailyChallenge.specialDailyId == SPECIAL_DAILY_JULY_4 && isFetusBomb) { Entity* fireworks = g_game->Spawn({.position = explosion.position, .subType = 1, .type = ENTITY_EFFECT, .variant = EFFECT_FIREWORKS, .seed = Random()}); diff --git a/src/boss_beast.cpp b/src/boss_beast.cpp index 5e83024..7b26afb 100644 --- a/src/boss_beast.cpp +++ b/src/boss_beast.cpp @@ -148,7 +148,6 @@ constexpr float BEAST_STALACTITE_HURT = 14; constexpr float BEAST_STALACTITE_HURT_NEAR = 500; constexpr float BEAST_STALACTITE_HURT_FALLOFF = 1500; constexpr float BEAST_STALACTITE_HURT_FAR = 0.8f; -constexpr int BEAST_STALACTITE_HIT_COUNTDOWN = 30; constexpr int BEAST_RING_AFTER = 20; constexpr int BEAST_RING_EVERY = 30; constexpr uint32_t BEAST_RING_GAPS = 20; @@ -256,7 +255,7 @@ static void beast_stalactites_hurt(Entity_NPC& npc, float left, float right) BEAST_STALACTITE_HURT_FALLOFF, 0.0f, 1.0f); stalactite->TakeDamage((1 - falloff * BEAST_STALACTITE_HURT_FAR) * (roll * BEAST_STALACTITE_HURT + BEAST_STALACTITE_HURT), - 0, EntityRef(), BEAST_STALACTITE_HIT_COUNTDOWN); + 0, EntityRef(), HIT_COUNTDOWN); } } @@ -921,8 +920,8 @@ static void beast_switch(Entity_NPC& npc, Room& room) npc.stateFrame = 0; } -// Red rays burst from the Beast: a wide one and three thin ones at random turns. -static void beast_rays_spawn(Entity_NPC& npc) +// Red rays burst from a beast at an offset: a wide one and three thin ones at random turns. +void beast_rays_spawn(Entity_NPC& npc, const Vector& offset) { int frames = (int)std::ceil(BEAST_RAY_FRAMES); auto* ray = static_cast(g_game->Spawn({.position = npc.pos, @@ -931,7 +930,7 @@ static void beast_rays_spawn(Entity_NPC& npc) .type = ENTITY_EFFECT, .variant = EFFECT_BIG_ATTRACT, .seed = Random()})); - ray->posOffset = BEAST_RAY_OFFSET; + ray->posOffset = offset; ray->SetColor(BEAST_RAY_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); ray->minRadius = BEAST_RAY_INNER; ray->maxRadius = BEAST_RAY_OUTER; @@ -948,7 +947,7 @@ static void beast_rays_spawn(Entity_NPC& npc) .type = ENTITY_EFFECT, .variant = EFFECT_BIG_ATTRACT, .seed = Random()})); - line->posOffset = BEAST_RAY_OFFSET; + line->posOffset = offset; line->sprite.rotation = random_unit() * BEAST_THIN_RAY_SPREAD - BEAST_THIN_RAY_SPREAD * HALF + (float)thin * BEAST_THIN_RAY_TURN + turn; line->SetColor(BEAST_RAY_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); @@ -982,7 +981,7 @@ static void beast_soul_call(Entity_NPC& npc, Room& room) g_game->Spawn({.position = at, .spawner = &npc, .type = ENTITY_BEAST, .variant = BEAST_SOUL, .seed = seed}) ->Update(); } - if ((npc.stateFrame & 1) == 0) beast_rays_spawn(npc); + if ((npc.stateFrame & 1) == 0) beast_rays_spawn(npc, BEAST_RAY_OFFSET); npc.stateFrame++; } } @@ -1274,7 +1273,7 @@ static void stalactite_burst(Entity_NPC& npc) { for (int draw = 0; draw < STALACTITE_DISCARDED_DRAWS; draw++) Random(); uint32_t seed = Random(); - float scatterAngle = random_unit() * RANDOM_HALF_TURN; + float scatterAngle = random_unit() * PI_ROUGH; scatterAngle += scatterAngle; float scatter = random_unit(); float turn = random_unit() * STALACTITE_THROW_SPREAD - STALACTITE_THROW_SPREAD * HALF; @@ -1295,7 +1294,7 @@ static void stalactite_burst(Entity_NPC& npc) piece->Update(); uint32_t dustSeed = Random(); - float dustAngle = random_unit() * RANDOM_HALF_TURN; + float dustAngle = random_unit() * PI_ROUGH; dustAngle += dustAngle; float dustSpeed = random_unit() * STALACTITE_SCATTER; auto* dust = static_cast(g_game->Spawn({.position = capsule.center, @@ -1676,33 +1675,22 @@ void boss_beast_update(Entity_NPC& npc) case BEAST_SOUL: return beast_soul_update(npc); case BEAST_ULTRA_FAMINE: - return NpcAI::ENTITY_BEAST_ultra_famine(&npc); case BEAST_ULTRA_FAMINE_FLY: - return NpcAI::ENTITY_BEAST_ultra_famine_fly(&npc); case BEAST_ULTRA_PESTILENCE: - return NpcAI::ENTITY_BEAST_ultra_pestilence(&npc); case BEAST_ULTRA_PESTILENCE_FLY: - return NpcAI::ENTITY_BEAST_pestilence_fly(&npc); case BEAST_ULTRA_PESTILENCE_MAGGOT: - return NpcAI::ENTITY_BEAST_ultra_pestilence_maggot(&npc); case BEAST_ULTRA_PESTILENCE_FLY_BALL: - return NpcAI::ENTITY_BEAST_ultra_pestilence_fly_ball(&npc); case BEAST_ULTRA_WAR: - return NpcAI::ENTITY_BEAST_ultra_war(&npc); case BEAST_ULTRA_WAR_BOMB: - return NpcAI::ENTITY_BEAST_ultra_war_bomb(&npc); case BEAST_ULTRA_DEATH: - return NpcAI::ENTITY_BEAST_ultra_death(&npc); case BEAST_ULTRA_DEATH_SCYTHE: - return NpcAI::ENTITY_BEAST_ultra_death_scythe(&npc); case BEAST_ULTRA_DEATH_HEAD: - return NpcAI::ENTITY_BEAST_ultra_death_head(&npc); case BEAST_BACKGROUND_BEAST: case BEAST_BACKGROUND_FAMINE: case BEAST_BACKGROUND_PESTILENCE: case BEAST_BACKGROUND_WAR: case BEAST_BACKGROUND_DEATH: - return NpcAI::ENTITY_BEAST_background(&npc); + return beast_horseman_update(npc); default: return beast_update(npc); } diff --git a/src/boss_beast_horsemen.cpp b/src/boss_beast_horsemen.cpp new file mode 100644 index 0000000..c6b0bd5 --- /dev/null +++ b/src/boss_beast_horsemen.cpp @@ -0,0 +1,3773 @@ +#include "boss_final.h" +#include "boss_ai.h" +#include "capsule.h" +#include "entity_bomb.h" +#include "entity_combat.h" +#include "entity_effect.h" +#include "entity_laser.h" +#include "entity_pickup.h" +#include "entity_player.h" +#include "entity_projectile.h" +#include "entity_list.h" +#include "grid_entity_trap_door.h" +#include "manager.h" +#include "music_manager.h" +#include "npc_basement.h" +#include "npc_fireplace.h" +#include "player_manager.h" +#include "room_grid.h" +#include +#include + +// What the four ultra horsemen share: the Beast sets them arriving, they sink into the lava dying, hover their own +// way, and every spawn of the Beast's dies with their headless form. +constexpr int ULTRA_HORSEMAN_ARRIVING = 99; +constexpr int ULTRA_HORSEMAN_HEADLESS = NPC_STATE_SPECIAL; +constexpr float ULTRA_HORSEMAN_FRICTION = 0.8f; +constexpr float ULTRA_HORSEMAN_SINK = 0.4f; +constexpr int ULTRA_HORSEMAN_SHAKE = 10; +constexpr int ULTRA_HORSEMAN_GIBS = 10; +constexpr float ULTRA_HORSEMAN_GIB_SPREAD = 90; + +// Famine's and War's hover: a drift pushed 0.55 a tick, a goal on their side of the player (100 off, swaying 100 at +// 0.01 to 0.013 a frame, jittered 20) picked every 20 to 39 ticks, steered toward turned up to 30 degrees, and kept +// 80 from the sides and 100 from the top and bottom. +constexpr float ULTRA_HOVER_PUSH = 0.55f; +constexpr int ULTRA_HOVER_RETARGET = 20; +constexpr float ULTRA_HOVER_SIDE = 100; +constexpr float ULTRA_HOVER_SWAY = 100; +constexpr float ULTRA_HOVER_SWAY_RATE = 0.01f; +constexpr float ULTRA_HOVER_SWAY_RATE_RANGE = 0.003f; +constexpr float ULTRA_HOVER_JITTER = 20; +constexpr float ULTRA_HOVER_TURN_RATE = 0.01f; +constexpr float ULTRA_HOVER_TURN = 30; +constexpr float ULTRA_HOVER_STEER = 0.001f; +constexpr float ULTRA_HOVER_MARGIN_X = 80; +constexpr float ULTRA_HOVER_MARGIN_Y = 100; + +// The dust their dashes leave every 2 ticks, 40 up: twice as big, spinning 2 to 12 a tick for 15 to 29 ticks, behind +// them. +static const Vector ULTRA_DUST_OFFSET = vector_make(0, -40); +constexpr float ULTRA_DUST_DRIFT = 2; +constexpr float ULTRA_DUST_CARRY = 0.2f; +constexpr int ULTRA_DUST_FRAMES = 15; +constexpr float ULTRA_DUST_DEPTH = -5; +constexpr float ULTRA_DUST_SCALE = 2; +constexpr float ULTRA_DUST_EVERY = 2; + +// The shots that fly straight, never falling: no fall speed and a slight lift. +constexpr float ULTRA_SHOT_LIFT = -0.1f; + +// The background beast and its horsemen (951.100 to 104): idle behind the arena, cheering, then leaving. The beast +// screams rays from 80 up while it dives, each horseman rides off its own way and is gone 200 past the sides. +constexpr uint64_t BACKGROUND_FLAGS = FLAG_NO_STATUS_EFFECTS | FLAG_NO_BLOOD_SPLASH | FLAG_NO_DEATH_TRIGGER | + FLAG_NO_KNOCKBACK | FLAG_NO_PHYSICS_KNOCKBACK | FLAG_DONT_COUNT_BOSS_HP | + FLAG_HIDE_HP_BAR; +constexpr int BACKGROUND_CHEER = NPC_STATE_ATTACK; +constexpr int BACKGROUND_SCREAM_SHAKE = 8; +static const Vector BACKGROUND_RAY_OFFSET = vector_make(0, -80); +constexpr float BACKGROUND_RAY_EVERY = 2; +constexpr float BACKGROUND_GONE = 200; +constexpr float BACKGROUND_FRICTION = 0.8f; +constexpr float BACKGROUND_DARKNESS = 0.96f; +constexpr float BACKGROUND_FAMINE_PULL = 0.8f; +constexpr float BACKGROUND_FAMINE_TOP = -8; +constexpr float BACKGROUND_PESTILENCE_PULL = 0.4f; +constexpr float BACKGROUND_PESTILENCE_TOP = -5; +constexpr float BACKGROUND_DEATH_PULL = 0.3f; +constexpr float BACKGROUND_DEATH_TOP = 5; + +// A dust cloud of the horsemen's: where, how fast, its tint and the seed it was drawn with. +struct HorsemanDust +{ + ColorMod color = COLOR_DEFAULT; + Vector position{}; + Vector velocity{}; + uint32_t seed = 0; +}; + +// Throws a dust cloud spinning 2 to 12 a tick for 15 to 29 ticks, twice as big. +static Entity_Effect* horseman_dust_spawn(Entity_NPC& npc, const HorsemanDust& dust) +{ + auto* cloud = static_cast(g_game->Spawn({.position = dust.position, + .velocity = dust.velocity, + .spawner = &npc, + .type = ENTITY_EFFECT, + .variant = EFFECT_DUST_CLOUD, + .seed = dust.seed})); + cloud->sprite.scale = vector_make(ULTRA_DUST_SCALE, ULTRA_DUST_SCALE); + cloud->rotation = random_between(DUST_SPIN_MIN, DUST_SPIN_RANGE); + int frames = (int)(Random() % ULTRA_DUST_FRAMES) + ULTRA_DUST_FRAMES; + cloud->timeout = frames; + cloud->lifespan = frames; + cloud->SetColor(dust.color, -1, COLOR_PRIORITY_DEFAULT, false, true); + return cloud; +} + +// The dust a dash leaves 40 up, drifting and carried a fifth of the dash's speed. +static void horseman_trail_dust(Entity_NPC& npc, const ColorMod& color) +{ + uint32_t seed = Random(); + Vector velocity = npc.velocity; + Vector drift = random_direction(); + horseman_dust_spawn(npc, {.color = color, + .position = vector_add(npc.pos, ULTRA_DUST_OFFSET), + .velocity = vector_add(vector_scale(drift, ULTRA_DUST_DRIFT), vector_scale(velocity, ULTRA_DUST_CARRY)), + .seed = seed}) + ->renderDepthOffset = ULTRA_DUST_DEPTH; +} + +// What a headless horseman's spawn clears: every shot gone, and every live enemy the Beast's forms spawned killed, +// but those of one variant spared (-1 for none). Pestilence also drops its shots' flags and the smoke. +enum HorsemanClear +{ + HORSEMAN_CLEAR_SHOTS, + HORSEMAN_CLEAR_SHOTS_AND_SMOKE +}; + +// The headless form's clearing of the room. +static void horseman_spawns_kill(Entity_NPC& npc, HorsemanClear clear, int sparedVariant) +{ + for (Entity* entity : entities_live(g_game->room->entityList.updateEL)) + { + if (entity->type == ENTITY_PROJECTILE) + { + if (clear == HORSEMAN_CLEAR_SHOTS_AND_SMOKE) static_cast(entity)->projectileFlags = 0; + entity->isDead = true; + } + else if (clear == HORSEMAN_CLEAR_SHOTS_AND_SMOKE && entity->IsType(ENTITY_EFFECT, EFFECT_SMOKE_CLOUD, -1)) + entity->isDead = true; + else if (Entity::is_enemy_type(entity->type) && !entity->isDead && entity->spawnerType == ENTITY_BEAST && + (sparedVariant < 0 || !entity->IsType(ENTITY_BEAST, sparedVariant, -1))) + entity->Kill(EntityRef(&npc)); + } +} + +// A horseman's sinking into the lava while it dies. +static void horseman_sink(Entity_NPC& npc) +{ + if (npc.state != NPC_STATE_DEATH) return; + npc.friction = ULTRA_HORSEMAN_FRICTION; + npc.velocity.y += npc.speedMultiplier * ULTRA_HORSEMAN_SINK; +} + +// Sets the Beast music's layers to only the one given (-1 for the base alone). +static void horseman_music_layer_set(int layer) +{ + MusicManager& music = g_manager->musicManager; + music.channels[music.currentChannel].enabledLayers.reset(); + if (layer >= 0) music.channels[music.currentChannel].enabledLayers.set((size_t)layer); +} + +// A horseman's start: idle, its goal where it is and a random drift, held against knockback. +static void horseman_init(Entity_NPC& npc) +{ + npc.state = NPC_STATE_IDLE; + npc.targetPosition = npc.pos; + npc.pathfinder.movementTarget = npc.pos; + Vector drift = random_direction(); + npc.pathfinder.moveDirection = vector_make(drift.x, drift.y * HALF); + npc.pathfinder.moveCountdown = 0; + npc.flags |= FLAG_NO_KNOCKBACK | FLAG_NO_PHYSICS_KNOCKBACK; + npc.stateFrame = 0; +} + +// The drift's steering toward the goal (turned by up to 30 degrees on a slow sine) at a strength. +static void horseman_steer(Entity_NPC& npc, float strength) +{ + Vector toGoal = vector_sub(npc.pathfinder.movementTarget, npc.pos); + if (vector_is_zero(toGoal)) return; + float turn = std::sin(npc.updateTime * ULTRA_HOVER_TURN_RATE) * ULTRA_HOVER_TURN; + Vector& drift = npc.pathfinder.moveDirection; + drift = vector_add(drift, vector_scale(vector_rotated(toGoal, turn), strength)); +} + +// The box a horseman's drift keeps it in, and how hard it pushes back. +struct HoverBounds +{ + Vector topLeft{}; + Vector bottomRight{}; + float strength = 0; +}; + +// The bounds a margin in from the room's sides (x) and top and bottom (y). +static HoverBounds hover_bounds_get(Vector margin, float strength) +{ + Room& room = *g_game->room; + return {vector_add(room.topLeftPos, margin), vector_sub(room.bottomRightPos, margin), strength}; +} + +// The drift pushed back inside its bounds by how far it strayed past them, then held to a unit. +static void horseman_keep_in(Entity_NPC& npc, const HoverBounds& bounds) +{ + Vector& drift = npc.pathfinder.moveDirection; + if (npc.pos.x < bounds.topLeft.x) drift.x += (bounds.topLeft.x - npc.pos.x) * bounds.strength; + else if (npc.pos.x > bounds.bottomRight.x) drift.x += (bounds.bottomRight.x - npc.pos.x) * bounds.strength; + if (npc.pos.y < bounds.topLeft.y) drift.y += (bounds.topLeft.y - npc.pos.y) * bounds.strength; + else if (npc.pos.y > bounds.bottomRight.y) drift.y += (bounds.bottomRight.y - npc.pos.y) * bounds.strength; + if (vector_length(drift) > 1) drift = vector_normalized(drift); +} + +// Famine's and War's hover: idle, drifting toward a goal on their side of the player that sways and is picked anew +// every 20 to 39 ticks, kept off the room's edges. Returns the frames hovered. +static int horseman_hover(Entity_NPC& npc) +{ + npc.sprite.Play("Idle"); + npc.friction = ULTRA_HORSEMAN_FRICTION; + npc.velocity = vector_add(npc.velocity, vector_scale(npc.pathfinder.moveDirection, ULTRA_HOVER_PUSH * npc.speedMultiplier)); + + Entity* target = npc.GetPlayerTarget(); + PathFinder& path = npc.pathfinder; + if (path.moveCountdown < 1) + { + path.moveCountdown = (int)(Random() % ULTRA_HOVER_RETARGET) + ULTRA_HOVER_RETARGET; + Vector player = target->pos; + float side = player.x <= npc.pos.x ? ULTRA_HOVER_SIDE : -ULTRA_HOVER_SIDE; + float sway = std::sin((random_unit() * ULTRA_HOVER_SWAY_RATE_RANGE + ULTRA_HOVER_SWAY_RATE) * npc.updateTime); + path.movementTarget = vector_make(sway * ULTRA_HOVER_SWAY + side + player.x, target->pos.y); + path.movementTarget = vector_add(path.movementTarget, vector_scale(random_direction(), ULTRA_HOVER_JITTER)); + } + else + path.moveCountdown -= npc_ticks_get(npc); + + horseman_steer(npc, ULTRA_HOVER_STEER * npc.speedMultiplier); + horseman_keep_in(npc, hover_bounds_get(vector_make(ULTRA_HOVER_MARGIN_X, ULTRA_HOVER_MARGIN_Y), ULTRA_HOVER_STEER)); + npc.stateFrame += npc_ticks_get(npc); + return npc.stateFrame; +} + +// Whether a horseman facing its way is past a line: left of it facing left, right of it facing right. +static bool horseman_is_past(Entity_NPC& npc, float leftLine, float rightLine) +{ + return npc.sprite.isFlipX ? npc.pos.x > rightLine : npc.pos.x < leftLine; +} + +// Whether it is outside the room by a margin on either side. +static bool horseman_is_off_sides(Entity_NPC& npc, float margin) +{ + Room& room = *g_game->room; + return npc.pos.x < room.topLeftPos.x - margin || npc.pos.x > room.bottomRightPos.x + margin; +} + +// A shot that flies straight on: no fall and a slight lift. +static void shot_level_set(Entity_Projectile* shot) +{ + shot->fallingSpeed = 0; + shot->fallingAccel = ULTRA_SHOT_LIFT; +} + +// The leaving horsemen ride off: Famine and War hurry left to 8, Pestilence to 5, Death right to 5. +static void background_ride(Entity_NPC& npc) +{ + float& ride = npc.v1.x; + switch (npc.variant) + { + case BEAST_BACKGROUND_FAMINE: + case BEAST_BACKGROUND_WAR: + ride = std::max(ride - npc.speedMultiplier * BACKGROUND_FAMINE_PULL, BACKGROUND_FAMINE_TOP); + break; + case BEAST_BACKGROUND_PESTILENCE: + ride = std::max(ride - npc.speedMultiplier * BACKGROUND_PESTILENCE_PULL, BACKGROUND_PESTILENCE_TOP); + break; + case BEAST_BACKGROUND_DEATH: + ride = std::min(npc.speedMultiplier * BACKGROUND_DEATH_PULL + ride, BACKGROUND_DEATH_TOP); + break; + } +} + +// The background beast leaving: its scream shakes the arena and bursts rays every 2 ticks, and it is gone once done. +static void background_beast_leave(Entity_NPC& npc) +{ + if (npc.sprite.IsEventTriggered("ScreamStart")) npc_sound_play(SOUND_BEAST_INTRO_SCREAM, 1, 2, 1); + if (npc.sprite.IsEventTriggered("Dive")) npc_sound_play(SOUND_BEAST_BACKGROUND_DIVE, 1, 2, 1); + if (npc.sprite.WasEventTriggered("ScreamStart") && !npc.sprite.WasEventTriggered("ScreamStop")) + { + game_shake_screen(BACKGROUND_SCREAM_SHAKE); + if (npc.GetIntervalTicks(BACKGROUND_RAY_EVERY, 0) != 0) beast_rays_spawn(npc, BACKGROUND_RAY_OFFSET); + } + if (!npc.sprite.IsFinished()) return; + npc.Remove(); +} + +// A background horseman leaving: its Leave once the Beast's LeaveStart ends, riding off from its Shoot. +static void background_horseman_leave(Entity_NPC& npc) +{ + if (npc.sprite.IsFinished()) npc.sprite.Play("Leave"); + if (!npc.sprite.WasEventTriggered("Shoot") && !npc.sprite.animState.IsLoopingAnimation()) return; + + npc.velocity = vector_add(npc.velocity, vector_scale(vector_make(npc.v1.x, 0), npc.speedMultiplier)); + background_ride(npc); + if (horseman_is_off_sides(npc, BACKGROUND_GONE)) npc.Remove(); +} + +// 00440630 The background beast and its horsemen (951.100 to 104): idle behind the arena and drawn in its darkness, +// cheering when told, and leaving when the Beast sends them (the beast screaming as it dives). +static void beast_background_update(Entity_NPC& npc) +{ + if (npc.isDead) npc.isDead = false; + switch (npc.state) + { + case NPC_STATE_INIT: + npc.flags = (npc.flags & ~FLAG_APPEAR) | BACKGROUND_FLAGS; + npc.sprite.Play("Idle"); + npc.entityCollisionClass = ENTCOLL_NONE; + npc.entityGridCollisionClass = GRIDCOLL_NONE; + npc.sortingLayer = SORTING_BACKGROUND; + npc.isInvincible = true; + npc.state = NPC_STATE_IDLE; + break; + case NPC_STATE_MOVE: + if (npc.variant == BEAST_BACKGROUND_BEAST) background_beast_leave(npc); + else background_horseman_leave(npc); + break; + case BACKGROUND_CHEER: + if (npc.stateFrame > 0) + { + npc.stateFrame -= npc_ticks_get(npc); + if (npc.stateFrame >= 1) break; + npc.sprite.Play("Cheer"); + npc.stateFrame = 0; + break; + } + if (!npc.sprite.IsFinished()) break; + npc.sprite.Play("Idle"); + npc.state = NPC_STATE_IDLE; + break; + } + + npc.friction *= BACKGROUND_FRICTION; + float light = 1 - g_game->darknessStrength * g_game->darknessModifier * BACKGROUND_DARKNESS; + npc.sprite.color = tint_color_make(light, light, light, 1); +} + +// Ultra Famine (951.10): hovers on its side of the player, dashes off-screen at its row, peeks in five times from the +// sides to spray 25 shots, sweeps across dropping flies, and comes back. On a hit below a third its head bursts off, +// kills every spawn of the Beast's, and from the room's centre turns pairs and rings of shots until it dies. +constexpr float ULTRA_FAMINE_HEADLESS_SHARE = 0.33f; +constexpr float ULTRA_FAMINE_HEAD_POP = 40; +constexpr int ULTRA_FAMINE_HOVER_FRAMES = 90; +constexpr int ULTRA_FAMINE_PEEKS = 5; +constexpr int ULTRA_FAMINE_DASH_OUT = NPC_STATE_ATTACK; +constexpr int ULTRA_FAMINE_PEEK = NPC_STATE_ATTACK2; +constexpr int ULTRA_FAMINE_SWEEP = NPC_STATE_ATTACK3; +constexpr int ULTRA_FAMINE_DASH_IN = NPC_STATE_STOMP; +constexpr ColorMod ULTRA_FAMINE_DUST_COLOR = tint_color_make(0.8f, 0.68f, 0.65f, 0.6f); +constexpr ColorMod ULTRA_FAMINE_BLOOD_COLOR = tint_color_make(1, 1, 1, 0.8f); + +// Its dashes: in at 10 a tick to 40 until 40 inside the edge, braking at 0.88 then 0.792 to under 8; out at 8 a tick +// to 30, homing on the player's row before the Shoot, until 180 past the far side. +constexpr float ULTRA_FAMINE_DASH_IN_PUSH = 10; +constexpr float ULTRA_FAMINE_DASH_IN_TOP = 40; +constexpr float ULTRA_FAMINE_ENTRY = 40; +constexpr float ULTRA_FAMINE_BRAKE = 0.88f; +constexpr float ULTRA_FAMINE_BRAKE_END = 0.9f; +constexpr float ULTRA_FAMINE_BRAKE_SPEED = 8; +constexpr float ULTRA_FAMINE_HOME = 0.003f; +constexpr float ULTRA_FAMINE_HOME_PUSH = 0.3f; +constexpr float ULTRA_FAMINE_DASH_OUT_PUSH = 8; +constexpr float ULTRA_FAMINE_DASH_OUT_TOP = 30; +constexpr float ULTRA_FAMINE_OFFSCREEN = 180; +constexpr float ULTRA_FAMINE_RETURN_DRIFT = 0.1f; + +// Its peeks: in from 200 past a side at a random height 80 inside, at 40 a tick, turning back 160 out; its spray of +// 5 rays 30 degrees apart at 10, 8, 6, 4 and 2 from 20 ahead and 50 up; then backing out at up to 10. +constexpr float ULTRA_FAMINE_PEEK_FROM = 200; +constexpr float ULTRA_FAMINE_PEEK_MARGIN = 80; +constexpr float ULTRA_FAMINE_PEEK_SPEED = 40; +constexpr float ULTRA_FAMINE_PEEK_PUSH = 10; +constexpr float ULTRA_FAMINE_PEEK_TURN = 160; +constexpr float ULTRA_FAMINE_PEEK_SLOW = HALF; +constexpr float ULTRA_FAMINE_PEEK_DRAG = 0.8f; +constexpr float ULTRA_FAMINE_BACK_OUT = 0.3f; +constexpr float ULTRA_FAMINE_BACK_OUT_TOP = 10; +constexpr float ULTRA_FAMINE_MOUTH_X = 20; +constexpr float ULTRA_FAMINE_MOUTH_Y = 50; +constexpr int ULTRA_FAMINE_SPRAY_RAYS = 2; +constexpr float ULTRA_FAMINE_SPRAY_TURN = 30; +constexpr int ULTRA_FAMINE_SPRAY_SHOTS = 5; +constexpr float ULTRA_FAMINE_SPRAY_SPEED = 10; +constexpr float ULTRA_FAMINE_SPRAY_STEP = 2; +constexpr float ULTRA_FAMINE_SPRAY_SCALE = 1.5f; + +// Its sweep: across from 120 past one side to 120 past the other over 240 ticks, on a sine from 80 above the room to +// 80 below, sprung 1% a tick, dropping flies every 10 ticks within 20 (pushed a fifth from the centre's height) with +// 100 health; then 90 ticks away, back from 200 out at 30 to 70% of the room's height. +constexpr float ULTRA_FAMINE_SWEEP_EDGE = 120; +constexpr float ULTRA_FAMINE_SWEEP_FRAMES = 240; +constexpr float ULTRA_FAMINE_SWEEP_OVER = 80; +constexpr float ULTRA_FAMINE_SWEEP_WAVE = 0.1f; +constexpr float ULTRA_FAMINE_SWEEP_SPRING = 0.01f; +constexpr float ULTRA_FAMINE_FLY_EVERY = 10; +constexpr uint32_t ULTRA_FAMINE_FLY_LOOKS = 3; +constexpr float ULTRA_FAMINE_FLY_SCATTER = 20; +constexpr float ULTRA_FAMINE_FLY_LEAN = 0.2f; +constexpr float ULTRA_FAMINE_FLY_HEALTH = 100; +constexpr int ULTRA_FAMINE_AWAY_FRAMES = 90; +constexpr float ULTRA_FAMINE_RETURN_FROM = 200; +constexpr float ULTRA_FAMINE_RETURN_LOW = 0.3f; +constexpr float ULTRA_FAMINE_RETURN_RANGE = 0.4f; + +// Its headless form: pulled to the room's centre, every 8 ticks its two angles turn (26.96 and -30.48 degrees); a ring +// of 6 rays of 6 wiggling shots (8 to 13 fast, 1 to 2 big, 16 out) every 32 (turned 30 degrees on odd ones), else a +// pair 25 degrees either side at 7 and 11 from 30 out, with blood splashes at 6. +constexpr float ULTRA_FAMINE_CENTER_PULL = 0.005f; +constexpr int ULTRA_FAMINE_TURN_EVERY = 8; +constexpr int ULTRA_FAMINE_RING_EVERY = 32; +constexpr int ULTRA_FAMINE_RING_SWAP = 64; +constexpr float ULTRA_FAMINE_HEAD_START = -90; +constexpr float ULTRA_FAMINE_TURN_A = 26.96f; +constexpr float ULTRA_FAMINE_TURN_B = -30.48f; +constexpr float ULTRA_FAMINE_RING_OFFSET = 30; +constexpr int ULTRA_FAMINE_RING_RAYS = 6; +constexpr float ULTRA_FAMINE_RING_TURN = 60; +constexpr int ULTRA_FAMINE_RING_SHOTS = 6; +constexpr float ULTRA_FAMINE_RING_FROM = 16; +constexpr float ULTRA_FAMINE_RING_SPEED = 8; +constexpr float ULTRA_FAMINE_RING_GROWTH = 0.2f; +constexpr int ULTRA_FAMINE_RING_WIGGLE = 10; +constexpr float ULTRA_FAMINE_CLOUD_DEPTH = 100; +static const Vector ULTRA_FAMINE_NECK = vector_make(0, -16); +constexpr float ULTRA_FAMINE_BURST_VOLUME = 1.2f; +constexpr float ULTRA_FAMINE_PAIR_SPREAD = 25; +constexpr float ULTRA_FAMINE_PAIR_SPEED = 9; +constexpr float ULTRA_FAMINE_PAIR_FROM = 30; +constexpr float ULTRA_FAMINE_PAIR_SCALE = 1.2f; +constexpr float ULTRA_FAMINE_SPLASH_SPEED = 6; + +// The dash out: DashStart turns it at the player, homes on its row until the Shoot, then it bolts off the far side +// for its peeks. +static void ultra_famine_dash_out(Entity_NPC& npc) +{ + npc.friction = ULTRA_HORSEMAN_FRICTION; + if (npc.sprite.IsFinished()) + { + npc_sound_play(SOUND_FAMINE_DASH, 1, 2, 1); + npc.sprite.Play("DashLoop"); + } + if (npc.sprite.IsEventTriggered("Turn")) npc.sprite.isFlipX = npc.pos.x < npc.GetPlayerTarget()->pos.x; + if (npc.sprite.IsEventTriggered("Shoot")) + { + npc.PlaySound(SOUND_FAMINE_SHOOT, 1, 2, false, 1); + npc.PlaySound(SOUND_FAMINE_GRUNT, 1, 2, false, 1); + npc.velocity.y = 0; + } + + if (!npc.sprite.animState.IsLoopingAnimation() && !npc.sprite.WasEventTriggered("Shoot")) + { + Entity* target = npc.GetPlayerTarget(); + Vector& drift = npc.pathfinder.moveDirection; + drift.y += (target->pos.y - npc.pos.y) * ULTRA_FAMINE_HOME; + npc.velocity = vector_add(npc.velocity, vector_scale(drift, ULTRA_FAMINE_HOME_PUSH * npc.speedMultiplier)); + } + else + { + float push = npc.sprite.isFlipX ? ULTRA_FAMINE_DASH_OUT_PUSH : -ULTRA_FAMINE_DASH_OUT_PUSH; + npc.velocity.x = std::clamp(push * npc.speedMultiplier + npc.velocity.x, -ULTRA_FAMINE_DASH_OUT_TOP, ULTRA_FAMINE_DASH_OUT_TOP); + if (npc.GetIntervalTicks(ULTRA_DUST_EVERY, 0) != 0) horseman_trail_dust(npc, ULTRA_FAMINE_DUST_COLOR); + } + + Room& room = *g_game->room; + if (!horseman_is_past(npc, room.topLeftPos.x - ULTRA_FAMINE_OFFSCREEN, room.bottomRightPos.x + ULTRA_FAMINE_OFFSCREEN)) return; + npc.v1 = {}; + npc.state = ULTRA_FAMINE_PEEK; + npc.i1 = ULTRA_FAMINE_PEEKS; +} + +// The dash back in: at speed until 40 inside its entry edge, then braking into DashEnd and the hover. +static void ultra_famine_dash_in(Entity_NPC& npc) +{ + Room& room = *g_game->room; + npc.friction = ULTRA_HORSEMAN_FRICTION; + bool isOutside = npc.sprite.isFlipX ? npc.pos.x <= room.topLeftPos.x - ULTRA_FAMINE_ENTRY + : npc.pos.x >= room.bottomRightPos.x + ULTRA_FAMINE_ENTRY; + if (npc.i1 == 0 && !isOutside) npc.i1 = 1; + if (npc.i1 == 0) + { + float push = npc.sprite.isFlipX ? ULTRA_FAMINE_DASH_IN_PUSH : -ULTRA_FAMINE_DASH_IN_PUSH; + npc.velocity.x = std::clamp(push * npc.speedMultiplier + npc.velocity.x, -ULTRA_FAMINE_DASH_IN_TOP, ULTRA_FAMINE_DASH_IN_TOP); + if (npc.GetIntervalTicks(ULTRA_DUST_EVERY, 0) != 0) horseman_trail_dust(npc, ULTRA_FAMINE_DUST_COLOR); + } + else + { + npc.friction = ULTRA_FAMINE_BRAKE; + if (vector_length(npc.velocity) < ULTRA_FAMINE_BRAKE_SPEED) npc.sprite.Play("DashEnd"); + } + if (!npc.sprite.animState.IsLoopingAnimation()) npc.friction *= ULTRA_FAMINE_BRAKE_END; + if (!npc.sprite.IsFinished()) return; + + npc.sprite.Play("Idle"); + npc.stateFrame = 0; + npc.state = NPC_STATE_IDLE; + npc.pathfinder.movementTarget = npc.pos; + npc.pathfinder.moveCountdown = 0; + npc.pathfinder.moveDirection = vector_scale(npc.velocity, ULTRA_FAMINE_RETURN_DRIFT); +} + +// The spray of a peek: five rays 30 degrees apart at the player, each of five shots slowing from 10 to 2. +static void ultra_famine_spray(Entity_NPC& npc) +{ + npc.PlaySound(SOUND_FAMINE_SHOOT, 1, 2, false, 1); + npc.PlaySound(SOUND_FAMINE_GRUNT, 1, 2, false, 1); + Vector mouth = vector_make((npc.sprite.isFlipX ? ULTRA_FAMINE_MOUTH_X : -ULTRA_FAMINE_MOUTH_X) + npc.pos.x, + npc.pos.y - ULTRA_FAMINE_MOUTH_Y); + npc.MakeBloodCloud(mouth, ULTRA_FAMINE_BLOOD_COLOR, 1); + ProjectileParams params; + params.scale = ULTRA_FAMINE_SPRAY_SCALE; + Vector aim = vector_normalized(vector_sub(npc.GetPlayerTarget()->pos, mouth)); + for (int ray = -ULTRA_FAMINE_SPRAY_RAYS; ray <= ULTRA_FAMINE_SPRAY_RAYS; ray++) + { + Vector direction = vector_rotated(aim, (float)ray * ULTRA_FAMINE_SPRAY_TURN); + for (int shot = 0; shot < ULTRA_FAMINE_SPRAY_SHOTS; shot++) + { + float speed = ULTRA_FAMINE_SPRAY_SPEED - (float)shot * ULTRA_FAMINE_SPRAY_STEP; + shot_level_set(npc.fire_projectiles(mouth, vector_scale(direction, speed), PROJECTILES_SINGLE, params)); + } + } +} + +// A peek's start: from a random side (the other one than it left by, three times in four), at a random height 200 +// out, rushing in. +static void ultra_famine_peek_start(Entity_NPC& npc, Room& room) +{ + npc.v1.x = (Random() & 1) == 0 ? 1.0f : -1.0f; + if ((npc.pathfinder.moveDirection.x < 0) == (npc.v1.x < 0)) npc.v1.x = (Random() & 1) == 0 ? 1.0f : -1.0f; + float top = room.topLeftPos.y + ULTRA_FAMINE_PEEK_MARGIN; + float y = (room.bottomRightPos.y - ULTRA_FAMINE_PEEK_MARGIN - top) * random_unit() + top; + npc.v1.y = y; + float x = npc.v1.x >= 0 ? room.bottomRightPos.x + ULTRA_FAMINE_PEEK_FROM : room.topLeftPos.x - ULTRA_FAMINE_PEEK_FROM; + npc.pos = vector_make(x, y); + npc.velocity = vector_make(npc.v1.x * -ULTRA_FAMINE_PEEK_SPEED, 0); + npc.pathfinder.moveDirection = vector_make(npc.v1.x * -ULTRA_FAMINE_PEEK_PUSH, 0); + npc.sprite.Play("DashLoop", PLAY_FORCED); + npc.sprite.isFlipX = npc.v1.x < 0; +} + +// The peeks: it rushes in from a side, turns back with Reverse and sprays at the player, then backs out the way it +// came. After five it sweeps. +static void ultra_famine_peek(Entity_NPC& npc, Room& room) +{ + if (vector_is_zero(npc.v1)) ultra_famine_peek_start(npc, room); + npc.friction = ULTRA_HORSEMAN_FRICTION; + Vector& drift = npc.pathfinder.moveDirection; + npc.velocity = vector_add(npc.velocity, vector_scale(drift, npc.speedMultiplier)); + if (vector_length_squared(npc.velocity) > ULTRA_FAMINE_PEEK_SPEED * ULTRA_FAMINE_PEEK_SPEED) + npc.velocity = vector_resized(npc.velocity, ULTRA_FAMINE_PEEK_SPEED); + + if (npc.sprite.animState.IsLoopingAnimation()) + { + bool isIn = (npc.v1.x < 0 && room.topLeftPos.x - ULTRA_FAMINE_PEEK_TURN < npc.pos.x) || + (npc.v1.x > 0 && npc.pos.x < room.bottomRightPos.x + ULTRA_FAMINE_PEEK_TURN); + if (!isIn) return; + npc.sprite.Play("Reverse"); + drift = vector_scale(drift, ULTRA_FAMINE_PEEK_SLOW); + return; + } + + if (npc.sprite.IsEventTriggered("Shoot")) ultra_famine_spray(npc); + if (!npc.sprite.WasEventTriggered("Turn")) + { + drift = vector_scale(drift, ULTRA_FAMINE_PEEK_DRAG); + return; + } + drift.x = std::clamp(npc.v1.x * ULTRA_FAMINE_BACK_OUT * npc.speedMultiplier + drift.x, -ULTRA_FAMINE_BACK_OUT_TOP, + ULTRA_FAMINE_BACK_OUT_TOP); + if (!horseman_is_off_sides(npc, ULTRA_FAMINE_OFFSCREEN)) return; + + npc.v1 = {}; + if (--npc.i1 >= 1) return; + npc.state = ULTRA_FAMINE_SWEEP; + npc.sprite.Play("Summon"); + npc.v1.x = 0; + npc.v1.y = random_unit() * TAU; + npc.sprite.isFlipX = Random() & 1; +} + +// The sweep's flies: one for every 10 ticks crossed, about it and leaning from the centre's height. +static void ultra_famine_flies_drop(Entity_NPC& npc) +{ + int flies = npc.GetIntervalTicks(ULTRA_FAMINE_FLY_EVERY, 0); + for (int fly = 0; fly < flies; fly++) + { + uint32_t seed = Random(); + int look = (int)(Random() % ULTRA_FAMINE_FLY_LOOKS); + float lean = (npc.pos.y - Room::GetCenterPos().y) * ULTRA_FAMINE_FLY_LEAN; + float angle = random_unit() * PI_ROUGH; + angle += angle; + float distance = random_unit() * ULTRA_FAMINE_FLY_SCATTER; + Vector at = vector_make(std::cos(angle) * distance + npc.pos.x, std::sin(angle) * distance + lean + npc.pos.y); + Entity* dropped = g_game->Spawn({.position = at, + .spawner = &npc, + .subType = look, + .type = ENTITY_BEAST, + .variant = BEAST_ULTRA_FAMINE_FLY, + .seed = seed}); + dropped->health = ULTRA_FAMINE_FLY_HEALTH; + dropped->Update(); + } +} + +// Rushing back in from 200 past the side it faces from, at a random height. +static void ultra_famine_return(Entity_NPC& npc, Room& room) +{ + npc.state = ULTRA_FAMINE_DASH_IN; + npc.isVisible = true; + npc.entityCollisionClass = ENTCOLL_ALL; + npc.sprite.Play("DashLoop"); + npc_sound_play(SOUND_FAMINE_APPEAR, 1, 2, 1); + npc.pos.x = npc.sprite.isFlipX ? room.topLeftPos.x - ULTRA_FAMINE_RETURN_FROM : room.bottomRightPos.x + ULTRA_FAMINE_RETURN_FROM; + npc.pos.y = (room.bottomRightPos.y - room.topLeftPos.y) * (random_unit() * ULTRA_FAMINE_RETURN_RANGE + ULTRA_FAMINE_RETURN_LOW) + + room.topLeftPos.y; +} + +// The sweep across the room on a sine, dropping flies, then 90 ticks away before rushing back. +static void ultra_famine_sweep(Entity_NPC& npc, Room& room) +{ + if (!npc.isVisible) + { + npc.i1 -= npc_ticks_get(npc); + npc.friction = ULTRA_HORSEMAN_FRICTION; + if (npc.i1 >= 1) return; + ultra_famine_return(npc, room); + npc.velocity = vector_make(npc.sprite.isFlipX ? ULTRA_FAMINE_DASH_IN_TOP : -ULTRA_FAMINE_DASH_IN_TOP, 0); + npc.i1 = 0; + return; + } + + float from = room.bottomRightPos.x + ULTRA_FAMINE_SWEEP_EDGE; + float to = room.topLeftPos.x - ULTRA_FAMINE_SWEEP_EDGE; + if (npc.sprite.isFlipX) std::swap(from, to); + Vector& goal = npc.pathfinder.movementTarget; + goal.x = (to - from) * (npc.v1.x / ULTRA_FAMINE_SWEEP_FRAMES) + from; + float wave = std::clamp((std::sin(npc.v1.x * ULTRA_FAMINE_SWEEP_WAVE + npc.v1.y) + 1) * HALF, 0.0f, 1.0f); + float top = room.topLeftPos.y - ULTRA_FAMINE_SWEEP_OVER; + goal.y = (room.bottomRightPos.y + ULTRA_FAMINE_SWEEP_OVER - top) * wave + top; + if (npc.v1.x == 0) + { + npc.pos = goal; + npc.velocity = {}; + } + npc.friction = ULTRA_HORSEMAN_FRICTION; + npc.velocity = vector_add(npc.velocity, vector_scale(vector_sub(goal, npc.pos), ULTRA_FAMINE_SWEEP_SPRING * npc.speedMultiplier)); + bool isPast = npc.sprite.isFlipX ? npc.pos.x > to : npc.pos.x < to; + if (isPast) + { + npc.isVisible = false; + npc.entityCollisionClass = ENTCOLL_NONE; + npc.i1 = ULTRA_FAMINE_AWAY_FRAMES; + } + ultra_famine_flies_drop(npc); + npc.v1.x += npc.speedMultiplier; +} + +// The headless form's ring: six rays of six wiggling shots growing faster and bigger, a blood cloud and its burst. +static void ultra_famine_ring(Entity_NPC& npc, Vector center) +{ + float offset = npc.stateFrame % ULTRA_FAMINE_RING_SWAP == 0 ? 0 : ULTRA_FAMINE_RING_OFFSET; + ProjectileParams params; + params.bulletFlags = PROJECTILE_WIGGLE; + for (int ray = 0; ray < ULTRA_FAMINE_RING_RAYS; ray++) + { + Vector direction = vector_from_angle((float)ray * ULTRA_FAMINE_RING_TURN + offset); + for (int shot = 0; shot < ULTRA_FAMINE_RING_SHOTS; shot++) + { + params.scale = (float)shot * ULTRA_FAMINE_RING_GROWTH + 1; + Entity_Projectile* projectile = + npc.fire_projectiles(vector_add(center, vector_scale(direction, ULTRA_FAMINE_RING_FROM)), + vector_scale(direction, (float)shot + ULTRA_FAMINE_RING_SPEED), PROJECTILES_SINGLE, params); + projectile->wiggleFrameOffset = shot * ULTRA_FAMINE_RING_WIGGLE; + shot_level_set(projectile); + } + } + npc.MakeBloodCloud(vector_add(center, ULTRA_FAMINE_NECK), ULTRA_FAMINE_BLOOD_COLOR, 1)->renderDepthOffset = + ULTRA_FAMINE_CLOUD_DEPTH; + npc.PlaySound(SOUND_BLOODSHOOT, ULTRA_FAMINE_BURST_VOLUME, 2, false, 1); + npc_sound_play(SOUND_FAMINE_BURST, 1, 2, 1); +} + +// The headless form's pair: one shot either side of its second angle (the slower first), and two blood splashes. +// The second splash follows v2, which nothing sets, so it always flies right. +static void ultra_famine_pair(Entity_NPC& npc, Vector center) +{ + ProjectileParams params; + for (int side = -1; side < 2; side += 2) + { + Vector direction = vector_from_angle((float)side * ULTRA_FAMINE_PAIR_SPREAD + npc.v1.y); + float speed = (float)side + (float)side + ULTRA_FAMINE_PAIR_SPEED; + Entity_Projectile* shot = npc.fire_projectiles(vector_add(center, vector_scale(direction, ULTRA_FAMINE_PAIR_FROM)), + vector_scale(direction, speed), PROJECTILES_SINGLE, params); + params.scale = ULTRA_FAMINE_PAIR_SCALE; + shot_level_set(shot); + } + Vector splash = vector_scale(vector_from_angle(npc.v1.x), ULTRA_FAMINE_SPLASH_SPEED); + blood_explosion_spawn(BLOOD_EXPLOSION_SPLASH_BIG, center, ULTRA_FAMINE_NECK, ULTRA_FAMINE_BLOOD_COLOR, splash) + ->renderDepthOffset = ULTRA_FAMINE_CLOUD_DEPTH; + splash = vector_scale(vector_from_angle(npc.v2.x), ULTRA_FAMINE_SPLASH_SPEED); + blood_explosion_spawn(BLOOD_EXPLOSION_SPLASH, center, ULTRA_FAMINE_NECK, ULTRA_FAMINE_BLOOD_COLOR, splash) + ->renderDepthOffset = ULTRA_FAMINE_CLOUD_DEPTH; + npc.PlaySound(SOUND_TEARS_FIRE, 1, 2, false, 1); +} + +// The headless form: its gurgle, pulled to the centre, its angles turning every 8 ticks with a ring or a pair. +static void ultra_famine_headless(Entity_NPC& npc) +{ + SFXManager& sfx = g_manager->sfxManager; + if (!npc.isDead && !sfx.IsPlaying(SOUND_FAMINE_GURGLE)) sfx.SetAmbientSound(SOUND_FAMINE_GURGLE, 1, 1); + if (npc.sprite.IsEventTriggered("Shoot")) + { + npc.sprite.isFlipX = false; + npc.PlaySound(SOUND_GRROOWL, 1, 2, false, 1); + } + if (npc.sprite.IsFinished()) + { + npc.sprite.Play("HeadLoop"); + npc.stateFrame = 0; + npc.v1 = vector_make(ULTRA_FAMINE_HEAD_START, ULTRA_FAMINE_HEAD_START); + } + npc.friction = ULTRA_HORSEMAN_FRICTION; + if (npc.sprite.animState.IsLoopingAnimation() || npc.sprite.WasEventTriggered("Shoot")) + { + Vector pull = vector_scale(vector_sub(Room::GetCenterPos(), npc.pos), ULTRA_FAMINE_CENTER_PULL); + if (vector_length(pull) > 1) pull = vector_normalized(pull); + npc.velocity = vector_add(npc.velocity, vector_scale(pull, npc.speedMultiplier)); + } + if (!npc.sprite.animState.IsLoopingAnimation()) return; + + Vector center = npc.pos; + for (int tick = npc_ticks_get(npc); tick > 0; tick--) + { + npc.stateFrame++; + if (npc.stateFrame % ULTRA_FAMINE_TURN_EVERY != 0) continue; + npc.v1.x = normalize_angle_degrees(npc.v1.x + ULTRA_FAMINE_TURN_A); + npc.v1.y = normalize_angle_degrees(npc.v1.y + ULTRA_FAMINE_TURN_B); + if (npc.stateFrame % ULTRA_FAMINE_RING_EVERY == 0) ultra_famine_ring(npc, center); + else ultra_famine_pair(npc, center); + } +} + +// Its head bursts off on the first hit below a third while it is on screen, and everything the Beast's forms +// spawned dies. +static void ultra_famine_behead(Entity_NPC& npc) +{ + gibs_spawn({.position = npc.pos, + .spawner = &npc, + .spread = ULTRA_HORSEMAN_GIB_SPREAD, + .amount = ULTRA_HORSEMAN_GIBS, + .gibFlags = npc.config->gibFlags}); + npc_sound_play(SOUND_FAMINE_DEATH_1, 1, 2, 1); + game_shake_screen(ULTRA_HORSEMAN_SHAKE); + npc.pos.y -= ULTRA_FAMINE_HEAD_POP; + npc.state = ULTRA_HORSEMAN_HEADLESS; + npc.sprite.Play("Transition"); + horseman_spawns_kill(npc, HORSEMAN_CLEAR_SHOTS, -1); +} + +// 00444cc0 Ultra Famine (951.10): hovers, dashes out at the player's row, peeks in five times to spray shots, sweeps +// across dropping flies and rushes back; beheaded below a third it turns rings and pairs of shots from the centre. +static void ultra_famine_update(Entity_NPC& npc) +{ + Room& room = *g_game->room; + if (npc.aiCallPhase == AI_PHASE_PRE_UPDATE) return horseman_sink(npc); + + bool isBeheaded = npc.state != ULTRA_HORSEMAN_HEADLESS && npc.health < npc.maxHitPoints * ULTRA_FAMINE_HEADLESS_SHARE && + npc.pendingDamage > 0 && room.IsPositionInRoom(npc.pos, 0); + if (isBeheaded) ultra_famine_behead(npc); + else if (npc.isDead) + { + g_manager->sfxManager.Stop(SOUND_FAMINE_GURGLE); + npc_sound_play(SOUND_FAMINE_DEATH_2, 1, 2, 1); + } + + switch (npc.state) + { + case NPC_STATE_INIT: + horseman_init(npc); + npc.aiCallFlags = AI_CALL_PRE_UPDATE; + horseman_music_layer_set(-1); + break; + case NPC_STATE_IDLE: + if (horseman_hover(npc) < ULTRA_FAMINE_HOVER_FRAMES) break; + npc_sound_play(SOUND_FAMINE_DASH_START, 1, 2, 1); + npc.sprite.Play("DashStart"); + npc.state = ULTRA_FAMINE_DASH_OUT; + break; + case ULTRA_FAMINE_DASH_IN: + ultra_famine_dash_in(npc); + break; + case ULTRA_FAMINE_DASH_OUT: + ultra_famine_dash_out(npc); + break; + case ULTRA_FAMINE_PEEK: + ultra_famine_peek(npc, room); + break; + case ULTRA_FAMINE_SWEEP: + ultra_famine_sweep(npc, room); + break; + case ULTRA_HORSEMAN_HEADLESS: + ultra_famine_headless(npc); + break; + case ULTRA_HORSEMAN_ARRIVING: + npc_sound_play(SOUND_FAMINE_APPEAR, 1, 2, 1); + npc.state = ULTRA_FAMINE_DASH_IN; + npc.isVisible = true; + npc.entityCollisionClass = ENTCOLL_ALL; + npc.sprite.Play("DashLoop"); + npc.velocity = vector_make(npc.sprite.isFlipX ? ULTRA_FAMINE_DASH_IN_TOP : -ULTRA_FAMINE_DASH_IN_TOP, 0); + npc.i1 = 0; + break; + } +} + +// Ultra Famine's fly (951.11): one of three looks, it jitters toward its target for 70 ticks (kept off the top 80), +// brakes for 10 and dashes straight at where the target was. Its extra health drains 10 every 15 ticks, and it is +// gone 100 outside the room. +constexpr int FAMINE_FLY_LOOKS = 3; +constexpr std::array FAMINE_FLY_ANIMATIONS = {"Idle", "Idle2", "Idle3"}; +constexpr int FAMINE_FLY_SEEK_FRAMES = 70; +constexpr int FAMINE_FLY_BRAKE_FRAMES = 10; +constexpr float FAMINE_FLY_FRICTION_RANGE = 0.1f; +constexpr float FAMINE_FLY_JITTER = 60; +constexpr float FAMINE_FLY_TOP = 80; +constexpr float FAMINE_FLY_TOP_PUSH = 0.4f; +constexpr float FAMINE_FLY_DASH_SPEED = 6; +constexpr float FAMINE_FLY_DASH_FRICTION = 0.86f; +constexpr float FAMINE_FLY_DASH_PUSH = 0.4f; +constexpr float FAMINE_FLY_GONE = -100; +constexpr float FAMINE_FLY_DRAIN_EVERY = 15; +constexpr float FAMINE_FLY_DRAIN = 10; + +// Its extra health drains every 15 ticks to its maximum. +static void fly_health_drain(Entity_NPC& npc) +{ + if (npc.health <= npc.maxHitPoints || npc.GetIntervalTicks(FAMINE_FLY_DRAIN_EVERY, 0) == 0) return; + npc.health = std::max(npc.health - FAMINE_FLY_DRAIN, npc.maxHitPoints); +} + +// 00447180 Ultra Famine's fly (951.11): it jitters toward its target, brakes and dashes at it. +// A look past the third shows the third, where the original reads past its table. +static void ultra_famine_fly_update(Entity_NPC& npc) +{ + switch (npc.state) + { + case NPC_STATE_INIT: + npc.sprite.Play(FAMINE_FLY_ANIMATIONS[std::min(npc.subtype, FAMINE_FLY_LOOKS - 1)]); + npc.state = NPC_STATE_IDLE; + npc.stateFrame = FAMINE_FLY_SEEK_FRAMES; + break; + case NPC_STATE_IDLE: + { + if (npc.stateFrame < 1) + { + npc.state = NPC_STATE_ATTACK; + npc.stateFrame = FAMINE_FLY_BRAKE_FRAMES; + break; + } + npc.friction *= random_unit() * FAMINE_FLY_FRICTION_RANGE + ULTRA_HORSEMAN_FRICTION; + Vector seek = vector_sub(npc.CalcTargetPosition(0), npc.pos); + seek = vector_resized(seek, random_unit()); + seek = vector_rotated(seek, random_unit() * FAMINE_FLY_JITTER - FAMINE_FLY_JITTER * HALF); + npc.velocity = vector_add(npc.velocity, vector_scale(seek, npc.speedMultiplier)); + float top = g_game->room->topLeftPos.y + FAMINE_FLY_TOP; + if (npc.pos.y < top) npc.velocity.y += (top - npc.pos.y) * FAMINE_FLY_TOP_PUSH * npc.speedMultiplier; + npc.stateFrame -= npc_ticks_get(npc); + break; + } + case NPC_STATE_ATTACK: + if (npc.stateFrame < 1) + { + npc.friction = FAMINE_FLY_DASH_FRICTION; + npc.velocity = vector_add(npc.velocity, vector_scale(npc.v1, FAMINE_FLY_DASH_PUSH * npc.speedMultiplier)); + break; + } + npc.friction = ULTRA_HORSEMAN_FRICTION; + npc.stateFrame -= npc_ticks_get(npc); + if (npc.stateFrame < 1) + npc.v1 = vector_scale(vector_normalized(vector_sub(npc.CalcTargetPosition(0), npc.pos)), FAMINE_FLY_DASH_SPEED); + break; + } + + if (!g_game->room->IsPositionInRoom(npc.pos, FAMINE_FLY_GONE)) npc.Remove(); + fly_health_drain(npc); +} + +// Ultra Pestilence (951.20): it drifts near the room's middle, spits a lob at the player three times and sends its +// maggot through the room once, trickling flies all the while (24 at most). Below 40% its head bursts, killing what +// the Beast's forms spawned but its flies; headless it sprays a fountain from its neck, and twice coughs up a ball of +// flies. Dying it sinks and bursts into maggots. +constexpr float ULTRA_PESTILENCE_HEADLESS_SHARE = 0.4f; +constexpr float ULTRA_PESTILENCE_BALL_SHARE = 0.2f; +constexpr int ULTRA_PESTILENCE_HEADLESS_HOVER = NPC_STATE_MOVE; +constexpr int ULTRA_PESTILENCE_SPIT = NPC_STATE_ATTACK; +constexpr int ULTRA_PESTILENCE_MAGGOT_ATTACK = NPC_STATE_ATTACK2; +constexpr int ULTRA_PESTILENCE_NECK_SPIT = NPC_STATE_STOMP; +constexpr int ULTRA_PESTILENCE_HORSE_SPIT = NPC_STATE_SUMMON; +constexpr int ULTRA_PESTILENCE_SPITS = 3; +constexpr int ULTRA_PESTILENCE_ATTACK_FRAMES = 90; +constexpr int ULTRA_PESTILENCE_MAGGOT_HOLD = 60; +constexpr int ULTRA_PESTILENCE_BALL_FRAMES = 59; +constexpr int ULTRA_PESTILENCE_NECK_FRAMES = 120; + +// Its arrival from the right at 2 a tick to 15, braking at 0.95 from 40 inside to under 8. +constexpr float ULTRA_PESTILENCE_ARRIVE_PUSH = 2; +constexpr float ULTRA_PESTILENCE_ARRIVE_TOP = 15; +constexpr float ULTRA_PESTILENCE_ARRIVE_EDGE = 40; +constexpr float ULTRA_PESTILENCE_ARRIVE_BRAKE = 0.95f; +constexpr float ULTRA_PESTILENCE_ARRIVE_STOP = 8; + +// Its hover: a goal 20 to 80 from the last within 60 of the room's edges every 20 to 39 ticks, kept 180 from the +// sides and inside the middle band (80 tall headless). +constexpr float ULTRA_PESTILENCE_GOAL_LEAST = 20; +constexpr float ULTRA_PESTILENCE_GOAL_RANGE = 60; +constexpr float ULTRA_PESTILENCE_GOAL_MARGIN = 60; +constexpr float ULTRA_PESTILENCE_KEEP_IN = 180; +constexpr float ULTRA_PESTILENCE_HEADLESS_BAND = 80; +constexpr float ULTRA_PESTILENCE_KEEP_IN_PUSH = 0.002f; + +// Its flies: 16 at the start, one every 30 ticks, up to 24, flung 2 to 6 from 10 to 30 out with 50 health, fading in +// over 15 ticks at 0.8 to 1.2 of their size. +constexpr int ULTRA_PESTILENCE_FIRST_FLIES = 16; +constexpr float ULTRA_PESTILENCE_FLY_EVERY = 30; +constexpr int ULTRA_PESTILENCE_FLY_CAP = 24; +constexpr uint32_t ULTRA_PESTILENCE_FLY_LOOKS = 3; +constexpr float ULTRA_PESTILENCE_FLY_SPEED = 2; +constexpr float ULTRA_PESTILENCE_FLY_SPEED_RANGE = 4; +constexpr float ULTRA_PESTILENCE_FLY_FROM = 10; +constexpr float ULTRA_PESTILENCE_FLY_FROM_RANGE = 20; +constexpr float ULTRA_PESTILENCE_FLY_HEALTH = 50; +constexpr int ULTRA_PESTILENCE_FLY_FADE = 15; +constexpr float ULTRA_PESTILENCE_FLY_SCALE = 0.8f; +constexpr float ULTRA_PESTILENCE_FLY_SCALE_RANGE = 0.4f; +constexpr ColorMod ULTRA_PESTILENCE_FLY_FADE_COLOR = tint_color_make(1, 1, 1, 0); + +// Its spit: a big exploding lob that lands on the player's x at the lava line, rising at 20 under a fall of 1. +constexpr float ULTRA_PESTILENCE_LOB_RISE = -20; +constexpr float ULTRA_PESTILENCE_LOB_FALL = 1; +constexpr float ULTRA_PESTILENCE_LOB_SCALE = 3; +constexpr ColorMod ULTRA_PESTILENCE_LOB_COLOR = {{1, 1, 1, 1}, {0.4f, 2, 0.5f, 1}, {0, 0, 0}}; + + +// Its maggot attack: the maggot out at 10 with 75% of that as its push, the horse kicked back half of it, its splash +// drawn on top, and 8 small maggots flung up to 3 off it from 6 about the mouth. +constexpr float ULTRA_PESTILENCE_MAGGOT_SPEED = 10; +constexpr float ULTRA_PESTILENCE_MAGGOT_PUSH = 0.75f; +constexpr float ULTRA_PESTILENCE_RECOIL_DECAY = HALF; +constexpr int ULTRA_PESTILENCE_SPLASH_Z = 500; +constexpr int ULTRA_PESTILENCE_SMALL_MAGGOTS = 8; +constexpr float ULTRA_PESTILENCE_SMALL_MAGGOT_SPEED = 3; +constexpr float ULTRA_PESTILENCE_SMALL_MAGGOT_SCATTER = 6; +constexpr float ULTRA_PESTILENCE_SMALL_MAGGOT_RISE = -8; +constexpr float ULTRA_PESTILENCE_SMALL_MAGGOT_MASS = 15; + +// Its neck fountain: a shot a tick for 30 ticks, up at 16 (at least 6) with 6 of scatter and 5 toward its facing, +// 1 to 1.8 big, slowing, hitting enemies too and speeding up after 30, falling at 0.5, a splash every 4. +constexpr int ULTRA_PESTILENCE_NECK_SHOTS = 29; +constexpr float ULTRA_PESTILENCE_NECK_SCATTER = 6; +constexpr float ULTRA_PESTILENCE_NECK_RISE = -16; +constexpr float ULTRA_PESTILENCE_NECK_LEAST_RISE = -6; +constexpr float ULTRA_PESTILENCE_NECK_LEAN = 5; +constexpr float ULTRA_PESTILENCE_NECK_SCALE_RANGE = 0.8f; +constexpr float ULTRA_PESTILENCE_NECK_ACCELERATION = 0.96f; +constexpr int ULTRA_PESTILENCE_NECK_CHANGE = 30; +constexpr float ULTRA_PESTILENCE_NECK_FALL = HALF; +constexpr int ULTRA_PESTILENCE_NECK_SPLASH_EVERY = 4; +constexpr float ULTRA_PESTILENCE_NECK_SPLASH_SHARE = 0.4f; + +// Its fly ball, coughed out at 8 and down 3, with 4 dust clouds about the mouth. +constexpr float ULTRA_PESTILENCE_BALL_SPEED = 8; +constexpr float ULTRA_PESTILENCE_BALL_DROP = 3; +constexpr int ULTRA_PESTILENCE_COUGH_DUSTS = 4; +constexpr float ULTRA_PESTILENCE_COUGH_SCATTER = 1.5f; +constexpr float ULTRA_PESTILENCE_COUGH_SPREAD = 10; +constexpr ColorMod ULTRA_PESTILENCE_DUST_COLOR = tint_color_make(0.7f, 0.8f, 0.65f, 0.6f); + +// Its death burst: 12 small maggots flung 8 to 18 about it and up 8 to 12, 1 to 1.5 big. +constexpr int ULTRA_PESTILENCE_DEATH_MAGGOTS = 12; +constexpr float ULTRA_PESTILENCE_DEATH_MAGGOT_SPEED = 8; +constexpr float ULTRA_PESTILENCE_DEATH_MAGGOT_SPEED_RANGE = 10; +constexpr float ULTRA_PESTILENCE_DEATH_MAGGOT_LIFT = -8; +constexpr float ULTRA_PESTILENCE_DEATH_MAGGOT_LIFT_RANGE = 4; +constexpr float ULTRA_PESTILENCE_DEATH_MAGGOT_SCALE_RANGE = HALF; + +// Its dying burst on the clip's Explosion: every shot gone, every spawn of the Beast's forms killed, and 12 maggots. +static void ultra_pestilence_death_burst(Entity_NPC& npc) +{ + horseman_spawns_kill(npc, HORSEMAN_CLEAR_SHOTS, -1); + for (int i = 0; i < ULTRA_PESTILENCE_DEATH_MAGGOTS; i++) + { + Vector direction = random_direction(); + float speed = random_unit() * ULTRA_PESTILENCE_DEATH_MAGGOT_SPEED_RANGE + ULTRA_PESTILENCE_DEATH_MAGGOT_SPEED; + Vector fling = vector_scale(direction, speed); + fling.y += ULTRA_PESTILENCE_DEATH_MAGGOT_LIFT - random_unit() * ULTRA_PESTILENCE_DEATH_MAGGOT_LIFT_RANGE; + Entity_NPC* maggot = small_maggot_spawn(vector_add(npc.pos, vector_scale(direction, speed * 2)), 0, fling, + ULTRA_PESTILENCE_SMALL_MAGGOT_RISE); + maggot->entityCollisionClass = ENTCOLL_NONE; + float scale = random_unit() * ULTRA_PESTILENCE_DEATH_MAGGOT_SCALE_RANGE + 1; + maggot->mass = ULTRA_PESTILENCE_SMALL_MAGGOT_MASS; + maggot->sprite.scale = vector_make(scale, scale); + } +} + +// Its head bursts below 40%: its fly ball threshold set, and every spawn of the Beast's forms but its flies killed. +static void ultra_pestilence_behead(Entity_NPC& npc) +{ + gibs_spawn({.color = npc.splatColor, + .position = npc.pos, + .spawner = &npc, + .spread = ULTRA_HORSEMAN_GIB_SPREAD, + .amount = ULTRA_HORSEMAN_GIBS, + .gibFlags = npc.config->gibFlags}); + game_shake_screen(ULTRA_HORSEMAN_SHAKE); + npc.state = ULTRA_HORSEMAN_HEADLESS; + npc.sprite.Play("Transition"); + npc_sound_play(SOUND_PESTILENCE_HEAD_DEATH, 1, 2, champion_pitch_get(npc)); + npc_sound_play(SOUND_PESTILENCE_HEAD_EXPLODE, 1, 2, champion_pitch_get(npc)); + npc.aiFloat = npc.maxHitPoints * ULTRA_PESTILENCE_HEADLESS_SHARE; + horseman_spawns_kill(npc, HORSEMAN_CLEAR_SHOTS_AND_SMOKE, BEAST_ULTRA_PESTILENCE_FLY); +} + +// Its trickle of flies: 16 at its start, then one each 30 ticks, while fewer than 24 fly about. +static void ultra_pestilence_flies_spawn(Entity_NPC& npc) +{ + int flies = npc.state == NPC_STATE_INIT ? ULTRA_PESTILENCE_FIRST_FLIES : npc.GetIntervalTicks(ULTRA_PESTILENCE_FLY_EVERY, 0); + if (flies <= 0) return; + int count = 0; + for (Entity* entity : g_game->room->entityList.updateEL) + if (entity->IsType(ENTITY_BEAST, BEAST_ULTRA_PESTILENCE_FLY, -1)) count++; + + for (int fly = 0; fly < flies && count < ULTRA_PESTILENCE_FLY_CAP; fly++, count++) + { + Vector direction = random_direction(); + uint32_t seed = Random(); + int look = (int)(Random() % ULTRA_PESTILENCE_FLY_LOOKS); + float speed = random_unit() * ULTRA_PESTILENCE_FLY_SPEED_RANGE + ULTRA_PESTILENCE_FLY_SPEED; + float distance = random_unit() * ULTRA_PESTILENCE_FLY_FROM_RANGE + ULTRA_PESTILENCE_FLY_FROM; + Entity* spawned = g_game->Spawn({.position = vector_add(npc.pos, vector_scale(direction, distance)), + .velocity = vector_scale(direction, speed), + .spawner = &npc, + .subType = look, + .type = ENTITY_BEAST, + .variant = BEAST_ULTRA_PESTILENCE_FLY, + .seed = seed}); + spawned->health = ULTRA_PESTILENCE_FLY_HEALTH; + spawned->parent = &npc; + spawned->flags &= ~FLAG_APPEAR; + spawned->SetColor(ULTRA_PESTILENCE_FLY_FADE_COLOR, ULTRA_PESTILENCE_FLY_FADE, 1, true, true); + float scale = random_unit() * ULTRA_PESTILENCE_FLY_SCALE_RANGE + ULTRA_PESTILENCE_FLY_SCALE; + spawned->sprite.scale = vector_make(scale, scale); + spawned->Update(); + } +} + +// Faces the player. +static void horseman_face_target(Entity_NPC& npc) +{ + npc.sprite.isFlipX = npc.pos.x < npc.GetPlayerTarget()->pos.x; +} + +// The hover's decisions with the horse: hold while the maggot is out, then spit three times and send the maggot. +static void ultra_pestilence_horse_decide(Entity_NPC& npc) +{ + if (npc.sprite.IsEventTriggered("Sound")) npc_sound_play(SOUND_DEATH_REVERSE, 1, 2, champion_pitch_get(npc)); + if (npc.child && npc.stateFrame > ULTRA_PESTILENCE_MAGGOT_HOLD) + { + npc.stateFrame = ULTRA_PESTILENCE_MAGGOT_HOLD; + return; + } + if (npc.stateFrame < ULTRA_PESTILENCE_ATTACK_FRAMES) return; + if (npc.projectileCooldown < ULTRA_PESTILENCE_SPITS) + { + npc.state = ULTRA_PESTILENCE_SPIT; + npc.sprite.Play("Spit"); + npc_sound_play(SOUND_PESTILENCE_PUKE_START, 1, 2, 1); + return; + } + npc.state = ULTRA_PESTILENCE_MAGGOT_ATTACK; + npc.sprite.Play("MaggotAttack"); + npc.projectileCooldown = 0; + horseman_face_target(npc); +} + +// The headless hover's decisions: a fly ball each time its health drops past the next threshold, else its neck +// fountain every 120 ticks. +static void ultra_pestilence_headless_decide(Entity_NPC& npc) +{ + if (npc.health < npc.aiFloat && npc.stateFrame > ULTRA_PESTILENCE_BALL_FRAMES) + { + npc.state = ULTRA_PESTILENCE_HORSE_SPIT; + npc.sprite.Play("HorseSpit"); + horseman_face_target(npc); + npc.aiFloat -= npc.maxHitPoints * ULTRA_PESTILENCE_BALL_SHARE; + return; + } + if (npc.stateFrame < ULTRA_PESTILENCE_NECK_FRAMES) return; + npc.state = ULTRA_PESTILENCE_NECK_SPIT; + npc.sprite.Play("HeadlessSpit"); + npc_sound_play(SOUND_PESTILENCE_BODY_SHOOT, 1, 2, 1); + npc_sound_play(SOUND_PESTILENCE_NECK_PUKE, 1, 2, 1); + horseman_face_target(npc); +} + +// The hover, with the horse or headless: drifting toward a goal wandering near the room's middle. +static void ultra_pestilence_hover(Entity_NPC& npc, Room& room) +{ + bool isHeadless = npc.state == ULTRA_PESTILENCE_HEADLESS_HOVER; + if (npc.sprite.IsFinished()) npc.sprite.Play(isHeadless ? "HeadlessIdle" : "Idle"); + npc.friction = ULTRA_HORSEMAN_FRICTION; + npc.velocity = vector_add(npc.velocity, vector_scale(npc.pathfinder.moveDirection, ULTRA_HOVER_PUSH * npc.speedMultiplier)); + npc.GetPlayerTarget(); + + PathFinder& path = npc.pathfinder; + if (path.moveCountdown < 1) + { + path.moveCountdown = (int)(Random() % ULTRA_HOVER_RETARGET) + ULTRA_HOVER_RETARGET; + Vector direction = random_direction(); + float distance = random_unit() * ULTRA_PESTILENCE_GOAL_RANGE + ULTRA_PESTILENCE_GOAL_LEAST; + path.movementTarget = room.GetClampedPositionImpl(vector_add(path.movementTarget, vector_scale(direction, distance)), + ULTRA_PESTILENCE_GOAL_MARGIN, ULTRA_PESTILENCE_GOAL_MARGIN, + ULTRA_PESTILENCE_GOAL_MARGIN, ULTRA_PESTILENCE_GOAL_MARGIN); + } + else + path.moveCountdown -= npc_ticks_get(npc); + + horseman_steer(npc, ULTRA_HOVER_STEER * npc.speedMultiplier); + HoverBounds bounds = hover_bounds_get(vector_make(ULTRA_PESTILENCE_KEEP_IN, ULTRA_PESTILENCE_KEEP_IN), ULTRA_PESTILENCE_KEEP_IN_PUSH); + if (isHeadless) bounds.bottomRight.y = bounds.topLeft.y + ULTRA_PESTILENCE_HEADLESS_BAND; + horseman_keep_in(npc, bounds); + npc.stateFrame += npc_ticks_get(npc); + if (isHeadless) ultra_pestilence_headless_decide(npc); + else ultra_pestilence_horse_decide(npc); +} + +// Where its ShootPos null is in the room. +static Vector shoot_pos_get(Entity_NPC& npc) +{ + return vector_add(npc.pos, npc.GetNullOffset("ShootPos")); +} + +// The spit: a blob lobbed to land on the player's x at the lava line. Returns whether it is done. +static bool ultra_pestilence_spit(Entity_NPC& npc, Room& room) +{ + npc.friction = ULTRA_HORSEMAN_FRICTION; + if (npc.sprite.IsEventTriggered("Shoot")) + { + npc_sound_play(SOUND_PESTILENCE_BARF, 1, 2, 1); + Vector mouth = shoot_pos_get(npc); + ColorMod cloud = npc.splatColor; + color_multiply(cloud, ULTRA_FAMINE_BLOOD_COLOR); + npc.MakeBloodCloud(mouth, cloud, 1); + ProjectileParams params; + params.scale = ULTRA_PESTILENCE_LOB_SCALE; + params.color = ULTRA_PESTILENCE_LOB_COLOR; + params.bulletFlags = PROJECTILE_EXPLODE | PROJECTILE_NO_WALL_COLLIDE; + + Entity* target = npc.GetPlayerTarget(); + npc.sprite.isFlipX = npc.pos.x < target->pos.x; + float across = target->pos.x - mouth.x; + float drop = room.get_lava_line_y() - mouth.y; + float distance = std::abs(across); + float rise = distance * ULTRA_PESTILENCE_LOB_RISE; + float root = std::sqrt(std::max(2 * distance * distance * drop + rise * rise, 0.0f)); + float speed = (root + rise) / (drop + drop); + Vector velocity = vector_make(across < 0 ? -speed : speed, ULTRA_PESTILENCE_LOB_RISE); + Entity_Projectile* lob = npc.fire_projectiles(mouth, velocity, PROJECTILES_SINGLE, params); + lob->fallingSpeed = 0; + lob->fallingAccel = ULTRA_PESTILENCE_LOB_FALL; + } + if (!npc.sprite.IsFinished()) return false; + npc.projectileCooldown++; + npc.sprite.Play("Idle"); + npc.state = NPC_STATE_IDLE; + return true; +} + +// The maggot attack: its maggot out of the mouth along its row with a recoil, 8 small maggots spilled after it. +// Returns whether it is done. +static bool ultra_pestilence_maggot_attack(Entity_NPC& npc) +{ + npc.friction = ULTRA_HORSEMAN_FRICTION; + if (npc.sprite.IsEventTriggered("Sound")) + { + npc_sound_play(SOUND_PESTILENCE_MAGGOT_START, 1, 2, 1); + npc_sound_play(SOUND_PESTILENCE_MAGGOT_POPOUT, 1, 2, 1); + } + if (npc.sprite.IsEventTriggered("Shoot")) + { + npc_sound_play(SOUND_PESTILENCE_MAGGOT_SHOOT, 1, 2, 1); + npc_sound_play(SOUND_PESTILENCE_MAGGOT_SHOOT2, 1, 2, 1); + Vector mouth = shoot_pos_get(npc); + float speed = npc.sprite.isFlipX ? ULTRA_PESTILENCE_MAGGOT_SPEED : -ULTRA_PESTILENCE_MAGGOT_SPEED; + npc.v1 = vector_make(-speed * HALF, -0.0f); + blood_explosion_spawn(BLOOD_EXPLOSION_SPLASH, mouth, {}, COLOR_GREEN_SPLAT, vector_make(speed * HALF, 0))->renderZOffset = + ULTRA_PESTILENCE_SPLASH_Z; + uint32_t seed = Random(); + Entity* maggot = g_game->Spawn({.position = mouth, + .velocity = vector_make(speed, 0), + .spawner = &npc, + .type = ENTITY_BEAST, + .variant = BEAST_ULTRA_PESTILENCE_MAGGOT, + .seed = seed}); + maggot->targetPosition = vector_make(speed * ULTRA_PESTILENCE_MAGGOT_PUSH, 0); + maggot->parent = &npc; + maggot->flags &= ~FLAG_APPEAR; + npc.child = maggot; + maggot->Update(); + + for (int i = 0; i < ULTRA_PESTILENCE_SMALL_MAGGOTS; i++) + { + Vector direction = random_direction(); + float fling = random_unit() * ULTRA_PESTILENCE_SMALL_MAGGOT_SPEED; + Vector velocity = vector_make(direction.x * fling + speed, direction.y * fling); + Vector spot = random_direction(); + float scatter = random_unit() * ULTRA_PESTILENCE_SMALL_MAGGOT_SCATTER; + Entity_NPC* small = small_maggot_spawn(vector_add(mouth, vector_scale(spot, scatter)), 0, velocity, + ULTRA_PESTILENCE_SMALL_MAGGOT_RISE); + small->entityCollisionClass = ENTCOLL_NONE; + small->mass = ULTRA_PESTILENCE_SMALL_MAGGOT_MASS; + } + } + if (npc.sprite.WasEventTriggered("Shoot")) + { + npc.velocity = vector_add(npc.velocity, vector_scale(npc.v1, npc.speedMultiplier)); + npc.v1 = vector_scale(npc.v1, timescale_factor(ULTRA_PESTILENCE_RECOIL_DECAY, npc.speedMultiplier)); + } + if (!npc.sprite.IsFinished()) return false; + npc.sprite.Play("Idle"); + npc.state = NPC_STATE_IDLE; + return true; +} + +// The neck fountain: from its Shoot a shot a tick for 30 ticks up out of its neck. Returns whether it is done. +static bool ultra_pestilence_neck_spit(Entity_NPC& npc) +{ + npc.friction = ULTRA_HORSEMAN_FRICTION; + if (npc.sprite.IsEventTriggered("Shoot")) npc.stateFrame = 0; + if (npc.sprite.WasEventTriggered("Shoot")) + { + Vector neck = shoot_pos_get(npc); + ProjectileParams params; + params.color = SHOT_COLOR_SICK; + float scale = random_unit() * ULTRA_PESTILENCE_NECK_SCALE_RANGE + 1; + params.bulletFlags = PROJECTILE_NO_WALL_COLLIDE | PROJECTILE_HIT_ENEMIES | PROJECTILE_CHANGE_FLAGS_AFTER_TIMEOUT; + params.changeFlags = PROJECTILE_ACCELERATE | PROJECTILE_NO_WALL_COLLIDE | PROJECTILE_HIT_ENEMIES; + params.acceleration = ULTRA_PESTILENCE_NECK_ACCELERATION; + params.changeTimeout = ULTRA_PESTILENCE_NECK_CHANGE; + params.scale = scale; + float lean = npc.sprite.isFlipX ? ULTRA_PESTILENCE_NECK_LEAN : -ULTRA_PESTILENCE_NECK_LEAN; + for (int tick = 0; tick < npc_ticks_get(npc) && npc.stateFrame <= ULTRA_PESTILENCE_NECK_SHOTS; tick++) + { + Vector direction = random_direction(); + Vector velocity = vector_make(direction.x * ULTRA_PESTILENCE_NECK_SCATTER + lean, + std::min(direction.y * ULTRA_PESTILENCE_NECK_SCATTER + ULTRA_PESTILENCE_NECK_RISE, + ULTRA_PESTILENCE_NECK_LEAST_RISE)); + Entity_Projectile* shot = npc.fire_projectiles(neck, velocity, PROJECTILES_SINGLE, params); + shot->fallingSpeed = 0; + shot->fallingAccel = ULTRA_PESTILENCE_NECK_FALL; + if (npc.stateFrame % ULTRA_PESTILENCE_NECK_SPLASH_EVERY == 0) + blood_explosion_spawn(BLOOD_EXPLOSION_BURST, neck, {}, COLOR_GREEN_SPLAT, + vector_scale(velocity, ULTRA_PESTILENCE_NECK_SPLASH_SHARE)); + npc.stateFrame++; + } + } + if (!npc.sprite.IsFinished()) return false; + npc.sprite.Play("HeadlessIdle"); + npc.state = ULTRA_PESTILENCE_HEADLESS_HOVER; + return true; +} + +// The cough: a fly ball out of the horse's mouth in a puff of dust. Returns whether it is done. +static bool ultra_pestilence_cough(Entity_NPC& npc) +{ + npc.friction = ULTRA_HORSEMAN_FRICTION; + if (npc.sprite.IsEventTriggered("Shoot")) + { + npc_sound_play(SOUND_PESTILENCE_COUGH, 1, 2, 1); + Vector mouth = shoot_pos_get(npc); + float speed = npc.sprite.isFlipX ? ULTRA_PESTILENCE_BALL_SPEED : -ULTRA_PESTILENCE_BALL_SPEED; + uint32_t seed = Random(); + Entity* ball = g_game->Spawn({.position = mouth, + .velocity = vector_make(speed, ULTRA_PESTILENCE_BALL_DROP), + .spawner = &npc, + .type = ENTITY_BEAST, + .variant = BEAST_ULTRA_PESTILENCE_FLY_BALL, + .seed = seed}); + ball->flags &= ~FLAG_APPEAR; + ball->parent = &npc; + npc.child = ball; + ball->Update(); + + for (int i = 0; i < ULTRA_PESTILENCE_COUGH_DUSTS; i++) + { + uint32_t dustSeed = Random(); + Vector direction = random_direction(); + float fling = random_unit() * ULTRA_PESTILENCE_COUGH_SCATTER; + Vector velocity = vector_make(direction.x * fling + speed, direction.y * fling + ULTRA_PESTILENCE_BALL_DROP); + Vector spot = random_direction(); + float spread = random_unit() * ULTRA_PESTILENCE_COUGH_SPREAD; + horseman_dust_spawn(npc, {.color = ULTRA_PESTILENCE_DUST_COLOR, + .position = vector_add(mouth, vector_scale(spot, spread)), + .velocity = velocity, + .seed = dustSeed}) + ->renderDepthOffset = ULTRA_DUST_DEPTH; + } + } + if (!npc.sprite.IsFinished()) return false; + npc.sprite.Play("HeadlessIdle"); + npc.state = ULTRA_PESTILENCE_HEADLESS_HOVER; + return true; +} + +// The arrival from the right: in at speed until 40 inside the edge, then braking into the hover. +static void ultra_pestilence_arrive(Entity_NPC& npc, Room& room) +{ + npc.sprite.Play("Idle"); + if (npc.i1 == 0) + { + npc.velocity.x = std::clamp(npc.velocity.x - npc.speedMultiplier * ULTRA_PESTILENCE_ARRIVE_PUSH, -ULTRA_PESTILENCE_ARRIVE_TOP, + ULTRA_PESTILENCE_ARRIVE_TOP); + if (npc.pos.x < room.bottomRightPos.x + ULTRA_PESTILENCE_ARRIVE_EDGE) npc.i1 = 1; + return; + } + npc.friction *= ULTRA_PESTILENCE_ARRIVE_BRAKE; + if (vector_length(npc.velocity) >= ULTRA_PESTILENCE_ARRIVE_STOP) return; + npc.state = NPC_STATE_IDLE; + npc.i1 = 0; +} + +// 004477b0 Ultra Pestilence (951.20): drifts, spits lobs and sends its maggot, trickling flies; headless below 40% +// it sprays from its neck and coughs fly balls; dying it sinks and bursts into maggots. +static void ultra_pestilence_update(Entity_NPC& npc) +{ + Room& room = *g_game->room; + if (npc.aiCallPhase == AI_PHASE_PRE_UPDATE) + { + if (npc.state != NPC_STATE_DEATH) return; + horseman_sink(npc); + if (npc.sprite.IsEventTriggered("Explosion")) ultra_pestilence_death_burst(npc); + return; + } + + bool isHorse = npc.state == NPC_STATE_IDLE || npc.state == ULTRA_PESTILENCE_SPIT || npc.state == ULTRA_PESTILENCE_MAGGOT_ATTACK; + if (isHorse && npc.health < npc.maxHitPoints * ULTRA_PESTILENCE_HEADLESS_SHARE) ultra_pestilence_behead(npc); + else if (npc.isDead) npc_sound_play(SOUND_PESTILENCE_DEATH, 1, 2, 1); + ultra_pestilence_flies_spawn(npc); + + bool isDone = false; + switch (npc.state) + { + case NPC_STATE_INIT: + npc.sprite.Play("Idle"); + npc_sound_play(SOUND_PESTILENCE_APPEAR, 1, 2, 1); + horseman_init(npc); + npc.splatColor = COLOR_GREEN_SPLAT; + npc.projectileCooldown = 0; + npc.aiCallFlags = AI_CALL_PRE_UPDATE; + horseman_music_layer_set(0); + return; + case NPC_STATE_IDLE: + case ULTRA_PESTILENCE_HEADLESS_HOVER: + return ultra_pestilence_hover(npc, room); + case ULTRA_PESTILENCE_NECK_SPIT: + isDone = ultra_pestilence_neck_spit(npc); + break; + case ULTRA_PESTILENCE_SPIT: + isDone = ultra_pestilence_spit(npc, room); + break; + case ULTRA_PESTILENCE_MAGGOT_ATTACK: + isDone = ultra_pestilence_maggot_attack(npc); + break; + case ULTRA_PESTILENCE_HORSE_SPIT: + isDone = ultra_pestilence_cough(npc); + break; + case ULTRA_HORSEMAN_HEADLESS: + npc.friction = ULTRA_HORSEMAN_FRICTION; + if (!npc.sprite.IsFinished()) return; + npc.sprite.Play("HeadlessIdle"); + npc.state = ULTRA_PESTILENCE_HEADLESS_HOVER; + return; + case ULTRA_HORSEMAN_ARRIVING: + return ultra_pestilence_arrive(npc, room); + } + if (isDone) npc.stateFrame = 0; +} + +// Ultra Pestilence's fly (951.21): one of three looks, it swarms about Pestilence (or wanders alone) on a heading that +// keeps it off the lava, which slows and burns it. A fly ball's flies orbit it on an ellipse of their own until it +// dies. Its extra health drains like Famine's flies', and with no spawner it dies off-screen. +constexpr int PESTILENCE_FLY_ORBIT = NPC_STATE_SPECIAL; +constexpr int PESTILENCE_FLY_Z = -1000; +constexpr uint64_t PESTILENCE_FLY_ORBIT_FLAGS = FLAG_NO_STATUS_EFFECTS | FLAG_NO_TARGET; +constexpr float PESTILENCE_FLY_WANDER = 40; +constexpr uint32_t PESTILENCE_FLY_WANDER_ODDS = 15; +constexpr float PESTILENCE_FLY_ALONE_PULL = 0.005f; +constexpr float PESTILENCE_FLY_ALONE_TOP = 2; +constexpr float PESTILENCE_FLY_ALONE_STEER = 0.004f; +constexpr float PESTILENCE_FLY_SWARM_PULL = 0.01f; +constexpr float PESTILENCE_FLY_SWARM_TOP = 4; +constexpr float PESTILENCE_FLY_SWARM_STEER = 0.001f; +constexpr float PESTILENCE_FLY_JITTER = 0.75f; +constexpr float PESTILENCE_FLY_LAVA_ABOVE = 80; +constexpr float PESTILENCE_FLY_LAVA_PUSH = 4; +constexpr float PESTILENCE_FLY_LAVA_NEAREST = 10; +constexpr float PESTILENCE_FLY_ORBIT_SPIN = 8; +constexpr int PESTILENCE_FLY_ORBIT_FRAMES = 30; + +// The lava's hold on what flies over it: slowed, and every 8 frames of the room burnt for 10 and set on fire. +constexpr float LAVA_FLY_SLOW = 0.9f; +constexpr int LAVA_BURN_FRAMES = 8; +constexpr float LAVA_BURN_DAMAGE = 10; +constexpr int LAVA_BURN_COUNTDOWN = 30; +constexpr int LAVA_FIRE_FRAMES = 90; + +// What flies low over the Beast's lava suffers. +static void lava_burn(Entity_NPC& npc) +{ + Room& room = *g_game->room; + if (npc.pos.y <= room.get_lava_line_y()) return; + npc.velocity = vector_scale(npc.velocity, LAVA_FLY_SLOW); + if (!room.isInitialized || (g_game->frameCount - room.enterFrame) % LAVA_BURN_FRAMES != 0) return; + npc.TakeDamage(LAVA_BURN_DAMAGE, DAMAGE_FIRE, EntityRef(), LAVA_BURN_COUNTDOWN); + npc.AddBurn(EntityRef(), LAVA_FIRE_FRAMES, 0, false); +} + +// Turns a heading up away from the lava when within 80 above it, then makes it a unit. +static void lava_heading_lift(Vector& heading, Entity& entity) +{ + float lava = g_game->room->get_lava_line_y(); + if (lava - PESTILENCE_FLY_LAVA_ABOVE < entity.pos.y) + heading.y -= PESTILENCE_FLY_LAVA_PUSH / std::max(PESTILENCE_FLY_LAVA_NEAREST, lava - entity.pos.y); + heading = vector_normalized(heading); +} + +// The swarm: pushed along its heading (harder the more it points at its goal), the heading drawn to the goal and +// jittered: Pestilence while it lives, else a spot it wanders to now and then. +static void pestilence_fly_swarm(Entity_NPC& npc) +{ + npc.friction *= ULTRA_HORSEMAN_FRICTION; + Vector& heading = npc.targetPosition; + Entity* parent = npc.parent.get(); + if (!parent) + { + if ((Random() & PESTILENCE_FLY_WANDER_ODDS) == 0) + npc.v2 = vector_add(npc.pos, vector_scale(random_direction(), PESTILENCE_FLY_WANDER)); + Vector toSpot = vector_sub(npc.v2, npc.pos); + float pull = std::clamp(vector_dot(toSpot, heading) * PESTILENCE_FLY_ALONE_PULL, 1.0f, PESTILENCE_FLY_ALONE_TOP); + npc_push(npc, vector_scale(heading, pull * random_unit())); + Vector jitter = random_direction(); + heading = vector_add(heading, vector_scale(vector_add(vector_scale(toSpot, PESTILENCE_FLY_ALONE_STEER), + vector_scale(jitter, PESTILENCE_FLY_JITTER)), + npc.speedMultiplier)); + } + else + { + Vector toParent = vector_sub(parent->pos, npc.pos); + float pull = std::clamp(vector_dot(toParent, heading) * PESTILENCE_FLY_SWARM_PULL, 1.0f, PESTILENCE_FLY_SWARM_TOP); + npc_push(npc, vector_scale(heading, pull * (random_unit() * HALF + HALF))); + Vector jitter = random_direction(); + heading = vector_add(heading, vector_scale(vector_add(vector_scale(toParent, PESTILENCE_FLY_SWARM_STEER), + vector_scale(jitter, PESTILENCE_FLY_JITTER)), + npc.speedMultiplier)); + } + lava_heading_lift(heading, npc); +} + +// Orbiting its fly ball on its ellipse, spinning its own way and flashing with it; free to swarm once it dies. +static void pestilence_fly_orbit(Entity_NPC& npc) +{ + Entity* ball = npc.parent.get(); + if (!ball) + { + npc.sprite.GetLayer(0)->color = COLOR_DEFAULT; + npc.flags &= ~PESTILENCE_FLY_ORBIT_FLAGS; + npc.state = NPC_STATE_IDLE; + npc.entityCollisionClass = ENTCOLL_ALL; + npc.isInvincible = false; + npc.targetPosition = vector_normalized(npc.velocity); + Vector wander = random_direction(); + npc.renderZOffset = PESTILENCE_FLY_Z; + npc.v2 = vector_add(npc.pos, vector_scale(wander, PESTILENCE_FLY_WANDER)); + return; + } + + RNG spin = RNG_DEFAULT; + spin._seed = npc.initSeed; + float turn = spin.RandomFloat() * PESTILENCE_FLY_ORBIT_SPIN - PESTILENCE_FLY_ORBIT_SPIN * HALF; + npc.v2.x = normalize_angle_degrees(turn * npc.speedMultiplier + npc.v2.x); + Vector along = vector_scale(vector_from_angle(npc.v2.x), npc.v1.x); + Vector across = vector_scale(vector_from_angle(npc.v2.x + RIGHT_ANGLE_DEGREES), npc.v1.y); + int previous = npc.stateFrame; + npc.stateFrame += npc_ticks_get(npc); + float phase = (float)previous / PESTILENCE_FLY_ORBIT_FRAMES * TAU; + while (npc.stateFrame > PESTILENCE_FLY_ORBIT_FRAMES) npc.stateFrame -= PESTILENCE_FLY_ORBIT_FRAMES; + npc.friction = 1; + Vector spot = vector_add(vector_add(vector_scale(along, std::cos(phase)), ball->pos), vector_scale(across, std::sin(phase))); + npc.velocity = vector_sub(spot, npc.pos); + npc.sprite.GetLayer(0)->color = ball->sprite.color; +} + +// 0044a040 Ultra Pestilence's fly (951.21): swarms about Pestilence or wanders alone, orbits a fly ball, and keeps off +// the lava that burns it. +static void pestilence_fly_update(Entity_NPC& npc) +{ + if (npc.aiCallPhase == AI_PHASE_PRE_UPDATE) + { + if (!npc.spawnerEntity && !g_game->room->IsPositionInRoom(npc.pos, 0)) npc.Kill(EntityRef()); + lava_burn(npc); + fly_health_drain(npc); + return; + } + + switch (npc.state) + { + case NPC_STATE_INIT: + { + npc.sprite.Play(FAMINE_FLY_ANIMATIONS[std::min(npc.subtype, FAMINE_FLY_LOOKS - 1)]); + npc.state = NPC_STATE_IDLE; + npc.targetPosition = random_direction(); + npc.renderZOffset = PESTILENCE_FLY_Z; + npc.aiCallFlags = AI_CALL_PRE_UPDATE; + npc.splatColor = COLOR_GREEN_SPLAT; + Entity* parent = npc.parent.get(); + if (parent && parent->IsType(ENTITY_BEAST, BEAST_ULTRA_PESTILENCE_FLY_BALL, -1)) + { + npc.flags |= PESTILENCE_FLY_ORBIT_FLAGS; + npc.state = PESTILENCE_FLY_ORBIT; + npc.entityCollisionClass = ENTCOLL_NONE; + npc.isInvincible = true; + npc.renderZOffset = 0; + return; + } + npc.v2 = vector_add(npc.pos, vector_scale(random_direction(), PESTILENCE_FLY_WANDER)); + break; + } + case NPC_STATE_IDLE: + pestilence_fly_swarm(npc); + break; + case PESTILENCE_FLY_ORBIT: + pestilence_fly_orbit(npc); + break; + } +} + +// Ultra Pestilence's fly ball (951.23): six flies orbit it, fewer as it is hurt, and 14 more break free over its +// health; it homes on its target (by its size), keeps apart from other balls within 100 and off the lava. +constexpr size_t FLY_BALL_ORBITERS = 6; +constexpr float FLY_BALL_RELEASES = 14; +constexpr float FLY_BALL_ORBIT_LEAST = 0.2f; +constexpr float FLY_BALL_ORBIT_STEP = 0.05f; +constexpr float FLY_BALL_ORBIT_RANGE = 0.1f; +constexpr float FLY_BALL_ORBIT_WIDE = 40; +constexpr float FLY_BALL_ORBIT_TALL = 8; +constexpr uint32_t FLY_BALL_ORBIT_PHASES = 30; +constexpr float FLY_BALL_FLY_SPEED = 5; +constexpr float FLY_BALL_FLY_SPEED_RANGE = 5; +constexpr float FLY_BALL_FLY_FROM = 10; +constexpr float FLY_BALL_FLY_FROM_RANGE = 10; +constexpr float FLY_BALL_FLY_HEALTH = 50; +constexpr float FLY_BALL_COAST = 1 / 0.85f; +constexpr float FLY_BALL_HOME = HALF; +constexpr float FLY_BALL_MASS = 8; +constexpr float FLY_BALL_APART = 100; +constexpr float FLY_BALL_APART_PUSH = 0.003f; +constexpr float FLY_BALL_LAVA_PUSH = -10; + +// The flies it keeps orbiting by its health, the rest killed. +static void fly_ball_orbiters_trim(Entity_NPC& npc) +{ + int kept = std::max(0, (int)std::floor(npc.health * FLY_BALL_ORBITERS / npc.maxHitPoints + HALF)); + if (kept >= (int)npc.entityDeque.size()) return; + for (size_t i = (size_t)kept; i < npc.entityDeque.size(); i++) + { + if (Entity* fly = npc.entityDeque[i].get()) fly->Kill(EntityRef(&npc)); + npc.entityDeque[i] = nullptr; + } + npc.entityDeque.resize((size_t)kept); +} + +// A fly breaking free each time its health drops past another fourteenth. +static void fly_ball_fly_release(Entity_NPC& npc) +{ + int left = std::max(0, (int)std::ceil(npc.health * FLY_BALL_RELEASES / npc.maxHitPoints)); + if (left >= npc.i1) return; + npc.i1--; + Vector direction = random_direction(); + uint32_t seed = Random(); + int look = (int)(Random() % ULTRA_PESTILENCE_FLY_LOOKS); + float speed = random_unit() * FLY_BALL_FLY_SPEED_RANGE + FLY_BALL_FLY_SPEED; + float distance = random_unit() * FLY_BALL_FLY_FROM_RANGE + FLY_BALL_FLY_FROM; + Entity* fly = g_game->Spawn({.position = vector_add(npc.pos, vector_scale(direction, distance)), + .velocity = vector_scale(direction, speed), + .spawner = &npc, + .subType = look, + .type = ENTITY_BEAST, + .variant = BEAST_ULTRA_PESTILENCE_FLY, + .seed = seed}); + fly->health = FLY_BALL_FLY_HEALTH; + fly->Update(); +} + +// Its six orbiting flies, each on its own ellipse, spin and phase. +static void fly_ball_init(Entity_NPC& npc) +{ + npc.entityDeque.resize(FLY_BALL_ORBITERS); + for (size_t i = 0; i < FLY_BALL_ORBITERS; i++) + { + uint32_t seed = Random(); + int look = (int)(Random() % ULTRA_PESTILENCE_FLY_LOOKS); + auto* fly = static_cast(g_game->Spawn({.position = npc.pos, + .spawner = &npc, + .subType = look, + .type = ENTITY_BEAST, + .variant = BEAST_ULTRA_PESTILENCE_FLY, + .seed = seed})); + float reach = random_unit() * FLY_BALL_ORBIT_RANGE + (float)i * FLY_BALL_ORBIT_STEP + FLY_BALL_ORBIT_LEAST; + fly->v1 = vector_make(reach * FLY_BALL_ORBIT_WIDE, reach * FLY_BALL_ORBIT_TALL); + fly->v2.x = random_unit() * FULL_TURN_DEGREES; + uint32_t phase = Random(); + fly->flags &= ~FLAG_APPEAR; + fly->stateFrame = (int)(phase % FLY_BALL_ORBIT_PHASES); + fly->parent = &npc; + npc.entityDeque[i] = fly; + fly->Update(); + } + npc.splatColor = COLOR_GREEN_SPLAT; + npc.sprite.Play("Idle"); + npc.aiCallFlags = AI_CALL_PRE_UPDATE; + npc.entityCollisionClass = ENTCOLL_PLAYEROBJECTS; + npc.state = NPC_STATE_IDLE; + npc.v1 = vector_is_zero(npc.velocity) ? random_direction() : vector_normalized(npc.velocity); + npc.i1 = (int)FLY_BALL_RELEASES; +} + +// 0044aad0 Ultra Pestilence's fly ball (951.23): its orbiting flies thin out and break free as it is hurt; it homes +// on its target, keeps apart from other balls and off the lava that burns it. +static void pestilence_fly_ball_update(Entity_NPC& npc) +{ + if (npc.aiCallPhase == AI_PHASE_PRE_UPDATE) + { + lava_burn(npc); + fly_ball_orbiters_trim(npc); + fly_ball_fly_release(npc); + return; + } + if (npc.state == NPC_STATE_INIT) return fly_ball_init(npc); + if (npc.state != NPC_STATE_IDLE) return; + + npc.friction *= ULTRA_HORSEMAN_FRICTION; + Vector toTarget = vector_sub(npc.CalcTargetPosition(0), npc.pos); + npc.velocity = vector_scale(npc.velocity, timescale_factor(FLY_BALL_COAST, npc.speedMultiplier)); + npc_push(npc, vector_scale(vector_normalized(toTarget), FLY_BALL_HOME * npc.scale)); + npc.mass = FLY_BALL_MASS; + for (Entity* other : entity_query(ENTITY_BEAST, BEAST_ULTRA_PESTILENCE_FLY_BALL)) + { + if (other == &npc || vector_length_squared(vector_sub(other->pos, npc.pos)) >= FLY_BALL_APART * FLY_BALL_APART) continue; + Vector away = vector_sub(npc.pos, other->pos); + float distance = vector_length(away); + if (distance > 0) away = vector_scale(away, (FLY_BALL_APART - distance) / distance); + npc_push(npc, vector_scale(away, FLY_BALL_APART_PUSH)); + } + float lava = g_game->room->get_lava_line_y(); + if (lava - PESTILENCE_FLY_LAVA_ABOVE < npc.pos.y) + npc_push(npc, vector_make(0, FLY_BALL_LAVA_PUSH / std::max(PESTILENCE_FLY_LAVA_NEAREST, lava - npc.pos.y))); +} + +// Ultra Pestilence's maggot (951.22): it crosses the room six times along lanes (its pass count in +// projectileCooldown, its lane in v2.y, its push in targetPosition): out of the mouth, the top lane, the player's row, +// the player's row turning back, the player's row and the top lane, then back into Pestilence's mouth. +constexpr int MAGGOT_TURN_PASS = 3; +constexpr int MAGGOT_TOP_PASS = 4; +constexpr int MAGGOT_HOME_PASS = 6; +constexpr int MAGGOT_Z = 400; +constexpr float MAGGOT_TURN = 0.26f; +constexpr float MAGGOT_HOME_PULL = 0.1f; +constexpr float MAGGOT_LANE_PULL = HALF; +constexpr float MAGGOT_OUTSIDE = 80; +constexpr float MAGGOT_TOP_LANE = 120; +constexpr float MAGGOT_SPLASH_DEPTH = 400; + +// Back into Pestilence's mouth on its last pass: a splash there, its MaggotBack if it hovers, and a push. Returns +// whether it went in. +static bool pestilence_maggot_home(Entity_NPC& npc, Entity_NPC& parent) +{ + Vector mouth = shoot_pos_get(parent); + npc.velocity.y = (mouth.y - npc.pos.y) * MAGGOT_HOME_PULL; + bool isShort = npc.targetPosition.x <= 0 ? mouth.x < npc.pos.x : npc.pos.x < mouth.x; + if (isShort) return false; + + blood_explosion_spawn(BLOOD_EXPLOSION_BURST, mouth, {}, COLOR_GREEN_SPLAT, vector_scale(npc.velocity, -HALF))->renderDepthOffset = + MAGGOT_SPLASH_DEPTH; + if (parent.state == NPC_STATE_IDLE) parent.sprite.Play("MaggotBack", PLAY_FORCED); + npc.PlaySound(SOUND_MEAT_JUMPS, 1, 2, false, 1); + npc_sound_play(SOUND_PESTILENCE_MAGGOT_RETURN, 1, 2, 1); + npc_sound_play(SOUND_PESTILENCE_MAGGOT_ENTER, 1, 2, 1); + parent.velocity = vector_add(parent.velocity, vector_scale(npc.targetPosition, 2 * parent.speedMultiplier)); + npc.Remove(); + return true; +} + +// Past the far side: gone after its last pass, else back in from the side it came by, along its next lane. +static void pestilence_maggot_pass(Entity_NPC& npc, Room& room) +{ + if (npc.projectileCooldown > MAGGOT_HOME_PASS - 1 || !npc.parent) + { + npc.Remove(); + return; + } + float lane = npc.GetPlayerTarget()->pos.y; + if (npc.projectileCooldown == 0 || npc.projectileCooldown == MAGGOT_TOP_PASS) lane = room.topLeftPos.y + MAGGOT_TOP_LANE; + int pass = ++npc.projectileCooldown; + Entity* parent = npc.parent.get(); + if (pass == MAGGOT_HOME_PASS && parent) + { + lane = parent->pos.y; + if (parent->IsEnemy()) lane += parent->GetNullOffset("ShootPos").y; + } + bool isRight = npc.targetPosition.x >= 0; + npc.pos = vector_make(isRight ? room.topLeftPos.x - MAGGOT_OUTSIDE : room.bottomRightPos.x + MAGGOT_OUTSIDE, lane); + npc.v2.y = npc.pos.y; + if (pass == MAGGOT_TURN_PASS) npc.v2.x = -npc.targetPosition.x; +} + +// 0044b6f0 Ultra Pestilence's maggot (951.22): it crosses the room along its lanes, turning back once, and ends back +// in Pestilence's mouth. +static void pestilence_maggot_update(Entity_NPC& npc) +{ + Room& room = *g_game->room; + if (npc.state == NPC_STATE_INIT) + { + npc.sprite.Play("Maggot"); + npc.state = NPC_STATE_IDLE; + npc.renderZOffset = MAGGOT_Z; + npc.v2 = {}; + return; + } + if (npc.state != NPC_STATE_IDLE) return; + + if (npc.v2.y == 0) npc.v2.y = npc.pos.y; + npc.friction *= ULTRA_HORSEMAN_FRICTION; + npc_push(npc, npc.targetPosition); + npc.sprite.isFlipX = npc.targetPosition.x > 0; + if (npc.projectileCooldown == MAGGOT_TURN_PASS) + { + float step = npc.speedMultiplier * MAGGOT_TURN; + float& push = npc.targetPosition.x; + if (std::abs(push - npc.v2.x) > step) push = npc.v2.x <= push ? push - step : push + step; + else push = npc.v2.x; + } + + Entity_NPC* parent = npc.ParentNPC(); + if (npc.projectileCooldown == MAGGOT_HOME_PASS && parent) + { + if (pestilence_maggot_home(npc, *parent)) return; + } + else + npc.velocity.y = (npc.v2.y - npc.pos.y) * MAGGOT_LANE_PULL; + + bool isPast = npc.targetPosition.x >= 0 ? npc.pos.x > room.bottomRightPos.x + MAGGOT_OUTSIDE + : npc.pos.x < room.topLeftPos.x - MAGGOT_OUTSIDE; + if (isPast) pestilence_maggot_pass(npc, room); +} + +// Ultra War (951.30): it hovers like Famine, throws three bombs that land on the player, then dashes off-screen and +// through the lava three times dropping bombs into it. Hit below half its horse dies in a burst of fire; headless it +// chases above the player, lunges, bursts into fire and moving fires, and grabs a bomb that blows it across the +// room into the lava. Dying it sinks and explodes. +constexpr float ULTRA_WAR_HEADLESS_SHARE = HALF; +constexpr int ULTRA_WAR_FLOAT = NPC_STATE_MOVE; +constexpr int ULTRA_WAR_KNOCKBACK = NPC_STATE_SUICIDE; +constexpr int ULTRA_WAR_CHASE = NPC_STATE_JUMP; +constexpr int ULTRA_WAR_LUNGE = NPC_STATE_STOMP; +constexpr int ULTRA_WAR_THROW = NPC_STATE_ATTACK; +constexpr int ULTRA_WAR_DASH = NPC_STATE_ATTACK2; +constexpr int ULTRA_WAR_LUNGE_BOMB = NPC_STATE_ATTACK3; +constexpr int ULTRA_WAR_QUICK_BURST = NPC_STATE_SUMMON; +constexpr int ULTRA_WAR_HOVER_FRAMES = 60; +constexpr int ULTRA_WAR_THROWS = 3; +constexpr int ULTRA_WAR_LUNGES = 2; +constexpr int ULTRA_WAR_MUSIC_LAYER = 1; +constexpr ColorMod ULTRA_WAR_FIRE_COLOR = tint_color_make(5, 0.5f, 0.2f, 1); +constexpr ColorMod ULTRA_WAR_KNOCKBACK_DUST_COLOR = tint_color_make(0.4f, 0.4f, 0.4f, 0.6f); +constexpr ColorMod ULTRA_WAR_LAVA_FLASH = {{1, 1, 1, 1}, {0, 0, 0, 0}, {0.5f, 0.25f, 0}}; +constexpr int ULTRA_WAR_LAVA_FLASH_FRAMES = 15; + +// Its explosions (its own death and its bombs'): 80 damage over 1.5 times the usual reach, 10 dust clouds flung 10 to +// 15 in a ring, a ground poof and a flash of bloom. +constexpr float ULTRA_WAR_BLAST_DAMAGE = 80; +constexpr float ULTRA_WAR_BLAST_REACH = 1.5f; +constexpr int ULTRA_WAR_BLAST_DUSTS = 10; +constexpr float ULTRA_WAR_BLAST_DUST_TURN = 36; +constexpr float ULTRA_WAR_BLAST_DUST_SPREAD = 0.8f; +constexpr float ULTRA_WAR_BLAST_DUST_SPEED = 10; +constexpr float ULTRA_WAR_BLAST_DUST_SPEED_RANGE = 5; +constexpr int ULTRA_WAR_BLAST_DUST_Z = -600; +constexpr int ULTRA_WAR_BLOOM_FRAMES = 6; +constexpr int ULTRA_WAR_DEATH_SHAKE = 50; +constexpr float ULTRA_WAR_SHOCKWAVE_AMPLITUDE = HALF; +constexpr float ULTRA_WAR_SHOCKWAVE_SPEED = 0.07f; +constexpr int ULTRA_WAR_SHOCKWAVE_FRAMES = 20; + +// Its fire bursts: five fans 20 degrees apart up from it, of five clouds each 14 to 24 fast, glowing fiery. +constexpr int ULTRA_WAR_FIRE_FANS = 2; +constexpr float ULTRA_WAR_FIRE_FAN_TURN = 20; +constexpr float ULTRA_WAR_FIRE_FAN_JITTER = 12; +constexpr float ULTRA_WAR_FIRE_SPEED = -14; +constexpr float ULTRA_WAR_FIRE_SPEED_RANGE = 10; +constexpr int ULTRA_WAR_FIRE_CLOUDS = 5; +constexpr float ULTRA_WAR_FIRE_CLOUD_STEP = 0.7f * 0.25f; +constexpr float ULTRA_WAR_FIRE_CLOUD_LEAST = 0.3f; +constexpr float ULTRA_WAR_FIRE_CLOUD_JITTER = 10; +constexpr uint32_t ULTRA_WAR_FIRE_CLOUD_FRAMES = 10; +constexpr float ULTRA_WAR_FIRE_CLOUD_SCALE = 0.3f; +constexpr float ULTRA_WAR_FIRE_CLOUD_SCALE_RANGE = 1.2f; + +// The thrown bomb: launched up at 18 under its fall of 1.2 (half of it in the lob's quadratic), timed to land on the +// player 15 ticks before it blows. +constexpr float ULTRA_WAR_THROW_RISE = -18; +constexpr float ULTRA_WAR_THROW_HALF_FALL = 0.6f; +constexpr float LOB_DISCRIMINANT = 4; +constexpr float ULTRA_WAR_THROW_NEAR = 0.1f; +constexpr float ULTRA_WAR_THROW_NEAR_FLIGHT = 30; +constexpr int ULTRA_WAR_THROW_FUSE = 15; + +// The dash: off the far side (180, 30 a tick once out), three runs along the lava from 180 out reaching 1000 (3200 on +// the last) past the other side, each dropping a bomb past a point 140 apart from the last (within 160 of the sides +// the first time), then back in at mid height, braking 20 inside. +constexpr int ULTRA_WAR_DASH_LEGS = 4; +constexpr float ULTRA_WAR_DASH_TOP = 40; +constexpr float ULTRA_WAR_DASH_TOP_LAST = 30; +constexpr float ULTRA_WAR_DASH_PUSH = 10; +constexpr float ULTRA_WAR_DASH_OUT = 180; +constexpr float ULTRA_WAR_DASH_AWAY = 1000; +constexpr float ULTRA_WAR_DASH_AWAY_LAST = 3200; +constexpr float ULTRA_WAR_DASH_LAVA = 20; +constexpr float ULTRA_WAR_DASH_TOP_MARGIN = 80; +constexpr float ULTRA_WAR_DASH_BOTTOM_MARGIN = 120; +constexpr float ULTRA_WAR_DROP_REACH = 60; +constexpr float ULTRA_WAR_DROP_CARRY = 0.06f; +constexpr float ULTRA_WAR_DROP_RISE = -8; +constexpr float ULTRA_WAR_DROP_FIRST_MARGIN = 160; +constexpr float ULTRA_WAR_DROP_MARGIN = 140; +constexpr float ULTRA_WAR_DROP_STEP = 140; +constexpr float ULTRA_WAR_DROP_HALF_STEP = 70; +constexpr float ULTRA_WAR_DASH_END = 20; +constexpr float ULTRA_WAR_BRAKE_FRAMES = -29; +constexpr float ULTRA_WAR_BRAKE = 0.6f; + +// The chase: drifting 1.6 a tick toward a point 160 diagonally above the player (nearer as War closes in, held in +// the upper half after 60 ticks), or leading the player while it is low; floating 0.55 a tick at the player. +constexpr float ULTRA_WAR_CHASE_PUSH = 1.6f; +constexpr float ULTRA_WAR_CHASE_STEER = 0.8f; +constexpr float ULTRA_WAR_FLOAT_STEER = 0.1f; +constexpr float ULTRA_WAR_CHASE_DIAGONAL = 113.137085f; +constexpr float ULTRA_WAR_CHASE_NEAR = 160; +constexpr float ULTRA_WAR_CHASE_RANGE = 180; +constexpr float ULTRA_WAR_CHASE_LEAD = 0.1f; +constexpr int ULTRA_WAR_CHASE_HOLD = 60; +constexpr int ULTRA_WAR_CHASE_FRAMES = 90; +constexpr float ULTRA_WAR_LUNGE_WALL = 150; +constexpr float ULTRA_WAR_LUNGE_SPEED = 15; +constexpr float ULTRA_WAR_LUNGE_DROP = 12; +constexpr float ULTRA_WAR_LUNGE_DECAY = 0.7f; + +// The knockback: blown back at 15 bouncing off the sides, falling once near the top (0.5 a tick) into the lava 80 +// below its line, then rising from it at 18. +constexpr float ULTRA_WAR_KNOCKBACK_SPEED = 15; +constexpr float ULTRA_WAR_KNOCKBACK_RISE = -2; +constexpr float ULTRA_WAR_KNOCKBACK_FRICTION = 0.6f; +constexpr float ULTRA_WAR_KNOCKBACK_TOP = 100; +constexpr float ULTRA_WAR_KNOCKBACK_DROP = 4; +constexpr float ULTRA_WAR_KNOCKBACK_SLOW = 0.94f; +constexpr float ULTRA_WAR_KNOCKBACK_FALL = HALF; +constexpr float ULTRA_WAR_KNOCKBACK_SINK = 80; +constexpr float ULTRA_WAR_LAVA_DECAY = 0.6f; +constexpr float ULTRA_WAR_LAVA_LIFT = 0.3f; +constexpr float ULTRA_WAR_RISE = -18; +constexpr float ULTRA_WAR_RISE_DECAY = 0.8f; +constexpr int ULTRA_WAR_RISE_FRAME = 5; +enum WarKnockback +{ + WAR_KNOCKBACK_FLYING, + WAR_KNOCKBACK_FALLING, + WAR_KNOCKBACK_LAVA, + WAR_KNOCKBACK_RISING +}; + +// The quick burst: 16 moving fires out of it (at 5 with more health, and 3 turned 22.5 degrees with less), then 4 +// fire shots every other tick 16 fast from up to 64 out. +constexpr int ULTRA_WAR_FIRE_RING = 8; +constexpr float ULTRA_WAR_FIRE_RING_TURN = 45; +constexpr float ULTRA_WAR_FIRE_SPEED_OUT = 5; +constexpr float ULTRA_WAR_FIRE_INNER_TURN = 22.5f; +constexpr float ULTRA_WAR_FIRE_INNER_SPEED = 0.6f; +constexpr float ULTRA_WAR_FIRE_FROM = 4; +constexpr float ULTRA_WAR_FIRE_HEALTH = 1.2f; +constexpr float ULTRA_WAR_FIRE_INNER_HEALTH = 0.8f; +constexpr int ULTRA_WAR_FIRE_Z = -2000; +constexpr int ULTRA_WAR_BURST_SHOTS = 4; +constexpr float ULTRA_WAR_BURST_SPEED = 16; +constexpr float ULTRA_WAR_BURST_SPEED_LEAST = 0.8f; +constexpr float ULTRA_WAR_BURST_SPEED_RANGE = 0.2f; +constexpr float ULTRA_WAR_BURST_SPREAD = 90; +constexpr float ULTRA_WAR_BURST_FROM = 4; +constexpr float ULTRA_WAR_BURST_SCALE = 0.7f; +constexpr float ULTRA_WAR_BURST_SCALE_RANGE = 0.4f; +constexpr float ULTRA_WAR_BURST_FALL = -0.2f; +constexpr ColorMod ULTRA_WAR_BURST_COLOR = tint_color_make(1, 0.8f, 0.8f, 1); + +// The smoke out of its neck every 3 ticks: from layer 0's spot, within 40, rising 2 to 8, glowing fiery. +constexpr float ULTRA_WAR_SMOKE_EVERY = 3; +constexpr float ULTRA_WAR_SMOKE_SCATTER = 40; +constexpr float ULTRA_WAR_SMOKE_CARRY = 0.1f; +constexpr float ULTRA_WAR_SMOKE_RISE = -2; +constexpr float ULTRA_WAR_SMOKE_RISE_RANGE = 6; +constexpr float ULTRA_WAR_SMOKE_SCALE = 0.6f; +constexpr float ULTRA_WAR_SMOKE_SCALE_RANGE = 0.6f; + +// A bomb of War's (951.31) by subtype: thrown, dropped into the lava, and held. +enum WarBombKind +{ + WAR_BOMB_THROWN, + WAR_BOMB_LAVA, + WAR_BOMB_HELD +}; + +// The dust thrown up by War's blasts: 10 clouds in a ring, behind everything. +static void war_blast_dusts_spawn(Entity_NPC& npc) +{ + for (int i = 0; i < ULTRA_WAR_BLAST_DUSTS; i++) + { + float angle = (random_unit() * ULTRA_WAR_BLAST_DUST_SPREAD + ((float)i - ULTRA_WAR_BLAST_DUST_SPREAD * HALF)) * + ULTRA_WAR_BLAST_DUST_TURN; + uint32_t seed = Random(); + float speed = random_unit() * ULTRA_WAR_BLAST_DUST_SPEED_RANGE + ULTRA_WAR_BLAST_DUST_SPEED; + horseman_dust_spawn(npc, {.color = ULTRA_FAMINE_DUST_COLOR, + .position = npc.pos, + .velocity = vector_scale(vector_from_angle(angle), speed), + .seed = seed}) + ->renderZOffset = ULTRA_WAR_BLAST_DUST_Z; + } +} + +// A blast of War's own: its explosion's damage from its spawner, the dust and the screen's flash. +static void war_blast(Entity_NPC& npc) +{ + explosion_effects({.position = npc.pos, + .source = npc.spawnerEntity.get(), + .damage = ULTRA_WAR_BLAST_DAMAGE, + .radiusMultiplier = ULTRA_WAR_BLAST_REACH, + .isLineCheck = false}); +} + +// The flash of bloom War's blasts give. +static void war_bloom() +{ + g_game->bloomDuration = ULTRA_WAR_BLOOM_FRAMES; + g_game->bloomTimer = ULTRA_WAR_BLOOM_FRAMES; + g_game->bloomStrength = 1; +} + +// 0044ee60 A burst of fire out of War: its roar and five fans of fiery clouds up from it. +static void ultra_war_fire_burst(Entity_NPC& npc) +{ + npc_sound_play(SOUND_FLAME_BURST, 1, 2, champion_pitch_get(npc)); + for (int fan = -ULTRA_WAR_FIRE_FANS; fan <= ULTRA_WAR_FIRE_FANS; fan++) + { + float speed = ULTRA_WAR_FIRE_SPEED - random_unit() * ULTRA_WAR_FIRE_SPEED_RANGE; + float turn = (random_unit() - HALF) * ULTRA_WAR_FIRE_FAN_JITTER + (float)fan * ULTRA_WAR_FIRE_FAN_TURN; + Vector direction = vector_rotated(vector_make(0, speed), turn); + for (int cloud = 0; cloud < ULTRA_WAR_FIRE_CLOUDS; cloud++) + { + Vector velocity = vector_scale(direction, (float)cloud * ULTRA_WAR_FIRE_CLOUD_STEP + ULTRA_WAR_FIRE_CLOUD_LEAST); + velocity = vector_rotated(velocity, random_unit() * ULTRA_WAR_FIRE_CLOUD_JITTER - ULTRA_WAR_FIRE_CLOUD_JITTER * HALF); + auto* flame = static_cast(g_game->Spawn({.position = vector_add(vector_scale(velocity, 2), npc.pos), + .velocity = velocity, + .spawner = &npc, + .type = ENTITY_EFFECT, + .variant = EFFECT_DUST_CLOUD, + .seed = Random()})); + layer_additive_set(*flame->sprite.GetLayer(0)); + flame->sprite.GetLayer(0)->color = ULTRA_WAR_FIRE_COLOR; + flame->rotation = random_between(DUST_SPIN_MIN, DUST_SPIN_RANGE); + int frames = (int)(Random() % ULTRA_WAR_FIRE_CLOUD_FRAMES + ULTRA_WAR_FIRE_CLOUD_FRAMES); + flame->timeout = frames; + flame->lifespan = frames; + float scale = random_unit() * ULTRA_WAR_FIRE_CLOUD_SCALE_RANGE + ULTRA_WAR_FIRE_CLOUD_SCALE; + flame->renderZOffset = ULTRA_WAR_BLAST_DUST_Z; + flame->sprite.scale = vector_make(scale, scale); + } + } +} + +// Its death throes' end: the blast, dust, a ground poof, the screen's shake, bloom and a shockwave. +static void ultra_war_death_blast(Entity_NPC& npc) +{ + war_blast(npc); + war_blast_dusts_spawn(npc); + npc.MakeGroundPoof(npc.pos, COLOR_DEFAULT, 1); + game_shake_screen(ULTRA_WAR_DEATH_SHAKE); + war_bloom(); + shockwave_make(npc.pos, ULTRA_WAR_SHOCKWAVE_AMPLITUDE, ULTRA_WAR_SHOCKWAVE_SPEED, ULTRA_WAR_SHOCKWAVE_FRAMES); +} + +// A bomb of War's, its kind given, its appearing skipped and run once. +static Entity_NPC* war_bomb_spawn(Entity_NPC& npc, Vector position, Vector velocity, WarBombKind kind) +{ + uint32_t seed = Random(); + auto* bomb = static_cast(g_game->Spawn({.position = position, + .velocity = velocity, + .spawner = &npc, + .subType = kind, + .type = ENTITY_BEAST, + .variant = BEAST_ULTRA_WAR_BOMB, + .seed = seed})); + bomb->flags &= ~FLAG_APPEAR; + return bomb; +} + +// The throw: a bomb lobbed to land on the player as its fuse runs out. +static void ultra_war_throw(Entity_NPC& npc) +{ + npc.friction *= ULTRA_HORSEMAN_FRICTION; + if (npc.sprite.IsEventTriggered("Shoot")) + { + npc_sound_play(SOUND_WAR_BOMB_TOSS, 1, 2, 1); + npc_sound_play(SOUND_WAR_BOMB_TICK, 1, 2, 1); + Vector hand = shoot_pos_get(npc); + Entity* target = npc.GetPlayerTarget(); + float across = target->pos.x - hand.x; + float drop = target->pos.y - hand.y; + bool isLeft = across < 0; + float distance = std::abs(across); + float rise = distance * ULTRA_WAR_THROW_RISE; + float root = std::sqrt(std::max(distance * ULTRA_WAR_THROW_HALF_FALL * distance * LOB_DISCRIMINANT * drop + rise * rise, 0.0f)); + float speed = (root + rise) / (drop + drop); + float flight = distance <= ULTRA_WAR_THROW_NEAR ? ULTRA_WAR_THROW_NEAR_FLIGHT : distance / speed; + if (isLeft) speed = -speed; + npc.sprite.isFlipX = !isLeft; + Entity_NPC* bomb = war_bomb_spawn(npc, hand, vector_make(speed, ULTRA_WAR_THROW_RISE), WAR_BOMB_THROWN); + bomb->parent = &npc; + bomb->stateFrame = (int)flight + ULTRA_WAR_THROW_FUSE; + bomb->Update(); + } + if (!npc.sprite.IsFinished()) return; + npc.sprite.Play("Idle"); + npc.state = NPC_STATE_IDLE; + npc.stateFrame = 0; +} + +// The next leg of the dash: back in from the side it left by, along the lava or (the last) at mid height, with the +// spot its bomb drops past and an orange flash. +static void ultra_war_dash_leg(Entity_NPC& npc, Room& room) +{ + int leg = ++npc.stateFrame; + if (leg < ULTRA_WAR_DASH_LEGS) + { + npc.PlaySound(SOUND_WAR_DASH_START, 1, 2, false, 1); + npc.PlaySound(SOUND_WAR_LAVA_DASH, 1, 2, false, 1); + } + else + npc_sound_play(SOUND_WAR_APPEAR, 1, 2, 1); + npc.pos.x = npc.sprite.isFlipX ? room.topLeftPos.x - ULTRA_WAR_DASH_OUT : room.bottomRightPos.x + ULTRA_WAR_DASH_OUT; + if (leg >= 1 && leg < ULTRA_WAR_DASH_LEGS) npc.pos.y = room.bottomRightPos.y - ULTRA_WAR_DASH_LAVA; + else + npc.pos.y = ((room.topLeftPos.y + ULTRA_WAR_DASH_TOP_MARGIN + room.bottomRightPos.y) - ULTRA_WAR_DASH_BOTTOM_MARGIN) * HALF; + + if (leg == 1) + { + float left = room.topLeftPos.x + ULTRA_WAR_DROP_FIRST_MARGIN; + npc.v1.x = (room.bottomRightPos.x - ULTRA_WAR_DROP_FIRST_MARGIN - left) * random_unit() + left; + } + else + { + float left = room.topLeftPos.x + ULTRA_WAR_DROP_MARGIN; + float base = npc.v1.x + ULTRA_WAR_DROP_HALF_STEP; + float spot = (room.bottomRightPos.x - ULTRA_WAR_DROP_MARGIN - left) * random_unit() + left; + npc.v1.x = std::round((spot - base) / ULTRA_WAR_DROP_STEP) * ULTRA_WAR_DROP_STEP + base; + } + npc.projectileDelay = 0; + npc.SetColor(ULTRA_WAR_LAVA_FLASH, ULTRA_WAR_LAVA_FLASH_FRAMES, 1, true, true); +} + +// The dash: its legs counted in stateFrame (braking below 0), dropping a bomb on each lava leg. +static void ultra_war_dash(Entity_NPC& npc, Room& room) +{ + if (npc.stateFrame < 0) + { + float brake = std::clamp((float)(npc.stateFrame + 1) / ULTRA_WAR_BRAKE_FRAMES, 0.0f, 1.0f); + npc.stateFrame -= npc_ticks_get(npc); + npc.friction *= 1 - brake * ULTRA_WAR_BRAKE; + if (!npc.sprite.IsFinished()) return; + npc.sprite.Play("Idle"); + npc.state = NPC_STATE_IDLE; + npc.stateFrame = 0; + return; + } + + float top = npc.stateFrame < ULTRA_WAR_DASH_LEGS ? ULTRA_WAR_DASH_TOP : ULTRA_WAR_DASH_TOP_LAST; + npc.friction = ULTRA_HORSEMAN_FRICTION; + if (npc.sprite.IsFinished()) npc.sprite.Play("DashLoop"); + if (npc.sprite.IsEventTriggered("Shoot")) npc.velocity.y = 0; + if (npc.sprite.animState.IsLoopingAnimation() || npc.sprite.WasEventTriggered("Shoot")) + { + float push = npc.sprite.isFlipX ? ULTRA_WAR_DASH_PUSH : -ULTRA_WAR_DASH_PUSH; + npc.velocity.x = std::clamp(push * npc.speedMultiplier + npc.velocity.x, -top, top); + if (npc.GetIntervalTicks(ULTRA_DUST_EVERY, 0) != 0) horseman_trail_dust(npc, ULTRA_FAMINE_DUST_COLOR); + } + + bool isLavaLeg = npc.stateFrame >= 1 && npc.stateFrame < ULTRA_WAR_DASH_LEGS; + if (npc.projectileDelay == 0 && isLavaLeg && + horseman_is_past(npc, npc.v1.x + ULTRA_WAR_DROP_REACH, npc.v1.x - ULTRA_WAR_DROP_REACH)) + { + npc.projectileDelay = 1; + Entity_NPC* bomb = war_bomb_spawn(npc, npc.pos, vector_make(npc.velocity.x * ULTRA_WAR_DROP_CARRY, ULTRA_WAR_DROP_RISE), + WAR_BOMB_LAVA); + bomb->parent = &npc; + bomb->Update(); + } + + if (npc.stateFrame < ULTRA_WAR_DASH_LEGS) + { + float away = npc.stateFrame == 0 ? ULTRA_WAR_DASH_OUT : ULTRA_WAR_DASH_AWAY; + if (npc.stateFrame == ULTRA_WAR_DASH_LEGS - 1) away = ULTRA_WAR_DASH_AWAY_LAST; + if (horseman_is_past(npc, room.topLeftPos.x - away, room.bottomRightPos.x + away)) ultra_war_dash_leg(npc, room); + return; + } + if (!horseman_is_past(npc, room.bottomRightPos.x - ULTRA_WAR_DASH_END, room.topLeftPos.x + ULTRA_WAR_DASH_END)) return; + npc.sprite.Play("DashEnd"); + npc.stateFrame = -1; +} + +// Where the headless chase heads: above the player, nearer the closer War is (held in the upper half late), or +// ahead of a player in the lower half. +static Vector ultra_war_chase_aim(Entity_NPC& npc, Entity& target, Room& room) +{ + Vector player = target.pos; + float middle = (room.bottomRightPos.y + room.topLeftPos.y) * HALF; + if (player.y > middle && npc.stateFrame < ULTRA_WAR_CHASE_HOLD) + return vector_add(player, vector_scale(target.velocity, vector_distance(npc.pos, player) * ULTRA_WAR_CHASE_LEAD)); + + Vector upLeft = vector_make(player.x - ULTRA_WAR_CHASE_DIAGONAL, player.y - ULTRA_WAR_CHASE_DIAGONAL); + Vector upRight = vector_make(player.x + ULTRA_WAR_CHASE_DIAGONAL, upLeft.y); + float rightDistance = vector_length_squared(vector_sub(npc.pos, upRight)); + Vector pick = rightDistance <= vector_length_squared(vector_sub(npc.pos, upLeft)) ? upRight : upLeft; + float closeness = std::clamp((vector_distance(npc.pos, player) - ULTRA_WAR_CHASE_NEAR) / ULTRA_WAR_CHASE_RANGE, 0.0f, 1.0f); + Vector aim = vector_make((pick.x - player.x) * closeness + player.x, player.y + (pick.y - player.y) * closeness); + if (npc.stateFrame >= ULTRA_WAR_CHASE_HOLD) aim.y = std::min(aim.y, middle); + return aim; +} + +// The headless float and chase: drifting at the player or toward its chase point, then the chase, then lunges +// (two short, then one with a bomb) when not heading into a near wall. +static void ultra_war_chase(Entity_NPC& npc, Room& room) +{ + bool isChasing = npc.state == ULTRA_WAR_CHASE; + if (isChasing && npc.sprite.IsFinished()) npc.sprite.Play("ChaseLoop"); + if (npc.sprite.IsEventTriggered("Shoot")) npc.PlaySound(SOUND_WAR_CHASE, 1, 2, false, 1); + npc.friction *= ULTRA_HORSEMAN_FRICTION; + Vector& drift = npc.pathfinder.moveDirection; + float push = isChasing ? ULTRA_WAR_CHASE_PUSH : ULTRA_HOVER_PUSH; + npc.velocity = vector_add(npc.velocity, vector_scale(drift, push * npc.speedMultiplier)); + + Entity& target = *npc.GetPlayerTarget(); + Vector aim = isChasing ? ultra_war_chase_aim(npc, target, room) : target.pos; + Vector toAim = vector_sub(aim, npc.pos); + if (!vector_is_zero(toAim)) + drift = vector_add(drift, vector_scale(vector_normalized(toAim), + (isChasing ? ULTRA_WAR_CHASE_STEER : ULTRA_WAR_FLOAT_STEER) * npc.speedMultiplier)); + if (vector_length(drift) > 1) drift = vector_normalized(drift); + npc.sprite.isFlipX = drift.x > 0; + npc.stateFrame += npc_ticks_get(npc); + + if (!isChasing) + { + if (npc.stateFrame < ULTRA_WAR_HOVER_FRAMES) return; + npc.sprite.Play("ChaseStart"); + npc.state = ULTRA_WAR_CHASE; + npc.stateFrame = 0; + return; + } + if (npc.stateFrame < ULTRA_WAR_CHASE_FRAMES) return; + bool isWallAhead = drift.x > 0 ? npc.pos.x > room.bottomRightPos.x - ULTRA_WAR_LUNGE_WALL + : npc.pos.x < room.topLeftPos.x + ULTRA_WAR_LUNGE_WALL; + if (isWallAhead) return; + if (npc.i1 < ULTRA_WAR_LUNGES) + { + npc.sprite.Play("LungeShort"); + horseman_face_target(npc); + npc.i1++; + npc.state = ULTRA_WAR_LUNGE; + npc.stateFrame = 0; + return; + } + npc.sprite.Play("LungeBomb"); + npc.sprite.isFlipX = npc.pos.x < (room.bottomRightPos.x + room.topLeftPos.x) * HALF; + npc.state = ULTRA_WAR_LUNGE_BOMB; + npc.stateFrame = 0; + npc.i1 = 0; +} + +// The lunges: a grab at the player into a quick burst, or a bomb held that blows War back across the room. +static void ultra_war_lunge(Entity_NPC& npc) +{ + npc.friction *= ULTRA_HORSEMAN_FRICTION; + if (npc.sprite.IsEventTriggered("Shoot")) + { + npc.PlaySound(npc.state == ULTRA_WAR_LUNGE_BOMB ? SOUND_WAR_BOMB_HOLD : SOUND_WAR_GRAB_PLAYER, 1, 2, false, 1); + npc.v1 = vector_make(npc.sprite.isFlipX ? ULTRA_WAR_LUNGE_SPEED : -ULTRA_WAR_LUNGE_SPEED, ULTRA_WAR_LUNGE_DROP); + } + if (npc.sprite.WasEventTriggered("Shoot")) + { + npc.velocity = vector_add(npc.velocity, vector_scale(npc.v1, npc.speedMultiplier)); + npc.v1 = vector_scale(npc.v1, timescale_factor(ULTRA_WAR_LUNGE_DECAY, npc.speedMultiplier)); + } + if (!npc.sprite.IsFinished()) return; + + if (npc.state != ULTRA_WAR_LUNGE_BOMB) + { + npc.sprite.Play("QuickBurst"); + npc.state = ULTRA_WAR_QUICK_BURST; + npc.stateFrame = 0; + return; + } + uint32_t seed = Random(); + Vector spot = vector_add(npc.pos, random_direction()); + auto* bomb = static_cast(g_game->Spawn({.position = spot, + .spawner = &npc, + .subType = WAR_BOMB_HELD, + .type = ENTITY_BEAST, + .variant = BEAST_ULTRA_WAR_BOMB, + .seed = seed})); + bomb->flags &= ~FLAG_APPEAR; + bomb->Update(); + bomb->isVisible = false; + bomb->stateFrame = 0; + bomb->Update(); + npc.state = ULTRA_WAR_KNOCKBACK; + npc.sprite.Play("Knockback"); + npc.v1 = vector_make(npc.sprite.isFlipX ? -ULTRA_WAR_KNOCKBACK_SPEED : ULTRA_WAR_KNOCKBACK_SPEED, ULTRA_WAR_KNOCKBACK_RISE); + npc.stateFrame = 0; +} + +// Blown back: bouncing off the sides, falling into the lava, an eruption under it, and rising back out. +static void ultra_war_knockback(Entity_NPC& npc, Room& room) +{ + npc.friction *= ULTRA_WAR_KNOCKBACK_FRICTION; + if (npc.stateFrame == WAR_KNOCKBACK_LAVA) + { + npc.v1 = vector_scale(npc.v1, timescale_factor(ULTRA_WAR_LAVA_DECAY, npc.speedMultiplier)); + npc.v1.y += npc.speedMultiplier * ULTRA_WAR_LAVA_LIFT; + auto* eruption = static_cast(npc.child.get()); + if (eruption && eruption->stateFrame >= 1) return; + npc.child = nullptr; + npc.stateFrame = WAR_KNOCKBACK_RISING; + npc.v1 = vector_make(0, ULTRA_WAR_RISE); + npc.pos.y = room.get_lava_line_y(); + npc.sprite.Play("QuickBurst"); + npc_sound_play(SOUND_WAR_APPEAR_LAVA, 1, 2, 1); + npc.sprite.SetFrame((float)ULTRA_WAR_RISE_FRAME); + return; + } + if (npc.stateFrame == WAR_KNOCKBACK_RISING) + { + npc.AddVelocity_divided(npc.v1, false); + npc.v1 = vector_scale(npc.v1, timescale_factor(ULTRA_WAR_RISE_DECAY, npc.speedMultiplier)); + if (!npc.sprite.IsFinished()) return; + npc.sprite.Play("Float"); + npc.i1 = 0; + npc.stateFrame = 0; + npc.state = ULTRA_WAR_FLOAT; + return; + } + + npc.AddVelocity_divided(npc.v1, false); + npc.sprite.isFlipX = npc.v1.x < 0; + bool isWall = (npc.v1.x > 0 && room.bottomRightPos.x < npc.size + npc.pos.x) || + (npc.v1.x < 0 && npc.pos.x - npc.size < room.topLeftPos.x); + if (isWall) + { + npc.PlaySound(SOUND_MEAT_IMPACTS, 1, 2, false, 1); + npc.v1.x = -npc.v1.x; + if (npc.pos.y < room.topLeftPos.y + ULTRA_WAR_KNOCKBACK_TOP) + { + npc.stateFrame = WAR_KNOCKBACK_FALLING; + npc.v1.y -= ULTRA_WAR_KNOCKBACK_DROP; + } + } + if (npc.GetIntervalTicks(ULTRA_DUST_EVERY, 0) != 0) horseman_trail_dust(npc, ULTRA_WAR_KNOCKBACK_DUST_COLOR); + if (npc.stateFrame != WAR_KNOCKBACK_FALLING) return; + + npc.v1.x *= timescale_factor(ULTRA_WAR_KNOCKBACK_SLOW, npc.speedMultiplier); + npc.v1.y += npc.speedMultiplier * ULTRA_WAR_KNOCKBACK_FALL; + if (npc.pos.y <= room.get_lava_line_y() + ULTRA_WAR_KNOCKBACK_SINK) return; + npc.PlaySound(SOUND_MEATHEADSHOOT, 1, 2, false, 1); + npc.PlaySound(SOUND_WAR_LAVA_SPLASH, 1, 2, false, 1); + npc.stateFrame = WAR_KNOCKBACK_LAVA; + Entity_NPC* eruption = war_bomb_spawn(npc, npc.pos, {}, WAR_BOMB_LAVA); + eruption->Update(); + eruption->isVisible = false; + eruption->Update(); + npc.child = eruption; +} + +// A moving fire out of War, 4 ticks of its flight out, with a share of its health, free of the grid. +static void war_fire_spawn(Entity_NPC& npc, Vector velocity, float healthShare) +{ + uint32_t seed = Random(); + Entity* fire = g_game->Spawn({.position = vector_add(vector_scale(velocity, ULTRA_WAR_FIRE_FROM), npc.pos), + .velocity = velocity, + .spawner = &npc, + .type = ENTITY_FIREPLACE, + .variant = FIRE_MOVEABLE, + .seed = seed}); + fire->renderZOffset = ULTRA_WAR_FIRE_Z; + fire->health = fire->maxHitPoints * healthShare; + fire->Update(); + fire->entityGridCollisionClass = GRIDCOLL_NONE; +} + +// The quick burst: fire out of it, moving fires all round, and fire shots every other tick until it ends. +static void ultra_war_quick_burst(Entity_NPC& npc) +{ + npc.friction *= ULTRA_WAR_LUNGE_DECAY; + if (npc.sprite.IsEventTriggered("Shoot")) + { + npc_sound_play(SOUND_WAR_FIRE_SCREEM, 1, 2, 1); + npc_sound_play(SOUND_WAR_FLAME, 1, 2, 1); + ultra_war_fire_burst(npc); + npc.stateFrame = 1; + for (int i = 0; i < ULTRA_WAR_FIRE_RING; i++) + { + Vector out = vector_scale(vector_from_angle((float)i * ULTRA_WAR_FIRE_RING_TURN), ULTRA_WAR_FIRE_SPEED_OUT); + Vector inner = vector_scale(vector_rotated(out, ULTRA_WAR_FIRE_INNER_TURN), ULTRA_WAR_FIRE_INNER_SPEED); + war_fire_spawn(npc, out, ULTRA_WAR_FIRE_HEALTH); + war_fire_spawn(npc, inner, ULTRA_WAR_FIRE_INNER_HEALTH); + } + } + + for (int tick = npc.stateFrame > 0 ? npc_ticks_get(npc) : 0; tick > 0; tick--) + { + if ((npc.stateFrame & 1) == 0) + for (int shot = 0; shot < ULTRA_WAR_BURST_SHOTS; shot++) + { + Vector base = vector_scale(vector_from_angle((float)shot * RIGHT_ANGLE_DEGREES), ULTRA_WAR_BURST_SPEED); + ProjectileParams params; + params.variant = PROJECTILE_FIRE; + params.scale = random_unit() * ULTRA_WAR_BURST_SCALE_RANGE + ULTRA_WAR_BURST_SCALE; + params.fallingAccelModifier = ULTRA_WAR_BURST_FALL; + params.color = ULTRA_WAR_BURST_COLOR; + Vector velocity = vector_scale(base, random_unit() * ULTRA_WAR_BURST_SPEED_RANGE + ULTRA_WAR_BURST_SPEED_LEAST); + float turn = random_unit() * ULTRA_WAR_BURST_SPREAD - ULTRA_WAR_BURST_SPREAD * HALF; + Vector from = vector_add(vector_scale(vector_rotated(base, turn), ULTRA_WAR_BURST_FROM), npc.pos); + npc.FireProjectiles(from, velocity, PROJECTILES_SINGLE, params); + } + npc.stateFrame++; + } + if (!npc.sprite.IsFinished()) return; + npc.sprite.Play("ChaseStart"); + npc.state = ULTRA_WAR_CHASE; + npc.stateFrame = 0; +} + +// Its horse dies: a burst of fire and gibs, then it floats headless. +static void ultra_war_transition(Entity_NPC& npc) +{ + npc.friction *= ULTRA_WAR_KNOCKBACK_FRICTION; + if (npc.sprite.IsEventTriggered("Shoot")) + { + npc_sound_play(SOUND_WAR_HORSE_DEATH, 1, 2, 1); + gibs_spawn({.color = npc.splatColor, + .position = npc.pos, + .spawner = &npc, + .spread = ULTRA_HORSEMAN_GIB_SPREAD, + .amount = ULTRA_HORSEMAN_GIBS, + .gibFlags = npc.config->gibFlags}); + npc.PlaySound(SOUND_ROCKET_BLAST_DEATH, 1, 2, false, 1); + game_shake_screen(ULTRA_HORSEMAN_SHAKE); + ultra_war_fire_burst(npc); + } + if (!npc.sprite.IsFinished()) return; + npc.entityCollisionClass = ENTCOLL_ALL; + npc.state = ULTRA_WAR_FLOAT; + npc.sprite.Play("Float"); + npc.stateFrame = 0; + npc.i1 = 0; +} + +// The smoke out of its neck every 3 ticks, from where its body layer shows. +static void ultra_war_neck_smoke(Entity_NPC& npc) +{ + const AnimationFrame* frame = npc.sprite.animState.GetLayerFrame(0); + if (!frame) return; + Vector spot = frame->pos; + Vector scale = frame->scale; + if (npc.sprite.isFlipX) + { + spot.x = -spot.x; + scale.x = -scale.x; + } + Vector scatter = random_direction(); + float reach = random_unit() * ULTRA_WAR_SMOKE_SCATTER; + Vector at = vector_make((spot.x / ROOM_SCREEN_SCALE) * scale.x + npc.pos.x + npc.posOffset.x + reach * scatter.x * scale.x, + (spot.y / ROOM_SCREEN_SCALE) * scale.y + npc.posOffset.y + npc.pos.y + reach * scatter.y * scale.y); + uint32_t seed = Random(); + float rise = ULTRA_WAR_SMOKE_RISE - random_unit() * ULTRA_WAR_SMOKE_RISE_RANGE; + Vector velocity = vector_make(npc.velocity.x * ULTRA_WAR_SMOKE_CARRY, rise + npc.velocity.y * ULTRA_WAR_SMOKE_CARRY); + auto* smoke = static_cast(g_game->Spawn({.position = at, + .velocity = velocity, + .spawner = &npc, + .type = ENTITY_EFFECT, + .variant = EFFECT_DUST_CLOUD, + .seed = seed})); + layer_additive_set(*smoke->sprite.GetLayer(0)); + smoke->sprite.GetLayer(0)->color = ULTRA_WAR_FIRE_COLOR; + smoke->rotation = random_between(DUST_SPIN_MIN, DUST_SPIN_RANGE); + int frames = (int)(Random() % ULTRA_WAR_FIRE_CLOUD_FRAMES + ULTRA_WAR_FIRE_CLOUD_FRAMES); + smoke->timeout = frames; + smoke->lifespan = frames; + float size = random_unit() * ULTRA_WAR_SMOKE_SCALE_RANGE + ULTRA_WAR_SMOKE_SCALE; + smoke->renderZOffset = ULTRA_WAR_FIRE_Z; + smoke->sprite.scale = vector_make(size, size); +} + +// 0044c070 Ultra War (951.30): throws bombs and dashes through the lava with the horse; hit below half it goes +// headless, chasing, lunging, bursting into fire and blown into the lava by its own bomb; dying it explodes. +// The neck smoke skips a frame with no body layer showing, where the original reads a null frame. +static void ultra_war_update(Entity_NPC& npc) +{ + Room& room = *g_game->room; + if (npc.aiCallPhase == AI_PHASE_PRE_UPDATE) + { + if (npc.state != NPC_STATE_DEATH) return; + horseman_sink(npc); + if (npc.sprite.IsEventTriggered("Explosion")) ultra_war_death_blast(npc); + return; + } + + bool isHeadless = npc.state == ULTRA_HORSEMAN_HEADLESS || npc.state == ULTRA_WAR_FLOAT || npc.state == ULTRA_WAR_CHASE || + npc.state == ULTRA_WAR_LUNGE || npc.state == ULTRA_WAR_QUICK_BURST || + npc.state == ULTRA_WAR_LUNGE_BOMB || npc.state == ULTRA_WAR_KNOCKBACK; + bool isBeheaded = !isHeadless && npc.health < npc.maxHitPoints * ULTRA_WAR_HEADLESS_SHARE && npc.pendingDamage > 0 && + room.IsPositionInRoom(npc.pos, 0); + if (isBeheaded) + { + npc.state = ULTRA_HORSEMAN_HEADLESS; + npc.sprite.Play("Transition"); + npc.entityCollisionClass = ENTCOLL_NONE; + horseman_spawns_kill(npc, HORSEMAN_CLEAR_SHOTS, -1); + } + else if (npc.isDead) + npc_sound_play(SOUND_WAR_DEATH, 1, 2, 1); + + switch (npc.state) + { + case NPC_STATE_INIT: + horseman_init(npc); + npc.aiCallFlags = AI_CALL_PRE_UPDATE; + npc.i1 = 0; + horseman_music_layer_set(ULTRA_WAR_MUSIC_LAYER); + break; + case NPC_STATE_IDLE: + if (horseman_hover(npc) < ULTRA_WAR_HOVER_FRAMES) break; + if (npc.i1 < ULTRA_WAR_THROWS) + { + npc.sprite.Play("ThrowBomb"); + npc_sound_play(SOUND_WAR_BOMB_PULL_OUT, 1, 2, 1); + npc.state = ULTRA_WAR_THROW; + horseman_face_target(npc); + npc.i1++; + } + else + { + npc.sprite.Play("DashStart"); + npc_sound_play(SOUND_WAR_DASH_START, 1, 2, 1); + npc.state = ULTRA_WAR_DASH; + horseman_face_target(npc); + npc.i1 = 0; + } + npc.stateFrame = 0; + break; + case ULTRA_WAR_FLOAT: + case ULTRA_WAR_CHASE: + ultra_war_chase(npc, room); + break; + case ULTRA_WAR_KNOCKBACK: + ultra_war_knockback(npc, room); + break; + case ULTRA_WAR_LUNGE: + case ULTRA_WAR_LUNGE_BOMB: + ultra_war_lunge(npc); + break; + case ULTRA_WAR_THROW: + ultra_war_throw(npc); + break; + case ULTRA_WAR_DASH: + ultra_war_dash(npc, room); + break; + case ULTRA_WAR_QUICK_BURST: + ultra_war_quick_burst(npc); + break; + case ULTRA_HORSEMAN_HEADLESS: + ultra_war_transition(npc); + break; + case ULTRA_HORSEMAN_ARRIVING: + npc.state = ULTRA_WAR_DASH; + npc.isVisible = true; + npc.entityCollisionClass = ENTCOLL_ALL; + npc.sprite.Play("DashLoop"); + npc_sound_play(SOUND_WAR_APPEAR, 1, 2, 1); + npc.stateFrame = ULTRA_WAR_DASH_LEGS; + npc.i1 = 0; + break; + } + + bool isSmoking = isHeadless && (npc.state != ULTRA_HORSEMAN_HEADLESS || npc.sprite.WasEventTriggered("Shoot")); + if (isSmoking && npc.GetIntervalTicks(ULTRA_WAR_SMOKE_EVERY, 0) != 0) ultra_war_neck_smoke(npc); +} + +// Ultra War's bomb (951.31): falling under its own weight, it blows when its fuse runs out. A thrown one sprays 48 +// shots and, like the held one, sends a cross of blasts out to the room's edges; a lava one lights a glow along the +// lava first and erupts in lava shots on either side. Under Safety Scissors it fizzles into a giga bomb pickup. +constexpr int WAR_BOMB_SINKING = NPC_STATE_IDLE; +constexpr int WAR_BOMB_FUSE = NPC_STATE_SUICIDE; +constexpr uint64_t WAR_BOMB_FLAGS = FLAG_NO_STATUS_EFFECTS | FLAG_NO_TARGET | FLAG_NO_KNOCKBACK | FLAG_NO_PHYSICS_KNOCKBACK; +constexpr int WAR_BOMB_Z = -500; +constexpr float WAR_BOMB_FALL = 1.2f; +constexpr float WAR_BOMB_LAVA_DRAG = HALF; +constexpr int WAR_BOMB_LAVA_FUSE = 15; +constexpr float WAR_BOMB_FUSE_FADE = 15; +constexpr int WAR_BOMB_FUSE_BRAKE = 20; +constexpr float WAR_BOMB_FUSE_BRAKE_LEAST = HALF; +constexpr float WAR_BOMB_FUSE_BRAKE_RANGE = 0.39999998f; +constexpr int WAR_BOMB_SHAKE = 10; +constexpr int WAR_BOMB_PICKUP_FRAMES_LEFT = 8; + +// The glow along the lava: a spawner under the bomb, and four pairs 140 apart either side fading 20% each. +constexpr int WAR_GLOW_PAIRS = 4; +constexpr float WAR_GLOW_STEP = 140; +constexpr float WAR_GLOW_FADE = 0.2f; +constexpr int WAR_GLOW_LINGER = 3; + +// The thrown bomb's spray: 12 rays of 4 shots, 10 to 7 fast and 1 to 2.2 big, flying straight. +constexpr int WAR_BOMB_RAYS = 12; +constexpr int WAR_BOMB_RAY_SHOTS = 4; +constexpr float WAR_BOMB_SHOT_SPEED = 10; +constexpr float WAR_BOMB_SHOT_GROWTH = 0.4f; +constexpr ColorMod WAR_BOMB_SHOT_COLOR = {{2, 2, 2, 1}, {0, 0, 0, 0}, {0.4f, 0.12f, -0.3f}}; + +// The cross of blasts: rings 80 farther every other tick, 30 damage over 45, until all four arms leave the room; +// the lava eruptions: every 4 ticks a pair 140 farther apart, rising at 20, until 16 ticks have passed. +static const std::array WAR_BLAST_ARMS = {vector_make(-1, 0), vector_make(0, -1), vector_make(1, 0), + vector_make(0, 1)}; +constexpr float WAR_BLAST_STEP = 80; +constexpr float WAR_BLAST_DAMAGE = 30; +constexpr float WAR_BLAST_RADIUS = 45; +constexpr int WAR_ERUPTION_EVERY = 4; +constexpr float WAR_ERUPTION_STEP = 140; +constexpr float WAR_ERUPTION_RISE = -20; +constexpr float WAR_ERUPTION_FALL = HALF; +constexpr int WAR_ERUPTION_LAST = -16; +constexpr int BOMB_EXPLOSION_SHOWN = 1; + +// A lava glow spawner along the bomb's line, see-through to start. +static Entity_Effect* war_glow_spawn(Entity_NPC& bomb, float x, Entity* parent) +{ + auto* glow = static_cast(g_game->Spawn({.position = vector_make(x, g_game->room->get_lava_line_y()), + .spawner = &bomb, + .type = ENTITY_EFFECT, + .variant = EFFECT_LAVA_SPAWNER, + .seed = Random()})); + glow->sprite.color._tint[3] = 0; + glow->maxRadius = 0; + glow->parent = parent; + return glow; +} + +// A lava bomb reaching the lava: a 15 tick fuse and its glow spreading along the lava. +static void war_bomb_sink(Entity_NPC& npc) +{ + if (npc.pos.y <= g_game->room->get_lava_line_y()) return; + npc.stateFrame = WAR_BOMB_LAVA_FUSE; + npc.state = WAR_BOMB_FUSE; + Entity_Effect* center = war_glow_spawn(npc, npc.pos.x, &npc); + npc.child = center; + center->minRadius = 1; + center->Update(); + for (int pair = 1; pair <= WAR_GLOW_PAIRS; pair++) + { + float reach = (float)pair * WAR_GLOW_STEP; + float fade = 1 - (float)pair * WAR_GLOW_FADE; + for (float x : {reach + npc.pos.x, npc.pos.x - reach}) + { + Entity_Effect* glow = war_glow_spawn(npc, x, center); + glow->state = WAR_GLOW_LINGER; + glow->minRadius = fade; + glow->Update(); + } + } +} + +// The fuse burning: the bomb pulsing toward its end, its glow brightening, and it slowing near the end. +static void war_bomb_fuse(Entity_NPC& npc) +{ + if (Entity* glow = npc.child.get()) + glow->sprite.color._tint[3] = 1 - std::clamp((float)npc.stateFrame / WAR_BOMB_FUSE_FADE, 0.0f, 1.0f); + npc.stateFrame = std::max(npc.stateFrame - npc_ticks_get(npc), 0); + if (const AnimationData* pulse = npc.sprite.animState.animData) + npc.sprite.animState.SetFrameFloat((float)std::max(pulse->length - npc.stateFrame, 0)); + if (npc.stateFrame >= WAR_BOMB_FUSE_BRAKE) return; + float left = std::clamp((float)npc.stateFrame / WAR_BOMB_FUSE_BRAKE, 0.0f, 1.0f); + npc.friction *= left * WAR_BOMB_FUSE_BRAKE_RANGE + WAR_BOMB_FUSE_BRAKE_LEAST; +} + +// The bomb blows: a giga bomb's fizzle under Safety Scissors, else War's blast, a thrown bomb's spray of shots and +// the bomb gone from sight while its aftermath plays. +static void war_bomb_explode(Entity_NPC& npc) +{ + if (Entity* glow = npc.child.get()) glow->isDead = true; + if (g_game->playerManager.AnyoneHasTrinket(TRINKET_SAFETY_SCISSORS)) + { + npc.Remove(); + npc_sound_play(SOUND_SAFETY_SCISSORS, 1, 2, 1); + Entity* giga = g_game->Spawn({.position = npc.pos, + .velocity = npc.velocity, + .subType = BOMB_SUBTYPE_GIGA, + .type = ENTITY_PICKUP, + .variant = PICKUP_BOMB, + .seed = Random()}); + if (const AnimationData* appear = giga->sprite.animState.animData) + giga->sprite.animState.SetFrameFloat((float)(appear->length - WAR_BOMB_PICKUP_FRAMES_LEFT)); + g_game->Spawn({.position = npc.pos, .subType = 1, .type = ENTITY_EFFECT, .variant = EFFECT_POOF01, .seed = Random()}); + return; + } + + war_blast(npc); + game_shake_screen(WAR_BOMB_SHAKE); + war_blast_dusts_spawn(npc); + if (npc.subtype == WAR_BOMB_THROWN) + { + ProjectileParams params; + params.color = WAR_BOMB_SHOT_COLOR; + params.bulletFlags = PROJECTILE_NO_WALL_COLLIDE; + for (int ray = 0; ray < WAR_BOMB_RAYS; ray++) + { + Vector direction = vector_from_angle((float)ray * FULL_TURN_DEGREES / WAR_BOMB_RAYS); + for (int shot = 0; shot < WAR_BOMB_RAY_SHOTS; shot++) + { + params.scale = (float)shot * WAR_BOMB_SHOT_GROWTH + 1; + Vector velocity = vector_scale(direction, WAR_BOMB_SHOT_SPEED - (float)shot); + shot_level_set(npc.fire_projectiles(npc.pos, velocity, PROJECTILES_SINGLE, params)); + } + } + } + npc.MakeGroundPoof(npc.pos, COLOR_DEFAULT, 1); + war_bloom(); + npc.stateFrame = -1; + npc.v1.x = 0; + npc.isVisible = false; + npc.entityCollisionClass = ENTCOLL_NONE; + npc.velocity = {}; +} + +// A bomb explosion's sprite shown at a spot. +static void bomb_explosion_show(Vector spot) +{ + auto* blast = static_cast( + g_game->Spawn({.position = spot, .type = ENTITY_EFFECT, .variant = EFFECT_BOMB_EXPLOSION, .seed = Random()})); + blast->state = BOMB_EXPLOSION_SHOWN; +} + +// The cross of blasts going out every other tick; gone once no arm is in the room. +static void war_bomb_cross(Entity_NPC& npc) +{ + if ((-npc.stateFrame & 1) != 0) return; + Room& room = *g_game->room; + bool isAnyInside = false; + npc.v1.x += WAR_BLAST_STEP; + for (Vector arm : WAR_BLAST_ARMS) + { + Vector spot = vector_add(vector_scale(arm, npc.v1.x), npc.pos); + if (!room.IsPositionInRoom(spot, 0)) continue; + isAnyInside = true; + bomb_explosion_show(spot); + explosion_damage({.position = spot, + .source = npc.spawnerEntity.get(), + .damage = WAR_BLAST_DAMAGE, + .radius = WAR_BLAST_RADIUS, + .isLineCheck = false}); + } + if (!isAnyInside) npc.Remove(); +} + +// The lava eruptions every 4 ticks, a pair farther apart each time (one at the start). Returns whether it is gone. +static bool war_bomb_eruptions(Entity_NPC& npc) +{ + if (-npc.stateFrame % WAR_ERUPTION_EVERY == 0) + { + Room& room = *g_game->room; + for (float offset : {-npc.v1.x, npc.v1.x}) + { + Vector spot = vector_make(offset + npc.pos.x, room.get_lava_line_y()); + if (room.IsPositionInRoom(spot, 0)) + { + ProjectileParams params; + params.variant = PROJECTILE_LAVA; + params.bulletFlags = PROJECTILE_NO_WALL_COLLIDE; + params.fallingAccelModifier = WAR_ERUPTION_FALL; + npc.FireProjectiles(spot, vector_make(0, WAR_ERUPTION_RISE), PROJECTILES_SINGLE, params); + bomb_explosion_show(spot); + } + if (npc.v1.x == 0) break; + } + npc.v1.x += WAR_ERUPTION_STEP; + } + npc.stateFrame--; + if (npc.stateFrame >= WAR_ERUPTION_LAST) return false; + npc.Remove(); + return true; +} + +// 0044f2b0 Ultra War's bomb (951.31): it falls, its fuse burns and it blows, then its cross of blasts or its lava +// eruptions play out. +static void ultra_war_bomb_update(Entity_NPC& npc) +{ + Room& room = *g_game->room; + if (npc.aiCallPhase == AI_PHASE_PRE_UPDATE) + { + if (!npc.isVisible) return; + npc.velocity.y += npc.speedMultiplier * WAR_BOMB_FALL; + if (npc.pos.y <= room.get_lava_line_y()) return; + npc.friction *= WAR_BOMB_LAVA_DRAG; + if (npc.subtype == WAR_BOMB_LAVA) npc.velocity.x = 0; + return; + } + if (npc.aiCallPhase == AI_PHASE_COLLISION) + { + int collider = npc.collisionEntity->type; + if (npc.subtype == WAR_BOMB_LAVA && (collider == ENTITY_PLAYER || collider == ENTITY_FAMILIAR)) npc.collisionResult = 0; + return; + } + + if (npc.state == NPC_STATE_INIT) + { + npc.flags |= WAR_BOMB_FLAGS; + npc.isInvincible = true; + npc.sprite.Play("Idle"); + npc.aiCallFlags = AI_CALL_PRE_UPDATE | AI_CALL_COLLISION; + npc.renderZOffset = WAR_BOMB_Z; + npc.state = npc.subtype == WAR_BOMB_LAVA ? WAR_BOMB_SINKING : WAR_BOMB_FUSE; + return; + } + if (npc.state == WAR_BOMB_SINKING) return war_bomb_sink(npc); + if (npc.state != WAR_BOMB_FUSE) return; + + if (npc.sprite.animState.IsLoopingAnimation()) npc.sprite.SetFrame("Pulse", 0); + if (npc.stateFrame > 0) return war_bomb_fuse(npc); + if (npc.stateFrame == 0) return war_bomb_explode(npc); + for (int tick = npc_ticks_get(npc); tick > 0; tick--) + { + if (npc.subtype == WAR_BOMB_LAVA) + { + if (war_bomb_eruptions(npc)) return; + continue; + } + if (npc.subtype != WAR_BOMB_THROWN && npc.subtype != WAR_BOMB_HELD) return; + war_bomb_cross(npc); + npc.stateFrame--; + } +} + +// Ultra Death (951.40): it hovers off the player's corners, summons three fans of scythes from the room's edges, then +// runs off the side and back as waves of skulls fly in, and in the dark swings its scythe four times from either +// side, its orbiting scythes cutting the skulls down. It has no headless form, and dying it throws its scythe. +constexpr int ULTRA_DEATH_GLIDE = NPC_STATE_STOMP; +constexpr int ULTRA_DEATH_SUMMON = NPC_STATE_ATTACK; +constexpr int ULTRA_DEATH_SKULL_RUN = NPC_STATE_ATTACK2; +constexpr int ULTRA_DEATH_SWING_PREPARE = NPC_STATE_ATTACK3; +constexpr int ULTRA_DEATH_SWINGS = NPC_STATE_SPECIAL; +constexpr int ULTRA_DEATH_SUMMONS = 2; +constexpr int ULTRA_DEATH_HOVER_FRAMES = 60; +constexpr int ULTRA_DEATH_MUSIC_LAYER = 2; +constexpr uint32_t ULTRA_DEATH_PHASES = AI_CALL_PRE_UPDATE | AI_CALL_INTERPOLATE | AI_CALL_POST_UPDATE; +constexpr int ULTRA_DEATH_GLOW_LAYER = 4; +constexpr int ULTRA_DEATH_BODY_LAYERS = 3; +constexpr ColorMod ULTRA_DEATH_TRAIL_COLOR = tint_color_make(1, 0.1f, 0.1f, 1); +constexpr float ULTRA_DEATH_TRAIL_WIDTH = 0.11f; +constexpr float ULTRA_DEATH_TRAIL_SCALE = 2; +static const Vector ULTRA_DEATH_SCYTHE_DROP = vector_make(0, -60); +constexpr float ULTRA_DEATH_SCYTHE_THROW_X = 8; +constexpr float ULTRA_DEATH_SCYTHE_THROW_Y = -13; + +// Its hover: faster and more nimble the more it lines up with the player within 160, its goal the nearest of the +// player's four corners 180 across and 120 up or down (within 60 of the room's edges), and kept harder off the sides. +constexpr float ULTRA_DEATH_LINE_UP = 160; +constexpr float ULTRA_DEATH_LINE_UP_PUSH = 0.8f; +constexpr float ULTRA_DEATH_RETARGET_HASTE = 0.6f; +static const std::array ULTRA_DEATH_CORNERS = {vector_make(-1.5f, -1), vector_make(1.5f, -1), + vector_make(-1.5f, 1), vector_make(1.5f, 1)}; +constexpr float ULTRA_DEATH_CORNER_REACH = 120; +constexpr float ULTRA_DEATH_CORNER_MARGIN = 60; +constexpr float ULTRA_DEATH_FAR = 1e6f; +constexpr float ULTRA_DEATH_STEER_LINED = 0.002f; +constexpr float ULTRA_DEATH_KEEP_IN = 0.01f; +constexpr float ULTRA_DEATH_FACE_MARGIN = 10; + +// Its glide in: from its push of 0.1 down 0.07 a tick to 0.2, until 200 inside the far side. +constexpr float ULTRA_DEATH_PUSH_START = 0.1f; +constexpr float ULTRA_DEATH_PUSH_DECAY = 0.07f; +constexpr float ULTRA_DEATH_PUSH_LEAST = 0.2f; +constexpr float ULTRA_DEATH_GLIDE_EDGE = 200; + +// Its summon: 11 scythes a tick apart where rays 20 degrees apart round its aim at the player leave the room (50 +// inside), each launching back at 1 to 1.2 once the 16 ticks from the first have passed, fading in from white. +constexpr float ULTRA_DEATH_AIM_REACH = 500; +constexpr int ULTRA_DEATH_RAY_MIDDLE = 6; +constexpr float ULTRA_DEATH_RAY_TURN = 20; +constexpr float ULTRA_DEATH_RAY_MARGIN = -50; +constexpr float ULTRA_DEATH_LAUNCH_RANGE = 0.2f; +constexpr int ULTRA_DEATH_SCYTHE_FADE = 8; +constexpr int ULTRA_DEATH_SCYTHE_WAIT = 16; +constexpr int ULTRA_DEATH_SCYTHES = 10; +constexpr ColorMod ULTRA_DEATH_WHITE_FADE = {{1, 1, 1, 0}, {0, 0, 0, 0}, {1, 1, 1}}; + +// Its skull run: out at a push growing 0.1 a tick to 4, past 200 out it turns back at mid height slowing to 0.2; +// waves of four skulls every 45 ticks from 100 out (the odd ones 80 farther and behind), flying back at 40; the +// swing prepared after 380. +constexpr float ULTRA_DEATH_RUN_PUSH_GROWTH = 0.1f; +constexpr float ULTRA_DEATH_RUN_PUSH_TOP = 4; +constexpr float ULTRA_DEATH_RUN_EDGE = 100; +constexpr float ULTRA_DEATH_RUN_OUT = 200; +constexpr float ULTRA_DEATH_LOOP_RAMP = 0.05f; +constexpr int ULTRA_DEATH_WAVE_EVERY = 45; +constexpr int ULTRA_DEATH_WAVE_SKULLS = 4; +constexpr float ULTRA_DEATH_WAVE_OUT = 100; +constexpr float ULTRA_DEATH_WAVE_STAGGER = 80; +constexpr float ULTRA_DEATH_WAVE_TOP = 120; +constexpr float ULTRA_DEATH_WAVE_STEP = 110; +constexpr float ULTRA_DEATH_WAVE_SPEED = -40; +constexpr float ULTRA_DEATH_WAVE_PHASE = 2.3561945f; +constexpr int ULTRA_DEATH_SKULL_Z = 1000; +constexpr int ULTRA_DEATH_RUN_END = 365; +constexpr int ULTRA_DEATH_RUN_LAST = 380; +constexpr int ULTRA_DEATH_FAN_SIDE = 2; +constexpr float ULTRA_DEATH_FAN_TURN = 22.5f; +constexpr float ULTRA_DEATH_FAN_SPEED = 8; +constexpr float ULTRA_DEATH_FAN_LAUNCH = 0.1f; +constexpr int ULTRA_DEATH_FAN_WAIT = 15; +constexpr ColorMod ULTRA_DEATH_WHITE_FLASH = {{1, 1, 1, 1}, {0, 0, 0, 0}, {1, 1, 1}}; + +// Its swing preparation: held in place at 10% a tick, three dark orbiting scythes 60 out, the skulls dying, and 60 +// ticks of fading out. +constexpr float ULTRA_DEATH_HOLD = 0.1f; +constexpr int ULTRA_DEATH_ORBITERS = 3; +constexpr float ULTRA_DEATH_ORBIT_RADIUS = 60; +constexpr float ULTRA_DEATH_ORBIT_TURN = 120; +constexpr float ULTRA_DEATH_ORBIT_START = -90; +constexpr ColorMod ULTRA_DEATH_ORBIT_COLOR = {{0.8f, 0.8f, 0.8f, 1}, {0, 0, 0, 0}, {-0.1f, -0.1f, -0.1f}}; +constexpr ColorMod ULTRA_DEATH_BLACK_FADE = tint_color_make(0, 0, 0, 1); +constexpr int ULTRA_DEATH_FADE_FRAMES = 60; +constexpr float ULTRA_DEATH_DARK_START = HALF; + +// Its swings: the dark deepening 0.02 a tick toward its goal (0.2 more a swing) for 300 ticks; it shows 280 off the +// player (1.8 times on the first) 30 ticks in, swings at 60 (52 later) with a lunge of 18, homing on where the player +// heads from 40 to 60 ticks in; its Hit null deals 2 to players and familiars and 35 to anything else. +constexpr int ULTRA_DEATH_DARK_FRAMES = 300; +constexpr int ULTRA_DEATH_DARK_FADE_FRAMES = 30; +constexpr float ULTRA_DEATH_DARK_RATE = 0.02f; +constexpr float ULTRA_DEATH_DARK_STEP = 0.2f; +constexpr int ULTRA_DEATH_SWING_COUNT = 4; +constexpr int ULTRA_DEATH_APPEAR_FRAME = 30; +constexpr int ULTRA_DEATH_SWING_FRAME = 52; +constexpr int ULTRA_DEATH_FIRST_SWING_DELAY = 8; +constexpr float ULTRA_DEATH_APPEAR_SIDE = 280; +constexpr float ULTRA_DEATH_FIRST_APPEAR_FAR = 1.8f; +constexpr float ULTRA_DEATH_LEAD = 15; +constexpr float ULTRA_DEATH_SWING_PITCH = 0.8f; +constexpr int ULTRA_DEATH_SWING_SHAKE = 4; +constexpr int ULTRA_DEATH_SWING_RECOVER = -10; +constexpr int ULTRA_DEATH_LUNGE_END = -5; +constexpr float ULTRA_DEATH_LUNGE_SPEED = 18; +constexpr float ULTRA_DEATH_LUNGE_DECAY = 0.8f; +constexpr float ULTRA_DEATH_HOME_FROM = 40; +constexpr float ULTRA_DEATH_HOME_SPAN = 20; +constexpr float ULTRA_DEATH_HOME_SIDE = 20; +constexpr float ULTRA_DEATH_HOME_PULL = 0.09f; +constexpr float ULTRA_DEATH_HOME_TOP = 30; +constexpr float ULTRA_DEATH_APPEAR_FADE = 10; +constexpr float ULTRA_DEATH_SWING_KNOCK = 10; +constexpr float ULTRA_DEATH_SWING_PLAYER_DAMAGE = 2; +constexpr float ULTRA_DEATH_SWING_DAMAGE = 35; +constexpr int ULTRA_DEATH_SWING_COUNTDOWN = 30; + +// Its smoke: dark puffs about it every 3 ticks while preparing, black smoke over the room every 2 in the dark. +constexpr float ULTRA_DEATH_SMOKE_EVERY = 3; +constexpr float ULTRA_DEATH_DARK_SMOKE_EVERY = 2; +constexpr float ULTRA_DEATH_SMOKE_SCALE = 1.5f; +constexpr float ULTRA_DEATH_SMOKE_SCALE_RANGE = HALF; +constexpr float ULTRA_DEATH_SMOKE_ALPHA = 0.2f; +constexpr float ULTRA_DEATH_SMOKE_ALPHA_RANGE = 0.2f; +constexpr float ULTRA_DEATH_DARK_SMOKE_ALPHA = 0.1f; +constexpr float ULTRA_DEATH_DARK_SMOKE_ALPHA_RANGE = 0.15f; +constexpr int ULTRA_DEATH_SMOKE_FADE = 10; +constexpr uint32_t ULTRA_DEATH_SMOKE_FRAMES = 15; +constexpr uint32_t ULTRA_DEATH_DARK_SMOKE_FRAMES = 20; +constexpr int ULTRA_DEATH_DARK_SMOKE_Z = 1000; +constexpr float ULTRA_DEATH_DARK_THRESHOLD = HALF; +constexpr float ULTRA_DEATH_LOOP_FADE = 0.05f; +constexpr ColorMod ULTRA_DEATH_SMOKE_GONE = tint_color_make(0, 0, 0, 0); + +// Every enemy of a type Death spawned, its spawner Death. +static std::vector death_spawns_get(Entity_NPC& npc, int variant) +{ + std::vector found; + for (Entity* entity : Entity_NPC::QueryNPCsType(ENTITY_BEAST, variant)) + if (entity && Entity::is_enemy_type(entity->type) && entity->spawnerEntity.get() == &npc) found.push_back(entity); + return found; +} + +// Its red trail follows its glowing eye while it swings in the dark, hidden otherwise. +static void ultra_death_trail_update(Entity_NPC& npc) +{ + Entity* trail = npc.entityRef.get(); + if (!trail) return; + if (npc.state == ULTRA_DEATH_SWINGS) + { + Vector eye = npc.GetNullOffset("Eye"); + if (!vector_is_zero(eye)) + { + trail->sprite.color._tint[3] = npc.sprite.GetLayer(ULTRA_DEATH_GLOW_LAYER)->color._tint[3]; + trail->pos = vector_add(npc.pos, eye); + return; + } + } + trail->sprite.color._tint[3] = 0; +} + +// Its start: the hover's, its three phases, the music's third layer, and its red trail. +static void ultra_death_init(Entity_NPC& npc) +{ + horseman_init(npc); + npc.aiCallFlags |= ULTRA_DEATH_PHASES; + npc.i1 = 0; + horseman_music_layer_set(-1); + g_manager->musicManager.EnableLayer(ULTRA_DEATH_MUSIC_LAYER, LAYER_FADE); + auto* trail = static_cast(g_game->Spawn({.position = npc.pos, + .spawner = &npc, + .type = ENTITY_EFFECT, + .variant = EFFECT_SPRITE_TRAIL, + .seed = Random()})); + trail->sprite.color = ULTRA_DEATH_TRAIL_COLOR; + trail->minRadius = ULTRA_DEATH_TRAIL_WIDTH; + trail->maxRadius = ULTRA_DEATH_TRAIL_WIDTH; + trail->sprite.scale = vector_make(ULTRA_DEATH_TRAIL_SCALE, ULTRA_DEATH_TRAIL_SCALE); + trail->parent = &npc; + npc.entityRef = trail; +} + +// The goal of its hover: the nearest of the player's corners inside the room's margins, or the player. +static Vector ultra_death_corner_pick(Entity_NPC& npc, Vector player) +{ + Room& room = *g_game->room; + float best = ULTRA_DEATH_FAR; + Vector goal = player; + for (Vector corner : ULTRA_DEATH_CORNERS) + { + Vector spot = vector_add(vector_scale(corner, ULTRA_DEATH_CORNER_REACH), player); + float distance = vector_length_squared(vector_sub(npc.pos, spot)); + bool isOutside = spot.x < room.topLeftPos.x + ULTRA_DEATH_CORNER_MARGIN || + room.bottomRightPos.x - ULTRA_DEATH_CORNER_MARGIN < spot.x || + spot.y < room.topLeftPos.y + ULTRA_DEATH_CORNER_MARGIN || + room.bottomRightPos.y - ULTRA_DEATH_CORNER_MARGIN < spot.y; + if (isOutside) distance = ULTRA_DEATH_FAR; + if (distance >= best) continue; + best = distance; + goal = spot; + } + return goal; +} + +// The hover off the player's corners; after three summons it runs for the skulls. +static void ultra_death_hover(Entity_NPC& npc, Room& room) +{ + if (npc.sprite.IsFinished()) npc.sprite.Play("Idle"); + npc.friction = ULTRA_HORSEMAN_FRICTION; + Entity* target = npc.GetPlayerTarget(); + Vector player = target->pos; + float lineUp = std::min(std::abs(player.x - npc.pos.x), std::abs(player.y - npc.pos.y)); + float closeness = std::clamp((ULTRA_DEATH_LINE_UP - lineUp) / vector_distance(npc.pos, player), 0.0f, 1.0f); + PathFinder& path = npc.pathfinder; + npc.velocity = vector_add(npc.velocity, vector_scale(path.moveDirection, + (closeness * ULTRA_DEATH_LINE_UP_PUSH + ULTRA_HOVER_PUSH) * npc.speedMultiplier)); + if (path.moveCountdown < 1) + { + float wait = (float)(Random() % ULTRA_HOVER_RETARGET + ULTRA_HOVER_RETARGET) + 0; + path.moveCountdown = (int)((1 - closeness * ULTRA_DEATH_RETARGET_HASTE) * wait); + path.movementTarget = ultra_death_corner_pick(npc, player); + path.movementTarget = vector_add(path.movementTarget, vector_scale(random_direction(), ULTRA_HOVER_JITTER * (1 - closeness))); + } + else + path.moveCountdown -= npc_ticks_get(npc); + + horseman_steer(npc, (closeness * closeness * ULTRA_DEATH_STEER_LINED + ULTRA_HOVER_STEER) * npc.speedMultiplier); + Vector margin = vector_make(ULTRA_HOVER_MARGIN_X, ULTRA_HOVER_MARGIN_Y); + horseman_keep_in(npc, hover_bounds_get(margin, ULTRA_DEATH_KEEP_IN * npc.speedMultiplier)); + if (player.x > npc.pos.x + ULTRA_DEATH_FACE_MARGIN) npc.sprite.isFlipX = true; + else if (player.x < npc.pos.x - ULTRA_DEATH_FACE_MARGIN) npc.sprite.isFlipX = false; + + npc.stateFrame += npc_ticks_get(npc); + if (npc.stateFrame < ULTRA_DEATH_HOVER_FRAMES) return; + if (npc.i1 > ULTRA_DEATH_SUMMONS) + { + npc.v1 = vector_make(npc.pos.x <= (room.bottomRightPos.x + room.topLeftPos.x) * HALF ? -1.0f : 1.0f, 0); + npc.aiFloat = ULTRA_DEATH_PUSH_START; + npc.sprite.isFlipX = npc.v1.x > 0; + npc.state = ULTRA_DEATH_SKULL_RUN; + npc.i1 = 0; + } + else + { + npc.sprite.Play("SummonStart"); + npc.state = ULTRA_DEATH_SUMMON; + horseman_face_target(npc); + npc.i1++; + } + npc.stateFrame = 0; +} + +// The glide in from the side, slowing until 200 inside the far side, into the hover. +static void ultra_death_glide(Entity_NPC& npc, Room& room) +{ + npc.sprite.Play("Idle"); + npc.velocity = vector_add(npc.velocity, vector_scale(npc.v1, npc.aiFloat * npc.speedMultiplier)); + npc.aiFloat = std::max(npc.aiFloat - npc.speedMultiplier * ULTRA_DEATH_PUSH_DECAY, ULTRA_DEATH_PUSH_LEAST); + if (!horseman_is_past(npc, room.bottomRightPos.x - ULTRA_DEATH_GLIDE_EDGE, room.topLeftPos.x + ULTRA_DEATH_GLIDE_EDGE)) return; + npc_sound_play(SOUND_DEATH_GROWL, 1, 2, 1); + npc.state = NPC_STATE_IDLE; + npc.i1 = 0; + npc.stateFrame = 0; +} + +// The summon: its scythes along rays round its aim, one a tick, all launching together. +static void ultra_death_summon(Entity_NPC& npc) +{ + npc.friction *= ULTRA_HORSEMAN_FRICTION; + if (npc.stateFrame < 0) + { + if (!npc.sprite.IsFinished()) return; + npc.sprite.Play("Idle"); + npc.state = NPC_STATE_IDLE; + npc.stateFrame = 0; + return; + } + if (npc.sprite.IsFinished()) npc.sprite.Play("SummonLoop"); + if (npc.sprite.IsEventTriggered("Shoot")) + { + npc.v1 = vector_scale(vector_normalized(vector_sub(npc.GetPlayerTarget()->pos, npc.pos)), ULTRA_DEATH_AIM_REACH); + npc.stateFrame = 1; + npc.PlaySound(SOUND_DEATH_SUMMON_SCYTHES, 1, 2, false, 1); + npc.PlaySound(SOUND_SUMMONSOUND, 1, 2, false, 1); + } + for (int tick = npc.stateFrame > 0 ? npc_ticks_get(npc) : 0; tick > 0; tick--) + { + Vector ray = vector_rotated(npc.v1, (float)(npc.stateFrame - ULTRA_DEATH_RAY_MIDDLE) * ULTRA_DEATH_RAY_TURN); + Vector edge = Entity_Laser::CalculateEndPoint(npc.pos, ray, {}, nullptr, ULTRA_DEATH_RAY_MARGIN); + uint32_t seed = Random(); + auto* scythe = static_cast(g_game->Spawn({.position = edge, + .spawner = &npc, + .type = ENTITY_BEAST, + .variant = BEAST_ULTRA_DEATH_SCYTHE, + .seed = seed})); + Vector back = vector_normalized(vector_sub(npc.pos, edge)); + float launch = random_unit() * ULTRA_DEATH_LAUNCH_RANGE + 1; + scythe->flags = (scythe->flags & ~FLAG_APPEAR) | FLAG_AMBUSH; + scythe->targetPosition = vector_scale(back, launch); + scythe->SetColor(ULTRA_DEATH_WHITE_FADE, ULTRA_DEATH_SCYTHE_FADE, COLOR_PRIORITY_DEFAULT, true, true); + scythe->Update(); + scythe->stateFrame = ULTRA_DEATH_SCYTHE_WAIT - npc.stateFrame; + if (npc.stateFrame > ULTRA_DEATH_SCYTHES) + { + npc.stateFrame = -1; + npc.sprite.Play("SummonEnd"); + return; + } + npc.stateFrame++; + } +} + +// The fan of scythes the skull run would throw on a Shoot, which neither of its animations has. +static void ultra_death_scythe_fan(Entity_NPC& npc) +{ + npc.PlaySound(SOUND_MONSTER_GRUNT_4, 1, 2, false, 1); + npc.PlaySound(SOUND_SUMMONSOUND, 1, 2, false, 1); + Vector aim = vector_normalized(vector_sub(npc.GetPlayerTarget()->pos, npc.pos)); + for (int side = -ULTRA_DEATH_FAN_SIDE; side <= ULTRA_DEATH_FAN_SIDE; side += 2) + { + Vector velocity = vector_scale(vector_rotated(aim, (float)side * ULTRA_DEATH_FAN_TURN), ULTRA_DEATH_FAN_SPEED); + uint32_t seed = Random(); + auto* scythe = static_cast(g_game->Spawn({.position = vector_add(vector_scale(velocity, 2), npc.pos), + .velocity = velocity, + .spawner = &npc, + .type = ENTITY_BEAST, + .variant = BEAST_ULTRA_DEATH_SCYTHE, + .seed = seed})); + scythe->flags &= ~FLAG_APPEAR; + scythe->targetPosition = vector_scale(velocity, ULTRA_DEATH_FAN_LAUNCH); + scythe->renderZOffset = ULTRA_DEATH_SKULL_Z; + scythe->SetColor(ULTRA_DEATH_WHITE_FLASH, ULTRA_DEATH_SCYTHE_FADE, COLOR_PRIORITY_DEFAULT, true, true); + scythe->Update(); + scythe->stateFrame = ULTRA_DEATH_FAN_WAIT; + } +} + +// A wave of four skulls flying in from beyond the side it runs to. +static void ultra_death_skulls_spawn(Entity_NPC& npc, Room& room) +{ + float from = npc.v1.x <= 0 ? room.topLeftPos.x - ULTRA_DEATH_WAVE_OUT : room.bottomRightPos.x + ULTRA_DEATH_WAVE_OUT; + npc_sound_play(SOUND_DEATH_SUMMON_SKULLS, 1, 2, 1); + for (int i = 0; i < ULTRA_DEATH_WAVE_SKULLS; i++) + { + bool isBehind = (i & 1) != 0; + Vector at = vector_make(isBehind ? npc.v1.x * ULTRA_DEATH_WAVE_STAGGER + from : from, + (float)i * ULTRA_DEATH_WAVE_STEP + ULTRA_DEATH_WAVE_TOP); + uint32_t seed = Random(); + Entity* skull = g_game->Spawn({.position = at, + .velocity = vector_scale(npc.v1, ULTRA_DEATH_WAVE_SPEED), + .spawner = &npc, + .type = ENTITY_BEAST, + .variant = BEAST_ULTRA_DEATH_HEAD, + .seed = seed}); + skull->renderZOffset = isBehind ? -ULTRA_DEATH_SKULL_Z : ULTRA_DEATH_SKULL_Z; + skull->targetPosition = vector_make((float)npc.stateFrame * PI_F / HALF_TURN_DEGREES + (float)i * ULTRA_DEATH_WAVE_PHASE, 0); + skull->Update(); + } +} + +// The skull run: off one side and back across as waves of skulls fly in, then the swing prepared. +static void ultra_death_skull_run(Entity_NPC& npc, Room& room) +{ + SFXManager& sfx = g_manager->sfxManager; + npc.friction *= ULTRA_HORSEMAN_FRICTION; + if (npc.sprite.IsFinished()) npc.sprite.Play("SummonLoop"); + if (npc.sprite.IsPlaying("SummonLoop")) + { + float volume = sfx.GetAmbientSoundVolume(SOUND_DEATH_SKULL_SUMMON_LOOP); + if (volume < 1) sfx.SetAmbientSound(SOUND_DEATH_SKULL_SUMMON_LOOP, volume + ULTRA_DEATH_LOOP_RAMP, 1); + } + + float push = npc.aiFloat; + if (npc.i1 == 0) + { + npc.velocity = vector_add(npc.velocity, vector_scale(npc.v1, push * npc.speedMultiplier)); + npc.aiFloat = std::min(npc.speedMultiplier * ULTRA_DEATH_RUN_PUSH_GROWTH + npc.aiFloat, ULTRA_DEATH_RUN_PUSH_TOP); + bool isRight = npc.v1.x > 0; + bool isLeft = npc.v1.x < 0; + if (npc.stateFrame == 0 && ((isRight && room.bottomRightPos.x - ULTRA_DEATH_RUN_EDGE < npc.pos.x) || + (isLeft && npc.pos.x < room.topLeftPos.x + ULTRA_DEATH_RUN_EDGE))) + npc.stateFrame = 1; + if ((isRight && room.bottomRightPos.x + ULTRA_DEATH_RUN_OUT < npc.pos.x) || + (isLeft && npc.pos.x < room.topLeftPos.x - ULTRA_DEATH_RUN_OUT)) + { + npc.i1 = 1; + npc.pos.x = npc.v1.x <= 0 ? room.topLeftPos.x - ULTRA_DEATH_RUN_OUT : room.bottomRightPos.x + ULTRA_DEATH_RUN_OUT; + npc.sprite.isFlipX = !npc.sprite.isFlipX; + npc.pos.y = (room.bottomRightPos.y + room.topLeftPos.y) * HALF; + npc.sprite.Play("SummonLoop"); + npc_sound_play(SOUND_DEATH_SUMMON_SKULLS, 1, 2, 1); + } + } + else + { + npc.velocity = vector_sub(npc.velocity, vector_scale(npc.v1, push * npc.speedMultiplier)); + npc.aiFloat = std::max(npc.aiFloat - npc.speedMultiplier * ULTRA_DEATH_PUSH_DECAY, ULTRA_DEATH_PUSH_LEAST); + } + if (npc.sprite.IsEventTriggered("Shoot")) ultra_death_scythe_fan(npc); + + for (int tick = npc.stateFrame > 0 ? npc_ticks_get(npc) : 0; tick > 0; tick--) + { + if (npc.stateFrame % ULTRA_DEATH_WAVE_EVERY == 0) ultra_death_skulls_spawn(npc, room); + if (npc.stateFrame > ULTRA_DEATH_RUN_END && npc.sprite.animState.IsLoopingAnimation()) npc.sprite.Play("SummonEnd"); + if (npc.stateFrame > ULTRA_DEATH_RUN_LAST) + { + npc.sprite.Play("SwingPrepare"); + npc.stateFrame = 0; + npc.i1 = 0; + npc.state = ULTRA_DEATH_SWING_PREPARE; + npc.targetPosition = npc.pos; + return; + } + npc.stateFrame++; + } +} + +// The swing's preparation: held in place, the skulls dying, three dark scythes set orbiting, and Death fading out. +// Returns the alpha its body shows. +static float ultra_death_swing_prepare(Entity_NPC& npc) +{ + npc.friction *= ULTRA_HORSEMAN_FRICTION; + npc.velocity = vector_add(npc.velocity, vector_scale(vector_sub(npc.targetPosition, npc.pos), ULTRA_DEATH_HOLD * npc.speedMultiplier)); + if (npc.sprite.IsFinished()) npc.sprite.Play("SwingPrepareLoop"); + if (npc.sprite.IsEventTriggered("Shoot")) + { + npc_sound_play(SOUND_DEATH_SKULL_SUMMON_END, 1, 2, 1); + for (Entity* skull : death_spawns_get(npc, BEAST_ULTRA_DEATH_HEAD)) + { + static_cast(skull)->state = NPC_STATE_SUICIDE; + skull->sprite.Play("DieStart", PLAY_FORCED); + } + npc.PlaySound(SOUND_DEATH_DESTROY_SKULLS, 1, 2, false, 1); + for (int i = 0; i < ULTRA_DEATH_ORBITERS; i++) + { + float angle = (float)i * ULTRA_DEATH_ORBIT_TURN + ULTRA_DEATH_ORBIT_START; + uint32_t seed = Random(); + Entity* scythe = g_game->Spawn({.position = npc.pos, + .spawner = &npc, + .subType = 1, + .type = ENTITY_BEAST, + .variant = BEAST_ULTRA_DEATH_SCYTHE, + .seed = seed}); + scythe->SetColor(ULTRA_DEATH_ORBIT_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); + scythe->SetColor(ULTRA_DEATH_BLACK_FADE, ULTRA_DEATH_SCYTHE_FADE, COLOR_PRIORITY_DEFAULT, true, true); + scythe->flags &= ~FLAG_APPEAR; + scythe->entityCollisionClass = ENTCOLL_NONE; + scythe->targetPosition = vector_make(ULTRA_DEATH_ORBIT_RADIUS, angle); + scythe->Update(); + scythe->renderZOffset = ULTRA_DEATH_SKULL_Z; + } + npc.stateFrame = 1; + } + + float alpha = std::clamp((float)(ULTRA_DEATH_FADE_FRAMES - npc.stateFrame) / ULTRA_DEATH_FADE_FRAMES, 0.0f, 1.0f); + if (npc.stateFrame <= 0) return alpha; + npc.stateFrame += npc_ticks_get(npc); + if (npc.stateFrame <= ULTRA_DEATH_FADE_FRAMES) return alpha; + npc.state = ULTRA_DEATH_SWINGS; + npc.entityCollisionClass = ENTCOLL_NONE; + npc.isVisible = false; + npc.v2 = vector_make(ULTRA_DEATH_DARK_START, ULTRA_DEATH_DARK_START); + npc.i1 = 0; + npc.stateFrame = 0; + return alpha; +} + +// The end of the swings: the dark lifting, Death back from the side for its glide, its skulls gone. +static void ultra_death_swings_end(Entity_NPC& npc, Room& room) +{ + g_game->darknessStrength = npc.v2.x; + g_game->darknessTimeout = ULTRA_DEATH_DARK_FADE_FRAMES; + bool isLeftFacing = !npc.sprite.isFlipX; + npc.pos = vector_make(isLeftFacing ? room.bottomRightPos.x + ULTRA_DEATH_GLIDE_EDGE : room.topLeftPos.x - ULTRA_DEATH_GLIDE_EDGE, + (room.bottomRightPos.y + room.topLeftPos.y) * HALF); + npc.velocity = {}; + npc.state = ULTRA_DEATH_GLIDE; + npc.isVisible = true; + npc.entityCollisionClass = ENTCOLL_ALL; + npc.v1 = vector_make(isLeftFacing ? -1.0f : 1.0f, 0); + npc.aiFloat = ULTRA_DEATH_PUSH_START; + for (Entity* skull : death_spawns_get(npc, BEAST_ULTRA_DEATH_HEAD)) skull->Remove(); +} + +// A tick of the swings: it shows off the player's side, swings, vanishes and comes from the other side. Returns +// whether the swings are over. +static bool ultra_death_swing_tick(Entity_NPC& npc, Room& room) +{ + npc.stateFrame++; + if (npc.stateFrame == ULTRA_DEATH_APPEAR_FRAME) + { + Vector player = npc.GetPlayerTarget()->pos; + npc.isVisible = true; + npc.entityCollisionClass = ENTCOLL_ALL; + npc.sprite.Play("SwingPrepareLoop"); + npc_sound_play(SOUND_DEATH_SWIPE_START, 1, 2, 1); + Entity* target = npc.GetPlayerTarget(); + float side = npc.sprite.isFlipX ? -ULTRA_DEATH_APPEAR_SIDE : ULTRA_DEATH_APPEAR_SIDE; + float far = npc.i1 == 0 ? ULTRA_DEATH_FIRST_APPEAR_FAR : 1; + npc.pos.y = player.y + target->velocity.y * ULTRA_DEATH_LEAD; + npc.pos.x = far * side + player.x; + npc.velocity = {}; + return false; + } + if (npc.stateFrame == (npc.i1 == 0 ? ULTRA_DEATH_FIRST_SWING_DELAY : 0) + ULTRA_DEATH_SWING_FRAME) + { + npc.sprite.Play("Swing"); + npc_sound_play(SOUND_DEATH_SWIPE, 1, 2, 1); + return false; + } + if (npc.stateFrame != 0) return false; + npc.i1++; + npc.isVisible = false; + npc.entityCollisionClass = ENTCOLL_NONE; + if (npc.i1 < ULTRA_DEATH_SWING_COUNT) + { + npc.sprite.isFlipX = !npc.sprite.isFlipX; + return false; + } + ultra_death_swings_end(npc, room); + return true; +} + +// The swing's hit: everything its Hit null touches is knocked away and hurt. +static void ultra_death_swing_hit(Entity_NPC& npc) +{ + Capsule blade; + npc.GetNullCapsule(blade, "Hit"); + if (blade.radius <= 0) return; + if (g_game->debugFlags & DEBUG_HITSPHERES) reconstruction_missing("Entity::GetDebugShape 006b5f10, Ultra Death's swing"); + for (Entity* entity : entity_query_radius(blade.center, blade.halfLength + blade.radius, QUERY_ALL)) + { + if (entity->entityCollisionClass == ENTCOLL_NONE || entity->entityGridCollisionClass == GRIDCOLL_BULLET || entity == &npc) + continue; + if (!Capsule::Collide(blade, entity->GetCollisionCapsule({}))) continue; + Vector away = vector_normalized(vector_sub(entity->pos, npc.pos)); + entity->velocity = vector_add(entity->velocity, vector_scale(away, ULTRA_DEATH_SWING_KNOCK)); + bool isPlayerSide = entity->type == ENTITY_PLAYER || entity->type == ENTITY_FAMILIAR; + entity->TakeDamage(isPlayerSide ? ULTRA_DEATH_SWING_PLAYER_DAMAGE : ULTRA_DEATH_SWING_DAMAGE, 0, EntityRef(&npc), + ULTRA_DEATH_SWING_COUNTDOWN); + } +} + +// The swings in the dark. Returns the alpha its body shows. +static float ultra_death_swings(Entity_NPC& npc, Room& room) +{ + npc.friction *= ULTRA_HORSEMAN_FRICTION; + g_game->darknessStrength = npc.v2.x; + g_game->darknessTimeout = ULTRA_DEATH_DARK_FRAMES; + float step = npc.speedMultiplier * ULTRA_DEATH_DARK_RATE; + if (std::abs(npc.v2.x - npc.v2.y) > step) npc.v2.x = npc.v2.y <= npc.v2.x ? npc.v2.x - step : npc.v2.x + step; + else npc.v2.x = npc.v2.y; + float alpha = npc.stateFrame < 1 ? (float)-npc.stateFrame / ULTRA_DEATH_APPEAR_FADE + : ((float)npc.stateFrame - ULTRA_DEATH_APPEAR_FRAME) / ULTRA_DEATH_APPEAR_FRAME; + alpha = std::clamp(alpha, 0.0f, 1.0f); + for (int tick = npc_ticks_get(npc); tick > 0; tick--) + if (ultra_death_swing_tick(npc, room)) return alpha; + + if (npc.sprite.IsEventTriggered("Shoot")) + { + npc.v2.y = std::min(npc.v2.y + ULTRA_DEATH_DARK_STEP, 1.0f); + npc.PlaySound(SOUND_SHELLGAME, 1, 2, false, ULTRA_DEATH_SWING_PITCH); + npc.PlaySound(SOUND_TOOTH_AND_NAIL, 1, 2, false, 1); + game_shake_screen(ULTRA_DEATH_SWING_SHAKE); + npc.stateFrame = ULTRA_DEATH_SWING_RECOVER; + npc.v1 = vector_make(npc.sprite.isFlipX ? ULTRA_DEATH_LUNGE_SPEED : -ULTRA_DEATH_LUNGE_SPEED, 0); + } + if (npc.isVisible) ultra_death_swing_hit(npc); + if (npc.stateFrame < ULTRA_DEATH_LUNGE_END) + { + npc.velocity = vector_add(npc.velocity, vector_scale(npc.v1, npc.speedMultiplier)); + npc.v1 = vector_scale(npc.v1, timescale_factor(ULTRA_DEATH_LUNGE_DECAY, npc.speedMultiplier)); + } + if (npc.stateFrame <= 0 || !npc.isVisible) return alpha; + + float homing = 1 - std::clamp(((float)npc.stateFrame - ULTRA_DEATH_HOME_FROM) / ULTRA_DEATH_HOME_SPAN, 0.0f, 1.0f); + Vector player = npc.GetPlayerTarget()->pos; + Entity* target = npc.GetPlayerTarget(); + float side = npc.sprite.isFlipX ? -ULTRA_DEATH_HOME_SIDE : ULTRA_DEATH_HOME_SIDE; + float pullY = ((target->velocity.y * ULTRA_DEATH_LEAD * homing + player.y) - npc.pos.y) * ULTRA_DEATH_HOME_PULL * homing * HALF; + float pullX = ((target->velocity.x * ULTRA_DEATH_LEAD * homing + player.x + side) - npc.pos.x) * ULTRA_DEATH_HOME_PULL * homing; + Vector pull = vector_make(pullX, pullY); + float length = vector_length(pull); + if (length > ULTRA_DEATH_HOME_TOP && length > 0) pull = vector_scale(pull, ULTRA_DEATH_HOME_TOP / length); + npc.velocity = pull; + return alpha; +} + +// A cloud of Death's smoke: where, how fast, how big, its tint's alpha range, how long it lasts and its depth. +struct DeathSmoke +{ + Vector position{}; + Vector velocity{}; + float alpha = 0; + float alphaRange = 0; + float scale = 1; + uint32_t seed = 0; + uint32_t frames = 0; + int zOffset = 0; +}; + +// A black smoke cloud of Death's fading out after its tint, run once. +static void death_smoke_spawn(Entity_NPC& npc, const DeathSmoke& smoke) +{ + auto* cloud = static_cast(g_game->Spawn({.position = smoke.position, + .velocity = smoke.velocity, + .spawner = &npc, + .type = ENTITY_EFFECT, + .variant = EFFECT_DUST_CLOUD, + .seed = smoke.seed})); + cloud->posOffset = npc.posOffset; + cloud->sprite.scale = vector_make(smoke.scale + smoke.scale, smoke.scale + smoke.scale); + cloud->SetColor(tint_color_make(0, 0, 0, random_unit() * smoke.alphaRange + smoke.alpha), -1, COLOR_PRIORITY_DEFAULT, false, + true); + cloud->SetColor(ULTRA_DEATH_SMOKE_GONE, ULTRA_DEATH_SMOKE_FADE, COLOR_PRIORITY_DEFAULT, true, true); + cloud->rotation = random_between(DUST_SPIN_MIN, DUST_SPIN_RANGE); + if (smoke.zOffset != 0) cloud->renderZOffset = smoke.zOffset; + int lifespan = (int)(Random() % smoke.frames + smoke.frames); + cloud->timeout = lifespan; + cloud->lifespan = lifespan; + cloud->Update(); +} + +// The smoke while it prepares its swing (puffs about it) and in the dark (black smoke over the room). +static void ultra_death_smoke(Entity_NPC& npc, Room& room, float alpha) +{ + bool isPreparing = npc.state == ULTRA_DEATH_SWING_PREPARE; + if (isPreparing && npc.stateFrame < 1) return; + if (isPreparing && npc.GetIntervalTicks(ULTRA_DEATH_SMOKE_EVERY, 0) != 0 && alpha > 0) + { + float scale = random_unit() * ULTRA_DEATH_SMOKE_SCALE_RANGE + ULTRA_DEATH_SMOKE_SCALE; + Vector direction = random_direction(); + Vector drift = vector_scale(direction, std::sqrt(random_unit())); + uint32_t seed = Random(); + death_smoke_spawn(npc, {.position = vector_add(vector_scale(drift, npc.size), npc.pos), + .velocity = drift, + .alpha = ULTRA_DEATH_SMOKE_ALPHA, + .alphaRange = ULTRA_DEATH_SMOKE_ALPHA_RANGE, + .scale = scale, + .seed = seed, + .frames = ULTRA_DEATH_SMOKE_FRAMES}); + } + bool isDark = isPreparing || npc.state == ULTRA_DEATH_SWINGS || + (npc.state == ULTRA_DEATH_GLIDE && g_game->darknessModifier > ULTRA_DEATH_DARK_THRESHOLD); + if (!isDark || npc.GetIntervalTicks(ULTRA_DEATH_DARK_SMOKE_EVERY, 0) == 0) return; + float scale = random_unit() * ULTRA_DEATH_SMOKE_SCALE_RANGE + ULTRA_DEATH_SMOKE_SCALE; + Vector at = room.GetRandomPosition(0); + uint32_t seed = Random(); + death_smoke_spawn(npc, {.position = at, + .alpha = ULTRA_DEATH_DARK_SMOKE_ALPHA, + .alphaRange = ULTRA_DEATH_DARK_SMOKE_ALPHA_RANGE, + .scale = scale, + .seed = seed, + .frames = ULTRA_DEATH_DARK_SMOKE_FRAMES, + .zOffset = ULTRA_DEATH_DARK_SMOKE_Z}); +} + +// Its layers' alpha: the body by the fade, the glow twice that in the room's darkness. +static void ultra_death_layers_fade(Entity_NPC& npc, float alpha) +{ + for (int layer = 0; layer < (int)npc.sprite.layerStates.size(); layer++) + { + float shown = alpha; + if (layer > ULTRA_DEATH_BODY_LAYERS) shown = std::min(alpha + alpha, 1.0f) * g_game->darknessModifier * g_game->darknessStrength; + npc.sprite.GetLayer(layer)->color._tint[3] = shown; + } +} + +// Its death: the dark lifting, every enemy it spawned killed, and its skulls' loop stopped. +static void ultra_death_die(Entity_NPC& npc) +{ + if (g_game->darknessModifier > 0) + { + g_game->darknessStrength = g_game->darknessModifier; + g_game->darknessTimeout = ULTRA_DEATH_DARK_FADE_FRAMES; + } + for (Entity* entity : entities_live(g_game->room->entityList.updateEL)) + if (Entity::is_enemy_type(entity->type) && entity->spawnerEntity.get() == &npc) entity->Kill(EntityRef(&npc)); + g_manager->sfxManager.Stop(SOUND_DEATH_SKULL_SUMMON_LOOP); +} + +// 00440f00 Ultra Death (951.40): hovers, summons scythes, runs off for the skulls, and swings in the dark; its red +// trail follows its eye; dying it throws its scythe away from the player. +static void ultra_death_update(Entity_NPC& npc) +{ + Room& room = *g_game->room; + if (npc.aiCallPhase == AI_PHASE_PRE_UPDATE) return horseman_sink(npc); + if (npc.aiCallPhase == AI_PHASE_POST_UPDATE || npc.aiCallPhase == AI_PHASE_INTERPOLATE) return ultra_death_trail_update(npc); + + if (npc.isDead) + { + npc_sound_play(SOUND_DEATH_DIES, 1, 2, 1); + Entity* scythe = g_game->Spawn({.position = vector_add(npc.pos, ULTRA_DEATH_SCYTHE_DROP), + .velocity = vector_make(-ULTRA_DEATH_SCYTHE_THROW_X, ULTRA_DEATH_SCYTHE_THROW_Y), + .type = ENTITY_EFFECT, + .variant = EFFECT_ULTRA_DEATH_SCYTHE, + .seed = Random()}); + if (npc.GetPlayerTarget()->pos.x < npc.pos.x) + { + scythe->velocity = vector_make(ULTRA_DEATH_SCYTHE_THROW_X, ULTRA_DEATH_SCYTHE_THROW_Y); + scythe->sprite.isFlipX = true; + } + scythe->Update(); + } + + float alpha = 1; + switch (npc.state) + { + case NPC_STATE_INIT: + ultra_death_init(npc); + break; + case NPC_STATE_IDLE: + ultra_death_hover(npc, room); + break; + case ULTRA_DEATH_GLIDE: + ultra_death_glide(npc, room); + break; + case ULTRA_DEATH_SUMMON: + ultra_death_summon(npc); + break; + case ULTRA_DEATH_SKULL_RUN: + ultra_death_skull_run(npc, room); + break; + case ULTRA_DEATH_SWING_PREPARE: + alpha = ultra_death_swing_prepare(npc); + break; + case ULTRA_DEATH_SWINGS: + alpha = ultra_death_swings(npc, room); + break; + case ULTRA_HORSEMAN_ARRIVING: + npc.state = ULTRA_DEATH_GLIDE; + npc.v1 = vector_make(-1, 0); + npc.isVisible = true; + npc.entityCollisionClass = ENTCOLL_ALL; + npc.i1 = 0; + npc.sprite.Play("Idle"); + break; + } + + ultra_death_smoke(npc, room, alpha); + ultra_death_layers_fade(npc, alpha); + SFXManager& sfx = g_manager->sfxManager; + if (npc.state != ULTRA_DEATH_SKULL_RUN && sfx.IsPlaying(SOUND_DEATH_SKULL_SUMMON_LOOP)) + { + float volume = sfx.GetAmbientSoundVolume(SOUND_DEATH_SKULL_SUMMON_LOOP); + if (volume > 0) sfx.SetAmbientSound(SOUND_DEATH_SKULL_SUMMON_LOOP, volume - ULTRA_DEATH_LOOP_FADE, 1); + } + if (npc.isDead) ultra_death_die(npc); +} + +// Ultra Death's scythe (951.41): a thrown one waits, then flies back across the room and is gone 200 outside it; an +// orbiting one (subtype 1) swings out round where it started, ever wider and faster with a dark trail and dust, and +// cuts down Death's skulls within reach once 30 ticks old. Either dies with Death. +constexpr int SCYTHE_ORBIT = 1; +constexpr int SCYTHE_THROW_WAIT = 15; +constexpr uint64_t SCYTHE_FLAGS = FLAG_NO_STATUS_EFFECTS | FLAG_NO_BLOOD_SPLASH | FLAG_NO_KNOCKBACK | FLAG_NO_PHYSICS_KNOCKBACK | + FLAG_NO_REWARD | FLAG_NO_PLAYER_CONTROL; +static const Vector SCYTHE_OFFSET = vector_make(0, -18); +constexpr uint32_t SCYTHE_PHASES = AI_CALL_INTERPOLATE | AI_CALL_POST_UPDATE; +constexpr ColorMod SCYTHE_TRAIL_COLOR = tint_color_make(0, 0, 0, 0.75f); +constexpr float SCYTHE_TRAIL_SCALE = 6; +constexpr float SCYTHE_TRAIL_FADE_IN = 0.05f; +constexpr float SCYTHE_LAUNCH = 0.2f; +constexpr float SCYTHE_SPIN_SPEED = 10; +constexpr float SCYTHE_HELD_SPIN = 0.01f; +constexpr float SCYTHE_GONE = -200; +constexpr float SCYTHE_ORBIT_STEP = 0.15f; +constexpr float SCYTHE_ORBIT_GROWTH = 0.1f; +constexpr float SCYTHE_ORBIT_TURN = 8; +constexpr float SCYTHE_ORBIT_LAST = 1000; +constexpr float SCYTHE_DUST_EVERY = 2; +constexpr float SCYTHE_DUST_AFTER = 10; +constexpr float SCYTHE_DUST_CARRY = 0.2f; +constexpr float SCYTHE_DUST_FLING = 0.4f; +constexpr float SCYTHE_DUST_NEAR = 100; +constexpr float SCYTHE_DUST_SPAN = 300; +constexpr float SCYTHE_DUST_SCALE = 0.8f; +constexpr float SCYTHE_DUST_SCALE_RANGE = 0.7f; +constexpr float SCYTHE_DUST_FADE_IN = 30; +constexpr float SCYTHE_DUST_ALPHA = 0.1f; +constexpr float SCYTHE_DUST_ALPHA_RANGE = 0.2f; +constexpr uint32_t SCYTHE_DUST_FRAMES = 30; +constexpr float SCYTHE_CUT_AFTER = 30; +constexpr float SCYTHE_CUT_REACH = 40; +constexpr std::array SCYTHE_SPINS = {"Rotate3", "Rotate4", "Rotate5", "Rotate6"}; +constexpr float SCYTHE_SPIN_REACH = 100; + +// Its start: a still spin at a random frame, 18 up, its orbit's centre where it is, and an orbiting one's trail. +static void death_scythe_init(Entity_NPC& npc) +{ + npc.state = NPC_STATE_IDLE; + npc.stateFrame = SCYTHE_THROW_WAIT; + AnimationState& anim = npc.sprite.animState; + if (npc.sprite.SetAnimation(SCYTHE_SPINS[0]) && anim.animData) + { + anim.SetFrameFloat(0); + anim.isPlaying = false; + } + int frame = anim.animData && anim.animData->length != 0 ? (int)(Random() % (uint32_t)anim.animData->length) : 0; + if (anim.animData) anim.SetFrameFloat((float)frame); + npc.flags |= SCYTHE_FLAGS; + npc.posOffset = SCYTHE_OFFSET; + npc.v1 = npc.pos; + if (npc.subtype != SCYTHE_ORBIT) return; + + npc.aiCallFlags = SCYTHE_PHASES; + auto* trail = static_cast(g_game->Spawn({.position = npc.pos, + .spawner = &npc, + .type = ENTITY_EFFECT, + .variant = EFFECT_SPRITE_TRAIL, + .seed = Random()})); + trail->sprite.color = SCYTHE_TRAIL_COLOR; + trail->minRadius = ULTRA_DEATH_TRAIL_WIDTH; + trail->maxRadius = ULTRA_DEATH_TRAIL_WIDTH; + trail->sprite.scale = vector_make(SCYTHE_TRAIL_SCALE, SCYTHE_TRAIL_SCALE); + trail->parent = &npc; + npc.entityRef = trail; +} + +// The dust an orbiting scythe sheds, darker and bigger the wider it swings. +static void death_scythe_dust(Entity_NPC& npc, float size) +{ + auto* dust = static_cast( + g_game->Spawn({.position = npc.pos, .spawner = &npc, .type = ENTITY_EFFECT, .variant = EFFECT_DUST_CLOUD, .seed = Random()})); + dust->velocity = vector_scale(npc.velocity, SCYTHE_DUST_CARRY); + Vector direction = random_direction(); + Vector fling = vector_scale(direction, random_unit()); + npc_push(*dust, vector_scale(fling, vector_length(npc.velocity) * SCYTHE_DUST_FLING)); + dust->posOffset = npc.posOffset; + dust->sprite.scale = vector_make(size + size, size + size); + float fadeIn = std::min(npc.updateTime / SCYTHE_DUST_FADE_IN, 1.0f); + float alpha = (random_unit() * SCYTHE_DUST_ALPHA_RANGE + SCYTHE_DUST_ALPHA) * fadeIn; + dust->SetColor(tint_color_make(0, 0, 0, alpha), -1, COLOR_PRIORITY_DEFAULT, false, true); + dust->rotation = random_between(DUST_SPIN_MIN, DUST_SPIN_RANGE); + int frames = (int)(Random() % SCYTHE_DUST_FRAMES + SCYTHE_DUST_FRAMES); + dust->timeout = frames; + dust->lifespan = frames; + dust->Update(); +} + +// The orbit: its radius and angle in targetPosition, its swing out sped up in v2.x, its spin by its radius, the +// skulls it cuts. +static void death_scythe_orbit(Entity_NPC& npc) +{ + float step = npc.updateTime * npc.updateTime * SCYTHE_ORBIT_STEP * SCYTHE_ORBIT_STEP; + Vector& orbit = npc.targetPosition; + Vector move = vector_sub(vector_add(vector_scale(vector_from_angle(orbit.y), orbit.x), npc.v1), npc.pos); + if (vector_length_squared(move) > step * step) move = vector_resized(move, step); + npc.v2.x += npc.speedMultiplier * SCYTHE_ORBIT_GROWTH; + orbit.x += npc.speedMultiplier * npc.v2.x; + orbit.y = normalize_angle_degrees(std::min(npc.v2.x, 1.0f) * SCYTHE_ORBIT_TURN * npc.speedMultiplier + orbit.y); + float size = std::clamp((orbit.x - SCYTHE_DUST_NEAR) / SCYTHE_DUST_SPAN, 0.0f, 1.0f) * SCYTHE_DUST_SCALE_RANGE + SCYTHE_DUST_SCALE; + if (npc.GetIntervalTicks(SCYTHE_DUST_EVERY, 0) != 0 && npc.updateTime > SCYTHE_DUST_AFTER) death_scythe_dust(npc, size); + + if (npc.sprite.IsFinished()) npc.sprite.Play(SCYTHE_SPINS[0], PLAY_FORCED); + size_t spin = std::min((size_t)std::max(orbit.x / SCYTHE_SPIN_REACH, 0.0f), SCYTHE_SPINS.size() - 1); + npc.sprite.SetAnimation(SCYTHE_SPINS[spin], SWITCH_KEEP_FRAME); + npc.sprite.playbackSpeed = std::clamp(vector_length(npc.velocity) / SCYTHE_SPIN_SPEED, 0.0f, 1.0f); + npc.velocity = move; + if (npc.updateTime <= SCYTHE_CUT_AFTER) return; + for (Entity* entity : entity_query_radius(npc.pos, npc.size + SCYTHE_CUT_REACH, QUERY_ENEMIES)) + if (Entity::is_enemy_type(entity->type) && !entity->isDead && entity->IsType(ENTITY_BEAST, BEAST_ULTRA_DEATH_HEAD, -1)) + entity->Kill(EntityRef()); +} + +// A thrown scythe waits, slowing, then flies back across the room, spinning by its speed. +static void death_scythe_throw(Entity_NPC& npc) +{ + if (npc.stateFrame < 1) + { + npc.velocity = vector_add(npc.velocity, vector_scale(npc.targetPosition, SCYTHE_LAUNCH * npc.speedMultiplier)); + npc.sprite.playbackSpeed = std::clamp(vector_length(npc.velocity) / SCYTHE_SPIN_SPEED, 0.0f, 1.0f); + return; + } + npc.stateFrame -= npc_ticks_get(npc); + npc.friction *= ULTRA_HORSEMAN_FRICTION; + if (npc.stateFrame >= 1) return; + int frame = npc.sprite.GetFrame(); + npc.sprite.Play(SCYTHE_SPINS[0], PLAY_FORCED); + if (npc.sprite.animState.animData) npc.sprite.animState.SetFrameFloat((float)frame); + npc.sprite.playbackSpeed = SCYTHE_HELD_SPIN; + npc.friction = 1; +} + +// 00443e50 Ultra Death's scythe (951.41): thrown across the room, or orbiting out cutting down the skulls; it dies +// with Death and its trail follows it. +static void ultra_death_scythe_update(Entity_NPC& npc) +{ + if (npc.aiCallPhase == AI_PHASE_POST_UPDATE || npc.aiCallPhase == AI_PHASE_INTERPOLATE) + { + Entity* spawner = npc.spawnerEntity.get(); + if (!npc.isDead && npc.aiCallPhase == AI_PHASE_POST_UPDATE && (!spawner || spawner->isDead)) + { + npc.Kill(EntityRef()); + return; + } + if (Entity* trail = npc.entityRef.get()) + { + trail->pos = vector_add(npc.pos, npc.posOffset); + trail->sprite.color._tint[3] = std::min(npc.updateTime * SCYTHE_TRAIL_FADE_IN, 1.0f); + } + return; + } + + if (npc.state == NPC_STATE_INIT) death_scythe_init(npc); + else if (npc.state == NPC_STATE_IDLE && npc.subtype == SCYTHE_ORBIT) death_scythe_orbit(npc); + else if (npc.state == NPC_STATE_IDLE) death_scythe_throw(npc); + if (npc.subtype == 0 && !g_game->room->IsPositionInRoom(npc.pos, SCYTHE_GONE)) npc.Remove(); + if (npc.subtype == SCYTHE_ORBIT && npc.targetPosition.x > SCYTHE_ORBIT_LAST) npc.Remove(); +} + +// Ultra Death's skull (951.42): it flies in bobbing on its own phase, dies when Death tells it, and dies with Death. +constexpr uint64_t SKULL_FLAGS = FLAG_NO_BLOOD_SPLASH | FLAG_NO_PLAYER_CONTROL; +constexpr int SKULL_DYING = NPC_STATE_SUICIDE; +constexpr float SKULL_BOB_RATE = 0.05f; +constexpr float SKULL_BOB = 6; +constexpr float SKULL_DYING_FRICTION = 0.7f; +constexpr float SKULL_BURST_VOLUME = 0.8f; +constexpr ColorMod SKULL_POOF_COLOR = tint_color_make(0.2f, 0.2f, 0.2f, 1); +constexpr float SKULL_POOF_SCALE = 1.5f; +constexpr ColorMod SKULL_CLOUD_COLOR = tint_color_make(0, 0, 0, 1); + +// 00444900 Ultra Death's skull (951.42): flying in on a bob, or dying at Death's word; its burst of black smoke. +static void ultra_death_head_update(Entity_NPC& npc) +{ + Entity* spawner = npc.spawnerEntity.get(); + if (!npc.isDead && (!spawner || spawner->isDead)) + { + npc.Kill(EntityRef()); + g_manager->sfxManager.Stop(SOUND_DEATH_SKULL_SUMMON_LOOP); + return; + } + + switch (npc.state) + { + case NPC_STATE_INIT: + npc.state = NPC_STATE_IDLE; + npc.flags |= SKULL_FLAGS; + npc.v1 = vector_normalized(npc.velocity); + npc.isInvincible = true; + break; + case NPC_STATE_IDLE: + npc.friction *= ULTRA_HORSEMAN_FRICTION; + npc.velocity.x += npc.speedMultiplier * npc.v1.x; + npc.sprite.isFlipX = npc.v1.x > 0; + npc.velocity.y = std::sin(npc.updateTime * SKULL_BOB_RATE + npc.targetPosition.x) * SKULL_BOB; + npc.sprite.Play("Idle"); + break; + case SKULL_DYING: + npc.sprite.isFlipX = false; + npc.entityCollisionClass = ENTCOLL_ENEMIES; + npc.friction *= SKULL_DYING_FRICTION; + if (npc.sprite.IsFinished()) npc.sprite.Play("DieLoop"); + break; + } + if (!npc.isDead) return; + npc_sound_play(SOUND_BLACK_POOF, SKULL_BURST_VOLUME, 2, champion_pitch_get(npc)); + npc.MakeGroundPoof(npc.pos, SKULL_POOF_COLOR, SKULL_POOF_SCALE); + g_game->room->fxLayers.AddPoopFx(SKULL_CLOUD_COLOR); +} + +// The Beast's horsemen and their spawns (951.10 to 42) and the background beasts (951.100 to 104), by variant. +void beast_horseman_update(Entity_NPC& npc) +{ + switch (npc.variant) + { + case BEAST_ULTRA_FAMINE: + return ultra_famine_update(npc); + case BEAST_ULTRA_FAMINE_FLY: + return ultra_famine_fly_update(npc); + case BEAST_ULTRA_PESTILENCE: + return ultra_pestilence_update(npc); + case BEAST_ULTRA_PESTILENCE_FLY: + return pestilence_fly_update(npc); + case BEAST_ULTRA_PESTILENCE_MAGGOT: + return pestilence_maggot_update(npc); + case BEAST_ULTRA_PESTILENCE_FLY_BALL: + return pestilence_fly_ball_update(npc); + case BEAST_ULTRA_WAR: + return ultra_war_update(npc); + case BEAST_ULTRA_WAR_BOMB: + return ultra_war_bomb_update(npc); + case BEAST_ULTRA_DEATH: + return ultra_death_update(npc); + case BEAST_ULTRA_DEATH_SCYTHE: + return ultra_death_scythe_update(npc); + case BEAST_ULTRA_DEATH_HEAD: + return ultra_death_head_update(npc); + default: + return beast_background_update(npc); + } +} diff --git a/src/boss_big_horn.cpp b/src/boss_big_horn.cpp index a0658c2..8adb5f8 100644 --- a/src/boss_big_horn.cpp +++ b/src/boss_big_horn.cpp @@ -209,7 +209,7 @@ void water_drops_spawn(const Vector& position, Vector radii, float speed) float scale = narrow > DROPS_BIG_RADIUS ? DROPS_BIG_SCALE : 1; for (int drops = (int)(Random() % DROPS_RANGE) + DROPS_MIN; drops > 0; drops--) { - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; Vector offset = vector_make(std::cos(angle) * radii.x, std::sin(angle) * radii.y); float pace = (random_unit() * DROPS_SPEED_RANGE + DROPS_SPEED_MIN) * speed; diff --git a/src/boss_bumbino.cpp b/src/boss_bumbino.cpp index 4129d0c..b2f8a8b 100644 --- a/src/boss_bumbino.cpp +++ b/src/boss_bumbino.cpp @@ -87,7 +87,6 @@ constexpr float SWIPE_WALL_FACING = 0.3f; constexpr float SWIPE_KNOCK = 10; constexpr float SWIPE_PLAYER_DAMAGE = 2; constexpr float SWIPE_DAMAGE = 35; -constexpr int SWIPE_HIT_COUNTDOWN = 30; constexpr uint32_t COIN_LOSS_RANGE = 3; constexpr float COIN_KNOCK = 3; constexpr float BUMBINO_COIN_SPEED_RANGE = 5; @@ -98,8 +97,6 @@ constexpr int SWIPE_AGAIN_FRAME = 7; // Its trail of dust while lunging, every 2 frames, at a fifth of its speed plus 2 at random. constexpr float DUST_EVERY = 2; constexpr float DUST_TRAIL_SHARE = 0.2f; -constexpr float BUMBINO_DUST_SPIN = 10; -constexpr float BUMBINO_DUST_SPIN_MIN = 2; constexpr uint32_t DUST_TRAIL_RANGE = 15; constexpr int DUST_TRAIL_FRAMES = 15; constexpr ColorMod BUMBINO_DUST_COLOR = {{0.8f, 0.7f, 0.65f, 0.75f}, {0, 0, 0, 0}, {0, 0, 0}}; @@ -186,7 +183,7 @@ static void bumbino_trail_spawn(Entity_NPC& npc) Vector velocity = vector_add(vector_scale(npc.velocity, DUST_TRAIL_SHARE), vector_add(drift, drift)); auto* cloud = static_cast(g_game->Spawn( {.position = npc.pos, .velocity = velocity, .spawner = &npc, .type = ENTITY_EFFECT, .variant = EFFECT_DUST_CLOUD, .seed = seed})); - cloud->rotation = random_unit() * BUMBINO_DUST_SPIN + BUMBINO_DUST_SPIN_MIN; + cloud->rotation = random_between(DUST_SPIN_MIN, DUST_SPIN_RANGE); cloud->SetTimeout((int)(Random() % DUST_TRAIL_RANGE) + DUST_TRAIL_FRAMES); cloud->SetColor(BUMBINO_DUST_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); cloud->renderDepthOffset = BUMBINO_DUST_DEPTH; @@ -202,7 +199,7 @@ static void bumbino_burst_dust(Entity_NPC& npc, const Vector& position, const Ve .variant = EFFECT_DUST_CLOUD, .seed = Random()})); float side = Random() & 1 ? 1.0f : -1.0f; - cloud->rotation = (random_unit() * BUMBINO_DUST_SPIN + BUMBINO_DUST_SPIN_MIN) * side; + cloud->rotation = (random_between(DUST_SPIN_MIN, DUST_SPIN_RANGE)) * side; float scale = random_unit() * BUMBINO_DUST_SCALE_RANGE + BUMBINO_DUST_SCALE; cloud->sprite.scale = vector_make(scale, scale); cloud->SetTimeout((int)(Random() % SLAM_DUST_RANGE) + SLAM_DUST_FRAMES); @@ -347,7 +344,7 @@ static void bumbino_dizzy_update(Entity_NPC& npc, int ticks) params.scale = RAIN_SCALE - random_unit() * RAIN_SCALE_RANGE; params.variant = PROJECTILE_ROCK; params.fallingSpeedModifier = random_unit() * RAIN_FALL_RANGE + 0; - float angle = random_unit() * RANDOM_HALF_TURN * 2; + float angle = random_unit() * PI_ROUGH * 2; float speed = random_unit(); npc.FireProjectiles(spot, vector_make(std::cos(angle) * speed, std::sin(angle) * speed), PROJECTILES_SINGLE, params); } @@ -363,7 +360,7 @@ static void bumbino_hitbox_update(Entity_NPC& npc) Capsule hitbox; npc.GetNullCapsule(hitbox, "Hitbox"); if (hitbox.radius <= 0) return; - // The hitspheres debug view (debug flag 6) is left out until Entity::GetDebugShape is written. + // The hitspheres debug view (debug flag 6) is left out until DebugRenderer is taken over. for (Entity* other : entity_query_radius(hitbox.center, hitbox.halfLength + hitbox.radius, QUERY_ALL)) { @@ -374,7 +371,7 @@ static void bumbino_hitbox_update(Entity_NPC& npc) Vector away = vector_normalized(vector_sub(other->pos, npc.pos)); other->velocity = vector_add(other->velocity, vector_scale(away, SWIPE_KNOCK)); bool isFriend = other->type == ENTITY_PLAYER || other->type == ENTITY_FAMILIAR; - other->TakeDamage(isFriend ? SWIPE_PLAYER_DAMAGE : SWIPE_DAMAGE, 0, EntityRef(&npc), SWIPE_HIT_COUNTDOWN); + other->TakeDamage(isFriend ? SWIPE_PLAYER_DAMAGE : SWIPE_DAMAGE, 0, EntityRef(&npc), HIT_COUNTDOWN); auto* player = other->ToPlayer(); bool isRobbed = player && player->variant == 0 && !player->isCoopGhost && @@ -386,7 +383,7 @@ static void bumbino_hitbox_update(Entity_NPC& npc) { uint32_t seed = Random(); Vector knock = vector_scale(away, COIN_KNOCK); - float angle = random_unit() * RANDOM_HALF_TURN * 2; + float angle = random_unit() * PI_ROUGH * 2; float speed = random_unit() * BUMBINO_COIN_SPEED_RANGE + COIN_SPEED; Vector velocity = vector_add(knock, vector_make(std::cos(angle) * speed, std::sin(angle) * speed)); g_game->Spawn({.position = player->pos, @@ -467,7 +464,7 @@ static void bumbino_slam_update(Entity_NPC& npc) game_shake_screen(BUMBINO_SLAM_SHAKE); for (int i = 0; i < SLAM_DUST; i++) { - float angle = random_unit() * RANDOM_HALF_TURN * 2; + float angle = random_unit() * PI_ROUGH * 2; float speed = random_unit() * BUMBINO_SLAM_DUST_SPEED_RANGE + SLAM_DUST_SPEED; bumbino_burst_dust(npc, hit, vector_make(std::cos(angle) * speed, std::sin(angle) * speed)); } @@ -487,7 +484,7 @@ static void bumbino_slam_update(Entity_NPC& npc) npc.FireProjectiles(hit, vector_make(BUMBINO_SLAM_ROCK_SPEED, 0), PROJECTILES_EIGHT, params); for (int i = 0; i < BUMBINO_SLAM_PARTICLES; i++) { - float angle = random_unit() * RANDOM_HALF_TURN * 2; + float angle = random_unit() * PI_ROUGH * 2; float speed = random_unit() + PARTICLE_SPEED_MIN; Vector direction = vector_make(std::cos(angle) * speed, std::sin(angle) * speed * PARTICLE_FLATTEN); uint32_t seed = Random(); @@ -572,8 +569,7 @@ static bool bumbino_rocks_break(Entity_NPC& npc) if (!isSolid || !rock || rock->collisionClass != COLLISION_SOLID) continue; if (!rock->Destroy(false, EntityRef(&npc))) continue; - Vector cell = vector_make((float)(rock->gridIndex % room.gridWidth) * GRID_CELL_SIZE + GRID_ORIGIN_X, - (float)(rock->gridIndex / room.gridWidth) * GRID_CELL_SIZE + GRID_ORIGIN_Y); + Vector cell = room.GetGridPosition(rock->gridIndex); Vector beyond = vector_add(cell, vector_scale(vector_cardinal(vector_sub(cell, npc.pos)), GRID_CELL_SIZE)); int beyondIndex = room.GetGridIndex(beyond); if (beyondIndex >= 0) room_bridge_make(room.GetGridEntity((uint32_t)beyondIndex), rock); diff --git a/src/boss_cage.cpp b/src/boss_cage.cpp index 9b1e023..daaea05 100644 --- a/src/boss_cage.cpp +++ b/src/boss_cage.cpp @@ -52,7 +52,6 @@ constexpr int CAGE_REST = 30; constexpr uint32_t CAGE_ATTACK_ODDS = 20; constexpr uint32_t CAGE_PUKE_ODDS = 3; constexpr int CAGE_VOMIT_ENEMY_LIMIT = 3; -constexpr float CAGE_HALF_TURN = 180; constexpr float CAGE_FULL_TURN = 360; constexpr float CAGE_JUMP_LEAD = 10; @@ -168,7 +167,7 @@ static void cage_idle(Entity_NPC& npc) return; } npc.state = CAGE_PUKE; - npc.v1.x = random_unit() * CAGE_FULL_TURN - CAGE_HALF_TURN; + npc.v1.x = random_unit() * CAGE_FULL_TURN - HALF_TURN_DEGREES; float turn = (float)(Random() & 1) + 0; npc.v1.y = (turn + turn) - 1; return; @@ -226,7 +225,7 @@ static void cage_land_burst(Entity_NPC& npc) for (int i = 0; i < CAGE_CREEPS; i++) { uint32_t seed = Random(); - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float reach = random_unit() * CAGE_CREEP_REACH; Vector spot = vector_make(std::cos(angle) * reach + npc.pos.x, std::sin(angle) * reach + npc.pos.y); @@ -389,7 +388,7 @@ static bool cage_laser(Entity_NPC& npc) {.position = npc.pos, .posOffset = offset, .source = &npc, - .angleDegrees = angle_wrap((float)direction * CAGE_LASER_QUARTER + CAGE_HALF_TURN), + .angleDegrees = angle_wrap((float)direction * CAGE_LASER_QUARTER + HALF_TURN_DEGREES), .timeout = CAGE_LASER_TIMEOUT, .variant = CAGE_LASER_VARIANT}); laser->renderDepthOffset = direction == DIRECTION_UP ? CAGE_LASER_DEPTH_UP : CAGE_LASER_DEPTH; diff --git a/src/boss_colostomia.cpp b/src/boss_colostomia.cpp index 7467ca2..de33494 100644 --- a/src/boss_colostomia.cpp +++ b/src/boss_colostomia.cpp @@ -429,7 +429,7 @@ static void colostomia_charge_splash(Entity_NPC& npc) for (uint32_t drops = Random() % COLO_DROPS_RANGE + COLO_DROPS; drops != 0; drops--) { - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; Vector reach = vector_make(std::cos(angle) * COLO_DROP_REACH_X, std::sin(angle) * COLO_DROP_REACH_Y); float speed = random_unit() * COLO_DROP_SPEED_RANGE + COLO_DROP_SPEED; @@ -680,7 +680,7 @@ static void colostomia_drip(Entity_NPC& npc) Vector guide = npc.GetNullOffset("EffectGuide"); if (vector_is_zero(guide)) return; - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float reach = random_unit(); Vector drift = vector_make(std::cos(angle) * reach, std::sin(angle) * reach); diff --git a/src/boss_daddy_long_legs.cpp b/src/boss_daddy_long_legs.cpp index 2e392e7..867692f 100644 --- a/src/boss_daddy_long_legs.cpp +++ b/src/boss_daddy_long_legs.cpp @@ -206,7 +206,7 @@ static void dll_drop(Entity_NPC& npc, int ticks) npc.stateFrame++; if (npc.variant != TRIACHNID || npc.stateFrame >= TRIACHNID_CREEP_FRAMES) continue; - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float reach = (float)npc.stateFrame + (float)npc.stateFrame + TRIACHNID_CREEP_REACH; Vector at = vector_make(std::cos(angle) * reach + npc.pos.x, std::sin(angle) * reach + npc.pos.y); diff --git a/src/boss_death.cpp b/src/boss_death.cpp index 097312d..29688f8 100644 --- a/src/boss_death.cpp +++ b/src/boss_death.cpp @@ -13,6 +13,8 @@ #include "npc_ai.h" #include "options_config.h" #include "persistent_game_data.h" +#include "player_manager.h" +#include "item_pool.h" #include "room.h" #include "room_descriptor.h" #include "room_grid.h" @@ -78,6 +80,8 @@ constexpr RNG COLOR_HEART_SHIFTS = {0, 3, 5, 22}; constexpr RNG CONSOLATION_SHIFTS = {0, 3, 3, 29}; constexpr RNG SOL_SHIFTS = {0, 5, 27, 25}; constexpr int DEATH_SEED_SHIFT_INDEX = 4; +// An angel's key piece drop draws from its seed at this shift index. +constexpr int ANGEL_DROP_SHIFT_INDEX = 30; constexpr int HORNFEL_SHIFT_INDEX = 23; constexpr int PERFECTION_SHIFT_INDEX = 24; constexpr int HORNFEL_CHEST_ODDS = 7; @@ -577,10 +581,67 @@ static void miniboss_death_rewards(Room& room, Entity_NPC& boss, RNG& rng, bool else if (isKrampus) save.TryUnlock(ACHIEVEMENT_HEAD_OF_KRAMPUS); } +// Part of 007fec00: an angel's key piece. The first Uriel (or Gabriel) of its kind killed in the room drops the +// first (or second) key piece unless someone has it or it lies in the room. Filigree Feather stands in for the piece +// another one would block: an angel item, with a half soul heart (doubled) or a soul heart (tripled) beside it. +// The original also counts the angels killed in a Game field nothing reads, left out here. +static void angel_key_piece_drop(Room& room, Entity_NPC& boss) +{ + for (const KilledNpc& fallen : room.killedNpcs) + if (fallen.type == (int)boss.type) return; + + Game& game = *g_game; + RNG rng; + rng.game_constructor(boss.initSeed, ANGEL_DROP_SHIFT_INDEX); + GameStateFlag killed = boss.type == ENTITY_URIEL ? GAME_STATE_URIEL_KILLED : GAME_STATE_GABRIEL_KILLED; + if (!game.GetStateFlag(killed)) game.gameStateFlags |= 1ull << killed; + + Vector spot = room_free_pickup_position_find({.position = boss.pos}); + PlayerManager& players = game.playerManager; + bool hasFirst = players.AnyoneHasCollectible(COLLECTIBLE_KEY_PIECE_1); + bool hasSecond = players.AnyoneHasCollectible(COLLECTIBLE_KEY_PIECE_2); + bool isFirstHere = false; + bool isSecondHere = false; + for (Entity* entity : room.entityList.updateEL) + { + if (entity->type != ENTITY_PICKUP || entity->variant != PICKUP_COLLECTIBLE) continue; + if (entity->subtype == COLLECTIBLE_KEY_PIECE_1) isFirstHere = true; + else if (entity->subtype == COLLECTIBLE_KEY_PIECE_2) isSecondHere = true; + } + bool isFirstDropped = !hasFirst && !isFirstHere && (!players.AnyoneHasTrinket(TRINKET_FILIGREE_FEATHERS) || hasSecond); + bool isSecondDropped = + !hasSecond && !isSecondHere && (!players.AnyoneHasTrinket(TRINKET_FILIGREE_FEATHERS) || hasFirst); + + int item = 0; + if (boss.type == ENTITY_URIEL && isFirstDropped) item = COLLECTIBLE_KEY_PIECE_1; + else if (boss.type == ENTITY_GABRIEL && isSecondDropped) item = COLLECTIBLE_KEY_PIECE_2; + else + { + if (players.AnyoneHasTrinket(TRINKET_FILIGREE_FEATHERS)) + { + item = game.itemPool.GetCollectible(POOL_ANGEL, rng.Next(), 0, 0, 0); + Entity_Player* owner = players.FirstTrinketOwner(TRINKET_FILIGREE_FEATHERS); + int multiplier = owner ? owner->GetTrinketMultiplier(TRINKET_FILIGREE_FEATHERS) : 0; + if (multiplier == 2 || multiplier == 3) + { + int heart = multiplier == 2 ? (int)HEART_HALF_SOUL : (int)HEART_SOUL; + game.Spawn({.position = spot, .spawner = &boss, .subType = heart, .type = ENTITY_PICKUP, .variant = PICKUP_HEART, + .seed = rng.Next()}); + spot = room_free_pickup_position_find({.position = boss.pos}); + } + } + if (isFirstDropped) item = COLLECTIBLE_KEY_PIECE_1; + else if (isSecondDropped) item = COLLECTIBLE_KEY_PIECE_2; + if (item == 0) return; + } + game.Spawn({.position = spot, .spawner = &boss, .subType = item, .type = ENTITY_PICKUP, .variant = PICKUP_COLLECTIBLE, + .seed = rng.Next()}); +} + // 007fec00 A boss leaving for good: counts it off the room's bosses (once, never a friendly one or one that does not // count), and the last one gives the room's rewards, a miniboss's or a boss's, then moves the room's death seed on. // In a challenge or the Boss Rush the rewards are drawn from the fight's seed instead, and the room's stays. -// Big Horn's holes never count. Uriel's and Gabriel's key pieces are not reconstructed yet. +// Big Horn's holes never count. Uriel and Gabriel may leave a key piece. void Room::TriggerBossDeath(Entity_NPC& boss) { Game& game = *g_game; @@ -616,7 +677,7 @@ void Room::TriggerBossDeath(Entity_NPC& boss) bool isAngel = boss.type == ENTITY_URIEL || boss.type == ENTITY_GABRIEL; RoomType currentType = game.room->roomType; bool isAngelRoom = currentType == ROOM_ANGEL || currentType == ROOM_SACRIFICE || currentType == ROOM_SUPERSECRET; - if (isAngel && isAngelRoom) reconstruction_missing("Room::TriggerBossDeath 007fec00: the angels' key pieces"); + if (isAngel && isAngelRoom) angel_key_piece_drop(*this, boss); } // 006d7520 A death animation's blood guide between its BloodStart and BloodStop (or Explosion) events: a huge boss @@ -684,7 +745,7 @@ void Entity_NPC::update_blood_guide_gibs(const NullFrame& guide) .variant = EFFECT_BLOOD_GUSH, .seed = Random()})); gush->FollowParent(this); - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float distance = random_unit(); gush->sprite.offset = diff --git a/src/boss_dogma.cpp b/src/boss_dogma.cpp index 73c8f7e..e3569fa 100644 --- a/src/boss_dogma.cpp +++ b/src/boss_dogma.cpp @@ -662,7 +662,7 @@ static void dogma_jacob(Entity_NPC& npc, float tvHealth) npc.sprite.GetLayer(DOGMA_DISTORTION_LAYER)->color._colorize[2] = DOGMA_GLOW_SHOT; for (int shot = (int)(Random() & 1) + 3; shot != 0; shot--) { - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; Vector velocity = vector_make(std::cos(angle) * DOGMA_JACOB_SPEED, std::sin(angle) * DOGMA_JACOB_SPEED); ProjectileParams params; @@ -1164,7 +1164,6 @@ constexpr float DOGMA_ANGEL_TRAIL_DRAG = 0.5f; constexpr float DOGMA_ANGEL_RING_REACH = 1.6f; constexpr float DOGMA_ANGEL_RING_PLAYER_DAMAGE = 1; constexpr float DOGMA_ANGEL_RING_DAMAGE = 100; -constexpr int DOGMA_ANGEL_RING_HIT_COUNTDOWN = 30; constexpr float DOGMA_ANGEL_RING_PUSH = 10; constexpr uint64_t DOGMA_ANGEL_RING_FLAGS = FLAG_NO_KNOCKBACK | FLAG_NO_PHYSICS_KNOCKBACK; @@ -1458,7 +1457,7 @@ static void angel_ring_touch(Entity_NPC& npc) { if (entity == &npc) continue; bool isAlly = entity->type == ENTITY_PLAYER || entity->type == ENTITY_FAMILIAR; - entity->TakeDamage(isAlly ? DOGMA_ANGEL_RING_PLAYER_DAMAGE : DOGMA_ANGEL_RING_DAMAGE, 0, EntityRef(&npc), DOGMA_ANGEL_RING_HIT_COUNTDOWN); + entity->TakeDamage(isAlly ? DOGMA_ANGEL_RING_PLAYER_DAMAGE : DOGMA_ANGEL_RING_DAMAGE, 0, EntityRef(&npc), HIT_COUNTDOWN); Vector away = vector_resized(vector_sub(entity->pos, npc.pos), DOGMA_ANGEL_RING_PUSH); entity->velocity = vector_add(entity->velocity, vector_scale(vector_rotated(away, RIGHT_ANGLE_DEGREES), entity->speedMultiplier)); } diff --git a/src/boss_final.h b/src/boss_final.h index ae20b44..5e18d4e 100644 --- a/src/boss_final.h +++ b/src/boss_final.h @@ -76,5 +76,7 @@ void boss_mother_update(Entity_NPC& npc); void boss_dogma_update(Entity_NPC& npc); void boss_beast_update(Entity_NPC& npc); void beast_background_spawn(Entity_NPC& npc); +void beast_horseman_update(Entity_NPC& npc); +void beast_rays_spawn(Entity_NPC& npc, const Vector& offset); void beast_render(Entity_NPC& npc, const Vector& offset); void mother_render(Entity_NPC& npc, const Vector& offset); diff --git a/src/boss_fistula.cpp b/src/boss_fistula.cpp index b5e871b..4b41e21 100644 --- a/src/boss_fistula.cpp +++ b/src/boss_fistula.cpp @@ -38,9 +38,6 @@ constexpr float TERATOMA_SPIDER_FAR_REACH = 100; constexpr float TERATOMA_SPIDER_LIFT = 10; constexpr float TERATOMA_SPIDER_JUMP = -8; constexpr float TERATOMA_SPIDER_SPEED = 0.04f; -constexpr float ROOM_GRID_ORIGIN_X = 40; -constexpr float ROOM_GRID_ORIGIN_Y = 120; -constexpr float ROOM_GRID_CELL = 40; // The growl one of the room's Fistulas lets out now and then, picked among their sizes. static void fistula_growl(Entity_NPC& npc) @@ -131,11 +128,8 @@ static void teratoma_spiders(Entity_NPC& npc) auto* spider = static_cast( g_game->Spawn({.position = spot, .spawner = &npc, .type = ENTITY_SPIDER, .seed = Random()})); - int column = (int)((spot.x - ROOM_GRID_ORIGIN_X) / ROOM_GRID_CELL + 0.5f); - int row = (int)((spot.y - ROOM_GRID_ORIGIN_Y) / ROOM_GRID_CELL + 0.5f); - int cell = room.gridWidth * row + column; - if (column >= 0 && column < room.gridWidth && row >= 0 && row < room.gridHeight && cell < ROOM_GRID_CELLS && - room.gridPaths[cell] < TERATOMA_SPIDER_PATH_LIMIT) + int cell = room.GetGridIndex(spot); + if (cell >= 0 && cell < ROOM_GRID_CELLS && room.gridPaths[cell] < TERATOMA_SPIDER_PATH_LIMIT) room.gridPaths[cell] = GRID_PATH_FREED; spider->targetPosition = spider->pos; @@ -170,7 +164,7 @@ static void fistula_maggot(Entity_NPC& npc) // small ones, and a small one into its maggot or Teratoma's spiders. static void fistula_split(Entity_NPC& npc) { - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float c = std::cos(angle) * FISTULA_SPLIT_REACH; float s = std::sin(angle) * FISTULA_SPLIT_REACH; diff --git a/src/boss_forsaken.cpp b/src/boss_forsaken.cpp index 776424e..aced322 100644 --- a/src/boss_forsaken.cpp +++ b/src/boss_forsaken.cpp @@ -92,7 +92,7 @@ static void anim_keep(Entity_NPC& npc, std::string_view anim) // A random spot 70 out from the Forsaken. static Vector summon_spot_roll(const Entity_NPC& npc) { - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; return vector_make(std::cos(angle) * FORSAKEN_SUMMON_REACH + npc.pos.x, std::sin(angle) * FORSAKEN_SUMMON_REACH + npc.pos.y); diff --git a/src/boss_gideon.cpp b/src/boss_gideon.cpp index 5f3e924..98771de 100644 --- a/src/boss_gideon.cpp +++ b/src/boss_gideon.cpp @@ -117,7 +117,6 @@ constexpr int CRUMBLE_PARTICLES_MIN = 12; constexpr int CRUMBLE_PARTICLES_RANGE = 3; constexpr float CRUMBLE_SPEED = 9; constexpr int DEATH_DUST_PARTICLES = 4; -constexpr float DEATH_DUST_SPEED = 5; constexpr float DEATH_EXPLOSION_SCALE = 2; constexpr int GIDEON_DEATH_SHAKE = 14; constexpr int GIDEON_ROCK_PARTICLE_SUBTYPE = 7; @@ -130,7 +129,6 @@ constexpr std::array WAVE_DIFFICULTY = {1, 1, 5, 5, 10, 10, 15}; constexpr int WAVE_PITS_FOR_FIRE_WORMS = 6; constexpr int WAVE_TRIES = 10; constexpr int STAGE_ID_HOME_DIMENSION = 35; -constexpr int GIDEON_DIMENSION_DEATH_CERTIFICATE = 2; constexpr float WAVE_ENTRY_SCALE = 2.3283062e-10f; constexpr float CELL_SIZE = 40; constexpr float CELL_ORIGIN_X = 40; @@ -290,7 +288,7 @@ static void gideon_wave_spawn(Entity_NPC& npc) int stageId = STAGE_ID_HOME_DIMENSION; if (game.challenge == CHALLENGE_RED_REDEMPTION) stageId = RoomConfig::GetStageID(game.stage, game.GetRoomStageType(game.currentRoomIdx), ROOM_MODE_CURRENT); - else if (game.currentDimensionIdx != GIDEON_DIMENSION_DEATH_CERTIFICATE) + else if (game.currentDimensionIdx != DIMENSION_DEATH_CERTIFICATE) stageId = RoomConfig::GetStageID(game.stage, game.stageType, ROOM_MODE_CURRENT); RoomQuery query = {.shape = (RoomShape)room.GetRoomShape(), .maxDifficulty = difficulty, @@ -713,7 +711,7 @@ void gideon_death_update(Entity_NPC& npc) npc_sound_play(SOUND_ROCK_CRUMBLE, 1, 2, champion_pitch_get(npc)); Random(); game_particles_spawn({.position = npc.pos, - .speed = DEATH_DUST_SPEED, + .speed = DUST_SPEED, .count = DEATH_DUST_PARTICLES, .subType = GIDEON_ROCK_PARTICLE_SUBTYPE, .variant = EFFECT_ROCK_PARTICLE}); diff --git a/src/boss_gurdy.cpp b/src/boss_gurdy.cpp index 4b4bbb4..08549c8 100644 --- a/src/boss_gurdy.cpp +++ b/src/boss_gurdy.cpp @@ -85,7 +85,7 @@ static void gurdy_players_place(Entity_NPC& npc) player.Teleport(vector_make(npc.pos.x, GURDY_PLAYER_ROW), false, false); continue; } - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; player.Teleport(vector_make(std::cos(angle) * GURDY_PLAYER_SCATTER + npc.pos.x, std::sin(angle) * GURDY_PLAYER_SCATTER + GURDY_PLAYER_ROW), diff --git a/src/boss_horny_boys.cpp b/src/boss_horny_boys.cpp index 9b10830..4341470 100644 --- a/src/boss_horny_boys.cpp +++ b/src/boss_horny_boys.cpp @@ -603,7 +603,7 @@ void boss_horny_boys_update(Entity_NPC& npc) for (size_t slot = 0; slot < HORNY_BOMBS; slot++) { - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; Vector spot = vector_make(std::cos(angle) * HORNY_DEATH_SPREAD + npc.pos.x, std::sin(angle) * HORNY_DEATH_SPREAD + npc.pos.y); diff --git a/src/boss_intro.cpp b/src/boss_intro.cpp index f0d81ea..ef93f8f 100644 --- a/src/boss_intro.cpp +++ b/src/boss_intro.cpp @@ -53,7 +53,6 @@ constexpr int BOSS_ROOM_DELIRIUM = 90; constexpr int DELIRIUM_STAGE = 8; constexpr int DOUBLE_TROUBLE_FIRST = 3700; constexpr int DOUBLE_TROUBLE_SPAN = 150; -constexpr float BYTE_TO_UNIT = 0.003921569f; constexpr float UNKNOWN_SHADOW_GREEN = 0.5568628f; constexpr float UNKNOWN_SHADOW_BLUE = 0.4666667f; diff --git a/src/boss_isaac.cpp b/src/boss_isaac.cpp index a88d682..bb190b3 100644 --- a/src/boss_isaac.cpp +++ b/src/boss_isaac.cpp @@ -989,7 +989,7 @@ static void blink_spot_pick(Entity_NPC& npc) { for (int tries = 0; vector_is_zero(npc.targetPosition) && tries < BLINK_TRIES; tries++) { - float angle = random_unit() * RANDOM_HALF_TURN * 2; + float angle = random_unit() * PI_ROUGH * 2; float reach = random_unit() * BLINK_REACH_RANGE + BLINK_REACH_MIN; Vector spot = vector_make(std::cos(angle) * reach + npc.pos.x, std::sin(angle) * reach + npc.pos.y); Vector fromTarget = vector_sub(npc.GetPlayerTarget()->pos, spot); diff --git a/src/boss_larry_jr.cpp b/src/boss_larry_jr.cpp index 4d76059..f4d1d28 100644 --- a/src/boss_larry_jr.cpp +++ b/src/boss_larry_jr.cpp @@ -4,6 +4,7 @@ #include "entity_config.h" #include "entity_pickup.h" #include "grid_entity.h" +#include "menu_manager.h" #include "room_descriptor.h" #include "sfx_manager.h" #include @@ -42,6 +43,7 @@ constexpr float GRUB_AIM_LEAD = 16; constexpr float GRUB_AIM_BAND = 20; constexpr float GRUB_CHARGE_FRICTION = 0.9f; constexpr float GRUB_CHARGE_SPEED = 3.7f; +constexpr float GRUB_CONTROLLED_CHARGE_SPEED = 5.55f; constexpr int GRUB_SPAWNS_MIN = 2; constexpr std::array GRUB_SPAWN_KINDS = {ENTITY_CHARGER, ENTITY_SPITTY, ENTITY_MAGGOT}; constexpr int DAMAGE_COUNTDOWN_SHARED = 30; @@ -108,7 +110,8 @@ static void direction_play(Entity_NPC& npc, const DirectionAnims& anims, int dir npc.sprite.isFlipX = direction == DIRECTION_LEFT; } -// A dead Grub's segments all die and up to 2 to 5 of their free spots, shuffled, grow a Charger, Spitty or Maggot. +// A dead Grub's segments all die and up to 2 to 5 of their free spots, shuffled, grow a Charger, Spitty or Maggot, +// the first of which takes over its controller. static void grub_death(Entity_NPC& npc) { std::vector spots = {npc.pos}; @@ -133,14 +136,15 @@ static void grub_death(Entity_NPC& npc) { if (room_grid_collision_at(spots[i]) != 0) continue; int kind = GRUB_SPAWN_KINDS[Random() % GRUB_SPAWN_KINDS.size()]; - g_game->Spawn({.position = spots[i], .spawner = &npc, .type = kind, .seed = Random()}); + Entity* spawned = g_game->Spawn({.position = spots[i], .spawner = &npc, .type = kind, .seed = Random()}); + if (npc.controllerID != -1 && spawned) npc.TransferControl(static_cast(spawned)); } npc.ClearEntityFlags(FLAG_NO_DEATH_TRIGGER); } // A dead segment: a Larry Jr. head heals the segment behind it, a Grub breaks apart, the last segments cry out and a // Hollow segment may leave a Charger, Boom Fly or coin by its subtype. -static void larry_death(Entity_NPC& npc) +static void larry_death_effects(Entity_NPC& npc) { if (npc.type == ENTITY_LARRYJR) { @@ -169,6 +173,16 @@ static void larry_death(Entity_NPC& npc) npc.PlaySound(++g_hollowDeathCount & 1 ? SOUND_HOLLOW_DEATH_2 : SOUND_HOLLOW_DEATH_1, 1, 2, false, 1); } +// A dead segment's effects, then its controller passes to the segment behind it (a Grub's went to its spawns). The +// original reads a missing segment's type, so none takes it here. +static void larry_death(Entity_NPC& npc) +{ + larry_death_effects(npc); + Entity* next = npc.child; + if (npc.controllerID != -1 && npc.type != ENTITY_GRUB && next && next->IsEnemy()) + npc.TransferControl(static_cast(next)); +} + // The first frame: a segment without a parent joins the nearest free tail of its kind within reach, a head names its // group, and a Grub segment pools its neighbours' health into its own. static void larry_init(Entity_NPC& npc) @@ -221,14 +235,23 @@ static void larry_init(Entity_NPC& npc) } // A Larry Jr. tail now and then (more often when hurt) drops a poop where it crawls, outside challenge rooms and -// calm Delirium forms, and pauses its next one. +// calm Delirium forms, and pauses its next one. A controlled chain's tail drops one on its bomb button once paused +// long enough. static void tail_poop(Entity_NPC& npc) { Room& room = *g_game->room; - if (room.roomType == ROOM_CHALLENGE) return; - bool isDropped = Random() % POOP_ODDS == 0; - if (!isDropped && npc.pendingDamage > 0) isDropped = Random() % HURT_POOP_ODDS == 0; - if (!isDropped) return; + Entity_NPC* head = chain_head(npc); + if (head && head->controllerID != -1) + { + if (!head->IsControllerActionPressed(ACTION_BOMB) || npc.v1.x > 0) return; + } + else + { + if (room.roomType == ROOM_CHALLENGE) return; + bool isDropped = Random() % POOP_ODDS == 0; + if (!isDropped && npc.pendingDamage > 0) isDropped = Random() % HURT_POOP_ODDS == 0; + if (!isDropped) return; + } if (npc.HasEntityFlags(FLAG_DELIRIUM_FORM) && room_is_clear()) return; int cell = room.GetGridIndex(npc.pos); @@ -275,7 +298,8 @@ static void body_update(Entity_NPC& npc) if (npc.type == ENTITY_LARRYJR && !npc.child && npc.subtype != LARRY_SHARED_HEALTH) tail_poop(npc); } -// A Grub head waits, then charges along a row or column when its target (led a little) lines up in plain sight. +// A Grub head waits, then charges along a row or column when its target (led a little) lines up in plain sight, or +// a controlled one along its controller's walking input on the item button. static void grub_aim(Entity_NPC& npc) { if (npc.HasEntityFlags(GRUB_STUNNED)) return; @@ -289,10 +313,16 @@ static void grub_aim(Entity_NPC& npc) Vector preyVelocity = npc.GetPlayerTarget()->velocity; Vector lead = vector_scale(vector_scale(preyVelocity, random_unit()), GRUB_AIM_LEAD); Vector aim = vector_sub(vector_add(lead, preyPos), npc.pos); - if (std::abs(aim.y) >= GRUB_AIM_BAND && std::abs(aim.x) >= GRUB_AIM_BAND) return; - if (!room_check_line(npc.pos, vector_add(npc.pos, aim), LINE_MODE_GROUND, 0)) return; + if (npc.controllerID == -1) + { + if (std::abs(aim.y) >= GRUB_AIM_BAND && std::abs(aim.x) >= GRUB_AIM_BAND) return; + if (!room_check_line(npc.pos, vector_add(npc.pos, aim), LINE_MODE_GROUND, 0)) return; + } + else if (!npc.IsControllerActionPressed(ACTION_ITEM) || vector_is_zero(npc.GetControllerInput(MOVEMENT_DEADZONE))) + return; npc.PlaySound(SOUND_MONSTER_ROAR_0, 1, 2, false, 1); + if (npc.controllerID != -1) aim = npc.GetControllerInput(0); npc.targetPosition = vector_cardinal(aim); npc.stateFrame = 0; npc.i1 = 1; @@ -300,7 +330,7 @@ static void grub_aim(Entity_NPC& npc) npc.pathfinder.moveDirection = {}; } -// A charging Grub runs straight on until it hits a wall or is stunned. +// A charging Grub runs straight on until it hits a wall or is stunned, faster under a player's control. static void grub_charge(Entity_NPC& npc) { if (npc.isCollidesWithGrid || npc.HasEntityFlags(GRUB_STUNNED)) @@ -310,13 +340,13 @@ static void grub_charge(Entity_NPC& npc) return; } npc.friction *= GRUB_CHARGE_FRICTION; + float speed = npc.controllerID == -1 ? GRUB_CHARGE_SPEED : GRUB_CONTROLLED_CHARGE_SPEED; if (npc.friction != 0) - npc.velocity = vector_add(npc.velocity, vector_scale(npc.targetPosition, - GRUB_CHARGE_SPEED * npc.speedMultiplier / npc.friction)); + npc.velocity = vector_add(npc.velocity, vector_scale(npc.targetPosition, speed * npc.speedMultiplier / npc.friction)); } // A Hollow head bounces about the room in a long or tall gait, turning off the walls, and keeps away from its -// target while feared or shrunk. Confused, it wanders. +// target while feared or shrunk. Confused, it wanders, unless a player controls it. static void hollow_move(Entity_NPC& npc) { if (vector_length_squared(npc.velocity) < HOLLOW_STILL_SPEED_SQUARED && npc.friction != 0) @@ -349,7 +379,7 @@ static void hollow_move(Entity_NPC& npc) npc.v1 = Random() & 1 ? vector_make(HOLLOW_GAIT_TALL_SHORT, HOLLOW_GAIT_LONG) : vector_make(HOLLOW_GAIT_LONG, HOLLOW_GAIT_WIDE_SHORT); - if (npc.HasEntityFlags(FLAG_CONFUSION)) + if (npc.HasEntityFlags(FLAG_CONFUSION) && npc.controllerID == -1) { npc.friction = HOLLOW_CONFUSED_FRICTION; for (int i = 0; i < 3; i++) npc.pathfinder.MoveRandomlyBoss(STATUS_OBEYED); @@ -358,7 +388,7 @@ static void hollow_move(Entity_NPC& npc) if (npc.friction != 0) npc.velocity = vector_add(npc.velocity, vector_scale(vector_make(sign.x * npc.v1.x, sign.y * npc.v1.y), npc.speedMultiplier / npc.friction)); - if (!npc.HasEntityFlags(FLAG_FEAR | FLAG_SHRINK)) return; + if (!npc.HasEntityFlags(FLAG_FEAR | FLAG_SHRINK) || npc.controllerID != -1) return; Vector away = vector_sub(npc.pos, npc.GetPlayerTarget()->pos); float strength = std::clamp((LARRY_FLEE_RANGE - vector_length(away)) * LARRY_FLEE_STRENGTH, 0.0f, LARRY_FLEE_MAX); @@ -367,10 +397,12 @@ static void hollow_move(Entity_NPC& npc) vector_scale(vector_resized(away, strength), npc.speedMultiplier / npc.friction)); } -// A spitting Larry Jr. (subtype 1) now and then shoots along its way: one shot, three for the Hollow. +// A spitting Larry Jr. (subtype 1) now and then shoots along its way: one shot, three for the Hollow. A controlled +// one spits on its controller's shooting input, on the shortest cooldown. static void larry_spit(Entity_NPC& npc) { - if (Random() % SPIT_ODDS != 0) return; + bool isControlled = npc.controllerID != -1; + if (!(isControlled ? npc.IsTargetInAttackRange(CONTROLLED_ATTACK_RANGE, 0, true) : Random() % SPIT_ODDS == 0)) return; if (npc.projectileCooldown > 0) { npc.projectileCooldown -= npc_ticks_get(npc); @@ -378,7 +410,7 @@ static void larry_spit(Entity_NPC& npc) } npc.PlaySound(SOUND_BLOODSHOOT, 1, 2, false, 1); - npc.projectileCooldown = (int)(Random() % SPIT_COOLDOWN_SPREAD) + SPIT_COOLDOWN; + npc.projectileCooldown = (isControlled ? 0 : (int)(Random() % SPIT_COOLDOWN_SPREAD)) + SPIT_COOLDOWN; ProjectileParams params; params.fallingAccelModifier = SPIT_FALLING_ACCEL; if (npc.variant == 0) params.fallingSpeedModifier = SPIT_FALLING_SPEED; @@ -439,15 +471,14 @@ static void head_update(Entity_NPC& npc) } // 0046a0f0 NpcAI::ENTITY_LARRYJR: Larry Jr. and the Hollow (type 19), Buttlicker (89) and Grub (239), heads that -// crawl about trailed by body segments, which die one by one. A head without a body dies too. Tuff Twins and a -// segment a player controls are not reconstructed yet. +// crawl about trailed by body segments, which die one by one. A head without a body dies too. A player controlling a +// segment steers the head instead. void boss_larry_jr_update(Entity_NPC& npc) { if (npc.type == ENTITY_LARRYJR && (npc.variant == LARRY_TUFF_TWINS || npc.variant == LARRY_TUFF_TWINS_ALT)) return boss_tuff_twins_update(npc); Entity_NPC* head = chain_head(npc); - if (npc.controllerID != -1 || (head && head->controllerID != -1)) - reconstruction_missing("NpcAI::ENTITY_LARRYJR 0046a0f0: a segment a player controls"); + if (npc.controllerID != -1 && npc.parent && head) npc.TransferControl(head); if (npc.isDead) return larry_death(npc); if (npc.state == NPC_STATE_INIT) return larry_init(npc); diff --git a/src/boss_lil_blub.cpp b/src/boss_lil_blub.cpp index 71fa200..1b3ce5c 100644 --- a/src/boss_lil_blub.cpp +++ b/src/boss_lil_blub.cpp @@ -386,7 +386,7 @@ static void blub_burst(Entity_NPC& npc) timer->Update(); for (uint32_t i = Random() % DEATH_LEECHES_RANGE + DEATH_LEECHES; i != 0; i--) { - float angle = random_unit() * RANDOM_HALF_TURN * 2; + float angle = random_unit() * PI_ROUGH * 2; float reach = random_unit() * DEATH_LEECH_REACH; blub_leech_throw(npc, vector_add(npc.pos, vector_make(std::cos(angle) * reach, std::sin(angle) * reach)), false); } diff --git a/src/boss_mask_of_infamy.cpp b/src/boss_mask_of_infamy.cpp index 70c9a04..c872d9b 100644 --- a/src/boss_mask_of_infamy.cpp +++ b/src/boss_mask_of_infamy.cpp @@ -1,5 +1,6 @@ #include "boss_ai.h" #include "entity_player.h" +#include "menu_manager.h" #include "npc_caves.h" #include "room_grid.h" #include "sfx_manager.h" @@ -228,6 +229,31 @@ static void mask_charge_try(Entity_NPC& npc, Vector cell) npc_sound_play(SOUND_MASKINFAMY_DASH, 1, 2, 1); } +// A controlled Mask charges on its controller's item button along the controller's input (the heart's walking input, +// its own shooting one), or along its own motion without input. +static void mask_controlled_charge_try(Entity_NPC& npc, Entity_NPC& controller) +{ + npc.targetPosition = {}; + if (!controller.IsControllerActionPressed(ACTION_ITEM)) return; + + Vector input = &controller == &npc ? controller.GetControllerInput(0) : controller.GetControllerMovementInput(0); + if (vector_is_zero(input)) input = npc.velocity; + if (vector_is_zero(input)) return; + npc.targetPosition = vector_scale(vector_cardinal(input), MASK_CHARGE_PUSH); + npc.i1 = MASK_DASH_CHARGE; +} + +// The NPC steering a Mask: the Mask itself, else its heart (parent, then its linked entity) when a player controls it. +// In versus the original also takes a player there. +static Entity_NPC* mask_controller_get(Entity_NPC& npc) +{ + if (npc.controllerID != -1) return &npc; + for (Entity* link : {npc.parent.get(), npc.entityRef.get()}) + if (link && link->IsEnemy() && static_cast(link)->controllerID != -1) + return static_cast(link); + return nullptr; +} + // The dash along its axis, drawn into its lane, until it hits a wall or is distracted. static void mask_dash(Entity_NPC& npc, Vector cell) { @@ -250,14 +276,11 @@ static void mask_dash(Entity_NPC& npc, Vector cell) // 00461fc0 NpcAI::ENTITY_MASK_OF_INFAMY: the Mask of Infamy (and the plain Mask) drifts along the axes untouchable // while its heart lives, charging targets lined up with it and lunging when the heart is hurt. Without the heart it // turns angry and can be hurt. The original compares the lane cell's coordinates, not the dash's axis, to pick -// which way it is drawn into its lane. +// which way it is drawn into its lane. A player steering the Mask or its heart charges it on the item button and walks +// it while it wanders. void boss_mask_of_infamy_update(Entity_NPC& npc) { - bool isControlled = npc.controllerID != -1; - for (Entity* link : {npc.parent.get(), npc.entityRef.get()}) - isControlled |= link && link->IsEnemy() && static_cast(link)->controllerID != -1; - if (isControlled) reconstruction_missing("NpcAI::ENTITY_MASK_OF_INFAMY 00461fc0: a Mask under a player's control"); - + Entity_NPC* controller = mask_controller_get(npc); if (npc.state == NPC_STATE_INIT) return mask_init(npc); mask_heart_check(npc); mask_lunge_check(npc); @@ -265,12 +288,26 @@ void boss_mask_of_infamy_update(Entity_NPC& npc) Vector cell = mask_cell_center(npc.pos); bool isActive = !npc.HasEntityFlags(FLAG_DELIRIUM_FORM) || !room_is_clear(); - if ((npc.i1 == MASK_DASH_NONE || npc.i1 == MASK_DASH_LUNGE) && !npc.HasEntityFlags(FLAG_DISTRACTED) && isActive) - mask_charge_try(npc, cell); + if ((npc.i1 == MASK_DASH_NONE || npc.i1 == MASK_DASH_LUNGE) && !npc.HasEntityFlags(FLAG_DISTRACTED)) + { + if (controller) mask_controlled_charge_try(npc, *controller); + else if (isActive) mask_charge_try(npc, cell); + } if (npc.i1 != MASK_DASH_NONE) return mask_dash(npc, cell); + int ownController = npc.controllerID; + if (controller) + { + npc.controllerID = controller->controllerID; + npc.isControlSwapped = controller != &npc; + } npc.pathfinder.MoveRandomlyAxisAligned(npc.state == MASK_ANGRY ? MASK_ANGRY_WANDER_SPEED : MASK_WANDER_SPEED, STATUS_OBEYED); + if (controller) + { + npc.controllerID = ownController; + npc.isControlSwapped = false; + } npc.velocity.x *= timescale_factor(MASK_DRAG_X, npc.speedMultiplier); npc.velocity.y *= timescale_factor(MASK_DRAG_Y, npc.speedMultiplier); } diff --git a/src/boss_matriarch.cpp b/src/boss_matriarch.cpp index 6cb1cab..cfc242c 100644 --- a/src/boss_matriarch.cpp +++ b/src/boss_matriarch.cpp @@ -78,7 +78,6 @@ constexpr float SUMMON_OUT = 20; constexpr float SUMMON_RAISE = 4; constexpr float MATRIARCH_SUMMON_SPEED = 10; constexpr float SUMMON_BLOOD_SHARE = 0.3f; -constexpr int SUMMON_HIT_COUNTDOWN = 30; // Worms: eight Chubber worms on an ellipse of 16 (22.4 across), their blood thrown at 0.3, 0.5 and 0.6 of their speed. constexpr int WORMS = 8; @@ -297,7 +296,7 @@ static void matriarch_summon_spit(Entity_NPC& npc) matriarch_blood_spawn(BLOOD_SUBTYPE_SPLASH, position, vector_scale(fistuloid->velocity, SUMMON_BLOOD_SHARE), BLOOD_RAISE); float left = std::max(npc.health - fistuloid_health_get(), matriarch_chunk_health(npc) + 1); - if (left < npc.health) npc.TakeDamage(npc.health - left, 0, EntityRef(), SUMMON_HIT_COUNTDOWN); + if (left < npc.health) npc.TakeDamage(npc.health - left, 0, EntityRef(), HIT_COUNTDOWN); } // Sprays a ring of eight Chubber worms, each in its blood. diff --git a/src/boss_mega_fatty.cpp b/src/boss_mega_fatty.cpp index 6e8d888..c4fe48b 100644 --- a/src/boss_mega_fatty.cpp +++ b/src/boss_mega_fatty.cpp @@ -288,7 +288,7 @@ static void mega_fatty_land_burst(Entity_NPC& npc) for (int i = 0; i < MEGA_FATTY_CREEPS; i++) { uint32_t seed = Random(); - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float reach = random_unit() * MEGA_FATTY_CREEP_REACH; Vector spot = vector_make(std::cos(angle) * reach + npc.pos.x, std::sin(angle) * reach + npc.pos.y); @@ -327,7 +327,7 @@ static void mega_fatty_dips_spawn(Entity_NPC& npc) { uint32_t seed = Random(); Vector spot = room_free_pickup_position_find({.position = npc.pos, .step = MEGA_FATTY_DIP_SEARCH}); - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float reach = random_unit(); Vector position = vector_make(std::cos(angle) * reach * MEGA_FATTY_DIP_SPREAD + spot.x, diff --git a/src/boss_min_min.cpp b/src/boss_min_min.cpp index 325495a..8134b98 100644 --- a/src/boss_min_min.cpp +++ b/src/boss_min_min.cpp @@ -124,9 +124,6 @@ constexpr float DIVE_GROUP_FLATTEN = 0.6f; constexpr int DIVE_RETURN_FRAMES = 29; constexpr float DIVE_RISE_RADIUS = 0.1f; -// collect_npcs_with_same_parent's turn: a full turn in radians, wrapped as if it were degrees. -constexpr float SIBLING_TURN = 6.2831855f; - // 00557ce0 collect_npcs_with_same_parent: the live Willos sharing the Willo's parent spread evenly around their ring. static void willo_siblings_spread(Entity_NPC& npc) { @@ -142,7 +139,7 @@ static void willo_siblings_spread(Entity_NPC& npc) } if (siblings.size() < 2) return; - float step = SIBLING_TURN / (float)siblings.size(); + float step = TAU / (float)siblings.size(); for (size_t i = 0; i < siblings.size(); i++) siblings[i]->v2.x = angle_wrap((float)i * step + lowest); } @@ -497,7 +494,7 @@ static Vector dive_spot_find(Entity_NPC& npc, const std::vector& spawne if (tries < DIVE_NEAR_TRIES && Random() % DIVE_NEAR_ODDS == 0) { Vector targetPos = npc.GetPlayerTarget()->pos; - float angle = random_unit() * RANDOM_HALF_TURN * 2; + float angle = random_unit() * PI_ROUGH * 2; float distance = random_unit() * DIVE_NEAR_RANGE + DIVE_NEAR_MIN; Vector near = vector_add(targetPos, vector_make(std::cos(angle) * distance, std::sin(angle) * distance)); spot = room.GetClampedPositionImpl(near, DIVE_SPOT_MARGIN, DIVE_SPOT_MARGIN, DIVE_SPOT_MARGIN, diff --git a/src/boss_monstro.cpp b/src/boss_monstro.cpp index eb11efe..5df9c0a 100644 --- a/src/boss_monstro.cpp +++ b/src/boss_monstro.cpp @@ -411,7 +411,7 @@ static void suckers_free(Entity_NPC& npc) for (int i = 0; i < count; i++) { uint32_t seed = Random(); - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; Vector spot = vector_make(std::cos(angle) * npc.size + npc.pos.x, std::sin(angle) * npc.size + npc.pos.y); Entity* sucker = g_game->Spawn({.position = spot, diff --git a/src/boss_mother.cpp b/src/boss_mother.cpp index 309cd2f..e849f29 100644 --- a/src/boss_mother.cpp +++ b/src/boss_mother.cpp @@ -122,7 +122,6 @@ constexpr int SCRAPE_SHAKE = 8; constexpr float SCRAPE_PUSH = 10; constexpr float SCRAPE_PLAYER_DAMAGE = 2; constexpr float SCRAPE_DAMAGE = 100; -constexpr int MOTHER_HIT_COUNTDOWN = 30; constexpr float SCRAPE_ISAAC_REACH = 140; // The crush: her hands sweep down 20 a frame from the Shoot, killing the Dead Isaacs above the sweep every other frame, @@ -962,7 +961,7 @@ static void mother_scrape_update(Entity_NPC& npc) other->velocity = vector_add( other->velocity, vector_scale(vector_normalized(vector_sub(other->pos, npc.pos)), SCRAPE_PUSH)); float damage = other->is_player() || other->IsFamiliar() ? SCRAPE_PLAYER_DAMAGE : SCRAPE_DAMAGE; - other->TakeDamage(damage, 0, EntityRef(&npc), MOTHER_HIT_COUNTDOWN); + other->TakeDamage(damage, 0, EntityRef(&npc), HIT_COUNTDOWN); } if (other->IsType(ENTITY_MOTHER, MOTHER_DEAD_ISAAC, -1)) npc_sound_play(SOUND_MOTHER_ISAAC_HIT, 1, 2, 1); } @@ -1124,7 +1123,7 @@ static void mother_wall_row_fall(Entity_NPC& npc) dust_spawn(spot, 1, 0); if (Random() % SUMMON_SPLAT_ODDS == 0) { - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float reach = random_unit() * MOTHER_WALL_SPLAT_REACH; Vector splat = vector_make(std::cos(angle) * reach + spot.x, spot.y + std::sin(angle) * reach); @@ -1481,7 +1480,7 @@ static void mother_charge_update(Entity_NPC& npc, const MotherBounds& bounds) for (size_t i = 0; i < CHARGE_SPOTS.size(); i++) { Vector spot = CHARGE_SPOTS[i]; - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float reach = random_unit() * CHARGE_SPLAT_REACH; Vector position = vector_make(std::cos(angle) * reach + npc.pos.x + spot.x, @@ -1646,7 +1645,7 @@ static void mother_spin_update(Entity_NPC& npc, int ticks) .spread = GIB_SPREAD, .amount = 1, .gibFlags = (Random() & 1) ? 4u : GIB_BLOOD}); - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; Vector direction = vector_make(std::cos(angle), std::sin(angle)); Vector velocity = vector_scale(direction, random_between(SPIN_SPLAT_SPEED, SPIN_SPLAT_SPEED_RANGE)); @@ -2119,7 +2118,7 @@ static void mother_worm_steer(Entity_NPC& npc) if (delay > 0) { float ramp = std::clamp((float)delay / WORM_WEAVE_RAMP, 0.0f, 1.0f); - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float jitter = random_unit(); Vector heading = vector_normalized(npc.velocity); @@ -2206,14 +2205,14 @@ static void mother_orb_collide(Entity_NPC& npc) Vector away = vector_sub(other->pos, npc.pos); if (vector_length(away) > 0) away = vector_resized(away, ORB_PUSH); other->velocity = vector_add(other->velocity, vector_scale(away, other->speedMultiplier)); - other->TakeDamage(npc.collisionDamage, 0, EntityRef(&npc), MOTHER_HIT_COUNTDOWN); + other->TakeDamage(npc.collisionDamage, 0, EntityRef(&npc), HIT_COUNTDOWN); npc.collisionResult = 0; return; } if (other->IsFamiliar() || !Entity::is_enemy_type(other->type) || npc.subtype != MOTHER_ORB_BIG) return; if (other->IsVulnerableEnemy(nullptr) && !other->IsBoss()) - other->TakeDamage(ORB_ENEMY_DAMAGE, 0, EntityRef(&npc), MOTHER_HIT_COUNTDOWN); + other->TakeDamage(ORB_ENEMY_DAMAGE, 0, EntityRef(&npc), HIT_COUNTDOWN); npc.collisionResult = 0; } @@ -2416,7 +2415,7 @@ static void mother_orb_burst(Entity_NPC& npc) Entity* mother = npc.entityRef; if (npc.subtype == MOTHER_ORB_SMALL) { - if (mother) mother->TakeDamage(ORB_SMALL_MOTHER_DAMAGE, 0, EntityRef(), MOTHER_HIT_COUNTDOWN); + if (mother) mother->TakeDamage(ORB_SMALL_MOTHER_DAMAGE, 0, EntityRef(), HIT_COUNTDOWN); else small_maggot_spawn(npc.pos, ORB_MAGGOT_HEIGHT, {}, ORB_MAGGOT_RISE - random_unit() * ORB_MAGGOT_RISE_RANGE); return; @@ -2427,7 +2426,7 @@ static void mother_orb_burst(Entity_NPC& npc) if (mother) { if (mother->entityCollisionClass != ENTCOLL_NONE) - mother->TakeDamage(ORB_MEDIUM_MOTHER_DAMAGE, 0, EntityRef(), MOTHER_HIT_COUNTDOWN); + mother->TakeDamage(ORB_MEDIUM_MOTHER_DAMAGE, 0, EntityRef(), HIT_COUNTDOWN); npc_sound_play(SOUND_DEATH_BURST_LARGE, 1, 2, 1); blood_explosion_spawn(4, npc.pos, npc.posOffset, npc.splatColor, vector_scale(npc.velocity, HALF)); game_shake_screen(ORB_MEDIUM_SHAKE); @@ -2446,7 +2445,7 @@ static void mother_orb_burst(Entity_NPC& npc) if (mother) { if (mother->entityCollisionClass != ENTCOLL_NONE) - mother->TakeDamage(ORB_BIG_MOTHER_DAMAGE, 0, EntityRef(), MOTHER_HIT_COUNTDOWN); + mother->TakeDamage(ORB_BIG_MOTHER_DAMAGE, 0, EntityRef(), HIT_COUNTDOWN); spread = ORB_MOTHER_SPREAD; } for (int i = 0; i < ORB_BIG_PIECES; i++) diff --git a/src/boss_mothers_shadow.cpp b/src/boss_mothers_shadow.cpp index 2fcf10d..8e06554 100644 --- a/src/boss_mothers_shadow.cpp +++ b/src/boss_mothers_shadow.cpp @@ -67,8 +67,6 @@ constexpr ColorMod DUST_COLOR = {{0, 0, 0, 1}, {0, 0, 0, 0}, {0, 0, 0}}; constexpr float DUST_DRAG = 0.1f; constexpr float DUST_RISE = -2; constexpr float DUST_RISE_RANGE = 6; -constexpr float SHADOW_DUST_SPIN = 10; -constexpr float SHADOW_DUST_SPIN_MIN = 2; constexpr uint32_t SHADOW_DUST_TIMEOUT_RANGE = 10; constexpr int SHADOW_DUST_TIMEOUT = 10; constexpr float SHADOW_DUST_SCALE = 1.5f; @@ -250,7 +248,7 @@ static void shadow_dust_spawn(Entity_NPC& npc) auto* dust = static_cast(g_game->Spawn( {.position = at, .velocity = velocity, .spawner = &npc, .type = ENTITY_EFFECT, .variant = EFFECT_DUST_CLOUD, .seed = seed})); dust->sprite.GetLayer(0)->color = DUST_COLOR; - dust->rotation = random_unit() * SHADOW_DUST_SPIN + SHADOW_DUST_SPIN_MIN; + dust->rotation = random_between(DUST_SPIN_MIN, DUST_SPIN_RANGE); int timeout = (int)(Random() % SHADOW_DUST_TIMEOUT_RANGE) + SHADOW_DUST_TIMEOUT; dust->timeout = timeout; dust->lifespan = timeout; diff --git a/src/boss_peep.cpp b/src/boss_peep.cpp index 9ed4ea2..bc920fc 100644 --- a/src/boss_peep.cpp +++ b/src/boss_peep.cpp @@ -278,7 +278,7 @@ static void peep_jump_down(Entity_NPC& npc, const ColorMod& bloodColor) for (int i = 0; i < BLOAT_LAND_CREEPS; i++) { uint32_t seed = Random(); - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float reach = random_unit() * BLOAT_LAND_CREEP_REACH; Vector spot = vector_make(std::cos(angle) * reach + npc.pos.x, std::sin(angle) * reach + npc.pos.y); @@ -368,7 +368,7 @@ static void peep_spray(Entity_NPC& npc, const ColorMod& bloodColor) const NullFrame* guide = npc.sprite.animState.GetNullFrame("BloodGuide"); if (!guide || !guide->isVisible) continue; - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; Vector fling = vector_make(std::cos(angle) * guide->scale.x * PEEP_GUIDE_REACH, std::sin(angle) * guide->scale.y * PEEP_GUIDE_REACH); @@ -424,7 +424,7 @@ static void peep_sheet_swap(Entity_NPC& npc, std::string_view suffix) static void peep_bleed(Entity_NPC& npc) { Entity_Effect* splat = npc.MakeSplat(random_unit() * PEEP_SPLAT_SIZE + PEEP_SPLAT_MIN); - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float sine = std::sin(angle); float cosine = std::cos(angle); @@ -447,7 +447,7 @@ static void peep_bleed(Entity_NPC& npc) npc_sound_play(SOUND_PLOP, 1, 2, champion_pitch_get(npc)); npc.i1++; uint32_t seed = Random(); - float turn = random_unit() * RANDOM_HALF_TURN; + float turn = random_unit() * PI_ROUGH; turn += turn; Vector spot = vector_make(std::cos(turn) * PEEP_EYE_REACH + npc.pos.x, std::sin(turn) * PEEP_EYE_REACH + npc.pos.y); diff --git a/src/boss_pestilence.cpp b/src/boss_pestilence.cpp index 576df86..e72b6f9 100644 --- a/src/boss_pestilence.cpp +++ b/src/boss_pestilence.cpp @@ -71,7 +71,7 @@ static void pestilence_splat(Entity_NPC& npc) { float scale = random_unit() * PESTILENCE_SPLAT_SIZE + PESTILENCE_SPLAT_MIN; uint32_t seed = Random(); - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; Vector spot = vector_make(std::cos(angle) * PESTILENCE_SPLAT_REACH + npc.pos.x, std::sin(angle) * PESTILENCE_SPLAT_REACH + npc.pos.y); diff --git a/src/boss_pin.cpp b/src/boss_pin.cpp index 27abf8c..c929fbc 100644 --- a/src/boss_pin.cpp +++ b/src/boss_pin.cpp @@ -144,10 +144,7 @@ constexpr float PHASE_GIB_SPEED_RANGE = 4; constexpr float PHASE_GIB_LIFT = 0.5f; constexpr float PHASE_GIB_SPREAD = 0.5f; constexpr int DEATH_DUST_MIN = 3; -constexpr float PIN_DEATH_DUST_SPEED = 5; constexpr float DEATH_DUST_SPREAD = 20; -constexpr float DEATH_DUST_SPIN_MIN = 2; -constexpr float DEATH_DUST_SPIN_RANGE = 10; constexpr int DEATH_DUST_LIFE_MIN = 15; constexpr int DEATH_DUST_LIFE_RANGE = 15; constexpr float DEATH_DUST_ALPHA_MIN = 0.2f; @@ -850,7 +847,7 @@ static void frail_death_dust(Entity_NPC& npc, const PinChain& chain) for (int i = 0; i < clouds; i++) { Vector heading = random_direction(); - Vector velocity = vector_scale(heading, random_unit() * PIN_DEATH_DUST_SPEED); + Vector velocity = vector_scale(heading, random_unit() * DUST_SPEED); uint32_t seed = Random(); Vector place = random_direction(); Vector position = vector_add(npc.pos, vector_scale(place, random_unit() * DEATH_DUST_SPREAD)); @@ -862,7 +859,7 @@ static void frail_death_dust(Entity_NPC& npc, const PinChain& chain) .seed = seed})); float side = (dust->pos.y - npc.pos.y) * -velocity.x + (dust->pos.x - npc.pos.x) * velocity.y < 0 ? -1.0f : 1.0f; - dust->rotation = (random_unit() * DEATH_DUST_SPIN_RANGE + DEATH_DUST_SPIN_MIN) * side; + dust->rotation = (random_between(DUST_SPIN_MIN, DUST_SPIN_RANGE)) * side; int life = (int)(Random() % DEATH_DUST_LIFE_RANGE) + DEATH_DUST_LIFE_MIN; dust->timeout = life; dust->lifespan = life; diff --git a/src/boss_polycephalus.cpp b/src/boss_polycephalus.cpp index 656a109..8912e8b 100644 --- a/src/boss_polycephalus.cpp +++ b/src/boss_polycephalus.cpp @@ -451,7 +451,7 @@ static void pile_move_pick(Entity_NPC& npc) // A random spot about a center, a fraction of the Pile's reach away. static Vector pile_spot_roll(Vector center) { - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float reach = (random_unit() * PILE_SPOT_REACH_SPREAD + PILE_SPOT_REACH_MIN) * PILE_SPOT_REACH; return vector_make(std::cos(angle) * reach + center.x, std::sin(angle) * reach + center.y); diff --git a/src/boss_pool.cpp b/src/boss_pool.cpp index de8e093..6de4453 100644 --- a/src/boss_pool.cpp +++ b/src/boss_pool.cpp @@ -38,7 +38,6 @@ constexpr int BOSS_REAP_CREEP = 74; constexpr std::array HORSEMEN = {BOSS_FAMINE, BOSS_PESTILENCE, BOSS_WAR, BOSS_DEATH}; // The bosses the dark bosses special daily fixes on stages 1 to 7 (none on stage 6). -constexpr int SPECIAL_DAILY_DARK_BOSSES = 13; constexpr std::array SPECIAL_DAILY_BOSSES = {0, 60, 43, 50, 23, 51, 0, 15}; constexpr int ACHIEVEMENT_HARBINGERS = 5; @@ -249,7 +248,7 @@ int BossPool::GetBossId(int levelStage, int stageType) if (game.challenge == CHALLENGE_APRILS_FOOL) return BOSS_THE_BLOAT; bool isDailyStage = levelStage >= 0 && levelStage < (int)SPECIAL_DAILY_BOSSES.size(); - if (game.dailyChallenge.specialDailyId == SPECIAL_DAILY_DARK_BOSSES && isDailyStage && + if (game.dailyChallenge.specialDailyId == SPECIAL_DAILY_HALLOWEEN && isDailyStage && SPECIAL_DAILY_BOSSES[levelStage] != 0) return SPECIAL_DAILY_BOSSES[levelStage]; if (int boss = chapter_end_boss(levelStage, stageType)) return boss; diff --git a/src/boss_rag_man.cpp b/src/boss_rag_man.cpp index 99f3c8d..d3e0b8c 100644 --- a/src/boss_rag_man.cpp +++ b/src/boss_rag_man.cpp @@ -653,7 +653,7 @@ static void mega_ball_trail(Entity_NPC& npc) .seed = Random()}); smoke->SetColor(npc.sprite.GetLayer(0)->color, -1, COLOR_PRIORITY_DEFAULT, false, true); smoke->velocity = vector_scale(npc.velocity, BALL_TRAIL_BACK); - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float scatter = random_unit() * vector_length(npc.velocity) * BALL_TRAIL_SCATTER; npc_push(*smoke, vector_make(std::cos(angle) * scatter, std::sin(angle) * scatter)); diff --git a/src/boss_repentance.h b/src/boss_repentance.h index 0027e96..27d7097 100644 --- a/src/boss_repentance.h +++ b/src/boss_repentance.h @@ -77,4 +77,27 @@ void chimera_head_update(Entity_NPC& npc); void boss_lil_blub_update(Entity_NPC& npc); void boss_bumbino_update(Entity_NPC& npc); void singe_ball_update(Entity_NPC& npc); + +// A Scourge chain link's states (its tip's: flying, latched onto a wall, drawn back), and the chains' kinds (their +// links' subtype): the trap's pair, the slice's pair and a single slicing chain. +enum ScourgeLinkState +{ + SCOURGE_LINK_FLYING = NPC_STATE_IDLE, + SCOURGE_LINK_LATCHED = NPC_STATE_JUMP, + SCOURGE_LINK_RETRACTING = NPC_STATE_STOMP +}; + +enum ScourgeChainKind +{ + SCOURGE_CHAIN_TRAP, + SCOURGE_CHAIN_SLICE, + SCOURGE_CHAIN_SLICE_ONE +}; + +// The Scourge and its chain (boss_scourge.cpp). +void boss_scourge_update(Entity_NPC& npc); +void scourge_chain_update(Entity_NPC& npc); + +// The Polty and the Kineti (npc_polty.cpp). +void npc_polty_update(Entity_NPC& npc); void clutch_render(Entity_NPC& npc, const Vector& offset); diff --git a/src/boss_rotgut.cpp b/src/boss_rotgut.cpp index c3aa6ba..5a1f964 100644 --- a/src/boss_rotgut.cpp +++ b/src/boss_rotgut.cpp @@ -440,7 +440,7 @@ static void face_shots_update(Entity_NPC& npc, int ticks) // A blood gib thrown from about the face, plain one in five, else rotten. static void face_gib_throw(Entity_NPC& npc) { - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; Vector direction = vector_make(std::cos(angle), std::sin(angle)); float reach = random_unit(); @@ -512,7 +512,7 @@ static void face_rubble_throw(Entity_NPC& npc) Vector velocity = vector_scale(spray, random_between(RUBBLE_SPLASH_SPEED, RUBBLE_SPLASH_SPEED_RANGE)); float rise = std::clamp((float)npc.projectileDelay / FACE_RUBBLE_FRAMES, 0.0f, 1.0f); float lift = random_unit(); - float wobble = random_unit() * RANDOM_HALF_TURN; + float wobble = random_unit() * PI_ROUGH; wobble += wobble; Vector offset = vector_make(std::cos(wobble) * RUBBLE_SPLASH_WOBBLE, RUBBLE_SPLASH_HEIGHT - rise * RUBBLE_SPLASH_RISE - lift * RUBBLE_SPLASH_RISE_RANGE + @@ -557,7 +557,7 @@ static void face_munch_spray(Entity_NPC& npc) { for (int i = 0; i < MUNCH_SPRAY_SHOTS; i++) { - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; Vector direction = vector_make(std::cos(angle), std::sin(angle)); float speed = random_unit() * MUNCH_SPRAY_SPEED; @@ -1190,7 +1190,7 @@ static void rotgut_wall_break(Entity_Effect* timer) for (int i = 0; i < ROTGUT_WALL_ROCKS; i++) { - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float speed = random_unit(); Vector velocity = vector_make(std::cos(angle) * speed * ROTGUT_WALL_ROCK_SPEED, diff --git a/src/boss_satan.cpp b/src/boss_satan.cpp index 672c52e..fa138f4 100644 --- a/src/boss_satan.cpp +++ b/src/boss_satan.cpp @@ -461,7 +461,7 @@ static void dying_update(Entity_NPC& npc) if (sprite.IsEventTriggered("Shoot2")) for (const Vector& spot : DEATH_BURSTS) { - float angle = random_unit() * RANDOM_HALF_TURN * 2; + float angle = random_unit() * PI_ROUGH * 2; uint32_t seed = Random(); Vector position = vector_make(std::cos(angle) * DEATH_BURST_REACH + spot.x + npc.pos.x, std::sin(angle) * DEATH_BURST_REACH + spot.y + npc.pos.y); diff --git a/src/boss_scourge.cpp b/src/boss_scourge.cpp new file mode 100644 index 0000000..395c97a --- /dev/null +++ b/src/boss_scourge.cpp @@ -0,0 +1,1349 @@ +#include "boss_ai.h" +#include "boss_repentance.h" +#include "entity_config.h" +#include "entity_effect.h" +#include "grid_entity.h" +#include "kage_graphics.h" +#include "loot_list.h" +#include "npc_basement.h" +#include "render_passes.h" +#include "room_grid.h" +#include +#include +#include +#include + +// The Scourge's states: hovering after its target, dragging two chains down, slicing, the hover ring, its broccoli +// spit, and drawing its chains back. +enum ScourgeState +{ + SCOURGE_IDLE = NPC_STATE_IDLE, + SCOURGE_HOVER = NPC_STATE_JUMP, + SCOURGE_HOVER_END = NPC_STATE_STOMP, + SCOURGE_TRAP = NPC_STATE_ATTACK, + SCOURGE_RECALL = NPC_STATE_ATTACK2, + SCOURGE_SLICE = NPC_STATE_ATTACK3, + SCOURGE_BROCCOLI = NPC_STATE_ATTACK4 +}; + +// Its attacks, each with its own cooldown (one byte of v2 each, counted down every 10 frames). +enum ScourgeAttack +{ + SCOURGE_ATTACK_NONE, + SCOURGE_ATTACK_TRAP, + SCOURGE_ATTACK_SLICE_BOTH, + SCOURGE_ATTACK_SLICE, + SCOURGE_ATTACK_BROCCOLI, + SCOURGE_ATTACK_HOVER, + SCOURGE_ATTACKS +}; + +constexpr std::array SCOURGE_ATTACK_STATES = { + SCOURGE_IDLE, SCOURGE_TRAP, SCOURGE_SLICE, SCOURGE_SLICE, SCOURGE_BROCCOLI, SCOURGE_HOVER}; +constexpr std::array SCOURGE_ATTACK_COOLDOWNS = {0, 90, 90, 54, 15, 90}; +constexpr float SCOURGE_COOLDOWN_EVERY = 10; +constexpr int SCOURGE_ATTACK_WEIGHT = 10; +constexpr int SCOURGE_REST_WEIGHT = 1; +constexpr float SCOURGE_TRAP_BELOW = 0.95f; +constexpr float SCOURGE_LEAD = 0.1f; +constexpr uint32_t SCOURGE_PICK_SHIFT_1 = 5; +constexpr uint32_t SCOURGE_PICK_SHIFT_2 = 9; +constexpr uint32_t SCOURGE_PICK_SHIFT_3 = 7; + +// Below half health the broccoli spits three times and waits 165 counts (its cooldown less 106, wrapped) to again. +constexpr uint8_t SCOURGE_BROCCOLI_WAIT = 106; +constexpr int SCOURGE_BROCCOLI_SPITS = 3; +constexpr float SCOURGE_ANGRY_HEALTH = 0.5f; + +// The halves of its packed counters: its attack's frames and its idle frames in projectileCooldown, its rise's +// frames and whether it slices one side in projectileDelay. +enum ScourgeHalf +{ + SCOURGE_HALF_LOW, + SCOURGE_HALF_HIGH +}; + +// Idle it hovers 120 over its target, eases toward it at 1.2 (a tenth of the gap, at most 1), and now and then (one +// time in 20) picks another spot 160 to 200 over it within 45 degrees. After 30 idle frames it attacks one time in 10. +constexpr float SCOURGE_HOVER_HEIGHT = -120; +constexpr float SCOURGE_IDLE_FRICTION = 0.8f; +constexpr float SCOURGE_ROOM_MARGIN = 4; +constexpr float SCOURGE_EASE = 0.1f; +constexpr float SCOURGE_IDLE_SPEED = 1.2f; +constexpr uint32_t SCOURGE_SPOT_ODDS = 20; +constexpr float SCOURGE_SPOT_RANGE = 40; +constexpr float SCOURGE_SPOT_HEIGHT = -200; +constexpr float SCOURGE_SPOT_TURN = 90; +constexpr float SCOURGE_SPOT_TURN_MIN = -45; +constexpr int SCOURGE_IDLE_FRAMES = 30; +constexpr uint32_t SCOURGE_ATTACK_ODDS = 10; + +// Attacking it slows by 0.6 a frame. Its death spits a burst from 60 up. +constexpr float SCOURGE_ATTACK_FRICTION = 0.6f; +constexpr float SCOURGE_DEATH_RAISE = -60; +constexpr float SCOURGE_SPLAT_RAISE = -20; + +// The trap: two chains thrown down to either side (4 off its middle), rising 14 frames by at most 4 a frame. Every +// 10 frames it lets go once its target leaves the space between the chains, or after 300 frames. Latched, the chains +// pull it like springs (260 long, 0.1 stiff, 0.1 damped), and it shoots every 30 frames (both chains slicing) or 15 +// (one chain). +constexpr float SCOURGE_TRAP_THROW = 20; +constexpr float SCOURGE_TRAP_OFFSET = 4; +constexpr int SCOURGE_TRAP_RISE = 14; +constexpr float SCOURGE_TRAP_RISE_MAX = 4; +constexpr float SCOURGE_TRAP_CHECK_EVERY = 10; +constexpr int SCOURGE_TRAP_FRAMES = 300; +constexpr float SCOURGE_TRAP_LEVEL = 20; +constexpr int SCOURGE_VOLLEY_EVERY = 30; +constexpr int SCOURGE_CHAIN_SHOT_EVERY = 15; +constexpr float SCOURGE_SPRING_STIFFNESS = 0.1f; +constexpr float SCOURGE_SPRING_DAMPING = 0.1f; +constexpr float SCOURGE_SPRING_LENGTH = 260; + +// The slice: chains thrown at 26 at its target (both ways, or one), then it pulls on them, drifting to the room's +// middle (a 0.05 damped spring), ringing 12 shots at 6 every 30 frames, for 240 frames (60 for one chain). +constexpr float SCOURGE_SLICE_THROW = 26; +constexpr float SCOURGE_SLICE_ONE_FRAME = 15; +constexpr float SCOURGE_CENTER_DAMPING = 0.05f; +constexpr int SCOURGE_SLICE_FRAMES = 240; +constexpr int SCOURGE_SLICE_ONE_FRAMES = 60; +constexpr float SCOURGE_RING_SPEED = 6; +constexpr float SCOURGE_RING_SHOTS = 12; +constexpr float SCOURGE_RING_FALL = -0.12f; + +// The hover: 300 frames drifting to the room's middle (at most 2 a frame) as a ring of shots closes in. Every other +// frame up to 240 a pair of shots appears opposite each other on a circle as wide as the room plus 60 to 80, and every +// 12 a bigger one somewhere on it. The pair's angle turns by a speed that turns toward ±12 at twice its speed, +// reversing one time in 50. Every 6 frames and 3 frames it leaves a puff of its big pull. +constexpr float SCOURGE_HOVER_MAX_STEP = 2; +constexpr int SCOURGE_HOVER_FRAMES = 300; +constexpr int SCOURGE_HOVER_SHOT_FRAMES = 240; +constexpr int SCOURGE_HOVER_BIG_EVERY = 12; +constexpr float SCOURGE_HOVER_RING_OUT = 60; +constexpr float SCOURGE_HOVER_RING_RANGE = 20; +constexpr float SCOURGE_HOVER_TURN = 12; +constexpr uint32_t SCOURGE_HOVER_REVERSE_ODDS = 50; +constexpr int SCOURGE_HOVER_PUFF_EVERY = 6; +constexpr int SCOURGE_HOVER_PUFF_SMALL_EVERY = 3; +constexpr float SCOURGE_HOVER_PUFF_RAISE = -24; +constexpr ColorMod SCOURGE_PUFF_COLOR = {{0.5f, 0.6f, 0.3f, 1}, {0, 0, 0, 0}, {0, 0, 0}}; + +// The hover ring's shots: faded in over 30 frames, homing (0.1) on the room's middle through walls and enemies, +// sized 2/3 to 10/3, and the bigger ones 4/3 and greener. +constexpr uint64_t SCOURGE_RING_FLAGS = + PROJECTILE_HIT_ENEMIES | PROJECTILE_NO_WALL_COLLIDE | PROJECTILE_ACCELERATE_TO_POSITION; +constexpr int SCOURGE_RING_FADE = 30; +constexpr float SCOURGE_RING_SHOT_FALL = -0.05f; +constexpr float SCOURGE_RING_HOMING = 0.1f; +constexpr float SCOURGE_RING_FRICTION = 0.8f; +constexpr float SCOURGE_RING_BIG_FRICTION = 0.99f; +constexpr uint32_t SCOURGE_RING_SIZE_RANGE = 3; +constexpr uint32_t SCOURGE_RING_SIZE_MIN = 5; +constexpr uint32_t SCOURGE_RING_SIZE_MAX = 13; +constexpr float SCOURGE_RING_SIZE_BASE = 3; +constexpr float SCOURGE_RING_BIG_SCALE = 1.3333334f; +constexpr ColorMod SCOURGE_RING_BIG_COLOR = {{1, 1, 1, 1}, {2, 3, 1, 1}, {0, 0, 0}}; + +// The broccoli: on Shoot a sick shot (14, or a smaller 5 below half health) at 14 from 23 up, homing 0.5, the +// Scourge kicked back at 10 for 10 frames (decaying 0.8 a frame) and the screen shaken. While spits are left it +// loops back to frame 30 past frame 56. +constexpr int SCOURGE_BROCCOLI_SHAKE = 7; +constexpr int SCOURGE_BROCCOLI_KICK_FRAMES = 10; +constexpr float SCOURGE_BROCCOLI_KICK = -10; +constexpr float SCOURGE_BROCCOLI_KICK_DECAY = 0.8f; +constexpr float SCOURGE_BROCCOLI_HEIGHT = -23; +constexpr float SCOURGE_BROCCOLI_SPEED = 14; +constexpr float SCOURGE_BROCCOLI_FALL = -0.08f; +constexpr float SCOURGE_BROCCOLI_HOMING = 0.5f; +constexpr int SCOURGE_BROCCOLI_BIG = 14; +constexpr int SCOURGE_BROCCOLI_SMALL = 5; +constexpr float SCOURGE_BROCCOLI_SMALL_SCALE = 0.6f; +constexpr float SCOURGE_BROCCOLI_LOOP_FRAME = 56; +constexpr float SCOURGE_BROCCOLI_LOOP_TO = 30; +constexpr ColorMod SCOURGE_SPIT_COLOR = {{1, 1, 1, 1}, {2, 4, 1, 1}, {0, 0, 0}}; + +// The volleys between latched chains: a fan of shots over the gap (12 per unit of the chains' spread, none within 5 +// degrees of a gap swaying ±10 a time within the fan's ends, 20 in from them and 10 at least) at 4 to 5, and one at +// the target at 8 to 10. Shots on its chains leave at 5 to 6 from a spot one time in five level with the target. +constexpr float SCOURGE_SHOT_RAISE = 10; +constexpr float SCOURGE_SHOT_FALL = -0.14f; +constexpr float SCOURGE_FAN_INSET = 20; +constexpr float SCOURGE_FAN_MIN = 10; +constexpr float SCOURGE_FAN_DENSITY = 0.707f * 12; +constexpr float SCOURGE_GAP_SWAY = 20; +constexpr float SCOURGE_GAP_WIDTH = 5; +constexpr float SCOURGE_FAN_SPEED = 4; +constexpr float SCOURGE_AIMED_SPEED = 8; +constexpr float SCOURGE_CHAIN_SHOT_SPEED = 5; +constexpr uint32_t SCOURGE_CHAIN_SHOT_LEVEL_ODDS = 5; +constexpr float SCOURGE_CHAIN_SHOT_OUT = 4; + +// A chain: 20 links thrown from a point over 10 along its throw. Its tip flies at 10 times its heading a frame (80 at +// most), waving (0.03 per unit of the chain's length). Retracting it shrinks by 0.8 a frame and goes inside 10 or +// below a tenth. +constexpr int SCOURGE_LINKS = 20; +constexpr float SCOURGE_CHAIN_SPAN = 10; +constexpr float SCOURGE_LINK_RAISE = -20; +constexpr float SCOURGE_TIP_FLIGHT = 15; +constexpr float SCOURGE_TIP_WAVE = 0.03f; +constexpr float SCOURGE_TIP_MASS = 1000; +constexpr float SCOURGE_TIP_THRUST = 10; +constexpr float SCOURGE_TIP_SPEED_MAX = 80; +constexpr float SCOURGE_RETRACT_PULL = 0.5f; +constexpr float SCOURGE_RETRACT_SHRINK = 0.8f; +constexpr float SCOURGE_RETRACT_NEAR = 10; +constexpr float SCOURGE_RETRACT_SMALL = 0.1f; +constexpr float SCOURGE_HEAD_DEPTH = 100; +constexpr float SCOURGE_LINK_REACH = 10; + +// The walls a tip latches onto lie 34 past the room's edges (the top and bottom 20 lower), turning its sprite +// (left, top, right, bottom). It hits with a thud, shaking the screen 8, bursting 6 rock pieces at up to 12 (5 fast) +// within 45 degrees, waving 0.06 and shrinking its flight to 22. +constexpr float SCOURGE_WALL_OUT = 34; +constexpr float SCOURGE_WALL_LOWER = 20; +constexpr std::array SCOURGE_WALL_ROTATIONS = {90, 180, -90, 0}; +constexpr int SCOURGE_IMPACT_SHAKE = 8; +constexpr int SCOURGE_IMPACT_PIECES = 6; +constexpr float SCOURGE_PIECE_SPREAD = 45; +constexpr float SCOURGE_PIECE_OUT = 12; +constexpr float SCOURGE_PIECE_SPEED = 5; +constexpr float SCOURGE_BLOOD_RAISE = -10; +constexpr float SCOURGE_BLOOD_RAISE_RANGE = 20; +constexpr float SCOURGE_LATCHED_WAVE = 0.06f; +constexpr float SCOURGE_LATCHED_FLIGHT = 22; +constexpr float SCOURGE_SLIDE_START = -1; + +// A slicing tip crawls along the walls, turning the corners: at up to 13 (1 more a frame), or 24 (1.1 more) for one +// chain, slowing to 0.3 at corners and one time in 30. The chain sags up to 40 (2 a frame) toward its side. Faster +// than 2 it bleeds one time in 6 (3 for one chain), sometimes (one in 3, always for one chain) with a gib and shake +// 4. One chain also leaves green creep at its gib (1.5 big), a splat, a maggot one time in 3 and a sick shot 140 on. +constexpr float SCOURGE_SLIDE_STEP = 1; +constexpr float SCOURGE_SLIDE_MAX = 13; +constexpr float SCOURGE_SLIDE_ONE_STEP = 1.1f; +constexpr float SCOURGE_SLIDE_ONE_MAX = 24; +constexpr uint32_t SCOURGE_SLIDE_SLOW_ODDS = 30; +constexpr float SCOURGE_SLIDE_SLOW = 0.3f; +constexpr float SCOURGE_SAG_STEP = 2; +constexpr float SCOURGE_SAG_MAX = 40; +constexpr float SCOURGE_BLEED_SPEED = 2; +constexpr int SCOURGE_BLEED_ODDS = 6; +constexpr int SCOURGE_BLEED_ONE_ODDS = 3; +constexpr uint32_t SCOURGE_GIB_ODDS = 3; +constexpr int SCOURGE_GIB_SHAKE = 4; +constexpr int SCOURGE_CREEP_SUBTYPE = 100; +constexpr float SCOURGE_CREEP_SCALE = 1.5f; +constexpr float SCOURGE_CREEP_SPOT_RANGE = 60; +constexpr float SCOURGE_CREEP_SPOT_MIN = 20; +constexpr float SCOURGE_SPLAT_SIZE = 1.5f; +constexpr uint32_t SCOURGE_MAGGOT_ODDS = 3; +constexpr float SCOURGE_MAGGOT_MARGIN = 16; +constexpr float SCOURGE_MAGGOT_HEIGHT = -4; +constexpr float SCOURGE_SLIDE_SHOT_REACH = 140; +constexpr float SCOURGE_CHAIN_FRICTION = 0.9f; +constexpr float SCOURGE_LATCHED_DECAY = 0.8f; + +// Links even out their health: any above the weakest takes the difference, and the Scourge a tenth of the most. +constexpr float SCOURGE_HEALTH_UNSET = 10000000000.0f; +constexpr float SCOURGE_SHARED_DAMAGE = 0.1f; +constexpr int SCOURGE_LINK_DAMAGE_COUNTDOWN = 30; + +// The chain's texture strip stops 16 short of its end on a latched trap chain. +constexpr float SCOURGE_STRIP_LATCHED_INSET = 16; + +// A short of a packed counter. +static int16_t scourge_half_get(int field, ScourgeHalf half) +{ + return (int16_t)((uint32_t)field >> (16 * half)); +} + +static void scourge_half_set(int& field, ScourgeHalf half, int value) +{ + uint32_t shift = 16 * (uint32_t)half; + field = (int)(((uint32_t)field & ~(0xffffu << shift)) | ((uint32_t)(uint16_t)value << shift)); +} + +// The attacks' cooldowns, a byte of v2 each. +static uint8_t* scourge_cooldowns(Entity_NPC& npc) +{ + return reinterpret_cast(&npc.v2); +} + +// A link keeps its wave and crawl speed as floats in i1 and i2. +static float link_float_get(int field) +{ + return std::bit_cast(field); +} + +static int link_float_make(float value) +{ + return std::bit_cast(value); +} + +static bool is_scourge_link(Entity* entity) +{ + return entity && entity->type == ENTITY_SCOURGE && entity->variant == SCOURGE_CHAIN; +} + +// (00582a60, 00582a80, 00582aa0) The chain's first link (by parents) and its tip (by children). +static Entity_NPC& link_head_get(Entity_NPC& link) +{ + Entity_NPC* head = &link; + while (is_scourge_link(head->parent.get())) head = static_cast(head->parent.get()); + return *head; +} + +static Entity_NPC& link_tip_get(Entity_NPC& link) +{ + Entity_NPC* tip = &link; + while (is_scourge_link(tip->child.get())) tip = static_cast(tip->child.get()); + return *tip; +} + +// (00582ad0, 00582b00) Whether a chain's tip has latched onto a wall, and where it is. +static bool chain_is_latched(Entity* chain) +{ + return link_tip_get(*static_cast(chain)).state == SCOURGE_LINK_LATCHED; +} + +static Vector chain_tip_position(Entity* chain) +{ + return link_tip_get(*static_cast(chain)).pos; +} + +// 00582b40 The Scourge's child when it is a chain. +static Entity* scourge_child_chain(Entity_NPC& npc) +{ + return is_scourge_link(npc.child.get()) ? npc.child.get() : nullptr; +} + +// 00583110 Flips a chain's first link and tip to a side. +static void chain_flip_set(Entity* chain, bool isFlipped) +{ + if (!chain) return; + auto& link = *static_cast(chain); + link_head_get(link).sprite.isFlipX = isFlipped; + link_tip_get(link).sprite.isFlipX = isFlipped; +} + +// 005830e0 Stops a chain's tip crawling. +static void chain_crawl_stop(Entity* chain) +{ + link_tip_get(*static_cast(chain)).i2 = link_float_make(0); +} + +// 00586b50 Pulls the Scourge toward a point like a spring of a length and stiffness, damped. +static void scourge_spring_pull(Entity_NPC& npc, Vector anchor, Vector spring, float damping) +{ + Vector away = vector_sub(npc.pos, anchor); + float length = vector_length(away); + if (length > 0) away = vector_scale(away, 1 / length); + float stretch = length - spring.x; + npc.velocity.x -= (stretch * away.x * spring.y + npc.velocity.x * damping) * npc.speedMultiplier; + npc.velocity.y -= (stretch * away.y * spring.y + npc.velocity.y * damping) * npc.speedMultiplier; +} + +// A splash of the Scourge's green blood, a size up. +static void scourge_splash(int subType, const Vector& position, float raise) +{ + blood_explosion_spawn(subType, position, vector_make(0, raise), COLOR_GREEN_SPLAT, {}); +} + +// A shot of its volleys: lower, falling slowly upward, fiery. +static ProjectileParams scourge_shot_params(uint64_t flags) +{ + ProjectileParams params; + params.heightModifier += SCOURGE_SHOT_RAISE; + params.fallingAccelModifier += SCOURGE_SHOT_FALL; + params.color = SHOT_COLOR_FIERY; + params.bulletFlags = flags; + return params; +} + +// A chain thrown (NpcHelper::scourge_spawn_chain's arguments): from where at what velocity, its kind (its links' +// subtype), the entity it hangs from and its first link's offset from it. +struct ScourgeChainThrow +{ + Vector position{}; + Vector velocity{}; + Vector offset{}; + Entity* parent = nullptr; + int kind = SCOURGE_CHAIN_TRAP; +}; + +// 00582b60 Throws a chain of 20 links strung from a point along its throw, its tip flying off, its first link +// hanging from its parent and whipping. Returns the first link. +static Entity_NPC* scourge_chain_spawn(const ScourgeChainThrow& chainThrow) +{ + Vector span = vector_sub(vector_add(vector_scale(vector_normalized(chainThrow.velocity), SCOURGE_CHAIN_SPAN), + chainThrow.position), + chainThrow.position); + std::vector links; + Entity_NPC* previous = nullptr; + + for (int index = SCOURGE_LINKS - 1; index >= 0; index--) + { + float share = (float)index / (float)(SCOURGE_LINKS - 1); + Vector at = vector_make(span.x * share + chainThrow.position.x, span.y * share + chainThrow.position.y); + uint32_t seed = Random(); + auto* link = static_cast(g_game->Spawn( + {.position = at, .subType = chainThrow.kind, .type = ENTITY_SCOURGE, .variant = SCOURGE_CHAIN, .seed = seed})); + link->projectileDelay = index; + link->projectileCooldown = SCOURGE_LINKS; + link->ClearEntityFlags(FLAG_APPEAR); + if (previous) + { + link->child = previous; + previous->parent = link; + } + link->posOffset.y = SCOURGE_LINK_RAISE; + previous = link; + links.push_back(link); + } + + Entity_NPC& tip = *links.front(); + tip.velocity = chainThrow.velocity; + tip.targetPosition = vector_normalized(chainThrow.velocity); + tip.aiFloat = SCOURGE_TIP_FLIGHT; + tip.i1 = link_float_make(SCOURGE_TIP_WAVE); + + Entity_NPC& head = *links.back(); + head.parent = chainThrow.parent; + head.v1 = chainThrow.offset; + head.sprite.Play(chainThrow.kind == SCOURGE_CHAIN_TRAP ? "Whip1" : "Whip2"); + for (Entity_NPC* link : links) link->Update(); + return &head; +} + +// 00582f60 Draws a chain back: its tip retracts, its first link whips again with a crack. +static void scourge_whip(Entity_NPC& chain) +{ + Entity_NPC& tip = link_tip_get(chain); + tip.state = SCOURGE_LINK_RETRACTING; + tip.targetPosition = {}; + link_head_get(chain).sprite.Play(chain.subtype == SCOURGE_CHAIN_TRAP ? "Whip1" : "Whip2"); + npc_sound_play(SOUND_MEAT_JUMPS, 1, 2, champion_pitch_get(chain)); +} + +// 00583170 A chain broken off its ends (its first link not first, its tip not last, or its owner gone) falls apart: +// every link but the last is killed. +static void scourge_chain_check(Entity_NPC& link) +{ + Entity_NPC& head = link_head_get(link); + Entity_NPC& tip = link_tip_get(link); + Entity* owner = head.parent.get(); + bool isWhole = head.projectileDelay == 0 && tip.projectileDelay == link.projectileCooldown - 1 && owner && !owner->isDead; + if (isWhole) return; + + for (Entity_NPC* each = &head; is_scourge_link(each->child.get()); each = static_cast(each->child.get())) + each->Kill(EntityRef()); +} + +// 005864b0 Picks its next attack by weight among those cooled down: the trap with its target (led by its speed) +// right below, slices with it lower, the broccoli and the hover always, resting the least. +static void scourge_attack_pick(Entity_NPC& npc) +{ + Entity* target = npc.GetPlayerTarget(); + Vector targetPos = target->pos; + Vector targetVelocity = npc.GetPlayerTarget()->velocity; + float distance = vector_distance(npc.pos, targetPos); + Vector lead = vector_make(targetVelocity.x * distance * SCOURGE_LEAD + targetPos.x, + targetVelocity.y * distance * SCOURGE_LEAD + targetPos.y); + uint8_t* cooldowns = scourge_cooldowns(npc); + bool isBelow = npc.pos.y < lead.y; + + WeightedOutcomePicker picker; + if (cooldowns[SCOURGE_ATTACK_TRAP] == 0) + { + Vector toward = vector_sub(lead, npc.pos); + float length = vector_length(toward); + float down = length <= 0 ? toward.y : toward.y * (1 / length); + if (down > SCOURGE_TRAP_BELOW) picker.AddOutcomeWeight(SCOURGE_ATTACK_TRAP, SCOURGE_ATTACK_WEIGHT); + } + if (cooldowns[SCOURGE_ATTACK_SLICE_BOTH] == 0 && isBelow) + picker.AddOutcomeWeight(SCOURGE_ATTACK_SLICE_BOTH, SCOURGE_ATTACK_WEIGHT); + if (cooldowns[SCOURGE_ATTACK_SLICE] == 0 && isBelow) picker.AddOutcomeWeight(SCOURGE_ATTACK_SLICE, SCOURGE_ATTACK_WEIGHT); + if (cooldowns[SCOURGE_ATTACK_BROCCOLI] == 0) picker.AddOutcomeWeight(SCOURGE_ATTACK_BROCCOLI, SCOURGE_ATTACK_WEIGHT); + if (cooldowns[SCOURGE_ATTACK_HOVER] == 0) picker.AddOutcomeWeight(SCOURGE_ATTACK_HOVER, SCOURGE_ATTACK_WEIGHT); + picker.AddOutcomeWeight(SCOURGE_ATTACK_NONE, SCOURGE_REST_WEIGHT); + + int attack = picker.PickOutcome({Random() | 1, SCOURGE_PICK_SHIFT_1, SCOURGE_PICK_SHIFT_2, SCOURGE_PICK_SHIFT_3}); + if (attack == SCOURGE_ATTACK_NONE) return; + + npc.state = SCOURGE_ATTACK_STATES[attack]; + cooldowns[attack] = SCOURGE_ATTACK_COOLDOWNS[attack]; + scourge_half_set(npc.projectileDelay, SCOURGE_HALF_LOW, -1); + scourge_half_set(npc.projectileCooldown, SCOURGE_HALF_LOW, -1); + scourge_half_set(npc.projectileDelay, SCOURGE_HALF_HIGH, 0); + + switch (attack) + { + case SCOURGE_ATTACK_TRAP: + npc.sprite.Play("TrapDown"); + break; + case SCOURGE_ATTACK_SLICE_BOTH: + npc.sprite.Play("SliceBoth"); + break; + case SCOURGE_ATTACK_SLICE: + scourge_half_set(npc.projectileDelay, SCOURGE_HALF_HIGH, 1); + npc.sprite.Play(npc.pos.x < lead.x ? "SliceRight" : "SliceLeft"); + break; + case SCOURGE_ATTACK_BROCCOLI: + npc.sprite.Play("BroccoliAttack"); + if (npc.health / npc.maxHitPoints >= SCOURGE_ANGRY_HEALTH) npc.i1 = 1; + else + { + npc.i1 = SCOURGE_BROCCOLI_SPITS; + cooldowns[attack] -= SCOURGE_BROCCOLI_WAIT; + } + break; + case SCOURGE_ATTACK_HOVER: + { + npc.sprite.Play("HoverStart"); + scourge_half_set(npc.projectileCooldown, SCOURGE_HALF_LOW, 0); + npc.vectorDeque1[0].x = random_unit() * FULL_TURN_DEGREES; + npc.vectorDeque1[1].x = (Random() & 1) == 0 ? -SCOURGE_HOVER_TURN : SCOURGE_HOVER_TURN; + npc.vectorDeque1[0].y = npc.vectorDeque1[1].x; + break; + } + } +} + +// 00586c40 A volley between its latched chains: a fan over the space between them, leaving a gap that sways about, +// and a shot at its target. +static void scourge_volley(Entity_NPC& npc) +{ + Vector first = vector_sub(chain_tip_position(npc.child.get()), npc.pos); + Vector second = vector_sub(chain_tip_position(npc.entityRef.get()), npc.pos); + first = vector_normalized(first); + second = vector_normalized(second); + float spread = angle_wrapped(vector_angle(first) - vector_angle(second)); + float half = std::max(std::abs(spread * HALF) - SCOURGE_FAN_INSET, SCOURGE_FAN_MIN); + Vector across = vector_sub(second, first); + int shots = std::max((int)(vector_length(across) * SCOURGE_FAN_DENSITY), 1) + 1; + Random(); + + float gap = std::clamp((random_unit() - HALF) * SCOURGE_GAP_SWAY + npc.vectorDeque1[1].y, -half, half); + for (int shot = 1; shot < shots; shot++) + { + float share = (float)shot / (float)shots; + if (std::abs(((half + half) * share - half) - gap) <= SCOURGE_GAP_WIDTH) continue; + + ProjectileParams params = scourge_shot_params(0); + float speed = random_unit() + SCOURGE_FAN_SPEED; + Vector velocity = vector_make((across.x * share + first.x) * speed, (across.y * share + first.y) * speed); + npc.FireProjectiles(npc.pos, velocity, PROJECTILES_SINGLE, params); + } + + Vector aim = vector_normalized(vector_sub(npc.GetPlayerTarget()->pos, npc.pos)); + ProjectileParams params = scourge_shot_params(0); + float speed = random_unit(); + speed = speed + speed + SCOURGE_AIMED_SPEED; + npc.FireProjectiles(npc.pos, vector_scale(aim, speed), PROJECTILES_SINGLE, params); + npc.vectorDeque1[1].y = gap; + scourge_splash(2, npc.pos, SCOURGE_SPLAT_RAISE); + npc_sound_play(SOUND_BLOODSHOOT, 1, 2, champion_pitch_get(npc)); +} + +// 00587480 Shots along its latched chains: two, each from a spot on one chain toward the other, at random spots or +// one time in five level with its target. +static void scourge_chain_shoot(Entity_NPC& npc) +{ + Vector first = vector_sub(chain_tip_position(npc.child.get()), npc.pos); + Vector second = vector_sub(chain_tip_position(npc.entityRef.get()), npc.pos); + Vector toTarget = vector_sub(npc.GetPlayerTarget()->pos, npc.pos); + Vector along = vector_normalized(vector_sub(second, first)); + float onto = -first.y * along.y - first.x * along.x; + Vector nearest = vector_make(onto * along.x + first.x, onto * along.y + first.y); + float level = (nearest.y * toTarget.y + nearest.x * toTarget.x) / (nearest.y * nearest.y + nearest.x * nearest.x); + + for (int side = 0; side < 2; side++) + { + float share = Random() % SCOURGE_CHAIN_SHOT_LEVEL_ODDS == 0 ? level : random_unit(); + Vector onFirst = vector_make(first.x * share + npc.pos.x, first.y * share + npc.pos.y); + Vector onSecond = vector_make(second.x * share + npc.pos.x, second.y * share + npc.pos.y); + Vector from = side == 0 ? onSecond : onFirst; + Vector direction = vector_normalized(side == 0 ? vector_sub(onFirst, onSecond) : vector_sub(onSecond, onFirst)); + + ProjectileParams params = scourge_shot_params(PROJECTILE_NO_WALL_COLLIDE); + float speed = random_unit() + SCOURGE_CHAIN_SHOT_SPEED; + npc.FireProjectiles(from, vector_scale(direction, speed), PROJECTILES_SINGLE, params); + scourge_splash(1, vector_add(vector_scale(direction, SCOURGE_CHAIN_SHOT_OUT), from), SCOURGE_SPLAT_RAISE); + } + npc_sound_play(SOUND_BLOODSHOOT, 1, 2, champion_pitch_get(npc)); +} + +// Its idle: easing toward its spot over its target, facing it, attacking now and then. +static void scourge_idle(Entity_NPC& npc, int ticks) +{ + npc.friction *= SCOURGE_IDLE_FRICTION; + Vector spot = g_game->room->GetClampedPositionImpl(vector_add(npc.GetPlayerTarget()->pos, npc.v1), SCOURGE_ROOM_MARGIN, + SCOURGE_ROOM_MARGIN, SCOURGE_ROOM_MARGIN, SCOURGE_ROOM_MARGIN); + Vector step = vector_scale(vector_sub(spot, npc.pos), SCOURGE_EASE); + float length = vector_length(step); + if (length > 1 && length > 0) step = vector_scale(step, 1 / length); + npc.velocity = vector_add(npc.velocity, vector_scale(step, SCOURGE_IDLE_SPEED * npc.speedMultiplier)); + + Vector toTarget = vector_sub(npc.GetPlayerTarget()->pos, npc.pos); + const AnimationData* data = npc.sprite.animState.animData; + bool isIdling = data && npc.sprite.animState.isPlaying && data->name.starts_with("Idle"); + if (!isIdling) npc.sprite.Play("Idle"); + bool isSideways = std::abs(toTarget.x) > std::abs(toTarget.y) && toTarget.y > 0; + std::string_view facing = !isSideways ? "Idle" : toTarget.x >= 0 ? "IdleRight" : "IdleLeft"; + npc.sprite.SetAnimation(facing, SWITCH_KEEP_FRAME); + + if (Random() % SCOURGE_SPOT_ODDS == 0) + { + float height = random_unit() * SCOURGE_SPOT_RANGE + SCOURGE_SPOT_HEIGHT; + float turn = random_unit() * SCOURGE_SPOT_TURN + SCOURGE_SPOT_TURN_MIN; + npc.v1 = vector_rotated(vector_make(0, height), turn); + } + + int idleFrames = scourge_half_get(npc.projectileCooldown, SCOURGE_HALF_HIGH) + ticks; + scourge_half_set(npc.projectileCooldown, SCOURGE_HALF_HIGH, idleFrames); + if (scourge_half_get(npc.projectileCooldown, SCOURGE_HALF_HIGH) > SCOURGE_IDLE_FRAMES && Random() % SCOURGE_ATTACK_ODDS == 0) + scourge_attack_pick(npc); +} + +// A shot of the hover ring on its circle, closing in on the middle. +static Entity_Projectile* scourge_ring_shot(Entity_NPC& npc, const Vector& position, const Vector& center, + const ColorMod& color) +{ + uint32_t seed = Random(); + auto* shot = static_cast( + g_game->Spawn({.position = position, .spawner = &npc, .type = ENTITY_PROJECTILE, .seed = seed})); + ColorMod faded = color; + faded._tint[3] = 0; + shot->SetColor(color, -1, COLOR_PRIORITY_DEFAULT, false, true); + shot->SetColor(faded, SCOURGE_RING_FADE, COLOR_PRIORITY_DEFAULT, true, true); + shot->parent = &npc; + shot->targetPosition = center; + shot->projectileFlags = SCOURGE_RING_FLAGS; + shot->fallingAccel = SCOURGE_RING_SHOT_FALL; + shot->homingStrength = SCOURGE_RING_HOMING; + return shot; +} + +// A puff of its big pull at it, small or big. +static void scourge_puff(Entity_NPC& npc, int subType) +{ + uint32_t seed = Random(); + Entity* puff = g_game->Spawn({.position = npc.pos, .subType = subType, .type = ENTITY_EFFECT, .variant = EFFECT_BIG_ATTRACT, .seed = seed}); + puff->posOffset = vector_make(0, SCOURGE_HOVER_PUFF_RAISE); + puff->SetColor(SCOURGE_PUFF_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); + puff->Update(); +} + +// A frame of the hover ring: a pair of shots on the circle (and now and then a bigger one), the pair's angle turning. +static void scourge_ring_update(Entity_NPC& npc, const Vector& center, int frame) +{ + Room& room = *g_game->room; + float radius = vector_distance(center, room.topLeftPos); + radius = random_unit() * SCOURGE_HOVER_RING_RANGE + radius + SCOURGE_HOVER_RING_OUT; + Vector out = vector_scale(vector_from_angle(npc.vectorDeque1[0].x), radius); + for (float side : {-1.0f, 1.0f}) + { + Entity_Projectile* shot = scourge_ring_shot(npc, vector_add(vector_scale(out, side), center), center, COLOR_GREEN_SPLAT); + uint32_t size = std::min(Random() % SCOURGE_RING_SIZE_RANGE + SCOURGE_RING_SIZE_MIN, SCOURGE_RING_SIZE_MAX); + shot->friction = SCOURGE_RING_FRICTION; + shot->scale = ((float)size - SCOURGE_RING_SIZE_BASE) / SCOURGE_RING_SIZE_BASE; + } + if (frame % SCOURGE_HOVER_BIG_EVERY == 0) + { + Vector spot = vector_add(vector_scale(vector_from_angle(random_unit() * FULL_TURN_DEGREES), radius), center); + Entity_Projectile* shot = scourge_ring_shot(npc, spot, center, SCOURGE_RING_BIG_COLOR); + shot->scale = SCOURGE_RING_BIG_SCALE; + shot->friction = SCOURGE_RING_BIG_FRICTION; + } + + npc.vectorDeque1[0].x = angle_wrapped(npc.vectorDeque1[0].y + npc.vectorDeque1[0].x); + npc.vectorDeque1[0].y = angle_approach(npc.vectorDeque1[0].y, npc.vectorDeque1[1].x, npc.speedMultiplier + npc.speedMultiplier); + if (Random() % SCOURGE_HOVER_REVERSE_ODDS == 0) npc.vectorDeque1[1].x = -npc.vectorDeque1[1].x; +} + +// Its hover: drifting to the room's middle while the ring closes in, puffing, for 300 frames. +static void scourge_hover(Entity_NPC& npc, const Vector& center, int ticks) +{ + npc.friction *= SCOURGE_ATTACK_FRICTION; + Vector step = vector_scale(vector_sub(center, npc.pos), SCOURGE_EASE); + if (vector_length(step) > SCOURGE_HOVER_MAX_STEP) step = vector_scale(vector_normalized(step), SCOURGE_HOVER_MAX_STEP); + npc.velocity = vector_add(npc.velocity, vector_scale(step, npc.speedMultiplier)); + + if (scourge_half_get(npc.projectileCooldown, SCOURGE_HALF_LOW) >= 0) + for (int tick = ticks; tick > 0; tick--) + { + int frame = scourge_half_get(npc.projectileCooldown, SCOURGE_HALF_LOW); + if (frame % 2 == 0 && frame <= SCOURGE_HOVER_SHOT_FRAMES) scourge_ring_update(npc, center, frame); + + frame = (int16_t)(frame + 1); + scourge_half_set(npc.projectileCooldown, SCOURGE_HALF_LOW, frame); + if (frame >= SCOURGE_HOVER_FRAMES) + { + npc.sprite.Play("HoverEnd"); + npc.state = SCOURGE_HOVER_END; + continue; + } + if (frame % SCOURGE_HOVER_PUFF_EVERY == 0) scourge_puff(npc, 0); + if (frame % SCOURGE_HOVER_PUFF_SMALL_EVERY == 0) scourge_puff(npc, 1); + } + if (!npc.sprite.animState.animData || !npc.sprite.animState.isPlaying) npc.sprite.Play("HoverLoop"); +} + +// Lets go of both chains and draws them back. +static void scourge_recall(Entity_NPC& npc) +{ + npc.state = SCOURGE_RECALL; + scourge_half_set(npc.projectileCooldown, SCOURGE_HALF_LOW, -1); + if (npc.child) scourge_whip(*static_cast(npc.child.get())); + if (npc.entityRef) scourge_whip(*static_cast(npc.entityRef.get())); + npc.sprite.Play("TrapEndDown"); +} + +// Whether its target stands between its two latched chains, as seen from it. +static bool scourge_is_target_trapped(Entity_NPC& npc, const Vector& target) +{ + Vector toTarget = vector_sub(target, npc.pos); + Vector first = vector_sub(chain_tip_position(npc.child.get()), npc.pos); + Vector second = vector_sub(chain_tip_position(npc.entityRef.get()), npc.pos); + return toTarget.x * first.y - toTarget.y * first.x >= 0 && toTarget.x * second.y - toTarget.y * second.x <= 0; +} + +// The trap: its chains thrown down, rising, shooting between them while its target stays trapped. +static void scourge_trap(Entity_NPC& npc, int ticks) +{ + npc.friction *= SCOURGE_ATTACK_FRICTION; + if (npc.sprite.IsEventTriggered("Sound")) npc.PlaySound(SOUND_SKIN_PULL, 1, 2, false, 1); + + int rise = scourge_half_get(npc.projectileDelay, SCOURGE_HALF_LOW); + bool isShooting = npc.sprite.IsEventTriggered("Shoot"); + if (isShooting) + { + npc.PlaySound(SOUND_WHIP, 1, 2, false, 1); + npc.child = scourge_chain_spawn({.position = npc.pos, + .velocity = vector_make(-SCOURGE_TRAP_THROW, SCOURGE_TRAP_THROW), + .offset = vector_make(-SCOURGE_TRAP_OFFSET, 0), + .parent = &npc}); + npc.entityRef = scourge_chain_spawn({.position = npc.pos, + .velocity = vector_make(SCOURGE_TRAP_THROW, SCOURGE_TRAP_THROW), + .offset = vector_make(SCOURGE_TRAP_OFFSET, 0), + .parent = &npc}); + rise = SCOURGE_TRAP_RISE; + } + if (isShooting || rise > 0) + { + rise = std::max(rise - ticks, 0); + scourge_half_set(npc.projectileDelay, SCOURGE_HALF_LOW, rise); + npc.velocity.y -= std::min((float)(int16_t)rise, SCOURGE_TRAP_RISE_MAX); + } + if (!npc.sprite.animState.animData || !npc.sprite.animState.isPlaying) + { + npc.sprite.Play("TrapLoopDown"); + rise = scourge_half_get(npc.projectileDelay, SCOURGE_HALF_LOW); + } + + if ((int16_t)rise >= 0) + { + bool isLost = !npc.child || !npc.entityRef || scourge_half_get(npc.projectileCooldown, SCOURGE_HALF_LOW) > SCOURGE_TRAP_FRAMES; + if (!isLost && npc.GetIntervalTicks(SCOURGE_TRAP_CHECK_EVERY, 0)) + { + Vector target = npc.GetPlayerTarget()->pos; + isLost = chain_is_latched(npc.child.get()) && chain_is_latched(npc.entityRef.get()) && + !scourge_is_target_trapped(npc, target); + } + if (isLost) scourge_recall(npc); + else if (scourge_half_get(npc.projectileCooldown, SCOURGE_HALF_LOW) < 0 && chain_is_latched(npc.child.get()) && + chain_is_latched(npc.entityRef.get())) + { + scourge_half_set(npc.projectileCooldown, SCOURGE_HALF_LOW, 0); + npc.vectorDeque1[1].y = 0; + int isSingle = (int)(Random() & 1); + if (std::abs(npc.child->pos.y - npc.entityRef->pos.y) > SCOURGE_TRAP_LEVEL) isSingle = 0; + scourge_half_set(npc.projectileDelay, SCOURGE_HALF_HIGH, isSingle); + } + } + + int frame = scourge_half_get(npc.projectileCooldown, SCOURGE_HALF_LOW); + if (frame >= 0) + { + int next = (int16_t)(frame + ticks); + scourge_half_set(npc.projectileCooldown, SCOURGE_HALF_LOW, next); + int previous = next - ticks; + bool isBoth = npc.child && npc.entityRef; + bool isSingle = scourge_half_get(npc.projectileDelay, SCOURGE_HALF_HIGH) != 0; + if (!isSingle && previous / SCOURGE_VOLLEY_EVERY < next / SCOURGE_VOLLEY_EVERY && isBoth) scourge_volley(npc); + else if (isSingle && previous / SCOURGE_CHAIN_SHOT_EVERY < next / SCOURGE_CHAIN_SHOT_EVERY && isBoth) + scourge_chain_shoot(npc); + } + + // The original reads an unset register for the springs' length, clamped to 260 to 400. Its usual small value + // gives 260. + for (Entity* chain : {npc.child.get(), npc.entityRef.get()}) + if (chain && chain_is_latched(chain)) + scourge_spring_pull(npc, chain_tip_position(chain), vector_make(SCOURGE_SPRING_LENGTH, SCOURGE_SPRING_STIFFNESS), + SCOURGE_SPRING_DAMPING); +} + +// The slice's throw on Shoot: both chains at its target and away, or one, each flipped to a random side. +static void scourge_slice_throw(Entity_NPC& npc) +{ + Vector direction = vector_normalized(vector_sub(npc.targetPosition, npc.pos)); + bool isFlipped = Random() & 1; + npc.PlaySound(SOUND_WHIP, 1, 2, false, 1); + if (scourge_half_get(npc.projectileDelay, SCOURGE_HALF_HIGH) == 0) + { + npc.child = scourge_chain_spawn({.position = npc.pos, + .velocity = vector_scale(direction, SCOURGE_SLICE_THROW), + .parent = &npc, + .kind = SCOURGE_CHAIN_SLICE}); + chain_flip_set(scourge_child_chain(npc), isFlipped); + npc.entityRef = scourge_chain_spawn({.position = npc.pos, + .velocity = vector_scale(direction, -SCOURGE_SLICE_THROW), + .parent = &npc, + .kind = SCOURGE_CHAIN_SLICE}); + chain_flip_set(is_scourge_link(npc.entityRef.get()) ? npc.entityRef.get() : nullptr, isFlipped); + } + else + { + npc.child = scourge_chain_spawn({.position = npc.pos, + .velocity = vector_scale(direction, SCOURGE_SLICE_THROW), + .parent = &npc, + .kind = SCOURGE_CHAIN_SLICE_ONE}); + chain_flip_set(scourge_child_chain(npc), isFlipped); + } + scourge_half_set(npc.projectileDelay, SCOURGE_HALF_LOW, 0); +} + +// The slice: thrown chains, then pulled along the walls once latched, ringing shots, drifting to the middle. +static void scourge_slice(Entity_NPC& npc, const Vector& center, int ticks) +{ + npc.friction *= SCOURGE_ATTACK_FRICTION; + bool isSingle = scourge_half_get(npc.projectileDelay, SCOURGE_HALF_HIGH) != 0; + if (scourge_half_get(npc.projectileCooldown, SCOURGE_HALF_LOW) < 0) + { + if (npc.sprite.IsEventTriggered("Sound")) + { + npc.PlaySound(SOUND_SKIN_PULL, 1, 2, false, 1); + npc.targetPosition = npc.GetPlayerTarget()->pos; + } + if (npc.sprite.IsEventTriggered("Shoot")) scourge_slice_throw(npc); + else if (scourge_half_get(npc.projectileDelay, SCOURGE_HALF_LOW) < 0) return; + + Entity* first = npc.child.get(); + Entity* second = npc.entityRef.get(); + bool isLatched = (first || second) && (!first || chain_is_latched(first)) && (!second || chain_is_latched(second)); + if (isLatched) + { + scourge_half_set(npc.projectileCooldown, SCOURGE_HALF_LOW, 0); + Entity* shown = first ? first : second; + npc.sprite.Play(shown->sprite.isFlipX ? "SlicePullLeft" : "SlicePullRight"); + if (isSingle && npc.sprite.animState.animData) npc.sprite.animState.SetFrameFloat(SCOURGE_SLICE_ONE_FRAME); + } + } + else + { + if (npc.sprite.IsEventTriggered("Shoot")) + { + if (npc.child) chain_crawl_stop(npc.child.get()); + if (npc.entityRef) chain_crawl_stop(npc.entityRef.get()); + } + Entity* shown = npc.child ? npc.child.get() : npc.entityRef.get(); + if ((!npc.sprite.animState.animData || !npc.sprite.animState.isPlaying) && shown) + npc.sprite.Play(shown->sprite.isFlipX ? "SlicePullLoopLeft" : "SlicePullLoopRight"); + + for (int tick = ticks; tick > 0; tick--) + { + int frame = (int16_t)(scourge_half_get(npc.projectileCooldown, SCOURGE_HALF_LOW) + 1); + scourge_half_set(npc.projectileCooldown, SCOURGE_HALF_LOW, frame); + if (isSingle || frame < SCOURGE_VOLLEY_EVERY || frame % SCOURGE_VOLLEY_EVERY != 0) continue; + + ProjectileParams params; + params.color = SHOT_COLOR_FIERY; + params.fallingAccelModifier = SCOURGE_RING_FALL; + npc.FireProjectiles(npc.pos, vector_make(SCOURGE_RING_SPEED, SCOURGE_RING_SHOTS), PROJECTILES_RING, params); + scourge_splash(2, npc.pos, SCOURGE_SPLAT_RAISE); + npc_sound_play(SOUND_BLOODSHOOT, 1, 2, champion_pitch_get(npc)); + } + } + + if (scourge_half_get(npc.projectileDelay, SCOURGE_HALF_LOW) < 0) return; + scourge_spring_pull(npc, center, vector_make(0, SCOURGE_SPRING_STIFFNESS), SCOURGE_CENTER_DAMPING); + int limit = isSingle ? SCOURGE_SLICE_ONE_FRAMES : SCOURGE_SLICE_FRAMES; + if (scourge_half_get(npc.projectileCooldown, SCOURGE_HALF_LOW) > limit || (!npc.child && !npc.entityRef)) scourge_recall(npc); +} + +// The broccoli: its spit (once, or three times below half health) kicking it back. +static void scourge_broccoli(Entity_NPC& npc, int ticks) +{ + npc.friction *= SCOURGE_ATTACK_FRICTION; + if (npc.sprite.IsEventTriggered("Sound")) + { + int count = (int16_t)(scourge_half_get(npc.projectileCooldown, SCOURGE_HALF_LOW) + 1); + scourge_half_set(npc.projectileCooldown, SCOURGE_HALF_LOW, count); + if (count == 0 || count == 2) npc.PlaySound(SOUND_MEAT_JUMPS, 1, 2, false, 1); + else if (count == 1) npc.PlaySound(SOUND_ANIMAL_SQUISH, 1, 2, false, 1); + } + if (npc.sprite.IsEventTriggered("Shoot")) + { + npc.PlaySound(SOUND_MEATHEADSHOOT, 1, 2, false, 1); + npc.PlaySound(SOUND_HEARTOUT, 1, 2, false, 1); + game_shake_screen(SCOURGE_BROCCOLI_SHAKE); + scourge_half_set(npc.projectileDelay, SCOURGE_HALF_LOW, SCOURGE_BROCCOLI_KICK_FRAMES); + Vector aim = vector_normalized(vector_sub(npc.GetPlayerTarget()->pos, npc.pos)); + npc.targetPosition = vector_scale(aim, SCOURGE_BROCCOLI_KICK); + + ProjectileParams params; + params.color = COLOR_GREEN_SPLAT; + params.bulletFlags = PROJECTILE_BROCCOLI; + Entity_Projectile* shot = npc.FireBossProjectiles(1, {}, 0, params); + shot->height = SCOURGE_BROCCOLI_HEIGHT; + shot->velocity = vector_scale(aim, SCOURGE_BROCCOLI_SPEED); + shot->fallingAccel = SCOURGE_BROCCOLI_FALL; + shot->fallingSpeed = 0; + shot->homingStrength = SCOURGE_BROCCOLI_HOMING; + bool isHealthy = npc.health / npc.maxHitPoints >= SCOURGE_ANGRY_HEALTH; + shot->subtype = isHealthy ? SCOURGE_BROCCOLI_BIG : SCOURGE_BROCCOLI_SMALL; + shot->scale = isHealthy ? 1 : SCOURGE_BROCCOLI_SMALL_SCALE; + blood_explosion_spawn(4, npc.pos, vector_make(0, SCOURGE_SPLAT_RAISE), SCOURGE_SPIT_COLOR, {}); + npc.i1--; + } + + int kick = scourge_half_get(npc.projectileDelay, SCOURGE_HALF_LOW); + if (kick > 0) + { + scourge_half_set(npc.projectileDelay, SCOURGE_HALF_LOW, kick - ticks); + npc.velocity = vector_add(npc.velocity, vector_scale(npc.targetPosition, npc.speedMultiplier)); + npc.targetPosition = vector_scale(npc.targetPosition, timescale_factor(SCOURGE_BROCCOLI_KICK_DECAY, npc.speedMultiplier)); + } + if (npc.sprite.animState.animFrame > SCOURGE_BROCCOLI_LOOP_FRAME && npc.i1 >= 1 && npc.sprite.animState.animData) + npc.sprite.animState.SetFrameFloat(SCOURGE_BROCCOLI_LOOP_TO); +} + +// Its death throes: the Death animation's Shoot bursts a splash of its blood. +static void scourge_death_update(Entity_NPC& npc) +{ + const AnimationData* data = npc.sprite.animState.animData; + if (npc.state != NPC_STATE_DEATH || !data || !npc.sprite.animState.isPlaying || data->name != "Death") return; + if (!npc.sprite.animState.IsEventTriggered("Shoot")) return; + + float pitch = champion_pitch_get(npc); + npc_sound_play(SOUND_SKIN_PULL, 1, 2, pitch); + npc_sound_play(SOUND_DEATH_BURST_SMALL, 1, 2, pitch); + scourge_splash(3, npc.pos, SCOURGE_DEATH_RAISE); +} + +// 00587aa0 The Scourge (909.0): it hovers over its target, then traps it between two chains thrown down, slices +// along the walls with one or two chains, spits broccoli shots, or hovers in the middle inside a closing ring. +void boss_scourge_update(Entity_NPC& npc) +{ + Room& room = *g_game->room; + Vector center = vector_make((room.bottomRightPos.x + room.topLeftPos.x) * HALF, (room.bottomRightPos.y + room.topLeftPos.y) * HALF); + int ticks = npc_ticks_get(npc); + if (npc.aiCallPhase == AI_PHASE_PRE_UPDATE) return scourge_death_update(npc); + + while (npc.vectorDeque1.size() < 2) npc.vectorDeque1.push_back({}); + int state = npc.state; + switch (state) + { + case NPC_STATE_INIT: + npc.state = SCOURGE_IDLE; + npc.v1 = vector_make(0, SCOURGE_HOVER_HEIGHT); + npc.splatColor = COLOR_GREEN_SPLAT; + npc.aiCallFlags = AI_CALL_PRE_UPDATE; + npc.v2.x = 0; + scourge_cooldowns(npc)[4] = 0; + scourge_cooldowns(npc)[5] = 0; + npc.projectileCooldown = 0; + scourge_half_set(npc.projectileDelay, SCOURGE_HALF_LOW, 0); + npc.vectorDeque1[0] = {}; + npc.vectorDeque1[1] = {}; + break; + case SCOURGE_IDLE: + scourge_idle(npc, ticks); + break; + case SCOURGE_HOVER: + scourge_hover(npc, center, ticks); + break; + case SCOURGE_HOVER_END: + case SCOURGE_RECALL: + npc.friction *= SCOURGE_ATTACK_FRICTION; + break; + case SCOURGE_TRAP: + scourge_trap(npc, ticks); + break; + case SCOURGE_SLICE: + scourge_slice(npc, center, ticks); + break; + case SCOURGE_BROCCOLI: + scourge_broccoli(npc, ticks); + break; + } + + bool isEnding = state == SCOURGE_HOVER_END || state == SCOURGE_RECALL || state == SCOURGE_BROCCOLI; + if (isEnding && (!npc.sprite.animState.animData || !npc.sprite.animState.isPlaying)) + { + npc.state = SCOURGE_IDLE; + scourge_half_set(npc.projectileCooldown, SCOURGE_HALF_LOW, -1); + scourge_half_set(npc.projectileDelay, SCOURGE_HALF_LOW, -1); + scourge_half_set(npc.projectileCooldown, SCOURGE_HALF_HIGH, 0); + } + + if (npc.GetIntervalTicks(SCOURGE_COOLDOWN_EVERY, 0)) + for (int attack = 0; attack < SCOURGE_ATTACKS; attack++) + if (scourge_cooldowns(npc)[attack] != 0) scourge_cooldowns(npc)[attack]--; + + if (npc.isDead) + for (Entity* shot : entity_query(ENTITY_PROJECTILE, 0)) + if (shot->parent.get() == &npc) shot->isDead = true; + if (npc.knockbackCountdown >= 3) npc.knockbackCountdown = 2; +} + +// Moves a chain's tip that is still flying: on along its heading until it meets a wall, where it latches. +static void chain_tip_fly(Entity_NPC& npc, Entity_NPC& head) +{ + Room& room = *g_game->room; + npc.mass = SCOURGE_TIP_MASS; + if (vector_is_zero(npc.targetPosition)) return; + + npc.velocity = vector_add(npc.velocity, vector_scale(npc.targetPosition, SCOURGE_TIP_THRUST * npc.speedMultiplier)); + float speed = vector_length(npc.velocity); + if (speed > SCOURGE_TIP_SPEED_MAX && speed > 0) npc.velocity = vector_scale(npc.velocity, SCOURGE_TIP_SPEED_MAX / speed); + + float left = room.topLeftPos.x - SCOURGE_WALL_OUT; + float right = room.bottomRightPos.x + SCOURGE_WALL_OUT; + float top = room.topLeftPos.y - SCOURGE_WALL_OUT + SCOURGE_WALL_LOWER; + float bottom = room.bottomRightPos.y + SCOURGE_WALL_OUT + SCOURGE_WALL_LOWER; + int side = 0; + if (npc.pos.x < left) side = 0; + else if (npc.pos.x > right) side = 2; + else if (npc.pos.y < top) side = 1; + else if (npc.pos.y > bottom) side = 3; + else return; + + if (npc.pos.x < left) npc.pos.x = left; + else if (npc.pos.x > right) npc.pos.x = right; + if (npc.pos.y < top) npc.pos.y = top; + else if (npc.pos.y > bottom) npc.pos.y = bottom; + npc.PlaySound(SOUND_MEATY_DEATHS, 1, 2, false, 1); + game_shake_screen(SCOURGE_IMPACT_SHAKE); + float raise = SCOURGE_BLOOD_RAISE - random_unit() * SCOURGE_BLOOD_RAISE_RANGE; + blood_explosion_spawn(4, npc.pos, vector_make(0, raise), COLOR_DEFAULT, {}) + ->SetColor(COLOR_GREEN_SPLAT, -1, COLOR_PRIORITY_DEFAULT, false, true); + for (int piece = 0; piece < SCOURGE_IMPACT_PIECES; piece++) + { + Vector direction = vector_rotated(npc.targetPosition, (random_unit() - HALF) * SCOURGE_PIECE_SPREAD); + float out = random_unit(); + Vector at = vector_make(direction.x * out * SCOURGE_PIECE_OUT + npc.pos.x, direction.y * out * SCOURGE_PIECE_OUT + npc.pos.y); + uint32_t seed = Random(); + g_game->Spawn({.position = at, .velocity = vector_scale(direction, SCOURGE_PIECE_SPEED), .type = ENTITY_EFFECT, + .variant = EFFECT_ROCK_PARTICLE, .seed = seed}) + ->Update(); + } + + npc.velocity = {}; + npc.targetPosition = npc.pos; + npc.state = SCOURGE_LINK_LATCHED; + npc.v2.x = vector_distance(head.pos, npc.pos); + npc.i1 = link_float_make(SCOURGE_LATCHED_WAVE); + npc.aiFloat = SCOURGE_LATCHED_FLIGHT; + head.sprite.Play(npc.subtype == SCOURGE_CHAIN_TRAP ? "Whip1_Latched" : "Whip2_Latched"); + npc.sprite.Play("WallImpact"); + npc.sprite.rotation = SCOURGE_WALL_ROTATIONS[side]; + if (npc.subtype == SCOURGE_CHAIN_TRAP) return; + npc.i2 = link_float_make(SCOURGE_SLIDE_START); + npc.stateFrame = (side + 1 + (npc.sprite.isFlipX ? 2 : 0)) & 3; +} + +// The mess a crawling single chain leaves where it bleeds: creep, a splat, maybe a maggot, and a sick shot toward +// its first link. +static void chain_tip_creep(Entity_NPC& npc, Entity_NPC& head, const Vector& gibPos) +{ + Room& room = *g_game->room; + Vector creepPos = room.GetClampedPositionImpl(gibPos, SCOURGE_ROOM_MARGIN, SCOURGE_ROOM_MARGIN, SCOURGE_ROOM_MARGIN, + SCOURGE_ROOM_MARGIN); + Vector toHead = vector_normalized(vector_sub(head.pos, creepPos)); + + // The original works out a free spot near the creep that it never uses. Its draws stay. + float reach = random_unit() * SCOURGE_CREEP_SPOT_RANGE + SCOURGE_CREEP_SPOT_MIN; + Vector spot = vector_add(vector_scale(toHead, reach), creepPos); + if (room_grid_collision_at(spot) != COLLISION_NONE) + { + room_free_pickup_position_find({.position = spot}); + random_unit(); + random_unit(); + } + + uint32_t seed = Random(); + Entity* creep = g_game->Spawn({.position = creepPos, .spawner = &npc, .subType = SCOURGE_CREEP_SUBTYPE, .type = ENTITY_EFFECT, + .variant = EFFECT_CREEP_GREEN, .seed = seed}); + creep->sprite.scale = vector_make(SCOURGE_CREEP_SCALE, SCOURGE_CREEP_SCALE); + Entity_Effect* splat = npc.MakeSplat((random_unit() * HALF + HALF) * SCOURGE_SPLAT_SIZE); + splat->SetColor(COLOR_GREEN_SPLAT, -1, COLOR_PRIORITY_DEFAULT, false, true); + splat->Update(); + if (Random() % SCOURGE_MAGGOT_ODDS == 0) + small_maggot_jump_spawn(gibPos, SCOURGE_MAGGOT_HEIGHT, + room.GetClampedPositionImpl(gibPos, SCOURGE_MAGGOT_MARGIN, SCOURGE_MAGGOT_MARGIN, + SCOURGE_MAGGOT_MARGIN, SCOURGE_MAGGOT_MARGIN)); + + ProjectileParams params; + params.color = SHOT_COLOR_SICK; + params.bulletFlags = PROJECTILE_NO_WALL_COLLIDE; + npc.FireBossProjectiles(1, vector_add(vector_scale(toHead, SCOURGE_SLIDE_SHOT_REACH), creepPos), 0, params); +} + +// A crawling tip bleeds now and then, faster for a single chain. +static void chain_tip_bleed(Entity_NPC& npc, Entity_NPC& head) +{ + bool isSingle = npc.subtype == SCOURGE_CHAIN_SLICE_ONE; + if (random_below(isSingle ? SCOURGE_BLEED_ONE_ODDS : SCOURGE_BLEED_ODDS) != 0) return; + + Vector wall = vector_from_direction((npc.stateFrame + 1 + (npc.sprite.isFlipX ? 2 : 0)) & 3); + scourge_splash(4, npc.pos, SCOURGE_BLOOD_RAISE - random_unit() * SCOURGE_BLOOD_RAISE_RANGE); + if (Random() % SCOURGE_GIB_ODDS != 0 && !isSingle) return; + + Vector direction = vector_rotated(wall, (random_unit() - HALF) * SCOURGE_PIECE_SPREAD); + float out = random_unit(); + Vector gibPos = vector_make(out * direction.x * SCOURGE_PIECE_OUT + npc.pos.x, out * direction.y * SCOURGE_PIECE_OUT + npc.pos.y); + uint32_t seed = Random(); + Entity* gib = g_game->Spawn({.position = gibPos, .velocity = vector_scale(direction, SCOURGE_PIECE_SPEED), .type = ENTITY_EFFECT, + .variant = EFFECT_BLOOD_PARTICLE, .seed = seed}); + gib->sprite.color = COLOR_GREEN_SPLAT; + gib->Update(); + game_shake_screen(SCOURGE_GIB_SHAKE); + if (isSingle) chain_tip_creep(npc, head, gibPos); +} + +// A latched tip: a slicing one crawls along the walls (turning their corners), sags its chain and bleeds. +static void chain_tip_latched(Entity_NPC& npc, Entity_NPC& head) +{ + Room& room = *g_game->room; + float speed = link_float_get(npc.i2); + if (npc.stateFrame >= 0 && speed >= 0) + { + bool isSingle = npc.subtype == SCOURGE_CHAIN_SLICE_ONE; + speed = isSingle ? std::min(speed + SCOURGE_SLIDE_ONE_STEP, SCOURGE_SLIDE_ONE_MAX) : std::min(speed + SCOURGE_SLIDE_STEP, SCOURGE_SLIDE_MAX); + Vector step = vector_from_direction(npc.stateFrame); + npc.targetPosition = vector_make(speed * step.x + npc.targetPosition.x, speed * step.y + npc.targetPosition.y); + + bool isCorner = false; + float left = room.topLeftPos.x - SCOURGE_WALL_OUT; + float right = room.bottomRightPos.x + SCOURGE_WALL_OUT; + float top = room.topLeftPos.y - SCOURGE_WALL_OUT + SCOURGE_WALL_LOWER; + float bottom = room.bottomRightPos.y + SCOURGE_WALL_OUT + SCOURGE_WALL_LOWER; + if (npc.targetPosition.x < left) + { + isCorner = npc.stateFrame == 0; + npc.targetPosition.x = left; + } + else if (npc.targetPosition.x > right) + { + isCorner = npc.stateFrame == 2; + npc.targetPosition.x = right; + } + if (npc.targetPosition.y < top) + { + npc.targetPosition.y = top; + isCorner = isCorner || npc.stateFrame == 1; + } + else if (npc.targetPosition.y > bottom) + { + isCorner = isCorner || npc.stateFrame == 3; + npc.targetPosition.y = bottom; + } + + if (Random() % SCOURGE_SLIDE_SLOW_ODDS == 0) speed *= SCOURGE_SLIDE_SLOW; + int flip = npc.sprite.isFlipX ? 2 : 0; + if (isCorner) + { + speed *= SCOURGE_SLIDE_SLOW; + npc.stateFrame = (npc.stateFrame + 1 + flip) & 3; + } + npc.i2 = link_float_make(speed); + npc.sprite.rotation = SCOURGE_WALL_ROTATIONS[(npc.stateFrame + 1 + (2 - flip)) & 3]; + npc.v2.y = flip ? std::max(npc.v2.y - SCOURGE_SAG_STEP, -SCOURGE_SAG_MAX) : std::min(npc.v2.y + SCOURGE_SAG_STEP, SCOURGE_SAG_MAX); + if (speed > SCOURGE_BLEED_SPEED) chain_tip_bleed(npc, head); + } + + npc.velocity = vector_sub(npc.targetPosition, npc.pos); + npc.friction *= SCOURGE_LATCHED_DECAY; + npc.aiFloat *= SCOURGE_LATCHED_DECAY; + npc.i1 = link_float_make(link_float_get(npc.i1) * SCOURGE_LATCHED_DECAY); +} + +// A middle link hangs on the line between its first link and its tip, waving and sagging with the tip. +static void chain_link_hang(Entity_NPC& npc, Entity_NPC& head, Entity_NPC& tip) +{ + Vector span = vector_sub(tip.pos, head.pos); + float length = vector_distance(head.pos, tip.pos); + Vector side = vector_rotated(vector_normalized(span), RIGHT_ANGLE_DEGREES); + float share = (float)npc.projectileDelay / (float)(npc.projectileCooldown - 1); + Vector at = vector_make(span.x * share + head.pos.x, span.y * share + head.pos.y); + npc.posOffset.y = (tip.posOffset.y - head.posOffset.y) * share + head.posOffset.y; + + float peak = share < HALF ? share + share : (1 - share) + (1 - share); + float wave = std::sin(share * length * link_float_get(tip.i1)) * link_float_get(tip.i2) * peak; + float bend = (share + share) - 1; + float offset = wave + (1 - (float)((double)bend * (double)bend)) * tip.v2.y; + npc.velocity = vector_make(side.x * offset + at.x - npc.pos.x, side.y * offset + at.y - npc.pos.y); +} + +// The links share their hurt: each above the weakest drops to it, and the Scourge takes a tenth of the most. +static void chain_health_share(Entity_NPC& npc, Entity_NPC& head) +{ + float weakest = SCOURGE_HEALTH_UNSET; + for (Entity* link = &head; is_scourge_link(link); link = link->child.get()) + weakest = std::min(link->health - link->pendingDamage, weakest); + + float most = 0; + EntityRef source(&npc); + for (Entity* link = &head; is_scourge_link(link); link = link->child.get()) + { + float left = link->health - link->pendingDamage; + if (left <= weakest) continue; + link->TakeDamage(left - weakest, 0, source, SCOURGE_LINK_DAMAGE_COUNTDOWN); + most = std::max(left - weakest, most); + } + if (head.parent && most > 0) head.parent->TakeDamage(most * SCOURGE_SHARED_DAMAGE, 0, source, SCOURGE_LINK_DAMAGE_COUNTDOWN); +} + +// A dead link lets go of its neighbours, checks what is left of its chain and shows its wall impact. +static void chain_link_death(Entity_NPC& npc) +{ + if (!npc.isDead) return; + Entity_NPC& head = link_head_get(npc); + Entity_NPC& tip = link_tip_get(npc); + npc.parent = nullptr; + npc.child = nullptr; + scourge_chain_check(head); + scourge_chain_check(tip); + npc.sprite.Play("WallImpact"); +} + +// 00584140 A link of the Scourge's chain (909.10): the first hangs from the Scourge, the tip flies until it latches +// onto a wall (where a slicing one crawls), and the others hang between them. Touching only far from the Scourge. +void scourge_chain_update(Entity_NPC& npc) +{ + if (npc.aiCallPhase == AI_PHASE_PRE_UPDATE) return chain_link_death(npc); + if (npc.state == NPC_STATE_INIT) + { + npc.AddEntityFlags(FLAG_NO_STATUS_EFFECTS); + npc.state = SCOURGE_LINK_FLYING; + npc.aiCallFlags = AI_CALL_PRE_UPDATE; + npc.stateFrame = -1; + npc.isBoss = false; + npc.splatColor = COLOR_GREEN_SPLAT; + } + if (npc.isDead) return; + + Entity_NPC& head = link_head_get(npc); + Entity_NPC& tip = link_tip_get(npc); + Entity* owner = head.parent.get(); + bool isFar = !owner || vector_distance(head.pos, npc.pos) > npc.config->collisionRadius + owner->size + SCOURGE_LINK_REACH; + npc.entityCollisionClass = isFar ? ENTCOLL_ALL : ENTCOLL_NONE; + if (npc.state != NPC_STATE_INIT) scourge_chain_check(npc); + + if (&npc == &head) + { + npc.renderDepthOffset = tip.pos.y - npc.pos.y >= 0 ? SCOURGE_HEAD_DEPTH : -SCOURGE_HEAD_DEPTH; + if (npc.subtype == SCOURGE_CHAIN_TRAP) npc.sprite.isFlipX = npc.pos.x < tip.pos.x; + if (!owner) npc.Kill(EntityRef()); + else npc.velocity = vector_sub(vector_add(owner->pos, npc.v1), npc.pos); + } + else if (&npc == &tip && npc.state == SCOURGE_LINK_RETRACTING) + { + npc.velocity = vector_scale(vector_sub(head.pos, npc.pos), SCOURGE_RETRACT_PULL); + npc.friction = 1; + float shrink = timescale_factor(SCOURGE_RETRACT_SHRINK, npc.speedMultiplier); + head.sprite.scale = vector_scale(head.sprite.scale, shrink); + if (vector_distance(head.pos, npc.pos) < SCOURGE_RETRACT_NEAR || head.sprite.scale.x < SCOURGE_RETRACT_SMALL) + { + std::vector links; + for (Entity* link = &head; is_scourge_link(link); link = link->child.get()) links.push_back(link); + for (Entity* link : links) link->Remove(); + return; + } + } + else if (&npc == &tip && npc.state == SCOURGE_LINK_LATCHED) chain_tip_latched(npc, head); + else if (&npc == &tip) chain_tip_fly(npc, head); + else chain_link_hang(npc, head, tip); + + chain_health_share(npc, head); + npc.friction *= SCOURGE_CHAIN_FRICTION; +} + +// 005832c0 The first link draws the whole chain as one strip of its first layer's frame, a quad from each link to +// the next, the frame's height spread over them (16 shorter while a trap chain is latched). +static void scourge_chain_strip_render(Entity_NPC& npc, const Vector& offset) +{ + namespace Graphics = KAGE::Graphics; + ColorMod color = npc.sprite.color; + Entity_NPC& tip = link_tip_get(npc); + int count = 0; + for (Entity* link = npc.child.get(); is_scourge_link(link); link = link->child.get()) count++; + + const AnimationFrame* frame = npc.sprite.animState.GetLayerFrame(0); + if (!frame) return; + + float halfWidth = frame->width * HALF * npc.sprite.scale.x * frame->scale.x; + float height = npc.subtype == SCOURGE_CHAIN_TRAP && tip.state == SCOURGE_LINK_LATCHED + ? (frame->height - SCOURGE_STRIP_LATCHED_INSET) * npc.sprite.scale.y + : npc.sprite.scale.y * frame->height; + float step = height / (float)count; + + std::vector quads; + std::vector sources; + float left = npc.sprite.isFlipX ? frame->crop.x + frame->width : frame->crop.x; + float right = npc.sprite.isFlipX ? frame->crop.x : frame->crop.x + frame->width; + float top = frame->crop.y; + Vector from = vector_add(npc.pos, npc.posOffset); + for (Entity* link = npc.child.get(); is_scourge_link(link); link = link->child.get()) + { + Vector to = vector_add(link->pos, link->posOffset); + Vector direction = vector_normalized(vector_sub(to, from)); + Vector edge = vector_make(-direction.y * halfWidth, direction.x * halfWidth); + Vector start = render_position_get(from, RENDER_SNAPPED); + Vector end = render_position_get(to, RENDER_SNAPPED); + DestinationQuad quad; + quad._topLeft = vector_add(vector_add(start, edge), offset); + quad._topRight = vector_add(vector_sub(start, edge), offset); + quad._bottomLeft = vector_add(vector_add(end, edge), offset); + quad._bottomRight = vector_add(vector_sub(end, edge), offset); + quads.emplace_back(quad, kcolor_rgba(1, 1, 1, 1)); + + SourceQuad source; + source._topLeft = vector_make(left, top); + source._topRight = vector_make(right, top); + source._bottomLeft = vector_make(left, top + step); + source._bottomRight = vector_make(right, top + step); + source._coordinateSpace = Graphics::COORDINATES_PIXEL; + sources.push_back(source); + top += step; + from = to; + } + if (quads.empty()) return; + + Graphics::BlendMode saved = Graphics::manager.blendMode; + Graphics::manager.blendMode.SetMode(Graphics::BLEND_NORMAL); + LayerState* layer = npc.sprite.GetLayer(0); + layer->wrapSMode = 0; + layer->wrapTMode = 0; + if (layer->spriteSheet) + for (size_t index = 0; index < quads.size(); index++) + { + apply_sprite_shader_params(color, SPRITE_SHADER_COLOR_APPLY, *layer->spriteSheet); + layer->spriteSheet->Render({&sources[index], 1}, {&quads[index], 1}); + } + Graphics::manager.blendMode = saved; + Graphics::manager.shader_default_set(); +} + +// 00589de0 A link of the Scourge's chain: the first draws the whole chain, the others draw themselves unflipped only +// while latched. +void scourge_chain_render(Entity_NPC& npc, const Vector& offset) +{ + if (!is_scourge_link(npc.parent.get())) return scourge_chain_strip_render(npc, offset); + if (npc.state != SCOURGE_LINK_LATCHED) return; + + bool isFlipX = npc.sprite.isFlipX; + npc.sprite.isFlipX = false; + npc.Entity::Render(offset); + npc.sprite.isFlipX = isFlipX; +} diff --git a/src/boss_sisters_vis.cpp b/src/boss_sisters_vis.cpp index e385f3c..7a1dfc1 100644 --- a/src/boss_sisters_vis.cpp +++ b/src/boss_sisters_vis.cpp @@ -188,7 +188,7 @@ static void sisters_init(Entity_NPC& npc) if (npc.spawnerType == npc.type) return; uint32_t seed = Random(); - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; Entity* sister = g_game->Spawn({.position = vector_make(std::cos(angle) * SISTERS_SPAWN_REACH + npc.pos.x, std::sin(angle) * SISTERS_SPAWN_REACH + npc.pos.y), diff --git a/src/boss_visage.cpp b/src/boss_visage.cpp index 3b7ea0c..aaafd13 100644 --- a/src/boss_visage.cpp +++ b/src/boss_visage.cpp @@ -225,9 +225,6 @@ constexpr float VISAGE_FRONT_DEPTH = 1000; constexpr uint32_t DUST_EXTRA_MASK = 3; constexpr int VISAGE_DUST_MIN = 5; constexpr float VISAGE_DUST_SPREAD = 20; -constexpr float VISAGE_DUST_SPEED = 5; -constexpr float VISAGE_DUST_SPIN = 10; -constexpr float VISAGE_DUST_SPIN_MIN = 2; constexpr float DUST_HEIGHT = -16; constexpr uint32_t VISAGE_DUST_TIMEOUT_RANGE = 10; constexpr int VISAGE_DUST_TIMEOUT = 30; @@ -396,14 +393,14 @@ static void visage_spawn_particles(const Vector& position, const Vector& directi uint32_t seed = Random(); float back = random_unit(); float sideways = random_unit() * 2 - 1; - Vector velocity = vector_add(vector_scale(direction, back * VISAGE_DUST_SPEED), vector_scale(side, sideways)); + Vector velocity = vector_add(vector_scale(direction, back * DUST_SPEED), vector_scale(side, sideways)); Vector at = random_direction(); Vector spot = vector_add(position, vector_scale(at, random_unit() * VISAGE_DUST_SPREAD)); auto* dust = static_cast(g_game->Spawn( {.position = spot, .velocity = velocity, .type = ENTITY_EFFECT, .variant = EFFECT_DUST_CLOUD, .seed = seed})); bool isBehind = vector_dot(vector_sub(dust->pos, position), direction) < 0; - dust->rotation = (random_unit() * VISAGE_DUST_SPIN + VISAGE_DUST_SPIN_MIN) * (float)isBehind == 0 ? 1.0f : -1.0f; + dust->rotation = (random_between(DUST_SPIN_MIN, DUST_SPIN_RANGE) * (float)isBehind == 0) ? 1.0f : -1.0f; int timeout = (int)(Random() % VISAGE_DUST_TIMEOUT_RANGE) + VISAGE_DUST_TIMEOUT; dust->posOffset = vector_make(0, DUST_HEIGHT); dust->timeout = timeout; diff --git a/src/boss_widow.cpp b/src/boss_widow.cpp index de3d72c..220f0fb 100644 --- a/src/boss_widow.cpp +++ b/src/boss_widow.cpp @@ -166,7 +166,7 @@ static void widow_creep_spread(Entity_NPC& npc) const ColorMod& color = isBlack ? WIDOW_BLACK_CREEP_COLOR : WIDOW_CREEP_COLOR; for (int ticks = npc_ticks_get(npc); ticks > 0; ticks--) { - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float reach = (float)npc.stateFrame * WIDOW_CREEP_SPREAD; Vector spot = vector_make(std::cos(angle) * reach + npc.pos.x, std::sin(angle) * reach + npc.pos.y); diff --git a/src/boss_wormwood.cpp b/src/boss_wormwood.cpp index f6b4fb7..802ab2d 100644 --- a/src/boss_wormwood.cpp +++ b/src/boss_wormwood.cpp @@ -121,10 +121,7 @@ constexpr int CROSS_PARTICLES_MIN = 6; constexpr int CROSS_PARTICLES_RANGE = 5; constexpr float CROSS_PARTICLE_SPEED = 8; constexpr int WORMWOOD_DUST_MIN = 3; -constexpr float WORMWOOD_DUST_SPEED = 5; constexpr float DUST_SPREAD = 20; -constexpr float WORMWOOD_DUST_SPIN_MIN = 2; -constexpr float WORMWOOD_DUST_SPIN_RANGE = 10; constexpr int WORMWOOD_DUST_LIFE_MIN = 15; constexpr int DUST_LIFE_RANGE = 15; @@ -501,7 +498,7 @@ static void dust_spawn(const DustBurst& burst, uint32_t seed, Vector place) .variant = EFFECT_DUST_CLOUD, .seed = seed})); float spin = vector_dot(vector_sub(dust->pos, burst.origin), burst.side) < 0 ? -1.0f : 1.0f; - dust->rotation = (random_unit() * WORMWOOD_DUST_SPIN_RANGE + WORMWOOD_DUST_SPIN_MIN) * spin; + dust->rotation = (random_between(DUST_SPIN_MIN, DUST_SPIN_RANGE)) * spin; int life = (int)(Random() % DUST_LIFE_RANGE) + WORMWOOD_DUST_LIFE_MIN; dust->timeout = life; dust->lifespan = life; @@ -537,8 +534,8 @@ static void crossing_start(Entity_NPC& npc) for (int i = 0; i < clouds; i++) { uint32_t seed = Random(); - float forward = random_unit() * WORMWOOD_DUST_SPEED; - float across = random_unit() * WORMWOOD_DUST_SPEED - WORMWOOD_DUST_SPEED / 2; + float forward = random_unit() * DUST_SPEED; + float across = random_unit() * DUST_SPEED - DUST_SPEED / 2; Vector velocity = vector_make(out * forward + across * 0.0f, -out * across + forward * 0.0f); Vector place = vector_add(npc.targetPosition, vector_scale(random_direction(), random_unit() * DUST_SPREAD)); dust_spawn({.origin = npc.pos, .side = vector_make(0, -out), .velocity = velocity}, seed, place); @@ -582,8 +579,8 @@ static void crossing_burst(Entity_NPC& npc) int clouds = (int)(Random() % 3) + WORMWOOD_DUST_MIN; for (int i = 0; i < clouds; i++) { - float across = random_unit() * WORMWOOD_DUST_SPEED - WORMWOOD_DUST_SPEED / 2; - float forward = random_unit() * WORMWOOD_DUST_SPEED; + float across = random_unit() * DUST_SPEED - DUST_SPEED / 2; + float forward = random_unit() * DUST_SPEED; Vector velocity = vector_make(i != 0 ? -forward : forward, across); uint32_t seed = Random(); Vector heading = random_direction(); diff --git a/src/camera.cpp b/src/camera.cpp index 2165d59..ea3c746 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -47,7 +47,6 @@ constexpr float SHAKE_PEAK = 0.9f; constexpr int SHAKE_KICK_FRAMES = 3; constexpr float SHAKE_KICK = 10; constexpr float SHAKE_FADE_FRAMES = 11; -constexpr float SHAKE_PI = 3.14f; // A door pulls the camera toward it from this close, fully from DOOR_PULL_FULL. constexpr float DOOR_PULL_RANGE = 30; @@ -66,7 +65,6 @@ constexpr float NET_VIEW_HALF_WIDTH = 369.23077f; constexpr float NET_VIEW_HALF_HEIGHT = 207.6923f; constexpr int ITEM_STATE_LUDOVICO_CHARGE = 49; -constexpr int COLLECTIBLE_LUDOVICO_TECHNIQUE = 329; // 00945130 Adds a vector, dropping the oldest when full. void VectorRing::push(Vector vector) @@ -396,7 +394,7 @@ void Camera::shake_update() if (g_game->screenShakeTimer < 1) shakeOffsets.push(vector_make(0, 0)); else { - float angle = random_unit() * SHAKE_PI; + float angle = random_unit() * PI_ROUGH; angle += angle; if (g_game->frameCount % SHAKE_KICK_FRAMES == 0) diff --git a/src/cutscene.cpp b/src/cutscene.cpp index 6c25436..d9700f6 100644 --- a/src/cutscene.cpp +++ b/src/cutscene.cpp @@ -2,6 +2,7 @@ #include "data.h" #include "game.h" #include "log.h" +#include "lua_engine.h" #include "music_manager.h" #include "nightmare_scene.h" #include "persistent_game_data.h" @@ -621,6 +622,15 @@ static void part_start(CutscenePart& part) part.isLetterbox ? SCREEN_FIT_FILL : SCREEN_FIT_INSIDE); } +// Whether a skip action was pressed this frame: a mod's answer through MC_INPUT_ACTION during a run, else any device's. +static bool skip_action_get(ButtonAction action) +{ + std::optional isModTriggered; + if (g_manager->state == MANAGER_STATE_GAME && g_luaEngine) + isModTriggered = lua_engine_get().InputAction(nullptr, INPUT_HOOK_TRIGGERED, action); + return isModTriggered ? *isModTriggered : is_action(action, ACTION_TRIGGERED); +} + // 0095df20 Plays the cutscene on: once the skip delay passed, menu confirm or back skips it. Runs the current part // and starts the next when it finishes. When the parts ran out or a skip faded out, unloads it and gives the screen // back to the window. (Labelled Manager::update_state_loading, it works on the cutscene player.) @@ -634,9 +644,12 @@ void Cutscene::Update() if (entry.currentPart >= 0 && entry.currentPart < partCount) isSkipAllowed = time_ms() - entry.parts[entry.currentPart]->startTime >= (uint64_t)(uint32_t)skipDelay; - if (isSkipAllowed && - (is_action(ACTION_MENU_CONFIRM, ACTION_TRIGGERED) || is_action(ACTION_MENU_BACK, ACTION_TRIGGERED))) - entry.isSkipped = true; + if (isSkipAllowed) + { + bool isConfirm = skip_action_get(ACTION_MENU_CONFIRM); + bool isBack = skip_action_get(ACTION_MENU_BACK); + if (isConfirm || isBack) entry.isSkipped = true; + } if (entry.isSkipped || (entry.isFadeOut && entry.currentPart >= partCount) || entry.isSkipVoted) entry.fadeProgress += CUTSCENE_FADE_STEP; diff --git a/src/daily_challenge.cpp b/src/daily_challenge.cpp index 9b6bd72..c52f0c9 100644 --- a/src/daily_challenge.cpp +++ b/src/daily_challenge.cpp @@ -3,6 +3,7 @@ #include "game.h" #include "level.h" #include "log.h" +#include "manager.h" #include "platform.h" #include "room.h" #include "seeds.h" @@ -11,10 +12,6 @@ #include constexpr uint32_t DAILY_SHIFT_INDEX = 64; -constexpr uint32_t SPECIAL_DAILY_GROUNDHOG = 2; -constexpr uint32_t SPECIAL_DAILY_EASTER = 6; -constexpr uint32_t SPECIAL_DAILY_THANKSGIVING = 16; -constexpr uint32_t SPECIAL_DAILY_G_FUEL = 52; constexpr const char* G_FUEL_SEED = "XRA8 J6GH"; constexpr int NOVEMBER = 11; constexpr int EASTER_LAST_YEAR = 3100; @@ -93,6 +90,34 @@ constexpr std::array SPECIAL_DAILY_RULES = {{ {SPECIAL_DAILY_G_FUEL, 0, 11, 1, 0, 0}, }}; +// The collectibles a special daily starts its player with, after or instead of the character's own. +struct SpecialDailyItems +{ + uint32_t id = 0; + std::array collectibles{}; + bool isReplacing = false; +}; +constexpr std::array SPECIAL_DAILY_ITEMS = {{ + {3, {382, 200, 63}}, {6, {138, 7, 83}}, {8, {31, 41, 55}}, {9, {163, 67, 8, 268, 265, 247}}, + {10, {175, 170, 116}}, {11, {191, 418, 174}}, {12, {52, 366, 330, 583}}, {13, {424}}, {14, {81}, true}, + {16, {48}}, {17, {132, 173}}, {18, {93}}, {19, {132, 74}}, {20, {145, 134, 212}}, + {22, {378, 6, 209, 291}}, {23, {150, 446, 86}}, {24, {330, 436}}, {25, {372, 116, 63, 356, 139}}, + {26, {413, 390, 499}}, {27, {104, 397, 457}}, {29, {67, 8, 163, 99, 100, 322}}, {30, {273, 316, 371, 81, 129}}, + {31, {180, 447, 484, 116}}, {32, {68, 579}}, {33, {282, 314}}, {34, {424, 166}}, {35, {210, 36, 376}}, + {36, {18}}, {37, {127}}, {38, {480, 151, 268}}, {39, {245, 123, 95}}, + {40, {118, 38, 221, 313, 3}}, {42, {182, 179, 374}}, {43, {232, 337}}, {45, {314, 129}}, {46, {52, 366}}, + {47, {402}}, {48, {156, 286, 74, 75}}, {49, {316, 371, 366, 273}}, {50, {286, 75, 156}}, + {51, {249, 414}}, {SPECIAL_DAILY_G_FUEL, {}, true}, +}}; + +// The bombs, luck and keys some special dailies start with, and St Patrick's green tint. +constexpr int NEW_YEAR_BOMBS = 99; +constexpr int VALENTINES_LUCK = 7; +constexpr int ST_PATRICKS_LUCK_PILLS = 18; +constexpr ColorMod ST_PATRICKS_TINT = {{1, 1, 1, 1}, {0, 1, 0, 0.6f}, {0, 0, 0}}; +constexpr int ST_PATRICKS_TINT_PRIORITY = 255; +constexpr int CHRISTMAS_KEYS = 1; + // A YYYYMMDD date as a calendar date, normalized as mktime would. static std::chrono::sys_days date_days_get(uint32_t date) { @@ -291,3 +316,62 @@ void DailyChallenge::Init(uint32_t dailyDate) seed = rng.Next(); special_daily_apply(*this); } + +// Part of Entity_Player::InitPostLevelInitStats: what a special daily starts a player with besides its trinket and +// card. New Year's bombs, Valentine's luck, St Patrick's lucky pills tinting the player green, December 6th's costume, +// Christmas's key, and every listed special daily's collectibles, replacing the character's own for some. +void special_daily_start_apply(Entity_Player& player, std::vector& items) +{ + uint32_t specialDailyId = g_game->dailyChallenge.specialDailyId; + + switch (specialDailyId) + { + case SPECIAL_DAILY_NEW_YEAR: player.AddBombs(NEW_YEAR_BOMBS); break; + case SPECIAL_DAILY_VALENTINES: player.luckModifier += VALENTINES_LUCK; break; + case SPECIAL_DAILY_ST_PATRICKS: + player.pillEffectUses[PILLEFFECT_LUCK_UP] += ST_PATRICKS_LUCK_PILLS; + player.cacheFlags |= CACHE_LUCK; + player.colorOverride = ST_PATRICKS_TINT; + player.SetColor(ST_PATRICKS_TINT, 1, ST_PATRICKS_TINT_PRIORITY, false, true); + break; + case SPECIAL_DAILY_DECEMBER_6: + player.AddCostume(g_manager->itemConfig.GetNullItem(NULLITEM_IWATA), false); + break; + case SPECIAL_DAILY_CHRISTMAS: player.AddKeys(CHRISTMAS_KEYS); break; + default: break; + } + + auto start = std::ranges::find(SPECIAL_DAILY_ITEMS, specialDailyId, &SpecialDailyItems::id); + if (start == SPECIAL_DAILY_ITEMS.end()) return; + if (start->isReplacing) items.clear(); + for (int id : start->collectibles) + if (id != 0) items.push_back(id); +} + +// Part of Entity_Player::InitPostLevelInitStats: the trinket a special daily starts with in place of the one picked, +// for a character without its own. +int special_daily_trinket_get(int trinket) +{ + switch (g_game->dailyChallenge.specialDailyId) + { + case SPECIAL_DAILY_MARCH_2: return TRINKET_LEFT_HAND; + case SPECIAL_DAILY_DECEMBER_6: return TRINKET_CARTRIDGE; + case SPECIAL_DAILY_FEBRUARY_18: return TRINKET_AAA_BATTERY; + case SPECIAL_DAILY_APRIL_15: + case SPECIAL_DAILY_NOVEMBER_19: return TRINKET_TICK; + default: return trinket; + } +} + +// Part of Entity_Player::InitPostLevelInitStats: the card a special daily starts with, for a character without its +// own, or 0. +int special_daily_card_get() +{ + switch (g_game->dailyChallenge.specialDailyId) + { + case SPECIAL_DAILY_JULY_13: return CARD_DICE_SHARD; + case SPECIAL_DAILY_NOVEMBER_13: return CARD_JUDGEMENT; + case SPECIAL_DAILY_DECEMBER_23: return CARD_STRENGTH; + default: return 0; + } +} diff --git a/src/daily_challenge.h b/src/daily_challenge.h index 1e73e9a..eebb163 100644 --- a/src/daily_challenge.h +++ b/src/daily_challenge.h @@ -2,11 +2,49 @@ #include "challenge_params.h" #include +#include + +struct Entity_Player; // A YYYYMMDD date's factors: the year's, then the month's and the day's part. constexpr uint32_t DATE_YEAR = 10000; constexpr uint32_t DATE_PART = 100; +// The special dailies the code tells apart, by the holiday or date they fall on. +enum SpecialDaily : uint32_t +{ + SPECIAL_DAILY_NONE, + SPECIAL_DAILY_NEW_YEAR = 1, + SPECIAL_DAILY_GROUNDHOG = 2, + SPECIAL_DAILY_VALENTINES = 3, + SPECIAL_DAILY_MARCH_2 = 4, + SPECIAL_DAILY_ST_PATRICKS = 5, + SPECIAL_DAILY_EASTER = 6, + SPECIAL_DAILY_APRIL_FOOLS = 7, + SPECIAL_DAILY_JULY_4 = 12, + SPECIAL_DAILY_HALLOWEEN = 13, + SPECIAL_DAILY_THANKSGIVING = 16, + SPECIAL_DAILY_DECEMBER_5 = 17, + SPECIAL_DAILY_DECEMBER_6 = 18, + SPECIAL_DAILY_CHRISTMAS = 19, + SPECIAL_DAILY_FEBRUARY_9 = 23, + SPECIAL_DAILY_FEBRUARY_18 = 25, + SPECIAL_DAILY_MARCH_22 = 28, + SPECIAL_DAILY_APRIL_15 = 30, + SPECIAL_DAILY_MAY_13 = 33, + SPECIAL_DAILY_JULY_2 = 37, + SPECIAL_DAILY_JULY_13 = 39, + SPECIAL_DAILY_AUGUST_16 = 41, + SPECIAL_DAILY_SEPTEMBER_5 = 43, + SPECIAL_DAILY_SEPTEMBER_17 = 44, + SPECIAL_DAILY_SEPTEMBER_22 = 45, + SPECIAL_DAILY_OCTOBER_6 = 46, + SPECIAL_DAILY_NOVEMBER_13 = 48, + SPECIAL_DAILY_NOVEMBER_19 = 49, + SPECIAL_DAILY_DECEMBER_23 = 50, + SPECIAL_DAILY_G_FUEL = 52 +}; + // A day's daily run (DailyChallenge): its date (0 when no daily is played), seed, the special daily the date falls on // and the rules drawn for it, and whether it is only practiced. struct DailyChallenge @@ -21,3 +59,6 @@ struct DailyChallenge }; uint32_t holiday_get_current(uint32_t date); +void special_daily_start_apply(Entity_Player& player, std::vector& items); +int special_daily_trinket_get(int trinket); +int special_daily_card_get(); diff --git a/src/deathmatch_manager.cpp b/src/deathmatch_manager.cpp index bd4896f..bf2a634 100644 --- a/src/deathmatch_manager.cpp +++ b/src/deathmatch_manager.cpp @@ -1,12 +1,209 @@ #include "deathmatch_manager.h" +#include "boss_ai.h" +#include "entity_effect.h" +#include "entity_familiar.h" +#include "entity_pickup.h" +#include "entity_player.h" +#include "fx_layers.h" +#include "game.h" +#include "game_state.h" +#include "grid_entity.h" +#include "item_config.h" +#include "item_pool.h" +#include "kage_graphics.h" #include "log.h" +#include "lua_engine.h" +#include "manager.h" +#include "menu_manager.h" +#include "music_manager.h" #include "platform.h" +#include "render_passes.h" +#include "room.h" +#include "room_grid.h" #include "seeds.h" +#include "sfx_manager.h" +#include "weapon.h" +#include +#include +#include +#include -constexpr int NORMAL_SPAWN_TIMER = 180; -constexpr int NORMAL_SPAWN_PHASE = 6; // A run draws Normal half the time, else one of the ten others. constexpr uint32_t OTHER_TYPE_COUNT = 10; +// The clock: fading in over a second, blinking every half second in sudden death, 30 below the top of the screen (24 +// higher with the HUD offset at 0). +constexpr int CLOCK_MINUTE_FRAMES = 1800; +constexpr float TIMER_FADE_IN = 1.0f / 30; +constexpr int CLOCK_BLINK_FRAMES = 15; +constexpr float TIMER_TOP = 30; +constexpr float TIMER_HUD_SHIFT = -24; +// Sudden death: a fly bomb every second, and every fourth second spikes on a free tile away from the players. +constexpr int SPIKES_EVERY_SECONDS = 4; +constexpr int SPIKES_TRIES = 10; +constexpr float SPIKES_PLAYER_DISTANCE_SQUARED = 144; +// The pickups: every five to ten seconds in a large room, eight to twelve in the others, while the room holds at most +// ten (five) besides collectibles. +constexpr uint32_t PICKUP_LARGE_RANGE = 6; +constexpr int PICKUP_LARGE_MIN = 5; +constexpr uint32_t PICKUP_SMALL_RANGE = 5; +constexpr int PICKUP_SMALL_MIN = 8; +constexpr size_t PICKUP_LARGE_LIMIT = 9; +constexpr size_t PICKUP_SMALL_LIMIT = 4; +constexpr uint32_t WEIGHT_ROLL = 101; +// The kinds of match: the bombs, flies, luck and damage scales they hand out, Bomberman's arena shape, Ipecac's ghost +// boosts and push, Venom's creep and the poof of a dropped collectible. +constexpr int BOMBERMAN_BOMBS = 99; +constexpr int BOMBERMAN_FLIES = 24; +constexpr int KNOCKOUT_LUCK = 8; +constexpr int ARENA_SHAPE_BOMBERMAN = 13; +constexpr int DUEL_PLAYERS = 2; +constexpr float KNOCKOUT_DAMAGE_SCALE = 0.5f; +constexpr float MACHINE_GUN_DAMAGE_SCALE = 6.8f; +constexpr float IPECAC_GHOST_SPEED = 10; +constexpr float IPECAC_GHOST_DAMAGE = 10; +constexpr float IPECAC_GHOST_FIRE_DELAY = 20; +constexpr float IPECAC_WALL_PUSH = 10; +constexpr uint32_t VENOM_CREEP_SKIP = 5; +constexpr float VENOM_CREEP_SCALE_MIN = 0.2f; +constexpr float VENOM_CREEP_SCALE_RANGE = 0.5f; +constexpr float POOF_SCALE = 0.3f; +// Camo Undies confuses the other versus players for three seconds. +constexpr int CAMO_CONFUSION_FRAMES = 90; +// A banned pickup's redraws: the generator's shifts. +constexpr uint32_t PICKUP_RNG_SHIFT_1 = 5; +constexpr uint32_t PICKUP_RNG_SHIFT_2 = 9; +constexpr uint32_t PICKUP_RNG_SHIFT_3 = 7; +// The Ludovico arrow: kept this far inside the screen's edges, fading in from 10 pixels off screen over 140 more, and +// shrinking from twice its size from 30 off over 250 more. +constexpr float ARROW_MARGIN = 16; +constexpr float ARROW_MARGIN_HUD = 8; +constexpr float ARROW_MARGIN_Y = 10; +constexpr float ARROW_FADE_START = 10; +constexpr float ARROW_FADE_RANGE = 140; +constexpr float ARROW_SHRINK_START = 30; +constexpr float ARROW_SHRINK_RANGE = 250; +constexpr float ARROW_SIZE = 16; +constexpr const char* ARROW_SHADER = "ColorOffset"; +constexpr const char* LUDOVICO_IMAGE = "gfx/Items/Collectibles/collectibles_329_theludovicotechnique.png"; +// The match's states: the intro's length, sound and music fade, the countdown's fade in, and the result's slowdown, +// winner poof and end. +constexpr float INTRO_SECONDS = 3; +constexpr float INTRO_SECONDS_SILENT = 6; +constexpr int INTRO_SOUND_FRAME_SILENT = 90; +constexpr int INTRO_MUSIC_FADE_FRAME = 67; +constexpr int INTRO_MUSIC_FADE_FRAME_SILENT = 72; +constexpr float INTRO_MUSIC_FADE_RATE = 0.02f; +constexpr float COUNTDOWN_FADE_SPEED = 0.033f; +constexpr float MUSIC_FADE_RATE_DEATHMATCH = 0.02f; +constexpr float RESULT_FRICTION = 0.95f; +constexpr int RESULT_EFFECT_FRAME = 30; +constexpr int RESULT_FRAMES = 140; + +// The ids each ban covers (the original's jump tables). +constexpr auto BANNED_CARDS = std::to_array({1, 5, 10, 18, 19, 20, 22, 31, 34, 36, 42, 43, 44, 45, 46, 47, 50, 51, + 54, 57, 58, 60, 62, 66, 67, 69, 72, 74, 77, 78, 82, 83, 86, 89, 91, + 95, 97}); +constexpr auto BANNED_PILLS = std::to_array({19, 23, 25, 31, 41, 42}); +constexpr auto BANNED_TRINKETS = std::to_array({3, 4, 5, 7, 13, 17, 18, 20, 21, 23, 28, 32, 43, 46, 53, 55, 56, + 58, 59, 60, 61, 63, 67, 68, 72, 74, 75, 81, 82, 83, 84, 85, 88, 102, 107, 110, 111, 112, 119, 120, 121, 123, 124, + 135, 137, 138, 142, 143, 146, 150, 151, 152, 154, 155, 160, 161, 162, 163, 165, 167, 168, 170, 171, 172, 173, 174, + 177, 182, 184, 187, 188}); +constexpr auto BANNED_COLLECTIBLES = std::to_array({11, 21, 44, 54, 60, 64, 76, 81, 84, 91, 94, 96, 98, 127, 131, + 133, 134, 135, 144, 158, 161, 173, 175, 177, 203, 210, 212, 215, 232, 234, 236, 238, 239, 241, 243, 246, 249, 250, + 251, 252, 258, 260, 271, 278, 283, 285, 287, 296, 299, 311, 313, 315, 316, 324, 327, 328, 332, 333, 335, 337, 350, + 362, 371, 376, 377, 378, 380, 381, 382, 385, 388, 389, 391, 398, 402, 403, 408, 414, 416, 419, 422, 424, 434, 437, + 445, 464, 466, 475, 476, 481, 482, 489, 492, 498, 499, 500, 505, 514, 520, 521, 523, 530, 535, 539, 545, 546, 550, + 551, 552, 566, 567, 569, 577, 580, 585, 586, 588, 589, 599, 602, 612, 619, 622, 626, 627, 628, 631, 633, 636, 638, + 640, 642, 651, 653, 657, 660, 661, 664, 665, 668, 670, 672, 673, 674, 675, 676, 677, 681, 683, 684, 687, 688, 691, + 692, 694, 697, 699, 701, 703, 705, 710, 711, 714, 715, 716, 719, 720, 721, 723, 724, 725}); + +// The damage the match sets on a familiar, laser or effect of a kind that hurts players. +struct EntityDamage +{ + int type = 0; + int variant = 0; + float damage = 0; +}; + +constexpr EntityDamage ENTITY_DAMAGES[] = { + {ENTITY_FAMILIAR, Entity_Familiar::DADDY_LONGLEGS, 10}, + {ENTITY_FAMILIAR, Entity_Familiar::SACRIFICIAL_DAGGER, 7}, + {ENTITY_FAMILIAR, Entity_Familiar::GB_BUG, 7}, + {ENTITY_FAMILIAR, Entity_Familiar::CUBE_OF_MEAT_1, 3}, + {ENTITY_FAMILIAR, Entity_Familiar::CUBE_OF_MEAT_2, 3}, + {ENTITY_FAMILIAR, Entity_Familiar::CUBE_OF_MEAT_3, 3}, + {ENTITY_FAMILIAR, Entity_Familiar::CUBE_OF_MEAT_4, 6}, + {ENTITY_FAMILIAR, Entity_Familiar::BEST_BUD, 6}, + {ENTITY_FAMILIAR, Entity_Familiar::BBF, 20}, + {ENTITY_FAMILIAR, Entity_Familiar::BOBS_BRAIN, 20}, + {ENTITY_FAMILIAR, Entity_Familiar::HUSHY, 5}, + {ENTITY_EFFECT, EFFECT_BLUE_FLAME, 7}, + {ENTITY_EFFECT, EFFECT_RED_CANDLE_FLAME, 7}, + {ENTITY_EFFECT, EFFECT_PLAYER_CREEP_HOLYWATER, 4}, + {ENTITY_EFFECT, EFFECT_PLAYER_CREEP_LEMON_PARTY, 6}, + {ENTITY_EFFECT, EFFECT_MAMA_MEGA_EXPLOSION, 30}, + {ENTITY_EFFECT, EFFECT_MEGA_BEAN_EXPLOSION, 30}}; +// The laser Robo-Baby spawns hurts for 2. +constexpr float ROBO_BABY_LASER_DAMAGE = 2; + +// The hearts the match gives a few collectibles: their red hearts and containers count ten, their soul hearts more. +struct ItemHearts +{ + int id = 0; + int maxHearts = -1; + int hearts = -1; + int soulHearts = -1; +}; + +constexpr ItemHearts ITEM_HEARTS[] = { + {COLLECTIBLE_BODY, 10, 10, -1}, + {COLLECTIBLE_BUCKET_OF_LARD, -1, 10, -1}, + {COLLECTIBLE_CANCER, -1, -1, 2}, + {COLLECTIBLE_PJS, -1, -1, 4}}; + +// Whether an id is among the sorted ids of a ban. +template +static bool is_listed(const std::array& ids, int id) +{ + return std::ranges::binary_search(ids, id); +} + +// How long until the next pickup: shorter in the large rooms (2x2 and L shapes). +static int pickup_interval_get() +{ + int shape = g_game->room->GetRoomShape(); + bool isLarge = shape == ROOMSHAPE_2x2 || (shape >= ROOMSHAPE_LTL && shape <= ROOMSHAPE_LBR); + uint32_t seconds = isLarge ? Random() % PICKUP_LARGE_RANGE + PICKUP_LARGE_MIN : Random() % PICKUP_SMALL_RANGE + PICKUP_SMALL_MIN; + return (int)seconds * FRAMES_PER_SECOND; +} + +// A player's bombs moved by an amount, kept within 0 to 99, with the HUD told. +static void bombs_add(Entity_Player& player, int amount) +{ + player.numBombs = std::clamp(player.numBombs + amount, 0, BOMBS_MAX); + player.ConsumableCountChanged(CONSUMABLE_BOMBS); + g_game->hud.refresh_request(HUD_REFRESH_PLAYER); +} + +// Camo Undies in a versus match: its effect wakes and confuses every other player (the twin aside) for three seconds. +void camo_undies_confuse(Entity_Player& player) +{ + player.temporaryEffects.AddCollectibleEffect(COLLECTIBLE_CAMO_UNDIES, true, 1); + for (Entity_Player* other : g_game->playerManager.playerList) + if (other != &player && other != player.twinPlayer.get()) other->AddConfusion(EntityRef(&player), CAMO_CONFUSION_FRAMES, false); +} + +// get_time_ms: the real time in milliseconds the versus items pace themselves by. +uint64_t versus_time_get() +{ + return GetTimeNs() / NS_PER_MS; +} + +// Whether a versus item's cooldown has run out since its stamp (a stamp ahead of the clock counts as run out). +bool versus_cooldown_is_over(uint64_t stampMs, uint64_t cooldownMs) +{ + return versus_time_get() - stampMs >= cooldownMs; +} // 00429550 Whether a match is under way, the players fighting each other. bool DeathmatchManager::is_active() @@ -26,28 +223,103 @@ void DeathmatchManager::enter_arena() reconstruction_missing("DeathmatchManager::enter_arena 00429570: the versus arena of an online match"); } -// The match types' destruction (0042a430, 0042d0f0, 0042d780) frees what their construction filled, which the curated -// code leaves empty, so it does nothing more. Ludovico's image waits for DeathmatchTypeLudovico's takeover. -DeathmatchTypeBase::~DeathmatchTypeBase() {} -DeathmatchTypeLudovico::~DeathmatchTypeLudovico() {} -DeathmatchTypeNormal::~DeathmatchTypeNormal() {} +// 00429810 Moves the match to a state: the intro's sound (unless entered silently), the countdown's fade in (white +// when silent) to the versus music, the fight handing the players their controls, and the result taking them back. +// The result names the winner (whom it pulls to the middle, invincible with a heart at least) or a draw, and the end +// sends the online stats: both go through netplay. +void DeathmatchManager::state_set(DeathmatchState newState) +{ + Manager& manager = *g_manager; + state = newState; + timer = 0; + + switch (newState) + { + case DEATHMATCH_INTRO: + if (!isSilentEntry) manager.sfxManager.Play(SOUND_DEATHMATCH_INTRO, {.frameDelay = 1}); + break; + case DEATHMATCH_COUNTDOWN: + { + g_game->Fadein(COUNTDOWN_FADE_SPEED, FADE_ICON_HIDE, isSilentEntry ? WHITE : BLACK); + float volume = manager.musicManager.isEnabled ? manager.optionsConfig.musicVolume : 0; + manager.musicManager.Fadein(MUSIC_DEATHMATCH, volume, MUSIC_FADE_RATE_DEATHMATCH); + break; + } + case DEATHMATCH_FIGHT: + for (Entity_Player* player : g_game->playerManager.playerList) player->isControlsEnabled = true; + break; + case DEATHMATCH_RESULT: + if (type->winner_get() == 0) reconstruction_missing("DeathmatchManager 00429810: the draw's netplay notice (online)"); + else reconstruction_missing("DeathmatchManager 00429810: the winner's name and player (online)"); + [[fallthrough]]; + case DEATHMATCH_FADE_OUT: + for (Entity_Player* player : g_game->playerManager.playerList) player->isControlsEnabled = false; + break; + case DEATHMATCH_OVER: + reconstruction_missing("DeathmatchManager 00429810: online_stats_finalize (online)"); + break; + default: break; + } +} + +// 004291c0 (update_cutscene_state_machine) Ticks the match: the intro fades the music out and moves on after three +// seconds (six when silent, with its sound at three), the countdown starts the fight once the fade in is done, the +// fight runs the rules until a winner stands, and the result pulls the winner in while the others slow down, shows a +// poof after a second and ends after 140 frames. +void DeathmatchManager::Update() +{ + Manager& manager = *g_manager; + int previous = timer++; + + switch (state) + { + case DEATHMATCH_INTRO: + { + int musicFadeFrame = isSilentEntry ? INTRO_MUSIC_FADE_FRAME_SILENT : INTRO_MUSIC_FADE_FRAME; + if (previous < musicFadeFrame && timer >= musicFadeFrame) + { + MusicChannel& channel = manager.musicManager.channels[manager.musicManager.currentChannel]; + channel.targetVolume = 0; + channel.fadeRate = INTRO_MUSIC_FADE_RATE; + manager.musicManager.queuedMusicId = 0; + } + if (isSilentEntry && timer == INTRO_SOUND_FRAME_SILENT) + manager.sfxManager.Play(SOUND_DEATHMATCH_INTRO, {.frameDelay = 1}); + if (timer >= (int)((isSilentEntry ? INTRO_SECONDS_SILENT : INTRO_SECONDS) * FRAMES_PER_SECOND)) + state_set(DEATHMATCH_COUNTDOWN); + break; + } + case DEATHMATCH_COUNTDOWN: + if (g_game->fadeInColor._alpha <= 0) state_set(DEATHMATCH_FIGHT); + break; + case DEATHMATCH_FIGHT: + type->Update(); + if (type->is_over()) state_set(DEATHMATCH_RESULT); + break; + case DEATHMATCH_RESULT: + { + uint64_t winner = type->winner_get(); + if (winner != 0) reconstruction_missing("update_cutscene_state_machine 004291c0: the winner's player (online)"); + for (Entity_Player* player : g_game->playerManager.playerList) + player->velocity = vector_scale(player->velocity, RESULT_FRICTION); + if (timer == RESULT_EFFECT_FRAME && winner != 0) + g_game->Spawn({.position = winnerPosition, .subType = 2, .type = ENTITY_EFFECT, + .variant = EFFECT_HEAVEN_LIGHT_DOOR, .seed = Random()}); + else if (timer == RESULT_FRAMES) state_set(DEATHMATCH_OVER); + break; + } + default: break; + } +} // 00429be0 Replaces the match's rules with those of a type, logging an unknown type and leaving none. -// The Ludovico rules also load the Ludovico Technique's image, which waits for DeathmatchTypeLudovico's takeover. void DeathmatchManager::set_type(DeathmatchRules rules) { type.reset(); switch (rules) { - case DEATHMATCH_NORMAL: - { - auto normal = std::make_unique(); - normal->_spawnTimer = NORMAL_SPAWN_TIMER; - normal->_spawnPhase = NORMAL_SPAWN_PHASE; - type = std::move(normal); - break; - } + case DEATHMATCH_NORMAL: type = std::make_unique(); break; case DEATHMATCH_IPECAC: type = std::make_unique(); break; case DEATHMATCH_BOMBERMAN: type = std::make_unique(); break; case DEATHMATCH_LUDOVICO: type = std::make_unique(); break; @@ -71,3 +343,721 @@ void DeathmatchManager::Reset() bool isOtherType = Random() & 1; set_type(isOtherType ? (DeathmatchRules)(Random() % OTHER_TYPE_COUNT + DEATHMATCH_IPECAC) : DEATHMATCH_NORMAL); } + +// 0042a4d0 Starts the match: the clock, the banned pills taken out of the pool, the players' weapons let go and the +// players replaced by the lobby's (online), the co-op seats emptied, the HUD and camera set on the new players, and the +// first pickup timed. +bool DeathmatchTypeBase::Init() +{ + Game& game = *g_game; + HUD& hud = game.hud; + timer = DEATHMATCH_MATCH_FRAMES; + game.itemPool.remove_deathmatch_pill_effects(); + + for (Entity_Player* player : game.playerManager.playerList) + for (size_t slot = 1; slot < player->weapons.size(); slot++) + if (player->weapons[slot]) player->weapons[slot]->ClearReferences(); + game.playerManager.players_clear(); + if (g_manager->lobbyMembers._begin != g_manager->lobbyMembers._end) + reconstruction_missing("DeathmatchTypeBase::Init 0042a4d0: the lobby's players (online)"); + + game.playerManager.coop_slots_reset(); + hud.AssignPlayerHUDs(); + game.room->camera->position_center(); + game.room->camera->DoUpdate(false); + hud.mark_all_slots_dirty(HISTORY_REBUILD_ICONS, HISTORY_CLEAR_ITEMS); + hud.statHUD.reset(); + for (Entity_Player* player : game.playerManager.playerList) + hud.statHUD.RecomputeStats(hud.statHUD.player_slot_get(player), STAT_FLAGS_ALL); + pickupTimer = pickup_interval_get(); + return true; +} + +// 0042a8b0 Runs the clock. Past zero comes sudden death: a fly bomb every second, and every fourth second spikes on a +// free tile away from the players, while the clock blinks every half second. The pickups drop as they are due. +void DeathmatchTypeBase::Update() +{ + Room& room = *g_game->room; + timer--; + if (timerAlpha < 1) timerAlpha += TIMER_FADE_IN; + + if (timer < 0) + { + if (timer % FRAMES_PER_SECOND == 0) + { + int seconds = -timer / FRAMES_PER_SECOND; + uint32_t seed = Random(); + g_game->Spawn({.position = room.GetRandomPosition(0), .type = ENTITY_FLY_BOMB, .seed = seed}); + for (int tries = SPIKES_TRIES; seconds % SPIKES_EVERY_SECONDS == 0 && tries > 0; tries--) + { + Vector spot = room_free_tile_position_find(room.GetRandomPosition(0), 0); + auto is_near = [&spot](Entity_Player* player) { + return vector_length_squared(vector_sub(spot, player->pos)) < SPIKES_PLAYER_DISTANCE_SQUARED; + }; + if (std::ranges::any_of(g_game->playerManager.playerList, is_near)) continue; + int gridIndex = room.GetGridIndex(spot); + room.SpawnGridEntity(gridIndex, GRID_SPIKES, 0, Random(), 0); + break; + } + } + timerAlpha = (float)(-timer % CLOCK_BLINK_FRAMES) / CLOCK_BLINK_FRAMES; + if ((-timer / CLOCK_BLINK_FRAMES) % 2 == 0) timerAlpha = 1 - timerAlpha; + } + + if (!isPickupSpawning || --pickupTimer != 0) return; + pickup_spawn_random(); + pickupTimer = pickup_interval_get(); +} + +// 0042aca0 Draws the clock at the top middle of the screen, red once it runs out. +void DeathmatchTypeBase::timer_render() +{ + Font& font = g_manager->font2_TeamMeatEx12; + Vector shake = g_game->screenShakeOffset; + int minutes = 0; + int seconds = 0; + if (timer > 0) + { + int frames = timer + FRAMES_PER_SECOND; + minutes = frames / CLOCK_MINUTE_FRAMES; + seconds = (frames - minutes * CLOCK_MINUTE_FRAMES) / FRAMES_PER_SECOND; + } + + std::string text = std::format("{:02}:{:02}", minutes, seconds); + float top = (1 - g_manager->optionsConfig.hudOffset) * TIMER_HUD_SHIFT + TIMER_TOP + shake.y; + float left = g_screenWidth * HALF + shake.x - (float)(uint32_t)font.GetStringWidth(text) * HALF; + float bright = timer < 1 ? 0 : 1; + FontSettings settings; + font.DrawString(text, vector_make(left, top), vector_make(1, 1), kcolor_rgba(1, bright, bright, timerAlpha), settings); +} + +// 0042ae90 Whether fewer than two players still stand: alive, not a ghost, and not carried by another player. +bool DeathmatchTypeBase::is_over() +{ + PlayerManager& players = g_game->playerManager; + int standing = 0; + + for (int i = 0; i < players.count_main_players(); i++) + { + Entity_Player* player = players.get_main_player(i); + Entity* parent = player->parent.get(); + if (!player->isDead && !player->isCoopGhost && (!parent || parent->type != ENTITY_PLAYER)) standing++; + } + return standing < 2; +} + +// 0042af00 The online user of the first standing player, read from its network input device. Offline no device is a +// network one, so there is no winner. +uint64_t DeathmatchTypeBase::winner_get() +{ + return 0; +} + +// 0042b480 Whether the match bans a card. +bool DeathmatchTypeBase::is_card_banned(int card) +{ + return is_listed(BANNED_CARDS, card); +} + +// 0042b430 Whether the match bans a pill effect. +bool DeathmatchTypeBase::is_pill_banned(int pillEffect) +{ + return is_listed(BANNED_PILLS, pillEffect); +} + +// 0042b340 Whether the match bans a trinket. +bool DeathmatchTypeBase::is_trinket_banned(int trinket) +{ + return is_listed(BANNED_TRINKETS, trinket); +} + +// 0042b020 Whether the match bans a collectible. +bool DeathmatchTypeBase::is_collectible_banned(int collectible) +{ + return is_listed(BANNED_COLLECTIBLES, collectible); +} + +// 0042b520 The arena's room shape: a 1x1 for a duel, else a 2x2. +int DeathmatchTypeBase::arena_shape_get() +{ + return g_game->playerManager.count_main_players() == DUEL_PLAYERS ? ROOMSHAPE_1x1 : ROOMSHAPE_2x2; +} + +// 0042b7c0 Drops a collectible from the pool on a free spot near a position with a poof, the spot kept off the paths. +// None when the pool is out. +Entity* DeathmatchTypeBase::collectible_spawn(Vector position, float radius) +{ + int collectible = collectible_take(true); + if (collectible == 0) return nullptr; + + Room& room = *g_game->room; + Vector spot = room_free_pickup_position_find({.position = position, .step = radius}); + int gridIndex = room.GetGridIndex(spot); + if (gridIndex >= 0 && gridIndex < ROOM_GRID_CELLS) room.gridPaths[gridIndex] = GRID_PATH_FREED; + + Entity* item = g_game->Spawn({.position = spot, .subType = collectible, .type = ENTITY_PICKUP, + .variant = PICKUP_COLLECTIBLE, .seed = Random()}); + sound_play(SOUND_BLACK_POOF); + item->MakeGroundPoof(item->pos, COLOR_DEFAULT, POOF_SCALE); + return item; +} + +// 0042b770 Drops a collectible somewhere in the room. +void DeathmatchTypeBase::collectible_spawn_random() +{ + collectible_spawn(g_game->room->GetRandomPosition(PICKUP_SPOT_STEP), 0); +} + +// 0042b940 The hearts a few collectibles give in a match. +void DeathmatchTypeBase::item_hearts_adjust(int collectible, HeartGain& gain) +{ + for (const ItemHearts& hearts : ITEM_HEARTS) + { + if (hearts.id != collectible) continue; + if (hearts.maxHearts >= 0) gain.maxHearts = hearts.maxHearts; + if (hearts.hearts >= 0) gain.hearts = hearts.hearts; + if (hearts.soulHearts >= 0) gain.soulHearts = hearts.soulHearts; + } +} + +// 0042b9a0 The contact damage a familiar, Robo-Baby's laser or a hurting effect deals in a match. +void DeathmatchTypeBase::entity_damage_adjust(Entity& entity) +{ + Entity* spawner = entity.spawnerEntity.get(); + if (entity.type == ENTITY_LASER && spawner && spawner->type == ENTITY_FAMILIAR && spawner->variant == Entity_Familiar::ROBO_BABY) + return entity.SetCollisionDamage(ROBO_BABY_LASER_DAMAGE); + + for (const EntityDamage& kind : ENTITY_DAMAGES) + if (kind.type == entity.type && kind.variant == entity.variant) return entity.SetCollisionDamage(kind.damage); +} + +// 0042bc00 Whether the player may shoot. +bool DeathmatchTypeBase::can_shoot(Entity_Player&) +{ + return true; +} + +// 0042bc10 How much of the base damage of 3.5 a player has. +float DeathmatchTypeBase::base_damage_scale() +{ + return 1; +} + +// Whether a player may drop or swap trinkets and pocket items (slot 20, 0042bc00's answer). +bool DeathmatchTypeBase::is_trinket_swap_allowed() +{ + return true; +} + +// 0042bc20 Whether a player takes contact damage from the others (Jelly Belly, as Sumo gives). +bool DeathmatchTypeBase::is_bouncy(Entity_Player& player) +{ + return player.HasCollectible(COLLECTIBLE_JELLY_BELLY); +} + +// 0042bc40 After a player's update: one about to hit a wall stops being knocked back. +void DeathmatchTypeBase::player_update(Entity_Player& player) +{ + if (player.is_grid_collision_at(player.velocity)) player.ClearEntityFlags(FLAG_KNOCKED_BACK); +} + +// 0042bc90 Draws over a player (only Ludovico does). +void DeathmatchTypeBase::player_render(Entity_Player&) +{ +} + +// 0042bca0 A player turned ghost loses its collectibles, and in a match gets the versus barf. +void DeathmatchTypeBase::player_ghost_morph(Entity_Player& player) +{ + while (!player.history.historyItems.empty()) player.RemoveCollectibleByHistoryIndex(0, true); + if (!g_game->deathmatchManager.is_active()) return; + + for (size_t slot = 1; slot < player.weapons.size(); slot++) player.weapons[slot].reset(); + player.weapons[1] = weapon_create(WEAPON_DEATHMATCH, &player); +} + +// The stat hooks each type may override (slots 25 to 27, 0042bc90 in the base). +void DeathmatchTypeBase::speed_evaluate(Entity_Player&, float&) +{ +} + +void DeathmatchTypeBase::damage_evaluate(Entity_Player&, float&) +{ +} + +void DeathmatchTypeBase::fire_delay_evaluate(Entity_Player&, float&) +{ +} + +// 0042bd70 Saves the collectibles the pool has known. +void DeathmatchTypeBase::StoreGameState(GameState& state) +{ + state.versusCollectibles.clear(); + for (auto& [collectible, isAvailable] : collectiblePool) state.versusCollectibles.push_back((uint32_t)collectible); +} + +// 0042bdf0 Restores the pool's collectibles, all available again. +void DeathmatchTypeBase::RestoreGameState(const GameState& state) +{ + collectiblePool.clear(); + for (uint32_t collectible : state.versusCollectibles) collectiblePool[(int)collectible] = true; +} + +// 0042c070 Puts a joining player on one of the arena's spawn points (logged when none are left), gives it its online +// user's controller and full hearts of the match. +void DeathmatchTypeBase::player_init(Entity_Player& player, uint64_t userId) +{ + Vector spot{}; + if (spawnPoints.empty()) KAGE_LogMessage(LOG_ERROR, (uint8_t*)"No spawnpoints to place player at, add more spawnpoints\n"); + else + { + auto picked = std::next(spawnPoints.begin(), (long)(Random() % spawnPoints.size())); + spot = *picked; + spawnPoints.erase(picked); + } + player.pos = spot; + player.SetControllerIndex(g_game->playerManager.get_player_by_user_id(userId)->controllerIndex, false); + player.InitPostLevelInitStats(); + player.AddMaxHearts(DEATHMATCH_MAX_HEARTS - player.maxHearts, true); + player.SetFullHearts(); +} + +// 0042c160 The character a joining user plays: Isaac. +int DeathmatchTypeBase::player_type_get(uint64_t) +{ + return PLAYER_ISAAC; +} + +// 0042c170 Drops a random pickup on a free spot of the room, unless it already holds too many: half the time hearts, +// coins, keys or bombs, else a sack or a pill (a battery when someone holds an active item), or a chest. +Entity* DeathmatchTypeBase::pickup_spawn_random() +{ + Room& room = *g_game->room; + size_t pickups = std::ranges::count_if(entity_query(ENTITY_PICKUP, -1), + [](Entity* pickup) { return pickup->variant != PICKUP_COLLECTIBLE; }); + int shape = room.GetRoomShape(); + bool isLarge = shape == ROOMSHAPE_2x2 || (shape >= ROOMSHAPE_LTL && shape <= ROOMSHAPE_LBR); + if (pickups > (isLarge ? PICKUP_LARGE_LIMIT : PICKUP_SMALL_LIMIT)) return nullptr; + + constexpr int BASIC_VARIANTS[] = {PICKUP_HEART, PICKUP_COIN, PICKUP_KEY, PICKUP_BOMB, PICKUP_HEART}; + constexpr int CHEST_VARIANTS[] = {PICKUP_CHEST, PICKUP_BOMBCHEST, PICKUP_SPIKEDCHEST, PICKUP_REDCHEST, PICKUP_HEART}; + auto is_holding_active = [](Entity_Player* player) { return player->activeItems[0].item != 0; }; + int variant = PICKUP_HEART; + + switch (weighted_pick({50, 20, 24})) + { + case 0: variant = BASIC_VARIANTS[weighted_pick({30, 10, 10, 50})]; break; + case 1: + switch (weighted_pick({33, 33, 34})) + { + case 0: variant = PICKUP_GRAB_BAG; break; + case 1: variant = PICKUP_PILL; break; + case 2: + if (std::ranges::any_of(g_game->playerManager.playerList, is_holding_active)) variant = PICKUP_LIL_BATTERY; + else variant = (Random() & 1) ? PICKUP_GRAB_BAG : PICKUP_PILL; + break; + default: break; + } + break; + case 2: variant = CHEST_VARIANTS[weighted_pick({40, 10, 10, 40})]; break; + default: break; + } + + uint32_t seed = Random(); + Vector size = vector_sub(room.bottomRightPos, room.topLeftPos); + Vector center = vector_make(size.x * HALF + room.topLeftPos.x, size.y * HALF + room.topLeftPos.y); + float step = random_unit() * std::max(size.x, size.y); + Vector spot = room_free_pickup_position_find({.position = center, .step = step}); + return g_game->Spawn({.position = spot, .type = ENTITY_PICKUP, .variant = variant, .seed = seed}); +} + +// 0042c540 Takes a random collectible still available from the pool, or none (Breakfast unless none is allowed) when +// the pool is out. +int DeathmatchTypeBase::collectible_take(bool isNoneAllowed) +{ + std::vector available; + for (auto& [collectible, isAvailable] : collectiblePool) + if (isAvailable) available.push_back(collectible); + if (available.empty()) return isNoneAllowed ? 0 : COLLECTIBLE_BREAKFAST; + + int collectible = available[Random() % available.size()]; + collectiblePool[collectible] = false; + return collectible; +} + +// 0042b560 Redraws a banned card, trinket or pill (keeping its horse flag) until an allowed one comes, and gives a +// collectible the pool never knew (Breakfast aside) one from the pool. Each pickup is about to spawn. +void DeathmatchTypeBase::pickup_replace_banned(int type, int variant, int& subType) +{ + RNG rng = {Random(), PICKUP_RNG_SHIFT_1, PICKUP_RNG_SHIFT_2, PICKUP_RNG_SHIFT_3}; + ItemPool& pool = g_game->itemPool; + if (type != ENTITY_PICKUP) return; + + switch (variant) + { + case PICKUP_TRINKET: + while (subType == 0 || is_trinket_banned(subType)) subType = (int)pool.GetTrinket(TRINKET_DRAW_TAKE); + break; + case PICKUP_TAROTCARD: + while (subType == 0 || is_card_banned(subType)) + { + uint32_t seed = rng.Next(); + int card = ItemPool::GetCardEx((int)seed, CARD_SPECIAL_CHANCE, CARD_RUNE_CHANCE, CARD_RUNE_CHANCE, true); + RNG cardRng = {seed, PICKUP_RNG_SHIFT_1, PICKUP_RNG_SHIFT_2, PICKUP_RNG_SHIFT_3}; + subType = lua_engine_get().GetCard({.rng = &cardRng, .card = card, .isOnlyRunes = false, .isPlaying = true, + .isRunes = true}); + } + break; + case PICKUP_PILL: + { + uint32_t horse = (uint32_t)subType & PILL_HORSE_FLAG; + while (subType == 0 || is_pill_banned(pool.GetPillEffect((uint32_t)subType, nullptr))) + subType = (int)((uint32_t)ItemPool::GetPill(rng.Next()) | horse); + break; + } + case PICKUP_COLLECTIBLE: + if (subType == 0 || (subType != COLLECTIBLE_BREAKFAST && !collectiblePool.contains(subType))) + subType = collectible_take(false); + break; + default: break; + } +} + +// 0042c6a0 A pick by weights out of 101: the first whose running total passes the roll, or the count when none does. +int DeathmatchTypeBase::weighted_pick(std::initializer_list weights) +{ + uint32_t roll = Random() % WEIGHT_ROLL; + uint32_t total = 0; + int index = 0; + + for (uint32_t weight : weights) + { + total += weight; + if (roll < total) return index; + index++; + } + return index; +} + +// 0042d7e0 Normal's rules. +DeathmatchRules DeathmatchTypeNormal::rules() +{ + return DEATHMATCH_NORMAL; +} + +// 0042d7f0 Starts the match with pickups dropping and a collectible for each player. +bool DeathmatchTypeNormal::Init() +{ + if (!DeathmatchTypeBase::Init()) return false; + + isPickupSpawning = true; + for (int i = 0; i < g_game->playerManager.count_main_players(); i++) collectible_spawn_random(); + return true; +} + +// 0042d850 Drops a collectible every six seconds, then runs the clock. +void DeathmatchTypeNormal::Update() +{ + if (--spawnTimer == 0) + { + collectible_spawn_random(); + spawnTimer = DEATHMATCH_NORMAL_SPAWN_FRAMES; + } + DeathmatchTypeBase::Update(); +} + +// 0042cc80 Ipecac's rules. +DeathmatchRules DeathmatchTypeIpecac::rules() +{ + return DEATHMATCH_IPECAC; +} + +// 0042cc90 A ghost is pushed toward the nearest wall, and like everyone stops being knocked back short of a wall. +void DeathmatchTypeIpecac::player_update(Entity_Player& player) +{ + if (player.isCoopGhost) + { + Room& room = *g_game->room; + float toLeft = player.pos.x - room.topLeftPos.x; + float toRight = room.bottomRightPos.x - player.pos.x; + float toTop = player.pos.y - room.topLeftPos.y; + float toBottom = room.bottomRightPos.y - player.pos.y; + float wallX = toRight <= toLeft ? room.bottomRightPos.x : room.topLeftPos.x; + float wallY = toBottom <= toTop ? room.bottomRightPos.y : room.topLeftPos.y; + bool isSideNearer = std::min(toTop, toBottom) > std::min(toLeft, toRight); + Vector wall = isSideNearer ? vector_make(wallX, player.pos.y) : vector_make(player.pos.x, wallY); + Vector away = vector_normalized(vector_sub(wall, player.pos)); + player.pos = vector_add(player.pos, vector_scale(away, IPECAC_WALL_PUSH)); + } + DeathmatchTypeBase::player_update(player); +} + +// A ghost keeps its collectibles and weapon here (the original's slot 24 does nothing). +void DeathmatchTypeIpecac::player_ghost_morph(Entity_Player&) +{ +} + +// 0042ce00 A ghost moves faster. +void DeathmatchTypeIpecac::speed_evaluate(Entity_Player& player, float& speed) +{ + if (player.isCoopGhost) speed += IPECAC_GHOST_SPEED; +} + +// 0042ce00 A ghost hits harder. +void DeathmatchTypeIpecac::damage_evaluate(Entity_Player& player, float& damage) +{ + if (player.isCoopGhost) damage += IPECAC_GHOST_DAMAGE; +} + +// 0042ce30 A ghost shoots faster. +void DeathmatchTypeIpecac::fire_delay_evaluate(Entity_Player& player, float& fireDelay) +{ + if (player.isCoopGhost) fireDelay -= IPECAC_GHOST_FIRE_DELAY; +} + +// 0042ce60 Gives Ipecac. +void DeathmatchTypeIpecac::player_init(Entity_Player& player, uint64_t userId) +{ + player.AddCollectible(COLLECTIBLE_IPECAC, 0, true, 0, 0); + DeathmatchTypeBase::player_init(player, userId); +} + +// 0042ca10 Bomberman's rules. +DeathmatchRules DeathmatchTypeBomberman::rules() +{ + return DEATHMATCH_BOMBERMAN; +} + +// 0042ca20 Bomberman's own arenas. +int DeathmatchTypeBomberman::arena_shape_get() +{ + return ARENA_SHAPE_BOMBERMAN; +} + +// 0042ca30 Only a ghost shoots. +bool DeathmatchTypeBomberman::can_shoot(Entity_Player& player) +{ + return player.isCoopGhost; +} + +// 0042ca40 Blindfolds the player and gives Bomber Boy and a golden bomb, then 99 bombs (Tainted ??? 24 blue flies). +void DeathmatchTypeBomberman::player_init(Entity_Player& player, uint64_t userId) +{ + player.AddCostume(g_manager->itemConfig.GetNullItem(NULLITEM_BLINDFOLD), false); + player.AddCollectible(COLLECTIBLE_BOMBER_BOY, 0, true, 0, 0); + player.hasGoldenBomb = true; + player.ConsumableCountChanged(CONSUMABLE_GOLDEN_BOMB); + g_game->hud.refresh_request(HUD_REFRESH_PLAYER); + if (player.playerType == PLAYER_BLUEBABY_B) player.AddBlueFlies(BOMBERMAN_FLIES, player.pos, nullptr); + else bombs_add(player, BOMBERMAN_BOMBS); + DeathmatchTypeBase::player_init(player, userId); +} + +// 0042d1b0 Ludovico's rules. +DeathmatchRules DeathmatchTypeLudovico::rules() +{ + return DEATHMATCH_LUDOVICO; +} + +// 00429be0 (part) Loads the Ludovico Technique's image for the arrow, filtered linearly. +DeathmatchTypeLudovico::DeathmatchTypeLudovico() : arrowImage(Manager::LoadImage(LUDOVICO_IMAGE)) +{ + if (arrowImage->minFilter != FILTER_LINEAR || arrowImage->magFilter != FILTER_LINEAR) + arrowImage->filter_set(FILTER_LINEAR, FILTER_LINEAR); +} + +// 0042cb80 Trinkets and pocket items stay put. +bool DeathmatchTypeLudovico::is_trinket_swap_allowed() +{ + return false; +} + +// 0042d1c0 For the local player whose Ludovico tear is off screen, draws its image at the screen's edge toward the +// tear, fading in and shrinking with the distance. +// The original finds the local player through netplay, which offline has no device and crashes. Here every local +// player gets its arrow. +void DeathmatchTypeLudovico::player_render(Entity_Player& player) +{ + if (!player.IsLocalPlayer()) return; + Weapon* weapon = player.weapons[0] ? player.weapons[0].get() : player.weapons[1].get(); + Entity* tear = weapon ? weapon->GetMainEntity() : nullptr; + if (!tear) return; + + float margin = g_manager->optionsConfig.hudOffset * ARROW_MARGIN_HUD + ARROW_MARGIN; + Vector screen = vector_add(render_position_get(tear->pos, RENDER_SNAPPED), g_game->room->renderScrollOffset); + Vector onScreen = vector_make(std::clamp(screen.x, 0.0f, g_screenWidth), std::clamp(screen.y, 0.0f, g_screenHeight)); + float distance = vector_length(vector_sub(screen, onScreen)); + float alpha = std::clamp((distance - ARROW_FADE_START) / ARROW_FADE_RANGE, 0.0f, 1.0f); + float shrink = std::clamp((distance - ARROW_SHRINK_START) / ARROW_SHRINK_RANGE, 0.0f, 1.0f); + if (alpha <= 0) return; + + float side = (2 - shrink) * ARROW_SIZE; + Vector size = vector_make(side, side); + Vector at = vector_make(std::clamp(screen.x, margin, g_screenWidth - margin) - side * HALF, + std::clamp(screen.y, margin + ARROW_MARGIN_Y, g_screenHeight - margin - ARROW_MARGIN_Y) - side * HALF); + shader_select(ARROW_SHADER); + apply_sprite_shader_params(COLOR_DEFAULT, SPRITE_SHADER_COLOR_APPLY, *arrowImage); + arrowImage->Render(KAGE::Graphics::color_quad_rect(at, size, WHITE), kcolor_rgba(1, 1, 1, alpha)); +} + +// 0042d5f0 Gives the Ludovico Technique, Proptosis, Cat-o-nine-tails and Whip Worm. +void DeathmatchTypeLudovico::player_init(Entity_Player& player, uint64_t userId) +{ + player.AddCollectible(COLLECTIBLE_LUDOVICO_TECHNIQUE, 0, true, 0, 0); + player.AddCollectible(COLLECTIBLE_PROPTOSIS, 0, true, 0, 0); + player.AddCollectible(COLLECTIBLE_CAT_O_NINE_TAILS, 0, true, 0, 0); + player.AddTrinket(TRINKET_WHIP_WORM, true); + DeathmatchTypeBase::player_init(player, userId); +} + +// 0042d8a0 Sumo's rules. +DeathmatchRules DeathmatchTypeSumo::rules() +{ + return DEATHMATCH_SUMO; +} + +// 0042ca30 Only a ghost shoots. +bool DeathmatchTypeSumo::can_shoot(Entity_Player& player) +{ + return player.isCoopGhost; +} + +// 0042d8b0 Gives Jelly Belly and takes a bomb. +void DeathmatchTypeSumo::player_init(Entity_Player& player, uint64_t userId) +{ + player.AddCollectible(COLLECTIBLE_JELLY_BELLY, 0, true, 0, 0); + bombs_add(player, -1); + DeathmatchTypeBase::player_init(player, userId); +} + +// 0042cef0 Knockout's rules. +DeathmatchRules DeathmatchTypeKnockout::rules() +{ + return DEATHMATCH_KNOCKOUT; +} + +// 0042cf00 Half the base damage. +float DeathmatchTypeKnockout::base_damage_scale() +{ + return KNOCKOUT_DAMAGE_SCALE; +} + +// 0042cf10 Gives Knockout Drops and 8 luck, and takes a bomb. +void DeathmatchTypeKnockout::player_init(Entity_Player& player, uint64_t userId) +{ + player.AddCollectible(COLLECTIBLE_KNOCKOUT_DROPS, 0, true, 0, 0); + player.donateLuck += KNOCKOUT_LUCK; + player.cacheFlags |= CACHE_LUCK; + player.EvaluateItems(); + bombs_add(player, -1); + DeathmatchTypeBase::player_init(player, userId); +} + +// 0042d950 Sword fight's rules. +DeathmatchRules DeathmatchTypeSwordFight::rules() +{ + return DEATHMATCH_SWORD_FIGHT; +} + +// 0042d960 Gives Spirit Sword and Trinity Shield. +void DeathmatchTypeSwordFight::player_init(Entity_Player& player, uint64_t userId) +{ + player.AddCollectible(COLLECTIBLE_SPIRIT_SWORD, 0, true, 0, 0); + player.AddCollectible(COLLECTIBLE_TRINITY_SHIELD, 0, true, 0, 0); + DeathmatchTypeBase::player_init(player, userId); +} + +// 0042d660 Machine gun's rules. +DeathmatchRules DeathmatchTypeMachineGun::rules() +{ + return DEATHMATCH_MACHINE_GUN; +} + +// 0042d670 Nearly seven times the base damage. +float DeathmatchTypeMachineGun::base_damage_scale() +{ + return MACHINE_GUN_DAMAGE_SCALE; +} + +// 0042d680 Gives Soy Milk, Spoon Bender, Taurus, Thunder Thighs and Bucket of Lard, and takes a bomb. +void DeathmatchTypeMachineGun::player_init(Entity_Player& player, uint64_t userId) +{ + for (int collectible : {COLLECTIBLE_SOY_MILK, COLLECTIBLE_SPOON_BENDER, COLLECTIBLE_TAURUS, COLLECTIBLE_THUNDER_THIGHS, + COLLECTIBLE_BUCKET_OF_LARD}) + player.AddCollectible(collectible, 0, true, 0, 0); + bombs_add(player, -1); + DeathmatchTypeBase::player_init(player, userId); +} + +// 0042cb70 Indigestion's rules. +DeathmatchRules DeathmatchTypeIndigestion::rules() +{ + return DEATHMATCH_INDIGESTION; +} + +// 0042cb80 Trinkets and pocket items stay put. +bool DeathmatchTypeIndigestion::is_trinket_swap_allowed() +{ + return false; +} + +// 0042cb90 Gives Jupiter, 9 Volt, Wait What? and Butt Bombs, and takes three bombs. +void DeathmatchTypeIndigestion::player_init(Entity_Player& player, uint64_t userId) +{ + for (int collectible : {COLLECTIBLE_JUPITER, COLLECTIBLE_9_VOLT, COLLECTIBLE_WAIT_WHAT, COLLECTIBLE_BUTT_BOMBS}) + player.AddCollectible(collectible, 0, true, 0, 0); + bombs_add(player, -3); + DeathmatchTypeBase::player_init(player, userId); +} + +// 0042cea0 Knife fight's rules. +DeathmatchRules DeathmatchTypeKnifeFight::rules() +{ + return DEATHMATCH_KNIFE_FIGHT; +} + +// 0042ceb0 Gives Mom's Knife. +void DeathmatchTypeKnifeFight::player_init(Entity_Player& player, uint64_t userId) +{ + player.AddCollectible(COLLECTIBLE_MOMS_KNIFE, 0, true, 0, 0); + DeathmatchTypeBase::player_init(player, userId); +} + +// 0042d9d0 Venom's rules. +DeathmatchRules DeathmatchTypeVenom::rules() +{ + return DEATHMATCH_VENOM; +} + +// 0042cb80 Trinkets and pocket items stay put. +bool DeathmatchTypeVenom::is_trinket_swap_allowed() +{ + return false; +} + +// 0042d9e0 A ghost (when not just interpolated) leaves green creep of random size on most even frames, and like +// everyone stops being knocked back short of a wall. +void DeathmatchTypeVenom::player_update(Entity_Player& player) +{ + bool isTrailing = player.isCoopGhost && !player.HasEntityFlags(FLAG_INTERPOLATION_UPDATE) && !g_game->IsPaused() && + (g_game->frameCount & 1) == 0; + if (isTrailing && Random() % VENOM_CREEP_SKIP > 1) + { + uint32_t seed = Random(); + Entity* creep = g_game->Spawn({.position = player.pos, .spawner = &player, .type = ENTITY_EFFECT, + .variant = EFFECT_PLAYER_CREEP_GREEN, .seed = seed}); + float scale = random_unit() * VENOM_CREEP_SCALE_RANGE + VENOM_CREEP_SCALE_MIN; + creep->sprite.scale = vector_make(scale, scale); + creep->Update(); + } + DeathmatchTypeBase::player_update(player); +} + +// 0042db40 Gives Mysterious Liquid, Aquarius and Lost Cork. +void DeathmatchTypeVenom::player_init(Entity_Player& player, uint64_t userId) +{ + player.AddCollectible(COLLECTIBLE_MYSTERIOUS_LIQUID, 0, true, 0, 0); + player.AddCollectible(COLLECTIBLE_AQUARIUS, 0, true, 0, 0); + player.AddTrinket(TRINKET_LOST_CORK, true); + DeathmatchTypeBase::player_init(player, userId); +} diff --git a/src/deathmatch_manager.h b/src/deathmatch_manager.h index b68753e..2248cc5 100644 --- a/src/deathmatch_manager.h +++ b/src/deathmatch_manager.h @@ -1,12 +1,23 @@ #pragma once #include "classes.h" +#include +#include +#include +#include #include +namespace KAGE::Graphics +{ +class ImageBase; +} +struct GameState; + // Where a versus match stands. From the intro on, the players fight each other. enum DeathmatchState : int { DEATHMATCH_OFF = 0, + DEATHMATCH_FADE_OUT = 1, DEATHMATCH_INTRO = 2, DEATHMATCH_COUNTDOWN = 3, DEATHMATCH_FIGHT = 4, @@ -30,13 +41,194 @@ enum DeathmatchRules : int DEATHMATCH_VENOM }; -// The versus mode of online co-op (g_game->deathmatchManager): the match's state and timer, and the rules it is played -// with. Offline no match ever starts, but a run still draws its rules. -// The rules are classes.h's DeathmatchType classes until those are taken over. +// A versus match's clock: a minute and a half, then sudden death. +constexpr int DEATHMATCH_MATCH_FRAMES = 2700; +// The heart containers a versus player starts with, in the match's eighths of a heart. +constexpr int DEATHMATCH_MAX_HEARTS = 80; +// Normal drops a collectible every six seconds. +constexpr int DEATHMATCH_NORMAL_SPAWN_FRAMES = 180; + +// The hearts a collectible gives when taken. +struct HeartGain +{ + int hearts = 0; + int maxHearts = 0; + int soulHearts = 0; +}; + +// The rules of a versus match (Rebirth's DeathmatchTypeBase): the clock and its sudden death of fly bombs and spikes, +// the pickups and collectibles it drops, what it bans, and the hooks the player code asks. Each kind of match +// (DeathmatchType*) overrides a few. +// Destruction (0042a430, 0042d0f0, 0042d780) is the default. +// The original has two more slots that do nothing in every type. +// The arena's spawn points come twice: for the joining players and for Pandora's Box's collectibles. +class DeathmatchTypeBase +{ +public: + std::list itemSpawnPoints; + std::list spawnPoints; + std::map collectiblePool; + float timerAlpha = 0; + int pickupTimer = 0; + int timer = 0; + bool isPickupSpawning = false; + + virtual ~DeathmatchTypeBase() = default; + virtual DeathmatchRules rules() = 0; + virtual bool Init(); + virtual void Update(); + void timer_render(); + bool is_over(); + uint64_t winner_get(); + bool is_card_banned(int card); + bool is_pill_banned(int pillEffect); + bool is_trinket_banned(int trinket); + bool is_collectible_banned(int collectible); + virtual int arena_shape_get(); + Entity* collectible_spawn(Vector position, float radius); + void collectible_spawn_random(); + void item_hearts_adjust(int collectible, HeartGain& gain); + void entity_damage_adjust(Entity& entity); + virtual bool can_shoot(Entity_Player& player); + virtual float base_damage_scale(); + virtual bool is_trinket_swap_allowed(); + bool is_bouncy(Entity_Player& player); + virtual void player_update(Entity_Player& player); + virtual void player_render(Entity_Player& player); + virtual void player_ghost_morph(Entity_Player& player); + virtual void speed_evaluate(Entity_Player& player, float& speed); + virtual void damage_evaluate(Entity_Player& player, float& damage); + virtual void fire_delay_evaluate(Entity_Player& player, float& fireDelay); + void StoreGameState(GameState& state); + void RestoreGameState(const GameState& state); + virtual void player_init(Entity_Player& player, uint64_t userId); + int player_type_get(uint64_t userId); + Entity* pickup_spawn_random(); + int collectible_take(bool isNoneAllowed); + void pickup_replace_banned(int type, int variant, int& subType); + static int weighted_pick(std::initializer_list weights); +}; + +// Normal: a collectible per player at the start and one every six seconds, and pickups now and then. +class DeathmatchTypeNormal : public DeathmatchTypeBase +{ +public: + int spawnTimer = DEATHMATCH_NORMAL_SPAWN_FRAMES; + + DeathmatchRules rules() override; + bool Init() override; + void Update() override; +}; + +// Ipecac: everyone shoots Ipecac, and the dead float off the walls with stronger, faster shots. +class DeathmatchTypeIpecac : public DeathmatchTypeBase +{ +public: + DeathmatchRules rules() override; + void player_update(Entity_Player& player) override; + void player_ghost_morph(Entity_Player& player) override; + void speed_evaluate(Entity_Player& player, float& speed) override; + void damage_evaluate(Entity_Player& player, float& damage) override; + void fire_delay_evaluate(Entity_Player& player, float& fireDelay) override; + void player_init(Entity_Player& player, uint64_t userId) override; +}; + +// Bomberman: Bomber Boy with 99 golden bombs (Tainted ???'s flies instead) in its own arenas, and only the dead shoot. +class DeathmatchTypeBomberman : public DeathmatchTypeBase +{ +public: + DeathmatchRules rules() override; + int arena_shape_get() override; + bool can_shoot(Entity_Player& player) override; + void player_init(Entity_Player& player, uint64_t userId) override; +}; + +// Ludovico: the Ludovico Technique with an arrow to the local player's tear when it leaves the screen. +class DeathmatchTypeLudovico : public DeathmatchTypeBase +{ +public: + std::shared_ptr arrowImage; + + DeathmatchTypeLudovico(); + DeathmatchRules rules() override; + bool is_trinket_swap_allowed() override; + void player_render(Entity_Player& player) override; + void player_init(Entity_Player& player, uint64_t userId) override; +}; + +// Sumo: Jelly Belly bounces, and only the dead shoot. +class DeathmatchTypeSumo : public DeathmatchTypeBase +{ +public: + DeathmatchRules rules() override; + bool can_shoot(Entity_Player& player) override; + void player_init(Entity_Player& player, uint64_t userId) override; +}; + +// Knockout: Knockout Drops and luck, at half the base damage. +class DeathmatchTypeKnockout : public DeathmatchTypeBase +{ +public: + DeathmatchRules rules() override; + float base_damage_scale() override; + void player_init(Entity_Player& player, uint64_t userId) override; +}; + +// Sword fight: Spirit Sword and Mom's Knife's swing. +class DeathmatchTypeSwordFight : public DeathmatchTypeBase +{ +public: + DeathmatchRules rules() override; + void player_init(Entity_Player& player, uint64_t userId) override; +}; + +// Machine gun: a stack of tears ups at nearly seven times the base damage. +class DeathmatchTypeMachineGun : public DeathmatchTypeBase +{ +public: + DeathmatchRules rules() override; + float base_damage_scale() override; + void player_init(Entity_Player& player, uint64_t userId) override; +}; + +// Indigestion: bomb items that keep their trinkets. +class DeathmatchTypeIndigestion : public DeathmatchTypeBase +{ +public: + DeathmatchRules rules() override; + bool is_trinket_swap_allowed() override; + void player_init(Entity_Player& player, uint64_t userId) override; +}; + +// Knife fight: Mom's Knife. +class DeathmatchTypeKnifeFight : public DeathmatchTypeBase +{ +public: + DeathmatchRules rules() override; + void player_init(Entity_Player& player, uint64_t userId) override; +}; + +// Venom: poison items, and the dead leave green creep. +class DeathmatchTypeVenom : public DeathmatchTypeBase +{ +public: + DeathmatchRules rules() override; + bool is_trinket_swap_allowed() override; + void player_update(Entity_Player& player) override; + void player_init(Entity_Player& player, uint64_t userId) override; +}; + +void camo_undies_confuse(Entity_Player& player); +uint64_t versus_time_get(); +bool versus_cooldown_is_over(uint64_t stampMs, uint64_t cooldownMs); + +// The versus mode of online co-op (g_game->deathmatchManager): the match's state and timer, where its winner stands, +// and the rules it is played with. Offline no match ever starts, but a run still draws its rules. class DeathmatchManager { public: std::unique_ptr type; + Vector winnerPosition{}; DeathmatchState state = DEATHMATCH_OFF; int timer = 0; bool isSilentEntry = false; @@ -44,6 +236,8 @@ public: bool is_active(); bool is_fighting(); void enter_arena(); + void state_set(DeathmatchState newState); + void Update(); void set_type(DeathmatchRules rules); void Reset(); }; diff --git a/src/entity.cpp b/src/entity.cpp index f9bb9bd..2316812 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -6,6 +6,8 @@ #include "entity_npc.h" #include "entity_player.h" #include "entity_tear.h" +#include "render_passes.h" +#include "entity_text.h" #include "fx_layers.h" #include "game.h" #include "log.h" @@ -17,6 +19,7 @@ #include #include #include +#include // classes.h declares the original's Lua imports, and its luaL_newstate differs from Lua's only in its return type. #define luaL_newstate lua_newstate_auxiliary @@ -29,6 +32,19 @@ extern "C" // GetRenderZ's bands: the background layer, the door layer and the normal layer sorted by depth. constexpr int RENDER_INDEX_MASK = 0x3ff; +constexpr int DEBUG_TEXT_PRIORITY = 255; +// The debug overlays' colors: a position (orange for an effect), and by grid collision class and collision class. +constexpr uint32_t DEBUG_POSITION_ARGB = 0xffff0000; +constexpr uint32_t DEBUG_EFFECT_POSITION_ARGB = 0xffffa500; +constexpr std::array DEBUG_GRID_COLLISION_ARGB = {0xff000000, 0xff8b0000, 0xff006400, 0xffffff00, + 0xffffa500, 0xffff0000, 0xff00ffff, 0xffff00ff}; +constexpr std::array DEBUG_HITSPHERE_ARGB = {0xff000000, 0xffffa500, 0xffffc0cb, 0xff00ff00, 0xffff0000}; +// A position's cross half a side, and a hitsphere drawn in segments about 10 long, from 4 to 24 to its half circle. +constexpr float DEBUG_CROSS_HALF = 2; +constexpr float DEBUG_SEGMENT_LENGTH = 10; +constexpr float DEBUG_SEGMENTS_MIN = 2; +constexpr float DEBUG_SEGMENTS_MAX = 12; +constexpr size_t DEBUG_TEXT_LENGTH = 255; constexpr int RENDER_Z_BACKGROUND_BASE = 100; constexpr int RENDER_Z_BACKGROUND_MAX = 4999; constexpr int RENDER_Z_DOOR_BASE = 5100; @@ -990,7 +1006,7 @@ void Entity::damage_events_update() { if (event.damage <= 0) continue; if (g_game->debugFlags & DEBUG_DAMAGE_VALUES) - reconstruction_missing("Entity::Update 006ae820: the debug damage numbers (spawn_debug_damage_text)"); + debug_damage_text_spawn(pos, DEBUG_DAMAGE_DEALT_ARGB, std::format("dmg {:.2f}", event.damage)); bool isHiss = (event.damageFlags & (DAMAGE_FIRE | DAMAGE_POOP)) && !(event.damageFlags & DAMAGE_EXPLOSION); if (isHiss) @@ -1102,15 +1118,77 @@ void Entity::Render(const Vector& offset) sprite.Render(SpriteDraw{renderPosition, {}, {}}); } -// 006b1260 Draws the debug overlays the console turns on. +// 006b1260 Draws the debug overlays the console turns on: its position as a small cross (debug 1), the points it +// checks against the grid colored by its grid collision class (debug 13), and its hitsphere colored by its collision +// class (debug 6), a circle or, stretched by its size multiplier, a capsule along its longer axis. void Entity::PostRender() { - uint32_t debugFlags = g_game->debugFlags; - bool isPositionShown = (debugFlags & DEBUG_ENTITY_POSITIONS) && type != ENTITY_LASER; - bool isGridShown = (debugFlags & DEBUG_GRID_COLLISION) && entityGridCollisionClass != GRIDCOLL_NONE; - bool isHitsphereShown = (debugFlags & DEBUG_HITSPHERES) && size > 0 && entityCollisionClass != ENTCOLL_NONE; - if (isPositionShown || isGridShown || isHitsphereShown) - reconstruction_missing("Entity::PostRender 006b1260: the debug overlays"); + Game& game = *g_game; + Vector screen = vector_add(render_position_get(pos, RENDER_SNAPPED), game.room->renderScrollOffset); + auto point = [&](Vector offset) { return vector_add(screen, vector_scale(offset, ROOM_SCREEN_SCALE)); }; + auto line = [](Vector from, Vector to, KColor color) { render_color_quad(from, to, color, color, 1); }; + + if ((game.debugFlags & DEBUG_ENTITY_POSITIONS) && type != ENTITY_LASER) + { + KColor color = kcolor_argb(type == ENTITY_EFFECT ? DEBUG_EFFECT_POSITION_ARGB : DEBUG_POSITION_ARGB); + Vector across = vector_make(DEBUG_CROSS_HALF, 0); + Vector down = vector_make(0, DEBUG_CROSS_HALF); + line(vector_sub(screen, across), vector_add(screen, across), color); + line(vector_sub(screen, down), vector_add(screen, down), color); + } + if ((game.debugFlags & DEBUG_GRID_COLLISION) && entityGridCollisionClass != GRIDCOLL_NONE) + { + uint32_t gridClass = entityGridCollisionClass; + if (gridClass >= DEBUG_GRID_COLLISION_ARGB.size()) gridClass = 0; + KColor color = kcolor_argb(DEBUG_GRID_COLLISION_ARGB[gridClass]); + for (Vector offset : collisionPoints) + render_color_shader_pass(KAGE::Graphics::color_quad_rect(point(offset), vector_make(1, 1), color)); + } + if (!(game.debugFlags & DEBUG_HITSPHERES) || size <= 0 || entityCollisionClass == ENTCOLL_NONE) return; + + uint32_t collisionClass = entityCollisionClass; + if (collisionClass >= DEBUG_HITSPHERE_ARGB.size()) collisionClass = 0; + KColor color = kcolor_argb(DEBUG_HITSPHERE_ARGB[collisionClass]); + int halfSegments = (int)std::clamp(size * TAU / DEBUG_SEGMENT_LENGTH, DEBUG_SEGMENTS_MIN, DEBUG_SEGMENTS_MAX) * 2; + auto angleGet = [&](int segment) { return (float)segment * HALF_TURN_DEGREES / (float)halfSegments; }; + + if (sizeMulti.x == 1 && sizeMulti.y == 1) + { + Vector from = point(vector_make(size, 0)); + for (int segment = 1; segment <= halfSegments * 2; segment++) + { + Vector to = point(vector_scale(vector_from_angle(angleGet(segment)), size)); + line(from, to, color); + from = to; + } + return; + } + + float rotation = sprite.rotation; + float major = sizeMulti.x * size; + float minor = size * sizeMulti.y; + if (major < minor) + { + rotation += RIGHT_ANGLE_DEGREES; + std::swap(major, minor); + } + Vector axis = vector_scale(vector_from_angle(rotation), major - minor); + Vector side = vector_scale(vector_from_angle(rotation + RIGHT_ANGLE_DEGREES), minor); + Vector backSide = vector_scale(side, -1); + + line(point(vector_sub(backSide, axis)), point(vector_add(backSide, axis)), color); + line(point(vector_sub(side, axis)), point(vector_add(side, axis)), color); + Vector front = point(vector_add(side, axis)); + Vector back = point(vector_sub(side, axis)); + for (int segment = 1; segment <= halfSegments; segment++) + { + Vector frontTo = point(vector_add(vector_rotated(side, -angleGet(segment)), axis)); + Vector backTo = point(vector_sub(vector_rotated(side, angleGet(segment)), axis)); + line(front, frontTo, color); + line(back, backTo, color); + front = frontTo; + back = backTo; + } } // 006b2000 Draws only its sprite's shadow layer, uncolored, under it. @@ -1255,12 +1333,25 @@ void Entity::SetSpriteOverlayFrame(std::string_view animation, int frame) sprite.overlayAnimState.SetFrameFloat((float)frame); } -// The rest of Entity is not reconstructed yet. - -// 006b5f10 -void* Entity::GetDebugShape(bool) +// 00703580 (spawn_debug_damage_text) Shows a debug damage number (debug 7) as a text entity at a position, tinted, +// and prints it to the error output as the original does. +void debug_damage_text_spawn(const Vector& position, uint32_t argb, const std::string& text) { - reconstruction_missing("Entity::GetDebugShape 006b5f10"); + std::perror(text.c_str()); + + Entity* entity = g_game->Spawn({.position = position, .type = ENTITY_TEXT, .seed = Random()}); + auto& label = static_cast(*entity); + KColor color = kcolor_argb(argb); + ColorMod tint = {{color._red, color._green, color._blue, color._alpha}, {}, {}}; + label.SetColor(tint, -1, DEBUG_TEXT_PRIORITY, false, true); + label.text = text.substr(0, DEBUG_TEXT_LENGTH); + label.Update(); +} + +// 006b5f10 The debug renderer's shape for this entity, by its index. +void* Entity::GetDebugShape(bool isUnknown) +{ + return g_game->debugRenderer.Get((int)index, isUnknown); } // 006b6c20 The capsule its sprite's null layer covers: placed and turned like GetNullOffset, four times the null's diff --git a/src/entity.h b/src/entity.h index 4735bce..0d557fa 100644 --- a/src/entity.h +++ b/src/entity.h @@ -545,8 +545,6 @@ enum GridCollisionMode // A tear, bomb, knife or laser's 128 TearFlags bits (BitSet128). using TearFlags = std::bitset<128>; -// The drop RNG an entity holds before Init seeds it. -constexpr RNG DROP_RNG_DEFAULT = {RNG_SEED_DEFAULT, 5, 9, 7}; // The shifts of a drop RNG restored from a save, its seed taken from the save. constexpr RNG DROP_RNG_SAVED = {0, 4, 3, 17}; @@ -659,7 +657,7 @@ struct Entity EntityPtr parent; EntityPtr spawnerEntity; EntityPtr target; - RNG dropRNG = DROP_RNG_DEFAULT; + RNG dropRNG = RNG_DEFAULT; EntityConfig_Entity* config = nullptr; uint64_t flags = 0; uint64_t pendingDamageFlags = 0; @@ -776,6 +774,7 @@ struct Entity virtual void SetColor(const ColorMod& newColor, int duration, int priority, bool isFadeout, bool isShared); virtual void SetCollisionDamage(float damage); virtual void ClearReferences(); + // 005ccc00 An entity does not keep the doors shut. virtual bool CanShutDoors() { return false; } virtual bool IsBoss() { return false; } virtual bool IsValidTarget(Entity* other); @@ -927,4 +926,9 @@ constexpr int CULTIST_BLOOD_SPAWN = 10; void hit_list_insert(std::vector& hitList, Entity& entity); float stage_health_get(float baseHealth, float stageHealth); Vector render_position_get(const Vector& world, RenderSnap snap); +void debug_damage_text_spawn(const Vector& position, uint32_t argb, const std::string& text); + +// The debug damage view's numbers (debug 7): damage an entity takes in light green, a player's hurt in orange red. +constexpr uint32_t DEBUG_DAMAGE_DEALT_ARGB = 0xff90ee90; +constexpr uint32_t DEBUG_DAMAGE_TAKEN_ARGB = 0xffff4500; int render_z_get(float depth); diff --git a/src/entity_bomb.cpp b/src/entity_bomb.cpp index 8db92bf..dd00760 100644 --- a/src/entity_bomb.cpp +++ b/src/entity_bomb.cpp @@ -85,7 +85,6 @@ constexpr int BOMB_PICKUP_GIGA = 7; constexpr int BLASTING_CAP_CHANCE = 10; // The sounds a bomb makes, and the size its costume sprites are picked by. -constexpr int SOUND_SAFETY_SCISSORS = 900; constexpr float GOLDEN_VOLUME = 0.8f; constexpr float GIGA_DROP_PITCH = 0.8f; constexpr float BEEP_PITCH = 1.5f; @@ -113,7 +112,6 @@ constexpr float BOUNCE_VOLUME = 0.5f; // Dr. Fetus' bombs in flight: Wiggle Worm's sway, Tractor Beam's pull toward its line, the boomerang's pull back, and // a rocket's wiggle, thrust and steering, and the smoke it trails. -constexpr float HALF_TURN = 180; constexpr float FETUS_WIGGLE_RATE = 0.7f; constexpr float TRACTOR_PULL = 0.01f; constexpr float TRACTOR_PULL_MAX = 2; @@ -633,7 +631,7 @@ void Entity_Bomb::explode(Entity_Player* spawner) sprite.Play("Appear", PLAY_FORCED); if (sprite.animState.animData) sprite.animState.SetFrameFloat(GOLDEN_APPEAR_FRAME); RNG directionRng = {dropRNG.Next(), 3, 1, 14}; - float angle = directionRng.RandomFloat() * RANDOM_HALF_TURN; + float angle = directionRng.RandomFloat() * PI_ROUGH; angle += angle; float speed = dropRNG.RandomFloat() * GOLDEN_SPEED_EXTRA + GOLDEN_SPEED; velocity = vector_make(speed * std::cos(angle), speed * std::sin(angle)); @@ -723,7 +721,7 @@ void Entity_Bomb::fetus_children_throw() } if (!tearFlags[TEAR_QUADSPLIT]) return; - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; Vector around = vector_make(std::cos(angle), std::sin(angle)); float turnCosine = std::cos(PI_F / 2); @@ -890,7 +888,7 @@ void Entity_Bomb::rocket_sprite_update(float shownAngle) if (HasEntityFlags(FLAG_HELD)) angle = 0; else if (angle > RIGHT_ANGLE_DEGREES || angle < -RIGHT_ANGLE_DEGREES) { - angle = HALF_TURN - angle; + angle = HALF_TURN_DEGREES - angle; sprite.isFlipX = true; } sprite.rotation = angle; diff --git a/src/entity_bomb.h b/src/entity_bomb.h index 7ea45c4..dde1b8a 100644 --- a/src/entity_bomb.h +++ b/src/entity_bomb.h @@ -122,7 +122,6 @@ struct PoisonSplash void explosion_damage(Explosion explosion); void poison_splash_spawn(const PoisonSplash& splash); void shovel_quest_dig(); -bool explosion_line_clear(const Vector& start, const Vector& end, bool isIgnoreWalls); void explosion_effects(const Explosion& explosion); void explosion_tear_flag_effects(const Explosion& explosion); Entity* bomb_crater_spawn(const Vector& position, Entity* spawner, float scale); diff --git a/src/entity_collision.cpp b/src/entity_collision.cpp index b0c20ca..d56cfa7 100644 --- a/src/entity_collision.cpp +++ b/src/entity_collision.cpp @@ -17,7 +17,6 @@ #include // What crushes rocks on contact: The Nail, Leo (worn or rolled by Zodiac), Thunder Thighs, Stompy and Mega Mush. -constexpr int COLLECTIBLE_THUNDER_THIGHS = 314; // A transformation counts once the player holds this many of its items. constexpr int PLAYER_FORM_ITEMS = 3; diff --git a/src/entity_combat.cpp b/src/entity_combat.cpp index 5ce8907..90d485d 100644 --- a/src/entity_combat.cpp +++ b/src/entity_combat.cpp @@ -100,10 +100,8 @@ constexpr float BISHOP_SHIELD_HEIGHT = -24; constexpr float BISHOP_SHIELD_NULL_Y = 4; constexpr float NULL_OFFSET_SCALE = 0.5f / 0.65f; -// Entity_Tear::HandleCollision: the hit countdown, the tears' push, the bounce of a just fired tear off a bomb, and +// Entity_Tear::HandleCollision: the bounce of a just fired tear off a bomb, and // the burning tear's explosion chance from luck. -constexpr int TEAR_HIT_COUNTDOWN = 30; -constexpr float TEAR_PUSH_MIN_DISTANCE = 0.0001f; constexpr float TEAR_DEFLECTOR_MASS_SCALE = 0.1f; constexpr int BOMB_GRACE_FRAMES = 3; constexpr float FLY_PUSH = 0.5f; @@ -140,6 +138,18 @@ constexpr float BABY_CONTACT_DAMAGE = 10; constexpr float HORN_DAMAGE = 3.5f; constexpr float RAM_DAMAGE = 20; constexpr float RAM_FINISH_HEALTH = 40; +// A versus ram deals 15 and waits a second, and Gamekid's touch scares a player (for the original's -60 frames). +constexpr float RAM_VERSUS_DAMAGE = 15; +constexpr int RAM_VERSUS_COOLDOWN = 30; +constexpr int GAMEKID_VERSUS_FEAR = -60; +// The kill trinkets a versus tear hit rolls. +constexpr uint32_t LOCUST_ODDS_MASK = 0xf; +constexpr uint32_t FISH_TAIL_EXTRA_ODDS = 5; +constexpr uint32_t VERSUS_BAT_WING_ODDS = 50; +constexpr uint32_t VERSUS_CRICKET_LEG_ODDS = 33; +constexpr uint32_t VERSUS_SIGIL_ODDS = 10; +constexpr int VERSUS_SIGIL_FRAMES = 30; +constexpr int VERSUS_SIGIL_MAX_FRAMES = 150; constexpr int MIDAS_CONTACT_FREEZE = 90; constexpr int MIDAS_CONTACT_FREEZE_VERSUS = 45; constexpr float MIDAS_CONTACT_DAMAGE = 3.5f; @@ -221,7 +231,7 @@ static Entity_Effect* effect_spawn(int variant, int subType, Vector position, Ve // A random angle of a full turn, as the bursts draw it. static float random_angle() { - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; return angle + angle; } @@ -317,7 +327,8 @@ static int coop_player_count() // 006ace60 Queues a hit for the next update: nothing from a friendly source, nothing from a fire or countdown hit // while its cooldown runs, and nothing a Bishop shields. A boss takes less in co-op, a weakened entity double, and a -// mod's MC_ENTITY_TAKE_DMG may cancel it. Whether the hit was queued. +// mod's MC_ENTITY_TAKE_DMG may cancel it. A hit on an enemy (or a versus player) counts toward the damage its +// attacking player dealt this frame. Whether the hit was queued. bool Entity::TakeDamage(float damage, uint64_t damageFlags, const EntityRef& source, int countdown) { if (type == ENTITY_PLAYER) log_printf(LOG_ASSERT, "Entity TakeDamage should not be called for Entity Player!"); @@ -355,7 +366,10 @@ bool Entity::TakeDamage(float damage, uint64_t damageFlags, const EntityRef& sou damageEvents.push_back({.source = source, .damage = damage, .damageFlags = damageFlags}); pendingDamageFlags |= damageFlags; pendingDamage += damage; - // The damage the attacking player dealt is tallied only for the online stats screen, which is not written yet. + + // The online stats screen also tallies the damage, which netplay being offline leaves out. + Entity* attacker = source.entity ? source.entity->GetPlayerAncestor() : nullptr; + if (attacker && is_enemy_type(type)) static_cast(attacker)->versus.damageDealt += (uint32_t)damage; return true; } @@ -441,6 +455,28 @@ static void burst_drops_spawn(Entity& entity, int gibsAmount) } } +constexpr ColorMod BULB_FLASH_COLOR = {{1, 1, 0, 1}, {0, 0, 0, 0}, {0, 0, 0}}; +constexpr int BULB_FLASH_FRAMES = 3; +constexpr float BULB_FLASH_SCALE = 0.75f; +constexpr float BULB_FLASH_RAISE = -10; + +// Part of 006b45c0: the Bulb's death flash, a yellow additive light 10 up for 3 frames. +static void bulb_flash_spawn(const Vector& position) +{ + npc_sound_play(SOUND_BULB_FLASH, 1, 2, 1); + uint32_t seed = Random(); + auto* flash = static_cast( + g_game->Spawn({.position = position, .type = ENTITY_EFFECT, .variant = EFFECT_LIGHT, .seed = seed})); + flash->SetColor(BULB_FLASH_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); + flash->timeout = BULB_FLASH_FRAMES; + flash->lifespan = BULB_FLASH_FRAMES; + flash->sprite.scale = vector_make(BULB_FLASH_SCALE, BULB_FLASH_SCALE); + flash->state = BULB_FLASH_FRAMES; + flash->posOffset = vector_make(0, BULB_FLASH_RAISE); + if (flash->sprite.animState.animData) flash->sprite.animState.SetFrameFloat(1); + layer_additive_set(*flash->sprite.GetLayer(0)); +} + // 006b45c0 Bursts it: an iced or frozen enemy only shatters into shards, anything else plays its burst sound and // throws its config's gibs, a big burst (extra gore, or a huge config) shaking the screen, pushed away from the first // hit and with blood drops. It leaves a blood splat unless it is a bomb, a pickup or splashes no blood. @@ -467,8 +503,7 @@ void Entity::BloodExplode() } burst_sound_play(*this); - if (type == ENTITY_SUCKER && variant == SUCKER_BULB) - reconstruction_missing("Entity::BloodExplode 006b45c0: the bulb's death flash"); + if (type == ENTITY_SUCKER && variant == SUCKER_BULB) bulb_flash_spawn(pos); int gibsAmount = config->gibsAmount; if (gibsAmount >= 1 && HasEntityFlags(FLAG_REDUCE_GIBS)) gibsAmount = std::max(gibsAmount / REDUCED_GIBS_DIVISOR, 1); @@ -558,7 +593,7 @@ static Entity_Effect* gib_fling(const GibSpawn& gibs, int variant, int subType, // Part of 006b31b0: a tooth or chain gib, scattered within half the spread and flung at its own speed. static Entity_Effect* gib_scatter(const GibSpawn& gibs, int variant, uint32_t angleDraw) { - float angle = (float)angleDraw * RANDOM_UNIT_SCALE * RANDOM_HALF_TURN; + float angle = (float)angleDraw * RANDOM_UNIT_SCALE * PI_ROUGH; angle += angle; float reach = random_unit(); Vector position = vector_add(gibs.position, vector_make(std::cos(angle) * reach * HALF_F * gibs.spread, @@ -707,7 +742,7 @@ static void tear_push(Entity_Tear& tear, Entity& collider, float massScale) { Vector offset = vector_sub(collider.pos, tear.pos); float distance = vector_length(offset); - if (distance < TEAR_PUSH_MIN_DISTANCE) return; + if (distance < PUSH_MIN_DISTANCE) return; Vector relative = vector_sub(tear.velocity, collider.velocity); float speed = vector_length(relative); @@ -850,6 +885,54 @@ static TearContact tear_contact_get(Entity_Tear& tear, Entity& collider, Entity* return TEAR_CONTACT_HIT; } +// How many locusts a locust trinket sends: one, or with Fish Tail two (sometimes three doubled, four tripled). +static int locust_count_get(Entity_Player& player) +{ + if (!player.HasTrinket(TRINKET_FISH_TAIL)) return 1; + int multiplier = player.GetTrinketMultiplier(TRINKET_FISH_TAIL); + if (multiplier == 2) return Random() % FISH_TAIL_EXTRA_ODDS == 0 ? 3 : 2; + if (multiplier == 3 && Random() % FISH_TAIL_EXTRA_ODDS == 0) return 4; + return 2; +} + +// Part of 00673660: a versus player's tear landing on another player rolls its kill trinkets: each locust one in 16 +// (Conquest's twice as many), Bat Wing's flight one in 50, Cricket Leg's pickup one in 33 and Sigil of Baphomet's +// shield one in 10 for a second, up to five. +static void versus_hit_trinkets(Entity_Player& player) +{ + TemporaryEffects& effects = player.temporaryEffects; + for (int trinket = TRINKET_LOCUST_OF_WRATH; trinket <= TRINKET_LOCUST_OF_CONQUEST; trinket++) + { + if (!player.HasTrinket(trinket) || (Random() & LOCUST_ODDS_MASK) != 0) continue; + int locusts = locust_count_get(player) * (trinket == TRINKET_LOCUST_OF_CONQUEST ? 2 : 1); + for (int i = 0; i < locusts; i++) + { + uint32_t seed = Random(); + Entity* locust = g_game->Spawn({.position = player.pos, .spawner = &player, + .subType = trinket - TRINKET_LOCUST_OF_WRATH + 1, .type = ENTITY_FAMILIAR, + .variant = Entity_Familiar::BLUE_FLY, .seed = seed}); + locust->ClearEntityFlags(FLAG_APPEAR); + } + } + if (player.HasTrinket(TRINKET_BAT_WING) && !effects.HasTrinketEffect(TRINKET_BAT_WING) && + player.GetTrinketRNG(TRINKET_BAT_WING).RandomInt(VERSUS_BAT_WING_ODDS) == 0) + { + effects.AddTrinketEffect(TRINKET_BAT_WING, true, 1); + player.AddCostume(g_manager->itemConfig.GetNullItem(NULLITEM_BATWING_WINGS), false); + } + if (player.HasTrinket(TRINKET_CRICKET_LEG) && Random() % VERSUS_CRICKET_LEG_ODDS == 0) player.SpawnTrinketRandomPickup(); + if (!player.HasTrinket(TRINKET_SIGIL_OF_BAPHOMET) || Random() % VERSUS_SIGIL_ODDS != 0) return; + + TemporaryEffect* shadows = effects.GetCollectibleEffect(COLLECTIBLE_BOOK_OF_SHADOWS); + if (shadows && shadows->cooldown >= VERSUS_SIGIL_MAX_FRAMES) return; + TemporaryEffect added; + added.item = g_manager->itemConfig.GetCollectible(COLLECTIBLE_BOOK_OF_SHADOWS); + added.cooldown = VERSUS_SIGIL_FRAMES; + added.unknown = shadows ? 0 : 1; + if (!shadows) sound_play(SOUND_BOOK_SHADOWS_SIGIL); + effects.AddEffect(added, true, 1); +} + // Part of 00673660: a tear hitting what it may hurt: whether its owner's side may hurt it, and whether it faces the // tear's way (a shielded front blocks). Piercing passes the fronts, and a spectral tear an obstacle with no grid // damage. Whether the tear flies through. @@ -872,10 +955,15 @@ static bool tear_damage_deal(Entity_Tear& tear, Entity& collider, bool& isHit) bool isSpectral = tear.tearFlags[TEAR_SPECTRAL]; if (collider.IsEnemy() && (!isPiercing || isObstacle) && (!isSpectral || !isObstacle) && !isFacing) return false; if (isSpectral && isObstacle && tear.tearFlags[TEAR_NO_GRID_DAMAGE]) return true; - if (g_game->deathmatchManager.is_active()) reconstruction_missing("Entity_Tear::HandleCollision 00673660: the versus trinkets"); + Entity_Player* shooterPlayer = shooter ? shooter->ToPlayer() : nullptr; + if (g_game->deathmatchManager.is_active() && shooterPlayer) + { + shooterPlayer->trigger_vampire_charm_kill(); + if (collider.type == ENTITY_PLAYER) versus_hit_trinkets(*shooterPlayer); + } isHit = true; - collider.TakeDamage(damage, damageFlags, EntityRef(&tear), TEAR_HIT_COUNTDOWN); + collider.TakeDamage(damage, damageFlags, EntityRef(&tear), HIT_COUNTDOWN); if (tear.tearFlags[TEAR_FETUS_FLAG] && !isObstacle) tear.fetus_hit(collider); if (collider.IsEnemy()) tear.isCanTriggerStreakEnd = false; return collider.IsEnemy() && (tear.tearFlags[TEAR_BOOGER_FLAG] || tear.tearFlags[TEAR_STICKY] || tear.tearFlags[TEAR_SPORE_FLAG]); @@ -1017,8 +1105,8 @@ bool Entity_Tear::HandleCollision(Entity* collider, bool isLow) { apply_death_flag_effects(collider); if (tearFlags[TEAR_BELIAL_FLAG]) belial_turn(); - if (g_game->deathmatchManager.is_active() && collider->type == ENTITY_FAMILIAR) - reconstruction_missing("Entity_Tear::HandleCollision 00673660: a versus familiar's block"); + bool isPassed = collider->type == ENTITY_FAMILIAR && !static_cast(collider)->CanBlockProjectiles(); + if (g_game->deathmatchManager.is_active() && isPassed) return true; if (tear_flies_on(*this, *collider)) return true; deathFlags |= TEAR_DEATH_ENTITY; isDead = true; @@ -1084,7 +1172,8 @@ void Entity_NPC::on_player_damaged() } } -// Part of 0078e1f0: the damage a player's touch deals: the ramming items (more against the weak), Mom's Heels, The +// Part of 0078e1f0: the damage a player's touch deals: in a versus fight 1 to a Sumo player (and Gamekid's fear), the +// ramming items (more against the weak, 15 against a versus player once a second), Mom's Heels, The // Virus and Serpent's Kiss, Isaac's Heart's melee, Midas' Touch's gold freeze, the crow baby, Little Horn, Breath of Life, Aries at speed (which makes the player heavy and briefly unhurt), // Tooth and Nail, all tripled when thrown. Whether Breath of Life adds to it goes back through isBreath. static float player_contact_damage(Entity_Player& player, Entity& collider, bool& isBreath) @@ -1093,14 +1182,24 @@ static float player_contact_damage(Entity_Player& player, Entity& collider, bool TemporaryEffects& effects = player.temporaryEffects; float damage = 0; if (collider.type == ENTITY_PLAYER && g_game->deathmatchManager.is_fighting()) - reconstruction_missing("Entity_Player::HandleCollision 0078e1f0: the versus rules' contact damage"); + { + damage = g_game->deathmatchManager.type->is_bouncy(static_cast(collider)) ? 1 : 0; + if (effects.HasCollectibleEffect(COLLECTIBLE_GAMEKID)) collider.AddFear(EntityRef(&player), GAMEKID_VERSUS_FEAR, false); + } TemporaryEffect* taurus = effects.GetCollectibleEffect(COLLECTIBLE_TAURUS); bool isRamming = effects.HasCollectibleEffect(COLLECTIBLE_MY_LITTLE_UNICORN) || effects.HasCollectibleEffect(COLLECTIBLE_GAMEKID) || effects.HasCollectibleEffect(COLLECTIBLE_THE_NAIL) || (taurus && taurus->cooldown != 0); - if (isRamming && isVersus) reconstruction_missing("Entity_Player::HandleCollision 0078e1f0: the versus ramming cooldown"); - if (isRamming) damage += collider.health <= RAM_FINISH_HEALTH ? RAM_DAMAGE + RAM_DAMAGE : RAM_DAMAGE; + if (isRamming && player.versus.ramCooldown == 0) + { + damage += collider.health <= RAM_FINISH_HEALTH ? RAM_DAMAGE + RAM_DAMAGE : RAM_DAMAGE; + if (isVersus && collider.type == ENTITY_PLAYER) + { + damage = RAM_VERSUS_DAMAGE; + player.versus.ramCooldown = RAM_VERSUS_COOLDOWN; + } + } if (player.HasCollectible(COLLECTIBLE_MOMS_HEELS)) damage += isVersus ? HEELS_DAMAGE_VERSUS : HEELS_DAMAGE; if (player.HasCollectible(COLLECTIBLE_VIRUS)) damage += isVersus ? VIRUS_DAMAGE_VERSUS : VIRUS_DAMAGE; if (player.HasCollectible(COLLECTIBLE_SERPENTS_KISS)) damage += isVersus ? VIRUS_DAMAGE_VERSUS : VIRUS_DAMAGE; diff --git a/src/entity_dummy.cpp b/src/entity_dummy.cpp index 023211e..932c186 100644 --- a/src/entity_dummy.cpp +++ b/src/entity_dummy.cpp @@ -1,5 +1,8 @@ #include "entity_dummy.h" -#include "log.h" +#include "font.h" +#include "fx_layers.h" +#include "manager.h" +#include constexpr float DUMMY_FRICTION = 0.965f; @@ -23,10 +26,17 @@ void Entity_Dummy::Update() if (isDead) Remove(); } -// The rest of Entity_Dummy is not reconstructed yet. +// Its type and variant label sits 8 above where it draws. +constexpr float DUMMY_LABEL_RAISE = 8; -// 006a7f80 -void Entity_Dummy::Render(const Vector&) +// 006a7f80 Draws as any entity, then its type and variant above it. +void Entity_Dummy::Render(const Vector& offset) { - reconstruction_missing("Entity_Dummy::Render 006a7f80"); + Entity::Render(offset); + std::string label = "e" + std::to_string(type) + "." + std::to_string(variant); + Font& font = g_manager->font2_TeamMeatEx12; + float width = (float)font.GetStringWidth(label); + Vector at = vector_make(renderPosition.x - width * HALF, renderPosition.y - DUMMY_LABEL_RAISE); + FontSettings settings; + font.DrawString(label, at, vector_make(1, 1), WHITE, settings); } diff --git a/src/entity_effect.cpp b/src/entity_effect.cpp index 4358f4e..857f43f 100644 --- a/src/entity_effect.cpp +++ b/src/entity_effect.cpp @@ -300,8 +300,7 @@ void Entity_Effect::Init(int entityType, int entityVariant, int entitySubType, u if (!isExists) return; sprite.LoadGraphics(); - if (g_game->deathmatchManager.is_active()) - reconstruction_missing("Entity_Effect::Init 005cdb20: the versus mode's entity registration"); + if (g_game->deathmatchManager.is_active()) g_game->deathmatchManager.type->entity_damage_adjust(*this); lua_engine_get().PostEffectInit(this); } diff --git a/src/entity_effect.h b/src/entity_effect.h index fa63883..db00e94 100644 --- a/src/entity_effect.h +++ b/src/entity_effect.h @@ -60,6 +60,7 @@ constexpr int BLOOD_EXPLOSION_FLAME = 5; constexpr float DUST_SPEED = 5; constexpr float DUST_RADIUS = 20; constexpr float DUST_SPIN_MIN = 2; +constexpr float DUST_SPIN_RANGE = 10; // Dogma's blackhole (171): its sparks (subtype 1) and swirls (2), and its states while open and closing. constexpr int BLACKHOLE_SPARK = 1; @@ -87,6 +88,9 @@ enum HaloSubtype HALO_BREATH_OF_LIFE = 9 }; +// The black of the trail drawn between Dark Arts' snares and what they hold. +constexpr ColorMod SNARE_TRAIL_TINT = {{0, 0, 0, 1}, {0, 0, 0, 0}, {0, 0, 0}}; + // The effect variants several files name (Lua's EffectVariant). enum EffectVariant : int { diff --git a/src/entity_effect_ambient.cpp b/src/entity_effect_ambient.cpp index abb4507..32d050e 100644 --- a/src/entity_effect_ambient.cpp +++ b/src/entity_effect_ambient.cpp @@ -33,7 +33,6 @@ constexpr int SOUND_SPAWNER_SUMMON = 265; constexpr int DOOR_STATE_KEEPS_DECORATIONS = 7; constexpr int RENDER_Z_DECORATION_LIMIT = 0x40000000; constexpr float NEAR_PLAYER_RANGE_SQUARED = 10000; -constexpr float HALF_TURN = 180; // The tiny fly: white in the Cathedral, how it wanders, flees the nearest player within range, dies to tears, // knives and fires, and drops down in circles when dead. @@ -162,8 +161,8 @@ static bool is_listed(const std::array& list, int value) static float angle_normalized(float angle) { if (std::abs(angle) > FULL_TURN_DEGREES) angle = std::fmod(angle, FULL_TURN_DEGREES); - if (angle > HALF_TURN) return angle - FULL_TURN_DEGREES; - if (angle < -HALF_TURN) angle += FULL_TURN_DEGREES; + if (angle > HALF_TURN_DEGREES) return angle - FULL_TURN_DEGREES; + if (angle < -HALF_TURN_DEGREES) angle += FULL_TURN_DEGREES; return angle; } @@ -469,7 +468,7 @@ static void tiny_fly_update(Entity_Effect& fly) } if (fly.IsFrame(FLY_JITTER_FRAMES, (int)fly.index)) { - float angle = random_unit() * RANDOM_HALF_TURN * 2; + float angle = random_unit() * PI_ROUGH * 2; Vector jitter = vector_make(std::cos(angle), std::sin(angle)); fly.AddVelocity_divided(vector_scale(jitter, random_unit() * FLY_JITTER), false); } @@ -1587,7 +1586,7 @@ static void tadpole_init(Entity_Effect& tadpole) { tadpole.sprite.Play("Idle"); tadpole.rotation = angle_normalized(random_unit() * FULL_TURN_DEGREES); - tadpole.sprite.GetLayer(0)->rotation = tadpole.rotation + HALF_TURN; + tadpole.sprite.GetLayer(0)->rotation = tadpole.rotation + HALF_TURN_DEGREES; tadpole.height = 0; tadpole.isUnknown176 = true; } @@ -1653,7 +1652,7 @@ static void tadpole_update(Entity_Effect& tadpole) break; } if (tadpole.isDead) bug_splat(tadpole, 0); - tadpole.sprite.GetLayer(0)->rotation = tadpole.rotation + HALF_TURN; + tadpole.sprite.GetLayer(0)->rotation = tadpole.rotation + HALF_TURN_DEGREES; } // A lil ghost starts where it was spawned with a random heading, size, speed and faintness, pale violet in the dark diff --git a/src/entity_effect_blast.cpp b/src/entity_effect_blast.cpp index b5e1205..b3cbdb5 100644 --- a/src/entity_effect_blast.cpp +++ b/src/entity_effect_blast.cpp @@ -65,7 +65,6 @@ constexpr float BLAST_PUSH = 3; constexpr float BLAST_TICK_SHARE = 50; constexpr float SMALL_BLAST_TICK_SHARE = 8; constexpr uint64_t BLAST_DAMAGE_FLAGS = DAMAGE_EXPLOSION | DAMAGE_CRUSH; -constexpr int BLAST_HIT_COUNTDOWN = 30; constexpr int BEAN_FREEZE = -50; constexpr int BEAN_POISON = 90; constexpr float BEAN_POISON_DAMAGE = 5; @@ -81,8 +80,6 @@ constexpr float DEBRIS_TRAIL = 50; constexpr float DEBRIS_SCATTER = 50; constexpr float DEBRIS_SPEED_MIN = 4; constexpr float DEBRIS_SPEED_SPAN = 4; -constexpr float BLAST_DUST_SPIN_MIN = 2; -constexpr float BLAST_DUST_SPIN_SPAN = 10; constexpr int BLAST_DUST_LIFE_MIN = 10; constexpr int BLAST_DUST_LIFE_SPAN = 10; constexpr float BLAST_DUST_ALPHA_MIN = 0.2f; @@ -230,7 +227,7 @@ static bool blast_first_hit(Entity_Effect& blast, Entity& entity, float damage) { if (EntityList::HitListContains(blast.hitList, entity)) return false; hit_list_insert(blast.hitList, entity); - entity.TakeDamage(damage, BLAST_DAMAGE_FLAGS, EntityRef(blast.spawnerEntity.get()), BLAST_HIT_COUNTDOWN); + entity.TakeDamage(damage, BLAST_DAMAGE_FLAGS, EntityRef(blast.spawnerEntity.get()), HIT_COUNTDOWN); return true; } @@ -250,7 +247,7 @@ static void blast_entity_hit(Entity_Effect& blast, Entity& entity, float tickDam entity.AddPoison(source, BEAN_POISON, BEAN_POISON_DAMAGE, false); } else if (blast.variant != EFFECT_MEGA_BEAN_EXPLOSION) - entity.TakeDamage(tickDamage, BLAST_DAMAGE_FLAGS, source, BLAST_HIT_COUNTDOWN); + entity.TakeDamage(tickDamage, BLAST_DAMAGE_FLAGS, source, HIT_COUNTDOWN); return; } @@ -264,7 +261,7 @@ static void blast_entity_hit(Entity_Effect& blast, Entity& entity, float tickDam else if (entity.is_slot()) { entity.AddVelocity(blast_push(blast, entity), false); - if (!entity.isDead) entity.TakeDamage(damage, BLAST_DAMAGE_FLAGS, source, BLAST_HIT_COUNTDOWN); + if (!entity.isDead) entity.TakeDamage(damage, BLAST_DAMAGE_FLAGS, source, HIT_COUNTDOWN); } else if (entity.is_pickup()) { @@ -286,7 +283,7 @@ static void blast_dust_throw(Entity_Effect& blast, Vector cell, Vector spot, Vec auto* dust = static_cast(g_game->Spawn( {.position = spot, .velocity = velocity, .type = ENTITY_EFFECT, .variant = EFFECT_DUST_CLOUD, .seed = seed})); float side = vector_dot(vector_sub(dust->pos, cell), vector_make(direction.y, -direction.x)) < 0 ? -1.0f : 1.0f; - dust->rotation = (random_unit() * BLAST_DUST_SPIN_SPAN + BLAST_DUST_SPIN_MIN) * side; + dust->rotation = (random_between(DUST_SPIN_MIN, DUST_SPIN_RANGE)) * side; dust->SetTimeout(random_below(BLAST_DUST_LIFE_SPAN) + BLAST_DUST_LIFE_MIN); if (blast.subtype == 2) { diff --git a/src/entity_effect_boss.cpp b/src/entity_effect_boss.cpp index 4dd2b60..0021df6 100644 --- a/src/entity_effect_boss.cpp +++ b/src/entity_effect_boss.cpp @@ -28,7 +28,6 @@ constexpr float CRACK_STRIKE_DAMAGE = 20; constexpr float CRACK_HOSTILE_DAMAGE = 2; constexpr float CRACK_VERSUS_HIT_DAMAGE = 7; constexpr int CRACK_HIT_SPACING = 3; -constexpr int CRACK_HIT_COUNTDOWN = 30; constexpr int CRACK_SHAKE = 5; // The crater it leaves. constexpr int CRACK_CRATER_SUBTYPE = 1; @@ -82,12 +81,12 @@ static void crack_hit(Entity_Effect& crack) effect_tear_flags_set(crack, flags); } float damage = isVersus ? CRACK_VERSUS_HIT_DAMAGE : CRACK_HOSTILE_DAMAGE; - entity->TakeDamage(damage, damageFlags, EntityRef(source), CRACK_HIT_COUNTDOWN); + entity->TakeDamage(damage, damageFlags, EntityRef(source), HIT_COUNTDOWN); } else if (entity->type >= CRACK_NPC_TYPE_FIRST) { float damage = isHostile ? CRACK_HOSTILE_DAMAGE : crack.collisionDamage; - entity->TakeDamage(damage, 0, EntityRef(source), CRACK_HIT_COUNTDOWN); + entity->TakeDamage(damage, 0, EntityRef(source), HIT_COUNTDOWN); } } if (crack.subtype == CRACK_PLAYER) crack.subtype = CRACK_PLAYER_STRUCK; @@ -202,7 +201,6 @@ constexpr float HUSH_LASER_PLAYER_PULL = 1.1f; constexpr float HUSH_LASER_FRICTION = 0.8f; constexpr int HUSH_LASER_HIT_SPACING = 2; constexpr float HUSH_LASER_DAMAGE = 2; -constexpr int HUSH_LASER_HIT_COUNTDOWN = 30; constexpr int HUSH_LASER_TRAIL_SPACING = 5; constexpr int HUSH_LASER_TRAIL_PRIORITY = 255; constexpr ColorMod HUSH_LASER_TRAIL_COLOR = {{0, 0, 0, 0.8f}, {0, 0, 0, 0}, {17 / 255.0f, 159 / 255.0f, 225 / 255.0f}}; @@ -227,7 +225,7 @@ static void hush_laser_hit(Entity_Effect& laser) if (vector_length_squared(vector_sub(victim.pos, laser.pos)) >= reach * reach) return; if (victim.isDead || victim.entityCollisionClass == ENTCOLL_NONE) return; - victim.TakeDamage(HUSH_LASER_DAMAGE, 0, EntityRef(source), HUSH_LASER_HIT_COUNTDOWN); + victim.TakeDamage(HUSH_LASER_DAMAGE, 0, EntityRef(source), HIT_COUNTDOWN); }; if (isFriendly) diff --git a/src/entity_effect_combat.cpp b/src/entity_effect_combat.cpp index 7a2d094..b89ea47 100644 --- a/src/entity_effect_combat.cpp +++ b/src/entity_effect_combat.cpp @@ -305,7 +305,6 @@ constexpr float WORM_STEP_SPEED_SQUARED = 1; constexpr float WORM_TEAR_RANGE = 5; constexpr float WORM_STILL_SPEED_SQUARED = 1; -constexpr float HALF_TURN = 180; constexpr float SPRITE_UP = 90; static CombatEffect variant_get(const Entity_Effect& effect) @@ -328,8 +327,8 @@ bool is_combat_effect(int variant) static float angle_wrap(float angle) { if (std::fabs(angle) > FULL_TURN_DEGREES) angle = std::fmod(angle, FULL_TURN_DEGREES); - if (angle > HALF_TURN) return angle - FULL_TURN_DEGREES; - if (angle < -HALF_TURN) return angle + FULL_TURN_DEGREES; + if (angle > HALF_TURN_DEGREES) return angle - FULL_TURN_DEGREES; + if (angle < -HALF_TURN_DEGREES) return angle + FULL_TURN_DEGREES; return angle; } @@ -369,7 +368,7 @@ void game_particles_spawn(const ParticleSpawn& spawn) for (int i = 0; i < spawn.count; i++) { uint32_t seed = Random(); - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; Vector velocity = vector_make(std::cos(angle) * spawn.speed, std::sin(angle) * HALF * spawn.speed); auto* particle = static_cast( @@ -479,7 +478,7 @@ static void dust_cloud_init(Entity_Effect& effect) int frame = clouds->length == 0 ? 0 : (int)(Random() % (uint32_t)clouds->length); effect.sprite.SetFrame(clouds->name, frame); effect.sprite.isFlipX = !(Random() & 1); - effect.sprite.rotation = random_unit() * FULL_TURN_DEGREES - HALF_TURN; + effect.sprite.rotation = random_unit() * FULL_TURN_DEGREES - HALF_TURN_DEGREES; effect.sprite.scale = vector_make(DUST_SCALE, DUST_SCALE); effect.renderZOffset = POOF_RENDER_Z; if (effect.subtype == DUST_DARK) effect.sprite.color = {{1, 1, 1, 1}, {}, {DUST_DARKEN, DUST_DARKEN, DUST_DARKEN}}; diff --git a/src/entity_effect_dogma.cpp b/src/entity_effect_dogma.cpp index 2c7f6f1..79f9bec 100644 --- a/src/entity_effect_dogma.cpp +++ b/src/entity_effect_dogma.cpp @@ -83,7 +83,6 @@ constexpr float ORB_FAN_TURN = 45; constexpr int ORB_FAN_EXTRA_FRAMES = 12; constexpr float ORB_FAN_SCALE = 2; constexpr int ORB_HIT_PERIOD = 5; -constexpr int ORB_HIT_COUNTDOWN = 30; // The beam guide a spot draws: a line out from it, fading in over its first 15 frames and out over its life, and in // its last 5 frames thickening as it fades. It turns half a frame ahead on even frames. @@ -315,7 +314,7 @@ static void dogma_orb_hits_update(Entity_Effect& orb) if (EntityList::HitListContains(orb.hitList, *entity)) continue; hit_list_insert(orb.hitList, *entity); float damage = entity->IsEnemy() ? orb.collisionDamage : 1; - entity->TakeDamage(damage, 0, EntityRef(&orb), ORB_HIT_COUNTDOWN); + entity->TakeDamage(damage, 0, EntityRef(&orb), HIT_COUNTDOWN); } } diff --git a/src/entity_effect_floor.cpp b/src/entity_effect_floor.cpp index 1773474..cece4fb 100644 --- a/src/entity_effect_floor.cpp +++ b/src/entity_effect_floor.cpp @@ -552,7 +552,6 @@ constexpr float PUDDLE_BUBBLE_SPREAD = 4; constexpr float PUDDLE_SCREEN_SCALE = 0.65f; constexpr float PUDDLE_TEXEL_ALPHA = 0.5f; constexpr float PUDDLE_DAMAGE = 1; -constexpr int PUDDLE_HIT_COUNTDOWN = 30; constexpr int PUDDLE_FADE_FRAMES = 15; constexpr int PUDDLE_SORTING_Z = 2000; constexpr std::string_view POOP_BUBBLE_SHEET = "gfx/effects/poop_bubble.png"; @@ -596,7 +595,7 @@ static void colostomia_player_burn(Entity_Effect& puddle, Entity_Player& player) .alphaThreshold = PUDDLE_TEXEL_ALPHA, .layerId = 0}); if (texel._alpha <= PUDDLE_TEXEL_ALPHA) return; - player.TakeDamage(PUDDLE_DAMAGE, DAMAGE_ACID, EntityRef(&puddle), PUDDLE_HIT_COUNTDOWN); + player.TakeDamage(PUDDLE_DAMAGE, DAMAGE_ACID, EntityRef(&puddle), HIT_COUNTDOWN); player.AddEntityFlags(FLAG_SLIPPERY_PHYSICS); player.SetFootprintColor(texel, false); } diff --git a/src/entity_effect_helpers.cpp b/src/entity_effect_helpers.cpp index 798b1c5..4397c73 100644 --- a/src/entity_effect_helpers.cpp +++ b/src/entity_effect_helpers.cpp @@ -181,7 +181,6 @@ constexpr float MR_ME_HIT_DAMAGE = 3; constexpr int MR_ME_HIT_PERIOD = 10; constexpr int MR_ME_VERSUS_HIT_PERIOD = 16; constexpr int MR_ME_VERSUS_FRAMES = 600; -constexpr int MR_ME_HIT_COUNTDOWN = 30; constexpr int MR_ME_FLASH_FRAMES = 5; constexpr int MR_ME_FLASH_PRIORITY = 200; constexpr int MR_ME_TARGET_PRIORITY = 255; @@ -511,7 +510,7 @@ static Vector mr_me_work(Entity_Effect& helper, MrMeData& data) if (helper.IsFrame(period, 0) && vector_length_squared(vector_sub(helper.pos, child->pos)) < helper.size * helper.size) { - child->TakeDamage(MR_ME_HIT_DAMAGE, 0, EntityRef(helper.parent), MR_ME_HIT_COUNTDOWN); + child->TakeDamage(MR_ME_HIT_DAMAGE, 0, EntityRef(helper.parent), HIT_COUNTDOWN); helper.SetColor(MR_ME_FLASH_COLOR, MR_ME_FLASH_FRAMES, MR_ME_FLASH_PRIORITY, true, true); } return move; diff --git a/src/entity_effect_items.cpp b/src/entity_effect_items.cpp index 8f12120..5b806b8 100644 --- a/src/entity_effect_items.cpp +++ b/src/entity_effect_items.cpp @@ -47,7 +47,6 @@ constexpr ColorMod FOOT_POOF_COLOR = {{0.62f, 0.62f, 0.62f, 0.8f}, {0, 0, 0, 0}, constexpr float FIRE_FRICTION = 0.95f; constexpr int FIRE_HIT_RESET_FRAMES = 5; constexpr int FIRE_LIFESPAN = 300; -constexpr int FIRE_HIT_COUNTDOWN = 30; constexpr float FIRE_SHRINK = 0.25f; constexpr float FIRE_MIN_DAMAGE_SCALE = 0.5f; constexpr float FIRE_ENEMY_REACH = 5; @@ -73,9 +72,6 @@ constexpr float FIRE_JET_PLAYER_THRESHOLD = 30; constexpr float DEATH_SKULL_HEIGHT = -30; constexpr int DEATH_SKULL_LINGER = 2; -// Mom's hand from Emergency Contact lands on its target for its damage. -constexpr int MOMS_HAND_HIT_COUNTDOWN = 30; - // The Ultra Death scythe falls 0.7 faster each frame and goes 120 below the room. constexpr float SCYTHE_FALL = 0.7f; constexpr float SCYTHE_FALL_MARGIN = 120; @@ -256,7 +252,7 @@ static bool fire_hit(Entity_Effect& fire, Entity& entity, float damage, uint64_t if (EntityList::HitListContains(fire.hitList, entity)) return false; hit_list_insert(fire.hitList, entity); - return entity.TakeDamage(damage, damageFlags, EntityRef(&fire), FIRE_HIT_COUNTDOWN); + return entity.TakeDamage(damage, damageFlags, EntityRef(&fire), HIT_COUNTDOWN); } // Whether a burnable entity is one a fire may hurt now: alive, collidable, not friendly and, for an item fire, no @@ -647,7 +643,7 @@ static void moms_hand_update(Entity_Effect& hand) { if (hand.sprite.IsEventTriggered("Land") && hand.target && hand.target->isExists) { - hand.target->TakeDamage(hand.collisionDamage, 0, EntityRef(&hand), MOMS_HAND_HIT_COUNTDOWN); + hand.target->TakeDamage(hand.collisionDamage, 0, EntityRef(&hand), HIT_COUNTDOWN); effect_sound_play(SOUND_FORESTBOSS_STOMPS); } if (hand.sprite.IsFinished("JumpDown")) hand.sprite.Play("Grab"); @@ -1082,7 +1078,7 @@ static void spear_update(Entity_Effect& spear) if (!isHittable || EntityList::HitListContains(spear.hitList, *entity)) continue; float damage = params.tearDamage * (isGuardian ? 1 : SPEAR_DAMAGE_SCALE); - entity->TakeDamage(damage, 0, EntityRef(&spear), FIRE_HIT_COUNTDOWN); + entity->TakeDamage(damage, 0, EntityRef(&spear), HIT_COUNTDOWN); if (entity->IsBoss()) entity->AddFear(EntityRef(spear.parent.get()), SPEAR_FEAR_FRAMES, false); hit_list_insert(spear.hitList, *entity); } @@ -1121,7 +1117,7 @@ static void brown_cloud_sting(Entity_Effect& cloud) { if (!entity->IsVulnerableEnemy(nullptr) || cloud.IsDescendantOf(entity)) continue; if (EntityList::HitListContains(cloud.hitList, *entity)) continue; - entity->TakeDamage(damage, 0, EntityRef(&cloud), FIRE_HIT_COUNTDOWN); + entity->TakeDamage(damage, 0, EntityRef(&cloud), HIT_COUNTDOWN); hit_list_insert(cloud.hitList, *entity); } for (Entity* tear : entity_query_radius(cloud.pos, reach, QUERY_TEARS)) @@ -1200,7 +1196,7 @@ static void boomerang_update(Entity_Effect& boomerang) if (entity->isDead || entity->entityCollisionClass == ENTCOLL_NONE) continue; if (EntityList::HitListContains(boomerang.hitList, *entity)) continue; - entity->TakeDamage(boomerang.collisionDamage, 0, EntityRef(&boomerang), FIRE_HIT_COUNTDOWN); + entity->TakeDamage(boomerang.collisionDamage, 0, EntityRef(&boomerang), HIT_COUNTDOWN); entity->AddFreeze(EntityRef(&boomerang), BOOMERANG_FREEZE, false); entity->AddVelocity(boomerang.velocity, false); hit_list_insert(boomerang.hitList, *entity); diff --git a/src/entity_effect_portal.cpp b/src/entity_effect_portal.cpp index f14188b..c76503f 100644 --- a/src/entity_effect_portal.cpp +++ b/src/entity_effect_portal.cpp @@ -40,11 +40,10 @@ constexpr std::array PORTAL_COLORS = {{ {{0.6f, 1, 0.6f, 1}, {0, 1.8f, 0, 1}, {0, 0, 0}}, }}; constexpr std::string_view WOMB_HOLE_ORANGE_SHEET = "gfx/Effects/wombhole_orange.png"; -constexpr float BYTE_SCALE = 1.0f / 255; constexpr ColorMod ORANGE_WISP_BODY = { - {400 * BYTE_SCALE, 250 * BYTE_SCALE, 60 * BYTE_SCALE, 1}, {0, 0, 0, 0}, {0, 0, 0}}; + {400 * BYTE_TO_UNIT, 250 * BYTE_TO_UNIT, 60 * BYTE_TO_UNIT, 1}, {0, 0, 0, 0}, {0, 0, 0}}; constexpr ColorMod ORANGE_WISP_FLAME = { - {300 * BYTE_SCALE, 200 * BYTE_SCALE, 10 * BYTE_SCALE, 1}, {0, 0, 0, 0}, {0, 0, 0}}; + {300 * BYTE_TO_UNIT, 200 * BYTE_TO_UNIT, 10 * BYTE_TO_UNIT, 1}, {0, 0, 0, 0}, {0, 0, 0}}; constexpr int WISP_ORBIT_LAYER = 9; // The portal states: closed, opening, open, taking a player in, and letting one out. diff --git a/src/entity_effect_shots.cpp b/src/entity_effect_shots.cpp index c962237..a03d94c 100644 --- a/src/entity_effect_shots.cpp +++ b/src/entity_effect_shots.cpp @@ -127,7 +127,6 @@ constexpr float SWIRL_PULL = 14; constexpr float TECH_DOT_PULL = 8; constexpr float SWIRL_PULL_RANGE = 250; constexpr int SWIRL_HIT_FRAMES = 3; -constexpr int SWIRL_HIT_COUNTDOWN = 30; constexpr int TECH_DOT_LASER_TIMEOUT = 10; constexpr int TECH_DOT_LIFE = 90; constexpr int DOGMA_DOT_LIFE = 60; @@ -200,7 +199,7 @@ static void swirl_enemy_hurt(Entity_Effect& swirl, Entity& enemy, Entity_Player* params = player->GetTearHitParams(WEAPON_LASER, 1, 0, swirl.spawnerEntity.get()); damageFlags = tear_damage_flags_get(params.tearFlags, &swirl); } - enemy.TakeDamage(swirl.collisionDamage, damageFlags, EntityRef(&swirl), SWIRL_HIT_COUNTDOWN); + enemy.TakeDamage(swirl.collisionDamage, damageFlags, EntityRef(&swirl), HIT_COUNTDOWN); if (isDot) hit_list_insert(swirl.hitList, enemy); if (player) Entity_Tear::ApplyTearFlagEffects(&enemy, swirl.pos, params.tearFlags, &swirl, swirl.collisionDamage); } @@ -287,7 +286,6 @@ static void swirl_update(Entity_Effect& swirl) // then runs from it to its child (or its player), and a strike lengthens Judas' Dark Arts effect. constexpr int SNARE_HOLD_FRAMES = 4; constexpr int SNARE_TINT_PRIORITY = 1; -constexpr int SNARE_HIT_COUNTDOWN = 30; constexpr int SNARE_SOUND_DELAY = 1; constexpr float SNARE_PITCH_MIN = 1.5f; constexpr float SNARE_PITCH_SPAN = 0.2f; @@ -301,7 +299,6 @@ constexpr int SNARE_JUDAS_FRAMES = 4; constexpr int SNARE_FRAMES_PER_COUNT = 30; constexpr ColorMod SNARE_HOLD_TINT = {{0.5f, 0.5f, 0.5f, 1}, {0, 0, 0, 0}, {0, 0, 0}}; constexpr ColorMod SNARE_POOF_TINT = {{0.2f, 0.2f, 0.2f, 0.8f}, {0, 0, 0, 0}, {0, 0, 0}}; -constexpr ColorMod SNARE_TRAIL_TINT = {{0, 0, 0, 1}, {0, 0, 0, 0}, {0, 0, 0}}; // Part of 005cdb20 (Init's case 194) The snare lies on the floor, its shadow showing. static void dark_snare_init(Entity_Effect& snare) @@ -322,7 +319,7 @@ static bool dark_snare_strike(Entity_Effect& snare) } if (!target->IsEnemy() || target->isDead) return false; - target->TakeDamage(snare.collisionDamage, 0, EntityRef(&snare), SNARE_HIT_COUNTDOWN); + target->TakeDamage(snare.collisionDamage, 0, EntityRef(&snare), HIT_COUNTDOWN); Entity_Tear::ApplyTearFlagEffects(target, snare.pos, effect_tear_flags(snare), &snare, snare.collisionDamage); Entity* spawner = snare.spawnerEntity; if (!target->HasMortalDamage() || !spawner || !spawner->is_player()) return true; diff --git a/src/entity_effect_souls.cpp b/src/entity_effect_souls.cpp index 6542382..8e53524 100644 --- a/src/entity_effect_souls.cpp +++ b/src/entity_effect_souls.cpp @@ -64,7 +64,6 @@ constexpr float HUNGRY_SOUL_FRICTION = 0.95f; constexpr float HUNGRY_SOUL_STOP_FRICTION = 0.8f; constexpr int HUNGRY_SOUL_HIT_RESET_FRAMES = 8; constexpr float HUNGRY_SOUL_BITE_SHARE = 0.5f; -constexpr int SOUL_HIT_COUNTDOWN = 30; constexpr float HUNGRY_SOUL_PITCH_MIN = 0.9f; constexpr float HUNGRY_SOUL_PITCH_SPAN = 0.2f; constexpr int HUNGRY_SOUL_SHAKE = 6; @@ -253,7 +252,7 @@ static void hungry_soul_bite(Entity_Effect& soul, Entity_Player& player) for (Entity* enemy : entity_query_radius(soul.pos, soul.size, QUERY_ENEMIES)) { if (!enemy->IsVulnerableEnemy(&player) || EntityList::HitListContains(soul.hitList, *enemy)) continue; - enemy->TakeDamage(player.meleeDamage * HUNGRY_SOUL_BITE_SHARE, 0, EntityRef(&soul), SOUL_HIT_COUNTDOWN); + enemy->TakeDamage(player.meleeDamage * HUNGRY_SOUL_BITE_SHARE, 0, EntityRef(&soul), HIT_COUNTDOWN); hit_list_insert(soul.hitList, *enemy); } } @@ -374,7 +373,7 @@ static void dead_bird_update(Entity_Effect& bird) { for (Entity* entity : entity_query_capsule(bird.GetCollisionCapsule({}), QUERY_ENEMIES)) if (entity->IsVulnerableEnemy(&bird)) - entity->TakeDamage(bird.collisionDamage, 0, EntityRef(nullptr), SOUL_HIT_COUNTDOWN); + entity->TakeDamage(bird.collisionDamage, 0, EntityRef(nullptr), HIT_COUNTDOWN); } float lastSpeed = vector_length(bird.velocity); diff --git a/src/entity_effect_vortex.cpp b/src/entity_effect_vortex.cpp index 0872795..dfe4133 100644 --- a/src/entity_effect_vortex.cpp +++ b/src/entity_effect_vortex.cpp @@ -294,7 +294,6 @@ constexpr float RIFT_SHOT_HOVER = 0.3f; constexpr int RIFT_SHOT_SAFE_FRAMES = 15; constexpr float RIFT_SHOT_LOWEST = -50; constexpr int RIFT_HIT_PERIOD = 10; -constexpr int RIFT_HIT_COUNTDOWN = 30; constexpr float RIFT_ATTRACT_STRENGTH = 20; constexpr float RIFT_ATTRACT_RADIUS = 250; @@ -324,7 +323,7 @@ static void rift_pull(Entity_Effect& rift, Entity& entity, float strength) pull *= strength; if (rift.IsFrame(RIFT_HIT_PERIOD, 0) && entity.IsEnemy() && distance < entity.size + rift.size && is_laser_target(entity)) - entity.TakeDamage(rift.collisionDamage, DAMAGE_LASER, EntityRef(rift.parent), RIFT_HIT_COUNTDOWN); + entity.TakeDamage(rift.collisionDamage, DAMAGE_LASER, EntityRef(rift.parent), HIT_COUNTDOWN); float nearness = distance < RIFT_NEAR ? distance / RIFT_NEAR_SHARE : 1 / distance; pull = pull * nearness / entity.friction; @@ -347,7 +346,7 @@ static void rift_hits_update(Entity_Effect& rift, Entity_Player* player) { if (entity == player || is_critter_eaten(*entity) || !is_laser_target(*entity)) continue; uint64_t damageFlags = laser_effects_apply(rift, *entity, player); - entity->TakeDamage(rift.collisionDamage, damageFlags, EntityRef(rift.parent), RIFT_HIT_COUNTDOWN); + entity->TakeDamage(rift.collisionDamage, damageFlags, EntityRef(rift.parent), HIT_COUNTDOWN); } } @@ -403,7 +402,6 @@ static void rift_update(Entity_Effect& rift) constexpr float BALL_SHRINK_SCALE = 1.5f; constexpr float BALL_FADE = 0.8f; constexpr float BALL_OCCULT_SPEED = 3; -constexpr float BALL_OCCULT_FRICTION = 0.8f; constexpr float BALL_HOMING_LOOKAHEAD = 5; constexpr float BALL_HOMING_RANGE = 100; constexpr int BALL_HOMING_PERIOD = 5; @@ -425,7 +423,6 @@ constexpr int BALL_SPLAT_SUBTYPE = 2; constexpr int BALL_SPLAT_PRIORITY = 255; constexpr float BALL_SPLAT_VOLUME = 0.7f; constexpr int BALL_SPLAT_DELAY = 8; -constexpr int BALL_HIT_COUNTDOWN = 30; constexpr ColorMod BALL_SPLAT_TINT = color_make({2, 1, 1, 1}); // The brimstone ball part of 005cdb20 (Init): it appears. @@ -511,7 +508,7 @@ static void brimstone_ball_hits_update(Entity_Effect& ball, Entity_Player* playe brimstone_ball_splatter(ball, *entity); damage = damage * BALL_MARK_DAMAGE_SCALE + BALL_MARK_DAMAGE_BONUS; } - entity->TakeDamage(damage, damageFlags, EntityRef(ball.parent), BALL_HIT_COUNTDOWN); + entity->TakeDamage(damage, damageFlags, EntityRef(ball.parent), HIT_COUNTDOWN); } } @@ -545,7 +542,7 @@ static void brimstone_ball_update(Entity_Effect& ball) player->GetMouseAimTarget(aim, false); if (!vector_is_zero(aim)) ball.velocity = vector_add(ball.velocity, vector_scale(vector_normalized(aim), player->shotSpeed * BALL_OCCULT_SPEED)); - ball.friction = BALL_OCCULT_FRICTION; + ball.friction = OCCULT_FRICTION; } if (flags[TEAR_HOMING]) brimstone_ball_home(ball); if (flags[TEAR_GROW]) diff --git a/src/entity_factory.cpp b/src/entity_factory.cpp index becc7a7..a4b4883 100644 --- a/src/entity_factory.cpp +++ b/src/entity_factory.cpp @@ -179,7 +179,6 @@ constexpr uint32_t ROOM_CONFIG_FLAG_AFTERBIRTH_HAZARDS = 1 << 3; constexpr int STAGE_BACKWARDS_LAST = 6; constexpr int STAGE_LABYRINTH_SHIFT = 1; constexpr uint32_t CURSE_LABYRINTH = 1 << 1; -constexpr int SPECIAL_DAILY_GOLDEN_FATTY = 7; constexpr int CHALLENGE_GOLDEN_FATTY = 32; template static std::unique_ptr entity_make() @@ -339,8 +338,7 @@ Entity* game_spawn(const EntitySpawn& request, PoolMode mode) EntitySpawn spawn = request; lua_engine_get().Callback_PreEntitySpawn(spawn); if (game.deathmatchManager.state >= DEATHMATCH_INTRO) - reconstruction_missing("Game::SpawnEx 006fe410: a versus match's " - "blacklisted pickups (0042b560)"); + game.deathmatchManager.type->pickup_replace_banned(spawn.type, spawn.variant, spawn.subType); Entity* spawner = spawn.spawner; int variant = spawn.variant; @@ -364,9 +362,10 @@ Entity* game_spawn(const EntitySpawn& request, PoolMode mode) std::set>& triggers = game.proceduralItemManager.spawnTriggerTargets; bool isTriggered = triggers.contains({entity->type, entity->variant}) || triggers.contains({entity->type, -1}); - if (entity->isExists && !game.proceduralItemManager.proceduralItems.empty() && isTriggered && - !game.playerManager.playerList.empty()) - reconstruction_missing("trigger_set_dispatch 009e0680: a TMTRAINER item's spawn trigger"); + if (entity->isExists && !game.proceduralItemManager.proceduralItems.empty() && isTriggered) + for (size_t i = 0; i < game.playerManager.playerList.size(); i++) + glitched_items_trigger(*game.playerManager.playerList[i], + {spawn.position, spawn.velocity, entity, CONDITION_ENTITY_SPAWN}); g_entitySpawnTimeMs += GetTimeNs() / NS_PER_MS - startMs; return entity; @@ -601,7 +600,7 @@ static bool enemy_variant_transform(Room& room, RoomEntry& entry, int stage, int switch (entry.type) { case ENTITY_STONEY: - if (game.dailyChallenge.specialDailyId == SPECIAL_DAILY_GOLDEN_FATTY || + if (game.dailyChallenge.specialDailyId == SPECIAL_DAILY_APRIL_FOOLS || game.challenge == CHALLENGE_GOLDEN_FATTY) return roll(true, 5, 1, 10); return false; diff --git a/src/entity_familiar.cpp b/src/entity_familiar.cpp index 1a15cb6..38ee65b 100644 --- a/src/entity_familiar.cpp +++ b/src/entity_familiar.cpp @@ -410,7 +410,7 @@ void Entity_Familiar::Init(int initType, int initVariant, int initSubtype, uint3 variant_init(kept); if (overwrite_limit() < 0) flags |= FLAG_DONT_OVERWRITE; - if (familiar_versus()) reconstruction_missing("Entity_Familiar::Init 0060de70 (a versus match's familiar)"); + if (familiar_versus()) g_game->deathmatchManager.type->entity_damage_adjust(*this); if (variant == BUM_FRIEND || variant == DARK_BUM || variant == KEY_BUM || variant == SUPER_BUM) sprite.Play("FloatDown"); if (variant == ISAACS_HEART) player->isaacsHeart = this; diff --git a/src/entity_knife.cpp b/src/entity_knife.cpp index 80449d0..f15b8d2 100644 --- a/src/entity_knife.cpp +++ b/src/entity_knife.cpp @@ -140,7 +140,6 @@ constexpr int KNIFE_HIT_REFRESH = 3; constexpr int SCYTHE_HIT_REFRESH = 5; constexpr int SCYTHE_WAIT_HIT_REFRESH = 10; constexpr float GRID_STEP = 40; -constexpr int KNIFE_HIT_COUNTDOWN = 30; // Local until entity_player_weapons.cpp drops its copy for the shared PlayerItemId enum. constexpr float KNIFE_BRIDGE_TURN = 90; constexpr float KNIFE_TURN_QUARTER = 90; @@ -265,7 +264,7 @@ void tear_flags_area_apply(const Vector& position, Entity* source, float radius, for (Entity* enemy : entity_query_radius(position, radius, QUERY_ENEMIES)) { if (!enemy->IsVulnerableEnemy(nullptr)) continue; - enemy->TakeDamage(damage, 0, EntityRef(source), KNIFE_HIT_COUNTDOWN); + enemy->TakeDamage(damage, 0, EntityRef(source), HIT_COUNTDOWN); Entity_Tear::ApplyTearFlagEffects(enemy, position, flags, source, damage); } } @@ -1721,7 +1720,7 @@ bool Entity_Knife::HandleCollision(Entity* collider, bool isLow) } uint64_t damageFlags = tear_damage_flags_get(flags, this); - collider->TakeDamage(damage, damageFlags, EntityRef(this), KNIFE_HIT_COUNTDOWN); + collider->TakeDamage(damage, damageFlags, EntityRef(this), HIT_COUNTDOWN); if (collider->type == ENTITY_FIREPLACE) return true; Entity_Tear::ApplyTearFlagEffects(collider, pos, flags, this, damage); diff --git a/src/entity_knife_hits.cpp b/src/entity_knife_hits.cpp index b80349b..0e0b5dc 100644 --- a/src/entity_knife_hits.cpp +++ b/src/entity_knife_hits.cpp @@ -148,7 +148,6 @@ constexpr int BURST_TRAIL_DEPTH = -400; constexpr float KNIFE_SPLIT_SCALE = 0.8f; constexpr float SPLIT_ANGLE = 90; constexpr float SHARD_CRAWLSPACE_OFFSET_Y = -18; -constexpr float RANDOM_HALF_TURN_KNIFE = 3.14f; // The tear effects a shard or stuck tear does not inherit. constexpr std::array QUAD_SHARD_DROPPED = {TEAR_EXPLOSIVE, TEAR_QUADSPLIT, TEAR_SPLIT, TEAR_LUDOVICO, TEAR_BONE_FLAG, @@ -889,7 +888,7 @@ void Entity_Knife::apply_hit_effects(const KnifeHit& hit) for (int i = 0; i < count; i++) { uint32_t seed = Random(); - float angle = random_unit() * RANDOM_HALF_TURN_KNIFE; + float angle = random_unit() * PI_ROUGH; angle += angle; Vector velocity = vector_make(std::cos(angle) * shardSpeed, std::sin(angle) * shardSpeed); Entity_Tear& tear = *static_cast(g_game->Spawn({.position = shardPosition, @@ -1026,7 +1025,7 @@ void Entity_Knife::apply_hit_effects(const KnifeHit& hit) if (tearFlags[TEAR_BONE_FLAG]) for (int i = 0; i < 2; i++) { - float angle = random_unit() * RANDOM_HALF_TURN_KNIFE; + float angle = random_unit() * PI_ROUGH; angle += angle; Vector velocity = vector_make(std::cos(angle) * shardSpeed, std::sin(angle) * shardSpeed); Entity_Tear& shard = bone_shard_spawn(*this, shardPosition, velocity, player); diff --git a/src/entity_laser_hits.cpp b/src/entity_laser_hits.cpp index d5c6814..56e5fe0 100644 --- a/src/entity_laser_hits.cpp +++ b/src/entity_laser_hits.cpp @@ -31,7 +31,6 @@ constexpr float ATTRACTOR_SOFT_RANGE = 100; constexpr float HIT_SHOT_INTERVAL = 4; constexpr float HIT_CREEP_MARGIN = 15; constexpr float HIT_CREEP_SCALE = 0.4f; -constexpr float STICKING_TEAR_SCALE_MIN = 0.01f; constexpr int CULTIST_STUCK_VARIANT = 10; constexpr float IMPACT_EXPLOSION_INTERVAL = 4; constexpr float RING_CONTINUUM_WRAP_MARGIN = -200; @@ -44,7 +43,6 @@ constexpr float IMPACT_EXPLOSION_REACH = 30; constexpr float IMPACT_EXPLOSION_GROWTH = 10; constexpr float IMPACT_EXPLOSION_PUSH = 10; constexpr float IMPACT_EXPLOSION_DAMAGE = 10; -constexpr float IMPACT_SPLIT_HALF_TURN = 3.14f; constexpr float IMPACT_SPLIT_SPEED = 10; constexpr float IMPACT_SPLIT_BACKSTEP = 4; constexpr float IMPACT_SPLIT_HEIGHT = -11.875f; @@ -69,7 +67,6 @@ constexpr float SPLASH_SPEED_MIN = 4; constexpr float SPLASH_SPEED_RANGE = 6; constexpr float SPLASH_SPREAD = 3; constexpr float SPLASH_SCALE = 2; -constexpr float SPLASH_HALF_TURN = 3.14f; constexpr float MARKED_SPLASH_SPEED_MIN = 2; constexpr float MARKED_SPLASH_SPEED_RANGE = 2; constexpr float MARKED_TINT_RED = 2; @@ -78,7 +75,6 @@ constexpr float MARKED_SOUND_VOLUME = 0.7f; constexpr int MARKED_SOUND_DELAY = 8; constexpr float MARKED_DAMAGE_EXTRA = 3; constexpr float PLAYER_HIT_DAMAGE = 1; -constexpr int LASER_HIT_COUNTDOWN = 30; constexpr int GRID_HURT_CHANCE_MASK = 3; constexpr int SHIELD_RING_CHANCE = 50; constexpr int SHIELD_CHANCE = 5; @@ -144,7 +140,7 @@ void Entity_Laser::DoDamage(Entity* entity, float damage) { if (!isVersus) { - entity->TakeDamage(PLAYER_HIT_DAMAGE, DAMAGE_LASER, EntityRef(source), LASER_HIT_COUNTDOWN); + entity->TakeDamage(PLAYER_HIT_DAMAGE, DAMAGE_LASER, EntityRef(source), HIT_COUNTDOWN); return; } if (IsDescendantOf(entity)) return; @@ -154,7 +150,7 @@ void Entity_Laser::DoDamage(Entity* entity, float damage) (g_game->challenge == CHALLENGE_GUARDIAN && entity->variant == Entity_Familiar::PUNCHING_BAG))) { Entity_Player* player = static_cast(entity)->player; - player->TakeDamage(PLAYER_HIT_DAMAGE, DAMAGE_LASER | DAMAGE_ISAAC_HURT, EntityRef(source), LASER_HIT_COUNTDOWN); + player->TakeDamage(PLAYER_HIT_DAMAGE, DAMAGE_LASER | DAMAGE_ISAAC_HURT, EntityRef(source), HIT_COUNTDOWN); return; } @@ -175,7 +171,7 @@ void Entity_Laser::DoDamage(Entity* entity, float damage) if (roll.RandomFloat() < blackHpDropChance) damageFlags |= DAMAGE_SPAWN_BLACK_HEART; } if (isVersus && tearFlags[TEAR_LASERSHOT]) damageFlags |= DAMAGE_LASER; - entity->TakeDamage(damage, damageFlags, EntityRef(source), LASER_HIT_COUNTDOWN); + entity->TakeDamage(damage, damageFlags, EntityRef(source), HIT_COUNTDOWN); } // 00971590 Hurts the grid entity in a cell the beam crosses. One time in four a standing one is broken by an Acid or @@ -330,7 +326,7 @@ void Entity_Laser::splash_spawn(const Vector& center, const Vector& along, float { uint32_t seed = Random(); float speed = random_unit() * SPLASH_SPEED_RANGE + SPLASH_SPEED_MIN; - float angle = random_unit() * SPLASH_HALF_TURN * 2; + float angle = random_unit() * PI_ROUGH * 2; Vector velocity = vector_add(vector_make(std::cos(angle), std::sin(angle)), vector_scale(along, speed)); float across = (to - from) * random_unit() + from; Vector position = vector_add(vector_add(center, vector_scale(side, across)), @@ -352,7 +348,7 @@ void Entity_Laser::splash_spawn(const Vector& center, const Vector& along, float color_multiply(marked, sprite.color); uint32_t seed = Random(); float speed = random_unit() * MARKED_SPLASH_SPEED_RANGE + MARKED_SPLASH_SPEED_MIN; - float angle = random_unit() * SPLASH_HALF_TURN * 2; + float angle = random_unit() * PI_ROUGH * 2; Vector velocity = vector_add(vector_make(std::cos(angle), std::sin(angle)), vector_scale(along, speed)); float across = (to - from) * random_unit() + from; Entity* spray = g_game->Spawn({.position = vector_add(center, vector_scale(side, across)), @@ -470,7 +466,7 @@ static void sticking_tear_fire(Entity_Laser& laser, Entity& entity, const Vector tear->Update(); tear->SetTearFlags(flags); tear->SetCollisionDamage(laser.collisionDamage); - float tearScale = std::max(laser.scale, STICKING_TEAR_SCALE_MIN); + float tearScale = std::max(laser.scale, TEAR_SCALE_MIN); tear->baseScale = tearScale; tear->fScale = tearScale; tear->ResetSpriteScale(); @@ -662,7 +658,7 @@ void Entity_Laser::impact_split(const Vector& position, const Vector& direction, if (!isFirstUpdate && GetIntervalTicks(IMPACT_EXPLOSION_INTERVAL, 0) == 0) return; Vector at = g_game->room->GetClampedPositionImpl(position, 1, 1, 1, 1); - float angle = random_unit() * IMPACT_SPLIT_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; Vector velocity = vector_make(std::cos(angle) * IMPACT_SPLIT_SPEED, std::sin(angle) * IMPACT_SPLIT_SPEED); TearFlags flags = tearFlags; @@ -701,7 +697,7 @@ void Entity_Laser::impact_split(const Vector& position, const Vector& direction, if (g_game->room->roomType == ROOM_DUNGEON) tear->posOffset.y = IMPACT_SPLIT_CRAWLSPACE_Y; tear->SetTearFlags(flags); tear->SetCollisionDamage(collisionDamage * 0.5f); - float tearScale = std::max(scale * IMPACT_SPLIT_SCALE, STICKING_TEAR_SCALE_MIN); + float tearScale = std::max(scale * IMPACT_SPLIT_SCALE, TEAR_SCALE_MIN); tear->baseScale = tearScale; tear->fScale = tearScale; tear->ResetSpriteScale(); @@ -903,7 +899,7 @@ void Entity_Laser::UpdateHits() else if (!isDead && !isInterpolating && variant == LASER_LIGHT_RING && GetIntervalTicks(LIGHT_RING_INTERVAL, 0)) for (Entity* entity : entity_query_radius(pos, radius, QUERY_ENEMIES)) if (entity->IsVulnerableEnemy(nullptr) && !IsDescendantOf(entity)) - entity->TakeDamage(collisionDamage, 0, EntityRef(this), LASER_HIT_COUNTDOWN); + entity->TakeDamage(collisionDamage, 0, EntityRef(this), HIT_COUNTDOWN); if (isHitFrame && (std::isfinite(impactDistance) || isGridHit)) impact_tear_flag_effects(impactPosition, impactDirection); diff --git a/src/entity_list.cpp b/src/entity_list.cpp index 94bdf6d..74b70b5 100644 --- a/src/entity_list.cpp +++ b/src/entity_list.cpp @@ -404,11 +404,12 @@ static bool is_update_skipped(Entity& entity, UpdateMode mode) return isDrawnAway || (mode == UPDATE_TRANSITION && !entity.HasEntityFlags(FLAG_TRANSITION_UPDATE)); } -// The damage an enemy has taken so far, which the frame's total compares before and after its update. +// The damage an enemy (or a versus player, in this room) has taken so far, which the frame's total compares before and +// after its update. static float damage_taken_get(Entity& entity) { if (!Entity::is_enemy_type(entity.type)) return 0; - if (entity.type == ENTITY_PLAYER) reconstruction_missing("EntityList::Update 004186c0: a versus player's damage"); + if (entity.type == ENTITY_PLAYER) return (float)(uint32_t)static_cast(entity).roomDamageTaken; return static_cast(entity).totalDamageTaken; } diff --git a/src/entity_npc.cpp b/src/entity_npc.cpp index 7b148fb..2427c08 100644 --- a/src/entity_npc.cpp +++ b/src/entity_npc.cpp @@ -595,63 +595,78 @@ static int line_cell_collision(Room& room, int column, int row) return path >= GRID_PATH_SOLID ? COLLISION_SOLID : COLLISION_NONE; } -// Whether a blast stops at a cell: walls (but an unlocked lock or a door) and solid blocks. -static bool line_cell_is_blast_wall(Room& room, int cellIndex) +// Whether a blast stops at a cell: walls (but an unlocked lock, a door, or a wall when walls are ignored) and solid +// blocks. With crushables ignored, a grid entity that can be crushed or walked stops it too. +static bool line_cell_is_blast_wall(Room& room, int cellIndex, const LineQuery& check) { uint32_t collision = room.GetGridCollision(cellIndex); bool isKnown = cellIndex >= 0 && cellIndex < ROOM_GRID_CELLS; GridEntity* grid = isKnown ? room.gridEntities[cellIndex] : nullptr; - if (collision == COLLISION_NONE) return false; if (!grid) return collision == COLLISION_WALL; - if (grid->type == GRID_ROCKB) return true; + if (collision != COLLISION_NONE && grid->type == GRID_ROCKB) return true; if (grid->type == GRID_LOCK && g_game->playerManager.AnyoneHasTrinket(TRINKET_BROKEN_PADLOCK)) return false; - return grid->type != GRID_DOOR && collision == COLLISION_WALL; + + bool isPassable = grid->type == GRID_DOOR || (grid->type == GRID_WALL && check.isIgnoreWalls); + if (!isPassable && collision == COLLISION_WALL) return true; + return check.isIgnoreCrushable && (grid->IsEasyCrushableOrWalkable() || grid->IsDangerousCrushableOrWalkable()); +} + +// Whether a band corner's collision lets a line through: with crushables ignored, a grid entity in the grid that can +// be crushed or walked does. +static bool line_corner_is_crushable(Room& room, int column, int row, const LineQuery& check) +{ + bool isInside = column >= 0 && column < room.gridWidth && row >= 0 && row < room.gridHeight; + int gridIndex = isInside ? row * room.gridWidth + column : -1; + if (!check.isIgnoreCrushable || gridIndex < 0 || gridIndex >= ROOM_GRID_CELLS) return false; + + GridEntity* grid = room.gridEntities[gridIndex]; + return grid && (grid->IsEasyCrushableOrWalkable() || grid->IsDangerousCrushableOrWalkable()); } // 007f0df0 Whether a line from start to end is clear, walked in steps of 10: mode 0 checks a 10 wide band for grid // collision and for more than 8 cells walked past their grid path threshold, mode 1 the same on the line's own cells, -// mode 2 the line's own cells for what stops a blast, mode 3 the band for shots (which fly over pits). Crushable -// rocks and the stop position are left to come. -bool room_check_line(const Vector& start, const Vector& end, int mode, int gridPathThreshold) +// mode 2 the line's own cells for what stops a blast, mode 3 the band for shots (which fly over pits), and any other +// mode nothing. The stop position, when asked, gets the step before the line was blocked, or the end. +bool room_check_line(const LineQuery& check) { - Room& room = *g_game->room; - Vector step = vector_sub(start, end); + auto stop = [&](const Vector& position, bool isClear) { + if (check.stopPosition) *check.stopPosition = position; + return isClear; + }; + Vector step = vector_sub(check.start, check.end); float length = vector_length(step); - if (length <= 0) return true; + if (length <= 0) return stop(check.end, true); step = vector_scale(step, LINE_STEP / length); auto cellOf = [](float value, float origin) { return (int)((value - origin) / GRID_CELL_SIZE + HALF); }; - int startColumn = cellOf(start.x, GRID_ORIGIN_X); - int startRow = cellOf(start.y, GRID_ORIGIN_Y); + int startColumn = cellOf(check.start.x, GRID_ORIGIN_X); + int startRow = cellOf(check.start.y, GRID_ORIGIN_Y); bool isStartInside = startColumn >= 0 && startColumn < room.gridWidth && startRow >= 0 && startRow < room.gridHeight; int startIndex = isStartInside ? room.gridWidth * startRow + startColumn : -1; int blocked = 0; - Vector at = start; + Vector at = check.start; for (float walked = 0; walked < length; walked += LINE_STEP) { at = vector_sub(at, step); - if (mode == LINE_MODE_EXPLOSION) + Vector before = vector_add(at, step); + if (check.mode != LINE_MODE_GROUND && check.mode != LINE_MODE_PROJECTILE) { int column = cellOf(at.x, GRID_ORIGIN_X); int row = cellOf(at.y, GRID_ORIGIN_Y); bool isInside = column >= 0 && column < room.gridWidth && row >= 0 && row < room.gridHeight; int cellIndex = isInside ? row * room.gridWidth + column : -1; - if (line_cell_is_blast_wall(room, cellIndex)) return false; - continue; - } - if (mode == LINE_MODE_CELL) - { - int column = cellOf(at.x, GRID_ORIGIN_X); - int row = cellOf(at.y, GRID_ORIGIN_Y); - bool isInside = column >= 0 && column < room.gridWidth && row >= 0 && row < room.gridHeight; - int cellIndex = isInside ? row * room.gridWidth + column : -1; - if (room.GetGridCollision(cellIndex) != COLLISION_NONE) return false; - if (cellIndex != startIndex && cellIndex >= 0 && room.GetGridPath(cellIndex) > gridPathThreshold) blocked++; + if (check.mode == LINE_MODE_EXPLOSION && line_cell_is_blast_wall(room, cellIndex, check)) + return stop(before, false); + if (check.mode != LINE_MODE_CELL) continue; + + if (room.GetGridCollision(cellIndex) != COLLISION_NONE) return stop(before, false); + if (cellIndex != startIndex && cellIndex >= 0 && room.GetGridPath(cellIndex) > check.gridPathThreshold) + blocked++; continue; } for (const LineCorner& corner : LINE_CORNERS) @@ -659,17 +674,22 @@ bool room_check_line(const Vector& start, const Vector& end, int mode, int gridP int column = cellOf(at.x + corner.x, GRID_ORIGIN_X); int row = cellOf(at.y + corner.y, GRID_ORIGIN_Y); int collision = line_cell_collision(room, column, row); - if (mode == LINE_MODE_PROJECTILE && collision == COLLISION_PIT) continue; - if (collision != COLLISION_NONE) return false; + if (check.mode == LINE_MODE_PROJECTILE && collision == COLLISION_PIT) continue; + if (collision != COLLISION_NONE) + { + if (line_corner_is_crushable(room, column, row, check)) continue; + return stop(before, false); + } bool isInside = column >= 0 && column < room.gridWidth && row >= 0 && row < room.gridHeight; int cornerIndex = isInside ? row * room.gridWidth + column : -1; if (cornerIndex == startIndex) continue; int path = cornerIndex >= 0 ? room.GetGridPath(cornerIndex) : 0; - if (mode == LINE_MODE_GROUND && path > gridPathThreshold) blocked++; + if (check.mode == LINE_MODE_GROUND && path > check.gridPathThreshold) blocked++; } } - return blocked <= LINE_BLOCKED_MAX; + if (blocked > LINE_BLOCKED_MAX) return stop(vector_add(at, step), false); + return stop(check.end, true); } // The suppression the console sets so its next spawned NPC is not rolled a champion (the original's 00c71670). @@ -2222,8 +2242,7 @@ bool Entity_NPC::TakeDamage(float damage, uint64_t damageFlags, const EntityRef& Entity_Player* player = attacker && attacker->type == ENTITY_PLAYER ? static_cast(attacker) : game_nearest_player(pos); if (damageFlags & DAMAGE_SPAWN_FLY) player->AddBlueFlies(1, player->pos, this); - if (!player->proceduralItems.empty()) - reconstruction_missing("Entity_NPC::TakeDamage 006d60a0: the attacker's on-hit procedural items"); + glitched_items_hit_trigger(*player, *this, CONDITION_ENEMY_HIT); return isHurt; } @@ -2461,7 +2480,7 @@ Vector Entity_NPC::CalcTargetPosition(float distanceLimit) g_game->frameCount % CONFUSION_RETARGET_FRAMES != 0); if (!isKept) { - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float scaleFirst = random_unit(); float distance = random_unit() * scaleFirst * CONFUSION_WANDER; @@ -3119,18 +3138,32 @@ Vector Entity_NPC::GetControllerMovementInput(float deadzone) return controller_input_finish(input, deadzone); } -// 006d9050 Keeps the controlling player's last movement, or none without one. -void Entity_NPC::UpdateControllerMovement(bool) +// 006d9050 Keeps the controlling player's shooting input as its movement, the last one held unless forced to take +// any (none included), or none without a player. +void Entity_NPC::UpdateControllerMovement(bool isForceUpdate) { if (controllerID == -1) { controllerMovement = {}; return; } - reconstruction_missing("Entity_NPC::UpdateControllerMovement 006d9050"); + + Vector input = GetControllerMovementInput(MOVEMENT_DEADZONE); + if (isForceUpdate || !vector_is_zero(input)) controllerMovement = input; } -// The rest of Entity_NPC is not reconstructed yet. +// 006d9320 Steers it by the controlling player's walking input: the input times the acceleration and its speed +// multiplier added to its velocity under a friction its multiplier eases, capped at a top speed. +void Entity_NPC::apply_controller_movement(float acceleration, float drag, float maxSpeed) +{ + float scaledDrag = drag; + if (speedMultiplier != 1) scaledDrag = drag / (speedMultiplier + drag - speedMultiplier * drag); + + Vector input = GetControllerInput(0); + velocity = vector_add(vector_scale(input, acceleration * speedMultiplier), vector_scale(velocity, scaledDrag)); + float speed = vector_length(velocity); + if (speed > maxSpeed && speed > 0) velocity = vector_scale(velocity, maxSpeed / speed); +} // 006d9440 Thrown: a poop pile flies at the throw's velocity from 20 pixels up at the throw's height, stops being kept // across rooms, gets the thrown flag (colliding with everything when a player threw it) and splats when fast. Other @@ -3330,11 +3363,38 @@ void Entity_NPC::TransferControl(Entity_NPC* target) controllerID = -1; } -// 006d8b20 The aim target a controlled NPC steers. Without a controller and none shown yet, there is nothing to do. -void Entity_NPC::SpawnControlTarget(int inputMode, float) +// 006d8b20 Shows the aim target a controlled NPC steers, turned by rotation, for two frames more: an aim target that +// is no effect goes first. A new one (1000.30, never timing out, tinted red) appears only on the input its mode +// watches (shooting, walking or none). +void Entity_NPC::SpawnControlTarget(int inputMode, float rotation) { - if (!aimTargetEffect && controllerID == -1 && inputMode <= 1) return; - reconstruction_missing("Entity_NPC::SpawnControlTarget 006d8b20"); + Entity* target = aimTargetEffect; + if (target && target->type != ENTITY_EFFECT) + { + target->Remove(); + aimTargetEffect = nullptr; + target = nullptr; + } + + if (!target) + { + if (inputMode == CONTROL_INPUT_SHOOT && vector_is_zero(GetControllerMovementInput(0))) return; + if (inputMode == CONTROL_INPUT_WALK && vector_is_zero(GetControllerInput(0))) return; + + auto* spawned = static_cast(g_game->Spawn( + {.position = pos, .spawner = this, .type = ENTITY_EFFECT, .variant = EFFECT_TARGET, .seed = Random()})); + spawned->timeout = 0; + spawned->lifespan = 0; + spawned->Update(); + spawned->sprite.color = CONTROL_TARGET_COLOR; + aimTargetEffect = spawned; + target = spawned; + } + + auto& effect = static_cast(*target); + effect.rotation = rotation; + effect.varData[1] = CONTROL_TARGET_FRAMES; + effect.varData[2] = (uint32_t)inputMode; } // 006d8d30 Where its aim target stands, or its own position without one. @@ -3343,10 +3403,17 @@ Vector Entity_NPC::GetAimTargetPosition() return aimTargetEffect ? aimTargetEffect->pos : pos; } -// 006d8d80 +// 006d8d80 Whether the controlling player lets its aim target be: no input on the one its mode watches (always for +// the mode watching none, the shooting input for an aim target that is no effect). Never without an aim target. bool Entity_NPC::is_controller_input_idle() { - reconstruction_missing("Entity_NPC::is_controller_input_idle 006d8d80"); + Entity* target = aimTargetEffect; + if (!target) return false; + + int mode = target->type == ENTITY_EFFECT ? (int)static_cast(target)->varData[2] : CONTROL_INPUT_SHOOT; + if (mode == CONTROL_INPUT_SHOOT) return vector_is_zero(GetControllerMovementInput(MOVEMENT_DEADZONE)); + if (mode == CONTROL_INPUT_WALK) return vector_is_zero(GetControllerInput(MOVEMENT_DEADZONE)); + return mode == CONTROL_INPUT_NONE; } // 006d8e40 A controlled NPC's charge bar at value between start and end, hidden when full if asked. diff --git a/src/entity_npc.h b/src/entity_npc.h index 1ce5bde..4fcabce 100644 --- a/src/entity_npc.h +++ b/src/entity_npc.h @@ -71,6 +71,26 @@ constexpr int MULLIGAN_VARIANT_FLEEING = 2; // Movement or controller input below this length counts as standing still. constexpr float MOVEMENT_DEADZONE = 0.1f; +// The input a controlled NPC's aim target appears on (SpawnControlTarget's mode): its controller's shooting input, +// its walking input, or none, shown at once. +enum ControlTargetInput : int +{ + CONTROL_INPUT_SHOOT, + CONTROL_INPUT_WALK, + CONTROL_INPUT_NONE +}; + +// A controlled NPC's aim target: the frames it outlasts its last refresh, and its red tint. +constexpr uint32_t CONTROL_TARGET_FRAMES = 2; +// A controlled NPC gliding through a leap: its acceleration, a drag that eases as it glides, and its top speed. The +// range it attacks within, which a controller's input decides alone. +constexpr float CONTROL_STEER_ACCEL = 3; +constexpr float CONTROL_STEER_DRAG = 1.25f; +constexpr float CONTROL_STEER_DRAG_FALL = 0.20000005f; +constexpr float CONTROL_STEER_SPEED = 30; +constexpr float CONTROLLED_ATTACK_RANGE = 1000; +constexpr ColorMod CONTROL_TARGET_COLOR = {{155 / 255.0f, 0, 0, 1}, {0, 0, 0, 0}, {0, 0, 0}}; + // Lua's ChampionColor values the NPC code tests. enum ChampionColor : int { @@ -369,6 +389,7 @@ struct Entity_NPC : Entity Vector GetControllerMovementInput(float deadzone); bool is_controller_input_idle(); void UpdateControllerMovement(bool isForceUpdate); + void apply_controller_movement(float acceleration, float drag, float maxSpeed); void UpdateChildEffectPosition(bool isPredictMovement); void TransferControl(Entity_NPC* target); void SpawnControlTarget(int inputMode, float rotation); @@ -406,6 +427,19 @@ enum LineCheckMode : int }; constexpr int LINE_CHECK_THRESHOLD = 999; +// A line to check (Room::CheckLine's arguments): from start to end in a mode, the grid path threshold walkers pass, +// whether walls and crushable grid entities are ignored, and where to put the position the line stops at. +struct LineQuery +{ + Vector start{}; + Vector end{}; + Vector* stopPosition = nullptr; + int mode = LINE_MODE_GROUND; + int gridPathThreshold = 0; + bool isIgnoreCrushable = false; + bool isIgnoreWalls = false; +}; + // The pitch of G FUEL!'s explosions and bursts, 0.9 to 1.1. constexpr float GFUEL_BLAST_PITCH = 0.9f; constexpr float GFUEL_BLAST_PITCH_RANGE = 0.2f; @@ -447,6 +481,12 @@ constexpr size_t SHEET_EXTENSION_SIZE = 4; constexpr std::string_view CHAMPION_SUFFIX = "_champion"; std::string sheet_path_resolve(const std::string& path, std::string_view floorSuffix, std::string_view championSuffix, bool& isChampionSheet); -bool room_check_line(const Vector& start, const Vector& end, int mode, int gridPathThreshold); +bool room_check_line(const LineQuery& check); + +// Room::CheckLine without the walls, crushables or stop position. +inline bool room_check_line(const Vector& start, const Vector& end, int mode, int gridPathThreshold) +{ + return room_check_line({.start = start, .end = end, .mode = mode, .gridPathThreshold = gridPathThreshold}); +} std::vector shopkeeper_loot_get(Entity_NPC& npc, bool isAdvance); bool entity_is_prey(Entity& prey); diff --git a/src/entity_npc_drop.cpp b/src/entity_npc_drop.cpp index d0f1813..bd9b6ac 100644 --- a/src/entity_npc_drop.cpp +++ b/src/entity_npc_drop.cpp @@ -22,7 +22,6 @@ constexpr uint32_t DROP_CHANCE_HARD = 33; constexpr uint32_t DROP_CHANCE_PURPLE_HEART = 50; constexpr uint32_t DROP_CHANCE_PURPLE_HEART_DOUBLE = 66; constexpr uint32_t DROP_CHANCE_PURPLE_HEART_TRIPLE = 75; -constexpr uint32_t PERCENT = 100; constexpr uint32_t VOID_DROP_ODDS = 20; constexpr uint32_t VOID_DROP_ODDS_SURE = 7; constexpr int PURPLE_HEART_TRIPLE = 3; diff --git a/src/entity_npc_render.cpp b/src/entity_npc_render.cpp index ca95afe..df67b9a 100644 --- a/src/entity_npc_render.cpp +++ b/src/entity_npc_render.cpp @@ -23,6 +23,8 @@ constexpr float HEALTH_BAR_DROP = 10; // Part of 006d2e50 The dummy shows the damage it took (its v1.x) to two places, centred 28 above it. constexpr float DUMMY_TEXT_RISE = 28; +// The health a persistent boss shows in the debug damage view (debug 7). +constexpr KColor DEBUG_HEALTH_COLOR = kcolor_rgba(1, 0, 1, 0.5f); // The health bar's sheet: left cap, stretched middle and right cap 8 high in the top row, the fill below the middle. // Its width grows with the log of the NPC's toughness, from 8 to 48. The fill's hue runs from red (none left) to green, @@ -469,7 +471,12 @@ void Entity_NPC::Render(const Vector& offset) chargeBarSprite.Render(SpriteDraw{at, {}, {}}); } if (HasEntityFlags(FLAG_PERSISTENT | FLAG_DELIRIUM_FORM) && (g_game->debugFlags & DEBUG_DAMAGE_VALUES)) - reconstruction_missing("Entity_NPC::Render 006d2e50: the debug health text"); + { + FontSettings settings(ALIGN_CENTER); + g_manager->font2_TeamMeatEx12.DrawString(std::format("{:.2f}", health), + vector_add(render_position_get(pos, RENDER_SNAPPED), offset), + vector_make(1, 1), DEBUG_HEALTH_COLOR, settings); + } } // The fade of a Fissure layer at a depth: gone above the floor, or below it in the reflection. diff --git a/src/entity_npc_rewards.cpp b/src/entity_npc_rewards.cpp index da2923d..658c96f 100644 --- a/src/entity_npc_rewards.cpp +++ b/src/entity_npc_rewards.cpp @@ -103,7 +103,7 @@ constexpr float KEEPER_BOSS_HEALTH_STEP = 10; // A pickup thrown out of the dead enemy in a random direction at two to five, gone after a while. static void reward_pickup_throw(Entity_NPC& npc, const EntitySpawn& spawn, int timeout) { - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float sine = std::sin(angle); float speed = random_unit() * DROP_SPEED_RANGE + DROP_SPEED_MIN; @@ -418,7 +418,7 @@ static void bone_spurs_spawn(Entity_NPC& npc, Entity_Player& owner) } for (int i = 0; i < count; i++) { - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float sine = std::sin(angle); float push = random_unit() + 1; @@ -481,7 +481,7 @@ static void kill_item_rewards(Entity_NPC& npc) if (g_game->challenge == CHALLENGE_CANTRIPPED && npc.dropRNG.Next() % CANTRIPPED_ODDS == 0) { uint32_t seed = Random(); - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; Vector direction = vector_make(std::cos(angle) * CANTRIPPED_CARD_SPEED, std::sin(angle) * CANTRIPPED_CARD_SPEED); diff --git a/src/entity_pickup.cpp b/src/entity_pickup.cpp index d6548be..5ce1151 100644 --- a/src/entity_pickup.cpp +++ b/src/entity_pickup.cpp @@ -60,7 +60,6 @@ constexpr float VERSUS_CHEST_VOLUME = 0.7f; constexpr int TRINKET_APPLE_OF_SODOM = 140; constexpr int TRINKET_NUH_UH = 165; constexpr int COLLECTIBLE_MITRE = 173; -constexpr int SPECIAL_DAILY_NICKELS = 7; // A bed of subtype 10 is held like the ending pickups, a while untouchable. The barren room's bed is torn, and Pay To // Play's chests show a coin slot. @@ -202,7 +201,6 @@ constexpr int CARD_SUIT_CHANCE = 10; // Pickup motion and timing. constexpr int COLLISION_COOLDOWN = 10; -constexpr int THROWN_PICKUP_HIT_COUNTDOWN = 30; constexpr int SETTLE_FRAMES = 6; constexpr float PICKUP_REPOSITION_STEP = 40; constexpr int APPEAR_KICK = 15; @@ -463,7 +461,7 @@ static void coin_subtype_pick(PickupChoice& choice, RNG& rng) return; } } - bool isNickelDaily = g_game->dailyChallenge.specialDailyId == SPECIAL_DAILY_NICKELS; + bool isNickelDaily = g_game->dailyChallenge.specialDailyId == SPECIAL_DAILY_APRIL_FOOLS; if (kind == COIN_NICKEL && isNickelDaily) kind = COIN_STICKYNICKEL; } @@ -1153,7 +1151,7 @@ static void rotten_heart_drip(Entity_Pickup& heart) constexpr float DRIP_SPEED = 3; constexpr uint32_t DRIP_ODDS = 3; constexpr uint32_t WORMS_MAX = 3; - constexpr float WORM_TURN = 2 * 3.14f; + constexpr float WORM_TURN = 2 * PI_ROUGH; bool isLanding = heart.sprite.animState.animData && heart.sprite.IsEventTriggered("DropSound"); if (!isLanding && !(vector_length(heart.velocity) > DRIP_SPEED && Random() % DRIP_ODDS == 0)) return; @@ -1863,6 +1861,30 @@ static void bed_touch(Entity_Pickup& bed, Entity_Player& player) g_game->itemOverlay.Show(isMomsBed && isHome ? GIANTBOOK_SLEEP_NIGHTMARE : GIANTBOOK_SLEEP, 0, nullptr); } +// A co-op copy of an item taken while more players live than copies made leaves the next copy, a boss pool item, where +// the item was (beside it when the pedestal keeps an item), unless Tainted Isaac took the item into his inventory. +// The copy's index setter (006e2ff0) is inlined. +static void coop_copy_spawn(Entity_Pickup& pickup, Entity& collider) +{ + bool isInventoried = pickup.subtype != 0 && collider.type == ENTITY_PLAYER && + static_cast(collider).playerType == PLAYER_ISAAC_B; + if (pickup.coopDuplicateIndex + 1 >= g_game->playerManager.GetNumAlivePlayers() || isInventoried) return; + + Vector position = pickup.pos; + if (pickup.subtype == 0) pickup.Remove(); + else position = room_free_pickup_position_find({.position = pickup.pos, .step = PICKUP_SPOT_STEP, .isAvoidActiveEntities = true}); + int id = g_game->itemPool.GetCollectible(POOL_BOSS, pickup.dropRNG.Next(), 0, 0, 0); + auto* copy = static_cast(g_game->Spawn({.position = position, + .subType = id, + .type = ENTITY_PICKUP, + .variant = PICKUP_COLLECTIBLE, + .seed = pickup.dropRNG.Next()})); + copy->coopDuplicateIndex = pickup.coopDuplicateIndex + 1; + if (copy->coopDuplicateIndex != 0 && copy->coopDuplicateIndex != -1) copy->cycleCollectibleCount = 0; + copy->Update(); + if (pickup.subtype != 0) pickup.coopDuplicateIndex = -1; +} + // 006e8ae0 A player touching the pickup collects it (hearts, coins, keys and bombs into their counters), plays its // pickup sound and animation and marks it dead. Coop ghosts, babies and players who cannot pick up take only a few // kinds. Whether the collision is solid: a priced or collected pickup and players' bombs pass through. @@ -1897,7 +1919,7 @@ bool Entity_Pickup::HandleCollision(Entity* collider, bool isLow) return false; if (g_game->seedEffects.HasSeedEffect(SEED_PICKUPS_TIMEOUT)) ResetColor(); if (HasEntityFlags(FLAG_THROWN) && spawnerType == ENTITY_POLTY && g_forceCollideDepth == 0) - collider->TakeDamage(1, 0, EntityRef(this), THROWN_PICKUP_HIT_COUNTDOWN); + collider->TakeDamage(1, 0, EntityRef(this), HIT_COUNTDOWN); } if (variant == PICKUP_COIN && subtype == COIN_STICKYNICKEL) { @@ -1932,7 +1954,7 @@ bool Entity_Pickup::HandleCollision(Entity* collider, bool isLow) RemoveOtherOptions(); g_game->scoreSheet.add_pickup_points(variant, subtype, pos); PlayPickupSound(); - collect_finish(nullptr); + collect_finish(); return true; } return g_game->room->roomType == ROOM_DUNGEON || collider->type == ENTITY_BOMB || price != 0; @@ -1956,9 +1978,9 @@ bool Entity_Pickup::HandleCollision(Entity* collider, bool isLow) bool isHelperRefused = is_listed({PICKUP_TAROTCARD, PICKUP_PILL, PICKUP_TRINKET, PICKUP_BED, PICKUP_BIGCHEST, PICKUP_TROPHY}, variant); - if (player->variant == 1 && player->babySkin == BABY_MAGNET && CanReroll()) - reconstruction_missing("Entity_Pickup::HandleCollision 006e8ae0: a co-op baby rerolling it"); - if (player->variant != 0) isRefused = true; + bool isMagnetBaby = player->variant == PLAYER_VARIANT_COOP_BABY && player->babySkin == BABY_MAGNET && + variant != PICKUP_COLLECTIBLE && CanReroll(); + if (player->variant != 0 && !isMagnetBaby) isRefused = true; else if (player->isCoopGhost) isRefused |= !isGhostPickup; else isRefused |= (player->parent && isHelperRefused) || (variant == PICKUP_COLLECTIBLE && is_collectible_refused(*player)); @@ -2061,14 +2083,12 @@ bool Entity_Pickup::HandleCollision(Entity* collider, bool isLow) g_game->scoreSheet.add_pickup_points(variant, collectedSubtype, pos); if (variant != PICKUP_COLLECTIBLE) PlayPickupSound(); + glitched_items_trigger(*player, {pos, {}, this, CONDITION_PICKUP_COLLECTED}); if (paidPrice != 0) purchase_finish(*player, paidPrice); else if (variant == PICKUP_TRINKET) trinket_lift(*this, *player); - else if (variant != PICKUP_COLLECTIBLE) collect_finish(player); - if ((variant == PICKUP_COLLECTIBLE || paidPrice != 0) && !player->proceduralItems.empty()) - reconstruction_missing("Entity_Pickup::HandleCollision 006e8ae0: the procedural items' pickup trigger"); + else if (variant != PICKUP_COLLECTIBLE) collect_finish(); - if (g_game->playerManager.IsCoopPlay() && coopDuplicateIndex != -1) - reconstruction_missing("Entity_Pickup::HandleCollision 006e8ae0: a co-op item copy"); + if (g_game->playerManager.IsCoopPlay() && coopDuplicateIndex != -1) coop_copy_spawn(*this, *collider); return variant != PICKUP_COLLECTIBLE || g_game->room->roomType == ROOM_DUNGEON || price != 0; } @@ -2093,13 +2113,10 @@ static void golden_penny_return(Entity_Pickup& penny) g_pickupIgnoreModifiers--; } -// The end of a collection: the procedural items' triggers, the pickup flying into its "Collect" animation and dying, -// and the run's note that a heart, bomb or coin was picked up. -void Entity_Pickup::collect_finish(Entity_Player* player) +// The end of a collection: the pickup flying into its "Collect" animation and dying, and the run's note that a heart, +// bomb or coin was picked up. +void Entity_Pickup::collect_finish() { - if (player && !player->proceduralItems.empty()) - reconstruction_missing("Entity_Pickup::HandleCollision 006e8ae0: the procedural items' pickup trigger"); - velocity = {}; entityCollisionClass = ENTCOLL_NONE; entityGridCollisionClass = GRIDCOLL_WALLS; @@ -2230,10 +2247,10 @@ static void apple_of_sodom_burst(Entity_Pickup& heart, Entity_Player& player, in effect.variant = EFFECT_BLOOD_PARTICLE; for (int gibs = (int)(Random() % SODOM_EXTRA_ODDS) + spiders; gibs > 0; gibs--) { - float angle = random_unit() * RANDOM_HALF_TURN * 2; + float angle = random_unit() * PI_ROUGH * 2; float reach = HALF * heart.size; effect.position = vector_make(std::cos(angle) * reach + heart.pos.x, std::sin(angle) * reach + heart.pos.y); - float heading = random_unit() * RANDOM_HALF_TURN * 2; + float heading = random_unit() * PI_ROUGH * 2; float speed = random_between(SODOM_GIB_SPEED_MIN, SODOM_GIB_SPEED_RANGE); effect.velocity = vector_make(std::cos(heading) * speed, std::sin(heading) * speed); effect.seed = Random(); @@ -2579,7 +2596,6 @@ void Entity_Pickup::PlayDropSound() } // 006e7dc0 Plays the sound of the pickup being collected, by its kind. -// An item's fanfare is not reconstructed yet. void Entity_Pickup::PlayPickupSound() { int sound = 0; diff --git a/src/entity_pickup.h b/src/entity_pickup.h index 4dcdacd..584bb7a 100644 --- a/src/entity_pickup.h +++ b/src/entity_pickup.h @@ -256,7 +256,7 @@ private: void coin_collect(Entity_Player& player); bool key_collect(Entity_Player& player); bool bomb_collect(Entity_Player& player); - void collect_finish(Entity_Player* player); + void collect_finish(); // The chests' parts of HandleCollision and TryOpenChest (entity_pickup_chest.cpp). bool chest_touch(Entity_Player& player); diff --git a/src/entity_pickup_chest.cpp b/src/entity_pickup_chest.cpp index bdcd051..6e9c7c8 100644 --- a/src/entity_pickup_chest.cpp +++ b/src/entity_pickup_chest.cpp @@ -21,7 +21,6 @@ constexpr int OUTCOME_SHIFT_INDEX = 35; constexpr int LOOT_ANGLE_SHIFT_INDEX = 18; constexpr int LOOT_DROP_SHIFT_INDEX = 12; -constexpr float LOOT_ANGLE_SCALE = 3.14f; // The chests a player opens by touch, a key for the locked ones, and their pedestals for the items they give. constexpr std::array LOCKED_CHESTS = {PICKUP_LOCKEDCHEST, PICKUP_ETERNALCHEST, PICKUP_OLDCHEST}; @@ -760,7 +759,7 @@ void Entity_Pickup::chest_loot_spawn(const LootList& loot, Entity_Player& player Vector velocity = GetRandomPickupVelocity(pos, &dropRng, 0); RNG angleRng; angleRng.SetSeed(dropRng.Next(), LOOT_ANGLE_SHIFT_INDEX); - float angle = angleRng.RandomFloat() * LOOT_ANGLE_SCALE * 2; + float angle = angleRng.RandomFloat() * PI_ROUGH * 2; Entity* out = g_game->Spawn({.position = vector_make(std::cos(angle) + pos.x, std::sin(angle) + pos.y), .velocity = vector_make(velocity.x * speed, velocity.y * speed), .subType = entry.subType, diff --git a/src/entity_pickup_morph.cpp b/src/entity_pickup_morph.cpp index 574fc7c..03471f7 100644 --- a/src/entity_pickup_morph.cpp +++ b/src/entity_pickup_morph.cpp @@ -64,7 +64,7 @@ void Entity_Pickup::Morph(int entityType, int entityVariant, int entitySubType, initSeed = rng.Next(); } if (g_game->deathmatchManager.is_active()) - reconstruction_missing("Entity_Pickup::Morph 006e30a0 (the deathmatch's blacklist)"); + g_game->deathmatchManager.type->pickup_replace_banned(entityType, entityVariant, entitySubType); std::array megaPair = megaChestCollectible; std::shared_ptr flipOther = flipSaveState; diff --git a/src/entity_pickup_shop.cpp b/src/entity_pickup_shop.cpp index 5868cb7..898f21c 100644 --- a/src/entity_pickup_shop.cpp +++ b/src/entity_pickup_shop.cpp @@ -29,7 +29,6 @@ constexpr float PICKUP_VELOCITY_CHALLENGE = 0.4f; constexpr float PICKUP_VELOCITY_LOB = 0.2f; constexpr float PICKUP_VELOCITY_LOB_BASE = 3; constexpr float PICKUP_VELOCITY_REACH = 7; -constexpr float PICKUP_VELOCITY_ROUND = 3.14f; constexpr float PICKUP_VELOCITY_SCALE = 2.3283062e-10f; constexpr int PICKUP_VELOCITY_TRIES = 10; constexpr int PRICE_DIGITS = 10; @@ -425,7 +424,7 @@ Vector Entity_Pickup::GetRandomPickupVelocity(const Vector& position, RNG* rng, value ^= value >> 14; unit = (float)value * PICKUP_VELOCITY_SCALE; } - float angle = unit * PICKUP_VELOCITY_ROUND + unit * PICKUP_VELOCITY_ROUND; + float angle = unit * PI_ROUGH + unit * PI_ROUGH; velocity = vector_make(std::cos(angle) * PICKUP_VELOCITY_SPEED, std::sin(angle) * PICKUP_VELOCITY_SPEED); if (ePickupVelType != 0) velocity.y = velocity.y * PICKUP_VELOCITY_LOB + PICKUP_VELOCITY_LOB_BASE; else if (g_game->room->roomType == ROOM_CHALLENGE) velocity = vector_scale(velocity, PICKUP_VELOCITY_CHALLENGE); diff --git a/src/entity_player.cpp b/src/entity_player.cpp index 989dbd8..3724f91 100644 --- a/src/entity_player.cpp +++ b/src/entity_player.cpp @@ -61,7 +61,6 @@ constexpr int ASCENT_HOME_STAGE = 6; constexpr int CAINS_EYE_CHANCE = 25; constexpr int CANTRIPPED_CARDS = 3; constexpr int CARD_START_RUNE_CHANCE = 10; -constexpr int DAILY_CHRISTMAS = 19; constexpr int EMPTY_HEART_RED_HEARTS = 3; constexpr int EVENT_BONUS_ITEMS = 114; constexpr int START_ITEM_ROLLS = 100; @@ -95,10 +94,9 @@ static bool is_file_found(const std::string& path) static ColorMod color_from_bytes(int tintRed, int tintGreen, int tintBlue, int tintAlpha, int offsetRed, int offsetGreen, int offsetBlue) { - constexpr float BYTE = 1.0f / 255; - return {{tintRed * BYTE, tintGreen * BYTE, tintBlue * BYTE, tintAlpha * BYTE}, + return {{tintRed * BYTE_TO_UNIT, tintGreen * BYTE_TO_UNIT, tintBlue * BYTE_TO_UNIT, tintAlpha * BYTE_TO_UNIT}, {0, 0, 0, 0}, - {offsetRed * BYTE, offsetGreen * BYTE, offsetBlue * BYTE}}; + {offsetRed * BYTE_TO_UNIT, offsetGreen * BYTE_TO_UNIT, offsetBlue * BYTE_TO_UNIT}}; } // A random card as the run hands one out: drawn from a seed, then offered to the mods' card callback. @@ -210,6 +208,7 @@ void Entity_Player::Init(int entityType, int entityVariant, int subType, uint32_ log_printf(LOG_INFO, "[Frame: %d] Initialized player with Variant %d and Subtype %d\n", manager.framecount, entityVariant, entitySubType); temporaryEffects.ClearEffects(true); + isCoPlayerItemsInvalid = false; stats_reset(); tonsilCounter = (short)(trinketRNGs[TRINKET_TONSIL].Next() % TONSIL_COUNTER_RANGE + TONSIL_COUNTER_MIN); @@ -269,8 +268,7 @@ void Entity_Player::Init(int entityType, int entityVariant, int subType, uint32_ babyFamiliar = nullptr; if (variant == PLAYER_VARIANT_COOP_BABY) { - if (babySkin == BABY_BLOAT || babySkin == BABY_YBAB || babySkin == BABY_APOLLYON) - reconstruction_missing("Entity_Player::Init 00755470 (the co-op babies that come with a familiar)"); + baby_companions_spawn(initRng); hasBabyRoomShield = true; } links_reset(); @@ -495,6 +493,7 @@ void Entity_Player::links_reset() heightVelocity = 0; redStewBonusDuration = 0; salvationEffect = nullptr; + darkArtsAura = nullptr; astralProjectionBody = nullptr; brokenHearts = 0; rottenHearts = 0; @@ -511,6 +510,7 @@ void Entity_Player::links_reset() reverseEmpressMaxHearts = 0; reverseChariotMoveCooldown = 0; reverseSunBoneHearts = 0; + pendingPill = -1; revelationChargeTimer = 0; montezumaChargeTimer = 0; jupiterCharge = 0; @@ -556,6 +556,8 @@ void Entity_Player::links_reset() wildCardVarData = 0; samsonBerserkCharge = 0; ibsCharge = 0; + versus = {}; + versusPauseTimer = 0; } // 007bbbd0 Gives a character the name, health and pickups its players.xml entry starts with, then what its type, Eden's @@ -799,7 +801,6 @@ void Entity_Player::starting_trinket_add(int id) // unlocked ones (D6, Wooden Nickel, Razor Blade), the daily's, its innate items and pocket active, its trinket, Eden's // rolled items, the Mega Satan key pieces and the challenge's lists. Then it evaluates the stats, shares the pickups // and starts the twins and companions. Straw Man's player only evaluates. Netplay's per-player save data is offline. -// The original's daily specials stop here until reached. void Entity_Player::InitPostLevelInitStats() { Game& game = *g_game; @@ -816,8 +817,6 @@ void Entity_Player::InitPostLevelInitStats() isPostLevelInitFinished = true; return; } - if (game.dailyChallenge.specialDailyId != 0) - reconstruction_missing("Entity_Player::InitPostLevelInitStats 007bc740 (a daily's special start)"); if (playerConfig->card > 0) AddPocketItem(playerConfig->card, POCKET_CARD); else if (playerConfig->card < 0) AddPocketItem(card_roll(initSeed, CARD_START_RUNE_CHANCE, true), POCKET_CARD); @@ -836,6 +835,7 @@ void Entity_Player::InitPostLevelInitStats() if (playerType == PLAYER_EVE && is_run_unlocked(ACHIEVEMENT_EVE_HOLDS_RAZOR_BLADE)) items.push_back(COLLECTIBLE_RAZOR_BLADE); } + special_daily_start_apply(*this, items); if (!game.deathmatchManager.is_active()) for (int id : items) starting_collectible_add(id); apply_innate_collectibles(); @@ -858,7 +858,12 @@ void Entity_Player::InitPostLevelInitStats() else if (playerType == PLAYER_SAMSON && is_run_unlocked(ACHIEVEMENT_SAMSON_HOLDS_CHILDS_HEART)) trinket = TRINKET_CHILDS_HEART; } + if (playerConfig->trinket == 0 && game.dailyChallenge.specialDailyId == SPECIAL_DAILY_FEBRUARY_18) + starting_trinket_add(TRINKET_WATCH_BATTERY); + if (playerConfig->trinket == 0) trinket = special_daily_trinket_get(trinket); if (trinket != 0 && !game.deathmatchManager.is_active()) starting_trinket_add(trinket); + int dailyCard = special_daily_card_get(); + if (playerConfig->card == 0 && dailyCard != 0) AddPocketItem(dailyCard, POCKET_CARD); if ((playerConfig->id == PLAYER_EDEN || playerConfig->id == TAINTED_EDEN_PLAYER_ID) && !game.deathmatchManager.is_active()) @@ -962,7 +967,15 @@ void Entity_Player::level_start(bool isForced) ventricleRazorPortal = 0; if (variant == PLAYER_VARIANT_COOP_BABY) { - if (isGlitchBaby) reconstruction_missing("Entity_Player::level_start 007a4ba0 (the glitched co-op baby)"); + if (isGlitchBaby) + { + babySkin = BABY_GLITCH; + InitBabySkin(); + g_game->playerManager.glitchBabyRng.Next(); + subtype = (int)GetGlitchBabySubType(); + babySkin = std::min(subtype, (int)BABY_BASIC); + PlayExtraAnimation("Glitch"); + } if (parent) pos = parent->pos; } isLevelStartPending = false; @@ -1415,8 +1428,7 @@ void Entity_Player::UpdateCanShoot() if (!playerConfig) log_printf(LOG_ASSERT, "Could not load config for player type %d\n", playerType); canShoot = isChallengeShooting && playerConfig && playerConfig->isCanShoot; } - if (game.deathmatchManager.is_active()) - reconstruction_missing("Entity_Player::UpdateCanShoot 007cba30 (deathmatch rules)"); + if (game.deathmatchManager.is_active()) canShoot = canShoot && game.deathmatchManager.type->can_shoot(*this); } // 0075dfe0 Takes off every costume, leaving each layer to the player's own sprite. @@ -1489,7 +1501,7 @@ void Entity_Player::update_player_skin() bool isBombForm = playerType == PLAYER_THEFORGOTTEN_B || playerType == PLAYER_THESOUL_B; if (variant == PLAYER_VARIANT_PLAYER && !game.GetChallengeParams().isCanShoot && !isBombForm) AddCostume(items.GetNullItem(NULLITEM_BLINDFOLD), false); - if (game.seedEffects.HasSeedEffect(SEED_CHRISTMAS) || game.dailyChallenge.specialDailyId == DAILY_CHRISTMAS) + if (game.seedEffects.HasSeedEffect(SEED_CHRISTMAS) || game.dailyChallenge.specialDailyId == SPECIAL_DAILY_CHRISTMAS) AddCostume(items.GetNullItem(NULLITEM_CHRISTMAS), false); if (game.challenge == CHALLENGE_HOT_POTATO && playerType == PLAYER_THEFORGOTTEN_B) AddCostume(items.GetNullItem(NULLITEM_FORGOTTEN_BOMB), false); @@ -1620,6 +1632,7 @@ void Entity_Player::release_weapons_and_effects(bool isRemoveEntities) link_release(monstranceAura, isRemoveEntities); link_release(babyFamiliar, isRemoveEntities); link_release(salvationEffect, isRemoveEntities); + link_release(darkArtsAura, isRemoveEntities); link_release(tetheredEffect, isRemoveEntities); link_release(astralProjectionBody, isRemoveEntities); link_release(montezumaLaser, isRemoveEntities); @@ -1808,51 +1821,3 @@ void Entity_Player::apply_victory_lap_penalty(uint32_t seed) size_t lost = std::min((size_t)std::floor((float)(collectibles.size() + 1) * loss), collectibles.size()); for (size_t i = 0; i < lost; i++) RemoveCollectible(collectibles[i], false, 0, true); } - -// 007585b0 Moves a dead co-op player's view to the next player alive. -void Entity_Player::cycle_spectate_target() -{ - reconstruction_missing("Entity_Player::cycle_spectate_target 007585b0 (co-op)"); -} - -// 007ba2b0 The effects of a co-op baby's skin each frame. -void Entity_Player::update_baby_skin_effects() -{ - reconstruction_missing("Entity_Player::update_baby_skin_effects 007ba2b0 (co-op)"); -} - -// 007bb5e0 A co-op baby's skin's effect as it dies. -void Entity_Player::coop_baby_death_effect() -{ - reconstruction_missing("Entity_Player::coop_baby_death_effect 007bb5e0 (co-op)"); -} - -// 007bf040 Dresses a co-op baby in its skin. -void Entity_Player::InitBabySkin() -{ - reconstruction_missing("Entity_Player::InitBabySkin 007bf040 (co-op)"); -} - -// 007c2e90 The skin a glitched co-op baby takes next. -uint32_t Entity_Player::GetGlitchBabySubType() -{ - reconstruction_missing("Entity_Player::GetGlitchBabySubType 007c2e90 (co-op)"); -} - -// 007cb090 What a co-op baby's skin brings as it joins. -void Entity_Player::apply_coop_baby_spawn_bonus() -{ - reconstruction_missing("Entity_Player::apply_coop_baby_spawn_bonus 007cb090 (co-op)"); -} - -// 007d93b0 Brings a co-op ghost back to life. -void Entity_Player::RevivePlayerGhost() -{ - reconstruction_missing("Entity_Player::RevivePlayerGhost 007d93b0 (co-op)"); -} - -// 007d96f0 Turns a dead co-op player into a ghost. -void Entity_Player::MorphToCoopGhost() -{ - reconstruction_missing("Entity_Player::MorphToCoopGhost 007d96f0 (co-op)"); -} diff --git a/src/entity_player.h b/src/entity_player.h index cc37400..8ffbf8a 100644 --- a/src/entity_player.h +++ b/src/entity_player.h @@ -24,6 +24,27 @@ constexpr int BAG_OF_CRAFTING_SIZE = 8; constexpr int CHARGE_BAR_COUNT = 7; constexpr int COLLECTIBLE_VANILLA_COUNT = 733; constexpr int COOP_BABY_BUFF_COUNT = 8; +// The frames a delayed sound played at once keeps for its next one. +constexpr int DELAYED_SFX_FRAMES = 2; +// The directions Ybab's aim axes are dealt from: right, left, down and up. +constexpr int AIM_AXIS_COUNT = 4; + +// The buffs the co-op baby skins Rage to Brown give every player (coopBabyBuffTimers), in skin order. +enum CoopBabyBuff +{ + COOP_BUFF_DAMAGE, + COOP_BUFF_TEARS, + COOP_BUFF_SPEED, + COOP_BUFF_RANGE, + COOP_BUFF_LUCK, + COOP_BUFF_SMALLER, + COOP_BUFF_LARGER, + COOP_BUFF_BUTT_PENNY +}; + +// The stats each co-op baby buff asks for again as it starts and ends (Butt Penny's none). +constexpr uint32_t COOP_BUFF_CACHES[] = {CACHE_DAMAGE, CACHE_FIREDELAY, CACHE_SPEED, CACHE_SHOTSPEED | CACHE_RANGE, + CACHE_LUCK, CACHE_SIZE, CACHE_SIZE}; constexpr int COSTUME_LAYER_COUNT = 15; constexpr int FORGOTTEN_BODY_ROOM_NONE = -99999; constexpr int HEART_STAT_COUNT = 6; @@ -61,6 +82,9 @@ constexpr uint8_t WILD_CARD_PILL = 0; constexpr uint8_t WILD_CARD_CARD = 1; constexpr uint8_t WILD_CARD_ACTIVE = 2; +// The most bombs a player holds. +constexpr int BOMBS_MAX = 99; + // Which consumables ConsumableCountChanged and SyncConsumables copy between players. enum ConsumableMask : uint32_t { @@ -154,21 +178,50 @@ enum PlayerVariant : int // The co-op baby skins Init and the frame tell apart (Lua's BabySubType). enum BabySubType : int { + BABY_SPIDER = 0, + BABY_LOVE = 1, BABY_BLOAT = 2, + BABY_WATER = 3, BABY_PSY = 4, + BABY_CURSED = 5, + BABY_TROLL = 6, BABY_YBAB = 7, + BABY_HOST = 9, + BABY_LOST = 10, BABY_SHADOW = 13, + BABY_GLASS = 14, + BABY_GOLD = 15, + BABY_CY = 16, BABY_MAG = 18, + BABY_WRATH = 19, BABY_BEGOTTEN = 21, BABY_DEAD = 22, BABY_FIGHTING = 23, + BABY_0 = 24, BABY_GLITCH = 25, BABY_MAGNET = 26, BABY_BLACK = 27, BABY_RED = 28, BABY_WHITE = 29, BABY_BLUE = 30, + BABY_RAGE = 31, + BABY_BROWN = 38, + BABY_NOOSE = 39, + BABY_HIVE = 40, + BABY_BUDDY = 41, + BABY_COLORFUL = 42, + BABY_WHORE = 43, + BABY_DRIPPING = 45, + BABY_BLINDING = 46, + BABY_SUCKY = 47, + BABY_DARK = 48, + BABY_PICKY = 49, + BABY_REVENGE = 50, + BABY_BELIAL = 51, + BABY_SALE = 52, + BABY_GOAT = 53, BABY_SUPER_GREED = 54, + BABY_MORT = 55, BABY_APOLLYON = 56, BABY_BONE = 57, BABY_BOUND = 58, @@ -411,6 +464,7 @@ enum PlayerItemId : int COLLECTIBLE_MOMS_PURSE = 139, COLLECTIBLE_BOBS_CURSE = 140, COLLECTIBLE_SCAPULAR = 142, + COLLECTIBLE_SPEED_BALL = 143, COLLECTIBLE_BUM_FRIEND = 144, COLLECTIBLE_NOTCHED_AXE = 147, COLLECTIBLE_INFESTATION = 148, @@ -437,6 +491,7 @@ enum PlayerItemId : int COLLECTIBLE_FANNY_PACK = 204, COLLECTIBLE_SPIDERBABY = 211, COLLECTIBLE_ANEMIC = 214, + COLLECTIBLE_GOAT_HEAD = 215, COLLECTIBLE_MOMS_WIG = 217, COLLECTIBLE_PLACENTA = 218, COLLECTIBLE_OLD_BANDAGE = 219, @@ -806,6 +861,7 @@ enum PlayerItemId : int TRINKET_STEM_CELL = 119, TRINKET_WOODEN_CROSS = 121, TRINKET_BUTTER = 122, + TRINKET_FILIGREE_FEATHERS = 123, TRINKET_DOOR_STOP = 124, TRINKET_BABY_BENDER = 127, TRINKET_GIGANTE_BEAN = 134, @@ -862,6 +918,7 @@ enum PlayerItemId : int TRINKET_WISH_BONE = 104, TRINKET_BAG_LUNCH = 105, TRINKET_BAT_WING = 118, + TRINKET_SIGIL_OF_BAPHOMET = 189, TRINKET_HAIRPIN = 120, TRINKET_BLESSED_PENNY = 131, TRINKET_BROKEN_SYRINGE = 132, @@ -880,6 +937,7 @@ enum PlayerItemId : int TRINKET_PANIC_BUTTON = 149, TRINKET_TORN_CARD = 157, TRINKET_EXPANSION_PACK = 181, + TRINKET_ENDLESS_NAMELESS = 79, NULLITEM_EXPLOSIVE_DIARRHEA = 0, NULLITEM_STATUE = 4, @@ -919,6 +977,7 @@ enum PlayerItemId : int NULLITEM_AZAZELS_RAGE_1 = 96, NULLITEM_AZAZELS_RAGE_4 = 99, NULLITEM_ESAU_JR = 100, + NULLITEM_SPIRIT_SHACKLES_SOUL = 101, NULLITEM_SPIRIT_SHACKLES_DISABLED = 102, NULLITEM_FORGOTTEN_BOMB = 106, NULLITEM_JACOBS_CURSE = 109, @@ -935,11 +994,13 @@ enum PlayerItemId : int NULLITEM_REVERSE_DEVIL = 67, NULLITEM_REVERSE_TEMPERANCE = 69, NULLITEM_MEGABLAST = 31, + NULLITEM_IWATA = 35, NULLITEM_REVERSE_CHARIOT_ALT = 68, NULLITEM_REVERSE_STARS = 70, NULLITEM_LAZARUS_SOUL_REVIVE = 113, NULLITEM_SOUL_MAGDALENE = 114, NULLITEM_SOUL_BLUEBABY = 115, + NULLITEM_MIRROR_DEATH = 116, NULLITEM_SOUL_JUDAS = 128, NULLITEM_HEMOPTYSIS_BOOST = 127, NULLITEM_ERA_WALK = 42, @@ -1065,7 +1126,17 @@ enum PlayerItemId : int COLLECTIBLE_GHOST_PEPPER = 495, COLLECTIBLE_IMMACULATE_HEART = 573, COLLECTIBLE_BIRDS_EYE = 616, - COLLECTIBLE_ROTTEN_BABY = 268 + COLLECTIBLE_ROTTEN_BABY = 268, + COLLECTIBLE_BOMBER_BOY = 353, + COLLECTIBLE_KNOCKOUT_DROPS = 637, + COLLECTIBLE_LUDOVICO_TECHNIQUE = 329, + COLLECTIBLE_CAT_O_NINE_TAILS = 165, + COLLECTIBLE_THUNDER_THIGHS = 314, + COLLECTIBLE_BUCKET_OF_LARD = 129, + COLLECTIBLE_JELLY_BELLY = 690, + COLLECTIBLE_MYSTERIOUS_LIQUID = 317, + COLLECTIBLE_BODY = 334, + COLLECTIBLE_PJS = 428 }; // The unlocks the player's code checks or grants (Lua's Achievement). @@ -1189,6 +1260,13 @@ struct CostumeSpriteDesc bool isOverwriteColor = false; }; +// A dash's after-image: where the player stood, drawn fading over the frames it has left. +struct AfterImageFrame +{ + Vector position{}; + int frames = 0; +}; + // A frame of the player's walk as the Void's hallucination replays it: where it stood and how it moved, and its body // and head animations (their indices, -1 for none) at their frames. struct TrailFrame @@ -1323,6 +1401,30 @@ void sound_play(int sound); // 006dad10, 006dad20, 006dad30, 006dad60, 006dad70, 006dae00, 006dae10, 00753930, 007539f0, 00753c20, 00753c30, // 007e92a0, 0083ab80, 00841ca0, 0085e220, 0085e230, 0085e240, 0085e250, 0085e270, 0085e290, 0085e2c0, 0085e2d0, // 0085e2e0, 0085e2f0) are the public fields. +// What a versus player keeps to pace its items: the real times (in milliseconds) Infestation, Spiderbaby, Varicose +// Veins, Dead Bird and Black Bean last went off, the damage and hits counted toward Giant Cell, Habit, +// Leprosy, It Hurts and Purity (negative while it recovers), the ramming cooldown, the damage the player dealt this +// frame, whether Missing Page 2 went off, and the effects Broken Syringe, Mom's Lock and the Twins lent. +struct VersusPacing +{ + std::vector twinsEffects; + uint64_t blackBeanMs = 0; + uint64_t deadBirdMs = 0; + uint64_t infestationMs = 0; + uint64_t spiderbabyMs = 0; + uint64_t varicoseVeinsMs = 0; + float giantCellDamage = 15; + int drugEffect = 0; + int momEffect = 0; + int ramCooldown = 0; + uint32_t damageDealt = 0; + short purityHits = 0; + uint8_t habitDamage = 0; + uint8_t itHurtsHits = 0; + uint8_t leprosyHits = 0; + bool isMissingPage2Used = false; +}; + // A player (Lua's EntityPlayer): a character, a co-op baby or an extra player, with its health, consumables, items, // costumes, stats and the sprites it draws over its own. struct Entity_Player : Entity @@ -1437,6 +1539,7 @@ public: TemporaryEffects temporaryEffects; History history; + VersusPacing versus; std::array inventory{}; std::vector collectibleCounts; std::vector extraCollectibleCounts; @@ -1492,6 +1595,7 @@ public: std::array weapons; std::array weaponTypes{}; + std::deque afterImageFrames; std::deque shootDirectionHistory; EntityPtr azazelsRageLaser; Vector aimDirection{}; @@ -1545,7 +1649,7 @@ public: std::shared_ptr unlistedRestoreState; std::shared_ptr playerHUD; std::vector contactHitList; - std::vector darkArtsHitList; + std::vector darkArtsHitList; std::vector curseMistFamiliars; std::vector pendingWisps; std::deque echoChamberItems; @@ -1557,6 +1661,7 @@ public: EntityPtr bestFriend; EntityPtr breathOfLifeEffect; EntityPtr dadsRingAura; + EntityPtr darkArtsAura; EntityPtr divineShield; EntityPtr darkEsau; EntityPtr deadToothRing; @@ -1593,12 +1698,14 @@ public: int suplexState = 0; bool hasBabyRoomShield = false; bool hasCurseMistEffect = false; + bool isCoPlayerItemsInvalid = false; bool isCoopGhost = false; bool isPreviewAdded = true; bool isGlitchBaby = false; bool isHeldEntityVisible = false; std::array coopBabyBuffTimers{}; + std::array mirroredAimAxes{}; float darkArtsDamage = 0; float delayedSfxVolume = 0; float forgottenBHeight = 0; @@ -1658,6 +1765,7 @@ public: int ponyCharge = 0; int potatoPeelerBandageCounter = 0; int potatoPeelerCounter = 0; + int pendingPill = -1; int purityState = 0; int rUaWizardTimer = 0; int redStewBonusDuration = 0; @@ -1743,6 +1851,7 @@ public: void UpdateBlackHeartMask(); void UpdateHeartDependentEffects(); void ClampGoldenHearts(bool isSkipBreak); + int golden_holders_count(); void ClampHeartsToLimit(HeartKind kind, int amount); void update_bone_hearts(); void update_greeds_gullet(); @@ -1790,16 +1899,15 @@ public: bool IsValidTarget(Entity* other) override; void ResetColor() override; - // Not reconstructed yet: each stops the game with reconstruction_missing when reached. bool TakeDamage(float damage, uint64_t damageFlags, const EntityRef& source, int damageCountdown) override; bool TryThrow(const EntityRef& source, const Vector& velocity, float height) override; bool HandleCollision(Entity* collider, bool isLow) override; void AddCollectible(int type, int charge, bool isFirstTime, int activeSlot, int varData, int poolType = 0); void SetQueuedItem(const QueueItemData& queued); + void PlayDelayedSFX(int sound, int soundDelay, int frameDelay, float volume); int tagged_item_count(uint64_t tag); void collectible_unlocks_check(int collectibleId, ItemConfig_Item& item); void collectible_pickups_add(ItemConfig_Item& item); - std::string frame_gap(); void costume_heads_update(int blinkFrame); void costume_layers_update(); float body_costumes_walk(const CostumeWalk& walk); @@ -1842,7 +1950,6 @@ private: Entity_Player* health_owner(); Entity_Player* heart_owner(PlayerType halfOwner); void eternal_heart_overlay_show(); - int golden_holders_count(); void bone_hearts_add(int amount); void rotten_hearts_add(int amount); void red_hearts_add(int hearts, bool isUnknown2); @@ -2047,6 +2154,11 @@ public: void update_baby_skin_effects(); void coop_baby_death_effect(); void InitBabySkin(); + void baby_companions_spawn(RNG& initRng); + void bound_chain_spawn(); + void coop_items_sync(); + void ghost_revive(); + Vector mirrored_aim_get(Vector aim); Entity_Laser* FireDelayedBrimstone(float angle, Entity* parent); bool CanPickupItem(); bool IsHeldItemVisible(); diff --git a/src/entity_player_actives.cpp b/src/entity_player_actives.cpp index 18fc1f6..e3f1647 100644 --- a/src/entity_player_actives.cpp +++ b/src/entity_player_actives.cpp @@ -23,6 +23,7 @@ #include "kage_input.h" #include "key_configs.h" #include "log.h" +#include "loot_list.h" #include "lua_callbacks.h" #include "lua_engine.h" #include "manager.h" @@ -58,7 +59,6 @@ constexpr float RED_CANDLE_DAMAGE = 4; constexpr int NINE_VOLT_RECHARGE_FRAMES = 450; constexpr int NECROMANCER_FORM_ITEMS = 3; constexpr int OVERLAY_DELAY = 3; -constexpr int PERCENT = 100; constexpr int REVELATIONS_SOUL_HEARTS = 2; constexpr int REVELATIONS_STATE_FLAG = 7; constexpr int TAMMY_TEAR_COUNT = 10; @@ -104,7 +104,6 @@ constexpr float METRONOME_GENESIS_CHANCE = 0.25f; constexpr int DELIRIOUS_LOKII = 1; constexpr float DELIRIOUS_HORSEMAN_HEAD_HEALTH = 50; constexpr float DELIRIOUS_PAIR_SPACING = 40; -constexpr float DELIRIOUS_HALF_TURN = 3.14f; constexpr int DELIRIOUS_HALLUCINATION_FRAMES = 25; constexpr std::array DELIRIOUS_WISPS = {65550, 65551, 65552, 65553}; @@ -145,6 +144,22 @@ constexpr int CASED_ACTIVES[] = { 552, 555, 556, 557, 577, 578, 580, 582, 584, 585, 604, 605, 609, 611, 622, 623, 625, 628, 631, 635, 636, 638, 639, 640, 642, 650, 653, 685, 687, 703, 704, 705, 706, 709, 710, 711, 712, 713, 714, 715, 719, 720, 722, 723, 728, 729}; +// Judas' Birthright's bonuses: Necronomicon's shake and bleeding walls, Golden Razor's strike, the poof and flames. +constexpr int BELIAL_NECRONOMICON_SHAKE = 8; +constexpr int BELIAL_BLOOD_WALLS_DURATION = 10; +constexpr int BELIAL_BLOOD_WALLS_COUNT = 5; +constexpr int BELIAL_RAZOR_SHAKE = 15; +constexpr int BELIAL_RAZOR_GOLD_FRAMES = 3; +constexpr float BELIAL_RAZOR_DAMAGE = 15; +constexpr int BELIAL_RAZOR_COUNTDOWN = 30; +constexpr int BELIAL_FLAMES = 5; +constexpr int BELIAL_BONUS_FLAME_DEPTH = -600; +constexpr ColorMod BELIAL_POOF_COLOR = {{0.2f, 0.2f, 0.2f, 0.6f}, {1, 1, 1, 1}, {0, 0, 0}}; +constexpr ColorMod BELIAL_BONUS_FLAME_COLOR = {{5, 0.5f, 0.2f, 1}, {0, 0, 0, 0}, {0, 0, 0}}; + +// M!'s chance in 100 to charge the swapped active with two copies (twice that with three). +constexpr int M_CHARGE_CHANCE = 10; + // The last collectible of each release, for the message where an unwritten active stops the game. struct ActiveRelease { @@ -202,16 +217,21 @@ void battery_effect_spawn(Entity_Player& player) } // Whether an action meets a test on a controller, or on any connected device for -1, through the key configs. +// A trigger of the raw action (33) is the grave accent key itself, which no config binds. static bool is_action_met(ButtonAction action, int controllerIndex, ActionTest test) { KAGE::Input::Manager& input = KAGE::Input::manager; + bool isRaw = action == INPUT_RAW_ACTION && test == ACTION_TRIGGERED; + ActionBinding rawBinding; + rawBinding.fill(KAGE::Input::BUTTON_NONE); + rawBinding[0] = KEY_GRAVE_ACCENT; for (int i = 0; i < input.get_device_count(); i++) { std::shared_ptr device = input.get_device(i); if (!device || !device->isConnected || (controllerIndex != -1 && device->id != controllerIndex)) continue; - for (int button : g_manager->keyConfigs.binding_get(*device, action)) + for (int button : isRaw ? rawBinding : g_manager->keyConfigs.binding_get(*device, action)) { if (button == KAGE::Input::BUTTON_NONE) continue; if (test == ACTION_TRIGGERED ? device->is_button_triggered(button) : device->is_button_pressed(button)) @@ -241,10 +261,7 @@ bool input_is_action_pressed(ButtonAction action, int controllerIndex, Entity* e bool input_is_action_triggered(ButtonAction action, int controllerIndex, Entity* entity) { std::optional isModTriggered = action_hook_run(entity, INPUT_HOOK_TRIGGERED, action); - if (isModTriggered) return *isModTriggered; - if (action == INPUT_RAW_ACTION) - reconstruction_missing("input_is_action_triggered 009561e0 (the raw button action)"); - return is_action_met(action, controllerIndex, ACTION_TRIGGERED); + return isModTriggered ? *isModTriggered : is_action_met(action, controllerIndex, ACTION_TRIGGERED); } // 00827180 The first door slot whose Red Key outline lies within 120 of a position, or -1. @@ -661,8 +678,87 @@ void Entity_Player::DischargeActiveItem(uint32_t slot, bool isRemoved) if (slot == ACTIVE_SLOT_POCKET2) SetPocketActiveItem(0, ACTIVE_SLOT_POCKET2, false); } +// The actives a trinket may swap in or use: every other available active with art, not barred from Eden. +static bool is_trinket_active(Entity_Player& player, ItemConfig_Item* item) +{ + return item && item->id != player.activeItems[ACTIVE_SLOT_PRIMARY].item && item->type == ITEM_ACTIVE && + !item->HasTags(TAG_NO_EDEN) && !item->gfxFilename.empty() && item->IsAvailableEx(AVAILABLE_ALL); +} + +// Uses an active for a trinket without its animation, as owned, the player's item state kept unless the use set one. +static void trinket_active_use(Entity_Player& player, int item) +{ + if (item == 0) return; + int itemState = player.itemState; + player.itemState = 0; + player.UseActiveItem({.item = item, .flags = USE_NOANIM | USE_OWNED, .slot = ACTIVE_SLOT_PRIMARY}); + if (player.itemState == 0) player.itemState = itemState; + else player.itemStateCooldown = 0; +} + +// M!: the spent active turns into another, weighed toward the low qualities (a glitched one with TMTRAINER), with more +// copies sometimes fully charged. +static void m_trinket_swap(Entity_Player& player) +{ + constexpr int QUALITY_WEIGHTS[] = {5, 4, 3, 2, 1}; + RNG& rng = player.GetTrinketRNG(TRINKET_M); + int swapped = 0; + if (player.HasCollectible(COLLECTIBLE_TMTRAINER)) + { + swapped = g_game->proceduralItemManager.CreateProceduralItem(rng.Next(), PROCEDURAL_FORCE_ACTIVE); + if (g_manager->itemConfig.GetCollectible(swapped)->type != ITEM_ACTIVE) return; + } + else + { + WeightedOutcomePicker picker; + for (std::unique_ptr& item : g_manager->itemConfig.collectibles) + if (is_trinket_active(player, item.get())) picker.AddOutcomeWeight(item->id, QUALITY_WEIGHTS[item->quality]); + swapped = picker.PickOutcome(rng_make(rng.Next(), DEFAULT_SHIFT_INDEX)); + } + if (swapped == 0) return; + + int copies = player.GetTrinketMultiplier(TRINKET_M); + player.RemoveCollectible(player.activeItems[ACTIVE_SLOT_PRIMARY].item, false, ACTIVE_SLOT_PRIMARY, true); + player.AddCollectible(swapped, 0, false, ACTIVE_SLOT_PRIMARY, 0); + if (copies > 1 && (int)rng.RandomInt(PERCENT) < (copies == 2 ? M_CHARGE_CHANCE : M_CHARGE_CHANCE * 2)) + { + ActiveItemDesc& active = player.activeItems[ACTIVE_SLOT_PRIMARY]; + player.AddActiveCharge(player.GetCollectibleMaxCharge(active.item, active.varData), ACTIVE_SLOT_PRIMARY, false, + false, false); + } +} + +// Expansion Pack: once a room (always in a versus match, and every use of an uncharged active), a spent active also +// uses a random one- or two-charge active (twice with two copies, after a three-charge one with three). +static void expansion_pack_use(Entity_Player& player) +{ + constexpr int EXCLUDED[] = {COLLECTIBLE_D_INFINITY, COLLECTIBLE_GLOWING_HOUR_GLASS, COLLECTIBLE_METRONOME, + COLLECTIBLE_ESAU_JR}; + TemporaryEffects& effects = player.temporaryEffects; + ItemConfig_Item* spent = g_manager->itemConfig.GetCollectible(player.activeItems[ACTIVE_SLOT_PRIMARY].item); + if (!spent) return; + bool isCharged = player.GetActiveMaxCharge(ACTIVE_SLOT_PRIMARY) != 0 || spent->maxCharges < 1; + if (isCharged && effects.HasTrinketEffect(TRINKET_EXPANSION_PACK) && !g_game->deathmatchManager.is_active()) return; + + effects.AddTrinketEffect(TRINKET_EXPANSION_PACK, true, 1); + WeightedOutcomePicker small; + WeightedOutcomePicker large; + for (std::unique_ptr& item : g_manager->itemConfig.collectibles) + { + if (!is_trinket_active(player, item.get()) || std::ranges::find(EXCLUDED, item->id) != std::end(EXCLUDED)) + continue; + if (item->maxCharges == 1 || item->maxCharges == 2) small.AddOutcomeWeight(item->id, 1); + else if (item->maxCharges == 3) large.AddOutcomeWeight(item->id, 1); + } + RNG& rng = player.GetTrinketRNG(TRINKET_EXPANSION_PACK); + int copies = player.GetTrinketMultiplier(TRINKET_EXPANSION_PACK); + if (copies == 3) trinket_active_use(player, large.PickOutcome(rng_make(rng.Next(), DEFAULT_SHIFT_INDEX))); + for (int use = copies >= 2 ? 2 : 1; use > 0; use--) + trinket_active_use(player, small.PickOutcome(rng_make(rng.Next(), DEFAULT_SHIFT_INDEX))); +} + // 007abf80 After a slot's item was spent: a Broken Glass Cannon mends, the first slot's use feeds Book of Virtues and -// Judas' Birthright. M!, Butter! and Expansion Pack are not written yet. +// Judas' Birthright, then M! swaps the active, Butter! drops it (unless it was removed) and Expansion Pack adds a use. void Entity_Player::active_used_post(int slot, bool isRemoved, int chargeBeforeUse) { if (activeItems[slot].item == COLLECTIBLE_BROKEN_GLASS_CANNON) glass_cannon_mend(*this, slot); @@ -670,15 +766,142 @@ void Entity_Player::active_used_post(int slot, bool isRemoved, int chargeBeforeU TriggerBookOfVirtues(activeItems[0].item, chargeBeforeUse); trigger_book_of_belial_passive(activeItems[0].item, chargeBeforeUse); - if (HasTrinket(TRINKET_M) || (HasTrinket(TRINKET_BUTTER) && !isRemoved) || HasTrinket(TRINKET_EXPANSION_PACK)) - reconstruction_missing("Entity_Player::active_used_post 007abf80 (M!, Butter! and Expansion Pack)"); + int active = activeItems[ACTIVE_SLOT_PRIMARY].item; + if (HasTrinket(TRINKET_M) && ItemConfig::IsValidCollectible(active)) m_trinket_swap(*this); + active = activeItems[ACTIVE_SLOT_PRIMARY].item; + ItemConfig_Item* item = g_manager->itemConfig.GetCollectible(active); + if (HasTrinket(TRINKET_BUTTER) && ItemConfig::IsValidCollectible(active) && !isRemoved && item && + item->type == ITEM_ACTIVE) + { + sound_play_local(*this, SOUND_BUTTER_DROP); + DropCollectible(active, nullptr, false); + } + if (HasTrinket(TRINKET_EXPANSION_PACK) && ItemConfig::IsValidCollectible(activeItems[ACTIVE_SLOT_PRIMARY].item)) + expansion_pack_use(*this); } -// 005c9930 Judas' Birthright: the bonus an active gives when Book of Belial's passive is held. -void Entity_Player::trigger_book_of_belial_passive(int, int) +// Golden Razor with Judas' Birthright: every enemy (every player too in a versus match) that can be hit is struck for +// twice the player's damage plus 15, one time in three turned to gold first. +static void golden_razor_belial(Entity_Player& player) +{ + sound_play(SOUND_ROCK_CRUMBLE); + game_shake_screen(BELIAL_RAZOR_SHAKE); + bool isVersus = g_game->deathmatchManager.is_active(); + for (Entity* entity : g_game->room->entityList.updateEL) + { + bool isTarget = (isVersus && entity->type == ENTITY_PLAYER) || + (entity->type >= ENTITY_GAPER && entity->type < ENTITY_EFFECT); + if (!isTarget || entity->entityCollisionClass == ENTCOLL_NONE || entity->entityCollisionClass == ENTCOLL_PLAYERONLY || + entity->isInvincible || entity->isDead) + continue; + if (entity->HasEntityFlags(FLAG_NO_TARGET) && entity->type != ENTITY_BLOOD_PUPPY && entity->type != ENTITY_DARK_ESAU) + continue; + if (Random() % 3 == 0) entity->AddMidasFreeze(EntityRef(&player), BELIAL_RAZOR_GOLD_FRAMES, false); + entity->TakeDamage(player.meleeDamage + player.meleeDamage + BELIAL_RAZOR_DAMAGE, 0, EntityRef(&player), + BELIAL_RAZOR_COUNTDOWN); + } +} + +// The flames Judas' Birthright's bonus sheds: five rising off the player, wider and faster one after another. +static void belial_flames_spawn(Entity_Player& player) +{ + for (int flame = 0; flame < BELIAL_FLAMES; flame++) + { + float reach = (float)flame * 0.7f * 0.25f + 0.3f; + Vector rise = vector_make(reach * 0, (-10 - random_unit() * 6) * reach); + float turn = (random_unit() * 10 - 5) * DEGREES_TO_RADIANS; + float speed = std::clamp((float)flame / 12, 0.0f, 1.0f) * 1.4f + 0.6f; + Vector velocity = vector_scale(vector_make(std::cos(turn) * rise.x - std::sin(turn) * rise.y, + std::cos(turn) * rise.y + std::sin(turn) * rise.x), + speed); + Vector at = vector_add(player.pos, vector_scale(velocity, 2)); + auto* spark = static_cast(g_game->Spawn({.position = at, .velocity = velocity, .spawner = &player, + .type = ENTITY_EFFECT, .variant = EFFECT_DUST_CLOUD, + .seed = Random()})); + LayerState& layer = *spark->sprite.GetLayer(0); + layer_additive_set(layer); + layer.color = BELIAL_BONUS_FLAME_COLOR; + spark->rotation = random_unit() * 10 + 2; + spark->SetTimeout((int)(Random() % 10) + 10); + float size = random_unit() * 0.4f + 0.2f; + spark->sprite.scale = vector_make(size * player.playerSpriteScale.x, size * player.playerSpriteScale.y); + spark->renderZOffset = BELIAL_BONUS_FLAME_DEPTH; + } +} + +// 005c9930 Judas' Birthright: with Book of Belial's passive held, a used active lends Belial's damage for its charges +// (at least one, or its first charge), with a dark poof (a ground poof for four or more) and five flames. Some actives +// do more or other: blood ones lend Razor Blade, Kamikaze and Razor Blade call a Necronomicon with bleeding walls, +// Forget Me Now and IV Bag lend lasting damage, Golden Razor strikes the room, Magic Fingers may lend Golden Razor's +// effect, Magic Skin lends it for good. Belial's own books and Guppy's Paw lend nothing, nor do uncharged or special +// actives. +void Entity_Player::trigger_book_of_belial_passive(int activeId, int charges) { if (!HasCollectible(COLLECTIBLE_BOOK_OF_BELIAL_PASSIVE)) return; - reconstruction_missing("Entity_Player::trigger_book_of_belial_passive 005c9930 (the active's bonus)"); + + ItemConfig_Item* item = g_manager->itemConfig.GetCollectible(activeId); + switch (activeId) + { + case COLLECTIBLE_BLOOD_RIGHTS: + case COLLECTIBLE_SHARP_KEY: + temporaryEffects.AddCollectibleEffect(COLLECTIBLE_RAZOR_BLADE, true, 1); + return; + case COLLECTIBLE_BOOK_OF_BELIAL: + case COLLECTIBLE_BOOK_OF_BELIAL_PASSIVE: + case COLLECTIBLE_GUPPYS_PAW: + return; + case COLLECTIBLE_KAMIKAZE: + case COLLECTIBLE_RAZOR_BLADE: + sound_play(SOUND_DEATH_CARD); + UseActiveItem({.item = COLLECTIBLE_NECRONOMICON, .flags = USE_NOANIM}); + game_shake_screen(BELIAL_NECRONOMICON_SHAKE); + g_game->room->bloodFromWallsDuration = BELIAL_BLOOD_WALLS_DURATION; + g_game->room->bloodFromWallsCount = BELIAL_BLOOD_WALLS_COUNT; + return; + case COLLECTIBLE_FORGET_ME_NOW: + temporaryEffects.AddNullEffect(NULLITEM_JUDAS_BIRTHRIGHT_STAGE, true, 2); + return; + case COLLECTIBLE_IV_BAG: + temporaryEffects.AddNullEffect(NULLITEM_JUDAS_BIRTHRIGHT, true, 1); + return; + case COLLECTIBLE_GOLDEN_RAZOR: + return golden_razor_belial(*this); + case COLLECTIBLE_HOW_TO_JUMP: + sound_play(SOUND_CANDLE_LIGHT); + return; + case COLLECTIBLE_THE_JAR: + if (charges < 1) return; + break; + case COLLECTIBLE_MAGIC_FINGERS: + if (GetCollectibleRNG(COLLECTIBLE_BOOK_OF_BELIAL_PASSIVE).RandomInt(4) != 0) return; + sound_play(SOUND_CASH_REGISTER); + temporaryEffects.AddCollectibleEffect(COLLECTIBLE_GOLDEN_RAZOR, true, 1); + return; + case COLLECTIBLE_MAGIC_SKIN: + temporaryEffects.AddNullEffect(NULLITEM_JUDAS_BIRTHRIGHT_PERMANENT, true, 1); + break; + default: + if (!item || item->maxCharges < 1 || item->chargeType != CHARGE_NORMAL) return; + } + + if (charges == 0) charges = std::max(1, item->initCharge); + bool isBelial = temporaryEffects.HasCollectibleEffect(COLLECTIBLE_BOOK_OF_BELIAL) || + temporaryEffects.HasNullEffect(NULLITEM_JUDAS_BIRTHRIGHT); + sound_play(isBelial ? SOUND_CANDLE_LIGHT : SOUND_DEVIL_CARD); + if (ItemConfig_Item* boost = g_manager->itemConfig.GetNullItem(NULLITEM_JUDAS_BIRTHRIGHT)) + { + TemporaryEffect effect(boost); + effect.cooldown = boost->maxCooldown; + temporaryEffects.AddEffect(effect, true, charges); + } + if (charges < 4) + { + Entity* poof = g_game->Spawn({.position = pos, .type = ENTITY_EFFECT, .variant = EFFECT_POOF01, .seed = Random()}); + poof->SetColor(BELIAL_POOF_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); + poof->Update(); + } + else MakeGroundPoof(pos, BELIAL_POOF_COLOR, 1); + belial_flames_spawn(*this); } // 007ad330 Takes off an item's costume unless its effect still runs (Shoop da Whoop's always goes), or it came with @@ -1036,11 +1259,12 @@ static void book_of_revelations_use(ItemUse& use) } // A pedestal the D6 rerolls: another item from the pools (with a wisp for Book of Virtues), or none a quarter of the -// time for the Eternal D6, then a poof. +// time for the Eternal D6 (the emptied pedestal vanishing in a versus match), then a poof. static void pedestal_reroll(ItemUse& use, Entity_Pickup& pickup) { constexpr int ETERNAL_D6_RNG_SHIFT = 44; constexpr float ETERNAL_D6_EMPTY_CHANCE = 0.25f; + constexpr float ETERNAL_D6_VERSUS_VOLUME = 0.7f; bool isEmptied = false; if (use.id == COLLECTIBLE_ETERNAL_D6) @@ -1052,7 +1276,11 @@ static void pedestal_reroll(ItemUse& use, Entity_Pickup& pickup) { pickup.empty_pedestal(); if (g_game->deathmatchManager.is_active()) - reconstruction_missing("Entity_Player::UseActiveItem 005b39d0 (the Eternal D6 in a deathmatch)"); + { + g_game->Spawn({.position = pickup.pos, .type = ENTITY_EFFECT, .variant = EFFECT_POOF01, .seed = Random()}); + npc_sound_play(SOUND_SUMMONSOUND, ETERNAL_D6_VERSUS_VOLUME, SOUND_FRAME_DELAY_DEFAULT, 1); + pickup.Kill(EntityRef()); + } } else { @@ -1157,8 +1385,8 @@ static int metronome_item_roll(Entity_Player& player) if (id == COLLECTIBLE_GENESIS && chances.RandomFloat() >= METRONOME_GENESIS_CHANCE) continue; if (g_game->dailyChallenge.id != 0 && id == COLLECTIBLE_FORGET_ME_NOW) continue; if (!ItemConfig::IsValidCollectible(id) || !config.GetCollectible(id)) continue; - if (g_game->deathmatchManager.is_active()) - reconstruction_missing("Entity_Player::UseActiveItem 005b39d0 (Metronome's pick in a versus match)"); + DeathmatchManager& versus = g_game->deathmatchManager; + if (versus.is_active() && versus.type->is_collectible_banned(id)) continue; return id; } return 0; @@ -1293,7 +1521,7 @@ void Entity_Player::console_spawn(const DeliriousBoss& boss, bool isAddWisp) {.position = pos, .health = boss.health, .count = boss.count, .type = boss.type, .variant = boss.variant}}; if (is_delirious_pair(boss)) { - float angle = random_unit() * DELIRIOUS_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; Vector offset = vector_make(std::cos(angle) * DELIRIOUS_PAIR_SPACING, std::sin(angle) * DELIRIOUS_PAIR_SPACING); DeliriousSpawn partner = spawns[0]; @@ -1671,7 +1899,11 @@ UseResult Entity_Player::UseActiveItem(const ActiveUse& request) use.isShowAnimation = variant == PLAYER_VARIANT_PLAYER && !(request.flags & USE_NOANIM); use.isLuaAnimationAllowed = use.isShowAnimation; use.isWispAllowed = use.isShowAnimation || (request.flags & USE_ALLOWWISPSPAWN); - if (use.id < 0) reconstruction_missing("Entity_Player::UseActiveItem 005b39d0: glitched_item_effects_run 009e01b0"); + if (use.id < 0) + { + if (use.isShowAnimation) AnimateCollectible(use.id, "UseItem", "PlayerPickupSparkle"); + glitched_item_effects_run(use.id, *this, {pos, aimDirection, this, CONDITION_ACTIVE}); + } if (use.isShowAnimation) sound_play(SOUND_ITEM_RAISE); if (!use.item) @@ -2240,8 +2472,6 @@ static void suplex_super_landing(Entity_Player& player) constexpr float SLAM_DUST_SPEED_RANGE = 5; constexpr float SLAM_DUST_SPEED_MIN = 15; constexpr float SLAM_DUST_FLATTEN = 0.85f; - constexpr float SLAM_DUST_SPIN_RANGE = 10; - constexpr float SLAM_DUST_SPIN_MIN = 2; constexpr float SLAM_DUST_SCALE_RANGE = 0.6f; constexpr uint32_t SLAM_DUST_LIFE_RANGE = 40; constexpr ColorMod SLAM_DUST_COLOR = {{0.45f, 0.45f, 0.46f, 0.75f}, {0, 0, 0, 0}, {0, 0, 0}}; @@ -2264,7 +2494,7 @@ static void suplex_super_landing(Entity_Player& player) .type = ENTITY_EFFECT, .variant = EFFECT_DUST_CLOUD, .seed = Random()})); float spin = (Random() & 1) ? 1 : -1; - dust->rotation = (random_unit() * SLAM_DUST_SPIN_RANGE + SLAM_DUST_SPIN_MIN) * spin; + dust->rotation = (random_between(DUST_SPIN_MIN, DUST_SPIN_RANGE)) * spin; float scale = random_unit() * SLAM_DUST_SCALE_RANGE + 1; dust->sprite.scale = vector_make(scale, scale); dust->SetTimeout((int)(Random() % SLAM_DUST_LIFE_RANGE + SLAM_DUST_LIFE_RANGE)); @@ -2471,47 +2701,6 @@ void Entity_Player::ControlActiveItem(int slot) if (slot == ACTIVE_SLOT_PRIMARY) bulbs_update(*this, chargeBefore, slot); } -// The temporary effects the plain frame, stats and tears are written for: the first floor's actives that leave one, -// Whore of Babylon and Tainted Eve's, Dead Bird, Bloody Lust and Bloody Gust, Lazarus' boost, Jacob's curse, -// Metronome's and Delirious' marks (the item Metronome lends counts as owned, so its own checks still apply), and the -// marks of the Bag of Crafting, Abyss, Flip, Lemegeton and Anima Sola. Book of Belial and Razor Blade change the -// damage and tears, which are not written for effects yet. -bool is_temporary_effect_plain(const TemporaryEffect& effect) -{ - constexpr int PLAIN_EFFECT_ITEMS[] = {COLLECTIBLE_BIBLE, - COLLECTIBLE_POOP, - COLLECTIBLE_MR_BOOM, - COLLECTIBLE_TAMMYS_HEAD, - COLLECTIBLE_MOMS_BRA, - COLLECTIBLE_KAMIKAZE, - COLLECTIBLE_TELEPORT, - COLLECTIBLE_YUM_HEART, - COLLECTIBLE_LEMON_MISHAP, - COLLECTIBLE_BOOK_OF_REVELATIONS, - COLLECTIBLE_D6, - COLLECTIBLE_SPIDER_BUTT, - COLLECTIBLE_ETERNAL_D6, - COLLECTIBLE_WHORE_OF_BABYLON, - COLLECTIBLE_DEAD_BIRD, - COLLECTIBLE_BLOODY_LUST, - COLLECTIBLE_BLOODY_GUST, - COLLECTIBLE_METRONOME, - COLLECTIBLE_DELIRIOUS, - COLLECTIBLE_BAG_OF_CRAFTING, - COLLECTIBLE_ABYSS, - COLLECTIBLE_FLIP, - COLLECTIBLE_LEMEGETON, - COLLECTIBLE_ANIMA_SOLA, - COLLECTIBLE_HOLD, - COLLECTIBLE_BOOK_OF_VIRTUES}; - - if (effect.item->type == ITEM_NULL) - return effect.item->id == NULLITEM_LAZARUS_BOOST || effect.item->id == NULLITEM_BLOODY_BABYLON || - effect.item->id == NULLITEM_JACOBS_CURSE; - return effect.item->IsCollectible() && - std::ranges::find(PLAIN_EFFECT_ITEMS, effect.item->id) != std::end(PLAIN_EFFECT_ITEMS); -} - // 007da7a0 Whether an active slot's item stays when another active is taken from a pedestal: an empty or unknown // item, the unused ids, and the books Book of Virtues and Judas's Birthright put in the slot. bool is_active_slot_kept(Entity_Player& player, int slot) @@ -2540,8 +2729,8 @@ void active_collectible_add(Entity_Player& player, ItemConfig_Item& item, const bool isSchoolbagMove = gain.slot == ACTIVE_SLOT_PRIMARY && player.HasCollectible(COLLECTIBLE_SCHOOLBAG) && player.activeItems[ACTIVE_SLOT_SECONDARY].item == 0; if (isSchoolbagMove) std::swap(player.activeItems[ACTIVE_SLOT_PRIMARY], player.activeItems[ACTIVE_SLOT_SECONDARY]); - if (active.item < 0) reconstruction_missing("Entity_Player::AddCollectible 0075f0e0 (replacing a procedural active)"); - if (active.item > 0) + if (active.item < 0) glitched_item_remove(player, active.item); + else if (active.item > 0) player.collectibleCounts[active.item] = std::max(player.collectibleCounts[active.item] - 1, 0); active.item = gain.item; diff --git a/src/entity_player_actives_rebirth.cpp b/src/entity_player_actives_rebirth.cpp index 4faca39..19d523e 100644 --- a/src/entity_player_actives_rebirth.cpp +++ b/src/entity_player_actives_rebirth.cpp @@ -339,7 +339,7 @@ static void monster_manual_use(ItemUse& use) } // Dead Sea Scrolls: one of 32 first floor actives used at once, named over the HUD, with its wisp for Book of -// Virtues. Ten tries skip what Cantripped forbids, then Tammy's Head. +// Virtues. Ten tries skip what Cantripped or the versus rules forbid, then Tammy's Head. static void dead_sea_scrolls_use(ItemUse& use) { Entity_Player& player = use.player; @@ -349,13 +349,13 @@ static void dead_sea_scrolls_use(ItemUse& use) if (player.itemState == 0) { int pick = COLLECTIBLE_TAMMYS_HEAD; - if (g_game->deathmatchManager.is_active()) - reconstruction_missing("Entity_Player::UseActiveItem 005b39d0 (Dead Sea Scrolls in a versus match)"); + DeathmatchManager& versus = g_game->deathmatchManager; for (int i = 0; i < DEAD_SEA_SCROLLS_TRIES; i++) { int id = DEAD_SEA_SCROLLS_ITEMS[player.GetCollectibleRNG(use.id).RandomInt(DEAD_SEA_SCROLLS_ITEMS.size())]; if (g_game->challenge == CHALLENGE_CANTRIPPED && ItemConfig::is_collectible_tagged(id, TAG_NO_CANTRIP)) continue; + if (versus.is_active() && versus.type->is_collectible_banned(id)) continue; pick = id; break; } @@ -383,13 +383,13 @@ static void forget_me_now_restart(Entity_Effect* timer) g_game->stageTransition.start({.player = player, .type = STAGE_TRANSITION_FORGET_ME_NOW, .isSameStage = true}); } -// Forget Me Now: the floor restarts a frame later. It goes once owned, or used through the Void. +// Forget Me Now: the floor restarts a frame later (during a versus fight it only buzzes). It goes once owned, or used +// through the Void. static void forget_me_now_use(ItemUse& use) { if (use.player.variant != PLAYER_VARIANT_PLAYER) return; if (use.request.flags & (USE_OWNED | USE_VOID)) use.result.isRemove = true; - if (g_game->deathmatchManager.is_active()) - reconstruction_missing("Entity_Player::UseActiveItem 005b39d0 (Forget Me Now in a versus match)"); + if (g_game->deathmatchManager.is_fighting()) return g_manager->sfxManager.Play(SOUND_ERROR_BUZZ); Entity_Effect* timer = Entity_Effect::CreateTimer(reinterpret_cast(&forget_me_now_restart), 1, 0, false); timer->parent = &use.player; @@ -984,9 +984,12 @@ static void flush_npc(ItemUse& use, Entity_NPC& npc) if (npc.minecart) static_cast(npc.minecart.get())->MinecartUpdateChild(poop); } -// The Flush: the room flooded for its effect, and every enemy flushed but the friendly ones. +// The Flush: the room flooded for its effect, and every enemy flushed but the friendly ones. The other versus players +// take 30. static void flush_use(ItemUse& use) { + constexpr float FLUSH_VERSUS_DAMAGE = 30; + constexpr int FLUSH_VERSUS_COUNTDOWN = 30; Entity_Player& player = use.player; if (player.variant == PLAYER_VARIANT_PLAYER) { @@ -998,7 +1001,10 @@ static void flush_use(ItemUse& use) Entity_NPC* npc = dynamic_cast(entities[i]); if (npc && npc->HasEntityFlags(FLAG_FRIENDLY)) continue; if (entities[i]->is_player() && entities[i] != &player && g_game->deathmatchManager.is_active()) - reconstruction_missing("Entity_Player::UseActiveItem 005b39d0 (the Flush in a versus match)"); + { + entities[i]->TakeDamage(FLUSH_VERSUS_DAMAGE, 0, EntityRef(), FLUSH_VERSUS_COUNTDOWN); + continue; + } if (npc) flush_npc(use, *npc); } } @@ -1559,7 +1565,24 @@ static void box_open(Entity_Player& player, int stage) } } -// Pandora's Box: opened by a main player, it gives what the floor holds (or the Strange Key's collectibles), one wisp +// Pandora's Box in a versus match: a collectible for each player on one of the arena's spawn points (each used once). +// The original reads an empty list's head when the points run out. Here no more collectibles come. +static void versus_box_open() +{ + constexpr float VERSUS_BOX_RADIUS = 40; + DeathmatchTypeBase& versus = *g_game->deathmatchManager.type; + std::list points = versus.itemSpawnPoints; + + for (int i = 0; i < g_game->playerManager.count_main_players() && !points.empty(); i++) + { + auto point = std::next(points.begin(), (long)(Random() % points.size())); + versus.collectible_spawn(*point, VERSUS_BOX_RADIUS); + points.erase(point); + } +} + +// Pandora's Box: opened by a main player, it gives what the floor holds (or the Strange Key's collectibles, or in a +// versus match a collectible per player), one wisp // per floor past the first with Book of Virtues and a devil familiar with Judas's kept Book of Belial. It goes once // owned, or used through the Void. static void pandoras_box_use(ItemUse& use) @@ -1572,8 +1595,7 @@ static void pandoras_box_use(ItemUse& use) if (use.request.flags & (USE_OWNED | USE_VOID)) use.result.isRemove = true; int stage = g_game->stage; if (player.HasTrinket(TRINKET_STRANGE_KEY)) strange_key_open(player); - else if (g_game->deathmatchManager.is_active()) - reconstruction_missing("Entity_Player::UseActiveItem 005b39d0 (Pandora's Box in a versus match)"); + else if (g_game->deathmatchManager.is_active()) versus_box_open(); else if (g_game->IsGreedMode()) greed_box_open(player, stage); else box_open(player, stage); diff --git a/src/entity_player_actives_repentance.cpp b/src/entity_player_actives_repentance.cpp index 869b691..4abbb5b 100644 --- a/src/entity_player_actives_repentance.cpp +++ b/src/entity_player_actives_repentance.cpp @@ -67,7 +67,6 @@ constexpr std::array, 4> D_INFINITY_OVERLAYS = { constexpr int DATAMINER_STATS = 6; constexpr uint32_t DATAMINER_CACHE_FLAGS = 0x41f; constexpr int PLAN_C_BOSS_DELIRIUM = 70; -constexpr int PLAN_C_BOSS_MOTHER = 88; constexpr int PLAN_C_DELIRIUM_FRAMES = 300; constexpr int PLAN_C_MOTHER_FRAMES = 345; constexpr int PLAN_C_FRAMES = 90; @@ -895,7 +894,7 @@ static void plan_c_use(ItemUse& use) single_use_remove(use); int boss = g_game->room->bossId; if (boss == PLAN_C_BOSS_DELIRIUM) player.planCKillCountdown = PLAN_C_DELIRIUM_FRAMES; - else player.planCKillCountdown = boss == PLAN_C_BOSS_MOTHER ? PLAN_C_MOTHER_FRAMES : PLAN_C_FRAMES; + else player.planCKillCountdown = boss == BOSS_MOTHER ? PLAN_C_MOTHER_FRAMES : PLAN_C_FRAMES; sound_play(SOUND_PLAN_C); EntityList_EL& entities = room_entities(); for (size_t i = 0; i < entities.size(); i++) diff --git a/src/entity_player_bombs.cpp b/src/entity_player_bombs.cpp index f50edd6..5616a0e 100644 --- a/src/entity_player_bombs.cpp +++ b/src/entity_player_bombs.cpp @@ -17,7 +17,6 @@ // The items a player's bombs ask about (Lua's CollectibleType and TrinketType). constexpr int COLLECTIBLE_BOBBY_BOMB = 125; constexpr int COLLECTIBLE_SAD_BOMBS = 220; -constexpr int COLLECTIBLE_BOMBER_BOY = 353; constexpr int COLLECTIBLE_SCATTER_BOMBS = 366; constexpr int COLLECTIBLE_STICKY_BOMBS = 367; constexpr int COLLECTIBLE_MR_MEGA = 106; @@ -35,6 +34,7 @@ constexpr int TRINKET_RING_CAP = 164; // damage, the spread of extra bombs, Short Fuse's fuse and extra damage, and the consumables the HUD redraws. constexpr int BOMB_DELAY = 30; constexpr int BOMB_DELAY_FAST = 1; +constexpr int BOMB_DELAY_BOMBERMAN = 15; constexpr int BOMB_FUSE = 45; constexpr float BOMB_INHERIT = 0.1f; constexpr float BOMB_SCALE_BIG = 1.5f; @@ -45,7 +45,6 @@ constexpr float ROCKET_FAN_STEP = 3; constexpr float ROCKET_FAN_REACH = 80; constexpr int SHORT_FUSE = 22; constexpr std::array SHORT_FUSE_DAMAGE = {15.000001f, 30.000002f, 50}; -constexpr int BOMBS_MAX = 99; constexpr int SOUND_GLITTER_FUSE = 867; constexpr int PLACE_SOUND_DELAY = 4; @@ -204,7 +203,8 @@ static void placed_bomb_setup(Entity_Player& player, Entity_Bomb& bomb, const Te if (flags[TEAR_FAST_BOMB]) bomb.AddEntityFlags(FLAG_NO_KNOCKBACK); } -// Blood Bombs' price for a bomb without bombs: Tainted Bethany's blood charge, or else a heart of the player's own. +// Blood Bombs' price for a bomb without bombs: Tainted Bethany's blood charge, or else a heart of the player's own (eight +// points in a versus match). // Whether it was paid. static bool blood_bomb_pay(Entity_Player& player) { @@ -215,8 +215,10 @@ static bool blood_bomb_pay(Entity_Player& player) player.AddBloodCharge(-1); return true; } + constexpr float BLOOD_BOMB_VERSUS_COST = 8; player.damageCooldown = 0; - return player.TakeDamage(1, BLOOD_BOMB_FLAGS, EntityRef(), BLOOD_BOMB_COUNTDOWN); + float cost = g_game->deathmatchManager.is_active() ? BLOOD_BOMB_VERSUS_COST : 1; + return player.TakeDamage(cost, BLOOD_BOMB_FLAGS, EntityRef(), BLOOD_BOMB_COUNTDOWN); } // Rocket in a Jar's aim for a placed bomb: along the fire direction held, launched at 10 with the player's motion, @@ -294,8 +296,8 @@ void Entity_Player::update_bomb_input() if (numBombs < 1 && !isFree) return; bombPlaceDelay = HasCollectible(COLLECTIBLE_FAST_BOMBS) ? BOMB_DELAY_FAST : BOMB_DELAY; - if (g_game->deathmatchManager.is_active()) - reconstruction_missing("Entity_Player::update_bomb_input 00780f40: a versus match's bomb delay"); + DeathmatchManager& versus = g_game->deathmatchManager; + if (versus.is_active() && versus.type->rules() == DEATHMATCH_BOMBERMAN) bombPlaceDelay = BOMB_DELAY_BOMBERMAN; int bombCount = 1 + (HasTrinket(TRINKET_RING_CAP) ? GetTrinketMultiplier(TRINKET_RING_CAP) : 0); for (int i = 0; i < bombCount; i++) { @@ -319,7 +321,7 @@ void Entity_Player::update_bomb_input() } else if (bombCount > 1) { - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; bomb.pos = vector_make(std::cos(angle) * EXTRA_BOMB_SPREAD + pos.x, std::sin(angle) * EXTRA_BOMB_SPREAD + pos.y); } diff --git a/src/entity_player_cards.cpp b/src/entity_player_cards.cpp index 474bcb1..564bb82 100644 --- a/src/entity_player_cards.cpp +++ b/src/entity_player_cards.cpp @@ -8,6 +8,7 @@ #include "entity_tear.h" #include "entity_familiar.h" #include "game.h" +#include "game_state_player.h" #include "hud.h" #include "level_generator.h" #include "loot_list.h" @@ -111,7 +112,6 @@ constexpr int SOUL_SAMSON_FRAMES = 300; constexpr float REVERSE_CHARIOT_DUST_ALPHA = 0.5f; constexpr float REVERSE_CHARIOT_DUST_MIN_ALPHA = 0.2f; constexpr float REVERSE_CHARIOT_DUST_MIN_TURN = 2; -constexpr float REVERSE_CHARIOT_DUST_SPEED = 5; constexpr float REVERSE_CHARIOT_DUST_SPREAD = 20; constexpr float REVERSE_CHARIOT_DUST_TURN = 10; constexpr float REVERSE_HERMIT_COIN_SPEED = 5; @@ -628,6 +628,25 @@ static PocketUseEnd suicide_king_use(PocketUse& use) } // ? Card: the first slot's active used for free (the Glowing Hour Glass's saved rewinds kept straight), with Book of +// ? Card on the Glowing Hour Glass: the rewind the hourglass would make no longer gives the ? Card back, the player's +// saved pockets losing their first one. +static void hourglass_question_card_forget(Entity_Player& player) +{ + Game& game = *g_game; + int slot = game.currentGlowingHourglassSlot; + if (player.glowingHourglassIndex < 0 || slot < 0) return; + GlowingHourglassState* state = &game.glowingHourglassStates[1 - slot]; + if (!state->isUsable) state = &game.glowingHourglassStates[slot]; + if (!state->isUsable || player.glowingHourglassIndex >= (int)state->gameState.players.size()) return; + + std::array& pockets = state->gameState.players[player.glowingHourglassIndex].pocketItems; + auto card = std::ranges::find_if(pockets, [](const PocketItem& item) + { return item.type == POCKET_CARD && item.id == CARD_QUESTIONMARK; }); + if (card == pockets.end()) return; + std::move(card + 1, pockets.end(), card); + pockets.back() = {0, POCKET_CARD}; +} + // Virtues' wisp. With Blank Card it opens the I AM ERROR room instead, or drops a trapdoor, and the Blank Card goes. static PocketUseEnd questionmark_use(PocketUse& use) { @@ -650,8 +669,7 @@ static PocketUseEnd questionmark_use(PocketUse& use) player.RemoveCollectible(item, false, ACTIVE_SLOT_PRIMARY, true); return POCKET_END_ANIMATE; } - if (item == COLLECTIBLE_GLOWING_HOUR_GLASS) - reconstruction_missing("Entity_Player::UseCard 007b2230 (? Card's Glowing Hour Glass rewinds)"); + if (item == COLLECTIBLE_GLOWING_HOUR_GLASS) hourglass_question_card_forget(player); player.UseActiveItem({.item = item, .flags = USE_OWNED, .slot = ACTIVE_SLOT_PRIMARY}); player.TriggerBookOfVirtues(item, 0); return POCKET_END_SKIP_ANIMATION; @@ -901,14 +919,14 @@ static PocketUseEnd reverse_devil_use(PocketUse& use) static bool is_versus_card_banned(int card) { DeathmatchManager& versus = g_game->deathmatchManager; - return versus.is_active() && versus.type->FUN_0042b480(card); + return versus.is_active() && versus.type->is_card_banned(card); } // Whether a versus match's rules ban a collectible. static bool is_versus_collectible_banned(int item) { DeathmatchManager& versus = g_game->deathmatchManager; - return versus.is_active() && versus.type->FUN_0042b020(item); + return versus.is_active() && versus.type->is_collectible_banned(item); } // Spawns a pickup near the player that no one spawned, with the card's next seed after its spot is found. @@ -945,10 +963,7 @@ constexpr std::array HAGALAZ_SHIFTS = {5, 27, 25}; constexpr float HAGALAZ_SHELL_DAMAGE = 40; constexpr int HAGALAZ_DUST_MIN = 6; constexpr uint32_t HAGALAZ_DUST_RANGE = 6; -constexpr float HAGALAZ_DUST_SPEED = 5; constexpr float HAGALAZ_DUST_SPREAD = 20; -constexpr float HAGALAZ_DUST_SPIN_MIN = 2; -constexpr float HAGALAZ_DUST_SPIN_RANGE = 10; constexpr int HAGALAZ_DUST_FRAMES = 15; constexpr float HAGALAZ_DUST_ALPHA_MIN = 0.2f; constexpr float HAGALAZ_DUST_ALPHA_RANGE = 0.5f; @@ -958,7 +973,7 @@ constexpr float HAGALAZ_QUIET_VOLUME = 0.8f; static void hagalaz_dust_spawn(Entity& npc) { Vector heading = random_direction(); - Vector velocity = vector_scale(heading, random_unit() * HAGALAZ_DUST_SPEED); + Vector velocity = vector_scale(heading, random_unit() * DUST_SPEED); uint32_t seed = Random(); Vector away = random_direction(); Vector position = vector_add(npc.pos, vector_scale(away, random_unit() * HAGALAZ_DUST_SPREAD)); @@ -969,7 +984,7 @@ static void hagalaz_dust_spawn(Entity& npc) .seed = seed})); Vector offset = vector_sub(dust->pos, npc.pos); float side = offset.x * velocity.y - offset.y * velocity.x < 0 ? -1.0f : 1.0f; - dust->rotation = (random_unit() * HAGALAZ_DUST_SPIN_RANGE + HAGALAZ_DUST_SPIN_MIN) * side; + dust->rotation = (random_between(DUST_SPIN_MIN, DUST_SPIN_RANGE)) * side; dust->timeout = (int)(Random() % HAGALAZ_DUST_FRAMES) + HAGALAZ_DUST_FRAMES; dust->lifespan = dust->timeout; dust->sprite.scale = vector_make(1, 1); @@ -1167,7 +1182,7 @@ static PocketUseEnd reverse_lovers_use(PocketUse& use) static void reverse_chariot_dust_spawn(Entity_Player& player) { Vector direction = random_direction(); - Vector velocity = vector_scale(direction, random_unit() * REVERSE_CHARIOT_DUST_SPEED); + Vector velocity = vector_scale(direction, random_unit() * DUST_SPEED); uint32_t seed = Random(); Vector offsetDirection = random_direction(); Vector position = vector_add(player.pos, vector_scale(offsetDirection, random_unit() * REVERSE_CHARIOT_DUST_SPREAD)); @@ -2051,6 +2066,6 @@ PocketUseEnd card_effect_run(PocketUse& use, int card) return soul_jacob_use(use); } if (card >= (int)g_manager->itemConfig.cards.size()) log_printf(LOG_WARN, "Warning: Card %d don't exist\n", card); - else reconstruction_missing(("Entity_Player::UseCard 007b2230 (card " + std::to_string(card) + ")").c_str()); + else if (card == CARD_REVERSE_FOOL) reconstruction_missing("Entity_Player::UseCard 007b2230 (Reverse Fool, case 56)"); return POCKET_END_ANIMATE; } diff --git a/src/entity_player_characters.cpp b/src/entity_player_characters.cpp index 3b580a5..a8797aa 100644 --- a/src/entity_player_characters.cpp +++ b/src/entity_player_characters.cpp @@ -22,6 +22,8 @@ #include #include +constexpr uint64_t DEAD_BIRD_VERSUS_MS = 30001; +constexpr int DEAD_BIRD_VERSUS_FRAMES = 450; constexpr int CHARGE_STORE_MAX = 99; constexpr int SOUL_CHARGE_CONSUMABLE = 0x20; constexpr int BLOOD_CHARGE_CONSUMABLE = 0x100; @@ -110,40 +112,6 @@ bool is_azazel(Entity_Player& player) player.temporaryEffects.HasTrinketEffect(TRINKET_AZAZELS_STUMP); } -// Whether the frame and the stat evaluation are reconstructed for the player's character: the normal ones and the -// tainted ones the frame (00782af0, 00794e50) has no branch for. Tainted Judas's and Tainted Keeper's Birthright have -// one, and so has Tainted Lazarus's, which keeps both forms in the room. -bool is_character_reconstructed(Entity_Player& player) -{ - switch (player.playerType) - { - case PLAYER_JUDAS_B: - case PLAYER_KEEPER_B: - case PLAYER_LAZARUS_B: - case PLAYER_LAZARUS2_B: - return !player.HasCollectible(COLLECTIBLE_BIRTHRIGHT); - case PLAYER_JACOB_B: - case PLAYER_JACOB2_B: - case PLAYER_ISAAC_B: - case PLAYER_MAGDALENE_B: - case PLAYER_BLUEBABY_B: - case PLAYER_THEFORGOTTEN_B: - case PLAYER_THESOUL_B: - case PLAYER_LILITH_B: - case PLAYER_CAIN_B: - case PLAYER_SAMSON_B: - case PLAYER_EVE_B: - case PLAYER_AZAZEL_B: - case PLAYER_EDEN_B: - case PLAYER_THELOST_B: - case PLAYER_APOLLYON_B: - case PLAYER_BETHANY_B: - return true; - default: - return player.playerType >= PLAYER_ISAAC && player.playerType <= PLAYER_ESAU; - } -} - // The tears up or down a character adds to the items' before Binge Eater's: Samson's, the tainted ones', Azazel's (or // its stump's) and the twins'. float character_tears_get(Entity_Player& player) @@ -426,7 +394,7 @@ Vector PlayerManager::find_safe_spawn_position(Vector position) for (int radius = 0; radius < SAFE_SPAWN_TRIES && bestDistance <= SAFE_SPAWN_FAR_ENOUGH; radius += SAFE_SPAWN_RADIUS_STEP) { - float angle = random_unit() * 3.14f; + float angle = random_unit() * PI_ROUGH; angle = angle + angle; float distance = (float)radius + SAFE_SPAWN_RADIUS_MIN; Vector spot = vector_make(std::cos(angle) * distance + position.x, std::sin(angle) * distance + position.y); @@ -1085,17 +1053,23 @@ void Entity_Player::ChangePlayerType(int newType, bool isKeepState) // The TakeDamage part (007729d0) for the items Eve and Samson start with: Dead Bird's effect wakes (and its costume // goes), and Bloody Lust, Bloody Gust and Blood Rights count the hit, Bloody Lust's and Bloody Gust's effects waking -// (Samson's Bloody Lust without its costume). The deathmatch's timed Dead Bird is not reconstructed yet. +// (Samson's Bloody Lust without its costume). A versus match wakes Dead Bird for 15 seconds at most every 30. void character_items_hit(Entity_Player& player) { TemporaryEffects& effects = player.temporaryEffects; + bool isVersus = g_game->deathmatchManager.is_active(); - if (player.HasCollectible(COLLECTIBLE_DEAD_BIRD)) + if (player.HasCollectible(COLLECTIBLE_DEAD_BIRD) && + (!isVersus || versus_cooldown_is_over(player.versus.deadBirdMs, DEAD_BIRD_VERSUS_MS))) { - if (g_game->deathmatchManager.is_active()) - reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Dead Bird's deathmatch cooldown)"); ItemConfig_Item* deadBird = g_manager->itemConfig.GetCollectible(COLLECTIBLE_DEAD_BIRD); - effects.AddEffect(TemporaryEffect(deadBird), true, 1); + TemporaryEffect birds(deadBird); + if (isVersus) + { + birds.cooldown = DEAD_BIRD_VERSUS_FRAMES; + player.versus.deadBirdMs = versus_time_get(); + } + effects.AddEffect(birds, true, 1); player.RemoveCostume(deadBird); } bool isLust = player.HasCollectible(COLLECTIBLE_BLOODY_LUST); @@ -1179,6 +1153,14 @@ void Entity_Player::add_samson_berserk_charge(int amount) temporaryEffects.isEvaluateCachePending = true; } +// The damage that charges a player's items this frame: what the room's enemies took, or in a versus match what the +// player itself dealt. +float damage_dealt_get(Entity_Player& player) +{ + if (g_game->deathmatchManager.is_active()) return (float)player.versus.damageDealt; + return g_game->room->entityList.enemyDamageInflicted; +} + // 007d3560 How much charge a point of damage dealt is worth: a tenth in a versus match, else less the deeper the // floor (the alternate floors count one deeper). float damage_charge_scale() @@ -1188,15 +1170,13 @@ float damage_charge_scale() return 1 / ((float)game.stage_depth_get() * DAMAGE_CHARGE_PER_STAGE + DAMAGE_CHARGE_BASE); } -// The Berserk! charge part of 00794e50: out of Berserk!, the damage enemies took this frame charges Tainted Samson's +// The Berserk! charge part of 00794e50: out of Berserk!, the damage dealt this frame charges Tainted Samson's // berserk bar and any Berserk! held in an active slot. static void berserk_charge_update(Entity_Player& player) { bool isCharging = player.HasCollectible(COLLECTIBLE_BERSERK) || player.playerType == PLAYER_SAMSON_B; if (!isCharging || player.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_BERSERK)) return; - if (g_game->deathmatchManager.is_active()) - reconstruction_missing("Entity_Player::update_effects 00794e50 (the versus damage dealt)"); - float dealt = g_game->room->entityList.enemyDamageInflicted; + float dealt = damage_dealt_get(player); if (dealt <= 0) return; int charge = (int)(damage_charge_scale() * dealt * BERSERK_CHARGE_PER_DAMAGE); diff --git a/src/entity_player_characters.h b/src/entity_player_characters.h index 105e236..fdb71ce 100644 --- a/src/entity_player_characters.h +++ b/src/entity_player_characters.h @@ -47,7 +47,6 @@ bool is_character_slowed(Entity_Player& player); bool is_eden(const Entity_Player& player); bool is_azazel(Entity_Player& player); -bool is_character_reconstructed(Entity_Player& player); // Eve's Whore of Babylon and Tainted Eve's last heart (007c9ea0). bool is_whore_of_babylon_awake(Entity_Player& player); @@ -87,3 +86,4 @@ void npc_poop_update(Entity_NPC& npc); // What a point of damage dealt adds to a damage charge (007d3560). float damage_charge_scale(); +float damage_dealt_get(Entity_Player& player); diff --git a/src/entity_player_collectibles.cpp b/src/entity_player_collectibles.cpp index 6073bc7..0c03f8f 100644 --- a/src/entity_player_collectibles.cpp +++ b/src/entity_player_collectibles.cpp @@ -2,6 +2,7 @@ #include "entity_player_passives.h" #include "active_items.h" #include "boss_ai.h" +#include "entity_combat.h" #include "entity_config.h" #include "entity_effect.h" #include "entity_familiar.h" @@ -11,6 +12,7 @@ #include "log.h" #include "manager.h" #include "music_manager.h" +#include "npc_ai.h" #include "room.h" #include "room_grid.h" #include @@ -41,8 +43,30 @@ enum RemovalItem : int NULLITEM_DOUBLED_B = 126 }; -// The collectible whose effect ends with more than its costume that is not written yet: Mega Mush. -constexpr int EFFECT_END_ITEMS[] = {625}; +// The ends of the effects: Mega Mush's unhurtable frames, Reverse Chariot's crumbling statue, Reverse Stars' shake and +// rng (shift index 34), and Spirit Shackles' trail of dust from the soul back to its body, with the exe's values. +constexpr int MEGA_MUSH_END_COOLDOWN = 90; +constexpr float STATUE_GIB_SPREAD = 40; +constexpr int STATUE_GIBS = 4; +constexpr uint32_t GIB_FLAGS_STATUE = 0x1000; +constexpr uint32_t GIB_FLAGS_STATUE_BARE = 0x1080; +constexpr int STATUE_CHIPS = 6; +constexpr float STATUE_CHIP_SPEED_MIN = 2; +constexpr float STATUE_CHIP_SPEED_RANGE = 4; +constexpr int REVERSE_STARS_SHAKE = 6; +constexpr uint32_t REVERSE_STARS_SHIFT = 34; +constexpr float SHACKLES_DRIFT = 0.1f; +constexpr float SHACKLES_DRIFT_MAX = 4; +constexpr float SHACKLES_DUST_STEP = 20; +constexpr int SHACKLES_DUST_MIN = 4; +constexpr int SHACKLES_DUST_MAX = 12; +constexpr float SHACKLES_DUST_SPREAD = 15; +constexpr float SHACKLES_DUST_SIZE = 0.3f; +constexpr float SHACKLES_DUST_RISE = 16; +constexpr int SHACKLES_POOF_SUBTYPE = 10; +constexpr int SHACKLES_FLASH_FRAMES = 8; +constexpr ColorMod SHACKLES_DUST_COLOR = {{1, 1, 1, 1}, {0, 0, 0, 0}, {1, 1, 1}}; +constexpr ColorMod SHACKLES_POOF_COLOR = {{1, 1, 1, 1}, {1, 1, 1, 1}, {0, 0, 0}}; // The suplex aiming when Berserk ends leaps at once. constexpr int SUPLEX_STATE_AIMING = 2; @@ -279,11 +303,9 @@ static void collectible_effect_end(Entity_Player& player, int collectibleId) } } -// Spin to Win's spin over: its costume comes off, the player's familiars come back to their own orbits, and its -// wisps go out. -static void spin_to_win_end(Entity_Player& player, ItemConfig_Item* spin) +// Spin to Win's spin over: the player's familiars come back to their own orbits, and its wisps go out. +static void spin_to_win_end(Entity_Player& player) { - player.RemoveCostume(spin); for (Entity* entity : g_game->room->entityList.updateEL) { if (entity->type != ENTITY_FAMILIAR || static_cast(entity)->player != &player) continue; @@ -297,27 +319,199 @@ static void spin_to_win_end(Entity_Player& player, ItemConfig_Item* spin) player.EvaluateItems(); } -// 00793970 An item's temporary effect ran out or was taken: a collectible's costume comes off unless the item keeps -// it, the doubled ones with it, then the collectible's own end runs (see collectible_effect_end), and a null effect's -// costume comes off (Spin to Win's spin ends). A trinket's effect takes its costume off (Faded Polaroid's fading -// colour too). The other null effects and the items whose end does more are not written yet. +// Mega Mush's end: a player wearing its giant costume shrinks back in a TransformBack shown over the screen, hidden +// meanwhile, and is unhurtable for 3 seconds at least. +static void mega_mush_end(Entity_Player& player) +{ + int costume = player.playerCostumeMap[PLAYER_LAYER_HEAD].index; + CostumeSpriteDesc* desc = costume >= 0 ? &player.costumeSpriteDescs[costume] : nullptr; + if (desc && desc->item && desc->item->type == ITEM_ACTIVE && desc->item->id == COLLECTIBLE_MEGA_MUSH) + { + sound_play(SOUND_MEGA_MUSH_SHRINK); + ANM2& overlay = g_game->itemOverlay.megaMushPlayerSprite; + overlay = desc->sprite; + for (LayerState& layer : overlay.layerStates) layer.pos = {}; + overlay.Play("TransformBack", PLAY_FORCED); + g_game->itemOverlay.Show(GIANTBOOK_MEGA_MUSH, 0, &player); + player.isVisible = false; + log_printf(LOG_INFO, "[Frame %d] Mega Mush Ending, starting Shrink Animation \n", g_game->frameCount); + } + player.damageCooldown = std::max(player.damageCooldown, MEGA_MUSH_END_COOLDOWN); +} + +// Reverse Chariot's statue crumbles: rock gibs (with six rock chips when its statue costume was worn) and a crumble. +static void reverse_chariot_end(Entity_Player& player, bool isStatueWorn) +{ + gibs_spawn({.position = player.pos, .spawner = &player, .spread = STATUE_GIB_SPREAD, .amount = STATUE_GIBS, + .gibFlags = isStatueWorn ? GIB_FLAGS_STATUE : GIB_FLAGS_STATUE_BARE}); + for (int chip = 0; isStatueWorn && chip < STATUE_CHIPS; chip++) + { + Vector side = random_direction(); + Vector at = vector_add(player.pos, vector_scale(side, random_unit() * 0.5f * player.size)); + Vector heading = random_direction(); + Vector velocity = vector_scale(heading, random_between(STATUE_CHIP_SPEED_MIN, STATUE_CHIP_SPEED_RANGE)); + g_game->Spawn({.position = at, .velocity = velocity, .spawner = &player, .type = ENTITY_EFFECT, + .variant = EFFECT_TOOTH_PARTICLE, .seed = Random()}); + } + sound_play(SOUND_ROCK_CRUMBLE); +} + +// Reverse Sun's end: the bone hearts it turned red heart containers into turn back, as far as the player still has +// them, unless the player's health is not plain hearts. +static void reverse_sun_end(Entity_Player& player) +{ + int restored = std::min(player.reverseSunBoneHearts, player.boneHearts); + for (int heart = 0; heart < player.reverseSunBoneHearts && player.boneHearts > 0; heart++) + { + player.boneHearts--; + uint32_t mask = (uint32_t)player.boneHeartsMask; + for (int bit = 0; bit < 32; bit++) + { + uint32_t below = (1u << bit) - 1; + if (!(mask & (1u << bit))) continue; + player.boneHeartsMask = (int)(((mask >> 1) & ~below) | (mask & below)); + break; + } + } + player.AddMaxHearts(restored * 2, false); + player.UpdateHeartDependentEffects(); + player.reverseSunBoneHearts = 0; +} + +// Reverse Stars' end: a black poof, a shake, and two items from the room's pool drop on either side, each with a +// poof. A player still lifting its pickup drops the held sprite in another poof. +static void reverse_stars_end(Entity_Player& player) +{ + sound_play(SOUND_BLACK_POOF); + player.MakeGroundPoof(player.pos, COLOR_DEFAULT, 1); + game_shake_screen(REVERSE_STARS_SHAKE); + RNG rng; + rng.SetSeed(player.GetCardRNG(CARD_REVERSE_STARS).Next(), REVERSE_STARS_SHIFT); + for (float side : {-PICKUP_SPOT_STEP, PICKUP_SPOT_STEP}) + { + int item = g_game->itemPool.GetSeededCollectible(rng.Next(), 0, *g_game->room->descriptor); + Vector spot = room_free_pickup_position_find({.position = vector_add(player.pos, vector_make(side, 0)), + .step = PICKUP_SPOT_STEP}); + g_game->Spawn({.position = spot, .subType = item, .type = ENTITY_PICKUP, .variant = PICKUP_COLLECTIBLE, + .seed = rng.Next()}); + g_game->Spawn({.position = spot, .type = ENTITY_EFFECT, .variant = EFFECT_POOF01, .seed = Random()})->Update(); + } + if (!player.bodySprite.IsPlaying("Pickup") && !player.bodySprite.IsPlaying("Pickup_Online")) return; + + player.heldSprite.Reset(); + const AnimationFrame* frame = player.bodySprite.animState.GetLayerFrame(0); + if (!frame) return; + Entity* poof = g_game->Spawn({.position = player.pos, .type = ENTITY_EFFECT, .variant = EFFECT_POOF01, .seed = Random()}); + poof->sprite.offset = vector_make(player.sprite.scale.x * frame->pos.x, player.sprite.scale.y * frame->pos.y); + poof->Update(); +} + +// Spirit Shackles' soul is pulled back into its body: a trail of white dust from the soul to the body, a poof where it +// stood, and the player is moved there unhurtable for 3 seconds, flashing white as the body goes. +static void spirit_shackles_end(Entity_Player& player) +{ + Entity* body = player.astralProjectionBody.get(); + if (!body) return; + + Vector gap = vector_sub(body->pos, player.pos); + Vector drift = vector_scale(gap, SHACKLES_DRIFT); + float driftLength = vector_length(drift); + if (driftLength > SHACKLES_DRIFT_MAX && driftLength > 0) drift = vector_scale(drift, SHACKLES_DRIFT_MAX / driftLength); + int dust = std::clamp((int)std::floor(vector_length(gap) / SHACKLES_DUST_STEP), SHACKLES_DUST_MIN, SHACKLES_DUST_MAX); + for (int puff = 1; puff <= dust; puff++) + { + float along = (float)puff / (float)(dust + 1); + Vector side = random_direction(); + Vector at = vector_add(vector_add(player.pos, vector_scale(gap, along)), + vector_scale(side, random_unit() * SHACKLES_DUST_SPREAD)); + uint32_t seed = Random(); + Vector velocity = vector_scale(drift, random_unit() * 0.5f + 0.5f); + Entity* puffEntity = g_game->Spawn({.position = at, .velocity = velocity, .type = ENTITY_EFFECT, + .variant = EFFECT_HAEMO_TRAIL, .seed = seed}); + puffEntity->SetColor(SHACKLES_DUST_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); + float size = random_unit() * SHACKLES_DUST_SIZE + SHACKLES_DUST_SIZE; + puffEntity->sprite.scale = vector_make(along * size, along * size); + puffEntity->posOffset = vector_make(player.posOffset.x, player.posOffset.y - player.sprite.scale.y * SHACKLES_DUST_RISE); + } + Entity* poof = g_game->Spawn({.position = player.pos, .velocity = drift, .subType = SHACKLES_POOF_SUBTYPE, + .type = ENTITY_EFFECT, .variant = EFFECT_POOF02, .seed = Random()}); + poof->SetColor(SHACKLES_POOF_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); + poof->posOffset = player.posOffset; + poof->sprite.scale = player.sprite.scale; + + player.velocity = {}; + player.Teleport(body->pos, false, false); + player.damageCooldown = std::max(player.damageCooldown, MEGA_MUSH_END_COOLDOWN); + player.ResetColor(); + ColorMod flash = player.sprite.color; + color_multiply(flash, SHACKLES_DUST_COLOR); + player.SetColor(flash, SHACKLES_FLASH_FRAMES, COLOR_PRIORITY_DEFAULT, true, true); + body->Remove(); +} + +// A null effect's end: its costume comes off (Reverse Chariot's statue first), then Spin to Win's spin, Reverse +// Empress's, Chariot's, Sun's, Devil's and Stars' cards, the Wavy Cap and Spirit Shackles' soul end their own way. +static void null_effect_end(Entity_Player& player, int nullItem) +{ + ItemConfig& items = g_manager->itemConfig; + TemporaryEffects& effects = player.temporaryEffects; + bool isStatueWorn = false; + + if (nullItem == NULLITEM_REVERSE_CHARIOT) + { + ItemConfig_Item* statue = items.GetNullItem(NULLITEM_REVERSE_CHARIOT_ALT); + isStatueWorn = std::ranges::any_of(player.playerCostumeMap, [&](const PlayerCostumeMap& map) + { return map.index >= 0 && player.costumeSpriteDescs[map.index].item == statue; }); + player.RemoveCostume(statue); + } + player.RemoveCostume(items.GetNullItem(nullItem)); + switch (nullItem) + { + case NULLITEM_SPIN_TO_WIN: + return spin_to_win_end(player); + case NULLITEM_REVERSE_EMPRESS: + for (int heart = player.reverseEmpressMaxHearts; heart > 0; heart--) + if (player.soulHearts + player.boneHearts * 2 + player.maxHearts > 2) player.AddMaxHearts(-2, false); + player.reverseEmpressMaxHearts = 0; + return; + case NULLITEM_REVERSE_CHARIOT: + if (!effects.HasNullEffect(nullItem)) reverse_chariot_end(player, isStatueWorn); + return; + case NULLITEM_REVERSE_SUN: + if (!effects.HasNullEffect(nullItem) && player.reverseSunBoneHearts > 0 && + player.GetHealthType() == HEALTH_DEFAULT) + reverse_sun_end(player); + return; + case NULLITEM_REVERSE_DEVIL: + if (!effects.HasNullEffect(nullItem) && !effects.HasCollectibleEffect(COLLECTIBLE_BIBLE)) + effects.AddCollectibleEffect(COLLECTIBLE_BIBLE, true, 1); + return; + case NULLITEM_REVERSE_STARS: + return reverse_stars_end(player); + case NULLITEM_WAVY_CAP_1: + return player.update_mini_mush_costume(); + case NULLITEM_SPIRIT_SHACKLES_SOUL: + return spirit_shackles_end(player); + } +} + +// 00793970 An item's temporary effect ran out or was taken. A null effect ends its own way (see null_effect_end). A +// trinket's effect takes its costume off (Faded Polaroid's fading colour too). A collectible's doubled costumes come +// off, Mega Mush shrinks back, its costume comes off unless the item keeps it, and its own end runs (see +// collectible_effect_end). void Entity_Player::trigger_collectible_effect_removed(ItemConfig_Item* item, int) { - constexpr int NULL_EFFECTS_WITH_ENDS[] = {62, 63, 66, 67, 70, 71, 101}; - if (item->type == ITEM_NULL && item->id == NULLITEM_SPIN_TO_WIN) return spin_to_win_end(*this, item); - if (item->type == ITEM_NULL && std::ranges::find(NULL_EFFECTS_WITH_ENDS, item->id) == std::end(NULL_EFFECTS_WITH_ENDS)) - return RemoveCostume(g_manager->itemConfig.GetNullItem(item->id)); + if (item->type == ITEM_NULL) return null_effect_end(*this, item->id); if (item->type == ITEM_TRINKET) { TryRemoveTrinketCostume(item->id); if (item->id == TRINKET_FADED_POLAROID) ResetColor(); return; } - if (!item->IsCollectible()) - reconstruction_missing("Entity_Player::trigger_collectible_effect_removed 00793970 (a null effect)"); + if (!item->IsCollectible()) return; + doubled_costume_remove(*this, item->id); - if (std::ranges::find(EFFECT_END_ITEMS, item->id) != std::end(EFFECT_END_ITEMS)) - reconstruction_missing("Entity_Player::trigger_collectible_effect_removed 00793970 (an item's own end)"); + if (item->id == COLLECTIBLE_MEGA_MUSH) mega_mush_end(*this); TryRemoveCollectibleCostume(item->id, true); collectible_effect_end(*this, item->id); } @@ -359,10 +553,9 @@ void Entity_Player::RemoveCollectible(int type, bool isIgnoreModifiers, int acti log_printf(LOG_INFO, "Removing collectible %d (%s) from player %d (%s)\n", type, item->GetLocalizedName().c_str(), playerIndex, name.c_str()); - if (type < 0) reconstruction_missing("Entity_Player::RemoveCollectible 0078f840 (a procedural item)"); - if (collectibleCounts[type] >= 1) collectibleCounts[type]--; - else if (!proceduralItems.empty()) - reconstruction_missing("Entity_Player::RemoveCollectible 0078f840 (the procedural item copying it)"); + if (type < 0) glitched_item_remove(*this, type); + else if (collectibleCounts[type] >= 1) collectibleCounts[type]--; + else if (int glitched = glitched_item_copying(*this, ITEM_PASSIVE, type)) RemoveCollectible(glitched, false, 0, true); bool isSlotGiven = activeSlot >= 0 && activeSlot < ACTIVE_SLOT_COUNT && activeItems[activeSlot].item == type; int first = isSlotGiven ? activeSlot : 0; @@ -377,7 +570,7 @@ void Entity_Player::RemoveCollectible(int type, bool isIgnoreModifiers, int acti TriggerCollectibleRemoved(type); doubled_costume_remove(*this, type); - if (collectibleCounts[type] < 1) + if (type >= 0 && collectibleCounts[type] < 1) { if (item->isAddCostumeOnPickup && !HasCollectible(type)) RemoveCostume(item); if (type == REMOVAL_MARS) RemoveCostume(items.GetNullItem(NULLITEM_MARS_DASH)); @@ -400,15 +593,17 @@ void Entity_Player::RemoveCollectible(int type, bool isIgnoreModifiers, int acti UpdateBookOfVirtues(false); } -// Shows an item over the player's head: the pedestal's sprite with the item's graphics plays its animation (left alone -// when it already shows it), lifted a little. -static void held_sprite_show(Entity_Player& player, const std::string& gfx, std::string_view spriteAnimName) +// Shows an item over the player's head: the pedestal's sprite with the item's graphics (a glitched item's cell of the +// item surface) plays its animation (left alone when it already shows it), lifted a little. +static void held_sprite_show(Entity_Player& player, const ItemConfig_Item& item, std::string_view spriteAnimName) { ANM2& held = player.heldSprite; held.Reset(); held.Load(g_manager->entityConfig.GetEntity(ENTITY_PICKUP, PICKUP_COLLECTIBLE, 0)->anm2Path, GRAPHICS_DEFER); - held.ReplaceSpritesheet(1, gfx); + LayerState* layer = item.type != ITEM_TRINKET && item.id < 0 ? held.GetLayer(1) : nullptr; + if (layer) procedural_layer_set(*layer, item.id); + else held.ReplaceSpritesheet(1, item.gfxFilename); held.LoadGraphics(); held.Play(spriteAnimName); held.offset = vector_make(0, HELD_SPRITE_RISE); @@ -432,8 +627,7 @@ void Entity_Player::AnimateCollectible(int collectibleId, std::string_view animN ItemConfig_Item* item = g_manager->itemConfig.GetCollectible(collectibleId); if (!item) return; - if (collectibleId < 0) reconstruction_missing("Entity_Player::AnimateCollectible 007ab380 (a procedural item)"); - held_sprite_show(*this, item->gfxFilename, spriteAnimName); + held_sprite_show(*this, *item, spriteAnimName); PlayExtraAnimation(animName); } @@ -443,7 +637,7 @@ void Entity_Player::AnimateTrinket(int trinketId, std::string_view animName, std ItemConfig_Item* item = g_manager->itemConfig.GetTrinket((uint32_t)trinketId & TRINKET_ID_MASK); if (!item) return; - held_sprite_show(*this, item->gfxFilename, spriteAnimName); + held_sprite_show(*this, *item, spriteAnimName); PlayExtraAnimation(animName); } diff --git a/src/entity_player_coop.cpp b/src/entity_player_coop.cpp new file mode 100644 index 0000000..636abd7 --- /dev/null +++ b/src/entity_player_coop.cpp @@ -0,0 +1,712 @@ +#include "entity_player.h" +#include "active_items.h" +#include "boss_ai.h" +#include "entity_bomb.h" +#include "entity_config.h" +#include "entity_effect.h" +#include "entity_familiar.h" +#include "entity_laser.h" +#include "entity_npc.h" +#include "entity_pickup.h" +#include "game.h" +#include "item_config.h" +#include "log.h" +#include "manager.h" +#include "menu_manager.h" +#include "npc_ai.h" +#include "persistent_game_data.h" +#include "room.h" +#include "room_grid.h" +#include "sfx_manager.h" +#include "temporary_effects.h" +#include +#include + +// The co-op babies' hover, and how often their skins act: every 30 frames, 1 time in 50. +constexpr float BABY_HOVER_RATE = 0.2f; +constexpr int BABY_EFFECT_FRAMES = 30; +constexpr uint32_t BABY_EFFECT_ODDS = 50; +constexpr int BABY_BUFF_FRAMES = 150; +constexpr int BABY_EFFECT_COOLDOWN = 150; +constexpr int REVENGE_LUSTY_BLOOD_COUNT = 5; + +// Spider Baby's blue spider (every 120 frames, 1 time in 30), Cursed Baby's pull (up to 0.9 within 300), Troll Baby's +// troll bomb (every 900 frames, half the time, not in its first 6), Lost Baby's creep (1 time in 80, scaled 0.2 to +// 0.7) and Sucky Baby's drain (every 7 frames, 0.3 of a tear's damage within 150, a hit every 30 frames). +constexpr int SPIDER_BABY_FRAMES = 120; +constexpr uint32_t SPIDER_BABY_ODDS = 30; +constexpr float CURSED_PULL_RANGE = 300; +constexpr float CURSED_PULL_MAX = 0.9f; +constexpr int TROLL_BABY_FRAMES = 900; +constexpr int TROLL_BABY_SETTLE = 6; +constexpr uint32_t LOST_CREEP_ODDS = 80; +constexpr float LOST_CREEP_SCALE_RANGE = 0.5f; +constexpr float LOST_CREEP_SCALE_MIN = 0.2f; +constexpr int SUCKY_FRAMES = 7; +constexpr float SUCKY_RANGE = 150; +constexpr float SUCKY_DAMAGE_SHARE = 0.3f; +constexpr int SUCKY_DAMAGE_COUNTDOWN = 30; + +// A dying baby's last act: up to 3 blue spiders, flies, coins or thrown spiders, 8 tears around at 10, a spider +// thrown 100 away from 30 up, and coins dropped 40 away. +constexpr int BABY_DEATH_DROPS = 3; +constexpr float BABY_DEATH_SPIDER_REACH = 40; +constexpr float BABY_DEATH_TEAR_SPEED = 10; +constexpr int BABY_DEATH_TEAR_STEP = 45; +constexpr float BABY_DEATH_THROW_STEP = 100; +constexpr float BABY_DEATH_THROW_HEIGHT = -30; +constexpr int HEART_HALF_SUBTYPE = 2; +constexpr uint32_t BABY_DEATH_TEAR_FLAGS = 3; + +// The chain a Bound Baby keeps to its player, and its reach. +constexpr float BOUND_CHAIN_REACH = 120; + +// A co-op baby the Apollyon skin brings: three orbital flies 20 away. +constexpr float BABY_COMPANION_REACH = 20; + +// A revived ghost: its hurt cooldown, its hearts (3 at most, two for a coin character, three halves for soul ones and +// one for the Lost, two red and a bone heart for bone ones), and its poof's sound. +constexpr int GHOST_REVIVE_COOLDOWN = 60; +constexpr int GHOST_REVIVE_RED_MAX = 3; +constexpr int GHOST_REVIVE_COIN_RED = 2; +constexpr int GHOST_REVIVE_COIN_MAX = 4; +constexpr int GHOST_REVIVE_SOUL = 3; +constexpr int GHOST_REVIVE_LOST_SOUL = 1; +constexpr int GHOST_REVIVE_BONE_RED = 2; + +// The inputs a possessed enemy waits for before it takes the possessing player's controller, in the original's order. +constexpr ButtonAction POSSESS_ACTIONS[] = {ACTION_LEFT, ACTION_UP, ACTION_RIGHT, ACTION_DOWN, + ACTION_SHOOT_LEFT, ACTION_SHOOT_UP, ACTION_SHOOT_RIGHT, ACTION_SHOOT_DOWN, + ACTION_ITEM, ACTION_PILL_CARD, ACTION_BOMB, ACTION_DROP}; + +// A skin that keeps an item effect going while its player lacks it: on its main player, or on the room. +struct BabyItemEffect +{ + int skin = 0; + int collectible = 0; + int count = 0; + bool isRoomEffect = false; +}; + +constexpr BabyItemEffect BABY_ITEM_EFFECTS[] = {{BABY_NOOSE, COLLECTIBLE_TRANSCENDENCE}, + {BABY_HIVE, COLLECTIBLE_HIVE_MIND}, + {BABY_BUDDY, COLLECTIBLE_GUILLOTINE}, + {BABY_WHORE, COLLECTIBLE_WHORE_OF_BABYLON}, + {BABY_DRIPPING, COLLECTIBLE_ANEMIC}, + {BABY_REVENGE, COLLECTIBLE_LUSTY_BLOOD, REVENGE_LUSTY_BLOOD_COUNT}, + {BABY_BELIAL, COLLECTIBLE_BOOK_OF_BELIAL}, + {BABY_SALE, COLLECTIBLE_STEAM_SALE, 0, true}, + {BABY_GOAT, COLLECTIBLE_GOAT_HEAD, 0, true}}; + +// Whether an entity is one a player can possess or pull: an enemy (or another player in versus). +static bool is_possessable(Entity* entity) +{ + if (!entity) return false; + return (g_game->deathmatchManager.is_active() && entity->type == ENTITY_PLAYER) || Entity::is_enemy_type(entity->type); +} + +// Whether a skin's chance to act came up this frame. +static bool is_baby_effect_roll(Entity_Player& player) +{ + return player.IsFrame(BABY_EFFECT_FRAMES, 0) && Random() % BABY_EFFECT_ODDS == 0; +} + +// Plays the dripping overlay over the baby's sprite once its extra animation is done. +static void baby_drip_show(Entity_Player& player) +{ + if (!player.IsExtraAnimationFinished()) return; + player.sprite.PlayOverlay("Dripping"); + player.sprite.isOverlayRenderFirst = true; +} + +// Gives every player one of the Rage to Brown skins' buffs for 150 frames at least, asking for its stats again. +static void coop_buff_share(CoopBabyBuff buff) +{ + for (Entity_Player* player : g_game->playerManager.playerList) + { + int& timer = player->coopBabyBuffTimers[buff]; + bool isSize = buff == COOP_BUFF_SMALLER || buff == COOP_BUFF_LARGER; + if (isSize && timer < 1) + { + player->cacheFlags |= CACHE_SIZE; + player->EvaluateItems(); + } + timer = std::max(timer, BABY_BUFF_FRAMES); + if (isSize || buff == COOP_BUFF_BUTT_PENNY) continue; + player->cacheFlags |= COOP_BUFF_CACHES[buff]; + player->EvaluateItems(); + } +} + +// Dark Baby's share: every buff from damage to luck for every player. +static void coop_buff_share_all() +{ + for (Entity_Player* player : g_game->playerManager.playerList) + for (int buff = COOP_BUFF_DAMAGE; buff <= COOP_BUFF_LUCK; buff++) + { + player->coopBabyBuffTimers[buff] = std::max(player->coopBabyBuffTimers[buff], BABY_BUFF_FRAMES); + player->cacheFlags |= COOP_BUFF_CACHES[buff]; + player->EvaluateItems(); + } +} + +// A skin that keeps an item effect going: added now and then while its holder lacks it. False when the effect is +// there, letting the frame go on to the ghost's drip. +static bool baby_item_effect_update(Entity_Player& player, const BabyItemEffect& kept) +{ + TemporaryEffects& effects = + kept.isRoomEffect ? g_game->room->temporaryEffects : player.GetMainPlayer()->temporaryEffects; + if (effects.HasCollectibleEffect(kept.collectible)) return false; + if (!is_baby_effect_roll(player)) return true; + + TemporaryEffect effect; + effect.item = g_manager->itemConfig.GetCollectible(kept.collectible); + effect.count = kept.count; + effect.cooldown = BABY_EFFECT_COOLDOWN; + effects.AddEffect(effect, true, 1); + return true; +} + +// Cursed Baby pulls enemies and projectiles toward itself, harder the nearer they are. +static void cursed_baby_pull(Entity_Player& player) +{ + for (Entity* entity : g_game->room->entityList.updateEL) + { + if (!is_possessable(entity) && entity->type != ENTITY_PROJECTILE) continue; + Vector toward = vector_sub(player.pos, entity->pos); + float distance = vector_length(toward); + Vector direction = distance > 0 ? vector_scale(toward, 1 / distance) : toward; + float pull = std::min(std::max((CURSED_PULL_RANGE - distance) * CURSED_PULL_MAX / CURSED_PULL_RANGE, 0.0f), + CURSED_PULL_MAX); + if (entity->friction == 0) continue; + entity->velocity.x = pull * direction.x * entity->speedMultiplier / entity->friction + entity->velocity.x; + entity->velocity.y = pull * direction.y * entity->speedMultiplier / entity->friction + entity->velocity.y; + } +} + +// Sucky Baby drains the vulnerable enemies around it. +static void sucky_baby_drain(Entity_Player& player) +{ + if (!player.IsFrame(SUCKY_FRAMES, (int)player.index)) return; + for (Entity* enemy : entity_query_radius(player.pos, SUCKY_RANGE, QUERY_ENEMIES)) + { + if (!enemy->IsVulnerableEnemy(nullptr)) continue; + EntityRef source(&player); + TearParams params = player.GetTearHitParams(WEAPON_TEARS, 1, (int)(Random() & 1) * 2 - 1, nullptr); + enemy->TakeDamage(params.tearDamage * SUCKY_DAMAGE_SHARE, 0, source, SUCKY_DAMAGE_COUNTDOWN); + } +} + +// A co-op baby's skin's frame. False when it lets the frame go on to the ghost's drip. +static bool baby_skin_update(Entity_Player& player) +{ + Game& game = *g_game; + int skin = player.babySkin; + + if (skin >= BABY_RAGE && skin <= BABY_BROWN) + { + auto buff = (CoopBabyBuff)(skin - BABY_RAGE); + if (player.coopBabyBuffTimers[buff] >= 1) return false; + if (is_baby_effect_roll(player)) coop_buff_share(buff); + return true; + } + for (const BabyItemEffect& kept : BABY_ITEM_EFFECTS) + if (kept.skin == skin) return baby_item_effect_update(player, kept); + + switch (skin) + { + case BABY_SPIDER: + { + if (!player.IsFrame(SPIDER_BABY_FRAMES, (int)player.index) || Random() % SPIDER_BABY_ODDS != 0) return true; + if (game.room->GetAliveEnemiesCount() < 1 || player.HasEntityFlags(FLAG_INTERPOLATION_UPDATE)) return true; + Vector spot = room_free_pickup_position_find({.position = player.pos, .isAvoidActiveEntities = true}); + player.numBlueSpiders++; + spawn_blue_spider(spot, &player, {}); + return true; + } + case BABY_CURSED: + cursed_baby_pull(player); + return true; + case BABY_TROLL: + { + int age = game.frameCount - player.spawnFrame; + if (age % TROLL_BABY_FRAMES != 0 || (Random() & 1) != 0 || age < TROLL_BABY_SETTLE) return true; + Entity* spawned = game.Spawn({.position = player.pos, .spawner = &player, .type = ENTITY_BOMB, + .variant = BOMB_TROLL, .seed = Random()}); + if (auto* bomb = dynamic_cast(spawned)) + { + bomb->tearFlags = player.GetBombFlags(false); + bomb->isLoadCostumes = true; + } + return true; + } + case BABY_LOST: + if (Random() % LOST_CREEP_ODDS == 0) + { + Entity* creep = game.Spawn({.position = player.pos, .spawner = &player, .type = ENTITY_EFFECT, + .variant = EFFECT_PLAYER_CREEP_RED, .seed = Random()}); + float scale = random_unit() * LOST_CREEP_SCALE_RANGE + LOST_CREEP_SCALE_MIN; + creep->sprite.scale = vector_make(scale, scale); + creep->Update(); + } + baby_drip_show(player); + return true; + case BABY_WATER: + if (!player.sprite.GetAnimationData("Dripping")) return false; + baby_drip_show(player); + return true; + case BABY_SUCKY: + sucky_baby_drain(player); + return true; + case BABY_DARK: + if (is_baby_effect_roll(player)) coop_buff_share_all(); + return true; + case BABY_PICKY: + { + Entity_Player* main = player.GetMainPlayer(); + if (main->paperClipTimer >= 1) return false; + main->paperClipTimer = std::max(main->paperClipTimer, BABY_BUFF_FRAMES); + return true; + } + case BABY_MORT: + { + if (player.babyFamiliar) return true; + auto* fly = static_cast(player.AddBlueFlies(1, player.pos, nullptr)); + fly->set_player(&player); + player.babyFamiliar = fly; + return true; + } + case BABY_BOUND: + case BABY_FOUND_SOUL: + baby_drip_show(player); + return true; + default: + return false; + } +} + +// 007ba2b0 A co-op baby's (or ghost's) frame: its skin's effect, a ghost's drip, and its hover. +void Entity_Player::update_baby_skin_effects() +{ + if (isDead) return; + if (!baby_skin_update(*this) && isCoopGhost) baby_drip_show(*this); + float wave = std::sin((float)g_game->frameCount * BABY_HOVER_RATE); + posOffset.y = wave + wave; +} + +// 007bb5e0 A co-op baby's skin's last act as it dies: spiders, a heart, tears around, a troll bomb, coins, a bomb, +// creep, a pickup, flies, the Sun, or its familiars gone. +void Entity_Player::coop_baby_death_effect() +{ + Game& game = *g_game; + + switch (babySkin) + { + case BABY_SPIDER: + for (int i = (int)(Random() % BABY_DEATH_DROPS) + 1; i > 0; i--) + { + Vector direction = random_direction(); + float reach = random_unit() * BABY_DEATH_SPIDER_REACH; + Vector at = vector_make(direction.x * reach + pos.x, direction.y * reach + pos.y); + numBlueSpiders++; + spawn_blue_spider(at, this, {}); + } + break; + case BABY_LOVE: + { + uint32_t seed = Random(); + game.Spawn({.position = room_free_tile_position_find(pos, 0), .spawner = this, .type = ENTITY_PICKUP, + .variant = PICKUP_HEART, .seed = seed}); + break; + } + case BABY_WATER: + for (int degrees = 0; degrees < (int)FULL_TURN_DEGREES; degrees += BABY_DEATH_TEAR_STEP) + { + float angle = (float)degrees * DEGREES_TO_RADIANS; + Vector velocity = vector_make(std::cos(angle) * BABY_DEATH_TEAR_SPEED, std::sin(angle) * BABY_DEATH_TEAR_SPEED); + FireTear({pos, velocity}, BABY_DEATH_TEAR_FLAGS, nullptr, 1); + } + break; + case BABY_TROLL: + { + Entity* spawned = game.Spawn({.position = pos, .spawner = this, .type = ENTITY_BOMB, .variant = BOMB_TROLL, + .seed = Random()}); + if (auto* bomb = dynamic_cast(spawned)) + { + bomb->tearFlags = GetBombFlags(false); + bomb->isLoadCostumes = true; + } + break; + } + case BABY_HOST: + for (int i = (int)(Random() % BABY_DEATH_DROPS) + 1; i > 0; i--) + { + Vector target = room_free_pickup_position_find({.position = pos, .step = BABY_DEATH_THROW_STEP}); + Entity_NPC::ThrowSpider(pos, this, target, false, BABY_DEATH_THROW_HEIGHT); + } + break; + case BABY_GOLD: + for (int i = (int)(Random() % BABY_DEATH_DROPS) + 1; i > 0; i--) + { + uint32_t seed = Random(); + game.Spawn({.position = room_free_pickup_position_find({.position = pos, .step = PICKUP_SPOT_STEP}), + .spawner = this, .type = ENTITY_PICKUP, .variant = PICKUP_COIN, .seed = seed}); + } + break; + case BABY_WRATH: + { + uint32_t seed = Random(); + game.Spawn({.position = room_free_tile_position_find(pos, 0), .type = ENTITY_PICKUP, .variant = PICKUP_BOMB, + .seed = seed}); + break; + } + case BABY_LOST: + { + Entity* creep = game.Spawn({.position = pos, .spawner = this, .type = ENTITY_EFFECT, + .variant = EFFECT_PLAYER_CREEP_HOLYWATER, .seed = Random()}); + creep->SetColor(ColorMod(), -1, COLOR_PRIORITY_DEFAULT, false, true); + creep->Update(); + break; + } + case BABY_GLASS: + game.Spawn({.position = pos, .type = ENTITY_PICKUP, .variant = PICKUP_NULL, .seed = Random()}); + break; + case BABY_DEAD: + AddBlueFlies((int)(Random() % BABY_DEATH_DROPS) + 1, pos, nullptr); + break; + case BABY_BLOAT: + case BABY_MORT: + if (babyFamiliar) babyFamiliar->Remove(); + break; + case BABY_FIGHTING: + { + uint32_t seed = Random(); + game.Spawn({.position = room_free_tile_position_find(pos, 0), .spawner = this, .subType = HEART_HALF_SUBTYPE, + .type = ENTITY_PICKUP, .variant = PICKUP_HEART, .seed = seed}); + break; + } + case BABY_BLINDING: + UseCard(CARD_SUN, 0); + break; + case BABY_APOLLYON: + { + Entity* companion = babyFamiliar; + if (!companion) break; + companion->Remove(); + Entity* next = companion->child; + if (next && next->type == ENTITY_FAMILIAR && next->variant == Entity_Familiar::FLY_ORBITAL) next->Remove(); + break; + } + } +} + +// 007bf040 Dresses a co-op baby in its skin's sheet (a basic baby in its subtype's), on every layer. +void Entity_Player::InitBabySkin() +{ + std::vector& babies = g_manager->entityConfig.babies; + uint32_t skin = (uint32_t)babySkin; + if (skin == BABY_BASIC) + { + skin = (uint32_t)subtype; + if (skin < BABY_BASIC || skin >= babies.size()) log_printf(LOG_ASSERT, "Bad baby basic id %d", subtype); + if (skin < BABY_BASIC) skin = UINT32_MAX; + } + else if (skin < BABY_BASIC && skin >= babies.size()) + log_printf(LOG_ASSERT, "Baby list is smaller than requested baby %d!", babySkin); + + // The original reads past the baby list for a skin it lacks, so such a skin keeps the sheets here. + if (skin < babies.size()) + for (int layer = 0; layer < (int)sprite.layerStates.size(); layer++) sprite.ReplaceSpritesheet(layer, babies[skin].gfx); + sprite.LoadGraphics(); +} + +// 007c2e90 The skin a glitched co-op baby takes: any unlocked baby but the glitched one and Baby 0, drawn from the +// player manager's glitch generator without moving it. The basic baby when none is unlocked. +uint32_t Entity_Player::GetGlitchBabySubType() +{ + std::vector candidates; + for (EntityConfig_Baby& baby : g_manager->entityConfig.babies) + { + if (baby.id == BABY_GLITCH || baby.id == BABY_0) continue; + if (baby.achievementID >= 0 && !g_manager->persistentGameData.Unlocked(baby.achievementID)) continue; + candidates.push_back(baby.id); + } + if (candidates.empty()) + { + log_printf(LOG_INFO, "[err] Couldn't select a baby subtype!\n"); + return BABY_BASIC; + } + + RNG draw = RNG_DEFAULT; + draw._seed = g_game->playerManager.glitchBabyRng._seed; + return (uint32_t)candidates[draw.RandomInt((uint32_t)candidates.size())]; +} + +// 007cb090 What a co-op baby's skin brings as it joins: hearts for itself or its player, a full heal, the Bound Baby's +// chain, or the Found Soul's single soul heart. +void Entity_Player::apply_coop_baby_spawn_bonus() +{ + switch (babySkin) + { + case BABY_BLACK: + AddBlackHearts(2); + break; + case BABY_RED: + AddMaxHearts(2, false); + AddHearts(2, false, false); + break; + case BABY_WHITE: + GetMainPlayer()->AddEternalHearts(1); + break; + case BABY_BLUE: + AddSoulHearts(2, false); + break; + case BABY_COLORFUL: + GetMainPlayer()->SetFullHearts(); + break; + case BABY_BOUND: + bound_chain_spawn(); + break; + case BABY_FOUND_SOUL: + AddMaxHearts(-maxHearts, false); + soulHearts = 1; + break; + } +} + +// The Bound Baby's chain to its main player, reaching 120. +void Entity_Player::bound_chain_spawn() +{ + Entity_Player* main = GetMainPlayer(); + auto* chain = static_cast(g_game->Spawn( + {.position = main->pos, .type = ENTITY_EFFECT, .variant = EFFECT_FORGOTTEN_CHAIN, .seed = Random()})); + chain->child = main; + chain->target = this; + chain->scale = BOUND_CHAIN_REACH; + chain->Update(); +} + +// The familiars some co-op babies join with, seeded on from the player's init generator: Bloat Baby's orbital fly, +// Apollyon Baby's two chained ones and Ybab's shuffled aim axes. +void Entity_Player::baby_companions_spawn(RNG& initRng) +{ + if (babySkin == BABY_YBAB) + { + mirroredAimAxes = {vector_make(1, 0), vector_make(-1, 0), vector_make(0, 1), vector_make(0, -1)}; + for (int i = AIM_AXIS_COUNT - 1; i > 0; i--) std::swap(mirroredAimAxes[i], mirroredAimAxes[Random() % (uint32_t)(i + 1)]); + return; + } + if (babySkin != BABY_BLOAT && babySkin != BABY_APOLLYON) return; + + Entity_Familiar* previous = nullptr; + int count = babySkin == BABY_APOLLYON ? 2 : 1; + for (int i = 0; i < count; i++) + { + uint32_t seed = initRng.Next(); + Vector direction = random_direction(); + Vector at = vector_make(direction.x * BABY_COMPANION_REACH + pos.x, direction.y * BABY_COMPANION_REACH + pos.y); + auto* fly = static_cast(g_game->Spawn({.position = at, .spawner = this, .type = ENTITY_FAMILIAR, + .variant = Entity_Familiar::FLY_ORBITAL, .seed = seed})); + fly->set_player(this); + if (previous) + { + previous->child = fly; + fly->Update(); + continue; + } + fly->Update(); + babyFamiliar = fly; + previous = fly; + } +} + +// Ybab's aim: each axis of the input turned along the axis it was dealt. +Vector Entity_Player::mirrored_aim_get(Vector aim) +{ + const Vector& across = mirroredAimAxes[aim.x < 0 ? 1 : 0]; + const Vector& along = mirroredAimAxes[aim.y < 0 ? 3 : 2]; + float x = std::abs(aim.x); + float y = std::abs(aim.y); + return vector_make(x * across.x + 0 + y * along.x, x * across.y + 0 + y * along.y); +} + +// 007829a0 A co-op baby whose items changed takes its main player's pill uses (Tainted Forgotten's soul its twin's) +// and asks for every stat again. +void Entity_Player::coop_items_sync() +{ + isCoPlayerItemsInvalid = false; + if (variant != PLAYER_VARIANT_COOP_BABY) return; + + Entity_Player* main = parent && parent->type == ENTITY_PLAYER ? parent->ToPlayer() : g_game->GetPlayer(0); + if (playerType == PLAYER_THESOUL_B) main = twinPlayer ? twinPlayer->ToPlayer() : nullptr; + if (main) std::copy_n(main->pillEffectUses.begin(), pillEffectUses.size(), pillEffectUses.begin()); + cacheFlags = CACHE_ALL; + EvaluateItems(); +} + +// 007585b0 A possessing player's frame: its map button moves it on to the next enemy in the room it can target +// (wrapping around), freeing the last one, snapping onto the first one it takes, with a sound for a local player. An +// enemy it holds with no controller yet takes its controller on its first move, shot or button. +void Entity_Player::cycle_spectate_target() +{ + if (input_is_action_triggered(ACTION_MAP, controllerIndex, nullptr)) + { + Entity* current = target; + Entity* first = nullptr; + Entity* next = nullptr; + bool isPastCurrent = !current; + for (Entity* entity : g_game->room->entityList.updateEL) + { + Entity* candidate = is_possessable(entity) ? entity : nullptr; + if (candidate == current) + { + isPastCurrent = true; + continue; + } + if (!candidate || !candidate->is_valid_target()) continue; + if (!first) first = candidate; + if (isPastCurrent) + { + next = candidate; + break; + } + } + if (!next) next = first; + + if (next && next != current) + { + if (!current) + { + pos = next->pos; + velocity = {}; + } + else if (Entity::is_enemy_type(current->type)) static_cast(current)->controllerID = -1; + targetPosition.x = current ? 0.0f : 1.0f; + target = next; + if (IsLocalPlayer()) sound_play(SOUND_CHARACTER_SELECT_RIGHT); + } + } + + Entity* held = target; + if (!held || !Entity::is_enemy_type(held->type)) return; + auto& npc = static_cast(*held); + if (npc.controllerID != -1) return; + for (ButtonAction action : POSSESS_ACTIONS) + if (input_is_action_pressed(action, controllerIndex, nullptr)) + { + npc.controllerID = controllerIndex; + return; + } +} + +// 007d93b0 Brings a co-op ghost back (and its backup players that are ghosts too): its character's sprite, pockets +// and trinkets back, a few hearts by its health kind, a poof, and Tainted Forgotten's soul back beside him. +void Entity_Player::RevivePlayerGhost() +{ + for (Entity_Player* player = this; player; player = player->backupPlayer) + { + if (player != this && !player->isCoopGhost) break; + player->ghost_revive(); + } +} + +// A ghost made a player again. +void Entity_Player::ghost_revive() +{ + Game& game = *g_game; + + isCoopGhost = false; + isInvincible = false; + entityCollisionClass = ENTCOLL_ALL; + sprite.overlayAnimState.SetAnimationData(nullptr); + // The original loads a garbage path without a player config, so the sprite stays here. + if (EntityConfig_Entity* config = g_manager->entityConfig.GetEntity(ENTITY_PLAYER, 0, 0)) + sprite.Load(config->anm2Path, GRAPHICS_DEFER); + update_player_skin(); + if (!game.isRestoringGlowingHourglassState) PlayExtraAnimation("Appear"); + damageCooldown = GHOST_REVIVE_COOLDOWN; + UpdateCostumes(); + pocketItems = ghostPocketItems; + trinkets = ghostTrinkets; + cacheFlags |= CACHE_ALL; + EvaluateItems(); + + soulHearts = 0; + blackHearts = 0; + eternalHearts = 0; + boneHeartsMask = 0; + boneHearts = 0; + rottenHearts = 0; + if (maxHearts >= 1) + { + redHearts = std::min(maxHearts, GHOST_REVIVE_RED_MAX); + if (GetHealthType() == HEALTH_COIN) redHearts = GHOST_REVIVE_COIN_RED; + } + else if (GetHealthType() == HEALTH_BONE) + { + redHearts = GHOST_REVIVE_BONE_RED; + AddBoneHearts(1); + } + else if (GetHealthType() == HEALTH_COIN) + { + redHearts = GHOST_REVIVE_COIN_MAX; + maxHearts = GHOST_REVIVE_COIN_MAX; + } + else + { + bool isLost = GetHealthType() == HEALTH_NO_HEALTH; + redHearts = 0; + soulHearts = isLost ? GHOST_REVIVE_LOST_SOUL : GHOST_REVIVE_SOUL; + } + + sound_play(SOUND_BLACK_POOF); + game.Spawn({.position = pos, .type = ENTITY_EFFECT, .variant = EFFECT_POOF01, .seed = Random()}); + if (playerType != PLAYER_THEFORGOTTEN_B) return; + + Entity_Player* soul = InitTwin(PLAYER_THESOUL_B); + soul->InitPostLevelInitStats(); + soul->PlayExtraAnimation("Appear"); + soul->damageCooldown = GHOST_REVIVE_COOLDOWN; +} + +// 007d96f0 Turns a dead co-op player into a ghost (and its backup player too): revived as a ghost without its soul +// twin, its Lost curse, pockets and trinkets (kept for its revival), passing through, untouchable and without wisps. +// Tainted Forgotten's soul never becomes one. +void Entity_Player::MorphToCoopGhost() +{ + if (playerType == PLAYER_THESOUL_B) return; + + Game& game = *g_game; + if (playerType == PLAYER_THEFORGOTTEN_B && twinPlayer) + { + game.playerManager.RemoveCoPlayer(twinPlayer->ToPlayer()); + twinPlayer = nullptr; + } + Revive(); + if (playerType == PLAYER_THEFORGOTTEN && forgottenBody) SwapForgottenForm(true, false); + temporaryEffects.RemoveNullEffect(NULLITEM_LOST_CURSE, 1); + if (game.deathmatchManager.is_active()) game.deathmatchManager.type->player_ghost_morph(*this); + UpdateCostumes(); + + auto& pockets = hasCurseMistEffect ? curseMistPocketItems : pocketItems; + auto& held = hasCurseMistEffect ? curseMistTrinkets : trinkets; + ghostPocketItems = pockets; + pockets.fill({0, POCKET_CARD}); + ghostTrinkets = held; + held.fill(0); + + reset_body_sprite(); + PlayExtraAnimation("GhostAppear"); + if (game.deathmatchManager.is_active()) entityCollisionClass = ENTCOLL_NONE; + entityGridCollisionClass = GRIDCOLL_WALLS; + cacheFlags |= CACHE_ALL; + isCoopGhost = true; + isInvincible = true; + isVisible = true; + EvaluateItems(); + + for (int wispVariant : {(int)Entity_Familiar::WISP, (int)Entity_Familiar::ITEM_WISP}) + for (Entity* wisp : entity_query(ENTITY_FAMILIAR, wispVariant)) + if (static_cast(wisp)->player == this) wisp->Remove(); + if (backupPlayer && !backupPlayer->isCoopGhost) backupPlayer->MorphToCoopGhost(); +} diff --git a/src/entity_player_crafting.cpp b/src/entity_player_crafting.cpp index e7882cb..b17445c 100644 --- a/src/entity_player_crafting.cpp +++ b/src/entity_player_crafting.cpp @@ -152,7 +152,6 @@ constexpr int BURST_RNG_SHIFT = 13; constexpr int BURST_PICK_RNG_SHIFT = 35; constexpr int BURST_MIN_PICKUPS = 4; constexpr int BURST_PICKUP_BASE = 3; -constexpr int BURST_LUCKY_TOE_ODDS = 3; constexpr int BURST_COIN_MAX = 3; constexpr float BURST_COINS_BELOW = 0.35f; constexpr float BURST_HEART_BELOW = 0.55f; @@ -465,7 +464,7 @@ void Entity_Player::tainted_cain_pedestal_burst(Vector position, uint32_t seed, { RNG rng = rng_make(seed, BURST_RNG_SHIFT); int count = std::max(BURST_MIN_PICKUPS, (int)(rng.Next() & 3) + BURST_PICKUP_BASE); - if (rng.Next() % BURST_LUCKY_TOE_ODDS != 0 && HasTrinket(TRINKET_LUCKY_TOE)) count++; + if (rng.Next() % LUCKY_TOE_ODDS != 0 && HasTrinket(TRINKET_LUCKY_TOE)) count++; burst_trinket_roll(*this, rng, position); if (HasCollectible(COLLECTIBLE_BIRTHRIGHT) && playerType == PLAYER_CAIN_B) count *= 2; diff --git a/src/entity_player_damage.cpp b/src/entity_player_damage.cpp index df9534f..4e2a0e7 100644 --- a/src/entity_player_damage.cpp +++ b/src/entity_player_damage.cpp @@ -25,10 +25,10 @@ #include "room_grid.h" #include #include +#include constexpr int COLLECTIBLE_BINKY = 438; constexpr int COLLECTIBLE_CONE_HEAD = 457; -constexpr int COLLECTIBLE_JELLY_BELLY = 690; constexpr int COLLECTIBLE_MARBLES = 538; constexpr int COLLECTIBLE_METAL_PLATE = 449; constexpr int COLLECTIBLE_SPIRIT_SHACKLES = 674; @@ -38,7 +38,6 @@ constexpr int TRINKET_FINGER_BONE = 128; constexpr int TRINKET_SWALLOWED_M80 = 178; constexpr int TRINKET_WALNUT = 108; constexpr int NULLITEM_DOUBLE_DAMAGE = 29; -constexpr int NULLITEM_SHACKLES_GHOST = 101; constexpr int SAMSON_B_HIT_CHARGE = 10000; constexpr int BLEED_OUT_HEALTH = 600; @@ -98,6 +97,13 @@ constexpr float BRITTLE_BONES_SPEED = 10; constexpr float BRITTLE_BONES_SCALE = 1.355f; constexpr float BRITTLE_BONES_DAMAGE_SCALE = 2; constexpr float BRITTLE_BONES_DAMAGE_BONUS = 22; + +// A versus hit's hearts: sixteen points to a heart, a fifth more on a baited player, and two to five blue flies from +// each rotten heart broken. +constexpr float VERSUS_HEART_POINTS = 16; +constexpr float VERSUS_BAITED_DAMAGE_SCALE = 1.2f; +constexpr int VERSUS_ROTTEN_FLIES_MIN = 2; +constexpr int VERSUS_ROTTEN_FLIES_RANGE = 4; constexpr float DAMAGE_ROUNDING = 0.5f; constexpr float HALVED_DAMAGE = 0.5f; constexpr float HALVED_DAMAGE_DEATHMATCH = 0.75f; @@ -140,7 +146,7 @@ static bool is_damage_ignored(Entity_Player& player, const EntityRef& source, ui if (source.type == ENTITY_EFFECT && source.variant == EFFECT_SELF_DAMAGE && source.spawnerType == ENTITY_PLAYER) return true; if (source.IsFriendly() && !game.deathmatchManager.is_active()) return true; - if (source.IsFriendly()) reconstruction_missing("Entity_Player::TakeDamage 007729d0 (friendly fire in versus)"); + if (source.IsFriendly() && (!entity || entity->IsDamageSourceFriendly(EntityRef(&player)))) return true; if (damageFlags & DAMAGE_IGNORED) return true; Entity* darkEsau = player.darkEsau.get(); @@ -596,6 +602,95 @@ static int hearts_remove(Entity_Player& player, int amount, uint64_t damageFlags return amount; } +// Takes a versus hit's points from one kind of heart, counted sixteen to a heart. Returns how many whole hearts broke. +static int versus_hearts_take(int& hearts, int& amount) +{ + int before = (int)std::ceil((float)hearts / VERSUS_HEART_POINTS); + int taken = std::min(hearts, amount); + hearts -= taken; + amount -= taken; + return before - (int)std::ceil((float)hearts / VERSUS_HEART_POINTS); +} + +// Takes a versus hit's points: Pause lifts at a hit from its user, the bait raises the hit by a fifth (rounded up) +// unless its baiter dealt it, then black hearts go first (each broken one sets off the Necronomicon), then bone hearts +// (each broken one shoots a ring of bone tears), rotten hearts (blue flies), golden, soul and red ones. +static int versus_hearts_remove(Entity_Player& player, int amount, const EntityRef& source) +{ + Room& room = *g_game->room; + Entity* attacker = source.entity ? source.entity->GetPlayerAncestor() : nullptr; + auto* user = static_cast(attacker); + + if (room.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_PAUSE) && user && user->versusPauseTimer != 0) + { + room.temporaryEffects.RemoveCollectibleEffect(COLLECTIBLE_PAUSE, 1); + room.isPacifist = false; + user->versusPauseTimer = 0; + } + if (player.HasEntityFlags(FLAG_BAITED) && source.entity && !source.entity->IsDescendantOf(player.baitedSource.entity)) + amount = (int)std::ceil((float)amount * VERSUS_BAITED_DAMAGE_SCALE); + + if (amount > 0) + { + for (int broken = versus_hearts_take(player.blackHearts, amount); broken > 0; broken--) + { + player.UseActiveItem({.item = COLLECTIBLE_NECRONOMICON, .flags = USE_NOANIM | USE_ALLOWNONMAIN}); + voice_play(SOUND_BLACK_POOF, 1, SOUND_FRAME_DELAY, 1); + } + } + if (amount > 0) + { + int broken = versus_hearts_take(player.boneHearts, amount); + for (int heart = 0; heart < broken; heart++) + { + float turn = random_unit() * BRITTLE_BONES_TURN; + for (int i = 0; i < BRITTLE_BONES_TEARS; i++) + { + uint32_t seed = Random(); + Vector direction = vector_from_angle(((float)i / BRITTLE_BONES_TEARS + turn) * BRITTLE_BONES_TURN); + auto* tear = static_cast(g_game->Spawn({.position = player.pos, + .velocity = vector_scale(direction, BRITTLE_BONES_SPEED), + .spawner = &player, .type = ENTITY_TEAR, + .variant = TEAR_BONE, .seed = seed})); + TearParams params = player.GetTearHitParams(WEAPON_TEARS, 1, random_below(2) * 2 - 1, nullptr); + params.tearFlags.set(TEAR_BONE_FLAG); + tear->SetTearFlags(params.tearFlags); + tear->SetScale(params.tearScale * BRITTLE_BONES_SCALE); + tear->SetCollisionDamage(params.tearDamage * BRITTLE_BONES_DAMAGE_SCALE); + tear->SetHeight(params.tearHeight); + tear->parent = &player; + tear->Update(); + } + } + if (broken > 0) + { + game_particles_spawn({.color = BONE_SHARD_COLOR, .position = player.pos, .height = player.posOffset.y, + .speed = random_unit() * BONE_SHARD_SPEED_RANDOM + BONE_SHARD_SPEED_MIN, + .count = BONE_SHARD_COUNT, .variant = EFFECT_TOOTH_PARTICLE}); + voice_play(SOUND_BONE_SNAP, BONE_SNAP_VOLUME, SOUND_FRAME_DELAY, random_unit() * BONE_SNAP_PITCH_RANDOM + 1); + if (player.HasCollectible(COLLECTIBLE_BRITTLE_BONES)) + { + player.brittleBonesUpgrades += broken; + player.cacheFlags |= CACHE_FIREDELAY; + player.EvaluateItems(); + } + } + } + if (amount > 0) + { + for (int broken = versus_hearts_take(player.rottenHearts, amount); broken > 0; broken--) + player.AddBlueFlies(VERSUS_ROTTEN_FLIES_MIN + random_below(VERSUS_ROTTEN_FLIES_RANGE), player.pos, nullptr); + } + + player.BreakGoldenHearts(amount > 0 ? versus_hearts_take(player.goldenHearts, amount) : 0); + if (amount > 0) versus_hearts_take(player.soulHearts, amount); + + bool isRedHit = amount > 0; + if (isRedHit) versus_hearts_take(player.redHearts, amount); + if (isRedHit) player.UpdateHeartDependentEffects(); + return amount; +} + // 007db2d0 Spends one of the Holy Mantles Wooden Cross lends (one per copy, two at most, beyond those spent), moving // one from the lent half of the stacks to the spent half. Whether there was one. static bool wooden_cross_mantle_spend(Entity_Player& player) @@ -660,8 +755,6 @@ static bool hit_items_check(Entity_Player& player, int amount, const ItemsHit& h if (player.HasEntityFlags(FLAG_BLEED_OUT) && player.bleedSource.entity == &player && player.bleedOutHealth > 0) player.bleedOutHealth = BLEED_OUT_HEALTH; - if (!player.proceduralItems.empty()) - reconstruction_missing("Entity_Player::TakeDamage 007729d0 (glitched items, trigger_set_dispatch)"); return isHurtShown; } @@ -940,7 +1033,7 @@ bool Entity_Player::TakeDamage(float damage, uint64_t damageFlags, const EntityR if (source.type >= ENTITY_FIRST_ENEMY && source.type <= ENTITY_LAST_ENEMY) bestiary_count_add(g_manager->persistentGameData.bestiary.hits, source.type, source.variant); if (game.debugFlags & DEBUG_DAMAGE_VALUES) - reconstruction_missing("Entity_Player::TakeDamage 007729d0 (spawn_debug_damage_text)"); + debug_damage_text_spawn(pos, DEBUG_DAMAGE_TAKEN_ARGB, std::format("hurt {}", (int)amount)); if ((damageFlags & (DAMAGE_FIRE | DAMAGE_POOP)) && !(damageFlags & DAMAGE_EXPLOSION)) voice_play(SOUND_FIREDEATH_HISS, 1, SOUND_FRAME_DELAY, 1); @@ -976,8 +1069,7 @@ bool Entity_Player::TakeDamage(float damage, uint64_t damageFlags, const EntityR } if (game.debugFlags & DEBUG_INFINITE_HP) amount = 0; - else if (amount > 0 && game.deathmatchManager.is_active()) - reconstruction_missing("Entity_Player::TakeDamage 007729d0 (versus hearts)"); + else if (amount > 0 && game.deathmatchManager.is_active()) amount = versus_hearts_remove(*this, amount, source); else if (amount > 0) amount = hearts_remove(*this, amount, damageFlags, isPenalized); bool isAstral = HasCollectible(COLLECTIBLE_ASTRAL_PROJECTION) && !game.room->IsClear() && @@ -1323,7 +1415,7 @@ static void spirit_shackles_bind(Entity_Player& player) constexpr int BODY_STATE = 10; constexpr float SHACKLES_CHAIN_SCALE = 80; constexpr float SHACKLES_CHAIN_REACH = 10; - player.temporaryEffects.AddNullEffect(NULLITEM_SHACKLES_GHOST, true, 1); + player.temporaryEffects.AddNullEffect(NULLITEM_SPIRIT_SHACKLES_SOUL, true, 1); player.temporaryEffects.AddNullEffect(NULLITEM_SPIRIT_SHACKLES_DISABLED, true, 1); player.soulHearts = 0; player.blackHearts = 0; @@ -1393,7 +1485,7 @@ bool Entity_Player::try_trigger_astral_projection() { bool isShackled = HasCollectible(COLLECTIBLE_SPIRIT_SHACKLES) && temporaryEffects.GetNullEffectNum(NULLITEM_SPIRIT_SHACKLES_DISABLED) == 0 && - temporaryEffects.GetNullEffectNum(NULLITEM_SHACKLES_GHOST) == 0; + temporaryEffects.GetNullEffectNum(NULLITEM_SPIRIT_SHACKLES_SOUL) == 0; if (isShackled) { spirit_shackles_bind(*this); @@ -1507,7 +1599,7 @@ const char* Entity_Player::GetDeathAnimName() bool isGhost = playerType == PLAYER_THELOST || playerType == PLAYER_THELOST_B || playerType == PLAYER_JACOB2_B || playerType == PLAYER_THESOUL_B || playerType == PLAYER_THESOUL || temporaryEffects.GetCollectibleEffectNum(COLLECTIBLE_ASTRAL_PROJECTION) == 1 || - temporaryEffects.GetNullEffectNum(NULLITEM_SHACKLES_GHOST) == 1 || + temporaryEffects.GetNullEffectNum(NULLITEM_SPIRIT_SHACKLES_SOUL) == 1 || temporaryEffects.HasNullEffect(NULLITEM_LOST_CURSE) || (variant == PLAYER_VARIANT_COOP_BABY && babySkin == BABY_GHOST) || isCoopGhost; if (isGhost) return "LostDeath"; diff --git a/src/entity_player_dashes.cpp b/src/entity_player_dashes.cpp new file mode 100644 index 0000000..b3a4c18 --- /dev/null +++ b/src/entity_player_dashes.cpp @@ -0,0 +1,607 @@ +#include "entity_player_effects.h" +#include "boss_ai.h" +#include "capsule.h" +#include "entity_bomb.h" +#include "entity_effect.h" +#include "entity_npc.h" +#include "entity_player.h" +#include "entity_projectile.h" +#include "game.h" +#include "manager.h" +#include "npc_ai.h" +#include "npc_basement.h" +#include "room.h" +#include "room_grid.h" +#include "sfx_manager.h" +#include "temporary_effects.h" +#include + +// Salvation's halo and Dark Arts' aura, a halo above the player, and Dark Arts' darkened sprite. +constexpr float RIDING_HALO_RISE = -15; +constexpr int HALO_TURN_FRAMES = 360; +constexpr float DARK_ARTS_ALPHA_MIN = 0.1f; +constexpr float DARK_ARTS_ALPHA_RANGE = 0.1f; +constexpr int DARK_ARTS_FRAMES_PER_COUNT = 30; +constexpr int DARK_ARTS_DAMAGE_COOLDOWN = 8; +constexpr int DARK_ARTS_END_COOLDOWN = 15; +constexpr int DARK_ARTS_SHAKE = 10; +constexpr float DARK_ARTS_POOF_SIZE = 0.8f; +constexpr float DARK_ARTS_BLAST_THRESHOLD = 50; +constexpr float DARK_ARTS_BLAST_RADIUS = 80; +constexpr int DARK_ARTS_FLASH_FRAMES = 3; +constexpr float DARK_ARTS_REACH = 10; +constexpr float DARK_ARTS_AURA_REACH = 40; +constexpr float DARK_ARTS_AURA_EXTRA = 30; +constexpr float DARK_ARTS_AURA_SCALE = 120; +constexpr float DARK_ARTS_TEAR_SCALE = 2; +constexpr float DARK_ARTS_SNARE_DAMAGE = 3.5f; +constexpr float DARK_ARTS_SNARE_VOLUME = 0.8f; +constexpr float DARK_ARTS_SNARE_PITCH = 1.5f; +constexpr float DARK_ARTS_SNARE_PITCH_STEP = 0.05f; +constexpr float DARK_ARTS_TRAIL_SCALE = 2; +constexpr float DARK_ARTS_TRAIL_RADIUS = 0.32f; +constexpr float DARK_ARTS_TRAIL_END_RADIUS = 0.16f; + +// The smoke Dark Arts' strikes (and Soul of Magdalene's) leave rising off the player's head every other tick. +constexpr int SMOKE_COUNT_MAX = 16; +constexpr float SMOKE_STEP = 0.0625f; +constexpr float SMOKE_ODDS = 0.6f; +constexpr float SMOKE_SOUL_ODDS = 1.6f; +constexpr float SMOKE_SPREAD_Y = 0.8f; +constexpr float SMOKE_REACH = 16; +constexpr float SMOKE_DRIFT = 0.3f; +constexpr float SMOKE_CARRY = 0.5f; +constexpr float SMOKE_SCALE_STEP = 1.33f; +constexpr float HEAD_SMOKE_SCALE_MIN = 0.66f; +constexpr float SMOKE_SOUL_SCALE = 1.99f; +constexpr float HEAD_SMOKE_RISE = -30; +constexpr float SMOKE_SPEED_MAX = 1.3f; +constexpr float SMOKE_SOUL_SPEED = 0.79999995f; +constexpr float SMOKE_DEPTH = -20; +constexpr int SMOKE_REMOVE_PERIOD = 15; + +// Soul of ???'s farts: every 8 frames, a butt bomb in its last 2 seconds, a fart before. +constexpr int SOUL_BLUEBABY_PERIOD = 8; +constexpr int SOUL_BLUEBABY_BOMB_FRAMES = 60; +constexpr float SOUL_BLUEBABY_FART_RADIUS = 85; +constexpr float SOUL_BLUEBABY_BEAN_RADIUS = 120; + +// Mega Mush's ending blinks: every 10 frames in its last second, then every 15 to 3 seconds, every 30 to 5. +constexpr int MEGA_MUSH_BLINK_LAST = 30; +constexpr int MEGA_MUSH_BLINK_MIDDLE = 90; +constexpr int MEGA_MUSH_BLINK_FIRST = 150; + +// The dashes: a pony's and Mars' speed, Suplex!'s, how they bounce off walls, hit and throw what they run into. +constexpr float PLAYER_DASH_SPEED = 15; +constexpr float SUPLEX_RUN_SPEED = 12; +constexpr int SUPLEX_DASH_FRAMES_MIN = 8; +constexpr int PONY_CHARGE_FRAMES = 60; +constexpr int MARS_EFFECT_PAD = 4; +constexpr float MARS_PUSH = 4; +constexpr float RECALL_SLOW_SQUARED = 25; +constexpr int DASH_FLASH_PERIOD = 4; +constexpr float WHITE_PONY_SPREAD = 12; +constexpr float WHITE_PONY_SPREAD_LATE = 4; +constexpr float WHITE_PONY_MARGIN = 10; +constexpr int WHITE_PONY_BEAM_SUBTYPE = 2; +constexpr float WHITE_PONY_DAMAGE_SCALE = 4; +constexpr float WHITE_PONY_DAMAGE = 10; +constexpr float WHITE_PONY_BEAM_SIZE = 64; +constexpr float DASH_DAMAGE_BONUS = 2; +constexpr float DASH_DAMAGE_SCALE = 4; +constexpr float DASH_DAMAGE_SCALE_VERSUS = 2; +constexpr float PONY_DAMAGE = 20; +constexpr float PONY_DAMAGE_VERSUS = 10; +constexpr float DASH_WIDTH = 24; +constexpr float RECALL_BATTERY_WIDTH = 36; +constexpr float DASH_QUERY_SCALE = 3; +constexpr float DASH_KNOCKBACK = 15; +constexpr float DASH_BOSS_KNOCKBACK = 0.6f; +constexpr float FIREPLACE_DAMAGE = 1000; +constexpr int DASH_SPLAT_DELAY = 10; +constexpr float DASH_SPLAT_PITCH = 1.5f; +constexpr int SUPLEX_HOLD_FRAMES = 60; +constexpr float SUPLEX_SCAMPER_PITCH = 0.9f; +constexpr float SUPLEX_SCAMPER_PITCH_RANGE = 0.2f; +constexpr LerpRange RECALL_PULL = {.inMin = 0, .inMax = 15, .outMin = 1, .outMax = 16}; +constexpr float RECALL_TRAIL_RISE = -8; +constexpr float RECALL_TRAIL_DEPTH = -5; +constexpr float RECALL_TRAIL_TINT_MIN = 0.3f; +constexpr float RECALL_TRAIL_TINT_RANGE = 0.7f; +constexpr float DASH_HEAD_ON = 0.2f; +constexpr int SUPLEX_WALL_FRAMES = 8; +constexpr int DASH_WALL_SHAKE = 8; +constexpr float DASH_WALL_BOUNCE = -10; +constexpr int AFTER_IMAGE_FRAMES = 10; + +constexpr ColorMod DARK_ARTS_BLAST_POOF = {{0.2f, 0.2f, 0.2f, 0.6f}, {1, 1, 1, 1}, {0, 0, 0}}; +constexpr ColorMod DARK_ARTS_BLAST_FLASH = {{1, 1, 1, 1}, {0, 0, 0, 0}, {1, 1, 1}}; +constexpr ColorMod DARK_SMOKE_COLOR = {{0.0313725508f, 0, 0, 1}, {0, 0, 0, 0}, {0, 0, 0}}; +constexpr ColorMod MEGA_MUSH_BLINK = {{1, 1, 1, 1}, {1, 0.2f, 0.2f, 0.6f}, {0.5f, 0, 0}}; +constexpr ColorMod RECALL_FLASH = {{0.5f, 0.5f, 0.5f, 1}, {0, 0, 0, 0}, {0.4f, 0.5f, 0.7f}}; +constexpr ColorMod DASH_FLASH = {{0.5f, 0.5f, 0.5f, 1}, {0, 0, 0, 0}, {0.6f, 0.6f, 0.6f}}; + +// Mars' dash directions by the tapped action (left, right, up, down). +constexpr Direction MARS_DIRECTIONS[] = {DIRECTION_LEFT, DIRECTION_RIGHT, DIRECTION_UP, DIRECTION_DOWN}; + +// The dash running this frame: what drives it, its frames so far and its speed. +struct Dash +{ + float speed = PLAYER_DASH_SPEED; + int frames = 0; + int kind = 0; +}; + +// A halo effect riding on the player: spawned once (or kept), the halo of a subtype, its scale and rise set each frame. +static Entity_Effect* halo_keep(Entity_Player& player, EntityPtr& halo, int subType, float scale) +{ + bool isSpawned = !halo; + if (isSpawned) + { + Entity* spawned = g_game->Spawn({.position = player.pos, .spawner = &player, .subType = subType, + .type = ENTITY_EFFECT, .variant = EFFECT_HALO, .seed = Random()}); + spawned->parent = &player; + halo = spawned; + } + auto* effect = static_cast(halo.get()); + if (effect) + { + effect->scale = scale; + effect->posOffset = vector_make(0, RIDING_HALO_RISE); + } + return isSpawned ? effect : nullptr; +} + +// Salvation: its halo floats above the player, growing with the rooms it counted and turning a degree a frame. Without +// the item it goes. +static void salvation_update(Entity_Player& player) +{ + if (!player.HasCollectible(COLLECTIBLE_SALVATION)) + { + if (Entity* halo = player.salvationEffect.get()) halo->Remove(); + player.salvationEffect = nullptr; + return; + } + Entity_Effect* spawned = halo_keep(player, player.salvationEffect, HALO_SALVATION, salvation_halo_scale_get(player)); + if (Entity* halo = player.salvationEffect.get()) + { + float half = player.HasEntityFlags(FLAG_INTERPOLATION_UPDATE) ? 0.5f : 0; + halo->sprite.rotation = (float)(player.FrameCount() % HALO_TURN_FRAMES) + half; + } + if (spawned) spawned->Update(); +} + +// Dark Arts' dash ends in a blast once its last snare is gone: the player comes back with a black poof, a shake and a +// burst hurting enemies around by the damage its snares dealt, flashing white and briefly unhurtable. +static void dark_arts_blast(Entity_Player& player) +{ + player.isDarkArtsBlastPending = false; + player.darkArtsLastSnare = nullptr; + player.ResetColor(); + npc_sound_play(SOUND_BLACK_POOF, 1, 2, 1); + game_shake_screen(DARK_ARTS_SHAKE); + player.MakeGroundPoofAtSelf(DARK_ARTS_BLAST_POOF, DARK_ARTS_POOF_SIZE); + damage_radius({.position = player.pos, .source = &player, .damage = player.darkArtsDamage, + .playerDamageThreshold = DARK_ARTS_BLAST_THRESHOLD, .radius = DARK_ARTS_BLAST_RADIUS}); + player.SetColor(DARK_ARTS_BLAST_FLASH, DARK_ARTS_FLASH_FRAMES, COLOR_PRIORITY_DEFAULT, false, true); + player.entityCollisionClass = ENTCOLL_ALL; + player.SetMinDamageCooldown(DARK_ARTS_END_COOLDOWN); + player.AddEntityFlags(FLAG_NO_DAMAGE_BLINK); + player.darkArtsHitList.clear(); + player.darkArtsDamage = 0; + player.temporaryEffects.RemoveNullEffect(NULLITEM_SOUL_JUDAS, -1); +} + +// A black trail drawn from a snare to the player when its target stands far off. +static void dark_arts_trail(Entity_Player& player, Entity& target, Vector at) +{ + auto* trail = static_cast(g_game->Spawn({.position = at, .spawner = &player, .type = ENTITY_EFFECT, + .variant = EFFECT_SPRITE_TRAIL, .seed = Random()})); + trail->parent = ⌖ + trail->sprite.color = SNARE_TRAIL_TINT; + layer_normal_set(*trail->sprite.GetLayer(0)); + trail->sprite.scale = vector_make(DARK_ARTS_TRAIL_SCALE, DARK_ARTS_TRAIL_SCALE); + trail->SetRadii(DARK_ARTS_TRAIL_RADIUS, DARK_ARTS_TRAIL_RADIUS); + trail->Update(); + trail->pos = player.pos; + trail->sprite.scale = vector_make(1, 1); + trail->SetRadii(DARK_ARTS_TRAIL_END_RADIUS, DARK_ARTS_TRAIL_END_RADIUS); + trail->Update(); +} + +// A snare laid on what Dark Arts' dash touches, at its edge within reach, chained to the last one: it holds the target +// (an enemy's status target when that shares its hit list), deals the player's tear damage plus 3.5 per link and adds +// it to the blast. +static void dark_arts_snare(Entity_Player& player, Entity& touched) +{ + Vector offset = vector_sub(touched.pos, player.pos); + float reach = player.size + (player.darkArtsAura ? DARK_ARTS_AURA_REACH : DARK_ARTS_REACH); + if (vector_length(offset) > reach) offset = vector_resized(offset, reach); + Vector at = vector_add(player.pos, offset); + Entity* target = &touched; + if (touched.IsEnemy() && touched.GetStatusEffectTarget()->GetHitListIndex() == touched.GetHitListIndex()) + target = touched.GetStatusEffectTarget(); + hit_list_insert(player.darkArtsHitList, *target); + + TearParams params = player.GetTearHitParams(WEAPON_TEARS, DARK_ARTS_TEAR_SCALE, random_below(2) * 2 - 1, nullptr); + auto* snare = static_cast(g_game->Spawn({.position = at, .spawner = &player, .type = ENTITY_EFFECT, + .variant = EFFECT_DARK_SNARE, .seed = Random()})); + if (Entity* last = player.darkArtsLastSnare) + { + last->child = snare; + snare->parent = last; + snare->subtype = last->subtype + 1; + } + snare->SetCollisionDamage((float)snare->subtype * DARK_ARTS_SNARE_DAMAGE + params.tearDamage); + effect_tear_flags_set(*snare, params.tearFlags); + snare->target = target; + snare->Update(); + player.darkArtsLastSnare = snare; + player.darkArtsDamage += snare->collisionDamage; + npc_sound_play(SOUND_TOOTH_AND_NAIL_TICK, DARK_ARTS_SNARE_VOLUME, 1, + (float)snare->subtype * DARK_ARTS_SNARE_PITCH_STEP + DARK_ARTS_SNARE_PITCH); + if (player.darkArtsAura && vector_distance(target->pos, player.pos) > target->size + player.size + DARK_ARTS_REACH) + dark_arts_trail(player, *target, at); +} + +// Dark Arts: while its dash lasts the player fades to a flicker and passes through everything, and its strikes' +// smoke lasts to a whole second. Tainted Judas with his Birthright reaches farther under a dark aura. Each enemy or +// enemy shot the dash touches is snared once. Its end turns to the blast once the snares are spent. +static void dark_arts_update(Entity_Player& player) +{ + TemporaryEffects& effects = player.temporaryEffects; + bool isDashing = effects.HasCollectibleEffect(COLLECTIBLE_DARK_ARTS); + if (isDashing || player.isDarkArtsBlastPending) + { + bool isFlicker = isDashing && !player.isDarkArtsBlastPending; + player.sprite.color._tint[3] = isFlicker ? random_between(DARK_ARTS_ALPHA_MIN, DARK_ARTS_ALPHA_RANGE) : 0; + player.entityCollisionClass = ENTCOLL_NONE; + if (TemporaryEffect* smoke = effects.GetNullEffect(NULLITEM_DARK_ARTS)) + smoke->cooldown = (smoke->cooldown + DARK_ARTS_FRAMES_PER_COUNT - 1) / DARK_ARTS_FRAMES_PER_COUNT * + DARK_ARTS_FRAMES_PER_COUNT + 1; + } + if (player.isDarkArtsBlastPending) player.SetMinDamageCooldown(DARK_ARTS_DAMAGE_COOLDOWN); + if (player.isDarkArtsBlastPending && (!player.darkArtsLastSnare || player.darkArtsLastSnare->isDead)) + dark_arts_blast(player); + if (!isDashing) + { + if (Entity* aura = player.darkArtsAura.get()) aura->parent = nullptr; + player.darkArtsAura = nullptr; + return; + } + + Capsule capsule = player.GetCollisionCapsule({}); + capsule.radius += DARK_ARTS_REACH; + if (player.playerType == PLAYER_JUDAS_B && player.HasCollectible(COLLECTIBLE_BIRTHRIGHT)) + { + capsule.radius += DARK_ARTS_AURA_EXTRA; + if (Entity_Effect* spawned = halo_keep(player, player.darkArtsAura, HALO_DARK_ARTS, + capsule.radius / DARK_ARTS_AURA_SCALE)) + spawned->Update(); + } + for (Entity* entity : entity_query_capsule(capsule, QUERY_PROJECTILES | QUERY_ENEMIES)) + { + bool isFoe = entity->IsActiveEnemy(DEAD_EXCLUDED) && !entity->IsFriendly(); + bool isShot = entity->IsProjectile() && + !(static_cast(entity)->projectileFlags & PROJECTILE_CANT_HIT_PLAYER); + if ((isFoe || isShot) && !EntityList::HitListContains(player.darkArtsHitList, *entity)) + dark_arts_snare(player, *entity); + } +} + +// A wisp of smoke off the player's head: drifting out with the player's motion, a size and playback speed, maybe +// tinted, behind what stands near. +static void head_smoke_spawn(Entity_Player& player, float scale, float speed, const ColorMod* color) +{ + Vector spread = vector_mul(vector_make(1, SMOKE_SPREAD_Y), random_direction()); + Vector offset = vector_scale(vector_scale(spread, random_unit()), SMOKE_REACH); + uint32_t seed = Random(); + Vector velocity = vector_add(vector_scale(offset, SMOKE_DRIFT), vector_scale(player.velocity, SMOKE_CARRY)); + Entity* smoke = g_game->Spawn({.position = vector_add(player.pos, player.tearsOffset), .velocity = velocity, + .type = ENTITY_EFFECT, .variant = EFFECT_HAEMO_TRAIL, .seed = seed}); + float size = std::min(scale, 1.0f); + smoke->sprite.scale = vector_make(size, size); + smoke->posOffset = vector_add(vector_make(0, HEAD_SMOKE_RISE), offset); + smoke->sprite.playbackSpeed = std::min(speed, 1.0f); + if (color) smoke->SetColor(*color, -1, COLOR_PRIORITY_DEFAULT, false, true); + smoke->renderDepthOffset = SMOKE_DEPTH; + smoke->Update(); +} + +// Dark Arts' strikes smoke off the player every other tick outside the dash (thicker the more counted), and count down +// a strike every half second. Soul of Magdalene smokes all the time. +static void head_smokes_update(Entity_Player& player) +{ + TemporaryEffects& effects = player.temporaryEffects; + if (TemporaryEffect* strikes = effects.GetNullEffect(NULLITEM_DARK_ARTS)) + { + if (player.GetIntervalTicks(2, 0) && !effects.HasCollectibleEffect(COLLECTIBLE_DARK_ARTS) && + !player.isDarkArtsBlastPending) + { + float thickness = (float)std::min(SMOKE_COUNT_MAX, strikes->count) * SMOKE_STEP; + if (random_unit() < thickness + SMOKE_ODDS) + head_smoke_spawn(player, thickness * SMOKE_SCALE_STEP + HEAD_SMOKE_SCALE_MIN, + SMOKE_SPEED_MAX - thickness * 0.5f, &DARK_SMOKE_COLOR); + } + if (strikes->cooldown % SMOKE_REMOVE_PERIOD == 0) + effects.RemoveNullEffect(NULLITEM_DARK_ARTS, strikes->count / DARK_ARTS_FRAMES_PER_COUNT + 1); + } + if (effects.GetNullEffect(NULLITEM_SOUL_MAGDALENE) && player.GetIntervalTicks(2, 0) && + random_unit() < SMOKE_SOUL_ODDS) + head_smoke_spawn(player, SMOKE_SOUL_SCALE, SMOKE_SOUL_SPEED, nullptr); +} + +// Soul of ???: every 8 frames the player farts a charming cloud with a Butter Bean push and a lasting smoke, and in the +// last 2 seconds drops butt bombs with its bomb effects instead. +static void soul_bluebaby_update(Entity_Player& player) +{ + TemporaryEffect* effect = player.temporaryEffects.GetNullEffect(NULLITEM_SOUL_BLUEBABY); + if (!effect || effect->cooldown % SOUL_BLUEBABY_PERIOD != 0) return; + + if (effect->cooldown <= SOUL_BLUEBABY_BOMB_FRAMES) + { + Entity* spawned = g_game->Spawn({.position = player.pos, .spawner = &player, .type = ENTITY_BOMB, + .variant = BOMB_BUTT, .seed = Random()}); + if (auto* bomb = static_cast(spawned)) + { + bomb->tearFlags = player.GetBombFlags(false); + bomb->isLoadCostumes = true; + } + return; + } + npc_sound_play(SOUND_FART, 1, 2, 1); + game_fart({.position = player.pos, .source = &player, .radius = SOUL_BLUEBABY_FART_RADIUS}); + game_butter_bean_fart({.position = player.pos, .source = &player, .radius = SOUL_BLUEBABY_BEAN_RADIUS, + .isShowEffect = false}); + auto* smoke = static_cast(g_game->Spawn({.position = player.pos, .spawner = &player, .subType = 1, + .type = ENTITY_EFFECT, .variant = EFFECT_SMOKE_CLOUD, + .seed = Random()})); + smoke->SetTimeout(-1); + smoke->Update(); +} + +// Mega Mush's last 5 seconds blink the player red, faster toward the end. +static void mega_mush_blink_update(Entity_Player& player) +{ + TemporaryEffect* effect = player.temporaryEffects.GetCollectibleEffect(COLLECTIBLE_MEGA_MUSH); + if (!effect || effect->cooldown > MEGA_MUSH_BLINK_FIRST) return; + + int period = effect->cooldown <= MEGA_MUSH_BLINK_LAST ? 10 : effect->cooldown <= MEGA_MUSH_BLINK_MIDDLE ? 15 : 30; + if (effect->cooldown % period != 0) return; + player.SetColor(MEGA_MUSH_BLINK, period == 10 ? 3 : 6, COLOR_PRIORITY_DEFAULT, true, true); +} + +// The dash this frame, if any: a pony's charge, Suplex!'s run past its first 8 frames, Mars' (pushed off on its +// first frame, its effect kept 4 frames ahead), or Tainted Forgotten's Recall pulling him to his body (stopped while +// slow). Without one the contacts are forgotten. +static bool dash_get(Entity_Player& player, Dash& dash) +{ + TemporaryEffects& effects = player.temporaryEffects; + if (player.ponyCharge > 0) + { + dash = {.frames = PONY_CHARGE_FRAMES - player.ponyCharge, .kind = COLLECTIBLE_PONY}; + return true; + } + if (player.suplexState == SUPLEX_DASHING) + { + if (player.suplexAimCountdown <= SUPLEX_DASH_FRAMES_MIN) return false; + dash = {.speed = SUPLEX_RUN_SPEED, .frames = player.suplexAimCountdown - SUPLEX_DASH_FRAMES_MIN, + .kind = COLLECTIBLE_SUPLEX}; + return true; + } + if (effects.HasCollectibleEffect(COLLECTIBLE_MARS)) + { + if (player.marsCooldown == player.marsDashCooldown) + { + Direction direction = player.marsDashDirection >= 0 && player.marsDashDirection < 4 + ? MARS_DIRECTIONS[player.marsDashDirection] + : DIRECTION_NONE; + Vector push = vector_from_direction(direction); + if (g_game->room->IsMirrorWorld()) push.x = -push.x; + player.AddVelocity(vector_scale(push, MARS_PUSH), false); + player.contactHitList.clear(); + npc_sound_play(SOUND_MONSTER_YELL_A, 1, 2, 1); + player.RemoveCostume(g_manager->itemConfig.GetNullItem(NULLITEM_MARS)); + return false; + } + TemporaryEffect* mars = effects.GetCollectibleEffect(COLLECTIBLE_MARS); + if (!mars || mars->cooldown <= 0) return false; + dash = {.frames = mars->cooldown, .kind = COLLECTIBLE_MARS}; + TemporaryEffect* berserk = effects.GetCollectibleEffect(COLLECTIBLE_BERSERK); + if (berserk && berserk->cooldown < MARS_EFFECT_PAD) + { + TemporaryEffect padded(g_manager->itemConfig.GetCollectible(COLLECTIBLE_BERSERK)); + padded.cooldown = MARS_EFFECT_PAD - berserk->cooldown; + effects.AddEffect(padded, false, 1); + } + return true; + } + if (!effects.HasCollectibleEffect(COLLECTIBLE_RECALL) || player.playerType != PLAYER_THEFORGOTTEN_B || + !player.twinPlayer) + return false; + ItemConfig_Item* recall = g_manager->itemConfig.GetCollectible(COLLECTIBLE_RECALL); + dash = {.frames = recall->maxCooldown - effects.GetCollectibleEffect(COLLECTIBLE_RECALL)->cooldown, + .kind = COLLECTIBLE_RECALL}; + if (vector_length_squared(player.velocity) < RECALL_SLOW_SQUARED) dash.speed = 0; + return true; +} + +// White Pony's beams fall beside the dash on even frames, to either side of its line, inside the room. +static void white_pony_beam(Entity_Player& player, bool isLate) +{ + Room& room = *g_game->room; + Vector side = vector_rotated(player.velocity, 90); + float spread = isLate ? WHITE_PONY_SPREAD_LATE : WHITE_PONY_SPREAD; + Vector along = vector_scale(side, (random_unit() - 0.5f) * spread); + Vector at = room.GetClampedPosition(vector_add(player.pos, along), WHITE_PONY_MARGIN); + Entity* beam = g_game->Spawn({.position = at, .spawner = &player, .subType = WHITE_PONY_BEAM_SUBTYPE, + .type = ENTITY_EFFECT, .variant = EFFECT_CRACK_THE_SKY, .seed = Random()}); + beam->SetCollisionDamage(player.meleeDamage * WHITE_PONY_DAMAGE_SCALE + WHITE_PONY_DAMAGE); + beam->SetSize(WHITE_PONY_BEAM_SIZE, vector_make(-1, -1), -1); + beam->parent = &player; + beam->Update(); +} + +// What a dash runs into: an enemy is thrown back (a boss less, the rest by its friction) and hurt, splatting when the +// hit lands. A fireplace is put out. Suplex! grabs it instead. Whether the dash grabbed and stops looking. +static bool dash_hit(Entity_Player& player, const Dash& dash, Entity& entity, float damage) +{ + if (!entity.IsEnemy()) return false; + if (entity.type == ENTITY_FIREPLACE) + { + entity.TakeDamage(FIREPLACE_DAMAGE, 0, EntityRef(&player), HIT_COUNTDOWN); + return false; + } + if (dash.kind == COLLECTIBLE_SUPLEX) + { + if (!player.TryHoldEntity(&entity)) return false; + player.itemState = COLLECTIBLE_SUPLEX; + player.suplexAimCountdown = SUPLEX_HOLD_FRAMES; + player.suplexState = SUPLEX_AIMING; + npc_sound_play(SOUND_SUPLEX_GRAB, 1, 2, 1); + npc_sound_play(SOUND_SCAMPER, 1, 2, random_between(SUPLEX_SCAMPER_PITCH, SUPLEX_SCAMPER_PITCH_RANGE)); + return true; + } + Vector away = vector_scale(vector_normalized(vector_sub(entity.pos, player.pos)), DASH_KNOCKBACK); + entity.AddVelocity(entity.IsBoss() ? vector_scale(away, DASH_BOSS_KNOCKBACK) : vector_scale(away, 1 / entity.friction), + false); + if (entity.TakeDamage(damage, 0, EntityRef(&player), HIT_COUNTDOWN) && entity.IsVulnerableEnemy(nullptr)) + { + npc_sound_play(SOUND_MEATY_DEATHS, 1, DASH_SPLAT_DELAY, DASH_SPLAT_PITCH); + static_cast(entity).MakeSplat(1)->SetColor(entity.splatColor, -1, COLOR_PRIORITY_DEFAULT, false, + true); + Entity::ForceCollide(&player, &entity, false); + } + return false; +} + +// Everything a dash sweeps over this frame, met once a dash: its capsule along the motion, wider for a battery-charged +// Recall, against each entity's own capsule. A pony hits harder. +static void dash_hits_update(Entity_Player& player, const Dash& dash) +{ + float length = vector_length(player.velocity); + bool isVersus = g_game->deathmatchManager.is_active(); + float damage = (player.meleeDamage + DASH_DAMAGE_BONUS) * (isVersus ? DASH_DAMAGE_SCALE_VERSUS : DASH_DAMAGE_SCALE); + float width = DASH_WIDTH; + if (dash.kind == COLLECTIBLE_PONY) damage += isVersus ? PONY_DAMAGE_VERSUS : PONY_DAMAGE; + else if (dash.kind == COLLECTIBLE_RECALL && player.HasCollectible(COLLECTIBLE_CAR_BATTERY)) + { + damage += damage; + width = RECALL_BATTERY_WIDTH; + } + Capsule sweep(player.pos, vector_make(length / DASH_WIDTH, 1), vector_angle(player.velocity), width); + + for (Entity* entity : entity_query_radius(player.pos, length * DASH_QUERY_SCALE, QUERY_ALL)) + { + bool isPlaced = vector_equal(entity->pos, entity->pos) && !vector_equal(entity->pos, player.pos); + if (!isPlaced || entity->size <= 0 || entity->sizeMulti.x <= 0 || entity->sizeMulti.y <= 0 || + EntityList::HitListContains(player.contactHitList, *entity)) + continue; + Capsule body(entity->pos, entity->sizeMulti, entity->sprite.rotation, entity->size); + if (!Capsule::Collide(sweep, body)) continue; + if (dash_hit(player, dash, *entity, damage)) return; + hit_list_insert(player.contactHitList, *entity); + } +} + +// Recall pulls Tainted Forgotten toward his body, faster the longer it runs, trailing blue dust every other tick. +static void recall_pull(Entity_Player& player, const Dash& dash) +{ + Entity* body = player.twinPlayer.get(); + float speed = lerp_range((float)dash.frames, RECALL_PULL); + player.AddVelocity(vector_resized(vector_sub(body->pos, player.pos), speed), false); + if (!player.GetIntervalTicks(2, 0)) return; + + Entity* trail = g_game->Spawn({.position = player.pos, .velocity = vector_scale(player.velocity, 0.5f), + .spawner = &player, .type = ENTITY_EFFECT, .variant = EFFECT_HAEMO_TRAIL, + .seed = Random()}); + layer_additive_set(*trail->sprite.GetLayer(0)); + trail->posOffset = vector_add(player.posOffset, vector_make(0, RECALL_TRAIL_RISE)); + float glow = random_between(RECALL_TRAIL_TINT_MIN, RECALL_TRAIL_TINT_RANGE); + trail->SetColor({{0, 0, 0, 1}, {0, 0, 0, 0}, {glow * 0.4f, glow * 0.7f, glow}}, -1, COLOR_PRIORITY_DEFAULT, false, + true); + trail->renderDepthOffset = RECALL_TRAIL_DEPTH; + trail->Update(); +} + +// A dash meeting a wall: a glancing one slides along, a head-on one ends it with a shake and a bounce (Mars' with its +// impact, Suplex!'s run cut short). In the open it keeps its speed. Either way it leaves an after-image. +static void dash_motion_update(Entity_Player& player, const Dash& dash) +{ + if (!player.isCollidesWithGrid) + { + if (!vector_is_zero(player.velocity) && !player.isDead) + player.velocity = vector_scale(vector_normalized(player.velocity), dash.speed); + } + else if (vector_dot(vector_normalized(player.gridCollisionVelocity), player.gridCollisionNormal) < DASH_HEAD_ON) + { + Vector hit = player.gridCollisionVelocity; + Vector normal = player.gridCollisionNormal; + player.velocity = vector_sub(hit, vector_scale(normal, vector_dot(hit, normal) * 2)); + } + else + { + if (player.suplexState == SUPLEX_DASHING) + player.suplexAimCountdown = std::min(player.suplexAimCountdown, SUPLEX_WALL_FRAMES); + if (player.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_MARS)) + { + player.temporaryEffects.RemoveCollectibleEffect(COLLECTIBLE_MARS, -1); + player.marsDashDirection = -1; + player.dash_impact(); + } + player.ponyCharge = 0; + player.temporaryEffects.RemoveCollectibleEffect(COLLECTIBLE_PONY, -1); + player.temporaryEffects.RemoveCollectibleEffect(COLLECTIBLE_WHITE_PONY, -1); + game_shake_screen(DASH_WALL_SHAKE); + player.AddVelocity(vector_scale(player.gridCollisionNormal, DASH_WALL_BOUNCE), false); + } + player.afterImageFrames.push_back({.position = player.pos, .frames = AFTER_IMAGE_FRAMES}); +} + +// The dashes' part of the frame: a running dash flashes every 4 frames (White Pony's beams on the even ones), sweeps +// what it runs into, then Recall pulls or the others keep their speed off the walls. A dash leaves the player +// unhurtable without the blink (Mars' once its next one is ready) and not knocked back. A pony's charge runs down. +static void dash_update(Entity_Player& player) +{ + Dash dash; + if (!dash_get(player, dash)) + { + player.contactHitList.clear(); + player.ClearEntityFlags(FLAG_NO_KNOCKBACK); + } + else + { + if (!player.HasEntityFlags(FLAG_INTERPOLATION_UPDATE)) + { + int beat = dash.frames % DASH_FLASH_PERIOD; + bool isRecall = dash.kind == COLLECTIBLE_RECALL; + if (beat == 0) player.SetColor(isRecall ? RECALL_FLASH : DASH_FLASH, isRecall ? 3 : 2, COLOR_PRIORITY_DEFAULT, + isRecall, true); + if (!isRecall && dash.kind == COLLECTIBLE_PONY && dash.frames % 2 == 0 && + player.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_WHITE_PONY)) + white_pony_beam(player, beat != 0); + if (dash.speed > 0) dash_hits_update(player, dash); + } + if (dash.kind == COLLECTIBLE_RECALL) + { + if (player.playerType == PLAYER_THEFORGOTTEN_B && player.twinPlayer) recall_pull(player, dash); + } + else dash_motion_update(player, dash); + player.SetMinDamageCooldown(DARK_ARTS_DAMAGE_COOLDOWN); + if (dash.kind != COLLECTIBLE_MARS || !player.isMarsDashReady) player.AddEntityFlags(FLAG_NO_DAMAGE_BLINK); + player.AddEntityFlags(FLAG_NO_KNOCKBACK); + } + if (player.ponyCharge > 0) player.ponyCharge--; +} + +// The dashes' block of the items' frame (update_effects 00794e50), in its order there: Salvation's halo, Dark Arts, +// the smokes off the head, Soul of ???'s farts, Mega Mush's blinks and the dashes. +void dashes_frame_update(Entity_Player& player) +{ + salvation_update(player); + dark_arts_update(player); + head_smokes_update(player); + soul_bluebaby_update(player); + mega_mush_blink_update(player); + dash_update(player); +} diff --git a/src/entity_player_death.cpp b/src/entity_player_death.cpp index 2a290ce..cc5c7bf 100644 --- a/src/entity_player_death.cpp +++ b/src/entity_player_death.cpp @@ -31,7 +31,6 @@ #include #include -constexpr int SPECIAL_DAILY_SHUFFLED_ITEMS = 7; constexpr float DEATH_FRICTION = 0.6f; constexpr int DEATH_FRAME_TWIN_FALLS = 7; @@ -960,7 +959,7 @@ void Entity_Player::death_update() // Metronome's item, Bat Wing's wings and Wavy Cap's trip wear off, the temporary effects clear, the costumes of actives // no longer worn come off, a held item is put away, the room's trail is kept for the Void's hallucinations when it is // the longest walked, and a soul player of the Forgotten or Jacob leaves. -// The after-images and the deathmatch's damage are not modeled. +// The after-images are not modeled. void Entity_Player::room_exit(bool isKeepHolyMantle) { ItemConfig& items = g_manager->itemConfig; @@ -971,6 +970,7 @@ void Entity_Player::room_exit(bool isKeepHolyMantle) isBrokenRemotePending = false; cursedPennyPending = 0; roomDamageTaken = 0; + versus.damageDealt = 0; if (temporaryEffects.HasCollectibleEffect(COLLECTIBLE_COMPASS) && !HasCollectible(COLLECTIBLE_COMPASS)) game.RemoveCompassEffect(); @@ -1030,7 +1030,8 @@ void Entity_Player::room_exit(bool isKeepHolyMantle) } // 0075e1d0 Adds the item held over the head, golden or not, as picked up for the first time unless it was touched -// before, then lets Astral Projection trigger. False when nothing was queued. +// before, then lets Astral Projection trigger. False when nothing was queued. April Fools' daily swaps it for a +// collectible drawn from the room's pool by its id, or the trinket pool's next trinket. bool Entity_Player::FlushQueueItem() { if (!queuedItem.item) @@ -1045,19 +1046,19 @@ bool Entity_Player::FlushQueueItem() queuedItem.charge = 0; queuedItem.varData = 0; bool isFirstTime = !(queued.flags & QUEUED_TOUCHED); - bool isShuffledDaily = g_game->dailyChallenge.specialDailyId == SPECIAL_DAILY_SHUFFLED_ITEMS; + bool isAprilFools = g_game->dailyChallenge.specialDailyId == SPECIAL_DAILY_APRIL_FOOLS; if (queued.item->type == ITEM_TRINKET) { - if (isShuffledDaily) - reconstruction_missing("Entity_Player::FlushQueueItem 0075e1d0 (a shuffled daily's trinket)"); - uint32_t id = (uint32_t)queued.item->id; + uint32_t id = isAprilFools ? g_game->itemPool.GetTrinket(TRINKET_DRAW_TAKE) : (uint32_t)queued.item->id; AddTrinket((int)(queued.flags & QUEUED_GOLDEN ? id | TRINKET_GOLDEN_FLAG : id), isFirstTime); } else if (queued.item->type != ITEM_NULL) { - if (isShuffledDaily) reconstruction_missing("Entity_Player::FlushQueueItem 0075e1d0 (a shuffled daily's item)"); - AddCollectible(queued.item->id, queued.charge, isFirstTime, 0, queued.varData, queued.itemPoolType); + int id = queued.item->id; + RNG rng = {(uint32_t)id, 1, 5, 16}; + if (isAprilFools) id = g_game->itemPool.GetSeededCollectible(rng.Next(), 0, *g_game->room->descriptor); + AddCollectible(id, queued.charge, isFirstTime, 0, queued.varData, queued.itemPoolType); } try_trigger_astral_projection(); return true; diff --git a/src/entity_player_effects.cpp b/src/entity_player_effects.cpp index e5799d7..49a447b 100644 --- a/src/entity_player_effects.cpp +++ b/src/entity_player_effects.cpp @@ -22,6 +22,9 @@ #include "room_grid.h" #include "temporary_effects.h" #include "sfx_manager.h" +#include "hud.h" +#include "loot_list.h" +#include "persistent_game_data.h" #include #include @@ -144,7 +147,6 @@ constexpr float MONSTRANCE_PERIOD = 4; constexpr LerpRange MONSTRANCE_FALLOFF = {.inMin = 30, .inMax = 90, .outMin = 0, .outMax = 0.4f}; constexpr float MONSTRANCE_STAGE_DAMAGE = 0.32f; constexpr float MONSTRANCE_BASE_DAMAGE = 3.6f; -constexpr int MONSTRANCE_HIT_COUNTDOWN = 30; constexpr int HALO_DADS_RING = 0; constexpr int HALO_MONSTRANCE = 2; constexpr int MARS_READY_PONY_STEP = 2; @@ -192,6 +194,51 @@ constexpr float WARNING_OFFSET_STEP = 0.06f; constexpr uint32_t FRAME_STAT_CACHE = CACHE_DAMAGE | CACHE_FIREDELAY | CACHE_TEARFLAG | CACHE_TEARCOLOR; constexpr int GROUND_CONTACT_MAX = 4; +// The mirror world's death once its mirror broke: the ghost fades as its count runs to 6, then dies with it. +constexpr int MIRROR_DEATH_COUNT = 6; +constexpr uint64_t MIRROR_DEATH_FLAGS = DAMAGE_INVINCIBLE | DAMAGE_NO_PENALTIES; +constexpr float FADE_FULL = 0.99f; +constexpr float FADE_RED_MIN = 0.5f; +constexpr float FADE_GREEN_MIN = 0.6f; +constexpr ColorMod BREATH_GLOW = {{1, 1, 1, 1}, {0, 0, 0, 0}, {0.25f, 0.35f, 0.5f}}; + +// Reverse Magician's repelling aura: how far it reaches, how hard it pushes, how much it bends shots aside. +constexpr float REPEL_RADIUS = 120; +constexpr float REPEL_MIN_SQUARED = 0.01f; +constexpr float REPEL_PUSH = 60; +constexpr float REPEL_ENEMY_BOOST = 0.25f; +constexpr uint32_t REPEL_SHIFT = 71; +constexpr float REPEL_JITTER = 0.01f; +constexpr float REPEL_JITTER_RANGE = 0.02f; +constexpr float REPEL_SIDE = 0.5f; +constexpr float REPEL_SHOT_SPEED_MIN = 5; +constexpr float REPEL_SHOT_SLOW = 0.4f; + +// Bethany's tainted Birthright: an item from a weighted pool joins her as a wisp four times as hardy. +constexpr int BETHANY_WISP_SHIFT = 35; +constexpr int BETHANY_WISP_QUALITY_MIN = 3; +constexpr float BETHANY_WISP_HEALTH_SCALE = 4; +struct PoolChance +{ + int pool = 0; + int weight = 0; +}; +constexpr PoolChance BETHANY_POOLS[] = {{POOL_TREASURE, 100}, {POOL_SHOP, 30}, {POOL_BOSS, 30}, {POOL_DEVIL, 10}, + {POOL_ANGEL, 10}, {POOL_SECRET, 2}, {POOL_PLANETARIUM, 2}, {POOL_CURSE, 2}}; +constexpr PoolChance BETHANY_GREED_POOLS[] = {{POOL_GREED_TREASURE, 100}, {POOL_GREED_SHOP, 50}, {POOL_GREED_BOSS, 30}, + {POOL_GREED_DEVIL, 10}, {POOL_GREED_ANGEL, 10}, + {POOL_PLANETARIUM, 2}}; + +// Extension Cord's beams between the player and its familiars: how often by how many there are, how far apart two +// must be, the damage per copy and the beam's look. +constexpr float CORD_MIN_SQUARED = 400; +constexpr float CORD_DAMAGE = 6; +constexpr int CORD_LASER_VARIANT = 2; +constexpr int CORD_LASER_TIMEOUT = 3; +constexpr int CORD_LASER_SUBTYPE = 4; +constexpr float CORD_LASER_RISE = -20; +constexpr ColorMod CORD_COLOR = {{1, 1, 1, 0.5f}, {0, 0, 0, 0}, {1, 1, 0}}; + // The flashes the frame lays on the player: Tooth and Nail's statue turning, and Mars' dash being ready. constexpr ColorMod GREY_FLASH = {{0.5f, 0.5f, 0.5f, 1}, {0, 0, 0, 0}, {0.8f, 0.8f, 0.8f}}; constexpr ColorMod MARS_READY_COLOR = {{0.5f, 0.5f, 0.5f, 1}, {0, 0, 0, 0}, {1, 0.2f, 0.2f}}; @@ -447,14 +494,13 @@ static void faded_polaroid_update(Entity_Player& player) constexpr int POLAROID_ODDS = 5; constexpr int POLAROID_SECONDS_MIN = 3; constexpr int POLAROID_SECONDS_RANGE = 5; - constexpr int POLAROID_FRAMES_PER_SECOND = 30; TemporaryEffects& effects = player.temporaryEffects; if (effects.HasTrinketEffect(TRINKET_FADED_POLAROID) || !player.HasTrinket(TRINKET_FADED_POLAROID)) return; if (!player.IsFrame(POLAROID_PERIOD, 0) || random_below(POLAROID_ODDS) != 0) return; TemporaryEffect fade(g_manager->itemConfig.GetTrinket(TRINKET_FADED_POLAROID)); int multiplier = player.GetTrinketMultiplier(TRINKET_FADED_POLAROID); - fade.cooldown = multiplier * (random_below(POLAROID_SECONDS_RANGE) + POLAROID_SECONDS_MIN) * POLAROID_FRAMES_PER_SECOND; + fade.cooldown = multiplier * (random_below(POLAROID_SECONDS_RANGE) + POLAROID_SECONDS_MIN) * FRAMES_PER_SECOND; effects.AddEffect(fade, true, 1); } @@ -678,7 +724,7 @@ static void monstrance_update(Entity_Player& player) { if (!enemy->IsVulnerableEnemy(nullptr) || enemy == &player) continue; float edge = vector_distance(player.pos, enemy->pos) - enemy->size; - enemy->TakeDamage(lerp_range(edge, falloff), 0, EntityRef(&player), MONSTRANCE_HIT_COUNTDOWN); + enemy->TakeDamage(lerp_range(edge, falloff), 0, EntityRef(&player), HIT_COUNTDOWN); } } aura_keep(player, player.monstranceAura, isWorn, HALO_MONSTRANCE); @@ -783,24 +829,23 @@ static void reverse_empress_blink_update(Entity_Player& player) else if (phase >= 4 && !isShown) player.AddCostume(costume, false); } -// Reverse Sun keeps the room dark for a second at a time while it lasts (in versus only for the local main player). +// Reverse Sun keeps the room dark for a second at a time while it lasts. In a versus match only the local user's player +// darkens it, whom netplay names: offline there is no local user, so it never does. static void reverse_sun_update(Entity_Player& player) { constexpr int REVERSE_SUN_DARKNESS_FRAMES = 60; - if (!player.temporaryEffects.HasNullEffect(NULLITEM_REVERSE_SUN)) return; - if (g_game->deathmatchManager.is_active()) - reconstruction_missing("Entity_Player::update_effects 00794e50 (Reverse Sun in versus)"); + if (!player.temporaryEffects.HasNullEffect(NULLITEM_REVERSE_SUN) || g_game->deathmatchManager.is_active()) return; g_game->darknessStrength = 1; g_game->darknessTimeout = REVERSE_SUN_DARKNESS_FRAMES; } -// IBS charges with the damage enemies took this frame, up to full. A spent charge (negative) drains back to zero +// IBS charges with the damage dealt this frame, up to full. A spent charge (negative) drains back to zero // over a second. static void ibs_charge_update(Entity_Player& player) { if (player.HasCollectible(COLLECTIBLE_IBS)) { - float dealt = g_game->room->entityList.enemyDamageInflicted; + float dealt = damage_dealt_get(player); if (dealt > 0 && player.ibsCharge >= 0) player.ibsCharge = std::min(player.ibsCharge + damage_charge_scale() * dealt * IBS_CHARGE_PER_DAMAGE, 1.0f); } @@ -1047,6 +1092,241 @@ static void size_update(Entity_Player& player) player.shadowSize = shadow * player.config->shadowSize; } +// A fading look laid over the player's color for a frame: redder and greener toward white as the fraction fills, +// maybe glowing blue. +static void fade_tint_set(Entity_Player& player, float fraction, float glow) +{ + const float* offset = BREATH_GLOW._offset; + ColorMod tint = {{FADE_RED_MIN + (1 - FADE_RED_MIN) * fraction, FADE_GREEN_MIN + (1 - FADE_GREEN_MIN) * fraction, 1, 1}, + {0, 0, 0, 0}, + {offset[0] * glow, offset[1] * glow, offset[2] * glow}}; + color_multiply(tint, player.color); + player.SetColor(tint, 1, COLOR_PRIORITY_DEFAULT, false, true); +} + +// The mirror world past its broken mirror: the player's ghost counts its seconds there, fading out over six, and dies +// at the sixth. +static void mirror_death_update(Entity_Player& player) +{ + Game& game = *g_game; + if (game.currentDimensionIdx == 0 || !game.HasMirrorDimension() || + !game.Level::GetStateFlag(LEVEL_STATE_MIRROR_BROKEN)) + return; + + TemporaryEffects& effects = player.temporaryEffects; + TemporaryEffect* death = effects.GetNullEffect(NULLITEM_MIRROR_DEATH); + if (death && death->cooldown == 1 && death->count >= MIRROR_DEATH_COUNT) + player.TakeDamage(1, MIRROR_DEATH_FLAGS, EntityRef(), 0); + if (!death || death->cooldown == 1) effects.AddNullEffect(NULLITEM_MIRROR_DEATH, true, 1); + death = death ? effects.GetNullEffect(NULLITEM_MIRROR_DEATH) : nullptr; + + float fraction = std::clamp(1 - (float)(death ? death->count : 0) / MIRROR_DEATH_COUNT, 0.0f, 1.0f); + if (fraction < FADE_FULL) fade_tint_set(player, fraction, 0); +} + +// Breath of Life held while not fully charged fades the player with its charge, and pulses blue while its spell runs +// on an empty charge. +static void breath_of_life_fade_update(Entity_Player& player) +{ + int slot = player.GetActiveItemSlot(COLLECTIBLE_BREATH_OF_LIFE); + if (slot < 0) return; + int charge = player.activeItems[slot].charge; + float fraction = (float)charge / (float)player.GetActiveMaxCharge(slot); + if (fraction >= FADE_FULL) return; + + if (charge != 0 || !player.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_BREATH_OF_LIFE)) + return fade_tint_set(player, fraction, 0); + float pulse = std::sin((float)player.FrameCount() * PI_F * 0.5f) * 0.5f + 0.5f; + fade_tint_set(player, pulse, pulse); +} + +// Reverse Magician pushes an enemy shot away from the player, harder the closer it is, and bends one coming straight +// at it aside (a little at random) so it passes at least half its width off. The shot keeps at least 5 speed. +static void repel_shot(Entity_Player& player, Entity& shot) +{ + RNG rng; + rng.game_constructor(shot.initSeed, REPEL_SHIFT); + Vector push = vector_sub(shot.pos, player.pos); + float lengthSquared = vector_length_squared(push); + if (lengthSquared < REPEL_MIN_SQUARED) return; + + push = vector_scale(push, REPEL_PUSH / lengthSquared); + float speed = vector_length(shot.velocity); + if (speed > 0 && vector_dot(push, shot.velocity) < 0) + { + Vector side = vector_scale(vector_rotated(vector_scale(shot.velocity, 1 / speed), RIGHT_ANGLE_DEGREES), -1); + float across = vector_dot(vector_normalized(push), side) - REPEL_JITTER + rng.RandomFloat() * REPEL_JITTER_RANGE; + if (std::fabs(across) < REPEL_SIDE) + { + float edge = across > 0 ? std::asin(REPEL_SIDE) : -std::asin(REPEL_SIDE); + push = vector_rotated(push, (edge - std::asin(across)) * 180 / PI_F); + } + } + Vector bent = vector_add(shot.velocity, vector_scale(push, shot.speedMultiplier)); + if (speed > REPEL_SHOT_SLOW) bent = vector_resized(bent, std::max(REPEL_SHOT_SPEED_MIN, speed)); + shot.velocity = bent; +} + +// Reverse Magician pushes an enemy away from where the player is heading, harder the closer, more when it walks in. +static void repel_enemy(Entity_Player& player, Entity& enemy) +{ + Vector push = vector_sub(vector_sub(enemy.pos, player.pos), player.velocity); + float lengthSquared = vector_length_squared(push); + if (lengthSquared < REPEL_MIN_SQUARED) return; + + push = vector_scale(push, REPEL_PUSH / lengthSquared); + float toward = vector_dot(enemy.velocity, vector_scale(vector_normalized(push), -1)); + if (toward > 0) push = vector_scale(push, toward * REPEL_ENEMY_BOOST + 1); + enemy.AddVelocity(push, false); +} + +// Reverse Magician: the enemy shots and enemies within 120 that have been around for 3 frames are pushed away. +static void reverse_magician_update(Entity_Player& player) +{ + if (!player.temporaryEffects.HasNullEffect(NULLITEM_REVERSE_MAGICIAN)) return; + + for (Entity* entity : entity_query_radius(player.pos, REPEL_RADIUS, QUERY_PROJECTILES | QUERY_ENEMIES)) + { + if (entity->FrameCount() <= 2) continue; + if (entity->IsProjectile() && + !(static_cast(entity)->projectileFlags & PROJECTILE_CANT_HIT_PLAYER)) + repel_shot(player, *entity); + else if (entity->IsActiveEnemy(DEAD_EXCLUDED) && !entity->IsFriendly()) + repel_enemy(player, *entity); + } +} + +// Reverse Temperance's next pill: once the player may pick something up and none is pending, a random pill is shown +// to be swallowed. +static void reverse_temperance_update(Entity_Player& player) +{ + TemporaryEffects& effects = player.temporaryEffects; + if (!effects.HasNullEffect(NULLITEM_REVERSE_TEMPERANCE) || player.pendingPill >= 0 || !player.CanPickupItem()) return; + + player.FlushQueueItem(); + effects.RemoveNullEffect(NULLITEM_REVERSE_TEMPERANCE, 1); + player.pendingPill = ItemPool::GetPill(player.GetCardRNG(CARD_REVERSE_TEMPERANCE).Next()); + player.AnimatePill(player.pendingPill, "UseItem"); + npc_sound_play(SOUND_SHELLGAME, 1, 2, 1); +} + +// 00753d60 The items Tainted Bethany's Birthright may give as wisps: summonable items of quality 3 or more. +static bool is_birthright_wisp(ItemConfig_Item& item) +{ + return !item.IsCollectible() || (item.HasTags(TAG_SUMMONABLE) && item.quality >= BETHANY_WISP_QUALITY_MIN); +} + +// Tainted Bethany's Birthright: each charge she holds, once she is free to pick something up, becomes a wisp of a good +// item from a weighted pool (Greed's pools in Greed mode), four times as hardy, with its name shown. +static void bethany_birthright_update(Entity_Player& player) +{ + TemporaryEffects& effects = player.temporaryEffects; + if (!effects.HasNullEffect(NULLITEM_BETHANY_B_BIRTHRIGHT) || !player.CanPickupItem() || player.IsHoldingItem()) return; + + Game& game = *g_game; + player.FlushQueueItem(); + effects.RemoveNullEffect(NULLITEM_BETHANY_B_BIRTHRIGHT, 1); + RNG& rng = player.GetCollectibleRNG(COLLECTIBLE_LEMEGETON); + WeightedOutcomePicker picker; + for (PoolChance chance : game.IsGreedMode() ? std::span(BETHANY_GREED_POOLS) + : std::span(BETHANY_POOLS)) + picker.AddOutcomeWeight(chance.pool, chance.weight); + int pool = picker.PickOutcome(rng_make(rng.Next(), BETHANY_WISP_SHIFT)); + + std::vector& filters = g_manager->itemConfig.availabilityFilters; + filters.push_back(is_birthright_wisp); + int item = game.itemPool.GetCollectible((ItemPoolType)pool, rng.Next(), 0, COLLECTIBLE_BROTHER_BOBBY, 0); + filters.pop_back(); + Entity_Familiar* wisp = player.AddItemWisp(item, player.pos, true); + wisp->health *= BETHANY_WISP_HEALTH_SCALE; + if (ItemConfig_Item* config = g_manager->itemConfig.GetCollectible(item)) game.hud.ShowItemText(&player, config); + player.AnimateCollectible(item, "UseItem", "PlayerPickupSparkle"); + sound_play(SOUND_DEVILROOM_DEAL); +} + +// The pill Reverse Temperance showed is swallowed once nothing transitions, the controls are free and the pill's +// animation is over: the player's familiars react, it counts for the save, and its effect runs unannounced. +static void pending_pill_update(Entity_Player& player) +{ + if (player.pendingPill < 0 || g_game->roomTransition.is_active() || !player.AreControlsEnabled() || + player.bodySprite.IsPlaying("UseItem")) + return; + + for (Entity* entity : entity_query(ENTITY_FAMILIAR, -1)) + if (static_cast(entity)->player == &player) + static_cast(entity)->farting_baby_fart(); + PersistentGameData& save = g_manager->persistentGameData; + save.IncreaseEventCounter(EVENT_COUNTER_PILLS_USED, 1); + save.AddToCollection(COLLECTION_PILL); + int color = player.pendingPill; + player.UsePill(g_game->itemPool.GetPillEffect((uint32_t)color, &player), color, USE_NOANNOUNCER); + if (player.cacheFlags != 0) + { + player.InvalidateCoPlayerItems(); + player.EvaluateItems(); + } + player.pendingPill = -1; +} + +// The links Extension Cord ties: the other living, visible players (none in a versus match), then the visible +// familiars the room never overwrites (in a versus match only the player's own). +static std::vector extension_cord_links(Entity_Player& player) +{ + Game& game = *g_game; + bool isVersus = game.deathmatchManager.is_active(); + std::vector links; + for (int index = 0; !isVersus && index < (int)game.playerManager.playerList.size(); index++) + { + Entity_Player* other = game.GetPlayer(index); + if (other != &player && !other->isDead && other->isVisible) links.push_back(other); + } + for (Entity* entity : entity_query(ENTITY_FAMILIAR, -1)) + { + auto* familiar = static_cast(entity); + if (familiar->overwrite_limit() < 0 && familiar->isVisible && (!isVersus || familiar->IsDescendantOf(&player))) + links.push_back(familiar); + } + return links; +} + +// Extension Cord: a beam runs from one link to the next (the first to the player), one link at a time going back +// down the chain, every 60 frames for one link, 10 for two, 4 up to eight and 2 beyond. Links less than 20 apart get +// none. The beams hurt 6 per copy. +static void extension_cord_update(Entity_Player& player) +{ + if (!player.HasTrinket(TRINKET_EXTENSION_CORD)) return; + + std::vector links = extension_cord_links(player); + int count = (int)links.size(); + if (count == 0) return; + int period = count == 1 ? 60 : count == 2 ? 10 : count <= 8 ? 4 : 2; + if (g_game->frameCount % period != 0) return; + + int& index = player.extensionCordIndex; + if (index == -1 || index >= count) index = count - 1; + if (index < 0) return; + Vector from = links[index]->pos; + Vector to = index > 0 ? links[index - 1]->pos : player.pos; + if (vector_length_squared(vector_sub(from, to)) > CORD_MIN_SQUARED) + { + float damage = (float)player.GetTrinketMultiplier(TRINKET_EXTENSION_CORD) * CORD_DAMAGE; + Entity_Laser* laser = Entity_Laser::ShootAngle({.position = from, + .posOffset = vector_make(0, CORD_LASER_RISE), + .source = links[index], + .angleDegrees = vector_angle(vector_sub(to, from)), + .timeout = CORD_LASER_TIMEOUT, + .variant = CORD_LASER_VARIANT}); + laser->subtype = CORD_LASER_SUBTYPE; + laser->maxDistance = vector_distance(from, to); + laser->SetCollisionDamage(damage); + laser->mass = 0; + laser->SetColor(CORD_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); + laser->isDisableInitSound = true; + laser->Update(); + } + if (--index < 0) index = count - 1; +} + // The written pieces of the items' frame (update_effects 00794e50) the plain path runs after its others, in their // order there. void items_frame_update(Entity_Player& player) @@ -1059,6 +1339,8 @@ void items_frame_update(Entity_Player& player) crack_the_sky_update(player); relax_poop_update(player); breath_of_life_update(player); + mirror_death_update(player); + breath_of_life_fade_update(player); faded_polaroid_update(player); empty_vessel_update(player); redemption_update(player); @@ -1069,14 +1351,19 @@ void items_frame_update(Entity_Player& player) berserk_tick_update(player); if (effects.HasCollectibleEffect(COLLECTIBLE_URN_OF_SOULS) && !player.HasCollectible(COLLECTIBLE_URN_OF_SOULS)) effects.RemoveCollectibleEffect(COLLECTIBLE_URN_OF_SOULS, -1); + reverse_magician_update(player); spooky_venus_update(player); volt_120_update(player); monstrance_update(player); + dashes_frame_update(player); mars_recharge_update(player); divine_intervention_recharge(player); tooth_and_nail_update(player); reverse_empress_blink_update(player); reverse_sun_update(player); + reverse_temperance_update(player); + bethany_birthright_update(player); + pending_pill_update(player); if (effects.HasNullEffect(NULLITEM_REVERSE_STARS) && player.IsExtraAnimationFinished()) effects.RemoveNullEffect(NULLITEM_REVERSE_STARS, 1); ibs_charge_update(player); @@ -1085,6 +1372,7 @@ void items_frame_update(Entity_Player& player) sumptorium_recall_update(player); purgatory_update(player); isaacs_heart_update(player); + extension_cord_update(player); montezuma_aim_update(player); plan_c_update(player); linger_bean_update(player); diff --git a/src/entity_player_effects.h b/src/entity_player_effects.h index 46a82a1..0e9fe28 100644 --- a/src/entity_player_effects.h +++ b/src/entity_player_effects.h @@ -3,3 +3,5 @@ struct Entity_Player; void items_frame_update(Entity_Player& player); +void dashes_frame_update(Entity_Player& player); +float salvation_halo_scale_get(Entity_Player& player); diff --git a/src/entity_player_evaluate.cpp b/src/entity_player_evaluate.cpp index c4b8536..1f23b81 100644 --- a/src/entity_player_evaluate.cpp +++ b/src/entity_player_evaluate.cpp @@ -50,26 +50,16 @@ constexpr int PILL_SHOT_SPEED_DOWN = 47; constexpr int PILL_SHOT_SPEED_UP = 48; constexpr int TRINKET_CRACKED_CROWN = 92; constexpr int FAMILIAR_ITEM_WISP = 206; -constexpr int COOP_BUFF_DAMAGE = 0; -constexpr int COOP_BUFF_TEARS = 1; -constexpr int COOP_BUFF_SPEED = 2; -constexpr int COOP_BUFF_RANGE = 3; -constexpr int COOP_BUFF_LUCK = 4; - // The constants of the other sections: the collectibles, trinkets, null items and characters they ask about. constexpr int PILL_LARGER = 32; constexpr int PILL_SMALLER = 33; -constexpr int COOP_BUFF_SMALLER = 5; -constexpr int COOP_BUFF_LARGER = 6; -constexpr int NULLITEM_SPIRIT_SHACKLES_SOUL = 101; constexpr int SPRITE_SCALE_UNLOCK = 3; constexpr int ACHIEVEMENT_HUGE = 361; constexpr float SIZE_STEP = 0.322f; constexpr float SIZE_SCALE_KNEE = 2; constexpr float SIZE_SCALE_SLOPE = 2.77259f; constexpr float SIZE_SCALE_AT_KNEE = 4; -constexpr int DAILY_BIG_SIZE = 45; constexpr float DAILY_BIG_SIZE_BONUS = 0.485f; constexpr float BIG_HEAD_BONUS = 1.585f; constexpr int BLOOD_LUST_COLOR_CAP = 6; @@ -95,8 +85,6 @@ constexpr float GHOST_DAMAGE_SCALE = 0.25f; constexpr float JUPITER_SLOW = -0.3f; constexpr float JUPITER_FAST = 0.2f; constexpr float DOGMA_MIN_SPEED = 1.1f; -constexpr int DAILY_LUCKY = 23; -constexpr int DAILY_SLOW = 43; constexpr float DAILY_LUCK_BONUS = 50; // Whether the player has a collectible, or its temporary effect. @@ -111,18 +99,6 @@ static float pill_uses(Entity_Player& player, int pillEffect) return pillEffect < (int)player.pillEffectUses.size() ? (float)player.pillEffectUses[pillEffect] : 0; } -// The trinket and late collectible effects the evaluation and the frame know: Red Patch, Samson's Lock, Eve's Bird -// Foot, Equality, Bat Wing, Purity and the crowns. -static bool is_trinket_effect_plain(const TemporaryEffect& effect) -{ - constexpr int PLAIN_TRINKET_EFFECTS[] = {TRINKET_RED_PATCH, TRINKET_SAMSONS_LOCK, TRINKET_EVES_BIRD_FOOT, - TRINKET_EQUALITY, TRINKET_BAT_WING}; - constexpr int PLAIN_LATE_EFFECTS[] = {COLLECTIBLE_PURITY, COLLECTIBLE_CROWN_OF_LIGHT, COLLECTIBLE_DARK_PRINCES_CROWN}; - std::span plain = effect.item->type == ITEM_TRINKET ? std::span(PLAIN_TRINKET_EFFECTS) - : std::span(PLAIN_LATE_EFFECTS); - return effect.item->type != ITEM_NULL && std::ranges::find(plain, effect.item->id) != plain.end(); -} - // Whether Purity's aura is on in a colour (0 damage, 1 tears, 2 speed, 3 range). static bool is_purity(Entity_Player& p, int state) { @@ -148,24 +124,6 @@ static void bulbs_apply(Entity_Player& p, float& stat, float dimScale, float vib if (p.HasTrinket(TRINKET_VIBRANT_BULB) && isFull) stat = trinket_num(p, TRINKET_VIBRANT_BULB) * vibrantScale + stat; } -// The temporary effects the items' frame (update_effects 00794e50) and the shooting part (0077b020) ask about by id -// but do not run yet: collectible effects and null effects. An effect the frame never asks about only counts down -// there. The frame's own part (00782af0) runs or stops on its own. -constexpr int FRAME_COLLECTIBLE_EFFECTS[] = {130, 181, 593, 705, 714}; -constexpr int FRAME_NULL_EFFECTS[] = {60, 69, 111, 114, 116, 122, 128}; - -// Whether the frame runs a temporary effect: the effects written for it, and those it never asks about. -static bool is_frame_effect_known(const TemporaryEffect& effect) -{ - if (is_temporary_effect_plain(effect) || is_passive_effect_plain(effect) || is_trinket_effect_plain(effect) || - effect.item->type == ITEM_TRINKET) - return true; - - std::span unwritten = effect.item->type == ITEM_NULL ? std::span(FRAME_NULL_EFFECTS) - : std::span(FRAME_COLLECTIBLE_EFFECTS); - return std::ranges::find(unwritten, effect.item->id) == unwritten.end(); -} - // What every section of the evaluation starts from: the bonuses Experimental Treatment, Binge Eater's foods, Candy // Heart and Soul Locket give (damage, tears, range, shot speed, speed and luck), Cracked Crown's scale, and whether // the curse mist or a co-op ghost drops the pills and stat modifiers. @@ -247,15 +205,6 @@ static StatBonuses stat_bonuses_get(Entity_Player& player) return bonus; } -// A stat glitched items add (GlitchedItemSet::recalculate 009e0500's sums, 00753870 to 007538c0), which TMTRAINER's -// items would give. The procedural items are not reconstructed, so a player holding one stops here. -static float glitched_stat_get(Entity_Player& p) -{ - if (!p.proceduralItems.empty() && p.proceduralItems.begin()->first < 0) - reconstruction_missing("GlitchedItemSet::recalculate 009e0500 (the glitched items' stats)"); - return 0; -} - // The Decap Attack effect's boost with Judas's Birthright book: a main weapon other than a knife, Ludovico or the // whip, whose shots Ludovico does not hold. static bool is_decap_boosted(Entity_Player& p) @@ -353,7 +302,7 @@ static void fire_delay_evaluate(Entity_Player& p, const StatBonuses& bonus) if (int hurts = effects.GetNullEffectNum(NULLITEM_IT_HURTS); hurts > 0) rate = (float)hurts * 0.4f + 0.8f + rate; if (int candle = effects.GetCollectibleEffectNum(COLLECTIBLE_PASCHAL_CANDLE); candle > 0) rate = (float)candle * 0.4f + rate; if (int luna = effects.GetNullEffectNum(NULLITEM_LUNA); luna > 0) rate = (float)luna * 0.5f + 0.5f + rate; - rate = glitched_stat_get(p) + rate; + rate = glitched_stat_get(p, GLITCHED_TEARS) + rate; if (p.grantedCollectibleCountdown > 0) rate = rate + 1.5f; if (TemporaryEffect* camo = effects.GetNullEffect(NULLITEM_CAMO_BOOST)) rate = rate + (float)camo->count * 0.25f; @@ -410,6 +359,7 @@ static void fire_delay_evaluate(Entity_Player& p, const StatBonuses& bonus) p.maxFireDelay = std::max(challenge->minFireRate, p.maxFireDelay); static_cast(g_luaEngine)->EvaluateItems(&p, CACHE_FIREDELAY); p.maxFireDelay = std::max(p.maxFireDelay, MAX_FIRE_DELAY_MIN); + if (g_game->deathmatchManager.is_active()) g_game->deathmatchManager.type->fire_delay_evaluate(p, p.maxFireDelay); } // The Judas's Birthright nulls' part of the damage: the plain stacks, the timed boost's frames, the stage stacks and @@ -540,7 +490,9 @@ static void damage_evaluate(Entity_Player& p, const StatBonuses& bonus) } if (is_purity(p, PURITY_DAMAGE)) damage = damage + 4; - damage = std::sqrt(std::max(damage * DAMAGE_CURVE_SCALE + 1, 0.0f)) * DAMAGE_BASE; + DeathmatchManager& versus = g_game->deathmatchManager; + float base = versus.is_active() ? versus.type->base_damage_scale() * DAMAGE_BASE : DAMAGE_BASE; + damage = std::sqrt(std::max(damage * DAMAGE_CURVE_SCALE + 1, 0.0f)) * base; if (has(169)) damage = !has(2) && !has(153) && !effects.HasCollectibleEffect(2) && !p.HasWeaponType(WEAPON_FETUS) && !has(245) ? damage + 4 + damage + 4 @@ -555,7 +507,7 @@ static void damage_evaluate(Entity_Player& p, const StatBonuses& bonus) damage = (float)(p.potatoPeelerBandageCounter + p.potatoPeelerCounter) * 0.2f + damage; damage = std::max((float)modifier_get(bonus, p.damageModifier) + bonus.damage + damage, DAMAGE_MIN); if (effects.HasCollectibleEffect(COLLECTIBLE_BERSERK)) damage = damage + 3; - damage = glitched_stat_get(p) + damage; + damage = glitched_stat_get(p, GLITCHED_DAMAGE) + damage; float horns = trinket_num(p, TRINKET_CURVED_HORN); damage = horns + horns + damage; if (has(513)) damage = damage + 0.1f; @@ -660,6 +612,7 @@ static void damage_evaluate(Entity_Player& p, const StatBonuses& bonus) } p.damage = std::max(p.damage, DAMAGE_MIN); p.meleeDamage = std::max(p.meleeDamage, DAMAGE_MIN); + if (versus.is_active()) versus.type->damage_evaluate(p, p.damage); } // The shot speed section of 00763570: shot speed ups and downs on 1. @@ -687,7 +640,7 @@ static void shot_speed_evaluate(Entity_Player& p, const StatBonuses& bonus) speed = ((float)modifier_get(bonus, p.shotSpeedModifier) + bonus.shotSpeed) * 0.2f + (float)n(329) * 0.2f + speed; bulbs_apply(p, speed, 0.3f, 0.1f); speed = speed + character_shot_speed_get(p); - speed = glitched_stat_get(p) * 0.2f + speed; + speed = glitched_stat_get(p, GLITCHED_SHOT_SPEED) * 0.2f + speed; if (p.coopBabyBuffTimers[COOP_BUFF_RANGE] > 0) speed = speed + 0.5f; if (effects.HasCollectibleEffect(COLLECTIBLE_DARK_PRINCES_CROWN)) speed = speed + 0.2f; if (effects.HasNullEffect(NULLITEM_ERA_WALK)) speed = speed - 1; @@ -749,7 +702,7 @@ static void range_evaluate(Entity_Player& p, const StatBonuses& bonus) if (has(594)) p.tearHeight = p.tearHeight - 8; if (has(598) || effects.HasCollectibleEffect(COLLECTIBLE_INNER_CHILD)) p.tearHeight = p.tearHeight * 0.4f; if (has(716)) p.tearRange = (float)((p.keepersSackBonus / 3 + 1) / 3) * 10 + p.tearRange; - p.tearRange = glitched_stat_get(p) * 60 + p.tearRange; + p.tearRange = glitched_stat_get(p, GLITCHED_RANGE) * 60 + p.tearRange; if (effects.HasCollectibleEffect(COLLECTIBLE_MEGA_MUSH)) { p.tearFallingAcceleration = 0.8f; @@ -860,7 +813,7 @@ static void speed_evaluate(Entity_Player& p, const StatBonuses& bonus) p.moveSpeed = lust * 0.02f * lust + lust * 0.05f + p.moveSpeed; } if (has(716)) p.moveSpeed = (float)(p.keepersSackBonus / 9) * 0.03f + p.moveSpeed; - p.moveSpeed = glitched_stat_get(p) * 0.2f + p.moveSpeed; + p.moveSpeed = glitched_stat_get(p, GLITCHED_SPEED) * 0.2f + p.moveSpeed; bulbs_apply(p, p.moveSpeed, 0.5f, 0.25f); if (effects.HasCollectibleEffect(77) || effects.HasCollectibleEffect(298)) p.moveSpeed = p.moveSpeed + 0.28f; if (p.HasTrinket(TRINKET_GOAT_HOOF)) p.moveSpeed = trinket_num(p, TRINKET_GOAT_HOOF) * 0.15f + p.moveSpeed; @@ -886,7 +839,8 @@ static void speed_evaluate(Entity_Player& p, const StatBonuses& bonus) else if (effects.HasCollectibleEffect(COLLECTIBLE_CAMO_UNDIES)) p.moveSpeed = p.moveSpeed + 0.5f; p.moveSpeed = p.d8SpeedModifier * p.moveSpeed; if (crownScale != 1 && p.moveSpeed > 1) p.moveSpeed = (p.moveSpeed - 1) * (crownScale - 1) + p.moveSpeed; - if (g_game->dailyChallenge.id == DAILY_SLOW) p.moveSpeed = p.moveSpeed - 1; + if (g_game->dailyChallenge.specialDailyId == SPECIAL_DAILY_SEPTEMBER_5) p.moveSpeed = p.moveSpeed - 1; + if (g_game->deathmatchManager.is_active()) g_game->deathmatchManager.type->speed_evaluate(p, p.moveSpeed); static_cast(g_luaEngine)->EvaluateItems(&p, CACHE_SPEED); } @@ -914,12 +868,12 @@ static void luck_evaluate(Entity_Player& p, const StatBonuses& bonus) entity->subtype == COLLECTIBLE_FORTUNE_COOKIE && static_cast(entity)->player == &p) wisps++; p.luck = (float)wisps * 0.2f + p.luck; - p.luck = glitched_stat_get(p) + p.luck; + p.luck = glitched_stat_get(p, GLITCHED_LUCK) + p.luck; if (p.coopBabyBuffTimers[COOP_BUFF_LUCK] > 0) p.luck = p.luck + 2; bulbs_apply(p, p.luck, 2, 0); if (p.HasCollectible(492)) p.luck = p.luck + 1; bulbs_apply(p, p.luck, 0, 1); - if (g_game->dailyChallenge.id == DAILY_LUCKY) p.luck = p.luck + DAILY_LUCK_BONUS; + if (g_game->dailyChallenge.specialDailyId == SPECIAL_DAILY_FEBRUARY_9) p.luck = p.luck + DAILY_LUCK_BONUS; if (g_game->debugFlags & DEBUG_HIGH_LUCK) p.luck = p.luck + DEBUG_LUCK_BONUS; static_cast(g_luaEngine)->EvaluateItems(&p, CACHE_LUCK); @@ -1096,7 +1050,14 @@ static ColorMod laser_color_get(Entity_Player& p) {p.playerType == PLAYER_BLUEBABY_B, color_make({2, 2, 2, 1}, {0.7f, 0.3f, 0.1f, 1})}}); } -// The tear colour part of 00763570: the first item in a fixed order picks it. +// A versus player's tears in its player color. +static ColorMod versus_tear_color_get(Entity_Player& p) +{ + ColorMod color = g_game->playerManager.player_color_mod_get(p); + return color_make({color._tint[0], color._tint[1], color._tint[2], 1}); +} + +// The tear colour part of 00763570: the first item in a fixed order picks it (a versus player's color when none does). static ColorMod tear_color_get(Entity_Player& p) { auto has = [&](int id) { return p.HasCollectible(id); }; @@ -1123,7 +1084,8 @@ static ColorMod tear_color_get(Entity_Player& p) {is_having(p, 398) && p.HasWeaponType(WEAPON_KNIFE), color_make({0.5f, 0.5f, 1, 1})}, {p.HasWeaponType(WEAPON_BONE) && has(COLLECTIBLE_HAEMOLACRIA), color_make({0.92f, 0.05f, 0.03f, 1})}, {p.playerType == PLAYER_BLUEBABY_B && !has(COLLECTIBLE_C_SECTION), - color_make({1.5f, 1.5f, 1.5f, 1}, {0.7f, 0.6f, 0.5f, 1}, {-0.4f, -0.45f, -0.4f})}}); + color_make({1.5f, 1.5f, 1.5f, 1}, {0.7f, 0.6f, 0.5f, 1}, {-0.4f, -0.45f, -0.4f})}, + {g_game->deathmatchManager.is_active(), versus_tear_color_get(p)}}); } // The tear colour section of 00763570: the laser and tear colours, both glowing for spirits and faded for holograms. @@ -1223,7 +1185,7 @@ static void size_evaluate(Entity_Player& p) float head = (float)(effect(121) + ((n(121) - n(120)) - effect(120))) * 0.152f + 0; if (game.seedEffects.HasSeedEffect(SEED_BIG_HEAD)) head = head + BIG_HEAD_BONUS; if (game.seedEffects.HasSeedEffect(SEED_SMALL_HEAD)) head = head - 1; - if (game.dailyChallenge.id == DAILY_BIG_SIZE) body = body + DAILY_BIG_SIZE_BONUS; + if (game.dailyChallenge.specialDailyId == SPECIAL_DAILY_SEPTEMBER_22) body = body + DAILY_BIG_SIZE_BONUS; float bodyScale = size_scale(body); float headScale = size_scale(head); @@ -1439,12 +1401,10 @@ static void speed_share(Entity_Player& p) // luck from the items, effects, pills, modifiers and the bonuses, then the tear flags and colours, flight, familiars, // luck, size and colour, each section handed to the mods. Libra, Rock Bottom and Dogma then reshape the stats, the // twins and helpers share their speed, and the stats are clamped and the tears' fall worked out. A shot speed change -// redoes the range. The versus mode's stat hooks stop the game. +// redoes the range. A versus match's rules scale the base damage, tint the tears in the player's color and adjust the +// fire delay, damage and speed. void Entity_Player::EvaluateItems() { - if (g_game->deathmatchManager.is_active()) - reconstruction_missing("Entity_Player::EvaluateItems 00763570 (the versus mode's stat hooks)"); - StatBonuses bonus = stat_bonuses_get(*this); if (cacheFlags & CACHE_WEAPON) weapons_evaluate(*this); if (cacheFlags & CACHE_SHOTSPEED) cacheFlags |= CACHE_RANGE; @@ -1479,31 +1439,3 @@ void Entity_Player::EvaluateItems() if ((cacheFlags & CACHE_SPEED) && g_fuel_count() > 0) moveSpeed = (float)g_fuel_count() * G_FUEL_SPEED + moveSpeed; cacheFlags = 0; } - -// The collectibles the items' part of the frame (update_effects 00794e50) looks at, which the plain path does not -// cover yet: Judas's kept Book of Belial. -constexpr int FRAME_ITEMS[] = {59}; - -// The trinkets the items' frame (00794e50) looks at that it does not run yet: Extension Cord. -constexpr std::array FRAME_TRINKETS = {TRINKET_EXTENSION_CORD}; - -// What the player's frame does not run yet, empty when it runs its plain path: a character or run it is not -// reconstructed for, a temporary effect it asks about but does not run, or an item or trinket it handles. The -// challenges' and daily runs' pieces of the frame are written where they fall. -std::string Entity_Player::frame_gap() -{ - Game& game = *g_game; - if (!is_character_reconstructed(*this)) return "character " + std::to_string(playerType); - if (variant != PLAYER_VARIANT_PLAYER || isCoopGhost || hasCurseMistEffect) return "a co-op baby, ghost or the mist"; - if (game.seedEffects.CountSeedEffects() != 0 || game.deathmatchManager.is_active()) return "a seeded or versus run"; - if (!proceduralItems.empty()) return "a glitched item"; - for (const TemporaryEffect& effect : temporaryEffects.effects) - if (!is_frame_effect_known(effect)) - return "update_effects 00794e50: the effect of item " + std::to_string(effect.item->type) + "." + - std::to_string(effect.item->id); - for (int id : FRAME_ITEMS) - if (HasCollectible(id)) return "update_effects 00794e50: collectible " + std::to_string(id); - for (int id : FRAME_TRINKETS) - if (HasTrinket(id)) return "update_effects 00794e50: trinket " + std::to_string(id); - return {}; -} diff --git a/src/entity_player_familiars.cpp b/src/entity_player_familiars.cpp index 33b8f88..5eb00cb 100644 --- a/src/entity_player_familiars.cpp +++ b/src/entity_player_familiars.cpp @@ -15,7 +15,7 @@ constexpr int LEPROSY_MAX = 3; constexpr size_t SWARM_FLIES_MAX = 15; -constexpr float MINISAAC_LAUNCH_TURN = 3.14f * 2; +constexpr float MINISAAC_LAUNCH_TURN = PI_ROUGH * 2; constexpr float MINISAAC_LAUNCH_SPEED_RANGE = 3; constexpr float MINISAAC_LAUNCH_SPEED_MIN = 2; constexpr int MINISAAC_FORGOTTEN_SUBTYPE = 99; @@ -184,7 +184,6 @@ void Entity_Player::twins_duplicate_familiars(int count) temporaryEffects.AddCollectibleEffect(lent, true, 1); std::swap(familiars[taken], familiars.back()); familiars.pop_back(); - if (g_game->deathmatchManager.is_active()) - reconstruction_missing("Entity_Player::twins_duplicate_familiars 007dbeb0 (the versus mode)"); + if (g_game->deathmatchManager.is_active()) versus.twinsEffects.push_back(lent); } } diff --git a/src/entity_player_forgotten.cpp b/src/entity_player_forgotten.cpp index 76b7cad..e0f9333 100644 --- a/src/entity_player_forgotten.cpp +++ b/src/entity_player_forgotten.cpp @@ -19,7 +19,6 @@ constexpr int FORGOTTEN_SWAP_COOLDOWN = 15; constexpr int FORGOTTEN_SWAP_HOLD_COOLDOWN = 10; constexpr uint32_t DROP_HOLD_FRAMES = 120; -constexpr uint32_t SPECIAL_DAILY_NO_DROP = 4; constexpr int DROP_TRINKET_TRIES = 2; constexpr int DROP_POCKET_TRIES = 4; constexpr int POCKET_SLOT_FIRST_FILLED = -1; @@ -42,7 +41,6 @@ constexpr int SWAP_POOF_SUBTYPE = 10; constexpr float SWAP_TRAIL_SPACING = 20; constexpr int SWAP_TRAIL_MIN = 4; constexpr int SWAP_TRAIL_MAX = 12; -constexpr float SWAP_TRAIL_TURN = 3.14f; constexpr float SWAP_TRAIL_SPREAD = 15; constexpr float SWAP_TRAIL_SPEED_MIN = 0.5f; constexpr float SWAP_TRAIL_SIZE_MIN = 0.3f; @@ -57,7 +55,6 @@ constexpr int FORGOTTEN_BODY_LEFT_GRID_PATH = 900; constexpr float FORGOTTEN_BODY_DUNGEON_FRICTION = 0.95f; constexpr float FORGOTTEN_BODY_LURE_RADIUS = 30; constexpr float FORGOTTEN_BODY_LURE_TURN_MAX = 0.99f; -constexpr float HALF_TURN_RADIANS = 3.1415927f; // The chain from The Soul to the body: its eight links spread along it, how far The Soul strays before it pulls, and // its colour on a co-op ghost. @@ -106,7 +103,7 @@ static void swap_trail_spawn(Entity_Player& player, Vector toBody, Vector poofVe float t = (float)i / (float)(count + 1); Vector along = vector_make(player.pos.x + (bodyPos.x - player.pos.x) * t, player.pos.y + (bodyPos.y - player.pos.y) * t); - float angle = random_unit() * SWAP_TRAIL_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float spread = random_unit(); Vector spot = vector_make(std::cos(angle) * spread * SWAP_TRAIL_SPREAD + along.x, @@ -442,20 +439,20 @@ static void tainted_inventory_rotate(Entity_Player& player) } } -// The drop button held two seconds: the trinkets (but Tick, and Rainbow Worm in Pride Day) and the cards and pills go -// to the floor. +// The drop button held two seconds: the trinkets (but Tick, and Rainbow Worm in Pride Day, or in a versus match all of +// them when its rules keep them) and the cards and pills go to the floor. static void drop_hold_update(Entity_Player& player) { Game& game = *g_game; + DeathmatchManager& versus = game.deathmatchManager; bool isAnythingToDrop = false; player.actionHoldDrop = 0; for (uint32_t trinket : player.trinkets) { if (trinket == 0) continue; - if (game.deathmatchManager.is_active()) - reconstruction_missing("Entity_Player::pockets_rotate 007a42b0 (a versus mode's trinket drop)"); - if (trinket != TRINKET_TICK && !(trinket == TRINKET_RAINBOW_WORM && game.challenge == CHALLENGE_PRIDE_DAY)) + if (versus.is_active()) isAnythingToDrop |= versus.type->is_trinket_swap_allowed(); + else if (trinket != TRINKET_TICK && !(trinket == TRINKET_RAINBOW_WORM && game.challenge == CHALLENGE_PRIDE_DAY)) isAnythingToDrop = true; } for (uint32_t slot = 0; slot < player.GetMaxPocketItems(); slot++) @@ -503,7 +500,7 @@ void Entity_Player::pockets_rotate() actionHoldDrop = 0; return; } - if ((uint32_t)++actionHoldDrop > DROP_HOLD_FRAMES && game.dailyChallenge.specialDailyId != SPECIAL_DAILY_NO_DROP) + if ((uint32_t)++actionHoldDrop > DROP_HOLD_FRAMES && game.dailyChallenge.specialDailyId != SPECIAL_DAILY_MARCH_2) drop_hold_update(*this); } @@ -550,7 +547,7 @@ void forgotten_body_update(Entity_Familiar& body) Vector heading = vector_normalized(shot->velocity); Vector lure = vector_normalized(toBody); Vector lured = vector_scale(lure, vector_length(shot->velocity)); - float kept = std::min(FORGOTTEN_BODY_LURE_TURN_MAX, std::acos(vector_dot(heading, lure)) / HALF_TURN_RADIANS); + float kept = std::min(FORGOTTEN_BODY_LURE_TURN_MAX, std::acos(vector_dot(heading, lure)) / PI_F); shot->velocity = vector_add(vector_scale(shot->velocity, kept), vector_scale(lured, 1 - kept)); } } diff --git a/src/entity_player_frame.cpp b/src/entity_player_frame.cpp index 886f29a..38001d4 100644 --- a/src/entity_player_frame.cpp +++ b/src/entity_player_frame.cpp @@ -1,4 +1,5 @@ #include "entity_player.h" +#include "entity_config.h" #include "entity_player_trinkets.h" #include "entity_player_characters.h" #include "entity_player_crafting.h" @@ -39,6 +40,7 @@ constexpr int DUCT_TAPE_MODES = 4; constexpr float BODY_TURN_RATE = 0.3f; constexpr float FLYING_OFFSET_Y = -4; constexpr float HELD_OFFSET_SCALE = 0.65f; +constexpr float AFTER_IMAGE_FADE_FRAMES = 10; constexpr float MOVE_SPEED_BASE = 0.75f; constexpr float MOVE_SPEED_SCALE = 0.25f; constexpr float SLIPPERY_FRAMES = 60; @@ -161,7 +163,6 @@ constexpr int ITEM_STATE_SHOOP_DA_WHOOP = 49; constexpr int POINTY_RIB_BLINK = 7; constexpr int SHOOP_BLINK = 10; constexpr int SHOOT_HISTORY_SIZE = 3; -constexpr int SPECIAL_DAILY_BUTTER_BEAN = 41; constexpr int SUPLEX_TARGET_VARIANT = 30; constexpr float MARKED_SPAWN_REACH = 5; constexpr float MARKED_STEER_SPEED = 8; @@ -881,8 +882,8 @@ static Vector item_throw_velocity(Entity_Player& p, Vector direction, float spee vector_scale(p.GetTearMovementInheritance(direction, INHERIT_CHECKED), inheritance)); } -// The Candle's and Red Candle's flames (one more with the Car Battery) and Bob's Rotten Head, thrown along the axis -// the player shoots on with its movement. +// The Candle's and Red Candle's flames (one more with the Car Battery, faded for a remote online player, hurting as +// the versus rules say) and Bob's Rotten Head, thrown along the axis the player shoots on with its movement. static void candle_throw(Entity_Player& p, const ItemStateShot& shot) { constexpr std::array FLAME_SPEEDS = {14, 7}; @@ -890,8 +891,6 @@ static void candle_throw(Entity_Player& p, const ItemStateShot& shot) if (p.itemState == COLLECTIBLE_CANDLE || p.itemState == COLLECTIBLE_RED_CANDLE) { - if (g_game->deathmatchManager.is_active() || !p.IsLocalPlayer()) - reconstruction_missing("Entity_Player::update_shooting 0077b020 (an online or versus player's flames)"); bool isCandle = p.itemState == COLLECTIBLE_CANDLE; int flames = p.HasCollectible(COLLECTIBLE_CAR_BATTERY) ? 2 : 1; for (int i = 0; i < flames; i++) @@ -901,6 +900,13 @@ static void candle_throw(Entity_Player& p, const ItemStateShot& shot) velocity); if (isCandle) static_cast(flame)->SetTimeout(CANDLE_FLAME_TIMEOUT); flame->SetCollisionDamage(CANDLE_FLAME_DAMAGE); + if (g_game->deathmatchManager.is_active()) g_game->deathmatchManager.type->entity_damage_adjust(*flame); + if (!p.IsLocalPlayer()) + { + ColorMod faded = flame->sprite.color; + faded._tint[3] *= tear_remote_opacity_get(); + flame->SetColor(faded, -1, COLOR_PRIORITY_DEFAULT, false, true); + } flame->Update(); } } @@ -973,14 +979,42 @@ static void glass_cannon_fire(Entity_Player& p, const ItemStateShot& shot) item_state_spend(p); } -// The Friend Ball, thrown empty or with the enemy it caught. The challenge filling it at random is not written. +// The Friend Ball challenge fills each throw with a random rerollable enemy, a flying or a walking one, redirected to +// what it becomes, at half health. +static void friend_ball_challenge_fill(Entity_Player& p) +{ + EntityConfig& configs = g_manager->entityConfig; + RNG& rng = p.GetCollectibleRNG(COLLECTIBLE_FRIEND_BALL); + std::vector& pool = rng.RandomInt(2) == 0 ? configs.otherRerolls : configs.groundRerolls; + if (pool.empty()) return; + + RerollEntry entry = pool[rng.RandomInt((uint32_t)pool.size())]; + int type = entry.id; + int variant = entry.variant; + if (Entity_NPC::Redirect(&type, &variant)) + if (EntityConfig_Entity* config = configs.GetEntity(type, variant, 0)) + { + type = config->id; + variant = config->variant; + entry.subtype = config->subtype; + entry.baseHP = config->baseHP; + } + p.friendBallEnemy.maxHealth = entry.baseHP; + p.friendBallEnemy.type = (uint32_t)type; + p.friendBallEnemy.variant = (uint32_t)variant; + p.friendBallEnemy.health = entry.baseHP * 0.5f; + p.friendBallEnemy.subtype = (uint32_t)entry.subtype; +} + +// The Friend Ball, thrown empty or with the enemy it caught. In its challenge it always flies full. static void friend_ball_throw(Entity_Player& p, const ItemStateShot& shot) { Vector velocity = item_throw_velocity(p, shot.direction, FRIEND_BALL_SPEED); - if (g_game->challenge == CHALLENGE_FRIEND_BALL_FILLED) - reconstruction_missing("Entity_Player::update_shooting 0077b020 (the Friend Ball's challenge enemy)"); + bool isChallenge = g_game->challenge == CHALLENGE_FRIEND_BALL_FILLED; + if (isChallenge) friend_ball_challenge_fill(p); - Entity* ball = item_throw_spawn(p, ENTITY_EFFECT, EFFECT_FRIEND_BALL, velocity, p.friendBallEnemy.type != 0); + Entity* ball = item_throw_spawn(p, ENTITY_EFFECT, EFFECT_FRIEND_BALL, velocity, + isChallenge || p.friendBallEnemy.type != 0); ball->parent = &p; ball->Update(); sound_fart_play(SOUND_FRIENDLYBALL_THROW); @@ -1691,8 +1725,7 @@ void Entity_Player::update_shooting() if (isFree && isPresent) shoot_input_read(input); } - if (variant == PLAYER_VARIANT_COOP_BABY && babySkin == BABY_YBAB) - reconstruction_missing("Entity_Player::update_shooting 0077b020 (the mirrored baby's aim)"); + if (variant == PLAYER_VARIANT_COOP_BABY && babySkin == BABY_YBAB) input.direction = mirrored_aim_get(input.direction); Vector markedAim = input.direction; bool isKidneyBurst = false; if (peeBurstCooldown > 0) @@ -1751,7 +1784,7 @@ void Entity_Player::update_shooting() if (HasCollectible(COLLECTIBLE_NO_2) && game.stageTransition.state == 0 && isInputAllowed && fireBlockCooldown < 1) number_two_update(*this, isShootHeld); - bool isButterBeanDaily = game.dailyChallenge.specialDailyId == SPECIAL_DAILY_BUTTER_BEAN; + bool isButterBeanDaily = game.dailyChallenge.specialDailyId == SPECIAL_DAILY_AUGUST_16; if (isButterBeanDaily && game.stageTransition.state == 0 && isInputAllowed && isShootHeld && IsFrame(BUTTER_BEAN_DAILY_PERIOD, 0) && (Random() & BUTTER_BEAN_DAILY_ODDS_MASK) == 0) game_butter_bean_fart({.position = pos, .source = this, .radius = BUTTER_BEAN_DAILY_RADIUS}); @@ -1868,16 +1901,23 @@ void Entity_Player::update_shooting() if (!IsFullSpriteRendering()) { if (variant != PLAYER_VARIANT_PLAYER || isCoopGhost) - reconstruction_missing("Entity_Player::update_shooting 0077b020 (co-op babies' and ghosts' heads)"); - if (HasCollectible(COLLECTIBLE_BONE_SPURS) && sprite.GetOverlayFrame() == 0 && blinkFrame != 0) - game_particles_spawn({.position = pos, - .height = posOffset.y, - .speed = random_between(BONE_SPUR_CHIP_SPEED, BONE_SPUR_CHIP_RANGE), - .count = 1, - .subType = 1, - .variant = EFFECT_TOOTH_PARTICLE}); - sprite.SetOverlayFrame(headAnim, blinkFrame); - costume_heads_update(blinkFrame); + { + bool isCharging = std::any_of(weapons.begin() + 1, weapons.end(), + [](const WeaponPtr& weapon) { return weapon && weapon->charge > 0; }); + if (!isCharging) sprite.SetFrame(headAnim, blinkFrame); + } + else + { + if (HasCollectible(COLLECTIBLE_BONE_SPURS) && sprite.GetOverlayFrame() == 0 && blinkFrame != 0) + game_particles_spawn({.position = pos, + .height = posOffset.y, + .speed = random_between(BONE_SPUR_CHIP_SPEED, BONE_SPUR_CHIP_RANGE), + .count = 1, + .subType = 1, + .variant = EFFECT_TOOTH_PARTICLE}); + sprite.SetOverlayFrame(headAnim, blinkFrame); + costume_heads_update(blinkFrame); + } } if (isFireReady && HasCollectible(COLLECTIBLE_EPIPHORA)) epiphora_update(*this, {shootDirection, false, isShootHeld}); @@ -1908,7 +1948,7 @@ static void hud_bubble_render(PlayerHUD& hud, Vector at) // 0078ca00 Draws the player at its place, lifted by its flight and its offset: blinking while hurt, the held entity // in front or behind, then its overlays (the co-op indicator, charge bars, status effect and the Void's hallucination // of its past walk) in the room's pass. A player following a target shows only a marker. Netplay's shadows and colors -// are offline, and nothing fills the after-images the original keeps. +// are offline. The dashes' after-images draw first, fading. void Entity_Player::Render(const Vector& offset) { if (target) @@ -1937,6 +1977,15 @@ void Entity_Player::Render(const Vector& offset) IsExtraAnimationFinished() && g_game->challenge != CHALLENGE_GUARDIAN && !HasEntityFlags(FLAG_NO_DAMAGE_BLINK)) return; held_entity_render(renderOffset, HELD_BEHIND); + for (const AfterImageFrame& image : afterImageFrames) + { + ColorMod faded = sprite.color; + faded._tint[3] = std::clamp((float)image.frames / AFTER_IMAGE_FADE_FRAMES, 0.0f, 1.0f) * sprite.color._tint[3]; + color_stack_push(faded); + render_pass(vector_add(vector_scale(vector_sub(image.position, pos), HELD_OFFSET_SCALE), renderOffset), + RENDER_PASS_AFTER_IMAGE); + color_stack_pop(); + } render_pass(renderOffset, RENDER_PASS_MAIN); held_entity_render(renderOffset, HELD_FRONT); lua_engine_get().PostPlayerRender(this, offset); @@ -1960,8 +2009,7 @@ void Entity_Player::Render(const Vector& offset) } } if (!hallucinationTrail.frames.empty() && g_game->hallucinationTimer > 0) hallucination_trail_render(*this, offset); - if (g_game->deathmatchManager.is_active()) - reconstruction_missing("Entity_Player::Render 0078ca00 (the deathmatch overlay)"); + if (g_game->deathmatchManager.is_active()) g_game->deathmatchManager.type->player_render(*this); } // The reflection Tainted Lazarus casts on water: his other form, shown and posed as he is, its layers and costumes diff --git a/src/entity_player_hits.cpp b/src/entity_player_hits.cpp index 97643d3..23a22f6 100644 --- a/src/entity_player_hits.cpp +++ b/src/entity_player_hits.cpp @@ -36,6 +36,15 @@ constexpr int MISSING_PAGE_ODDS_MIN = 2; constexpr int OVERLAY_MISSING_PAGE = 30; constexpr int FISH_HEAD_VERSUS_ODDS = 5; constexpr int GIANT_CELL_MAX = 16; +// A versus match paces the hit items: Giant Cell every 15 damage, Purity after five hits then 210 frames away, Leprosy +// every fifth hit, It Hurts three times, and Varicose Veins at most every four seconds, at 32 percent. +constexpr float GIANT_CELL_VERSUS_DAMAGE = 15; +constexpr short PURITY_VERSUS_HITS = 5; +constexpr short PURITY_VERSUS_RECOVERY = -210; +constexpr int LEPROSY_VERSUS_HITS = 5; +constexpr int IT_HURTS_VERSUS_MAX = 3; +constexpr uint64_t VARICOSE_VERSUS_MS = 4001; +constexpr int VARICOSE_VERSUS_SCALE = 32; constexpr int SALVATION_HITS_MAX = 10; constexpr float PERFECTION_SPEED_MIN = 4; constexpr float PERFECTION_SPEED_RANDOM = 6; @@ -119,13 +128,18 @@ static void missing_page_hit(Entity_Player& player) player.UseActiveItem({.item = COLLECTIBLE_NECRONOMICON, .flags = USE_NOANIM}); } -// Giant Cell's part of 007729d0: the player's Minisaacs heal, and one more joins them up to sixteen. -static void giant_cell_hit(Entity_Player& player) +// Giant Cell's part of 007729d0: the player's Minisaacs heal, and one more joins them up to sixteen (in a versus match +// only once 15 damage has been taken since the last). +static void giant_cell_hit(Entity_Player& player, float damage) { - if (g_game->deathmatchManager.is_active()) - reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Giant Cell in versus)"); std::vector minisaacs = player_familiars(player, Entity_Familiar::MINISAAC); for (Entity_Familiar* minisaac : minisaacs) minisaac->health = minisaac->maxHitPoints; + if (g_game->deathmatchManager.is_active()) + { + player.versus.giantCellDamage += damage; + if (player.versus.giantCellDamage < GIANT_CELL_VERSUS_DAMAGE) return; + player.versus.giantCellDamage -= GIANT_CELL_VERSUS_DAMAGE; + } if (minisaacs.size() < GIANT_CELL_MAX) player.AddMinisaac(player.pos, true); } @@ -171,38 +185,50 @@ static void swallowed_penny_hit(Entity_Player& player) } } -// Purity's part of 007729d0: a hit ends its aura and rolls the next room's colour. +// Purity's part of 007729d0: a hit ends its aura and rolls the next room's colour. In a versus match it takes five +// hits, and the aura recovers on its own (see the player's update). static void purity_hit(Entity_Player& player) { - if (g_game->deathmatchManager.is_active()) reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Purity in versus)"); + if (g_game->deathmatchManager.is_active()) + { + if (++player.versus.purityHits < PURITY_VERSUS_HITS) return; + player.versus.purityHits = PURITY_VERSUS_RECOVERY; + } player.temporaryEffects.RemoveCollectibleEffect(COLLECTIBLE_PURITY, 1); player.purityState = (int)player.GetCollectibleRNG(COLLECTIBLE_PURITY).RandomInt(PURITY_STATES); player.RemoveCostume(g_manager->itemConfig.GetNullItem(NULLITEM_PURITY_GLOW)); } // Varicose Veins' part of 007729d0: the hit fires Tammy's Head's ring of tears, and one hit in five bleeds Anemic's -// trail for two seconds. +// trail for two seconds. A versus match fires it at most every four seconds, with weaker tears. static void varicose_veins_hit(Entity_Player& player) { TemporaryEffects& effects = player.temporaryEffects; - if (g_game->deathmatchManager.is_active()) - reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Varicose Veins in versus)"); + bool isVersus = g_game->deathmatchManager.is_active(); + if (isVersus && !versus_cooldown_is_over(player.versus.varicoseVeinsMs, VARICOSE_VERSUS_MS)) return; effects.AddCollectibleEffect(COLLECTIBLE_VARICOSE_VEINS, true, 1); - player.UseActiveItem({.item = COLLECTIBLE_TAMMYS_HEAD, .flags = USE_NOANIM}); + player.UseActiveItem({.item = COLLECTIBLE_TAMMYS_HEAD, .flags = USE_NOANIM, .varData = isVersus ? VARICOSE_VERSUS_SCALE : 0}); effects.RemoveCollectibleEffect(COLLECTIBLE_VARICOSE_VEINS, 1); - if (effects.HasCollectibleEffect(COLLECTIBLE_ANEMIC) || - player.GetCollectibleRNG(COLLECTIBLE_VARICOSE_VEINS).RandomInt(VARICOSE_ANEMIC_ODDS) != 0) - return; - TemporaryEffect anemic(g_manager->itemConfig.GetCollectible(COLLECTIBLE_ANEMIC)); - anemic.cooldown = VARICOSE_ANEMIC_FRAMES; - effects.AddEffect(anemic, true, 1); + if (!effects.HasCollectibleEffect(COLLECTIBLE_ANEMIC) && + player.GetCollectibleRNG(COLLECTIBLE_VARICOSE_VEINS).RandomInt(VARICOSE_ANEMIC_ODDS) == 0) + { + TemporaryEffect anemic(g_manager->itemConfig.GetCollectible(COLLECTIBLE_ANEMIC)); + anemic.cooldown = VARICOSE_ANEMIC_FRAMES; + effects.AddEffect(anemic, true, 1); + } + player.versus.varicoseVeinsMs = versus_time_get(); } -// It Hurts' part of 007729d0: ten blood tears burst out in a ring, and the tears go up for the room. +// It Hurts' part of 007729d0: ten blood tears burst out in a ring, and the tears go up for the room (three times in a +// versus match). static void it_hurts_hit(Entity_Player& player) { - if (g_game->deathmatchManager.is_active()) reconstruction_missing("Entity_Player::TakeDamage 007729d0 (It Hurts in versus)"); + if (g_game->deathmatchManager.is_active()) + { + if (player.versus.itHurtsHits >= IT_HURTS_VERSUS_MAX) return; + player.versus.itHurtsHits++; + } for (int i = 0; i < IT_HURTS_TEARS; i++) { Vector velocity = vector_scale(vector_from_angle((float)i * DEGREES_PER_TURN / IT_HURTS_TEARS), IT_HURTS_SPEED); @@ -387,10 +413,9 @@ bool late_items_hit_trigger(Entity_Player& player, const ItemsHit& hit) } if (player.HasCollectible(COLLECTIBLE_LEPROSY)) { - if (isVersus) reconstruction_missing("Entity_Player::TakeDamage 007729d0 (Leprosy in versus)"); - player.AddLeprosy(); + if (!isVersus || ++player.versus.leprosyHits % LEPROSY_VERSUS_HITS == 0) player.AddLeprosy(); } - if (player.HasCollectible(COLLECTIBLE_GIANT_CELL)) giant_cell_hit(player); + if (player.HasCollectible(COLLECTIBLE_GIANT_CELL)) giant_cell_hit(player, hit.damage); if (player.HasCollectible(COLLECTIBLE_SALVATION) && effects.GetCollectibleEffectNum(COLLECTIBLE_SALVATION) < SALVATION_HITS_MAX) effects.AddCollectibleEffect(COLLECTIBLE_SALVATION, true, 1); if (hit.isPenalized && player.HasTrinket(TRINKET_PERFECTION) && player.TryRemoveTrinket(TRINKET_PERFECTION)) @@ -434,6 +459,7 @@ bool late_items_hit_trigger(Entity_Player& player, const ItemsHit& hit) .flags = USE_NOANIM}); } if (player.HasCollectible(COLLECTIBLE_PURITY) && effects.HasCollectibleEffect(COLLECTIBLE_PURITY)) purity_hit(player); + if (player.versus.purityHits < 0) player.versus.purityHits = PURITY_VERSUS_RECOVERY; if (!isVersus && player.HasCollectible(COLLECTIBLE_CROWN_OF_LIGHT) && effects.HasCollectibleEffect(COLLECTIBLE_CROWN_OF_LIGHT)) { effects.RemoveCollectibleEffect(COLLECTIBLE_CROWN_OF_LIGHT, 1); @@ -462,6 +488,8 @@ bool late_items_hit_trigger(Entity_Player& player, const ItemsHit& hit) if (player.HasTrinket(TRINKET_TORN_POCKET)) torn_pocket_hit(player); if (player.HasCollectible(COLLECTIBLE_HYPERCOAGULATION) && !(hit.damageFlags & (DAMAGE_IV_BAG | DAMAGE_NO_PENALTIES))) hypercoagulation_hit(player, hit.damage); + glitched_items_trigger(player, {player.pos, vector_normalized(vector_sub(player.pos, hit.source.position)), + hit.source.entity, CONDITION_DAMAGE_TAKEN}); if (player.HasCollectible(COLLECTIBLE_LARGE_ZIT)) player.DoZitEffect(vector_from_angle(random_unit() * DEGREES_PER_TURN)); if (player.HasTrinket(TRINKET_TONSIL)) tonsil_hit(player); if (player.HasTrinket(TRINKET_BAG_LUNCH) && diff --git a/src/entity_player_hold.cpp b/src/entity_player_hold.cpp index 3b33fb9..45a611c 100644 --- a/src/entity_player_hold.cpp +++ b/src/entity_player_hold.cpp @@ -8,6 +8,7 @@ #include "log.h" #include "manager.h" #include "npc_ai.h" +#include #include constexpr float THROW_HEIGHT = 7; @@ -22,6 +23,7 @@ constexpr float HELD_THROW_SPEED = 10; constexpr float HELD_THROW_BOOST = 1.2f; constexpr int HELD_HIDE_COOLDOWN = 5; constexpr int SUPLEX_GRAB = 1; +constexpr float SUPLEX_LIFT = 0.2f; constexpr float PLAYER_FALL_GRAVITY = 1.1f; constexpr float THROWN_GRAVITY = 0.6f; constexpr float THROWN_HIGH = -26; @@ -215,7 +217,7 @@ bool Entity_Player::TryThrow(const EntityRef& source, const Vector& throwVelocit } // The held entity's part of 00782af0: it moves with the player. A held player sits at the height of the body's held -// null. +// null, or while suplexed the player's own. void Entity_Player::held_entity_follow() { if (!heldEntity) return; @@ -224,31 +226,82 @@ void Entity_Player::held_entity_follow() heldEntity->velocity = velocity; if (!heldEntity->is_player()) return; - if (suplexState > SUPLEX_GRAB && !bodySprite.GetNullFrameById(0)) - reconstruction_missing("Entity_Player::Update 00782af0 (a suplexed player's height)"); - if (const NullFrame* held = bodySprite.GetNullFrameById(0)) - heldEntity->posOffset.y = held->pos.y / HELD_RENDER_SCALE * playerSpriteScale.y; + const NullFrame* held = bodySprite.GetNullFrameById(0); + if (!held && suplexState > SUPLEX_GRAB) held = sprite.GetNullFrameById(0); + if (held) heldEntity->posOffset.y = held->pos.y / HELD_RENDER_SCALE * playerSpriteScale.y; } -// Part of 0078ca00: draws the held entity on its side of the player, at the body's held null while lifting, shown for -// the draw only. One with a negative depth goes behind. +// How the held entity shows on the player: where it sits, its scale and turn, and on which side it draws. +struct HeldPose +{ + Vector offset{}; + Vector scale = vector_make(1, 1); + float rotation = 0; + bool isBehind = false; +}; + +// The top of a suplexed entity's sprite: the highest corner its layers reach at their keyframes, infinite for none. +static float held_sprite_top(Entity& held) +{ + const AnimationData* animation = held.sprite.animState.animData; + float top = INFINITY; + for (const AnimationLayer& track : animation->animLayers) + { + LayerState* layer = held.sprite.GetLayer(track.layerId); + const AnimationFrame* frame = held.sprite.animState.GetLayerFrame(track.layerId); + if (!layer || !frame) continue; + DestinationQuad quad = AnimationLayer::GetDestQuad(*frame, *layer, {}, held.sprite); + top = std::min({top, quad._topLeft.y, quad._topRight.y, quad._bottomLeft.y, quad._bottomRight.y}); + } + return top; +} + +// Part of 0078ca00: how the held entity is posed. One with a negative depth goes behind. Mom's Bracelet and a suplex +// hold it at the body's held null (the player's own while suplexed). A suplex also scales and turns it with that +// null, puts it behind while landing, and lifts it by a fifth of its sprite's height. Without the null it hides. +static bool held_pose_get(Entity_Player& player, HeldPose& pose) +{ + Entity& held = *player.heldEntity; + pose.isBehind = held.renderZOffset < 0; + bool isSuplexed = player.suplexState > SUPLEX_GRAB; + if (player.itemState != COLLECTIBLE_MOMS_BRACELET && !isSuplexed) return true; + + const NullFrame* frame = player.bodySprite.animState.animData ? player.bodySprite.GetNullFrameById(0) : nullptr; + if (!frame && isSuplexed) frame = player.sprite.GetNullFrameById(0); + if (!frame) return false; + pose.offset = frame->pos; + if (!isSuplexed) return true; + + pose.scale = frame->scale; + pose.isBehind = player.suplexState == SUPLEX_LANDING; + pose.rotation = frame->rotation; + if (!held.sprite.animState.animData) return true; + float top = held_sprite_top(held); + if (!std::isfinite(top)) return true; + float lift = pose.scale.y * SUPLEX_LIFT * top; + pose.offset.y = pose.rotation == 0 ? pose.offset.y - lift : pose.offset.y + lift; + return true; +} + +// Part of 0078ca00: draws the held entity on its side of the player, posed for the draw only (scaled, turned and +// shown) and put back after. void Entity_Player::held_entity_render(Vector renderOffset, HeldSide side) { - if (!heldEntity || heldEntity->isVisible || (heldEntity->renderZOffset < 0) != (side == HELD_BEHIND)) return; - - Vector lift{}; - if (itemState == COLLECTIBLE_MOMS_BRACELET || suplexState > SUPLEX_GRAB) - { - if (suplexState > SUPLEX_GRAB) reconstruction_missing("Entity_Player::Render 0078ca00 (a suplexed entity)"); - const NullFrame* held = bodySprite.animState.animData ? bodySprite.GetNullFrameById(0) : nullptr; - if (!held) return; - lift = held->pos; - } + HeldPose pose; + if (!heldEntity || !held_pose_get(*this, pose) || heldEntity->isVisible || pose.isBehind != (side == HELD_BEHIND)) + return; Entity& entity = *heldEntity; + Vector scale = entity.sprite.scale; + float rotation = entity.sprite.rotation; + entity.sprite.scale = vector_make(scale.x * pose.scale.x, scale.y * pose.scale.y); + entity.sprite.rotation = rotation + pose.rotation; entity.isVisible = true; - entity.Render(vector_add(vector_add(vector_scale(vector_sub(pos, entity.pos), HELD_RENDER_SCALE), renderOffset), lift)); + entity.Render( + vector_add(vector_add(vector_scale(vector_sub(pos, entity.pos), HELD_RENDER_SCALE), renderOffset), pose.offset)); entity.isVisible = false; + entity.sprite.scale = scale; + entity.sprite.rotation = rotation; } // Whether Tainted Forgotten's soul holds its body while the body's weapon takes the throw over or its urethra is diff --git a/src/entity_player_items.cpp b/src/entity_player_items.cpp index 01fa520..12afa5c 100644 --- a/src/entity_player_items.cpp +++ b/src/entity_player_items.cpp @@ -3,6 +3,7 @@ #include "active_items.h" #include "entity_familiar.h" #include "entity_player_characters.h" +#include "entity_effect.h" #include "entity_pickup.h" #include "stage_transition.h" #include "entity_player_passives.h" @@ -20,13 +21,11 @@ constexpr int ROOM_TRINKET_ROLL_SHIFT = 13; constexpr float PICKUP_SPAWN_STEP = 40; -constexpr uint32_t DAILY_RAINBOW_TRINKETS = 28; constexpr int ERROR_TRINKET_RANGE = 189; constexpr uint32_t GRANTED_FIRE_MIND = 0x8; constexpr uint32_t GRANTED_SCORPIO = 0x10; constexpr uint32_t GRANTED_BALL_OF_TAR = 0x20; constexpr uint32_t GRANTED_SACRED_HEART = 0x40; -constexpr int G_FUEL_SLOT = 143; constexpr int G_FUEL_COLLECTIBLE_COUNT = 6; constexpr int G_FUEL_STACKS = 8; constexpr uint32_t G_FUEL_RNG_SHIFT = 8; @@ -34,6 +33,18 @@ constexpr uint32_t USED_DIAPER_RNG_SHIFT = 4; constexpr uint32_t USED_DIAPER_CHANCE = 33; constexpr uint32_t SEEDED_VARIANT_RNG_SHIFT = 15; +// The G FUEL! item's jingle as it is held up, by the run's stacks (0 to 1, 2 to 3, 4 to 5, more): its sound, frame +// delay and volume, played a second later. +struct GFuelJingle +{ + int sound = 0; + int frameDelay = 0; + float volume = 1; +}; +constexpr std::array G_FUEL_JINGLES = { + {{SOUND_GFUEL_1, 15, 1.5f}, {SOUND_GFUEL_2, 15, 1.7f}, {SOUND_GFUEL_3, 15, 2}, {SOUND_GFUEL_4, 20, 2.4f}}}; +constexpr int G_FUEL_JINGLE_DELAY = 60; + // The trinkets Rainbow Worm cycles through, and that daily 28 doubles. constexpr std::array RAINBOW_WORM_TRINKETS = {9, 11, 65, 27, 10, 12, 26, 66, 96, 144}; // The collectibles G FUEL! grants one of by the start seed. @@ -368,7 +379,7 @@ int Entity_Player::GetTrinketMultiplier(uint32_t trinketType) int multiplier = trinketType == TRINKET_LIL_LARVA && owner.playerType == PLAYER_BLUEBABY ? 1 : 0; if (owner.hasCurseMistEffect || owner.isCoopGhost) return multiplier; - if (game.dailyChallenge.specialDailyId == DAILY_RAINBOW_TRINKETS && + if (game.dailyChallenge.specialDailyId == SPECIAL_DAILY_MARCH_22 && std::ranges::find(RAINBOW_WORM_TRINKETS, (int)id) != RAINBOW_WORM_TRINKETS.end()) multiplier++; @@ -433,7 +444,7 @@ int Entity_Player::trinket_bonus(uint32_t id, int multiplier) } if (id == TRINKET_MISSING_POSTER) return multiplier + temporaryEffects.GetTrinketEffectNum(TRINKET_MISSING_POSTER); - if (id == TRINKET_BUTT_PENNY) return multiplier + (coopBabyBuffTimers[COOP_BABY_BUFF_COUNT - 1] > 0 ? 1 : 0); + if (id == TRINKET_BUTT_PENNY) return multiplier + (coopBabyBuffTimers[COOP_BUFF_BUTT_PENNY] > 0 ? 1 : 0); if (id == TRINKET_PAPER_CLIP) return multiplier + (paperClipTimer > 0 ? 1 : 0); return multiplier; } @@ -450,7 +461,7 @@ int Entity_Player::GetActiveItemSlot(int id) int Entity_Player::g_fuel_count() { if (!g_game->seedEffects.HasSeedEffect(SEED_G_FUEL)) return 0; - return G_FUEL_SLOT < (int)extraCollectibleCounts.size() ? extraCollectibleCounts[G_FUEL_SLOT] : 0; + return COLLECTIBLE_SPEED_BALL < (int)extraCollectibleCounts.size() ? extraCollectibleCounts[COLLECTIBLE_SPEED_BALL] : 0; } // 007db8d0 Which seeded variant of Soy Milk and Mutant Spider the G FUEL! stacks give: -1 below two, then one per @@ -512,20 +523,15 @@ int Entity_Player::GetZodiacEffect() // 007a8350 The effects a new room gives back: Holy Mantle's shield (and the Blanket's in a boss room), Taurus's charge // in a room seen for the first time, Whore of Babylon at one red heart (Eve's at two, or always with her Birthright), -// Scapular, the shields Holy Mantle stacks and Holy Card keep, Camo Undies, and the effects of the items that last the -// floor, with the trinkets' room effects (entity_player_trinkets.cpp) in their places. A shield broken in the last room -// is taken away first. The other items with room effects stop the game until reached. +// Empty Vessel without red hearts, Scapular, the shields Holy Mantle stacks and Holy Card keep, Camo Undies, Sol's +// glow once the floor's boss is beaten, and the effects of the items that last the floor, with the trinkets' room +// effects (entity_player_trinkets.cpp) in their places. A shield broken in the last room is taken away first. void Entity_Player::TriggerNewRoom_TemporaryEffects() { - // Empty Vessel and Sol. - constexpr int ROOM_ITEMS[] = {409, 588}; constexpr int CAMO_UNDIES = 497; ItemConfig& items = g_manager->itemConfig; ItemConfig_Item* mantle = items.GetCollectible(COLLECTIBLE_HOLY_MANTLE); - for (int item : ROOM_ITEMS) - if (HasCollectible(item)) - reconstruction_missing("Entity_Player::TriggerNewRoom_TemporaryEffects 007a8350 (room items)"); trinkets_room_enter(*this); if (holyMantleState == 0) @@ -559,6 +565,17 @@ void Entity_Player::TriggerNewRoom_TemporaryEffects() if (redHearts < 2 || isEveAwake) temporaryEffects.AddCollectibleEffect(COLLECTIBLE_WHORE_OF_BABYLON, true, 1); } umbilical_cord_room_enter(*this); + if (HasCollectible(COLLECTIBLE_EMPTY_VESSEL) && !temporaryEffects.HasCollectibleEffect(COLLECTIBLE_EMPTY_VESSEL)) + { + ItemConfig_Item* vessel = items.GetNullItem(NULLITEM_EMPTY_VESSEL); + RemoveCostume(vessel); + if (redHearts < 1) + { + temporaryEffects.AddCollectibleEffect(COLLECTIBLE_EMPTY_VESSEL, true, 1); + AddCostume(vessel, false); + } + if (vessel) temporaryEffects.AddEffect(TemporaryEffect(vessel), true, 1); + } if (ItemConfig_Item* scapular = items.GetCollectible(COLLECTIBLE_SCAPULAR); scapular && HasCollectible(COLLECTIBLE_SCAPULAR)) temporaryEffects.AddEffect(TemporaryEffect(scapular), true, 1); crowns_room_enter(*this); @@ -570,6 +587,15 @@ void Entity_Player::TriggerNewRoom_TemporaryEffects() if (ItemConfig_Item* undies = items.GetCollectible(CAMO_UNDIES); undies && variant == PLAYER_VARIANT_PLAYER && HasCollectible(CAMO_UNDIES)) temporaryEffects.AddEffect(TemporaryEffect(undies), true, 1); + if (HasCollectible(COLLECTIBLE_SOL) && !temporaryEffects.HasNullEffect(NULLITEM_SOL)) + { + ItemConfig_Item* sol = items.GetNullItem(NULLITEM_SOL); + RemoveCostume(sol); + Game& game = *g_game; + bool isBossBeaten = game.lastBossRoomListIdx >= 0 && + (game.roomList[game.lastBossRoomListIdx].flags & ROOM_DESCRIPTOR_FLAG_CLEAR); + if (isBossBeaten && sol) temporaryEffects.AddEffect(TemporaryEffect(sol), true, 1); + } if (!hasCurseMistEffect && !isCoopGhost) for (int id : levelEffectItems) if (ItemConfig_Item* item = items.GetCollectible(id)) @@ -650,9 +676,31 @@ void Entity_Player::SetQueuedItem(const QueueItemData& queued) FlushQueueItem(); queuedItem = queued; ItemConfig_Item* item = queued.item; - bool isGlitchedFuel = item && item->id == -1 && item->type == ITEM_PASSIVE; - if (isGlitchedFuel && g_game->seedEffects.HasSeedEffect(SEED_G_FUEL)) - reconstruction_missing("Entity_Player::SetQueuedItem 0075e050 (the G FUEL! jingle)"); + bool isGlitchedFuel = item && item->id == COLLECTIBLE_GLITCHED_GFUEL && item->type == ITEM_PASSIVE; + if (!isGlitchedFuel || !g_game->seedEffects.HasSeedEffect(SEED_G_FUEL)) return; + + int tier = std::min(g_game->playerManager.GetGFuelCount() / 2, (int)G_FUEL_JINGLES.size() - 1); + const GFuelJingle& jingle = G_FUEL_JINGLES[tier]; + PlayDelayedSFX(jingle.sound, G_FUEL_JINGLE_DELAY, jingle.frameDelay, jingle.volume); +} + +// 007cb5d0 Plays the sound waiting from the last call at once, then keeps a sound to play after a delay, or plays it +// now (through the seeds' fart override) when it has none. +void Entity_Player::PlayDelayedSFX(int sound, int soundDelay, int frameDelay, float volume) +{ + if (delayedSfxId != 0 && delayedSfxDelay > 0) + effect_sound_play(delayedSfxId, {.volume = delayedSfxVolume, .frameDelay = delayedSfxFrameDelay}); + if (soundDelay == 0) + { + effect_sound_play(sound, {.volume = volume}); + volume = 1; + frameDelay = DELAYED_SFX_FRAMES; + sound = 0; + } + delayedSfxId = sound; + delayedSfxVolume = volume; + delayedSfxDelay = soundDelay; + delayedSfxFrameDelay = frameDelay; } // 0075e190 Forgets the queued item, and the held sprite while one is held up. @@ -722,7 +770,7 @@ uint32_t Entity_Player::InvalidateCoPlayerItems() { Entity_Player* owner = other->parent && other->parent->is_player() ? other->parent->ToPlayer() : nullptr; if (!owner && other->variant == PLAYER_VARIANT_COOP_BABY) owner = g_game->GetPlayer(0); - if (owner == this) reconstruction_missing("Entity_Player::InvalidateCoPlayerItems 007584b0 (a co-op player)"); + if (owner == this) other->isCoPlayerItemsInvalid = true; } return (uint32_t)players.playerList.size(); } @@ -804,25 +852,26 @@ void Entity_Player::collectible_unlocks_check(int collectibleId, ItemConfig_Item save.TryUnlock(STARS_UNLOCK.achievement); } -// The pickups, coins, keys, bombs and hearts a collectible gives the first time it is taken. Tainted Bethany takes -// at most six red hearts. Containers past the cap are counted for a reroll to take back first. +// The pickups, coins, keys, bombs and hearts a collectible gives the first time it is taken, a few giving other hearts +// in a versus match. Tainted Bethany takes at most six red hearts. Containers past the cap are counted for a reroll to +// take back first. void Entity_Player::collectible_pickups_add(ItemConfig_Item& item) { - if (g_game->deathmatchManager.is_active()) - reconstruction_missing("Entity_Player::AddCollectible 0075f0e0 (the deathmatch's item changes)"); + HeartGain gain = {.hearts = item.addHearts, .maxHearts = item.addMaxHearts, .soulHearts = item.addSoulHearts}; + if (g_game->deathmatchManager.is_active()) g_game->deathmatchManager.type->item_hearts_adjust(item.id, gain); - int hearts = playerType == PLAYER_BETHANY_B ? std::min(item.addHearts, T_BETHANY_HEART_CAP) : item.addHearts; + int hearts = playerType == PLAYER_BETHANY_B ? std::min(gain.hearts, T_BETHANY_HEART_CAP) : gain.hearts; int maxHeartsBefore = maxHearts; AddBombs(item.addBombs); AddKeys(item.addKeys); AddCoins(item.addCoins); - AddMaxHearts(item.addMaxHearts, false); + AddMaxHearts(gain.maxHearts, false); AddHearts(hearts, false, false); - AddSoulHearts(item.addSoulHearts, false); + AddSoulHearts(gain.soulHearts, false); AddBlackHearts(item.addBlackHearts); HealthType health = GetHealthType(); - int overflow = item.addMaxHearts - maxHearts + maxHeartsBefore; + int overflow = gain.maxHearts - maxHearts + maxHeartsBefore; if ((health == HEALTH_COIN || health == HEALTH_DEFAULT) && overflow > 0) itemHeartsOverflow += overflow; } @@ -1549,8 +1598,9 @@ static void collectible_late_effect_apply(Entity_Player& p, const CollectibleGai // 0075f0e0 Gives the player a collectible: Tainted Jacob's ghost passes it to Jacob, it joins the collection, the // counts and the history, its first pickup gives its pickups and hearts, the unlocks for many items are checked, its // own pickup effect runs, its cache flags are evaluated, transformations count it, and its costume goes on. An active -// takes its slot, and Book of Virtues an empty first one. The history keeps the pool the item came from. Procedural -// items and the pickup effects not written yet stop the game. +// takes its slot, and Book of Virtues an empty first one. The history keeps the pool the item came from. Nothing is +// given while Forget Me Now takes the floor away. Online, an item the versus rules allow joins the next match's pool. +// Procedural items stop the game. void Entity_Player::AddCollectible(int type, int charge, bool isFirstTime, int activeSlot, int varData, int poolType) { Game& game = *g_game; @@ -1559,14 +1609,18 @@ void Entity_Player::AddCollectible(int type, int charge, bool isFirstTime, int a int slot = std::clamp(activeSlot, 0, ACTIVE_SLOT_COUNT - 1); StageTransitionState transition = game.stageTransition.state; - if (transition != STAGE_TRANSITION_NONE && transition != STAGE_TRANSITION_IN && transition != STAGE_TRANSITION_LANDING) - reconstruction_missing("Entity_Player::AddCollectible 0075f0e0 (during a stage transition)"); + if (transition != STAGE_TRANSITION_NONE && game.stageTransition.type == STAGE_TRANSITION_FORGET_ME_NOW && + transition != STAGE_TRANSITION_IN && transition != STAGE_TRANSITION_LANDING) + return; Entity_Player* twin = twin_get(); if (playerType == PLAYER_JACOB2_B && twin && item->type != ITEM_ACTIVE) return twin->AddCollectible(type, charge, isFirstTime, slot, varData, poolType); log_printf(LOG_INFO, "Adding collectible %d (%s) to player %d (%s) from pool %s\n", type, item->GetLocalizedName(LANGUAGE_CURRENT).c_str(), playerIndex, name.c_str(), ""); + DeathmatchManager& versus = game.deathmatchManager; + if (!versus.is_active() && g_manager->netplayManager.is_online() && !versus.type->is_collectible_banned(type)) + versus.type->collectiblePool[type] = true; bool isMainPlayer = variant == PLAYER_VARIANT_PLAYER && !isCoopGhost; if (isMainPlayer) @@ -1575,8 +1629,13 @@ void Entity_Player::AddCollectible(int type, int charge, bool isFirstTime, int a if (isFirstTime) game.itemPool.unkFloat674 = std::min(game.itemPool.unkFloat674, game.itemPool.unkFloat678); } g_manager->persistentGameData.AddToCollection(type); - if (type < 0) reconstruction_missing("Entity_Player::AddCollectible 0075f0e0 (a procedural item)"); - collectibleCounts[type]++; + if (type >= 0) collectibleCounts[type]++; + else + { + glitched_item_add(*this, type); + if (type == COLLECTIBLE_GLITCHED_GFUEL && game.seedEffects.HasSeedEffect(SEED_G_FUEL)) + g_manager->musicManager.targetPitch = game.room->time_scale_update(); + } if (isMainPlayer) { @@ -1629,7 +1688,6 @@ constexpr int NULLITEM_EDEN_HAIR_B = 88; constexpr int NULLITEM_INTRUDER_TRANSCENDENCE = 132; constexpr int COLLECTIBLE_SACK_HEAD_COSTUME = 424; constexpr int COLLECTIBLE_HOLY_GRAIL = 184; -constexpr int SPECIAL_DAILY_COSTUME_PRIORITY = 13; constexpr int DAILY_COSTUME_PRIORITY_BONUS = 3; // Whether a costume is one of Eden's hairs, whose sheet the hair roll picked. @@ -1701,7 +1759,7 @@ void Entity_Player::AddCostume(ItemConfig_Item* item, bool isItemStateOnly) costume.isOverwriteColor = item->costume.isOverwriteColor; costume.isItemStateOnly = isItemStateOnly; costume.playerType = -1; - if (g_game->dailyChallenge.specialDailyId == SPECIAL_DAILY_COSTUME_PRIORITY && item->IsCollectible() && + if (g_game->dailyChallenge.specialDailyId == SPECIAL_DAILY_HALLOWEEN && item->IsCollectible() && item->id == COLLECTIBLE_SACK_HEAD_COSTUME) costume.priority += DAILY_COSTUME_PRIORITY_BONUS; costume.sprite.Load(item->costume.anm2Path, GRAPHICS_DEFER); diff --git a/src/entity_player_kills.cpp b/src/entity_player_kills.cpp index 437b874..cd4eab7 100644 --- a/src/entity_player_kills.cpp +++ b/src/entity_player_kills.cpp @@ -12,9 +12,6 @@ constexpr int COLLECTIBLE_CHARM_OF_THE_VAMPIRE = 62; constexpr int COLLECTIBLE_BERSERK_KILLS = 704; -constexpr int TRINKET_BAT_WING_KILLS = 118; -constexpr int TRINKET_SIGIL_OF_BAPHOMET = 189; -constexpr int SOUND_BOOK_SHADOWS_SIGIL = 1028; // Charm of the Vampire heals every 13 kills, every 8 in a versus match. The heart rises 24 above the player. constexpr int VAMPIRE_KILLS = 13; @@ -101,13 +98,13 @@ static void luck_trinkets_update(Entity_Player& player) // Bat Wing: while it is not flying, one kill in 20 (10 doubled, 7 tripled) gives its flight and wings. static void bat_wing_update(Entity_Player& player) { - int multiplier = player.GetTrinketMultiplier(TRINKET_BAT_WING_KILLS); - if (multiplier <= 0 || player.temporaryEffects.HasTrinketEffect(TRINKET_BAT_WING_KILLS)) return; + int multiplier = player.GetTrinketMultiplier(TRINKET_BAT_WING); + if (multiplier <= 0 || player.temporaryEffects.HasTrinketEffect(TRINKET_BAT_WING)) return; int odds = multiplier == 2 ? BAT_WING_ODDS_DOUBLE : multiplier == 3 ? BAT_WING_ODDS_TRIPLE : BAT_WING_ODDS; - if (player.trinketRNGs[TRINKET_BAT_WING_KILLS].RandomInt(odds) != 0) return; + if (player.trinketRNGs[TRINKET_BAT_WING].RandomInt(odds) != 0) return; - player.temporaryEffects.AddTrinketEffect(TRINKET_BAT_WING_KILLS, true, 1); + player.temporaryEffects.AddTrinketEffect(TRINKET_BAT_WING, true, 1); player.AddCostume(g_manager->itemConfig.GetNullItem(NULLITEM_BATWING_WINGS), false); } @@ -217,9 +214,7 @@ void Entity_Player::trigger_npc_death(Entity* npc) } berserk_update(*this, *npc); - if (!proceduralItems.empty()) - reconstruction_missing("Entity_Player::trigger_npc_death 007a0080: the TMTRAINER kill triggers " - "(trigger_set_dispatch 009e0680)"); + glitched_items_hit_trigger(*this, *npc, CONDITION_ENEMY_KILL); sigil_update(*this); if (killedNpc) g_manager->persistentGameData.AddBestiaryKill(killedNpc->type, killedNpc->variant); diff --git a/src/entity_player_passives.cpp b/src/entity_player_passives.cpp index 8ba3e61..bc727f0 100644 --- a/src/entity_player_passives.cpp +++ b/src/entity_player_passives.cpp @@ -52,7 +52,6 @@ constexpr float AQUARIUS_DAMAGE_SCALE = 0.666f; constexpr float TAURUS_SPEED_STEP = 0.0022222223f; constexpr float TAURUS_SPEED_FULL = 2; constexpr int TAURUS_RAGE_FRAMES = 180; -constexpr float COLOR_UNIT = 0.003921569f; // The tear effects 3 Dollar Bill lends, rolled every 180 frames. constexpr int DOLLAR_BILL_ITEMS[] = {1, 2, 3, 5, 6, 46, 53, 110, 115, 143, 150, 153, 104, @@ -74,24 +73,24 @@ constexpr int INFESTATION_FLIES_MIN = 2; constexpr int INFESTATION_FLIES_RANGE = 5; constexpr int SPIDERBABY_SPIDERS_MIN = 2; constexpr int SPIDERBABY_SPIDERS_RANGE = 4; +// A versus match paces the hit items: Infestation and the Black Bean at most every five seconds, Spiderbaby every one +// and a half (with fewer spiders), Habit's charge every 20 points of damage, Anemic for ten seconds, Missing Page 2 +// once, and the Old Bandage's half heart at half the chance. Virgo's chance grows in steps of luck. +constexpr uint64_t INFESTATION_VERSUS_MS = 5001; +constexpr uint64_t BLACK_BEAN_VERSUS_MS = 5001; +constexpr uint64_t SPIDERBABY_VERSUS_MS = 1501; +constexpr int SPIDERBABY_VERSUS_SPIDERS_MIN = 1; +constexpr int SPIDERBABY_VERSUS_SPIDERS_RANGE = 2; +constexpr int HABIT_VERSUS_DAMAGE = 20; +constexpr int ANEMIC_VERSUS_FRAMES = 300; +constexpr float OLD_BANDAGE_VERSUS_CHANCE = 0.1f; +constexpr int VIRGO_VERSUS_CHANCES[] = {10, 20, 35, 50}; +constexpr float VIRGO_VERSUS_LUCK[] = {4, 7, 10}; constexpr int MISSING_PAGE_HEARTS = 2; constexpr int POLAROID_SHIELD_FRAMES = 150; constexpr int HEART_EFFECT_SCAPULAR = 4; constexpr std::array FANNY_PACK_PICKUPS = {PICKUP_HEART, PICKUP_COIN, PICKUP_KEY, PICKUP_BOMB}; -// The collectible effects these items leave whose frame, stats and hits are written: Book of Shadows (Celtic Cross, -// Virgo, the Polaroid), the Wafer (Cancer), Scapular, the Black Bean, Anemic, Experimental Treatment, Best Bud, Taurus -// and Holy Mantle's shield. -bool is_passive_effect_plain(const TemporaryEffect& effect) -{ - constexpr int PLAIN_PASSIVE_EFFECTS[] = { - COLLECTIBLE_BOOK_OF_SHADOWS, COLLECTIBLE_WAFER, COLLECTIBLE_SCAPULAR, - COLLECTIBLE_BLACK_BEAN, COLLECTIBLE_ANEMIC, COLLECTIBLE_EXPERIMENTAL_TREATMENT, - COLLECTIBLE_BEST_BUD, COLLECTIBLE_TAURUS, COLLECTIBLE_HOLY_MANTLE}; - return effect.item->IsCollectible() && - std::ranges::find(PLAIN_PASSIVE_EFFECTS, effect.item->id) != std::end(PLAIN_PASSIVE_EFFECTS); -} - // 007c9000 Rolls the tear effect 3 Dollar Bill lends, asking for the stats of the old and the new one. void Entity_Player::AddDollarBillEffect() { @@ -144,7 +143,7 @@ static ColorMod invincible_flash_color() else if (random_below(2) == 0) green = blue = FULL; else red = blue = FULL; } - float shade = (float)offset * COLOR_UNIT; + float shade = (float)offset * BYTE_TO_UNIT; return {{red, green, blue, FULL}, {0, 0, 0, 0}, {shade, shade, shade}}; } @@ -392,22 +391,27 @@ static void heart_items_hit(Entity_Player& player) { RNG& bandageRng = player.GetCollectibleRNG(COLLECTIBLE_OLD_BANDAGE); RNG& tailRng = player.GetTrinketRNG(TRINKET_DAEMONS_TAIL); - float bandageChance = OLD_BANDAGE_CHANCE + player.luck * OLD_BANDAGE_LUCK; + bool isVersus = g_game->deathmatchManager.is_active(); + float bandageChance = (isVersus ? OLD_BANDAGE_VERSUS_CHANCE : OLD_BANDAGE_CHANCE) + player.luck * OLD_BANDAGE_LUCK; if (player.HasCollectible(COLLECTIBLE_OLD_BANDAGE) && bandageRng.RandomFloat() <= bandageChance && is_daemons_tail_passed(player, tailRng)) - pickup_drop(player, PICKUP_HEART, HEART_FULL, Random()); + { + uint32_t seed = Random(); + pickup_drop(player, PICKUP_HEART, isVersus ? HEART_HALF : HEART_FULL, seed); + } RNG& gimpyRng = player.GetCollectibleRNG(COLLECTIBLE_GIMPY); if (player.HasCollectible(COLLECTIBLE_GIMPY) && gimpyRng.RandomFloat() <= player.luck * GIMPY_LUCK + GIMPY_CHANCE && is_daemons_tail_passed(player, tailRng)) pickup_drop(player, PICKUP_HEART, HEART_SOUL, Random()); } -// Piggy Bank: one or two pennies spill out (none or one for coin health). +// Piggy Bank: one or two pennies spill out (none or one for coin health or in a versus match). static void piggy_bank_hit(Entity_Player& player) { RNG& rng = player.GetCollectibleRNG(COLLECTIBLE_PIGGY_BANK); - int coins = (int)rng.RandomInt(2) + (player.GetHealthType() == HEALTH_COIN ? 0 : 1); + bool isFewer = player.GetHealthType() == HEALTH_COIN || g_game->deathmatchManager.is_active(); + int coins = (int)rng.RandomInt(2) + (isFewer ? 0 : 1); for (int i = 0; i < coins; i++) { @@ -418,12 +422,14 @@ static void piggy_bank_hit(Entity_Player& player) } } -// Missing Page 2: a hit that brings the player to two hearts or fewer reads the Necronomicon. +// Missing Page 2: a hit that brings the player to two hearts or fewer reads the Necronomicon (once in a versus match). static void missing_page_hit(Entity_Player& player, int amount) { int limit = scale_for_hard_difficulty(MISSING_PAGE_HEARTS); int hearts = player.redHearts + player.boneHearts + player.soulHearts; if (hearts - amount > limit || hearts <= limit) return; + if (g_game->deathmatchManager.is_active() && player.versus.isMissingPage2Used) return; + player.versus.isMissingPage2Used = true; npc_sound_play(SOUND_DEATH_CARD, 1, 2, 1); g_game->itemOverlay.Show(GIANTBOOK_MISSING_PAGE_2, 0, nullptr); @@ -440,37 +446,67 @@ void passives_hit_trigger(Entity_Player& player, int amount) auto has = [&](int id) { return player.HasCollectible(id); }; auto zodiac = [&](int id) { return has(id) || player.GetZodiacEffect() == id; }; - if (isVersus && (has(COLLECTIBLE_INFESTATION) || has(COLLECTIBLE_HABIT) || has(COLLECTIBLE_BLACK_BEAN) || - has(COLLECTIBLE_ANEMIC) || has(COLLECTIBLE_PIGGY_BANK) || has(COLLECTIBLE_SPIDERBABY) || - has(COLLECTIBLE_MISSING_PAGE_2) || zodiac(COLLECTIBLE_VIRGO) || has(COLLECTIBLE_OLD_BANDAGE))) - reconstruction_missing("Entity_Player::TakeDamage 007729d0 (the versus timings of the hit items)"); + VersusPacing& pacing = player.versus; + auto is_ready = [isVersus](uint64_t stampMs, uint64_t cooldownMs) { + return !isVersus || versus_cooldown_is_over(stampMs, cooldownMs); + }; - if (has(COLLECTIBLE_INFESTATION)) + if (has(COLLECTIBLE_INFESTATION) && is_ready(pacing.infestationMs, INFESTATION_VERSUS_MS)) + { player.AddBlueFlies(random_below(INFESTATION_FLIES_RANGE) + INFESTATION_FLIES_MIN, player.pos, nullptr); + pacing.infestationMs = versus_time_get(); + } if (has(COLLECTIBLE_CELTIC_CROSS) && random_below(std::max(1, CELTIC_CROSS_ODDS - (int)(player.luck * CELTIC_CROSS_LUCK))) == 0) effect_lend(player, COLLECTIBLE_BOOK_OF_SHADOWS, COLLECTIBLE_CELTIC_CROSS); if (has(COLLECTIBLE_BEST_BUD)) player.temporaryEffects.AddCollectibleEffect(COLLECTIBLE_BEST_BUD, true, 1); - if (has(COLLECTIBLE_HABIT)) player.AddActiveCharge(1, ACTIVE_SLOT_NONE, false, false, false); - if (has(COLLECTIBLE_BLACK_BEAN)) player.temporaryEffects.AddCollectibleEffect(COLLECTIBLE_BLACK_BEAN, true, 1); - if (has(COLLECTIBLE_ANEMIC)) effect_lend(player, COLLECTIBLE_ANEMIC, COLLECTIBLE_ANEMIC); + if (has(COLLECTIBLE_HABIT)) + { + bool isCharged = !isVersus; + if (isVersus) + { + pacing.habitDamage = (uint8_t)(pacing.habitDamage + amount); + isCharged = pacing.habitDamage >= HABIT_VERSUS_DAMAGE; + if (isCharged) pacing.habitDamage -= HABIT_VERSUS_DAMAGE; + } + if (isCharged) player.AddActiveCharge(1, ACTIVE_SLOT_NONE, false, false, false); + } + if (has(COLLECTIBLE_BLACK_BEAN) && is_ready(pacing.blackBeanMs, BLACK_BEAN_VERSUS_MS)) + { + player.temporaryEffects.AddCollectibleEffect(COLLECTIBLE_BLACK_BEAN, true, 1); + pacing.blackBeanMs = versus_time_get(); + } + if (has(COLLECTIBLE_ANEMIC)) + { + TemporaryEffect anemic(g_manager->itemConfig.GetCollectible(COLLECTIBLE_ANEMIC)); + if (isVersus) anemic.cooldown = ANEMIC_VERSUS_FRAMES; + player.temporaryEffects.AddEffect(anemic, true, 1); + } if (has(COLLECTIBLE_FANNY_PACK)) fanny_pack_hit(player); heart_items_hit(player); if (has(COLLECTIBLE_PIGGY_BANK)) piggy_bank_hit(player); - if (has(COLLECTIBLE_SPIDERBABY)) + if (has(COLLECTIBLE_SPIDERBABY) && is_ready(pacing.spiderbabyMs, SPIDERBABY_VERSUS_MS)) { RNG& rng = player.GetCollectibleRNG(COLLECTIBLE_SPIDERBABY); - int spiders = (int)rng.RandomInt(SPIDERBABY_SPIDERS_RANGE) + SPIDERBABY_SPIDERS_MIN; + int spiders = isVersus ? (int)rng.RandomInt(SPIDERBABY_VERSUS_SPIDERS_RANGE) + SPIDERBABY_VERSUS_SPIDERS_MIN + : (int)rng.RandomInt(SPIDERBABY_SPIDERS_RANGE) + SPIDERBABY_SPIDERS_MIN; Vector spot = room_free_pickup_position_find({.position = player.pos, .isAvoidActiveEntities = true}); for (int i = 0; i < spiders; i++) player.ThrowBlueSpider(spot, Vector{}); + pacing.spiderbabyMs = versus_time_get(); } if (has(COLLECTIBLE_MISSING_PAGE_2)) missing_page_hit(player, amount); if (zodiac(COLLECTIBLE_CANCER)) player.temporaryEffects.AddCollectibleEffect(COLLECTIBLE_WAFER, true, 1); if (zodiac(COLLECTIBLE_VIRGO)) { RNG& rng = player.GetCollectibleRNG(COLLECTIBLE_VIRGO); - if (rng.RandomInt(std::max(1, VIRGO_ODDS - (int)(player.luck * VIRGO_LUCK))) == 0) - player.temporaryEffects.AddCollectibleEffect(COLLECTIBLE_BOOK_OF_SHADOWS, true, 1); + bool isShielded = false; + if (isVersus) + { + int step = (int)std::ranges::count_if(VIRGO_VERSUS_LUCK, [&](float luck) { return player.luck >= luck; }); + isShielded = rng.RandomInt(100) < (uint32_t)VIRGO_VERSUS_CHANCES[step]; + } + else isShielded = rng.RandomInt(std::max(1, VIRGO_ODDS - (int)(player.luck * VIRGO_LUCK))) == 0; + if (isShielded) player.temporaryEffects.AddCollectibleEffect(COLLECTIBLE_BOOK_OF_SHADOWS, true, 1); } } diff --git a/src/entity_player_passives.h b/src/entity_player_passives.h index 008604c..a45ab80 100644 --- a/src/entity_player_passives.h +++ b/src/entity_player_passives.h @@ -13,7 +13,6 @@ constexpr float STUMP_VOLUME_RATE = 0.08f; // The passive collectibles' (1 to 366) pieces other files call: the effects the frame and stats are written for, the // items' frame, the walking items' costumes and the hit, Cursed Eye's teleport and the last heart's saves. -bool is_passive_effect_plain(const TemporaryEffect& effect); void passives_frame_update(Entity_Player& player); void walking_items_animate(Entity_Player& player); void book_of_belial_passive_update(Entity_Player& player); diff --git a/src/entity_player_pills.cpp b/src/entity_player_pills.cpp index a38ef88..951af51 100644 --- a/src/entity_player_pills.cpp +++ b/src/entity_player_pills.cpp @@ -88,9 +88,6 @@ constexpr float LEMON_PARTY_HORSE_SCALE = 2; constexpr float PICKUP_STEP = 40; constexpr float PHEROMONES_ECHO_PITCH = 0.5f; constexpr float PHEROMONES_ECHO_VOLUME = 1.2f; -constexpr float SPIDER_GRID_ORIGIN_X = 40; -constexpr float SPIDER_GRID_ORIGIN_Y = 120; -constexpr float SPIDER_GRID_STEP = 40; constexpr float STAT_COLOR_TINT = 0.3f; constexpr ColorMod HORF_COLOR = {{0.5f, 0.9f, 0.4f, 1}, {0, 0, 0, 0}, {0, 0, 0}}; constexpr ColorMod PARALYSIS_COLOR = {{0.6f, 0.6f, 0.6f, 1}, {0, 0, 0, 0}, {0.4f, 0.4f, 0.4f}}; @@ -558,9 +555,7 @@ static void infested_use(PocketUse& use) GridEntity* grid = room.GetGridEntity(y * room.gridWidth + x); if (!grid || grid->type != GRID_POOP) continue; - Vector position = vector_make((float)(grid->gridIndex % room.gridWidth) * SPIDER_GRID_STEP + SPIDER_GRID_ORIGIN_X, - (float)(grid->gridIndex / room.gridWidth) * SPIDER_GRID_STEP + SPIDER_GRID_ORIGIN_Y); - pill_spiders_spawn(use, position, 1); + pill_spiders_spawn(use, room.GetGridPosition(grid->gridIndex), 1); grid->Destroy(false, EntityRef(&player)); isBurst = true; } @@ -593,14 +588,13 @@ static void power_use(PocketUse& use) player.temporaryEffects.AddCollectibleEffect(COLLECTIBLE_LEO, false, 1); } -// Retro Vision: the screen pixelated for a while, longer for a horse pill. In a versus match only the local player -// would see it, which is not written. +// Retro Vision: the screen pixelated for a while, longer for a horse pill. In a versus match only the local user's +// player sees it, whom netplay names: offline there is no local user, so the pill only animates. static void retro_vision_use(PocketUse& use) { Game& game = *g_game; - if (game.deathmatchManager.is_active()) - reconstruction_missing("Entity_Player::UsePill 007c4180 (Retro Vision's local player in a versus match)"); + if (game.deathmatchManager.is_active()) return pill_animate(use); game.pixelationTimer = std::max(use.isHorse ? RETRO_HORSE_FRAMES : RETRO_FRAMES, game.pixelationTimer); game.pixelationDuration = game.pixelationTimer; pill_animate(use); diff --git a/src/entity_player_pockets.cpp b/src/entity_player_pockets.cpp index 438d063..5db9ea0 100644 --- a/src/entity_player_pockets.cpp +++ b/src/entity_player_pockets.cpp @@ -22,6 +22,10 @@ #include constexpr int CARD_ID_VANILLA_LAST = 97; +// Endless Nameless' odds to copy a used card or pill, by its copies. +constexpr float ENDLESS_NAMELESS_CHANCE = 0.25f; +constexpr float ENDLESS_NAMELESS_CHANCE_DOUBLE = 0.33f; +constexpr float ENDLESS_NAMELESS_CHANCE_TRIPLE = 0.5f; constexpr int PILL_ID_TEARS_UP = 16; constexpr int PILL_ID_GULP = 43; @@ -32,7 +36,6 @@ constexpr int ANNOUNCER_FRAMES_RANDOM = 900; constexpr int ANNOUNCER_FRAMES = 2; constexpr int CHALLENGE_RANDOM_POCKETS = 32; constexpr int COLLECTIBLE_ECHO_CHAMBER = 700; -constexpr int DELAYED_SFX_FRAMES = 2; constexpr int GULP_UNLOCK_USES = 4; constexpr float CARD_HELD_RISE = -12; constexpr float POCKET_DROP_STEP = 40; @@ -227,13 +230,21 @@ static void overlay_frame_set(ANM2& sprite, std::string_view animation, float fr sprite.overlayAnimState.SetFrameFloat(frame); } -// 007ab6b0 Holds a card up: its front from the cards sheet, or the card pickup's own sprite when the sheet has no -// front for it, while the player plays the given animation. A mod's card front is not written yet. +// 007ab6b0 Holds a card up: a mod's card from its own card front sheet, else its front from the cards sheet, or the +// card pickup's own sprite when the sheet has no front for it, while the player plays the given animation. void Entity_Player::AnimateCard(int cardId, std::string_view animName) { ItemConfig_Card* card = g_manager->itemConfig.GetCard(cardId); if (cardId > CARD_ID_VANILLA_LAST && card && card->moddedCardFront) - reconstruction_missing("Entity_Player::AnimateCard 007ab6b0 (a mod's card front)"); + { + heldSprite.Reset(); + heldSprite.Load(card->moddedCardFront->filename, GRAPHICS_LOAD); + heldSprite.Play("Sparkle"); + heldSprite.PlayOverlay(card->hudAnim); + heldSprite.offset = vector_make(0, CARD_HELD_RISE); + PlayExtraAnimation(animName); + return; + } heldSprite.Reset(); heldSprite.Load(CARDS_PILLS_ANM2, GRAPHICS_LOAD); @@ -461,16 +472,10 @@ static void pockets_shift(Entity_Player& player) // 007a3d30 Reads the pocket button: a pocket active is used through its slot, else (when the controls allow and no // item is being used) the first card or pill is used and leaves the pockets (a golden pill only now and then), saving // the rewind state first. The player's familiars may fart for a pill. Jacob and Esau share their buttons. Endless -// Nameless' copies are not written yet. +// Nameless may drop a copy of a card or pill (one time in 4, 3 or 2 by its copies). void Entity_Player::pocket_use_input() { - constexpr int EVENT_PILLS_USED = 6; - constexpr int EVENT_CARDS_USED = 196; - constexpr int COLLECTION_PILL = 43; - constexpr int COLLECTION_CARD = 61; - constexpr int TRINKET_ENDLESS_NAMELESS = 79; constexpr int GOLDEN_PILL_KEEP_CHANCE = 5; - constexpr int PERCENT = 100; Game& game = *g_game; if (game.stageTransition.state != STAGE_TRANSITION_NONE || game.roomTransition.is_active() || IsHologram()) return; @@ -493,7 +498,7 @@ void Entity_Player::pocket_use_input() { if (used.id == CARD_CRACKED_KEY && !is_active_usable(*this, COLLECTIBLE_RED_KEY, -1)) return; save.AddToCollection(COLLECTION_CARD); - save.IncreaseEventCounter(EVENT_CARDS_USED, 1); + save.IncreaseEventCounter(EVENT_COUNTER_CARDS_USED, 1); pockets_shift(*this); TriggerEchoChamber(POCKET_CARD, used.id); UseCard(used.id, USE_OWNED); @@ -509,7 +514,7 @@ void Entity_Player::pocket_use_input() for (Entity* entity : entities_live(g_game->room->GetEntities()->updateEL)) if (entity->IsFamiliar() && static_cast(entity)->player == this) static_cast(entity)->farting_baby_fart(); - save.IncreaseEventCounter(EVENT_PILLS_USED, 1); + save.IncreaseEventCounter(EVENT_COUNTER_PILLS_USED, 1); save.AddToCollection(COLLECTION_PILL); int effect = game.itemPool.GetPillEffect((uint32_t)used.id, this); bool isGoldenKept = (used.id & PILL_COLOR_MASK) == PILL_COLOR_GOLD && @@ -529,7 +534,19 @@ void Entity_Player::pocket_use_input() else ControlActiveItem(used.id - 1); if (HasTrinket(TRINKET_ENDLESS_NAMELESS) && used.type != POCKET_ACTIVE) - reconstruction_missing("Entity_Player::pocket_use_input 007a3d30 (Endless Nameless' copy)"); + { + int copies = GetTrinketMultiplier(TRINKET_ENDLESS_NAMELESS); + float chance = copies == 2 ? ENDLESS_NAMELESS_CHANCE_DOUBLE + : copies == 3 ? ENDLESS_NAMELESS_CHANCE_TRIPLE + : ENDLESS_NAMELESS_CHANCE; + if (GetTrinketRNG(TRINKET_ENDLESS_NAMELESS).RandomFloat() < chance) + { + uint32_t seed = Random(); + Vector spot = room_free_pickup_position_find({.position = pos, .step = PICKUP_SPOT_STEP}); + game.Spawn({.position = spot, .spawner = this, .subType = used.id, .type = ENTITY_PICKUP, + .variant = used.type == POCKET_CARD ? PICKUP_TAROTCARD : PICKUP_PILL, .seed = seed}); + } + } game.hud.refresh_request(HUD_REFRESH_PLAYER); } diff --git a/src/entity_player_poop_spells.cpp b/src/entity_player_poop_spells.cpp index 17ea7cd..7dda747 100644 --- a/src/entity_player_poop_spells.cpp +++ b/src/entity_player_poop_spells.cpp @@ -217,14 +217,12 @@ void hold_use(ItemUse& use) g_manager->sfxManager.Play(sound); } -// Tainted ???'s part of 00794e50: out of a versus match, the damage enemies took this frame charges poop pickups, one -// for each whole point, with a purple fart. +// Tainted ???'s part of 00794e50: the damage dealt this frame (damage_dealt_get) charges poop pickups, one for each +// whole point, with a purple fart. void blue_baby_poop_update(Entity_Player& player) { if (player.playerType != PLAYER_BLUEBABY_B) return; - if (g_game->deathmatchManager.is_active()) - reconstruction_missing("Entity_Player::update_effects 00794e50 (the versus damage dealt)"); - float dealt = g_game->room->entityList.enemyDamageInflicted; + float dealt = damage_dealt_get(player); if (dealt <= 0) return; player.poopSpellCharge += damage_charge_scale() * dealt * POOP_CHARGE_PER_DAMAGE; diff --git a/src/entity_player_room.cpp b/src/entity_player_room.cpp index 62b47d3..1958b9f 100644 --- a/src/entity_player_room.cpp +++ b/src/entity_player_room.cpp @@ -2,6 +2,7 @@ #include "entity_player_passives.h" #include "boss_ai.h" #include "entity_familiar.h" +#include "grid_entity_poop.h" #include "grid_entity_rock.h" #include "room_grid.h" #include "game.h" @@ -27,13 +28,11 @@ constexpr int CHALLENGE_FORGOTTEN_COSTUME = 42; constexpr int BETHS_ESSENCE_WISPS = 5; constexpr int BETHS_ESSENCE_CHANCE_DOUBLE = 50; constexpr int BETHS_ESSENCE_CHANCE_TRIPLE = 100; -constexpr int PERCENT = 100; constexpr int SOUND_BETHS_ESSENCE = 471; constexpr int SOUND_DOG_TOOTH_SECRET = 442; constexpr int SOUND_DOG_TOOTH_ROCK = 441; constexpr int DOG_TOOTH_SECRET_DELAY = 30; constexpr int DOG_TOOTH_ROCK_DELAY = 60; -constexpr int DELAYED_SOUND_FRAMES = 2; constexpr int POKE_GO_CHANCE = 5; constexpr size_t POKE_GO_MESSAGE_SIZE = 256; constexpr int GREED_WAVE_MAX = 12; @@ -91,23 +90,31 @@ static void delayed_sound_queue(Entity_Player& player, int sound, int delay) player.delayedSfxId = sound; player.delayedSfxVolume = 1; player.delayedSfxDelay = delay; - player.delayedSfxFrameDelay = DELAYED_SOUND_FRAMES; + player.delayedSfxFrameDelay = DELAYED_SFX_FRAMES; } // Beth's Essence in an angel room's first visit: five wisps, of the Book of Virtues or (half the time with two copies, -// always with three) a random active item. +// always with three) a random active item that has wisps. static void beths_essence_wisps_add(Entity_Player& player) { int multiplier = player.GetTrinketMultiplier(TRINKET_BETHS_ESSENCE); int chance = multiplier == 2 ? BETHS_ESSENCE_CHANCE_DOUBLE : multiplier == 3 ? BETHS_ESSENCE_CHANCE_TRIPLE : 0; + RNG& rng = player.trinketRNGs[TRINKET_BETHS_ESSENCE]; for (int i = 0; i < BETHS_ESSENCE_WISPS; i++) { - if (chance == 0 || (int)player.trinketRNGs[TRINKET_BETHS_ESSENCE].RandomInt(PERCENT) >= chance) + if (chance == 0 || (int)rng.RandomInt(PERCENT) >= chance) + { player.AddWisp(COLLECTIBLE_BOOK_OF_VIRTUES, player.pos, true, false); - else - reconstruction_missing("Entity_Player::room_enter 007a6c50: Beth's Essence's random active item wisps " - "(the actives with a wisp, ItemConfig_Item +0x190)"); + continue; + } + std::vector actives; + for (int id = 0; id < (int)g_manager->itemConfig.collectibles.size(); id++) + { + ItemConfig_Item* item = g_manager->itemConfig.GetCollectible(id); + if (item && item->type == ITEM_ACTIVE && item->wispConfig && item->wispConfig->count > 0) actives.push_back(id); + } + player.AddWisp(actives[rng.RandomInt((uint32_t)actives.size())], player.pos, true, false); } sound_play(SOUND_BETHS_ESSENCE); } @@ -212,8 +219,7 @@ static void room_items_apply(Entity_Player& player) if (player.variant == PLAYER_VARIANT_COOP_BABY) { player.hasBabyRoomShield = true; - if (player.babySkin == BABY_BOUND) - reconstruction_missing("Entity_Player::room_enter 007a6c50: the co-op baby's follower effect 1000.114"); + if (player.babySkin == BABY_BOUND) player.bound_chain_spawn(); } else if (player.variant == PLAYER_VARIANT_PLAYER && room.isFirstVisit) { @@ -240,15 +246,25 @@ static void room_items_apply(Entity_Player& player) GridEntity* poop = isInside && cell < ROOM_GRID_CELLS ? room.gridEntities[cell] : nullptr; if (poop && poop->type == GRID_POOP && !player.canFly) room.RemoveGridEntity(cell, GRID_PATH_FREED, DECORATION_KEPT); - else if (poop && poop->type == GRID_POOP && poop->variant == 1) - reconstruction_missing("Entity_Player::room_enter 007a6c50: the red poop flown over drops to its last state"); + else if (poop && poop->type == GRID_POOP && poop->variant == POOP_RED) + { + auto* red = static_cast(poop); + red->state = POOP_STATE_BROKEN; + red->reviveTimer = RED_POOP_REVIVE_FRAMES; + red->collisionClass = COLLISION_NONE; + const AnimationData* broken = red->sprite.GetAnimationData("State5"); + if (broken && red->sprite.SetAnimation("State5") && red->sprite.animState.animData) + { + red->sprite.animState.SetFrameFloat((float)broken->length); + red->sprite.animState.isPlaying = false; + } + } } // Friendly enemies following the player in stand within 10 of it (Gurdy, Mega Maw and the Gate at their size), up to // 45 degrees off the way into the room from the door entered (any way after a teleport). Their target moves with them // and their path starts over. The original rounds pi to 3.14 for the random way. The Glowing Hourglass removes the // Blood Puppy. -constexpr float FOLLOWER_PI = 3.14f; constexpr float FOLLOWER_DISTANCE = 10; constexpr float FOLLOWER_TARGET_SET_SQUARED = 3600; constexpr uint32_t FOLLOWER_SPREAD = 90; @@ -260,7 +276,7 @@ static void friendly_followers_place(Entity_Player& player) Room& room = *game.room; uint32_t slot = (uint32_t)game.enterDoor; GridEntity_Door* door = slot < DOOR_SLOT_COUNT ? room.doors[slot] : nullptr; - float randomAngle = random_unit() * FOLLOWER_PI * 2; + float randomAngle = random_unit() * PI_ROUGH * 2; Vector way = vector_make(std::cos(randomAngle), std::sin(randomAngle)); if (door && door->direction >= DIRECTION_LEFT && door->direction <= DIRECTION_DOWN) way = vector_scale(vector_from_direction(door->direction), -1); diff --git a/src/entity_player_tears.cpp b/src/entity_player_tears.cpp index 84a8322..a7cfb6a 100644 --- a/src/entity_player_tears.cpp +++ b/src/entity_player_tears.cpp @@ -5,6 +5,7 @@ #include "log.h" #include "manager.h" #include "npc_ai.h" +#include "room_render.h" #include #include #include @@ -28,7 +29,6 @@ constexpr float JACOB_TEAR_SCALE = 0.9f; constexpr ColorMod LIL_DELIRIUM_COLOR = {{1, 1, 1, 1}, {2.4f, 2.4f, 2.4f, 1}, {0, 0, 0}}; // The chances the items roll: a percent out of a hundred, or one in a denominator that luck lowers. -constexpr int PERCENT = 100; constexpr int TRINKET_PERCENT_ONE = 10; constexpr int TRINKET_PERCENT_TWO = 20; constexpr int TRINKET_PERCENT_MORE = 33; @@ -144,7 +144,6 @@ constexpr int COLLECTIBLE_MUCORMYCOSIS = 553; constexpr int COLLECTIBLE_TERRA = 592; constexpr int COLLECTIBLE_OCULAR_RIFT = 606; constexpr int COLLECTIBLE_LODESTONE = 617; -constexpr int COLLECTIBLE_KNOCKOUT_DROPS = 637; constexpr int COLLECTIBLE_TROPICAMIDE = 659; constexpr int TRINKET_PINKY_EYE = 30; constexpr int TRINKET_PUSH_PIN = 31; @@ -303,7 +302,12 @@ static void familiar_params_apply(Entity_Player& player, TearParams& params, Tea if (player.HasCollectible(COLLECTIBLE_BFFS)) params.tearDamage *= BFFS_DAMAGE; if (player.HasTrinket(TRINKET_BABY_BENDER) && !params.tearFlags[TEAR_HOMING]) - reconstruction_missing("Entity_Player::GetTearHitParams 007bf6c0 (Baby-Bender's familiar tears)"); + { + float fallingSpeed = 0; + float range = 0; + familiar.apply_baby_bender_tear_params(params.tearFlags, params.tearColor, ¶ms.tearHeight, &fallingSpeed, + &range, false); + } else if (familiar.isLilDelirium) { std::copy(std::begin(LIL_DELIRIUM_COLOR._colorize), std::end(LIL_DELIRIUM_COLOR._colorize), @@ -821,6 +825,42 @@ static void mass_knockback_apply(Entity_Player& player, TearParams& params) params.tearVariant = TEAR_CUPID_BLUE; } +// The G FUEL! stacks' tears (part of 007bf6c0): nails in the laser color knocking back at least 3, then the seeded +// variant's own. Mutant Spider's bounce off walls and slow down, the slow variant's are big and strong and bounce too, +// the rapid variant's are weak, and the far variant's are strong, speeding, exploding bloody nails. +static void g_fuel_tears_apply(Entity_Player& player, TearParams& params) +{ + constexpr float G_FUEL_KNOCKBACK = 3; + constexpr float G_FUEL_STRONG_DAMAGE = 4; + constexpr float G_FUEL_RAPID_DAMAGE = 0.6f; + int seeded = player.get_seeded_variant(); + + if (seeded != SEEDED_VARIANT_NONE) + { + params.tearVariant = TEAR_NAIL; + params.knockbackMultiplier = std::max(params.knockbackMultiplier, G_FUEL_KNOCKBACK); + KColor laser = kcolor_apply(player.laserColor, WHITE); + params.tearColor = {{laser._red, laser._green, laser._blue, params.tearColor._tint[TINT_ALPHA]}, {0, 0, 0, 0}, {0, 0, 0}}; + } + switch (seeded) + { + case SEEDED_VARIANT_SLOW: + params.tearScale += params.tearScale; + params.tearDamage *= G_FUEL_STRONG_DAMAGE; + [[fallthrough]]; + case SEEDED_VARIANT_MUTANT_SPIDER: + params.tearFlags.set(TEAR_BOUNCE_WALLSONLY).set(TEAR_DECELERATE); + break; + case SEEDED_VARIANT_RAPID: params.tearDamage *= G_FUEL_RAPID_DAMAGE; break; + case SEEDED_VARIANT_SLOW_FAR: + params.tearDamage *= G_FUEL_STRONG_DAMAGE; + params.tearFlags.set(TEAR_ACCELERATE).set(TEAR_EXPLOSIVE); + params.tearVariant = TEAR_NAIL_BLOOD; + break; + default: break; + } +} + // 007bf6c0 What a tear from the player (or its familiar) is fired with: its stats, flags, color and look from the // items, the eye it leaves from, and a size from its damage. Every item's roll draws in the order the game draws it. TearParams Entity_Player::GetTearHitParams(WeaponType weaponType, float damageScale, int displacement, Entity* source) @@ -873,8 +913,7 @@ TearParams Entity_Player::GetTearHitParams(WeaponType weaponType, float damageSc break; } if (IsHologram()) params.tearColor._tint[TINT_ALPHA] = HOLOGRAM_TEAR_ALPHA; - if (get_seeded_variant() != -1) - reconstruction_missing("Entity_Player::GetTearHitParams 007bf6c0 (the G-Fuel seed's nails)"); + g_fuel_tears_apply(*this, params); NetplayManager& netplay = g_manager->netplayManager; if (netplay.is_online() && !netplay.IsIdxLocalPlayer(controllerIndex) && !g_game->deathmatchManager.is_active()) diff --git a/src/entity_player_trinkets.cpp b/src/entity_player_trinkets.cpp index aba4ee7..d030764 100644 --- a/src/entity_player_trinkets.cpp +++ b/src/entity_player_trinkets.cpp @@ -20,8 +20,10 @@ #include "room.h" #include "room_config.h" #include "room_grid.h" +#include "room_transition.h" #include "sfx_manager.h" #include +#include #include // The trinkets' constants: Rosary Bead's Bible chance, the battery trinkets' achievement, Wooden Cross's mantles @@ -48,9 +50,12 @@ constexpr int BOOSTER_SPECIAL = 25; constexpr int BOOSTER_SUIT_FIRST = 1; constexpr int BOOSTER_SUIT = 5; -// Whether a trinket stays in its slot when a new one is picked up: the Tick, and Rainbow Worm in Pride Day. +// Whether a trinket stays in its slot when a new one is picked up: the Tick, and Rainbow Worm in Pride Day (in a +// versus match every trinket, when its rules keep them). static bool is_trinket_stuck(uint32_t trinket) { + DeathmatchManager& versus = g_game->deathmatchManager; + if (versus.is_active()) return !versus.type->is_trinket_swap_allowed(); return trinket == TRINKET_TICK || (trinket == TRINKET_RAINBOW_WORM && g_game->challenge == CHALLENGE_PRIDE_DAY); } @@ -111,9 +116,6 @@ bool Entity_Player::HasGoldenTrinket(uint32_t trinketId) // Tick (and Rainbow Worm in Pride Day) stay unless the new trinket burns the Tick. bool Entity_Player::TryHoldTrinket(int trinketId) { - if (g_game->deathmatchManager.is_active()) - reconstruction_missing("Entity_Player::TryHoldTrinket 007716f0 (the versus mode)"); - for (int i = 0; i < GetMaxTrinkets(); i++) { uint32_t held = trinkets[i]; @@ -150,9 +152,6 @@ static void moms_toenail_stomp(Vector position, int stomps) Entity_Pickup* Entity_Player::DropTrinket(Vector position, bool isReplaceTick) { FlushQueueItem(); - if (g_game->deathmatchManager.is_active()) - reconstruction_missing("Entity_Player::DropTrinket 00771800 (the versus mode)"); - int slot = -1; for (int i = 0; i < TRINKET_SLOT_COUNT && trinkets[i] != 0; i++) { @@ -325,8 +324,18 @@ void Entity_Player::TriggerTrinketRemoved(uint32_t trinketId) break; case TRINKET_BROKEN_SYRINGE: case TRINKET_MOMS_LOCK: + { + int& lent = id == TRINKET_BROKEN_SYRINGE ? versus.drugEffect : versus.momEffect; + if (!isVersusLost || lent == 0) break; + temporaryEffects.RemoveCollectibleEffect(lent, 1); + lent = 0; + break; + } case TRINKET_THE_TWINS: - if (isVersusLost) reconstruction_missing("Entity_Player::TriggerTrinketRemoved 007adb30 (the versus trinkets)"); + if (!isVersusLost) break; + for (int lent : versus.twinsEffects) + if (g_manager->itemConfig.GetCollectible(lent)) temporaryEffects.RemoveCollectibleEffect(lent, 1); + versus.twinsEffects.clear(); break; case TRINKET_DEVILS_CROWN: Level::update_treasure_room_doors_for_trinket(); break; case TRINKET_MOTHERS_KISS: update_greeds_gullet(); break; @@ -418,8 +427,10 @@ bool Entity_Player::TryRemoveTrinket(uint32_t trinketId) return true; } if (isMain) return TryRemoveSmeltedTrinket(trinketId); - if (!proceduralItems.empty()) reconstruction_missing("Entity_Player::TryRemoveTrinket 00771f60 (a glitched item)"); - return false; + int glitched = glitched_item_copying(*this, ITEM_TRINKET, (int)trinketId); + if (glitched == 0) return false; + RemoveCollectible(glitched, false, 0, true); + return true; } // 007d83f0 Lil Clot's clots: one per copy of the trinket, less those already following, each launched in a random @@ -437,7 +448,7 @@ void Entity_Player::spawn_lil_clot_familiars() for (int i = clots; i < multiplier; i++) { uint32_t seed = Random(); - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; Vector velocity = vector_make(std::cos(angle) * CLOT_LAUNCH_SPEED, std::sin(angle) * CLOT_LAUNCH_SPEED); Entity* clot = g_game->Spawn({.position = pos, .velocity = velocity, .spawner = this, .subType = CLOT_SUBTYPE, @@ -503,8 +514,140 @@ void equality_update(Entity_Player& player) player.EvaluateItems(); } +// Where a Cursed Penny teleport may lead: the room types it draws from, the special rooms it adds, and whether cleared +// (visited) and uncleared (unvisited) rooms count. +struct PennyTeleport +{ + std::vector roomTypes; + std::vector rooms; + bool isClearedAllowed = false; + bool isUnclearedAllowed = false; +}; + +// The ordinary rooms most coins send to, with the Isaac's rooms and the extra ones some add after them. +constexpr int PENNY_ROOMS[] = {ROOM_DEFAULT, ROOM_SHOP, ROOM_TREASURE, ROOM_BOSS, ROOM_MINIBOSS, ROOM_SECRET, + ROOM_SUPERSECRET, ROOM_ARCADE, ROOM_CHALLENGE, ROOM_LIBRARY, ROOM_SACRIFICE}; + +// The rooms a coin's Cursed Penny teleport may lead to, rolled by the coin (a penny, a nickel, a dime, a double, a +// lucky, a sticky or a golden one): better rooms the more Cursed Pennies (25 or 50 more in 100). A dime may open the +// devil or the angel room, others the error room or the black market. +static PennyTeleport penny_teleport_roll(int coin, int bonus, RNG& rng) +{ + auto rooms = [](std::initializer_list extra) { + std::vector types(std::begin(PENNY_ROOMS), std::end(PENNY_ROOMS)); + types.insert(types.end(), extra); + return types; + }; + PennyTeleport teleport; + teleport.isClearedAllowed = coin >= 2 && coin <= 7; + teleport.isUnclearedAllowed = coin >= 1 && coin <= 7; + uint32_t roll = coin >= 1 && coin <= 7 ? rng.RandomInt(100) : 0; + switch (coin) + { + case 1: + if (roll < (uint32_t)bonus + 50) teleport.roomTypes = {ROOM_DEFAULT}; + else + { + teleport.isClearedAllowed = true; + teleport.roomTypes = rooms({ROOM_CHEST, ROOM_DICE, ROOM_BLACK_MARKET, ROOM_PLANETARIUM, ROOM_ISAACS}); + } + break; + case 2: + teleport.roomTypes = roll < (uint32_t)bonus + 50 + ? std::vector{ROOM_SHOP, ROOM_TREASURE, ROOM_ARCADE, ROOM_CHALLENGE, + ROOM_LIBRARY, ROOM_PLANETARIUM} + : std::vector{ROOM_DEFAULT, ROOM_BOSS, ROOM_MINIBOSS, ROOM_SECRET, + ROOM_SUPERSECRET, ROOM_SACRIFICE, ROOM_CHEST, ROOM_DICE, + ROOM_BLACK_MARKET, ROOM_ISAACS}; + break; + case 3: + if (roll < (uint32_t)bonus + 25) + { + bool isAngel = rng.RandomInt(100) < 50; + g_game->InitializeDevilAngelRoom(isAngel, !isAngel); + teleport.rooms = {ROOM_DEVIL_IDX}; + break; + } + teleport.roomTypes = rooms({ROOM_CURSE, ROOM_CHEST, ROOM_DICE, ROOM_PLANETARIUM, ROOM_ISAACS}); + teleport.rooms = {ROOM_ERROR_IDX, ROOM_BLACK_MARKET_IDX}; + break; + case 4: + if (roll < (uint32_t)bonus + 50) teleport.roomTypes = {ROOM_CHEST, ROOM_DICE, ROOM_ISAACS}; + else + { + teleport.roomTypes = rooms({ROOM_PLANETARIUM, ROOM_SECRET, ROOM_SUPERSECRET}); + teleport.rooms = {ROOM_BLACK_MARKET_IDX}; + } + break; + case 5: + if (roll < (uint32_t)bonus + 50) teleport.roomTypes = {ROOM_SECRET, ROOM_SUPERSECRET}; + else + { + teleport.roomTypes = rooms({ROOM_CHEST, ROOM_DICE, ROOM_PLANETARIUM, ROOM_ISAACS}); + teleport.rooms = {ROOM_BLACK_MARKET_IDX}; + } + break; + case 6: + teleport.roomTypes = {roll < 50 ? ROOM_CURSE : ROOM_BOSS}; + break; + case 7: + if (roll < (uint32_t)bonus + 10) teleport.rooms = {ROOM_ERROR_IDX}; + else + { + teleport.roomTypes = rooms({ROOM_PLANETARIUM, ROOM_SECRET, ROOM_SUPERSECRET, ROOM_CHEST, ROOM_DICE, + ROOM_ISAACS}); + teleport.rooms = {ROOM_BLACK_MARKET_IDX}; + } + break; + } + return teleport; +} + +// The floor's rooms in the current dimension of the rolled types, each cell once: a cleared one when cleared rooms +// count, an uncleared one when those do, and only when a visited room's (or an unvisited room's) kind counts too. +static void penny_rooms_add(PennyTeleport& teleport) +{ + Game& game = *g_game; + std::set seen; + for (int index = 0; index < game.nbRooms; index++) + { + RoomDescriptor& room = game.roomList[index]; + if (!room.data || room.dimension != game.currentDimensionIdx) continue; + if (std::ranges::find(teleport.roomTypes, room.data->type) == teleport.roomTypes.end()) continue; + if (!seen.insert(room.gridIndex).second) continue; + + bool isClear = room.flags & ROOM_DESCRIPTOR_FLAG_CLEAR; + bool isAllowed = isClear ? teleport.isClearedAllowed : teleport.isUnclearedAllowed; + bool isVisitAllowed = room.visitedCount != 0 ? teleport.isClearedAllowed : teleport.isUnclearedAllowed; + if (isAllowed && isVisitAllowed) teleport.rooms.push_back(room.gridIndex); + } +} + +// Cursed Penny's teleport after a coin: to a random room of the coin's roll (a sticky coin's curse room falling back +// on the boss room), else as Teleport! does. +static void cursed_penny_teleport(Entity_Player& player) +{ + RNG& rng = player.GetTrinketRNG(TRINKET_CURSED_PENNY); + int copies = player.GetTrinketMultiplier(TRINKET_CURSED_PENNY); + int bonus = copies == 2 ? 25 : copies == 3 ? 50 : 0; + PennyTeleport teleport = penny_teleport_roll(player.cursedPennyPending, bonus, rng); + penny_rooms_add(teleport); + + int target = teleport.rooms.empty() ? 0 : teleport.rooms[rng.RandomInt((uint32_t)teleport.rooms.size())]; + if (player.cursedPennyPending == 6 && teleport.roomTypes.front() == ROOM_CURSE && target == 0) + target = g_game->QueryRoomTypeIndex(ROOM_BOSS, false, rng, false); + if (target == 0) + { + int item = player.GetTrinketMultiplier(TRINKET_BROKEN_REMOTE) <= 1 ? COLLECTIBLE_TELEPORT : COLLECTIBLE_TELEPORT_2; + player.UseActiveItem({.item = item, .flags = USE_NOANIM}); + return; + } + g_game->leaveDoor = -1; + g_game->StartRoomTransition({.player = &player, .animation = TRANSITION_TELEPORT, .roomIndex = target}); +} + // Broken Remote's part of 00782af0: after an active used from the main slot the player teleports (Teleport 2.0's pick -// with more than one copy). Cursed Penny's teleports stop the game. +// with more than one copy). After a coin Cursed Penny teleports it. void trinket_teleports_update(Entity_Player& player) { Game& game = *g_game; @@ -517,8 +660,7 @@ void trinket_teleports_update(Entity_Player& player) int item = player.GetTrinketMultiplier(TRINKET_BROKEN_REMOTE) <= 1 ? COLLECTIBLE_TELEPORT : COLLECTIBLE_TELEPORT_2; player.UseActiveItem({.item = item, .flags = USE_NOANIM}); } - else if (player.cursedPennyPending != 0) - reconstruction_missing("Entity_Player::Update 00782af0 (Cursed Penny's teleport)"); + else if (player.cursedPennyPending != 0) cursed_penny_teleport(player); player.isBrokenRemotePending = false; player.cursedPennyPending = 0; } @@ -537,8 +679,7 @@ void Entity_Player::add_random_drug_item_effect() int id = DRUG_ITEMS[GetTrinketRNG(TRINKET_BROKEN_SYRINGE).Next() & 7]; temporaryEffects.AddEffect(TemporaryEffect(g_manager->itemConfig.GetCollectible(id)), true, 1); - if (g_game->deathmatchManager.is_active()) - reconstruction_missing("Entity_Player::add_random_drug_item_effect 007dbba0 (the versus mode)"); + if (g_game->deathmatchManager.is_active()) versus.drugEffect = id; } // 007dbc80 Mom's Lock lends one of Mom's thirteen collectibles' effects for the room. The versus mode remembers which. @@ -548,8 +689,7 @@ void Entity_Player::AddRandomMomItemEffect() int id = MOM_ITEMS[GetTrinketRNG(TRINKET_MOMS_LOCK).Next() % std::size(MOM_ITEMS)]; temporaryEffects.AddEffect(TemporaryEffect(g_manager->itemConfig.GetCollectible(id)), true, 1); - if (g_game->deathmatchManager.is_active()) - reconstruction_missing("Entity_Player::AddRandomMomItemEffect 007dbc80 (the versus mode)"); + if (g_game->deathmatchManager.is_active()) versus.momEffect = id; } // 007dbe70 Modeling Clay copies only summonable collectibles. @@ -759,8 +899,8 @@ static bool is_pre_ascent_mom_room() return room.roomType == ROOM_BOSS && room.descriptor->data->subtype == BOSS_SUBTYPE_MOM && g_game->IsPreAscent(); } -// The pickup effects of 0075f0e0 for the collectibles 367 on that do more than drop pickups: Mom's Box's Wooden -// Cross and Duct Tape, Tarot Cloth's card, Divorce Papers, Brittle Bones, the Broken Shovel, Luna's secret room, +// The pickup effects of 0075f0e0 for Clear Rune's rune and the collectibles 367 on that do more than drop pickups: +// Mom's Box's Wooden Cross and Duct Tape, Tarot Cloth's card, Divorce Papers, Brittle Bones, the Broken Shovel, Luna's secret room, // Saturnus' tears, the Booster Pack, False PHD, Dad's Note's ascent and TMTRAINER. Camo Undies only acts in versus. void late_collectible_gain(Entity_Player& player, int type, bool isFirstTime) { @@ -772,6 +912,15 @@ void late_collectible_gain(Entity_Player& player, int type, bool isFirstTime) wooden_cross_mantle_add(player); if (player.GetTrinketMultiplier(TRINKET_DUCT_TAPE) > 1 && player.ductTapeMode == 0) player.ductTapeMode = 1; return; + case COLLECTIBLE_CLEAR_RUNE: + if (!isFirstTime) return; + { + int rune = ItemPool::GetCardEx((int)rng.Next(), 0, -1, 0, true); + Vector position = room_free_pickup_position_find({.position = player.pos, .step = GAIN_PICKUP_STEP}); + g_game->Spawn({.position = position, .subType = rune, .type = ENTITY_PICKUP, .variant = PICKUP_TAROTCARD, + .seed = rng.Next()}); + } + return; case COLLECTIBLE_TAROT_CLOTH: if (!isFirstTime) return; { @@ -782,8 +931,7 @@ void late_collectible_gain(Entity_Player& player, int type, bool isFirstTime) } return; case COLLECTIBLE_CAMO_UNDIES: - if (g_game->deathmatchManager.is_active()) - reconstruction_missing("Entity_Player::AddCollectible 0075f0e0 (Camo Undies in versus)"); + if (g_game->deathmatchManager.is_active()) camo_undies_confuse(player); return; case COLLECTIBLE_DIVORCE_PAPERS: if (isFirstTime) divorce_papers_gain(player, rng); @@ -813,8 +961,6 @@ void late_collectible_gain(Entity_Player& player, int type, bool isFirstTime) if (isFirstTime) tmtrainer_gain(player); return; } - reconstruction_missing((std::string("Entity_Player::AddCollectible 0075f0e0 (the pickup effect of ") + - std::to_string(type) + ")").c_str()); } // Purity's pickup in 0075f0e0: a colour is rolled, its aura and glow come on. diff --git a/src/entity_player_update.cpp b/src/entity_player_update.cpp index c7bc540..e13113d 100644 --- a/src/entity_player_update.cpp +++ b/src/entity_player_update.cpp @@ -9,6 +9,9 @@ #include "entity_familiar.h" #include "entity_tear.h" #include "game.h" +#include "grid_entity_poop.h" +#include "music_manager.h" +#include "seeds.h" #include "kage_input.h" #include "key_configs.h" #include "log.h" @@ -79,7 +82,6 @@ constexpr float CAMO_RADIUS = 80; constexpr float CAMO_PLAYER_THRESHOLD = 50; constexpr int SLIPPERY_SLIDE_FRAMES = 60; constexpr float SCHOOLBAG_DROP_STEP = 40; -constexpr int HOW_TO_JUMP_SPECIAL_DAILY = 33; constexpr float BELIAL_FLASH_INTERVAL = 4; constexpr int BELIAL_FLASH_FRAMES = 4; constexpr float BELIAL_BURN_INTERVAL = 2; @@ -142,9 +144,32 @@ constexpr int VOID_HALLUCINATION_BACKDROP = 63; // The damage a bleeding out player takes when its time runs out: red hearts first, through invincibility, with no // modifiers, as the IV Bag's. constexpr uint64_t BLEED_OUT_DAMAGE_FLAGS = DAMAGE_RED_HEARTS | DAMAGE_INVINCIBLE | DAMAGE_IV_BAG | DAMAGE_NO_MODIFIERS; -// The seeds the frame reads: the slippery floor, the music following the player's speed, the tints, the grid's -// footsteps and the timed deaths. -constexpr int FRAME_SEEDS[] = {1, 2, 14, 24, 26, 27, 28, 37, 52, 53}; +// The seeds' part of the frame: the music follows the speed or the health, the poop trail's reach, the damage when +// standing still, every 45 seconds or past 30 minutes, with their warning beeps. +constexpr float SPEED_PITCH_SCALE = 0.1f; +constexpr float SPEED_PITCH_BASE = 0.5f; +constexpr float HEALTH_PITCH_HEARTS = 6; +constexpr float POOP_TRAIL_REACH = 20; +constexpr float POOP_TRAIL_VOLUME = 0.3f; +constexpr int STILL_DAMAGE_GAME_FRAMES = 60; +constexpr int STILL_DAMAGE_ROOM_FRAMES = 10; +constexpr float STILL_SPEED = 0.2f; +constexpr float STILL_MOVEMENT = 0.1f; +constexpr int SEED_DAMAGE_COUNTDOWN = 30; +constexpr int INTERVAL_DAMAGE_FRAMES = 1350; +constexpr int TIME_LIMIT_FRAMES = 54000; +constexpr int WARNING_BEEP_PERIOD = 30; +constexpr int WARNING_BEEP_FAST_PERIOD = 15; +constexpr int INTERVAL_WARNING_FRAMES = 150; +constexpr int TIME_LIMIT_WARNING_FRAMES = 900; +constexpr int TIME_LIMIT_FAST_FRAMES = 300; +constexpr float WARNING_BEEP_QUIET = 0.8f; +constexpr float WARNING_BEEP_PITCH = 4; +constexpr float DEATH_BEEP_PITCH = 8; +constexpr int DEBUG_POOP_MANA = 9; +constexpr ColorMod BLACK_ISAAC_COLOR = {{0, 0, 0, 1}, {0, 0, 0, 0}, {0, 0, 0}}; +constexpr ColorMod INVISIBLE_COLOR = {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0}}; +constexpr ColorMod KAPPA_COLOR = {{1, 1, 1, 1}, {1, 1, 1, 1}, {0, 0, 0}}; // The kept Book of Belial's flash and flames: a red flash, orange flames, and red ones on a shadow's head. constexpr ColorMod BELIAL_FLASH = {{1, 0.8f, 0.8f, 1}, {0, 0, 0, 0}, {0.8f, 0.4f, 0}}; constexpr ColorMod BELIAL_FLAME_COLOR = {{5, 0.5f, 0.2f, 1}, {0, 0, 0, 0}, {0, 0, 0}}; @@ -158,6 +183,12 @@ constexpr ColorMod BLEED_OUT_FLASH = {{1, 0, 0, 1}, {0, 0, 0, 0}, {0, 0, 0}}; // The ghost a hallucination replays: half transparent and greyed (008391a0). constexpr ColorMod TRAIL_COLOR = {{1, 1, 1, 0.5f}, {0.5f, 0.5f, 0.5f, 1}, {0, 0, 0}}; // The status effects the player's head shows, by the entity flag that shows it, first match first. +// A versus player frozen by another's Pause: whitened for a few frames at a time, shown paused, and kept from acting. +constexpr ColorMod VERSUS_PAUSE_COLOR = {{1, 1, 1, 1}, {0, 0, 0, 0}, {0.4f, 0.4f, 0.4f}}; +constexpr int VERSUS_PAUSE_COLOR_FRAMES = 3; +constexpr int VERSUS_PAUSE_COLOR_PRIORITY = -1; +// Camo Undies cloaks a versus player again 15 seconds after its last shot. +constexpr int64_t CAMO_UNDIES_VERSUS_MS = 15000; constexpr std::pair STATUS_EFFECT_ANIMS[] = { {FLAG_CHARM, "Charm"}, {FLAG_CONFUSION, "Confuse"}, {FLAG_BURN, "Burning"}, {FLAG_POISON, "Poison"}, {FLAG_FEAR, "Fear"}, {FLAG_BLEED_OUT, "BleedingOut"}}; @@ -177,12 +208,12 @@ static void hud_update(Entity_Player& player) if (player.playerHUD) player.playerHUD->Update(); } -// 007d4340 Salvation's halo grows a tenth for each room its effect counts, up to twice. -static float salvation_scale_get(Entity_Player& player) +// 007d4340 Salvation's halo grows a tenth for each room its effect counts, up to twice, over its own 1.2. +float salvation_halo_scale_get(Entity_Player& player) { TemporaryEffect* effect = player.temporaryEffects.GetCollectibleEffect(COLLECTIBLE_SALVATION); float count = effect ? (float)effect->count : 0; - return std::clamp(count * SALVATION_GROWTH + 1, 1.0f, SALVATION_SCALE_MAX); + return std::clamp(count * SALVATION_GROWTH + 1, 1.0f, SALVATION_SCALE_MAX) * SALVATION_HALO_SCALE; } // Salvation's halo floats above the player at its size, turning a degree a frame. @@ -191,7 +222,7 @@ static void salvation_halo_update(Entity_Player& player) auto* halo = static_cast(player.salvationEffect.get()); if (!halo) return; - halo->scale = salvation_scale_get(player) * SALVATION_HALO_SCALE; + halo->scale = salvation_halo_scale_get(player); halo->posOffset = vector_make(0, SALVATION_HALO_RISE); float half = player.HasEntityFlags(FLAG_INTERPOLATION_UPDATE) ? 0.5f : 0; halo->sprite.rotation = (float)((g_game->frameCount - player.spawnFrame) % SALVATION_TURN_FRAMES) + half; @@ -278,7 +309,7 @@ static void curse_mist_update(Entity_Player& player) } // The entities that ride on the player: Dad's Ring's halo, Breath of Life's glow above it, Monstrance's and -// Salvation's halos, and the Dark Esau chasing it with its speed. +// Salvation's halos, the Dark Esau chasing it with its speed and Dark Arts' aura. static void riders_update(Entity_Player& player) { if (Entity* aura = player.dadsRingAura) @@ -307,6 +338,11 @@ static void riders_update(Entity_Player& player) esau->pos = player.pos; esau->velocity = player.velocity; } + if (Entity* aura = player.darkArtsAura) + { + aura->pos = player.pos; + aura->velocity = {}; + } } // The poisonous gas (and a static's) builds up on a player standing in it: each frame it hits for nothing adds to the @@ -497,9 +533,10 @@ static void schoolbag_drop_check(Entity_Player& player) g_pickupIgnoreModifiers--; } -// The floor turns slippery under the seed or a slippery flag, the slide lasting a second after it. +// The floor turns slippery under the ice seed or a slippery flag, the slide lasting a second after it. static void slippery_update(Entity_Player& player) { + if (g_game->seedEffects.HasSeedEffect(SEED_ICE_PHYSICS)) player.AddEntityFlags(FLAG_SLIPPERY_PHYSICS); if (player.HasEntityFlags(FLAG_SLIPPERY_PHYSICS)) player.slipperyTimer = SLIPPERY_SLIDE_FRAMES; else player.slipperyTimer = std::max(player.slipperyTimer - 1, 0); } @@ -575,7 +612,7 @@ static void how_to_jump_update(Entity_Player& player) Vector leap = vector_scale(vector_sub(player.targetPosition, player.pos), progress * progress); player.pos = vector_add(player.pos, leap); player.velocity = {}; - if (g_game->dailyChallenge.specialDailyId != HOW_TO_JUMP_SPECIAL_DAILY || jump->cooldown != 1) return; + if (g_game->dailyChallenge.specialDailyId != SPECIAL_DAILY_MAY_13 || jump->cooldown != 1) return; auto* wave = static_cast(g_game->Spawn({.position = player.pos, .spawner = &player, @@ -665,22 +702,30 @@ static void leap_auras_update(Entity_Player& player) } } -// The timers the frame counts down: the hurt, controls, fire and item hold cooldowns, and the co-op babies' buffs, -// each asking for the stats it raised once over. +// The timers the frame counts down: the hurt, controls, fire and item hold cooldowns, a versus player's ramming +// cooldown and Purity's recovery (its aura back in a new colour), and the co-op babies' buffs, each asking for the +// stats it raised once over. static void cooldowns_update(Entity_Player& player) { - constexpr uint32_t BUFF_CACHES[] = {CACHE_DAMAGE, CACHE_FIREDELAY, CACHE_SPEED, CACHE_SHOTSPEED | CACHE_RANGE, - CACHE_LUCK, CACHE_SIZE, CACHE_SIZE}; for (int* cooldown : {&player.damageCooldown, &player.controlsCooldown, &player.fireBlockCooldown, &player.itemHoldCooldown, &player.flashCountdown}) if (*cooldown > 0) (*cooldown)--; - for (size_t buff = 0; buff < std::size(BUFF_CACHES); buff++) + VersusPacing& versus = player.versus; + if (!player.HasEntityFlags(FLAG_INTERPOLATION_UPDATE) && versus.ramCooldown != 0) versus.ramCooldown--; + if (!player.HasEntityFlags(FLAG_INTERPOLATION_UPDATE) && versus.purityHits < 0 && ++versus.purityHits == 0) + { + player.purityState = (int)player.GetCollectibleRNG(COLLECTIBLE_PURITY).RandomInt(PURITY_STATES); + player.temporaryEffects.AddCollectibleEffect(COLLECTIBLE_PURITY, true, 1); + player.AddCostume(g_manager->itemConfig.GetNullItem(NULLITEM_PURITY_GLOW), false); + player.update_purity_glow(); + } + for (size_t buff = 0; buff < std::size(COOP_BUFF_CACHES); buff++) if (player.coopBabyBuffTimers[buff] > 0 && --player.coopBabyBuffTimers[buff] == 0) { - player.cacheFlags |= BUFF_CACHES[buff]; + player.cacheFlags |= COOP_BUFF_CACHES[buff]; player.EvaluateItems(); } - int& last = player.coopBabyBuffTimers[std::size(BUFF_CACHES)]; + int& last = player.coopBabyBuffTimers[COOP_BUFF_BUTT_PENNY]; if (last > 0) last--; } @@ -766,6 +811,101 @@ static void delayed_sound_update(Entity_Player& player) player.delayedSfxId = 0; } +// The debug flag for infinite charges keeps every active full, and Tainted ???'s poop spells at 9. +static void debug_charges_update(Entity_Player& player) +{ + if (!(g_game->debugFlags & DEBUG_INFINITE_CHARGE)) return; + for (int slot = 0; slot < (int)player.activeItems.size(); slot++) + if (player.activeItems[slot].item != 0) player.activeItems[slot].charge = player.GetActiveMaxCharge(slot); + if (player.playerType == PLAYER_BLUEBABY_B) player.poopMana = DEBUG_POOP_MANA; +} + +// A look laid on the player for good and on its sprite: the black, invisible and Kappa seeds'. +static void seed_color_set(Entity_Player& player, const ColorMod& color) +{ + player.SetColor(color, -1, COLOR_PRIORITY_DEFAULT, false, true); + player.sprite.color = color; +} + +// The poop trail seed: a player standing close to the middle of an empty cell (or one with a broken poop, a +// decoration or a web) leaves a poop there, though not in a crawl space. +static void poop_trail_update(Entity_Player& player) +{ + Room& room = *g_game->room; + int gridIndex = room.GetGridIndex(player.pos); + GridEntity* grid = room.GetGridEntity((uint32_t)gridIndex); + bool isPoop = grid && grid->type == GRID_POOP; + bool isBrokenPoop = isPoop && grid->state == POOP_STATE_BROKEN; + bool isWalkable = grid && !isPoop && (grid->type == GRID_DECORATION || grid->type == GRID_SPIDERWEB); + float distance = vector_distance(player.pos, room.GetGridPosition(gridIndex)); + if (distance >= POOP_TRAIL_REACH - player.size * 0.5f || room.roomType == ROOM_DUNGEON) return; + if (grid && !isBrokenPoop && !isWalkable) return; + + room.SpawnGridEntity(gridIndex, GRID_POOP, 0, player.GetCollectibleRNG(COLLECTIBLE_POOP).Next(), 0); + npc_sound_play(SOUND_FART, POOP_TRAIL_VOLUME, 2, 1); +} + +// The seeds' timed hurts beep before they strike: every 30 frames in their warning time, then every 15 more quietly in +// the last 5 seconds (150 frames for the interval's). +static void seed_warning_beep(int left, int warningFrames, int fastFrames) +{ + if (left % WARNING_BEEP_PERIOD == 0 && left <= warningFrames) npc_sound_play(SOUND_DOOR_HEAVY_CLOSE, 1, 0, WARNING_BEEP_PITCH); + else if (left % WARNING_BEEP_FAST_PERIOD == 0 && left <= fastFrames) + npc_sound_play(SOUND_DOOR_HEAVY_CLOSE, WARNING_BEEP_QUIET, 0, WARNING_BEEP_PITCH); +} + +// The seeds' hurts: standing still past the room's first frames (or pushing into a wall), every 45 seconds, and past +// the 30 minute limit once nothing plays. A hurt from the interval or the limit sounds the long beep. +static void seed_damage_update(Entity_Player& player) +{ + Game& game = *g_game; + Seeds& seeds = game.seedEffects; + if (seeds.HasSeedEffect(SEED_DAMAGE_WHEN_STOPPED) && game.frameCount > STILL_DAMAGE_GAME_FRAMES && + game.room->GetFrameCount() > STILL_DAMAGE_ROOM_FRAMES && player.IsExtraAnimationFinished() && + is_transition_idle()) + { + bool isStill = vector_length(player.lastVelocity) < STILL_SPEED && + vector_length(player.recentMovementVector) < STILL_MOVEMENT; + bool isPushing = vector_length(player.lastVelocity) < STILL_SPEED && player.isCollidesWithGrid; + if (isStill || isPushing) player.TakeDamage(1, DAMAGE_TIMER, EntityRef(), SEED_DAMAGE_COUNTDOWN); + } + if (player.HasEntityFlags(FLAG_INTERPOLATION_UPDATE)) return; + + if (seeds.HasSeedEffect(SEED_DAMAGE_ON_INTERVAL)) + { + int left = INTERVAL_DAMAGE_FRAMES - 1 - game.frameCount % INTERVAL_DAMAGE_FRAMES; + if (left == 0) + { + player.TakeDamage(1, DAMAGE_TIMER, EntityRef(), SEED_DAMAGE_COUNTDOWN); + npc_sound_play(SOUND_DOOR_HEAVY_CLOSE, 1, 0, DEATH_BEEP_PITCH); + } + else seed_warning_beep(left, INTERVAL_WARNING_FRAMES, INTERVAL_WARNING_FRAMES); + } + if (!seeds.HasSeedEffect(SEED_DAMAGE_ON_TIME_LIMIT)) return; + int left = TIME_LIMIT_FRAMES - 1 - game.frameCount; + if (left > 0 || !player.IsExtraAnimationFinished()) + return seed_warning_beep(left, TIME_LIMIT_WARNING_FRAMES, TIME_LIMIT_FAST_FRAMES); + if (player.TakeDamage(1, DAMAGE_TIMER, EntityRef(), SEED_DAMAGE_COUNTDOWN)) + npc_sound_play(SOUND_DOOR_HEAVY_CLOSE, 1, 0, DEATH_BEEP_PITCH); +} + +// The seeds' part of the frame: the music's pitch follows the main player's speed or health, the black, invisible +// and Kappa looks, the poop trail and the timed hurts. +static void seeds_update(Entity_Player& player) +{ + Seeds& seeds = g_game->seedEffects; + MusicManager& music = g_manager->musicManager; + if (seeds.HasSeedEffect(SEED_MOVEMENT_PITCH) && player.variant == PLAYER_VARIANT_PLAYER) + music.PitchSlide(vector_length(player.velocity) * SPEED_PITCH_SCALE + SPEED_PITCH_BASE); + if (seeds.HasSeedEffect(SEED_HEALTH_PITCH) && player.variant == PLAYER_VARIANT_PLAYER) + music.PitchSlide((float)(player.redHearts + player.soulHearts) / HEALTH_PITCH_HEARTS); + if (seeds.HasSeedEffect(SEED_BLACK_ISAAC)) seed_color_set(player, BLACK_ISAAC_COLOR); + if (seeds.HasSeedEffect(SEED_INVISIBLE_ISAAC)) seed_color_set(player, INVISIBLE_COLOR); + if (seeds.HasSeedEffect(SEED_KAPPA)) seed_color_set(player, KAPPA_COLOR); + if (seeds.HasSeedEffect(SEED_POOP_TRAIL)) poop_trail_update(player); + seed_damage_update(player); +} + // Bleeding out from its own wound drains the player's time while it has red hearts to lose (more than one, or two // for Keeper's coins, with no soul or bone hearts): out of time it loses a red heart and the time restarts, near the // end it flashes red. With none left to lose the bleeding stops. @@ -821,21 +961,30 @@ static void half_heart_floors_update(Entity_Player& player) if (floors > HALF_HEART_FLOORS) g_manager->persistentGameData.TryUnlock(ACHIEVEMENT_HALF_HEART_FLOORS); } +// Whether a versus player is frozen by another player's Pause. +static bool is_versus_paused(Entity_Player& player) +{ + return player.pauseTimer > 0 && g_game->deathmatchManager.is_active() && player.versusPauseTimer == 0; +} + // The status effect over the player's head, by its first flag: charmed, confused, burning, poisoned, afraid or -// bleeding out, none otherwise. +// bleeding out (and in a versus match slowed or paused), none otherwise. static void status_effect_update(Entity_Player& player) { ANM2& status = player.statusEffectSprite; auto shown = std::ranges::find_if(STATUS_EFFECT_ANIMS, [&](const auto& anim) { return player.HasEntityFlags(anim.first); }); - if (shown == std::end(STATUS_EFFECT_ANIMS)) + std::string_view animation = shown != std::end(STATUS_EFFECT_ANIMS) ? shown->second : ""; + if (animation.empty() && g_game->deathmatchManager.is_active() && player.HasEntityFlags(FLAG_SLOW)) animation = "Slow"; + else if (animation.empty() && is_versus_paused(player)) animation = "Pause"; + if (animation.empty()) { status.Stop(); return; } if (!status.isLoaded) status.Load("gfx/StatusEffects.anm2", GRAPHICS_LOAD); if (status.IsPlaying()) status.Update(); - status.Play(shown->second); + status.Play(animation); } // Records the frame into the room's trail (900 frames at most), and in the Void, every 150 frames, a hallucination @@ -873,12 +1022,23 @@ static void trail_update(Entity_Player& player) if (game.hallucinationTimer > 0 && ghost.current < ghost.frames.size()) ghost.current++; } -// The rest of a frame once alive or dead: the damage multiplier is spent, a co-op ghost passes through enemies in -// the versus mode and over the grid, a hologram touches nothing. +// The rest of a frame once alive or dead: the dashes' after-images fade (all at once on death) and the damage +// multiplier is spent, a co-op ghost passes through enemies in the versus mode and over the grid, a hologram touches +// nothing. static void frame_finish(Entity_Player& player) { - if (!player.HasEntityFlags(FLAG_INTERPOLATION_UPDATE)) player.damageMultiplierStacks = 0; - if (player.isCoopGhost) player.entityGridCollisionClass = GRIDCOLL_WALLS; + if (!player.HasEntityFlags(FLAG_INTERPOLATION_UPDATE)) + { + if (player.isDead) player.afterImageFrames.clear(); + for (AfterImageFrame& image : player.afterImageFrames) image.frames--; + std::erase_if(player.afterImageFrames, [](const AfterImageFrame& image) { return image.frames <= 0; }); + player.damageMultiplierStacks = 0; + } + if (player.isCoopGhost) + { + if (g_game->deathmatchManager.is_active()) player.entityCollisionClass = ENTCOLL_NONE; + player.entityGridCollisionClass = GRIDCOLL_WALLS; + } if (player.IsHologram()) player.entityCollisionClass = ENTCOLL_NONE; } @@ -1004,7 +1164,7 @@ static void montezuma_spray_update(Entity_Player& player) } // The living player's frame: the glitched co-op baby glitches after appearing and then takes a new skin. It walks, -// uses its buttons and shoots, its effects and costumes update, its leaps, charges and timers run, and its body +// uses its buttons and shoots (unless frozen in a versus match by another's Pause or a freeze), its effects and costumes update, its leaps, charges and timers run, and its body // animates. static void living_frame_update(Entity_Player& player) { @@ -1016,12 +1176,20 @@ static void living_frame_update(Entity_Player& player) } player.held_entity_follow(); camo_undies_update(player); - player.update_body_animations(); - player.update_bomb_input(); - player.ControlActiveItem(ACTIVE_SLOT_PRIMARY); - player.pocket_use_input(); - player.update_shooting(); - player.pockets_rotate(); + Room& room = *g_game->room; + bool isFrozen = g_game->deathmatchManager.is_active() && + ((room.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_PAUSE) && player.versusPauseTimer == 0) || + player.freezeCountdown != 0); + if (isFrozen) player.velocity = {}; + else + { + player.update_body_animations(); + player.update_bomb_input(); + player.ControlActiveItem(ACTIVE_SLOT_PRIMARY); + player.pocket_use_input(); + player.update_shooting(); + player.pockets_rotate(); + } players_push_apart(player); if (player.variant == PLAYER_VARIANT_PLAYER && !player.isCoopGhost) { @@ -1082,9 +1250,7 @@ static void extra_player_update(Entity_Player& player) void Entity_Player::Update() { Game& game = *g_game; - if (game.deathmatchManager.is_active()) reconstruction_missing("Entity_Player::Update 00782af0 (the versus mode)"); - if (std::ranges::any_of(FRAME_SEEDS, [&game](int seed) { return game.seedEffects.HasSeedEffect(seed); })) - reconstruction_missing("Entity_Player::Update 00782af0 (the seeds the frame reads)"); + DeathmatchManager& deathmatch = game.deathmatchManager; hud_update(*this); salvation_halo_update(*this); lazarus_twins_update(*this); @@ -1098,6 +1264,7 @@ void Entity_Player::Update() equality_update(*this); if (variant == PLAYER_VARIANT_EXTRA) return extra_player_update(*this); if (!isExists) return; + if (isCoPlayerItemsInvalid) coop_items_sync(); riders_update(*this); speedMultiplier = game.room->GetTimeScale(this); @@ -1105,7 +1272,8 @@ void Entity_Player::Update() if (!HasEntityFlags(FLAG_INTERPOLATION_UPDATE)) { poison_buildup_update(*this); - if (HasEntityFlags(FLAG_POISON) && poisonDamageFrames < 1) ClearEntityFlags(FLAG_POISON); + if (is_versus_paused(*this)) SetColor(VERSUS_PAUSE_COLOR, VERSUS_PAUSE_COLOR_FRAMES, VERSUS_PAUSE_COLOR_PRIORITY, true, true); + if (!deathmatch.is_active() && HasEntityFlags(FLAG_POISON) && poisonDamageFrames < 1) ClearEntityFlags(FLAG_POISON); } Entity::Update(); @@ -1116,6 +1284,7 @@ void Entity_Player::Update() } if (controller_check(*this)) return; if (isPlayingExtraAnimation && sprite.IsFinished()) isPlayingExtraAnimation = false; + if (deathmatch.is_active() && sprite.IsFinished("LightTravel")) isVisible = false; if (isHurtPending && !isPlayingExtraAnimation) { isHurtPending = false; @@ -1134,21 +1303,22 @@ void Entity_Player::Update() trinket_teleports_update(*this); schoolbag_drop_check(*this); book_of_belial_passive_update(*this); + bool isCamoReady = deathmatch.is_active() && variant == PLAYER_VARIANT_PLAYER && HasCollectible(COLLECTIBLE_CAMO_UNDIES) && + !temporaryEffects.HasCollectibleEffect(COLLECTIBLE_CAMO_UNDIES); + if (isCamoReady && (int64_t)versus_time_get() - lastShootTime > CAMO_UNDIES_VERSUS_MS) camo_undies_confuse(*this); slippery_update(*this); lastActionTriggers = 0; - if (!isDead) - { - if (std::string gap = frame_gap(); !gap.empty()) - reconstruction_missing(("Entity_Player::Update 00782af0 (" + gap + ")").c_str()); - living_frame_update(*this); - } + if (!isDead) living_frame_update(*this); else death_update(); item_animations_update(*this); update_footprints(); if (variant == PLAYER_VARIANT_COOP_BABY || isCoopGhost) update_baby_skin_effects(); delayed_sound_update(*this); + debug_charges_update(*this); + seeds_update(*this); + if (HasEntityFlags(FLAG_INTERPOLATION_UPDATE)) ClearEntityFlags(FLAG_APPLY_GRAVITY); if (!HasEntityFlags(FLAG_INTERPOLATION_UPDATE)) ClearEntityFlags(FLAG_SLIPPERY_PHYSICS); if (!HasEntityFlags(FLAG_INTERPOLATION_UPDATE)) bleed_out_update(*this); isHeldItemVisible = IsHeldItemVisible(); @@ -1160,6 +1330,8 @@ void Entity_Player::Update() trail_update(*this); } frame_finish(*this); + if (deathmatch.is_active()) deathmatch.type->player_update(*this); + if (!HasEntityFlags(FLAG_INTERPOLATION_UPDATE)) versus.damageDealt = 0; lua_engine_get().PostPlayerUpdate(this); } diff --git a/src/entity_player_weapons.cpp b/src/entity_player_weapons.cpp index fe43a39..c6756f2 100644 --- a/src/entity_player_weapons.cpp +++ b/src/entity_player_weapons.cpp @@ -5,6 +5,7 @@ #include "weapon_knives.h" #include "entity_laser.h" #include "entity_player.h" +#include "boss_ai.h" #include "entity_tear.h" #include "game.h" #include "log.h" @@ -60,7 +61,8 @@ constexpr int CONJOINED_EXTRA_TEARS = 2; constexpr float WIZ_EYE_ANGLE_MAX = 55; constexpr int MAX_TEARS = 16; constexpr int MAX_EYES = 8; -constexpr int BABY_TECHNOLOGY = 16; +// The Cy co-op baby's shots: one in three also fires a Technology laser along the shot's axis. +constexpr uint32_t CY_BABY_LASER_ODDS = 3; constexpr int BABY_TWENTY_TWENTY = 65; constexpr int PLAYERFORM_CONJOINED = 7; constexpr int PLAYERFORM_BOOKWORM = 10; @@ -171,13 +173,12 @@ void Entity_Player::stop_costume_item_anims() } // 007826d0 What firing does each frame: a shot opens Dead Tooth's ring if none is out and squeezes Large Zit one time -// in three every 30 frames, then the weapon in charge fires, or every weapon does. Offline every player is local, so -// the versus mode's remote players are not written. +// in three every 30 frames, then the weapon in charge fires, or every weapon does. Nothing fires for a player the +// versus rules keep from shooting. void Entity_Player::trigger_fire_item_effects(Vector direction, bool isShotFired) { Game& game = *g_game; - if (game.deathmatchManager.is_active()) - reconstruction_missing("Entity_Player::trigger_fire_item_effects 007826d0 (deathmatch)"); + if (game.deathmatchManager.is_active() && !game.deathmatchManager.type->can_shoot(*this)) return; bool isInterpolated = HasEntityFlags(FLAG_INTERPOLATION_UPDATE); if (HasCollectible(COLLECTIBLE_DEAD_TOOTH) && isShotFired && !deadToothRing) @@ -405,13 +406,13 @@ PosVel Entity_Player::GetMultiShotPositionVelocity(int loopIndex, WeaponType wea // 00790af0 Fires a tear with the player's hit params from a shot (from the player's tear offset when it shoots it // itself): its height, fall, scale, color, range, Stye's slower fall, Dead Eye's (or Dark Arts') glow and an index, -// updated once and moved back a frame. +// updated once and moved back a frame. The Cy co-op baby now and then fires a laser with it. // The Marked target holds no tear back, and extra shots drop the Tractor Beam and end no streak. With Evil Eye, one -// shot in 30 less luck (one in 10 at best) becomes an eye instead. The co-op baby's lasers are not written yet. +// shot in 30 less luck (one in 10 at best) becomes an eye instead. Entity_Tear* Entity_Player::FireTear(const PosVel& shot, uint32_t fireFlags, Entity* source, float damageMultiplier) { - if (variant == PLAYER_VARIANT_COOP_BABY && babySkin == BABY_TECHNOLOGY) - reconstruction_missing("Entity_Player::FireTear 00790af0 (the laser baby)"); + if (variant == PLAYER_VARIANT_COOP_BABY && babySkin == BABY_CY && Random() % CY_BABY_LASER_ODDS == 0) + FireTechLaser({.direction = vector_cardinal(shot.velocity), .position = pos, .isLeftEye = true, .isOneHit = true})->Update(); Vector position = shot.position; if (source && source == this) position = vector_add(position, tearsOffset); diff --git a/src/entity_projectile.cpp b/src/entity_projectile.cpp index 777ba3a..974b678 100644 --- a/src/entity_projectile.cpp +++ b/src/entity_projectile.cpp @@ -149,8 +149,6 @@ constexpr float PEEP_TRAIL_ALPHA = 0.5f; // The splashes: a thrown grid entity's packed subtype, the rock's poof tint and chips, the meat ball's Globin and the // head's gibs. -constexpr int GRID_TYPE_SHIFT = 16; -constexpr int GRID_VARIANT_MASK = 0xffff; constexpr ColorMod ROCK_POOF_COLOR = {{140 / 255.0f, 123 / 255.0f, 123 / 255.0f, 1}, {0, 0, 0, 0}, {0, 0, 0}}; constexpr float ROCK_SOUND_MARGIN = -20; constexpr float ROCK_CHIPS_SCALE = 4; @@ -296,9 +294,6 @@ constexpr float FADEOUT_RATE = 0.1f; constexpr float BOUNCE_FLOOR_SPEED = 2; constexpr float BOUNCE_FLOOR_REBOUND = -2; constexpr float REFLECT_REBOUND = 0.85f; -constexpr int CIRCLE_RNG_SHIFT = 44; -constexpr int CIRCLE_CHANCE = 100; -constexpr int CIRCLE_PROC_MAX = 32; // Hits: a small player lets shots pass over, hats block falling ones, Infamy blocks some, the frozen flash. constexpr float PLAYER_HIT_SCALE_MIN = 0.5f; @@ -2120,9 +2115,6 @@ void Entity_Projectile::fall_update() // a player), flying back the way it came at its height and fall, purple. void Entity_Projectile::circle_reflect() { - constexpr int LIGHT_RING_CIRCLE = 3; - constexpr ColorMod CIRCLE_TEAR_COLOR = {{0.4f, 0.15f, 0.38f, 1}, {0, 0, 0, 0}, {0.2784314f, 0, 0.454902f}}; - for (Entity* entity : entity_query(ENTITY_LASER, LASER_LIGHT_RING)) { auto& ring = *static_cast(entity); diff --git a/src/entity_projectile.h b/src/entity_projectile.h index 302dfbf..d810322 100644 --- a/src/entity_projectile.h +++ b/src/entity_projectile.h @@ -28,6 +28,17 @@ enum ProjectileVariant : int constexpr ColorMod SHOT_COLOR_SICK = {{1, 1, 1, 1}, {1.5f, 2, 1, 1}, {0, 0, 0}}; constexpr ColorMod SHOT_COLOR_SICK_PALE = {{1, 1, 1, 1}, {2.7f, 3, 2, 1}, {0, 0, 0}}; constexpr ColorMod SHOT_COLOR_ROTTEN = {{1, 1, 1, 1}, {3, 2, 1, 1}, {0, 0, 0}}; +// Circle of Protection: one shot in three (rolled from its seed) inside a light ring of the circle subtype turns into +// the ring's player's purple homing tear. +constexpr int CIRCLE_RNG_SHIFT = 44; +constexpr int CIRCLE_CHANCE = 100; +constexpr int CIRCLE_PROC_MAX = 32; +constexpr int LIGHT_RING_CIRCLE = 3; +constexpr ColorMod CIRCLE_TEAR_COLOR = {{0.4f, 0.15f, 0.38f, 1}, {0, 0, 0, 0}, {0.2784314f, 0, 0.454902f}}; +// A thrown grid entity's subtype packs its grid type above its variant. +constexpr int GRID_TYPE_SHIFT = 16; +constexpr int GRID_VARIANT_MASK = 0xffff; + constexpr ColorMod SHOT_COLOR_FIERY = {{1, 1, 1, 1}, {3.5f, 2.5f, 1, 1}, {0, 0, 0}}; // Lua's ProjectileFlags: how a shot flies and what it does when it lands. diff --git a/src/entity_slot.cpp b/src/entity_slot.cpp index f87ca39..ca654e2 100644 --- a/src/entity_slot.cpp +++ b/src/entity_slot.cpp @@ -14,6 +14,7 @@ #include "npc_basement.h" #include "npc_caves.h" #include "persistent_game_data.h" +#include "player_stats.h" #include "room.h" #include "room_config.h" #include "room_grid.h" @@ -1562,6 +1563,39 @@ void Entity_Slot::rotten_beggar_pay(Entity_Player& player, RNG& prizeRng, int co {.position = pos, .source = &player, .radius = ROTTEN_BUTTER_BEAN_RADIUS, .isShowEffect = false}); } +// The Revive Machine's coin: the last coin of its price revives the one ghost, or opens the revive menu for the payer +// when several players are ghosts, and the price rises by 2 a use up to twice the first. Online, the menu opens for the +// payer's device instead. Netplay is offline. +// Its Game counters' helpers (00704b50, 0065d010, 0065d020, 0065d040, 0065d060, 0065d090) are inlined. +void Entity_Slot::revive_machine_pay(Entity_Player& player) +{ + Game& game = *g_game; + + state = SLOT_STATE_IDLE; + if (--game.reviveMachineCoinsLeft < 1) + { + touch = 0; + int ghosts = game.playerManager.GetNumCoopPlayers(); + if (ghosts == 1) + { + npc_sound_play(SOUND_HOLY, 1, 2, 1); + game.playerManager.revive_player_ghosts(); + game.reviveMachineUses++; + Player_stats_add(game.onlinePlayerStats, ONLINE_STAT_REVIVES, &player, 1); + } + else if (ghosts < 2) npc_sound_play(SOUND_THUMBS_DOWN, 1, 2, 1); + else + { + game.revivePlayerMenu.Open(player.controllerIndex); + game.reviveMachineUses++; + } + game.reviveMachineCoinsLeft = std::min(game.reviveMachineUses * 2, REVIVE_MACHINE_COINS) + REVIVE_MACHINE_COINS; + } + revive_counter_show(); + timeout = (int16_t)std::max(0, COIN_FRAMES - touch / TOUCH_SLOWDOWN); + npc_sound_play(SOUND_COIN_SLOT, 1, 2, 1); +} + // Pays out what a slot owes once its payment animation is done, by kind. The payout's pickups are thrown by an RNG // from the slot's, and the Poker Chip multiplies them up to three. void Entity_Slot::payout(Entity_Player& player) @@ -1619,8 +1653,7 @@ void Entity_Slot::payout(Entity_Player& player) rotten_beggar_pay(player, prizeRng, count); break; case SLOT_REVIVE_MACHINE: - if (sprite.overlayAnimState.IsEventTriggered("CoinInsert")) - reconstruction_missing("Entity_Slot::Update 0065d950: the Revive Machine's coin"); + if (sprite.overlayAnimState.IsEventTriggered("CoinInsert")) revive_machine_pay(player); break; default: KAGE_LogMessage(LOG_INFO, (uint8_t*)"Slot type %d is not implemented!\n"); @@ -2160,7 +2193,7 @@ void Entity_Slot::blood_trails_spawn() for (int trail = 0; trail < BLOOD_TRAILS; trail++) { - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float length = random_unit() * BLOOD_TRAIL_RANGE + BLOOD_TRAIL_MIN; Vector step = vector_make(std::cos(angle) * length, std::sin(angle) * length * BLOOD_TRAIL_FLAT); diff --git a/src/entity_slot.h b/src/entity_slot.h index c1e3677..daf4847 100644 --- a/src/entity_slot.h +++ b/src/entity_slot.h @@ -100,6 +100,7 @@ private: void key_master_pay(RNG& prizeRng); void donation_pay(Entity_Player& player); void greed_donation_pay(Entity_Player& player); + void revive_machine_pay(Entity_Player& player); void bomb_bum_pay(Entity_Player& player, RNG& prizeRng, int count); void restock_pay(Entity_Player& player); void battery_bum_pay(Entity_Player& player, RNG& prizeRng, int count); diff --git a/src/entity_status.cpp b/src/entity_status.cpp index d0a11aa..06c2a76 100644 --- a/src/entity_status.cpp +++ b/src/entity_status.cpp @@ -31,7 +31,6 @@ constexpr float POISON_FADE_FRAMES = 200; constexpr float POISON_FADE_OFFSET = 0.1f; constexpr float POISON_TINT_MIN = 0.6f; constexpr float POISON_GLOW = 90; -constexpr float COLOR_STEP = 0.003921569f; constexpr float HALF_SIZE = 0.5f; // Three permanently charmed enemies in a room unlock the Mystery Egg. constexpr int MYSTERY_EGG_CHARMED = 3; @@ -179,7 +178,7 @@ void Entity::AddPoison(const EntityRef& source, int duration, float damage, bool float tint = std::max((POISON_FADE_FRAMES - (float)head.poisonCountdown) / POISON_FADE_FRAMES - POISON_FADE_OFFSET, POISON_TINT_MIN); - float glow = (float)(int)((1 - tint) * POISON_GLOW) * COLOR_STEP; + float glow = (float)(int)((1 - tint) * POISON_GLOW) * BYTE_TO_UNIT; head.SetColor({{tint, 1, tint, 1}, {0, 0, 0, 0}, {0, glow, 0}}, head.poisonCountdown, STATUS_COLOR_PRIORITY, false, true); boss_cooldown_start(head, isIgnoreBossCooldown); diff --git a/src/entity_tear.cpp b/src/entity_tear.cpp index 819112e..0098016 100644 --- a/src/entity_tear.cpp +++ b/src/entity_tear.cpp @@ -197,7 +197,6 @@ constexpr float SPIRAL_SIDE = 10; constexpr float SPIRAL_FORWARD = 20; constexpr float BIG_SPIRAL_RATE = 0.2f; constexpr float BIG_SPIRAL_RADIUS = 15; -constexpr float QUARTER_TURN = 1.5707964f; constexpr float HALF_FRAME = 0.5f; // The creep Mysterious Liquid's and It Hurts' tears leave where they die. @@ -486,6 +485,42 @@ void Entity_Tear::Init(int entityType, int entityVariant, int entitySubType, uin lua_engine_get().PostTearInit(this); } +// Part of 006670f0: in a versus match where someone holds Circle of Protection, one tear in three (rolled from its seed) +// inside another player's circle light ring is removed and comes back as that player's purple homing tear (a plain one +// without a player), at its height and fall. A tear inside several rings comes back from each. +static void versus_circle_reflect(Entity_Tear& tear) +{ + if (!g_game->playerManager.AnyoneHasCollectible(COLLECTIBLE_CIRCLE_OF_PROTECTION)) return; + RNG rng; + rng.SetSeed(tear.initSeed, CIRCLE_RNG_SHIFT); + if ((int)rng.RandomInt(CIRCLE_CHANCE) > CIRCLE_PROC_MAX) return; + + for (Entity* entity : entity_query(ENTITY_LASER, LASER_LIGHT_RING)) + { + auto& ring = *static_cast(entity); + Entity* spawner = ring.spawnerEntity; + auto* player = spawner && spawner->is_player() ? static_cast(spawner) : nullptr; + if (ring.subtype != LIGHT_RING_CIRCLE || tear.spawnerEntity.get() == player) continue; + if (vector_length_squared(vector_sub(tear.pos, ring.pos)) >= ring.radius * ring.radius) continue; + + tear.Remove(); + TearParams params = + player ? player->GetTearHitParams(WEAPON_TEARS, 1, random_below(2) * 2 - 1, nullptr) : TearParams{}; + uint32_t seed = Random(); + auto* back = static_cast(g_game->Spawn({.position = tear.pos, .velocity = vector_scale(tear.velocity, -1), + .spawner = player, .type = ENTITY_TEAR, .seed = seed})); + back->SetHeight(tear.height); + back->fallingSpeed = tear.fallingSpeed; + back->SetCollisionDamage(params.tearDamage); + back->SetTearFlags(TearFlags().set(TEAR_HOMING)); + back->SetScale(params.tearScale); + back->fallingAccel = tear.fallingAccel; + back->SetColor(CIRCLE_TEAR_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); + back->parent = player; + back->Update(); + } +} + // 006670f0 Flies the tear for a frame, or splashes and removes it once it has died (a Chaos Card stuck in a wall // stays). While held it bobs at its parent, while waiting it hovers until its player stops firing, and its flags // steer, grow, shrink, split, link and stick it. @@ -658,8 +693,7 @@ void Entity_Tear::flight_update(float verticalMotion) key_open(); if (isLudovico) scaleFactor *= ludovico_update(); - if (g_game->deathmatchManager.is_active()) - reconstruction_missing("Entity_Tear::Update 006670f0: the versus mode's tear reflections"); + if (g_game->deathmatchManager.is_active()) versus_circle_reflect(*this); fScale = std::max(scaleFactor * baseScale, TEAR_SCALE_MIN); ResetSpriteScale(); fire_update(); @@ -2016,7 +2050,7 @@ static void rerollable_flags_apply(Entity& entity, const TearFlags& flags, Entit } // Holy Light's beam strikes the enemy for three times the hit's damage, its spawner's player (or the first player) -// its parent, with a wide reach. +// its parent, with a wide reach. A versus beam strikes through a player's hit cooldown once. static void holy_light_strike(Entity& entity, Entity* source, float damage) { Entity* spawner = source ? source->GetLastSpawner() : nullptr; @@ -2026,7 +2060,7 @@ static void holy_light_strike(Entity& entity, Entity* source, float damage) beam->parent = player; beam->SetCollisionDamage(damage * HOLY_LIGHT_HIT_SCALE); if (g_game->deathmatchManager.is_active()) - reconstruction_missing("Entity_Tear::ApplyTearFlagEffects 0067af60: Holy Light in versus"); + effect_tear_flags_set(*static_cast(beam), TearFlags().set(TEAR_THROUGH_COOLDOWN)); EntityConfig_Entity* beamConfig = g_manager->entityConfig.GetEntity(ENTITY_EFFECT, EFFECT_CRACK_THE_SKY, 0); beam->SetSize(HOLY_LIGHT_REACH, vector_make(1, 1), beamConfig->gridCollisionPoints); beam->subtype = 1; @@ -2156,9 +2190,6 @@ void Entity_Tear::ApplyTearFlagEffects(Entity* entity, const Vector& position, c if (flags[TEAR_EXTRA_GORE] && isGoreTarget) entity->AddEntityFlags(FLAG_EXTRA_GORE); } -// The rest of Entity_Tear is not reconstructed yet: the split projectiles, Dead Eye, the multidimensional copies, -// the variant change, the links and the rerolls. - // The glow a player's tears fire with: an eighth per Dead Eye charge (up to eight), or a sixteenth per Dark Arts // kill (up to sixteen) when that is more. float dead_eye_glow_get(Entity_Player& player) diff --git a/src/entity_tear_death.cpp b/src/entity_tear_death.cpp index 37cb0f0..0b7f572 100644 --- a/src/entity_tear_death.cpp +++ b/src/entity_tear_death.cpp @@ -148,7 +148,6 @@ constexpr float HAEMO_BURST_FALL_SPREAD = 0.75f; // rise and fuse, and its Tech X rings' radius. constexpr float HAEMO_BOMB_SPEED_MIN = 3; constexpr float HAEMO_BOMB_SPEED_RANGE = 4; -constexpr float HAEMO_BOMB_PI = 3.14f; constexpr float HAEMO_BOMB_SPREAD = 10; constexpr float HAEMO_BOMB_RADIUS = 0.65f; constexpr float HAEMO_BOMB_RISE_MIN = 3; @@ -635,7 +634,7 @@ void Entity_Tear::bone_shards_fire(bool isRising) for (int i = 0; i < BONE_SHARDS; i++) { - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float speed = vector_length(velocity); Vector shardVelocity = vector_make(std::cos(angle) * speed, std::sin(angle) * speed); @@ -688,7 +687,7 @@ static void haemo_bomb_throw(Entity_Tear& tear, Entity_Player& player) { float speed = (random_unit() * HAEMO_BOMB_SPEED_RANGE + HAEMO_BOMB_SPEED_MIN) * player.shotSpeed; Vector velocity = vector_scale(vector_from_angle(random_unit() * TEAR_FULL_TURN), speed); - float angle = random_unit() * HAEMO_BOMB_PI * 2; + float angle = random_unit() * PI_ROUGH * 2; float reach = random_unit() * HAEMO_BOMB_SPREAD; Vector position = vector_make(std::cos(angle) * reach + tear.pos.x, std::sin(angle) * reach + tear.pos.y); diff --git a/src/entity_tear_flags.cpp b/src/entity_tear_flags.cpp index 3f276af..2fbfd6a 100644 --- a/src/entity_tear_flags.cpp +++ b/src/entity_tear_flags.cpp @@ -498,7 +498,7 @@ void Entity_Tear::orbit_update() // The vulnerable enemy a searching tear picks ahead of it, each skipped half the time, scored by its distance plus a // random part: not its spawner's kin, nor marked friendly or untargetable. A homing tear skips the enemies it hit and -// the invisible players, and one colliding with the grid needs a clear line. In versus the other players' familiars +// the invisible players, and one colliding with the grid needs a clear line. In versus the other players' Punching Bags // count too. Entity* homing_target_find(Entity_Tear& tear, bool isFetus) { @@ -525,8 +525,18 @@ Entity* homing_target_find(Entity_Tear& tear, bool isFetus) bestScore = score; } } - if (!isFetus && g_game->deathmatchManager.is_active()) - reconstruction_missing("Entity_Tear::Update 006670f0: homing on the versus mode's familiars"); + if (isFetus || !g_game->deathmatchManager.is_active()) return best; + + for (Entity* bag : entity_query(ENTITY_FAMILIAR, Entity_Familiar::PUNCHING_BAG)) + { + if (bag->IsDescendantOf(tear.spawnerEntity.get())) continue; + float score = vector_length(vector_sub(ahead, bag->pos)) + random_unit() * HOMING_RADIUS; + if (score < bestScore) + { + best = bag; + bestScore = score; + } + } return best; } diff --git a/src/familiar_babies.cpp b/src/familiar_babies.cpp index 10df4a2..a9d02e9 100644 --- a/src/familiar_babies.cpp +++ b/src/familiar_babies.cpp @@ -84,7 +84,6 @@ constexpr int WAVE_RED_LAST_TIMEOUT = 60; // Acid Baby's answer to a pill: poison on every enemy and a green cloud. constexpr float ACID_BABY_DAMAGE = 10; -constexpr int ACID_BABY_HIT_COUNTDOWN = 30; constexpr int ACID_BABY_POISON_FRAMES = 150; constexpr ColorMod ACID_BABY_POOF = {{1, 1, 1, 0.5f}, {0.6f, 1, 0.3f, 1}, {0, 0, 0}}; @@ -512,7 +511,7 @@ void Entity_Familiar::farting_baby_fart() for (Entity* enemy : entities_live(g_game->room->entityList.updateEL)) { if (!enemy->IsActiveEnemy(DEAD_EXCLUDED) || IsDescendantOf(enemy)) continue; - enemy->TakeDamage(ACID_BABY_DAMAGE, 0, EntityRef(this), ACID_BABY_HIT_COUNTDOWN); + enemy->TakeDamage(ACID_BABY_DAMAGE, 0, EntityRef(this), HIT_COUNTDOWN); enemy->AddPoison(EntityRef(this), ACID_BABY_POISON_FRAMES, 0, false); } sprite.Play("Spawn"); @@ -781,9 +780,9 @@ static void minisaac_death(Entity_Familiar& minisaac) ->sprite.Play("Poof_Small"); for (uint32_t drops = (Random() & 1) + 1; drops > 0; drops--) { - float turn = random_unit() * RANDOM_HALF_TURN * 2; + float turn = random_unit() * PI_ROUGH * 2; Vector spot = vector_add(minisaac.pos, vector_scale(vector_make(std::cos(turn), std::sin(turn)), minisaac.size * HALF)); - float fling = random_unit() * RANDOM_HALF_TURN * 2; + float fling = random_unit() * PI_ROUGH * 2; float speed = random_unit() * MINISAAC_DROP_SPEED_RANGE + 1; Vector velocity = vector_scale(vector_make(std::cos(fling), std::sin(fling)), speed); g_game->Spawn({.position = spot, .velocity = velocity, .type = ENTITY_EFFECT, .variant = EFFECT_BLOOD_PARTICLE, diff --git a/src/familiar_clot.cpp b/src/familiar_clot.cpp index 057d8cd..a8e2132 100644 --- a/src/familiar_clot.cpp +++ b/src/familiar_clot.cpp @@ -101,7 +101,6 @@ constexpr float CLOT_DRIP_SIZE_RANGE = 0.3f; constexpr float CLOT_LIFT = -8; constexpr float CLOT_HIT_RADIUS = 20; constexpr float CLOT_HIT_SCALE = 3; -constexpr int CLOT_HIT_COUNTDOWN = 30; constexpr float CLOT_HOME_SPEED = 20; constexpr float CLOT_HOME_MARGIN = 2; constexpr float CLOT_HOME_REACH = 10; @@ -415,7 +414,7 @@ static void clot_fly(Entity_Familiar& clot) continue; hit_list_insert(clot.hitList, *enemy); - enemy->TakeDamage(clot.player->meleeDamage * CLOT_HIT_SCALE, 0, EntityRef(&clot), CLOT_HIT_COUNTDOWN); + enemy->TakeDamage(clot.player->meleeDamage * CLOT_HIT_SCALE, 0, EntityRef(&clot), HIT_COUNTDOWN); } float pull = (float)(clot.state++ - 1); diff --git a/src/familiar_collision.cpp b/src/familiar_collision.cpp index 27c41e4..1dcfd05 100644 --- a/src/familiar_collision.cpp +++ b/src/familiar_collision.cpp @@ -26,7 +26,6 @@ constexpr int POOTER_SUPER = 2; constexpr int CONTACT_VARIANTS[] = {33, 60, 15, 14, 79, 77, 3, 104, 44, 45, 46, 47, 32, 83, 121, 126, 226, 224, 210, 218, 206, 237, 229, 204}; -// The familiars whose block or hit has an effect of its own not reconstructed yet. // The hit Tinytoma takes from each shot it stops. constexpr float TINYTOMA_SHOT_HURT = 3.5f; @@ -163,7 +162,6 @@ constexpr float DIP_SLOWING = 0.9f; constexpr ColorMod DIP_SLOW_COLOR = {{0.2f, 0.2f, 0.2f, 1}, {0, 0, 0, 0}, {0, 0, 0}}; constexpr float DIP_BURN_DAMAGE = 3.5f; constexpr float DIP_THROWN_DAMAGE = 7; -constexpr int DIP_HIT_COUNTDOWN = 30; constexpr float DIP_BOUNCE = 10; constexpr float DIP_RECOIL = 3; @@ -175,7 +173,6 @@ constexpr int DIP_HURT_DELAY = 15; constexpr int VERSUS_BAG_COUNTDOWN = 4; constexpr int LEECH_HEAL_DAMAGE = 50; constexpr float LEECH_HEART_LIFT = -24; -constexpr int MILK_HIT_COUNTDOWN = 30; // The familiars that never yield to what they touch, unless it is a player or a bomb. constexpr int SOLID_VARIANTS[] = {62, 67, 228, 238}; @@ -612,13 +609,13 @@ static bool dip_touch(Entity_Familiar& dip, Entity& enemy, float damageMultiplie dip.headFrameDelay = 1; } } - if (dip.damageCountdown <= 0) enemy.TakeDamage(damage * damageMultiplier, damageFlags, source, DIP_HIT_COUNTDOWN); + if (dip.damageCountdown <= 0) enemy.TakeDamage(damage * damageMultiplier, damageFlags, source, HIT_COUNTDOWN); Vector away = vector_normalized(vector_sub(enemy.pos, dip.pos)); enemy.AddVelocity_divided(vector_scale(away, DIP_BOUNCE), true); dip.AddVelocity_divided(vector_scale(away, -DIP_RECOIL), true); if (enemy.collisionDamage > 0 && dip.damageCountdown <= 0) - dip.TakeDamage(TINYTOMA_SHOT_HURT, 0, EntityRef(&enemy), DIP_HIT_COUNTDOWN); + dip.TakeDamage(TINYTOMA_SHOT_HURT, 0, EntityRef(&enemy), HIT_COUNTDOWN); return true; } @@ -773,7 +770,7 @@ bool Entity_Familiar::TakeDamage(float damage, uint64_t damageFlags, const Entit if (variant == MILK) { if ((uint32_t)subtype < (uint32_t)maxSubtype && (uint32_t)++subtype == (uint32_t)maxSubtype) sprite.Play("Drop"); - this->damageCountdown = MILK_HIT_COUNTDOWN; + this->damageCountdown = HIT_COUNTDOWN; health += damage; } return isDamaged; @@ -822,7 +819,7 @@ static void dip_death(Entity_Familiar& dip) auto scatter = [&dip](int variant, int subtype) { uint32_t seed = dip.dropRNG.Next(); - float turn = random_unit() * RANDOM_HALF_TURN * 2; + float turn = random_unit() * PI_ROUGH * 2; g_game->Spawn({.position = dip.pos, .velocity = vector_scale(vector_make(std::cos(turn), std::sin(turn)), DIP_DROP_SPEED), .spawner = &dip, diff --git a/src/familiar_dip.cpp b/src/familiar_dip.cpp index f2cc5ec..2af405c 100644 --- a/src/familiar_dip.cpp +++ b/src/familiar_dip.cpp @@ -227,7 +227,7 @@ static void dip_scoot(Entity_Familiar& dip, float speedScale) else if (dip.subtype == DIP_SUBTYPE_RED) speedScale = DIP_RED_CHARGE; Vector heading = vector_is_zero(vector_sub(destination, dip.pos)) - ? vector_from_angle(random_unit() * RANDOM_HALF_TURN * 2 * RADIANS_TO_DEGREES) + ? vector_from_angle(random_unit() * PI_ROUGH * 2 * RADIANS_TO_DEGREES) : vector_normalized(vector_sub(destination, dip.pos)); float speed = random_unit() * DIP_SCOOT_SPEED + DIP_SCOOT_SPEED; dip.velocity = vector_add(dip.velocity, vector_scale(heading, speed * speedScale / dip.friction)); diff --git a/src/familiar_follow.cpp b/src/familiar_follow.cpp index 887473a..006de2a 100644 --- a/src/familiar_follow.cpp +++ b/src/familiar_follow.cpp @@ -78,7 +78,6 @@ constexpr float MY_SHADOW_PULL = 0.5f; constexpr float RIDE_SPREAD_BASE = 5; constexpr float RIDE_SPREAD_BFFS = 1.5f; constexpr float RIDE_SIZE_SHARE = 0.3f; -constexpr float RIDE_HALF_TURN = 3.14f; constexpr uint32_t RIDE_SEED_SHIFT = 35; constexpr uint32_t RIDE_ANGLE_SHIFT = 18; constexpr int RIDE_STRAIGHT_VARIANTS[] = {213, 214, 223}; @@ -125,7 +124,6 @@ constexpr int WISP_UNICORN_STUMP = 298; constexpr float WIDE_WISP_SPEED = 2; constexpr float BIG_FAN_SPEED = 1.0f / 3; constexpr float BEST_BUD_SPEED = 3; -constexpr float TWO_PI = 6.2831855f; // The orbitals that turn their sprite with the orbit. constexpr int SACRIFICIAL_DAGGER_ROTATION_FRAME = 6; @@ -246,7 +244,7 @@ static void ride_gello(Entity_Familiar& rider) seedRng.SetSeed(rider.initSeed, RIDE_SEED_SHIFT); RNG angleRng; angleRng.SetSeed(seedRng.Next(), RIDE_ANGLE_SHIFT); - float turn = angleRng.RandomFloat() * RIDE_HALF_TURN; + float turn = angleRng.RandomFloat() * PI_ROUGH; float reach = gello->size * RIDE_SIZE_SHARE + spread; Vector offset = vector_make(std::cos(turn + turn) * reach, std::sin(turn + turn) * reach); if (familiar_listed(RIDE_STRAIGHT_VARIANTS, rider.variant)) offset = vector_make(gello->size * RIDE_SIZE_SHARE, 0); @@ -734,7 +732,7 @@ static Vector blood_puppy_spot() { if (vector_length_squared(vector_sub(game_nearest_player(spot)->pos, spot)) >= BLOOD_PUPPY_SPOT_DISTANCE_SQUARED) break; - float turn = random_unit() * RANDOM_HALF_TURN * 2; + float turn = random_unit() * PI_ROUGH * 2; Vector around = vector_add(Room::GetCenterPos(), vector_scale(vector_make(std::cos(turn), std::sin(turn)), BLOOD_PUPPY_SPOT_RADIUS)); spot = room_free_pickup_position_find( @@ -801,7 +799,7 @@ void Entity_Familiar::RecalculateOrbitOffset(int layer, OrbitChange change) for (size_t i = 0; i < orbiters.size(); i++) { Entity_Familiar& orbiter = *orbiters[i]; - orbiter.orbitAngleOffset = (float)i * TWO_PI / (float)orbiters.size(); + orbiter.orbitAngleOffset = (float)i * TAU / (float)orbiters.size(); float speed = player->HasCollectible(COLLECTIBLE_GUARDIAN_ANGEL) ? entry.guardianAngelSpeed * entry.speed : entry.speed; orbiter.orbitSpeed = speed * speedScale; @@ -843,7 +841,7 @@ Vector Entity_Familiar::GetOrbitPosition(const Vector& center) if (!vector_is_zero(formationOffset)) reset_follow_target(); float phase = (float)(g_manager->framecount % 2) * 0.5f + (float)g_game->frameCount; - float angle = std::fmod(orbitAngleOffset - phase * orbitSpeed * PI_F * 0.5f, TWO_PI); + float angle = std::fmod(orbitAngleOffset - phase * orbitSpeed * PI_F * 0.5f, TAU); if (variant == SACRIFICIAL_DAGGER) { if (sprite.SetAnimation("Rotation", SWITCH_KEEP_FRAME) && sprite.animState.animData) @@ -907,7 +905,7 @@ void Entity_Familiar::MoveDiagonally(float speed) } if (vector_is_zero(velocity)) { - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; velocity = vector_make(std::cos(angle) * DIAGONAL_KICK, std::sin(angle) * DIAGONAL_KICK); return; diff --git a/src/familiar_gello.cpp b/src/familiar_gello.cpp index 1122504..1754a55 100644 --- a/src/familiar_gello.cpp +++ b/src/familiar_gello.cpp @@ -85,7 +85,6 @@ constexpr float CORD_REFLECT_HEIGHT = -50; constexpr float CORD_GRID_RADIUS = 20; constexpr float CORD_FIREPLACE_DAMAGE = 1000; constexpr int CORD_FIREPLACE_HIT_VARIANT = 11; -constexpr int CORD_HIT_COUNTDOWN = 30; constexpr float CORD_KNOCKBACK = 900; constexpr float CORD_KNOCKBACK_MASS = 50; constexpr float CORD_NEAREST_START = 1000000; @@ -416,7 +415,7 @@ static void cord_enemy_hit(Entity_Familiar& gello, UmbilicalBabyData& data, Enti owner.numBlueFlies <= CORD_FLY_LIMIT) damageFlags = DAMAGE_SPAWN_FLY; if (gello.HasEntityFlags(FLAG_BLEED_OUT)) damageFlags |= DAMAGE_SPAWN_TEMP_HEART; - if (enemy.TakeDamage(strike.damage, damageFlags, EntityRef(&owner), CORD_HIT_COUNTDOWN) && + if (enemy.TakeDamage(strike.damage, damageFlags, EntityRef(&owner), HIT_COUNTDOWN) && enemy.IsVulnerableEnemy(nullptr)) { int sound = SOUND_MEATY_DEATHS; @@ -526,7 +525,7 @@ static void gello_fling_hits(Entity_Familiar& gello, UmbilicalBabyData& data) if (entity->type != ENTITY_POOP && entity->type != ENTITY_MOVABLE_TNT) hit_list_insert(gello.hitList, *entity); if (entity->type == ENTITY_FIREPLACE && entity->variant != CORD_FIREPLACE_HIT_VARIANT) - entity->TakeDamage(CORD_FIREPLACE_DAMAGE, 0, EntityRef(gello.parent.get()), CORD_HIT_COUNTDOWN); + entity->TakeDamage(CORD_FIREPLACE_DAMAGE, 0, EntityRef(gello.parent.get()), HIT_COUNTDOWN); else if (entity->type == ENTITY_FROZEN_ENEMY) Entity::ForceCollide(&owner, entity, true); else if (entity->type != ENTITY_SHOPKEEPER) cord_enemy_hit(gello, data, *entity, strike); } diff --git a/src/familiar_locust.cpp b/src/familiar_locust.cpp index 29611ab..da71f4b 100644 --- a/src/familiar_locust.cpp +++ b/src/familiar_locust.cpp @@ -78,7 +78,6 @@ constexpr int APOLLYONS_BEST_FRIEND_QUALITY = 3; constexpr float MULTIPLIER_DAMAGE_STEP = 0.25f; constexpr float MULTIPLIER_DAMAGE_BASE = 0.75f; constexpr float LOCUST_PUSH = 1.8f; -constexpr int LOCUST_HIT_COUNTDOWN = 30; // The flight: its speed per config speed, the margin it launches inside the room, how the player's motion carries it, // how it bends toward a homing target (every four frames, within 128, odds and noise), how it returns and slows, @@ -614,7 +613,7 @@ void locust_update(Entity_Familiar& locust) if (locust.state == 0) { locust.velocity = vector_scale(locust.velocity, CHASE_DRAG); - float angle = random_unit() * RANDOM_HALF_TURN * 2; + float angle = random_unit() * PI_ROUGH * 2; Vector pull = vector_scale(vector_sub(player.pos, locust.pos), LOCUST_SWARM_PULL); Vector heading = vector_normalized(vector_add(vector_make(std::cos(angle), std::sin(angle)), pull)); float speed = random_unit() * SWARM_SPEED_RANGE + SWARM_SPEED_MIN; @@ -749,7 +748,7 @@ static void locust_hit_effects(Entity_Familiar& locust, const TearFlags& flags, shardFlags.reset(TEAR_BONE_FLAG).reset(TEAR_LUDOVICO); for (int i = 0; i < LOCUST_BONE_SHARDS; i++) { - float angle = random_unit() * RANDOM_HALF_TURN * 2; + float angle = random_unit() * PI_ROUGH * 2; Vector velocity = vector_make(std::cos(angle) * BONE_SHARD_SPEED, std::sin(angle) * BONE_SHARD_SPEED); auto* shard = static_cast(g_game->Spawn({.position = vector_sub(locust.pos, locust.velocity), .velocity = velocity, @@ -887,7 +886,7 @@ void locust_touch(Entity_Familiar& locust, Entity& enemy) damage = damage * locust.player->damage + (float)data.hunger * HUNGER_DAMAGE; uint64_t damageFlags = tear_damage_flags_get(flags, &locust); - enemy.TakeDamage(damage, damageFlags, EntityRef(&locust), LOCUST_HIT_COUNTDOWN); + enemy.TakeDamage(damage, damageFlags, EntityRef(&locust), HIT_COUNTDOWN); Entity_Tear::ApplyTearFlagEffects(&enemy, locust.pos, flags, &locust, damage); locust_hit_effects(locust, flags, locustFlags, enemy); if (locust.fireCooldown == -1 && !flags[TEAR_PIERCING]) locust.fireCooldown = -2; diff --git a/src/familiar_repentance.cpp b/src/familiar_repentance.cpp index a848924..2f78109 100644 --- a/src/familiar_repentance.cpp +++ b/src/familiar_repentance.cpp @@ -483,10 +483,10 @@ bool tinytoma_death(Entity_Familiar& tinytoma) splat->Update(); for (uint32_t i = Random() % TINYTOMA_GIBS_RANGE + TINYTOMA_GIBS_MIN; i > 0; i--) { - float angle = random_unit() * RANDOM_HALF_TURN * 2; + float angle = random_unit() * PI_ROUGH * 2; Vector spot = vector_add(tinytoma.pos, vector_scale(vector_make(std::cos(angle), std::sin(angle)), tinytoma.size / 2)); - float heading = random_unit() * RANDOM_HALF_TURN * 2; + float heading = random_unit() * PI_ROUGH * 2; float speed = random_unit() * TINYTOMA_GIB_SPEED_RANGE + TINYTOMA_GIB_SPEED_MIN; Entity* gib = g_game->Spawn({.position = spot, .velocity = vector_make(std::cos(heading) * speed, std::sin(heading) * speed), @@ -512,7 +512,7 @@ bool tinytoma_death(Entity_Familiar& tinytoma) for (int i = 0; i < TINYTOMA_PIECES; i++) { uint32_t seed = Random(); - float angle = random_unit() * RANDOM_HALF_TURN * 2; + float angle = random_unit() * PI_ROUGH * 2; Vector spot = vector_add( tinytoma.pos, vector_scale(vector_make(std::cos(angle), std::sin(angle)), TINYTOMA_PIECE_SPREAD)); Entity* piece = g_game->Spawn({.position = spot, @@ -1443,7 +1443,7 @@ enum DamoclesState // Part of 00644e80: a burst of the player's blood around them, a few particles drifting and the rest flung as gibs. static void damocles_burst(Entity_Player& player) { - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float speed = random_unit() * DAMOCLES_BURST_SPEED_RANGE + DAMOCLES_BURST_SPEED_MIN; Vector burst = vector_scale(vector_make(std::cos(angle), std::sin(angle)), speed); @@ -1500,7 +1500,6 @@ static void damocles_fall(Entity_Familiar& damocles) // apart, Gideon's growth and the other bosses' health share, three frames without a copy before its reward, its // reward kept off the cell 80 above the room's centre in steps of 10, and There's Options' item 24 beside it. constexpr float TWIN_GIDEON_DROP = 100; -constexpr float TWIN_HALF_TURN = 3.14f; constexpr float TWIN_NUDGE_SPREAD = 15; constexpr float TWIN_NUDGE_MIN = 15; constexpr float TWIN_GLIDE = 0.1f; @@ -1566,7 +1565,7 @@ static void vanishing_twin_settle(Entity_Familiar& twin) other->targetPosition.y != twin.targetPosition.y) continue; - float half = random_unit() * TWIN_HALF_TURN; + float half = random_unit() * PI_ROUGH; float angle = half + half; float sine = std::sin(angle); float distance = random_unit() * TWIN_NUDGE_SPREAD + TWIN_NUDGE_MIN; @@ -1679,7 +1678,7 @@ static Vector twin_spot_same(Vector origin) // A spot 24 from the origin in a random direction (the twin's angle draws 3.14, not pi). static Vector twin_spot_beside(Vector origin) { - float half = random_unit() * TWIN_HALF_TURN; + float half = random_unit() * PI_ROUGH; float angle = half + half; return vector_make(std::cos(angle) * TWIN_OPTION_GAP + origin.x, std::sin(angle) * TWIN_OPTION_GAP + origin.y); } diff --git a/src/familiar_shoot.cpp b/src/familiar_shoot.cpp index ffc1c9e..a7aae6f 100644 --- a/src/familiar_shoot.cpp +++ b/src/familiar_shoot.cpp @@ -778,7 +778,7 @@ void Entity_Familiar::update_weapon(bool isInterpolated) if (playerWeapon && weapon) TryAimAtMarkedTarget(aim, direction, &markedAim); if (variant == CAINS_OTHER_EYE) { - float angle = random_unit() * 3.14f; + float angle = random_unit() * PI_ROUGH; angle = angle + angle; aim = vector_make(std::cos(angle), std::sin(angle)); if (std::abs(aim.x) <= std::abs(aim.y)) direction = aim.y >= 0 ? DIRECTION_DOWN : DIRECTION_UP; diff --git a/src/familiar_sprinkler.cpp b/src/familiar_sprinkler.cpp index 5577bdd..ed4cf32 100644 --- a/src/familiar_sprinkler.cpp +++ b/src/familiar_sprinkler.cpp @@ -234,7 +234,7 @@ static void sprinkler_targets(Entity_Familiar& sprinkler, const Weapon_MultiShot for (uint32_t i = sprinkler_lung_extras(player, LUNG_TARGETS_MIN); i > 0; i--) { Entity_Effect* scattered = spawn({}, Random(), lead, TARGET_LUNG_SUBTYPE); - float turn = random_unit() * RANDOM_HALF_TURN * 2; + float turn = random_unit() * PI_ROUGH * 2; float spread = random_unit() * TARGET_LUNG_SPREAD_RANGE + TARGET_LUNG_SPREAD_MIN; scattered->posOffset = vector_scale(vector_make(std::cos(turn), std::sin(turn)), spread); } @@ -324,7 +324,7 @@ static void sprinkler_lung(Entity_Familiar& sprinkler, Vector aim, const Weapon_ Vector eyeAim = vector_from_angle(vector_angle(aim) + angle); for (int i = 0; i < perEye; i++) { - float turn = random_unit() * RANDOM_HALF_TURN * 2; + float turn = random_unit() * PI_ROUGH * 2; float reach = random_unit(); Vector velocity = vector_add(vector_scale(vector_make(std::cos(turn), std::sin(turn)), reach * SPRINKLER_LUNG_SCATTER), diff --git a/src/familiar_variants.cpp b/src/familiar_variants.cpp index 1ff20a5..f8ffa01 100644 --- a/src/familiar_variants.cpp +++ b/src/familiar_variants.cpp @@ -218,7 +218,6 @@ constexpr float STITCHES_BOUNCE_MAX = 10; // countdown. constexpr int RIB_FIREPLACE_TYPES[] = {ENTITY_FIREPLACE, ENTITY_MOVABLE_TNT, ENTITY_POOP}; constexpr float RIB_SWING_SCALE = 0.1f; -constexpr int RIB_HIT_COUNTDOWN = 30; // My Shadow's Chargers: how many may be out, how far away they rise (four tries at a free spot), how long they chase // their enemy, and their black fading in. @@ -246,8 +245,6 @@ constexpr float CUBE_FRICTION_RANGE = 0.060000002f; constexpr float CUBE_FROST_MIN = 0.2f; constexpr float CUBE_FROST_RANGE = 0.5f; constexpr float CUBE_DUST_DRIFT = 0.14f; -constexpr float CUBE_DUST_SPIN_MIN = 2; -constexpr float CUBE_DUST_SPIN_RANGE = 10; constexpr uint32_t CUBE_DUST_LIFE = 15; constexpr ColorMod CUBE_DUST_COLOR = {{1, 1, 1, 0.4f}, {0, 0, 0, 0}, {0.8f, 0.9f, 1}}; @@ -1228,7 +1225,7 @@ void pointy_rib_touch(Entity_Familiar& rib, Entity& collider, float damageMultip float swing = std::clamp(vector_dot(edge, player.velocity) * RIB_SWING_SCALE, 0.0f, 1.0f); int displacement = (int)(Random() & 1) * 2 - 1; TearParams params = player.GetTearHitParams(WEAPON_KNIFE, 1, displacement, nullptr); - collider.TakeDamage((swing + damageMultiplier) * params.tearDamage, 0, EntityRef(&rib), RIB_HIT_COUNTDOWN); + collider.TakeDamage((swing + damageMultiplier) * params.tearDamage, 0, EntityRef(&rib), HIT_COUNTDOWN); } // Part of 006261f0 (My Shadow): the first touch of each vulnerable enemy summons a charmed shadow Charger nearby (a @@ -1243,7 +1240,7 @@ void my_shadow_touch(Entity_Familiar& shadow, Entity& collider) Vector spot = vector_add(shadow.pos, vector_scale(random_direction(), MY_SHADOW_REACH * random_unit())); for (int i = 0; i < MY_SHADOW_TRIES && room_grid_collision_at(spot) != 0; i++) { - float turn = random_unit() * RANDOM_HALF_TURN * 2; + float turn = random_unit() * PI_ROUGH * 2; float reach = random_unit() * MY_SHADOW_REACH; spot = vector_add(shadow.pos, vector_make(std::cos(turn) * reach, std::sin(turn) * reach)); } @@ -1383,7 +1380,7 @@ void cube_baby_update(Entity_Familiar& cube) .type = ENTITY_EFFECT, .variant = EFFECT_DUST_CLOUD, .seed = Random()})); - dust->rotation = random_unit() * CUBE_DUST_SPIN_RANGE + CUBE_DUST_SPIN_MIN; + dust->rotation = random_between(DUST_SPIN_MIN, DUST_SPIN_RANGE); int life = (int)(Random() % CUBE_DUST_LIFE) + (int)CUBE_DUST_LIFE; dust->timeout = life; dust->lifespan = life; @@ -1512,7 +1509,7 @@ void blood_puppy_room_enter(Entity_Familiar& puppy) if (entity == puppy.linkedEntity.get()) entity->pos = puppy.pos; else { - float turn = random_unit() * RANDOM_HALF_TURN * 2; + float turn = random_unit() * PI_ROUGH * 2; entity->pos = vector_add(puppy.pos, vector_make(std::cos(turn), std::sin(turn))); } entity->velocity = {}; diff --git a/src/familiar_walker.cpp b/src/familiar_walker.cpp index 4f4c750..0866f07 100644 --- a/src/familiar_walker.cpp +++ b/src/familiar_walker.cpp @@ -245,7 +245,7 @@ Entity_Familiar* spawn_blue_spider(const Vector& position, Entity* spawner, Vect { Vector spot = room_free_pickup_position_find( {.position = position, .step = SPIDER_THROW_SPOT_STEP, .isAvoidActiveEntities = true}); - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float distance = random_unit(); target = vector_add(spot, vector_scale(vector_make(std::cos(angle), std::sin(angle)), distance * SPIDER_THROW_SCATTER)); diff --git a/src/familiar_wisp_kinds.cpp b/src/familiar_wisp_kinds.cpp index 301245a..19b799a 100644 --- a/src/familiar_wisp_kinds.cpp +++ b/src/familiar_wisp_kinds.cpp @@ -130,7 +130,6 @@ constexpr int GAMEKID_HIT_FEAR = 2; constexpr int GAMEKID_TARGET_FRAMES = 150; constexpr int GAMEKID_TINT_FRAMES = 2; constexpr uint32_t GAMEKID_HEART_CHANCE = 4; -constexpr int GAMEKID_HIT_COUNTDOWN = 30; constexpr ColorMod GAMEKID_TINT = {{0.3f, 0.5f, 1.2f, 1}, {0, 0, 0, 0}, {0, 0, 0}}; // Mom's Bottle of Pills: the pill each wisp shows (one to six) and the colours of the six pills, shuffled per run. @@ -245,7 +244,6 @@ constexpr int NUGGET_LINE_THRESHOLD = 900; constexpr float CRAFTER_FRICTION = 0.9f; constexpr float CRAFTER_SPEED = 2; constexpr float CRAFTER_BUMP = 0.1f; -constexpr float CRAFTER_TURN = 3.14f; constexpr float CRAFTER_DAMAGE = 100; constexpr float CRAFTER_RADIUS = 75; @@ -268,7 +266,6 @@ constexpr float PLUM_TEAR_HEIGHT = 10; constexpr float PLUM_TEAR_DAMAGE = 3; constexpr float PLUM_THRUST = 0.4f; constexpr std::array PLUM_TEAR_SCALES = {0.5f, 0.625f}; -constexpr float PLUM_TEAR_SCALE_MIN = 0.01f; // Red Candle's and Urn of Souls' flames, Sulfur's beam and the Delirious Haunt's. constexpr float CANDLE_FLAME_SPEED = 5; @@ -693,7 +690,7 @@ static void gamekid_wisp_update(Entity_Familiar& wisp) target->SetColor(GAMEKID_TINT, GAMEKID_TINT_FRAMES, 0, false, true); target->AddFear(EntityRef(&wisp), GAMEKID_FEAR, false); if (Random() % GAMEKID_HEART_CHANCE == 0) - target->TakeDamage(0, DAMAGE_SPAWN_RED_HEART, EntityRef(&wisp), GAMEKID_HIT_COUNTDOWN); + target->TakeDamage(0, DAMAGE_SPAWN_RED_HEART, EntityRef(&wisp), HIT_COUNTDOWN); } // Mom's Bottle of Pills' wisp shows its pill's colours on its first frame. @@ -894,7 +891,7 @@ static void mine_crafter_wisp_update(Entity_Familiar& wisp) wisp.velocity = vector_resized(wisp.velocity, CRAFTER_SPEED); if (wisp.isCollidesWithGrid) { - float angle = random_unit() * CRAFTER_TURN * 2; + float angle = random_unit() * PI_ROUGH * 2; wisp.velocity = vector_add(wisp.velocity, vector_make(std::cos(angle) * CRAFTER_BUMP, std::sin(angle) * CRAFTER_BUMP)); } for (Entity* entity : entity_query_radius(wisp.pos, wisp.size, QUERY_TEARS)) @@ -1040,7 +1037,7 @@ void plum_flute_wisp_spray(Entity_Familiar& wisp, int updateSteps) .variant = TEAR_BLOOD, .seed = Random()})); tear->fallingAccel -= PLUM_TEAR_FALL; - float scale = std::max(PLUM_TEAR_SCALES[Random() & 1], PLUM_TEAR_SCALE_MIN); + float scale = std::max(PLUM_TEAR_SCALES[Random() & 1], TEAR_SCALE_MIN); tear->baseScale = scale; tear->fScale = scale; tear->ResetSpriteScale(); diff --git a/src/fx_layers.cpp b/src/fx_layers.cpp index d609c6a..b2f7b76 100644 --- a/src/fx_layers.cpp +++ b/src/fx_layers.cpp @@ -92,8 +92,6 @@ constexpr float VEIN_ALPHA_MIN = 0.3f; constexpr float VEIN_ALPHA_RANGE = 0.7f; constexpr int VEIN_DEPTH_MAX = 4; -constexpr float HALF_TURN = 180; -constexpr float QUARTER_TURN = 90; // The vein and ray phase generator, seeded anew by every LoadConfig. static RNG fxRng = {}; @@ -250,14 +248,14 @@ static Vector room_center_get(const FXLayers& fx) static float angle_wrap(float angle) { if (std::abs(angle) > FULL_TURN_DEGREES) angle = std::fmod(angle, FULL_TURN_DEGREES); - if (angle > HALF_TURN) return angle - FULL_TURN_DEGREES; - return angle < -HALF_TURN ? angle + FULL_TURN_DEGREES : angle; + if (angle > HALF_TURN_DEGREES) return angle - FULL_TURN_DEGREES; + return angle < -HALF_TURN_DEGREES ? angle + FULL_TURN_DEGREES : angle; } // Whether something turned by angle at position points to target's side of it. static bool is_facing(Vector target, float angle, Vector position) { - float radians = (angle - QUARTER_TURN) * DEGREES_TO_RADIANS; + float radians = (angle - RIGHT_ANGLE_DEGREES) * DEGREES_TO_RADIANS; return std::sin(radians) * (target.y - position.y) + std::cos(radians) * (target.x - position.x) >= 0; } @@ -877,7 +875,7 @@ void FXLayers::Update(PlayerFollow follow) float dx = veinTarget.x - vein.position.x; float distance = std::sqrt(dy * dy + dx * dx); float reach = (distance - VEIN_LENGTH_REACH) * VEIN_LENGTH_PER_DISTANCE; - float angle = angle_wrap(std::atan2(dy, dx) * RADIANS_TO_DEGREES + QUARTER_TURN); + float angle = angle_wrap(std::atan2(dy, dx) * RADIANS_TO_DEGREES + RIGHT_ANGLE_DEGREES); vein.scale = std::min(VEIN_SCALE_MAX, std::max(VEIN_SCALE_MIN, distance * VEIN_SCALE_PER_DISTANCE)); vein.rotation = angle_lerp(vein.baseRotation, angle, VEIN_TURN_RATE); diff --git a/src/fx_layers.h b/src/fx_layers.h index a495ce6..1bda8a2 100644 --- a/src/fx_layers.h +++ b/src/fx_layers.h @@ -59,6 +59,7 @@ constexpr float ROOM_VIEW_WIDTH = 338; constexpr KColor WHITE = kcolor_rgba(1, 1, 1, 1); constexpr KColor BLACK = kcolor_rgba(0, 0, 0, 1); +constexpr KColor RED = kcolor_rgba(1, 0, 0, 1); constexpr uint32_t WHITE_ARGB = 0xffffffff; constexpr uint32_t BLACK_ARGB = 0xff000000; constexpr uint32_t CLEAR_ARGB = 0; diff --git a/src/game.cpp b/src/game.cpp index 40d9909..d435980 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -16,8 +16,13 @@ #include "victory_run_prompt.h" #include #include +#include #include #include +extern "C" +{ +#include "lua.h" +} constexpr const char* STAGES_XML = "stages.xml"; constexpr const char* CURSES_XML = "curses.xml"; @@ -40,7 +45,6 @@ constexpr const char* HALLUCINATION_SNAPSHOT = "Hallucination Snapshot"; constexpr const char* COLORMOD_SURFACE = "Colormod Surface"; constexpr int BLOOM_DURATION_DEFAULT = 30; -constexpr int REVIVE_MACHINE_COINS = 10; constexpr float DIZZY_CHANGE_SPEED_DEFAULT = 0.001f; constexpr int BLUE_WOMB_PAR_TIME = 54000; // The attributes of a giant book layer's tint channels. @@ -109,7 +113,6 @@ Game::Game() level_reset(); coop_awards_load(coopAwards); deathmatchManager.Reset(); - // ChallengeParam::Reset on dailyChallenge's params waits for DailyChallenge's takeover (classes.h has bytes). create_render_surfaces(); g_manager->modManager.create_shader_render_targets(); @@ -475,6 +478,13 @@ void Game::create_render_surfaces() surface_create(colormodSurface, COLORMOD_SURFACE); } +// 009ba9a0 Gives every main player the stats a new floor's first room sets, on a copy of the list it may grow. +static void main_players_post_level_init(PlayerManager& players) +{ + for (Entity_Player* player : std::vector(players.playerList)) + if (player->variant == PLAYER_VARIANT_PLAYER) player->InitPostLevelInitStats(); +} + // 006f5320 Starts a new run on a character, challenge, seeds and difficulty: the run's seeds (a challenge's own // effects), whether progress is frozen, the item and boss pools, the player, the first floor (Backasswards' Dark Room), // then saves it, fades in from black and runs the first room's update and the mods' game start. @@ -517,10 +527,7 @@ void Game::Start(int playerType, uint32_t startChallenge, const Seeds& seeds, Di SetNextStage(); if (challenge == CHALLENGE_BACKASSWARDS) SetStage(STAGE_DARK_ROOM, STAGETYPE_ORIGINAL); Init(true); - - std::vector players = playerManager.playerList; - for (Entity_Player* player : players) - if (player->variant == PLAYER_VARIANT_PLAYER) player->InitPostLevelInitStats(); + main_players_post_level_init(playerManager); Manager::save_game_state(); playerManager.trigger_new_room_effects(); @@ -532,6 +539,126 @@ void Game::Start(int playerType, uint32_t startChallenge, const Seeds& seeds, Di lua_engine_get().PostGameStart(false); } +// 006f72f0 Starts a run again from a rerun's saved state: its challenge, difficulty and seeds (dropping their effects, +// the start seed stepped on), new pools, its player restored around the first floor, then saved, the pause screen +// reset, the first room's update, the fade in from black and the mods' game start. Progress stays frozen. +void Game::StartFromRerunState(GameState& state) +{ + Manager& manager = *g_manager; + + isStarted = true; + hud.LoadGraphics(); + challenge = state.challenge; + isConsoleUsedThisRun = state.isConsoleUsedThisRun || manager.isConsoleEnabled; + difficulty = (Difficulty)state.difficulty; + isRerun = true; + seedEffects = state.seeds; + seedEffects.ClearSeedEffects(); + seedEffects.set_start_seed(seedEffects.GetNextSeed()); + fortuneRNG.SetSeed(seedEffects.GetNextSeed(), DEFAULT_SHIFT_INDEX); + + bool isReadOnly = seedEffects.isCustomRun || seedEffects.AchievementUnlocksDisallowed() || + Manager::AchievementUnlocksDisallowed() || isRerun; + manager.persistentGameData.SetReadOnly(isReadOnly); + uint32_t startSeed = seedEffects.GetStartSeed(); + std::string seedText = Seeds::Seed2String(seedEffects.GetStartSeed()); + log_printf(LOG_INFO, "RNG Start Seed: %s (%u) [Rerun, %d]\n", seedText.c_str(), startSeed, manager.currentSaveSlot); + + proceduralItemManager.Init(); + std::string itemPoolsPath = manager.modManager.TryRedirectPath(ITEM_POOLS_XML); + itemPool.Init(seedEffects.GetNextSeed(), itemPoolsPath); + bossPool.init(seedEffects.GetStartSeed()); + playerManager.init_main_player(state.playerType, seedEffects.GetPlayerInitSeed()); + playerManager.RestoreGameState(state); + SetNextStage(); + Init(true); + playerManager.RestoreGameState_PostLevelInit(state); + + Manager::save_game_state(); + playerManager.trigger_new_room_effects(); + pause_screen_reset(pauseScreen); + encounteredBosses.clear(); + room->Update(); + Fadein(START_FADE_SPEED, FADE_ICON_SHOW, kcolor_rgba(0, 0, 0, 1)); + framesSinceRoomTransition = 0; + lua_engine_get().PostGameStart(true); +} + +// 006f6dd0 Starts a day's daily run: its difficulty, rules and seed (a custom run with the daily's effects), frozen +// progress, new pools, its character on the first floor, then fades in from black and resets the pause screen before +// the mods' game start. Unlike a new run it is not saved and the first room does not update. +// (006f6260) The rules are copied whole. +void Game::StartDailyChallenge(const DailyChallenge& daily) +{ + Manager& manager = *g_manager; + + isStarted = true; + difficulty = (Difficulty)daily.params.difficulty; + challenge = 0; + isConsoleUsedThisRun = manager.isConsoleEnabled; + hud.LoadGraphics(); + dailyChallenge = daily; + + seedEffects.Reset(); + seedEffects.isCustomRun = true; + seedEffects.SetStartSeed(Seeds::Seed2String(daily.seed)); + for (int effect : daily.params.seedEffects) seedEffects.AddSeedEffect(effect); + fortuneRNG.SetSeed(seedEffects.GetNextSeed(), DEFAULT_SHIFT_INDEX); + manager.persistentGameData.SetReadOnly(true); + uint32_t startSeed = seedEffects.GetStartSeed(); + std::string seedText = Seeds::Seed2String(seedEffects.GetStartSeed()); + log_printf(LOG_INFO, "RNG Start Seed: %s (%u) [Daily, %d]\n", seedText.c_str(), startSeed, manager.currentSaveSlot); + + proceduralItemManager.Init(); + std::string itemPoolsPath = manager.modManager.TryRedirectPath(ITEM_POOLS_XML); + itemPool.Init(seedEffects.GetNextSeed(), itemPoolsPath); + bossPool.init(seedEffects.GetStartSeed()); + playerManager.init_main_player(daily.params.playerType, seedEffects.GetPlayerInitSeed()); + SetNextStage(); + Init(true); + main_players_post_level_init(playerManager); + + playerManager.trigger_new_room_effects(); + Fadein(START_FADE_SPEED, FADE_ICON_SHOW, kcolor_rgba(0, 0, 0, 1)); + pause_screen_reset(pauseScreen); + lua_engine_get().PostGameStart(false); +} + +// 006f7750 Starts the command line's debug run: a random custom seed with frozen progress, new pools, Isaac on the +// asked stage, and the asked room file's room entered, read once for every later debug start. +void Game::StartDebug(int levelStage, int levelStageType, Difficulty startDifficulty, const std::string& roomFile) +{ + Manager& manager = *g_manager; + + isStarted = true; + isConsoleUsedThisRun = manager.isConsoleEnabled; + difficulty = startDifficulty; + isDebug = true; + seedEffects.isCustomRun = true; + seedEffects.SetStartSeed(""); + manager.persistentGameData.SetReadOnly(true); + hud.LoadGraphics(); + challenge = 0; + + proceduralItemManager.Init(); + std::string itemPoolsPath = manager.modManager.TryRedirectPath(ITEM_POOLS_XML); + itemPool.Init(seedEffects.GetNextSeed(), itemPoolsPath); + bossPool.init(seedEffects.GetStartSeed()); + playerManager.init_main_player(PLAYER_ISAAC, seedEffects.GetPlayerInitSeed()); + SetStage(levelStage, levelStageType); + Init(true); + if (!roomFile.empty()) + { + static RoomConfig_Room debugRoom = RoomConfig::LoadRoomFromXmlFile(roomFile); + debugRoom.stageId = GetStageID(); + DEBUG_goto_room(&debugRoom); + } + + main_players_post_level_init(playerManager); + playerManager.trigger_new_room_effects(); + lua_engine_get().PostGameStart(false); +} + // 006f7ac0 Starts the next victory lap: progress freezes, the first lap turns the run hard, the main players pay the // lap's toll, the Mega Satan door closes and the run's seed steps on to new pools. The floor before the backwards // path is saved, the stage bar starts over and the first floor begins, saved and faded in from black. @@ -673,8 +800,8 @@ static void screen_size_set(const KAGE::Graphics::ImageBase& surface) if (shader) shader->set_uniform(SCREEN_SIZE_UNIFORM, KAGE::Graphics::UNIFORM_VEC4, size.data()); } -// Whether the screen pixelates: a pixelation room transition going out or coming in. -// A stage transition decides with StageTransition's own check (009301d0), which waits for its takeover. +// Whether the screen pixelates: a pixelation room transition going out or coming in, or a stage transition that +// StageTransition::is_pixelated says pixelates. static bool is_pixelating(Game& game) { int stageState = game.stageTransition.state; @@ -780,7 +907,7 @@ static void overlays_render(Game& game) popups.render_layer(0); game.hud.Render(); - if (isFighting) game.deathmatchManager.type->FUN_0042aca0(); + if (isFighting) game.deathmatchManager.type->timer_render(); if (stageState == STAGE_TRANSITION_OUT || stageState == STAGE_TRANSITION_IN) game.stageTransition.Render(); else graphics.blendMode.SetMode(KAGE::Graphics::BLEND_NORMAL); game.itemOverlay.Render(); @@ -803,6 +930,63 @@ static void overlays_render(Game& game) g_manager->modManager.shaders_render(); } +// The Lua memory graph (debug 14): sampled every 30 frames into the last 128 samples, drawn right to left over the +// bottom right corner with its axes ticked every 256 MB. +constexpr int LUA_MEMORY_SAMPLE_FRAMES = 30; +constexpr float LUA_GRAPH_MARGIN = 10; +constexpr float LUA_GRAPH_WIDTH = 128; +constexpr float LUA_GRAPH_HEIGHT = 64; +constexpr float LUA_GRAPH_FULL_KB = 512000; +constexpr int LUA_GRAPH_TICKS = 3; +constexpr float LUA_GRAPH_TICK_STEP = 32; +constexpr int LUA_GRAPH_TICK_MB = 256; +constexpr float LUA_LABEL_GAP = 4; +constexpr float LUA_LABEL_RAISE = 9; + +// 00872090 (render_debug_lua_memory) Samples the Lua heap's size on its timer and draws the graph of the samples. +static void lua_memory_render() +{ + if (!g_luaEngine || !lua_engine_get().state) return; + + LuaEngine& lua = lua_engine_get(); + if (lua.memoryHistoryTimer == 0) + { + lua.memoryHistoryTimer = LUA_MEMORY_SAMPLE_FRAMES; + lua.memoryHistory[lua.memoryHistoryIndex] = lua_gc(lua.state, LUA_GCCOUNT, 0); + if (++lua.memoryHistoryIndex >= LUA_MEMORY_HISTORY_SIZE) lua.memoryHistoryIndex = 0; + if (lua.memoryHistoryCount < LUA_MEMORY_HISTORY_SIZE) lua.memoryHistoryCount++; + } + else + lua.memoryHistoryTimer--; + + float right = g_screenWidth - LUA_GRAPH_MARGIN; + float bottom = g_screenHeight - LUA_GRAPH_MARGIN; + float left = right - LUA_GRAPH_WIDTH; + Vector from = vector_make(right + 1, 0); + int index = lua.memoryHistoryIndex; + for (int i = 0; i < lua.memoryHistoryCount; i++) + { + index = index == 0 ? LUA_MEMORY_HISTORY_SIZE - 1 : index - 1; + float kilobytes = (float)(uint32_t)lua.memoryHistory[index]; + Vector to = vector_make(from.x - 1, std::ceil(bottom - kilobytes * LUA_GRAPH_HEIGHT / LUA_GRAPH_FULL_KB)); + if (from.y != 0) render_color_quad(from, to, RED, RED, 1); + from = to; + } + render_color_quad(vector_make(left, bottom), vector_make(right, bottom), WHITE, WHITE, 1); + render_color_quad(vector_make(left, bottom - LUA_GRAPH_HEIGHT), vector_make(left, bottom), WHITE, WHITE, 1); + + Font& font = g_manager->font8_LuaMiniOutlined; + for (int tick = 0; tick < LUA_GRAPH_TICKS; tick++) + { + float y = bottom - (float)tick * LUA_GRAPH_TICK_STEP; + std::string label = std::format("{}M", tick * LUA_GRAPH_TICK_MB); + FontSettings settings; + render_color_quad(vector_make(left - 1, y), vector_make(left, y), WHITE, WHITE, 1); + float x = left - LUA_LABEL_GAP - (float)(uint32_t)font.GetStringWidth(label); + font.DrawString(label, vector_make(x, y - LUA_LABEL_RAISE), vector_make(1, 1), WHITE, settings); + } +} + // Resolves the effect surfaces in turn (the room snapshot, bloom, pixelation, hallucination, old TV), then draws the // Ascent's white, the fade in (with the loading icon) or out, and the debug displays. static void effects_resolve(Game& game, bool isRoomSnapshot, bool isOldTv) @@ -855,7 +1039,7 @@ static void effects_resolve(Game& game, bool isRoomSnapshot, bool isOldTv) if (game.debugFlags & DEBUG_PLAYER_INFO && !game.playerManager.playerList.empty()) reconstruction_missing("Game::Render 006fbc10: the player debug info"); - if (game.debugFlags & DEBUG_LUA_MEMORY) reconstruction_missing("render_debug_lua_memory 00872090"); + if (game.debugFlags & DEBUG_LUA_MEMORY) lua_memory_render(); } // 006fbc10 Draws the run's frame. The room, or the room transition, draws through the effect surfaces that are on (old @@ -867,7 +1051,6 @@ void Game::Render() { KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager; OptionsConfig& options = g_manager->optionsConfig; - bool isFighting = deathmatchManager.state == DEATHMATCH_FIGHT; bool isOldTv = seedEffects.HasSeedEffect(SEED_OLD_TV); bool isTransitionShown = roomTransition.mode == TRANSITION_OUT || roomTransition.mode == TRANSITION_IN; @@ -877,7 +1060,6 @@ void Game::Render() isWindowResizePending = false; } room->render_lighting(); - if (isFighting) deathmatchManager.type->vfunc_5(); if (isOldTv) effect_pass_begin(oldTvSurface); if (hallucinationTimer > 0) effect_pass_begin(hallucinationSurface); if (options.render.isPixelationEnabled && is_pixelating(*this)) effect_pass_begin(pixelationSurface); diff --git a/src/game.h b/src/game.h index 2484d83..96f5246 100644 --- a/src/game.h +++ b/src/game.h @@ -46,14 +46,13 @@ constexpr int GLOWING_HOURGLASS_SLOTS = 2; constexpr int GIANTBOOK_ENTRY_COUNT = 48; constexpr int COOP_AWARD_COUNT = 21; constexpr int COOP_STAT_NONE = 22; +// The Revive Machine's first price, which rises by 2 a use up to twice that. +constexpr int REVIVE_MACHINE_COINS = 10; // The room's render surface, its size and margin, centered on the screen. constexpr float ROOM_SURFACE_WIDTH = 338; constexpr float ROOM_SURFACE_HEIGHT = 182; constexpr float ROOM_SURFACE_MARGIN = 52; -// The xorshift every RNG of Game starts on, before a run seeds it (shift index 35). -constexpr RNG RNG_DEFAULT = {RNG_SEED_DEFAULT, 5, 9, 7}; - // A screen color modifier that changes nothing. constexpr ColorModState COLOR_MOD_NEUTRAL = {1, 1, 1, 0, 0, 1}; @@ -76,6 +75,7 @@ enum DebugFlag : uint32_t DEBUG_ROOM_INFO = 1u << 4, DEBUG_HITSPHERES = 1u << 5, DEBUG_DAMAGE_VALUES = 1u << 6, + DEBUG_INFINITE_CHARGE = 1u << 7, DEBUG_HIGH_LUCK = 1u << 8, DEBUG_QUICK_KILL = 1u << 9, DEBUG_GRID_INDICES = 1u << 10, @@ -102,7 +102,9 @@ enum GameStateFlag : int GAME_STATE_MAUSOLEUM_HEART_KILLED = 46, GAME_STATE_BACKWARDS_PATH_INIT = 47, GAME_STATE_BACKWARDS_PATH = 48, - GAME_STATE_MEGA_SATAN_DOOR_OPENED = 49 + GAME_STATE_MEGA_SATAN_DOOR_OPENED = 49, + GAME_STATE_URIEL_KILLED = 50, + GAME_STATE_GABRIEL_KILLED = 51 }; // The string table keys of the co-op awards, in the order of Game's award table. @@ -343,6 +345,9 @@ public: void create_render_surfaces(); void Start(int playerType, uint32_t startChallenge, const Seeds& seeds, Difficulty startDifficulty); + void StartFromRerunState(GameState& state); + void StartDailyChallenge(const DailyChallenge& daily); + void StartDebug(int levelStage, int levelStageType, Difficulty startDifficulty, const std::string& roomFile); void NextVictoryLap(); void Fadein(float speed, FadeIcon icon, KColor color); void SetColorModifier(const ColorModState& color, bool isLerp, float rate); diff --git a/src/game_end.cpp b/src/game_end.cpp index 77cdb38..047577a 100644 --- a/src/game_end.cpp +++ b/src/game_end.cpp @@ -209,6 +209,46 @@ void PlayerManager::unlock_completion_mark(int completionType) } } +// 006f9f20 Ends a daily run. Outside practice a death ends the streak and counts a loss, any other ending ends the +// losing streak and counts to the streak and the wins, keeping the best streak, and the daily is no longer active. +// The ending is recorded with the floor finished (one deeper under the Labyrinth) unless it is a death, then the score +// is calculated and its breakdown shown, submitted outside practice. +// Netplay is offline, so the online daily's achievement is left out. +static void daily_end(Game& game, GameEnding ending) +{ + PersistentGameData& data = g_manager->persistentGameData; + std::array& counters = data.eventCounters; + + data.SetReadOnly(false); + if (!game.dailyChallenge.isPractice) + { + if (ending == ENDING_DEATH) + { + counters[EVENT_COUNTER_DAILYS_STREAK] = 0; + data.IncreaseEventCounter(EVENT_COUNTER_DAILYS_LOSING_STREAK, 1); + } + else + { + counters[EVENT_COUNTER_DAILYS_LOSING_STREAK] = 0; + data.IncreaseEventCounter(EVENT_COUNTER_DAILYS_STREAK, 1); + data.IncreaseEventCounter(EVENT_COUNTER_DAILYS_WON, 1); + } + if ((uint32_t)counters[EVENT_COUNTER_DAILYS_BEST_STREAK] < (uint32_t)counters[EVENT_COUNTER_DAILYS_STREAK]) + counters[EVENT_COUNTER_DAILYS_BEST_STREAK] = counters[EVENT_COUNTER_DAILYS_STREAK]; + counters[EVENT_COUNTER_DAILY_RUN_IS_ACTIVE] = 0; + } + data.SetReadOnly(true); + + game.scoreSheet.runEnding = ending; + if (ending != ENDING_DEATH) + { + int stage = (int)game.stage + (game.filter_curses(CURSE_OF_LABYRINTH) ? 1 : 0); + game.scoreSheet.AddFinishedStage({stage, (int)game.stageType, false}, game.timeCounter); + } + game.scoreSheet.Calculate(); + game.leaderboard.Show(game.dailyChallenge.id, game.scoreSheet, !game.dailyChallenge.isPractice, false); +} + // 006f9770 Ends the run (Rebirth's Game::End): a death forgets the saved run and opens the game over screen. Any other // ending queues its cutscene, unloading the run and going back to the title after it, then saves the rerun (outside // challenges) and the run's progress. Nothing ends during a versus match until it is over. Mods hear of the end. @@ -226,7 +266,11 @@ void game_end(GameEnding ending) if (game.deathmatchManager.is_active() && game.deathmatchManager.state != DEATHMATCH_OVER) return; if (ending == ENDING_DEATH) game_save_delete(); - if (game.dailyChallenge.id != 0) reconstruction_missing("Game::End 006f9770 (a daily run's end, 006f9f20)"); + if (game.dailyChallenge.id != 0) + { + daily_end(game, ending); + return lua_engine_get().PostGameEnd(ending == ENDING_DEATH); + } if (ending == ENDING_DEATH) { diff --git a/src/game_over.cpp b/src/game_over.cpp index 50fb06c..e352e8f 100644 --- a/src/game_over.cpp +++ b/src/game_over.cpp @@ -1,5 +1,6 @@ #include "game_over.h" #include "entity_config.h" +#include "entity_effect.h" #include "entity_player.h" #include "game.h" #include "log.h" @@ -326,13 +327,25 @@ void GameOver::Render() } // 009bc120 A player's death that ends the run: the deaths counter, the game over jingle with its music queued, and the -// run's end. A co-op baby leaves the run instead. +// run's end. A co-op baby leaves the run instead, in a poof unless it is a Found Soul following a player. void PlayerManager::trigger_coop_baby_death(Entity_Player* deadPlayerEntity) { Manager& manager = *g_manager; if (deadPlayerEntity->variant != PLAYER_VARIANT_PLAYER) - reconstruction_missing("PlayerManager::trigger_coop_baby_death 009bc120 (a co-op baby leaves)"); + { + Entity* owner = deadPlayerEntity->parent; + bool isPoof = deadPlayerEntity->babySkin != BABY_FOUND_SOUL || !owner || owner->type != ENTITY_PLAYER; + for (size_t slot = 1; slot < playerList.size(); slot++) + { + if (playerList[slot] != deadPlayerEntity) continue; + RemoveCoPlayer(deadPlayerEntity); + if (!isPoof) continue; + Vector at = vector_make(deadPlayerEntity->pos.x, deadPlayerEntity->pos.y - LEAVE_POOF_HEIGHT); + g_game->Spawn({.position = at, .type = ENTITY_EFFECT, .variant = EFFECT_POOF01, .seed = Random()}); + } + return; + } deadPlayer = deadPlayerEntity; manager.persistentGameData.IncreaseEventCounter(EVENT_COUNTER_DEATHS, 1); diff --git a/src/game_restore.cpp b/src/game_restore.cpp index eb7a761..b572895 100644 --- a/src/game_restore.cpp +++ b/src/game_restore.cpp @@ -104,7 +104,7 @@ static void ambush_resume(Ambush& ambush, int wave) // than rewinding) the first player, the pools, the fortune generator and whether achievements may unlock. The // generators, pools, TMTRAINER items, the Ascent's stages, the versus rules, the players, the floor with the room the // players are in, the nightmare stage bar, the ambush, the score and each player's Wavy Cap costume follow. -// Netplay is offline. The versus rules keep no players offline. +// Netplay is offline. void Game::restore_game_state(GameState& state, GameRestore restore) { Manager& manager = *g_manager; @@ -173,6 +173,7 @@ void Game::restore_game_state(GameState& state, GameRestore restore) deathmatchManager.state = DEATHMATCH_OFF; deathmatchManager.timer = 0; deathmatchManager.set_type((DeathmatchRules)state.versusRules); + if (deathmatchManager.type) deathmatchManager.type->RestoreGameState(state); playerManager.RestoreGameState(state); Level::RestoreGameState(state); @@ -364,8 +365,7 @@ static void mothers_shadow_restore(Level& level) // maps and every room descriptor with its config named again, the rooms the players are in and came from, and the // Ventricle Razor portals. Backasswards resumed in the uncleared boss room starts over in the first room and walks back // in. A new stage starts for the players, the camera catches up, and the room's watch speed and slowdown come back. -// The Death Certificate's return room is not kept by the curated game state, and the mineshaft escape's Mother's shadow -// waits for its takeover. +// A saved mineshaft escape brings Mother's shadow back. void Level::RestoreGameState(GameState& state) { Game& game = *g_game; @@ -511,7 +511,7 @@ static void twins_link(std::vector& matched, size_t index) } // Part of 009bcaa0: the dead Lazarus kept as a restored Tainted Lazarus' backup, made for it when it has none, then -// restored from its save, which it keeps for when it comes back. +// restored from its save, which it keeps (with the save's familiars, which are not in the room) for when it comes back. static void backup_player_restore(Entity_Player& main, GameStatePlayer& saved) { if (!main.backupPlayer) @@ -526,6 +526,7 @@ static void backup_player_restore(Entity_Player& main, GameStatePlayer& saved) backup.RestoreGameState(saved); backup.unlistedRestoreState = std::make_shared(); backup.StoreGameState(backup.unlistedRestoreState.get(), true); + backup.unlistedRestoreState->familiars = saved.familiars; } // 009bcaa0 Restores the saved players: each matched player from its save (its twin forgotten first), then the twins, @@ -645,6 +646,34 @@ static void rng_seeds_restore(std::vector& rngs, const std::vector& saved) +{ + PlayerManager& players = g_game->playerManager; + std::vector babies; + for (Entity_Player* baby : players.playerList) + { + if (baby->variant != PLAYER_VARIANT_COOP_BABY) continue; + Entity* owner = baby->parent; + if (!owner || owner->type != ENTITY_PLAYER) owner = players.GetPlayer(0); + if (owner == &player) babies.push_back(baby); + } + + for (size_t i = 0; i < saved.size(); i++) + { + if (i < babies.size()) + { + if (babies[i]->babySkin == saved[i].playerType) co_player_restore(*babies[i], saved[i]); + continue; + } + Entity_Player* baby = players.SpawnCoPlayerBaby(saved[i].playerType); + co_player_restore(*baby, saved[i]); + players.RemoveCoPlayer(baby); + } +} + // 007ae4b0 Restores a player from its save: its controller (and character, rewinding), its name, collectible counts, // trinkets (an unknown first one dropped for the second), voided items, Moving Box, forms, costumes and item RNGs, // its health (hearts added again), sub player, history and inventory with the smelted trinkets counted from the @@ -726,7 +755,7 @@ void Entity_Player::RestoreGameState(GameStatePlayer& saved) boneHeartsMask = saved.boneHeartsMask; AddHearts(saved.redHearts, true, false); if (saved.subPlayer && subPlayer) co_player_restore(*subPlayer, *saved.subPlayer); - if (!saved.coopBabies.empty()) reconstruction_missing("Entity_Player::RestoreGameState 007ae4b0: the co-op babies"); + coop_babies_restore(*this, saved.coopBabies); history.historyItems = saved.history; inventory = saved.inventory; @@ -780,6 +809,7 @@ void Entity_Player::RestoreGameState(GameStatePlayer& saved) rockBottomShotSpeed = saved.rockBottomShotSpeed; reverseEmpressMaxHearts = saved.reverseEmpressMaxHearts; reverseSunBoneHearts = saved.reverseSunBoneHearts; + pendingPill = saved.pendingPill; forgottenBodyRoomIdx = saved.forgottenBodyRoomIdx; forgottenBodyPos = saved.forgottenBodyPos; maggyHealthDrainCooldown = saved.maggyHealthDrainCooldown; @@ -813,7 +843,7 @@ void Entity_Player::RestoreGameState(GameStatePlayer& saved) samsonBerserkCharge = saved.samsonBerserkCharge; ibsCharge = saved.ibsCharge; proceduralItems = saved.proceduralItems; - if (!proceduralItems.empty()) reconstruction_missing("GlitchedItemSet::recalculate 009e0500 (TMTRAINER items)"); + glitched_items_recalculate(*this); edenSpeed = saved.edenSpeed; edenFireDelay = saved.edenFireDelay; diff --git a/src/game_save.cpp b/src/game_save.cpp index f90ad2a..3a7728c 100644 --- a/src/game_save.cpp +++ b/src/game_save.cpp @@ -7,40 +7,20 @@ #include "manager.h" #include "platform.h" #include "room.h" -#include constexpr int CHARGER_MY_SHADOW = 1; constexpr int FAMILIAR_UMBILICAL_BABY = 240; constexpr int REWIND_DOOR_FRAMES = 15; constexpr uint32_t ROOM_FLAG_SAVED = 0x40; -// The versus rules each kind of match plays, as its slot 1 answers. -static const std::array, DEATHMATCH_VENOM> DEATHMATCH_TYPE_RULES = {{ - {&typeid(DeathmatchTypeNormal), DEATHMATCH_NORMAL}, - {&typeid(DeathmatchTypeIpecac), DEATHMATCH_IPECAC}, - {&typeid(DeathmatchTypeBomberman), DEATHMATCH_BOMBERMAN}, - {&typeid(DeathmatchTypeLudovico), DEATHMATCH_LUDOVICO}, - {&typeid(DeathmatchTypeSumo), DEATHMATCH_SUMO}, - {&typeid(DeathmatchTypeKnockout), DEATHMATCH_KNOCKOUT}, - {&typeid(DeathmatchTypeSwordFight), DEATHMATCH_SWORD_FIGHT}, - {&typeid(DeathmatchTypeMachineGun), DEATHMATCH_MACHINE_GUN}, - {&typeid(DeathmatchTypeIndigestion), DEATHMATCH_INDIGESTION}, - {&typeid(DeathmatchTypeKnifeFight), DEATHMATCH_KNIFE_FIGHT}, - {&typeid(DeathmatchTypeVenom), DEATHMATCH_VENOM}, -}}; - -// Saves the versus rules as DeathmatchTypeBase::StoreGameState does: which kind of match the run drew (each type's -// slot 1) and its players. -// Offline no player ever joins a match, so its player set stays empty. A run without rules saves none. +// Saves the versus rules: which kind of match the run drew and the collectibles its pool knows. A run without rules +// saves none. static void versus_store(DeathmatchManager& manager, GameState& state) { - state.versusPlayers.clear(); + state.versusCollectibles.clear(); if (!manager.type) return; - - DeathmatchTypeBase* type = manager.type.get(); - const std::type_info& drawn = typeid(*type); - for (auto [info, rules] : DEATHMATCH_TYPE_RULES) - if (*info == drawn) state.versusRules = (uint8_t)rules; + state.versusRules = (uint8_t)manager.type->rules(); + manager.type->StoreGameState(state); } // 006f9000 Copies the run into a game state to save: its rules and seeds, the counters and histories of the run, the @@ -85,8 +65,9 @@ void Game::store_game_state(GameState& state) state.erasedEntities = erasedEntities; itemPool.StoreGameState(state.itemPool); bossPool.store_game_state(state.bossPool); - if (!proceduralItemManager.proceduralItems.empty()) - reconstruction_missing("Game::store_game_state 006f9000: the TMTRAINER items' seeds (ProceduralItem +0x8)"); + state.proceduralItemSeeds.clear(); + for (std::unique_ptr& item : proceduralItemManager.proceduralItems) + state.proceduralItemSeeds.push_back(item->seed); room->on_leave(); Level::store_game_state(state); @@ -332,7 +313,7 @@ static bool is_familiar_saved(Entity_Familiar& familiar, bool isSaveTemporaryFam // Moving Box, the friendly enemies it charmed (up to 10, the first twin only), its familiars and persistent effects. // The fields the curated player does not have yet keep their defaults: the soul charge, the last collectible frame // and the unknown fields. Its Echo Chamber items are saved without their kind, and its voided passives without their -// second word. The unlisted restore state is never set, so familiars come from the room. +// second word. A player kept out of the room with an unlisted restore state (a backup player) keeps its familiars. void Entity_Player::StoreGameState(GameStatePlayer* saveState, bool isSaveTemporaryFamiliars) { GameStatePlayer& state = *saveState; @@ -397,6 +378,7 @@ void Entity_Player::StoreGameState(GameStatePlayer* saveState, bool isSaveTempor state.rockBottomShotSpeed = rockBottomShotSpeed; state.reverseEmpressMaxHearts = reverseEmpressMaxHearts; state.reverseSunBoneHearts = reverseSunBoneHearts; + state.pendingPill = pendingPill; state.forgottenBodyRoomIdx = forgottenBodyRoomIdx; state.forgottenBodyPos = forgottenBodyPos; state.maggyHealthDrainCooldown = maggyHealthDrainCooldown; @@ -500,13 +482,17 @@ void Entity_Player::StoreGameState(GameStatePlayer* saveState, bool isSaveTempor if (isMine) state.charmedEnemies.push_back(charmed_enemy_save(*npc)); } - state.familiars.clear(); - for (Entity* entity : entities) + if (unlistedRestoreState && unlistedRestoreState.get() != &state) state.familiars = unlistedRestoreState->familiars; + else { - if (entity->type != ENTITY_FAMILIAR) continue; - Entity_Familiar& familiar = *static_cast(entity); - if (familiar.player == this && is_familiar_saved(familiar, isSaveTemporaryFamiliars)) - familiar.store_backup(&state.familiars.emplace_back()); + state.familiars.clear(); + for (Entity* entity : entities) + { + if (entity->type != ENTITY_FAMILIAR) continue; + Entity_Familiar& familiar = *static_cast(entity); + if (familiar.player == this && is_familiar_saved(familiar, isSaveTemporaryFamiliars)) + familiar.store_backup(&state.familiars.emplace_back()); + } } state.levelEffectItems = levelEffectItems; bool isBleedingOut = (flags & FLAG_BLEED_OUT) && bleedSource.entity == this; diff --git a/src/game_state.cpp b/src/game_state.cpp index 90915bb..b8aa102 100644 --- a/src/game_state.cpp +++ b/src/game_state.cpp @@ -424,7 +424,7 @@ void StateWriter::player_write(const GameStatePlayer& player) for (const PersistentEffect& effect : player.persistentEffects) for (int value : {effect.type, effect.id, effect.count, effect.cooldown}) write(value); write(player.reverseSunBoneHearts); - write(player.unknownTimer); + write(player.pendingPill); write((uint16_t)player.unknownValue); write(player.forgottenBodyRoomIdx); write(player.forgottenBodyPos.x); @@ -704,7 +704,7 @@ std::vector GameState::write() writer.write((uint16_t)deathCertificateExitTimer); writer.list_write(proceduralItemSeeds); writer.write(versusRules); - writer.list_write(versusPlayers); + writer.list_write(versusCollectibles); checksum = writer.seal(); return writer.bytes; @@ -1123,7 +1123,7 @@ bool StateReader::player_read(GameStatePlayer& player) if (!is_valid_item_config_id(effect.type, effect.id)) return fail(LOG_INFO, "[warn] Invalid temporary effect (type: %d, ID: %d)\n", effect.type, effect.id); } - fields_read(player.reverseSunBoneHearts, player.unknownTimer); + fields_read(player.reverseSunBoneHearts, player.pendingPill); player.unknownValue = read(); fields_read(player.forgottenBodyRoomIdx, player.forgottenBodyPos, player.lastCollectibleFrame, player.maggyHealthDrainCooldown); @@ -1459,7 +1459,7 @@ bool GameState::read(std::span file) deathCertificateExitTimer = reader.read(); reader.list_read(proceduralItemSeeds); versusRules = reader.read(); - reader.list_read(versusPlayers); + reader.list_read(versusCollectibles); bool isEndEarly = reader.is_end(); bool isSealMatching = (reader.read() ^ CHECKSUM_KEY) == checksum; diff --git a/src/game_state.h b/src/game_state.h index da972ab..0c3a37b 100644 --- a/src/game_state.h +++ b/src/game_state.h @@ -99,7 +99,7 @@ struct GameState std::vector encounteredBosses; std::vector erasedEntities; std::vector proceduralItemSeeds; - std::vector versusPlayers; + std::vector versusCollectibles; std::string rerunPath; std::string savePath; diff --git a/src/game_state_player.h b/src/game_state_player.h index c96496e..aa4c712 100644 --- a/src/game_state_player.h +++ b/src/game_state_player.h @@ -178,7 +178,7 @@ struct GameStatePlayer int speedModifier = 0; int strengthMaxHearts = 0; int tearRangeModifier = 0; - int unknownTimer = -1; + int pendingPill = -1; int unknownValue = 0; int wildCardItem = 0; int wildCardVarData = 0; diff --git a/src/game_update.cpp b/src/game_update.cpp index 1b0b0e6..c642c6f 100644 --- a/src/game_update.cpp +++ b/src/game_update.cpp @@ -140,15 +140,6 @@ static void trapdoor_loop_sfx_update(Game& game) sfx.pan_adjust(SOUND_TRAPDOOR_LOOP, pan); } -// 004291c0 Ticks the versus match's timer. Its intro, countdown, fight and result states never run offline, as no -// match starts there. -static void deathmatch_update(DeathmatchManager& deathmatch) -{ - deathmatch.timer++; - if (deathmatch.state >= DEATHMATCH_INTRO && deathmatch.state <= DEATHMATCH_RESULT) - reconstruction_missing("update_cutscene_state_machine 004291c0: the versus match's states"); -} - // Runs where a finished fade out leads: a menu, a restart (Eden's costs a token, and without one goes to the menus), // the victory lap or the versus arena. Holding restart also ends the win streak. // Netplay is offline, so the online targets restart at once or wait for a lobby that never comes. @@ -353,7 +344,7 @@ void Game::Update() trapdoor_loop_sfx_update(*this); hud.Update(); - deathmatch_update(deathmatchManager); + deathmatchManager.Update(); if (bloomTimer > 0) bloomTimer--; if (screenShakeTimer > 0 && --screenShakeTimer < 1) screenShakeOffset = {}; if (hallucinationTimer > 0) hallucinationTimer--; diff --git a/src/generic_prompt.cpp b/src/generic_prompt.cpp index 60c4c02..65e1379 100644 --- a/src/generic_prompt.cpp +++ b/src/generic_prompt.cpp @@ -12,7 +12,6 @@ constexpr const char* ANIMATION_DISAPPEAR = "Dissappear"; constexpr const char* TEXT_TOP_NULL = "TextTop"; constexpr int CURSOR_LAYER = 1; constexpr int SMALL_SHEET_LAYER = 2; -constexpr uint32_t PROMPT_TEXT_ARGB = 0xff362f2d; constexpr float TITLE_LINE_HEIGHT = 17; constexpr float TITLE_BODY_GAP = 12; constexpr float BODY_LINE_HEIGHT = 13; @@ -133,7 +132,7 @@ void GenericPrompt::Render() const NullFrame* textTop = sprite.GetNullFrame(TEXT_TOP_NULL); if (!textTop) return; - KColor color = kcolor_argb(PROMPT_TEXT_ARGB); + KColor color = kcolor_argb(TEXT_ARGB); FontSettings settings; float lineY = textTop->pos.y; auto line_draw = [&](Font& font, const std::string& text, float lineHeight) diff --git a/src/grid_entity.h b/src/grid_entity.h index ec2eb88..4c52d0a 100644 --- a/src/grid_entity.h +++ b/src/grid_entity.h @@ -63,9 +63,8 @@ constexpr int GRID_PATH_IMPASSABLE = 950; constexpr int GRID_PATH_BAND = 1000; constexpr int GRID_PATH_PIT = 3000; -// The seeds and RNG a grid entity holds before Init seeds it. +// The seed a grid entity holds before Init seeds it. constexpr uint32_t GRID_SEED_DEFAULT = 0x16a9de81; -constexpr RNG GRID_RNG_DEFAULT = {0xaa17414f, 5, 9, 7}; // The water clips the grid entities use. constexpr uint32_t WATER_CLIP_SOLID = 0x39; @@ -92,7 +91,7 @@ struct GridHurt struct GridEntity { ANM2 sprite; - RNG rng = GRID_RNG_DEFAULT; + RNG rng = RNG_DEFAULT; GridEntityType type = GRID_NULL; GridCollision collisionClass = COLLISION_NONE; int gridIndex = 0; diff --git a/src/grid_entity_door.cpp b/src/grid_entity_door.cpp index 1cc107b..2d63108 100644 --- a/src/grid_entity_door.cpp +++ b/src/grid_entity_door.cpp @@ -39,10 +39,8 @@ constexpr uint64_t GAME_STATE_HEART_EXIT_OPENED = 1ull << 52; constexpr int FAMILIAR_KEY_FULL = 28; constexpr int FAMILIAR_STATE_KEY_DOOR = 1; -// How far a door's sprite stands out from the wall, and the angles its sprites turn to by direction. +// How far a door's sprite stands out from the wall. constexpr float DOOR_SPRITE_OFFSET = 15; -constexpr float DOOR_ANGLES[4] = {-90, 0, 90, 180}; -constexpr float DEG_TO_RAD = 0.017453292f; // The frame a closing or opening door plays its sound on, and the sounds. constexpr int DOOR_SOUND_FRAME = 2; @@ -678,7 +676,7 @@ void GridEntity_Door::LoadSprite() doorFlags |= DOOR_FLAG_COIN_LOCK; } - float angle = (sprite.rotation + RIGHT_ANGLE_DEGREES) * DEG_TO_RAD; + float angle = (sprite.rotation + RIGHT_ANGLE_DEGREES) * DEGREES_TO_RADIANS; sprite.offset = vector_make(std::cos(angle) * offsetLength, std::sin(angle) * offsetLength); extraSprite.offset = sprite.offset; if (!extraSprite.isLoaded && isExtraAllowed) diff --git a/src/grid_entity_door.h b/src/grid_entity_door.h index fecb677..3df2c71 100644 --- a/src/grid_entity_door.h +++ b/src/grid_entity_door.h @@ -5,6 +5,8 @@ #include constexpr int DOOR_SIDES = 4; +// The angles a door's sprites turn to by its direction. +constexpr float DOOR_ANGLES[DOOR_SIDES] = {-90, 0, 90, 180}; // How a door is locked (Lua's DoorVariant). enum DoorVariant : int diff --git a/src/grid_entity_pit.cpp b/src/grid_entity_pit.cpp index c23d92e..0676b09 100644 --- a/src/grid_entity_pit.cpp +++ b/src/grid_entity_pit.cpp @@ -47,8 +47,6 @@ constexpr uint32_t MINESHAFT_DUST_ODDS = 40; constexpr int MINESHAFT_DUST_SUBTYPE = 2; constexpr float MINESHAFT_DUST_ALPHA_MIN = 0.1f; constexpr float MINESHAFT_DUST_ALPHA_RANGE = 0.2f; -constexpr float MINESHAFT_DUST_SPIN_MIN = 2; -constexpr float MINESHAFT_DUST_SPIN_RANGE = 10; constexpr int MINESHAFT_DUST_LIFE_MIN = 20; constexpr uint32_t MINESHAFT_DUST_LIFE_RANGE = 30; constexpr float MINESHAFT_DUST_SCALE_MIN = 0.8f; @@ -205,7 +203,7 @@ static void mineshaft_dust_spawn(const Vector& position) layer->blendMode = {mode.equation, mode.rgbSource, mode.rgbDest, mode.alphaSource, mode.alphaDest}; Entity_Effect& effect = static_cast(*dust); - effect.rotation = random_unit() * MINESHAFT_DUST_SPIN_RANGE + MINESHAFT_DUST_SPIN_MIN; + effect.rotation = random_between(DUST_SPIN_MIN, DUST_SPIN_RANGE); effect.timeout = (int)(Random() % MINESHAFT_DUST_LIFE_RANGE) + MINESHAFT_DUST_LIFE_MIN; effect.lifespan = effect.timeout; float scale = random_unit() * MINESHAFT_DUST_SCALE_RANGE + MINESHAFT_DUST_SCALE_MIN; diff --git a/src/grid_entity_poop.cpp b/src/grid_entity_poop.cpp index 3fcb349..8548a82 100644 --- a/src/grid_entity_poop.cpp +++ b/src/grid_entity_poop.cpp @@ -31,9 +31,8 @@ constexpr int POOP_STAGE_LAST_STANDING = 3; constexpr int POOP_STAGE_BROKEN = 4; constexpr uint32_t BONUS_HIT_ODDS = 3; -// The grid path a standing poop claims, how long a red poop takes to grow back, and its burn. +// The grid path a standing poop claims, and a red poop's burn. constexpr int GRID_PATH_POOP = 1500; -constexpr int RED_POOP_REVIVE_FRAMES = 120; constexpr float RED_POOP_DISTANCE = 22.5f; constexpr float RED_POOP_PLAYER_DISTANCE = 18.5f; constexpr float RED_POOP_DAMAGE = 16; @@ -105,7 +104,6 @@ constexpr int OH_CRAP_FORM_COUNT = 3; // The gibs: a third more of them per hit with Extra Blood, how fast they fly, and a rainbow gib's flatter throw. constexpr int POOP_EXTRA_BLOOD_GIBS = 3; constexpr float POOP_GIB_SPEED_MIN = 2; -constexpr float POOP_HALF_TURN = 3.14f; constexpr float RAINBOW_GIB_FLATTEN = 0.5f; constexpr float STONE_BREAK_SPEED = 4; constexpr int STONE_BREAK_COUNT = 3; @@ -584,7 +582,7 @@ void GridEntity_Poop::spawn_hit_gibs(const Vector& position, int poopVariant, in color._colorize[3] = 1; uint32_t seed = Random(); - float angle = random_unit() * POOP_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float speed = random_unit() + POOP_GIB_SPEED_MIN; Vector velocity = vector_make(std::cos(angle) * speed, std::sin(angle) * RAINBOW_GIB_FLATTEN * speed); @@ -789,7 +787,7 @@ static void golden_drops_spawn(const Vector& position, RNG& rng) Vector velocity{}; for (int attempt = 0; attempt < COIN_THROW_ATTEMPTS; attempt++) { - float angle = random_unit() * POOP_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; velocity = vector_make(std::cos(angle) * COIN_THROW_SPEED, std::sin(angle) * COIN_THROW_SPEED); if (room_check_line(position, vector_add(position, vector_scale(velocity, COIN_THROW_CHECK)), LINE_MODE_CELL, diff --git a/src/grid_entity_poop.h b/src/grid_entity_poop.h index 3d2873d..962c72e 100644 --- a/src/grid_entity_poop.h +++ b/src/grid_entity_poop.h @@ -24,9 +24,10 @@ enum PoopVariant : int POOP_STINKY }; -// A poop's state once broken, and a red poop's while it grows back. +// A poop's state once broken, a red poop's while it grows back, and how long it takes to grow back. constexpr int POOP_STATE_BROKEN = 1000; constexpr int POOP_STATE_REVIVING = 1000; +constexpr int RED_POOP_REVIVE_FRAMES = 120; // A hit on a poop as its rewards and drops see it: where it broke, its kind and seed, the state before the hit and // the damage dealt, and who dealt it. A poop reduced by ReduceSpawnRate rarely drops. The poop enemies leave out diff --git a/src/grid_entity_pressure_plate.cpp b/src/grid_entity_pressure_plate.cpp index 92fdd31..d15cdab 100644 --- a/src/grid_entity_pressure_plate.cpp +++ b/src/grid_entity_pressure_plate.cpp @@ -41,7 +41,6 @@ constexpr int ROOM_CLEAR_HOLD = 10; constexpr int AMBUSH_RESPAWN_FRAME = 4; // Greed's timer under the button: seconds and minutes, how far below the button it shows, and its grey blink. -constexpr int TIMER_FRAMES_PER_SECOND = 30; constexpr int TIMER_TEXT_SIZE = 32; constexpr int TIMER_BLINK_FRAMES = 4; constexpr float TIMER_PLATE_DROP = 21; @@ -202,7 +201,7 @@ static void greed_timer_render(Vector position) Game& game = *g_game; Font& font = g_manager->font4_terminus; int timer = game.room->greedWaveTimer; - int seconds = (timer - 1) / TIMER_FRAMES_PER_SECOND; + int seconds = (timer - 1) / FRAMES_PER_SECOND; int minutes = seconds / SECONDS_PER_MINUTE; char text[TIMER_TEXT_SIZE]; @@ -447,7 +446,7 @@ static void plate_ambush_spawn(GridEntity& plate, RNG& rng) { uint32_t seed = seeds.Next(); Vector position = room_free_pickup_position_find({.position = positions[(size_t)i % positions.size()]}); - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float distance = random_unit() * AMBUSH_SCATTER; position = vector_add(position, vector_make(std::cos(angle) * distance, std::sin(angle) * distance)); diff --git a/src/grid_entity_pressure_plate.h b/src/grid_entity_pressure_plate.h index 1480a14..22b339b 100644 --- a/src/grid_entity_pressure_plate.h +++ b/src/grid_entity_pressure_plate.h @@ -40,7 +40,7 @@ enum GreedButtonColor struct GridEntity_PressurePlate : GridEntity { ANM2 timerPlate; - RNG greedModeRNG = GRID_RNG_DEFAULT; + RNG greedModeRNG = RNG_DEFAULT; std::string_view nextGreedAnimation; void subclass_init() override; diff --git a/src/item_config.cpp b/src/item_config.cpp index 755597b..204b365 100644 --- a/src/item_config.cpp +++ b/src/item_config.cpp @@ -38,7 +38,6 @@ constexpr int SPECIAL_CHARGE_SEGMENTS_LAST = 12; // Ids and values the availability and charge rules name. constexpr int COLLECTIBLE_SACRED_ORB = 691; -constexpr unsigned int SPECIAL_DAILY_BANNED_SET = 52; constexpr uint32_t STAGE_VANISHING_TWIN_LAST = 6; constexpr int QUALITY_LOW_LAST = 1; constexpr int QUALITY_MIDDLE = 2; @@ -439,12 +438,10 @@ ActiveDischarge ItemConfig_Item::discharge_get() return chargeType == CHARGE_TIMED || isLongSpecial ? DISCHARGE_BAR : DISCHARGE_CHARGES; } -// Whether a deathmatch bans a pickup. The deathmatch type's ban checks (its vtable slots 9 to 12) have no -// declaration to call yet. -static bool is_deathmatch_banned() +// The rules of the versus match under way, which ban some pickups, or none outside a match. +static DeathmatchTypeBase* versus_rules_get() { - if (!g_game->deathmatchManager.is_active()) return false; - reconstruction_missing("DeathmatchType ban checks, vtable slots 9 to 12"); + return g_game->deathmatchManager.is_active() ? g_game->deathmatchManager.type.get() : nullptr; } static bool is_achievement_unlocked(int achievementId) @@ -470,7 +467,9 @@ bool ItemConfig_Item::IsAvailableEx(uint32_t checks) auto isListed = [&](std::span ids) { return std::ranges::find(ids, id) != ids.end(); }; if (isHidden) return false; - if (g_game && (IsCollectible() || IsTrinket()) && is_deathmatch_banned()) return false; + DeathmatchTypeBase* versus = g_game ? versus_rules_get() : nullptr; + if (versus && IsCollectible() && versus->is_collectible_banned(id)) return false; + if (versus && IsTrinket() && versus->is_trinket_banned(id)) return false; if (checks & AVAILABLE_FILTERS) for (auto filter = g_manager->itemConfig.availabilityFilters.rbegin(); filter != g_manager->itemConfig.availabilityFilters.rend(); filter++) @@ -484,7 +483,7 @@ bool ItemConfig_Item::IsAvailableEx(uint32_t checks) { if (game.challenge == CHALLENGE_ONANS_STREAK && isListed(WEAPON_COLLECTIBLES)) return false; if (game.seedEffects.HasSeedEffect(SEED_G_FUEL) && isListed(WEAPON_COLLECTIBLES)) return false; - if (game.dailyChallenge.specialDailyId == SPECIAL_DAILY_BANNED_SET && + if (game.dailyChallenge.specialDailyId == SPECIAL_DAILY_G_FUEL && isListed(SPECIAL_DAILY_BANNED_COLLECTIBLES)) return false; } @@ -564,7 +563,7 @@ bool ItemConfig_Card::IsAvailable() { if (!isGreedModeAllowed && g_game->IsGreedMode()) return false; if (id == CARD_SUICIDE_KING && g_game->playerManager.FirstPlayerByType(PLAYER_JACOB)) return false; - if (is_deathmatch_banned()) return false; + if (versus_rules_get() && versus_rules_get()->is_card_banned(id)) return false; } return is_achievement_unlocked(achievementId); } @@ -575,7 +574,7 @@ bool ItemConfig_Pill::IsAvailable() if (g_game) { if (!isGreedModeAllowed && g_game->IsGreedMode()) return false; - if (is_deathmatch_banned()) return false; + if (versus_rules_get() && versus_rules_get()->is_pill_banned(id)) return false; } return is_achievement_unlocked(achievementId); } @@ -1256,7 +1255,7 @@ ItemConfig_Item* ItemConfig::GetCollectible(int id) if (!g_game) return nullptr; auto& items = g_game->proceduralItemManager.proceduralItems; - return (size_t)~id < items.size() ? items[~id]->item : nullptr; + return (size_t)~id < items.size() ? items[~id]->item.get() : nullptr; } // 0072fd70 The trinket with this id, its golden flag ignored, or nullptr. diff --git a/src/item_pickup.cpp b/src/item_pickup.cpp index 4b75ffd..a6d4bbd 100644 --- a/src/item_pickup.cpp +++ b/src/item_pickup.cpp @@ -17,6 +17,7 @@ #include "procedural_item_manager.h" #include "log.h" #include "manager.h" +#include "npc_ai.h" #include "room.h" #include "room_grid.h" #include "room_special.h" @@ -26,6 +27,9 @@ #include #include +// A taken versus pedestal vanishes with a summoning sound this loud. +constexpr float VERSUS_PEDESTAL_VOLUME = 0.7f; + // The items, characters, rooms and unlocks the pedestals ask about. constexpr int COLLECTIBLE_KEY_PIECE_A = 238; constexpr int COLLECTIBLE_KEY_PIECE_B = 239; @@ -37,7 +41,6 @@ constexpr float CAIN_POOF_DROP = 10; constexpr int CAIN_PEDESTAL_TIMEOUT = 2; constexpr int COLLECTIBLE_KNIFE_PIECE_A = 626; constexpr int COLLECTIBLE_KNIFE_PIECE_B = 627; -constexpr int COLLECTIBLE_GLITCHED_GFUEL = -1; constexpr int ACHIEVEMENT_GLITCHED_ITEMS = 593; constexpr int EVENT_ANGEL_ITEMS_TAKEN = 15; constexpr uint32_t MONSTER_MANUEL_ODDS = 3; @@ -259,10 +262,7 @@ void Entity_Pickup::load_collectible_gfx(ANM2& itemSprite, int layerId, int coll if (collectibleId < 0) { if (!layer) return; - layer->spriteSheet = g_game->proceduralItemManager.renderTarget; - layer->cropOffset = vector_make((float)(~collectibleId % PROCEDURAL_CELLS_PER_ROW) * PROCEDURAL_CELL_SIZE, - (float)(~collectibleId / PROCEDURAL_CELLS_PER_ROW) * PROCEDURAL_CELL_SIZE); - layer->isSpriteSheetLoaded = true; + procedural_layer_set(*layer, collectibleId); layer->bitflags &= ~ITEM_LAYER_UNFILTERED; return; } @@ -583,8 +583,12 @@ bool Entity_Pickup::collectible_collect(Entity_Player& player) bool isInventoryItem = player.playerType == PLAYER_ISAAC_B && player.CanAddCollectibleToInventory(item->id); bool isExchanged = item->type == ITEM_ACTIVE ? active_pedestal_swap(*this, player) : isInventoryItem && tainted_isaac_pedestal_swap(*this, player); - if (game.deathmatchManager.is_active()) - reconstruction_missing("Entity_Pickup::HandleCollision 006e8ae0: the deathmatch's items"); + if (!isExchanged && game.deathmatchManager.is_active()) + { + game.Spawn({.position = pos, .type = ENTITY_EFFECT, .variant = EFFECT_POOF01, .seed = Random()}); + npc_sound_play(SOUND_SUMMONSOUND, VERSUS_PEDESTAL_VOLUME, 2, 1); + Kill(EntityRef()); + } SetAlternatePedestal(alternatePedestal); player.SetQueuedItem({item, heldCharge, isRetaken ? QUEUED_TOUCHED : 0u, heldVarData, itemPoolType}); @@ -608,8 +612,9 @@ bool Entity_Pickup::collectible_collect(Entity_Player& player) return shop_restock_after_take(*this); } -// The collectible part of 006e7dc0: a bought item rings like a pickup, 1up and the mushrooms and Super Bandage have -// their own sound, and any other item sounds by its room (the boss rooms, the treasure rooms and library, the shop, +// The collectible part of 006e7dc0: a bought item rings like a pickup, a glitched item may have its own sound, the +// G FUEL! sounds by its stacks, 1up and the mushrooms and Super Bandage have their own sound, and any other item +// sounds by its room (the boss rooms, the treasure rooms and library, the shop, // the devil's rooms, or any other). void Entity_Pickup::collectible_sound_play() { @@ -618,9 +623,9 @@ void Entity_Pickup::collectible_sound_play() SoundPlay play = {}; if (HasEntityFlags(FLAG_NO_DEATH_TRIGGER)) sound = SOUND_SHELLGAME; - else if (subtype < 0) reconstruction_missing("Entity_Pickup::PlayPickupSound 006e7dc0: a procedural item"); + else if (glitched_pickup_sound_play((int)subtype)) return; else if (subtype == COLLECTIBLE_GLITCHED_GFUEL && g_game->seedEffects.HasSeedEffect(SEED_G_FUEL)) - reconstruction_missing("Entity_Pickup::PlayPickupSound 006e7dc0: the G FUEL!"); + return g_fuel_pickup_sound_play((int)subtype); else if (subtype == COLLECTIBLE_1UP || subtype == COLLECTIBLE_MAGIC_MUSHROOM || subtype == COLLECTIBLE_MEGA_MUSH || subtype == COLLECTIBLE_MINI_MUSH || subtype == COLLECTIBLE_SUPER_BANDAGE) { diff --git a/src/item_pool.cpp b/src/item_pool.cpp index ebf72ff..42f922c 100644 --- a/src/item_pool.cpp +++ b/src/item_pool.cpp @@ -100,14 +100,6 @@ constexpr int ACHIEVEMENT_GOLD_PILLS = 603; constexpr int ACHIEVEMENT_HORSE_PILLS = 606; // The daily challenges that change what pools give. -constexpr uint32_t DAILY_TREASURE_LIST = 1; -constexpr uint32_t DAILY_ROTTEN_BOSSES = 16; -constexpr uint32_t DAILY_TREASURE_LIST_SHORT = 18; -constexpr uint32_t DAILY_EXPLOSIVE_PILLS = 41; -constexpr uint32_t DAILY_APPLE_BOSSES = 44; -constexpr uint32_t DAILY_TREASURE_RANDOM = 46; -constexpr uint32_t DAILY_TREASURE_FOUR = 50; -constexpr uint32_t DAILY_HOST_HAT = 52; constexpr int DAILY_TREASURE_LIST_ITEMS[] = {37, 125, 106, 19, 190, 140, 220, 65, 42, 137, 250, 131, 209, 52, 256, 344, 223, 353, 371, 432, 366, 367, 563, 583, 614, 727}; constexpr int DAILY_TREASURE_LIST_SHORT_ITEMS[] = {282, 382, 210, 60, 338, 12, 121, 120, 71, @@ -262,8 +254,8 @@ void ItemPool::Init(uint32_t startSeed, std::string_view path) for (auto& pill : config.pillEffects) { if (!pill || (!pill->isGreedModeAllowed && g_game && g_game->IsGreedMode())) continue; - if (g_game && g_game->deathmatchManager.is_active()) - reconstruction_missing("DeathmatchType pill ban, vtable slot 10"); + if (g_game && g_game->deathmatchManager.is_active() && g_game->deathmatchManager.type->is_pill_banned(pill->id)) + continue; if (!is_unlocked(pill->achievementId)) continue; effects.push_back(pill->id); @@ -527,19 +519,19 @@ int ItemPool::GetCollectible(ItemPoolType poolType, uint32_t drawSeed, uint32_t if (int item = lua_engine_get().PreGetCollectible(luaDraw)) return item; RNG dailyRng = rng_make(drawSeed, DAILY_SHIFT); - if (daily == DAILY_APPLE_BOSSES && poolType == POOL_BOSS) return COLLECTIBLE_APPLE; - if (daily == DAILY_TREASURE_RANDOM && poolType == POOL_TREASURE) + if (daily == SPECIAL_DAILY_SEPTEMBER_17 && poolType == POOL_BOSS) return COLLECTIBLE_APPLE; + if (daily == SPECIAL_DAILY_OCTOBER_6 && poolType == POOL_TREASURE) return DAILY_TREASURE_RANDOM_ITEMS[dailyRng.RandomInt( isBanActives ? DAILY_TREASURE_RANDOM_PASSIVES : std::size(DAILY_TREASURE_RANDOM_ITEMS))]; - if (daily == DAILY_TREASURE_FOUR && poolType == POOL_TREASURE) + if (daily == SPECIAL_DAILY_DECEMBER_23 && poolType == POOL_TREASURE) return DAILY_TREASURE_FOUR_ITEMS[dailyRng.RandomInt(std::size(DAILY_TREASURE_FOUR_ITEMS))]; RNG pickRng = rng_make(drawSeed, DRAW_SHIFT); uint32_t listFlags = LIST_PICK_BLACKLIST | (isBanActives ? LIST_PICK_BAN_ACTIVES : 0); std::span list; - if (daily == DAILY_ROTTEN_BOSSES && pool == POOL_BOSS) return COLLECTIBLE_ROTTEN_MEAT; - if (daily == DAILY_TREASURE_LIST && pool == POOL_TREASURE) list = DAILY_TREASURE_LIST_ITEMS; - if (daily == DAILY_TREASURE_LIST_SHORT && pool == POOL_TREASURE) list = DAILY_TREASURE_LIST_SHORT_ITEMS; + if (daily == SPECIAL_DAILY_THANKSGIVING && pool == POOL_BOSS) return COLLECTIBLE_ROTTEN_MEAT; + if (daily == SPECIAL_DAILY_NEW_YEAR && pool == POOL_TREASURE) list = DAILY_TREASURE_LIST_ITEMS; + if (daily == SPECIAL_DAILY_DECEMBER_6 && pool == POOL_TREASURE) list = DAILY_TREASURE_LIST_SHORT_ITEMS; if (!list.empty()) if (int item = GetCollectibleFromList(list, pickRng.Next(), 0, listFlags)) return item; @@ -585,7 +577,7 @@ int ItemPool::GetCollectible(ItemPoolType poolType, uint32_t drawSeed, uint32_t if (rosaryMultiplier > 1 && (int)pickRng.RandomInt((uint32_t)items->totalWeight) < rosaryMultiplier * ROSARY_CHANCE_PER_MULTIPLIER) result = COLLECTIBLE_ROSARY; - else if (result == COLLECTIBLE_PYROMANIAC && daily == DAILY_HOST_HAT) + else if (result == COLLECTIBLE_PYROMANIAC && daily == SPECIAL_DAILY_G_FUEL) result = COLLECTIBLE_HOST_HAT; } @@ -915,7 +907,7 @@ int ItemPool::GetPillEffect(uint32_t pillColor, Entity_Player* player) int effect = color < PILL_COLOR_SLOTS ? pillEffects[color] : PILL_EFFECT_NONE; bool isFalsePhd = false; - if (g_game->dailyChallenge.specialDailyId == DAILY_EXPLOSIVE_PILLS) return PILLEFFECT_EXPLOSIVE_DIARRHEA; + if (g_game->dailyChallenge.specialDailyId == SPECIAL_DAILY_AUGUST_16) return PILLEFFECT_EXPLOSIVE_DIARRHEA; if (player) { bool isPhd = player->HasCollectible(COLLECTIBLE_PHD) || player->HasCollectible(COLLECTIBLE_VIRGO) || @@ -983,8 +975,7 @@ int ItemPool::on_pill_used(int pillColor, uint32_t useSeed, uint32_t&) for (auto& pill : config.pillEffects) { if (!pill || (!pill->isGreedModeAllowed && g_game->IsGreedMode())) continue; - if (g_game->deathmatchManager.is_active()) - reconstruction_missing("ItemPool::on_pill_used 00736c30 (the deathmatch's pill ban)"); + if (g_game->deathmatchManager.is_active() && g_game->deathmatchManager.type->is_pill_banned(pill->id)) continue; if (is_unlocked(pill->achievementId) && !isHeld[pill->id]) candidates.push_back(pill->id); } @@ -993,10 +984,37 @@ int ItemPool::on_pill_used(int pillColor, uint32_t useSeed, uint32_t&) return pillEffects[slot]; } -// (00734cc0) Takes the effects deathmatch bans out of the pill colors. +// 00734cc0 In a versus match, gives each pill color holding a banned effect another available effect no color holds, +// drawn from the pool's generator. +// The original reads past an empty list of effects left. Here the color keeps no effect (-1). void ItemPool::remove_deathmatch_pill_effects() { - reconstruction_missing("ItemPool::remove_deathmatch_pill_effects 00734cc0"); + DeathmatchManager& versus = g_game->deathmatchManager; + if (!versus.is_active()) return; + + std::vector candidates; + for (auto& pill : g_manager->itemConfig.pillEffects) + { + if (!pill || !pill->IsAvailable()) continue; + bool isHeld = false; + for (int& effect : pillEffects) + { + if (effect != pill->id) continue; + isHeld = true; + if (versus.type->is_pill_banned(effect)) effect = -1; + } + if (!isHeld && !versus.type->is_pill_banned(pill->id)) candidates.push_back(pill->id); + } + + for (int color = 1; color < PILL_COLOR_SLOTS; color++) + { + if (pillEffects[color] != -1) continue; + uint32_t roll = itemPoolRNG.Next(); + if (candidates.empty()) continue; + auto pick = candidates.begin() + roll % candidates.size(); + pillEffects[color] = *pick; + candidates.erase(pick); + } } // 00734870 A card from a seed as MC_GET_CARD leaves it: special cards one in 25 unless only runes, runes one in ten diff --git a/src/item_pool.h b/src/item_pool.h index a4f4156..dec04a7 100644 --- a/src/item_pool.h +++ b/src/item_pool.h @@ -210,7 +210,7 @@ public: void IdentifyPill(uint32_t pillColor); bool IsPillIdentified(uint32_t pillColor); int on_pill_used(int pillColor, uint32_t useSeed, uint32_t& rngState); - static void remove_deathmatch_pill_effects(); + void remove_deathmatch_pill_effects(); static int GetCard(uint32_t drawSeed, bool isPlaying, bool isRunes, bool isOnlyRunes); static int GetCardEx(int drawSeed, int specialChance, int runeChance, int suitChance, bool isNonCardsAllowed); diff --git a/src/leaderboard.cpp b/src/leaderboard.cpp index 4b80a36..4352bd6 100644 --- a/src/leaderboard.cpp +++ b/src/leaderboard.cpp @@ -6,6 +6,7 @@ #include "menu_manager.h" #include "render_passes.h" #include +#include constexpr const char* SCORE_MENU_ANM2 = "gfx/ui/ScoreMenu.anm2"; constexpr const char* LEADERBOARD_MENU_ANM2 = "gfx/ui/LeaderboardMenu.anm2"; @@ -20,6 +21,15 @@ constexpr int GAME_FADE_TARGET_MENU = 2; constexpr float GAME_FADE_SPEED = 0.08f; constexpr float DIM_SHADE = 0.3f; constexpr float DIM_ALPHA = 0.5f; +// The breakdown sheet: its nulls, a line's height and the label's inset from the mirrored side, the gap before the +// total and the finish time, and the finish time label's length. +constexpr const char* NULL_TEXT = "Text"; +constexpr const char* NULL_SCORE_RANK = "ScoreRank"; +constexpr const char* NULL_TIME_RANK = "TimeRank"; +constexpr float BREAKDOWN_LINE_HEIGHT = 15; +constexpr float BREAKDOWN_LABEL_INSET = 16; +constexpr float BREAKDOWN_TOTAL_GAP = 10; +constexpr size_t FINISH_LABEL_LENGTH = 71; // Whether a sprite stopped, or never started. static bool is_sprite_stopped(const ANM2& sprite) @@ -265,12 +275,103 @@ void Leaderboard::download_entries(LeaderboardKind kind, LeaderboardScope scope) } } -// 008588f0 Draws the breakdown: the bonuses, penalties and total of the run, its finish time, and the score and time -// ranks once submitted. +// 00859100 (leaderboard_render_label_value) Draws a breakdown line, its label mirrored across the screen from the +// right-aligned value, and moves down a line. +static void breakdown_line_render(Vector& position, std::string_view label, int value) +{ + Font& font = g_manager->font2_TeamMeatEx12; + std::string text = std::to_string(value); + KColor color = kcolor_argb(TEXT_ARGB); + FontSettings settings; + + font.DrawString(label, vector_make(g_screenWidth - position.x - BREAKDOWN_LABEL_INSET, position.y), + vector_make(1, 1), color, settings); + font.DrawString(text, vector_make(position.x - (float)(uint32_t)font.GetStringWidth(text), position.y), + vector_make(1, 1), color, settings); + position.y += BREAKDOWN_LINE_HEIGHT; +} + +// 00858870 A rank as an English ordinal (1st, 2nd, 3rd, 11th ...), or N/A without one. +static std::string rank_text_get(int rank) +{ + if (rank < 1) return "N/A"; + int lastTwo = rank % 100; + bool isTeen = lastTwo >= 11 && lastTwo <= 13; + std::string_view suffix = "th"; + if (!isTeen && rank % 10 == 1) suffix = "st"; + if (!isTeen && rank % 10 == 2) suffix = "nd"; + if (!isTeen && rank % 10 == 3) suffix = "rd"; + return std::format("{}{}", rank, suffix); +} + +// 008588f0 Draws the breakdown sheet: from its Text null the bonuses (the boss bonuses only when won), penalties and +// total of the run, then its finish time once a floor was finished, and once both scores were submitted the score and +// time ranks centered on their nulls, as faded as the ScoreRank null. +// The original reads the ScoreRank null's fade for the time rank even when that null is missing, and crashes. Here +// the time rank then keeps its own null's. void Leaderboard::render_daily_score_breakdown() { - reconstruction_missing("Leaderboard::render_daily_score_breakdown 008588f0: shown after a daily run, which needs " - "the online boards"); + StringTable& strings = g_manager->stringTable; + Font& font = g_manager->font2_TeamMeatEx12; + ScoreSheet& sheet = scoreSheet; + Vector anchor = vector_make((g_screenWidth - MENU_WIDTH) * 0.5f, (g_screenHeight - MENU_HEIGHT) * 0.5f); + AnimationState& state = scoreSprite.animState; + auto nullGet = [&](std::string_view name) { return state.animData ? state.GetNullFrame(name) : nullptr; }; + + scoreSprite.Render({.position = anchor}); + if (const NullFrame* text = nullGet(NULL_TEXT)) + { + Vector position = vector_add(anchor, text->pos); + auto line = [&](const char* key, int value) { breakdown_line_render(position, strings.translate(key), value); }; + auto bonus = [&](const char* key, int value) { if (value > 0) line(key, value); }; + line("#DAILY_RUN_STAGE_BONUS", sheet.stageBonus); + line("#DAILY_RUN_EXPLORATION_BONUS", sheet.explorationBonus); + line("#DAILY_RUN_SCHWAG_BONUS", sheet.schwagBonus); + bonus("#DAILY_RUN_???_BONUS", sheet.blueBabyBonus); + bonus("#DAILY_RUN_LAMB_BONUS", sheet.lambBonus); + bonus("#DAILY_RUN_MOTHER_BONUS", sheet.motherBonus); + bonus("#DAILY_RUN_DELIRIUM_BONUS", sheet.deliriumBonus); + bonus("#DAILY_RUN_BEAST_BONUS", sheet.beastBonus); + bonus("#DAILY_RUN_RUSH_BONUS", sheet.rushBonus); + bonus("#DAILY_RUN_MEGA_SATAN_BONUS", sheet.megaSatanBonus); + line("#DAILY_RUN_DAMAGE_PENALTY", -sheet.damagePenalty); + line("#DAILY_RUN_TIME_PENALTY", -sheet.timePenalty); + line("#DAILY_RUN_ITEM_PENALTY", -sheet.itemPenalty); + position.y += BREAKDOWN_TOTAL_GAP; + line("#DAILY_RUN_TOTAL", sheet.totalScore); + + if (sheet.runTimeLevel > 0) + { + uint32_t seconds = (uint32_t)sheet.runTime / FRAMES_PER_SECOND; + uint32_t minutes = seconds % SECONDS_PER_HOUR / SECONDS_PER_MINUTE; + std::string time = + std::format("{}:{:02}:{:02}", seconds / SECONDS_PER_HOUR, minutes, seconds % SECONDS_PER_MINUTE); + std::string label(strings.translate("#DAILY_RUN_FINISH_TIME").substr(0, FINISH_LABEL_LENGTH)); + float y = position.y + BREAKDOWN_TOTAL_GAP; + KColor color = kcolor_argb(TEXT_ARGB); + FontSettings settings; + float labelX = g_screenWidth - position.x - BREAKDOWN_LABEL_INSET; + font.DrawString(label, vector_make(labelX, y), vector_make(1, 1), color, settings); + font.DrawString(time, vector_make(position.x - (float)(uint32_t)font.GetStringWidth(time), y), + vector_make(1, 1), color, settings); + } + } + if (!isScoreSubmitted || !isTimeSubmitted) return; + + const NullFrame* scoreNull = nullGet(NULL_SCORE_RANK); + const NullFrame* timeNull = nullGet(NULL_TIME_RANK); + auto rankRender = [&](const NullFrame* frame, int rank) + { + std::string text = rank_text_get(rank); + Vector position = vector_add(anchor, frame->pos); + KColor color = kcolor_argb(TEXT_ARGB); + FontSettings settings; + color._alpha = (scoreNull ? scoreNull : frame)->color._tint[3]; + position.x -= (float)((uint32_t)font.GetStringWidth(text) >> 1); + font.DrawString(text, position, vector_make(1, 1), color, settings); + }; + if (scoreNull) rankRender(scoreNull, scoreRank); + if (timeNull) rankRender(timeNull, timeRank); } // 00859290 Draws the boards: their kind, scope and day, and the page of rows. diff --git a/src/level.cpp b/src/level.cpp index 8a7f9dd..47b34cb 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -55,7 +55,6 @@ constexpr uint32_t CHALLENGE_XXXXXXXXL = 21; constexpr int ALT_PATH_LAYER_FIRST = 3; constexpr int DIMENSION_MINESHAFT = 2; // X-Ray Vision opening a hidden door: the wall crack turned to the door's side, and its sound. -constexpr int XRAY_DOOR_SIDES = 4; constexpr float XRAY_WALL_TURN = 90; constexpr float XRAY_SOUND_VOLUME = 0.75f; constexpr int XRAY_SOUND_DELAY = 10; @@ -82,9 +81,6 @@ constexpr uint32_t NUMERAL_EXCLAIM = 4; constexpr uint32_t NUMERAL_ELLIPSIS = 5; constexpr uint32_t NUMERAL_SPIKES = 1001; constexpr std::string_view DEATHMATCH_NAME_KEY = "Online/DEATHMATCH_NAME"; -constexpr uint32_t SPECIAL_DAILY_NO_CURSES = 18; -constexpr uint32_t SPECIAL_DAILY_DEALS = 17; -constexpr uint32_t SPECIAL_DAILY_CURSED = 37; constexpr uint32_t SPECIAL_DAILY_CURSES = CURSE_OF_THE_LOST | CURSE_OF_THE_UNKNOWN | CURSE_OF_BLIND; constexpr int ACHIEVEMENT_SOMETHING_FROM_THE_FUTURE = 16; @@ -143,7 +139,6 @@ constexpr int TREASURE_SUBTYPE_OPTIONS_PAY_TO_WIN = 3; constexpr uint32_t TREASURE_OPTIONS_ODDS = 100; constexpr uint32_t HORSE_SHOE_PERIOD = 100; constexpr uint32_t HORSE_SHOE_HITS = 15; -constexpr uint32_t SPECIAL_DAILY_TREASURE_OPTIONS = 19; constexpr uint32_t DICE_ROOM_ODDS = 50; constexpr uint32_t DICE_ROOM_KEY_ODDS = 5; constexpr uint32_t SACRIFICE_ROOM_ODDS = 7; @@ -279,7 +274,6 @@ constexpr float SPLAT_LENGTH = 128; constexpr float SPLAT_SPREAD = 40; constexpr float SPLAT_SCALE_RANGE = 5; constexpr float SPLAT_SCALE_MIN = 0.5f; -constexpr float QUARTER_TURN = 1.5707964f; constexpr ColorMod SPLAT_COLOR = {{0.8f, 0.8f, 0.8f, 1}, {0, 0, 0, 0}, {0, 0, 0}}; // The cell offsets of the four sides: left, up, right, down. @@ -566,7 +560,7 @@ void Level::Init(bool isResetLilPortalRoom) curseRng.SetSeed(generationRNG._seed, DEFAULT_SHIFT_INDEX); bool isCurseRolled = stage != STAGE_HOME && !IsAscent() && curseOdds != 0 && !game.playerManager.FirstCollectibleOwner(COLLECTIBLE_BLACK_CANDLE, LAZARUS_SHARE_CHECK) && - game.dailyChallenge.specialDailyId != SPECIAL_DAILY_NO_CURSES; + game.dailyChallenge.specialDailyId != SPECIAL_DAILY_DECEMBER_6; curses = CURSE_NONE; if (isCurseRolled) @@ -616,7 +610,7 @@ void Level::Init(bool isResetLilPortalRoom) curses = lua_engine_get().PostCurseEval(curses); } - if (game.dailyChallenge.specialDailyId == SPECIAL_DAILY_CURSED) curses |= SPECIAL_DAILY_CURSES; + if (game.dailyChallenge.specialDailyId == SPECIAL_DAILY_JULY_2) curses |= SPECIAL_DAILY_CURSES; if (game.challenge != 0) { ChallengeParam& params = g_manager->GetChallengeParams((int)game.challenge); @@ -1520,7 +1514,7 @@ static int treasure_subtype_get(RNG& rng) isOptions = (isHorseShoe && players.FirstTrinketOwner(TRINKET_GOLDEN_HORSE_SHOE, nullptr, LAZARUS_SHARE_CHECK)) || - g_game->dailyChallenge.specialDailyId == SPECIAL_DAILY_TREASURE_OPTIONS; + g_game->dailyChallenge.specialDailyId == SPECIAL_DAILY_CHRISTMAS; } bool isPayToWin = players.FirstTrinketOwner(TRINKET_PAY_TO_WIN, nullptr, LAZARUS_SHARE_CHECK); @@ -2937,7 +2931,7 @@ void Level::reveal_room_visibility(RoomDescriptor& target, RoomDescriptor* fromR uint32_t seed = Random(); Entity* wall = g_game->Spawn( {.position = door.Position(), .type = ENTITY_EFFECT, .variant = EFFECT_XRAY_WALL, .seed = seed}); - wall->sprite.rotation = (float)(doorSlot % XRAY_DOOR_SIDES - 1) * XRAY_WALL_TURN; + wall->sprite.rotation = (float)(doorSlot % DOOR_SIDES - 1) * XRAY_WALL_TURN; door.variant = DOOR_UNSPECIFIED; int sound = SOUND_DEATH_CARD; seed_fart_sound_override(&sound); @@ -4171,7 +4165,7 @@ bool Level::CanSpawnDevilRoom() int dealStage = labyrinthStage + (isAltStage ? 1 : 0); if (!is_greed()) { - if (dealStage == (int)STAGE_BASEMENT_I && game.dailyChallenge.specialDailyId != SPECIAL_DAILY_DEALS) + if (dealStage == (int)STAGE_BASEMENT_I && game.dailyChallenge.specialDailyId != SPECIAL_DAILY_DECEMBER_5) return false; if (dealStage != (int)STAGE_BASEMENT_I && dealStage > (int)STAGE_WOMB_II) return false; if (dealStage == (int)STAGE_DEPTHS_II && !is_unlocked(ACHIEVEMENT_THE_WOMB)) return false; @@ -4262,7 +4256,7 @@ void Level::InitializeDevilAngelRoom(bool isForceAngel, bool isForceDevil) uint32_t odds = 0; if (game.gameStateFlags & (1ull << GAME_STATE_DEVILROOM_VISITED | 1ull << GAME_STATE_KRAMPUS_SPAWNED)) odds = game.devilRoomDeals > 0 ? KRAMPUS_ODDS_DEAL : KRAMPUS_ODDS_VISITED; - bool isDealsDaily = game.dailyChallenge.specialDailyId == SPECIAL_DAILY_DEALS; + bool isDealsDaily = game.dailyChallenge.specialDailyId == SPECIAL_DAILY_DECEMBER_5; if (isDealsDaily) odds += KRAMPUS_ODDS_DEALS_DAILY; if (devilAngelRoomRNG.Next() % KRAMPUS_ROLL >= odds || query.minVariant >= DEAL_VARIANT_WOMB) return; diff --git a/src/level.h b/src/level.h index 7ee9d2a..4542b66 100644 --- a/src/level.h +++ b/src/level.h @@ -25,9 +25,6 @@ constexpr int GREED_STAGE_SHOP = 5; 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 mirror world's dimension (the mineshaft's on a Mines floor) and Death Certificate's. constexpr int DIMENSION_MIRROR = 1; constexpr int DIMENSION_DEATH_CERTIFICATE = 2; @@ -71,6 +68,7 @@ enum OffMapRoom : int ROOM_BLUE_ROOM_IDX = -16, ROOM_EXTRA_BOSS_IDX = -17, ROOM_ANGEL_SHOP_IDX = -18, + ROOM_DEATHMATCH_IDX = -19, ROOM_LIL_PORTAL_IDX = -20 }; @@ -237,8 +235,8 @@ public: DimensionReturn deathCertificateReturn; std::unique_ptr room; int* currentRoomMap = nullptr; - RNG devilAngelRoomRNG = LEVEL_RNG_DEFAULT; - RNG generationRNG = LEVEL_RNG_DEFAULT; + RNG devilAngelRoomRNG = RNG_DEFAULT; + RNG generationRNG = RNG_DEFAULT; Vector dungeonReturnPosition{}; float angelRoomChance = 0; int bombPickupsSpawned = 0; diff --git a/src/lua_api.cpp b/src/lua_api.cpp index aa25372..d59a5f2 100644 --- a/src/lua_api.cpp +++ b/src/lua_api.cpp @@ -8,7 +8,7 @@ static int field_raw_get(lua_State* state, int index, const char* name) return lua_rawget(state, index < 0 ? index - 1 : index); } -// Sets field name of the table at index to the value on top, popping it, without metamethods. +// (0085bf90, 0085da20) Sets field name of the table at index to the value on top, popping it, without metamethods. void lua_table_set(lua_State* state, int table, const char* name) { lua_pushstring(state, name); @@ -25,8 +25,8 @@ void lua_property_set(lua_State* state, const char* table, const char* name) lua_pop(state, 1); } -// __index of objects, classes and namespaces: a method or field of the metatable, else a property getter, else the -// same in each parent class, else nil. +// (0085c810, 0085cd40) __index of objects, classes and namespaces: a method or field of the metatable, else a property +// getter, else the same in each parent class, else nil. static int index_get(lua_State* state) { lua_getmetatable(state, 1); @@ -54,8 +54,8 @@ static int index_get(lua_State* state) } } -// __newindex of objects, classes and namespaces: a property setter of the class or a parent. Anything else raises -// an error, so scripts add to namespaces with rawset. +// (0085c970, 0085cf30, 0085cad0) __newindex of objects, classes and namespaces: a property setter of the class or a +// parent. Anything else raises an error, so scripts add to namespaces with rawset. static int index_set(lua_State* state) { lua_getmetatable(state, 1); @@ -81,7 +81,7 @@ static int index_set(lua_State* state) } } -// Pushes an object as a userdata holding its pointer, with its class's metatable, or nil for none. +// (0085c7e0) Pushes an object as a userdata holding its pointer, with its class's metatable, or nil for none. void lua_object_push(lua_State* state, void* object, LuaClass luaClass) { if (!object) return lua_pushnil(state); @@ -91,7 +91,8 @@ void lua_object_push(lua_State* state, void* object, LuaClass luaClass) lua_setmetatable(state, -2); } -// The object argument index holds when it is of the class or one derived from it. Raises an argument error if not. +// (0085c590, 0085c3e0) The object argument index holds when it is of the class or one derived from it. Raises an +// argument error if not. void* lua_object_check(lua_State* state, int index, LuaClass luaClass) { void** block = lua_type(state, index) == LUA_TUSERDATA ? (void**)lua_touserdata(state, index) : nullptr; @@ -130,7 +131,7 @@ static void table_init(lua_State* state, const char* name) lua_table_set(state, -2, "__name"); } -// Begins a class as LuaBridge lays one out: a static table that is its own metatable, holding the constructor and +// (0085d040, 0085d2c0, 0085d500) Begins a class as LuaBridge lays one out: a static table that is its own metatable, holding the constructor and // static functions with __class pointing at the class table, the metatable its objects get. The class table keeps the // methods and properties, with __parent pointing at the parent class's. Leaves the static and class tables on top. void lua_class_begin(lua_State* state, const char* name, LuaClass luaClass, LuaClass parent) @@ -153,7 +154,7 @@ void lua_class_begin(lua_State* state, const char* name, LuaClass luaClass, LuaC lua_rawsetp(state, LUA_REGISTRYINDEX, lua_class_key(luaClass)); } -// Begins a namespace: a table that is its own metatable, left on top twice so functions and properties are added to +// (0085d730, 0085da00) Begins a namespace: a table that is its own metatable, left on top twice so functions and properties are added to // it as to a class. void lua_namespace_begin(lua_State* state, const char* name) { @@ -164,7 +165,7 @@ void lua_namespace_begin(lua_State* state, const char* name) lua_pushvalue(state, -1); } -// Ends the class or namespace begun last, naming it as a global or in the namespace below it. +// (0085d910, 0085d980, 0085cce0, 00872510) Ends the class or namespace begun last, naming it as a global or in the namespace below it. void lua_class_end(lua_State* state, LuaScope scope) { field_raw_get(state, -1, "__name"); diff --git a/src/lua_api.h b/src/lua_api.h index 7970e44..246318b 100644 --- a/src/lua_api.h +++ b/src/lua_api.h @@ -280,7 +280,7 @@ void lua_copy_push(lua_State* state, const T& value) lua_setmetatable(state, -2); } -// Pushes a value as the API does: numbers, booleans and strings as themselves, objects by pointer (nil for none) and +// (0085c010, 0085c030, 0085c050) Pushes a value as the API does: numbers, booleans and strings as themselves, objects by pointer (nil for none) and // class values as copies. template void lua_push(lua_State* state, const T& value) diff --git a/src/lua_api_bit_set128.cpp b/src/lua_api_bit_set128.cpp index ef0636a..0afc71a 100644 --- a/src/lua_api_bit_set128.cpp +++ b/src/lua_api_bit_set128.cpp @@ -24,8 +24,8 @@ static LuaBitSet bit_set_make(uint64_t low, uint64_t high) return LuaBitSet(high) << BIT_SET_HALF | LuaBitSet(low); } -// (008bc330, 0085e490, 0085e4d0, 0085e4f0, 0085e510, 00592200, 0085e530, 0085e560, 0085e5c0) Registers Lua's -// BitSet128, the 128 bit flags tears and bombs carry, with l and h as its halves. +// (008bc330, 0085e490, 0085e4d0, 0085e4f0, 0085e510, 0085dae0, 00592200, 0085e530, 0085e560, 0085e5c0) +// Registers Lua's BitSet128, the 128 bit flags tears and bombs carry, with l and h as its halves. // Get and Set ignore bits past 127, which the original wraps into the 128. void lua_api_bit_set128_register(lua_State* state) { diff --git a/src/lua_api_color.cpp b/src/lua_api_color.cpp index 21796b8..029d4df 100644 --- a/src/lua_api_color.cpp +++ b/src/lua_api_color.cpp @@ -14,7 +14,8 @@ static void color_channel_add(lua_State* state, const char* name) } // (008bb5c0, 008bb3b0, 008a9360) Registers Lua's Color, the game's ColorMod: a tint, a colorize and an offset, with -// multiplication changing the left color and returning it, and KColor, a plain color. +// multiplication changing the left color and returning it, and KColor, a plain color. The offset setters only Lua +// calls (005cd3d0, 005cd3f0, 005cd410) are color_channel_add's. void lua_api_color_register(lua_State* state) { lua_class_begin(state, "Color", LUA_CLASS_COLOR); diff --git a/src/lua_api_entities.cpp b/src/lua_api_entities.cpp index a46bdfc..4327c91 100644 --- a/src/lua_api_entities.cpp +++ b/src/lua_api_entities.cpp @@ -16,6 +16,10 @@ #include "weapon.h" #include +// The range Lua's EntityPickup.ShopItemId keeps a written id in: anything below -1 becomes -2. +constexpr int SHOP_ITEM_ID_LOWEST = -2; +constexpr int SHOP_ITEM_ID_HIGHEST = 7; + // The entities of a query as the EntityList Lua copies out. template static EntityList_EL entity_list_make(const std::vector& entities) { @@ -38,7 +42,8 @@ static int familiar_orbit_count(Entity_Familiar& familiar, int layer, bool isJoi return (int)std::ranges::count_if(familiar_query(-1), isOrbiter) + isJoining; } -// Registers Lua's EntityTear and EntityProjectile, the shots of players and enemies. +// Registers Lua's EntityTear and EntityProjectile, the shots of players and enemies. The projectile setters only Lua +// calls (004aad50, 0085e340) are lua_field's. static void shots_register(lua_State* state) { lua_class_begin(state, "EntityTear", LUA_CLASS_TEAR, LUA_CLASS_ENTITY); @@ -57,12 +62,12 @@ static void shots_register(lua_State* state) lua_field<&Entity_Tear::rotation>(state, "Rotation"); lua_field<&Entity_Tear::waitFrames>(state, "WaitFrames"); lua_field<&Entity_Tear::homingFriction>(state, "HomingFriction"); - lua_field<&Entity_Tear::baseScale>(state, "BaseScale"); - lua_field<&Entity_Tear::baseDamage>(state, "BaseDamage"); + lua_field_get<&Entity_Tear::baseScale>(state, "BaseScale"); + lua_field_get<&Entity_Tear::baseDamage>(state, "BaseDamage"); lua_field<&Entity_Tear::knockbackMultiplier>(state, "KnockbackMultiplier"); lua_field<&Entity_Tear::continueVelocity>(state, "ContinueVelocity"); lua_field<&Entity_Tear::parentOffset>(state, "ParentOffset"); - lua_field<&Entity_Tear::posDisplacement>(state, "PosDisplacement"); + lua_field_get<&Entity_Tear::posDisplacement>(state, "PosDisplacement"); lua_field<&Entity_Tear::stickDiff>(state, "StickDiff"); lua_field<&Entity_Tear::stickTimer>(state, "StickTimer"); lua_field<&Entity_Tear::isCanTriggerStreakEnd>(state, "CanTriggerStreakEnd"); @@ -161,6 +166,8 @@ static void weapons_register(lua_State* state) lua_method(state, "IsSampleLaser", [](Entity_Laser& laser) { return laser.isSampleLaser; }); lua_field<&Entity_Laser::rotationDelay>(state, "RotationDelay"); lua_field<&Entity_Laser::bounceLaser>(state, "BounceLaser"); + // HomingLaser is a class the original never registers, so its setter (0085e000, the copy it would make) fails on + // every value. The original crashes reading it. This leaves the property read-only, so a write raises an error. lua_property(state, "HomingLaser", [](Entity_Laser&) { return LuaOpaque{}; }); lua_method(state, "GetRenderZ", [](Entity_Laser& laser) { return laser.GetRenderZ(); }); lua_method(state, "GetEndPoint", [](Entity_Laser& laser) -> Vector& { return laser.endPoint; }); @@ -174,7 +181,8 @@ static void weapons_register(lua_State* state) lua_class_end(state); } -// Registers Lua's EntityFamiliar and EntityEffect. +// Registers Lua's EntityFamiliar and EntityEffect. The familiar setters only Lua calls (0060d0d0, 0060d0f0, 005b18d0) +// are lua_field's. static void companions_register(lua_State* state) { lua_class_begin(state, "EntityFamiliar", LUA_CLASS_FAMILIAR, LUA_CLASS_ENTITY); @@ -210,8 +218,8 @@ static void companions_register(lua_State* state) lua_field<&Entity_Familiar::orbitSpeed>(state, "OrbitSpeed"); lua_field<&Entity_Familiar::orbitLayer>(state, "OrbitLayer"); lua_field<&Entity_Familiar::roomClearCount>(state, "RoomClearCount"); - lua_field_get<&Entity_Familiar::isDelayed>(state, "IsDelayed"); - lua_field_get<&Entity_Familiar::isFollower>(state, "IsFollower"); + lua_field<&Entity_Familiar::isDelayed>(state, "IsDelayed"); + lua_field<&Entity_Familiar::isFollower>(state, "IsFollower"); lua_method(state, "AddCoins", [](Entity_Familiar& familiar, int count) { familiar.AddCoins(count); }); lua_method(state, "AddHearts", [](Entity_Familiar& familiar, int amount) { familiar.AddHearts(amount); }); lua_method(state, "AddKeys", [](Entity_Familiar& familiar, int amount) { familiar.AddKeys(amount); }); @@ -261,7 +269,8 @@ static void companions_register(lua_State* state) lua_class_end(state); } -// Registers Lua's EntityNPC, enemies and other characters, and EntityPickup. +// Registers Lua's EntityNPC, enemies and other characters, and EntityPickup. The pickup setters only Lua calls +// (005b1950, 005b1970, 00436210, 0071df70) are lua_field's. static void npc_pickup_register(lua_State* state) { lua_class_begin(state, "EntityNPC", LUA_CLASS_NPC, LUA_CLASS_ENTITY); @@ -284,13 +293,17 @@ static void npc_pickup_register(lua_State* state) lua_field<&Entity_NPC::v2>(state, "V2"); lua_field<&Entity_NPC::projectileCooldown>(state, "ProjectileCooldown"); lua_field<&Entity_NPC::projectileDelay>(state, "ProjectileDelay"); - lua_field_get<&Entity_NPC::groupIdx>(state, "GroupIdx"); + lua_field<&Entity_NPC::groupIdx>(state, "GroupIdx"); lua_property( state, "Scale", [](Entity_NPC& npc) { return npc.scale; }, [](Entity_NPC& npc, float scale) { npc.SetScale(scale); }); lua_property( state, "EntityRef", [](Entity_NPC& npc) { return npc.entityRef.get(); }, [](Entity_NPC& npc, Entity* entity) { npc.entityRef = entity; }); + // (00436220) CanShutDoors is a property here, a method on Entity. Writing it sets the flag unless the NPC is friendly. + lua_property( + state, "CanShutDoors", [](Entity_NPC& npc) { return npc.CanShutDoors(); }, + [](Entity_NPC& npc, bool isOn) { npc.isCanShutDoors = isOn && !npc.IsFriendly(); }); lua_property(state, "ParentNPC", [](Entity_NPC& npc) { return dynamic_cast(npc.parent.get()); }); lua_property(state, "ChildNPC", [](Entity_NPC& npc) { return dynamic_cast(npc.child.get()); }); lua_method(state, "Morph", [](Entity_NPC& npc, int type, int variant, int subType, int championColor) { @@ -313,7 +326,10 @@ static void npc_pickup_register(lua_State* state) }); lua_method(state, "MakeSplat", [](Entity_NPC& npc, float size) { return npc.MakeSplat(size); }); lua_method(state, "KillUnique", [](Entity_NPC& npc) { npc.KillUnique(); }); - lua_property(state, "Pathfinder", [](Entity_NPC& npc) -> PathFinder& { return npc.pathfinder; }); + // Pathfinder hands out a copy, as the original's does, which still steers the NPC through its owner. + lua_property( + state, "Pathfinder", [](Entity_NPC& npc) { return npc.pathfinder; }, + [](Entity_NPC& npc, PathFinder& pathfinder) { npc.pathfinder = pathfinder; }); lua_method(state, "ResetPathFinderTarget", [](Entity_NPC& npc) { npc.ResetPathFinderTarget(); }); lua_method(state, "GetAliveEnemyCount", [](Entity_NPC& npc) { return npc.GetAliveEnemyCount(); }); lua_method(state, "FireProjectiles", [](Entity_NPC& npc, Vector position, Vector velocity, ProjectilesMode mode, @@ -324,8 +340,7 @@ static void npc_pickup_register(lua_State* state) const ProjectileParams& params) { return npc.FireBossProjectiles(count, target, trajectory, params); }); - lua_method(state, "ThrowSpider", [](Entity_NPC&, Vector position, Entity* spawner, Vector target, bool isBig, - float yOffset) { + lua_static(state, "ThrowSpider", [](Vector position, Entity* spawner, Vector target, bool isBig, float yOffset) { return Entity_NPC::ThrowSpider(position, spawner, target, isBig, yOffset); }); lua_class_end(state); @@ -333,7 +348,12 @@ static void npc_pickup_register(lua_State* state) lua_class_begin(state, "EntityPickup", LUA_CLASS_PICKUP, LUA_CLASS_ENTITY); lua_field<&Entity_Pickup::charge>(state, "Charge"); lua_field<&Entity_Pickup::price>(state, "Price"); - lua_field<&Entity_Pickup::shopItemId>(state, "ShopItemId"); + // 007e93d0 The setter keeps the id within SHOP_ITEM_ID_LOWEST and SHOP_ITEM_ID_HIGHEST. + lua_property( + state, "ShopItemId", [](Entity_Pickup& pickup) { return pickup.shopItemId; }, + [](Entity_Pickup& pickup, int id) { + pickup.shopItemId = std::min(id < -1 ? SHOP_ITEM_ID_LOWEST : id, SHOP_ITEM_ID_HIGHEST); + }); lua_field<&Entity_Pickup::timeout>(state, "Timeout"); lua_field<&Entity_Pickup::isTouched>(state, "Touched"); lua_field<&Entity_Pickup::state>(state, "State"); @@ -366,6 +386,7 @@ static StatusMode status_mode(bool isIgnored) static void path_finder_register(lua_State* state) { lua_class_begin(state, "PathFinder", LUA_CLASS_PATH_FINDER); + lua_gc_set(state); lua_method(state, "Reset", [](PathFinder& path) { path.Reset(); }); lua_method(state, "ResetMovementTarget", [](PathFinder& path) { path.ResetMovementTarget(); }); lua_method(state, "UpdateGridIndex", [](PathFinder& path) { path.UpdateGridIndex(); }); diff --git a/src/lua_api_entity.cpp b/src/lua_api_entity.cpp index e6fd28d..c211e39 100644 --- a/src/lua_api_entity.cpp +++ b/src/lua_api_entity.cpp @@ -45,8 +45,8 @@ static void entity_link_add(lua_State* state, const char* name) [](Entity& entity, Entity* target) { entity.*Link = target; }); } -// (008bb770) Registers EntityRef, a snapshot of a damage source, and EntityPtr, a pointer that clears itself when its -// entity goes. +// (008bb770, 0085dc10, 0085dbf0) Registers EntityRef, a snapshot of a damage source, with its flag setters, and +// EntityPtr, a pointer that clears itself when its entity goes. static void entity_ref_register(lua_State* state) { lua_class_begin(state, "EntityRef", LUA_CLASS_ENTITY_REF); @@ -83,7 +83,9 @@ static void entity_ref_register(lua_State* state) // Registers Lua's Entity: what every entity has, its links, status effects and the casts to its subclasses. // Position, Velocity, SizeMulti and Color read copies, the sprite's offset, scale, the target position and colors are -// read by reference, as in the original. +// read by reference, as in the original. The accessors only Lua calls (00871ed0, 00871f70, 006a8180, 00565dd0) +// (00440ea0, 00871fa0, 004563e0, 00435d40), and the GetData and IsVulnerableEnemy registrations and their callers +// (00872530, 00872780, 00872590, 00872730), are the lambdas below. static void entity_class_register(lua_State* state) { lua_class_begin(state, "Entity", LUA_CLASS_ENTITY); @@ -161,7 +163,9 @@ static void entity_class_register(lua_State* state) lua_method(state, "Die", [](Entity& entity) { entity.isDead = true; }); lua_method(state, "Remove", [](Entity& entity) { entity.Remove(); }); lua_method(state, "BloodExplode", [](Entity& entity) { entity.BloodExplode(); }); - lua_method(state, "AddVelocity", [](Entity& entity, Vector added) { entity.AddVelocity_divided(added, false); }); + lua_method(state, "AddVelocity", [](Entity& entity, Vector added, bool isIgnoreSpeedMultiplier) { + entity.AddVelocity_divided(added, isIgnoreSpeedMultiplier); + }); lua_method(state, "MultiplyFriction", [](Entity& entity, float scale) { entity.friction *= scale; }); lua_method(state, "SetColor", [](Entity& entity, ColorMod color, int duration, int priority, bool isFadeout, bool isShared) { @@ -219,9 +223,10 @@ static void entity_class_register(lua_State* state) [](Entity& entity, const EntityRef& source, int duration, float damage, bool isIgnoreBoss) { entity.AddBurn(source, duration, damage, isIgnoreBoss); }); - lua_method(state, "AddShrink", [](Entity& entity, const EntityRef& source, int duration, bool isIgnoreBoss) { - entity.AddShrink(source, duration, isIgnoreBoss); - }); + lua_method(state, "AddShrink", + [](Entity& entity, const EntityRef& source, int duration, bool isIgnoreBoss, bool isForced) { + entity.AddShrink(source, duration, isIgnoreBoss, isForced); + }); lua_method(state, "RemoveStatusEffects", [](Entity& entity) { entity.RemoveStatusEffects(); }); lua_method(state, "Exists", [](Entity& entity) { return entity.isExists; }); diff --git a/src/lua_api_entity_player.cpp b/src/lua_api_entity_player.cpp index 4629f65..5b4b9f7 100644 --- a/src/lua_api_entity_player.cpp +++ b/src/lua_api_entity_player.cpp @@ -23,7 +23,8 @@ static Weapon* player_weapon_main(Entity_Player& player) return player.weapons[0] ? player.weapons[0].get() : player.weapons[1].get(); } -// Registers the player's health: the hearts of each kind, their limits, and the charges some characters use. +// Registers the player's health: the hearts of each kind, their limits, and the charges some characters use, with the +// controls state, whose setters only Lua calls (005b17a0, 005b17b0). static void player_health_register(lua_State* state) { lua_method(state, "GetHearts", [](Entity_Player& player) { return player.redHearts; }); @@ -48,16 +49,19 @@ static void player_health_register(lua_State* state) lua_method(state, "AddMaxHearts", [](Entity_Player& player, int amount, bool isIgnoreKeeper) { player.AddMaxHearts(amount, isIgnoreKeeper); }); - lua_method(state, "AddHearts", [](Entity_Player& player, int amount) { player.AddHearts(amount, false, false); }); - lua_method(state, "AddSoulHearts", [](Entity_Player& player, int amount) { player.AddSoulHearts(amount, false); }); + lua_method(state, "AddHearts", [](Entity_Player& player, int amount, bool isUnknown, bool isUnknown2) { + player.AddHearts(amount, isUnknown, isUnknown2); + }); + lua_method(state, "AddSoulHearts", + [](Entity_Player& player, int amount, bool isUnknown) { player.AddSoulHearts(amount, isUnknown); }); lua_method(state, "AddBlackHearts", [](Entity_Player& player, int amount) { player.AddBlackHearts(amount); }); lua_method(state, "RemoveBlackHeart", [](Entity_Player& player, int heart) { player.RemoveBlackHeart(heart); }); lua_method(state, "AddEternalHearts", [](Entity_Player& player, int amount) { player.AddEternalHearts(amount); }); lua_method(state, "AddGoldenHearts", - [](Entity_Player& player, int amount) { player.AddGoldenHearts(amount, false); }); + [](Entity_Player& player, int amount, bool isSkipBreak) { player.AddGoldenHearts(amount, isSkipBreak); }); lua_method(state, "AddBoneHearts", [](Entity_Player& player, int amount) { player.AddBoneHearts(amount); }); lua_method(state, "AddRottenHearts", - [](Entity_Player& player, int amount) { player.AddRottenHearts(amount, false); }); + [](Entity_Player& player, int amount, bool isUnknown) { player.AddRottenHearts(amount, isUnknown); }); lua_method(state, "AddBrokenHearts", [](Entity_Player& player, int amount) { player.AddBrokenHearts(amount); }); lua_method(state, "AddJarHearts", [](Entity_Player& player, int amount) { player.AddJarHearts(amount); }); lua_method(state, "AddJarFlies", [](Entity_Player& player, int amount) { player.AddJarFlies(amount); }); @@ -124,8 +128,8 @@ static void player_items_register(lua_State* state) }); lua_method(state, "GetCollectibleCount", [](Entity_Player& player) { return player.GetCollectibleCount(); }); lua_method(state, "AddCollectible", - [](Entity_Player& player, int id, int charge, bool isFirstTime, int slot, int varData) { - player.AddCollectible(id, charge, isFirstTime, slot, varData); + [](Entity_Player& player, int id, int charge, bool isFirstTime, int slot, int varData, int poolType) { + player.AddCollectible(id, charge, isFirstTime, slot, varData, poolType); }); lua_method(state, "RemoveCollectible", [](Entity_Player& player, int id, bool isOwnedOnly, int slot, bool isRemoveFromForm) { @@ -162,10 +166,10 @@ static void player_items_register(lua_State* state) lua_method(state, "SetActiveCharge", [](Entity_Player& player, int charge, int slot) { player.SetActiveCharge(charge, slot); }); lua_method(state, "DischargeActiveItem", - [](Entity_Player& player, uint32_t slot) { player.DischargeActiveItem(slot, false); }); + [](Entity_Player& player, uint32_t slot, bool isRemoved) { player.DischargeActiveItem(slot, isRemoved); }); lua_method(state, "NeedsCharge", [](Entity_Player& player, int slot) { return player.NeedsCharge(slot); }); - lua_method(state, "FullCharge", [](Entity_Player& player, int slot, bool isForced) { - return (int)player.FullCharge(slot, isForced, false); + lua_method(state, "FullCharge", [](Entity_Player& player, int slot, bool isForced, bool isOvercharge) { + return (int)player.FullCharge(slot, isForced, isOvercharge); }); lua_method(state, "UseActiveItem", [](Entity_Player& player, int item, uint32_t flags, int slot, int varData) { player.UseActiveItem({item, flags, slot, varData}); @@ -230,7 +234,7 @@ static void player_misc_register(lua_State* state) lua_method(state, "GetName", [](Entity_Player& player) -> const std::string& { return player.name; }); lua_method(state, "GetPlayerType", [](Entity_Player& player) { return player.playerType; }); lua_method(state, "ChangePlayerType", - [](Entity_Player& player, int type) { player.ChangePlayerType(type, false); }); + [](Entity_Player& player, int type, bool isUnknown) { player.ChangePlayerType(type, isUnknown); }); lua_method(state, "AddCacheFlags", [](Entity_Player& player, uint32_t flags) { player.AddCacheFlags(flags); }); lua_method(state, "EvaluateItems", [](Entity_Player& player) { player.EvaluateItems(); }); lua_method(state, "RespawnFamiliars", [](Entity_Player& player) { player.RespawnFamiliars(); }); @@ -330,7 +334,8 @@ static void player_misc_register(lua_State* state) lua_method(state, "AnimateTeleport", [](Entity_Player& player, bool isUp) { player.AnimateTeleport(isUp); }); lua_method(state, "AnimateHappy", [](Entity_Player& player) { player.AnimateHappy(); }); lua_method(state, "AnimateSad", [](Entity_Player& player) { player.AnimateSad(); }); - lua_method(state, "AnimatePitfallIn", [](Entity_Player& player) { player.AnimatePitfallIn(false); }); + lua_method(state, "AnimatePitfallIn", + [](Entity_Player& player, bool isIgnoreEffect) { player.AnimatePitfallIn(isIgnoreEffect); }); lua_method(state, "AnimatePitfallOut", [](Entity_Player& player) { player.AnimatePitfallOut(); }); lua_method(state, "PlayExtraAnimation", [](Entity_Player& player, std::string_view anim) { player.PlayExtraAnimation(anim); }); @@ -341,7 +346,7 @@ static void player_misc_register(lua_State* state) lua_method(state, "StopExtraAnimation", [](Entity_Player& player) { player.StopExtraAnimation(); }); } -// Registers the player's stats, which mods change in MC_EVALUATE_CACHE. +// (00782ab0) Registers the player's stats, which mods change in MC_EVALUATE_CACHE. static void player_stats_register(lua_State* state) { lua_property( @@ -372,7 +377,22 @@ static void player_stats_register(lua_State* state) state, "ControlsEnabled", [](Entity_Player& player) { return player.isControlsEnabled; }, [](Entity_Player& player, bool isEnabled) { player.isControlsEnabled = isEnabled; }); lua_field<&Entity_Player::controlsCooldown>(state, "ControlsCooldown"); - lua_method(state, "SpriteScale", [](Entity_Player& player) { return player.SpriteScale(); }); + // 0085e2a0 SpriteScale is a property, a copy of the player's own scale, which the setter replaces. + lua_property( + state, "SpriteScale", [](Entity_Player& player) { return player.SpriteScale(); }, + [](Entity_Player& player, Vector scale) { player.playerSpriteScale = scale; }); +} + +// (00882f90) GetMultiShotPositionVelocity reads its last argument as MultiShotParams, a class the original never +// registers, so no call gets past it. The original crashes reading it. This raises the argument error instead. +static int multi_shot_position_velocity_get(lua_State* state) +{ + lua_get(state, 1); + lua_get(state, 2); + lua_get(state, 3); + lua_get(state, 4); + lua_get(state, 5); + return luaL_argerror(state, 6, lua_pushfstring(state, "MultiShotParams expected, got %s", luaL_typename(state, 6))); } // (007e92a0, 004361a0, 004361b0, 0085e240, 005cd7d0, 0085e2c0, 00753c30, 0065cf60, 00782a60) Registers the player's @@ -401,8 +421,12 @@ static void player_state_register(lua_State* state) lua_method(state, "AddCurseMistEffect", [](Entity_Player& player) { player.AddCurseMistEffect(); }); lua_method(state, "RemoveCurseMistEffect", [](Entity_Player& player) { player.RemoveCurseMistEffect(); }); lua_method(state, "GetPocketItem", [](Entity_Player&, int) { return LuaOpaque{}; }); - lua_method(state, "FriendBallEnemy", [](Entity_Player&) { return LuaOpaque{}; }); + // FriendBallEnemy is a property of a class the original never registers, so its setter (005cd7a0) fails on every + // value. The original crashes reading it. This leaves the property read-only, so a write raises an error. + lua_property(state, "FriendBallEnemy", [](Entity_Player&) { return LuaOpaque{}; }); lua_method(state, "GetMultiShotParams", [](Entity_Player&, int) { return LuaOpaque{}; }); + lua_pushcfunction(state, multi_shot_position_velocity_get); + lua_table_set(state, -2, "GetMultiShotPositionVelocity"); lua_method(state, "GetGreedDonationBreakChance", [](Entity_Player& player) { return player.GetGreedDonationBreakChance(); }); lua_method(state, "GetLaserOffset", [](Entity_Player& player, int offsetId, Vector direction) { @@ -471,7 +495,8 @@ static void player_actions_register(lua_State* state) }); } -// (007537a0) Registers Lua's EntityPlayer, TemporaryEffects and TearParams. +// (007537a0, 0085e1d0) Registers Lua's EntityPlayer, QueueItemData with its Touched setter, TemporaryEffects and +// TearParams. void lua_api_entity_player_register(lua_State* state) { lua_class_begin(state, "EntityPlayer", LUA_CLASS_PLAYER, LUA_CLASS_ENTITY); @@ -534,7 +559,8 @@ void lua_api_entity_player_register(lua_State* state) [](TemporaryEffects& effects, int id) { return effects.GetTrinketEffectNum(id); }); lua_method(state, "GetNullEffectNum", [](TemporaryEffects& effects, int id) { return effects.GetNullEffectNum(id); }); - lua_method(state, "ClearEffects", [](TemporaryEffects& effects) { effects.ClearEffects(false); }); + lua_method(state, "ClearEffects", + [](TemporaryEffects& effects, bool isClearPersistent) { effects.ClearEffects(isClearPersistent); }); lua_class_end(state); lua_class_begin(state, "TearParams", LUA_CLASS_TEAR_PARAMS); diff --git a/src/lua_api_game.cpp b/src/lua_api_game.cpp index af96cf0..f8d3a88 100644 --- a/src/lua_api_game.cpp +++ b/src/lua_api_game.cpp @@ -24,8 +24,6 @@ #include "stage_transition.h" #include -// The reach of a Fart a script leaves out. -constexpr float FART_RADIUS = 85; // The last stage the run's stage counters keep. constexpr int STAGE_COUNTER_MAX = 13; // Making this many devil deals in one run unlocks Azazel. @@ -236,7 +234,8 @@ static void game_flow_register(lua_State* state) } // (00703510, 00703570) Registers Lua's Game: the run's level, room, players, pools, seeds and HUD, spawning, room -// transitions and farts, and its state flags and counters. Game is also the Level it derives from. +// transitions and farts, and its state flags and counters. Game is also the Level it derives from. The setters only +// Lua calls (00738390, 0085e3b0, 007e92e0) are lua_field's. static void game_register(lua_State* state) { lua_class_begin(state, "Game", LUA_CLASS_GAME); @@ -261,10 +260,10 @@ static void game_register(lua_State* state) return game.Spawn({position, velocity, spawner, subType, type, variant, seed}); }); lua_method(state, "StartRoomTransition", - [](Game& game, int roomIndex, Direction direction, LuaDefault animation, - Entity_Player* player, LuaDefault dimension) { - game.StartRoomTransition({.player = player, .animation = (RoomTransitionAnim)animation.value, - .direction = direction, .dimension = dimension.value, + [](Game& game, int roomIndex, Direction direction, int animation, Entity_Player* player, + int dimension) { + game.StartRoomTransition({.player = player, .animation = (RoomTransitionAnim)animation, + .direction = direction, .dimension = dimension, .roomIndex = roomIndex}); }); lua_method(state, "HasEncounteredBoss", [](Game& game, int type, int variant) { @@ -273,15 +272,15 @@ static void game_register(lua_State* state) }); lua_method(state, "GetGreedBossWaveNum", [](Game& game) { return GREED_BOSS_WAVE + (game.difficulty == DIFFICULTY_GREEDIER); }); - lua_method(state, "Fart", [](Game&, Vector position, LuaDefault radius, Entity* source, - LuaDefault scale, LuaDefault subType, ColorMod* color) { + lua_method(state, "Fart", [](Game&, Vector position, float radius, Entity* source, float scale, int subType, + ColorMod* color) { game_fart({.position = position, .source = source, .color = color ? *color : COLOR_DEFAULT, - .radius = radius.value, .scale = scale.value, .subType = subType.value}); + .radius = radius, .scale = scale, .subType = subType}); }); - lua_method(state, "ButterBeanFart", [](Game&, Vector position, float radius, Entity* source, - LuaDefault isShowEffect, bool isSuperKnockback) { + lua_method(state, "ButterBeanFart", [](Game&, Vector position, float radius, Entity* source, bool isShowEffect, + bool isSuperKnockback) { game_butter_bean_fart({.position = position, .source = source, .radius = radius, - .isShowEffect = isShowEffect.value, .isSuperKnockback = isSuperKnockback}); + .isShowEffect = isShowEffect, .isSuperKnockback = isSuperKnockback}); }); lua_method(state, "GetVictoryLap", [](Game& game) { return game.victoryLap; }); lua_method(state, "GetDevilRoomDeals", [](Game& game) { return game.devilRoomDeals; }); @@ -291,8 +290,13 @@ static void game_register(lua_State* state) lua_method(state, "GetStagesWithoutHeartsPicked", [](Game& game) { return game.stagesWithoutHeartsPicked; }); lua_method(state, "GetDarknessModifier", [](Game& game) { return game.darknessModifier; }); lua_method(state, "GetScreenShakeCountdown", [](Game& game) { return game.screenShakeTimer; }); - lua_field<&Game::challenge>(state, "Challenge"); - lua_field<&Game::difficulty>(state, "Difficulty"); + // 007068f0 Writing Challenge keeps it within the loaded challenges. + lua_property( + state, "Challenge", [](Game& game) { return game.challenge; }, + [](Game& game, int challenge) { + game.challenge = std::min(std::max(challenge, 0), (int)g_manager->challengeParams.size() - 1); + }); + lua_field_get<&Game::difficulty>(state, "Difficulty"); lua_field<&Game::timeCounter>(state, "TimeCounter"); lua_field<&Game::blueWombParTime>(state, "BlueWombParTime"); lua_field<&Game::bossRushParTime>(state, "BossRushParTime"); @@ -352,7 +356,8 @@ static int hud_item_text_show(lua_State* state) return 0; } -// Registers Lua's HUD, ItemPool and Seeds, the parts of a run Game hands out. +// Registers Lua's HUD, ItemPool and Seeds, the parts of a run Game hands out. CountSeedEffects, which only Lua calls +// (0085e1b0), is a lambda below. static void game_parts_register(lua_State* state) { lua_class_begin(state, "HUD", LUA_CLASS_HUD); @@ -378,8 +383,9 @@ static void game_parts_register(lua_State* state) lua_method(state, "GetCollectible", [](ItemPool& pool, ItemPoolType poolType, uint32_t seed, uint32_t flags, int defaultItem, int fallbackPool) { return pool.GetCollectible(poolType, seed, flags, defaultItem, fallbackPool); }); - lua_method(state, "RemoveCollectible", [](ItemPool& pool, int collectible) { - return pool.RemoveCollectible(collectible, REMOVE_ANY, REMOVE_APPLY); + lua_method(state, "RemoveCollectible", [](ItemPool& pool, int collectible, bool isAvailableOnly, bool isQuery) { + return pool.RemoveCollectible(collectible, isAvailableOnly ? REMOVE_AVAILABLE : REMOVE_ANY, + isQuery ? REMOVE_QUERY : REMOVE_APPLY); }); lua_method(state, "GetTrinket", [](ItemPool& pool, bool isPeek) { return pool.GetTrinket(isPeek ? TRINKET_DRAW_PEEK : TRINKET_DRAW_TAKE); @@ -426,7 +432,8 @@ static void game_parts_register(lua_State* state) lua_method(state, "CountSeedEffects", [](Seeds& seeds) { return seeds.CountSeedEffects(); }); lua_static(state, "GetSeedEffect", [](std::string_view seed) { return Seeds::GetSeedEffect(seed); }); lua_static(state, "IsSpecialSeed", [](std::string_view seed) { return Seeds::IsSpecialSeed(seed); }); - lua_static(state, "IsSeedComboBanned", [](int effectA, int effectB) { return Seeds::IsSeedComboBanned(effectA, effectB); }); + lua_method(state, "IsSeedComboBanned", + [](Seeds*, int effectA, int effectB) { return Seeds::IsSeedComboBanned(effectA, effectB); }); lua_static(state, "InitSeedInfo", []() { Seeds::InitSeedInfo(); }); lua_static(state, "CountUnlockedSeedEffects", []() { return Seeds::CountUnlockedSeedEffects(); }); lua_static(state, "Seed2String", [](uint32_t seed) { return Seeds::Seed2String(seed); }); diff --git a/src/lua_api_grid_entity.cpp b/src/lua_api_grid_entity.cpp index e831fc4..e64d1b6 100644 --- a/src/lua_api_grid_entity.cpp +++ b/src/lua_api_grid_entity.cpp @@ -31,7 +31,8 @@ static void grid_entity_desc_register(lua_State* state) lua_class_end(state); } -// Registers Lua's GridEntity, the base of rocks, pits, doors and the other tiles of a room. +// Registers Lua's GridEntity, the base of rocks, pits, doors and the other tiles of a room. GetGridIndex and the +// VarData setter, which only Lua calls (004e4830, 00718ed0), are the lambdas below. static void grid_entity_base_register(lua_State* state) { lua_class_begin(state, "GridEntity", LUA_CLASS_GRID_ENTITY); @@ -56,7 +57,9 @@ static void grid_entity_base_register(lua_State* state) return grid.Destroy(isImmediate, source); }); lua_property(state, "Position", [](GridEntity& grid) { return grid.Position(); }); - lua_property(state, "Desc", [](GridEntity& grid) { return grid.desc_save(); }); + lua_property( + state, "Desc", [](GridEntity& grid) { return grid.desc_save(); }, + [](GridEntity& grid, GridEntityDesc& desc) { grid.desc_load(desc); }); lua_field<&GridEntity::state>(state, "State"); lua_field<&GridEntity::varData>(state, "VarData"); lua_field<&GridEntity::collisionClass>(state, "CollisionClass"); @@ -70,7 +73,8 @@ static void grid_entity_base_register(lua_State* state) lua_class_end(state); } -// Registers Lua's GridEntityDoor: the rooms it joins, its locks and its animations. +// Registers Lua's GridEntityDoor: the rooms it joins, its locks and its animations. The TargetRoomIndex and Slot +// setters only Lua calls (00738150, 00738160) are lua_field's. static void grid_entity_door_register(lua_State* state) { lua_class_begin(state, "GridEntityDoor", LUA_CLASS_GRID_ENTITY_DOOR, LUA_CLASS_GRID_ENTITY); @@ -96,7 +100,17 @@ static void grid_entity_door_register(lua_State* state) lua_method(state, "IsTargetRoomArcade", [](GridEntity_Door& door) { return door.IsTargetRoomArcade(); }); lua_method(state, "GetSpriteOffset", [](GridEntity_Door& door) -> Vector& { return door.sprite.offset; }); lua_field<&GridEntity_Door::slot>(state, "Slot"); - lua_field<&GridEntity_Door::direction>(state, "Direction"); + // 00711530 Writing Direction turns the door's sprites to face it. The original reads past its angles for a + // direction outside them. This leaves the sprites as they are. + lua_property( + state, "Direction", [](GridEntity_Door& door) { return door.direction; }, + [](GridEntity_Door& door, Direction direction) { + door.direction = direction; + if (direction < 0 || direction >= DOOR_SIDES) return; + door.sprite.rotation = DOOR_ANGLES[direction]; + door.extraSprite.rotation = DOOR_ANGLES[direction]; + door.sparkleSprite.rotation = DOOR_ANGLES[direction]; + }); lua_field<&GridEntity_Door::currentRoomType>(state, "CurrentRoomType"); lua_field<&GridEntity_Door::targetRoomType>(state, "TargetRoomType"); lua_field<&GridEntity_Door::targetRoomIdx>(state, "TargetRoomIndex"); @@ -104,7 +118,7 @@ static void grid_entity_door_register(lua_State* state) lua_field<&GridEntity_Door::previousVariant>(state, "PreviousVariant"); lua_field<&GridEntity_Door::isBusted>(state, "Busted"); lua_field<&GridEntity_Door::isExtraVisible>(state, "ExtraVisible"); - lua_property(state, "ExtraSprite", [](GridEntity_Door& door) -> ANM2& { return door.extraSprite; }); + lua_field<&GridEntity_Door::extraSprite>(state, "ExtraSprite"); lua_field<&GridEntity_Door::openAnimation>(state, "OpenAnimation"); lua_field<&GridEntity_Door::closeAnimation>(state, "CloseAnimation"); lua_field<&GridEntity_Door::lockedAnimation>(state, "LockedAnimation"); @@ -117,8 +131,8 @@ static void grid_entity_door_register(lua_State* state) static void grid_entity_kinds_register(lua_State* state) { lua_class_begin(state, "GridEntityPit", LUA_CLASS_GRID_ENTITY_PIT, LUA_CLASS_GRID_ENTITY); - lua_method(state, "MakeBridge", [](GridEntity_Pit& pit, GridEntity* building) { - pit.MakeBridge(dynamic_cast(building), 0); + lua_method(state, "MakeBridge", [](GridEntity_Pit& pit, GridEntity* building, int bridgeVarData) { + pit.MakeBridge(dynamic_cast(building), bridgeVarData); }); lua_method(state, "SetLadder", [](GridEntity_Pit& pit, bool isLadder) { pit.SetLadder(isLadder); }); lua_method(state, "UpdateCollision", [](GridEntity_Pit& pit) { pit.UpdateCollision(); }); @@ -135,9 +149,9 @@ static void grid_entity_kinds_register(lua_State* state) lua_class_begin(state, "GridEntityPressurePlate", LUA_CLASS_GRID_ENTITY_PRESSURE_PLATE, LUA_CLASS_GRID_ENTITY); lua_method(state, "Reward", [](GridEntity_PressurePlate& plate) { plate.Reward(); }); - lua_property(state, "TimerPlate", [](GridEntity_PressurePlate& plate) -> ANM2& { return plate.timerPlate; }); - lua_field_get<&GridEntity_PressurePlate::nextGreedAnimation>(state, "NextGreedAnimation"); - lua_property(state, "GreedModeRNG", [](GridEntity_PressurePlate& plate) -> RNG& { return plate.greedModeRNG; }); + lua_field<&GridEntity_PressurePlate::timerPlate>(state, "TimerPlate"); + lua_field<&GridEntity_PressurePlate::nextGreedAnimation>(state, "NextGreedAnimation"); + lua_field<&GridEntity_PressurePlate::greedModeRNG>(state, "GreedModeRNG"); lua_class_end(state); lua_class_begin(state, "GridEntityRock", LUA_CLASS_GRID_ENTITY_ROCK, LUA_CLASS_GRID_ENTITY); diff --git a/src/lua_api_item_config.cpp b/src/lua_api_item_config.cpp index 82d2054..4e3a201 100644 --- a/src/lua_api_item_config.cpp +++ b/src/lua_api_item_config.cpp @@ -10,7 +10,9 @@ static void item_register(lua_State* state) lua_method(state, "IsTrinket", [](ItemConfig_Item& item) { return item.IsTrinket(); }); lua_method(state, "IsNull", [](ItemConfig_Item& item) { return item.IsNull(); }); lua_method(state, "HasTags", [](ItemConfig_Item& item, uint64_t tags) { return item.HasTags(tags); }); - lua_method(state, "IsAvailable", [](ItemConfig_Item& item) { return item.IsAvailable(UNLOCK_CHECKED); }); + lua_method(state, "IsAvailable", [](ItemConfig_Item& item, bool isIgnoreUnlock) { + return item.IsAvailable(isIgnoreUnlock ? UNLOCK_IGNORED : UNLOCK_CHECKED); + }); lua_field<&ItemConfig_Item::type>(state, "Type"); lua_field<&ItemConfig_Item::id>(state, "ID"); lua_field<&ItemConfig_Item::name>(state, "Name"); diff --git a/src/lua_api_rng.cpp b/src/lua_api_rng.cpp index a4aa012..6c22706 100644 --- a/src/lua_api_rng.cpp +++ b/src/lua_api_rng.cpp @@ -2,13 +2,11 @@ #include "lua_api.h" #include "seeds.h" -constexpr RNG LUA_RNG_DEFAULT = {RNG_SEED_DEFAULT, 5, 9, 7}; - // (008bbcf0) Registers Lua's RNG: a default seeded constructor and the game's RNG methods. void lua_api_rng_register(lua_State* state) { lua_class_begin(state, "RNG", LUA_CLASS_RNG); - lua_static(state, "__call", [](LuaIgnored) { return LUA_RNG_DEFAULT; }); + lua_static(state, "__call", [](LuaIgnored) { return RNG_DEFAULT; }); lua_method(state, "GetSeed", [](RNG& rng) { return rng._seed; }); lua_method(state, "SetSeed", [](RNG& rng, uint32_t seed, uint32_t shiftIndex) { rng.SetSeed(seed, shiftIndex); }); lua_method(state, "RandomInt", [](RNG& rng, uint32_t max) { return rng.RandomInt(max); }); diff --git a/src/lua_api_room.cpp b/src/lua_api_room.cpp index ef690e4..bce597b 100644 --- a/src/lua_api_room.cpp +++ b/src/lua_api_room.cpp @@ -15,11 +15,15 @@ #include "room_clear.h" #include "room_grid.h" #include "room_special.h" +#include // The frames KeepDoorsClosed holds the room uncleared for. constexpr int ROOM_CLEAR_DELAY_KEPT = 10; +// The last wave Lua's Level.GreedModeWave can be set to. +constexpr uint32_t GREED_MODE_WAVE_HIGHEST = 12; -// Adds a property for one of a room descriptor's flags. +// Adds a property for one of a room descriptor's flags. Its setters only Lua calls (004aae30, 007e9150, 004aae50) +// (008332a0, 00738190, 007e9170, 005b1690) are this one. template static void descriptor_flag_add(lua_State* state, const char* name) { @@ -28,31 +32,35 @@ static void descriptor_flag_add(lua_State* state, const char* name) [](RoomDescriptor& room, bool isSet) { room.flags = isSet ? room.flags | Flag : room.flags & ~Flag; }); } -// Registers RoomConfig.Spawn, a cell of a layout and the entities it picks one of, RoomConfig.Entry, one of those, and -// their lists, in the RoomConfig namespace begun before. +// (00872000) Registers RoomConfig.Spawn, a cell of a layout and the entities it picks one of, RoomConfig.Entry, one of +// those, and their lists, in the RoomConfig namespace begun before. static void room_config_spawns_register(lua_State* state) { lua_class_begin(state, "Spawn", LUA_CLASS_ROOM_CONFIG_SPAWN); - lua_field_get<&RoomSpawn::x>(state, "X"); - lua_field_get<&RoomSpawn::y>(state, "Y"); - lua_field_get<&RoomSpawn::sumWeights>(state, "SumWeights"); - lua_property(state, "EntryCount", [](RoomSpawn& spawn) { return (int)spawn.entries.size(); }); + lua_field<&RoomSpawn::x>(state, "X"); + lua_field<&RoomSpawn::y>(state, "Y"); + lua_field<&RoomSpawn::sumWeights>(state, "SumWeights"); + // The original's count is a byte apart from the entries, and a larger one reads past them. This only drops entries. + lua_property( + state, "EntryCount", [](RoomSpawn& spawn) { return (int)spawn.entries.size(); }, + [](RoomSpawn& spawn, uint8_t count) { spawn.entries.resize(std::min(count, spawn.entries.size())); }); lua_property(state, "Entries", [](RoomSpawn& spawn) -> std::vector& { return spawn.entries; }); lua_method(state, "PickEntry", [](RoomSpawn& spawn, float value) { return spawn.PickEntry(value); }); lua_class_end(state, LUA_SCOPE_NAMESPACE); lua_class_begin(state, "Entry", LUA_CLASS_ROOM_CONFIG_ENTRY); - lua_field_get<&RoomEntry::type>(state, "Type"); - lua_field_get<&RoomEntry::variant>(state, "Variant"); - lua_field_get<&RoomEntry::subtype>(state, "Subtype"); - lua_field_get<&RoomEntry::weight>(state, "Weight"); + lua_field<&RoomEntry::type>(state, "Type"); + lua_field<&RoomEntry::variant>(state, "Variant"); + lua_field<&RoomEntry::subtype>(state, "Subtype"); + lua_field<&RoomEntry::weight>(state, "Weight"); lua_class_end(state, LUA_SCOPE_NAMESPACE); lua_list_register>(state, "SpawnList"); lua_list_register>(state, "EntryList"); } -// Registers Lua's Level, which Game is: the floor's stage, curses, rooms and maps. +// Registers Lua's Level, which Game is: the floor's stage, curses, rooms and maps. The accessors only Lua calls +// (0057be60, 0085e160, 007e9250) are the lambdas below. static void level_register(lua_State* state) { lua_class_begin(state, "Level", LUA_CLASS_LEVEL); @@ -72,8 +80,8 @@ static void level_register(lua_State* state) lua_method(state, "AddCurse", [](Level& level, uint32_t curses, bool isShowName) { level.AddCurse(curses, isShowName); }); lua_method(state, "RemoveCurses", [](Level& level, uint32_t curses) { level.RemoveCurses(curses); }); - lua_static(state, "CanStageHaveCurseOfLabyrinth", - [](uint32_t stage) { return Level::CanStageHaveCurseOfLabyrinth(stage); }); + lua_method(state, "CanStageHaveCurseOfLabyrinth", + [](Level*, uint32_t stage) { return Level::CanStageHaveCurseOfLabyrinth(stage); }); lua_method(state, "GetStateFlag", [](Level& level, int flag) { return level.GetStateFlag(flag); }); lua_method(state, "SetStateFlag", [](Level& level, int flag, bool isSet) { level.SetStateFlag(flag, isSet); }); @@ -99,11 +107,19 @@ static void level_register(lua_State* state) lua_method(state, "ChangeRoom", [](Level& level, int index, int dimension) { level.ChangeRoom(index, dimension); }); lua_method(state, "Update", [](Level& level) { level.Update(); }); lua_method(state, "GetEnterPosition", [](Level& level) { return level.GetEnterPosition(); }); - lua_field<&Level::enterDoor>(state, "EnterDoor"); + // 0057be30 Writing EnterDoor keeps it between -1, no door, and the last door slot. + lua_property( + state, "EnterDoor", [](Level& level) { return level.enterDoor; }, + [](Level& level, int slot) { level.enterDoor = std::clamp(slot, -1, DOOR_SLOT_COUNT - 1); }); lua_field<&Level::leaveDoor>(state, "LeaveDoor"); lua_field<&Level::dungeonReturnRoomIndex>(state, "DungeonReturnRoomIndex"); lua_field<&Level::dungeonReturnPosition>(state, "DungeonReturnPosition"); - lua_field<&Level::greedModeWave>(state, "GreedModeWave"); + // 00753800 Writing GreedModeWave turns anything past GREED_MODE_WAVE_HIGHEST, negatives included, into it. + lua_property( + state, "GreedModeWave", [](Level& level) { return level.greedModeWave; }, + [](Level& level, int wave) { + level.greedModeWave = (uint32_t)wave < GREED_MODE_WAVE_HIGHEST ? wave : (int)GREED_MODE_WAVE_HIGHEST; + }); lua_method(state, "CanOpenChallengeRoom", [](Level& level, int index) { return level.CanOpenChallengeRoom(index); }); lua_method(state, "MakeRedRoomDoor", @@ -146,6 +162,7 @@ static void level_register(lua_State* state) }); lua_class_end(state); + // (00872020, 00872040) The RoomConfig namespace: a room layout, with its doors and spawns, then its cells. lua_namespace_begin(state, "RoomConfig"); lua_class_begin(state, "Room", LUA_CLASS_ROOM_CONFIG_ROOM); lua_field_get<&RoomConfig_Room::stageId>(state, "StageID"); @@ -345,9 +362,12 @@ static void room_register(lua_State* state) lua_method(state, "GetClampedPosition", [](Room& room, Vector position, float margin) { return room.GetClampedPosition(position, margin); }); lua_method(state, "FindFreePickupSpawnPosition", [](Room&, Vector position, float step, bool isAvoidActive, - bool isAllowPits) { - return room_free_pickup_position_find( - {.position = position, .step = step, .isAvoidActiveEntities = isAvoidActive, .isAllowPits = isAllowPits}); + bool isAllowPits, bool isAvoidDoors) { + return room_free_pickup_position_find({.position = position, + .step = step, + .isAvoidActiveEntities = isAvoidActive, + .isAllowPits = isAllowPits, + .isAvoidDoors = isAvoidDoors}); }); lua_method(state, "FindFreeTilePosition", [](Room&, Vector position, float distanceThreshold) { return room_free_tile_position_find(position, distanceThreshold); @@ -360,8 +380,15 @@ static void room_register(lua_State* state) return vector_make(screen.x + room.renderScrollOffset.x + g_game->screenShakeOffset.x, screen.y + room.renderScrollOffset.y + g_game->screenShakeOffset.y); }); - lua_method(state, "CheckLine", [](Room&, Vector start, Vector end, int mode, int threshold) { - return room_check_line(start, end, mode, threshold); + lua_method(state, "CheckLine", [](Room&, Vector start, Vector end, int mode, int threshold, bool isIgnoreWalls, + bool isIgnoreCrushable, Vector* stopPosition) { + return room_check_line({.start = start, + .end = end, + .stopPosition = stopPosition, + .mode = mode, + .gridPathThreshold = threshold, + .isIgnoreCrushable = isIgnoreCrushable, + .isIgnoreWalls = isIgnoreWalls}); }); lua_method(state, "GetGridWidth", [](Room& room) { return room.gridWidth; }); diff --git a/src/lua_api_sprite.cpp b/src/lua_api_sprite.cpp index 06813f1..ff6115e 100644 --- a/src/lua_api_sprite.cpp +++ b/src/lua_api_sprite.cpp @@ -5,6 +5,8 @@ // Registers Lua's Sprite, the game's ANM2: loading, playing and rendering an animation and its overlay, and its // offset, scale, rotation, color, flips and speed. Sprites scripts construct are destroyed with their userdata. +// The Sprite wrappers of ANM2 only Lua calls (0040a530, 004312e0, 0040a5b0, 0040a4b0, 0040aad0, 00431300, 0040a9d0) +// (0040aa50, 0040b000, 0040b060, 0049cb40) are the lambdas below. static void sprite_register(lua_State* state) { lua_class_begin(state, "Sprite", LUA_CLASS_SPRITE); @@ -40,7 +42,7 @@ static void sprite_register(lua_State* state) return sprite.SetAnimation(name, isReset ? SWITCH_RESET : SWITCH_KEEP_FRAME); }); lua_method(state, "SetFrame", [](ANM2& sprite, std::string_view name, int frame) { sprite.SetFrame(name, frame); }); - lua_method(state, "SetFrame_1", [](ANM2& sprite, float frame) { sprite.SetFrame(frame); }); + lua_method(state, "SetFrame_1", [](ANM2& sprite, int frame) { sprite.SetFrame((float)frame); }); lua_method(state, "SetLastFrame", [](ANM2& sprite) { sprite.SetLastFrame(); }); lua_method(state, "SetLayerFrame", [](ANM2& sprite, int layerId, int frame) { sprite.SetLayerFrame(layerId, frame); }); @@ -111,13 +113,13 @@ static void font_register(lua_State* state) }); lua_method(state, "IsTruncationEnabled", [](FontSettings& settings) { return settings.wrapMode == FONT_WRAP_TRUNCATE; }); - lua_method(state, "SetMaxLineWidth", [](FontSettings& settings, uint16_t width) { settings.maxLineWidth = width; }); - lua_method(state, "GetMaxLineWidth", [](FontSettings& settings) { return settings.maxLineWidth; }); lua_method(state, "SetLineHeightModifier", [](FontSettings& settings, float modifier) { settings.lineHeightModifier = modifier; }); lua_method(state, "GetLineHeightModifier", [](FontSettings& settings) { return settings.lineHeightModifier; }); lua_method(state, "SetMissingCharacterOverride", [](FontSettings& settings, int character) { settings.missingCharacterOverride = character; }); + lua_method(state, "GetMissingCharacterOverride", + [](FontSettings& settings) { return settings.missingCharacterOverride; }); lua_class_end(state); lua_class_begin(state, "Font", LUA_CLASS_FONT); diff --git a/src/lua_api_vector.cpp b/src/lua_api_vector.cpp index cb4fee9..6f95da6 100644 --- a/src/lua_api_vector.cpp +++ b/src/lua_api_vector.cpp @@ -9,7 +9,8 @@ static Vector vector_clamped(const Vector& vector, float minX, float minY, float } // (008bb260, 0085e630) Registers Lua's Vector: its constructor, X and Y, the math methods and the arithmetic -// metamethods. The methods are those of the game's Vector, Lerp changing the vector and returning it. +// metamethods. The methods are those of the game's Vector, Lerp changing the vector and returning it. Cross, Clamp +// and Clamped, which only Lua calls (00a101a0, 00a103c0, 00a103f0), are written here. void lua_api_vector_register(lua_State* state) { lua_class_begin(state, "Vector", LUA_CLASS_VECTOR); diff --git a/src/lua_callbacks.cpp b/src/lua_callbacks.cpp index 2448f10..331a80a 100644 --- a/src/lua_callbacks.cpp +++ b/src/lua_callbacks.cpp @@ -30,13 +30,23 @@ struct CallbackRun // (00872980, 00872c60, 00873470, 00873980, 00873d00, 00873fc0, 00874120, 00874210, 00874310, 00874a10, 00874f60) // (0085c080, 008727d0, 0086130e, 00861225, 00861d96, 00861e7f, 008623a6, 0086248f, 008628b6, 0086299f, 00864453) // (0086453c, 00865bbc, 00872a20, 00872b10, 00872ff0, 008730e0, 00873890, 00873ac0, 00873bb0, 00873e40, 008746b0) -// (00874860, 00874910, 00874ac0, 00874d20, 00874dd0, 00874e90, 00865a04, 0085bfd0, 0085bff0, 0085c270, 00873f40), +// (00874860, 00874910, 00874ac0, 00874d20, 00874dd0, 00874e90, 00865a04, 0085bfd0, 0085bff0, 0085c270, 00873f40) +// (00872da0, 00872e90, 00873230, 00873320, 00873560, 00873650, 00873740, 00874400, 00874550, 00875050, 008663b6) +// (00872820, 00872860, 00872910, 00861c23, 00862233, 00862d53, 00865aad, 00865c61, 00866474, 00872a0c, 00872af1) +// (00872c43, 00872d80, 00872e71, 00872fc3, 008730c1, 00873213, 00873301, 00873453, 00873541, 00873631, 00873721) +// (00873873, 00873961, 00873aa0, 00873b91, 00873ce3, 00873e20, 00873f26, 00874103, 008741f1, 008742f7, 008743eb) +// (00874533, 0087469a, 00874846, 008748f6, 008749f7, 00874aa8, 00874bbb, 00874d0a, 00874db6, 00874e7e, 00874f4a) +// (00861bda, 008621ea, 00862d0a, 0085c250, 0085c2d0, 0085c300, 0085c340, 0085bf50, 0085c1d0, 0085c200, 0085c210) +// (0085da70) // and their catches log through lua_error_log // (00860ea3, 008611da, 0086191f, 00861d4b, 0086235b, 0086286b, 00862ea4, 008632e1) // (00863706, 00863b6a, 00863e31, 00863f1e, 008640de, 00864408, 00864f6e, 00865b69, 008661cc, 00860826, 0086090e) // (00860a70, 00860b4b, 00860c36, 00860d1e, 008613bf, 0086149f, 00861587, 00862a4c, 00862b2f, 00862cb8, 00862f8c) // (0086306c, 00863154, 0086354b, 00863fff, 00864a6a, 00864bb8, 00864d16, 00865209, 008652e9, 00865424, 008659a7) -// (00865d53, 00865e99, 00865fe8, 008660ec). +// (00865d53, 00865e99, 00865fe8, 008660ec) +// (00860f8b, 00861076, 0086166f, 0086174f, 00861837, 008619ff, 00861b88, 00861f2f, 0086200f, 00862198, 0086253f) +// (0086261f, 00862707, 0086362b, 00863879, 00863c6e, 00863d4e, 008641bb, 008642a4, 00864682, 00864e6d, 0086504e) +// (0086512e, 008655b7, 00866364, 0086675e, 008668e0). template static bool callback_run(LuaEngine& engine, CallbackRun run, Args... args) { diff --git a/src/lua_engine.cpp b/src/lua_engine.cpp index aa3fdbb..352211b 100644 --- a/src/lua_engine.cpp +++ b/src/lua_engine.cpp @@ -39,7 +39,7 @@ constexpr luaL_Reg SANDBOX_LIBRARIES[] = { {LUA_STRLIBNAME, luaopen_string}, {LUA_MATHLIBNAME, luaopen_math}, {LUA_UTF8LIBNAME, luaopen_utf8}, {LUA_DBLIBNAME, luaopen_debug}}; -// One distinct address per class, the registry keys of their metatables, as LuaBridge's class keys are. +// One distinct address per class, the registry keys of their metatables, as LuaBridge's class keys are (0085c390). static std::array classKeys; const void* lua_class_key(LuaClass luaClass) @@ -174,7 +174,8 @@ void LuaEngine::Init(LuaMode luaMode) } // 00866960 Registers the mod API: the classes, then the namespaces and the global functions, which replace the -// SFXManager and MusicManager classes with the functions returning them. +// SFXManager and MusicManager classes with the functions returning them. Its global namespace helpers +// (0085dab0, 0086e4d0) are the state itself. void LuaEngine::RegisterAPI() { for (auto registerPart : diff --git a/src/manager.cpp b/src/manager.cpp index 804a993..ae1f823 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -578,7 +578,7 @@ void IsaacStartup(int argc, uint8_t** argv) // 009ab700 Shuts the game down when the window closes: an unended daily run counts as lost, the options and changed // progress (backed up first) are saved, and a run in progress is saved through Game::Exit. -// Netplay's leaving is offline. The daily check's third word (Game 0x2673c) is not identified yet and counts as 0. +// Netplay's leaving is offline. // The menus, run, manager, animation cache, shaders and Lua engine are left to the process's exit, as their destructors // only free memory. void isaac_shutdown() @@ -587,7 +587,8 @@ void isaac_shutdown() PersistentGameData& data = manager.persistentGameData; log_printf(LOG_INFO, "Isaac is shutting down...\n"); - if (g_game && g_game->dailyChallenge.id != 0 && !g_game->dailyChallenge.isPractice) + if (g_game && g_game->dailyChallenge.id != 0 && !g_game->dailyChallenge.isPractice && + g_game->scoreSheet.runEnding == ENDING_NONE) { data.eventCounters[EVENT_COUNTER_DAILYS_STREAK] = 0; data.IncreaseEventCounter(EVENT_COUNTER_DAILYS_LOSING_STREAK, 1); @@ -1305,12 +1306,11 @@ void Manager::start_pending_game() else { isStartingFromRerun = false; - reconstruction_missing("Game::StartFromRerunState 006f72f0"); + g_game->StartFromRerunState(gamestate); } } - 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 if (dailyChallenge.id != 0) g_game->StartDailyChallenge(dailyChallenge); + else if (isDebugStart) g_game->StartDebug(startStage, startStageType, (Difficulty)startDifficulty, startRoomPath); else g_game->Start(startPlayerType, startChallenge, startSeeds, (Difficulty)startDifficulty); if ((int)framecount % 2 == 1) framecount++; @@ -1756,6 +1756,12 @@ bool Manager::render_controller_action_glyph(const ActionGlyph& glyph) return true; } -// Not reconstructed yet: each stops the game where it is reached. -Manager::~Manager() { reconstruction_missing("Manager::destructor 00951160"); } -void Manager::apply_device_key_config(int) { reconstruction_missing("Manager::apply_device_key_config 0095b180"); } +// 00951160 Destruction only resets the sprites, fonts and surfaces and frees the members, so it is the default. +Manager::~Manager() = default; + +// 0095b180 Saves the key configs once a device exists. The original first copied the device's bindings into the config +// of its name (00835ba0), which binding_get reads directly here. +void Manager::apply_device_key_config(int deviceId) +{ + if (KAGE::Input::manager.device_find(deviceId)) g_manager->keyConfigs.SaveButtonMaps(); +} diff --git a/src/menu_character.cpp b/src/menu_character.cpp index 2b33d15..307b213 100644 --- a/src/menu_character.cpp +++ b/src/menu_character.cpp @@ -121,8 +121,6 @@ constexpr int MENU_ID_RANDOM = 0; constexpr int MENU_ID_EDEN = 10; constexpr int EVENT_NEGATIVE_STREAK_COUNTER = 113; constexpr int ACHIEVEMENT_GREEDIER = 341; -constexpr int SOUND_CHARACTER_SELECT_LEFT = 194; -constexpr int SOUND_CHARACTER_SELECT_RIGHT = 195; constexpr int SOUND_MENU_FLIP_LIGHT = 569; constexpr int SOUND_MENU_FLIP_DARK = 570; constexpr int SOUND_MENU_RIP = 571; @@ -155,8 +153,6 @@ constexpr float WHEEL_DEPTH_GROWTH = 0.01f; constexpr int WHEEL_CROWD = 10; constexpr float WHEEL_WIDTH_SCALE = 1.3f; constexpr float WHEEL_SPEED_SCALE = 50; -constexpr float HALF_TURN = 180; -constexpr float QUARTER_TURN = 90; constexpr float SPIN_EASE_START = 60; constexpr float SPIN_EASE_LENGTH = -60; constexpr float SPIN_SLOWDOWN = 6; @@ -703,12 +699,12 @@ void Menu_Character::wheel_rotate(int portrait) if (target > scroll) { float distance = target - scroll; - scroll = distance < HALF_TURN ? scroll + std::min(distance, speed) : scroll - std::min(distance, speed); + scroll = distance < HALF_TURN_DEGREES ? scroll + std::min(distance, speed) : scroll - std::min(distance, speed); } else if (scroll > target) { float distance = scroll - target; - scroll = distance < HALF_TURN ? scroll - std::min(distance, speed) : scroll + std::min(distance, speed); + scroll = distance < HALF_TURN_DEGREES ? scroll - std::min(distance, speed) : scroll + std::min(distance, speed); } else if (status == CHARACTER_STATUS_RANDOM_SPIN) random_spin_step(); else isInputPossible = true; @@ -717,7 +713,7 @@ void Menu_Character::wheel_rotate(int portrait) float angleCos = (float)std::cos((double)angle); float angleSin = (float)std::sin((double)angle); - float turn = (QUARTER_TURN - scroll) * DEGREES_TO_RADIANS; + float turn = (RIGHT_ANGLE_DEGREES - scroll) * DEGREES_TO_RADIANS; float turnCos = (float)std::cos((double)turn); float turnSin = (float)std::sin((double)turn); float depth = turnCos * angleSin + turnSin * angleCos; diff --git a/src/mines.cpp b/src/mines.cpp index 9b5da87..0d8fe15 100644 --- a/src/mines.cpp +++ b/src/mines.cpp @@ -32,8 +32,6 @@ constexpr float MINECART_LEAVE_MARGIN = -300; constexpr float MINECART_DUST_SPEED = 0.8f; constexpr float MINECART_DUST_INTERVAL = 2; constexpr float MINECART_DUST_DRAG = 0.2f; -constexpr float MINECART_DUST_SPIN_RANGE = 10; -constexpr float MINECART_DUST_SPIN_MIN = 2; constexpr int MINECART_DUST_FRAMES_MIN = 15; constexpr float MINECART_DUST_SCALE_MIN = 0.3f; constexpr float MINECART_DUST_SCALE_RANGE = 0.3f; @@ -348,7 +346,7 @@ static void minecart_dust_spawn(Entity_NPC& minecart) .type = ENTITY_EFFECT, .variant = EFFECT_DUST_CLOUD, .seed = seed})); - dust->rotation = random_unit() * MINECART_DUST_SPIN_RANGE + MINECART_DUST_SPIN_MIN; + dust->rotation = random_between(DUST_SPIN_MIN, DUST_SPIN_RANGE); dust->SetTimeout((int)(Random() % MINECART_DUST_FRAMES_MIN) + MINECART_DUST_FRAMES_MIN); dust->SetColor(MINECART_DUST_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); diff --git a/src/minimap.cpp b/src/minimap.cpp index 149a3b5..a587ce0 100644 --- a/src/minimap.cpp +++ b/src/minimap.cpp @@ -59,7 +59,6 @@ constexpr int TAP_FRAMES = 9; constexpr int SHOW_NAME_FRAMES = 10; constexpr float SHAKE_DIVISOR = 10; constexpr float SHAKE_KEEP = 0.5f; -constexpr float HALF_TURN = 3.14f; constexpr float HUD_INSET_X = 24; constexpr float HUD_INSET_Y = -14; @@ -768,7 +767,7 @@ void Minimap::Update() if (shakeDuration > 0) { shakeDuration--; - float angle = random_unit() * HALF_TURN * 2; + float angle = random_unit() * PI_ROUGH * 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); diff --git a/src/mod_manager.cpp b/src/mod_manager.cpp index b36e489..05ef2f7 100644 --- a/src/mod_manager.cpp +++ b/src/mod_manager.cpp @@ -377,7 +377,8 @@ void ModShader::render_target_create() renderTarget->wrap_set(WRAP_CLAMP, WRAP_CLAMP); } -// 00865490 Runs MC_GET_SHADER_PARAMS for a shader, leaving the table a mod returned on the stack. Whether it did. +// 00865490 Runs MC_GET_SHADER_PARAMS for a shader, its caller included (00874bd0), leaving the table a mod returned +// on the stack. Whether it did. // A Lua error is logged, as the game's callbacks log theirs. static bool shader_params_push(std::string_view shaderName) { diff --git a/src/music_manager.h b/src/music_manager.h index 27944b7..186aaed 100644 --- a/src/music_manager.h +++ b/src/music_manager.h @@ -94,7 +94,8 @@ enum MusicId : int MUSIC_DOWNPOUR = 104, MUSIC_DOWNPOUR_REVERSED = 114, MUSIC_ABANDONED_MINESHAFT = 116, - MUSIC_REVERSE_GENESIS = 118 + MUSIC_REVERSE_GENESIS = 118, + MUSIC_DEATHMATCH = 119 }; // Construction and destruction (007e1430) are the defaults. diff --git a/src/npc_ai.cpp b/src/npc_ai.cpp index b6d82de..b8867e2 100644 --- a/src/npc_ai.cpp +++ b/src/npc_ai.cpp @@ -519,7 +519,7 @@ static void npc_ai_routine_run(Entity_NPC& npc) case 815: return npc_fissure_update(npc); case 816: - return (void)NpcAI::ENTITY_POLTY(&npc); + return npc_polty_update(npc); case 818: return npc_rock_spider_update(npc); case 820: @@ -655,7 +655,7 @@ static void npc_ai_routine_run(Entity_NPC& npc) case 908: return boss_baby_plum_update(npc); case 909: - return npc.variant == 10 ? NpcAI::ENTITY_SCOURGE_chain(&npc) : NpcAI::ENTITY_SCOURGE(&npc); + return npc.variant == SCOURGE_CHAIN ? scourge_chain_update(npc) : boss_scourge_update(npc); case 910: return npc.variant == 2 ? chimera_head_update(npc) : chimera_body_update(npc); case 911: diff --git a/src/npc_ai.h b/src/npc_ai.h index 42b2c99..b979897 100644 --- a/src/npc_ai.h +++ b/src/npc_ai.h @@ -8,7 +8,8 @@ #include #include -constexpr float RANDOM_HALF_TURN = 3.14f; +// The friction an evading enemy keeps. +constexpr float FLEE_FRICTION = 0.8f; constexpr int GURGLING_TURDLING = 2; // Isaac::Random: a random number below max, or 0 for none. @@ -20,7 +21,7 @@ inline int random_below(int max) // MusicManager::RandomVector: a random unit direction. inline Vector random_direction() { - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; return vector_make(std::cos(angle), std::sin(angle)); } diff --git a/src/npc_ball_and_chain.cpp b/src/npc_ball_and_chain.cpp index e1c8149..e490424 100644 --- a/src/npc_ball_and_chain.cpp +++ b/src/npc_ball_and_chain.cpp @@ -28,8 +28,6 @@ constexpr int CHAIN_FACINGS = 4; constexpr float BALL_DUST_INTERVAL = 2; constexpr float BALL_DUST_ODDS_SCALE = 10; constexpr float BALL_DUST_DRAG_SHARE = 0.2f; -constexpr float BALL_DUST_SPIN_MIN = 2; -constexpr float BALL_DUST_SPIN_RANGE = 10; constexpr int BALL_DUST_TIMEOUT_MIN = 15; constexpr int BALL_DUST_TIMEOUT_SPREAD = 15; constexpr float BALL_DUST_SCALE_MIN = 0.3f; @@ -166,7 +164,7 @@ static void ball_swing(Entity_NPC& npc, float speed) Vector puff = vector_add(random_direction(), drag); auto* dust = static_cast(g_game->Spawn( {.position = npc.pos, .velocity = puff, .spawner = &npc, .type = ENTITY_EFFECT, .variant = EFFECT_DUST_CLOUD, .seed = seed})); - dust->rotation = random_between(BALL_DUST_SPIN_MIN, BALL_DUST_SPIN_RANGE); + dust->rotation = random_between(DUST_SPIN_MIN, DUST_SPIN_RANGE); int timeout = (int)(Random() % BALL_DUST_TIMEOUT_SPREAD) + BALL_DUST_TIMEOUT_MIN; dust->timeout = timeout; dust->lifespan = timeout; diff --git a/src/npc_boom_fly.cpp b/src/npc_boom_fly.cpp index 6f08813..0744b15 100644 --- a/src/npc_boom_fly.cpp +++ b/src/npc_boom_fly.cpp @@ -94,8 +94,6 @@ constexpr float TAINTED_DUST_SHIFT = 0.4f; constexpr float TAINTED_DUST_TURN = 36; constexpr float TAINTED_DUST_SPEED = 10; constexpr float TAINTED_DUST_SPEED_RANGE = 5; -constexpr float TAINTED_DUST_SPIN = 2; -constexpr float TAINTED_DUST_SPIN_RANGE = 10; constexpr int TAINTED_DUST_TIMEOUT = 15; constexpr int TAINTED_DUST_DEPTH = -600; constexpr float TAINTED_DUST_SCALE = 2; @@ -217,7 +215,7 @@ static void tainted_explode(Entity_NPC& npc) .type = ENTITY_EFFECT, .variant = EFFECT_DUST_CLOUD, .seed = seed})); - dust->rotation = random_unit() * TAINTED_DUST_SPIN_RANGE + TAINTED_DUST_SPIN; + dust->rotation = random_between(DUST_SPIN_MIN, DUST_SPIN_RANGE); dust->SetTimeout((int)(Random() % TAINTED_DUST_TIMEOUT) + TAINTED_DUST_TIMEOUT); dust->SetColor(TAINTED_DUST_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); dust->renderZOffset = TAINTED_DUST_DEPTH; @@ -381,7 +379,7 @@ static void sick_fly_trail(Entity_NPC& npc) if (npc.GetIntervalTicks(SICK_TRAIL_INTERVAL, 0) == 0) return; uint32_t seed = Random(); - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float reach = random_unit(); Vector drift = vector_make(std::cos(angle) * reach, std::sin(angle) * reach); diff --git a/src/npc_clotty.cpp b/src/npc_clotty.cpp index 8d7936d..ec8d74f 100644 --- a/src/npc_clotty.cpp +++ b/src/npc_clotty.cpp @@ -18,7 +18,6 @@ constexpr int BLOOD_EXPLOSION_SPURT = 2; // They hop around (a Mega Clotty wading through more friction) and attack once a hop ends while the target is in // range, waiting 30 frames between (45 for the Mega Clotty, 15 for the Grilled Clotty, who rests after three). constexpr float CLOTTY_FRICTION = 0.9f; -constexpr float FLEE_FRICTION = 0.8f; constexpr float MEGA_CLOTTY_FRICTION = 0.85f; constexpr float CLOTTY_WAIT = 30; constexpr float MEGA_CLOTTY_WAIT = 45; @@ -105,7 +104,7 @@ static void mega_clotty_split(Entity_NPC& npc) for (int i = std::max(0, MEGA_SPLIT - npc.championRegenCount); i > 0; i--) { uint32_t seed = Random(); - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; Vector at = vector_make(std::cos(angle) * MEGA_SPLIT_SPREAD + npc.pos.x, std::sin(angle) * MEGA_SPLIT_SPREAD + npc.pos.y); @@ -188,7 +187,7 @@ static void mega_clotty_shoot(Entity_NPC& npc) for (int i = 0; i < MEGA_CREEPS; i++) { uint32_t seed = Random(); - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float distance = random_unit() * MEGA_CREEP_SPREAD; Vector at = vector_make(std::cos(angle) * distance + npc.pos.x, std::sin(angle) * distance + npc.pos.y); diff --git a/src/npc_cultist.cpp b/src/npc_cultist.cpp index 87fb0c5..af4e584 100644 --- a/src/npc_cultist.cpp +++ b/src/npc_cultist.cpp @@ -486,7 +486,7 @@ static void pool_raise(Entity_NPC& npc) } else { - float angle = random_unit() * RANDOM_HALF_TURN * 2; + float angle = random_unit() * PI_ROUGH * 2; way = vector_make(std::cos(angle), std::sin(angle)); } float reach = random_unit() * CULTIST_SPOT_SPREAD + CULTIST_SPOT_MIN; diff --git a/src/npc_dark_esau.cpp b/src/npc_dark_esau.cpp index 0ceeca4..141e1c8 100644 --- a/src/npc_dark_esau.cpp +++ b/src/npc_dark_esau.cpp @@ -85,7 +85,6 @@ constexpr float BURN_RADIUS = 50; constexpr float BURN_DAMAGE_BASE = 9; constexpr int BURN_FRAMES = 150; constexpr float BURN_TICK = 5; -constexpr int ESAU_HIT_COUNTDOWN = 30; constexpr float ESAU_CONTACT_DAMAGE = 30; // Climbing out, he shakes the screen and sprays 12 rings of 8 shots at speed 8. @@ -156,7 +155,7 @@ static void dash_burn(Entity_NPC& npc) { if (entity->IsVulnerableEnemy(nullptr) && entity != &npc && !entity->HasEntityFlags(FLAG_FRIENDLY)) { - entity->TakeDamage(damage, DAMAGE_IGNORE_ARMOR, EntityRef(&npc), ESAU_HIT_COUNTDOWN); + entity->TakeDamage(damage, DAMAGE_IGNORE_ARMOR, EntityRef(&npc), HIT_COUNTDOWN); entity->AddBurn(EntityRef(npc.parent), BURN_FRAMES, BURN_TICK, false); continue; } @@ -194,7 +193,7 @@ static void dark_esau_pre_update(Entity_NPC& npc) blast->Update(); if (Entity* spawner = npc.spawnerEntity) spawner->TakeDamage(0, DAMAGE_INVINCIBLE | DAMAGE_NO_MODIFIERS | DAMAGE_NO_PENALTIES, EntityRef(&npc), - ESAU_HIT_COUNTDOWN); + HIT_COUNTDOWN); } // The collision phase: he hurts an enemy (or a deathmatch player) he touches once a dash, letting the touch through. @@ -207,7 +206,7 @@ static void dark_esau_collide(Entity_NPC& npc, Entity_Player* owner) if (!isTarget || EntityList::HitListContains(npc.hitList, *other)) return; hit_list_insert(npc.hitList, *other); - other->TakeDamage(ESAU_CONTACT_DAMAGE, 0, EntityRef(&npc), ESAU_HIT_COUNTDOWN); + other->TakeDamage(ESAU_CONTACT_DAMAGE, 0, EntityRef(&npc), HIT_COUNTDOWN); npc.collisionResult = 0; } diff --git a/src/npc_fat_sack.cpp b/src/npc_fat_sack.cpp index baeb84e..4c9fc67 100644 --- a/src/npc_fat_sack.cpp +++ b/src/npc_fat_sack.cpp @@ -84,7 +84,7 @@ static void fat_sack_splash(Entity_NPC& npc) for (int i = 0; i < FAT_SACK_PUDDLES; i++) { uint32_t seed = Random(); - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float distance = random_unit() * FAT_SACK_PUDDLE_RANGE; Vector at = vector_make(std::cos(angle) * distance + npc.pos.x, std::sin(angle) * distance + npc.pos.y); @@ -109,7 +109,8 @@ static void fat_sack_leap(Entity_NPC& npc) else { if (!npc.sprite.WasEventTriggered("Hit")) - reconstruction_missing("NpcAI::ENTITY_FAT_SACK 00530a80: apply_controller_movement 006d9320"); + npc.apply_controller_movement(CONTROL_STEER_ACCEL, CONTROL_STEER_DRAG - glide * CONTROL_STEER_DRAG_FALL, + CONTROL_STEER_SPEED); else { Vector input = npc.GetControllerInput(0); diff --git a/src/npc_fistuloid.cpp b/src/npc_fistuloid.cpp index b570de1..99aef6b 100644 --- a/src/npc_fistuloid.cpp +++ b/src/npc_fistuloid.cpp @@ -29,7 +29,6 @@ constexpr float ORBIT_CATCHUP = 10; // A decaying one hurts itself now and then. The Matriarch's held one dies to her red acid shots, and a Fistuloid // gone adds to her wait. constexpr float DECAY_SHARE = 0.4f; -constexpr int SELF_HIT_COUNTDOWN = 30; constexpr int MATRIARCH_DELAY_PER_LOSS = 150; // The ejection: the worm thrown at 12 along an axis on Shoot, the Fistuloid gone after. @@ -169,7 +168,7 @@ static void fistuloid_matriarch_acid_check(Entity_NPC& npc) if (entity->spawnerType != ENTITY_MATRIARCH) continue; if (!(static_cast(entity)->projectileFlags & PROJECTILE_ACID_RED)) continue; - npc.TakeDamage(npc.maxHitPoints, 0, EntityRef(entity), SELF_HIT_COUNTDOWN); + npc.TakeDamage(npc.maxHitPoints, 0, EntityRef(entity), HIT_COUNTDOWN); break; } } @@ -221,7 +220,7 @@ void npc_fistuloid_update(Entity_NPC& npc) npc.friction = FISTULOID_FRICTION; } if (npc.isKillOnTouch && npc.IsFrame(4, 0) && (Random() & 1) == 0) - npc.TakeDamage(npc.maxHitPoints * DECAY_SHARE, 0, EntityRef(), SELF_HIT_COUNTDOWN); + npc.TakeDamage(npc.maxHitPoints * DECAY_SHARE, 0, EntityRef(), HIT_COUNTDOWN); fistuloid_matriarch_acid_check(npc); if (npc.controllerID != -1 && input_is_action_pressed(ACTION_ITEM, npc.controllerID, &npc) && npc.state != NPC_STATE_SUICIDE) diff --git a/src/npc_fly.cpp b/src/npc_fly.cpp index c8aeb3a..88b70bf 100644 --- a/src/npc_fly.cpp +++ b/src/npc_fly.cpp @@ -672,7 +672,6 @@ void npc_fly_update(Entity_NPC& npc) // The dart fly circles while it homes in on where its target is heading, at up to 8. constexpr float DART_TURN = 0.18849558f; -constexpr float DART_FULL_TURN = 6.2831855f; constexpr float DART_LEAD = 0.25f; constexpr float DART_CIRCLE = 10; constexpr float DART_HOMING = 15; @@ -682,9 +681,13 @@ constexpr float DART_ACCEL_DAMP = 0.9f; constexpr float DART_ACCEL_SHARE = 0.033333335f; constexpr float DART_MAX_SPEED = 8; constexpr float DART_FRICTION = 0.95f; +// A controlled dart fly circles at 6 and follows its input at 1.2 times the homing. +constexpr float DART_CONTROLLED_CIRCLE = 6; +constexpr float DART_CONTROLLED_SHARE = 1.2f; // 005400d0 The dart fly's AI: Lord of the Flies turns it blue and Skatole tames it into a fly. It weaves along a -// circle while homing in on where its target is heading, at up to 8. +// circle while homing in on where its target is heading, at up to 8. A controlled one weaves less and follows its +// controller's walking input. void npc_dart_fly_update(Entity_NPC& npc) { PlayerManager& players = g_game->playerManager; @@ -694,12 +697,14 @@ void npc_dart_fly_update(Entity_NPC& npc) g_game->scoreSheet.AddKilledEnemy(npc); npc.Remove(); beelzebub->AddBlueFlies(1, npc.pos, nullptr); + return; } if (players.FirstCollectibleOwner(COLLECTIBLE_SKATOLE, LAZARUS_SHARE_CHECK) && !npc.IsFriendly()) { npc.Morph(ENTITY_FLY, 0, 0, -1); npc.v2 = {}; npc.v1 = {}; + return; } if (npc.state == NPC_STATE_INIT) { @@ -707,24 +712,27 @@ void npc_dart_fly_update(Entity_NPC& npc) npc.state = NPC_STATE_MOVE; float turn = random_unit(); npc.v1.x = (turn + turn) * PI_F; + return; } if (npc.state == NPC_STATE_MOVE) { - if (npc.controllerID != -1) - reconstruction_missing("NpcAI::ENTITY_DART_FLY 005400d0: a dart fly under a player's control"); npc.v1.x += DART_TURN; - if (npc.v1.x >= DART_FULL_TURN) npc.v1.x -= DART_FULL_TURN; + if (npc.v1.x >= TAU) npc.v1.x -= TAU; Vector toward = vector_sub(npc.CalcTargetPosition(0), npc.pos); float distance = vector_length(toward); Vector lead = npc.GetPlayerTarget()->velocity; - Vector aim = vector_normalized(vector_make((lead.x + lead.x) * distance * DART_LEAD + toward.x, - (lead.y + lead.y) * distance * DART_LEAD + toward.y)); + bool isControlled = npc.controllerID != -1; + Vector aim = isControlled ? npc.GetControllerInput(0) + : vector_normalized(vector_make((lead.x + lead.x) * distance * DART_LEAD + toward.x, + (lead.y + lead.y) * distance * DART_LEAD + toward.y)); + float circle = isControlled ? DART_CONTROLLED_CIRCLE : DART_CIRCLE; + float share = isControlled ? DART_CONTROLLED_SHARE : DART_HOMING_SHARE; float circleX = (float)std::cos((double)(npc.v1.x * 0.5f)); float circleY = (float)std::sin((double)npc.v1.x); - float steerX = circleX * DART_CIRCLE + aim.x * DART_HOMING * DART_HOMING_SHARE; - float steerY = circleY * DART_CIRCLE + aim.y * DART_HOMING * DART_HOMING_SHARE; + float steerX = circleX * circle + aim.x * DART_HOMING * share; + float steerY = circleY * circle + aim.y * DART_HOMING * share; npc.velocity.x += steerX * DART_ACCEL * DART_ACCEL_DAMP * DART_ACCEL_SHARE * npc.speedMultiplier; npc.velocity.y += steerY * DART_ACCEL * DART_ACCEL_DAMP * DART_ACCEL_SHARE * npc.speedMultiplier; if (vector_length(npc.velocity) > DART_MAX_SPEED) npc.velocity = vector_resized(npc.velocity, DART_MAX_SPEED); diff --git a/src/npc_gaper.cpp b/src/npc_gaper.cpp index 3987b77..52c148e 100644 --- a/src/npc_gaper.cpp +++ b/src/npc_gaper.cpp @@ -46,7 +46,6 @@ constexpr float NULLS_SPEED = 0.90000004f; // The walk: the gap path marker each leaves (the Stoney's lower), the walk animation's threshold, and fleeing. constexpr int PATH_MARKER_STONEY = 100; -constexpr float FLEE_FRICTION = 0.8f; constexpr float ATTACK_FRICTION = 0.4f; // A dying gaper that was not torn apart gets up one time in two, a Gusher pacing one time in three. diff --git a/src/npc_grudge.cpp b/src/npc_grudge.cpp index d224204..3df2855 100644 --- a/src/npc_grudge.cpp +++ b/src/npc_grudge.cpp @@ -58,8 +58,6 @@ constexpr float GRUDGE_SPLAT_FRESH = 0.2f; constexpr int GRUDGE_SPLAT_PRIORITY = 255; constexpr float GRUDGE_DUST_EVERY = 2; constexpr float GRUDGE_DUST_DRAG = 0.2f; -constexpr float GRUDGE_DUST_SPIN_MIN = 2; -constexpr float GRUDGE_DUST_SPIN_RANGE = 10; constexpr int GRUDGE_DUST_LIFE_MIN = 15; constexpr int GRUDGE_DUST_LIFE_RANGE = 15; constexpr float GRUDGE_DUST_SCALE_MIN = 0.3f; @@ -154,7 +152,7 @@ static void trail_spawn(Entity_NPC& npc) .type = ENTITY_EFFECT, .variant = EFFECT_DUST_CLOUD, .seed = seed})); - dust->rotation = random_unit() * GRUDGE_DUST_SPIN_RANGE + GRUDGE_DUST_SPIN_MIN; + dust->rotation = random_between(DUST_SPIN_MIN, DUST_SPIN_RANGE); int life = (int)(Random() % GRUDGE_DUST_LIFE_RANGE) + GRUDGE_DUST_LIFE_MIN; dust->timeout = life; dust->lifespan = life; diff --git a/src/npc_gusher.cpp b/src/npc_gusher.cpp index 39b0057..1e4a01a 100644 --- a/src/npc_gusher.cpp +++ b/src/npc_gusher.cpp @@ -32,7 +32,6 @@ constexpr int BLUBBER_SHOTS_RANGE = 3; // They wander, slowed to three quarters (and more while fleeing), bleeding every 10 frames. constexpr float GUSHER_FRICTION = 0.75f; -constexpr float FLEE_FRICTION = 0.8f; constexpr float BLEED_TICKS = 10; constexpr float SPLAT_MIN = 0.2f; constexpr float SPLAT_RANGE = 0.3f; diff --git a/src/npc_guts.cpp b/src/npc_guts.cpp index faff5ea..dfeb622 100644 --- a/src/npc_guts.cpp +++ b/src/npc_guts.cpp @@ -62,7 +62,6 @@ constexpr int SLOG_RUMBLE_FRAMES = 4; constexpr float SLOG_RUMBLE_VOLUME = 0.4f; constexpr float SLOG_RUMBLE_PITCH = 0.7f; constexpr int SLOG_LANE_PATH_MAX = 650; -constexpr int LINE_CELL_BLOCKED_MAX = 8; // The Cyst shoots at 10 every 30 frames, from a blood poof 14 up. constexpr int CYST_SHOT_FRAMES = 30; @@ -120,27 +119,12 @@ static uint32_t guts_cell_collision_get(Vector position) return collision; } -// Room::CheckLine's stop position in its cell mode: a step short of the first blocked cell from start toward end, or -// of the end when the line crosses more than 8 cells with any grid path, else the end itself. +// Room::CheckLine's stop position in its cell mode. static Vector line_cell_stop_get(Vector start, Vector end) { - Room& room = *g_game->room; - Vector gap = vector_sub(start, end); - float length = vector_length(gap); - if (length <= 0) return end; - - Vector step = vector_make(gap.x / length * LINE_STEP, gap.y / length * LINE_STEP); - int startIndex = room.GetGridIndex(start); - int blocked = 0; - Vector at = start; - for (float walked = 0; walked < length; walked += LINE_STEP) - { - at = vector_sub(at, step); - int index = room.GetGridIndex(at); - if (room.GetGridCollision(index) != 0) return vector_add(at, step); - if (index != startIndex && room.GetGridPath(index) > 0) blocked++; - } - return blocked > LINE_CELL_BLOCKED_MAX ? vector_add(at, step) : end; + Vector stop = end; + room_check_line({.start = start, .end = end, .stopPosition = &stop, .mode = LINE_MODE_CELL}); + return stop; } // 005150b0 The unit step from one position to another in its row or column, when every cell between is open and diff --git a/src/npc_heart.cpp b/src/npc_heart.cpp index 831842e..ad9b5bf 100644 --- a/src/npc_heart.cpp +++ b/src/npc_heart.cpp @@ -175,7 +175,7 @@ static void dodge_pick(Entity_NPC& npc, Entity_NPC& partner, const LinkDodge& do for (float tries = 0; tries < LINK_SEARCH_TRIES - path.evadeDistance * LINK_SEARCH_TRY_COST; tries++) { float reach = random_unit() * LINK_SEARCH_RANGE + LINK_SEARCH_MIN; - float angle = random_unit() * RANDOM_HALF_TURN * 2; + float angle = random_unit() * PI_ROUGH * 2; Vector candidate = vector_make(std::cos(angle) * reach + ahead.x, std::sin(angle) * LINK_SEARCH_FLAT * reach + ahead.y); int cell = room.GetGridIndex(candidate); if (path.visitedGridIndices.contains(cell)) diff --git a/src/npc_hive.cpp b/src/npc_hive.cpp index ffe7f01..4d555fd 100644 --- a/src/npc_hive.cpp +++ b/src/npc_hive.cpp @@ -1,6 +1,7 @@ #include "npc_basement.h" #include "boss_ai.h" #include "game.h" +#include "menu_manager.h" #include "room.h" #include "room_grid.h" #include @@ -29,6 +30,7 @@ constexpr int NEST_REST_MIN = 55; constexpr int NEST_REST_RANGE = 20; constexpr float TAINTED_REST = 210; constexpr float CALM_REST = 3; +constexpr float HIDDEN_REST = 7; constexpr float HIVE_FRICTION = 0.8f; constexpr float DROWNED_FRICTION = 0.95f; @@ -96,14 +98,18 @@ static void hive_init(Entity_NPC& npc) npc.v1.x = 0; } -// Walking: it evades a hostile target (buzzing while it does) or wanders, its head bobbing along. +// Walking: it evades a hostile target (buzzing while it does) or wanders, its head bobbing along. A controlled one +// always evades, buzzing on its controller's pill button. static void hive_walk_update(Entity_NPC& npc) { - if (!npc.IsHostileTo(npc.GetPlayerTarget())) npc.pathfinder.MoveRandomly(STATUS_IGNORED); + bool isControlled = npc.controllerID != -1; + if (!isControlled && !npc.IsHostileTo(npc.GetPlayerTarget())) npc.pathfinder.MoveRandomly(STATUS_IGNORED); else { npc.pathfinder.EvadeTarget(npc.CalcTargetPosition(0), STATUS_OBEYED); - if (npc.pathfinder.evadeMovementCountdown > 0) + bool isBuzzing = isControlled ? npc.IsControllerActionTriggered(ACTION_PILL_CARD) + : npc.pathfinder.evadeMovementCountdown > 0; + if (isBuzzing) npc.PlaySound(SOUND_HIVE_BUZZ, 1, (int)(Random() % BUZZ_DELAY_RANGE) + BUZZ_DELAY_MIN, false, 1); } @@ -169,7 +175,8 @@ static void hive_release(Entity_NPC& npc) fly->isKillOnTouch = true; } -// Off rest while evading, it attacks a target within 300 (resting a short while otherwise), facing it. +// Off rest while evading, it attacks a target within 300 in sight (resting a short while otherwise, a bit longer when +// out of sight), facing it. A controlled one attacks on its controller's shooting input, facing along it. static void hive_attack_start(Entity_NPC& npc) { if (npc.v1.x > 0) @@ -178,18 +185,28 @@ static void hive_attack_start(Entity_NPC& npc) return; } + bool isControlled = npc.controllerID != -1; float facing = npc.GetPlayerTarget()->pos.x - npc.pos.x; float distance = vector_length(vector_sub(npc.GetPlayerTarget()->pos, npc.pos)); - if (distance >= ATTACK_RANGE || npc.HasEntityFlags(FLAG_DISTRACTED)) + bool isAttackWanted = isControlled ? !vector_is_zero(npc.GetControllerMovementInput(MOVEMENT_DEADZONE)) + : distance < ATTACK_RANGE; + if (!isAttackWanted || npc.HasEntityFlags(FLAG_DISTRACTED)) { npc.v1.x = CALM_REST; return; } + if (!isControlled && !room_check_line(npc.GetPlayerTarget()->pos, npc.pos, LINE_MODE_EXPLOSION, 0)) + { + npc.v1.x = HIDDEN_REST; + return; + } npc.v1.x = ATTACK_REST; - if (npc.type == ENTITY_NEST) npc.v1.x += (float)((int)(Random() % NEST_REST_RANGE) + NEST_REST_MIN); + if (npc.type == ENTITY_NEST) + npc.v1.x += (float)((isControlled ? 0 : (int)(Random() % NEST_REST_RANGE)) + NEST_REST_MIN); if (npc.type == ENTITY_HIVE && npc.variant == HIVE_TAINTED) npc.v1.x = TAINTED_REST; - npc.controllerMovement = {}; + npc.UpdateControllerMovement(true); + if (!vector_is_zero(npc.controllerMovement)) facing = npc.controllerMovement.x; if (npc.sprite.SetOverlayAnimation("HeadAttack", SWITCH_KEEP_FRAME)) { npc.sprite.overlayAnimState.Rewind(); @@ -277,7 +294,6 @@ static void hive_death(Entity_NPC& npc) void npc_hive_update(Entity_NPC& npc) { if (npc.state == NPC_STATE_INIT) return hive_init(npc); - if (npc.controllerID != -1) reconstruction_missing("NpcAI::ENTITY_HIVE 0050c370: a hive under a player's control"); if (npc.state == NPC_STATE_MOVE) hive_walk_update(npc); else @@ -298,7 +314,8 @@ void npc_hive_update(Entity_NPC& npc) if (ringFly->parent.get() != ringFly && ringFly->initSeed % TAINTED_CROWD_EVERY == 0) crowd--; if (npc.v1.x - npc.speedMultiplier <= 0 && (int)(Random() % REST_CROWD_RANGE) + REST_CROWD_MIN <= crowd) npc.v1.x += (float)((int)(Random() % REST_RANGE) + REST_MIN); - if (npc.pathfinder.evadeMovementCountdown > 0) hive_attack_start(npc); + if (npc.pathfinder.evadeMovementCountdown > 0 || npc.controllerID != -1) hive_attack_start(npc); if (npc.isDead && npc.health > HIVE_OVERKILL) hive_death(npc); + if (npc.controllerID != -1) npc.friction = 1; } diff --git a/src/npc_hopper.cpp b/src/npc_hopper.cpp index 7875738..55cc0b8 100644 --- a/src/npc_hopper.cpp +++ b/src/npc_hopper.cpp @@ -5,6 +5,7 @@ #include "room.h" #include "room_grid.h" #include "loot_list.h" +#include "menu_manager.h" // The hoppers this AI runs: the Hopper (with the Trite, Eggy and the tainted hopper as its variants), the Leaper, // the flaming hopper, the Keeper, Rag Man's Ragling, Ministro and Pon. @@ -58,6 +59,14 @@ constexpr float HOP_STALL_SPEED = 0.75f; constexpr int HOP_STALL_FRAMES = 30; constexpr int HOP_STALL_ODDS = 10; constexpr float HOPPER_FRICTION = 0.7f; + +// A controlled hopper: the fixed reach the Trite, Ragling and flaming hopper take, the charge (v2.x) its walking input +// builds up to 30 frames, a hop at once past 10 of it (for those resting no frames), and the step toward its aim target. +constexpr float CONTROLLED_TRITE_BONUS = 120; +constexpr float CONTROLLED_FLAMING_BONUS = 50; +constexpr float CONTROL_CHARGE_MAX = 30; +constexpr float CONTROL_CHARGE_HOP = 10; +constexpr float CONTROL_AIM_STEP = 10; constexpr int SOUND_HOPPER_LAND = 69; // The Keeper and Ministro shoot at a target within 200 in sight, the Ministro's shots heavier; the Ragling shoots @@ -165,13 +174,19 @@ static HopperJump hopper_jump_get(Entity_NPC& npc) { HopperJump jump; bool isTrite = (npc.type == ENTITY_HOPPER && npc.variant == HOPPER_TRITE) || npc.type == ENTITY_RAGLING; + bool isControlled = npc.controllerID != -1; if (isTrite) { - float first = random_unit() * TRITE_BONUS_FIRST; - jump.bonus = first + random_unit() * TRITE_BONUS_SECOND; + if (isControlled) jump.bonus = CONTROLLED_TRITE_BONUS; + else + { + float first = random_unit() * TRITE_BONUS_FIRST; + jump.bonus = first + random_unit() * TRITE_BONUS_SECOND; + } jump.delay = TRITE_JUMP_DELAY; } - else if (npc.type == ENTITY_FLAMING_HOPPER) jump.bonus = random_unit() * FLAMING_BONUS; + else if (npc.type == ENTITY_FLAMING_HOPPER) + jump.bonus = isControlled ? CONTROLLED_FLAMING_BONUS : random_unit() * FLAMING_BONUS; else if (npc.type == ENTITY_HOPPER && npc.variant == HOPPER_EGGY) jump.delay = EGGY_JUMP_DELAY; else if (npc.type == ENTITY_HOPPER && npc.variant == HOPPER_TAINTED) jump.delay = TAINTED_JUMP_DELAY; @@ -182,6 +197,20 @@ static HopperJump hopper_jump_get(Entity_NPC& npc) return jump; } +// A controlled hopper charges while walking input is held, shows its aim target at rest (and on landing), and the item +// button readies the Leaper's big jump (v2.y). +static void hopper_control_update(Entity_NPC& npc, const HopperJump& jump) +{ + npc.v2.x = vector_is_zero(npc.GetControllerInput(MOVEMENT_DEADZONE)) ? 0 : std::min(npc.v2.x + 1, CONTROL_CHARGE_MAX); + + AnimationState& anim = npc.sprite.animState; + bool isLanding = npc.state == NPC_STATE_MOVE && anim.animData && anim.WasEventTriggered("Land"); + if (npc.state == NPC_STATE_IDLE || npc.state == NPC_STATE_ATTACK || isLanding) + npc.SpawnControlTarget(CONTROL_INPUT_WALK, jump.range); + bool isGrounded = npc.state == NPC_STATE_IDLE || npc.state == NPC_STATE_MOVE; + if (isGrounded && npc.IsControllerActionPressed(ACTION_ITEM)) npc.v2.y = 1; +} + static void hopper_idle_reset(Entity_NPC& npc) { npc.state = NPC_STATE_IDLE; @@ -195,8 +224,10 @@ static void hopper_shoot_start(Entity_NPC& npc, const HopperAnims& anims, const bool isShooter = npc.type == ENTITY_KEEPER || npc.type == ENTITY_MINISTRO; if (!vector_is_zero(npc.targetPosition) || !isShooter || npc.HasEntityFlags(FLAG_DISTRACTED)) return; - if (npc.projectileCooldown < 1 && vector_length_squared(toward) < SHOOT_RANGE_SQUARED && - room_check_line(npc.pos, aim, LINE_MODE_PROJECTILE, LINE_CHECK_THRESHOLD)) + bool isInRange = npc.controllerID == -1 ? vector_length_squared(toward) < SHOOT_RANGE_SQUARED + : npc.IsTargetInAttackRange(CONTROLLED_ATTACK_RANGE, 0, true); + if (npc.projectileCooldown < 1 && isInRange && + (npc.controllerID != -1 || room_check_line(npc.pos, aim, LINE_MODE_PROJECTILE, LINE_CHECK_THRESHOLD))) { npc.UpdateControllerMovement(true); npc.projectileCooldown = SHOOT_COOLDOWN; @@ -212,16 +243,17 @@ static void hopper_shoot_start(Entity_NPC& npc, const HopperAnims& anims, const } // On its Shoot event a shooter fires two shots at its target, the Ministro a spray of five more, the Ragling one each -// way. It rests again once the animation ends. +// way, a controlled one along its controller's last shooting input. It rests again once the animation ends. static void hopper_shoot_update(Entity_NPC& npc, Vector toward) { - npc.controllerMovement = {}; + npc.UpdateControllerMovement(false); if (npc.sprite.animState.animData && npc.sprite.animState.IsEventTriggered("Shoot")) { float pitch = 1; if (npc.championColorIdx == CHAMPION_TINY) pitch = TINY_PITCH; else if (npc.championColorIdx == CHAMPION_GIANT) pitch = GIANT_PITCH; npc_sound_play(SOUND_SHOOT, 1, 2, pitch); + if (npc.controllerID != -1 && !vector_is_zero(npc.controllerMovement)) toward = npc.controllerMovement; Vector shot = vector_scale(vector_normalized(toward), SHOT_SPEED); if (npc.type == ENTITY_RAGLING) @@ -272,27 +304,40 @@ static uint32_t pon_landing_find(Entity_NPC& npc, float bonus, Vector& spot, uin } // A rested hopper picks its next spot: toward its target when in range (the flaming one leading it), else a random -// one, clamped into the room. It hops to the middle of a free cell there, or the Ragling attacks now and then. +// one, clamped into the room. A controlled one hops at its aim target (10 at most) once its input rests or it charged +// enough, Pon taking that spot as it is. It hops to the middle of a free cell there, or the Ragling attacks now and then +// (when its controller shoots). static void hopper_hop_start(Entity_NPC& npc, const HopperJump& jump, const HopperAnims& anims, const Vector& aim, const Vector& toward) { if (npc.stateFrame < jump.delay || !vector_is_zero(npc.targetPosition)) return; Room& room = *g_game->room; - Vector spot; - if (jump.range * jump.range <= vector_length_squared(toward)) - spot = vector_add(npc.pos, vector_scale(random_direction(), jump.bonus + RANDOM_HOP_REACH)); - else + bool isControlled = npc.controllerID != -1; + Vector spot{}; + if (!isControlled) { - spot = vector_add(aim, vector_scale(toward, jump.bonus / AIM_BONUS_SCALE)); - if (npc.type == ENTITY_FLAMING_HOPPER) - spot = vector_add(spot, vector_scale(npc.GetPlayerTarget()->velocity, FLAMING_LEAD)); + if (jump.range * jump.range <= vector_length_squared(toward)) + spot = vector_add(npc.pos, vector_scale(random_direction(), jump.bonus + RANDOM_HOP_REACH)); + else + { + spot = vector_add(aim, vector_scale(toward, jump.bonus / AIM_BONUS_SCALE)); + if (npc.type == ENTITY_FLAMING_HOPPER) + spot = vector_add(spot, vector_scale(npc.GetPlayerTarget()->velocity, FLAMING_LEAD)); + } + spot = room.GetClampedPosition(spot, HOP_CLAMP_MARGIN); + } + else if ((jump.delay == 0 && npc.v2.x > CONTROL_CHARGE_HOP) || npc.is_controller_input_idle()) + { + Vector target = npc.GetAimTargetPosition(); + if (vector_length(vector_sub(target, npc.pos)) > CONTROL_AIM_STEP) + spot = room.GetClampedPosition(target, CONTROL_AIM_STEP); } - spot = room.GetClampedPosition(spot, HOP_CLAMP_MARGIN); uint32_t collision = vector_is_zero(spot) ? COLLISION_BLOCKED : room_grid_collision_at(spot); - if (npc.type == ENTITY_PON) collision = pon_landing_find(npc, jump.bonus, spot, collision); - bool isAttacking = Random() % RAGLING_ATTACK_ODDS == 0; + if (npc.type == ENTITY_PON && !isControlled) collision = pon_landing_find(npc, jump.bonus, spot, collision); + bool isAttacking = isControlled ? npc.IsTargetInAttackRange(CONTROLLED_ATTACK_RANGE, 0, true) + : Random() % RAGLING_ATTACK_ODDS == 0; if (isAttacking && npc.type == ENTITY_RAGLING && !npc.HasEntityFlags(FLAG_DISTRACTED)) { npc.UpdateControllerMovement(true); @@ -476,13 +521,22 @@ static void leaper_land(Entity_NPC& npc) npc.FireProjectiles(npc.pos, vector_make(speed, 0), PROJECTILES_PLUS, ProjectileParams()); } -// In the air the Leaper passes over everything, drifting a growing share of the way to its spot. +// In the air the Leaper passes over everything, drifting a growing share of the way to its spot. A controlled one is +// steered instead, kept in by the walls, its spot following it. static void leaper_drift(Entity_NPC& npc) { + bool isControlled = npc.controllerID != -1; npc.entityCollisionClass = ENTCOLL_NONE; - npc.entityGridCollisionClass = GRIDCOLL_NONE; + npc.entityGridCollisionClass = isControlled ? GRIDCOLL_WALLS : GRIDCOLL_NONE; npc.v1.x += BIG_JUMP_DRIFT; float share = npc.v1.x; + if (isControlled) + { + npc.apply_controller_movement(CONTROL_STEER_ACCEL, CONTROL_STEER_DRAG - share * CONTROL_STEER_DRAG_FALL, + CONTROL_STEER_SPEED); + npc.targetPosition = npc.pos; + return; + } npc.pos.y = (1 - share) * npc.pos.y + share * npc.targetPosition.y; npc.pos.x = (1 - share) * npc.pos.x + share * npc.targetPosition.x; } @@ -502,7 +556,12 @@ static void leaper_big_jump_update(Entity_NPC& npc) AnimationState& anim = npc.sprite.animState; if (npc.state == NPC_STATE_JUMP) { - if (!anim.animData || !anim.WasEventTriggered("Jump")) return leaper_ground(npc); + if (!anim.animData || !anim.WasEventTriggered("Jump")) + { + leaper_ground(npc); + if (npc.controllerID != -1) npc.pathfinder.FindGridPath({}, HALF, 0, DIRECT_PATH_FAR); + return; + } leaper_drift(npc); if (anim.animData && anim.isPlaying) return; npc.state = NPC_STATE_STOMP; @@ -678,7 +737,6 @@ static void eggy_burst_start(Entity_NPC& npc) void npc_hopper_update(Entity_NPC& npc) { if (npc.state == NPC_STATE_INIT) return hopper_init(npc); - if (npc.controllerID != -1) reconstruction_missing("NpcAI::ENTITY_HOPPER 00526470: a hopper under a player's control"); bool isHopKnocked = npc.HasEntityFlags(FLAG_KNOCKED_BACK) && npc.knockbackCountdown == 1 && !vector_is_zero(npc.targetPosition) && npc.state == NPC_STATE_MOVE; @@ -692,6 +750,7 @@ void npc_hopper_update(Entity_NPC& npc) else if (isAnimDone && npc.state == NPC_STATE_STOMP) npc.sprite.Play("BigJumpDown"); HopperJump jump = hopper_jump_get(npc); + if (npc.controllerID != -1) hopper_control_update(npc, jump); Vector aim = npc.CalcTargetPosition(TARGET_DISTANCE); Vector toward = vector_sub(aim, npc.pos); if (npc.state == NPC_STATE_IDLE) hopper_shoot_start(npc, anims, aim, toward); @@ -702,8 +761,8 @@ void npc_hopper_update(Entity_NPC& npc) else if (state == NPC_STATE_IDLE) hopper_hop_start(npc, jump, anims, aim, toward); else if (state == NPC_STATE_MOVE) hopper_hop_update(npc, anims); - if (npc.type == ENTITY_LEAPER && vector_is_zero(npc.targetPosition) && Random() % BIG_JUMP_ODDS == 0 && - !npc.HasEntityFlags(FLAG_DISTRACTED)) + if (npc.type == ENTITY_LEAPER && vector_is_zero(npc.targetPosition) && + (npc.controllerID == -1 ? Random() % BIG_JUMP_ODDS == 0 : npc.v2.y > 0) && !npc.HasEntityFlags(FLAG_DISTRACTED)) leaper_big_jump_start(npc, aim); if (npc.state == NPC_STATE_IDLE) npc.entityGridCollisionClass = GRIDCOLL_GROUND; if (npc.type == ENTITY_RAGLING && npc.variant == RAGLING_RAG_MAN) ragling_update(npc); diff --git a/src/npc_maggot.cpp b/src/npc_maggot.cpp index 499aae6..4b32070 100644 --- a/src/npc_maggot.cpp +++ b/src/npc_maggot.cpp @@ -490,9 +490,7 @@ static void maggot_charge_try(Entity_NPC& npc, MaggotFrame& frame) { if (std::abs(delta.x) >= CHARGE_AXIS && std::abs(delta.y) >= CHARGE_AXIS) return; if (vector_length_squared(delta) >= CHARGE_RANGE_SQUARED && npc.type != ENTITY_LEECH) return; - bool isClear = npc.type == ENTITY_LEECH ? explosion_line_clear(cell, spot, false) - : room_check_line(cell, spot, LINE_MODE_GROUND, 0); - if (!isClear) return; + if (!room_check_line(cell, spot, npc.type == ENTITY_LEECH ? LINE_MODE_EXPLOSION : LINE_MODE_GROUND, 0)) return; } if (npc.type == ENTITY_LEECH) npc.PlaySound(SOUND_LEECH, 1, MAGGOT_CHARGE_SOUND_DELAY, false, 1); diff --git a/src/npc_mama_fly.cpp b/src/npc_mama_fly.cpp index aa6c4e5..019182b 100644 --- a/src/npc_mama_fly.cpp +++ b/src/npc_mama_fly.cpp @@ -98,7 +98,7 @@ static void mama_fly_spot_pick(Entity_NPC& npc) float bestDistance = 0; for (int i = 0; i < MAMA_FLY_SPOT_TRIES; i++) { - float angle = random_unit() * RANDOM_HALF_TURN * 2; + float angle = random_unit() * PI_ROUGH * 2; float reach = random_unit() * MAMA_FLY_SPOT_RANGE + MAMA_FLY_SPOT_MIN; Vector spot = vector_add(npc.pos, vector_make(std::cos(angle) * reach, std::sin(angle) * reach)); int cell = room.GetGridIndex(spot); @@ -128,7 +128,7 @@ static void mama_fly_death(Entity_NPC& npc) Room& room = *g_game->room; for (int i = 0; i < MAMA_FLY_MAGGOTS; i++) { - float angle = random_unit() * RANDOM_HALF_TURN * 2; + float angle = random_unit() * PI_ROUGH * 2; float reach = random_unit(); Vector spot = vector_make(std::cos(angle) * reach * MAMA_FLY_MAGGOT_REACH + npc.pos.x, std::sin(angle) * reach * MAMA_FLY_MAGGOT_REACH + npc.pos.y); diff --git a/src/npc_mole.cpp b/src/npc_mole.cpp index f999de4..43bd49a 100644 --- a/src/npc_mole.cpp +++ b/src/npc_mole.cpp @@ -54,8 +54,10 @@ constexpr float DIG_OUT_NEAR_SQUARED = 8100; constexpr float DIG_OUT_FAR_SQUARED = 40000; constexpr int DIG_OUT_LATE_FRAMES = 90; constexpr int DIG_OUT_CONTROLLED_FRAMES = 150; +// A controlled mole kept under past that, unable to dig out, takes 5 damage every 30 frames. +constexpr float CONTROLLED_UNDER_DAMAGE = 5; +constexpr int CONTROLLED_UNDER_TICK = 30; constexpr int CONTROLLER_ATTACK_ACTION = 9; -constexpr float CONTROLLED_ATTACK_RANGE = 1000; constexpr int CONTROLLED_ATTACK_EVERY = 7; constexpr float DIRT_PILE_SPACING_SQUARED = 144; constexpr float TAINTED_CRUSH_DAMAGE = 10; @@ -141,7 +143,7 @@ static Vector jump_spot_get(Entity_NPC& npc, int tries) return vector_add(npc.pos, vector_scale(input, JUMP_CONTROLLED_REACH - (float)tries * JUMP_CONTROLLED_SHRINK)); } if ((Random() & JUMP_TARGET_MASK) == 0) return npc.CalcTargetPosition(0); - float angle = random_unit() * RANDOM_HALF_TURN * 2; + float angle = random_unit() * PI_ROUGH * 2; return vector_add(npc.pos, vector_make(std::cos(angle) * JUMP_STEP, std::sin(angle) * JUMP_STEP)); } @@ -285,8 +287,9 @@ static void mole_burrow(Entity_NPC& npc, bool isDark) npc.UpdateDirtColor(true); return; } - if (npc.stateFrame > DIG_OUT_CONTROLLED_FRAMES && npc.controllerID != -1) - reconstruction_missing("NpcAI::ENTITY_MOLE 004fdf80: a controlled mole kept under too long"); + bool isTick = npc.stateFrame / CONTROLLED_UNDER_TICK < (npc.stateFrame + npc_ticks_get(npc)) / CONTROLLED_UNDER_TICK; + if (npc.stateFrame > DIG_OUT_CONTROLLED_FRAMES && npc.controllerID != -1 && isTick) + npc.TakeDamage(CONTROLLED_UNDER_DAMAGE, 0, EntityRef(), CONTROLLED_UNDER_TICK); } npc.stateFrame += npc_ticks_get(npc); dirt_pile_leave(npc); diff --git a/src/npc_polty.cpp b/src/npc_polty.cpp new file mode 100644 index 0000000..ae6bf07 --- /dev/null +++ b/src/npc_polty.cpp @@ -0,0 +1,802 @@ +#include "boss_ai.h" +#include "boss_repentance.h" +#include "entity_config.h" +#include "entity_pickup.h" +#include "entity_player.h" +#include "grid_entity.h" +#include "npc_basement.h" +#include "room_grid.h" +#include + +// The Polty's states: waiting unseen to appear (Kineti), looking for something to lift, holding it, lifting a pickup +// or a pot it hid in, lifting a rock, throwing, the Kineti's telekinesis and hiding in a pot. +enum PoltyState +{ + POLTY_HIDDEN = NPC_STATE_APPEAR_CUSTOM, + POLTY_IDLE = NPC_STATE_IDLE, + POLTY_HOLD = NPC_STATE_MOVE, + POLTY_LIFT_FIRST = NPC_STATE_ATTACK, + POLTY_LIFT = NPC_STATE_ATTACK2, + POLTY_THROW = NPC_STATE_ATTACK3, + POLTY_TELEKINESIS = NPC_STATE_SUMMON, + POLTY_POT = NPC_STATE_SPECIAL +}; + +// Its variants, and what i2 holds besides a target cell: nothing, or nothing it may ever lift (it then drifts away +// from its target). +constexpr int POLTY_KINETI = 1; +constexpr int POLTY_NO_TARGET = -1; +constexpr int POLTY_FLEEING = -2; + +// It hides 30 to 59 frames, showing up only farther than 80 (squared) from the nearest player. Its splat is pale. +constexpr uint32_t POLTY_HIDE_RANGE = 30; +constexpr int POLTY_HIDE_FRAMES = 30; +constexpr float POLTY_APPEAR_DISTANCE_SQUARED = 80; +constexpr ColorMod POLTY_SPLAT_COLOR = {{0, 0, 0, 0.3f}, {0, 0, 0, 0}, {0.8f, 0.8f, 0.8f}}; + +// Every 10 frames without a target it picks the liftable cell scoring least: its distance over its walled sides (a +// twelfth each), or for the Kineti how far behind its target it lies (at least 0.1). Pots count a fifth, bomb rocks +// and TNT two fifths, poops 0.7 and tinted and super secret rocks three times. Six searches without one and it flees +// (unless friendly), as it does carrying a tinted or super secret rock. Feared, confused or shrunk it drops its target +// one time in six. +constexpr int POLTY_SEARCH_EVERY = 10; +constexpr float POLTY_SCORE_UNSET = 1e10f; +constexpr float POLTY_WALL_SHARE = 12; +constexpr float POLTY_KINETI_SCORE = 1000; +constexpr float POLTY_KINETI_SCORE_MIN = 0.1f; +constexpr float POLTY_POT_SCORE = 0.2f; +constexpr float POLTY_BLAST_SCORE = 0.4f; +constexpr float POLTY_POOP_SCORE = 0.7f; +constexpr float POLTY_PRECIOUS_SCORE = 3; +constexpr int POLTY_SEARCHES = 5; +constexpr uint32_t POLTY_FORGET_ODDS = 6; + +// Next to its target cell (within 8, slower than 1) it lifts it. The Kineti instead (one time in ten, on screen) +// reaches for it by telekinesis. +constexpr float POLTY_REACH_SQUARED = 64; +constexpr float POLTY_LIFT_SPEED = 1; +constexpr uint32_t POLTY_TELEKINESIS_ODDS = 10; + +// Its throw: at 10 where its target will be in 4 frames (from its own speed in 4 frames), a pickup with a fifth of +// its speed and thrown at 8. +constexpr float POLTY_THROW_LEAD = 4; +constexpr float POLTY_THROW_SPEED = 10; +constexpr float POLTY_PICKUP_CARRY = 0.2f; +constexpr float POLTY_PICKUP_THROW_FORCE = 8; + +// The telekinesis: 7 frames after the throw event the rock rises from its cell at 1 toward the Kineti (from 8 up, +// falling slowly upward, through walls), then is pulled in at up to 22 (1.1 times its speed plus 0.6), tinted every +// 4 frames, and caught within 60. The beam shows while the rock is on its way. +constexpr int POLTY_TELEKINESIS_RISE = 6; +constexpr float POLTY_TELEKINESIS_FRICTION = 0.6f; +constexpr float POLTY_RISE_SPEED = 1; +constexpr float POLTY_RISE_HEIGHT = -8; +constexpr float POLTY_RISE_FALL = -0.9f; +constexpr float POLTY_PULL_SHARE = 1.1f; +constexpr float POLTY_PULL_MIN = 0.6f; +constexpr float POLTY_PULL_MAX = 22; +constexpr float POLTY_PULL_HEIGHT = -20; +constexpr float POLTY_PULL_LIFT = 0.2f; +constexpr int POLTY_PULL_TINT_EVERY = 4; +constexpr int POLTY_PULL_TINT_FRAMES = 4; +constexpr ColorMod POLTY_PULL_COLOR = {{0.8f, 0.8f, 0.8f, 1}, {0, 0, 0, 0}, {0.2f, 0, 0.4f}}; +constexpr float POLTY_CATCH_SQUARED = 3600; +constexpr float POLTY_CATCH_PUSH = 0.5f; + +// Moving: at 0.7 toward its target cell (twice that, braking at 0.7, within 40), or for the Kineti to 120 beyond its +// target from the cell. Without a target it hovers 100 short of where it aims, throwing (one time in four within 150 +// of where it will be in 4 frames). Fleeing it drifts away and goes 400 out of the room. It slows by 0.95. +constexpr float POLTY_MOVE_SPEED = 0.7f; +constexpr float POLTY_NEAR = 40; +constexpr float POLTY_NEAR_FRICTION = 0.7f; +constexpr float POLTY_KINETI_SPOT = 120; +constexpr float POLTY_HOVER_SHORT = 100; +constexpr uint32_t POLTY_THROW_MASK = 3; +constexpr float POLTY_THROW_REACH = 150; +constexpr float POLTY_MOVE_FRICTION = 0.95f; +constexpr float POLTY_FLEE_OUT = -400; +constexpr float POLTY_CONTROLLED_RANGE = 1000; + +// Its death drops what it holds at 0.7 of its speed (a pickup thrown at 8), breaks the pot it hid in, and lets the +// Kineti's rock fall. +constexpr float POLTY_DROP_SHARE = 0.7f; +constexpr float POLTY_DROPPED_FALL = 0.8f; + +// A rock it throws: from 30 up, rising at 5 and falling 0.8 a tick. A giant poop is four times as big. +constexpr float POLTY_ROCK_HEIGHT = -30; +constexpr float POLTY_ROCK_RISE = -5; +constexpr float POLTY_ROCK_FALL = 0.8f; +constexpr float POLTY_GIANT_POOP_SCALE = 4; +constexpr float POLTY_GIANT_POOP_SIZE = 3; +constexpr int POLTY_GIANT_POOP_VARIANT = 7; + +// 0055d070 Takes a cell as its target unless a path already runs over it. +static bool polty_target_set(Entity_NPC& npc, int gridIndex) +{ + bool isFree = gridIndex < 0 || gridIndex >= ROOM_GRID_CELLS || g_game->room->gridPaths[gridIndex] < 1; + if (isFree) npc.i2 = gridIndex; + return isFree; +} + +// 0055d0b0 Whether what it is after can still be lifted: the pickup it came from (it snaps to it), or its target cell +// (the Polty snaps onto it). +static bool polty_is_target_liftable(Entity_NPC& npc) +{ + Entity* spawner = npc.spawnerEntity.get(); + if (spawner && spawner->type == ENTITY_PICKUP) npc.pos = spawner->pos; + else + { + if (npc.i2 < 0 || !g_game->room->CanPickupGridEntity(npc.i2)) return false; + if (npc.variant == POLTY_KINETI) return true; + npc.pos = g_game->room->GetGridPosition(npc.i2); + } + npc.velocity = {}; + return true; +} + +// 0055d180 Hides in the pot or urn on a cell (a whole one), taking it as its target. +static bool polty_is_pot_cell(Entity_NPC& npc, int gridIndex) +{ + if ((uint32_t)gridIndex >= ROOM_GRID_CELLS) return false; + GridEntity* grid = g_game->room->gridEntities[gridIndex]; + bool isPot = grid && (grid->type == GRID_ROCK_ALT || grid->type == GRID_ROCK_ALT2) && grid->state == 1; + if (!isPot || !polty_target_set(npc, gridIndex)) return false; + npc.pos = g_game->room->GetGridPosition(gridIndex); + return true; +} + +// 006d9550 Throws a lifted grid entity as a rock projectile wearing its look, from 30 up: it keeps a poop's health +// (a giant one four times as big) and a rock's death trigger. A charmed Polty's rock hits enemies, a friendly one's +// spares players. +static Entity_Projectile* polty_rock_throw(Entity_NPC& npc, Entity_Effect& lifted, const Vector& velocity, int backdrop) +{ + const GridEntityDesc& desc = lifted.gridDesc; + int subType = (int)((uint32_t)desc._type << GRID_TYPE_SHIFT | (uint16_t)desc._variant); + auto* rock = static_cast(g_game->Spawn({.position = npc.pos, .velocity = velocity, .spawner = &npc, + .subType = subType, .type = ENTITY_PROJECTILE, + .variant = PROJECTILE_GRID, .seed = desc._spawnSeed})); + if (desc._type == GRID_POOP) + { + rock->health = (float)desc._state; + if (desc._variant == POLTY_GIANT_POOP_VARIANT) + { + rock->scale = POLTY_GIANT_POOP_SCALE; + rock->SetSize(rock->config->collisionRadius * POLTY_GIANT_POOP_SIZE, vector_make(-1, -1), -1); + } + if (desc._varData == 1) rock->AddEntityFlags(FLAG_NO_DEATH_TRIGGER); + } + rock->wiggleFrameOffset = backdrop; + rock->height = POLTY_ROCK_HEIGHT; + rock->fallingAccel = POLTY_ROCK_FALL; + rock->fallingSpeed = POLTY_ROCK_RISE; + + rock->sprite = lifted.sprite; + for (LayerState& layer : rock->sprite.layerStates) + { + layer.pos = {}; + layer.size = vector_make(1, 1); + } + if (npc.HasEntityFlags(FLAG_CHARM)) + { + rock->projectileFlags |= PROJECTILE_HIT_ENEMIES; + rock->parent = &npc; + } + if (npc.HasEntityFlags(FLAG_FRIENDLY)) rock->projectileFlags |= PROJECTILE_CANT_HIT_PLAYER; + rock->Update(); + return rock; +} + +// The walls about a cell, summed by their collision. +static uint32_t polty_walls_around(const Vector& cell) +{ + return room_grid_collision_at(vector_make(cell.x - GRID_CELL_SIZE, cell.y)) + + room_grid_collision_at(vector_make(cell.x + GRID_CELL_SIZE, cell.y)) + + room_grid_collision_at(vector_make(cell.x, cell.y - GRID_CELL_SIZE)) + + room_grid_collision_at(vector_make(cell.x, cell.y + GRID_CELL_SIZE)); +} + +// How much a liftable cell suits it (less is better): near and sheltered, or for the Kineti far behind its target. +static float polty_cell_score(Entity_NPC& npc, int cell, const Vector& target) +{ + Room& room = *g_game->room; + Vector at = room.GetGridPosition(cell); + float score = 0; + if (npc.variant == POLTY_KINETI) + { + Vector away = vector_normalized(vector_sub(target, npc.pos)); + float behind = std::max(away.y * (at.y - target.y) + away.x * (at.x - target.x), POLTY_KINETI_SCORE_MIN); + score = POLTY_KINETI_SCORE / behind; + } + else + score = vector_distance(npc.pos, at) / ((float)(int)polty_walls_around(at) / POLTY_WALL_SHARE + 1); + + switch (room.gridEntities[cell]->type) + { + case GRID_ROCK_ALT: + case GRID_ROCK_ALT2: + return score * POLTY_POT_SCORE; + case GRID_ROCK_BOMB: + case GRID_TNT: + return score * POLTY_BLAST_SCORE; + case GRID_POOP: + return score * POLTY_POOP_SCORE; + case GRID_ROCKT: + case GRID_ROCK_SS: + return score * POLTY_PRECIOUS_SCORE; + default: + return score; + } +} + +// Picks its target cell every 10 frames while it has none, fleeing after six fruitless searches. +static void polty_target_search(Entity_NPC& npc, bool isFriendly) +{ + Room& room = *g_game->room; + if (npc.i2 == POLTY_NO_TARGET && npc.IsFrame(POLTY_SEARCH_EVERY, 0) && !npc.HasEntityFlags(FLAG_FEAR | FLAG_SHRINK)) + { + Vector target = npc.GetPlayerTarget()->pos; + float best = POLTY_SCORE_UNSET; + int bestCell = -1; + for (int cell = 0; cell < room.gridHeight * room.gridWidth; cell++) + { + bool isFree = cell >= ROOM_GRID_CELLS || room.gridPaths[cell] == 0; + if (!isFree || !room.CanPickupGridEntity(cell)) continue; + float score = polty_cell_score(npc, cell, target); + if (bestCell < 0 || score < best) + { + bestCell = cell; + best = score; + } + } + if (bestCell >= 0) polty_target_set(npc, bestCell); + + if (npc.i2 < 0 && !isFriendly) + { + if (++npc.i1 > POLTY_SEARCHES) + { + npc.i2 = POLTY_FLEEING; + npc.entityGridCollisionClass = GRIDCOLL_NONE; + } + } + else npc.i1 = 0; + } + if (npc.HasEntityFlags(FLAG_DISTRACTED) && Random() % POLTY_FORGET_ODDS == 0) npc.i2 = POLTY_NO_TARGET; +} + +// The Kineti's beam marker, the first of its entity deque. +static Entity* kineti_beam_get(Entity_NPC& npc) +{ + return npc.entityDeque.empty() ? nullptr : npc.entityDeque[0].get(); +} + +static void kineti_beam_remove(Entity_NPC& npc) +{ + if (!kineti_beam_get(npc)) return; + npc.entityDeque[0]->Remove(); + npc.entityDeque[0] = nullptr; +} + +// Back to looking about, shown and touchable. +static void polty_idle_restore(Entity_NPC& npc) +{ + npc.state = POLTY_IDLE; + npc.sprite.Play("Idle"); + npc.entityCollisionClass = ENTCOLL_ALL; + npc.isVisible = true; +} + +// Hides, out of sight and untouchable, for 30 to 59 frames. +static void polty_hide(Entity_NPC& npc, PoltyState state) +{ + npc.ClearEntityFlags(FLAG_APPEAR); + npc.state = state; + npc.isVisible = false; + uint32_t frames = Random(); + npc.entityCollisionClass = ENTCOLL_NONE; + npc.stateFrame = (int)(frames % POLTY_HIDE_RANGE) + POLTY_HIDE_FRAMES; +} + +// Its first frame: from a pickup it lifts it at once, else (on the room's first frame) the Kineti hides to appear +// later and the Polty hides in a pot next to it or anywhere in the room. +static void polty_init(Entity_NPC& npc) +{ + Room& room = *g_game->room; + npc.state = POLTY_IDLE; + npc.splatColor = POLTY_SPLAT_COLOR; + npc.stateFrame = 0; + npc.i1 = 0; + if (Entity* spawner = npc.spawnerEntity.get()) + { + if (spawner->type != ENTITY_PICKUP) return; + npc.ClearEntityFlags(FLAG_APPEAR); + npc.state = POLTY_LIFT_FIRST; + return; + } + if (!room.isInitialized || g_game->frameCount != room.enterFrame) return; + + if (npc.variant == POLTY_KINETI) + { + polty_hide(npc, POLTY_HIDDEN); + npc.sprite.SetFrame("SpecialAppear", 0); + return; + } + + int cell = room.GetGridIndex(npc.pos); + int row = cell / room.gridWidth; + int column = cell % room.gridWidth; + bool isHidden = (row < room.gridHeight - 1 && polty_is_pot_cell(npc, room.GetGridIndexByTile(column, row + 1))) || + (row > 0 && polty_is_pot_cell(npc, room.GetGridIndexByTile(column, row - 1))) || + (column > 0 && polty_is_pot_cell(npc, room.GetGridIndexByTile(column - 1, row))) || + (column < room.gridWidth - 1 && polty_is_pot_cell(npc, room.GetGridIndexByTile(column + 1, row))); + for (int each = 0; !isHidden && each < room.gridHeight * room.gridWidth; each++) isHidden = polty_is_pot_cell(npc, each); + if (isHidden) polty_hide(npc, POLTY_POT); +} + +// The Kineti waiting unseen, then appearing away from the players. +static void polty_hidden(Entity_NPC& npc, int ticks) +{ + if (npc.controllerID != -1 && !vector_is_zero(npc.GetControllerInput(MOVEMENT_DEADZONE))) npc.stateFrame = 0; + if (npc.stateFrame >= 1) + { + npc.stateFrame -= ticks; + return; + } + Entity_Player* nearest = game_nearest_player(npc.pos); + if (vector_length_squared(vector_sub(npc.pos, nearest->pos)) <= POLTY_APPEAR_DISTANCE_SQUARED) return; + + if (!npc.isVisible) + { + npc.isVisible = true; + if (npc.sprite.SetAnimation("SpecialAppear")) + { + npc.sprite.animState.Rewind(); + npc.sprite.animState.isPlaying = true; + } + } + if (npc.sprite.IsEventTriggered("PickupThrow")) npc.PlaySound(SOUND_PORTAL_SPAWN, 1, 2, false, 1); + const NullFrame* overlay = npc.sprite.GetNullFrame("OverlayEffect"); + if (overlay && overlay->isVisible) npc.entityCollisionClass = ENTCOLL_ALL; + if (!npc.sprite.animState.animData || !npc.sprite.animState.isPlaying) + { + npc.entityCollisionClass = ENTCOLL_ALL; + npc.state = POLTY_IDLE; + } +} + +// Looking about: keeping or choosing a target cell, and lifting it once beside it (the Kineti by telekinesis). +static void polty_idle(Entity_NPC& npc, bool isFriendly) +{ + Room& room = *g_game->room; + npc.sprite.Play("Idle"); + if (npc.i2 >= 0 && !room.CanPickupGridEntity(npc.i2)) npc.i2 = POLTY_NO_TARGET; + + if (npc.controllerID == -1) polty_target_search(npc, isFriendly); + else + { + if (npc.variant == POLTY_KINETI) npc.SpawnControlTarget(0, -1); + if (npc.IsControllerActionPressed(CONTROLLER_ACTION_SHOOT)) + { + int cell = room.GetGridIndex(npc.variant == POLTY_KINETI ? npc.GetAimTargetPosition() : npc.pos); + if (room.CanPickupGridEntity(cell)) npc.i2 = cell; + } + } + + if (npc.i2 < 0) return; + if (npc.variant == POLTY_KINETI) + { + if (Random() % POLTY_TELEKINESIS_ODDS != 0 || !room.camera->IsPosVisible(npc.pos)) return; + npc.state = POLTY_TELEKINESIS; + npc.sprite.Play("TeleStart"); + npc.stateFrame = 0; + return; + } + bool isBeside = vector_length(npc.velocity) < POLTY_LIFT_SPEED && + vector_length_squared(vector_sub(room.GetGridPosition(npc.i2), npc.pos)) < POLTY_REACH_SQUARED; + if (npc.controllerID != -1 || isBeside) npc.state = POLTY_LIFT; +} + +// Its throw: on PickupThrow what it holds flies at its target (or where its player steers), a rock as a projectile, a +// pickup thrown. Then it looks about again. +static void polty_throw(Entity_NPC& npc, Entity*& held) +{ + npc.sprite.Play("Throw"); + if (npc.controllerID == -1) npc.controllerMovement = {}; + else + { + Vector input = npc.GetControllerMovementInput(MOVEMENT_DEADZONE); + if (!vector_is_zero(input)) npc.controllerMovement = input; + } + + if (npc.sprite.animState.animData && npc.sprite.animState.IsEventTriggered("PickupThrow") && held) + { + Entity* target = npc.GetPlayerTarget(); + Vector lead = vector_make(target->velocity.x * POLTY_THROW_LEAD + target->pos.x + npc.velocity.x * POLTY_THROW_LEAD - npc.pos.x, + target->velocity.y * POLTY_THROW_LEAD + target->pos.y + npc.velocity.y * POLTY_THROW_LEAD - npc.pos.y); + Vector aim = vector_normalized(lead); + bool isPickup = held->type == ENTITY_PICKUP; + Vector carried = isPickup ? vector_scale(npc.velocity, POLTY_PICKUP_CARRY) : npc.velocity; + Vector throwVelocity = vector_make(carried.x + aim.x * POLTY_THROW_SPEED, carried.y + aim.y * POLTY_THROW_SPEED); + if (npc.controllerID != -1) + throwVelocity = vector_add(vector_scale(npc.controllerMovement, POLTY_THROW_SPEED), npc.velocity); + + if (held->type == ENTITY_EFFECT && held->variant == EFFECT_GRID_ENTITY_PROJECTILE_HELPER) + { + polty_rock_throw(npc, *static_cast(held), throwVelocity, 0); + held->Remove(); + } + else if (!isPickup) held->Remove(); + else + { + held->TryThrow(EntityRef(&npc), throwVelocity, POLTY_PICKUP_THROW_FORCE); + held->parent = nullptr; + npc.entityRef = nullptr; + } + held = nullptr; + } + if (npc.sprite.animState.animData && npc.sprite.animState.isPlaying) return; + polty_idle_restore(npc); +} + +// The Kineti's rock arrives: it becomes a held rock again, the beam goes, and the Kineti takes the rock's push. +static Entity* kineti_rock_catch(Entity_NPC& npc, Entity& rock) +{ + rock.sprite.color = COLOR_DEFAULT; + uint32_t seed = Random(); + auto* lifted = static_cast( + g_game->Spawn({.position = npc.pos, .type = ENTITY_EFFECT, .variant = EFFECT_GRID_ENTITY_PROJECTILE_HELPER, .seed = seed})); + lifted->sprite = rock.sprite; + lifted->gridDesc._type = (int)((uint32_t)rock.subtype >> GRID_TYPE_SHIFT); + lifted->gridDesc._variant = rock.subtype & GRID_VARIANT_MASK; + lifted->gridDesc._spawnSeed = rock.initSeed; + lifted->gridDesc._state = lifted->gridDesc._type == GRID_POOP ? (int)rock.health : 0; + lifted->pos = npc.pos; + lifted->parent = &npc; + npc.entityRef = lifted; + kineti_beam_remove(npc); + + npc.velocity = vector_add(npc.velocity, vector_scale(rock.velocity, POLTY_CATCH_PUSH * npc.speedMultiplier)); + rock.Remove(); + npc.child = nullptr; + npc.sprite.Play("Pickup"); + npc.state = POLTY_LIFT; + return lifted; +} + +// The telekinesis: on the throw event (or 7 frames on) the target cell's rock rises toward the Kineti, then is pulled +// in and caught. Without a target it gives up. +static void kineti_telekinesis(Entity_NPC& npc, Entity*& held, int ticks) +{ + Room& room = *g_game->room; + Entity* rock = npc.child.get(); + if (rock && (rock->type != ENTITY_PROJECTILE || rock->variant != PROJECTILE_GRID)) + { + npc.child = nullptr; + rock = nullptr; + } + Entity* spawner = npc.spawnerEntity.get(); + if (!rock && spawner && spawner->type == ENTITY_PICKUP) + { + npc.pos = spawner->pos; + npc.velocity = {}; + } + else if (!rock && !room.CanPickupGridEntity(npc.i2)) + { + kineti_beam_remove(npc); + polty_idle_restore(npc); + return; + } + else if (!rock && npc.variant != POLTY_KINETI) + { + npc.pos = room.GetGridPosition(npc.i2); + npc.velocity = {}; + } + + if (!npc.sprite.animState.animData || !npc.sprite.animState.isPlaying) npc.sprite.Play("TeleLoop"); + bool isThrown = npc.sprite.animState.animData && npc.sprite.animState.IsEventTriggered("PickupThrow"); + if (isThrown) npc.stateFrame = 1; + bool isReaching = npc.stateFrame > 0; + if (isReaching) npc.friction *= POLTY_TELEKINESIS_FRICTION; + if (isReaching && !rock) + { + int frame = npc.stateFrame; + npc.stateFrame = ticks + frame; + Vector cell = room.GetGridPosition(npc.i2); + if (ticks + frame > POLTY_TELEKINESIS_RISE) + { + Vector rise = vector_resized(vector_sub(cell, npc.pos), POLTY_RISE_SPEED); + // The original crashes when the cell has nothing to lift. Here it waits. + Entity_Effect* lifted = room.PickupGridEntity(npc.i2); + if (!lifted) return; + Entity_Projectile* thrown = polty_rock_throw(npc, *lifted, rise, lifted->state); + thrown->pos = cell; + thrown->fallingAccel = POLTY_RISE_FALL; + thrown->fallingSpeed = 0; + thrown->height = POLTY_RISE_HEIGHT; + lifted->Remove(); + thrown->projectileFlags |= PROJECTILE_NO_WALL_COLLIDE; + npc.child = thrown; + if (Entity* beam = kineti_beam_get(npc)) beam->target = thrown; + rock = thrown; + } + } + else if (isReaching) + { + float pull = std::min(vector_length(rock->velocity) * POLTY_PULL_SHARE + POLTY_PULL_MIN, POLTY_PULL_MAX); + rock->velocity = vector_resized(vector_sub(npc.pos, rock->pos), pull); + auto* shot = static_cast(rock); + shot->fallingSpeed = (POLTY_PULL_HEIGHT - shot->height) * POLTY_PULL_LIFT; + if (npc.IsFrame(POLTY_PULL_TINT_EVERY, 0)) + rock->SetColor(POLTY_PULL_COLOR, POLTY_PULL_TINT_FRAMES, COLOR_PRIORITY_DEFAULT, true, true); + if (vector_length_squared(vector_sub(npc.pos, rock->pos)) < POLTY_CATCH_SQUARED) + { + held = kineti_rock_catch(npc, *rock); + return; + } + } + + if (kineti_beam_get(npc)) return; + Vector from = rock ? rock->pos : room.GetGridPosition(npc.i2); + uint32_t seed = Random(); + Entity* beam = g_game->Spawn({.position = from, .spawner = &npc, .type = ENTITY_EFFECT, .variant = EFFECT_KINETI_BEAM, .seed = seed}); + // The original crashes when the beam cannot spawn. Here it goes without. + if (!beam) return; + beam->target = rock; + beam->parent = &npc; + beam->Update(); + npc.entityDeque[0] = beam; +} + +// Its moves: fleeing, hovering short of its aim (throwing when near), or heading for its target cell. +static void polty_move(Entity_NPC& npc, Entity*& held, int state) +{ + Room& room = *g_game->room; + if (npc.i2 == POLTY_FLEEING && npc.controllerID == -1) + { + Vector away = vector_sub(npc.pos, npc.CalcTargetPosition(0)); + if (vector_length(away) > POLTY_MOVE_SPEED) away = vector_scale(vector_normalized(away), POLTY_MOVE_SPEED); + npc.velocity = vector_add(npc.velocity, vector_scale(away, npc.speedMultiplier)); + npc.friction *= POLTY_MOVE_FRICTION; + if (!room.IsPositionInRoom(npc.pos, POLTY_FLEE_OUT)) + { + if (held) + { + held->Remove(); + held = nullptr; + } + npc.Remove(); + } + return; + } + if (npc.i2 < 0 && npc.controllerID != -1) + { + Vector input = npc.GetControllerInput(0); + npc.velocity = vector_add(npc.velocity, vector_scale(input, POLTY_MOVE_SPEED * npc.speedMultiplier)); + npc.friction *= POLTY_MOVE_FRICTION; + if (state != POLTY_THROW && held && npc.IsTargetInAttackRange(POLTY_CONTROLLED_RANGE, 0, true)) + { + npc.UpdateControllerMovement(true); + npc.state = POLTY_THROW; + } + return; + } + if (npc.i2 < 0) + { + Vector aim = npc.CalcTargetPosition(0); + Vector toward = vector_sub(aim, npc.pos); + bool isNear = state != POLTY_THROW && held && (Random() & POLTY_THROW_MASK) == 0 && + vector_distance(aim, vector_add(vector_scale(npc.velocity, POLTY_THROW_LEAD), npc.pos)) <= POLTY_THROW_REACH; + if (isNear) npc.state = POLTY_THROW; + Vector direction = vector_normalized(toward); + Vector step = vector_sub(vector_sub(aim, vector_scale(direction, POLTY_HOVER_SHORT)), npc.pos); + if (vector_length(step) > POLTY_MOVE_SPEED) step = vector_scale(vector_normalized(step), POLTY_MOVE_SPEED); + npc.velocity = vector_add(npc.velocity, vector_scale(step, npc.speedMultiplier)); + npc.friction *= POLTY_MOVE_FRICTION; + return; + } + if (npc.state == POLTY_TELEKINESIS) return; + if (npc.controllerID != -1) + { + Vector input = npc.GetControllerInput(0); + npc.velocity = vector_add(npc.velocity, vector_scale(input, POLTY_MOVE_SPEED * npc.speedMultiplier)); + npc.friction *= POLTY_MOVE_FRICTION; + return; + } + + Vector spot{}; + if (npc.variant == POLTY_KINETI) + { + Entity* target = npc.GetPlayerTarget(); + Vector beyond = vector_add(target->pos, vector_resized(vector_sub(target->pos, room.GetGridPosition(npc.i2)), POLTY_KINETI_SPOT)); + spot = room.GetClampedPosition(beyond, 0); + } + else spot = room.GetGridPosition(npc.i2); + Vector toward = vector_sub(spot, npc.pos); + float distance = vector_length(toward); + Vector step = distance > POLTY_MOVE_SPEED ? vector_scale(vector_normalized(toward), POLTY_MOVE_SPEED) : toward; + if (distance >= POLTY_NEAR) + { + npc.velocity = vector_add(npc.velocity, vector_scale(step, npc.speedMultiplier)); + npc.friction *= POLTY_MOVE_FRICTION; + return; + } + npc.velocity = vector_add(npc.velocity, vector_scale(vector_add(step, step), npc.speedMultiplier)); + npc.friction *= POLTY_NEAR_FRICTION; +} + +// Lifting: on PickupThrow it takes the pickup it came from (out of reach of everything) or lifts its target cell's +// grid entity. Once lifted it holds it, a bomb rock or TNT making it flee. +static void polty_lift(Entity_NPC& npc, Entity*& held, bool isFriendly) +{ + Room& room = *g_game->room; + if (!held && !polty_is_target_liftable(npc)) return polty_idle_restore(npc); + + if (npc.sprite.animState.animData) + { + if (npc.sprite.animState.IsEventTriggered("PickupThrow")) + { + Entity* spawner = npc.spawnerEntity.get(); + if (!spawner || spawner->type != ENTITY_PICKUP) + { + if (held) held->Remove(); + held = room.PickupGridEntity(npc.i2); + if (!held) + { + KAGE_LogMessage(LOG_WARN, (uint8_t*)"polty lost target rock (failed to pick up)\n"); + return polty_idle_restore(npc); + } + held->pos = npc.pos; + held->parent = &npc; + npc.entityRef = held; + } + else + { + spawner->entityCollisionClass = ENTCOLL_NONE; + spawner->pos = npc.pos; + spawner->parent = &npc; + spawner->isVisible = false; + npc.entityRef = spawner; + npc.spawnerEntity = nullptr; + } + } + if (npc.sprite.animState.animData && npc.sprite.animState.isPlaying) return; + } + + npc.state = POLTY_HOLD; + npc.entityCollisionClass = ENTCOLL_ALL; + bool isPrecious = held && held->type == ENTITY_EFFECT && + (static_cast(held)->gridDesc._type == GRID_ROCKT || + static_cast(held)->gridDesc._type == GRID_ROCK_SS); + if (!isPrecious || isFriendly || npc.controllerID != -1) npc.i2 = POLTY_NO_TARGET; + else + { + npc.i2 = POLTY_FLEEING; + npc.entityGridCollisionClass = GRIDCOLL_NONE; + } +} + +// Its death: the pot it hid in breaks, what it held drops, and the Kineti's beam and rock let go. +static void polty_death(Entity_NPC& npc, Entity* held) +{ + Room& room = *g_game->room; + bool isHiding = npc.state == POLTY_LIFT_FIRST || npc.state == POLTY_POT; + if (isHiding && npc.i2 >= 0 && npc.i2 < ROOM_GRID_CELLS) + if (GridEntity* pot = room.gridEntities[npc.i2]) pot->Destroy(false, EntityRef(&npc)); + + if (held && held->type == ENTITY_PICKUP) + { + held->TryThrow(EntityRef(&npc), vector_scale(npc.velocity, POLTY_DROP_SHARE), POLTY_PICKUP_THROW_FORCE); + held->parent = nullptr; + npc.entityRef = nullptr; + } + else if (held) + { + if (held->type == ENTITY_EFFECT) + { + auto& lifted = *static_cast(held); + polty_rock_throw(npc, lifted, vector_scale(npc.velocity, POLTY_DROP_SHARE), lifted.state); + } + held->Remove(); + } + + if (npc.variant != POLTY_KINETI) return; + if (Entity* beam = kineti_beam_get(npc)) beam->Remove(); + if (Entity* rock = npc.child.get(); rock && rock->type == ENTITY_PROJECTILE) + { + auto* shot = static_cast(rock); + shot->projectileFlags &= ~PROJECTILE_NO_WALL_COLLIDE; + shot->fallingAccel = POLTY_DROPPED_FALL; + } +} + +// 0055d230 The Polty and the Kineti (816): they hide (in a pot, or unseen), then pick the best rock, pot, poop or TNT +// to lift, lift it (the Kineti by telekinesis from afar) and throw it at their target, keeping their distance. They +// shrug off other enemies' blasts. +void npc_polty_update(Entity_NPC& npc) +{ + Room& room = *g_game->room; + Entity* held = npc.entityRef.get(); + bool isFriendly = npc.HasEntityFlags(FLAG_FRIENDLY); + int ticks = npc_ticks_get(npc); + if (npc.pendingDamage > 0) + for (DamageEvent& hit : npc.damageEvents) + { + bool isPlayerBlast = hit.source.type == ENTITY_PLAYER || hit.source.spawnerType == ENTITY_PLAYER; + if (!(hit.damageFlags & DAMAGE_EXPLOSION) || isPlayerBlast) continue; + npc.pendingDamage = std::max(npc.pendingDamage - hit.damage, 0.0f); + hit.damage = 0; + hit.damageFlags = 0; + } + if (npc.variant == POLTY_KINETI && npc.entityDeque.empty()) npc.entityDeque.resize(1); + + int state = npc.state; + bool isMoving = true; + switch (state) + { + case NPC_STATE_INIT: + return polty_init(npc); + case POLTY_HIDDEN: + polty_hidden(npc, ticks); + isMoving = false; + break; + case POLTY_IDLE: + polty_idle(npc, isFriendly); + break; + case POLTY_HOLD: + npc.sprite.Play("PickupIdle"); + if (!held) + { + npc.state = POLTY_IDLE; + npc.sprite.Play("Idle"); + npc.entityCollisionClass = ENTCOLL_ALL; + npc.isVisible = true; + return; + } + break; + case POLTY_LIFT_FIRST: + npc.sprite.Play("PickupFirst"); + break; + case POLTY_LIFT: + npc.sprite.Play("Pickup"); + break; + case POLTY_THROW: + polty_throw(npc, held); + break; + case POLTY_TELEKINESIS: + kineti_telekinesis(npc, held, ticks); + break; + case POLTY_POT: + isMoving = false; + if (!polty_is_target_liftable(npc)) + { + npc.state = POLTY_IDLE; + npc.sprite.Play("Idle"); + npc.entityCollisionClass = ENTCOLL_ALL; + npc.isVisible = true; + break; + } + if (npc.controllerID != -1 && !vector_is_zero(npc.GetControllerInput(MOVEMENT_DEADZONE))) npc.stateFrame = 0; + if (npc.stateFrame >= 1) + { + npc.stateFrame -= ticks; + break; + } + npc.isVisible = true; + npc.sprite.Play("PotAppear"); + if (!npc.sprite.animState.animData || !npc.sprite.animState.isPlaying) + { + npc.state = POLTY_LIFT_FIRST; + npc.entityCollisionClass = ENTCOLL_ALL; + } + break; + } + + if (isMoving) + { + polty_move(npc, held, state); + npc.sprite.isFlipX = npc.velocity.x > 0; + if (state == POLTY_LIFT_FIRST || state == POLTY_LIFT) polty_lift(npc, held, isFriendly); + } + + if (npc.i2 >= 0 && npc.i2 < ROOM_GRID_CELLS) room.gridPaths[npc.i2] = 2; + if (npc.isDead) polty_death(npc, held); +} diff --git a/src/npc_poofer.cpp b/src/npc_poofer.cpp index 744ad4b..fa382bb 100644 --- a/src/npc_poofer.cpp +++ b/src/npc_poofer.cpp @@ -56,8 +56,6 @@ constexpr int BURST_DUST_MIN = 5; constexpr int BURST_DUST_RANGE = 5; constexpr float BURST_DUST_SPEED = 10; constexpr float BURST_DUST_SPREAD = 20; -constexpr float BURST_DUST_SPIN_MIN = 2; -constexpr float BURST_DUST_SPIN_RANGE = 10; constexpr int BURST_DUST_LIFE_MIN = 15; constexpr int BURST_DUST_LIFE_RANGE = 15; constexpr float BURST_DUST_ALPHA_MIN = 0.1f; @@ -180,11 +178,11 @@ static void dust_spawn(Entity_NPC& npc) float alpha = color._tint[3]; for (int i = 0; i < count; i++) { - float throwAngle = random_unit() * RANDOM_HALF_TURN * 2; + float throwAngle = random_unit() * PI_ROUGH * 2; float speed = random_unit() * BURST_DUST_SPEED; Vector velocity = vector_make(std::cos(throwAngle) * speed, speed * std::sin(throwAngle)); uint32_t seed = Random(); - float placeAngle = random_unit() * RANDOM_HALF_TURN * 2; + float placeAngle = random_unit() * PI_ROUGH * 2; float reach = random_unit() * BURST_DUST_SPREAD; Vector place = vector_add(npc.pos, vector_make(std::cos(placeAngle) * reach, std::sin(placeAngle) * reach)); auto* dust = static_cast(g_game->Spawn({.position = place, @@ -195,7 +193,7 @@ static void dust_spawn(Entity_NPC& npc) .seed = seed})); Vector out = vector_sub(dust->pos, npc.pos); float spin = -velocity.x * out.y + out.x * velocity.y < 0 ? -1 : 1; - dust->rotation = (random_unit() * BURST_DUST_SPIN_RANGE + BURST_DUST_SPIN_MIN) * spin; + dust->rotation = (random_between(DUST_SPIN_MIN, DUST_SPIN_RANGE)) * spin; int life = (int)(Random() % BURST_DUST_LIFE_RANGE) + BURST_DUST_LIFE_MIN; dust->timeout = life; dust->lifespan = life; diff --git a/src/npc_poop.cpp b/src/npc_poop.cpp index 1522422..b9f53a3 100644 --- a/src/npc_poop.cpp +++ b/src/npc_poop.cpp @@ -19,7 +19,6 @@ constexpr int POOP_STAGE_LAST = 5; constexpr int POOP_STATE_READY = 3; constexpr float POOP_REWARD_SCALE = 250; constexpr float POOP_THROWN_HIT = 15; -constexpr int POOP_THROWN_HIT_COUNTDOWN = 30; constexpr float POOP_THROWN_PUSH = 0.5f; constexpr float POOP_GRAVITY = 2; constexpr float POOP_STONE_GRAVITY = 0.8f; @@ -130,7 +129,7 @@ static void poop_touch(Entity_NPC& npc) npc.Kill(EntityRef()); uint64_t damageFlags = npc.variant == POOP_NPC_STONE ? DAMAGE_CRUSH : 0; Entity* source = npc.spawnerEntity ? npc.spawnerEntity.get() : &npc; - enemy->TakeDamage(POOP_THROWN_HIT, damageFlags, EntityRef(source), POOP_THROWN_HIT_COUNTDOWN); + enemy->TakeDamage(POOP_THROWN_HIT, damageFlags, EntityRef(source), HIT_COUNTDOWN); npc.collisionResult = 0; enemy->velocity = vector_add(enemy->velocity, vector_scale(npc.velocity, POOP_THROWN_PUSH)); } @@ -349,6 +348,9 @@ static bool poop_hits_update(Entity_NPC& npc, bool& isGone) return isChanged; } +// A controlled pile loses a fifth of its push each frame of sliding. +constexpr float POOP_CONTROL_SLIDE = 0.2f; + // A pile's first frame: its flags and AI calls, its sheet and side, a burning pile's fire following it. static void poop_init(Entity_NPC& npc) { @@ -398,6 +400,26 @@ static void poop_stage_show(Entity_NPC& npc, bool isJustMade) npc.renderZOffset = POOP_BROKEN_DEPTH; } +// A controlled pile slides along its controller's walking input, less the more it slid (v2.x builds by a fifth of its +// speed multiplier over v1.x, up to 1), and resets when let go. +static void poop_control_update(Entity_NPC& npc) +{ + Vector input = npc.GetControllerInput(MOVEMENT_DEADZONE); + if (vector_is_zero(input)) + { + npc.v2.x = 0; + return; + } + + float share = std::max(1 - npc.v2.x, 0.0f); + if (npc.friction != 0) + { + npc.velocity.y += npc.speedMultiplier * input.y * share / npc.friction; + npc.velocity.x += npc.speedMultiplier * input.x * share / npc.friction; + } + npc.v2.x = std::min(npc.speedMultiplier * POOP_CONTROL_SLIDE + npc.v1.x, 1.0f); +} + // The main frame: Midas's touch gilds a plain pile, a resting pile slides to a stop, corny piles keep their flies, a // pile led to a spot marks its path there, and its hits break it stage by stage. static void poop_frame(Entity_NPC& npc) @@ -429,8 +451,7 @@ static void poop_frame(Entity_NPC& npc) room.gridPaths[cell] += POOP_GRID_PATH - room.gridPaths[cell] % POOP_GRID_PATH_MOD; npc.velocity = vector_sub(npc.targetPosition, npc.pos); } - if (!npc.isDead && npc.health > 1 && npc.controllerID != -1) - reconstruction_missing("NpcAI::ENTITY_POOP 00571280 (a controlled poop)"); + if (!npc.isDead && npc.health > 1 && npc.controllerID != -1) poop_control_update(npc); bool isGone = false; if (poop_hits_update(npc, isGone)) isChanged = true; diff --git a/src/npc_pustule.cpp b/src/npc_pustule.cpp index 99e012f..71ab81c 100644 --- a/src/npc_pustule.cpp +++ b/src/npc_pustule.cpp @@ -87,7 +87,7 @@ static bool pustule_maggot_spawn(Entity_NPC& npc) if (entity_query(ENTITY_SMALL_MAGGOT, -1).size() >= PUSTULE_MAGGOT_CAP) return false; Room& room = *g_game->room; - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float reach = random_unit(); Vector spot = vector_make(std::cos(angle) * reach * PUSTULE_MAGGOT_REACH + npc.pos.x, diff --git a/src/npc_render_parts.cpp b/src/npc_render_parts.cpp index 54481d9..a76e8c6 100644 --- a/src/npc_render_parts.cpp +++ b/src/npc_render_parts.cpp @@ -3,9 +3,8 @@ #include "beam_renderer.h" #include "game.h" -// Evis' cord layer, the Scourge's chain links and the Chimera's body, as their renders know them. +// Evis' cord layer and the Chimera's body, as their renders know them. constexpr int EVIS_CORD_LAYER = 1; -constexpr int SCOURGE_LINK_SHOWN = NPC_STATE_JUMP; constexpr int CHIMERA_BODY_LAYER = 2; constexpr int CHIMERA_SPLIT = NPC_STATE_SPECIAL; @@ -56,21 +55,6 @@ void evis_render(Entity_NPC& npc, const Vector& offset) npc.sprite.RenderLayer(EVIS_CORD_LAYER, SpriteDraw{vector_add(anchor, offset), {}, {}}); } -// 00589de0 A link of the Scourge's chain: the first draws the whole chain, the others draw themselves unflipped only -// while thrown. -void scourge_chain_render(Entity_NPC& npc, const Vector& offset) -{ - Entity* parent = npc.parent.get(); - bool isFirstLink = !parent || parent->type != ENTITY_SCOURGE || parent->variant != SCOURGE_CHAIN; - if (isFirstLink) return reconstruction_missing("NpcHelper::scourge_chain_render 005832c0"); - if (npc.state != SCOURGE_LINK_SHOWN) return; - - bool isFlipX = npc.sprite.isFlipX; - npc.sprite.isFlipX = false; - npc.Entity::Render(offset); - npc.sprite.isFlipX = isFlipX; -} - // 004a1000 Once split, the Chimera's body draws its hidden head where its own third layer shows, flipped with it. void chimera_child_render(Entity_NPC& npc, const Vector& offset) { diff --git a/src/npc_rock_spider.cpp b/src/npc_rock_spider.cpp index 18fdf5c..675379a 100644 --- a/src/npc_rock_spider.cpp +++ b/src/npc_rock_spider.cpp @@ -260,7 +260,7 @@ static void coal_sparks(Entity_NPC& npc) float rise = random_unit() * SPARK_RISE; float drift = (random_unit() - 0.5f) * SPARK_DRIFT; - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float reach = random_unit(); Vector position = vector_make(std::cos(angle) * reach * SPARK_SPREAD + npc.pos.x, diff --git a/src/npc_rotten_gaper.cpp b/src/npc_rotten_gaper.cpp index 126ba5a..a6504c9 100644 --- a/src/npc_rotten_gaper.cpp +++ b/src/npc_rotten_gaper.cpp @@ -56,7 +56,7 @@ constexpr int MOTHER_GAPER_SHOTS = 4; constexpr float MOTHER_GAPER_SHOT_TRAJECTORY = 10; constexpr float MOTHER_GAPER_SHOT_SPEED = 0.4f; constexpr float MOTHER_GAPER_LOB_SPREAD = 40; -constexpr float MOTHER_GAPER_LOB_TURN = 3.14f * 2; +constexpr float MOTHER_GAPER_LOB_TURN = PI_ROUGH * 2; constexpr float MOTHER_GAPER_LOB_FALL = -0.06f; constexpr float MOTHER_GAPER_LOB_PACE = 0.05f; constexpr float MOTHER_GAPER_LOB_SPEED = 25; diff --git a/src/npc_round_worm.cpp b/src/npc_round_worm.cpp index 8576dbf..db803b8 100644 --- a/src/npc_round_worm.cpp +++ b/src/npc_round_worm.cpp @@ -129,7 +129,7 @@ static Vector round_worm_free_spot(const Vector& position) // A spot nudged up to 15 in a random direction. static Vector round_worm_jitter(const Vector& position) { - float angle = random_unit() * RANDOM_HALF_TURN * 2; + float angle = random_unit() * PI_ROUGH * 2; float reach = random_unit() * ROUND_WORM_JITTER; return vector_add(position, vector_scale(vector_make(std::cos(angle), std::sin(angle)), reach)); } @@ -137,7 +137,7 @@ static Vector round_worm_jitter(const Vector& position) // A spot a random reach (min, plus up to range) in a random direction from a center, kept a margin in the room. static Vector round_worm_spot_around(const Vector& center, float min, float range, float margin) { - float angle = random_unit() * RANDOM_HALF_TURN * 2; + float angle = random_unit() * PI_ROUGH * 2; float reach = random_unit() * range + min; Vector spot = vector_add(center, vector_scale(vector_make(std::cos(angle), std::sin(angle)), reach)); return g_game->room->GetClampedPosition(spot, margin); diff --git a/src/npc_small_maggot.cpp b/src/npc_small_maggot.cpp index b954047..c1736ae 100644 --- a/src/npc_small_maggot.cpp +++ b/src/npc_small_maggot.cpp @@ -75,7 +75,7 @@ static void small_maggot_init(Entity_NPC& npc) npc.state = NPC_STATE_IDLE; RNG rng = CLUSTER_RNG_SHIFTS; rng._seed = Random(); - float angle = (float)rng._seed * RANDOM_UNIT_SCALE * RANDOM_HALF_TURN * 2; + float angle = (float)rng._seed * RANDOM_UNIT_SCALE * PI_ROUGH * 2; npc.pathfinder.movementTarget = vector_make(std::cos(angle), std::sin(angle)); npc.pathfinder.moveCountdown = (int)(rng.Next() % CRAWL_FRAMES) + CRAWL_MIN; } diff --git a/src/npc_spider.cpp b/src/npc_spider.cpp index 500f2b9..27fa996 100644 --- a/src/npc_spider.cpp +++ b/src/npc_spider.cpp @@ -8,6 +8,7 @@ #include "data.h" #include "entity_config.h" #include "manager.h" +#include "menu_manager.h" #include // A spider rests 14 frames, then runs at its target (leading it) when near and in sight, else somewhere at random @@ -28,6 +29,10 @@ constexpr int WANDER_RETRY_ODDS = 20; constexpr float WANDER_PROBE_NEAR = 0.1f; constexpr float WANDER_PROBE_FAR = 0.9f; constexpr int JUMP_ODDS = 3; +// A controlled spider: the reach of the jumping kinds' aim target, and the frames it runs on a walking input. +constexpr float CONTROL_AIM_RANGE = 110; +constexpr int CONTROL_RUN_FRAMES = 8; +constexpr float CONTROL_PATH_SPEED_SCALE = 0.8f; // How it runs: at 6 (the Migraine spider 4.5), stopping at its spot or once stuck. constexpr float RUN_SPEED = 6; @@ -120,8 +125,23 @@ static void spider_rest_update(Entity_NPC& npc, bool isPassive, const Vector& ai if (rested <= REST_FRAMES) return; Vector spot; - spider_spot_pick(npc, isPassive, aim, spot); - if (!is_jumper(npc.type) || Random() % JUMP_ODDS != 0 || room_grid_collision_at(spot) != 0) return; + if (npc.controllerID != -1) + { + spot = npc.GetAimTargetPosition(); + bool isLeaping = is_jumper(npc.type) && npc.is_controller_input_idle() && room_grid_collision_at(spot) == 0; + if (!isLeaping) + { + if (vector_is_zero(npc.GetControllerInput(MOVEMENT_DEADZONE))) return; + npc.targetPosition = npc.pos; + npc.stateFrame = CONTROL_RUN_FRAMES; + return; + } + } + else + { + spider_spot_pick(npc, isPassive, aim, spot); + if (!is_jumper(npc.type) || Random() % JUMP_ODDS != 0 || room_grid_collision_at(spot) != 0) return; + } npc.targetPosition = spot; npc.state = NPC_STATE_JUMP; @@ -132,7 +152,8 @@ static void spider_rest_update(Entity_NPC& npc, bool isPassive, const Vector& ai } } -// Running to its spot, walking, until it gets there or gets stuck. +// Running to its spot, walking, until it gets there or gets stuck. A controlled one runs along its path while its +// walking input lasts. static void spider_run_update(Entity_NPC& npc) { npc.stateFrame -= npc_ticks_get(npc); @@ -145,6 +166,18 @@ static void spider_run_update(Entity_NPC& npc) } float speed = npc.type == ENTITY_MIGRAINE_SPIDER ? MIGRAINE_RUN_SPEED : RUN_SPEED; + if (npc.controllerID != -1) + { + npc.pathfinder.FindGridPath({}, speed * CONTROL_PATH_SPEED_SCALE, 0, DIRECT_PATH_FAR); + npc.targetPosition = npc.pos; + if (npc.stateFrame < 0 || vector_is_zero(npc.GetControllerInput(MOVEMENT_DEADZONE))) + { + npc.targetPosition = {}; + npc.stateFrame = 0; + } + npc.sprite.isFlipX = npc.velocity.x < 0; + return; + } Vector toward = vector_sub(npc.targetPosition, npc.pos); bool isStuck = vector_length(npc.velocity) < RUN_STUCK_SPEED && npc.stateFrame < 0; if (vector_length(toward) < RUN_ARRIVED || isStuck) @@ -326,11 +359,14 @@ void npc_spider_update(Entity_NPC& npc) npc.stateFrame = 0; return; } - if (npc.controllerID != -1) reconstruction_missing("NpcAI::ENTITY_SPIDER 00529da0: a spider under a player's control"); Room& room = *g_game->room; - npc.pos = room.GetClampedPositionImpl(npc.pos, CLAMP_TOP, 0, CLAMP_BOTTOM, 0); + bool isControlled = npc.controllerID != -1; + if (!npc.HasEntityFlags(FLAG_FRIENDLY) || !isControlled) + npc.pos = room.GetClampedPositionImpl(npc.pos, CLAMP_TOP, 0, CLAMP_BOTTOM, 0); npc.entityCollisionClass = npc.state == NPC_STATE_JUMP ? ENTCOLL_NONE : ENTCOLL_ALL; + bool isBomb = npc.type == ENTITY_TICKING_SPIDER || npc.type == ENTITY_MIGRAINE_SPIDER; + if (isBomb && isControlled && npc.IsControllerActionPressed(ACTION_ITEM)) npc.Kill(EntityRef()); if (npc.state == NPC_STATE_JUMP) { @@ -343,6 +379,7 @@ void npc_spider_update(Entity_NPC& npc) else if (npc.state == NPC_STATE_MOVE) { Vector aim = npc.CalcTargetPosition(TARGET_DISTANCE); + if (is_jumper(npc.type)) npc.SpawnControlTarget(CONTROL_INPUT_SHOOT, CONTROL_AIM_RANGE); if (vector_is_zero(npc.targetPosition)) spider_rest_update(npc, isPassive, aim); else spider_run_update(npc); } diff --git a/src/npc_stonehead.cpp b/src/npc_stonehead.cpp index b3b605c..d7cbd2a 100644 --- a/src/npc_stonehead.cpp +++ b/src/npc_stonehead.cpp @@ -2,11 +2,13 @@ #include "entity_projectile.h" #include "entity_laser.h" #include "entity_player.h" +#include "menu_manager.h" #include "npc_caves.h" #include "room_descriptor.h" #include "sfx_manager.h" #include #include +#include // The Stone Grimace's vomiting and triple variants. constexpr int GRIMACE_VOMIT = 1; @@ -54,6 +56,16 @@ constexpr float VOMIT_SPEED_SCALE = 0.55f; constexpr float VOMIT_SCALE = 1.6f; constexpr float VOMIT_FALL_SPEED = -30.5f; constexpr float VOMIT_FALL_ACCEL = 0.92f; +// A controlled vomiting grimace lobs its blob to land on its aim target: the frames the flight takes at 10 times its +// speed share, the drag those frames add up to (at least 0.01), and the fall from 5 up clamped between -38 and -5. +constexpr float VOMIT_LOB_STEP = 10; +constexpr double VOMIT_LOB_DECAY = 0.9; +constexpr float VOMIT_LOB_SPAN = -9.491221f; +constexpr float VOMIT_LOB_FLOOR = 0.01f; +constexpr float VOMIT_LOB_LIFT = 5; +constexpr float VOMIT_LOB_GRAVITY = 10.2f; +constexpr float VOMIT_LOB_FASTEST = -38; +constexpr float VOMIT_LOB_SLOWEST = -5; // The grey a face splats, and the vomit's green. constexpr ColorMod STONEHEAD_SPLAT_COLOR = {{1, 1, 1, 1}, {1, 1, 1, 1}, {0, 0, 0}}; constexpr std::array VOMIT_COLORIZE = {0.4f, 2, 0.5f, 1}; @@ -223,22 +235,37 @@ static void grimace_shoot(Entity_NPC& npc) params.fallingSpeedModifier = VOMIT_FALL_SPEED; params.fallingAccelModifier = VOMIT_FALL_ACCEL; std::copy(VOMIT_COLORIZE.begin(), VOMIT_COLORIZE.end(), params.color._colorize); - if (npc.controllerID != -1) reconstruction_missing("NpcAI::ENTITY_STONEHEAD 00520c60: a controlled vomit's aim"); + if (npc.controllerID != -1) + { + float frames = vector_length(vector_sub(npc.pos, npc.GetAimTargetPosition())) / (params.velocityMulti * VOMIT_LOB_STEP); + float drag = std::max(((float)std::pow(VOMIT_LOB_DECAY, (double)frames) - 1) * VOMIT_LOB_SPAN, VOMIT_LOB_FLOOR); + float fall = (VOMIT_LOB_LIFT - (frames - drag) * VOMIT_LOB_GRAVITY) / drag; + params.fallingSpeedModifier = std::min(std::max(fall, VOMIT_LOB_FASTEST), VOMIT_LOB_SLOWEST); + } } - if (npc.controllerID != -1) reconstruction_missing("NpcAI::ENTITY_STONEHEAD 00520c60: a controlled grimace's aim"); Vector aim = vector_sub(npc.GetPlayerTarget()->pos, npc.pos); + if (npc.controllerID != -1 && !vector_equal(npc.GetAimTargetPosition(), npc.pos)) + aim = vector_sub(npc.GetAimTargetPosition(), npc.pos); float speed = game_is_hard_mode() ? GRIMACE_SHOT_SPEED_HARD : GRIMACE_SHOT_SPEED; ProjectilesMode mode = npc.variant == GRIMACE_TRIPLE ? PROJECTILES_THREE_WIDE : PROJECTILES_SINGLE; npc.FireProjectiles(npc.pos, vector_resized(aim, speed), mode, params); } -// A Stone Grimace shoots a target in range when its cooldown is out. +// Whether a Stone Grimace shoots: at a target in range, or for a controlled one on its controller's item button with +// an aim target. +static bool is_grimace_shooting(Entity_NPC& npc) +{ + if (npc.controllerID == -1) return npc.IsTargetInAttackRange(GRIMACE_RANGE, 0, true); + return npc.IsControllerActionPressed(ACTION_ITEM) && !vector_is_zero(npc.GetAimTargetPosition()); +} + +// A Stone Grimace shoots when its cooldown is out, a controlled one showing its aim target. static void grimace_update(Entity_NPC& npc) { if (npc.projectileCooldown > 0) npc.projectileCooldown -= npc_ticks_get(npc); - if (npc.controllerID != -1) reconstruction_missing("NpcAI::ENTITY_STONEHEAD 00520c60: Entity_NPC::SpawnControlTarget"); - if (npc.projectileCooldown < 1 && npc.IsTargetInAttackRange(GRIMACE_RANGE, 0, true)) + npc.SpawnControlTarget(CONTROL_INPUT_SHOOT, -1); + if (npc.projectileCooldown < 1 && is_grimace_shooting(npc)) { npc.projectileCooldown = GRIMACE_COOLDOWN; npc_anim_restart(npc.sprite, "Shoot"); diff --git a/src/npc_sub_horf.cpp b/src/npc_sub_horf.cpp index 9bc67bf..8c22f76 100644 --- a/src/npc_sub_horf.cpp +++ b/src/npc_sub_horf.cpp @@ -59,7 +59,7 @@ static void sub_horf_knockback(Entity_NPC& npc) npc.velocity = vector_normalized(vector_sub(npc.pos, npc.damageEvents.back().source.position)); if (vector_length_squared(npc.velocity) < SUB_HORF_STILL_SQUARED) { - float angle = random_unit() * RANDOM_HALF_TURN * 2; + float angle = random_unit() * PI_ROUGH * 2; npc.velocity = vector_make(std::cos(angle), std::sin(angle)); } float speed = vector_length(npc.velocity); diff --git a/src/npc_swarm.cpp b/src/npc_swarm.cpp index ed9639c..f031f44 100644 --- a/src/npc_swarm.cpp +++ b/src/npc_swarm.cpp @@ -95,7 +95,7 @@ void npc_swarm_update(Entity_NPC& npc) for (int i = 0; i < SWARM_FLY_COUNT && !npc.parent; i++) { uint32_t seed = npc.dropRNG.Next(); - float angle = random_unit() * RANDOM_HALF_TURN * 2; + float angle = random_unit() * PI_ROUGH * 2; Vector spot = vector_make(std::cos(angle) * SWARM_SPREAD + npc.pos.x, std::sin(angle) * SWARM_SPREAD + npc.pos.y); Entity* fly = g_game->Spawn({.position = spot, diff --git a/src/npc_swarmer.cpp b/src/npc_swarmer.cpp index 4e45edd..0a5d13d 100644 --- a/src/npc_swarmer.cpp +++ b/src/npc_swarmer.cpp @@ -38,8 +38,6 @@ constexpr float SWARMER_DUST_HEIGHT = -34; constexpr float SWARMER_DUST_SPREAD = 40; constexpr float SWARMER_DUST_SPEED_MIN = 3; constexpr float SWARMER_DUST_SPEED_RANGE = 3; -constexpr float SWARMER_DUST_SPIN_MIN = 2; -constexpr float SWARMER_DUST_SPIN_RANGE = 10; constexpr int SWARMER_DUST_LIFE_MIN = 15; constexpr uint32_t SWARMER_DUST_LIFE_RANGE = 15; constexpr float SWARMER_DUST_ALPHA_MIN = 0.2f; @@ -173,7 +171,7 @@ static void swarmer_spit(Entity_NPC& npc, Vector aim) .variant = EFFECT_DUST_CLOUD, .seed = Random()})); float spin = vector_dot(vector_sub(dust->pos, npc.pos), vector_make(velocity.y, -velocity.x)) < 0 ? -1.0f : 1.0f; - dust->rotation = (random_unit() * SWARMER_DUST_SPIN_RANGE + SWARMER_DUST_SPIN_MIN) * spin; + dust->rotation = (random_between(DUST_SPIN_MIN, DUST_SPIN_RANGE)) * spin; dust->timeout = (int)(Random() % SWARMER_DUST_LIFE_RANGE) + SWARMER_DUST_LIFE_MIN; dust->lifespan = dust->timeout; ColorMod dustColor = COLOR_DEFAULT; diff --git a/src/npc_swinger.cpp b/src/npc_swinger.cpp index 05c0669..a6357c1 100644 --- a/src/npc_swinger.cpp +++ b/src/npc_swinger.cpp @@ -24,7 +24,6 @@ constexpr float SWINGER_PAYOUT_FRAMES = 60; constexpr float SWINGER_SWING_LIMIT = 0.5f; constexpr float SWINGER_SWING_STEP = 0.05f; constexpr float SWINGER_TURN_FRAMES = 50; -constexpr float SWINGER_FULL_TURN = 6.2831855f; constexpr float SWINGER_CORD_SAG = 10; constexpr float SWINGER_CORD_DROP = 7; @@ -104,7 +103,7 @@ static void swinger_head_update(Entity_NPC& npc) if (std::abs(npc.v2.x - swing) > step) swing = swing <= npc.v2.x ? npc.v2.x - step : step + npc.v2.x; npc.v2.x = swing; npc.v1.x = (swing + 1) * npc.speedMultiplier * PI_F / SWINGER_TURN_FRAMES + npc.v1.x; - while (npc.v1.x > SWINGER_FULL_TURN) npc.v1.x -= SWINGER_FULL_TURN; + while (npc.v1.x > TAU) npc.v1.x -= TAU; if (!npc.HasEntityFlags(FLAG_CONFUSION)) return; body->AddEntityFlags(FLAG_CONFUSION); diff --git a/src/npc_ultra_greed.cpp b/src/npc_ultra_greed.cpp index e5ccd94..fdbd17d 100644 --- a/src/npc_ultra_greed.cpp +++ b/src/npc_ultra_greed.cpp @@ -217,7 +217,6 @@ constexpr float SPIN_KNOCK_DEGREES = 70; constexpr float SPIN_KNOCK = 5; constexpr float SPIN_DAMAGE = 2; constexpr float SPIN_ENEMY_DAMAGE = 30; -constexpr int SPIN_HIT_COUNTDOWN = 30; constexpr float SPIN_SOUND_FADE = 0.15f; // The stomps: faster with rage, shaking the room and, on each foot, a Keeper (up to four) or Greedier's two bomb @@ -686,7 +685,7 @@ static void ultra_greed_spin_hit(Entity_NPC& npc) if (vector_length(knock) > 0) knock = vector_resized(knock, SPIN_KNOCK); if (entity->friction != 0) entity->AddVelocity_divided(knock, false); float damage = isVersusPlayer || isEnemy ? SPIN_ENEMY_DAMAGE : SPIN_DAMAGE; - entity->TakeDamage(damage, DAMAGE_COUNTDOWN, EntityRef(&npc), SPIN_HIT_COUNTDOWN); + entity->TakeDamage(damage, DAMAGE_COUNTDOWN, EntityRef(&npc), HIT_COUNTDOWN); } g_manager->sfxManager.SetAmbientSound(SOUND_ULTRA_GREED_SPINNING, 1, 1); } @@ -784,7 +783,7 @@ static Entity_NPC* ultra_coin_throw(Entity_NPC& npc, int variant) Room& room = *g_game->room; Vector spot = room_free_pickup_position_find({.position = room.GetRandomPosition(0)}); uint32_t seed = Random(); - float angle = random_unit() * RANDOM_HALF_TURN * 2; + float angle = random_unit() * PI_ROUGH * 2; return dynamic_cast(g_game->Spawn({.position = spot, .velocity = vector_make(std::cos(angle), std::sin(angle)), @@ -931,7 +930,7 @@ static void ultra_greed_turn_gold(Entity_NPC& npc) npc.shadowSize = 0; for (int i = 0; i < TURN_GOLD_BURSTS; i++) { - float angle = random_unit() * RANDOM_HALF_TURN * 2; + float angle = random_unit() * PI_ROUGH * 2; float reach = random_unit(); Vector spot = vector_make(npc.size * std::cos(angle) * reach * TURN_GOLD_REACH + npc.pos.x, npc.size * reach * std::sin(angle) * TURN_GOLD_REACH + npc.pos.y); @@ -1333,7 +1332,7 @@ static int ultra_greed_dash(Entity_NPC& npc, int next) uint32_t seed = Random(); Vector back = vector_scale(vector_length(npc.velocity) > 0 ? vector_normalized(npc.velocity) : npc.velocity, DASH_DUST_BACK); - float angle = random_unit() * RANDOM_HALF_TURN * 2; + float angle = random_unit() * PI_ROUGH * 2; float spread = random_unit(); Vector velocity = vector_add(vector_make(std::cos(angle) * spread, std::sin(angle) * spread), back); Entity* dust = g_game->Spawn({.position = npc.pos, @@ -1515,7 +1514,7 @@ static void ultra_greed_rocks_crush(Entity_NPC& npc) static void ultra_greed_footfall(Entity_NPC& npc, const NullFrame& foot) { Vector offset = vector_make(foot.pos.x * (npc.sprite.isFlipX ? -1.0f : 1.0f), foot.pos.y); - float angle = random_unit() * RANDOM_HALF_TURN * 2; + float angle = random_unit() * PI_ROUGH * 2; float reach = random_unit(); Vector scatter = vector_make(std::cos(angle) * reach * FOOT_SCATTER + offset.x / FOOT_SCALE, reach * std::sin(angle) * FOOT_SCATTER + offset.y / FOOT_SCALE); @@ -1531,7 +1530,7 @@ static void ultra_greed_footfall(Entity_NPC& npc, const NullFrame& foot) .variant = EFFECT_GOLD_PARTICLE}); for (int i = 0; i < FOOT_PUFFS; i++) { - float puffAngle = random_unit() * RANDOM_HALF_TURN * 2; + float puffAngle = random_unit() * PI_ROUGH * 2; float puffReach = random_unit(); float kickX = std::cos(puffAngle) * puffReach * FOOT_PUFF_SPEED; float kickY = std::abs(puffReach * std::sin(puffAngle) * FOOT_PUFF_SPEED); @@ -1551,7 +1550,7 @@ static void ultra_greed_footfall(Entity_NPC& npc, const NullFrame& foot) uint32_t seed = Random(); Vector base = vector_make(npc.velocity.x, npc.velocity.y + FOOT_ROCK_LIFT); - float rockAngle = random_unit() * RANDOM_HALF_TURN * 2; + float rockAngle = random_unit() * PI_ROUGH * 2; Entity* rock = g_game->Spawn({.position = vector_add(scatter, npc.pos), .velocity = vector_make(std::cos(rockAngle) + base.x, std::sin(rockAngle) + base.y), .type = ENTITY_EFFECT, diff --git a/src/npc_vis_fatty.cpp b/src/npc_vis_fatty.cpp index f47ed9b..24ebcdf 100644 --- a/src/npc_vis_fatty.cpp +++ b/src/npc_vis_fatty.cpp @@ -129,7 +129,6 @@ constexpr float PULSE_BLOOD_DEPTH = 60; // Its rage without its demon: it charges along a diagonal away from its target, breathing a laser behind it and // sparks, bouncing off walls, healed a quarter. constexpr float RAGE_VOLUME = 0.8f; -constexpr float RAGE_DIAGONAL = 0.70710677f; constexpr ColorMod VIS_RAGE_TRACER_COLOR = tint_color_make(0.6f, 0.05f, 0, 0.8f); constexpr float RAGE_TRACER_RISE = -20; constexpr int RAGE_TRACER_FRAMES = 30; @@ -266,8 +265,8 @@ static void vis_fatty_rage_start(Entity_NPC& npc) npc.PlaySound(SOUND_MOUTH_FULL, RAGE_VOLUME, 2, false, 1); npc.sprite.Play("RageStart"); Entity* target = npc.GetPlayerTarget(); - npc.targetPosition = vector_make(target->pos.x - npc.pos.x > 0 ? -RAGE_DIAGONAL : RAGE_DIAGONAL, - target->pos.y - npc.pos.y > 0 ? -RAGE_DIAGONAL : RAGE_DIAGONAL); + npc.targetPosition = vector_make(target->pos.x - npc.pos.x > 0 ? -DIAGONAL : DIAGONAL, + target->pos.y - npc.pos.y > 0 ? -DIAGONAL : DIAGONAL); float behind = vector_angle(npc.targetPosition) + DEGREES_PER_TURN / 2; following_effect_spawn(npc, {.offset = vector_make(0, RAGE_TRACER_RISE), .targetPosition = vector_from_angle(behind), diff --git a/src/path_finder.cpp b/src/path_finder.cpp index c631ed2..9e03f23 100644 --- a/src/path_finder.cpp +++ b/src/path_finder.cpp @@ -434,7 +434,7 @@ static void evade_spot_try(PathFinder& finder, const Vector& targetPos, const Ve Entity* entity = finder.entity; Room& room = *g_game->room; float reach = random_unit() * EVADE_REACH_RANGE + EVADE_REACH_MIN; - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; Vector spot = vector_make(std::cos(angle) * reach + base.x, std::sin(angle) * EVADE_FLATTEN * reach + base.y); int column = (int)((spot.x - GRID_CELL_SIZE) / GRID_CELL_SIZE + 0.5f); @@ -550,7 +550,7 @@ bool PathFinder::MoveRandomly(StatusMode mode) if (vector_is_zero(movementTarget)) { - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; Vector spot = vector_make(std::cos(angle) * WANDER_STEP + entity->pos.x, std::sin(angle) * WANDER_STEP + entity->pos.y); diff --git a/src/pause_screen.cpp b/src/pause_screen.cpp index 7742a7e..18c5d10 100644 --- a/src/pause_screen.cpp +++ b/src/pause_screen.cpp @@ -100,7 +100,6 @@ 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 uint32_t PAPER_TEXT_ARGB = 0xff362f2d; constexpr float SOUND_VOLUME = 0.7f; constexpr float FADE_SPEED = 0.08f; constexpr int FADE_TARGET_MENU = 2; @@ -643,7 +642,7 @@ void PauseScreen_MyStuff::section_cursor_render(Vector position) // The original draws an unidentified pill's text in no set color. Here it is the page's ink. bool PauseScreen_MyStuff::title_text_render(InfoDisplayEntry& entry, Vector at) { - KColor ink = kcolor_argb(PAPER_TEXT_ARGB); + KColor ink = kcolor_argb(TEXT_ARGB); bool isPill = entry.type == INFO_DISPLAY_PILL; if (entry.isUnidentified) { @@ -704,7 +703,7 @@ void PauseScreen_MyStuff::description_render(InfoDisplayEntry& entry, Vector pos const DescriptionScroll& scroll) { Entity_Player& paused = *g_game->GetPlayer(g_game->pauseScreen.playerIdx); - KColor ink = kcolor_argb(PAPER_TEXT_ARGB); + KColor ink = kcolor_argb(TEXT_ARGB); KColor highlight = kcolor_argb(ITEM_INFO_FORM_ARGB); Vector at = position; int line = 0; @@ -1092,6 +1091,6 @@ void PauseScreen::render_seed_paper(Vector position) 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); + font.DrawString(first, firstLine, vector_make(1, 1), kcolor_argb(TEXT_ARGB), settings); + font.DrawString(second, secondLine, vector_make(1, 1), kcolor_argb(TEXT_ARGB), settings); } diff --git a/src/persistent_game_data.cpp b/src/persistent_game_data.cpp index a6657dc..b499c55 100644 --- a/src/persistent_game_data.cpp +++ b/src/persistent_game_data.cpp @@ -78,7 +78,7 @@ enum ChunkCount CHUNK_COUNT_CLAMPED }; -// How the logs name a chunk: as its title, and in the count mismatch warning. +// How the logs name a chunk: as its title (none for an Afterbirth save), and in the count mismatch warning. struct ChunkName { const char* title; @@ -294,7 +294,7 @@ static void chunk_read(SaveReader& reader, uint32_t chunkSize, Entries& entries, uint32_t count = 0; Filed value = 0; - log_printf(LOG_INFO, "Reading %s\n", name.title); + if (name.title) log_printf(LOG_INFO, "Reading %s\n", name.title); reader.read(count); if (count != entries.size()) log_printf(LOG_WARN, "Different number of %s %d/%d\n", name.noun, (int)count, (int)entries.size()); @@ -309,7 +309,7 @@ static void chunk_read(SaveReader& reader, uint32_t chunkSize, Entries& entries, else entries[index] = value; } - log_printf(LOG_INFO, "Done Reading %s\n", name.title); + if (name.title) log_printf(LOG_INFO, "Done Reading %s\n", name.title); } // Loads a whole file, false when it cannot be opened. @@ -525,7 +525,7 @@ bool PersistentGameData::Load(std::string_view path) return false; } -// (0092c7e0, 0092c550, 0092c2c0, 0092b2e0, 0092b930) Imports an earlier game's save, found by swapping its folder +// (0092c7e0, 0092c550, 0092c2c0, 0092b2e0) Imports an earlier game's save, found by swapping its folder // into the save path (and dropping a "rep+" prefix for Rebirth), false when there is none. bool PersistentGameData::TryImportLocalSave(std::string_view path, const SaveImport& import) { @@ -546,14 +546,292 @@ bool PersistentGameData::TryImportLocalSave(std::string_view path, const SaveImp if (import.name) log_printf(LOG_INFO, "No %s save found! (%s)\n", import.name, importPath.c_str()); return false; } - if (import.format == SAVE_FORMAT_AFTERBIRTH) - reconstruction_missing("PersistentGameData::import_afterbirth_save 0092b930"); - if (import.format == SAVE_FORMAT_REBIRTH) reconstruction_missing("RebirthSaveData load 009e4260"); - - isFileLoaded = read(file); + if (import.format == SAVE_FORMAT_AFTERBIRTH) isFileLoaded = import_afterbirth_save(file); + else if (import.format == SAVE_FORMAT_REBIRTH) isFileLoaded = import_rebirth_save(file); + else isFileLoaded = read(file); return isFileLoaded; } +// An Afterbirth or Afterbirth+ save (versions 6 to 8), as AfterbirthPersistentGameData reads it: Repentance's chunks +// at Afterbirth+'s sizes. Version 6 has no special seeds, and only version 8's checksum is checked. The trailing save +// count is never used. +struct AfterbirthSave +{ + std::array achievements{}; + std::array bosses{}; + std::array challenges{}; + std::array collectibles{}; + std::array minibosses{}; + std::array specialSeeds{}; + std::array counters{}; + std::array cutscenes{}; + std::array levelCounters{}; + std::array settings{}; + uint32_t gameStateChecksum = 0; +}; +constexpr int AFTERBIRTH_VERSION_FIRST = 6; +constexpr int AFTERBIRTH_VERSION_CHECKED = 8; +constexpr std::array AFTERBIRTH_HEADERS = {"ISAACNGSAVE06R ", "ISAACNGSAVE07R ", + "ISAACNGSAVE08R "}; +// The counters Repentance added among Afterbirth+'s, which an imported counter's index moves past. +constexpr std::array AFTERBIRTH_SKIPPED_COUNTERS = {4, 40, 54, 68, 82, 96, 110, 129, 143, 157}; + +// 0041d670 (AfterbirthPersistentGameData::check_header) Reads an Afterbirth save, false for a wrong header or a bad +// version 8 checksum. Every chunk keeps at most the entries Afterbirth+ had. +static bool afterbirth_read(std::span file, AfterbirthSave& save) +{ + std::string_view header((const char*)file.data(), std::min(file.size(), SAVE_HEADER_SIZE)); + auto version = std::ranges::find(AFTERBIRTH_HEADERS, header); + if (version == AFTERBIRTH_HEADERS.end()) + { + log_printf(LOG_INFO, "AfterbirthPersistentGameData wrong file header (%.16s)\n", std::string(header).c_str()); + return false; + } + + int versionNumber = (int)(version - AFTERBIRTH_HEADERS.begin()) + AFTERBIRTH_VERSION_FIRST; + int chunkLimit = versionNumber == AFTERBIRTH_VERSION_FIRST ? CHUNK_GAME_SETTINGS : CHUNK_SPECIAL_SEEDS; + uint32_t storedChecksum = 0; + if (file.size() >= SAVE_HEADER_SIZE + sizeof(storedChecksum)) + std::memcpy(&storedChecksum, file.data() + file.size() - sizeof(storedChecksum), sizeof(storedChecksum)); + bool isChecksumValid = + file.size() >= SAVE_HEADER_SIZE + sizeof(storedChecksum) && + storedChecksum == save_checksum_get(file.subspan(SAVE_HEADER_SIZE, file.size() - SAVE_HEADER_SIZE - 4)); + if (versionNumber >= AFTERBIRTH_VERSION_CHECKED && !isChecksumValid) + { + log_printf(LOG_INFO, "[warn] AfterbirthPersistentGameData checksum invalid!\n"); + return false; + } + + SaveReader reader{file, SAVE_HEADER_SIZE}; + int chunkId = 0; + reader.read(save.gameStateChecksum); + while (!reader.is_end() && chunkId >= 0 && chunkId < chunkLimit) + { + uint32_t chunkSize = 0; + auto entries_read = [&](auto& entries, const char* noun) + { chunk_read(reader, chunkSize, entries, {nullptr, noun, CHUNK_COUNT_CLAMPED}); }; + reader.read(chunkId); + reader.read(chunkSize); + if (chunkSize == 0) continue; + + switch (chunkId) + { + case CHUNK_ACHIEVEMENTS: entries_read(save.achievements, "achievements"); break; + case CHUNK_COUNTERS: entries_read(save.counters, "counters"); break; + case CHUNK_LEVEL_COUNTERS: entries_read(save.levelCounters, "counters"); break; + case CHUNK_COLLECTIBLES: entries_read(save.collectibles, "collectibles in collection"); break; + case CHUNK_MINIBOSSES: entries_read(save.minibosses, "minibosses"); break; + case CHUNK_BOSSES: entries_read(save.bosses, "minibosses"); break; + case CHUNK_CHALLENGES: entries_read(save.challenges, "challenges"); break; + case CHUNK_CUTSCENES: entries_read(save.cutscenes, "cutscenes"); break; + case CHUNK_GAME_SETTINGS: entries_read(save.settings, "settings"); break; + case CHUNK_SPECIAL_SEEDS: entries_read(save.specialSeeds, "special seeds"); break; + default: break; + } + } + return true; +} + +// A Rebirth save (versions 2 to 6), as RebirthSaveData reads it: Rebirth's chunks at Rebirth's sizes and from version 4 +// the saved run's checksum after the header. The trailing save count from version 6 is never used. +struct RebirthSave +{ + std::array achievements{}; + std::array bosses{}; + std::array challenges{}; + std::array collectibles{}; + std::array minibosses{}; + std::array counters{}; + std::array cutscenes{}; + std::array levelCounters{}; + std::array settings{}; + uint32_t gameStateChecksum = 0; +}; +// The Rebirth save headers, each version's with and without its R, and the version each pair stands for. +constexpr std::array REBIRTH_HEADERS = { + "ISAACNGSAVE02R ", "ISAACNGSAVE02 ", "ISAACNGSAVE03R ", "ISAACNGSAVE03 ", "ISAACNGSAVE04R ", + "ISAACNGSAVE04 ", "ISAACNGSAVE05R ", "ISAACNGSAVE05 ", "ISAACNGSAVE06R ", "ISAACNGSAVE06 "}; +constexpr int REBIRTH_VERSION_FIRST = 2; +constexpr int REBIRTH_VERSION_RUN_CHECKSUM = 4; +// The chunks each version has: up to the challenges, the cutscenes from version 3, the settings from version 5. +constexpr std::array REBIRTH_CHUNK_LIMITS = {CHUNK_CHALLENGES, CHUNK_CUTSCENES, CHUNK_CUTSCENES, + CHUNK_GAME_SETTINGS, CHUNK_GAME_SETTINGS}; +// The counters Repentance added among Rebirth's, and (009e4f80) where Rebirth's level counters sit among Repentance's. +constexpr std::array REBIRTH_SKIPPED_COUNTERS = {4, 38, 39, 40, 52, 53, 54, 66, 67, 68, + 80, 81, 82, 94, 95, 96, 108, 109, 110}; +constexpr std::array REBIRTH_LEVEL_COUNTERS = {0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 0, 11}; +// The cutscenes Rebirth's repair marks seen for its kill counters, by Rebirth's counter index. +constexpr std::array, 5> REBIRTH_KILL_CUTSCENES = { + {{12, 15}, {10, 16}, {24, 18}, {23, 17}, {25, 19}}}; +constexpr int REBIRTH_COUNTER_MOM_KILLS = 1; +// The collectibles Rebirth's collection check counts as seen whether or not they were. +constexpr std::array REBIRTH_REMOVED_COLLECTIBLES = {43, 61, 235}; + +// 0041ddb0, 009e3ea0 (afterbirth_save_index_remap and Rebirth's) An earlier game's counter index among Repentance's, +// moved past each counter Repentance added before it. +template static int counter_remap(int counter, const Skipped& skipped) +{ + for (int added : skipped) + if (counter > 0 && counter >= added) counter++; + return counter; +} + +// Marks a cutscene of a Rebirth save seen at least once, and with it the credits. +static void rebirth_cutscene_mark(RebirthSave& save, int cutscene) +{ + save.cutscenes[cutscene] = std::max(save.cutscenes[cutscene], 1); + save.cutscenes[CUTSCENE_CREDITS] = std::max(save.cutscenes[CUTSCENE_CREDITS], 1); +} + +// 009e4af0 (RebirthSaveData::repair_counters) Marks seen the cutscenes a Rebirth save's progress played: the +// epilogue, one per Mom kill up to eleven, and the final bosses' by their kill counters. +static void rebirth_repair(RebirthSave& save) +{ + if (save.achievements[ACHIEVEMENT_EPILOGUE]) rebirth_cutscene_mark(save, CUTSCENE_EPILOGUE); + for (int kill = 0; kill < MOM_KILL_CUTSCENE_COUNT && kill < save.counters[REBIRTH_COUNTER_MOM_KILLS]; kill++) + rebirth_cutscene_mark(save, MOM_KILL_CUTSCENE_FIRST + kill); + for (auto [counter, cutscene] : REBIRTH_KILL_CUTSCENES) + if (save.counters[counter] > 0) rebirth_cutscene_mark(save, cutscene); +} + +// The end of RebirthSaveData's load: the base collection's achievement once every collectible is seen (the removed +// ones counted, the unobtainable ones owed) with every achievement unlocked but the exempt ones, and Everything's once +// all are unlocked with nothing owed. Rebirth sets them without unlocking. +static void rebirth_collection_check(RebirthSave& save) +{ + int seenCount = 0; + int unobtainableCount = 0; + for (int collectible = 1; collectible < (int)save.collectibles.size(); collectible++) + { + if (save.collectibles[collectible] || is_listed(REBIRTH_REMOVED_COLLECTIBLES, collectible)) seenCount++; + else unobtainableCount += is_listed(COLLECTION_UNOBTAINABLE, collectible); + } + if (seenCount + unobtainableCount < COLLECTION_BASE_NEEDED) return; + + int exemptCount = 0; + int unlockedCount = 0; + for (int achievement = 1; achievement < COLLECTION_BASE_ACHIEVEMENTS_END; achievement++) + { + if (save.achievements[achievement]) unlockedCount++; + else exemptCount += is_listed(COLLECTION_ACHIEVEMENTS_EXEMPT, achievement); + } + if (exemptCount + unlockedCount >= COLLECTION_BASE_ACHIEVEMENTS_NEEDED) + save.achievements[ACHIEVEMENT_BASE_COLLECTION] = true; + if (unlockedCount >= COLLECTION_BASE_ACHIEVEMENTS_NEEDED && unobtainableCount == 0) + save.achievements[ACHIEVEMENT_BASE_EVERYTHING] = true; +} + +// 009e4260 (RebirthSaveData's load) Reads a Rebirth save, false for a wrong header, then repairs its cutscene counters +// and checks its collection. Its checksum is never checked, and every chunk keeps at most the entries Rebirth had. +// (009e3dc0) The save starts empty, as RebirthSaveData::Clear left it. +static bool rebirth_read(std::span file, RebirthSave& save) +{ + std::string_view header((const char*)file.data(), std::min(file.size(), SAVE_HEADER_SIZE)); + auto found = std::ranges::find(REBIRTH_HEADERS, header); + if (found == REBIRTH_HEADERS.end()) + { + log_printf(LOG_INFO, "RebirthPersistentGameData wrong file header (%.16s)\n", std::string(header).c_str()); + return false; + } + + int version = (int)(found - REBIRTH_HEADERS.begin()) / 2 + REBIRTH_VERSION_FIRST; + SaveReader reader{file, SAVE_HEADER_SIZE}; + int chunkId = 0; + if (version >= REBIRTH_VERSION_RUN_CHECKSUM) reader.read(save.gameStateChecksum); + while (!reader.is_end() && chunkId >= 0 && chunkId < REBIRTH_CHUNK_LIMITS[version - REBIRTH_VERSION_FIRST]) + { + uint32_t chunkSize = 0; + auto entries_read = [&](auto& entries, const char* noun) + { chunk_read(reader, chunkSize, entries, {nullptr, noun, CHUNK_COUNT_CLAMPED}); }; + reader.read(chunkId); + reader.read(chunkSize); + if (chunkSize == 0) continue; + + switch (chunkId) + { + case CHUNK_ACHIEVEMENTS: entries_read(save.achievements, "achievements"); break; + case CHUNK_COUNTERS: entries_read(save.counters, "counters"); break; + case CHUNK_LEVEL_COUNTERS: entries_read(save.levelCounters, "counters"); break; + case CHUNK_COLLECTIBLES: entries_read(save.collectibles, "collectibles in collection"); break; + case CHUNK_MINIBOSSES: entries_read(save.minibosses, "minibosses"); break; + case CHUNK_BOSSES: entries_read(save.bosses, "minibosses"); break; + case CHUNK_CHALLENGES: entries_read(save.challenges, "challenges"); break; + case CHUNK_CUTSCENES: entries_read(save.cutscenes, "cutscenes"); break; + case CHUNK_GAME_SETTINGS: entries_read(save.settings, "settings"); break; + default: break; + } + } + + rebirth_repair(save); + rebirth_collection_check(save); + return true; +} + +// TryImportRebirthLocalSave's import: takes a Rebirth save's progress whole as the Afterbirth import does, with its +// level counters moved to Repentance's indices too. +bool PersistentGameData::import_rebirth_save(std::span file) +{ + RebirthSave save; + if (!rebirth_read(file, save)) return false; + + Clear(CLEAR_ALL); + std::ranges::copy(save.achievements, achievements.begin()); + std::ranges::copy(save.bosses, bosses.begin()); + std::ranges::copy(save.challenges, challenges.begin()); + std::ranges::copy(save.collectibles, itemsCollection.begin()); + for (int counter = 0; counter < (int)save.counters.size(); counter++) + eventCounters[counter_remap(counter, REBIRTH_SKIPPED_COUNTERS)] = save.counters[counter]; + std::ranges::copy(save.cutscenes, cutsceneCounters.begin()); + std::ranges::copy(save.minibosses, miniBosses.begin()); + lastDifficulty = save.settings[0]; + for (int counter = 0; counter < (int)save.levelCounters.size(); counter++) + levelCounters[REBIRTH_LEVEL_COUNTERS[counter]] = save.levelCounters[counter]; + imported_unlocks_check(); + return true; +} + +// 0092b930 Takes an Afterbirth save's progress whole (achievements, bosses, challenges, the collection, counters moved +// to Repentance's indices, cutscenes, minibosses, the last difficulty and the level counters), then unlocks what it +// earned without popups, backing up and writing the save when that changed it. False when the save cannot be read. +// Steam Cloud is offline. +bool PersistentGameData::import_afterbirth_save(std::span file) +{ + AfterbirthSave save; + if (!afterbirth_read(file, save)) return false; + + Clear(CLEAR_ALL); + std::ranges::copy(save.achievements, achievements.begin()); + std::ranges::copy(save.bosses, bosses.begin()); + std::ranges::copy(save.challenges, challenges.begin()); + std::ranges::copy(save.collectibles, itemsCollection.begin()); + for (int counter = 0; counter < (int)save.counters.size(); counter++) + eventCounters[counter_remap(counter, AFTERBIRTH_SKIPPED_COUNTERS)] = save.counters[counter]; + std::ranges::copy(save.cutscenes, cutsceneCounters.begin()); + std::ranges::copy(save.minibosses, miniBosses.begin()); + lastDifficulty = save.settings[0]; + std::ranges::copy(save.levelCounters, levelCounters.begin()); + imported_unlocks_check(); + return true; +} + +// Unlocks what an imported save earned, with the popups off, then backs up and writes the save when that changed it. +void PersistentGameData::imported_unlocks_check() +{ + OptionsConfig& options = g_manager->optionsConfig; + int popupsMode = options.popupsMode; + + isChangesMade = true; + options.popupsMode = 0; + check_challenge_unlocks(); + IncreaseEventCounter(0, 0); + options.popupsMode = popupsMode; + if (!isChangesMade || !isFileLoaded) return; + + isChangesMade = false; + BackupSaveFile(); + Save(); +} + // 00926e90 Reads a save, completes what older saves lack, and writes it back (with a backup) if that changed it. bool PersistentGameData::stream_load(std::span file) { diff --git a/src/persistent_game_data.h b/src/persistent_game_data.h index 2b4bec2..1141a43 100644 --- a/src/persistent_game_data.h +++ b/src/persistent_game_data.h @@ -49,6 +49,10 @@ constexpr int CHALLENGE_COUNT = 46; constexpr int COLLECTIBLE_SEEN_COUNT = 733; constexpr int CUTSCENE_COUNTER_COUNT = 27; constexpr int EVENT_COUNTER_COUNT = 523; + +// The collection's slots a pill and a card taken fill (no item of their own has those ids). +constexpr int COLLECTION_PILL = 43; +constexpr int COLLECTION_CARD = 61; constexpr int LEVEL_COUNTER_COUNT = 14; constexpr int MINIBOSS_COUNT = 7; constexpr int SPECIAL_SEED_COUNT = 80; @@ -57,6 +61,7 @@ constexpr int SPECIAL_SEED_COUNT = 80; enum EventCounter : int { EVENT_COUNTER_MOM_KILLS = 1, + EVENT_COUNTER_PILLS_USED = 6, EVENT_COUNTER_DEATHS = 10, EVENT_COUNTER_ISAAC_KILLS = 11, EVENT_COUNTER_SATAN_KILLS = 13, @@ -80,6 +85,8 @@ enum EventCounter : int EVENT_COUNTER_DAILIES_PLAYED = 190, EVENT_COUNTER_DAILY_RUN_IS_ACTIVE = 191, EVENT_COUNTER_DAILYS_STREAK = 192, + EVENT_COUNTER_DAILYS_WON = 193, + EVENT_COUNTER_CARDS_USED = 196, EVENT_COUNTER_MOTHER_KILLS = 491, EVENT_COUNTER_BEAST_KILLS = 492, EVENT_COUNTER_BATTERY_BUMS_KILLED = 494, @@ -299,6 +306,9 @@ private: bool read(std::span file); std::vector write(); bool stream_load(std::span file); + bool import_afterbirth_save(std::span file); + bool import_rebirth_save(std::span file); + void imported_unlocks_check(); void backfill_cutscene_counters(); void check_counter_unlocks(); void check_challenge_unlocks(); diff --git a/src/player_hud.cpp b/src/player_hud.cpp index 8d7e23b..3443b7c 100644 --- a/src/player_hud.cpp +++ b/src/player_hud.cpp @@ -76,10 +76,8 @@ constexpr float HEART_SMALL_SPACING_Y = 6; constexpr int HEARTS_PER_ROW = 6; constexpr int HEART_ALPHA_FULL = 255; constexpr int HEART_ALPHA_DIMMED = 80; -constexpr float BYTE_TO_UNIT = 1 / 255.0f; constexpr int FORGOTTEN_HEART_SLOTS = 6; constexpr int GOLD_RESET_SLOT = 5; -constexpr int ROOM_INDEX_DEATHMATCH = -19; constexpr float DEATHMATCH_BAR_SHIFT_X = -4; constexpr float DEATHMATCH_BAR_SHIFT_Y = -6; @@ -490,7 +488,9 @@ static void trinket_icon_load(PlayerHUDTrinket& trinket) minY = std::min(minY, y); maxY = std::max(maxY, y); } - trinket.offset = vector_make((float)((maxY - minY) / 2 + minY), (float)((maxX - minX) / 2 + minX)); + uint32_t middleY = (maxY - minY) / 2 + minY; + uint32_t middleX = (maxX - minX) / 2 + minX; + trinket.offset = vector_make((float)middleY, (float)middleX); } // The trinket the error trinket passes for in the current room, picked by the room's spawn seed, or the error trinket @@ -734,7 +734,7 @@ void PlayerHUD::UpdateHearts(std::span slots, Entity_Player& sho void PlayerHUD::RenderHearts(Vector& outExtent, ANM2& sprite, PlayerHudLayout layout, float heartScale, Vector at) { Game& game = *g_game; - if (game.currentRoomIdx == ROOM_INDEX_DEATHMATCH) + if (game.currentRoomIdx == ROOM_DEATHMATCH_IDX) { outExtent = render_deathmatch_health_bar(vector_make(at.x + DEATHMATCH_BAR_SHIFT_X, at.y + DEATHMATCH_BAR_SHIFT_Y)); return; @@ -779,8 +779,9 @@ void PlayerHUD::RenderHearts(Vector& outExtent, ANM2& sprite, PlayerHudLayout la float stepX = isFlipped ? -spacingX : spacingX; auto slot_position = [&](int slot) { + int row = slot / HEARTS_PER_ROW; return vector_make((float)(slot % HEARTS_PER_ROW) * stepX * heartScale + at.x, - (float)(slot / HEARTS_PER_ROW) * spacingY * heartScale + at.y); + (float)row * spacingY * heartScale + at.y); }; int maxColumn = -1; int maxRow = 0; @@ -862,8 +863,9 @@ void PlayerHUD::RenderHearts(Vector& outExtent, ANM2& sprite, PlayerHudLayout la slot = limit; } maxColumn = std::max(maxColumn, slot % HEARTS_PER_ROW); + int row = slot / HEARTS_PER_ROW; Vector position = vector_make(((float)(slot % HEARTS_PER_ROW) * stepX + shift) * heartScale + at.x, - (float)(slot / HEARTS_PER_ROW) * spacingY * heartScale + at.y); + (float)row * spacingY * heartScale + at.y); if (mantle->count > 1 && shields[1]) { @@ -1552,8 +1554,9 @@ void PlayerHUD::render_inventory(Vector at, float inventoryScale) sprite.scale = vector_make(inventoryScale, inventoryScale); for (int slot = 0; slot < slots; slot++) { + int row = slot / columns; Vector cell = vector_make((float)(slot % columns) * INVENTORY_STEP * inventoryScale + at.x, - (float)(slot / columns) * INVENTORY_STEP * inventoryScale + at.y); + (float)row * INVENTORY_STEP * inventoryScale + at.y); bool isShown = slot < (int)inventoryIcons.size() && (inventoryIcons[slot].image || inventoryIcons[slot].id < 0); if (isShown) { @@ -1679,8 +1682,9 @@ void PlayerHUD::RenderCraftingTable(Vector at, float tableScale) float reach = tableScale * CRAFTING_SLOT_REACH; for (int slot = 0; slot < BAG_OF_CRAFTING_SIZE; slot++) { + int row = slot / CRAFTING_COLUMNS; Vector spot = vector_make(((float)(slot % CRAFTING_COLUMNS) * CRAFTING_STEP - CRAFTING_SLOTS_X) * tableScale + at.x, - ((float)(slot / CRAFTING_COLUMNS) * CRAFTING_STEP - CRAFTING_SLOTS_Y) * tableScale + at.y); + ((float)row * CRAFTING_STEP - CRAFTING_SLOTS_Y) * tableScale + at.y); crafting_frame_set(sprite, CRAFTING_SLOT_ANIMATION, (float)player->bagOfCraftingContent[slot]); sprite.Render({spot}); boundsMin = vector_make(std::min(boundsMin.x, spot.x - reach), std::min(boundsMin.y, spot.y - reach)); @@ -1689,10 +1693,199 @@ void PlayerHUD::RenderCraftingTable(Vector at, float tableScale) KAGE::Graphics::manager.shader_default_set(); } -// 0084ad40 Draws a versus health bar and returns its size. -Vector PlayerHUD::render_deathmatch_health_bar(Vector) +// The hearts of a versus health bar's segments in the order it shows them, also the order of their columns in its +// image (two texels each: a cap and a fill). +enum VersusBarKind : int { - reconstruction_missing("PlayerHUD::render_deathmatch_health_bar 0084ad40"); + VERSUS_BAR_RED, + VERSUS_BAR_EMPTY, + VERSUS_BAR_SOUL, + VERSUS_BAR_GOLDEN, + VERSUS_BAR_ROTTEN, + VERSUS_BAR_BONE, + VERSUS_BAR_BLACK, + VERSUS_BAR_KIND_COUNT +}; + +// A rectangle of texels in the health bar's image. +struct VersusBarTexels +{ + float x = 0; + float y = 0; + float width = 0; + float height = 0; +}; + +// A versus health bar: 80 hearts on its first row and the rest on a second one 13 lower, 1.2 wide each, drawn in +// segments of at most 16 between caps 2 wide, with a tick 1 wide between kinds, all 8 high. A frame 14 high goes +// around each row, starting 2 above and left of it, and the player's portrait sits left of the first row. +constexpr const char* VERSUS_BAR_PNG = "gfx/ui/ui_isaachealthbar.png"; +constexpr int VERSUS_BAR_ROW_HEARTS = 80; +constexpr int VERSUS_BAR_SEGMENT_HEARTS = 16; +constexpr float VERSUS_BAR_HEART_WIDTH = 1.2f; +constexpr float VERSUS_BAR_CAP_WIDTH = 2; +constexpr float VERSUS_BAR_TICK_WIDTH = 1; +constexpr float VERSUS_BAR_HEIGHT = 8; +constexpr float VERSUS_BAR_ROW_SPACING = 13; +constexpr float VERSUS_BAR_FRAME_INSET = 2; +constexpr float VERSUS_BAR_PORTRAIT_BACK_X = -14; +constexpr float VERSUS_BAR_PORTRAIT_X = -16; +constexpr float VERSUS_BAR_PORTRAIT_Y = -2; +constexpr float VERSUS_BAR_SIZE_X = 46; +constexpr float VERSUS_BAR_SIZE_Y = 17; +constexpr VersusBarTexels VERSUS_BAR_TICK = {12, 6, 1, 2}; +constexpr VersusBarTexels VERSUS_BAR_FRAME_LEFT = {22, 16, 3, 14}; +constexpr VersusBarTexels VERSUS_BAR_FRAME_MIDDLE = {25, 16, 1, 14}; +constexpr VersusBarTexels VERSUS_BAR_FRAME_RIGHT = {26, 16, 5, 14}; +constexpr VersusBarTexels VERSUS_BAR_PORTRAIT_BACK = {15, 0, 16, 14}; +constexpr VersusBarTexels VERSUS_BAR_PORTRAIT = {0, 14, 20, 18}; + +// The source quad of a rectangle of the health bar's image. +static SourceQuad versus_bar_source(const VersusBarTexels& texels) +{ + return KAGE::Graphics::source_quad_rect(vector_make(texels.x, texels.y), vector_make(texels.width, texels.height)); +} + +// The hearts a player has of a kind of the health bar: its empty heart containers stand for the empty kind. +static int versus_bar_hearts_get(const Entity_Player& shown, int kind) +{ + switch (kind) + { + case VERSUS_BAR_RED: return shown.redHearts; + case VERSUS_BAR_EMPTY: return shown.maxHearts - shown.redHearts; + case VERSUS_BAR_SOUL: return shown.soulHearts; + case VERSUS_BAR_GOLDEN: return shown.goldenHearts; + case VERSUS_BAR_ROTTEN: return shown.rottenHearts; + case VERSUS_BAR_BONE: return shown.boneHearts; + default: return shown.blackHearts; + } +} + +// (0084a920, 0084abc0) Draws up to 16 hearts of a kind at the cursor as a cap, a stretched fill and a cap, taking them +// from both the kind's and the row's counts. Whether either count ran out. +static bool versus_bar_segment_render(KAGE::Graphics::ImageBase& image, int kind, Vector& cursor, int& hearts, + int& remaining) +{ + float column = (float)(kind * 2); + SourceQuad cap = versus_bar_source({column, 0, 1, VERSUS_BAR_HEIGHT}); + SourceQuad fill = versus_bar_source({column + 1, 0, 1, VERSUS_BAR_HEIGHT}); + int taken = std::min({remaining, hearts, VERSUS_BAR_SEGMENT_HEARTS}); + + hearts -= taken; + remaining -= taken; + float width = (float)taken * VERSUS_BAR_HEART_WIDTH; + Vector capSize = vector_make(VERSUS_BAR_CAP_WIDTH, VERSUS_BAR_HEIGHT); + if (width > 0) + { + image.Render(cap, KAGE::Graphics::color_quad_rect(cursor, capSize, WHITE), WHITE); + cursor.x += VERSUS_BAR_CAP_WIDTH; + width -= VERSUS_BAR_CAP_WIDTH; + } + if (width > VERSUS_BAR_CAP_WIDTH) + { + Vector fillSize = vector_make(width - VERSUS_BAR_CAP_WIDTH, VERSUS_BAR_HEIGHT); + KAGE::Graphics::ColorQuad quad = KAGE::Graphics::color_quad_rect(cursor, fillSize, WHITE); + image.Render(fill, quad, WHITE); + cursor.x += quad._topRight.x - quad._topLeft.x; + width = VERSUS_BAR_CAP_WIDTH; + } + if (width > 0) + { + image.Render(cap, KAGE::Graphics::color_quad_rect(cursor, capSize, WHITE), WHITE); + cursor.x += VERSUS_BAR_CAP_WIDTH; + } + return std::min(hearts, remaining) == 0; +} + +// 0084ad40 Draws a versus health bar and returns its size (none for a ghost): the hearts kind by kind from red to +// black, a tick before each kind but the first of a row, the empty containers first finishing the red hearts' last +// segment. Past 80 hearts a second row starts. Then the frames, the portrait's backing and the portrait in the +// player's color. +Vector PlayerHUD::render_deathmatch_health_bar(Vector at) +{ + Entity_Player& shown = *player; + if (shown.isCoopGhost) return vector_make(0, 0); + if (!deathmatchHealthBarImage) deathmatchHealthBarImage = Manager::LoadImage(VERSUS_BAR_PNG); + if (!deathmatchHealthBarImage) return vector_make(0, 0); + + KAGE::Graphics::ImageBase& image = *deathmatchHealthBarImage; + std::vector rowEnds; + std::vector rowStarts = {vector_make(at.x - VERSUS_BAR_FRAME_INSET, at.y - VERSUS_BAR_FRAME_INSET)}; + std::vector ticks; + Vector cursor = at; + int total = shown.rottenHearts + shown.boneHearts + shown.goldenHearts + shown.blackHearts + shown.soulHearts + + shown.maxHearts; + int rowHearts = (unsigned)total > VERSUS_BAR_ROW_HEARTS ? VERSUS_BAR_ROW_HEARTS : total; + int overflowHearts = total - rowHearts; + int* remaining = &rowHearts; + int hearts = shown.redHearts; + int kind = VERSUS_BAR_RED; + bool isTickSkipped = hearts > 0; + + while (kind < VERSUS_BAR_KIND_COUNT) + { + cursor = vector_make(std::floor(cursor.x), std::floor(cursor.y)); + if (std::min(*remaining, hearts) > 0) + { + if (!isTickSkipped) + { + ticks.push_back(cursor); + cursor.x += VERSUS_BAR_TICK_WIDTH; + } + isTickSkipped = false; + } + + int startHearts = hearts; + if (!versus_bar_segment_render(image, kind, cursor, hearts, *remaining)) continue; + if (*remaining == 0) + { + if (overflowHearts <= 0) break; + remaining = &overflowHearts; + rowEnds.push_back(vector_make(cursor.x - 1, cursor.y - VERSUS_BAR_FRAME_INSET)); + cursor = vector_make(at.x, at.y + VERSUS_BAR_ROW_SPACING); + isTickSkipped = true; + rowStarts.push_back(vector_make(cursor.x - VERSUS_BAR_FRAME_INSET, cursor.y - VERSUS_BAR_FRAME_INSET)); + } + if (hearts != 0 || ++kind == VERSUS_BAR_KIND_COUNT) continue; + + hearts = versus_bar_hearts_get(shown, kind); + if (kind != VERSUS_BAR_EMPTY) continue; + int finish = std::min(VERSUS_BAR_SEGMENT_HEARTS - startHearts, hearts); + if (finish == 0) continue; + hearts -= finish; + versus_bar_segment_render(image, kind, cursor, finish, *remaining); + } + if (rowStarts.size() > rowEnds.size()) + rowEnds.push_back(vector_make(cursor.x - 1, cursor.y - VERSUS_BAR_FRAME_INSET)); + + SourceQuad tick = versus_bar_source(VERSUS_BAR_TICK); + Vector tickSize = vector_make(VERSUS_BAR_TICK_WIDTH, VERSUS_BAR_HEIGHT); + for (Vector& spot : ticks) image.Render(tick, KAGE::Graphics::color_quad_rect(spot, tickSize, WHITE), WHITE); + + SourceQuad left = versus_bar_source(VERSUS_BAR_FRAME_LEFT); + SourceQuad middle = versus_bar_source(VERSUS_BAR_FRAME_MIDDLE); + SourceQuad right = versus_bar_source(VERSUS_BAR_FRAME_RIGHT); + for (size_t row = 0; row < rowStarts.size(); row++) + { + Vector start = rowStarts[row]; + Vector end = rowEnds[row]; + image.Render(left, start, WHITE); + image.Render(right, end, WHITE); + Vector from = vector_make(start.x + VERSUS_BAR_FRAME_LEFT.width, start.y); + Vector to = vector_make(end.x, end.y + VERSUS_BAR_FRAME_MIDDLE.height); + DestinationQuad quad = {from, vector_make(to.x, from.y), vector_make(from.x, to.y), to}; + image.Render(middle, KAGE::Graphics::ColorQuad(quad, WHITE), WHITE); + } + + std::array& colors = g_game->playerManager.colorControllers; + auto color = std::ranges::find(colors, shown.controllerIndex); + int colorIndex = color == colors.end() ? PLAYER_COLOR_NONE : (int)(color - colors.begin()); + image.Render(versus_bar_source(VERSUS_BAR_PORTRAIT_BACK), vector_make(at.x + VERSUS_BAR_PORTRAIT_BACK_X, at.y), + WHITE); + image.Render(versus_bar_source(VERSUS_BAR_PORTRAIT), + vector_make(at.x + VERSUS_BAR_PORTRAIT_X, at.y + VERSUS_BAR_PORTRAIT_Y), + PlayerManager::GetPlayerColorValue(colorIndex)); + return vector_make(VERSUS_BAR_SIZE_X, VERSUS_BAR_SIZE_Y); } // 009a8500 A new corner of a HUD, not one of its eight, showing a player. diff --git a/src/player_hud.h b/src/player_hud.h index b5fd38d..9818227 100644 --- a/src/player_hud.h +++ b/src/player_hud.h @@ -17,12 +17,11 @@ constexpr int PLAYER_HUD_POCKET_COUNT = 4; constexpr float PLAYER_HUD_BOUNDS_FAR = 1e7f; // A trinket icon as the corners and the recent items draw it: its size, its frames across for Monkey Paw, the tint of -// the error trinket, the clay colorize of a Modeling Clay copy and the golden shimmer's steps. +// the error trinket and the clay colorize of a Modeling Clay copy. constexpr float TRINKET_SIZE = 32; constexpr int MONKEY_PAW_FRAMES = 3; constexpr std::array ERROR_TRINKET_TINT = {132 / 255.0f, 26 / 255.0f, 26 / 255.0f}; constexpr std::array CLAY_COLORIZE = {0.5976471f, 0.33411765f, 0.31058824f, 1}; -constexpr int GOLD_SHIMMER_STEPS = 256; // REPENTOGON's HUD layouts of a player, and the spot an online player's status takes. enum PlayerHudLayout : int diff --git a/src/player_manager.cpp b/src/player_manager.cpp index 89ed42e..c80d193 100644 --- a/src/player_manager.cpp +++ b/src/player_manager.cpp @@ -42,9 +42,13 @@ constexpr int HOURGLASS_INDEX_LAST = 3; constexpr int JOIN_CONTROLS_COOLDOWN = 15; constexpr int JOIN_DAMAGE_COOLDOWN = 45; constexpr float JOIN_SPAWN_DISTANCE = 10; -constexpr float LEAVE_POOF_HEIGHT = 10; constexpr float JOIN_MENU_POSITION = 1; constexpr int COOP_BABY_MIN_HEARTS = 3; + +// A baby joining when only babies may join: its invincibility, and the share of the first player's hearts it takes. +constexpr int JOIN_BABY_DAMAGE_COOLDOWN = 150; +constexpr uint32_t JOIN_BABY_HEART_SHARE = 4; +constexpr uint32_t JOIN_BABY_MIN_HEARTS = 2; constexpr int SOUND_JOIN_REFUSED = 187; constexpr int SOUND_CAROUSEL_LEFT = 194; constexpr int SOUND_CAROUSEL_RIGHT = 195; @@ -62,7 +66,6 @@ constexpr float START_DEPTH_STEP = 0.01f; // How far enter_level moves the other players toward where they stood from the lead player. constexpr float ENTER_SPREAD = 3; -constexpr float HALF_TURN = 3.14f; constexpr const char* PLAYER_TEARS_GROUP = "player tears"; // The babies of babies.xml the game ships (those past them are a random pick's extras) and the glitched one. @@ -700,7 +703,7 @@ void PlayerManager::enter_level() Vector offset = vector_make(player->pos.x - lead->pos.x, player->pos.y - lead->pos.y); if (offset.x == 0 && offset.y == 0 && player != lead) { - float angle = random_unit() * HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; offset = vector_make(std::cos(angle), std::sin(angle)); } @@ -921,10 +924,10 @@ void PlayerManager::RemoveCoPlayer(Entity_Player* player) if (player->variant == PLAYER_VARIANT_EXTRA) { + // The original also writes a versus player's field at the NPC controller's offset (an unrelated player field). + // Here only NPCs lose the controller. for (Entity* entity : room.entityList.updateEL) { - if (entity && entity->type == ENTITY_PLAYER && game.deathmatchManager.is_active()) - reconstruction_missing("PlayerManager::RemoveCoPlayer 009ba000 (a versus player's controller)"); auto* npc = dynamic_cast(entity); if (npc && npc->controllerID == controller) npc->controllerID = -1; } @@ -1129,10 +1132,147 @@ void PlayerManager::add_lost_curse() } } -void PlayerManager::spawn_coop_baby_for_join(int) +// Part of 009bd3b0: a joining baby takes a quarter of the first player's hearts from the top, at least one heart. +// Soul and bone hearts go first (a bone heart with the red hearts in it), then red hearts with their containers. +static void join_baby_hearts_take(Entity_Player& first, Entity_Player& baby, uint32_t totalHearts) { - reconstruction_missing("PlayerManager::spawn_coop_baby_for_join 009bd3b0"); + int wanted = (int)std::max(totalHearts / JOIN_BABY_HEART_SHARE, JOIN_BABY_MIN_HEARTS); + log_printf(LOG_INFO, "Co-player wants %d HP\n", wanted); + + int boneLeft = first.boneHearts; + int red = first.redHearts; + int redOutsideBones = boneLeft * 2; + int soul = first.soulHearts; + int sideSlots = (soul + 1) / 2 + boneLeft; + int slot = sideSlots - 1; + int boneTaken = 0; + int maxTaken = 0; + int redTaken = 0; + int soulTaken = 0; + for (int taken = 0; wanted > 0; taken++) + { + bool isBone = slot >= 0 && boneLeft > 0 && first.boneHearts > 0 && (first.boneHeartsMask & (1 << (slot & 31))); + int amount = slot < 0 ? 2 - red % 2 + : isBone ? std::clamp(red - redOutsideBones - first.maxHearts + 2, 0, 2) + : 2 - soul % 2; + int cost = isBone ? amount + 1 : amount; + if (taken > 0 && wanted < cost) break; + + wanted -= cost; + if (slot < 0) + { + red -= amount; + redTaken += amount; + maxTaken += 2; + continue; + } + if (isBone) + { + red -= amount; + redTaken += amount; + redOutsideBones -= 2; + boneLeft--; + boneTaken++; + } + else + { + soul -= amount; + soulTaken += amount; + } + slot--; + } + log_printf(LOG_INFO, "Taking %d red HP, %d soul HP and %d bone HP\n", redTaken, soulTaken, boneTaken); + + for (int i = slot + 1; i < sideSlots; i++) + { + if (first.boneHearts > 0 && (first.boneHeartsMask & (1 << (i & 31)))) + { + baby.AddBoneHearts(1); + continue; + } + + int heart = ((baby.soulHearts + 1) & ~1) + 1; + bool isBlack = heart > 0 && heart <= first.soulHearts && (first.blackHearts & (1 << (heart / 2))); + if (isBlack) + { + first.blackHearts &= ~(1 << (heart / 2)); + first.ClampGoldenHearts(false); + first.update_bone_hearts(); + baby.AddBlackHearts(std::min(soulTaken - baby.soulHearts, 2)); + } + else + baby.AddSoulHearts(std::min(soulTaken - baby.soulHearts, 2), false); + } + baby.AddMaxHearts(maxTaken, false); + baby.AddHearts(redTaken, true, false); + first.AddSoulHearts(-soulTaken, false); + first.AddHearts(-redTaken, true, false); + first.AddBoneHearts(-boneTaken); + first.AddMaxHearts(-maxTaken, false); } + +// 009bd3b0 A co-op baby joins on a controller when only babies may: it appears by the first player, safe from harm for +// a while, with a share of its hearts (two free ones in kids mode), its second familiar, and copies of its items. +void PlayerManager::spawn_coop_baby_for_join(int controllerIndex) +{ + Entity_Player* first = GetPlayer(0); + uint32_t totalHearts = first->redHearts + first->soulHearts + first->boneHearts; + bool isKidsMode = g_game->seedEffects.HasSeedEffect(SEED_KIDS_MODE); + if (first->golden_holders_count() < 2 && !isKidsMode) return; + + // The original crashes on a full player list. handle_coop_join never calls it then. + Entity_Player* baby = SpawnCoPlayerBaby(-1); + if (!baby) return; + baby->PlayExtraAnimation("Appear"); + baby->damageCooldown = JOIN_BABY_DAMAGE_COOLDOWN; + baby->SetControllerIndex(controllerIndex, true); + baby->pos = find_safe_spawn_position(first->pos); + baby->AddMaxHearts(-baby->maxHearts, false); + baby->apply_coop_baby_spawn_bonus(); + if (isKidsMode) + { + baby->AddMaxHearts(2, false); + baby->AddHearts(2, true, false); + } + else + join_baby_hearts_take(*first, *baby, totalHearts); + + // The original reads a familiar's player unchecked. One without a player is skipped here. + std::vector familiars = entity_query(ENTITY_FAMILIAR, -1); + int sharable = 0; + for (Entity* entity : familiars) + { + auto* familiar = static_cast(entity); + int variant = familiar->variant; + bool isKept = variant == Entity_Familiar::PUNCHING_BAG || variant == Entity_Familiar::ISAACS_HEART || + variant == Entity_Familiar::GUILLOTINE || variant == Entity_Familiar::FORGOTTEN_BODY; + if (isKept || !familiar->player || familiar->player->variant != PLAYER_VARIANT_PLAYER) continue; + if (++sharable < 2) continue; + + familiar->set_player(baby); + break; + } + for (Entity* entity : familiars) + { + auto* familiar = static_cast(entity); + auto* parent = dynamic_cast(familiar->parent.get()); + if (parent && parent->player != familiar->player) familiar->set_player(familiar->player); + } + + for (int id = 0; id < COLLECTIBLE_VANILLA_COUNT; id++) + for (int i = 0; i < first->collectibleCounts[id]; i++) baby->AddCollectible(id, 0, true, 0, 0, 0); + baby->activeItems[0] = first->activeItems[0]; + for (uint32_t trinket : first->trinkets) + if (trinket) baby->AddTrinket(trinket, true); + std::copy_n(first->pillEffectUses.begin(), PILL_EFFECT_SLOTS, baby->pillEffectUses.begin()); + baby->smeltedTrinkets = first->smeltedTrinkets; + baby->voidedCollectibles = first->voidedCollectibles; + + baby->cacheFlags = CACHE_ALL; + baby->EvaluateItems(); + g_game->hud.AssignPlayerHUDs(); +} + // Plays a sound at a volume, unless the seeds swap it for a fart. static void manager_sound_play(int sound, SoundPlay play = {}) { @@ -1268,7 +1408,7 @@ static void coop_seat_update(PlayerManager& players, CoopJoinSlot& seat) Entity_Player* player = game.playerManager.SpawnCoPlayer2(playerType); player->SetControllerIndex(seat.controllerIndex, true); Vector first = game.playerManager.GetPlayer(0)->pos; - float angle = random_unit() * HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; player->pos = vector_make(std::cos(angle) * JOIN_SPAWN_DISTANCE + first.x, std::sin(angle) * JOIN_SPAWN_DISTANCE + first.y); game.hud.AssignPlayerHUDs(); diff --git a/src/player_manager.h b/src/player_manager.h index e5c211d..ac35fd2 100644 --- a/src/player_manager.h +++ b/src/player_manager.h @@ -1,6 +1,7 @@ #pragma once #include "classes.h" +#include "seeds.h" #include #include #include @@ -9,8 +10,6 @@ constexpr int COOP_SLOT_COUNT = 4; constexpr int ESAU_JR_SLOT_COUNT = 4; constexpr int RANDOM_BABY_COUNT = 5; -// The xorshift the manager's generators start on, before a run seeds them (shift index 35). -constexpr RNG PLAYER_RNG_UNSEEDED = {0xaa17414f, 5, 9, 7}; constexpr uint32_t PLAYER_RNG_SHIFT = 34; // Whether an item query also asks the dead Lazarus kept as a backup player, for items tagged as shared globally. @@ -52,6 +51,9 @@ struct CoopJoinSlot bool isPlayerTypeForced = false; }; +// How far over a co-op baby leaving the run its poof shows. +constexpr float LEAVE_POOF_HEIGHT = 10; + // The player color index of a controller with none assigned. constexpr int PLAYER_COLOR_NONE = 5; @@ -74,8 +76,8 @@ public: std::array colorControllers = {-1, -1, -1, -1}; std::array randomBabies{}; Vector centerCache{}; - RNG glitchBabyRng = PLAYER_RNG_UNSEEDED; - RNG rng = PLAYER_RNG_UNSEEDED; + RNG glitchBabyRng = RNG_DEFAULT; + RNG rng = RNG_DEFAULT; int randomBabyCount = 0; unsigned int centerCacheFrame = UINT32_MAX; bool isColorAssignEnabled = true; diff --git a/src/popups.cpp b/src/popups.cpp index e9a5fb3..faafcec 100644 --- a/src/popups.cpp +++ b/src/popups.cpp @@ -49,7 +49,6 @@ constexpr float SLIDE_IN_Y = -223; constexpr float SLIDE_OUT_Y = -233; constexpr float CENTER_RAISE = 9; constexpr float HEIGHT_PADDING_SCALE = 1.65f; -constexpr float QUARTER_TURN = -1.5707964f; constexpr int BOUNCE_STEP_COUNT = 4; constexpr int BOUNCE_LAST_STEP = BOUNCE_STEP_COUNT - 1; @@ -492,7 +491,7 @@ static void frame_piece_render(const Popup& popup, const FrameSource& source, Fr Vector sourceAt = vector_make(source.x0, source.y0); Vector sourceSize = vector_make(source.x1 - source.x0, source.y1 - source.y0); - if (pivot) quad_turn(quad, quad.*pivot, QUARTER_TURN); + if (pivot) quad_turn(quad, quad.*pivot, -QUARTER_TURN); popup.frameImage->Render(KAGE::Graphics::source_quad_rect(sourceAt, sourceSize), quad, unset); } diff --git a/src/procedural_item_manager.cpp b/src/procedural_item_manager.cpp index 139dd3b..84edd28 100644 --- a/src/procedural_item_manager.cpp +++ b/src/procedural_item_manager.cpp @@ -1,28 +1,683 @@ #include "procedural_item_manager.h" +#include "boss_ai.h" +#include "entity_combat.h" +#include "entity_effect.h" +#include "entity_npc.h" +#include "entity_player.h" +#include "entity_tear.h" +#include "fx_layers.h" #include "game.h" -#include "log.h" #include "manager.h" +#include "platform.h" +#include "render_passes.h" +#include "room_grid.h" #include -#include +#include +#include +#include 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. +// The most glitched items a run makes, past which a seed picks an existing one. +constexpr size_t PROCEDURAL_ITEM_LIMIT = 1024; +// The seed bits that make a glitched item an active. +constexpr uint32_t ACTIVE_SEED_BITS = 0xc000; +// The xorshift triples of the generators: picking past the limit, the item's own, a text's glyphs and an effect's. +constexpr uint32_t LIMIT_SHIFT_INDEX = 1; +constexpr uint32_t ITEM_SHIFT_INDEX = 31; +constexpr uint32_t GLYPH_SHIFT_INDEX = 69; +constexpr uint32_t EFFECT_SHIFT_INDEX = 71; + +// The G FUEL! seed's item: the seed it comes with, its sprite, name and collection icon, the costume it wears and the +// real item whose effects it lends (Speed Ball). constexpr uint32_t G_FUEL_ITEM_SEED = 1; +constexpr const char* G_FUEL_GFX = "gfx/promo/gfuel/items/collectibles/Collectibles_143_Speedball.png"; +constexpr const char* G_FUEL_NAME = "G FUEL!"; +constexpr const char* G_FUEL_ICON_PNG = "gfx/promo/gfuel/ui/death items.png"; +constexpr const char* MOD_ICON_PNG = "gfx/ui/mod_defaults.png"; // 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 UNUSABLE_ACTIVES = {127, 297, 347, 475, 482, 483, 490, 515, 585, 628, 636}; +// A glitched text: the mark the glitched font draws it by, its length (three rolls of 0 to 7 over 4, 1 in 80 times up +// to 39 more), where in its stream it starts, and the runs of random glyphs between the items' fields. +constexpr char GLITCH_TEXT_MARK = 1; +constexpr uint32_t GLITCH_ROLL_MASK = 7; +constexpr int GLITCH_LENGTH_MIN = 4; +constexpr uint32_t GLITCH_LONG_ODDS = 80; +constexpr uint32_t GLITCH_LONG_EXTRA = 40; +constexpr uint32_t GLITCH_POSITION_MASK = 63; +constexpr int GLITCH_GLYPH_RUN = 32; +constexpr uint8_t UTF8_CONTINUATION = 0x80; +constexpr uint8_t UTF8_PAYLOAD = 0x3f; +constexpr uint8_t UTF8_LEAD = 0xc0; +constexpr uint8_t UTF8_LEAD_LOWEST = 0xc2; +constexpr uint8_t UTF8_LEAD_PAYLOAD = 0x1f; +constexpr uint8_t UTF8_OVERLONG_BITS = 0x1e; + +// The pickups a glitched item gives: one kind of fourteen (eight give none), each rolled below 6 less one below 3, +// then a 1 in 40 chance each of up to 5 more. +constexpr uint32_t PICKUP_KINDS = 14; +constexpr uint32_t PICKUP_ROLL = 6; +constexpr uint32_t PICKUP_TAKEN = 3; +constexpr uint32_t PICKUP_BONUS_ODDS = 40; + +// The stats a glitched item adds: 1 in 20 times (1 in 5 without cache flags or containers), all of them 1 in 40 times, +// else one or two of 0.25 to 1.25 in a shuffled order, maybe with a third one down by up to 0.4. +constexpr uint32_t STAT_ODDS = 20; +constexpr uint32_t STAT_ODDS_PLAIN = 5; +constexpr uint32_t STAT_ALL_ODDS = 40; +constexpr uint32_t STAT_SECOND_MASK = 7; +constexpr uint32_t STAT_DOWN_ODDS = 2; +constexpr uint32_t STAT_DOWN_ODDS_LOW = 5; +constexpr float STAT_UP_BASE = 0.25f; +constexpr float STAT_SECOND_BELOW = 0.5f; +constexpr float STAT_DOWN_BASE = 0.1f; +constexpr std::array GLITCHED_STAT_CACHES = {CACHE_DAMAGE, CACHE_FIREDELAY, CACHE_SPEED, + CACHE_RANGE, CACHE_SHOTSPEED, CACHE_LUCK}; + +// A glitched active's charges by the seed's low bits, timed from 13 on. +constexpr std::array ACTIVE_CHARGES = {0, 1, 2, 2, 3, 3, 3, 4, 4, 4, 6, 6, 6, 12, 300, 600}; +constexpr int TIMED_CHARGES_FROM = 13; + +// The effects: at most 100 rolls and 8 effects, the passive conditions and the actions by the seed's low bits, a chain +// three times in four after the first, and 1 in 20 kept over the budget. +constexpr int EFFECT_ROLLS = 100; +constexpr size_t EFFECTS_MAX = 8; +constexpr std::array PASSIVE_CONDITIONS = { + CONDITION_TEAR_FIRE, CONDITION_ENEMY_HIT, CONDITION_ENEMY_KILL, CONDITION_DAMAGE_TAKEN, + CONDITION_ROOM_CLEAR, CONDITION_ENTITY_SPAWN, CONDITION_PICKUP_COLLECTED}; +constexpr std::array EFFECT_ACTIONS = { + ACTION_USE_ACTIVE_ITEM, ACTION_USE_ACTIVE_ITEM, ACTION_ADD_TEMPORARY_EFFECT, ACTION_ADD_TEMPORARY_EFFECT, + ACTION_CONVERT_ENTITIES, ACTION_AREA_DAMAGE, ACTION_SPAWN_ENTITY, ACTION_FART}; +constexpr uint32_t CHAIN_MASK = 3; +constexpr uint32_t EFFECT_KEEP_ODDS = 20; + +// The prices (one or two hearts, 1 to 99 coins) and the sounds a glitched item never plays. +constexpr uint32_t SHOP_PRICE_RANGE = 99; +constexpr std::string_view VOICEOVER_SFX = "sfx/voiceover"; + +// A glitched sprite: 8 by 8 tiles of 4 pixels, each a tile of one of four random items' sprites, in one of four colors. +constexpr int TILE_SIZE = 4; +constexpr int TILES_PER_SIDE = 8; +constexpr int TILE_COUNT = TILES_PER_SIDE * TILES_PER_SIDE; +constexpr int SPRITE_SOURCES = 4; +constexpr int SOURCE_TRIES = 10; +constexpr uint32_t TILE_SHIFT_ODDS = 5; +constexpr uint32_t TILE_COLOR_ODDS = 5; +constexpr uint32_t TILE_COLOR_CHANGE_ODDS = 12; +constexpr uint32_t TILE_SOURCE_SWITCH_ODDS = 12; +constexpr uint32_t TILE_SOURCE_STEP_ODDS = 20; +constexpr uint32_t TILE_COLORS = 3; +constexpr uint32_t TILE_COLOR_MASK = 3; +constexpr ColorMod TILE_INVERTED = {{-1, -1, -1, 1}, {0, 0, 0, 0}, {1, 1, 1}}; +constexpr ColorMod TILE_BRIGHT = {{1, 1, 1, 1}, {1, 1, 1, 2}, {0, 0, 0}}; +// A collection icon: the 16 pixel corner of its sheet drawn 32 wide at 16 pixel cells. +constexpr float COLLECTION_ICON_SOURCE = 16; +constexpr float COLLECTION_ICON_SIZE = 32; + +// The odds of an effect's conditions and the any-enemy target, the strength of each action's roll, and their scores. +constexpr uint32_t ANY_VARIANT = 0xffff; +constexpr uint32_t TARGET_ANY_ENEMY = 999; +constexpr uint32_t TARGET_TYPE_SHIFT = 16; +constexpr uint32_t ENEMY_TYPE_RANGE = 990; +constexpr float CHANCE_RARE = 0.01f; +constexpr float CHANCE_UNCOMMON = 0.02f; +constexpr float CHANCE_ALWAYS = 1; +constexpr float CHANCE_SPAWN_BASE = 0.1f; +constexpr float TRIGGER_CHANCE = 0.05f; +constexpr float KILL_TRIGGER_CHANCE = 0.2f; +constexpr int COLLECTIBLE_BERSERK_SCORE = 704; +constexpr float BERSERK_SCORE = 6; +constexpr float CONVERT_RADIUS = 1000; +constexpr float CONVERT_SCORE_UNBOUNDED = 10000; +constexpr float AREA_RADIUS_SCALE = 8000; +constexpr float AREA_RADIUS_BASE = 30; +constexpr float AREA_DAMAGE_OFFSET = 0.2f; +constexpr double AREA_DAMAGE_SCALE = 80; +constexpr float AREA_SCORE_SCALE = 0.1f; +constexpr float AREA_FLAG_SCORE = 0.4f; +constexpr float AREA_FEW_FLAGS_BELOW = 5; +constexpr uint32_t AREA_FLAG_ODDS = 20; +constexpr uint32_t AREA_FLAG_ODDS_HIGH = 100; +constexpr uint32_t AREA_FLAGS_ODDS = 3; +constexpr float SPAWN_SCORE_SCALE = 100; +constexpr double FART_ROLL_SCALE = 10; +constexpr double FART_ROLL_BASE = 5; +constexpr uint32_t FART_SUBTYPES = 10; +constexpr uint32_t FART_COLOR_ODDS = 4; +constexpr float FART_RADIUS_SCALE = 6; +constexpr float FART_SIZE_RADIUS = 85; +constexpr float TEAR_FIRE_SCORE_SCALE = 10; +constexpr float SPAWN_SPEED = 8; +constexpr int AREA_DAMAGE_COUNTDOWN = 30; +constexpr int CONVERT_ROLL_TRIES = 100; +constexpr int SPAWN_ROLL_TRIES = 10; +constexpr uint32_t TRIGGER_CATEGORIES = 6; +constexpr uint32_t SPAWN_CONFIG_MASK = 7; +constexpr uint32_t SPAWN_CATEGORY_MASK = 3; + +// The G FUEL! item's descriptions, one rolled each time it is taken, and the sounds by the run's G FUEL! stacks. +constexpr std::array G_FUEL_DESCRIPTIONS = { + "GAMER SPEED UP!", "G UP!", "WISDOM UP!", "FASTER UP!", "GENEROSITY UP!", "MISERY UP!", "MANA UP!", "ENERGY UP!", + "SLEEP HOURS DOWN!", "GOOD UP!", "MIX UP!", "REACTION UP!", "A STAT UP!", "THOU ART HERO!", "BLOOD UP!", + "WHITE BLOOD CELLS UP!", "FAME UP!", "SHOTS UP!", "SENTIENCE UP!", "MOVEMENT UP!", "RESPECT UP!", "FEAR UP!", + "BONES UP!", "RISK UP!", "EXPLOSIONS UP!", "RANK UP! REACHED RANK: ISAAC'S FACE", "STRENGTH UP!", + "POPULATION UP!", "FAVOR UP!", "SUSPICION UP!", "MORALITY UP!", "SUNSHINE UP!", "VOLUME UP!", "SOUL UP!", + "VITALITY UP!", "SHARPNESS UP!", "BUILDING SPEED UP!", "GOD'S LIGHT UP!", "TEAR TASTE UP!", "ACIDITY UP!", + "HEIGHT UP!", "HURTFUL WORDS RESISTANCE UP!", "AMMO CAPACITY UP!", "AMBITION UP!", "DISC SPEED UP!", + "ACCEPTANCE UP!", "HUMOR UP!", "SHUTTER SPEED UP!", "MOMENTUM UP!", "AIR RESISTANCE UP!"}; + +// The G FUEL! stacks from which its pickup sounds louder, adds a spewer and then a louder one. +constexpr int G_FUEL_LOUD_STACKS = 2; +constexpr int G_FUEL_SPEWER_STACKS = 4; +constexpr int G_FUEL_LOUDEST_STACKS = 6; +// A glitched item's pickup sound plays at a pitch of 0.2 to 1.6 its seed rolls. +constexpr float PICKUP_PITCH_RANGE = 1.4f; +constexpr float PICKUP_PITCH_BASE = 0.2f; + +// Whether a glitched effect's trigger is running, so effects it sets off do not trigger again (DAT_00c7f600). +static bool isGlitchedTriggering = false; + +// A tile of a glitched sprite: the tile of its source sprite, which of the four sources, and which color. +struct GlitchTile +{ + uint8_t source = 0; + uint8_t image = 0; + uint8_t color = 0; +}; + +// A target rolled for an effect, packed as type << 16 | variant, and how likely it is to come about. +struct RolledTarget +{ + uint32_t target = 0; + float chance = 0; +}; + +// The writer of a glitched text (009dcc70's, written to by 009dcbb0): the stream position written up to, where the +// stream's current piece starts, the bytes left to write, and the UTF-8 continuation bytes a lead still wants. +struct GlitchWriter +{ + std::string& text; + int base = 0; + int position = 0; + int remaining = 0; + int pending = 0; + + // Appends a stream byte: a continuation while a lead wants one, a lead for one at or above 0x80, 1 for a 0. + void put(uint8_t byte) + { + if (pending > 0) + { + text.push_back((char)((byte & UTF8_PAYLOAD) | UTF8_CONTINUATION)); + pending--; + } + else if (byte & UTF8_CONTINUATION) + { + text.push_back((char)((byte & UTF8_LEAD_PAYLOAD) | ((byte & UTF8_OVERLONG_BITS) ? UTF8_LEAD : UTF8_LEAD_LOWEST))); + pending = 1; + } + else text.push_back(byte == 0 ? 1 : (char)byte); + remaining--; + } + + // 009dcbb0 Writes the bytes of the stream's next piece past the position, and whether the text is full. + bool write(const void* data, int size) + { + int end = base + size; + for (; position < end && remaining > 0; position++) put(static_cast(data)[position - base]); + base = end; + return remaining < 1; + } + + // A 16-bit field, low byte first. + bool number_write(int value) + { + uint8_t bytes[2] = {(uint8_t)value, (uint8_t)(value >> 8)}; + return write(bytes, 2); + } + + // Random glyphs up to a stream position. + void glyphs_write(RNG& glyphs, int end) + { + for (; position < end && remaining > 0; position++) put((uint8_t)glyphs.Next()); + } + + // An item's raw fields: its id, its name and description with their lengths, its type and its charges. + bool item_write(ItemConfig_Item& item, const std::string& name, const std::string& desc) + { + return number_write(item.id) || number_write((int)name.size()) || write(name.data(), (int)name.size()) || + number_write((int)desc.size()) || write(desc.data(), (int)desc.size()) || number_write(item.type) || + number_write(item.chargeType) || number_write(item.initCharge) || number_write(item.maxCharges) || + number_write(item.maxCooldown); + } +}; + +// A pickup count rolled below 6, less one below 3. +static int pickup_roll(RNG& rng) +{ + int count = (int)rng.RandomInt(PICKUP_ROLL); + return count - (int)rng.RandomInt(PICKUP_TAKEN); +} + +// Where an item's cell starts on a surface of cells of a size. +static Vector cell_position(int itemId, float cellSize) +{ + int index = ~itemId; + return vector_make((float)(index % PROCEDURAL_CELLS_PER_ROW) * cellSize, (float)(index / PROCEDURAL_CELLS_PER_ROW) * cellSize); +} + +// Draws an image's source rect over a rect of the bound surface, through a sprite color. +static void surface_draw(KAGE::Graphics::ImageBase& image, const SourceQuad& source, const Vector& position, + const Vector& size, const ColorMod& color) +{ + KAGE::Graphics::ColorQuad quad = KAGE::Graphics::color_quad_rect(position, size, WHITE); + apply_sprite_shader_params(color, SPRITE_SHADER_COLOR_APPLY, image); + image.Render(source, quad, kcolor_rgba(color._tint[0], color._tint[1], color._tint[2], color._tint[3])); +} + // 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}); } +// One pass of 009dcc70's glitched text: its mark, then random glyphs and the raw fields of real items from a rolled +// one on, read as a byte stream from a rolled point, as UTF-8. +static std::string glitch_text_make(RNG& rng) +{ + std::vector>& collectibles = g_manager->itemConfig.collectibles; + int length = (int)(rng.Next() & GLITCH_ROLL_MASK); + length += (int)(rng.Next() & GLITCH_ROLL_MASK); + length += (int)(rng.Next() & GLITCH_ROLL_MASK) + GLITCH_LENGTH_MIN; + if (rng.Next() % GLITCH_LONG_ODDS == 0) length += (int)(rng.Next() % GLITCH_LONG_EXTRA); + + uint32_t count = (uint32_t)collectibles.size(); + uint32_t roll = rng.Next(); + uint32_t id = count == 0 ? 0 : roll % count; + while (!collectibles[id]) id = (id + 1) % count; + + std::string text(1, GLITCH_TEXT_MARK); + RNG glyphs = rng_make(rng.Next(), GLYPH_SHIFT_INDEX); + GlitchWriter writer = {text, 0, (int)(rng.Next() & GLITCH_POSITION_MASK), length}; + while (true) + { + ItemConfig_Item& source = *collectibles[id]; + std::string name = source.GetLocalizedName(); + std::string desc = source.description_get(); + + writer.glyphs_write(glyphs, GLITCH_GLYPH_RUN); + writer.base = GLITCH_GLYPH_RUN; + if (writer.remaining < 1 || writer.item_write(source, name, desc)) break; + writer.glyphs_write(glyphs, writer.base + GLITCH_GLYPH_RUN); + writer.base += GLITCH_GLYPH_RUN; + if (writer.remaining < 1) break; + + do id = (id + 1) % count; + while (!collectibles[id]); + writer.position = 0; + writer.base = 0; + } + return text; +} + +// The part of 009dcc70 rolling a glitched item's stats: all six, or one or two up in a shuffled order and maybe a +// third down. +static void glitched_stats_roll(std::array& stats, RNG& rng) +{ + std::array order = {0, 1, 2, 3, 4, 5}; + for (uint32_t i = 0; i + 1 < GLITCHED_STAT_COUNT; i++) + std::swap(order[i], order[rng.RandomInt(GLITCHED_STAT_COUNT - i) + i]); + + if (rng.Next() % STAT_ALL_ODDS == 0) + { + for (float& stat : stats) + { + float first = rng.RandomFloat(); + stat = rng.RandomFloat() + first; + } + return; + } + stats[order[0]] = rng.RandomFloat() + STAT_UP_BASE; + if (stats[order[0]] < STAT_SECOND_BELOW || (rng.Next() & STAT_SECOND_MASK) == 0) + stats[order[1]] = rng.RandomFloat() + STAT_UP_BASE; + uint32_t downOdds = stats[order[1]] + stats[order[0]] > 1 ? STAT_DOWN_ODDS : STAT_DOWN_ODDS_LOW; + if (rng.RandomInt(downOdds) == 0) stats[order[2]] = STAT_DOWN_BASE - rng.RandomFloat() * HALF; +} + +// A rolled variant of an entity type, among the configs of that type, packed with the type. +// The original reads past an empty list. Here an empty one gives variant 0. +static RolledTarget variant_pick(RNG& rng, int type, float chance) +{ + std::vector configs = g_manager->entityConfig.entities_get(type); + uint32_t index = rng.RandomInt((uint32_t)configs.size()); + uint32_t variant = index < configs.size() ? (uint32_t)configs[index].variant & ANY_VARIANT : 0; + return {(uint32_t)type << TARGET_TYPE_SHIFT | variant, chance}; +} + +// A random enemy type that is no boss, of ten (a hundred) tries, or 0. +static uint32_t enemy_type_roll(RNG& rng, int tries) +{ + std::map& entities = g_manager->entityConfig.entities; + for (int i = 0; i < tries; i++) + { + uint32_t type = rng.Next() % ENEMY_TYPE_RANGE + ENTITY_FIRST_ENEMY; + auto found = entities.find(entity_key((int)type, 0, 0)); + if (found != entities.end() && !found->second.isBoss) return type & ANY_VARIANT; + } + return 0; +} + +// 009e0700 ProceduralEffect::roll_trigger_target: an entity a convert or spawn condition acts on: tears, projectiles, +// pickups (each maybe of a rolled variant), bombs, any non-boss enemy (often one rolled type of them) or an effect. +static RolledTarget trigger_target_roll(RNG& rng) +{ + switch (rng.Next() % TRIGGER_CATEGORIES) + { + case 0: + if (rng.RandomInt(3) != 0) return {(uint32_t)ENTITY_TEAR << TARGET_TYPE_SHIFT | ANY_VARIANT, CHANCE_RARE}; + return variant_pick(rng, ENTITY_TEAR, CHANCE_RARE); + case 1: + if (rng.RandomInt(3) != 0) return {(uint32_t)ENTITY_PROJECTILE << TARGET_TYPE_SHIFT | ANY_VARIANT, CHANCE_RARE}; + return variant_pick(rng, ENTITY_PROJECTILE, CHANCE_RARE); + case 2: + if (rng.RandomInt(4) == 0) return {(uint32_t)ENTITY_PICKUP << TARGET_TYPE_SHIFT | ANY_VARIANT, CHANCE_ALWAYS}; + return variant_pick(rng, ENTITY_PICKUP, CHANCE_ALWAYS); + case 3: return {(uint32_t)ENTITY_BOMB << TARGET_TYPE_SHIFT | ANY_VARIANT, CHANCE_UNCOMMON}; + case 4: + { + uint32_t type = rng.RandomInt(4) == 0 ? enemy_type_roll(rng, CONVERT_ROLL_TRIES) : 0; + return {(type != 0 ? type : TARGET_ANY_ENEMY) << TARGET_TYPE_SHIFT | ANY_VARIANT, CHANCE_UNCOMMON}; + } + default: return variant_pick(rng, ENTITY_EFFECT, CHANCE_UNCOMMON); + } +} + +// 009e0ad0 ProceduralEffect::roll_spawn_target: an entity an effect spawns or converts into: 1 in 8 the last of ten +// random non-boss, non-player configs, else a tear, a pickup (often of a rolled variant), a bomb or an enemy type. +static RolledTarget spawn_target_roll(RNG& rng) +{ + std::map& entities = g_manager->entityConfig.entities; + if ((rng.Next() & SPAWN_CONFIG_MASK) == 0) + { + RolledTarget rolled; + for (int i = 0; i < SPAWN_ROLL_TRIES; i++) + { + uint32_t roll = rng.Next(); + auto config = entities.begin(); + if (!entities.empty()) std::advance(config, roll % entities.size()); + if (config == entities.end() || config->second.id == ENTITY_PLAYER || config->second.isBoss) continue; + rolled.target = ((uint32_t)config->second.id & ANY_VARIANT) << TARGET_TYPE_SHIFT | + ((uint32_t)config->second.variant & ANY_VARIANT); + rolled.chance = rng.RandomFloat() + CHANCE_SPAWN_BASE; + } + return rolled; + } + + switch (rng.Next() & SPAWN_CATEGORY_MASK) + { + case 0: return variant_pick(rng, ENTITY_TEAR, CHANCE_RARE); + case 1: + if (rng.RandomInt(4) == 0) return {(uint32_t)ENTITY_PICKUP << TARGET_TYPE_SHIFT, CHANCE_ALWAYS}; + return variant_pick(rng, ENTITY_PICKUP, CHANCE_ALWAYS); + case 2: return variant_pick(rng, ENTITY_BOMB, CHANCE_UNCOMMON); + default: + { + uint32_t type = enemy_type_roll(rng, SPAWN_ROLL_TRIES); + return {(type != 0 ? type : (uint32_t)ENTITY_FIRST_ENEMY) << TARGET_TYPE_SHIFT, CHANCE_UNCOMMON}; + } + } +} + +// 009e0f60 Rolls what an effect does from its seed and scores it: an usable active (by its charge, more for +// Berserk!), a temporary collectible effect, a conversion, an area hit with maybe tear flags, a spawn or a fart. A +// spawn condition divides the score by its target's chance, a tear one multiplies it by ten. +void ProceduralEffect::roll_params(ProceduralCondition rolledCondition, ProceduralAction rolledAction, uint32_t rollSeed) +{ + RNG rng = rng_make(rollSeed, EFFECT_SHIFT_INDEX); + condition = rolledCondition; + action = rolledAction; + seed = rollSeed; + score = 0; + target = 0; + convertTarget = 0; + radius = 0; + strength = 0; + tearFlags.reset(); + chanceScale = 1; + + switch (action) + { + case ACTION_USE_ACTIVE_ITEM: + { + std::vector& actives = g_game->proceduralItemManager.usableActives; + uint32_t index = rng.RandomInt((uint32_t)actives.size()); + // The original reads past an empty list. Here the effect keeps no item. + if (index >= actives.size()) break; + ItemConfig_Item& active = *actives[index]; + if (active.chargeType == CHARGE_TIMED) score = (float)active.quality; + else if (active.chargeType == CHARGE_NORMAL) score = (float)active.maxCharges * HALF + 1; + if (active.id == COLLECTIBLE_BERSERK_SCORE) score += BERSERK_SCORE; + target = (uint32_t)active.id; + break; + } + case ACTION_ADD_TEMPORARY_EFFECT: + for (int i = 0; i < SPAWN_ROLL_TRIES; i++) + { + uint32_t count = (uint32_t)g_manager->itemConfig.collectibles.size(); + uint32_t roll = rng.Next(); + uint32_t id = count == 0 ? 0 : roll % count; + if (!g_manager->itemConfig.GetCollectible((int)id)) continue; + target = id; + score = 1; + break; + } + break; + case ACTION_CONVERT_ENTITIES: + { + radius = CONVERT_RADIUS; + RolledTarget from = trigger_target_roll(rng); + RolledTarget to = spawn_target_roll(rng); + target = from.target; + convertTarget = to.target; + score = from.chance > 0 ? to.chance / from.chance : CONVERT_SCORE_UNBOUNDED; + break; + } + case ACTION_AREA_DAMAGE: + { + float first = rng.RandomFloat(); + float spread = rng.RandomFloat() * first; + radius = rng.RandomFloat() * spread * AREA_RADIUS_SCALE + AREA_RADIUS_BASE; + float offset = rng.RandomFloat() - AREA_DAMAGE_OFFSET; + strength = std::max((float)(rng.RandomFloat() * (double)offset * AREA_DAMAGE_SCALE), 0.0f); + score = strength * AREA_SCORE_SCALE; + if (rng.RandomInt(AREA_FLAGS_ODDS) != 0) break; + + uint32_t odds = strength < AREA_FEW_FLAGS_BELOW ? AREA_FLAG_ODDS : AREA_FLAG_ODDS_HIGH; + for (size_t flag = 0; flag < tearFlags.size(); flag++) + { + if (rng.Next() % odds != 0) continue; + tearFlags.set(flag); + score += AREA_FLAG_SCORE; + } + tearFlags.reset(TEAR_LUDOVICO); + break; + } + case ACTION_SPAWN_ENTITY: + { + RolledTarget spawned = spawn_target_roll(rng); + target = spawned.target; + score = spawned.chance * SPAWN_SCORE_SCALE; + break; + } + case ACTION_FART: + { + float size = (float)(rng.RandomFloat() * FART_ROLL_SCALE + FART_ROLL_BASE); + score = 1; + strength = (float)(rng.RandomFloat() * FART_ROLL_SCALE + size); + target = rng.RandomInt(FART_SUBTYPES); + if (rng.RandomInt(FART_COLOR_ODDS) != 0) break; + + std::array rolls; + for (float& roll : rolls) roll = rng.RandomFloat(); + color = {{rolls[9], rolls[8], rolls[7], 1}, {rolls[6], rolls[5], rolls[4], rolls[3]}, {rolls[2], rolls[1], rolls[0]}}; + break; + } + } + + if (condition == CONDITION_ENTITY_SPAWN) + { + RolledTarget spawn = trigger_target_roll(rng); + spawnTarget = spawn.target; + if (spawn.chance > 0) score /= spawn.chance; + } + if (condition == CONDITION_TEAR_FIRE) score *= TEAR_FIRE_SCORE_SCALE; +} + +// 009e14b0 Fires an effect: a spawn condition needs its entity (tears, projectiles and effects only now and then), +// the tear, hit and kill conditions their chance. Then it uses an active, adds a temporary effect, turns entities +// within its radius into another, hurts the enemies within its radius, spawns an entity thrown along the trigger or +// farts. Whether it did anything. +bool ProceduralEffect::execute(Entity_Player& player, const ProceduralTrigger& trigger) +{ + RNG& rng = player.GetCollectibleRNG(0); + + if (condition == CONDITION_ENTITY_SPAWN) + { + int type = (int)(spawnTarget >> TARGET_TYPE_SHIFT); + int variant = (spawnTarget & ANY_VARIANT) == ANY_VARIANT ? -1 : (int)(spawnTarget & ANY_VARIANT); + Entity* spawned = trigger.entity; + if (!spawned || spawned->type != type || (variant != -1 && spawned->variant != variant)) return false; + bool isFrequent = type == ENTITY_TEAR || type == ENTITY_PROJECTILE || type == ENTITY_EFFECT; + if (isFrequent && rng.RandomFloat() >= chanceScale * TRIGGER_CHANCE) return false; + } + if ((condition == CONDITION_TEAR_FIRE || condition == CONDITION_ENEMY_HIT) && rng.RandomFloat() >= chanceScale * TRIGGER_CHANCE) + return false; + if (condition == CONDITION_ENEMY_KILL && rng.RandomFloat() >= chanceScale * KILL_TRIGGER_CHANCE) return false; + + switch (action) + { + case ACTION_USE_ACTIVE_ITEM: + player.UseActiveItem({.item = (int)target, .flags = USE_NOANIM | USE_NOCOSTUME}); + return true; + case ACTION_ADD_TEMPORARY_EFFECT: + player.temporaryEffects.AddCollectibleEffect((int)target, true, 1); + return true; + case ACTION_CONVERT_ENTITIES: + { + int fromType = (int)(target >> TARGET_TYPE_SHIFT); + int fromVariant = (target & ANY_VARIANT) == ANY_VARIANT ? -1 : (int)(target & ANY_VARIANT); + bool isConverted = false; + for (Entity* entity : entities_live(g_game->room->entityList.updateEL)) + { + if (entity->HasEntityFlags(FLAG_DONT_OVERWRITE)) continue; + bool isAnyEnemy = fromType == (int)TARGET_ANY_ENEMY && entity->IsEnemy() && !entity->IsBoss(); + bool isTarget = entity->type == fromType && (fromVariant == -1 || entity->variant == fromVariant); + if (!isAnyEnemy && !isTarget) continue; + if (vector_length_squared(vector_sub(trigger.position, entity->pos)) > radius * radius) continue; + + entity->Remove(); + uint32_t spawnSeed = rng.Next(); + Entity* converted = g_game->Spawn({.position = entity->pos, .velocity = entity->velocity, .spawner = &player, + .type = (int)(convertTarget >> TARGET_TYPE_SHIFT), + .variant = (int)(convertTarget & ANY_VARIANT), .seed = spawnSeed}); + if (!converted) continue; + if (converted->IsEnemy()) converted->AddEntityFlags(FLAG_AMBUSH); + converted->Update(); + isConverted = true; + } + return isConverted; + } + case ACTION_AREA_DAMAGE: + { + bool isHit = false; + for (Entity* entity : entity_query_radius(trigger.position, radius, QUERY_ENEMIES)) + { + uint64_t damageFlags = tearFlags.any() ? tear_damage_flags_get(tearFlags, trigger.entity) : 0; + if (entity->TakeDamage(strength, damageFlags, EntityRef(&player), AREA_DAMAGE_COUNTDOWN)) isHit = true; + if (tearFlags.any()) + Entity_Tear::ApplyTearFlagEffects(entity, trigger.position, tearFlags, trigger.entity, strength); + } + return isHit; + } + case ACTION_SPAWN_ENTITY: + { + int type = (int)(target >> TARGET_TYPE_SHIFT); + if (type == 0) return false; + uint32_t spawnSeed = rng.Next(); + RNG throwRng = rng_make(seed, DEFAULT_SHIFT_INDEX); + float speed = throwRng.RandomFloat(); + Vector velocity = vector_make(trigger.velocity.x * SPAWN_SPEED * speed, trigger.velocity.y * SPAWN_SPEED * speed); + Entity* spawned = g_game->Spawn({.position = trigger.position, .velocity = velocity, .spawner = &player, + .type = type, .variant = (int)(target & ANY_VARIANT), .seed = spawnSeed}); + if (!spawned) return false; + if (spawned->IsEnemy()) spawned->AddEntityFlags(FLAG_AMBUSH); + spawned->Update(); + return true; + } + case ACTION_FART: + { + float fartRadius = strength * FART_RADIUS_SCALE; + game_fart({.position = trigger.position, .source = &player, .color = color, .radius = fartRadius, + .scale = fartRadius / FART_SIZE_RADIUS, .subType = (int)target}); + return true; + } + } + return false; +} + +// 009e1c30 The line the log gives an effect: its condition, then what it does. +std::string ProceduralEffect::describe() +{ + constexpr std::array CONDITION_NAMES = { + "active", "tear_fire", "enemy_hit", "enemy_kill", "damage_taken", "room_clear", "", "pickup_collected", "chain"}; + char text[MESSAGE_LENGTH]; + int spawnVariant = (spawnTarget & ANY_VARIANT) == ANY_VARIANT ? -1 : (int)(spawnTarget & ANY_VARIANT); + int fromVariant = (target & ANY_VARIANT) == ANY_VARIANT ? -1 : (int)(target & ANY_VARIANT); + auto item_name = [&] + { + ItemConfig_Item* item = g_manager->itemConfig.GetCollectible((int)target); + return item ? item->GetLocalizedName(LANGUAGE_ENGLISH) : std::string(); + }; + + if (condition == CONDITION_ENTITY_SPAWN) + std::snprintf(text, sizeof(text), "entity_spawned(%d.%d)", (int)(spawnTarget >> TARGET_TYPE_SHIFT), spawnVariant); + else std::snprintf(text, sizeof(text), "%s", condition >= 0 && condition <= CONDITION_CHAIN ? CONDITION_NAMES[condition] : "unknown"); + std::string line = std::string(text) + " -> "; + + switch (action) + { + case ACTION_USE_ACTIVE_ITEM: return line + "use_active_item " + item_name(); + case ACTION_ADD_TEMPORARY_EFFECT: return line + "add_temporary_effect " + item_name(); + case ACTION_CONVERT_ENTITIES: + std::snprintf(text, sizeof(text), "convert_entities %d.%d to %d.%d", (int)(target >> TARGET_TYPE_SHIFT), + fromVariant, (int)(convertTarget >> TARGET_TYPE_SHIFT), (int)(convertTarget & ANY_VARIANT)); + break; + case ACTION_AREA_DAMAGE: + { + unsigned long long high = 0; + unsigned long long low = 0; + for (int bit = 0; bit < 64; bit++) + { + low |= (unsigned long long)tearFlags[bit] << bit; + high |= (unsigned long long)tearFlags[bit + 64] << bit; + } + std::snprintf(text, sizeof(text), "area_damage %g (flags %08llx%08llx)", (double)strength, high, low); + break; + } + case ACTION_SPAWN_ENTITY: + std::snprintf(text, sizeof(text), "spawn_entity %d.%d", (int)(target >> TARGET_TYPE_SHIFT), (int)(target & ANY_VARIANT)); + break; + case ACTION_FART: std::snprintf(text, sizeof(text), "fart %g", (double)strength); break; + default: std::snprintf(text, sizeof(text), "unknown"); break; + } + return line + text; +} + // 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() @@ -55,16 +710,21 @@ void ProceduralItemManager::items_restore(const std::vector& seeds) for (uint32_t seed : seeds) CreateProceduralItem(seed, 0); } +// (009e0180, 009e0150) The glitched item with an id, or null. +ProceduralItem* ProceduralItemManager::GetProceduralItem(int itemId) +{ + return itemId < 0 && (size_t)~itemId < proceduralItems.size() ? proceduralItems[~itemId].get() : nullptr; +} + // 009e0240 Draws a glitched item's icon, its 32 pixel cell of the item surface by -1 - id, and whether it had one. // Rebirth named it GlitchedCollectibleGfx::render_item. bool ProceduralItemManager::render_item(int itemId, const SourceQuad& source, const KAGE::Graphics::ColorQuad& quad, const KColor& color) { - int index = -1 - itemId; - if (itemId >= 0 || index >= (int)proceduralItems.size() || !proceduralItems[index]->item) return false; + ProceduralItem* glitched = GetProceduralItem(itemId); + if (!glitched || !glitched->item) return false; - Vector cell = vector_make((float)(index % PROCEDURAL_CELLS_PER_ROW) * PROCEDURAL_CELL_SIZE, - (float)(index / PROCEDURAL_CELLS_PER_ROW) * PROCEDURAL_CELL_SIZE); + Vector cell = cell_position(itemId, PROCEDURAL_CELL_SIZE); SourceQuad atlas = source; for (Vector* corner : {&atlas._topLeft, &atlas._topRight, &atlas._bottomLeft, &atlas._bottomRight}) *corner = vector_add(*corner, cell); @@ -72,7 +732,372 @@ bool ProceduralItemManager::render_item(int itemId, const SourceQuad& source, co return true; } -int ProceduralItemManager::CreateProceduralItem(uint32_t, uint32_t) +// The end of 009dcc70 and 009dfc90: an item's collection icon drawn into its cell of the collection surface, the +// item surface pushed before given back. +void ProceduralItemManager::collection_icon_draw(ItemConfig_Item& item, std::string_view path) { - reconstruction_missing("ProceduralItemManager::CreateProceduralItem 009dcc70"); + KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager; + + graphics.SetRenderTarget(collectionRenderTarget.get(), KAGE::Graphics::TARGET_OWN_SIZE); + graphics.blend_set(KAGE::Graphics::BLEND_NORMAL); + graphics.shader_default_set(); + if (KAGE::Graphics::ImagePtr icon = Manager::LoadImage(path)) + surface_draw(*icon, KAGE::Graphics::source_quad_rect({}, vector_make(COLLECTION_ICON_SOURCE, COLLECTION_ICON_SOURCE)), + cell_position(item.id, COLLECTION_ICON_SOURCE), vector_make(COLLECTION_ICON_SIZE, COLLECTION_ICON_SIZE), + COLOR_DEFAULT); + graphics.Present(KAGE::Graphics::PRESENT_FINISH); + graphics.render_target_pop(KAGE::Graphics::PRESENT_FLUSH); + graphics.shader_default_set(); +} + +// 009dfc90 Adds a ready glitched item (the G FUEL! seed's), lending a real item's effects: its sprite is drawn into its +// cell and its gfx forgotten, and its collection icon comes from the G FUEL! sheet. Its id. +int ProceduralItemManager::item_add(std::unique_ptr item, ItemConfig_Item* target) +{ + KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager; + ProceduralItem& added = *proceduralItems.emplace_back(std::make_unique()); + added.index = (int)proceduralItems.size() - 1; + added.seed = G_FUEL_ITEM_SEED; + added.targetItem = target; + if (target) item->cacheFlags |= target->cacheFlags; + item->id = -(int)proceduralItems.size(); + + graphics.render_target_push(renderTarget.get(), KAGE::Graphics::TARGET_OWN_SIZE, KAGE::Graphics::PRESENT_FLUSH); + graphics.blend_set(KAGE::Graphics::BLEND_NORMAL); + graphics.shader_default_set(); + if (KAGE::Graphics::ImagePtr image = Manager::LoadImage(item->gfxFilename)) + { + Vector size = vector_make(PROCEDURAL_CELL_SIZE, PROCEDURAL_CELL_SIZE); + surface_draw(*image, KAGE::Graphics::source_quad_rect({}, size), cell_position(item->id, PROCEDURAL_CELL_SIZE), + size, COLOR_DEFAULT); + } + item->gfxFilename.clear(); + graphics.Present(KAGE::Graphics::PRESENT_FINISH); + collection_icon_draw(*item, G_FUEL_ICON_PNG); + + added.item = std::move(item); + g_manager->infoDisplay.add_item_entry(*added.item, DESCRIPTION_ADD); + return added.item->id; +} + +// The sprite part of 009dcc70: 8 by 8 tiles copied from four random items' sprites, each run of tiles from one source +// in one color (plain, the item's rolled hue, inverted or bright), then its collection icon. +void ProceduralItemManager::sprite_draw(ItemConfig_Item& item, RNG& rng) +{ + KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager; + graphics.render_target_push(renderTarget.get(), KAGE::Graphics::TARGET_OWN_SIZE, KAGE::Graphics::PRESENT_FLUSH); + graphics.blend_set(KAGE::Graphics::BLEND_NORMAL); + graphics.shader_default_set(); + + int source = 0; + if (rng.Next() % TILE_SHIFT_ODDS == 0) source = (int)(rng.Next() & (TILE_COUNT - 1)); + int image = 0; + int nextColor = rng.Next() % TILE_COLOR_ODDS == 0 ? (int)(Random() % TILE_COLORS + 1) : 0; + int color = nextColor; + std::array tiles; + for (int i = 0; i < TILE_COUNT; i++) + { + tiles[i] = {(uint8_t)source, (uint8_t)image, (uint8_t)color}; + source++; + if (rng.Next() % TILE_COLOR_CHANGE_ODDS == 0) nextColor = (int)(rng.Next() & TILE_COLOR_MASK); + if (source < TILE_COUNT && rng.Next() % TILE_SOURCE_SWITCH_ODDS != 0) + { + color = nextColor; + continue; + } + + image = (image + 1) % SPRITE_SOURCES; + source = rng.Next() % TILE_SOURCE_STEP_ODDS == 0 ? i + 1 : i; + nextColor = rng.Next() % TILE_COLOR_ODDS == 0 ? (int)(rng.Next() % TILE_COLORS + 1) : 0; + color = nextColor; + } + + std::array images; + uint32_t count = (uint32_t)g_manager->itemConfig.collectibles.size(); + for (KAGE::Graphics::ImagePtr& sprite : images) + for (int attempt = 0; attempt < SOURCE_TRIES; attempt++) + { + ItemConfig_Item* picked = g_manager->itemConfig.GetCollectible((int)rng.RandomInt(count - 1) + 1); + if (!picked || picked->gfxFilename.empty()) continue; + sprite = Manager::LoadImage(picked->gfxFilename); + break; + } + + KColor rolled = hsv_to_rgb(rng.RandomFloat() * FULL_TURN_DEGREES, 1, 1, 1); + ColorMod hue = {{1, 1, 1, 1}, {rolled._red, rolled._green, rolled._blue, rolled._alpha}, {0, 0, 0}}; + const std::array colors = {&COLOR_DEFAULT, &hue, &TILE_INVERTED, &TILE_BRIGHT}; + Vector cell = cell_position(item.id, PROCEDURAL_CELL_SIZE); + Vector tileSize = vector_make(TILE_SIZE, TILE_SIZE); + for (int i = 0; i < TILE_COUNT; i++) + { + GlitchTile& tile = tiles[i]; + if (!images[tile.image]) continue; + Vector from = vector_make((float)(tile.source / TILES_PER_SIDE * TILE_SIZE), (float)(tile.source % TILES_PER_SIDE * TILE_SIZE)); + Vector to = vector_make(cell.x + (float)(i / TILES_PER_SIDE * TILE_SIZE), cell.y + (float)(i % TILES_PER_SIDE * TILE_SIZE)); + surface_draw(*images[tile.image], KAGE::Graphics::source_quad_rect(from, tileSize), to, tileSize, *colors[tile.color]); + } + graphics.Present(KAGE::Graphics::PRESENT_FINISH); + collection_icon_draw(item, MOD_ICON_PNG); +} + +// 009dcc70 Makes the glitched item of a seed and returns its id. Past 1024 items an existing one is picked by the seed. +// The seed's 0xc000 bits make an active, unless the flags force one or the other. Its name and description are +// glitched text. Then come its pickups, the real item it copies, its stats, its charge, effects worth up to a rolled +// budget, its prices and pickup sound, and its sprite. A G FUEL! run's seed 1 makes the G FUEL! item first. +// Spawn conditions are listed (009e24f0) for Game::Spawn to trigger. +int ProceduralItemManager::CreateProceduralItem(uint32_t seed, uint32_t flags) +{ + ItemConfig& config = g_manager->itemConfig; + if (proceduralItems.size() >= PROCEDURAL_ITEM_LIMIT) + { + RNG pick = rng_make(seed, LIMIT_SHIFT_INDEX); + return proceduralItems[pick.RandomInt((uint32_t)proceduralItems.size())]->item->id; + } + if (g_game->seedEffects.HasSeedEffect(SEED_G_FUEL) && seed == G_FUEL_ITEM_SEED) + { + auto fuel = std::make_unique(); + fuel->gfxFilename = G_FUEL_GFX; + fuel->name = G_FUEL_NAME; + fuel->tags |= TAG_QUEST; + fuel->cacheFlags |= CACHE_ALL; + fuel->type = ITEM_PASSIVE; + fuel->isAddCostumeOnPickup = true; + if (ItemConfig_Item* costume = config.GetNullItem(NULLITEM_OVERDOSE)) fuel->costume = costume->costume; + item_add(std::move(fuel), config.GetCollectible(COLLECTIBLE_SPEED_BALL)); + } + + ProceduralItem& glitched = *proceduralItems.emplace_back(std::make_unique()); + bool isActive = (seed & ACTIVE_SEED_BITS) == ACTIVE_SEED_BITS; + if (isActive && (flags & PROCEDURAL_FORCE_PASSIVE)) seed &= ~ACTIVE_SEED_BITS; + else if (!isActive && (flags & PROCEDURAL_FORCE_ACTIVE)) seed |= ACTIVE_SEED_BITS; + isActive = (seed & ACTIVE_SEED_BITS) == ACTIVE_SEED_BITS; + glitched.seed = seed; + glitched.index = (int)proceduralItems.size() - 1; + glitched.item = std::make_unique(); + ItemConfig_Item& item = *glitched.item; + item.type = ITEM_PASSIVE; + item.id = -(int)proceduralItems.size(); + + RNG rng = rng_make(seed, ITEM_SHIFT_INDEX); + item.name = glitch_text_make(rng); + item.desc = glitch_text_make(rng); + + switch (rng.Next() % PICKUP_KINDS) + { + case 0: + item.addMaxHearts = pickup_roll(rng); + item.addHearts = pickup_roll(rng); + break; + case 1: item.addSoulHearts = (int)rng.RandomInt(PICKUP_ROLL); break; + case 2: item.addBlackHearts = (int)rng.RandomInt(PICKUP_ROLL); break; + case 3: item.addBombs = pickup_roll(rng); break; + case 4: item.addKeys = pickup_roll(rng); break; + case 5: + { + int first = (int)rng.RandomInt(PICKUP_ROLL); + int taken = (int)rng.RandomInt(PICKUP_ROLL); + int third = (int)rng.RandomInt(PICKUP_ROLL); + item.addCoins = (int)rng.RandomInt(PICKUP_ROLL) + (first - taken) + third; + break; + } + } + + if ((rng.Next() & 1) == 0) glitched.targetItem = config.GetCollectible((int)rng.RandomInt((uint32_t)config.collectibles.size())); + else + { + uint32_t trinket = rng.RandomInt((uint32_t)config.trinkets.size()) & TRINKET_ID_MASK; + glitched.targetItem = trinket < config.trinkets.size() ? config.trinkets[trinket].get() : nullptr; + } + if (glitched.targetItem) item.cacheFlags |= glitched.targetItem->cacheFlags; + for (int* bonus : {&item.addMaxHearts, &item.addHearts, &item.addSoulHearts, &item.addBlackHearts, &item.addBombs, + &item.addKeys, &item.addCoins}) + if (rng.Next() % PICKUP_BONUS_ODDS == 0) *bonus += (int)rng.RandomInt(PICKUP_ROLL); + item.addMaxHearts &= ~1; + + if (rng.RandomInt(item.cacheFlags != 0 || item.addMaxHearts > 0 ? STAT_ODDS : STAT_ODDS_PLAIN) == 0) + glitched_stats_roll(glitched.stats, rng); + for (int stat = 0; stat < GLITCHED_STAT_COUNT; stat++) + if (glitched.stats[stat] != 0) item.cacheFlags |= GLITCHED_STAT_CACHES[stat]; + + float budget = 0; + if (!isActive) + { + float first = rng.RandomFloat(); + float second = rng.RandomFloat(); + budget = second + first + rng.RandomFloat(); + } + else + { + item.type = ITEM_ACTIVE; + int charges = ACTIVE_CHARGES[rng.Next() % ACTIVE_CHARGES.size()]; + item.maxCharges = charges; + item.initCharge = charges; + item.chargeType = charges < TIMED_CHARGES_FROM ? CHARGE_NORMAL : CHARGE_TIMED; + float first = rng.RandomFloat(); + float chargeShare = first * (float)charges; + budget = charges < TIMED_CHARGES_FROM ? chargeShare + chargeShare + 1 : rng.RandomFloat() + first; + } + + float score = 0; + for (int roll = 0; roll < EFFECT_ROLLS && score < budget && glitched.effects.size() < EFFECTS_MAX; roll++) + { + ProceduralCondition condition = CONDITION_ACTIVE; + if (item.type != ITEM_ACTIVE) condition = PASSIVE_CONDITIONS[rng.Next() % PASSIVE_CONDITIONS.size()]; + if (!glitched.effects.empty() && (rng.Next() & CHAIN_MASK) != 0) condition = CONDITION_CHAIN; + ProceduralAction action = EFFECT_ACTIONS[rng.Next() % EFFECT_ACTIONS.size()]; + auto effect = std::make_unique(); + effect->roll_params(condition, action, rng.Next()); + bool isKept = roll == EFFECT_ROLLS - 1 || score + effect->score < budget || rng.Next() % EFFECT_KEEP_ODDS == 0; + if (!isKept) continue; + + uint32_t spawn = effect->spawnTarget; + int variant = (spawn & ANY_VARIANT) == ANY_VARIANT ? -1 : (int)(spawn & ANY_VARIANT); + if (effect->condition == CONDITION_ENTITY_SPAWN) spawnTriggerTargets.insert({spawn >> TARGET_TYPE_SHIFT, variant}); + score += effect->score; + glitched.effects.push_back(std::move(effect)); + } + log_printf(LOG_INFO, "initialized with %d effects (score: %g)\n", (int)glitched.effects.size(), (double)score); + for (std::unique_ptr& effect : glitched.effects) log_printf(LOG_INFO, "%s\n", effect->describe().c_str()); + + item.devilPrice = (short)((rng.Next() & 1) + 1); + item.shopPrice = (short)(rng.Next() % SHOP_PRICE_RANGE + 1); + if ((rng.Next() & 1) == 0) + { + std::vector& sounds = g_manager->sfxManager.sounds; + uint32_t sound = rng.RandomInt((uint32_t)sounds.size()); + bool isVoice = sound >= sounds.size() || sounds[sound].samples.empty() || + strncasecmp(sounds[sound].samples[0].path.c_str(), VOICEOVER_SFX.data(), VOICEOVER_SFX.size()) == 0; + if (!isVoice) glitched.sound = (int)sound; + } + + sprite_draw(item, rng); + g_manager->infoDisplay.add_item_entry(item, DESCRIPTION_ADD); + return item.id; +} + +// 009e0500 GlitchedItemSet::recalculate: counts the real collectibles and trinkets the held glitched items lend, each +// as often as the glitched item is held. Their stats are summed when read (glitched_stat_get). +void glitched_items_recalculate(Entity_Player& player) +{ + std::ranges::fill(player.extraCollectibleCounts, 0); + std::ranges::fill(player.extraTrinketCounts, 0); + for (auto [id, count] : player.proceduralItems) + { + ProceduralItem* glitched = g_game->proceduralItemManager.GetProceduralItem(id); + ItemConfig_Item* target = glitched ? glitched->targetItem : nullptr; + if (!target || target->type == ITEM_NULL) continue; + std::vector& counts = target->type == ITEM_TRINKET ? player.extraTrinketCounts : player.extraCollectibleCounts; + if (target->id >= 0 && target->id < (int)counts.size()) counts[target->id] += (uint8_t)count; + } +} + +// 009e03d0 Holds one more copy of a glitched item. +void glitched_item_add(Entity_Player& player, int itemId) +{ + player.proceduralItems[itemId]++; + glitched_items_recalculate(player); +} + +// 009e0450 Holds one copy less of a glitched item, forgetting it at none. +void glitched_item_remove(Entity_Player& player, int itemId) +{ + auto held = player.proceduralItems.find(itemId); + if (held != player.proceduralItems.end() && --held->second < 1) player.proceduralItems.erase(held); + glitched_items_recalculate(player); +} + +// The held glitched item lending a real collectible (any kind but a trinket) or trinket, or 0: what removing that real +// item takes away instead (parts of 0078f840 and 00771f60). +int glitched_item_copying(Entity_Player& player, ItemType kind, int id) +{ + for (auto [heldId, count] : player.proceduralItems) + { + ProceduralItem* glitched = g_game->proceduralItemManager.GetProceduralItem(heldId); + ItemConfig_Item* target = glitched ? glitched->targetItem : nullptr; + if (!target || target->id != id) continue; + if (kind == ITEM_TRINKET ? target->type == ITEM_TRINKET : target->IsCollectible()) return heldId; + } + return 0; +} + +// (00753870 to 007538c0) A stat the held glitched items add, summed in id order as GlitchedItemSet::recalculate does. +float glitched_stat_get(Entity_Player& player, GlitchedStat stat) +{ + float total = 0; + for (auto [id, count] : player.proceduralItems) + if (ProceduralItem* glitched = g_game->proceduralItemManager.GetProceduralItem(id)) total = glitched->stats[stat] + total; + return total; +} + +// 009e0680 Runs the held glitched items' effects for a trigger, in id order. Effects they set off trigger nothing. +// The original walks on from an item its effects removed. Here the walk goes on from the next id. +void glitched_items_trigger(Entity_Player& player, const ProceduralTrigger& trigger) +{ + if (isGlitchedTriggering || player.proceduralItems.empty()) return; + + isGlitchedTriggering = true; + auto held = player.proceduralItems.begin(); + while (held != player.proceduralItems.end()) + { + int id = held->first; + glitched_item_effects_run(id, player, trigger); + held = player.proceduralItems.upper_bound(id); + } + isGlitchedTriggering = false; +} + +// The trigger of a hit or kill on an entity (parts of 006d60a0 and 007a0080): at its edge facing the player, along the +// player's line to it. +void glitched_items_hit_trigger(Entity_Player& player, Entity& target, ProceduralCondition condition) +{ + Vector direction = vector_normalized(vector_sub(target.pos, player.pos)); + glitched_items_trigger(player, {vector_sub(target.pos, vector_scale(direction, target.size)), direction, &target, condition}); +} + +// 009e01b0 Runs a glitched item's effects of a trigger's condition, and each chained one right after one that fired. +void glitched_item_effects_run(int itemId, Entity_Player& player, const ProceduralTrigger& trigger) +{ + ProceduralItem* glitched = g_game->proceduralItemManager.GetProceduralItem(itemId); + if (!glitched) return; + + uint32_t lastFired = UINT32_MAX; + for (uint32_t i = 0; i < glitched->effects.size(); i++) + { + ProceduralEffect& effect = *glitched->effects[i]; + bool isChained = effect.condition == CONDITION_CHAIN && lastFired == i - 1; + if ((effect.condition == trigger.condition || isChained) && effect.execute(player, trigger)) lastFired = i; + } +} + +// Shows a glitched item's cell of the item surface on a sprite layer (parts of 007ab380 and the pedestal's sprite). +void procedural_layer_set(LayerState& layer, int itemId) +{ + layer.spriteSheet = g_game->proceduralItemManager.renderTarget; + layer.cropOffset = cell_position(itemId, PROCEDURAL_CELL_SIZE); + layer.isSpriteSheetLoaded = true; +} + +// The part of 006e7dc0 for a glitched item with a pickup sound: the sound at a pitch its seed rolls. Whether it played. +bool glitched_pickup_sound_play(int itemId) +{ + ProceduralItem* glitched = g_game->proceduralItemManager.GetProceduralItem(itemId); + if (!glitched || glitched->sound == 0) return false; + + RNG pitch = rng_make(glitched->seed, LIMIT_SHIFT_INDEX); + effect_sound_play(glitched->sound, {.pitch = pitch.RandomFloat() * PICKUP_PITCH_RANGE + PICKUP_PITCH_BASE}); + return true; +} + +// The part of 006e7dc0 for the G FUEL! item: louder sounds as the run's G FUEL! stacks grow, then a description +// rolled anew. +void g_fuel_pickup_sound_play(int itemId) +{ + int stacks = g_game->playerManager.GetGFuelCount(); + if (stacks >= G_FUEL_SPEWER_STACKS) effect_sound_play(SOUND_POWERUP_SPEWER); + if (stacks >= G_FUEL_LOUDEST_STACKS) effect_sound_play(SOUND_POWERUP_SPEWER_AMPLIFIED); + effect_sound_play(stacks < G_FUEL_LOUD_STACKS ? SOUND_THUMBSUP : SOUND_THUMBSUP_AMPLIFIED); + + uint32_t roll = Random(); + ProceduralItem* fuel = g_game->proceduralItemManager.GetProceduralItem(itemId); + if (fuel && fuel->item) fuel->item->desc = G_FUEL_DESCRIPTIONS[roll % G_FUEL_DESCRIPTIONS.size()]; } diff --git a/src/procedural_item_manager.h b/src/procedural_item_manager.h index 564465c..e7e8fe3 100644 --- a/src/procedural_item_manager.h +++ b/src/procedural_item_manager.h @@ -1,15 +1,112 @@ #pragma once +#include "item_config.h" #include "kage_graphics.h" +#include #include #include #include +#include #include #include // The glitched items' icons on the item surface: 32 pixel cells, 32 to a row, by -1 - id. constexpr int PROCEDURAL_CELLS_PER_ROW = 32; constexpr float PROCEDURAL_CELL_SIZE = 32; +// The G FUEL! seed's own glitched item, always the first. +constexpr int COLLECTIBLE_GLITCHED_GFUEL = -1; + +// What sets off a glitched item's effect (REPENTOGON's ProceduralEffect::ConditionType). +// CONDITION_CHAIN fires right after the effect before it did. +enum ProceduralCondition : int +{ + CONDITION_ACTIVE, + CONDITION_TEAR_FIRE, + CONDITION_ENEMY_HIT, + CONDITION_ENEMY_KILL, + CONDITION_DAMAGE_TAKEN, + CONDITION_ROOM_CLEAR, + CONDITION_ENTITY_SPAWN, + CONDITION_PICKUP_COLLECTED, + CONDITION_CHAIN +}; + +// What a glitched item's effect does (REPENTOGON's ProceduralEffect::ActionType). +enum ProceduralAction : int +{ + ACTION_USE_ACTIVE_ITEM, + ACTION_ADD_TEMPORARY_EFFECT, + ACTION_CONVERT_ENTITIES, + ACTION_AREA_DAMAGE, + ACTION_SPAWN_ENTITY, + ACTION_FART +}; + +// What CreateProceduralItem may force on a seed: a glitched passive or a glitched active. +enum ProceduralItemFlag : uint32_t +{ + PROCEDURAL_FORCE_PASSIVE = 1 << 1, + PROCEDURAL_FORCE_ACTIVE = 1 << 3 +}; + +// The stats a glitched item adds, in the order it keeps them (ProceduralItem +0x14 to +0x28). +enum GlitchedStat +{ + GLITCHED_DAMAGE, + GLITCHED_TEARS, + GLITCHED_SPEED, + GLITCHED_RANGE, + GLITCHED_SHOT_SPEED, + GLITCHED_LUCK, + GLITCHED_STAT_COUNT +}; + +// What set off a glitched item's effects: the condition, the entity behind it, where, and which way. +struct ProceduralTrigger +{ + Vector position{}; + Vector velocity{}; + Entity* entity = nullptr; + ProceduralCondition condition = CONDITION_ACTIVE; +}; + +// Construction (part of 009dcc70) is the default. +// One effect of a glitched item: when it fires, what it does and how strongly, and the score it counts toward the +// item's budget. Targets pack an entity as type << 16 | variant, a variant of 0xffff meaning any. +// target is the active used, the effect added, the entity spawned or converted, or the fart's subtype. +struct ProceduralEffect +{ + ColorMod color = COLOR_DEFAULT; + TearFlags tearFlags; + ProceduralCondition condition = CONDITION_ACTIVE; + ProceduralAction action = ACTION_USE_ACTIVE_ITEM; + float chanceScale = 1; + float radius = 0; + float score = 0; + float strength = 0; + uint32_t convertTarget = 0; + uint32_t seed = 0; + uint32_t spawnTarget = 0; + uint32_t target = 0; + + void roll_params(ProceduralCondition rolledCondition, ProceduralAction rolledAction, uint32_t rollSeed); + bool execute(Entity_Player& player, const ProceduralTrigger& trigger); + std::string describe(); +}; + +// Construction (009dc6e0) and destruction (part of 009dc830) are the defaults. +// A glitched item: its item config, the effects it fires, the real item whose effects it lends, the stats it adds, +// its seed and the sound it plays when taken. +struct ProceduralItem +{ + std::vector> effects; + std::unique_ptr item; + std::array stats{}; + ItemConfig_Item* targetItem = nullptr; + uint32_t seed = 0x12345678; + int index = 0; + int sound = 0; +}; // Destruction (009dc750) is the default. // The glitched items TMTRAINER makes (Game's ProceduralItemManager): the items by -1 - id, the render surfaces their @@ -26,5 +123,27 @@ public: void Init(); void items_restore(const std::vector& seeds); int CreateProceduralItem(uint32_t seed, uint32_t flags); + ProceduralItem* GetProceduralItem(int itemId); bool render_item(int itemId, const SourceQuad& source, const KAGE::Graphics::ColorQuad& quad, const KColor& color); + +private: + int item_add(std::unique_ptr item, ItemConfig_Item* target); + void sprite_draw(ItemConfig_Item& item, RNG& rng); + void collection_icon_draw(ItemConfig_Item& item, std::string_view path); }; + +// The glitched items a player holds (the original's GlitchedItemSet over Entity_Player::proceduralItems): their +// counts toward the real items they copy, their stats, the item copying a real one, and their triggers. +// Its destruction (009e0390) is the default. Its lookups (009e04b0, 009e0650) are in Entity_Player::HasCollectible +// and extra_collectible_count. +void glitched_items_recalculate(Entity_Player& player); +void glitched_item_add(Entity_Player& player, int itemId); +void glitched_item_remove(Entity_Player& player, int itemId); +int glitched_item_copying(Entity_Player& player, ItemType kind, int id); +float glitched_stat_get(Entity_Player& player, GlitchedStat stat); +void glitched_items_trigger(Entity_Player& player, const ProceduralTrigger& trigger); +void glitched_items_hit_trigger(Entity_Player& player, Entity& target, ProceduralCondition condition); +void glitched_item_effects_run(int itemId, Entity_Player& player, const ProceduralTrigger& trigger); +void procedural_layer_set(LayerState& layer, int itemId); +bool glitched_pickup_sound_play(int itemId); +void g_fuel_pickup_sound_play(int itemId); diff --git a/src/revive_player_menu.cpp b/src/revive_player_menu.cpp index 009695f..2e63573 100644 --- a/src/revive_player_menu.cpp +++ b/src/revive_player_menu.cpp @@ -21,7 +21,6 @@ constexpr float SELECTOR_ABOVE = 35; constexpr float SELECTOR_BELOW = 65; constexpr float SELECTOR_BELOW_COMPACT = 50; constexpr int CLOSE_FRAMES = 8; -constexpr int SOUND_FRAME_DELAY = 2; constexpr uint32_t PLAYER_INDEX_NONE = UINT32_MAX; // Whether an action was pressed this frame on one device, by its default bindings. @@ -115,7 +114,7 @@ void RevivePlayerMenu::Update() 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); + if (selectedPlayer != previous) menu_sound_play(SOUND_MENU_SCROLL, SOUND_DELAY); return; } @@ -123,7 +122,7 @@ void RevivePlayerMenu::Update() 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); + menu_sound_play(SOUND_HOLY, SOUND_DELAY); } state = REVIVE_MENU_CLOSING; diff --git a/src/room.cpp b/src/room.cpp index 2810e6b..5454327 100644 --- a/src/room.cpp +++ b/src/room.cpp @@ -142,7 +142,6 @@ constexpr int BOSS_ROTGUT = 87; // The backdrops LoadBackdropGraphics picks beyond the stage's own (backdrops.xml ids), and what picks them: rooms off // the map, Home's rooms by subtype, the bosses and stages with their own, and the Void's random ones. -constexpr int ROOM_DEATHMATCH_IDX = -19; constexpr int DARK_CLOSET_B_SUBTYPE = 33; constexpr int HOME_ISAACS_BEDROOM = 0; constexpr int HOME_MOMS_BEDROOM = 2; @@ -183,7 +182,6 @@ constexpr float DEAL_CHANCE_GOAT_HEAD = 66.6f; constexpr float DEAL_RECENT_SCALE = 0.25f; constexpr float DEAL_LAST_SCALE = 0.5f; constexpr uint32_t GREED_DEAL_WAVE = 11; -constexpr int COLLECTIBLE_GOAT_HEAD = 215; // The doors of a cleared boss room: what unlocks them and the stages they open on, the secret exit kinds, the deal // door's jingles and Greed's deal door slot, Mom's parts the Boss Rush door clears, and the run flags they set. @@ -199,7 +197,6 @@ constexpr uint64_t GAME_STATE_DEVILROOM_SPAWNED_BITS = 1ull << 5; // The dust a door throws as it appears: how many puffs at least, how fast and far, how they spin and how long they // last. constexpr int DOOR_DUST_MIN = 5; -constexpr float DUST_SPIN_RANGE = 10; constexpr uint32_t DUST_TIMEOUT_RANGE = 10; constexpr int DUST_TIMEOUT_MIN = 30; @@ -232,8 +229,6 @@ constexpr float RAIN_RADIUS_MIN = 20; constexpr float RAIN_RADIUS_RANGE = 60; constexpr float RAIN_FADE = 0.02f; constexpr float RAIN_INTENSITY_MIN = 0.01f; -constexpr float RAIN_PI = 3.14f; -constexpr float QUARTER_TURN = 1.5707964f; // The screen color: how much secret rooms wash it out, pitch black rooms brighten it and the Mines' lava tints it, // and how fast it fades. @@ -250,7 +245,6 @@ constexpr int COLLECTIBLE_ISAACS_TOMB = 701; constexpr int COLLECTIBLE_CARD_READING = 660; constexpr int SEED_EFFECT_PRE_ITEMS = 79; constexpr int SEED_EFFECT_NO_LAST_BOSS_DOORS = 71; -constexpr int SPECIAL_DAILY_SURPRISE_MINIBOSS = 17; constexpr int ACHIEVEMENT_STORE_KEY = 379; constexpr int EVENT_ARCADES_VISITED = 9; constexpr int SHOP_VISITS_FOR_ACHIEVEMENT = 5; @@ -420,10 +414,11 @@ void Room::Init(RoomConfig_Room& config, RoomDescriptor& roomDescriptor) outputGroupGridIndices[group].clear(); outputGroupCallbacks[group].clear(); } - // The original empties these lists in every room. DeathmatchManager::Reset gives every run a type, but only a - // versus arena's spawn points fill them, so outside a match they are already empty. - if (g_game->deathmatchManager.is_active()) - reconstruction_missing("Room::Init 007f2800: the versus spawn lists of DeathmatchTypeBase (+0x10, +0x18)"); + if (DeathmatchTypeBase* versus = g_game->deathmatchManager.type.get()) + { + versus->itemSpawnPoints.clear(); + versus->spawnPoints.clear(); + } waterCurrent = vector_make(0, 0); unknown73f0 = 0; @@ -468,7 +463,7 @@ void Room::Init(RoomConfig_Room& config, RoomDescriptor& roomDescriptor) if (roomType == ROOM_BOSS) boss_ids_init(); isSurpriseMiniboss = descriptor->flags & ROOM_DESCRIPTOR_FLAG_SURPRISE_MINIBOSS; - if (g_game->dailyChallenge.specialDailyId == SPECIAL_DAILY_SURPRISE_MINIBOSS && isSurpriseMiniboss) + if (g_game->dailyChallenge.specialDailyId == SPECIAL_DAILY_DECEMBER_5 && isSurpriseMiniboss) g_game->gameStateFlags |= GAME_STATE_SURPRISE_MINIBOSS_SEEN; isTriggerPressurePlates = false; update_bounds(true); @@ -705,8 +700,8 @@ void Room::init_shop_level() } // What the layout's spawns say about the room before anything spawns: water, a dump, the Heretic or Raglich, the -// pitch black, cursed mist and alternate backdrop flags, and a water current. Each spawn draws its entry from the -// spawn seed, as init_spawns draws them again. +// pitch black, cursed mist and alternate backdrop flags, a water current, and the versus arena's spawn points. Each +// spawn draws its entry from the spawn seed, as init_spawns draws them again. SpawnFlags Room::init_spawn_flags(RoomConfig_Room& config) { SpawnFlags flags; @@ -746,7 +741,11 @@ SpawnFlags Room::init_spawn_flags(RoomConfig_Room& config) if (entry.variant == ROOM_CONFIG_PITCH_BLACK) descriptor->flags |= ROOM_DESCRIPTOR_FLAG_PITCH_BLACK; else if (entry.variant == ROOM_CONFIG_CURSED_MIST) descriptor->flags |= ROOM_DESCRIPTOR_FLAG_CURSED_MIST; else if (entry.variant == ROOM_CONFIG_VERSUS_SPAWN && g_game->deathmatchManager.type) - reconstruction_missing("Room::Init 007f2800: a 970.4 versus spawn point (DeathmatchTypeBase lists)"); + { + Vector point = GetGridPosition(spawn.x + 1 + (spawn.y + 1) * gridWidth); + g_game->deathmatchManager.type->itemSpawnPoints.push_back(point); + g_game->deathmatchManager.type->spawnPoints.push_back(point); + } else if (entry.variant == ROOM_CONFIG_WATER) { if (entry.subtype == WATER_SUBTYPE_DRY) flags.isDry = true; @@ -2196,7 +2195,7 @@ float Room::GetDevilRoomChance() if (game.isDevilRoomDisabled) chance = 0; if (is_owned(COLLECTIBLE_GOAT_HEAD) || temporaryEffects.HasCollectibleEffect(COLLECTIBLE_GOAT_HEAD)) chance = DEAL_CHANCE_GOAT_HEAD; - if (game.dailyChallenge.specialDailyId == SPECIAL_DAILY_SURPRISE_MINIBOSS && + if (game.dailyChallenge.specialDailyId == SPECIAL_DAILY_DECEMBER_5 && !(game.gameStateFlags & GAME_STATE_SURPRISE_MINIBOSS_SEEN)) chance = 1; if (is_owned(COLLECTIBLE_EUCHARIST)) chance = 1; @@ -2820,7 +2819,7 @@ void Room::update_ambient_spawns() for (int i = 0; i < numRainSpawners; i++) { RainSpawner& spawner = rainSpawners[i]; - float angle = random_unit() * RAIN_PI; + float angle = random_unit() * PI_ROUGH; angle += angle; float radius = random_unit(); float along = std::cos(angle) * radius; @@ -2967,7 +2966,7 @@ static void door_dust_spawn(Room& room, GridEntity_Door& door, const DoorDust& d Vector velocity = isDeal ? vector_make(side * out.y + out.x * speed, side * -out.x + out.y * speed) : vector_make(speed * out.x * DUST_SPEED + across.x * side, speed * out.y * DUST_SPEED + across.y * side); - float angle = random_unit() * RAIN_PI; + float angle = random_unit() * PI_ROUGH; angle += angle; float radius = random_unit() * (isDeal ? DUST_RADIUS : 1); float scale = isDeal ? 1 : DUST_RADIUS; @@ -2980,7 +2979,7 @@ static void door_dust_spawn(Room& room, GridEntity_Door& door, const DoorDust& d auto* puff = static_cast(game_spawn(spawn, POOL_OVERWRITE)); Vector offset = vector_make(puff->pos.x - doorPosition.x, puff->pos.y - doorPosition.y); bool isBehind = isDeal ? offset.x * out.y + offset.y * -out.x < 0 : offset.x * out.x + offset.y * out.y < 0; - float spin = random_unit() * DUST_SPIN_RANGE + DUST_SPIN_MIN; + float spin = random_between(DUST_SPIN_MIN, DUST_SPIN_RANGE); // The secret exit's spin is only ever 1 or -1, its random speed lost in the original. if (!isDeal) puff->rotation = spin * (float)isBehind == 0 ? 1.0f : -1.0f; else puff->rotation = spin * (isBehind ? -1.0f : 1.0f); @@ -3401,7 +3400,6 @@ void Room::UpdateRedKey() return; } - constexpr float DOOR_ANGLES[4] = {-90, 0, 90, 180}; bool isLastBossRoom = descriptor->data->type == ROOM_BOSS && descriptor->listIndex == game.lastBossRoomListIdx; if (isLastBossRoom || descriptor->gridIndex < 0) return; diff --git a/src/room.h b/src/room.h index 654e704..d8ff2cd 100644 --- a/src/room.h +++ b/src/room.h @@ -383,6 +383,7 @@ public: void Render(); void render_lighting(); void render_debug_grid_values(Vector offset); + void render_debug_grid_indices(Vector offset); void update_bounds(bool isFromGridSize); void LoadBackdropGraphics(); diff --git a/src/room_clear.cpp b/src/room_clear.cpp index 423cf86..580bd60 100644 --- a/src/room_clear.cpp +++ b/src/room_clear.cpp @@ -534,7 +534,7 @@ Entity_Pickup* Room::spawn_options_alternative(Entity_Pickup& pickup) Vector origin = pickup.pos; RNG angleRng = {rng.Next(), 3, 1, 14}; - float angle = angleRng.RandomFloat() * RANDOM_HALF_TURN * 2; + float angle = angleRng.RandomFloat() * PI_ROUGH * 2; Vector offset = vector_make(std::cos(angle) * OPTIONS_SPREAD, std::sin(angle) * OPTIONS_SPREAD); auto* twin = static_cast(g_game->Spawn( {.position = vector_add(origin, offset), .type = ENTITY_PICKUP, .variant = variant, .seed = rng.Next()})); @@ -1347,7 +1347,7 @@ static void ultra_greed_award_spawn(Room& room, ClearAward& award) } Entity_Player* player = game.playerManager.get_main_player(0); - float angle = random_unit() * RANDOM_HALF_TURN * 2; + float angle = random_unit() * PI_ROUGH * 2; Vector spot = room.GetClampedPosition( vector_add(player->pos, vector_make(std::cos(angle) * GREED_MACHINE_REACH, std::sin(angle) * GREED_MACHINE_REACH)), GRID_CELL_SIZE); @@ -1731,9 +1731,7 @@ void Entity_Player::TriggerRoomClear() if (isTaintedLazarus && (backupPlayer || twinPlayer) && controlsCooldown <= 0 && !hasCurseMistEffect) tainted_lazarus_flip(*this); azazels_stump_update(*this); - if (!proceduralItems.empty()) - reconstruction_missing("Entity_Player::TriggerRoomClear 007a8fd0: the TMTRAINER clear triggers " - "(trigger_set_dispatch 009e0680)"); + glitched_items_trigger(*this, {pos, {}, nullptr, CONDITION_ROOM_CLEAR}); for (size_t i = 0; i < pendingWisps.size(); i++) AddWisp(pendingWisps[i], pos, false, false); pendingWisps.clear(); diff --git a/src/room_config.cpp b/src/room_config.cpp index 313fd80..aebd20e 100644 --- a/src/room_config.cpp +++ b/src/room_config.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -502,10 +503,183 @@ void RoomConfig::ResetRoomWeights(int stageId, RoomMode mode) for (RoomConfig_Room& room : set.configs) room.weight = room.initialWeight; } -// (00829710, 00829af0) Reads one room from an XML room file, for the --load-room start option. -RoomConfig_Room RoomConfig::LoadRoomFromXmlFile(std::string_view) +// An XML attribute value or name as JSON string text: its entities decoded, quotes, backslashes and controls escaped. +static std::string xml_value_json(std::string_view text) { - reconstruction_missing("RoomConfig::LoadRoomFromXmlFile 00829710 (RoomConfigRoom::ParseXml 00829af0)"); + constexpr std::array, 5> ENTITIES = { + {{"<", '<'}, {">", '>'}, {"&", '&'}, {""", '"'}, {"'", '\''}}}; + std::string json = "\""; + + for (size_t i = 0; i < text.size(); i++) + { + char letter = text[i]; + for (auto [entity, decoded] : ENTITIES) + { + if (!text.substr(i).starts_with(entity)) continue; + letter = decoded; + i += entity.size() - 1; + break; + } + if (letter == '"' || letter == '\\') json += '\\'; + if ((unsigned char)letter < ' ') json += std::format("\\u{:04x}", (int)letter); + else json += letter; + } + return json + '"'; +} + +// An XML document as the import tool's JSON (tag, attrs and children, under #document), for a file nothing converted. +// Text, comments and declarations are left out, as no room file holds text. +static std::string xml_json_get(std::string_view text) +{ + constexpr std::string_view NAME_END = " \t\r\n/>"; + std::string json = "{\"tag\":\"#document\",\"attrs\":{},\"children\":["; + std::vector childCounts = {0}; + size_t pos = 0; + + while ((pos = text.find('<', pos)) != std::string_view::npos && pos + 1 < text.size()) + { + std::string_view rest = text.substr(pos); + size_t end = rest.starts_with("", pos) : text.find('>', pos); + if (rest[1] == '?' || rest[1] == '!' || end == std::string_view::npos) + { + pos = end; + continue; + } + if (rest[1] == '/') + { + if (childCounts.size() > 1) json += "]}"; + if (childCounts.size() > 1) childCounts.pop_back(); + pos = end; + continue; + } + + size_t nameEnd = text.find_first_of(NAME_END, pos + 1); + json += childCounts.back()++ ? "," : ""; + json += "{\"tag\":" + xml_value_json(text.substr(pos + 1, nameEnd - pos - 1)) + ",\"attrs\":{"; + pos = nameEnd; + for (bool isFirst = true;; isFirst = false) + { + pos = text.find_first_not_of(" \t\r\n", pos); + if (pos == std::string_view::npos || text[pos] == '/' || text[pos] == '>') break; + size_t equals = text.find('=', pos); + size_t open = text.find_first_of("\"'", equals); + size_t close = open == std::string_view::npos ? open : text.find(text[open], open + 1); + if (close == std::string_view::npos) break; + + std::string_view name = text.substr(pos, text.find_last_not_of(" \t\r\n=", equals) + 1 - pos); + json += (isFirst ? "" : ",") + xml_value_json(name) + ":" + + xml_value_json(text.substr(open + 1, close - open - 1)); + pos = close + 1; + } + json += "},\"children\":["; + pos = text.find('>', pos); + if (pos == std::string_view::npos) break; + if (text[pos - 1] == '/') json += "]}"; + else childCounts.push_back(0); + } + for (size_t open = childCounts.size(); open > 1; open--) json += "]}"; + return json + "]}"; +} + +// An attribute as rapidxml handed it to atoi: its text, or empty when the element lacks it. +static int attr_int(DataNode node, std::string_view name) +{ + return std::atoi(std::string(attr_find(node, name).value_or("")).c_str()); +} + +// An attribute as atof read it, 0 when the element lacks it. +static float attr_float(DataNode node, std::string_view name) +{ + return (float)std::atof(std::string(attr_find(node, name).value_or("")).c_str()); +} + +// 00829af0 (RoomConfigRoom::ParseXml) Reads a room element: its attributes, then for a typed room the doors that +// exist and the spawns sorted by row then column, marking quest doors (970.2 on a door) and pressure plates (4500.0). +// A door's coordinates and whether it exists carry over from the door before when it lacks them, as the original's +// locals do, and an entity's fields from the entity before. The original reads uninitialized fields for a room +// without them. Here those keep RoomConfig_Room's defaults. +static void room_parse(DataNode node, RoomConfig_Room& room) +{ + room.type = attr_int(node, "type"); + room.variant = room.originalVariant = attr_int(node, "variant"); + room.subtype = attr_int(node, "subtype"); + room.name = attr_find(node, "name").value_or(""); + room.difficulty = attr_int(node, "difficulty"); + room.weight = room.initialWeight = attr_float(node, "weight"); + room.flags = (uint32_t)attr_int(node, "flags"); + if (attr_find(node, "width")) room.width = (uint8_t)attr_int(node, "width"); + if (attr_find(node, "height")) room.height = (uint8_t)attr_int(node, "height"); + if (attr_find(node, "shape")) room.shape = (RoomShape)attr_int(node, "shape"); + if (room.type == 0) return; + + short doorX = 0; + short doorY = 0; + bool isDoorExisting = false; + RoomEntry entry; + + for (DataNode child : node_children(node)) + { + std::string_view tag = node_tag(child); + if (tag == "door") + { + if (attr_find(child, "x")) doorX = (short)attr_int(child, "x"); + if (attr_find(child, "y")) doorY = (short)attr_int(child, "y"); + if (auto text = attr_find(child, "exists")) + isDoorExisting = *text == "true" || *text == "True" || attr_int(child, "exists") != 0; + + int slot = isDoorExisting ? RoomConfig::get_door_from_position(doorX, doorY, room.shape) : DOOR_NONE; + if (slot != DOOR_NONE) room.doors |= 1u << slot; + } + if (tag != "spawn") continue; + + RoomSpawn& spawn = room.spawns.emplace_back(); + spawn.x = (short)attr_int(child, "x"); + spawn.y = (short)attr_int(child, "y"); + for (DataNode entity : node_children(child)) + { + if (node_tag(entity) != "entity") continue; + if (attr_find(entity, "type")) entry.type = (uint32_t)attr_int(entity, "type"); + if (attr_find(entity, "variant")) entry.variant = (uint16_t)attr_int(entity, "variant"); + if (attr_find(entity, "subtype")) entry.subtype = (uint16_t)attr_int(entity, "subtype"); + if (attr_find(entity, "weight")) entry.weight = attr_float(entity, "weight"); + if (attr_find(entity, "weight")) spawn.sumWeights += entry.weight; + + int slot = RoomConfig::get_door_from_position(spawn.x, spawn.y, room.shape); + bool isQuestDoor = entry.type == ENTITY_ENVIRONMENT && entry.variant == QUEST_DOOR_VARIANT; + if (isQuestDoor && slot != DOOR_NONE) room.questDoors |= 1u << slot; + else if (entry.type == GRID_SPAWN_PRESSURE_PLATE && entry.variant == 0) + room.flags |= ROOM_FLAG_PRESSURE_PLATE; + spawn.entries.push_back(entry); + } + } + std::ranges::sort(room.spawns, [](const RoomSpawn& a, const RoomSpawn& b) + { return a.y < b.y || (a.y == b.y && a.x < b.x); }); +} + +// 00829710 Reads the room element of a room file, for the --load-room start option: its converted JSON through the +// resources when the import tool converted it, else the XML file itself. An unreadable file gives an empty room, as +// does a file without a room element, where the original crashes. +RoomConfig_Room RoomConfig::LoadRoomFromXmlFile(std::string_view path) +{ + RoomConfig_Room room; + Data data; + + data_load(data, path); + if (!data.isLoaded) + { + std::ifstream file{std::string(path), std::ios::binary}; + if (!file) + { + log_printf(LOG_INFO, "[error] Could not open %s\n", std::string(path).c_str()); + return room; + } + std::string text{std::istreambuf_iterator(file), std::istreambuf_iterator()}; + data.isLoaded = data.parser.parse(xml_json_get(text)).get(data.root) == simdjson::SUCCESS; + } + + std::optional root = root_find(data, "room"); + if (root) room_parse(*root, room); + return room; } // The room set a lookup reads, loaded first when it is not. diff --git a/src/room_lighting.cpp b/src/room_lighting.cpp index 819d780..589e1e1 100644 --- a/src/room_lighting.cpp +++ b/src/room_lighting.cpp @@ -167,7 +167,7 @@ Vector RandomVector(uint32_t seed) seed ^= seed >> 3; seed ^= seed << 1; seed ^= seed >> 14; - float angle = (float)seed * RANDOM_UNIT_SCALE * RANDOM_HALF_TURN; + float angle = (float)seed * RANDOM_UNIT_SCALE * PI_ROUGH; angle += angle; return vector_make(std::cos(angle), std::sin(angle)); } diff --git a/src/room_render.cpp b/src/room_render.cpp index a0225d1..130c070 100644 --- a/src/room_render.cpp +++ b/src/room_render.cpp @@ -20,12 +20,21 @@ #include #include #include +#include // The debug grid views: half a cell's outline on screen, where a cell's text starts, and their faint yellow. constexpr float DEBUG_CELL_HALF = 13; constexpr float DEBUG_TEXT_LEFT = 12; constexpr float DEBUG_TEXT_UP = 10; constexpr KColor DEBUG_GRID_COLOR = kcolor_rgba(1, 1, 0, 0.2f); +// The debug room info line: the room types' names, its color and its height over the screen's bottom. +constexpr std::array ROOM_TYPE_NAMES = { + "Null", "Default", "Shop", "Error", "Treasure", "Boss", "Miniboss", "Secret", + "SSecret", "Arcade", "Curse", "Ambush", "Library", "Sacrifice", "Devil", "Angel", + "Dungeon", "Bossrush", "Isaac", "Barren", "Chest", "Dice", "Market", "Exit", + "Planetarium", "TeleEntrance", "TeleExit", "SecretExit", "Blue", "USecret"}; +constexpr KColor ROOM_INFO_COLOR = kcolor_rgba(1, 1, 1, 128.0f / 255); +constexpr float ROOM_INFO_RAISE = 12; // The images rooms draw from, and the texel settings init_room_render_surfaces gives some of them. constexpr const char* ASH_MASK_PNG = "gfx/ash_mask.png"; @@ -243,7 +252,6 @@ constexpr float CAUSTICS_TURN_SPEED = 0.01f; constexpr float CAUSTICS_DRIFT = 0.1f; constexpr float CAUSTICS_FLOOD_PITS = 30; constexpr float CORPSE_CAUSTICS_GREEN_BLUE = 0.3f; -constexpr float CAUSTICS_DEGREES_TO_RADIANS = 0.017453292f; // -1, 0 or 1 by the sign of a number. static float sign_get(float value) @@ -563,7 +571,7 @@ static void water_render(Room& room, WaterPass) float scale = (float)std::floor(perimeter / textureWidth + 0.5f) * textureWidth / perimeter; float edge = scale * CAUSTICS_EDGE; float scroll = (float)game.frameCount * CAUSTICS_SCROLL_SPEED; - float turn = (float)game.frameCount * CAUSTICS_TURN_SPEED * CAUSTICS_DEGREES_TO_RADIANS; + float turn = (float)game.frameCount * CAUSTICS_TURN_SPEED * DEGREES_TO_RADIANS; float drift = scroll * CAUSTICS_DRIFT; KColor light = room.fxLayers.fxParams.lightColor; bool isCorpse = room.backdropType == BACKDROP_CORPSE3; @@ -1444,13 +1452,65 @@ void Room::render_debug_grid_values(Vector offset) } } +// 0081f130 The debug view of the grid indices (debug 11): the grid's lines in faint yellow, and over each cell its +// index above its column and row. +void Room::render_debug_grid_indices(Vector offset) +{ + Font& font = g_manager->font2_TeamMeatEx12; + Vector halfCell = vector_make(GRID_CELL_SIZE / 2, GRID_CELL_SIZE / 2); + float cellSize = DEBUG_CELL_HALF * 2; + auto cornerGet = [&](int gridIndex) + { + Vector corner = vector_sub(GetGridPosition(gridIndex), halfCell); + return vector_add(render_position_get(corner, RENDER_SNAPPED), offset); + }; + + for (int column = 0; column < gridWidth; column++) + { + Vector from = cornerGet(column); + Vector to = vector_make(from.x, from.y + (float)gridHeight * cellSize); + render_color_quad(from, to, DEBUG_GRID_COLOR, DEBUG_GRID_COLOR, 1); + } + for (int row = 0; row < gridHeight; row++) + { + Vector from = cornerGet(row * gridWidth); + Vector to = vector_make(from.x + (float)gridWidth * cellSize, from.y); + render_color_quad(from, to, DEBUG_GRID_COLOR, DEBUG_GRID_COLOR, 1); + } + for (int i = 0; i < gridWidth * gridHeight; i++) + { + Vector cell = vector_add(render_position_get(GetGridPosition(i), RENDER_SNAPPED), offset); + FontSettings settings; + font.DrawString(std::to_string(i), vector_make(cell.x - DEBUG_CELL_HALF, cell.y - DEBUG_CELL_HALF), + vector_make(1, 1), DEBUG_GRID_COLOR, settings); + font.DrawString(std::format("{},{}", i % gridWidth, i / gridWidth), + vector_make(cell.x - DEBUG_CELL_HALF, cell.y), vector_make(1, 1), DEBUG_GRID_COLOR, settings); + } +} + +// The debug room info (debug 5): the stage's English name, the room's type, variant, name and group, centered over +// the screen's bottom. +static void room_info_render(Room& room) +{ + RoomConfig_Room& config = *room.descriptor->data; + Font& font = g_manager->font5_terminus8; + std::string stage = g_game->roomConfig.stages[config.stageId].GetDisplayName(LANGUAGE_ENGLISH); + std::string text = std::format("{} {} {} {} (group {})", stage, ROOM_TYPE_NAMES[room.roomType], config.variant, + config.name, room.descriptor->group); + FontSettings settings; + float x = g_screenWidth * 0.5f - (float)((uint32_t)font.GetStringWidth(text) >> 1); + + font.DrawString(text, vector_make(x, g_screenHeight - ROOM_INFO_RAISE), vector_make(1, 1), ROOM_INFO_COLOR, + settings); +} + // 0080f200 Draws the room: the behind layers, the floor with its entities, the walls, rails and flat grid entities, // the doors, shading and shadows, the players' glows, the grid entities and entities by depth, the players' extra // bodies and Night Lights, the lighting overlay, the foreground and overlay layers, and the Ashpit's dust. Retro // Vision or the game's pixelation timer pixelate the sprites meanwhile, and Dataminer garbles them. // The room draws through effect surfaces, each drawn back onto the screen through its shader: the mirror world's -// (flipped), dizziness, the shockwaves' ripples, Utero's water overlay and the Beast's heat wave. The water surface and -// the debug overlays are not reconstructed yet. +// (flipped), dizziness, the shockwaves' ripples, Utero's water overlay and the Beast's heat wave, then the debug +// overlays: the grid's path values and indices, and the room info. void Room::Render() { KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager; @@ -1498,7 +1558,7 @@ void Room::Render() for (Entity_Player* extra : game.playerManager.extraPlayers) extra->Render(renderScrollOffset); night_lights_render(*this); if (game.debugFlags & DEBUG_GRID_VALUES) render_debug_grid_values(renderScrollOffset); - if (game.debugFlags & DEBUG_GRID_INDICES) reconstruction_missing("Room::render_debug_grid_indices 0081f130"); + if (game.debugFlags & DEBUG_GRID_INDICES) render_debug_grid_indices(renderScrollOffset); shader_select(COLOR_OFFSET_SHADER); if (render.isLightingEnabled) lighting_overlay_render(*this); @@ -1513,7 +1573,7 @@ void Room::Render() spriteShaderParams.pixelationAmount = 0; graphics.shader_default_set(); - if (game.debugFlags & DEBUG_ROOM_INFO) reconstruction_missing("Room::Render 0080f200: the room info text"); + if (game.debugFlags & DEBUG_ROOM_INFO) room_info_render(*this); } // The glow of a lava pit: in a flooded Mines room orange as hot as its lava, drawn plainly. In a flooded shaft it is diff --git a/src/room_special.cpp b/src/room_special.cpp index e28dcee..74a2cc8 100644 --- a/src/room_special.cpp +++ b/src/room_special.cpp @@ -865,9 +865,7 @@ constexpr int KNIFE_SPLASH_SUBTYPE = 10; constexpr float POOF_DEPTH = 5; constexpr int DUST_MIN = 3; constexpr float DUST_SIDE_SPEED = 2.5f; -constexpr float DUST_SPIN = 10; constexpr int DUST_LIFE_MIN = 15; -constexpr float HALF_TURN = 3.14f; constexpr ColorMod BLUE_KEY_COLOR = {{1, 1, 1, 1}, {0.4f, 0.6f, 1, 1}, {0, 0, 0}}; // Throws a door's debris: a few particles of a kind from the door's cell. @@ -1022,7 +1020,7 @@ void GridEntity_Door::SpawnDust() float inward = random_unit() * DUST_SPEED; float along = random_unit() * DUST_SPEED - DUST_SIDE_SPEED; Vector velocity = vector_make(-along * facing.y - inward * facing.x, along * facing.x - inward * facing.y); - float angle = random_unit() * HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float radius = random_unit() * DUST_RADIUS; Vector position = vector_make(std::cos(angle) * radius + cell.x, std::sin(angle) * radius + cell.y); @@ -1033,7 +1031,7 @@ void GridEntity_Door::SpawnDust() .variant = EFFECT_DUST_CLOUD, .seed = seed})); float side = (dust->pos.x - cell.x) * -facing.y + (dust->pos.y - cell.y) * facing.x < 0 ? -1.0f : 1.0f; - dust->rotation = (random_unit() * DUST_SPIN + DUST_SPIN_MIN) * side; + dust->rotation = (random_between(DUST_SPIN_MIN, DUST_SPIN_RANGE)) * side; int life = (int)(Random() % DUST_LIFE_MIN) + DUST_LIFE_MIN; dust->timeout = life; dust->lifespan = life; diff --git a/src/room_transition.cpp b/src/room_transition.cpp index 1abdc5a..a34908a 100644 --- a/src/room_transition.cpp +++ b/src/room_transition.cpp @@ -197,7 +197,7 @@ static void teleporter_arrival_place(Room& room, int target) for (Entity_Player* player : players.playerList) { if (player == traveller) continue; - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float x = std::cos(angle) * TELEPORTER_SCATTER + at.x; float y = std::sin(angle) * TELEPORTER_SCATTER + at.y; @@ -229,7 +229,7 @@ static void death_certificate_players_place(Room& room) if (!player) continue; if (placed++ != 0) { - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; spot = vector_add(arrival, vector_make(std::cos(angle) * ARRIVAL_SCATTER, std::sin(angle) * ARRIVAL_SCATTER)); } @@ -428,7 +428,7 @@ void RoomTransition::start_update(Entity_NPC* minecartNpc) idlePlayer->moveToTarget = slowestPlayer->moveToTarget; if (animation == TRANSITION_MINECART && minecartNpc) { - float angle = random_unit() * RANDOM_HALF_TURN * 2; + float angle = random_unit() * PI_ROUGH * 2; float reach = random_unit() * MINECART_JITTER; idlePlayer->moveToTarget = vector_make(reach * std::cos(angle) + minecartNpc->targetPosition.x, reach * std::sin(angle) + minecartNpc->targetPosition.y); diff --git a/src/room_update.cpp b/src/room_update.cpp index 360dcc5..dbe9d86 100644 --- a/src/room_update.cpp +++ b/src/room_update.cpp @@ -195,7 +195,6 @@ constexpr int CURRENT_SPLASH_MIN = 2; constexpr float CURRENT_SPLASH_SPEED_MIN = 4; constexpr float CURRENT_SPLASH_SPEED_RANGE = 6; constexpr float CURRENT_WALL_BACK = 0.54f; -constexpr float CURRENT_HALF_TURN = 3.14f; // Where a current's splashes start: around a wading entity (its spawner), or past a wall. struct CurrentSplash @@ -845,14 +844,14 @@ static void current_splashes_spawn(Room& room, const CurrentSplash& splash) Vector position = splash.position; if (splash.wader) { - float angle = random_unit() * CURRENT_HALF_TURN * 2; + float angle = random_unit() * PI_ROUGH * 2; float reach = random_unit(); position = vector_make(std::cos(angle) * splash.wader->size * reach + position.x, std::sin(angle) * splash.wader->size * reach + position.y); } uint32_t seed = Random(); float speed = random_unit() * CURRENT_SPLASH_SPEED_RANGE + CURRENT_SPLASH_SPEED_MIN; - float angle = random_unit() * CURRENT_HALF_TURN * 2; + float angle = random_unit() * PI_ROUGH * 2; Vector velocity = vector_make(std::cos(angle) + current.x * speed, std::sin(angle) + current.y * speed); if (!splash.wader) { @@ -927,7 +926,7 @@ static void walls_bleed_update(Room& room) else if (along >= width) position = vector_make(room.bottomRightPos.x, along + room.topLeftPos.y - width); uint32_t seed = Random(); - float angle = random_unit() * 3.14f * 2; + float angle = random_unit() * PI_ROUGH * 2; Vector velocity = vector_make(std::cos(angle) * BLOOD_SPEED, std::sin(angle) * BLOOD_SPEED); Entity* blood = entity_spawn(ENTITY_EFFECT, EFFECT_BLOOD_PARTICLE, position, velocity, seed); if (room.backdropType == BACKDROP_CORPSE || room.backdropType == BACKDROP_CORPSE2 || @@ -1025,7 +1024,6 @@ static void home_crawlspace_update(Room& room) constexpr int LAVA_SLOW_FRAMES = 4; constexpr float LAVA_SLOW = 0.6f; constexpr ColorMod LAVA_SLOW_COLOR = {{1, 1, 1.3f, 1}, {0, 0, 0, 0}, {0.15686275f, 0.15686275f, 0.15686275f}}; - constexpr int LAVA_HIT_COUNTDOWN = 30; constexpr float HOME_EMBER_RISE = -2.88f; constexpr float HOME_EMBER_DRIFT = 0.4f; constexpr float HOME_EMBER_TOP = 40; @@ -1043,7 +1041,7 @@ static void home_crawlspace_update(Room& room) { if (player->pos.y + player->size < lava || player->entityCollisionClass == ENTCOLL_NONE) continue; player->AddSlowing(EntityRef(), LAVA_SLOW_FRAMES, LAVA_SLOW, LAVA_SLOW_COLOR, false); - player->TakeDamage(1, DAMAGE_FIRE, EntityRef(), LAVA_HIT_COUNTDOWN); + player->TakeDamage(1, DAMAGE_FIRE, EntityRef(), HIT_COUNTDOWN); } if ((Random() & 1) != 0) return; diff --git a/src/score_sheet.cpp b/src/score_sheet.cpp index 510a306..8bd3b8d 100644 --- a/src/score_sheet.cpp +++ b/src/score_sheet.cpp @@ -204,10 +204,23 @@ void ScoreSheet::AddFinishedStage(const StageVisit& visit, int time) // The score's players: the first one with its sub player, its twin with that one's sub player, and its backup player // with that one's sub player. +// The first is null when there is no player, and the others are then left out. static std::vector score_players_get() { - reconstruction_missing("ScoreSheet::Calculate 009e5d90: the first player's sub, twin and backup players, which " - "classes.h holds as 32-bit values until Entity_Player is taken over"); + std::vector players = {g_game->GetPlayer(0)}; + Entity_Player* first = players.front(); + if (!first) return players; + + auto pairAdd = [&](Entity_Player* player) + { + if (!player) return; + players.push_back(player); + if (player->subPlayer) players.push_back(player->subPlayer); + }; + if (first->subPlayer) players.push_back(first->subPlayer); + pairAdd(first->twin_get()); + pairAdd(first->backupPlayer); + return players; } // The penalty that grows from nothing toward 80% of a score as an amount passes its allowance, rounded up. @@ -226,9 +239,9 @@ void ScoreSheet::Calculate() if (!players.front()) return; int stage = (int)game.stage; - int stagesDone = runEnding == RUN_ENDING_NONE || runEnding == RUN_ENDING_DIE ? stage - 1 : stage; + int stagesDone = runEnding == ENDING_NONE || runEnding == ENDING_DEATH ? stage - 1 : stage; int parStages = std::min(stagesDone, PAR_STAGE_COUNT); - bool isPastWomb = stage > STAGE_WOMB_END || runEnding == RUN_ENDING_SATAN || runEnding == RUN_ENDING_ISAAC; + bool isPastWomb = stage > STAGE_WOMB_END || runEnding == ENDING_SATAN || runEnding == ENDING_ISAAC; stageBonus = 0; for (StageVisit& visit : finishedStages) @@ -237,14 +250,14 @@ void ScoreSheet::Calculate() stageBonus += visit.isAscent ? ASCENT_STAGE_BONUS : isScored ? STAGE_BONUSES[visit.stage] : 0; } - lambBonus = runEnding == RUN_ENDING_LAMB ? CHEST_BONUS : 0; - blueBabyBonus = runEnding == RUN_ENDING_BLUE_BABY ? CHEST_BONUS : 0; - megaSatanBonus = runEnding == RUN_ENDING_MEGA_SATAN ? FINAL_BOSS_BONUS : 0; - motherBonus = runEnding == RUN_ENDING_MOTHER ? FINAL_BOSS_BONUS : 0; + lambBonus = runEnding == ENDING_LAMB ? CHEST_BONUS : 0; + blueBabyBonus = runEnding == ENDING_BLUE_BABY ? CHEST_BONUS : 0; + megaSatanBonus = runEnding == ENDING_MEGA_SATAN ? FINAL_BOSS_BONUS : 0; + motherBonus = runEnding == ENDING_MOTHER ? FINAL_BOSS_BONUS : 0; rushBonus = (game.GetStateFlag(GAME_STATE_BLUEWOMB_DONE) ? BLUE_WOMB_BONUS : 0) + (game.GetStateFlag(GAME_STATE_BOSSRUSH_DONE) ? BOSS_RUSH_BONUS : 0); - deliriumBonus = runEnding == RUN_ENDING_DELIRIUM ? FINAL_BOSS_BONUS : 0; - beastBonus = runEnding == RUN_ENDING_BEAST ? FINAL_BOSS_BONUS : 0; + deliriumBonus = runEnding == ENDING_DELIRIUM ? FINAL_BOSS_BONUS : 0; + beastBonus = runEnding == ENDING_BEAST ? FINAL_BOSS_BONUS : 0; int hearts = 0; int goldenHearts = 0; @@ -270,17 +283,17 @@ void ScoreSheet::Calculate() calculate_room_score(); int parTime = PAR_TIME_BASE; - if (game.GetChallengeParams().pathType == PATH_TYPE_HOME || runEnding == RUN_ENDING_BEAST) + if (game.GetChallengeParams().pathType == PATH_TYPE_HOME || runEnding == ENDING_BEAST) { isPastWomb = false; parStages = std::min(stagesDone, PAR_STAGE_COUNT_HOME); for (StageVisit& visit : finishedStages) parTime += visit.isAscent ? PAR_TIME_ASCENT_STAGE : 0; - if (runEnding == RUN_ENDING_BEAST) parTime += PAR_TIME_BOSS; + if (runEnding == ENDING_BEAST) parTime += PAR_TIME_BOSS; } for (int i = 0; i < parStages; i++) parTime += STAGE_PAR_TIMES[i]; - bool isChestEnding = runEnding == RUN_ENDING_LAMB || runEnding == RUN_ENDING_BLUE_BABY || - runEnding == RUN_ENDING_MEGA_SATAN; + bool isChestEnding = runEnding == ENDING_LAMB || runEnding == ENDING_BLUE_BABY || + runEnding == ENDING_MEGA_SATAN; parTime += (isPastWomb + isChestEnding) * PAR_TIME_BOSS; if (game.GetStateFlag(GAME_STATE_BOSSRUSH_DONE)) parTime += PAR_TIME_BOSS_RUSH; @@ -298,7 +311,7 @@ void ScoreSheet::Calculate() } damagePenalty = penalty_get((float)(uint32_t)damage, DAMAGE_DECAY_HITS, explorationBonus); - int itemStages = runEnding == RUN_ENDING_BEAST ? STAGE_COUNT_BEAST : stagesDone; + int itemStages = runEnding == ENDING_BEAST ? STAGE_COUNT_BEAST : stagesDone; float itemAllowance = std::max((float)itemStages * ITEM_DECAY_PER_STAGE, 1.0f); itemPenalty = penalty_get((float)(uint32_t)items, itemAllowance, schwagBonus); diff --git a/src/score_sheet.h b/src/score_sheet.h index b7d0ca8..e9c0570 100644 --- a/src/score_sheet.h +++ b/src/score_sheet.h @@ -1,28 +1,9 @@ #pragma once #include "classes.h" +#include "game_end.h" #include -// How a run ended (REPENTOGON's Ending), which picks the boss bonus of its score. -enum RunEnding : int -{ - RUN_ENDING_NONE, - RUN_ENDING_DIE, - RUN_ENDING_EPILOGUE, - RUN_ENDING_CREDITS, - RUN_ENDING_SATAN, - RUN_ENDING_ISAAC, - RUN_ENDING_LAMB, - RUN_ENDING_BLUE_BABY, - RUN_ENDING_MEGA_SATAN, - RUN_ENDING_ULTRA_GREED, - RUN_ENDING_HUSH, - RUN_ENDING_DELIRIUM, - RUN_ENDING_ULTRA_GREEDIER, - RUN_ENDING_MOTHER, - RUN_ENDING_BEAST -}; - // A room the score counts: its type, whether it is a red room, and how much the floor still scores. struct RoomScore { @@ -55,7 +36,7 @@ struct ScoreRecord std::vector visitedRooms; std::vector finishedStages; std::vector replayedStages; - RunEnding runEnding = RUN_ENDING_NONE; + GameEnding runEnding = ENDING_NONE; int angelsKilled = 0; int bossChallengesCleared = 0; int enemyPoints = 0; diff --git a/src/seeds.h b/src/seeds.h index f024fb9..afd2fe0 100644 --- a/src/seeds.h +++ b/src/seeds.h @@ -7,8 +7,9 @@ #include #include -// The seed every RNG starts on before a run seeds it. +// The seed every RNG starts on before a run seeds it, and the xorshift it holds until then (shift index 35). constexpr uint32_t RNG_SEED_DEFAULT = 0xaa17414f; +constexpr RNG RNG_DEFAULT = {RNG_SEED_DEFAULT, 5, 9, 7}; // The run modifiers a special seed code turns on (Lua's SeedEffect). The gaps are effects the game no longer has. enum SeedEffect : int diff --git a/src/sfx_manager.h b/src/sfx_manager.h index bc32bf6..1e5c006 100644 --- a/src/sfx_manager.h +++ b/src/sfx_manager.h @@ -51,6 +51,7 @@ enum SoundId : int SOUND_DEATH_BURST_SMALL = 30, SOUND_DEATH_CARD = 33, SOUND_HOURGLASS = 1039, + SOUND_BOOK_SHADOWS_SIGIL = 1028, SOUND_BOOK_OF_SIN = 1042, SOUND_DEAD_SEA_SCROLLS = 1034, SOUND_FORGET_ME_NOW = 1054, @@ -150,6 +151,8 @@ enum SoundId : int SOUND_BOSS2_BUBBLES = 185, SOUND_ERROR_BUZZ = 187, SOUND_CASTLEPORTCULLIS = 190, + SOUND_CHARACTER_SELECT_LEFT = 194, + SOUND_CHARACTER_SELECT_RIGHT = 195, SOUND_GOLDENKEY = 204, SOUND_GOOATTACH0 = 205, SOUND_MAW_OF_VOID = 426, @@ -274,6 +277,7 @@ enum SoundId : int SOUND_BULLET_SHOT = 482, SOUND_FLAME_BURST = 483, SOUND_INFLATE = 484, + SOUND_BULB_FLASH = 492, SOUND_BATTERYDISCHARGE = 493, SOUND_FREEZE = 496, SOUND_FREEZE_SHATTER = 498, @@ -299,6 +303,10 @@ enum SoundId : int SOUND_GFUEL_ITEM_APPEAR = 829, SOUND_GFUEL_GUNSHOT_MINI = 830, SOUND_GFUEL_ROCKETLAUNCHER = 832, + SOUND_GFUEL_1 = 818, + SOUND_GFUEL_2 = 819, + SOUND_GFUEL_3 = 820, + SOUND_GFUEL_4 = 821, SOUND_CRACKED_ORB = 850, SOUND_DARK_BUM_PAYOUT = 853, SOUND_DRSREMOTE_WARNING = 855, @@ -497,6 +505,7 @@ enum SoundId : int SOUND_MOTHER_CHARGE2 = 648, SOUND_MOTHER_LAND_SMASH = 649, SOUND_ABYSS = 834, + SOUND_DEATHMATCH_INTRO = 833, SOUND_FLIP_POOF = 856, SOUND_ERASER_HIT = 857, SOUND_GNAWED_LEAF_STONE = 858, @@ -578,6 +587,7 @@ enum SoundId : int SOUND_JAR_OF_FLIES = 1060, SOUND_MR_ME = 1069, SOUND_MAGIC_SKIN = 1041, + SOUND_MEGA_MUSH_SHRINK = 1040, SOUND_DATAMINER = 854, SOUND_PLAN_C = 897, SOUND_LARYNX_SCREAM_LO = 575, @@ -655,6 +665,58 @@ enum SoundId : int SOUND_BEAST_GRUMBLE = 816, SOUND_UNBORN_GROWL = 1089, SOUND_UNBORN_WARP = 1090, + SOUND_FAMINE_APPEAR = 651, + SOUND_FAMINE_DEATH_1 = 652, + SOUND_FAMINE_DEATH_2 = 653, + SOUND_FAMINE_DASH_START = 654, + SOUND_FAMINE_DASH = 655, + SOUND_FAMINE_SHOOT = 656, + SOUND_FAMINE_BURST = 657, + SOUND_FAMINE_GURGLE = 658, + SOUND_PESTILENCE_MAGGOT_START = 659, + SOUND_PESTILENCE_MAGGOT_SHOOT = 660, + SOUND_PESTILENCE_MAGGOT_RETURN = 661, + SOUND_PESTILENCE_BODY_SHOOT = 662, + SOUND_PESTILENCE_HEAD_DEATH = 663, + SOUND_PESTILENCE_DEATH = 664, + SOUND_PESTILENCE_COUGH = 665, + SOUND_PESTILENCE_BARF = 666, + SOUND_PESTILENCE_APPEAR = 667, + SOUND_PESTILENCE_HEAD_EXPLODE = 668, + SOUND_PESTILENCE_MAGGOT_ENTER = 669, + SOUND_PESTILENCE_MAGGOT_POPOUT = 670, + SOUND_PESTILENCE_MAGGOT_SHOOT2 = 671, + SOUND_PESTILENCE_NECK_PUKE = 672, + SOUND_PESTILENCE_PUKE_START = 673, + SOUND_WAR_APPEAR = 674, + SOUND_WAR_APPEAR_LAVA = 675, + SOUND_WAR_BOMB_TOSS = 676, + SOUND_WAR_DASH_START = 677, + SOUND_WAR_DASH = 678, + SOUND_WAR_HORSE_DEATH = 679, + SOUND_WAR_DEATH = 680, + SOUND_WAR_FIRE_SCREEM = 681, + SOUND_WAR_GRAB_PLAYER = 682, + SOUND_WAR_BOMB_HOLD = 683, + SOUND_WAR_BOMB_PULL_OUT = 684, + SOUND_WAR_CHASE = 685, + SOUND_WAR_BOMB_TICK = 686, + SOUND_WAR_FLAME = 687, + SOUND_WAR_LAVA_SPLASH = 688, + SOUND_WAR_LAVA_DASH = 689, + SOUND_DEATH_DIES = 690, + SOUND_DEATH_DESTROY_SKULLS = 691, + SOUND_DEATH_GROWL = 692, + SOUND_DEATH_SWIPE_START = 693, + SOUND_DEATH_SWIPE = 694, + SOUND_DEATH_SUMMON_SCYTHES = 695, + SOUND_DEATH_SUMMON_SKULLS = 696, + SOUND_BEAST_BACKGROUND_DIVE = 699, + SOUND_BEAST_INTRO_SCREAM = 708, + SOUND_DEATH_SKULL_SUMMON_LOOP = 729, + SOUND_DEATH_SKULL_SUMMON_END = 730, + SOUND_FAMINE_GRUNT = 817, + SOUND_SAFETY_SCISSORS = 900, SOUND_BALL_AND_CHAIN_HIT = 581 }; diff --git a/src/stage_transition.cpp b/src/stage_transition.cpp index 24b1805..e0e9a21 100644 --- a/src/stage_transition.cpp +++ b/src/stage_transition.cpp @@ -42,7 +42,6 @@ constexpr float SPLASH_SPEED = 8; constexpr float SPLASH_FALL = 1; constexpr float SPLASH_LIFT = -8; constexpr float SPLASH_LIFT_SPREAD = 4; -constexpr float RANDOM_PI = 3.14f; constexpr float LIGHT_SCALE_LIMIT = 2; constexpr float LIGHT_SCALE_TARGET = 1.5f; @@ -197,7 +196,7 @@ static void trapdoor_splash(GridEntity& trapDoor) for (int i = 0; i < drops; i++) { uint32_t seed = Random(); - float angle = random_unit() * RANDOM_PI; + float angle = random_unit() * PI_ROUGH; angle += angle; float speed = random_unit() * SPLASH_SPEED; auto* drop = static_cast( diff --git a/src/stat_hud.cpp b/src/stat_hud.cpp index c48c36f..04b3e53 100644 --- a/src/stat_hud.cpp +++ b/src/stat_hud.cpp @@ -14,7 +14,6 @@ constexpr int STAT_TEXT_SIZE = 12; constexpr int STAT_COARSE_FIRST = STAT_DEVIL_CHANCE; constexpr float TEARS_PER_SECOND = 30; constexpr float RANGE_UNIT = 40; -constexpr float PERCENT = 100; constexpr float ICON_ALPHA = 0.5f; constexpr float TEXT_ALPHA = 0.5f; constexpr float CHANGE_ALPHA = 0.5f; @@ -184,7 +183,7 @@ static void stat_text_get(StatHUDPlayer& slot, int statIndex, char* valueText, c if (isRosary) { StatTracker& devil = slot.stats[STAT_DEVIL_CHANCE]; - value = std::min(devil.value + value, PERCENT); + value = std::min(devil.value + value, (float)PERCENT); change += devil.change; stat.changeTimer = std::max(stat.changeTimer, devil.changeTimer); } diff --git a/src/tainted_characters.cpp b/src/tainted_characters.cpp index 4b90339..17754a8 100644 --- a/src/tainted_characters.cpp +++ b/src/tainted_characters.cpp @@ -83,7 +83,7 @@ struct AnimaChain }; // A locust flies out at a random angle, 6 to 10 pixels a frame, in one of its two flying states. -constexpr float LOCUST_TURN = 3.14f * 2; +constexpr float LOCUST_TURN = PI_ROUGH * 2; constexpr float LOCUST_SPEED_MIN = 6; constexpr float LOCUST_SPEED_RANGE = 4; constexpr int LOCUST_STATE_FIRST = 4; @@ -145,7 +145,8 @@ void locust_spawn(Entity_Player& player, int collectibleType, Vector position) } // Abyss: the held item and every free pedestal item of the room become locusts, with the success sounds, and eating -// starts a challenge room's or the boss rush's waves. +// starts a challenge room's or the boss rush's waves. In co-op the last co-op copy eaten leaves the next copy, a boss +// pool item. void abyss_use(ItemUse& use) { Entity_Player& player = use.player; @@ -161,6 +162,8 @@ void abyss_use(ItemUse& use) } PlayerManager& players = g_game->playerManager; + int duplicate = -1; + Vector duplicatePos{}; for (Entity* entity : std::vector(g_game->room->GetEntities()->updateEL)) { if (entity->type != ENTITY_PICKUP || entity->isDead) continue; @@ -174,7 +177,10 @@ void abyss_use(ItemUse& use) pickup.RemoveOtherOptions(); if (players.IsCoopPlay() && pickup.coopDuplicateIndex != -1 && pickup.coopDuplicateIndex + 1 < players.GetNumAlivePlayers()) - reconstruction_missing("Abyss in Entity_Player::UseActiveItem 005b39d0 (a co-op duplicate's item)"); + { + duplicate = pickup.coopDuplicateIndex; + duplicatePos = pickup.pos; + } isEaten = true; } @@ -183,6 +189,18 @@ void abyss_use(ItemUse& use) { sound_play(SOUND_ABYSS); sound_play(SOUND_ABYSS_SUCCESS); + if (players.IsCoopPlay() && duplicate != -1) + { + int id = g_game->itemPool.GetCollectible(POOL_BOSS, player.dropRNG.Next(), 0, 0, 0); + auto* copy = static_cast(g_game->Spawn({.position = duplicatePos, + .subType = id, + .type = ENTITY_PICKUP, + .variant = PICKUP_COLLECTIBLE, + .seed = player.dropRNG.Next()})); + copy->coopDuplicateIndex = duplicate + 1; + if (copy->coopDuplicateIndex != 0 && copy->coopDuplicateIndex != -1) copy->cycleCollectibleCount = 0; + copy->Update(); + } RoomType type = g_game->room->roomType; if (type == ROOM_CHALLENGE || type == ROOM_BOSSRUSH) g_game->ambush.StartChallenge(); } @@ -246,7 +264,7 @@ static bool is_summonable(ItemConfig_Item& item) } // Lemegeton: a summonable item from the room's pool one time in four, else from a weighted pool, joins the player as -// an item wisp, with its name shown. +// an item wisp, with its name shown. A versus match redraws what its rules ban. void lemegeton_use(ItemUse& use) { Entity_Player& player = use.player; @@ -256,9 +274,14 @@ void lemegeton_use(ItemUse& use) std::vector& filters = g_manager->itemConfig.availabilityFilters; filters.push_back(is_summonable); RNG& rng = player.GetCollectibleRNG(COLLECTIBLE_LEMEGETON); + DeathmatchManager& versus = game.deathmatchManager; + auto is_banned = [&versus](int id) { return versus.is_active() && versus.type->is_collectible_banned(id); }; int collectible = 0; if (rng.RandomInt(LEMEGETON_ROOM_POOL_CHANCE) == 0) - collectible = game.itemPool.GetSeededCollectible(rng.Next(), true, *game.room->descriptor); + { + do collectible = game.itemPool.GetSeededCollectible(rng.Next(), true, *game.room->descriptor); + while (is_banned(collectible)); + } else { WeightedOutcomePicker picker; @@ -266,10 +289,9 @@ void lemegeton_use(ItemUse& use) : std::span(LEMEGETON_POOLS)) picker.AddOutcomeWeight(each.pool, each.weight); int pool = picker.PickOutcome(rng_make(rng.Next(), LEMEGETON_PICK_SHIFT)); - collectible = game.itemPool.GetCollectible((ItemPoolType)pool, rng.Next(), 0, COLLECTIBLE_BROTHER_BOBBY, 0); + do collectible = game.itemPool.GetCollectible((ItemPoolType)pool, rng.Next(), 0, COLLECTIBLE_BROTHER_BOBBY, 0); + while (is_banned(collectible)); } - if (game.deathmatchManager.is_active()) - reconstruction_missing("Lemegeton in Entity_Player::UseActiveItem 005b39d0 (the deathmatch's redraws)"); filters.pop_back(); player.AddItemWisp(collectible, player.pos, true); diff --git a/src/weapon.cpp b/src/weapon.cpp index 867d827..2b4b9f3 100644 --- a/src/weapon.cpp +++ b/src/weapon.cpp @@ -68,8 +68,6 @@ constexpr uint32_t MOMS_WIG_HIVE_SPIDERS = 9; constexpr float EXTRA_TEAR_SPEED = 10; constexpr float EXTRA_TEAR_SPEED_MIN = 0.9f; constexpr float EXTRA_TEAR_SPEED_SPREAD = 0.2f; -constexpr float EXTRA_TEAR_SCALE_MIN = 0.01f; -constexpr float EXTRA_TEAR_FALL_SPREAD = 0.2f; constexpr float IMMACULATE_LIFT = 7; constexpr float IMMACULATE_FALL_SCALE = 0.01f; constexpr ColorMod IMMACULATE_TINT = {{1.5f, 2, 2, 1}, {0, 0, 0, 0}, {0, 0, 0}}; @@ -88,6 +86,9 @@ constexpr float TORN_CARD_FLOOR = -5; constexpr float TORN_CARD_ARC = 9; constexpr float TORN_CARD_FALL_ACCEL = 0.8f; constexpr ColorMod TORN_CARD_COLOR = {{0.5f, 0.9f, 0.4f, 1}, {0, 0, 0, 0}, {0, 0, 0}}; + +// The Dead co-op baby's tears now and then (1 in 50) let a blue fly out while enemies live. +constexpr uint32_t DEAD_BABY_FLY_ODDS = 50; constexpr int CANDLE_ODDS = 8; constexpr int GHOST_PEPPER_ODDS = 12; constexpr int CANDLE_ODDS_MIN = 2; @@ -97,7 +98,6 @@ constexpr float GREED_DAMAGE_SCALE = 1.5f; constexpr float GREED_DAMAGE_BONUS = 10; constexpr int PENCIL_PERIOD = 15; constexpr int PENCIL_TEARS = 12; -constexpr float PENCIL_HALF_TURN = 3.14f; constexpr float PENCIL_SCATTER = 3.5f; constexpr float PENCIL_SCALE_STEP = 0.4f; constexpr float PENCIL_SCALE_JITTER = 0.05f; @@ -604,11 +604,11 @@ static void torn_card_fire(Weapon& weapon, Entity_Player& player) Entity_Tear* tear = extra_tear_spawn(weapon, player, velocity, params.tearVariant, params.tearHeight); tear->SetCollisionDamage(params.tearDamage); tear->SetTearFlags(params.tearFlags); - tear->baseScale = std::max(params.tearScale, EXTRA_TEAR_SCALE_MIN); + tear->baseScale = std::max(params.tearScale, TEAR_SCALE_MIN); tear->fScale = tear->baseScale; tear->ResetSpriteScale(); tear->SetColor(TORN_CARD_COLOR, -1, COLOR_PRIORITY_DEFAULT, false, true); - float slope = std::max(((float)std::pow(TORN_CARD_DRAG, TORN_CARD_FLIGHT) - 1) * TORN_CARD_SLOPE, EXTRA_TEAR_SCALE_MIN); + float slope = std::max(((float)std::pow(TORN_CARD_DRAG, TORN_CARD_FLIGHT) - 1) * TORN_CARD_SLOPE, TEAR_SCALE_MIN); float fallingSpeed = ((TORN_CARD_FLOOR - tear->height) - (TORN_CARD_FLIGHT - slope) * TORN_CARD_ARC) / slope; extra_tear_finish(*tear, player, fallingSpeed, TORN_CARD_FALL_ACCEL); } @@ -667,7 +667,7 @@ static void greed_coin_fire(Weapon& weapon, Entity_Player& player, const Vector& else tear->SetCollisionDamage(params.tearDamage); tear->SetTearFlags(flags); - float fallingSpeed = random_unit() * EXTRA_TEAR_FALL_SPREAD - player.tearFallingSpeed - IMMACULATE_LIFT; + float fallingSpeed = random_unit() * TEAR_FALL_SPREAD - player.tearFallingSpeed - IMMACULATE_LIFT; extra_tear_finish(*tear, player, fallingSpeed, player.tearFallingAcceleration * IMMACULATE_FALL_SCALE); effect_sound_play(SOUND_CASH_REGISTER); } @@ -684,7 +684,7 @@ static void lead_pencil_fire(Weapon& weapon, Entity_Player& player) Vector inherited = weapon.get_tear_movement_inheritance(direction); float speed = weapon_shot_speed(weapon); Vector velocity = vector_make((direction.x + inherited.x) * speed, (direction.y + inherited.y) * speed); - float angle = random_unit() * PENCIL_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float scatter = random_unit(); velocity.x = std::cos(angle) * scatter * PENCIL_SCATTER + velocity.x; @@ -696,11 +696,11 @@ static void lead_pencil_fire(Weapon& weapon, Entity_Player& player) float lane = (float)(Random() & 1); float jitter = random_unit() * PENCIL_SCALE_JITTER; tear->baseScale = - std::max((lane * PENCIL_SCALE_STEP + EXTRA_TEAR_SPEED_MIN + jitter) * params.tearScale, EXTRA_TEAR_SCALE_MIN); + std::max((lane * PENCIL_SCALE_STEP + EXTRA_TEAR_SPEED_MIN + jitter) * params.tearScale, TEAR_SCALE_MIN); tear->fScale = tear->baseScale; tear->ResetSpriteScale(); tear->SetColor(params.tearColor, -1, COLOR_PRIORITY_DEFAULT, false, true); - float fallingSpeed = random_unit() * EXTRA_TEAR_FALL_SPREAD - player.tearFallingSpeed; + float fallingSpeed = random_unit() * TEAR_FALL_SPREAD - player.tearFallingSpeed; extra_tear_finish(*tear, player, fallingSpeed, player.tearFallingAcceleration); if (g_game->deathmatchManager.is_active()) { @@ -737,13 +737,13 @@ void Weapon::TriggerTearEffects(const Vector& shootDirection, int count) continue; } - if (!player->proceduralItems.empty()) - reconstruction_missing("Weapon::TriggerTearEffects 009f7930 (glitched items, trigger_set_dispatch 009e0680)"); + glitched_items_trigger(*player, {get_owner_position(), aim, nullptr, CONDITION_TEAR_FIRE}); if (player->HasCollectible(COLLECTIBLE_MOMS_WIG)) moms_wig_spider(*this, *player); if (player->HasCollectible(COLLECTIBLE_IMMACULATE_HEART)) immaculate_heart_fire(*this, *player, count); torn_card_fire(*this, *player); - if (player->variant == PLAYER_VARIANT_COOP_BABY && player->babySkin == BABY_DEAD) - reconstruction_missing("Weapon::TriggerTearEffects 009f7930 (a co-op baby's blue flies)"); + bool isDeadBaby = player->variant == PLAYER_VARIANT_COOP_BABY && player->babySkin == BABY_DEAD; + if (isDeadBaby && Random() % DEAD_BABY_FLY_ODDS == 0 && g_game->room->GetAliveEnemiesCount() > 0) + player->AddBlueFlies(1, owner ? owner->pos : vector_make(0, 0), nullptr); candle_fire(*player, aim); numFired++; if (player->HasCollectible(COLLECTIBLE_EYE_OF_GREED)) greed_coin_fire(*this, *player, aim, count); diff --git a/src/weapon_fetus.cpp b/src/weapon_fetus.cpp index 9119dc9..e9f5c5e 100644 --- a/src/weapon_fetus.cpp +++ b/src/weapon_fetus.cpp @@ -7,6 +7,7 @@ #include "game.h" #include "item_config.h" #include "log.h" +#include "lua_engine.h" #include "manager.h" #include "npc_ai.h" #include @@ -108,8 +109,8 @@ static void fetus_birth_splash(Entity_Tear& tear) // 009f6e60 Throws a fetus (a C Section tear) for the weapon's owner (or a given source): its player's fetus hit // params at three quarters of the damage, spectral, never held by Marked, the Tractor Beam or a laser, carrying the -// weapons its player's items give, skinned like its player and born in a splash of blood. It updates once and steps -// back a frame. A familiar throws for its player. The original reads a missing player's effects and type. This skips +// weapons its player's items give, skinned like its player and born in a splash of blood. It updates once, steps +// back a frame and runs MC_POST_FIRE_TEAR. A familiar throws for its player. The original reads a missing player's effects and type. This skips // them. Entity_Tear* fire_fetus_tear(Weapon& weapon, const FetusShot& shot) { @@ -159,6 +160,7 @@ Entity_Tear* fire_fetus_tear(Weapon& weapon, const FetusShot& shot) if (vector_length_squared(shot.velocity) > FETUS_BIRTH_SPEED_SQUARED) fetus_birth_splash(tear); tear.Update(); tear.pos = vector_sub(tear.pos, tear.velocity); + lua_engine_get().PostFireTear(&tear); return &tear; } diff --git a/src/weapon_lasers.cpp b/src/weapon_lasers.cpp index 44458f6..9bdd967 100644 --- a/src/weapon_lasers.cpp +++ b/src/weapon_lasers.cpp @@ -24,7 +24,6 @@ constexpr float LASER_INHERIT_SCALE = 0.4f; constexpr float FAMILIAR_EYE_SPREAD = 7; constexpr float C_SECTION_FETUS_SPEED = 10; -constexpr float C_SECTION_HALF_TURN = 3.14f; constexpr float C_SECTION_JITTER = 3; constexpr float FAMILIAR_EYE_LIFT = 8; constexpr ColorMod BABY_BENDER_LASER_COLOR = {{0.4f, 0.15f, 0.38f, 1}, {0, 0, 0, 0}, {0.3529412f, 0, 0.7058824f}}; @@ -119,7 +118,6 @@ constexpr float SNEEZE_PUSH_MASS_BASE = 50; constexpr float SNEEZE_KNOCKBACK = 20; constexpr int SNEEZE_KNOCKBACK_FRAMES = 14; constexpr int SNEEZE_MARK_FRAMES = -150; -constexpr int SNEEZE_HIT_COUNTDOWN = 30; constexpr float SNEEZE_FIRE_DAMAGE = 1000; constexpr float SNEEZE_PUSH = 18; constexpr float SNEEZE_LUDOVICO_FLING = 1.25f; @@ -504,7 +502,7 @@ std::vector Weapon_Laser::fire_lasers(const LaserVolley& volley) Vector reach = vector_scale(direction, SPRAY_REACH); for (int spray = 0; spray < volley.sprayCount; spray++) { - float angle = random_unit() * RANDOM_HALF_TURN * 2; + float angle = random_unit() * PI_ROUGH * 2; float scatter = random_unit(); Vector aim = vector_add(reach, vector_make(std::cos(angle) * SPRAY_SCATTER * scatter, std::sin(angle) * SPRAY_SCATTER * scatter)); @@ -1143,7 +1141,7 @@ void Weapon_Brimstone::fire_c_section_fetuses() if (beam != mainLaser.get() && beam->parent != mainLaser.get()) continue; Vector along = vector_scale(vector_from_angle(static_cast(beam)->angleDegrees), C_SECTION_FETUS_SPEED); - float angle = random_unit() * C_SECTION_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; Vector velocity = vector_make((std::cos(angle) * C_SECTION_JITTER + along.x) * shotSpeed, (std::sin(angle) * C_SECTION_JITTER + along.y) * shotSpeed); @@ -1239,7 +1237,7 @@ static bool sneeze_entity_hit(Entity& target, const SneezeHit& hit) if (target.HasEntityFlags(FLAG_FRIENDLY) || type == ENTITY_SHOPKEEPER) return false; if (type == ENTITY_FIREPLACE && target.variant != FIRE_COAL) { - target.TakeDamage(SNEEZE_FIRE_DAMAGE, 0, EntityRef(hit.owner), SNEEZE_HIT_COUNTDOWN); + target.TakeDamage(SNEEZE_FIRE_DAMAGE, 0, EntityRef(hit.owner), HIT_COUNTDOWN); return false; } // The original lets the player of a familiar's sneeze be missing here and crashes. Here nothing collides. @@ -1256,7 +1254,7 @@ static bool sneeze_entity_hit(Entity& target, const SneezeHit& hit) target.AddKnockback(EntityRef(hit.owner), vector_scale(away, SNEEZE_KNOCKBACK), SNEEZE_KNOCKBACK_FRAMES, true); } uint64_t damageFlags = sneeze_damage_flags(target, player); - if (!target.TakeDamage(hit.params.tearDamage, damageFlags, EntityRef(hit.owner), SNEEZE_HIT_COUNTDOWN) || + if (!target.TakeDamage(hit.params.tearDamage, damageFlags, EntityRef(hit.owner), HIT_COUNTDOWN) || !target.IsVulnerableEnemy(nullptr)) return false; Entity_Tear::ApplyTearFlagEffects(&target, hit.ownerPosition, hit.params.tearFlags, hit.owner, hit.params.tearDamage); diff --git a/src/weapon_lua.cpp b/src/weapon_lua.cpp index fb8c830..29c2aee 100644 --- a/src/weapon_lua.cpp +++ b/src/weapon_lua.cpp @@ -4,19 +4,19 @@ #include "lua_api.h" #include "weapon.h" -constexpr float LUA_ROTATE_SPEED = 8; -constexpr float LUA_TECH_X_DAMAGE = 1; - -// Adds Lua's EntityLaser functions that fire and turn beams to the class begun last. +// Adds Lua's EntityLaser functions that fire and turn beams to the class begun last. The original registers no +// RotateToAngle. void weapon_lua_laser_register(lua_State* state) { - lua_static(state, "ShootAngle", [](int variant, Vector position, float angle, int timeout, Vector offset, Entity* source) { + lua_static(state, "ShootAngle", [](int variant, Vector position, float angle, int timeout, Vector offset, + Entity* source, bool isPoolKept) { return Entity_Laser::ShootAngle({.position = position, .posOffset = offset, .source = source, .angleDegrees = angle, .timeout = timeout, - .variant = variant}); + .variant = variant, + .isPoolKept = isPoolKept}); }); lua_static(state, "CalculateEndPoint", [](Vector start, Vector direction, Vector offset, Entity* parent, float margin) { return Entity_Laser::CalculateEndPoint(start, direction, offset, parent, margin); @@ -24,9 +24,6 @@ void weapon_lua_laser_register(lua_State* state) lua_method(state, "SetActiveRotation", [](Entity_Laser& laser, int delay, float angle, float speed, bool isTimeout) { laser.SetActiveRotation(delay, angle, speed, isTimeout); }); - lua_method(state, "RotateToAngle", [](Entity_Laser& laser, float angle, LuaDefault speed) { - laser.RotateToAngle(angle, speed.value); - }); } // Adds Lua's EntityKnife functions that bring a knife back to rest to the class begun last. @@ -41,35 +38,35 @@ void weapon_lua_player_register(lua_State* state) { lua_method(state, "FireTechLaser", [](Entity_Player& player, Vector position, int offsetId, Vector direction, bool isLeftEye, bool isOneHit, - Entity* source, LuaDefault damageScale) { + Entity* source, float damageScale) { return player.FireTechLaser({.direction = direction, .position = position, .source = source, - .damageScale = damageScale.value, + .damageScale = damageScale, .offsetId = offsetId, .isLeftEye = isLeftEye, .isOneHit = isOneHit}); }); lua_method(state, "FireTechXLaser", [](Entity_Player& player, Vector position, Vector velocity, float radius, Entity* source, - LuaDefault damageMultiplier) { + float damageMultiplier) { return player.FireTechXLaser({.position = position, .velocity = velocity, .source = source, - .damageMultiplier = damageMultiplier.value, + .damageMultiplier = damageMultiplier, .radius = radius}); }); lua_method(state, "FireBrimstone", - [](Entity_Player& player, Vector direction, Entity* source, LuaDefault damageMultiplier) { - return player.FireBrimstone(direction, source, damageMultiplier.value); + [](Entity_Player& player, Vector direction, Entity* source, float damageMultiplier) { + return player.FireBrimstone(direction, source, damageMultiplier); }); lua_method(state, "FireKnife", - [](Entity_Player& player, Entity* parent, LuaDefault rotationOffset, - LuaDefault isCantOverwrite, LuaDefault subType, LuaDefault variant) { + [](Entity_Player& player, Entity* parent, int variant, float rotationOffset, bool isCantOverwrite, + int subType) { return player.FireKnife({.parent = parent, - .rotationOffset = rotationOffset.value, - .subType = subType.value, - .variant = variant.value, - .isCantOverwrite = isCantOverwrite.value}); + .rotationOffset = rotationOffset, + .subType = subType, + .variant = variant, + .isCantOverwrite = isCantOverwrite}); }); } diff --git a/src/weapon_ludovico.cpp b/src/weapon_ludovico.cpp index 19a6f8e..37e8229 100644 --- a/src/weapon_ludovico.cpp +++ b/src/weapon_ludovico.cpp @@ -181,7 +181,7 @@ void Weapon_Ludovico::lung_tears_update() auto& mainTear = *static_cast(main); for (int i = 0; i < LUNG_TEAR_COUNT; i++) { - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float sine = std::sin(angle); float reach = random_unit() * LUNG_REACH + LUNG_REACH_MIN; diff --git a/src/weapon_monstros_lung.cpp b/src/weapon_monstros_lung.cpp index f93a653..971d13c 100644 --- a/src/weapon_monstros_lung.cpp +++ b/src/weapon_monstros_lung.cpp @@ -91,7 +91,7 @@ void Weapon_MonstrosLung::FireBurst(const Vector& velocity, int count, float dam for (int i = 0; i < count; i++) { float shotSpeed = player ? player->shotSpeed : 1; - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float scatter = random_unit() * COUGH_SCATTER; Vector shot = vector_make(std::cos(angle) * scatter + velocity.x * shotSpeed, diff --git a/src/weapon_rockets.cpp b/src/weapon_rockets.cpp index 86e1d41..e75e3dc 100644 --- a/src/weapon_rockets.cpp +++ b/src/weapon_rockets.cpp @@ -180,7 +180,7 @@ void Weapon_Rockets::Fire(const Vector& shootDirection, bool isShooting, bool is for (int i = 0; i < params.numRandomDirTears; i++) { Entity_Effect* added = extra(TARGET_RANDOM); - float angle = random_unit() * RANDOM_HALF_TURN; + float angle = random_unit() * PI_ROUGH; angle += angle; float sine = std::sin(angle); float reach = random_unit() * RANDOM_TARGET_REACH + RANDOM_TARGET_MIN;