Esempio n. 1
0
        public void Finish()
        {
            if (!Started)
            {
                Debugger.Break();
                return;
            }

            var A       = 0;
            var UnitAdd = new clsUnitAdd();
            var Unit    = default(Unit);

            UnitAdd.Map         = Map;
            UnitAdd.StoreChange = true;

            for (A = 0; A <= OldUnitCount - 1; A++)
            {
                Unit        = OldUnits[A];
                NewAltitude = Map.GetTerrainHeight(Unit.Pos.Horizontal).ToInt();
                if (NewAltitude != Unit.Pos.Altitude)
                {
                    NewUnit = new Unit(Unit, Map);
                    ID      = Unit.ID;
                    //NewUnit.Pos.Altitude = NewAltitude
                    //these create changed sectors and must be done before drawing the new sectors
                    Map.UnitRemoveStoreChange(Unit.MapLink.ArrayPosition);
                    UnitAdd.NewUnit = NewUnit;
                    UnitAdd.ID      = ID;
                    UnitAdd.Perform();
                    App.ErrorIDChange(ID, NewUnit, "UpdateSectorUnitHeights");
                }
            }

            Started = false;
        }
Esempio n. 2
0
        public void UnitSwap(Unit OldUnit, Unit NewUnit)
        {
            if (OldUnit.MapLink.Source != this)
            {
                Debugger.Break();
                return;
            }

            UnitRemoveStoreChange(OldUnit.MapLink.ArrayPosition);
            var UnitAdd = new clsUnitAdd();

            UnitAdd.Map         = this;
            UnitAdd.StoreChange = true;
            UnitAdd.ID          = OldUnit.ID;
            UnitAdd.NewUnit     = NewUnit;
            UnitAdd.Label       = OldUnit.Label;
            UnitAdd.Perform();
            App.ErrorIDChange(OldUnit.ID, NewUnit, "UnitSwap");
        }
Esempio n. 3
0
        public void MapInsert(clsMap MapToInsert, sXY_int Offset, sXY_int Area, bool InsertHeights, bool InsertTextures, bool InsertUnits,
            bool DeleteUnits, bool InsertGateways, bool DeleteGateways)
        {
            sXY_int Finish = new sXY_int();
            int X = 0;
            int Y = 0;
            sXY_int SectorStart = new sXY_int();
            sXY_int SectorFinish = new sXY_int();
            sXY_int AreaAdjusted = new sXY_int();
            sXY_int SectorNum = new sXY_int();

            Finish.X = Math.Min(Offset.X + Math.Min(Area.X, MapToInsert.Terrain.TileSize.X), Terrain.TileSize.X);
            Finish.Y = Math.Min(Offset.Y + Math.Min(Area.Y, MapToInsert.Terrain.TileSize.Y), Terrain.TileSize.Y);
            AreaAdjusted.X = Finish.X - Offset.X;
            AreaAdjusted.Y = Finish.Y - Offset.Y;

            GetTileSectorRange(new sXY_int(Offset.X - 1, Offset.Y - 1), Finish, ref SectorStart, ref SectorFinish);
            for ( Y = SectorStart.Y; Y <= SectorFinish.Y; Y++ )
            {
                SectorNum.Y = Y;
                for ( X = SectorStart.X; X <= SectorFinish.X; X++ )
                {
                    SectorNum.X = X;
                    SectorGraphicsChanges.Changed(SectorNum);
                    SectorUnitHeightsChanges.Changed(SectorNum);
                    SectorTerrainUndoChanges.Changed(SectorNum);
                }
            }

            if ( InsertHeights )
            {
                for ( Y = 0; Y <= AreaAdjusted.Y; Y++ )
                {
                    for ( X = 0; X <= AreaAdjusted.X; X++ )
                    {
                        Terrain.Vertices[Offset.X + X, Offset.Y + Y].Height = MapToInsert.Terrain.Vertices[X, Y].Height;
                    }
                }
                for ( Y = 0; Y <= AreaAdjusted.Y - 1; Y++ )
                {
                    for ( X = 0; X <= AreaAdjusted.X - 1; X++ )
                    {
                        Terrain.Tiles[Offset.X + X, Offset.Y + Y].Tri = MapToInsert.Terrain.Tiles[X, Y].Tri;
                    }
                }
            }
            if ( InsertTextures )
            {
                for ( Y = 0; Y <= AreaAdjusted.Y; Y++ )
                {
                    for ( X = 0; X <= AreaAdjusted.X; X++ )
                    {
                        Terrain.Vertices[Offset.X + X, Offset.Y + Y].Terrain = MapToInsert.Terrain.Vertices[X, Y].Terrain;
                    }
                }
                bool TriDirection = default(bool);
                for ( Y = 0; Y <= AreaAdjusted.Y - 1; Y++ )
                {
                    for ( X = 0; X <= AreaAdjusted.X - 1; X++ )
                    {
                        TriDirection = Terrain.Tiles[Offset.X + X, Offset.Y + Y].Tri;
                        Terrain.Tiles[Offset.X + X, Offset.Y + Y].Copy(MapToInsert.Terrain.Tiles[X, Y]);
                        Terrain.Tiles[Offset.X + X, Offset.Y + Y].Tri = TriDirection;
                    }
                }
                for ( Y = 0; Y <= AreaAdjusted.Y; Y++ )
                {
                    for ( X = 0; X <= AreaAdjusted.X - 1; X++ )
                    {
                        Terrain.SideH[Offset.X + X, Offset.Y + Y].Road = MapToInsert.Terrain.SideH[X, Y].Road;
                    }
                }
                for ( Y = 0; Y <= AreaAdjusted.Y - 1; Y++ )
                {
                    for ( X = 0; X <= AreaAdjusted.X; X++ )
                    {
                        Terrain.SideV[Offset.X + X, Offset.Y + Y].Road = MapToInsert.Terrain.SideV[X, Y].Road;
                    }
                }
            }

            sXY_int LastTile = new sXY_int();
            LastTile = Finish;
            LastTile.X--;
            LastTile.Y--;
            if ( DeleteGateways )
            {
                int A = 0;
                A = 0;
                while ( A < Gateways.Count )
                {
                    if ( Gateways[A].PosA.IsInRange(Offset, LastTile) || Gateways[A].PosB.IsInRange(Offset, LastTile) )
                    {
                        GatewayRemoveStoreChange(A);
                    }
                    else
                    {
                        A++;
                    }
                }
            }
            if ( InsertGateways )
            {
                sXY_int GateStart = new sXY_int();
                sXY_int GateFinish = new sXY_int();
                clsGateway Gateway = default(clsGateway);
                foreach ( clsGateway tempLoopVar_Gateway in MapToInsert.Gateways )
                {
                    Gateway = tempLoopVar_Gateway;
                    GateStart.X = Offset.X + Gateway.PosA.X;
                    GateStart.Y = Offset.Y + Gateway.PosA.Y;
                    GateFinish.X = Offset.X + Gateway.PosB.X;
                    GateFinish.Y = Offset.Y + Gateway.PosB.Y;
                    if ( GateStart.IsInRange(Offset, LastTile) || GateFinish.IsInRange(Offset, LastTile) )
                    {
                        GatewayCreateStoreChange(GateStart, GateFinish);
                    }
                }
            }

            if ( DeleteUnits )
            {
                SimpleList<clsUnit> UnitsToDelete = new SimpleList<clsUnit>();
                int UnitToDeleteCount = 0;
                clsUnit Unit = default(clsUnit);
                for ( Y = SectorStart.Y; Y <= SectorFinish.Y; Y++ )
                {
                    for ( X = SectorStart.X; X <= SectorFinish.X; X++ )
                    {
                        clsUnitSectorConnection Connection = default(clsUnitSectorConnection);
                        foreach ( clsUnitSectorConnection tempLoopVar_Connection in Sectors[X, Y].Units )
                        {
                            Connection = tempLoopVar_Connection;
                            Unit = Connection.Unit;
                            if ( App.PosIsWithinTileArea(Unit.Pos.Horizontal, Offset, Finish) )
                            {
                                UnitsToDelete.Add(Unit);
                            }
                        }
                    }
                }
                foreach ( clsUnit tempLoopVar_Unit in UnitsToDelete )
                {
                    Unit = tempLoopVar_Unit;
                    if ( Unit.MapLink.IsConnected ) //units may be in the list multiple times and already be deleted
                    {
                        UnitRemoveStoreChange(Unit.MapLink.ArrayPosition);
                    }
                }
            }
            if ( InsertUnits )
            {
                sXY_int PosDif = new sXY_int();
                clsUnit NewUnit = default(clsUnit);
                clsUnit Unit = default(clsUnit);
                sXY_int ZeroPos = new sXY_int(0, 0);
                clsUnitAdd UnitAdd = new clsUnitAdd();

                UnitAdd.Map = this;
                UnitAdd.StoreChange = true;

                PosDif.X = Offset.X * App.TerrainGridSpacing;
                PosDif.Y = Offset.Y * App.TerrainGridSpacing;
                foreach ( clsUnit tempLoopVar_Unit in MapToInsert.Units )
                {
                    Unit = tempLoopVar_Unit;
                    if ( App.PosIsWithinTileArea(Unit.Pos.Horizontal, ZeroPos, AreaAdjusted) )
                    {
                        NewUnit = new clsUnit(Unit, this);
                        NewUnit.Pos.Horizontal.X += PosDif.X;
                        NewUnit.Pos.Horizontal.Y += PosDif.Y;
                        UnitAdd.NewUnit = NewUnit;
                        UnitAdd.Label = Unit.Label;
                        UnitAdd.Perform();
                    }
                }
            }

            SectorsUpdateGraphics();
            SectorsUpdateUnitHeights();
            MinimapMakeLater();
        }
Esempio n. 4
0
        public clsMap(clsMap MapToCopy, sXY_int Offset, sXY_int Area)
        {
            frmMainLink = new ConnectedListLink<clsMap, frmMain>(this);
            Gateways = new ConnectedList<clsGateway, clsMap>(this);

            int EndX = 0;
            int EndY = 0;
            int X = 0;
            int Y = 0;

            Initialize();

            //make some map data for selection

            EndX = Math.Min(MapToCopy.Terrain.TileSize.X - Offset.X, Area.X);
            EndY = Math.Min(MapToCopy.Terrain.TileSize.Y - Offset.Y, Area.Y);

            Terrain = new clsTerrain(Area);

            for ( Y = 0; Y <= Terrain.TileSize.Y - 1; Y++ )
            {
                for ( X = 0; X <= Terrain.TileSize.X - 1; X++ )
                {
                    Terrain.Tiles[X, Y].Texture.TextureNum = -1;
                }
            }

            for ( Y = 0; Y <= EndY; Y++ )
            {
                for ( X = 0; X <= EndX; X++ )
                {
                    Terrain.Vertices[X, Y].Height = MapToCopy.Terrain.Vertices[Offset.X + X, Offset.Y + Y].Height;
                    Terrain.Vertices[X, Y].Terrain = MapToCopy.Terrain.Vertices[Offset.X + X, Offset.Y + Y].Terrain;
                }
            }
            for ( Y = 0; Y <= EndY - 1; Y++ )
            {
                for ( X = 0; X <= EndX - 1; X++ )
                {
                    Terrain.Tiles[X, Y].Copy(MapToCopy.Terrain.Tiles[Offset.X + X, Offset.Y + Y]);
                }
            }
            for ( Y = 0; Y <= EndY; Y++ )
            {
                for ( X = 0; X <= EndX - 1; X++ )
                {
                    Terrain.SideH[X, Y].Road = MapToCopy.Terrain.SideH[Offset.X + X, Offset.Y + Y].Road;
                }
            }
            for ( Y = 0; Y <= EndY - 1; Y++ )
            {
                for ( X = 0; X <= EndX; X++ )
                {
                    Terrain.SideV[X, Y].Road = MapToCopy.Terrain.SideV[Offset.X + X, Offset.Y + Y].Road;
                }
            }

            SectorCount.X = (int)(Math.Ceiling((double)(Area.X / Constants.SectorTileSize)));
            SectorCount.Y = (int)(Math.Ceiling((double)(Area.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));
                }
            }

            sXY_int PosDif = new sXY_int();
            clsUnitAdd NewUnitAdd = new clsUnitAdd();
            NewUnitAdd.Map = this;
            clsUnit NewUnit = default(clsUnit);

            clsGateway Gateway = default(clsGateway);
            foreach ( clsGateway tempLoopVar_Gateway in MapToCopy.Gateways )
            {
                Gateway = tempLoopVar_Gateway;
                GatewayCreate(new sXY_int(Gateway.PosA.X - Offset.X, Gateway.PosA.Y - Offset.Y),
                    new sXY_int(Gateway.PosB.X - Offset.X, Gateway.PosB.Y - Offset.Y));
            }

            PosDif.X = - Offset.X * App.TerrainGridSpacing;
            PosDif.Y = - Offset.Y * App.TerrainGridSpacing;
            clsUnit Unit = default(clsUnit);
            sXY_int NewPos = new sXY_int();
            foreach ( clsUnit tempLoopVar_Unit in MapToCopy.Units )
            {
                Unit = tempLoopVar_Unit;
                NewPos = Unit.Pos.Horizontal + PosDif;
                if ( PosIsOnMap(NewPos) )
                {
                    NewUnit = new clsUnit(Unit, this);
                    NewUnit.Pos.Horizontal = NewPos;
                    NewUnitAdd.NewUnit = NewUnit;
                    NewUnitAdd.Label = Unit.Label;
                    NewUnitAdd.Perform();
                }
            }
        }
