mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-01-22 03:38:48 +02:00
Merge branch 'develop' into journey1.9
This commit is contained in:
commit
e34c7cd82a
@ -276,6 +276,18 @@ local function set_train_final_health(final_damage_amount, repair)
|
||||
rendering.set_text(health_text, 'HP: ' .. round(locomotive_health) .. ' / ' .. round(locomotive_max_health))
|
||||
end
|
||||
|
||||
local function is_protected(e)
|
||||
local map_name = 'mtn_v3'
|
||||
|
||||
if string.sub(e.surface.name, 0, #map_name) ~= map_name then
|
||||
return true
|
||||
end
|
||||
if protect_types[e.type] then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function protect_entities(data)
|
||||
local cause = data.cause
|
||||
local entity = data.entity
|
||||
@ -298,18 +310,6 @@ local function protect_entities(data)
|
||||
return
|
||||
end
|
||||
|
||||
local function is_protected(e)
|
||||
local map_name = 'mtn_v3'
|
||||
|
||||
if string.sub(e.surface.name, 0, #map_name) ~= map_name then
|
||||
return true
|
||||
end
|
||||
if protect_types[e.type] then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local carriages_numbers = Public.get('carriages_numbers')
|
||||
if is_protected(entity) then
|
||||
if (cause and cause.valid) then
|
||||
|
@ -890,16 +890,18 @@ function Public.set_difficulty()
|
||||
Diff.value = 0.1
|
||||
end
|
||||
|
||||
if Diff.index == 1 then
|
||||
wave_defense_table.max_active_biters = 768 + player_count * (90 * Diff.value)
|
||||
elseif Diff.index == 2 then
|
||||
wave_defense_table.max_active_biters = 845 + player_count * (90 * Diff.value)
|
||||
elseif Diff.index == 3 then
|
||||
wave_defense_table.max_active_biters = 1000 + player_count * (90 * Diff.value)
|
||||
end
|
||||
if not wave_defense_table.enforce_max_active_biters then
|
||||
if Diff.index == 1 then
|
||||
wave_defense_table.max_active_biters = 768 + player_count * (90 * Diff.value)
|
||||
elseif Diff.index == 2 then
|
||||
wave_defense_table.max_active_biters = 845 + player_count * (90 * Diff.value)
|
||||
elseif Diff.index == 3 then
|
||||
wave_defense_table.max_active_biters = 1000 + player_count * (90 * Diff.value)
|
||||
end
|
||||
|
||||
if wave_defense_table.max_active_biters >= 4000 then
|
||||
wave_defense_table.max_active_biters = 4000
|
||||
if wave_defense_table.max_active_biters >= 4000 then
|
||||
wave_defense_table.max_active_biters = 4000
|
||||
end
|
||||
end
|
||||
|
||||
-- threat gain / wave
|
||||
|
@ -100,7 +100,7 @@ end
|
||||
local function on_tick()
|
||||
local tick = game.tick
|
||||
|
||||
if tick % 20 == 1 then
|
||||
if tick % 30 == 1 then
|
||||
Functions.item_transfer()
|
||||
local upgrades = WPT.get('upgrades')
|
||||
if upgrades.has_upgraded_health_pool then
|
||||
|
@ -104,7 +104,7 @@ end
|
||||
|
||||
local function on_tick()
|
||||
local tick = game.tick
|
||||
if tick % 10 == 0 then
|
||||
if tick % 20 == 0 then
|
||||
Functions.item_transfer()
|
||||
Functions.hazardous_debris()
|
||||
end
|
||||
|
@ -598,6 +598,7 @@ function Public.is_around_train(entity)
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
local surface = game.surfaces[active_surface_index]
|
||||
local upgrades = Public.get('upgrades')
|
||||
|
||||
|
@ -1,53 +1,60 @@
|
||||
local Public = require 'modules.rpg.table'
|
||||
local Event = require 'utils.event'
|
||||
local Token = require 'utils.token'
|
||||
|
||||
local function on_entity_damaged(event)
|
||||
local enable_range_buffs = Public.get_range_buffs()
|
||||
if not enable_range_buffs then
|
||||
return
|
||||
end
|
||||
local on_entity_damaged_token =
|
||||
Token.register(
|
||||
function(event)
|
||||
local enable_range_buffs = Public.get_range_buffs()
|
||||
if not enable_range_buffs then
|
||||
return
|
||||
end
|
||||
|
||||
local cause = event.cause
|
||||
if not cause then
|
||||
return
|
||||
end
|
||||
if not cause.valid then
|
||||
return
|
||||
end
|
||||
if cause.name ~= 'character' then
|
||||
return
|
||||
end
|
||||
local damage_type = event.damage_type
|
||||
if damage_type.name ~= 'physical' then
|
||||
return
|
||||
end
|
||||
local cause = event.cause
|
||||
if not cause then
|
||||
return
|
||||
end
|
||||
|
||||
local player = cause
|
||||
if player.shooting_state.state == defines.shooting.not_shooting then
|
||||
return
|
||||
end
|
||||
local weapon = player.get_inventory(defines.inventory.character_guns)[player.selected_gun_index]
|
||||
local ammo = player.get_inventory(defines.inventory.character_ammo)[player.selected_gun_index]
|
||||
if not weapon.valid_for_read or not ammo.valid_for_read then
|
||||
return
|
||||
end
|
||||
local p = cause.player
|
||||
if not (p and p.valid) then
|
||||
return
|
||||
end
|
||||
local modifier = Public.get_range_modifier(p)
|
||||
if ammo.name ~= 'firearm-magazine' and ammo.name ~= 'piercing-rounds-magazine' and ammo.name ~= 'uranium-rounds-magazine' then
|
||||
return
|
||||
end
|
||||
local entity = event.entity
|
||||
if not entity.valid then
|
||||
return
|
||||
end
|
||||
if not cause.valid then
|
||||
return
|
||||
end
|
||||
|
||||
local final_damage_amount = event.final_damage_amount
|
||||
entity.damage(final_damage_amount * modifier, player.force, 'impact', player)
|
||||
end
|
||||
if cause.name ~= 'character' then
|
||||
return
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_entity_damaged, on_entity_damaged)
|
||||
local damage_type = event.damage_type
|
||||
if damage_type.name ~= 'physical' then
|
||||
return
|
||||
end
|
||||
|
||||
local player = cause
|
||||
if player.shooting_state.state == defines.shooting.not_shooting then
|
||||
return
|
||||
end
|
||||
local weapon = player.get_inventory(defines.inventory.character_guns)[player.selected_gun_index]
|
||||
local ammo = player.get_inventory(defines.inventory.character_ammo)[player.selected_gun_index]
|
||||
if not weapon.valid_for_read or not ammo.valid_for_read then
|
||||
return
|
||||
end
|
||||
local p = cause.player
|
||||
if not (p and p.valid) then
|
||||
return
|
||||
end
|
||||
local modifier = Public.get_range_modifier(p)
|
||||
if ammo.name ~= 'firearm-magazine' and ammo.name ~= 'piercing-rounds-magazine' and ammo.name ~= 'uranium-rounds-magazine' then
|
||||
return
|
||||
end
|
||||
local entity = event.entity
|
||||
if not entity.valid then
|
||||
return
|
||||
end
|
||||
|
||||
local final_damage_amount = event.final_damage_amount
|
||||
entity.damage(final_damage_amount * modifier, player.force, 'impact', player)
|
||||
end
|
||||
)
|
||||
|
||||
Event.add_removable(defines.events.on_entity_damaged, on_entity_damaged_token, 'on_entity_damaged_token_range_buffs')
|
||||
|
||||
return Public
|
||||
|
@ -220,8 +220,11 @@ end
|
||||
|
||||
--- Sets value to table
|
||||
---@param key string
|
||||
function Public.set(key)
|
||||
if key then
|
||||
function Public.set(key, value)
|
||||
if key and (value or value == false) then
|
||||
this[key] = value
|
||||
return this[key]
|
||||
elseif key then
|
||||
return this[key]
|
||||
else
|
||||
return this
|
||||
|
@ -222,8 +222,7 @@ local function get_spawn_pos()
|
||||
return valid_position
|
||||
end
|
||||
|
||||
local function is_unit_valid(biter)
|
||||
local max_biter_age = Public.get('max_biter_age')
|
||||
local function is_unit_valid(biter, max_biter_age, tick)
|
||||
if not biter.entity then
|
||||
Public.debug_print('is_unit_valid - unit destroyed - does no longer exist')
|
||||
return false
|
||||
@ -232,7 +231,7 @@ local function is_unit_valid(biter)
|
||||
Public.debug_print('is_unit_valid - unit destroyed - invalid')
|
||||
return false
|
||||
end
|
||||
if biter.spawn_tick + max_biter_age < game.tick then
|
||||
if biter.spawn_tick + max_biter_age < tick then
|
||||
Public.debug_print('is_unit_valid - unit destroyed - timed out')
|
||||
return false
|
||||
end
|
||||
@ -263,17 +262,24 @@ end
|
||||
local function time_out_biters()
|
||||
local generated_units = Public.get('generated_units')
|
||||
local active_biter_count = Public.get('active_biter_count')
|
||||
local max_active_biters = Public.get('max_active_biters')
|
||||
local active_biter_threat = Public.get('active_biter_threat')
|
||||
local valid_enemy_forces = Public.get('valid_enemy_forces')
|
||||
|
||||
if active_biter_count >= 100 and #generated_units.active_biters <= 10 then
|
||||
Public.set('active_biter_count', 50)
|
||||
if active_biter_count < 0 then
|
||||
Public.set('active_biter_count', 0)
|
||||
Public.debug_print('Resetting active_biter_count')
|
||||
elseif active_biter_count > max_active_biters then
|
||||
Public.set('active_biter_count', max_active_biters)
|
||||
Public.debug_print('Resetting active_biter_count')
|
||||
end
|
||||
|
||||
local biter_health_boost = BiterHealthBooster.get('biter_health_boost')
|
||||
local max_biter_age = Public.get('max_biter_age')
|
||||
local tick = game.tick
|
||||
|
||||
for k, biter in pairs(generated_units.active_biters) do
|
||||
if not is_unit_valid(biter) then
|
||||
if not is_unit_valid(biter, max_biter_age, tick) then
|
||||
Public.set('active_biter_count', active_biter_count - 1)
|
||||
local entity = biter.entity
|
||||
if entity and entity.valid then
|
||||
|
@ -3,7 +3,6 @@ local Event = require 'utils.event'
|
||||
local BiterHealthBooster = require 'modules.biter_health_booster_v2'
|
||||
local Token = require 'utils.token'
|
||||
local Task = require 'utils.task'
|
||||
local Alert = require 'utils.alert'
|
||||
|
||||
local round = math.round
|
||||
local random = math.random
|
||||
|
@ -19,7 +19,7 @@
|
||||
-- end
|
||||
-- )
|
||||
--
|
||||
-- ** Event.add_removable(event_name, token) **
|
||||
-- ** Event.add_removable(event_name, token, event_reference) **
|
||||
--
|
||||
-- For conditional event handlers. Event.add_removable can be safely called at runtime without desync risk.
|
||||
-- Only use this if you need to add the handler at runtime or need to remove the handler, otherwise use Event.add
|
||||
@ -42,10 +42,10 @@
|
||||
-- )
|
||||
--
|
||||
-- The below code would typically be inside another event or a custom command.
|
||||
-- Event.add_removable(defines.events.on_built_entity, handler)
|
||||
-- Event.add_removable(defines.events.on_built_entity, handler, 'ref_to_find')
|
||||
--
|
||||
-- When you no longer need the handler.
|
||||
-- Event.remove_removable(defines.events.on_built_entity, handler)
|
||||
-- Event.remove_removable(defines.events.on_built_entity, handler, 'ref_to_find')
|
||||
--
|
||||
-- It's not an error to register the same token multiple times to the same event, however when
|
||||
-- removing only the first occurrence is removed.
|
||||
@ -234,7 +234,8 @@ end
|
||||
-- See documentation at top of file for details on using events.
|
||||
-- @param event_name<number>
|
||||
-- @param token<number>
|
||||
function Event.add_removable(event_name, token)
|
||||
-- @param event_reference<string>
|
||||
function Event.add_removable(event_name, token, event_reference)
|
||||
if type(token) ~= 'number' then
|
||||
error('token must be a number', 2)
|
||||
end
|
||||
@ -242,11 +243,12 @@ function Event.add_removable(event_name, token)
|
||||
error('cannot call during on_load', 2)
|
||||
end
|
||||
|
||||
local tokens = token_handlers[event_name]
|
||||
local tokens = token_handlers[event_reference]
|
||||
if not tokens then
|
||||
token_handlers[event_name] = {token}
|
||||
else
|
||||
tokens[#tokens + 1] = token
|
||||
token_handlers[event_reference] = {
|
||||
data = token,
|
||||
event_name = event_name
|
||||
}
|
||||
end
|
||||
|
||||
if handlers_added then
|
||||
@ -260,11 +262,12 @@ end
|
||||
-- See documentation at top of file for details on using events.
|
||||
-- @param event_name<number>
|
||||
-- @param token<number>
|
||||
function Event.remove_removable(event_name, token)
|
||||
-- @param event_reference<string>
|
||||
function Event.remove_removable(event_name, token, event_reference)
|
||||
if _LIFECYCLE == stage_load then
|
||||
error('cannot call during on_load', 2)
|
||||
end
|
||||
local tokens = token_handlers[event_name]
|
||||
local tokens = token_handlers[event_reference]
|
||||
|
||||
if not tokens then
|
||||
return
|
||||
@ -550,7 +553,7 @@ local function add_handlers()
|
||||
for event_name, tokens in pairs(token_handlers) do
|
||||
for i = 1, #tokens do
|
||||
local handler = Token.get(tokens[i])
|
||||
core_add(event_name, handler.data, handler.filter)
|
||||
core_add(event_name, handler.data)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -21,7 +21,8 @@ local data = {}
|
||||
local element_map = {}
|
||||
local settings = {
|
||||
mod_gui_top_frame = false,
|
||||
disabled_tabs = {}
|
||||
disabled_tabs = {},
|
||||
disable_clear_invalid_data = true
|
||||
}
|
||||
|
||||
Public.token =
|
||||
|
@ -13,7 +13,9 @@ local Global = require 'utils.global'
|
||||
local floor = math.floor
|
||||
local log10 = math.log10
|
||||
local Token_get = Token.get
|
||||
local pcall = pcall
|
||||
local xpcall = xpcall
|
||||
local trace = debug.traceback
|
||||
local log = log
|
||||
local Queue_peek = Queue.peek
|
||||
local Queue_pop = Queue.pop
|
||||
local Queue_push = Queue.push
|
||||
@ -47,6 +49,10 @@ Global.register(
|
||||
end
|
||||
)
|
||||
|
||||
local function handler_error(err)
|
||||
log('\n\t' .. trace(err))
|
||||
end
|
||||
|
||||
local function get_task_per_tick(tick)
|
||||
if tick % 300 == 0 then
|
||||
local size = primitives.total_task_weight
|
||||
@ -64,11 +70,11 @@ end
|
||||
local function on_tick()
|
||||
local tick = game.tick
|
||||
|
||||
for i = 1, get_task_per_tick(tick) do
|
||||
for _ = 1, get_task_per_tick(tick) do
|
||||
local task = Queue_peek(task_queue)
|
||||
if task ~= nil then
|
||||
-- result is error if not success else result is a boolean for if the task should stay in the queue.
|
||||
local success, result = pcall(Token_get(task.func_token), task.params)
|
||||
local success, result = xpcall(Token_get(task.func_token), handler_error, task.params)
|
||||
if not success then
|
||||
if _DEBUG then
|
||||
error(result)
|
||||
@ -86,14 +92,7 @@ local function on_tick()
|
||||
|
||||
local callback = PriorityQueue_peek(callbacks)
|
||||
while callback ~= nil and tick >= callback.time do
|
||||
local success, result = pcall(Token_get(callback.func_token), callback.params)
|
||||
if not success then
|
||||
if _DEBUG then
|
||||
error(result)
|
||||
else
|
||||
log(result)
|
||||
end
|
||||
end
|
||||
xpcall(Token_get(callback.func_token), handler_error, callback.params)
|
||||
PriorityQueue_pop(callbacks)
|
||||
callback = PriorityQueue_peek(callbacks)
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user