diff --git a/.gitignore b/.gitignore index a9ca5f2..d33a722 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,12 @@ # Build output -addons/*.pbo +/.hemttout/ # Releases -releases/* +/releases/ + hemtt hemtt.exe +.hemtt/local symbols/* # Bikey diff --git a/.hemtt/project.toml b/.hemtt/project.toml new file mode 100644 index 0000000..44d7453 --- /dev/null +++ b/.hemtt/project.toml @@ -0,0 +1,85 @@ + +name = "ArmaForces Mission Framework" +mainprefix = "z" +prefix = "afmf" + +[files] +include = [ + "LICENSE", + "mod.cpp", + "README.md" +] + +exclude = ["*.psd", "*.png", "*.tga"] + +[properties] +author = "ArmaForces" + +[version] +path = "addons/main/script_version.hpp" + +# Unused in HEMTT v1.11 or higher, kept for backwards compatibility +[asc] +exclude = [ + ".inc.sqf", +] + +[hemtt.launch] +workshop = [ + "450814997", # CBA_A3 + "2369477168", # ADT +] +parameters = [ + "-name=dev", + "-window", +] + +[hemtt.launch.ace] +workshop = [ + "450814997", # CBA_A3 + "2369477168", # ADT + "463939057", # ACE +# "766491311", # KKA3 ACE Extension +] +parameters = [ + "-name=dev", + "-window", +] + +[hemtt.launch.cup] +workshop = [ + "450814997", # CBA_A3 + "2369477168", # ADT + "583496184", # CUP Terrains - Core + "583544987", # CUP Terrains - Maps +] +parameters = [ + "-name=dev", + "-window", +] + +[hemtt.launch.vn] +workshop = [ + "450814997", # CBA_A3 + "2369477168", # ADT +] +parameters = [ + "-name=dev", + "-window", +] +dlc = [ + "S.O.G. Prairie Fire", +] + +[hemtt.launch.ww2] +workshop = [ + "450814997", # CBA_A3 + "2369477168", # ADT +] +parameters = [ + "-name=dev", + "-window", +] +dlc = [ + "Spearhead 1944", +] diff --git a/addons/main/script_mod.hpp b/addons/main/script_mod.hpp index 37f3bc8..db167db 100644 --- a/addons/main/script_mod.hpp +++ b/addons/main/script_mod.hpp @@ -7,7 +7,7 @@ #define VERSION_STR MAJOR.MINOR.PATCH #define VERSION_AR MAJOR,MINOR,PATCH -#define REQUIRED_VERSION 1.94 +#define REQUIRED_VERSION 2.14 #ifdef COMPONENT_BEAUTIFIED #define COMPONENT_NAME QUOTE(AFMF - COMPONENT_BEAUTIFIED) diff --git a/addons/task_download/$PBOPREFIX$ b/addons/task_download/$PBOPREFIX$ new file mode 100644 index 0000000..9550119 --- /dev/null +++ b/addons/task_download/$PBOPREFIX$ @@ -0,0 +1 @@ +z\afmf\addons\task_download \ No newline at end of file diff --git a/addons/task_download/CfgEventHandlers.hpp b/addons/task_download/CfgEventHandlers.hpp new file mode 100644 index 0000000..e90bed4 --- /dev/null +++ b/addons/task_download/CfgEventHandlers.hpp @@ -0,0 +1,15 @@ +class Extended_PreStart_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_preStart)); + }; +}; +class Extended_PreInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_preInit)); + }; +}; +class Extended_PostInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_postInit)); + }; +}; diff --git a/addons/task_download/README.md b/addons/task_download/README.md new file mode 100644 index 0000000..6f421b6 --- /dev/null +++ b/addons/task_download/README.md @@ -0,0 +1,42 @@ +# Task Download + +A simple script that tracks "download" of some data and publishes event on success and failure, that can be used e.g., in Tasks Framework for completing or failing tasks. + +## Setup + +```SQF +private _downloadTime = 900; // In seconds +private _downloadSize = 3.42; // In GB +private _result = [laptop, _downloadTime, _downloadSize] call afmf_task_download_fnc_setupSimple; +``` + +## Settings + +For now there are no CBA Settings, but you can easily change some things via variables below if you'd like a different behaviour. + +```SQF +// Display refresh interval. Changing it after setup won't work correctly. +afmf_task_download_displayProgressOnScreenRefreshInterval = 1; +``` + +_Note that this might be changed at some point to proper CBA Settings._ + +## Events + +_Global events:_ + +- `afmf_task_download_started` +- `afmf_task_download_paused` **Not implemented** +- `afmf_task_download_resumed` **Not implemented** +- `afmf_task_download_successful` +- `afmf_task_download_failed` + +_Server side events:_ + +- `afmf_task_download_start` + +## Authors + +- [3Mydlo3](http://github.com/3Mydlo3) +- [Mike](https://github.com/Mike-MF) +- [Jonpas](https://github.com/jonpas) diff --git a/addons/task_download/XEH_PREP.hpp b/addons/task_download/XEH_PREP.hpp new file mode 100644 index 0000000..73a42f2 --- /dev/null +++ b/addons/task_download/XEH_PREP.hpp @@ -0,0 +1,9 @@ +PREP(canContinue); +PREP(displayProgressOnScreen); +PREP(formatEstimatedTimeRemaining); +PREP(formatProgress); +PREP(initDownloadAction); +PREP(initGetDeviceAction); +PREP(prepareDisplay); +PREP(setupSimple); +PREP(start); diff --git a/addons/task_download/XEH_postInit.sqf b/addons/task_download/XEH_postInit.sqf new file mode 100644 index 0000000..b081d7d --- /dev/null +++ b/addons/task_download/XEH_postInit.sqf @@ -0,0 +1,27 @@ +#include "script_component.hpp" + +if (isServer) then { + [QGVAR(start), FUNC(start)] call CBA_fnc_addEventHandler; + + [QGVAR(deviceUnplugged), { + params ["_object"]; + + _object setVariable [QGVAR(deviceUnplugged), true, true]; + [QGVAR(successful), [_object]] call CBA_fnc_globalEvent; + }] call CBA_fnc_addEventHandler; + + [QGVAR(successful), { + ["ocap_customEvent", ["generalEvent", "Intel was downloaded!"]] call CBA_fnc_serverEvent; + }] call CBA_fnc_addEventHandler; +}; + +if (hasInterface) then { + [QGVAR(failed), { + systemChat LLSTRING(Failed); + }] call CBA_fnc_addEventHandler; + + [QGVAR(startFailed), { + params ["_msg"]; + systemChat (_msg call BIS_fnc_localize); + }] call CBA_fnc_addEventHandler; +}; diff --git a/addons/task_download/XEH_preInit.sqf b/addons/task_download/XEH_preInit.sqf new file mode 100644 index 0000000..8acb8e8 --- /dev/null +++ b/addons/task_download/XEH_preInit.sqf @@ -0,0 +1,11 @@ +#include "script_component.hpp" +ADDON = false; + +PREP_RECOMPILE_START; +#include "XEH_PREP.hpp" +PREP_RECOMPILE_END; + +// Display refresh interval. Changing it after setup won't work correctly. +GVAR(displayProgressOnScreenRefreshInterval) = PROGRESS_INTERVAL; + +ADDON = true; diff --git a/addons/task_download/XEH_preStart.sqf b/addons/task_download/XEH_preStart.sqf new file mode 100644 index 0000000..a51262a --- /dev/null +++ b/addons/task_download/XEH_preStart.sqf @@ -0,0 +1,2 @@ +#include "script_component.hpp" +#include "XEH_PREP.hpp" diff --git a/addons/task_download/config.cpp b/addons/task_download/config.cpp new file mode 100644 index 0000000..94bf41c --- /dev/null +++ b/addons/task_download/config.cpp @@ -0,0 +1,20 @@ +#include "script_component.hpp" + +class CfgPatches { + class ADDON { + name = COMPONENT_NAME; + units[] = {}; + weapons[] = {}; + requiredVersion = REQUIRED_VERSION; + requiredAddons[] = { + "afmf_main", + "ace_interact_menu" + }; + skipWhenMissingDependencies = 1; + author = "ArmaForces"; + authors[] = {"3Mydlo3"}; + VERSION_CONFIG; + }; +}; + +#include "CfgEventHandlers.hpp" diff --git a/addons/task_download/functions/fnc_canContinue.sqf b/addons/task_download/functions/fnc_canContinue.sqf new file mode 100644 index 0000000..e6ee01f --- /dev/null +++ b/addons/task_download/functions/fnc_canContinue.sqf @@ -0,0 +1,20 @@ +#include "script_component.hpp" +/* + * Author: 3Mydlo3 + * Function checks if download from given object can continue. + * + * Arguments: + * 0: Object which is used for download + * + * Return Value: + * True if download can continue + * + * Example: + * [laptop] call afmf_task_download_fnc_canContinue + * + * Public: No + */ + +params [["_object", objNull]]; + +alive _object // return diff --git a/addons/task_download/functions/fnc_displayProgressOnScreen.sqf b/addons/task_download/functions/fnc_displayProgressOnScreen.sqf new file mode 100644 index 0000000..5104b68 --- /dev/null +++ b/addons/task_download/functions/fnc_displayProgressOnScreen.sqf @@ -0,0 +1,118 @@ +#include "script_component.hpp" +/* + * Author: Mike, Jonpas from Theseus Mods; 3Mydlo3 + * Only Laptop, Rugged Laptop & PC Set - Screen are actively supported. + * Has a laptop generate an intel download after an ACE interaction. + * Texture source is shown on the object via Attributes > Object Specific > Texture #X + * + * Further adjusted by 3Mydlo3 + * + * Arguments: + * 0: PFH Args + * 0: Last refresh time + * 1: Current terminal content + * 2: Object used for download + * 3: Total file size (in GB) to download + * 4: Texture source + * 5: Download tick rate + * 6: Pending terminal prepare steps + * 1: PFH Handle + * + * Return Value: + * None + * + * Example: + * None + * + * Public: No + */ + +params ["_args", "_handle"]; +_args params ["_lastTime", "_terminal", "_object", "_fileSize", "_textureSelection", "_downloadTime", "_terminalPrepare"]; + +// Exit if download hasn't yet started +if !(_object getVariable [QGVAR(downloadStarted), false]) exitWith {}; + +private _prepareFinished = _object getVariable [QGVAR(downloadIntel_prepareFinished_client), false]; + +// Prepare +if (!_prepareFinished) exitWith { + // 2s tick rate + if (_lastTime + PREPARATION_INTERVAL > CBA_missionTime) exitWith {}; + _args set [0, CBA_missionTime]; + + private _prepareStage = _object getVariable [QGVAR(downloadIntel_prepareStage_client), 0]; + + _terminal deleteAt (count _terminal - 1); + _terminal append (_terminalPrepare select _prepareStage); + + private _texture = format ['#(rgb,512,512,3)text(0,0,"EtelkaMonospacePro",0.03,"#1A1818","#00B200","%1")', _terminal joinString "\n"]; + _object setObjectTexture [_textureSelection, _texture]; + _object setVariable [QGVAR(downloadIntel_prepareStage_client), _prepareStage + 1]; + + if (_prepareStage + 1 >= count _terminalPrepare) then { + _object setVariable [QGVAR(downloadIntel_prepareFinished_client), true]; + }; +}; + +// Follow wanted download (tick) rate from here +if (_lastTime + _downloadTime > CBA_missionTime) exitWith {}; +_args set [0, CBA_missionTime]; + +// Show download progress +private _downloadStartTime = _object getVariable [QGVAR(downloadStartTime), 0]; +private _progressPerTick = _object getVariable [QGVAR(downloadProgressPerTick), MAX_PROGRESS]; +private _currentProgress = (CBA_missionTime - _downloadStartTime)/PROGRESS_INTERVAL * _progressPerTick max 0 min MAX_PROGRESS; + +private _progressBarStages = floor (_currentProgress / 10); +private _downloaded = _fileSize * (_currentProgress / 100); +private _progressBar = "[ ]"; +for "_i" from 1 to _progressBarStages do { + _progressBar = _progressBar splitString ""; + _progressBar set [_i, "="]; + _progressBar = _progressBar joinString ""; +}; + +private _progressString = format [" %1GB / %2GB %3 (%4)\n", _downloaded, _fileSize, _progressBar, [_currentProgress] call FUNC(formatProgress)]; +_terminal set [-3, _progressString]; + +// Set time display +private _totalDownloadTime = _object getVariable [QGVAR(downloadTime), 0]; +private _timeText = if (_currentProgress isEqualTo MAX_PROGRESS) then { + format [" Download completed in: %1", [_totalDownloadTime] call CBA_fnc_formatElapsedTime] +} else { + private _estimatedTimeLeft = [_totalDownloadTime, _currentProgress] call FUNC(formatEstimatedTimeRemaining); + format [" Estimated time left: %1", _estimatedTimeLeft] +}; + +_terminal set [-1, _timeText]; + +_texture = format ['#(rgb,512,512,3)text(0,0,"EtelkaMonospacePro",0.03,"#1A1818","#00B200","%1")', _terminal joinString "\n"]; +_object setObjectTexture [_textureSelection, _texture]; + +// Finish +if (_currentProgress isEqualTo MAX_PROGRESS) exitWith { + _handle call CBA_fnc_removePerFrameHandler; + + private _terminalFinal = [ + " Wiping...", + " Remove Device!" + ]; + _terminal append _terminalFinal; + _texture = format ['#(rgb,512,512,3)text(0,0,"EtelkaMonospacePro",0.03,"#1A1818","#00B200","%1")', _terminal joinString "\n"]; + _object setObjectTexture [_textureSelection, _texture]; + + [{(_this select 0) getVariable [QGVAR(deviceUnplugged), true]}, { + params ["_object", "_terminal", "_textureSelection"]; + INFO_1("Device unplugged %1",_object); + + private _terminalDeviceUnplugged = [ + "", + " Device unplugged!" + ]; + + _terminal append _terminalDeviceUnplugged; + _texture = format ['#(rgb,512,512,3)text(0,0,"EtelkaMonospacePro",0.03,"#1A1818","#00B200","%1")', _terminal joinString "\n"]; + _object setObjectTexture [_textureSelection, _texture]; + }, [_object, _terminal, _textureSelection]] call CBA_fnc_waitUntilAndExecute; +}; diff --git a/addons/task_download/functions/fnc_formatEstimatedTimeRemaining.sqf b/addons/task_download/functions/fnc_formatEstimatedTimeRemaining.sqf new file mode 100644 index 0000000..302b2b9 --- /dev/null +++ b/addons/task_download/functions/fnc_formatEstimatedTimeRemaining.sqf @@ -0,0 +1,44 @@ +#include "script_component.hpp" +/* + * Author: 3Mydlo3 + * Formats remaining estimated time as a formatted string. + * + * Arguments: + * 0: Total expected time of the download + * 1: Current download progress (Optional, default 0) + * + * Return Value: + * Formatted time + * + * Example: + * [60, 50] call afmf_task_download_fnc_formatEstimatedTimeRemaining + * + * Public: No + */ + +#define RETURN_ARRAY true + +params ["_totalExpectedTime", ["_currentProgress", INITIAL_PROGRESS]]; + +if (_currentProgress isEqualTo INITIAL_PROGRESS) exitWith { "Unknown" }; + +private _timeLeft = _totalExpectedTime - _totalExpectedTime * (_currentProgress/100); + +private _timeLeftArray = [_timeLeft, "HH:MM:SS", RETURN_ARRAY] call BIS_fnc_secondsToString; + +_timeLeftArray params ["_hours", "_minutes", "_seconds"]; +private _expectedRemainingTimeText = if (_hours isEqualTo "00") then { + if (_minutes isEqualTo "00") then { + private _value = [_seconds, "0"] call CBA_fnc_leftTrim; + if (_value isEqualTo "") then { _value = "0" }; + format ["%1 s", _value] + } else { + private _value = [_minutes, "0"] call CBA_fnc_leftTrim; + format ["%1 min", _value] + }; +} else { + private _value = [_hours, "0"] call CBA_fnc_leftTrim; + format ["%1 h", _value] +}; + +_expectedRemainingTimeText diff --git a/addons/task_download/functions/fnc_formatProgress.sqf b/addons/task_download/functions/fnc_formatProgress.sqf new file mode 100644 index 0000000..8cf48a1 --- /dev/null +++ b/addons/task_download/functions/fnc_formatProgress.sqf @@ -0,0 +1,21 @@ +#include "script_component.hpp" +/* + * Author: 3Mydlo3 + * Formats progress number to a string with fixed decimals and % sign. + * + * Arguments: + * 0: Number to format + * + * Return Value: + * Number converted for display to percentage with 2 decimal places + * + * Example: + * [99.999] call afmf_task_download_fnc_formatProgress; + * // Returns "99.99%" + * + * Public: No + */ + +params ["_progress"]; + +format ["%1%2", floor(_progress * 100)/100 toFixed 2, "%"] diff --git a/addons/task_download/functions/fnc_initDownloadAction.sqf b/addons/task_download/functions/fnc_initDownloadAction.sqf new file mode 100644 index 0000000..8f9bb18 --- /dev/null +++ b/addons/task_download/functions/fnc_initDownloadAction.sqf @@ -0,0 +1,51 @@ +#include "script_component.hpp" +/* + * Author: 3Mydlo3 + * Initializes download action on given object. + * Runs clientside. + * + * Arguments: + * 0: Object to assign an action to + * 1: Actual action code + * 2: Condition for showing action + * + * Return Value: + * None + * + * Example: + * None + * + * Public: No + */ + +params ["_object"]; + +if (!hasInterface) exitWith {}; + +private _statement = { + params ["_object"]; + [QGVAR(start), [_object, player]] call CBA_fnc_serverEvent; +}; + +private _showCondition = { + params ["_object"]; + !(_object getVariable [QGVAR(downloadStarted), false]) +}; + +private _action = [ + QGVAR(startDownloadAction), + LLSTRING(StartAction), + "", + _statement, + _showCondition, + {}, [_object], "", 4, [false, false, false, false, false], {} +] call ACEFUNC(interact_menu,createAction); + +[ + _object, + ACTION_TYPE, + ["ACE_MainActions"], + _action +] call ACEFUNC(interact_menu,addActionToObject); + +nil diff --git a/addons/task_download/functions/fnc_initGetDeviceAction.sqf b/addons/task_download/functions/fnc_initGetDeviceAction.sqf new file mode 100644 index 0000000..5e5857a --- /dev/null +++ b/addons/task_download/functions/fnc_initGetDeviceAction.sqf @@ -0,0 +1,52 @@ +#include "script_component.hpp" +/* + * Author: 3Mydlo3 + * Initializes check progress action on given object. + * Runs clientside. + * + * Arguments: + * 0: Object to assign an action to + * 1: Actual action code + * 2: Condition for showing action + * + * Return Value: + * None + * + * Example: + * None + * + * Public: No + */ + +params ["_object"]; + +if (!hasInterface) exitWith {}; + +private _statement = { + params ["_object"]; + [QGVAR(deviceUnplugged), [_object, player]] call CBA_fnc_serverEvent; +}; + +private _showCondition = { + params ["_object"]; + _object getVariable [QGVAR(downloadFinished), false] && + {!(_object getVariable [QGVAR(deviceUnplugged), false])} +}; + +private _action = [ + QGVAR(getDeviceAction), + LLSTRING(GetDeviceAction), + "", + _statement, + _showCondition, + {}, [_object], "", 4, [false, false, false, false, false], {} +] call ACEFUNC(interact_menu,createAction); + +[ + _object, + ACTION_TYPE, + ["ACE_MainActions"], + _action +] call ACEFUNC(interact_menu,addActionToObject); + +nil diff --git a/addons/task_download/functions/fnc_prepareDisplay.sqf b/addons/task_download/functions/fnc_prepareDisplay.sqf new file mode 100644 index 0000000..f328567 --- /dev/null +++ b/addons/task_download/functions/fnc_prepareDisplay.sqf @@ -0,0 +1,76 @@ +#include "script_component.hpp" +/* + * Author: Mike, Jonpas from Theseus Mods; 3Mydlo3 + * Only Laptop, Rugged Laptop & PC Set - Screen are actively supported. + * Has a laptop generate an intel download after an ACE interaction. + * Will update in increments of 10% until 100. Refresh rate of the download is worked out as downloadTime / 10 + * Texture source is shown on the object via Attributes > Object Specific > Texture #X + * Can use getVariable on the laptop to check if download is complete with QGVAR(downloadIntel_complete) + * + * Further adjusted by 3Mydlo3 + * + * Arguments: + * 0: Laptop + * 1: Texture Source + * 2: Filesize + * 3: Download Time + * + * Return Value: + * None + * + * Example: + * + * + * Public: No + */ + +params ["_object", "_textureSelection", "_fileSize", "_downloadTime"]; + +TRACE_4("Prepare display",_object,_textureSelection,_fileSize,_downloadTime); + +private _terminalLogin = " balls login:"; +private _terminalPrepare = [ + [ + format ["%1 Ligma", _terminalLogin], + " Password:", + "" // replaced with next + ], [ + "Welcome back Ligma! Balls waiting.", + " ligma@balls:~$" // replaced with next + ], [ + " ligma@balls:~$ ls", + " arma3 bateleeye free-bpp genocides", + " hypercas mk-xiv music pictures", + " secret special-arma wdzydze", + "", + " ligma@balls:~$" // replaced with next + ], [ + " ligma@balls:~$ ls secret/", + " accounts.xls arsenal embassy.txt", + " furries identities plans", + " renchon_nudes.tar weapons", + " ligma@balls:~$" // replaced with next + ], [ + " ligma@balls:~$ mkdir -p /mnt/usb", + " ligma@balls:~$" // replaced with next + ], [ + " ligma@balls:~$ mount /dev/sdb1 /mnt/usb", + " ligma@balls:~$" // replaced with next + ], [ + " ligma@balls:~$ /mnt/usb/steal.py /home/secret/furries", + " >> --wipe", + "", + " Preparing...", + "", + "" // replaced with next + ], [ + "", // replaced with progress bar + "", + "" // replaced with estimated remaining time + ] +]; + +private _texture = format ['#(rgb,512,512,3)text(0,0,"EtelkaMonospacePro",0.03,"#1A1818","#00B200","%1")', _terminalLogin]; +_object setObjectTexture [_textureSelection, _texture]; + +[FUNC(displayProgressOnScreen), 0.1, [CBA_missionTime, [], _object, _fileSize, _textureSelection, GVAR(displayProgressOnScreenRefreshInterval), _terminalPrepare]] call CBA_fnc_addPerFrameHandler; diff --git a/addons/task_download/functions/fnc_setupSimple.sqf b/addons/task_download/functions/fnc_setupSimple.sqf new file mode 100644 index 0000000..c50d600 --- /dev/null +++ b/addons/task_download/functions/fnc_setupSimple.sqf @@ -0,0 +1,56 @@ +#include "script_component.hpp" +/* + * Author: 3Mydlo3 + * Function sets up given object as a download source. + * This is a simple version that works on a fixed time basis and minimalizes network traffic. + * + * Arguments: + * 0: Object that will have download action added + * 1: Time it will take for the download to finish + * 2: Size of the download + * + * Return Value: + * Set up finished correctly + * + * Example: + * [laptop, 66, 2096] call afmf_task_download_fnc_setupSimple + * + * Public: Yes + */ + +params [ + "_object", + "_downloadTime", + "_downloadSize" +]; + +TRACE_3("Setup simple download",_object,_downloadTime,_downloadSize); + +if (isNil "_downloadTime" || isNil "_downloadSize") exitWith { false }; +if (!([_object] call FUNC(canContinue))) exitWith { false }; + +if (isServer) then { + _object setVariable [QGVAR(initialized), true, true]; + _object setVariable [QGVAR(downloadTime), _downloadTime, true]; + + // For display progress on screen + _object setVariable [QGVAR(downloadStarted), false, true]; + _object setVariable [QGVAR(downloadInProgress), false, true]; + _object setVariable [QGVAR(downloadFinished), false, true]; + _object setVariable [QGVAR(deviceUnplugged), false, true]; + + private _progressPerTick = MAX_PROGRESS / (_downloadTime / PROGRESS_INTERVAL); + _object setVariable [QGVAR(downloadProgressPerTick), _progressPerTick, true]; +}; + +// Create action +if (hasInterface) then { + _object setVariable [QGVAR(downloadIntel_prepareFinished_client), false]; + _object setVariable [QGVAR(downloadIntel_prepareStage_client), 0]; + + [_object] call FUNC(initDownloadAction); + [_object] call FUNC(initGetDeviceAction); + [_object, 0, _downloadSize, _downloadTime] call FUNC(prepareDisplay); +}; + +true diff --git a/addons/task_download/functions/fnc_start.sqf b/addons/task_download/functions/fnc_start.sqf new file mode 100644 index 0000000..39c6e7c --- /dev/null +++ b/addons/task_download/functions/fnc_start.sqf @@ -0,0 +1,51 @@ +#include "script_component.hpp" +/* + * Author: 3Mydlo3 + * Starts the download loop. + * Notifies player who started the download about estimated finish time. + * + * Arguments: + * 0: Object which is used for the download + * + * Return Value: + * None + * + * Example: + * None + * + * Public: No + */ + +#define PREPARATION_TIME 20 + +params ["_object", "_player"]; + +if (!isServer) exitWith {}; + +private _canStart = [_object] call FUNC(canContinue); +if (!_canStart) exitWith {}; + +private _totalDownloadTime = _object getVariable [QGVAR(downloadTime), 0]; +private _downloadStartTime = CBA_missionTime + PREPARATION_DURATION; +private _timeToDownloadEnd = _totalDownloadTime + PREPARATION_DURATION; + +_object setVariable [QGVAR(downloadStarted), true, true]; +_object setVariable [QGVAR(downloadInProgress), true, true]; +_object setVariable [QGVAR(downloadStartTime), _downloadStartTime, true]; + +[{!([_this select 0] call FUNC(canContinue))}, { + // Download interrupted + params ["_object"]; + _object setVariable [QGVAR(downloadInProgress), false, true]; + [QGVAR(failed)] call CBA_fnc_globalEvent; +}, [_object], _timeToDownloadEnd, { + // Download finished + params ["_object"]; + _object setVariable [QGVAR(downloadFinished), true, true]; + _object setVariable [QGVAR(downloadInProgress), false, true]; +}] call CBA_fnc_waitUntilAndExecute; + +// Invoke public event +[QGVAR(started), [_object]] call CBA_fnc_globalEvent; + +nil diff --git a/addons/task_download/functions/script_component.hpp b/addons/task_download/functions/script_component.hpp new file mode 100644 index 0000000..fcf9da9 --- /dev/null +++ b/addons/task_download/functions/script_component.hpp @@ -0,0 +1 @@ +#include "..\script_component.hpp" diff --git a/addons/task_download/script_component.hpp b/addons/task_download/script_component.hpp new file mode 100644 index 0000000..769bfb6 --- /dev/null +++ b/addons/task_download/script_component.hpp @@ -0,0 +1,22 @@ +#define COMPONENT task_download +#include "\z\afmf\addons\main\script_mod.hpp" + +// #define DEBUG_MODE_FULL +// #define DISABLE_COMPILE_CACHE + +#ifdef DEBUG_ENABLED_TASK_DOWNLOAD + #define DEBUG_MODE_FULL +#endif + #ifdef DEBUG_SETTINGS_TASK_DOWNLOAD + #define DEBUG_SETTINGS DEBUG_SETTINGS_TASK_DOWNLOAD +#endif + +#include "\z\afmf\addons\main\script_macros.hpp" + +#define INITIAL_PROGRESS 0 +#define MAX_PROGRESS 100 +#define PREPARATION_INTERVAL 3 +#define PREPARATION_STAGES 8 +#define PREPARATION_DURATION PREPARATION_INTERVAL * PREPARATION_STAGES +#define PROGRESS_INTERVAL 1 +#define ACTION_TYPE 0 diff --git a/addons/task_download/stringtable.xml b/addons/task_download/stringtable.xml new file mode 100644 index 0000000..b2891f0 --- /dev/null +++ b/addons/task_download/stringtable.xml @@ -0,0 +1,21 @@ + + + + + Task Download + Zadanie pobierania + + + Failed downloading data. Remote host lost. + Pobieranie danych nieudane. Utracono połączenie z hostem. + + + Unplug device + Odepnij nośnik + + + Start download + Rozpocznij pobieranie + + +