Adds loads of useless debugging output
M ineptifex/fn_addContactReports.sqf +18 -16
@@ 38,22 38,24 @@ LOGVAR(count _current_contacts);
 }
 forEach _new_contacts;
 
-
-LOGVAR(count _current_contacts);
+if (LOGGING_ENABLED()) then
 {
-    diag_log (format [
-            "Contact: %1 (%2)",
-            (_x select CONTACT_INFO) select UNIT_INFO_CLASS,
-            (_x select CONTACT_POS)
-            ]);
-    diag_log (
-        [
-            (_x select CONTACT_INFO) select UNIT_INFO_CARGO,
-            {_x select UNIT_INFO_CLASS}
-        ]
-        call INEPT_fnc_applyToAll
-        );
-}
-forEach (_ao select AO_CONTACTS);
+    LOGVAR(count _current_contacts);
+    {
+        diag_log (format [
+                "Contact: %1 (%2)",
+                (_x select CONTACT_INFO) select UNIT_INFO_CLASS,
+                (_x select CONTACT_POS)
+                ]);
+        diag_log (
+            [
+                (_x select CONTACT_INFO) select UNIT_INFO_CARGO,
+                {_x select UNIT_INFO_CLASS}
+            ]
+            call INEPT_fnc_applyToAll
+            );
+    }
+    forEach _current_contacts;
+};
 
 MUTEX_UNLOCK(_ao select AO_CONTACTS_MUTEX);

          
M ineptifex/fn_correlateContact.sqf +21 -7
@@ 27,10 27,18 @@ params [ "_contacts"
        , "_time"
        , ["_given_mobility", 0] ];
 
-LOGVAR(_contacts);
-LOGVAR(_classname);
-LOGVAR(_position);
-LOGVAR(_time);
+if (LOGGING_ENABLED()) then
+{
+    LOGVAR(count _contacts);
+    {
+        LOGVAR(_x select CONTACT_INFO select UNIT_INFO_CLASS);
+        LOGVAR(_x select CONTACT_INFO select UNIT_INFO_CARGO);
+    }
+    forEach _contacts;
+    LOGVAR(_classname);
+    LOGVAR(_position);
+    LOGVAR(_time);
+};
 
 VAR(_closest_path) = NEW_PAIR(-1, -1);
 VAR(_closest_value) = 0;

          
@@ 45,7 53,11 @@ VAR(_closest_value) = 0;
         VAR(_mobility) = (_con select CONTACT_MOBILITY) max _given_mobility;
         VAR(_dist) = _position distance (_con select CONTACT_POS);
         VAR(_time_elapsed) = _time - (_con select CONTACT_LASTSEEN);
-        VAR(_r) = _dist - (100 * _mobility * _time_elapsed / 60);
+        // For the purposes of correlation, we are liberal with mobility
+        // measurements. It's better to make false correlations than to not
+        // make a correlation where one ought to be.
+        // And sometimes things move faster than we might expect.
+        VAR(_r) = _dist - (1.5 * 100 * _mobility * _time_elapsed / 60);
         LOGVAR(_dist);
         LOGVAR(_mobility);
         LOGVAR(_time_elapsed);

          
@@ 65,15 77,17 @@ VAR(_closest_value) = 0;
         {
             VAR(_cnt_idx) = _forEachIndex;
             {
+                // Holy fucking code dupe, batman
                 VAR(_cargo_info) = _x;
+                LOGVAR(_cargo_info);
                 if (
                     (_cargo_info select UNIT_INFO_CLASS) isEqualTo _classname
                     ) then
                 {
-                    VAR(_mobility) = _con select CONTACT_MOBILITY;
+                    VAR(_mobility) = (_con select CONTACT_MOBILITY) max _given_mobility;
                     VAR(_dist) = _position distance (_con select CONTACT_POS);
                     VAR(_time_elapsed) = _time - (_con select CONTACT_LASTSEEN);
-                    VAR(_r) = _dist - (100 * _mobility * _time_elapsed / 60);
+                    VAR(_r) = _dist - (1.5 * 100 * _mobility * _time_elapsed / 60);
                     LOGVAR(_dist);
                     LOGVAR(_mobility);
                     LOGVAR(_time_elapsed);

          
M ineptifex/fn_getUnitInfo.sqf +1 -0
@@ 172,4 172,5 @@ if (_include_cargo == UNIT_INFO_WITH_CAR
     };
 };
 
+LOGVAR(_info);
 _info

          
M ineptifex/fn_internalAddContactReports.sqf +23 -8
@@ 41,6 41,27 @@ LOGENTRY();
         ] call INEPT_fnc_correlateContact;
 
     LOGVAR(_correlation);
+
+    if (LOGGING_ENABLED()) then
+    {
+        LOGVAR(count _current_contacts);
+        {
+            diag_log (format [
+                    "Contact: %1 (%2)",
+                    (_x select CONTACT_INFO) select UNIT_INFO_CLASS,
+                    (_x select CONTACT_POS)
+                    ]);
+            diag_log (
+                [
+                    (_x select CONTACT_INFO) select UNIT_INFO_CARGO,
+                    {_x select UNIT_INFO_CLASS}
+                ]
+                call INEPT_fnc_applyToAll
+                );
+        }
+        forEach _current_contacts;
+    };
+
     VAR(_contact_idx) = _correlation select PAIR_FIRST;
     if (_contact_idx == -1) then
     {

          
@@ 83,7 104,7 @@ LOGENTRY();
                         NEW_CONTACT(_new_contact select CONTACT_POS,
                                     _x,
                                     _correlated_contact select CONTACT_LASTSEEN,
-                                    [_x select UNIT_INFO_CLASS] call INEPT_fnc_getMobility);
+                                    (_correlated_contact select CONTACT_MOBILITY) max ([_x select UNIT_INFO_CLASS] call INEPT_fnc_getMobility));
                 }
                 forEach _old_cargo;
 

          