Esempio n. 5
0
            public void Finish()
            {
                if ( !Started )
                {
                    Debugger.Break();
                    return;
                }

                int A = 0;
                clsUnitAdd UnitAdd = new clsUnitAdd();
                clsUnit Unit = default(clsUnit);

                UnitAdd.Map = Map;
                UnitAdd.StoreChange = true;

                for ( A = 0; A <= OldUnitCount - 1; A++ )
                {
                    Unit = OldUnits[A];
                    NewAltitude = (int)(Map.GetTerrainHeight(Unit.Pos.Horizontal));
                    if ( NewAltitude != Unit.Pos.Altitude )
                    {
                        NewUnit = new clsUnit(Unit, Map);
                        ID = Unit.ID;
                        //NewUnit.Pos.Altitude = NewAltitude
                        //these create changed sectors and must be done before drawing the new sectors
                        Map.UnitRemoveStoreChange(Unit.MapLink.ArrayPosition);
                        UnitAdd.NewUnit = NewUnit;
                        UnitAdd.ID = ID;
                        UnitAdd.Perform();
                        App.ErrorIDChange(ID, NewUnit, "UpdateSectorUnitHeights");
                    }
                }

                Started = false;
            }
Esempio n. 6
0
        public void UndoPerform()
        {
            clsUndo ThisUndo = default(clsUndo);

            UndoStepCreate("Incomplete Action"); //make another redo step incase something has changed, such as if user presses undo while still dragging a tool

            UndoPosition--;

            ThisUndo = Undos[UndoPosition];

            sXY_int SectorNum = new sXY_int();
            clsShadowSector CurrentSector = default(clsShadowSector);
            clsShadowSector UndoSector = default(clsShadowSector);
            SimpleList<clsShadowSector> NewSectorsForThisUndo = new SimpleList<clsShadowSector>();
            foreach ( clsShadowSector tempLoopVar_UndoSector in ThisUndo.ChangedSectors )
            {
                UndoSector = tempLoopVar_UndoSector;
                SectorNum = UndoSector.Num;
                //store existing state for redo
                CurrentSector = ShadowSectors[SectorNum.X, SectorNum.Y];
                //remove graphics from sector
                Sectors[SectorNum.X, SectorNum.Y].DeleteLists();
                //perform the undo
                Undo_Sector_Rejoin(UndoSector);
                //update the backup
                ShadowSector_Create(SectorNum);
                //add old state to the redo step (that was this undo step)
                NewSectorsForThisUndo.Add(CurrentSector);
                //prepare to update graphics on this sector
                SectorGraphicsChanges.Changed(SectorNum);
            }
            ThisUndo.ChangedSectors = NewSectorsForThisUndo;

            UInt32 ID = 0;
            clsUnitAdd UnitAdd = new clsUnitAdd();
            UnitAdd.Map = this;
            clsUnit Unit = default(clsUnit);
            for ( int A = ThisUndo.UnitChanges.Count - 1; A >= 0; A-- ) //must do in reverse order, otherwise may try to delete units that havent been added yet
            {
                Unit = ThisUndo.UnitChanges[A].Unit;
                if ( ThisUndo.UnitChanges[A].Type == clsUnitChange.enumType.Added )
                {
                    //remove the unit from the map
                    UnitRemove(Unit.MapLink.ArrayPosition);
                }
                else if ( ThisUndo.UnitChanges[A].Type == clsUnitChange.enumType.Deleted )
                {
                    //add the unit back on to the map
                    ID = Unit.ID;
                    UnitAdd.ID = ID;
                    UnitAdd.NewUnit = Unit;
                    UnitAdd.Perform();
                    App.ErrorIDChange(ID, Unit, "Undo_Perform");
                }
                else
                {
                    Debugger.Break();
                }
            }

            clsGatewayChange GatewayChange = default(clsGatewayChange);
            for ( int A = ThisUndo.GatewayChanges.Count - 1; A >= 0; A-- )
            {
                GatewayChange = ThisUndo.GatewayChanges[A];
                switch ( GatewayChange.Type )
                {
                    case clsGatewayChange.enumType.Added:
                        //remove the unit from the map
                        GatewayChange.Gateway.MapLink.Disconnect();
                        break;
                    case clsGatewayChange.enumType.Deleted:
                        //add the unit back on to the map
                        GatewayChange.Gateway.MapLink.Connect(Gateways);
                        break;
                    default:
                        Debugger.Break();
                        break;
                }
            }

            SectorsUpdateGraphics();
            MinimapMakeLater();
            Program.frmMainInstance.SelectedObject_Changed();
        }
Esempio n. 7
0
        public void RedoPerform()
        {
            clsUndo ThisUndo = default(clsUndo);

            ThisUndo = Undos[UndoPosition];

            sXY_int SectorNum = new sXY_int();
            clsShadowSector CurrentSector = default(clsShadowSector);
            clsShadowSector UndoSector = default(clsShadowSector);
            SimpleList<clsShadowSector> NewSectorsForThisUndo = new SimpleList<clsShadowSector>();
            foreach ( clsShadowSector tempLoopVar_UndoSector in ThisUndo.ChangedSectors )
            {
                UndoSector = tempLoopVar_UndoSector;
                SectorNum = UndoSector.Num;
                //store existing state for undo
                CurrentSector = ShadowSectors[SectorNum.X, SectorNum.Y];
                //remove graphics from sector
                Sectors[SectorNum.X, SectorNum.Y].DeleteLists();
                //perform the redo
                Undo_Sector_Rejoin(UndoSector);
                //update the backup
                ShadowSector_Create(SectorNum);
                //add old state to the undo step (that was this redo step)
                NewSectorsForThisUndo.Add(CurrentSector);
                //prepare to update graphics on this sector
                SectorGraphicsChanges.Changed(SectorNum);
            }
            ThisUndo.ChangedSectors = NewSectorsForThisUndo;

            UInt32 ID = 0;
            clsUnitAdd UnitAdd = new clsUnitAdd();
            UnitAdd.Map = this;
            clsUnit Unit = default(clsUnit);
            for ( int A = 0; A <= ThisUndo.UnitChanges.Count - 1; A++ ) //forward order is important
            {
                Unit = ThisUndo.UnitChanges[A].Unit;
                if ( ThisUndo.UnitChanges[A].Type == clsUnitChange.enumType.Added )
                {
                    //add the unit back on to the map
                    ID = Unit.ID;
                    UnitAdd.ID = ID;
                    UnitAdd.NewUnit = Unit;
                    UnitAdd.Perform();
                    App.ErrorIDChange(ID, Unit, "Redo_Perform");
                }
                else if ( ThisUndo.UnitChanges[A].Type == clsUnitChange.enumType.Deleted )
                {
                    //remove the unit from the map
                    UnitRemove(Unit.MapLink.ArrayPosition);
                }
                else
                {
                    Debugger.Break();
                }
            }

            clsGatewayChange GatewayChange = default(clsGatewayChange);
            for ( int A = 0; A <= ThisUndo.GatewayChanges.Count - 1; A++ ) //forward order is important
            {
                GatewayChange = ThisUndo.GatewayChanges[A];
                switch ( GatewayChange.Type )
                {
                    case clsGatewayChange.enumType.Added:
                        //add the unit back on to the map
                        GatewayChange.Gateway.MapLink.Connect(Gateways);
                        break;
                    case clsGatewayChange.enumType.Deleted:
                        //remove the unit from the map
                        GatewayChange.Gateway.MapLink.Disconnect();
                        break;
                    default:
                        Debugger.Break();
                        break;
                }
            }

            UndoPosition++;

            SectorsUpdateGraphics();
            MinimapMakeLater();
            Program.frmMainInstance.SelectedObject_Changed();
        }
