Skip to content

Commit 1f4dee3

Browse files
committed
Fix issues with AITargetTypes and add new one only for bridge repair huts
- Tech building now only requires Capturable=true + NeedsEngineer=true and skips checking NeutralTechBuildings and other keys - Bridge repair huts no longer check Repairable and instead check if they are linked to broken bridges - Team leader guard area uses the getter function instead of reading GuardRange from type
1 parent 263f068 commit 1f4dee3

2 files changed

Lines changed: 20 additions & 29 deletions

File tree

docs/AI-Scripting-and-Mapping.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ x=i,n ; For i values check the next table
185185
| 8 | House Threats | Any object that targets anything of the Team's House or any enemy that is near to the Team Leader |
186186
| 9 | Power Plants | Any enemy `BuildingTypes` with positive `Power=` values |
187187
| 10 | Occupied | Any `BuildingTypes` with garrisoned infantry |
188-
| 11 | Tech Buildings | Any `BuildingTypes` with `Unsellable=yes`, `Capturable=yes`, negative `TechLevel=` values or appears in `[AI] -> NeutralTechBuildings=` list |
188+
| 11 | Tech Buildings | Any `BuildingTypes` with `Capturable=yes` and `NeedsEngineer=yes` |
189189
| 12 | Refinery | Any enemy `BuildingTypes` with `Refinery=yes` or `ResourceGatherer=yes`, `VehicleTypes` with `ResourceGatherer=yes` & `Harvester=no` (i.e. Slave Miner) |
190190
| 13 | Mind Controller | Anything `VehicleTypes`, `AircraftTypes`, `InfantryTypes` and `BuildingTypes` with `MindControl=yes` in the weapons Warheads |
191191
| 14 | Air Units (incl. landed) | Any enemy, `AircraftTypes` and `Jumpjet=yes` `VehicleTypes` or `InfantryTypes`, including landed ones as well as any other currently airborne units |
@@ -207,10 +207,11 @@ x=i,n ; For i values check the next table
207207
| 30 | Inhibitors | Any enemy objects with positive `InhibitorRange=` values |
208208
| 31 | Naval Units | Any enemy `VehicleTypes` with a `Naval=yes` or any enemy `VehicleTypes`, `AircraftTypes`, `InfantryTypes` in a water cell |
209209
| 32 | Mobile Units | Anything `VehicleTypes`, `AircraftTypes` and `InfantryTypes` |
210-
| 33 | Capturable | Any `BuildingTypes` with `Capturable=yes` or any `BuildingTypes` with `BridgeRepairHut=yes` and `Repairable=yes` |
210+
| 33 | Capturable | Any `BuildingTypes` with `Capturable=yes` or any `BuildingTypes` with `BridgeRepairHut=yes` that are linked to broken bridges |
211211
| 34 | Area Threats | Any enemy object that is inside of the Team Leader's Guard Area |
212212
| 35 | Vehicle & Naval Factory | Any enemy `BuildingTypes` with `Factory=UnitType` |
213213
| 36 | Non-defensive Structures | Any enemy `BuildingTypes` with `IsBaseDefense=no` |
214+
| 37 | Bridge Repair Huts | Any `BuildingTypes`with `BridgeRepairHut=yes` that are linked to broken bridges |
214215

215216
- The second parameter with a 0-based index for the `AITargetTypes` section specifies the list of possible `VehicleTypes`, `AircraftTypes`, `InfantryTypes` and `BuildingTypes` that can be evaluated.
216217
- The *`AITargetTypes` index#* values are obtained in the new `AITargetTypes` section that must be declared in `rulesmd.ini`:

src/Ext/Script/Mission.Attack.cpp

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -871,26 +871,8 @@ bool ScriptExt::EvaluateObjectWithMask(TechnoClass* pTechno, int mask, int attac
871871

872872
if (const auto pBuildingType = abstract_cast<BuildingTypeClass*, true>(pTechnoType))
873873
{
874-
const auto& neutralTechBuildings = RulesClass::Instance->NeutralTechBuildings;
875-
876-
if (const int count = neutralTechBuildings.Count)
877-
{
878-
for (int i = 0; i < count; ++i)
879-
{
880-
if (neutralTechBuildings.GetItem(i) == pTechnoType)
881-
return true;
882-
}
883-
}
884-
885-
// Other cases of civilian Tech Structures
886-
if (pBuildingType->Unsellable
887-
&& pBuildingType->Capturable
888-
&& pBuildingType->TechLevel < 0
889-
&& pBuildingType->NeedsEngineer
890-
&& !pBuildingType->BridgeRepairHut)
891-
{
874+
if (pBuildingType->Capturable && pBuildingType->NeedsEngineer)
892875
return true;
893-
}
894876
}
895877

896878
break;
@@ -1300,7 +1282,7 @@ bool ScriptExt::EvaluateObjectWithMask(TechnoClass* pTechno, int mask, int attac
13001282
{
13011283
if (pBuildingType->Capturable
13021284
|| (pBuildingType->BridgeRepairHut
1303-
&& pBuildingType->Repairable))
1285+
&& MapClass::Instance.IsLinkedBridgeDestroyed(pTechno->GetMapCoords())))
13041286
{
13051287
return true;
13061288
}
@@ -1313,14 +1295,8 @@ bool ScriptExt::EvaluateObjectWithMask(TechnoClass* pTechno, int mask, int attac
13131295

13141296
if (pTeamLeader && !pTechno->Owner->IsNeutral())
13151297
{
1316-
const int distanceToTarget = pTeamLeader->DistanceFrom(pTechno);
1317-
const int guardRange = pTeamLeader->GetTechnoType()->GuardRange;
1318-
1319-
if (guardRange > 0
1320-
&& distanceToTarget <= (guardRange * 2))
1321-
{
1298+
if (pTeamLeader->DistanceFrom(pTechno) <= pTeamLeader->GetGuardRange(1))
13221299
return true;
1323-
}
13241300
}
13251301

13261302
break;
@@ -1356,6 +1332,20 @@ bool ScriptExt::EvaluateObjectWithMask(TechnoClass* pTechno, int mask, int attac
13561332

13571333
break;
13581334

1335+
case 37:
1336+
// Bridge Repair Hut
1337+
1338+
if (const auto pBuildingType = abstract_cast<BuildingTypeClass*, true>(pTechnoType))
1339+
{
1340+
if (pBuildingType->BridgeRepairHut
1341+
&& MapClass::Instance.IsLinkedBridgeDestroyed(pTechno->GetMapCoords()))
1342+
{
1343+
return true;
1344+
}
1345+
}
1346+
1347+
break;
1348+
13591349
default:
13601350
break;
13611351
}

0 commit comments

Comments
 (0)