NotchyMapGenerator( int mapWidth, int mapLength, int mapHeight )
 {
     this.mapWidth = mapWidth;
     this.mapLength = mapLength;
     this.mapHeight = mapHeight;
     random = new Random();
     waterLevel = mapHeight / 2;
     heightmap = new int[mapWidth * mapLength];
     map = new Map( mapWidth, mapLength, mapHeight );
     blocks = map.Blocks;
 }
Beispiel #2
0
 public static Map CreateFlatgrass( int width, int length, int height )
 {
     Map map = new Map( width, length, height );
     map.Blocks.MemSet( (byte)Block.Stone, 0, width*length*(height/2 - 5) );
     map.Blocks.MemSet( (byte)Block.Dirt, width*length*(height/2 - 5), width*length*4 );
     map.Blocks.MemSet( (byte)Block.Grass, width*length*(height/2 - 1), width*length );
     if( Config.Physics ) {
         map.EnablePhysics();
     }
     return map;
 }
Beispiel #3
0
 public PlantPhysics( [NotNull] Map map )
 {
     if( map == null ) throw new ArgumentNullException( "map" );
     this.map = map;
     random = new Random();
     traversePattern = Enumerable.Range( 0, TraverseStep ).ToArray();
     RandomizeTraversal();
     shadows = new short[map.Width,map.Length];
     for( int x = 0; x < map.Width; x++ ) {
         for( int y = 0; y < map.Length; y++ ) {
             UpdateShadow( x, y, map.Height - 1 );
         }
     }
 }
Beispiel #4
0
 public SandPhysics( [NotNull] Map map )
 {
     if( map == null ) throw new ArgumentNullException( "map" );
     this.map = map;
 }
Beispiel #5
0
        public static Map Load( [NotNull] string fileName )
        {
            if( fileName == null ) throw new ArgumentNullException( "fileName" );
            using( FileStream mapStream = File.OpenRead( fileName ) ) {
                byte[] temp = new byte[8];
                Map map = null;

                mapStream.Seek( -4, SeekOrigin.End );
                mapStream.Read( temp, 0, 4 );
                mapStream.Seek( 0, SeekOrigin.Begin );
                int uncompressedLength = BitConverter.ToInt32( temp, 0 );
                byte[] data = new byte[uncompressedLength];
                using( GZipStream reader = new GZipStream( mapStream, CompressionMode.Decompress, true ) ) {
                    reader.Read( data, 0, uncompressedLength );
                }

                for( int i = 0; i < uncompressedLength - 1; i++ ) {
                    if( data[i] != 0xAC || data[i + 1] != 0xED ) continue;

                    // bypassing the header crap
                    int pointer = i + 6;
                    Array.Copy( data, pointer, temp, 0, 2 );
                    pointer += IPAddress.HostToNetworkOrder( BitConverter.ToInt16( temp, 0 ) );
                    pointer += 13;

                    int headerEnd;
                    // find the end of serialization listing
                    for( headerEnd = pointer; headerEnd < data.Length - 1; headerEnd++ ) {
                        if( data[headerEnd] == 0x78 && data[headerEnd + 1] == 0x70 ) {
                            headerEnd += 2;
                            break;
                        }
                    }

                    // start parsing serialization listing
                    int offset = 0;
                    int width = 0, length = 0, height = 0;
                    Position spawn = new Position();
                    while( pointer < headerEnd ) {
                        switch( (char)data[pointer] ) {
                            case 'Z':
                                offset++;
                                break;
                            case 'F':
                            case 'I':
                                offset += 4;
                                break;
                            case 'J':
                                offset += 8;
                                break;
                        }

                        pointer += 1;
                        Array.Copy( data, pointer, temp, 0, 2 );
                        short skip = IPAddress.HostToNetworkOrder( BitConverter.ToInt16( temp, 0 ) );
                        pointer += 2;

                        // look for relevant variables
                        Array.Copy( data, headerEnd + offset - 4, temp, 0, 4 );
                        if( MemCmp( data, pointer, "width" ) ) {
                            width = (ushort)IPAddress.HostToNetworkOrder( BitConverter.ToInt32( temp, 0 ) );
                        } else if( MemCmp( data, pointer, "depth" ) ) {
                            height = (ushort)IPAddress.HostToNetworkOrder( BitConverter.ToInt32( temp, 0 ) );
                        } else if( MemCmp( data, pointer, "height" ) ) {
                            length = (ushort)IPAddress.HostToNetworkOrder( BitConverter.ToInt32( temp, 0 ) );
                        } else if( MemCmp( data, pointer, "xSpawn" ) ) {
                            spawn.X =
                                (short)(IPAddress.HostToNetworkOrder( BitConverter.ToInt32( temp, 0 ) )*32 + 16);
                        } else if( MemCmp( data, pointer, "ySpawn" ) ) {
                            spawn.Z =
                                (short)(IPAddress.HostToNetworkOrder( BitConverter.ToInt32( temp, 0 ) )*32 + 16);
                        } else if( MemCmp( data, pointer, "zSpawn" ) ) {
                            spawn.Y =
                                (short)(IPAddress.HostToNetworkOrder( BitConverter.ToInt32( temp, 0 ) )*32 + 16);
                        }

                        pointer += skip;
                    }

                    map = new Map( width, length, height ) { Spawn = spawn };

                    // find the start of the block array
                    bool foundBlockArray = false;
                    offset = Array.IndexOf<byte>( data, 0x00, headerEnd );
                    while( offset != -1 && offset < data.Length - 2 ) {
                        if( data[offset] == 0x00 && data[offset + 1] == 0x78 && data[offset + 2] == 0x70 ) {
                            foundBlockArray = true;
                            pointer = offset + 7;
                        }
                        offset = Array.IndexOf<byte>( data, 0x00, offset + 1 );
                    }

                    // copy the block array... or fail
                    if( !foundBlockArray ) {
                        throw new Exception( "DatMapConverter: Could not locate block array." );
                    }

                    Array.Copy( data, pointer, map.Blocks, 0, map.Blocks.Length );

                    // Map survivaltest/indev blocktypes to standard/presentation blocktypes
                    map.ConvertBlockTypes( Mapping );

                    if( Config.Physics ) map.EnablePhysics();
                    break;
                }
                if( map == null ) {
                    throw new Exception( "DatMapConverter: Error loading map." );
                }
                return map;
            }
        }
