Beispiel #1
0
 public PathfinderNode(PathfinderNetwork ParentNetwork)
 {
     PathfinderLayer layer;
     this.Network_FindParentNum = -1;
     this.Layer_NodeNum = -1;
     this.Layer_ChangedNodeNum = -1;
     this.ParentNode_NodeNum = -1;
     this.Nodes = new PathfinderNode[4];
     this.Connections = new PathfinderConnection[2];
     this.Clearance = 0x7fffffff;
     if (ParentNetwork.NodeLayerCount == 0)
     {
         layer = new PathfinderLayer(ParentNetwork);
     }
     else
     {
         layer = ParentNetwork.NodeLayers[0];
     }
     this.Layer = layer;
     layer.Node_Add(this);
 }
Beispiel #2
0
 public PathfinderLayer(PathfinderNetwork NewParentNetwork)
 {
     this.Network = NewParentNetwork;
     this.Network.NodeLayer_Add(this);
 }
Beispiel #3
0
 public void ForceDeallocate()
 {
     int num2 = this.NodeCount - 1;
     for (int i = 0; i <= num2; i++)
     {
         this.Nodes[i].ForceDeallocate();
     }
     this.Nodes = null;
     this.Connections = null;
     this.Network = null;
     this.ParentLayer = null;
 }
Beispiel #4
0
 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;
 }
Beispiel #5
0
 public PathfinderNode GetNearestNode(PathfinderNetwork Network, modMath.sXY_int Pos, int MinClearance)
 {
     double maxValue = double.MaxValue;
     PathfinderNode node = null;
     int num4 = Network.get_GetNodeLayer(0).GetNodeCount - 1;
     for (int i = 0; i <= num4; i++)
     {
         PathfinderNode node3 = Network.get_GetNodeLayer(0).get_GetNode(i);
         if (node3.GetClearance >= MinClearance)
         {
             clsNodeTag tag = (clsNodeTag) node3.Tag;
             modMath.sXY_int _int = tag.Pos - Pos;
             double magnitude = _int.ToDoubles().GetMagnitude();
             if (magnitude < maxValue)
             {
                 maxValue = magnitude;
                 node = node3;
             }
         }
     }
     return node;
 }
Beispiel #6
0
 public void GenerateTilePathMap()
 {
     int num;
     int num2;
     this.TilePathMap = new PathfinderNetwork();
     int num3 = this.Map.Terrain.TileSize.Y - 1;
     for (num2 = 0; num2 <= num3; num2++)
     {
         int num4 = this.Map.Terrain.TileSize.X - 1;
         num = 0;
         while (num <= num4)
         {
             this.GenerateTerrainTiles[num, num2] = new GenerateTerrainTile();
             this.GenerateTerrainTiles[num, num2].Node = new PathfinderNode(this.TilePathMap);
             clsNodeTag tag = new clsNodeTag {
                 Pos = new modMath.sXY_int((int) Math.Round((double) ((num + 0.5) * 128.0)), (int) Math.Round((double) ((num2 + 0.5) * 128.0)))
             };
             this.GenerateTerrainTiles[num, num2].Node.Tag = tag;
             num++;
         }
     }
     int num5 = this.Map.Terrain.TileSize.Y - 1;
     for (num2 = 0; num2 <= num5; num2++)
     {
         int num6 = this.Map.Terrain.TileSize.X - 1;
         for (num = 0; num <= num6; num++)
         {
             PathfinderNode node;
             PathfinderNode nodeA = this.GenerateTerrainTiles[num, num2].Node;
             if (num > 0)
             {
                 node = this.GenerateTerrainTiles[num - 1, num2].Node;
                 this.GenerateTerrainTiles[num, num2].LeftLink = nodeA.GetOrCreateConnection(node, this.GetNodePosDist(nodeA, node));
             }
             if (num2 > 0)
             {
                 if (num > 0)
                 {
                     node = this.GenerateTerrainTiles[num - 1, num2 - 1].Node;
                     this.GenerateTerrainTiles[num, num2].TopLeftLink = nodeA.GetOrCreateConnection(node, this.GetNodePosDist(nodeA, node));
                 }
                 node = this.GenerateTerrainTiles[num, num2 - 1].Node;
                 this.GenerateTerrainTiles[num, num2].TopLink = nodeA.GetOrCreateConnection(node, this.GetNodePosDist(nodeA, node));
                 if (num < (this.Map.Terrain.TileSize.X - 1))
                 {
                     node = this.GenerateTerrainTiles[num + 1, num2 - 1].Node;
                     this.GenerateTerrainTiles[num, num2].TopRightLink = nodeA.GetOrCreateConnection(node, this.GetNodePosDist(nodeA, node));
                 }
             }
             if (num < (this.Map.Terrain.TileSize.X - 1))
             {
                 node = this.GenerateTerrainTiles[num + 1, num2].Node;
                 this.GenerateTerrainTiles[num, num2].RightLink = nodeA.GetOrCreateConnection(node, this.GetNodePosDist(nodeA, node));
             }
             if (num2 < (this.Map.Terrain.TileSize.Y - 1))
             {
                 if (num > 0)
                 {
                     node = this.GenerateTerrainTiles[num - 1, num2 + 1].Node;
                     this.GenerateTerrainTiles[num, num2].BottomLeftLink = nodeA.GetOrCreateConnection(node, this.GetNodePosDist(nodeA, node));
                 }
                 node = this.GenerateTerrainTiles[num, num2 + 1].Node;
                 this.GenerateTerrainTiles[num, num2].BottomLink = nodeA.GetOrCreateConnection(node, this.GetNodePosDist(nodeA, node));
                 if (num < (this.Map.Terrain.TileSize.X - 1))
                 {
                     node = this.GenerateTerrainTiles[num + 1, num2 + 1].Node;
                     this.GenerateTerrainTiles[num, num2].BottomRightLink = nodeA.GetOrCreateConnection(node, this.GetNodePosDist(nodeA, node));
                 }
             }
         }
     }
     this.TilePathMap.LargeArraysResize();
     this.TilePathMap.FindCalc();
 }
