Example #1
0
 public clsResult GenerateLayout()
 {
     int num;
     int num2;
     int level;
     int num5;
     bool flag;
     int num6;
     int baseLevel;
     int num9;
     modMath.sXY_int _int;
     Position.XY_dbl _dbl;
     bool flag2;
     int num12;
     int num13;
     int num14;
     clsNearest nearest;
     modProgram.sResult result3;
     modMath.sXY_int _int4;
     clsPassageNode node;
     clsPassageNode other;
     clsPassageNode node3;
     modMath.sXY_int _int5;
     int num41;
     int[] mapLevelCount;
     clsResult result4 = new clsResult("Layout");
     this.TotalPlayerCount = this.TopLeftPlayerCount * this.SymmetryBlockCount;
     _int4.X = (int) Math.Round((double) (((double) (this.TileSize.X * 0x80)) / ((double) this.SymmetryBlockCountXY.X)));
     _int4.Y = (int) Math.Round((double) (((double) (this.TileSize.Y * 0x80)) / ((double) this.SymmetryBlockCountXY.Y)));
     int num19 = (int) Math.Round((double) (128f * this.NodeScale));
     int num16 = (int) Math.Round(Math.Ceiling((double) (((((2.0 * this.TileSize.X) * 128.0) * this.TileSize.Y) * 128.0) / ((3.1415926535897931 * num19) * num19))));
     this.PassageNodes = new clsPassageNode[(this.SymmetryBlockCount - 1) + 1, (num16 - 1) + 1];
     int x = 0;
     if (this.SymmetryBlockCountXY.X == 1)
     {
         _int.X = (int) Math.Round(((double) (((this.TileSize.X * 0x80) - (x * 2.0)) / ((double) ((this.NodeScale * 128f) * 2f)))));
         _dbl.X = ((this.TileSize.X * 0x80) - (x * 2.0)) / ((double) _int.X);
         _int.X--;
     }
     else
     {
         _int.X = (int) Math.Round(((double) ((((((double) (this.TileSize.X * 0x80)) / ((double) this.SymmetryBlockCountXY.X)) - x) / ((double) ((this.NodeScale * 128f) * 2f))) - 0.5)));
         _dbl.X = ((((double) (this.TileSize.X * 0x80)) / ((double) this.SymmetryBlockCountXY.X)) - x) / (((double) ((((((double) (this.TileSize.X * 0x80)) / ((double) this.SymmetryBlockCountXY.X)) - x) / ((double) ((this.NodeScale * 128f) * 2f))) - 0.5)) + 0.5);
     }
     if (this.SymmetryBlockCountXY.Y == 1)
     {
         _int.Y = (int) Math.Round(((double) (((this.TileSize.Y * 0x80) - (x * 2.0)) / ((double) ((this.NodeScale * 128f) * 2f)))));
         _dbl.Y = ((this.TileSize.Y * 0x80) - (x * 2.0)) / ((double) _int.Y);
         _int.Y--;
     }
     else
     {
         _int.Y = (int) Math.Round(((double) ((((((double) (this.TileSize.Y * 0x80)) / ((double) this.SymmetryBlockCountXY.Y)) - x) / ((double) ((this.NodeScale * 128f) * 2f))) - 0.5)));
         _dbl.Y = ((((double) (this.TileSize.Y * 0x80)) / ((double) this.SymmetryBlockCountXY.Y)) - x) / (((double) ((((((double) (this.TileSize.Y * 0x80)) / ((double) this.SymmetryBlockCountXY.Y)) - x) / ((double) ((this.NodeScale * 128f) * 2f))) - 0.5)) + 0.5);
     }
     this.PassageNodeCount = 0;
     int y = _int.Y;
     for (int i = 0; i <= y; i++)
     {
         _int5 = new modMath.sXY_int(x, x + ((int) Math.Round((double) (i * _dbl.Y))));
         if (!this.MakePassageNodes(_int5, true))
         {
             result4.ProblemAdd("Error: Bad border node.");
             return result4;
         }
         if (this.SymmetryBlockCountXY.X == 1)
         {
             _int5 = new modMath.sXY_int((this.TileSize.X * 0x80) - x, x + ((int) Math.Round((double) (i * _dbl.Y))));
             if (!this.MakePassageNodes(_int5, true))
             {
                 result4.ProblemAdd("Error: Bad border node.");
                 return result4;
             }
         }
     }
     int num26 = _int.X;
     for (int j = 1; j <= num26; j++)
     {
         _int5 = new modMath.sXY_int(x + ((int) Math.Round((double) (j * _dbl.X))), x);
         if (!this.MakePassageNodes(_int5, true))
         {
             result4.ProblemAdd("Error: Bad border node.");
             return result4;
         }
         if (this.SymmetryBlockCountXY.Y == 1)
         {
             _int5 = new modMath.sXY_int(x + ((int) Math.Round((double) (j * _dbl.X))), (this.TileSize.Y * 0x80) - x);
             if (!this.MakePassageNodes(_int5, true))
             {
                 result4.ProblemAdd("Error: Bad border node.");
                 return result4;
             }
         }
     }
     Label_0538:
     num14 = 0;
     do
     {
         modMath.sXY_int _int2;
         if (this.SymmetryBlockCountXY.X == 1)
         {
             _int2.X = x + ((int) Math.Round((double) ((float) (App.Random.Next() * ((_int4.X - (x * 2)) + 1)))));
         }
         else
         {
             _int2.X = x + ((int) Math.Round((double) ((float) (App.Random.Next() * ((_int4.X - x) + 1)))));
         }
         if (this.SymmetryBlockCountXY.Y == 1)
         {
             _int2.Y = x + ((int) Math.Round((double) ((float) (App.Random.Next() * ((_int4.Y - (x * 2)) + 1)))));
         }
         else
         {
             _int2.Y = x + ((int) Math.Round((double) ((float) (App.Random.Next() * ((_int4.Y - x) + 1)))));
         }
         int num27 = this.PassageNodeCount - 1;
         num = 0;
         while (num <= num27)
         {
             int num28 = this.SymmetryBlockCount - 1;
             num2 = 0;
             while (num2 <= num28)
             {
                 _int5 = this.PassageNodes[num2, num].Pos - _int2;
                 if (_int5.ToDoubles().GetMagnitude() < (num19 * 2))
                 {
                     break;
                 }
                 num2++;
             }
             num++;
         }
         if ((num == this.PassageNodeCount) && this.MakePassageNodes(_int2, false))
         {
             goto Label_0538;
         }
         num14++;
     }
     while (num14 < ((int) Math.Round((double) (((64f * this.TileSize.X) * this.TileSize.Y) / (this.NodeScale * this.NodeScale)))));
     this.PassageNodes = (clsPassageNode[,]) Utils.CopyArray((Array) this.PassageNodes, new clsPassageNode[(this.SymmetryBlockCount - 1) + 1, (this.PassageNodeCount - 1) + 1]);
     int num15 = (num19 * 2) * 4;
     num15 *= num15;
     this.Nearests = new clsNearest[((this.PassageNodeCount * 0x40) - 1) + 1];
     clsTestNearestArgs args2 = new clsTestNearestArgs();
     int num17 = (int) Math.Round((double) ((this.NodeScale * 1.25f) * 128f));
     args2.MaxConDist2 = num15;
     args2.MinConDist = num17;
     int num29 = this.PassageNodeCount - 1;
     num = 0;
     while (num <= num29)
     {
         args2.PassageNodeA = this.PassageNodes[0, num];
         int num30 = this.PassageNodeCount - 1;
         num2 = num;
         while (num2 <= num30)
         {
             int num31 = this.SymmetryBlockCount - 1;
             num5 = 0;
             while (num5 <= num31)
             {
                 args2.PassageNodeB = this.PassageNodes[num5, num2];
                 if (args2.PassageNodeA != args2.PassageNodeB)
                 {
                     this.TestNearest(args2);
                 }
                 num5++;
             }
             num2++;
         }
         num++;
     }
     int num32 = this.NearestCount - 1;
     for (num12 = 0; num12 <= num32; num12++)
     {
         nearest = this.Nearests[num12];
         int num33 = nearest.NodeCount - 1;
         num = 0;
         while (num <= num33)
         {
             node = nearest.NodeA[num];
             other = nearest.NodeB[num];
             int num34 = this.NearestCount - 1;
             num13 = 0;
             while (num13 <= num34)
             {
                 clsNearest nearest2 = this.Nearests[num13];
                 if (nearest2 != nearest)
                 {
                     if (nearest2.Dist2 < nearest.Dist2)
                     {
                         flag2 = true;
                     }
                     else if (nearest2.Dist2 == nearest.Dist2)
                     {
                         flag2 = nearest.Num > nearest2.Num;
                     }
                     else
                     {
                         flag2 = false;
                     }
                     if (flag2)
                     {
                         int num35 = nearest2.NodeCount - 1;
                         num2 = 0;
                         while (num2 <= num35)
                         {
                             if (!((((node == nearest2.NodeA[num2]) | (node == nearest2.NodeB[num2])) | (other == nearest2.NodeA[num2])) | (other == nearest2.NodeB[num2])) && modMath.GetLinesIntersectBetween(node.Pos, other.Pos, nearest2.NodeA[num2].Pos, nearest2.NodeB[num2].Pos).Exists)
                             {
                                 break;
                             }
                             num2++;
                         }
                         if (num2 < nearest2.NodeCount)
                         {
                             clsNearest nearest3 = nearest;
                             nearest3.BlockedCount++;
                             clsNearest nearest4 = nearest2;
                             nearest4.BlockedNearests[nearest4.BlockedNearestCount] = nearest;
                             nearest3 = nearest4;
                             nearest3.BlockedNearestCount++;
                             nearest4 = null;
                         }
                     }
                 }
                 num13++;
             }
             num++;
         }
     }
     this.Connections = new clsConnection[((this.PassageNodeCount * 0x10) - 1) + 1];
     do
     {
         num6 = 0;
         num12 = 0;
         while (num12 < this.NearestCount)
         {
             nearest = this.Nearests[num12];
             flag2 = true;
             if ((nearest.BlockedCount == 0) & flag2)
             {
                 int connectionCount = this.ConnectionCount;
                 int num36 = nearest.NodeCount - 1;
                 baseLevel = 0;
                 while (baseLevel <= num36)
                 {
                     this.Connections[this.ConnectionCount] = new clsConnection(nearest.NodeA[baseLevel], nearest.NodeB[baseLevel]);
                     this.ConnectionCount++;
                     baseLevel++;
                 }
                 int num37 = nearest.NodeCount - 1;
                 baseLevel = 0;
                 while (baseLevel <= num37)
                 {
                     num = connectionCount + baseLevel;
                     this.Connections[num].ReflectionCount = nearest.NodeCount - 1;
                     this.Connections[num].Reflections = new clsConnection[(this.Connections[num].ReflectionCount - 1) + 1];
                     num2 = 0;
                     int num38 = nearest.NodeCount - 1;
                     num9 = 0;
                     while (num9 <= num38)
                     {
                         if (num9 != baseLevel)
                         {
                             this.Connections[num].Reflections[num2] = this.Connections[connectionCount + num9];
                             num2++;
                         }
                         num9++;
                     }
                     baseLevel++;
                 }
                 int num39 = nearest.BlockedNearestCount - 1;
                 num5 = 0;
                 while (num5 <= num39)
                 {
                     nearest.BlockedNearests[num5].Invalid = true;
                     num5++;
                 }
                 this.NearestCount--;
                 num13 = nearest.Num;
                 nearest.Num = -1;
                 if (num13 != this.NearestCount)
                 {
                     this.Nearests[num13] = this.Nearests[this.NearestCount];
                     this.Nearests[num13].Num = num13;
                 }
                 num6++;
             }
             else
             {
                 if (!flag2)
                 {
                     nearest.Invalid = true;
                 }
                 num12++;
             }
         }
         num12 = 0;
         while (num12 < this.NearestCount)
         {
             nearest = this.Nearests[num12];
             if (nearest.Invalid)
             {
                 nearest.Num = -1;
                 int num40 = nearest.BlockedNearestCount - 1;
                 baseLevel = 0;
                 while (baseLevel <= num40)
                 {
                     clsNearest[] blockedNearests = nearest.BlockedNearests;
                     num41 = baseLevel;
                     blockedNearests[num41].BlockedCount--;
                     baseLevel++;
                 }
                 this.NearestCount--;
                 if (num12 != this.NearestCount)
                 {
                     this.Nearests[num12] = this.Nearests[this.NearestCount];
                     this.Nearests[num12].Num = num12;
                 }
             }
             else
             {
                 num12++;
             }
         }
     }
     while (num6 > 0);
     int num42 = this.PassageNodeCount - 1;
     for (num = 0; num <= num42; num++)
     {
         int num43 = this.SymmetryBlockCount - 1;
         for (num2 = 0; num2 <= num43; num2++)
         {
             this.PassageNodes[num2, num].ReorderConnections();
             this.PassageNodes[num2, num].CalcIsNearBorder();
         }
     }
     clsPassageNode[] nodeArray2 = new clsPassageNode[(this.PassageNodeCount - 1) + 1];
     int index = 0;
     clsPassageNode[] nodeArray3 = new clsPassageNode[(this.PassageNodeCount - 1) + 1];
     int num44 = this.PassageNodeCount - 1;
     num = 0;
     while (num <= num44)
     {
         nodeArray2[index] = this.PassageNodes[0, num];
         index++;
         num++;
     }
     num2 = 0;
     while (index > 0)
     {
         num = (int) Math.Round((double) ((float) (App.Random.Next() * index)));
         nodeArray3[num2] = nodeArray2[num];
         num2++;
         index--;
         nodeArray2[num] = nodeArray2[index];
     }
     this.LevelHeight = 255f / ((float) (this.LevelCount - 1));
     clsPassageNodeHeightLevelArgs args = new clsPassageNodeHeightLevelArgs {
         PassageNodesMinLevel = { Nodes = new int[(this.PassageNodeCount - 1) + 1] },
         PassageNodesMaxLevel = { Nodes = new int[(this.PassageNodeCount - 1) + 1] },
         MapLevelCount = new int[(this.LevelCount - 1) + 1]
     };
     int num45 = this.PassageNodeCount - 1;
     num = 0;
     while (num <= num45)
     {
         args.PassageNodesMinLevel.Nodes[num] = 0;
         args.PassageNodesMaxLevel.Nodes[num] = this.LevelCount - 1;
         num++;
     }
     double[] numArray = new double[(this.BaseFlatArea - 1) + 1];
     clsPassageNode[] nodeArray = new clsPassageNode[(this.BaseFlatArea - 1) + 1];
     int[] numArray2 = new int[(this.BaseFlatArea - 1) + 1];
     this.PlayerBases = new sPlayerBase[(this.TotalPlayerCount - 1) + 1];
     int num46 = this.TopLeftPlayerCount - 1;
     num2 = 0;
     while (num2 <= num46)
     {
         int num3 = 0;
         int num47 = this.PassageNodeCount - 1;
         num = 0;
         while (num <= num47)
         {
             int num48 = this.SymmetryBlockCount - 1;
             num9 = 0;
             while (num9 <= num48)
             {
                 node = this.PassageNodes[num9, num];
                 if (!node.IsOnBorder)
                 {
                     _int5 = node.Pos - this.PlayerBasePos[num2];
                     double magnitude = _int5.ToDoubles().GetMagnitude();
                     num5 = num3 - 1;
                     while (num5 >= 0)
                     {
                         if (magnitude > numArray[num5])
                         {
                             break;
                         }
                         num5 += -1;
                     }
                     num5++;
                     int num49 = num5;
                     baseLevel = Math.Min((int) (num3 - 1), (int) (this.BaseFlatArea - 2));
                     while (baseLevel >= num49)
                     {
                         numArray[baseLevel + 1] = numArray[baseLevel];
                         nodeArray[baseLevel + 1] = nodeArray[baseLevel];
                         baseLevel += -1;
                     }
                     if (num5 < this.BaseFlatArea)
                     {
                         numArray[num5] = magnitude;
                         nodeArray[num5] = node;
                         num3 = Math.Max(num3, num5 + 1);
                     }
                 }
                 num9++;
             }
             num++;
         }
         if (this.BaseLevel < 0)
         {
             baseLevel = (int) Math.Round((double) ((float) (App.Random.Next() * this.LevelCount)));
         }
         else
         {
             baseLevel = this.BaseLevel;
         }
         mapLevelCount = args.MapLevelCount;
         num41 = baseLevel;
         mapLevelCount[num41] += num3;
         int num50 = num3 - 1;
         num = 0;
         while (num <= num50)
         {
             if (nodeArray[num].MirrorNum == 0)
             {
                 numArray2[num] = -1;
             }
             else
             {
                 int num51 = ((int) Math.Round((double) (((double) this.SymmetryBlockCount) / 2.0))) - 1;
                 num5 = 0;
                 while (num5 <= num51)
                 {
                     if (this.SymmetryBlocks[0].ReflectToNum[num5] == nodeArray[num].MirrorNum)
                     {
                         break;
                     }
                     num5++;
                 }
                 numArray2[num] = num5;
             }
             num++;
         }
         int num52 = this.SymmetryBlockCount - 1;
         num = 0;
         while (num <= num52)
         {
             num9 = (num * this.TopLeftPlayerCount) + num2;
             this.PlayerBases[num9].NodeCount = num3;
             this.PlayerBases[num9].Nodes = new clsPassageNode[(this.PlayerBases[num9].NodeCount - 1) + 1];
             int num53 = num3 - 1;
             num5 = 0;
             while (num5 <= num53)
             {
                 if (numArray2[num5] < 0)
                 {
                     this.PlayerBases[num9].Nodes[num5] = this.PassageNodes[num, nodeArray[num5].Num];
                 }
                 else
                 {
                     this.PlayerBases[num9].Nodes[num5] = this.PassageNodes[this.SymmetryBlocks[num].ReflectToNum[numArray2[num5]], nodeArray[num5].Num];
                 }
                 this.PlayerBases[num9].Nodes[num5].PlayerBaseNum = num9;
                 this.PlayerBases[num9].Nodes[num5].Level = baseLevel;
                 this.PassageNodesMinLevelSet(this.PlayerBases[num9].Nodes[num5], args.PassageNodesMinLevel, baseLevel, this.MaxLevelTransition);
                 this.PassageNodesMaxLevelSet(this.PlayerBases[num9].Nodes[num5], args.PassageNodesMaxLevel, baseLevel, this.MaxLevelTransition);
                 num5++;
             }
             _int5 = new modMath.sXY_int(_int4.X - 1, _int4.Y - 1);
             modMath.sXY_int _int3 = TileOrientation.GetRotatedPos(this.SymmetryBlocks[num].Orientation, this.PlayerBasePos[num2], _int5);
             this.PlayerBases[num9].Pos.X = (this.SymmetryBlocks[num].XYNum.X * _int4.X) + _int3.X;
             this.PlayerBases[num9].Pos.Y = (this.SymmetryBlocks[num].XYNum.Y * _int4.Y) + _int3.Y;
             num++;
         }
         num2++;
     }
     int num54 = this.PassageNodeCount - 1;
     for (num = 0; num <= num54; num++)
     {
         node = nodeArray3[num];
         if ((node.Level < 0) & !node.IsOnBorder)
         {
             int num20;
             int num22;
             int num21 = 0;
             int num55 = node.ConnectionCount - 1;
             num2 = 0;
             while (num2 <= num55)
             {
                 if (node.Connections[num2].GetOther().IsWater)
                 {
                     num21++;
                 }
                 num2++;
             }
             flag = true;
             int num56 = node.ConnectionCount - 1;
             num2 = 0;
             while (num2 <= num56)
             {
                 if (args.PassageNodesMinLevel.Nodes[node.Connections[num2].GetOther().Num] > 0)
                 {
                     flag = false;
                 }
                 num2++;
             }
             if (((flag & (((num21 == 0) & (num22 < this.WaterSpawnQuantity)) | ((num21 == 1) & ((this.TotalWaterQuantity - num20) > (this.WaterSpawnQuantity - num22))))) & (args.PassageNodesMinLevel.Nodes[node.Num] == 0)) & (num20 < this.TotalWaterQuantity))
             {
                 if (num21 == 0)
                 {
                     num22++;
                 }
                 num20++;
                 num5 = node.Num;
                 int num57 = this.SymmetryBlockCount - 1;
                 baseLevel = 0;
                 while (baseLevel <= num57)
                 {
                     this.PassageNodes[baseLevel, num5].IsWater = true;
                     this.PassageNodes[baseLevel, num5].Level = 0;
                     baseLevel++;
                 }
                 this.PassageNodesMinLevelSet(node, args.PassageNodesMinLevel, 0, this.MaxLevelTransition);
                 this.PassageNodesMaxLevelSet(node, args.PassageNodesMaxLevel, 0, this.MaxLevelTransition);
                 mapLevelCount = args.MapLevelCount;
                 num41 = 0;
                 mapLevelCount[num41]++;
                 int num58 = node.ConnectionCount - 1;
                 num2 = 0;
                 while (num2 <= num58)
                 {
                     other = node.Connections[num2].GetOther();
                     this.PassageNodesMinLevelSet(other, args.PassageNodesMinLevel, 0, this.MaxLevelTransition);
                     this.PassageNodesMaxLevelSet(other, args.PassageNodesMaxLevel, 0, this.MaxLevelTransition);
                     num2++;
                 }
             }
         }
     }
     args.FlatsCutoff = 1;
     args.PassagesCutoff = 1;
     args.VariationCutoff = 1;
     args.ActionTotal = 1;
     int num59 = this.PassageNodeCount - 1;
     for (num = 0; num <= num59; num++)
     {
         node = nodeArray3[num];
         if (((node.Level < 0) & !node.IsOnBorder) & node.IsNearBorder)
         {
             args.PassageNode = node;
             result3 = this.PassageNodeHeightLevel(args);
             if (!result3.Success)
             {
                 result4.ProblemAdd(result3.Problem);
                 return result4;
             }
         }
     }
     args.FlatsCutoff = this.FlatsChance;
     args.PassagesCutoff = args.FlatsCutoff + this.PassagesChance;
     args.VariationCutoff = args.PassagesCutoff + this.VariationChance;
     args.ActionTotal = args.VariationCutoff;
     if (args.ActionTotal <= 0)
     {
         result4.ProblemAdd("All height level behaviors are zero");
         return result4;
     }
     int num60 = this.PassageNodeCount - 1;
     for (num = 0; num <= num60; num++)
     {
         node = nodeArray3[num];
         if ((node.Level < 0) & !node.IsOnBorder)
         {
             args.PassageNode = node;
             result3 = this.PassageNodeHeightLevel(args);
             if (!result3.Success)
             {
                 result4.ProblemAdd(result3.Problem);
                 return result4;
             }
         }
     }
     int num61 = this.PassageNodeCount - 1;
     for (num = 0; num <= num61; num++)
     {
         node = this.PassageNodes[0, num];
         if (node.IsOnBorder)
         {
             if (node.Level >= 0)
             {
                 result4.ProblemAdd("Error: Border has had its height set.");
                 return result4;
             }
             node3 = null;
             flag = true;
             int num62 = node.ConnectionCount - 1;
             num2 = 0;
             while (num2 <= num62)
             {
                 other = node.Connections[num2].GetOther();
                 if ((((other.Level >= 0) & !other.IsOnBorder) && ((args.PassageNodesMinLevel.Nodes[node.Num] <= other.Level) & (args.PassageNodesMaxLevel.Nodes[node.Num] >= other.Level))) && (node3 == null))
                 {
                     node3 = other;
                 }
                 if (args.PassageNodesMinLevel.Nodes[other.Num] > 0)
                 {
                     flag = false;
                 }
                 num2++;
             }
             if (node3 != null)
             {
                 level = node3.Level;
                 this.PassageNodesMinLevelSet(node, args.PassageNodesMinLevel, level, this.MaxLevelTransition);
                 this.PassageNodesMaxLevelSet(node, args.PassageNodesMaxLevel, level, this.MaxLevelTransition);
                 int num63 = this.SymmetryBlockCount - 1;
                 baseLevel = 0;
                 while (baseLevel <= num63)
                 {
                     this.PassageNodes[baseLevel, num].IsWater = node3.IsWater & flag;
                     this.PassageNodes[baseLevel, num].Level = level;
                     baseLevel++;
                 }
                 if (node.IsWater)
                 {
                     int num64 = node.ConnectionCount - 1;
                     num2 = 0;
                     while (num2 <= num64)
                     {
                         other = node.Connections[num2].GetOther();
                         this.PassageNodesMinLevelSet(other, args.PassageNodesMinLevel, node.Level, this.MaxLevelTransition);
                         this.PassageNodesMaxLevelSet(other, args.PassageNodesMaxLevel, node.Level, this.MaxLevelTransition);
                         num2++;
                     }
                 }
             }
         }
         else if (node.Level < 0)
         {
             result4.ProblemAdd("Error: Node height not set");
             return result4;
         }
     }
     int num65 = this.PassageNodeCount - 1;
     for (num = 0; num <= num65; num++)
     {
         node = this.PassageNodes[0, num];
         if (node.IsOnBorder & (node.Level < 0))
         {
             node3 = null;
             flag = true;
             int num66 = node.ConnectionCount - 1;
             num2 = 0;
             while (num2 <= num66)
             {
                 other = node.Connections[num2].GetOther();
                 if (((other.Level >= 0) && ((args.PassageNodesMinLevel.Nodes[node.Num] <= other.Level) & (args.PassageNodesMaxLevel.Nodes[node.Num] >= other.Level))) && (node3 == null))
                 {
                     node3 = other;
                 }
                 if (args.PassageNodesMinLevel.Nodes[other.Num] > 0)
                 {
                     flag = false;
                 }
                 num2++;
             }
             if (node3 == null)
             {
                 result4.ProblemAdd("Error: No connection for border node");
                 return result4;
             }
             level = node3.Level;
             this.PassageNodesMinLevelSet(node, args.PassageNodesMinLevel, level, this.MaxLevelTransition);
             this.PassageNodesMaxLevelSet(node, args.PassageNodesMaxLevel, level, this.MaxLevelTransition);
             int num67 = this.SymmetryBlockCount - 1;
             for (baseLevel = 0; baseLevel <= num67; baseLevel++)
             {
                 this.PassageNodes[baseLevel, num].IsWater = node3.IsWater & flag;
                 this.PassageNodes[baseLevel, num].Level = level;
             }
             if (node.IsWater)
             {
                 int num68 = node.ConnectionCount - 1;
                 for (num2 = 0; num2 <= num68; num2++)
                 {
                     other = node.Connections[num2].GetOther();
                     this.PassageNodesMinLevelSet(other, args.PassageNodesMinLevel, node.Level, this.MaxLevelTransition);
                     this.PassageNodesMaxLevelSet(other, args.PassageNodesMaxLevel, node.Level, this.MaxLevelTransition);
                 }
             }
         }
     }
     this.RampBase = 1.0;
     this.MaxDisconnectionDist = 99999f;
     clsResult resultToAdd = this.GenerateRamps();
     result4.Add(resultToAdd);
     return result4;
 }
