public HumanPrefabMapping()
        {
            _helper = MonitorHelper.Instance;
            _data = HumanMonitorData.Instance;

            _mapping = new PrefabMapping<uint>();
        }
        private void CalculateMappingForLocation(ChassisLocations location, List <MechComponentRef> sortedComponentRefs)
        {
            var bestSelection     = new PrefabSelectionCandidate(GetAvailablePrefabSetsForLocation(location), new List <PrefabMapping>());
            var currentCandidates = new List <PrefabSelectionCandidate> {
                bestSelection
            };

            foreach (var componentRef in sortedComponentRefs)
            {
                var newCandidates = new List <PrefabSelectionCandidate>();
                foreach (var candidate in currentCandidates)
                {
                    var hasNew = false;
                    foreach (var set in candidate.Sets)
                    {
                        var prefabName = set.GetCompatiblePrefab(componentRef.Def.PrefabIdentifier);
                        if (prefabName == null)
                        {
                            //Control.mod.Logger.LogDebug("could not find prefabName for " + componentRef?.Def?.PrefabIdentifier);
                            continue;
                        }

                        var newMapping   = new PrefabMapping(prefabName, componentRef);
                        var newCandidate = candidate.CreateWithoutSet(set, newMapping);
                        newCandidates.Add(newCandidate);
                        hasNew = true;
                    }

                    if (!hasNew) // we didn't find anything better, so re-add the old one
                    {
                        newCandidates.Add(candidate);
                    }
                }

                currentCandidates = newCandidates;
            }

            foreach (var candidate in currentCandidates)
            {
                if (candidate.CompareTo(bestSelection) > 0)
                {
                    bestSelection = candidate;
                }
            }

            if (bestSelection.Mappings.Count < 1)
            {
                return;
            }

            var text = $"Mappings for chassis {chassisDef.Description.Id} at {location}";

            foreach (var mapping in bestSelection.Mappings)
            {
                text += $"\n{mapping.MechComponentRef.Def.Description.Id} {mapping.PrefabName}";
                cacheMappings[mapping.MechComponentRef] = mapping.PrefabName;
            }
            Control.mod.Logger.LogDebug(text);
        }
        public VehiclePrefabMapping()
        {
            _settings = Settings.Instance;
            _helper = Helper.Instance;
            _data = Data.Instance;

            _mapping = new PrefabMapping<ushort>();
        }
        public HumanPrefabMapping()
        {
            _settings = Settings.Instance;
            _helper = Helper.Instance;
            _data = Data.Instance;

            _mapping = new PrefabMapping<uint>();
        }
Beispiel #5
0
            internal PrefabSelectionCandidate CreateWithoutSet(PrefabSet exclude, PrefabMapping newMapping)
            {
                var sets     = FreeSets.Except(exclude);
                var mappings = new List <PrefabMapping>(Mappings)
                {
                    newMapping
                };

                return(new PrefabSelectionCandidate(sets, mappings));
            }
        public AnimalPrefabMapping()
        {
            _settings = Settings.Instance;
            _helper = Helper.Instance;
            _data = Data.Instance;

            _prefabs = new Dictionary<string, int>();
            LoadTrackedPrefabs();

            _mapping = new PrefabMapping<ushort>();
        }
    private void CalculateMappingForLocation(ChassisLocations location, List <MechComponentRef> sortedComponentRefs)
    {
        var availablePrefabSets = GetAvailablePrefabSetsForLocation(location);
        var bestSelection       = new PrefabSelectionCandidate(availablePrefabSets);

        Control.Logger.Debug?.Log($"CalculateMappingForLocation chassisDef={chassisDef.Description.Id} location={location} availablePrefabSets={availablePrefabSets.JoinAsString()} sortedComponentRefs=[{sortedComponentRefs.Select(x => x.ComponentDefID).JoinAsString()}]");

        foreach (var componentRef in sortedComponentRefs)
        {
            var prefabIdentifier = componentRef.Def.PrefabIdentifier;
            var compatibleTerms  = HardpointFixFeature.Shared.GetCompatiblePrefabTerms(prefabIdentifier);

            Control.Logger.Debug?.Log($" componentRef={componentRef.ComponentDefID} prefabIdentifier={prefabIdentifier} compatibleTerms={compatibleTerms.JoinAsString()}");

            foreach (var compatibleTerm in compatibleTerms)
            {
                var prefab = bestSelection.FreeSets
                             .Select(x => x.GetPrefabByIdentifier(compatibleTerm))
                             .FirstOrDefault(x => x != null);

                if (prefab == null)
                {
                    continue;
                }

                Control.Logger.Debug?.Log($"  prefab={prefab}");

                var newMapping = new PrefabMapping(prefab, componentRef);
                bestSelection = bestSelection.CreateWithoutPrefab(prefab, newMapping);

                break;
            }
        }
        fallbackPrefabs[location] = bestSelection.FreeSets;
        Control.Logger.Debug?.Log($"Mappings for chassis {chassisDef.Description.Id} at {location} [{bestSelection.Mappings.JoinAsString()}]");
        foreach (var mapping in bestSelection.Mappings)
        {
            weaponMappings[mapping.MechComponentRef] = mapping.Prefab.Name;
        }

        CalculateBlanksForLocation(location);
    }
