Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ores generation in quarries #337

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
8 changes: 8 additions & 0 deletions gui-src/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,14 @@ button:hover {
margin: 15px 0;
}

#fillground-toggle {
accent-color: #fecc44;
}

.fillground-toggle-container, .scale-slider-container {
margin: 15px 0;
}

#winter-toggle {
accent-color: #fecc44;
}
Expand Down
6 changes: 5 additions & 1 deletion gui-src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ <h2 data-localize="customization_settings">Customization Settings</h2>
<label for="terrain-toggle" data-localize="terrain">Terrain:</label>
<input type="checkbox" id="terrain-toggle" name="terrain-toggle">
</div>

<!-- Fill ground Toggle Button -->
<div class="fillground-toggle-container">
<label for="fillground-toggle" data-localize="fillground">Fill Ground:</label>
<input type="checkbox" id="fillground-toggle" name="fillground-toggle">
</div>
<!-- Winter Mode Toggle Button -->
<div class="winter-toggle-container">
<label for="winter-toggle" data-localize="winter_mode">Winter Mode:</label>
Expand Down
4 changes: 3 additions & 1 deletion gui-src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ async function startGeneration() {

var terrain = document.getElementById("terrain-toggle").checked;
var winter_mode = document.getElementById("winter-toggle").checked;
var fill_ground = document.getElementById("fillground-toggle").checked;
var scale = parseFloat(document.getElementById("scale-value-slider").value);
var floodfill_timeout = parseInt(document.getElementById("floodfill-timeout").value, 10);
var ground_level = parseInt(document.getElementById("ground-level").value, 10);
Expand All @@ -496,7 +497,8 @@ async function startGeneration() {
groundLevel: ground_level,
winterMode: winter_mode,
floodfillTimeout: floodfill_timeout,
terrainEnabled: terrain
terrainEnabled: terrain,
fillgroundEnabled: fill_ground
});

console.log("Generation process started.");
Expand Down
4 changes: 3 additions & 1 deletion src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ pub struct Args {
/// Enable terrain (optional)
#[arg(long, default_value_t = false, action = clap::ArgAction::SetFalse)]
pub terrain: bool,

/// Enable filling ground (optional)
#[arg(long, default_value_t = false, action = clap::ArgAction::SetFalse)]
pub fillground: bool,
/// Enable debug mode (optional)
#[arg(long, default_value_t = false, action = clap::ArgAction::SetTrue)]
pub debug: bool,
Expand Down
6 changes: 6 additions & 0 deletions src/block_definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ impl Block {
126 => "coarse_dirt",
127 => "iron_ore",
128 => "coal_ore",
129 => "gold_ore",
130 => "copper_ore",
131 => "clay",
_ => panic!("Invalid id"),
}
}
Expand Down Expand Up @@ -411,6 +414,9 @@ pub const RAIL_SOUTH_WEST: Block = Block::new(125);
pub const COARSE_DIRT: Block = Block::new(126);
pub const IRON_ORE: Block = Block::new(127);
pub const COAL_ORE: Block = Block::new(128);
pub const GOLD_ORE: Block = Block::new(129);
pub const COPPER_ORE: Block = Block::new(130);
pub const CLAY: Block = Block::new(131);

