1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-24 03:47:58 +02:00

210 lines
5.3 KiB
Lua
Raw Normal View History

2020-08-10 23:15:29 +02:00
require 'modules.check_fullness'
2020-07-30 17:47:50 +02:00
local Event = require 'utils.event'
local Functions = require 'maps.mountain_fortress_v3.ic.functions'
local IC = require 'maps.mountain_fortress_v3.ic.table'
2020-08-21 13:56:01 +02:00
local Minimap = require 'maps.mountain_fortress_v3.ic.minimap'
2020-07-30 17:47:50 +02:00
local Public = {}
Public.reset = IC.reset
Public.get_table = IC.get
local function on_entity_died(event)
local entity = event.entity
2020-08-09 20:31:50 +02:00
if not entity or not entity.valid then
2020-07-30 17:47:50 +02:00
return
end
local valid_types = IC.get_types()
2020-08-10 23:15:29 +02:00
if (valid_types[entity.type] or valid_types[entity.name]) then
local ic = IC.get()
2020-08-10 23:15:29 +02:00
Functions.kill_car(ic, entity)
2020-07-30 17:47:50 +02:00
end
end
local function on_player_mined_entity(event)
local entity = event.entity
2020-08-09 20:31:50 +02:00
if not entity or not entity.valid then
2020-07-30 17:47:50 +02:00
return
end
2020-08-05 21:36:20 +02:00
local valid_types = IC.get_types()
2020-08-05 21:36:20 +02:00
if (valid_types[entity.type] or valid_types[entity.name]) then
local ic = IC.get()
2021-01-12 21:53:19 +01:00
Minimap.kill_minimap(game.players[event.player_index])
2020-08-10 23:15:29 +02:00
Functions.save_car(ic, event)
2020-08-09 20:31:50 +02:00
end
2020-07-30 17:47:50 +02:00
end
local function on_robot_mined_entity(event)
local entity = event.entity
2020-08-05 21:36:20 +02:00
2020-07-30 17:47:50 +02:00
if not entity and not entity.valid then
return
end
2020-08-05 21:36:20 +02:00
local valid_types = IC.get_types()
if (valid_types[entity.type] or valid_types[entity.name]) then
local ic = IC.get()
2020-08-10 23:15:29 +02:00
Functions.kill_car(ic, entity)
2020-08-05 21:36:20 +02:00
end
2020-07-30 17:47:50 +02:00
end
local function on_built_entity(event)
2020-08-09 20:31:50 +02:00
local ce = event.created_entity
if not ce or not ce.valid then
return
end
local valid_types = IC.get_types()
if (valid_types[ce.type] or valid_types[ce.name]) ~= true then
2020-08-09 20:31:50 +02:00
return
end
local player = game.get_player(event.player_index)
if not player or not player.valid then
2020-08-05 21:36:20 +02:00
return
end
2020-07-30 17:47:50 +02:00
local ic = IC.get()
2020-08-05 21:36:20 +02:00
Functions.create_car(ic, event)
2020-07-30 17:47:50 +02:00
end
local function on_player_driving_changed_state(event)
local ic = IC.get()
local player = game.players[event.player_index]
2020-08-05 21:36:20 +02:00
Functions.use_door_with_entity(ic, player, event.entity)
2020-08-10 23:15:29 +02:00
Functions.validate_owner(ic, player, event.entity)
2020-07-30 17:47:50 +02:00
end
local function on_tick()
local tick = game.tick
2020-12-02 09:20:35 +01:00
if tick % 10 == 1 then
2021-05-16 14:42:15 +02:00
Functions.item_transfer()
2020-07-30 17:47:50 +02:00
end
2020-08-21 13:56:01 +02:00
if tick % 240 == 0 then
Minimap.update_minimap()
end
if tick % 400 == 0 then
2021-05-16 14:42:15 +02:00
Functions.remove_invalid_cars()
2020-07-30 17:47:50 +02:00
end
end
2020-08-27 13:27:34 +02:00
local function on_gui_closed(event)
local entity = event.entity
if not entity then
return
end
if not entity.valid then
return
end
if not entity.unit_number then
return
end
local ic = IC.get()
if not ic.cars[entity.unit_number] then
return
end
Minimap.kill_minimap(game.players[event.player_index])
end
local function on_gui_opened(event)
local entity = event.entity
if not entity or not entity.valid then
return
end
if not entity.unit_number then
return
end
local ic = IC.get()
local car = ic.cars[entity.unit_number]
if not car then
return
end
Minimap.minimap(
game.players[event.player_index],
car.surface,
{
car.area.left_top.x + (car.area.right_bottom.x - car.area.left_top.x) * 0.5,
car.area.left_top.y + (car.area.right_bottom.y - car.area.left_top.y) * 0.5
}
)
end
2020-08-21 13:56:01 +02:00
local function on_gui_click(event)
local element = event.element
if not element or not element.valid then
return
end
local player = game.get_player(event.player_index)
if not player or not player.valid then
return
end
if event.element.name == 'minimap_button' then
Minimap.minimap(player, false)
elseif event.element.name == 'minimap_frame' or event.element.name == 'minimap_toggle_frame' then
Minimap.toggle_minimap(event)
elseif event.element.name == 'switch_auto_map' then
Minimap.toggle_auto(player)
end
end
local function trigger_on_player_kicked_from_surface(data)
local player = data.player
local target = data.target
local this = data.this
Functions.kick_player_from_surface(this, player, target)
end
2020-07-30 17:47:50 +02:00
local function on_init()
Public.reset()
end
2021-01-11 15:58:12 +01:00
local function on_gui_switch_state_changed(event)
local element = event.element
local player = game.players[event.player_index]
if not (player and player.valid) then
return
end
if not element.valid then
return
end
if element.name == 'ic_auto_switch' then
Minimap.toggle_auto(player)
end
end
2020-08-21 13:56:01 +02:00
local changed_surface = Minimap.changed_surface
2020-07-30 17:47:50 +02:00
Event.on_init(on_init)
Event.add(defines.events.on_tick, on_tick)
2020-08-27 13:27:34 +02:00
Event.add(defines.events.on_gui_opened, on_gui_opened)
Event.add(defines.events.on_gui_closed, on_gui_closed)
2020-07-30 17:47:50 +02:00
Event.add(defines.events.on_player_driving_changed_state, on_player_driving_changed_state)
Event.add(defines.events.on_entity_died, on_entity_died)
Event.add(defines.events.on_built_entity, on_built_entity)
Event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
Event.add(defines.events.on_robot_mined_entity, on_robot_mined_entity)
2020-08-21 13:56:01 +02:00
Event.add(defines.events.on_gui_click, on_gui_click)
Event.add(defines.events.on_player_changed_surface, changed_surface)
Event.add(IC.events.on_player_kicked_from_surface, trigger_on_player_kicked_from_surface)
2021-01-11 15:58:12 +01:00
Event.add(defines.events.on_gui_switch_state_changed, on_gui_switch_state_changed)
2020-07-30 17:47:50 +02:00
return Public