Skip to content
Merged
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
21 changes: 18 additions & 3 deletions src/features/lights/components/headlight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,14 @@ bool HeadlightComponent::TryRegisterDummy(CVehicle* pVeh, RwFrame* pFrame, const
void HeadlightComponent::Process(CVehicle* pVeh, VehLightData& data) {
if (!CanVehicleHaveHeadlights(pVeh)) return;

bool isHeadlightsActive = (pVeh->bLightsOn || CarUtil::IsLightsForcedOn(pVeh) || (Util::IsNightTime() && !Util::IsEngineOff(pVeh))) && !CarUtil::IsLightsForcedOff(pVeh);
bool isAlarmActive = pVeh->m_nAlarmState != 0 && pVeh->m_nAlarmState != 0xFFFF;
bool isAlarmLightOn = isAlarmActive && ((pVeh->m_nAlarmState & 0x100) != 0);

bool isHeadlightsActive = ((pVeh->bLightsOn || CarUtil::IsLightsForcedOn(pVeh) || (Util::IsNightTime() && !Util::IsEngineOff(pVeh))) || isAlarmLightOn) && !CarUtil::IsLightsForcedOff(pVeh);
if (isAlarmActive && !isAlarmLightOn) {
isHeadlightsActive = false;
}

if (pVeh->IsDriver(FindPlayerPed())) {
if (!isHeadlightsActive && data.fLightFactor[eMaterialType::HeadLightLeft] <= 0.001f) {
data.bLongLightsOn = false;
Expand All @@ -101,7 +108,7 @@ void HeadlightComponent::Process(CVehicle* pVeh, VehLightData& data) {
AudioMgr::PlaySwitchSound(pVeh);
}
} else if (pVeh->m_fHealth > 0.0f) {
if (CarUtil::IsLightsForcedOff(pVeh) || (Util::IsEngineOff(pVeh) && !CarUtil::IsLightsForcedOn(pVeh) && !pVeh->bLightsOn)) {
if (CarUtil::IsLightsForcedOff(pVeh) || (Util::IsEngineOff(pVeh) && !CarUtil::IsLightsForcedOn(pVeh) && !pVeh->bLightsOn && !isAlarmActive)) {
return;
}

Expand All @@ -128,7 +135,15 @@ void HeadlightComponent::Render(CVehicle* pControlVeh, CVehicle* pTowedVeh, VehL
return;
}

bool isNightOrOn = (pControlVeh->bLightsOn || CarUtil::IsLightsForcedOn(pControlVeh) || (Util::IsNightTime() && !Util::IsEngineOff(pControlVeh))) && !CarUtil::IsLightsForcedOff(pControlVeh);
bool isAlarmActive = pControlVeh->m_nAlarmState != 0 && pControlVeh->m_nAlarmState != 0xFFFF;
bool isAlarmLightOn = isAlarmActive && ((pControlVeh->m_nAlarmState & 0x100) != 0);

bool isNightOrOn = ((pControlVeh->bLightsOn || CarUtil::IsLightsForcedOn(pControlVeh) || (Util::IsNightTime() && !Util::IsEngineOff(pControlVeh))) || isAlarmLightOn) && !CarUtil::IsLightsForcedOff(pControlVeh);
if (isAlarmActive && !isAlarmLightOn) {
isNightOrOn = false;
pControlVeh->m_renderLights.m_bLeftFront = false;
pControlVeh->m_renderLights.m_bRightFront = false;
}
if (!isNightOrOn || !AreHeadlightsOpen(pControlVeh, data)) return;

auto damage = LightDamageState::Get(pControlVeh, pTowedVeh);
Expand Down
10 changes: 6 additions & 4 deletions src/features/lights/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,11 @@ void LightManager::Render(CVehicle* pControlVeh, CVehicle* pTowedVeh) {
m_VehData.Get(pTowedVeh).bLightRenderedThisFrame.fill(false);
}

bool isAlarmActive = pControlVeh->m_nAlarmState != 0 && pControlVeh->m_nAlarmState != 0xFFFF;

// Fix for UIF SAMP server https://github.com/user-grinch/ModelExtras/issues/112
// Don't clear light state when lights are forced on/already on via SAMP
if (((Util::IsEngineOff(pControlVeh) && indState == eIndicatorState::Off) && !CarUtil::IsLightsForcedOn(pControlVeh) && !pControlVeh->bLightsOn) || CarUtil::IsLightsForcedOff(pControlVeh)) {
// Don't clear light state when lights are forced on/already on via SAMP or alarm is active
if (((Util::IsEngineOff(pControlVeh) && indState == eIndicatorState::Off && !isAlarmActive) && !CarUtil::IsLightsForcedOn(pControlVeh) && !pControlVeh->bLightsOn) || CarUtil::IsLightsForcedOff(pControlVeh)) {
pControlVeh->bLightsOn = false;
pControlVeh->m_renderLights.m_bLeftFront = false;
pControlVeh->m_renderLights.m_bRightFront = false;
Expand All @@ -119,8 +121,8 @@ void LightManager::Render(CVehicle* pControlVeh, CVehicle* pTowedVeh) {
}

// Fix for park car alarm lights
// Allow through if lights or indicators are explicitly on
if (pControlVeh->m_fHealth <= 0.0f || ((Util::IsEngineOff(pControlVeh) && indState == eIndicatorState::Off) && !CarUtil::IsLightsForcedOn(pControlVeh) && !pControlVeh->bLightsOn)) {
// Allow through if lights, indicators, or alarm are explicitly on
if (pControlVeh->m_fHealth <= 0.0f || ((Util::IsEngineOff(pControlVeh) && indState == eIndicatorState::Off && !isAlarmActive) && !CarUtil::IsLightsForcedOn(pControlVeh) && !pControlVeh->bLightsOn)) {
return;
}

Expand Down