Example #2
0
        public clsResult ReadPIE(StreamReader File, clsObjectData Owner)
        {
            int num;
            int num2;
            int num3;
            bool flag;
            int num6;
            int num8;
            int num9;
            int num10;
            clsResult result;
            string[] strArray;
            string str;
            string str2;
            string[] strArray2;
            int num12;
            clsResult result2 = new clsResult("Reading PIE");
            string stringCheck = "";
            sPIELevel[] levelArray = new sPIELevel[0];
            int index = -1;
            Label_001E:
            str = File.ReadLine();
            if (str == null)
            {
                goto Label_0BD9;
            }
            Label_002F:
            if (Strings.Left(str, 3) == "PIE")
            {
                num10 = Conversions.ToInteger(Strings.Right(str, str.Length - 4));
                if ((num10 != 2) & (num10 != 3))
                {
                    result2.ProblemAdd("Version is unknown.");
                    return result2;
                }
                goto Label_001E;
            }
            if (Strings.Left(str, 4) == "TYPE")
            {
                goto Label_001E;
            }
            if (Strings.Left(str, 7) == "TEXTURE")
            {
                stringCheck = Strings.Right(str, str.Length - 10);
                num = Strings.InStrRev(stringCheck, " ", -1, CompareMethod.Binary);
                if (num > 0)
                {
                    num = Strings.InStrRev(stringCheck, " ", num - 1, CompareMethod.Binary);
                }
                else
                {
                    result2.ProblemAdd("Bad texture name.");
                    return result2;
                }
                if (num <= 0)
                {
                    result2.ProblemAdd("Bad texture name.");
                    return result2;
                }
                stringCheck = Strings.Left(stringCheck, num - 1);
                goto Label_001E;
            }
            if (Strings.Left(str, 6) == "LEVELS")
            {
                num6 = Conversions.ToInteger(Strings.Right(str, str.Length - 7));
                levelArray = new sPIELevel[(num6 - 1) + 1];
                goto Label_001E;
            }
            if (Strings.Left(str, 6) == "LEVEL ")
            {
                index = Conversions.ToInteger(Strings.Right(str, str.Length - 6)) - 1;
                if (index >= num6)
                {
                    result2.ProblemAdd("Level number >= number of levels.");
                    return result2;
                }
                goto Label_001E;
            }
            if (Strings.Left(str, 6) != "POINTS")
            {
                if (Strings.Left(str, 8) != "POLYGONS")
                {
                    if (Strings.Left(str, 10) != "CONNECTORS")
                    {
                        goto Label_001E;
                    }
                    this.ConnectorCount = Conversions.ToInteger(Strings.Right(str, str.Length - 11));
                    this.Connectors = new modMath.sXYZ_sng[(this.ConnectorCount - 1) + 1];
                    num = 0;
                    goto Label_0A69;
                }
                levelArray[index].PolygonCount = Conversions.ToInteger(Strings.Right(str, str.Length - 9));
                levelArray[index].Polygon = new sPIELevel.sPolygon[(levelArray[index].PolygonCount - 1) + 1];
                num = 0;
            }
            else
            {
                levelArray[index].PointCount = Conversions.ToInteger(Strings.Right(str, str.Length - 7));
                levelArray[index].Point = new modMath.sXYZ_sng[(levelArray[index].PointCount - 1) + 1];
                num = 0;
                while (true)
                {
                    str = File.ReadLine();
                    if (str == null)
                    {
                        goto Label_0BD9;
                    }
                    str2 = Strings.Left(str, 1);
                    if (!((str2 == "\t") | (str2 == " ")))
                    {
                        if (str2 != "")
                        {
                            goto Label_002F;
                        }
                    }
                    else
                    {
                        strArray = new string[3];
                        num3 = 0;
                        strArray[0] = "";
                        flag = false;
                        int num11 = str.Length - 1;
                        for (num2 = 0; num2 <= num11; num2++)
                        {
                            if ((str[num2] != ' ') & (str[num2] != '\t'))
                            {
                                flag = true;
                                strArray2 = strArray;
                                num12 = num3;
                                strArray2[num12] = strArray2[num12] + Conversions.ToString(str[num2]);
                            }
                            else if (flag)
                            {
                                num3++;
                                if (num3 == 3)
                                {
                                    break;
                                }
                                strArray[num3] = "";
                                flag = false;
                            }
                        }
                        try
                        {
                            levelArray[index].Point[num].X = Conversions.ToSingle(strArray[0]);
                            levelArray[index].Point[num].Y = Conversions.ToSingle(strArray[1]);
                            levelArray[index].Point[num].Z = Conversions.ToSingle(strArray[2]);
                        }
                        catch (Exception exception1)
                        {
                            ProjectData.SetProjectError(exception1);
                            Exception exception = exception1;
                            result2.ProblemAdd("Bad point " + Conversions.ToString(num));
                            result = result2;
                            ProjectData.ClearProjectError();
                            return result;
                        }
                        num++;
                    }
                }
            }
            while (true)
            {
                str = File.ReadLine();
                if (str == null)
                {
                    goto Label_0BD9;
                }
                str2 = Strings.Left(str, 1);
                if (!((str2 == "\t") | (str2 == " ")))
                {
                    if (str2 != "")
                    {
                        goto Label_002F;
                    }
                }
                else
                {
                    num3 = 0;
                    strArray = new string[num3 + 1];
                    strArray[num3] = "";
                    int num13 = str.Length - 1;
                    for (num2 = 0; num2 <= num13; num2++)
                    {
                        if ((str[num2] == ' ') | (str[num2] == '\t'))
                        {
                            if (strArray[num3].Length > 0)
                            {
                                num3++;
                                strArray = (string[]) Utils.CopyArray((Array) strArray, new string[num3 + 1]);
                                strArray[num3] = "";
                            }
                        }
                        else
                        {
                            strArray2 = strArray;
                            num12 = num3;
                            strArray2[num12] = strArray2[num12] + Conversions.ToString(str[num2]);
                        }
                    }
                    if (strArray[num3].Length == 0)
                    {
                        strArray = (string[]) Utils.CopyArray((Array) strArray, new string[(num3 - 1) + 1]);
                    }
                    else
                    {
                        num3++;
                    }
                    if (num10 == 3)
                    {
                        int num4;
                        if (num3 < 2)
                        {
                            result2.ProblemAdd("Too few fields for polygon " + Conversions.ToString(num));
                            return result2;
                        }
                        try
                        {
                            num4 = Conversions.ToInteger(strArray[1]);
                        }
                        catch (Exception exception7)
                        {
                            ProjectData.SetProjectError(exception7);
                            Exception exception2 = exception7;
                            result2.ProblemAdd("Bad polygon point count: " + exception2.Message);
                            result = result2;
                            ProjectData.ClearProjectError();
                            return result;
                        }
                        levelArray[index].Polygon[num].PointCount = num4;
                        levelArray[index].Polygon[num].PointNum = new int[(num4 - 1) + 1];
                        levelArray[index].Polygon[num].TexCoord = new modMath.sXY_sng[(num4 - 1) + 1];
                        switch (num4)
                        {
                            case 3:
                                num9++;
                                break;

                            case 4:
                                num8++;
                                break;
                        }
                        int num14 = strArray.GetUpperBound(0) + 1;
                        if (num14 == 0)
                        {
                            goto Label_002F;
                        }
                        if (num14 != (2 + (num4 * 3)))
                        {
                            result2.ProblemAdd("Wrong number of fields (" + Conversions.ToString((int) (strArray.GetUpperBound(0) + 1)) + ") for polygon " + Conversions.ToString(num));
                            return result2;
                        }
                        int num15 = num4 - 1;
                        for (num2 = 0; num2 <= num15; num2++)
                        {
                            try
                            {
                                levelArray[index].Polygon[num].PointNum[num2] = Conversions.ToInteger(strArray[2 + num2]);
                            }
                            catch (Exception exception8)
                            {
                                ProjectData.SetProjectError(exception8);
                                Exception exception3 = exception8;
                                result2.ProblemAdd("Bad polygon point: " + exception3.Message);
                                result = result2;
                                ProjectData.ClearProjectError();
                                return result;
                            }
                            try
                            {
                                levelArray[index].Polygon[num].TexCoord[num2].X = Conversions.ToSingle(strArray[(2 + num4) + (2 * num2)]);
                            }
                            catch (Exception exception9)
                            {
                                ProjectData.SetProjectError(exception9);
                                Exception exception4 = exception9;
                                result2.ProblemAdd("Bad polygon x tex coord: " + exception4.Message);
                                result = result2;
                                ProjectData.ClearProjectError();
                                return result;
                            }
                            try
                            {
                                levelArray[index].Polygon[num].TexCoord[num2].Y = Conversions.ToSingle(strArray[((2 + num4) + (2 * num2)) + 1]);
                            }
                            catch (Exception exception10)
                            {
                                ProjectData.SetProjectError(exception10);
                                Exception exception5 = exception10;
                                result2.ProblemAdd("Bad polygon y tex coord: " + exception5.Message);
                                result = result2;
                                ProjectData.ClearProjectError();
                                return result;
                            }
                        }
                        num++;
                    }
                    else if (num10 == 2)
                    {
                        int num5 = 0;
                        do
                        {
                            levelArray[index].Polygon[num].PointCount = Conversions.ToInteger(strArray[num5 + 1]);
                            levelArray[index].Polygon[num].PointNum = new int[(levelArray[index].Polygon[num].PointCount - 1) + 1];
                            levelArray[index].Polygon[num].TexCoord = new modMath.sXY_sng[(levelArray[index].Polygon[num].PointCount - 1) + 1];
                            if (levelArray[index].Polygon[num].PointCount == 3)
                            {
                                num9++;
                            }
                            else if (levelArray[index].Polygon[num].PointCount == 4)
                            {
                                num8++;
                            }
                            int num16 = levelArray[index].Polygon[num].PointCount - 1;
                            for (num2 = 0; num2 <= num16; num2++)
                            {
                                levelArray[index].Polygon[num].PointNum[num2] = Conversions.ToInteger(strArray[(num5 + 2) + num2]);
                            }
                            num3 = (num5 + 2) + levelArray[index].Polygon[num].PointCount;
                            if ((((((((strArray[num5] == "4200") | (strArray[num5] == "4000")) | (strArray[num5] == "6a00")) | (strArray[num5] == "4a00")) | (strArray[num5] == "6200")) | (strArray[num5] == "14200")) | (strArray[num5] == "14a00")) | (strArray[num5] == "16a00"))
                            {
                                num3 += 4;
                            }
                            int num17 = levelArray[index].Polygon[num].PointCount - 1;
                            for (num2 = 0; num2 <= num17; num2++)
                            {
                                levelArray[index].Polygon[num].TexCoord[num2].X = Conversions.ToSingle(strArray[num3]);
                                levelArray[index].Polygon[num].TexCoord[num2].Y = Conversions.ToSingle(strArray[num3 + 1]);
                                num3 += 2;
                            }
                            num5 = num3;
                            num++;
                        }
                        while (num5 < strArray.GetUpperBound(0));
                    }
                }
            }
            Label_0A69:
            str = File.ReadLine();
            if (str != null)
            {
                str2 = Strings.Left(str, 1);
                if (!((str2 == "\t") | (str2 == " ")))
                {
                    if (str2 != "")
                    {
                        goto Label_002F;
                    }
                }
                else
                {
                    strArray = new string[3];
                    num3 = 0;
                    strArray[0] = "";
                    flag = false;
                    int num18 = str.Length - 1;
                    for (num2 = 0; num2 <= num18; num2++)
                    {
                        if ((str[num2] != ' ') & (str[num2] != '\t'))
                        {
                            flag = true;
                            strArray2 = strArray;
                            num12 = num3;
                            strArray2[num12] = strArray2[num12] + Conversions.ToString(str[num2]);
                        }
                        else if (flag)
                        {
                            num3++;
                            if (num3 == 3)
                            {
                                break;
                            }
                            strArray[num3] = "";
                            flag = false;
                        }
                    }
                    try
                    {
                        this.Connectors[num].X = Conversions.ToSingle(strArray[0]);
                        this.Connectors[num].Y = Conversions.ToSingle(strArray[2]);
                        this.Connectors[num].Z = Conversions.ToSingle(strArray[1]);
                    }
                    catch (Exception exception11)
                    {
                        ProjectData.SetProjectError(exception11);
                        Exception exception6 = exception11;
                        result2.ProblemAdd("Bad connector " + Conversions.ToString(num));
                        result = result2;
                        ProjectData.ClearProjectError();
                        return result;
                    }
                    num++;
                }
                goto Label_0A69;
            }
            Label_0BD9:
            this.GLTextureNum = Owner.Get_TexturePage_GLTexture(Strings.Left(stringCheck, stringCheck.Length - 4));
            if (this.GLTextureNum == 0)
            {
                result2.WarningAdd("Texture \"" + stringCheck + "\" was not loaded");
            }
            this.TriangleCount = num9;
            this.QuadCount = num8;
            this.Triangles = new sTriangle[(this.TriangleCount - 1) + 1];
            this.Quads = new sQuad[(this.QuadCount - 1) + 1];
            num9 = 0;
            num8 = 0;
            int num19 = num6 - 1;
            for (index = 0; index <= num19; index++)
            {
                int num20 = levelArray[index].PolygonCount - 1;
                for (num = 0; num <= num20; num++)
                {
                    if (levelArray[index].Polygon[num].PointCount == 3)
                    {
                        this.Triangles[num9].PosA = levelArray[index].Point[levelArray[index].Polygon[num].PointNum[0]];
                        this.Triangles[num9].PosB = levelArray[index].Point[levelArray[index].Polygon[num].PointNum[1]];
                        this.Triangles[num9].PosC = levelArray[index].Point[levelArray[index].Polygon[num].PointNum[2]];
                        switch (num10)
                        {
                            case 2:
                                this.Triangles[num9].TexCoordA.X = (float) (((double) levelArray[index].Polygon[num].TexCoord[0].X) / 255.0);
                                this.Triangles[num9].TexCoordA.Y = (float) (((double) levelArray[index].Polygon[num].TexCoord[0].Y) / 255.0);
                                this.Triangles[num9].TexCoordB.X = (float) (((double) levelArray[index].Polygon[num].TexCoord[1].X) / 255.0);
                                this.Triangles[num9].TexCoordB.Y = (float) (((double) levelArray[index].Polygon[num].TexCoord[1].Y) / 255.0);
                                this.Triangles[num9].TexCoordC.X = (float) (((double) levelArray[index].Polygon[num].TexCoord[2].X) / 255.0);
                                this.Triangles[num9].TexCoordC.Y = (float) (((double) levelArray[index].Polygon[num].TexCoord[2].Y) / 255.0);
                                break;

                            case 3:
                                this.Triangles[num9].TexCoordA = levelArray[index].Polygon[num].TexCoord[0];
                                this.Triangles[num9].TexCoordB = levelArray[index].Polygon[num].TexCoord[1];
                                this.Triangles[num9].TexCoordC = levelArray[index].Polygon[num].TexCoord[2];
                                break;
                        }
                        num9++;
                        continue;
                    }
                    if (levelArray[index].Polygon[num].PointCount == 4)
                    {
                        this.Quads[num8].PosA = levelArray[index].Point[levelArray[index].Polygon[num].PointNum[0]];
                        this.Quads[num8].PosB = levelArray[index].Point[levelArray[index].Polygon[num].PointNum[1]];
                        this.Quads[num8].PosC = levelArray[index].Point[levelArray[index].Polygon[num].PointNum[2]];
                        this.Quads[num8].PosD = levelArray[index].Point[levelArray[index].Polygon[num].PointNum[3]];
                        switch (num10)
                        {
                            case 2:
                                this.Quads[num8].TexCoordA.X = (float) (((double) levelArray[index].Polygon[num].TexCoord[0].X) / 255.0);
                                this.Quads[num8].TexCoordA.Y = (float) (((double) levelArray[index].Polygon[num].TexCoord[0].Y) / 255.0);
                                this.Quads[num8].TexCoordB.X = (float) (((double) levelArray[index].Polygon[num].TexCoord[1].X) / 255.0);
                                this.Quads[num8].TexCoordB.Y = (float) (((double) levelArray[index].Polygon[num].TexCoord[1].Y) / 255.0);
                                this.Quads[num8].TexCoordC.X = (float) (((double) levelArray[index].Polygon[num].TexCoord[2].X) / 255.0);
                                this.Quads[num8].TexCoordC.Y = (float) (((double) levelArray[index].Polygon[num].TexCoord[2].Y) / 255.0);
                                this.Quads[num8].TexCoordD.X = (float) (((double) levelArray[index].Polygon[num].TexCoord[3].X) / 255.0);
                                this.Quads[num8].TexCoordD.Y = (float) (((double) levelArray[index].Polygon[num].TexCoord[3].Y) / 255.0);
                                break;

                            case 3:
                                this.Quads[num8].TexCoordA = levelArray[index].Polygon[num].TexCoord[0];
                                this.Quads[num8].TexCoordB = levelArray[index].Polygon[num].TexCoord[1];
                                this.Quads[num8].TexCoordC = levelArray[index].Polygon[num].TexCoord[2];
                                this.Quads[num8].TexCoordD = levelArray[index].Polygon[num].TexCoord[3];
                                break;
                        }
                        num8++;
                    }
                }
            }
            return result2;
        }
