more common code cleanup

This commit is contained in:
commy2 2015-09-18 19:12:38 +02:00
parent 2674310e65
commit a18f63d861
3 changed files with 67 additions and 40 deletions

View File

@ -41,7 +41,8 @@ if (_slotsOpen) then {
_vehicle setVariable [QGVAR(loaded_persons), _loaded, true];
if !([_unit] call FUNC(isAwake)) then {
// @todo never used. Remove?
/*if !([_unit] call FUNC(isAwake)) then {
[{
(_this select 0) params ["_unit", "_vehicle"];
@ -59,5 +60,5 @@ if (_slotsOpen) then {
[_this select 1] call CBA_fnc_removePerFrameHandler;
}, 0.5, [_unit, _vehicle]] call CBA_fnc_addPerFrameHandler;
};
};*/
};

View File

@ -10,23 +10,26 @@
*
* Public: No
*/
//#define DEBUG_MODE_FULL
#include "script_component.hpp"
#define GROUP_SWITCH_ID QUOTE(FUNC(loadPerson))
private ["_vehicle","_emptyPos"];
PARAMS_1(_unit);
params ["_unit"];
private "_vehicle";
_vehicle = vehicle _unit;
if (_vehicle == _unit) exitwith {false;};
if !(speed _vehicle <1 && (((getpos _vehicle) select 2) < 2)) exitwith {false;};
if (_vehicle == _unit) exitWith {false};
_emptyPos = ((getPos _vehicle) findEmptyPosition [0, 10, typeof _unit]);
if (count _emptyPos == 0) exitwith {false};
if (speed _vehicle > 1 || getPos _vehicle select 2 > 2) exitWith {false};
private "_emptyPos";
_emptyPos = (getPos _vehicle) findEmptyPosition [0, 10, typeof _unit];
if (count _emptyPos == 0) exitWith {false};
if (!isNull _vehicle) then {
[[_unit], QUOTE(FUNC(unloadPersonLocal)), _unit, false] call EFUNC(common,execRemoteFnc);
[[_unit], QUOTE(FUNC(unloadPersonLocal)), _unit, false] call FUNC(execRemoteFnc);
};
true;
true

View File

@ -10,34 +10,48 @@
*
* Public: No
*/
//#define DEBUG_MODE_FULL
#include "script_component.hpp"
#define GROUP_SWITCH_ID QUOTE(FUNC(loadPerson))
private ["_loaded", "_emptyPos","_validVehiclestate"];
PARAMS_2(_unit,_vehicle);
params ["_unit", "_vehicle"];
private ["_validVehiclestate", "_emptyPos", "_loaded"];
_validVehiclestate = true;
if (_vehicle isKindOf "Ship" ) then {
if !(speed _vehicle <1 && {(((getPosATL _vehicle) select 2) < 2)}) then {_validVehiclestate = false};
TRACE_1("SHIP Ground Check", getPosATL _vehicle );
_emptyPos = ((getPosASL _vehicle) call EFUNC(common,ASLtoPosition) findEmptyPosition [0, 13, typeof _unit]); // TODO: if spot is underwater pick another spot.
if (speed _vehicle > 1 || {getPos _vehicle select 2 > 2}) then {
_validVehiclestate = false;
};
TRACE_1("SHIP Ground Check",getPos _vehicle);
_emptyPos = (ASLToAGL getPosASL _vehicle) findEmptyPosition [0, 13, typeof _unit]; // TODO: if spot is underwater pick another spot.
} else {
if (_vehicle isKindOf "Air" ) then {
if !(speed _vehicle <1 && {isTouchingGround _vehicle}) then {_validVehiclestate = false};
TRACE_1("Vehicle Ground Check", isTouchingGround _vehicle);
_emptyPos = (getPosASL _vehicle) call EFUNC(common,ASLtoPosition);
_emptyPos = [(_emptyPos select 0) + random(5), (_emptyPos select 1) + random(5), _emptyPos select 2 ];
if (_vehicle isKindOf "Air") then {
if (speed _vehicle > 1 || {isTouchingGround _vehicle}) then {
_validVehiclestate = false;
};
TRACE_1("Vehicle Ground Check",isTouchingGround _vehicle);
_emptyPos = ASLToAGL getPosASL _vehicle;
_emptyPos = _emptyPos vectorAdd [random 10 - 5, random 10 - 5, 0];
} else {
if !(speed _vehicle <1 && {(((getPosATL _vehicle) select 2) < 2)}) then {_validVehiclestate = false};
if (speed _vehicle > 1 || {getPos _vehicle select 2 > 2}) then {
_validVehiclestate = false;
};
TRACE_1("Vehicle Ground Check", isTouchingGround _vehicle);
_emptyPos = ((getPosASL _vehicle) call EFUNC(common,ASLtoPosition) findEmptyPosition [0, 13, typeof _unit]);
_emptyPos = (ASLToAGL getPosASL _vehicle) findEmptyPosition [0, 13, typeof _unit]);
};
};
TRACE_1("getPosASL Vehicle Check", getPosASL _vehicle);
if (!_validVehiclestate) exitwith {
if !(_validVehiclestate) exitwith {
ACE_LOGWARNING_4("Unable to unload patient because invalid (%1) vehicle state. Either moving or Not close enough on the ground. position: %2 isTouchingGround: %3 Speed: %4",_vehicle,getPos _vehicle,isTouchingGround _vehicle,speed _vehicle);
false
};
@ -47,36 +61,45 @@ if (count _emptyPos == 0) exitwith {
false
}; //consider displaying text saying there are no safe places to exit the vehicle
unassignVehicle _unit;
[_unit] orderGetIn false;
TRACE_1("Ejecting", alive _unit);
_unit action ["Eject", vehicle _unit];
[ {
private "_anim";
PARAMS_2(_unit,_emptyPos);
_unit setPosASL (_emptyPos call EFUNC(common,PositiontoASL));
if (!([_unit] call FUNC(isAwake))) then {
[{
params ["_unit", "_emptyPos"];
_unit setPosASL AGLToASL _emptyPos;
// @todo never used. Remove?
/*if !([_unit] call FUNC(isAwake)) then {
TRACE_1("Check if isAwake", [_unit] call FUNC(isAwake));
if (driver _unit == _unit) then {
_anim = [_unit] call EFUNC(common,getDeathAnim);
[_unit, _anim, 1, true] call EFUNC(common,doAnimation);
private "_anim";
_anim = [_unit] call FUNC(getDeathAnim);
[_unit, _anim, 1, true] call FUNC(doAnimation);
[{
_unit = _this select 0;
_anim = _this select 1;
if ((_unit getVariable "ACE_isUnconscious") and (animationState _unit != _anim)) then {
[_unit, _anim, 2, true] call EFUNC(common,doAnimation);
[_unit, _anim, 2, true] call FUNC(doAnimation);
};
}, [_unit, _anim], 0.5, 0] call EFUNC(common,waitAndExecute);
}, [_unit, _anim], 0.5, 0] call FUNC(waitAndExecute);
};
};
},[_unit,_emptyPos], 0.5, 0] call EFUNC(common,waitAndExecute);
};*/
}, [_unit, _emptyPos], 0.5, 0] call FUNC(waitAndExecute);
[_unit, false, GROUP_SWITCH_ID, side group _unit] call FUNC(switchToGroupSide);
_loaded = _vehicle getvariable [QGVAR(loaded_persons),[]];
_loaded = _loaded - [_unit];
_vehicle setvariable [QGVAR(loaded_persons),_loaded,true];
_loaded deleteAt (_loaded find _unit);
_vehicle setvariable [QGVAR(loaded_persons), _loaded, true];
true