mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2024-12-30 23:17:53 +02:00
minor adjustments
added support for when mods try to call freeplay fixes for mountain fortress added more info to wave_defense module
This commit is contained in:
parent
33fa5f5826
commit
853bfa1659
@ -7,6 +7,7 @@ require 'utils.server'
|
||||
require 'utils.server_commands'
|
||||
require 'utils.utils'
|
||||
require 'utils.table'
|
||||
require 'utils.freeplay'
|
||||
require 'utils.datastore.color_data'
|
||||
require 'utils.datastore.session_data'
|
||||
require 'utils.datastore.jail_data'
|
||||
|
@ -41,7 +41,7 @@ flamethrowers_placed=Amount of flamethrower-turrets that can be built.
|
||||
train_upgrades=Amount of train upgrades.
|
||||
info_tooltip=Shows statistics!
|
||||
hide_minimap=Hide locomotive minimap!
|
||||
current_pickaxe_tier=The team currently has the __1__ pickaxe tier.
|
||||
current_pickaxe_tier=The team currently has the __1__ pickaxe tier.\nBonus speed is: __2__%
|
||||
|
||||
[locomotive]
|
||||
upgrades=Upgrades:
|
||||
|
@ -41,7 +41,7 @@ flamethrowers_placed=Amount of flamethrower-turrets that can be built.
|
||||
train_upgrades=Amount of train upgrades.
|
||||
info_tooltip=Shows statistics!
|
||||
hide_minimap=Hide locomotive minimap!
|
||||
current_pickaxe_tier=The team currently has the __1__ pickaxe tier.
|
||||
current_pickaxe_tier=The team currently has the __1__ pickaxe tier.\nBonus speed is: __2__%
|
||||
|
||||
[locomotive]
|
||||
upgrades=Upgrades:
|
||||
|
@ -41,7 +41,7 @@ flamethrowers_placed=Amount of flamethrower-turrets that can be built.
|
||||
train_upgrades=Amount of train upgrades.
|
||||
info_tooltip=Shows statistics!
|
||||
hide_minimap=Hide locomotive minimap!
|
||||
current_pickaxe_tier=The team currently has the __1__ pickaxe tier.
|
||||
current_pickaxe_tier=The team currently has the __1__ pickaxe tier.\nBonus speed is: __2__%
|
||||
|
||||
[locomotive]
|
||||
upgrades=Upgrades:
|
||||
|
@ -339,9 +339,11 @@ function Public.update_gui(player)
|
||||
local pickaxe_tiers = WPT.pickaxe_upgrades
|
||||
local tier = WPT.get('pickaxe_tier')
|
||||
local pick_tier = pickaxe_tiers[tier]
|
||||
local speed =
|
||||
math.round((player.force.manual_mining_speed_modifier + player.character_mining_speed_modifier + 1) * 100)
|
||||
|
||||
gui.pickaxe_tier.caption = ' [img=item.dummy-steel-axe]: ' .. pick_tier
|
||||
gui.pickaxe_tier.tooltip = ({'gui.current_pickaxe_tier', pick_tier})
|
||||
gui.pickaxe_tier.tooltip = ({'gui.current_pickaxe_tier', pick_tier, speed})
|
||||
|
||||
gui.biters_killed.caption = ' [img=entity.small-biter]: ' .. format_number(this.biters_killed, true)
|
||||
gui.biters_killed.tooltip = ({'gui.biters_killed'})
|
||||
|
@ -962,7 +962,10 @@ local function gui_click(event)
|
||||
}
|
||||
)
|
||||
|
||||
game.forces.player.manual_mining_speed_modifier = -0.25 + tier * 0.25
|
||||
game.forces.player.manual_mining_speed_modifier = game.forces.player.manual_mining_speed_modifier + 0.25
|
||||
|
||||
local force_mining_speed = WPT.get('force_mining_speed')
|
||||
force_mining_speed.speed = game.forces.player.manual_mining_speed_modifier
|
||||
|
||||
redraw_market_items(data.item_frame, player, data.search_text)
|
||||
redraw_coins_left(data.coins_left, player)
|
||||
|
@ -529,12 +529,8 @@ local on_research_finished = function(event)
|
||||
local mining_speed_bonus = game.forces.player.mining_drill_productivity_bonus * 5 -- +50% speed / level
|
||||
if research.force.technologies['steel-axe'].researched then
|
||||
mining_speed_bonus = mining_speed_bonus + 0.5
|
||||
research.force.manual_mining_speed_modifier = mining_speed_bonus + this.force_mining_speed.speed
|
||||
end -- +50% speed for steel-axe research
|
||||
if this.breached_wall <= 2 then
|
||||
research.force.manual_mining_speed_modifier = this.force_mining_speed.speed + mining_speed_bonus
|
||||
else
|
||||
research.force.manual_mining_speed_modifier = mining_speed_bonus
|
||||
end
|
||||
|
||||
local force_name = research.force.name
|
||||
if not force_name then
|
||||
|
@ -81,7 +81,11 @@ local function update_gui(player)
|
||||
gui.threat.caption = {'wave_defense.gui_3'}
|
||||
gui.threat.tooltip = {'wave_defense.tooltip_1', biter_health_boost * 100, wave_defense_table.max_active_biters}
|
||||
gui.threat_value.caption = math.floor(wave_defense_table.threat)
|
||||
gui.threat_value.tooltip = {'wave_defense.tooltip_1', biter_health_boost * 100}
|
||||
gui.threat_value.tooltip = {
|
||||
'wave_defense.tooltip_1',
|
||||
biter_health_boost * 100,
|
||||
wave_defense_table.max_active_biters
|
||||
}
|
||||
|
||||
if wave_defense_table.wave_number == 0 then
|
||||
gui.threat_gains.caption = ''
|
||||
|
@ -594,11 +594,13 @@ local function command_unit_group(group)
|
||||
if not this.unit_group_last_command[group.group_number] then
|
||||
this.unit_group_last_command[group.group_number] = game.tick - (this.unit_group_command_delay + 1)
|
||||
end
|
||||
|
||||
if this.unit_group_last_command[group.group_number] then
|
||||
if this.unit_group_last_command[group.group_number] + this.unit_group_command_delay > game.tick then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local tile = group.surface.get_tile(group.position)
|
||||
if tile.valid and tile.collides_with('player-layer') then
|
||||
group = reform_group(group)
|
||||
@ -716,20 +718,6 @@ local function log_threat()
|
||||
end
|
||||
end
|
||||
|
||||
local function clear_tables()
|
||||
local this = WD.get()
|
||||
this.unit_group_last_command = {}
|
||||
for k, groups in next, this.active_biters do
|
||||
for _, entity in next, groups do
|
||||
if type(entity) == 'table' then
|
||||
if not entity or not entity.valid then
|
||||
this.active_biters[k] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local tick_tasks = {
|
||||
[30] = set_main_target,
|
||||
[60] = set_enemy_evolution,
|
||||
@ -738,8 +726,7 @@ local tick_tasks = {
|
||||
[150] = ThreatEvent.build_nest,
|
||||
[180] = ThreatEvent.build_worm,
|
||||
[3600] = time_out_biters,
|
||||
[7200] = refresh_active_unit_threat,
|
||||
[7400] = clear_tables
|
||||
[7200] = refresh_active_unit_threat
|
||||
}
|
||||
|
||||
local function on_tick()
|
||||
|
@ -119,31 +119,38 @@ local create_gulag_surface = function()
|
||||
if not surface then
|
||||
local walls = {}
|
||||
local tiles = {}
|
||||
surface =
|
||||
game.create_surface(
|
||||
'gulag',
|
||||
{
|
||||
autoplace_controls = {
|
||||
['coal'] = {frequency = 23, size = 3, richness = 3},
|
||||
['stone'] = {frequency = 20, size = 3, richness = 3},
|
||||
['copper-ore'] = {frequency = 25, size = 3, richness = 3},
|
||||
['iron-ore'] = {frequency = 35, size = 3, richness = 3},
|
||||
['uranium-ore'] = {frequency = 20, size = 3, richness = 3},
|
||||
['crude-oil'] = {frequency = 80, size = 3, richness = 1},
|
||||
['trees'] = {frequency = 0.75, size = 2, richness = 0.1},
|
||||
['enemy-base'] = {frequency = 15, size = 0, richness = 1}
|
||||
},
|
||||
cliff_settings = {cliff_elevation_0 = 1024, cliff_elevation_interval = 10, name = 'cliff'},
|
||||
height = 64,
|
||||
width = 256,
|
||||
peaceful_mode = false,
|
||||
seed = 1337,
|
||||
starting_area = 'very-low',
|
||||
starting_points = {{x = 0, y = 0}},
|
||||
terrain_segmentation = 'normal',
|
||||
water = 'normal'
|
||||
}
|
||||
pcall(
|
||||
function()
|
||||
surface =
|
||||
game.create_surface(
|
||||
'gulag',
|
||||
{
|
||||
autoplace_controls = {
|
||||
['coal'] = {frequency = 23, size = 3, richness = 3},
|
||||
['stone'] = {frequency = 20, size = 3, richness = 3},
|
||||
['copper-ore'] = {frequency = 25, size = 3, richness = 3},
|
||||
['iron-ore'] = {frequency = 35, size = 3, richness = 3},
|
||||
['uranium-ore'] = {frequency = 20, size = 3, richness = 3},
|
||||
['crude-oil'] = {frequency = 80, size = 3, richness = 1},
|
||||
['trees'] = {frequency = 0.75, size = 2, richness = 0.1},
|
||||
['enemy-base'] = {frequency = 15, size = 0, richness = 1}
|
||||
},
|
||||
cliff_settings = {cliff_elevation_0 = 1024, cliff_elevation_interval = 10, name = 'cliff'},
|
||||
height = 64,
|
||||
width = 256,
|
||||
peaceful_mode = false,
|
||||
seed = 1337,
|
||||
starting_area = 'very-low',
|
||||
starting_points = {{x = 0, y = 0}},
|
||||
terrain_segmentation = 'normal',
|
||||
water = 'normal'
|
||||
}
|
||||
)
|
||||
end
|
||||
)
|
||||
if not surface then
|
||||
surface = game.create_surface('gulag', {width = 40, height = 40})
|
||||
end
|
||||
surface.always_day = true
|
||||
surface.request_to_generate_chunks({0, 0}, 9)
|
||||
surface.force_generate_chunk_requests()
|
||||
|
@ -11,6 +11,15 @@ local event_handlers = {}
|
||||
-- map of nth_tick to handlers[]
|
||||
local on_nth_tick_event_handlers = {}
|
||||
|
||||
--[[ local interface = {
|
||||
get_handler = function()
|
||||
return event_handlers
|
||||
end
|
||||
}
|
||||
|
||||
if not remote.interfaces['interface'] then
|
||||
remote.add_interface('interface', interface)
|
||||
end ]]
|
||||
local pcall = pcall
|
||||
local log = log
|
||||
local script_on_event = script.on_event
|
||||
@ -19,6 +28,9 @@ local script_on_nth_tick = script.on_nth_tick
|
||||
local call_handlers
|
||||
if _DEBUG then
|
||||
function call_handlers(handlers, event)
|
||||
if not handlers then
|
||||
return log('Handlers was nil!')
|
||||
end
|
||||
for i = 1, #handlers do
|
||||
local handler = handlers[i]
|
||||
handler(event)
|
||||
@ -26,6 +38,9 @@ if _DEBUG then
|
||||
end
|
||||
else
|
||||
function call_handlers(handlers, event)
|
||||
if not handlers then
|
||||
return log('Handlers was nil!')
|
||||
end
|
||||
for i = 1, #handlers do
|
||||
local handler = handlers[i]
|
||||
local success, error = pcall(handler, event)
|
||||
@ -38,6 +53,9 @@ end
|
||||
|
||||
local function on_event(event)
|
||||
local handlers = event_handlers[event.name]
|
||||
if not handlers then
|
||||
handlers = event_handlers[event.input_name]
|
||||
end
|
||||
call_handlers(handlers, event)
|
||||
end
|
||||
|
||||
|
224
utils/freeplay.lua
Normal file
224
utils/freeplay.lua
Normal file
@ -0,0 +1,224 @@
|
||||
local Global = require 'utils.global'
|
||||
local Event = require 'utils.event'
|
||||
|
||||
local this = {
|
||||
created_items = {},
|
||||
respawn_items = {},
|
||||
skip_intro = true,
|
||||
chart_distance = 0,
|
||||
disable_crashsite = true,
|
||||
crashed_ship_items = {},
|
||||
crashed_debris_items = {}
|
||||
}
|
||||
|
||||
Global.register(
|
||||
this,
|
||||
function(t)
|
||||
this = t
|
||||
end
|
||||
)
|
||||
|
||||
local util = require('util')
|
||||
local crash_site = require('crash-site')
|
||||
|
||||
local created_items = function()
|
||||
return {
|
||||
['iron-plate'] = 8,
|
||||
['wood'] = 1,
|
||||
['pistol'] = 1,
|
||||
['firearm-magazine'] = 10,
|
||||
['burner-mining-drill'] = 1,
|
||||
['stone-furnace'] = 1
|
||||
}
|
||||
end
|
||||
|
||||
local respawn_items = function()
|
||||
return {
|
||||
['pistol'] = 1,
|
||||
['firearm-magazine'] = 10
|
||||
}
|
||||
end
|
||||
|
||||
local ship_items = function()
|
||||
return {
|
||||
['firearm-magazine'] = 8
|
||||
}
|
||||
end
|
||||
|
||||
local debris_items = function()
|
||||
return {
|
||||
['iron-plate'] = 8
|
||||
}
|
||||
end
|
||||
|
||||
local chart_starting_area = function()
|
||||
local r = this.chart_distance or 200
|
||||
local force = game.forces.player
|
||||
local surface = game.surfaces[1]
|
||||
local origin = force.get_spawn_position(surface)
|
||||
force.chart(surface, {{origin.x - r, origin.y - r}, {origin.x + r, origin.y + r}})
|
||||
end
|
||||
|
||||
local on_player_created = function(event)
|
||||
if not this.modded then
|
||||
return
|
||||
end
|
||||
local player = game.get_player(event.player_index)
|
||||
util.insert_safe(player, this.created_items)
|
||||
|
||||
if not this.init_ran then
|
||||
--This is so that other mods and scripts have a chance to do remote calls before we do things like charting the starting area, creating the crash site, etc.
|
||||
this.init_ran = true
|
||||
|
||||
chart_starting_area()
|
||||
|
||||
if not this.disable_crashsite then
|
||||
local surface = player.surface
|
||||
surface.daytime = 0.7
|
||||
crash_site.create_crash_site(
|
||||
surface,
|
||||
{-5, -6},
|
||||
util.copy(this.crashed_ship_items),
|
||||
util.copy(this.crashed_debris_items)
|
||||
)
|
||||
util.remove_safe(player, this.crashed_ship_items)
|
||||
util.remove_safe(player, this.crashed_debris_items)
|
||||
player.get_main_inventory().sort_and_merge()
|
||||
if player.character then
|
||||
player.character.destructible = false
|
||||
end
|
||||
crash_site.create_cutscene(player, {-5, -4})
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local on_player_respawned = function(event)
|
||||
if not this.modded then
|
||||
return
|
||||
end
|
||||
local player = game.players[event.player_index]
|
||||
util.insert_safe(player, this.respawn_items)
|
||||
end
|
||||
|
||||
local on_cutscene_waypoint_reached = function(event)
|
||||
if not this.modded then
|
||||
return
|
||||
end
|
||||
if not crash_site.is_crash_site_cutscene(event) then
|
||||
return
|
||||
end
|
||||
|
||||
local player = game.get_player(event.player_index)
|
||||
|
||||
player.exit_cutscene()
|
||||
end
|
||||
|
||||
local skip_crash_site_cutscene = function(event)
|
||||
if not this.modded then
|
||||
return
|
||||
end
|
||||
|
||||
if event.player_index ~= 1 then
|
||||
return
|
||||
end
|
||||
if event.tick > 2000 then
|
||||
return
|
||||
end
|
||||
|
||||
local player = game.get_player(event.player_index)
|
||||
if player.controller_type == defines.controllers.cutscene then
|
||||
player.exit_cutscene()
|
||||
end
|
||||
end
|
||||
|
||||
local on_cutscene_cancelled = function(event)
|
||||
if not this.modded then
|
||||
return
|
||||
end
|
||||
|
||||
local player = game.get_player(event.player_index)
|
||||
if player.gui.screen.skip_cutscene_label then
|
||||
player.gui.screen.skip_cutscene_label.destroy()
|
||||
end
|
||||
if player.character then
|
||||
player.character.destructible = true
|
||||
end
|
||||
player.zoom = 1.5
|
||||
end
|
||||
|
||||
local freeplay_interface = {
|
||||
get_created_items = function()
|
||||
return this.created_items
|
||||
end,
|
||||
set_created_items = function(map)
|
||||
this.created_items = map or error("Remote call parameter to freeplay set created items can't be nil.")
|
||||
end,
|
||||
get_respawn_items = function()
|
||||
return this.respawn_items
|
||||
end,
|
||||
set_respawn_items = function(map)
|
||||
this.respawn_items = map or error("Remote call parameter to freeplay set respawn items can't be nil.")
|
||||
end,
|
||||
set_skip_intro = function(bool)
|
||||
this.skip_intro = bool
|
||||
end,
|
||||
set_chart_distance = function(value)
|
||||
this.chart_distance =
|
||||
tonumber(value) or error('Remote call parameter to freeplay set chart distance must be a number')
|
||||
end,
|
||||
set_disable_crashsite = function(bool)
|
||||
this.disable_crashsite = bool
|
||||
end,
|
||||
get_ship_items = function()
|
||||
return this.crashed_ship_items
|
||||
end,
|
||||
set_ship_items = function(map)
|
||||
this.crashed_ship_items = map or error("Remote call parameter to freeplay set created items can't be nil.")
|
||||
end,
|
||||
get_debris_items = function()
|
||||
return this.crashed_debris_items
|
||||
end,
|
||||
set_debris_items = function(map)
|
||||
this.crashed_debris_items = map or error("Remote call parameter to freeplay set respawn items can't be nil.")
|
||||
end
|
||||
}
|
||||
|
||||
if not remote.interfaces['freeplay'] then
|
||||
remote.add_interface('freeplay', freeplay_interface)
|
||||
end
|
||||
|
||||
Event.on_init(
|
||||
function()
|
||||
local i = 0
|
||||
for k, _ in pairs(game.active_mods) do
|
||||
i = i + 1
|
||||
if i > 1 then
|
||||
this.modded = true
|
||||
this.disable_crashsite = false
|
||||
this.created_items = created_items()
|
||||
this.respawn_items = respawn_items()
|
||||
this.crashed_ship_items = ship_items()
|
||||
this.crashed_debris_items = debris_items()
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
Event.on_configuration_changed = function()
|
||||
this.created_items = this.created_items or created_items()
|
||||
this.respawn_items = this.respawn_items or respawn_items()
|
||||
this.crashed_ship_items = this.crashed_ship_items or ship_items()
|
||||
this.crashed_debris_items = this.crashed_debris_items or debris_items()
|
||||
|
||||
if not this.init_ran then
|
||||
this.init_ran = #game.players > 0
|
||||
end
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_player_created, on_player_created)
|
||||
Event.add(defines.events.on_player_respawned, on_player_respawned)
|
||||
Event.add(defines.events.on_cutscene_waypoint_reached, on_cutscene_waypoint_reached)
|
||||
Event.add('crash-site-skip-cutscene', skip_crash_site_cutscene)
|
||||
Event.add(defines.events.on_cutscene_cancelled, on_cutscene_cancelled)
|
Loading…
Reference in New Issue
Block a user