本文整理汇总了C#中fCraft.Map.Save方法的典型用法代码示例。如果您正苦于以下问题:C# Map.Save方法的具体用法?C# Map.Save怎么用?C# Map.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fCraft.Map
的用法示例。
在下文中一共展示了Map.Save方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
public static Map Load( World world, string fileName ) {
world.log.Log( "Converting {0}...", LogType.SystemActivity, fileName );
byte[] temp = new byte[8];
Map map = new Map( world );
byte[] data;
int length;
try {
using( FileStream stream = File.OpenRead( fileName ) ) {
stream.Seek( -4, SeekOrigin.End );
stream.Read( temp, 0, sizeof( int ) );
stream.Seek( 0, SeekOrigin.Begin );
length = BitConverter.ToInt32( temp, 0 );
data = new byte[length];
using( GZipStream reader = new GZipStream( stream, CompressionMode.Decompress ) ) {
reader.Read( data, 0, length );
}
}
//if( data[0] == 0xBE && data[1] == 0xEE && data[2] == 0xEF ) {
for( int i = 0; i < length - 1; i++ ) {
if( data[i] == 0xAC && data[i + 1] == 0xED ) {
// bypassing the header crap
int pointer = i + 6;
Array.Copy( data, pointer, temp, 0, sizeof( short ) );
pointer += Server.htons( BitConverter.ToInt16( temp, 0 ) );
pointer += 13;
int headerEnd = 0;
// 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;
while( pointer < headerEnd ) {
if( data[pointer] == 'Z' ) offset++;
else if( data[pointer] == 'I' || data[pointer] == 'F' ) offset += 4;
else if( data[pointer] == 'J' ) offset += 8;
pointer += 1;
Array.Copy( data, pointer, temp, 0, sizeof( short ) );
short skip = Server.htons( BitConverter.ToInt16( temp, 0 ) );
pointer += 2;
// look for relevant variables
Array.Copy( data, headerEnd + offset - 4, temp, 0, sizeof( int ) );
if( MemCmp( data, pointer, "width" ) ) {
map.widthX = (ushort)Server.htons( BitConverter.ToInt32( temp, 0 ) );
} else if( MemCmp( data, pointer, "depth" ) ) {
map.height = (ushort)Server.htons( BitConverter.ToInt32( temp, 0 ) );
} else if( MemCmp( data, pointer, "height" ) ) {
map.widthY = (ushort)Server.htons( BitConverter.ToInt32( temp, 0 ) );
} else if( MemCmp( data, pointer, "xSpawn" ) ) {
map.spawn.x = (short)(Server.htons( BitConverter.ToInt32( temp, 0 ) )*32+16);
} else if( MemCmp( data, pointer, "ySpawn" ) ) {
map.spawn.h = (short)(Server.htons( BitConverter.ToInt32( temp, 0 ) ) * 32 + 16);
} else if( MemCmp( data, pointer, "zSpawn" ) ) {
map.spawn.y = (short)(Server.htons( BitConverter.ToInt32( temp, 0 ) ) * 32 + 16);
}
pointer += skip;
}
// 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 ) {
map.CopyBlocks( data, pointer );
if( !map.ValidateBlockTypes() ) {
throw new Exception( "Map validation failed: unknown block types found. Either parsing has done wrong, or this is an incompatible format." );
}
} else {
throw new Exception( "Could not locate block array." );
}
break;
}
//}
}
} catch( Exception ex ) {
world.log.Log( "Conversion failed: {0}", LogType.Error, ex.Message );
world.log.Log( ex.StackTrace, LogType.Debug );
return null;
}
map.Save();
world.log.Log( "Conversion completed succesfully succesful.", LogType.SystemActivity, fileName );
return map;
//.........这里部分代码省略.........
示例2: DoGenerate
internal static void DoGenerate( Map map, Player player, string mode, string filename, Random rand, bool hollow )
{
switch( mode ) {
case "flatgrass":
player.Message( "Generating flatgrass map..." );
GenerateFlatgrass( map, hollow );
if( map.Save( filename ) ) {
player.Message( "Map generation: Done." );
} else {
player.Message( Color.Red, "An error occured while generating the map." );
}
break;
case "lag":
player.Message( "Generating laggy map..." );
for( int x = 0; x < map.widthX; x+=2 ) {
for( int y = 0; y < map.widthY; y+=2 ) {
for( int h = 0; h < map.widthY; h+=2 ) {
map.SetBlock( x, y, h, Block.Lava );
}
}
}
if( map.Save( filename ) ) {
player.Message( "Map generation: Done." );
} else {
player.Message( Color.Red, "An error occured while generating the map." );
}
break;
case "empty":
player.Message( "Generating empty map..." );
map.MakeFloodBarrier();
if( map.Save( filename ) ) {
player.Message( "Map generation: Done." );
} else {
player.Message( Color.Red, "An error occured while generating the map." );
}
break;
case "hills":
player.Message( "Generating terrain..." );
Tasks.Add( MapGenerator.GenerationTask, new MapGenerator( rand, map, player, filename,
1, 1, 0.5, 0.5, 0, 0.5, hollow ), false );
break;
case "mountains":
player.Message( "Generating terrain..." );
Tasks.Add( MapGenerator.GenerationTask, new MapGenerator( rand, map, player, filename,
4, 1, 0.5, 0.5, 0.1, 0.5, hollow ), false );
break;
case "lake":
player.Message( "Generating terrain..." );
Tasks.Add( MapGenerator.GenerationTask, new MapGenerator( rand, map, player, filename,
1, 0.6, 0.9, 0.5, -0.35, 0.55, hollow ), false );
break;
case "island":
player.Message( "Generating terrain..." );
Tasks.Add( MapGenerator.GenerationTask, new MapGenerator( rand, map, player, filename,
1, 0.6, 1, 0.5, 0.3, 0.35, hollow ), false );
break;
default:
player.Message( "Unknown map generation mode: " + mode );
break;
}
}
示例3: LoadMap
public void LoadMap( string mapName ) {
try {
map = Map.Load( this, mapName );
} catch( Exception ex ) {
log.Log( "Could not open the specified file ({0}): {1}", LogType.Error, mapName, ex.Message );
}
// or generate a default one
if( map == null ) {
log.Log( "World.Init: Generating default flatgrass level.", LogType.SystemActivity );
map = new Map( this, 64, 64, 64 );
map.spawn.Set( map.widthX / 2 * 32 + 16, map.widthY / 2 * 32 + 16, map.height * 32, 0, 0 );
MapCommands.GenerateFlatgrass( map, false );
if( !map.Save() ) throw new Exception( "Could not save file." );
}
}