aeroson

Untitled

Apr 28th, 2013
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.13 KB | None | 0 0
  1.  
  2. /* FHQ TaskTracker for the FHQ Multiplayer framework
  3. *
  4. * This scriptset is used to create briefings and tasks, and keep track of
  5. * task states.
  6. *
  7. * In general, briefings and tasks can be created for individual players, for
  8. * groups of players, and specific to the side or faction of the player.
  9. *
  10. * Unit filters:
  11. * Whenever a unit filter is asked for, there are several possibilities to
  12. * define what you need to assign to:
  13. * single object: A single player
  14. * group: All players of a group
  15. * side: All players of a side
  16. * faction (string): All players of a certain faction
  17. * code: The piece of code is called for every playable character. Return true if you want
  18. * the character to be selected, or false otherwise. The only parameter is the playable
  19. * object to be tested
  20. *
  21. * When calling a function that assigns briefings or tasks, a pool of all playable units is created.
  22. * The filter is tested against those units, and all units matching the filter will have the tasks/briefing
  23. * assigned to them. Subsequently, these units (that mached the filter) are removed from the pool. Further
  24. * filtering is done on the remaining units.
  25. *
  26. * This essentially means that you should define tasks/briefing entries from specific to general. For example,
  27. * assuming one player group is west (whith special tasks), and the rest of the players share another set of tasks,
  28. * you would first use the specific group as filter value, followed by west to assign the following tasks to all
  29. * remaining west players.
  30. *
  31. * Examples:
  32. * {(side _this) != west): All playable characters that are not BLUFOR
  33. * player: the player on the current client
  34. * group westMan1_1: All units in westMan1_1's group
  35. * east: All playable characters on the OPFOR side
  36. * "BIS_BAF": All playable british soliders
  37. *
  38. *
  39. * Briefing entries:
  40. * Briefing entries are defined as an array of two strings. The first string is the title as it
  41. * will appear in the middle colum when the "Notes" section is highlighted in the left colum.
  42. * The second string is a text that can contains links to markers, code, and some html formatting
  43. * and will be displayed on the right column when the title in the center column is highlited.
  44. *
  45. *
  46. * Task entries:
  47. * A single task entry is an array. The elements in the array are as follows:
  48. * String: task name
  49. * String: Task text (the text that will appear in the right colum)
  50. * String: Task title (it will appear in the center column when "Tasks" is highlited in the left column).
  51. * String: optional Waypoint title (Will appear on the waypoint marker in the player's main view).
  52. * Object or position: The destination for this task, either an object, or a position.
  53. * String: Optional initial state ("created" if nothing given)
  54. *
  55. *
  56. * Commonly used examples:
  57. *
  58. * 1. Assign a task as current task:
  59. * ["taskDestroy", "assigned"] call FHQ_TT_setTaskState;
  60. *
  61. *
  62. * 2. Check if a task is completed (Note, might be successful, failed or cancelled)
  63. * if (["taskInsert"] call FHQ_TT_isTaskCompleted) then {hint "yes";};
  64. *
  65. *
  66. * 3. Check if a task is successful
  67. * if (["taskDestroy"] call FHQ_TT_isTaskSuccessful) then {hint "yay";};
  68. *
  69. *
  70. * 4. Mark a task and select another task that is not completed yet.
  71. * ["taskDestroySecondary", "succeeded", "taskDestroyPrimary", "taskDestroySecondary", "taskExfiltrate"]
  72. * call FHQ_TT_markTaskAndNext;
  73. *
  74. * This example marks taskDestroySecondary as succesful, and then checks if taskDestroyPrimary is completed.
  75. * If not, it is set to assigned. If it is completed, it continues with the taskDestroySecondary and eventually
  76. * taskExfiltrate.
  77. *
  78. *
  79. *
  80. *
  81. * TODO: Add possibility to change waypoint position
  82. */
  83.  
  84. FHQ_TT_init =
  85. {
  86. FHQ_TT_supressTaskHints = true;
  87.  
  88. /* Check for Arma 3 or 2 */
  89. FHQ_TT_is_arma3 = false;
  90.  
  91. if (isClass (configfile >> "CfgAddons" >> "PreloadAddons" >> "A3")) then {
  92. FHQ_TT_is_arma3 = true;
  93. };
  94.  
  95. if (isServer) then
  96. {
  97. // Global list of tasks kept on the server. Always contains full info:
  98. // [unit filter, description, state]
  99. FHQ_TT_TaskList = [];
  100. };
  101.  
  102. if (!isDedicated) then
  103. {
  104. // Local version of the client
  105. // I wonder, though, why this is necessary, since according to the documentation,
  106. // the effects of createSimpleTask are global
  107. // Anyway, [name, state, list of objects]
  108. FHQ_TT_ClientTaskList = [];
  109.  
  110. if (isNil {player} || isNull player) then
  111. {
  112. FHQ_TT_isJIPPlayer = true;
  113. };
  114.  
  115. [] spawn
  116. {
  117. // Wait for join in progress
  118. waitUntil {!isNil {player}};
  119. waitUntil {!isNull player};
  120.  
  121. // Wait until the task list is ready.
  122. waitUntil {!isNil "FHQ_TT_initialized"};
  123. FHQ_TT_TaskList call FHQ_TT_UpdateTaskList;
  124. FHQ_TT_supressTaskHints = false;
  125. "FHQ_TT_TaskList" addPublicVariableEventHandler {(_this select 1) call FHQ_TT_UpdateTaskList};
  126. };
  127. };
  128. };
  129.  
  130.  
  131. FHQ_TT_filterUnits =
  132. {
  133. private ["_unitsArray", "_inputArray", "_outputArray"];
  134.  
  135. _unitsArray = _this select 1;
  136. _inputArray = _this select 0;
  137. _outputArray = [];
  138.  
  139. switch (typename _inputArray) do
  140. {
  141. case "CODE":
  142. {
  143. // Filter all playable units by comparing them with the code
  144. {if (_x call _inputArray) then {_outputArray = _outputArray + [_x];};} forEach _unitsArray;
  145. };
  146. case "GROUP":
  147. {
  148. // Filter out all objects not in group
  149. {if (_x in units _inputArray) then {_outputArray = _outputArray + [_x];};} forEach _unitsArray;
  150. };
  151. case "OBJECT":
  152. {
  153. // Result is only the array containing the object
  154. _outputArray = [_inputArray];
  155. };
  156. case "SIDE":
  157. {
  158. // Filter out all objects not belonging to side
  159. {if (side _x == _inputArray) then {_outputArray = _outputArray + [_x];};} forEach _unitsArray;
  160. };
  161. case "STRING":
  162. {
  163. // Filer out all objects not belonging to the faction
  164. {if (faction _x == _inputArray) then {_outputArray = _outputArray + [_x];};} forEach _unitsArray;
  165. };
  166. };
  167.  
  168. _outputArray;
  169. };
  170.  
  171. /* FHQ_TT_addBriefingEntry: Add a briefing entry for the given entities
  172. *
  173. * This function adds a briefing entry for the given units. The units can be
  174. * supplied as either a player, a group, a side, a faction, or a piece of code.
  175. * All playable units will receive the given entries if they match the condition.
  176. *
  177. * [_units, _topic, _text] call FHQ_TT_addBriefingEntry;
  178. * [_units, _subject, _topic, _text] call FHQ_TT_addBriefingEntry; (NOT YET IMPLEMENTED)
  179. *
  180. * Parameters:
  181. * _units: A single unit, a group, side faction, or piece of code that will
  182. * be run on all playable units.
  183. * _topic: topic to add to
  184. * _text: text for this subject
  185. * _subject: Subject to file this under. A new subject is created if it does not exist yet.
  186. * (optional, not yet implemented)
  187. *
  188. */
  189.  
  190. FHQ_TT_addBriefingEntry =
  191. {
  192. private ["_units", "_subject", "_topic", "_text", "_unitsArray", "_unitPool"];
  193.  
  194. _units = _this select 0;
  195. _subject = "Diary";
  196. _topic = _this select 1;
  197. _text = _this select 2;
  198. _unitPool = (if (isMultiplayer) then {playableUnits} else {switchableUnits});
  199.  
  200. _unitsArray = [_units, _unitPool] call FHQ_TT_filterUnits;
  201.  
  202. {_x createDiaryRecord [_subject, [_topic, _text]]} forEach _unitsArray;
  203. };
  204.  
  205.  
  206. /* Internally used to add topics to units in reversed order */
  207. FHQ_TT_addBriefingEntries =
  208. {
  209. private ["_units", "_subject", "_topics", "_count", "_i", "_topic", "_text"];
  210.  
  211. _units = _this select 0;
  212. _subject = "Diary";
  213. _topics = _this select 1;
  214.  
  215. _count = count _topics;
  216. if (_count > 0) then
  217. {
  218. for [ {_i = _count - 1}, {_i >= 0}, {_i = _i - 1}] do
  219. {
  220. _topic = (_topics select _i) select 0;
  221. _text = (_topics select _i) select 1;
  222. {_x createDiaryRecord [_subject, [_topic, _text]]} forEach _units;
  223. };
  224. };
  225. };
  226.  
  227. /* FHQ_TT_addBriefing: Add a full briefing to the selected units.
  228. *
  229. * This functions receives an array as input. The elements of the input array
  230. * are interpreted as follows:
  231. * If the element is a two-element array consisting of two strings, the entry is
  232. * interpreted as a new briefing topic.
  233. * If the element is anything else, the following topics will only be presented to
  234. * the units matching the element. For example, if the element is a group, the following
  235. * entries are added to this group only.
  236. * If a new unit match is encountered, the units that have been assigned targets before
  237. * will be removed from the pool of units being considered for future topics.
  238. *
  239. * In other words, you can define briefings from bottom up. If you first define briefing topics
  240. * for a group of players, and then for a side, the side specific topics will not be added to the
  241. * group. This is meant to enable you to go from specific units up to general.
  242. *
  243. * In normal circumstances, you will most likely only define one briefing for a single group of
  244. * players, and thus passing only an array of string pairs.
  245. */
  246.  
  247. FHQ_TT_addBriefing =
  248. {
  249. private ["_unitPool", "_numEntries", "_currentUnits", "_currentTopicList", "_current"];
  250. _unitPool = (if (isMultiplayer) then {playableUnits} else {switchableUnits});
  251. _numEntries = count _this;
  252. _currentUnits = _unitPool;
  253. _currentTopicList = [];
  254.  
  255. for "_i" from 0 to (_numEntries - 1) do
  256. {
  257. _current = _this select _i;
  258.  
  259.  
  260. if (typename _current == "ARRAY") then
  261. {
  262. // Parameter is an entry for the briefing, apply it to the _currentUnits pool
  263. // {_x createDiaryRecord ["Diary", [_current select 0, _current select 1]];} forEach _currentUnits;
  264. _currentTopicList = _currentTopicList + [[_current select 0, _current select 1]];
  265. }
  266. else
  267. {
  268. // Parameter is a filter for the units. Remove the _currentUnits from the pool and select
  269. // units according to the filter. Note: not removing anything on _i = 0
  270. if (_i != 0) then
  271. {
  272. _unitPool = _unitPool - _currentUnits;
  273. };
  274.  
  275. if (count _currentTopicList > 0) then
  276. {
  277. [_currentUnits, _currentTopicList] call FHQ_TT_addBriefingEntries;
  278. _currentTopicList = [];
  279. };
  280.  
  281. _currentUnits = [_current, _unitPool] call FHQ_TT_filterUnits;
  282. };
  283. };
  284.  
  285. // Add any leftovers
  286. if (count _currentTopicList > 0) then
  287. {
  288. [_currentUnits, _currentTopicList] call FHQ_TT_addBriefingEntries;
  289. _currentTopicList = [];
  290. };
  291. };
  292.  
  293.  
  294. /* FHQ_TT_getTaskName
  295. * Internal
  296. */
  297.  
  298. FHQ_TT_getTaskName =
  299. {
  300. private ["_task", "_name"];
  301.  
  302. _task = (_this select 0) select 0;
  303. if (typename _task == "ARRAY") then
  304. {
  305. _name = _task select 0;
  306. }
  307. else
  308. {
  309. _name = _task;
  310. };
  311.  
  312. _name;
  313. };
  314.  
  315. /* FHQ_TT_createSimpleTask:
  316. *
  317. * Internal
  318. */
  319. FHQ_TT_createSimpleTask =
  320. {
  321. private ["_currentUnits", "_currentTask", "_currentTaskState", "_taskObjects", "_taskName"];
  322. _currentUnits = _this select 0;
  323. _currentTask = _this select 1; // [name|[name,parent], text, title, waypoint, object/position]
  324. _currentTaskState = _this select 2;
  325. _taskObjects = [];
  326.  
  327. {
  328. private "_task";
  329. if (typename (_currentTask select 0) == "ARRAY") then
  330. {
  331. private ["_parentTask"];
  332.  
  333. _taskName = (_currentTask select 0) select 0;
  334. _parentTask = (_currentTask select 0) select 1;
  335. _task = _x createSimpleTask [_taskName, _x getVariable format["FHQ_TT_taskname_%1", _parentTask]];
  336. }
  337. else
  338. {
  339. _taskName = _currentTask select 0;
  340. _task = _x createSimpleTask [_currentTask select 0];
  341. };
  342.  
  343. _task setSimpleTaskDescription [_currentTask select 1, _currentTask select 2, _currentTask select 3];
  344.  
  345. if (count _currentTask > 4) then
  346. {
  347. switch (typename (_currentTask select 4)) do
  348. {
  349. case "ARRAY":
  350. {
  351. _task setSimpleTaskDestination (_currentTask select 4);
  352. };
  353. case "OBJECT":
  354. {
  355. _task setSimpleTaskTarget [_currentTask select 4, true];
  356. };
  357. };
  358. };
  359.  
  360. _task setTaskState _currentTaskState;
  361. if (tolower(_currentTaskState) == "assigned") then
  362. {
  363. _x setCurrentTask _task;
  364. };
  365.  
  366. _x setVariable [format["FHQ_TT_taskname_%1", _taskName], _task, true];
  367.  
  368. _taskObjects = _taskObjects + [_task];
  369. } forEach _currentUnits;
  370.  
  371. _taskObjects;
  372. };
  373.  
  374. /* Internal */
  375. FHQ_TT_addTaskEntries =
  376. {
  377. private ["_currentUnits", "_tasks", "_count", "_i", "_current", "_state"];
  378. _currentUnits = _this select 0;
  379. _tasks = _this select 1;
  380. _count = count _tasks;
  381.  
  382. if (_count > 0) then
  383. {
  384. if (FHQ_TT_is_arma3) then
  385. {
  386. for [ {_i = 0}, {_i < _count}, {_i = _i + 1}] do
  387. {
  388. _current = _tasks select _i;
  389. _state = "created";
  390.  
  391. // Optional state
  392. if (count _current >= 6) then
  393. {
  394. _state = _current select 5;
  395. };
  396.  
  397. // fifth element is either an object/position, or a string. In the latter case,
  398. // object/position was ommited but initial state given
  399. if (count _current >= 5) then
  400. {
  401. if (typename (_current select 4) == "STRING") then
  402. {
  403. _state = _current select 4;
  404. };
  405. };
  406.  
  407. FHQ_TT_TaskList = FHQ_TT_TaskList + [[_currentUnits, _current, _state]];
  408. };
  409. }
  410. else
  411. {
  412. for [ {_i = _count - 1}, {_i >= 0}, {_i = _i - 1}] do
  413. {
  414. _current = _tasks select _i;
  415. _state = "created";
  416.  
  417. // Optional state
  418. if (count _current >= 6) then
  419. {
  420. _state = _current select 5;
  421. };
  422.  
  423. // fifth element is either an object/position, or a string. In the latter case,
  424. // object/position was ommited but initial state given
  425. if (count _current >= 5) then
  426. {
  427. if (typename (_current select 4) == "STRING") then
  428. {
  429. _state = _current select 4;
  430. };
  431. };
  432.  
  433. FHQ_TT_TaskList = FHQ_TT_TaskList + [[_currentUnits, _current, _state]];
  434. };
  435. }
  436. };
  437. };
  438.  
  439. /* FHQ_TT_addTasks: Add tasks to the mission
  440. *
  441. * write me
  442. *
  443. */
  444. FHQ_TT_addTasks =
  445. {
  446. private ["_numEntries", "_unitPool", "_currentUnits", "_currentTaskList", "_current"];
  447.  
  448. if (!isServer) exitWith {};
  449.  
  450. _numEntries = count _this;
  451. if (_numEntries <= 0) exitWith {};
  452.  
  453. //_unitPool = (if (isMultiplayer) then {playableUnits} else {switchableUnits});
  454. //_currentUnits = _unitPool;
  455. _currentTaskList = [];
  456.  
  457. for "_i" from 0 to (_numEntries - 1) do
  458. {
  459. _current = _this select _i;
  460.  
  461. if (typename _current == "ARRAY") then
  462. {
  463. _currentTaskList = _currentTaskList + [_current];
  464. }
  465. else
  466. {
  467. // Parameter is a filter for the units.
  468. if (_i != 0) then
  469. {
  470. //_unitPool = _unitPool - _currentUnits;
  471. };
  472.  
  473. if (count _currentTaskList > 0) then
  474. {
  475. [_currentUnits, _currentTaskList] call FHQ_TT_addTaskEntries;
  476. _currentTaskList = [];
  477. };
  478.  
  479. //_currentUnits = [_current, _unitPool] call FHQ_TT_filterUnits;
  480. _currentUnits = _current;
  481. };
  482. };
  483.  
  484. if (count _currentTaskList > 0) then
  485. {
  486. [_currentUnits, _currentTaskList] call FHQ_TT_addTaskEntries;
  487. };
  488.  
  489. // Send task list to clients
  490. publicVariable "FHQ_TT_TaskList";
  491. if (!isDedicated) then
  492. {
  493. FHQ_TT_TaskList call FHQ_TT_UpdateTaskList;
  494. };
  495.  
  496. FHQ_TT_initialized = true;
  497. publicVariable "FHQ_TT_initialized";
  498.  
  499. };
  500.  
  501. FHQ_TT_hasTask =
  502. {
  503. private "_result";
  504.  
  505. _result = false;
  506.  
  507. {
  508. if ((_x call FHQ_TT_getTaskName) == _this) exitWith {_result = true;};
  509. } forEach FHQ_TT_ClientTaskList;
  510.  
  511. _result;
  512. };
  513.  
  514.  
  515. FHQ_TT_taskHint =
  516. {
  517. if (!FHQ_TT_is_arma3) then
  518. {
  519. /* Arma 2 */
  520. private ["_desc", "_state", "_color", "_icon", "_text"];
  521.  
  522. _desc = _this select 0;
  523. _state = _this select 1;
  524.  
  525. _color = [1, 1, 1, 1];
  526. _icon = "taskNew";
  527. _text = "New Task";
  528.  
  529. switch (tolower(_state)) do
  530. {
  531. case "created":
  532. {
  533. _color = [1, 1, 1, 1];
  534. _icon = "taskNew";
  535. _text = localize "str_taskNew";
  536. };
  537. case "assigned":
  538. {
  539. _color = [1, 1, 1, 1];
  540. _icon = "taskCurrent";
  541. _text = localize "str_taskSetCurrent";
  542. };
  543. case "succeeded":
  544. {
  545. _color = [0.600000,0.839215,0.466666,1];
  546. _icon = "taskDone";
  547. _text = localize "str_taskAccomplished";
  548. };
  549. case "canceled":
  550. {
  551. _color = [0.75,0.75,0.75,1];
  552. _icon = "taskFailed";
  553. _text = localize "str_taskCancelled";
  554. };
  555. case "cancelled":
  556. {
  557. _color = [0.75,0.75,0.75,1];
  558. _icon = "taskFailed";
  559. _text = localize "str_taskCancelled";
  560. };
  561. case "failed":
  562. {
  563. _color = [0.972549,0.121568,0,1];
  564. _icon = "taskFailed";
  565. _text = localize "str_taskFailed";
  566. };
  567. };
  568.  
  569. taskHint [format ["%1\n%2", _text, _desc], _color, _icon];
  570. }
  571. else
  572. {
  573. /* Arma 3 */
  574. private ["_notifyTemplate", "_desc", "_state"];
  575.  
  576. _desc = _this select 0;
  577. _state = _this select 1;
  578.  
  579. switch (tolower _state) do
  580. {
  581. case "created":
  582. {
  583. _notifyTemplate = "TaskCreated";
  584. };
  585. case "assigned":
  586. {
  587. _notifyTemplate = "TaskAssigned";
  588. };
  589. case "succeeded":
  590. {
  591. _notifyTemplate = "TaskSucceeded";
  592. };
  593. case "canceled":
  594. {
  595. _notifyTemplate = "TaskCanceled";
  596. };
  597. case "cancelled":
  598. {
  599. _notifyTemplate = "TaskCanceled";
  600. };
  601. case "failed":
  602. {
  603. _notifyTemplate = "TaskFailed";
  604. };
  605. };
  606.  
  607. [_notifyTemplate, ["", _desc]] call BIS_fnc_showNotification;
  608. };
  609. };
  610.  
  611.  
  612. FHQ_TT_UpdateTaskList =
  613. {
  614. if (isDedicated) exitWith {};
  615.  
  616. private ["_count", "_i", "_tasks"];
  617. _tasks = _this;
  618. _count = count _tasks;
  619.  
  620. _unitPool = (if (isMultiplayer) then {playableUnits} else {switchableUnits});
  621.  
  622. if (_count > 0) then
  623. {
  624. for [ {_i = 0}, {_i < _count}, {_i = _i + 1}] do
  625. {
  626. private ["_current", "_currentUnits", "_taskObjects", "_currentTask",
  627. "_currentTaskState", "_currentTaskName", "_currentTaskParent"];
  628. _current = _tasks select _i; // [units, taskDesc, state]
  629. _currentTask = _current select 1; // [name|[name,parent], text, title, waypoint, object/position]
  630. _currentUnits = _current select 0;
  631. _currentTaskState = _current select 2;
  632. _currentTaskName = "";
  633. _currentTaskParent = "";
  634.  
  635. _currentUnits = [_currentUnits, _unitPool] call FHQ_TT_filterUnits;
  636. _unitPool = _unitPool - _currentUnits;
  637.  
  638. if (typename (_currentTask select 0) == "ARRAY") then
  639. {
  640. _currentTaskName = (_currentTask select 0) select 0;
  641. _currentTaskParent = (_currentTask select 0) select 1;
  642. }
  643. else
  644. {
  645. _currentTaskName = _currentTask select 0;
  646. };
  647.  
  648. if (_currentTaskName call FHQ_TT_hasTask) then
  649. {
  650. private ["_localTask", "_x", "_task"];
  651.  
  652. _localTask = FHQ_TT_ClientTaskList select _i; // [name, state, objects]
  653. diag_log format["_localTask -> %1, _curent -> %2", _localTask select 1, _current select 2];
  654. if ((_current select 2) != (_localTask select 1)) then
  655. {
  656. // Update the task
  657. _localTask set [1, _current select 2];
  658. FHQ_TT_ClientTaskList set [_i, _localTask];
  659.  
  660. if (player in (_currentUnits)) then
  661. {
  662. [_currentTask select 2, _current select 2] call FHQ_TT_taskHint;
  663. };
  664.  
  665. {
  666. _task = _x;
  667. if (_current select 2 == "assigned") then
  668. {
  669. {
  670. if (_task in (simpletasks _x)) then
  671. {
  672. _x setCurrentTask _task;
  673. };
  674. } forEach _currentUnits;
  675. };
  676. _task setTaskState (_current select 2);
  677. } forEach (_localTask select 2);
  678. };
  679. }
  680. else
  681. {
  682. _taskObjects = [_currentUnits, _currentTask, _currentTaskState] call FHQ_TT_createSimpleTask;
  683. FHQ_TT_ClientTaskList set [_i, [(_current select 1), _currentTaskState, _taskObjects]];
  684. if (player in (_currentUnits) && !FHQ_TT_supressTaskHints) then
  685. {
  686. [_currentTask select 2, _currentTaskState] call FHQ_TT_taskHint;
  687. };
  688.  
  689. };
  690. };
  691. };
  692. };
  693.  
  694. /* FHQ_TT_setTaskState: Set state of a specific task
  695. *
  696. * write me
  697. *
  698. * [_taskName, _state] call FHQ_TT_setTaskState;
  699. */
  700.  
  701. FHQ_TT_setTaskState =
  702. {
  703. if (!isServer) exitWith {};
  704.  
  705. private ["_count", "_taskName", "_newState", "_i", "_curTask"];
  706.  
  707. _count = count FHQ_TT_TaskList;
  708. _taskName = _this select 0;
  709. _newState = _this select 1;
  710.  
  711. for [ {_i = 0}, {_i < _count}, {_i = _i + 1}] do
  712. {
  713. _curTask = FHQ_TT_TaskList select _i;
  714. diag_log format["_curTask = %1", _curTask];
  715.  
  716. //if (_taskName == ((_curTask select 1) select 0)) exitWith
  717. if (_taskName == ([_curTask select 1] call FHQ_TT_getTaskName)) exitWith
  718. {
  719. _curTask set [2, _newState];
  720. FHQ_TT_TaskList set [_i, _curTask];
  721. };
  722. };
  723.  
  724. publicVariable "FHQ_TT_TaskList";
  725. if (!isDedicated) then
  726. {
  727. FHQ_TT_TaskList call FHQ_TT_UpdateTaskList;
  728. };
  729. };
  730.  
  731.  
  732. /* FHQ_TT_getTaskState: Get state of a specific task
  733. *
  734. * write me
  735. *
  736. * _result = [_taskName] call FHQ_TT_getTaskState;
  737. */
  738. FHQ_TT_getTaskState =
  739. {
  740. private ["_result", "_taskName"];
  741.  
  742. _result = "";
  743. _taskName = _this select 0;
  744.  
  745. {
  746. // if (((_x select 1) select 0) == _taskname) exitWith
  747. if (([_x select 1] call FHQ_TT_getTaskName) == _taskname) exitWith
  748. {
  749. _result = (_x select 2);
  750. };
  751. } forEach FHQ_TT_TaskList;
  752.  
  753. _result;
  754. };
  755.  
  756. /* FHQ_TT_isTaskCompleted: Check whether a task is canceled, successful or failed
  757. *
  758. * _result = [_taskName] call FHQ_TT_isTaskCompleted;
  759. */
  760. FHQ_TT_isTaskCompleted =
  761. {
  762. private "_result";
  763.  
  764. _result = (tolower(_this call FHQ_TT_getTaskState) in ["succeeded", "canceled", "failed"]);
  765.  
  766. _result;
  767. };
  768.  
  769. /* FHQ_TT_areTasksCompleted: Check for all tasks given whether they are cancelled, successful, or failed
  770. * _result = [_taskName1, _taskName2, ...] call FHQ_TT_areTasksCompleted
  771. */
  772. FHQ_TT_areTasksCompleted =
  773. {
  774. private ["_result", "_x"];
  775.  
  776. _result = true;
  777.  
  778. {
  779. if (!(tolower ([_x] call FHQ_TT_getTaskState) in ["succeeded", "canceled", "failed"])) exitWith
  780. {
  781. _result = false;
  782. };
  783. } forEach _this;
  784.  
  785. _result;
  786. };
  787.  
  788. /* FHQ_TT_isTaskSuccessful: Check whether a task is ended successfully
  789. *
  790. * _result = [_taskName] call FHQ_TT_isTaskSuccessful;
  791. */
  792. FHQ_TT_isTaskSuccessful =
  793. {
  794. private "_result";
  795.  
  796. _result = (tolower(_this call FHQ_TT_getTaskState) == "succeeded");
  797.  
  798. _result;
  799. };
  800.  
  801. /* FHQ_TT_areTasksSuccessful: Check success for all tasks given
  802. * _result = [_taskName1, _taskName2, ...] call FHQ_TT_areTasksSuccessful
  803. */
  804. FHQ_TT_areTasksSuccessful =
  805. {
  806. private ["_result", "_x"];
  807.  
  808. _result = true;
  809.  
  810. {
  811. if (tolower ([_x] call FHQ_TT_getTaskState) != "succeeded") exitWith
  812. {
  813. _result = false;
  814. };
  815. } forEach _this;
  816.  
  817. _result;
  818. };
  819.  
  820.  
  821. /* FHQ_TT_getAllTasksWithState: Get all tasks with a given state
  822. *
  823. * _taskList = [_state] call FHQ_TT_getAllTasksWithState;
  824. */
  825. FHQ_TT_getAllTasksWithState =
  826. {
  827. private ["_result", "_taskState"];
  828.  
  829. _result = [];
  830. _taskState = _this select 0;
  831.  
  832. {
  833. if ((_x select 2) == _taskState) then
  834. {
  835. _result = _result + [(_x select 1) select 0];
  836. };
  837. } forEach FHQ_TT_TaskList;
  838.  
  839. _result;
  840. };
  841.  
  842. /* FHQ_TT_markTaskAndNext: Mark a task as completed, and look for the next
  843. * open task.
  844. *
  845. * ["taskName", "state", ("newTask1", "newTask2" ... )] call FHQ_TT_markTaskAndNext;
  846. */
  847. FHQ_TT_markTaskAndNext =
  848. {
  849. private "_i";
  850. [_this select 0, _this select 1] call FHQ_TT_setTaskState;
  851.  
  852. for [ {_i = 2}, {_i < count _this}, {_i = _i + 1} ] do
  853. {
  854. if (!([_this select _i] call FHQ_TT_isTaskCompleted)) exitWith
  855. {
  856. [_this select _i, "assigned"] call FHQ_TT_setTaskState;
  857. };
  858. };
  859.  
  860. };
  861.  
  862. /* ------------ End of file, calling init ------------ */
  863. call FHQ_TT_init;
Advertisement
Add Comment
Please, Sign In to add comment