From 4ce23426297ac4860e3bb18e929fcb1ba20c2bcb Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Thu, 7 Apr 2022 16:10:40 +0200 Subject: [PATCH 1/8] rpg - revert inventory bonus --- modules/rpg/functions.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/rpg/functions.lua b/modules/rpg/functions.lua index 6d98a923..4f644ea8 100644 --- a/modules/rpg/functions.lua +++ b/modules/rpg/functions.lua @@ -519,7 +519,7 @@ function Public.update_player_stats(player) local rpg_extra = Public.get('rpg_extra') local rpg_t = Public.get_value_from_player(player.index) local strength = rpg_t.strength - 10 - P.update_single_modifier(player, 'character_inventory_slots_bonus', 'rpg', round(strength * 0.1, 3)) + P.update_single_modifier(player, 'character_inventory_slots_bonus', 'rpg', round(strength * 0.2, 3)) P.update_single_modifier(player, 'character_mining_speed_modifier', 'rpg', round(strength * 0.006, 3)) P.update_single_modifier(player, 'character_maximum_following_robot_count_bonus', 'rpg', round(strength / 2 * 0.03, 3)) From 38415cead945b3ce7602ca1b060e6afcacc4f7af Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Thu, 7 Apr 2022 16:11:03 +0200 Subject: [PATCH 2/8] player modifiers - limit rpg inventory --- utils/player_modifiers.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/utils/player_modifiers.lua b/utils/player_modifiers.lua index 1091dd44..c2ac34d5 100644 --- a/utils/player_modifiers.lua +++ b/utils/player_modifiers.lua @@ -8,7 +8,8 @@ local round = math.round local this = { modifiers = {}, - disabled_modifier = {} + disabled_modifier = {}, + rpg_inventory_slot_limit = 320 -- huge inventory lags the server, this fixes it } Global.register( @@ -74,7 +75,7 @@ function Public.update_player_modifiers(player) if disabled_modifiers and disabled_modifiers[k] then player[modifier] = 0 else - player[modifier] = round(sum_value, 8) + player[modifier] = round(sum_value, 4) end end end @@ -92,9 +93,13 @@ function Public.update_single_modifier(player, modifier, category, value) if modifiers[k] == modifier and player_modifiers[k] then if category then if not player_modifiers[k][category] then - player_modifiers[k][category] = {} + player_modifiers[k][category] = 0 end player_modifiers[k][category] = value + + if category == 'rpg' and modifiers[k] == 'character_inventory_slots_bonus' and player_modifiers[k][category] >= this.rpg_inventory_slot_limit then + player_modifiers[k][category] = this.rpg_inventory_slot_limit - player.force.character_inventory_slots_bonus + end else player_modifiers[k] = value end From 98d29e73da1da684a8b4f1db29cfab005c434be6 Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Thu, 7 Apr 2022 16:11:18 +0200 Subject: [PATCH 3/8] mtn v3 - fixes --- locale/en/mtn_fortress_v3.cfg | 2 +- maps/mountain_fortress_v3/breached_wall.lua | 6 +- maps/mountain_fortress_v3/functions.lua | 18 +- maps/mountain_fortress_v3/locomotive.lua | 4 +- .../locomotive/market.lua | 2 + .../locomotive/spawn_locomotive.lua | 1 + maps/mountain_fortress_v3/main.lua | 26 ++- maps/mountain_fortress_v3/mining.lua | 2 +- maps/mountain_fortress_v3/mystical_chest.lua | 45 ---- maps/mountain_fortress_v3/table.lua | 14 +- maps/mountain_fortress_v3/terrain.lua | 205 ++++++++---------- 11 files changed, 140 insertions(+), 185 deletions(-) diff --git a/locale/en/mtn_fortress_v3.cfg b/locale/en/mtn_fortress_v3.cfg index 07a960cf..bdf6a061 100644 --- a/locale/en/mtn_fortress_v3.cfg +++ b/locale/en/mtn_fortress_v3.cfg @@ -1,7 +1,7 @@ [mountain_fortress_v3] map_info_main_caption=M O U N T A I N F O R T R E S S V3 map_info_sub_caption= ~~ diggy diggy choo choo ~~ -map_info_text=[color=red]READ THIS!\nIf there are any code bugs or desyncs. Please report asap to @Gerkiz!\nIf there are any game breaking bugs then this map might be shutdown to hot-fix the issue.[/color]\n\nThe biters have caught the scent of fish in the cargo wagon.\nGuide the choo into the mountain and protect it as long as possible!\nThis however will not be an easy task,\nsince their strength and numbers increase over time.\n\nIn additon, the southern grounds collapse over time.\n\nDelve deep for greater treasures, but also face increased dangers.\nMining productivity research will overhaul your mining equipment, increasing the size of your backpack.\n\nAs you dig, you will encounter impassable dark chasms or rivers.\nArtillery will try to shoot you down! Dig fast, dig north!\n\nSome explosives may cause rocks to fall down the mountain, filling the void, creating new ways.\nAll they need is a container and a well aimed shot.\n\nEnter the cargo wagon to reveal the wagon surface!\n\nRandom buildings that generate resources can be found throughout the world.\n\nPlacing steel-chests near cargo-wagons enables you to quickly move content.\n\nStaying inside the locomotive aura prevents biters from spawning when mining entities.\n\nRPG GUI is disabled inside the locomotive.\nDisconnecting wagons is disabled.\nYou can't cancel crafting when standing inside the locomotive aura.\n\nDon't try to run north with your Spidertron if the train is not near you.\nYou have been warned.\n\nMining drills have great mining-bonus which also is increased after each research, use them when you can!\n\nThe mystical chest in the locomotive offers some rewards.\nOne must feed the chest to receive such rewards.\n\nGood luck on your journey! +map_info_text=[color=red]READ THIS!\nIf there are any code bugs or desyncs. Please report asap to @Gerkiz!\nIf there are any game breaking bugs then this map might be shutdown to hot-fix the issue.[/color]\n\nThe biters have caught the scent of fish in the cargo wagon.\nGuide the choo into the mountain and protect it as long as possible!\nThis however will not be an easy task,\nsince their strength and numbers increase over time.\n\nIn additon, the southern grounds collapse over time.\n\nDelve deep for greater treasures, but also face increased dangers.\nMining productivity research will overhaul your mining equipment, increasing the size of your backpack.\n\nAs you dig, you will encounter impassable dark chasms or rivers.\nArtillery will try to shoot you down! Dig fast, dig north!\n\nSome explosives may cause rocks to fall down the mountain, filling the void, creating new ways.\nAll they need is a container and a well aimed shot.\n\nEnter the cargo wagon to reveal the wagon surface!\n\nRandom buildings that generate resources can be found throughout the world.\n\nPlacing steel-chests near cargo-wagons enables you to quickly move content.\n\nStaying inside the locomotive aura prevents biters from spawning when mining entities.\n\nRadars do not generate new areas.\n\nRPG GUI is disabled inside the locomotive.\n\nDisconnecting wagons is disabled.\nYou can't cancel crafting when standing inside the locomotive aura.\n\nDon't try to run north with your Spidertron if the train is not near you.\nYou have been warned.\n\nMining drills have great mining-bonus which also is increased after each research, use them when you can!\n\nThe mystical chest in the locomotive offers some rewards.\nOne must feed the chest to receive such rewards.\n\nGood luck on your journey! [breached_wall] collapse_start=[color=blue]Mapkeeper:[/color]\nWarning, Collapse has begun! diff --git a/maps/mountain_fortress_v3/breached_wall.lua b/maps/mountain_fortress_v3/breached_wall.lua index 27472fb1..0e39d38e 100644 --- a/maps/mountain_fortress_v3/breached_wall.lua +++ b/maps/mountain_fortress_v3/breached_wall.lua @@ -125,8 +125,12 @@ end local compare_player_pos = function(player) local p = player.position local index = player.index - local zone = floor((abs(p.y / zone_settings.zone_depth)) % zone_settings.size) + 1 local adjusted_zones = WPT.get('adjusted_zones') + if not adjusted_zones.size then + return + end + + local zone = floor((abs(p.y / zone_settings.zone_depth)) % adjusted_zones.size) + 1 if adjusted_zones.scrap[zone] then RPG.set_value_to_player(index, 'scrap_zone', true) diff --git a/maps/mountain_fortress_v3/functions.lua b/maps/mountain_fortress_v3/functions.lua index e75e1283..caa70565 100644 --- a/maps/mountain_fortress_v3/functions.lua +++ b/maps/mountain_fortress_v3/functions.lua @@ -13,6 +13,7 @@ local Difficulty = require 'modules.difficulty_vote_by_amount' local ICW_Func = require 'maps.mountain_fortress_v3.icw.functions' local math2d = require 'math2d' local Misc = require 'utils.commands.misc' +local Core = require 'utils.core' local zone_settings = WPT.zone_settings local this = { @@ -159,7 +160,7 @@ local function do_magic_crafters() local index = magic_crafters.index - for i = 1, magic_crafters_per_tick do + for _ = 1, magic_crafters_per_tick do if index > limit then index = 1 end @@ -211,7 +212,7 @@ local function do_magic_fluid_crafters() local index = magic_fluid_crafters.index - for i = 1, magic_fluid_crafters_per_tick do + for _ = 1, magic_fluid_crafters_per_tick do if index > limit then index = 1 end @@ -430,7 +431,7 @@ Public.disable_minable_and_ICW_callback = function(entity) if entity and entity.valid then entity.minable = false - ICW.register_wagon(entity, true) + ICW.register_wagon(entity) end end ) @@ -791,12 +792,13 @@ local function calc_players() return #players end local total = 0 - for i = 1, #players do - local player = players[i] - if player.afk_time < 36000 then - total = total + 1 + Core.iter_connected_players( + function(player) + if player.afk_time < 36000 then + total = total + 1 + end end - end + ) if total <= 0 then total = #players end diff --git a/maps/mountain_fortress_v3/locomotive.lua b/maps/mountain_fortress_v3/locomotive.lua index c7545bf9..a147d7aa 100644 --- a/maps/mountain_fortress_v3/locomotive.lua +++ b/maps/mountain_fortress_v3/locomotive.lua @@ -85,7 +85,7 @@ local function validate_player(player) return true end -local function property_boost(data) +local function give_passive_xp(data) local xp_floating_text_color = {r = 188, g = 201, b = 63} local visuals_delay = 1800 local loco_surface = WPT.get('loco_surface') @@ -430,7 +430,7 @@ function Public.boost_players_around_train() locomotive_surface = locomotive_surface, rpg = rpg } - property_boost(data) + give_passive_xp(data) end function Public.is_around_train(entity) diff --git a/maps/mountain_fortress_v3/locomotive/market.lua b/maps/mountain_fortress_v3/locomotive/market.lua index 3fcecdd1..9374664f 100644 --- a/maps/mountain_fortress_v3/locomotive/market.lua +++ b/maps/mountain_fortress_v3/locomotive/market.lua @@ -553,6 +553,7 @@ local function redraw_market_items(gui, player, search_text) frame.add( { type = 'sprite-button', + ---@diagnostic disable-next-line: ambiguity-1 sprite = data.sprite or 'item/' .. item, number = item_count, name = item, @@ -611,6 +612,7 @@ local function redraw_market_items(gui, player, search_text) frame.add( { type = 'sprite-button', + ---@diagnostic disable-next-line: ambiguity-1 sprite = data.sprite or 'item/' .. item, number = item_count, name = item, diff --git a/maps/mountain_fortress_v3/locomotive/spawn_locomotive.lua b/maps/mountain_fortress_v3/locomotive/spawn_locomotive.lua index 04a05019..e6042d7d 100644 --- a/maps/mountain_fortress_v3/locomotive/spawn_locomotive.lua +++ b/maps/mountain_fortress_v3/locomotive/spawn_locomotive.lua @@ -72,6 +72,7 @@ local set_loco_tiles = local p = {} + ---@diagnostic disable-next-line: count-down-loop for x = position.x - 5, 1, 3 do for y = 1, position.y + 5, 2 do if random(1, 4) == 1 then diff --git a/maps/mountain_fortress_v3/main.lua b/maps/mountain_fortress_v3/main.lua index a2db0647..e6461ba7 100644 --- a/maps/mountain_fortress_v3/main.lua +++ b/maps/mountain_fortress_v3/main.lua @@ -313,7 +313,8 @@ end local is_player_valid = function() local players = game.connected_players - for _, player in pairs(players) do + for i = 1, #players do + local player = players[i] if player.connected and player.controller_type == 2 then player.set_controller {type = defines.controllers.god} player.create_character() @@ -467,9 +468,11 @@ end local on_tick = function() local update_gui = Gui_mf.update_gui local tick = game.tick + local players = game.connected_players if tick % 40 == 0 then - for _, player in pairs(game.connected_players) do + for i = 1, #players do + local player = players[i] update_gui(player) end lock_locomotive_positions() @@ -537,5 +540,24 @@ end Event.on_nth_tick(10, on_tick) Event.on_init(on_init) Event.add(WPT.events.reset_map, Public.reset_map) +Event.add( + defines.events.on_sector_scanned, + function(event) + local radar = event.radar + if not radar or not radar.valid then + return + end + + local radars_reveal_new_chunks = WPT.get('radars_reveal_new_chunks') + if radars_reveal_new_chunks then + return + end + + local pos = event.chunk_position + + radar.force.cancel_charting(radar.surface.index) + radar.force.unchart_chunk(pos, radar.surface.index) + end +) return Public diff --git a/maps/mountain_fortress_v3/mining.lua b/maps/mountain_fortress_v3/mining.lua index 1ca8f2a7..4c360eb2 100644 --- a/maps/mountain_fortress_v3/mining.lua +++ b/maps/mountain_fortress_v3/mining.lua @@ -177,7 +177,7 @@ local function create_particles(surface, name, position, amount, cause_position) d2 = (cause_position.y - position.y) * 0.025 end - for i = 1, amount, 1 do + for _ = 1, amount, 1 do local m = random(4, 10) local m2 = m * 0.005 diff --git a/maps/mountain_fortress_v3/mystical_chest.lua b/maps/mountain_fortress_v3/mystical_chest.lua index 7507b535..1920e536 100644 --- a/maps/mountain_fortress_v3/mystical_chest.lua +++ b/maps/mountain_fortress_v3/mystical_chest.lua @@ -1,7 +1,6 @@ local Color = require 'utils.color_presets' local Event = require 'utils.event' local WPT = require 'maps.mountain_fortress_v3.table' -local WD = require 'modules.wave_defense.table' local RPG = require 'modules.rpg.main' local Alert = require 'utils.alert' local Task = require 'utils.task' @@ -265,17 +264,6 @@ local function roll_item_stacks(remaining_budget, max_slots, blacklist) return item_stack_set, item_stack_set_worth end -local pause_wd_token = - Token.register( - function() - WD.pause(false) - local mc_rewards = WPT.get('mc_rewards') - mc_rewards.temp_boosts.wave_defense = nil - local message = ({'locomotive.wd_resumed'}) - Alert.alert_all_players(15, message, nil, 'achievement/tech-maniac') - end -) - local restore_mining_speed_token = Token.register( function() @@ -379,19 +367,6 @@ local mc_random_rewards = { end), 512 }, - { - name = 'Inventory Bonus', - color = {r = 0.00, g = 0.00, b = 0.25}, - tooltip = 'Selecting this will grant the team permanent inventory bonus!', - func = (function(player) - local force = game.forces.player - force.character_inventory_slots_bonus = force.character_inventory_slots_bonus + 1 - local message = ({'locomotive.inventory_bonus', player.name}) - Alert.alert_all_players(15, message, nil, 'achievement/tech-maniac') - return true - end), - 512 - }, { name = 'Heal Locomotive', color = {r = 0.00, g = 0.00, b = 0.25}, @@ -404,26 +379,6 @@ local mc_random_rewards = { return true end), 256 - }, - { - name = 'Wave Defense', - str = 'wave_defense', - color = {r = 0.35, g = 0.00, b = 0.00}, - tooltip = 'Selecting this will pause the wave defense for 5 minutes. Ideal if you want to take a break!', - func = (function(player) - local mc_rewards = WPT.get('mc_rewards') - if mc_rewards.temp_boosts.wave_defense then - return false, '[Rewards] Wave Defense break is already applied. Please choose another reward.' - end - mc_rewards.temp_boosts.wave_defense = true - - WD.pause(true) - Task.set_timeout_in_ticks(18000, pause_wd_token) - local message = ({'locomotive.wd_paused', player.name}) - Alert.alert_all_players(15, message, nil, 'achievement/tech-maniac') - return true - end), - 64 } } diff --git a/maps/mountain_fortress_v3/table.lua b/maps/mountain_fortress_v3/table.lua index 5a01fd81..29687451 100644 --- a/maps/mountain_fortress_v3/table.lua +++ b/maps/mountain_fortress_v3/table.lua @@ -19,8 +19,7 @@ Global.register( Public.zone_settings = { zone_depth = 704, - zone_width = 510, - size = nil + zone_width = 510 } Public.pickaxe_upgrades = { @@ -230,9 +229,12 @@ function Public.reset_table() } this.adjusted_zones = { scrap = {}, - forest = {} + forest = {}, + size = nil, + shuffled_zones = nil } this.alert_zone_1 = false -- alert the players + this.radars_reveal_new_chunks = false -- allows for the player to explore the map instead for k, _ in pairs(this.players) do this.players[k] = {} @@ -270,10 +272,6 @@ function Public.remove(key, sub_key) end end -local on_init = function() - Public.reset_table() -end - -Event.on_init(on_init) +Event.on_init(Public.reset_table) return Public diff --git a/maps/mountain_fortress_v3/terrain.lua b/maps/mountain_fortress_v3/terrain.lua index a810c496..c2bb0fc6 100644 --- a/maps/mountain_fortress_v3/terrain.lua +++ b/maps/mountain_fortress_v3/terrain.lua @@ -144,7 +144,7 @@ local function is_position_near(area, table_to_check) end for i = 1, #table_to_check do - if inside(table_to_check[i], area) then + if inside(table_to_check[i]) then status = true end end @@ -152,7 +152,7 @@ local function is_position_near(area, table_to_check) return status end -local function place_wagon(data) +local function place_wagon(data, adjusted_zones) local placed_trains_in_zone = WPT.get('placed_trains_in_zone') if not placed_trains_in_zone.randomized then placed_trains_in_zone.limit = random(1, 2) @@ -164,11 +164,11 @@ local function place_wagon(data) data.new_zone = 1 end - if data.new_zone == zone_settings.size then + if data.new_zone == adjusted_zones.size then data.new_zone = 1 end - if data.current_zone == zone_settings.size then + if data.current_zone == adjusted_zones.size then local new_zone = placed_trains_in_zone.zones[data.new_zone] if new_zone then new_zone.placed = 0 @@ -215,6 +215,7 @@ local function place_wagon(data) local location local direction + local r1 = random(2, 4) * 2 local r2 = random(2, 4) * 2 @@ -226,7 +227,7 @@ local function place_wagon(data) direction = 2 end - for k, tile in pairs(location) do + for _, tile in pairs(location) do tiles[#tiles + 1] = {name = 'nuclear-ground', position = tile.position} if tile.position.y % 1 == 0 and tile.position.x % 1 == 0 then entities[#entities + 1] = { @@ -458,7 +459,7 @@ local function wall(p, data) end end -local function generate_zone_14(x, y, data) +local function zone_14(x, y, data, _, adjusted_zones) local p = {x = x, y = y} local seed = data.seed local tiles = data.tiles @@ -510,7 +511,7 @@ local function generate_zone_14(x, y, data) if small_caves > -0.41 and small_caves < 0.41 then if noise_cave_ponds > 0.35 then - local success = place_wagon(data) + local success = place_wagon(data, adjusted_zones) if success then return end @@ -538,7 +539,7 @@ local function generate_zone_14(x, y, data) tiles[#tiles + 1] = {name = 'water-shallow', position = p} end -local function generate_zone_13(x, y, data) +local function zone_13(x, y, data, _, adjusted_zones) local p = {x = x, y = y} local seed = data.seed local tiles = data.tiles @@ -590,7 +591,7 @@ local function generate_zone_13(x, y, data) if small_caves > -0.40 and small_caves < 0.40 then if noise_cave_ponds > 0.35 then - local success = place_wagon(data) + local success = place_wagon(data, adjusted_zones) if success then return end @@ -618,7 +619,7 @@ local function generate_zone_13(x, y, data) tiles[#tiles + 1] = {name = 'water-shallow', position = p} end -local function generate_zone_12(x, y, data, void_or_lab) +local function zone_12(x, y, data, void_or_lab, adjusted_zones) local p = {x = x, y = y} local seed = data.seed local tiles = data.tiles @@ -653,7 +654,7 @@ local function generate_zone_12(x, y, data, void_or_lab) end if noise_1 < -0.72 then - local success = place_wagon(data) + local success = place_wagon(data, adjusted_zones) if success then return end @@ -704,7 +705,7 @@ local function generate_zone_12(x, y, data, void_or_lab) tiles[#tiles + 1] = {name = 'tutorial-grid', position = p} end -local function generate_zone_11(x, y, data) +local function zone_11(x, y, data, _, adjusted_zones) local p = {x = x, y = y} local seed = data.seed local tiles = data.tiles @@ -767,7 +768,7 @@ local function generate_zone_11(x, y, data) } end - local success = place_wagon(data) + local success = place_wagon(data, adjusted_zones) if success then return end @@ -800,7 +801,7 @@ local function generate_zone_11(x, y, data) end end -local function generate_zone_10(x, y, data) +local function zone_10(x, y, data, _, adjusted_zones) local p = {x = x, y = y} local seed = data.seed local tiles = data.tiles @@ -844,7 +845,7 @@ local function generate_zone_10(x, y, data) return end if abs(scrapyard) > 0.25 and abs(scrapyard) < 0.40 then - local success = place_wagon(data) + local success = place_wagon(data, adjusted_zones) if success then return end @@ -914,7 +915,7 @@ local function generate_zone_10(x, y, data) tiles[#tiles + 1] = {name = 'grass-2', position = p} end -local function generate_zone_9(x, y, data) +local function zone_9(x, y, data, _, adjusted_zones) local p = {x = x, y = y} local seed = data.seed local tiles = data.tiles @@ -949,7 +950,7 @@ local function generate_zone_9(x, y, data) end if maze_noise > 0 and maze_noise < 0.45 then - local success = place_wagon(data) + local success = place_wagon(data, adjusted_zones) if success then return end @@ -987,7 +988,7 @@ local function generate_zone_9(x, y, data) end --SCRAPYARD -local function process_zone_scrap_2(x, y, data, void_or_lab) +local function zone_scrap_2(x, y, data, void_or_lab, adjusted_zones) local p = {x = x, y = y} local seed = data.seed local tiles = data.tiles @@ -1033,7 +1034,7 @@ local function process_zone_scrap_2(x, y, data, void_or_lab) return end if scrapyard_modified < -0.28 or scrapyard_modified > 0.28 then - local success = place_wagon(data) + local success = place_wagon(data, adjusted_zones) if success then return end @@ -1116,7 +1117,7 @@ local function process_zone_scrap_2(x, y, data, void_or_lab) end --SCRAPYARD -local function process_zone_scrap_1(x, y, data, void_or_lab) +local function zone_scrap_1(x, y, data, void_or_lab, adjusted_zones) local p = {x = x, y = y} local seed = data.seed local tiles = data.tiles @@ -1162,7 +1163,7 @@ local function process_zone_scrap_1(x, y, data, void_or_lab) return end if scrapyard < -0.28 or scrapyard > 0.28 then - local success = place_wagon(data) + local success = place_wagon(data, adjusted_zones) if success then return end @@ -1244,7 +1245,7 @@ local function process_zone_scrap_1(x, y, data, void_or_lab) end end -local function generate_zone_7(x, y, data, void_or_lab) +local function zone_7(x, y, data, void_or_lab, adjusted_zones) local p = {x = x, y = y} local seed = data.seed local tiles = data.tiles @@ -1304,7 +1305,7 @@ local function generate_zone_7(x, y, data, void_or_lab) if cave_rivers_4 > -0.20 and cave_rivers_4 < 0.20 then tiles[#tiles + 1] = {name = 'grass-' .. floor(cave_rivers_4 * 32) % 3 + 1, position = p} if cave_rivers_4 > -0.10 and cave_rivers_4 < 0.10 then - local success = place_wagon(data) + local success = place_wagon(data, adjusted_zones) if success then return end @@ -1361,7 +1362,7 @@ local function generate_zone_7(x, y, data, void_or_lab) end end -local function generate_zone_forest_2(x, y, data, void_or_lab) +local function zone_forest_2(x, y, data, void_or_lab, adjusted_zones) local p = {x = x, y = y} local seed = data.seed local tiles = data.tiles @@ -1418,7 +1419,7 @@ local function generate_zone_forest_2(x, y, data, void_or_lab) end local noise_forest_location = get_perlin('forest_location', p, seed) if cave_rivers > -0.1 and cave_rivers < 0.1 then - local success = place_wagon(data) + local success = place_wagon(data, adjusted_zones) if success then return end @@ -1497,7 +1498,7 @@ local function generate_zone_forest_2(x, y, data, void_or_lab) end end -local function generate_zone_5(x, y, data, void_or_lab) +local function zone_5(x, y, data, void_or_lab, adjusted_zones) local p = {x = x, y = y} local seed = data.seed local tiles = data.tiles @@ -1561,7 +1562,7 @@ local function generate_zone_5(x, y, data, void_or_lab) if small_caves > -0.40 and small_caves < 0.40 then if noise_cave_ponds > 0.35 then - local success = place_wagon(data) + local success = place_wagon(data, adjusted_zones) if success then return end @@ -1589,7 +1590,7 @@ local function generate_zone_5(x, y, data, void_or_lab) tiles[#tiles + 1] = {name = void_or_lab, position = p} end -local function generate_zone_4(x, y, data, void_or_lab) +local function zone_4(x, y, data, void_or_lab, adjusted_zones) local p = {x = x, y = y} local seed = data.seed local tiles = data.tiles @@ -1632,7 +1633,7 @@ local function generate_zone_4(x, y, data, void_or_lab) note = true } end - local success = place_wagon(data) + local success = place_wagon(data, adjusted_zones) if success then return end @@ -1720,7 +1721,7 @@ local function generate_zone_4(x, y, data, void_or_lab) tiles[#tiles + 1] = {name = void_or_lab, position = p} end -local function generate_zone_3(x, y, data, void_or_lab) +local function zone_3(x, y, data, void_or_lab, adjusted_zones) local p = {x = x, y = y} local seed = data.seed local tiles = data.tiles @@ -1857,7 +1858,7 @@ local function generate_zone_3(x, y, data, void_or_lab) --Main Rock Terrain local no_rocks_2 = get_perlin('no_rocks_2', p, seed + 75000) if no_rocks_2 > 0.80 or no_rocks_2 < -0.80 then - local success = place_wagon(data) + local success = place_wagon(data, adjusted_zones) if success then return end @@ -1886,7 +1887,7 @@ local function generate_zone_3(x, y, data, void_or_lab) end end -local function generate_zone_2(x, y, data, void_or_lab) +local function zone_2(x, y, data, void_or_lab, adjusted_zones) local p = {x = x, y = y} local seed = data.seed local tiles = data.tiles @@ -2005,7 +2006,7 @@ local function generate_zone_2(x, y, data, void_or_lab) --Main Rock Terrain local no_rocks_2 = get_perlin('no_rocks_2', p, seed + 75000) if no_rocks_2 > 0.80 or no_rocks_2 < -0.80 then - local success = place_wagon(data) + local success = place_wagon(data, adjusted_zones) if success then return end @@ -2030,7 +2031,7 @@ local function generate_zone_2(x, y, data, void_or_lab) tiles[#tiles + 1] = {name = void_or_lab, position = p} end -local function generate_zone_forest_1(x, y, data, void_or_lab) +local function zone_forest_1(x, y, data, void_or_lab, adjusted_zones) local p = {x = x, y = y} local seed = data.seed local buildings = data.buildings @@ -2149,7 +2150,7 @@ local function generate_zone_forest_1(x, y, data, void_or_lab) --Main Rock Terrain local no_rocks_2 = get_perlin('no_rocks_2', p, seed + 5000) if no_rocks_2 > 0.64 or no_rocks_2 < -0.64 then - local success = place_wagon(data) + local success = place_wagon(data, adjusted_zones) if success then return end @@ -2214,7 +2215,7 @@ local function generate_zone_forest_1(x, y, data, void_or_lab) end end -local function generate_zone_1(x, y, data, void_or_lab) +local function zone_1(x, y, data, void_or_lab, adjusted_zones) local p = {x = x, y = y} local seed = data.seed local buildings = data.buildings @@ -2331,7 +2332,7 @@ local function generate_zone_1(x, y, data, void_or_lab) --Main Rock Terrain local no_rocks_2 = get_perlin('no_rocks_2', p, seed + 75000) if no_rocks_2 > 0.66 or no_rocks_2 < -0.66 then - local success = place_wagon(data) + local success = place_wagon(data, adjusted_zones) if success then return end @@ -2378,7 +2379,7 @@ local function generate_zone_1(x, y, data, void_or_lab) end end -local function starting_zone(x, y, data, void_or_lab) +local function starting_zone(x, y, data, void_or_lab, adjusted_zones) local p = {x = x, y = y} local seed = data.seed local buildings = data.buildings @@ -2492,7 +2493,7 @@ local function starting_zone(x, y, data, void_or_lab) --Main Rock Terrain if no_rocks_2 > 0.334 and no_rocks_2 < 0.544 then - local success = place_wagon(data) + local success = place_wagon(data, adjusted_zones) if success then return end @@ -2517,78 +2518,27 @@ local function starting_zone(x, y, data, void_or_lab) end local zones = { - generate_zone_1, - generate_zone_forest_1, - generate_zone_3, - generate_zone_5, - generate_zone_11, - generate_zone_forest_2, - process_zone_scrap_1, - process_zone_scrap_2, - generate_zone_9, - generate_zone_4, - process_zone_scrap_1, - generate_zone_2, - generate_zone_3, - process_zone_scrap_2, - generate_zone_3, - generate_zone_forest_2, - generate_zone_4, - generate_zone_forest_1, - generate_zone_forest_2, - generate_zone_2, - generate_zone_4, - process_zone_scrap_2, - generate_zone_5, - generate_zone_1, - generate_zone_forest_2, - generate_zone_7, - process_zone_scrap_1, - generate_zone_9, - generate_zone_10, - generate_zone_11, - generate_zone_12, - generate_zone_forest_2, - process_zone_scrap_2, - process_zone_scrap_1, - generate_zone_11, - generate_zone_12, - process_zone_scrap_1, - generate_zone_13, - generate_zone_14, - process_zone_scrap_1, - generate_zone_forest_1, - generate_zone_14, - process_zone_scrap_2 + ['zone_1'] = zone_1, + ['zone_2'] = zone_2, + ['zone_3'] = zone_3, + ['zone_4'] = zone_4, + ['zone_5'] = zone_5, + ['zone_forest_1'] = zone_forest_1, + ['zone_forest_2'] = zone_forest_2, + ['zone_scrap_1'] = zone_scrap_1, + ['zone_scrap_2'] = zone_scrap_2, + ['zone_7'] = zone_7, + ['zone_9'] = zone_9, + ['zone_10'] = zone_10, + ['zone_11'] = zone_11, + ['zone_12'] = zone_12, + ['zone_13'] = zone_13, + ['zone_14'] = zone_14 } ---[[ local zones_non_raffled = { - generate_zone_1, - generate_zone_2, - generate_zone_3, - generate_zone_4, - generate_zone_5, - generate_zone_forest_1, - generate_zone_forest_2, - process_zone_scrap_1, - process_zone_scrap_2, - generate_zone_7, - generate_zone_9, - generate_zone_11, - generate_zone_10, - generate_zone_11, - generate_zone_12, - generate_zone_13, - generate_zone_14 -} ]] - -zone_settings.size = #zones - -local function shuffle_terrains(new_zone) - local adjusted_zones = WPT.get('adjusted_zones') - +local function shuffle_terrains(adjusted_zones, new_zone) if not adjusted_zones.shuffled_terrains then - shuffle(zones) + shuffle(adjusted_zones.shuffled_zones) adjusted_zones.shuffled_terrains = new_zone end @@ -2605,25 +2555,43 @@ local function is_out_of_map(p) return true end -local function process_bits(p, data) +local function init_terrain(adjusted_zones) + if adjusted_zones.init_terrain then + return + end + + local count = 1 + local shuffled_zones = {} + + for zone_name, _ in pairs(zones) do + shuffled_zones[count] = zone_name + count = count + 1 + end + + adjusted_zones.size = count + adjusted_zones.shuffled_zones = shuffled_zones + adjusted_zones.init_terrain = true +end + +local function process_bits(p, data, adjusted_zones) local left_top_y = data.area.left_top.y - local index = floor((abs(left_top_y / zone_settings.zone_depth)) % zone_settings.size) + 1 - shuffle_terrains(index) + + local index = floor((abs(left_top_y / zone_settings.zone_depth)) % adjusted_zones.size) + 1 + + shuffle_terrains(adjusted_zones, index) local generate_zone if left_top_y >= -zone_settings.zone_depth then generate_zone = starting_zone else - generate_zone = zones[index] + generate_zone = zones[adjusted_zones.shuffled_zones[index]] if not generate_zone then - generate_zone = zones[zone_settings.size] + generate_zone = zones[adjusted_zones.shuffled_zones[adjusted_zones.size]] end end data.current_zone = index - local adjusted_zones = WPT.get('adjusted_zones') - if data.forest_zone and not adjusted_zones.forest[index] then adjusted_zones.forest[index] = true end @@ -2637,7 +2605,7 @@ local function process_bits(p, data) local x = p.x local y = p.y - generate_zone(x, y, data, void_or_tile) + generate_zone(x, y, data, void_or_tile, adjusted_zones) end local function border_chunk(p, data) @@ -2729,6 +2697,9 @@ function Public.heavy_functions(data) local p = data.position local get_tile = surface.get_tile(p) + local adjusted_zones = WPT.get('adjusted_zones') + init_terrain(adjusted_zones) + local map_name = 'mountain_fortress_v3' if string.sub(surface.name, 0, #map_name) ~= map_name then @@ -2749,7 +2720,7 @@ function Public.heavy_functions(data) end if top_y < 0 then - return process_bits(p, data) + return process_bits(p, data, adjusted_zones) end if top_y > 120 then From 5a6539b6db235aa3256bcbee8df11f54cdaaf946 Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Thu, 7 Apr 2022 16:11:26 +0200 Subject: [PATCH 4/8] fix gui issue --- modules/difficulty_vote_by_amount.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/difficulty_vote_by_amount.lua b/modules/difficulty_vote_by_amount.lua index 0b6714b1..c16684f8 100644 --- a/modules/difficulty_vote_by_amount.lua +++ b/modules/difficulty_vote_by_amount.lua @@ -333,7 +333,7 @@ Gui.on_click( end local player = event.player - if not player or not player.valid or not player.character then + if not player or not player.valid then return end @@ -373,13 +373,14 @@ Gui.on_click( return end local player = event.player - if not player or not player.valid or not player.character then + if not player or not player.valid then return end if game.tick > this.difficulty_poll_closing_timeout then clear_main_frame(player) return end + local screen = player.gui.center if screen[main_frame_name] and screen[main_frame_name].valid then clear_main_frame(player) @@ -397,7 +398,7 @@ Gui.on_click( return end local player = event.player - if not player or not player.valid or not player.character then + if not player or not player.valid then return end clear_main_frame(player) From 86ae1d5c9b774a6461e151e99134b21b2cf87f8f Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Thu, 7 Apr 2022 16:11:57 +0200 Subject: [PATCH 5/8] fix lua tooltip warnings --- utils/antigrief.lua | 39 ++++++++++++++------------------------- utils/event.lua | 2 +- utils/gui.lua | 11 ++++++----- utils/table.lua | 1 + 4 files changed, 22 insertions(+), 31 deletions(-) diff --git a/utils/antigrief.lua b/utils/antigrief.lua index 4ffd8a66..3745a099 100644 --- a/utils/antigrief.lua +++ b/utils/antigrief.lua @@ -88,7 +88,7 @@ end -- Removes the first 100 entries of a table local function overflow(t) - for _=1,100,1 do + for _ = 1, 100, 1 do table.remove(t, 1) end end @@ -352,12 +352,7 @@ local function on_player_used_capsule(event) local prefix = '[Capsule]' msg = format(player.name .. ' damaged: %s with: %s', get_entities(name, entities), name) - local ban_msg = - format( - 'Damaged: %s with: %s. This action was performed automatically. Visit getcomfy.eu/discord for forgiveness', - get_entities(name, entities), - name - ) + local ban_msg = format('Damaged: %s with: %s. This action was performed automatically. Visit getcomfy.eu/discord for forgiveness', get_entities(name, entities), name) do_action(player, prefix, msg, ban_msg, true) else @@ -736,13 +731,7 @@ local function on_player_cancelled_crafting(event) player.character.die('player') - Utils.action_warning( - '[Crafting]', - player.name .. - ' canceled their craft of item ' .. - event.recipe.name .. - ' of total count ' .. crafting_queue_item_count .. ' in raw items (' .. crafted_items .. ' slots) but had no inventory left.' - ) + Utils.action_warning('[Crafting]', player.name .. ' canceled their craft of item ' .. event.recipe.name .. ' of total count ' .. crafting_queue_item_count .. ' in raw items (' .. crafted_items .. ' slots) but had no inventory left.') end if not this.cancel_crafting_history then @@ -865,9 +854,9 @@ local function on_permission_string_imported(event) end --- This is used for the RPG module, when casting capsules. ----@param player ----@param position ----@param msg +---@param player userdata +---@param position table +---@param msg string function Public.insert_into_capsule_history(player, position, msg) if not this.capsule_history then this.capsule_history = {} @@ -901,8 +890,8 @@ function Public.reset_tables() end --- Add entity type to the whitelist so it gets logged. ----@param key ----@param value +---@param key string +---@param value string function Public.whitelist_types(key, value) if key and value then this.whitelist_types[key] = value @@ -912,35 +901,35 @@ function Public.whitelist_types(key, value) end --- If the event should also check trusted players. ----@param value +---@param value string function Public.do_not_check_trusted(value) this.do_not_check_trusted = value or false return this.do_not_check_trusted end --- If ANY actions should be performed when a player misbehaves. ----@param value +---@param value string function Public.enable_capsule_warning(value) this.enable_capsule_warning = value or false return this.enable_capsule_warning end --- If ANY actions should be performed when a player misbehaves. ----@param value +---@param value string function Public.enable_capsule_cursor_warning(value) this.enable_capsule_cursor_warning = value or false return this.enable_capsule_cursor_warning end --- If the script should jail a person instead of kicking them ----@param value +---@param value string function Public.enable_jail(value) this.enable_jail = value or false return this.enable_jail end --- Defines what the threshold for amount of explosives in chest should be - logged or not. ----@param value +---@param value string function Public.explosive_threshold(value) if value then this.explosive_threshold = value @@ -950,7 +939,7 @@ function Public.explosive_threshold(value) end --- Defines what the threshold for amount of times before the script should take action. ----@param value +---@param value string function Public.damage_entity_threshold(value) if value then this.damage_entity_threshold = value diff --git a/utils/event.lua b/utils/event.lua index 7a20999c..0f9b4c95 100644 --- a/utils/event.lua +++ b/utils/event.lua @@ -477,7 +477,7 @@ function Event.remove_removable_nth_tick_function(tick, name) local handlers = on_nth_tick_event_handlers[tick] local f = function_nth_tick_table[name] - for k, v in pairs(function_nth_tick_table[name]) do + for _, v in pairs(function_nth_tick_table[name]) do local t = v.tick if t == tick then f = v.handler diff --git a/utils/gui.lua b/utils/gui.lua index 5a90aa1c..d6a0616b 100644 --- a/utils/gui.lua +++ b/utils/gui.lua @@ -298,6 +298,7 @@ local function custom_handler_factory(handlers) end --luacheck: ignore custom_raise +---@diagnostic disable-next-line: unused-function, unused-local local function custom_raise(handlers, element, player) local handler = handlers[element.name] if not handler then @@ -355,8 +356,8 @@ function Public.get_parent_frame(player) end --- This adds the given gui to the top gui. ----@param player ----@param frame +---@param player userdata +---@param frame userdata function Public.add_mod_button(player, frame) if Public.get_button_flow(player)[frame.name] and Public.get_button_flow(player)[frame.name].valid then return @@ -365,7 +366,7 @@ function Public.add_mod_button(player, frame) Public.get_button_flow(player).add(frame) end ----@param state +---@param state boolean --- If we should use the new mod gui or not function Public.set_mod_gui_top_frame(state) settings.mod_gui_top_frame = state or false @@ -377,7 +378,7 @@ function Public.get_mod_gui_top_frame() end --- This adds the given gui to the main gui. ----@param tbl +---@param tbl table function Public.add_tab_to_gui(tbl) if not tbl then return @@ -411,7 +412,7 @@ function Public.screen_to_bypass(elem) end --- Fetches the main gui tabs. You are forbidden to write as this is local. ----@param key +---@param key string function Public.get(key) if key then return main_gui_tabs[key] diff --git a/utils/table.lua b/utils/table.lua index 8d24b99b..70ce292b 100644 --- a/utils/table.lua +++ b/utils/table.lua @@ -1,3 +1,4 @@ +---@diagnostic disable: undefined-field --luacheck: globals table local Stats = require 'utils.stats' local random = math.random From 095895ed81d99cd180a81a9629345d9a6664ab2c Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Thu, 7 Apr 2022 16:12:25 +0200 Subject: [PATCH 6/8] perlin - made it faster when using in loop --- utils/simplex_noise.lua | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/utils/simplex_noise.lua b/utils/simplex_noise.lua index ec0b3715..833ea750 100644 --- a/utils/simplex_noise.lua +++ b/utils/simplex_noise.lua @@ -286,11 +286,6 @@ for i = 0, 511 do perm[i + 1] = p[bit32_band(i, 255) + 1] end --- special case of dot with 3 inputs -local function dot2(g, x, y) - return x * g[1] + y * g[2] -end - local F2 = 0.5 * (math.sqrt(3.0) - 1.0) local G2 = (3.0 - math.sqrt(3.0)) / 6.0 @@ -317,6 +312,7 @@ function Simplex.d2(xin, yin, seed) i1 = 0 j1 = 1 end + -- upper triangle, YX order: (0,0)->(0,1)->(1,1) -- A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and -- a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where @@ -339,7 +335,7 @@ function Simplex.d2(xin, yin, seed) n0 = 0.0 else t0 = t0 * t0 - n0 = t0 * t0 * dot2(grad3[gi0 + 1], x0, y0) -- (x,y) of grad3 used for 2D gradient + n0 = t0 * t0 * (x0 * grad3[gi0 + 1][1] + y0 * grad3[gi0 + 1][2]) -- (x,y) of grad3 used for 2D gradient end local t1 = 0.5 - x1 * x1 - y1 * y1 @@ -347,7 +343,7 @@ function Simplex.d2(xin, yin, seed) n1 = 0.0 else t1 = t1 * t1 - n1 = t1 * t1 * dot2(grad3[gi1 + 1], x1, y1) + n1 = t1 * t1 * (x1 * grad3[gi1 + 1][1] + y1 * grad3[gi1 + 1][2]) end local t2 = 0.5 - x2 * x2 - y2 * y2 @@ -355,7 +351,7 @@ function Simplex.d2(xin, yin, seed) n2 = 0.0 else t2 = t2 * t2 - n2 = t2 * t2 * dot2(grad3[gi2 + 1], x2, y2) + n2 = t2 * t2 * (x2 * grad3[gi2 + 1][1] + y2 * grad3[gi2 + 1][2]) end -- Add contributions from each corner to get the final noise value. From c048002b7d2769e7025a67e6e8e90566dc18801e Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Thu, 7 Apr 2022 16:12:34 +0200 Subject: [PATCH 7/8] gui label fixes --- utils/gui/group.lua | 38 +++++++++++++------- utils/gui/player_list.lua | 6 +++- utils/gui/score.lua | 16 ++++----- utils/gui/server_select.lua | 72 +++++++++++++++++++------------------ 4 files changed, 75 insertions(+), 57 deletions(-) diff --git a/utils/gui/group.lua b/utils/gui/group.lua index c2fa9191..35652038 100644 --- a/utils/gui/group.lua +++ b/utils/gui/group.lua @@ -30,8 +30,8 @@ local function build_group_gui(data) local group_name_width = 150 local description_width = 240 local members_width = 90 - local member_columns = 3 - local actions_width = 80 + local member_columns = 2 + local actions_width = 130 local total_height = frame.style.minimal_height - 60 frame.clear() @@ -46,11 +46,12 @@ local function build_group_gui(data) for _, h in pairs(headings) do local l = t.add({type = 'label', caption = h[1]}) l.style.font_color = {r = 0.98, g = 0.66, b = 0.22} - l.style.font = 'default-listbox' + l.style.font = 'heading-2' l.style.top_padding = 6 l.style.minimal_height = 40 l.style.minimal_width = h[2] l.style.maximal_width = h[2] + l.style.horizontal_align = 'center' end local scroll_pane = @@ -76,11 +77,12 @@ local function build_group_gui(data) for _, group in pairs(this.tag_groups) do if (group.name and group.founder and group.description) then local l = t.add({type = 'label', caption = group.name}) - l.style.font = 'default-bold' l.style.top_padding = 16 l.style.bottom_padding = 16 l.style.minimal_width = group_name_width l.style.maximal_width = group_name_width + l.style.font = 'heading-3' + l.style.horizontal_align = 'center' local color if game.players[group.founder] and game.players[group.founder].color then color = game.players[group.founder].color @@ -97,11 +99,17 @@ local function build_group_gui(data) l.style.maximal_width = description_width l.style.font_color = {r = 0.90, g = 0.90, b = 0.90} l.style.single_line = false + l.style.font = 'heading-3' + l.style.horizontal_align = 'center' - local tt = t.add({type = 'table', column_count = member_columns}) + local tt = t.add({type = 'table', column_count = 2}) + local flow = tt.add({type = 'flow'}) + flow.style.left_padding = 65 + local ttt = tt.add({type = 'table', column_count = member_columns}) + ttt.style.minimal_width = members_width * 2 - 25 for _, p in pairs(game.connected_players) do if group.name == this.player_group[p.name] then - l = tt.add({type = 'label', caption = p.name}) + l = ttt.add({type = 'label', caption = p.name}) color = { r = p.color.r * 0.6 + 0.4, g = p.color.g * 0.6 + 0.4, @@ -109,8 +117,10 @@ local function build_group_gui(data) a = 1 } l.style.font_color = color - --l.style.minimal_width = members_width - l.style.maximal_width = members_width * 2 + l.style.maximal_width = members_width * 2 - 60 + l.style.single_line = false + l.style.font = 'heading-3' + l.style.horizontal_align = 'center' end end @@ -153,10 +163,12 @@ end local build_group_gui_token = Token.register(build_group_gui) local function refresh_gui() - for _, p in pairs(game.connected_players) do - local frame = Gui.get_player_active_frame(p) + local players = game.connected_players + for i = 1, #players do + local player = players[i] + local frame = Gui.get_player_active_frame(player) if frame then - if frame.name == module_name then + if frame.frame2 and frame.frame2.valid then local new_group_name = frame.frame2.group_table.new_group_name.text local new_group_description = frame.frame2.group_table.new_group_description.text @@ -168,10 +180,10 @@ local function refresh_gui() new_group_description = '' end - local data = {player = p, frame = frame} + local data = {player = player, frame = frame} build_group_gui(data) - frame = Gui.get_player_active_frame(p) + frame = Gui.get_player_active_frame(player) frame.frame2.group_table.new_group_name.text = new_group_name frame.frame2.group_table.new_group_description.text = new_group_description end diff --git a/utils/gui/player_list.lua b/utils/gui/player_list.lua index 52cb1df7..7522aed3 100644 --- a/utils/gui/player_list.lua +++ b/utils/gui/player_list.lua @@ -576,7 +576,7 @@ local function player_list_show(data) name = 'player_list_panel_header_' .. k, caption = v } - header_label.style.font = 'default-bold' + header_label.style.font = 'heading-2' header_label.style.font_color = {r = 0.98, g = 0.66, b = 0.22} end @@ -677,6 +677,7 @@ local function player_list_show(data) } name_label.style.minimal_width = column_widths['name_label'] name_label.style.maximal_width = column_widths['name_label'] + name_label.style.font = 'heading-3' -- RPG level if this.rpg_enabled then @@ -689,6 +690,7 @@ local function player_list_show(data) } rpg_level_label.style.minimal_width = column_widths['rpg_level_label'] rpg_level_label.style.maximal_width = column_widths['rpg_level_label'] + rpg_level_label.style.font = 'heading-3' end -- Total time @@ -700,6 +702,7 @@ local function player_list_show(data) } total_label.style.minimal_width = column_widths['total_label'] total_label.style.maximal_width = column_widths['total_label'] + total_label.style.font = 'heading-3' -- Current time local current_label = @@ -710,6 +713,7 @@ local function player_list_show(data) } current_label.style.minimal_width = column_widths['current_label'] current_label.style.maximal_width = column_widths['current_label'] + current_label.style.font = 'heading-3' -- Poke local flow = player_list_panel_table.add {type = 'flow', name = 'button_flow_' .. i, direction = 'horizontal'} diff --git a/utils/gui/score.lua b/utils/gui/score.lua index baee7819..6b651d5f 100644 --- a/utils/gui/score.lua +++ b/utils/gui/score.lua @@ -127,22 +127,22 @@ local function add_global_stats(frame, player) local t = frame.add {type = 'table', column_count = 5} local l = t.add {type = 'label', caption = 'Rockets launched: '} - l.style.font = 'default-game' + l.style.font = 'heading-2' l.style.font_color = {r = 175, g = 75, b = 255} l.style.minimal_width = 140 local rocketsLaunched_label = t.add {type = 'label', caption = format_number(player.force.rockets_launched, true)} - rocketsLaunched_label.style.font = 'default-listbox' + rocketsLaunched_label.style.font = 'heading-3' rocketsLaunched_label.style.font_color = {r = 0.9, g = 0.9, b = 0.9} rocketsLaunched_label.style.minimal_width = 123 local bugs_dead_label = t.add {type = 'label', caption = 'Dead bugs: '} - bugs_dead_label.style.font = 'default-game' + bugs_dead_label.style.font = 'heading-2' bugs_dead_label.style.font_color = {r = 0.90, g = 0.3, b = 0.3} bugs_dead_label.style.minimal_width = 100 local killcount_label = t.add {type = 'label', caption = format_number(tonumber(get_total_biter_killcount(player.force)), true)} - killcount_label.style.font = 'default-listbox' + killcount_label.style.font = 'heading-3' killcount_label.style.font_color = {r = 0.9, g = 0.9, b = 0.9} killcount_label.style.minimal_width = 145 end @@ -191,10 +191,10 @@ local function show_score(data) caption = cap, name = header.name } - label.style.font = 'default-listbox' + label.style.font = 'heading-2' label.style.font_color = {r = 0.98, g = 0.66, b = 0.22} -- yellow label.style.minimal_width = 150 - label.style.horizontal_align = 'right' + label.style.horizontal_align = 'center' end -- Score list @@ -243,10 +243,10 @@ local function show_score(data) caption = column.caption, color = column.color or default_color } - label.style.font = 'default' + label.style.font = 'heading-3' label.style.minimal_width = 150 label.style.maximal_width = 150 - label.style.horizontal_align = 'right' + label.style.horizontal_align = 'center' end -- foreach column end -- foreach entry end diff --git a/utils/gui/server_select.lua b/utils/gui/server_select.lua index 997708ed..ddde5d00 100644 --- a/utils/gui/server_select.lua +++ b/utils/gui/server_select.lua @@ -66,42 +66,44 @@ local function draw_main_frame(player) } else for _, i in ipairs(instances) do - viewer_table.add { - type = 'label', - caption = i.name, - tooltip = i.connected .. '\nVersion: ' .. i.version, - style = 'caption_label' - } - local flow = viewer_table.add {type = 'flow'} - flow.style.horizontal_align = 'right' - flow.style.horizontally_stretchable = true - local empty_flow = viewer_table.add {type = 'flow'} - local button = - empty_flow.add { - type = 'button', - caption = 'Connect', - tooltip = 'Click to connect to this server.\n' .. i.connected .. '\nVersion: ' .. i.version, - name = instance_id_name - } - Gui.set_data(button, i.id) - apply_button_style(button) + if string.len(i.name) > 1 then + viewer_table.add { + type = 'label', + caption = i.name, + tooltip = i.connected .. '\nVersion: ' .. i.version, + style = 'caption_label' + } + local flow = viewer_table.add {type = 'flow'} + flow.style.horizontal_align = 'right' + flow.style.horizontally_stretchable = true + local empty_flow = viewer_table.add {type = 'flow'} + local button = + empty_flow.add { + type = 'button', + caption = 'Connect', + tooltip = 'Click to connect to this server.\n' .. i.connected .. '\nVersion: ' .. i.version, + name = instance_id_name + } + Gui.set_data(button, i.id) + apply_button_style(button) - if i.id == instance.id then - button.enabled = false - button.tooltip = 'You are here' - elseif i.status == 'unknown' then - button.enabled = i.game_port ~= nil - button.style.font_color = {r = 0.65} - button.style.hovered_font_color = {r = 0.65} - button.style.clicked_font_color = {r = 0.65} - button.style.disabled_font_color = {r = 0.75, g = 0.1, b = 0.1} - button.tooltip = 'Unknown status for this server' - elseif i.status ~= 'running' then - button.enabled = false - button.tooltip = 'This server is offline' - elseif i.version ~= instance.version then - button.enabled = false - button.tooltip = "We're on version: " .. instance.version .. '\nDestination server is on version: ' .. i.version + if i.id == instance.id then + button.enabled = false + button.tooltip = 'You are here' + elseif i.status == 'unknown' then + button.enabled = i.game_port ~= nil + button.style.font_color = {r = 0.65} + button.style.hovered_font_color = {r = 0.65} + button.style.clicked_font_color = {r = 0.65} + button.style.disabled_font_color = {r = 0.75, g = 0.1, b = 0.1} + button.tooltip = 'Unknown status for this server' + elseif i.status ~= 'running' then + button.enabled = false + button.tooltip = 'This server is offline' + elseif i.version ~= instance.version then + button.enabled = false + button.tooltip = "We're on version: " .. instance.version .. '\nDestination server is on version: ' .. i.version + end end end end From 5bbd70443804cbb68f172b6ed2a7a356fb91e87a Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Thu, 7 Apr 2022 16:12:47 +0200 Subject: [PATCH 8/8] Added new function to iterate over all connected players --- utils/core.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/utils/core.lua b/utils/core.lua index 4269e0db..27839b0b 100644 --- a/utils/core.lua +++ b/utils/core.lua @@ -103,6 +103,16 @@ function Public.get_actor() return '' end +--- Iterates over all connected players +---@param callback function +function Public.iter_connected_players(callback) + local players = game.connected_players + for i = 1, #players do + local player = players[i] + callback(player) + end +end + function Public.cast_bool(var) if var then return true