Beispiel #8
0
    internal PrefabSelectionCandidate CreateWithoutPrefab(Prefab exclude, PrefabMapping newMapping)
    {
        var blacklistedPrefabNames = FreeSets
                                     .Where(x => x.ContainsPrefab(exclude))
                                     .SelectMany(x => x)
                                     .Select(x => x.Name)
                                     .ToHashSet();

        var sets = FreeSets
                   .Select(x => x.CreateWithoutPrefabNames(blacklistedPrefabNames))
                   .Where(x => !x.IsEmpty)
                   .ToList();

        var mappings = new List <PrefabMapping>(Mappings)
        {
            newMapping
        };

        return(new PrefabSelectionCandidate(sets, mappings));
    }
Beispiel #9
0
        private void CalculateMappingForLocation(ChassisLocations location, List <MechComponentRef> sortedComponentRefs)
        {
            //Control.mod.Logger.LogDebug($"CalculateMappingForLocation chassisDef={chassisDef.Description.Id} location={location} sortedComponentRefs=[{sortedComponentRefs.Select(x => x.ComponentDefID).JoinAsString()}]");

            var bestSelection     = new PrefabSelectionCandidate(GetAvailablePrefabSetsForLocation(location), new List <PrefabMapping>());
            var currentCandidates = new List <PrefabSelectionCandidate> {
                bestSelection
            };

            foreach (var componentRef in sortedComponentRefs)
            {
                // Control.mod.Logger.LogDebug($" componentRef={componentRef.ComponentDefID}");

                var newCandidates = new List <PrefabSelectionCandidate>();
                foreach (var candidate in currentCandidates)
                {
                    //Control.mod.Logger.LogDebug($"  candidate={candidate}");

                    var hasNew = false;
                    foreach (var set in candidate.FreeSets)
                    {
                        //Control.mod.Logger.LogDebug($"   set={set}");

                        var prefabName = set.GetCompatiblePrefab(componentRef.Def.PrefabIdentifier);
                        if (prefabName == null)
                        {
                            continue;
                        }

                        var newMapping   = new PrefabMapping(prefabName, componentRef);
                        var newCandidate = candidate.CreateWithoutSet(set, newMapping);
                        newCandidates.Add(newCandidate);
                        hasNew = true;
                    }

                    if (!hasNew) // we didn't find anything better, so re-add the old one
                    {
                        newCandidates.Add(candidate);
                    }
                }

                currentCandidates = newCandidates;
            }

            foreach (var candidate in currentCandidates)
            {
                if (candidate.CompareTo(bestSelection) > 0)
                {
                    bestSelection = candidate;
                }
            }

            if (bestSelection.Mappings.Count < 1)
            {
                return;
            }

            Control.mod.Logger.LogDebug($"Mappings for chassis {chassisDef.Description.Id} at {location} [{bestSelection.Mappings.JoinAsString()}]");
            foreach (var mapping in bestSelection.Mappings)
            {
                cacheMappings[mapping.MechComponentRef] = mapping.PrefabName;
            }
        }