2015-03-14 16:46:10 +00:00
|
|
|
/*
|
2015-03-24 04:18:00 +00:00
|
|
|
* Author: Rocko and esteldunedain
|
2015-03-14 16:46:10 +00:00
|
|
|
* Calculates the current map illumination for a given unit
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Unit <OBJECT>
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* 0: Does the map needs shading? <BOOL>
|
|
|
|
* 1: Color of the overlay <ARRAY>
|
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
2015-03-13 00:04:10 +00:00
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2015-03-14 16:46:10 +00:00
|
|
|
EXPLODE_1_PVT(_this,_unit);
|
2015-03-13 00:04:10 +00:00
|
|
|
|
2015-03-14 16:46:10 +00:00
|
|
|
private ["_isEnclosed","_nearObjects","_light","_ll","_flashlight"];
|
2015-03-13 00:04:10 +00:00
|
|
|
|
2015-03-14 16:46:10 +00:00
|
|
|
// Blend two colors
|
2015-03-13 04:35:45 +00:00
|
|
|
_fnc_blendColor = {
|
|
|
|
EXPLODE_3_PVT(_this,_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]
|
|
|
|
};
|
|
|
|
|
2015-03-14 16:46:10 +00:00
|
|
|
// Ambient light tint depending on time of day
|
2015-03-14 01:27:38 +00:00
|
|
|
_lightTint = switch (true) do {
|
2015-03-14 16:46:10 +00:00
|
|
|
case (sunOrMoon == 1.0) : { [0.5,0.5,0.5,1] };
|
2015-03-14 01:27:38 +00:00
|
|
|
case (sunOrMoon > 0.80) : {[[1.0 - overcast,0.2,0,1], [1,1,1,1], (sunOrMoon - 0.8)/0.2] call _fnc_blendColor};
|
|
|
|
case (sunOrMoon > 0.50) : {[[0,0,0.1,1], [1.0 - overcast,0.2,0,1], (sunOrMoon - 0.5)/0.3] call _fnc_blendColor};
|
|
|
|
case (sunOrMoon <= 0.5) : { [0,0,0.1,1] };
|
2015-03-13 04:35:45 +00:00
|
|
|
};
|
|
|
|
|
2015-03-14 16:46:10 +00:00
|
|
|
// Calculates overlay color from tint and light level
|
2015-03-13 04:35:45 +00:00
|
|
|
_fnc_calcColor = {
|
|
|
|
EXPLODE_2_PVT(_this,_c1,_lightLevel);
|
|
|
|
|
|
|
|
if (_lightLevel < 0.5) then {
|
2015-03-14 16:46:10 +00:00
|
|
|
_l = _lightLevel / 0.5;
|
|
|
|
[(_c1 select 0) * _l,
|
|
|
|
(_c1 select 1) * _l,
|
|
|
|
(_c1 select 2) * _l,
|
2015-03-13 04:35:45 +00:00
|
|
|
(_c1 select 3) * (1 - _lightLevel)]
|
|
|
|
} else {
|
2015-03-14 16:46:10 +00:00
|
|
|
_l = (_lightLevel - 0.5) / 0.5;
|
2015-03-13 04:35:45 +00:00
|
|
|
[(_c1 select 0) * (1 - _l) + _l,
|
|
|
|
(_c1 select 1) * (1 - _l) + _l,
|
|
|
|
(_c1 select 2) * (1 - _l) + _l,
|
|
|
|
(_c1 select 3) * (1 - _lightLevel)]
|
|
|
|
};
|
|
|
|
};
|
2015-03-13 00:04:10 +00:00
|
|
|
|
2015-03-14 16:46:10 +00:00
|
|
|
_lightLevel = 0.04 + (0.96 * call EFUNC(common,ambientBrightness));
|
2015-03-13 00:04:10 +00:00
|
|
|
|
2015-03-13 04:35:45 +00:00
|
|
|
// check if player has NVG enabled
|
2015-03-14 16:46:10 +00:00
|
|
|
if (currentVisionMode _unit == 1) exitWith {
|
2015-03-13 04:35:45 +00:00
|
|
|
// stick to nvg color
|
2015-03-14 16:46:10 +00:00
|
|
|
[true, [154/255,253/255,177/255,0.5]]
|
2015-03-13 04:35:45 +00:00
|
|
|
};
|
|
|
|
|
2015-03-14 16:46:10 +00:00
|
|
|
// Do not obscure the map if the ambient light level is above 0.95
|
2015-03-13 04:35:45 +00:00
|
|
|
if (_lightLevel > 0.95) exitWith {
|
2015-03-14 16:46:10 +00:00
|
|
|
[false, [0.5,0.5,0.5,0]]
|
2015-03-13 04:35:45 +00:00
|
|
|
};
|
|
|
|
|
2015-04-07 20:19:03 +00:00
|
|
|
private "_vehicle";
|
|
|
|
_vehicle = vehicle _unit;
|
|
|
|
|
2015-03-14 16:46:10 +00:00
|
|
|
// Do not obscure the map if the player is on a enclosed vehicle (assume internal illumination)
|
2015-04-07 20:19:03 +00:00
|
|
|
if (_vehicle != _unit) then {
|
2015-03-14 16:46:10 +00:00
|
|
|
// Player is in a vehicle
|
2015-04-07 20:19:03 +00:00
|
|
|
if (isTurnedOut _unit && {_vehicle isKindOf "Tank" || {_vehicle isKindOf "Wheeled_APC"}}) then {
|
2015-03-14 16:46:10 +00:00
|
|
|
_isEnclosed = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
if (_isEnclosed) exitWith {
|
|
|
|
TRACE_1("Player in a enclosed vehicle","");
|
|
|
|
[false, [1,1,1,0]]
|
|
|
|
};
|
2015-03-13 04:35:45 +00:00
|
|
|
|
2015-03-14 16:46:10 +00:00
|
|
|
// Player is not in a vehicle
|
|
|
|
TRACE_1("Player is on foot or in an open vehicle","");
|
2015-03-13 00:04:10 +00:00
|
|
|
|
2015-04-07 20:19:03 +00:00
|
|
|
// Check if player is near a campfires, streetlamps, units with flashlights, vehicles with lights on, etc. - 40m
|
|
|
|
{
|
2015-04-07 20:33:35 +00:00
|
|
|
_lightLevel = _lightLevel max ([_unit, _x] call EFUNC(common,lightIntensityFromObject));
|
2015-04-07 20:19:03 +00:00
|
|
|
} forEach nearestObjects [_unit, ["All"], 40];
|
2015-03-13 00:04:10 +00:00
|
|
|
|
|
|
|
|
2015-03-14 16:46:10 +00:00
|
|
|
// @todo: Illumination flares (timed)
|
2015-03-13 00:04:10 +00:00
|
|
|
|
2015-03-13 04:35:45 +00:00
|
|
|
|
2015-03-14 16:46:10 +00:00
|
|
|
// Using chemlights
|
|
|
|
_nearObjects = [_unit nearObjects ["SmokeShell", 4], {
|
|
|
|
alive _this && {(typeOf _this == "Chemlight_red") || {
|
|
|
|
(typeOf _this == "Chemlight_green") || {
|
|
|
|
(typeOf _this == "Chemlight_blue") || {
|
|
|
|
(typeOf _this == "Chemlight_yellow")}}}}}] call EFUNC(common,filter);
|
|
|
|
if (count (_nearObjects) > 0) then {
|
|
|
|
_light = _nearObjects select 0;
|
2015-03-13 00:04:10 +00:00
|
|
|
|
2015-03-14 16:46:10 +00:00
|
|
|
_ll = (1 - ((((_unit distance _light) - 2)/2) max 0)) * 0.4;
|
|
|
|
if (_ll > _lightLevel) then {
|
|
|
|
_flareTint = switch (typeOf _light) do {
|
|
|
|
case "Chemlight_red" : {[1,0,0,1]};
|
|
|
|
case "Chemlight_green" : {[0,1,0,1]};
|
|
|
|
case "Chemlight_blue" : {[0,0,1,1]};
|
|
|
|
case "Chemlight_yellow" : {[1,1,0,1]};
|
2015-03-13 00:04:10 +00:00
|
|
|
};
|
2015-03-14 16:46:10 +00:00
|
|
|
_lightTint = [_lightTint, _flareTint, (_ll - _lightLevel)/(1 - _lightLevel)] call _fnc_blendColor;
|
|
|
|
_lightLevel = _ll;
|
|
|
|
TRACE_1("player near chemlight","");
|
2015-03-13 00:04:10 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-03-14 16:46:10 +00:00
|
|
|
// Do not obscure the map if the ambient light level is above 0.95
|
|
|
|
if (_lightLevel > 0.95) exitWith {
|
|
|
|
[false, [0.5,0.5,0.5,0]]
|
|
|
|
};
|
2015-03-13 04:35:45 +00:00
|
|
|
|
2015-03-14 16:46:10 +00:00
|
|
|
// Calculate resulting map color
|
|
|
|
[true, [_lightTint, _lightLevel] call _fnc_calcColor]
|