示例#1
0
        private clsResult Read_FME(BinaryReader File)
        {
            clsResult ReturnResult = new clsResult("Reading FME");

            UInt32 Version = 0;

            clsInterfaceOptions ResultInfo = new clsInterfaceOptions();

            clsUnitAdd UnitAdd = new clsUnitAdd();
            UnitAdd.Map = this;

            try
            {
                Version = File.ReadUInt32();

                if ( Version <= 4U )
                {
                    ReturnResult.ProblemAdd("Version " + Convert.ToString(Version) + " is not supported.");
                    return ReturnResult;
                }
                else if ( Version == 5U || Version == 6U || Version == 7U )
                {
                    byte byteTemp = 0;

                    //tileset
                    byteTemp = File.ReadByte();
                    if ( byteTemp == 0 )
                    {
                        Tileset = null;
                    }
                    else if ( byteTemp == 1 )
                    {
                        Tileset = App.Tileset_Arizona;
                    }
                    else if ( byteTemp == 2 )
                    {
                        Tileset = App.Tileset_Urban;
                    }
                    else if ( byteTemp == 3 )
                    {
                        Tileset = App.Tileset_Rockies;
                    }
                    else
                    {
                        ReturnResult.WarningAdd("Tileset value out of range.");
                        Tileset = null;
                    }

                    SetPainterToDefaults(); //depends on tileset. must be called before loading the terrains.

                    UInt16 MapWidth = 0;
                    UInt16 MapHeight = 0;

                    MapWidth = File.ReadUInt16();
                    MapHeight = File.ReadUInt16();

                    if ( MapWidth < 1U || MapHeight < 1U || MapWidth > Constants.MapMaxSize || MapHeight > Constants.MapMaxSize )
                    {
                        ReturnResult.ProblemAdd("Map size is invalid.");
                        return ReturnResult;
                    }

                    TerrainBlank(new sXY_int(MapWidth, MapHeight));
                    TileType_Reset();

                    int X = 0;
                    int Y = 0;
                    int A = 0;
                    int B = 0;
                    int intTemp = 0;
                    int WarningCount = 0;

                    WarningCount = 0;
                    for ( Y = 0; Y <= Terrain.TileSize.Y; Y++ )
                    {
                        for ( X = 0; X <= Terrain.TileSize.X; X++ )
                        {
                            Terrain.Vertices[X, Y].Height = File.ReadByte();
                            byteTemp = File.ReadByte();
                            intTemp = (byteTemp) - 1;
                            if ( intTemp < 0 )
                            {
                                Terrain.Vertices[X, Y].Terrain = null;
                            }
                            else if ( intTemp >= Painter.TerrainCount )
                            {
                                WarningCount++;
                                Terrain.Vertices[X, Y].Terrain = null;
                            }
                            else
                            {
                                Terrain.Vertices[X, Y].Terrain = Painter.Terrains[intTemp];
                            }
                        }
                    }
                    if ( WarningCount > 0 )
                    {
                        ReturnResult.WarningAdd(WarningCount + " painted ground vertices were out of range.");
                    }
                    WarningCount = 0;
                    for ( Y = 0; Y <= Terrain.TileSize.Y - 1; Y++ )
                    {
                        for ( X = 0; X <= Terrain.TileSize.X - 1; X++ )
                        {
                            byteTemp = File.ReadByte();
                            Terrain.Tiles[X, Y].Texture.TextureNum = (byteTemp) - 1;

                            byteTemp = File.ReadByte();

                            intTemp = 128;
                            A = (int)(Conversion.Int(byteTemp / intTemp));
                            byteTemp -= (byte)(A * intTemp);
                            Terrain.Tiles[X, Y].Terrain_IsCliff = A == 1;

                            intTemp = 64;
                            A = (int)(Conversion.Int(byteTemp / intTemp));
                            byteTemp -= (byte)(A * intTemp);
                            Terrain.Tiles[X, Y].Texture.Orientation.SwitchedAxes = A == 1;

                            intTemp = 32;
                            A = (int)(Conversion.Int(byteTemp / intTemp));
                            byteTemp -= (byte)(A * intTemp);
                            Terrain.Tiles[X, Y].Texture.Orientation.ResultXFlip = A == 1;

                            intTemp = 16;
                            A = (int)(Conversion.Int(byteTemp / intTemp));
                            byteTemp -= (byte)(A * intTemp);
                            Terrain.Tiles[X, Y].Texture.Orientation.ResultYFlip = A == 1;

                            intTemp = 4;
                            A = (int)(Conversion.Int(byteTemp / intTemp));
                            byteTemp -= (byte)(A * intTemp);
                            Terrain.Tiles[X, Y].Tri = A == 1;

                            intTemp = 2;
                            A = (int)(Conversion.Int(byteTemp / intTemp));
                            byteTemp -= (byte)(A * intTemp);
                            if ( Terrain.Tiles[X, Y].Tri )
                            {
                                Terrain.Tiles[X, Y].TriTopLeftIsCliff = A == 1;
                            }
                            else
                            {
                                Terrain.Tiles[X, Y].TriBottomLeftIsCliff = A == 1;
                            }

                            intTemp = 1;
                            A = (int)(Conversion.Int(byteTemp / intTemp));
                            byteTemp -= (byte)(A * intTemp);
                            if ( Terrain.Tiles[X, Y].Tri )
                            {
                                Terrain.Tiles[X, Y].TriBottomRightIsCliff = A == 1;
                            }
                            else
                            {
                                Terrain.Tiles[X, Y].TriTopRightIsCliff = A == 1;
                            }

                            //attributes2
                            byteTemp = File.ReadByte();

                            if ( byteTemp == ((byte)0) )
                            {
                                Terrain.Tiles[X, Y].DownSide = TileUtil.None;
                            }
                            else if ( byteTemp == ((byte)1) )
                            {
                                Terrain.Tiles[X, Y].DownSide = TileUtil.Top;
                            }
                            else if ( byteTemp == ((byte)2) )
                            {
                                Terrain.Tiles[X, Y].DownSide = TileUtil.Left;
                            }
                            else if ( byteTemp == ((byte)3) )
                            {
                                Terrain.Tiles[X, Y].DownSide = TileUtil.Right;
                            }
                            else if ( byteTemp == ((byte)4) )
                            {
                                Terrain.Tiles[X, Y].DownSide = TileUtil.Bottom;
                            }
                            else
                            {
                                WarningCount++;
                            }
                        }
                    }
                    if ( WarningCount > 0 )
                    {
                        ReturnResult.WarningAdd(WarningCount + " tile cliff down-sides were out of range.");
                    }
                    WarningCount = 0;
                    for ( Y = 0; Y <= Terrain.TileSize.Y; Y++ )
                    {
                        for ( X = 0; X <= Terrain.TileSize.X - 1; X++ )
                        {
                            byteTemp = File.ReadByte();
                            intTemp = (byteTemp) - 1;
                            if ( intTemp < 0 )
                            {
                                Terrain.SideH[X, Y].Road = null;
                            }
                            else if ( intTemp >= Painter.RoadCount )
                            {
                                WarningCount++;
                                Terrain.SideH[X, Y].Road = null;
                            }
                            else
                            {
                                Terrain.SideH[X, Y].Road = Painter.Roads[intTemp];
                            }
                        }
                    }
                    for ( Y = 0; Y <= Terrain.TileSize.Y - 1; Y++ )
                    {
                        for ( X = 0; X <= Terrain.TileSize.X; X++ )
                        {
                            byteTemp = File.ReadByte();
                            intTemp = (byteTemp) - 1;
                            if ( intTemp < 0 )
                            {
                                Terrain.SideV[X, Y].Road = null;
                            }
                            else if ( intTemp >= Painter.RoadCount )
                            {
                                WarningCount++;
                                Terrain.SideV[X, Y].Road = null;
                            }
                            else
                            {
                                Terrain.SideV[X, Y].Road = Painter.Roads[intTemp];
                            }
                        }
                    }
                    if ( WarningCount > 0 )
                    {
                        ReturnResult.WarningAdd(WarningCount + " roads were out of range.");
                    }
                    UInt32 TempUnitCount = 0;
                    TempUnitCount = File.ReadUInt32();
                    sFMEUnit[] TempUnit = new sFMEUnit[(Convert.ToInt32(TempUnitCount))];
                    for ( A = 0; A <= (Convert.ToInt32(TempUnitCount)) - 1; A++ )
                    {
                        TempUnit[A].Code = new string(File.ReadChars(40));
                        B = Strings.InStr(TempUnit[A].Code, Convert.ToString('\0'), (CompareMethod)0);
                        if ( B > 0 )
                        {
                            TempUnit[A].Code = Strings.Left(TempUnit[A].Code, B - 1);
                        }
                        TempUnit[A].LNDType = File.ReadByte();
                        TempUnit[A].ID = File.ReadUInt32();
                        if ( Version == 6U )
                        {
                            TempUnit[A].SavePriority = File.ReadInt32();
                        }
                        TempUnit[A].X = File.ReadUInt32();
                        TempUnit[A].Z = File.ReadUInt32();
                        TempUnit[A].Y = File.ReadUInt32();
                        TempUnit[A].Rotation = File.ReadUInt16();
                        TempUnit[A].Name = IOUtil.ReadOldText(File);
                        TempUnit[A].Player = File.ReadByte();
                    }

                    clsUnit NewUnit = default(clsUnit);
                    clsUnitType UnitType = null;
                    UInt32 AvailableID = 0;

                    AvailableID = 1U;
                    for ( A = 0; A <= (Convert.ToInt32(TempUnitCount)) - 1; A++ )
                    {
                        if ( TempUnit[A].ID >= AvailableID )
                        {
                            AvailableID = TempUnit[A].ID + 1U;
                        }
                    }
                    WarningCount = 0;
                    for ( A = 0; A <= (Convert.ToInt32(TempUnitCount)) - 1; A++ )
                    {
                        if ( TempUnit[A].LNDType == ((byte)0) )
                        {
                            UnitType = App.ObjectData.FindOrCreateUnitType(TempUnit[A].Code, clsUnitType.enumType.Feature, -1);
                        }
                        else if ( TempUnit[A].LNDType == ((byte)1) )
                        {
                            UnitType = App.ObjectData.FindOrCreateUnitType(TempUnit[A].Code, clsUnitType.enumType.PlayerStructure, -1);
                        }
                        else if ( TempUnit[A].LNDType == ((byte)2) )
                        {
                            UnitType = App.ObjectData.FindOrCreateUnitType(Convert.ToString(TempUnit[A].Code), clsUnitType.enumType.PlayerDroid, -1);
                        }
                        else
                        {
                            UnitType = null;
                        }
                        if ( UnitType != null )
                        {
                            NewUnit = new clsUnit();
                            NewUnit.Type = UnitType;
                            NewUnit.ID = TempUnit[A].ID;
                            NewUnit.SavePriority = TempUnit[A].SavePriority;
                            //NewUnit.Name = TempUnit(A).Name
                            if ( TempUnit[A].Player >= Constants.PlayerCountMax )
                            {
                                NewUnit.UnitGroup = ScavengerUnitGroup;
                            }
                            else
                            {
                                NewUnit.UnitGroup = UnitGroups[TempUnit[A].Player];
                            }
                            NewUnit.Pos.Horizontal.X = Convert.ToInt32(TempUnit[A].X);
                            //NewUnit.Pos.Altitude = TempUnit(A).Y
                            NewUnit.Pos.Horizontal.Y = Convert.ToInt32(TempUnit[A].Z);
                            NewUnit.Rotation = Math.Min(Convert.ToInt32(TempUnit[A].Rotation), 359);
                            if ( TempUnit[A].ID == 0U )
                            {
                                TempUnit[A].ID = AvailableID;
                                App.ZeroIDWarning(NewUnit, TempUnit[A].ID, ReturnResult);
                            }
                            UnitAdd.ID = TempUnit[A].ID;
                            UnitAdd.NewUnit = NewUnit;
                            UnitAdd.Perform();
                            App.ErrorIDChange(TempUnit[A].ID, NewUnit, "Read_FMEv5+");
                            if ( AvailableID == TempUnit[A].ID )
                            {
                                AvailableID = NewUnit.ID + 1U;
                            }
                        }
                        else
                        {
                            WarningCount++;
                        }
                    }
                    if ( WarningCount > 0 )
                    {
                        ReturnResult.WarningAdd(WarningCount + " types of units were invalid. That many units were ignored.");
                    }

                    UInt32 NewGatewayCount = 0;
                    sXY_int NewGateStart = new sXY_int();
                    sXY_int NewGateFinish = new sXY_int();

                    NewGatewayCount = File.ReadUInt32();
                    WarningCount = 0;
                    for ( A = 0; A <= (Convert.ToInt32(NewGatewayCount)) - 1; A++ )
                    {
                        NewGateStart.X = File.ReadUInt16();
                        NewGateStart.Y = File.ReadUInt16();
                        NewGateFinish.X = File.ReadUInt16();
                        NewGateFinish.Y = File.ReadUInt16();
                        if ( GatewayCreate(NewGateStart, NewGateFinish) == null )
                        {
                            WarningCount++;
                        }
                    }
                    if ( WarningCount > 0 )
                    {
                        ReturnResult.WarningAdd(WarningCount + " gateways were invalid.");
                    }

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

                    //scroll limits
                    ResultInfo.ScrollMin.X = File.ReadInt32();
                    ResultInfo.ScrollMin.Y = File.ReadInt32();
                    ResultInfo.ScrollMax.X = File.ReadUInt32();
                    ResultInfo.ScrollMax.Y = File.ReadUInt32();

                    //other compile info

                    string strTemp = null;

                    ResultInfo.CompileName = IOUtil.ReadOldText(File);
                    byteTemp = File.ReadByte();
                    if ( byteTemp == ((byte)0) )
                    {
                        //no compile type
                    }
                    else if ( byteTemp == ((byte)1) )
                    {
                        //compile multi
                    }
                    else if ( byteTemp == ((byte)2) )
                    {
                        //compile campaign
                    }
                    else
                    {
                        //error
                    }
                    ResultInfo.CompileMultiPlayers = IOUtil.ReadOldText(File);
                    byteTemp = File.ReadByte();
                    if ( byteTemp == ((byte)0) )
                    {
                        ResultInfo.CompileMultiXPlayers = false;
                    }
                    else if ( byteTemp == ((byte)1) )
                    {
                        ResultInfo.CompileMultiXPlayers = true;
                    }
                    else
                    {
                        ReturnResult.WarningAdd("Compile player format out of range.");
                    }
                    ResultInfo.CompileMultiAuthor = IOUtil.ReadOldText(File);
                    ResultInfo.CompileMultiLicense = IOUtil.ReadOldText(File);
                    strTemp = IOUtil.ReadOldText(File); //game time
                    ResultInfo.CampaignGameType = File.ReadInt32();
                    if ( ResultInfo.CampaignGameType < -1 | ResultInfo.CampaignGameType >= Constants.GameTypeCount )
                    {
                        ReturnResult.WarningAdd("Compile campaign type out of range.");
                        ResultInfo.CampaignGameType = -1;
                    }

                    if ( File.PeekChar() >= 0 )
                    {
                        ReturnResult.WarningAdd("There were unread bytes at the end of the file.");
                    }
                }
                else
                {
                    ReturnResult.ProblemAdd("File version number not recognised.");
                }

                InterfaceOptions = ResultInfo;
            }
            catch ( Exception ex )
            {
                ReturnResult.ProblemAdd("Read error: " + ex.Message);
            }

            return ReturnResult;
        }
