public static void ReturnVehicle(ContractHelper contract, Vehicle vehicle, MechDef mech)
        {
            var vid  = vehicle.VehicleDef.Description.Id;
            var vdef = vehicle.VehicleDef;

            if (vdef == null)
            {
                Control.Instance.LogError("No vehicledef for return");
            }

            ReturnParts(contract, vehicle, mech);
            var chance = Control.Instance.Settings.ModuleRecoveryChance;

            foreach (var component in vehicle.VehicleDef.Inventory)
            {
                var rnd = CustomShops.Control.State.Sim.NetworkRandom.Float();

                if (component.DamageLevel != ComponentDamageLevel.Destroyed)
                {
                    if (rnd < chance)
                    {
                        Control.Instance.LogDebug(DInfo.Salvage, "-- {1:0.00}<{2:0.00}, recovered {0}", component.ComponentDefID, rnd, chance);
                        contract.AddComponentToFinalSalvage(component.Def);
                    }
                    else
                    {
                        Control.Instance.LogDebug(DInfo.Salvage, "-- {1:0.00}>{2:0.00}, destroyed {0}", component.ComponentDefID, rnd, chance);
                    }
                }
                else
                {
                    Control.Instance.LogDebug(DInfo.Salvage, "-- {0}, DESTROYED", component.ComponentDefID);
                }
            }
        }
        private static void SalvageParts(ContractHelper contract, Vehicle vehicle, MechDef mech)
        {
            if (!string.IsNullOrEmpty(Control.Instance.Settings.NoVehiclePartsTag))
            {
                if (vehicle.VehicleDef.VehicleTags.Contains(Control.Instance.Settings.NoVehiclePartsTag))
                {
                    Control.Instance.LogDebug(DInfo.Salvage, "Salvaging {0} - no parts by tags", mech.Description.Id);
                    return;
                }
            }

            var simgame = contract.Contract.BattleTechGame.Simulation;
            var parts   = NumParts(vehicle, simgame);

            if (string.IsNullOrEmpty(CustomSalvage.Control.Instance.Settings.NoSalvageVehicleTag) || !vehicle.VehicleDef.VehicleTags.Contains(CustomSalvage.Control.Instance.Settings.NoSalvageVehicleTag))
            {
                contract.AddMechPartsToPotentialSalvage(simgame.Constants, mech, parts);
            }
        }
        public static bool ProcessPlayerVehicle(UnitResult unitResult, ContractHelper Contract)
        {
            var mech = unitResult.mech;

            if (Control.Instance.Settings.LostVehicleAction == PlayerVehicleAction.None)
            {
                Control.Instance.LogDebug(DInfo.Salvage, $"- None action for player vehicle, skipping");
                return(true);
            }

            var original = UnityGameInstance.BattleTechGame.DataManager.MechDefs.Get(mech.Description.Id);

            if (!original.IsVehicle())
            {
                Control.Instance.LogDebug(DInfo.Salvage, $"- {mech.Description.Id} with GUID {mech.GUID} is not vehicle, return to mech process");
                return(true);
            }


            //Control.Instance.LogDebug(DInfo.Salvage, "Found vehicle {0}, guid:[{1}]", mech.Description.Id, mech.GUID);
            //Control.Instance.LogDebug(DInfo.Salvage, "-- all units:");
            //foreach (var actor in Contract.Contract.BattleTechGame.Combat.AllActors)
            //{
            //    string unit_guid = "";
            //    if (actor is Vehicle v)
            //        unit_guid = v.VehicleDef.GUID;
            //    else if (actor is Mech m)
            //        unit_guid = m.MechDef.GUID;


            //    Control.Instance.LogDebug(DInfo.Salvage, "{0}/{5}({3}/{6}): {2}[{1}] - {4}", actor.GUID, actor.Description.Id, actor.DisplayName, actor.UnitType, actor.DeathMethod, unit_guid, actor.Type.ToString());
            //}

            Control.Instance.LogDebug(DInfo.Salvage, "-- vehicles:");
            Vehicle vehicle = null;

            foreach (var v in Contract.Contract.BattleTechGame.Combat.AllActors.OfType <Vehicle>())
            {
                //Control.Instance.LogDebug(DInfo.Salvage, "{0}/{5}({3}/{6}): {2}[{1}] - {4}", v.GUID, v.Description.Id, v.DisplayName, v.UnitType, v.DeathMethod, v.VehicleDef.GUID, v.Type.ToString());
                if (v.VehicleDef.GUID == mech.GUID)
                {
                    vehicle = v;
                    break;
                }
            }

            if (vehicle == null)
            {
                Control.Instance.LogError($"Vehicle {mech.Description.Id} with GUID {mech.GUID} not found, return vehicle to player fallback");
                unitResult.mechLost = false;
                return(false);
            }

            unitResult.mechLost = !CanRecover(vehicle);
            if (unitResult.mechLost)
            {
                switch (Control.Instance.Settings.LostVehicleAction)
                {
                case PlayerVehicleAction.Salvage:
                    SalvageVehicle(Contract, vehicle, mech);
                    break;

                case PlayerVehicleAction.Return:
                    ReturnVehicle(Contract, vehicle, mech);
                    break;

                case PlayerVehicleAction.SalvageParts:
                    SalvageParts(Contract, vehicle, mech);
                    break;

                case PlayerVehicleAction.ReturnParts:
                    ReturnParts(Contract, vehicle, mech);
                    break;
                }
            }

            return(false);
        }