Пример #1
0
        public static App.sResult SaveBitmap(string Path, bool Overwrite, Bitmap BitmapToSave)
        {
            App.sResult ReturnResult = new App.sResult();
            ReturnResult.Problem = "";
            ReturnResult.Success = false;

            try
            {
                if ( File.Exists(Path) )
                {
                    if ( Overwrite )
                    {
                        File.Delete(Path);
                    }
                    else
                    {
                        ReturnResult.Problem = "File already exists.";
                        return ReturnResult;
                    }
                }
                BitmapToSave.Save(Path);
            }
            catch ( Exception ex )
            {
                ReturnResult.Problem = ex.Message;
                return ReturnResult;
            }

            ReturnResult.Success = true;
            return ReturnResult;
        }
Пример #2
0
        public App.sResult Default_TileTypes_Load(string Path)
        {
            App.sResult ReturnResult = new App.sResult();
            BinaryReader File = default(BinaryReader);

            try
            {
                File = new BinaryReader(new FileStream(Path, FileMode.Open));
            }
            catch ( Exception ex )
            {
                ReturnResult.Problem = ex.Message;
                return ReturnResult;
            }
            ReturnResult = Default_TileTypes_Read(File);
            File.Close();
            return ReturnResult;
        }
Пример #3
0
        public string GetDefaultScriptLabel(string Prefix)
        {
            int Number = 1;
            App.sResult Valid = new App.sResult();
            string Label = "";

            do
            {
                Label = Prefix + IOUtil.InvariantToString(Number);
                Valid = ScriptLabelIsValid(Label);
                if ( Valid.Success )
                {
                    return Label;
                }
                Number++;
                if ( Number >= 16384 )
                {
                    MessageBox.Show("Error: Unable to set default script label.");
                    return "";
                }
            } while ( true );
        }
Пример #4
0
        public static App.sResult LoadBitmap(string Path, ref Bitmap ResultBitmap)
        {
            App.sResult ReturnResult = new App.sResult();
            ReturnResult.Problem = "";
            ReturnResult.Success = false;

            Bitmap Bitmap = default(Bitmap);

            try
            {
                Bitmap = new Bitmap(Path);
            }
            catch ( Exception ex )
            {
                ReturnResult.Problem = ex.Message;
                ResultBitmap = null;
                return ReturnResult;
            }

            ResultBitmap = new Bitmap(Bitmap); //copying the bitmap is needed so it doesn't lock access to the file

            ReturnResult.Success = true;
            return ReturnResult;
        }
Пример #5
0
        public App.sResult Load_TTP(string Path)
        {
            App.sResult ReturnResult = new App.sResult();
            ReturnResult.Success = false;
            ReturnResult.Problem = "";
            BinaryReader File = default(BinaryReader);

            try
            {
                File = new BinaryReader(new FileStream(Path, FileMode.Open));
            }
            catch ( Exception ex )
            {
                ReturnResult.Problem = ex.Message;
                return ReturnResult;
            }
            ReturnResult = Read_TTP(File);
            File.Close();

            return ReturnResult;
        }
Пример #6
0
        public App.sResult Write_TTP(string Path, bool Overwrite)
        {
            App.sResult ReturnResult = new App.sResult();
            ReturnResult.Success = false;
            ReturnResult.Problem = "";

            if ( File.Exists(Path) )
            {
                if ( Overwrite )
                {
                    File.Delete(Path);
                }
                else
                {
                    ReturnResult.Problem = "File already exists.";
                    return ReturnResult;
                }
            }

            BinaryWriter File_TTP = default(BinaryWriter);

            try
            {
                File_TTP = new BinaryWriter(new FileStream(Path, FileMode.CreateNew), App.ASCIIEncoding);
            }
            catch ( Exception ex )
            {
                ReturnResult.Problem = ex.Message;
                return ReturnResult;
            }

            int A = 0;

            IOUtil.WriteText(File_TTP, false, "ttyp");

            File_TTP.Write(8U);
            if ( Tileset == null )
            {
                File_TTP.Write(0U);
            }
            else
            {
                File_TTP.Write(Convert.ToBoolean((uint)Tileset.TileCount));
                for ( A = 0; A <= Tileset.TileCount - 1; A++ )
                {
                    File_TTP.Write(Convert.ToBoolean(Tile_TypeNum[A]));
                }
            }
            File_TTP.Close();

            ReturnResult.Success = true;
            return ReturnResult;
        }
Пример #7
0
        public App.sResult Write_MinimapFile(string Path, bool Overwrite)
        {
            App.sResult ReturnResult = new App.sResult();
            int X = 0;
            int Y = 0;

            Bitmap MinimapBitmap = new Bitmap(Terrain.TileSize.X, Terrain.TileSize.Y);

            clsMinimapTexture Texture = new clsMinimapTexture(new sXY_int(Terrain.TileSize.X, Terrain.TileSize.Y));
            MinimapTextureFill(Texture);

            for ( Y = 0; Y <= Terrain.TileSize.Y - 1; Y++ )
            {
                for ( X = 0; X <= Terrain.TileSize.X - 1; X++ )
                {
                    MinimapBitmap.SetPixel(X, Y,
                        ColorTranslator.FromOle(
                            ColorUtil.OSRGB((int)(MathUtil.Clamp_sng(Convert.ToSingle(Texture.get_Pixels(X, Y).Red * 255.0F), 0.0F, 255.0F)),
                                (int)(MathUtil.Clamp_sng(Convert.ToSingle(Texture.get_Pixels(X, Y).Green * 255.0F), 0.0F, 255.0F)),
                                (int)(MathUtil.Clamp_sng(Convert.ToSingle(Texture.get_Pixels(X, Y).Blue * 255.0F), 0.0F, 255.0F)))));
                }
            }

            ReturnResult = BitmapUtil.SaveBitmap(Path, Overwrite, MinimapBitmap);

            return ReturnResult;
        }
Пример #8
0
        public App.sResult Write_Heightmap(string Path, bool Overwrite)
        {
            App.sResult ReturnResult = new App.sResult();
            Bitmap HeightmapBitmap = new Bitmap(Terrain.TileSize.X + 1, Terrain.TileSize.Y + 1);
            int X = 0;
            int Y = 0;

            for ( Y = 0; Y <= Terrain.TileSize.Y; Y++ )
            {
                for ( X = 0; X <= Terrain.TileSize.X; X++ )
                {
                    HeightmapBitmap.SetPixel(X, Y,
                        ColorTranslator.FromOle(ColorUtil.OSRGB(Convert.ToInt32(Terrain.Vertices[X, Y].Height), Terrain.Vertices[X, Y].Height,
                            Terrain.Vertices[X, Y].Height)));
                }
            }

            ReturnResult = BitmapUtil.SaveBitmap(Path, Overwrite, HeightmapBitmap);
            return ReturnResult;
        }
