From 8e3c8cc1eaab05c8092821c10a811bff0fdb2623 Mon Sep 17 00:00:00 2001 From: hanakocz Date: Tue, 17 Mar 2020 21:36:00 +0100 Subject: [PATCH] mini fixes + new admin tab --- comfy_panel/main.lua | 4 +- control.lua | 4 +- maps/chronosphere/config_tab.lua | 97 ++++++++++++++++++++++++++++ maps/chronosphere/main.lua | 2 +- maps/chronosphere/terrain.lua | 8 +-- maps/chronosphere/tick_functions.lua | 8 ++- 6 files changed, 112 insertions(+), 11 deletions(-) create mode 100644 maps/chronosphere/config_tab.lua diff --git a/comfy_panel/main.lua b/comfy_panel/main.lua index 0c1f7c79..e3e1b014 100644 --- a/comfy_panel/main.lua +++ b/comfy_panel/main.lua @@ -36,13 +36,13 @@ end function Public.comfy_panel_get_active_frame(player) if not player.gui.left.comfy_panel then return false end if not player.gui.left.comfy_panel.tabbed_pane.selected_tab_index then return player.gui.left.comfy_panel.tabbed_pane.tabs[1].content end - return player.gui.left.comfy_panel.tabbed_pane.tabs[player.gui.left.comfy_panel.tabbed_pane.selected_tab_index].content + return player.gui.left.comfy_panel.tabbed_pane.tabs[player.gui.left.comfy_panel.tabbed_pane.selected_tab_index].content end function Public.comfy_panel_refresh_active_tab(player) local frame = Public.comfy_panel_get_active_frame(player) if not frame then return end - comfy_panel_tabs[frame.name](player, frame) + comfy_panel_tabs[frame.name].gui(player, frame) end local function top_button(player) diff --git a/control.lua b/control.lua index 6e640b29..38bfd29d 100644 --- a/control.lua +++ b/control.lua @@ -126,8 +126,8 @@ require "maps.chronosphere.main" --require "modules.trees_grow" --require "modules.trees_randomly_die" ---require "terrain_layouts.scrap_01" ---require "terrain_layouts.caves" +--require "terrain_layouts.scrap_01" +--require "terrain_layouts.caves" --require "terrain_layouts.cone_to_east" --require "terrain_layouts.biters_and_resources_east" ------ diff --git a/maps/chronosphere/config_tab.lua b/maps/chronosphere/config_tab.lua new file mode 100644 index 00000000..256d19ad --- /dev/null +++ b/maps/chronosphere/config_tab.lua @@ -0,0 +1,97 @@ +-- config tab for chronotrain-- + +local Tabs = require 'comfy_panel.main' + +local functions = { + ["comfy_panel_offline_accidents"] = function(event) + if game.players[event.player_index].admin then + if event.element.switch_state == "left" then + global.objective.config.offline_loot = true + else + global.objective.config.offline_loot = false + end + else + game.players[event.player_index].print("You are not admin!") + end + end, + + ["comfy_panel_danger_events"] = function(event) + if game.players[event.player_index].admin then + if event.element.switch_state == "left" then + global.objective.config.jumpfailure = true + else + global.objective.config.jumpfailure = false + end + else + game.players[event.player_index].print("You are not admin!") + end + end, +} + +local function add_switch(element, switch_state, name, description_main, description) + local t = element.add({type = "table", column_count = 5}) + local label = t.add({type = "label", caption = "ON"}) + label.style.padding = 0 + label.style.left_padding= 10 + label.style.font_color = {0.77, 0.77, 0.77} + local switch = t.add({type = "switch", name = name}) + switch.switch_state = switch_state + switch.style.padding = 0 + switch.style.margin = 0 + local label = t.add({type = "label", caption = "OFF"}) + label.style.padding = 0 + label.style.font_color = {0.70, 0.70, 0.70} + + local label = t.add({type = "label", caption = description_main}) + label.style.padding = 2 + label.style.left_padding= 10 + label.style.minimal_width = 120 + label.style.font = "heading-2" + label.style.font_color = {0.88, 0.88, 0.99} + + local label = t.add({type = "label", caption = description}) + label.style.padding = 2 + label.style.left_padding= 10 + label.style.single_line = false + label.style.font = "heading-3" + label.style.font_color = {0.85, 0.85, 0.85} +end + +local build_config_gui = (function (player, frame) + frame.clear() + + local line_elements = {} + local switch_label_elements = {} + local label_elements = {} + + line_elements[#line_elements + 1] = frame.add({type = "line"}) + + local switch_state = "right" + if global.objective.config.offline_loot then switch_state = "left" end + add_switch(frame, switch_state, "comfy_panel_offline_accidents", "Offline Accidents", "Disablesr enables dropping of inventory when player goes offline.\nTimer is 15 minutes.") + + line_elements[#line_elements + 1] = frame.add({type = "line"}) + + if global.auto_hotbar_enabled then + local switch_state = "right" + if global.objective.config.jumpfailure then switch_state = "left" end + add_switch(frame, switch_state, "comfy_panel_danger_events", "Dangerous Events", "Disables or enables dangerous event maps\n(they require at least 2-4 capable players to survive)") + line_elements[#line_elements + 1] = frame.add({type = "line"}) + end + +end) + +local function on_gui_click(event) + if not event.element then return end + if not event.element.valid then return end + if functions[event.element.name] then + functions[event.element.name](event) + return + end +end + +comfy_panel_tabs["ChronoTrain"] = {gui = build_config_gui, admin = true} + + +local event = require 'utils.event' +event.add(defines.events.on_gui_click, on_gui_click) diff --git a/maps/chronosphere/main.lua b/maps/chronosphere/main.lua index b6c71b97..ceb8581c 100644 --- a/maps/chronosphere/main.lua +++ b/maps/chronosphere/main.lua @@ -141,7 +141,7 @@ local function reset_map() global.active_surface_index = game.create_surface("chronosphere", Chrono.get_map_gen_settings()).index else game.forces.player.set_spawn_position({12, 10}, game.surfaces[global.active_surface_index]) - global.active_surface_index = Reset.soft_reset_map(game.surfaces[global.active_surface_index], map_gen_settings, starting_items).index + global.active_surface_index = Reset.soft_reset_map(game.surfaces[global.active_surface_index], Chrono.get_map_gen_settings(), starting_items).index end local surface = game.surfaces[global.active_surface_index] diff --git a/maps/chronosphere/terrain.lua b/maps/chronosphere/terrain.lua index b76884fe..6e28d794 100644 --- a/maps/chronosphere/terrain.lua +++ b/maps/chronosphere/terrain.lua @@ -286,7 +286,7 @@ local function process_rocky_position(p, seed, tiles, entities, treasure, planet end if math_abs(noise_large_caves) > 0.375 then tiles[#tiles + 1] = {name = "dirt-7", position = p} - if math_random(1,6) > 1 then entities[#entities + 1] = {name = rock_raffle[math_random(1, size_of_rock_raffle)], position = p} end + if math_random(1,5) > 1 then entities[#entities + 1] = {name = rock_raffle[math_random(1, size_of_rock_raffle)], position = p} end if math_random(1,2048) == 1 then treasure[#treasure + 1] = p end return end @@ -306,9 +306,9 @@ local function process_rocky_position(p, seed, tiles, entities, treasure, planet if small_caves > -0.25 and small_caves < 0.25 then tiles[#tiles + 1] = {name = "dirt-7", position = p} local roll = math_random(1,1000) - if roll > 800 then + if roll > 830 then entities[#entities + 1] = {name = rock_raffle[math_random(1, size_of_rock_raffle)], position = p} - elseif roll > 790 and math_sqrt(p.x * p.x + p.y * p.y) > 150 then + elseif roll > 820 and math_sqrt(p.x * p.x + p.y * p.y) > 150 then entities[#entities + 1] = {name = worm_raffle[math_random(1 + math_floor(game.forces["enemy"].evolution_factor * 8), math_floor(1 + game.forces["enemy"].evolution_factor * 16))], position = p} else @@ -329,7 +329,7 @@ local function process_rocky_position(p, seed, tiles, entities, treasure, planet if math_random(1,2048) == 1 then treasure[#treasure + 1] = p end tiles[#tiles + 1] = {name = "dirt-7", position = p} - if math_random(1,100) > 40 then entities[#entities + 1] = {name = rock_raffle[math_random(1, size_of_rock_raffle)], position = p} end + if math_random(1,100) > 50 then entities[#entities + 1] = {name = rock_raffle[math_random(1, size_of_rock_raffle)], position = p} end return end diff --git a/maps/chronosphere/tick_functions.lua b/maps/chronosphere/tick_functions.lua index b5beb73a..334d91c2 100644 --- a/maps/chronosphere/tick_functions.lua +++ b/maps/chronosphere/tick_functions.lua @@ -210,7 +210,6 @@ function Public_tick.offline_players() player_inv[3] = game.players[players[i].index].get_inventory(defines.inventory.character_guns) player_inv[4] = game.players[players[i].index].get_inventory(defines.inventory.character_ammo) player_inv[5] = game.players[players[i].index].get_inventory(defines.inventory.character_trash) - game.print({"chronosphere.message_accident"}, {r=0.98, g=0.66, b=0.22}) local e = surface.create_entity({name = "character", position = game.forces.player.get_spawn_position(surface), force = "neutral"}) local inv = e.get_inventory(defines.inventory.character_main) for ii = 1, 5, 1 do @@ -228,8 +227,12 @@ function Public_tick.offline_players() inv.insert(items[item]) end end + game.print({"chronosphere.message_accident"}, {r=0.98, g=0.66, b=0.22}) + e.die("neutral") + else + e.destroy() end - e.die("neutral") + for ii = 1, 5, 1 do if player_inv[ii].valid then player_inv[ii].clear() @@ -247,6 +250,7 @@ function Public_tick.offline_players() players[#players + 1] = later[i] end end + objective.offline_players = players end end