internal bool CanBeFielded(MechDef mechDef)
        {
            var weapons_per_location = mechDef.Inventory
                                       .Select(i => new { location = i.MountedLocation, item = i, wcat = i.GetWeaponCategory() })
                                       .Where(i => !i.wcat.Is_NotSet)

                                       .GroupBy(i => i.location)
                                       .Select(i => new { location = i.Key, items = i.ToList() })
                                       .ToList();


            foreach (var w_location in weapons_per_location)
            {
                var hardpoints = mechDef.GetAllHardpoints(w_location.location, mechDef.Inventory.ToInvItems());

                foreach (var recrd in w_location.items)
                {
                    if (HardpointsByID.TryGetValue(recrd.wcat.ID, out var hpInfo))
                    {
                        var nearest = hardpoints.FirstOrDefault(i => i.Total > i.Used && i.hpInfo.CompatibleID.Contains(hpInfo.WeaponCategory.ID));
                        if (nearest != null)
                        {
                            nearest.Used += 1;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
        public static List <HPUsage> GetHardpointUsage(this MechDef mech, ChassisLocations location, IEnumerable <InvItem> inventory = null)
        {
            if (inventory == null)
            {
                inventory = mech.Inventory.ToInvItems();
            }
            var inv = inventory.ToList();

            var result = mech.GetAllHardpoints(location, inv);

            foreach (var item in inv.Where(i => i.Location == location)
                     .Select(i => i.Item.GetComponent <UseHardpointCustom>())
                     .Where(i => i != null && !i.WeaponCategory.Is_NotSet))
            {
                HPUsage first = null;
                bool    found = false;

                for (int i = 0; i < result.Count; i++)
                {
                    var hp = result[i];

                    if (!hp.hpInfo.CompatibleID.Contains(item.WeaponCategory.ID))
                    {
                        continue;
                    }
                    if (hp.Used < hp.Total)
                    {
                        found    = true;
                        hp.Used += 1;
                    }

                    first ??= hp;
                }

                if (!found)
                {
                    if (first == null)
                    {
                        result.Add(new HPUsage(item.hpInfo, 0, -1));
                    }
                    else
                    {
                        first.Used += 1;
                    }
                }
            }

            return(result);
        }
        public void ValidateMech(Dictionary <MechValidationType, List <Text> > errors, MechValidationLevel validationlevel, MechDef mechdef)
        {
            var weapons_per_location = mechdef.Inventory
                                       .Select(i => new { location = i.MountedLocation, item = i, wcat = i.GetWeaponCategory() })
                                       .Where(i => !i.wcat.Is_NotSet)

                                       .GroupBy(i => i.location)
                                       .Select(i => new { location = i.Key, items = i.ToList() })
                                       .ToList();

            foreach (var w_location in weapons_per_location)
            {
                var hardpoints = mechdef.GetAllHardpoints(w_location.location, mechdef.Inventory.ToInvItems());

                foreach (var recrd in w_location.items)
                {
                    if (HardpointsByID.TryGetValue(recrd.wcat.ID, out var hpInfo))
                    {
                        var nearest = hardpoints.FirstOrDefault(i => i.Total > i.Used && i.hpInfo.CompatibleID.Contains(hpInfo.WeaponCategory.ID));
                        if (nearest != null)
                        {
                            nearest.Used += 1;
                        }
                        else
                        {
                            errors[MechValidationType.InvalidInventorySlots].Add(new Localize.Text(
                                                                                     Control.Settings.Message.Base_AddNotEnoughHardpoints,
                                                                                     mechdef.Description.UIName, recrd.item.Def.Description.Name,
                                                                                     recrd.item.Def.Description.UIName,
                                                                                     recrd.wcat.Name, recrd.wcat.FriendlyName,
                                                                                     w_location.location
                                                                                     ));
                        }
                    }
                }
            }
        }