diff --git a/README.md b/README.md index dd0ccf8..c54d413 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,12 @@ # ChangeMapSettings -Allows you to change your map settings at any time you want. +Allows you to change your map and map generation settings at any time you want. Note that map generation changes only apply to new chunks. -## Settings that can be changed: - -General: - -* Peaceful mode enabled/disabled - -Pollution: - -* Enabled/Disabled -* Diffusion ratio in percent -> The amount of pollution diffused into neighboring chunks per second. -* Dissipation rate -> Controls how fast pollution dissipates naturally. -* Minimum to damage trees -> Any pollution above this amount starts to damage trees. -* Absorbed per damaged tree -> The amount of pollution absorbed by a tree when it is damaged by pollution. - -Evolution: - -* Enabled/Disabled -* Evolution -> Current enemy evolution (factor) -* Time factor -> Controls how fast evolution increases over time. -* Destroy factor -> Controls how fast evolution increases due to destroying enemy spawners. -* Pollution factor -> Controls how fast evolution increases due to producing pollution. - -Enemy expansion: +## Changelog: -* Enabled/Disabled -* Maximum expansion distance -> The maximum distance enemies will look to expand from other enemy bases. -* Minimum group size -> The minimum size of an enemy expansion party modified by the current evolution level. -* Maximum group size -> The maximum size of an enemy expansion party modified by the current evolution level. -* Minimum cooldown in minutes -> The minimum time between enemy expansions being sent out. -* Maximum cooldown in minutes -> The maximum time between enemy expansions being sent out. +2.1.0 -## Changelog: +* Added map generation options 2.0.0 diff --git a/control.lua b/control.lua index afc5a19..e460938 100644 --- a/control.lua +++ b/control.lua @@ -3,231 +3,429 @@ local gui = require("gui") local util = require("utilities") local function reset_to_default(player) - local frame_flow = mod_gui.get_frame_flow(player) - local more_config_table = frame_flow["change-map-settings-config-more-frame"]["change-map-settings-config-more-table"] - --General - local general_table = more_config_table["change-map-settings-config-more-general-flow"]["change-map-settings-config-more-general-table"] - general_table["change-map-settings-peaceful-checkbox"].state = false - -- MAP SETTINGS -- - --Evolution - local evo_table = more_config_table["change-map-settings-config-more-evo-flow"]["change-map-settings-config-more-evo-table"] - evo_table["change-map-settings-evolution-checkbox"].state = true - evo_table["change-map-settings-evolution-factor-textfield"].text = "0" - evo_table["change-map-settings-evolution-time-textfield"].text = "0.000004" - evo_table["change-map-settings-evolution-destroy-textfield"].text = "0.002000" - evo_table["change-map-settings-evolution-pollution-textfield"].text = "0.000015" - --Pollution - local pollution_table = more_config_table["change-map-settings-config-more-pollution-flow"]["change-map-settings-config-more-pollution-table"] - pollution_table["change-map-settings-pollution-checkbox"].state = true - pollution_table["change-map-settings-pollution-diffusion-textfield"].text = "2" - pollution_table["change-map-settings-pollution-dissipation-textfield"].text = "1" - pollution_table["change-map-settings-pollution-tree-dmg-textfield"].text = "3500" - pollution_table["change-map-settings-pollution-tree-absorb-textfield"].text = "500" - --Enemy expansion - local expansion_table = more_config_table["change-map-settings-config-more-expansion-flow"]["change-map-settings-config-more-expansion-table"] - expansion_table["change-map-settings-enemy-expansion-checkbox"].state = true - expansion_table["change-map-settings-expansion-distance-textfield"].text = "7" - expansion_table["change-map-settings-expansion-min-size-textfield"].text = "5" - expansion_table["change-map-settings-expansion-max-size-textfield"].text = "20" - expansion_table["change-map-settings-expansion-min-cd-textfield"].text = "4" - expansion_table["change-map-settings-expansion-max-cd-textfield"].text = "60" + local frame_flow = mod_gui.get_frame_flow(player) + local config_table = frame_flow["change-map-settings-main-flow"]["change-map-settings-config-frame"]["change-map-settings-config-table"] + --General + local general_table = config_table["change-map-settings-config-more-general-flow"]["change-map-settings-config-more-general-table"] + general_table["change-map-settings-peaceful-checkbox"].state = false + -- MAP SETTINGS -- + --Evolution + local evo_table = config_table["change-map-settings-config-more-evo-flow"]["change-map-settings-config-more-evo-table"] + evo_table["change-map-settings-evolution-checkbox"].state = true + evo_table["change-map-settings-evolution-factor-textfield"].text = "0" + evo_table["change-map-settings-evolution-time-textfield"].text = "0.000004" + evo_table["change-map-settings-evolution-destroy-textfield"].text = "0.002000" + evo_table["change-map-settings-evolution-pollution-textfield"].text = "0.000015" + --Pollution + local pollution_table = config_table["change-map-settings-config-more-pollution-flow"]["change-map-settings-config-more-pollution-table"] + pollution_table["change-map-settings-pollution-checkbox"].state = true + pollution_table["change-map-settings-pollution-diffusion-textfield"].text = "2" + pollution_table["change-map-settings-pollution-dissipation-textfield"].text = "1" + pollution_table["change-map-settings-pollution-tree-dmg-textfield"].text = "3500" + pollution_table["change-map-settings-pollution-tree-absorb-textfield"].text = "500" + --Enemy expansion + local expansion_table = config_table["change-map-settings-config-more-expansion-flow"]["change-map-settings-config-more-expansion-table"] + expansion_table["change-map-settings-enemy-expansion-checkbox"].state = true + expansion_table["change-map-settings-expansion-distance-textfield"].text = "7" + expansion_table["change-map-settings-expansion-min-size-textfield"].text = "5" + expansion_table["change-map-settings-expansion-max-size-textfield"].text = "20" + expansion_table["change-map-settings-expansion-min-cd-textfield"].text = "4" + expansion_table["change-map-settings-expansion-max-cd-textfield"].text = "60" end -local function use_current_map_gen(player) - local frame_flow = mod_gui.get_frame_flow(player) - local more_config_table = frame_flow["change-map-settings-config-more-frame"]["change-map-settings-config-more-table"] - --General - local general_table = more_config_table["change-map-settings-config-more-general-flow"]["change-map-settings-config-more-general-table"] - general_table["change-map-settings-peaceful-checkbox"].state = player.surface.peaceful_mode - -- MAP SETTINGS -- - local map_settings = game.map_settings - --Evolution - local evo_table = more_config_table["change-map-settings-config-more-evo-flow"]["change-map-settings-config-more-evo-table"] - evo_table["change-map-settings-evolution-checkbox"].state = map_settings.enemy_evolution.enabled - evo_table["change-map-settings-evolution-factor-textfield"].text = util.float_to_string(game.forces["enemy"].evolution_factor) - evo_table["change-map-settings-evolution-time-textfield"].text = util.float_to_string(map_settings.enemy_evolution.time_factor) - evo_table["change-map-settings-evolution-destroy-textfield"].text = util.float_to_string(map_settings.enemy_evolution.destroy_factor) - evo_table["change-map-settings-evolution-pollution-textfield"].text = util.float_to_string(map_settings.enemy_evolution.pollution_factor) - --Pollution - local pollution_table = more_config_table["change-map-settings-config-more-pollution-flow"]["change-map-settings-config-more-pollution-table"] - pollution_table["change-map-settings-pollution-checkbox"].state = map_settings.pollution.enabled - pollution_table["change-map-settings-pollution-diffusion-textfield"].text = tostring(map_settings.pollution.diffusion_ratio * 100) - pollution_table["change-map-settings-pollution-dissipation-textfield"].text = tostring(map_settings.pollution.ageing) - pollution_table["change-map-settings-pollution-tree-dmg-textfield"].text = tostring(map_settings.pollution.min_pollution_to_damage_trees) - pollution_table["change-map-settings-pollution-tree-absorb-textfield"].text = tostring(map_settings.pollution.pollution_restored_per_tree_damage) - --Enemy expansion - local expansion_table = more_config_table["change-map-settings-config-more-expansion-flow"]["change-map-settings-config-more-expansion-table"] - expansion_table["change-map-settings-enemy-expansion-checkbox"].state = map_settings.enemy_expansion.enabled - expansion_table["change-map-settings-expansion-distance-textfield"].text = tostring(map_settings.enemy_expansion.max_expansion_distance) - expansion_table["change-map-settings-expansion-min-size-textfield"].text = tostring(map_settings.enemy_expansion.settler_group_min_size) - expansion_table["change-map-settings-expansion-max-size-textfield"].text = tostring(map_settings.enemy_expansion.settler_group_max_size) - expansion_table["change-map-settings-expansion-min-cd-textfield"].text = tostring(map_settings.enemy_expansion.min_expansion_cooldown / 3600) - expansion_table["change-map-settings-expansion-max-cd-textfield"].text = tostring(map_settings.enemy_expansion.max_expansion_cooldown / 3600) +local function set_to_current_map_gen_settings(player) + local frame_flow = mod_gui.get_frame_flow(player) + local surface = player.surface + local map_gen_settings = surface.map_gen_settings + -- general options -- + local map_gen_frame = frame_flow["change-map-settings-main-flow"]["change-map-settings-map-gen-frame"] + + map_gen_frame["change-map-settings-seed-table"]["change-map-settings-seed-textfield"].text = tostring(map_gen_settings.seed) + + -- MAP GEN SETTINGS -- + -- resource table -- + local resource_table = map_gen_frame["change-map-settings-resource-scroll-pane"]["change-map-settings-resource-table"] + local terrain_table = map_gen_frame["change-map-settings-resource-scroll-pane"]["change-map-settings-terrain-table"] + local resources = util.get_table_of_resources() + local none_lookup = { + ["none"] = 1, + ["very-low"] = 2, + ["low"] = 3, + ["normal"] = 4, + ["high"] = 5, + ["very-high"] = 6 + } + local lookup = { + ["very-low"] = 1, + ["low"] = 2, + ["normal"] = 3, + ["high"] = 4, + ["very-high"] = 5 + } + --water stuff + terrain_table["change-map-settings-map-gen-water-freq"].selected_index = lookup[map_gen_settings.terrain_segmentation] + terrain_table["change-map-settings-map-gen-water-size"].selected_index = none_lookup[map_gen_settings.water] + --starting area + terrain_table["change-map-settings-map-gen-starting-area-size"].selected_index = lookup[map_gen_settings.starting_area] + -- resources and terrain + local autoplace_controls = map_gen_settings.autoplace_controls + for resource, tbl in pairs(autoplace_controls) do + if resources[resource] then + resource_table["change-map-settings-map-gen-" .. resource .. "-freq"].selected_index = lookup[tbl["frequency"]] + resource_table["change-map-settings-map-gen-" .. resource .. "-size"].selected_index = none_lookup[tbl["size"]] + resource_table["change-map-settings-map-gen-" .. resource .. "-richn"].selected_index = lookup[tbl["richness"]] + else + terrain_table["change-map-settings-map-gen-" .. resource .. "-freq"].selected_index = lookup[tbl["frequency"]] + terrain_table["change-map-settings-map-gen-" .. resource .. "-size"].selected_index = none_lookup[tbl["size"]] + if terrain_table["change-map-settings-map-gen-" .. resource .. "-richn"] then + terrain_table["change-map-settings-map-gen-" .. resource .. "-richn"].selected_index = lookup[tbl["richness"]] + end + end + end + + local cliff_freq_index_lookup = { + [40] = 1, + [20] = 2, + [10] = 3, + [5] = 4, + [2.5] = 5 + } + local cliff_size_index_lookup = { + [1024] = 1, + [40] = 2, + [20] = 3, + [10] = 4, + [5] = 5, + [2.5] = 6 + } + local cliff_settings = map_gen_settings.cliff_settings + terrain_table["change-map-settings-map-gen-cliffs-freq"].selected_index = cliff_freq_index_lookup[math.floor(cliff_settings.cliff_elevation_interval*10)/10] --floor to 1 digit after the decimal point -> 2.55 => 2.5 + terrain_table["change-map-settings-map-gen-cliffs-size"].selected_index = cliff_size_index_lookup[math.floor(cliff_settings.cliff_elevation_0*10)/10] +end + +local function set_to_current_map_settings(player) + local frame_flow = mod_gui.get_frame_flow(player) + local config_table = frame_flow["change-map-settings-main-flow"]["change-map-settings-config-frame"]["change-map-settings-config-table"] + --General + local general_table = config_table["change-map-settings-config-more-general-flow"]["change-map-settings-config-more-general-table"] + general_table["change-map-settings-peaceful-checkbox"].state = player.surface.peaceful_mode + -- MAP SETTINGS -- + local map_settings = game.map_settings + --Evolution + local evo_table = config_table["change-map-settings-config-more-evo-flow"]["change-map-settings-config-more-evo-table"] + evo_table["change-map-settings-evolution-checkbox"].state = map_settings.enemy_evolution.enabled + evo_table["change-map-settings-evolution-factor-textfield"].text = util.float_to_string(game.forces["enemy"].evolution_factor) + evo_table["change-map-settings-evolution-time-textfield"].text = util.float_to_string(map_settings.enemy_evolution.time_factor) + evo_table["change-map-settings-evolution-destroy-textfield"].text = util.float_to_string(map_settings.enemy_evolution.destroy_factor) + evo_table["change-map-settings-evolution-pollution-textfield"].text = util.float_to_string(map_settings.enemy_evolution.pollution_factor) + --Pollution + local pollution_table = config_table["change-map-settings-config-more-pollution-flow"]["change-map-settings-config-more-pollution-table"] + pollution_table["change-map-settings-pollution-checkbox"].state = map_settings.pollution.enabled + pollution_table["change-map-settings-pollution-diffusion-textfield"].text = tostring(map_settings.pollution.diffusion_ratio * 100) + pollution_table["change-map-settings-pollution-dissipation-textfield"].text = tostring(map_settings.pollution.ageing) + pollution_table["change-map-settings-pollution-tree-dmg-textfield"].text = tostring(map_settings.pollution.min_pollution_to_damage_trees) + pollution_table["change-map-settings-pollution-tree-absorb-textfield"].text = tostring(map_settings.pollution.pollution_restored_per_tree_damage) + --Enemy expansion + local expansion_table = config_table["change-map-settings-config-more-expansion-flow"]["change-map-settings-config-more-expansion-table"] + expansion_table["change-map-settings-enemy-expansion-checkbox"].state = map_settings.enemy_expansion.enabled + expansion_table["change-map-settings-expansion-distance-textfield"].text = tostring(map_settings.enemy_expansion.max_expansion_distance) + expansion_table["change-map-settings-expansion-min-size-textfield"].text = tostring(map_settings.enemy_expansion.settler_group_min_size) + expansion_table["change-map-settings-expansion-max-size-textfield"].text = tostring(map_settings.enemy_expansion.settler_group_max_size) + expansion_table["change-map-settings-expansion-min-cd-textfield"].text = tostring(map_settings.enemy_expansion.min_expansion_cooldown / 3600) + expansion_table["change-map-settings-expansion-max-cd-textfield"].text = tostring(map_settings.enemy_expansion.max_expansion_cooldown / 3600) end --- WOLRD GEN -- local function change_map_settings(player) - local frame_flow = mod_gui.get_frame_flow(player) - local more_config_table = frame_flow["change-map-settings-config-more-frame"]["change-map-settings-config-more-table"] - --General - local general_table = more_config_table["change-map-settings-config-more-general-flow"]["change-map-settings-config-more-general-table"] - for _, surface in pairs(game.surfaces) do - surface.peaceful_mode = general_table["change-map-settings-peaceful-checkbox"].state - end - -- MAP SETTINGS -- - local map_settings = game.map_settings - --Evolution - local evo_table = more_config_table["change-map-settings-config-more-evo-flow"]["change-map-settings-config-more-evo-table"] - map_settings.enemy_evolution.enabled = evo_table["change-map-settings-evolution-checkbox"].state - local evolution_factor = util.textfield_to_number(evo_table["change-map-settings-evolution-factor-textfield"]) - if evolution_factor and (evolution_factor >= 0) and (evolution_factor <= 1) then - game.forces["enemy"].evolution_factor = evolution_factor - else - player.print({"msg.change-map-settings-invalid-evolution-factor"}) - return false - end - local evolution_time = util.textfield_to_number(evo_table["change-map-settings-evolution-time-textfield"]) - if evolution_time and (evolution_time >= 0) and (evolution_time <= 0.0001) then - map_settings.enemy_evolution.time_factor = evolution_time - else - player.print({"msg.change-map-settings-invalid-evolution-time"}) - return false - end - local evolution_destroy = util.textfield_to_number(evo_table["change-map-settings-evolution-destroy-textfield"]) - if evolution_destroy and (evolution_destroy >= 0) and (evolution_destroy <= 0.01) then - map_settings.enemy_evolution.destroy_factor = evolution_destroy - else - player.print({"msg.change-map-settings-invalid-evolution-destroy"}) - return false - end - local evolution_pollution = util.textfield_to_number(evo_table["change-map-settings-evolution-pollution-textfield"]) - if evolution_pollution and (evolution_pollution >= 0) and (evolution_pollution <= 0.0001) then - map_settings.enemy_evolution.pollution_factor = evolution_pollution - else - player.print({"msg.change-map-settings-invalid-evolution-pollution"}) - return false - end - --Pollution - local pollution_table = more_config_table["change-map-settings-config-more-pollution-flow"]["change-map-settings-config-more-pollution-table"] - local pollution_enabled = pollution_table["change-map-settings-pollution-checkbox"].state - if (pollution_enabled ~= map_settings.pollution.enabled) and (pollution_enabled == false) then - for _, surface in pairs(game.surfaces) do - surface.clear_pollution() - end - end - map_settings.pollution.enabled = pollution_table["change-map-settings-pollution-checkbox"].state - local pollution_diffusion = util.textfield_to_uint(pollution_table["change-map-settings-pollution-diffusion-textfield"]) - if pollution_diffusion and (pollution_diffusion >= 0) and (pollution_diffusion <= 25) then - map_settings.pollution.diffusion_ratio = (pollution_diffusion / 100) - else - player.print({"msg.change-map-settings-invalid-pollution-diffusion"}) - return false - end - local pollution_dissipation = util.textfield_to_uint(pollution_table["change-map-settings-pollution-dissipation-textfield"]) - if pollution_dissipation and (pollution_dissipation > 0) and (pollution_dissipation <= 1000) then - map_settings.pollution.ageing = pollution_dissipation - else - player.print({"msg.change-map-settings-invalid-pollution-dissipation"}) - return false - end - local pollution_tree_dmg = util.textfield_to_uint(pollution_table["change-map-settings-pollution-tree-dmg-textfield"]) - if pollution_tree_dmg and (pollution_tree_dmg >= 0) and (pollution_tree_dmg <= 9999) then - map_settings.pollution.min_pollution_to_damage_trees = pollution_tree_dmg - else - player.print({"msg.change-map-settings-invalid-pollution-tree-dmg"}) - return false - end - local pollution_tree_absorb = util.textfield_to_uint(pollution_table["change-map-settings-pollution-tree-absorb-textfield"]) - if pollution_tree_absorb and (pollution_tree_absorb >= 0) and (pollution_tree_absorb <= 9999) then - map_settings.pollution.pollution_restored_per_tree_damage = pollution_tree_absorb - else - player.print({"msg.change-map-settings-invalid-pollution-tree-absorb"}) - return false - end - --Enemy expansion - local expansion_table = more_config_table["change-map-settings-config-more-expansion-flow"]["change-map-settings-config-more-expansion-table"] - map_settings.enemy_expansion.enabled = expansion_table["change-map-settings-enemy-expansion-checkbox"].state - local expansion_distance = util.textfield_to_uint(expansion_table["change-map-settings-expansion-distance-textfield"]) - if expansion_distance and (expansion_distance >= 2) and (expansion_distance <= 20) then - map_settings.enemy_expansion.max_expansion_distance = expansion_distance - else - player.print({"msg.change-map-settings-invalid-expansion-distance"}) - return false - end - local expansion_min_size = util.textfield_to_uint(expansion_table["change-map-settings-expansion-min-size-textfield"]) - if expansion_min_size and (expansion_min_size >= 1) and (expansion_min_size <= 20) then - map_settings.enemy_expansion.settler_group_min_size = expansion_min_size - else - player.print({"msg.change-map-settings-invalid-expansion-min-size"}) - return false - end - local expansion_max_size = util.textfield_to_uint(expansion_table["change-map-settings-expansion-max-size-textfield"]) - if expansion_max_size and (expansion_max_size >= 1) and (expansion_max_size <= 50) then - if expansion_max_size < map_settings.enemy_expansion.settler_group_min_size then - player.print({"msg.change-map-settings-too-low-expansion-max-size"}) - return false - else - map_settings.enemy_expansion.settler_group_max_size = expansion_max_size - end - else - player.print({"msg.change-map-settings-invalid-expansion-max-size"}) - return false - end - local expansion_min_cd = util.textfield_to_uint(expansion_table["change-map-settings-expansion-min-cd-textfield"]) - if expansion_min_cd and (expansion_min_cd >= 1) and (expansion_min_cd <= 60) then - map_settings.enemy_expansion.min_expansion_cooldown = (expansion_min_cd * 3600) - else - player.print({"msg.change-map-settings-invalid-expansion-min-cd"}) - return false - end - local expansion_max_cd = util.textfield_to_uint(expansion_table["change-map-settings-expansion-max-cd-textfield"]) - if expansion_max_cd and (expansion_max_cd >= 5) and (expansion_max_cd <= 180) then - if expansion_max_cd < (map_settings.enemy_expansion.min_expansion_cooldown / 3600) then - player.print({"msg.change-map-settings-too-low-expansion-max-cd"}) - return false - else - map_settings.enemy_expansion.max_expansion_cooldown = (expansion_max_cd * 3600) - end - else - player.print({"msg.change-map-settings-invalid-expansion-max-cd"}) - return false - end - for _, plyr in pairs(game.players) do - gui.regen(plyr) - end + local frame_flow = mod_gui.get_frame_flow(player) + local config_table = frame_flow["change-map-settings-main-flow"]["change-map-settings-config-frame"]["change-map-settings-config-table"] + + -- Reading everything out + local general_table = config_table["change-map-settings-config-more-general-flow"]["change-map-settings-config-more-general-table"] + local peaceful_mode = general_table["change-map-settings-peaceful-checkbox"].state + local map_settings = game.map_settings + -- Evolution + local evo_table = config_table["change-map-settings-config-more-evo-flow"]["change-map-settings-config-more-evo-table"] + local evolution_enabled = evo_table["change-map-settings-evolution-checkbox"].state + local evolution_factor = util.check_bounds(util.textfield_to_number(evo_table["change-map-settings-evolution-factor-textfield"]), + 0, 1, + player, {"msg.change-map-settings-invalid-evolution-factor"}) + if not evolution_factor then return end + local evolution_time = util.check_bounds(util.textfield_to_number(evo_table["change-map-settings-evolution-time-textfield"]), + 0, 0.0001, + player, {"msg.change-map-settings-invalid-evolution-time"}) + if not evolution_time then return end + local evolution_destroy = util.check_bounds(util.textfield_to_number(evo_table["change-map-settings-evolution-destroy-textfield"]), + 0, 0.01, + player, {"msg.change-map-settings-invalid-evolution-destroy"}) + if not evolution_destroy then return end + local evolution_pollution = util.check_bounds(util.textfield_to_number(evo_table["change-map-settings-evolution-pollution-textfield"]), + 0, 0.0001, + player, {"msg.change-map-settings-invalid-evolution-pollution"}) + if not evolution_pollution then return end + -- Pollution + local pollution_table = config_table["change-map-settings-config-more-pollution-flow"]["change-map-settings-config-more-pollution-table"] + local pollution_enabled = pollution_table["change-map-settings-pollution-checkbox"].state + local pollution_diffusion = util.check_bounds(util.textfield_to_uint(pollution_table["change-map-settings-pollution-diffusion-textfield"]), + 0, 25, + player, {"msg.change-map-settings-invalid-pollution-diffusion"}) + if not pollution_diffusion then return end + local pollution_dissipation = util.check_bounds(util.textfield_to_uint(pollution_table["change-map-settings-pollution-dissipation-textfield"]), + 0, 1000, + player, {"msg.change-map-settings-invalid-pollution-dissipation"}) + if not pollution_dissipation then return end + local pollution_tree_dmg = util.check_bounds(util.textfield_to_uint(pollution_table["change-map-settings-pollution-tree-dmg-textfield"]), + 0, 9999, + player, {"msg.change-map-settings-invalid-pollution-tree-dmg"}) + if not pollution_tree_dmg then return end + local pollution_tree_absorb = util.check_bounds(util.textfield_to_uint(pollution_table["change-map-settings-pollution-tree-absorb-textfield"]), + 0, 9999, + player, {"msg.change-map-settings-invalid-pollution-tree-absorb"}) + if not pollution_tree_absorb then return end + -- Enemy expansion + local expansion_table = config_table["change-map-settings-config-more-expansion-flow"]["change-map-settings-config-more-expansion-table"] + local expansion_enabled = expansion_table["change-map-settings-enemy-expansion-checkbox"].state + local expansion_distance = util.check_bounds(util.textfield_to_uint(expansion_table["change-map-settings-expansion-distance-textfield"]), + 2, 20, + player, {"msg.change-map-settings-invalid-expansion-distance"}) + if not expansion_distance then return end + local expansion_min_size = util.check_bounds(util.textfield_to_uint(expansion_table["change-map-settings-expansion-min-size-textfield"]), + 1, 20, + player, {"msg.change-map-settings-invalid-expansion-min-size"}) + if not expansion_min_size then return end + local expansion_max_size = util.check_bounds(util.textfield_to_uint(expansion_table["change-map-settings-expansion-max-size-textfield"]), + math.max(expansion_min_size, 1), 50, + player, {"msg.change-map-settings-invalid-expansion-max-size"}) + if not expansion_max_size then return end + local expansion_min_cd = util.check_bounds(util.textfield_to_uint(expansion_table["change-map-settings-expansion-min-cd-textfield"]), + 1, 60, + player, {"msg.change-map-settings-invalid-expansion-min-cd"}) + if not expansion_min_cd then return end + local expansion_max_cd = util.check_bounds(util.textfield_to_uint(expansion_table["change-map-settings-expansion-max-cd-textfield"]), + math.max(expansion_min_cd, 5), 180, + player, {"msg.change-map-settings-invalid-expansion-max-cd"}) + if not expansion_max_cd then return end + + -- And now to apply it all + for _, surface in pairs(game.surfaces) do + surface.peaceful_mode = peaceful_mode + end + + map_settings.enemy_evolution.enabled = evolution_enabled + game.forces["enemy"].evolution_factor = evolution_factor + map_settings.enemy_evolution.time_factor = evolution_time + map_settings.enemy_evolution.destroy_factor = evolution_destroy + map_settings.enemy_evolution.pollution_factor = evolution_pollution + + if (pollution_enabled ~= map_settings.pollution.enabled) and (pollution_enabled == false) then + for _, surface in pairs(game.surfaces) do + surface.clear_pollution() + end + end + map_settings.pollution.enabled = pollution_enabled + map_settings.pollution.diffusion_ratio = (pollution_diffusion / 100) + map_settings.pollution.ageing = pollution_dissipation + map_settings.pollution.min_pollution_to_damage_trees = pollution_tree_dmg + map_settings.pollution.pollution_restored_per_tree_damage = pollution_tree_absorb + + map_settings.enemy_expansion.enabled = expansion_enabled + map_settings.enemy_expansion.max_expansion_distance = expansion_distance + map_settings.enemy_expansion.settler_group_min_size = expansion_min_size + map_settings.enemy_expansion.settler_group_max_size = expansion_max_size + map_settings.enemy_expansion.min_expansion_cooldown = (expansion_min_cd * 3600) + map_settings.enemy_expansion.max_expansion_cooldown = (expansion_max_cd * 3600) + + player.print({"msg.change-map-settings-applied"}) + + -- Update the values shown in everyones gui + for _, plyr in pairs(game.players) do + gui.regen(plyr) + set_to_current_map_gen_settings(plyr) + local frame_flow = mod_gui.get_frame_flow(plyr) + frame_flow["change-map-settings-main-flow"].style.visible = true + end +end + +local function reset_map_gen_to_default(player) + local frame_flow = mod_gui.get_frame_flow(player) + -- general options -- + local map_gen_frame = frame_flow["change-map-settings-main-flow"]["change-map-settings-map-gen-frame"] + + map_gen_frame["change-map-settings-seed-table"]["change-map-settings-seed-textfield"].text = 0 + + -- MAP GEN SETTINGS -- + -- resource table -- + local resource_table = map_gen_frame["change-map-settings-resource-scroll-pane"]["change-map-settings-resource-table"] + local terrain_table = map_gen_frame["change-map-settings-resource-scroll-pane"]["change-map-settings-terrain-table"] + local resources = util.get_table_of_resources() + --water stuff + terrain_table["change-map-settings-map-gen-water-freq"].selected_index = 3 + terrain_table["change-map-settings-map-gen-water-size"].selected_index = 4 + --starting area + terrain_table["change-map-settings-map-gen-starting-area-size"].selected_index = 3 + -- resources and terrain + local autoplace_control_prototypes = game.autoplace_control_prototypes + for _, control in pairs(autoplace_control_prototypes) do + if resources[control.name] then + resource_table["change-map-settings-map-gen-" .. control.name .. "-freq"].selected_index = 3 + resource_table["change-map-settings-map-gen-" .. control.name .. "-size"].selected_index = 4 + resource_table["change-map-settings-map-gen-" .. control.name .. "-richn"].selected_index = 3 + else + terrain_table["change-map-settings-map-gen-" .. control.name .. "-freq"].selected_index = 3 + terrain_table["change-map-settings-map-gen-" .. control.name .. "-size"].selected_index = 4 + if control.richness then terrain_table["change-map-settings-map-gen-" .. control.name .. "-richn"].selected_index = 3 end + end + end + --cliffs + terrain_table["change-map-settings-map-gen-cliffs-freq"].selected_index = 3 + terrain_table["change-map-settings-map-gen-cliffs-size"].selected_index = 4 +end + +local function change_map_gen_settings(player) + local frame_flow = mod_gui.get_frame_flow(player) + local map_gen_frame = frame_flow["change-map-settings-main-flow"]["change-map-settings-map-gen-frame"] + + local map_gen_settings = {} + --general things + local seed = util.textfield_to_uint(map_gen_frame["change-map-settings-seed-table"]["change-map-settings-seed-textfield"]) + if seed and seed == 0 then + map_gen_settings.seed = math.random(0, 4294967295) + elseif seed then + map_gen_settings.seed = seed + else + player.print({"msg.change-map-settings-invalid-seed"}) + return nil + end + + -- Autoplace controls -- + local freq_options = {"very-low", "low", "normal", "high", "very-high"} + local size_options = {"none", "very-small", "small", "medium", "big", "very-big"} + local richn_options = {"very-poor", "poor", "regular", "good", "very-good"} + local autoplace_control_prototypes = game.autoplace_control_prototypes + local resource_table = map_gen_frame["change-map-settings-resource-scroll-pane"]["change-map-settings-resource-table"] + local autoplace_controls_mine = {} + local resources = util.get_table_of_resources() + --Resource settings-- + --resources + for _, control in pairs(autoplace_control_prototypes) do + if resources[control.name] then + autoplace_controls_mine[control.name] = { + frequency = freq_options[resource_table["change-map-settings-map-gen-" .. control.name .. "-freq"].selected_index], + size = size_options[resource_table["change-map-settings-map-gen-" .. control.name .. "-size"].selected_index], + richness = richn_options[resource_table["change-map-settings-map-gen-" .. control.name .. "-richn"].selected_index] + } + end + end + --Terrain settings-- + local terrain_table = map_gen_frame["change-map-settings-resource-scroll-pane"]["change-map-settings-terrain-table"] + --water stuff + map_gen_settings.terrain_segmentation = freq_options[terrain_table["change-map-settings-map-gen-water-freq"].selected_index] + map_gen_settings.water = size_options[terrain_table["change-map-settings-map-gen-water-size"].selected_index] + --starting area + local starting_area_options = {"very-small", "small", "medium", "big", "very-big"} + map_gen_settings.starting_area = starting_area_options[terrain_table["change-map-settings-map-gen-starting-area-size"].selected_index] + --biters + --terrain + for _, control in pairs(autoplace_control_prototypes) do + if not resources[control.name] then + if control.richness then + autoplace_controls_mine[control.name] = { + frequency = freq_options[terrain_table["change-map-settings-map-gen-" .. control.name .. "-freq"].selected_index], + size = size_options[terrain_table["change-map-settings-map-gen-" .. control.name .. "-size"].selected_index], + richness = richn_options[terrain_table["change-map-settings-map-gen-" .. control.name .. "-richn"].selected_index] + } + else + autoplace_controls_mine[control.name] = { + frequency = freq_options[terrain_table["change-map-settings-map-gen-" .. control.name .. "-freq"].selected_index], + size = size_options[terrain_table["change-map-settings-map-gen-" .. control.name .. "-size"].selected_index] + } + end + end + end + map_gen_settings.autoplace_controls = autoplace_controls_mine + + local cliff_freq_lookup = { + [1] = 40, + [2] = 20, + [3] = 10, + [4] = 5, + [5] = 2.5 + } + local cliff_size_lookup = { + [1] = 1024, + [2] = 40, + [3] = 20, + [4] = 10, + [5] = 5, + [6] = 2.5 + } + local cliff_settings = {} + cliff_settings.name = "cliff" + cliff_settings.cliff_elevation_interval = cliff_freq_lookup[terrain_table["change-map-settings-map-gen-cliffs-freq"].selected_index] + cliff_settings.cliff_elevation_0 = cliff_size_lookup[terrain_table["change-map-settings-map-gen-cliffs-size"].selected_index] + map_gen_settings.cliff_settings = cliff_settings + + -- Apply + player.surface.map_gen_settings = map_gen_settings + player.print({"msg.change-map-settings-applied"}) + + -- Update the values shown in everyones gui + for _, plyr in pairs(game.players) do + gui.regen(plyr) + set_to_current_map_gen_settings(plyr) + local frame_flow = mod_gui.get_frame_flow(plyr) + frame_flow["change-map-settings-main-flow"].style.visible = true + end end script.on_event({defines.events.on_gui_click}, function(event) - local player = game.players[event.player_index] - local frame_flow = mod_gui.get_frame_flow(player) - local clicked_name = event.element.name - if clicked_name == "change-map-settings-toggle-config" then - frame_flow["change-map-settings-config-more-frame"].style.visible = not frame_flow["change-map-settings-config-more-frame"].style.visible - elseif clicked_name == "change-map-settings-use-current-button" then - if player.admin then - use_current_map_gen(player) - else - player.print({"msg.change-map-settings-start-admin-restriction"}) - end - elseif clicked_name == "change-map-settings-start-button" then - change_map_settings(player) - elseif clicked_name == "change-map-settings-default-button" then - reset_to_default(player) - end + local player = game.players[event.player_index] + local frame_flow = mod_gui.get_frame_flow(player) + local clicked_name = event.element.name + if clicked_name == "change-map-settings-toggle-config" then + frame_flow["change-map-settings-main-flow"].style.visible = not frame_flow["change-map-settings-main-flow"].style.visible + elseif clicked_name == "change-map-settings-start-button" then + if player.admin then + change_map_settings(player) + else + player.print({"msg.change-map-settings-start-admin-restriction", {"gui.change-map-settings-title"}}) + end + elseif clicked_name == "change-map-settings-start-map-gen-button" then + if player.admin then + change_map_gen_settings(player) + else + player.print({"msg.change-map-settings-start-admin-restriction", {"gui.change-map-settings-map-gen-title"}}) + end + elseif clicked_name == "change-map-settings-use-current-button" then + set_to_current_map_settings(player) + elseif clicked_name == "change-map-settings-use-current-map-gen-button" then + set_to_current_map_gen_settings(player) + elseif clicked_name == "change-map-settings-default-button" then + reset_to_default(player) + elseif clicked_name == "change-map-settings-default-map-gen-button" then + reset_map_gen_to_default(player) + elseif clicked_name == "change-map-settings-map-gen-tab-button" then + local resource_scroll_pane = frame_flow["change-map-settings-main-flow"]["change-map-settings-map-gen-frame"]["change-map-settings-resource-scroll-pane"] + resource_scroll_pane["change-map-settings-terrain-table"].style.visible = not resource_scroll_pane["change-map-settings-terrain-table"].style.visible + resource_scroll_pane["change-map-settings-resource-table"].style.visible = not resource_scroll_pane["change-map-settings-resource-table"].style.visible + end end) script.on_configuration_changed(function() --migration - for _, player in pairs(game.players) do - gui.regen(player) - end + for _, player in pairs(game.players) do + gui.regen(player) + set_to_current_map_gen_settings(player) + end end) -script.on_event(defines.events.on_player_created, function(event) --create gui for joining player - gui.regen(game.players[event.player_index]) +script.on_event(defines.events.on_player_created, function(event) + local player = game.players[event.player_index] + gui.regen(player) + set_to_current_map_gen_settings(player) end) script.on_init(function() - for _, player in pairs(game.players) do - gui.regen(player) - end + for _, player in pairs(game.players) do + gui.regen(player) + set_to_current_map_gen_settings(player) + end end) diff --git a/gui.lua b/gui.lua index a14ca1a..a374931 100644 --- a/gui.lua +++ b/gui.lua @@ -3,233 +3,434 @@ local util = require("utilities") local gui = {} -- GUI -- -gui.kill = function(player) - local button_flow = mod_gui.get_button_flow(player) - local frame_flow = mod_gui.get_frame_flow(player) - if button_flow["change-map-settings-toggle-config"] then - button_flow["change-map-settings-toggle-config"].destroy() - end - if frame_flow["change-map-settings-config-more-frame"] then - frame_flow["change-map-settings-config-more-frame"].destroy() - end +function gui.regen(player) + gui.kill(player) + --toggle button + local button_flow = mod_gui.get_button_flow(player) + local button = button_flow.add{ + type = "button", + name = "change-map-settings-toggle-config", + style = mod_gui.button_style, + tooltip = {"gui.change-map-settings-toggle-tooltip", {"gui.change-map-settings-title"}}, + caption = {"gui.change-map-settings-toggle-config-caption"} + } + button.style.visible = true + -- general gui frame setup -- + local frame_flow = mod_gui.get_frame_flow(player) + local main_flow = frame_flow.add{ + type = "flow", + name = "change-map-settings-main-flow", + direction = "horizontal" + } + main_flow.style.visible = false + local config_frame = main_flow.add{ + type = "frame", + caption = {"gui.change-map-settings-title"}, + name = "change-map-settings-config-frame", + direction = "vertical" + } + + local button_table = config_frame.add{ + type = "table", + name = "change-map-settings-config-button-table", + column_count = 2 + } + button_table.add{ + type = "button", + name = "change-map-settings-use-current-button", + style = mod_gui.button_style, + caption = {"gui.change-map-settings-use-current-button-caption"} + } + button_table.add{ + type = "button", + name = "change-map-settings-default-button", + style = mod_gui.button_style, + caption = {"gui.change-map-settings-default-button-caption"} + } + --make gui sections + gui.make_advanced_settings(config_frame, player.surface) + + -- start button at the bottom + local start_button = config_frame.add{ + type = "button", + name = "change-map-settings-start-button", + tooltip = {"gui.change-map-settings-start-button-tooltip"}, + caption = {"gui.change-map-settings-start-button-caption", {"gui.change-map-settings-title"}} + } + start_button.style.font_color = { r=1, g=0.75, b=0.22} + + -- map gen settings + local map_gen_frame = main_flow.add{ + type = "frame", + caption = {"gui.change-map-settings-map-gen-title"}, + name = "change-map-settings-map-gen-frame", + direction = "vertical" + } + local map_gen_button_table = map_gen_frame.add{ + type = "table", + name = "change-map-settings-map-gen-button-table", + column_count = 2 + } + map_gen_button_table.add{ + type = "button", + name = "change-map-settings-use-current-map-gen-button", + style = mod_gui.button_style, + caption = {"gui.change-map-settings-use-current-button-caption"} + } + map_gen_button_table.add{ + type = "button", + name = "change-map-settings-default-map-gen-button", + style = mod_gui.button_style, + caption = {"gui.change-map-settings-default-button-caption"} + } + + gui.make_map_gen_settings(map_gen_frame) + + -- start button at the bottom + local start_button = map_gen_frame.add{ + type = "button", + name = "change-map-settings-start-map-gen-button", + tooltip = {"gui.change-map-settings-start-map-gen-button-tooltip"}, + caption = {"gui.change-map-settings-start-button-caption", {"gui.change-map-settings-map-gen-title"}} + } + start_button.style.font_color = { r=1, g=0.75, b=0.22} +end + +gui.make_advanced_settings = function(parent, surface) + local config_table = parent.add{ + type = "table", + name = "change-map-settings-config-table", + column_count = 2 + } + config_table.style.horizontal_spacing = 20 + local map_settings = game.map_settings + --make different advanced option groups + gui.make_pollution_settings(config_table, map_settings) + gui.make_evolution_settings(config_table, map_settings) + gui.make_expansion_settings(config_table, map_settings) + gui.make_general_settings(config_table, surface) +end + +gui.make_pollution_settings = function(parent, map_settings) + local config_more_option_pollution_flow = parent.add{ + type = "flow", + name = "change-map-settings-config-more-pollution-flow", + direction = "vertical" + } + config_more_option_pollution_flow.add{ + type = "label", + caption = {"gui-map-generator.pollution"}, + style = "caption_label" + } + local config_more_option_pollution_table = config_more_option_pollution_flow.add{ + type = "table", + name = "change-map-settings-config-more-pollution-table", + column_count = 2 + } + + config_more_option_pollution_table.add{ + type = "label", + caption = {"gui-map-generator.pollution"} + } + config_more_option_pollution_table.add{ + type = "checkbox", + name = "change-map-settings-pollution-checkbox", + state = map_settings.pollution.enabled, + } + gui.make_config_option(config_more_option_pollution_table, "pollution-diffusion", {"gui.change-map-settings-in-unit", {"gui-map-generator.pollution-diffusion-ratio"}, {"gui.change-map-settings-percent"}}, {"gui-map-generator.pollution-diffusion-ratio-description"}, tostring(map_settings.pollution.diffusion_ratio * 100), 50) + gui.make_config_option(config_more_option_pollution_table, "pollution-dissipation", {"gui-map-generator.pollution-dissipation-rate"}, {"gui-map-generator.pollution-dissipation-rate-description"}, tostring(map_settings.pollution.ageing), 50) + gui.make_config_option(config_more_option_pollution_table, "pollution-tree-dmg", {"gui-map-generator.minimum-pollution-to-damage-trees"}, {"gui-map-generator.minimum-pollution-to-damage-trees-description"}, tostring(map_settings.pollution.min_pollution_to_damage_trees), 50) + gui.make_config_option(config_more_option_pollution_table, "pollution-tree-absorb", {"gui-map-generator.pollution-absorbed-per-tree-damaged"}, {"gui-map-generator.pollution-absorbed-per-tree-damaged-description"}, tostring(map_settings.pollution.pollution_restored_per_tree_damage), 50) +end + +gui.make_evolution_settings = function(parent, map_settings) + local config_more_option_evo_flow = parent.add{ + type = "flow", + name = "change-map-settings-config-more-evo-flow", + direction = "vertical" + } + config_more_option_evo_flow.add{ + type = "label", + caption = {"gui-map-generator.evolution"}, + style = "caption_label" + } + local config_more_option_evo_table = config_more_option_evo_flow.add{ + type = "table", + name = "change-map-settings-config-more-evo-table", + column_count = 2 + } + + config_more_option_evo_table.add{ + type = "label", + caption = {"gui-map-generator.evolution"} + } + config_more_option_evo_table.add{ + type = "checkbox", + name = "change-map-settings-evolution-checkbox", + state = map_settings.enemy_evolution.enabled, + } + gui.make_config_option(config_more_option_evo_table, "evolution-factor", {"gui-map-generator.evolution"}, {"gui.change-map-settings-evolution-factor-tooltip"}, util.float_to_string(game.forces["enemy"].evolution_factor), 80) + gui.make_config_option(config_more_option_evo_table, "evolution-time", {"gui-map-generator.evolution-time-factor"}, {"gui-map-generator.evolution-time-factor-description"}, util.float_to_string(map_settings.enemy_evolution.time_factor), 80) + gui.make_config_option(config_more_option_evo_table, "evolution-destroy", {"gui-map-generator.evolution-destroy-factor"}, {"gui-map-generator.evolution-destroy-factor-description"}, util.float_to_string(map_settings.enemy_evolution.destroy_factor), 80) + gui.make_config_option(config_more_option_evo_table, "evolution-pollution", {"gui-map-generator.evolution-pollution-factor"}, {"gui-map-generator.evolution-pollution-factor-description"}, util.float_to_string(map_settings.enemy_evolution.pollution_factor), 80) +end + +gui.make_expansion_settings = function(parent, map_settings) + local config_more_option_expansion_flow = parent.add{ + type = "flow", + name = "change-map-settings-config-more-expansion-flow", + direction = "vertical" + } + config_more_option_expansion_flow.add{ + type = "label", + caption = {"gui-map-generator.enemy-expansion-group-tile"}, + style = "caption_label" + } + local config_more_option_expansion_table = config_more_option_expansion_flow.add{ + type = "table", + name = "change-map-settings-config-more-expansion-table", + column_count = 2 + } + + config_more_option_expansion_table.add{ + type = "label", + caption = {"gui-map-generator.enemy-expansion-group-tile"} + } + config_more_option_expansion_table.add{ + type = "checkbox", + name = "change-map-settings-enemy-expansion-checkbox", + state = map_settings.enemy_expansion.enabled, + } + gui.make_config_option(config_more_option_expansion_table, "expansion-distance", {"gui-map-generator.enemy-expansion-maximum-expansion-distance"}, {"gui-map-generator.enemy-expansion-maximum-expansion-distance-description"}, tostring(map_settings.enemy_expansion.max_expansion_distance), 30) + gui.make_config_option(config_more_option_expansion_table, "expansion-min-size", {"gui-map-generator.enemy-expansion-minimum-expansion-group-size"}, {"gui-map-generator.enemy-expansion-minimum-expansion-group-size-description"}, tostring(map_settings.enemy_expansion.settler_group_min_size), 30) + gui.make_config_option(config_more_option_expansion_table, "expansion-max-size", {"gui-map-generator.enemy-expansion-maximum-expansion-group-size"}, {"gui-map-generator.enemy-expansion-maximum-expansion-group-size-description"}, tostring(map_settings.enemy_expansion.settler_group_max_size), 30) + gui.make_config_option(config_more_option_expansion_table, "expansion-min-cd", {"gui.change-map-settings-in-unit", {"gui-map-generator.enemy-expansion-minimum-expansion-cooldown"}, {"minute5+"}}, {"gui-map-generator.enemy-expansion-minimum-expansion-cooldown-description"}, tostring(map_settings.enemy_expansion.min_expansion_cooldown / 3600), 30) + gui.make_config_option(config_more_option_expansion_table, "expansion-max-cd", {"gui.change-map-settings-in-unit", {"gui-map-generator.enemy-expansion-maximum-expansion-cooldown"}, {"minute5+"}}, {"gui-map-generator.enemy-expansion-maximum-expansion-cooldown-description"}, tostring(map_settings.enemy_expansion.max_expansion_cooldown / 3600), 30) +end + +gui.make_general_settings = function(parent, surface) + local config_more_option_general_flow = parent.add{ + type = "flow", + name = "change-map-settings-config-more-general-flow", + direction = "vertical" + } + config_more_option_general_flow.add{ + type = "label", + caption = {"gui.change-map-settings-general-title"}, + style = "caption_label" + } + local config_more_option_general_table = config_more_option_general_flow.add{ + type = "table", + name = "change-map-settings-config-more-general-table", + column_count = 2 + } + + config_more_option_general_table.add{ + type = "label", + caption = {"gui-map-generator.peaceful-mode"} + } + config_more_option_general_table.add{ + type = "checkbox", + name = "change-map-settings-peaceful-checkbox", + state = surface.peaceful_mode, + } end gui.make_config_option = function(parent, name, caption, tooltip, default, max_width) - parent.add{ - type = "label", - caption = caption, - tooltip = tooltip, - name = "change-map-settings-" .. name .. "-label", - } - local child = parent.add{ - type = "textfield", - name = "change-map-settings-" .. name .. "-textfield", - } - child.text = default - if max_width then child.style.maximal_width = max_width end - return child + parent.add{ + type = "label", + caption = caption, + tooltip = tooltip + } + local child = parent.add{ + type = "textfield", + name = "change-map-settings-" .. name .. "-textfield", + } + child.text = default + if max_width then child.style.maximal_width = max_width end + return child end -gui.make_general_settings = function(config_more_table) - local config_more_option_general_flow = config_more_table.add{ - type = "flow", - name = "change-map-settings-config-more-general-flow", - direction = "vertical" - } - config_more_option_general_flow.add{ - type = "label", - caption = {"gui.change-map-settings-general-title"}, - style = "caption_label", - name = "change-map-settings-general-title-label", - } - local config_more_option_general_table = config_more_option_general_flow.add{ - type = "table", - name = "change-map-settings-config-more-general-table", - column_count = 2 - } - - config_more_option_general_table.add{ - type = "label", - caption = {"gui-map-generator.peaceful-mode"}, - name = "change-map-settings-peaceful-label", - } - config_more_option_general_table.add{ - type = "checkbox", - name = "change-map-settings-peaceful-checkbox", - state = false, - } +gui.make_map_gen_settings = function(parent) + local seed_table = parent.add{ + type = "table", + name = "change-map-settings-seed-table", + column_count = 2 + } + seed_table.add{ + type = "label", + caption = {"gui.change-map-settings-seed-caption"} + } + local seed_textfield = seed_table.add{ + type = "textfield", + name = "change-map-settings-seed-textfield" + } + seed_textfield.text = "0" + local scroll_pane = parent.add{ + type = "scroll-pane", + name = "change-map-settings-resource-scroll-pane", + } + scroll_pane.style.maximal_height = 400 + scroll_pane.style.visible = true + + local freq_options = {{"frequency.very-low"}, {"frequency.low"}, {"frequency.normal"}, {"frequency.high"}, {"frequency.very-high"}} + local size_options = {{"size.none"}, {"size.very-low"}, {"size.low"}, {"size.normal"}, {"size.high"}, {"size.very-high"}} + local richn_options = {{"richness.very-low"}, {"richness.low"}, {"richness.normal"}, {"richness.high"}, {"richness.very-high"}} + local resources = util.get_table_of_resources() + + local resource_table = scroll_pane.add{ + type = "table", + name = "change-map-settings-resource-table", + column_count = 4 + } + resource_table.style.visible = true + gui.autoplace_table_header(resource_table, false) + gui.resource_options(resource_table, freq_options, size_options, richn_options, resources) + + local terrain_table = scroll_pane.add{ + type = "table", + name = "change-map-settings-terrain-table", + column_count = 4 + } + terrain_table.style.visible = false + gui.autoplace_table_header(terrain_table, true) + gui.terrain_options(terrain_table, freq_options, size_options, richn_options, resources) end -gui.make_expansion_settings = function(config_more_table, map_settings) - local config_more_option_expansion_flow = config_more_table.add{ - type = "flow", - name = "change-map-settings-config-more-expansion-flow", - direction = "vertical" - } - config_more_option_expansion_flow.add{ - type = "label", - caption = {"gui-map-generator.enemy-expansion-group-tile"}, - style = "caption_label", - name = "change-map-settings-expansion-title-label", - } - local config_more_option_expansion_table = config_more_option_expansion_flow.add{ - type = "table", - name = "change-map-settings-config-more-expansion-table", - column_count = 2 - } - - config_more_option_expansion_table.add{ - type = "label", - caption = {"gui-map-generator.enemy-expansion-group-tile"}, - name = "change-map-settings-enemy-expansion-label", - } - config_more_option_expansion_table.add{ - type = "checkbox", - name = "change-map-settings-enemy-expansion-checkbox", - state = map_settings.enemy_expansion.enabled, - } - local thirty = 30 - gui.make_config_option(config_more_option_expansion_table, "expansion-distance", {"gui-map-generator.enemy-expansion-maximum-expansion-distance"}, {"gui-map-generator.enemy-expansion-maximum-expansion-distance-description"}, tostring(map_settings.enemy_expansion.max_expansion_distance), thirty) - gui.make_config_option(config_more_option_expansion_table, "expansion-min-size", {"gui-map-generator.enemy-expansion-minimum-expansion-group-size"}, {"gui-map-generator.enemy-expansion-minimum-expansion-group-size-description"}, tostring(map_settings.enemy_expansion.settler_group_min_size), thirty) - gui.make_config_option(config_more_option_expansion_table, "expansion-max-size", {"gui-map-generator.enemy-expansion-maximum-expansion-group-size"}, {"gui-map-generator.enemy-expansion-maximum-expansion-group-size-description"}, tostring(map_settings.enemy_expansion.settler_group_max_size), thirty) - gui.make_config_option(config_more_option_expansion_table, "expansion-min-cd", {"gui.change-map-settings-in-unit", {"gui-map-generator.enemy-expansion-minimum-expansion-cooldown"}, {"minute5+"}}, {"gui-map-generator.enemy-expansion-minimum-expansion-cooldown-description"}, tostring(map_settings.enemy_expansion.min_expansion_cooldown / 3600), thirty) - gui.make_config_option(config_more_option_expansion_table, "expansion-max-cd", {"gui.change-map-settings-in-unit", {"gui-map-generator.enemy-expansion-maximum-expansion-cooldown"}, {"minute5+"}}, {"gui-map-generator.enemy-expansion-maximum-expansion-cooldown-description"}, tostring(map_settings.enemy_expansion.max_expansion_cooldown / 3600), thirty) +gui.autoplace_table_header = function(parent, bool) + local button = parent.add{ + type = "button", + name = "change-map-settings-map-gen-tab-button", + style = mod_gui.button_style, + caption = {"gui-map-generator.terrain-tab-title"} + } + if bool then + button.caption = {"gui-map-generator.resources-tab-title"} + end + parent.add{ + type = "label", + caption = {"gui-map-generator.frequency"}, + style = "caption_label" + } + parent.add{ + type = "label", + caption = {"gui-map-generator.size"}, + style = "caption_label" + } + parent.add{ + type = "label", + caption = {"gui-map-generator.richness"}, + style = "caption_label" + } end -gui.make_pollution_settings = function(config_more_table, map_settings) - local config_more_option_pollution_flow = config_more_table.add{ - type = "flow", - name = "change-map-settings-config-more-pollution-flow", - direction = "vertical" - } - config_more_option_pollution_flow.add{ - type = "label", - caption = {"gui-map-generator.pollution"}, - style = "caption_label", - name = "change-map-settings-pollution-title-label", - } - local config_more_option_pollution_table = config_more_option_pollution_flow.add{ - type = "table", - name = "change-map-settings-config-more-pollution-table", - column_count = 2 - } - - config_more_option_pollution_table.add{ - type = "label", - caption = {"gui-map-generator.pollution"}, - name = "change-map-settings-pollution-label", - } - config_more_option_pollution_table.add{ - type = "checkbox", - name = "change-map-settings-pollution-checkbox", - state = map_settings.pollution.enabled, - } - gui.make_config_option(config_more_option_pollution_table, "pollution-diffusion", {"gui.change-map-settings-in-unit", {"gui-map-generator.pollution-diffusion-ratio"}, {"gui.change-map-settings-percent"}}, {"gui-map-generator.pollution-diffusion-ratio-description"}, tostring(map_settings.pollution.diffusion_ratio * 100), 50) - gui.make_config_option(config_more_option_pollution_table, "pollution-dissipation", {"gui-map-generator.pollution-dissipation-rate"}, {"gui-map-generator.pollution-dissipation-rate-description"}, tostring(map_settings.pollution.ageing), 50) - gui.make_config_option(config_more_option_pollution_table, "pollution-tree-dmg", {"gui-map-generator.minimum-pollution-to-damage-trees"}, {"gui-map-generator.minimum-pollution-to-damage-trees-description"}, tostring(map_settings.pollution.min_pollution_to_damage_trees), 50) - gui.make_config_option(config_more_option_pollution_table, "pollution-tree-absorb", {"gui-map-generator.pollution-absorbed-per-tree-damaged"}, {"gui-map-generator.pollution-absorbed-per-tree-damaged-description"}, tostring(map_settings.pollution.pollution_restored_per_tree_damage), 50) +gui.resource_options = function(parent, freq_options, size_options, richn_options, resources) + --resources + for _, control in pairs(game.autoplace_control_prototypes) do + if resources[control.name] then + gui.make_autoplace_options(control.name, parent, freq_options, size_options, richn_options) + end + end end -gui.make_evolution_settings = function(config_more_table, map_settings) - local config_more_option_evo_flow = config_more_table.add{ - type = "flow", - name = "change-map-settings-config-more-evo-flow", - direction = "vertical" - } - config_more_option_evo_flow.add{ - type = "label", - caption = {"gui-map-generator.evolution"}, - style = "caption_label", - name = "change-map-settings-evolution-title-label", - } - local config_more_option_evo_table = config_more_option_evo_flow.add{ - type = "table", - name = "change-map-settings-config-more-evo-table", - column_count = 2 - } - - config_more_option_evo_table.add{ - type = "label", - caption = {"gui-map-generator.evolution"}, - name = "change-map-settings-evolution-label", - } - config_more_option_evo_table.add{ - type = "checkbox", - name = "change-map-settings-evolution-checkbox", - state = map_settings.enemy_evolution.enabled, - } - gui.make_config_option(config_more_option_evo_table, "evolution-factor", {"gui-map-generator.evolution"}, {"gui.change-map-settings-evolution-factor-tooltip"}, util.float_to_string(game.forces["enemy"].evolution_factor), 80) - gui.make_config_option(config_more_option_evo_table, "evolution-time", {"gui-map-generator.evolution-time-factor"}, {"gui-map-generator.evolution-time-factor-description"}, util.float_to_string(map_settings.enemy_evolution.time_factor), 80) - gui.make_config_option(config_more_option_evo_table, "evolution-destroy", {"gui-map-generator.evolution-destroy-factor"}, {"gui-map-generator.evolution-destroy-factor-description"}, util.float_to_string(map_settings.enemy_evolution.destroy_factor), 80) - gui.make_config_option(config_more_option_evo_table, "evolution-pollution", {"gui-map-generator.evolution-pollution-factor"}, {"gui-map-generator.evolution-pollution-factor-description"}, util.float_to_string(map_settings.enemy_evolution.pollution_factor), 80) +gui.terrain_options = function(parent, freq_options, size_options, richn_options, resources) + --starting area + parent.add{ + type = "label", + caption = {"gui-map-generator.starting-area"} + } + parent.add{type = "label"} + local starting_area_size = parent.add{ + type = "drop-down", + name = "change-map-settings-map-gen-starting-area-size", + } + starting_area_size.items = {{"size.very-low"}, {"size.low"}, {"size.normal"}, {"size.high"}, {"size.very-high"}} + starting_area_size.selected_index = 3 + parent.add{type = "label"} + + --water + parent.add{ + type = "label", + caption = {"gui-map-generator.water"} + } + local water_freq = parent.add{ + type = "drop-down", + name = "change-map-settings-map-gen-water-freq", + } + water_freq.items = freq_options + water_freq.selected_index = 3 + local water_size = parent.add{ + type = "drop-down", + name = "change-map-settings-map-gen-water-size", + } + water_size.items = size_options --first option should actually be size.only-starting-area but that localized string is waaaay too long + water_size.selected_index = 4 + parent.add{type = "label"} + + --terrain + for _, control in pairs(game.autoplace_control_prototypes) do + if not resources[control.name] then + gui.make_autoplace_options(control.name, parent, freq_options, size_options, control.richness and richn_options or false) + end + end + --cliffs + gui.make_autoplace_options("cliffs", parent, freq_options, size_options, false) end -gui.make_advanced_settings = function(config_more_frame) - local config_more_table = config_more_frame.add{ - type = "table", - name = "change-map-settings-config-more-table", - column_count = 2 - } - config_more_table.style.horizontal_spacing = 20 - local map_settings = game.map_settings - --make different advanced option groups - gui.make_pollution_settings(config_more_table, map_settings) - gui.make_evolution_settings(config_more_table, map_settings) - gui.make_expansion_settings(config_more_table, map_settings) - gui.make_general_settings(config_more_table) +gui.make_autoplace_options = function(name, parent, freq_options, size_options, richn_options) + if name ~= "cliffs" then + parent.add{ + type = "label", + caption = {"autoplace-control-names." .. name} + } + else + parent.add{ + type = "label", + caption = {"gui-map-generator.cliffs"} + } + end + local resource_freq = parent.add{ + type = "drop-down", + name = "change-map-settings-map-gen-" .. name .. "-freq", + } + resource_freq.items = freq_options + resource_freq.selected_index = 3 + local resource_size = parent.add{ + type = "drop-down", + name = "change-map-settings-map-gen-" .. name .. "-size", + } + resource_size.items = size_options + resource_size.selected_index = 4 + if richn_options then + local resource_richn = parent.add{ + type = "drop-down", + name = "change-map-settings-map-gen-" .. name .. "-richn", + } + resource_richn.items = richn_options + resource_richn.selected_index = 3 + else + parent.add{type = "label"} + end end -function gui.regen(player) - gui.kill(player) - --toggle button - local button_flow = mod_gui.get_button_flow(player) - local button = button_flow.add{ - type = "button", - name = "change-map-settings-toggle-config", - style = mod_gui.button_style, - tooltip = {"gui.change-map-settings-toggle-tooltip", {"gui.change-map-settings-toggle-config-caption"}}, - caption = {"gui.change-map-settings-toggle-config-caption"} - } - button.style.visible = true - -- general gui frame setup -- - local frame_flow = mod_gui.get_frame_flow(player) - local config_more_frame = frame_flow.add{ - type = "frame", - caption = {"gui.change-map-settings-toggle-config-caption"}, - name = "change-map-settings-config-more-frame", - direction = "vertical" - } - config_more_frame.style.visible = false - - local button_table = config_more_frame.add{ - type = "table", - name = "change-map-settings-config-button-table", - column_count = 2 - } - button_table.add{ - type = "button", - name = "change-map-settings-use-current-button", - style = mod_gui.button_style, - caption = {"gui.change-map-settings-use-current-button-caption"} - } - button_table.add{ - type = "button", - name = "change-map-settings-default-button", - style = mod_gui.button_style, - caption = {"gui.change-map-settings-default-button-caption"} - } - --make gui sections - gui.make_advanced_settings(config_more_frame) - - -- start button at the bottom - local start_button = config_more_frame.add{ - type = "button", - name = "change-map-settings-start-button", - --style = mod_gui.button_style, - tooltip = {"gui.change-map-settings-start-button-tooltip"}, - caption = {"gui.change-map-settings-start-button-caption"} - } - start_button.style.font_color = { r=1, g=0.75, b=0.22} +gui.kill = function(player) + local button_flow = mod_gui.get_button_flow(player) + local frame_flow = mod_gui.get_frame_flow(player) + if button_flow["change-map-settings-toggle-config"] then + button_flow["change-map-settings-toggle-config"].destroy() + end + if frame_flow["change-map-settings-main-flow"] then + frame_flow["change-map-settings-main-flow"].destroy() + end + + --migration from 2.0.0 + if frame_flow["change-map-settings-config-more-frame"] then + frame_flow["change-map-settings-config-more-frame"].destroy() + end + -- from internal testing.. + if frame_flow["change-map-settings-config-frame"] then + frame_flow["change-map-settings-config-frame"].destroy() + end end -return gui \ No newline at end of file +return gui diff --git a/info.json b/info.json index f523191..c14f3c6 100644 --- a/info.json +++ b/info.json @@ -1,6 +1,6 @@ { "name": "ChangeMapSettings", - "version": "2.0.0", + "version": "2.1.0", "factorio_version" : "0.16", "title": "Change Map Settings", "author": "Bilka", diff --git a/locale/en/en.cfg b/locale/en/en.cfg index 22e0e3e..6a26c03 100644 --- a/locale/en/en.cfg +++ b/locale/en/en.cfg @@ -1,7 +1,8 @@ [gui] -change-map-settings-toggle-config-caption=Map settings +change-map-settings-toggle-config-caption=Change Map Settings +change-map-settings-title=Map settings change-map-settings-toggle-tooltip=Click to toggle __1__ options -change-map-settings-start-button-caption=Apply map settings +change-map-settings-start-button-caption=Apply __1__ change-map-settings-start-button-tooltip=Click to change the map settings to the currently set values change-map-settings-default-button-caption=Reset fields to default change-map-settings-use-current-button-caption=Set fields to current settings @@ -9,9 +10,13 @@ change-map-settings-in-unit=__1__ in __2__ change-map-settings-percent=percent change-map-settings-evolution-factor-tooltip=Current enemy evolution factor change-map-settings-general-title=General +change-map-settings-map-gen-title=Map generation settings +change-map-settings-seed-caption=Seed (0 for random) +change-map-settings-start-map-gen-button-tooltip=Click to apply the currently set map generation settings to new chunks [msg] -change-map-settings-start-admin-restriction=Only admins can start change the map settings +change-map-settings-start-admin-restriction=Only admins can change the __1__ +change-map-settings-invalid-seed=Invalid seed change-map-settings-invalid-evolution-factor=Invalid evolution factor. Possible values: 0 to 1 change-map-settings-invalid-evolution-time=Invalid evolution time factor. Possible values: 0 to 0.0001 change-map-settings-invalid-evolution-destroy=Invalid evolution destroy factor. Possible values: 0 to 0.01 @@ -22,8 +27,7 @@ change-map-settings-invalid-pollution-tree-dmg=Invalid pollution minimum to dama change-map-settings-invalid-pollution-tree-absorb=Invalid pollution absorbed per damaged tree. Possible values: 0 to 9999 change-map-settings-invalid-expansion-distance=Invalid maximum expansion distance. Possible values: 2 to 20 change-map-settings-invalid-expansion-min-size=Invalid expansion minimum group size. Possible values: 1 to 20 -change-map-settings-too-low-expansion-max-size=Expansion maximum group size has to be higher than expansion minimum group size. -change-map-settings-invalid-expansion-max-size=Invalid expansion maximum group size. Possible values: 1 to 50 +change-map-settings-invalid-expansion-max-size=Invalid expansion maximum group size. Possible values: 1 to 50. Has to be higher than expansion minimum group size. change-map-settings-invalid-expansion-min-cd=Invalid expansion minimum cooldown. Possible values: 1 to 60 -change-map-settings-too-low-expansion-max-cd=Expansion maximum cooldown has to be higher than expansion minimum cooldown. -change-map-settings-invalid-expansion-max-cd=Invalid expansion maximum cooldown. Possible values: 5 to 180 \ No newline at end of file +change-map-settings-invalid-expansion-max-cd=Invalid expansion maximum cooldown. Possible values: 5 to 180. Has to be higher than expansion minimum cooldown. +change-map-settings-applied=Applied changes. diff --git a/utilities.lua b/utilities.lua index 30a70bf..e532e8d 100644 --- a/utilities.lua +++ b/utilities.lua @@ -1,25 +1,43 @@ local util = {} util.textfield_to_uint = function(textfield) - local number = tonumber(textfield.text) - if textfield.text and number and (number >= 0) and (number <= 4294967295) and (math.floor(number) == number) then - return number - else - return false - end + local number = tonumber(textfield.text) + if textfield.text and number and (number >= 0) and (number <= 4294967295) and (math.floor(number) == number) then + return number + else + return false + end end util.textfield_to_number = function(textfield) - local number = tonumber(textfield.text) - if textfield.text and number then - return number - else - return false - end + local number = tonumber(textfield.text) + if textfield.text and number then + return number + else + return false + end end util.float_to_string = function(number) - return string.format("%f", tostring(number)) + return string.format("%f", tostring(number)) end -return util \ No newline at end of file +util.check_bounds = function(input, min, max, player, error) + if input and (input >= min) and (input <= max) then + return input + end + player.print(error) + return false +end + +util.get_table_of_resources = function(number) + local resources = {} + for _, prototype in pairs(game.entity_prototypes) do + if prototype.type == "resource" then + resources[prototype.name] = true + end + end + return resources +end + +return util