Esempio n. 1
0
 public sRGB_sng GetUnitGroupMinimapColour(clsUnitGroup ColourUnitGroup)
 {
     if ( ColourUnitGroup.WZ_StartPos < 0 )
     {
         return new sRGB_sng(1.0F, 1.0F, 1.0F);
     }
     return App.PlayerColour[ColourUnitGroup.WZ_StartPos].MinimapColour;
 }
Esempio n. 2
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. 3
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;
        }
Esempio n. 4
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;
        }
Esempio n. 5
0
        public void MakeDefaultUnitGroups()
        {
            var A = 0;
            var NewGroup = default(clsUnitGroup);

            UnitGroups.Clear();
            for ( A = 0; A <= Constants.PlayerCountMax - 1; A++ )
            {
                NewGroup = new clsUnitGroup();
                NewGroup.WZ_StartPos = A;
                NewGroup.MapLink.Connect(UnitGroups);
            }
            ScavengerUnitGroup = new clsUnitGroup();
            ScavengerUnitGroup.MapLink.Connect(UnitGroups);
            ScavengerUnitGroup.WZ_StartPos = -1;
        }