Example #3
0
 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;
 }
Example #4
0
 public clsResult GenerateUnits()
 {
     int num;
     int num3;
     int num5;
     int num7;
     modMath.sXY_int _int;
     uint num12;
     int num13;
     clsMap.clsUnit unit;
     uint num14;
     clsResult result2 = new clsResult("Objects");
     int maxDistFromPos = 0x300;
     int num4 = 0x800;
     clsMap.clsTerrain terrain = this.Map.Terrain;
     int num15 = this.PassageNodeCount - 1;
     for (num = 0; num <= num15; num++)
     {
         int num16 = this.SymmetryBlockCount - 1;
         num3 = 0;
         while (num3 <= num16)
         {
             this.PassageNodes[num3, num].HasFeatureCluster = false;
             num3++;
         }
     }
     int num17 = this.TotalPlayerCount - 1;
     for (num = 0; num <= num17; num++)
     {
         int num11 = num;
         if (this.PlaceUnitNear(modGenerator.UnitType_CommandCentre, this.PlayerBases[num].Pos, this.Map.UnitGroups[num11], 3, 0, num4) == null)
         {
             result2.ProblemAdd("No room for base structures");
             return result2;
         }
         unit = this.PlaceUnitNear(modGenerator.UnitType_PowerGenerator, this.PlayerBases[num].Pos, this.Map.UnitGroups[num11], 3, 0, num4);
         if (unit == null)
         {
             result2.ProblemAdd("No room for base structures.");
             return result2;
         }
         if (this.PlaceUnit(modGenerator.UnitType_PowerModule, unit.Pos, this.Map.UnitGroups[num11], 0) == null)
         {
             result2.ProblemAdd("No room for module.");
             return result2;
         }
         num3 = 1;
         do
         {
             unit = this.PlaceUnitNear(modGenerator.UnitType_ResearchFacility, this.PlayerBases[num].Pos, this.Map.UnitGroups[num11], 3, 0, num4);
             if (unit == null)
             {
                 result2.ProblemAdd("No room for base structures");
                 return result2;
             }
             if (this.PlaceUnit(modGenerator.UnitType_ResearchModule, unit.Pos, this.Map.UnitGroups[num11], 0) == null)
             {
                 result2.ProblemAdd("No room for module.");
                 return result2;
             }
             num3++;
         }
         while (num3 <= 2);
         num3 = 1;
         do
         {
             unit = this.PlaceUnitNear(modGenerator.UnitType_Factory, this.PlayerBases[num].Pos, this.Map.UnitGroups[num11], 4, 0, num4);
             if (unit == null)
             {
                 result2.ProblemAdd("No room for base structures");
                 return result2;
             }
             if (this.PlaceUnit(modGenerator.UnitType_FactoryModule, unit.Pos, this.Map.UnitGroups[num11], 0) == null)
             {
                 result2.ProblemAdd("No room for module.");
                 return result2;
             }
             num3++;
         }
         while (num3 <= 2);
         if (this.PlaceUnitNear(modGenerator.UnitType_CyborgFactory, this.PlayerBases[num].Pos, this.Map.UnitGroups[num11], 3, 0, num4) == null)
         {
             result2.ProblemAdd("No room for base structures");
             return result2;
         }
         int baseTruckCount = this.BaseTruckCount;
         num3 = 1;
         while (num3 <= baseTruckCount)
         {
             if (this.PlaceUnitNear(modGenerator.UnitType_Truck, this.PlayerBases[num].Pos, this.Map.UnitGroups[num11], 2, 0, num4) == null)
             {
                 result2.ProblemAdd("No room for trucks");
                 return result2;
             }
             num3++;
         }
     }
     int num19 = this.PassageNodeCount - 1;
     for (num = 0; num <= num19; num++)
     {
         int num20 = this.SymmetryBlockCount - 1;
         num7 = 0;
         while (num7 <= num20)
         {
             int num21 = this.PassageNodes[num7, num].OilCount - 1;
             num3 = 0;
             while (num3 <= num21)
             {
                 modMath.sXY_int _int2;
                 if (this.PassageNodes[num7, num].PlayerBaseNum >= 0)
                 {
                     unit = this.PlaceUnitNear(modGenerator.UnitType_OilResource, this.PassageNodes[num7, num].Pos, this.Map.ScavengerUnitGroup, 2, 0, num4);
                 }
                 else
                 {
                     unit = this.PlaceUnitNear(modGenerator.UnitType_OilResource, this.PassageNodes[num7, num].Pos, this.Map.ScavengerUnitGroup, 2, 0, maxDistFromPos);
                 }
                 if (unit == null)
                 {
                     result2.ProblemAdd("No room for oil.");
                     return result2;
                 }
                 _int2.X = (int) Math.Round(((double) (((double) unit.Pos.Horizontal.X) / 128.0)));
                 _int2.Y = (int) Math.Round(((double) (((double) unit.Pos.Horizontal.Y) / 128.0)));
                 byte num2 = (byte) Math.Round((double) (((double) (((terrain.Vertices[_int2.X, _int2.Y].Height + terrain.Vertices[_int2.X + 1, _int2.Y].Height) + terrain.Vertices[_int2.X, _int2.Y + 1].Height) + terrain.Vertices[_int2.X + 1, _int2.Y + 1].Height)) / 4.0));
                 terrain.Vertices[_int2.X, _int2.Y].Height = num2;
                 terrain.Vertices[_int2.X + 1, _int2.Y].Height = num2;
                 terrain.Vertices[_int2.X, _int2.Y + 1].Height = num2;
                 terrain.Vertices[_int2.X + 1, _int2.Y + 1].Height = num2;
                 this.Map.SectorGraphicsChanges.TileChanged(_int2);
                 this.Map.SectorUnitHeightsChanges.TileChanged(_int2);
                 this.Map.SectorTerrainUndoChanges.TileChanged(_int2);
                 unit.Pos.Altitude = num2 * this.Map.HeightMultiplier;
                 if ((this.PassageNodes[num7, num].PlayerBaseNum >= 0) && (this.PlaceUnit(modGenerator.UnitType_Derrick, unit.Pos, this.Map.UnitGroups[this.PassageNodes[num7, num].PlayerBaseNum], 0) == null))
                 {
                     result2.ProblemAdd("No room for derrick.");
                     return result2;
                 }
                 num3++;
             }
             num7++;
         }
     }
     int num22 = this.PassageNodeCount - 1;
     for (num = 0; num <= num22; num++)
     {
         int num23 = this.SymmetryBlockCount - 1;
         num7 = 0;
         while (num7 <= num23)
         {
             if ((this.PassageNodes[num7, num].PlayerBaseNum < 0) & !this.PassageNodes[num7, num].IsOnBorder)
             {
                 this.PassageNodes[num7, num].HasFeatureCluster = App.Random.Next() < this.FeatureClusterChance;
             }
             num7++;
         }
     }
     int num10 = 0;
     if (this.GenerateTileset.ClusteredUnitChanceTotal > 0)
     {
         int num24 = this.PassageNodeCount - 1;
         for (num = 0; num <= num24; num++)
         {
             int num25 = this.SymmetryBlockCount - 1;
             for (num7 = 0; num7 <= num25; num7++)
             {
                 if (this.PassageNodes[num7, num].HasFeatureCluster)
                 {
                     int num6 = this.FeatureClusterMinUnits + ((int) Math.Round((double) ((float) (App.Random.Next() * ((this.FeatureClusterMaxUnits - this.FeatureClusterMinUnits) + 1)))));
                     int num26 = num6;
                     num3 = 1;
                     while (num3 <= num26)
                     {
                         num12 = (uint) Math.Round(((double) (App.Random.Next() * this.GenerateTileset.ClusteredUnitChanceTotal)));
                         num14 = 0;
                         int num27 = this.GenerateTileset.ClusteredUnitCount - 1;
                         num5 = 0;
                         while (num5 <= num27)
                         {
                             num14 += this.GenerateTileset.ClusteredUnits[num5].Chance;
                             if (num12 < num14)
                             {
                                 break;
                             }
                             num5++;
                         }
                         num13 = 0;
                         _int = this.GenerateTileset.ClusteredUnits[num5].Type.get_GetFootprintSelected(num13);
                         int clearance = ((int) Math.Round(Math.Ceiling((double) (((float) Math.Max(_int.X, _int.Y)) / 2f)))) + 1;
                         if (this.PlaceUnitNear(this.GenerateTileset.ClusteredUnits[num5].Type, this.PassageNodes[num7, num].Pos, this.Map.ScavengerUnitGroup, clearance, num13, maxDistFromPos) == null)
                         {
                             num10 += (num6 - num3) + 1;
                             break;
                         }
                         num3++;
                     }
                 }
             }
         }
         if (num10 > 0)
         {
             result2.WarningAdd("Not enough space for " + Conversions.ToString(num10) + " clustered objects.");
         }
     }
     if (this.TilePathMap.get_GetNodeLayer(this.TilePathMap.GetNodeLayerCount - 1).GetNodeCount != 1)
     {
         result2.ProblemAdd("Error: bad node count on top layer!");
         return result2;
     }
     if (this.GenerateTileset.ScatteredUnitChanceTotal > 0)
     {
         int featureScatterCount = this.FeatureScatterCount;
         num = 1;
         while (num <= featureScatterCount)
         {
             num12 = (uint) Math.Round(((double) (App.Random.Next() * this.GenerateTileset.ScatteredUnitChanceTotal)));
             num14 = 0;
             int num29 = this.GenerateTileset.ScatteredUnitCount - 1;
             num5 = 0;
             while (num5 <= num29)
             {
                 num14 += this.GenerateTileset.ScatteredUnits[num5].Chance;
                 if (num12 < num14)
                 {
                     break;
                 }
                 num5++;
             }
             num13 = 0;
             _int = this.GenerateTileset.ScatteredUnits[num5].Type.get_GetFootprintSelected(num13);
             num3 = this.FeatureScatterGap + ((int) Math.Round(Math.Ceiling((double) (((float) Math.Max(_int.X, _int.Y)) / 2f))));
             PathfinderNode randomChildNode = this.GetRandomChildNode(this.TilePathMap.get_GetNodeLayer(this.TilePathMap.GetNodeLayerCount - 1).get_GetNode(0), num3);
             if (randomChildNode == null)
             {
                 break;
             }
             clsNodeTag tag = (clsNodeTag) randomChildNode.Tag;
             if (this.PlaceUnitNear(this.GenerateTileset.ScatteredUnits[num5].Type, tag.Pos, this.Map.ScavengerUnitGroup, num3, num13, maxDistFromPos) == null)
             {
                 break;
             }
             num++;
         }
         if (num < (this.FeatureScatterCount + 1))
         {
             result2.WarningAdd("Only enough space for " + Conversions.ToString((int) (num - 1)) + " scattered objects.");
         }
     }
     return result2;
 }
