Skip to content
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

Shootingrange trigger expansion #159

Merged
merged 8 commits into from
May 9, 2016
Merged
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
12 changes: 12 additions & 0 deletions addons/shootingrange/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ class CfgVehicles {
typeName = "STRING";
defaultValue = "";
};
class TargetsInvalid {
displayName = CSTRING(TargetsInvalid);
description = CSTRING(TargetsInvalidDesc);
typeName = "STRING";
defaultValue = "";
};
class Controllers {
displayName = CSTRING(Controllers);
description = CSTRING(ControllersDesc);
Expand Down Expand Up @@ -111,6 +117,12 @@ class CfgVehicles {
typeName = "STRING";
defaultValue = "";
};
class PopOnTriggerExit {
displayName = CSTRING(PopOnTriggerExit);
description = CSTRING(PopOnTriggerExitDesc);
typeName = "BOOL";
defaultValue = 1;
};
};
class ModuleDescription {
description = CSTRING(ModuleDesc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,4 @@ private _actions = [];
];
} forEach _countdownTimes;

TRACE_1("Children actions",_actions);

_actions
4 changes: 2 additions & 2 deletions addons/shootingrange/functions/fnc_animateTarget.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private _fnc_animate = {
// Wait animation time before changing animation again
[{
params ["_target", "_state", "_anims"];
TRACE_3("Wait Animate",_target,_state,_anims);
//TRACE_3("Wait Animate",_target,_state,_anims);
{
_target animate [_x, _state];
} forEach _anims;
Expand All @@ -34,7 +34,7 @@ private _fnc_animate = {

// Find oval target
private _index = OVAL_TARGETS find (typeOf _target);
TRACE_3("Animate",_target,_state,_index);
//TRACE_3("Animate",_target,_state,_index);

if (_index != -1) then {
// Oval target
Expand Down
17 changes: 12 additions & 5 deletions addons/shootingrange/functions/fnc_create.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* 8: Countdown Times <ARRAY> (default: 6, 9, 12, 15)
* 9: Default Countdown Time <NUMBER> (default: 9)
* 10: Trigger Markers <ARRAY> (default: [])
* 11: Pop on Trigger Exit <BOOL> (default: true)
* 12: Invalid Targets <ARRAY> (default: [])
*
* Return Value:
* None
Expand All @@ -38,7 +40,9 @@ params [
["_defaultPauseDuration", PAUSEDURATION_DEFAULT, [0] ],
["_countdownTimes", COUNTDOWNTIMES_DEFAULT, [[]] ],
["_defaultCountdownTime", COUNTDOWNTIME_DEFAULT, [0] ],
["_triggerMarkers", [], [[]] ]
["_triggerMarkers", [], [[]] ],
["_popOnTriggerExit", POPONTRIGGEREXIT_DEFAULT, [true] ],
["_targetsInvalid", [], [[]] ]
];

// Verify data
Expand All @@ -60,6 +64,9 @@ if (_defaultCountdownTime < COUNTDOWNTIME_LOWEST) then {
if (_mode == 4 && {count _triggerMarkers != count _targets}) exitWith {
ACE_LOGERROR("Trigger Markers field/argument must have the same number of elements as Targets field/argument when Trigger Mode is used!");
};
if (_mode == 4 && {count _triggerMarkers < count _targetsInvalid}) exitWith {
ACE_LOGERROR("Invalid Targets field/argument must have equal or less elements than Trigger Markers and Targets fields/arguments when Trigger Mode is used!");
};

// Defaults
if !(_name isEqualTo "") then {
Expand Down Expand Up @@ -158,7 +165,7 @@ _countdownTimes sort true;
{(_this select 2) call FUNC(start)},
{true},
{},
[_x, _controllers, _name, _targets, _triggerMarkers]
[_x, _controllers, _name, _targets, _targetsInvalid]
] call ACE_Interact_Menu_fnc_createAction;

[_x, 0, ["ACE_MainActions", QGVAR(Range)], _actionStart] call ACE_Interact_Menu_fnc_addActionToObject;
Expand Down Expand Up @@ -302,7 +309,7 @@ _countdownTimes sort true;
private _triggers = [];
if (_mode == 4) then {
// Prepare target groups
[_targets, _triggerMarkers] call FUNC(setTargetGroups);
[_targets, _targetsInvalid, _triggerMarkers] call FUNC(setTargetGroups);

// Set up triggers
{
Expand All @@ -318,7 +325,7 @@ if (_mode == 4) then {
_trigger setTriggerStatements [
format ["[%1, %2, %3] call %4", _controller, _target, _forEachIndex, QFUNC(canActivateTrigger)],
format ["[%1, %2] call %3", _target, 0, QFUNC(triggerPopup)],
format ["[%1, %2] call %3", _target, 1, QFUNC(triggerPopup)]
format ["if (%1) then { [%2, %3] call %4 }", _popOnTriggerExit, _target, 1, QFUNC(triggerPopup)]
];

_trigger enableSimulation false;
Expand All @@ -334,4 +341,4 @@ if (_mode == 4) then {
_x setVariable [QGVAR(controllers), _controllers];
_x setVariable [QGVAR(triggers), _triggers];
_x addEventHandler ["HitPart", { (_this select 0) call FUNC(handleHitPart); }];
} forEach _targets;
} forEach (_targets + _targetsInvalid);
12 changes: 9 additions & 3 deletions addons/shootingrange/functions/fnc_handleHitPart.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,17 @@ private _controller = (_target getVariable [QGVAR(controllers), nil]) select 0;
// Exit if not running
if !(_controller getVariable [QGVAR(running), false]) exitWith {};

private _targets = _target getVariable [QGVAR(targets), []];

// Exit if invalid target hit and set variable checked in PFH
if !(_target in _targets) exitWith {
GVAR(invalidTargetHit) = true;
};

// Exit if target already hit
if (_target getVariable [QGVAR(alreadyHit), false]) exitWith {};

// Exit if not direct hit (does not seem to count bullet bouning)
// Exit if not direct hit (does not seem to count bullet bouncing)
if (!_directHit) exitWith {
hint "[TAC] Debug: Indirect Hit";
[_target, 0] call FUNC(animateTarget); // Up
Expand All @@ -62,11 +69,10 @@ GVAR(targetNumber) = GVAR(targetNumber) + 1;


private _mode = _controller getVariable [QGVAR(mode), 0];
private _targets = _target getVariable [QGVAR(targets), nil];

// Handle random pop-ups in hit-based (exit if last target in hit-based with target limit)
if (_mode == 2 || {_mode == 3 && {GVAR(targetNumber) < _controller getVariable [QGVAR(targetAmount), 0]}}) then {
GVAR(nextTarget) = _targets select (floor (random (count _targets)));
GVAR(nextTarget) = selectRandom _targets;

// Animate target
[GVAR(nextTarget), 0] call FUNC(animateTarget); // Up
Expand Down
10 changes: 9 additions & 1 deletion addons/shootingrange/functions/fnc_moduleInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ private _name = _logic getVariable "Name";
private _targets = [_logic getVariable "Targets", true, true] call ACE_Common_fnc_parseList;
_targets append (synchronizedObjects _logic);

// Extract invalid target objects and manually check nil (use object if exists, otherwise objNull)
private _targetsInvalid = [_logic getVariable "TargetsInvalid", true, false] call ACE_Common_fnc_parseList;
_targetsInvalid = _targetsInvalid apply { [missionNamespace getVariable _x, objNull] select (isNil _x) };
//TRACE_1("Invalid Targets",_targetsInvalid);

// Exctract controller objects
private _controllers = [_logic getVariable "Controllers", true, true] call ACE_Common_fnc_parseList;

Expand Down Expand Up @@ -78,8 +83,11 @@ private _defaultCountdownTime = _logic getVariable "DefaultCountdownTime";
// Exctract triggers
private _triggerMarkers = [_logic getVariable "TriggerMarkers", true, false] call ACE_Common_fnc_parseList;

// Extract pop targets down on trigger exit setting
private _popOnTriggerExit = _logic getVariable "PopOnTriggerExit";


// Prepare with actions
[_name, _targets, _controllers, _mode, _durations, _defaultDuration, _targetAmounts, _defaultTargetAmount, _pauseDurations, _defaultPauseDuration, _countdownTimes, _defaultCountdownTime, _triggerMarkers] call FUNC(create);
[_name, _targets, _controllers, _mode, _durations, _defaultDuration, _targetAmounts, _defaultTargetAmount, _pauseDurations, _defaultPauseDuration, _countdownTimes, _defaultCountdownTime, _triggerMarkers, _popOnTriggerExit, _targetsInvalid] call FUNC(create);

ACE_LOGINFO("Shooting Range Module Initialized");
29 changes: 15 additions & 14 deletions addons/shootingrange/functions/fnc_popupPFH.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,37 @@
* 2: Pause Duration <NUMBER>
* 3: Target Amount <NUMBER>
* 4: Targets <ARRAY>
* 5: Controller <OBJECT>
* 6: Controllers <ARRAY>
* 7: Name <STRING>
* 8: Mode (1 = Time, 2 = Hit (Time Limited), 3 = Hit (Target Limited), 4 = Trigger, 5 = Rampage) <NUMBER>
* 9: Triggers <ARRAY>
* 5: Invalid Targets <ARRAY>
* 6: Controller <OBJECT>
* 7: Controllers <ARRAY>
* 8: Name <STRING>
* 9: Mode (1 = Time, 2 = Hit (Time Limited), 3 = Hit (Target Limited), 4 = Trigger, 5 = Rampage) <NUMBER>
* 10: Triggers <ARRAY>
* 1: Per-Frame Handler ID <NUMBER>
*
* Return Value:
* None
*
* Example:
* [ [450, 60, 3, [target1, target2], controller, [controller1, controller2], "range", 1, [trigger1, trigger2]], idPFH] call tac_shootingrange_fnc_popupPFH;
* [ [450, 60, 3, [target1, target2], [invalidTarget1, invalidTarget2], controller, [controller1, controller2], "range", 1, [trigger1, trigger2]], idPFH] call tac_shootingrange_fnc_popupPFH;
*
* Public: No
*/
#include "script_component.hpp"

params ["_args", "_idPFH"];
_args params ["_timeStart", "_duration", "_pauseDuration", "_targetAmount", "_targets", "_controller", "_controllers", "_name", "_mode", "_triggers"];
_args params ["_timeStart", "_duration", "_pauseDuration", "_targetAmount", "_targets", "_targetsInvalid", "_controller", "_controllers", "_name", "_mode", "_triggers"];

// Remove if stopped - fail
if !(_controller getVariable [QGVAR(running), false]) exitWith {
[_idPFH, _controller, _controllers, _name, _targets, _mode, false] call FUNC(popupPFHexit);
if (!(_controller getVariable [QGVAR(running), false]) || {GVAR(invalidTargetHit)}) exitWith {
[_idPFH, _controller, _controllers, _name, _targets, _targetsInvalid, _mode, false] call FUNC(popupPFHexit);
};

private _currentTime = diag_tickTime;

// Remove when time limit (duration) reached - success
if (_mode in [1, 2, 5] && {_currentTime >= _timeStart + _duration}) exitWith {
[_idPFH, _controller, _controllers, _name, _targets, _mode, true, GVAR(targetNumber), GVAR(maxScore)] call FUNC(popupPFHexit);
[_idPFH, _controller, _controllers, _name, _targets, _targetsInvalid, _mode, true, GVAR(targetNumber), GVAR(maxScore)] call FUNC(popupPFHexit);
};

// Remove when all targets hit - success
Expand All @@ -47,9 +48,9 @@ if ((_mode == 3 && {GVAR(targetNumber) >= _targetAmount}) || {_mode > 3 && {GVAR
private _timeElapsed = _currentTime - _timeStart;
_timeElapsed = (str _timeElapsed) splitString ".";
_timeElapsed = format ["%1.%2", _timeElapsed select 0, (_timeElapsed select 1) select [0, TIME_ROUND_CHARS]];
_timeElapsed = parseNumber (_timeElapsed);
_timeElapsed = parseNumber _timeElapsed;

[_idPFH, _controller, _controllers, _name, _targets, _mode, true, GVAR(targetNumber), GVAR(maxScore), _timeElapsed, _triggers] call FUNC(popupPFHexit);
[_idPFH, _controller, _controllers, _name, _targets, _targetsInvalid, _mode, true, GVAR(targetNumber), GVAR(maxScore), _timeElapsed, _triggers] call FUNC(popupPFHexit);
};

// Handle automatic target pop-ups in time-based mode
Expand All @@ -64,7 +65,7 @@ if (_mode == 1 && {GVAR(lastPauseTime) + _pauseDuration <= _currentTime}) exitWi
};

// Select random index (save for later removal from array) and new target
GVAR(nextTarget) = _targets select (floor (random (count _targets)));
GVAR(nextTarget) = selectRandom _targets;

// Animate new target
[GVAR(nextTarget), 0] call FUNC(animateTarget); // Up
Expand All @@ -84,7 +85,7 @@ if (_mode in [2, 3] && {GVAR(firstRun)}) exitWith {
GVAR(firstRun) = false;

// Select random index (save for later removal from array) and new target
GVAR(targetUp) = _targets select (floor (random (count _targets)));
GVAR(targetUp) = selectRandom _targets;

// Animate new target
[GVAR(targetUp), 0] call FUNC(animateTarget); // Up
Expand Down
19 changes: 10 additions & 9 deletions addons/shootingrange/functions/fnc_popupPFHexit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,25 @@
* 2: Controllers <ARRAY>
* 3: Name <STRING>
* 4: Targets <ARRAY>
* 5: Mode (1 = Time, 2 = Hit (Time Limited), 3 = Hit (Target Limited), 4 = Trigger) <NUMBER>
* 6: Success <BOOL>
* 7: Score <NUMBER> (default: 0)
* 8: Maximum Score <NUMBER> (default: 0)
* 9: Time Elapsed <NUMBER> (default: 0)
* 10: Triggers <ARRAY> (default: [])
* 5: Invalid Targets <ARRAY>
* 6: Mode (1 = Time, 2 = Hit (Time Limited), 3 = Hit (Target Limited), 4 = Trigger) <NUMBER>
* 7: Success <BOOL>
* 8: Score <NUMBER> (default: 0)
* 9: Maximum Score <NUMBER> (default: 0)
* 10: Time Elapsed <NUMBER> (default: 0)
* 11: Triggers <ARRAY> (default: [])
*
* Return Value:
* None
*
* Example:
* [idPFH, controller, [controller1, controller2], "range", [target1, target2], 1, true] call tac_shootingrange_fnc_popupPFHexit;
* [idPFH, controller, [controller1, controller2], "range", [target1, target2], [invalidTarget1, invalidTarget2], 1, true] call tac_shootingrange_fnc_popupPFHexit;
*
* Public: No
*/
#include "script_component.hpp"

params ["_idPFH", "_controller", "_controllers", "_name", "_targets", "_mode", "_success", ["_score", 0], ["_maxScore", 0], ["_timeElapsed", 0], ["_triggers", []] ];
params ["_idPFH", "_controller", "_controllers", "_name", "_targets", "_targetsInvalid", "_mode", "_success", ["_score", 0], ["_maxScore", 0], ["_timeElapsed", 0], ["_triggers", []] ];

// Remove PFH
[_idPFH] call CBA_fnc_removePerFrameHandler;
Expand All @@ -34,7 +35,7 @@ params ["_idPFH", "_controller", "_controllers", "_name", "_targets", "_mode", "
nopop = false;

// Finish or Stop
[_controller, _controllers, _name, _targets, _success, _score, _maxScore, _timeElapsed] call FUNC(stop);
[_controller, _controllers, _name, _targets, _targetsInvalid, _success, _score, _maxScore, _timeElapsed] call FUNC(stop);

// Cleanup variables
GVAR(targetNumber) = nil;
Expand Down
17 changes: 14 additions & 3 deletions addons/shootingrange/functions/fnc_setTargetGroups.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,55 @@
*
* Arguments:
* 0: Targets <ARRAY>
* 1: Markers <ARRAY>
* 1: Invalid Targets <ARRAY>
* 2: Markers <ARRAY>
*
* Return Value:
* None
*
* Example:
* [[target1, target2], [marker1, marker2]] call tac_shootingrange_fnc_setTargetGroups;
* [[target1, target2], [invalidTarget1, invalidTarget2], [marker1, marker2]] call tac_shootingrange_fnc_setTargetGroups;
*
* Public: No
*/
#include "script_component.hpp"

params ["_targets", "_markers"];
params ["_targets", "_targetsInvalid", "_markers"];

// Parse target groups
private _targetGroups = [];
private _targetInvalidGroups = [];
private _lastMarker = "";
private _currentTargetGroup = [];
private _currentTargetInvalidGroup = [];

{
if (_forEachIndex != 0 && {_x != _lastMarker}) then {
_targetGroups pushBack _currentTargetGroup;
_currentTargetGroup = [];
_targetInvalidGroups pushBack _currentTargetInvalidGroup;
_currentTargetInvalidGroup = [];
};

_currentTargetGroup pushBack (_targets select _forEachIndex);
_currentTargetInvalidGroup pushBack (_targetsInvalid select _forEachIndex);

if (_forEachIndex + 1 == count _markers) then {
_targetGroups pushBack _currentTargetGroup;
_targetInvalidGroups pushBack _currentTargetInvalidGroup;
};

_lastMarker = _x;
} forEach _markers;

TRACE_2("Target Groups",_targetGroups,_targetInvalidGroups);

// Set targets groups on targets
{
private _targetGroup = _x;
private _targetInvalidGroup = _targetInvalidGroups select _forEachIndex;
{
_x setVariable [QGVAR(targetGroup), _targetGroup];
_x setVariable [QGVAR(targetInvalidGroup), _targetInvalidGroup];
} forEach _x;
} forEach _targetGroups;
13 changes: 7 additions & 6 deletions addons/shootingrange/functions/fnc_start.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
#include "script_component.hpp"

params ["_controller", "_controllers", "_name", "_targets"];
params ["_controller", "_controllers", "_name", "_targets", "_targetsInvalid"];

private _duration = _controller getVariable [QGVAR(duration), nil];
private _targetAmount = _controller getVariable [QGVAR(targetAmount), nil];
Expand All @@ -32,7 +32,7 @@ if (isNil "_duration" || {isNil "_targetAmount"} || {isNil "_pauseDuration"} ||
// Prepare targets
{
[_x, 1] call FUNC(animateTarget); // Down
} forEach _targets;
} forEach (_targets + _targetsInvalid);

// Set variables
{
Expand Down Expand Up @@ -91,6 +91,7 @@ _text = format ["%1<br/><br/>%2: %3", _text, localize LSTRING(By), _playerName];
// Prepare variables
GVAR(targetNumber) = 0;
GVAR(maxScore) = [0, count _targets] select (_mode == 5);
GVAR(invalidTargetHit) = false;

if (_mode > 1) then {
if (_mode < 5) then {
Expand Down Expand Up @@ -131,7 +132,7 @@ if (_mode > 1) then {

// Start pop-up handling and final countdown notification
[{
params ["_controller", "_pauseDuration", "_duration", "_targetAmount", "_targets", "_controller", "_controllers", "_name", "_mode", "_triggers"];
params ["_controller", "_pauseDuration", "_duration", "_targetAmount", "_targets", "_targetsInvalid", "_controller", "_controllers", "_name", "_mode", "_triggers"];

// Exit if not running (eg. stopped)
if !(_controller getVariable [QGVAR(running), false]) exitWith {};
Expand All @@ -156,10 +157,10 @@ if (_mode > 1) then {
if (_mode == 5) then {
{
[_x, 0] call FUNC(animateTarget); // Up
} forEach _targets;
} forEach (_targets + _targetsInvalid);
};

// Start PFH
[FUNC(popupPFH), 0, [_timeStart, _duration, _pauseDuration, _targetAmount, _targets, _controller, _controllers, _name, _mode, _triggers]] call CBA_fnc_addPerFrameHandler;
[FUNC(popupPFH), 0, [_timeStart, _duration, _pauseDuration, _targetAmount, _targets, _targetsInvalid, _controller, _controllers, _name, _mode, _triggers]] call CBA_fnc_addPerFrameHandler;

}, [_controller, _pauseDuration, _duration, _targetAmount, _targets, _controller, _controllers, _name, _mode, _triggers], _countdownTime] call ACE_Common_fnc_waitAndExecute;
}, [_controller, _pauseDuration, _duration, _targetAmount, _targets, _targetsInvalid, _controller, _controllers, _name, _mode, _triggers], _countdownTime] call ACE_Common_fnc_waitAndExecute;
Loading