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

Update map generation to be more natural, turn off unnecessary settings #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
237 changes: 97 additions & 140 deletions control.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
--require("functions/autobuilder")

require "util"

--rare earth and moly need to show up around sci 2

local startchunk = false
Expand Down Expand Up @@ -36,67 +38,13 @@ local by = 32
local fx = tx
local fy = ty

for i = 0,4096 do

table.insert(oldtiles,{name=waters[math.random(1,2)],position={fx,fy}})

fx = fx + 1

if fx == tx + 64 then

fx = tx
fy = fy + 1

end

end

game.surfaces["nauvis"].set_tiles(oldtiles)

local crap = game.surfaces["nauvis"].find_entities({{tx,ty},{bx,by}})

for _,c in pairs(crap) do

--log(serpent.block(c))
if c ~= game.player and c.name ~= 'seaweed' and c.name ~= 'fish' then

c.destroy()

end

end

--setup spawn area

global.firstrock = true
global.secondrock = true

local t

for x = 0,10 do

table.insert(Tiles,{name="landfill", position={X,Y}})

X = X + 1

if X == 2 then

X = -1

Y = Y + 1

if Y == 2 then

Y = -1

end

end

end

game.surfaces["nauvis"].set_tiles(Tiles)

end)

local crashedshipparts =
Expand Down Expand Up @@ -220,6 +168,15 @@ local Rocks =
"tar-patch"
}

-- Create a set of the rock types, for quick determination so they don't accidentally get deleted when the next chunk generates
local function Set (list)
local set = {}
for _, l in ipairs(list) do set[l] = true end
return set
end

local RocksSet = Set(Rocks)

--local firstrock = true

local loot_table_fuelrod =
Expand Down Expand Up @@ -283,7 +240,6 @@ elseif tx == 0 and ty == 0 then
--log(serpent.block(event.area))
else


local crap = game.surfaces["nauvis"].find_entities({{tx,ty},{bx,by}})

for _,c in pairs(crap) do
Expand All @@ -292,7 +248,7 @@ else
--log(serpent.block(c.name))
--log(serpent.block(c.position))

if c.name ~= "iron-rock" and c.name ~= 'seaweed' and c.name ~= 'fish' then
if RocksSet[c.name] == nil and c.name ~= 'seaweed' and c.name ~= 'fish' then
Copy link
Author

Choose a reason for hiding this comment

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

Not deleting generated resources is important because otherwise there are occasions when the next chunk is generated it will delete the resource generated on the nearby chunk leaving map artifacts.

--log('destroying')
c.destroy()

Expand All @@ -315,110 +271,111 @@ else
local fx = tx
local fy = ty

for i = 0,1024 do

--check for landfill from another chunk and dont replace
if game.surfaces["nauvis"].get_tile(fx,fy).name == "landfill" then



else

--local ent = game.surfaces["nauvis"].find_entities({{fx,fy},{fx,fy}})

--for _, e in pairs(ent) do

--log(e.name)

--if e.name == "iron-rock" then

--else
table.insert(oldtiles,{name=waters[math.random(1,2)],position={fx,fy}})

--end

--end

end

fx = fx + 1

if fx == tx + 32 then
end

fx = tx
fy = fy + 1
-- -----------------------------------------------------------------------------------------------------------------------------
-- Helper Functions
-- -----------------------------------------------------------------------------------------------------------------------------

end
-- Multiply the amount certain resources have
-- Separate this into a second function for easy extention
local function amplifyAmountBasedOnRock(rock, amount)

if rock == 'oil-mk01' or rock == 'oil-mk02' or rock == 'oil-mk03' or rock == 'oil-mk04' or rock == 'tar-patch' then
return amount * 4
end

return amount

game.surfaces["nauvis"].set_tiles(oldtiles)
end

local crap = game.surfaces["nauvis"].find_entities({{tx,ty},{bx,by}})
-- Caluclate the distance the possible placement position is from the starting area, calculate amount based on this distance
local function getDistanceBasedAmount(position, rock)

for _,c in pairs(crap) do
--log(serpent.block(c.name))
if c.name ~= 'fish' and c.name ~= 'seaweed' then
c.destroy()
function calculateFactor(distance, exponent)
if distance< 1 and exponent < 1 then
return distance
end

return distance^exponent
end
--end
end
--setting stuff in chunk
local SelectedRock = math.random(1,25)

local Randx = math.random(tx+7,bx-7)
local Randy = math.random(ty+7,by-7)

local tiles = {}

amount = 1000 * calculateFactor(util.distance({x=0, y=0},
{x = math.abs(position.x), y = math.abs(position.y)}), 1.05)

amount = math.floor(amount)

amount = amplifyAmountBasedOnRock(rock, amount)