Example #5
0
 public static clsResult WriteMemoryToNewFile(MemoryStream Memory, string Path)
 {
     FileStream stream;
     clsResult result2;
     clsResult result = new clsResult("Writing to \"" + Path + "\"");
     try
     {
         stream = new FileStream(Path, FileMode.CreateNew);
     }
     catch (Exception exception1)
     {
         ProjectData.SetProjectError(exception1);
         Exception exception = exception1;
         result.ProblemAdd(exception.Message);
         result2 = result;
         ProjectData.ClearProjectError();
         return result2;
     }
     try
     {
         Memory.WriteTo(stream);
     }
     catch (Exception exception3)
     {
         ProjectData.SetProjectError(exception3);
         Exception exception2 = exception3;
         result.ProblemAdd(exception2.Message);
         result2 = result;
         ProjectData.ClearProjectError();
         return result2;
     }
     Memory.Close();
     stream.Close();
     return result;
 }
Example #6
0
 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;
 }
Example #7
0
        public clsResult LoadDirectory(string Path)
        {
            IEnumerator enumerator;
            clsResult result3 = new clsResult("Loading object data from \"" + Path + "\"");
            Path = modProgram.EndWithPathSeperator(Path);
            string str10 = "messages" + Conversions.ToString(modProgram.PlatformPathSeparator) + "strings" + Conversions.ToString(modProgram.PlatformPathSeparator) + "names.txt";
            string str17 = "stats" + Conversions.ToString(modProgram.PlatformPathSeparator) + "structures.txt";
            string str5 = "stats" + Conversions.ToString(modProgram.PlatformPathSeparator) + "brain.txt";
            string str3 = "stats" + Conversions.ToString(modProgram.PlatformPathSeparator) + "body.txt";
            string str13 = "stats" + Conversions.ToString(modProgram.PlatformPathSeparator) + "propulsion.txt";
            string str4 = "stats" + Conversions.ToString(modProgram.PlatformPathSeparator) + "bodypropulsionimd.txt";
            string str6 = "stats" + Conversions.ToString(modProgram.PlatformPathSeparator) + "construction.txt";
            string str15 = "stats" + Conversions.ToString(modProgram.PlatformPathSeparator) + "sensor.txt";
            string str14 = "stats" + Conversions.ToString(modProgram.PlatformPathSeparator) + "repair.txt";
            string str19 = "stats" + Conversions.ToString(modProgram.PlatformPathSeparator) + "templates.txt";
            string str21 = "stats" + Conversions.ToString(modProgram.PlatformPathSeparator) + "weapons.txt";
            string str7 = "stats" + Conversions.ToString(modProgram.PlatformPathSeparator) + "ecm.txt";
            string str9 = "stats" + Conversions.ToString(modProgram.PlatformPathSeparator) + "features.txt";
            string str11 = "pies" + Conversions.ToString(modProgram.PlatformPathSeparator);
            string str16 = str11;
            string str2 = str11;
            string str12 = str11;
            string str22 = str11;
            string str20 = "texpages" + Conversions.ToString(modProgram.PlatformPathSeparator);
            string str = "stats" + Conversions.ToString(modProgram.PlatformPathSeparator) + "assignweapons.txt";
            string str8 = str11;
            string str18 = "stats" + Conversions.ToString(modProgram.PlatformPathSeparator) + "structureweapons.txt";
            modLists.SimpleList<clsTextFile> list = new modLists.SimpleList<clsTextFile>();
            clsTextFile file8 = new clsTextFile {
                SubDirectory = str10,
                UniqueField = 0
            };
            result3.Add(file8.LoadNamesFile(Path));
            if (!file8.CalcUniqueField())
            {
                result3.ProblemAdd("There are two entries for the same code in " + str10 + ".");
            }
            clsTextFile newItem = new clsTextFile {
                SubDirectory = str17,
                FieldCount = 0x19
            };
            list.Add(newItem);
            clsTextFile file4 = new clsTextFile {
                SubDirectory = str5,
                FieldCount = 9
            };
            list.Add(file4);
            clsTextFile file2 = new clsTextFile {
                SubDirectory = str3,
                FieldCount = 0x19
            };
            list.Add(file2);
            clsTextFile file9 = new clsTextFile {
                SubDirectory = str13,
                FieldCount = 12
            };
            list.Add(file9);
            clsTextFile file3 = new clsTextFile {
                SubDirectory = str4,
                FieldCount = 5,
                UniqueField = -1
            };
            list.Add(file3);
            clsTextFile file5 = new clsTextFile {
                SubDirectory = str6,
                FieldCount = 12
            };
            list.Add(file5);
            clsTextFile file11 = new clsTextFile {
                SubDirectory = str15,
                FieldCount = 0x10
            };
            list.Add(file11);
            clsTextFile file10 = new clsTextFile {
                SubDirectory = str14,
                FieldCount = 14
            };
            list.Add(file10);
            clsTextFile file14 = new clsTextFile {
                SubDirectory = str19,
                FieldCount = 12
            };
            list.Add(file14);
            clsTextFile file6 = new clsTextFile {
                SubDirectory = str7,
                FieldCount = 14
            };
            list.Add(file6);
            clsTextFile file7 = new clsTextFile {
                SubDirectory = str9,
                FieldCount = 11
            };
            list.Add(file7);
            clsTextFile file = new clsTextFile {
                SubDirectory = str,
                FieldCount = 5
            };
            list.Add(file);
            clsTextFile file15 = new clsTextFile {
                SubDirectory = str21,
                FieldCount = 0x35
            };
            list.Add(file15);
            clsTextFile file13 = new clsTextFile {
                SubDirectory = str18,
                FieldCount = 6
            };
            list.Add(file13);
            try
            {
                enumerator = list.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    clsTextFile current = (clsTextFile) enumerator.Current;
                    clsResult resultToAdd = current.LoadCommaFile(Path);
                    result3.Add(resultToAdd);
                    if (!resultToAdd.HasProblems)
                    {
                        if (current.CalcIsFieldCountValid())
                        {
                            if (!current.CalcUniqueField())
                            {
                                result3.ProblemAdd("An entry in field " + Conversions.ToString(current.UniqueField) + " was not unique for file " + current.SubDirectory + ".");
                            }
                        }
                        else
                        {
                            result3.ProblemAdd("There were entries with the wrong number of fields for file " + current.SubDirectory + ".");
                        }
                    }
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            if (!result3.HasProblems)
            {
                clsUnitType.clsAttachment baseAttachment;
                clsBody body;
                clsECM secm;
                string[] strArray;
                string[] strArray2;
                clsPropulsion propulsion;
                clsSensor sensor;
                string[] files;
                clsWeapon weapon;
                IEnumerator enumerator2;
                IEnumerator enumerator3;
                IEnumerator enumerator4;
                IEnumerator enumerator5;
                IEnumerator enumerator6;
                IEnumerator enumerator7;
                IEnumerator enumerator8;
                IEnumerator enumerator9;
                IEnumerator enumerator10;
                IEnumerator enumerator11;
                IEnumerator enumerator12;
                IEnumerator enumerator13;
                try
                {
                    files = Directory.GetFiles(Path + str20);
                }
                catch (Exception exception1)
                {
                    ProjectData.SetProjectError(exception1);
                    Exception exception = exception1;
                    result3.WarningAdd("Unable to access texture pages.");
                    files = new string[0];
                    ProjectData.ClearProjectError();
                }
                System.Drawing.Bitmap resultBitmap = null;
                foreach (string str23 in files)
                {
                    if (Strings.Right(str23, 4).ToLower() == ".png")
                    {
                        clsResult result5 = new clsResult("Loading texture page \"" + str23 + "\"");
                        if (File.Exists(str23))
                        {
                            modProgram.sResult result = modBitmap.LoadBitmap(str23, ref resultBitmap);
                            clsTexturePage page = new clsTexturePage();
                            if (result.Success)
                            {
                                modBitmap.sBitmapGLTexture texture;
                                result5.Take(modBitmap.BitmapIsGLCompatible(resultBitmap));
                                texture.MagFilter = TextureMagFilter.Nearest;
                                texture.MinFilter = TextureMinFilter.Nearest;
                                texture.TextureNum = 0;
                                texture.MipMapLevel = 0;
                                texture.Texture = resultBitmap;
                                texture.Perform();
                                page.GLTexture_Num = texture.TextureNum;
                            }
                            else
                            {
                                result5.WarningAdd(result.Problem);
                            }
                            int num = Strings.InStrRev(str23, Conversions.ToString(modProgram.PlatformPathSeparator), -1, CompareMethod.Binary);
                            page.FileTitle = Strings.Mid(str23, num + 1, (str23.Length - 4) - num);
                            this.TexturePages.Add(page);
                        }
                        else
                        {
                            result5.WarningAdd("Texture page missing (" + str23 + ").");
                        }
                        result3.Add(result5);
                    }
                }
                modLists.SimpleList<clsPIE> list2 = new modLists.SimpleList<clsPIE>();
                try
                {
                    strArray2 = Directory.GetFiles(Path + str11);
                }
                catch (Exception exception3)
                {
                    ProjectData.SetProjectError(exception3);
                    Exception exception2 = exception3;
                    result3.WarningAdd("Unable to access PIE files.");
                    strArray2 = new string[0];
                    ProjectData.ClearProjectError();
                }
                foreach (string str23 in strArray2)
                {
                    modProgram.sSplitPath path = new modProgram.sSplitPath(str23);
                    if (path.FileExtension.ToLower() == "pie")
                    {
                        clsPIE spie = new clsPIE {
                            Path = str23,
                            LCaseFileTitle = path.FileTitle.ToLower()
                        };
                        list2.Add(spie);
                    }
                }
                try
                {
                    enumerator2 = file2.ResultData.GetEnumerator();
                    while (enumerator2.MoveNext())
                    {
                        strArray = (string[]) enumerator2.Current;
                        body = new clsBody();
                        body.ObjectDataLink.Connect(this.Bodies);
                        body.Code = strArray[0];
                        this.SetComponentName(file8.ResultData, body, result3);
                        modIO.InvariantParse_int(strArray[6], ref body.Hitpoints);
                        body.Designable = strArray[0x18] != "0";
                        body.Attachment.Models.Add(this.GetModelForPIE(list2, strArray[7].ToLower(), result3));
                    }
                }
                finally
                {
                    if (enumerator2 is IDisposable)
                    {
                        (enumerator2 as IDisposable).Dispose();
                    }
                }
                try
                {
                    enumerator3 = file9.ResultData.GetEnumerator();
                    while (enumerator3.MoveNext())
                    {
                        strArray = (string[]) enumerator3.Current;
                        propulsion = new clsPropulsion(this.Bodies.Count);
                        propulsion.ObjectDataLink.Connect(this.Propulsions);
                        propulsion.Code = strArray[0];
                        this.SetComponentName(file8.ResultData, propulsion, result3);
                        modIO.InvariantParse_int(strArray[7], ref propulsion.HitPoints);
                        propulsion.Designable = strArray[11] != "0";
                    }
                }
                finally
                {
                    if (enumerator3 is IDisposable)
                    {
                        (enumerator3 as IDisposable).Dispose();
                    }
                }
                BodyProp[,] propArray = new BodyProp[(this.Bodies.Count - 1) + 1, (this.Propulsions.Count - 1) + 1];
                int num10 = this.Bodies.Count - 1;
                for (int i = 0; i <= num10; i++)
                {
                    int num11 = this.Propulsions.Count - 1;
                    for (int k = 0; k <= num11; k++)
                    {
                        propArray[i, k] = new BodyProp();
                        propArray[i, k].LeftPIE = "0";
                        propArray[i, k].RightPIE = "0";
                    }
                }
                try
                {
                    enumerator4 = file3.ResultData.GetEnumerator();
                    while (enumerator4.MoveNext())
                    {
                        strArray = (string[]) enumerator4.Current;
                        body = this.FindBodyCode(strArray[0]);
                        propulsion = this.FindPropulsionCode(strArray[1]);
                        if ((body != null) & (propulsion != null))
                        {
                            if (strArray[2] != "0")
                            {
                                propArray[body.ObjectDataLink.ArrayPosition, propulsion.ObjectDataLink.ArrayPosition].LeftPIE = strArray[2].ToLower();
                            }
                            if (strArray[3] != "0")
                            {
                                propArray[body.ObjectDataLink.ArrayPosition, propulsion.ObjectDataLink.ArrayPosition].RightPIE = strArray[3].ToLower();
                            }
                        }
                    }
                }
                finally
                {
                    if (enumerator4 is IDisposable)
                    {
                        (enumerator4 as IDisposable).Dispose();
                    }
                }
                int num12 = this.Propulsions.Count - 1;
                for (int j = 0; j <= num12; j++)
                {
                    propulsion = this.Propulsions[j];
                    int num13 = this.Bodies.Count - 1;
                    for (int m = 0; m <= num13; m++)
                    {
                        body = this.Bodies[m];
                        propulsion.Bodies[m].LeftAttachment = new clsUnitType.clsAttachment();
                        propulsion.Bodies[m].LeftAttachment.Models.Add(this.GetModelForPIE(list2, propArray[m, j].LeftPIE, result3));
                        propulsion.Bodies[m].RightAttachment = new clsUnitType.clsAttachment();
                        propulsion.Bodies[m].RightAttachment.Models.Add(this.GetModelForPIE(list2, propArray[m, j].RightPIE, result3));
                    }
                }
                try
                {
                    enumerator5 = file5.ResultData.GetEnumerator();
                    while (enumerator5.MoveNext())
                    {
                        strArray = (string[]) enumerator5.Current;
                        clsConstruct component = new clsConstruct();
                        component.ObjectDataLink.Connect(this.Constructors);
                        component.TurretObjectDataLink.Connect(this.Turrets);
                        component.Code = strArray[0];
                        this.SetComponentName(file8.ResultData, component, result3);
                        component.Designable = strArray[11] != "0";
                        component.Attachment.Models.Add(this.GetModelForPIE(list2, strArray[8].ToLower(), result3));
                    }
                }
                finally
                {
                    if (enumerator5 is IDisposable)
                    {
                        (enumerator5 as IDisposable).Dispose();
                    }
                }
                try
                {
                    enumerator6 = file15.ResultData.GetEnumerator();
                    while (enumerator6.MoveNext())
                    {
                        strArray = (string[]) enumerator6.Current;
                        weapon = new clsWeapon();
                        weapon.ObjectDataLink.Connect(this.Weapons);
                        weapon.TurretObjectDataLink.Connect(this.Turrets);
                        weapon.Code = strArray[0];
                        this.SetComponentName(file8.ResultData, weapon, result3);
                        modIO.InvariantParse_int(strArray[7], ref weapon.HitPoints);
                        weapon.Designable = strArray[0x33] != "0";
                        weapon.Attachment.Models.Add(this.GetModelForPIE(list2, strArray[8].ToLower(), result3));
                        weapon.Attachment.Models.Add(this.GetModelForPIE(list2, strArray[9].ToLower(), result3));
                    }
                }
                finally
                {
                    if (enumerator6 is IDisposable)
                    {
                        (enumerator6 as IDisposable).Dispose();
                    }
                }
                try
                {
                    enumerator7 = file11.ResultData.GetEnumerator();
                    while (enumerator7.MoveNext())
                    {
                        strArray = (string[]) enumerator7.Current;
                        sensor = new clsSensor();
                        sensor.ObjectDataLink.Connect(this.Sensors);
                        sensor.TurretObjectDataLink.Connect(this.Turrets);
                        sensor.Code = strArray[0];
                        this.SetComponentName(file8.ResultData, sensor, result3);
                        modIO.InvariantParse_int(strArray[7], ref sensor.HitPoints);
                        sensor.Designable = strArray[15] != "0";
                        string str27 = strArray[11].ToLower();
                        if (str27 == "turret")
                        {
                            sensor.Location = clsSensor.enumLocation.Turret;
                        }
                        else if (str27 == "default")
                        {
                            sensor.Location = clsSensor.enumLocation.Invisible;
                        }
                        else
                        {
                            sensor.Location = clsSensor.enumLocation.Invisible;
                        }
                        sensor.Attachment.Models.Add(this.GetModelForPIE(list2, strArray[8].ToLower(), result3));
                        sensor.Attachment.Models.Add(this.GetModelForPIE(list2, strArray[9].ToLower(), result3));
                    }
                }
                finally
                {
                    if (enumerator7 is IDisposable)
                    {
                        (enumerator7 as IDisposable).Dispose();
                    }
                }
                try
                {
                    enumerator8 = file10.ResultData.GetEnumerator();
                    while (enumerator8.MoveNext())
                    {
                        strArray = (string[]) enumerator8.Current;
                        clsRepair repair = new clsRepair();
                        repair.ObjectDataLink.Connect(this.Repairs);
                        repair.TurretObjectDataLink.Connect(this.Turrets);
                        repair.Code = strArray[0];
                        this.SetComponentName(file8.ResultData, repair, result3);
                        repair.Designable = strArray[13] != "0";
                        repair.Attachment.Models.Add(this.GetModelForPIE(list2, strArray[9].ToLower(), result3));
                        repair.Attachment.Models.Add(this.GetModelForPIE(list2, strArray[10].ToLower(), result3));
                    }
                }
                finally
                {
                    if (enumerator8 is IDisposable)
                    {
                        (enumerator8 as IDisposable).Dispose();
                    }
                }
                try
                {
                    enumerator9 = file4.ResultData.GetEnumerator();
                    while (enumerator9.MoveNext())
                    {
                        strArray = (string[]) enumerator9.Current;
                        clsBrain brain = new clsBrain();
                        brain.ObjectDataLink.Connect(this.Brains);
                        brain.TurretObjectDataLink.Connect(this.Turrets);
                        brain.Code = strArray[0];
                        this.SetComponentName(file8.ResultData, brain, result3);
                        brain.Designable = true;
                        weapon = this.FindWeaponCode(strArray[7]);
                        if (weapon != null)
                        {
                            brain.Weapon = weapon;
                            brain.Attachment = weapon.Attachment;
                        }
                    }
                }
                finally
                {
                    if (enumerator9 is IDisposable)
                    {
                        (enumerator9 as IDisposable).Dispose();
                    }
                }
                try
                {
                    enumerator10 = file6.ResultData.GetEnumerator();
                    while (enumerator10.MoveNext())
                    {
                        strArray = (string[]) enumerator10.Current;
                        secm = new clsECM();
                        secm.ObjectDataLink.Connect(this.ECMs);
                        secm.TurretObjectDataLink.Connect(this.Turrets);
                        secm.Code = strArray[0];
                        this.SetComponentName(file8.ResultData, secm, result3);
                        modIO.InvariantParse_int(strArray[7], ref secm.HitPoints);
                        secm.Designable = false;
                        secm.Attachment.Models.Add(this.GetModelForPIE(list2, strArray[8].ToLower(), result3));
                    }
                }
                finally
                {
                    if (enumerator10 is IDisposable)
                    {
                        (enumerator10 as IDisposable).Dispose();
                    }
                }
                try
                {
                    enumerator11 = file7.ResultData.GetEnumerator();
                    while (enumerator11.MoveNext())
                    {
                        strArray = (string[]) enumerator11.Current;
                        clsFeatureType featureType = new clsFeatureType();
                        featureType.UnitType_ObjectDataLink.Connect(this.UnitTypes);
                        featureType.FeatureType_ObjectDataLink.Connect(this.FeatureTypes);
                        featureType.Code = strArray[0];
                        if (strArray[7] == "OIL RESOURCE")
                        {
                            featureType.FeatureType = clsFeatureType.enumFeatureType.OilResource;
                        }
                        this.SetFeatureName(file8.ResultData, featureType, result3);
                        if (!modIO.InvariantParse_int(strArray[1], ref featureType.Footprint.X))
                        {
                            result3.WarningAdd("Feature footprint-x was not an integer for " + featureType.Code + ".");
                        }
                        if (!modIO.InvariantParse_int(strArray[2], ref featureType.Footprint.Y))
                        {
                            result3.WarningAdd("Feature footprint-y was not an integer for " + featureType.Code + ".");
                        }
                        featureType.BaseAttachment = new clsUnitType.clsAttachment();
                        baseAttachment = featureType.BaseAttachment;
                        name = strArray[6].ToLower();
                        baseAttachment.CreateAttachment().Models.Add(this.GetModelForPIE(list2, name, result3));
                    }
                }
                finally
                {
                    if (enumerator11 is IDisposable)
                    {
                        (enumerator11 as IDisposable).Dispose();
                    }
                }
                try
                {
                    enumerator12 = newItem.ResultData.GetEnumerator();
                    while (enumerator12.MoveNext())
                    {
                        modMath.sXY_int _int;
                        strArray = (string[]) enumerator12.Current;
                        string str25 = strArray[0];
                        string str26 = strArray[1];
                        string[] strArray4 = strArray[0x15].ToLower().Split(new char[] { '@' });
                        string str24 = strArray[0x16].ToLower();
                        if (!modIO.InvariantParse_int(strArray[5], ref _int.X))
                        {
                            result3.WarningAdd("Structure footprint-x was not an integer for " + str25 + ".");
                        }
                        if (!modIO.InvariantParse_int(strArray[6], ref _int.Y))
                        {
                            result3.WarningAdd("Structure footprint-y was not an integer for " + str25 + ".");
                        }
                        if ((str26 != "WALL") | (strArray4.GetLength(0) != 4))
                        {
                            clsStructureType structureType = new clsStructureType();
                            structureType.UnitType_ObjectDataLink.Connect(this.UnitTypes);
                            structureType.StructureType_ObjectDataLink.Connect(this.StructureTypes);
                            structureType.Code = str25;
                            this.SetStructureName(file8.ResultData, structureType, result3);
                            structureType.Footprint = _int;
                            string str28 = str26;
                            if (str28 == "DEMOLISH")
                            {
                                structureType.StructureType = clsStructureType.enumStructureType.Demolish;
                            }
                            else if (str28 == "WALL")
                            {
                                structureType.StructureType = clsStructureType.enumStructureType.Wall;
                            }
                            else if (str28 == "CORNER WALL")
                            {
                                structureType.StructureType = clsStructureType.enumStructureType.CornerWall;
                            }
                            else if (str28 == "FACTORY")
                            {
                                structureType.StructureType = clsStructureType.enumStructureType.Factory;
                            }
                            else if (str28 == "CYBORG FACTORY")
                            {
                                structureType.StructureType = clsStructureType.enumStructureType.CyborgFactory;
                            }
                            else if (str28 == "VTOL FACTORY")
                            {
                                structureType.StructureType = clsStructureType.enumStructureType.VTOLFactory;
                            }
                            else if (str28 == "COMMAND")
                            {
                                structureType.StructureType = clsStructureType.enumStructureType.Command;
                            }
                            else if (str28 == "HQ")
                            {
                                structureType.StructureType = clsStructureType.enumStructureType.HQ;
                            }
                            else if (str28 == "DEFENSE")
                            {
                                structureType.StructureType = clsStructureType.enumStructureType.Defense;
                            }
                            else if (str28 == "POWER GENERATOR")
                            {
                                structureType.StructureType = clsStructureType.enumStructureType.PowerGenerator;
                            }
                            else if (str28 == "POWER MODULE")
                            {
                                structureType.StructureType = clsStructureType.enumStructureType.PowerModule;
                            }
                            else if (str28 == "RESEARCH")
                            {
                                structureType.StructureType = clsStructureType.enumStructureType.Research;
                            }
                            else if (str28 == "RESEARCH MODULE")
                            {
                                structureType.StructureType = clsStructureType.enumStructureType.ResearchModule;
                            }
                            else if (str28 == "FACTORY MODULE")
                            {
                                structureType.StructureType = clsStructureType.enumStructureType.FactoryModule;
                            }
                            else if (str28 == "DOOR")
                            {
                                structureType.StructureType = clsStructureType.enumStructureType.DOOR;
                            }
                            else if (str28 == "REPAIR FACILITY")
                            {
                                structureType.StructureType = clsStructureType.enumStructureType.RepairFacility;
                            }
                            else if (str28 == "SAT UPLINK")
                            {
                                structureType.StructureType = clsStructureType.enumStructureType.DOOR;
                            }
                            else if (str28 == "REARM PAD")
                            {
                                structureType.StructureType = clsStructureType.enumStructureType.RearmPad;
                            }
                            else if (str28 == "MISSILE SILO")
                            {
                                structureType.StructureType = clsStructureType.enumStructureType.MissileSilo;
                            }
                            else if (str28 == "RESOURCE EXTRACTOR")
                            {
                                structureType.StructureType = clsStructureType.enumStructureType.ResourceExtractor;
                            }
                            else
                            {
                                structureType.StructureType = clsStructureType.enumStructureType.Unknown;
                            }
                            baseAttachment = structureType.BaseAttachment;
                            if (strArray4.GetLength(0) > 0)
                            {
                                baseAttachment.Models.Add(this.GetModelForPIE(list2, strArray4[0], result3));
                            }
                            structureType.StructureBasePlate = this.GetModelForPIE(list2, str24, result3);
                            if ((baseAttachment.Models.Count == 1) && (baseAttachment.Models[0].ConnectorCount >= 1))
                            {
                                modMath.sXYZ_sng _sng = baseAttachment.Models[0].Connectors[0];
                                modLists.SimpleList<string[]> rowsWithValue = this.GetRowsWithValue(file13.ResultData, structureType.Code);
                                if (rowsWithValue.Count > 0)
                                {
                                    weapon = this.FindWeaponCode(rowsWithValue[0][1]);
                                }
                                else
                                {
                                    weapon = null;
                                }
                                secm = this.FindECMCode(strArray[0x12]);
                                sensor = this.FindSensorCode(strArray[0x13]);
                                if ((weapon != null) && (weapon.Code != "ZNULLWEAPON"))
                                {
                                    baseAttachment.CopyAttachment(weapon.Attachment).Pos_Offset = _sng;
                                }
                                if ((secm != null) && (secm.Code != "ZNULLECM"))
                                {
                                    baseAttachment.CopyAttachment(secm.Attachment).Pos_Offset = _sng;
                                }
                                if ((sensor != null) && (sensor.Code != "ZNULLSENSOR"))
                                {
                                    baseAttachment.CopyAttachment(sensor.Attachment).Pos_Offset = _sng;
                                }
                            }
                            continue;
                        }
                        clsWallType wallType = new clsWallType();
                        wallType.WallType_ObjectDataLink.Connect(this.WallTypes);
                        wallType.Code = str25;
                        this.SetWallName(file8.ResultData, wallType, result3);
                        clsModel model = this.GetModelForPIE(list2, str24, result3);
                        int index = 0;
                        do
                        {
                            clsStructureType type4 = new clsStructureType();
                            type4.UnitType_ObjectDataLink.Connect(this.UnitTypes);
                            type4.StructureType_ObjectDataLink.Connect(this.StructureTypes);
                            type4.WallLink.Connect(wallType.Segments);
                            type4.Code = str25;
                            name = wallType.Name;
                            switch (index)
                            {
                                case 0:
                                    name = name + " - ";
                                    break;

                                case 1:
                                    name = name + " + ";
                                    break;

                                case 2:
                                    name = name + " T ";
                                    break;

                                case 3:
                                    name = name + " L ";
                                    break;
                            }
                            type4.Name = name;
                            type4.Footprint = _int;
                            type4.StructureType = clsStructureType.enumStructureType.Wall;
                            baseAttachment = type4.BaseAttachment;
                            name = strArray4[index];
                            baseAttachment.Models.Add(this.GetModelForPIE(list2, name, result3));
                            type4.StructureBasePlate = model;
                            index++;
                        }
                        while (index <= 3);
                    }
                }
                finally
                {
                    if (enumerator12 is IDisposable)
                    {
                        (enumerator12 as IDisposable).Dispose();
                    }
                }
                int num2 = 0;
                try
                {
                    enumerator13 = file14.ResultData.GetEnumerator();
                    while (enumerator13.MoveNext())
                    {
                        strArray = (string[]) enumerator13.Current;
                        clsDroidTemplate template = new clsDroidTemplate();
                        template.UnitType_ObjectDataLink.Connect(this.UnitTypes);
                        template.DroidTemplate_ObjectDataLink.Connect(this.DroidTemplates);
                        template.Code = strArray[0];
                        this.SetTemplateName(file8.ResultData, template, result3);
                        string str29 = strArray[9];
                        if (str29 == "ZNULLDROID")
                        {
                            template.TemplateDroidType = modProgram.TemplateDroidType_Null;
                        }
                        else if (str29 == "DROID")
                        {
                            template.TemplateDroidType = modProgram.TemplateDroidType_Droid;
                        }
                        else if (str29 == "CYBORG")
                        {
                            template.TemplateDroidType = modProgram.TemplateDroidType_Cyborg;
                        }
                        else if (str29 == "CYBORG_CONSTRUCT")
                        {
                            template.TemplateDroidType = modProgram.TemplateDroidType_CyborgConstruct;
                        }
                        else if (str29 == "CYBORG_REPAIR")
                        {
                            template.TemplateDroidType = modProgram.TemplateDroidType_CyborgRepair;
                        }
                        else if (str29 == "CYBORG_SUPER")
                        {
                            template.TemplateDroidType = modProgram.TemplateDroidType_CyborgSuper;
                        }
                        else if (str29 == "TRANSPORTER")
                        {
                            template.TemplateDroidType = modProgram.TemplateDroidType_Transporter;
                        }
                        else if (str29 == "PERSON")
                        {
                            template.TemplateDroidType = modProgram.TemplateDroidType_Person;
                        }
                        else
                        {
                            template.TemplateDroidType = null;
                            result3.WarningAdd("Template " + template.GetDisplayTextCode() + " had an unrecognised type.");
                        }
                        clsDroidDesign.sLoadPartsArgs args = new clsDroidDesign.sLoadPartsArgs {
                            Body = this.FindBodyCode(strArray[2]),
                            Brain = this.FindBrainCode(strArray[3]),
                            Construct = this.FindConstructorCode(strArray[4]),
                            ECM = this.FindECMCode(strArray[5]),
                            Propulsion = this.FindPropulsionCode(strArray[7]),
                            Repair = this.FindRepairCode(strArray[8]),
                            Sensor = this.FindSensorCode(strArray[10])
                        };
                        modLists.SimpleList<string[]> list4 = this.GetRowsWithValue(file.ResultData, template.Code);
                        if (list4.Count > 0)
                        {
                            name = list4[0][1];
                            if (name != "NULL")
                            {
                                args.Weapon1 = this.FindWeaponCode(name);
                            }
                            name = list4[0][2];
                            if (name != "NULL")
                            {
                                args.Weapon2 = this.FindWeaponCode(name);
                            }
                            name = list4[0][3];
                            if (name != "NULL")
                            {
                                args.Weapon3 = this.FindWeaponCode(name);
                            }
                        }
                        if (!template.LoadParts(args))
                        {
                            if (num2 < 0x10)
                            {
                                result3.WarningAdd("Template " + template.GetDisplayTextCode() + " had multiple conflicting turrets.");
                            }
                            num2++;
                        }
                    }
                }
                finally
                {
                    if (enumerator13 is IDisposable)
                    {
                        (enumerator13 as IDisposable).Dispose();
                    }
                }
                if (num2 > 0)
                {
                    result3.WarningAdd(Conversions.ToString(num2) + " templates had multiple conflicting turrets.");
                }
            }
            return result3;
        }
Example #8
0
 private void btnCompileCampaign_Click(object sender, EventArgs e)
 {
     clsResult result = new clsResult("Compile campaign");
     this.SaveToMap();
     int num = this.ValidateMap_WaterTris();
     if (num > 0)
     {
         result.WarningAdd(Conversions.ToString(num) + " water tiles have an incorrect triangle direction. There might be in-game graphical glitches on those tiles.");
     }
     result.Add(this.ValidateMap());
     result.Add(this.ValidateMap_UnitPositions());
     string text = this.txtName.Text;
     if (text.Length < 1)
     {
         result.ProblemAdd("Enter a name for the campaign files.");
     }
     int selectedIndex = this.cboCampType.SelectedIndex;
     if ((selectedIndex < 0) | (selectedIndex > 2))
     {
         result.ProblemAdd("Select a campaign type.");
     }
     if (result.HasProblems)
     {
         modProgram.ShowWarnings(result);
     }
     else
     {
         FolderBrowserDialog dialog = new FolderBrowserDialog();
         if (dialog.ShowDialog(this) == DialogResult.OK)
         {
             clsMap.sWrite_WZ_Args args = new clsMap.sWrite_WZ_Args {
                 MapName = text,
                 Path = dialog.SelectedPath,
                 Overwrite = false
             };
             this.SetScrollLimits(ref args.ScrollMin, ref args.ScrollMax);
             args.Campaign = new clsMap.sWrite_WZ_Args.clsCampaign();
             args.Campaign.GAMType = (uint) selectedIndex;
             args.CompileType = clsMap.sWrite_WZ_Args.enumCompileType.Campaign;
             result.Add(this.Map.Write_WZ(args));
             modProgram.ShowWarnings(result);
             if (!result.HasWarnings)
             {
                 this.Close();
             }
         }
     }
 }
Example #9
0
 public clsResult LoadCommaFile(string Path)
 {
     string str;
     StreamReader reader;
     clsResult result2 = new clsResult("Loading comma separated file \"" + this.SubDirectory + "\"");
     try
     {
         reader = new StreamReader(Path + this.SubDirectory, modProgram.UTF8Encoding);
         goto Label_00B2;
     }
     catch (Exception exception1)
     {
         ProjectData.SetProjectError(exception1);
         Exception exception = exception1;
         result2.ProblemAdd(exception.Message);
         clsResult result = result2;
         ProjectData.ClearProjectError();
         return result;
     }
     Label_0056:
     str = reader.ReadLine().Trim();
     if (str.Length > 0)
     {
         string[] newItem = str.Split(new char[] { ',' });
         int upperBound = newItem.GetUpperBound(0);
         for (int i = 0; i <= upperBound; i++)
         {
             newItem[i] = newItem[i].Trim();
         }
         this.ResultData.Add(newItem);
     }
     Label_00B2:
     if (!reader.EndOfStream)
     {
         goto Label_0056;
     }
     reader.Close();
     return result2;
 }
Example #10
0
 public clsResult LoadNamesFile(string Path)
 {
     char ch;
     FileStream stream;
     bool flag2;
     bool flag3;
     clsResult result;
     char ch2;
     BinaryReader reader;
     clsResult result2 = new clsResult("Loading names file \"" + this.SubDirectory + "\"");
     try
     {
         stream = new FileStream(Path + this.SubDirectory, FileMode.Open);
     }
     catch (Exception exception1)
     {
         ProjectData.SetProjectError(exception1);
         Exception exception = exception1;
         result2.ProblemAdd(exception.Message);
         result = result2;
         ProjectData.ClearProjectError();
         return result;
     }
     try
     {
         reader = new BinaryReader(stream, modProgram.UTF8Encoding);
     }
     catch (Exception exception4)
     {
         ProjectData.SetProjectError(exception4);
         Exception exception2 = exception4;
         stream.Close();
         result2.ProblemAdd(exception2.Message);
         result = result2;
         ProjectData.ClearProjectError();
         return result;
     }
     string str = "";
     bool flag = false;
     Label_0097:
     ch2 = ch;
     bool flag4 = flag;
     try
     {
         ch = reader.ReadChar();
         flag = true;
     }
     catch (Exception exception5)
     {
         ProjectData.SetProjectError(exception5);
         Exception exception3 = exception5;
         flag = false;
         ProjectData.ClearProjectError();
     }
     if (flag)
     {
         char ch3 = ch;
         switch (ch3)
         {
             case '\r':
             case '\n':
                 flag3 = false;
                 if (flag4)
                 {
                     str = str + Conversions.ToString(ch2);
                 }
                 flag = false;
                 if (str.Length > 0)
                 {
                     int index = str.IndexOf('\t');
                     int num2 = str.IndexOf(' ');
                     int length = index;
                     if ((num2 >= 0) & ((num2 < length) | (length < 0)))
                     {
                         length = num2;
                     }
                     if (length >= 0)
                     {
                         int num4 = str.IndexOf('"', length + 1, str.Length - (length + 1));
                         if (num4 >= 0)
                         {
                             int num5 = str.IndexOf('"', num4 + 1, str.Length - (num4 + 1));
                             if (num5 >= 0)
                             {
                                 string[] newItem = new string[] { str.Substring(0, length), str.Substring(num4 + 1, num5 - (num4 + 1)) };
                                 this.ResultData.Add(newItem);
                             }
                         }
                     }
                     str = "";
                 }
                 goto Label_0097;
         }
         if (ch3 == '*')
         {
             if (!(flag4 & (ch2 == '/')))
             {
                 goto Label_02DF;
             }
             flag2 = true;
             flag = false;
         }
         else
         {
             if ((ch3 != '/') || !flag4)
             {
                 goto Label_02DF;
             }
             if (ch2 == '/')
             {
                 flag3 = true;
                 flag = false;
             }
             else
             {
                 if (ch2 != '*')
                 {
                     goto Label_02DF;
                 }
                 flag2 = false;
                 flag = false;
             }
         }
         goto Label_0097;
     }
     if (flag4)
     {
         str = str + Conversions.ToString(ch2);
     }
     if (str.Length > 0)
     {
         int num8 = str.IndexOf('\t');
         int num7 = str.IndexOf(' ');
         int num6 = num8;
         if ((num7 >= 0) & ((num7 < num6) | (num6 < 0)))
         {
             num6 = num7;
         }
         if (num6 >= 0)
         {
             int num9 = str.IndexOf('"', num6 + 1, str.Length - (num6 + 1));
             if (num9 >= 0)
             {
                 int num10 = str.IndexOf('"', num9 + 1, str.Length - (num9 + 1));
                 if (num10 >= 0)
                 {
                     string[] strArray2 = new string[] { str.Substring(0, num6), str.Substring(num9 + 1, num10 - (num9 + 1)) };
                     this.ResultData.Add(strArray2);
                 }
             }
         }
         str = "";
     }
     reader.Close();
     return result2;
     Label_02DF:
     if (flag4 && !(flag2 | flag3))
     {
         str = str + Conversions.ToString(ch2);
     }
     goto Label_0097;
 }
Example #11
0
        private clsResult FinishTextures()
        {
            int num;
            clsBrush.sPosNum num2;
            clsResult result2 = new clsResult("");
            if (!this.cbxMasterTexture.Checked)
            {
                switch (this.cboTileset.SelectedIndex)
                {
                    case 0:
                        this.Generator.Map.Tileset = modProgram.Tileset_Arizona;
                        this.Generator.GenerateTileset = modGenerator.Generator_TilesetArizona;
                        goto Label_023D;

                    case 1:
                        this.Generator.Map.Tileset = modProgram.Tileset_Urban;
                        this.Generator.GenerateTileset = modGenerator.Generator_TilesetUrban;
                        goto Label_023D;

                    case 2:
                        this.Generator.Map.Tileset = modProgram.Tileset_Rockies;
                        this.Generator.GenerateTileset = modGenerator.Generator_TilesetRockies;
                        goto Label_023D;
                }
                result2.ProblemAdd("Error: bad tileset selection.");
                this.btnGenerateLayout.Enabled = true;
                return result2;
            }
            switch (this.cboTileset.SelectedIndex)
            {
                case 0:
                    this.Generator.GenerateTileset = modGenerator.Generator_TilesetArizona;
                    modGenerator.TerrainStyle_Arizona.Watermap = this.Generator.GetWaterMap();
                    modGenerator.TerrainStyle_Arizona.LevelCount = this.Generator.LevelCount;
                    this.Generator.Map.GenerateMasterTerrain(ref modGenerator.TerrainStyle_Arizona);
                    modGenerator.TerrainStyle_Arizona.Watermap = null;
                    break;

                case 1:
                    this.Generator.GenerateTileset = modGenerator.Generator_TilesetUrban;
                    modGenerator.TerrainStyle_Urban.Watermap = this.Generator.GetWaterMap();
                    modGenerator.TerrainStyle_Urban.LevelCount = this.Generator.LevelCount;
                    this.Generator.Map.GenerateMasterTerrain(ref modGenerator.TerrainStyle_Urban);
                    modGenerator.TerrainStyle_Urban.Watermap = null;
                    break;

                case 2:
                    this.Generator.GenerateTileset = modGenerator.Generator_TilesetRockies;
                    modGenerator.TerrainStyle_Rockies.Watermap = this.Generator.GetWaterMap();
                    modGenerator.TerrainStyle_Rockies.LevelCount = this.Generator.LevelCount;
                    this.Generator.Map.GenerateMasterTerrain(ref modGenerator.TerrainStyle_Rockies);
                    modGenerator.TerrainStyle_Rockies.Watermap = null;
                    break;

                default:
                    result2.ProblemAdd("Error: bad tileset selection.");
                    this.btnGenerateLayout.Enabled = true;
                    return result2;
            }
            this.Generator.Map.TileType_Reset();
            this.Generator.Map.SetPainterToDefaults();
            goto Label_054A;
            Label_023D:
            this.Generator.Map.TileType_Reset();
            this.Generator.Map.SetPainterToDefaults();
            double num3 = Math.Atan((255.0 * this.Generator.Map.HeightMultiplier) / ((2.0 * (this.Generator.LevelCount - 1.0)) * 128.0)) - 0.017453292519943295;
            clsBrush brush = new clsBrush(Math.Max(this.Generator.Map.Terrain.TileSize.X, this.Generator.Map.Terrain.TileSize.Y) * 1.1, clsBrush.enumShape.Square);
            clsMap.clsApplyCliff tool = new clsMap.clsApplyCliff {
                Map = this.Generator.Map,
                Angle = num3,
                SetTris = true
            };
            num2.Normal = new modMath.sXY_int((int) Math.Round(((double) (((double) this.Generator.Map.Terrain.TileSize.X) / 2.0))), (int) Math.Round(((double) (((double) this.Generator.Map.Terrain.TileSize.Y) / 2.0))));
            num2.Alignment = num2.Normal;
            brush.PerformActionMapTiles(tool, num2);
            clsBooleanMap exterior = new clsBooleanMap();
            clsBooleanMap map = new clsBooleanMap();
            exterior = this.Generator.GetWaterMap();
            clsGeneratorTileset generateTileset = this.Generator.GenerateTileset;
            bool[] flagArray2 = new bool[(generateTileset.OldTextureLayers.LayerCount - 1) + 1];
            bool[] flagArray = new bool[(generateTileset.OldTextureLayers.LayerCount - 1) + 1];
            int num6 = generateTileset.OldTextureLayers.LayerCount - 1;
            for (num = 0; num <= num6; num++)
            {
                modProgram.sLayerList.clsLayer layer = generateTileset.OldTextureLayers.Layers[num];
                layer.Terrainmap = this.Generator.Map.GenerateTerrainMap(layer.Scale, layer.Density);
                if (layer.SlopeMax < 0f)
                {
                    layer.SlopeMax = (float) (num3 - 0.017453292519943295);
                    if (layer.HeightMax < 0f)
                    {
                        layer.HeightMax = 255f;
                        map.Within(layer.Terrainmap, exterior);
                        layer.Terrainmap.ValueData = map.ValueData;
                        map.ValueData = new clsBooleanMap.clsValueData();
                        flagArray[num] = true;
                    }
                    flagArray2[num] = true;
                }
                layer = null;
            }
            this.Generator.Map.MapTexturer(ref generateTileset.OldTextureLayers);
            int num7 = generateTileset.OldTextureLayers.LayerCount - 1;
            for (num = 0; num <= num7; num++)
            {
                modProgram.sLayerList.clsLayer layer2 = generateTileset.OldTextureLayers.Layers[num];
                layer2.Terrainmap = null;
                if (flagArray2[num])
                {
                    layer2.SlopeMax = -1f;
                }
                if (flagArray[num])
                {
                    layer2.HeightMax = -1f;
                }
                layer2 = null;
            }
            generateTileset = null;
            Label_054A:
            this.Generator.Map.LevelWater();
            this.Generator.Map.WaterTriCorrection();
            this.Generator.Map.SectorGraphicsChanges.SetAllChanged();
            this.Generator.Map.SectorUnitHeightsChanges.SetAllChanged();
            this.Generator.Map.Update();
            this.Generator.Map.UndoStepCreate("Generated Textures");
            if (this.Generator.Map == this._Owner.MainMap)
            {
                modMain.frmMainInstance.PainterTerrains_Refresh(-1, -1);
                modMain.frmMainInstance.MainMapTilesetChanged();
            }
            return result2;
        }
Example #12
0
 public static ZipEntry ZipMakeEntry(ZipOutputStream ZipOutputStream, string Path, clsResult Result)
 {
     ZipEntry entry;
     try
     {
         ZipEntry entry2 = new ZipEntry(Path) {
             DateTime = DateAndTime.Now
         };
         ZipOutputStream.PutNextEntry(entry2);
         entry = entry2;
     }
     catch (Exception exception1)
     {
         ProjectData.SetProjectError(exception1);
         Exception exception = exception1;
         Result.ProblemAdd("Zip entry \"" + Path + "\" failed: " + exception.Message);
         entry = null;
         ProjectData.ClearProjectError();
     }
     return entry;
 }
Example #13
0
 public static clsResult WriteMemoryToZipEntryAndFlush(MemoryStream Memory, ZipOutputStream Stream)
 {
     clsResult result = new clsResult("Writing to zip stream");
     try
     {
         Memory.WriteTo(Stream);
         Memory.Flush();
         Stream.Flush();
         Stream.CloseEntry();
     }
     catch (Exception exception1)
     {
         ProjectData.SetProjectError(exception1);
         Exception exception = exception1;
         result.ProblemAdd(exception.Message);
         clsResult result2 = result;
         ProjectData.ClearProjectError();
         return result2;
     }
     return result;
 }
Example #14
0
 private clsResult ValidateMap()
 {
     clsStructureType type;
     IEnumerator enumerator;
     IEnumerator enumerator2;
     clsResult result = new clsResult("Validate map");
     if (this.Map.Terrain.TileSize.X > 250)
     {
         result.WarningAdd("Map width is too large. The maximum is " + Conversions.ToString(250) + ".");
     }
     if (this.Map.Terrain.TileSize.Y > 250)
     {
         result.WarningAdd("Map height is too large. The maximum is " + Conversions.ToString(250) + ".");
     }
     if (this.Map.Tileset == null)
     {
         result.ProblemAdd("No tileset selected.");
     }
     int[,] numArray = new int[10, (modProgram.ObjectData.StructureTypes.Count - 1) + 1];
     int[] numArray2 = new int[(modProgram.ObjectData.StructureTypes.Count - 1) + 1];
     try
     {
         enumerator = this.Map.Units.GetEnumerator();
         while (enumerator.MoveNext())
         {
             clsMap.clsUnit current = (clsMap.clsUnit) enumerator.Current;
             if (current.Type.Type == clsUnitType.enumType.PlayerStructure)
             {
                 int arrayPosition;
                 type = (clsStructureType) current.Type;
                 if (current.UnitGroup == this.Map.ScavengerUnitGroup)
                 {
                     int[] numArray3 = numArray2;
                     arrayPosition = type.StructureType_ObjectDataLink.ArrayPosition;
                     numArray3[arrayPosition]++;
                 }
                 else
                 {
                     int[,] numArray4 = numArray;
                     arrayPosition = current.UnitGroup.WZ_StartPos;
                     int num4 = type.StructureType_ObjectDataLink.ArrayPosition;
                     numArray4[arrayPosition, num4]++;
                 }
             }
         }
     }
     finally
     {
         if (enumerator is IDisposable)
         {
             (enumerator as IDisposable).Dispose();
         }
     }
     try
     {
         enumerator2 = modProgram.ObjectData.StructureTypes.GetEnumerator();
         while (enumerator2.MoveNext())
         {
             type = (clsStructureType) enumerator2.Current;
             int index = type.StructureType_ObjectDataLink.ArrayPosition;
             int num = 0;
             do
             {
                 if (numArray[num, index] > 0xff)
                 {
                     result.ProblemAdd("Player " + Conversions.ToString(num) + " has too many (" + Conversions.ToString(numArray[num, index]) + ") of structure \"" + type.Code + "\". The limit is 255 of any one structure type.");
                 }
                 num++;
             }
             while (num <= 9);
             if (numArray2[index] > 0xff)
             {
                 result.ProblemAdd("Scavengers have too many (" + Conversions.ToString(numArray2[index]) + ") of structure \"" + type.Code + "\". The limit is 255 of any one structure type.");
             }
         }
     }
     finally
     {
         if (enumerator2 is IDisposable)
         {
             (enumerator2 as IDisposable).Dispose();
         }
     }
     return result;
 }
Example #15
0
 public clsResult LoadDirectory(string Path)
 {
     clsResult result3 = new clsResult("Loading tileset from \"" + Path + "\"");
     System.Drawing.Bitmap resultBitmap = null;
     modProgram.sSplitPath path = new modProgram.sSplitPath(Path);
     string slashPath = modProgram.EndWithPathSeperator(Path);
     if (path.FileTitle != "")
     {
         this.Name = path.FileTitle;
     }
     else if (path.PartCount >= 2)
     {
         this.Name = path.Parts[path.PartCount - 2];
     }
     modProgram.sResult result2 = this.Default_TileTypes_Load(slashPath + this.Name + ".ttp");
     if (!result2.Success)
     {
         result3.ProblemAdd("Loading tile types: " + result2.Problem);
         return result3;
     }
     float[] pixels = new float[4];
     int num7 = this.TileCount - 1;
     for (int i = 0; i <= num7; i++)
     {
         modBitmap.sBitmapGLTexture texture;
         string strTile = "tile-" + modProgram.MinDigits(i, 2) + ".png";
         string str = slashPath + this.Name + "-128" + Conversions.ToString(modProgram.PlatformPathSeparator) + strTile;
         if (!modBitmap.LoadBitmap(str, ref resultBitmap).Success)
         {
             return result3;
         }
         if ((resultBitmap.Width != 0x80) | (resultBitmap.Height != 0x80))
         {
             result3.WarningAdd("Tile graphic " + str + " from tileset " + this.Name + " is not 128x128.");
             return result3;
         }
         texture.Texture = resultBitmap;
         texture.MipMapLevel = 0;
         texture.MagFilter = TextureMagFilter.Nearest;
         texture.MinFilter = TextureMinFilter.Nearest;
         texture.TextureNum = 0;
         texture.Perform();
         this.Tiles[i].TextureView_GL_Texture_Num = texture.TextureNum;
         texture.MagFilter = TextureMagFilter.Nearest;
         if (modSettings.Settings.Mipmaps)
         {
             texture.MinFilter = TextureMinFilter.LinearMipmapLinear;
         }
         else
         {
             texture.MinFilter = TextureMinFilter.Nearest;
         }
         texture.TextureNum = 0;
         texture.Perform();
         this.Tiles[i].MapView_GL_Texture_Num = texture.TextureNum;
         if (modSettings.Settings.Mipmaps)
         {
             if (modSettings.Settings.MipmapsHardware)
             {
                 GL.Enable(EnableCap.Texture2D);
                 GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
                 GL.Disable(EnableCap.Texture2D);
             }
             else
             {
                 clsResult resultToAdd = this.GenerateMipMaps(slashPath, strTile, texture, i);
                 result3.Add(resultToAdd);
                 if (resultToAdd.HasProblems)
                 {
                     return result3;
                 }
             }
             GL.GetTexImage<float>(TextureTarget.Texture2D, 7, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, PixelType.Float, pixels);
             this.Tiles[i].AverageColour.Red = pixels[0];
             this.Tiles[i].AverageColour.Green = pixels[1];
             this.Tiles[i].AverageColour.Blue = pixels[2];
         }
         else
         {
             int num3 = 0;
             int num2 = 0;
             int num = 0;
             int num8 = resultBitmap.Height - 1;
             for (int j = 0; j <= num8; j++)
             {
                 int num9 = resultBitmap.Width - 1;
                 for (int k = 0; k <= num9; k++)
                 {
                     Color pixel = resultBitmap.GetPixel(k, j);
                     num3 += pixel.R;
                     num2 += pixel.G;
                     num += pixel.B;
                 }
             }
             this.Tiles[i].AverageColour.Red = (float) (((double) num3) / 4177920.0);
             this.Tiles[i].AverageColour.Green = (float) (((double) num2) / 4177920.0);
             this.Tiles[i].AverageColour.Blue = (float) (((double) num) / 4177920.0);
         }
     }
     return result3;
 }
Example #16
0
 private clsResult ValidateMap_Multiplayer(int PlayerCount, bool IsXPlayerFormat)
 {
     IEnumerator enumerator;
     clsResult result = new clsResult("Validate for multiplayer");
     if ((PlayerCount < 2) | (PlayerCount > 10))
     {
         result.ProblemAdd("Unable to evaluate for multiplayer due to bad number of players.");
         return result;
     }
     int[] numArray2 = new int[10];
     int[] numArray = new int[10];
     int[] numArray3 = new int[10];
     int num = 0;
     int num3 = 0;
     int num2 = Math.Max(PlayerCount, 7);
     try
     {
         enumerator = this.Map.Units.GetEnumerator();
         while (enumerator.MoveNext())
         {
             clsMap.clsUnit current = (clsMap.clsUnit) enumerator.Current;
             if (current.UnitGroup != this.Map.ScavengerUnitGroup)
             {
                 int[] numArray4;
                 int num5;
                 if (current.Type.Type == clsUnitType.enumType.PlayerDroid)
                 {
                     clsDroidDesign design = (clsDroidDesign) current.Type;
                     if (((((design.Body != null) & (design.Propulsion != null)) & (design.Turret1 != null)) & (design.TurretCount == 1)) && (design.Turret1.TurretType == clsTurret.enumTurretType.Construct))
                     {
                         numArray4 = numArray3;
                         num5 = current.UnitGroup.WZ_StartPos;
                         numArray4[num5]++;
                         if (design.IsTemplate)
                         {
                             numArray4 = numArray;
                             num5 = current.UnitGroup.WZ_StartPos;
                             numArray4[num5]++;
                         }
                     }
                 }
                 else if (current.Type.Type == clsUnitType.enumType.PlayerStructure)
                 {
                     clsStructureType type = (clsStructureType) current.Type;
                     if (type.Code == "A0CommandCentre")
                     {
                         numArray4 = numArray2;
                         num5 = current.UnitGroup.WZ_StartPos;
                         numArray4[num5]++;
                     }
                 }
             }
             if (current.Type.Type != clsUnitType.enumType.Feature)
             {
                 if ((current.UnitGroup.WZ_StartPos == num2) | (current.UnitGroup == this.Map.ScavengerUnitGroup))
                 {
                     num++;
                 }
                 else if ((current.UnitGroup.WZ_StartPos >= PlayerCount) && (num3 < 0x20))
                 {
                     num3++;
                     clsResultProblemGoto<clsResultItemPosGoto> item = modResults.CreateResultProblemGotoForObject(current);
                     item.Text = "An unused player (" + Conversions.ToString(current.UnitGroup.WZ_StartPos) + ") has a unit at " + current.GetPosText() + ".";
                     result.ItemAdd(item);
                 }
             }
         }
     }
     finally
     {
         if (enumerator is IDisposable)
         {
             (enumerator as IDisposable).Dispose();
         }
     }
     if (!((num2 <= 7) | IsXPlayerFormat) && (num > 0))
     {
         result.ProblemAdd("Scavengers are not supported on a map with this number of players without enabling X player support.");
     }
     int num6 = PlayerCount - 1;
     for (int i = 0; i <= num6; i++)
     {
         if (numArray2[i] == 0)
         {
             result.ProblemAdd("There is no Command Centre for player " + Conversions.ToString(i) + ".");
         }
         if (numArray3[i] == 0)
         {
             result.ProblemAdd("There are no constructor units for player " + Conversions.ToString(i) + ".");
         }
         else if (numArray[i] == 0)
         {
             result.WarningAdd("All constructor units for player " + Conversions.ToString(i) + " will only exist in master.");
         }
     }
     return result;
 }
Example #17
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;
 }
