Exemplo n.º 1
0
		/// <summary>
		/// Generates the roof through the boxserver
		/// </summary>
		/// <param name="height">The height at which generation should happen</param>
		/// <param name="hue">The hue for the items</param>
		public void GenerateThroughServer( int height, int hue )
		{
			int[] roofIDs = new int[ m_RoofImage.Width * m_RoofImage.Height ];
			bool fail = false;

			// Revert any sign changes due to image processing
			for ( int i = 0; i < m_RoofImage.Width * m_RoofImage.Height; i++ )
			{
				// Issue 10 - Update the code to Net Framework 3.5 - http://code.google.com/p/pandorasbox3/issues/detail?id=10 - Smjert
				if ( m_RoofImage.Data[ i ] < 0 )
					m_RoofImage.Data[ i ] = - m_RoofImage.Data[ i ];
				// Issue 10 - End
			}

			// Calculate the roof ids
			for ( int i = 0; i < m_RoofImage.Width * m_RoofImage.Height; i++ )
			{
				// Issue 10 - Update the code to Net Framework 3.5 - http://code.google.com/p/pandorasbox3/issues/detail?id=10 - Smjert
				if ( m_RoofImage.Data[ i ] == 0 )
				// Issue 10 - End
				{
					roofIDs[ i ] = 0;
				}
				else
				{
					uint flags = RoofingHelper.GetFlags( MakeLine( i - m_RoofImage.Width ), MakeLine( i ), MakeLine( i + m_RoofImage.Width ) );
					roofIDs[ i ] = m_TileSet.FindID( flags );

					if ( roofIDs[ i ] == 0 )
					{
						// Issue 10 - Update the code to Net Framework 3.5 - http://code.google.com/p/pandorasbox3/issues/detail?id=10 - Smjert
						m_RoofImage.Data[ i ] = - m_RoofImage.Data[ i ];
						// Issue 10 - End
						fail = true;
					}
				}
			}

			if ( fail )
			{
				m_RoofImage.CreateImage();

				// Request redraw image
				if ( RoofImageChanged != null )
				{
					RoofImageChanged( this, new EventArgs() );
				}

				if ( MessageBox.Show(
					Pandora.Localization.TextProvider[ "Roofing.MissTiles" ],
					"",
					MessageBoxButtons.YesNo,
					MessageBoxIcon.Question ) == DialogResult.No )
				{
					return;
				}
			}

			string idFormat = hue > 0 ? "static {0} set hue " + hue.ToString() : "static {0}";

			int p = 0;

			// Issue 10 - Update the code to Net Framework 3.5 - http://code.google.com/p/pandorasbox3/issues/detail?id=10 - Smjert
			List<BuildItem> items = new List<BuildItem>();
			// Issue 10 - End

			for ( int y = 0; y < m_RoofImage.Height; y++ )
			{
				for ( int x = 0; x < m_RoofImage.Width; x++, p++ )
				{
					if ( roofIDs[ p ] == 0 )
					{
						continue;
					}

					// Build item
					BuildItem item = new BuildItem();
					
					item.Hue = hue;
					item.ID = roofIDs[ p ];

					item.X = m_BasePoint.X + x;
					item.Y = m_BasePoint.Y + y;
					// Issue 10 - Update the code to Net Framework 3.5 - http://code.google.com/p/pandorasbox3/issues/detail?id=10 - Smjert
					item.Z = height + ( 3 * m_RoofImage.Data[ p ] ) - 3;
					// Issue 10 - End

					items.Add( item );
				}
			}

			TheBox.BoxServer.BuildMessage msg = new BuildMessage();
			msg.Items = items;

            Pandora.BoxConnection.SendToServer(msg);
		}
Exemplo n.º 2
0
		/// <summary>
		/// Generates the items
		/// </summary>
		private void GenerateItems()
		{
			Random rnd = new Random();
			m_Message = new BuildMessage();

			MapViewer.Maps oldMap = Pandora.Map.Map;
			Pandora.Map.Map = (MapViewer.Maps) m_Map;

			for ( int x = 0; x < m_Rectangle.Width; x++ )
			{
				for ( int y = 0; y < m_Rectangle.Height; y++ )
				{
					if ( ! m_Grid[ x, y ] )
						continue;

					RandomTile tile = m_TileSet.Tiles[ rnd.Next( m_TileSet.Tiles.Count ) ] as RandomTile;

					foreach( int id in tile.Items )
					{
						BuildItem item = new BuildItem();
						item.ID = id;

						// Hue
						int hue = m_Hue;

						if ( m_RandomHues != null )
						{
							// Issue 10 - Update the code to Net Framework 3.5 - http://code.google.com/p/pandorasbox3/issues/detail?id=10 - Smjert
							hue = m_RandomHues.Hues[ rnd.Next( m_RandomHues.Hues.Count ) ];
							// Issue 10 - End
						}
						
						item.Hue = hue;

						// Location
						item.X = m_Rectangle.X + x;
						item.Y = m_Rectangle.Y + y;

						if ( m_Z != -1 )
							item.Z = Pandora.Map.GetMapHeight( new Point( item.X, item.Y ) );
						else
							item.Z = m_Z;
						

						m_Message.Items.Add( item );
					}
				}
			}

			Pandora.Map.Map = oldMap;
		}