mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Refactor and tweak map illumination to:
- add tint depending on time of day. - make it slightly less dark at night, so it's usable under any condition. Temporarily remove light creation.
This commit is contained in:
parent
a4ea5fb724
commit
86c16953ea
@ -1,125 +1,155 @@
|
||||
#include "script_component.hpp"
|
||||
|
||||
//TODO: Fix NVG color
|
||||
private ["_darkMap","_lightColor","_lightFill","_createLight","_gunlight","_nearObjects","_light"];
|
||||
private ["_darkenMap","_darkenColor","_createLight","_gunlight","_nearObjects","_light"];
|
||||
|
||||
// @todo: Update the way to check for flashlights
|
||||
_gunlight = isArray(configFile>> "CfgWeapons" >> currentWeapon player >>"ace_gunlight_classes") || {"ACE_MugLite" in weapons player};
|
||||
|
||||
// Default Values
|
||||
_alphaBase = if (round overcast > 0.5) then { 0.90 } else { 0.85};
|
||||
_alpha = _alphaBase min abs(sunOrMoon - 1);
|
||||
_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]
|
||||
};
|
||||
|
||||
_lightColor = [0,0,0,((_alpha*1.1) min 1)];
|
||||
_lightFill = format["#(rgb,1,1,1)color(0,0,0,%1)",_alpha];
|
||||
_darkMap = true;
|
||||
_lightTint = switch (true) do {
|
||||
case (daytime < 4 || dayTime >= 20) : {[0,0,0.2,1]};
|
||||
case (daytime < 5.5) : {[[0,0,0.4,1], [0.8,0.2,0,1], (daytime - 4)/1.5 ] call _fnc_blendColor};
|
||||
case (daytime < 6.5) : {[[0.8,0.2,0,1], [1,1,1,1], daytime - 5.5 ] call _fnc_blendColor};
|
||||
case (daytime < 17) : { [1,1,1,1] };
|
||||
case (daytime < 18) : {[[1,1,1,1], [0.8,0.2,0,1], daytime - 17 ] call _fnc_blendColor};
|
||||
case (daytime < 20) : {[[0.8,0.2,0,1], [0,0,0.4,1], (daytime - 18)/2] call _fnc_blendColor};
|
||||
};
|
||||
|
||||
_lightLevel = switch (true) do {
|
||||
case (daytime < 4 || dayTime >= 20) : {0.08};
|
||||
case (daytime < 6) : {0.08 + (1 - 0.08) * (daytime - 4) / 2};
|
||||
case (daytime < 18): {1};
|
||||
case (daytime < 20): {1 + (0.08 - 1) * (daytime - 18) / 2};
|
||||
};
|
||||
|
||||
_lightLevel = _lightLevel - 0.5 * (_lightLevel + 0.08) * ((overcast - 0.5) max 0);
|
||||
|
||||
_fnc_calcColor = {
|
||||
EXPLODE_2_PVT(_this,_c1,_lightLevel);
|
||||
|
||||
_l = abs(_lightLevel - 0.5) / 0.5;
|
||||
|
||||
if (_lightLevel < 0.5) then {
|
||||
[(_c1 select 0) * _l * _l * _l,
|
||||
(_c1 select 1) * _l * _l * _l,
|
||||
(_c1 select 2) * _l * _l * _l,
|
||||
(_c1 select 3) * (1 - _lightLevel)]
|
||||
} else {
|
||||
[(_c1 select 0) * (1 - _l) + _l,
|
||||
(_c1 select 1) * (1 - _l) + _l,
|
||||
(_c1 select 2) * (1 - _l) + _l,
|
||||
(_c1 select 3) * (1 - _lightLevel)]
|
||||
};
|
||||
};
|
||||
|
||||
_darkenMap = true;
|
||||
_createLight = false;
|
||||
|
||||
// check if player has NVG enabled
|
||||
if (currentVisionMode ACE_player == 1) exitWith {
|
||||
// stick to nvg color
|
||||
_darkenMap = true;
|
||||
_darkenColor = [154/255,253/255,177/255,0.5];
|
||||
_createLight = false;
|
||||
|
||||
[_darkenMap,_darkenColor,_createLight]
|
||||
};
|
||||
|
||||
if (_lightLevel > 0.95) exitWith {
|
||||
[false, [1,1,1,0], false]
|
||||
};
|
||||
|
||||
|
||||
// Check if player is not in a vehicle
|
||||
if (vehicle ACE_player == ACE_player) then {
|
||||
// Player is not in a vehicle
|
||||
TRACE_1("NOT in vehicle","");
|
||||
_lightColor = [0,0,0,(_alpha*1.1)];
|
||||
_lightFill = format["#(rgb,1,1,1)color(0,0,0,%1)",_alpha];
|
||||
|
||||
// check if player has NVG enabled
|
||||
if (currentVisionMode ACE_player == 1) then {
|
||||
// stick to nvg color
|
||||
_alpha = 0.8;
|
||||
_lightColor = [154/255,253/255,177/255,_alpha];
|
||||
_lightFill = "#(rgb,1,1,1)color(0.20,0.48,0.23,0.7)";
|
||||
TRACE_1("nvg on - green tint","");
|
||||
} else {
|
||||
// darken map, unless following cases are fulfilled
|
||||
// Priorities: Weapons flashlight, lamppost, fire, chemlight, flares
|
||||
|
||||
if (_alpha < 0.05) exitWith {
|
||||
_darkMap = false;
|
||||
};
|
||||
|
||||
// darken map, unless following cases are fulfilled
|
||||
// Priorities: Weapons flashlight, lamppost, fire, chemlight, flares
|
||||
|
||||
// Check if player is near a campfires, lights or vehicles with lights on - 15m
|
||||
_nearObjects = [nearestObjects [ACE_player, ["All"], 15], {(inflamed _this) || (isLightOn _this)}] call EFUNC(common,filter);
|
||||
if (count (_nearObjects) > 0) then {
|
||||
_light = _nearObjects select 0;
|
||||
_alpha = (((((ACE_player distance _light) - 5)/10) max 0) min 1) min _alphaBase;
|
||||
_lightColor = [0,0,0,_alpha];
|
||||
_lightFill = format["#(rgb,1,1,1)color(0,0,0,%1)",_alpha];
|
||||
TRACE_1("player near campfire","");
|
||||
};
|
||||
|
||||
// TODO: Illumination flares (timed)
|
||||
|
||||
// Using chemlights
|
||||
_fnc_chemLight = {
|
||||
EXPLODE_2_PVT(_this,_no,_lc);
|
||||
|
||||
if (count (_no) == 0) exitWith {};
|
||||
|
||||
_light = _no select 0;
|
||||
_alpha = (((((player distance _light) - 2)/4) max 0) min 0.5);
|
||||
_lightColor = +_lc;
|
||||
_lightColor set [3, _alpha];
|
||||
_lightFill = format["#(rgb,1,1,1)color(%1,%2,%3,%4)",(_lightColor select 0),(_lightColor select 1),(_lightColor select 2),(_lightColor select 3)];
|
||||
TRACE_1("player near chemlight","");
|
||||
};
|
||||
|
||||
_nearObjects = [ACE_player nearObjects ["Chemlight_red", 4], {alive _this}] call EFUNC(common,filter);
|
||||
[_nearObjects, [1,0,0,0]] call _fnc_chemLight;
|
||||
|
||||
_nearObjects = [ACE_player nearObjects ["Chemlight_green", 4], {alive _this}] call EFUNC(common,filter);
|
||||
[_nearObjects, [0,1,0,0]] call _fnc_chemLight;
|
||||
|
||||
_nearObjects = [ACE_player nearObjects ["Chemlight_blue", 4], {alive _this}] call EFUNC(common,filter);
|
||||
[_nearObjects, [0,0,1,0]] call _fnc_chemLight;
|
||||
|
||||
_nearObjects = [ACE_player nearObjects ["Chemlight_yellow", 4], {alive _this}] call EFUNC(common,filter);
|
||||
[_nearObjects, [1,1,0,0]] call _fnc_chemLight;
|
||||
|
||||
// Gun with light
|
||||
if (_gunlight) then {
|
||||
_darkMap = false;
|
||||
_createLight = true;
|
||||
TRACE_1("using gun light","");
|
||||
};
|
||||
// Check if player is near a campfires, lights or vehicles with lights on - 15m
|
||||
_nearObjects = [nearestObjects [ACE_player, ["All"], 15], {(inflamed _this) || (isLightOn _this)}] call EFUNC(common,filter);
|
||||
if (count (_nearObjects) > 0) then {
|
||||
_light = _nearObjects select 0;
|
||||
_lightLevel = _lightLevel max (1 - (((((ACE_player distance _light) - 5)/10) max 0) min 1));
|
||||
TRACE_1("player near campfire","");
|
||||
};
|
||||
|
||||
// TODO: Illumination flares (timed)
|
||||
|
||||
// Using chemlights
|
||||
_fnc_chemLight = {
|
||||
EXPLODE_2_PVT(_this,_no,_lc);
|
||||
if (count (_no) == 0) exitWith {};
|
||||
|
||||
_light = _no select 0;
|
||||
_ll = (1 - ((((ACE_player distance _light) - 2)/2) max 0)) * 0.4;
|
||||
if (_ll > _lightLevel) then {
|
||||
_lightLevel = _ll;
|
||||
_lightTint = +_lc;
|
||||
hint format ["%1 %2",ACE_player distance _light,_ll];
|
||||
};
|
||||
TRACE_1("player near chemlight","");
|
||||
};
|
||||
|
||||
_nearObjects = [ACE_player nearObjects ["Chemlight_red", 4], {alive _this}] call EFUNC(common,filter);
|
||||
[_nearObjects, [1,0,0,1]] call _fnc_chemLight;
|
||||
|
||||
_nearObjects = [ACE_player nearObjects ["Chemlight_green", 4], {alive _this}] call EFUNC(common,filter);
|
||||
[_nearObjects, [0,1,0,1]] call _fnc_chemLight;
|
||||
|
||||
_nearObjects = [ACE_player nearObjects ["Chemlight_blue", 4], {alive _this}] call EFUNC(common,filter);
|
||||
[_nearObjects, [0,0,1,1]] call _fnc_chemLight;
|
||||
|
||||
_nearObjects = [ACE_player nearObjects ["Chemlight_yellow", 4], {alive _this}] call EFUNC(common,filter);
|
||||
[_nearObjects, [1,1,0,1]] call _fnc_chemLight;
|
||||
|
||||
// Gun with light
|
||||
if (_gunlight) then {
|
||||
_darkenMap = false;
|
||||
_createLight = true;
|
||||
TRACE_1("using gun light","");
|
||||
};
|
||||
|
||||
} else {
|
||||
// Player is in a vehicle
|
||||
if ((vehicle ACE_player) isKindOf "Tank") exitWith {
|
||||
_darkMap = false;
|
||||
_darkenMap = false;
|
||||
_createLight = false;
|
||||
};
|
||||
|
||||
// check if vehicle is not of following type: parachute
|
||||
TRACE_1("in vehicle","");
|
||||
// check if player has NVG enabled
|
||||
if (currentVisionMode ACE_player == 1) then {
|
||||
// stick to nvg color
|
||||
_alpha = 0.8;
|
||||
_lightColor = [0,0.96,0,_alpha];
|
||||
_lightFill = "#(rgb,1,1,1)color(0,0.96,0,0.8)";
|
||||
TRACE_1("nvg on - green tint","");
|
||||
} else {
|
||||
// darken map if vehicle is kind of bicycle or motorbike or ATV or parachute or PBX boat
|
||||
if (vehicle ACE_player isKindOf "Bicycle" || {vehicle ACE_player isKindOf "Motorcycle"}) then {
|
||||
if (_gunlight) then {
|
||||
_darkMap = false;
|
||||
_createLight = true;
|
||||
TRACE_1("bright map - gun lights","");
|
||||
} else {
|
||||
_lightColor = [0,0,0,(_alpha*1.1)];
|
||||
_lightFill = format["#(rgb,1,1,1)color(0,0,0,%1)",_alpha];
|
||||
TRACE_1("darken map - no lights","");
|
||||
};
|
||||
} else {
|
||||
// do not darken map, but create a lightpoint at players eye pos to simulate dash light / flashlight usage to view map
|
||||
// do nothing if in a tank or apc
|
||||
_darkMap = false;
|
||||
_createLight = true;
|
||||
TRACE_1("using vehicle light","");
|
||||
};
|
||||
};
|
||||
};
|
||||
TRACE_4("",_darkMap,_lightColor,_lightFill,_createLight);
|
||||
|
||||
[_darkMap,_lightColor,_lightFill,_createLight]
|
||||
// darken map if vehicle is kind of bicycle or motorbike or ATV or parachute or PBX boat
|
||||
if (vehicle ACE_player isKindOf "Bicycle" || {vehicle ACE_player isKindOf "Motorcycle"}) then {
|
||||
if (_gunlight) then {
|
||||
_darkenMap = false;
|
||||
_createLight = true;
|
||||
TRACE_1("bright map - gun lights","");
|
||||
} else {
|
||||
_darkenColor = [0,0,0,(_alpha*1.1)];
|
||||
TRACE_1("darken map - no lights","");
|
||||
};
|
||||
} else {
|
||||
// do not darken map, but create a lightpoint at players eye pos to simulate dash light / flashlight usage to view map
|
||||
// do nothing if in a tank or apc
|
||||
_darkenMap = false;
|
||||
_createLight = true;
|
||||
TRACE_1("using vehicle light","");
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
_darkenColor = [_lightTint, _lightLevel] call _fnc_calcColor;
|
||||
|
||||
TRACE_4("",_darkenMap,_darkenColor,_createLight);
|
||||
[_darkenMap,_darkenColor,_createLight]
|
||||
|
@ -2,15 +2,15 @@
|
||||
|
||||
// Calculate the light
|
||||
_data = [[], FUNC(determineMapLight), missionNamespace, QGVAR(mapLight), 0.1] call EFUNC(common,cachedCall);
|
||||
diag_log _data;
|
||||
_darkMap = _data select 0;
|
||||
_color = _data select 1;
|
||||
_fill = _data select 2;
|
||||
_externalLight = _data select 3;
|
||||
if (_darkMap) then {
|
||||
((findDisplay 12) displayCtrl 51) drawRectangle [(getArray(configFile >> 'CfgWorlds' >> worldName >> 'centerPosition')),80000,80000,0,_color,_fill];
|
||||
|
||||
EXPLODE_3_PVT(_data,_darkenMap,_darkenColor,_externalLight);
|
||||
//systemChat format ["%1 %2 %3", _darkenMap, _darkenColor, _createLight];
|
||||
|
||||
if (_darkenMap) then {
|
||||
_darkenFill = format["#(rgb,1,1,1)color(%1,%2,%3,%4)",_darkenColor select 0, _darkenColor select 1, _darkenColor select 2, _darkenColor select 3];
|
||||
((findDisplay 12) displayCtrl 51) drawRectangle [(getArray(configFile >> 'CfgWorlds' >> worldName >> 'centerPosition')),80000,80000,0,_darkenColor,_darkenFill];
|
||||
} else {
|
||||
if (_externalLight) then {
|
||||
/*if (_externalLight) then {
|
||||
[] spawn {
|
||||
_light = ACE_player getVariable ['ace_map_light',objNull];
|
||||
if (isNull _light) then {
|
||||
@ -23,7 +23,7 @@ if (_darkMap) then {
|
||||
ACE_player setVariable ['ace_map_light',objNull];
|
||||
};
|
||||
};
|
||||
};
|
||||
};*/
|
||||
};
|
||||
|
||||
_ctrl = ((findDisplay 12) displayCtrl 51);
|
||||
|
Loading…
Reference in New Issue
Block a user