Example #18
0
 private void btnCompile_Click(object sender, EventArgs e)
 {
     int num2;
     clsResult result = new clsResult("Compile multiplayer");
     this.SaveToMap();
     string text = this.cboLicense.Text;
     if (!modIO.InvariantParse_int(this.txtMultiPlayers.Text, ref num2))
     {
         num2 = 0;
     }
     bool isXPlayerFormat = this.cbxLevFormat.Checked;
     if ((num2 < 2) | (num2 > 10))
     {
         result.ProblemAdd("The number of players must be from 2 to " + Conversions.ToString(10));
     }
     if (!isXPlayerFormat && (((num2 != 2) & (num2 != 4)) & (num2 != 8)))
     {
         result.ProblemAdd("You must enable support for this number of players.");
     }
     int num = this.ValidateMap_WaterTris();
     if (num > 0)
     {
         result.WarningAdd(Conversions.ToString(num) + " water tiles have an incorrect triangle direction. There might be in-game graphical glitches on those tiles.");
     }
     result.Add(this.ValidateMap());
     result.Add(this.ValidateMap_UnitPositions());
     result.Add(this.ValidateMap_Multiplayer(num2, isXPlayerFormat));
     string str2 = this.txtName.Text;
     int num3 = str2.Length - 1;
     num = 0;
     while (num <= num3)
     {
         char ch = str2[num];
         if (!((((ch >= 'a') & (ch <= 'z')) | ((ch >= 'A') & (ch <= 'Z'))) | ((num >= 1) & ((((ch >= '0') & (ch <= '9')) | (ch == '-')) | (ch == '_')))))
         {
             break;
         }
         num++;
     }
     if (num < str2.Length)
     {
         result.ProblemAdd("The map's name must contain only letters, numbers, underscores and hyphens, and must begin with a letter.");
     }
     if ((str2.Length < 1) | (str2.Length > 0x10))
     {
         result.ProblemAdd("Map name must be from 1 to 16 characters.");
     }
     if (text == "")
     {
         result.ProblemAdd("Enter a valid license.");
     }
     if (result.HasProblems)
     {
         modProgram.ShowWarnings(result);
     }
     else
     {
         SaveFileDialog dialog = new SaveFileDialog();
         if (this.Map.PathInfo != null)
         {
             dialog.InitialDirectory = this.Map.PathInfo.Path;
         }
         dialog.FileName = Conversions.ToString(num2) + "c-" + str2;
         dialog.Filter = "WZ Files (*.wz)|*.wz";
         if (dialog.ShowDialog(this) == DialogResult.OK)
         {
             clsMap.sWrite_WZ_Args args = new clsMap.sWrite_WZ_Args {
                 MapName = str2,
                 Path = dialog.FileName,
                 Overwrite = true
             };
             this.SetScrollLimits(ref args.ScrollMin, ref args.ScrollMax);
             args.Multiplayer = new clsMap.sWrite_WZ_Args.clsMultiplayer();
             args.Multiplayer.AuthorName = this.txtAuthor.Text;
             args.Multiplayer.PlayerCount = num2;
             args.Multiplayer.IsBetaPlayerFormat = isXPlayerFormat;
             args.Multiplayer.License = text;
             args.CompileType = clsMap.sWrite_WZ_Args.enumCompileType.Multiplayer;
             result.Add(this.Map.Write_WZ(args));
             modProgram.ShowWarnings(result);
             if (!result.HasWarnings)
             {
                 this.Close();
             }
         }
     }
 }
