diff --git a/README.md b/README.md index 531bdea541..d0a13668bc 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,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 - **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 +- **FS-21** - Dump Object Info enhancements, Powered.KillSpawns, Spawner.LimitRange, ScriptType Actions 71 to 113, MC deployer fixes, help with docs, Automatic Passenger Deletion, Customize resource storage - **AutoGavy** - interceptor logic, warhead critical damage system - **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/Fixed-or-Improved-Logics.md b/docs/Fixed-or-Improved-Logics.md index 9f0eb08ad8..2604df504b 100644 --- a/docs/Fixed-or-Improved-Logics.md +++ b/docs/Fixed-or-Improved-Logics.md @@ -168,6 +168,17 @@ In `rulesmd.ini`: Powered.KillSpawns=no ; boolean ``` +### Customize resource storage + +- Now Ares `Storage` feature can set which Tiberium type from `[Tiberiums]` list should be used for storing resources in structures with `Refinery.UseStorage=yes` and `Storage` > 0. +- This tag can not be used without Ares. + +In `rulesmd.ini`: +```ini +[General] +Storage.TiberiumIndex=-1 ; integer, [Tiberiums] list index +``` + ### Customizable unit image in art - `Image` tag in art INI is no longer limited to AnimationTypes and BuildingTypes, and can be applied to all TechnoTypes (InfantryTypes, VehicleTypes, AircraftTypes, BuildingTypes). diff --git a/docs/Whats-New.md b/docs/Whats-New.md index fd885309e8..08cc15f54a 100644 --- a/docs/Whats-New.md +++ b/docs/Whats-New.md @@ -264,6 +264,7 @@ New: - Added Production and Money to Dump Object Info command (by FS-21) - `EnemyUIName=` Now also works for other TechnoTypes (by Otamaa) - `DestroyAnim` & `DestroySound` for TerrainTypes (by Otamaa) +- `Storage.TiberiumIndex` for customizing resource storage in structures (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/Building/Body.cpp b/src/Ext/Building/Body.cpp index 7e023d7192..3fc7724434 100644 --- a/src/Ext/Building/Body.cpp +++ b/src/Ext/Building/Body.cpp @@ -3,6 +3,29 @@ template<> const DWORD Extension::Canary = 0x87654321; BuildingExt::ExtContainer BuildingExt::ExtMap; +void BuildingExt::StoreTiberium(BuildingClass* pThis, float amount, int idxTiberiumType, int idxStorageTiberiumType) +{ + auto const pDepositableTiberium = TiberiumClass::Array->GetItem(idxStorageTiberiumType); + float depositableTiberiumAmount = 0.0f; // Number of 'bails' that will be stored. + auto const pTiberium = TiberiumClass::Array->GetItem(idxTiberiumType); + + if (amount > 0.0) + { + if (auto pBuildingType = pThis->Type) + { + if (auto const pExt = BuildingTypeExt::ExtMap.Find(pBuildingType)) + { + if (pExt->Refinery_UseStorage) + { + // Store Tiberium in structures + depositableTiberiumAmount = (amount * pTiberium->Value) / pDepositableTiberium->Value; + pThis->Owner->GiveTiberium(depositableTiberiumAmount, idxStorageTiberiumType); + } + } + } + } +} + // ============================= // load / save diff --git a/src/Ext/Building/Body.h b/src/Ext/Building/Body.h index 84feae8552..dd026c4b97 100644 --- a/src/Ext/Building/Body.h +++ b/src/Ext/Building/Body.h @@ -1,11 +1,14 @@ #pragma once #include +#include +#include #include #include #include #include +#include class BuildingExt { @@ -49,4 +52,6 @@ class BuildingExt static bool LoadGlobals(PhobosStreamReader& Stm); static bool SaveGlobals(PhobosStreamWriter& Stm); + + static void StoreTiberium(BuildingClass* pThis, float amount, int idxTiberiumType, int idxStorageTiberiumType); }; \ No newline at end of file diff --git a/src/Ext/BuildingType/Body.cpp b/src/Ext/BuildingType/Body.cpp index 454d145d47..aa7bcee538 100644 --- a/src/Ext/BuildingType/Body.cpp +++ b/src/Ext/BuildingType/Body.cpp @@ -132,6 +132,7 @@ void BuildingTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI) } } + this->Refinery_UseStorage.Read(exINI, pSection, "Refinery.UseStorage"); } void BuildingTypeExt::ExtData::CompleteInitialization() @@ -151,6 +152,7 @@ void BuildingTypeExt::ExtData::Serialize(T& Stm) .Process(this->PowerPlantEnhancer_Factor) .Process(this->SuperWeapons) .Process(this->OccupierMuzzleFlashes) + .Process(this->Refinery_UseStorage) ; } diff --git a/src/Ext/BuildingType/Body.h b/src/Ext/BuildingType/Body.h index 5768e689a3..77ddd8faa2 100644 --- a/src/Ext/BuildingType/Body.h +++ b/src/Ext/BuildingType/Body.h @@ -24,6 +24,8 @@ class BuildingTypeExt DynamicVectorClass OccupierMuzzleFlashes; + Valueable Refinery_UseStorage; + ExtData(BuildingTypeClass* OwnerObject) : Extension(OwnerObject) , PowersUp_Owner { AffectedHouse::Owner } , PowersUp_Buildings {} @@ -31,6 +33,7 @@ class BuildingTypeExt , PowerPlantEnhancer_Amount {} , PowerPlantEnhancer_Factor {} , OccupierMuzzleFlashes() + , Refinery_UseStorage { false } { } virtual ~ExtData() = default; diff --git a/src/Ext/House/Hooks.cpp b/src/Ext/House/Hooks.cpp index aa91c67fc1..5aae6365d1 100644 --- a/src/Ext/House/Hooks.cpp +++ b/src/Ext/House/Hooks.cpp @@ -1,5 +1,7 @@ #include "Body.h" +#include "../Techno/Body.h" +#include "../Building/Body.h" #include DEFINE_HOOK(0x508C30, HouseClass_UpdatePower_UpdateCounter, 0x5) @@ -36,4 +38,28 @@ DEFINE_HOOK(0x508CF2, HouseClass_UpdatePower_PowerOutput, 0x7) pThis->PowerOutput += BuildingTypeExt::GetEnhancedPower(pBld, pThis); return 0x508D07; -} \ No newline at end of file +} + +DEFINE_HOOK(0x73E474, UnitClass_Unload_Storage, 0x6) +{ + GET(BuildingClass* const, pBuilding, EDI); + GET(int const, idxTiberium, EBP); + REF_STACK(float, amount, 0x1C); + + auto pTypeExt = BuildingTypeExt::ExtMap.Find(pBuilding->Type); + if (!pTypeExt) + return 0; + + if (!pBuilding->Owner) + return 0; + + auto storageTiberiumIndex = RulesExt::Global()->Storage_TiberiumIndex; + + if (pTypeExt->Refinery_UseStorage && storageTiberiumIndex >= 0) + { + BuildingExt::StoreTiberium(pBuilding, amount, idxTiberium, storageTiberiumIndex); + amount = 0.0f; + } + + return 0; +} diff --git a/src/Ext/Rules/Body.cpp b/src/Ext/Rules/Body.cpp index 9acb6d9b11..c6a0afca64 100644 --- a/src/Ext/Rules/Body.cpp +++ b/src/Ext/Rules/Body.cpp @@ -66,6 +66,7 @@ void RulesExt::ExtData::LoadBeforeTypeData(RulesClass* pThis, CCINIClass* pINI) INI_EX exINI(pINI); + this->Storage_TiberiumIndex.Read(exINI, GENERAL_SECTION, "Storage.TiberiumIndex"); this->RadApplicationDelay_Building.Read(exINI, "Radiation", "RadApplicationDelay.Building"); this->Pips_Shield.Read(exINI, "AudioVisual", "Pips.Shield"); this->Pips_Shield_Buildings.Read(exINI, "AudioVisual", "Pips.Shield.Building"); @@ -165,6 +166,7 @@ void RulesExt::ExtData::Serialize(T& Stm) .Process(this->JumpjetAllowLayerDeviation) .Process(this->AITargetTypesLists) .Process(this->AIScriptsLists) + .Process(this->Storage_TiberiumIndex) ; } diff --git a/src/Ext/Rules/Body.h b/src/Ext/Rules/Body.h index 19004b004a..0219a2cf7f 100644 --- a/src/Ext/Rules/Body.h +++ b/src/Ext/Rules/Body.h @@ -34,6 +34,7 @@ class RulesExt Valueable JumpjetCrash; Valueable JumpjetNoWobbles; Valueable JumpjetAllowLayerDeviation; + Valueable Storage_TiberiumIndex; ExtData(RulesClass* OwnerObject) : Extension(OwnerObject) , Pips_Shield { { -1,-1,-1 } } @@ -43,6 +44,7 @@ class RulesExt , JumpjetCrash { 5.0 } , JumpjetNoWobbles { false } , JumpjetAllowLayerDeviation { true } + , Storage_TiberiumIndex { -1 } { } virtual ~ExtData() = default;