Пример #9
0
        public clsResult GenerateLayout()
        {
            clsResult ReturnResult = new clsResult("Layout");

            int X = 0;
            int Y = 0;
            int A = 0;
            int B = 0;
            int C = 0;
            int D = 0;
            int E = 0;
            int F = 0;
            int G = 0;
            int H = 0;

            TotalPlayerCount = TopLeftPlayerCount * SymmetryBlockCount;

            sXY_int SymmetrySize = new sXY_int();

            SymmetrySize.X = (int)(TileSize.X * App.TerrainGridSpacing / SymmetryBlockCountXY.X);
            SymmetrySize.Y = (int)(TileSize.Y * App.TerrainGridSpacing / SymmetryBlockCountXY.Y);

            //create passage nodes

            int PassageRadius = (int)(128.0F * NodeScale);
            int MaxLikelyPassageNodeCount = 0;
            MaxLikelyPassageNodeCount =
                (int)(Math.Ceiling(Convert.ToDecimal(2.0D * TileSize.X * 128 * TileSize.Y * 128 / (Math.PI * PassageRadius * PassageRadius))));

            PassageNodes = new clsPassageNode[SymmetryBlockCount, MaxLikelyPassageNodeCount];
            int LoopCount = 0;
            int EdgeOffset = 0 * 128;
            bool PointIsValid;
            sXY_int EdgeSections = new sXY_int();
            Position.XY_dbl EdgeSectionSize = default(Position.XY_dbl);
            sXY_int NewPointPos = new sXY_int();

            if ( SymmetryBlockCountXY.X == 1 )
            {
                EdgeSections.X =
                    Convert.ToInt32(
                        Conversion.Int((TileSize.X * App.TerrainGridSpacing - EdgeOffset * 2.0D) / (NodeScale * App.TerrainGridSpacing * 2.0F)));
                EdgeSectionSize.X = (TileSize.X * App.TerrainGridSpacing - EdgeOffset * 2.0D) / EdgeSections.X;
                EdgeSections.X--;
            }
            else
            {
                EdgeSections.X =
                    (int)
                        (Conversion.Int((TileSize.X * App.TerrainGridSpacing / SymmetryBlockCountXY.X - EdgeOffset) /
                                        (NodeScale * App.TerrainGridSpacing * 2.0F) - 0.5D));
                EdgeSectionSize.X =
                    Convert.ToDouble((TileSize.X * App.TerrainGridSpacing / SymmetryBlockCountXY.X - EdgeOffset) /
                                            (Convert.ToDouble(
                                                Conversion.Int((TileSize.X * App.TerrainGridSpacing / SymmetryBlockCountXY.X - EdgeOffset) /
                                                               (NodeScale * App.TerrainGridSpacing * 2.0F) - 0.5D)) + 0.5D));
            }
            if ( SymmetryBlockCountXY.Y == 1 )
            {
                EdgeSections.Y =
                    Convert.ToInt32(
                        Conversion.Int((TileSize.Y * App.TerrainGridSpacing - EdgeOffset * 2.0D) / (NodeScale * App.TerrainGridSpacing * 2.0F)));
                EdgeSectionSize.Y = (TileSize.Y * App.TerrainGridSpacing - EdgeOffset * 2.0D) / EdgeSections.Y;
                EdgeSections.Y--;
            }
            else
            {
                EdgeSections.Y =
                    Convert.ToInt32(
                        Conversion.Int((TileSize.Y * App.TerrainGridSpacing / SymmetryBlockCountXY.Y - EdgeOffset) /
                                       (NodeScale * App.TerrainGridSpacing * 2.0F) - 0.5D));
                EdgeSectionSize.Y =
                    Convert.ToDouble((TileSize.Y * App.TerrainGridSpacing / SymmetryBlockCountXY.Y - EdgeOffset) /
                                            (Convert.ToDouble(
                                                Conversion.Int((TileSize.Y * App.TerrainGridSpacing / SymmetryBlockCountXY.Y - EdgeOffset) /
                                                               (NodeScale * App.TerrainGridSpacing * 2.0F) - 0.5D)) + 0.5D));
            }

            PassageNodeCount = 0;
            for ( Y = 0; Y <= EdgeSections.Y; Y++ )
            {
                if ( !MakePassageNodes(new sXY_int(EdgeOffset, EdgeOffset + (int)(Y * EdgeSectionSize.Y)), true) )
                {
                    ReturnResult.ProblemAdd("Error: Bad border node.");
                    return ReturnResult;
                }
                if ( SymmetryBlockCountXY.X == 1 )
                {
                    if (
                        !MakePassageNodes(new sXY_int(TileSize.X * App.TerrainGridSpacing - EdgeOffset, EdgeOffset + (int)(Y * EdgeSectionSize.Y)), true) )
                    {
                        ReturnResult.ProblemAdd("Error: Bad border node.");
                        return ReturnResult;
                    }
                }
            }
            for ( X = 1; X <= EdgeSections.X; X++ )
            {
                if ( !MakePassageNodes(new sXY_int(EdgeOffset + (int)(X * EdgeSectionSize.X), EdgeOffset), true) )
                {
                    ReturnResult.ProblemAdd("Error: Bad border node.");
                    return ReturnResult;
                }
                if ( SymmetryBlockCountXY.Y == 1 )
                {
                    if (
                        !MakePassageNodes(new sXY_int(EdgeOffset + (int)(X * EdgeSectionSize.X), TileSize.Y * App.TerrainGridSpacing - EdgeOffset), true) )
                    {
                        ReturnResult.ProblemAdd("Error: Bad border node.");
                        return ReturnResult;
                    }
                }
            }
            do
            {
                LoopCount = 0;
                do
                {
                    PointIsValid = true;
                    if ( SymmetryBlockCountXY.X == 1 )
                    {
                        NewPointPos.X = (int)(EdgeOffset + Conversion.Int(VBMath.Rnd() * (SymmetrySize.X - EdgeOffset * 2 + 1)));
                    }
                    else
                    {
                        NewPointPos.X = EdgeOffset + (int)(Conversion.Int(VBMath.Rnd() * (SymmetrySize.X - EdgeOffset + 1)));
                    }
                    if ( SymmetryBlockCountXY.Y == 1 )
                    {
                        NewPointPos.Y = EdgeOffset + (int)(Conversion.Int(VBMath.Rnd() * (SymmetrySize.Y - EdgeOffset * 2 + 1)));
                    }
                    else
                    {
                        NewPointPos.Y = EdgeOffset + Convert.ToInt32(Conversion.Int(VBMath.Rnd() * (SymmetrySize.Y - EdgeOffset + 1)));
                    }
                    for ( A = 0; A <= PassageNodeCount - 1; A++ )
                    {
                        for ( B = 0; B <= SymmetryBlockCount - 1; B++ )
                        {
                            if ( (PassageNodes[B, A].Pos - NewPointPos).ToDoubles().GetMagnitude() < PassageRadius * 2 )
                            {
                                goto PointTooClose;
                            }
                        }
                    }
                    PointTooClose:
                    if ( A == PassageNodeCount )
                    {
                        if ( MakePassageNodes(NewPointPos, false) )
                        {
                            break;
                        }
                    }
                    LoopCount++;
                    if ( LoopCount >= (int)(64.0F * TileSize.X * TileSize.Y / (NodeScale * NodeScale)) )
                    {
                        goto PointMakingFinished;
                    }
                } while ( true );
            } while ( true );
            PointMakingFinished:
            PassageNodes =
                (clsPassageNode[,])
                    Utils.CopyArray((Array)PassageNodes, new clsPassageNode[SymmetryBlockCount, PassageNodeCount]);

            //connect until all are connected without intersecting

            MathUtil.sIntersectPos IntersectPos = new MathUtil.sIntersectPos();
            int MaxConDist2 = PassageRadius * 2 * 4;
            MaxConDist2 *= MaxConDist2;
            clsNearest NearestA = default(clsNearest);
            Nearests = new clsNearest[PassageNodeCount * 64];
            clsPassageNode tmpPassageNodeA = default(clsPassageNode);
            clsPassageNode tmpPassageNodeB = default(clsPassageNode);
            clsTestNearestArgs NearestArgs = new clsTestNearestArgs();
            int MinConDist = (int)(NodeScale * 1.25F * 128.0F);

            NearestArgs.MaxConDist2 = MaxConDist2;
            NearestArgs.MinConDist = MinConDist;

            for ( A = 0; A <= PassageNodeCount - 1; A++ )
            {
                NearestArgs.PassageNodeA = PassageNodes[0, A];
                for ( B = A; B <= PassageNodeCount - 1; B++ )
                {
                    for ( C = 0; C <= SymmetryBlockCount - 1; C++ )
                    {
                        NearestArgs.PassageNodeB = PassageNodes[C, B];
                        if ( NearestArgs.PassageNodeA != NearestArgs.PassageNodeB )
                        {
                            TestNearest(NearestArgs);
                        }
                    }
                }
            }

            clsNearest NearestB = default(clsNearest);
            bool Flag = default(bool);

            for ( G = 0; G <= NearestCount - 1; G++ )
            {
                NearestA = Nearests[G];
                for ( A = 0; A <= NearestA.NodeCount - 1; A++ )
                {
                    tmpPassageNodeA = NearestA.NodeA[A];
                    tmpPassageNodeB = NearestA.NodeB[A];
                    for ( H = 0; H <= NearestCount - 1; H++ )
                    {
                        NearestB = Nearests[H];
                        if ( NearestB != NearestA )
                        {
                            if ( NearestB.Dist2 < NearestA.Dist2 )
                            {
                                Flag = true;
                            }
                            else if ( NearestB.Dist2 == NearestA.Dist2 )
                            {
                                Flag = NearestA.Num > NearestB.Num;
                            }
                            else
                            {
                                Flag = false;
                            }
                            if ( Flag )
                            {
                                for ( B = 0; B <= NearestB.NodeCount - 1; B++ )
                                {
                                    if ( !(tmpPassageNodeA == NearestB.NodeA[B] || tmpPassageNodeA == NearestB.NodeB[B]
                                           || tmpPassageNodeB == NearestB.NodeA[B] || tmpPassageNodeB == NearestB.NodeB[B]) )
                                    {
                                        IntersectPos = MathUtil.GetLinesIntersectBetween(tmpPassageNodeA.Pos, tmpPassageNodeB.Pos, NearestB.NodeA[B].Pos,
                                            NearestB.NodeB[B].Pos);
                                        if ( IntersectPos.Exists )
                                        {
                                            break;
                                        }
                                    }
                                }
                                if ( B < NearestB.NodeCount )
                                {
                                    NearestA.BlockedCount++;
                                    NearestB.BlockedNearests[NearestB.BlockedNearestCount] = NearestA;
                                    NearestB.BlockedNearestCount++;
                                }
                            }
                        }
                    }
                }
            }

            int ChangeCount = 0;
            Connections = new clsConnection[PassageNodeCount * 16];

            do
            {
                //create valid connections
                ChangeCount = 0;
                G = 0;
                while ( G < NearestCount )
                {
                    NearestA = Nearests[G];
                    Flag = true;
                    if ( NearestA.BlockedCount == 0 && Flag )
                    {
                        F = ConnectionCount;
                        for ( D = 0; D <= NearestA.NodeCount - 1; D++ )
                        {
                            Connections[ConnectionCount] = new clsConnection(NearestA.NodeA[D], NearestA.NodeB[D]);
                            ConnectionCount++;
                        }
                        for ( D = 0; D <= NearestA.NodeCount - 1; D++ )
                        {
                            A = F + D;
                            Connections[A].ReflectionCount = NearestA.NodeCount - 1;
                            Connections[A].Reflections = new clsConnection[Connections[A].ReflectionCount];
                            B = 0;
                            for ( E = 0; E <= NearestA.NodeCount - 1; E++ )
                            {
                                if ( E != D )
                                {
                                    Connections[A].Reflections[B] = Connections[F + E];
                                    B++;
                                }
                            }
                        }
                        for ( C = 0; C <= NearestA.BlockedNearestCount - 1; C++ )
                        {
                            NearestA.BlockedNearests[C].Invalid = true;
                        }
                        NearestCount--;
                        H = NearestA.Num;
                        NearestA.Num = -1;
                        if ( H != NearestCount )
                        {
                            Nearests[H] = Nearests[NearestCount];
                            Nearests[H].Num = H;
                        }
                        ChangeCount++;
                    }
                    else
                    {
                        if ( !Flag )
                        {
                            NearestA.Invalid = true;
                        }
                        G++;
                    }
                }
                //remove blocked ones and their blocking effect
                G = 0;
                while ( G < NearestCount )
                {
                    NearestA = Nearests[G];
                    if ( NearestA.Invalid )
                    {
                        NearestA.Num = -1;
                        for ( D = 0; D <= NearestA.BlockedNearestCount - 1; D++ )
                        {
                            NearestA.BlockedNearests[D].BlockedCount--;
                        }
                        NearestCount--;
                        if ( G != NearestCount )
                        {
                            Nearests[G] = Nearests[NearestCount];
                            Nearests[G].Num = G;
                        }
                    }
                    else
                    {
                        G++;
                    }
                }
            } while ( ChangeCount > 0 );

            //put connections in order of angle

            for ( A = 0; A <= PassageNodeCount - 1; A++ )
            {
                for ( B = 0; B <= SymmetryBlockCount - 1; B++ )
                {
                    PassageNodes[B, A].ReorderConnections();
                    PassageNodes[B, A].CalcIsNearBorder();
                }
            }

            //get nodes in random order

            clsPassageNode[] PassageNodeListOrder = new clsPassageNode[PassageNodeCount];
            int PassageNodeListOrderCount = 0;
            clsPassageNode[] PassageNodeOrder = new clsPassageNode[PassageNodeCount];
            for ( A = 0; A <= PassageNodeCount - 1; A++ )
            {
                PassageNodeListOrder[PassageNodeListOrderCount] = PassageNodes[0, A];
                PassageNodeListOrderCount++;
            }
            B = 0;
            while ( PassageNodeListOrderCount > 0 )
            {
                A = (int)(Conversion.Int(VBMath.Rnd() * PassageNodeListOrderCount));
                PassageNodeOrder[B] = PassageNodeListOrder[A];
                B++;
                PassageNodeListOrderCount--;
                PassageNodeListOrder[A] = PassageNodeListOrder[PassageNodeListOrderCount];
            }

            //designate height levels

            LevelHeight = 255.0F / (LevelCount - 1);
            int BestNum = 0;
            double Dist = 0;
            clsPassageNodeHeightLevelArgs HeightsArgs = new clsPassageNodeHeightLevelArgs();
            HeightsArgs.PassageNodesMinLevel.Nodes = new int[PassageNodeCount];
            HeightsArgs.PassageNodesMaxLevel.Nodes = new int[PassageNodeCount];
            HeightsArgs.MapLevelCount = new int[LevelCount];
            sXY_int RotatedPos = new sXY_int();

            for ( A = 0; A <= PassageNodeCount - 1; A++ )
            {
                HeightsArgs.PassageNodesMinLevel.Nodes[A] = 0;
                HeightsArgs.PassageNodesMaxLevel.Nodes[A] = LevelCount - 1;
            }

            //create bases
            double[] BestDists = new double[BaseFlatArea];
            clsPassageNode[] BestNodes = new clsPassageNode[BaseFlatArea];
            int[] BestNodesReflectionNums = new int[BaseFlatArea];
            int BestDistCount = 0;
            PlayerBases = new sPlayerBase[TotalPlayerCount];
            for ( B = 0; B <= TopLeftPlayerCount - 1; B++ )
            {
                BestDistCount = 0;
                for ( A = 0; A <= PassageNodeCount - 1; A++ )
                {
                    for ( E = 0; E <= SymmetryBlockCount - 1; E++ )
                    {
                        tmpPassageNodeA = PassageNodes[E, A];
                        if ( !tmpPassageNodeA.IsOnBorder )
                        {
                            Dist = (tmpPassageNodeA.Pos - PlayerBasePos[B]).ToDoubles().GetMagnitude();
                            for ( C = BestDistCount - 1; C >= 0; C-- )
                            {
                                if ( Dist > BestDists[C] )
                                {
                                    break;
                                }
                            }
                            C++;
                            for ( D = Math.Min(BestDistCount - 1, BaseFlatArea - 2); D >= C; D-- )
                            {
                                BestDists[D + 1] = BestDists[D];
                                BestNodes[D + 1] = BestNodes[D];
                            }
                            if ( C < BaseFlatArea )
                            {
                                BestDists[C] = Dist;
                                BestNodes[C] = tmpPassageNodeA;
                                BestDistCount = Math.Max(BestDistCount, C + 1);
                            }
                        }
                    }
                }

                if ( BaseLevel < 0 )
                {
                    D = Convert.ToInt32(Conversion.Int(VBMath.Rnd() * LevelCount));
                }
                else
                {
                    D = BaseLevel;
                }

                HeightsArgs.MapLevelCount[D] += BestDistCount;

                for ( A = 0; A <= BestDistCount - 1; A++ )
                {
                    if ( BestNodes[A].MirrorNum == 0 )
                    {
                        BestNodesReflectionNums[A] = -1;
                    }
                    else
                    {
                        for ( C = 0; C <= ((int)(SymmetryBlockCount / 2.0D)) - 1; C++ )
                        {
                            if ( SymmetryBlocks[0].ReflectToNum[C] == BestNodes[A].MirrorNum )
                            {
                                break;
                            }
                        }
                        BestNodesReflectionNums[A] = C;
                    }
                }

                for ( A = 0; A <= SymmetryBlockCount - 1; A++ )
                {
                    E = A * TopLeftPlayerCount + B;
                    PlayerBases[E].NodeCount = BestDistCount;
                    PlayerBases[E].Nodes = new clsPassageNode[PlayerBases[E].NodeCount];
                    for ( C = 0; C <= BestDistCount - 1; C++ )
                    {
                        if ( BestNodesReflectionNums[C] < 0 )
                        {
                            PlayerBases[E].Nodes[C] = PassageNodes[A, BestNodes[C].Num];
                        }
                        else
                        {
                            PlayerBases[E].Nodes[C] = PassageNodes[SymmetryBlocks[A].ReflectToNum[BestNodesReflectionNums[C]], BestNodes[C].Num];
                        }
                        PlayerBases[E].Nodes[C].PlayerBaseNum = E;
                        PlayerBases[E].Nodes[C].Level = D;
                        PassageNodesMinLevelSet(PlayerBases[E].Nodes[C], HeightsArgs.PassageNodesMinLevel, D, MaxLevelTransition);
                        PassageNodesMaxLevelSet(PlayerBases[E].Nodes[C], HeightsArgs.PassageNodesMaxLevel, D, MaxLevelTransition);
                    }
                    //PlayerBases(E).CalcPos()
                    RotatedPos = TileUtil.GetRotatedPos(SymmetryBlocks[A].Orientation, PlayerBasePos[B],
                        new sXY_int(SymmetrySize.X - 1, SymmetrySize.Y - 1));
                    PlayerBases[E].Pos.X = SymmetryBlocks[A].XYNum.X * SymmetrySize.X + RotatedPos.X;
                    PlayerBases[E].Pos.Y = SymmetryBlocks[A].XYNum.Y * SymmetrySize.Y + RotatedPos.Y;
                }
            }

            int WaterCount = 0;
            bool CanDoFlatsAroundWater = default(bool);
            int TotalWater = 0;
            int WaterSpawns = 0;

            for ( A = 0; A <= PassageNodeCount - 1; A++ )
            {
                tmpPassageNodeA = PassageNodeOrder[A];
                if ( tmpPassageNodeA.Level < 0 && !tmpPassageNodeA.IsOnBorder )
                {
                    WaterCount = 0;
                    for ( B = 0; B <= tmpPassageNodeA.ConnectionCount - 1; B++ )
                    {
                        tmpPassageNodeB = tmpPassageNodeA.Connections[B].GetOther();
                        if ( tmpPassageNodeB.IsWater )
                        {
                            WaterCount++;
                        }
                    }
                    CanDoFlatsAroundWater = true;
                    for ( B = 0; B <= tmpPassageNodeA.ConnectionCount - 1; B++ )
                    {
                        if ( HeightsArgs.PassageNodesMinLevel.Nodes[tmpPassageNodeA.Connections[B].GetOther().Num] > 0 )
                        {
                            CanDoFlatsAroundWater = false;
                        }
                    }
                    if ( CanDoFlatsAroundWater &&
                         ((WaterCount == 0 & WaterSpawns < WaterSpawnQuantity) || (WaterCount == 1 & TotalWaterQuantity - TotalWater > WaterSpawnQuantity - WaterSpawns)) &&
                         HeightsArgs.PassageNodesMinLevel.Nodes[tmpPassageNodeA.Num] == 0 & TotalWater < TotalWaterQuantity )
                    {
                        if ( WaterCount == 0 )
                        {
                            WaterSpawns++;
                        }
                        TotalWater++;
                        C = tmpPassageNodeA.Num;
                        for ( D = 0; D <= SymmetryBlockCount - 1; D++ )
                        {
                            PassageNodes[D, C].IsWater = true;
                            PassageNodes[D, C].Level = 0;
                        }
                        PassageNodesMinLevelSet(tmpPassageNodeA, HeightsArgs.PassageNodesMinLevel, 0, MaxLevelTransition);
                        PassageNodesMaxLevelSet(tmpPassageNodeA, HeightsArgs.PassageNodesMaxLevel, 0, MaxLevelTransition);
                        HeightsArgs.MapLevelCount[0]++;
                        for ( B = 0; B <= tmpPassageNodeA.ConnectionCount - 1; B++ )
                        {
                            tmpPassageNodeB = tmpPassageNodeA.Connections[B].GetOther();
                            PassageNodesMinLevelSet(tmpPassageNodeB, HeightsArgs.PassageNodesMinLevel, 0, MaxLevelTransition);
                            PassageNodesMaxLevelSet(tmpPassageNodeB, HeightsArgs.PassageNodesMaxLevel, 0, MaxLevelTransition);
                        }
                    }
                }
            }

            clsPassageNode tmpPassageNodeC = default(clsPassageNode);
            App.sResult Result = new App.sResult();

            HeightsArgs.FlatsCutoff = 1;
            HeightsArgs.PassagesCutoff = 1;
            HeightsArgs.VariationCutoff = 1;
            HeightsArgs.ActionTotal = 1;

            for ( A = 0; A <= PassageNodeCount - 1; A++ )
            {
                tmpPassageNodeA = PassageNodeOrder[A];
                if ( tmpPassageNodeA.Level < 0 && !tmpPassageNodeA.IsOnBorder && tmpPassageNodeA.IsNearBorder )
                {
                    HeightsArgs.PassageNode = tmpPassageNodeA;
                    Result = PassageNodeHeightLevel(HeightsArgs);
                    if ( !Result.Success )
                    {
                        ReturnResult.ProblemAdd(Result.Problem);
                        return ReturnResult;
                    }
                }
            }

            HeightsArgs.FlatsCutoff = FlatsChance;
            HeightsArgs.PassagesCutoff = HeightsArgs.FlatsCutoff + PassagesChance;
            HeightsArgs.VariationCutoff = HeightsArgs.PassagesCutoff + VariationChance;
            HeightsArgs.ActionTotal = HeightsArgs.VariationCutoff;
            if ( HeightsArgs.ActionTotal <= 0 )
            {
                ReturnResult.ProblemAdd("All height level behaviors are zero");
                return ReturnResult;
            }

            for ( A = 0; A <= PassageNodeCount - 1; A++ )
            {
                tmpPassageNodeA = PassageNodeOrder[A];
                if ( tmpPassageNodeA.Level < 0 && !tmpPassageNodeA.IsOnBorder )
                {
                    HeightsArgs.PassageNode = tmpPassageNodeA;
                    Result = PassageNodeHeightLevel(HeightsArgs);
                    if ( !Result.Success )
                    {
                        ReturnResult.ProblemAdd(Result.Problem);
                        return ReturnResult;
                    }
                }
            }

            //set edge points to the level of their neighbour
            for ( A = 0; A <= PassageNodeCount - 1; A++ )
            {
                tmpPassageNodeA = PassageNodes[0, A];
                if ( tmpPassageNodeA.IsOnBorder )
                {
                    if ( tmpPassageNodeA.Level >= 0 )
                    {
                        ReturnResult.ProblemAdd("Error: Border has had its height set.");
                        return ReturnResult;
                    }
                    //If tmpPassageNodeA.ConnectionCount <> 1 Then
                    //    ReturnResult.Problem = "Error: Border has incorrect connections."
                    //    Exit Function
                    //End If
                    tmpPassageNodeC = null;
                    CanDoFlatsAroundWater = true;
                    for ( B = 0; B <= tmpPassageNodeA.ConnectionCount - 1; B++ )
                    {
                        tmpPassageNodeB = tmpPassageNodeA.Connections[B].GetOther();
                        if ( tmpPassageNodeB.Level >= 0 && !tmpPassageNodeB.IsOnBorder )
                        {
                            if ( HeightsArgs.PassageNodesMinLevel.Nodes[tmpPassageNodeA.Num] <= tmpPassageNodeB.Level &&
                                 HeightsArgs.PassageNodesMaxLevel.Nodes[tmpPassageNodeA.Num] >= tmpPassageNodeB.Level )
                            {
                                if ( tmpPassageNodeC == null )
                                {
                                    tmpPassageNodeC = tmpPassageNodeB;
                                }
                            }
                        }
                        if ( HeightsArgs.PassageNodesMinLevel.Nodes[tmpPassageNodeB.Num] > 0 )
                        {
                            CanDoFlatsAroundWater = false;
                        }
                    }
                    //If tmpPassageNodeC Is Nothing Then
                    //    ReturnResult.Problem_Add("Error: No connection for border node")
                    //    Return ReturnResult
                    //End If
                    if ( tmpPassageNodeC != null )
                    {
                        BestNum = tmpPassageNodeC.Level;
                        PassageNodesMinLevelSet(tmpPassageNodeA, HeightsArgs.PassageNodesMinLevel, BestNum, MaxLevelTransition);
                        PassageNodesMaxLevelSet(tmpPassageNodeA, HeightsArgs.PassageNodesMaxLevel, BestNum, MaxLevelTransition);
                        for ( D = 0; D <= SymmetryBlockCount - 1; D++ )
                        {
                            PassageNodes[D, A].IsWater = tmpPassageNodeC.IsWater && CanDoFlatsAroundWater;
                            PassageNodes[D, A].Level = BestNum;
                        }
                        if ( tmpPassageNodeA.IsWater )
                        {
                            for ( B = 0; B <= tmpPassageNodeA.ConnectionCount - 1; B++ )
                            {
                                tmpPassageNodeB = tmpPassageNodeA.Connections[B].GetOther();
                                PassageNodesMinLevelSet(tmpPassageNodeB, HeightsArgs.PassageNodesMinLevel, tmpPassageNodeA.Level, MaxLevelTransition);
                                PassageNodesMaxLevelSet(tmpPassageNodeB, HeightsArgs.PassageNodesMaxLevel, tmpPassageNodeA.Level, MaxLevelTransition);
                            }
                        }
                    }
                }
                else if ( tmpPassageNodeA.Level < 0 )
                {
                    ReturnResult.ProblemAdd("Error: Node height not set");
                    return ReturnResult;
                }
            }
            //set level of edge points only connected to another border point
            for ( A = 0; A <= PassageNodeCount - 1; A++ )
            {
                tmpPassageNodeA = PassageNodes[0, A];
                if ( tmpPassageNodeA.IsOnBorder && tmpPassageNodeA.Level < 0 )
                {
                    tmpPassageNodeC = null;
                    CanDoFlatsAroundWater = true;
                    for ( B = 0; B <= tmpPassageNodeA.ConnectionCount - 1; B++ )
                    {
                        tmpPassageNodeB = tmpPassageNodeA.Connections[B].GetOther();
                        if ( tmpPassageNodeB.Level >= 0 )
                        {
                            if ( HeightsArgs.PassageNodesMinLevel.Nodes[tmpPassageNodeA.Num] <= tmpPassageNodeB.Level &&
                                 HeightsArgs.PassageNodesMaxLevel.Nodes[tmpPassageNodeA.Num] >= tmpPassageNodeB.Level )
                            {
                                if ( tmpPassageNodeC == null )
                                {
                                    tmpPassageNodeC = tmpPassageNodeB;
                                }
                            }
                        }
                        if ( HeightsArgs.PassageNodesMinLevel.Nodes[tmpPassageNodeB.Num] > 0 )
                        {
                            CanDoFlatsAroundWater = false;
                        }
                    }
                    if ( tmpPassageNodeC == null )
                    {
                        ReturnResult.ProblemAdd("Error: No connection for border node");
                        return ReturnResult;
                    }
                    BestNum = tmpPassageNodeC.Level;
                    PassageNodesMinLevelSet(tmpPassageNodeA, HeightsArgs.PassageNodesMinLevel, BestNum, MaxLevelTransition);
                    PassageNodesMaxLevelSet(tmpPassageNodeA, HeightsArgs.PassageNodesMaxLevel, BestNum, MaxLevelTransition);
                    for ( D = 0; D <= SymmetryBlockCount - 1; D++ )
                    {
                        PassageNodes[D, A].IsWater = tmpPassageNodeC.IsWater && CanDoFlatsAroundWater;
                        PassageNodes[D, A].Level = BestNum;
                    }
                    if ( tmpPassageNodeA.IsWater )
                    {
                        for ( B = 0; B <= tmpPassageNodeA.ConnectionCount - 1; B++ )
                        {
                            tmpPassageNodeB = tmpPassageNodeA.Connections[B].GetOther();
                            PassageNodesMinLevelSet(tmpPassageNodeB, HeightsArgs.PassageNodesMinLevel, tmpPassageNodeA.Level, MaxLevelTransition);
                            PassageNodesMaxLevelSet(tmpPassageNodeB, HeightsArgs.PassageNodesMaxLevel, tmpPassageNodeA.Level, MaxLevelTransition);
                        }
                    }
                }
            }

            RampBase = 1.0D;
            MaxDisconnectionDist = 99999.0F;

            clsResult RampResult = GenerateRamps();
            ReturnResult.Add(RampResult);

            return ReturnResult;
        }
