From 9712a77f1d21c9ca70afd26283d9574eca5f1a5a Mon Sep 17 00:00:00 2001 From: Death Killer <884052+deathkiller@users.noreply.github.com> Date: Fri, 15 Dec 2023 21:54:50 +0100 Subject: [PATCH] Show upgraded ammo if player has upgraded weapon, adjusted Bird's fire rate, added JJ2+ ammo crates, fixed minor crash --- Content/Metadata/Collectible/AmmoBouncer.res | 7 ++++++- Content/Metadata/Collectible/AmmoElectro.res | 7 ++++++- Content/Metadata/Collectible/AmmoFreezer.res | 7 ++++++- Content/Metadata/Collectible/AmmoPepper.res | 7 ++++++- Content/Metadata/Collectible/AmmoRF.res | 7 ++++++- Content/Metadata/Collectible/AmmoSeeker.res | 7 ++++++- Content/Metadata/Collectible/AmmoTNT.res | 3 ++- Content/Metadata/Collectible/AmmoThunderbolt.res | 3 ++- Content/Metadata/Collectible/AmmoToaster.res | 7 ++++++- .../Jazz2/Actors/Collectibles/AmmoCollectible.cpp | 6 +++++- Sources/Jazz2/Actors/Environment/Bird.cpp | 2 +- Sources/Jazz2/Compatibility/EventConverter.cpp | 14 +++++++++++++- Sources/Jazz2/Events/EventMap.cpp | 5 +++++ 13 files changed, 70 insertions(+), 12 deletions(-) diff --git a/Content/Metadata/Collectible/AmmoBouncer.res b/Content/Metadata/Collectible/AmmoBouncer.res index 44c00aab..85830ece 100644 --- a/Content/Metadata/Collectible/AmmoBouncer.res +++ b/Content/Metadata/Collectible/AmmoBouncer.res @@ -3,7 +3,12 @@ "Animations": { "Ammo": { - "Path": "Pickup/ammo_bouncer.aura" + "Path": "Pickup/ammo_bouncer.aura", + "States": [ 0 ] + }, + "AmmoUpgraded": { + "Path": "Pickup/ammo_bouncer_upgraded.aura", + "States": [ 1 ] } } } \ No newline at end of file diff --git a/Content/Metadata/Collectible/AmmoElectro.res b/Content/Metadata/Collectible/AmmoElectro.res index 438034f5..6b542372 100644 --- a/Content/Metadata/Collectible/AmmoElectro.res +++ b/Content/Metadata/Collectible/AmmoElectro.res @@ -3,7 +3,12 @@ "Animations": { "Ammo": { - "Path": "Pickup/ammo_electro.aura" + "Path": "Pickup/ammo_electro.aura", + "States": [ 0 ] + }, + "AmmoUpgraded": { + "Path": "Pickup/ammo_electro_upgraded.aura", + "States": [ 1 ] } } } \ No newline at end of file diff --git a/Content/Metadata/Collectible/AmmoFreezer.res b/Content/Metadata/Collectible/AmmoFreezer.res index d2fba956..dc0e720e 100644 --- a/Content/Metadata/Collectible/AmmoFreezer.res +++ b/Content/Metadata/Collectible/AmmoFreezer.res @@ -3,7 +3,12 @@ "Animations": { "Ammo": { - "Path": "Pickup/ammo_freezer.aura" + "Path": "Pickup/ammo_freezer.aura", + "States": [ 0 ] + }, + "AmmoUpgraded": { + "Path": "Pickup/ammo_freezer_upgraded.aura", + "States": [ 1 ] } } } \ No newline at end of file diff --git a/Content/Metadata/Collectible/AmmoPepper.res b/Content/Metadata/Collectible/AmmoPepper.res index 9ce97a2c..05cfcf5f 100644 --- a/Content/Metadata/Collectible/AmmoPepper.res +++ b/Content/Metadata/Collectible/AmmoPepper.res @@ -3,7 +3,12 @@ "Animations": { "Ammo": { - "Path": "Pickup/ammo_pepper.aura" + "Path": "Pickup/ammo_pepper.aura", + "States": [ 0 ] + }, + "AmmoUpgraded": { + "Path": "Pickup/ammo_pepper_upgraded.aura", + "States": [ 1 ] } } } \ No newline at end of file diff --git a/Content/Metadata/Collectible/AmmoRF.res b/Content/Metadata/Collectible/AmmoRF.res index a0677ba3..f4ca218f 100644 --- a/Content/Metadata/Collectible/AmmoRF.res +++ b/Content/Metadata/Collectible/AmmoRF.res @@ -3,7 +3,12 @@ "Animations": { "Ammo": { - "Path": "Pickup/ammo_rf.aura" + "Path": "Pickup/ammo_rf.aura", + "States": [ 0 ] + }, + "AmmoUpgraded": { + "Path": "Pickup/ammo_rf_upgraded.aura", + "States": [ 1 ] } } } \ No newline at end of file diff --git a/Content/Metadata/Collectible/AmmoSeeker.res b/Content/Metadata/Collectible/AmmoSeeker.res index 60f73a2c..3a827fee 100644 --- a/Content/Metadata/Collectible/AmmoSeeker.res +++ b/Content/Metadata/Collectible/AmmoSeeker.res @@ -3,7 +3,12 @@ "Animations": { "Ammo": { - "Path": "Pickup/ammo_seeker.aura" + "Path": "Pickup/ammo_seeker.aura", + "States": [ 0 ] + }, + "AmmoUpgraded": { + "Path": "Pickup/ammo_seeker_upgraded.aura", + "States": [ 1 ] } } } \ No newline at end of file diff --git a/Content/Metadata/Collectible/AmmoTNT.res b/Content/Metadata/Collectible/AmmoTNT.res index 75ebb7dc..4e50dc7a 100644 --- a/Content/Metadata/Collectible/AmmoTNT.res +++ b/Content/Metadata/Collectible/AmmoTNT.res @@ -3,7 +3,8 @@ "Animations": { "Ammo": { - "Path": "Object/tnt.aura" + "Path": "Object/tnt.aura", + "States": [ 0, 1 ] } } } \ No newline at end of file diff --git a/Content/Metadata/Collectible/AmmoThunderbolt.res b/Content/Metadata/Collectible/AmmoThunderbolt.res index 5a0b0a36..30891892 100644 --- a/Content/Metadata/Collectible/AmmoThunderbolt.res +++ b/Content/Metadata/Collectible/AmmoThunderbolt.res @@ -3,7 +3,8 @@ "Animations": { "Ammo": { - "Path": "Pickup/ammo_thunderbolt.aura" + "Path": "Pickup/ammo_thunderbolt.aura", + "States": [ 0, 1 ] } } } \ No newline at end of file diff --git a/Content/Metadata/Collectible/AmmoToaster.res b/Content/Metadata/Collectible/AmmoToaster.res index 8ca2d2e1..90844a45 100644 --- a/Content/Metadata/Collectible/AmmoToaster.res +++ b/Content/Metadata/Collectible/AmmoToaster.res @@ -3,7 +3,12 @@ "Animations": { "Ammo": { - "Path": "Pickup/ammo_toaster.aura" + "Path": "Pickup/ammo_toaster.aura", + "States": [ 0 ] + }, + "AmmoUpgraded": { + "Path": "Pickup/ammo_toaster_upgraded.aura", + "States": [ 1 ] } } } \ No newline at end of file diff --git a/Sources/Jazz2/Actors/Collectibles/AmmoCollectible.cpp b/Sources/Jazz2/Actors/Collectibles/AmmoCollectible.cpp index faf0b493..89fc76f2 100644 --- a/Sources/Jazz2/Actors/Collectibles/AmmoCollectible.cpp +++ b/Sources/Jazz2/Actors/Collectibles/AmmoCollectible.cpp @@ -1,4 +1,5 @@ #include "AmmoCollectible.h" +#include "../../ILevelHandler.h" #include "../../WeaponType.h" #include "../Player.h" @@ -45,7 +46,10 @@ namespace Jazz2::Actors::Collectibles case WeaponType::Thunderbolt: async_await RequestMetadataAsync("Collectible/AmmoThunderbolt"_s); break; } - SetAnimation(AnimState::Default); + // Show upgraded ammo if player has upgraded weapon + const auto& players = _levelHandler->GetPlayers(); + bool upgraded = (!players.empty() && (players[0]->GetWeaponUpgrades()[(std::uint8_t)_weaponType] & 0x01) != 0); + SetAnimation((AnimState)(upgraded ? 1 : 0)); SetFacingDirection(); diff --git a/Sources/Jazz2/Actors/Environment/Bird.cpp b/Sources/Jazz2/Actors/Environment/Bird.cpp index dac3837e..c805c2e7 100644 --- a/Sources/Jazz2/Actors/Environment/Bird.cpp +++ b/Sources/Jazz2/Actors/Environment/Bird.cpp @@ -183,7 +183,7 @@ namespace Jazz2::Actors::Environment _levelHandler->AddActor(shot2); PlaySfx("Fire"_s, 0.5f); - _fireCooldown = 48.0f; + _fireCooldown = 32.0f; } SetState(ActorState::CollideWithTileset, false); break; diff --git a/Sources/Jazz2/Compatibility/EventConverter.cpp b/Sources/Jazz2/Compatibility/EventConverter.cpp index 7486a9f9..b44d0846 100644 --- a/Sources/Jazz2/Compatibility/EventConverter.cpp +++ b/Sources/Jazz2/Compatibility/EventConverter.cpp @@ -823,7 +823,19 @@ namespace Jazz2::Compatibility Add(JJ2Event::FOOD_CHEESE, ConstantParamList(EventType::Food, { (uint8_t)FoodType::Cheese })); Add(JJ2Event::CRATE_AMMO, GetAmmoCrateConverter(0)); - Add(JJ2Event::CRATE_AMMO_BOUNCER, GetAmmoCrateConverter(1)); + Add(JJ2Event::CRATE_AMMO_BOUNCER, [](JJ2Level* level, uint32_t jj2Params) -> ConversionResult { + uint8_t eventParams[16]; + ConvertParamInt(jj2Params, { + { JJ2ParamUInt, 3 } // Weapon + }, eventParams); + + uint8_t type = eventParams[0] + 1; + if (type < 1 || type > 8) { + type = 1; // Fallback to Bouncer if out of range + } + + return { EventType::CrateAmmo, { type } }; + }); Add(JJ2Event::CRATE_AMMO_FREEZER, GetAmmoCrateConverter(2)); Add(JJ2Event::CRATE_AMMO_SEEKER, GetAmmoCrateConverter(3)); Add(JJ2Event::CRATE_AMMO_RF, GetAmmoCrateConverter(4)); diff --git a/Sources/Jazz2/Events/EventMap.cpp b/Sources/Jazz2/Events/EventMap.cpp index 31e469a6..bc9201d2 100644 --- a/Sources/Jazz2/Events/EventMap.cpp +++ b/Sources/Jazz2/Events/EventMap.cpp @@ -217,6 +217,11 @@ namespace Jazz2::Events // Linked actor was deactivated, but not destroyed // Reset its generator, so it can be respawned immediately std::uint32_t generatorIdx = *(std::uint32_t*)_eventLayout[tx + ty * _layoutSize.X].EventParams; + if (generatorIdx >= _generators.size()) { + // Do nothing if generator if wrongly configured + return; + } + _generators[generatorIdx].TimeLeft = 0.0f; _generators[generatorIdx].SpawnedActor = nullptr; }