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; } }
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; }