public void LoadMap() { lock( WorldLock ) { if( Map != null ) return; try { Map = MapUtility.Load( GetMapName() ); } catch( Exception ex ) { Logger.Log( "World.LoadMap: Failed to load map ({0}): {1}", LogType.Error, GetMapName(), ex ); } // or generate a default one if( Map != null ) { Map.World = this; } else { Logger.Log( "World.LoadMap: Generating default flatgrass level.", LogType.SystemActivity ); Map = new Map( this, 64, 64, 64, true ); MapGenerator.GenerateFlatgrass( Map ); Map.ResetSpawn(); } StartTasks(); if( OnLoaded != null ) OnLoaded(); } }
public static Map GenerateFlatgrass( int width, int length, int height ) { Map map = new Map( null, width, length, height, true ); map.Blocks.MemSet( (byte)Block.Stone, 0, width * length * (height / 2 - FlatgrassDirtLevel) ); map.Blocks.MemSet( (byte)Block.Dirt, width * length * (height / 2 - FlatgrassDirtLevel), width * length * (FlatgrassDirtLevel - 1) ); map.Blocks.MemSet( (byte)Block.Grass, width * length * (height / 2 - 1), width * length ); return map; }
internal void WriteLevelEnd( Map map ) { if( map == null ) throw new ArgumentNullException( "map" ); Write( OpCode.MapEnd ); Write( (short)map.WidthX ); Write( (short)map.Height ); Write( (short)map.WidthY ); }
public void Deserialize( string group, string key, string value, Map map ) { try { WorldVariableLoader data = World.Deserialize( key, value, map ); data.LoadWorldVariables( map.World ); } catch ( Exception ex ) { Logger.Log( LogType.Error, "WorldV.Deserialize: Error deserializing key {0}: {1}", key, ex ); } }
public int Serialize( Map map, Stream stream, IMapConverterEx converter ) { BinaryWriter writer = new BinaryWriter( stream ); int count = 0; foreach ( World world in WorldManager.Worlds ) { converter.WriteMetadataEntry( _group[0], world.Name, world.Serialize(), writer ); ++count; } return count; }
public MapGenerator( Random _rand, Map _map, Player _player, string _filename, double _roughness, double _smoothingOver, double _smoothingUnder, double _water, double _midpoint, double _sides, bool _hollow ) { rand = _rand; map = _map; player = _player; filename = _filename; roughness = _roughness; smoothingOver = _smoothingOver; smoothingUnder = _smoothingUnder; midpoint = _midpoint; sides = _sides; water = _water; hollow = _hollow; }
public int Serialize( Map map, Stream stream, IMapConverterEx converter ) { BinaryWriter writer = new BinaryWriter( stream ); int count = 0; if ( map.MessageBlocks != null ) { if ( map.MessageBlocks.Count >= 1 ) { foreach ( MessageBlock MessageBlock in map.MessageBlocks ) { converter.WriteMetadataEntry( _group[0], MessageBlock.Name, MessageBlock.Serialize(), writer ); ++count; } } } return count; }
public void Deserialize( string group, string key, string value, Map map ) { try { MessageBlock MessageBlock = MessageBlock.Deserialize( key, value, map ); if ( map.MessageBlocks == null ) map.MessageBlocks = new ArrayList(); if ( map.MessageBlocks.Count >= 1 ) { if ( map.MessageBlocks.Contains( key ) ) { Logger.Log( LogType.Error, "Map loading warning: duplicate MessageBlock name found: " + key + ", ignored" ); return; } } map.MessageBlocks.Add( MessageBlock ); } catch ( Exception ex ) { Logger.Log( LogType.Error, "MessageBlock.Deserialize: Error deserializing MessageBlock {0}: {1}", key, ex ); } }
public void Deserialize(string group, string key, string value, Map map) { try { Life2DZone life = Life2DZone.Deserialize(key, value, map); if (map.LifeZones.ContainsKey(key.ToLower())) { Logger.Log(LogType.Error, "Map loading warning: duplicate life name found: " + key+", ignored"); return; } map.LifeZones.Add(key.ToLower(), life); } catch (Exception ex) { Logger.Log(LogType.Error, "LifeSerialization.Deserialize: Error deserializing life {0}: {1}", key, ex); } }
public int Serialize(Map map, Stream stream, IMapConverterEx converter) { BinaryWriter writer = new BinaryWriter(stream); int count = 0; World w = map.World; Object lockObj = null == w ? new object() : w.SyncRoot; IEnumerable<Life2DZone> lifes; lock (lockObj) { lifes = map.LifeZones.Values.ToList(); //copies the current life list under a lock } foreach (Life2DZone life in lifes) { converter.WriteMetadataEntry(_group[0], life.Name, life.Serialize(), writer); ++count; } return count; }
static void AddSingleVein(Random rand, Map map, byte bedrockType, byte fillingType, int k, double maxDiameter, int l) { AddSingleVein(rand, map, bedrockType, fillingType, k, maxDiameter, l, 10); }
void UpdateTask( SchedulerTask task ) { Map tempMap = Map; if( tempMap != null ) { tempMap.ProcessUpdates(); } }
public static void removal(ConcurrentDictionary<String, Vector3I> bullets, Map map) { foreach (Vector3I bp in bullets.Values) { map.QueueUpdate(new BlockUpdate(null, (short)bp.X, (short)bp.Y, (short)bp.Z, Block.Air)); Vector3I removed; bullets.TryRemove(bp.ToString(), out removed); } }
//stolen from BuildingCommands #region DrawOneBlock static void DrawOneBlock ( Player player, Map map, Block drawBlock, Vector3I coord, BlockChangeContext context, ref int blocks, ref int blocksDenied, fCraft.Drawing.UndoState undoState ) { if ( map == null ) return; if ( player == null ) throw new ArgumentNullException( "player" ); if ( !map.InBounds( coord ) ) return; Block block = map.GetBlock( coord ); if ( block == drawBlock ) return; if ( player.CanPlace( map, coord, drawBlock, context ) != CanPlaceResult.Allowed ) { blocksDenied++; return; } map.QueueUpdate( new BlockUpdate( null, coord, drawBlock ) ); Player.RaisePlayerPlacedBlockEvent( player, map, coord, block, drawBlock, context ); if ( !undoState.IsTooLargeToUndo ) { if ( !undoState.Add( coord, block ) ) { player.Message( "NOTE: This draw command is too massive to undo." ); player.LastDrawOp = null; } } blocks++; }
public ReturnNewestProcessor( Map map, int max, Func<BlockDBEntry, bool> selector ) { this.max = max; this.selector = selector; this.map = map; }
public static World AddWorld( string name, Map map, bool neverUnload ) { lock( worldListLock ) { if( worlds.ContainsKey( name ) ) return null; if( !Player.IsValidName( name ) ) return null; World newWorld = new World( name ); newWorld.neverUnload = neverUnload; if( map != null ) { // if a map is given newWorld.map = map; if( !neverUnload ) { newWorld.UnloadMap();// UnloadMap also saves the map } else { newWorld.SaveMap( null ); } } else { // generate default map if( neverUnload ) newWorld.LoadMap(); } worlds.Add( name, newWorld ); newWorld.updateTaskId = AddTask( UpdateBlocks, Config.GetInt( ConfigKey.TickInterval ), newWorld ); if( Config.GetInt( ConfigKey.SaveInterval ) > 0 ) { int saveInterval = Config.GetInt( ConfigKey.SaveInterval ) * 1000; newWorld.saveTaskId = AddTask( SaveMap, saveInterval, newWorld, saveInterval ); } if( Config.GetInt( ConfigKey.BackupInterval ) > 0 ) { int backupInterval = Config.GetInt( ConfigKey.BackupInterval ) * 1000 * 60; newWorld.backupTaskId = AddTask( AutoBackup, backupInterval, newWorld, (Config.GetBool( ConfigKey.BackupOnStartup ) ? 0 : backupInterval) ); } newWorld.UpdatePlayerList(); return newWorld; } }
public override Map Generate() { if( Finished ) return Result; try { StatusString = "Generating"; FlatMapGenParameters p = (FlatMapGenParameters)Parameters; int layer = Parameters.MapWidth*Parameters.MapLength; Map map = new Map( null, Parameters.MapWidth, Parameters.MapLength, Parameters.MapHeight, true ); int offset = 0; if( p.BedrockThickness > 0 ) { int bedrockBlocks = layer*p.BedrockThickness; map.Blocks.MemSet( (byte)p.BedrockBlock, 0, bedrockBlocks ); offset += bedrockBlocks; } int rockBlocks = layer*(Parameters.MapHeight/2 + p.GroundLevelOffset - p.BedrockThickness - p.SoilThickness - p.SurfaceThickness); map.Blocks.MemSet( (byte)p.DeepBlock, offset, rockBlocks ); offset += rockBlocks; if( p.SoilThickness > 0 ) { int soilBlocks = layer*p.SoilThickness; map.Blocks.MemSet( (byte)p.ShallowBlock, offset, soilBlocks ); offset += soilBlocks; } if( p.SurfaceThickness > 0 ) { int surfaceBlocks = layer*p.SurfaceThickness; map.Blocks.MemSet( (byte)p.SurfaceBlock, offset, surfaceBlocks ); offset += surfaceBlocks; } if( p.AirBlock != Block.Air ) { map.Blocks.MemSet( (byte)p.AirBlock, offset, map.Blocks.Length - offset ); } Result = map; StatusString = "Done"; return map; } finally { Finished = true; } }
static void AddSingleVein(Random rand, Map map, byte bedrockType, byte fillingType, int k, double maxDiameter, int l, int i1) { int j1 = rand.Next(0, map.Width); int k1 = rand.Next(0, map.Height); int l1 = rand.Next(0, map.Length); double thirteenOverK = 1 / (double)k; for (int i2 = 0; i2 < i1; i2++) { int j2 = j1 + (int)(.5 * (rand.NextDouble() - .5) * map.Width); int k2 = k1 + (int)(.5 * (rand.NextDouble() - .5) * map.Height); int l2 = l1 + (int)(.5 * (rand.NextDouble() - .5) * map.Length); for (int l3 = 0; l3 < k; l3++) { int diameter = (int)(maxDiameter * rand.NextDouble() * map.Width); if (diameter < 1) diameter = 2; int radius = diameter / 2; if (radius == 0) radius = 1; int i3 = (int)((1 - thirteenOverK) * j1 + thirteenOverK * j2 + (l * radius) * (rand.NextDouble() - .5)); int j3 = (int)((1 - thirteenOverK) * k1 + thirteenOverK * k2 + (l * radius) * (rand.NextDouble() - .5)); int k3 = (int)((1 - thirteenOverK) * l1 + thirteenOverK * l2 + (l * radius) * (rand.NextDouble() - .5)); for (int k4 = 0; k4 < diameter; k4++) { for (int l4 = 0; l4 < diameter; l4++) { for (int i5 = 0; i5 < diameter; i5++) { if ((k4 - radius) * (k4 - radius) + (l4 - radius) * (l4 - radius) + (i5 - radius) * (i5 - radius) < radius * radius && i3 + k4 < map.Width && j3 + l4 < map.Height && k3 + i5 < map.Length && i3 + k4 >= 0 && j3 + l4 >= 0 && k3 + i5 >= 0) { int index = i3 + k4 + map.Width * map.Length * (map.Height - 1 - (j3 + l4)) + map.Width * (k3 + i5); if (map.Blocks[index] == bedrockType) { map.Blocks[index] = fillingType; } } } } } } j1 = j2; k1 = k2; l1 = l2; } }
static void SealLiquids(Map map, byte sealantType) { for (int x = 1; x < map.Width - 1; x++) { for (int z = 1; z < map.Height; z++) { for (int y = 1; y < map.Length - 1; y++) { int index = map.Index(x, y, z); if ((map.Blocks[index] == 10 || map.Blocks[index] == 11 || map.Blocks[index] == 8 || map.Blocks[index] == 9) && (map.GetBlock(x - 1, y, z) == Block.Air || map.GetBlock(x + 1, y, z) == Block.Air || map.GetBlock(x, y - 1, z) == Block.Air || map.GetBlock(x, y + 1, z) == Block.Air || map.GetBlock(x, y, z - 1) == Block.Air)) { map.Blocks[index] = sealantType; } } } } }
internal static void RaisePlayerPlacedBlockEvent( Player player, Map map, Vector3I coords, Block oldBlock, Block newBlock, BlockChangeContext context ) { var handler = PlacedBlock; if( handler != null ) { handler( null, new PlayerPlacedBlockEventArgs( player, map, coords, oldBlock, newBlock, context ) ); } }
public static void Start( Player player ) { Map map = MapGeneratorOld.GenerateEmpty( 64, 128, 16 ); map.Save( "maps/minefield.fcm" ); if ( _world != null ) { WorldManager.RemoveWorld( _world ); } WorldManager.AddWorld( Player.Console, "Minefield", map, true ); _map = map; _world = WorldManager.FindWorldExact( "Minefield" ); SetUpRed(); SetUpMiddleWater(); SetUpGreen(); SetUpMines(); _map.Spawn = new Position( _map.Width / 2, 5, _ground + 3 ).ToVector3I().ToPlayerCoords(); _world.LoadMap(); _world.gameMode = GameMode.MineField; _world.EnableTNTPhysics( Player.Console, false ); Server.Message( "{0}&S started a game of MineField on world Minefield!", player.ClassyName ); WorldManager.SaveWorldList(); Server.RequestGC(); }
void PlantGiantTrees() { if( genParams.GiantTreeDensity <= 0 ) return; Map outMap = new Map( null, map.Width, map.Length, map.Height, false ) { Blocks = (byte[])map.Blocks.Clone() }; int plantableBlocks = ComputeSurfaceCoverage( Block.Grass ); var foresterArgs = new ForesterArgs { Map = map, Rand = rand, TreeCount = (int)(plantableBlocks*genParams.GiantTreeDensity/BaseGiantTreeDensity), Operation = Forester.ForesterOperation.Add, PlantOn = Block.Grass }; foresterArgs.BlockPlacing += ( sender, e ) => outMap.SetBlock( e.Coordinate, e.Block ); Forester.Generate( foresterArgs ); map = outMap; }
public static MessageBlock Deserialize( string name, string sdata, Map map ) { byte[] bdata = Convert.FromBase64String( sdata ); MessageBlock MessageBlock = new MessageBlock(); DataContractSerializer serializer = new DataContractSerializer( typeof( SerializedData ) ); System.IO.MemoryStream s = new System.IO.MemoryStream( bdata ); SerializedData data = ( SerializedData )serializer.ReadObject( s ); data.UpdateMessageBlock( MessageBlock ); return MessageBlock; }
internal static Packet MakeLevelEnd( Map map ) { Packet packet = new Packet( 7 ); packet.data[0] = (byte)OutputCodes.LevelEnd; ToNetOrder( (short)map.widthX, packet.data, 1 ); ToNetOrder( (short)map.height, packet.data, 3 ); ToNetOrder( (short)map.widthY, packet.data, 5 ); return packet; }
public static Map GenerateOcean(int width, int length, int height) { Map map = new Map(null, width, length, height, true); map.Blocks.MemSet((byte)Block.Sand, 0, width * length); map.Blocks.MemSet((byte)Block.Water, width * length, width * length * (height / 2 - 1)); return map; }
public void AddCaves(Map map) { if (args.AddCaves) { ReportProgress(5, "Processing: Adding caves"); for (int i1 = 0; i1 < 36 * args.CaveDensity; i1++) AddSingleCave(rand, map, (byte)bBedrock, (byte)Block.Air, 30, 0.05 * args.CaveSize); for (int j1 = 0; j1 < 9 * args.CaveDensity; j1++) AddSingleVein(rand, map, (byte)bBedrock, (byte)Block.Air, 500, 0.015 * args.CaveSize, 1); for (int k1 = 0; k1 < 30 * args.CaveDensity; k1++) AddSingleVein(rand, map, (byte)bBedrock, (byte)Block.Air, 300, 0.03 * args.CaveSize, 1, 20); if (args.AddCaveLava) { for (int i = 0; i < 8 * args.CaveDensity; i++) { AddSingleCave(rand, map, (byte)bBedrock, (byte)Block.Lava, 30, 0.05 * args.CaveSize); } for (int j = 0; j < 3 * args.CaveDensity; j++) { AddSingleVein(rand, map, (byte)bBedrock, (byte)Block.Lava, 1000, 0.015 * args.CaveSize, 1); } } if (args.AddCaveWater) { for (int k = 0; k < 8 * args.CaveDensity; k++) { AddSingleCave(rand, map, (byte)bBedrock, (byte)Block.Water, 30, 0.05 * args.CaveSize); } for (int l = 0; l < 3 * args.CaveDensity; l++) { AddSingleVein(rand, map, (byte)bBedrock, (byte)Block.Water, 1000, 0.015 * args.CaveSize, 1); } } SealLiquids(map, (byte)bBedrock); } if (args.AddOre) { ReportProgress(3, "Processing: Adding ore"); for (int l1 = 0; l1 < 12 * args.CaveDensity; l1++) { AddSingleCave(rand, map, (byte)bBedrock, (byte)Block.Coal, 500, 0.03); } for (int i2 = 0; i2 < 32 * args.CaveDensity; i2++) { AddSingleVein(rand, map, (byte)bBedrock, (byte)Block.Coal, 200, 0.015, 1); AddSingleCave(rand, map, (byte)bBedrock, (byte)Block.IronOre, 500, 0.02); } for (int k2 = 0; k2 < 8 * args.CaveDensity; k2++) { AddSingleVein(rand, map, (byte)bBedrock, (byte)Block.IronOre, 200, 0.015, 1); AddSingleVein(rand, map, (byte)bBedrock, (byte)Block.GoldOre, 200, 0.0145, 1); } for (int l2 = 0; l2 < 20 * args.CaveDensity; l2++) { AddSingleCave(rand, map, (byte)bBedrock, (byte)Block.GoldOre, 400, 0.0175); } } }
public ExcludingReturnOldestProcessor( Map map, int max, Func<BlockDBEntry, bool> inclusionSelector, Func<BlockDBEntry, bool> exclusionSelector ) { this.max = max; this.inclusionSelector = inclusionSelector; this.exclusionSelector = exclusionSelector; this.map = map; }
public Map GenerateMap() { Map map = new Map(null, args.MapWidth, args.MapLength, args.MapHeight, true); // Match water coverage float desiredWaterLevel = .5f; if (args.MatchWaterCoverage) { ReportProgress(2, "Heightmap Processing: Matching water coverage"); desiredWaterLevel = Noise.FindThreshold(heightmap, args.WaterCoverage); } // Calculate above/below water multipliers float aboveWaterMultiplier = 0; if (desiredWaterLevel != 1) { aboveWaterMultiplier = (args.MaxHeight / (1 - desiredWaterLevel)); } // Apply power functions to above/below water parts of the heightmap if (args.BelowFuncExponent != 1 || args.AboveFuncExponent != 1) { ReportProgress(5, "Heightmap Processing: Adjusting slope"); for (int x = heightmap.GetLength(0) - 1; x >= 0; x--) { for (int y = heightmap.GetLength(1) - 1; y >= 0; y--) { if (heightmap[x, y] < desiredWaterLevel) { float normalizedDepth = 1 - heightmap[x, y] / desiredWaterLevel; heightmap[x, y] = desiredWaterLevel - (float)Math.Pow(normalizedDepth, args.BelowFuncExponent) * desiredWaterLevel; } else { float normalizedHeight = (heightmap[x, y] - desiredWaterLevel) / (1 - desiredWaterLevel); heightmap[x, y] = desiredWaterLevel + (float)Math.Pow(normalizedHeight, args.AboveFuncExponent) * (1 - desiredWaterLevel); } } } } // Calculate the slope if (args.CliffSmoothing) { ReportProgress(2, "Heightmap Processing: Smoothing"); slopemap = Noise.CalculateSlope(Noise.GaussianBlur5X5(heightmap)); } else { slopemap = Noise.CalculateSlope(heightmap); } float[,] altmap = null; if (args.MaxHeightVariation != 0 || args.MaxDepthVariation != 0) { ReportProgress(5, "Heightmap Processing: Randomizing"); altmap = new float[map.Width, map.Length]; int blendmapDetailSize = (int)Math.Log(Math.Max(args.MapWidth, args.MapLength), 2) - 2; new Noise(rand.Next(), NoiseInterpolationMode.Cosine).PerlinNoise(altmap, 3, blendmapDetailSize, 0.5f, 0, 0); Noise.Normalize(altmap, -1, 1); } int snowStartThreshold = args.SnowAltitude - args.SnowTransition; int snowThreshold = args.SnowAltitude; ReportProgress(10, "Filling"); for (int x = heightmap.GetLength(0) - 1; x >= 0; x--) { for (int y = heightmap.GetLength(1) - 1; y >= 0; y--) { int level; float slope; if (heightmap[x, y] < desiredWaterLevel) { float depth = args.MaxDepth; if (altmap != null) { depth += altmap[x, y] * args.MaxDepthVariation; } slope = slopemap[x, y] * depth; level = args.WaterLevel - (int)Math.Round(Math.Pow(1 - heightmap[x, y] / desiredWaterLevel, args.BelowFuncExponent) * depth); if (args.AddWater) { if (args.WaterLevel - level > 3) { map.SetBlock(x, y, args.WaterLevel, bDeepWaterSurface); } else { map.SetBlock(x, y, args.WaterLevel, bWaterSurface); } for (int i = args.WaterLevel; i > level; i--) { map.SetBlock(x, y, i, bWater); } for (int i = level; i >= 0; i--) { if (level - i < SeaFloorThickness) { map.SetBlock(x, y, i, bSeaFloor); } else { map.SetBlock(x, y, i, bBedrock); } } } else { if (blendmap != null && blendmap[x, y] > .25 && blendmap[x, y] < .75) { map.SetBlock(x, y, level, bCliff); } else { if (slope < args.CliffThreshold) { map.SetBlock(x, y, level, bGroundSurface); } else { map.SetBlock(x, y, level, bCliff); } } for (int i = level - 1; i >= 0; i--) { if (level - i < groundThickness) { if (blendmap != null && blendmap[x, y] > CliffsideBlockThreshold && blendmap[x, y] < (1 - CliffsideBlockThreshold)) { map.SetBlock(x, y, i, bCliff); } else { if (slope < args.CliffThreshold) { map.SetBlock(x, y, i, bGround); } else { map.SetBlock(x, y, i, bCliff); } } } else { map.SetBlock(x, y, i, bBedrock); } } } } else { float height; if (altmap != null) { height = args.MaxHeight + altmap[x, y] * args.MaxHeightVariation; } else { height = args.MaxHeight; } slope = slopemap[x, y] * height; if (height != 0) { level = args.WaterLevel + (int)Math.Round(Math.Pow(heightmap[x, y] - desiredWaterLevel, args.AboveFuncExponent) * aboveWaterMultiplier / args.MaxHeight * height); } else { level = args.WaterLevel; } bool snow = args.AddSnow && (level > snowThreshold || (level > snowStartThreshold && rand.NextDouble() < (level - snowStartThreshold) / (double)(snowThreshold - snowStartThreshold))); if (blendmap != null && blendmap[x, y] > .25 && blendmap[x, y] < .75) { map.SetBlock(x, y, level, bCliff); } else { if (slope < args.CliffThreshold) { map.SetBlock(x, y, level, (snow ? Block.White : bGroundSurface)); } else { map.SetBlock(x, y, level, bCliff); } } for (int i = level - 1; i >= 0; i--) { if (level - i < groundThickness) { if (blendmap != null && blendmap[x, y] > CliffsideBlockThreshold && blendmap[x, y] < (1 - CliffsideBlockThreshold)) { map.SetBlock(x, y, i, bCliff); } else { if (slope < args.CliffThreshold) { if (snow) { map.SetBlock(x, y, i, Block.White); } else { map.SetBlock(x, y, i, bGround); } } else { map.SetBlock(x, y, i, bCliff); } } } else { map.SetBlock(x, y, i, bBedrock); } } } } } if (args.AddCaves || args.AddOre) { AddCaves(map); } if (args.AddBeaches) { ReportProgress(5, "Processing: Adding beaches"); AddBeaches(map); } if (args.AddTrees) { ReportProgress(5, "Processing: Planting trees"); if (args.AddGiantTrees) { Map outMap = new Map(null, map.Width, map.Length, map.Height, false) { Blocks = (byte[])map.Blocks.Clone() }; var foresterArgs = new ForesterArgs { Map = map, Rand = rand, TreeCount = (int)(map.Width * map.Length * 4 / (1024f * (args.TreeSpacingMax + args.TreeSpacingMin) / 2)), Operation = Forester.ForesterOperation.Add, PlantOn = bGroundSurface }; foresterArgs.BlockPlacing += (sender, e) => outMap.SetBlock(e.Coordinate, e.Block); Forester.Generate(foresterArgs); map = outMap; } GenerateTrees(map); } ReportProgress(0, "Generation complete"); map.Metadata["_Origin", "GeneratorName"] = "fCraft"; map.Metadata["_Origin", "GeneratorVersion"] = Updater.LatestStable; map.Metadata["_Origin", "GeneratorParams"] = args.Serialize().ToString(SaveOptions.DisableFormatting); return map; }
public static bool CanPlacePortal(short x, short y, short z, Map map) { int Count = 0; for (short Z = z; Z < z + 2; Z++) { Block check = map.GetBlock(x, y, Z); if (check != Block.Air && check != Block.Water && check != Block.Lava) { Count++; } } if (Count == 2) { return true; } else { return false; } }
// Cave generation method from Omen 0.70, used with osici's permission static void AddSingleCave(Random rand, Map map, byte bedrockType, byte fillingType, int length, double maxDiameter) { int startX = rand.Next(0, map.Width); int startY = rand.Next(0, map.Length); int startZ = rand.Next(0, map.Height); int k1; for (k1 = 0; map.Blocks[startX + map.Width * map.Length * (map.Height - 1 - startZ) + map.Width * startY] != bedrockType && k1 < 10000; k1++) { startX = rand.Next(0, map.Width); startY = rand.Next(0, map.Length); startZ = rand.Next(0, map.Height); } if (k1 >= 10000) return; int x = startX; int y = startY; int z = startZ; for (int k2 = 0; k2 < length; k2++) { int diameter = (int)(maxDiameter * rand.NextDouble() * map.Width); if (diameter < 1) diameter = 2; int radius = diameter / 2; if (radius == 0) radius = 1; x += (int)(0.7 * (rand.NextDouble() - 0.5D) * diameter); y += (int)(0.7 * (rand.NextDouble() - 0.5D) * diameter); z += (int)(0.7 * (rand.NextDouble() - 0.5D) * diameter); for (int j3 = 0; j3 < diameter; j3++) { for (int k3 = 0; k3 < diameter; k3++) { for (int l3 = 0; l3 < diameter; l3++) { if ((j3 - radius) * (j3 - radius) + (k3 - radius) * (k3 - radius) + (l3 - radius) * (l3 - radius) >= radius * radius || x + j3 >= map.Width || z + k3 >= map.Height || y + l3 >= map.Length || x + j3 < 0 || z + k3 < 0 || y + l3 < 0) { continue; } int index = x + j3 + map.Width * map.Length * (map.Height - 1 - (z + k3)) + map.Width * (y + l3); if (map.Blocks[index] == bedrockType) { map.Blocks[index] = fillingType; } if ((fillingType == 10 || fillingType == 11 || fillingType == 8 || fillingType == 9) && z + k3 < startZ) { map.Blocks[index] = 0; } } } } } }
public DoorInfo(Zone zone, Block[] buffer, Map worldMap) { Zone = zone; Buffer = buffer; WorldMap = worldMap; }
public Map AcceptPlayer( [NotNull] Player player, bool announce ) { if( player == null ) throw new ArgumentNullException( "player" ); lock( SyncRoot ) { if( IsFull ) { if( player.Info.Rank.ReservedSlot ) { Player idlestPlayer = Players.Where( p => p.Info.Rank.IdleKickTimer != 0 ) .OrderBy( p => p.LastActiveTime ) .FirstOrDefault(); if( idlestPlayer != null ) { idlestPlayer.Kick( Player.Console, "Auto-kicked to make room (idle).", LeaveReason.IdleKick, false, false, false ); Server.Players .CanSee( player ) .Message( "&SPlayer {0}&S was auto-kicked to make room for {1}", idlestPlayer.ClassyName, player.ClassyName ); Server.Players .CantSee( player ) .Message( "{0}&S was kicked for being idle for {1} min", player.ClassyName, player.Info.Rank.IdleKickTimer ); } else { return null; } } else { return null; } } if( playerIndex.ContainsKey( player.Name.ToLower() ) ) { Logger.Log( LogType.Error, "This world already contains the player by name ({0}). " + "Some sort of state corruption must have occured.", player.Name ); playerIndex.Remove( player.Name.ToLower() ); } playerIndex.Add( player.Name.ToLower(), player ); // load the map, if it's not yet loaded IsPendingMapUnload = false; Map = LoadMap(); if( ConfigKey.BackupOnJoin.Enabled() && (Map.HasChangedSinceBackup || !ConfigKey.BackupOnlyWhenChanged.Enabled()) ) { string backupFileName = String.Format( JoinBackupFormat, Name, DateTime.Now, player.Name ); // localized Map.SaveBackup( MapFileName, Path.Combine( Paths.BackupPath, backupFileName ) ); } UpdatePlayerList(); if (!IsRealm && announce && ConfigKey.ShowJoinedWorldMessages.Enabled()) { Server.Players.CanSee(player) .Message("&SPlayer {0}&S joined world {1}", player.ClassyName, ClassyName); } //realm joining announcer if (IsRealm && announce && ConfigKey.ShowJoinedWorldMessages.Enabled()) { Server.Players.CanSee(player) .Message("&SPlayer {0}&S joined realm {1}", player.ClassyName, ClassyName); } if (IsRealm) { Logger.Log(LogType.ChangedWorld, "Player {0} joined realm {1}.", player.Name, Name); } if (!IsRealm) { Logger.Log(LogType.ChangedWorld, "Player {0} joined world {1}.", player.Name, Name); } if( IsLocked ) { player.Message( "&WThis map is currently locked (read-only)." ); } if( player.Info.IsHidden ) { player.Message( "&8Reminder: You are still hidden." ); } return Map; } }