Esempio n. 1
0
        private clsResult ValidateMap_UnitPositions()
        {
            var Result = new clsResult("Validate unit positions", false);
            logger.Info("Validate unit positions");

            //check unit positions

            var TileHasUnit = new bool[Map.Terrain.TileSize.X, Map.Terrain.TileSize.Y];
            var tileStructureTypeBase = new StructureTypeBase[Map.Terrain.TileSize.X, Map.Terrain.TileSize.Y];
            var tileFeatureTypeBase = new FeatureTypeBase[Map.Terrain.TileSize.X, Map.Terrain.TileSize.Y];
            var TileObjectGroup = new clsUnitGroup[Map.Terrain.TileSize.X, Map.Terrain.TileSize.Y];

            var StartPos = new XYInt();
            var FinishPos = new XYInt();
            var CentrePos = new XYInt();
            StructureTypeBase.enumStructureType StructureTypeType;
            StructureTypeBase structureTypeBase;
            var Footprint = new XYInt();
            var UnitIsStructureModule = new bool[Map.Units.Count];
            bool IsValid;

            foreach ( var unit in Map.Units )
            {
                if ( unit.TypeBase.Type == UnitType.PlayerStructure )
                {
                    structureTypeBase = (StructureTypeBase)unit.TypeBase;
                    StructureTypeType = structureTypeBase.StructureType;
                    UnitIsStructureModule[unit.MapLink.ArrayPosition] = structureTypeBase.IsModule() |
                                                                        StructureTypeType == StructureTypeBase.enumStructureType.ResourceExtractor;
                }
            }
            //check and store non-module units first. modules need to check for the underlying unit.
            foreach ( var unit in Map.Units )
            {
                if ( !UnitIsStructureModule[unit.MapLink.ArrayPosition] )
                {
                    Footprint = unit.TypeBase.get_GetFootprintSelected(unit.Rotation);
                    Map.GetFootprintTileRange(unit.Pos.Horizontal, Footprint, ref StartPos, ref FinishPos);
                    if ( StartPos.X < 0 | FinishPos.X >= Map.Terrain.TileSize.X
                         | StartPos.Y < 0 | FinishPos.Y >= Map.Terrain.TileSize.Y )
                    {
                        var resultItem = modResults.CreateResultProblemGotoForObject(unit);
                        resultItem.Text = string.Format("Unit off map at position {0}.", unit.GetPosText());
                        Result.ItemAdd(resultItem);
                    }
                    else
                    {
                        for ( var y = StartPos.Y; y <= FinishPos.Y; y++ )
                        {
                            for ( var x = StartPos.X; x <= FinishPos.X; x++ )
                            {
                                if ( TileHasUnit[x, y] )
                                {
                                    var resultItem = modResults.CreateResultProblemGotoForObject(unit);
                                    logger.Info("Bad overlap of {0} on tile {1}, {2}.", unit.TypeBase.GetDisplayTextName(), x, y);
                                    resultItem.Text = string.Format("Bad unit overlap of {0} on tile {1}, {2}.", unit.TypeBase.GetDisplayTextName(), x, y);
                                    Result.ItemAdd(resultItem);
                                }
                                else
                                {
                                    logger.Debug("{0} on X:{1}, Y:{2} tile.", unit.TypeBase.GetDisplayTextName(), x, y);

                                    TileHasUnit[x, y] = true;
                                    if ( unit.TypeBase.Type == UnitType.PlayerStructure )
                                    {
                                        tileStructureTypeBase[x, y] = (StructureTypeBase)unit.TypeBase;
                                    }
                                    else if ( unit.TypeBase.Type == UnitType.Feature )
                                    {
                                        tileFeatureTypeBase[x, y] = (FeatureTypeBase)unit.TypeBase;
                                    }
                                    TileObjectGroup[x, y] = unit.UnitGroup;
                                }
                            }
                        }
                    }
                }
            }
            //check modules and extractors
            foreach ( var unit in Map.Units )
            {
                if ( UnitIsStructureModule[unit.MapLink.ArrayPosition] )
                {
                    StructureTypeType = ((StructureTypeBase)unit.TypeBase).StructureType;
                    CentrePos.X = (unit.Pos.Horizontal.X / Constants.TerrainGridSpacing);
                    CentrePos.Y = unit.Pos.Horizontal.Y / Constants.TerrainGridSpacing;
                    if ( CentrePos.X < 0 | CentrePos.X >= Map.Terrain.TileSize.X
                         | CentrePos.Y < 0 | CentrePos.Y >= Map.Terrain.TileSize.Y )
                    {
                        var resultItem = modResults.CreateResultProblemGotoForObject(unit);
                        resultItem.Text = "Module off map at position " + unit.GetPosText() + ".";
                        Result.ItemAdd(resultItem);
                    }
                    else
                    {
                        if ( tileStructureTypeBase[CentrePos.X, CentrePos.Y] != null )
                        {
                            if ( TileObjectGroup[CentrePos.X, CentrePos.Y] == unit.UnitGroup )
                            {
                                if ( StructureTypeType == StructureTypeBase.enumStructureType.FactoryModule )
                                {
                                    if ( tileStructureTypeBase[CentrePos.X, CentrePos.Y].StructureType == StructureTypeBase.enumStructureType.Factory
                                         | tileStructureTypeBase[CentrePos.X, CentrePos.Y].StructureType == StructureTypeBase.enumStructureType.VTOLFactory )
                                    {
                                        IsValid = true;
                                    }
                                    else
                                    {
                                        IsValid = false;
                                    }
                                }
                                else if ( StructureTypeType == StructureTypeBase.enumStructureType.PowerModule )
                                {
                                    if ( tileStructureTypeBase[CentrePos.X, CentrePos.Y].StructureType == StructureTypeBase.enumStructureType.PowerGenerator )
                                    {
                                        IsValid = true;
                                    }
                                    else
                                    {
                                        IsValid = false;
                                    }
                                }
                                else if ( StructureTypeType == StructureTypeBase.enumStructureType.ResearchModule )
                                {
                                    if ( tileStructureTypeBase[CentrePos.X, CentrePos.Y].StructureType == StructureTypeBase.enumStructureType.Research )
                                    {
                                        IsValid = true;
                                    }
                                    else
                                    {
                                        IsValid = false;
                                    }
                                }
                                else
                                {
                                    IsValid = false;
                                }
                            }
                            else
                            {
                                IsValid = false;
                            }
                        }
                        else if ( tileFeatureTypeBase[CentrePos.X, CentrePos.Y] != null )
                        {
                            if ( StructureTypeType == StructureTypeBase.enumStructureType.ResourceExtractor )
                            {
                                if ( tileFeatureTypeBase[CentrePos.X, CentrePos.Y].FeatureType == FeatureTypeBase.enumFeatureType.OilResource )
                                {
                                    IsValid = true;
                                }
                                else
                                {
                                    IsValid = false;
                                }
                            }
                            else
                            {
                                IsValid = false;
                            }
                        }
                        else if ( StructureTypeType == StructureTypeBase.enumStructureType.ResourceExtractor )
                        {
                            IsValid = true;
                        }
                        else
                        {
                            IsValid = false;
                        }
                        if ( !IsValid )
                        {
                            var resultItem = modResults.CreateResultProblemGotoForObject(unit);
                            resultItem.Text = "Bad module on tile " + Convert.ToString(CentrePos.X) + ", " + Convert.ToString(CentrePos.Y) + ".";
                            Result.ItemAdd(resultItem);
                        }
                    }
                }
            }

            return Result;
        }
