public PathfinderConnection(PathfinderConnection SourceConnection) { this.Layer_ConnectionNum = -1; this.NodeA_ConnectionNum = -1; this.NodeB_ConnectionNum = -1; this.Value = 1f; this.CalcValueNum = -1; this.NodeA = SourceConnection.NodeA.ParentNode; this.NodeB = SourceConnection.NodeB.ParentNode; this.NodeA.Connection_Add(this, ref this.NodeA_ConnectionNum); this.NodeB.Connection_Add(this, ref this.NodeB_ConnectionNum); this.NodeA.Layer.Connection_Add(this); this.ValueCalc(); }
public PathfinderConnection(PathfinderNode NewNodeA, PathfinderNode NewNodeB, float NewValue) { this.Layer_ConnectionNum = -1; this.NodeA_ConnectionNum = -1; this.NodeB_ConnectionNum = -1; this.Value = 1f; this.CalcValueNum = -1; if (((NewNodeA.Layer.Network_LayerNum > 0) | (NewNodeB.Layer.Network_LayerNum > 0)) | (NewValue <= 0f)) { Debugger.Break(); } else { this.Value = NewValue; this.LinkCount = 1; this.NodeA = NewNodeA; this.NodeB = NewNodeB; this.NodeA.Connection_Add(this, ref this.NodeA_ConnectionNum); this.NodeB.Connection_Add(this, ref this.NodeB_ConnectionNum); this.NodeA.Layer.Connection_Add(this); this.RaiseDependant(); } }
public Path[] GetAllPaths(PathfinderNode[] StartNodes, PathfinderNode FinishNode, int MinClearance) { int num4; int num7; sFloodRouteAllArgs args; int num10 = StartNodes.GetUpperBound(0) + 1; PathfinderNode[,] nodeArray3 = new PathfinderNode[0x20, (num10 - 1) + 1]; PathfinderNode[] nodeArray2 = new PathfinderNode[0x20]; PathfinderNode[] nodeArray = new PathfinderNode[0x18]; bool[] flagArray = new bool[(num10 - 1) + 1]; Path[] pathArray2 = new Path[0x20]; PathfinderNode[] nodeArray4 = this.NetworkLargeArrays.Nodes_Nodes; bool[] flagArray2 = this.NetworkLargeArrays.Nodes_Booleans; float[] numArray = this.NetworkLargeArrays.Nodes_ValuesA; float[] numArray2 = this.NetworkLargeArrays.Nodes_ValuesB; int index = StartNodes[0].Layer.Network_LayerNum; nodeArray2[index] = FinishNode; int num2 = index; while (true) { if (nodeArray2[num2].ParentNode == null) { num7 = num2; break; } nodeArray2[num2 + 1] = nodeArray2[num2].ParentNode; num2++; } int num11 = num10 - 1; int num = 0; while (num <= num11) { nodeArray3[index, num] = StartNodes[num]; num2 = index; while (true) { if (nodeArray3[num2, num].ParentNode == null) { if (nodeArray3[num2, num] == nodeArray2[num2]) { flagArray[num] = true; num4++; } break; } nodeArray3[num2 + 1, num] = nodeArray3[num2, num].ParentNode; num2++; } num++; } if (num4 == 0) { return null; } int num9 = num7; pathArray2[num9] = new Path(); pathArray2[num9].Nodes = new PathfinderNode[] { nodeArray2[num9] }; pathArray2[num9].NodeCount = 1; do { int num3; PathfinderNode node; int num8 = num9; num9--; if (num9 < index) { return pathArray2; } int num12 = pathArray2[num8].NodeCount - 1; num = 0; while (num <= num12) { node = pathArray2[num8].Nodes[num]; int num13 = node.ConnectionCount - 1; for (num2 = 0; num2 <= num13; num2++) { num3 = node.Connections[num2].GetOtherNode(node).Layer_NodeNum; flagArray2[num3] = false; } num++; } int num14 = pathArray2[num8].NodeCount - 1; num = 0; while (num <= num14) { node = pathArray2[num8].Nodes[num]; num3 = node.Layer_NodeNum; flagArray2[num3] = true; int num15 = node.NodeCount - 1; for (int i = 0; i <= num15; i++) { num3 = node.Nodes[i].Layer_NodeNum; numArray[num3] = float.MaxValue; numArray2[num3] = float.MaxValue; } num++; } args = new sFloodRouteAllArgs { FinishNode = nodeArray2[num9], Visit = flagArray2, NodeValuesA = numArray, SourceNodes = nodeArray4, NodeValuesB = numArray2, MinClearance = MinClearance, BestTolerance = (float) Math.Pow(1.1, (double) num9), StartNodes = new PathfinderNode[(num10 - 1) + 1] }; int num16 = num10 - 1; num = 0; while (num <= num16) { if (flagArray[num]) { args.StartNodes[args.StartNodeCount] = nodeArray3[num9, num]; args.StartNodeCount++; } num++; } args.StartNodes = (PathfinderNode[]) Utils.CopyArray((Array) args.StartNodes, new PathfinderNode[(args.StartNodeCount - 1) + 1]); this.FloodRouteAll(ref args); pathArray2[num9] = new Path(); pathArray2[num9].Nodes = new PathfinderNode[(args.BestNodeCount - 1) + 1]; int num17 = args.BestNodeCount - 1; for (num = 0; num <= num17; num++) { pathArray2[num9].Nodes[num] = args.SourceNodes[num]; } pathArray2[num9].NodeCount = args.BestNodeCount; } while (args.BestNodeCount != 0); Debugger.Break(); return pathArray2; }
public void ChangedNode_Add(PathfinderNode NewChangedNode) { if (NewChangedNode.Layer_ChangedNodeNum < 0) { if (this.ChangedNodes.GetUpperBound(0) < this.ChangedNodeCount) { this.ChangedNodes = (PathfinderNode[]) Utils.CopyArray((Array) this.ChangedNodes, new PathfinderNode[((this.ChangedNodeCount * 2) + 1) + 1]); } this.ChangedNodes[this.ChangedNodeCount] = NewChangedNode; this.ChangedNodes[this.ChangedNodeCount].Layer_ChangedNodeNum = this.ChangedNodeCount; this.ChangedNodeCount++; } }
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 PathfinderNode GetNearestNodeConnection(PathfinderNetwork Network, modMath.sXY_int Pos, int MinClearance, float MaxDistance) { PathfinderNode[] nodeArray = new PathfinderNode[((Network.get_GetNodeLayer(0).GetNodeCount * 10) - 1) + 1]; float[] numArray = new float[(Network.get_GetNodeLayer(0).GetNodeCount - 1) + 1]; int index = 0; PathfinderNode node = null; int num5 = Network.get_GetNodeLayer(0).GetNodeCount - 1; int num = 0; while (num <= num5) { numArray[num] = float.MaxValue; num++; } nodeArray[0] = this.GetNearestNode(Network, Pos, 1); if (nodeArray[0] == null) { return null; } int num3 = 1; numArray[nodeArray[0].Layer_NodeNum] = 0f; while (index < num3) { PathfinderNode self = nodeArray[index]; if (self.Clearance >= MinClearance) { if (node == null) { node = self; } else if (numArray[self.Layer_NodeNum] < numArray[node.Layer_NodeNum]) { node = self; } } int num6 = self.GetConnectionCount - 1; for (num = 0; num <= num6; num++) { bool flag; PathfinderConnection connection = self.get_GetConnection(num); PathfinderNode otherNode = connection.GetOtherNode(self); float num2 = numArray[self.Layer_NodeNum] + connection.GetValue; if (node == null) { flag = true; } else if (num2 < numArray[node.Layer_NodeNum]) { flag = true; } else { flag = false; } if (flag & (num2 < numArray[otherNode.Layer_NodeNum])) { numArray[otherNode.Layer_NodeNum] = num2; nodeArray[num3] = otherNode; num3++; } } index++; } return node; }
public float GetNodePosDist(PathfinderNode NodeA, PathfinderNode NodeB) { clsNodeTag tag = (clsNodeTag) NodeA.Tag; clsNodeTag tag2 = (clsNodeTag) NodeB.Tag; modMath.sXY_int _int = tag.Pos - tag2.Pos; return (float) _int.ToDoubles().GetMagnitude(); }
public clsResult GenerateOil() { int num; int num2; int num6; clsPassageNode[,] passageNodes; int num17; int num18; clsResult result2 = new clsResult("Oil"); int num7 = this.PassageNodeCount - 1; for (num = 0; num <= num7; num++) { int num8 = this.SymmetryBlockCount - 1; num2 = 0; while (num2 <= num8) { this.PassageNodes[num2, num].OilCount = 0; num2++; } } clsPassageNodeNework nework = this.MakePassageNodeNetwork(); PathfinderNode[] startNodes = new PathfinderNode[1]; this.PassageNodeDists = new float[(this.SymmetryBlockCount - 1) + 1, (this.PassageNodeCount - 1) + 1, (this.SymmetryBlockCount - 1) + 1, (this.PassageNodeCount - 1) + 1]; int num9 = this.PassageNodeCount - 1; for (num = 0; num <= num9; num++) { int num10 = this.SymmetryBlockCount - 1; for (int i = 0; i <= num10; i++) { this.PassageNodeDists[i, num, i, num] = 0f; int num11 = this.PassageNodeCount - 1; num2 = 0; while (num2 <= num11) { int num12 = this.SymmetryBlockCount - 1; for (int j = 0; j <= num12; j++) { if ((this.PassageNodes[0, num].IsWater | this.PassageNodes[j, num2].IsWater) | ((j != 0) & (i != 0))) { this.PassageNodeDists[i, num, j, num2] = float.MaxValue; this.PassageNodeDists[j, num2, i, num] = float.MaxValue; } else { startNodes[0] = nework.PassageNodePathNodes[i, num]; PathfinderNetwork.PathList[] listArray = nework.Network.GetPath(startNodes, nework.PassageNodePathNodes[j, num2], -1, 0); if (listArray == null) { result2.ProblemAdd("Map is not all connected."); nework.Network.Deallocate(); return result2; } if (listArray[0].PathCount != 1) { Debugger.Break(); } this.PassageNodeDists[i, num, j, num2] = listArray[0].Paths[0].Value; this.PassageNodeDists[j, num2, i, num] = listArray[0].Paths[0].Value; } } num2++; } } } nework.Network.Deallocate(); int num5 = 1; int num13 = this.OilAtATime - 1; num = 0; while (num <= num13) { num5 *= this.PassageNodeCount; num++; } clsOilBalanceLoopArgs args = new clsOilBalanceLoopArgs { OilClusterSizes = new int[(this.OilAtATime - 1) + 1], PlayerOilScore = new double[(this.TopLeftPlayerCount - 1) + 1], OilNodes = new clsPassageNode[(this.OilAtATime - 1) + 1] }; while (num6 < this.ExtraOilCount) { int num14 = this.OilAtATime - 1; num = 0; while (num <= num14) { args.OilClusterSizes[num] = Math.Min(this.ExtraOilClusterSizeMin + ((int) Math.Round((double) ((float) (App.Random.Next() * ((this.ExtraOilClusterSizeMax - this.ExtraOilClusterSizeMin) + 1))))), Math.Max((int) Math.Round(Math.Ceiling((double) (((double) (this.ExtraOilCount - num6)) / ((double) this.SymmetryBlockCount)))), 1)); num++; } args.OilPossibilities = new clsOilPossibilities(); this.OilBalanceLoop(args, 0); clsOilPossibilities.clsPossibility bestPossibility = args.OilPossibilities.BestPossibility; if (bestPossibility != null) { int num15 = this.OilAtATime - 1; num2 = 0; while (num2 <= num15) { int num16 = this.SymmetryBlockCount - 1; num = 0; while (num <= num16) { passageNodes = this.PassageNodes; num17 = num; num18 = bestPossibility.Nodes[num2].Num; passageNodes[num17, num18].OilCount += args.OilClusterSizes[num2]; num++; } num6 += args.OilClusterSizes[num2] * this.SymmetryBlockCount; num2++; } int num19 = this.TopLeftPlayerCount - 1; num = 0; while (num <= num19) { double[] playerOilScore = args.PlayerOilScore; num18 = num; playerOilScore[num18] += bestPossibility.PlayerOilScoreAddition[num]; num++; } } else { result2.WarningAdd("Could not place all of the oil. " + Conversions.ToString(num6) + " oil was placed."); break; } } int num20 = this.TopLeftPlayerCount - 1; for (num = 0; num <= num20; num++) { int num21 = this.SymmetryBlockCount - 1; for (num2 = 0; num2 <= num21; num2++) { passageNodes = this.PassageNodes; num18 = num2; num17 = this.PlayerBases[num].Nodes[0].Num; passageNodes[num18, num17].OilCount += this.BaseOilCount; } } return result2; }
public void Split() { int num; PathfinderNode parentNode; if (this.NodeCount != 4) { Debugger.Break(); } PathfinderNode nodeToAdd = null; PathfinderNode node2 = null; PathfinderNode node3 = null; PathfinderNode node4 = null; PathfinderConnection connection = null; PathfinderConnection connection2 = null; PathfinderNode[] nodeArray = new PathfinderNode[(this.NodeCount - 1) + 1]; int num8 = this.NodeCount - 1; for (num = 0; num <= num8; num++) { nodeArray[num] = this.Nodes[num]; } int nodeCount = this.NodeCount; PathfinderLayer newParentLayer = this.Layer; this.Disband(); float maxValue = float.MaxValue; int num9 = nodeCount - 1; for (num = 0; num <= num9; num++) { parentNode = nodeArray[num]; int num10 = nodeCount - 1; for (int i = num + 1; i <= num10; i++) { PathfinderNode node6 = nodeArray[i]; int num11 = nodeCount - 1; int index = 0; while (index <= num11) { if ((nodeArray[index] != parentNode) & (nodeArray[index] != node6)) { break; } index++; } PathfinderNode self = nodeArray[index]; int num12 = nodeCount - 1; int num6 = index + 1; while (num6 <= num12) { if ((nodeArray[num6] != parentNode) & (nodeArray[num6] != node6)) { break; } num6++; } PathfinderNode node8 = nodeArray[num6]; int num13 = parentNode.ConnectionCount - 1; index = 0; while (index <= num13) { connection = parentNode.Connections[index]; if (connection.GetOtherNode(parentNode) == node6) { break; } index++; } int num14 = self.ConnectionCount - 1; num6 = 0; while (num6 <= num14) { connection2 = self.Connections[num6]; if (connection2.GetOtherNode(self) == node8) { break; } num6++; } if ((index < parentNode.ConnectionCount) & (num6 < self.ConnectionCount)) { float num7 = connection.Value + connection2.Value; if (num7 < maxValue) { maxValue = num7; nodeToAdd = parentNode; node2 = node6; node3 = self; node4 = node8; } } } } if (nodeToAdd != null) { if (this.ParentNode != null) { parentNode = this.ParentNode; parentNode.Node_Remove(this.ParentNode_NodeNum); } else { parentNode = null; } if (parentNode != null) { parentNode.CheckIntegrity(); } PathfinderNode newFindParentNode = new PathfinderNode(newParentLayer); PathfinderNode node10 = new PathfinderNode(newParentLayer); newFindParentNode.Node_Add(nodeToAdd); newFindParentNode.Node_Add(node2); newFindParentNode.SpanCalc(); nodeToAdd.RaiseConnections(); node2.RaiseConnections(); newFindParentNode.Layer.Network.FindParentNode_Add(newFindParentNode); node10.Node_Add(node3); node10.Node_Add(node4); node10.SpanCalc(); node3.RaiseConnections(); node4.RaiseConnections(); node10.Layer.Network.FindParentNode_Add(node10); } else { Debugger.Break(); } }
private void RemoveFromNodes() { this.NodeA.Connection_Remove(this.NodeA_ConnectionNum); this.NodeA = null; this.NodeA_ConnectionNum = -1; this.NodeB.Connection_Remove(this.NodeB_ConnectionNum); this.NodeB = null; this.NodeB_ConnectionNum = -1; }
public PathfinderNode GetOtherNode(PathfinderNode Self) { if (this.NodeA == Self) { return this.NodeB; } return this.NodeA; }
public void ForceDeallocate() { this.DependantConnection = null; this.NodeA = null; this.NodeB = null; }
public bool NodeCanReachNode(PathfinderNode StartNode, PathfinderNode FinishNode) { PathfinderNode parentNode = StartNode; PathfinderNode node = FinishNode; do { if (parentNode == node) { return true; } parentNode = parentNode.ParentNode; if (parentNode == null) { return false; } node = node.ParentNode; } while (node != null); return false; }
public PathList[] GetPath(PathfinderNode[] StartNodes, PathfinderNode FinishNode, int Accuracy, int MinClearance) { int num; int num4; int num9; int num13 = StartNodes.GetUpperBound(0) + 1; PathList[] listArray2 = new PathList[(this.NodeLayerCount - 1) + 1]; PathfinderNode[,] nodeArray3 = new PathfinderNode[(this.NodeLayerCount - 1) + 1, (num13 - 1) + 1]; PathfinderNode[] nodeArray2 = new PathfinderNode[(this.NodeLayerCount - 1) + 1]; PathfinderNode[] nodeArray = new PathfinderNode[0x18]; int[] numArray2 = new int[0x18]; bool[] flagArray = new bool[(num13 - 1) + 1]; Path[] pathArray = new Path[0x18]; float[] numArray = new float[0x18]; bool[] flagArray2 = this.NetworkLargeArrays.Nodes_Booleans; float[] numArray3 = this.NetworkLargeArrays.Nodes_ValuesA; PathfinderNode[] nodeArray4 = this.NetworkLargeArrays.Nodes_Nodes; Path path = this.NetworkLargeArrays.Nodes_Path; int index = StartNodes[0].Layer.Network_LayerNum; nodeArray2[index] = FinishNode; int num2 = index; while (true) { if (nodeArray2[num2].ParentNode == null) { num9 = num2; break; } nodeArray2[num2 + 1] = nodeArray2[num2].ParentNode; num2++; } int num14 = num13 - 1; for (num = 0; num <= num14; num++) { nodeArray3[index, num] = StartNodes[num]; num2 = index; while (true) { if (nodeArray3[num2, num].ParentNode == null) { if (nodeArray3[num2, num] == nodeArray2[num2]) { flagArray[num] = true; num4++; } break; } nodeArray3[num2 + 1, num] = nodeArray3[num2, num].ParentNode; num2++; } } if (num4 != 0) { int num11 = num9; listArray2[num11].Paths = new Path[] { new Path() }; listArray2[num11].PathCount = 1; listArray2[num11].Paths[0].Nodes = new PathfinderNode[] { nodeArray2[num11] }; listArray2[num11].Paths[0].NodeCount = 1; do { int num3; int num5; int num6; int num7; bool flag; int num12; bool flag3; PathfinderNode node; PathfinderNode otherNode; int num10 = num11; num11--; if (num11 < index) { return listArray2; } if (flag3) { if (Accuracy < 0) { Debugger.Break(); } int num15 = listArray2[num10].PathCount - 1; for (num12 = 0; num12 <= num15; num12++) { numArray2[num12] = Math.Min(Accuracy, listArray2[num10].Paths[num12].NodeCount - 1); } nodeArray[0] = listArray2[num10].Paths[0].Nodes[numArray2[0]]; num6 = 1; flag = true; } else { if (Accuracy >= 0) { int num16 = listArray2[num10].PathCount - 1; for (num12 = 0; num12 <= num16; num12++) { if (listArray2[num10].Paths[num12].NodeCount > Accuracy) { flag3 = true; break; } } } nodeArray[0] = nodeArray2[num11]; if (num11 == index) { num6 = 1; } else { int num17 = nodeArray[0].ConnectionCount - 1; num = 0; while (num <= num17) { nodeArray[1 + num] = nodeArray[0].Connections[num].GetOtherNode(nodeArray[0]); num++; } num6 = 1 + nodeArray[0].ConnectionCount; } int num18 = listArray2[num10].PathCount - 1; for (num12 = 0; num12 <= num18; num12++) { numArray2[num12] = listArray2[num10].Paths[num12].NodeCount - 1; } flag = false; } int num19 = listArray2[num10].PathCount - 1; for (num12 = 0; num12 <= num19; num12++) { int num20 = numArray2[num12]; num = 0; while (num <= num20) { node = listArray2[num10].Paths[num12].Nodes[num]; int num21 = node.ConnectionCount - 1; num5 = 0; while (num5 <= num21) { otherNode = node.Connections[num5].GetOtherNode(node); int num22 = otherNode.ConnectionCount - 1; num7 = 0; while (num7 <= num22) { num3 = otherNode.Connections[num7].GetOtherNode(otherNode).Layer_NodeNum; flagArray2[num3] = false; num7++; } num5++; } num++; } } int num23 = listArray2[num10].PathCount - 1; num12 = 0; while (num12 <= num23) { int num24 = numArray2[num12]; num = 0; while (num <= num24) { node = listArray2[num10].Paths[num12].Nodes[num]; num3 = node.Layer_NodeNum; flagArray2[num3] = true; int num25 = node.NodeCount - 1; num7 = 0; while (num7 <= num25) { num3 = node.Nodes[num7].Layer_NodeNum; numArray3[num3] = float.MaxValue; num7++; } int num26 = node.ConnectionCount - 1; for (num5 = 0; num5 <= num26; num5++) { otherNode = node.Connections[num5].GetOtherNode(node); num3 = otherNode.Layer_NodeNum; flagArray2[num3] = true; int num27 = otherNode.NodeCount - 1; for (num7 = 0; num7 <= num27; num7++) { num3 = otherNode.Nodes[num7].Layer_NodeNum; numArray3[num3] = float.MaxValue; } } num++; } num12++; } sFloodRouteArgs args = new sFloodRouteArgs { CurrentPath = path, FinishNodes = nodeArray, FinishNodeCount = num6, FinishIsParent = flag, Visit = flagArray2, NodeValues = numArray3, SourceNodes = nodeArray4, MinClearance = MinClearance }; int num28 = num6 - 1; for (num = 0; num <= num28; num++) { pathArray[num] = null; numArray[num] = float.MaxValue; } int num29 = num13 - 1; for (num = 0; num <= num29; num++) { if (flagArray[num]) { path.NodeCount = 1; path.Nodes[0] = nodeArray3[num11, num]; path.Value = 0f; args.BestPaths = new Path[(num6 - 1) + 1]; this.FloodRoute(ref args); int num30 = num6 - 1; num12 = 0; while (num12 <= num30) { if ((args.BestPaths[num12] != null) && (args.BestPaths[num12].Value < numArray[num12])) { numArray[num12] = args.BestPaths[num12].Value; pathArray[num12] = args.BestPaths[num12]; } num12++; } } } listArray2[num11].Paths = new Path[(num6 - 1) + 1]; listArray2[num11].PathCount = 0; int num31 = num6 - 1; for (num12 = 0; num12 <= num31; num12++) { if (pathArray[num12] != null) { listArray2[num11].Paths[listArray2[num11].PathCount] = pathArray[num12]; PathList[] listArray3 = listArray2; int num32 = num11; listArray3[num32].PathCount++; } } listArray2[num11].Paths = (Path[]) Utils.CopyArray((Array) listArray2[num11].Paths, new Path[(listArray2[num11].PathCount - 1) + 1]); } while (listArray2[num11].PathCount != 0); } return null; }
public void FindCalc() { while (this.FindParentNodeCount > 0) { int num3; int[] numArray = new int[(this.FindParentNodeCount - 1) + 1]; int findParentNodeCount = this.FindParentNodeCount; PathfinderNode[] nodeArray = new PathfinderNode[(findParentNodeCount - 1) + 1]; int num6 = this.FindParentNodeCount - 1; int num = 0; while (num <= num6) { numArray[num3] = num3; num3++; num++; } int num7 = this.FindParentNodeCount - 1; num = 0; while (num <= num7) { int num4 = (int) Math.Round((double) Conversion.Int((float) (VBMath.Rnd() * num3))); nodeArray[numArray[num4]] = this.FindParentNodes[num]; num3--; if (num4 < num3) { numArray[num4] = numArray[num3]; } num++; } int num8 = findParentNodeCount - 1; for (num = 0; num <= num8; num++) { if (nodeArray[num].Network_FindParentNum >= 0) { if (nodeArray[num].ParentNode == null) { nodeArray[num].FindParent(); } this.FindParentNode_Remove(nodeArray[num].Network_FindParentNum); } } } int index = this.NodeLayerCount - 1; while (true) { if (this.NodeLayers[index].NodeCount > 0) { break; } this.NodeLayers[index].Network_LayerNum = -1; if (index == 0) { break; } this.NodeLayers[index - 1].ParentLayer = null; index--; } if (index < (this.NodeLayerCount - 1)) { this.NodeLayers = (PathfinderLayer[]) Utils.CopyArray((Array) this.NodeLayers, new PathfinderLayer[index + 1]); this.NodeLayerCount = index + 1; } }
public PathfinderConnection GetOrCreateConnection(PathfinderNode OtherNode, float Value) { if (OtherNode.Layer != this.Layer) { return null; } PathfinderConnection connection2 = this.FindConnection(OtherNode); if (connection2 == null) { return new PathfinderConnection(this, OtherNode, Value); } return connection2; }
public void Node_Add(PathfinderNode NodeToAdd) { if (this.Layer == null) { Debugger.Break(); } else if (NodeToAdd.Layer.Network_LayerNum != (this.Layer.Network_LayerNum - 1)) { Debugger.Break(); } else if (NodeToAdd.ParentNode != null) { Debugger.Break(); } else { if (this.Layer_ChangedNodeNum < 0) { this.Layer.ChangedNode_Add(this); } NodeToAdd.ParentNode = this; NodeToAdd.ParentNode_NodeNum = this.NodeCount; this.Nodes[this.NodeCount] = NodeToAdd; this.NodeCount++; if (NodeToAdd.ConnectionCount == 0) { Debugger.Break(); } if (NodeToAdd.Clearance > this.Clearance) { this.ClearanceSet(this.Clearance); } else { this.ClearanceCalc(); } } }
public void CheckIntegrity() { int num; PathfinderNode[] nodeArray; if (this.NodeCount >= 2) { sVisited visited; visited.Visited = new bool[(this.NodeCount - 1) + 1]; this.FloodCheckInternal(this.Nodes[0], ref visited); int num4 = this.NodeCount - 1; for (int i = 0; i <= num4; i++) { if (!visited.Visited[i]) { goto Label_00BF; } } } if (!((this.NodeCount == 1) & (this.ConnectionCount == 0))) { if (this.NodeCount > 1) { this.SpanCalc(); return; } if (this.NodeCount == 0) { if (this.ParentNode != null) { PathfinderNode parentNode = this.ParentNode; parentNode.Node_Remove(this.ParentNode_NodeNum); parentNode.CheckIntegrity(); } if (this.Layer.Network_LayerNum > 0) { this.Deallocate(); } return; } return; } Label_00BF: nodeArray = new PathfinderNode[(this.NodeCount - 1) + 1]; int num5 = this.NodeCount - 1; for (num = 0; num <= num5; num++) { nodeArray[num] = this.Nodes[num]; } int nodeCount = this.NodeCount; this.Disband(); int num6 = nodeCount - 1; for (num = 0; num <= num6; num++) { nodeArray[num].Layer.Network.FindParentNode_Add(nodeArray[num]); } }
public void CalcNodePos(PathfinderNode Node, ref Position.XY_dbl Pos, ref int SampleCount) { if (Node.GetLayer.GetNetwork_LayerNum == 0) { clsNodeTag tag = (clsNodeTag) Node.Tag; Pos.X += tag.Pos.X; Pos.Y += tag.Pos.Y; } else { int num2 = Node.GetChildNodeCount - 1; for (int i = 0; i <= num2; i++) { this.CalcNodePos(Node.get_GetChildNode(i), ref Pos, ref SampleCount); } SampleCount += Node.GetChildNodeCount; } }
public PathfinderConnection CreateConnection(PathfinderNode OtherNode, float Value) { if ((OtherNode.Layer == this.Layer) && (this.FindConnection(OtherNode) == null)) { return new PathfinderConnection(this, OtherNode, Value); } return null; }
public clsResult GenerateRamps() { int num; int num6; int num7; int num9; clsResult result2 = new clsResult("Ramps"); int num13 = this.ConnectionCount - 1; for (num = 0; num <= num13; num++) { this.Connections[num].IsRamp = false; } clsPassageNodeNework nework = this.MakePassageNodeNetwork(); PathfinderNode[,] passageNodePathNodes = nework.PassageNodePathNodes; clsConnection[] connectionArray = new clsConnection[(this.ConnectionCount - 1) + 1]; PathfinderNode[] startNodes = new PathfinderNode[1]; bool[] flagArray = new bool[(this.ConnectionCount - 1) + 1]; int num14 = this.ConnectionCount - 1; int index = 0; while (index <= num14) { if (Math.Abs((int) (this.Connections[index].PassageNodeA.Level - this.Connections[index].PassageNodeB.Level)) == 1) { if ((!(this.Connections[index].PassageNodeA.IsOnBorder | this.Connections[index].PassageNodeB.IsOnBorder) & (this.Connections[index].PassageNodeA.MirrorNum == 0)) & (this.Connections[index].PassageNodeA.Num != this.Connections[index].PassageNodeB.Num)) { flagArray[index] = true; } else { flagArray[index] = false; } } else { flagArray[index] = false; } index++; } clsNodeConnectedness connectedness = new clsNodeConnectedness { NodeConnectedness = new float[(this.PassageNodeCount - 1) + 1], PassageNodeVisited = new bool[(this.SymmetryBlockCount - 1) + 1, (this.PassageNodeCount - 1) + 1], PassageNodePathNodes = passageNodePathNodes, PassageNodePathMap = nework.Network }; PathfinderConnection[] connectionArray2 = new PathfinderConnection[4]; clsUpdateNodeConnectednessArgs args3 = new clsUpdateNodeConnectednessArgs(); clsUpdateNetworkConnectednessArgs args2 = new clsUpdateNetworkConnectednessArgs(); args3.Args = connectedness; args2.Args = connectedness; args2.PassageNodeUpdated = new bool[(this.PassageNodeCount - 1) + 1]; args2.SymmetryBlockCount = this.SymmetryBlockCount; int num15 = this.PassageNodeCount - 1; for (num = 0; num <= num15; num++) { connectedness.NodeConnectedness[num] = 0f; int num16 = this.PassageNodeCount - 1; for (index = 0; index <= num16; index++) { int num17 = this.SymmetryBlockCount - 1; num7 = 0; while (num7 <= num17) { connectedness.PassageNodeVisited[num7, index] = false; num7++; } } args3.OriginalNode = this.PassageNodes[0, num]; this.UpdateNodeConnectedness(args3, this.PassageNodes[0, num]); } Label_0269: num6 = -1; double num4 = 1.0; double num5 = 0.0; int num10 = 0; int num18 = this.ConnectionCount - 1; index = 0; while (index <= num18) { if (flagArray[index] & !this.Connections[index].IsRamp) { if (this.CheckRampAngles(this.Connections[index], 1.3962634015954636, 2.0943951023931953, 0.0)) { modMath.sXY_int _int; startNodes[0] = passageNodePathNodes[this.Connections[index].PassageNodeA.MirrorNum, this.Connections[index].PassageNodeA.Num]; PathfinderNetwork.PathList[] listArray = nework.Network.GetPath(startNodes, passageNodePathNodes[this.Connections[index].PassageNodeB.MirrorNum, this.Connections[index].PassageNodeB.Num], -1, 0); double maxValue = double.MaxValue; _int.X = (int) Math.Round((double) (((double) (this.Connections[index].PassageNodeA.Pos.X + this.Connections[index].PassageNodeB.Pos.X)) / 2.0)); _int.Y = (int) Math.Round((double) (((double) (this.Connections[index].PassageNodeA.Pos.Y + this.Connections[index].PassageNodeB.Pos.Y)) / 2.0)); int num19 = this.TotalPlayerCount - 1; num9 = 0; while (num9 <= num19) { modMath.sXY_int _int2 = this.PlayerBases[num9].Pos - _int; double magnitude = _int2.ToDoubles().GetMagnitude(); if (magnitude < maxValue) { maxValue = magnitude; } num9++; } double num11 = Math.Max((double) (this.MaxDisconnectionDist * Math.Pow(this.RampBase, maxValue / 1024.0)), (double) 1.0); if (listArray == null) { double num12 = connectedness.NodeConnectedness[this.Connections[index].PassageNodeA.Num] + connectedness.NodeConnectedness[this.Connections[index].PassageNodeB.Num]; if (double.MaxValue > num4) { num4 = double.MaxValue; num5 = num12; connectionArray[0] = this.Connections[index]; num10 = 1; } else if (num12 < num5) { num5 = num12; connectionArray[0] = this.Connections[index]; num10 = 1; } else if (num12 == num5) { connectionArray[num10] = this.Connections[index]; num10++; } } else { if (listArray[0].PathCount != 1) { result2.ProblemAdd("Error: Invalid number of routes returned."); goto Label_088A; } if ((((double) listArray[0].Paths[0].Value) / num11) > num4) { num4 = ((double) listArray[0].Paths[0].Value) / num11; connectionArray[0] = this.Connections[index]; num10 = 1; } else if ((((double) listArray[0].Paths[0].Value) / num11) == num4) { connectionArray[num10] = this.Connections[index]; num10++; } else if (listArray[0].Paths[0].Value <= num11) { flagArray[index] = false; } } } else { flagArray[index] = false; } } else { flagArray[index] = false; } index++; } if (num10 > 0) { num6 = (int) Math.Round((double) ((float) (App.Random.Next() * num10))); connectionArray[num6].IsRamp = true; clsPassageNode passageNodeA = connectionArray[num6].PassageNodeA; clsPassageNode passageNodeB = connectionArray[num6].PassageNodeB; PathfinderNode nodeA = passageNodePathNodes[passageNodeA.MirrorNum, passageNodeA.Num]; PathfinderNode otherNode = passageNodePathNodes[passageNodeB.MirrorNum, passageNodeB.Num]; PathfinderConnection connection = nodeA.CreateConnection(otherNode, this.GetNodePosDist(nodeA, otherNode)); int num20 = connectionArray[num6].ReflectionCount - 1; for (num7 = 0; num7 <= num20; num7++) { connectionArray[num6].Reflections[num7].IsRamp = true; passageNodeA = connectionArray[num6].Reflections[num7].PassageNodeA; passageNodeB = connectionArray[num6].Reflections[num7].PassageNodeB; nodeA = passageNodePathNodes[passageNodeA.MirrorNum, passageNodeA.Num]; otherNode = passageNodePathNodes[passageNodeB.MirrorNum, passageNodeB.Num]; connection = nodeA.CreateConnection(otherNode, this.GetNodePosDist(nodeA, otherNode)); } nework.Network.FindCalc(); int num21 = this.PassageNodeCount - 1; for (num9 = 0; num9 <= num21; num9++) { args2.PassageNodeUpdated[num9] = false; } if (connectionArray[num6].PassageNodeA.MirrorNum == 0) { this.UpdateNetworkConnectedness(args2, connectionArray[num6].PassageNodeA); goto Label_0269; } if (connectionArray[num6].PassageNodeB.MirrorNum == 0) { this.UpdateNetworkConnectedness(args2, connectionArray[num6].PassageNodeB); goto Label_0269; } result2.ProblemAdd("Error: Initial ramp not in area 0."); } else { PathfinderNetwork.sFloodProximityArgs args; args.StartNode = nework.PassageNodePathNodes[0, 0]; args.NodeValues = nework.Network.NetworkLargeArrays.Nodes_ValuesA; int num22 = this.PassageNodeCount - 1; for (num = 0; num <= num22; num++) { int num23 = this.SymmetryBlockCount - 1; index = 0; while (index <= num23) { args.NodeValues[nework.PassageNodePathNodes[index, num].Layer_NodeNum] = float.MaxValue; index++; } } nework.Network.FloodProximity(ref args); int num24 = this.PassageNodeCount - 1; for (num = 0; num <= num24; num++) { int num25 = this.SymmetryBlockCount - 1; for (index = 0; index <= num25; index++) { if (!this.PassageNodes[index, num].IsWater && (args.NodeValues[nework.PassageNodePathNodes[index, num].Layer_NodeNum] == float.MaxValue)) { result2.ProblemAdd("Land is unreachable. Reduce variation or retry."); break; } } } } Label_088A: nework.Network.Deallocate(); return result2; }
public PathfinderConnection FindConnection(PathfinderNode NodeToFind) { int num2 = this.ConnectionCount - 1; for (int i = 0; i <= num2; i++) { PathfinderConnection connection2 = this.Connections[i]; if (connection2.GetOtherNode(this) == NodeToFind) { return connection2; } } return null; }
public PathfinderNode GetRandomChildNode(PathfinderNode InputNode, int MinClearance) { int num; if (InputNode.GetClearance < MinClearance) { return null; } if (InputNode.GetChildNodeCount == 0) { return InputNode; } do { num = (int) Math.Round((double) ((float) (App.Random.Next() * InputNode.GetChildNodeCount))); } while (InputNode.get_GetChildNode(num).GetClearance < MinClearance); return this.GetRandomChildNode(InputNode.get_GetChildNode(num), MinClearance); }
public void FindParent() { PathfinderNode nodeToAdd = null; if ((this.NodeCount == 0) & (this.Layer.Network_LayerNum > 0)) { Debugger.Break(); } else if (this.ParentNode != null) { Debugger.Break(); } else { bool flag2; float maxValue = float.MaxValue; int num7 = this.ConnectionCount - 1; for (int i = 0; i <= num7; i++) { bool flag; float num6; PathfinderConnection connection = this.Connections[i]; PathfinderNode otherNode = connection.GetOtherNode(this); PathfinderNode parentNode = otherNode.ParentNode; if (parentNode == null) { parentNode = connection.GetOtherNode(this); num6 = connection.Value * (0.98f + (VBMath.Rnd() * 0.04f)); if (num6 < maxValue) { maxValue = num6; nodeToAdd = parentNode; flag2 = true; } continue; } if (parentNode.NodeCount == 3) { int num5 = 0; flag = false; int num8 = parentNode.NodeCount - 1; for (int j = 0; j <= num8; j++) { int num9 = parentNode.Nodes[j].ConnectionCount - 1; for (int k = 0; k <= num9; k++) { if (parentNode.Nodes[j].Connections[k].GetOtherNode(parentNode.Nodes[j]) == this) { num5++; if (num5 >= 2) { flag = true; } break; } } } } else { flag = true; } if (flag) { num6 = (otherNode.SiblingSpan + connection.Value) * (0.98f + (VBMath.Rnd() * 0.04f)); if (num6 < maxValue) { maxValue = num6; nodeToAdd = parentNode; flag2 = false; } } } if (nodeToAdd != null) { if (flag2) { PathfinderLayer parentLayer; if (this.Layer.ParentLayer == null) { parentLayer = new PathfinderLayer(this.Layer.Network); } else { parentLayer = this.Layer.ParentLayer; } PathfinderNode newFindParentNode = new PathfinderNode(parentLayer); newFindParentNode.Node_Add(this); newFindParentNode.Node_Add(nodeToAdd); newFindParentNode.SpanCalc(); this.RaiseConnections(); nodeToAdd.RaiseConnections(); newFindParentNode.Layer.Network.FindParentNode_Add(newFindParentNode); } else if (nodeToAdd != null) { nodeToAdd.Node_Add(this); if (nodeToAdd.NodeCount >= 4) { nodeToAdd.Split(); } else { nodeToAdd.SpanCalc(); this.RaiseConnections(); if (nodeToAdd.ParentNode == null) { nodeToAdd.Layer.Network.FindParentNode_Add(nodeToAdd); } } } } else if (this.ConnectionCount > 0) { PathfinderLayer layer2; if (this.Layer.ParentLayer == null) { layer2 = new PathfinderLayer(this.Layer.Network); } else { layer2 = this.Layer.ParentLayer; } PathfinderNode node5 = new PathfinderNode(layer2); node5.Node_Add(this); node5.SpanCalc(); this.RaiseConnections(); node5.Layer.Network.FindParentNode_Add(node5); } } }
private void SetBaseLevel(PathfinderNode Node, int NewLevel, clsBaseNodeLevels BaseLevel) { if (Node.GetChildNodeCount == 0) { float num3 = NewLevel; int num5 = Node.GetConnectionCount - 1; for (int i = 0; i <= num5; i++) { float num2 = BaseLevel.NodeLevels[Node.get_GetConnection(i).GetOtherNode(Node).GetLayer_NodeNum]; if (num2 < num3) { num3 = num2; } } if ((NewLevel - num3) > 1f) { BaseLevel.NodeLevels[Node.GetLayer_NodeNum] = num3 + 1f; } else { BaseLevel.NodeLevels[Node.GetLayer_NodeNum] = NewLevel; } } else { int num6 = Node.GetChildNodeCount - 1; for (int j = 0; j <= num6; j++) { this.SetBaseLevel(Node.get_GetChildNode(j), NewLevel, BaseLevel); } } }
public void FloodCheckInternal(PathfinderNode CurrentNode, ref sVisited Visited) { Visited.Visited[CurrentNode.ParentNode_NodeNum] = true; int num2 = CurrentNode.ConnectionCount - 1; for (int i = 0; i <= num2; i++) { PathfinderNode otherNode = CurrentNode.Connections[i].GetOtherNode(CurrentNode); if ((otherNode.ParentNode == this) && !Visited.Visited[otherNode.ParentNode_NodeNum]) { this.FloodCheckInternal(otherNode, ref Visited); } } }
private void UpdateNodeConnectedness(clsUpdateNodeConnectednessArgs Args, clsPassageNode PassageNode) { int num2; Args.Args.PassageNodeVisited[PassageNode.MirrorNum, PassageNode.Num] = true; int num3 = PassageNode.ConnectionCount - 1; for (int i = 0; i <= num3; i++) { clsConnection connection = PassageNode.Connections[i].Connection; if (!(((connection.PassageNodeA.IsOnBorder | connection.PassageNodeB.IsOnBorder) | connection.PassageNodeA.IsWater) | connection.PassageNodeB.IsWater) & (connection.IsRamp | (connection.PassageNodeA.Level == connection.PassageNodeB.Level))) { clsPassageNode other = PassageNode.Connections[i].GetOther(); if (!Args.Args.PassageNodeVisited[other.MirrorNum, other.Num]) { this.UpdateNodeConnectedness(Args, other); } num2++; } } PathfinderNode[] startNodes = new PathfinderNode[] { Args.Args.PassageNodePathNodes[0, Args.OriginalNode.Num] }; PathfinderNetwork.PathList[] listArray = Args.Args.PassageNodePathMap.GetPath(startNodes, Args.Args.PassageNodePathNodes[PassageNode.MirrorNum, PassageNode.Num], -1, 0); float[] nodeConnectedness = Args.Args.NodeConnectedness; int num = Args.OriginalNode.Num; nodeConnectedness[num] += (float) (num2 * Math.Pow(0.999, (double) listArray[0].Paths[0].Value)); }
public void ForceDeallocate() { int num2 = this.ConnectionCount - 1; for (int i = 0; i <= num2; i++) { this.Connections[i].ForceDeallocate(); } this.Connections = null; this.Nodes = null; this.ParentNode = null; this.Layer = null; }
public void Node_Add(PathfinderNode NewNode) { if (this.Nodes.GetUpperBound(0) < this.NodeCount) { this.Nodes = (PathfinderNode[]) Utils.CopyArray((Array) this.Nodes, new PathfinderNode[(((this.NodeCount + 1) * 2) - 1) + 1]); } this.Nodes[this.NodeCount] = NewNode; this.Nodes[this.NodeCount].Layer_NodeNum = this.NodeCount; this.NodeCount++; }
public void FindParentNode_Add(PathfinderNode NewFindParentNode) { if (NewFindParentNode.Network_FindParentNum < 0) { if (this.FindParentNodes.GetUpperBound(0) < this.FindParentNodeCount) { this.FindParentNodes = (PathfinderNode[]) Utils.CopyArray((Array) this.FindParentNodes, new PathfinderNode[(((this.FindParentNodeCount + 1) * 2) - 1) + 1]); } this.FindParentNodes[this.FindParentNodeCount] = NewFindParentNode; this.FindParentNodes[this.FindParentNodeCount].Network_FindParentNum = this.FindParentNodeCount; this.FindParentNodeCount++; } }