public static int CountBlocksAt( int x_beg, int x_end, int y_beg, int y_end,
int? minimum_count = null, ushort? tile_type = null, ushort? wall_type = null, byte? liquid_type = null ) {
int count = 0;
if( tile_type == null && wall_type == null && liquid_type == null ) {
tile_type = 0; // Empty, air blocks
wall_type = 0;
liquid_type = 0;
}
for( int i = x_beg; i < x_end; i++ ) {
for( int j = y_beg; j < y_end; j++ ) {
if( minimum_count != null && count >= minimum_count ) { break; }
Tile tile = Main.tile[i, j];
if( tile_type != null && tile.type != tile_type ) { continue; }
if( wall_type != null && tile.wall != wall_type ) { continue; }
if( liquid_type != null && tile.liquid != liquid_type ) { continue; }
count++;
}
}
return count;
}
public static int CountBlocksAtPlayer( Player player, int? minimum_count = null,
ushort? tile_type = null, ushort? wall_type = null, byte? liquid_type = null ) {
//int? min_x = null, int? max_x = null, int? min_y = null, int? max_y = null ) {
Vector2 my_center = player.Center;
int x_beg = ((int)my_center.X - (Main.maxScreenW / 2)) / 16;
int x_end = ((int)my_center.X + (Main.maxScreenW / 2)) / 16;
int y_beg = ((int)my_center.Y - (Main.maxScreenH / 2)) / 16;
int y_end = ((int)my_center.Y + (Main.maxScreenH / 2)) / 16;
int count = CountBlocksAt( x_beg, x_end, y_beg, y_end, minimum_count, tile_type, wall_type, liquid_type );
return count;
}
public static bool IsPlayerOutdoors( Player player ) {
//if( !player.zone["Surface"] ) { return false; }
if( (double)player.position.Y >= (double)(Main.worldSurface * 16.0) ) { return false; }
int total_blocks = (Main.maxScreenW / 16) * (Main.maxScreenH / 16);
int req_blocks = total_blocks / 3;
return CountBlocksAtPlayer( player, req_blocks ) >= req_blocks;
}