Beispiel #7
0
 public void ClearLayout()
 {
     int num;
     if (this.TilePathMap != null)
     {
         this.TilePathMap.Deallocate();
         this.TilePathMap = null;
     }
     if (this.VertexPathMap != null)
     {
         this.VertexPathMap.Deallocate();
         this.VertexPathMap = null;
     }
     int num3 = this.ConnectionCount - 1;
     for (num = 0; num <= num3; num++)
     {
         this.Connections[num].PassageNodeA = null;
         this.Connections[num].PassageNodeB = null;
         this.Connections[num].Reflections = null;
     }
     this.ConnectionCount = 0;
     int num4 = this.PassageNodeCount - 1;
     for (num = 0; num <= num4; num++)
     {
         int num5 = this.SymmetryBlockCount - 1;
         for (int i = 0; i <= num5; i++)
         {
             this.PassageNodes[i, num].Connections = null;
         }
     }
     this.PassageNodeCount = 0;
     this.NearestCount = 0;
 }
Beispiel #8
0
 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 void Resize(PathfinderNetwork NetworkForSize)
 {
     int nodeCount;
     if (NetworkForSize.NodeLayerCount > 0)
     {
         nodeCount = NetworkForSize.NodeLayers[0].NodeCount;
     }
     else
     {
         nodeCount = 0;
     }
     if (this.Size < nodeCount)
     {
         this.Size = (int) Math.Round((double) (nodeCount * this.SizeEnlargementRatio));
         int num2 = this.Size - 1;
         this.Nodes_Booleans = new bool[num2 + 1];
         this.Nodes_ValuesA = new float[num2 + 1];
         this.Nodes_ValuesB = new float[num2 + 1];
         this.Nodes_Booleans = new bool[num2 + 1];
         this.Nodes_Path.Nodes = new PathfinderNode[num2 + 1];
         this.Nodes_Nodes = new PathfinderNode[num2 + 1];
     }
     else if (this.Size > (nodeCount * this.SizeReductionRatio))
     {
         this.Size = (int) Math.Round((double) (nodeCount * this.SizeEnlargementRatio));
         int num3 = this.Size - 1;
         this.Nodes_Booleans = new bool[num3 + 1];
         this.Nodes_ValuesA = new float[num3 + 1];
         this.Nodes_ValuesB = new float[num3 + 1];
         this.Nodes_Booleans = new bool[num3 + 1];
         this.Nodes_Path.Nodes = new PathfinderNode[num3 + 1];
         this.Nodes_Nodes = new PathfinderNode[num3 + 1];
     }
 }