@@ 111,16 132,10 @@ LOGENTRY();
             else 
             {
                 VAR(_correlated_contact) = _current_contacts select _contact_idx;
+                LOGVAR(_correlated_contact);
                 ((_correlated_contact select CONTACT_INFO) select UNIT_INFO_CARGO) deleteAt _cargo_idx
             };
 
-        // This is done to avoid suddenly changing the equipment (and therefore
-        // firepower) of vehicles for which we are guessing the contents of
-        // (which happens) to be all of our contacts I guess. (TODO, this is a
-        // bad assumption!)
-        // It would really be a lot better if our arguments did not contain
-        // full unit info, and instead we could ask a thing to produce that
-        // info if we so desired.
         (_new_contact select CONTACT_INFO) set
             [ UNIT_INFO_EQUIPMENT
             , _correlated_info select UNIT_INFO_EQUIPMENT ];

          
M tests/test_cargoCorrelation.sqf +46 -12
@@ 18,7 18,7 @@ VAR(__assert_equal) =
     VAR(_lhv) = call _lh;
     VAR(_rhv) = call _rh;
     if (_lhv isEqualTo _rhv) then
-    { 
+    {
         diag_log format ["PASS:%1 - %2 == %3", _line + 1, _lh, _rh];
     }
     else

          
@@ 33,7 33,7 @@ VAR(__assert_equal) =
 VAR(__assert) =
 {
     if (call _this) then
-    { 
+    {
         diag_log format ["PASS:%1 - %2", __LINE__ + 1, _this];
     }
     else

          
@@ 84,7 84,7 @@ VAR(__test) =
             , [ (_x select CONTACT_INFO) select UNIT_INFO_CARGO
               , {_x select UNIT_INFO_CLASS} ] call INEPT_fnc_applyToAll
             ];
-    } 
+    }
     forEach (_ao select AO_CONTACTS);
     _results
 };

          
@@ 153,27 153,29 @@ try
 //deleteVehicle _crewman;
 //deleteVehicle _apc;
 
-#define HUMMINGBIRD "B_Heli_Light_01_armed_F"
-#define DUDEMAN     "B_soldier_AR_F"
+#define PAWNEE  "B_Heli_Light_01_armed_F"
+#define DUDEMAN "B_soldier_AR_F"
 
-VAR(_pilot) = (createGroup west) createUnit    [DUDEMAN,     [0, 0, 0], [], 0, "CAN_COLLIDE"];
-VAR(_helo) =                     createVehicle [HUMMINGBIRD, [0, 0, 0], [], 0, "CAN_COLLIDE"];
+VAR(_pilot) =   (createGroup west) createUnit    [DUDEMAN, [0, 0, 0], [], 0, "CAN_COLLIDE"];
+VAR(_copilot) = (createGroup west) createUnit    [DUDEMAN, [0, 0, 0], [], 0, "CAN_COLLIDE"];
+VAR(_helo) =                       createVehicle [PAWNEE,  [0, 0, 0], [], 0, "CAN_COLLIDE"];
 
-// Pilot is flying helicopter at 0, 0, 0
+// Pilot is flying helicopter with copilot at 0, 0, 0
 _pilot moveInAny _helo;
+_copilot moveInAny _helo;
 
 [ __LINE__
-, {[[HUMMINGBIRD, [DUDEMAN]]]}
+, {[[PAWNEE, [DUDEMAN, DUDEMAN]]]}
 , {[[_helo], _start_time + 0] call __test}
 ] call __assert_equal;
 
 // In 6 seconds, pilot can walk only about 25 metres, but he flew 40 meters and
 // then got out.
 [_helo, [40, 0, 0]] call __translate;
-moveOut _pilot; 
+moveOut _pilot;
 
 [ __LINE__
-, {[[HUMMINGBIRD, []], [DUDEMAN, []]]}
+, {[[PAWNEE, [DUDEMAN]], [DUDEMAN, []]]}
 , {[[_helo, _pilot], _start_time + 6] call __test}
 ] call __assert_equal;
 

          
@@ 183,10 185,42 @@ moveOut _pilot;
 [_helo, [40, 0, 0]] call __translate;
 
 [ __LINE__
-, {[[HUMMINGBIRD, [DUDEMAN]]]}
+, {[[PAWNEE, [DUDEMAN, DUDEMAN]]]}
 , {[[_helo], _start_time + 12] call __test}
 ] call __assert_equal;
 
+// Everybody gets out
+moveOut _pilot;
+moveOut _copilot;
+
+[ __LINE__
+, {[[DUDEMAN, []], [DUDEMAN, []], [PAWNEE, []]]}
+, {[[_helo], _start_time + 18] call __test}
+] call __assert_equal;
+
+// He moves again and blows up I guess?
+_pilot moveInAny _helo;
+_copilot moveInAny _helo;
+
+[ __LINE__
+, {[[PAWNEE, [DUDEMAN, DUDEMAN]]]}
+, {[[_helo], _start_time + 24] call __test}
+] call __assert_equal;
+
+[_helo, [40, 0, 0]] call __translate;
+_helo setDamage 1;
+
+sleep 0.1;
+
+{not alive _helo} call __assert;
+{not alive _pilot} call __assert;
+{not alive _copilot} call __assert;
+
+[ __LINE__
+, {[]}
+, {[[_helo], _start_time + 30] call __test}
+] call __assert_equal;
+
 deleteVehicle _pilot;
 deleteVehicle _helo;