Skip to content

Commit

Permalink
Map - Use getLightingAt (more light sources illuminate map) (acemod…
Browse files Browse the repository at this point in the history
…#8343)

Co-authored-by: PabstMirror <pabstmirror@gmail.com>
  • Loading branch information
2 people authored and AndreasBrostrom committed Dec 3, 2021
1 parent 12bc80e commit 9c92aca
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 73 deletions.
25 changes: 21 additions & 4 deletions addons/map/XEH_postInitClient.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,12 @@ GVAR(vehicleLightColor) = [1,1,1,0];
private _vehicleLightCondition = getText (_cfg >> QGVAR(vehicleLightCondition));
if (_vehicleLightCondition == "") then {
private _userAction = toLower getText (_cfg >> "UserActions" >> "ToggleLight" >> "statement");
switch (true) do {
case ((_userAction find "cabinlights_hide") > 0): {_vehicleLightCondition = "(_vehicle animationSourcePhase 'cabinlights_hide') == 1";};
case ((_userAction find "cargolights_hide") > 0): {_vehicleLightCondition = "(_vehicle animationSourcePhase 'cargolights_hide') == 1";};
if (
false // isClass (_cfg >> "compartmentsLights")
|| {_userAction find "cabinlights_hide" > 0}
|| {_userAction find "cargolights_hide" > 0}
) then {
_vehicleLightCondition = "false";
};
};

Expand All @@ -109,11 +112,25 @@ GVAR(vehicleLightColor) = [1,1,1,0];
} else {
switch (true) do {
case (_vehicle isKindOf "Tank");
case (_vehicle isKindOf "Wheeled_APC"): { {true} };
case (_vehicle isKindOf "Wheeled_APC_F"): { {true} };
case (_vehicle isKindOf "ParachuteBase"): { {false} };
case (_vehicle isKindOf "Helicopter");
case (_vehicle isKindOf "Plane"): { {(driver _vehicle == _unit) || {gunner _vehicle == _unit}} };
default { {false} };
};
};
}, true] call CBA_fnc_addPlayerEventHandler;

// compartmentsLights work only when cameraView == "INTERNAL" so we switch it on map opening
["visibleMap", {
params ["_player", "_mapOn"];
if (_mapOn) then {
if (!isClass (configOf vehicle _player >> "compartmentsLights") || {cameraView == "INTERNAL"}) exitWith {};
GVAR(cameraViewLast) = cameraView;
vehicle _player switchCamera "INTERNAL";
} else {
if (isNil QGVAR(cameraViewLast)) exitWith {};
vehicle _player switchCamera GVAR(cameraViewLast);
GVAR(cameraViewLast) = nil;
};
}] call CBA_fnc_addPlayerEventHandler;
89 changes: 26 additions & 63 deletions addons/map/functions/fnc_determineMapLight.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -18,82 +18,45 @@

params ["_unit"];

// Blend two colors
private _fnc_blendColor = {
params ["_c1", "_c2", "_alpha"];
[(_c1 select 0) * (1 - _alpha) + (_c2 select 0) * _alpha,
(_c1 select 1) * (1 - _alpha) + (_c2 select 1) * _alpha,
(_c1 select 2) * (1 - _alpha) + (_c2 select 2) * _alpha,
(_c1 select 3) * (1 - _alpha) + (_c2 select 3) * _alpha]
};

// Ambient light tint depending on time of day
private _lightTint = call {
if (sunOrMoon == 1.0) exitWith {[0.5,0.5,0.5,1]};
if (sunOrMoon > 0.80) exitWith {[[1.0 - overcast,0.2,0,1], [1,1,1,1], (sunOrMoon - 0.8) / 0.2] call _fnc_blendColor};
if (sunOrMoon > 0.50) exitWith {[[0,0,0.1,1], [1.0 - overcast,0.2,0,1], (sunOrMoon - 0.5) / 0.3] call _fnc_blendColor};
if (sunOrMoon <= 0.5) exitWith {[0,0,0.1,1]};
[0,0,0,0]
};

private _lightLevel = 0.04 + (0.96 * call EFUNC(common,ambientBrightness));

// Do not obscure the map if the ambient light level is above 0.95
if (_lightLevel > 0.95) exitWith {
[false, [1,1,1,0]]
};

private _vehicle = vehicle _unit;