Example #19
0
 public static clsResult LoadTilesets(string TilesetsPath)
 {
     string[] directories;
     clsResult result3 = new clsResult("Loading tilesets");
     try
     {
         directories = Directory.GetDirectories(TilesetsPath);
     }
     catch (Exception exception1)
     {
         ProjectData.SetProjectError(exception1);
         Exception exception = exception1;
         result3.ProblemAdd(exception.Message);
         clsResult result = result3;
         ProjectData.ClearProjectError();
         return result;
     }
     if (directories != null)
     {
         clsTileset current;
         IEnumerator enumerator;
         foreach (string str in directories)
         {
             current = new clsTileset();
             clsResult resultToAdd = current.LoadDirectory(str);
             result3.Add(resultToAdd);
             if (!resultToAdd.HasProblems)
             {
                 Tilesets.Add(current);
             }
         }
         try
         {
             enumerator = Tilesets.GetEnumerator();
             while (enumerator.MoveNext())
             {
                 current = (clsTileset) enumerator.Current;
                 if (current.Name == "tertilesc1hw")
                 {
                     current.Name = "Arizona";
                     Tileset_Arizona = current;
                     current.IsOriginal = true;
                     current.BGColour = new sRGB_sng(0.8f, 0.5843138f, 0.2745098f);
                 }
                 else
                 {
                     if (current.Name == "tertilesc2hw")
                     {
                         current.Name = "Urban";
                         Tileset_Urban = current;
                         current.IsOriginal = true;
                         current.BGColour = new sRGB_sng(0.4627451f, 0.6470588f, 0.7960784f);
                         continue;
                     }
                     if (current.Name == "tertilesc3hw")
                     {
                         current.Name = "Rocky Mountains";
                         Tileset_Rockies = current;
                         current.IsOriginal = true;
                         current.BGColour = new sRGB_sng(0.7137255f, 0.8823529f, 0.9254902f);
                     }
                 }
             }
         }
         finally
         {
             if (enumerator is IDisposable)
             {
                 (enumerator as IDisposable).Dispose();
             }
         }
         if (Tileset_Arizona == null)
         {
             result3.WarningAdd("Arizona tileset is missing.");
         }
         if (Tileset_Urban == null)
         {
             result3.WarningAdd("Urban tileset is missing.");
         }
         if (Tileset_Rockies == null)
         {
             result3.WarningAdd("Rocky Mountains tileset is missing.");
         }
     }
     return result3;
 }