This repository was archived by the owner on Sep 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcontrol.lua
More file actions
53 lines (44 loc) · 2.04 KB
/
control.lua
File metadata and controls
53 lines (44 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require("smallRuins")
require("mediumRuins")
require("largeRuins")
local DEBUG = false --used for debug, users should not enable
--function that will return true 'percent' of the time.
function probability(percent)
return math.random() <= percent
end
script.on_event({defines.events.on_chunk_generated},
function (e)
local center = {x=(e.area.left_top.x+e.area.right_bottom.x)/2, y=(e.area.left_top.y+e.area.right_bottom.y)/2}
if math.abs(center.x) < settings.global["ruins-min-distance-from-spawn"].value and math.abs(center.y) < settings.global["ruins-min-distance-from-spawn"].value then return end --too close to spawn
if probability(settings.global["ruins-small-ruin-chance"].value) then
--spawn small ruin
if DEBUG then
game.print("A small ruin was spawned at " .. center.x .. "," .. center.y)
end
--random variance so they aren't always chunk aligned
center.x = center.x + math.random(-10,10)
center.y = center.y + math.random(-10,10)
spawnSmallRuins(center, e.surface)
elseif probability(settings.global["ruins-medium-ruin-chance"].value) then
--spawn medium ruin
if DEBUG then
game.print("A medium ruin was spawned at " .. center.x .. "," .. center.y)
end
--random variance so they aren't always chunk aligned
center.x = center.x + math.random(-5,5)
center.y = center.y + math.random(-5,5)
spawnMediumRuins(center, e.surface)
elseif probability(settings.global["ruins-large-ruin-chance"].value) then
--spawn large ruin
if DEBUG then
game.print("A large ruin was spawned at " .. center.x .. "," .. center.y)
end
spawnLargeRuins(center, e.surface)
end
end
)
script.on_init(
function()
math.randomseed(game.surfaces[1].map_gen_settings.seed) --set the random seed to the map seed, so ruins are the same-ish with each generation.
end
)