48 end |
62 end |
49 |
63 |
50 script.on_nth_tick(31, function(event) |
64 script.on_nth_tick(31, function(event) |
51 init_storage() |
65 init_storage() |
52 local need_cleanup = false |
66 local need_cleanup = false |
53 for lab, lab_info in pairs(storage.fusion_labs) |
67 for lab, lab_info in pairs(storage.fusion_labs or {}) |
54 do |
68 do |
55 if not lab.valid |
69 if not lab.valid |
56 then |
70 then |
57 need_cleanup = true |
71 need_cleanup = true |
58 elseif lab.status == defines.entity_status.working |
72 elseif lab.status == defines.entity_status.working |
59 then |
73 then |
60 local heat_interface = lab_info.heat_interface |
74 local heat_interface = lab_info.heat_interface |
|
75 |
|
76 if not heat_interface.valid |
|
77 then |
|
78 -- (╯°□°)╯︵ ┻━┻ |
|
79 game.print("[Fusion lab] Heat interface data corrupt, rebuilding") |
|
80 storage.fusion_labs = nil |
|
81 init_storage() |
|
82 return |
|
83 end |
|
84 |
61 lab.minable = (heat_interface.temperature <= 900) |
85 lab.minable = (heat_interface.temperature <= 900) |
62 -- A cryogenic plant cooling hot fluoroketone voids 1320kW |
86 -- A cryogenic plant cooling hot fluoroketone voids 1320kW |
63 -- of heat energy, so the fusion lab with no modules just happens |
87 -- of heat energy, so the fusion lab with no modules just happens |
64 -- to conveniently radiate exactly half of that energy rate. |
88 -- to conveniently radiate exactly half of that energy rate. |
65 -- |
89 -- |
78 if heat_interface.temperature > 710.0 |
102 if heat_interface.temperature > 710.0 |
79 then |
103 then |
80 lab.surface.create_entity{ |
104 lab.surface.create_entity{ |
81 name = 'crash-site-fire-flame', |
105 name = 'crash-site-fire-flame', |
82 position={lab.position.x + 3.5 * (math.random() - 0.5), lab.position.y + 3.5 * (math.random() - 0.5)}, |
106 position={lab.position.x + 3.5 * (math.random() - 0.5), lab.position.y + 3.5 * (math.random() - 0.5)}, |
83 force=game.forces.enemy, |
107 force=game.forces.neutral, |
84 } |
108 } |
85 end |
109 end |
86 --[[ |
|
87 if heat_interface.temperature > 750.0 |
|
88 then |
|
89 lab.die() |
|
90 end |
|
91 ]]-- |
|
92 end |
110 end |
93 end |
111 end |
94 if need_cleanup |
112 if need_cleanup |
95 then |
113 then |
96 cleanup_labs() |
114 cleanup_labs() |
97 end |
115 end |
|
116 for _, player in pairs(game.players) |
|
117 do |
|
118 if player.gui.relative.fusion_lab_gui and player.opened and player.opened.name == "fusion-lab" |
|
119 then |
|
120 for lab, lab_info in pairs(storage.fusion_labs) |
|
121 do |
|
122 if lab == player.opened |
|
123 then |
|
124 local heat_interface = lab_info.heat_interface |
|
125 local gui = player.gui.relative.fusion_lab_gui |
|
126 gui.heat.value = heat_interface.temperature / 700 |
|
127 gui.heat.caption = {"format-degrees", string.format("%.2f", heat_interface.temperature)} |
|
128 end |
|
129 end |
|
130 end |
|
131 end |
98 end) |
132 end) |
99 |
|
100 |
133 |
101 script.on_event(defines.events.on_entity_died, function(event) |
134 script.on_event(defines.events.on_entity_died, function(event) |
102 local lab = event.entity |
135 local lab = event.entity |
103 -- we can't rely on storage here |
136 event.entity.force = game.forces.neutral |
|
137 -- we can't rely on storage here; search for the heat interface on the map |
104 local heat_interfaces = lab.surface.find_entities_filtered{ |
138 local heat_interfaces = lab.surface.find_entities_filtered{ |
105 name='fusion-lab-heat-interface', |
139 name = 'fusion-lab-heat-interface', |
106 position=lab.position, |
140 position = lab.position, |
107 limit = 1, |
141 limit = 1, |
108 } |
142 } |
109 if #heat_interfaces > 0 |
143 if #heat_interfaces > 0 |
110 then |
144 then |
111 local heat_interface = heat_interfaces[1] |
145 local heat_interface = heat_interfaces[1] |
112 if heat_interface.temperature > 700 |
146 if heat_interface.temperature > 700 |
113 then |
147 then |
114 for _, ofs in pairs{{0, 0}, {5, 0}, {-5, 0}, {0, 5}, {0, -5}, {1.5, 1.5}, {-1.5, 1.5}, {-1.5, -1.5}, {1.5, -1.5}} |
148 for _, ofs in pairs{ |
|
149 {0, 0}, |
|
150 {5, 0}, |
|
151 {-5, 0}, |
|
152 {0, 5}, |
|
153 {0, -5}, |
|
154 {1.5, 1.5}, |
|
155 {-1.5, 1.5}, |
|
156 {-1.5, -1.5}, |
|
157 {1.5, -1.5}} |
115 do |
158 do |
116 local pos = {x = lab.position.x + ofs[1], y = lab.position.y + ofs[2]} |
159 local pos = { |
|
160 x = lab.position.x + ofs[1], |
|
161 y = lab.position.y + ofs[2]} |
117 lab.surface.create_entity{ |
162 lab.surface.create_entity{ |
118 name = 'artillery-projectile', |
163 name = 'artillery-projectile', |
119 position = pos, |
164 position = pos, |
120 target = pos, |
165 target = pos, |
121 force = game.forces.enemy, |
166 force = game.forces.neutral, |
|
167 cause = event.entity, |
122 } |
168 } |
123 end |
169 end |
124 end |
170 end |
125 heat_interface.destroy() |
171 heat_interface.destroy() |
126 end |
172 end |
127 end, {{filter="name", name="fusion-lab"}}) |
173 end, {{filter="name", name="fusion-lab"}}) |
128 |
174 |
|
175 ---@param event EventData |
129 local function on_fusion_lab_mined(event) |
176 local function on_fusion_lab_mined(event) |
130 init_storage() |
177 init_storage() |
131 local entity = event.entity |
178 local entity = event.entity ---@type LuaEntity |
132 for _, heat_interface in pairs(entity.surface.find_entities_filtered{ |
179 for _, heat_interface in pairs(entity.surface.find_entities_filtered{ |
133 name='fusion-lab-heat-interface', |
180 name='fusion-lab-heat-interface', |
134 position = entity.position |
181 position = entity.position |
135 }) |
182 }) |
136 do |
183 do |
146 position=lab.position, |
193 position=lab.position, |
147 force=lab.force, |
194 force=lab.force, |
148 } |
195 } |
149 heat_interface.temperature = 15 |
196 heat_interface.temperature = 15 |
150 heat_interface.destructible = false |
197 heat_interface.destructible = false |
|
198 heat_interface.active = false |
151 storage.fusion_labs[lab] = {heat_interface = heat_interface} |
199 storage.fusion_labs[lab] = {heat_interface = heat_interface} |
152 end |
200 end |
153 |
201 |
154 script.on_event(defines.events.on_player_mined_entity, on_fusion_lab_mined, {{filter="name", name="fusion-lab"}}) |
202 script.on_event(defines.events.on_player_mined_entity, on_fusion_lab_mined, {{filter="name", name="fusion-lab"}}) |
155 script.on_event(defines.events.on_robot_mined_entity, on_fusion_lab_mined, {{filter="name", name="fusion-lab"}}) |
203 script.on_event(defines.events.on_robot_mined_entity, on_fusion_lab_mined, {{filter="name", name="fusion-lab"}}) |