From 97eb7322b5b61d34219b927e0f50b47ea8e8202d Mon Sep 17 00:00:00 2001 From: aquanight Date: Thu, 23 Jul 2026 21:03:41 -0600 Subject: [PATCH 1/2] Resource collection obeys HUD limits --- patches/ips/resource_collection_hudcap.ips | Bin 0 -> 161 bytes patches/src/resource_collection_hudcap.asm | 88 +++++++++++++++++++++ rust/maprando-logic/src/lib.rs | 16 ++-- rust/maprando/src/patch.rs | 8 ++ rust/maprando/src/randomize.rs | 40 ---------- 5 files changed, 104 insertions(+), 48 deletions(-) create mode 100644 patches/ips/resource_collection_hudcap.ips create mode 100644 patches/src/resource_collection_hudcap.asm diff --git a/patches/ips/resource_collection_hudcap.ips b/patches/ips/resource_collection_hudcap.ips new file mode 100644 index 0000000000000000000000000000000000000000..625524cae4b8cd070887bb34330dda5f37f38aa9 GIT binary patch literal 161 zcmWG=3~}~g;>=-SR#@0l* z;tNyB0)~)E28NS2SSK*Ayuq3PVozWMvL`Tt+0U7Q?B~p2b}|Eyoy-7YpFP1jfqCr- WPB8lnh~R literal 0 HcmV?d00001 diff --git a/patches/src/resource_collection_hudcap.asm b/patches/src/resource_collection_hudcap.asm new file mode 100644 index 000000000..f9a85e4d6 --- /dev/null +++ b/patches/src/resource_collection_hudcap.asm @@ -0,0 +1,88 @@ +!bank_84_free_space_start = $84F4A0 +!bank_84_free_space_end = $84F4FF + +org $84896C + jsr add_max_energy_capped + +org $84898A + jsr add_max_reserve_capped + +org $8489AD + jsr add_max_missile_capped + +org $8489B7 + jsr add_current_missile_capped + +org $8489D6 + jsr add_max_super_capped + +org $8489E0 + jsr add_current_super_capped + +org $8489FF + jsr add_max_powerbomb_capped + +org $848A09 + jsr add_current_powerbomb_capped + +org !bank_84_free_space_start + +add_max_energy_capped: + adc $0000,Y + cmp #$05D8 ;1499 energy + bcc + + lda #$05D8 ++ + rts + +add_max_reserve_capped: + adc $0000,Y + cmp #$0190 + bcc + + lda #$0190 ++ + rts + +add_max_missile_capped: + adc $0000,Y + cmp #$03E7 ;999 missiles + bcc + + lda #$03E7 ++ + rts + +add_max_super_capped: +add_max_powerbomb_capped: + adc $0000,Y + cmp #$0063 ;99 supers/powerbombs + bcc + + lda #$0063 ++ + rts + +add_current_missile_capped: + adc $0000,Y + cmp $09C8 + bcc + + lda $09C8 ++ + rts + +add_current_super_capped: + adc $0000,Y + cmp $09CC + bcc + + lda $09CC ++ + rts + +add_current_powerbomb_capped: + adc $0000,Y + cmp $09D0 + bcc + + lda $09D0 ++ + rts + + print pc +assert pc() <= !bank_84_free_space_end \ No newline at end of file diff --git a/rust/maprando-logic/src/lib.rs b/rust/maprando-logic/src/lib.rs index ce11ea6a9..50ccfe2c6 100644 --- a/rust/maprando-logic/src/lib.rs +++ b/rust/maprando-logic/src/lib.rs @@ -54,30 +54,30 @@ impl GlobalState { match item { Item::Missile => { self.inventory.collectible_missile_packs += 1; - let new_max_missiles = (ammo_collect_fraction + let new_max_missiles = std::cmp::min(999, (ammo_collect_fraction * self.inventory.collectible_missile_packs as f32) .round() as Capacity - * (missile_size as Capacity); + * (missile_size as Capacity)); self.inventory.max_missiles = new_max_missiles; } Item::Super => { self.inventory.collectible_super_packs += 1; - let new_max_supers = (ammo_collect_fraction + let new_max_supers = std::cmp::min(99, (ammo_collect_fraction * self.inventory.collectible_super_packs as f32) .round() as Capacity - * (super_size as Capacity); + * (super_size as Capacity)); self.inventory.max_supers = new_max_supers; } Item::PowerBomb => { self.inventory.collectible_power_bomb_packs += 1; - let new_max_power_bombs = (ammo_collect_fraction + let new_max_power_bombs = std::cmp::min(99, (ammo_collect_fraction * self.inventory.collectible_power_bomb_packs as f32) .round() as Capacity - * (powerbomb_size as Capacity); + * (powerbomb_size as Capacity)); self.inventory.max_power_bombs = new_max_power_bombs; } Item::ETank => { - self.inventory.max_energy += 100; + self.inventory.max_energy = std::cmp::min(1499, self.inventory.max_energy + 100); if !tech[game_data.manage_reserves_tech_idx] { self.inventory.max_reserves = Capacity::min(self.inventory.max_reserves, self.inventory.max_energy); @@ -85,7 +85,7 @@ impl GlobalState { } Item::ReserveTank => { self.inventory.collectible_reserve_tanks += 1; - self.inventory.max_reserves = self.inventory.collectible_reserve_tanks * 100; + self.inventory.max_reserves = std::cmp::min(400, self.inventory.collectible_reserve_tanks * 100); if !tech[game_data.manage_reserves_tech_idx] { self.inventory.max_reserves = Capacity::min(self.inventory.max_reserves, self.inventory.max_energy); diff --git a/rust/maprando/src/patch.rs b/rust/maprando/src/patch.rs index d6bffac1a..0b4aa4881 100644 --- a/rust/maprando/src/patch.rs +++ b/rust/maprando/src/patch.rs @@ -486,6 +486,7 @@ impl Patcher<'_> { "fix_horiz_doors", // this too? "fix_dust_torizo", "fix_choot", + "resource_collection_hudcap", ]; patches.push("new_game"); @@ -2304,6 +2305,13 @@ impl Patcher<'_> { * (self.settings.item_progression_settings.powerbomb_size as isize); } } + + if starting_energy > 1499 { starting_energy = 1499 } + if starting_reserves > 400 { starting_reserves = 400 } + if starting_missiles > 999 { starting_missiles = 999 } + if starting_supers > 99 { starting_supers = 99 } + if starting_powerbombs > 99 { starting_powerbombs = 99 } + let beam_equipped_mask = if beam_mask & 0x000C == 0x000C { // Don't equip Spazer if Plasma equipped beam_mask & !0x0004 diff --git a/rust/maprando/src/randomize.rs b/rust/maprando/src/randomize.rs index 159b7fe39..a2a426e25 100644 --- a/rust/maprando/src/randomize.rs +++ b/rust/maprando/src/randomize.rs @@ -3640,26 +3640,6 @@ pub fn get_starting_items(settings: &RandomizerSettings) -> Vec { if x.item == Item::WallJump && settings.other_settings.wall_jump == WallJump::Vanilla { continue; } - // Enforce HUD-based limits for starting ammo - // TODO: eliminate this in favor of an in-game patch to cap ammo capacity to HUD limits. - match x.item { - Item::Missile => { - while x.count * settings.item_progression_settings.missile_size as usize > 999 { - x.count -= 1; - } - } - Item::Super => { - while x.count * settings.item_progression_settings.super_size as usize > 99 { - x.count -= 1; - } - } - Item::PowerBomb => { - while x.count * settings.item_progression_settings.powerbomb_size as usize > 99 { - x.count -= 1; - } - } - _ => {} - } // Depending on if Split Speed Booster is enabled, do not place inapplicable booster items. match (x.item, settings.other_settings.speed_booster) { (Item::BlueBooster | Item::SparkBooster, SpeedBooster::Vanilla) => continue, @@ -3745,26 +3725,6 @@ impl<'r> Randomizer<'r> { } } - // Enforce HUD-based total resource limits (999 missile, 99 super, 99 PB) - while initial_items_remaining[Item::Missile as usize] - * settings.item_progression_settings.missile_size as usize - > 999 - { - initial_items_remaining[Item::Missile as usize] -= 1; - } - while initial_items_remaining[Item::Super as usize] - * settings.item_progression_settings.super_size as usize - > 99 - { - initial_items_remaining[Item::Super as usize] -= 1; - } - while initial_items_remaining[Item::PowerBomb as usize] - * settings.item_progression_settings.powerbomb_size as usize - > 99 - { - initial_items_remaining[Item::PowerBomb as usize] -= 1; - } - let target_initial_items = initial_items_remaining.clone(); let ammo_shortage_weight: Vec<(Item, f32)> = vec![ (Item::Missile, 0.12), From 3d07e0f9566b49109351e53454859a14a04fa2b0 Mon Sep 17 00:00:00 2001 From: aquanight Date: Mon, 27 Jul 2026 20:39:16 -0600 Subject: [PATCH 2/2] Fix formatting --- rust/maprando-logic/src/lib.rs | 33 ++++++++++++++++++++------------- rust/maprando/src/patch.rs | 20 +++++++++++++++----- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/rust/maprando-logic/src/lib.rs b/rust/maprando-logic/src/lib.rs index 50ccfe2c6..34707226d 100644 --- a/rust/maprando-logic/src/lib.rs +++ b/rust/maprando-logic/src/lib.rs @@ -54,26 +54,32 @@ impl GlobalState { match item { Item::Missile => { self.inventory.collectible_missile_packs += 1; - let new_max_missiles = std::cmp::min(999, (ammo_collect_fraction - * self.inventory.collectible_missile_packs as f32) - .round() as Capacity - * (missile_size as Capacity)); + let new_max_missiles = std::cmp::min( + 999, + (ammo_collect_fraction * self.inventory.collectible_missile_packs as f32) + .round() as Capacity + * (missile_size as Capacity), + ); self.inventory.max_missiles = new_max_missiles; } Item::Super => { self.inventory.collectible_super_packs += 1; - let new_max_supers = std::cmp::min(99, (ammo_collect_fraction - * self.inventory.collectible_super_packs as f32) - .round() as Capacity - * (super_size as Capacity)); + let new_max_supers = std::cmp::min( + 99, + (ammo_collect_fraction * self.inventory.collectible_super_packs as f32).round() + as Capacity + * (super_size as Capacity), + ); self.inventory.max_supers = new_max_supers; } Item::PowerBomb => { self.inventory.collectible_power_bomb_packs += 1; - let new_max_power_bombs = std::cmp::min(99, (ammo_collect_fraction - * self.inventory.collectible_power_bomb_packs as f32) - .round() as Capacity - * (powerbomb_size as Capacity)); + let new_max_power_bombs = std::cmp::min( + 99, + (ammo_collect_fraction * self.inventory.collectible_power_bomb_packs as f32) + .round() as Capacity + * (powerbomb_size as Capacity), + ); self.inventory.max_power_bombs = new_max_power_bombs; } Item::ETank => { @@ -85,7 +91,8 @@ impl GlobalState { } Item::ReserveTank => { self.inventory.collectible_reserve_tanks += 1; - self.inventory.max_reserves = std::cmp::min(400, self.inventory.collectible_reserve_tanks * 100); + self.inventory.max_reserves = + std::cmp::min(400, self.inventory.collectible_reserve_tanks * 100); if !tech[game_data.manage_reserves_tech_idx] { self.inventory.max_reserves = Capacity::min(self.inventory.max_reserves, self.inventory.max_energy); diff --git a/rust/maprando/src/patch.rs b/rust/maprando/src/patch.rs index 0b4aa4881..56dfa9dfb 100644 --- a/rust/maprando/src/patch.rs +++ b/rust/maprando/src/patch.rs @@ -2306,11 +2306,21 @@ impl Patcher<'_> { } } - if starting_energy > 1499 { starting_energy = 1499 } - if starting_reserves > 400 { starting_reserves = 400 } - if starting_missiles > 999 { starting_missiles = 999 } - if starting_supers > 99 { starting_supers = 99 } - if starting_powerbombs > 99 { starting_powerbombs = 99 } + if starting_energy > 1499 { + starting_energy = 1499 + } + if starting_reserves > 400 { + starting_reserves = 400 + } + if starting_missiles > 999 { + starting_missiles = 999 + } + if starting_supers > 99 { + starting_supers = 99 + } + if starting_powerbombs > 99 { + starting_powerbombs = 99 + } let beam_equipped_mask = if beam_mask & 0x000C == 0x000C { // Don't equip Spazer if Plasma equipped