예제 #1
0
		public bool Initialize() {
			Logger.Info("Initializing theater of type {0}", _theaterType);

			if (!ModConfig.SetActiveTheater(_theaterType))
				return false;
			Active = this;

			// load palettes and additional mix files for this theater
			_palettes = new PaletteCollection();
			_palettes.IsoPalette = new Palette(VFS.Open<PalFile>(ModConfig.ActiveTheater.IsoPaletteName));
			_palettes.OvlPalette = new Palette(VFS.Open<PalFile>(ModConfig.ActiveTheater.OverlayPaletteName));
            _palettes.UnitPalette = new Palette(VFS.Open<PalFile>(ModConfig.ActiveTheater.UnitPaletteName), ModConfig.ActiveTheater.UnitPaletteName, true);

			foreach (string mix in ModConfig.ActiveTheater.Mixes)
				VFS.Add(mix, CacheMethod.Cache); // we wish for these to be cached as they're gonna be hit often

			_palettes.AnimPalette = new Palette(VFS.Open<PalFile>("anim.pal"));

			_animations = new ObjectCollection(CollectionType.Animation, _theaterType, _engine, _rules, _art,
				_rules.GetSection("Animations"), _palettes);

			_tileTypes = new TileCollection(CollectionType.Tiles, _theaterType, _engine, _rules, _art, ModConfig.ActiveTheater);

			_buildingTypes = new ObjectCollection(CollectionType.Building, _theaterType, _engine, _rules, _art,
				_rules.GetSection("BuildingTypes"), _palettes);

			_aircraftTypes = new ObjectCollection(CollectionType.Aircraft, _theaterType, _engine, _rules, _art,
				_rules.GetSection("AircraftTypes"), _palettes);

			_infantryTypes = new ObjectCollection(CollectionType.Infantry, _theaterType, _engine, _rules, _art,
				_rules.GetSection("InfantryTypes"), _palettes);

			_overlayTypes = new ObjectCollection(CollectionType.Overlay, _theaterType, _engine, _rules, _art,
				_rules.GetSection("OverlayTypes"), _palettes);

			_terrainTypes = new ObjectCollection(CollectionType.Terrain, _theaterType, _engine, _rules, _art,
				_rules.GetSection("TerrainTypes"), _palettes);

			_smudgeTypes = new ObjectCollection(CollectionType.Smudge, _theaterType, _engine, _rules, _art,
				_rules.GetSection("SmudgeTypes"), _palettes);

			_vehicleTypes = new ObjectCollection(CollectionType.Vehicle, _theaterType, _engine, _rules, _art,
				_rules.GetSection("VehicleTypes"), _palettes);

			_tileTypes.InitTilesets();
			_tileTypes.InitAnimations(_animations);

			return true;
		}
예제 #2
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;
		}
