private HardpointDataDef._WeaponHardpointData GetWeaponData(ChassisLocations location) { var locationString = VHLUtils.GetStringFromLocation(location); var weaponsData = chassisDef.HardpointDataDef.HardpointData.FirstOrDefault(x => x.location == locationString); return(weaponsData); }
private PrefabSets GetAvailablePrefabSetsForLocation(ChassisLocations location) { var locationString = VHLUtils.GetStringFromLocation(location); var weaponsData = chassisDef.HardpointDataDef.HardpointData.FirstOrDefault(x => x.location == locationString); var sets = new PrefabSets(); if (weaponsData.weapons == null) { //Control.mod.Logger.LogDebug($"no hardpoint data found for {chassisDef.Description.Id} at {location}"); } else { foreach (var weapons in weaponsData.weapons) { var index = sets.Count; try { var set = new PrefabSet(index, weapons); sets.Add(set); } catch (Exception e) { Control.mod.Logger.LogDebug($"error processing hardpoint data for {chassisDef.Description.Id} at {location}: index={index} weapons=[{weapons?.JoinAsString()}]", e); throw; } } } return(sets); }
private List <string> GetAvailablePrefabNamesForLocation(ChassisLocations location) { var hardpointDatas = chassisDef.HardpointDataDef.HardpointData .Where(x => x.location == VHLUtils.GetStringFromLocation(location)); // SelectMany with string[][] crashes if compiled with Mono.CSharp (2.1.0.0) for Unity, newer Mono and VS compilers are fine var hpsets = new List <string[]>(); foreach (var hardpointData in hardpointDatas) { foreach (var hpset in hardpointData.weapons) { hpsets.Add(hpset); } } return(hpsets .Where(hpset => !hpset.Intersect(mapping.Values).Any()) // only include hardpoint sets not yet used // commented out code not required, instead of filling the least used, we get the complete weapons list and sort by weapon sizes and fill from nicest index to ugliest index //.Select(hpset => RemoveUnwantedHardpoints(location, hpset)) // that allows our length order to work better //.OrderBy(hpset => hpset.Length) // sort hardpoints by how many weapon types are supported (use up the ones with less options first) - no -> use index order, lower index = nicer looking .SelectMany(hpset => hpset) // we don't care about groups anymore, just flatten everything into one stream .ToList()); }