Esempio n. 8
0
        public void PerformTileWall(clsWallType WallType, sXY_int TileNum, bool Expand)
        {
            sXY_int SectorNum = new sXY_int();
            clsUnit Unit = default(clsUnit);
            sXY_int UnitTile = new sXY_int();
            sXY_int Difference = new sXY_int();
            App.enumTileWalls TileWalls = App.enumTileWalls.None;
            SimpleList<clsUnit> Walls = new SimpleList<clsUnit>();
            SimpleList<clsUnit> Removals = new SimpleList<clsUnit>();
            clsUnitType UnitType = default(clsUnitType);
            clsStructureType StructureType = default(clsStructureType);
            int X = 0;
            int Y = 0;
            sXY_int MinTile = new sXY_int();
            sXY_int MaxTile = new sXY_int();
            clsUnitSectorConnection Connection = default(clsUnitSectorConnection);
            MinTile.X = TileNum.X - 1;
            MinTile.Y = TileNum.Y - 1;
            MaxTile.X = TileNum.X + 1;
            MaxTile.Y = TileNum.Y + 1;
            sXY_int SectorStart = GetSectorNumClamped(GetTileSectorNum(MinTile));
            sXY_int SectorFinish = GetSectorNumClamped(GetTileSectorNum(MaxTile));

            for ( Y = SectorStart.Y; Y <= SectorFinish.Y; Y++ )
            {
                for ( X = SectorStart.X; X <= SectorFinish.X; X++ )
                {
                    SectorNum.X = X;
                    SectorNum.Y = Y;
                    foreach ( clsUnitSectorConnection tempLoopVar_Connection in Sectors[SectorNum.X, SectorNum.Y].Units )
                    {
                        Connection = tempLoopVar_Connection;
                        Unit = Connection.Unit;
                        UnitType = Unit.Type;
                        if ( UnitType.Type == clsUnitType.enumType.PlayerStructure )
                        {
                            StructureType = (clsStructureType)UnitType;
                            if ( StructureType.WallLink.Source == WallType )
                            {
                                UnitTile = GetPosTileNum(Unit.Pos.Horizontal);
                                Difference.X = UnitTile.X - TileNum.X;
                                Difference.Y = UnitTile.Y - TileNum.Y;
                                if ( Difference.Y == 1 )
                                {
                                    if ( Difference.X == 0 )
                                    {
                                        TileWalls = (App.enumTileWalls)(TileWalls | App.enumTileWalls.Bottom);
                                        Walls.Add(Unit);
                                    }
                                }
                                else if ( Difference.Y == 0 )
                                {
                                    if ( Difference.X == 0 )
                                    {
                                        Removals.Add(Unit);
                                    }
                                    else if ( Difference.X == -1 )
                                    {
                                        TileWalls = (App.enumTileWalls)(TileWalls | App.enumTileWalls.Left);
                                        Walls.Add(Unit);
                                    }
                                    else if ( Difference.X == 1 )
                                    {
                                        TileWalls = (App.enumTileWalls)(TileWalls | App.enumTileWalls.Right);
                                        Walls.Add(Unit);
                                    }
                                }
                                else if ( Difference.Y == -1 )
                                {
                                    if ( Difference.X == 0 )
                                    {
                                        TileWalls = (App.enumTileWalls)(TileWalls | App.enumTileWalls.Top);
                                        Walls.Add(Unit);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            foreach ( clsUnit tempLoopVar_Unit in Removals )
            {
                Unit = tempLoopVar_Unit;
                UnitRemoveStoreChange(Unit.MapLink.ArrayPosition);
            }

            clsUnit NewUnit = new clsUnit();
            clsUnitType NewUnitType = WallType.Segments[WallType.TileWalls_Segment[(int)TileWalls]];
            NewUnit.Rotation = WallType.TileWalls_Direction[(int)TileWalls];
            if ( Expand )
            {
                NewUnit.UnitGroup = SelectedUnitGroup.Item;
            }
            else
            {
                if ( Removals.Count == 0 )
                {
                    Debugger.Break();
                    return;
                }
                NewUnit.UnitGroup = Removals[0].UnitGroup;
            }
            NewUnit.Pos = TileAlignedPos(TileNum, new sXY_int(1, 1));
            NewUnit.Type = NewUnitType;
            clsUnitAdd UnitAdd = new clsUnitAdd();
            UnitAdd.Map = this;
            UnitAdd.NewUnit = NewUnit;
            UnitAdd.StoreChange = true;
            UnitAdd.Perform();

            if ( Expand )
            {
                clsUnit Wall = default(clsUnit);
                foreach ( clsUnit tempLoopVar_Wall in Walls )
                {
                    Wall = tempLoopVar_Wall;
                    PerformTileWall(WallType, GetPosTileNum(Wall.Pos.Horizontal), false);
                }
            }
        }
Esempio n. 9
0
        public Result Load(string path)
        {
            var returnResult =
                new Result("Loading LND from \"{0}\"".Format2(path), false);

            logger.Info("Loading LND from \"{0}\"".Format2(path));
            try
            {
                var strTemp  = "";
                var strTemp2 = "";
                var X        = 0;
                var Y        = 0;
                var A        = 0;
                var B        = 0;
                var Tile_Num = 0;
                // SimpleList<string> LineData = default(SimpleList<string>);
                var       Line_Num   = 0;
                LNDTile[] LNDTile    = null;
                var       LNDObjects = new SimpleList <LNDObject>();
                var       UnitAdd    = new clsUnitAdd();

                UnitAdd.Map = map;

                var Reader = default(BinaryReader);
                try
                {
                    Reader = new BinaryReader(new FileStream(path, FileMode.Open), App.UTF8Encoding);
                }
                catch (Exception ex)
                {
                    returnResult.ProblemAdd(ex.Message);
                    return(returnResult);
                }
                var LineData = IOUtil.BytesToLinesRemoveComments(Reader);
                Reader.Close();

                Array.Resize(ref LNDTile, LineData.Count);

                var    strTemp3         = "";
                var    GotTiles         = default(bool);
                var    GotObjects       = default(bool);
                var    GotGates         = default(bool);
                var    GotTileTypes     = default(bool);
                var    LNDTileType      = new byte[0];
                var    ObjectText       = new string[11];
                var    GateText         = new string[4];
                var    TileTypeText     = new string[256];
                var    LNDTileTypeCount = 0;
                var    LNDGates         = new SimpleList <Gateway>();
                var    Gateway          = default(Gateway);
                var    C           = 0;
                var    D           = 0;
                var    GotText     = default(bool);
                var    FlipX       = default(bool);
                var    FlipZ       = default(bool);
                byte   Rotation    = 0;
                var    NewTileSize = new XYInt();
                double dblTemp     = 0;

                Line_Num = 0;
                while (Line_Num < LineData.Count)
                {
                    strTemp = LineData[Line_Num];

                    A = strTemp.IndexOf("TileWidth ") + 1;
                    if (A == 0)
                    {
                    }

                    A = strTemp.IndexOf("TileHeight ") + 1;
                    if (A == 0)
                    {
                    }

                    A = strTemp.IndexOf("MapWidth ") + 1;
                    if (A == 0)
                    {
                    }
                    else
                    {
                        IOUtil.InvariantParse(strTemp.Substring(strTemp.Length - (strTemp.Length - (A + 8)), strTemp.Length - (A + 8)), ref NewTileSize.X);
                        goto LineDone;
                    }

                    A = strTemp.IndexOf("MapHeight ") + 1;
                    if (A == 0)
                    {
                    }
                    else
                    {
                        IOUtil.InvariantParse(strTemp.Substring(strTemp.Length - (strTemp.Length - (A + 9)), strTemp.Length - (A + 9)), ref NewTileSize.Y);
                        goto LineDone;
                    }

                    A = strTemp.IndexOf("Textures {") + 1;
                    if (A == 0)
                    {
                    }
                    else
                    {
                        Line_Num++;
                        strTemp = LineData[Line_Num];

                        strTemp2 = strTemp.ToLower();
                        if (strTemp2.IndexOf("tertilesc1") + 1 > 0)
                        {
                            map.Tileset = App.Tileset_Arizona;
                        }
                        if (strTemp2.IndexOf("tertilesc2") + 1 > 0)
                        {
                            map.Tileset = App.Tileset_Urban;
                        }
                        if (strTemp2.IndexOf("tertilesc3") + 1 > 0)
                        {
                            map.Tileset = App.Tileset_Rockies;
                        }

                        goto LineDone;
                    }

                    A = strTemp.IndexOf("Tiles {") + 1;
                    if (A == 0 || GotTiles)
                    {
                    }
                    else
                    {
                        Line_Num++;
                        while (Line_Num < LineData.Count)
                        {
                            strTemp = LineData[Line_Num];

                            A = strTemp.IndexOf("}") + 1;
                            if (A == 0)
                            {
                                A = strTemp.IndexOf("TID ") + 1;
                                if (A == 0)
                                {
                                    returnResult.ProblemAdd("Tile ID missing");
                                    return(returnResult);
                                }
                                strTemp2 = strTemp.Substring(strTemp.Length - (strTemp.Length - A - 3), strTemp.Length - A - 3);
                                A        = strTemp2.IndexOf(" ") + 1;
                                if (A > 0)
                                {
                                    strTemp2 = strTemp2.Substring(0, A - 1);
                                }
                                var temp_Result = LNDTile[Tile_Num].TID;
                                IOUtil.InvariantParse(strTemp2, ref temp_Result);

                                A = strTemp.IndexOf("VF ") + 1;
                                if (A == 0)
                                {
                                    returnResult.ProblemAdd("Tile VF missing");
                                    return(returnResult);
                                }
                                strTemp2 = strTemp.Substring(strTemp.Length - (strTemp.Length - A - 2), strTemp.Length - A - 2);
                                A        = strTemp2.IndexOf(" ") + 1;
                                if (A > 0)
                                {
                                    strTemp2 = strTemp2.Substring(0, A - 1);
                                }
                                var temp_Result2 = LNDTile[Tile_Num].VF;
                                IOUtil.InvariantParse(strTemp2, ref temp_Result2);

                                A = strTemp.IndexOf("TF ") + 1;
                                if (A == 0)
                                {
                                    returnResult.ProblemAdd("Tile TF missing");
                                    return(returnResult);
                                }
                                strTemp2 = strTemp.Substring(strTemp.Length - (strTemp.Length - A - 2), strTemp.Length - A - 2);
                                A        = strTemp2.IndexOf(" ") + 1;
                                if (A > 0)
                                {
                                    strTemp2 = strTemp2.Substring(0, A - 1);
                                }
                                var temp_Result3 = LNDTile[Tile_Num].TF;
                                IOUtil.InvariantParse(strTemp2, ref temp_Result3);

                                A = strTemp.IndexOf(" F ") + 1;
                                if (A == 0)
                                {
                                    returnResult.ProblemAdd("Tile flip missing");
                                    return(returnResult);
                                }
                                strTemp2 = strTemp.Substring(strTemp.Length - A - 2, strTemp.Length - A - 2);
                                A        = strTemp2.IndexOf(" ");
                                if (A > 0)
                                {
                                    strTemp2 = strTemp2.Substring(0, A);
                                }
                                var temp_Result4 = LNDTile[Tile_Num].F;
                                IOUtil.InvariantParse(strTemp2, ref temp_Result4);

                                A = strTemp.IndexOf(" VH ") + 1;
                                if (A == 0)
                                {
                                    returnResult.ProblemAdd("Tile height is missing");
                                    return(returnResult);
                                }
                                strTemp3 = strTemp.Substring(strTemp.Length - (strTemp.Length - A - 3), strTemp.Length - A - 3);
                                for (A = 0; A <= 2; A++)
                                {
                                    B = strTemp3.IndexOf(" ") + 1;
                                    if (B == 0)
                                    {
                                        returnResult.ProblemAdd("A tile height value is missing");
                                        return(returnResult);
                                    }
                                    strTemp2 = strTemp3.Substring(0, B - 1);
                                    strTemp3 = strTemp3.Substring(strTemp3.Length - (strTemp3.Length - B), strTemp3.Length - B);

                                    if (A == 0)
                                    {
                                        var temp_Result5 = LNDTile[Tile_Num].Vertex0Height;
                                        IOUtil.InvariantParse(strTemp2, ref temp_Result5);
                                    }
                                    else if (A == 1)
                                    {
                                        var temp_Result6 = LNDTile[Tile_Num].Vertex1Height;
                                        IOUtil.InvariantParse(strTemp2, ref temp_Result6);
                                    }
                                    else if (A == 2)
                                    {
                                        var temp_Result7 = LNDTile[Tile_Num].Vertex2Height;
                                        IOUtil.InvariantParse(strTemp2, ref temp_Result7);
                                    }
                                }
                                var temp_Result8 = LNDTile[Tile_Num].Vertex3Height;
                                IOUtil.InvariantParse(strTemp3, ref temp_Result8);

                                Tile_Num++;
                            }
                            else
                            {
                                GotTiles = true;
                                goto LineDone;
                            }

                            Line_Num++;
                        }

                        GotTiles = true;
                        goto LineDone;
                    }

                    A = strTemp.IndexOf("Objects {") + 1;
                    if (A == 0 || GotObjects)
                    {
                    }
                    else
                    {
                        Line_Num++;
                        while (Line_Num < LineData.Count)
                        {
                            strTemp = LineData[Line_Num];

                            A = strTemp.IndexOf("}") + 1;
                            if (A == 0)
                            {
                                C             = 0;
                                ObjectText[0] = "";
                                GotText       = false;
                                for (B = 0; B <= strTemp.Length - 1; B++)
                                {
                                    if (strTemp[B] != ' ' && strTemp[B] != '\t')
                                    {
                                        GotText        = true;
                                        ObjectText[C] += strTemp[B].ToString();
                                    }
                                    else
                                    {
                                        if (GotText)
                                        {
                                            C++;
                                            if (C == 11)
                                            {
                                                returnResult.ProblemAdd("Too many fields for an object, or a space at the end.");
                                                return(returnResult);
                                            }
                                            ObjectText[C] = "";
                                            GotText       = false;
                                        }
                                    }
                                }

                                var NewObject = new LNDObject();
                                IOUtil.InvariantParse(ObjectText[0], ref NewObject.ID);
                                IOUtil.InvariantParse(ObjectText[1], ref NewObject.TypeNum);
                                NewObject.Code = ObjectText[2].Substring(1, ObjectText[2].Length - 2); //remove quotes
                                IOUtil.InvariantParse(ObjectText[3], ref NewObject.PlayerNum);
                                NewObject.Name = ObjectText[4].Substring(1, ObjectText[4].Length - 2); //remove quotes
                                IOUtil.InvariantParse(ObjectText[5], ref NewObject.Pos.X);
                                IOUtil.InvariantParse(ObjectText[6], ref NewObject.Pos.Y);
                                IOUtil.InvariantParse(ObjectText[7], ref NewObject.Pos.Z);
                                if (IOUtil.InvariantParse(ObjectText[8], ref dblTemp))
                                {
                                    NewObject.Rotation.X = MathUtil.ClampDbl(dblTemp, 0.0D, 359.0D).ToInt();
                                }
                                if (IOUtil.InvariantParse(ObjectText[9], ref dblTemp))
                                {
                                    NewObject.Rotation.Y = MathUtil.ClampDbl(dblTemp, 0.0D, 359.0D).ToInt();
                                }
                                if (IOUtil.InvariantParse(ObjectText[10], ref dblTemp))
                                {
                                    NewObject.Rotation.Z = MathUtil.ClampDbl(dblTemp, 0.0D, 359.0D).ToInt();
                                }
                                LNDObjects.Add(NewObject);
                            }
                            else
                            {
                                GotObjects = true;
                                goto LineDone;
                            }

                            Line_Num++;
                        }

                        GotObjects = true;
                        goto LineDone;
                    }

                    A = strTemp.IndexOf("Gates {") + 1;
                    if (A == 0 || GotGates)
                    {
                    }
                    else
                    {
                        Line_Num++;
                        while (Line_Num < LineData.Count)
                        {
                            strTemp = LineData[Line_Num];

                            A = strTemp.IndexOf("}") + 1;
                            if (A == 0)
                            {
                                C           = 0;
                                GateText[0] = "";
                                GotText     = false;
                                for (B = 0; B <= strTemp.Length - 1; B++)
                                {
                                    if (strTemp[B] != ' ' && strTemp[B] != '\t')
                                    {
                                        GotText      = true;
                                        GateText[C] += strTemp[B].ToString();
                                    }
                                    else
                                    {
                                        if (GotText)
                                        {
                                            C++;
                                            if (C == 4)
                                            {
                                                returnResult.ProblemAdd("Too many fields for a gateway, or a space at the end.");
                                                return(returnResult);
                                            }
                                            GateText[C] = "";
                                            GotText     = false;
                                        }
                                    }
                                }

                                Gateway = new Gateway();
                                IOUtil.InvariantParse(GateText[0], ref Gateway.PosA.X);
                                Gateway.PosA.X = Math.Max(Gateway.PosA.X, 0);
                                IOUtil.InvariantParse(GateText[1], ref Gateway.PosA.Y);
                                Gateway.PosA.Y = Math.Max(Gateway.PosA.Y, 0);
                                IOUtil.InvariantParse(GateText[2], ref Gateway.PosB.X);
                                Gateway.PosB.X = Math.Max(Gateway.PosB.X, 0);
                                IOUtil.InvariantParse(GateText[3], ref Gateway.PosB.Y);
                                Gateway.PosB.Y = Math.Max(Gateway.PosB.Y, 0);
                                LNDGates.Add(Gateway);
                            }
                            else
                            {
                                GotGates = true;
                                goto LineDone;
                            }

                            Line_Num++;
                        }

                        GotGates = true;
                        goto LineDone;
                    }

                    A = strTemp.IndexOf("Tiles {") + 1;
                    if (A == 0 || GotTileTypes || !GotTiles)
                    {
                    }
                    else
                    {
                        Line_Num++;
                        while (Line_Num < LineData.Count)
                        {
                            strTemp = LineData[Line_Num];

                            A = strTemp.IndexOf("}") + 1;
                            if (A == 0)
                            {
                                C = 0;
                                TileTypeText[0] = "";
                                GotText         = false;
                                for (B = 0; B <= strTemp.Length - 1; B++)
                                {
                                    if (strTemp[B] != ' ' && strTemp[B] != '\t')
                                    {
                                        GotText          = true;
                                        TileTypeText[C] += strTemp[B].ToString();
                                    }
                                    else
                                    {
                                        if (GotText)
                                        {
                                            C++;
                                            if (C == 256)
                                            {
                                                returnResult.ProblemAdd("Too many fields for tile types.");
                                                return(returnResult);
                                            }
                                            TileTypeText[C] = "";
                                            GotText         = false;
                                        }
                                    }
                                }

                                if (TileTypeText[C] == "" || TileTypeText[C] == " ")
                                {
                                    C--;
                                }

                                for (D = 0; D <= C; D++)
                                {
                                    Array.Resize(ref LNDTileType, LNDTileTypeCount + 1);
                                    LNDTileType[LNDTileTypeCount] = Math.Min(byte.Parse(TileTypeText[D]), (byte)11);
                                    LNDTileTypeCount++;
                                }
                            }
                            else
                            {
                                GotTileTypes = true;
                                goto LineDone;
                            }

                            Line_Num++;
                        }

                        GotTileTypes = true;
                    }

LineDone:
                    Line_Num++;
                }

                Array.Resize(ref LNDTile, Tile_Num);

                map.SetPainterToDefaults();

                if (NewTileSize.X < 1 | NewTileSize.Y < 1)
                {
                    returnResult.ProblemAdd("The LND\'s terrain dimensions are missing or invalid.");
                    return(returnResult);
                }

                map.TerrainBlank(NewTileSize);
                map.TileType_Reset();

                for (Y = 0; Y <= map.Terrain.TileSize.Y - 1; Y++)
                {
                    for (X = 0; X <= map.Terrain.TileSize.X - 1; X++)
                    {
                        Tile_Num = Y * map.Terrain.TileSize.X + X;
                        //lnd uses different order! (3 = 2, 2 = 3), this program goes left to right, lnd goes clockwise around each tile
                        map.Terrain.Vertices[X, Y].Height = (byte)(LNDTile[Tile_Num].Vertex0Height);
                    }
                }

                for (Y = 0; Y <= map.Terrain.TileSize.Y - 1; Y++)
                {
                    for (X = 0; X <= map.Terrain.TileSize.X - 1; X++)
                    {
                        Tile_Num = Y * map.Terrain.TileSize.X + X;

                        map.Terrain.Tiles[X, Y].Texture.TextureNum = LNDTile[Tile_Num].TID - 1;

                        //ignore higher values
                        A = Math.Floor(LNDTile[Tile_Num].F / 64.0D).ToInt();
                        LNDTile[Tile_Num].F = Convert.ToInt16(LNDTile[Tile_Num].F - A * 64);

                        A = Math.Floor(LNDTile[Tile_Num].F / 16.0D).ToInt();
                        LNDTile[Tile_Num].F = Convert.ToInt16(LNDTile[Tile_Num].F - A * 16);
                        if (A < 0 | A > 3)
                        {
                            returnResult.ProblemAdd("Invalid flip value.");
                            return(returnResult);
                        }
                        Rotation = (byte)A;

                        A = Math.Floor(LNDTile[Tile_Num].F / 8.0D).ToInt();
                        LNDTile[Tile_Num].F -= (short)(A * 8);
                        FlipZ = A == 1;

                        A = Math.Floor(LNDTile[Tile_Num].F / 4.0D).ToInt();
                        LNDTile[Tile_Num].F -= (short)(A * 4);
                        FlipX = A == 1;

                        A = Math.Floor(LNDTile[Tile_Num].F / 2.0D).ToInt();
                        LNDTile[Tile_Num].F        -= (short)(A * 2);
                        map.Terrain.Tiles[X, Y].Tri = A == 1;

                        //vf, tf, ignore

                        TileUtil.OldOrientation_To_TileOrientation(Rotation, FlipX, FlipZ, ref map.Terrain.Tiles[X, Y].Texture.Orientation);
                    }
                }

                var    newUnit     = default(Unit);
                var    xyzInt      = new XYZInt(0, 0, 0);
                var    newTypeBase = default(UnitTypeBase);
                UInt32 availableID = 0;

                availableID = 1U;
                foreach (var currentObject in LNDObjects)
                {
                    if (currentObject.ID >= availableID)
                    {
                        availableID = currentObject.ID + 1U;
                    }
                }
                foreach (var currentObject in LNDObjects)
                {
                    switch (currentObject.TypeNum)
                    {
                    case 0:
                        newTypeBase = App.ObjectData.FindOrCreateUnitType(currentObject.Code, UnitType.Feature, -1);
                        break;

                    case 1:
                        newTypeBase = App.ObjectData.FindOrCreateUnitType(currentObject.Code, UnitType.PlayerStructure, -1);
                        break;

                    case 2:
                        newTypeBase = App.ObjectData.FindOrCreateUnitType(currentObject.Code, UnitType.PlayerDroid, -1);
                        break;

                    default:
                        newTypeBase = null;
                        break;
                    }
                    if (newTypeBase != null)
                    {
                        newUnit          = new Unit();
                        newUnit.TypeBase = newTypeBase;
                        if (currentObject.PlayerNum < 0 | currentObject.PlayerNum >= Constants.PlayerCountMax)
                        {
                            newUnit.UnitGroup = map.ScavengerUnitGroup;
                        }
                        else
                        {
                            newUnit.UnitGroup = map.UnitGroups[currentObject.PlayerNum];
                        }
                        xyzInt.X         = currentObject.Pos.X.ToInt();
                        xyzInt.Y         = currentObject.Pos.Y.ToInt();
                        xyzInt.Z         = currentObject.Pos.Z.ToInt();
                        newUnit.Pos      = mapPos_From_LNDPos(xyzInt);
                        newUnit.Rotation = currentObject.Rotation.Y;
                        if (currentObject.ID == 0U)
                        {
                            currentObject.ID = availableID;
                            App.ZeroIDWarning(newUnit, currentObject.ID, returnResult);
                        }
                        UnitAdd.NewUnit = newUnit;
                        UnitAdd.ID      = currentObject.ID;
                        UnitAdd.Perform();
                        App.ErrorIDChange(currentObject.ID, newUnit, "Load_LND");
                        if (availableID == currentObject.ID)
                        {
                            availableID = newUnit.ID + 1U;
                        }
                    }
                }

                foreach (var tempLoopVar_Gateway in LNDGates)
                {
                    Gateway = tempLoopVar_Gateway;
                    map.GatewayCreate(Gateway.PosA, Gateway.PosB);
                }

                if (map.Tileset != null)
                {
                    for (A = 0; A <= Math.Min(LNDTileTypeCount - 1, map.Tileset.TileCount) - 1; A++)
                    {
                        map.TileTypeNum[A] = LNDTileType[A + 1]; //lnd value 0 is ignored
                    }
                }
            }
            catch (Exception ex)
            {
                returnResult.ProblemAdd(ex.Message);
                return(returnResult);
            }

            return(returnResult);
        }
Esempio n. 10
0
        public clsResult Load_LND(string Path)
        {
            clsResult ReturnResult =
                new clsResult("Loading LND from " + Convert.ToString(ControlChars.Quote) + Path + Convert.ToString(ControlChars.Quote));

            try
            {
                string strTemp = "";
                string strTemp2 = "";
                int X = 0;
                int Y = 0;
                int A = 0;
                int B = 0;
                int Tile_Num = 0;
                SimpleList<string> LineData = default(SimpleList<string>);
                int Line_Num = 0;
                sLNDTile[] LNDTile = null;
                SimpleList<clsLNDObject> LNDObjects = new SimpleList<clsLNDObject>();
                clsUnitAdd UnitAdd = new clsUnitAdd();

                UnitAdd.Map = this;

                BinaryReader Reader = default(BinaryReader);
                try
                {
                    Reader = new BinaryReader(new FileStream(Path, FileMode.Open), App.UTF8Encoding);
                }
                catch ( Exception ex )
                {
                    ReturnResult.ProblemAdd(ex.Message);
                    return ReturnResult;
                }
                LineData = IOUtil.BytesToLinesRemoveComments(Reader);
                Reader.Close();

                Array.Resize(ref LNDTile, LineData.Count);

                string strTemp3 = "";
                bool GotTiles = default(bool);
                bool GotObjects = default(bool);
                bool GotGates = default(bool);
                bool GotTileTypes = default(bool);
                byte[] LNDTileType = new byte[0];
                string[] ObjectText = new string[11];
                string[] GateText = new string[4];
                string[] TileTypeText = new string[256];
                int LNDTileTypeCount = 0;
                SimpleList<clsGateway> LNDGates = new SimpleList<clsGateway>();
                clsGateway Gateway = default(clsGateway);
                int C = 0;
                int D = 0;
                bool GotText = default(bool);
                bool FlipX = default(bool);
                bool FlipZ = default(bool);
                byte Rotation = 0;
                sXY_int NewTileSize = new sXY_int();
                double dblTemp = 0;

                Line_Num = 0;
                while ( Line_Num < LineData.Count )
                {
                    strTemp = LineData[Line_Num];

                    A = strTemp.IndexOf("TileWidth ") + 1;
                    if ( A == 0 )
                    {
                    }
                    else
                    {
                    }

                    A = strTemp.IndexOf("TileHeight ") + 1;
                    if ( A == 0 )
                    {
                    }
                    else
                    {
                    }

                    A = strTemp.IndexOf("MapWidth ") + 1;
                    if ( A == 0 )
                    {
                    }
                    else
                    {
                        IOUtil.InvariantParse(strTemp.Substring(strTemp.Length - (strTemp.Length - (A + 8)), strTemp.Length - (A + 8)), ref NewTileSize.X);
                        goto LineDone;
                    }

                    A = strTemp.IndexOf("MapHeight ") + 1;
                    if ( A == 0 )
                    {
                    }
                    else
                    {
                        IOUtil.InvariantParse(strTemp.Substring(strTemp.Length - (strTemp.Length - (A + 9)), strTemp.Length - (A + 9)), ref NewTileSize.Y);
                        goto LineDone;
                    }

                    A = strTemp.IndexOf("Textures {") + 1;
                    if ( A == 0 )
                    {
                    }
                    else
                    {
                        Line_Num++;
                        strTemp = LineData[Line_Num];

                        strTemp2 = strTemp.ToLower();
                        if ( strTemp2.IndexOf("tertilesc1") + 1 > 0 )
                        {
                            Tileset = App.Tileset_Arizona;

                            goto LineDone;
                        }
                        else if ( strTemp2.IndexOf("tertilesc2") + 1 > 0 )
                        {
                            Tileset = App.Tileset_Urban;

                            goto LineDone;
                        }
                        else if ( strTemp2.IndexOf("tertilesc3") + 1 > 0 )
                        {
                            Tileset = App.Tileset_Rockies;

                            goto LineDone;
                        }

                        goto LineDone;
                    }

                    A = strTemp.IndexOf("Tiles {") + 1;
                    if ( A == 0 || GotTiles )
                    {
                    }
                    else
                    {
                        Line_Num++;
                        while ( Line_Num < LineData.Count )
                        {
                            strTemp = LineData[Line_Num];

                            A = strTemp.IndexOf("}") + 1;
                            if ( A == 0 )
                            {
                                A = strTemp.IndexOf("TID ") + 1;
                                if ( A == 0 )
                                {
                                    ReturnResult.ProblemAdd("Tile ID missing");
                                    return ReturnResult;
                                }
                                else
                                {
                                    strTemp2 = strTemp.Substring(strTemp.Length - (strTemp.Length - A - 3), strTemp.Length - A - 3);
                                    A = strTemp2.IndexOf(" ") + 1;
                                    if ( A > 0 )
                                    {
                                        strTemp2 = strTemp2.Substring(0, A - 1);
                                    }
                                    Int16 temp_Result = LNDTile[Tile_Num].TID;
                                    IOUtil.InvariantParse(strTemp2, ref temp_Result);
                                }

                                A = strTemp.IndexOf("VF ") + 1;
                                if ( A == 0 )
                                {
                                    ReturnResult.ProblemAdd("Tile VF missing");
                                    return ReturnResult;
                                }
                                else
                                {
                                    strTemp2 = strTemp.Substring(strTemp.Length - (strTemp.Length - A - 2), strTemp.Length - A - 2);
                                    A = strTemp2.IndexOf(" ") + 1;
                                    if ( A > 0 )
                                    {
                                        strTemp2 = strTemp2.Substring(0, A - 1);
                                    }
                                    Int16 temp_Result2 = LNDTile[Tile_Num].VF;
                                    IOUtil.InvariantParse(strTemp2, ref temp_Result2);
                                }

                                A = strTemp.IndexOf("TF ") + 1;
                                if ( A == 0 )
                                {
                                    ReturnResult.ProblemAdd("Tile TF missing");
                                    return ReturnResult;
                                }
                                else
                                {
                                    strTemp2 = strTemp.Substring(strTemp.Length - (strTemp.Length - A - 2), strTemp.Length - A - 2);
                                    A = strTemp2.IndexOf(" ") + 1;
                                    if ( A > 0 )
                                    {
                                        strTemp2 = strTemp2.Substring(0, A - 1);
                                    }
                                    Int16 temp_Result3 = LNDTile[Tile_Num].TF;
                                    IOUtil.InvariantParse(strTemp2, ref temp_Result3);
                                }

                                A = strTemp.IndexOf(" F ") + 1;
                                if ( A == 0 )
                                {
                                    ReturnResult.ProblemAdd("Tile flip missing");
                                    return ReturnResult;
                                }
                                else
                                {
                                    strTemp2 = Strings.Right(strTemp, strTemp.Length - A - 2);
                                    A = strTemp2.IndexOf(" ") + 1;
                                    if ( A > 0 )
                                    {
                                        strTemp2 = strTemp2.Substring(0, A - 1);
                                    }
                                    short temp_Result4 = LNDTile[Tile_Num].F;
                                    IOUtil.InvariantParse(strTemp2, ref temp_Result4);
                                }

                                A = strTemp.IndexOf(" VH ") + 1;
                                if ( A == 0 )
                                {
                                    ReturnResult.ProblemAdd("Tile height is missing");
                                    return ReturnResult;
                                }
                                else
                                {
                                    strTemp3 = strTemp.Substring(strTemp.Length - (strTemp.Length - A - 3), strTemp.Length - A - 3);
                                    for ( A = 0; A <= 2; A++ )
                                    {
                                        B = strTemp3.IndexOf(" ") + 1;
                                        if ( B == 0 )
                                        {
                                            ReturnResult.ProblemAdd("A tile height value is missing");
                                            return ReturnResult;
                                        }
                                        strTemp2 = strTemp3.Substring(0, B - 1);
                                        strTemp3 = strTemp3.Substring(strTemp3.Length - (strTemp3.Length - B), strTemp3.Length - B);

                                        if ( A == 0 )
                                        {
                                            short temp_Result5 = LNDTile[Tile_Num].Vertex0Height;
                                            IOUtil.InvariantParse(strTemp2, ref temp_Result5);
                                        }
                                        else if ( A == 1 )
                                        {
                                            short temp_Result6 = LNDTile[Tile_Num].Vertex1Height;
                                            IOUtil.InvariantParse(strTemp2, ref temp_Result6);
                                        }
                                        else if ( A == 2 )
                                        {
                                            Int16 temp_Result7 = LNDTile[Tile_Num].Vertex2Height;
                                            IOUtil.InvariantParse(strTemp2, ref temp_Result7);
                                        }
                                    }
                                    short temp_Result8 = LNDTile[Tile_Num].Vertex3Height;
                                    IOUtil.InvariantParse(strTemp3, ref temp_Result8);
                                }

                                Tile_Num++;
                            }
                            else
                            {
                                GotTiles = true;
                                goto LineDone;
                            }

                            Line_Num++;
                        }

                        GotTiles = true;
                        goto LineDone;
                    }

                    A = strTemp.IndexOf("Objects {") + 1;
                    if ( A == 0 || GotObjects )
                    {
                    }
                    else
                    {
                        Line_Num++;
                        while ( Line_Num < LineData.Count )
                        {
                            strTemp = LineData[Line_Num];

                            A = strTemp.IndexOf("}") + 1;
                            if ( A == 0 )
                            {
                                C = 0;
                                ObjectText[0] = "";
                                GotText = false;
                                for ( B = 0; B <= strTemp.Length - 1; B++ )
                                {
                                    if ( strTemp[B] != ' ' && strTemp[B] != '\t' )
                                    {
                                        GotText = true;
                                        ObjectText[C] += strTemp[B].ToString();
                                    }
                                    else
                                    {
                                        if ( GotText )
                                        {
                                            C++;
                                            if ( C == 11 )
                                            {
                                                ReturnResult.ProblemAdd("Too many fields for an object, or a space at the end.");
                                                return ReturnResult;
                                            }
                                            ObjectText[C] = "";
                                            GotText = false;
                                        }
                                    }
                                }

                                clsLNDObject NewObject = new clsLNDObject();
                                IOUtil.InvariantParse(ObjectText[0], NewObject.ID);
                                IOUtil.InvariantParse(ObjectText[1], ref NewObject.TypeNum);
                                NewObject.Code = ObjectText[2].Substring(1, ObjectText[2].Length - 2); //remove quotes
                                IOUtil.InvariantParse(ObjectText[3], ref NewObject.PlayerNum);
                                NewObject.Name = ObjectText[4].Substring(1, ObjectText[4].Length - 2); //remove quotes
                                IOUtil.InvariantParse(ObjectText[5], ref NewObject.Pos.X);
                                IOUtil.InvariantParse(ObjectText[6], ref NewObject.Pos.Y);
                                IOUtil.InvariantParse(ObjectText[7], ref NewObject.Pos.Z);
                                if ( IOUtil.InvariantParse(ObjectText[8], ref dblTemp) )
                                {
                                    NewObject.Rotation.X = (int)(MathUtil.Clamp_dbl(dblTemp, 0.0D, 359.0D));
                                }
                                if ( IOUtil.InvariantParse(ObjectText[9], ref dblTemp) )
                                {
                                    NewObject.Rotation.Y = (int)(MathUtil.Clamp_dbl(dblTemp, 0.0D, 359.0D));
                                }
                                if ( IOUtil.InvariantParse(ObjectText[10], ref dblTemp) )
                                {
                                    NewObject.Rotation.Z = (int)(MathUtil.Clamp_dbl(dblTemp, 0.0D, 359.0D));
                                }
                                LNDObjects.Add(NewObject);
                            }
                            else
                            {
                                GotObjects = true;
                                goto LineDone;
                            }

                            Line_Num++;
                        }

                        GotObjects = true;
                        goto LineDone;
                    }

                    A = strTemp.IndexOf("Gates {") + 1;
                    if ( A == 0 || GotGates )
                    {
                    }
                    else
                    {
                        Line_Num++;
                        while ( Line_Num < LineData.Count )
                        {
                            strTemp = LineData[Line_Num];

                            A = strTemp.IndexOf("}") + 1;
                            if ( A == 0 )
                            {
                                C = 0;
                                GateText[0] = "";
                                GotText = false;
                                for ( B = 0; B <= strTemp.Length - 1; B++ )
                                {
                                    if ( strTemp[B] != ' ' && strTemp[B] != '\t' )
                                    {
                                        GotText = true;
                                        GateText[C] += strTemp[B].ToString();
                                    }
                                    else
                                    {
                                        if ( GotText )
                                        {
                                            C++;
                                            if ( C == 4 )
                                            {
                                                ReturnResult.ProblemAdd("Too many fields for a gateway, or a space at the end.");
                                                return ReturnResult;
                                            }
                                            GateText[C] = "";
                                            GotText = false;
                                        }
                                    }
                                }

                                Gateway = new clsGateway();
                                IOUtil.InvariantParse(GateText[0], ref Gateway.PosA.X);
                                Gateway.PosA.X = Math.Max(Gateway.PosA.X, 0);
                                IOUtil.InvariantParse(GateText[1], ref Gateway.PosA.Y);
                                Gateway.PosA.Y = Math.Max(Gateway.PosA.Y, 0);
                                IOUtil.InvariantParse(GateText[2], ref Gateway.PosB.X);
                                Gateway.PosB.X = Math.Max(Gateway.PosB.X, 0);
                                IOUtil.InvariantParse(GateText[3], ref Gateway.PosB.Y);
                                Gateway.PosB.Y = Math.Max(Gateway.PosB.Y, 0);
                                LNDGates.Add(Gateway);
                            }
                            else
                            {
                                GotGates = true;
                                goto LineDone;
                            }

                            Line_Num++;
                        }

                        GotGates = true;
                        goto LineDone;
                    }

                    A = strTemp.IndexOf("Tiles {") + 1;
                    if ( A == 0 || GotTileTypes || !GotTiles )
                    {
                    }
                    else
                    {
                        Line_Num++;
                        while ( Line_Num < LineData.Count )
                        {
                            strTemp = LineData[Line_Num];

                            A = strTemp.IndexOf("}") + 1;
                            if ( A == 0 )
                            {
                                C = 0;
                                TileTypeText[0] = "";
                                GotText = false;
                                for ( B = 0; B <= strTemp.Length - 1; B++ )
                                {
                                    if ( strTemp[B] != ' ' && strTemp[B] != '\t' )
                                    {
                                        GotText = true;
                                        TileTypeText[C] += strTemp[B].ToString();
                                    }
                                    else
                                    {
                                        if ( GotText )
                                        {
                                            C++;
                                            if ( C == 256 )
                                            {
                                                ReturnResult.ProblemAdd("Too many fields for tile types.");
                                                return ReturnResult;
                                            }
                                            TileTypeText[C] = "";
                                            GotText = false;
                                        }
                                    }
                                }

                                if ( TileTypeText[C] == "" || TileTypeText[C] == " " )
                                {
                                    C--;
                                }

                                for ( D = 0; D <= C; D++ )
                                {
                                    Array.Resize(ref LNDTileType, LNDTileTypeCount + 1);
                                    LNDTileType[LNDTileTypeCount] = Math.Min(byte.Parse(TileTypeText[D]), (byte)11);
                                    LNDTileTypeCount++;
                                }
                            }
                            else
                            {
                                GotTileTypes = true;
                                goto LineDone;
                            }

                            Line_Num++;
                        }

                        GotTileTypes = true;
                        goto LineDone;
                    }

                    LineDone:
                    Line_Num++;
                }

                Array.Resize(ref LNDTile, Tile_Num);

                SetPainterToDefaults();

                if ( NewTileSize.X < 1 | NewTileSize.Y < 1 )
                {
                    ReturnResult.ProblemAdd("The LND\'s terrain dimensions are missing or invalid.");
                    return ReturnResult;
                }

                TerrainBlank(NewTileSize);
                TileType_Reset();

                for ( Y = 0; Y <= Terrain.TileSize.Y - 1; Y++ )
                {
                    for ( X = 0; X <= Terrain.TileSize.X - 1; X++ )
                    {
                        Tile_Num = Y * Terrain.TileSize.X + X;
                        //lnd uses different order! (3 = 2, 2 = 3), this program goes left to right, lnd goes clockwise around each tile
                        Terrain.Vertices[X, Y].Height = (byte)(LNDTile[Tile_Num].Vertex0Height);
                    }
                }

                for ( Y = 0; Y <= Terrain.TileSize.Y - 1; Y++ )
                {
                    for ( X = 0; X <= Terrain.TileSize.X - 1; X++ )
                    {
                        Tile_Num = Y * Terrain.TileSize.X + X;

                        Terrain.Tiles[X, Y].Texture.TextureNum = LNDTile[Tile_Num].TID - 1;

                        //ignore higher values
                        A = Convert.ToInt32(Conversion.Int(LNDTile[Tile_Num].F / 64.0D));
                        LNDTile[Tile_Num].F = (short)(LNDTile[Tile_Num].F - A * 64);

                        A = (int)(Conversion.Int(LNDTile[Tile_Num].F / 16.0D));
                        LNDTile[Tile_Num].F = (short)(LNDTile[Tile_Num].F - A * 16);
                        if ( A < 0 | A > 3 )
                        {
                            ReturnResult.ProblemAdd("Invalid flip value.");
                            return ReturnResult;
                        }
                        Rotation = (byte)A;

                        A = (int)(Conversion.Int(LNDTile[Tile_Num].F / 8.0D));
                        LNDTile[Tile_Num].F -= (short)(A * 8);
                        FlipZ = A == 1;

                        A = (int)(Conversion.Int(LNDTile[Tile_Num].F / 4.0D));
                        LNDTile[Tile_Num].F -= (short)(A * 4);
                        FlipX = A == 1;

                        A = Convert.ToInt32(Conversion.Int(LNDTile[Tile_Num].F / 2.0D));
                        LNDTile[Tile_Num].F -= (short)(A * 2);
                        Terrain.Tiles[X, Y].Tri = A == 1;

                        //vf, tf, ignore

                        TileUtil.OldOrientation_To_TileOrientation(Rotation, FlipX, FlipZ, Terrain.Tiles[X, Y].Texture.Orientation);
                    }
                }

                clsUnit NewUnit = default(clsUnit);
                sXYZ_int XYZ_int = new sXYZ_int();
                clsUnitType NewType = default(clsUnitType);
                UInt32 AvailableID = 0;
                clsLNDObject CurrentObject = default(clsLNDObject);

                AvailableID = 1U;
                foreach ( clsLNDObject tempLoopVar_CurrentObject in LNDObjects )
                {
                    CurrentObject = tempLoopVar_CurrentObject;
                    if ( CurrentObject.ID >= AvailableID )
                    {
                        AvailableID = CurrentObject.ID + 1U;
                    }
                }
                foreach ( clsLNDObject tempLoopVar_CurrentObject in LNDObjects )
                {
                    CurrentObject = tempLoopVar_CurrentObject;
                    switch ( CurrentObject.TypeNum )
                    {
                        case 0:
                            NewType = App.ObjectData.FindOrCreateUnitType(CurrentObject.Code, clsUnitType.enumType.Feature, -1);
                            break;
                        case 1:
                            NewType = App.ObjectData.FindOrCreateUnitType(CurrentObject.Code, clsUnitType.enumType.PlayerStructure, -1);
                            break;
                        case 2:
                            NewType = App.ObjectData.FindOrCreateUnitType(CurrentObject.Code, clsUnitType.enumType.PlayerDroid, -1);
                            break;
                        default:
                            NewType = null;
                            break;
                    }
                    if ( NewType != null )
                    {
                        NewUnit = new clsUnit();
                        NewUnit.Type = NewType;
                        if ( CurrentObject.PlayerNum < 0 | CurrentObject.PlayerNum >= Constants.PlayerCountMax )
                        {
                            NewUnit.UnitGroup = ScavengerUnitGroup;
                        }
                        else
                        {
                            NewUnit.UnitGroup = UnitGroups[CurrentObject.PlayerNum];
                        }
                        XYZ_int.X = (int)CurrentObject.Pos.X;
                        XYZ_int.Y = (int)CurrentObject.Pos.Y;
                        XYZ_int.Z = (int)CurrentObject.Pos.Z;
                        NewUnit.Pos = MapPos_From_LNDPos(XYZ_int);
                        NewUnit.Rotation = CurrentObject.Rotation.Y;
                        if ( CurrentObject.ID == 0U )
                        {
                            CurrentObject.ID = AvailableID;
                            App.ZeroIDWarning(NewUnit, CurrentObject.ID, ReturnResult);
                        }
                        UnitAdd.NewUnit = NewUnit;
                        UnitAdd.ID = CurrentObject.ID;
                        UnitAdd.Perform();
                        App.ErrorIDChange(CurrentObject.ID, NewUnit, "Load_LND");
                        if ( AvailableID == CurrentObject.ID )
                        {
                            AvailableID = NewUnit.ID + 1U;
                        }
                    }
                }

                foreach ( clsGateway tempLoopVar_Gateway in LNDGates )
                {
                    Gateway = tempLoopVar_Gateway;
                    GatewayCreate(Gateway.PosA, Gateway.PosB);
                }

                if ( Tileset != null )
                {
                    for ( A = 0; A <= Math.Min(LNDTileTypeCount - 1, Tileset.TileCount) - 1; A++ )
                    {
                        Tile_TypeNum[A] = LNDTileType[A + 1]; //lnd value 0 is ignored
                    }
                }
            }
            catch ( Exception ex )
            {
                ReturnResult.ProblemAdd(ex.Message);
                return ReturnResult;
            }

            return ReturnResult;
        }
Esempio n. 11
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;
        }
Esempio n. 12
0
        private clsResult Read_FMap_Objects(StreamReader File)
        {
            clsResult ReturnResult = new clsResult("Reading objects");

            int A = 0;

            IniReader ObjectsINI = new IniReader();
            ReturnResult.Take(ObjectsINI.ReadFile(File));

            FMapIniObjects INIObjects = new FMapIniObjects(ObjectsINI.Sections.Count);
            ReturnResult.Take(ObjectsINI.Translate(INIObjects));

            int DroidComponentUnknownCount = 0;
            int ObjectTypeMissingCount = 0;
            int ObjectPlayerNumInvalidCount = 0;
            int ObjectPosInvalidCount = 0;
            int DesignTypeUnspecifiedCount = 0;
            int UnknownUnitTypeCount = 0;
            int MaxUnknownUnitTypeWarningCount = 16;

            clsDroidDesign DroidDesign = default(clsDroidDesign);
            clsUnit NewObject = default(clsUnit);
            clsUnitAdd UnitAdd = new clsUnitAdd();
            clsUnitType UnitType = default(clsUnitType);
            bool IsDesign = default(bool);
            clsUnitGroup UnitGroup = default(clsUnitGroup);
            sXY_int ZeroPos = new sXY_int(0, 0);
            UInt32 AvailableID = 0;

            UnitAdd.Map = this;

            AvailableID = 1U;
            for ( A = 0; A <= INIObjects.ObjectCount - 1; A++ )
            {
                if ( INIObjects.Objects[A].ID >= AvailableID )
                {
                    AvailableID = INIObjects.Objects[A].ID + 1U;
                }
            }
            for ( A = 0; A <= INIObjects.ObjectCount - 1; A++ )
            {
                if ( INIObjects.Objects[A].Pos == null )
                {
                    ObjectPosInvalidCount++;
                }
                else if ( !App.PosIsWithinTileArea(INIObjects.Objects[A].Pos.XY, ZeroPos, Terrain.TileSize) )
                {
                    ObjectPosInvalidCount++;
                }
                else
                {
                    UnitType = null;
                    if ( INIObjects.Objects[A].Type != clsUnitType.enumType.Unspecified )
                    {
                        IsDesign = false;
                        if ( INIObjects.Objects[A].Type == clsUnitType.enumType.PlayerDroid )
                        {
                            if ( !INIObjects.Objects[A].IsTemplate )
                            {
                                IsDesign = true;
                            }
                        }
                        if ( IsDesign )
                        {
                            DroidDesign = new clsDroidDesign();
                            DroidDesign.TemplateDroidType = INIObjects.Objects[A].TemplateDroidType;
                            if ( DroidDesign.TemplateDroidType == null )
                            {
                                DroidDesign.TemplateDroidType = App.TemplateDroidType_Droid;
                                DesignTypeUnspecifiedCount++;
                            }
                            if ( INIObjects.Objects[A].BodyCode != "" )
                            {
                                DroidDesign.Body = App.ObjectData.FindOrCreateBody(Convert.ToString(INIObjects.Objects[A].BodyCode));
                                if ( DroidDesign.Body.IsUnknown )
                                {
                                    DroidComponentUnknownCount++;
                                }
                            }
                            if ( INIObjects.Objects[A].PropulsionCode != "" )
                            {
                                DroidDesign.Propulsion = App.ObjectData.FindOrCreatePropulsion(INIObjects.Objects[A].PropulsionCode);
                                if ( DroidDesign.Propulsion.IsUnknown )
                                {
                                    DroidComponentUnknownCount++;
                                }
                            }
                            DroidDesign.TurretCount = (byte)(INIObjects.Objects[A].TurretCount);
                            if ( INIObjects.Objects[A].TurretCodes[0] != "" )
                            {
                                DroidDesign.Turret1 = App.ObjectData.FindOrCreateTurret(INIObjects.Objects[A].TurretTypes[0],
                                    Convert.ToString(INIObjects.Objects[A].TurretCodes[0]));
                                if ( DroidDesign.Turret1.IsUnknown )
                                {
                                    DroidComponentUnknownCount++;
                                }
                            }
                            if ( INIObjects.Objects[A].TurretCodes[1] != "" )
                            {
                                DroidDesign.Turret2 = App.ObjectData.FindOrCreateTurret(INIObjects.Objects[A].TurretTypes[1],
                                    Convert.ToString(INIObjects.Objects[A].TurretCodes[1]));
                                if ( DroidDesign.Turret2.IsUnknown )
                                {
                                    DroidComponentUnknownCount++;
                                }
                            }
                            if ( INIObjects.Objects[A].TurretCodes[2] != "" )
                            {
                                DroidDesign.Turret3 = App.ObjectData.FindOrCreateTurret(INIObjects.Objects[A].TurretTypes[2],
                                    Convert.ToString(INIObjects.Objects[A].TurretCodes[2]));
                                if ( DroidDesign.Turret3.IsUnknown )
                                {
                                    DroidComponentUnknownCount++;
                                }
                            }
                            DroidDesign.UpdateAttachments();
                            UnitType = DroidDesign;
                        }
                        else
                        {
                            UnitType = App.ObjectData.FindOrCreateUnitType(INIObjects.Objects[A].Code, INIObjects.Objects[A].Type, INIObjects.Objects[A].WallType);
                            if ( UnitType.IsUnknown )
                            {
                                if ( UnknownUnitTypeCount < MaxUnknownUnitTypeWarningCount )
                                {
                                    ReturnResult.WarningAdd(ControlChars.Quote + INIObjects.Objects[A].Code + Convert.ToString(ControlChars.Quote) +
                                                            " is not a loaded object.");
                                }
                                UnknownUnitTypeCount++;
                            }
                        }
                    }
                    if ( UnitType == null )
                    {
                        ObjectTypeMissingCount++;
                    }
                    else
                    {
                        NewObject = new clsUnit();
                        NewObject.Type = UnitType;
                        NewObject.Pos.Horizontal.X = INIObjects.Objects[A].Pos.X;
                        NewObject.Pos.Horizontal.Y = INIObjects.Objects[A].Pos.Y;
                        NewObject.Health = INIObjects.Objects[A].Health;
                        NewObject.SavePriority = INIObjects.Objects[A].Priority;
                        NewObject.Rotation = (int)(INIObjects.Objects[A].Heading);
                        if ( NewObject.Rotation >= 360 )
                        {
                            NewObject.Rotation -= 360;
                        }
                        if ( INIObjects.Objects[A].UnitGroup == null || INIObjects.Objects[A].UnitGroup == "" )
                        {
                            if ( INIObjects.Objects[A].Type != clsUnitType.enumType.Feature )
                            {
                                ObjectPlayerNumInvalidCount++;
                            }
                            NewObject.UnitGroup = ScavengerUnitGroup;
                        }
                        else
                        {
                            if ( INIObjects.Objects[A].UnitGroup.ToLower() == "scavenger" )
                            {
                                NewObject.UnitGroup = ScavengerUnitGroup;
                            }
                            else
                            {
                                UInt32 PlayerNum = 0;
                                try
                                {
                                    if ( !IOUtil.InvariantParse(INIObjects.Objects[A].UnitGroup, PlayerNum) )
                                    {
                                        throw (new Exception());
                                    }
                                    if ( PlayerNum < Constants.PlayerCountMax )
                                    {
                                        UnitGroup = UnitGroups[Convert.ToInt32(PlayerNum)];
                                    }
                                    else
                                    {
                                        UnitGroup = ScavengerUnitGroup;
                                        ObjectPlayerNumInvalidCount++;
                                    }
                                }
                                catch ( Exception )
                                {
                                    ObjectPlayerNumInvalidCount++;
                                    UnitGroup = ScavengerUnitGroup;
                                }
                                NewObject.UnitGroup = UnitGroup;
                            }
                        }
                        if ( INIObjects.Objects[A].ID == 0U )
                        {
                            INIObjects.Objects[A].ID = AvailableID;
                            App.ZeroIDWarning(NewObject, INIObjects.Objects[A].ID, ReturnResult);
                        }
                        UnitAdd.NewUnit = NewObject;
                        UnitAdd.ID = INIObjects.Objects[A].ID;
                        UnitAdd.Label = INIObjects.Objects[A].Label;
                        UnitAdd.Perform();
                        App.ErrorIDChange(INIObjects.Objects[A].ID, NewObject, "Read_FMap_Objects");
                        if ( AvailableID == INIObjects.Objects[A].ID )
                        {
                            AvailableID = NewObject.ID + 1U;
                        }
                    }
                }
            }

            if ( UnknownUnitTypeCount > MaxUnknownUnitTypeWarningCount )
            {
                ReturnResult.WarningAdd(UnknownUnitTypeCount + " objects were not in the loaded object data.");
            }
            if ( ObjectTypeMissingCount > 0 )
            {
                ReturnResult.WarningAdd(ObjectTypeMissingCount + " objects did not specify a type and were ignored.");
            }
            if ( DroidComponentUnknownCount > 0 )
            {
                ReturnResult.WarningAdd(DroidComponentUnknownCount + " components used by droids were loaded as unknowns.");
            }
            if ( ObjectPlayerNumInvalidCount > 0 )
            {
                ReturnResult.WarningAdd(ObjectPlayerNumInvalidCount + " objects had an invalid player number and were set to player 0.");
            }
            if ( ObjectPosInvalidCount > 0 )
            {
                ReturnResult.WarningAdd(ObjectPosInvalidCount + " objects had a position that was off-map and were ignored.");
            }
            if ( DesignTypeUnspecifiedCount > 0 )
            {
                ReturnResult.WarningAdd(DesignTypeUnspecifiedCount + " designed droids did not specify a template droid type and were set to droid.");
            }

            return ReturnResult;
        }
Esempio n. 13
0
        public clsResult CreateWZObjects(sCreateWZObjectsArgs Args)
        {
            clsResult ReturnResult = new clsResult("Creating objects");
            clsUnit NewUnit = default(clsUnit);
            UInt32 AvailableID = 0;
            SimpleClassList<clsWZBJOUnit> BJOUnits = Args.BJOUnits;
            IniStructures INIStructures = Args.INIStructures;
            IniDroids INIDroids = Args.INIDroids;
            IniFeatures INIFeatures = Args.INIFeatures;
            clsUnitAdd UnitAdd = new clsUnitAdd();
            int A = 0;
            int B = 0;
            clsWZBJOUnit BJOUnit = default(clsWZBJOUnit);

            UnitAdd.Map = this;

            AvailableID = 1U;
            foreach ( clsWZBJOUnit tempLoopVar_BJOUnit in BJOUnits )
            {
                BJOUnit = tempLoopVar_BJOUnit;
                if ( BJOUnit.ID >= AvailableID )
                {
                    AvailableID = BJOUnit.ID + 1U;
                }
            }
            if ( INIStructures != null )
            {
                for ( A = 0; A <= INIStructures.StructureCount - 1; A++ )
                {
                    if ( INIStructures.Structures[A].ID >= AvailableID )
                    {
                        AvailableID = INIStructures.Structures[A].ID + 1U;
                    }
                }
            }
            if ( INIFeatures != null )
            {
                for ( A = 0; A <= INIFeatures.FeatureCount - 1; A++ )
                {
                    if ( INIFeatures.Features[A].ID >= AvailableID )
                    {
                        AvailableID = INIFeatures.Features[A].ID + 1U;
                    }
                }
            }
            if ( INIDroids != null )
            {
                for ( A = 0; A <= INIDroids.DroidCount - 1; A++ )
                {
                    if ( INIDroids.Droids[A].ID >= AvailableID )
                    {
                        AvailableID = INIDroids.Droids[A].ID + 1U;
                    }
                }
            }

            foreach ( clsWZBJOUnit tempLoopVar_BJOUnit in BJOUnits )
            {
                BJOUnit = tempLoopVar_BJOUnit;
                NewUnit = new clsUnit();
                NewUnit.ID = BJOUnit.ID;
                NewUnit.Type = App.ObjectData.FindOrCreateUnitType(BJOUnit.Code, BJOUnit.ObjectType, -1);
                if ( NewUnit.Type == null )
                {
                    ReturnResult.ProblemAdd("Unable to create object type.");
                    return ReturnResult;
                }
                if ( BJOUnit.Player >= Constants.PlayerCountMax )
                {
                    NewUnit.UnitGroup = ScavengerUnitGroup;
                }
                else
                {
                    NewUnit.UnitGroup = UnitGroups[Convert.ToInt32(BJOUnit.Player)];
                }
                NewUnit.Pos = BJOUnit.Pos;
                NewUnit.Rotation = (int)(Math.Min(BJOUnit.Rotation, 359U));
                if ( BJOUnit.ID == 0U )
                {
                    BJOUnit.ID = AvailableID;
                    App.ZeroIDWarning(NewUnit, BJOUnit.ID, ReturnResult);
                }
                UnitAdd.NewUnit = NewUnit;
                UnitAdd.ID = BJOUnit.ID;
                UnitAdd.Perform();
                App.ErrorIDChange(BJOUnit.ID, NewUnit, "CreateWZObjects");
                if ( AvailableID == BJOUnit.ID )
                {
                    AvailableID = NewUnit.ID + 1U;
                }
            }

            clsStructureType StructureType = default(clsStructureType);
            clsDroidDesign DroidType = default(clsDroidDesign);
            clsFeatureType FeatureType = default(clsFeatureType);
            clsDroidDesign.sLoadPartsArgs LoadPartsArgs = new clsDroidDesign.sLoadPartsArgs();
            clsUnitType UnitType = null;
            int ErrorCount = 0;
            int UnknownDroidComponentCount = 0;
            int UnknownDroidTypeCount = 0;
            int DroidBadPositionCount = 0;
            int StructureBadPositionCount = 0;
            int StructureBadModulesCount = 0;
            int FeatureBadPositionCount = 0;
            int ModuleLimit = 0;
            sXY_int ZeroPos = new sXY_int(0, 0);
            clsStructureType ModuleType = default(clsStructureType);
            clsUnit NewModule = default(clsUnit);

            clsStructureType FactoryModule = App.ObjectData.FindFirstStructureType(clsStructureType.enumStructureType.FactoryModule);
            clsStructureType ResearchModule = App.ObjectData.FindFirstStructureType(clsStructureType.enumStructureType.ResearchModule);
            clsStructureType PowerModule = App.ObjectData.FindFirstStructureType(clsStructureType.enumStructureType.PowerModule);

            if ( FactoryModule == null )
            {
                ReturnResult.WarningAdd("No factory module loaded.");
            }
            if ( ResearchModule == null )
            {
                ReturnResult.WarningAdd("No research module loaded.");
            }
            if ( PowerModule == null )
            {
                ReturnResult.WarningAdd("No power module loaded.");
            }

            if ( INIStructures != null )
            {
                for ( A = 0; A <= INIStructures.StructureCount - 1; A++ )
                {
                    if ( INIStructures.Structures[A].Pos == null )
                    {
                        StructureBadPositionCount++;
                    }
                    else if ( !App.PosIsWithinTileArea(INIStructures.Structures[A].Pos.WorldPos.Horizontal, ZeroPos, Terrain.TileSize) )
                    {
                        StructureBadPositionCount++;
                    }
                    else
                    {
                        UnitType = App.ObjectData.FindOrCreateUnitType(Convert.ToString(INIStructures.Structures[A].Code),
                            clsUnitType.enumType.PlayerStructure, INIStructures.Structures[A].WallType);
                        if ( UnitType.Type == clsUnitType.enumType.PlayerStructure )
                        {
                            StructureType = (clsStructureType)UnitType;
                        }
                        else
                        {
                            StructureType = null;
                        }
                        if ( StructureType == null )
                        {
                            ErrorCount++;
                        }
                        else
                        {
                            NewUnit = new clsUnit();
                            NewUnit.Type = StructureType;
                            if ( INIStructures.Structures[A].UnitGroup == null )
                            {
                                NewUnit.UnitGroup = ScavengerUnitGroup;
                            }
                            else
                            {
                                NewUnit.UnitGroup = INIStructures.Structures[A].UnitGroup;
                            }
                            NewUnit.Pos = INIStructures.Structures[A].Pos.WorldPos;
                            NewUnit.Rotation = Convert.ToInt32(INIStructures.Structures[A].Rotation.Direction * 360.0D / App.INIRotationMax);
                            if ( NewUnit.Rotation == 360 )
                            {
                                NewUnit.Rotation = 0;
                            }
                            if ( INIStructures.Structures[A].HealthPercent >= 0 )
                            {
                                NewUnit.Health = MathUtil.Clamp_dbl(INIStructures.Structures[A].HealthPercent / 100.0D, 0.01D, 1.0D);
                            }
                            if ( INIStructures.Structures[A].ID == 0U )
                            {
                                INIStructures.Structures[A].ID = AvailableID;
                                App.ZeroIDWarning(NewUnit, INIStructures.Structures[A].ID, ReturnResult);
                            }
                            UnitAdd.NewUnit = NewUnit;
                            UnitAdd.ID = INIStructures.Structures[A].ID;
                            UnitAdd.Perform();
                            App.ErrorIDChange(INIStructures.Structures[A].ID, NewUnit, "Load_WZ->INIStructures");
                            if ( AvailableID == INIStructures.Structures[A].ID )
                            {
                                AvailableID = NewUnit.ID + 1U;
                            }
                            //create modules
                            switch ( StructureType.StructureType )
                            {
                                case clsStructureType.enumStructureType.Factory:
                                    ModuleLimit = 2;
                                    ModuleType = FactoryModule;
                                    break;
                                case clsStructureType.enumStructureType.VTOLFactory:
                                    ModuleLimit = 2;
                                    ModuleType = FactoryModule;
                                    break;
                                case clsStructureType.enumStructureType.PowerGenerator:
                                    ModuleLimit = 1;
                                    ModuleType = PowerModule;
                                    break;
                                case clsStructureType.enumStructureType.Research:
                                    ModuleLimit = 1;
                                    ModuleType = ResearchModule;
                                    break;
                                default:
                                    ModuleLimit = 0;
                                    ModuleType = null;
                                    break;
                            }
                            if ( INIStructures.Structures[A].ModuleCount > ModuleLimit )
                            {
                                INIStructures.Structures[A].ModuleCount = ModuleLimit;
                                StructureBadModulesCount++;
                            }
                            else if ( INIStructures.Structures[A].ModuleCount < 0 )
                            {
                                INIStructures.Structures[A].ModuleCount = 0;
                                StructureBadModulesCount++;
                            }
                            if ( ModuleType != null )
                            {
                                for ( B = 0; B <= INIStructures.Structures[A].ModuleCount - 1; B++ )
                                {
                                    NewModule = new clsUnit();
                                    NewModule.Type = ModuleType;
                                    NewModule.UnitGroup = NewUnit.UnitGroup;
                                    NewModule.Pos = NewUnit.Pos;
                                    NewModule.Rotation = NewUnit.Rotation;
                                    UnitAdd.NewUnit = NewModule;
                                    UnitAdd.ID = AvailableID;
                                    UnitAdd.Perform();
                                    AvailableID = NewModule.ID + 1U;
                                }
                            }
                        }
                    }
                }
                if ( StructureBadPositionCount > 0 )
                {
                    ReturnResult.WarningAdd(StructureBadPositionCount + " structures had an invalid position and were removed.");
                }
                if ( StructureBadModulesCount > 0 )
                {
                    ReturnResult.WarningAdd(StructureBadModulesCount + " structures had an invalid number of modules.");
                }
            }
            if ( INIFeatures != null )
            {
                for ( A = 0; A <= INIFeatures.FeatureCount - 1; A++ )
                {
                    if ( INIFeatures.Features[A].Pos == null )
                    {
                        FeatureBadPositionCount++;
                    }
                    else if ( !App.PosIsWithinTileArea(INIFeatures.Features[A].Pos.WorldPos.Horizontal, ZeroPos, Terrain.TileSize) )
                    {
                        FeatureBadPositionCount++;
                    }
                    else
                    {
                        UnitType = App.ObjectData.FindOrCreateUnitType(Convert.ToString(INIFeatures.Features[A].Code), clsUnitType.enumType.Feature, -1);
                        if ( UnitType.Type == clsUnitType.enumType.Feature )
                        {
                            FeatureType = (clsFeatureType)UnitType;
                        }
                        else
                        {
                            FeatureType = null;
                        }
                        if ( FeatureType == null )
                        {
                            ErrorCount++;
                        }
                        else
                        {
                            NewUnit = new clsUnit();
                            NewUnit.Type = FeatureType;
                            NewUnit.UnitGroup = ScavengerUnitGroup;
                            NewUnit.Pos = INIFeatures.Features[A].Pos.WorldPos;
                            NewUnit.Rotation = Convert.ToInt32(INIFeatures.Features[A].Rotation.Direction * 360.0D / App.INIRotationMax);
                            if ( NewUnit.Rotation == 360 )
                            {
                                NewUnit.Rotation = 0;
                            }
                            if ( INIFeatures.Features[A].HealthPercent >= 0 )
                            {
                                NewUnit.Health = MathUtil.Clamp_dbl(INIFeatures.Features[A].HealthPercent / 100.0D, 0.01D, 1.0D);
                            }
                            if ( INIFeatures.Features[A].ID == 0U )
                            {
                                INIFeatures.Features[A].ID = AvailableID;
                                App.ZeroIDWarning(NewUnit, INIFeatures.Features[A].ID, ReturnResult);
                            }
                            UnitAdd.NewUnit = NewUnit;
                            UnitAdd.ID = INIFeatures.Features[A].ID;
                            UnitAdd.Perform();
                            App.ErrorIDChange(INIFeatures.Features[A].ID, NewUnit, "Load_WZ->INIFeatures");
                            if ( AvailableID == INIFeatures.Features[A].ID )
                            {
                                AvailableID = NewUnit.ID + 1U;
                            }
                        }
                    }
                }
                if ( FeatureBadPositionCount > 0 )
                {
                    ReturnResult.WarningAdd(FeatureBadPositionCount + " features had an invalid position and were removed.");
                }
            }
            if ( INIDroids != null )
            {
                for ( A = 0; A <= INIDroids.DroidCount - 1; A++ )
                {
                    if ( INIDroids.Droids[A].Pos == null )
                    {
                        DroidBadPositionCount++;
                    }
                    else if ( !App.PosIsWithinTileArea(INIDroids.Droids[A].Pos.WorldPos.Horizontal, ZeroPos, Terrain.TileSize) )
                    {
                        DroidBadPositionCount++;
                    }
                    else
                    {
                        if ( INIDroids.Droids[A].Template == null || INIDroids.Droids[A].Template == "" )
                        {
                            DroidType = new clsDroidDesign();
                            if ( !DroidType.SetDroidType((App.enumDroidType)(INIDroids.Droids[A].DroidType)) )
                            {
                                UnknownDroidTypeCount++;
                            }
                            LoadPartsArgs.Body = App.ObjectData.FindOrCreateBody(INIDroids.Droids[A].Body);
                            if ( LoadPartsArgs.Body == null )
                            {
                                UnknownDroidComponentCount++;
                            }
                            else
                            {
                                if ( LoadPartsArgs.Body.IsUnknown )
                                {
                                    UnknownDroidComponentCount++;
                                }
                            }
                            LoadPartsArgs.Propulsion = App.ObjectData.FindOrCreatePropulsion(Convert.ToString(INIDroids.Droids[A].Propulsion));
                            if ( LoadPartsArgs.Propulsion == null )
                            {
                                UnknownDroidComponentCount++;
                            }
                            else
                            {
                                if ( LoadPartsArgs.Propulsion.IsUnknown )
                                {
                                    UnknownDroidComponentCount++;
                                }
                            }
                            LoadPartsArgs.Construct = App.ObjectData.FindOrCreateConstruct(Convert.ToString(INIDroids.Droids[A].Construct));
                            if ( LoadPartsArgs.Construct == null )
                            {
                                UnknownDroidComponentCount++;
                            }
                            else
                            {
                                if ( LoadPartsArgs.Construct.IsUnknown )
                                {
                                    UnknownDroidComponentCount++;
                                }
                            }
                            LoadPartsArgs.Repair = App.ObjectData.FindOrCreateRepair(INIDroids.Droids[A].Repair);
                            if ( LoadPartsArgs.Repair == null )
                            {
                                UnknownDroidComponentCount++;
                            }
                            else
                            {
                                if ( LoadPartsArgs.Repair.IsUnknown )
                                {
                                    UnknownDroidComponentCount++;
                                }
                            }
                            LoadPartsArgs.Sensor = App.ObjectData.FindOrCreateSensor(INIDroids.Droids[A].Sensor);
                            if ( LoadPartsArgs.Sensor == null )
                            {
                                UnknownDroidComponentCount++;
                            }
                            else
                            {
                                if ( LoadPartsArgs.Sensor.IsUnknown )
                                {
                                    UnknownDroidComponentCount++;
                                }
                            }
                            LoadPartsArgs.Brain = App.ObjectData.FindOrCreateBrain(INIDroids.Droids[A].Brain);
                            if ( LoadPartsArgs.Brain == null )
                            {
                                UnknownDroidComponentCount++;
                            }
                            else
                            {
                                if ( LoadPartsArgs.Brain.IsUnknown )
                                {
                                    UnknownDroidComponentCount++;
                                }
                            }
                            LoadPartsArgs.ECM = App.ObjectData.FindOrCreateECM(Convert.ToString(INIDroids.Droids[A].ECM));
                            if ( LoadPartsArgs.ECM == null )
                            {
                                UnknownDroidComponentCount++;
                            }
                            else
                            {
                                if ( LoadPartsArgs.ECM.IsUnknown )
                                {
                                    UnknownDroidComponentCount++;
                                }
                            }
                            LoadPartsArgs.Weapon1 = App.ObjectData.FindOrCreateWeapon(Convert.ToString(INIDroids.Droids[A].Weapons[0]));
                            if ( LoadPartsArgs.Weapon1 == null )
                            {
                                UnknownDroidComponentCount++;
                            }
                            else
                            {
                                if ( LoadPartsArgs.Weapon1.IsUnknown )
                                {
                                    UnknownDroidComponentCount++;
                                }
                            }
                            LoadPartsArgs.Weapon2 = App.ObjectData.FindOrCreateWeapon(Convert.ToString(INIDroids.Droids[A].Weapons[1]));
                            if ( LoadPartsArgs.Weapon2 == null )
                            {
                                UnknownDroidComponentCount++;
                            }
                            else
                            {
                                if ( LoadPartsArgs.Weapon2.IsUnknown )
                                {
                                    UnknownDroidComponentCount++;
                                }
                            }
                            LoadPartsArgs.Weapon3 = App.ObjectData.FindOrCreateWeapon(Convert.ToString(INIDroids.Droids[A].Weapons[2]));
                            if ( LoadPartsArgs.Weapon3 == null )
                            {
                                UnknownDroidComponentCount++;
                            }
                            else
                            {
                                if ( LoadPartsArgs.Weapon3.IsUnknown )
                                {
                                    UnknownDroidComponentCount++;
                                }
                            }
                            DroidType.LoadParts(LoadPartsArgs);
                        }
                        else
                        {
                            UnitType = App.ObjectData.FindOrCreateUnitType(INIDroids.Droids[A].Template, clsUnitType.enumType.PlayerDroid, -1);
                            if ( UnitType == null )
                            {
                                DroidType = null;
                            }
                            else
                            {
                                if ( UnitType.Type == clsUnitType.enumType.PlayerDroid )
                                {
                                    DroidType = (clsDroidDesign)UnitType;
                                }
                                else
                                {
                                    DroidType = null;
                                }
                            }
                        }
                        if ( DroidType == null )
                        {
                            ErrorCount++;
                        }
                        else
                        {
                            NewUnit = new clsUnit();
                            NewUnit.Type = DroidType;
                            if ( INIDroids.Droids[A].UnitGroup == null )
                            {
                                NewUnit.UnitGroup = ScavengerUnitGroup;
                            }
                            else
                            {
                                NewUnit.UnitGroup = INIDroids.Droids[A].UnitGroup;
                            }
                            NewUnit.Pos = INIDroids.Droids[A].Pos.WorldPos;
                            NewUnit.Rotation = Convert.ToInt32(INIDroids.Droids[A].Rotation.Direction * 360.0D / App.INIRotationMax);
                            if ( NewUnit.Rotation == 360 )
                            {
                                NewUnit.Rotation = 0;
                            }
                            if ( INIDroids.Droids[A].HealthPercent >= 0 )
                            {
                                NewUnit.Health = MathUtil.Clamp_dbl(INIDroids.Droids[A].HealthPercent / 100.0D, 0.01D, 1.0D);
                            }
                            if ( INIDroids.Droids[A].ID == 0U )
                            {
                                INIDroids.Droids[A].ID = AvailableID;
                                App.ZeroIDWarning(NewUnit, INIDroids.Droids[A].ID, ReturnResult);
                            }
                            UnitAdd.NewUnit = NewUnit;
                            UnitAdd.ID = INIDroids.Droids[A].ID;
                            UnitAdd.Perform();
                            App.ErrorIDChange(INIDroids.Droids[A].ID, NewUnit, "Load_WZ->INIDroids");
                            if ( AvailableID == INIDroids.Droids[A].ID )
                            {
                                AvailableID = NewUnit.ID + 1U;
                            }
                        }
                    }
                }
                if ( DroidBadPositionCount > 0 )
                {
                    ReturnResult.WarningAdd(DroidBadPositionCount + " droids had an invalid position and were removed.");
                }
                if ( UnknownDroidTypeCount > 0 )
                {
                    ReturnResult.WarningAdd(UnknownDroidTypeCount + " droid designs had an unrecognised droidType and were removed.");
                }
                if ( UnknownDroidComponentCount > 0 )
                {
                    ReturnResult.WarningAdd(UnknownDroidComponentCount + " droid designs had components that are not loaded.");
                }
            }

            if ( ErrorCount > 0 )
            {
                ReturnResult.WarningAdd("Object Create Error.");
            }

            return ReturnResult;
        }