-
Notifications
You must be signed in to change notification settings - Fork 80
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 tile_picker feature for better dirt generation in diggy #894
Open
ChickingWasTaken
wants to merge
1
commit into
Refactorio:develop
Choose a base branch
from
ChickingWasTaken:tile_picker
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
--[[-- info | ||
Provides nicer tile picking | ||
]] | ||
|
||
-- dependencies | ||
local Event = require 'utils.event' | ||
local perlin_noise = require 'map_gen.shared.perlin_noise'.noise | ||
|
||
-- this | ||
local Picker = {} | ||
|
||
local floor = math.floor | ||
local random = math.random | ||
|
||
local enabled = false | ||
local replacement_tiles | ||
local tile_count | ||
local noise_variance | ||
local seed | ||
|
||
-- should be called once before calling get_tile | ||
function Picker.set_seed(new_seed) | ||
seed = new_seed | ||
end | ||
|
||
-- returns tile generated by perlin noise from coordinates | ||
function Picker.get_tile(x, y) | ||
if not enabled then | ||
return 'dirt-' .. random(1, 7) | ||
end | ||
|
||
-- value in range [-1, 1] | ||
local noise | ||
if seed then | ||
noise = perlin_noise(x * noise_variance, y * noise_variance, seed) | ||
else | ||
noise = perlin_noise(x * noise_variance, y * noise_variance) | ||
end | ||
|
||
-- value in range [0, 1] | ||
local corrected_noise = (noise + 1) / 2 | ||
|
||
-- value in range [1, tile_count] | ||
local tile_number = floor(corrected_noise * tile_count) + 1 | ||
|
||
-- just in case perlin_noise() returns '1', not even sure if it can | ||
if tile_number > tile_count then | ||
tile_number = tile_count | ||
end | ||
|
||
return replacement_tiles[tile_number] | ||
end | ||
|
||
function Picker.register(config) | ||
enabled = true | ||
replacement_tiles = config.tiles or {'dirt-1', 'dirt-2', 'dirt-3', 'dirt-4', 'dirt-5', 'dirt-6', 'dirt-7'} | ||
tile_count = #replacement_tiles | ||
noise_variance = config.noise_variance or 0.03 | ||
|
||
-- add landfill event | ||
Event.add(defines.events.on_player_built_tile, function(event) | ||
local item = event.item | ||
if not item or item.name ~= 'landfill' then | ||
return | ||
end | ||
|
||
local tiles = event.tiles | ||
for i = 1, #tiles do | ||
local tile_name = Picker.get_tile(tiles[i].position.x, tiles[i].position.y) | ||
tiles[i].name = tile_name | ||
end | ||
|
||
local surface = game.surfaces[event.surface_index] | ||
surface.set_tiles(tiles) | ||
end) | ||
end | ||
|
||
return Picker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you disable the feature, what happens?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It generates terrain like it used to
if not enabled then return 'dirt-' .. random(1, 7) end