if amount > 1e9 then
amount = 1e9
elseif amount < 250000 then
amount = math.random(250000, 400000)
end

return amount

local x = Randx - 7
local y = Randy - 7
end

local a=0
local b=0
-- -----------------------------------------------------------------------------------------------------------------------------
-- Place resources on generated islands
-- -----------------------------------------------------------------------------------------------------------------------------

local RandChance
local placementChance = math.random(1,5)
local rockSelection = 0
local forcePlace = false

-- Determine Resource
if global.firstrock == true then
SelectedRock = 1
RandChance = math.random(0,30)
rockSelection = 1
forcePlace = true
elseif global.secondrock == true and global.firstrock == false then
SelectedRock = 2
RandChance = math.random(0,30)
rockSelection = 2
forcePlace = true
else
RandChance = math.random(0,240)
rockSelection = math.random(1,25)
end
if RandChance == 5 then
for i = 0,169 do
table.insert(tiles,{name="landfill", position={x,y}})
x = x+1
a=a+1
if a==13 then
x = x-13
y = y+1
b = b+1
a=0
if b==13 then
y=y-13
b=0
end

-- Determine if the Resource can be placed,
local possiblePosition = event.surface.find_non_colliding_position_in_box(Rocks[rockSelection], event.area, 1)

if possiblePosition ~= nil then

local canPlaceEntity = event.surface.can_place_entity{name=Rocks[rockSelection], position=possiblePosition}

-- If there are no other resources nearby, roll the chance to place the resource
local nearbyEntities = event.surface.find_entities_filtered{position=possiblePosition, radius=25, name=Rocks, limit=1}

if canPlaceEntity == true and nearbyEntities ~= nil and #nearbyEntities == 0 then
if forcePlace == true or placementChance == 1 then

local amount

-- Now that we have confirmed that we can generate a resource, determine the amount
if settings.startup["pyblock-ore-distance-richness"].value then
amount = getDistanceBasedAmount(possiblePosition, Rocks[rockSelection])
else
-- Base generation setting
amount = amplifyAmountBasedOnRock(Rocks[rockSelection], math.random(250000,1000000))
end
end
game.surfaces["nauvis"].set_tiles(tiles)
local rock = Rocks[SelectedRock]
if rock == 'oil-mk01' or rock == 'oil-mk02' or rock == 'oil-mk03' or rock == 'oil-mk04' or rock == 'tar-patch' then
amount = math.random(1000000,5000000)
else
amount = math.random(250000,1000000)
end
game.surfaces["nauvis"].create_entity{name=rock,position={Randx,Randy},amount=amount}
if global.firstrock == true then
global.firstrock = false
elseif global.firstrock == false and global.secondrock == true then
global.secondrock = false

local entity = game.surfaces["nauvis"].create_entity{name=Rocks[rockSelection], position=possiblePosition, amount=amount}

if entity ~= nil and global.firstrock == true then
global.firstrock = false
elseif entity ~= nil and global.secondrock == true and global.firstrock == false then
global.secondrock = false
end
end
end
end

-- -----------------------------------------------------------------------------------------------------------------------------
-- Place ship parts in chunk
-- -----------------------------------------------------------------------------------------------------------------------------

local RandChance = math.random(0,240)

if RandChance == 6 then
local ship = game.surfaces['nauvis'].create_entity{name = crashedshipparts[math.random(1,3)], position={math.random(tx+3,bx-3),math.random(ty+3,by-3)}, force=game.players[1].force}
local loot_rand_pick = math.random(1,25)
Expand Down
1 change: 1 addition & 0 deletions data-updates.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local fun = require('functions/functions')
require('prototypes/updates/pyhightech-updates')
require('prototypes/updates/pyalienlife-updates')
require('prototypes/updates/ddc-coal-updates')
require('prototypes/updates/generator-updates')

RECIPE("bio-reactor"):replace_ingredient('advanced-circuit','electronic-circuit')

Expand Down
2 changes: 2 additions & 0 deletions data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ require("prototypes/recipes")
--require("prototypes/overrides/angel-recipe-overrides")
--require("prototypes/overrides/angel-tech-overrides")

require("prototypes/generator")


--formula to calulate steam consumption
--flowrate (in units/s) * heat capacity (J/unit/C) * (T - 15 C) = wattage
Expand Down
7 changes: 7 additions & 0 deletions locale/en/locale.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,10 @@ alloying-mk02=Alloying 2

[controls]
recipe-selector=Recipe Selector

[mod-setting-name]
pyblock-ore-distance-richness=Enable distance based ore richness


[mod-setting-description]
pyblock-ore-distance-richness=Generated ores are more lucrative the further away from the starting area they spawn.
Loading