diff --git a/ConfigGUI/AddWorldPopup.cs b/ConfigGUI/AddWorldPopup.cs index e2cb806..f0cd27c 100644 --- a/ConfigGUI/AddWorldPopup.cs +++ b/ConfigGUI/AddWorldPopup.cs @@ -360,13 +360,13 @@ private void AsyncGen( object sender, DoWorkEventArgs e ) { GC.Collect( GC.MaxGeneration, GCCollectionMode.Forced ); Map generatedMap; if ( tab == Tabs.Generator ) { - MapGenerator gen = new MapGenerator( generatorArgs ); + MapGeneratorOld gen = new MapGeneratorOld( generatorArgs ); gen.ProgressChanged += ( progressSender, progressArgs ) => bwGenerator.ReportProgress( progressArgs.ProgressPercentage, progressArgs.UserState ); generatedMap = gen.Generate(); } else { - generatedMap = MapGenerator.GenerateFlatgrass( Convert.ToInt32( nFlatgrassDimX.Value ), + generatedMap = MapGeneratorOld.GenerateFlatgrass( Convert.ToInt32( nFlatgrassDimX.Value ), Convert.ToInt32( nFlatgrassDimY.Value ), Convert.ToInt32( nFlatgrassDimZ.Value ) ); } @@ -865,7 +865,7 @@ private void bSaveTemplate_Click( object sender, EventArgs e ) { } private void cTemplates_SelectedIndexChanged( object sender, EventArgs e ) { - generatorArgs = MapGenerator.MakeTemplate( ( MapGenTemplate )cTemplates.SelectedIndex ); + generatorArgs = MapGeneratorOld.MakeTemplate( ( MapGenTemplate )cTemplates.SelectedIndex ); LoadGeneratorArgs(); bGenerate.PerformClick(); } diff --git a/ConfigGUI/Properties/Resources.Designer.cs b/ConfigGUI/Properties/Resources.Designer.cs index 1b8e2fd..826ced2 100644 --- a/ConfigGUI/Properties/Resources.Designer.cs +++ b/ConfigGUI/Properties/Resources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.17379 +// Runtime Version:4.0.30319.18052 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -60,6 +60,9 @@ internal Resources() { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// internal static System.Drawing.Bitmap ChatBackground { get { object obj = ResourceManager.GetObject("ChatBackground", resourceCulture); @@ -67,6 +70,9 @@ internal static System.Drawing.Bitmap ChatBackground { } } + /// + /// Looks up a localized resource of type System.Byte[]. + /// internal static byte[] MinecraftFont { get { object obj = ResourceManager.GetObject("MinecraftFont", resourceCulture); diff --git a/fCraft/Commands/BuildingCommands.cs b/fCraft/Commands/BuildingCommands.cs index 3b41f71..3e74fe5 100644 --- a/fCraft/Commands/BuildingCommands.cs +++ b/fCraft/Commands/BuildingCommands.cs @@ -111,6 +111,9 @@ internal static void Init() { CommandManager.RegisterCommand( CdDraw2D ); CommandManager.RegisterCommand( CdSetFont ); CommandManager.RegisterCommand( CdDrawImage ); + + CommandManager.RegisterCommand( CdPlane ); + CommandManager.RegisterCommand( CdPlaneW ); } #endregion Init @@ -1103,6 +1106,34 @@ private static void TriangleHandler( Player player, Command cmd ) { DrawOperationBegin( player, cmd, new TriangleDrawOperation( player ) ); } + private static readonly CommandDescriptor CdPlane = new CommandDescriptor { + Name = "Plane", + Aliases = new[] { "Quad" }, + Category = CommandCategory.Building, + Permissions = new[] { Permission.Draw }, + RepeatableSelection = true, + Help = "Draws a plane between three points.", + Handler = PlaneHandler + }; + + private static void PlaneHandler( Player player, Command cmd ) { + DrawOperationBegin( player, cmd, new PlaneDrawOperation( player ) ); + } + + private static readonly CommandDescriptor CdPlaneW = new CommandDescriptor { + Name = "PlaneW", + Aliases = new[] { "QuadW" }, + Category = CommandCategory.Building, + Permissions = new[] { Permission.Draw }, + RepeatableSelection = true, + Help = "Draws a wireframe plane between four points.", + Handler = PlaneWHandler + }; + + private static void PlaneWHandler( Player player, Command cmd ) { + DrawOperationBegin( player, cmd, new PlaneWireframeDrawOperation( player ) ); + } + private static readonly CommandDescriptor CdTorus = new CommandDescriptor { Name = "Torus", Aliases = new[] { "donut", "bagel" }, diff --git a/fCraft/Commands/Command Handlers/FeedData.cs b/fCraft/Commands/Command Handlers/FeedData.cs index 8f5cdfa..9968ce3 100644 --- a/fCraft/Commands/Command Handlers/FeedData.cs +++ b/fCraft/Commands/Command Handlers/FeedData.cs @@ -140,7 +140,7 @@ public static void AddMessages() { Messages.Clear(); } Messages = new List(); - Messages.Add( "Server Time: " + DateTime.Now.ToString( "HH:mm:ss tt" ) ); + Messages.Add( "Server Time: " + DateTime.UtcNow.ToString( "HH:mm:ss tt" ) ); Messages.Add( "Welcome to " + ConfigKey.ServerName.GetString() ); Messages.Add( Server.Players.Where( p => !p.Info.IsHidden ).Count().ToString() + " players online" ); Messages.Add( "Staff online: " + Server.Players.Where( p => !p.Info.IsHidden && p.Can( per ) ).JoinToString( r => String.Format( "{0}", r.Name ) ) ); diff --git a/fCraft/Commands/Command Handlers/GunHandler.cs b/fCraft/Commands/Command Handlers/GunHandler.cs index 5087c57..981eb0c 100644 --- a/fCraft/Commands/Command Handlers/GunHandler.cs +++ b/fCraft/Commands/Command Handlers/GunHandler.cs @@ -255,7 +255,7 @@ public static void ClickedGlass( object sender, PlayerClickingEventArgs e ) { public static void movePortal( object sender, PlayerMovingEventArgs e ) { try { - if ( e.Player.LastUsedPortal != null && ( DateTime.Now - e.Player.LastUsedPortal ).TotalSeconds < 4 ) { + if ( e.Player.LastUsedPortal != null && ( DateTime.UtcNow - e.Player.LastUsedPortal ).TotalSeconds < 4 ) { return; } Vector3I newPos = new Vector3I( e.NewPosition.X / 32, e.NewPosition.Y / 32, ( e.NewPosition.Z / 32 ) ); @@ -272,7 +272,7 @@ public static void movePortal( object sender, PlayerMovingEventArgs e ) { L = e.Player.Position.L } ); } - e.Player.LastUsedPortal = DateTime.Now; + e.Player.LastUsedPortal = DateTime.UtcNow; } } } @@ -289,7 +289,7 @@ public static void movePortal( object sender, PlayerMovingEventArgs e ) { L = e.Player.Position.L } ); } - e.Player.LastUsedPortal = DateTime.Now; + e.Player.LastUsedPortal = DateTime.UtcNow; } } } diff --git a/fCraft/Commands/Command Handlers/RealmHandler.cs b/fCraft/Commands/Command Handlers/RealmHandler.cs index 4c6c507..12f352f 100644 --- a/fCraft/Commands/Command Handlers/RealmHandler.cs +++ b/fCraft/Commands/Command Handlers/RealmHandler.cs @@ -315,7 +315,7 @@ public static void RealmCreate( Player player, Command cmd, string themeName, st return; } - MapGeneratorArgs args = MapGenerator.MakeTemplate( template ); + MapGeneratorArgs args = MapGeneratorOld.MakeTemplate( template ); args.MapWidth = wx; args.MapLength = wy; args.MapHeight = height; @@ -332,9 +332,9 @@ public static void RealmCreate( Player player, Command cmd, string themeName, st player.MessageNow( "Generating {0} {1}...", theme, template ); } if ( theme == MapGenTheme.Forest && noTrees && template == MapGenTemplate.Flat ) { - map = MapGenerator.GenerateFlatgrass( args.MapWidth, args.MapLength, args.MapHeight ); + map = MapGeneratorOld.GenerateFlatgrass( args.MapWidth, args.MapLength, args.MapHeight ); } else { - MapGenerator generator = new MapGenerator( args ); + MapGeneratorOld generator = new MapGeneratorOld( args ); map = generator.Generate(); } } catch ( Exception ex ) { diff --git a/fCraft/Commands/System.Drawing/FontHandler.cs b/fCraft/Commands/System.Drawing/FontHandler.cs index cfb7204..ce9585c 100644 --- a/fCraft/Commands/System.Drawing/FontHandler.cs +++ b/fCraft/Commands/System.Drawing/FontHandler.cs @@ -81,8 +81,7 @@ public void Draw( Bitmap img ) { } //check if player can make the drawing if ( !player.CanDraw( Count ) ) { - player.MessageNow( String.Format( "You are only allowed to run commands that affect up to {0} blocks. This one would affect {1} blocks.", - player.Info.Rank.DrawLimit, Count ) ); + player.MessageNow( String.Format( "You are only allowed to run commands that affect up to {0} blocks. This one would affect {1} blocks.", player.Info.Rank.DrawLimit, Count ) ); return; } //check direction and draw diff --git a/fCraft/Commands/WorldCommands.cs b/fCraft/Commands/WorldCommands.cs index e27ffed..9207771 100644 --- a/fCraft/Commands/WorldCommands.cs +++ b/fCraft/Commands/WorldCommands.cs @@ -2041,7 +2041,7 @@ private static void TimeCheck( SchedulerTask task ) { int sky; int clouds; int fog; - DateTime now = DateTime.Now; + DateTime now = DateTime.UtcNow; var SunriseStart = new TimeSpan( 6, 30, 0 ); var SunriseEnd = new TimeSpan( 7, 29, 59 ); var MorningStart = new TimeSpan( 7, 30, 0 ); @@ -2350,13 +2350,13 @@ private static void GenHandler( Player player, Command cmd ) { player.MessageNow( "Generating {0}...", templateFullName ); if ( genEmpty ) { - map = MapGenerator.GenerateEmpty( mapWidth, mapLength, mapHeight ); + map = MapGeneratorOld.GenerateEmpty( mapWidth, mapLength, mapHeight ); } else if ( genOcean ) { - map = MapGenerator.GenerateOcean( mapWidth, mapLength, mapHeight ); + map = MapGeneratorOld.GenerateOcean( mapWidth, mapLength, mapHeight ); } else if ( genFlatgrass ) { - map = MapGenerator.GenerateFlatgrass( mapWidth, mapLength, mapHeight ); + map = MapGeneratorOld.GenerateFlatgrass( mapWidth, mapLength, mapHeight ); } else { - MapGeneratorArgs args = MapGenerator.MakeTemplate( template ); + MapGeneratorArgs args = MapGeneratorOld.MakeTemplate( template ); if ( theme == MapGenTheme.Desert ) { args.AddWater = false; } @@ -2370,7 +2370,7 @@ private static void GenHandler( Player player, Command cmd ) { args.Theme = theme; args.AddTrees = !noTrees; - MapGenerator generator = new MapGenerator( args ); + MapGeneratorOld generator = new MapGeneratorOld( args ); map = generator.Generate(); } diff --git a/fCraft/Drawing/DrawOps/PlaneDrawOperation.cs b/fCraft/Drawing/DrawOps/PlaneDrawOperation.cs new file mode 100644 index 0000000..1b385de --- /dev/null +++ b/fCraft/Drawing/DrawOps/PlaneDrawOperation.cs @@ -0,0 +1,121 @@ +// fCraft is Copyright 2009-2012 Matvei Stefarov +// TriangleDrawOperation contributed by Conrad "Redshift" Morgan +using System; + +namespace fCraft.Drawing { + + public sealed class PlaneDrawOperation : DrawOperation { + + public override string Name { + get { return "Plane"; } + } + + public override int ExpectedMarks { + get { return 3; } + } + + public PlaneDrawOperation( Player player ) + : base( player ) { + } + + // Plane vertices. + private Vector3I a, b, c, d; + + // Edge planes perpendicular to surface, pointing outwards. + private Vector3F s1, s2, s3, s4; + + private Vector3I normal; + private Vector3F normalF; + + public override bool Prepare( Vector3I[] marks ) { + a = marks[0]; + c = marks[1]; + b = marks[2]; + + d = new Vector3I( a.X + c.X - b.X, a.Y + c.Y - b.Y, a.Z + c.Z - b.Z ); + + Bounds = new BoundingBox( + Math.Min( Math.Min( a.X, b.X ), Math.Min( c.X, d.X ) ), + Math.Min( Math.Min( a.Y, b.Y ), Math.Min( c.Y, d.Y ) ), + Math.Min( Math.Min( a.Z, b.Z ), Math.Min( c.Z, d.Z ) ), + Math.Max( Math.Max( a.X, b.X ), Math.Max( c.X, d.X ) ), + Math.Max( Math.Max( a.Y, b.Y ), Math.Max( c.Y, d.Y ) ), + Math.Max( Math.Max( a.Z, b.Z ), Math.Max( c.Z, d.Z ) ) + ); + + Coords = Bounds.MinVertex; + + if ( !base.Prepare( marks ) ) + return false; + + normal = ( b - a ).Cross( c - a ); + normalF = normal.Normalize(); + BlocksTotalEstimate = GetBlockTotalEstimate(); + + s1 = normal.Cross( a - b ).Normalize(); + s2 = normal.Cross( b - c ).Normalize(); + s3 = normal.Cross( c - d ).Normalize(); + s4 = normal.Cross( d - a ).Normalize(); + + return true; + } + + private int GetBlockTotalEstimate() { + Vector3I nabs = normal.Abs(); + return Math.Max( Math.Max( nabs.X, nabs.Y ), nabs.Z ) / 2; + } + + public override int DrawBatch( int maxBlocksToDraw ) { + int blocksDone = 0; + for ( ; Coords.X <= Bounds.XMax; Coords.X++ ) { + for ( ; Coords.Y <= Bounds.YMax; Coords.Y++ ) { + for ( ; Coords.Z <= Bounds.ZMax; Coords.Z++ ) { + if ( IsPlaneBlock() && DrawOneBlock() ) { + blocksDone++; + if ( blocksDone >= maxBlocksToDraw ) + return blocksDone; + } + if ( TimeToEndBatch ) + return blocksDone; + } + Coords.Z = Bounds.ZMin; + } + Coords.Y = Bounds.YMin; + } + + IsDone = true; + return blocksDone; + } + + private const float Extra = 0.5f; + + private bool IsPlaneBlock() { + // Early out. + if ( Math.Abs( normalF.Dot( Coords - a ) ) > 1 ) + return false; + + // Check if within plane region. + if ( ( Coords - a ).Dot( s1 ) > Extra || + ( Coords - b ).Dot( s2 ) > Extra || + ( Coords - c ).Dot( s3 ) > Extra || + ( Coords - d ).Dot( s4 ) > Extra ) + return false; + + // Check if minimal plane block. + return TestAxis( 1, 0, 0 ) || + TestAxis( 0, 1, 0 ) || + TestAxis( 0, 0, 1 ); + } + + // Checks distance to plane along axis. + private bool TestAxis( int x, int y, int z ) { + Vector3I v = new Vector3I( x, y, z ); + int numerator = normal.Dot( a - Coords ); + int denominator = normal.Dot( v ); + if ( denominator == 0 ) + return numerator == 0; + double distance = ( double )numerator / denominator; + return distance > -0.5 && distance <= 0.5; + } + } +} \ No newline at end of file diff --git a/fCraft/Drawing/DrawOps/PlaneWireframeDrawOperation.cs b/fCraft/Drawing/DrawOps/PlaneWireframeDrawOperation.cs new file mode 100644 index 0000000..2df09d3 --- /dev/null +++ b/fCraft/Drawing/DrawOps/PlaneWireframeDrawOperation.cs @@ -0,0 +1,103 @@ +// Copyright 2009-2013 Matvei Stefarov +using System; +using System.Collections.Generic; + +namespace fCraft.Drawing { + + public sealed class PlaneWireframeDrawOperation : DrawOperation { + + public override int ExpectedMarks { + get { return 4; } + } + + public override string Name { + get { return "PlaneW"; } + } + + public PlaneWireframeDrawOperation( Player player ) + : base( player ) { + } + + public override bool Prepare( Vector3I[] marks ) { + Vector3I minVector = new Vector3I( Math.Min( Math.Min( marks[0].X, marks[1].X ), Math.Min( marks[2].X, marks[3].X ) ), + Math.Min( Math.Min( marks[0].Y, marks[1].Y ), Math.Min( marks[2].Y, marks[3].Y ) ), + Math.Min( Math.Min( marks[0].Z, marks[1].Z ), Math.Min( marks[2].Z, marks[3].Z ) ) ); + Vector3I maxVector = new Vector3I( Math.Max( Math.Max( marks[0].X, marks[1].X ), Math.Max( marks[2].X, marks[3].X ) ), + Math.Max( Math.Max( marks[0].Y, marks[1].Y ), Math.Max( marks[2].Y, marks[3].Y ) ), + Math.Max( Math.Max( marks[0].Z, marks[1].Z ), Math.Max( marks[2].Z, marks[3].Z ) ) ); + Bounds = new BoundingBox( minVector, maxVector ); + + if ( !base.Prepare( marks ) ) + return false; + + BlocksTotalEstimate = Math.Max( Bounds.Width, Math.Max( Bounds.Height, Bounds.Length ) ); + + coordEnumerator1 = LineEnumerator( Marks[0], Marks[1] ).GetEnumerator(); + coordEnumerator2 = LineEnumerator( Marks[1], Marks[2] ).GetEnumerator(); + coordEnumerator3 = LineEnumerator( Marks[2], Marks[3] ).GetEnumerator(); + coordEnumerator4 = LineEnumerator( Marks[3], Marks[0] ).GetEnumerator(); + return true; + } + + private IEnumerator coordEnumerator1, coordEnumerator2, coordEnumerator3, coordEnumerator4; + + public override int DrawBatch( int maxBlocksToDraw ) { + int blocksDone = 0; + while ( coordEnumerator1.MoveNext() ) { + Coords = coordEnumerator1.Current; + if ( DrawOneBlockIfNotDuplicate() ) { + blocksDone++; + if ( blocksDone >= maxBlocksToDraw ) + return blocksDone; + } + if ( TimeToEndBatch ) + return blocksDone; + } + while ( coordEnumerator2.MoveNext() ) { + Coords = coordEnumerator2.Current; + if ( DrawOneBlockIfNotDuplicate() ) { + blocksDone++; + if ( blocksDone >= maxBlocksToDraw ) + return blocksDone; + } + if ( TimeToEndBatch ) + return blocksDone; + } + while ( coordEnumerator3.MoveNext() ) { + Coords = coordEnumerator3.Current; + if ( DrawOneBlockIfNotDuplicate() ) { + blocksDone++; + if ( blocksDone >= maxBlocksToDraw ) + return blocksDone; + } + if ( TimeToEndBatch ) + return blocksDone; + } + + while ( coordEnumerator4.MoveNext() ) { + Coords = coordEnumerator4.Current; + if ( DrawOneBlockIfNotDuplicate() ) { + blocksDone++; + if ( blocksDone >= maxBlocksToDraw ) + return blocksDone; + } + if ( TimeToEndBatch ) + return blocksDone; + } + IsDone = true; + return blocksDone; + } + + private readonly HashSet modifiedBlocks = new HashSet(); + + private bool DrawOneBlockIfNotDuplicate() { + int index = Map.Index( Coords ); + if ( modifiedBlocks.Contains( index ) ) { + return false; + } else { + modifiedBlocks.Add( index ); + return DrawOneBlock(); + } + } + } +} \ No newline at end of file diff --git a/fCraft/Drawing/DrawOps/WallsOp.cs b/fCraft/Drawing/DrawOps/WallsDrawOperation.cs similarity index 100% rename from fCraft/Drawing/DrawOps/WallsOp.cs rename to fCraft/Drawing/DrawOps/WallsDrawOperation.cs diff --git a/fCraft/Games/MineField.cs b/fCraft/Games/MineField.cs index e4db390..6bdd162 100644 --- a/fCraft/Games/MineField.cs +++ b/fCraft/Games/MineField.cs @@ -61,7 +61,7 @@ public static MineField GetInstance() { } public static void Start( Player player ) { - Map map = MapGenerator.GenerateEmpty( 64, 128, 16 ); + Map map = MapGeneratorOld.GenerateEmpty( 64, 128, 16 ); map.Save( "maps/minefield.fcm" ); if ( _world != null ) { WorldManager.RemoveWorld( _world ); diff --git a/fCraft/Network/Heartbeat.cs b/fCraft/Network/Heartbeat.cs index 39a9ec0..41c31ae 100644 --- a/fCraft/Network/Heartbeat.cs +++ b/fCraft/Network/Heartbeat.cs @@ -88,6 +88,7 @@ private static void Send800CraftNetBeat() { // create a request try { HttpWebRequest request = ( HttpWebRequest )WebRequest.Create( uri ); + request.Timeout = 3000; request.Method = "POST"; // turn request string into a byte stream @@ -101,7 +102,7 @@ private static void Send800CraftNetBeat() { request.ContentType = "application/x-www-form-urlencoded"; request.CachePolicy = new System.Net.Cache.RequestCachePolicy( System.Net.Cache.RequestCacheLevel.NoCacheNoStore ); request.ContentLength = postBytes.Length; - request.Timeout = 5000; + request.Timeout = 3000; Stream requestStream = request.GetRequestStream(); // send it diff --git a/fCraft/Player/Chat.cs b/fCraft/Player/Chat.cs index 9b7d85c..82d2bb5 100644 --- a/fCraft/Player/Chat.cs +++ b/fCraft/Player/Chat.cs @@ -39,7 +39,7 @@ public static bool SendGlobal( [NotNull] Player player, [NotNull] string rawMess rawMessage = rawMessage.Replace( "$server", ConfigKey.ServerName.GetString() ); rawMessage = rawMessage.Replace( "$motd", ConfigKey.MOTD.GetString() ); rawMessage = rawMessage.Replace( "$date", DateTime.UtcNow.ToShortDateString() ); - rawMessage = rawMessage.Replace( "$time", DateTime.Now.ToString() ); + rawMessage = rawMessage.Replace( "$time", DateTime.UtcNow.ToString() ); if ( !player.Can( Permission.ChatWithCaps ) ) { int caps = 0; diff --git a/fCraft/Player/PlayerDB.cs b/fCraft/Player/PlayerDB.cs index 5accf1d..eae09a3 100644 --- a/fCraft/Player/PlayerDB.cs +++ b/fCraft/Player/PlayerDB.cs @@ -208,7 +208,7 @@ private static void LoadInternal( StreamReader reader, string header ) { RunCompatibilityChecks( version ); } - private static Dictionary rankMapping; + private static Dictionary rankMapping = null; internal static Rank GetRankByIndex( int index ) { Rank rank; diff --git a/fCraft/Utils/ExtensionMethods.cs b/fCraft/Utils/ExtensionMethods.cs index 9ecbbdb..42c55df 100644 --- a/fCraft/Utils/ExtensionMethods.cs +++ b/fCraft/Utils/ExtensionMethods.cs @@ -310,7 +310,11 @@ public static bool TryParseLocalDate( [NotNull] string dateString, out DateTime return false; } else { if ( !DateTime.TryParse( dateString, cultureInfo, DateTimeStyles.None, out date ) ) { + + #pragma warning disable CultureInfo[] cultureList = CultureInfo.GetCultures( CultureTypes.FrameworkCultures ); + #pragma warning restore + foreach ( CultureInfo otherCultureInfo in cultureList ) { cultureInfo = otherCultureInfo; try { diff --git a/fCraft/World/MapGenerator.cs b/fCraft/World/MapGenerator.cs index 300fee3..880cacf 100644 --- a/fCraft/World/MapGenerator.cs +++ b/fCraft/World/MapGenerator.cs @@ -34,7 +34,7 @@ public enum MapGenTemplate { Streams } - public sealed class MapGenerator { + public sealed class MapGeneratorOld { private readonly MapGeneratorArgs args; private readonly Random rand; private readonly Noise noise; @@ -48,7 +48,7 @@ public sealed class MapGenerator { private int groundThickness = 5; private const int SeaFloorThickness = 3; - public MapGenerator( [NotNull] MapGeneratorArgs generatorArgs ) { + public MapGeneratorOld( [NotNull] MapGeneratorArgs generatorArgs ) { if ( generatorArgs == null ) throw new ArgumentNullException( "generatorArgs" ); args = generatorArgs; @@ -201,6 +201,32 @@ private void GenerateHeightmap() { Noise.Normalize( heightmap ); } + public void setIgloo( Map Map, int xIn, int yIn, int zIn) { + int width = rand.Next( 15, 30 ); + int height = rand.Next( 15, 30 ); + for ( int x = -width; x <= width; x++ ) + for ( int y = height; y >= -height; y-- ) + for ( int z = -width; z <= width; z++ ) { + if ( y == height || ( Math.Abs( x ) == width && Math.Abs( z ) == width && y >= 0 ) ) { + Map.SetBlock( x + xIn, y + yIn, z + zIn, Block.Stone); + Map.SetBlock( x + xIn, y + yIn + 1, z + zIn, Block.Admincrete ); + } + + if ( y >= 1 && ( ( Math.Abs( x ) == width ) ^ ( Math.Abs( z ) == width ) ) ) + Map.SetBlock( x + xIn, y + yIn, z + zIn, Block.Gravel ); + + if ( y > 0 && y < height && Math.Abs( z ) < width && Math.Abs( x ) < width ) + Map.SetBlock( x + xIn, y + yIn, z + zIn, Block.Air ); //unsure + + if ( y == -1 || y == 0 ) + Map.SetBlock( x + xIn, y + yIn, z + zIn, Block.Gray ); + + if ( y < -1 ) { + if ( ( Math.Abs( x ) == width || Math.Abs( z ) == width )) + Map.SetBlock( x + xIn, y + yIn, z + zIn, Block.Brick ); + } + } + } private void ApplyBias() { // set corners and midpoint float[] corners = new float[4]; @@ -392,6 +418,10 @@ public Map GenerateMap() { AddBeaches( map ); } + if ( args.AddIgloos ) { + //GenerateIgloos( map ); + } + if ( args.AddTrees ) { ReportProgress( 5, "Processing: Planting trees" ); if ( args.AddGiantTrees ) { @@ -833,7 +863,8 @@ public static MapGeneratorArgs MakeTemplate( MapGenTemplate template ) { MarbledHeightmap = true, MatchWaterCoverage = true, WaterCoverage = .3f, - MaxHeightVariation = 0 + MaxHeightVariation = 0, + AddIgloos = true }; case MapGenTemplate.Island: diff --git a/fCraft/World/MapGeneratorArgs.cs b/fCraft/World/MapGeneratorArgs.cs index 498a11c..a883221 100644 --- a/fCraft/World/MapGeneratorArgs.cs +++ b/fCraft/World/MapGeneratorArgs.cs @@ -50,6 +50,8 @@ public sealed class MapGeneratorArgs { public bool AddTrees = true, AddGiantTrees; // false + public bool AddIgloos = false; + public int TreeSpacingMin = 7, TreeSpacingMax = 11, TreeHeightMin = 5, @@ -151,6 +153,8 @@ public MapGeneratorArgs( [NotNull] string fileName ) { TreeHeightMin = Int32.Parse( root.Element( "treeHeightMin" ).Value ); TreeHeightMax = Int32.Parse( root.Element( "treeHeightMax" ).Value ); + AddIgloos = Boolean.Parse( root.Element( "addIgloos" ).Value ); + if ( root.Element( "addCaves" ) != null ) { AddCaves = Boolean.Parse( root.Element( "addCaves" ).Value ); AddCaveLava = Boolean.Parse( root.Element( "addCaveLava" ).Value ); @@ -243,6 +247,8 @@ public XElement Serialize() { root.Add( new XElement( "treeHeightMin", TreeHeightMin ) ); root.Add( new XElement( "treeHeightMax", TreeHeightMax ) ); + root.Add( new XElement( "addIgloos", AddIgloos ) ); + root.Add( new XElement( "addCaves", AddCaves ) ); root.Add( new XElement( "addCaveLava", AddCaveLava ) ); root.Add( new XElement( "addCaveWater", AddCaveWater ) ); diff --git a/fCraft/World/World.cs b/fCraft/World/World.cs index e101ccb..cef4c44 100644 --- a/fCraft/World/World.cs +++ b/fCraft/World/World.cs @@ -513,7 +513,7 @@ public Map LoadMap() { Logger.Log( LogType.Warning, "World.LoadMap: Map file missing for world {0}. Generating default flatgrass map.", Name ); - Map = MapGenerator.GenerateFlatgrass( 128, 128, 64 ); + Map = MapGeneratorOld.GenerateFlatgrass( 128, 128, 64 ); } return Map; } diff --git a/fCraft/World/WorldManager.cs b/fCraft/World/WorldManager.cs index faeea59..f1af2cc 100644 --- a/fCraft/World/WorldManager.cs +++ b/fCraft/World/WorldManager.cs @@ -109,12 +109,12 @@ internal static bool LoadWorldList() { Logger.Log( LogType.Error, "Server.Start: Could not load any of the specified worlds, or no worlds were specified. " + "Creating default \"main\" world." ); - newMainWorld = AddWorld( null, "main", MapGenerator.GenerateFlatgrass( 128, 128, 64 ), true ); + newMainWorld = AddWorld( null, "main", MapGeneratorOld.GenerateFlatgrass( 128, 128, 64 ), true ); } } else { Logger.Log( LogType.SystemActivity, "Server.Start: No world list found. Creating default \"main\" world." ); - newMainWorld = AddWorld( null, "main", MapGenerator.GenerateFlatgrass( 128, 128, 64 ), true ); + newMainWorld = AddWorld( null, "main", MapGeneratorOld.GenerateFlatgrass( 128, 128, 64 ), true ); } // if there is no default world still, die. diff --git a/fCraft/fCraft.csproj b/fCraft/fCraft.csproj index 792d27b..c347adc 100644 --- a/fCraft/fCraft.csproj +++ b/fCraft/fCraft.csproj @@ -143,15 +143,17 @@ + + Code - + diff --git a/fCraftGUI/fCraftGUI.csproj b/fCraftGUI/fCraftGUI.csproj index 09eb0ff..eb08fa4 100644 --- a/fCraftGUI/fCraftGUI.csproj +++ b/fCraftGUI/fCraftGUI.csproj @@ -98,6 +98,7 @@ ResXFileCodeGenerator Resources.Designer.cs + Designer