public void Finish()
        {
            if ( !Started )
            {
                Debugger.Break();
                return;
            }

            var A = 0;
            var UnitAdd = new clsUnitAdd();
            var 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;
        }
Beispiel #2
0
 public clsUnit Perform()
 {
     if ( AutoWalls )
     {
         if ( ObjectTypeBase.Type == UnitType.PlayerStructure )
         {
             var structureTypeBase = (StructureTypeBase)ObjectTypeBase;
             if ( structureTypeBase.WallLink.IsConnected )
             {
                 clsWallType AutoWallType = null;
                 AutoWallType = structureTypeBase.WallLink.Source;
                 Map.PerformTileWall(AutoWallType, Map.GetPosTileNum(Horizontal), true);
                 return null;
             }
         }
     }
     var newUnit = new clsUnit();
     if ( RandomizeRotation )
     {
         newUnit.Rotation = (int)(App.Random.Next() * 360.0D);
     }
     else
     {
         newUnit.Rotation = Rotation;
     }
     newUnit.UnitGroup = UnitGroup;
     newUnit.Pos = Map.TileAlignedPosFromMapPos(Horizontal, ObjectTypeBase.get_GetFootprintSelected(newUnit.Rotation));
     newUnit.TypeBase = ObjectTypeBase;
     var UnitAdd = new clsUnitAdd();
     UnitAdd.Map = Map;
     UnitAdd.NewUnit = newUnit;
     UnitAdd.StoreChange = true;
     UnitAdd.Perform();
     return newUnit;
 }
Beispiel #3
0
        public clsResult Load(string path)
        {
            var returnResult =
                new clsResult("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<clsGateway>();
                var Gateway = default(clsGateway);
                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 = (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;
                    }

                    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 = Convert.ToInt32((LNDTile[Tile_Num].F / 64.0D));
                        LNDTile[Tile_Num].F = (short)(LNDTile[Tile_Num].F - A * 64);

                        A = (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)((LNDTile[Tile_Num].F / 8.0D));
                        LNDTile[Tile_Num].F -= (short)(A * 8);
                        FlipZ = A == 1;

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

                        A = Convert.ToInt32((LNDTile[Tile_Num].F / 2.0D));
                        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(clsUnit);
                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 clsUnit();
                        newUnit.TypeBase = newTypeBase;
                        if ( currentObject.PlayerNum < 0 | currentObject.PlayerNum >= Constants.PlayerCountMax )
                        {
                            newUnit.UnitGroup = map.ScavengerUnitGroup;
                        }
                        else
                        {
                            newUnit.UnitGroup = map.UnitGroups[currentObject.PlayerNum];
                        }
                        xyzInt.X = (int)currentObject.Pos.X;
                        xyzInt.Y = (int)currentObject.Pos.Y;
                        xyzInt.Z = (int)currentObject.Pos.Z;
                        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.Tile_TypeNum[A] = LNDTileType[A + 1]; //lnd value 0 is ignored
                    }
                }
            }
            catch ( Exception ex )
            {
                returnResult.ProblemAdd(ex.Message);
                return returnResult;
            }

            return returnResult;
        }
