1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-10 00:43:27 +02:00
ComfyFactorio/maps/mountain_fortress_v3/ic/main.lua

328 lines
7.9 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'
2021-10-15 16:59:25 +02:00
local WPT = require 'maps.mountain_fortress_v3.table'
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
Functions.kill_car(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
2021-01-12 22:53:19 +02:00
Minimap.kill_minimap(game.players[event.player_index])
Functions.save_car(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
Functions.kill_car(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
Functions.create_car(event)
2020-07-30 17:47:50 +02:00
end
local function on_player_driving_changed_state(event)
local player = game.players[event.player_index]
Functions.use_door_with_entity(player, event.entity)
Functions.validate_owner(player, event.entity)
2020-07-30 17:47:50 +02:00
end
2021-10-02 21:15:31 +02:00
local function on_player_died(event)
local player = game.get_player(event.player_index)
if not player or not player.valid then
return
end
Functions.on_player_died(player)
end
local function on_player_respawned(event)
local player = game.get_player(event.player_index)
if not player or not player.valid then
return
end
Functions.on_player_respawned(player)
end
local function nth_30_tick()
Functions.item_transfer()
local upgrades = WPT.get('upgrades')
2024-03-28 23:22:36 +02:00
if not upgrades then
return
end
if upgrades.has_upgraded_health_pool then
Functions.check_entity_healths()
2020-07-30 17:47:50 +02:00
end
end
2020-07-30 17:47:50 +02:00
local function nth_240_tick()
Minimap.update_minimap()
end
2020-08-21 13:56:01 +02:00
local function nth_400_tick()
Functions.remove_invalid_cars()
2020-07-30 17:47:50 +02:00
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 cars = IC.get('cars')
if not cars[entity.unit_number] then
2020-08-27 13:27:34 +02:00
return
end
2022-11-08 01:09:13 +02:00
local player = game.get_player(event.player_index)
if not player or not player.valid then
return
end
if player.controller_type == defines.controllers.spectator then
return
end
Minimap.kill_minimap(player)
2020-08-27 13:27:34 +02:00
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 cars = IC.get('cars')
local car = cars[entity.unit_number]
2020-08-27 13:27:34 +02:00
if not car then
return
end
2022-11-08 01:09:13 +02:00
local player = game.get_player(event.player_index)
if not player or not player.valid then
return
end
if player.controller_type == defines.controllers.spectator then
return
end
2021-05-18 21:11:28 +02:00
local surface_index = car.surface
local surface = game.surfaces[surface_index]
if not surface or not surface.valid then
return
end
2020-08-27 13:27:34 +02:00
Minimap.minimap(
2022-11-08 01:09:13 +02:00
player,
2021-05-18 21:11:28 +02:00
surface,
2020-08-27 13:27:34 +02:00
{
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
Functions.kick_player_from_surface(player, target)
2020-08-21 13:56:01 +02:00
end
2020-07-30 17:47:50 +02:00
local function on_init()
Public.reset()
end
2021-01-11 16:58:12 +02: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
2021-10-15 16:59:25 +02:00
local function on_entity_damaged(event)
local upgrades = WPT.get('upgrades')
if not upgrades.has_upgraded_health_pool then
2021-10-15 16:59:25 +02:00
return
end
local entity = event.entity
if not (entity and entity.valid) then
return
end
if not entity.unit_number then
return
end
local cars = IC.get('cars')
local car = cars[entity.unit_number]
if not car then
return
end
local final_damage_amount = event.final_damage_amount
local force = event.force
if force.index == 1 then
return
end
local data = {
entity = entity,
final_damage_amount = final_damage_amount,
car = car
}
Functions.set_damage_health(data)
end
local function on_player_repaired_entity(event)
local upgrades = WPT.get('upgrades')
if not upgrades.has_upgraded_health_pool then
2021-10-15 16:59:25 +02:00
return
end
local entity = event.entity
if not (entity and entity.valid) then
return
end
if not entity.unit_number then
return
end
local player = game.get_player(event.player_index)
local cars = IC.get('cars')
local car = cars[entity.unit_number]
if not car then
return
end
local data = {
entity = entity,
car = car,
player = player
}
Functions.set_repair_health(data)
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.on_nth_tick(30, nth_30_tick)
Event.on_nth_tick(240, nth_240_tick)
Event.on_nth_tick(400, nth_400_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)
2021-10-02 21:15:31 +02:00
Event.add(defines.events.on_player_died, on_player_died)
Event.add(defines.events.on_player_respawned, on_player_respawned)
2020-07-30 17:47:50 +02:00
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 16:58:12 +02:00
Event.add(defines.events.on_gui_switch_state_changed, on_gui_switch_state_changed)
2021-10-15 16:59:25 +02:00
Event.add(defines.events.on_entity_damaged, on_entity_damaged)
Event.add(defines.events.on_player_repaired_entity, on_player_repaired_entity)
2021-01-11 16:58:12 +02:00
2020-07-30 17:47:50 +02:00
return Public