/// <summary> /// Default constructor /// </summary> public TrackSavable() { Author = ""; Comment = ""; Style = 0; Ambience = "day.amb"; FieldFilesNumber = 2; FieldFiles = new List <string>(2) { "field.cfl", "chkpoint.cfl" }; Height = 5; Width = 5; TrackTiles = new List <List <TrackTileSavable> >(5); for (int y = 0; y < Height; y++) { TrackTiles.Add(new List <TrackTileSavable>(5)); for (int x = 0; x < Width; x++) { TrackTileSavable tile = new TrackTileSavable(0, 0, 0, 0); if (x == 2 && y == 2) { tile = new TrackTileSavable(1, 0, 0, 0); } TrackTiles[y].Add(tile); } } DynamicObjectFilesNumber = 0; DynamicObjectFiles = new List <string>(); DynamicObjectsNumber = 0; DynamicObjects = new List <DynamicObjectSavable>(); CheckpointsNumber = 1; Checkpoints = new List <ushort> { 12 }; Permission = 0; GroundBumpyness = 1.0f; Scenery = 0; Heightmap = new List <List <float> >(21); for (int y = 0; y < Height * 4 + 1; y++) { Heightmap.Add(new List <float>(21)); for (int x = 0; x < Width * 4 + 1; x++) { Heightmap[y].Add(0.0f); } } }
public TrackTileSavable(TrackTileSavable old) { FieldId = old.FieldId; Rotation = old.Rotation; IsMirrored = old.IsMirrored; Height = old.Height; }
public void SetupTile(TrackTileSavable trackTileSavable, IntVector2 size, IntVector2 gridPosition, TerrainManager term, string fieldName) { _trackTileSavable = trackTileSavable; Size = size; GridPosition = gridPosition; _terrainManager = term; FieldName = fieldName; SetRotation(trackTileSavable.Rotation); }
void PopulateTilePlacementArray() { InitializeTilePlacementArray(Consts.TRACK.Height, Consts.TRACK.Width); // Load tiles layout from TRACK to TilePlacementArray for (int z = 0; z < Consts.TRACK.Height; z++) { for (int x = 0; x < Consts.TRACK.Width; x++) { TrackTileSavable tile = Consts.TRACK.TrackTiles[Consts.TRACK.Height - z - 1][x]; // tiles bigger than 1x1 have funny max uint numbers around center block. We ignore them as well as grass fields (FieldId = 0) if (tile.FieldId < Consts.TRACK.FieldFiles.Count) { // without .cfl suffix string TileName = Consts.TRACK.FieldFiles[tile.FieldId].Substring(0, Consts.TRACK.FieldFiles[tile.FieldId].Length - 4); // ignore strange grass tiles if (TileName == "border1" || TileName == "border2" || TileName == "field") { continue; } // Don't load tiles that aren't in tile database if (!TileManager.TileListInfo.ContainsKey(TileName)) { if (!Consts.MissingTilesNames.Contains(TileName)) { Consts.MissingTilesNames.Add(TileName); } continue; } int Rotation = tile.Rotation * 90; bool Inversion = tile.IsMirrored == 0 ? false : true; //Inversed tiles rotate anti-clockwise so.. if (Inversion && Rotation != 0) { Rotation = 360 - Rotation; } byte Height = tile.Height; Vector2Int dim = TileManager.GetRealDims(TileName, (Rotation == 90 || Rotation == 270) ? true : false); if (!Consts.LoadMirrored) { Consts.TilePlacementArray[z, x].Set(TileName, Rotation, Inversion, Height); } else { Consts.TilePlacementArray[z, Consts.TRACK.Width - 1 - x - dim.x + 1].Set( TileName, 360 - Rotation, !Inversion, Height); } } } } }
//reads map from file to Track object public static TrackSavable ReadMap(string path) { TrackSavable Track = new TrackSavable(); List <byte> data = new List <byte>(File.ReadAllBytes(path)); ByteFileParser io = new ByteFileParser(data); //ignore "CDTRK" string in the start of the file io.SetReadingOffest(5); //unused current time thing Track.CurrentTime = io.ReadInt(); //author Track.Author = io.ReadString(); //comment Track.Comment = io.ReadString(); //skip unneeded block for (int n = 0; n < 20; n++) { io.ReadInt(); io.ReadString(); } //track style (race, derby, htf) Track.Style = io.ReadByte(); //ambience Track.Ambience = io.ReadString(); //amount of fileds used on map Track.FieldFilesNumber = io.ReadUShort(); //name of fields Track.FieldFiles = new List <string>(Track.FieldFilesNumber); for (int n = 0; n < Track.FieldFilesNumber; n++) { Track.FieldFiles.Add(io.ReadString()); } //width and height in tiles Track.Width = io.ReadUShort(); Track.Height = io.ReadUShort(); Track.TrackTiles = new List <List <TrackTileSavable> >(Track.Height); for (int y = 0; y < Track.Height; y++) { Track.TrackTiles.Add(new List <TrackTileSavable>(Track.Width)); for (int x = 0; x < Track.Width; x++) { TrackTileSavable newTile = new TrackTileSavable(); newTile.FieldId = io.ReadUShort(); newTile.Rotation = io.ReadByte(); newTile.IsMirrored = io.ReadByte(); newTile.Height = io.ReadByte(); Track.TrackTiles[y].Add(newTile); } } Track.DynamicObjectFilesNumber = io.ReadUShort(); Track.DynamicObjectFiles = new List <string>(Track.DynamicObjectFilesNumber); for (int i = 0; i < Track.DynamicObjectFilesNumber; i++) { Track.DynamicObjectFiles.Add(io.ReadString()); } Track.DynamicObjectsNumber = io.ReadUShort(); Track.DynamicObjects = new List <DynamicObjectSavable>(Track.DynamicObjectsNumber); for (int i = 0; i < Track.DynamicObjectsNumber; i++) { DynamicObjectSavable newDynamicObject = new DynamicObjectSavable(); newDynamicObject.ObjectId = io.ReadUShort(); newDynamicObject.Position = io.ReadVector3(); newDynamicObject.Rotation = io.ReadFloat(); Track.DynamicObjects.Add(newDynamicObject); } Track.CheckpointsNumber = io.ReadUShort(); Track.Checkpoints = new List <ushort>(Track.CheckpointsNumber); for (int i = 0; i < Track.CheckpointsNumber; i++) { Track.Checkpoints.Add(io.ReadUShort()); } Track.Permission = io.ReadByte(); Track.GroundBumpyness = io.ReadFloat(); Track.Scenery = io.ReadByte(); Track.Heightmap = new List <List <float> >(); for (int y = 0; y < Track.Height * 4 + 1; y++) { Track.Heightmap.Add(new List <float>()); for (int x = 0; x < Track.Width * 4 + 1; x++) { Track.Heightmap[y].Add(io.ReadFloat()); } } return(Track); }
public void UpdateTrackSize(int addLeft, int addRight, int addUp, int addDown) { //TODO: //Move DynamicObjects TrackSavable newTrack = new TrackSavable(CurrentTrack); newTrack.Width += (ushort)(addLeft + addRight); newTrack.Height += (ushort)(addUp + addDown); List <ushort> newCPs = new List <ushort>(); for (int i = 0; i < CurrentTrack.CheckpointsNumber; i++) { int newPosX = CurrentTrack.Checkpoints[i] % CurrentTrack.Width; int newPosY = CurrentTrack.Checkpoints[i] / CurrentTrack.Height; newPosX += addLeft; newPosY += addUp; if (newPosX >= 0 && newPosX < newTrack.Width && newPosY >= 0 && newPosY < newTrack.Height) { newCPs.Add((ushort)(newPosY * newTrack.Width + newPosX)); } } newTrack.CheckpointsNumber = (ushort)newCPs.Count; newTrack.Checkpoints = newCPs; newTrack.TrackTiles = new List <List <TrackTileSavable> >(newTrack.Height); for (int y = 0; y < newTrack.Height; y++) { newTrack.TrackTiles.Add(new List <TrackTileSavable>(newTrack.Width)); for (int x = 0; x < newTrack.Width; x++) { TrackTileSavable tile; if (x - addLeft >= 0 && y - addUp >= 0 && x - addLeft < CurrentTrack.Width && y - addUp < CurrentTrack.Height) { tile = new TrackTileSavable(CurrentTrack.TrackTiles[y - addUp][x - addLeft]); } else { tile = new TrackTileSavable(0, 0, 0, 0); } newTrack.TrackTiles[y].Add(tile); } } newTrack.Heightmap = new List <List <float> >(newTrack.Height * 4 + 1); for (int y = 0; y < newTrack.Height * 4 + 1; y++) { newTrack.Heightmap.Add(new List <float>(newTrack.Width * 4 + 1)); for (int x = 0; x < newTrack.Width * 4 + 1; x++) { if (x + addLeft * 4 >= 0 && y + addUp * 4 >= 0 && x + addLeft * 4 < CurrentTrack.Width * 4 + 1 && y + addUp * 4 < CurrentTrack.Height * 4 + 1) { newTrack.Heightmap[y].Add(CurrentTrack.Heightmap[y + addUp * 4][x + addLeft * 4]); } else { newTrack.Heightmap[y].Add(0.0f); } } } LoadTrack(newTrack); GetComponent <ToolManager>().OnMapSizeChange(); }