diff --git a/addons/cars/XEH_PREP.hpp b/addons/cars/XEH_PREP.hpp index 05196b70..6e525666 100644 --- a/addons/cars/XEH_PREP.hpp +++ b/addons/cars/XEH_PREP.hpp @@ -7,9 +7,13 @@ PREP(setVehicles); PREP(sm_business_state_dismount_enter); PREP(sm_business_state_mountUp_enter); PREP(sm_business_state_mountUp_exit); +PREP(sm_business_state_rideInBack_enter); +PREP(sm_business_state_rideInBack_exit); PREP(sm_business_trans_dismount_rally_condition); PREP(sm_business_trans_mountUp_dismount_condition); PREP(sm_business_trans_rally_mountUp_condition); +PREP(sm_business_trans_rally_rideInBack_condition); +PREP(sm_business_trans_rideInBack_rally_condition); PREP(sm_business); PREP(spawnCarAndCrew); PREP(spawnVehicle); diff --git a/addons/cars/functions/fnc_sm_business.sqf b/addons/cars/functions/fnc_sm_business.sqf index a737c731..e8d4063e 100644 --- a/addons/cars/functions/fnc_sm_business.sqf +++ b/addons/cars/functions/fnc_sm_business.sqf @@ -24,6 +24,14 @@ private _bus_dismount = [ "bus_dismount" ] call EFUNC(cba_statemachine,addState); +private _bus_rideInBack = [ + _business, + {}, + { _this call FUNC(sm_business_state_rideInBack_enter) }, + { _this call FUNC(sm_business_state_rideInBack_exit) }, + "bus_rideInBack" +] call EFUNC(cba_statemachine,addState); + // TRANSITIONS assert ([ @@ -51,4 +59,20 @@ assert ([ _bus_dismount + _bus_rally ] call EFUNC(cba_statemachine,addTransition)); +assert ([ + _business, + _bus_rally, _bus_rideInBack, + { _this call FUNC(sm_business_trans_rally_rideInBack_condition) }, + {}, + _bus_rally + _bus_rideInBack +] call EFUNC(cba_statemachine,addTransition)); + +assert ([ + _business, + _bus_rideInBack, _bus_rally, + { _this call FUNC(sm_business_trans_rideInBack_rally_condition) }, + {}, + _bus_rideInBack + _bus_rally +] call EFUNC(cba_statemachine,addTransition)); + _business diff --git a/addons/cars/functions/fnc_sm_business_state_rideInBack_enter.sqf b/addons/cars/functions/fnc_sm_business_state_rideInBack_enter.sqf new file mode 100644 index 00000000..80a31296 --- /dev/null +++ b/addons/cars/functions/fnc_sm_business_state_rideInBack_enter.sqf @@ -0,0 +1,8 @@ +#include "..\script_component.hpp" + +private _grpVeh = _this call FUNC(getGroupVehicle); + +if (vehicle _this != _grpVeh) then { + _this assignAsCargo _grpVeh; + [_this] orderGetIn true; +}; diff --git a/addons/cars/functions/fnc_sm_business_state_rideInBack_exit.sqf b/addons/cars/functions/fnc_sm_business_state_rideInBack_exit.sqf new file mode 100644 index 00000000..b8766e55 --- /dev/null +++ b/addons/cars/functions/fnc_sm_business_state_rideInBack_exit.sqf @@ -0,0 +1,3 @@ +#include "..\script_component.hpp" + +unassignVehicle _this; diff --git a/addons/cars/functions/fnc_sm_business_trans_rally_mountUp_condition.sqf b/addons/cars/functions/fnc_sm_business_trans_rally_mountUp_condition.sqf index 274e3b0a..13b56f53 100644 --- a/addons/cars/functions/fnc_sm_business_trans_rally_mountUp_condition.sqf +++ b/addons/cars/functions/fnc_sm_business_trans_rally_mountUp_condition.sqf @@ -1,13 +1,11 @@ #include "..\script_component.hpp" +if (leader _this != _this) exitWith {}; + private _haveVehicle = (canMove (_this call FUNC(getGroupVehicle))); if (!_haveVehicle && (_this getVariable ["grad_civs_primaryTask", ""] in ["voyage", "transit"])) exitWith { _this setVariable ["grad_civs_primaryTask", "patrol", true]; INFO_1("%1 was tasked with voyage but vehicle %2 is immovable or absent - will go on patrol hencewith", _this, _this call FUNC(getGroupVehicle)); }; - -private _grpUnits = units _this; -private _allRallying = -1 == (_grpUnits findIf { ([_x, "business"] call EFUNC(common,civGetState)) != "bus_rally" }); - -_allRallying && _haveVehicle && (leader _this == _this) +_haveVehicle diff --git a/addons/cars/functions/fnc_sm_business_trans_rally_rideInBack_condition.sqf b/addons/cars/functions/fnc_sm_business_trans_rally_rideInBack_condition.sqf new file mode 100644 index 00000000..006d7b6b --- /dev/null +++ b/addons/cars/functions/fnc_sm_business_trans_rally_rideInBack_condition.sqf @@ -0,0 +1,13 @@ +#include "..\script_component.hpp" + +private _leader = leader _this; + +if (_leader == _this) exitWith {false}; + +private _leaderStatus = [_leader, "business"] call EFUNC(common,civGetState); +private _grpVeh = _this call FUNC(getGroupVehicle); + +private _leaderIsCallingForMountUp = (_leaderStatus == "bus_mountUp"); +private _leaderIsRallyingAndMounted = {_leaderStatus == "bus_rally" && vehicle _leader == _grpVeh}; + +_leaderIsCallingForMountUp || _leaderIsRallyingAndMounted diff --git a/addons/cars/functions/fnc_sm_business_trans_rideInBack_rally_condition.sqf b/addons/cars/functions/fnc_sm_business_trans_rideInBack_rally_condition.sqf new file mode 100644 index 00000000..029015c0 --- /dev/null +++ b/addons/cars/functions/fnc_sm_business_trans_rideInBack_rally_condition.sqf @@ -0,0 +1,9 @@ +#include "..\script_component.hpp" + +private _leader = leader _this; +private _leaderStatus = [_leader, "business"] call EFUNC(common,civGetState); + +private _leaderDismounts = _leaderStatus == "bus_dismount"; +private _leaderRallyingAndDismounted = {_leaderStatus == "bus_rally" && vehicle _leader == _leader}; + +_leaderDismounts || _leaderRallyingAndDismounted diff --git a/addons/legacy/XEH_PREP.hpp b/addons/legacy/XEH_PREP.hpp index cc2a07b6..14a38436 100644 --- a/addons/legacy/XEH_PREP.hpp +++ b/addons/legacy/XEH_PREP.hpp @@ -77,7 +77,6 @@ PREP(sm_activities_trans_surrendered_business_condition); PREP(sm_activities_trans_surrendered_panic_condition); PREP(sm_business); PREP(sm_business_state_rally_enter); -PREP(sm_business_state_rally_loop); PREP(sm_emotions); PREP(sm_lifecycle); PREP(sm_lifecycle_state_death_enter); diff --git a/addons/legacy/functions/fnc_sm_business.sqf b/addons/legacy/functions/fnc_sm_business.sqf index 4bd054ba..9117482f 100644 --- a/addons/legacy/functions/fnc_sm_business.sqf +++ b/addons/legacy/functions/fnc_sm_business.sqf @@ -5,7 +5,7 @@ private _business = [[], true] call CBA_statemachine_fnc_create; // entry point private _bus_rally = [ _business, - { _this call FUNC(sm_business_state_rally_loop) }, + { }, { _this call FUNC(sm_business_state_rally_enter) }, { }, "bus_rally" diff --git a/addons/legacy/functions/fnc_sm_business_state_rally_loop.sqf b/addons/legacy/functions/fnc_sm_business_state_rally_loop.sqf deleted file mode 100644 index b63a68ab..00000000 --- a/addons/legacy/functions/fnc_sm_business_state_rally_loop.sqf +++ /dev/null @@ -1,17 +0,0 @@ -#include "..\script_component.hpp" - -private _leader = leader _this; - -/*if leader is calling for mounting up: get in*/ -if (([_leader, "business"] call EFUNC(common,civGetState)) == "bus_mountUp") then { // TODO resolve circular dependency - private _veh = _this call EFUNC(cars,getGroupVehicle); // TODO resolve circular dependency - create new "passenger" state for passengers - if (_veh != vehicle _this) then { - _this assignAsCargo _veh; - [_this] orderGetIn true; - }; -} else { - /*if leader is unmounted, and I'm not: get out*/ - if ((_leader == vehicle _leader) && (_this != vehicle _this)) then { - unassignVehicle _this; - }; -}; diff --git a/addons/transit/functions/fnc_sm_business_trans_mountUp_transit_condition.sqf b/addons/transit/functions/fnc_sm_business_trans_mountUp_transit_condition.sqf index 9e4daaf6..a7c25a52 100644 --- a/addons/transit/functions/fnc_sm_business_trans_mountUp_transit_condition.sqf +++ b/addons/transit/functions/fnc_sm_business_trans_mountUp_transit_condition.sqf @@ -1,15 +1,21 @@ +#include "..\script_component.hpp" + private _civ = _this; -private _isLeader = (leader _civ) == _civ; +if (leader _civ != _this) exitWith {false}; + +private _groupVehicle = _civ call EFUNC(cars,getGroupVehicle); +private _units = units _civ; + +private _allAssigned = { + (_units arrayIntersect (crew _groupVehicle)) isEqualTo _units +}; private _allMounted = { - private _units = units _civ; - private _mountedUnits = crew vehicle _civ; + private _mountedUnits = _units select {vehicle _x == _groupVehicle}; (_units arrayIntersect _mountedUnits) isEqualTo _units }; -private _isTaskTransit = { - _civ getVariable ["grad_civs_primaryTask", ""] == "transit" -}; +private _isTaskTransit = _civ getVariable ["grad_civs_primaryTask", ""] == "transit"; -_isLeader && _allMounted && _isTaskTransit +_isTaskTransit && _allAssigned && _allMounted diff --git a/addons/voyage/functions/fnc_sm_business_trans_mountUp_voyage_condition.sqf b/addons/voyage/functions/fnc_sm_business_trans_mountUp_voyage_condition.sqf index b950f999..fe93eea9 100644 --- a/addons/voyage/functions/fnc_sm_business_trans_mountUp_voyage_condition.sqf +++ b/addons/voyage/functions/fnc_sm_business_trans_mountUp_voyage_condition.sqf @@ -1,4 +1,21 @@ -private _grpMembers = units _this; -private _mountedCount = { vehicle _x != _x } count _grpMembers; +#include "..\script_component.hpp" -(_mountedCount == count _grpMembers) && (leader _this == _this) && (_this getVariable ["grad_civs_primaryTask", ""] == "voyage") +private _civ = _this; + +if (leader _civ != _this) exitWith {false}; + +private _groupVehicle = _civ call EFUNC(cars,getGroupVehicle); +private _units = units _civ; + +private _allAssigned = { + (_units arrayIntersect (crew _groupVehicle)) isEqualTo _units +}; + +private _allMounted = { + private _mountedUnits = _units select {vehicle _x == _groupVehicle}; + (_units arrayIntersect _mountedUnits) isEqualTo _units +}; + +private _isTaskTransit = _civ getVariable ["grad_civs_primaryTask", ""] == "voyage"; + +_isTaskTransit && _allAssigned && _allMounted