Esempio n. 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;
        }
Esempio n. 3
0
        private clsResult ValidateMap_Multiplayer(int PlayerCount)
        {
            var Result = new clsResult("Validate for multiplayer", false);
            logger.Info("Validate for multiplayer");

            if ( PlayerCount < 2 | PlayerCount > Constants.PlayerCountMax )
            {
                Result.ProblemAdd("Unable to evaluate for multiplayer due to bad number of players.");
                return Result;
            }

            //check HQs, Trucks and unit counts

            var PlayerHQCount = new int[Constants.PlayerCountMax];
            var Player23TruckCount = new int[Constants.PlayerCountMax];
            var PlayerMasterTruckCount = new int[Constants.PlayerCountMax];
            var ScavPlayerNum = 0;
            var ScavObjectCount = 0;
            var DroidType = default(DroidDesign);
            StructureTypeBase structureTypeBase;
            var UnusedPlayerUnitWarningCount = 0;
            var Unit = default(clsUnit);

            ScavPlayerNum = Math.Max(PlayerCount, 7);

            foreach ( var tempLoopVar_Unit in Map.Units )
            {
                Unit = tempLoopVar_Unit;
                if ( Unit.UnitGroup == Map.ScavengerUnitGroup )
                {
                }
                else
                {
                    if ( Unit.TypeBase.Type == UnitType.PlayerDroid )
                    {
                        DroidType = (DroidDesign)Unit.TypeBase;
                        if ( DroidType.Body != null && DroidType.Propulsion != null && DroidType.Turret1 != null && DroidType.TurretCount == 1 )
                        {
                            if ( DroidType.Turret1.TurretType == enumTurretType.Construct )
                            {
                                PlayerMasterTruckCount[Unit.UnitGroup.WZ_StartPos]++;
                                if ( DroidType.IsTemplate )
                                {
                                    Player23TruckCount[Unit.UnitGroup.WZ_StartPos]++;
                                }
                            }
                        }
                    }
                    else if ( Unit.TypeBase.Type == UnitType.PlayerStructure )
                    {
                        structureTypeBase = (StructureTypeBase)Unit.TypeBase;
                        if ( structureTypeBase.Code == "A0CommandCentre" )
                        {
                            PlayerHQCount[Unit.UnitGroup.WZ_StartPos]++;
                        }
                    }
                }
                if ( Unit.TypeBase.Type != UnitType.Feature )
                {
                    if ( Unit.UnitGroup.WZ_StartPos == ScavPlayerNum || Unit.UnitGroup == Map.ScavengerUnitGroup )
                    {
                        ScavObjectCount++;
                    }
                    else if ( Unit.UnitGroup.WZ_StartPos >= PlayerCount )
                    {
                        if ( UnusedPlayerUnitWarningCount < 32 )
                        {
                            UnusedPlayerUnitWarningCount++;
                            var resultItem = modResults.CreateResultProblemGotoForObject(Unit);
                            resultItem.Text = string.Format("An unused player ({0}) has a unit at {1}.", Unit.UnitGroup.WZ_StartPos, Unit.GetPosText());
                            Result.ItemAdd(resultItem);
                        }
                    }
                }
            }

            for ( var A = 0; A <= PlayerCount - 1; A++ )
            {
                if ( PlayerHQCount[A] == 0 )
                {
                    Result.ProblemAdd("There is no Command Centre for player " + Convert.ToString(A) + ".");
                }
                if ( PlayerMasterTruckCount[A] == 0 )
                {
                    Result.ProblemAdd("There are no constructor units for player " + Convert.ToString(A) + ".");
                }
                else if ( Player23TruckCount[A] == 0 )
                {
                    Result.WarningAdd("All constructor units for player " + Convert.ToString(A) + " will only exist in master.");
                }
            }

            return Result;
        }
