Skip to content

Unit & infantry auto-conversion on ammo change #1653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ This page lists all the individual contributions to the project by their author.
- Warhead activation target health thresholds enhancements
- Event 606: AttachEffect is attaching to a Techno
- Linked superweapons
- Unit & infantry auto-conversion on ammo change
- **Starkku**:
- Misc. minor bugfixes & improvements
- AI script actions:
Expand Down
2 changes: 1 addition & 1 deletion YRpp
Submodule YRpp updated 1 files
+3 −3 ScenarioClass.h
21 changes: 21 additions & 0 deletions docs/Fixed-or-Improved-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -1804,6 +1804,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 @@ -425,6 +425,7 @@ New:
- [Damaged aircraft image changes](New-or-Enhanced-Logics.md#damaged-aircraft-image-changes) (by Fryone)
- [Additional attached animation position customizations](Fixed-or-Improved-Logics.md#attached-animation-position-customization) (by Starkku)
- Use `SkipCrushSlowdown=true` to avoid the bug related to `Accelerates=true` and `MovementZone=CrushAll` (by TaranDahl)
- 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
29 changes: 29 additions & 0 deletions src/Ext/Techno/Body.Update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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 @@ -43,6 +44,7 @@ void TechnoExt::ExtData::OnEarlyUpdate()
this->ApplyMindControlRangeLimit();
this->UpdateRecountBurst();
this->UpdateRearmInEMPState();
this->AmmoAutoConvertActions();

if (this->AttackMoveFollowerTempCount)
this->AttackMoveFollowerTempCount--;
Expand Down Expand Up @@ -198,6 +200,33 @@ void TechnoExt::ExtData::DepletedAmmoActions()
pThis->QueueMission(Mission::Unload, true);
}

void TechnoExt::ExtData::AmmoAutoConvertActions()
{
const auto pThis = this->OwnerObject();
const auto pTypeExt = this->TypeExtData;

if (!pTypeExt || pThis->GetTechnoType()->Ammo <= 0)
return;

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

if (skipMinimum && skipMaximum)
return;

if ((skipMinimum || pThis->Ammo >= pTypeExt->Ammo_AutoConvertMinimumAmount) // More than minimum
&& (skipMaximum || pThis->Ammo <= pTypeExt->Ammo_AutoConvertMaximumAmount)) // Less than maximum
{
const auto pFoot = abstract_cast<FootClass*, true>(pThis);

if (!pFoot)
return;

if (pTypeExt->Ammo_AutoConvertType.isset())
TechnoExt::ConvertToType(pFoot, pTypeExt->Ammo_AutoConvertType);
}
}

// 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 @@ -184,6 +184,8 @@ class TechnoExt
void ResetDelayedFireTimer();
void UpdateTintValues();

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 @@ -908,6 +908,10 @@ void TechnoTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
this->AttackMove_StopWhenTargetAcquired.Read(exINI, pSection, "AttackMove.StopWhenTargetAcquired");
this->AttackMove_PursuitTarget.Read(exINI, pSection, "AttackMove.PursuitTarget");

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 @@ -1511,6 +1515,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)

.Process(this->FiringForceScatter)

.Process(this->FireUp)
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 @@ -390,6 +390,10 @@ class TechnoTypeExt
Valueable<double> FallingDownDamage;
Nullable<double> FallingDownDamage_Water;

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

Valueable<bool> FiringForceScatter;

Valueable<int> FireUp;
Expand Down Expand Up @@ -752,6 +756,10 @@ class TechnoTypeExt
, FallingDownDamage { 1.0 }
, FallingDownDamage_Water {}

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

, FiringForceScatter { true }

, FireUp { -1 }
Expand Down
Loading