예제 #3
0
		/// <summary>Recalculates tile system. </summary>
		public static void FixTiles(TileLayer tiles, TileCollection collection) {
			Logger.Info("Recalculating tile LAT system");

			// change all CLAT tiles to their corresponding LAT tiles
			foreach (MapTile t in tiles) {
				// If this tile comes from a CLAT (connecting lat) set,
				// then replace it's set and tilenr by corresponding LAT sets'
				t.SetNum = collection.GetSetNum(t.TileNum);

				if (collection.IsCLAT(t.SetNum)) {
					t.SetNum = collection.GetLAT(t.SetNum);
					t.TileNum = collection.GetTileNumFromSet(t.SetNum);
				}
			}

			// apply autolat
			foreach (MapTile t in tiles) {
				// If this tile is a LAT tile, we might have to connect it
				if (collection.IsLAT(t.SetNum)) {
					// Which tile to use from CLAT tileset
					byte transitionTile = 0;
					MapTile tileTopRight = tiles.GetNeighbourTile(t, TileLayer.TileDirection.TopRight);
					MapTile tileBottomRight = tiles.GetNeighbourTile(t, TileLayer.TileDirection.BottomRight);
					MapTile tileBottomLeft = tiles.GetNeighbourTile(t, TileLayer.TileDirection.BottomLeft);
					MapTile tileTopLeft = tiles.GetNeighbourTile(t, TileLayer.TileDirection.TopLeft);


					// Find out setnums of adjacent cells
					if (tileTopRight != null && collection.ConnectTiles(t.SetNum, tileTopRight.SetNum))
						transitionTile += 1;

					if (tileBottomRight != null && collection.ConnectTiles(t.SetNum, tileBottomRight.SetNum))
						transitionTile += 2;

					if (tileBottomLeft != null && collection.ConnectTiles(t.SetNum, tileBottomLeft.SetNum))
						transitionTile += 4;

					if (tileTopLeft != null && collection.ConnectTiles(t.SetNum, tileTopLeft.SetNum))
						transitionTile += 8;

					if (transitionTile > 0) {
						// Find Tileset that contains the connecting pieces
						short clatSet = collection.GetCLATSet(t.SetNum);
						// Do not change this setnum, as then we could recognize it as
						// a different tileset for later tiles around this one.
						// (T->SetNum = clatSet;)
						t.TileNum = collection.GetTileNumFromSet(clatSet, transitionTile);
						t.Drawable = collection.GetDrawable(t);
					}
				}

				// apply ramp fixup
				else if (t.SetNum == collection.RampBase) {
					var ti = t.GetTileImage();
					if (ti.RampType < 1 || 4 < ti.TerrainType) continue;

					int fixup = -1;
					MapTile tileTopRight = tiles.GetNeighbourTile(t, TileLayer.TileDirection.TopRight);
					MapTile tileBottomRight = tiles.GetNeighbourTile(t, TileLayer.TileDirection.BottomRight);
					MapTile tileBottomLeft = tiles.GetNeighbourTile(t, TileLayer.TileDirection.BottomLeft);
					MapTile tileTopLeft = tiles.GetNeighbourTile(t, TileLayer.TileDirection.TopLeft);


					switch (ti.RampType) {
						case 1:
							// northwest facing
							if (tileTopLeft != null && tileTopLeft.GetTileImage().RampType == 0)
								fixup++;
							if (tileBottomRight != null && tileBottomRight.GetTileImage().RampType == 0)
								fixup += 2;
							break;

						case 2: // northeast facing
							if (tileTopRight != null && tileTopRight.GetTileImage().RampType == 0)
								fixup++;
							if (tileBottomLeft != null && tileBottomLeft.GetTileImage().RampType == 0)
								fixup += 2;
							break;

						case 3: // southeast facing
							if (tileBottomRight != null && tileBottomRight.GetTileImage().RampType == 0)
								fixup++;
							if (tileTopLeft != null && tileTopLeft.GetTileImage().RampType == 0)
								fixup += 2;
							break;

						case 4: // southwest facing
							if (tileBottomLeft != null && tileBottomLeft.GetTileImage().RampType == 0)
								fixup++;
							if (tileTopRight != null && tileTopRight.GetTileImage().RampType == 0)
								fixup += 2;
							break;
					}

					if (fixup != -1) {
						t.TileNum = collection.GetTileNumFromSet(collection.RampSmooth, (byte)((ti.RampType - 1) * 3 + fixup));
						// update drawable too
						t.Drawable = collection.GetDrawable(t);
					}
				}

			}


		}
예제 #4
0
		public TileDrawable(IniFile.IniSection rules, IniFile.IniSection art, TileCollection.TileSetEntry entry)
			: base(rules, art) {
			TsEntry = entry;
			if (entry != null)
				Name = entry.ToString();
		}
예제 #5
0
파일: Map.cs 프로젝트: zzattack/ccmaps-net
        private void ChangeTileToClear(TileCollection coll, MapTile tile)
        {
            tile.TileNum = 0;
            tile.SubTile = 0;
            tile.Drawable = coll.GetDrawable(0);

            var t = _mapFile.Tiles.GetTileR(tile.Rx, tile.Ry);
            t.TileNum = 0;
            t.SubTile = 0;
        }