Skip to content

Commit

Permalink
Allow customizing AI superweapon logic delay
Browse files Browse the repository at this point in the history
  • Loading branch information
Starkku committed Aug 25, 2024
1 parent d336bc7 commit 998505f
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ This page lists all the individual contributions to the project by their author.
- Option to enable parsing 8-bit RGB values from `[ColorAdd]` instead of RGB565
- Customizing height at which subterranean units travel
- `MovementZone=Subterannean` harvester fix
- AI superweapon delay timer customization
- **Morton (MortonPL)**:
- `XDrawOffset` for animations
- Shield passthrough & absorption
Expand Down
10 changes: 10 additions & 0 deletions docs/New-or-Enhanced-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,16 @@ This currently has same limitations as `AirburstWeapon` in that it does not prop

## Super Weapons

### AI Superweapon delay timer

- By default AI houses only process superweapon logic e.g checks if it can fire any superweapons firing them at randomized intervals of 106 to 112 game frames. This behaviour can now be customized by setting explicit delay, or disabling it entirely. Values of 0 and below disable the delay and cause AI houses to check superweapons on every game frame.

In `rulesmd.ini`:
```ini
[General]
AISuperWeaponDelay= ; integer, game frames
```

### Convert TechnoType

- Warheads can now change TechnoTypes of affected units to other Types in the same category (infantry to infantry, vehicles to vehicles, aircraft to aircraft).
Expand Down
1 change: 1 addition & 0 deletions docs/Whats-New.md
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ New:
- Option for Warhead to remove all shield types at once (by Starkku)
- Allow customizing voxel light source position (by Kerbiter, Morton, based on knowledge of thomassnedon)
- Option to fix voxel light source being offset and incorrectly tilting on slopes (by Kerbiter)
- AI superweapon delay timer customization (by Starkku)
Vanilla fixes:
- Allow AI to repair structures built from base nodes/trigger action 125/SW delivery in single player missions (by Trsdy)
Expand Down
1 change: 1 addition & 0 deletions src/Ext/House/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ void HouseExt::ExtData::Serialize(T& Stm)
.Process(this->Factory_VehicleType)
.Process(this->Factory_NavyType)
.Process(this->Factory_AircraftType)
.Process(this->AISuperWeaponDelayTimer)
.Process(this->RepairBaseNodes)
.Process(this->LastBuiltNavalVehicleType)
.Process(this->ProducingNavalUnitTypeIndex)
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 @@ -35,6 +35,8 @@ class HouseExt
BuildingClass* Factory_NavyType;
BuildingClass* Factory_AircraftType;

CDTimerClass AISuperWeaponDelayTimer;

//Read from INI
bool RepairBaseNodes[3];

Expand All @@ -53,6 +55,7 @@ class HouseExt
, Factory_VehicleType { nullptr }
, Factory_NavyType { nullptr }
, Factory_AircraftType { nullptr }
, AISuperWeaponDelayTimer {}
, RepairBaseNodes { false,false,false }
, LastBuiltNavalVehicleType { -1 }
, ProducingNavalUnitTypeIndex { -1 }
Expand Down
35 changes: 35 additions & 0 deletions src/Ext/House/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,38 @@ DEFINE_HOOK(0x50B669, HouseClass_ShouldDisableCameo, 0x5)

return 0;
}

DEFINE_HOOK(0x4F9038, HouseClass_ExpertAI_Superweapons, 0x5)
{
enum { SkipSWProcess = 0x4FD7A0 };

if (RulesExt::Global()->AISuperWeaponDelay.isset())
return SkipSWProcess;

return 0;
}

DEFINE_HOOK(0x4F9038, HouseClass_AI_Superweapons, 0x5)
{
GET(HouseClass*, pThis, ESI);

if (!RulesExt::Global()->AISuperWeaponDelay.isset() || pThis->IsControlledByHuman() || pThis->Type->MultiplayPassive)
return 0;

int delay = RulesExt::Global()->AISuperWeaponDelay.Get();

if (delay > 0)
{
auto const pExt = HouseExt::ExtMap.Find(pThis);

if (pExt->AISuperWeaponDelayTimer.HasTimeLeft())
return 0;

pExt->AISuperWeaponDelayTimer.Start(delay);
}

if (!SessionClass::IsCampaign() || pThis->IQLevel2 >= RulesClass::Instance->SuperWeapons)
pThis->AI_TryFireSW();

return 0;
}
2 changes: 2 additions & 0 deletions src/Ext/Rules/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void RulesExt::ExtData::LoadBeforeTypeData(RulesClass* pThis, CCINIClass* pINI)
this->AIChronoSphereSW.Read(exINI, GameStrings::General, "AIChronoSphereSW");
this->AIChronoWarpSW.Read(exINI, GameStrings::General, "AIChronoWarpSW");
this->SubterraneanHeight.Read(exINI, GameStrings::General, "SubterraneanHeight");
this->AISuperWeaponDelay.Read(exINI, GameStrings::General, "AISuperWeaponDelay");
this->UseGlobalRadApplicationDelay.Read(exINI, GameStrings::Radiation, "UseGlobalRadApplicationDelay");
this->RadApplicationDelay_Building.Read(exINI, GameStrings::Radiation, "RadApplicationDelay.Building");
this->RadBuildingDamageMaxCount.Read(exINI, GameStrings::Radiation, "RadBuildingDamageMaxCount");
Expand Down Expand Up @@ -264,6 +265,7 @@ void RulesExt::ExtData::Serialize(T& Stm)
.Process(this->AIChronoSphereSW)
.Process(this->AIChronoWarpSW)
.Process(this->SubterraneanHeight)
.Process(this->AISuperWeaponDelay)
.Process(this->UseGlobalRadApplicationDelay)
.Process(this->RadApplicationDelay_Building)
.Process(this->RadBuildingDamageMaxCount)
Expand Down
2 changes: 2 additions & 0 deletions src/Ext/Rules/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class RulesExt
ValueableIdx<SuperWeaponTypeClass> AIChronoSphereSW;
ValueableIdx<SuperWeaponTypeClass> AIChronoWarpSW;
Valueable<int> SubterraneanHeight;
Nullable<int> AISuperWeaponDelay;
Valueable<bool> UseGlobalRadApplicationDelay;
Valueable<int> RadApplicationDelay_Building;
Valueable<int> RadBuildingDamageMaxCount;
Expand Down Expand Up @@ -156,6 +157,7 @@ class RulesExt
, AIChronoSphereSW {}
, AIChronoWarpSW {}
, SubterraneanHeight { -256 }
, AISuperWeaponDelay {}
, UseGlobalRadApplicationDelay { true }
, RadApplicationDelay_Building { 0 }
, RadBuildingDamageMaxCount { -1 }
Expand Down

0 comments on commit 998505f

Please sign in to comment.