-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrol.lua
More file actions
81 lines (67 loc) · 2.06 KB
/
control.lua
File metadata and controls
81 lines (67 loc) · 2.06 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
require "defines"
-- ==================================================================================================
-- Code from Toxic Jungle Mod. (https://forums.factorio.com/viewtopic.php?f=91&t=22348)
-- ==================================================================================================
-- list of tree entities
local trees = {
--"dead-dry-hairy-tree",
--"dead-grey-trunk",
--"dead-tree",
--"dry-hairy-tree",
--"dry-tree",
--"green-coral",
"tree-01",
"tree-02",
"tree-02-red",
"tree-03",
"tree-04",
"tree-05",
"tree-06",
"tree-06-brown",
"tree-07",
"tree-08",
"tree-08-brown",
"tree-08-red",
"tree-09",
"tree-09-brown",
"tree-09-red"
}
-- chance of a tree being spawned on a tile (density)
local tree_chance = 0.6
function generate_trees(event)
local entity = event.created_entity
local surface = entity.surface
-- bottom left of the chunk
local minx = entity.position.x - 10.5
local miny = entity.position.y - 10.5
-- bottom right of the chunk
local maxx = entity.position.x + 10.5
local maxy = entity.position.y + 10.5
surface.create_entity({name = "gackit-magicpuff", position = entity.position, force = game.forces.enemy})
-- iterate left to right
for x = minx, maxx do
-- iterate up to down
for y = miny, maxy do
if math.random() < tree_chance then
-- chose random tree type
local tree_type = trees[math.random(#trees)]
-- spawn tree
if surface.can_place_entity{name = tree_type, position = {x, y}} then
surface.create_entity{name = tree_type, position = {x, y}}
end
end
end
end
entity.destroy()
end
-- ==================================================================================================
script.on_event(defines.events.on_built_entity, function(event)
if event.created_entity.name == "gackit-seed" then
generate_trees(event)
end
end)
script.on_event(defines.events.on_robot_built_entity, function(event)
if event.created_entity.name == "gackit-seed" then
generate_trees(event)
end
end)