Skip to content

Commit

Permalink
refactor: create extra state for passengers (#79)
Browse files Browse the repository at this point in the history
* resolve circular dependency, hopefully more robust  and more clear mountup/dismount logic
* Remove condition for mountUp:   I cannot remember why all civs of a group needed to rally for the group leader to call everyone to mount up. Remove condition.
* fix mountUp->voyage|transit logic. take care to look for the correct vehicle.
  • Loading branch information
Fusselwurm authored Jul 17, 2020
1 parent 9b6e3cd commit 2fe1853
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 34 deletions.
4 changes: 4 additions & 0 deletions addons/cars/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
24 changes: 24 additions & 0 deletions addons/cars/functions/fnc_sm_business.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 ([
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "..\script_component.hpp"

unassignVehicle _this;
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion addons/legacy/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion addons/legacy/functions/fnc_sm_business.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
17 changes: 0 additions & 17 deletions addons/legacy/functions/fnc_sm_business_state_rally_loop.sqf

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2fe1853

Please sign in to comment.