Esempio n. 4
0
        private clsResult ValidateMap_Multiplayer(int PlayerCount, bool IsXPlayerFormat)
        {
            clsResult Result = new clsResult("Validate for multiplayer");

            if ( PlayerCount < 2 | PlayerCount > Constants.PlayerCountMax )
            {
                Result.ProblemAdd("Unable to evaluate for multiplayer due to bad number of players.");
                return Result;
            }

            //check HQs, Trucks and unit counts

            int[] PlayerHQCount = new int[Constants.PlayerCountMax];
            int[] Player23TruckCount = new int[Constants.PlayerCountMax];
            int[] PlayerMasterTruckCount = new int[Constants.PlayerCountMax];
            int ScavPlayerNum = 0;
            int ScavObjectCount = 0;
            clsDroidDesign DroidType = default(clsDroidDesign);
            clsStructureType StructureType;
            int UnusedPlayerUnitWarningCount = 0;
            clsMap.clsUnit Unit = default(clsMap.clsUnit);

            ScavPlayerNum = Math.Max(PlayerCount, 7);

            foreach ( clsMap.clsUnit tempLoopVar_Unit in Map.Units )
            {
                Unit = tempLoopVar_Unit;
                if ( Unit.UnitGroup == Map.ScavengerUnitGroup )
                {
                }
                else
                {
                    if ( Unit.Type.Type == clsUnitType.enumType.PlayerDroid )
                    {
                        DroidType = (clsDroidDesign)Unit.Type;
                        if ( DroidType.Body != null && DroidType.Propulsion != null && DroidType.Turret1 != null && DroidType.TurretCount == 1 )
                        {
                            if ( DroidType.Turret1.TurretType == clsTurret.enumTurretType.Construct )
                            {
                                PlayerMasterTruckCount[Unit.UnitGroup.WZ_StartPos]++;
                                if ( DroidType.IsTemplate )
                                {
                                    Player23TruckCount[Unit.UnitGroup.WZ_StartPos]++;
                                }
                            }
                        }
                    }
                    else if ( Unit.Type.Type == clsUnitType.enumType.PlayerStructure )
                    {
                        StructureType = (clsStructureType)Unit.Type;
                        if ( StructureType.Code == "A0CommandCentre" )
                        {
                            PlayerHQCount[Unit.UnitGroup.WZ_StartPos]++;
                        }
                    }
                }
                if ( Unit.Type.Type != clsUnitType.enumType.Feature )
                {
                    if ( Unit.UnitGroup.WZ_StartPos == ScavPlayerNum || Unit.UnitGroup == Map.ScavengerUnitGroup )
                    {
                        ScavObjectCount++;
                    }
                    else if ( Unit.UnitGroup.WZ_StartPos >= PlayerCount )
                    {
                        if ( UnusedPlayerUnitWarningCount < 32 )
                        {
                            UnusedPlayerUnitWarningCount++;
                            clsResultProblemGoto<clsResultItemPosGoto> resultItem = modResults.CreateResultProblemGotoForObject(Unit);
                            resultItem.Text = "An unused player (" + Convert.ToString(Unit.UnitGroup.WZ_StartPos) + ") has a unit at " + Unit.GetPosText() + ".";
                            Result.ItemAdd(resultItem);
                        }
                    }
                }
            }

            if ( ScavPlayerNum <= 7 || IsXPlayerFormat )
            {
            }
            else if ( ScavObjectCount > 0 ) //only counts non-features
            {
                Result.ProblemAdd("Scavengers are not supported on a map with this number of players without enabling X player support.");
            }

            for ( int A = 0; A <= PlayerCount - 1; A++ )
            {
                if ( PlayerHQCount[A] == 0 )
                {
                    Result.ProblemAdd("There is no Command Centre for player " + Convert.ToString(A) + ".");
                }
                if ( PlayerMasterTruckCount[A] == 0 )
                {
                    Result.ProblemAdd("There are no constructor units for player " + Convert.ToString(A) + ".");
                }
                else if ( Player23TruckCount[A] == 0 )
                {
                    Result.WarningAdd("All constructor units for player " + Convert.ToString(A) + " will only exist in master.");
                }
            }

            return Result;
        }