示例#2
0
        public void InitializeUserInput()
        {
            if ( _ReadyForUserInput )
            {
                return;
            }

            _ReadyForUserInput = true;

            int X = 0;
            int Y = 0;

            SectorCount.X = (int)(Math.Ceiling((double)(Terrain.TileSize.X / Constants.SectorTileSize)));
            SectorCount.Y = (int)(Math.Ceiling((double)(Terrain.TileSize.Y / Constants.SectorTileSize)));
            Sectors = new clsSector[SectorCount.X, SectorCount.Y];
            for ( Y = 0; Y <= SectorCount.Y - 1; Y++ )
            {
                for ( X = 0; X <= SectorCount.X - 1; X++ )
                {
                    Sectors[X, Y] = new clsSector(new sXY_int(X, Y));
                }
            }

            clsUnit Unit = default(clsUnit);
            foreach ( clsUnit tempLoopVar_Unit in Units )
            {
                Unit = tempLoopVar_Unit;
                UnitSectorsCalc(Unit);
            }

            ShadowSectors = new clsShadowSector[SectorCount.X, SectorCount.Y];
            for ( Y = 0; Y <= SectorCount.Y - 1; Y++ )
            {
                for ( X = 0; X <= SectorCount.X - 1; X++ )
                {
                    ShadowSector_Create(new sXY_int(X, Y));
                }
            }

            SectorGraphicsChanges = new clsSectorChanges(this);
            SectorGraphicsChanges.SetAllChanged();
            SectorUnitHeightsChanges = new clsSectorChanges(this);
            SectorTerrainUndoChanges = new clsSectorChanges(this);
            AutoTextureChanges = new clsAutoTextureChanges(this);
            TerrainInterpretChanges = new clsTerrainUpdate(Terrain.TileSize);

            UnitChanges = new SimpleClassList<clsUnitChange>();
            UnitChanges.MaintainOrder = true;
            GatewayChanges = new SimpleClassList<clsGatewayChange>();
            GatewayChanges.MaintainOrder = true;
            Undos = new SimpleClassList<clsUndo>();
            Undos.MaintainOrder = true;
            UndoPosition = 0;

            SelectedUnits = new ConnectedList<clsUnit, clsMap>(this);

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

            ViewInfo = new clsViewInfo(this, Program.frmMainInstance.MapViewControl);

            _SelectedUnitGroup = new clsUnitGroupContainer();
            SelectedUnitGroup.Item = ScavengerUnitGroup;

            Messages = new SimpleClassList<clsMessage>();
            Messages.MaintainOrder = true;
        }
示例#3
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;
        }