Пример #10
0
        private App.sResult Read_TTP(BinaryReader File)
        {
            App.sResult ReturnResult = new App.sResult();
            ReturnResult.Success = false;
            ReturnResult.Problem = "";

            string strTemp = "";
            UInt32 uintTemp = 0;
            UInt16 ushortTemp = 0;
            int A = 0;

            try
            {
                strTemp = IOUtil.ReadOldTextOfLength(File, 4);
                if ( strTemp != "ttyp" )
                {
                    ReturnResult.Problem = "Incorrect identifier.";
                    return ReturnResult;
                }

                uintTemp = File.ReadUInt32();
                if ( uintTemp != 8U )
                {
                    ReturnResult.Problem = "Unknown version.";
                    return ReturnResult;
                }
                uintTemp = File.ReadUInt32();
                for ( A = 0; A <= ((int)(Math.Min(uintTemp, (uint)Tileset.TileCount))) - 1; A++ )
                {
                    ushortTemp = File.ReadUInt16();
                    if ( ushortTemp > 11 )
                    {
                        ReturnResult.Problem = "Unknown tile type number.";
                        return ReturnResult;
                    }
                    Tile_TypeNum[A] = (byte)ushortTemp;
                }
            }
            catch ( Exception ex )
            {
                ReturnResult.Problem = ex.Message;
                return ReturnResult;
            }

            ReturnResult.Success = true;
            return ReturnResult;
        }
Пример #11
0
        private App.sResult Read_WZ_Structures(BinaryReader File, SimpleClassList<clsWZBJOUnit> WZUnits)
        {
            App.sResult ReturnResult = new App.sResult();
            ReturnResult.Success = false;
            ReturnResult.Problem = "";

            string strTemp = null;
            UInt32 Version = 0;
            UInt32 uintTemp = 0;
            int A = 0;
            int B = 0;
            clsWZBJOUnit WZBJOUnit = default(clsWZBJOUnit);

            try
            {
                strTemp = IOUtil.ReadOldTextOfLength(File, 4);
                if ( strTemp != "stru" )
                {
                    ReturnResult.Problem = "Unknown struct.bjo identifier.";
                    return ReturnResult;
                }

                Version = File.ReadUInt32();
                if ( Version != 8U )
                {
                    if (
                        Interaction.MsgBox("struct.bjo version is unknown. Continue?", (MsgBoxStyle)(MsgBoxStyle.OkCancel | MsgBoxStyle.Question),
                            null) != MsgBoxResult.Ok )
                    {
                        ReturnResult.Problem = "Aborted.";
                        return ReturnResult;
                    }
                }

                uintTemp = File.ReadUInt32();
                for ( A = 0; A <= (Convert.ToInt32(uintTemp)) - 1; A++ )
                {
                    WZBJOUnit = new clsWZBJOUnit();
                    WZBJOUnit.ObjectType = clsUnitType.enumType.PlayerStructure;
                    WZBJOUnit.Code = IOUtil.ReadOldTextOfLength(File, 40);
                    B = Strings.InStr(WZBJOUnit.Code, Convert.ToString('\0'), (CompareMethod)0);
                    if ( B > 0 )
                    {
                        WZBJOUnit.Code = Strings.Left(WZBJOUnit.Code, B - 1);
                    }
                    WZBJOUnit.ID = File.ReadUInt32();
                    WZBJOUnit.Pos.Horizontal.X = (int)(File.ReadUInt32());
                    WZBJOUnit.Pos.Horizontal.Y = (int)(File.ReadUInt32());
                    WZBJOUnit.Pos.Altitude = (int)(File.ReadUInt32());
                    WZBJOUnit.Rotation = File.ReadUInt32();
                    WZBJOUnit.Player = File.ReadUInt32();
                    File.ReadBytes(56);
                    WZUnits.Add(WZBJOUnit);
                }
            }
            catch ( Exception ex )
            {
                ReturnResult.Problem = ex.Message;
                return ReturnResult;
            }

            ReturnResult.Success = true;
            return ReturnResult;
        }
Пример #12
0
        public static App.sResult TryOpenFileStream(string Path, ref FileStream Output)
        {
            App.sResult ReturnResult = new App.sResult();
            ReturnResult.Success = false;
            ReturnResult.Problem = "";

            try
            {
                Output = new FileStream(Path, FileMode.Open);
            }
            catch ( Exception ex )
            {
                Output = null;
                ReturnResult.Problem = ex.Message;
                return ReturnResult;
            }

            ReturnResult.Success = true;
            return ReturnResult;
        }
Пример #13
0
            public App.sResult SetLabel(string Text)
            {
                App.sResult Result = new App.sResult();

                Result = _ParentMapLink.Source.ScriptLabelIsValid(Text);
                if ( Result.Success )
                {
                    _Label = Text;
                }
                return Result;
            }
Пример #14
0
        private App.sResult Read_WZ_gam(BinaryReader File)
        {
            App.sResult ReturnResult = new App.sResult();
            ReturnResult.Success = false;
            ReturnResult.Problem = "";

            string strTemp = "";
            UInt32 Version = 0;

            try
            {
                strTemp = IOUtil.ReadOldTextOfLength(File, 4);
                if ( strTemp != "game" )
                {
                    ReturnResult.Problem = "Unknown game identifier.";
                    return ReturnResult;
                }

                Version = File.ReadUInt32();
                if ( Version != 8U )
                {
                    if (
                        Interaction.MsgBox("Game file version is unknown. Continue?", (MsgBoxStyle)(MsgBoxStyle.OkCancel | MsgBoxStyle.Question),
                            null) != MsgBoxResult.Ok )
                    {
                        ReturnResult.Problem = "Aborted.";
                        return ReturnResult;
                    }
                }

                if ( InterfaceOptions == null )
                {
                    InterfaceOptions = new clsInterfaceOptions();
                }

                File.ReadInt32(); //game time
                InterfaceOptions.CampaignGameType = File.ReadInt32();
                InterfaceOptions.AutoScrollLimits = false;
                InterfaceOptions.ScrollMin.X = File.ReadInt32();
                InterfaceOptions.ScrollMin.Y = File.ReadInt32();
                InterfaceOptions.ScrollMax.X = File.ReadUInt32();
                InterfaceOptions.ScrollMax.Y = File.ReadUInt32();
            }
            catch ( Exception ex )
            {
                ReturnResult.Problem = ex.Message;
                return ReturnResult;
            }

            ReturnResult.Success = true;
            return ReturnResult;
        }
Пример #15
0
        public clsResult LoadDirectory(string Path)
        {
            clsResult ReturnResult =
                new clsResult("Loading tileset from " + Convert.ToString(ControlChars.Quote) + Path + Convert.ToString(ControlChars.Quote));

            Bitmap Bitmap = null;
            App.sSplitPath SplitPath = new App.sSplitPath(Path);
            string SlashPath = App.EndWithPathSeperator(Path);
            App.sResult Result = new App.sResult();

            if ( SplitPath.FileTitle != "" )
            {
                Name = SplitPath.FileTitle;
            }
            else if ( SplitPath.PartCount >= 2 )
            {
                Name = SplitPath.Parts[SplitPath.PartCount - 2];
            }

            Result = Default_TileTypes_Load(SlashPath + Name + ".ttp");
            if ( !Result.Success )
            {
                ReturnResult.ProblemAdd("Loading tile types: " + Result.Problem);
                return ReturnResult;
            }

            int RedTotal = 0;
            int GreenTotal = 0;
            int BlueTotal = 0;
            int TileNum = 0;
            string strTile = "";
            BitmapGLTexture BitmapTextureArgs = new BitmapGLTexture();
            float[] AverageColour = new float[4];
            int X = 0;
            int Y = 0;
            Color Pixel = new Color();

            string GraphicPath = "";

            //tile count has been set by the ttp file

            for ( TileNum = 0; TileNum <= TileCount - 1; TileNum++ )
            {
                strTile = "tile-" + App.MinDigits(TileNum, 2) + ".png";

                //-------- 128 --------

                GraphicPath = SlashPath + Name + "-128" + Convert.ToString(App.PlatformPathSeparator) + strTile;

                Result = BitmapUtil.LoadBitmap(GraphicPath, ref Bitmap);
                if ( !Result.Success )
                {
                    //ignore and exit, since not all tile types have a corresponding tile graphic
                    return ReturnResult;
                }

                if ( Bitmap.Width != 128 | Bitmap.Height != 128 )
                {
                    ReturnResult.WarningAdd("Tile graphic " + GraphicPath + " from tileset " + Name + " is not 128x128.");
                    return ReturnResult;
                }

                BitmapTextureArgs.Texture = Bitmap;
                BitmapTextureArgs.MipMapLevel = 0;
                BitmapTextureArgs.MagFilter = TextureMagFilter.Nearest;
                BitmapTextureArgs.MinFilter = TextureMinFilter.Nearest;
                BitmapTextureArgs.TextureNum = 0;
                BitmapTextureArgs.Perform();
                Tiles[TileNum].TextureView_GL_Texture_Num = BitmapTextureArgs.TextureNum;

                BitmapTextureArgs.MagFilter = TextureMagFilter.Nearest;
                if ( SettingsManager.Settings.Mipmaps )
                {
                    BitmapTextureArgs.MinFilter = TextureMinFilter.LinearMipmapLinear;
                }
                else
                {
                    BitmapTextureArgs.MinFilter = TextureMinFilter.Nearest;
                }
                BitmapTextureArgs.TextureNum = 0;

                BitmapTextureArgs.Perform();
                Tiles[TileNum].MapView_GL_Texture_Num = BitmapTextureArgs.TextureNum;

                if ( SettingsManager.Settings.Mipmaps )
                {
                    if ( SettingsManager.Settings.MipmapsHardware )
                    {
                        GL.Enable(EnableCap.Texture2D);
                        GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
                        GL.Disable(EnableCap.Texture2D);
                    }
                    else
                    {
                        clsResult MipmapResult = default(clsResult);
                        MipmapResult = GenerateMipMaps(SlashPath, strTile, BitmapTextureArgs, TileNum);
                        ReturnResult.Add(MipmapResult);
                        if ( MipmapResult.HasProblems )
                        {
                            return ReturnResult;
                        }
                    }
                    GL.GetTexImage<Single>(TextureTarget.Texture2D, 7, PixelFormat.Rgba, PixelType.Float, AverageColour);
                    Tiles[TileNum].AverageColour.Red = AverageColour[0];
                    Tiles[TileNum].AverageColour.Green = AverageColour[1];
                    Tiles[TileNum].AverageColour.Blue = AverageColour[2];
                }
                else
                {
                    RedTotal = 0;
                    GreenTotal = 0;
                    BlueTotal = 0;
                    for ( Y = 0; Y <= Bitmap.Height - 1; Y++ )
                    {
                        for ( X = 0; X <= Bitmap.Width - 1; X++ )
                        {
                            Pixel = Bitmap.GetPixel(X, Y);
                            RedTotal += Pixel.R;
                            GreenTotal += Pixel.G;
                            BlueTotal += Pixel.B;
                        }
                    }
                    Tiles[TileNum].AverageColour.Red = (float)(RedTotal / 4177920.0D);
                    Tiles[TileNum].AverageColour.Green = (float)(GreenTotal / 4177920.0D);
                    Tiles[TileNum].AverageColour.Blue = (float)(BlueTotal / 4177920.0D);
                }
            }

            return ReturnResult;
        }
