1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-09-16 09:16:22 +02:00

fixed stutter caused by reactors, changes: reactor takes dmg only at 1000°C, warning above 800°C

This commit is contained in:
Maik Wild
2017-12-22 14:58:48 +01:00
parent fb19e52a5e
commit 2c077d82a5

View File

@@ -1,22 +1,19 @@
--Reactors melt down if:
--temperature is above 700°C and health is 0 or they are picked up
--temperature is at 1000°C and health is 0 or they are picked up
--
--a reactors loses (T - 800) * 1 damage per second
--a reactors loses 2 damage per second at 1000°C
global.wastelands = {}
global.last_reactor_warning = 0
global.reactors = {}
local wasteland_duration_seconds = 300
local function damage_per_second(T)
return (T - 800) * 1
end
local function entity_destroyed(event)
if event.entity.name == "nuclear-reactor" then
if event.entity.temperature > 700 then
event.entity.surface.create_entity{name="atomic-rocket", position=event.entity.position, target=event.entity, speed=1}
spawn_wasteland(reactor.surface, reactor.position)
global.wastelands[reactor.position.x .. "/" .. reactor.position.y] = {position = reactor.position, surface_id = reactor.surface.index, creation_time = game.tick}
end
end
end
@@ -58,18 +55,22 @@ end
local function check_reactors()
for _,surface in pairs(game.surfaces) do
local last_reactor_warning = global.last_reactor_warning
for _,reactor in pairs(surface.find_entities_filtered{name = "nuclear-reactor"}) do
if reactor.temperature > 500 and game.tick - global.last_reactor_warning > 600 then
game.print(string.format("Warning! Reactor at %s°C", reactor.temperature))
last_reactor_warning = game.tick
end
if reactor.temperature > 800 then
reactor.health = reactor.health - damage_per_second(reactor.temperature)
if reactor.health == 0 and (not global.wastelands[reactor.position.x .. "/" .. reactor.position.y]) then
reactor.surface.create_entity{name="atomic-rocket", position=reactor.position, target=reactor, speed=1}
spawn_wasteland(reactor.surface, reactor.position)
global.wastelands[reactor.position.x .. "/" .. reactor.position.y] = {position = reactor.position, surface_id = reactor.surface.index, creation_time = game.tick}
for i,reactor in pairs(global.reactors) do
if reactor.valid then
if reactor.temperature > 800 and game.tick - global.last_reactor_warning > 900 then
game.print(string.format("Warning! Reactor at %s°C", math.floor(reactor.temperature)))
last_reactor_warning = game.tick
end
if reactor.temperature > 800 then
reactor.health = reactor.health - 120
if reactor.health == 0 and (not global.wastelands[reactor.position.x .. "/" .. reactor.position.y]) then
reactor.surface.create_entity{name="atomic-rocket", position=reactor.position, target=reactor, speed=1}
spawn_wasteland(reactor.surface, reactor.position)
global.wastelands[reactor.position.x .. "/" .. reactor.position.y] = {position = reactor.position, surface_id = reactor.surface.index, creation_time = game.tick}
end
end
else
table.remove(global.reactors, i)
end
end
global.last_reactor_warning = last_reactor_warning
@@ -97,7 +98,15 @@ local function on_tick()
end
end
local function entity_build(event)
if event.created_entity.name == "nuclear-reactor" then
table.insert(global.reactors, event.created_entity)
end
end
Event.register(defines.events.on_tick, on_tick)
Event.register(defines.events.on_player_mined_entity, entity_destroyed)
Event.register(defines.events.on_robot_mined_entity, entity_destroyed)
Event.register(defines.events.on_entity_died, entity_destroyed)
Event.register(defines.events.on_built_entity, entity_build)
Event.register(defines.events.on_robot_built_entity, entity_build)