require "util" script.on_init(function() On_Load() end) script.on_load(function() On_Load() end) script.on_event(defines.events.on_tick, function() On_Tick() end) script.on_event(defines.events.on_built_entity, function(event) On_Built(event) end) script.on_event(defines.events.on_robot_built_entity, function(event) On_Built(event) end) script.on_event(defines.events.on_preplayer_mined_item, function(event) On_Removed(event) end) script.on_event(defines.events.on_robot_pre_mined, function(event) On_Removed(event) end) script.on_event(defines.events.on_entity_died, function(event) On_Removed(event) end) --printout = game.players[1].print --Values set at start.. --How to check which surface it is: --if game.players[1].surface == game.surfaces["nauvis"] then game.players[1].print("yes") else game.players[1].print("no") end --tickerA = 60 global.energyCreated = 0 modifier = 1.45 global.findRockets = 0 function message(mes) for i, player in pairs(game.players) do player.print(mes) end end script.on_event(defines.events.on_player_joined_game, function(event) player_joined(event) end) function player_joined() global.energyCreated = global.rockets_sent * 100 * 60000 * modifier global.findRockets = 1 read_satellites_sent_from_gui(game.forces.player) message("Satelites already orbiting the planet was detected: "..global.rockets_sent) end function On_Load() if not global.rockets_sent then global.rockets_sent = 0 end if not global.energyReceivers then global.energyReceivers = {} end end globTempChange = 0 function On_Tick() if (game.tick % 60 == 0) then if global.energyCreated ~= 0 then addEnergy() end end end function On_Built(event) local ent = event.created_entity if ent.name == "energy-receiver" then global.energyReceivers[#global.energyReceivers+1] = ent message("New energy receiver connected. Remember it will spread the energy created evenly between all the "..#global.energyReceivers.." receivers!") end end function On_Removed(event) local ent = event.entity if ent.name == "energy-receiver" then for receivers = 1, #global.energyReceivers do if global.energyReceivers[receivers] == ent then table.remove(global.energyReceivers, receivers) end end end end --Counting how many rockets that have been sent script.on_event(defines.events.on_rocket_launched, function(event) read_satellites_sent_from_gui(game.forces.player) message("Congratulation at sending up another satelite! ") message("Number of satelites in operation: "..global.rockets_sent) if global.rockets_sent/#global.energyReceivers > 10 then message("To fully utilize the energy your rockets are creating. Please build atleast one more energy receiver. Thank you.") end end) --Find out how many satelites there are, and then how much energy to create --For simplicity i can choose to give each energy receiver 1/x amount of energy where x is number of receivers. This way its --A little bit simpler. Though i would wish to at a later point to add in the functionality to place down an energyreceiver and then --open a GUI and then you can specify how many satelites that should be connected to that one energy receiver. local counter = 1 local full_rec = 0 function addEnergy() local receivers = #global.energyReceivers local tempChange = (global.energyCreated/receivers)/200000 tempChange = tempChange*receivers/(receivers-full_rec) full_rec = 0 for receiver = counter, receivers,4 do --Satelites are iterated once every 60 ticks However a quarter at a time every 15 ticks of 60 local receiv = global.energyReceivers[receiver] if global.energyReceivers[receiver].valid then -- For each energy receiver, while we are creating energy, create beamed energy 'fluid' in the receiver (a steam generator object) -- The amount of fluid created is determines by the amount of launched satellites, spread evenly between the receivers. -- A single receiver can at max receive 10 satellites worth of energy. -- Note: beamedenergy fluid has 0 - 1000 temperature and a heat capacity of 100MJ. (Receivers are 100% efficient) -- Energy received is adjusted by adjusting the temperature of the fluid. (Fluid is always fully filled) if receiv.valid then local receiv_fluidBox = receiv.fluidbox if receiv_fluidBox.valid then local energyfluidbox = receiv_fluidBox[1] if energyfluidbox == nil then energyfluidbox = {type="beamedenergy", amount=10, temperature=tempChange} global.energyReceivers[receiver].fluidbox[1] = energyfluidbox else if energyfluidbox["amount"] < 5 then energyfluidbox["amount"] = 10 -- Liquid has a heat capacity of 2 KJ per degree C. Which means -- 1 Sat = 100 * 60000 * 1.05 -- Temperature of receiver = (Energy generated / number of receivers) / (conversion of J to C) -- C per receiver = (J per receiver) / (J / C) energyfluidbox["temperature"] = tempChange -- Roughly 6C per satellite. if energyfluidbox["temperature"] > 60.0 then energyfluidbox["temperature"] = 60.0 -- Limit to 10 satellites per receiver. end global.energyReceivers[receiver].fluidbox[1] = energyfluidbox else full_rec = full_rec + 1 end end else full_rec = full_rec + 1 end else full_rec = full_rec + 1 end else full_rec = full_rec + 1 end end --End by doing the last that are lost due to the division for receiver = receivers, receivers-(receivers%4-1),-1 do --Satelites are iterated once every 60 ticks However a quarter at a time every 15 ticks of 60 local receiv = global.energyReceivers[receiver] if global.energyReceivers[receiver].valid then -- For each energy receiver, while we are creating energy, create beamed energy 'fluid' in the receiver (a steam generator object) -- The amount of fluid created is determines by the amount of launched satellites, spread evenly between the receivers. -- A single receiver can at max receive 10 satellites worth of energy. -- Note: beamedenergy fluid has 0 - 1000 temperature and a heat capacity of 100MJ. (Receivers are 100% efficient) -- Energy received is adjusted by adjusting the temperature of the fluid. (Fluid is always fully filled) if receiv.valid then local receiv_fluidBox = receiv.fluidbox if receiv_fluidBox.valid then local energyfluidbox = receiv_fluidBox[1] if energyfluidbox == nil then energyfluidbox = {type="beamedenergy", amount=10, temperature=tempChange} global.energyReceivers[receiver].fluidbox[1] = energyfluidbox else if energyfluidbox["amount"] < 5 then energyfluidbox["amount"] = 10 -- Liquid has a heat capacity of 2 KJ per degree C. Which means -- 1 Sat = 100 * 60000 * 1.05 -- Temperature of receiver = (Energy generated / number of receivers) / (conversion of J to C) -- C per receiver = (J per receiver) / (J / C) energyfluidbox["temperature"] = tempChange -- Roughly 6C per satellite. if energyfluidbox["temperature"] > 60.0 then energyfluidbox["temperature"] = 60.0 -- Limit to 10 satellites per receiver. end global.energyReceivers[receiver].fluidbox[1] = energyfluidbox else full_rec = full_rec + 1 end end else full_rec = full_rec + 1 end else full_rec = full_rec + 1 end else full_rec = full_rec + 1 end end counter = counter + 1 if counter == 5 then counter = 1 end end --Thank you Zwobot :D! function read_satellites_sent_from_gui(force) --print("Reading #satellites from " .. force.name) for i, player in pairs(game.players) do local rocket_score = player.gui.left.rocket_score if rocket_score then local rocket_count = rocket_score.rocket_count global.rockets_sent = tonumber(rocket_count.caption) if rocket_count ~= nil then --message("FoundGUI: " .. tostring_ex(rocket_count.caption)) end end end end