Пример #16
0
        public clsResult Load_WZ(string Path)
        {
            clsResult ReturnResult =
                new clsResult("Loading WZ from " + Convert.ToString(ControlChars.Quote) + Path + Convert.ToString(ControlChars.Quote));
            App.sResult SubResult = new App.sResult();
            string Quote = ControlChars.Quote.ToString();
            ZipEntry ZipEntry = default(ZipEntry);
            bool GameFound = default(bool);
            bool DatasetFound = default(bool);
            SimpleList<clsWZMapEntry> Maps = new SimpleList<clsWZMapEntry>();
            clsTileset GameTileset = null;
            string GameName = "";
            string strTemp = "";
            ZipSplitPath SplitPath;
            int A = 0;
            int B = 0;
            int C = 0;
            int D = 0;

            FileStream File = default(FileStream);
            try
            {
                File = System.IO.File.OpenRead(Path);
            }
            catch ( Exception ex )
            {
                ReturnResult.ProblemAdd(ex.Message);
                return ReturnResult;
            }

            ZipInputStream ZipStream = new ZipInputStream(File);

            //get all usable lev entries
            do
            {
                ZipEntry = ZipStream.GetNextEntry();
                if ( ZipEntry == null )
                {
                    break;
                }

                SplitPath = new ZipSplitPath(ZipEntry.Name);

                if ( SplitPath.FileExtension == "lev" && SplitPath.PartCount == 1 )
                {
                    if ( ZipEntry.Size > 10 * 1024 * 1024 )
                    {
                        ReturnResult.ProblemAdd("lev file is too large.");
                        ZipStream.Close();
                        return ReturnResult;
                    }
                    BinaryReader Reader = new BinaryReader(ZipStream);
                    SimpleList<string> LineData = IOUtil.BytesToLinesRemoveComments(Reader);
                    //find each level block
                    for ( A = 0; A <= LineData.Count - 1; A++ )
                    {
                        if ( Strings.LCase(Strings.Left(LineData[A], 5)) == "level" )
                        {
                            //find each levels game file
                            GameFound = false;
                            B = 1;
                            while ( A + B < LineData.Count )
                            {
                                if ( Strings.LCase(Strings.Left(Convert.ToString(LineData[A + B]), 4)) == "game" )
                                {
                                    C = Strings.InStr(Convert.ToString(LineData[A + B]), Quote, (CompareMethod)0);
                                    D = Strings.InStrRev(Convert.ToString(LineData[A + B]), Quote, -1, (CompareMethod)0);
                                    if ( C > 0 & D > 0 & D - C > 1 )
                                    {
                                        GameName = Strings.LCase(Strings.Mid(Convert.ToString(LineData[A + B]), C + 1, D - C - 1));
                                        //see if map is already counted
                                        for ( C = 0; C <= Maps.Count - 1; C++ )
                                        {
                                            if ( GameName == Maps[C].Name )
                                            {
                                                break;
                                            }
                                        }
                                        if ( C == Maps.Count )
                                        {
                                            GameFound = true;
                                        }
                                    }
                                    break;
                                }
                                else if ( Strings.LCase(Strings.Left(Convert.ToString(LineData[A + B]), 5)) == "level" )
                                {
                                    break;
                                }
                                B++;
                            }
                            if ( GameFound )
                            {
                                //find the dataset (determines tileset)
                                DatasetFound = false;
                                B = 1;
                                while ( A + B < LineData.Count )
                                {
                                    if ( Strings.LCase(Strings.Left(Convert.ToString(LineData[A + B]), 7)) == "dataset" )
                                    {
                                        strTemp = Strings.LCase(Strings.Right(Convert.ToString(LineData[A + B]), 1));
                                        if ( strTemp == "1" )
                                        {
                                            GameTileset = App.Tileset_Arizona;
                                            DatasetFound = true;
                                        }
                                        else if ( strTemp == "2" )
                                        {
                                            GameTileset = App.Tileset_Urban;
                                            DatasetFound = true;
                                        }
                                        else if ( strTemp == "3" )
                                        {
                                            GameTileset = App.Tileset_Rockies;
                                            DatasetFound = true;
                                        }
                                        break;
                                    }
                                    else if ( Strings.LCase(Strings.Left(Convert.ToString(LineData[A + B]), 5)) == "level" )
                                    {
                                        break;
                                    }
                                    B++;
                                }
                                if ( DatasetFound )
                                {
                                    clsWZMapEntry NewMap = new clsWZMapEntry();
                                    NewMap.Name = GameName;
                                    NewMap.Tileset = GameTileset;
                                    Maps.Add(NewMap);
                                }
                            }
                        }
                    }
                }
            } while ( true );
            ZipStream.Close();

            string MapLoadName = "";

            //prompt user for which of the entries to load
            if ( Maps.Count < 1 )
            {
                ReturnResult.ProblemAdd("No maps found in file.");
                return ReturnResult;
            }
            else if ( Maps.Count == 1 )
            {
                MapLoadName = Convert.ToString(Maps[0].Name);
                Tileset = Maps[0].Tileset;
            }
            else
            {
                frmWZLoad.clsOutput SelectToLoadResult = new frmWZLoad.clsOutput();
                string[] Names = new string[Maps.Count];
                for ( A = 0; A <= Maps.Count - 1; A++ )
                {
                    Names[A] = Convert.ToString(Maps[A].Name);
                }
                frmWZLoad SelectToLoadForm = new frmWZLoad(Names, SelectToLoadResult,
                    "Select a map from " + Convert.ToString(new App.sSplitPath(Path).FileTitle));
                SelectToLoadForm.ShowDialog();
                if ( SelectToLoadResult.Result < 0 )
                {
                    ReturnResult.ProblemAdd("No map selected.");
                    return ReturnResult;
                }
                MapLoadName = Convert.ToString(Maps[SelectToLoadResult.Result].Name);
                Tileset = Maps[SelectToLoadResult.Result].Tileset;
            }

            TileType_Reset();
            SetPainterToDefaults();

            ZipSplitPath GameSplitPath = new ZipSplitPath(MapLoadName);
            string GameFilesPath = GameSplitPath.FilePath + GameSplitPath.FileTitleWithoutExtension + "/";

            ZipStreamEntry ZipSearchResult = default(ZipStreamEntry);

            ZipSearchResult = IOUtil.FindZipEntryFromPath(Path, MapLoadName);
            if ( ZipSearchResult == null )
            {
                ReturnResult.ProblemAdd("Game file not found.");
                return ReturnResult;
            }
            else
            {
                BinaryReader Map_Reader = new BinaryReader(ZipSearchResult.Stream);
                SubResult = Read_WZ_gam(Map_Reader);
                Map_Reader.Close();

                if ( !SubResult.Success )
                {
                    ReturnResult.ProblemAdd(SubResult.Problem);
                    return ReturnResult;
                }
            }

            ZipSearchResult = IOUtil.FindZipEntryFromPath(Path, GameFilesPath + "game.map");
            if ( ZipSearchResult == null )
            {
                ReturnResult.ProblemAdd("game.map file not found");
                return ReturnResult;
            }
            else
            {
                BinaryReader Map_Reader = new BinaryReader(ZipSearchResult.Stream);
                SubResult = Read_WZ_map(Map_Reader);
                Map_Reader.Close();

                if ( !SubResult.Success )
                {
                    ReturnResult.ProblemAdd(SubResult.Problem);
                    return ReturnResult;
                }
            }

            SimpleClassList<clsWZBJOUnit> BJOUnits = new SimpleClassList<clsWZBJOUnit>();

            IniFeatures INIFeatures = null;

            ZipSearchResult = IOUtil.FindZipEntryFromPath(Path, GameFilesPath + "feature.ini");
            if ( ZipSearchResult == null )
            {
            }
            else
            {
                clsResult Result = new clsResult("feature.ini");
                IniReader FeaturesINI = new IniReader();
                StreamReader FeaturesINI_Reader = new StreamReader(ZipSearchResult.Stream);
                Result.Take(FeaturesINI.ReadFile(FeaturesINI_Reader));
                FeaturesINI_Reader.Close();
                INIFeatures = new IniFeatures(FeaturesINI.Sections.Count);
                Result.Take(FeaturesINI.Translate(INIFeatures));
                ReturnResult.Add(Result);
            }

            if ( INIFeatures == null )
            {
                clsResult Result = new clsResult("feat.bjo");
                ZipSearchResult = IOUtil.FindZipEntryFromPath(Path, GameFilesPath + "feat.bjo");
                if ( ZipSearchResult == null )
                {
                    Result.WarningAdd("file not found");
                }
                else
                {
                    BinaryReader Features_Reader = new BinaryReader(ZipSearchResult.Stream);
                    SubResult = Read_WZ_Features(Features_Reader, BJOUnits);
                    Features_Reader.Close();
                    if ( !SubResult.Success )
                    {
                        Result.WarningAdd(SubResult.Problem);
                    }
                }
                ReturnResult.Add(Result);
            }

            if ( true )
            {
                clsResult Result = new clsResult("ttypes.ttp");
                ZipSearchResult = IOUtil.FindZipEntryFromPath(Path, GameFilesPath + "ttypes.ttp");
                if ( ZipSearchResult == null )
                {
                    Result.WarningAdd("file not found");
                }
                else
                {
                    BinaryReader TileTypes_Reader = new BinaryReader(ZipSearchResult.Stream);
                    SubResult = Read_WZ_TileTypes(TileTypes_Reader);
                    TileTypes_Reader.Close();
                    if ( !SubResult.Success )
                    {
                        Result.WarningAdd(SubResult.Problem);
                    }
                }
                ReturnResult.Add(Result);
            }

            IniStructures INIStructures = null;

            ZipSearchResult = IOUtil.FindZipEntryFromPath(Path, GameFilesPath + "struct.ini");
            if ( ZipSearchResult == null )
            {
            }
            else
            {
                clsResult Result = new clsResult("struct.ini");
                IniReader StructuresINI = new IniReader();
                StreamReader StructuresINI_Reader = new StreamReader(ZipSearchResult.Stream);
                Result.Take(StructuresINI.ReadFile(StructuresINI_Reader));
                StructuresINI_Reader.Close();
                INIStructures = new IniStructures(StructuresINI.Sections.Count, this);
                Result.Take(StructuresINI.Translate(INIStructures));
                ReturnResult.Add(Result);
            }

            if ( INIStructures == null )
            {
                clsResult Result = new clsResult("struct.bjo");
                ZipSearchResult = IOUtil.FindZipEntryFromPath(Path, GameFilesPath + "struct.bjo");
                if ( ZipSearchResult == null )
                {
                    Result.WarningAdd("file not found");
                }
                else
                {
                    BinaryReader Structures_Reader = new BinaryReader(ZipSearchResult.Stream);
                    SubResult = Read_WZ_Structures(Structures_Reader, BJOUnits);
                    Structures_Reader.Close();
                    if ( !SubResult.Success )
                    {
                        Result.WarningAdd(SubResult.Problem);
                    }
                }
                ReturnResult.Add(Result);
            }

            IniDroids INIDroids = null;

            ZipSearchResult = IOUtil.FindZipEntryFromPath(Path, GameFilesPath + "droid.ini");
            if ( ZipSearchResult == null )
            {
            }
            else
            {
                clsResult Result = new clsResult("droid.ini");
                IniReader DroidsINI = new IniReader();
                StreamReader DroidsINI_Reader = new StreamReader(ZipSearchResult.Stream);
                Result.Take(DroidsINI.ReadFile(DroidsINI_Reader));
                DroidsINI_Reader.Close();
                INIDroids = new IniDroids(DroidsINI.Sections.Count, this);
                Result.Take(DroidsINI.Translate(INIDroids));
                ReturnResult.Add(Result);
            }

            if ( INIDroids == null )
            {
                clsResult Result = new clsResult("dinit.bjo");
                ZipSearchResult = IOUtil.FindZipEntryFromPath(Path, GameFilesPath + "dinit.bjo");
                if ( ZipSearchResult == null )
                {
                    Result.WarningAdd("file not found");
                }
                else
                {
                    BinaryReader Droids_Reader = new BinaryReader(ZipSearchResult.Stream);
                    SubResult = Read_WZ_Droids(Droids_Reader, BJOUnits);
                    Droids_Reader.Close();
                    if ( !SubResult.Success )
                    {
                        Result.WarningAdd(SubResult.Problem);
                    }
                }
                ReturnResult.Add(Result);
            }

            sCreateWZObjectsArgs CreateObjectsArgs = new sCreateWZObjectsArgs();
            CreateObjectsArgs.BJOUnits = BJOUnits;
            CreateObjectsArgs.INIStructures = INIStructures;
            CreateObjectsArgs.INIDroids = INIDroids;
            CreateObjectsArgs.INIFeatures = INIFeatures;
            ReturnResult.Add(CreateWZObjects(CreateObjectsArgs));

            //objects are modified by this and must already exist
            ZipSearchResult = IOUtil.FindZipEntryFromPath(Path, GameFilesPath + "labels.ini");
            if ( ZipSearchResult == null )
            {
            }
            else
            {
                clsResult Result = new clsResult("labels.ini");
                IniReader LabelsINI = new IniReader();
                StreamReader LabelsINI_Reader = new StreamReader(ZipSearchResult.Stream);
                Result.Take(LabelsINI.ReadFile(LabelsINI_Reader));
                LabelsINI_Reader.Close();
                Result.Take(Read_WZ_Labels(LabelsINI, false));
                ReturnResult.Add(Result);
            }

            return ReturnResult;
        }
Пример #17
0
        public clsResult Load_Game(string Path)
        {
            clsResult ReturnResult =
                new clsResult("Loading game file from " + Convert.ToString(ControlChars.Quote) + Path + Convert.ToString(ControlChars.Quote));
            App.sResult SubResult = new App.sResult();
            string Quote = ControlChars.Quote.ToString();

            Tileset = null;

            TileType_Reset();
            SetPainterToDefaults();

            App.sSplitPath GameSplitPath = new App.sSplitPath(Path);
            string GameFilesPath = GameSplitPath.FilePath + GameSplitPath.FileTitleWithoutExtension + Convert.ToString(App.PlatformPathSeparator);
            string MapDirectory = "";
            FileStream File = null;

            SubResult = IOUtil.TryOpenFileStream(Path, ref File);
            if ( !SubResult.Success )
            {
                ReturnResult.ProblemAdd("Game file not found: " + SubResult.Problem);
                return ReturnResult;
            }
            else
            {
                BinaryReader Map_Reader = new BinaryReader(File);
                SubResult = Read_WZ_gam(Map_Reader);
                Map_Reader.Close();

                if ( !SubResult.Success )
                {
                    ReturnResult.ProblemAdd(SubResult.Problem);
                    return ReturnResult;
                }
            }

            SubResult = IOUtil.TryOpenFileStream(GameFilesPath + "game.map", ref File);
            if ( !SubResult.Success )
            {
                MsgBoxResult PromptResult =
                    Interaction.MsgBox(
                        "game.map file not found at " + GameFilesPath + ControlChars.NewLine + "Do you want to select another directory to load the underlying map from?",
                        (MsgBoxStyle)(MsgBoxStyle.OkCancel | MsgBoxStyle.Question), null);
                if ( PromptResult != MsgBoxResult.Ok )
                {
                    ReturnResult.ProblemAdd("Aborted.");
                    return ReturnResult;
                }
                FolderBrowserDialog DirectorySelect = new FolderBrowserDialog();
                DirectorySelect.SelectedPath = GameFilesPath;
                if ( DirectorySelect.ShowDialog() != DialogResult.OK )
                {
                    ReturnResult.ProblemAdd("Aborted.");
                    return ReturnResult;
                }
                MapDirectory = DirectorySelect.SelectedPath + Convert.ToString(App.PlatformPathSeparator);

                SubResult = IOUtil.TryOpenFileStream(MapDirectory + "game.map", ref File);
                if ( !SubResult.Success )
                {
                    ReturnResult.ProblemAdd("game.map file not found: " + SubResult.Problem);
                    return ReturnResult;
                }
            }
            else
            {
                MapDirectory = GameFilesPath;
            }

            BinaryReader Map_ReaderB = new BinaryReader(File);
            SubResult = Read_WZ_map(Map_ReaderB);
            Map_ReaderB.Close();

            if ( !SubResult.Success )
            {
                ReturnResult.ProblemAdd(SubResult.Problem);
                return ReturnResult;
            }

            SimpleClassList<clsWZBJOUnit> BJOUnits = new SimpleClassList<clsWZBJOUnit>();

            IniFeatures INIFeatures = null;

            SubResult = IOUtil.TryOpenFileStream(GameFilesPath + "feature.ini", ref File);
            if ( !SubResult.Success )
            {
            }
            else
            {
                clsResult Result = new clsResult("feature.ini");
                IniReader FeaturesINI = new IniReader();
                StreamReader FeaturesINI_Reader = new StreamReader(File);
                Result.Take(FeaturesINI.ReadFile(FeaturesINI_Reader));
                FeaturesINI_Reader.Close();
                INIFeatures = new IniFeatures(FeaturesINI.Sections.Count);
                Result.Take(FeaturesINI.Translate(INIFeatures));
                ReturnResult.Add(Result);
            }

            if ( INIFeatures == null )
            {
                clsResult Result = new clsResult("feat.bjo");
                SubResult = IOUtil.TryOpenFileStream(GameFilesPath + "feat.bjo", ref File);
                if ( !SubResult.Success )
                {
                    Result.WarningAdd("file not found");
                }
                else
                {
                    BinaryReader Features_Reader = new BinaryReader(File);
                    SubResult = Read_WZ_Features(Features_Reader, BJOUnits);
                    Features_Reader.Close();
                    if ( !SubResult.Success )
                    {
                        Result.WarningAdd(SubResult.Problem);
                    }
                }
                ReturnResult.Add(Result);
            }

            if ( true )
            {
                clsResult Result = new clsResult("ttypes.ttp");
                SubResult = IOUtil.TryOpenFileStream(MapDirectory + "ttypes.ttp", ref File);
                if ( !SubResult.Success )
                {
                    Result.WarningAdd("file not found");
                }
                else
                {
                    BinaryReader TileTypes_Reader = new BinaryReader(File);
                    SubResult = Read_WZ_TileTypes(TileTypes_Reader);
                    TileTypes_Reader.Close();
                    if ( !SubResult.Success )
                    {
                        Result.WarningAdd(SubResult.Problem);
                    }
                }
                ReturnResult.Add(Result);
            }

            IniStructures INIStructures = null;

            SubResult = IOUtil.TryOpenFileStream(GameFilesPath + "struct.ini", ref File);
            if ( !SubResult.Success )
            {
            }
            else
            {
                clsResult Result = new clsResult("struct.ini");
                IniReader StructuresINI = new IniReader();
                StreamReader StructuresINI_Reader = new StreamReader(File);
                Result.Take(StructuresINI.ReadFile(StructuresINI_Reader));
                StructuresINI_Reader.Close();
                INIStructures = new IniStructures(StructuresINI.Sections.Count, this);
                Result.Take(StructuresINI.Translate(INIStructures));
                ReturnResult.Add(Result);
            }

            if ( INIStructures == null )
            {
                clsResult Result = new clsResult("struct.bjo");
                SubResult = IOUtil.TryOpenFileStream(GameFilesPath + "struct.bjo", ref File);
                if ( !SubResult.Success )
                {
                    Result.WarningAdd("struct.bjo file not found.");
                }
                else
                {
                    BinaryReader Structures_Reader = new BinaryReader(File);
                    SubResult = Read_WZ_Structures(Structures_Reader, BJOUnits);
                    Structures_Reader.Close();
                    if ( !SubResult.Success )
                    {
                        Result.WarningAdd(SubResult.Problem);
                    }
                }
                ReturnResult.Add(Result);
            }

            IniDroids INIDroids = null;

            SubResult = IOUtil.TryOpenFileStream(GameFilesPath + "droid.ini", ref File);
            if ( !SubResult.Success )
            {
            }
            else
            {
                clsResult Result = new clsResult("droid.ini");
                IniReader DroidsINI = new IniReader();
                StreamReader DroidsINI_Reader = new StreamReader(File);
                Result.Take(DroidsINI.ReadFile(DroidsINI_Reader));
                DroidsINI_Reader.Close();
                INIDroids = new IniDroids(DroidsINI.Sections.Count, this);
                Result.Take(DroidsINI.Translate(INIDroids));
                ReturnResult.Add(Result);
            }

            if ( INIStructures == null )
            {
                clsResult Result = new clsResult("dinit.bjo");
                SubResult = IOUtil.TryOpenFileStream(GameFilesPath + "dinit.bjo", ref File);
                if ( !SubResult.Success )
                {
                    Result.WarningAdd("dinit.bjo file not found.");
                }
                else
                {
                    BinaryReader Droids_Reader = new BinaryReader(File);
                    SubResult = Read_WZ_Droids(Droids_Reader, BJOUnits);
                    Droids_Reader.Close();
                    if ( !SubResult.Success )
                    {
                        Result.WarningAdd(SubResult.Problem);
                    }
                }
                ReturnResult.Add(Result);
            }

            sCreateWZObjectsArgs CreateObjectsArgs = new sCreateWZObjectsArgs();
            CreateObjectsArgs.BJOUnits = BJOUnits;
            CreateObjectsArgs.INIStructures = INIStructures;
            CreateObjectsArgs.INIDroids = INIDroids;
            CreateObjectsArgs.INIFeatures = INIFeatures;
            ReturnResult.Add(CreateWZObjects(CreateObjectsArgs));

            //map objects are modified by this and must already exist
            SubResult = IOUtil.TryOpenFileStream(GameFilesPath + "labels.ini", ref File);
            if ( !SubResult.Success )
            {
            }
            else
            {
                clsResult Result = new clsResult("labels.ini");
                IniReader LabelsINI = new IniReader();
                StreamReader LabelsINI_Reader = new StreamReader(File);
                Result.Take(LabelsINI.ReadFile(LabelsINI_Reader));
                LabelsINI_Reader.Close();
                Result.Take(Read_WZ_Labels(LabelsINI, false));
                ReturnResult.Add(Result);
            }

            return ReturnResult;
        }
Пример #18
0
        private App.sResult Read_WZ_TileTypes(BinaryReader File)
        {
            App.sResult ReturnResult = new App.sResult();
            ReturnResult.Success = false;
            ReturnResult.Problem = "";

            string strTemp = null;
            UInt32 Version = 0;
            UInt32 uintTemp = 0;
            UInt16 ushortTemp = 0;
            int A = 0;

            try
            {
                strTemp = IOUtil.ReadOldTextOfLength(File, 4);
                if ( strTemp != "ttyp" )
                {
                    ReturnResult.Problem = "Unknown ttypes.ttp identifier.";
                    return ReturnResult;
                }

                Version = File.ReadUInt32();
                if ( Version != 8U )
                {
                    //Load_WZ.Problem = "Unknown ttypes.ttp version."
                    //Exit Function
                    if (
                        Interaction.MsgBox("ttypes.ttp version is unknown. Continue?", (MsgBoxStyle)(MsgBoxStyle.OkCancel | MsgBoxStyle.Question),
                            null) != MsgBoxResult.Ok )
                    {
                        ReturnResult.Problem = "Aborted.";
                        return ReturnResult;
                    }
                }

                uintTemp = File.ReadUInt32();

                if ( Tileset != null )
                {
                    for ( A = 0; A <= Math.Min(Convert.ToInt32(uintTemp), Tileset.TileCount) - 1; A++ )
                    {
                        ushortTemp = File.ReadUInt16();
                        if ( ushortTemp > 11U )
                        {
                            ReturnResult.Problem = "Unknown tile type.";
                            return ReturnResult;
                        }
                        Tile_TypeNum[A] = (byte)ushortTemp;
                    }
                }
            }
            catch ( Exception ex )
            {
                ReturnResult.Problem = ex.Message;
                return ReturnResult;
            }

            ReturnResult.Success = true;
            return ReturnResult;
        }
