public sXYZ_int LNDPos_From_MapPos(sXY_int Horizontal) { sXYZ_int Result = new sXYZ_int(); Result.X = Horizontal.X - (int)(Terrain.TileSize.X * App.TerrainGridSpacing / 2.0D); Result.Z = ((int)(Terrain.TileSize.Y * App.TerrainGridSpacing / 2.0D)) - Horizontal.Y; Result.Y = (int)(GetTerrainHeight(Horizontal)); return Result; }
public clsViewInfo(clsMap Map, MapViewControl MapViewControl) { this.Map = Map; this.MapViewControl = MapViewControl; ViewPos = new sXYZ_int(0, 3072, 0); FOV_Multiplier_Set(SettingsManager.Settings.FOVDefault); ViewAngleSetToDefault(); LookAtPos(new sXY_int((int)(Map.Terrain.TileSize.X * App.TerrainGridSpacing / 2.0D), (int)(Map.Terrain.TileSize.Y * App.TerrainGridSpacing / 2.0D))); }
public void OpenGL_MouseWheel(object sender, MouseEventArgs e) { clsMap Map = MainMap; if ( Map == null ) { return; } sXYZ_int Move = new sXYZ_int(); Position.XYZ_dbl XYZ_dbl = default(Position.XYZ_dbl); int A = 0; for ( A = 0; A <= (int)(Math.Abs(e.Delta / 120.0D)); A++ ) { Matrix3DMath.VectorForwardsRotationByMatrix(Map.ViewInfo.ViewAngleMatrix, Convert.ToDouble(Math.Sign(e.Delta) * Math.Max(Map.ViewInfo.ViewPos.Y, 512.0D) / 24.0D), ref XYZ_dbl); Move.Set_dbl(XYZ_dbl); Map.ViewInfo.ViewPosChange(Move); } }
public App.sWorldPos MapPos_From_LNDPos(sXYZ_int Pos) { App.sWorldPos Result = new App.sWorldPos(); Result.Horizontal.X = Pos.X + (int)(Terrain.TileSize.X * App.TerrainGridSpacing / 2.0D); Result.Horizontal.Y = ((int)(Terrain.TileSize.Y * App.TerrainGridSpacing / 2.0D)) - Pos.Z; Result.Altitude = (int)(GetTerrainHeight(Result.Horizontal)); return Result; }
public clsResult Load_LND(string Path) { clsResult ReturnResult = new clsResult("Loading LND from " + Convert.ToString(ControlChars.Quote) + Path + Convert.ToString(ControlChars.Quote)); try { string strTemp = ""; string strTemp2 = ""; int X = 0; int Y = 0; int A = 0; int B = 0; int Tile_Num = 0; SimpleList<string> LineData = default(SimpleList<string>); int Line_Num = 0; sLNDTile[] LNDTile = null; SimpleList<clsLNDObject> LNDObjects = new SimpleList<clsLNDObject>(); clsUnitAdd UnitAdd = new clsUnitAdd(); UnitAdd.Map = this; BinaryReader Reader = default(BinaryReader); try { Reader = new BinaryReader(new FileStream(Path, FileMode.Open), App.UTF8Encoding); } catch ( Exception ex ) { ReturnResult.ProblemAdd(ex.Message); return ReturnResult; } LineData = IOUtil.BytesToLinesRemoveComments(Reader); Reader.Close(); Array.Resize(ref LNDTile, LineData.Count); string strTemp3 = ""; bool GotTiles = default(bool); bool GotObjects = default(bool); bool GotGates = default(bool); bool GotTileTypes = default(bool); byte[] LNDTileType = new byte[0]; string[] ObjectText = new string[11]; string[] GateText = new string[4]; string[] TileTypeText = new string[256]; int LNDTileTypeCount = 0; SimpleList<clsGateway> LNDGates = new SimpleList<clsGateway>(); clsGateway Gateway = default(clsGateway); int C = 0; int D = 0; bool GotText = default(bool); bool FlipX = default(bool); bool FlipZ = default(bool); byte Rotation = 0; sXY_int NewTileSize = new sXY_int(); double dblTemp = 0; Line_Num = 0; while ( Line_Num < LineData.Count ) { strTemp = LineData[Line_Num]; A = strTemp.IndexOf("TileWidth ") + 1; if ( A == 0 ) { } else { } A = strTemp.IndexOf("TileHeight ") + 1; if ( A == 0 ) { } else { } A = strTemp.IndexOf("MapWidth ") + 1; if ( A == 0 ) { } else { IOUtil.InvariantParse(strTemp.Substring(strTemp.Length - (strTemp.Length - (A + 8)), strTemp.Length - (A + 8)), ref NewTileSize.X); goto LineDone; } A = strTemp.IndexOf("MapHeight ") + 1; if ( A == 0 ) { } else { IOUtil.InvariantParse(strTemp.Substring(strTemp.Length - (strTemp.Length - (A + 9)), strTemp.Length - (A + 9)), ref NewTileSize.Y); goto LineDone; } A = strTemp.IndexOf("Textures {") + 1; if ( A == 0 ) { } else { Line_Num++; strTemp = LineData[Line_Num]; strTemp2 = strTemp.ToLower(); if ( strTemp2.IndexOf("tertilesc1") + 1 > 0 ) { Tileset = App.Tileset_Arizona; goto LineDone; } else if ( strTemp2.IndexOf("tertilesc2") + 1 > 0 ) { Tileset = App.Tileset_Urban; goto LineDone; } else if ( strTemp2.IndexOf("tertilesc3") + 1 > 0 ) { Tileset = App.Tileset_Rockies; goto LineDone; } goto LineDone; } A = strTemp.IndexOf("Tiles {") + 1; if ( A == 0 || GotTiles ) { } else { Line_Num++; while ( Line_Num < LineData.Count ) { strTemp = LineData[Line_Num]; A = strTemp.IndexOf("}") + 1; if ( A == 0 ) { A = strTemp.IndexOf("TID ") + 1; if ( A == 0 ) { ReturnResult.ProblemAdd("Tile ID missing"); return ReturnResult; } else { strTemp2 = strTemp.Substring(strTemp.Length - (strTemp.Length - A - 3), strTemp.Length - A - 3); A = strTemp2.IndexOf(" ") + 1; if ( A > 0 ) { strTemp2 = strTemp2.Substring(0, A - 1); } Int16 temp_Result = LNDTile[Tile_Num].TID; IOUtil.InvariantParse(strTemp2, ref temp_Result); } A = strTemp.IndexOf("VF ") + 1; if ( A == 0 ) { ReturnResult.ProblemAdd("Tile VF missing"); return ReturnResult; } else { strTemp2 = strTemp.Substring(strTemp.Length - (strTemp.Length - A - 2), strTemp.Length - A - 2); A = strTemp2.IndexOf(" ") + 1; if ( A > 0 ) { strTemp2 = strTemp2.Substring(0, A - 1); } Int16 temp_Result2 = LNDTile[Tile_Num].VF; IOUtil.InvariantParse(strTemp2, ref temp_Result2); } A = strTemp.IndexOf("TF ") + 1; if ( A == 0 ) { ReturnResult.ProblemAdd("Tile TF missing"); return ReturnResult; } else { strTemp2 = strTemp.Substring(strTemp.Length - (strTemp.Length - A - 2), strTemp.Length - A - 2); A = strTemp2.IndexOf(" ") + 1; if ( A > 0 ) { strTemp2 = strTemp2.Substring(0, A - 1); } Int16 temp_Result3 = LNDTile[Tile_Num].TF; IOUtil.InvariantParse(strTemp2, ref temp_Result3); } A = strTemp.IndexOf(" F ") + 1; if ( A == 0 ) { ReturnResult.ProblemAdd("Tile flip missing"); return ReturnResult; } else { strTemp2 = Strings.Right(strTemp, strTemp.Length - A - 2); A = strTemp2.IndexOf(" ") + 1; if ( A > 0 ) { strTemp2 = strTemp2.Substring(0, A - 1); } short temp_Result4 = LNDTile[Tile_Num].F; IOUtil.InvariantParse(strTemp2, ref temp_Result4); } A = strTemp.IndexOf(" VH ") + 1; if ( A == 0 ) { ReturnResult.ProblemAdd("Tile height is missing"); return ReturnResult; } else { strTemp3 = strTemp.Substring(strTemp.Length - (strTemp.Length - A - 3), strTemp.Length - A - 3); for ( A = 0; A <= 2; A++ ) { B = strTemp3.IndexOf(" ") + 1; if ( B == 0 ) { ReturnResult.ProblemAdd("A tile height value is missing"); return ReturnResult; } strTemp2 = strTemp3.Substring(0, B - 1); strTemp3 = strTemp3.Substring(strTemp3.Length - (strTemp3.Length - B), strTemp3.Length - B); if ( A == 0 ) { short temp_Result5 = LNDTile[Tile_Num].Vertex0Height; IOUtil.InvariantParse(strTemp2, ref temp_Result5); } else if ( A == 1 ) { short temp_Result6 = LNDTile[Tile_Num].Vertex1Height; IOUtil.InvariantParse(strTemp2, ref temp_Result6); } else if ( A == 2 ) { Int16 temp_Result7 = LNDTile[Tile_Num].Vertex2Height; IOUtil.InvariantParse(strTemp2, ref temp_Result7); } } short temp_Result8 = LNDTile[Tile_Num].Vertex3Height; IOUtil.InvariantParse(strTemp3, ref temp_Result8); } Tile_Num++; } else { GotTiles = true; goto LineDone; } Line_Num++; } GotTiles = true; goto LineDone; } A = strTemp.IndexOf("Objects {") + 1; if ( A == 0 || GotObjects ) { } else { Line_Num++; while ( Line_Num < LineData.Count ) { strTemp = LineData[Line_Num]; A = strTemp.IndexOf("}") + 1; if ( A == 0 ) { C = 0; ObjectText[0] = ""; GotText = false; for ( B = 0; B <= strTemp.Length - 1; B++ ) { if ( strTemp[B] != ' ' && strTemp[B] != '\t' ) { GotText = true; ObjectText[C] += strTemp[B].ToString(); } else { if ( GotText ) { C++; if ( C == 11 ) { ReturnResult.ProblemAdd("Too many fields for an object, or a space at the end."); return ReturnResult; } ObjectText[C] = ""; GotText = false; } } } clsLNDObject NewObject = new clsLNDObject(); IOUtil.InvariantParse(ObjectText[0], NewObject.ID); IOUtil.InvariantParse(ObjectText[1], ref NewObject.TypeNum); NewObject.Code = ObjectText[2].Substring(1, ObjectText[2].Length - 2); //remove quotes IOUtil.InvariantParse(ObjectText[3], ref NewObject.PlayerNum); NewObject.Name = ObjectText[4].Substring(1, ObjectText[4].Length - 2); //remove quotes IOUtil.InvariantParse(ObjectText[5], ref NewObject.Pos.X); IOUtil.InvariantParse(ObjectText[6], ref NewObject.Pos.Y); IOUtil.InvariantParse(ObjectText[7], ref NewObject.Pos.Z); if ( IOUtil.InvariantParse(ObjectText[8], ref dblTemp) ) { NewObject.Rotation.X = (int)(MathUtil.Clamp_dbl(dblTemp, 0.0D, 359.0D)); } if ( IOUtil.InvariantParse(ObjectText[9], ref dblTemp) ) { NewObject.Rotation.Y = (int)(MathUtil.Clamp_dbl(dblTemp, 0.0D, 359.0D)); } if ( IOUtil.InvariantParse(ObjectText[10], ref dblTemp) ) { NewObject.Rotation.Z = (int)(MathUtil.Clamp_dbl(dblTemp, 0.0D, 359.0D)); } LNDObjects.Add(NewObject); } else { GotObjects = true; goto LineDone; } Line_Num++; } GotObjects = true; goto LineDone; } A = strTemp.IndexOf("Gates {") + 1; if ( A == 0 || GotGates ) { } else { Line_Num++; while ( Line_Num < LineData.Count ) { strTemp = LineData[Line_Num]; A = strTemp.IndexOf("}") + 1; if ( A == 0 ) { C = 0; GateText[0] = ""; GotText = false; for ( B = 0; B <= strTemp.Length - 1; B++ ) { if ( strTemp[B] != ' ' && strTemp[B] != '\t' ) { GotText = true; GateText[C] += strTemp[B].ToString(); } else { if ( GotText ) { C++; if ( C == 4 ) { ReturnResult.ProblemAdd("Too many fields for a gateway, or a space at the end."); return ReturnResult; } GateText[C] = ""; GotText = false; } } } Gateway = new clsGateway(); IOUtil.InvariantParse(GateText[0], ref Gateway.PosA.X); Gateway.PosA.X = Math.Max(Gateway.PosA.X, 0); IOUtil.InvariantParse(GateText[1], ref Gateway.PosA.Y); Gateway.PosA.Y = Math.Max(Gateway.PosA.Y, 0); IOUtil.InvariantParse(GateText[2], ref Gateway.PosB.X); Gateway.PosB.X = Math.Max(Gateway.PosB.X, 0); IOUtil.InvariantParse(GateText[3], ref Gateway.PosB.Y); Gateway.PosB.Y = Math.Max(Gateway.PosB.Y, 0); LNDGates.Add(Gateway); } else { GotGates = true; goto LineDone; } Line_Num++; } GotGates = true; goto LineDone; } A = strTemp.IndexOf("Tiles {") + 1; if ( A == 0 || GotTileTypes || !GotTiles ) { } else { Line_Num++; while ( Line_Num < LineData.Count ) { strTemp = LineData[Line_Num]; A = strTemp.IndexOf("}") + 1; if ( A == 0 ) { C = 0; TileTypeText[0] = ""; GotText = false; for ( B = 0; B <= strTemp.Length - 1; B++ ) { if ( strTemp[B] != ' ' && strTemp[B] != '\t' ) { GotText = true; TileTypeText[C] += strTemp[B].ToString(); } else { if ( GotText ) { C++; if ( C == 256 ) { ReturnResult.ProblemAdd("Too many fields for tile types."); return ReturnResult; } TileTypeText[C] = ""; GotText = false; } } } if ( TileTypeText[C] == "" || TileTypeText[C] == " " ) { C--; } for ( D = 0; D <= C; D++ ) { Array.Resize(ref LNDTileType, LNDTileTypeCount + 1); LNDTileType[LNDTileTypeCount] = Math.Min(byte.Parse(TileTypeText[D]), (byte)11); LNDTileTypeCount++; } } else { GotTileTypes = true; goto LineDone; } Line_Num++; } GotTileTypes = true; goto LineDone; } LineDone: Line_Num++; } Array.Resize(ref LNDTile, Tile_Num); SetPainterToDefaults(); if ( NewTileSize.X < 1 | NewTileSize.Y < 1 ) { ReturnResult.ProblemAdd("The LND\'s terrain dimensions are missing or invalid."); return ReturnResult; } TerrainBlank(NewTileSize); TileType_Reset(); for ( Y = 0; Y <= Terrain.TileSize.Y - 1; Y++ ) { for ( X = 0; X <= Terrain.TileSize.X - 1; X++ ) { Tile_Num = Y * Terrain.TileSize.X + X; //lnd uses different order! (3 = 2, 2 = 3), this program goes left to right, lnd goes clockwise around each tile Terrain.Vertices[X, Y].Height = (byte)(LNDTile[Tile_Num].Vertex0Height); } } for ( Y = 0; Y <= Terrain.TileSize.Y - 1; Y++ ) { for ( X = 0; X <= Terrain.TileSize.X - 1; X++ ) { Tile_Num = Y * Terrain.TileSize.X + X; Terrain.Tiles[X, Y].Texture.TextureNum = LNDTile[Tile_Num].TID - 1; //ignore higher values A = Convert.ToInt32(Conversion.Int(LNDTile[Tile_Num].F / 64.0D)); LNDTile[Tile_Num].F = (short)(LNDTile[Tile_Num].F - A * 64); A = (int)(Conversion.Int(LNDTile[Tile_Num].F / 16.0D)); LNDTile[Tile_Num].F = (short)(LNDTile[Tile_Num].F - A * 16); if ( A < 0 | A > 3 ) { ReturnResult.ProblemAdd("Invalid flip value."); return ReturnResult; } Rotation = (byte)A; A = (int)(Conversion.Int(LNDTile[Tile_Num].F / 8.0D)); LNDTile[Tile_Num].F -= (short)(A * 8); FlipZ = A == 1; A = (int)(Conversion.Int(LNDTile[Tile_Num].F / 4.0D)); LNDTile[Tile_Num].F -= (short)(A * 4); FlipX = A == 1; A = Convert.ToInt32(Conversion.Int(LNDTile[Tile_Num].F / 2.0D)); LNDTile[Tile_Num].F -= (short)(A * 2); Terrain.Tiles[X, Y].Tri = A == 1; //vf, tf, ignore TileUtil.OldOrientation_To_TileOrientation(Rotation, FlipX, FlipZ, Terrain.Tiles[X, Y].Texture.Orientation); } } clsUnit NewUnit = default(clsUnit); sXYZ_int XYZ_int = new sXYZ_int(); clsUnitType NewType = default(clsUnitType); UInt32 AvailableID = 0; clsLNDObject CurrentObject = default(clsLNDObject); AvailableID = 1U; foreach ( clsLNDObject tempLoopVar_CurrentObject in LNDObjects ) { CurrentObject = tempLoopVar_CurrentObject; if ( CurrentObject.ID >= AvailableID ) { AvailableID = CurrentObject.ID + 1U; } } foreach ( clsLNDObject tempLoopVar_CurrentObject in LNDObjects ) { CurrentObject = tempLoopVar_CurrentObject; switch ( CurrentObject.TypeNum ) { case 0: NewType = App.ObjectData.FindOrCreateUnitType(CurrentObject.Code, clsUnitType.enumType.Feature, -1); break; case 1: NewType = App.ObjectData.FindOrCreateUnitType(CurrentObject.Code, clsUnitType.enumType.PlayerStructure, -1); break; case 2: NewType = App.ObjectData.FindOrCreateUnitType(CurrentObject.Code, clsUnitType.enumType.PlayerDroid, -1); break; default: NewType = null; break; } if ( NewType != null ) { NewUnit = new clsUnit(); NewUnit.Type = NewType; if ( CurrentObject.PlayerNum < 0 | CurrentObject.PlayerNum >= Constants.PlayerCountMax ) { NewUnit.UnitGroup = ScavengerUnitGroup; } else { NewUnit.UnitGroup = UnitGroups[CurrentObject.PlayerNum]; } XYZ_int.X = (int)CurrentObject.Pos.X; XYZ_int.Y = (int)CurrentObject.Pos.Y; XYZ_int.Z = (int)CurrentObject.Pos.Z; NewUnit.Pos = MapPos_From_LNDPos(XYZ_int); NewUnit.Rotation = CurrentObject.Rotation.Y; if ( CurrentObject.ID == 0U ) { CurrentObject.ID = AvailableID; App.ZeroIDWarning(NewUnit, CurrentObject.ID, ReturnResult); } UnitAdd.NewUnit = NewUnit; UnitAdd.ID = CurrentObject.ID; UnitAdd.Perform(); App.ErrorIDChange(CurrentObject.ID, NewUnit, "Load_LND"); if ( AvailableID == CurrentObject.ID ) { AvailableID = NewUnit.ID + 1U; } } } foreach ( clsGateway tempLoopVar_Gateway in LNDGates ) { Gateway = tempLoopVar_Gateway; GatewayCreate(Gateway.PosA, Gateway.PosB); } if ( Tileset != null ) { for ( A = 0; A <= Math.Min(LNDTileTypeCount - 1, Tileset.TileCount) - 1; A++ ) { Tile_TypeNum[A] = LNDTileType[A + 1]; //lnd value 0 is ignored } } } catch ( Exception ex ) { ReturnResult.ProblemAdd(ex.Message); return ReturnResult; } return ReturnResult; }
public clsResult Write_LND(string Path, bool Overwrite) { clsResult ReturnResult = new clsResult("Writing LND to " + Convert.ToString(ControlChars.Quote) + Path + Convert.ToString(ControlChars.Quote)); if ( System.IO.File.Exists(Path) ) { if ( Overwrite ) { System.IO.File.Delete(Path); } else { ReturnResult.ProblemAdd("The selected file already exists."); return ReturnResult; } } StreamWriter File = null; try { string Text = ""; char EndChar = (char)0; char Quote = (char)0; int A = 0; int X = 0; int Y = 0; byte Flip = 0; int B = 0; int VF = 0; int TF = 0; int C = 0; byte Rotation = 0; bool FlipX = default(bool); Quote = ControlChars.Quote; EndChar = '\n'; File = new StreamWriter(new FileStream(Path, FileMode.CreateNew), new UTF8Encoding(false, false)); if ( Tileset == App.Tileset_Arizona ) { Text = "DataSet WarzoneDataC1.eds" + Convert.ToString(EndChar); } else if ( Tileset == App.Tileset_Urban ) { Text = "DataSet WarzoneDataC2.eds" + Convert.ToString(EndChar); } else if ( Tileset == App.Tileset_Rockies ) { Text = "DataSet WarzoneDataC3.eds" + Convert.ToString(EndChar); } else { Text = "DataSet " + Convert.ToString(EndChar); } File.Write(Text); Text = "GrdLand {" + Convert.ToString(EndChar); File.Write(Text); Text = " Version 4" + Convert.ToString(EndChar); File.Write(Text); Text = " 3DPosition 0.000000 3072.000000 0.000000" + Convert.ToString(EndChar); File.Write(Text); Text = " 3DRotation 80.000000 0.000000 0.000000" + Convert.ToString(EndChar); File.Write(Text); Text = " 2DPosition 0 0" + Convert.ToString(EndChar); File.Write(Text); Text = " CustomSnap 16 16" + Convert.ToString(EndChar); File.Write(Text); Text = " SnapMode 0" + Convert.ToString(EndChar); File.Write(Text); Text = " Gravity 1" + Convert.ToString(EndChar); File.Write(Text); Text = " HeightScale " + IOUtil.InvariantToString(HeightMultiplier) + Convert.ToString(EndChar); File.Write(Text); Text = " MapWidth " + IOUtil.InvariantToString(Terrain.TileSize.X) + Convert.ToString(EndChar); File.Write(Text); Text = " MapHeight " + IOUtil.InvariantToString(Terrain.TileSize.Y) + Convert.ToString(EndChar); File.Write(Text); Text = " TileWidth 128" + Convert.ToString(EndChar); File.Write(Text); Text = " TileHeight 128" + Convert.ToString(EndChar); File.Write(Text); Text = " SeaLevel 0" + Convert.ToString(EndChar); File.Write(Text); Text = " TextureWidth 64" + Convert.ToString(EndChar); File.Write(Text); Text = " TextureHeight 64" + Convert.ToString(EndChar); File.Write(Text); Text = " NumTextures 1" + Convert.ToString(EndChar); File.Write(Text); Text = " Textures {" + Convert.ToString(EndChar); File.Write(Text); if ( Tileset == App.Tileset_Arizona ) { Text = " texpages\\tertilesc1.pcx" + Convert.ToString(EndChar); } else if ( Tileset == App.Tileset_Urban ) { Text = " texpages\\tertilesc2.pcx" + Convert.ToString(EndChar); } else if ( Tileset == App.Tileset_Rockies ) { Text = " texpages\\tertilesc3.pcx" + Convert.ToString(EndChar); } else { Text = " " + Convert.ToString(EndChar); } File.Write(Text); Text = " }" + Convert.ToString(EndChar); File.Write(Text); Text = " NumTiles " + IOUtil.InvariantToString(Terrain.TileSize.X * Terrain.TileSize.Y) + Convert.ToString(EndChar); File.Write(Text); Text = " Tiles {" + Convert.ToString(EndChar); File.Write(Text); for ( Y = 0; Y <= Terrain.TileSize.Y - 1; Y++ ) { for ( X = 0; X <= Terrain.TileSize.X - 1; X++ ) { TileUtil.TileOrientation_To_OldOrientation(Terrain.Tiles[X, Y].Texture.Orientation, ref Rotation, ref FlipX); Flip = (byte)0; if ( Terrain.Tiles[X, Y].Tri ) { Flip += (byte)2; } if ( FlipX ) { Flip += (byte)4; } Flip += (byte)(Rotation * 16); if ( Terrain.Tiles[X, Y].Tri ) { VF = 1; } else { VF = 0; } if ( FlipX ) { TF = 1; } else { TF = 0; } Text = " TID " + (Terrain.Tiles[X, Y].Texture.TextureNum + 1) + " VF " + IOUtil.InvariantToString(VF) + " TF " + IOUtil.InvariantToString(TF) + " F " + IOUtil.InvariantToString((int)Flip) + " VH " + IOUtil.InvariantToString(Convert.ToByte(Terrain.Vertices[X, Y].Height)) + " " + IOUtil.InvariantToString(Terrain.Vertices[X + 1, Y].Height) + " " + Convert.ToString(Terrain.Vertices[X + 1, Y + 1].Height) + " " + IOUtil.InvariantToString(Convert.ToByte(Terrain.Vertices[X, Y + 1].Height)) + Convert.ToString(EndChar); File.Write(Text); } } Text = " }" + Convert.ToString(EndChar); File.Write(Text); Text = "}" + Convert.ToString(EndChar); File.Write(Text); Text = "ObjectList {" + Convert.ToString(EndChar); File.Write(Text); Text = " Version 3" + Convert.ToString(EndChar); File.Write(Text); if ( Tileset == App.Tileset_Arizona ) { Text = " FeatureSet WarzoneDataC1.eds" + Convert.ToString(EndChar); } else if ( Tileset == App.Tileset_Urban ) { Text = " FeatureSet WarzoneDataC2.eds" + Convert.ToString(EndChar); } else if ( Tileset == App.Tileset_Rockies ) { Text = " FeatureSet WarzoneDataC3.eds" + Convert.ToString(EndChar); } else { Text = " FeatureSet " + Convert.ToString(EndChar); } File.Write(Text); Text = " NumObjects " + IOUtil.InvariantToString(Units.Count) + Convert.ToString(EndChar); File.Write(Text); Text = " Objects {" + Convert.ToString(EndChar); File.Write(Text); sXYZ_int XYZ_int = new sXYZ_int(); string Code = null; int CustomDroidCount = 0; clsUnit Unit = default(clsUnit); foreach ( clsUnit tempLoopVar_Unit in Units ) { Unit = tempLoopVar_Unit; switch ( Unit.Type.Type ) { case clsUnitType.enumType.Feature: B = 0; break; case clsUnitType.enumType.PlayerStructure: B = 1; break; case clsUnitType.enumType.PlayerDroid: if ( ((clsDroidDesign)Unit.Type).IsTemplate ) { B = 2; } else { B = -1; } break; default: B = -1; ReturnResult.WarningAdd("Unit type classification not accounted for."); break; } XYZ_int = LNDPos_From_MapPos(Units[A].Pos.Horizontal); if ( B >= 0 ) { if ( Unit.Type.GetCode(ref Code) ) { Text = " " + IOUtil.InvariantToString(Unit.ID) + " " + Convert.ToString(B) + " " + Convert.ToString(Quote) + Code + Convert.ToString(Quote) + " " + Unit.UnitGroup.GetLNDPlayerText() + " " + Convert.ToString(Quote) + "NONAME" + Convert.ToString(Quote) + " " + IOUtil.InvariantToString(XYZ_int.X) + ".00 " + IOUtil.InvariantToString(XYZ_int.Y) + ".00 " + IOUtil.InvariantToString(XYZ_int.Z) + ".00 0.00 " + IOUtil.InvariantToString(Unit.Rotation) + ".00 0.00" + Convert.ToString(EndChar); File.Write(Text); } else { ReturnResult.WarningAdd("Error. Code not found."); } } else { CustomDroidCount++; } } Text = " }" + Convert.ToString(EndChar); File.Write(Text); Text = "}" + Convert.ToString(EndChar); File.Write(Text); Text = "ScrollLimits {" + Convert.ToString(EndChar); File.Write(Text); Text = " Version 1" + Convert.ToString(EndChar); File.Write(Text); Text = " NumLimits 1" + Convert.ToString(EndChar); File.Write(Text); Text = " Limits {" + Convert.ToString(EndChar); File.Write(Text); Text = " " + Convert.ToString(Quote) + "Entire Map" + Convert.ToString(Quote) + " 0 0 0 " + IOUtil.InvariantToString(Terrain.TileSize.X) + " " + IOUtil.InvariantToString(Terrain.TileSize.Y) + Convert.ToString(EndChar); File.Write(Text); Text = " }" + Convert.ToString(EndChar); File.Write(Text); Text = "}" + Convert.ToString(EndChar); File.Write(Text); Text = "Gateways {" + Convert.ToString(EndChar); File.Write(Text); Text = " Version 1" + Convert.ToString(EndChar); File.Write(Text); Text = " NumGateways " + IOUtil.InvariantToString(Gateways.Count) + Convert.ToString(EndChar); File.Write(Text); Text = " Gates {" + Convert.ToString(EndChar); File.Write(Text); clsGateway Gateway = default(clsGateway); foreach ( clsGateway tempLoopVar_Gateway in Gateways ) { Gateway = tempLoopVar_Gateway; Text = " " + IOUtil.InvariantToString(Gateway.PosA.X) + " " + IOUtil.InvariantToString(Gateway.PosA.Y) + " " + IOUtil.InvariantToString(Gateway.PosB.X) + " " + IOUtil.InvariantToString(Gateway.PosB.Y) + Convert.ToString(EndChar); File.Write(Text); } Text = " }" + Convert.ToString(EndChar); File.Write(Text); Text = "}" + Convert.ToString(EndChar); File.Write(Text); Text = "TileTypes {" + Convert.ToString(EndChar); File.Write(Text); Text = " NumTiles " + Convert.ToString(Tileset.TileCount) + Convert.ToString(EndChar); File.Write(Text); Text = " Tiles {" + Convert.ToString(EndChar); File.Write(Text); for ( A = 0; A <= ((int)(Math.Ceiling(Convert.ToDecimal((Tileset.TileCount + 1) / 16.0D)))) - 1; A++ ) //+1 because the first number is not a tile type { Text = " "; C = A * 16 - 1; //-1 because the first number is not a tile type for ( B = 0; B <= Math.Min(16, Tileset.TileCount - C) - 1; B++ ) { if ( C + B < 0 ) { Text = Text + "2 "; } else { Text = Text + IOUtil.InvariantToString(Tile_TypeNum[C + B]) + " "; } } Text = Text + Convert.ToString(EndChar); File.Write(Text); } Text = " }" + Convert.ToString(EndChar); File.Write(Text); Text = "}" + Convert.ToString(EndChar); File.Write(Text); Text = "TileFlags {" + Convert.ToString(EndChar); File.Write(Text); Text = " NumTiles 90" + Convert.ToString(EndChar); File.Write(Text); Text = " Flags {" + Convert.ToString(EndChar); File.Write(Text); Text = " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 " + Convert.ToString(EndChar); File.Write(Text); Text = " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 " + Convert.ToString(EndChar); File.Write(Text); Text = " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 " + Convert.ToString(EndChar); File.Write(Text); Text = " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 " + Convert.ToString(EndChar); File.Write(Text); Text = " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 " + Convert.ToString(EndChar); File.Write(Text); Text = " 0 0 0 0 0 0 0 0 0 0 " + Convert.ToString(EndChar); File.Write(Text); Text = " }" + Convert.ToString(EndChar); File.Write(Text); Text = "}" + Convert.ToString(EndChar); File.Write(Text); Text = "Brushes {" + Convert.ToString(EndChar); File.Write(Text); Text = " Version 2" + Convert.ToString(EndChar); File.Write(Text); Text = " NumEdgeBrushes 0" + Convert.ToString(EndChar); File.Write(Text); Text = " NumUserBrushes 0" + Convert.ToString(EndChar); File.Write(Text); Text = " EdgeBrushes {" + Convert.ToString(EndChar); File.Write(Text); Text = " }" + Convert.ToString(EndChar); File.Write(Text); Text = "}" + Convert.ToString(EndChar); File.Write(Text); } catch ( Exception ex ) { ReturnResult.ProblemAdd(ex.Message); } if ( File != null ) { File.Close(); } return ReturnResult; }
public void ViewPosSet(sXYZ_int NewViewPos) { ViewPos = NewViewPos; ViewPosClamp(); MapViewControl.DrawViewLater(); }
public void ViewPosChange(sXYZ_int Displacement) { ViewPos.X += Displacement.X; ViewPos.Z += Displacement.Z; ViewPos.Y += Displacement.Y; ViewPosClamp(); MapViewControl.DrawViewLater(); }
public void TimedActions(double Zoom, double Move, double Pan, double Roll, double OrbitRate) { Position.XYZ_dbl XYZ_dbl = default(Position.XYZ_dbl); double PanRate = Pan * FieldOfViewY; Angles.AnglePY AnglePY = default(Angles.AnglePY); Matrix3DMath.Matrix3D matrixA = new Matrix3DMath.Matrix3D(); Matrix3DMath.Matrix3D matrixB = new Matrix3DMath.Matrix3D(); Position.XYZ_dbl ViewAngleChange = default(Position.XYZ_dbl); sXYZ_int ViewPosChangeXYZ = new sXYZ_int(); bool AngleChanged = default(bool); Move *= FOVMultiplier * (MapViewControl.GLSize.X + MapViewControl.GLSize.Y) * Math.Max(Math.Abs(ViewPos.Y), 512.0D); if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewZoomIn) ) { FOV_Scale_2E_Change(Convert.ToDouble(- Zoom)); } if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewZoomOut) ) { FOV_Scale_2E_Change(Zoom); } if ( App.ViewMoveType == App.enumView_Move_Type.Free ) { ViewPosChangeXYZ.X = 0; ViewPosChangeXYZ.Y = 0; ViewPosChangeXYZ.Z = 0; if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewMoveForward) ) { Matrix3DMath.VectorForwardsRotationByMatrix(ViewAngleMatrix, Move, ref XYZ_dbl); ViewPosChangeXYZ.Add_dbl(XYZ_dbl); } if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewMoveBackward) ) { Matrix3DMath.VectorBackwardsRotationByMatrix(ViewAngleMatrix, Move, ref XYZ_dbl); ViewPosChangeXYZ.Add_dbl(XYZ_dbl); } if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewMoveLeft) ) { Matrix3DMath.VectorLeftRotationByMatrix(ViewAngleMatrix, Move, ref XYZ_dbl); ViewPosChangeXYZ.Add_dbl(XYZ_dbl); } if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewMoveRight) ) { Matrix3DMath.VectorRightRotationByMatrix(ViewAngleMatrix, Move, ref XYZ_dbl); ViewPosChangeXYZ.Add_dbl(XYZ_dbl); } if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewMoveUp) ) { Matrix3DMath.VectorUpRotationByMatrix(ViewAngleMatrix, Move, ref XYZ_dbl); ViewPosChangeXYZ.Add_dbl(XYZ_dbl); } if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewMoveDown) ) { Matrix3DMath.VectorDownRotationByMatrix(ViewAngleMatrix, Move, ref XYZ_dbl); ViewPosChangeXYZ.Add_dbl(XYZ_dbl); } ViewAngleChange.X = 0.0D; ViewAngleChange.Y = 0.0D; ViewAngleChange.Z = 0.0D; if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewLeft) ) { Matrix3DMath.VectorForwardsRotationByMatrix(ViewAngleMatrix, Roll, ref XYZ_dbl); ViewAngleChange += XYZ_dbl; } if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewRight) ) { Matrix3DMath.VectorBackwardsRotationByMatrix(ViewAngleMatrix, Roll, ref XYZ_dbl); ViewAngleChange += XYZ_dbl; } if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewBackward) ) { Matrix3DMath.VectorLeftRotationByMatrix(ViewAngleMatrix, PanRate, ref XYZ_dbl); ViewAngleChange += XYZ_dbl; } if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewForward) ) { Matrix3DMath.VectorRightRotationByMatrix(ViewAngleMatrix, PanRate, ref XYZ_dbl); ViewAngleChange += XYZ_dbl; } if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewRollLeft) ) { Matrix3DMath.VectorDownRotationByMatrix(ViewAngleMatrix, PanRate, ref XYZ_dbl); ViewAngleChange += XYZ_dbl; } if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewRollRight) ) { Matrix3DMath.VectorUpRotationByMatrix(ViewAngleMatrix, PanRate, ref XYZ_dbl); ViewAngleChange += XYZ_dbl; } if ( ViewPosChangeXYZ.X != 0.0D | ViewPosChangeXYZ.Y != 0.0D | ViewPosChangeXYZ.Z != 0.0D ) { ViewPosChange(ViewPosChangeXYZ); } //do rotation if ( ViewAngleChange.X != 0.0D | ViewAngleChange.Y != 0.0D | ViewAngleChange.Z != 0.0D ) { Matrix3DMath.VectorToPY(ViewAngleChange, ref AnglePY); Matrix3DMath.MatrixSetToPY(matrixA, AnglePY); Matrix3DMath.MatrixRotationAroundAxis(ViewAngleMatrix, matrixA, ViewAngleChange.GetMagnitude(), matrixB); ViewAngleSet_Rotate(matrixB); } } else if ( App.ViewMoveType == App.enumView_Move_Type.RTS ) { ViewPosChangeXYZ = new sXYZ_int(); Matrix3DMath.MatrixToPY(ViewAngleMatrix, ref AnglePY); Matrix3DMath.MatrixSetToYAngle(matrixA, AnglePY.Yaw); if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewMoveForward) ) { Matrix3DMath.VectorForwardsRotationByMatrix(matrixA, Move, ref XYZ_dbl); ViewPosChangeXYZ.Add_dbl(XYZ_dbl); } if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewMoveBackward) ) { Matrix3DMath.VectorBackwardsRotationByMatrix(matrixA, Move, ref XYZ_dbl); ViewPosChangeXYZ.Add_dbl(XYZ_dbl); } if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewMoveLeft) ) { Matrix3DMath.VectorLeftRotationByMatrix(matrixA, Move, ref XYZ_dbl); ViewPosChangeXYZ.Add_dbl(XYZ_dbl); } if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewMoveRight) ) { Matrix3DMath.VectorRightRotationByMatrix(matrixA, Move, ref XYZ_dbl); ViewPosChangeXYZ.Add_dbl(XYZ_dbl); } if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewMoveUp) ) { ViewPosChangeXYZ.Y += (int)Move; } if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewMoveDown) ) { ViewPosChangeXYZ.Y -= (int)Move; } AngleChanged = false; if ( App.RTSOrbit ) { if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewForward) ) { AnglePY.Pitch = MathUtil.Clamp_dbl(AnglePY.Pitch + OrbitRate, Convert.ToDouble(- MathUtil.RadOf90Deg + 0.03125D * MathUtil.RadOf1Deg), MathUtil.RadOf90Deg - 0.03125D * MathUtil.RadOf1Deg); AngleChanged = true; } if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewBackward) ) { AnglePY.Pitch = MathUtil.Clamp_dbl(AnglePY.Pitch - OrbitRate, Convert.ToDouble(- MathUtil.RadOf90Deg + 0.03125D * MathUtil.RadOf1Deg), MathUtil.RadOf90Deg - 0.03125D * MathUtil.RadOf1Deg); AngleChanged = true; } if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewLeft) ) { AnglePY.Yaw = MathUtil.AngleClamp(AnglePY.Yaw + OrbitRate); AngleChanged = true; } if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewRight) ) { AnglePY.Yaw = MathUtil.AngleClamp(AnglePY.Yaw - OrbitRate); AngleChanged = true; } } else { if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewForward) ) { AnglePY.Pitch = MathUtil.Clamp_dbl(AnglePY.Pitch - OrbitRate, Convert.ToDouble(- MathUtil.RadOf90Deg + 0.03125D * MathUtil.RadOf1Deg), MathUtil.RadOf90Deg - 0.03125D * MathUtil.RadOf1Deg); AngleChanged = true; } if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewBackward) ) { AnglePY.Pitch = MathUtil.Clamp_dbl(AnglePY.Pitch + OrbitRate, Convert.ToDouble(- MathUtil.RadOf90Deg + 0.03125D * MathUtil.RadOf1Deg), MathUtil.RadOf90Deg - 0.03125D * MathUtil.RadOf1Deg); AngleChanged = true; } if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewLeft) ) { AnglePY.Yaw = MathUtil.AngleClamp(AnglePY.Yaw - OrbitRate); AngleChanged = true; } if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewRight) ) { AnglePY.Yaw = MathUtil.AngleClamp(AnglePY.Yaw + OrbitRate); AngleChanged = true; } } //Dim HeightChange As Double //HeightChange = Map.Terrain_Height_Get(view.View_Pos.X + ViewPosChange.X, view.View_Pos.Z + ViewPosChange.Z) - Map.Terrain_Height_Get(view.View_Pos.X, view.View_Pos.Z) //ViewPosChange.Y = ViewPosChange.Y + HeightChange if ( ViewPosChangeXYZ.X != 0.0D | ViewPosChangeXYZ.Y != 0.0D | ViewPosChangeXYZ.Z != 0.0D ) { ViewPosChange(ViewPosChangeXYZ); } if ( AngleChanged ) { Matrix3DMath.MatrixSetToPY(matrixA, AnglePY); ViewAngleSet_Rotate(matrixA); } } }
public void MoveToViewTerrainPosFromDistance(Position.XYZ_dbl TerrainPos, double Distance) { Position.XYZ_dbl XYZ_dbl = default(Position.XYZ_dbl); sXYZ_int XYZ_int = new sXYZ_int(); Matrix3DMath.VectorForwardsRotationByMatrix(ViewAngleMatrix, ref XYZ_dbl); XYZ_int.X = (int)(TerrainPos.X - XYZ_dbl.X * Distance); XYZ_int.Y = (int)(TerrainPos.Y - XYZ_dbl.Y * Distance); XYZ_int.Z = (int)(- TerrainPos.Z - XYZ_dbl.Z * Distance); ViewPosSet(XYZ_int); }
public void LookAtPos(sXY_int Horizontal) { Position.XYZ_dbl XYZ_dbl = default(Position.XYZ_dbl); sXYZ_int XYZ_int = new sXYZ_int(); double dblTemp = 0; int A = 0; Matrix3DMath.Matrix3D matrixA = new Matrix3DMath.Matrix3D(); Angles.AnglePY AnglePY = default(Angles.AnglePY); Matrix3DMath.VectorForwardsRotationByMatrix(ViewAngleMatrix, ref XYZ_dbl); dblTemp = Map.GetTerrainHeight(Horizontal); A = ((int)(Math.Ceiling(dblTemp))) + 128; if ( ViewPos.Y < A ) { ViewPos.Y = A; } if ( XYZ_dbl.Y > -0.33333333333333331D ) { XYZ_dbl.Y = -0.33333333333333331D; Matrix3DMath.VectorToPY(XYZ_dbl, ref AnglePY); Matrix3DMath.MatrixSetToPY(matrixA, AnglePY); ViewAngleSet(matrixA); } dblTemp = (ViewPos.Y - dblTemp) / XYZ_dbl.Y; XYZ_int.X = (int)(Horizontal.X + dblTemp * XYZ_dbl.X); XYZ_int.Y = ViewPos.Y; XYZ_int.Z = (int)(- Horizontal.Y + dblTemp * XYZ_dbl.Z); ViewPosSet(XYZ_int); }