mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-01-04 00:15:45 +02:00
planet prison - fixes
This commit is contained in:
parent
5ffecd97b5
commit
1478bbbbff
@ -40,6 +40,17 @@ function Public.add_tab_to_gui(tbl)
|
||||
end
|
||||
end
|
||||
|
||||
--- This modifies a given gui
|
||||
--@param name <string>
|
||||
--@param state <boolean>
|
||||
function Public.modify_gui(name, state)
|
||||
if not main_gui_tabs[name] then
|
||||
return
|
||||
end
|
||||
|
||||
main_gui_tabs[name].disabled = state or false
|
||||
end
|
||||
|
||||
function Public.screen_to_bypass(elem)
|
||||
screen_elements[elem] = true
|
||||
return screen_elements
|
||||
@ -154,13 +165,23 @@ local function main_frame(player)
|
||||
tabbed_pane.add_tab(tab, name_frame)
|
||||
end
|
||||
else
|
||||
local tab = tabbed_pane.add({type = 'tab', caption = name, name = 'tab_' .. name})
|
||||
local name_frame = tabbed_pane.add({type = 'frame', name = name, direction = 'vertical'})
|
||||
name_frame.style.minimal_height = 480
|
||||
name_frame.style.maximal_height = 480
|
||||
name_frame.style.minimal_width = 800
|
||||
name_frame.style.maximal_width = 800
|
||||
tabbed_pane.add_tab(tab, name_frame)
|
||||
if not func.disabled then
|
||||
local tab = tabbed_pane.add({type = 'tab', caption = name, name = 'tab_' .. name})
|
||||
local name_frame = tabbed_pane.add({type = 'frame', name = name, direction = 'vertical'})
|
||||
name_frame.style.minimal_height = 480
|
||||
name_frame.style.maximal_height = 480
|
||||
name_frame.style.minimal_width = 800
|
||||
name_frame.style.maximal_width = 800
|
||||
tabbed_pane.add_tab(tab, name_frame)
|
||||
elseif player.admin then
|
||||
local tab = tabbed_pane.add({type = 'tab', caption = name, name = 'tab_' .. name})
|
||||
local name_frame = tabbed_pane.add({type = 'frame', name = name, direction = 'vertical'})
|
||||
name_frame.style.minimal_height = 480
|
||||
name_frame.style.maximal_height = 480
|
||||
name_frame.style.minimal_width = 800
|
||||
name_frame.style.maximal_width = 800
|
||||
tabbed_pane.add_tab(tab, name_frame)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -4,6 +4,8 @@
|
||||
local Global = require 'utils.global'
|
||||
local Session = require 'utils.datastore.session_data'
|
||||
local Event = require 'utils.event'
|
||||
local ComfyGui = require 'comfy_panel.main'
|
||||
local Freeplay = require 'utils.freeplay'
|
||||
local Server = require 'utils.server'
|
||||
local MapFuntions = require 'tools.map_functions'
|
||||
local CommonFunctions = require 'utils.common'
|
||||
@ -19,6 +21,9 @@ local Color = require 'utils.color_presets'
|
||||
-- require 'modules.thirst'
|
||||
|
||||
local this = {
|
||||
entities_cache = nil,
|
||||
active_surface = nil,
|
||||
last_friend = nil,
|
||||
remove_offline_players = {
|
||||
players = {},
|
||||
time = 216000, -- 1h
|
||||
@ -270,6 +275,88 @@ local industrial_zone_layers = {
|
||||
}
|
||||
}
|
||||
|
||||
local industrial_zone_layers_modded = {
|
||||
{
|
||||
type = 'LuaTile',
|
||||
name = 'concrete',
|
||||
objects = {
|
||||
'concrete'
|
||||
},
|
||||
elevation = 0.3,
|
||||
resolution = 0.2,
|
||||
hook = nil,
|
||||
deps = nil
|
||||
},
|
||||
{
|
||||
type = 'LuaTile',
|
||||
name = 'stones',
|
||||
objects = {
|
||||
'stone-path'
|
||||
},
|
||||
elevation = 0.2,
|
||||
resolution = 0.4,
|
||||
hook = nil,
|
||||
deps = nil
|
||||
},
|
||||
{
|
||||
type = 'LuaTile',
|
||||
name = 'shallows',
|
||||
objects = {
|
||||
'water-shallow'
|
||||
},
|
||||
elevation = 0.7,
|
||||
resolution = 0.01,
|
||||
hook = nil,
|
||||
deps = nil
|
||||
},
|
||||
{
|
||||
type = 'LuaEntity',
|
||||
name = 'scrap',
|
||||
objects = {
|
||||
'mineable-wreckage'
|
||||
},
|
||||
elevation = 0.5,
|
||||
resolution = 0.1,
|
||||
hook = set_neutral_to_entity,
|
||||
deps = nil
|
||||
},
|
||||
{
|
||||
type = 'LuaEntity',
|
||||
name = 'walls',
|
||||
objects = {
|
||||
'stone-wall'
|
||||
},
|
||||
elevation = 0.5,
|
||||
resolution = 0.09,
|
||||
hook = set_neutral_to_entity,
|
||||
deps = nil
|
||||
},
|
||||
{
|
||||
type = 'LuaEntity',
|
||||
name = 'hostile',
|
||||
objects = {
|
||||
'character',
|
||||
'gun-turret'
|
||||
},
|
||||
elevation = 0.92,
|
||||
resolution = 0.99,
|
||||
hook = set_noise_hostile_hook,
|
||||
deps = fetch_common
|
||||
},
|
||||
{
|
||||
type = 'LuaEntity',
|
||||
name = 'structures',
|
||||
objects = {
|
||||
'big-electric-pole',
|
||||
'medium-electric-pole'
|
||||
},
|
||||
elevation = 0.9,
|
||||
resolution = 0.9,
|
||||
hook = set_neutral_to_entity,
|
||||
deps = nil
|
||||
}
|
||||
}
|
||||
|
||||
local swampy_rivers_layers = {
|
||||
{
|
||||
type = 'LuaTile',
|
||||
@ -359,9 +446,11 @@ this.presets = {
|
||||
['swampy-rivers'] = swampy_rivers_layers
|
||||
}
|
||||
|
||||
this.entities_cache = nil
|
||||
this.surface = nil
|
||||
this.last_friend = nil
|
||||
this.presets_modded = {
|
||||
['flooded-metropolia'] = industrial_zone_layers_modded,
|
||||
['swampy-rivers'] = swampy_rivers_layers
|
||||
}
|
||||
|
||||
local function pick_map()
|
||||
return this.maps[CommonFunctions.rand_range(1, #this.maps)]
|
||||
end
|
||||
@ -430,18 +519,26 @@ this.bp = {
|
||||
merchant = require('planet_prison.bp.merchant')
|
||||
}
|
||||
local function init_game()
|
||||
Freeplay.set('disabled', true)
|
||||
ComfyGui.modify_gui('Players', true)
|
||||
LayersFunctions.init()
|
||||
ClaimsFunctions.init(MapConfig.claim_markers, MapConfig.claim_max_distance)
|
||||
|
||||
local map = pick_map()
|
||||
local preset = this.presets[map.name]
|
||||
this.surface = game.create_surface('arena', map)
|
||||
this.surface.brightness_visual_weights = {
|
||||
local preset
|
||||
if is_game_modded() then
|
||||
preset = this.presets_modded[map.name]
|
||||
else
|
||||
preset = this.presets[map.name]
|
||||
end
|
||||
local surface = game.create_surface('arena', map)
|
||||
surface.brightness_visual_weights = {
|
||||
1 / 0.85,
|
||||
1 / 0.85,
|
||||
1 / 0.85
|
||||
}
|
||||
this.surface.ticks_per_day = 25000 * 4
|
||||
surface.ticks_per_day = 25000 * 4
|
||||
this.active_surface = surface.index
|
||||
this.perks = {}
|
||||
this.events.merchant.spawn_tick = game.tick + 5000
|
||||
this.events.raid_groups = {}
|
||||
@ -507,7 +604,12 @@ local explode_ship =
|
||||
function(data)
|
||||
local ship = data.ship
|
||||
local id = data.id
|
||||
local surface = data.surface
|
||||
local active_surface = data.active_surface
|
||||
local surface = game.get_surface(active_surface)
|
||||
if not surface or not surface.valid then
|
||||
return
|
||||
end
|
||||
|
||||
for _, ent in pairs(Blueprints.reference_get_entities(ship)) do
|
||||
if not ent.valid then
|
||||
goto continue
|
||||
@ -554,7 +656,7 @@ local function do_spawn_point(player)
|
||||
}
|
||||
|
||||
local id = rendering.draw_text(object)
|
||||
local data = {id = id, time_left = time_left, ship = instance, surface = player.surface}
|
||||
local data = {id = id, time_left = time_left, ship = instance, active_surface = player.surface.index}
|
||||
|
||||
local timer = Timers.set_timer(time_left, explode_ship)
|
||||
Timers.set_timer_on_update(timer, explode_ship_update)
|
||||
@ -986,7 +1088,6 @@ local function _calculate_attack_costs(surf, bb)
|
||||
}
|
||||
local objects = surf.find_entities_filtered(query)
|
||||
if next(objects) == nil then
|
||||
log('B')
|
||||
return 0
|
||||
end
|
||||
|
||||
@ -1230,7 +1331,7 @@ local function cause_event(s)
|
||||
end
|
||||
|
||||
local function on_tick()
|
||||
local s = this.surface
|
||||
local s = this.active_surface
|
||||
if not s then
|
||||
log('on_tick: surface empty!')
|
||||
return
|
||||
@ -1238,7 +1339,7 @@ local function on_tick()
|
||||
|
||||
local tick = game.tick
|
||||
|
||||
local surf = this.surface
|
||||
local surf = game.get_surface(this.active_surface)
|
||||
if not surf or not surf.valid then
|
||||
return
|
||||
end
|
||||
@ -1248,7 +1349,7 @@ local function on_tick()
|
||||
end
|
||||
|
||||
LayersFunctions.do_job(surf)
|
||||
cause_event(s)
|
||||
cause_event(surf)
|
||||
|
||||
if (tick + 1) % 60 == 0 then
|
||||
Timers.do_job()
|
||||
@ -1291,6 +1392,7 @@ local valid_ents = {
|
||||
['crash-site-spaceship-wreck-small-4'] = true,
|
||||
['crash-site-spaceship-wreck-small-5'] = true,
|
||||
['crash-site-spaceship-wreck-small-6'] = true,
|
||||
['mineable-wreckage'] = true,
|
||||
['sand-rock-big'] = true,
|
||||
['rock-big'] = true,
|
||||
['rock-huge'] = true
|
||||
@ -1754,7 +1856,11 @@ local function move_to_orbit(player)
|
||||
end
|
||||
|
||||
local function on_rocket_launched(e)
|
||||
local surf = this.surface
|
||||
local surf = game.get_surface(this.active_surface)
|
||||
if not surf or not surf.valid then
|
||||
return
|
||||
end
|
||||
|
||||
local pid = e.player_index
|
||||
surf.print('>> The rocket was launched')
|
||||
if pid == nil then
|
||||
|
@ -1,4 +1,4 @@
|
||||
local CommonFunctions = require 'maps.planet_prison.mod.common'
|
||||
local CommonFunctions = require 'utils.common'
|
||||
local Global = require 'utils.global'
|
||||
local Token = require 'utils.token'
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
local CommonFunctions = require 'maps.planet_prison.mod.common'
|
||||
local CommonFunctions = require 'utils.common'
|
||||
local Global = require 'utils.global'
|
||||
|
||||
local Public = {}
|
||||
|
@ -1,4 +1,4 @@
|
||||
local CommonFunctions = require 'maps.planet_prison.mod.common'
|
||||
local CommonFunctions = require 'utils.common'
|
||||
local SimplexFunctions = require 'maps.planet_prison.mod.simplex_noise'
|
||||
local Token = require 'utils.token'
|
||||
local Global = require 'utils.global'
|
||||
|
@ -1,7 +1,7 @@
|
||||
-- Original implementation taken from here https://github.com/thenumbernine/lua-simplexnoise/blob/master/2d.lua
|
||||
|
||||
local Global = require 'utils.global'
|
||||
local CommonFunctions = require 'maps.planet_prison.mod.common'
|
||||
local CommonFunctions = require 'utils.common'
|
||||
|
||||
local Public = {}
|
||||
local this = {}
|
||||
|
42
utils/ai.lua
42
utils/ai.lua
@ -109,7 +109,7 @@ end
|
||||
|
||||
local function _shoot_at(ent, trgt)
|
||||
ent.shooting_state = {
|
||||
state = defines.shooting.shooting_selected,
|
||||
state = defines.shooting.shooting_enemies,
|
||||
position = trgt.position
|
||||
}
|
||||
end
|
||||
@ -137,7 +137,11 @@ local function set_noise_hostile_hook(ent)
|
||||
end
|
||||
|
||||
local function _do_job_seek_and_destroy_player(data)
|
||||
local surf = data.surface
|
||||
local active_surface = data.active_surface
|
||||
local surf = game.get_surface(active_surface)
|
||||
if not surf or not surf.valid then
|
||||
return
|
||||
end
|
||||
local force = data.force
|
||||
local players = game.connected_players
|
||||
|
||||
@ -188,8 +192,13 @@ local function _do_job_seek_and_destroy_player(data)
|
||||
end
|
||||
|
||||
local function _do_job_attack_objects(data)
|
||||
local surf = data.surface
|
||||
local active_surface = data.active_surface
|
||||
local surf = game.get_surface(active_surface)
|
||||
if not surf or not surf.valid then
|
||||
return
|
||||
end
|
||||
local force = data.force
|
||||
local args = data.args
|
||||
local position = data.position
|
||||
|
||||
if type(surf) == 'number' then
|
||||
@ -241,7 +250,16 @@ local function _do_job_attack_objects(data)
|
||||
if #closest ~= 0 then
|
||||
target = CommonFunctions.get_closest_neighbour(agent.position, closest)
|
||||
else
|
||||
goto continue
|
||||
if not args or not args.objects then
|
||||
goto continue
|
||||
end
|
||||
|
||||
if #args.objects == 0 then
|
||||
_shoot_stop(agent)
|
||||
goto continue
|
||||
end
|
||||
|
||||
target = CommonFunctions.get_closest_neighbour(agent.position, args.objects)
|
||||
end
|
||||
|
||||
if target == nil or not target.valid then
|
||||
@ -311,10 +329,22 @@ Public.do_job = function(surf, command, args, force)
|
||||
args = {}
|
||||
end
|
||||
|
||||
if not surf and not surf.valid then
|
||||
return
|
||||
end
|
||||
|
||||
if command == Public.command.seek_and_destroy_player then
|
||||
_do_job_seek_and_destroy_player(surf, force)
|
||||
local data = {
|
||||
active_surface = surf.index,
|
||||
force = force
|
||||
}
|
||||
_do_job_seek_and_destroy_player(data)
|
||||
elseif command == Public.command.attack_objects then
|
||||
_do_job_attack_objects(surf, args)
|
||||
local data = {
|
||||
active_surface = surf.index,
|
||||
args = args
|
||||
}
|
||||
_do_job_attack_objects(data)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
local Global = require 'utils.global'
|
||||
local Event = require 'utils.event'
|
||||
|
||||
local Public = {}
|
||||
|
||||
local this = {
|
||||
created_items = {},
|
||||
respawn_items = {},
|
||||
disabled = false,
|
||||
skip_intro = true,
|
||||
chart_distance = 0,
|
||||
disable_crashsite = true,
|
||||
@ -74,6 +77,9 @@ local on_player_created = function(event)
|
||||
if not this.modded then
|
||||
return
|
||||
end
|
||||
if this.disabled then
|
||||
return
|
||||
end
|
||||
local player = game.get_player(event.player_index)
|
||||
util.insert_safe(player, this.created_items)
|
||||
|
||||
@ -103,6 +109,9 @@ local on_player_respawned = function(event)
|
||||
if not this.modded then
|
||||
return
|
||||
end
|
||||
if this.disabled then
|
||||
return
|
||||
end
|
||||
local player = game.players[event.player_index]
|
||||
util.insert_safe(player, this.respawn_items)
|
||||
end
|
||||
@ -111,6 +120,9 @@ local on_cutscene_waypoint_reached = function(event)
|
||||
if not this.modded then
|
||||
return
|
||||
end
|
||||
if this.disabled then
|
||||
return
|
||||
end
|
||||
if not crash_site.is_crash_site_cutscene(event) then
|
||||
return
|
||||
end
|
||||
@ -131,6 +143,10 @@ local skip_crash_site_cutscene = function(event)
|
||||
return
|
||||
end
|
||||
|
||||
if this.disabled then
|
||||
return
|
||||
end
|
||||
|
||||
if event.player_index ~= 1 then
|
||||
return
|
||||
end
|
||||
@ -154,6 +170,10 @@ local on_cutscene_cancelled = function(event)
|
||||
return
|
||||
end
|
||||
|
||||
if this.disabled 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()
|
||||
@ -208,6 +228,25 @@ if not remote.interfaces['freeplay'] then
|
||||
remote.add_interface('freeplay', freeplay_interface)
|
||||
end
|
||||
|
||||
function Public.get(key)
|
||||
if key then
|
||||
return this[key]
|
||||
else
|
||||
return this
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
Event.on_init(
|
||||
function()
|
||||
local game_has_mods = is_game_modded()
|
||||
@ -240,3 +279,5 @@ 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)
|
||||
|
||||
return Public
|
||||
|
Loading…
Reference in New Issue
Block a user