Beispiel #4
0
        protected clsResult createWZObjects(List<WZBJOUnit> bjoUnits, List<IniStructure> iniStructures, List<IniDroid> iniDroids, List<IniFeature> iniFeatures)
        {
            var ReturnResult = new clsResult("Creating objects", false);
            logger.Info("Creating objects");

            var newUnit = default(clsUnit);
            UInt32 availableID = 0;
            var unitAdd = new clsUnitAdd();
            var a = 0;
            var b = 0;

            unitAdd.Map = map;

            availableID = 1U;
            foreach ( var bjoUnit in bjoUnits )
            {
                if ( bjoUnit.ID >= availableID )
                {
                    availableID = bjoUnit.ID + 1U;
                }
            }
            if ( iniStructures.Count > 0)
            {
                var structMaxId = iniStructures.Max(w => w.ID) + 10;
                if ( structMaxId > availableID )
                {
                    availableID = structMaxId;
                }
            }
            if ( iniFeatures.Count > 0 )
            {
                var featuresMaxId = iniFeatures.Max(w => w.ID) + 10;
                if ( featuresMaxId > availableID )
                {
                    availableID = featuresMaxId;
                }
            }
            if ( iniDroids.Count > 0 )
            {
                var droidsMaxId = iniDroids.Max(w => w.ID) + 10;
                if ( droidsMaxId > availableID )
                {
                    availableID += droidsMaxId;
                }
            }

            foreach ( var bjoUnit in bjoUnits )
            {
                newUnit = new clsUnit();
                newUnit.ID = bjoUnit.ID;
                newUnit.TypeBase = App.ObjectData.FindOrCreateUnitType(bjoUnit.Code, bjoUnit.ObjectType, -1);
                if ( newUnit.TypeBase == null )
                {
                    ReturnResult.ProblemAdd("Unable to create object type.");
                    return ReturnResult;
                }
                if ( bjoUnit.Player >= Constants.PlayerCountMax )
                {
                    newUnit.UnitGroup = map.ScavengerUnitGroup;
                }
                else
                {
                    newUnit.UnitGroup = map.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;
                }
            }

            var structureTypeBase = default(StructureTypeBase);
            var droidType = default(DroidDesign);
            var featureTypeBase = default(FeatureTypeBase);
            var loadPartsArgs = new DroidDesign.sLoadPartsArgs();
            UnitTypeBase unitTypeBase = null;
            var errorCount = 0;
            var unknownDroidComponentCount = 0;
            var unknownDroidTypeCount = 0;
            var droidBadPositionCount = 0;
            var structureBadPositionCount = 0;
            var structureBadModulesCount = 0;
            var featureBadPositionCount = 0;
            var moduleLimit = 0;
            var zeroPos = new XYInt(0, 0);
            var moduleTypeBase = default(StructureTypeBase);
            var newModule = default(clsUnit);

            var factoryModule = App.ObjectData.FindFirstStructureType(StructureTypeBase.enumStructureType.FactoryModule);
            var researchModule = App.ObjectData.FindFirstStructureType(StructureTypeBase.enumStructureType.ResearchModule);
            var powerModule = App.ObjectData.FindFirstStructureType(StructureTypeBase.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.");
            }

            foreach ( var iniStructure in iniStructures )
            {
                if ( iniStructure.Pos == null )
                {
                    logger.Debug("{0} pos was null", iniStructure.Code);
                    structureBadPositionCount++;
                }
                else if ( !App.PosIsWithinTileArea(iniStructure.Pos, zeroPos, map.Terrain.TileSize) )
                {
                    logger.Debug("{0} structure pos x{1} y{2}, is wrong.", iniStructure.Code, iniStructure.Pos.X,
                        iniStructure.Pos.Y);
                    structureBadPositionCount++;
                }
                else
                {
                    unitTypeBase = App.ObjectData.FindOrCreateUnitType(Convert.ToString(iniStructure.Code),
                        UnitType.PlayerStructure, iniStructure.WallType);
                    if ( unitTypeBase.Type == UnitType.PlayerStructure )
                    {
                        structureTypeBase = (StructureTypeBase)unitTypeBase;
                    }
                    else
                    {
                        structureTypeBase = null;
                    }
                    if ( structureTypeBase == null )
                    {
                        errorCount++;
                    }
                    else
                    {
                        newUnit = new clsUnit();
                        newUnit.TypeBase = structureTypeBase;
                        if ( iniStructure.UnitGroup == null )
                        {
                            newUnit.UnitGroup = map.ScavengerUnitGroup;
                        }
                        else
                        {
                            newUnit.UnitGroup = iniStructure.UnitGroup;
                        }
                        newUnit.Pos = new WorldPos(iniStructure.Pos, iniStructure.Pos.Z);
                        newUnit.Rotation = Convert.ToInt32(iniStructure.Rotation.Direction * 360.0D / Constants.INIRotationMax);
                        if ( newUnit.Rotation == 360 )
                        {
                            newUnit.Rotation = 0;
                        }
                        if ( iniStructure.HealthPercent >= 0 )
                        {
                            newUnit.Health = MathUtil.Clamp_dbl(iniStructure.HealthPercent / 100.0D, 0.01D, 1.0D);
                        }
                        if ( iniStructure.ID == 0U )
                        {
                            iniStructure.ID = availableID;
                            App.ZeroIDWarning(newUnit, iniStructure.ID, ReturnResult);
                        }
                        unitAdd.NewUnit = newUnit;
                        unitAdd.ID = iniStructure.ID;
                        unitAdd.Perform();
                        App.ErrorIDChange(iniStructure.ID, newUnit, "Load_WZ->INIStructures");
                        if ( availableID == iniStructure.ID )
                        {
                            availableID = newUnit.ID + 1U;
                        }
                        //create modules
                        switch ( structureTypeBase.StructureType )
                        {
                            case StructureTypeBase.enumStructureType.Factory:
                                moduleLimit = 2;
                                moduleTypeBase = factoryModule;
                                break;
                            case StructureTypeBase.enumStructureType.VTOLFactory:
                                moduleLimit = 2;
                                moduleTypeBase = factoryModule;
                                break;
                            case StructureTypeBase.enumStructureType.PowerGenerator:
                                moduleLimit = 1;
                                moduleTypeBase = powerModule;
                                break;
                            case StructureTypeBase.enumStructureType.Research:
                                moduleLimit = 1;
                                moduleTypeBase = researchModule;
                                break;
                            default:
                                moduleLimit = 0;
                                moduleTypeBase = null;
                                break;
                        }
                        if ( iniStructure.ModuleCount > moduleLimit )
                        {
                            iniStructure.ModuleCount = moduleLimit;
                            structureBadModulesCount++;
                        }
                        else if ( iniStructure.ModuleCount < 0 )
                        {
                            iniStructure.ModuleCount = 0;
                            structureBadModulesCount++;
                        }
                        if ( moduleTypeBase != null )
                        {
                            for ( b = 0; b <= iniStructure.ModuleCount - 1; b++ )
                            {
                                newModule = new clsUnit();
                                newModule.TypeBase = moduleTypeBase;
                                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.");
            }

            foreach ( var iniFeature in iniFeatures )
            {
                if ( iniFeature.Pos == null )
                {
                    featureBadPositionCount++;
                }
                else if ( !App.PosIsWithinTileArea(iniFeature.Pos, zeroPos, map.Terrain.TileSize) )
                {
                    featureBadPositionCount++;
                }
                else
                {
                    unitTypeBase = App.ObjectData.FindOrCreateUnitType(Convert.ToString(iniFeature.Code), UnitType.Feature, -1);
                    if ( unitTypeBase.Type == UnitType.Feature )
                    {
                        featureTypeBase = (FeatureTypeBase)unitTypeBase;
                    }
                    else
                    {
                        featureTypeBase = null;
                    }
                    if ( featureTypeBase == null )
                    {
                        errorCount++;
                    }
                    else
                    {
                        newUnit = new clsUnit();
                        newUnit.TypeBase = featureTypeBase;
                        newUnit.UnitGroup = map.ScavengerUnitGroup;
                        newUnit.Pos = new WorldPos(iniFeature.Pos, iniFeature.Pos.Z);
                        newUnit.Rotation = Convert.ToInt32(iniFeature.Rotation.Direction * 360.0D / Constants.INIRotationMax);
                        if ( newUnit.Rotation == 360 )
                        {
                            newUnit.Rotation = 0;
                        }
                        if ( iniFeature.HealthPercent >= 0 )
                        {
                            newUnit.Health = MathUtil.Clamp_dbl(iniFeature.HealthPercent / 100.0D, 0.01D, 1.0D);
                        }
                        if ( iniFeature.ID == 0U )
                        {
                            iniFeature.ID = availableID;
                            App.ZeroIDWarning(newUnit, iniFeature.ID, ReturnResult);
                        }
                        unitAdd.NewUnit = newUnit;
                        unitAdd.ID = iniFeature.ID;
                        unitAdd.Perform();
                        App.ErrorIDChange(iniFeature.ID, newUnit, "Load_WZ->INIFeatures");
                        if ( availableID == iniFeature.ID )
                        {
                            availableID = newUnit.ID + 1U;
                        }
                    }
                }
            }
            if ( featureBadPositionCount > 0 )
            {
                ReturnResult.WarningAdd(featureBadPositionCount + " features had an invalid position and were removed.");
            }

            foreach ( var iniDroid in iniDroids )
            {
                if ( iniDroid.Pos == null )
                {
                    droidBadPositionCount++;
                }
                else if ( !App.PosIsWithinTileArea(iniDroid.Pos, zeroPos, map.Terrain.TileSize) )
                {
                    droidBadPositionCount++;
                }
                else
                {
                    if ( iniDroid.Template == null || iniDroid.Template == "" )
                    {
                        droidType = new DroidDesign();
                        if ( !droidType.SetDroidType((enumDroidType)(iniDroid.DroidType)) )
                        {
                            unknownDroidTypeCount++;
                        }
                        loadPartsArgs.Body = App.ObjectData.FindOrCreateBody(iniDroid.Body);
                        if ( loadPartsArgs.Body == null )
                        {
                            unknownDroidComponentCount++;
                        }
                        else
                        {
                            if ( loadPartsArgs.Body.IsUnknown )
                            {
                                unknownDroidComponentCount++;
                            }
                        }
                        loadPartsArgs.Propulsion = App.ObjectData.FindOrCreatePropulsion(Convert.ToString(iniDroid.Propulsion));
                        if ( loadPartsArgs.Propulsion == null )
                        {
                            unknownDroidComponentCount++;
                        }
                        else
                        {
                            if ( loadPartsArgs.Propulsion.IsUnknown )
                            {
                                unknownDroidComponentCount++;
                            }
                        }
                        loadPartsArgs.Construct = App.ObjectData.FindOrCreateConstruct(Convert.ToString(iniDroid.Construct));
                        if ( loadPartsArgs.Construct == null )
                        {
                            unknownDroidComponentCount++;
                        }
                        else
                        {
                            if ( loadPartsArgs.Construct.IsUnknown )
                            {
                                unknownDroidComponentCount++;
                            }
                        }
                        loadPartsArgs.Repair = App.ObjectData.FindOrCreateRepair(iniDroid.Repair);
                        if ( loadPartsArgs.Repair == null )
                        {
                            unknownDroidComponentCount++;
                        }
                        else
                        {
                            if ( loadPartsArgs.Repair.IsUnknown )
                            {
                                unknownDroidComponentCount++;
                            }
                        }
                        loadPartsArgs.Sensor = App.ObjectData.FindOrCreateSensor(iniDroid.Sensor);
                        if ( loadPartsArgs.Sensor == null )
                        {
                            unknownDroidComponentCount++;
                        }
                        else
                        {
                            if ( loadPartsArgs.Sensor.IsUnknown )
                            {
                                unknownDroidComponentCount++;
                            }
                        }
                        loadPartsArgs.Brain = App.ObjectData.FindOrCreateBrain(iniDroid.Brain);
                        if ( loadPartsArgs.Brain == null )
                        {
                            unknownDroidComponentCount++;
                        }
                        else
                        {
                            if ( loadPartsArgs.Brain.IsUnknown )
                            {
                                unknownDroidComponentCount++;
                            }
                        }
                        loadPartsArgs.ECM = App.ObjectData.FindOrCreateECM(Convert.ToString(iniDroid.ECM));
                        if ( loadPartsArgs.ECM == null )
                        {
                            unknownDroidComponentCount++;
                        }
                        else
                        {
                            if ( loadPartsArgs.ECM.IsUnknown )
                            {
                                unknownDroidComponentCount++;
                            }
                        }
                        loadPartsArgs.Weapon1 = App.ObjectData.FindOrCreateWeapon(Convert.ToString(iniDroid.Weapons[0]));
                        if ( loadPartsArgs.Weapon1 == null )
                        {
                            unknownDroidComponentCount++;
                        }
                        else
                        {
                            if ( loadPartsArgs.Weapon1.IsUnknown )
                            {
                                unknownDroidComponentCount++;
                            }
                        }
                        loadPartsArgs.Weapon2 = App.ObjectData.FindOrCreateWeapon(Convert.ToString(iniDroid.Weapons[1]));
                        if ( loadPartsArgs.Weapon2 == null )
                        {
                            unknownDroidComponentCount++;
                        }
                        else
                        {
                            if ( loadPartsArgs.Weapon2.IsUnknown )
                            {
                                unknownDroidComponentCount++;
                            }
                        }
                        loadPartsArgs.Weapon3 = App.ObjectData.FindOrCreateWeapon(Convert.ToString(iniDroid.Weapons[2]));
                        if ( loadPartsArgs.Weapon3 == null )
                        {
                            unknownDroidComponentCount++;
                        }
                        else
                        {
                            if ( loadPartsArgs.Weapon3.IsUnknown )
                            {
                                unknownDroidComponentCount++;
                            }
                        }
                        droidType.LoadParts(loadPartsArgs);
                    }
                    else
                    {
                        unitTypeBase = App.ObjectData.FindOrCreateUnitType(iniDroid.Template, UnitType.PlayerDroid, -1);
                        if ( unitTypeBase == null )
                        {
                            droidType = null;
                        }
                        else
                        {
                            if ( unitTypeBase.Type == UnitType.PlayerDroid )
                            {
                                droidType = (DroidDesign)unitTypeBase;
                            }
                            else
                            {
                                droidType = null;
                            }
                        }
                    }
                    if ( droidType == null )
                    {
                        errorCount++;
                    }
                    else
                    {
                        newUnit = new clsUnit();
                        newUnit.TypeBase = droidType;
                        if ( iniDroid.UnitGroup == null )
                        {
                            newUnit.UnitGroup = map.ScavengerUnitGroup;
                        }
                        else
                        {
                            newUnit.UnitGroup = iniDroid.UnitGroup;
                        }
                        newUnit.Pos = new WorldPos(iniDroid.Pos, iniDroid.Pos.Z);
                        newUnit.Rotation = Convert.ToInt32(iniDroid.Rotation.Direction * 360.0D / Constants.INIRotationMax);
                        if ( newUnit.Rotation == 360 )
                        {
                            newUnit.Rotation = 0;
                        }
                        if ( iniDroid.HealthPercent >= 0 )
                        {
                            newUnit.Health = MathUtil.Clamp_dbl(iniDroid.HealthPercent / 100.0D, 0.01D, 1.0D);
                        }
                        if ( iniDroid.ID == 0U )
                        {
                            iniDroid.ID = availableID;
                            App.ZeroIDWarning(newUnit, iniDroid.ID, ReturnResult);
                        }
                        unitAdd.NewUnit = newUnit;
                        unitAdd.ID = iniDroid.ID;
                        unitAdd.Perform();
                        App.ErrorIDChange(iniDroid.ID, newUnit, "Load_WZ->INIDroids");
                        if ( availableID == iniDroid.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;
        }
Beispiel #5
0
        public clsUnit PlaceUnitNear(UnitTypeBase TypeBase, XYInt Pos, clsUnitGroup UnitGroup, int Clearance, int Rotation, int MaxDistFromPos)
        {
            var PosNode = default(PathfinderNode);
            var NodeTag = default(clsNodeTag);
            var FinalTilePos = new XYInt();
            var TilePosA = new XYInt();
            var TilePosB = new XYInt();
            var X2 = 0;
            var Y2 = 0;
            var Remainder = 0;
            var Footprint = new XYInt();

            PosNode = GetNearestNodeConnection(TilePathMap, Pos, Clearance, MaxDistFromPos);
            if ( PosNode != null )
            {
                NodeTag = (clsNodeTag)PosNode.Tag;
                if ( (Pos - NodeTag.Pos).ToDoubles().GetMagnitude() <= MaxDistFromPos )
                {
                    var NewUnitAdd = new clsUnitAdd();
                    NewUnitAdd.Map = Map;
                    NewUnitAdd.StoreChange = true;
                    var NewUnit = new clsUnit();
                    NewUnitAdd.NewUnit = NewUnit;
                    NewUnit.TypeBase = TypeBase;
                    NewUnit.UnitGroup = UnitGroup;

                    FinalTilePos.X = NodeTag.Pos.X / Constants.TerrainGridSpacing;
                    FinalTilePos.Y = (NodeTag.Pos.Y / Constants.TerrainGridSpacing);
                    Footprint = TypeBase.get_GetFootprintSelected(Rotation);
                    Remainder = Footprint.X % 2;
                    if ( Remainder > 0 )
                    {
                        NewUnit.Pos.Horizontal.X = NodeTag.Pos.X;
                    }
                    else
                    {
                        if ( App.Random.Next() >= 0.5F )
                        {
                            NewUnit.Pos.Horizontal.X = (int)(NodeTag.Pos.X - Constants.TerrainGridSpacing / 2.0D);
                        }
                        else
                        {
                            NewUnit.Pos.Horizontal.X = (int)(NodeTag.Pos.X + Constants.TerrainGridSpacing / 2.0D);
                        }
                    }
                    Remainder = Footprint.Y % 2;
                    if ( Remainder > 0 )
                    {
                        NewUnit.Pos.Horizontal.Y = NodeTag.Pos.Y;
                    }
                    else
                    {
                        if ( App.Random.Next() >= 0.5F )
                        {
                            NewUnit.Pos.Horizontal.Y = (int)(NodeTag.Pos.Y - Constants.TerrainGridSpacing / 2.0D);
                        }
                        else
                        {
                            NewUnit.Pos.Horizontal.Y = (int)(NodeTag.Pos.Y + Constants.TerrainGridSpacing / 2.0D);
                        }
                    }
                    TilePosA.X = (int)((double)NewUnit.Pos.Horizontal.X / Constants.TerrainGridSpacing - Footprint.X / 2.0D + 0.5D);
                    TilePosA.Y = (int)((double)NewUnit.Pos.Horizontal.Y / Constants.TerrainGridSpacing - Footprint.Y / 2.0D + 0.5D);
                    TilePosB.X = (int)(((double)NewUnit.Pos.Horizontal.X / Constants.TerrainGridSpacing + Footprint.X / 2.0D - 0.5D));
                    TilePosB.Y = (int)(((double)NewUnit.Pos.Horizontal.Y / Constants.TerrainGridSpacing + Footprint.Y / 2.0D - 0.5D));
                    NewUnit.Rotation = Rotation;

                    NewUnitAdd.Perform();

                    for ( Y2 = Math.Max(TilePosA.Y, 0); Y2 <= Math.Min(TilePosB.Y, Map.Terrain.TileSize.Y - 1); Y2++ )
                    {
                        for ( X2 = Math.Max(TilePosA.X, 0); X2 <= Math.Min(TilePosB.X, Map.Terrain.TileSize.X - 1); X2++ )
                        {
                            TileNodeBlock(X2, Y2);
                        }
                    }

                    TilePathMap.FindCalc();

                    return NewUnit;
                }
                return null;
            }
            return null;
        }
Beispiel #6
0
        public clsUnit PlaceUnit(UnitTypeBase TypeBase, WorldPos Pos, clsUnitGroup UnitGroup, int Rotation)
        {
            var TilePosA = new XYInt();
            var TilePosB = new XYInt();
            var X2 = 0;
            var Y2 = 0;
            var FinalTilePos = new XYInt();
            var Footprint = new XYInt();

            var NewUnitAdd = new clsUnitAdd();
            NewUnitAdd.Map = Map;
            NewUnitAdd.StoreChange = true;
            var NewUnit = new clsUnit();
            NewUnitAdd.NewUnit = NewUnit;
            NewUnit.TypeBase = TypeBase;
            NewUnit.UnitGroup = UnitGroup;

            FinalTilePos.X = Pos.Horizontal.X / Constants.TerrainGridSpacing;
            FinalTilePos.Y = Pos.Horizontal.Y / Constants.TerrainGridSpacing;

            Footprint = TypeBase.get_GetFootprintSelected(Rotation);

            NewUnit.Pos = Pos;
            TilePosA.X = (int)(((double)NewUnit.Pos.Horizontal.X / Constants.TerrainGridSpacing - Footprint.X / 2.0D + 0.5D));
            TilePosA.Y = (int)(((double)NewUnit.Pos.Horizontal.Y / Constants.TerrainGridSpacing - Footprint.Y / 2.0D + 0.5D));
            TilePosB.X = (int)((double)NewUnit.Pos.Horizontal.X / Constants.TerrainGridSpacing + Footprint.X / 2.0D - 0.5D);
            TilePosB.Y = (int)((double)NewUnit.Pos.Horizontal.Y / Constants.TerrainGridSpacing + Footprint.Y / 2.0D - 0.5D);
            NewUnit.Rotation = Rotation;

            NewUnitAdd.Perform();

            for ( Y2 = Math.Max(TilePosA.Y, 0); Y2 <= Math.Min(TilePosB.Y, Map.Terrain.TileSize.Y - 1); Y2++ )
            {
                for ( X2 = Math.Max(TilePosA.X, 0); X2 <= Math.Min(TilePosB.X, Map.Terrain.TileSize.X - 1); X2++ )
                {
                    TileNodeBlock(X2, Y2);
                }
            }

            TilePathMap.FindCalc();

            return NewUnit;
        }
Beispiel #7
0
        private clsResult read_FMap_Objects(string text)
        {
            var returnResult = new clsResult("Reading objects", false);
            logger.Info("Reading objects");

            var objectsINI = IniReader.ReadString(text);

            var droidComponentUnknownCount = 0;
            var objectTypeMissingCount = 0;
            var objectPlayerNumInvalidCount = 0;
            var objectPosInvalidCount = 0;
            var designTypeUnspecifiedCount = 0;
            var unknownUnitTypeCount = 0;
            var maxUnknownUnitTypeWarningCount = 16;

            var droidDesign = default(DroidDesign);
            var newObject = default(clsUnit);
            var unitAdd = new clsUnitAdd();
            var unitTypeBase = default(UnitTypeBase);
            var isDesign = default(bool);
            var unitGroup = default(clsUnitGroup);
            var zeroPos = new XYInt(0, 0);
            UInt32 availableID = 0;

            unitAdd.Map = map;

            INIObject iniObject = default(INIObject);
            var invalid = true;
            var iniObjects = new List<INIObject> ();

            foreach (var iniSection in objectsINI) {
                iniObject = new INIObject ();
                iniObject.Type = UnitType.Unspecified;
                iniObject.Health = 1.0D;
                iniObject.WallType = -1;
                iniObject.TurretCodes = new string[Constants.MaxDroidWeapons];
                iniObject.TurretTypes = new enumTurretType[Constants.MaxDroidWeapons];
                for (var i = 0; i < Constants.MaxDroidWeapons; i++) {
                    iniObject.TurretTypes [i] = enumTurretType.Unknown;
                    iniObject.TurretCodes [i] = "";
                }
                invalid = false;
                foreach (var iniToken in iniSection.Data) {
                    if (invalid)
                    {
                        break;
                    }

                    try {
                        switch (iniToken.Name.ToLower()) {
                        case "type":
                            var typeTokens = iniToken.Data.Split (new string[] { ", " }, StringSplitOptions.None);
                            if (typeTokens.Length < 1) {
                                invalid = true;
                                returnResult.WarningAdd (string.Format ("#{0} type \"{1}\" is not valid.", iniSection.Name, iniToken.Data));
                                logger.Warn ("#{0} type \"{1}\" is not valid.", iniSection.Name, iniToken.Data);
                                continue;
                            }
                            switch (typeTokens [0].ToLower ()) {
                            case "feature":
                                iniObject.Type = UnitType.Feature;
                                iniObject.Code = typeTokens [1];
                                break;
                            case "structure":
                                iniObject.Type = UnitType.PlayerStructure;
                                iniObject.Code = typeTokens [1];
                                break;
                            case "droidtemplate":
                                iniObject.Type = UnitType.PlayerDroid;
                                iniObject.IsTemplate = true;
                                iniObject.Code = typeTokens [1];
                                break;
                            case "droiddesign":
                                iniObject.Type = UnitType.PlayerDroid;
                                break;
                            default:
                                invalid = true;
                                returnResult.WarningAdd (string.Format ("#{0} {1} \"{2}\" is not valid.", iniSection.Name, iniToken.Name, iniToken.Data));
                                logger.Warn ("#{0} {1} \"{2}\" is not valid.", iniSection.Name, iniToken.Name, iniToken.Data);
                                continue;
                            }
                            break;
                        case "droidtype":
                            var droidType = App.GetTemplateDroidTypeFromTemplateCode (iniToken.Data);
                            if (droidType == null) {
                                invalid = true;
                                returnResult.WarningAdd (string.Format ("#{0} {1} \"{2}\" is not valid.", iniSection.Name, iniToken.Name, iniToken.Data));
                                logger.Warn ("#{0} {1} \"{2}\" is not valid.", iniSection.Name, iniToken.Name, iniToken.Data);
                                continue;
                            }
                            break;
                        case "body":
                            iniObject.BodyCode = iniToken.Data;
                            break;
                        case "propulsion":
                            iniObject.PropulsionCode = iniToken.Data;
                            break;
                        case "turrentcount":
                            iniObject.TurretCount = int.Parse(iniToken.Data);
                            if (iniObject.TurretCount < 0 || iniObject.TurretCount > Constants.MaxDroidWeapons) {
                                invalid = true;
                                returnResult.WarningAdd (string.Format ("#{0} {1} \"{2}\" is not valid.", iniSection.Name, iniToken.Name, iniToken.Data));
                                logger.Warn ("#{0} {1} \"{2}\" is not valid.", iniSection.Name, iniToken.Name, iniToken.Data);
                                continue;
                            }
                            break;
                        case "turret1":
                            var turret1Tokens = iniToken.Data.Split (new string[] { ", " }, StringSplitOptions.None);
                            if (turret1Tokens.Length < 2) {
                                invalid = true;
                                returnResult.WarningAdd (string.Format ("#{0} {1} \"{2}\" is not valid.", iniSection.Name, iniToken.Name, iniToken.Data));
                                logger.Warn ("#{0} {1} \"{2}\" is not valid.", iniSection.Name, iniToken.Name, iniToken.Data);
                                continue;
                            }
                            iniObject.TurretTypes[0] = App.GetTurretTypeFromName(turret1Tokens[0]);
                            iniObject.TurretCodes[1] = turret1Tokens[1];
                            break;
                        case "turret2":
                            var turret2Tokens = iniToken.Data.Split (new string[] { ", " }, StringSplitOptions.None);
                            if (turret2Tokens.Length < 2) {
                                invalid = true;
                                returnResult.WarningAdd (string.Format ("#{0} {1} \"{2}\" is not valid.", iniSection.Name, iniToken.Name, iniToken.Data));
                                logger.Warn ("#{0} {1} \"{2}\" is not valid.", iniSection.Name, iniToken.Name, iniToken.Data);
                                continue;
                            }
                            iniObject.TurretTypes[0] = App.GetTurretTypeFromName(turret2Tokens[0]);
                            iniObject.TurretCodes[1] = turret2Tokens[1];
                            break;
                        case "turret3":
                            var turret3Tokens = iniToken.Data.Split (new string[] { ", " }, StringSplitOptions.None);
                            if (turret3Tokens.Length < 2) {
                                invalid = true;
                                returnResult.WarningAdd (string.Format ("#{0} {1} \"{2}\" is not valid.", iniSection.Name, iniToken.Name, iniToken.Data));
                                logger.Warn ("#{0} {1} \"{2}\" is not valid.", iniSection.Name, iniToken.Name, iniToken.Data);
                                continue;
                            }
                            iniObject.TurretTypes[0] = App.GetTurretTypeFromName(turret3Tokens[0]);
                            iniObject.TurretCodes[1] = turret3Tokens[1];
                            break;
                        case "id":
                            iniObject.ID = uint.Parse(iniToken.Data);
                            break;
                        case "priority":
                            iniObject.Priority = int.Parse(iniToken.Data);
                            break;
                        case "pos":
                            iniObject.Pos = XYInt.FromString(iniToken.Data);
                            break;
                        case "heading":
                            if ( !IOUtil.InvariantParse(iniToken.Data, ref iniObject.Heading) )
                            {
                                invalid = true;
                                returnResult.WarningAdd (string.Format ("#{0} {1} \"{2}\" is not valid.", iniSection.Name, iniToken.Name, iniToken.Data));
                                logger.Warn ("#{0} {1} \"{2}\" is not valid.", iniSection.Name, iniToken.Name, iniToken.Data);
                                continue;
                            }
                            break;
                        case "unitgroup":
                            iniObject.UnitGroup = iniToken.Data;
                            break;
                        case "health":
                            if ( !IOUtil.InvariantParse(iniToken.Data, ref iniObject.Health) )
                            {
                                invalid = true;
                                returnResult.WarningAdd (string.Format ("#{0} {1} \"{2}\" is not valid.", iniSection.Name, iniToken.Name, iniToken.Data));
                                logger.Warn ("#{0} {1} \"{2}\" is not valid.", iniSection.Name, iniToken.Name, iniToken.Data);
                                continue;
                            }
                            break;
                        case "walltype":
                            if ( !IOUtil.InvariantParse(iniToken.Data, ref iniObject.WallType) )
                            {
                                invalid = true;
                                returnResult.WarningAdd (string.Format ("#{0} {1} \"{2}\" is not valid.", iniSection.Name, iniToken.Name, iniToken.Data));
                                logger.Warn ("#{0} {1} \"{2}\" is not valid.", iniSection.Name, iniToken.Name, iniToken.Data);
                                continue;
                            }
                            if (iniObject.WallType < 0 || iniObject.WallType > 3) {
                                iniObject.WallType = -1;
                            }
                            break;
                        case "scriptlabel":
                            iniObject.Label = iniToken.Data;
                            break;
                        default:
                            returnResult.WarningAdd(string.Format("Found an invalid key: {0} = {1}", iniToken.Name, iniToken.Data), false);
                            logger.Warn("Found an invalid key: {0} = {1}", iniToken.Name, iniToken.Data);
                            break;
                        }
                    }
                    catch (Exception ex) {
                        invalid = true;
                        returnResult.WarningAdd(
                            string.Format("#{0} invalid {2}: \"{3}\", got exception: {2}", iniSection.Name, iniToken.Name, iniToken.Data, ex.Message), false);
                        logger.WarnException(string.Format("#{0} invalid {2} \"{1}\"", iniSection.Name, iniToken.Name, iniToken.Data), ex);
                    }
                }

                if (!invalid) {
                    iniObjects.Add (iniObject);
                }
            }

            try {
                availableID = iniObjects.Max (w => w.ID) + 10;
                foreach (var iniObject2 in iniObjects)
                {
                    if ( iniObject2.Pos == null )
                    {
                        objectPosInvalidCount++;
                        continue;
                    }
                    else if ( !App.PosIsWithinTileArea(iniObject2.Pos, zeroPos, map.Terrain.TileSize) )
                    {
                        objectPosInvalidCount++;
                        continue;
                    }

                    unitTypeBase = null;
                    if ( iniObject2.Type != UnitType.Unspecified )
                    {
                        isDesign = false;
                        if ( iniObject2.Type == UnitType.PlayerDroid )
                        {
                            if ( !iniObject2.IsTemplate )
                            {
                                isDesign = true;
                            }
                        }
                        if ( isDesign )
                        {
                            droidDesign = new DroidDesign();
                            droidDesign.TemplateDroidType = iniObject2.TemplateDroidType;
                            if ( droidDesign.TemplateDroidType == null )
                            {
                                droidDesign.TemplateDroidType = App.TemplateDroidType_Droid;
                                designTypeUnspecifiedCount++;
                            }
                            if ( iniObject2.BodyCode != null )
                            {
                                droidDesign.Body = App.ObjectData.FindOrCreateBody(Convert.ToString(iniObject2.BodyCode));
                                if ( droidDesign.Body.IsUnknown )
                                {
                                    droidComponentUnknownCount++;
                                }
                            }
                            if ( iniObject2.PropulsionCode != null )
                            {
                                droidDesign.Propulsion = App.ObjectData.FindOrCreatePropulsion(iniObject2.PropulsionCode);
                                if ( droidDesign.Propulsion.IsUnknown )
                                {
                                    droidComponentUnknownCount++;
                                }
                            }
                            droidDesign.TurretCount = (byte)(iniObject2.TurretCount);
                            if ( iniObject2.TurretCodes[0] != "" )
                            {
                                droidDesign.Turret1 = App.ObjectData.FindOrCreateTurret(iniObject2.TurretTypes[0],
                                    Convert.ToString(iniObject2.TurretCodes[0]));
                                if ( droidDesign.Turret1.IsUnknown )
                                {
                                    droidComponentUnknownCount++;
                                }
                            }
                            if ( iniObject2.TurretCodes[1] != "" )
                            {
                                droidDesign.Turret2 = App.ObjectData.FindOrCreateTurret(iniObject2.TurretTypes[1],
                                    Convert.ToString(iniObject2.TurretCodes[1]));
                                if ( droidDesign.Turret2.IsUnknown )
                                {
                                    droidComponentUnknownCount++;
                                }
                            }
                            if ( iniObject2.TurretCodes[2] != "" )
                            {
                                droidDesign.Turret3 = App.ObjectData.FindOrCreateTurret(iniObject2.TurretTypes[2],
                                    Convert.ToString(iniObject2.TurretCodes[2]));
                                if ( droidDesign.Turret3.IsUnknown )
                                {
                                    droidComponentUnknownCount++;
                                }
                            }
                            droidDesign.UpdateAttachments();
                            unitTypeBase = droidDesign;
                        }
                        else
                        {
                            unitTypeBase = App.ObjectData.FindOrCreateUnitType(iniObject2.Code, iniObject2.Type, iniObject2.WallType);
                            if ( unitTypeBase.IsUnknown )
                            {
                                if ( unknownUnitTypeCount < maxUnknownUnitTypeWarningCount )
                                {
                                    returnResult.WarningAdd("\"{0}\" is not a loaded object.".Format2(iniObject2.Code));
                                }
                                unknownUnitTypeCount++;
                            }
                        }
                    }
                    if ( unitTypeBase == null )
                    {
                        objectTypeMissingCount++;
                        continue;
                    }

                    newObject = new clsUnit();
                    newObject.TypeBase = unitTypeBase;
                    newObject.Pos.Horizontal.X = iniObject2.Pos.X;
                    newObject.Pos.Horizontal.Y = iniObject2.Pos.Y;
                    newObject.Health = iniObject2.Health;
                    newObject.SavePriority = iniObject2.Priority;
                    newObject.Rotation = (int)(iniObject2.Heading);
                    if ( newObject.Rotation >= 360 )
                    {
                        newObject.Rotation -= 360;
                    }
                    if ( iniObject2.UnitGroup == null || iniObject2.UnitGroup == "" )
                    {
                        if ( iniObject2.Type != UnitType.Feature )
                        {
                            objectPlayerNumInvalidCount++;
                        }
                        newObject.UnitGroup = map.ScavengerUnitGroup;
                    }
                    else
                    {
                        if ( iniObject2.UnitGroup.ToLower() == "scavenger" )
                        {
                            newObject.UnitGroup = map.ScavengerUnitGroup;
                        }
                        else
                        {
                            UInt32 PlayerNum = 0;
                            try
                            {
                                if ( !IOUtil.InvariantParse(iniObject2.UnitGroup, ref PlayerNum) )
                                {
                                    throw (new Exception());
                                }
                                if ( PlayerNum < Constants.PlayerCountMax )
                                {
                                    unitGroup = map.UnitGroups[Convert.ToInt32(PlayerNum)];
                                }
                                else
                                {
                                    unitGroup = map.ScavengerUnitGroup;
                                    objectPlayerNumInvalidCount++;
                                }
                            }
                            catch ( Exception )
                            {
                                objectPlayerNumInvalidCount++;
                                unitGroup = map.ScavengerUnitGroup;
                            }
                            newObject.UnitGroup = unitGroup;
                        }
                    }
                    if ( iniObject2.ID == 0U )
                    {
                        // iniObject2.ID = availableID;
                        App.ZeroIDWarning(newObject, iniObject2.ID, returnResult);
                    }
                    unitAdd.NewUnit = newObject;
                    unitAdd.ID = iniObject2.ID;
                    unitAdd.Label = iniObject2.Label;
                    unitAdd.Perform();
                    App.ErrorIDChange(iniObject2.ID, newObject, "Read_FMap_Objects");
                    if ( availableID == iniObject2.ID )
                    {
                        availableID = newObject.ID + 1U;
                    }
                }

                if ( unknownUnitTypeCount > maxUnknownUnitTypeWarningCount )
                {
                    returnResult.WarningAdd (string.Format ("{0} objects were not in the loaded object data.", unknownUnitTypeCount));
                }
                if ( objectTypeMissingCount > 0 )
                {
                    returnResult.WarningAdd (string.Format ("{0} objects did not specify a type and were ignored.", objectTypeMissingCount));
                }
                if ( droidComponentUnknownCount > 0 )
                {
                    returnResult.WarningAdd (string.Format ("{0} components used by droids were loaded as unknowns.", droidComponentUnknownCount));
                }
                if ( objectPlayerNumInvalidCount > 0 )
                {
                    returnResult.WarningAdd (string.Format ("{0} objects had an invalid player number and were set to player 0.", objectPlayerNumInvalidCount));
                }
                if ( objectPosInvalidCount > 0 )
                {
                    returnResult.WarningAdd (string.Format ("{0} objects had a position that was off-map and were ignored.", objectPosInvalidCount));
                }
                if ( designTypeUnspecifiedCount > 0 )
                {
                    returnResult.WarningAdd (string.Format ("{0} designed droids did not specify a template droid type and were set to droid.", designTypeUnspecifiedCount));
                }
            }
            catch (Exception ex) {
                Debugger.Break ();
                returnResult.ProblemAdd (string.Format("Got a exeption: {0}", ex.Message));
                logger.ErrorException ("Got exception", ex);
            }

            return returnResult;
        }
Beispiel #8
0
        public void MapInsert(clsMap MapToInsert, XYInt Offset, XYInt Area, bool InsertHeights, bool InsertTextures, bool InsertUnits,
            bool DeleteUnits, bool InsertGateways, bool DeleteGateways)
        {
            var Finish = new XYInt();
            var X = 0;
            var Y = 0;
            var SectorStart = new XYInt();
            var SectorFinish = new XYInt();
            var AreaAdjusted = new XYInt();
            var SectorNum = new XYInt();

            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 XYInt(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;
                    }
                }
                var 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;
                    }
                }
            }

            var LastTile = new XYInt();
            LastTile = Finish;
            LastTile.X--;
            LastTile.Y--;
            if ( DeleteGateways )
            {
                var 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 )
            {
                var GateStart = new XYInt();
                var GateFinish = new XYInt();
                var Gateway = default(clsGateway);
                foreach ( var 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 )
            {
                var UnitsToDelete = new SimpleList<clsUnit>();
                var Unit = default(clsUnit);
                for ( Y = SectorStart.Y; Y <= SectorFinish.Y; Y++ )
                {
                    for ( X = SectorStart.X; X <= SectorFinish.X; X++ )
                    {
                        var Connection = default(clsUnitSectorConnection);
                        foreach ( var 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 ( var 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 )
            {
                var PosDif = new XYInt();
                var NewUnit = default(clsUnit);
                var Unit = default(clsUnit);
                var ZeroPos = new XYInt(0, 0);
                var UnitAdd = new clsUnitAdd();

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

                PosDif.X = Offset.X * Constants.TerrainGridSpacing;
                PosDif.Y = Offset.Y * Constants.TerrainGridSpacing;
                foreach ( var 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();
        }
Beispiel #9
0
        public void UndoPerform()
        {
            var 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];

            var SectorNum = new XYInt();
            var CurrentSector = default(clsShadowSector);
            var UndoSector = default(clsShadowSector);
            var NewSectorsForThisUndo = new SimpleList<clsShadowSector>();
            foreach ( var 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;
            var UnitAdd = new clsUnitAdd();
            UnitAdd.Map = this;
            var Unit = default(clsUnit);
            for ( var 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();
                }
            }

            var GatewayChange = default(clsGatewayChange);
            for ( var 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();
        }
Beispiel #10
0
        public void RedoPerform()
        {
            var ThisUndo = default(clsUndo);

            ThisUndo = Undos[UndoPosition];

            var SectorNum = new XYInt();
            var CurrentSector = default(clsShadowSector);
            var UndoSector = default(clsShadowSector);
            var NewSectorsForThisUndo = new SimpleList<clsShadowSector>();
            foreach ( var 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;
            var UnitAdd = new clsUnitAdd();
            UnitAdd.Map = this;
            var Unit = default(clsUnit);
            for ( var 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();
                }
            }

            var GatewayChange = default(clsGatewayChange);
            for ( var 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();
        }
Beispiel #11
0
        public void PerformTileWall(clsWallType WallType, XYInt TileNum, bool Expand)
        {
            var SectorNum = new XYInt();
            var Unit = default(clsUnit);
            var UnitTile = new XYInt();
            var Difference = new XYInt();
            var TileWalls = enumTileWalls.None;
            var Walls = new SimpleList<clsUnit>();
            var Removals = new SimpleList<clsUnit>();
            var unitTypeBase = default(UnitTypeBase);
            var structureTypeBase = default(StructureTypeBase);
            var X = 0;
            var Y = 0;
            var MinTile = new XYInt();
            var MaxTile = new XYInt();
            var Connection = default(clsUnitSectorConnection);
            MinTile.X = TileNum.X - 1;
            MinTile.Y = TileNum.Y - 1;
            MaxTile.X = TileNum.X + 1;
            MaxTile.Y = TileNum.Y + 1;
            var SectorStart = GetSectorNumClamped(GetTileSectorNum(MinTile));
            var 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 ( var tempLoopVar_Connection in Sectors[SectorNum.X, SectorNum.Y].Units )
                    {
                        Connection = tempLoopVar_Connection;
                        Unit = Connection.Unit;
                        unitTypeBase = Unit.TypeBase;
                        if ( unitTypeBase.Type == UnitType.PlayerStructure )
                        {
                            structureTypeBase = (StructureTypeBase)unitTypeBase;
                            if ( structureTypeBase.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 = TileWalls | enumTileWalls.Bottom;
                                        Walls.Add(Unit);
                                    }
                                }
                                else if ( Difference.Y == 0 )
                                {
                                    if ( Difference.X == 0 )
                                    {
                                        Removals.Add(Unit);
                                    }
                                    else if ( Difference.X == -1 )
                                    {
                                        TileWalls = TileWalls | enumTileWalls.Left;
                                        Walls.Add(Unit);
                                    }
                                    else if ( Difference.X == 1 )
                                    {
                                        TileWalls = TileWalls | enumTileWalls.Right;
                                        Walls.Add(Unit);
                                    }
                                }
                                else if ( Difference.Y == -1 )
                                {
                                    if ( Difference.X == 0 )
                                    {
                                        TileWalls = TileWalls | enumTileWalls.Top;
                                        Walls.Add(Unit);
                                    }
                                }
                            }
                        }
                    }
                }
            }

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

            var NewUnit = new clsUnit();
            UnitTypeBase newUnitTypeBase = 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 XYInt(1, 1));
            NewUnit.TypeBase = newUnitTypeBase;
            var UnitAdd = new clsUnitAdd();
            UnitAdd.Map = this;
            UnitAdd.NewUnit = NewUnit;
            UnitAdd.StoreChange = true;
            UnitAdd.Perform();

            if ( Expand )
            {
                var Wall = default(clsUnit);
                foreach ( var tempLoopVar_Wall in Walls )
                {
                    Wall = tempLoopVar_Wall;
                    PerformTileWall(WallType, GetPosTileNum(Wall.Pos.Horizontal), false);
                }
            }
        }
Beispiel #12
0
        public clsMap(clsMap MapToCopy, XYInt Offset, XYInt Area)
            : this()
        {
            var EndX = 0;
            var EndY = 0;
            var X = 0;
            var 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 XYInt(X, Y));
                }
            }

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

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

            PosDif.X = - Offset.X * Constants.TerrainGridSpacing;
            PosDif.Y = - Offset.Y * Constants.TerrainGridSpacing;
            var Unit = default(clsUnit);
            var NewPos = new XYInt();
            foreach ( var 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();
                }
            }
        }
Beispiel #13
0
        public void UnitSwap(clsUnit OldUnit, clsUnit 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");
        }