From 722c2af4dc2b37056cf6054764837ac2ab15d40f Mon Sep 17 00:00:00 2001 From: commy2 Date: Tue, 7 Apr 2015 20:54:25 +0200 Subject: [PATCH] lightIntensity, handle soldier flashlights --- addons/common/XEH_preInit.sqf | 1 + .../fnc_getLightPropertiesWeapon.sqf | 58 ++++++++++++++ .../fnc_lightIntensityFromObject.sqf | 75 +++++++++++++++---- 3 files changed, 118 insertions(+), 16 deletions(-) create mode 100644 addons/common/functions/fnc_getLightPropertiesWeapon.sqf diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index 95a639b943..b7da27ea75 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -193,6 +193,7 @@ PREP(getHitPoints); PREP(getHitPointsWithSelections); PREP(getReflectorsWithSelections); PREP(getLightProperties); +PREP(getLightPropertiesWeapon); PREP(getVehicleCrew); // turrets diff --git a/addons/common/functions/fnc_getLightPropertiesWeapon.sqf b/addons/common/functions/fnc_getLightPropertiesWeapon.sqf new file mode 100644 index 0000000000..d444654b5f --- /dev/null +++ b/addons/common/functions/fnc_getLightPropertiesWeapon.sqf @@ -0,0 +1,58 @@ +/* + * Author: commy2 + * Read properties of given flashlight. @todo, Can weapons themselves still have flashlights (no attachment)? + * + * Arguments: + * 0: A flashlight (String) + * + * Return Value: + * Stuff from config (Array) + * + */ +#include "script_component.hpp" + +private "_weapon"; + +_weapon = _this select 0; + +private "_config"; +_config = configFile >> "CfgWeapons" >> _weapon >> "ItemInfo" >> "FlashLight"; + +private ["_intensity", "_position", "_direction", "_innerAngle", "_outerAngle"]; + +_intensity = getNumber (_config >> "intensity"); +_position = getText (_config >> "position"); +_direction = getText (_config >> "direction"); +_innerAngle = getNumber (_config >> "innerAngle"); +_outerAngle = getNumber (_config >> "outerAngle"); + +[_intensity, _position, _direction, _innerAngle, _outerAngle] + +/* +class FlashLight +{ + color[] = {180,156,120}; + ambient[] = {0.9,0.78,0.6}; + intensity = 20; + size = 1; + innerAngle = 20; + outerAngle = 80; + coneFadeCoef = 5; + position = "flash dir"; + direction = "flash"; + useFlare = 1; + flareSize = 1.4; + flareMaxDistance = "100.0f"; + dayLight = 0; + class Attenuation + { + start = 0.5; + constant = 0; + linear = 0; + quadratic = 1.1; + hardLimitStart = 20; + hardLimitEnd = 30; + }; + scale[] = {0}; +}; +*/ diff --git a/addons/common/functions/fnc_lightIntensityFromObject.sqf b/addons/common/functions/fnc_lightIntensityFromObject.sqf index cf9e215403..1a79ceb211 100644 --- a/addons/common/functions/fnc_lightIntensityFromObject.sqf +++ b/addons/common/functions/fnc_lightIntensityFromObject.sqf @@ -20,37 +20,80 @@ _lightSource = _this select 1; private "_unitPos"; _unitPos = _unit modelToWorld (_unit selectionPosition "spine3"); -private ["_lights", "_lightLevel"]; - -_lights = [_lightSource] call FUNC(getTurnedOnLights); - +private "_lightLevel"; _lightLevel = 0; -{ - private ["_properties", "_intensity", "_innerAngle", "_outerAngle", "_position", "_direction", "_directionToUnit", "_distance", "_angle"]; +if (_lightSource isKindOf "CAManBase") then { + // handle persons with flashlights - _properties = [_lightSource, _x] call FUNC(getLightProperties); + private "_weapon"; + _weapon = currentWeapon _lightSource; - // @todo intensity affects range? - //_intensity = _properties select 0; + if !(_lightSource isFlashlightOn _weapon) exitWith {}; + + private ["_flashlight", "_properties", "_intensity", "_innerAngle", "_outerAngle", "_position", "_direction", "_directionToUnit", "_distance", "_angle"]; + + _flashlight = switch (_weapon) do { + case (primaryWeapon _lightSource): { + primaryWeaponItems _lightSource select 1 + }; + case (secondaryWeapon _lightSource): { + secondaryWeaponItems _lightSource select 1 + }; + case (handgunWeapon _lightSource): { + handgunItems _lightSource select 1 + }; + default {""}; + }; + + _properties = [_flashlight] call FUNC(getLightPropertiesWeapon); _innerAngle = (_properties select 3) / 2; _outerAngle = (_properties select 4) / 2; - // get world position and direction - _position = _lightSource modelToWorld (_lightSource selectionPosition (_properties select 1)); - _direction = _lightSource modelToWorld (_lightSource selectionPosition (_properties select 2)); + _position = _lightSource modelToWorld (_lightSource selectionPosition "rightHand"); + _direction = _lightSource weaponDirection _weapon; - _direction = _position vectorFromTo _direction; _directionToUnit = _position vectorFromTo _unitPos; _distance = _unitPos distance _position; _angle = acos (_direction vectorDotProduct _directionToUnit); - _lightLevel = _lightLevel max ((linearConversion [0, 30, _distance, 1, 0, true]) * (linearConversion [_innerAngle, _outerAngle, _angle, 1, 0, true])); + _lightLevel = (linearConversion [0, 30, _distance, 1, 0, true]) * (linearConversion [_innerAngle, _outerAngle, _angle, 1, 0, true]); -//systemChat format ["%1 %2", (linearConversion [0, 30, _distance, 1, 0, true]), (linearConversion [_innerAngle, _outerAngle, _angle, 1, 0, true])]; +} else { + // handle any object, strcutures, cars, tanks, etc. -} forEach _lights; + private "_lights"; + _lights = [_lightSource] call FUNC(getTurnedOnLights); + + { + private ["_properties", "_intensity", "_innerAngle", "_outerAngle", "_position", "_direction", "_directionToUnit", "_distance", "_angle"]; + + _properties = [_lightSource, _x] call FUNC(getLightProperties); + + // @todo intensity affects range? + //_intensity = _properties select 0; + + _innerAngle = (_properties select 3) / 2; + _outerAngle = (_properties select 4) / 2; + + // get world position and direction + _position = _lightSource modelToWorld (_lightSource selectionPosition (_properties select 1)); + _direction = _lightSource modelToWorld (_lightSource selectionPosition (_properties select 2)); + + _direction = _position vectorFromTo _direction; + _directionToUnit = _position vectorFromTo _unitPos; + + _distance = _unitPos distance _position; + _angle = acos (_direction vectorDotProduct _directionToUnit); + + _lightLevel = _lightLevel max ((linearConversion [0, 30, _distance, 1, 0, true]) * (linearConversion [_innerAngle, _outerAngle, _angle, 1, 0, true])); + + //systemChat format ["%1 %2", (linearConversion [0, 30, _distance, 1, 0, true]), (linearConversion [_innerAngle, _outerAngle, _angle, 1, 0, true])]; + + } forEach _lights; + +}; _lightLevel