2018-11-14 14:08:47 +02:00
|
|
|
--- Provides the ability to inform players that solar panels doesn't work underground
|
|
|
|
-- also handles the freezing of nighttime
|
|
|
|
-- @module NightTime
|
|
|
|
--
|
|
|
|
|
2018-11-11 16:47:51 +02:00
|
|
|
|
|
|
|
-- dependencies
|
|
|
|
local Event = require 'utils.event'
|
|
|
|
local Game = require 'utils.game'
|
2019-01-16 20:44:55 +02:00
|
|
|
local RS = require 'map_gen.shared.redmew_surface'
|
2018-11-11 16:47:51 +02:00
|
|
|
|
|
|
|
-- this
|
|
|
|
local NightTime = {}
|
|
|
|
|
2018-11-14 14:08:47 +02:00
|
|
|
--- Event handler for on_built_entity
|
|
|
|
-- checks if player placed a solar-panel and displays a popup
|
2018-11-14 17:56:20 +02:00
|
|
|
-- @param event table containing the on_built_entity event specific attributes
|
2018-11-14 14:08:47 +02:00
|
|
|
--
|
2018-11-11 16:47:51 +02:00
|
|
|
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
|
2018-11-16 23:43:41 +02:00
|
|
|
require 'features.gui.popup'.player(
|
2018-11-11 16:47:51 +02:00
|
|
|
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
|
|
|
|
|
2018-12-13 21:59:00 +02:00
|
|
|
--- Event handler for on_research_finished
|
2018-11-14 14:08:47 +02:00
|
|
|
-- sets the force, which the research belongs to, recipe for solar-panel-equipment
|
2018-12-13 21:59:00 +02:00
|
|
|
-- to false, to prevent wastefully crafting. The technology is needed for further progression
|
2018-11-14 17:56:20 +02:00
|
|
|
-- @param event table containing the on_research_finished event specific attributes
|
2018-11-14 14:08:47 +02:00
|
|
|
--
|
2018-11-11 16:47:51 +02:00
|
|
|
local function on_research_finished(event)
|
2018-11-11 17:24:09 +02:00
|
|
|
local force = event.research.force
|
2018-12-13 21:59:00 +02:00
|
|
|
force.recipes["solar-panel-equipment"].enabled = false
|
2018-11-11 16:47:51 +02:00
|
|
|
end
|
|
|
|
|
2018-11-14 14:08:47 +02:00
|
|
|
--- 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
|
|
|
|
--
|
2018-12-13 21:59:00 +02:00
|
|
|
function NightTime.register()
|
2018-11-11 17:24:09 +02:00
|
|
|
Event.add(defines.events.on_built_entity, on_built_entity)
|
|
|
|
Event.add(defines.events.on_research_finished, on_research_finished)
|
2018-11-11 16:47:51 +02:00
|
|
|
end
|
|
|
|
|
2018-11-14 14:08:47 +02:00
|
|
|
--- 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.
|
|
|
|
--
|
2018-11-11 16:47:51 +02:00
|
|
|
function NightTime.on_init()
|
2019-01-16 20:44:55 +02:00
|
|
|
local surface = RS.get_surface()
|
2018-11-14 14:08:47 +02:00
|
|
|
|
2018-11-11 16:47:51 +02:00
|
|
|
surface.daytime = 0.5
|
|
|
|
surface.freeze_daytime = 1
|
|
|
|
end
|
|
|
|
|
2018-11-11 17:24:09 +02:00
|
|
|
return NightTime
|