public XYZDouble(double X, double Y, double Z) { this = new XYZDouble(); this.X = X; this.Y = Y; this.Z = Z; }
public static double MatrixAngleToVector(Matrix3D Matrix, XYZDouble Vector) { var matrixOut = new Matrix3D(); MatrixInvert(Matrix, matrixOut); var y = ((matrixOut.Values[0] * Vector.X) + (matrixOut.Values[1] * Vector.Y)) + (matrixOut.Values[2] * Vector.Z); var x = ((matrixOut.Values[3] * Vector.X) + (matrixOut.Values[4] * Vector.Y)) + (matrixOut.Values[5] * Vector.Z); var num3 = ((matrixOut.Values[6] * Vector.X) + (matrixOut.Values[7] * Vector.Y)) + (matrixOut.Values[8] * Vector.Z); var a = Math.Atan2(y, x); var num5 = (Math.Sin(a) * y) + (Math.Cos(a) * x); return Math.Atan2(num5, num3); }
public static void MatrixAngleToVector(Matrix3D Matrix, XYZDouble Vector, ref double ResultArcAngle, ref double ResultDirectionAngle) { var matrixOut = new Matrix3D(); MatrixInvert(Matrix, matrixOut); var x = ((matrixOut.Values[0] * Vector.X) + (matrixOut.Values[1] * Vector.Y)) + (matrixOut.Values[2] * Vector.Z); var y = ((matrixOut.Values[3] * Vector.X) + (matrixOut.Values[4] * Vector.Y)) + (matrixOut.Values[5] * Vector.Z); var num3 = ((matrixOut.Values[6] * Vector.X) + (matrixOut.Values[7] * Vector.Y)) + (matrixOut.Values[8] * Vector.Z); ResultDirectionAngle = Math.Atan2(y, x); var a = Math.Atan2(x, y); var num4 = (Math.Sin(a) * x) + (Math.Cos(a) * y); ResultArcAngle = Math.Atan2(num4, num3); }
public void DrawTileWireframe(int TileX, int TileY) { var TileTerrainHeight = new double[4]; var Vertex0 = new XYZDouble(); var Vertex1 = new XYZDouble(); var Vertex2 = new XYZDouble(); var Vertex3 = new XYZDouble(); TileTerrainHeight[0] = Terrain.Vertices[TileX, TileY].Height; TileTerrainHeight[1] = Terrain.Vertices[TileX + 1, TileY].Height; TileTerrainHeight[2] = Terrain.Vertices[TileX, TileY + 1].Height; TileTerrainHeight[3] = Terrain.Vertices[TileX + 1, TileY + 1].Height; Vertex0.X = TileX * Constants.TerrainGridSpacing; Vertex0.Y = (float)(TileTerrainHeight[0] * HeightMultiplier); Vertex0.Z = - TileY * Constants.TerrainGridSpacing; Vertex1.X = (TileX + 1) * Constants.TerrainGridSpacing; Vertex1.Y = (float)(TileTerrainHeight[1] * HeightMultiplier); Vertex1.Z = - TileY * Constants.TerrainGridSpacing; Vertex2.X = TileX * Constants.TerrainGridSpacing; Vertex2.Y = (float)(TileTerrainHeight[2] * HeightMultiplier); Vertex2.Z = - (TileY + 1) * Constants.TerrainGridSpacing; Vertex3.X = (TileX + 1) * Constants.TerrainGridSpacing; Vertex3.Y = (float)(TileTerrainHeight[3] * HeightMultiplier); Vertex3.Z = - (TileY + 1) * Constants.TerrainGridSpacing; GL.Begin(BeginMode.Lines); if ( Terrain.Tiles[TileX, TileY].Tri ) { GL.Vertex3(Vertex0.X, Vertex0.Y, Convert.ToDouble(- Vertex0.Z)); GL.Vertex3(Vertex2.X, Vertex2.Y, Convert.ToDouble(- Vertex2.Z)); GL.Vertex3(Vertex2.X, Vertex2.Y, Convert.ToDouble(- Vertex2.Z)); GL.Vertex3(Vertex1.X, Vertex1.Y, Convert.ToDouble(- Vertex1.Z)); GL.Vertex3(Vertex1.X, Vertex1.Y, Convert.ToDouble(- Vertex1.Z)); GL.Vertex3(Vertex0.X, Vertex0.Y, Convert.ToDouble(- Vertex0.Z)); GL.Vertex3(Vertex1.X, Vertex1.Y, Convert.ToDouble(- Vertex1.Z)); GL.Vertex3(Vertex2.X, Vertex2.Y, Convert.ToDouble(- Vertex2.Z)); GL.Vertex3(Vertex2.X, Vertex2.Y, Convert.ToDouble(- Vertex2.Z)); GL.Vertex3(Vertex3.X, Vertex3.Y, Convert.ToDouble(- Vertex3.Z)); GL.Vertex3(Vertex3.X, Vertex3.Y, Convert.ToDouble(- Vertex3.Z)); GL.Vertex3(Vertex1.X, Vertex1.Y, Convert.ToDouble(- Vertex1.Z)); } else { GL.Vertex3(Vertex0.X, Vertex0.Y, Convert.ToDouble(- Vertex0.Z)); GL.Vertex3(Vertex2.X, Vertex2.Y, Convert.ToDouble(- Vertex2.Z)); GL.Vertex3(Vertex2.X, Vertex2.Y, Convert.ToDouble(- Vertex2.Z)); GL.Vertex3(Vertex3.X, Vertex3.Y, Convert.ToDouble(- Vertex3.Z)); GL.Vertex3(Vertex3.X, Vertex3.Y, Convert.ToDouble(- Vertex3.Z)); GL.Vertex3(Vertex0.X, Vertex0.Y, Convert.ToDouble(- Vertex0.Z)); GL.Vertex3(Vertex0.X, Vertex0.Y, Convert.ToDouble(- Vertex0.Z)); GL.Vertex3(Vertex3.X, Vertex3.Y, Convert.ToDouble(- Vertex3.Z)); GL.Vertex3(Vertex3.X, Vertex3.Y, Convert.ToDouble(- Vertex3.Z)); GL.Vertex3(Vertex1.X, Vertex1.Y, Convert.ToDouble(- Vertex1.Z)); GL.Vertex3(Vertex1.X, Vertex1.Y, Convert.ToDouble(- Vertex1.Z)); GL.Vertex3(Vertex0.X, Vertex0.Y, Convert.ToDouble(- Vertex0.Z)); } GL.End(); }
public static void MatrixToPY(Matrix3D Matrix, ref Angles.AnglePY ResultPY) { var _dbl = new XYZDouble(); VectorForwardsRotationByMatrix(Matrix, ref _dbl); VectorToPY(_dbl, ref ResultPY); }
public void AddDbl(XYZDouble xyz) { X += xyz.X.ToInt(); Y += xyz.Y.ToInt(); Z += xyz.Z.ToInt(); }
public void UpdateAttachments() { BaseAttachment = new clsAttachment(); if ( Body == null ) { AlwaysDrawTextLabel = true; return; } var NewBody = BaseAttachment.AddCopyOfAttachment(Body.Attachment); AlwaysDrawTextLabel = NewBody.Models.Count == 0; if ( Propulsion != null ) { if ( Body.ObjectDataLink.IsConnected ) { BaseAttachment.AddCopyOfAttachment(Propulsion.Bodies[Body.ObjectDataLink.ArrayPosition].LeftAttachment); BaseAttachment.AddCopyOfAttachment(Propulsion.Bodies[Body.ObjectDataLink.ArrayPosition].RightAttachment); } } if ( NewBody.Models.Count == 0 ) { return; } if ( NewBody.Models[0].ConnectorCount <= 0 ) { return; } var TurretConnector = new XYZDouble(); TurretConnector = Body.Attachment.Models[0].Connectors[0]; if ( TurretCount >= 1 ) { if ( Turret1 != null ) { var NewTurret = NewBody.AddCopyOfAttachment(Turret1.Attachment); NewTurret.Pos_Offset = TurretConnector; } } if ( Body.Attachment.Models[0].ConnectorCount <= 1 ) { return; } TurretConnector = Body.Attachment.Models[0].Connectors[1]; if ( TurretCount >= 2 ) { if ( Turret2 != null ) { var NewTurret = NewBody.AddCopyOfAttachment(Turret2.Attachment); NewTurret.Pos_Offset = TurretConnector; } } }
public bool Pos_Get_Screen_XY(XYZDouble Pos, ref XYInt Result) { if ( Pos.Z <= 0.0D ) { return false; } try { var RatioZ_px = 1.0D / (FOVMultiplier * Pos.Z); Result.X = (int)(MapViewControl.GLSize.X / 2.0D + (Pos.X * RatioZ_px)); Result.Y = (int)(MapViewControl.GLSize.Y / 2.0D - (Pos.Y * RatioZ_px)); return true; } catch { } return false; }
public void Set_dbl( XYZDouble XYZ ) { X = (int)XYZ.X; Y = (int)XYZ.Y; Z = (int)XYZ.Z; }
public static void VectorRightRotationByMatrix(Matrix3D Matrix, double Scale, ref XYZDouble ResultVector) { ResultVector.X = Matrix.Values[0] * Scale; ResultVector.Y = Matrix.Values[3] * Scale; ResultVector.Z = Matrix.Values[6] * Scale; }
public static void VectorRightRotationByMatrix(Matrix3D Matrix, ref XYZDouble ResultVector) { ResultVector.X = Matrix.Values[0]; ResultVector.Y = Matrix.Values[3]; ResultVector.Z = Matrix.Values[6]; }
public static void VectorForwardsRotationByMatrix(Matrix3D Matrix, double Scale, ref XYZDouble ResultVector) { ResultVector.X = Matrix.Values[2] * Scale; ResultVector.Y = Matrix.Values[5] * Scale; ResultVector.Z = Matrix.Values[8] * Scale; }
public static void VectorCrossProduct(XYZDouble VectorA, XYZDouble VectorB, ref XYZDouble ResultVector) { ResultVector.X = (VectorA.Y * VectorB.Z) - (VectorB.Y * VectorA.Z); ResultVector.Y = (VectorA.Z * VectorB.X) - (VectorB.Z * VectorA.X); ResultVector.Z = (VectorA.X * VectorB.Y) - (VectorB.X * VectorA.Y); }
public static void VectorBackwardsRotationByMatrix(Matrix3D Matrix, ref XYZDouble ResultVector) { ResultVector.X = -Matrix.Values[2]; ResultVector.Y = -Matrix.Values[5]; ResultVector.Z = -Matrix.Values[8]; }
public static double VectorAngleToVector(XYZDouble VectorA, XYZDouble VectorB) { var epy = new Angles.AnglePY(); var matrix = new Matrix3D(); VectorToPY(VectorA, ref epy); MatrixSetToPY(matrix, epy); return MatrixAngleToVector(matrix, VectorB); }
public static void MatrixToRPY(Matrix3D Matrix, ref Angles.AngleRPY ResultRPY) { var epy = new Angles.AnglePY(); var _dbl = new XYZDouble(); var _dbl2 = new XYZDouble(); var matrix = new Matrix3D(); var matrixd = new Matrix3D(); VectorForwardsRotationByMatrix(Matrix, ref _dbl2); VectorToPY(_dbl2, ref epy); ResultRPY.PY = epy; VectorRightRotationByMatrix(Matrix, ref _dbl2); MatrixSetToXAngle(matrixd, -epy.Pitch); MatrixSetToYAngle(matrix, -epy.Yaw); VectorRotationByMatrix(matrix, _dbl2, ref _dbl); VectorRotationByMatrix(matrixd, _dbl, ref _dbl2); ResultRPY.Roll = Math.Atan2(_dbl2.Y, _dbl2.X); }
public void Add_dbl( XYZDouble XYZ ) { X += (int)XYZ.X; Y += (int)XYZ.Y; Z += (int)XYZ.Z; }
public static void VectorRotationByMatrix(Matrix3D Matrix, XYZDouble Vector, ref XYZDouble ResultVector) { ResultVector.X = ((Vector.X * Matrix.Values[0]) + (Vector.Y * Matrix.Values[1])) + (Vector.Z * Matrix.Values[2]); ResultVector.Y = ((Vector.X * Matrix.Values[3]) + (Vector.Y * Matrix.Values[4])) + (Vector.Z * Matrix.Values[5]); ResultVector.Z = ((Vector.X * Matrix.Values[6]) + (Vector.Y * Matrix.Values[7])) + (Vector.Z * Matrix.Values[8]); }
public void MoveToViewTerrainPosFromDistance(XYZDouble TerrainPos, double Distance) { var XYZ_dbl = default(XYZDouble); var XYZ_int = new XYZInt(0, 0, 0); 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 static void VectorToPY(XYZDouble Vector, ref Angles.AnglePY ResultPY) { ResultPY.Pitch = Math.Atan2(-Vector.Y, Math.Sqrt((Vector.X * Vector.X) + (Vector.Z * Vector.Z))); if ( ResultPY.Pitch > 1.5707963267948966 ) { ResultPY.Pitch = 3.1415926535897931 - ResultPY.Pitch; } else if ( ResultPY.Pitch < -1.5707963267948966 ) { ResultPY.Pitch = -ResultPY.Pitch - 3.1415926535897931; } ResultPY.Yaw = Math.Atan2(Vector.X, Vector.Z); }
public void TimedActions(double Zoom, double Move, double Pan, double Roll, double OrbitRate) { var XYZ_dbl = new XYZDouble(); var PanRate = Pan * FieldOfViewY; var AnglePY = default(Angles.AnglePY); var matrixA = new Matrix3DMath.Matrix3D(); var matrixB = new Matrix3DMath.Matrix3D(); var ViewAngleChange = default(XYZDouble); var ViewPosChangeXYZ = new XYZInt(0, 0, 0); var 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 == 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 == enumView_Move_Type.RTS ) { ViewPosChangeXYZ = new XYZInt(0, 0, 0); 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 static void VectorUpRotationByMatrix(Matrix3D Matrix, ref XYZDouble ResultVector) { ResultVector.X = Matrix.Values[1]; ResultVector.Y = Matrix.Values[4]; ResultVector.Z = Matrix.Values[7]; }
public override void Perform() { var terrain = Map.Terrain; var tileset = Map.Tileset; var tileTerrainHeight = new double[5]; var vertices = new XYZDouble[5]; //4 corners + center var normals = new XYZDouble[5]; var texCoords = new XYDouble[5]; //Texture binding code copied from clsDrawTileOld if ( terrain.Tiles[TileX, TileY].Texture.TextureNum < 0 ) { GL.BindTexture(TextureTarget.Texture2D, App.GLTexture_NoTile); } else if ( tileset == null ) { GL.BindTexture(TextureTarget.Texture2D, App.GLTexture_OverflowTile); } else if ( terrain.Tiles[TileX, TileY].Texture.TextureNum < tileset.TileCount ) { var viewGlTextureNum = tileset.Tiles[terrain.Tiles[TileX, TileY].Texture.TextureNum].MapViewGlTextureNum; if ( viewGlTextureNum == 0 ) { GL.BindTexture(TextureTarget.Texture2D, App.GLTexture_OverflowTile); } else { GL.BindTexture(TextureTarget.Texture2D, viewGlTextureNum); } } else { GL.BindTexture(TextureTarget.Texture2D, App.GLTexture_OverflowTile); } GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)TextureEnvMode.Modulate); //Vertex order: //0 1 // 4 //2 3 tileTerrainHeight[0] = terrain.Vertices[TileX, TileY].Height; tileTerrainHeight[1] = terrain.Vertices[TileX + 1, TileY].Height; tileTerrainHeight[2] = terrain.Vertices[TileX, TileY + 1].Height; tileTerrainHeight[3] = terrain.Vertices[TileX + 1, TileY + 1].Height; tileTerrainHeight[4] = (tileTerrainHeight[0] + tileTerrainHeight[1] + tileTerrainHeight[2] + tileTerrainHeight[3]) / 4; //middle height is average of the corners TileUtil.GetTileRotatedTexCoords(terrain.Tiles[TileX, TileY].Texture.Orientation, ref texCoords[0], ref texCoords[1], ref texCoords[2], ref texCoords[3]); //cowboy: don't forget the middle texture coordinate regardless of rotation. texCoords[4].X = 0.5f; texCoords[4].Y = 0.5f; vertices[0].X = TileX * Constants.TerrainGridSpacing; vertices[0].Y = (float)(tileTerrainHeight[0] * Map.HeightMultiplier); vertices[0].Z = -TileY * Constants.TerrainGridSpacing; vertices[1].X = (TileX + 1) * Constants.TerrainGridSpacing; vertices[1].Y = (float)(tileTerrainHeight[1] * Map.HeightMultiplier); vertices[1].Z = -TileY * Constants.TerrainGridSpacing; vertices[2].X = TileX * Constants.TerrainGridSpacing; vertices[2].Y = (float)(tileTerrainHeight[2] * Map.HeightMultiplier); vertices[2].Z = -(TileY + 1) * Constants.TerrainGridSpacing; vertices[3].X = (TileX + 1) * Constants.TerrainGridSpacing; vertices[3].Y = (float)(tileTerrainHeight[3] * Map.HeightMultiplier); vertices[3].Z = -(TileY + 1) * Constants.TerrainGridSpacing; vertices[4].X = (TileX + 0.5f) * Constants.TerrainGridSpacing; vertices[4].Y = (float)(tileTerrainHeight[4] * Map.HeightMultiplier); vertices[4].Z = -(TileY + 0.5f) * Constants.TerrainGridSpacing; normals[0] = Map.TerrainVertexNormalCalc(TileX, TileY); normals[1] = Map.TerrainVertexNormalCalc(TileX + 1, TileY); normals[2] = Map.TerrainVertexNormalCalc(TileX, TileY + 1); normals[3] = Map.TerrainVertexNormalCalc(TileX + 1, TileY + 1); normals[4] = (normals[0] + normals[1] + normals[2] + normals[3]) / 4; //Linearly interpolate from corner vertices normals[4] /= normals[4].GetMagnitude(); //normalize vector length GL.Begin(BeginMode.Triangles); int[] indices = {1, 0, 4, 3, 1, 4, 2, 3, 4, 0, 2, 4}; foreach ( var i in indices ) { GL.Normal3(normals[i].X, normals[i].Y, -normals[i].Z); GL.TexCoord2(texCoords[i].X, texCoords[i].Y); GL.Vertex3(vertices[i].X, vertices[i].Y, -vertices[i].Z); } GL.End(); }
public static void VectorUpRotationByMatrix(Matrix3D Matrix, double Scale, ref XYZDouble ResultVector) { ResultVector.X = Matrix.Values[1] * Scale; ResultVector.Y = Matrix.Values[4] * Scale; ResultVector.Z = Matrix.Values[7] * Scale; }
public void SetDbl(XYZDouble xyz) { X = xyz.X.ToInt(); Y = xyz.Y.ToInt(); Z = xyz.Z.ToInt(); }
public clsResult LoadDirectory(string Path) { var ReturnResult = new clsResult(string.Format("Loading object data from \"{0}\"", Path)); Path = PathUtil.EndWithPathSeperator(Path); var SubDirNames = ""; var SubDirStructures = ""; var SubDirBrain = ""; var SubDirBody = ""; var SubDirPropulsion = ""; var SubDirBodyPropulsion = ""; var SubDirConstruction = ""; var SubDirSensor = ""; var SubDirRepair = ""; var SubDirTemplates = ""; var SubDirWeapons = ""; var SubDirECM = ""; var SubDirFeatures = ""; var SubDirTexpages = ""; var SubDirAssignWeapons = ""; var SubDirStructureWeapons = ""; var SubDirPIEs = ""; SubDirNames = "messages" + Convert.ToString(App.PlatformPathSeparator) + "strings" + Convert.ToString(App.PlatformPathSeparator) + "names.txt"; SubDirStructures = "stats" + Convert.ToString(App.PlatformPathSeparator) + "structures.txt"; SubDirBrain = "stats" + Convert.ToString(App.PlatformPathSeparator) + "brain.txt"; SubDirBody = "stats" + Convert.ToString(App.PlatformPathSeparator) + "body.txt"; SubDirPropulsion = "stats" + Convert.ToString(App.PlatformPathSeparator) + "propulsion.txt"; SubDirBodyPropulsion = "stats" + Convert.ToString(App.PlatformPathSeparator) + "bodypropulsionimd.txt"; SubDirConstruction = "stats" + Convert.ToString(App.PlatformPathSeparator) + "construction.txt"; SubDirSensor = "stats" + Convert.ToString(App.PlatformPathSeparator) + "sensor.txt"; SubDirRepair = "stats" + Convert.ToString(App.PlatformPathSeparator) + "repair.txt"; SubDirTemplates = "stats" + Convert.ToString(App.PlatformPathSeparator) + "templates.txt"; SubDirWeapons = "stats" + Convert.ToString(App.PlatformPathSeparator) + "weapons.txt"; SubDirECM = "stats" + Convert.ToString(App.PlatformPathSeparator) + "ecm.txt"; SubDirFeatures = "stats" + Convert.ToString(App.PlatformPathSeparator) + "features.txt"; SubDirPIEs = "pies" + Convert.ToString(App.PlatformPathSeparator); //SubDirStructurePIE = "structs" & ospathseperator //SubDirBodiesPIE = "components" & ospathseperator & "bodies" & ospathseperator //SubDirPropPIE = "components" & ospathseperator & "prop" & ospathseperator //SubDirWeaponsPIE = "components" & ospathseperator & "weapons" & ospathseperator SubDirTexpages = "texpages" + Convert.ToString(App.PlatformPathSeparator); SubDirAssignWeapons = "stats" + Convert.ToString(App.PlatformPathSeparator) + "assignweapons.txt"; //SubDirFeaturePIE = "features" & ospathseperator SubDirStructureWeapons = "stats" + Convert.ToString(App.PlatformPathSeparator) + "structureweapons.txt"; var CommaFiles = new SimpleList<clsTextFile>(); var DataNames = new clsTextFile(); DataNames.SubDirectory = SubDirNames; DataNames.UniqueField = 0; ReturnResult.Add(DataNames.LoadNamesFile(Path)); if ( !DataNames.CalcUniqueField() ) { ReturnResult.ProblemAdd("There are two entries for the same code in " + SubDirNames + "."); } var DataStructures = new clsTextFile(); DataStructures.SubDirectory = SubDirStructures; DataStructures.FieldCount = 25; CommaFiles.Add(DataStructures); var DataBrain = new clsTextFile(); DataBrain.SubDirectory = SubDirBrain; DataBrain.FieldCount = 9; CommaFiles.Add(DataBrain); var DataBody = new clsTextFile(); DataBody.SubDirectory = SubDirBody; DataBody.FieldCount = 25; CommaFiles.Add(DataBody); var DataPropulsion = new clsTextFile(); DataPropulsion.SubDirectory = SubDirPropulsion; DataPropulsion.FieldCount = 12; CommaFiles.Add(DataPropulsion); var DataBodyPropulsion = new clsTextFile(); DataBodyPropulsion.SubDirectory = SubDirBodyPropulsion; DataBodyPropulsion.FieldCount = 5; DataBodyPropulsion.UniqueField = -1; //no unique requirement CommaFiles.Add(DataBodyPropulsion); var DataConstruction = new clsTextFile(); DataConstruction.SubDirectory = SubDirConstruction; DataConstruction.FieldCount = 12; CommaFiles.Add(DataConstruction); var DataSensor = new clsTextFile(); DataSensor.SubDirectory = SubDirSensor; DataSensor.FieldCount = 16; CommaFiles.Add(DataSensor); var DataRepair = new clsTextFile(); DataRepair.SubDirectory = SubDirRepair; DataRepair.FieldCount = 14; CommaFiles.Add(DataRepair); var DataTemplates = new clsTextFile(); DataTemplates.SubDirectory = SubDirTemplates; DataTemplates.FieldCount = 12; CommaFiles.Add(DataTemplates); var DataECM = new clsTextFile(); DataECM.SubDirectory = SubDirECM; DataECM.FieldCount = 14; CommaFiles.Add(DataECM); var DataFeatures = new clsTextFile(); DataFeatures.SubDirectory = SubDirFeatures; DataFeatures.FieldCount = 11; CommaFiles.Add(DataFeatures); var DataAssignWeapons = new clsTextFile(); DataAssignWeapons.SubDirectory = SubDirAssignWeapons; DataAssignWeapons.FieldCount = 5; CommaFiles.Add(DataAssignWeapons); var DataWeapons = new clsTextFile(); DataWeapons.SubDirectory = SubDirWeapons; DataWeapons.FieldCount = 53; CommaFiles.Add(DataWeapons); var DataStructureWeapons = new clsTextFile(); DataStructureWeapons.SubDirectory = SubDirStructureWeapons; DataStructureWeapons.FieldCount = 6; CommaFiles.Add(DataStructureWeapons); var TextFile = default(clsTextFile); foreach ( var tempLoopVar_TextFile in CommaFiles ) { TextFile = tempLoopVar_TextFile; var Result = TextFile.LoadCommaFile(Path); ReturnResult.Add(Result); if ( !Result.HasProblems ) { if ( TextFile.CalcIsFieldCountValid() ) { if ( !TextFile.CalcUniqueField() ) { ReturnResult.ProblemAdd("An entry in field " + Convert.ToString(TextFile.UniqueField) + " was not unique for file " + TextFile.SubDirectory + "."); } } else { ReturnResult.ProblemAdd("There were entries with the wrong number of fields for file " + TextFile.SubDirectory + "."); } } } if ( ReturnResult.HasProblems ) { return ReturnResult; } //load texpages string[] TexFiles = null; try { TexFiles = Directory.GetFiles(Path + SubDirTexpages); } catch ( Exception ) { ReturnResult.WarningAdd("Unable to access texture pages."); TexFiles = new string[0]; } var Text = ""; Bitmap Bitmap = null; var InstrPos2 = 0; var BitmapTextureArgs = new BitmapGLTexture(); var BitmapResult = new sResult(); foreach ( var tempLoopVar_Text in TexFiles ) { Text = tempLoopVar_Text; if ( Text.Substring(Text.Length - 4, 4).ToLower() == ".png" ) { var Result = new clsResult(string.Format("Loading texture page \"{0}\"", Text)); if ( File.Exists(Text) ) { BitmapResult = BitmapUtil.LoadBitmap(Text, ref Bitmap); var NewPage = new clsTexturePage(); if ( BitmapResult.Success ) { Result.Take(BitmapUtil.BitmapIsGLCompatible(Bitmap)); BitmapTextureArgs.MagFilter = TextureMagFilter.Nearest; BitmapTextureArgs.MinFilter = TextureMinFilter.Nearest; BitmapTextureArgs.TextureNum = 0; BitmapTextureArgs.MipMapLevel = 0; BitmapTextureArgs.Texture = Bitmap; BitmapTextureArgs.Perform(); NewPage.GLTexture_Num = BitmapTextureArgs.TextureNum; } else { Result.WarningAdd(BitmapResult.Problem); } InstrPos2 = Text.LastIndexOf(System.IO.Path.DirectorySeparatorChar); NewPage.FileTitle = Text.Substring(InstrPos2 + 1, Text.Length - 5 - InstrPos2); TexturePages.Add(NewPage); } else { Result.WarningAdd("Texture page missing (" + Text + ")."); } ReturnResult.Add(Result); } } //load PIEs string[] PIE_Files = null; var PIE_List = new SimpleList<clsPIE>(); var NewPIE = default(clsPIE); try { PIE_Files = Directory.GetFiles(Path + SubDirPIEs); } catch ( Exception ) { ReturnResult.WarningAdd("Unable to access PIE files."); PIE_Files = new string[0]; } var SplitPath = new sSplitPath(); foreach ( var tempLoopVar_Text in PIE_Files ) { Text = tempLoopVar_Text; SplitPath = new sSplitPath(Text); if ( SplitPath.FileExtension.ToLower() == "pie" ) { NewPIE = new clsPIE(); NewPIE.Path = Text; NewPIE.LCaseFileTitle = SplitPath.FileTitle.ToLower(); PIE_List.Add(NewPIE); } } //interpret stats var Attachment = default(clsAttachment); var BaseAttachment = default(clsAttachment); var Connector = new XYZDouble(); var structureTypeBase = default(StructureTypeBase); var featureTypeBase = default(FeatureTypeBase); var Template = default(DroidTemplate); var Body = default(Body); var Propulsion = default(Propulsion); var Construct = default(Construct); var Weapon = default(Weapon); var Repair = default(Repair); var Sensor = default(Sensor); var Brain = default(Brain); var ECM = default(Ecm); string[] Fields = null; //interpret body foreach ( var tempLoopVar_Fields in DataBody.ResultData ) { Fields = tempLoopVar_Fields; Body = new Body(); Body.ObjectDataLink.Connect(Bodies); Body.Code = Fields[0]; SetComponentName(DataNames.ResultData, Body, ReturnResult); IOUtil.InvariantParse(Fields[6], ref Body.Hitpoints); Body.Designable = Fields[24] != "0"; Body.Attachment.Models.Add(GetModelForPIE(PIE_List, Fields[7].ToLower(), ReturnResult)); } //interpret propulsion foreach ( var tempLoopVar_Fields in DataPropulsion.ResultData ) { Fields = tempLoopVar_Fields; Propulsion = new Propulsion(Bodies.Count); Propulsion.ObjectDataLink.Connect(Propulsions); Propulsion.Code = Fields[0]; SetComponentName(DataNames.ResultData, Propulsion, ReturnResult); IOUtil.InvariantParse(Fields[7], ref Propulsion.HitPoints); //.Propulsions(Propulsion_Num).PIE = LCase(DataPropulsion.Entries(Propulsion_Num).FieldValues(8)) Propulsion.Designable = Fields[11] != "0"; } //interpret body-propulsions var BodyPropulsionPIEs = new BodyProp[Bodies.Count, Propulsions.Count]; for ( var A = 0; A <= Bodies.Count - 1; A++ ) { for ( var B = 0; B <= Propulsions.Count - 1; B++ ) { BodyPropulsionPIEs[A, B] = new BodyProp(); BodyPropulsionPIEs[A, B].LeftPIE = "0"; BodyPropulsionPIEs[A, B].RightPIE = "0"; } } foreach ( var tempLoopVar_Fields in DataBodyPropulsion.ResultData ) { Fields = tempLoopVar_Fields; Body = FindBodyCode(Fields[0]); Propulsion = FindPropulsionCode(Fields[1]); if ( Body != null && Propulsion != null ) { if ( Fields[2] != "0" ) { BodyPropulsionPIEs[Body.ObjectDataLink.ArrayPosition, Propulsion.ObjectDataLink.ArrayPosition].LeftPIE = Fields[2].ToLower(); } if ( Fields[3] != "0" ) { BodyPropulsionPIEs[Body.ObjectDataLink.ArrayPosition, Propulsion.ObjectDataLink.ArrayPosition].RightPIE = Fields[3].ToLower(); } } } //set propulsion-body PIEs for ( var A = 0; A <= Propulsions.Count - 1; A++ ) { Propulsion = Propulsions[A]; for ( var B = 0; B <= Bodies.Count - 1; B++ ) { Body = Bodies[B]; Propulsion.Bodies[B].LeftAttachment = new clsAttachment(); Propulsion.Bodies[B].LeftAttachment.Models.Add(GetModelForPIE(PIE_List, BodyPropulsionPIEs[B, A].LeftPIE, ReturnResult)); Propulsion.Bodies[B].RightAttachment = new clsAttachment(); Propulsion.Bodies[B].RightAttachment.Models.Add(GetModelForPIE(PIE_List, BodyPropulsionPIEs[B, A].RightPIE, ReturnResult)); } } //interpret construction foreach ( var tempLoopVar_Fields in DataConstruction.ResultData ) { Fields = tempLoopVar_Fields; Construct = new Construct(); Construct.ObjectDataLink.Connect(Constructors); Construct.TurretObjectDataLink.Connect(Turrets); Construct.Code = Fields[0]; SetComponentName(DataNames.ResultData, Construct, ReturnResult); Construct.Designable = Fields[11] != "0"; Construct.Attachment.Models.Add(GetModelForPIE(PIE_List, Fields[8].ToLower(), ReturnResult)); } //interpret weapons foreach ( var tempLoopVar_Fields in DataWeapons.ResultData ) { Fields = tempLoopVar_Fields; Weapon = new Weapon(); Weapon.ObjectDataLink.Connect(Weapons); Weapon.TurretObjectDataLink.Connect(Turrets); Weapon.Code = Fields[0]; SetComponentName(DataNames.ResultData, Weapon, ReturnResult); IOUtil.InvariantParse(Fields[7], ref Weapon.HitPoints); Weapon.Designable = Fields[51] != "0"; Weapon.Attachment.Models.Add(GetModelForPIE(PIE_List, Convert.ToString(Fields[8].ToLower()), ReturnResult)); Weapon.Attachment.Models.Add(GetModelForPIE(PIE_List, Fields[9].ToLower(), ReturnResult)); } //interpret sensor foreach ( var tempLoopVar_Fields in DataSensor.ResultData ) { Fields = tempLoopVar_Fields; Sensor = new Sensor(); Sensor.ObjectDataLink.Connect(Sensors); Sensor.TurretObjectDataLink.Connect(Turrets); Sensor.Code = Fields[0]; SetComponentName(DataNames.ResultData, Sensor, ReturnResult); IOUtil.InvariantParse(Fields[7], ref Sensor.HitPoints); Sensor.Designable = Fields[15] != "0"; switch ( Fields[11].ToLower() ) { case "turret": Sensor.Location = Sensor.enumLocation.Turret; break; case "default": Sensor.Location = Sensor.enumLocation.Invisible; break; default: Sensor.Location = Sensor.enumLocation.Invisible; break; } Sensor.Attachment.Models.Add(GetModelForPIE(PIE_List, Fields[8].ToLower(), ReturnResult)); Sensor.Attachment.Models.Add(GetModelForPIE(PIE_List, Fields[9].ToLower(), ReturnResult)); } //interpret repair foreach ( var tempLoopVar_Fields in DataRepair.ResultData ) { Fields = tempLoopVar_Fields; Repair = new Repair(); Repair.ObjectDataLink.Connect(Repairs); Repair.TurretObjectDataLink.Connect(Turrets); Repair.Code = Fields[0]; SetComponentName(DataNames.ResultData, Repair, ReturnResult); Repair.Designable = Fields[13] != "0"; Repair.Attachment.Models.Add(GetModelForPIE(PIE_List, Fields[9].ToLower(), ReturnResult)); Repair.Attachment.Models.Add(GetModelForPIE(PIE_List, Fields[10].ToLower(), ReturnResult)); } //interpret brain foreach ( var tempLoopVar_Fields in DataBrain.ResultData ) { Fields = tempLoopVar_Fields; Brain = new Brain(); Brain.ObjectDataLink.Connect(Brains); Brain.TurretObjectDataLink.Connect(Turrets); Brain.Code = Fields[0]; SetComponentName(DataNames.ResultData, Brain, ReturnResult); Brain.Designable = true; Weapon = FindWeaponCode(Fields[7]); if ( Weapon != null ) { Brain.Weapon = Weapon; Brain.Attachment = Weapon.Attachment; } } //interpret ecm foreach ( var tempLoopVar_Fields in DataECM.ResultData ) { Fields = tempLoopVar_Fields; ECM = new Ecm(); ECM.ObjectDataLink.Connect(ECMs); ECM.TurretObjectDataLink.Connect(Turrets); ECM.Code = Fields[0]; SetComponentName(DataNames.ResultData, ECM, ReturnResult); IOUtil.InvariantParse(Fields[7], ref ECM.HitPoints); ECM.Designable = false; ECM.Attachment.Models.Add(GetModelForPIE(PIE_List, Fields[8].ToLower(), ReturnResult)); } //interpret feature foreach ( var tempLoopVar_Fields in DataFeatures.ResultData ) { Fields = tempLoopVar_Fields; featureTypeBase = new FeatureTypeBase(); featureTypeBase.UnitType_ObjectDataLink.Connect(UnitTypes); featureTypeBase.FeatureType_ObjectDataLink.Connect(FeatureTypes); featureTypeBase.Code = Fields[0]; if ( Fields[7] == "OIL RESOURCE" ) //type { featureTypeBase.FeatureType = FeatureTypeBase.enumFeatureType.OilResource; } SetFeatureName(DataNames.ResultData, featureTypeBase, ReturnResult); if ( !IOUtil.InvariantParse(Fields[1], ref featureTypeBase.Footprint.X) ) { ReturnResult.WarningAdd("Feature footprint-x was not an integer for " + featureTypeBase.Code + "."); } if ( !IOUtil.InvariantParse(Fields[2], ref featureTypeBase.Footprint.Y) ) { ReturnResult.WarningAdd("Feature footprint-y was not an integer for " + featureTypeBase.Code + "."); } featureTypeBase.BaseAttachment = new clsAttachment(); BaseAttachment = featureTypeBase.BaseAttachment; Text = Fields[6].ToLower(); Attachment = BaseAttachment.CreateAttachment(); Attachment.Models.Add(GetModelForPIE(PIE_List, Text, ReturnResult)); } //interpret structure foreach ( var tempLoopVar_Fields in DataStructures.ResultData ) { Fields = tempLoopVar_Fields; var StructureCode = Fields[0]; var StructureTypeText = Fields[1]; var StructurePIEs = Fields[21].ToLower().Split('@'); var StructureFootprint = new XYInt(); var StructureBasePIE = Fields[22].ToLower(); if ( !IOUtil.InvariantParse(Fields[5], ref StructureFootprint.X) ) { ReturnResult.WarningAdd("Structure footprint-x was not an integer for " + StructureCode + "."); } if ( !IOUtil.InvariantParse(Fields[6], ref StructureFootprint.Y) ) { ReturnResult.WarningAdd("Structure footprint-y was not an integer for " + StructureCode + "."); } if ( StructureTypeText != "WALL" || StructurePIEs.GetLength(0) != 4 ) { //this is NOT a generic wall structureTypeBase = new StructureTypeBase(); structureTypeBase.UnitType_ObjectDataLink.Connect(UnitTypes); structureTypeBase.StructureType_ObjectDataLink.Connect(StructureTypes); structureTypeBase.Code = StructureCode; SetStructureName(DataNames.ResultData, structureTypeBase, ReturnResult); structureTypeBase.Footprint = StructureFootprint; switch ( StructureTypeText ) { case "DEMOLISH": structureTypeBase.StructureType = StructureTypeBase.enumStructureType.Demolish; break; case "WALL": structureTypeBase.StructureType = StructureTypeBase.enumStructureType.Wall; break; case "CORNER WALL": structureTypeBase.StructureType = StructureTypeBase.enumStructureType.CornerWall; break; case "FACTORY": structureTypeBase.StructureType = StructureTypeBase.enumStructureType.Factory; break; case "CYBORG FACTORY": structureTypeBase.StructureType = StructureTypeBase.enumStructureType.CyborgFactory; break; case "VTOL FACTORY": structureTypeBase.StructureType = StructureTypeBase.enumStructureType.VTOLFactory; break; case "COMMAND": structureTypeBase.StructureType = StructureTypeBase.enumStructureType.Command; break; case "HQ": structureTypeBase.StructureType = StructureTypeBase.enumStructureType.HQ; break; case "DEFENSE": structureTypeBase.StructureType = StructureTypeBase.enumStructureType.Defense; break; case "POWER GENERATOR": structureTypeBase.StructureType = StructureTypeBase.enumStructureType.PowerGenerator; break; case "POWER MODULE": structureTypeBase.StructureType = StructureTypeBase.enumStructureType.PowerModule; break; case "RESEARCH": structureTypeBase.StructureType = StructureTypeBase.enumStructureType.Research; break; case "RESEARCH MODULE": structureTypeBase.StructureType = StructureTypeBase.enumStructureType.ResearchModule; break; case "FACTORY MODULE": structureTypeBase.StructureType = StructureTypeBase.enumStructureType.FactoryModule; break; case "DOOR": structureTypeBase.StructureType = StructureTypeBase.enumStructureType.DOOR; break; case "REPAIR FACILITY": structureTypeBase.StructureType = StructureTypeBase.enumStructureType.RepairFacility; break; case "SAT UPLINK": structureTypeBase.StructureType = StructureTypeBase.enumStructureType.DOOR; break; case "REARM PAD": structureTypeBase.StructureType = StructureTypeBase.enumStructureType.RearmPad; break; case "MISSILE SILO": structureTypeBase.StructureType = StructureTypeBase.enumStructureType.MissileSilo; break; case "RESOURCE EXTRACTOR": structureTypeBase.StructureType = StructureTypeBase.enumStructureType.ResourceExtractor; break; default: structureTypeBase.StructureType = StructureTypeBase.enumStructureType.Unknown; break; } BaseAttachment = structureTypeBase.BaseAttachment; if ( StructurePIEs.GetLength(0) > 0 ) { BaseAttachment.Models.Add(GetModelForPIE(PIE_List, StructurePIEs[0], ReturnResult)); } structureTypeBase.StructureBasePlate = GetModelForPIE(PIE_List, StructureBasePIE, ReturnResult); if ( BaseAttachment.Models.Count == 1 ) { if ( BaseAttachment.Models[0].ConnectorCount >= 1 ) { Connector = BaseAttachment.Models[0].Connectors[0]; var StructureWeapons = default(SimpleList<string[]>); StructureWeapons = GetRowsWithValue(DataStructureWeapons.ResultData, structureTypeBase.Code); if ( StructureWeapons.Count > 0 ) { Weapon = FindWeaponCode(Convert.ToString(StructureWeapons[0][1])); } else { Weapon = null; } ECM = FindECMCode(Fields[18]); Sensor = FindSensorCode(Fields[19]); if ( Weapon != null ) { if ( Weapon.Code != "ZNULLWEAPON" ) { Attachment = BaseAttachment.CopyAttachment(Weapon.Attachment); Attachment.Pos_Offset = Connector; } } if ( ECM != null ) { if ( ECM.Code != "ZNULLECM" ) { Attachment = BaseAttachment.CopyAttachment(ECM.Attachment); Attachment.Pos_Offset = Connector; } } if ( Sensor != null ) { if ( Sensor.Code != "ZNULLSENSOR" ) { Attachment = BaseAttachment.CopyAttachment(Sensor.Attachment); Attachment.Pos_Offset = Connector; } } } } } else { //this is a generic wall var NewWall = new clsWallType(); NewWall.WallType_ObjectDataLink.Connect(WallTypes); NewWall.Code = StructureCode; SetWallName(DataNames.ResultData, NewWall, ReturnResult); var WallBasePlate = GetModelForPIE(PIE_List, StructureBasePIE, ReturnResult); var WallNum = 0; var wallStructureTypeBase = default(StructureTypeBase); for ( WallNum = 0; WallNum <= 3; WallNum++ ) { wallStructureTypeBase = new StructureTypeBase(); wallStructureTypeBase.UnitType_ObjectDataLink.Connect(UnitTypes); wallStructureTypeBase.StructureType_ObjectDataLink.Connect(StructureTypes); wallStructureTypeBase.WallLink.Connect(NewWall.Segments); wallStructureTypeBase.Code = StructureCode; Text = NewWall.Name; switch ( WallNum ) { case 0: Text += " - "; break; case 1: Text += " + "; break; case 2: Text += " T "; break; case 3: Text += " L "; break; } wallStructureTypeBase.Name = Text; wallStructureTypeBase.Footprint = StructureFootprint; wallStructureTypeBase.StructureType = StructureTypeBase.enumStructureType.Wall; BaseAttachment = wallStructureTypeBase.BaseAttachment; Text = StructurePIEs[WallNum]; BaseAttachment.Models.Add(GetModelForPIE(PIE_List, Text, ReturnResult)); wallStructureTypeBase.StructureBasePlate = WallBasePlate; } } } //interpret templates var TurretConflictCount = 0; foreach ( var tempLoopVar_Fields in DataTemplates.ResultData ) { Fields = tempLoopVar_Fields; Template = new DroidTemplate(); Template.UnitType_ObjectDataLink.Connect(UnitTypes); Template.DroidTemplate_ObjectDataLink.Connect(DroidTemplates); Template.Code = Fields[0]; SetTemplateName(DataNames.ResultData, Template, ReturnResult); switch ( Fields[9] ) //type { case "ZNULLDROID": Template.TemplateDroidType = App.TemplateDroidType_Null; break; case "DROID": Template.TemplateDroidType = App.TemplateDroidType_Droid; break; case "CYBORG": Template.TemplateDroidType = App.TemplateDroidType_Cyborg; break; case "CYBORG_CONSTRUCT": Template.TemplateDroidType = App.TemplateDroidType_CyborgConstruct; break; case "CYBORG_REPAIR": Template.TemplateDroidType = App.TemplateDroidType_CyborgRepair; break; case "CYBORG_SUPER": Template.TemplateDroidType = App.TemplateDroidType_CyborgSuper; break; case "TRANSPORTER": Template.TemplateDroidType = App.TemplateDroidType_Transporter; break; case "PERSON": Template.TemplateDroidType = App.TemplateDroidType_Person; break; default: Template.TemplateDroidType = null; ReturnResult.WarningAdd("Template " + Template.GetDisplayTextCode() + " had an unrecognised type."); break; } var LoadPartsArgs = new DroidDesign.sLoadPartsArgs(); LoadPartsArgs.Body = FindBodyCode(Fields[2]); LoadPartsArgs.Brain = FindBrainCode(Fields[3]); LoadPartsArgs.Construct = FindConstructorCode(Fields[4]); LoadPartsArgs.ECM = FindECMCode(Fields[5]); LoadPartsArgs.Propulsion = FindPropulsionCode(Fields[7]); LoadPartsArgs.Repair = FindRepairCode(Fields[8]); LoadPartsArgs.Sensor = FindSensorCode(Fields[10]); var TemplateWeapons = GetRowsWithValue(DataAssignWeapons.ResultData, Template.Code); if ( TemplateWeapons.Count > 0 ) { Text = Convert.ToString(TemplateWeapons[0][1]); if ( Text != "NULL" ) { LoadPartsArgs.Weapon1 = FindWeaponCode(Text); } Text = Convert.ToString(TemplateWeapons[0][2]); if ( Text != "NULL" ) { LoadPartsArgs.Weapon2 = FindWeaponCode(Text); } Text = Convert.ToString(TemplateWeapons[0][3]); if ( Text != "NULL" ) { LoadPartsArgs.Weapon3 = FindWeaponCode(Text); } } if ( !Template.LoadParts(LoadPartsArgs) ) { if ( TurretConflictCount < 16 ) { ReturnResult.WarningAdd("Template " + Template.GetDisplayTextCode() + " had multiple conflicting turrets."); } TurretConflictCount++; } } if ( TurretConflictCount > 0 ) { ReturnResult.WarningAdd(TurretConflictCount + " templates had multiple conflicting turrets."); } return ReturnResult; }