Make flashlight on/off + glow a PVAR.

Clean up all privates.
Change glow proxies to not inherit from chemlight_base, to avoid ammo detection issues.
Make handleDisconnect glow deletion dedi server compatible (was only listen server compatible).
Clean up determineMapLight: faster when no chemlights nearby, a tad slower when chemlights nearby, however sources the colour settings directly from the chemlight's config.
This commit is contained in:
voiper 2016-06-17 17:18:06 -07:00
parent d4dfaeaf85
commit d5b3b03c1c
12 changed files with 226 additions and 252 deletions

View File

@ -1,39 +1,34 @@
class CfgAmmo { class CfgAmmo {
class Chemlight_base; class Grenade;
class ACE_FlashlightProxy_White: Chemlight_base { class ACE_FlashlightProxy_White: Grenade {
model = "\A3\Weapons_f\empty";
effectsSmoke = "ACE_FlashlightEffect_White"; effectsSmoke = "ACE_FlashlightEffect_White";
explosionTime = 0.01; explosionTime = 0.01;
grenadeBurningSound[] = {};
grenadeFireSound[] = {};
hit = 0;
model = "\A3\Weapons_f\empty.p3d";
simulation = "shotSmokeX";
smokeColor[] = {1,1,1,1};
timeToLive = 1e10; timeToLive = 1e10;
soundImpactHard1[] = {"",1,1}; impactArmor[] = {};
soundImpactHard2[] = {"",1,1}; impactConcrete[] = {};
soundImpactHard3[] = {"",1,1}; impactDefault[] = {};
soundImpactHard4[] = {"",1,1}; impactGlass[] = {};
soundImpactHard5[] = {"",1,1}; impactGlassArmored[] = {};
soundImpactHard6[] = {"",1,1}; impactGroundHard[] = {};
soundImpactHard7[] = {"",1,1}; impactGroundSoft[] = {};
soundImpactIron1[] = {"",1,1}; impactIron[] = {};
soundImpactIron2[] = {"",1,1}; impactMan[] = {};
soundImpactIron3[] = {"",1,1}; impactMetal[] = {};
soundImpactIron4[] = {"",1,1}; impactMetalPlate[] = {};
soundImpactIron5[] = {"",1,1}; impactMetalPlastic[] = {};
soundImpactSoft1[] = {"",1,1}; impactRubber[] = {};
soundImpactSoft2[] = {"",1,1}; impactTyre[] = {};
soundImpactSoft3[] = {"",1,1}; impactWater[] = {};
soundImpactSoft4[] = {"",1,1}; impactWood[] = {};
soundImpactSoft5[] = {"",1,1};
soundImpactSoft6[] = {"",1,1};
soundImpactSoft7[] = {"",1,1};
soundImpactWater1[] = {"",1,1};
soundImpactWater2[] = {"",1,1};
soundImpactWater3[] = {"",1,1};
soundImpactWoodExt1[] = {"",1,1};
soundImpactWoodExt2[] = {"",1,1};
soundImpactWoodExt3[] = {"",1,1};
soundImpactWoodExt4[] = {"",1,1};
}; };
class ACE_FlashlightProxy_Red: ACE_FlashlightProxy_White { class ACE_FlashlightProxy_Red: ACE_FlashlightProxy_White {

View File

@ -7,12 +7,13 @@ class Extended_PreStart_EventHandlers {
class Extended_PreInit_EventHandlers { class Extended_PreInit_EventHandlers {
class ADDON { class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preInit) ); init = QUOTE(call COMPILE_FILE(XEH_preInit));
}; };
}; };
class Extended_PostInit_EventHandlers { class Extended_PostInit_EventHandlers {
class ADDON { class ADDON {
clientInit = QUOTE(call COMPILE_FILE(XEH_postInitClient) ); clientInit = QUOTE(call COMPILE_FILE(XEH_postInitClient));
serverInit = QUOTE(call COMPILE_FILE(XEH_postInitServer));
}; };
}; };

View File

@ -1,23 +1,5 @@
#include "script_component.hpp" #include "script_component.hpp"
//Delete map glow lights from disconnecting players #2810
if (isServer) then {
addMissionEventHandler ["HandleDisconnect",{
params ["_disconnectedPlayer"];
if ((!GVAR(mapGlow)) || {isNull _disconnectedPlayer}) exitWith {};
{
if (_x isKindOf "ACE_FlashlightProxy_White") then {
// ACE_LOGINFO_2("Deleting leftover light [%1:%2] from DC player [%3]", _x, typeOf _x, _disconnectedPlayer);
detach _x;
deleteVehicle _x;
};
} forEach attachedObjects _disconnectedPlayer;
nil
}];
};
// Exit on Headless as well // Exit on Headless as well
if (!hasInterface) exitWith {}; if (!hasInterface) exitWith {};
@ -39,12 +21,11 @@ call FUNC(determineZoom);
//Allow panning the lastStillPosition while mapShake is active //Allow panning the lastStillPosition while mapShake is active
GVAR(rightMouseButtonLastPos) = []; GVAR(rightMouseButtonLastPos) = [];
((findDisplay 12) displayCtrl 51) ctrlAddEventHandler ["Draw", {[] call FUNC(updateMapEffects);}]; ((findDisplay 12) displayCtrl 51) ctrlAddEventHandler ["Draw", {_this call FUNC(updateMapEffects)}];
((findDisplay 12) displayCtrl 51) ctrlAddEventHandler ["MouseMoving", { ((findDisplay 12) displayCtrl 51) ctrlAddEventHandler ["MouseMoving", {
if (GVAR(isShaking) && {(count GVAR(rightMouseButtonLastPos)) == 2}) then { if (GVAR(isShaking) && {(count GVAR(rightMouseButtonLastPos)) == 2}) then {
private["_lastPos", "_newPos"]; private _lastPos = (_this select 0) ctrlMapScreenToWorld GVAR(rightMouseButtonLastPos);
_lastPos = (_this select 0) ctrlMapScreenToWorld GVAR(rightMouseButtonLastPos); private _newPos = (_this select 0) ctrlMapScreenToWorld (_this select [1,2]);
_newPos = (_this select 0) ctrlMapScreenToWorld (_this select [1,2]);
GVAR(lastStillPosition) set [0, (GVAR(lastStillPosition) select 0) + (_lastPos select 0) - (_newPos select 0)]; GVAR(lastStillPosition) set [0, (GVAR(lastStillPosition) select 0) + (_lastPos select 0) - (_newPos select 0)];
GVAR(lastStillPosition) set [1, (GVAR(lastStillPosition) select 1) + (_lastPos select 1) - (_newPos select 1)]; GVAR(lastStillPosition) set [1, (GVAR(lastStillPosition) select 1) + (_lastPos select 1) - (_newPos select 1)];
GVAR(rightMouseButtonLastPos) = _this select [1,2]; GVAR(rightMouseButtonLastPos) = _this select [1,2];
@ -97,35 +78,33 @@ call FUNC(determineZoom);
//illumination settings //illumination settings
if (GVAR(mapIllumination)) then { if (GVAR(mapIllumination)) then {
GVAR(flashlightInUse) = "";
GVAR(glow) = objNull;
["ace_playerInventoryChanged", { ["ace_playerInventoryChanged", {
private _flashlights = [ACE_player] call FUNC(getUnitFlashlights); params ["_player", ""];
if ((GVAR(flashlightInUse) != "") && !(GVAR(flashlightInUse) in _flashlights)) then { private _flashlightItems = [_player] call FUNC(getUnitFlashlights);
GVAR(flashlightInUse) = ""; private _unitLight = _player getVariable [QGVAR(flashlight), ["", objNull]];
_unitLight params ["_flashlight", "_glow"];
if (!(_flashlight isEqualTo "") && {!(_flashlight in _flashlightItems)}) then {
if (!isNull _glow) then {
_glow = [_player, "", false] call FUNC(flashlightGlow);
};
_player setVariable [QGVAR(flashlight), ["", _glow], true];
}; };
}] call CBA_fnc_addEventHandler; }] call CBA_fnc_addEventHandler;
if (GVAR(mapGlow)) then { if (GVAR(mapGlow)) then {
["ace_visibleMapChanged", { ["ace_visibleMapChanged", {
params ["_player", "_mapOn"]; params ["_player", "_mapOn"];
private _unitLight = _player getVariable [QGVAR(flashlight), ["", objNull]];
_unitLight params ["_flashlight", "_glow"];
private _flashlightOn = !(_flashlight isEqualTo "");
if (_mapOn) then { if (_mapOn) then {
if (!alive _player && !isNull GVAR(glow)) then { if (_flashlightOn && {isNull _glow}) then {
GVAR(flashlightInUse) = ""; [_player, _flashlight] call FUNC(flashlightGlow);
}; playSound QGVAR(flashlightClick);
if (GVAR(flashlightInUse) != "") then {
if (isNull GVAR(glow)) then {
[GVAR(flashlightInUse)] call FUNC(flashlightGlow);
}; };
} else { } else {
if (!isNull GVAR(glow)) then { if (!isNull _glow) then {
[""] call FUNC(flashlightGlow); [_player, ""] call FUNC(flashlightGlow);
};
};
} else {
if (!isNull GVAR(glow)) then {
[""] call FUNC(flashlightGlow);
}; };
}; };
}] call CBA_fnc_addEventHandler; }] call CBA_fnc_addEventHandler;

View File

@ -0,0 +1,16 @@
#include "script_component.hpp"
// Delete map glow lights from disconnecting players, #2810
addMissionEventHandler ["HandleDisconnect",{
params ["_disconnectedPlayer"];
if (!GVAR(mapGlow)) exitWith {};
private _unitLight = _disconnectedPlayer getVariable [QGVAR(flashlight), ["", objNull]];
_unitLight params ["", "_glow"];
if ((!isNull _disconnectedPlayer) && {!isNull _glow}) then {
detach _glow;
deleteVehicle _glow;
};
nil
}];

View File

@ -2,8 +2,6 @@
#include "script_component.hpp" #include "script_component.hpp"
// BEGIN_COUNTER(blueForceTrackingUpdate); // BEGIN_COUNTER(blueForceTrackingUpdate);
private ["_groupsToDrawMarkers", "_playersToDrawMarkers", "_playerSide", "_anyPlayers", "_colour", "_marker"];
// Delete last set of markers (always) // Delete last set of markers (always)
{ {
deleteMarkerLocal _x; deleteMarkerLocal _x;
@ -13,8 +11,8 @@ GVAR(BFT_markers) = [];
if (GVAR(BFT_Enabled) and {(!isNil "ACE_player") and {alive ACE_player}}) then { if (GVAR(BFT_Enabled) and {(!isNil "ACE_player") and {alive ACE_player}}) then {
_groupsToDrawMarkers = []; private _groupsToDrawMarkers = [];
_playerSide = call EFUNC(common,playerSide); private _playerSide = call EFUNC(common,playerSide);
_groupsToDrawMarkers = allGroups select {side _x == _playerSide}; _groupsToDrawMarkers = allGroups select {side _x == _playerSide};
@ -27,7 +25,7 @@ if (GVAR(BFT_Enabled) and {(!isNil "ACE_player") and {alive ACE_player}}) then {
}; };
if (GVAR(BFT_ShowPlayerNames)) then { if (GVAR(BFT_ShowPlayerNames)) then {
_playersToDrawMarkers = allPlayers select {side _x == _playerSide}; private _playersToDrawMarkers = allPlayers select {side _x == _playerSide};
{ {
private _markerType = [_x] call EFUNC(common,getMarkerType); private _markerType = [_x] call EFUNC(common,getMarkerType);

View File

@ -20,27 +20,27 @@
params ["", "_player"]; params ["", "_player"];
private["_action", "_actions", "_cfg", "_displayName", "_flashlights", "_icon", "_statement"]; private _actions = [];
private _flashlightItems = [_player] call FUNC(getUnitFlashlights);
_actions = []; private _unitLight = _player getVariable [QGVAR(flashlight), ["", objNull]];
_flashlights = [_player] call FUNC(getUnitFlashlights); _unitLight params ["_flashlight", ""];
//add all carried flashlight menus and on/off submenu actions //add all carried flashlight menus and on/off submenu actions
{ {
_cfg = (configFile >> "CfgWeapons" >> _x); private _cfg = (configFile >> "CfgWeapons" >> _x);
_displayName = getText (_cfg >> "displayName"); private _displayName = getText (_cfg >> "displayName");
_icon = getText (_cfg >> "picture"); private _icon = getText (_cfg >> "picture");
_statement = if (GVAR(flashlightInUse) == _x) then { private _statement = if (_flashlight == _x) then {
_displayName = format [localize LSTRING(turnLightOff), _displayName]; _displayName = format [localize LSTRING(turnLightOff), _displayName];
{[""] call FUNC(switchFlashlight)} {[_player, ""] call FUNC(switchFlashlight)}
} else { } else {
_displayName = format [localize LSTRING(turnLightOn), _displayName]; _displayName = format [localize LSTRING(turnLightOn), _displayName];
{[_this select 2] call FUNC(switchFlashlight)} {[_player, _this select 2] call FUNC(switchFlashlight)}
}; };
_action = [_x, _displayName, _icon, _statement, {true}, {}, _x] call EFUNC(interact_menu,createAction); _action = [_x, _displayName, _icon, _statement, {true}, {}, _x] call EFUNC(interact_menu,createAction);
_actions pushBack [_action, [], _player]; _actions pushBack [_action, [], _player];
} forEach _flashlights; } forEach _flashlightItems;
_actions _actions

View File

@ -1,23 +1,23 @@
/* /*
* Author: Rocko and esteldunedain * Author: Rocko and esteldunedain
* Calculates the current map illumination for a given unit * Calculates the current map illumination for a given unit
* *
* Arguments: * Arguments:
* 0: Unit <OBJECT> * 0: Unit <OBJECT>
* *
* Return Value: * Return Value:
* 0: Does the map needs shading? <BOOL> * 0: Does the map needs shading? <BOOL>
* 1: Color of the overlay <ARRAY> * 1: Color of the overlay <ARRAY>
* *
* Public: No * Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
params ["_unit"]; params ["_unit"];
private ["_fnc_blendColor", "_lightTint", "_fnc_calcColor", "_l", "_lightLevel", "_vehicle", "_isEnclosed", "_nearObjects", "_light", "_ll", "_flashlight", "_flareTint"];
// Blend two colors // Blend two colors
_fnc_blendColor = { private _fnc_blendColor = {
params ["_c1", "_c2", "_alpha"]; params ["_c1", "_c2", "_alpha"];
[(_c1 select 0) * (1 - _alpha) + (_c2 select 0) * _alpha, [(_c1 select 0) * (1 - _alpha) + (_c2 select 0) * _alpha,
(_c1 select 1) * (1 - _alpha) + (_c2 select 1) * _alpha, (_c1 select 1) * (1 - _alpha) + (_c2 select 1) * _alpha,
@ -26,58 +26,25 @@ _fnc_blendColor = {
}; };
// Ambient light tint depending on time of day // Ambient light tint depending on time of day
_lightTint = call { private _lightTint = call {
if (sunOrMoon == 1.0) exitWith { [0.5,0.5,0.5,1] }; 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.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.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] }; if (sunOrMoon <= 0.5) exitWith {[0,0,0.1,1]};
[0,0,0,0] [0,0,0,0]
}; };
// Calculates overlay color from tint and light level private _lightLevel = 0.04 + (0.96 * call EFUNC(common,ambientBrightness));
_fnc_calcColor = {
params ["_c1", "_lightLevel"];
if (_lightLevel < 0.5) then {
_l = _lightLevel / 0.5;
[(_c1 select 0) * _l,
(_c1 select 1) * _l,
(_c1 select 2) * _l,
(_c1 select 3) * (1 - _lightLevel)]
} else {
_l = (_lightLevel - 0.5) / 0.5;
[(_c1 select 0) * (1 - _l) + _l,
(_c1 select 1) * (1 - _l) + _l,
(_c1 select 2) * (1 - _l) + _l,
(_c1 select 3) * (1 - _lightLevel)]
};
};
_lightLevel = 0.04 + (0.96 * call EFUNC(common,ambientBrightness));
/*
// check if player has NVG enabled
if (currentVisionMode _unit == 1) exitWith {
// stick to nvg color
[true, [154/255,253/255,177/255,0.5]]
};
*/
// Do not obscure the map if the ambient light level is above 0.95 // Do not obscure the map if the ambient light level is above 0.95
if (_lightLevel > 0.95) exitWith { if (_lightLevel > 0.95) exitWith {
[false, [0.5,0.5,0.5,0]] [false, [1,1,1,0]]
}; };
_vehicle = vehicle _unit; private _vehicle = vehicle _unit;
// Do not obscure the map if the player is on a enclosed vehicle (assume internal illumination) // Do not obscure the map if the player is on a enclosed vehicle (assume internal illumination)
if (_vehicle != _unit) then { if ((_vehicle != _unit) && {!isTurnedOut _unit && {_vehicle isKindOf "Tank" || {(_vehicle isKindOf "Helicopter" || _vehicle isKindOf "Plane") && {driver _vehicle == _unit || {gunner _vehicle == _unit}}} || {_vehicle isKindOf "Wheeled_APC"}}}) exitWith {
// Player is in a vehicle
if (!isTurnedOut _unit && { _vehicle isKindOf "Tank" || { ( _vehicle isKindOf "Helicopter" || _vehicle isKindOf "Plane" ) && { (driver _vehicle) == _unit || { (gunner _vehicle) == _unit } } } || {_vehicle isKindOf "Wheeled_APC"}}) then {
_isEnclosed = true;
};
};
if (_isEnclosed) exitWith {
TRACE_1("Player in a enclosed vehicle",""); TRACE_1("Player in a enclosed vehicle","");
[false, [1,1,1,0]] [false, [1,1,1,0]]
}; };
@ -93,29 +60,38 @@ TRACE_1("Player is on foot or in an open vehicle","");
// @todo: Illumination flares (timed) // @todo: Illumination flares (timed)
// Using chemlights // Using chemlights
_nearObjects = (_unit nearObjects ["SmokeShell", 4]) select {alive _x && {toLower typeOf _x in ["chemlight_red", "chemlight_green", "chemlight_blue", "chemlight_yellow"]}}; private _nearObjects = (_unit nearObjects ["Chemlight_base", 4]) select {alive _x};
if (count (_nearObjects) > 0) then { if !(_nearObjects isEqualTo []) then {
_light = _nearObjects select 0; private _nearestlight = _nearObjects select 0;
private _lightLevelTemp = (1 - ((((_unit distance _nearestlight) - 2) / 2) max 0)) * 0.4;
_ll = (1 - ((((_unit distance _light) - 2)/2) max 0)) * 0.4; if (_lightLevelTemp > _lightLevel) then {
if (_ll > _lightLevel) then { private _flareTint = getArray (configFile >> "CfgLights" >> (getText (configFile >> (getText (configFile >> "CfgAmmo" >> typeOf _nearestlight >> "EffectsSmoke")) >> "Light1" >> "type")) >> "color");
_flareTint = switch (toLower typeOf _light) do { _lightTint = [_lightTint, _flareTint, (_lightLevelTemp - _lightLevel) / (1 - _lightLevel)] call _fnc_blendColor;
case "chemlight_red" : {[1,0,0,1]}; _lightLevel = _lightLevelTemp;
case "chemlight_green" : {[0,1,0,1]};
case "chemlight_blue" : {[0,0,1,1]};
case "chemlight_yellow" : {[1,1,0,1]};
};
_lightTint = [_lightTint, _flareTint, (_ll - _lightLevel)/(1 - _lightLevel)] call _fnc_blendColor;
_lightLevel = _ll;
TRACE_1("player near chemlight",""); TRACE_1("player near chemlight","");
}; };
}; };
// Do not obscure the map if the ambient light level is above 0.95 // Do not obscure the map if the ambient light level is above 0.95
if (_lightLevel > 0.95) exitWith { if (_lightLevel > 0.95) exitWith {
[false, [0.5,0.5,0.5,0]] [false, [1,1,1,0]]
}; };
// Calculate resulting map color // Calculate resulting map color from tint and light level
[true, [_lightTint, _lightLevel] call _fnc_calcColor] private _halfLight = _lightLevel / 0.5;
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)]
};
[true, _finalLevel]

View File

@ -12,15 +12,14 @@
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_grids", "_fourSize", "_sixSize", "_continue", "_size", "_i"]; private _grids = (configFile >> "CfgWorlds" >> worldName >> "Grid");
_grids = (configFile >> "CfgWorlds" >> worldName >> "Grid"); private _fourSize = -1;
_fourSize = -1; private _sixSize = -1;
_sixSize = -1;
for "_i" from 1 to 10 do { for "_i" from 1 to 10 do {
_continue = false; private _continue = false;
if (isClass(_grids >> format["Zoom%1", _i])) then { if (isClass(_grids >> format["Zoom%1", _i])) then {
_continue = true; _continue = true;
_size = getText(_grids >> format["Zoom%1", _i] >> "formatX"); private _size = getText(_grids >> format["Zoom%1", _i] >> "formatX");
if ((count toArray(_size)) == 2) then { if ((count toArray(_size)) == 2) then {
_fourSize = getNumber(_grids >> format["Zoom%1", _i] >> "zoomMax"); _fourSize = getNumber(_grids >> format["Zoom%1", _i] >> "zoomMax");
}; };

View File

@ -3,36 +3,44 @@
* Add or remove global flashlight glow for when player is looking at map. * Add or remove global flashlight glow for when player is looking at map.
* *
* Arguments: * Arguments:
* 0: Flashlight classname ("" for off) <STRING> * 0: Unit <OBJECT>
* 1: Flashlight classname ("" for off) <STRING>
* 2: Set the PVAR? <BOOL> (default: true)
* *
* Return value: * Return value:
* None * Glow object <OBJECT>
* *
* Example: * Example:
* ["ACE_Flashlight_MX991"] call ace_map_fnc_flashlightGlow; * [ACE_player, "ACE_Flashlight_MX991"] call ace_map_fnc_flashlightGlow;
* *
* Public: No * Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
params ["_flashlight"]; params ["_unit", "_flashlightType", ["_set", true]];
private _light = GVAR(glow); private _unitLight = _unit getVariable [QGVAR(flashlight), ["", objNull]];
if (!isNull _light) then { _unitLight params ["_flashlight", "_glow"];
detach _light;
deleteVehicle _light; if (!isNull _glow) then {
detach _glow;
deleteVehicle _glow;
}; };
if (_flashlight != "") then { if !(_flashlightType isEqualTo "") then {
private _color = getText (configFile >> "CfgWeapons" >> _flashlight >> "ItemInfo" >> "FlashLight" >> "ACE_Flashlight_Colour"); private _color = getText (configFile >> "CfgWeapons" >> _flashlightType >> "ItemInfo" >> "FlashLight" >> "ACE_Flashlight_Colour");
if !(_color in ["white", "red", "green", "blue", "yellow", "orange"]) then {_color = "white"}; if !(_color in ["white", "red", "green", "blue", "yellow", "orange"]) then {_color = "white"};
private _class = format["ACE_FlashlightProxy_%1", _color]; private _class = format ["ACE_FlashlightProxy_%1", _color];
_light = _class createVehicle [0,0,0]; _glow = _class createVehicle [0,0,0];
_light attachTo [ACE_player, [0,0.1,-0.05], "neck"]; _glow attachTo [_unit, [0,0.1,-0.05], "neck"];
} else { } else {
_light = objNull; _glow = objNull;
}; };
GVAR(glow) = _light; if (_set) then {
_unit setVariable [QGVAR(flashlight), [_flashlight, _glow], true];
};
_glow

View File

@ -1,48 +1,47 @@
/* /*
* Author: voiper * Author: voiper
* Draw nearby lighting and sexy flashlight beams on main map. * Draw nearby lighting and sexy flashlight beams on main map.
* *
* Arguments: * Arguments:
* 0: Map control <CONTROL> * 0: Map control <CONTROL>
* 1: Map zoom level <NUMBER> * 1: Map zoom level <NUMBER>
* 2: Current map centre <ARRAY> * 2: Current map centre <ARRAY>
* 3: Light level from ace_map_fnc_determineMapLight <ARRAY> * 3: Light level from ace_map_fnc_determineMapLight <ARRAY>
* *
* Return Value: * Return Value:
* None * None
* *
* Public: No * Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_hmd", "_flashlight", "_screenSize", "_realViewPortY", "_realViewPortX", "_fillTex", "_colourAlpha", "_shadeAlpha", "_colourList", "_maxColour"];
params ["_mapCtrl", "_mapScale", "_mapCentre", "_lightLevel"]; params ["_mapCtrl", "_mapScale", "_mapCentre", "_lightLevel"];
_hmd = hmd ACE_player; private _unitLight = ACE_player getVariable [QGVAR(flashlight), ["", objNull]];
_flashlight = GVAR(flashlightInUse); _unitLight params ["_flashlight", ""];
//map width (on screen) in pixels //map width (on screen) in pixels
_screenSize = 640 * safeZoneWAbs; private _screenSize = 640 * safeZoneWAbs;
//resolution params (every frame in case resolution change) //resolution params (every frame in case resolution change)
getResolution params ["_resX", "_resY", "_viewPortX", "_viewPortY", "", "_uiScale"]; getResolution params ["_resX", "_resY", "_viewPortX", "_viewPortY", "", "_uiScale"];
//engine rounds the viewport ratios, when they should be fractions; this can cause problems //engine rounds the viewport ratios, when they should be fractions; this can cause problems
_realViewPortY = _resY * _uiScale; private _realViewPortY = _resY * _uiScale;
_realViewPortX = _realViewPortY * 4/3; private _realViewPortX = _realViewPortY * 4/3;
//textures //textures
_fillTex = "#(rgb,8,8,3)color(0,0,0,1)"; private _fillTex = "#(rgb,8,8,3)color(0,0,0,1)";
//colour/alpha //colour/alpha
_lightLevel params ["_r", "_g", "_b", "_a"]; _lightLevel params ["_r", "_g", "_b", "_a"];
_colourAlpha = (_r + _g + _b) min _a; private _colourAlpha = (_r + _g + _b) min _a;
_shadeAlpha = _a; private _shadeAlpha = _a;
_colourList = [_r, _g, _b]; private _colourList = [_r, _g, _b];
_colourList sort false; _colourList sort false;
_maxColour = _colourList select 0; private _maxColour = _colourList select 0;
//ambient colour fill //ambient colour fill
_mapCtrl drawIcon [format["#(rgb,8,8,3)color(%1,%2,%3,1)", _r / _maxColour, _g / _maxColour, _b / _maxColour], [1,1,1,_colourAlpha], _mapCentre, _screenSize, _screenSize, 0, "", 0]; _mapCtrl drawIcon [format["#(rgb,8,8,3)color(%1,%2,%3,1)", _r / _maxColour, _g / _maxColour, _b / _maxColour], [1,1,1,_colourAlpha], _mapCentre, _screenSize, _screenSize, 0, "", 0];
@ -51,21 +50,19 @@ if (_flashlight == "") then {
//ambient shade fill //ambient shade fill
_mapCtrl drawIcon [_fillTex, [1,1,1,_shadeAlpha], _mapCentre, _screenSize, _screenSize, 0, "", 0]; _mapCtrl drawIcon [_fillTex, [1,1,1,_shadeAlpha], _mapCentre, _screenSize, _screenSize, 0, "", 0];
} else { } else {
private ["_mousePos", "_cfg", "_size", "_flashTex", "_beamSize", "_viewPortRatioFixY", "_offsetX", "_offsetYDown", "_offsetYUp"]; private _mousePos = GVAR(mousePos);
//mouse pos
_mousePos = GVAR(mousePos);
//flashlight settings //flashlight settings
_cfg = (configFile >> "CfgWeapons" >> _flashlight >> "ItemInfo" >> "FlashLight"); private _cfg = (configFile >> "CfgWeapons" >> _flashlight >> "ItemInfo" >> "FlashLight");
_size = getNumber (_cfg >> "ACE_Flashlight_Size"); private _size = getNumber (_cfg >> "ACE_Flashlight_Size");
_flashTex = getText (_cfg >> "ACE_Flashlight_Beam"); private _flashTex = getText (_cfg >> "ACE_Flashlight_Beam");
_beamSize = (safeZoneW/safeZoneWAbs) * _screenSize / _size; private _beamSize = (safeZoneW/safeZoneWAbs) * _screenSize / _size;
//after 5x zoom, it's simulated to be fixed (it actually gets bigger relative to zoom) //after 5x zoom, it's simulated to be fixed (it actually gets bigger relative to zoom)
if (_mapScale < 0.2) then {_beamSize = _beamSize / (_mapScale * (1 / 0.2))}; if (_mapScale < 0.2) then {_beamSize = _beamSize / (_mapScale * (1 / 0.2))};
//assign corrective ratio to fix sub-pixel gaps/overlaps (symptom of viewport * X/Y resolution rounding) //assign corrective ratio to fix sub-pixel gaps/overlaps (symptom of viewport * X/Y resolution rounding)
_viewPortRatioFixY = if (_realViewPortY != _viewPortY) then { private _viewPortRatioFixY = if (_realViewPortY != _viewPortY) then {
_realViewPortX / (_realViewPortY / _viewPortY * _viewPortX) _realViewPortX / (_realViewPortY / _viewPortY * _viewPortX)
} else { } else {
if (_realViewPortX != _viewPortX) then { if (_realViewPortX != _viewPortX) then {
@ -76,10 +73,10 @@ if (_flashlight == "") then {
}; };
//offset the elements //offset the elements
_offsetX = _mapScale * GVAR(worldSize) * (_screenSize * 2 + _beamSize); private _offsetX = _mapScale * GVAR(worldSize) * (_screenSize * 2 + _beamSize);
_offsetYDown = _mapScale * GVAR(worldSize) * (_screenSize + _beamSize) * _viewPortRatioFixY; private _offsetYDown = _mapScale * GVAR(worldSize) * (_screenSize + _beamSize) * _viewPortRatioFixY;
//up is bigger because of a potential exploit //up is bigger because of a potential exploit
_offsetYUp = _mapScale * GVAR(worldSize) * (_screenSize * 4 + _beamSize) * _viewPortRatioFixY; private _offsetYUp = _mapScale * GVAR(worldSize) * (_screenSize * 4 + _beamSize) * _viewPortRatioFixY;
//draw the matrix /whoa //draw the matrix /whoa
_mapCtrl drawIcon [_flashTex, [1,1,1,_shadeAlpha], _mousePos, _beamSize, _beamSize, 0, "", 0]; //centre beam _mapCtrl drawIcon [_flashTex, [1,1,1,_shadeAlpha], _mousePos, _beamSize, _beamSize, 0, "", 0]; //centre beam

View File

@ -3,31 +3,37 @@
* Switch flashlight on/off. * Switch flashlight on/off.
* *
* Arguments: * Arguments:
* 0: New flashlight classname ("" for off) <STRING> * 0: Unit <OBJECT>
* 1: New flashlight classname ("" for off) <STRING>
* *
* Return value: * Return value:
* None * None
* *
* Example: * Example:
* ["ACE_Flashlight_MX991"] call ace_map_fnc_switchFlashlight; * [ACE_player, "ACE_Flashlight_MX991"] call ace_map_fnc_switchFlashlight;
* *
* Public: No * Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
params ["_newFlashlight"]; params ["_unit", "_newFlashlight"];
private _oldFlashlight = GVAR(flashlightInUse);
private _unitLight = _unit getVariable [QGVAR(flashlight), ["", objNull]];
_unitLight params ["_flashlight", "_glow"];
if (GVAR(mapGlow)) then { if (GVAR(mapGlow)) then {
[_newFlashlight] call FUNC(flashlightGlow); // we don't want to set the PVAR twice in a row, so tell this func not to set it
_glow = [_unit, _newFlashlight, false] call FUNC(flashlightGlow);
}; };
private _config = (configFile >> "CfgWeapons");
if ( if (
(getNumber (configFile >> "CfgWeapons" >> _newFlashlight >> "ItemInfo" >> "FlashLight" >> "ACE_Flashlight_Sound") > 0) || (getNumber (_config >> _newFlashlight >> "ItemInfo" >> "FlashLight" >> "ACE_Flashlight_Sound") > 0) ||
{getNumber (configFile >> "CfgWeapons" >> _oldFlashlight >> "ItemInfo" >> "FlashLight" >> "ACE_Flashlight_Sound") > 0} {getNumber (_config >> _flashlight >> "ItemInfo" >> "FlashLight" >> "ACE_Flashlight_Sound") > 0}
) then { ) then {
playSound QGVAR(flashlightClick); playSound QGVAR(flashlightClick);
}; };
GVAR(flashlightInUse) = _newFlashlight; _unit setVariable [QGVAR(flashlight), [_newFlashlight, _glow], true];

View File

@ -1,25 +1,25 @@
/* /*
* Author: Rocko and esteldunedain * Author: Rocko and esteldunedain
* On map draw, updates the effects * On map draw, updates the effects
* *
* Arguments: * Arguments:
* None * None
* *
* Return Value: * Return Value:
* None * None
* *
* Public: No * Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_mapCtrl", "_mapScale", "_mapCentre", "_light"];
_mapCtrl = findDisplay 12 displayCtrl 51; params ["_mapCtrl"];
_mapScale = ctrlMapScale _mapCtrl; private _mapScale = ctrlMapScale _mapCtrl;
_mapCentre = _mapCtrl ctrlMapScreenToWorld [0.5, 0.5]; private _mapCentre = _mapCtrl ctrlMapScreenToWorld [0.5, 0.5];
if (GVAR(mapIllumination)) then { if (GVAR(mapIllumination)) then {
//get nearby lighting //get nearby lighting
_light = [[ACE_player], FUNC(determineMapLight), missionNamespace, QGVAR(mapLight), 0.1] call EFUNC(common,cachedCall); private _light = [[ACE_player], FUNC(determineMapLight), missionNamespace, QGVAR(mapLight), 0.1] call EFUNC(common,cachedCall);
_light params ["_applyLighting", "_lightLevel"]; _light params ["_applyLighting", "_lightLevel"];
@ -29,10 +29,9 @@ if (GVAR(mapIllumination)) then {
}; };
if (GVAR(mapShake)) then { if (GVAR(mapShake)) then {
private ["_speed","_amplitude", "_time", "_shakePos"];
// Only shake map while moving on foot // Only shake map while moving on foot
_speed = 0; private _speed = 0;
if (vehicle ACE_player == ACE_player) then { if (vehicle ACE_player == ACE_player) then {
_speed = vectorMagnitude (velocity ACE_player); _speed = vectorMagnitude (velocity ACE_player);
}; };
@ -41,10 +40,10 @@ if (GVAR(mapShake)) then {
if (_speed > 0.1) then { if (_speed > 0.1) then {
if (ctrlMapAnimDone _mapCtrl) then { if (ctrlMapAnimDone _mapCtrl) then {
_amplitude = (_speed - 0.1) / 5 * (1000 * _mapScale); private _amplitude = (_speed - 0.1) / 5 * (1000 * _mapScale);
_time = 0.1; private _time = 0.1;
_shakePos = [(GVAR(lastStillPosition) select 0) + sin((CBA_missionTime + _time - GVAR(lastStillTime))*100) * _amplitude * 0.25, private _shakePos = [(GVAR(lastStillPosition) select 0) + sin((CBA_missionTime + _time - GVAR(lastStillTime))*100) * _amplitude * 0.25,
(GVAR(lastStillPosition) select 1) + sin((CBA_missionTime + _time - GVAR(lastStillTime))*260) * _amplitude]; (GVAR(lastStillPosition) select 1) + sin((CBA_missionTime + _time - GVAR(lastStillTime))*260) * _amplitude];
_mapCtrl ctrlMapAnimAdd [_time, _mapScale, _shakePos]; _mapCtrl ctrlMapAnimAdd [_time, _mapScale, _shakePos];