Skip to content

Commit

Permalink
New Adjacent.AllowedUnit and Adjacent.DisallowedUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
CrimRecya committed Feb 8, 2025
1 parent c3f1db1 commit 8680aa1
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/Fixed-or-Improved-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ ForbidParallelAIQueues=false ; boolean

### Check building adjacent by using units

- You can now set `CheckUnitBaseNormal` to true to use units to expand the construction scope of the base.
- You can now set `CheckUnitBaseNormal` to true to use units (without jumpjets) to expand the construction scope of the base.
- `UnitBaseNormal` controls whether our own buildings can be place around it like vanilla `BaseNormal` do.
- `UnitBaseForAllyBuilding` controls whether ally buildings can be place around it like vanilla `EligibileForAllyBuilding` do.

Expand Down
3 changes: 3 additions & 0 deletions docs/New-or-Enhanced-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -514,13 +514,16 @@ DetachedReport= ; sound entry
- There are now additional customizations available for building placement next to other buildings.
- `Adjacent.Allowed` lists BuildingTypes this BuildingType can be placed off (within distance defined by `Adjacent`). If empty, any BuildingType not listed in `Adjacent.Disallowed` is okay.
- `Adjacent.Disallowed` lists BuildingTypes this BuildingType cannot be placed next to. If empty, any BuildingTypes are okay as long as `Adjacent.Allowed` is empty or they are listed on it.
- If `CheckUnitBaseNormal` ([Check building adjacent by using units](Fixed-or-Improved-Logics.md#Check-building-adjacent-by-using-units)) is set to true , `Adjacent.AllowedUnit` and `Adjacent.DisallowedUnit` will work for units as what `Adjacent.Allowed` and `Adjacent.Disallowed` do.
- If `NoBuildAreaOnBuildup` is set to true, no building can be built next to this building regardless of any other settings if it is currently displaying its buildup animation.

In `rulesmd.ini`:
```ini
[SOMEBUILDING] ; BuildingType
Adjacent.Allowed= ; list of BuildingTypes
Adjacent.Disallowed= ; list of BuildingTypes
Adjacent.AllowedUnit= ; list of UnitTypes
Adjacent.DisallowedUnit= ; list of UnitTypes
NoBuildAreaOnBuildup=false ; boolean
```

Expand Down
4 changes: 4 additions & 0 deletions src/Ext/BuildingType/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ void BuildingTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
this->NoBuildAreaOnBuildup.Read(exINI, pSection, "NoBuildAreaOnBuildup");
this->Adjacent_Allowed.Read(exINI, pSection, "Adjacent.Allowed");
this->Adjacent_Disallowed.Read(exINI, pSection, "Adjacent.Disallowed");
this->Adjacent_AllowedUnit.Read(exINI, pSection, "Adjacent.AllowedUnit");
this->Adjacent_DisallowedUnit.Read(exINI, pSection, "Adjacent.DisallowedUnit");

this->BarracksExitCell.Read(exINI, pSection, "BarracksExitCell");

Expand Down Expand Up @@ -387,6 +389,8 @@ void BuildingTypeExt::ExtData::Serialize(T& Stm)
.Process(this->NoBuildAreaOnBuildup)
.Process(this->Adjacent_Allowed)
.Process(this->Adjacent_Disallowed)
.Process(this->Adjacent_AllowedUnit)
.Process(this->Adjacent_DisallowedUnit)
.Process(this->BarracksExitCell)
;
}
Expand Down
4 changes: 4 additions & 0 deletions src/Ext/BuildingType/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class BuildingTypeExt
Valueable<bool> NoBuildAreaOnBuildup;
ValueableVector<BuildingTypeClass*> Adjacent_Allowed;
ValueableVector<BuildingTypeClass*> Adjacent_Disallowed;
ValueableVector<UnitTypeClass*> Adjacent_AllowedUnit;
ValueableVector<UnitTypeClass*> Adjacent_DisallowedUnit;

Nullable<Point2D> BarracksExitCell;

Expand Down Expand Up @@ -131,6 +133,8 @@ class BuildingTypeExt
, NoBuildAreaOnBuildup { false }
, Adjacent_Allowed {}
, Adjacent_Disallowed {}
, Adjacent_AllowedUnit {}
, Adjacent_DisallowedUnit {}
, BarracksExitCell {}
{ }

Expand Down
40 changes: 31 additions & 9 deletions src/Ext/BuildingType/Hooks.Placing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,39 @@ DEFINE_HOOK(0x4A8FCA, DisplayClass_BuildingProximityCheck_BaseNormalExtra, 0x7)

if (RulesExt::Global()->CheckUnitBaseNormal)
{
if (const auto pUnit = pCell->GetUnit(false))
for (auto pObject = pCell->FirstObject; pObject; pObject = pObject->NextObject)
{
if (const auto pOwner = pUnit->Owner)
const auto pCellUnit = abstract_cast<UnitClass*>(pObject);

if (!pCellUnit)
continue;

const auto pOwner = pCellUnit->Owner;
const auto pTypeExt = TechnoTypeExt::ExtMap.Find(pCellUnit->Type);

auto canBeBaseNormal = [&]()
{
if (pOwner->ArrayIndex == idxHouse)
return pTypeExt->UnitBaseNormal.Get();
else if (RulesClass::Instance->BuildOffAlly && pOwner->IsAlliedWith(HouseClass::Array->Items[idxHouse]))
return pTypeExt->UnitBaseForAllyBuilding.Get();

return false;
};

if (canBeBaseNormal())
{
if (const auto pTypeExt = TechnoTypeExt::ExtMap.Find(pUnit->Type))
{
if (pOwner->ArrayIndex == idxHouse && pTypeExt->UnitBaseNormal)
return CanBuild;
else if (RulesClass::Instance->BuildOffAlly && pOwner->IsAlliedWith(HouseClass::Array->Items[idxHouse]) && pTypeExt->UnitBaseForAllyBuilding)
return CanBuild;
}
const auto& pUnitsAllowed = BuildingTypeExt::ExtMap.Find(ProximityTemp::BuildType)->Adjacent_AllowedUnit;

if (pUnitsAllowed.size() > 0 && !pUnitsAllowed.Contains(pCellUnit->Type))
continue;

const auto& pUnitsDisallowed = BuildingTypeExt::ExtMap.Find(ProximityTemp::BuildType)->Adjacent_DisallowedUnit;

if (pUnitsDisallowed.size() > 0 && pUnitsDisallowed.Contains(pCellUnit->Type))
continue;

return CanBuild;
}
}
}
Expand Down

0 comments on commit 8680aa1

Please sign in to comment.