Beispiel #6
0
        public static Map Load( [NotNull] string fileName )
        {
            if( fileName == null ) throw new ArgumentNullException( "fileName" );
            using( FileStream mapStream = File.OpenRead( fileName ) ) {
                using( GZipStream gs = new GZipStream( mapStream, CompressionMode.Decompress ) ) {
                    BinaryReader bs = new BinaryReader( gs );

                    // Read in the magic number
                    if( bs.ReadUInt16() != 0x752 ) {
                        throw new Exception( "Could not load map (incorrect header)." );
                    }

                    // Read in the map dimensions
                    int width = bs.ReadInt16();
                    int length = bs.ReadInt16();
                    int height = bs.ReadInt16();

                    Map map = new Map( width, length, height );

                    // Read in the spawn location
                    map.Spawn = new Position {
                        X = (short)( bs.ReadInt16() * 32 + 16 ),
                        Z = (short)( bs.ReadInt16() * 32 + 16 ),
                        Y = (short)( bs.ReadInt16() * 32 + 16 ),
                        R = bs.ReadByte(),
                        L = bs.ReadByte(),
                    };

                    // Write the VisitPermission and BuildPermission bytes
                    ushort magic = bs.ReadUInt16();
                    bool isFemto = (magic == MagicNumber);

                    // Read map data
                    int bytesRead = 0;
                    int bytesLeft = map.Blocks.Length;
                    while( bytesLeft > 0 ) {
                        int readPass = bs.Read( map.Blocks, bytesRead, bytesLeft );
                        if( readPass == 0 ) throw new EndOfStreamException();
                        bytesRead += readPass;
                        bytesLeft -= readPass;
                    }

                    if( !isFemto ) {
                        // Map custom MCSharp+ blocktypes to standard/presentation blocktypes
                        map.ConvertBlockTypes( Mapping );
                    }

                    if( Config.Physics ) map.EnablePhysics();
                    return map;
                }
            }
        }
Beispiel #7
0
 public void ChangeMap( [NotNull] Map newMap )
 {
     if( newMap == null ) throw new ArgumentNullException( "newMap" );
     mapToJoin = newMap;
 }