2018-09-17 19:19:29 +00:00
|
|
|
#include "script_component.hpp"
|
2015-04-07 16:54:53 +00:00
|
|
|
/*
|
|
|
|
* Author: commy2
|
|
|
|
* Calculate light intensity object 1 recieves from object 2
|
|
|
|
*
|
|
|
|
* Arguments:
|
2015-09-18 19:12:40 +00:00
|
|
|
* 0: Object that recieves light <OBJECT>
|
|
|
|
* 1: Object that emits light <OBJECT>
|
2015-04-07 16:54:53 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
2017-06-08 13:31:51 +00:00
|
|
|
* Brightest light level <NUMBER>
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [reciever, giver] call ace_common_fnc_lightIntensityFromObject
|
2015-04-07 16:54:53 +00:00
|
|
|
*
|
2015-09-18 19:12:40 +00:00
|
|
|
* Public: Yes
|
2015-04-07 16:54:53 +00:00
|
|
|
*/
|
|
|
|
|
2015-09-18 19:12:40 +00:00
|
|
|
params ["_unit", "_lightSource"];
|
2015-04-07 16:54:53 +00:00
|
|
|
|
2015-12-12 15:48:54 +00:00
|
|
|
private _unitPos = _unit modelToWorld (_unit selectionPosition "spine3");
|
|
|
|
private _lightLevel = 0;
|
2015-04-07 16:54:53 +00:00
|
|
|
|
2015-04-07 18:54:25 +00:00
|
|
|
if (_lightSource isKindOf "CAManBase") then {
|
|
|
|
// handle persons with flashlights
|
2015-04-07 16:54:53 +00:00
|
|
|
|
2015-12-12 15:48:54 +00:00
|
|
|
private _weapon = currentWeapon _lightSource;
|
2015-04-07 16:54:53 +00:00
|
|
|
|
2015-04-07 18:54:25 +00:00
|
|
|
if !(_lightSource isFlashlightOn _weapon) exitWith {};
|
2015-04-07 16:54:53 +00:00
|
|
|
|
2015-12-12 15:48:54 +00:00
|
|
|
private _flashlight = (_lightSource weaponAccessories _weapon) select 1;
|
2015-04-07 18:54:25 +00:00
|
|
|
|
2018-10-25 16:40:27 +00:00
|
|
|
if (getNumber (configFile >> "CfgWeapons" >> _flashlight >> "ACE_laserpointer") > 0) exitWith {}; // Red = 1, Green = 2
|
2015-09-17 12:17:48 +00:00
|
|
|
|
2015-12-12 15:48:54 +00:00
|
|
|
private _properties = [[_flashlight], FUNC(getLightPropertiesWeapon), uiNamespace, format [QEGVAR(cache,%1_%2), QUOTE(DFUNC(getLightPropertiesWeapon)), _flashlight], 1E11] call FUNC(cachedCall);
|
2015-04-07 19:22:00 +00:00
|
|
|
//_properties = [_flashlight] call FUNC(getLightPropertiesWeapon);
|
2015-04-07 16:54:53 +00:00
|
|
|
|
2015-12-12 15:48:54 +00:00
|
|
|
private _innerAngle = (_properties select 3) / 2;
|
|
|
|
private _outerAngle = (_properties select 4) / 2;
|
2015-04-07 16:54:53 +00:00
|
|
|
|
2015-12-12 15:48:54 +00:00
|
|
|
private _position = _lightSource modelToWorld (_lightSource selectionPosition "rightHand");
|
|
|
|
private _direction = _lightSource weaponDirection _weapon;
|
2015-04-07 16:54:53 +00:00
|
|
|
|
2015-12-12 15:48:54 +00:00
|
|
|
private _directionToUnit = _position vectorFromTo _unitPos;
|
2015-04-07 16:54:53 +00:00
|
|
|
|
2015-12-12 15:48:54 +00:00
|
|
|
private _distance = _unitPos distance _position;
|
|
|
|
private _angle = acos (_direction vectorDotProduct _directionToUnit);
|
2015-04-07 16:54:53 +00:00
|
|
|
|
2015-04-07 18:54:25 +00:00
|
|
|
_lightLevel = (linearConversion [0, 30, _distance, 1, 0, true]) * (linearConversion [_innerAngle, _outerAngle, _angle, 1, 0, true]);
|
|
|
|
|
|
|
|
} else {
|
2015-04-07 20:19:03 +00:00
|
|
|
// handle any object, strcutures, cars, tanks, etc. @todo campfires, burning vehicles
|
2015-04-07 18:54:25 +00:00
|
|
|
|
2015-12-12 16:26:47 +00:00
|
|
|
private _lights = _lightSource call FUNC(getTurnedOnLights);
|
2015-04-07 18:54:25 +00:00
|
|
|
|
|
|
|
{
|
2015-12-12 15:48:54 +00:00
|
|
|
private _properties = [[_lightSource, _x], FUNC(getLightProperties), uiNamespace, format [QEGVAR(cache,%1_%2_%3), QUOTE(DFUNC(getLightProperties)), typeOf _lightSource, _x], 1E11] call FUNC(cachedCall);
|
2015-04-07 19:22:00 +00:00
|
|
|
//_properties = [_lightSource, _x] call FUNC(getLightProperties);
|
2015-04-07 18:54:25 +00:00
|
|
|
|
|
|
|
// @todo intensity affects range?
|
2015-12-12 16:26:47 +00:00
|
|
|
//_properties params ["_intensity"];
|
2015-04-07 18:54:25 +00:00
|
|
|
|
2015-12-12 15:48:54 +00:00
|
|
|
private _innerAngle = (_properties select 3) / 2;
|
|
|
|
private _outerAngle = (_properties select 4) / 2;
|
2015-04-07 18:54:25 +00:00
|
|
|
|
|
|
|
// get world position and direction
|
2015-12-12 15:48:54 +00:00
|
|
|
private _position = _lightSource modelToWorld (_lightSource selectionPosition (_properties select 1));
|
|
|
|
private _direction = _lightSource modelToWorld (_lightSource selectionPosition (_properties select 2));
|
2015-04-07 18:54:25 +00:00
|
|
|
|
|
|
|
_direction = _position vectorFromTo _direction;
|
2015-12-12 15:48:54 +00:00
|
|
|
private _directionToUnit = _position vectorFromTo _unitPos;
|
2015-04-07 18:54:25 +00:00
|
|
|
|
2015-12-12 15:48:54 +00:00
|
|
|
private _distance = _unitPos distance _position;
|
|
|
|
private _angle = acos (_direction vectorDotProduct _directionToUnit);
|
2015-04-07 18:54:25 +00:00
|
|
|
|
|
|
|
_lightLevel = _lightLevel max ((linearConversion [0, 30, _distance, 1, 0, true]) * (linearConversion [_innerAngle, _outerAngle, _angle, 1, 0, true]));
|
|
|
|
|
2015-09-17 12:17:48 +00:00
|
|
|
//systemChat format ["%1 %2", (linearConversion [0, 30, _distance, 1, 0, true]), (linearConversion [_innerAngle, _outerAngle, _angle, 1, 0, true])];
|
2015-04-07 16:54:53 +00:00
|
|
|
|
2015-04-07 18:54:25 +00:00
|
|
|
} forEach _lights;
|
2015-04-07 16:54:53 +00:00
|
|
|
|
2018-02-13 19:27:57 +00:00
|
|
|
if (isCollisionLightOn _lightSource) then {
|
|
|
|
private _markerLights = [
|
|
|
|
_lightSource,
|
2021-02-18 18:58:08 +00:00
|
|
|
{configProperties [configOf _this >> "MarkerLights", "isClass _x", true]},
|
2018-02-13 19:27:57 +00:00
|
|
|
uiNamespace,
|
|
|
|
format [QEGVAR(cache,MarkerLights_%1), typeOf _lightSource],
|
|
|
|
1E11
|
|
|
|
] call FUNC(cachedCall);
|
|
|
|
{
|
|
|
|
private _position = _lightSource modelToWorld (_lightSource selectionPosition getText (_x >> "name"));
|
|
|
|
private _distance = _unitPos distance _position;
|
|
|
|
_lightLevel = _lightLevel max (linearConversion [0, 10, _distance, 1, 0, true] * linearConversion [0, 1300, getNumber (_x >> "intensity"), 0, 1, true]);
|
|
|
|
} forEach _markerLights;
|
|
|
|
};
|
|
|
|
|
2015-04-07 21:02:54 +00:00
|
|
|
// handle campfires
|
|
|
|
if (inflamed _lightSource) then {
|
2015-12-12 15:48:54 +00:00
|
|
|
private _distance = _unitPos distance position _lightSource;
|
2015-04-07 21:02:54 +00:00
|
|
|
|
|
|
|
_lightLevel = _lightLevel max linearConversion [0, 30, _distance, 0.5, 0, true];
|
|
|
|
};
|
|
|
|
|
2015-04-07 18:54:25 +00:00
|
|
|
};
|
2015-04-07 16:54:53 +00:00
|
|
|
|
|
|
|
_lightLevel
|