Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -983,4 +983,6 @@ This page lists all the individual contributions to the project by their author.
- **Nuke** - Reload speed adjustment on promotion
- **frg2089 (舰队的偶像-岛风酱!)** - Fix `Slaved.OwnerWhenMasterKilled` not being respected when the master is sold or self-destructed
- **weiyongxuan** - Extended `CanTargetHouses` to allow targeting neutral houses
- **dh381-1** - Detonate ivan bomb on impact
- **dh381-1**:
- Detonate ivan bomb on impact
- Allow Ares Academy add country-level filters
1 change: 1 addition & 0 deletions Phobos.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<ClCompile Include="src\Ext\BuildingType\Hooks.cpp" />
<ClCompile Include="src\Ext\BuildingType\Hooks.Placing.cpp" />
<ClCompile Include="src\Ext\BuildingType\Hooks.Upgrade.cpp" />
<ClCompile Include="src\Ext\BuildingType\Hooks.Academy.cpp" />
<!-- src\Ext\Bullet -->
<ClCompile Include="src\Ext\Bullet\Body.cpp" />
<ClCompile Include="src\Ext\Bullet\Hooks.cpp" />
Expand Down
22 changes: 22 additions & 0 deletions docs/New-or-Enhanced-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,28 @@ SpyEffect.VictimSuperWeapon= ; SuperWeaponType
SpyEffect.InfiltratorSuperWeapon= ; SuperWeaponType
```

## Country

### Allow Ares Academy add country-level filters

- Ares' Academy feature could previously only add `Academy.Types` and `Academy.Ignore` to buildings. Now, `Academy.Country.Types.*` and `Academy.Country.Ignore.*` can be used to add country-level filters to buildings.

In `rulesmd.ini`:
```ini
[SOMEBUILDING] ; BuildingType

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the flag in country sections merely serves as a global enabling statement for building flags, then its documentation paragraph only needs to be placed in the Buildings section, just as a techno flag is not regarded as a global feature simply because a toggle in [General] is also added at the same time.

Academy.Country.Types.N= ; List of TechnoType, empty for all types
Academy.Country.Ignore.N= ; List of TechnoType
; Where N is 0,1,2...15.
```

- Additionally, `Academy.AllowCountryFilter` must be set for a country to enable this feature. Only countries with this feature enabled will use the academy's `Academy.Country.Types.*` and `Academy.Country.Ignore.*` instead of `Academy.Types` and `Academy.Ignore`.

In `rulesmd.ini`:
```ini
[SOMECOUNTRY] ; Country
Academy.AllowCountryFilter=false ; boolean
```

## Infantry

### Allow infantry to perform type conversion when deploying and undeploying
Expand Down
1 change: 1 addition & 0 deletions docs/Whats-New.md
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ HideShakeEffects=false ; boolean
- Allowed `SW.ShowCameo` and `SW.ManualFire` to work independently of `SW.AutoFire` (by Noble_Fish)
- [Added a global default value for `KeepAlive`](Fixed-or-Improved-Logics.md#add-a-global-default-value-for-keepalive) (by FlyStar)
- Fixed the bug that Ares tunnel-type buildings cannot unload via the Deploy hotkey or command bar button (by Noble_Fish)
- [Allow Ares Academy add country-level filters](New-or-Enhanced-Logics.md#allow-ares-academy-add-country-level-filters) (by dh381)
```

### 0.5
Expand Down
28 changes: 26 additions & 2 deletions src/Ext/BuildingType/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ void BuildingTypeExt::LoadFromINIFile(CCINIClass* const pINI)
auto pArtINI = &CCINIClass::INI_Art;
INI_EX exINI(pINI);
INI_EX exArtINI(pArtINI);
char tempBuffer[0x20];

this->PowersUp_Owner.Read(exINI, pSection, "PowersUp.Owner");
this->PowersUp_Buildings.Read(exINI, pSection, "PowersUp.Buildings");
Expand Down Expand Up @@ -296,7 +297,6 @@ void BuildingTypeExt::LoadFromINIFile(CCINIClass* const pINI)

