ALiVEOS / ALiVE.OS

ALiVE Open Source GPL v2
http://alivemod.com/
Other
160 stars 80 forks source link

[mil_OPCOM] Multiple bug fixes #787

Closed ttrebuchon closed 1 year ago

ttrebuchon commented 1 year ago

1. Fix typo from "mechandized" to "mechanized".

2. Reset "_rtb" to nil if no air profiles are available

3. Fix the synchronizeorders function so that it is possible for it to return true

See annotated (old) code below:

private _ordersToRemove = [];
{
    _x params ["_pos","_profileID","_objectiveID","_time"];

    private _dead = isnil { [ALiVE_profileHandler,"getProfile", _profileID] call ALiVE_fnc_profileHandler };
    private _timeout = (time - _time) > 3600;

    if (_dead || { _timeout } || { _ProfileID == _ProfileIDInput }) then {
        _ordersToRemove pushback _foreachindex;

        //  ***************HERE***************
        // It checks to see if there are any more orders for this objective, 
        // but this one (in_x variable) hasn't been deleted yet, 
        // so this will always find and return the index of the current value.
        //  **********************************

        private _objectiveFound = _pendingOrders findIf { _objectiveID == (_x select 2) };
        if (_objectiveFound == -1) then {
            _synchronized = true; 
        };
    };
} foreach _pendingOrders;

[_pendingOrders, _ordersToRemove] call ALiVE_fnc_deleteAtMany;

The check needed to occur after the ALiVE_fnc_deleteAtMany call for this to work.

While writing this PR, I noticed something else. Is "synchronizeorders" supposed to return true even if a different objective is synchronized due to the _dead || { _timeout } condition? Even if the objective of the profileId specified as an argument still has pending orders?

If this is a mistake, I can further optimize this code to only check a single objective after deletion, rather than looping through an array of objective ids.

DarrellJMartin commented 1 year ago

Merged for public testing

Azraeel commented 1 year ago

@ttrebuchon yo are you around to possibly accept an invite to an alive contributor discord?