Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions addons/statemachine/CBA_FSMEditor.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Usage:
4.2 'condition' is parsed as condition = QUOTE(x)
4.3 'action' is parsed as is, and may contain onTransition = ""
and/or events[] = {}
4.4 'preCondition' is parsed as is, and may contain conditionFrequency = <NUMBER>

Dependencies:
In order to properly function, script_macros_common.hpp must be included.
Expand Down Expand Up @@ -52,6 +53,7 @@ class Compile {
print_transition = "class %(linkname) {\n";
indent_transitionOpen = 12;
print_target = "targetState = QUOTE(%(to));\n";
print_condFrequency = "%(condPrecondition);\n";
print_condition = "condition = QUOTE(%(condition));";
indent_transitionContents = 12; // Neccessary to preserve formatting.
print_transitionContents = "%(action)\n";
Expand Down
23 changes: 22 additions & 1 deletion addons/statemachine/fnc_addTransition.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ params [
["_targetState", "", [""]],
["_condition", {}, [{}]],
["_onTransition", {}, [{}]],
["_name", "NONAME", [""]]
["_name", "NONAME", [""]],
["_conditionFrequency", 0, [0]]
];

private _states = _stateMachine getVariable QGVAR(states);
Expand All @@ -49,6 +50,26 @@ if (isNull _stateMachine
|| {_condition isEqualTo {}}
) exitWith {false};

if (_conditionFrequency > 0) then {
_condition = compile format [QUOTE(\
private _return = false;\
if ((_current getVariable [ARR_2((QQGVAR(lastCheckedState) + str _id), '')]) isEqualTo _thisState) then {\
private _lastCheckedTime = _current getVariable [ARR_2((QQGVAR(lastCheckedTime) + str _id), CBA_MissionTime)];\
if (CBA_MissionTime >= (_lastCheckedTime + %2)) then {\
_current setVariable [ARR_2((QQGVAR(lastCheckedTime) + str _id), CBA_MissionTime)];\
_return = true;\
} else {\
_return = false;\
};\
} else {\
_current setVariable [ARR_2((QQGVAR(lastCheckedState) + str _id), _thisState)];\
_current setVariable [ARR_2((QQGVAR(lastCheckedTime) + str _id), CBA_MissionTime)];\
_return = false;\
};\
_return && %1\
), _condition, _conditionFrequency];
};

private _transitions = _stateMachine getVariable TRANSITIONS(_originalState);
_transitions pushBack [_name, _condition, _targetState, _onTransition];
_stateMachine setVariable [TRANSITIONS(_originalState), _transitions];
Expand Down
3 changes: 2 additions & 1 deletion addons/statemachine/fnc_createFromConfig.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ private _stateMachine = [_list, _skipNull] call FUNC(create);
if (isText (_x >> "targetState")) then {
_targetState = getText (_x >> "targetState");
};
private _conditionFrequency = getNumber (_x >> "conditionFrequency");
GET_FUNCTION(_condition,_x >> "condition");
GET_FUNCTION(_onTransition,_x >> "onTransition");
private _events = getArray (_x >> "events");

if (_events isEqualTo []) then {
[_stateMachine, _state, _targetState, _condition, _onTransition, _transition] call FUNC(addTransition);
[_stateMachine, _state, _targetState, _condition, _onTransition, _transition, _conditionFrequency] call FUNC(addTransition);
} else {
[_stateMachine, _state, _targetState, _events, _condition, _onTransition, _transition] call FUNC(addEventTransition);
};
Expand Down
1 change: 1 addition & 0 deletions addons/statemachine/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

// #define DISABLE_COMPILE_CACHE
// #define STATEMACHINE_PERFORMANCE_COUNTERS
// #define DEBUG_ENABLED_STATEMACHINE

#ifdef DEBUG_ENABLED_STATEMACHINE
#define DEBUG_MODE_FULL
Expand Down