mirror of
https://github.com/Refactorio/RedMew.git
synced 2024-12-14 10:13:13 +02:00
3f8be3151a
* Add redmew_surface * Change map_layout to have all maps use redmew_surface * Maps: switch hardcoded nauvis refs to redmew_surface * Features: switch hardcoded nauvis refs to redmew_surface * Per discussion, removal of RSO * Changes to files based on linting warnings/errors * ent_functions: remove functions from global scope, ignore remaining linting warnings (~100 remaining) * borg_planet: ignore linting warnings (88 remaining) * mazes refactored * Changed global.lua so events are run in the order they are registered
66 lines
2.1 KiB
Lua
66 lines
2.1 KiB
Lua
--- Provides the ability to inform players that solar panels doesn't work underground
|
|
-- also handles the freezing of nighttime
|
|
-- @module NightTime
|
|
--
|
|
|
|
|
|
-- dependencies
|
|
local Event = require 'utils.event'
|
|
local Game = require 'utils.game'
|
|
local RS = require 'map_gen.shared.redmew_surface'
|
|
|
|
-- this
|
|
local NightTime = {}
|
|
|
|
--- Event handler for on_built_entity
|
|
-- checks if player placed a solar-panel and displays a popup
|
|
-- @param event table containing the on_built_entity event specific attributes
|
|
--
|
|
local function on_built_entity(event)
|
|
local player = Game.get_player_by_index(event.player_index)
|
|
local entity = event.created_entity
|
|
if (entity.name == 'solar-panel') then
|
|
require 'features.gui.popup'.player(
|
|
player,[[
|
|
Placing solar panels underground does not seem
|
|
to have an effect on power production!
|
|
Studies show, that the same applies to the portable version!
|
|
|
|
Foreman's advice: Solar Panels are only useful in crafting
|
|
satellites
|
|
]]
|
|
)
|
|
end
|
|
end
|
|
|
|
--- Event handler for on_research_finished
|
|
-- sets the force, which the research belongs to, recipe for solar-panel-equipment
|
|
-- to false, to prevent wastefully crafting. The technology is needed for further progression
|
|
-- @param event table containing the on_research_finished event specific attributes
|
|
--
|
|
local function on_research_finished(event)
|
|
local force = event.research.force
|
|
force.recipes["solar-panel-equipment"].enabled = false
|
|
end
|
|
|
|
--- Setup of on_built_entity and on_research_finished events
|
|
-- assigns the two events to the corresponding local event handlers
|
|
-- @param config table containing the configurations for NightTime.lua
|
|
--
|
|
function NightTime.register()
|
|
Event.add(defines.events.on_built_entity, on_built_entity)
|
|
Event.add(defines.events.on_research_finished, on_research_finished)
|
|
end
|
|
|
|
--- Sets the daytime to 0.5 and freezes the day/night circle.
|
|
-- a daytime of 0.5 is the value where every light and ambient lights are turned on.
|
|
--
|
|
function NightTime.on_init()
|
|
local surface = RS.get_surface()
|
|
|
|
surface.daytime = 0.5
|
|
surface.freeze_daytime = 1
|
|
end
|
|
|
|
return NightTime
|