mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Initial port/reimplementation of ace_mapfx, providing:
- dynamic map illumination - shacking maps when on the move - optional max zoom
This commit is contained in:
parent
d02b5d2125
commit
8d0cc787b0
1
addons/mapfx/$PBOPREFIX$
Normal file
1
addons/mapfx/$PBOPREFIX$
Normal file
@ -0,0 +1 @@
|
||||
x\ace\addons\mapfx
|
11
addons/mapfx/CfgEventhandlers.hpp
Normal file
11
addons/mapfx/CfgEventhandlers.hpp
Normal file
@ -0,0 +1,11 @@
|
||||
class Extended_PreInit_EventHandlers {
|
||||
class ADDON {
|
||||
init = QUOTE(call COMPILE_FILE(XEH_preInit));
|
||||
};
|
||||
};
|
||||
|
||||
class Extended_PostInit_EventHandlers {
|
||||
class ADDON {
|
||||
clientInit = QUOTE(call COMPILE_FILE(XEH_postClientInit));
|
||||
};
|
||||
};
|
21
addons/mapfx/XEH_postClientInit.sqf
Normal file
21
addons/mapfx/XEH_postClientInit.sqf
Normal file
@ -0,0 +1,21 @@
|
||||
#include "script_component.hpp"
|
||||
|
||||
ADDON = false;
|
||||
LOG(MSG_INIT);
|
||||
|
||||
call FUNC(determineZoom);
|
||||
|
||||
//Probably need this spawn, because CBA_fnc_addPerFrameHandler doesn't work durring briefing.
|
||||
[] spawn {
|
||||
// Wait until the map display is detected
|
||||
waitUntil {(!isNull findDisplay 12)};
|
||||
|
||||
GVAR(lastStillPosition) = ((findDisplay 12) displayCtrl 51) ctrlMapScreenToWorld [0.5, 0.5];
|
||||
GVAR(lastStillTime) = time;
|
||||
GVAR(isShaking) = false;
|
||||
|
||||
((findDisplay 12) displayCtrl 51) ctrlAddEventHandler ["Draw", {[] call FUNC(updateMapFx);}];
|
||||
|
||||
};
|
||||
|
||||
ADDON = true;
|
11
addons/mapfx/XEH_preInit.sqf
Normal file
11
addons/mapfx/XEH_preInit.sqf
Normal file
@ -0,0 +1,11 @@
|
||||
//#define DEBUG_MODE_FULL
|
||||
#include "script_component.hpp"
|
||||
|
||||
ADDON = false;
|
||||
LOG(MSG_INIT);
|
||||
|
||||
PREP(determineMapLight);
|
||||
PREP(determineZoom);
|
||||
PREP(updateMapFx);
|
||||
|
||||
ADDON = true;
|
20
addons/mapfx/config.cpp
Normal file
20
addons/mapfx/config.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
#include "script_component.hpp"
|
||||
class CfgPatches {
|
||||
class ADDON {
|
||||
units[] = {};
|
||||
weapons[] = {};
|
||||
requiredVersion = REQUIRED_VERSION;
|
||||
requiredAddons[] = {"ace_interaction"};
|
||||
author[] = {"Rocko","CAA-Picard"};
|
||||
VERSION_CONFIG;
|
||||
};
|
||||
};
|
||||
|
||||
#include "CfgEventHandlers.hpp"
|
||||
|
||||
class ACE_Settings {
|
||||
class GVAR(limitZoom) {
|
||||
value = 0;
|
||||
typeName = "BOOL";
|
||||
};
|
||||
};
|
125
addons/mapfx/functions/fnc_determineMapLight.sqf
Normal file
125
addons/mapfx/functions/fnc_determineMapLight.sqf
Normal file
@ -0,0 +1,125 @@
|
||||
#include "script_component.hpp"
|
||||
|
||||
//TODO: Fix NVG color
|
||||
private ["_darkMap","_lightColor","_lightFill","_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);
|
||||
|
||||
_lightColor = [0,0,0,((_alpha*1.1) min 1)];
|
||||
_lightFill = format["#(rgb,1,1,1)color(0,0,0,%1)",_alpha];
|
||||
_darkMap = true;
|
||||
_createLight = 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 {
|
||||
|
||||
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","");
|
||||
};
|
||||
};
|
||||
} else {
|
||||
// Player is in a vehicle
|
||||
if ((vehicle ACE_player) isKindOf "Tank") exitWith {
|
||||
_darkMap = 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]
|
33
addons/mapfx/functions/fnc_determineZoom.sqf
Normal file
33
addons/mapfx/functions/fnc_determineZoom.sqf
Normal file
@ -0,0 +1,33 @@
|
||||
#include "script_component.hpp"
|
||||
|
||||
// TODO: Perhaps change to return values instead of setting GVAR's directly
|
||||
|
||||
private ["_grids", "_fourSize", "_sixSize", "_continue", "_size"];
|
||||
_grids = configFile >> "CfgWorlds" >> worldName >> "Grid";
|
||||
_fourSize = -1;
|
||||
_sixSize = -1;
|
||||
for "_i" from 1 to 10 do {
|
||||
_continue = false;
|
||||
if (isClass(_grids >> format["Zoom%1", _i])) then {
|
||||
_continue = true;
|
||||
_size = getText(_grids >> format["Zoom%1", _i] >> "formatX");
|
||||
if ((count toArray(_size)) == 2) then {
|
||||
_fourSize = getNumber(_grids >> format["Zoom%1", _i] >> "zoomMax");
|
||||
};
|
||||
if ((count toArray(_size)) == 3) then {
|
||||
_sixSize = getNumber(_grids >> format["Zoom%1", _i] >> "zoomMax");
|
||||
};
|
||||
if (_fourSize != -1 && {_sixSize != -1}) then {
|
||||
_continue = false;
|
||||
};
|
||||
};
|
||||
if (!_continue) exitWith {};
|
||||
};
|
||||
|
||||
if(_fourSize != -1 && {_sixSize != -1}) then {
|
||||
if (isNil QGVAR(minMapSize)) then {
|
||||
GVAR(minMapSize) = _sixSize + 0.01
|
||||
} else {
|
||||
GVAR(minMapSize) = -1
|
||||
};
|
||||
};
|
70
addons/mapfx/functions/fnc_updateMapFx.sqf
Normal file
70
addons/mapfx/functions/fnc_updateMapFx.sqf
Normal file
@ -0,0 +1,70 @@
|
||||
#include "script_component.hpp"
|
||||
|
||||
// Calculate the light
|
||||
//_data = [[], FUNC(determineMapLight), missionNamespace, QGVAR(mapLight), 0.1] call EFUNC(common,cachedCall);
|
||||
_data = call FUNC(determineMapLight);
|
||||
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];
|
||||
} else {
|
||||
if (_externalLight) then {
|
||||
[] spawn {
|
||||
_light = ACE_player getVariable ['ace_map_light',objNull];
|
||||
if (isNull _light) then {
|
||||
_type = if (ACE_player == vehicle ACE_player) then { 'ACE_Flashlight' } else { 'ACE_Dashlight' };
|
||||
_light = _type createVehicle (getPos ACE_player);
|
||||
_light attachTo [(vehicle ACE_player), if (_type == 'ACE_Flashlight') then { [0,0.4,1] } else { [0,0,-1]}];
|
||||
ACE_player setVariable ['ace_map_light',_light];
|
||||
waitUntil {sleep 0.1; !visibleMap; };
|
||||
deleteVehicle _light;
|
||||
ACE_player setVariable ['ace_map_light',objNull];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
_ctrl = ((findDisplay 12) displayCtrl 51);
|
||||
_scale = ctrlMapScale _ctrl;
|
||||
|
||||
_speed = 0;
|
||||
if (vehicle ACE_player == ACE_player) then {
|
||||
_speed = vectorMagnitude (velocity ACE_player);
|
||||
};
|
||||
|
||||
|
||||
if (_speed > 0.1) then {
|
||||
if (ctrlMapAnimDone _ctrl) then {
|
||||
|
||||
_amplitude = (_speed - 0.1) / 5 * (1000 * _scale);
|
||||
_time = 0.1;
|
||||
|
||||
_shakePos = [(GVAR(lastStillPosition) select 0) + sin((time + _time - GVAR(lastStillTime))*100) * _amplitude * 0.25,
|
||||
(GVAR(lastStillPosition) select 1) + sin((time + _time - GVAR(lastStillTime))*260) * _amplitude];
|
||||
|
||||
_ctrl ctrlMapAnimAdd [_time, _scale, _shakePos];
|
||||
ctrlMapAnimCommit _ctrl;
|
||||
|
||||
GVAR(isShaking) = true;
|
||||
};
|
||||
} else {
|
||||
if (GVAR(isShaking)) then {
|
||||
_ctrl ctrlMapAnimAdd [0, _scale, GVAR(lastStillPosition)];
|
||||
ctrlMapAnimCommit _ctrl;
|
||||
GVAR(isShaking) = false;
|
||||
} else {
|
||||
ctrlMapAnimClear _ctrl;
|
||||
GVAR(lastStillPosition) = _ctrl ctrlMapScreenToWorld [0.5, 0.5];
|
||||
GVAR(lastStillTime) = time;
|
||||
|
||||
if (GVAR(limitZoom)) then {
|
||||
if (GVAR(minMapSize) >= _scale) then {
|
||||
_ctrl ctrlMapAnimAdd [0, GVAR(minMapSize) + 0.001, (_ctrl ctrlMapScreenToWorld [0.5, 0.5])];
|
||||
ctrlMapAnimCommit _ctrl;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
1
addons/mapfx/functions/script_component.hpp
Normal file
1
addons/mapfx/functions/script_component.hpp
Normal file
@ -0,0 +1 @@
|
||||
#include "\z\ace\addons\mapfx\script_component.hpp"
|
12
addons/mapfx/script_component.hpp
Normal file
12
addons/mapfx/script_component.hpp
Normal file
@ -0,0 +1,12 @@
|
||||
#define COMPONENT mapfx
|
||||
#include "\z\ace\addons\main\script_mod.hpp"
|
||||
|
||||
#ifdef DEBUG_ENABLED_MAPFX
|
||||
#define DEBUG_MODE_FULL
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_SETTINGS_MAPFX
|
||||
#define DEBUG_SETTINGS DEBUG_SETTINGS_MAPFX
|
||||
#endif
|
||||
|
||||
#include "\z\ace\addons\main\script_macros.hpp"
|
Loading…
Reference in New Issue
Block a user