// Variations for building corners
pub fn building_corner_variations() -> Vec<Block> {
Expand Down
12 changes: 10 additions & 2 deletions src/data_processing.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::args::Args;
use crate::block_definitions::{DIRT, GRASS_BLOCK, SNOW_BLOCK};
use crate::block_definitions::{BEDROCK, DIRT, GRASS_BLOCK, SNOW_BLOCK, STONE};
use crate::cartesian::XZPoint;
use crate::element_processing::*;
use crate::ground::Ground;
Expand All @@ -9,7 +9,7 @@ use crate::world_editor::WorldEditor;
use colored::Colorize;
use indicatif::{ProgressBar, ProgressStyle};

const MIN_Y: i32 = -64;
pub const MIN_Y: i32 = -64;

pub fn generate_world(
elements: Vec<ProcessedElement>,
Expand Down Expand Up @@ -170,6 +170,13 @@ pub fn generate_world(
editor.set_block(groundlayer_block, x, max_y, z, None, None);
editor.set_block(DIRT, x, max_y - 1, z, None, None);
editor.set_block(DIRT, x, max_y - 2, z, None, None);
// Fill underground with stone
if args.fillground {
for y in MIN_Y + 1..max_y - 2 {
editor.set_block(STONE, x, y, z, None, None);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use editor.fill_blocks() instead.

}
editor.set_block(BEDROCK, x, MIN_Y, z, None, Some(&[BEDROCK]));

block_counter += 1;
if block_counter % batch_size == 0 {
Expand All @@ -196,6 +203,7 @@ pub fn generate_world(
let ground_level = ground.level(XZPoint::new(x, z));
editor.set_block(groundlayer_block, x, ground_level, z, None, None);
editor.set_block(DIRT, x, ground_level - 1, z, None, None);
editor.set_block(BEDROCK, x, MIN_Y, z, None, Some(&[BEDROCK]));

block_counter += 1;
if block_counter % batch_size == 0 {
Expand Down
31 changes: 27 additions & 4 deletions src/element_processing/landuse.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::args::Args;
use crate::block_definitions::*;
use crate::cartesian::XZPoint;
use crate::data_processing::MIN_Y;
use crate::element_processing::tree::create_tree;
use crate::floodfill::flood_fill_area;
use crate::ground::Ground;
Expand Down Expand Up @@ -45,15 +46,15 @@ pub fn generate_landuse(
"military" => GRAY_CONCRETE,
"railway" => GRAVEL,
"landfill" => {
// Gravel if man_made = spoil_heap, coarse dirt else
let manmade = element.tags.get("man_made").unwrap_or(&binding);
if manmade == "spoil_heap" {
// Gravel if man_made = spoil_heap or heap, coarse dirt else
let manmade_tag = element.tags.get("man_made").unwrap_or(&binding);
if manmade_tag == "spoil_heap" || manmade_tag == "heap" {
GRAVEL
} else {
COARSE_DIRT
}
}
"quarry" => STONE, // TODO: add ores
"quarry" => STONE,
_ => {
if args.winter {
SNOW_BLOCK
Expand Down Expand Up @@ -349,6 +350,28 @@ pub fn generate_landuse(
}
}
}
"quarry" => {
if let Some(resource) = element.tags.get("resource") {
let ore_block = match resource.as_str() {
"iron_ore" => IRON_ORE,
"coal" => COAL_ORE,
"copper" => COPPER_ORE,
"gold" => GOLD_ORE,
"clay" | "kaolinite" => CLAY,
_ => STONE,
};
let random_choice: i32 = rng.gen_range(0..100 + ground_level); // with more depth there's more resources
if random_choice < 5 {
editor.set_block(ore_block, x, ground_level, z, Some(&[STONE]), None);
}
// Fill everything with stone so dirt won't be there
if args.fillground {
for y in MIN_Y + 1..ground_level {
editor.set_block(STONE, x, y, z, None, None);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

editor.fill_blocks()

}
}
}
_ => {}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ fn gui_check_for_updates() -> Result<bool, String> {

#[cfg(feature = "gui")]
#[tauri::command]
#[allow(clippy::too_many_arguments)]
fn gui_start_generation(
bbox_text: String,
selected_world: String,
Expand All @@ -400,6 +401,7 @@ fn gui_start_generation(
winter_mode: bool,
floodfill_timeout: u64,
terrain_enabled: bool,
fillground_enabled: bool,
) -> Result<(), String> {
tauri::async_runtime::spawn(async move {
if let Err(e) = tokio::task::spawn_blocking(move || {
Expand Down Expand Up @@ -427,6 +429,7 @@ fn gui_start_generation(
scale: world_scale,
ground_level,
terrain: terrain_enabled,
fillground: fillground_enabled,
winter: winter_mode,
debug: false,
timeout: Some(std::time::Duration::from_secs(floodfill_timeout)),
Expand Down