1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-10 00:43:27 +02:00
ComfyFactorio/maps/lumberjack/power.lua

68 lines
1.7 KiB
Lua
Raw Normal View History

2020-05-06 14:59:23 +02:00
local Event = require 'utils.event'
2020-05-10 02:42:10 +02:00
local WPT = require 'maps.lumberjack.table'
2020-04-27 00:19:06 +02:00
local function balance(t)
2020-05-06 14:59:23 +02:00
local g = 0
local c = 0
for k, v in pairs(t) do
if (v.valid) then
g = g + v.energy
c = c + v.electric_buffer_size
end
end
for k, v in pairs(t) do
if (v.valid) then
local r = (v.electric_buffer_size / c)
v.energy = g * r
end
end
2020-04-27 00:19:06 +02:00
end
local function tick()
2020-05-10 02:02:29 +02:00
local this = WPT.get_table()
2020-05-10 02:42:10 +02:00
if not this.energy['lumberjack'] then
this.energy['lumberjack'] = this.ow_energy
2020-05-06 14:59:23 +02:00
end
2020-04-27 00:19:06 +02:00
2020-05-06 14:59:23 +02:00
if not this.energy['loco'] then
this.energy['loco'] = this.lo_energy
end
2020-04-27 00:19:06 +02:00
2020-05-10 02:42:10 +02:00
local lumberjack = this.energy['lumberjack']
2020-05-06 14:59:23 +02:00
local loco = this.energy['loco']
2020-05-10 02:42:10 +02:00
if not lumberjack or not loco then
2020-05-06 14:59:23 +02:00
return
end
2020-05-10 02:42:10 +02:00
if not lumberjack.valid or not loco.valid then
2020-05-06 14:59:23 +02:00
return
end
balance(this.energy)
2020-04-27 00:19:06 +02:00
end
local function built_entity(event)
2020-05-06 14:59:23 +02:00
local entity = event.created_entity
if not entity.valid then
return
end
local player = game.players[event.player_index]
local surface = entity.surface
2020-05-11 21:04:13 +02:00
local map_name = 'lumberjack'
if surface.name ~= map_name then
2020-05-06 14:59:23 +02:00
return
end
if
entity.name == 'steam-engine' or entity.name == 'steam-turbine' or entity.name == 'lab' or
entity.name == 'rocket-silo'
then
if not entity.valid then
return
end
player.print('"' .. entity.name .. '" Does not seem to work down here, thats strange!', {r = 1, g = 0, b = 0})
entity.active = false
end
2020-04-27 00:19:06 +02:00
end
Event.add(defines.events.on_tick, tick)
2020-05-06 14:59:23 +02:00
--Event.add(defines.events.on_built_entity, built_entity)