Пример #19
0
        public App.sResult Write_FME(string Path, bool Overwrite, byte ScavengerPlayerNum)
        {
            App.sResult ReturnResult = new App.sResult();
            ReturnResult.Success = false;
            ReturnResult.Problem = "";

            if ( System.IO.File.Exists(Path) )
            {
                if ( Overwrite )
                {
                    System.IO.File.Delete(Path);
                }
                else
                {
                    ReturnResult.Problem = "The selected file already exists.";
                    return ReturnResult;
                }
            }

            BinaryWriter File = null;

            try
            {
                File = new BinaryWriter(new FileStream(Path, FileMode.CreateNew));

                int X = 0;
                int Z = 0;

                File.Write(6U);

                if ( Tileset == null )
                {
                    File.Write((byte)0);
                }
                else if ( Tileset == App.Tileset_Arizona )
                {
                    File.Write((byte)1);
                }
                else if ( Tileset == App.Tileset_Urban )
                {
                    File.Write((byte)2);
                }
                else if ( Tileset == App.Tileset_Rockies )
                {
                    File.Write((byte)3);
                }

                File.Write(Convert.ToBoolean((ushort)Terrain.TileSize.X));
                File.Write(Convert.ToBoolean((ushort)Terrain.TileSize.Y));

                byte TileAttributes = 0;
                byte DownSideData = 0;

                for ( Z = 0; Z <= Terrain.TileSize.Y; Z++ )
                {
                    for ( X = 0; X <= Terrain.TileSize.X; X++ )
                    {
                        File.Write(Terrain.Vertices[X, Z].Height);
                        if ( Terrain.Vertices[X, Z].Terrain == null )
                        {
                            File.Write((byte)0);
                        }
                        else if ( Terrain.Vertices[X, Z].Terrain.Num < 0 )
                        {
                            ReturnResult.Problem = "Terrain number out of range.";
                            return ReturnResult;
                        }
                        else
                        {
                            File.Write(Convert.ToByte(Terrain.Vertices[X, Z].Terrain.Num + 1));
                        }
                    }
                }
                for ( Z = 0; Z <= Terrain.TileSize.Y - 1; Z++ )
                {
                    for ( X = 0; X <= Terrain.TileSize.X - 1; X++ )
                    {
                        File.Write(Convert.ToByte(Terrain.Tiles[X, Z].Texture.TextureNum + 1));

                        TileAttributes = (byte)0;
                        if ( Terrain.Tiles[X, Z].Terrain_IsCliff )
                        {
                            TileAttributes += (byte)128;
                        }
                        if ( Terrain.Tiles[X, Z].Texture.Orientation.SwitchedAxes )
                        {
                            TileAttributes += (byte)64;
                        }
                        if ( Terrain.Tiles[X, Z].Texture.Orientation.ResultXFlip )
                        {
                            TileAttributes += (byte)32;
                        }
                        if ( Terrain.Tiles[X, Z].Texture.Orientation.ResultYFlip )
                        {
                            TileAttributes += (byte)16;
                        }
                        //8 is free
                        if ( Terrain.Tiles[X, Z].Tri )
                        {
                            TileAttributes += (byte)4;
                            if ( Terrain.Tiles[X, Z].TriTopLeftIsCliff )
                            {
                                TileAttributes += (byte)2;
                            }
                            if ( Terrain.Tiles[X, Z].TriBottomRightIsCliff )
                            {
                                TileAttributes += (byte)1;
                            }
                        }
                        else
                        {
                            if ( Terrain.Tiles[X, Z].TriBottomLeftIsCliff )
                            {
                                TileAttributes += (byte)2;
                            }
                            if ( Terrain.Tiles[X, Z].TriTopRightIsCliff )
                            {
                                TileAttributes += (byte)1;
                            }
                        }
                        File.Write(TileAttributes);
                        if ( TileUtil.IdenticalTileDirections(Terrain.Tiles[X, Z].DownSide, TileUtil.Top) )
                        {
                            DownSideData = (byte)1;
                        }
                        else if ( TileUtil.IdenticalTileDirections(Terrain.Tiles[X, Z].DownSide, TileUtil.Left) )
                        {
                            DownSideData = (byte)2;
                        }
                        else if ( TileUtil.IdenticalTileDirections(Terrain.Tiles[X, Z].DownSide, TileUtil.Right) )
                        {
                            DownSideData = (byte)3;
                        }
                        else if ( TileUtil.IdenticalTileDirections(Terrain.Tiles[X, Z].DownSide, TileUtil.Bottom) )
                        {
                            DownSideData = (byte)4;
                        }
                        else
                        {
                            DownSideData = (byte)0;
                        }
                        File.Write(DownSideData);
                    }
                }
                for ( Z = 0; Z <= Terrain.TileSize.Y; Z++ )
                {
                    for ( X = 0; X <= Terrain.TileSize.X - 1; X++ )
                    {
                        if ( Terrain.SideH[X, Z].Road == null )
                        {
                            File.Write((byte)0);
                        }
                        else if ( Terrain.SideH[X, Z].Road.Num < 0 )
                        {
                            ReturnResult.Problem = "Road number out of range.";
                            return ReturnResult;
                        }
                        else
                        {
                            File.Write(Convert.ToByte(Terrain.SideH[X, Z].Road.Num + 1));
                        }
                    }
                }
                for ( Z = 0; Z <= Terrain.TileSize.Y - 1; Z++ )
                {
                    for ( X = 0; X <= Terrain.TileSize.X; X++ )
                    {
                        if ( Terrain.SideV[X, Z].Road == null )
                        {
                            File.Write((byte)0);
                        }
                        else if ( Terrain.SideV[X, Z].Road.Num < 0 )
                        {
                            ReturnResult.Problem = "Road number out of range.";
                            return ReturnResult;
                        }
                        else
                        {
                            File.Write(Convert.ToByte(Terrain.SideV[X, Z].Road.Num + 1));
                        }
                    }
                }

                clsUnit[] OutputUnits = new clsUnit[Units.Count];
                string[] OutputUnitCode = new string[Units.Count];
                int OutputUnitCount = 0;
                clsUnit Unit = default(clsUnit);
                int A = 0;

                foreach ( clsUnit tempLoopVar_Unit in Units )
                {
                    Unit = tempLoopVar_Unit;
                    if ( Unit.Type.GetCode(ref OutputUnitCode[OutputUnitCount]) )
                    {
                        OutputUnits[OutputUnitCount] = Unit;
                        OutputUnitCount++;
                    }
                }

                File.Write(Convert.ToBoolean((uint)OutputUnitCount));

                for ( A = 0; A <= OutputUnitCount - 1; A++ )
                {
                    Unit = OutputUnits[A];
                    IOUtil.WriteTextOfLength(File, 40, OutputUnitCode[A]);
                    switch ( Unit.Type.Type )
                    {
                        case clsUnitType.enumType.Feature:
                            File.Write((byte)0);
                            break;
                        case clsUnitType.enumType.PlayerStructure:
                            File.Write((byte)1);
                            break;
                        case clsUnitType.enumType.PlayerDroid:
                            File.Write((byte)2);
                            break;
                    }
                    File.Write(Unit.ID);
                    File.Write(Unit.SavePriority);
                    File.Write(Convert.ToBoolean((uint)Unit.Pos.Horizontal.X));
                    File.Write(Convert.ToBoolean((uint)Unit.Pos.Horizontal.Y));
                    File.Write(Convert.ToBoolean((uint)Unit.Pos.Altitude));
                    File.Write(Convert.ToBoolean((ushort)Unit.Rotation));
                    IOUtil.WriteText(File, true, "");
                    if ( Unit.UnitGroup == ScavengerUnitGroup )
                    {
                        File.Write(ScavengerPlayerNum);
                    }
                    else
                    {
                        File.Write((byte)Unit.UnitGroup.WZ_StartPos);
                    }
                }

                File.Write(Convert.ToBoolean((uint)Gateways.Count));

                clsGateway Gateway = default(clsGateway);
                foreach ( clsGateway tempLoopVar_Gateway in Gateways )
                {
                    Gateway = tempLoopVar_Gateway;
                    File.Write(Convert.ToBoolean((ushort)Gateway.PosA.X));
                    File.Write(Convert.ToBoolean((ushort)Gateway.PosA.Y));
                    File.Write(Convert.ToBoolean((ushort)Gateway.PosB.X));
                    File.Write(Convert.ToBoolean((ushort)Gateway.PosB.Y));
                }

                if ( Tileset != null )
                {
                    for ( A = 0; A <= Tileset.TileCount - 1; A++ )
                    {
                        File.Write(Tile_TypeNum[A]);
                    }
                }

                //scroll limits
                File.Write(InterfaceOptions.ScrollMin.X);
                File.Write(InterfaceOptions.ScrollMin.Y);
                File.Write(InterfaceOptions.ScrollMax.X);
                File.Write(InterfaceOptions.ScrollMax.Y);

                //other compile info
                IOUtil.WriteText(File, true, InterfaceOptions.CompileName);
                File.Write((byte)0); //multiplayer/campaign. 0 = neither
                IOUtil.WriteText(File, true, InterfaceOptions.CompileMultiPlayers);
                File.Write(InterfaceOptions.CompileMultiXPlayers);
                IOUtil.WriteText(File, true, InterfaceOptions.CompileMultiAuthor);
                IOUtil.WriteText(File, true, InterfaceOptions.CompileMultiLicense);
                IOUtil.WriteText(File, true, "0"); //game time
                int intTemp = InterfaceOptions.CampaignGameType;
                File.Write(intTemp);
            }
            catch ( Exception ex )
            {
                ReturnResult.Problem = ex.Message;
                return ReturnResult;
            }

            if ( File != null )
            {
                File.Close();
            }

            ReturnResult.Success = true;
            return ReturnResult;
        }
Пример #20
0
        private App.sResult Default_TileTypes_Read(BinaryReader File)
        {
            App.sResult ReturnResult = new App.sResult();
            ReturnResult.Success = false;
            ReturnResult.Problem = "";

            UInt32 uintTemp = 0;
            int A = 0;
            UInt16 ushortTemp = 0;
            string strTemp = "";

            try
            {
                strTemp = IOUtil.ReadOldTextOfLength(File, 4);
                if ( strTemp != "ttyp" )
                {
                    ReturnResult.Problem = "Bad identifier.";
                    return ReturnResult;
                }

                uintTemp = File.ReadUInt32();
                if ( !(uintTemp == 8U) )
                {
                    ReturnResult.Problem = "Unknown version.";
                    return ReturnResult;
                }

                uintTemp = File.ReadUInt32();
                TileCount = Convert.ToInt32(uintTemp);
                Tiles = new sTile[TileCount];

                for ( A = 0; A <= Math.Min(Convert.ToInt32(uintTemp), TileCount) - 1; A++ )
                {
                    ushortTemp = File.ReadUInt16();
                    if ( ushortTemp > App.TileTypes.Count )
                    {
                        ReturnResult.Problem = "Unknown tile type.";
                        return ReturnResult;
                    }
                    Tiles[A].Default_Type = (byte)ushortTemp;
                }
            }
            catch ( Exception ex )
            {
                ReturnResult.Problem = ex.Message;
                return ReturnResult;
            }

            ReturnResult.Success = true;
            return ReturnResult;
        }
Пример #21
0
        private App.sResult Read_WZ_map(BinaryReader File)
        {
            App.sResult ReturnResult = new App.sResult();
            ReturnResult.Success = false;
            ReturnResult.Problem = "";

            string strTemp = null;
            UInt32 Version = 0;
            UInt32 MapWidth = 0;
            UInt32 MapHeight = 0;
            UInt32 uintTemp = 0;
            byte Flip = 0;
            bool FlipX = default(bool);
            bool FlipZ = default(bool);
            byte Rotate = 0;
            byte TextureNum = 0;
            int A = 0;
            int X = 0;
            int Y = 0;
            sXY_int PosA = new sXY_int();
            sXY_int PosB = new sXY_int();

            try
            {
                strTemp = IOUtil.ReadOldTextOfLength(File, 4);
                if ( strTemp != "map " )
                {
                    ReturnResult.Problem = "Unknown game.map identifier.";
                    return ReturnResult;
                }

                Version = File.ReadUInt32();
                if ( Version != 10U )
                {
                    if (
                        Interaction.MsgBox("game.map version is unknown. Continue?", (MsgBoxStyle)(MsgBoxStyle.OkCancel | MsgBoxStyle.Question),
                            null) != MsgBoxResult.Ok )
                    {
                        ReturnResult.Problem = "Aborted.";
                        return ReturnResult;
                    }
                }
                MapWidth = File.ReadUInt32();
                MapHeight = File.ReadUInt32();
                if ( MapWidth < 1U || MapWidth > Constants.MapMaxSize || MapHeight < 1U || MapHeight > Constants.MapMaxSize )
                {
                    ReturnResult.Problem = "Map size out of range.";
                    return ReturnResult;
                }

                TerrainBlank(new sXY_int(Convert.ToInt32(MapWidth), Convert.ToInt32(MapHeight)));

                for ( Y = 0; Y <= Terrain.TileSize.Y - 1; Y++ )
                {
                    for ( X = 0; X <= Terrain.TileSize.X - 1; X++ )
                    {
                        TextureNum = File.ReadByte();
                        Terrain.Tiles[X, Y].Texture.TextureNum = TextureNum;
                        Flip = File.ReadByte();
                        Terrain.Vertices[X, Y].Height = File.ReadByte();
                        //get flipx
                        A = (int)(Conversion.Int(Flip / 128.0D));
                        Flip -= (byte)(A * 128);
                        FlipX = A == 1;
                        //get flipy
                        A = (int)(Conversion.Int(Flip / 64.0D));
                        Flip -= (byte)(A * 64);
                        FlipZ = A == 1;
                        //get rotation
                        A = (int)(Conversion.Int(Flip / 16.0D));
                        Flip -= (byte)(A * 16);
                        Rotate = (byte)A;
                        TileUtil.OldOrientation_To_TileOrientation(Rotate, FlipX, FlipZ, Terrain.Tiles[X, Y].Texture.Orientation);
                        //get tri direction
                        A = (int)(Conversion.Int(Flip / 8.0D));
                        Flip -= (byte)(A * 8);
                        Terrain.Tiles[X, Y].Tri = A == 1;
                    }
                }

                if ( Version != 2U )
                {
                    uintTemp = File.ReadUInt32();
                    if ( uintTemp != 1 )
                    {
                        ReturnResult.Problem = "Bad gateway version number.";
                        return ReturnResult;
                    }

                    uintTemp = File.ReadUInt32();

                    for ( A = 0; A <= (Convert.ToInt32(uintTemp)) - 1; A++ )
                    {
                        PosA.X = File.ReadByte();
                        PosA.Y = File.ReadByte();
                        PosB.X = File.ReadByte();
                        PosB.Y = File.ReadByte();
                        if ( GatewayCreate(PosA, PosB) == null )
                        {
                            ReturnResult.Problem = "Gateway placement error.";
                            return ReturnResult;
                        }
                    }
                }
            }
            catch ( Exception ex )
            {
                ReturnResult.Problem = ex.Message;
                return ReturnResult;
            }

            ReturnResult.Success = true;
            return ReturnResult;
        }
Пример #22
0
        public App.sResult ScriptLabelIsValid(string Text)
        {
            App.sResult ReturnResult = new App.sResult();
            ReturnResult.Success = false;
            ReturnResult.Problem = "";

            if ( Text == null )
            {
                ReturnResult.Problem = "Label cannot be nothing.";
                return ReturnResult;
            }

            string LCaseText = Text.ToLower();

            if ( LCaseText.Length < 1 )
            {
                ReturnResult.Problem = "Label cannot be nothing.";
                return ReturnResult;
            }

            char CurrentChar = (char)0;
            bool Invalid = default(bool);

            Invalid = false;
            foreach ( char tempLoopVar_CurrentChar in LCaseText )
            {
                CurrentChar = tempLoopVar_CurrentChar;
                if ( !((CurrentChar >= 'a' && CurrentChar <= 'z') || (CurrentChar >= '0' && CurrentChar <= '9') || CurrentChar == '_') )
                {
                    Invalid = true;
                    break;
                }
            }
            if ( Invalid )
            {
                ReturnResult.Problem = "Label contains invalid characters. Use only letters, numbers or underscores.";
                return ReturnResult;
            }

            clsUnit Unit = default(clsUnit);

            foreach ( clsUnit tempLoopVar_Unit in Units )
            {
                Unit = tempLoopVar_Unit;
                if ( Unit.Label != null )
                {
                    if ( LCaseText == Unit.Label.ToLower() )
                    {
                        ReturnResult.Problem = "Label text is already in use.";
                        return ReturnResult;
                    }
                }
            }

            clsScriptPosition ScriptPosition = default(clsScriptPosition);

            foreach ( clsScriptPosition tempLoopVar_ScriptPosition in ScriptPositions )
            {
                ScriptPosition = tempLoopVar_ScriptPosition;
                if ( LCaseText == ScriptPosition.Label.ToLower() )
                {
                    ReturnResult.Problem = "Label text is already in use.";
                    return ReturnResult;
                }
            }

            clsScriptArea ScriptArea = default(clsScriptArea);

            foreach ( clsScriptArea tempLoopVar_ScriptArea in ScriptAreas )
            {
                ScriptArea = tempLoopVar_ScriptArea;
                if ( LCaseText == ScriptArea.Label.ToLower() )
                {
                    ReturnResult.Problem = "Label text is already in use.";
                    return ReturnResult;
                }
            }

            ReturnResult.Success = true;
            return ReturnResult;
        }
