forked from Blu3wolf/Treefarm-Lite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterfaces.lua
201 lines (150 loc) · 7.61 KB
/
interfaces.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
module(..., package.seeall)
remote.add_interface("treefarm_interface",
{
addSeed = function(seedInfo)
if seedInfo.name == nil then return "name not defined" end
if seedInfo.states == nil then return "growing states not defined" end
if seedInfo.efficiency == nil then return "efficiency not defined" end
if seedInfo.basicGrowingTime == nil or seedInfo.basicGrowingTime <= 0 then return "basicGrowingTime not defined" end
if seedInfo.randomGrowingTime == nil or seedInfo.randomGrowingTime <= 0 then return "randomGrowingTime not defined" end
if seedInfo.fertilizerBoost == nil or seedInfo.fertilizerBoost <= 0 then return "fertilizerBoost not defined" end
local newPlantGroupList = {}
newPlantGroupList[seedInfo.name] = seedInfo
register_plant_groups( newPlantGroupList )
end,
readSeed = function(seedName)
return global.tf.plantGroups[seedName]
end,
getSeedTypesData = function()
return global.tf.plantGroups
end,
clearGUIs = function()
for _, player in pairs(game.players) do
clear_farm_configuration_gui(player)
end
end,
test_setup_world = function(num_treefarms, origin_position, surface)
-- if no origin is given then center on the center of the world
origin_position = origin_position or { 0,0 }
-- default to the player's current surface
surface = surface or game.player.surface
-- we will place treefarms in a box centered around the origin
-- so each side of the box is sqrt(num_treefarms) long
local treefarms_per_side = math.ceil(math.sqrt(num_treefarms))
-- each treefarm occupies a 20x20 tile box, each chunk is 32x32
-- and we only need half of the chunks (b/c we want the radius not the diameter)
local chunk_radius = (treefarms_per_side * 20 / 32 ) / 2;
local coordinate = treefarms_per_side * 20 / 2;
local x_offset = origin_position.x or origin_position[1]
local y_offset = origin_position.y or origin_position[2]
-- generate the necessary chunks
surface.request_to_generate_chunks( origin_position, chunk_radius)
-- remove all the entities from a 1000 unit box around the center
for _, v in pairs(surface.find_entities ({{-coordinate + x_offset,-coordinate + y_offset}, {coordinate + x_offset,coordinate + y_offset}}))
do v.destroy()
end
-- replace all the terrain w/ grass terrain
for i = -coordinate + x_offset, coordinate + x_offset, 1 do
for j = -coordinate + y_offset,coordinate + y_offset,1 do
surface.set_tiles ({ { name = "grass", position = { i,j } } })
end
end
end,
test_create_mk2_treefarms = function(num_treefarms, origin_position, num_seeds, surface)
-- if no origin is given then center on the center of the world
origin_position = origin_position or { 0,0 }
-- default to the player's surface
surface = surface or game.player.surface
local treefarm_type = "tf-fieldmk2" -- treefarm_type or "tf-fieldmk2"
local field_size = 20
local treefarms_per_side = math.ceil(math.sqrt(num_treefarms))
local coordinate = treefarms_per_side * field_size / 2
local seed_type = "tf-germling"
local x_offset = origin_position.x or origin_position[1]
local y_offset = origin_position.y or origin_position[2]
local seed_quantity = num_seeds or game.get_item_prototype ( seed_type ).stack_size
local fertilizer_quantity = 0
if game.item_prototypes["tf-fertilizer"] ~= nil then
fertilizer_quantity = game.get_item_prototype ( "tf-fertilizer" ).stack_size
end
for i = -coordinate + x_offset + 10, coordinate + x_offset - 10, field_size do
for j = -coordinate + y_offset + 10, coordinate + y_offset - 10, field_size do
local ent = game.player.surface.create_entity({name=treefarm_type, position= {j,i}, force=game.player.force })
if (seed_quantity > 0) then
ent.insert({name=seed_type, count=seed_quantity})
if fertilizer_quantity > 0 then
ent.insert({name="tf-fertilizer", count=fertilizer_quantity})
end
end
on_farm_created(ent)
num_treefarms = num_treefarms - 1
if (num_treefarms == 0) then
return
end
end
end
end,
test_deconstruct_marked_trees = function(num_treefarms)
local field_size = 20
local treefarms_per_side = math.ceil(math.sqrt(num_treefarms))
local coordinate = treefarms_per_side * field_size / 2
for k, v in pairs(game.player.surface.find_entities_filtered({type="tree", area={ {-coordinate, -coordinate}, {coordinate,coordinate}} })) do
if v.to_be_deconstructed(game.player.force) then
v.destroy()
end
end
end,
test_create_mk1_treefarms = function(num_treefarms, gather_harvested, origin_position, num_seeds, surface)
if gather_harvested == nil then
gather_harvested = true
end
-- if no origin is given then center on the center of the world
origin_position = origin_position or { 0,0 }
-- default to the player's surface
surface = surface or game.player.surface
local treefarm_type = "tf-field" -- treefarm_type or "tf-fieldmk2"
local field_size = 20 -- it's actually 8 by 7, with the placement location in the upper-left corner
local treefarms_per_side = math.ceil(math.sqrt(num_treefarms))
local coordinate = treefarms_per_side * field_size / 2
local seed_type = "tf-germling"
local x_offset = origin_position.x or origin_position[1]
local y_offset = origin_position.y or origin_position[2]
local seed_quantity = num_seeds or game.get_item_prototype ( seed_type ).stack_size
local fertilizer_quantity = 0
if game.item_prototypes["tf-fertilizer"] ~= nil then
fertilizer_quantity = game.get_item_prototype ( "tf-fertilizer" ).stack_size
end
for i = -coordinate + x_offset + 10, coordinate + x_offset - 10, field_size do
for j = -coordinate + y_offset + 10, coordinate + y_offset - 10, field_size do
local ent = game.player.surface.create_entity({name=treefarm_type, position= {j,i}, force=game.player.force })
if (seed_quantity > 0) then
ent.insert({name=seed_type, count=seed_quantity})
if fertilizer_quantity > 0 then
ent.insert({name="tf-fertilizer", count=fertilizer_quantity})
end
end
on_farm_created(ent)
if gather_harvested then
-- create fast inserter to remove harvested trees
game.player.surface.create_entity({name="fast-inserter", position={j,i+1}, force = game.player.force, direction=defines.direction.north})
game.player.surface.create_entity({name="fast-inserter", position={j,i+3}, force = game.player.force, direction=defines.direction.north})
game.player.surface.create_entity({name="fast-inserter", position={j,i+5}, force = game.player.force, direction=defines.direction.north})
-- create storage chest to hold harvested trees
game.player.surface.create_entity({name="steel-chest", position={j,i+2}, force = game.player.force})
game.player.surface.create_entity({name="steel-chest", position={j,i+4}, force = game.player.force})
game.player.surface.create_entity({name="steel-chest", position={j,i+6}, force = game.player.force})
-- power for the inserters
game.player.surface.create_entity({name="medium-electric-pole", position={j-1,i+3}, force = game.player.force})
game.player.surface.create_entity({name="solar-panel", position={j-2,i+1}, force = game.player.force})
game.player.surface.create_entity({name="solar-panel", position={j-5,i+1}, force = game.player.force})
game.player.surface.create_entity({name="solar-panel", position={j-2,i+5}, force = game.player.force})
game.player.surface.create_entity({name="solar-panel", position={j-5,i+5}, force = game.player.force})
end
num_treefarms = num_treefarms - 1
if (num_treefarms == 0) then
return
end
end
end
end
})