diff --git a/README.md b/README.md index fc1cc8eca5..4e1c7ff8cf 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ Credits - **secsome (SEC-SOME)** - debug info dump hotkey, refactoring & porting of Ares helper code, introducing more Ares-derived stuff, disguise removal warhead, Mind Control removal warhead, Mind Control enhancement, shields, AnimList.PickRandom, MoveToCell fix, unlimited waypoints, Build At trigger action buildup anim fix, Undeploy building into a unit plays `EVA_NewRallyPointEstablished` fix, custom ore gathering anim, TemporaryClass related crash, Retry dialog on mission failure, Default disguise for individual InfantryTypes, PowerPlant Enhancer, SaveGame Trigger Action, QuickSave command, Numeric variables, Custom gravity for projectiles, Retint map actions bugfix, Sharpnel enhancement - **Otamaa (Fahroni, BoredEXE)** - help with CellSpread, ported and fixed custom RadType code, togglable ElectricBolt bolts, customizable Chrono Locomotor properties per TechnoClass, DebrisMaximums fixes, Anim-to-Unit, NotHuman anim sequences improvements, Customizable OpenTopped Properties, hooks for ScriptType Actions 92 & 93, ore stage threshold for `HideIfNoOre`, occupied building `MuzzleFlashX` bugfix,`EnemyUIName=` for other TechnoTypes, TerrainType `DestroyAnim` & `DestroySound` - **E1 Elite** - TileSet 255 and above bridge repair fix -- **FS-21** - Dump Object Info enhancements, Powered.KillSpawns, Spawner.LimitRange, ScriptType Actions 71 to 113, MC deployer fixes, help with docs, Automatic Passenger Deletion, Fire SW At Location Trigger Action, Fire SW At Waypoint Trigger Action, Kill Object Automatically, Customize resource storage, Override Uncloaked Underwater attack behavior, AI Aircraft docks fix +- **FS-21** - Dump Object Info enhancements, Powered.KillSpawns, Spawner.LimitRange, ScriptType Actions 71 to 113, MC deployer fixes, help with docs, Automatic Passenger Deletion, Fire SW At Location Trigger Action, Fire SW At Waypoint Trigger Action, Kill Object Automatically, Customize resource storage, Override Uncloaked Underwater attack behavior, AI Aircraft docks fix, Shared Ammo - **AutoGavy** - interceptor logic, warhead critical damage system, Customize resource storage - **ChrisLv_CN** - interceptor logic, LaserTrails, laser fixes, general assistance (work relicensed under [following permission](images/ChrisLv-relicense.png)) - **Xkein** - general assistance, YRpp edits diff --git a/docs/New-or-Enhanced-Logics.md b/docs/New-or-Enhanced-Logics.md index 209928b4dc..0359ced4ef 100644 --- a/docs/New-or-Enhanced-Logics.md +++ b/docs/New-or-Enhanced-Logics.md @@ -287,6 +287,24 @@ OpenTopped.DamageMultiplier=1.3 ; float OpenTopped.WarpDistance=8 ; integer ``` +### Shared Ammo + +- Transports with `OpenTopped=yes` and `Ammo.Shared=yes` will transfer ammo to passengers that have `Ammo.Shared=yes`. +In addition, a transport can filter who will receive ammo if passengers have the same value in `Ammo.Shared.Group=` of the transport, ignoring other passengers with different groups values. +- Transports with `Ammo.Shared.Group=-1` will transfer ammo to any passenger with `Ammo.Shared=yes` ignoring the group. +- Transports must have ammo and should be able to reload ammo. + +In `rulesmd.ini`: +```ini +[SOMETECHNO1] ; TechnoType, transport with OpenTopped=yes +Ammo.Shared=no ; boolean +Ammo.Shared.Group=-1 ; integer + +[SOMETECHNO2] ; TechnoType, passenger +Ammo.Shared=no ; boolean +Ammo.Shared.Group=-1 ; integer +``` + ## Technos ### Mind Control enhancement diff --git a/docs/Whats-New.md b/docs/Whats-New.md index 38c06bc1c3..7205fc38f0 100644 --- a/docs/Whats-New.md +++ b/docs/Whats-New.md @@ -275,6 +275,7 @@ New: - Trigger Action 506 for Firing at waypoint (by FS-21) - New ways for self-killing objects under certaing cases (by FS-21) - `ForceWeapon.Naval.Decloacked` for overriding uncloaked underwater attack behavior (by FS-21) +- Shared Ammo for transports to passengers (by FS-21) Vanilla fixes: - Fixed laser drawing code to allow for thicker lasers in house color draw mode (by Kerbiter, ChrisLv_CN) diff --git a/src/Ext/Techno/Body.cpp b/src/Ext/Techno/Body.cpp index fc0471c841..3c9fedd229 100644 --- a/src/Ext/Techno/Body.cpp +++ b/src/Ext/Techno/Body.cpp @@ -453,6 +453,47 @@ void TechnoExt::CheckDeathConditions(TechnoClass* pThis) } } +void TechnoExt::UpdateSharedAmmo(TechnoClass* pThis) +{ + if (!pThis) + return; + + if (const auto pType = pThis->GetTechnoType()) + { + if (pType->OpenTopped && pThis->Passengers.NumPassengers > 0) + { + if (const auto pExt = TechnoTypeExt::ExtMap.Find(pType)) + { + if (pExt->Ammo_Shared && pType->Ammo > 0) + { + auto passenger = pThis->Passengers.FirstPassenger; + TechnoTypeClass* passengerType; + + do + { + passengerType = passenger->GetTechnoType(); + auto pPassengerExt = TechnoTypeExt::ExtMap.Find(passengerType); + + if (pPassengerExt && pPassengerExt->Ammo_Shared) + { + if (pExt->Ammo_Shared_Group < 0 || pExt->Ammo_Shared_Group == pPassengerExt->Ammo_Shared_Group) + { + if (pThis->Ammo > 0 && (passenger->Ammo < passengerType->Ammo)) + { + pThis->Ammo--; + passenger->Ammo++; + } + } + } + + passenger = static_cast(passenger->NextObject); + } while (passenger); + } + } + } + } +} + // ============================= // load / save diff --git a/src/Ext/Techno/Body.h b/src/Ext/Techno/Body.h index f9f8e5e8f9..77ffe79168 100644 --- a/src/Ext/Techno/Body.h +++ b/src/Ext/Techno/Body.h @@ -94,6 +94,7 @@ class TechnoExt static void CheckDeathConditions(TechnoClass* pThis); static void ObjectKilledBy(TechnoClass* pThis, TechnoClass* pKiller); static void EatPassengers(TechnoClass* pThis); + static void UpdateSharedAmmo(TechnoClass* pThis); static bool CanFireNoAmmoWeapon(TechnoClass* pThis, int weaponIndex); }; diff --git a/src/Ext/Techno/Hooks.cpp b/src/Ext/Techno/Hooks.cpp index 7e050e0a65..872f098c9c 100644 --- a/src/Ext/Techno/Hooks.cpp +++ b/src/Ext/Techno/Hooks.cpp @@ -414,3 +414,13 @@ DEFINE_HOOK(0x6F3428, TechnoClass_GetWeapon_ForceWeapon, 0x6) return 0; } + +// Update ammo rounds +DEFINE_HOOK(0x6FB086, TechnoClass_Reload_ReloadAmount, 0x8) +{ + GET(TechnoClass* const, pThis, ECX); + + TechnoExt::UpdateSharedAmmo(pThis); + + return 0; +} diff --git a/src/Ext/TechnoType/Body.cpp b/src/Ext/TechnoType/Body.cpp index 07d3f44224..ff13041dad 100644 --- a/src/Ext/TechnoType/Body.cpp +++ b/src/Ext/TechnoType/Body.cpp @@ -225,6 +225,8 @@ void TechnoTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI) this->EnemyUIName.Read(exINI, pSection, "EnemyUIName"); this->ForceWeapon_Naval_Decloaked.Read(exINI, pSection, "ForceWeapon.Naval.Decloaked"); + this->Ammo_Shared.Read(exINI, pSection, "Ammo.Shared"); + this->Ammo_Shared_Group.Read(exINI, pSection, "Ammo.Shared.Group"); } template @@ -301,6 +303,8 @@ void TechnoTypeExt::ExtData::Serialize(T& Stm) .Process(this->DeployingAnim_UseUnitDrawer) .Process(this->EnemyUIName) .Process(this->ForceWeapon_Naval_Decloaked) + .Process(this->Ammo_Shared) + .Process(this->Ammo_Shared_Group) ; } void TechnoTypeExt::ExtData::LoadFromStream(PhobosStreamReader& Stm) diff --git a/src/Ext/TechnoType/Body.h b/src/Ext/TechnoType/Body.h index 9c3bf96b2d..ddadc73584 100644 --- a/src/Ext/TechnoType/Body.h +++ b/src/Ext/TechnoType/Body.h @@ -101,6 +101,9 @@ class TechnoTypeExt Valueable ForceWeapon_Naval_Decloaked; + Valueable Ammo_Shared; + Valueable Ammo_Shared_Group; + struct LaserTrailDataEntry { ValueableIdx idxType; @@ -187,6 +190,8 @@ class TechnoTypeExt , Death_NoAmmo { false } , Death_Countdown { 0 } , ForceWeapon_Naval_Decloaked { -1 } + , Ammo_Shared { false } + , Ammo_Shared_Group { -1 } { } virtual ~ExtData() = default;