public void Add(List <Identifier> idents, string relPath) { var ident = idents.FirstOrDefault(); if (ident == null) { ExtraFiles.Add(relPath); return; } if (ident is SkinIdentifier skinId) { var skinIds = idents.Cast <SkinIdentifier>().ToList(); if (skinIds.Count > 1) { MultiSkinFiles.Add(relPath, skinIds); } else { Skins.Add(relPath, ident as SkinIdentifier); } } else if (ident is PortraitIdentifier) { Portraits.Add(relPath, idents.Cast <PortraitIdentifier>()); } else if (ident is CrosshairIdentifier) { Crosshairs.Add(relPath, idents.Cast <CrosshairIdentifier>()); } else if (ident is WeaponIdentifier) { Weapons.Add(relPath, idents.Cast <WeaponIdentifier>()); } else if (ident is EffectsIdentifier) { Effects.Add(relPath, idents.Cast <EffectsIdentifier>()); } else if (ident is CanopyIdentifier) { Canopies.Add(relPath, idents.Cast <CanopyIdentifier>()); } else if (ident is EmblemIdentifier) { Emblems.Add(relPath, idents.Cast <EmblemIdentifier>()); } else if (ident is CockpitIdentifier) { Cockpits.Add(relPath, idents.Cast <CockpitIdentifier>()); } }
private void BuildGraph() { var canopies = Canopies .Where(x => x.P1.X <= Destination.X && x.P1.Y <= Destination.Y) .ToArray(); Graph = new Graph(); for (int i = 1; i <= Math.Max(Start.X, Destination.X); i++) { for (int j = 1; j <= Math.Max(Start.Y, Destination.Y); j++) { Graph.AddVertex($"{i}:{j}"); } } for (int i = 1; i <= Math.Max(Start.X, Destination.X); i++) { for (int j = 1; j <= Math.Max(Start.Y, Destination.Y); j++) { var cost = GeneralCost; Canopy bestCanopy = null; var canopiesOver = canopies.Where(c => c.P1.X <= i && c.P2.X >= i && c.P1.Y <= j && c.P2.Y >= j); if (canopiesOver.Any()) { cost = canopiesOver.Min(x => x.Rate); bestCanopy = canopiesOver.FirstOrDefault(x => x.Rate == cost); } var currentVertex = $"{i}:{j}"; var bottomVertex = $"{i}:{j + 1}"; var rightVertex = $"{i + 1}:{j}"; var leftVertex = $"{i - 1}:{j}"; var topVertex = $"{i}:{j - 1}"; Graph.FindVertex(currentVertex).CanopyIndex = bestCanopy?.Index ?? 0; Graph.AddEdge(currentVertex, rightVertex, cost); // add edge to the rigtht Graph.AddEdge(currentVertex, bottomVertex, cost); // add edge to the bottom Graph.AddEdge(currentVertex, topVertex, cost); // add edge to the bottom Graph.AddEdge(currentVertex, leftVertex, cost); // add edge to the bottom } } FindPath(); }