예제 #1
0
        private clsResult ValidateMap_UnitPositions()
        {
            clsStructureType.enumStructureType structureType;
            clsMap.clsUnit current;
            IEnumerator enumerator;
            IEnumerator enumerator2;
            IEnumerator enumerator3;
            clsResult result = new clsResult("Validate unit positions");
            bool[,] flagArray = new bool[(this.Map.Terrain.TileSize.X - 1) + 1, (this.Map.Terrain.TileSize.Y - 1) + 1];
            clsStructureType[,] typeArray2 = new clsStructureType[(this.Map.Terrain.TileSize.X - 1) + 1, (this.Map.Terrain.TileSize.Y - 1) + 1];
            clsFeatureType[,] typeArray = new clsFeatureType[(this.Map.Terrain.TileSize.X - 1) + 1, (this.Map.Terrain.TileSize.Y - 1) + 1];
            clsMap.clsUnitGroup[,] groupArray = new clsMap.clsUnitGroup[(this.Map.Terrain.TileSize.X - 1) + 1, (this.Map.Terrain.TileSize.Y - 1) + 1];
            bool[] flagArray2 = new bool[(this.Map.Units.Count - 1) + 1];
            try
            {
                enumerator = this.Map.Units.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    current = (clsMap.clsUnit) enumerator.Current;
                    if (current.Type.Type == clsUnitType.enumType.PlayerStructure)
                    {
                        clsStructureType type = (clsStructureType) current.Type;
                        structureType = type.StructureType;
                        flagArray2[current.MapLink.ArrayPosition] = type.IsModule() | (structureType == clsStructureType.enumStructureType.ResourceExtractor);
                    }
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            try
            {
                enumerator2 = this.Map.Units.GetEnumerator();
                while (enumerator2.MoveNext())
                {
                    current = (clsMap.clsUnit) enumerator2.Current;
                    if (!flagArray2[current.MapLink.ArrayPosition])
                    {
                        modMath.sXY_int _int2;
                        modMath.sXY_int _int4;
                        modMath.sXY_int footprint = current.Type.get_GetFootprintSelected(current.Rotation);
                        this.Map.GetFootprintTileRange(current.Pos.Horizontal, footprint, ref _int4, ref _int2);
                        if ((((_int4.X < 0) | (_int2.X >= this.Map.Terrain.TileSize.X)) | (_int4.Y < 0)) | (_int2.Y >= this.Map.Terrain.TileSize.Y))
                        {
                            clsResultProblemGoto<clsResultItemPosGoto> item = modResults.CreateResultProblemGotoForObject(current);
                            item.Text = "Unit off map at position " + current.GetPosText() + ".";
                            result.ItemAdd(item);
                        }
                        else
                        {
                            int y = _int2.Y;
                            for (int i = _int4.Y; i <= y; i++)
                            {
                                int x = _int2.X;
                                for (int j = _int4.X; j <= x; j++)
                                {
                                    if (flagArray[j, i])
                                    {
                                        clsResultProblemGoto<clsResultItemPosGoto> goto2 = modResults.CreateResultProblemGotoForObject(current);
                                        goto2.Text = "Bad unit overlap on tile " + Conversions.ToString(j) + ", " + Conversions.ToString(i) + ".";
                                        result.ItemAdd(goto2);
                                    }
                                    else
                                    {
                                        flagArray[j, i] = true;
                                        if (current.Type.Type == clsUnitType.enumType.PlayerStructure)
                                        {
                                            typeArray2[j, i] = (clsStructureType) current.Type;
                                        }
                                        else if (current.Type.Type == clsUnitType.enumType.Feature)
                                        {
                                            typeArray[j, i] = (clsFeatureType) current.Type;
                                        }
                                        groupArray[j, i] = current.UnitGroup;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                if (enumerator2 is IDisposable)
                {
                    (enumerator2 as IDisposable).Dispose();
                }
            }
            try
            {
                enumerator3 = this.Map.Units.GetEnumerator();
                while (enumerator3.MoveNext())
                {
                    modMath.sXY_int _int;
                    bool flag;
                    current = (clsMap.clsUnit) enumerator3.Current;
                    if (!flagArray2[current.MapLink.ArrayPosition])
                    {
                        continue;
                    }
                    structureType = ((clsStructureType) current.Type).StructureType;
                    _int.X = (int) Math.Round(((double) (((double) current.Pos.Horizontal.X) / 128.0)));
                    _int.Y = (int) Math.Round(((double) (((double) current.Pos.Horizontal.Y) / 128.0)));
                    if ((((_int.X < 0) | (_int.X >= this.Map.Terrain.TileSize.X)) | (_int.Y < 0)) | (_int.Y >= this.Map.Terrain.TileSize.Y))
                    {
                        clsResultProblemGoto<clsResultItemPosGoto> goto3 = modResults.CreateResultProblemGotoForObject(current);
                        goto3.Text = "Module off map at position " + current.GetPosText() + ".";
                        result.ItemAdd(goto3);
                        continue;
                    }
                    if (typeArray2[_int.X, _int.Y] != null)
                    {
                        if (groupArray[_int.X, _int.Y] == current.UnitGroup)
                        {
                            switch (structureType)
                            {
                                case clsStructureType.enumStructureType.FactoryModule:
                                    if ((typeArray2[_int.X, _int.Y].StructureType == clsStructureType.enumStructureType.Factory) | (typeArray2[_int.X, _int.Y].StructureType == clsStructureType.enumStructureType.VTOLFactory))
                                    {
                                        flag = true;
                                    }
                                    else
                                    {
                                        flag = false;
                                    }
                                    goto Label_0648;

                                case clsStructureType.enumStructureType.PowerModule:
                                    if (typeArray2[_int.X, _int.Y].StructureType == clsStructureType.enumStructureType.PowerGenerator)
                                    {
                                        flag = true;
                                    }
                                    else
                                    {
                                        flag = false;
                                    }
                                    goto Label_0648;

                                case clsStructureType.enumStructureType.ResearchModule:
                                    if (typeArray2[_int.X, _int.Y].StructureType == clsStructureType.enumStructureType.Research)
                                    {
                                        flag = true;
                                    }
                                    else
                                    {
                                        flag = false;
                                    }
                                    goto Label_0648;
                            }
                            flag = false;
                        }
                        else
                        {
                            flag = false;
                        }
                    }
                    else if (typeArray[_int.X, _int.Y] != null)
                    {
                        if (structureType == clsStructureType.enumStructureType.ResourceExtractor)
                        {
                            if (typeArray[_int.X, _int.Y].FeatureType == clsFeatureType.enumFeatureType.OilResource)
                            {
                                flag = true;
                            }
                            else
                            {
                                flag = false;
                            }
                        }
                        else
                        {
                            flag = false;
                        }
                    }
                    else if (structureType == clsStructureType.enumStructureType.ResourceExtractor)
                    {
                        flag = true;
                    }
                    else
                    {
                        flag = false;
                    }
                Label_0648:
                    if (!flag)
                    {
                        clsResultProblemGoto<clsResultItemPosGoto> goto4 = modResults.CreateResultProblemGotoForObject(current);
                        goto4.Text = "Bad module on tile " + Conversions.ToString(_int.X) + ", " + Conversions.ToString(_int.Y) + ".";
                        result.ItemAdd(goto4);
                    }
                }
            }
            finally
            {
                if (enumerator3 is IDisposable)
                {
                    (enumerator3 as IDisposable).Dispose();
                }
            }
            return result;
        }
예제 #2
0
        private clsResult ValidateMap_UnitPositions()
        {
            clsResult Result = new clsResult("Validate unit positions");

            //check unit positions

            bool[,] TileHasUnit = new bool[Map.Terrain.TileSize.X, Map.Terrain.TileSize.Y];
            clsStructureType[,] TileStructureType = new clsStructureType[Map.Terrain.TileSize.X, Map.Terrain.TileSize.Y];
            clsFeatureType[,] TileFeatureType = new clsFeatureType[Map.Terrain.TileSize.X, Map.Terrain.TileSize.Y];
            clsMap.clsUnitGroup[,] TileObjectGroup = new clsMap.clsUnitGroup[Map.Terrain.TileSize.X, Map.Terrain.TileSize.Y];
            int X = 0;
            int Y = 0;
            sXY_int StartPos = new sXY_int();
            sXY_int FinishPos = new sXY_int();
            sXY_int CentrePos = new sXY_int();
            clsStructureType.enumStructureType StructureTypeType;
            clsStructureType StructureType = default(clsStructureType);
            sXY_int Footprint = new sXY_int();
            bool[] UnitIsStructureModule = new bool[Map.Units.Count];
            bool IsValid = default(bool);
            clsMap.clsUnit Unit = default(clsMap.clsUnit);
            foreach ( clsMap.clsUnit tempLoopVar_Unit in Map.Units )
            {
                Unit = tempLoopVar_Unit;
                if ( Unit.Type.Type == clsUnitType.enumType.PlayerStructure )
                {
                    StructureType = (clsStructureType)Unit.Type;
                    StructureTypeType = StructureType.StructureType;
                    UnitIsStructureModule[Unit.MapLink.ArrayPosition] = StructureType.IsModule() |
                                                                        StructureTypeType == clsStructureType.enumStructureType.ResourceExtractor;
                }
            }
            //check and store non-module units first. modules need to check for the underlying unit.
            foreach ( clsMap.clsUnit tempLoopVar_Unit in Map.Units )
            {
                Unit = tempLoopVar_Unit;
                if ( !UnitIsStructureModule[Unit.MapLink.ArrayPosition] )
                {
                    Footprint = Unit.Type.get_GetFootprintSelected(Unit.Rotation);
                    Map.GetFootprintTileRange(Unit.Pos.Horizontal, Footprint, StartPos, FinishPos);
                    if ( StartPos.X < 0 | FinishPos.X >= Map.Terrain.TileSize.X
                         | StartPos.Y < 0 | FinishPos.Y >= Map.Terrain.TileSize.Y )
                    {
                        clsResultProblemGoto<clsResultItemPosGoto> resultItem = modResults.CreateResultProblemGotoForObject(Unit);
                        resultItem.Text = "Unit off map at position " + Unit.GetPosText() + ".";
                        Result.ItemAdd(resultItem);
                    }
                    else
                    {
                        for ( Y = StartPos.Y; Y <= FinishPos.Y; Y++ )
                        {
                            for ( X = StartPos.X; X <= FinishPos.X; X++ )
                            {
                                if ( TileHasUnit[X, Y] )
                                {
                                    clsResultProblemGoto<clsResultItemPosGoto> resultItem = modResults.CreateResultProblemGotoForObject(Unit);
                                    resultItem.Text = "Bad unit overlap on tile " + Convert.ToString(X) + ", " + Convert.ToString(Y) + ".";
                                    Result.ItemAdd(resultItem);
                                }
                                else
                                {
                                    TileHasUnit[X, Y] = true;
                                    if ( Unit.Type.Type == clsUnitType.enumType.PlayerStructure )
                                    {
                                        TileStructureType[X, Y] = (clsStructureType)Unit.Type;
                                    }
                                    else if ( Unit.Type.Type == clsUnitType.enumType.Feature )
                                    {
                                        TileFeatureType[X, Y] = (clsFeatureType)Unit.Type;
                                    }
                                    TileObjectGroup[X, Y] = Unit.UnitGroup;
                                }
                            }
                        }
                    }
                }
            }
            //check modules and extractors
            foreach ( clsMap.clsUnit tempLoopVar_Unit in Map.Units )
            {
                Unit = tempLoopVar_Unit;
                if ( UnitIsStructureModule[Unit.MapLink.ArrayPosition] )
                {
                    StructureTypeType = ((clsStructureType)Unit.Type).StructureType;
                    CentrePos.X = Conversion.Int(Unit.Pos.Horizontal.X / App.TerrainGridSpacing);
                    CentrePos.Y = (int)(Conversion.Int(Unit.Pos.Horizontal.Y / App.TerrainGridSpacing));
                    if ( CentrePos.X < 0 | CentrePos.X >= Map.Terrain.TileSize.X
                         | CentrePos.Y < 0 | CentrePos.Y >= Map.Terrain.TileSize.Y )
                    {
                        clsResultProblemGoto<clsResultItemPosGoto> resultItem = modResults.CreateResultProblemGotoForObject(Unit);
                        resultItem.Text = "Module off map at position " + Unit.GetPosText() + ".";
                        Result.ItemAdd(resultItem);
                    }
                    else
                    {
                        if ( TileStructureType[CentrePos.X, CentrePos.Y] != null )
                        {
                            if ( TileObjectGroup[CentrePos.X, CentrePos.Y] == Unit.UnitGroup )
                            {
                                if ( StructureTypeType == clsStructureType.enumStructureType.FactoryModule )
                                {
                                    if ( TileStructureType[CentrePos.X, CentrePos.Y].StructureType == clsStructureType.enumStructureType.Factory
                                         | TileStructureType[CentrePos.X, CentrePos.Y].StructureType == clsStructureType.enumStructureType.VTOLFactory )
                                    {
                                        IsValid = true;
                                    }
                                    else
                                    {
                                        IsValid = false;
                                    }
                                }
                                else if ( StructureTypeType == clsStructureType.enumStructureType.PowerModule )
                                {
                                    if ( TileStructureType[CentrePos.X, CentrePos.Y].StructureType == clsStructureType.enumStructureType.PowerGenerator )
                                    {
                                        IsValid = true;
                                    }
                                    else
                                    {
                                        IsValid = false;
                                    }
                                }
                                else if ( StructureTypeType == clsStructureType.enumStructureType.ResearchModule )
                                {
                                    if ( TileStructureType[CentrePos.X, CentrePos.Y].StructureType == clsStructureType.enumStructureType.Research )
                                    {
                                        IsValid = true;
                                    }
                                    else
                                    {
                                        IsValid = false;
                                    }
                                }
                                else
                                {
                                    IsValid = false;
                                }
                            }
                            else
                            {
                                IsValid = false;
                            }
                        }
                        else if ( TileFeatureType[CentrePos.X, CentrePos.Y] != null )
                        {
                            if ( StructureTypeType == clsStructureType.enumStructureType.ResourceExtractor )
                            {
                                if ( TileFeatureType[CentrePos.X, CentrePos.Y].FeatureType == clsFeatureType.enumFeatureType.OilResource )
                                {
                                    IsValid = true;
                                }
                                else
                                {
                                    IsValid = false;
                                }
                            }
                            else
                            {
                                IsValid = false;
                            }
                        }
                        else if ( StructureTypeType == clsStructureType.enumStructureType.ResourceExtractor )
                        {
                            IsValid = true;
                        }
                        else
                        {
                            IsValid = false;
                        }
                        if ( !IsValid )
                        {
                            clsResultProblemGoto<clsResultItemPosGoto> resultItem = modResults.CreateResultProblemGotoForObject(Unit);
                            resultItem.Text = "Bad module on tile " + Convert.ToString(CentrePos.X) + ", " + Convert.ToString(CentrePos.Y) + ".";
                            Result.ItemAdd(resultItem);
                        }
                    }
                }
            }

            return Result;
        }