// Do not obscure the map if the player is on a enclosed vehicle (assume internal illumination)
if ((_vehicle != _unit) && {(!isTurnedOut _unit)} && GVAR(vehicleLightCondition) && {!((_unit call CBA_fnc_turretPath) in GVAR(vehicleExteriorTurrets))}) exitWith {
if (
_vehicle != _unit
&& {!isTurnedOut _unit}
&& GVAR(vehicleLightCondition)
&& {!((_unit call CBA_fnc_turretPath) in GVAR(vehicleExteriorTurrets))}
) exitWith {
TRACE_1("Player in a enclosed vehicle",GVAR(vehicleLightColor));
[GVAR(vehicleLightColor) isNotEqualTo [1,1,1,0], GVAR(vehicleLightColor)]
};

// Player is not in a vehicle
TRACE_1("Player is on foot or in an open vehicle","");

// Check if player is near a campfires, streetlamps, units with flashlights, vehicles with lights on, etc. - 40m
{
_lightLevel = _lightLevel max ([_unit, _x] call EFUNC(common,lightIntensityFromObject));
} forEach nearestObjects [_unit, ["All"], 40];
getLightingAt _unit params ["_ambientLightColor", "_ambientLightBrightness", "_dynamicLightColor", "_dynamicLightBrightness"];

// @todo: Illumination flares (timed)
private _brightness = _ambientLightBrightness + _dynamicLightBrightness;
if (_brightness > 3000) exitWith {[false, [1,1,1,0]]};

// Using chemlights
private _nearObjects = (_unit nearObjects ["Chemlight_base", 4]) select {alive _x};

if (_nearObjects isNotEqualTo []) then {
private _nearestlight = _nearObjects select 0;
private _lightLevelTemp = (1 - ((((_unit distance _nearestlight) - 2) / 2) max 0)) * 0.4;
if (_lightLevelTemp > _lightLevel) then {
private _flareTint = getArray (configFile >> "CfgLights" >> (getText (configFile >> (getText (configFile >> "CfgAmmo" >> typeOf _nearestlight >> "EffectsSmoke")) >> "Light1" >> "type")) >> "color");
_lightTint = [_lightTint, _flareTint, (_lightLevelTemp - _lightLevel) / (1 - _lightLevel)] call _fnc_blendColor;
_lightLevel = _lightLevelTemp;
TRACE_1("player near chemlight","");
};
};

// Do not obscure the map if the ambient light level is above 0.95
if (_lightLevel > 0.95) exitWith {
[false, [1,1,1,0]]
private _alfa = switch (true) do {
case (_brightness <= 0.2): { 1 };
case (_brightness <= 2): { linearConversion [0.2, 2, _brightness, 1, 0.86] };
case (_brightness <= 10): { linearConversion [2, 10, _brightness, 0.86, 0.6] };
case (_brightness <= 100): { linearConversion [10, 100, _brightness, 0.6, 0.3] };
case (_brightness <= 200): { linearConversion [100, 200, _brightness, 0.3, 0.14] };
default { linearConversion [200, 3000, _brightness, 0.14, 0] };
};

// Calculate resulting map color from tint and light level
private _halfLight = _lightLevel / 0.5;
private _finalLightColor = [];
{
private _finalColor = (_ambientLightBrightness * _x + _dynamicLightBrightness * (_dynamicLightColor select _forEachIndex)) / _brightness;
if (_alfa > 0.5) then {
_finalColor = _finalColor * (1 - _alfa) / 3;
};
_finalLightColor pushBack _finalColor;
} forEach _ambientLightColor;

private _finalLevel = if (_lightLevel < 0.5) then {
[(_lightTint select 0) * _halfLight,
(_lightTint select 1) * _halfLight,
(_lightTint select 2) * _halfLight,
(_lightTint select 3) * (1 - _lightLevel)]
} else {
_halfLight = (_lightLevel - 0.5) / 0.5;
[(_lightTint select 0) * (1 - _halfLight) + _halfLight,
(_lightTint select 1) * (1 - _halfLight) + _halfLight,
(_lightTint select 2) * (1 - _halfLight) + _halfLight,
(_lightTint select 3) * (1 - _lightLevel)]
};
_finalLightColor pushBack _alfa;

[true, _finalLevel]
[true, _finalLightColor]
11 changes: 7 additions & 4 deletions addons/map/functions/fnc_simulateMapLight.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ _lightLevel params ["_r", "_g", "_b", "_a"];
private _colourAlpha = (_r + _g + _b) min _a;
private _shadeAlpha = _a;

private _colourList = [_r, _g, _b];
_colourList sort false;
private _maxColour = _colourList select 0;
private _maxColour = selectMax [_r, _g, _b];
private _ambientColor = if (_maxColour == 0) then {
[1, 1, 1, _colourAlpha];
} else {
[_r / _maxColour, _g / _maxColour, _b / _maxColour, _colourAlpha];
};

//ambient colour fill
_mapCtrl drawIcon ["#(rgb,8,8,3)color(1,1,1,1)", [_r / _maxColour, _g / _maxColour, _b / _maxColour, _colourAlpha], _mapCentre, _screenSize, _screenSize, 0, "", 0];
_mapCtrl drawIcon ["#(rgb,8,8,3)color(1,1,1,1)", _ambientColor, _mapCentre, _screenSize, _screenSize, 0, "", 0];

if (_flashlight == "") then {
//ambient shade fill
Expand Down
4 changes: 2 additions & 2 deletions addons/map/functions/fnc_updateMapEffects.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
* On map draw, updates the effects
*
* Arguments:
* None
* 0: Map control <CONTROL>
*
* Return Value:
* None
*
* Example:
* call ACE_map_fnc_updateMapEffects
* _mapControl call ACE_map_fnc_updateMapEffects
*
* Public: No
*/
Expand Down

0 comments on commit 9c92aca

Please sign in to comment.