pyanodon / PyBlock

pymod style seablock
9 stars 8 forks source link

Distance based ore richness #3

Closed John-Ender closed 3 years ago

John-Ender commented 3 years ago

Razahin here. I've only ever played Factorio with RSO, so I really liked the concept that ores would become more lucrative the further away from the starting area you went.

I made a very crude approximation of this effect in the generation code for PyBlock. I would have made a pull request but I was unable to pull down the code. (Permissions and whatnot).

Anyhow if you wanted to use it just replace line 409 with the following

local function calculateFactor(distance, exponent)
    if distance< 1 and exponent < 1 then
        return distance
    end

    return distance^exponent
end

local amount = math.random(1000, 1500) * calculateFactor(util.distance({x=0, y=0}, {x = event.area.left_top.x, y = event.area.left_top.y}), 1.075)

amount = math.floor(amount)

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

game.surfaces["nauvis"].create_entity{name=Rocks[SelectedRock],position={Randx,Randy},amount=amount}

and add

require "util" to the top of the file.