-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathentity_generator.lua
61 lines (51 loc) · 1.69 KB
/
entity_generator.lua
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
54
55
56
57
58
59
60
61
-- spawns the correct type of ore depending on it's quadrant
function spawn_quadrant_ore(surface, x, y)
local entityName = nil
if (x >= TRACK_WIDTH and y <= -TRACK_WIDTH) then --top right
entityName = "iron-ore"
end
if (x >= TRACK_WIDTH and y >= TRACK_WIDTH) then --bottom right
entityName = "stone"
end
if (x <= -TRACK_WIDTH and y >= TRACK_WIDTH) then --bottom left
entityName = "copper-ore"
end
if (x <= -TRACK_WIDTH and y <= -TRACK_WIDTH) then --top left
entityName = "coal"
end
if entityName ~= nil then
spawn_entity(surface, entityName, costCalc(x,y), x, y)
end
end
function spawn_built_ore(surface, x, y)
local tile = surface.get_tile(x, y)
if (tile.name ~= "grass") then
return
end
spawn_quadrant_ore(surface, x, y)
end
function spawn_entity(surface, entityName, amount, x, y)
surface.create_entity({name=entityName, position={x,y}, amount=amount})
end
function spawn_tree(surface, x, y)
if (x % 2 == 0 and y % 3 == 0 and getRandomIntInclusive(1, 100) <= 50) then
spawn_entity(surface, "tree-01", 1, x, y)
end
end
function spawn_oil(surface, x, y)
if (x % 2 == 0 and y % 2 == 0 and getRandomIntInclusive(1, 100) <= 10) then
spawn_entity(surface, "crude-oil", getRandomIntInclusive(400000,1000000), x, y)
end
end
function spawn_enemy(surface, x, y)
spawnertype = "biter-spawner"
chance = getRandomIntInclusive(1, 100)
if (chance <= 33) then
spawnertype = "spitter-spawner"
elseif (chance <= 40) then
spawnertype = "medium-worm-turret"
end
if (x % 4 == 0 and y % 4 == 0 and getRandomIntInclusive(1, 100) <= 40) then
spawn_entity(surface, spawnertype, 1, x, y)
end
end