2015-01-11 16:42:31 +00:00
|
|
|
/*
|
|
|
|
* Author: commy2
|
|
|
|
*
|
|
|
|
* Set the captivity status of an unit. This allows the handling of more than one reason to set a unit captive.
|
|
|
|
*
|
|
|
|
* Argument:
|
|
|
|
* 0: Unit (Object)
|
|
|
|
* 1: The reason of the captivity (String)
|
|
|
|
* 2: Is the reason still valid? True for setting this reason, false for removing it (Bool)
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
* None.
|
|
|
|
*/
|
2015-01-13 19:56:02 +00:00
|
|
|
#include "script_component.hpp"
|
2015-01-11 16:42:31 +00:00
|
|
|
|
|
|
|
private ["_unit", "_reason", "_status", "_captivityReasons", "_unitCaptivityReasons", "_captivityReasonsBooleans", "_bitmask"];
|
|
|
|
|
|
|
|
_unit = _this select 0;
|
|
|
|
_reason = _this select 1;
|
|
|
|
_status = _this select 2;
|
|
|
|
|
2015-01-12 04:02:33 +00:00
|
|
|
_captivityReasons = missionNamespace getVariable ["ACE_captivityReasons", []];
|
2015-01-11 16:42:31 +00:00
|
|
|
|
|
|
|
// register new reason (these reasons are shared publicly, since units can change ownership, but keep their captivity status)
|
|
|
|
if !(_reason in _captivityReasons) then {
|
|
|
|
_captivityReasons pushBack _reason;
|
|
|
|
|
2015-01-12 04:02:33 +00:00
|
|
|
ACE_captivityReasons = _captivityReasons;
|
|
|
|
publicVariable "ACE_captivityReasons";
|
2015-01-11 16:42:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// get reasons why the unit is captive already and update to the new status
|
2015-01-11 18:20:14 +00:00
|
|
|
_unitCaptivityReasons = [_unit] call FUNC(getCaptivityStatus);
|
2015-01-11 16:42:31 +00:00
|
|
|
|
|
|
|
_captivityReasonsBooleans = [];
|
|
|
|
{
|
|
|
|
_captivityReasonsBooleans set [_forEachIndex, (_captivityReasons select _forEachIndex) in _unitCaptivityReasons];
|
|
|
|
} forEach _captivityReasons;
|
|
|
|
|
|
|
|
_captivityReasonsBooleans set [_captivityReasons find _reason, _status];
|
|
|
|
|
2015-01-11 18:20:14 +00:00
|
|
|
_bitmask = _captivityReasonsBooleans call FUNC(toBitmask);
|
2015-01-11 16:42:31 +00:00
|
|
|
|
|
|
|
// actually apply the setCaptive command globaly
|
2015-01-11 18:20:14 +00:00
|
|
|
[[_unit, _bitmask], "{(_this select 0) setCaptive (_this select 1)}", _unit] call FUNC(execRemoteFnc);
|