Skip to content

Commit

Permalink
Sites: Refactor and improve performance for 'stolen objects' soft lock.
Browse files Browse the repository at this point in the history
  • Loading branch information
dijksterhuis committed Oct 8, 2024
1 parent dec52c4 commit 46f90a4
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 46 deletions.
1 change: 1 addition & 0 deletions mission/config/functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ class CfgFunctions
class sites_init {};
class sites_load {};
class sites_teardown_site {};
class sites_check_standard_site_completed {};

//Specific types of site
class sites_create_aa_site {};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
File: fn_sites_check_standard_site_completed.sqf
Author: @dijksterhuis
Public: Yes
Description:
Standardised check for whether a site should be considered completed or not.
'Standardised' here basically means typical Mike Force sites where players need
to clear/destroy/spike certain objects to complete that site and progress.
The check also covers the case where a player has picked up a mortar/ZPU object
and walked away from the site with the advanced logistics module. Or some 'arma'
happened, yeeting the object away from the site.
Parameter(s):
* _objectsToCheck -- [ARRAY]: the objects in the site whose presence
needs to be checked
* _centrepointObjectOrPos -- [OBJECT/POSITION]: centrepoint for the area search.
either an object (usually the _siteStore simple
object), or a position array
* _checkRadius -- [NUMBER]: how far away from the site do we need to
check for the objects before considering them
"gone".
* _checkIsRectangle -- [BOOL]: whether the search area is an ellipse
(default) or rectangular
Returns:
true if site is completed, false otherwise
Example(s):
// circular area search using _storeStore object as centre
[
_siteStore getVariable ["aaGuns", []],
_siteStore,
20
] call vn_mf_fnc_sites_check_standard_site_completed;
// circular area search using some other position as centre
[
_siteStore getVariable ["staticMgs", []],
[0, 0, 0],
10,
false
] call vn_mf_fnc_sites_check_standard_site_completed;
// rectangular area search
[
_siteStore getVariable ["mortars", []],
_siteStore,
5,
true
] call vn_mf_fnc_sites_check_standard_site_completed;
*/

params [
"_objectsToCheck",
"_centrepointObjectOrPos",
"_checkRadius",
["_checkIsRectangle", false]
];

private _objectsInArea = _objectsToCheck inAreaArray [
_centrepointObjectOrPos,
_checkRadius,
_checkRadius,
0,
false
];

_objectsInArea findIf {alive _x} == -1;
20 changes: 5 additions & 15 deletions mission/functions/systems/sites/fn_sites_create_aa_site.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,11 @@ params ["_pos"];
//Teardown condition
{
params ["_siteStore"];

private _pos = getPos _siteStore;
private _objects = _siteStore getVariable ["aaGuns", []];

/*
Teardown when all guns are either
- destroyed
- no longer with 20m radius of site centre point
*/

private _objectsAreAliveInRadius = _objects findIf {
(alive _x) && (count ([_x] inAreaArray [_pos, 20, 20, 0, false]) > 0)
};

_objectsAreAliveInRadius == -1
[
_siteStore getVariable ["aaGuns", []],
_siteStore,
20
] call vn_mf_fnc_sites_check_standard_site_completed;
},
//Teardown code
{
Expand Down
20 changes: 5 additions & 15 deletions mission/functions/systems/sites/fn_sites_create_artillery_site.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,11 @@ params ["_pos"];
//Teardown condition
{
params ["_siteStore"];

private _pos = getPos _siteStore;
private _objects = _siteStore getVariable ["mortars", []];

/*
Teardown when all guns are either
- destroyed
- no longer with 20m radius of site cetnre point
*/

private _objectsAreAliveInRadius = _objects findIf {
(alive _x) && (count ([_x] inAreaArray [_pos, 20, 20, 0, false]) > 0)
};

_objectsAreAliveInRadius == -1
[
_siteStore getVariable ["mortars", []],
_siteStore,
20
] call vn_mf_fnc_sites_check_standard_site_completed;
},
//Teardown code
{
Expand Down
21 changes: 5 additions & 16 deletions mission/functions/systems/sites/fn_sites_create_hq.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,11 @@ params ["_pos"];
//Teardown condition
{
params ["_siteStore"];

private _pos = getPos _siteStore;
private _radius = _siteStore getVariable ["siteRadius", 50];
private _objects = _siteStore getVariable ["objectsToDestroy", []];

/*
Teardown when all ammo crates are either
- destroyed
- no longer within radius of site
*/

private _objectsAreAliveInRadius = _objects findIf {
(alive _x) && (count ([_x] inAreaArray [_pos, _, _radius, 0, false]) > 0)
};

_objectsAreAliveInRadius == -1
[
_siteStore getVariable ["objectsToDestroy", []],
_siteStore,
_siteStore getVariable ["siteRadius", 50]
] call vn_mf_fnc_sites_check_standard_site_completed;
},
//Teardown code
{
Expand Down

0 comments on commit 46f90a4

Please sign in to comment.