public void MapInsert(clsMap MapToInsert, XYInt Offset, XYInt Area, bool InsertHeights, bool InsertTextures, bool InsertUnits, bool DeleteUnits, bool InsertGateways, bool DeleteGateways) { var Finish = new XYInt(); var X = 0; var Y = 0; var SectorStart = new XYInt(); var SectorFinish = new XYInt(); var AreaAdjusted = new XYInt(); var SectorNum = new XYInt(); Finish.X = Math.Min(Offset.X + Math.Min(Area.X, MapToInsert.Terrain.TileSize.X), Terrain.TileSize.X); Finish.Y = Math.Min(Offset.Y + Math.Min(Area.Y, MapToInsert.Terrain.TileSize.Y), Terrain.TileSize.Y); AreaAdjusted.X = Finish.X - Offset.X; AreaAdjusted.Y = Finish.Y - Offset.Y; GetTileSectorRange(new XYInt(Offset.X - 1, Offset.Y - 1), Finish, ref SectorStart, ref SectorFinish); for ( Y = SectorStart.Y; Y <= SectorFinish.Y; Y++ ) { SectorNum.Y = Y; for ( X = SectorStart.X; X <= SectorFinish.X; X++ ) { SectorNum.X = X; SectorGraphicsChanges.Changed(SectorNum); SectorUnitHeightsChanges.Changed(SectorNum); SectorTerrainUndoChanges.Changed(SectorNum); } } if ( InsertHeights ) { for ( Y = 0; Y <= AreaAdjusted.Y; Y++ ) { for ( X = 0; X <= AreaAdjusted.X; X++ ) { Terrain.Vertices[Offset.X + X, Offset.Y + Y].Height = MapToInsert.Terrain.Vertices[X, Y].Height; } } for ( Y = 0; Y <= AreaAdjusted.Y - 1; Y++ ) { for ( X = 0; X <= AreaAdjusted.X - 1; X++ ) { Terrain.Tiles[Offset.X + X, Offset.Y + Y].Tri = MapToInsert.Terrain.Tiles[X, Y].Tri; } } } if ( InsertTextures ) { for ( Y = 0; Y <= AreaAdjusted.Y; Y++ ) { for ( X = 0; X <= AreaAdjusted.X; X++ ) { Terrain.Vertices[Offset.X + X, Offset.Y + Y].Terrain = MapToInsert.Terrain.Vertices[X, Y].Terrain; } } var TriDirection = default(bool); for ( Y = 0; Y <= AreaAdjusted.Y - 1; Y++ ) { for ( X = 0; X <= AreaAdjusted.X - 1; X++ ) { TriDirection = Terrain.Tiles[Offset.X + X, Offset.Y + Y].Tri; Terrain.Tiles[Offset.X + X, Offset.Y + Y].Copy(MapToInsert.Terrain.Tiles[X, Y]); Terrain.Tiles[Offset.X + X, Offset.Y + Y].Tri = TriDirection; } } for ( Y = 0; Y <= AreaAdjusted.Y; Y++ ) { for ( X = 0; X <= AreaAdjusted.X - 1; X++ ) { Terrain.SideH[Offset.X + X, Offset.Y + Y].Road = MapToInsert.Terrain.SideH[X, Y].Road; } } for ( Y = 0; Y <= AreaAdjusted.Y - 1; Y++ ) { for ( X = 0; X <= AreaAdjusted.X; X++ ) { Terrain.SideV[Offset.X + X, Offset.Y + Y].Road = MapToInsert.Terrain.SideV[X, Y].Road; } } } var LastTile = new XYInt(); LastTile = Finish; LastTile.X--; LastTile.Y--; if ( DeleteGateways ) { var A = 0; A = 0; while ( A < Gateways.Count ) { if ( Gateways[A].PosA.IsInRange(Offset, LastTile) || Gateways[A].PosB.IsInRange(Offset, LastTile) ) { GatewayRemoveStoreChange(A); } else { A++; } } } if ( InsertGateways ) { var GateStart = new XYInt(); var GateFinish = new XYInt(); var Gateway = default(clsGateway); foreach ( var tempLoopVar_Gateway in MapToInsert.Gateways ) { Gateway = tempLoopVar_Gateway; GateStart.X = Offset.X + Gateway.PosA.X; GateStart.Y = Offset.Y + Gateway.PosA.Y; GateFinish.X = Offset.X + Gateway.PosB.X; GateFinish.Y = Offset.Y + Gateway.PosB.Y; if ( GateStart.IsInRange(Offset, LastTile) || GateFinish.IsInRange(Offset, LastTile) ) { GatewayCreateStoreChange(GateStart, GateFinish); } } } if ( DeleteUnits ) { var UnitsToDelete = new SimpleList<clsUnit>(); var Unit = default(clsUnit); for ( Y = SectorStart.Y; Y <= SectorFinish.Y; Y++ ) { for ( X = SectorStart.X; X <= SectorFinish.X; X++ ) { var Connection = default(clsUnitSectorConnection); foreach ( var tempLoopVar_Connection in Sectors[X, Y].Units ) { Connection = tempLoopVar_Connection; Unit = Connection.Unit; if ( App.PosIsWithinTileArea(Unit.Pos.Horizontal, Offset, Finish) ) { UnitsToDelete.Add(Unit); } } } } foreach ( var tempLoopVar_Unit in UnitsToDelete ) { Unit = tempLoopVar_Unit; if ( Unit.MapLink.IsConnected ) //units may be in the list multiple times and already be deleted { UnitRemoveStoreChange(Unit.MapLink.ArrayPosition); } } } if ( InsertUnits ) { var PosDif = new XYInt(); var NewUnit = default(clsUnit); var Unit = default(clsUnit); var ZeroPos = new XYInt(0, 0); var UnitAdd = new clsUnitAdd(); UnitAdd.Map = this; UnitAdd.StoreChange = true; PosDif.X = Offset.X * Constants.TerrainGridSpacing; PosDif.Y = Offset.Y * Constants.TerrainGridSpacing; foreach ( var tempLoopVar_Unit in MapToInsert.Units ) { Unit = tempLoopVar_Unit; if ( App.PosIsWithinTileArea(Unit.Pos.Horizontal, ZeroPos, AreaAdjusted) ) { NewUnit = new clsUnit(Unit, this); NewUnit.Pos.Horizontal.X += PosDif.X; NewUnit.Pos.Horizontal.Y += PosDif.Y; UnitAdd.NewUnit = NewUnit; UnitAdd.Label = Unit.Label; UnitAdd.Perform(); } } } SectorsUpdateGraphics(); SectorsUpdateUnitHeights(); MinimapMakeLater(); }
public void SetMap(clsMap NewMap) { var A = 0; if ( NewMap == null ) { for ( A = 0; A <= Constants.PlayerCountMax - 1; A++ ) { tsbNumber[A].Tag = null; } tsbNumber[ScavButtonNum].Tag = null; } else { for ( A = 0; A <= Constants.PlayerCountMax - 1; A++ ) { tsbNumber[A].Tag = NewMap.UnitGroups[A]; } tsbNumber[ScavButtonNum].Tag = NewMap.ScavengerUnitGroup; } SelectedChanged(); }
public clsMap(clsMap MapToCopy, XYInt Offset, XYInt Area) : this() { var EndX = 0; var EndY = 0; var X = 0; var Y = 0; Initialize(); //make some map data for selection EndX = Math.Min(MapToCopy.Terrain.TileSize.X - Offset.X, Area.X); EndY = Math.Min(MapToCopy.Terrain.TileSize.Y - Offset.Y, Area.Y); Terrain = new clsTerrain(Area); for ( Y = 0; Y <= Terrain.TileSize.Y - 1; Y++ ) { for ( X = 0; X <= Terrain.TileSize.X - 1; X++ ) { Terrain.Tiles[X, Y].Texture.TextureNum = -1; } } for ( Y = 0; Y <= EndY; Y++ ) { for ( X = 0; X <= EndX; X++ ) { Terrain.Vertices[X, Y].Height = MapToCopy.Terrain.Vertices[Offset.X + X, Offset.Y + Y].Height; Terrain.Vertices[X, Y].Terrain = MapToCopy.Terrain.Vertices[Offset.X + X, Offset.Y + Y].Terrain; } } for ( Y = 0; Y <= EndY - 1; Y++ ) { for ( X = 0; X <= EndX - 1; X++ ) { Terrain.Tiles[X, Y].Copy(MapToCopy.Terrain.Tiles[Offset.X + X, Offset.Y + Y]); } } for ( Y = 0; Y <= EndY; Y++ ) { for ( X = 0; X <= EndX - 1; X++ ) { Terrain.SideH[X, Y].Road = MapToCopy.Terrain.SideH[Offset.X + X, Offset.Y + Y].Road; } } for ( Y = 0; Y <= EndY - 1; Y++ ) { for ( X = 0; X <= EndX; X++ ) { Terrain.SideV[X, Y].Road = MapToCopy.Terrain.SideV[Offset.X + X, Offset.Y + Y].Road; } } SectorCount.X = (int)(Math.Ceiling(((double)Area.X / Constants.SectorTileSize))); SectorCount.Y = (int)(Math.Ceiling(((double)Area.Y / Constants.SectorTileSize))); Sectors = new clsSector[SectorCount.X, SectorCount.Y]; for ( Y = 0; Y <= SectorCount.Y - 1; Y++ ) { for ( X = 0; X <= SectorCount.X - 1; X++ ) { Sectors[X, Y] = new clsSector(new XYInt(X, Y)); } } var PosDif = new XYInt(); var NewUnitAdd = new clsUnitAdd(); NewUnitAdd.Map = this; var NewUnit = default(clsUnit); var Gateway = default(clsGateway); foreach ( var tempLoopVar_Gateway in MapToCopy.Gateways ) { Gateway = tempLoopVar_Gateway; GatewayCreate(new XYInt(Gateway.PosA.X - Offset.X, Gateway.PosA.Y - Offset.Y), new XYInt(Gateway.PosB.X - Offset.X, Gateway.PosB.Y - Offset.Y)); } PosDif.X = - Offset.X * Constants.TerrainGridSpacing; PosDif.Y = - Offset.Y * Constants.TerrainGridSpacing; var Unit = default(clsUnit); var NewPos = new XYInt(); foreach ( var tempLoopVar_Unit in MapToCopy.Units ) { Unit = tempLoopVar_Unit; NewPos = Unit.Pos.Horizontal + PosDif; if ( PosIsOnMap(NewPos) ) { NewUnit = new clsUnit(Unit, this); NewUnit.Pos.Horizontal = NewPos; NewUnitAdd.NewUnit = NewUnit; NewUnitAdd.Label = Unit.Label; NewUnitAdd.Perform(); } } }