Fix rival faction detection: include Faction in fallback TeamId resolution

- GetTeamAttitudeTowards fallback (interface path) was calling MakeTeamId
  without Faction, so enemies of different factions had identical TeamIds
  → always Friendly instead of Hostile
- Now reads Faction from PersonalityProfile when resolving via interface

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
j.foucher 2026-04-01 18:14:36 +02:00
parent af93194f48
commit d471714fbd

View File

@ -368,14 +368,22 @@ ETeamAttitude::Type APS_AI_Behavior_AIController::GetTeamAttitudeTowards(const A
} }
} }
// 3) Fallback: check if Pawn implements IPS_AI_Behavior_Interface → derive TeamId from NPCType // 3) Fallback: check if Pawn implements IPS_AI_Behavior_Interface → derive TeamId from NPCType + Faction
if (OtherTeam == FGenericTeamId::NoTeam && OtherPawn->Implements<UPS_AI_Behavior_Interface>()) if (OtherTeam == FGenericTeamId::NoTeam && OtherPawn->Implements<UPS_AI_Behavior_Interface>())
{ {
const EPS_AI_Behavior_NPCType OtherNPCType = const EPS_AI_Behavior_NPCType OtherNPCType =
IPS_AI_Behavior_Interface::Execute_GetBehaviorNPCType(const_cast<APawn*>(OtherPawn)); IPS_AI_Behavior_Interface::Execute_GetBehaviorNPCType(const_cast<APawn*>(OtherPawn));
if (OtherNPCType != EPS_AI_Behavior_NPCType::Any) if (OtherNPCType != EPS_AI_Behavior_NPCType::Any)
{ {
OtherTeam = PS_AI_Behavior_Team::MakeTeamId(OtherNPCType); uint8 OtherFaction = 0;
if (const auto* OtherPersonality = OtherPawn->FindComponentByClass<UPS_AI_Behavior_PersonalityComponent>())
{
if (OtherPersonality->Profile)
{
OtherFaction = OtherPersonality->Profile->Faction;
}
}
OtherTeam = PS_AI_Behavior_Team::MakeTeamId(OtherNPCType, OtherFaction);
} }
} }
} }