Beispiel #1
0
 public clsMap.clsUnit PlaceUnitNear(clsUnitType Type, modMath.sXY_int Pos, clsMap.clsUnitGroup UnitGroup, int Clearance, int Rotation, int MaxDistFromPos)
 {
     modMath.sXY_int _int;
     modMath.sXY_int _int3;
     modMath.sXY_int _int4;
     PathfinderNode node = this.GetNearestNodeConnection(this.TilePathMap, Pos, Clearance, (float) MaxDistFromPos);
     if (node == null)
     {
         return null;
     }
     clsNodeTag tag = (clsNodeTag) node.Tag;
     modMath.sXY_int _int5 = Pos - tag.Pos;
     if (_int5.ToDoubles().GetMagnitude() > MaxDistFromPos)
     {
         return null;
     }
     clsMap.clsUnitAdd add = new clsMap.clsUnitAdd {
         Map = this.Map,
         StoreChange = true
     };
     clsMap.clsUnit unit2 = new clsMap.clsUnit();
     add.NewUnit = unit2;
     unit2.Type = Type;
     unit2.UnitGroup = UnitGroup;
     _int.X = (int) Math.Round(((double) (((double) tag.Pos.X) / 128.0)));
     _int.Y = (int) Math.Round(((double) (((double) tag.Pos.Y) / 128.0)));
     modMath.sXY_int _int2 = Type.get_GetFootprintSelected(Rotation);
     int num = _int2.X % 2;
     if (num > 0)
     {
         unit2.Pos.Horizontal.X = tag.Pos.X;
     }
     else if (App.Random.Next() >= 0.5f)
     {
         unit2.Pos.Horizontal.X = tag.Pos.X - 0x40;
     }
     else
     {
         unit2.Pos.Horizontal.X = tag.Pos.X + 0x40;
     }
     num = _int2.Y % 2;
     if (num > 0)
     {
         unit2.Pos.Horizontal.Y = tag.Pos.Y;
     }
     else if (App.Random.Next() >= 0.5f)
     {
         unit2.Pos.Horizontal.Y = tag.Pos.Y - 0x40;
     }
     else
     {
         unit2.Pos.Horizontal.Y = tag.Pos.Y + 0x40;
     }
     _int3.X = (int) Math.Round(((double) (((((double) unit2.Pos.Horizontal.X) / 128.0) - (((double) _int2.X) / 2.0)) + 0.5)));
     _int3.Y = (int) Math.Round(((double) (((((double) unit2.Pos.Horizontal.Y) / 128.0) - (((double) _int2.Y) / 2.0)) + 0.5)));
     _int4.X = (int) Math.Round(((double) (((((double) unit2.Pos.Horizontal.X) / 128.0) + (((double) _int2.X) / 2.0)) - 0.5)));
     _int4.Y = (int) Math.Round(((double) (((((double) unit2.Pos.Horizontal.Y) / 128.0) + (((double) _int2.Y) / 2.0)) - 0.5)));
     unit2.Rotation = Rotation;
     add.Perform();
     int num4 = Math.Min(_int4.Y, this.Map.Terrain.TileSize.Y - 1);
     for (int i = Math.Max(_int3.Y, 0); i <= num4; i++)
     {
         int num5 = Math.Min(_int4.X, this.Map.Terrain.TileSize.X - 1);
         for (int j = Math.Max(_int3.X, 0); j <= num5; j++)
         {
             this.TileNodeBlock(j, i);
         }
     }
     this.TilePathMap.FindCalc();
     return unit2;
 }
Beispiel #2
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;
            }
        }
Beispiel #3
0
 public clsMap.clsUnit PlaceUnit(clsUnitType Type, modProgram.sWorldPos Pos, clsMap.clsUnitGroup UnitGroup, int Rotation)
 {
     modMath.sXY_int _int;
     modMath.sXY_int _int3;
     modMath.sXY_int _int4;
     clsMap.clsUnitAdd add = new clsMap.clsUnitAdd {
         Map = this.Map,
         StoreChange = true
     };
     clsMap.clsUnit unit = new clsMap.clsUnit();
     add.NewUnit = unit;
     unit.Type = Type;
     unit.UnitGroup = UnitGroup;
     _int.X = (int) Math.Round(((double) (((double) Pos.Horizontal.X) / 128.0)));
     _int.Y = (int) Math.Round(((double) (((double) Pos.Horizontal.Y) / 128.0)));
     modMath.sXY_int _int2 = Type.get_GetFootprintSelected(Rotation);
     unit.Pos = Pos;
     _int3.X = (int) Math.Round(((double) (((((double) unit.Pos.Horizontal.X) / 128.0) - (((double) _int2.X) / 2.0)) + 0.5)));
     _int3.Y = (int) Math.Round(((double) (((((double) unit.Pos.Horizontal.Y) / 128.0) - (((double) _int2.Y) / 2.0)) + 0.5)));
     _int4.X = (int) Math.Round(((double) (((((double) unit.Pos.Horizontal.X) / 128.0) + (((double) _int2.X) / 2.0)) - 0.5)));
     _int4.Y = (int) Math.Round(((double) (((((double) unit.Pos.Horizontal.Y) / 128.0) + (((double) _int2.Y) / 2.0)) - 0.5)));
     unit.Rotation = Rotation;
     add.Perform();
     int num3 = Math.Min(_int4.Y, this.Map.Terrain.TileSize.Y - 1);
     for (int i = Math.Max(_int3.Y, 0); i <= num3; i++)
     {
         int num4 = Math.Min(_int4.X, this.Map.Terrain.TileSize.X - 1);
         for (int j = Math.Max(_int3.X, 0); j <= num4; j++)
         {
             this.TileNodeBlock(j, i);
         }
     }
     this.TilePathMap.FindCalc();
     return unit;
 }
Beispiel #4
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;
        }