private void SetBaseLevelRamp(clsSetBaseLevelRampArgs Args, PathfinderNode Node) { if (Node.GetChildNodeCount == 0) { clsNodeTag tag = (clsNodeTag) Node.Tag; modMath.sXY_int _int = modMath.PointGetClosestPosOnLine(Args.Connection.PassageNodeA.Pos, Args.Connection.PassageNodeB.Pos, tag.Pos); modMath.sXY_int _int2 = Args.Connection.PassageNodeA.Pos - Args.Connection.PassageNodeB.Pos; float magnitude = (float) _int2.ToDoubles().GetMagnitude(); float num3 = magnitude - Args.RampLength; _int2 = _int - Args.Connection.PassageNodeA.Pos; float num2 = (float) _int2.ToDoubles().GetMagnitude(); float num5 = modMath.Clamp_sng((num2 - (num3 / 2f)) / ((float) Args.RampLength), 0f, 1f); int index = Node.GetLayer_NodeNum; num5 = (float) (1.0 - ((Math.Cos(num5 * 3.1415926535897931) + 1.0) / 2.0)); if ((num5 > 0f) & (num5 < 1f)) { _int2 = tag.Pos - _int; float num6 = (float) _int2.ToDoubles().GetMagnitude(); if (num6 < Args.RampRadius) { float num7 = 1f; if (Args.BaseLevel.NodeLevels[index] == (Args.BaseLevel.NodeLevels[index])) { Args.BaseLevel.NodeLevels[index] = (Args.BaseLevel.NodeLevels[index] * (1f - num7)) + (((Args.Connection.PassageNodeA.Level * (1f - num5)) + (Args.Connection.PassageNodeB.Level * num5)) * num7); } else { Args.BaseLevel.NodeLevels[index] = ((Args.BaseLevel.NodeLevels[index] * (2f - num7)) + (((Args.Connection.PassageNodeA.Level * (1f - num5)) + (Args.Connection.PassageNodeB.Level * num5)) * num7)) / 2f; } } } } else { int num9 = Node.GetChildNodeCount - 1; for (int i = 0; i <= num9; i++) { this.SetBaseLevelRamp(Args, Node.get_GetChildNode(i)); } } }
private void SetBaseLevelRamp(clsSetBaseLevelRampArgs Args, PathfinderNode Node) { if ( Node.GetChildNodeCount == 0 ) { clsNodeTag NodeTag = (clsNodeTag)Node.Tag; sXY_int XY_int = MathUtil.PointGetClosestPosOnLine(Args.Connection.PassageNodeA.Pos, Args.Connection.PassageNodeB.Pos, NodeTag.Pos); float ConnectionLength = Convert.ToSingle((Args.Connection.PassageNodeA.Pos - Args.Connection.PassageNodeB.Pos).ToDoubles().GetMagnitude()); float Extra = ConnectionLength - Args.RampLength; float ConnectionPos = Convert.ToSingle((XY_int - Args.Connection.PassageNodeA.Pos).ToDoubles().GetMagnitude()); float RampPos = MathUtil.Clamp_sng((float)((ConnectionPos - Extra / 2.0F) / Args.RampLength), 0.0F, 1.0F); int Layer_NodeNum = Node.GetLayer_NodeNum; RampPos = (float)(1.0D - (Math.Cos(RampPos * Math.PI) + 1.0D) / 2.0D); if ( RampPos > 0.0F & RampPos < 1.0F ) { float Dist2 = Convert.ToSingle((NodeTag.Pos - XY_int).ToDoubles().GetMagnitude()); if ( Dist2 < Args.RampRadius ) { float Dist2Factor = 1.0F; //Math.Min(3.0F - 3.0F * Dist2 / 384.0F, 1.0F) 'distance fading if ( Args.BaseLevel.NodeLevels[Layer_NodeNum] == Conversion.Int(Args.BaseLevel.NodeLevels[Layer_NodeNum]) ) { Args.BaseLevel.NodeLevels[Layer_NodeNum] = Args.BaseLevel.NodeLevels[Layer_NodeNum] * (1.0F - Dist2Factor) + (Args.Connection.PassageNodeA.Level * (1.0F - RampPos) + Args.Connection.PassageNodeB.Level * RampPos) * Dist2Factor; } else { Args.BaseLevel.NodeLevels[Layer_NodeNum] = (Args.BaseLevel.NodeLevels[Layer_NodeNum] * (2.0F - Dist2Factor) + (Args.Connection.PassageNodeA.Level * (1.0F - RampPos) + Args.Connection.PassageNodeB.Level * RampPos) * Dist2Factor) / 2.0F; } } } } else { int A = 0; for ( A = 0; A <= Node.GetChildNodeCount - 1; A++ ) { SetBaseLevelRamp(Args, Node.get_GetChildNode(A)); } } }
public clsResult GenerateLayoutTerrain() { int num2; int num4; double magnitude; clsNodeTag tag; PathfinderNode node2; int num8; int num9; modMath.sXY_int _int3; clsResult result2 = new clsResult("Terrain heights"); this.Map = new clsMap(this.TileSize); this.GenerateTerrainTiles = new GenerateTerrainTile[(this.Map.Terrain.TileSize.X - 1) + 1, (this.Map.Terrain.TileSize.Y - 1) + 1]; this.GenerateTerrainVertices = new GenerateTerrainVertex[this.Map.Terrain.TileSize.X + 1, this.Map.Terrain.TileSize.Y + 1]; this.VertexPathMap = new PathfinderNetwork(); int y = this.Map.Terrain.TileSize.Y; for (num9 = 0; num9 <= y; num9++) { int x = this.Map.Terrain.TileSize.X; num8 = 0; while (num8 <= x) { this.GenerateTerrainVertices[num8, num9] = new GenerateTerrainVertex(); this.GenerateTerrainVertices[num8, num9].Node = new PathfinderNode(this.VertexPathMap); tag = new clsNodeTag { Pos = new modMath.sXY_int(num8 * 0x80, num9 * 0x80) }; this.GenerateTerrainVertices[num8, num9].Node.Tag = tag; num8++; } } int num12 = this.Map.Terrain.TileSize.Y; for (num9 = 0; num9 <= num12; num9++) { int num13 = this.Map.Terrain.TileSize.X; for (num8 = 0; num8 <= num13; num8++) { PathfinderNode node3; node2 = this.GenerateTerrainVertices[num8, num9].Node; if (num8 > 0) { node3 = this.GenerateTerrainVertices[num8 - 1, num9].Node; this.GenerateTerrainVertices[num8, num9].LeftLink = node2.GetOrCreateConnection(node3, this.GetNodePosDist(node2, node3)); } if (num9 > 0) { if (num8 > 0) { node3 = this.GenerateTerrainVertices[num8 - 1, num9 - 1].Node; this.GenerateTerrainVertices[num8, num9].TopLeftLink = node2.GetOrCreateConnection(node3, this.GetNodePosDist(node2, node3)); } node3 = this.GenerateTerrainVertices[num8, num9 - 1].Node; this.GenerateTerrainVertices[num8, num9].TopLink = node2.GetOrCreateConnection(node3, this.GetNodePosDist(node2, node3)); if (num8 < this.Map.Terrain.TileSize.X) { node3 = this.GenerateTerrainVertices[num8 + 1, num9 - 1].Node; this.GenerateTerrainVertices[num8, num9].TopRightLink = node2.GetOrCreateConnection(node3, this.GetNodePosDist(node2, node3)); } } if (num8 < this.Map.Terrain.TileSize.X) { node3 = this.GenerateTerrainVertices[num8 + 1, num9].Node; this.GenerateTerrainVertices[num8, num9].RightLink = node2.GetOrCreateConnection(node3, this.GetNodePosDist(node2, node3)); } if (num9 < this.Map.Terrain.TileSize.Y) { if (num8 > 0) { node3 = this.GenerateTerrainVertices[num8 - 1, num9 + 1].Node; this.GenerateTerrainVertices[num8, num9].BottomLeftLink = node2.GetOrCreateConnection(node3, this.GetNodePosDist(node2, node3)); } node3 = this.GenerateTerrainVertices[num8, num9 + 1].Node; this.GenerateTerrainVertices[num8, num9].BottomLink = node2.GetOrCreateConnection(node3, this.GetNodePosDist(node2, node3)); if (num8 < this.Map.Terrain.TileSize.X) { node3 = this.GenerateTerrainVertices[num8 + 1, num9 + 1].Node; this.GenerateTerrainVertices[num8, num9].BottomRightLink = node2.GetOrCreateConnection(node3, this.GetNodePosDist(node2, node3)); } } } } this.VertexPathMap.LargeArraysResize(); this.VertexPathMap.FindCalc(); PathfinderLayer layer = this.VertexPathMap.get_GetNodeLayer(0); PathfinderLayer layer2 = this.VertexPathMap.get_GetNodeLayer(this.JitterScale); int num = layer2.GetNodeCount - 1; int[] numArray = new int[num + 1]; clsBaseNodeLevels baseLevel = new clsBaseNodeLevels { NodeLevels = new float[(layer.GetNodeCount - 1) + 1] }; if (num > 0) { int num14 = num; num2 = 0; while (num2 <= num14) { Position.XY_dbl _dbl; node2 = layer2.get_GetNode(num2); num4 = 0; _dbl.X = 0.0; _dbl.Y = 0.0; this.CalcNodePos(node2, ref _dbl, ref num4); tag = new clsNodeTag(); tag.Pos.X = (int) Math.Round((double) (_dbl.X / ((double) num4))); tag.Pos.Y = (int) Math.Round((double) (_dbl.Y / ((double) num4))); node2.Tag = tag; num2++; } } int num15 = layer2.GetNodeCount - 1; for (num = 0; num <= num15; num++) { bool flag; tag = (clsNodeTag) layer2.get_GetNode(num).Tag; numArray[num] = -1; double num3 = 3.4028234663852886E+38; clsConnection connection = null; clsPassageNode passageNodeA = null; int num16 = this.ConnectionCount - 1; num2 = 0; while (num2 <= num16) { if (this.Connections[num2].PassageNodeA.Level == this.Connections[num2].PassageNodeB.Level) { modMath.sXY_int _int2 = modMath.PointGetClosestPosOnLine(this.Connections[num2].PassageNodeA.Pos, this.Connections[num2].PassageNodeB.Pos, tag.Pos) - tag.Pos; magnitude = (float) _int2.ToDoubles().GetMagnitude(); if (magnitude < num3) { num3 = magnitude; _int2 = tag.Pos - this.Connections[num2].PassageNodeA.Pos; _int3 = tag.Pos - this.Connections[num2].PassageNodeB.Pos; if (_int2.ToDoubles().GetMagnitude() <= _int3.ToDoubles().GetMagnitude()) { passageNodeA = this.Connections[num2].PassageNodeA; } else { passageNodeA = this.Connections[num2].PassageNodeB; } flag = true; } } num2++; } int num17 = this.PassageNodeCount - 1; for (num4 = 0; num4 <= num17; num4++) { int num18 = this.SymmetryBlockCount - 1; for (int i = 0; i <= num18; i++) { _int3 = tag.Pos - this.PassageNodes[i, num4].Pos; magnitude = (float) _int3.ToDoubles().GetMagnitude(); if (magnitude < num3) { num3 = magnitude; passageNodeA = this.PassageNodes[i, num4]; flag = true; } } } if (flag) { numArray[num] = passageNodeA.Level; } else { numArray[num] = connection.PassageNodeA.Level; } if (numArray[num] < 0) { result2.ProblemAdd("Error: Node height is not set."); return result2; } } int num19 = this.LevelCount - 1; num = 0; while (num <= num19) { int num20 = layer2.GetNodeCount - 1; num2 = 0; while (num2 <= num20) { if (numArray[num2] >= num) { this.SetBaseLevel(layer2.get_GetNode(num2), num, baseLevel); } num2++; } num++; } int num7 = ((int) Math.Round((double) ((this.LevelHeight * this.Map.HeightMultiplier) * 2.0))) + 0x80; clsSetBaseLevelRampArgs args = new clsSetBaseLevelRampArgs { BaseLevel = baseLevel, RampRadius = 320f }; int num21 = this.ConnectionCount - 1; for (num2 = 0; num2 <= num21; num2++) { args.Connection = this.Connections[num2]; _int3 = this.Connections[num2].PassageNodeA.Pos - this.Connections[num2].PassageNodeB.Pos; args.RampLength = Math.Max((int) Math.Round((double) (_int3.ToDoubles().GetMagnitude() * 0.75)), num7 * Math.Abs((int) (this.Connections[num2].PassageNodeA.Level - this.Connections[num2].PassageNodeB.Level))); int num22 = layer2.GetNodeCount - 1; num = 0; while (num <= num22) { if (this.Connections[num2].IsRamp) { tag = (clsNodeTag) layer2.get_GetNode(num).Tag; _int3 = modMath.PointGetClosestPosOnLine(this.Connections[num2].PassageNodeA.Pos, this.Connections[num2].PassageNodeB.Pos, tag.Pos) - tag.Pos; magnitude = (float) _int3.ToDoubles().GetMagnitude(); if (magnitude < (args.RampLength * 2f)) { this.SetBaseLevelRamp(args, layer2.get_GetNode(num)); } } num++; } } int num23 = layer.GetNodeCount - 1; for (num = 0; num <= num23; num++) { tag = (clsNodeTag) layer.get_GetNode(num).Tag; this.Map.Terrain.Vertices[(int) Math.Round((double) (((float) tag.Pos.X) / 128f)), (int) Math.Round((double) (((float) tag.Pos.Y) / 128f))].Height = (byte) Math.Round((double) (baseLevel.NodeLevels[num] * this.LevelHeight)); } return result2; }
public clsResult GenerateLayoutTerrain() { clsResult ReturnResult = new clsResult("Terrain heights"); clsNodeTag NodeTag = default(clsNodeTag); PathfinderNode tmpNodeA = default(PathfinderNode); PathfinderNode tmpNodeB = default(PathfinderNode); int A = 0; int B = 0; int C = 0; int D = 0; int X = 0; int Y = 0; sXY_int XY_int = new sXY_int(); double Dist = 0; double BestDist = 0; bool Flag = default(bool); Map = new clsMap(TileSize); GenerateTerrainTiles = new GenerateTerrainTile[Map.Terrain.TileSize.X, Map.Terrain.TileSize.Y]; GenerateTerrainVertices = new GenerateTerrainVertex[Map.Terrain.TileSize.X + 1, Map.Terrain.TileSize.Y + 1]; //set terrain heights VertexPathMap = new PathfinderNetwork(); for ( Y = 0; Y <= Map.Terrain.TileSize.Y; Y++ ) { for ( X = 0; X <= Map.Terrain.TileSize.X; X++ ) { GenerateTerrainVertices[X, Y] = new GenerateTerrainVertex(); GenerateTerrainVertices[X, Y].Node = new PathfinderNode(VertexPathMap); NodeTag = new clsNodeTag(); NodeTag.Pos = new sXY_int(X * 128, Y * 128); GenerateTerrainVertices[X, Y].Node.Tag = NodeTag; } } for ( Y = 0; Y <= Map.Terrain.TileSize.Y; Y++ ) { for ( X = 0; X <= Map.Terrain.TileSize.X; X++ ) { tmpNodeA = GenerateTerrainVertices[X, Y].Node; if ( X > 0 ) { tmpNodeB = GenerateTerrainVertices[X - 1, Y].Node; GenerateTerrainVertices[X, Y].LeftLink = tmpNodeA.GetOrCreateConnection(tmpNodeB, GetNodePosDist(tmpNodeA, tmpNodeB)); } if ( Y > 0 ) { if ( X > 0 ) { tmpNodeB = GenerateTerrainVertices[X - 1, Y - 1].Node; GenerateTerrainVertices[X, Y].TopLeftLink = tmpNodeA.GetOrCreateConnection(tmpNodeB, GetNodePosDist(tmpNodeA, tmpNodeB)); } tmpNodeB = GenerateTerrainVertices[X, Y - 1].Node; GenerateTerrainVertices[X, Y].TopLink = tmpNodeA.GetOrCreateConnection(tmpNodeB, GetNodePosDist(tmpNodeA, tmpNodeB)); if ( X < Map.Terrain.TileSize.X ) { tmpNodeB = GenerateTerrainVertices[X + 1, Y - 1].Node; GenerateTerrainVertices[X, Y].TopRightLink = tmpNodeA.GetOrCreateConnection(tmpNodeB, GetNodePosDist(tmpNodeA, tmpNodeB)); } } if ( X < Map.Terrain.TileSize.X ) { tmpNodeB = GenerateTerrainVertices[X + 1, Y].Node; GenerateTerrainVertices[X, Y].RightLink = tmpNodeA.GetOrCreateConnection(tmpNodeB, GetNodePosDist(tmpNodeA, tmpNodeB)); } if ( Y < Map.Terrain.TileSize.Y ) { if ( X > 0 ) { tmpNodeB = GenerateTerrainVertices[X - 1, Y + 1].Node; GenerateTerrainVertices[X, Y].BottomLeftLink = tmpNodeA.GetOrCreateConnection(tmpNodeB, GetNodePosDist(tmpNodeA, tmpNodeB)); } tmpNodeB = GenerateTerrainVertices[X, Y + 1].Node; GenerateTerrainVertices[X, Y].BottomLink = tmpNodeA.GetOrCreateConnection(tmpNodeB, GetNodePosDist(tmpNodeA, tmpNodeB)); if ( X < Map.Terrain.TileSize.X ) { tmpNodeB = GenerateTerrainVertices[X + 1, Y + 1].Node; GenerateTerrainVertices[X, Y].BottomRightLink = tmpNodeA.GetOrCreateConnection(tmpNodeB, GetNodePosDist(tmpNodeA, tmpNodeB)); } } } } VertexPathMap.LargeArraysResize(); VertexPathMap.FindCalc(); PathfinderLayer BaseLayer = VertexPathMap.get_GetNodeLayer(0); PathfinderLayer JitterLayer = VertexPathMap.get_GetNodeLayer(JitterScale); A = JitterLayer.GetNodeCount - 1; int[] NodeLevel = new int[A + 1]; clsBaseNodeLevels BaseNodeLevel = new clsBaseNodeLevels(); BaseNodeLevel.NodeLevels = new float[BaseLayer.GetNodeCount]; //set position of jitter layer nodes Position.XY_dbl XY_dbl = default(Position.XY_dbl); if ( A > 0 ) { for ( B = 0; B <= A; B++ ) { tmpNodeA = JitterLayer.get_GetNode(B); C = 0; XY_dbl.X = 0.0D; XY_dbl.Y = 0.0D; CalcNodePos(tmpNodeA, ref XY_dbl, ref C); NodeTag = new clsNodeTag(); NodeTag.Pos.X = (int)(XY_dbl.X / C); NodeTag.Pos.Y = (int)(XY_dbl.Y / C); tmpNodeA.Tag = NodeTag; } } //set node heights clsConnection BestConnection = default(clsConnection); clsPassageNode BestNode = default(clsPassageNode); for ( A = 0; A <= JitterLayer.GetNodeCount - 1; A++ ) { NodeTag = (clsNodeTag)(JitterLayer.get_GetNode(A).Tag); NodeLevel[A] = -1; BestDist = float.MaxValue; BestConnection = null; BestNode = null; for ( B = 0; B <= ConnectionCount - 1; B++ ) { //If Not (Connections(B).PassageNodeA.IsOnBorder Or Connections(B).PassageNodeB.IsOnBorder) Then if ( Connections[B].PassageNodeA.Level == Connections[B].PassageNodeB.Level ) { //only do this if the levels are the same //this is to make sure nodes that are connected are actually connected on the terrain XY_int = MathUtil.PointGetClosestPosOnLine(Connections[B].PassageNodeA.Pos, Connections[B].PassageNodeB.Pos, NodeTag.Pos); Dist = Convert.ToSingle((XY_int - NodeTag.Pos).ToDoubles().GetMagnitude()); if ( Dist < BestDist ) { BestDist = Dist; if ( (NodeTag.Pos - Connections[B].PassageNodeA.Pos).ToDoubles().GetMagnitude() <= (NodeTag.Pos - Connections[B].PassageNodeB.Pos).ToDoubles().GetMagnitude() ) { BestNode = Connections[B].PassageNodeA; } else { BestNode = Connections[B].PassageNodeB; } Flag = true; } } } for ( C = 0; C <= PassageNodeCount - 1; C++ ) { //If Not PassageNodesA(C).IsOnBorder Then for ( D = 0; D <= SymmetryBlockCount - 1; D++ ) { Dist = Convert.ToSingle((NodeTag.Pos - PassageNodes[D, C].Pos).ToDoubles().GetMagnitude()); if ( Dist < BestDist ) { BestDist = Dist; BestNode = PassageNodes[D, C]; Flag = true; } } //End If } if ( Flag ) { NodeLevel[A] = BestNode.Level; } else { NodeLevel[A] = BestConnection.PassageNodeA.Level; } if ( NodeLevel[A] < 0 ) { ReturnResult.ProblemAdd("Error: Node height is not set."); return ReturnResult; } } for ( A = 0; A <= LevelCount - 1; A++ ) { for ( B = 0; B <= JitterLayer.GetNodeCount - 1; B++ ) { if ( NodeLevel[B] >= A ) { SetBaseLevel(JitterLayer.get_GetNode(B), A, BaseNodeLevel); } } } //make ramp slopes int MinRampLength = ((int)(LevelHeight * Map.HeightMultiplier * 2.0D)) + 128; clsSetBaseLevelRampArgs RampArgs = new clsSetBaseLevelRampArgs(); RampArgs.BaseLevel = BaseNodeLevel; RampArgs.RampRadius = 320.0F; for ( B = 0; B <= ConnectionCount - 1; B++ ) { RampArgs.Connection = Connections[B]; RampArgs.RampLength = Math.Max(Convert.ToInt32((Connections[B].PassageNodeA.Pos - Connections[B].PassageNodeB.Pos).ToDoubles().GetMagnitude() * 0.75D), MinRampLength * Math.Abs(Connections[B].PassageNodeA.Level - Connections[B].PassageNodeB.Level)); for ( A = 0; A <= JitterLayer.GetNodeCount - 1; A++ ) { if ( Connections[B].IsRamp ) { NodeTag = (clsNodeTag)(JitterLayer.get_GetNode(A).Tag); XY_int = MathUtil.PointGetClosestPosOnLine(Connections[B].PassageNodeA.Pos, Connections[B].PassageNodeB.Pos, NodeTag.Pos); Dist = Convert.ToSingle((XY_int - NodeTag.Pos).ToDoubles().GetMagnitude()); if ( Dist < RampArgs.RampLength * 2.0F ) { SetBaseLevelRamp(RampArgs, JitterLayer.get_GetNode(A)); } } } } for ( A = 0; A <= BaseLayer.GetNodeCount - 1; A++ ) { NodeTag = (clsNodeTag)(BaseLayer.get_GetNode(A).Tag); Map.Terrain.Vertices[(int)(NodeTag.Pos.X / 128.0F), (int)(NodeTag.Pos.Y / 128.0F)].Height = (byte)(BaseNodeLevel.NodeLevels[A] * LevelHeight); } return ReturnResult; }