Esempio n. 1
0
        private static double PercentageObjectsKnown(MapFile mf, VFS vfs, IniFile rules, TheaterSettings ths)
        {
            if (rules == null || ths == null)
            {
                return(0.0);
            }
            var theaterIni = vfs.OpenFile <IniFile>(ths.TheaterIni);

            if (theaterIni == null)
            {
                return(0.0);
            }

            Func <MapObject, IniFile.IniSection, bool> objectKnown = (obj, section) => {
                if (obj is NamedMapObject)
                {
                    string name = (obj as NamedMapObject).Name;
                    return(section.OrderedEntries.Any(kvp => kvp.Value.ToString().Equals(name, StringComparison.InvariantCultureIgnoreCase)));
                }
                else if (obj is NumberedMapObject)
                {
                    int number = (obj as NumberedMapObject).Number;
                    return(section.HasKey(number.ToString()));
                }
                return(false);                // should not happen
            };

            int known = 0;
            int total = 0;

            var tiles           = mf.Tiles.Where(t => t != null).DistinctBy(t => t.TileNum);
            var tilesCollection = new TileCollection(ths, vfs.OpenFile <IniFile>(ths.TheaterIni));

            tilesCollection.InitTilesets();
            known += mf.Tiles.Count(o => o.TileNum <= tilesCollection.NumTiles);
            total += mf.Tiles.Count();

            var infs = mf.Infantries.DistinctBy(o => o.Name);

            known += infs.Count(o => objectKnown(o, rules.GetSection("InfantryTypes")));
            total += infs.Count();

            var terrains = mf.Infantries.DistinctBy(o => o.Name);

            known += terrains.Count(o => objectKnown(o, rules.GetSection("TerrainTypes")));
            total += terrains.Count();

            var units = mf.Infantries.DistinctBy(o => o.Name);

            known += units.Count(o => objectKnown(o, rules.GetSection("VehicleTypes")));
            total += units.Count();

            var aircrafts = mf.Aircrafts.DistinctBy(o => o.Name);

            known += aircrafts.Count(o => objectKnown(o, rules.GetSection("AircraftTypes")));
            total += aircrafts.Count();

            var smudges = mf.Smudges.DistinctBy(o => o.Name);

            known += smudges.Count(o => objectKnown(o, rules.GetSection("SmudgeTypes")));
            total += smudges.Count();

            var structures = mf.Structures.DistinctBy(o => o.Name);

            known += structures.Count(o => objectKnown(o, rules.GetSection("BuildingTypes")) ||
                                      objectKnown(o, rules.GetSection("OverlayTypes")));
            total += structures.Count();

            var overlays = mf.Overlays.DistinctBy(o => o.Number);

            known += overlays.Count(o => objectKnown(o, rules.GetSection("OverlayTypes")));
            total += overlays.Count();


            return(known / (double)total);
        }