Ejemplo n.º 1
0
		private static EngineType DetectEngineFromRules(MapFile mf,
			IniFile rulesTS, IniFile rulesFS, IniFile rulesRA2, IniFile rulesYR,
			TheaterSettings theaterTS, TheaterSettings theaterFS, TheaterSettings theaterRA2, TheaterSettings theaterYR,
			VFS vfsTS, VFS vfsFS, VFS vfsRA2, VFS vfsYR) {

			double tsScore = PercentageObjectsKnown(mf, vfsTS, rulesTS, theaterTS);
			double fsScore = PercentageObjectsKnown(mf, vfsFS, rulesFS, theaterFS);
			double ra2Score = PercentageObjectsKnown(mf, vfsRA2, rulesRA2, theaterRA2);
			double yrScore = PercentageObjectsKnown(mf, vfsYR, rulesYR, theaterYR);

			double maxScore = Math.Max(Math.Max(Math.Max(tsScore, fsScore), ra2Score), yrScore);
			if (maxScore == ra2Score) return EngineType.RedAlert2;
			else if (maxScore == yrScore) return EngineType.YurisRevenge;
			else if (maxScore == tsScore) return EngineType.TiberianSun;
			else if (maxScore == fsScore) return EngineType.Firestorm;
			return EngineType.YurisRevenge; // default
		}
Ejemplo n.º 2
0
		public static bool SetActiveTheater(TheaterType theater) {
			ActiveTheater = ActiveConfig.Theaters.First(t => t.Type == theater);
			return ActiveTheater != null;
		}
Ejemplo n.º 3
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;
		}
Ejemplo n.º 4
0
 public static bool SetActiveTheater(TheaterType theater)
 {
     ActiveTheater = ActiveConfig.Theaters.First(t => t.Type == theater);
     return(ActiveTheater != null);
 }
Ejemplo n.º 5
0
		public TileCollection(CollectionType type, TheaterType theater, EngineType engine, IniFile rules, IniFile art,
			TheaterSettings theaterSettings, IniFile theaterIni=null)
			: base(type, theater, engine, rules, art) {

			_theaterSettings = theaterSettings;
			if (theaterIni == null) {
				_theaterIni = VFS.Open<IniFile>(theaterSettings.TheaterIni);
				if (_theaterIni == null) {
					Logger.Warn("Unavailable theater loaded, theater.ini not found");
					return;
				}
			}
			else _theaterIni = theaterIni;

			#region Set numbers

			IniFile.IniSection General = _theaterIni.GetSection("General");
			ACliffMMPieces = General.ReadShort("ACliffMMPieces", -1);
			ACliffPieces = General.ReadShort("ACliffPieces", -1);
			BlackTile = General.ReadShort("BlackTile", -1);
			BridgeBottomLeft1 = General.ReadShort("BridgeBottomLeft1", -1);
			BridgeBottomLeft2 = General.ReadShort("BridgeBottomLeft2", -1);
			BridgeBottomRight1 = General.ReadShort("BridgeBottomRight1", -1);
			BridgeBottomRight2 = General.ReadShort("BridgeBottomRight2", -1);
			BridgeMiddle1 = General.ReadShort("BridgeMiddle1", -1);
			BridgeMiddle2 = General.ReadShort("BridgeMiddle2", -1);
			BridgeSet = General.ReadShort("BridgeSet", -1);
			BridgeTopLeft1 = General.ReadShort("BridgeTopLeft1", -1);
			BridgeTopLeft2 = General.ReadShort("BridgeTopLeft2", -1);
			BridgeTopRight1 = General.ReadShort("BridgeTopRight1", -1);
			BridgeTopRight2 = General.ReadShort("BridgeTopRight2", -1);
			ClearTile = General.ReadShort("ClearTile", -1);
			ClearToGreenLat = General.ReadShort("ClearToGreenLat", -1);
			ClearToPaveLat = General.ReadShort("ClearToPaveLat", -1);
			ClearToRoughLat = General.ReadShort("ClearToRoughLat", -1);
			ClearToSandLat = General.ReadShort("ClearToSandLat", -1);
			CliffRamps = General.ReadShort("CliffRamps", -1);
			CliffSet = General.ReadShort("CliffSet", -1);
			DestroyableCliffs = General.ReadShort("DestroyableCliffs", -1);
			DirtRoadCurve = General.ReadShort("DirtRoadCurve", -1);
			DirtRoadJunction = General.ReadShort("DirtRoadJunction", -1);
			DirtRoadSlopes = General.ReadShort("DirtRoadSlopes", -1);
			DirtRoadStraight = General.ReadShort("DirtRoadStraight", -1);
			DirtTrackTunnels = General.ReadShort("DirtTrackTunnels", -1);
			DirtTunnels = General.ReadShort("DirtTunnels", -1);
			GreenTile = General.ReadShort("GreenTile", -1);
			HeightBase = General.ReadShort("HeightBase", -1);
			Ice1Set = General.ReadShort("Ice1Set", -1);
			Ice2Set = General.ReadShort("Ice2Set", -1);
			Ice3Set = General.ReadShort("Ice3Set", -1);
			IceShoreSet = General.ReadShort("IceShoreSet", -1);
			MMRampBase = General.ReadShort("MMRampBase", -1);
			MMWaterCliffAPieces = General.ReadShort("MMWaterCliffAPieces", -1);
			Medians = General.ReadShort("Medians", -1);
			MiscPaveTile = General.ReadShort("MiscPaveTile", -1);
			MonorailSlopes = General.ReadShort("MonorailSlopes", -1);
			PaveTile = General.ReadShort("PaveTile", -1);
			PavedRoadEnds = General.ReadShort("PavedRoadEnds", -1);
			PavedRoadSlopes = General.ReadShort("PavedRoadSlopes", -1);
			PavedRoads = General.ReadShort("PavedRoads", -1);
			RampBase = General.ReadShort("RampBase", -1);
			RampSmooth = General.ReadShort("RampSmooth", -1);
			Rocks = General.ReadShort("Rocks", -1);
			RoughGround = General.ReadShort("RoughGround", -1);
			RoughTile = General.ReadShort("RoughTile", -1);
			SandTile = General.ReadShort("SandTile", -1);
			ShorePieces = General.ReadShort("ShorePieces", -1);
			SlopeSetPieces = General.ReadShort("SlopeSetPieces", -1);
			SlopeSetPieces2 = General.ReadShort("SlopeSetPieces2", -1);
			TrackTunnels = General.ReadShort("TrackTunnels", -1);
			TrainBridgeSet = General.ReadShort("TrainBridgeSet", -1);
			Tunnels = General.ReadShort("Tunnels", -1);
			WaterBridge = General.ReadShort("WaterBridge", -1);
			WaterCaves = General.ReadShort("WaterCaves", -1);
			WaterCliffAPieces = General.ReadShort("WaterCliffAPieces", -1);
			WaterCliffs = General.ReadShort("WaterCliffs", -1);
			WaterSet = General.ReadShort("WaterSet", -1);
			WaterfallEast = General.ReadShort("WaterfallEast", -1);
			WaterfallNorth = General.ReadShort("WaterfallNorth", -1);
			WaterfallSouth = General.ReadShort("WaterfallSouth", -1);
			WaterfallWest = General.ReadShort("WaterfallWest", -1);
			WoodBridgeSet = General.ReadShort("WoodBridgeSet", -1);

			#endregion
		}
Ejemplo n.º 6
0
		public TileCollection(TheaterSettings ths, IniFile theaterIni)
			: base() {
			_theaterSettings = ths;
			_theaterIni = theaterIni;
		}