Skip to content
Open
1 change: 1 addition & 0 deletions CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ This page lists all the individual contributions to the project by their author.
- Map Events 604 & 605 for checking if a specific Techno enters in a cell
- Warhead that can not kill
- `Pips.HideIfNoStrength` and `SelfHealing.EnabledBy` additions for shields
- Unit & infantry auto-conversion on ammo change
- **Starkku**:
- Misc. minor bugfixes & improvements
- AI script actions:
Expand Down
21 changes: 21 additions & 0 deletions docs/Fixed-or-Improved-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,27 @@ HarvesterDumpAmount=0.0 ; float point value
HarvesterDumpAmount= ; float point value
```

### Unit & infantry auto-conversion on ammo change

- Units & infantry can now be converted into another unit by ammo count.
- `Ammo.AutoConvertMinimumAmount` determines the minimal number of ammo at which a unit converts automatically after the ammo update.
- `Ammo.AutoConvertMaximumAmount` determines the maximum number of ammo at which a unit converts automatically after the ammo update.
- `Ammo.AutoConvertType` specify the new techno after the conversion. This unit must be of the same type of the original (vehicle -> vehicle or infantry -> infantry).
- Setting a negative number will disable ammo count check.

In `rulesmd.ini`:
```ini
[SOMETECHNO] ; InfantryType or VehicleType
Ammo.AutoConvertMinimumAmount=-1 ; integer
Ammo.AutoConvertMaximumAmount=-1 ; integer
Ammo.AutoConvertType= ; InfantryType or VehicleType
```

```{warning}
This auto-conversion feature requires [Ares](https://github.com/Ares-Developers/Ares).
Aircrafts weren't tested but if Ares supported them then this feature should work on them too.
```

## Veinholes & Weeds

### Veinholes
Expand Down
1 change: 1 addition & 0 deletions docs/Whats-New.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ New:
- [Tiberium eater logic](New-or-Enhanced-Logics.md#tiberium-eater) (by NetsuNegi)
- [Customize the damage taken when falling from a bridge](Fixed-or-Improved-Logics.md#customize-bridge-falling-down-damage) (by FlyStar)
- Dehardcoded 255 limit of `OverlayType` (by secsome)
- Unit & infantry auto-conversion on ammo change (by FS-21)

Vanilla fixes:
- Fixed sidebar not updating queued unit numbers when adding or removing units when the production is on hold (by CrimRecya)
Expand Down
40 changes: 40 additions & 0 deletions src/Ext/Techno/Body.Update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <Ext/Scenario/Body.h>
#include <Utilities/EnumFunctions.h>
#include <Utilities/AresFunctions.h>
#include <New/Type/Affiliated/TypeConvertGroup.h>


// TechnoClass_AI_0x6F9E50
Expand All @@ -37,6 +38,7 @@ void TechnoExt::ExtData::OnEarlyUpdate()
this->ApplyMindControlRangeLimit();
this->UpdateRecountBurst();
this->UpdateRearmInEMPState();
this->AmmoAutoConvertActions();
}

void TechnoExt::ExtData::ApplyInterceptor()
Expand Down Expand Up @@ -116,6 +118,44 @@ void TechnoExt::ExtData::DepletedAmmoActions()
pThis->QueueMission(Mission::Unload, true);
}

void TechnoExt::ExtData::AmmoAutoConvertActions()
{
auto const pThis = abstract_cast<TechnoClass*>(this->OwnerObject());
if (!pThis || pThis->GetTechnoType()->Ammo <= 0)
return;

const auto pTypeExt = this->TypeExtData;
const bool skipMinimum = pTypeExt->Ammo_AutoConvertMinimumAmount < 0;
const bool skipMaximum = pTypeExt->Ammo_AutoConvertMaximumAmount < 0;

if (skipMinimum && skipMaximum)
return;

const bool moreThanMinimum = pThis->Ammo >= pTypeExt->Ammo_AutoConvertMinimumAmount;
const bool lessThanMaximum = pThis->Ammo <= pTypeExt->Ammo_AutoConvertMaximumAmount;

if ((skipMinimum || moreThanMinimum) && (skipMaximum || lessThanMaximum))
{
const auto pFoot = abstract_cast<FootClass*>(pThis);

if (!pFoot)
return;

// Preparing the needed convert stuff
std::vector<TypeConvertGroup> convertPair;
ValueableVector<TechnoTypeClass*> convertFrom;
Nullable<TechnoTypeClass*> convertTo;
Nullable<AffectedHouse> convertAffectedHouses;

convertFrom.emplace_back(pThis->GetTechnoType());
convertTo = pTypeExt->Ammo_AutoConvertType;
convertAffectedHouses = AffectedHouse::Owner;
convertPair.emplace_back(convertFrom, convertTo, convertAffectedHouses);

TypeConvertGroup::Convert(pFoot, convertPair, pThis->Owner);
}
}

// TODO : Merge into new AttachEffects
bool TechnoExt::ExtData::CheckDeathConditions(bool isInLimbo)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Ext/Techno/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ class TechnoExt

UnitTypeClass* GetUnitTypeExtra() const;

void AmmoAutoConvertActions();

virtual ~ExtData() override;
virtual void InvalidatePointer(void* ptr, bool bRemoved) override { }
virtual void LoadFromStream(PhobosStreamReader& Stm) override;
Expand Down
8 changes: 8 additions & 0 deletions src/Ext/TechnoType/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,10 @@ void TechnoTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
this->Harvester_CanGuardArea.Read(exINI, pSection, "Harvester.CanGuardArea");
this->HarvesterScanAfterUnload.Read(exINI, pSection, "HarvesterScanAfterUnload");

this->Ammo_AutoConvertMinimumAmount.Read(exINI, pSection, "Ammo.AutoConvertMinimumAmount");
this->Ammo_AutoConvertMaximumAmount.Read(exINI, pSection, "Ammo.AutoConvertMaximumAmount");
this->Ammo_AutoConvertType.Read(exINI, pSection, "Ammo.AutoConvertType");

// Ares 0.2
this->RadarJamRadius.Read(exINI, pSection, "RadarJamRadius");

Expand Down Expand Up @@ -1122,6 +1126,10 @@ void TechnoTypeExt::ExtData::Serialize(T& Stm)

.Process(this->FallingDownDamage)
.Process(this->FallingDownDamage_Water)

.Process(this->Ammo_AutoConvertMinimumAmount)
.Process(this->Ammo_AutoConvertMaximumAmount)
.Process(this->Ammo_AutoConvertType)
;
}
void TechnoTypeExt::ExtData::LoadFromStream(PhobosStreamReader& Stm)
Expand Down
8 changes: 8 additions & 0 deletions src/Ext/TechnoType/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ class TechnoTypeExt
Valueable<double> FallingDownDamage;
Nullable<double> FallingDownDamage_Water;

Valueable<int> Ammo_AutoConvertMinimumAmount;
Valueable<int> Ammo_AutoConvertMaximumAmount;
Nullable<TechnoTypeClass*> Ammo_AutoConvertType;

ExtData(TechnoTypeClass* OwnerObject) : Extension<TechnoTypeClass>(OwnerObject)
, HealthBar_Hide { false }
, UIDescription {}
Expand Down Expand Up @@ -663,6 +667,10 @@ class TechnoTypeExt

, FallingDownDamage { 1.0 }
, FallingDownDamage_Water {}

, Ammo_AutoConvertMinimumAmount { -1 }
, Ammo_AutoConvertMaximumAmount { -1 }
, Ammo_AutoConvertType { nullptr }
{ }

virtual ~ExtData() = default;
Expand Down