Esempio n. 1
0
        public clsMap.clsUnit PlaceUnitNear(clsUnitType Type, sXY_int Pos, clsMap.clsUnitGroup UnitGroup, int Clearance, int Rotation, int MaxDistFromPos)
        {
            PathfinderNode PosNode = default(PathfinderNode);
            clsNodeTag NodeTag = default(clsNodeTag);
            sXY_int FinalTilePos = new sXY_int();
            sXY_int TilePosA = new sXY_int();
            sXY_int TilePosB = new sXY_int();
            int X2 = 0;
            int Y2 = 0;
            int Remainder = 0;
            sXY_int Footprint = new sXY_int();

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

                    FinalTilePos.X = (int)(Conversion.Int(NodeTag.Pos.X / App.TerrainGridSpacing));
                    FinalTilePos.Y = Conversion.Int(NodeTag.Pos.Y / App.TerrainGridSpacing);
                    Footprint = Type.get_GetFootprintSelected(Rotation);
                    Remainder = Footprint.X % 2;
                    if ( Remainder > 0 )
                    {
                        NewUnit.Pos.Horizontal.X = NodeTag.Pos.X;
                    }
                    else
                    {
                        if ( VBMath.Rnd() >= 0.5F )
                        {
                            NewUnit.Pos.Horizontal.X = (int)(NodeTag.Pos.X - App.TerrainGridSpacing / 2.0D);
                        }
                        else
                        {
                            NewUnit.Pos.Horizontal.X = (int)(NodeTag.Pos.X + App.TerrainGridSpacing / 2.0D);
                        }
                    }
                    Remainder = Footprint.Y % 2;
                    if ( Remainder > 0 )
                    {
                        NewUnit.Pos.Horizontal.Y = NodeTag.Pos.Y;
                    }
                    else
                    {
                        if ( VBMath.Rnd() >= 0.5F )
                        {
                            NewUnit.Pos.Horizontal.Y = (int)(NodeTag.Pos.Y - App.TerrainGridSpacing / 2.0D);
                        }
                        else
                        {
                            NewUnit.Pos.Horizontal.Y = (int)(NodeTag.Pos.Y + App.TerrainGridSpacing / 2.0D);
                        }
                    }
                    TilePosA.X = (int)Conversion.Int(NewUnit.Pos.Horizontal.X / App.TerrainGridSpacing - Footprint.X / 2.0D + 0.5D);
                    TilePosA.Y = (int)Conversion.Int(NewUnit.Pos.Horizontal.Y / App.TerrainGridSpacing - Footprint.Y / 2.0D + 0.5D);
                    TilePosB.X = (int)(Conversion.Int(NewUnit.Pos.Horizontal.X / App.TerrainGridSpacing + Footprint.X / 2.0D - 0.5D));
                    TilePosB.Y = (int)(Conversion.Int(NewUnit.Pos.Horizontal.Y / App.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;
                }
                else
                {
                    return null;
                }
            }
            else
            {
                return null;
            }
        }
Esempio n. 2
0
 public sUnitChance(clsUnitType Type, UInt32 Chance)
 {
     this.Type = Type;
     this.Chance = Chance;
 }
Esempio n. 3
0
        public clsMap.clsUnit PlaceUnit(clsUnitType Type, App.sWorldPos Pos, clsMap.clsUnitGroup UnitGroup, int Rotation)
        {
            sXY_int TilePosA = new sXY_int();
            sXY_int TilePosB = new sXY_int();
            int X2 = 0;
            int Y2 = 0;
            sXY_int FinalTilePos = new sXY_int();
            sXY_int Footprint = new sXY_int();

            clsMap.clsUnitAdd NewUnitAdd = new clsMap.clsUnitAdd();
            NewUnitAdd.Map = Map;
            NewUnitAdd.StoreChange = true;
            clsMap.clsUnit NewUnit = new clsMap.clsUnit();
            NewUnitAdd.NewUnit = NewUnit;
            NewUnit.Type = Type;
            NewUnit.UnitGroup = UnitGroup;

            FinalTilePos.X = (int)(Conversion.Int(Pos.Horizontal.X / App.TerrainGridSpacing));
            FinalTilePos.Y = (int)(Conversion.Int(Pos.Horizontal.Y / App.TerrainGridSpacing));

            Footprint = Type.get_GetFootprintSelected(Rotation);

            NewUnit.Pos = Pos;
            TilePosA.X = (int)(Conversion.Int(NewUnit.Pos.Horizontal.X / App.TerrainGridSpacing - Footprint.X / 2.0D + 0.5D));
            TilePosA.Y = (int)(Conversion.Int(NewUnit.Pos.Horizontal.Y / App.TerrainGridSpacing - Footprint.Y / 2.0D + 0.5D));
            TilePosB.X = (int)Conversion.Int(NewUnit.Pos.Horizontal.X / App.TerrainGridSpacing + Footprint.X / 2.0D - 0.5D);
            TilePosB.Y = (int)Conversion.Int(NewUnit.Pos.Horizontal.Y / App.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. 4
0
 public clsUnitType FindOrCreateUnitType(string Code, clsUnitType.enumType Type, int WallType)
 {
     switch ( Type )
     {
         case clsUnitType.enumType.Feature:
             clsFeatureType FeatureType = default(clsFeatureType);
             foreach ( clsFeatureType tempLoopVar_FeatureType in FeatureTypes )
             {
                 FeatureType = tempLoopVar_FeatureType;
                 if ( FeatureType.Code == Code )
                 {
                     return FeatureType;
                 }
             }
             FeatureType = new clsFeatureType();
             FeatureType.IsUnknown = true;
             FeatureType.Code = Code;
             FeatureType.Footprint.X = 1;
             FeatureType.Footprint.Y = 1;
             return FeatureType;
         case clsUnitType.enumType.PlayerStructure:
             clsStructureType StructureType = default(clsStructureType);
             foreach ( clsStructureType tempLoopVar_StructureType in StructureTypes )
             {
                 StructureType = tempLoopVar_StructureType;
                 if ( StructureType.Code == Code )
                 {
                     if ( WallType < 0 )
                     {
                         return StructureType;
                     }
                     else if ( StructureType.WallLink.IsConnected )
                     {
                         if ( StructureType.WallLink.ArrayPosition == WallType )
                         {
                             return StructureType;
                         }
                     }
                 }
             }
             StructureType = new clsStructureType();
             StructureType.IsUnknown = true;
             StructureType.Code = Code;
             StructureType.Footprint.X = 1;
             StructureType.Footprint.Y = 1;
             return StructureType;
         case clsUnitType.enumType.PlayerDroid:
             clsDroidTemplate DroidType = default(clsDroidTemplate);
             foreach ( clsDroidTemplate tempLoopVar_DroidType in DroidTemplates )
             {
                 DroidType = tempLoopVar_DroidType;
                 if ( DroidType.IsTemplate )
                 {
                     if ( DroidType.Code == Code )
                     {
                         return DroidType;
                     }
                 }
             }
             DroidType = new clsDroidTemplate();
             DroidType.IsUnknown = true;
             DroidType.Code = Code;
             return DroidType;
         default:
             return null;
     }
 }