Separate spectator physical and virtual states

With the changes planned to allow spectator in the true death state, physical changes aren't applicable in all of the possible usage cases. This separates the physical process into new function ace_spectator_fnc_stageSpectator
This commit is contained in:
SilentSpike 2015-08-01 18:10:11 +01:00
parent 777d8f6d43
commit 612aa2d679
3 changed files with 77 additions and 41 deletions

View File

@ -16,6 +16,7 @@ PREP(handleUnits);
PREP(moduleSpectatorSettings);
PREP(setCameraAttributes);
PREP(setSpectator);
PREP(stageSpectator);
PREP(transitionCamera);
PREP(toggleInterface);
PREP(updateCameraModes);

View File

@ -1,10 +1,14 @@
/*
* Author: SilentSpike
* Sets target unit to the given spectator state
* Sets target unit to the given spectator state (virtually)
* To physically handle a spectator see ace_spectator_fnc_stageSpectator
*
* Units will be able to communicate in ACRE/TFAR as appropriate
* The spectator interface will be opened/closed
*
* Arguments:
* 0: Unit to put into spectator state <OBJECT>
* 1: New spectator state <BOOL> <OPTIONAL>
* 1: Spectator state <BOOL> <OPTIONAL>
*
* Return Value:
* None <NIL>
@ -17,10 +21,7 @@
#include "script_component.hpp"
params ["_unit",["_set",true,[true]],["_target",objNull,[objNull]]];
// No change, no service (but allow spectators who respawn to be reset)
if !(_set || (_unit getVariable [QGVAR(isSpectator), false])) exitWith {};
params ["_unit", ["_set",true,[true]]];
// Only run for player units
if !(isPlayer _unit) exitWith {};
@ -29,49 +30,15 @@ if !(local _unit) exitwith {
[[_unit, _set, _target], QFUNC(setSpectator), _unit] call EFUNC(common,execRemoteFnc);
};
// Prevent player falling into water
_unit enableSimulation !_set;
// Move to/from group as appropriate
[_unit, _set, QGVAR(isSpectator), side group _unit] call EFUNC(common,switchToGroupSide);
if (_set) then {
// Move and hide the player ASAP to avoid being seen
_unit setPos (getMarkerPos QGVAR(respawn));
// Ghosts can't talk
[_unit, QGVAR(isSpectator)] call EFUNC(common,hideUnit);
[_unit, QGVAR(isSpectator)] call EFUNC(common,muteUnit);
["open"] call FUNC(handleInterface);
} else {
["close"] call FUNC(handleInterface);
// Physical beings can talk
[_unit, QGVAR(isSpectator)] call EFUNC(common,unhideUnit);
[_unit, QGVAR(isSpectator)] call EFUNC(common,unmuteUnit);
private "_marker";
_marker = ["respawn_west","respawn_east","respawn_guerrila","respawn_civilian"] select ([west,east,resistance,civilian] find (side group _unit));
_unit setPos (getMarkerPos _marker);
};
// Enable/disable input as appropriate
//[QGVAR(isSpectator), _set] call EFUNC(common,setDisableUserInputStatus);
// Handle common addon audio
if (["ace_hearing"] call EFUNC(common,isModLoaded)) then {EGVAR(hearing,disableVolumeUpdate) = _set};
if (["acre_sys_radio"] call EFUNC(common,isModLoaded)) then {[_set] call acre_api_fnc_setSpectator};
if (["task_force_radio"] call EFUNC(common,isModLoaded)) then {[_unit, _set] call TFAR_fnc_forceSpectator};
// Spectators ignore damage (vanilla and ace_medical)
_unit allowDamage !_set;
_unit setVariable [QEGVAR(medical,allowDamage), !_set];
// No theoretical change if an existing spectator was reset
if !(_set && (_unit getVariable [QGVAR(isSpectator), false])) then {
// Mark spectator state for reference
_unit setVariable [QGVAR(isSpectator), _set, true];
["spectatorChanged",[_set]] call EFUNC(common,localEvent);
};
["spectatorSet",[_set]] call EFUNC(common,localEvent);

View File

@ -0,0 +1,68 @@
/*
* Author: SilentSpike
* Sets target unit to the given spectator state (physically)
* To virtually handle a spectator see ace_spectator_fnc_setSpectator
*
* Units will be gathered at marker ace_spectator_respawn (or [0,0,0] by default)
* Upon unstage, units will be moved to the position they were in upon staging
*
* Arguments:
* 0: Unit to put into spectator stage <OBJECT>
* 1: Spectator stage <BOOL> <OPTIONAL>
*
* Return Value:
* None <NIL>
*
* Example:
* [player, false] call ace_spectator_fnc_stageSpectator
*
* Public: Yes
*/
#include "script_component.hpp"
params ["_unit", ["_set",true,[true]]];
// No change, no service (but allow spectators who respawn to be reset)
if !(_set || (GETVAR(_unit,GVAR(isSpectator),false))) exitWith {};
// Only run for player units
if !(isPlayer _unit) exitWith {};
if !(local _unit) exitwith {
[[_unit, _set, _target], QFUNC(stageSpectator), _unit] call EFUNC(common,execRemoteFnc);
};
// Prevent player falling into water
_unit enableSimulation !_set;
// Move to/from group as appropriate
[_unit, _set, QGVAR(isSpectator), side group _unit] call EFUNC(common,switchToGroupSide);
if (_set) then {
// Move and hide the player ASAP to avoid being seen
GVAR(oldPos) = getPosATL _unit;
_unit setPos (getMarkerPos QGVAR(respawn));
// Ghosts can't talk
[_unit, QGVAR(isSpectator)] call EFUNC(common,hideUnit);
[_unit, QGVAR(isSpectator)] call EFUNC(common,muteUnit);
} else {
// Physical beings can talk
[_unit, QGVAR(isSpectator)] call EFUNC(common,unhideUnit);
[_unit, QGVAR(isSpectator)] call EFUNC(common,unmuteUnit);
_unit setPosATL GVAR(oldPos);
};
// Spectators ignore damage (vanilla and ace_medical)
_unit allowDamage !_set;
_unit setVariable [QEGVAR(medical,allowDamage), !_set];
// No theoretical change if an existing spectator was reset
if !(_set isEqualTo (GETVAR(_unit,GVAR(isSpectator),false))) then {
// Mark spectator state for reference
_unit setVariable [QGVAR(isSpectator), _set, true];
["spectatorStaged",[_set]] call EFUNC(common,localEvent);
};