Пример #23
0
        public clsResult GenerateMipMaps(string SlashPath, string strTile, BitmapGLTexture BitmapTextureArgs, int TileNum)
        {
            clsResult ReturnResult = new clsResult("Generating mipmaps");
            string GraphicPath = "";
            int PixX = 0;
            int PixY = 0;
            Color PixelColorA = new Color();
            Color PixelColorB = new Color();
            Color PixelColorC = new Color();
            Color PixelColorD = new Color();
            int X1 = 0;
            int Y1 = 0;
            int X2 = 0;
            int Y2 = 0;
            int Red = 0;
            int Green = 0;
            int Blue = 0;
            Bitmap Bitmap8 = default(Bitmap);
            Bitmap Bitmap4 = default(Bitmap);
            Bitmap Bitmap2 = default(Bitmap);
            Bitmap Bitmap1 = default(Bitmap);
            Bitmap Bitmap = null;
            App.sResult Result = new App.sResult();

            //-------- 64 --------

            GraphicPath = SlashPath + Name + "-64" + Convert.ToString(App.PlatformPathSeparator) + strTile;

            Result = BitmapUtil.LoadBitmap(GraphicPath, ref Bitmap);
            if ( !Result.Success )
            {
                ReturnResult.WarningAdd("Unable to load tile graphic: " + Result.Problem);
                return ReturnResult;
            }

            if ( Bitmap.Width != 64 | Bitmap.Height != 64 )
            {
                ReturnResult.WarningAdd("Tile graphic " + GraphicPath + " from tileset " + Name + " is not 64x64.");
                return ReturnResult;
            }

            BitmapTextureArgs.Texture = Bitmap;
            BitmapTextureArgs.MipMapLevel = 1;
            BitmapTextureArgs.Perform();

            //-------- 32 --------

            GraphicPath = SlashPath + Name + "-32" + Convert.ToString(App.PlatformPathSeparator) + strTile;

            Result = BitmapUtil.LoadBitmap(GraphicPath, ref Bitmap);
            if ( !Result.Success )
            {
                ReturnResult.WarningAdd("Unable to load tile graphic: " + Result.Problem);
                return ReturnResult;
            }

            if ( Bitmap.Width != 32 | Bitmap.Height != 32 )
            {
                ReturnResult.WarningAdd("Tile graphic " + GraphicPath + " from tileset " + Name + " is not 32x32.");
                return ReturnResult;
            }

            BitmapTextureArgs.Texture = Bitmap;
            BitmapTextureArgs.MipMapLevel = 2;
            BitmapTextureArgs.Perform();

            //-------- 16 --------

            GraphicPath = SlashPath + Name + "-16" + Convert.ToString(App.PlatformPathSeparator) + strTile;

            Result = BitmapUtil.LoadBitmap(GraphicPath, ref Bitmap);
            if ( !Result.Success )
            {
                ReturnResult.WarningAdd("Unable to load tile graphic: " + Result.Problem);
                return ReturnResult;
            }

            if ( Bitmap.Width != 16 | Bitmap.Height != 16 )
            {
                ReturnResult.WarningAdd("Tile graphic " + GraphicPath + " from tileset " + Name + " is not 16x16.");
                return ReturnResult;
            }

            BitmapTextureArgs.Texture = Bitmap;
            BitmapTextureArgs.MipMapLevel = 3;
            BitmapTextureArgs.Perform();

            //-------- 8 --------

            Bitmap8 = new Bitmap(8, 8, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            for ( PixY = 0; PixY <= 7; PixY++ )
            {
                Y1 = PixY * 2;
                Y2 = Y1 + 1;
                for ( PixX = 0; PixX <= 7; PixX++ )
                {
                    X1 = PixX * 2;
                    X2 = X1 + 1;
                    PixelColorA = Bitmap.GetPixel(X1, Y1);
                    PixelColorB = Bitmap.GetPixel(X2, Y1);
                    PixelColorC = Bitmap.GetPixel(X1, Y2);
                    PixelColorD = Bitmap.GetPixel(X2, Y2);
                    Red = Convert.ToInt32(((PixelColorA.R) + PixelColorB.R + PixelColorC.R + PixelColorD.R) / 4.0F);
                    Green = Convert.ToInt32(((PixelColorA.G) + PixelColorB.G + PixelColorC.G + PixelColorD.G) / 4.0F);
                    Blue = Convert.ToInt32(((PixelColorA.B) + PixelColorB.B + PixelColorC.B + PixelColorD.B) / 4.0F);
                    Bitmap8.SetPixel(PixX, PixY, ColorTranslator.FromOle(ColorUtil.OSRGB(Red, Green, Blue)));
                }
            }

            BitmapTextureArgs.Texture = Bitmap8;
            BitmapTextureArgs.MipMapLevel = 4;
            BitmapTextureArgs.Perform();

            //-------- 4 --------

            Bitmap = Bitmap8;
            Bitmap4 = new Bitmap(4, 4, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            for ( PixY = 0; PixY <= 3; PixY++ )
            {
                Y1 = PixY * 2;
                Y2 = Y1 + 1;
                for ( PixX = 0; PixX <= 3; PixX++ )
                {
                    X1 = PixX * 2;
                    X2 = X1 + 1;
                    PixelColorA = Bitmap.GetPixel(X1, Y1);
                    PixelColorB = Bitmap.GetPixel(X2, Y1);
                    PixelColorC = Bitmap.GetPixel(X1, Y2);
                    PixelColorD = Bitmap.GetPixel(X2, Y2);
                    Red = Convert.ToInt32(((PixelColorA.R) + PixelColorB.R + PixelColorC.R + PixelColorD.R) / 4.0F);
                    Green = Convert.ToInt32(((PixelColorA.G) + PixelColorB.G + PixelColorC.G + PixelColorD.G) / 4.0F);
                    Blue = Convert.ToInt32(((PixelColorA.B) + PixelColorB.B + PixelColorC.B + PixelColorD.B) / 4.0F);
                    Bitmap4.SetPixel(PixX, PixY, ColorTranslator.FromOle(ColorUtil.OSRGB(Red, Green, Blue)));
                }
            }

            BitmapTextureArgs.Texture = Bitmap4;
            BitmapTextureArgs.MipMapLevel = 5;
            BitmapTextureArgs.Perform();

            //-------- 2 --------

            Bitmap = Bitmap4;
            Bitmap2 = new Bitmap(2, 2, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            for ( PixY = 0; PixY <= 1; PixY++ )
            {
                Y1 = PixY * 2;
                Y2 = Y1 + 1;
                for ( PixX = 0; PixX <= 1; PixX++ )
                {
                    X1 = PixX * 2;
                    X2 = X1 + 1;
                    PixelColorA = Bitmap.GetPixel(X1, Y1);
                    PixelColorB = Bitmap.GetPixel(X2, Y1);
                    PixelColorC = Bitmap.GetPixel(X1, Y2);
                    PixelColorD = Bitmap.GetPixel(X2, Y2);
                    Red = Convert.ToInt32(((PixelColorA.R) + PixelColorB.R + PixelColorC.R + PixelColorD.R) / 4.0F);
                    Green = Convert.ToInt32(((PixelColorA.G) + PixelColorB.G + PixelColorC.G + PixelColorD.G) / 4.0F);
                    Blue = Convert.ToInt32(((PixelColorA.B) + PixelColorB.B + PixelColorC.B + PixelColorD.B) / 4.0F);
                    Bitmap2.SetPixel(PixX, PixY, ColorTranslator.FromOle(ColorUtil.OSRGB(Red, Green, Blue)));
                }
            }

            BitmapTextureArgs.Texture = Bitmap2;
            BitmapTextureArgs.MipMapLevel = 6;
            BitmapTextureArgs.Perform();

            //-------- 1 --------

            Bitmap = Bitmap2;
            Bitmap1 = new Bitmap(1, 1, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            PixX = 0;
            PixY = 0;
            Y1 = PixY * 2;
            Y2 = Y1 + 1;
            X1 = PixX * 2;
            X2 = X1 + 1;
            PixelColorA = Bitmap.GetPixel(X1, Y1);
            PixelColorB = Bitmap.GetPixel(X2, Y1);
            PixelColorC = Bitmap.GetPixel(X1, Y2);
            PixelColorD = Bitmap.GetPixel(X2, Y2);
            Red = Convert.ToInt32(((PixelColorA.R) + PixelColorB.R + PixelColorC.R + PixelColorD.R) / 4.0F);
            Green = Convert.ToInt32(((PixelColorA.G) + PixelColorB.G + PixelColorC.G + PixelColorD.G) / 4.0F);
            Blue = Convert.ToInt32(((PixelColorA.B) + PixelColorB.B + PixelColorC.B + PixelColorD.B) / 4.0F);
            Bitmap1.SetPixel(PixX, PixY, ColorTranslator.FromOle(ColorUtil.OSRGB(Red, Green, Blue)));

            BitmapTextureArgs.Texture = Bitmap1;
            BitmapTextureArgs.MipMapLevel = 7;
            BitmapTextureArgs.Perform();

            return ReturnResult;
        }
Пример #24
0
        public App.sResult Load_Image(string Path)
        {
            App.sResult ReturnResult = new App.sResult();
            ReturnResult.Success = false;
            ReturnResult.Problem = "";

            Bitmap HeightmapBitmap = null;
            App.sResult Result = new App.sResult();

            Result = BitmapUtil.LoadBitmap(Path, ref HeightmapBitmap);
            if ( !Result.Success )
            {
                ReturnResult.Problem = Result.Problem;
                return ReturnResult;
            }

            Blank(HeightmapBitmap.Height, HeightmapBitmap.Width);
            int X = 0;
            int Y = 0;
            for ( Y = 0; Y <= HeightmapBitmap.Height - 1; Y++ )
            {
                for ( X = 0; X <= HeightmapBitmap.Width - 1; X++ )
                {
                    Color with_1 = HeightmapBitmap.GetPixel(X, Y);
                    HeightData.Height[Y, X] = Convert.ToInt32(((with_1.R) + with_1.G + with_1.B) / (3.0D * HeightScale));
                }
            }

            ReturnResult.Success = true;
            return ReturnResult;
        }
Пример #25
0
        public App.sResult GenerateGateways()
        {
            App.sResult ReturnResult = new App.sResult();
            ReturnResult.Success = false;
            ReturnResult.Problem = "";

            //must be done before units otherwise the units will be treated as gateway obstacles

            clsMap.clsTerrain Terrain = Map.Terrain;

            int X = 0;
            int SpaceCount = 0;
            int Y = 0;
            sPossibleGateway[] PossibleGateways = new sPossibleGateway[Terrain.TileSize.X * Terrain.TileSize.Y * 2];
            int PossibleGatewayCount = 0;

            for ( Y = 0; Y <= Terrain.TileSize.Y - 1; Y++ )
            {
                SpaceCount = 0;
                for ( X = 0; X <= Terrain.TileSize.X - 1; X++ )
                {
                    if ( GenerateTerrainTiles[X, Y].Node.GetClearance < 1 )
                    {
                    }
                    else if ( GenerateTerrainTiles[X, Y].Node.GetClearance == 1 )
                    {
                        if ( SpaceCount > 3 & SpaceCount <= 9 )
                        {
                            PossibleGateways[PossibleGatewayCount].StartPos.X = X - SpaceCount;
                            PossibleGateways[PossibleGatewayCount].StartPos.Y = Y;
                            PossibleGateways[PossibleGatewayCount].Length = SpaceCount + 1;
                            PossibleGateways[PossibleGatewayCount].IsVertical = false;
                            PossibleGateways[PossibleGatewayCount].MiddlePos.X = PossibleGateways[PossibleGatewayCount].StartPos.X * 128 +
                                                                                 PossibleGateways[PossibleGatewayCount].Length * 64;
                            PossibleGateways[PossibleGatewayCount].MiddlePos.Y = PossibleGateways[PossibleGatewayCount].StartPos.Y * 128;
                            PossibleGatewayCount++;
                        }
                        SpaceCount = 1;
                    }
                    else
                    {
                        SpaceCount++;
                    }
                }
            }
            for ( X = 0; X <= Terrain.TileSize.X - 1; X++ )
            {
                SpaceCount = 0;
                Y = 0;
                while ( Y < Terrain.TileSize.Y )
                {
                    if ( GenerateTerrainTiles[X, Y].Node.GetClearance < 1 )
                    {
                    }
                    else if ( GenerateTerrainTiles[X, Y].Node.GetClearance == 1 )
                    {
                        if ( SpaceCount >= 3 & SpaceCount <= 9 )
                        {
                            PossibleGateways[PossibleGatewayCount].StartPos.X = X;
                            PossibleGateways[PossibleGatewayCount].StartPos.Y = Y - SpaceCount;
                            PossibleGateways[PossibleGatewayCount].Length = SpaceCount + 1;
                            PossibleGateways[PossibleGatewayCount].IsVertical = true;
                            PossibleGateways[PossibleGatewayCount].MiddlePos.X = PossibleGateways[PossibleGatewayCount].StartPos.X * 128;
                            PossibleGateways[PossibleGatewayCount].MiddlePos.Y = PossibleGateways[PossibleGatewayCount].StartPos.Y * 128 +
                                                                                 PossibleGateways[PossibleGatewayCount].Length * 64;
                            PossibleGatewayCount++;
                        }
                        SpaceCount = 1;
                    }
                    else
                    {
                        SpaceCount++;
                    }
                    Y++;
                }
            }

            //add the best gateways

            int A = 0;
            float Value = 0;
            float BestValue = 0;
            int BestNum = 0;
            bool[,] TileIsGateway = new bool[Terrain.TileSize.X, Terrain.TileSize.Y];
            bool Valid = default(bool);
            sXY_int InvalidPos = new sXY_int();
            double InvalidDist = 0;

            while ( PossibleGatewayCount > 0 )
            {
                BestNum = -1;
                BestValue = float.MaxValue;
                for ( A = 0; A <= PossibleGatewayCount - 1; A++ )
                {
                    //Value = 0.0F
                    //For B = 0 To PossibleGatewayCount - 1
                    //    Value += GetDist(PossibleGateways(A).MiddlePos, PossibleGateways(B).MiddlePos)
                    //Next
                    Value = PossibleGateways[A].Length;
                    if ( Value < BestValue )
                    {
                        BestValue = Value;
                        BestNum = A;
                    }
                }
                if ( PossibleGateways[BestNum].IsVertical )
                {
                    Map.GatewayCreateStoreChange(PossibleGateways[BestNum].StartPos,
                        new sXY_int(PossibleGateways[BestNum].StartPos.X, PossibleGateways[BestNum].StartPos.Y + PossibleGateways[BestNum].Length - 1));
                    for ( Y = PossibleGateways[BestNum].StartPos.Y; Y <= PossibleGateways[BestNum].StartPos.Y + PossibleGateways[BestNum].Length - 1; Y++ )
                    {
                        TileIsGateway[PossibleGateways[BestNum].StartPos.X, Y] = true;
                    }
                }
                else
                {
                    Map.GatewayCreateStoreChange(PossibleGateways[BestNum].StartPos,
                        new sXY_int(PossibleGateways[BestNum].StartPos.X + PossibleGateways[BestNum].Length - 1, PossibleGateways[BestNum].StartPos.Y));
                    for ( X = PossibleGateways[BestNum].StartPos.X; X <= PossibleGateways[BestNum].StartPos.X + PossibleGateways[BestNum].Length - 1; X++ )
                    {
                        TileIsGateway[X, PossibleGateways[BestNum].StartPos.Y] = true;
                    }
                }
                InvalidPos = PossibleGateways[BestNum].MiddlePos;
                InvalidDist = PossibleGateways[BestNum].Length * 128;
                A = 0;
                while ( A < PossibleGatewayCount )
                {
                    Valid = true;
                    if ( PossibleGateways[A].IsVertical )
                    {
                        for ( Y = PossibleGateways[A].StartPos.Y; Y <= PossibleGateways[A].StartPos.Y + PossibleGateways[A].Length - 1; Y++ )
                        {
                            if ( TileIsGateway[PossibleGateways[A].StartPos.X, Y] )
                            {
                                Valid = false;
                                break;
                            }
                        }
                    }
                    else
                    {
                        for ( X = PossibleGateways[A].StartPos.X; X <= PossibleGateways[A].StartPos.X + PossibleGateways[A].Length - 1; X++ )
                        {
                            if ( TileIsGateway[X, PossibleGateways[A].StartPos.Y] )
                            {
                                Valid = false;
                                break;
                            }
                        }
                    }
                    if ( Valid )
                    {
                        if ( (InvalidPos - PossibleGateways[A].MiddlePos).ToDoubles().GetMagnitude() < InvalidDist )
                        {
                            Valid = false;
                        }
                    }
                    if ( !Valid )
                    {
                        PossibleGatewayCount--;
                        if ( A != PossibleGatewayCount )
                        {
                            PossibleGateways[A] = PossibleGateways[PossibleGatewayCount];
                        }
                    }
                    else
                    {
                        A++;
                    }
                }
            }

            ReturnResult.Success = true;
            return ReturnResult;
        }
Пример #26
0
        private App.sResult PassageNodeHeightLevel(clsPassageNodeHeightLevelArgs Args)
        {
            App.sResult ReturnResult = new App.sResult();
            ReturnResult.Problem = "";
            ReturnResult.Success = false;

            int[] LevelCounts = new int[LevelCount];
            int WaterCount = 0;
            bool ConnectedToLevel = default(bool);
            clsPassageNode tmpPassageNodeB = default(clsPassageNode);
            clsPassageNode tmpPassageNodeC = default(clsPassageNode);
            int EligableCount = 0;
            int[] Eligables = new int[LevelCount];
            int NewHeightLevel = 0;
            int RandomAction = 0;
            int A = 0;
            int B = 0;

            for ( B = 0; B <= Args.PassageNode.ConnectionCount - 1; B++ )
            {
                tmpPassageNodeB = Args.PassageNode.Connections[B].GetOther();
                if ( tmpPassageNodeB.Level >= 0 )
                {
                    LevelCounts[tmpPassageNodeB.Level]++;
                    ConnectedToLevel = true;
                }
                if ( tmpPassageNodeB.IsWater )
                {
                    WaterCount++;
                }
            }
            if ( WaterCount > 0 )
            {
                NewHeightLevel = 0;
            }
            else if ( Args.PassageNodesMinLevel.Nodes[Args.PassageNode.Num] > Args.PassageNodesMaxLevel.Nodes[Args.PassageNode.Num] )
            {
                ReturnResult.Problem = "Error: Min height more than max.";
                return ReturnResult;
            }
            else if ( !ConnectedToLevel )
            {
                //switch to the most uncommon level on the map
                A = int.MaxValue;
                EligableCount = 0;
                for ( B = Args.PassageNodesMinLevel.Nodes[Args.PassageNode.Num]; B <= Args.PassageNodesMaxLevel.Nodes[Args.PassageNode.Num]; B++ )
                {
                    if ( Args.MapLevelCount[B] < A )
                    {
                        A = Args.MapLevelCount[B];
                        Eligables[0] = B;
                        EligableCount = 1;
                    }
                    else if ( Args.MapLevelCount[B] == A )
                    {
                        Eligables[EligableCount] = B;
                        EligableCount++;
                    }
                }
                NewHeightLevel = Eligables[(int)(Conversion.Int(VBMath.Rnd() * EligableCount))];
            }
            else
            {
                RandomAction = Convert.ToInt32(Conversion.Int(VBMath.Rnd() * Args.ActionTotal));
                if ( RandomAction < Args.FlatsCutoff )
                {
                    //extend the level that surrounds this most
                    A = 0;
                    EligableCount = 0;
                    for ( B = Args.PassageNodesMinLevel.Nodes[Args.PassageNode.Num]; B <= Args.PassageNodesMaxLevel.Nodes[Args.PassageNode.Num]; B++ )
                    {
                        if ( LevelCounts[B] > A )
                        {
                            A = LevelCounts[B];
                            Eligables[0] = B;
                            EligableCount = 1;
                        }
                        else if ( LevelCounts[B] == A )
                        {
                            Eligables[EligableCount] = B;
                            EligableCount++;
                        }
                    }
                }
                else if ( RandomAction < Args.PassagesCutoff )
                {
                    //extend any level that surrounds only once, or twice by nodes that aren't already connected
                    EligableCount = 0;
                    for ( B = Args.PassageNodesMinLevel.Nodes[Args.PassageNode.Num]; B <= Args.PassageNodesMaxLevel.Nodes[Args.PassageNode.Num]; B++ )
                    {
                        if ( LevelCounts[B] == 1 )
                        {
                            Eligables[EligableCount] = B;
                            EligableCount++;
                        }
                        else if ( LevelCounts[B] == 2 )
                        {
                            EligableCount = 0;
                            tmpPassageNodeC = null;
                            for ( A = 0; A <= Args.PassageNode.ConnectionCount - 1; A++ )
                            {
                                tmpPassageNodeB = Args.PassageNode.Connections[A].GetOther();
                                if ( tmpPassageNodeB.Level == B )
                                {
                                    if ( tmpPassageNodeC == null )
                                    {
                                        tmpPassageNodeC = tmpPassageNodeB;
                                    }
                                    else
                                    {
                                        if ( tmpPassageNodeC.FindConnection(tmpPassageNodeB) == null )
                                        {
                                            Eligables[EligableCount] = B;
                                            EligableCount++;
                                        }
                                        break;
                                    }
                                }
                            }
                            if ( A == Args.PassageNode.ConnectionCount )
                            {
                                MessageBox.Show("Error: two nodes not found");
                            }
                        }
                    }
                }
                else if ( RandomAction < Args.VariationCutoff )
                {
                    EligableCount = 0;
                }
                else
                {
                    ReturnResult.Problem = "Error: Random number out of range.";
                    return ReturnResult;
                }
                if ( EligableCount == 0 )
                {
                    //extend the most uncommon surrounding
                    A = int.MaxValue;
                    EligableCount = 0;
                    for ( B = Args.PassageNodesMinLevel.Nodes[Args.PassageNode.Num]; B <= Args.PassageNodesMaxLevel.Nodes[Args.PassageNode.Num]; B++ )
                    {
                        if ( LevelCounts[B] < A )
                        {
                            A = LevelCounts[B];
                            Eligables[0] = B;
                            EligableCount = 1;
                        }
                        else if ( LevelCounts[B] == A )
                        {
                            Eligables[EligableCount] = B;
                            EligableCount++;
                        }
                    }
                }
                NewHeightLevel = Eligables[(int)(Conversion.Int(VBMath.Rnd() * EligableCount))];
            }
            for ( B = 0; B <= SymmetryBlockCount - 1; B++ )
            {
                PassageNodes[B, Args.PassageNode.Num].Level = NewHeightLevel;
            }
            PassageNodesMinLevelSet(Args.PassageNode, Args.PassageNodesMinLevel, NewHeightLevel, MaxLevelTransition);
            PassageNodesMaxLevelSet(Args.PassageNode, Args.PassageNodesMaxLevel, NewHeightLevel, MaxLevelTransition);
            Args.MapLevelCount[NewHeightLevel]++;

            ReturnResult.Success = true;
            return ReturnResult;
        }
Пример #27
0
        public clsResult LoadDirectory(string Path)
        {
            clsResult ReturnResult =
                new clsResult("Loading object data from " + Convert.ToString(ControlChars.Quote) + Path + Convert.ToString(ControlChars.Quote));

            Path = App.EndWithPathSeperator(Path);

            string SubDirNames = "";
            string SubDirStructures = "";
            string SubDirBrain = "";
            string SubDirBody = "";
            string SubDirPropulsion = "";
            string SubDirBodyPropulsion = "";
            string SubDirConstruction = "";
            string SubDirSensor = "";
            string SubDirRepair = "";
            string SubDirTemplates = "";
            string SubDirWeapons = "";
            string SubDirECM = "";
            string SubDirFeatures = "";
            string SubDirStructurePIE;
            string SubDirBodiesPIE;
            string SubDirPropPIE;
            string SubDirWeaponsPIE;
            string SubDirTexpages = "";
            string SubDirAssignWeapons = "";
            string SubDirFeaturePIE;
            string SubDirStructureWeapons = "";
            string SubDirPIEs = "";

            SubDirNames = "messages" + Convert.ToString(App.PlatformPathSeparator) + "strings" +
                          Convert.ToString(App.PlatformPathSeparator) + "names.txt";
            SubDirStructures = "stats" + Convert.ToString(App.PlatformPathSeparator) + "structures.txt";
            SubDirBrain = "stats" + Convert.ToString(App.PlatformPathSeparator) + "brain.txt";
            SubDirBody = "stats" + Convert.ToString(App.PlatformPathSeparator) + "body.txt";
            SubDirPropulsion = "stats" + Convert.ToString(App.PlatformPathSeparator) + "propulsion.txt";
            SubDirBodyPropulsion = "stats" + Convert.ToString(App.PlatformPathSeparator) + "bodypropulsionimd.txt";
            SubDirConstruction = "stats" + Convert.ToString(App.PlatformPathSeparator) + "construction.txt";
            SubDirSensor = "stats" + Convert.ToString(App.PlatformPathSeparator) + "sensor.txt";
            SubDirRepair = "stats" + Convert.ToString(App.PlatformPathSeparator) + "repair.txt";
            SubDirTemplates = "stats" + Convert.ToString(App.PlatformPathSeparator) + "templates.txt";
            SubDirWeapons = "stats" + Convert.ToString(App.PlatformPathSeparator) + "weapons.txt";
            SubDirECM = "stats" + Convert.ToString(App.PlatformPathSeparator) + "ecm.txt";
            SubDirFeatures = "stats" + Convert.ToString(App.PlatformPathSeparator) + "features.txt";
            SubDirPIEs = "pies" + Convert.ToString(App.PlatformPathSeparator);
            //SubDirStructurePIE = "structs" & ospathseperator
            SubDirStructurePIE = SubDirPIEs;
            //SubDirBodiesPIE = "components" & ospathseperator & "bodies" & ospathseperator
            SubDirBodiesPIE = SubDirPIEs;
            //SubDirPropPIE = "components" & ospathseperator & "prop" & ospathseperator
            SubDirPropPIE = SubDirPIEs;
            //SubDirWeaponsPIE = "components" & ospathseperator & "weapons" & ospathseperator
            SubDirWeaponsPIE = SubDirPIEs;
            SubDirTexpages = "texpages" + Convert.ToString(App.PlatformPathSeparator);
            SubDirAssignWeapons = "stats" + Convert.ToString(App.PlatformPathSeparator) + "assignweapons.txt";
            //SubDirFeaturePIE = "features" & ospathseperator
            SubDirFeaturePIE = SubDirPIEs;
            SubDirStructureWeapons = "stats" + Convert.ToString(App.PlatformPathSeparator) + "structureweapons.txt";

            SimpleList<clsTextFile> CommaFiles = new SimpleList<clsTextFile>();

            clsTextFile DataNames = new clsTextFile();
            DataNames.SubDirectory = SubDirNames;
            DataNames.UniqueField = 0;

            ReturnResult.Add(DataNames.LoadNamesFile(Path));
            if ( !DataNames.CalcUniqueField() )
            {
                ReturnResult.ProblemAdd("There are two entries for the same code in " + SubDirNames + ".");
            }

            clsTextFile DataStructures = new clsTextFile();
            DataStructures.SubDirectory = SubDirStructures;
            DataStructures.FieldCount = 25;
            CommaFiles.Add(DataStructures);

            clsTextFile DataBrain = new clsTextFile();
            DataBrain.SubDirectory = SubDirBrain;
            DataBrain.FieldCount = 9;
            CommaFiles.Add(DataBrain);

            clsTextFile DataBody = new clsTextFile();
            DataBody.SubDirectory = SubDirBody;
            DataBody.FieldCount = 25;
            CommaFiles.Add(DataBody);

            clsTextFile DataPropulsion = new clsTextFile();
            DataPropulsion.SubDirectory = SubDirPropulsion;
            DataPropulsion.FieldCount = 12;
            CommaFiles.Add(DataPropulsion);

            clsTextFile DataBodyPropulsion = new clsTextFile();
            DataBodyPropulsion.SubDirectory = SubDirBodyPropulsion;
            DataBodyPropulsion.FieldCount = 5;
            DataBodyPropulsion.UniqueField = -1; //no unique requirement
            CommaFiles.Add(DataBodyPropulsion);

            clsTextFile DataConstruction = new clsTextFile();
            DataConstruction.SubDirectory = SubDirConstruction;
            DataConstruction.FieldCount = 12;
            CommaFiles.Add(DataConstruction);

            clsTextFile DataSensor = new clsTextFile();
            DataSensor.SubDirectory = SubDirSensor;
            DataSensor.FieldCount = 16;
            CommaFiles.Add(DataSensor);

            clsTextFile DataRepair = new clsTextFile();
            DataRepair.SubDirectory = SubDirRepair;
            DataRepair.FieldCount = 14;
            CommaFiles.Add(DataRepair);

            clsTextFile DataTemplates = new clsTextFile();
            DataTemplates.SubDirectory = SubDirTemplates;
            DataTemplates.FieldCount = 12;
            CommaFiles.Add(DataTemplates);

            clsTextFile DataECM = new clsTextFile();
            DataECM.SubDirectory = SubDirECM;
            DataECM.FieldCount = 14;
            CommaFiles.Add(DataECM);

            clsTextFile DataFeatures = new clsTextFile();
            DataFeatures.SubDirectory = SubDirFeatures;
            DataFeatures.FieldCount = 11;
            CommaFiles.Add(DataFeatures);

            clsTextFile DataAssignWeapons = new clsTextFile();
            DataAssignWeapons.SubDirectory = SubDirAssignWeapons;
            DataAssignWeapons.FieldCount = 5;
            CommaFiles.Add(DataAssignWeapons);

            clsTextFile DataWeapons = new clsTextFile();
            DataWeapons.SubDirectory = SubDirWeapons;
            DataWeapons.FieldCount = 53;
            CommaFiles.Add(DataWeapons);

            clsTextFile DataStructureWeapons = new clsTextFile();
            DataStructureWeapons.SubDirectory = SubDirStructureWeapons;
            DataStructureWeapons.FieldCount = 6;
            CommaFiles.Add(DataStructureWeapons);

            clsTextFile TextFile = default(clsTextFile);

            foreach ( clsTextFile tempLoopVar_TextFile in CommaFiles )
            {
                TextFile = tempLoopVar_TextFile;
                clsResult Result = TextFile.LoadCommaFile(Path);
                ReturnResult.Add(Result);
                if ( !Result.HasProblems )
                {
                    if ( TextFile.CalcIsFieldCountValid() )
                    {
                        if ( !TextFile.CalcUniqueField() )
                        {
                            ReturnResult.ProblemAdd("An entry in field " + Convert.ToString(TextFile.UniqueField) + " was not unique for file " +
                                                    TextFile.SubDirectory + ".");
                        }
                    }
                    else
                    {
                        ReturnResult.ProblemAdd("There were entries with the wrong number of fields for file " + TextFile.SubDirectory + ".");
                    }
                }
            }

            if ( ReturnResult.HasProblems )
            {
                return ReturnResult;
            }

            //load texpages

            string[] TexFiles = null;

            try
            {
                TexFiles = Directory.GetFiles(Path + SubDirTexpages);
            }
            catch ( Exception )
            {
                ReturnResult.WarningAdd("Unable to access texture pages.");
                TexFiles = new string[0];
            }

            string Text = "";
            Bitmap Bitmap = null;
            int InstrPos2 = 0;
            BitmapGLTexture BitmapTextureArgs = new BitmapGLTexture();
            App.sResult BitmapResult = new App.sResult();

            foreach ( string tempLoopVar_Text in TexFiles )
            {
                Text = tempLoopVar_Text;
                if ( Text.Substring(Text.Length - 4, 4).ToLower() == ".png" )
                {
                    clsResult Result =
                        new clsResult("Loading texture page " + Convert.ToString(ControlChars.Quote) + Text + Convert.ToString(ControlChars.Quote));
                    if ( File.Exists(Text) )
                    {
                        BitmapResult = BitmapUtil.LoadBitmap(Text, ref Bitmap);
                        clsTexturePage NewPage = new clsTexturePage();
                        if ( BitmapResult.Success )
                        {
                            Result.Take(BitmapUtil.BitmapIsGLCompatible(Bitmap));
                            BitmapTextureArgs.MagFilter = TextureMagFilter.Nearest;
                            BitmapTextureArgs.MinFilter = TextureMinFilter.Nearest;
                            BitmapTextureArgs.TextureNum = 0;
                            BitmapTextureArgs.MipMapLevel = 0;
                            BitmapTextureArgs.Texture = Bitmap;
                            BitmapTextureArgs.Perform();
                            NewPage.GLTexture_Num = BitmapTextureArgs.TextureNum;
                        }
                        else
                        {
                            Result.WarningAdd(BitmapResult.Problem);
                        }
                        InstrPos2 = Strings.InStrRev(Text, App.PlatformPathSeparator.ToString(), -1, (CompareMethod)0);
                        NewPage.FileTitle = Strings.Mid(Text, InstrPos2 + 1, Text.Length - 4 - InstrPos2);
                        TexturePages.Add(NewPage);
                    }
                    else
                    {
                        Result.WarningAdd("Texture page missing (" + Text + ").");
                    }
                    ReturnResult.Add(Result);
                }
            }

            //load PIEs

            string[] PIE_Files = null;
            SimpleList<clsPIE> PIE_List = new SimpleList<clsPIE>();
            clsPIE NewPIE = default(clsPIE);

            try
            {
                PIE_Files = Directory.GetFiles(Path + SubDirPIEs);
            }
            catch ( Exception )
            {
                ReturnResult.WarningAdd("Unable to access PIE files.");
                PIE_Files = new string[0];
            }

            App.sSplitPath SplitPath = new App.sSplitPath();

            foreach ( string tempLoopVar_Text in PIE_Files )
            {
                Text = tempLoopVar_Text;
                SplitPath = new App.sSplitPath(Text);
                if ( SplitPath.FileExtension.ToLower() == "pie" )
                {
                    NewPIE = new clsPIE();
                    NewPIE.Path = Text;
                    NewPIE.LCaseFileTitle = SplitPath.FileTitle.ToLower();
                    PIE_List.Add(NewPIE);
                }
            }

            //interpret stats

            clsUnitType.clsAttachment Attachment = default(clsUnitType.clsAttachment);
            clsUnitType.clsAttachment BaseAttachment = default(clsUnitType.clsAttachment);
            sXYZ_sng Connector = new sXYZ_sng();
            clsStructureType StructureType = default(clsStructureType);
            clsFeatureType FeatureType = default(clsFeatureType);
            clsDroidTemplate Template = default(clsDroidTemplate);
            clsBody Body = default(clsBody);
            clsPropulsion Propulsion = default(clsPropulsion);
            clsConstruct Construct = default(clsConstruct);
            clsWeapon Weapon = default(clsWeapon);
            clsRepair Repair = default(clsRepair);
            clsSensor Sensor = default(clsSensor);
            clsBrain Brain = default(clsBrain);
            clsECM ECM = default(clsECM);
            string[] Fields = null;

            //interpret body

            foreach ( string[] tempLoopVar_Fields in DataBody.ResultData )
            {
                Fields = tempLoopVar_Fields;
                Body = new clsBody();
                Body.ObjectDataLink.Connect(Bodies);
                Body.Code = Fields[0];
                SetComponentName(DataNames.ResultData, Body, ReturnResult);
                IOUtil.InvariantParse(Fields[6], ref Body.Hitpoints);
                Body.Designable = Fields[24] != "0";
                Body.Attachment.Models.Add(GetModelForPIE(PIE_List, Fields[7].ToLower(), ReturnResult));
            }

            //interpret propulsion

            foreach ( string[] tempLoopVar_Fields in DataPropulsion.ResultData )
            {
                Fields = tempLoopVar_Fields;
                Propulsion = new clsPropulsion(Bodies.Count);
                Propulsion.ObjectDataLink.Connect(Propulsions);
                Propulsion.Code = Fields[0];
                SetComponentName(DataNames.ResultData, Propulsion, ReturnResult);
                IOUtil.InvariantParse(Fields[7], ref Propulsion.HitPoints);
                //.Propulsions(Propulsion_Num).PIE = LCase(DataPropulsion.Entries(Propulsion_Num).FieldValues(8))
                Propulsion.Designable = Fields[11] != "0";
            }

            //interpret body-propulsions

            BodyProp[,] BodyPropulsionPIEs = new BodyProp[Bodies.Count, Propulsions.Count];
            for ( int A = 0; A <= Bodies.Count - 1; A++ )
            {
                for ( int B = 0; B <= Propulsions.Count - 1; B++ )
                {
                    BodyPropulsionPIEs[A, B] = new BodyProp();
                    BodyPropulsionPIEs[A, B].LeftPIE = "0";
                    BodyPropulsionPIEs[A, B].RightPIE = "0";
                }
            }

            foreach ( string[] tempLoopVar_Fields in DataBodyPropulsion.ResultData )
            {
                Fields = tempLoopVar_Fields;
                Body = FindBodyCode(Fields[0]);
                Propulsion = FindPropulsionCode(Fields[1]);
                if ( Body != null && Propulsion != null )
                {
                    if ( Fields[2] != "0" )
                    {
                        BodyPropulsionPIEs[Body.ObjectDataLink.ArrayPosition, Propulsion.ObjectDataLink.ArrayPosition].LeftPIE = Fields[2].ToLower();
                    }
                    if ( Fields[3] != "0" )
                    {
                        BodyPropulsionPIEs[Body.ObjectDataLink.ArrayPosition, Propulsion.ObjectDataLink.ArrayPosition].RightPIE = Fields[3].ToLower();
                    }
                }
            }

            //set propulsion-body PIEs

            for ( int A = 0; A <= Propulsions.Count - 1; A++ )
            {
                Propulsion = Propulsions[A];
                for ( int B = 0; B <= Bodies.Count - 1; B++ )
                {
                    Body = Bodies[B];
                    Propulsion.Bodies[B].LeftAttachment = new clsUnitType.clsAttachment();
                    Propulsion.Bodies[B].LeftAttachment.Models.Add(GetModelForPIE(PIE_List, BodyPropulsionPIEs[B, A].LeftPIE, ReturnResult));
                    Propulsion.Bodies[B].RightAttachment = new clsUnitType.clsAttachment();
                    Propulsion.Bodies[B].RightAttachment.Models.Add(GetModelForPIE(PIE_List, BodyPropulsionPIEs[B, A].RightPIE, ReturnResult));
                }
            }

            //interpret construction

            foreach ( string[] tempLoopVar_Fields in DataConstruction.ResultData )
            {
                Fields = tempLoopVar_Fields;
                Construct = new clsConstruct();
                Construct.ObjectDataLink.Connect(Constructors);
                Construct.TurretObjectDataLink.Connect(Turrets);
                Construct.Code = Fields[0];
                SetComponentName(DataNames.ResultData, Construct, ReturnResult);
                Construct.Designable = Fields[11] != "0";
                Construct.Attachment.Models.Add(GetModelForPIE(PIE_List, Fields[8].ToLower(), ReturnResult));
            }

            //interpret weapons

            foreach ( string[] tempLoopVar_Fields in DataWeapons.ResultData )
            {
                Fields = tempLoopVar_Fields;
                Weapon = new clsWeapon();
                Weapon.ObjectDataLink.Connect(Weapons);
                Weapon.TurretObjectDataLink.Connect(Turrets);
                Weapon.Code = Fields[0];
                SetComponentName(DataNames.ResultData, Weapon, ReturnResult);
                IOUtil.InvariantParse(Fields[7], ref Weapon.HitPoints);
                Weapon.Designable = Fields[51] != "0";
                Weapon.Attachment.Models.Add(GetModelForPIE(PIE_List, Convert.ToString(Fields[8].ToLower()), ReturnResult));
                Weapon.Attachment.Models.Add(GetModelForPIE(PIE_List, Fields[9].ToLower(), ReturnResult));
            }

            //interpret sensor

            foreach ( string[] tempLoopVar_Fields in DataSensor.ResultData )
            {
                Fields = tempLoopVar_Fields;
                Sensor = new clsSensor();
                Sensor.ObjectDataLink.Connect(Sensors);
                Sensor.TurretObjectDataLink.Connect(Turrets);
                Sensor.Code = Fields[0];
                SetComponentName(DataNames.ResultData, Sensor, ReturnResult);
                IOUtil.InvariantParse(Fields[7], ref Sensor.HitPoints);
                Sensor.Designable = Fields[15] != "0";
                switch ( Fields[11].ToLower() )
                {
                    case "turret":
                        Sensor.Location = clsSensor.enumLocation.Turret;
                        break;
                    case "default":
                        Sensor.Location = clsSensor.enumLocation.Invisible;
                        break;
                    default:
                        Sensor.Location = clsSensor.enumLocation.Invisible;
                        break;
                }
                Sensor.Attachment.Models.Add(GetModelForPIE(PIE_List, Fields[8].ToLower(), ReturnResult));
                Sensor.Attachment.Models.Add(GetModelForPIE(PIE_List, Fields[9].ToLower(), ReturnResult));
            }

            //interpret repair

            foreach ( string[] tempLoopVar_Fields in DataRepair.ResultData )
            {
                Fields = tempLoopVar_Fields;
                Repair = new clsRepair();
                Repair.ObjectDataLink.Connect(Repairs);
                Repair.TurretObjectDataLink.Connect(Turrets);
                Repair.Code = Fields[0];
                SetComponentName(DataNames.ResultData, Repair, ReturnResult);
                Repair.Designable = Fields[13] != "0";
                Repair.Attachment.Models.Add(GetModelForPIE(PIE_List, Fields[9].ToLower(), ReturnResult));
                Repair.Attachment.Models.Add(GetModelForPIE(PIE_List, Fields[10].ToLower(), ReturnResult));
            }

            //interpret brain

            foreach ( string[] tempLoopVar_Fields in DataBrain.ResultData )
            {
                Fields = tempLoopVar_Fields;
                Brain = new clsBrain();
                Brain.ObjectDataLink.Connect(Brains);
                Brain.TurretObjectDataLink.Connect(Turrets);
                Brain.Code = Fields[0];
                SetComponentName(DataNames.ResultData, Brain, ReturnResult);
                Brain.Designable = true;
                Weapon = FindWeaponCode(Fields[7]);
                if ( Weapon != null )
                {
                    Brain.Weapon = Weapon;
                    Brain.Attachment = Weapon.Attachment;
                }
            }

            //interpret ecm

            foreach ( string[] tempLoopVar_Fields in DataECM.ResultData )
            {
                Fields = tempLoopVar_Fields;
                ECM = new clsECM();
                ECM.ObjectDataLink.Connect(ECMs);
                ECM.TurretObjectDataLink.Connect(Turrets);
                ECM.Code = Fields[0];
                SetComponentName(DataNames.ResultData, ECM, ReturnResult);
                IOUtil.InvariantParse(Fields[7], ref ECM.HitPoints);
                ECM.Designable = false;
                ECM.Attachment.Models.Add(GetModelForPIE(PIE_List, Fields[8].ToLower(), ReturnResult));
            }

            //interpret feature

            foreach ( string[] tempLoopVar_Fields in DataFeatures.ResultData )
            {
                Fields = tempLoopVar_Fields;
                FeatureType = new clsFeatureType();
                FeatureType.UnitType_ObjectDataLink.Connect(UnitTypes);
                FeatureType.FeatureType_ObjectDataLink.Connect(FeatureTypes);
                FeatureType.Code = Fields[0];
                if ( Fields[7] == "OIL RESOURCE" ) //type
                {
                    FeatureType.FeatureType = clsFeatureType.enumFeatureType.OilResource;
                }
                SetFeatureName(DataNames.ResultData, FeatureType, ReturnResult);
                if ( !IOUtil.InvariantParse(Fields[1], ref FeatureType.Footprint.X) )
                {
                    ReturnResult.WarningAdd("Feature footprint-x was not an integer for " + FeatureType.Code + ".");
                }
                if ( !IOUtil.InvariantParse(Fields[2], ref FeatureType.Footprint.Y) )
                {
                    ReturnResult.WarningAdd("Feature footprint-y was not an integer for " + FeatureType.Code + ".");
                }
                FeatureType.BaseAttachment = new clsUnitType.clsAttachment();
                BaseAttachment = FeatureType.BaseAttachment;
                Text = Fields[6].ToLower();
                Attachment = BaseAttachment.CreateAttachment();
                Attachment.Models.Add(GetModelForPIE(PIE_List, Text, ReturnResult));
            }

            //interpret structure

            foreach ( string[] tempLoopVar_Fields in DataStructures.ResultData )
            {
                Fields = tempLoopVar_Fields;
                string StructureCode = Fields[0];
                string StructureTypeText = Fields[1];
                string[] StructurePIEs = Fields[21].ToLower().Split('@');
                sXY_int StructureFootprint = new sXY_int();
                string StructureBasePIE = Fields[22].ToLower();
                if ( !IOUtil.InvariantParse(Fields[5], ref StructureFootprint.X) )
                {
                    ReturnResult.WarningAdd("Structure footprint-x was not an integer for " + StructureCode + ".");
                }
                if ( !IOUtil.InvariantParse(Fields[6], ref StructureFootprint.Y) )
                {
                    ReturnResult.WarningAdd("Structure footprint-y was not an integer for " + StructureCode + ".");
                }
                if ( StructureTypeText != "WALL" || StructurePIEs.GetLength(0) != 4 )
                {
                    //this is NOT a generic wall
                    StructureType = new clsStructureType();
                    StructureType.UnitType_ObjectDataLink.Connect(UnitTypes);
                    StructureType.StructureType_ObjectDataLink.Connect(StructureTypes);
                    StructureType.Code = StructureCode;
                    SetStructureName(DataNames.ResultData, StructureType, ReturnResult);
                    StructureType.Footprint = StructureFootprint;
                    switch ( StructureTypeText )
                    {
                        case "DEMOLISH":
                            StructureType.StructureType = clsStructureType.enumStructureType.Demolish;
                            break;
                        case "WALL":
                            StructureType.StructureType = clsStructureType.enumStructureType.Wall;
                            break;
                        case "CORNER WALL":
                            StructureType.StructureType = clsStructureType.enumStructureType.CornerWall;
                            break;
                        case "FACTORY":
                            StructureType.StructureType = clsStructureType.enumStructureType.Factory;
                            break;
                        case "CYBORG FACTORY":
                            StructureType.StructureType = clsStructureType.enumStructureType.CyborgFactory;
                            break;
                        case "VTOL FACTORY":
                            StructureType.StructureType = clsStructureType.enumStructureType.VTOLFactory;
                            break;
                        case "COMMAND":
                            StructureType.StructureType = clsStructureType.enumStructureType.Command;
                            break;
                        case "HQ":
                            StructureType.StructureType = clsStructureType.enumStructureType.HQ;
                            break;
                        case "DEFENSE":
                            StructureType.StructureType = clsStructureType.enumStructureType.Defense;
                            break;
                        case "POWER GENERATOR":
                            StructureType.StructureType = clsStructureType.enumStructureType.PowerGenerator;
                            break;
                        case "POWER MODULE":
                            StructureType.StructureType = clsStructureType.enumStructureType.PowerModule;
                            break;
                        case "RESEARCH":
                            StructureType.StructureType = clsStructureType.enumStructureType.Research;
                            break;
                        case "RESEARCH MODULE":
                            StructureType.StructureType = clsStructureType.enumStructureType.ResearchModule;
                            break;
                        case "FACTORY MODULE":
                            StructureType.StructureType = clsStructureType.enumStructureType.FactoryModule;
                            break;
                        case "DOOR":
                            StructureType.StructureType = clsStructureType.enumStructureType.DOOR;
                            break;
                        case "REPAIR FACILITY":
                            StructureType.StructureType = clsStructureType.enumStructureType.RepairFacility;
                            break;
                        case "SAT UPLINK":
                            StructureType.StructureType = clsStructureType.enumStructureType.DOOR;
                            break;
                        case "REARM PAD":
                            StructureType.StructureType = clsStructureType.enumStructureType.RearmPad;
                            break;
                        case "MISSILE SILO":
                            StructureType.StructureType = clsStructureType.enumStructureType.MissileSilo;
                            break;
                        case "RESOURCE EXTRACTOR":
                            StructureType.StructureType = clsStructureType.enumStructureType.ResourceExtractor;
                            break;
                        default:
                            StructureType.StructureType = clsStructureType.enumStructureType.Unknown;
                            break;
                    }

                    BaseAttachment = StructureType.BaseAttachment;
                    if ( StructurePIEs.GetLength(0) > 0 )
                    {
                        BaseAttachment.Models.Add(GetModelForPIE(PIE_List, StructurePIEs[0], ReturnResult));
                    }
                    StructureType.StructureBasePlate = GetModelForPIE(PIE_List, StructureBasePIE, ReturnResult);
                    if ( BaseAttachment.Models.Count == 1 )
                    {
                        if ( BaseAttachment.Models[0].ConnectorCount >= 1 )
                        {
                            Connector = BaseAttachment.Models[0].Connectors[0];
                            SimpleList<string[]> StructureWeapons = default(SimpleList<string[]>);
                            StructureWeapons = GetRowsWithValue(DataStructureWeapons.ResultData, StructureType.Code);
                            if ( StructureWeapons.Count > 0 )
                            {
                                Weapon = FindWeaponCode(Convert.ToString(StructureWeapons[0][1]));
                            }
                            else
                            {
                                Weapon = null;
                            }
                            ECM = FindECMCode(Fields[18]);
                            Sensor = FindSensorCode(Fields[19]);
                            if ( Weapon != null )
                            {
                                if ( Weapon.Code != "ZNULLWEAPON" )
                                {
                                    Attachment = BaseAttachment.CopyAttachment(Weapon.Attachment);
                                    Attachment.Pos_Offset = Connector;
                                }
                            }
                            if ( ECM != null )
                            {
                                if ( ECM.Code != "ZNULLECM" )
                                {
                                    Attachment = BaseAttachment.CopyAttachment(ECM.Attachment);
                                    Attachment.Pos_Offset = Connector;
                                }
                            }
                            if ( Sensor != null )
                            {
                                if ( Sensor.Code != "ZNULLSENSOR" )
                                {
                                    Attachment = BaseAttachment.CopyAttachment(Sensor.Attachment);
                                    Attachment.Pos_Offset = Connector;
                                }
                            }
                        }
                    }
                }
                else
                {
                    //this is a generic wall
                    clsWallType NewWall = new clsWallType();
                    NewWall.WallType_ObjectDataLink.Connect(WallTypes);
                    NewWall.Code = StructureCode;
                    SetWallName(DataNames.ResultData, NewWall, ReturnResult);
                    clsModel WallBasePlate = GetModelForPIE(PIE_List, StructureBasePIE, ReturnResult);

                    int WallNum = 0;
                    clsStructureType WallStructureType = default(clsStructureType);
                    for ( WallNum = 0; WallNum <= 3; WallNum++ )
                    {
                        WallStructureType = new clsStructureType();
                        WallStructureType.UnitType_ObjectDataLink.Connect(UnitTypes);
                        WallStructureType.StructureType_ObjectDataLink.Connect(StructureTypes);
                        WallStructureType.WallLink.Connect(NewWall.Segments);
                        WallStructureType.Code = StructureCode;
                        Text = NewWall.Name;
                        switch ( WallNum )
                        {
                            case 0:
                                Text += " - ";
                                break;
                            case 1:
                                Text += " + ";
                                break;
                            case 2:
                                Text += " T ";
                                break;
                            case 3:
                                Text += " L ";
                                break;
                        }
                        WallStructureType.Name = Text;
                        WallStructureType.Footprint = StructureFootprint;
                        WallStructureType.StructureType = clsStructureType.enumStructureType.Wall;

                        BaseAttachment = WallStructureType.BaseAttachment;

                        Text = StructurePIEs[WallNum];
                        BaseAttachment.Models.Add(GetModelForPIE(PIE_List, Text, ReturnResult));
                        WallStructureType.StructureBasePlate = WallBasePlate;
                    }
                }
            }

            //interpret templates

            int TurretConflictCount = 0;
            foreach ( string[] tempLoopVar_Fields in DataTemplates.ResultData )
            {
                Fields = tempLoopVar_Fields;
                Template = new clsDroidTemplate();
                Template.UnitType_ObjectDataLink.Connect(UnitTypes);
                Template.DroidTemplate_ObjectDataLink.Connect(DroidTemplates);
                Template.Code = Fields[0];
                SetTemplateName(DataNames.ResultData, Template, ReturnResult);
                switch ( Fields[9] ) //type
                {
                    case "ZNULLDROID":
                        Template.TemplateDroidType = App.TemplateDroidType_Null;
                        break;
                    case "DROID":
                        Template.TemplateDroidType = App.TemplateDroidType_Droid;
                        break;
                    case "CYBORG":
                        Template.TemplateDroidType = App.TemplateDroidType_Cyborg;
                        break;
                    case "CYBORG_CONSTRUCT":
                        Template.TemplateDroidType = App.TemplateDroidType_CyborgConstruct;
                        break;
                    case "CYBORG_REPAIR":
                        Template.TemplateDroidType = App.TemplateDroidType_CyborgRepair;
                        break;
                    case "CYBORG_SUPER":
                        Template.TemplateDroidType = App.TemplateDroidType_CyborgSuper;
                        break;
                    case "TRANSPORTER":
                        Template.TemplateDroidType = App.TemplateDroidType_Transporter;
                        break;
                    case "PERSON":
                        Template.TemplateDroidType = App.TemplateDroidType_Person;
                        break;
                    default:
                        Template.TemplateDroidType = null;
                        ReturnResult.WarningAdd("Template " + Template.GetDisplayTextCode() + " had an unrecognised type.");
                        break;
                }
                clsDroidDesign.sLoadPartsArgs LoadPartsArgs = new clsDroidDesign.sLoadPartsArgs();
                LoadPartsArgs.Body = FindBodyCode(Fields[2]);
                LoadPartsArgs.Brain = FindBrainCode(Fields[3]);
                LoadPartsArgs.Construct = FindConstructorCode(Fields[4]);
                LoadPartsArgs.ECM = FindECMCode(Fields[5]);
                LoadPartsArgs.Propulsion = FindPropulsionCode(Fields[7]);
                LoadPartsArgs.Repair = FindRepairCode(Fields[8]);
                LoadPartsArgs.Sensor = FindSensorCode(Fields[10]);
                SimpleList<string[]> TemplateWeapons = GetRowsWithValue(DataAssignWeapons.ResultData, Template.Code);
                if ( TemplateWeapons.Count > 0 )
                {
                    Text = Convert.ToString(TemplateWeapons[0][1]);
                    if ( Text != "NULL" )
                    {
                        LoadPartsArgs.Weapon1 = FindWeaponCode(Text);
                    }
                    Text = Convert.ToString(TemplateWeapons[0][2]);
                    if ( Text != "NULL" )
                    {
                        LoadPartsArgs.Weapon2 = FindWeaponCode(Text);
                    }
                    Text = Convert.ToString(TemplateWeapons[0][3]);
                    if ( Text != "NULL" )
                    {
                        LoadPartsArgs.Weapon3 = FindWeaponCode(Text);
                    }
                }
                if ( !Template.LoadParts(LoadPartsArgs) )
                {
                    if ( TurretConflictCount < 16 )
                    {
                        ReturnResult.WarningAdd("Template " + Template.GetDisplayTextCode() + " had multiple conflicting turrets.");
                    }
                    TurretConflictCount++;
                }
            }
            if ( TurretConflictCount > 0 )
            {
                ReturnResult.WarningAdd(TurretConflictCount + " templates had multiple conflicting turrets.");
            }

            return ReturnResult;
        }