for (int i = 0; i < pThis->NumberOfDocks; ++i)
{
char tempBuffer[32];
_snprintf_s(tempBuffer, sizeof(tempBuffer), "AircraftDockingDir%d", i);
nLandingDir.Read(exINI, pSection, tempBuffer);

Expand Down Expand Up @@ -334,6 +334,24 @@ void BuildingTypeExt::LoadFromINIFile(CCINIClass* const pINI)
this->RoofProductionAnimPoweredEffect.Read(exArtINI, pArtSection, "RoofProductionAnimPoweredEffect");
this->RoofProductionAnimPoweredSpecial.Read(exArtINI, pArtSection, "RoofProductionAnimPoweredSpecial");

this->Academy_Infantry_Veterancy.Read(exINI, pSection, "Academy.InfantryVeterancy");
this->Academy_Vehicle_Veterancy.Read(exINI, pSection, "Academy.VehicleVeterancy");
this->Academy_Aircraft_Veterancy.Read(exINI, pSection, "Academy.AircraftVeterancy");
this->Academy_Building_Veterancy.Read(exINI, pSection, "Academy.BuildingVeterancy");
this->Academy = Academy_Infantry_Veterancy > 0.0
|| Academy_Vehicle_Veterancy > 0.0
|| Academy_Aircraft_Veterancy > 0.0
|| Academy_Building_Veterancy > 0.0;

for (size_t idx = 0; idx < std::min(std::size(this->Academy_Country_Types), std::size(this->Academy_Country_Ignore)); ++idx)
{
_snprintf_s(tempBuffer, sizeof(tempBuffer), "Academy.Country.Types.%d", idx);
this->Academy_Country_Types[idx].Read(exINI, pSection, tempBuffer);

_snprintf_s(tempBuffer, sizeof(tempBuffer), "Academy.Country.Ignore.%d", idx);
this->Academy_Country_Ignore[idx].Read(exINI, pSection, tempBuffer);
}

// Ares tag
this->SpyEffect_Custom.Read(exINI, pSection, "SpyEffect.Custom");
if (SuperWeaponTypeClass::Array.Count > 0)
Expand All @@ -346,7 +364,6 @@ void BuildingTypeExt::LoadFromINIFile(CCINIClass* const pINI)

if (pThis->MaxNumberOccupants > 10)
{
char tempBuffer[32];
this->OccupierMuzzleFlashes.clear();
this->OccupierMuzzleFlashes.resize(pThis->MaxNumberOccupants);

Expand Down Expand Up @@ -496,6 +513,13 @@ void BuildingTypeExt::Serialize(T& Stm)
.Process(this->RoofProductionAnimPoweredLight)
.Process(this->RoofProductionAnimPoweredEffect)
.Process(this->RoofProductionAnimPoweredSpecial)
.Process(this->Academy)
.Process(this->Academy_Infantry_Veterancy)
.Process(this->Academy_Vehicle_Veterancy)
.Process(this->Academy_Aircraft_Veterancy)
.Process(this->Academy_Building_Veterancy)
.Process(this->Academy_Country_Types)
.Process(this->Academy_Country_Ignore)

// Ares 0.2
.Process(this->CloningFacility)
Expand Down
16 changes: 16 additions & 0 deletions src/Ext/BuildingType/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ class BuildingTypeExt final : public TechnoTypeExt
Nullable<bool> RoofProductionAnimPoweredEffect;
Nullable<bool> RoofProductionAnimPoweredSpecial;

bool Academy;
Valueable<double> Academy_Infantry_Veterancy;
Valueable<double> Academy_Vehicle_Veterancy;
Valueable<double> Academy_Aircraft_Veterancy;
Valueable<double> Academy_Building_Veterancy;
ValueableVector<TechnoTypeClass*> Academy_Country_Types[16];
ValueableVector<TechnoTypeClass*> Academy_Country_Ignore[16];

// Ares 0.2
Valueable<bool> CloningFacility;

Expand Down Expand Up @@ -253,6 +261,14 @@ class BuildingTypeExt final : public TechnoTypeExt
, RoofProductionAnimPoweredEffect { }
, RoofProductionAnimPoweredSpecial { }

, Academy { false }
, Academy_Infantry_Veterancy { 0.0 }
, Academy_Vehicle_Veterancy { 0.0 }
, Academy_Aircraft_Veterancy { 0.0 }
, Academy_Building_Veterancy { 0.0 }
, Academy_Country_Types {}
, Academy_Country_Ignore {}

// Ares 0.2
, CloningFacility { false }

Expand Down
197 changes: 197 additions & 0 deletions src/Ext/BuildingType/Hooks.Academy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
#include "Body.h"

#include <Ext/House/Body.h>
#include <Ext/Building/Body.h>
#include <Ext/BuildingType/Body.h>
#include <Ext/Techno/Body.h>

static void UpdateAcademy(HouseExt* pHouseExt, BuildingClass* pAcademy, bool added)
{
const auto it = std::find(pHouseExt->Academies.cbegin(), pHouseExt->Academies.cend(), pAcademy);

if (added == (it != pHouseExt->Academies.cend()))
return;

if (added)
pHouseExt->Academies.push_back(pAcademy);
else
pHouseExt->Academies.erase(it);
}

static void ApplyAcademy(TechnoClass* const pTechno, AbstractType const considerAs)
{
if (Unsorted::ScenarioInit)
return;

const auto pType = pTechno->GetTechnoType();

if (!pType->Trainable)
return;

const auto pHouseExt = HouseExt::Fetch(pTechno->Owner);
const auto pHouseTypeExt = HouseTypeExt::Fetch(pTechno->Owner->Type);
const int countryIdx = pTechno->Owner->Type->ArrayIndex;

if (!pHouseTypeExt->Academy_AllowCountryFilter)
return;

double maximumBonus = 0.0;

for (const auto pBuilding : pHouseExt->Academies)
{
const auto pBuildingType = pBuilding->Type;
const auto pBuildingTypeExt = BuildingTypeExt::Fetch(pBuildingType);

const auto& academyWhiteList = pBuildingTypeExt->Academy_Country_Types[countryIdx];
const auto& academyBlackList = pBuildingTypeExt->Academy_Country_Ignore[countryIdx];

const bool canAffect = (academyWhiteList.empty() || academyWhiteList.Contains(pType))
&& !academyBlackList.Contains(pType);

if (!canAffect)
continue;

double veterancyBonus = 0.0;

switch (considerAs)
{
case AbstractType::Infantry:
veterancyBonus = pBuildingTypeExt->Academy_Infantry_Veterancy;
break;

case AbstractType::Unit:
veterancyBonus = pBuildingTypeExt->Academy_Vehicle_Veterancy;
break;

case AbstractType::Aircraft:
veterancyBonus = pBuildingTypeExt->Academy_Aircraft_Veterancy;
break;

case AbstractType::Building:
veterancyBonus = pBuildingTypeExt->Academy_Building_Veterancy;
break;

default:
break;
}

if (maximumBonus < veterancyBonus)
maximumBonus = veterancyBonus;
}

auto& value = pTechno->Veterancy.Veterancy;
value = static_cast<float>(TechnoExt::Fetch(pTechno)->OriginVeterancy);

if (maximumBonus > value)
value = static_cast<float>(std::min(maximumBonus, RulesClass::Instance->VeteranCap));
}

static void SetOriginVeterancy(TechnoClass* pTechno)
{
const auto pHouse = pTechno->Owner;

switch (pTechno->WhatAmI())
{
case AbstractType::Infantry:
if (pHouse->BarracksInfiltrated)
TechnoExt::Fetch(pTechno)->OriginVeterancy = 1.0;

break;

case AbstractType::Unit:
if (pHouse->WarFactoryInfiltrated)
TechnoExt::Fetch(pTechno)->OriginVeterancy = 1.0;

break;

default:
break;
}
}

DEFINE_HOOK(0x446366, BuildingClass_Place_Academy, 0x6)
{
GET(BuildingClass*, pThis, EBP);

if (BuildingTypeExt::Fetch(pThis->Type)->Academy)
UpdateAcademy(HouseExt::Fetch(pThis->Owner), pThis, true);

return 0;
}

DEFINE_HOOK(0x445905, BuildingClass_Remove_Academy, 0x6)
{
GET(BuildingClass*, pThis, ESI);

if (pThis->IsOnMap && BuildingTypeExt::Fetch(pThis->Type)->Academy)
UpdateAcademy(HouseExt::Fetch(pThis->Owner), pThis, false);

return 0;
}

DEFINE_HOOK(0x448AB2, BuildingClass_SetOwningHouse_Remove_Academy, 0x6)
{
GET(BuildingClass*, pThis, ESI);

if (pThis->IsOnMap && BuildingTypeExt::Fetch(pThis->Type)->Academy)
UpdateAcademy(HouseExt::Fetch(pThis->Owner), pThis, false);

return 0;
}

DEFINE_HOOK(0x4491D5, BuildingClass_SetOwningHouse_Add_Academy, 0x6)
{
GET(BuildingClass*, pThis, ESI);

if (pThis->IsOnMap && BuildingTypeExt::Fetch(pThis->Type)->Academy)
UpdateAcademy(HouseExt::Fetch(pThis->Owner), pThis, true);

return 0;
}

DEFINE_HOOK(0x517D57, InfantryClass_Init_Academy, 0x6)
{
GET(InfantryClass*, pThis, ESI);

SetOriginVeterancy(pThis);
ApplyAcademy(pThis, AbstractType::Infantry);

return 0;
}

DEFINE_HOOK_AGAIN(0x735678, UnitClass_Init_Academy, 0x6) // CTOR
DEFINE_HOOK(0x74689B, UnitClass_Init_Academy, 0x6)
{
GET(UnitClass*, pThis, ESI);

SetOriginVeterancy(pThis);

if (pThis->Type->ConsideredAircraft)
ApplyAcademy(pThis, AbstractType::Aircraft);
else if (pThis->Type->Organic)
ApplyAcademy(pThis, AbstractType::Infantry);
else
ApplyAcademy(pThis, AbstractType::Unit);

return 0;
}

DEFINE_HOOK(0x413FD2, AircraftClass_Init_Academy, 0x6)
{
GET(AircraftClass*, pThis, ESI);

SetOriginVeterancy(pThis);
ApplyAcademy(pThis, AbstractType::Aircraft);

return 0;
}

DEFINE_HOOK(0x442D34, BuildingClass_Init_Academy, 0x6)
{
GET(BuildingClass*, pThis, ESI);

SetOriginVeterancy(pThis);
ApplyAcademy(pThis, AbstractType::Building);

return 0;
}
1 change: 1 addition & 0 deletions src/Ext/House/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,7 @@ void HouseExt::Serialize(T& Stm)
.Process(this->FreeRadar)
.Process(this->ForceRadar)
.Process(this->PlayerAutoRepair)
.Process(this->Academies)
//.Process(this->BeaconsPlacedOrder) beacon is not saved, so this follows it.
;
}
Expand Down
3 changes: 3 additions & 0 deletions src/Ext/House/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class HouseExt final : public AbstractExt, public Detach::Listener<BuildingClass

std::array<int, 3> BeaconsPlacedOrder;

std::vector<BuildingClass*> Academies;

HouseExt(HouseClass* OwnerObject) : AbstractExt(OwnerObject)
, PowerPlantEnhancers {}
, OwnedLimboDeliveredBuildings {}
Expand Down Expand Up @@ -107,6 +109,7 @@ class HouseExt final : public AbstractExt, public Detach::Listener<BuildingClass
, ForceRadar(false)
, PlayerAutoRepair(true)
, BeaconsPlacedOrder { 0, 0, 0 }
, Academies {}
{ }

bool OwnsLimboDeliveredBuilding(BuildingClass* pBuilding) const;
Expand Down
3 changes: 3 additions & 0 deletions src/Ext/HouseType/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ void HouseTypeExt::LoadFromINIFile(CCINIClass* pINI)
this->VeteranDefenses.Read(exINI, pSection, "VeteranDefenses");

this->RevealHouses.Read<false, true>(exINI, pSection, "RevealHouses");

this->Academy_AllowCountryFilter.Read(exINI, pSection, "Academy.AllowCountryFilter");
}

template <typename T>
Expand All @@ -41,6 +43,7 @@ void HouseTypeExt::Serialize(T& Stm)
.Process(this->VeteranBuildings)
.Process(this->VeteranDefenses)
.Process(this->RevealHouses)
.Process(this->Academy_AllowCountryFilter)
;
}

Expand Down
Loading
Loading