-
Notifications
You must be signed in to change notification settings - Fork 762
Common - Add loading of dead units into vehicles #11372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Dystopian
wants to merge
11
commits into
acemod:master
Choose a base branch
from
Dystopian:loadDeadUnit
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
04305f7
Add loading of dead units into vehicles
Dystopian 7a87c34
Fix cargo seats assigning, Fix dedicated server crash
Dystopian c411943
Fix unit not always loaded in after drop
Dystopian 3438b34
Fix flow, Fix comments, Improve naming
Dystopian e373abf
Use fixes and features from dev 153732
Dystopian 1e17e47
Remove useless condition
Dystopian b279089
Use reverse fill for cargo
Dystopian 5e6ebd5
Remove useless comment
Dystopian 84c9ca6
Make emptyPositions parameters clearer
Dystopian 5e91d07
Rework main loop after dev 153788: emptyPositions respects locked state
Dystopian e1a284e
Improve event handler
Dystopian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| #include "..\script_component.hpp" | ||
| /* | ||
| * Author: Dystopian | ||
| * Loads dead person into most suitable seat in vehicle. | ||
| * | ||
| * Arguments: | ||
| * 0: Unit <OBJECT> | ||
| * 1: Vehicle <OBJECT> | ||
| * | ||
| * Return Value: | ||
| * None | ||
| * | ||
| * Example: | ||
| * [cursorObject, vehicle player] call ace_common_fnc_loadDeadPerson | ||
| * | ||
| * Public: No | ||
| */ | ||
|
|
||
| params ["_unit", "_vehicle"]; | ||
| TRACE_4("loadDeadPerson",_unit,_vehicle,typeOf _vehicle,local _unit); | ||
|
|
||
| if (!local _vehicle) exitWith {ERROR_4("loadDeadPerson vehicle not local; unit=%1[%2] vehicle=%3[%4]",_unit,typeOf _unit,_vehicle,typeOf _vehicle)}; | ||
|
|
||
| #define PRIORITY_NONE -1 | ||
| #define PRIORITY_DRIVER 0 | ||
| #define PRIORITY_GUNNER 1 | ||
| #define PRIORITY_COMMANDER 2 | ||
| #define PRIORITY_TURRET_NO_FFV 3 | ||
| #define PRIORITY_TURRET_FFV 4 | ||
| #define PRIORITY_TURRET_EMPTY 5 | ||
| #define PRIORITY_CARGO 6 | ||
|
|
||
| // Determine highest-priority available seats | ||
| private _emptySeats = fullCrew [_vehicle, "", true] select {isNull (_x select 0)}; | ||
| private _vehicleConfig = configOf _vehicle; | ||
| private _bestSeatsPriority = PRIORITY_NONE; | ||
| private _bestSeatsRole = ""; | ||
| private _bestSeatsParams = []; | ||
| { | ||
| _x params ["", "_role", "_cargoIndex", "_turretPath", "_isPersonTurret"]; | ||
| private _priority = PRIORITY_NONE; | ||
| switch (_role) do { | ||
| case "driver": { | ||
| if ( | ||
| lockedDriver _vehicle | ||
| || {unitIsUAV _vehicle} | ||
| || {getNumber (_vehicleConfig >> "hasDriver") < 1} | ||
| || {getNumber (_vehicleConfig >> "ejectDeadDriver") > 0} | ||
| ) then {continue}; | ||
| _priority = PRIORITY_DRIVER; | ||
| }; | ||
| case "cargo": { | ||
| if ( | ||
| _vehicle lockedCargo _cargoIndex | ||
| || {getNumber (_vehicleConfig >> "ejectDeadCargo") > 0} | ||
| ) then {continue}; | ||
| _priority = PRIORITY_CARGO; | ||
| }; | ||
| default { | ||
| private _turretConfig = [_vehicleConfig, _turretPath] call CBA_fnc_getTurret; | ||
| if ( | ||
| _vehicle lockedTurret _turretPath | ||
| || {getNumber (_turretConfig >> "ejectDeadGunner") > 0} | ||
| || {_role == "gunner" && {unitIsUAV _vehicle}} | ||
| ) then {continue}; | ||
| _priority = switch (_role) do { | ||
| case "gunner": {PRIORITY_GUNNER}; | ||
| case "commander": {PRIORITY_COMMANDER}; | ||
| case "turret": { | ||
| if (_isPersonTurret) then {PRIORITY_TURRET_FFV} | ||
| else {[PRIORITY_TURRET_NO_FFV, PRIORITY_TURRET_EMPTY] select (getText (_turretConfig >> "gun") == "")} | ||
| }; | ||
| }; | ||
| }; | ||
| }; | ||
| TRACE_2("emptySeat",_x,_priority); | ||
| if (_priority > _bestSeatsPriority) then { | ||
| _bestSeatsPriority = _priority; | ||
| _bestSeatsRole = _role; | ||
| _bestSeatsParams = [[_cargoIndex, _turretPath]]; | ||
| continue; | ||
| }; | ||
| if (_priority == _bestSeatsPriority) then { | ||
| if (_priority == PRIORITY_CARGO) then { | ||
| _bestSeatsParams = [[_cargoIndex, _turretPath]]; // use only the last cargo seat | ||
| } else { | ||
| _bestSeatsParams pushBack [_cargoIndex, _turretPath]; | ||
| }; | ||
| }; | ||
| } forEach _emptySeats; | ||
|
|
||
| if (_bestSeatsPriority == PRIORITY_NONE) exitWith { | ||
| TRACE_2("No seats found",_emptySeats apply {_x select [ARR_2(1,3)]},fullCrew _vehicle apply {_x select [ARR_2(0,4)]}); | ||
| }; | ||
|
|
||
| private _moveInAnyPosition = toUpper _bestSeatsRole; | ||
| private _emptyPositions = _vehicle emptyPositions [_moveInAnyPosition]; | ||
| TRACE_4("emptySeats",_bestSeatsPriority,_bestSeatsRole,_bestSeatsParams,_emptyPositions); | ||
|
|
||
| // Probe seat positions using temporary units to identify exact seat | ||
| private _seatHolders = []; | ||
|
|
||
| while {_emptyPositions > 1} do { | ||
| private _seatHolder = createVehicleLocal [QGVAR(seatHolder), [0,0,0], [], 0, "CAN_COLLIDE"]; | ||
| private _seatHolderMoveSuccess = _seatHolder moveInAny [_vehicle, [_moveInAnyPosition]]; | ||
| private _seatHolderSeat = fullCrew _vehicle select {_x select 0 == _seatHolder}; | ||
| if (!_seatHolderMoveSuccess || {_seatHolderSeat isEqualTo []}) then { | ||
| ERROR_8("moveInAny holder failed unit=%1[%2] vehicle=%3[%4] pos=%5 seatHolder=%6 success=%7 fullCrew=%8",_unit,typeOf _unit,_vehicle,typeOf _vehicle,_moveInAnyPosition,_seatHolder,_seatHolderMoveSuccess,fullCrew _vehicle apply {_x select [ARR_2(0,4)]}); | ||
| _vehicle deleteVehicleCrew _seatHolder; | ||
| if (!isNull _seatHolder) then { // failsafe | ||
| moveOut _seatHolder; | ||
| deleteVehicle _seatHolder; | ||
| }; | ||
| break; | ||
| }; | ||
| _seatHolderSeat select 0 params ["", "", "_cargoIndex", "_turretPath"]; | ||
| TRACE_3("seatHolder",_emptyPositions,_cargoIndex,_turretPath); | ||
| if ([_cargoIndex, _turretPath] in _bestSeatsParams) then { | ||
| _vehicle deleteVehicleCrew _seatHolder; | ||
| _emptyPositions = 1; | ||
| break; | ||
| }; | ||
| _seatHolders pushBack _seatHolder; | ||
| DEC(_emptyPositions); | ||
| }; | ||
|
|
||
| if (_emptyPositions == 1) then { // need this check in case of seatHolder moveInAny fail | ||
| private _unitMoveSuccess = _unit moveInAny [_vehicle, [_moveInAnyPosition]]; | ||
| if (_unitMoveSuccess) then { | ||
| [QGVAR(deadPersonLoaded), _unit] call CBA_fnc_globalEvent; // Ensure dead unit stays unconscious on all clients | ||
| } else { | ||
| ERROR_8("moveInAny unit failed unit=%1[%2] vehicle=%3[%4] pos=%5 local=%6 seatHolders=%7 fullCrew=%8",_unit,typeOf _unit,_vehicle,typeOf _vehicle,_moveInAnyPosition,local _unit,_seatHolders,fullCrew _vehicle apply {_x select [ARR_2(0,4)]}); | ||
| }; | ||
| }; | ||
|
|
||
| { | ||
| _vehicle deleteVehicleCrew _x; | ||
| } forEach _seatHolders; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth to move
_overrideVehicleto the_distanceand make one hybrid argument? When there is overriding vehicle, distance does not make sense anyway.