diff --git a/antigrief.lua b/antigrief.lua index 8c1cf261..9b51abbf 100644 --- a/antigrief.lua +++ b/antigrief.lua @@ -5,6 +5,7 @@ local event = require 'utils.event' local session = require 'utils.session_data' +local Server = require 'utils.server' --[[ local function create_admin_button(player) @@ -73,7 +74,7 @@ local function on_player_ammo_inventory_changed(event) if nukes > 0 then player.surface.spill_item_stack(player.position, {name = "atomic-bomb", count = nukes}, false) player.print("You have not grown accustomed to this technology yet.", {r=0.22, g=0.99, b=0.99}) - server_commands.to_discord_bold(table.concat{'[Nuke] ' .. player.name .. ' tried to equip nukes but was not trusted.'}) + Server.to_discord_bold(table.concat{'[Nuke] ' .. player.name .. ' tried to equip nukes but was not trusted.'}) player.character.health = 0 end end @@ -230,7 +231,7 @@ local function on_gui_opened(event) if corpse_owner.force.name ~= player.force.name then return end if player.name ~= corpse_owner.name then game.print(player.name .. " is looting " .. corpse_owner.name .. "´s body.", { r=0.85, g=0.85, b=0.85}) - server_commands.to_discord_bold(table.concat{'[Corpse] ' .. player.name .. " is looting " .. corpse_owner.name .. "´s body."}) + Server.to_discord_bold(table.concat{'[Corpse] ' .. player.name .. " is looting " .. corpse_owner.name .. "´s body."}) end end @@ -242,7 +243,7 @@ local function on_pre_player_mined_item(event) if corpse_owner.force.name ~= player.force.name then return end if player.name ~= corpse_owner.name then game.print(player.name .. " has looted " .. corpse_owner.name .. "´s body.", { r=0.85, g=0.85, b=0.85}) - server_commands.to_discord_bold(table.concat{'[Corpse] ' .. player.name .. " has looted " .. corpse_owner.name .. "´s body."}) + Server.to_discord_bold(table.concat{'[Corpse] ' .. player.name .. " has looted " .. corpse_owner.name .. "´s body."}) end end diff --git a/comfy_panel/admin.lua b/comfy_panel/admin.lua index d27902ab..e0506045 100644 --- a/comfy_panel/admin.lua +++ b/comfy_panel/admin.lua @@ -1,6 +1,7 @@ --antigrief things made by mewmew local event = require 'utils.event' +local Tabs = require 'comfy_panel.main' local function admin_only_message(str) for _, player in pairs(game.connected_players) do @@ -169,7 +170,7 @@ local function create_mini_camera_gui(player, caption, position) camera.style.minimal_height = 480 end -local function create_admin_panel(player, frame) +local create_admin_panel = (function (player, frame) frame.clear() local player_names = {} @@ -272,7 +273,7 @@ local function create_admin_panel(player, frame) scroll_pane.add({type = "label", caption = history_index[history][i], tooltip = "Click to open mini camera."}) end -end +end) local admin_functions = { ["jail"] = jail, @@ -328,7 +329,7 @@ end local function on_gui_click(event) local player = game.players[event.player_index] - local frame = comfy_panel_get_active_frame(player) + local frame = Tabs.comfy_panel_get_active_frame(player) if not frame then return end if frame.name ~= "Admin" then return end @@ -381,7 +382,7 @@ local function on_gui_selection_state_changed(event) if not global.admin_panel_selected_history_index then global.admin_panel_selected_history_index = {} end global.admin_panel_selected_history_index[player.name] = event.element.selected_index - local frame = comfy_panel_get_active_frame(player) + local frame = Tabs.comfy_panel_get_active_frame(player) if not frame then return end if frame.name ~= "Admin" then return end @@ -391,5 +392,7 @@ end comfy_panel_tabs["Admin"] = create_admin_panel + + event.add(defines.events.on_gui_click, on_gui_click) event.add(defines.events.on_gui_selection_state_changed, on_gui_selection_state_changed) \ No newline at end of file diff --git a/comfy_panel/config.lua b/comfy_panel/config.lua new file mode 100644 index 00000000..22fcfc67 --- /dev/null +++ b/comfy_panel/config.lua @@ -0,0 +1,89 @@ +-- config tab -- + +local Tabs = require 'comfy_panel.main' + +local functions = { + ["comfy_panel_spectator_switch"] = function(event) + if event.element.switch_state == "left" then + game.players[event.player_index].spectator = true + else + game.players[event.player_index].spectator = false + end + end, + + ["comfy_panel_auto_hotbar_switch"] = function(event) + if event.element.switch_state == "left" then + global.auto_hotbar_enabled[event.player_index] = true + else + global.auto_hotbar_enabled[event.player_index] = false + end + end, +} + +local function add_switch(element, switch_state, name, description_main, description) + local t = element.add({type = "table", column_count = 5}) + local label = t.add({type = "label", caption = "ON"}) + label.style.padding = 0 + label.style.left_padding= 10 + label.style.font_color = {0.77, 0.77, 0.77} + local switch = t.add({type = "switch", name = name}) + switch.switch_state = switch_state + switch.style.padding = 0 + switch.style.margin = 0 + local label = t.add({type = "label", caption = "OFF"}) + label.style.padding = 0 + label.style.font_color = {0.70, 0.70, 0.70} + + local label = t.add({type = "label", caption = description_main}) + label.style.padding = 2 + label.style.left_padding= 10 + label.style.minimal_width = 120 + label.style.font = "heading-2" + label.style.font_color = {0.88, 0.88, 0.99} + + local label = t.add({type = "label", caption = description}) + label.style.padding = 2 + label.style.left_padding= 10 + label.style.single_line = false + label.style.font = "heading-3" + label.style.font_color = {0.85, 0.85, 0.85} +end + +local build_config_gui = (function (player, frame) + frame.clear() + + local line_elements = {} + local switch_label_elements = {} + local label_elements = {} + + line_elements[#line_elements + 1] = frame.add({type = "line"}) + + local switch_state = "right" + if player.spectator then switch_state = "left" end + add_switch(frame, switch_state, "comfy_panel_spectator_switch", "SpectatorMode", "Disables zoom-to-world view noise effect.\nEnvironmental sounds will be based on map view.") + + line_elements[#line_elements + 1] = frame.add({type = "line"}) + + if global.auto_hotbar_enabled then + local switch_state = "right" + if global.auto_hotbar_enabled[player.index] then switch_state = "left" end + add_switch(frame, switch_state, "comfy_panel_auto_hotbar_switch", "AutoHotbar", "Automatically fills your hotbar with placeable items.") + line_elements[#line_elements + 1] = frame.add({type = "line"}) + end + +end) + +local function on_gui_click(event) + if not event.element then return end + if not event.element.valid then return end + if functions[event.element.name] then + functions[event.element.name](event) + return + end +end + +comfy_panel_tabs["Config"] = build_config_gui + + +local event = require 'utils.event' +event.add(defines.events.on_gui_click, on_gui_click) \ No newline at end of file diff --git a/comfy_panel/group.lua b/comfy_panel/group.lua index 19fb99ab..82f20c87 100644 --- a/comfy_panel/group.lua +++ b/comfy_panel/group.lua @@ -1,6 +1,8 @@ -- this script adds a group button to create groups for your players -- -local function build_group_gui(player, frame) +local Tabs = require 'comfy_panel.main' + +local build_group_gui = (function (player, frame) local group_name_width = 150 local description_width = 240 local members_width = 90 @@ -99,13 +101,13 @@ local function build_group_gui(player, frame) b.style.minimal_width = 150 b.style.font = "default-bold" -end +end) local function refresh_gui() for _, p in pairs(game.connected_players) do - local frame = comfy_panel_get_active_frame(p) + local frame = Tabs.comfy_panel_get_active_frame(p) if frame then if frame.name == "Groups" then local new_group_name = frame.frame2.group_table.new_group_name.text @@ -113,7 +115,7 @@ local function refresh_gui() build_group_gui(p, frame) - local frame = comfy_panel_get_active_frame(p) + local frame = Tabs.comfy_panel_get_active_frame(p) frame.frame2.group_table.new_group_name.text = new_group_name frame.frame2.group_table.new_group_description.text = new_group_description end @@ -137,7 +139,7 @@ local function on_gui_click(event) local player = game.players[event.element.player_index] local name = event.element.name - local frame = comfy_panel_get_active_frame(player) + local frame = Tabs.comfy_panel_get_active_frame(player) if not frame then return end if frame.name ~= "Groups" then return end @@ -214,6 +216,7 @@ end comfy_panel_tabs["Groups"] = build_group_gui -local event = require 'utils.event' + +local event = require 'utils.event' event.add(defines.events.on_gui_click, on_gui_click) event.add(defines.events.on_player_joined_game, on_player_joined_game) \ No newline at end of file diff --git a/comfy_panel/main.lua b/comfy_panel/main.lua index 5b498316..b05d32c4 100644 --- a/comfy_panel/main.lua +++ b/comfy_panel/main.lua @@ -4,26 +4,37 @@ Comfy Panel To add a tab, insert into the "comfy_panel_tabs" table. Example: comfy_panel_tabs["mapscores"] = draw_map_scores + draw_map_scores would be a function with the player and the frame as arguments ]] +local event = require 'utils.event' + comfy_panel_tabs = {} -function comfy_panel_clear_left_gui(player) + +local Public = {} + +function Public.get_tabs(data) + return comfy_panel_tabs +end + + +function Public.comfy_panel_clear_left_gui(player) for _, child in pairs(player.gui.left.children) do child.destroy() end end -function comfy_panel_get_active_frame(player) +function Public.comfy_panel_get_active_frame(player) if not player.gui.left.comfy_panel then return false end if not player.gui.left.comfy_panel.tabbed_pane.selected_tab_index then return player.gui.left.comfy_panel.tabbed_pane.tabs[1].content end return player.gui.left.comfy_panel.tabbed_pane.tabs[player.gui.left.comfy_panel.tabbed_pane.selected_tab_index].content end -function comfy_panel_refresh_active_tab(player) - local frame = comfy_panel_get_active_frame(player) +function Public.comfy_panel_refresh_active_tab(player) + local frame = Public.comfy_panel_get_active_frame(player) if not frame then return end comfy_panel_tabs[frame.name](player, frame) end @@ -33,18 +44,19 @@ local function top_button(player) local button = player.gui.top.add({type = "sprite-button", name = "comfy_panel_top_button", sprite = "item/raw-fish"}) button.style.minimal_height = 38 button.style.minimal_width = 38 - button.style.padding = -2 + button.style.padding = -2 end local function main_frame(player) - comfy_panel_clear_left_gui(player) - + local tabs = comfy_panel_tabs + Public.comfy_panel_clear_left_gui(player) + local frame = player.gui.left.add({type = "frame", name = "comfy_panel"}) frame.style.margin = 6 - + local tabbed_pane = frame.add({type = "tabbed-pane", name = "tabbed_pane"}) - - for name, func in pairs(comfy_panel_tabs) do + + for name, func in pairs(tabs) do if name == "Admin" then if player.admin then local tab = tabbed_pane.add({type = "tab", caption = name}) @@ -65,29 +77,29 @@ local function main_frame(player) tabbed_pane.add_tab(tab, frame) end end - + local tab = tabbed_pane.add({type = "tab", name = "comfy_panel_close", caption = "X"}) tab.style.maximal_width = 32 local frame = tabbed_pane.add({type = "frame", name = name, direction = "vertical"}) tabbed_pane.add_tab(tab, frame) - + for _, child in pairs(tabbed_pane.children) do child.style.padding = 8 child.style.left_padding = 2 child.style.right_padding = 2 end - - comfy_panel_refresh_active_tab(player) + + Public.comfy_panel_refresh_active_tab(player) end -function comfy_panel_call_tab(player, name) +function Public.comfy_panel_call_tab(player, name) main_frame(player) local tabbed_pane = player.gui.left.comfy_panel.tabbed_pane for key, v in pairs(tabbed_pane.tabs) do if v.tab.caption == name then tabbed_pane.selected_tab_index = key - comfy_panel_refresh_active_tab(player) - end + Public.comfy_panel_refresh_active_tab(player) + end end end @@ -99,7 +111,7 @@ local function on_gui_click(event) if not event.element then return end if not event.element.valid then return end local player = game.players[event.player_index] - + if event.element.name == "comfy_panel_top_button" then if player.gui.left.comfy_panel then player.gui.left.comfy_panel.destroy() @@ -107,19 +119,20 @@ local function on_gui_click(event) else main_frame(player) return - end + end end - + if event.element.caption == "X" and event.element.name == "comfy_panel_close" then player.gui.left.comfy_panel.destroy() return end - + if not event.element.caption then return end if event.element.type ~= "tab" then return end - comfy_panel_refresh_active_tab(player) + Public.comfy_panel_refresh_active_tab(player) end -local event = require 'utils.event' event.add(defines.events.on_player_joined_game, on_player_joined_game) -event.add(defines.events.on_gui_click, on_gui_click) \ No newline at end of file +event.add(defines.events.on_gui_click, on_gui_click) + +return Public \ No newline at end of file diff --git a/comfy_panel/player_list.lua b/comfy_panel/player_list.lua index a8c417fe..c27cde80 100644 --- a/comfy_panel/player_list.lua +++ b/comfy_panel/player_list.lua @@ -15,6 +15,7 @@ Minor changes by ~~~Gerkiz~~~ local event = require 'utils.event' local play_time = require 'utils.session_data' +local Tabs = require 'comfy_panel.main' local symbol_asc = "▲" local symbol_desc = "▼" @@ -167,7 +168,7 @@ local function get_sorted_list(sort_by) return player_list end -local column_widths = {40, 250, 250, 150, 100} + local function player_list_show(player, frame, sort_by) -- Frame management @@ -176,6 +177,7 @@ local function player_list_show(player, frame, sort_by) -- Header management local t = frame.add { type = "table", name = "player_list_panel_header_table", column_count = 5 } + local column_widths = {tonumber(40), tonumber(250), tonumber(250), tonumber(150), tonumber(100)} for _, w in ipairs(column_widths) do local label = t.add { type = "label", caption = "" } label.style.minimal_width = w @@ -293,7 +295,7 @@ local function on_gui_click(event) if not event.element.name then return end local player = game.players[event.element.player_index] - local frame = comfy_panel_get_active_frame(player) + local frame = Tabs.comfy_panel_get_active_frame(player) if not frame then return end if frame.name ~= "Players" then return end @@ -367,21 +369,21 @@ local function on_player_joined_game(event) global.player_list.last_poke_tick[event.player_index] = 0 end - local frame = comfy_panel_get_active_frame(player) + local frame = Tabs.comfy_panel_get_active_frame(player) if not frame then return end if frame.name ~= "Players" then return end player_list_show(player, frame, "total_time_played_desc") end -comfy_panel_tabs["Players"] = player_list_show - -local function on_init() +local on_init = function() global.player_list = {} global.player_list.last_poke_tick = {} global.player_list.pokes = {} end +comfy_panel_tabs["Players"] = player_list_show + event.on_init(on_init) event.add(defines.events.on_player_joined_game, on_player_joined_game) event.add(defines.events.on_gui_click, on_gui_click) \ No newline at end of file diff --git a/comfy_panel/poll.lua b/comfy_panel/poll.lua index 945a6299..ad9d2391 100644 --- a/comfy_panel/poll.lua +++ b/comfy_panel/poll.lua @@ -1,8 +1,10 @@ local Gui = require 'utils.gui' local Global = require 'utils.global' local Event = require 'utils.event' +local Server = require 'utils.server' local Game = require 'utils.game' local session = require 'utils.session_data' +local Tabs = require 'comfy_panel.main' local insert = table.insert @@ -148,7 +150,7 @@ local function send_poll_result_to_discord(poll) end local message = table.concat(result) - server_commands.to_discord_embed(message) + Server.to_discord_embed(message) end local function redraw_poll_viewer_content(data) @@ -425,7 +427,7 @@ local function toggle(event) if main_frame then remove_main_frame(main_frame, left, event.player) else - comfy_panel_call_tab(p, "Polls") + Tabs.comfy_panel_call_tab(p, "Polls") end end @@ -637,7 +639,7 @@ local function show_new_poll(poll_data) if block_notify[p.index] then p.print(message) else - local frame = comfy_panel_call_tab(p, "Polls") + local frame = Tabs.comfy_panel_call_tab(p, "Polls") p.print(message) if frame and frame.valid then local data = Gui.get_data(frame) @@ -645,7 +647,7 @@ local function show_new_poll(poll_data) update_poll_viewer(data) else player_poll_index[p.index] = nil - comfy_panel_call_tab(p, "Polls") + Tabs.comfy_panel_call_tab(p, "Polls") end end end @@ -801,16 +803,20 @@ end local function tick() for _, p in pairs(game.connected_players) do if p.gui.left.comfy_panel ~= nil then - local frame = p.gui.left.comfy_panel.tabbed_pane.Polls[main_frame_name] - if frame and frame.valid then - local data = Gui.get_data(frame) - local poll = polls[data.poll_index] - if poll then - local poll_enabled = do_remaining_time(poll, data.remaining_time_label) + if p.gui.left.comfy_panel.tabbed_pane ~= nil then + if p.gui.left.comfy_panel.tabbed_pane.Polls ~= nil then + local frame = p.gui.left.comfy_panel.tabbed_pane.Polls[main_frame_name] + if frame and frame.valid then + local data = Gui.get_data(frame) + local poll = polls[data.poll_index] + if poll then + local poll_enabled = do_remaining_time(poll, data.remaining_time_label) - if not poll_enabled then - for _, v in pairs(data.vote_buttons) do - v.enabled = poll_enabled + if not poll_enabled then + for _, v in pairs(data.vote_buttons) do + v.enabled = poll_enabled + end + end end end end @@ -1094,7 +1100,7 @@ Gui.on_click( main_frame_data.poll_index = poll_index update_poll_viewer(main_frame_data) else - comfy_panel_call_tab(p, "Polls") + Tabs.comfy_panel_call_tab(p, "Polls") end end end @@ -1276,7 +1282,7 @@ end function Class.send_poll_result_to_discord(id) if type(id) ~= 'number' then - server_commands.to_discord_embed('poll-id must be a number') + Server.to_discord_embed('poll-id must be a number') return end @@ -1288,7 +1294,7 @@ function Class.send_poll_result_to_discord(id) end local message = table.concat {'poll #', id, ' not found'} - server_commands.to_discord_embed(message) + Server.to_discord_embed(message) end comfy_panel_tabs["Polls"] = draw_main_frame diff --git a/comfy_panel/score.lua b/comfy_panel/score.lua index 2e9f7640..4b2465b5 100644 --- a/comfy_panel/score.lua +++ b/comfy_panel/score.lua @@ -1,6 +1,8 @@ --scoreboard by mewmew local event = require 'utils.event' +local Tabs = require 'comfy_panel.main' + local sorting_symbol = {ascending = "▲", descending = "▼"} local building_and_mining_blacklist = { ["tile-ghost"] = true, @@ -74,7 +76,7 @@ local function add_global_stats(frame, player) l.style.font_color = { r=0.8, g=0.8, b=0.8} end -local function show_score(player, frame) +local show_score = (function (player, frame) frame.clear() -- Global stats : rockets, biters kills @@ -162,10 +164,11 @@ local function show_score(player, frame) end -- foreach column end -- foreach entry end -- show_score +) local function refresh_score_full() for _, player in pairs(game.connected_players) do - local frame = comfy_panel_get_active_frame(player) + local frame = Tabs.comfy_panel_get_active_frame(player) if frame then if frame.name == "Scoreboard" then show_score(player, frame) @@ -184,7 +187,7 @@ local function init_player_table(player) deaths = 0, killscore = 0, mined_entities = 0, - } + } end end @@ -206,7 +209,7 @@ local function on_gui_click(event) if not event.element.valid then return end local player = game.players[event.element.player_index] - local frame = comfy_panel_get_active_frame(player) + local frame = Tabs.comfy_panel_get_active_frame(player) if not frame then return end if frame.name ~= "Scoreboard" then return end diff --git a/commands.lua b/commands.lua index 990f74db..32ebfe03 100644 --- a/commands.lua +++ b/commands.lua @@ -1,3 +1 @@ -require "commands.misc" -require "commands.decoratives" ---require "commands.effects" \ No newline at end of file +require "commands.misc" \ No newline at end of file diff --git a/commands/decoratives.lua b/commands/decoratives.lua deleted file mode 100644 index 867ba5a5..00000000 --- a/commands/decoratives.lua +++ /dev/null @@ -1,14 +0,0 @@ -function generate_decoratives_for_all_existing_chunks() - local decorative_names = {} - for k,v in pairs(game.decorative_prototypes) do - if v.autoplace_specification then - decorative_names[#decorative_names+1] = k - end - end - - for _, surface in pairs(game.surfaces) do - for chunk in surface.get_chunks() do - surface.regenerate_decorative(decorative_names, {chunk}) - end - end -end \ No newline at end of file diff --git a/commands/effects.lua b/commands/effects.lua deleted file mode 100644 index 68fc0670..00000000 --- a/commands/effects.lua +++ /dev/null @@ -1,47 +0,0 @@ -local event = require 'utils.event' - -local function spin(player) - local d = player.character.direction - d = d + 1 - if d > 7 then d = 0 end - player.character.direction = d -end - -local function on_player_joined_game(event) - if global.effects_commands_added then return end - - commands.add_command("spin", "spins you", - function(args) - local player = game.players[args.player_index] - - --if not args.parameter then player.print("Please add a player name.") return end - local c = 25 - for t = 0, 600, 1 do - if t % math.ceil(c) == 0 then - local trigger_tick = game.tick + t - if not global.on_tick_schedule[trigger_tick] then global.on_tick_schedule[trigger_tick] = {} end - table.insert(global.on_tick_schedule[trigger_tick], {func = spin, args = {player}}) - - c = c - c * 0.05 - if c < 1 then c = 1 end - end - end - - local c = 1 - for t = 600, 1200, 1 do - if t % math.ceil(c) == 0 then - local trigger_tick = game.tick + t - if not global.on_tick_schedule[trigger_tick] then global.on_tick_schedule[trigger_tick] = {} end - table.insert(global.on_tick_schedule[trigger_tick], {func = spin, args = {player}}) - - c = c + c * 0.05 - if c > 25 then c = 25 end - end - end - end - ) - - global.effects_commands_added = true -end - -event.add(defines.events.on_player_joined_game, on_player_joined_game) \ No newline at end of file diff --git a/commands/misc.lua b/commands/misc.lua index d925bd0b..e77ed6e8 100644 --- a/commands/misc.lua +++ b/commands/misc.lua @@ -1,83 +1,251 @@ -function generate_map(radius) - local surface = game.players[1].surface - if surface.is_chunk_generated({radius, radius}) then - game.print("Map generation done!", {r=0.22, g=0.99, b=0.99}) - return - end - surface.request_to_generate_chunks({0,0}, radius) - surface.force_generate_chunk_requests() - for _, player in pairs(game.connected_players) do - player.play_sound{path="utility/new_objective", volume_modifier=1} - end - game.print("Map generation done!", {r=0.22, g=0.99, b=0.99}) -end +local Session = require 'utils.session_data' -function spaghetti() - game.forces["player"].technologies["logistic-system"].enabled = false - game.forces["player"].technologies["construction-robotics"].enabled = false - game.forces["player"].technologies["logistic-robotics"].enabled = false - game.forces["player"].technologies["robotics"].enabled = false - game.forces["player"].technologies["personal-roboport-equipment"].enabled = false - game.forces["player"].technologies["personal-roboport-mk2-equipment"].enabled = false - game.forces["player"].technologies["character-logistic-trash-slots-1"].enabled = false - game.forces["player"].technologies["character-logistic-trash-slots-2"].enabled = false - game.forces["player"].technologies["auto-character-logistic-trash-slots"].enabled = false - game.forces["player"].technologies["worker-robots-storage-1"].enabled = false - game.forces["player"].technologies["worker-robots-storage-2"].enabled = false - game.forces["player"].technologies["worker-robots-storage-3"].enabled = false - game.forces["player"].technologies["character-logistic-slots-1"].enabled = false - game.forces["player"].technologies["character-logistic-slots-2"].enabled = false - game.forces["player"].technologies["character-logistic-slots-3"].enabled = false - game.forces["player"].technologies["character-logistic-slots-4"].enabled = false - game.forces["player"].technologies["character-logistic-slots-5"].enabled = false - game.forces["player"].technologies["character-logistic-slots-6"].enabled = false - game.forces["player"].technologies["worker-robots-speed-1"].enabled = false - game.forces["player"].technologies["worker-robots-speed-2"].enabled = false - game.forces["player"].technologies["worker-robots-speed-3"].enabled = false - game.forces["player"].technologies["worker-robots-speed-4"].enabled = false - game.forces["player"].technologies["worker-robots-speed-5"].enabled = false - game.forces["player"].technologies["worker-robots-speed-6"].enabled = false -end +commands.add_command( + 'spaghetti', + 'Does spaghett.', + function(cmd) + local player = game.player + local param = tostring(cmd.parameter) + local force = game.forces["player"] + local p -function dump_layout() - local surface = game.surfaces["labyrinth"] - game.write_file("layout.lua", "" , false) - - local area = { - left_top = {x = 0, y = 0}, - right_bottom = {x = 32, y = 32} - } - - local entities = surface.find_entities_filtered{area = area} - local tiles = surface.find_tiles_filtered{area = area} - - for _, e in pairs(entities) do - local str = "{position = {x = " .. e.position.x - str = str .. ", y = " - str = str .. e.position.y - str = str .. '}, name = "' - str = str .. e.name - str = str .. '", direction = ' - str = str .. tostring(e.direction) - str = str .. ', force = "' - str = str .. e.force.name - str = str .. '"},' - if e.name ~= "character" then - game.write_file("layout.lua", str .. '\n' , true) + if player then + if player ~= nil then + p = player.print + if not player.admin then + p("You're not admin!", {r = 1, g = 0.5, b = 0.1}) + return + end + else + p = log + end + end + if param == nil then player.print("Arguments are true/false", {r=0.22, g=0.99, b=0.99}) return end + if param == "true" then + game.print("The world has been spaghettified!", {r = 1, g = 0.5, b = 0.1}) + force.technologies["logistic-system"].enabled = false + force.technologies["construction-robotics"].enabled = false + force.technologies["logistic-robotics"].enabled = false + force.technologies["robotics"].enabled = false + force.technologies["personal-roboport-equipment"].enabled = false + force.technologies["personal-roboport-mk2-equipment"].enabled = false + force.technologies["character-logistic-trash-slots-1"].enabled = false + force.technologies["character-logistic-trash-slots-2"].enabled = false + force.technologies["auto-character-logistic-trash-slots"].enabled = false + force.technologies["worker-robots-storage-1"].enabled = false + force.technologies["worker-robots-storage-2"].enabled = false + force.technologies["worker-robots-storage-3"].enabled = false + force.technologies["character-logistic-slots-1"].enabled = false + force.technologies["character-logistic-slots-2"].enabled = false + force.technologies["character-logistic-slots-3"].enabled = false + force.technologies["character-logistic-slots-4"].enabled = false + force.technologies["character-logistic-slots-5"].enabled = false + force.technologies["character-logistic-slots-6"].enabled = false + force.technologies["worker-robots-speed-1"].enabled = false + force.technologies["worker-robots-speed-2"].enabled = false + force.technologies["worker-robots-speed-3"].enabled = false + force.technologies["worker-robots-speed-4"].enabled = false + force.technologies["worker-robots-speed-5"].enabled = false + force.technologies["worker-robots-speed-6"].enabled = false + elseif param == "false" then + game.print("The world is no longer spaghett!", {r = 1, g = 0.5, b = 0.1}) + force.technologies["logistic-system"].enabled = true + force.technologies["construction-robotics"].enabled = true + force.technologies["logistic-robotics"].enabled = true + force.technologies["robotics"].enabled = true + force.technologies["personal-roboport-equipment"].enabled = true + force.technologies["personal-roboport-mk2-equipment"].enabled = true + force.technologies["character-logistic-trash-slots-1"].enabled = true + force.technologies["character-logistic-trash-slots-2"].enabled = true + force.technologies["auto-character-logistic-trash-slots"].enabled = true + force.technologies["worker-robots-storage-1"].enabled = true + force.technologies["worker-robots-storage-2"].enabled = true + force.technologies["worker-robots-storage-3"].enabled = true + force.technologies["character-logistic-slots-1"].enabled = true + force.technologies["character-logistic-slots-2"].enabled = true + force.technologies["character-logistic-slots-3"].enabled = true + force.technologies["character-logistic-slots-4"].enabled = true + force.technologies["character-logistic-slots-5"].enabled = true + force.technologies["character-logistic-slots-6"].enabled = true + force.technologies["worker-robots-speed-1"].enabled = true + force.technologies["worker-robots-speed-2"].enabled = true + force.technologies["worker-robots-speed-3"].enabled = true + force.technologies["worker-robots-speed-4"].enabled = true + force.technologies["worker-robots-speed-5"].enabled = true + force.technologies["worker-robots-speed-6"].enabled = true + end +end) + +commands.add_command( + 'generate_map', + 'Pregenerates map.', + function(cmd) + local player = game.player + local param = tonumber(cmd.parameter) + local p + + if player then + if player ~= nil then + p = player.print + if not player.admin then + p("You're not admin!", {r = 1, g = 0.5, b = 0.1}) + return + end + else + p = log + end + end + if param == nil then player.print("Must specify radius!", {r=0.22, g=0.99, b=0.99}) return end + local radius = param + local surface = game.players[1].surface + if surface.is_chunk_generated({radius, radius}) then + game.print("Map generation done!", {r=0.22, g=0.99, b=0.99}) + return end - end - - game.write_file("layout.lua",'\n' , true) - game.write_file("layout.lua",'\n' , true) - game.write_file("layout.lua",'Tiles: \n' , true) - - for _, t in pairs(tiles) do - local str = "{position = {x = " .. t.position.x - str = str .. ", y = " - str = str .. t.position.y - str = str .. '}, name = "' - str = str .. t.name - str = str .. '"},' - game.write_file("layout.lua", str .. '\n' , true) - end -end \ No newline at end of file + surface.request_to_generate_chunks({0,0}, radius) + surface.force_generate_chunk_requests() + for _, pl in pairs(game.connected_players) do + pl.play_sound{path="utility/new_objective", volume_modifier=1} + end + game.print("Map generation done!", {r=0.22, g=0.99, b=0.99}) +end) + +commands.add_command( + 'dump_layout', + 'Dump the current map-layout.', + function() + local player = game.player + local p + + if player then + if player ~= nil then + p = player.print + if not player.admin then + p("You're not admin!", {r = 1, g = 0.5, b = 0.1}) + return + end + else + p = log + end + end + local surface = game.players[1].surface + game.write_file("layout.lua", "" , false) + + local area = { + left_top = {x = 0, y = 0}, + right_bottom = {x = 32, y = 32} + } + + local entities = surface.find_entities_filtered{area = area} + local tiles = surface.find_tiles_filtered{area = area} + + for _, e in pairs(entities) do + local str = "{position = {x = " .. e.position.x + str = str .. ", y = " + str = str .. e.position.y + str = str .. '}, name = "' + str = str .. e.name + str = str .. '", direction = ' + str = str .. tostring(e.direction) + str = str .. ', force = "' + str = str .. e.force.name + str = str .. '"},' + if e.name ~= "character" then + game.write_file("layout.lua", str .. '\n' , true) + end + end + + game.write_file("layout.lua",'\n' , true) + game.write_file("layout.lua",'\n' , true) + game.write_file("layout.lua",'Tiles: \n' , true) + + for _, t in pairs(tiles) do + local str = "{position = {x = " .. t.position.x + str = str .. ", y = " + str = str .. t.position.y + str = str .. '}, name = "' + str = str .. t.name + str = str .. '"},' + game.write_file("layout.lua", str .. '\n' , true) + player.print("Dumped layout as file: layout.lua") + end +end) + +commands.add_command( + 'creative', + 'Enables creative_mode.', + function() + local player = game.player + local p + + if player then + if player ~= nil then + p = player.print + if not player.admin then + p("You're not admin!", {r = 1, g = 0.5, b = 0.1}) + return + end + else + p = log + end + end + game.print(player.name .. " has activated creative-mode!", {r=0.22, g=0.99, b=0.99}) + log(player.name .. " has activated creative-mode!") + player.cheat_mode = true + player.insert{name="power-armor-mk2", count = 1} + local p_armor = player.get_inventory(5)[1].grid + p_armor.put({name = "fusion-reactor-equipment"}) + p_armor.put({name = "fusion-reactor-equipment"}) + p_armor.put({name = "fusion-reactor-equipment"}) + p_armor.put({name = "exoskeleton-equipment"}) + p_armor.put({name = "exoskeleton-equipment"}) + p_armor.put({name = "exoskeleton-equipment"}) + p_armor.put({name = "energy-shield-mk2-equipment"}) + p_armor.put({name = "energy-shield-mk2-equipment"}) + p_armor.put({name = "energy-shield-mk2-equipment"}) + p_armor.put({name = "energy-shield-mk2-equipment"}) + p_armor.put({name = "personal-roboport-mk2-equipment"}) + p_armor.put({name = "night-vision-equipment"}) + p_armor.put({name = "battery-mk2-equipment"}) + p_armor.put({name = "battery-mk2-equipment"}) + local item = game.item_prototypes + local i = 0 + for k, v in pairs(item) do + i = i + 1 + if k and v.type ~= "mining-tool" then + player.force.character_inventory_slots_bonus = tonumber(i) + player.insert{name=k, count=v.stack_size} + player.print("Inserted all items") + end + end +end) + +commands.add_command( + 'clear-corpses', + 'Clears all the biter corpses..', + function(cmd) + local player = game.player + local trusted = Session.get_trusted_table() + local param = tonumber(cmd.parameter) + local p + + if player then + if player ~= nil then + p = player.print + if not trusted[player.name] then + if not player.admin then + p("Only admins and trusted weebs are allowed to run this command!", {r = 1, g = 0.5, b = 0.1}) + return + end + end + else + p = log + end + end + if param == nil then player.print("Must specify radius!", {r=0.22, g=0.99, b=0.99}) return end + local radius = {{x = -param, y = -param}, {x = param, y = param}} or {{x = -1, y = -1}, {x = 1, y = 1}} + for _, entity in pairs(player.surface.find_entities_filtered{area = radius, type = "corpse"}) do + player.print("Cleared biter-corpses.") + entity.destroy() + end +end) \ No newline at end of file diff --git a/control.lua b/control.lua index 2b3e3882..5d3ec431 100644 --- a/control.lua +++ b/control.lua @@ -3,7 +3,7 @@ _LIFECYCLE = _STAGE.control -- Control stage _DEBUG = false _DUMP_ENV = false -server_commands = require 'utils.server' +require 'utils.server' require "utils.server_commands" require "utils.utils" require "utils.table" @@ -13,22 +13,21 @@ require "chatbot" require "commands" require "antigrief" require "player_modifiers" +require "modules.corpse_markers" +require "modules.floaty_chat" +require "modules.autohotbar" require "comfy_panel.main" require "comfy_panel.player_list" -require "comfy_panel.group" -require "comfy_panel.score" -require "comfy_panel.poll" require "comfy_panel.admin" +require "comfy_panel.group" +require "comfy_panel.poll" +require "comfy_panel.score" +require "comfy_panel.config" require "modules.autostash" -require "modules.corpse_markers" -require "modules.floaty_chat" ---require "modules.autohotbar" ---require "on_tick_schedule" ---- enable modules here ---- ---require "tools.cheat_mode" --require "modules.the_floor_is_lava" --require "modules.biters_landfill_on_death" --require "modules.autodecon_when_depleted" diff --git a/functions/basic_markets.lua b/functions/basic_markets.lua index cd42244c..c05cedf3 100644 --- a/functions/basic_markets.lua +++ b/functions/basic_markets.lua @@ -1,3 +1,5 @@ +local Public = {} + local market = {} market.weapons = { @@ -34,8 +36,8 @@ market.caspules = { ["poison-capsule"] = {value = 32, rarity = 6}, ["slowdown-capsule"] = {value = 8, rarity = 1}, ["defender-capsule"] = {value = 8, rarity = 1}, - ["distractor-capsule"] = {value = 16, rarity = 5}, - ["destroyer-capsule"] = {value = 24, rarity = 7}, + ["distractor-capsule"] = {value = 20, rarity = 5}, + ["destroyer-capsule"] = {value = 32, rarity = 7}, ["discharge-defense-remote"] = {value = 64, rarity = 6}, ["artillery-targeting-remote"] = {value = 32, rarity = 7}, ["raw-fish"] = {value = 6, rarity = 1}, @@ -123,12 +125,12 @@ market.vehicles = { ["train-stop"] = {value = 32, rarity = 3}, ["rail-signal"] = {value = 8, rarity = 5}, ["rail-chain-signal"] = {value = 8, rarity = 5}, - ["locomotive"] = {value = 640, rarity = 4}, - ["cargo-wagon"] = {value = 320, rarity = 4}, - ["fluid-wagon"] = {value = 480, rarity = 5}, + ["locomotive"] = {value = 400, rarity = 4}, + ["cargo-wagon"] = {value = 200, rarity = 4}, + ["fluid-wagon"] = {value = 300, rarity = 5}, ["artillery-wagon"] = {value = 8192, rarity = 8}, - ["car"] = {value = 96, rarity = 1}, - ["tank"] = {value = 2048, rarity = 5}, + ["car"] = {value = 80, rarity = 1}, + ["tank"] = {value = 1800, rarity = 5}, } market.wire = { @@ -172,7 +174,7 @@ local function get_resource_market_buys() {price = {{'stone', math.random(10,12)}}, offer = {type = 'give-item', item = "coin"}}, {price = {{'coal', math.random(10,12)}}, offer = {type = 'give-item', item = "coin"}}, {price = {{'uranium-ore', math.random(8,10)}}, offer = {type = 'give-item', item = "coin"}}, - {price = {{'water-barrel', 1}}, offer = {type = 'give-item', item = "coin", count = math.random(1,3)}}, + {price = {{'water-barrel', 1}}, offer = {type = 'give-item', item = "coin", count = math.random(1,2)}}, {price = {{'lubricant-barrel', 1}}, offer = {type = 'give-item', item = "coin", count = math.random(3,6)}}, {price = {{'sulfuric-acid-barrel', 1}}, offer = {type = 'give-item', item = "coin", count = math.random(4,8)}}, {price = {{'light-oil-barrel', 1}}, offer = {type = 'give-item', item = "coin", count = math.random(2,4)}}, @@ -212,7 +214,7 @@ local function get_random_market_item_list(rarity) return false end -function mountain_market(surface, position, rarity) +function Public.mountain_market(surface, position, rarity) local types = get_types() table.shuffle_table(types) local items = get_market_item_list({types[1], types[2], types[3]}, rarity) @@ -237,7 +239,7 @@ function mountain_market(surface, position, rarity) return market end -function super_market(surface, position, rarity) +function Public.super_market(surface, position, rarity) local items = get_market_item_list(get_types(), rarity) if not items then return end if #items > 0 then table.shuffle_table(items) end @@ -262,3 +264,5 @@ function super_market(surface, position, rarity) return market end + +return Public \ No newline at end of file diff --git a/functions/boss_unit.lua b/functions/boss_unit.lua index 3d67c565..3d9823ad 100644 --- a/functions/boss_unit.lua +++ b/functions/boss_unit.lua @@ -24,21 +24,25 @@ function add_boss_unit(entity, health_factor, size) if health == 0 then return end local s = 0.5 if size then s = size end - global.boss_units[entity.unit_number] = {entity = entity, max_health = health, health = health, healthbar_id = create_healthbar(entity, s)} + global.boss_units[entity.unit_number] = {entity = entity, max_health = health, health = health, healthbar_id = create_healthbar(entity, s), last_update = game.tick} end local function on_entity_damaged(event) local entity = event.entity if not entity.valid then return end - if entity.type ~= "unit" then return end - if not global.boss_units[entity.unit_number] then return end + if entity.type ~= "unit" then return end + local boss = global.boss_units[entity.unit_number] + if not boss then return end entity.health = entity.health + event.final_damage_amount - global.boss_units[entity.unit_number].health = global.boss_units[entity.unit_number].health - event.final_damage_amount - if global.boss_units[entity.unit_number].health <= 0 then + boss.health = boss.health - event.final_damage_amount + if boss.health <= 0 then global.boss_units[entity.unit_number] = nil entity.die() else - set_healthbar(global.boss_units[entity.unit_number]) + if boss.last_update + 10 < game.tick then + set_healthbar(global.boss_units[entity.unit_number]) + boss.last_update = game.tick + end end end diff --git a/functions/soft_reset.lua b/functions/soft_reset.lua index 7e88b66c..eb08eb2a 100644 --- a/functions/soft_reset.lua +++ b/functions/soft_reset.lua @@ -1,3 +1,8 @@ +local Server = require 'utils.server' +local Modifers = require 'player_modifiers' + +local Public = {} + local function reset_forces(new_surface, old_surface) for _, f in pairs(game.forces) do local spawn = {x = game.forces.player.get_spawn_position(old_surface).x, y = game.forces.player.get_spawn_position(old_surface).y} @@ -29,10 +34,11 @@ local function equip_players(player_starting_items) for item, amount in pairs(player_starting_items) do player.insert({name = item, count = amount}) end + Modifers.update_player_modifiers(player) end end -function soft_reset_map(old_surface, map_gen_settings, player_starting_items) +function Public.soft_reset_map(old_surface, map_gen_settings, player_starting_items) if not global.soft_reset_counter then global.soft_reset_counter = 0 end if not global.original_surface_name then global.original_surface_name = old_surface.name end global.soft_reset_counter = global.soft_reset_counter + 1 @@ -52,7 +58,9 @@ function soft_reset_map(old_surface, map_gen_settings, player_starting_items) message = table.concat({">> The world has been reshaped, welcome to ", global.original_surface_name, " number ", tostring(global.soft_reset_counter), "!"}) end game.print(message, {r=0.98, g=0.66, b=0.22}) - server_commands.to_discord_embed(message) + Server.to_discord_embed(message) return new_surface -end \ No newline at end of file +end + +return Public \ No newline at end of file diff --git a/maps/biter_battles/biter_battles.lua b/maps/biter_battles/biter_battles.lua index 3be06fde..b1546410 100644 --- a/maps/biter_battles/biter_battles.lua +++ b/maps/biter_battles/biter_battles.lua @@ -1,5 +1,6 @@ -- Biter Battles -- mewmew made this -- +local Server = require 'utils.server' require "on_tick_schedule" require "modules.splice_double" require "modules.explosive_biters" @@ -150,7 +151,7 @@ local function show_mvps(player) insert(result, 'MVP Deaths: \\n') insert(result, mvp.deaths.name .. " died " .. mvp.deaths.score .. " times" ) local message = table.concat(result) - server_commands.to_discord_embed(message) + Server.to_discord_embed(message) global.results_sent_north = true end end @@ -195,7 +196,7 @@ local function show_mvps(player) insert(result, 'MVP Deaths: \\n') insert(result, mvp.deaths.name .. " died " .. mvp.deaths.score .. " times" ) local message = table.concat(result) - server_commands.to_discord_embed(message) + Server.to_discord_embed(message) global.results_sent_south = true end end @@ -1193,8 +1194,8 @@ local function on_tick(event) global.game_restart_timer_completed = true game.print("Map is restarting!", { r=0.22, g=0.88, b=0.22}) local message = 'Map is restarting! ' - server_commands.to_discord_bold(table.concat{'*** ', message, ' ***'}) - server_commands.start_scenario('Biter_Battles') + Server.to_discord_bold(table.concat{'*** ', message, ' ***'}) + Server.start_scenario('Biter_Battles') end end end diff --git a/maps/biter_battles_v2/difficulty_vote.lua b/maps/biter_battles_v2/difficulty_vote.lua index 854ac47c..01a91bfd 100644 --- a/maps/biter_battles_v2/difficulty_vote.lua +++ b/maps/biter_battles_v2/difficulty_vote.lua @@ -1,4 +1,5 @@ -local event = require 'utils.event' +local event = require 'utils.event' +local Server = require 'utils.server' local difficulties = { [1] = {name = "Peaceful", str = "25%", value = 0.25, color = {r=0.00, g=0.45, b=0.00}, print_color = {r=0.00, g=0.9, b=0.00}}, @@ -70,7 +71,7 @@ local function set_difficulty() if global.difficulty_vote_index ~= new_index then local message = table.concat({">> Map difficulty has changed to ", difficulties[new_index].name, " difficulty!"}) game.print(message, difficulties[new_index].print_color) - server_commands.to_discord_embed(message) + Server.to_discord_embed(message) end global.difficulty_vote_index = new_index global.difficulty_vote_value = difficulties[new_index].value diff --git a/maps/biter_battles_v2/game_won.lua b/maps/biter_battles_v2/game_won.lua index 0fe4d5a3..14b9da16 100644 --- a/maps/biter_battles_v2/game_won.lua +++ b/maps/biter_battles_v2/game_won.lua @@ -1,4 +1,5 @@ -local event = require 'utils.event' +local event = require 'utils.event' +local Server = require 'utils.server' local gui_values = { ["north"] = {c1 = "Team North", color1 = {r = 0.55, g = 0.55, b = 0.99}}, @@ -235,7 +236,7 @@ local function show_mvps(player) table.insert(result, 'MVP Deaths: \\n') table.insert(result, mvp.deaths.name .. " died " .. mvp.deaths.score .. " times" ) local message = table.concat(result) - server_commands.to_discord_embed(message) + Server.to_discord_embed(message) global.results_sent_north = true end end @@ -280,7 +281,7 @@ local function show_mvps(player) table.insert(result, 'MVP Deaths: \\n') table.insert(result, mvp.deaths.name .. " died " .. mvp.deaths.score .. " times" ) local message = table.concat(result) - server_commands.to_discord_embed(message) + Server.to_discord_embed(message) global.results_sent_south = true end end @@ -298,8 +299,8 @@ local function server_restart() if global.server_restart_timer == 0 then game.print("Map is restarting!", {r=0.22, g=0.88, b=0.22}) local message = 'Map is restarting! ' - server_commands.to_discord_bold(table.concat{'*** ', message, ' ***'}) - server_commands.start_scenario('Biter_Battles') + Server.to_discord_bold(table.concat{'*** ', message, ' ***'}) + Server.start_scenario('Biter_Battles') global.server_restart_timer = nil return end @@ -346,8 +347,8 @@ local function on_entity_died(event) local c = gui_values[global.bb_game_won_by_team].c1 if global.tm_custom_name[global.bb_game_won_by_team] then c = global.tm_custom_name[global.bb_game_won_by_team] end - server_commands.to_discord_embed(c .. " has won!") - server_commands.to_discord_embed(global.victory_time) + Server.to_discord_embed(c .. " has won!") + Server.to_discord_embed(global.victory_time) fireworks(event.entity.surface) annihilate_base_v2(event.entity.position, event.entity.surface, event.entity.force.name) diff --git a/maps/biter_battles_v2/on_tick.lua b/maps/biter_battles_v2/on_tick.lua index 6f112260..31a037da 100644 --- a/maps/biter_battles_v2/on_tick.lua +++ b/maps/biter_battles_v2/on_tick.lua @@ -1,4 +1,5 @@ local event = require 'utils.event' +local Server = require 'utils.server' local gui = require "maps.biter_battles_v2.gui" local ai = require "maps.biter_battles_v2.ai" @@ -44,7 +45,7 @@ local function restart_idle_map() if not global.restart_idle_map_countdown then global.restart_idle_map_countdown = 2 end global.restart_idle_map_countdown = global.restart_idle_map_countdown - 1 if global.restart_idle_map_countdown ~= 0 then return end - server_commands.start_scenario('Biter_Battles') + Server.start_scenario('Biter_Battles') end local function on_tick(event) diff --git a/maps/biter_battles_v2/terrain.lua b/maps/biter_battles_v2/terrain.lua index 5236ec0b..9d7ebe38 100644 --- a/maps/biter_battles_v2/terrain.lua +++ b/maps/biter_battles_v2/terrain.lua @@ -1,4 +1,5 @@ local event = require 'utils.event' +local Server = require 'utils.server' local math_random = math.random local simplex_noise = require 'utils.simplex_noise'.d2 local create_tile_chain = require "functions.create_tile_chain" @@ -516,7 +517,7 @@ end local function on_init(surface) local surface = game.surfaces["biter_battles"] if bb_config.on_init_pregen then - server_commands.to_discord_embed("Generating chunks...") + Server.to_discord_embed("Generating chunks...") print("Generating chunks...") surface.request_to_generate_chunks({x = 0, y = -512}, 16) surface.request_to_generate_chunks({x = 1024, y = -512}, 16) diff --git a/maps/biter_hatchery/main.lua b/maps/biter_hatchery/main.lua new file mode 100644 index 00000000..0b45653e --- /dev/null +++ b/maps/biter_hatchery/main.lua @@ -0,0 +1,332 @@ +require "modules.no_turrets" +local RPG = require "modules.rpg" +local unit_raffle = require "maps.biter_hatchery.raffle_tables" +local map_functions = require "tools.map_functions" +local Terrain = require "maps.biter_hatchery.terrain" +local Reset = require "functions.soft_reset" +local Map = require "modules.map_info" +local math_random = math.random +local Public = {} +local starting_items = {['pistol'] = 1, ['firearm-magazine'] = 16} + +local function draw_spawn_ores(surface) + local x = global.map_forces.west.hatchery.position.x - 64 + map_functions.draw_smoothed_out_ore_circle({x = x, y = 32}, "iron-ore", surface, 15, 2500) + map_functions.draw_smoothed_out_ore_circle({x = x, y = -32}, "copper-ore", surface, 15, 2500) + map_functions.draw_smoothed_out_ore_circle({x = x, y = 0}, "coal", surface, 15, 1500) + + local x = global.map_forces.east.hatchery.position.x + 64 + map_functions.draw_smoothed_out_ore_circle({x = x, y = 32}, "copper-ore", surface, 15, 2500) + map_functions.draw_smoothed_out_ore_circle({x = x, y = -32}, "iron-ore", surface, 15, 2500) + map_functions.draw_smoothed_out_ore_circle({x = x, y = 0}, "coal", surface, 15, 1500) +end + +function Public.reset_map() + local map_gen_settings = {} + map_gen_settings.seed = math_random(1, 10000000) + map_gen_settings.height = 192 + map_gen_settings.water = 0.2 + map_gen_settings.starting_area = 1 + map_gen_settings.terrain_segmentation = 10 + map_gen_settings.cliff_settings = {cliff_elevation_interval = math.random(16, 48), cliff_elevation_0 = math.random(16, 48)} + map_gen_settings.autoplace_controls = { + ["coal"] = {frequency = 100, size = 0.5, richness = 0.5,}, + ["stone"] = {frequency = 100, size = 0.5, richness = 0.5,}, + ["copper-ore"] = {frequency = 100, size = 0.5, richness = 0.5,}, + ["iron-ore"] = {frequency = 100, size = 0.5, richness = 0.5,}, + ["uranium-ore"] = {frequency = 50, size = 0.5, richness = 0.5,}, + ["crude-oil"] = {frequency = 50, size = 0.5, richness = 0.5,}, + ["trees"] = {frequency = math.random(5, 10) * 0.1, size = math.random(5, 10) * 0.1, richness = math.random(3, 10) * 0.1}, + ["enemy-base"] = {frequency = 0, size = 0, richness = 0} + } + + if not global.active_surface_index then + global.active_surface_index = game.create_surface("biter_hatchery", map_gen_settings).index + else + global.active_surface_index = Reset.soft_reset_map(game.surfaces[global.active_surface_index], map_gen_settings, starting_items).index + end + + local surface = game.surfaces[global.active_surface_index] + surface.request_to_generate_chunks({0,0}, 10) + surface.force_generate_chunk_requests() + + for key, _ in pairs(global.map_forces) do + game.forces[key].technologies["artillery"].enabled = false + game.forces[key].technologies["artillery-shell-range-1"].enabled = false + game.forces[key].technologies["artillery-shell-speed-1"].enabled = false + end + + local e = surface.create_entity({name = "biter-spawner", position = {-160, 0}, force = "west"}) + e.active = false + global.map_forces.west.hatchery = e + global.map_forces.east.target = e + + local e = surface.create_entity({name = "biter-spawner", position = {160, 0}, force = "east"}) + e.active = false + global.map_forces.east.hatchery = e + global.map_forces.west.target = e + + draw_spawn_ores(surface) + + RPG.rpg_reset_all_players() + + game.forces.west.set_spawn_position({-160, 0}, surface) + game.forces.east.set_spawn_position({160, 0}, surface) + + for _, player in pairs(game.connected_players) do + if player.gui.left.biter_hatchery_game_won then player.gui.left.biter_hatchery_game_won.destroy() end + if math_random(1, 2) == 1 then + player.force = game.forces.east + else + player.force = game.forces.west + end + player.teleport(surface.find_non_colliding_position("character", player.force.get_spawn_position(surface), 32, 0.5), surface) + end +end + +local function spawn_units(belt, food_item, removed_item_count) + local count = unit_raffle[food_item][2] + local raffle = unit_raffle[food_item][1] + for _ = 1, count, 1 do + local unit = belt.surface.create_entity({name = raffle[math_random(1, #raffle)], position = belt.position, force = belt.force}) + unit.ai_settings.allow_destroy_when_commands_fail = false + unit.ai_settings.allow_try_return_to_spawner = false + end +end + +local function get_belts(spawner) + local belts = spawner.surface.find_entities_filtered({ + type = "transport-belt", + area = {{spawner.position.x - 5, spawner.position.y - 3},{spawner.position.x + 4, spawner.position.y + 3}}, + force = spawner.force, + }) + return belts +end + +local nom_msg = {"munch", "munch", "yum"} + +local function feed_floaty_text(entity) + entity.surface.create_entity({name = "flying-text", position = entity.position, text = nom_msg[math_random(1, #nom_msg)], color = {math_random(50, 100), 0, 255}}) + local position = {x = entity.position.x - 0.75, y = entity.position.y - 1} + local b = 1.35 + for a = 1, math_random(0, 2), 1 do + local p = {(position.x + 0.4) + (b * -1 + math_random(0, b * 20) * 0.1), position.y + (b * -1 + math_random(0, b * 20) * 0.1)} + entity.surface.create_entity({name = "flying-text", position = p, text = "♥", color = {math_random(150, 255), 0, 255}}) + end +end + +local function eat_food_from_belt(belt) + for i = 1, 2, 1 do + local line = belt.get_transport_line(i) + for food_item, raffle in pairs(unit_raffle) do + local removed_item_count = line.remove_item({name = food_item, count = 8}) + if removed_item_count > 0 then + feed_floaty_text(belt) + spawn_units(belt, food_item, removed_item_count) + end + end + end +end + +local function nom() + local surface = game.surfaces[global.active_surface_index] + for key, force in pairs(global.map_forces) do + local belts = get_belts(force.hatchery) + for _, belt in pairs(belts) do + eat_food_from_belt(belt) + end + end +end + +local function send_unit_groups() + local surface = game.surfaces[global.active_surface_index] + for key, force in pairs(global.map_forces) do + local units = {} + for _, unit in pairs(surface.find_entities_filtered({type = "unit", force = key})) do + if not unit.unit_group then + units[#units + 1] = unit + end + end + if #units > 0 then + local unit_group = surface.create_unit_group({position = force.hatchery.position, force = key}) + for _, unit in pairs(units) do unit_group.add_member(unit) end + unit_group.set_command({ + type = defines.command.compound, + structure_type = defines.compound_command.return_last, + commands = { + { + type = defines.command.attack_area, + destination = {x = force.target.position.x, y = force.target.position.y}, + radius = 8, + distraction = defines.distraction.by_enemy + }, + { + type = defines.command.attack, + target = force.target, + distraction = defines.distraction.by_enemy, + }, + } + }) + end + end +end + +local border_teleport = { + ["east"] = 2, + ["west"] = -2, +} + +local function on_player_changed_position(event) + local player = game.players[event.player_index] + if player.position.x >= -4 and player.position.x <= 4 then + if player.character.driving then player.character.driving = false end + player.teleport({player.position.x + border_teleport[player.force.name], player.position.y}, game.surfaces[global.active_surface_index]) + end +end + +local function on_entity_died(event) + if not event.entity.valid then return end + if event.entity.type ~= "unit-spawner" then return end + + local gui_str + if event.entity.force.name == "east" then + game.print("East lost their Hatchery.", {100, 100, 100}) + gui_str = ">>>> West team has won the game!!! <<<<" + else + game.print("West lost their Hatchery.", {100, 100, 100}) + gui_str = ">>>> East team has won the game!!! <<<<" + end + + global.game_reset_tick = game.tick + 1800 + + for _, player in pairs(game.connected_players) do + player.play_sound{path="utility/game_won", volume_modifier=0.85} + for _, child in pairs(player.gui.left.children) do child.destroy() end + player.gui.left.add({type = "frame", name = "biter_hatchery_game_won", caption = gui_str}) + end +end + +local function on_player_joined_game(event) + local player = game.players[event.player_index] + local surface = game.surfaces[global.active_surface_index] + + if player.gui.left.biter_hatchery_game_won then player.gui.left.biter_hatchery_game_won.destroy() end + + if player.surface.index ~= global.active_surface_index then + local force + if math_random(1, 2) == 1 then + force = game.forces.east + else + force = game.forces.west + end + player.force = force + if player.character then + if player.character.valid then + player.character.destroy() + end + end + player.character = nil + player.set_controller({type=defines.controllers.god}) + player.create_character() + player.teleport(surface.find_non_colliding_position("character", force.get_spawn_position(surface), 32, 0.5), surface) + for item, amount in pairs(starting_items) do + player.insert({name = item, count = amount}) + end + end +end + +local function tick() + local t2 = game.tick % 900 + if t2 == 0 then send_unit_groups() end + + if global.game_reset_tick then + if global.game_reset_tick < game.tick then + global.game_reset_tick = nil + Public.reset_map() + end + return + end + + nom() + + if game.tick % 240 == 0 then + local area = {{-256, -96}, {255, 96}} + game.forces.west.chart(game.surfaces[global.active_surface_index], area) + game.forces.east.chart(game.surfaces[global.active_surface_index], area) + end +end + +--Construction Robot Restriction +local robot_build_restriction = { + ["east"] = function(x) + if x < 0 then return true end + end, + ["west"] = function(x) + if x > 0 then return true end + end +} + +local function on_robot_built_entity(event) + if not robot_build_restriction[event.robot.force.name] then return end + if not robot_build_restriction[event.robot.force.name](event.created_entity.position.x) then return end + local inventory = event.robot.get_inventory(defines.inventory.robot_cargo) + inventory.insert({name = event.created_entity.name, count = 1}) + event.robot.surface.create_entity({name = "explosion", position = event.created_entity.position}) + game.print("Team " .. event.robot.force.name .. "'s construction drone had an accident.", {r = 200, g = 50, b = 100}) + event.created_entity.destroy() +end + +local function on_entity_damaged(event) + local entity = event.entity + if not entity.valid then return end + if entity.type ~= "unit-spawner" then return end + local cause = event.cause + if cause then + if cause.valid then + if cause.type == "unit" then return end + end + end + entity.health = entity.health + event.final_damage_amount +end + +local function on_init() + game.map_settings.enemy_evolution.destroy_factor = 0 + game.map_settings.enemy_evolution.pollution_factor = 0 + game.map_settings.enemy_evolution.time_factor = 0 + game.map_settings.enemy_expansion.enabled = false + game.map_settings.pollution.enabled = false + global.map_forces = { + ["west"] = {}, + ["east"] = {}, + } + + local T = Map.Pop_info() + T.main_caption = "Biter Hatchery" + T.sub_caption = "..nibble nibble nom nom.." + T.text = table.concat({ + "Defeat the enemy teams nest.\n", + "Feed your hatchery science flasks to breed biters!\n", + "They will soon after swarm to the opposing teams nest!,\n", + "\n", + "Lay transport belts to your hatchery and they will happily nom the juice off the conveyor.\n", + "Higher tier flasks will breed stronger biters!\n", + "\n", + "Turrets are disabled.\n", + "The center river may not be crossed.\n", + "Construction robots may not build over the river.\n", + }) + T.main_caption_color = {r = 150, g = 0, b = 255} + T.sub_caption_color = {r = 0, g = 250, b = 150} + + for key, _ in pairs(global.map_forces) do game.create_force(key) end + Public.reset_map() +end + +local event = require 'utils.event' +event.on_init(on_init) +event.on_nth_tick(60, tick) +event.add(defines.events.on_robot_built_entity, on_robot_built_entity) +event.add(defines.events.on_entity_died, on_entity_died) +event.add(defines.events.on_player_joined_game, on_player_joined_game) +event.add(defines.events.on_player_changed_position, on_player_changed_position) +event.add(defines.events.on_entity_damaged, on_entity_damaged) \ No newline at end of file diff --git a/maps/biter_hatchery/raffle_tables.lua b/maps/biter_hatchery/raffle_tables.lua new file mode 100644 index 00000000..d9444a19 --- /dev/null +++ b/maps/biter_hatchery/raffle_tables.lua @@ -0,0 +1,51 @@ +local raffle = { + ["automation-science-pack"] = {{}, 1}, + ["logistic-science-pack"] = {{}, 2}, + ["military-science-pack"] = {{}, 3}, + ["chemical-science-pack"] = {{}, 4}, + ["production-science-pack"] = {{}, 5}, + ["utility-science-pack"] = {{}, 6}, + ["space-science-pack"] = {{}, 7}, +} + +local t = raffle["automation-science-pack"][1] +for _ = 1, 4, 1 do table.insert(t, "small-biter") end +for _ = 1, 1, 1 do table.insert(t, "small-spitter") end + +local t = raffle["logistic-science-pack"][1] +for _ = 1, 32, 1 do table.insert(t, "small-biter") end +for _ = 1, 8, 1 do table.insert(t, "small-spitter") end +for _ = 1, 4, 1 do table.insert(t, "medium-biter") end +for _ = 1, 1, 1 do table.insert(t, "medium-spitter") end + +local t = raffle["military-science-pack"][1] +for _ = 1, 8, 1 do table.insert(t, "small-biter") end +for _ = 1, 2, 1 do table.insert(t, "small-spitter") end +for _ = 1, 16, 1 do table.insert(t, "medium-biter") end +for _ = 1, 4, 1 do table.insert(t, "medium-spitter") end +for _ = 1, 4, 1 do table.insert(t, "big-biter") end +for _ = 1, 1, 1 do table.insert(t, "big-spitter") end + +local t = raffle["chemical-science-pack"][1] +for _ = 1, 12, 1 do table.insert(t, "medium-biter") end +for _ = 1, 3, 1 do table.insert(t, "medium-spitter") end +for _ = 1, 4, 1 do table.insert(t, "big-biter") end +for _ = 1, 1, 1 do table.insert(t, "big-spitter") end + +local t = raffle["production-science-pack"][1] +for _ = 1, 4, 1 do table.insert(t, "medium-biter") end +for _ = 1, 1, 1 do table.insert(t, "medium-spitter") end +for _ = 1, 12, 1 do table.insert(t, "big-biter") end +for _ = 1, 3, 1 do table.insert(t, "big-spitter") end + +local t = raffle["utility-science-pack"][1] +for _ = 1, 32, 1 do table.insert(t, "big-biter") end +for _ = 1, 8, 1 do table.insert(t, "big-spitter") end +for _ = 1, 4, 1 do table.insert(t, "behemoth-biter") end +for _ = 1, 1, 1 do table.insert(t, "behemoth-spitter") end + +local t = raffle["space-science-pack"][1] +for _ = 1, 4, 1 do table.insert(t, "behemoth-biter") end +for _ = 1, 1, 1 do table.insert(t, "behemoth-spitter") end + +return raffle \ No newline at end of file diff --git a/maps/biter_hatchery/terrain.lua b/maps/biter_hatchery/terrain.lua new file mode 100644 index 00000000..b23b913a --- /dev/null +++ b/maps/biter_hatchery/terrain.lua @@ -0,0 +1,45 @@ +local function get_replacement_tile(surface, position) + for i = 1, 128, 1 do + local vectors = {{0, i}, {0, i * -1}, {i, 0}, {i * -1, 0}} + table.shuffle_table(vectors) + for k, v in pairs(vectors) do + local tile = surface.get_tile(position.x + v[1], position.y + v[2]) + if not tile.collides_with("resource-layer") then return tile.name end + end + end + return "grass-1" +end + +local function combat_area(event) + local surface = event.surface + for _, tile in pairs(surface.find_tiles_filtered({area = event.area})) do + if tile.name == "water" or tile.name == "deepwater" then + surface.set_tiles({{name = get_replacement_tile(surface, tile.position), position = tile.position}}, true) + end + if tile.position.x >= -4 and tile.position.x <= 4 then + surface.set_tiles({{name = "water-shallow", position = tile.position}}, true) + end + end + for _, entity in pairs(surface.find_entities_filtered({type = {"resource", "cliff"}, area = event.area})) do + entity.destroy() + end +end + +local function on_chunk_generated(event) + local left_top = event.area.left_top + if left_top.y >= 96 then return end + if left_top.y < -96 then return end + + if left_top.x >= -192 and left_top.x < 192 then combat_area(event) end + + if left_top.x > 512 then return end + if left_top.x < -512 then return end + if left_top.y > 512 then return end + if left_top.y < -512 then return end + + game.forces.west.chart(event.surface, {{left_top.x, left_top.y},{left_top.x + 31, left_top.y + 31}}) + game.forces.east.chart(event.surface, {{left_top.x, left_top.y},{left_top.x + 31, left_top.y + 31}}) +end + +local event = require 'utils.event' +event.add(defines.events.on_chunk_generated, on_chunk_generated) \ No newline at end of file diff --git a/maps/blue_beach.lua b/maps/blue_beach.lua index 5d1e23b8..a47ce6ec 100644 --- a/maps/blue_beach.lua +++ b/maps/blue_beach.lua @@ -7,8 +7,8 @@ require "modules.dynamic_player_spawn" require "modules.no_deconstruction_of_neutral_entities" require "modules.biter_pets" require "modules.biter_evasion_hp_increaser" -require "modules.wave_defense.main" +local WD = require "modules.wave_defense.main" local event = require 'utils.event' local math_random = math.random local simplex_noise = require 'utils.simplex_noise'.d2 @@ -144,6 +144,7 @@ local function on_chunk_generated(event) end local function init_surface() + local wave_defense_table = WD.get_table() if game.surfaces["blue_beach"] then return game.surfaces["blue_beach"] end local map_gen_settings = {} @@ -181,18 +182,19 @@ local function init_surface() global.average_worm_amount_per_chunk = 4 - global.wave_defense.surface_index = surface.index + wave_defense_table.surface_index = surface.index return surface end local function on_player_joined_game(event) + local wave_defense_table = WD.get_table() local surface = init_surface() local player = game.players[event.player_index] --20 Players for maximum difficulty - global.wave_defense.wave_interval = 3600 - #game.connected_players * 180 - if global.wave_defense.wave_interval < 1800 then global.wave_defense.wave_interval = 1800 end + wave_defense_table.wave_interval = 3600 - #game.connected_players * 180 + if wave_defense_table.wave_interval < 1800 then wave_defense_table.wave_interval = 1800 end if player.online_time == 0 then local spawn = game.forces["player"].get_spawn_position(game.surfaces["blue_beach"]) diff --git a/maps/choppy.lua b/maps/choppy.lua index 3f6241e8..fb87f7c9 100644 --- a/maps/choppy.lua +++ b/maps/choppy.lua @@ -4,28 +4,7 @@ require "on_tick_schedule" require "modules.dynamic_landfill" require "modules.satellite_score" require "modules.spawners_contain_biters" -require "modules.map_info" -map_info = {} -map_info.main_caption = "Choppy" -map_info.sub_caption = "" -map_info.text = [[ - You are a lumberjack with a passion to chop. - - Different kinds of trees, yield different kinds of ore and wood. - Yes, they seem to draw minerals out of the ground and manifesting it as "fruit". - Their yield increases with distance. Mining Productivity Research will increase chopping speed and backpack size. - - Beware, sometimes there are some bugs hiding underneath the trees. - Even dangerous traps have been encountered before. - - Also, these mysterious ore trees don't burn very well, so do not worry if some of them catch on fire. - - Choppy Choppy Wood -]] - -map_info.main_caption_color = {r = 0, g = 120, b = 0} -map_info.sub_caption_color = {r = 255, g = 0, b = 255} - +local Map = require "modules.map_info" local unearthing_worm = require "functions.unearthing_worm" local unearthing_biters = require "functions.unearthing_biters" local tick_tack_trap = require "functions.tick_tack_trap" @@ -351,7 +330,31 @@ local function on_entity_died(event) end end end - + +local on_init = function() + local T = Map.Pop_info() + T.main_caption = "Choppy" + T.sub_caption = "" + T.text = [[ + You are a lumberjack with a passion to chop. + + Different kinds of trees, yield different kinds of ore and wood. + Yes, they seem to draw minerals out of the ground and manifesting it as "fruit". + Their yield increases with distance. Mining Productivity Research will increase chopping speed and backpack size. + + Beware, sometimes there are some bugs hiding underneath the trees. + Even dangerous traps have been encountered before. + + Also, these mysterious ore trees don't burn very well, so do not worry if some of them catch on fire. + + Choppy Choppy Wood + ]] + + T.main_caption_color = {r = 0, g = 120, b = 0} + T.sub_caption_color = {r = 255, g = 0, b = 255} +end + +event.on_init(on_init) event.add(defines.events.on_research_finished, on_research_finished) event.add(defines.events.on_marked_for_deconstruction, on_marked_for_deconstruction) event.add(defines.events.on_player_joined_game, on_player_joined_game) diff --git a/maps/fish_defender/main.lua b/maps/fish_defender/main.lua index ada482fe..e9d45018 100644 --- a/maps/fish_defender/main.lua +++ b/maps/fish_defender/main.lua @@ -1,7 +1,8 @@ -- fish defender -- by mewmew -- +require "modules.rpg" + require "maps.fish_defender.terrain" -require "maps.fish_defender.map_intro" require "maps.fish_defender.market" require "maps.fish_defender.shotgun_buff" require "maps.fish_defender.on_entity_damaged" @@ -9,16 +10,14 @@ require "maps.fish_defender.on_entity_damaged" require "modules.rocket_launch_always_yields_science" require "modules.launch_fish_to_win" require "modules.biters_yield_coins" -require "modules.dynamic_landfill" require "modules.dangerous_goods" require "modules.custom_death_messages" -require "modules.biter_evasion_hp_increaser" -require "modules.rocks_yield_ore" -require "modules.rpg" +local Unit_health_booster = require "modules.biter_health_booster" +local Map = require "modules.map_info" local event = require 'utils.event' +local Server = require 'utils.server' local boss_biter = require "maps.fish_defender.boss_biters" -require "functions.boss_unit" local math_random = math.random local insert = table.insert local enable_start_grace_period = true @@ -482,7 +481,7 @@ local function spawn_boss_units(surface) biter.ai_settings.allow_destroy_when_commands_fail = false biter.ai_settings.allow_try_return_to_spawner = false global.boss_biters[biter.unit_number] = biter - add_boss_unit(biter, global.biter_evasion_health_increase_factor * health_factor, 0.55) + Unit_health_booster.add_boss_unit(biter, global.biter_health_boost * health_factor, 0.55) biter_group.add_member(biter) end end @@ -573,7 +572,7 @@ local function biter_attack_wave() end game.forces.enemy.set_ammo_damage_modifier("melee", global.wave_count * m) game.forces.enemy.set_ammo_damage_modifier("biological", global.wave_count * m) - global.biter_evasion_health_increase_factor = 1 + (global.wave_count * (m * 2)) + global.biter_health_boost = 1 + (global.wave_count * (m * 2)) local m = 4 if global.difficulty_vote_index then @@ -743,7 +742,7 @@ local function is_game_lost() insert(result, 'MVP Deaths: \\n') insert(result, mvp.deaths.name .. " died " .. mvp.deaths.score .. " times" ) local message = table.concat(result) - server_commands.to_discord_embed(message) + Server.to_discord_embed(message) global.results_sent = true end end @@ -968,8 +967,8 @@ local function on_tick() --game.write_file("commandPipe", ":loadscenario --force", false, 0) local message = 'Map is restarting! ' - server_commands.to_discord_bold(table.concat{'*** ', message, ' ***'}) - server_commands.start_scenario('Fish_Defender') + Server.to_discord_bold(table.concat{'*** ', message, ' ***'}) + Server.start_scenario('Fish_Defender') end end @@ -1081,6 +1080,32 @@ local function on_init(event) fish_eye(surface, {x = -2150, y = -300}) global.chunk_queue = {} + + local T = Map.Pop_info() + T.main_caption = "--Fish Defender--" + T.sub_caption = "*blb blubby blub*" + T.text = [[ + The biters have catched the scent of fish in the market. + Fend them off as long as possible! + This however will not be an easy task, + since their strength and resistance increases constantly over time. + + Your ultimate goal is to evacuate all the fish to cat planet! + Put them in your rocket's cargo and launch them into space. + Don't worry, you will still get space science. + + The Market will gladly take any coin you might find. + Additional turret slots can be bought at the market. + Several unique upgrades are available too. + + Researching tanks will unlock the artillery technology early. + + Any container bearing dangerous goods, like ammo, grenades or barrels, + causes heavy explosions when it breaks. + Maybe this can be used to our advantage. + ]] + T.main_caption_color = {r=0.11, g=0.8, b=0.44} + T.sub_caption_color = {r=0.33, g=0.66, b=0.9} end event.add(defines.events.on_gui_click, on_gui_click) @@ -1097,5 +1122,4 @@ event.add(defines.events.on_robot_mined_entity, on_robot_mined_entity) event.add(defines.events.on_tick, on_tick) event.on_init(on_init) -require "modules.difficulty_vote" -require "modules.rpg" \ No newline at end of file +require "modules.difficulty_vote" \ No newline at end of file diff --git a/maps/fish_defender/map_intro.lua b/maps/fish_defender/map_intro.lua deleted file mode 100644 index 61ad2c64..00000000 --- a/maps/fish_defender/map_intro.lua +++ /dev/null @@ -1,97 +0,0 @@ -local event = require 'utils.event' - -local main_caption = " --Fish Defender-- " -local sub_caption = " *blb blubby blub* " -local info = [[ - The biters have catched the scent of fish in the market. - Fend them off as long as possible! - This however will not be an easy task, - since their strength and resistance increases constantly over time. - - Your ultimate goal is to evacuate all the fish to cat planet! - Put them in your rocket's cargo and launch them into space. - Don't worry, you will still get space science. - - The Market will gladly take any coin you might find. - Additional turret slots can be bought at the market. - Several unique upgrades are available too. - - Researching tanks will unlock the artillery technology early. - - Any container bearing dangerous goods, like ammo, grenades or barrels, - causes heavy explosions when it breaks. - Maybe this can be used to our advantage. -]] - -local function create_map_intro_button(player) - if player.gui.top["map_intro_button"] then return end - local b = player.gui.top.add({type = "sprite-button", caption = "?", name = "map_intro_button", tooltip = "Map Info"}) - b.style.font_color = {r=0.11, g=0.8, b=0.44} - b.style.font = "heading-1" - b.style.minimal_height = 38 - b.style.minimal_width = 38 - b.style.top_padding = 2 - b.style.left_padding = 4 - b.style.right_padding = 4 - b.style.bottom_padding = 2 -end - -local function create_map_intro(player) - if player.gui.left["map_intro_frame"] then player.gui.left["map_intro_frame"].destroy() end - local frame = player.gui.left.add {type = "frame", name = "map_intro_frame", direction = "vertical"} - local t = frame.add {type = "table", column_count = 1} - - local tt = t.add {type = "table", column_count = 3} - local l = tt.add {type = "label", caption = main_caption} - l.style.font = "heading-1" - l.style.font_color = {r=0.11, g=0.8, b=0.44} - - local l = tt.add {type = "label", caption = sub_caption} - l.style.font = "heading-2" - l.style.font_color = {r=0.33, g=0.66, b=0.9} - l.style.minimal_width = 320 - - local b = tt.add {type = "button", caption = "X", name = "close_map_intro_frame", align = "right"} - b.style.font = "heading-2" - b.style.minimal_height = 30 - b.style.minimal_width = 30 - b.style.top_padding = 2 - b.style.left_padding = 4 - b.style.right_padding = 4 - b.style.bottom_padding = 2 - - local tt = t.add {type = "table", column_count = 1} - local frame = t.add {type = "frame"} - local l = frame.add {type = "label", caption = info} - l.style.single_line = false - l.style.font = "heading-2" - l.style.font_color = {r=0.75, g=0.8, b=0.8} - l.style.minimal_width = 480 -end - -local function on_gui_click(event) - if not event then return end - if not event.element then return end - if not event.element.valid then return end - local player = game.players[event.element.player_index] - if event.element.name == "close_map_intro_frame" then player.gui.left["map_intro_frame"].destroy() return end - if event.element.name == "map_intro_button" then - if player.gui.left["map_intro_frame"] then - player.gui.left["map_intro_frame"].destroy() - else - create_map_intro(player) - end - return - end -end - -local function on_player_joined_game(event) - local player = game.players[event.player_index] - create_map_intro_button(player) - if player.online_time == 0 then - create_map_intro(player) - end -end - -event.add(defines.events.on_player_joined_game, on_player_joined_game) -event.add(defines.events.on_gui_click, on_gui_click) \ No newline at end of file diff --git a/maps/fish_defender/market.lua b/maps/fish_defender/market.lua index 002df2cf..cdbacee8 100644 --- a/maps/fish_defender/market.lua +++ b/maps/fish_defender/market.lua @@ -6,6 +6,7 @@ require 'maps.fish_defender.vehicle_nanobots' require 'maps.fish_defender.laser_pointer' local event = require 'utils.event' +local Server = require 'utils.server' local slot_upgrade_offers = { [1] = {"gun-turret", "gun turret"}, @@ -166,7 +167,7 @@ local function slot_upgrade(player, offer_index) global.entity_limits[slot_upgrade_offers[offer_index][1]].limit = global.entity_limits[slot_upgrade_offers[offer_index][1]].limit + gain game.print(player.name .. " has bought a " .. slot_upgrade_offers[offer_index][2] .. " slot for " .. price .. " coins!", {r = 0.22, g = 0.77, b = 0.44}) - server_commands.to_discord_bold(table.concat{player.name .. " has bought a " .. slot_upgrade_offers[offer_index][2] .. " slot for " .. price .. " coins!"}) + Server.to_discord_bold(table.concat{player.name .. " has bought a " .. slot_upgrade_offers[offer_index][2] .. " slot for " .. price .. " coins!"}) refresh_market_offers() end diff --git a/maps/fish_defender/on_entity_damaged.lua b/maps/fish_defender/on_entity_damaged.lua index 193ebc9d..dbb66a36 100644 --- a/maps/fish_defender/on_entity_damaged.lua +++ b/maps/fish_defender/on_entity_damaged.lua @@ -6,9 +6,9 @@ local bouncy_shells = require 'maps.fish_defender.bouncy_shells' local boss_biter = require "maps.fish_defender.boss_biters" local function protect_market(event) - if event.entity.name ~= "market" then return false end + if event.entity.name ~= "market" then return end if event.cause then - if event.cause.force.name == "enemy" then return false end + if event.cause.force.name == "enemy" then return end end event.entity.health = event.entity.health + event.final_damage_amount return true diff --git a/maps/fish_defender/terrain.lua b/maps/fish_defender/terrain.lua index 0000511c..fc81fd03 100644 --- a/maps/fish_defender/terrain.lua +++ b/maps/fish_defender/terrain.lua @@ -1,6 +1,9 @@ local map_functions = require "tools.map_functions" local simplex_noise = require "utils.simplex_noise".d2 local math_random = math.random +local math_abs = math.abs +local math_floor = math.floor +local math_sqrt = math.sqrt local hourglass_center_piece_length = 64 local worm_raffle_table = { @@ -30,22 +33,22 @@ local function get_replacement_tile(surface, position) end local function is_enemy_territory(p) - if p.x - 64 < math.abs(p.y) then return false end + if p.x - 64 < math_abs(p.y) then return false end --if p.x - 64 < p.y then return false end if p.x < 160 then return false end if p.x > 1024 then return false end if p.y > 512 then return false end if p.y < -512 then return false end - local noise = math.abs(simplex_noise(0, p.y * 0.015, game.surfaces[1].map_gen_settings.seed) * 96) - local noise_2 = math.abs(simplex_noise(0, p.y * 0.1, game.surfaces[1].map_gen_settings.seed) * 16) - if p.x > 288 + noise + noise_2 + math.abs(p.y * 0.75) then return false end + local noise = math_abs(simplex_noise(0, p.y * 0.015, game.surfaces[1].map_gen_settings.seed) * 96) + local noise_2 = math_abs(simplex_noise(0, p.y * 0.1, game.surfaces[1].map_gen_settings.seed) * 16) + if p.x > 288 + noise + noise_2 + math_abs(p.y * 0.75) then return false end return true end local body_radius = 3072 local body_square_radius = body_radius ^ 2 local body_center_position = {x = -1500, y = 0} -local body_spacing = math.floor(body_radius * 0.82) +local body_spacing = math_floor(body_radius * 0.82) local body_circle_center_1 = {x = body_center_position.x, y = body_center_position.y - body_spacing} local body_circle_center_2 = {x = body_center_position.x, y = body_center_position.y + body_spacing} @@ -64,7 +67,7 @@ local function is_body(p) --Fish Fins local distance_to_center_1 = ((p.x - fin_circle_center_1.x)^2 + (p.y - fin_circle_center_1.y)^2) - if distance_to_center_1 + math.abs(simplex_noise(0, p.y * 0.075, game.surfaces[1].map_gen_settings.seed) * 32000) > square_fin_radius then + if distance_to_center_1 + math_abs(simplex_noise(0, p.y * 0.075, game.surfaces[1].map_gen_settings.seed) * 32000) > square_fin_radius then local distance_to_center_2 = ((p.x - fin_circle_center_2.x)^2 + (p.y - fin_circle_center_2.y)^2) if distance_to_center_2 < square_fin_radius then return true @@ -98,13 +101,13 @@ local function generate_spawn_area(surface) surface.create_entity({name = "electric-beam", position = {160, -96}, source = {160, -96}, target = {160,96}}) for _, tile in pairs(surface.find_tiles_filtered({name = {"water", "deepwater"}, area = {{-160, -160},{160, 160}}})) do - local noise = math.abs(simplex_noise(tile.position.x * 0.02, tile.position.y * 0.02, game.surfaces[1].map_gen_settings.seed) * 16) + local noise = math_abs(simplex_noise(tile.position.x * 0.02, tile.position.y * 0.02, game.surfaces[1].map_gen_settings.seed) * 16) if tile.position.x > -160 + noise then surface.set_tiles({{name = get_replacement_tile(surface, tile.position), position = {tile.position.x, tile.position.y}}}, true) end end for _, entity in pairs(surface.find_entities_filtered({type = {"resource", "cliff"}, area = {{spawn_position_x - 32, -256},{160, 256}}})) do if is_body(entity.position) then - if entity.position.x > spawn_position_x - 32 + math.abs(simplex_noise(entity.position.x * 0.02, entity.position.y * 0.02, game.surfaces[1].map_gen_settings.seed) * 16) then + if entity.position.x > spawn_position_x - 32 + math_abs(simplex_noise(entity.position.x * 0.02, entity.position.y * 0.02, game.surfaces[1].map_gen_settings.seed) * 16) then entity.destroy() end end @@ -137,7 +140,7 @@ local function generate_spawn_area(surface) local r = 16 for _, entity in pairs(surface.find_entities_filtered({area = {{global.market.position.x - r, global.market.position.y - r}, {global.market.position.x + r, global.market.position.y + r}}, type = "tree"})) do - local distance_to_center = math.sqrt((entity.position.x - global.market.position.x)^2 + (entity.position.y - global.market.position.y)^2) + local distance_to_center = math_sqrt((entity.position.x - global.market.position.x)^2 + (entity.position.y - global.market.position.y)^2) if distance_to_center < r then if math_random(1, r) > distance_to_center then entity.destroy() end end @@ -150,7 +153,7 @@ local function generate_spawn_area(surface) for x = -20, 20, 1 do for y = -20, 20, 1 do local pos = {x = global.market.position.x + x, y = global.market.position.y + y} - local distance_to_center = math.sqrt(x^2 + y^2) + local distance_to_center = math_sqrt(x^2 + y^2) if distance_to_center > 8 and distance_to_center < 15 then if math_random(1,3) == 1 and surface.can_place_entity({name = "wooden-chest", position = pos, force = "player"}) then local chest = surface.create_entity({name = "wooden-chest", position = pos, force = "player"}) @@ -215,7 +218,7 @@ local function enemy_territory(surface, left_top) -- decorative_names[#decorative_names+1] = k -- end -- end - -- surface.regenerate_decorative(decorative_names, {{x=math.floor(pos.x/32),y=math.floor(pos.y/32)}}) + -- surface.regenerate_decorative(decorative_names, {{x=math_floor(pos.x/32),y=math_floor(pos.y/32)}}) --end end end @@ -258,7 +261,7 @@ function fish_eye(surface, position) for x = -48, 48, 1 do for y = -48, 48, 1 do local p = {x = position.x + x, y = position.y + y} - local distance = math.sqrt(((position.x - p.x) ^ 2) + ((position.y - p.y) ^ 2)) + local distance = math_sqrt(((position.x - p.x) ^ 2) + ((position.y - p.y) ^ 2)) if distance < 44 then surface.set_tiles({{name = "water-green", position = p}}, true) end @@ -274,26 +277,26 @@ local ores = {"coal", "iron-ore", "copper-ore", "stone"} local function plankton_territory(surface, position, seed) local noise = simplex_noise(position.x * 0.009, position.y * 0.009, seed) local d = 196 - if position.x + position.y > (d * -1) - (math.abs(noise) * d * 3) and position.x > position.y - (d + (math.abs(noise) * d * 3)) then return false end + if position.x + position.y > (d * -1) - (math_abs(noise) * d * 3) and position.x > position.y - (d + (math_abs(noise) * d * 3)) then return false end local noise_2 = simplex_noise(position.x * 0.0075, position.y * 0.0075, seed + 10000) if noise_2 > 0.87 then surface.set_tiles({{name = "deepwater-green", position = position}}, true) return true end if noise_2 > 0.75 then - local i = math.floor(noise * 6) % 4 + 1 + local i = math_floor(noise * 6) % 4 + 1 surface.set_tiles({{name = "grass-" .. i, position = position}}, true) - surface.create_entity({name = ores[i], position = position, amount = 1 + 2500 * math.abs(noise_2 * 3)}) + surface.create_entity({name = ores[i], position = position, amount = 1 + 2500 * math_abs(noise_2 * 3)}) return true end if noise_2 < -0.76 then - local i = math.floor(noise * 6) % 4 + 1 + local i = math_floor(noise * 6) % 4 + 1 surface.set_tiles({{name = "grass-" .. i, position = position}}, true) - if noise_2 < -0.86 then surface.create_entity({name = "uranium-ore", position = position, amount = 1 + 1000 * math.abs(noise_2 * 2)}) return true end + if noise_2 < -0.86 then surface.create_entity({name = "uranium-ore", position = position, amount = 1 + 1000 * math_abs(noise_2 * 2)}) return true end if math_random(1, 3) ~= 1 then surface.create_entity({name = rock_raffle[math_random(1, #rock_raffle)], position = position}) end return true end if noise < 0.12 and noise > -0.12 then - local i = math.floor(noise * 32) % 4 + 1 + local i = math_floor(noise * 32) % 4 + 1 surface.set_tiles({{name = "grass-" .. i, position = position}}, true) if math_random(1, 5) == 1 then surface.create_entity({name = rock_raffle[math_random(1, #rock_raffle)], position = position}) end return true @@ -343,10 +346,10 @@ local function on_chunk_generated(event) if game.tick == 0 then process_chunk(left_top) else - global.chunk_queue[#global.chunk_queue + 1] = {x = left_top.x, y = left_top.y} + table.insert(global.chunk_queue, {x = left_top.x, y = left_top.y}) end end local event = require 'utils.event' -event.on_nth_tick(30, process_chunk_queue) +event.on_nth_tick(25, process_chunk_queue) event.add(defines.events.on_chunk_generated, on_chunk_generated) \ No newline at end of file diff --git a/maps/fish_defender_v1/fish_defender.lua b/maps/fish_defender_v1/fish_defender.lua index e5cf0a56..1863124c 100644 --- a/maps/fish_defender_v1/fish_defender.lua +++ b/maps/fish_defender_v1/fish_defender.lua @@ -14,6 +14,7 @@ require "modules.custom_death_messages" require "modules.biter_evasion_hp_increaser" local event = require 'utils.event' +local Server = require 'utils.server' local boss_biter = require "maps.fish_defender.boss_biters" require "functions.boss_unit" local map_functions = require "tools.map_functions" @@ -840,7 +841,7 @@ local function is_game_lost() insert(result, 'MVP Deaths: \\n') insert(result, mvp.deaths.name .. " died " .. mvp.deaths.score .. " times" ) local message = table.concat(result) - server_commands.to_discord_embed(message) + Server.to_discord_embed(message) global.results_sent = true end end @@ -1371,8 +1372,8 @@ local function on_tick() --game.write_file("commandPipe", ":loadscenario --force", false, 0) local message = 'Map is restarting! ' - server_commands.to_discord_bold(table.concat{'*** ', message, ' ***'}) - server_commands.start_scenario('Fish_Defender') + Server.to_discord_bold(table.concat{'*** ', message, ' ***'}) + Server.start_scenario('Fish_Defender') end end diff --git a/maps/fish_defender_v1/market.lua b/maps/fish_defender_v1/market.lua index 002df2cf..cdbacee8 100644 --- a/maps/fish_defender_v1/market.lua +++ b/maps/fish_defender_v1/market.lua @@ -6,6 +6,7 @@ require 'maps.fish_defender.vehicle_nanobots' require 'maps.fish_defender.laser_pointer' local event = require 'utils.event' +local Server = require 'utils.server' local slot_upgrade_offers = { [1] = {"gun-turret", "gun turret"}, @@ -166,7 +167,7 @@ local function slot_upgrade(player, offer_index) global.entity_limits[slot_upgrade_offers[offer_index][1]].limit = global.entity_limits[slot_upgrade_offers[offer_index][1]].limit + gain game.print(player.name .. " has bought a " .. slot_upgrade_offers[offer_index][2] .. " slot for " .. price .. " coins!", {r = 0.22, g = 0.77, b = 0.44}) - server_commands.to_discord_bold(table.concat{player.name .. " has bought a " .. slot_upgrade_offers[offer_index][2] .. " slot for " .. price .. " coins!"}) + Server.to_discord_bold(table.concat{player.name .. " has bought a " .. slot_upgrade_offers[offer_index][2] .. " slot for " .. price .. " coins!"}) refresh_market_offers() end diff --git a/maps/mountain_fortress_v2/flamethrower_nerf.lua b/maps/mountain_fortress_v2/flamethrower_nerf.lua index f5f8e9b7..6402bc18 100644 --- a/maps/mountain_fortress_v2/flamethrower_nerf.lua +++ b/maps/mountain_fortress_v2/flamethrower_nerf.lua @@ -2,15 +2,15 @@ local function on_research_finished(event) local research = event.research local force_name = research.force.name - if research.name == "flamethrower" then + if research.name == "military" then if not global.flamethrower_damage then global.flamethrower_damage = {} end - global.flamethrower_damage[force_name] = -0.6 + global.flamethrower_damage[force_name] = -0.50 game.forces[force_name].set_turret_attack_modifier("flamethrower-turret", global.flamethrower_damage[force_name]) game.forces[force_name].set_ammo_damage_modifier("flamethrower", global.flamethrower_damage[force_name]) end if string.sub(research.name, 0, 18) == "refined-flammables" then - global.flamethrower_damage[force_name] = global.flamethrower_damage[force_name] + 0.08 + global.flamethrower_damage[force_name] = global.flamethrower_damage[force_name] + 0.10 game.forces[force_name].set_turret_attack_modifier("flamethrower-turret", global.flamethrower_damage[force_name]) game.forces[force_name].set_ammo_damage_modifier("flamethrower", global.flamethrower_damage[force_name]) end diff --git a/maps/mountain_fortress_v2/locomotive.lua b/maps/mountain_fortress_v2/locomotive.lua index 35d90759..cd80e291 100644 --- a/maps/mountain_fortress_v2/locomotive.lua +++ b/maps/mountain_fortress_v2/locomotive.lua @@ -1,4 +1,6 @@ -function locomotive_spawn(surface, position) +local Public = {} + +function Public.locomotive_spawn(surface, position) for y = -6, 6, 2 do surface.create_entity({name = "straight-rail", position = {position.x, position.y + y}, force = "player", direction = 0}) end @@ -20,7 +22,7 @@ function locomotive_spawn(surface, position) global.locomotive_cargo.operable = false end ---[[ + local function fish_tag() if not global.locomotive_cargo then return end if not global.locomotive_cargo.valid then return end @@ -39,7 +41,7 @@ local function fish_tag() text = " " }) end - +--[[ local function accelerate() if not global.locomotive then return end if not global.locomotive.valid then return end @@ -55,28 +57,18 @@ local function remove_acceleration() if global.locomotive_driver then global.locomotive_driver.destroy() end global.locomotive_driver = nil end - -local function set_daytime() - if not global.locomotive_cargo then return end - if not global.locomotive_cargo.valid then return end - local p = global.locomotive_cargo.position.y - local t = math.abs(global.locomotive_cargo.position.y) * 0.02 - if t > 0.5 then t = 0.5 end - global.locomotive_cargo.surface.daytime = t - game.print(t) -end ]] - local function set_player_spawn_and_refill_fish() if not global.locomotive_cargo then return end if not global.locomotive_cargo.valid then return end - global.locomotive_cargo.get_inventory(defines.inventory.cargo_wagon).insert({name = "raw-fish", count = 4}) + global.locomotive_cargo.health = global.locomotive_cargo.health + 6 + global.locomotive_cargo.get_inventory(defines.inventory.cargo_wagon).insert({name = "raw-fish", count = math.random(2, 5)}) local position = global.locomotive_cargo.surface.find_non_colliding_position("stone-furnace", global.locomotive_cargo.position, 16, 2) if not position then return end game.forces.player.set_spawn_position({x = position.x, y = position.y}, global.locomotive_cargo.surface) end -local function tick() +local function tick() if game.tick % 30 == 0 then if game.tick % 1800 == 0 then set_player_spawn_and_refill_fish() @@ -84,12 +76,11 @@ local function tick() if global.game_reset_tick then if global.game_reset_tick < game.tick then global.game_reset_tick = nil - reset_map() + require "maps.mountain_fortress_v2.main".reset_map() end return end - --fish_tag() - --set_daytime() + fish_tag() --accelerate() else --remove_acceleration() @@ -97,4 +88,6 @@ local function tick() end local event = require 'utils.event' -event.on_nth_tick(5, tick) \ No newline at end of file +event.on_nth_tick(5, tick) + +return Public \ No newline at end of file diff --git a/maps/mountain_fortress_v2/main.lua b/maps/mountain_fortress_v2/main.lua index 283db7c2..358cd8d9 100644 --- a/maps/mountain_fortress_v2/main.lua +++ b/maps/mountain_fortress_v2/main.lua @@ -1,46 +1,31 @@ -- Mountain digger fortress, protect the cargo wagon! -- by MewMew ---require "modules.flashlight_toggle_button" ---require "modules.biter_noms_you" -require "modules.rpg" -require "modules.wave_defense.main" require "functions.soft_reset" require "functions.basic_markets" + +local RPG = require "modules.rpg" +require "modules.wave_defense.main" require "modules.biters_yield_coins" -require "modules.biter_pets" require "modules.no_deconstruction_of_neutral_entities" require "modules.shotgun_buff" require "modules.explosives" +require "modules.mineable_wreckage_yields_scrap" require "modules.rocks_broken_paint_tiles" require "modules.rocks_heal_over_time" require "modules.rocks_yield_ore_veins" -require "modules.spawners_contain_biters" -require "modules.map_info" -map_info = {} -map_info.main_caption = "M O U N T A I N F O R T R E S S" -map_info.sub_caption = " ..diggy diggy choo choo.." -map_info.text = table.concat({ - "The biters have catched the scent of fish in the cargo wagon.\n", - "Guide the choo into the mountain and protect it as long as possible!\n", - "This however will not be an easy task,\n", - "since their strength and resistance increases constantly over time.\n", - "\n", - "Delve deep for greater treasures, but also face increased dangers.\n", - "Mining productivity research, will overhaul your mining equipment,\n", - "reinforcing your pickaxe as well as increasing the size of your backpack.\n", - "\n", - "As you dig, you will encounter impassable dark chasms or rivers.\n", - "Some explosives may cause parts of the ceiling to crumble, filling the void, creating new ways.\n", - "All they need is a container and a well aimed shot.\n", -}) -map_info.main_caption_color = {r = 150, g = 150, b = 0} -map_info.sub_caption_color = {r = 0, g = 150, b = 0} - require "maps.mountain_fortress_v2.market" -require "maps.mountain_fortress_v2.treasure" -require "maps.mountain_fortress_v2.terrain" -require "maps.mountain_fortress_v2.locomotive" +local level_depth = require "maps.mountain_fortress_v2.terrain" require "maps.mountain_fortress_v2.flamethrower_nerf" +local BiterRolls = require "modules.wave_defense.biter_rolls" +local Reset = require "functions.soft_reset" +local Pets = require "modules.biter_pets" +local Map = require "modules.map_info" +local WD = require "modules.wave_defense.table" +local Treasure = require "maps.mountain_fortress_v2.treasure" +local Locomotive = require "maps.mountain_fortress_v2.locomotive".locomotive_spawn +local Modifier = require "player_modifiers" + +local Public = {} local starting_items = {['pistol'] = 1, ['firearm-magazine'] = 16, ['rail'] = 16, ['wood'] = 16, ['explosives'] = 32} local treasure_chest_messages = { @@ -49,7 +34,8 @@ local treasure_chest_messages = { "We has found the precious!", } -function reset_map() +function Public.reset_map() + local wave_defense_table = WD.get_table() global.chunk_queue = {} local map_gen_settings = { @@ -71,7 +57,7 @@ function reset_map() global.active_surface_index = game.create_surface("mountain_fortress", map_gen_settings).index else game.forces.player.set_spawn_position({-2, 16}, game.surfaces[global.active_surface_index]) - global.active_surface_index = soft_reset_map(game.surfaces[global.active_surface_index], map_gen_settings, starting_items).index + global.active_surface_index = Reset.soft_reset_map(game.surfaces[global.active_surface_index], map_gen_settings, starting_items).index end local surface = game.surfaces[global.active_surface_index] @@ -100,20 +86,15 @@ function reset_map() game.forces.player.technologies["railway"].researched = true game.forces.player.set_spawn_position({-2, 16}, surface) - locomotive_spawn(surface, {x = 0, y = 16}) + Locomotive(surface, {x = 0, y = 16}) - reset_wave_defense() - global.wave_defense.surface_index = global.active_surface_index - global.wave_defense.target = global.locomotive_cargo - global.wave_defense.side_target_search_radius = 768 - global.wave_defense.unit_group_command_step_length = 32 - global.wave_defense.nest_building_density = 32 - global.wave_defense.threat_gain_multiplier = 3 - global.wave_defense.game_lost = false + WD.reset_wave_defense() + wave_defense_table.surface_index = global.active_surface_index + wave_defense_table.target = global.locomotive_cargo + wave_defense_table.nest_building_density = 32 + wave_defense_table.game_lost = false - --for _, p in pairs(game.connected_players) do - -- if p.character then p.character.disable_flashlight() end - --end + RPG.rpg_reset_all_players() end local function protect_train(event) @@ -149,73 +130,125 @@ local function biters_chew_rocks_faster(event) if not event.cause then return end if not event.cause.valid then return end if event.cause.force.index ~= 2 then return end --Enemy Force - --local bonus_damage = event.final_damage_amount * math.abs(global.wave_defense.threat) * 0.0002 + --local bonus_damage = event.final_damage_amount * math.abs(wave_defense_table.threat) * 0.0002 event.entity.health = event.entity.health - event.final_damage_amount * 2.5 end local function hidden_biter(entity) - wave_defense_set_unit_raffle(math.sqrt(entity.position.x ^ 2 + entity.position.y ^ 2) * 0.33) + BiterRolls.wave_defense_set_unit_raffle(math.sqrt(entity.position.x ^ 2 + entity.position.y ^ 2) * 0.25) if math.random(1,3) == 1 then - entity.surface.create_entity({name = wave_defense_roll_spitter_name(), position = entity.position}) + entity.surface.create_entity({name = BiterRolls.wave_defense_roll_spitter_name(), position = entity.position}) else - entity.surface.create_entity({name = wave_defense_roll_biter_name(), position = entity.position}) + entity.surface.create_entity({name = BiterRolls.wave_defense_roll_biter_name(), position = entity.position}) end end +local function hidden_worm(entity) + BiterRolls.wave_defense_set_worm_raffle(math.sqrt(entity.position.x ^ 2 + entity.position.y ^ 2) * 0.25) + entity.surface.create_entity({name = BiterRolls.wave_defense_roll_worm_name(), position = entity.position}) +end + local function hidden_biter_pet(event) if math.random(1, 2048) ~= 1 then return end - wave_defense_set_unit_raffle(math.sqrt(event.entity.position.x ^ 2 + event.entity.position.y ^ 2) * 0.33) + BiterRolls.wave_defense_set_unit_raffle(math.sqrt(event.entity.position.x ^ 2 + event.entity.position.y ^ 2) * 0.25) local unit if math.random(1,3) == 1 then - unit = event.entity.surface.create_entity({name = wave_defense_roll_spitter_name(), position = event.entity.position}) + unit = event.entity.surface.create_entity({name = BiterRolls.wave_defense_roll_spitter_name(), position = event.entity.position}) else - unit = event.entity.surface.create_entity({name = wave_defense_roll_biter_name(), position = event.entity.position}) - end - biter_pets_tame_unit(game.players[event.player_index], unit, true) + unit = event.entity.surface.create_entity({name = BiterRolls.wave_defense_roll_biter_name(), position = event.entity.position}) + end + Pets.biter_pets_tame_unit(game.players[event.player_index], unit, true) end local function hidden_treasure(event) if math.random(1, 320) ~= 1 then return end game.players[event.player_index].print(treasure_chest_messages[math.random(1, #treasure_chest_messages)], {r=0.98, g=0.66, b=0.22}) - treasure_chest(event.entity.surface, event.entity.position) + Treasure(event.entity.surface, event.entity.position, "wooden-chest") +end + +local projectiles = {"grenade", "explosive-rocket", "grenade", "explosive-rocket", "explosive-cannon-projectile"} +local function angry_tree(entity, cause) + if entity.type ~= "tree" then return end + if math.abs(entity.position.y) < level_depth then return end + if math.random(1,4) == 1 then hidden_biter(entity) end + if math.random(1,8) == 1 then hidden_worm(entity) end + if math.random(1,16) ~= 1 then return end + local position = false + if cause then + if cause.valid then + position = cause.position + end + end + if not position then position = {entity.position.x + (-20 + math.random(0, 40)), entity.position.y + (-20 + math.random(0, 40))} end + + entity.surface.create_entity({ + name = projectiles[math.random(1, 5)], + position = entity.position, + force = "neutral", + source = entity.position, + target = position, + max_range = 64, + speed = 0.10 + }) +end + +local function give_coin(player) + player.insert({name = "coin", count = 1}) end local function on_player_mined_entity(event) if not event.entity.valid then return end - if event.entity.force.index == 3 then - if event.entity.type ~= "simple-entity" then return end + if event.entity.force.index ~= 3 then return end + + if event.entity.type == "simple-entity" then + give_coin(game.players[event.player_index]) + if math.random(1,32) == 1 then hidden_biter(event.entity) return - end + end + if math.random(1,512) == 1 then + hidden_worm(event.entity) + return + end hidden_biter_pet(event) - hidden_treasure(event) + hidden_treasure(event) end + + angry_tree(event.entity, game.players[event.player_index].character) end local function on_entity_died(event) + local wave_defense_table = WD.get_table() if not event.entity.valid then return end if event.entity == global.locomotive_cargo then game.print("The cargo was destroyed!") - global.wave_defense.game_lost = true + wave_defense_table.game_lost = true + wave_defense_table.target = nil global.game_reset_tick = game.tick + 1800 for _, player in pairs(game.connected_players) do player.play_sound{path="utility/game_lost", volume_modifier=0.75} end event.entity.surface.spill_item_stack(event.entity.position,{name = "raw-fish", count = 512}, false) - --rpg_reset_all_players() return end - + if event.cause then if event.cause.valid then if event.cause.force.index == 2 or event.cause.force.index == 3 then return end end end + if event.entity.force.index == 3 then + --local r_max = 15 - math.floor(math.abs(event.entity.position.y) / (level_depth * 0.5)) + --if r_max < 3 then r_max = 3 end if math.random(1,8) == 1 then hidden_biter(event.entity) end + + if math.random(1,256) == 1 then hidden_worm(event.entity) end + + angry_tree(event.entity, event.cause) end end @@ -236,15 +269,17 @@ local function on_research_finished(event) end local function set_difficulty() - --20 Players for maximum difficulty - global.wave_defense.wave_interval = 3600 - #game.connected_players * 90 - if global.wave_defense.wave_interval < 1800 then global.wave_defense.wave_interval = 1800 end + local wave_defense_table = WD.get_table() + + wave_defense_table.threat_gain_multiplier = 2 + #game.connected_players * 0.1 + --20 Players for fastest wave_interval + wave_defense_table.wave_interval = 3600 - #game.connected_players * 90 + if wave_defense_table.wave_interval < 1800 then wave_defense_table.wave_interval = 1800 end end local function on_player_joined_game(event) local player = game.players[event.player_index] - --if player.character then player.character.disable_flashlight() end - + set_difficulty() local surface = game.surfaces[global.active_surface_index] @@ -267,19 +302,36 @@ local function on_player_joined_game(event) end global.player_modifiers[player.index].character_mining_speed_modifier["mountain_fortress"] = 0.5 - update_player_modifiers(player) + Modifier.update_player_modifiers(player) end ---[[ -local function on_player_respawned(event) - local player = game.players[event.player_index] - if player.character then player.character.disable_flashlight() end -end -]] -local function on_init(surface) +local function on_player_left_game(event) + set_difficulty() +end + +local function on_init() + local T = Map.Pop_info() + T.main_caption = "M O U N T A I N F O R T R E S S" + T.sub_caption = " ..diggy diggy choo choo.." + T.text = table.concat({ + "The biters have catched the scent of fish in the cargo wagon.\n", + "Guide the choo into the mountain and protect it as long as possible!\n", + "This however will not be an easy task,\n", + "since their strength and numbers increase over time.\n", + "\n", + "Delve deep for greater treasures, but also face increased dangers.\n", + "Mining productivity research, will overhaul your mining equipment,\n", + "reinforcing your pickaxe as well as increasing the size of your backpack.\n", + "\n", + "As you dig, you will encounter impassable dark chasms or rivers.\n", + "Some explosives may cause parts of the ceiling to crumble, filling the void, creating new ways.\n", + "All they need is a container and a well aimed shot.\n", + }) + T.main_caption_color = {r = 150, g = 150, b = 0} + T.sub_caption_color = {r = 0, g = 150, b = 0} global.rocks_yield_ore_maximum_amount = 999 global.rocks_yield_ore_base_amount = 50 - global.rocks_yield_ore_distance_modifier = 0.03 + global.rocks_yield_ore_distance_modifier = 0.025 global.explosion_cells_destructible_tiles = { ["out-of-map"] = 1500, @@ -290,16 +342,18 @@ local function on_init(surface) ["water-shallow"] = 1000, } - reset_map() + Public.reset_map() end local event = require 'utils.event' event.on_init(on_init) event.add(defines.events.on_entity_damaged, on_entity_damaged) event.add(defines.events.on_entity_died, on_entity_died) +event.add(defines.events.on_player_joined_game, on_player_joined_game) +event.add(defines.events.on_player_left_game, on_player_left_game) event.add(defines.events.on_player_mined_entity, on_player_mined_entity) event.add(defines.events.on_research_finished, on_research_finished) -event.add(defines.events.on_player_joined_game, on_player_joined_game) ---event.add(defines.events.on_player_respawned, on_player_respawned) -require "modules.rocks_yield_ore" \ No newline at end of file +require "modules.rocks_yield_ore" + +return Public \ No newline at end of file diff --git a/maps/mountain_fortress_v2/market.lua b/maps/mountain_fortress_v2/market.lua index 8b28687c..d369bce1 100644 --- a/maps/mountain_fortress_v2/market.lua +++ b/maps/mountain_fortress_v2/market.lua @@ -1,6 +1,9 @@ local math_random = math.random -function secret_shop(pos, surface) +local Public = {} + + +function Public.secret_shop(pos, surface) if surface.count_entities_filtered{area={{pos.x - 128, pos.y - 128}, {pos.x + 128, pos.y + 128}}, name="market", limit=1} > 0 then return end local secret_market_items = { {price = {{"coin", math_random(8,16)}}, offer = {type = 'give-item', item = 'grenade'}}, @@ -48,4 +51,6 @@ function secret_shop(pos, surface) for i = 1, math_random(6, 8), 1 do market.add_market_item(secret_market_items[i]) end -end \ No newline at end of file +end + +return Public.secret_shop \ No newline at end of file diff --git a/maps/mountain_fortress_v2/terrain.lua b/maps/mountain_fortress_v2/terrain.lua index 65758de0..83c1a9ef 100644 --- a/maps/mountain_fortress_v2/terrain.lua +++ b/maps/mountain_fortress_v2/terrain.lua @@ -1,4 +1,9 @@ +local Biters = require 'modules.wave_defense.biter_rolls' +local Treasure = require 'maps.mountain_fortress_v2.treasure' +local Market = require 'functions.basic_markets' local math_random = math.random +local math_floor = math.floor +local math_abs = math.abs local simplex_noise = require "utils.simplex_noise".d2 local rock_raffle = {"sand-rock-big","sand-rock-big", "rock-big","rock-big","rock-big","rock-big","rock-big","rock-big","rock-big","rock-huge"} local spawner_raffle = {"biter-spawner", "biter-spawner", "biter-spawner", "spitter-spawner"} @@ -11,9 +16,12 @@ local noises = { ["cave_ponds"] = {{modifier = 0.01, weight = 1}, {modifier = 0.1, weight = 0.06}}, ["cave_rivers"] = {{modifier = 0.005, weight = 1}, {modifier = 0.01, weight = 0.25}, {modifier = 0.05, weight = 0.01}}, ["cave_rivers_2"] = {{modifier = 0.003, weight = 1}, {modifier = 0.01, weight = 0.21}, {modifier = 0.05, weight = 0.01}}, + ["cave_rivers_3"] = {{modifier = 0.002, weight = 1}, {modifier = 0.01, weight = 0.15}, {modifier = 0.05, weight = 0.01}}, + ["cave_rivers_4"] = {{modifier = 0.001, weight = 1}, {modifier = 0.01, weight = 0.11}, {modifier = 0.05, weight = 0.01}}, + ["scrapyard"] = {{modifier = 0.005, weight = 1}, {modifier = 0.01, weight = 0.35}, {modifier = 0.05, weight = 0.23}, {modifier = 0.1, weight = 0.11}}, } -local level_depth = 1024 -local worm_level_modifier = 0.25 +local level_depth = 960 +local worm_level_modifier = 0.20 local function get_noise(name, pos, seed) local noise = 0 @@ -39,27 +47,232 @@ local function get_replacement_tile(surface, position) return "grass-1" end +local function get_oil_amount(p) + return (math_abs(p.y) * 200 + 10000) * math_random(75, 125) * 0.01 +end + +local function process_level_10_position(p, seed, tiles, entities, markets, treasure) + local noise_1 = get_noise("small_caves", p, seed) + local noise_2 = get_noise("no_rocks_2", p, seed + 10000) + + if noise_1 > 0.7 then + tiles[#tiles + 1] = {name = "water", position = p} + if math_random(1,48) == 1 then entities[#entities + 1] = {name="fish", position=p} end + return + end + + if noise_1 < -0.72 then + tiles[#tiles + 1] = {name = "lab-dark-1", position = p} + entities[#entities + 1] = {name = "uranium-ore", position = p, amount = math_abs(p.y) + 1 * 3} + return + end + + if noise_1 > -0.25 and noise_1 < 0.25 then + tiles[#tiles + 1] = {name = "dirt-7", position = p} + if noise_1 > -0.20 and noise_1 < 0.20 then + if math_random(1,10) > 1 then entities[#entities + 1] = {name = rock_raffle[math_random(1, #rock_raffle)], position = p} end + if math_random(1,256) == 1 then treasure[#treasure + 1] = p end + end + return + end + + if math_random(1,64) == 1 and noise_2 > 0.65 then entities[#entities + 1] = {name = "crude-oil", position = p, amount = get_oil_amount(p)} end + if math_random(1,8192) == 1 then markets[#markets + 1] = p end + if math_random(1,1024) == 1 then entities[#entities + 1] = {name = "crash-site-chest-" .. math_random(1,2), position = p, force = "neutral"} end + + tiles[#tiles + 1] = {name = "tutorial-grid", position = p} +end + +local function process_level_9_position(p, seed, tiles, entities, markets, treasure) + local maze_p = {x = math_floor(p.x - p.x % 10), y = math_floor(p.y - p.y % 10)} + local maze_noise = get_noise("no_rocks_2", maze_p, seed) + + if maze_noise > -0.35 and maze_noise < 0.35 then + tiles[#tiles + 1] = {name = "dirt-7", position = p} + local no_rocks_2 = get_noise("no_rocks_2", p, seed) + if math_random(1,4) > 1 and no_rocks_2 > -0.5 then entities[#entities + 1] = {name = rock_raffle[math_random(1, #rock_raffle)], position = p} end + if math_random(1,1024) == 1 then treasure[#treasure + 1] = p end + if math_random(1,256) == 1 then + Biters.wave_defense_set_worm_raffle(math_abs(p.y) * worm_level_modifier) + entities[#entities + 1] = {name = Biters.wave_defense_roll_worm_name(), position = p, force = "enemy"} + end + return + end + + if maze_noise > 0 and maze_noise < 0.45 then + if math_random(1,512) == 1 then markets[#markets + 1] = p end + if math_random(1,256) == 1 then entities[#entities + 1] = {name = "crude-oil", position = p, amount = get_oil_amount(p)} end + if math_random(1,32) == 1 then entities[#entities + 1] = {name = "tree-0" .. math_random(1, 9), position=p} end + return + end + + if maze_noise < -0.5 or maze_noise > 0.5 then + tiles[#tiles + 1] = {name = "deepwater", position = p} + if math_random(1,96) == 1 then entities[#entities + 1] = {name="fish", position=p} end + return + end + + tiles[#tiles + 1] = {name = "water", position = p} + if math_random(1,96) == 1 then entities[#entities + 1] = {name="fish", position=p} end +end + +local scrap_entities = {"crash-site-assembling-machine-1-broken", "crash-site-assembling-machine-2-broken", "crash-site-assembling-machine-1-broken", "crash-site-assembling-machine-2-broken", "crash-site-lab-broken", + "medium-ship-wreck", "small-ship-wreck", "medium-ship-wreck", "small-ship-wreck", "medium-ship-wreck", "small-ship-wreck", "medium-ship-wreck", "small-ship-wreck", + "crash-site-chest-1", "crash-site-chest-2", "crash-site-chest-1", "crash-site-chest-2", "crash-site-chest-1", "crash-site-chest-2"} +local scrap_entities_index = #scrap_entities + +--SCRAPYARD +local function process_level_8_position(p, seed, tiles, entities, markets, treasure) + local scrapyard = get_noise("scrapyard", p, seed) + + --Chasms + local noise_cave_ponds = get_noise("cave_ponds", p, seed) + local small_caves = get_noise("small_caves", p, seed) + if noise_cave_ponds < 0.15 and noise_cave_ponds > -0.15 then + if small_caves > 0.35 then + tiles[#tiles + 1] = {name = "out-of-map", position = p} + return + end + if small_caves < -0.35 then + tiles[#tiles + 1] = {name = "out-of-map", position = p} + return + end + end + + if scrapyard < -0.25 or scrapyard > 0.25 then + if math_random(1, 256) == 1 then + entities[#entities + 1] = {name="gun-turret", position=p, force = "enemy"} + end + tiles[#tiles + 1] = {name = "dirt-7", position = p} + if scrapyard < -0.55 or scrapyard > 0.55 then + if math_random(1,5) > 1 then entities[#entities + 1] = {name = rock_raffle[math_random(1, #rock_raffle)], position = p} end + return + end + if scrapyard < -0.28 or scrapyard > 0.28 then + if math_random(1,128) == 1 then + Biters.wave_defense_set_worm_raffle(math_abs(p.y) * worm_level_modifier) + entities[#entities + 1] = {name = Biters.wave_defense_roll_worm_name(), position = p, force = "enemy"} + end + if math_random(1,96) == 1 then entities[#entities + 1] = {name = scrap_entities[math_random(1, scrap_entities_index)], position = p, force = "enemy"} end + if math_random(1,5) > 1 then entities[#entities + 1] = {name="mineable-wreckage", position=p} end + return + end + return + end + + local cave_ponds = get_noise("cave_ponds", p, seed) + if cave_ponds < -0.6 and scrapyard > -0.2 and scrapyard < 0.2 then + tiles[#tiles + 1] = {name = "deepwater-green", position = p} + if math_random(1,128) == 1 then entities[#entities + 1] = {name="fish", position=p} end + return + end + + local large_caves = get_noise("large_caves", p, seed) + if scrapyard > -0.15 and scrapyard < 0.15 then + if math_floor(large_caves * 10) % 4 < 3 then + tiles[#tiles + 1] = {name = "dirt-7", position = p} + if math_random(1,3) > 1 then entities[#entities + 1] = {name = rock_raffle[math_random(1, #rock_raffle)], position = p} end + return + end + end + + if math_random(1,64) == 1 and cave_ponds > 0.6 then entities[#entities + 1] = {name = "crude-oil", position = p, amount = get_oil_amount(p)} end + + tiles[#tiles + 1] = {name = "stone-path", position = p} +end + +local function process_level_7_position(p, seed, tiles, entities, markets, treasure) + local cave_rivers_3 = get_noise("cave_rivers_3", p, seed) + local cave_rivers_4 = get_noise("cave_rivers_4", p, seed + 50000) + local no_rocks_2 = get_noise("no_rocks_2", p, seed) + + if cave_rivers_3 > -0.025 and cave_rivers_3 < 0.025 and no_rocks_2 > -0.6 then + tiles[#tiles + 1] = {name = "water", position = p} + if math_random(1,128) == 1 then entities[#entities + 1] = {name="fish", position=p} end + return + end + + if cave_rivers_4 > -0.025 and cave_rivers_4 < 0.025 and no_rocks_2 > -0.6 then + tiles[#tiles + 1] = {name = "water", position = p} + if math_random(1,128) == 1 then entities[#entities + 1] = {name="fish", position=p} end + return + end + + local noise_ores = get_noise("no_rocks_2", p, seed + 25000) + + if cave_rivers_3 > -0.20 and cave_rivers_3 < 0.20 then + tiles[#tiles + 1] = {name = "grass-" .. math_floor(cave_rivers_3 * 32) % 3 + 1, position = p} + if cave_rivers_3 > -0.10 and cave_rivers_3 < 0.10 then + if math_random(1,12) == 1 and no_rocks_2 > -0.25 then entities[#entities + 1] = {name = "tree-01", position=p} end + if math_random(1,2048) == 1 then markets[#markets + 1] = p end + if noise_ores < -0.5 and no_rocks_2 > -0.6 then + if cave_rivers_3 > 0 and cave_rivers_3 < 0.07 then + entities[#entities + 1] = {name = "iron-ore", position=p, amount = math_abs(p.y) + 1} + end + end + end + if math_random(1,64) == 1 and no_rocks_2 > 0.7 then entities[#entities + 1] = {name = "crude-oil", position = p, amount = get_oil_amount(p)} end + if math_random(1,2048) == 1 then treasure[#treasure + 1] = p end + return + end + + if cave_rivers_4 > -0.20 and cave_rivers_4 < 0.20 then + tiles[#tiles + 1] = {name = "grass-" .. math_floor(cave_rivers_4 * 32) % 3 + 1, position = p} + if cave_rivers_4 > -0.10 and cave_rivers_4 < 0.10 then + if math_random(1,12) == 1 and no_rocks_2 > -0.25 then entities[#entities + 1] = {name = "tree-02", position=p} end + if math_random(1,2048) == 1 then markets[#markets + 1] = p end + if noise_ores < -0.5 and no_rocks_2 > -0.6 then + if cave_rivers_4 > 0 and cave_rivers_4 < 0.07 then + entities[#entities + 1] = {name = "copper-ore", position=p, amount = math_abs(p.y) + 1} + end + end + end + if math_random(1,64) == 1 and no_rocks_2 > 0.7 then entities[#entities + 1] = {name = "crude-oil", position = p, amount = get_oil_amount(p)} end + if math_random(1,2048) == 1 then treasure[#treasure + 1] = p end + return + end + + --Chasms + local noise_cave_ponds = get_noise("cave_ponds", p, seed) + local small_caves = get_noise("small_caves", p, seed) + if noise_cave_ponds < 0.25 and noise_cave_ponds > -0.25 then + if small_caves > 0.55 then + tiles[#tiles + 1] = {name = "out-of-map", position = p} + return + end + if small_caves < -0.55 then + tiles[#tiles + 1] = {name = "out-of-map", position = p} + return + end + end + + tiles[#tiles + 1] = {name = "dirt-7", position = p} + if math_random(1,5) > 1 then entities[#entities + 1] = {name = rock_raffle[math_random(1, #rock_raffle)], position = p} end + if math_random(1,256) == 1 then treasure[#treasure + 1] = p end +end + local function process_level_6_position(p, seed, tiles, entities, markets, treasure) local large_caves = get_noise("large_caves", p, seed) - if large_caves > -0.03 and large_caves < 0.03 then + local cave_rivers = get_noise("cave_rivers", p, seed) + + if large_caves > -0.03 and large_caves < 0.03 and cave_rivers < 0.25 then tiles[#tiles + 1] = {name = "water-green", position = p} if math_random(1,128) == 1 then entities[#entities + 1] = {name="fish", position=p} end return end - - local cave_rivers = get_noise("cave_rivers", p, seed) + if cave_rivers > -0.05 and cave_rivers < 0.05 then if math_random(1,48) == 1 then entities[#entities + 1] = {name = "tree-0" .. math_random(1, 9), position=p} end - if math_random(1,768) == 1 then - wave_defense_set_worm_raffle(math.abs(p.y) * worm_level_modifier) - entities[#entities + 1] = {name = wave_defense_roll_worm_name(), position = p, force = "enemy"} + if math_random(1,128) == 1 then + Biters.wave_defense_set_worm_raffle(math_abs(p.y) * worm_level_modifier) + entities[#entities + 1] = {name = Biters.wave_defense_roll_worm_name(), position = p, force = "enemy"} end else tiles[#tiles + 1] = {name = "dirt-7", position = p} if math_random(1,8) > 1 then entities[#entities + 1] = {name = rock_raffle[math_random(1, #rock_raffle)], position = p} end - if math_random(1,320) == 1 then treasure[#treasure + 1] = p end - if math_random(1,1536) == 1 then entities[#entities + 1] = {name = "crude-oil", position = p, amount = math.abs(p.y) * 1000} end - if math_random(1,4096) == 1 then markets[#markets + 1] = p end + if math_random(1,512) == 1 then treasure[#treasure + 1] = p end + if math_random(1,4096) == 1 then entities[#entities + 1] = {name = "crude-oil", position = p, amount = get_oil_amount(p)} end + if math_random(1,8096) == 1 then markets[#markets + 1] = p end end end @@ -67,10 +280,10 @@ local function process_level_5_position(p, seed, tiles, entities, markets, treas local small_caves = get_noise("small_caves", p, seed) local noise_cave_ponds = get_noise("cave_ponds", p, seed) - if small_caves > -0.10 and small_caves < 0.10 then + if small_caves > -0.14 and small_caves < 0.14 then tiles[#tiles + 1] = {name = "dirt-7", position = p} - if math_random(1,512) == 1 then treasure[#treasure + 1] = p end - if math_random(1,2) > 1 then entities[#entities + 1] = {name = rock_raffle[math_random(1, #rock_raffle)], position = p} end + if math_random(1,768) == 1 then treasure[#treasure + 1] = p end + if math_random(1,3) > 1 then entities[#entities + 1] = {name = rock_raffle[math_random(1, #rock_raffle)], position = p} end return end @@ -78,17 +291,17 @@ local function process_level_5_position(p, seed, tiles, entities, markets, treas tiles[#tiles + 1] = {name = "deepwater-green", position = p} if math_random(1,128) == 1 then entities[#entities + 1] = {name="fish", position=p} end if math_random(1,128) == 1 then - wave_defense_set_worm_raffle(math.abs(p.y) * worm_level_modifier) - entities[#entities + 1] = {name = wave_defense_roll_worm_name(), position = p, force = "enemy"} + Biters.wave_defense_set_worm_raffle(math_abs(p.y) * worm_level_modifier) + entities[#entities + 1] = {name = Biters.wave_defense_roll_worm_name(), position = p, force = "enemy"} end return end if small_caves > -0.30 and small_caves < 0.30 then if noise_cave_ponds > 0.35 then - tiles[#tiles + 1] = {name = "dirt-" .. math.random(1, 4), position = p} - if math_random(1,128) == 1 then treasure[#treasure + 1] = p end - if math_random(1,256) == 1 then entities[#entities + 1] = {name = "crude-oil", position = p, amount = math.abs(p.y) * 500} end + tiles[#tiles + 1] = {name = "dirt-" .. math_random(1, 4), position = p} + if math_random(1,256) == 1 then treasure[#treasure + 1] = p end + if math_random(1,256) == 1 then entities[#entities + 1] = {name = "crude-oil", position = p, amount = get_oil_amount(p)} end return end if noise_cave_ponds > 0.25 then @@ -107,26 +320,26 @@ local function process_level_4_position(p, seed, tiles, entities, markets, treas local noise_cave_ponds = get_noise("cave_ponds", p, seed) local small_caves = get_noise("small_caves", p, seed) - if math.abs(noise_large_caves) > 0.7 then + if math_abs(noise_large_caves) > 0.7 then tiles[#tiles + 1] = {name = "water", position = p} if math_random(1,16) == 1 then entities[#entities + 1] = {name="fish", position=p} end return end - if math.abs(noise_large_caves) > 0.6 then + if math_abs(noise_large_caves) > 0.6 then if math_random(1,16) == 1 then entities[#entities + 1] = {name="tree-02", position=p} end if math_random(1,32) == 1 then markets[#markets + 1] = p end end - if math.abs(noise_large_caves) > 0.5 then + if math_abs(noise_large_caves) > 0.5 then tiles[#tiles + 1] = {name = "grass-2", position = p} - if math_random(1,620) == 1 then entities[#entities + 1] = {name = "crude-oil", position = p, amount = math.abs(p.y) * 500} end + if math_random(1,620) == 1 then entities[#entities + 1] = {name = "crude-oil", position = p, amount = get_oil_amount(p)} end if math_random(1,384) == 1 then - wave_defense_set_worm_raffle(math.abs(p.y) * worm_level_modifier) - entities[#entities + 1] = {name = wave_defense_roll_worm_name(), position = p, force = "enemy"} + Biters.wave_defense_set_worm_raffle(math_abs(p.y) * worm_level_modifier) + entities[#entities + 1] = {name = Biters.wave_defense_roll_worm_name(), position = p, force = "enemy"} end if math_random(1, 1024) == 1 then treasure[#treasure + 1] = p end return end - if math.abs(noise_large_caves) > 0.475 then + if math_abs(noise_large_caves) > 0.475 then tiles[#tiles + 1] = {name = "dirt-7", position = p} if math_random(1,3) > 1 then entities[#entities + 1] = {name = rock_raffle[math_random(1, #rock_raffle)], position = p} end if math_random(1,2048) == 1 then treasure[#treasure + 1] = p end @@ -157,7 +370,7 @@ local function process_level_4_position(p, seed, tiles, entities, markets, treas --Main Rock Terrain local no_rocks_2 = get_noise("no_rocks_2", p, seed + 75000) if no_rocks_2 > 0.80 or no_rocks_2 < -0.80 then - tiles[#tiles + 1] = {name = "dirt-" .. math.floor(no_rocks_2 * 8) % 2 + 5, position = p} + tiles[#tiles + 1] = {name = "dirt-" .. math_floor(no_rocks_2 * 8) % 2 + 5, position = p} if math_random(1,512) == 1 then treasure[#treasure + 1] = p end return end @@ -183,7 +396,7 @@ local function process_level_3_position(p, seed, tiles, entities, markets, treas tiles[#tiles + 1] = {name = "dirt-7", position = p} entities[#entities + 1] = {name = rock_raffle[math_random(1, #rock_raffle)], position = p} else - tiles[#tiles + 1] = {name = "grass-" .. math.floor(noise_cave_ponds * 32) % 3 + 1, position = p} + tiles[#tiles + 1] = {name = "grass-" .. math_floor(noise_cave_ponds * 32) % 3 + 1, position = p} if math_random(1,32) == 1 then markets[#markets + 1] = p end if math_random(1,16) == 1 then entities[#entities + 1] = {name = "tree-0" .. math_random(1, 9), position=p} end end @@ -237,11 +450,11 @@ local function process_level_3_position(p, seed, tiles, entities, markets, treas --Worm oil Zones if no_rocks < 0.15 and no_rocks > -0.15 then if small_caves > 0.35 then - tiles[#tiles + 1] = {name = "dirt-" .. math.floor(noise_cave_ponds * 32) % 7 + 1, position = p} - if math_random(1,320) == 1 then entities[#entities + 1] = {name = "crude-oil", position = p, amount = math.abs(p.y) * 500} end + tiles[#tiles + 1] = {name = "dirt-" .. math_floor(noise_cave_ponds * 32) % 7 + 1, position = p} + if math_random(1,320) == 1 then entities[#entities + 1] = {name = "crude-oil", position = p, amount = get_oil_amount(p)} end if math_random(1,50) == 1 then - wave_defense_set_worm_raffle(math.abs(p.y) * worm_level_modifier) - entities[#entities + 1] = {name = wave_defense_roll_worm_name(), position = p, force = "enemy"} + Biters.wave_defense_set_worm_raffle(math_abs(p.y) * worm_level_modifier) + entities[#entities + 1] = {name = Biters.wave_defense_roll_worm_name(), position = p, force = "enemy"} end if math_random(1,512) == 1 then treasure[#treasure + 1] = p end if math_random(1,64) == 1 then entities[#entities + 1] = {name = "dead-tree-desert", position=p} end @@ -252,7 +465,7 @@ local function process_level_3_position(p, seed, tiles, entities, markets, treas --Main Rock Terrain local no_rocks_2 = get_noise("no_rocks_2", p, seed + 75000) if no_rocks_2 > 0.80 or no_rocks_2 < -0.80 then - tiles[#tiles + 1] = {name = "dirt-" .. math.floor(no_rocks_2 * 8) % 2 + 5, position = p} + tiles[#tiles + 1] = {name = "dirt-" .. math_floor(no_rocks_2 * 8) % 2 + 5, position = p} if math_random(1,512) == 1 then treasure[#treasure + 1] = p end return end @@ -275,12 +488,12 @@ local function process_level_2_position(p, seed, tiles, entities, markets, treas local noise_cave_ponds = get_noise("cave_ponds", p, seed) --Chasms - if noise_cave_ponds < 0.13 and noise_cave_ponds > -0.13 then - if small_caves > 0.35 then + if noise_cave_ponds < 0.15 and noise_cave_ponds > -0.15 then + if small_caves > 0.32 then tiles[#tiles + 1] = {name = "out-of-map", position = p} return end - if small_caves < -0.35 then + if small_caves < -0.32 then tiles[#tiles + 1] = {name = "out-of-map", position = p} return end @@ -310,7 +523,7 @@ local function process_level_2_position(p, seed, tiles, entities, markets, treas --Market Spots if noise_cave_ponds < -0.80 then - tiles[#tiles + 1] = {name = "grass-" .. math.floor(noise_cave_ponds * 32) % 3 + 1, position = p} + tiles[#tiles + 1] = {name = "grass-" .. math_floor(noise_cave_ponds * 32) % 3 + 1, position = p} if math_random(1,32) == 1 then markets[#markets + 1] = p end if math_random(1,16) == 1 then entities[#entities + 1] = {name = "tree-0" .. math_random(1, 9), position=p} end return @@ -320,11 +533,11 @@ local function process_level_2_position(p, seed, tiles, entities, markets, treas --Worm oil Zones if no_rocks < 0.15 and no_rocks > -0.15 then if small_caves > 0.35 then - tiles[#tiles + 1] = {name = "dirt-" .. math.floor(noise_cave_ponds * 32) % 7 + 1, position = p} - if math_random(1,450) == 1 then entities[#entities + 1] = {name = "crude-oil", position = p, amount = math.abs(p.y) * 500} end + tiles[#tiles + 1] = {name = "dirt-" .. math_floor(noise_cave_ponds * 32) % 7 + 1, position = p} + if math_random(1,450) == 1 then entities[#entities + 1] = {name = "crude-oil", position = p, amount = get_oil_amount(p)} end if math_random(1,64) == 1 then - wave_defense_set_worm_raffle(math.abs(p.y) * worm_level_modifier) - entities[#entities + 1] = {name = wave_defense_roll_worm_name(), position = p, force = "enemy"} + Biters.wave_defense_set_worm_raffle(math_abs(p.y) * worm_level_modifier) + entities[#entities + 1] = {name = Biters.wave_defense_roll_worm_name(), position = p, force = "enemy"} end if math_random(1,1024) == 1 then treasure[#treasure + 1] = p end if math_random(1,64) == 1 then entities[#entities + 1] = {name = "dead-tree-desert", position=p} end @@ -336,7 +549,7 @@ local function process_level_2_position(p, seed, tiles, entities, markets, treas --Main Rock Terrain local no_rocks_2 = get_noise("no_rocks_2", p, seed + 75000) if no_rocks_2 > 0.80 or no_rocks_2 < -0.80 then - tiles[#tiles + 1] = {name = "dirt-" .. math.floor(no_rocks_2 * 8) % 2 + 5, position = p} + tiles[#tiles + 1] = {name = "dirt-" .. math_floor(no_rocks_2 * 8) % 2 + 5, position = p} if math_random(1,512) == 1 then treasure[#treasure + 1] = p end return end @@ -392,7 +605,7 @@ local function process_level_1_position(p, seed, tiles, entities, markets, treas --Market Spots if noise_cave_ponds < -0.75 then - tiles[#tiles + 1] = {name = "grass-" .. math.floor(noise_cave_ponds * 32) % 3 + 1, position = p} + tiles[#tiles + 1] = {name = "grass-" .. math_floor(noise_cave_ponds * 32) % 3 + 1, position = p} if math_random(1,32) == 1 then markets[#markets + 1] = p end if math_random(1,32) == 1 then entities[#entities + 1] = {name = "tree-0" .. math_random(1, 9), position=p} end return @@ -403,11 +616,11 @@ local function process_level_1_position(p, seed, tiles, entities, markets, treas if p.y < -64 + noise_cave_ponds * 10 then if no_rocks < 0.08 and no_rocks > -0.08 then if small_caves > 0.35 then - tiles[#tiles + 1] = {name = "dirt-" .. math.floor(noise_cave_ponds * 32) % 7 + 1, position = p} - if math_random(1,450) == 1 then entities[#entities + 1] = {name = "crude-oil", position = p, amount = math.abs(p.y) * 500} end + tiles[#tiles + 1] = {name = "dirt-" .. math_floor(noise_cave_ponds * 32) % 7 + 1, position = p} + if math_random(1,450) == 1 then entities[#entities + 1] = {name = "crude-oil", position = p, amount = get_oil_amount(p)} end if math_random(1,96) == 1 then - wave_defense_set_worm_raffle(math.abs(p.y) * worm_level_modifier) - entities[#entities + 1] = {name = wave_defense_roll_worm_name(), position = p, force = "enemy"} + Biters.wave_defense_set_worm_raffle(math_abs(p.y) * worm_level_modifier) + entities[#entities + 1] = {name = Biters.wave_defense_roll_worm_name(), position = p, force = "enemy"} end if math_random(1,1024) == 1 then treasure[#treasure + 1] = p end if math_random(1,64) == 1 then entities[#entities + 1] = {name = "dead-tree-desert", position=p} end @@ -419,7 +632,7 @@ local function process_level_1_position(p, seed, tiles, entities, markets, treas --Main Rock Terrain local no_rocks_2 = get_noise("no_rocks_2", p, seed + 75000) if no_rocks_2 > 0.70 or no_rocks_2 < -0.70 then - tiles[#tiles + 1] = {name = "dirt-" .. math.floor(no_rocks_2 * 8) % 2 + 5, position = p} + tiles[#tiles + 1] = {name = "dirt-" .. math_floor(no_rocks_2 * 8) % 2 + 5, position = p} if math_random(1,32) == 1 then entities[#entities + 1] = {name = "dead-tree-desert", position=p} end if math_random(1,512) == 1 then treasure[#treasure + 1] = p end return @@ -437,6 +650,22 @@ local levels = { process_level_4_position, process_level_5_position, process_level_6_position, + process_level_7_position, + process_level_8_position, + process_level_9_position, + process_level_10_position, +} + +local entity_functions = { + ["turret"] = function(surface, entity) surface.create_entity(entity) end, + ["simple-entity"] = function(surface, entity) surface.create_entity(entity) end, + ["ammo-turret"] = function(surface, entity) + local e = surface.create_entity(entity) + e.insert({name = "uranium-rounds-magazine", count = math_random(16, 64)}) + end, + ["container"] = function(surface, entity) + Treasure(surface, entity.position, entity.name) + end, } local function rock_chunk(surface, left_top) @@ -445,8 +674,8 @@ local function rock_chunk(surface, left_top) local markets = {} local treasure = {} local seed = surface.map_gen_settings.seed - local process_level = levels[math.floor(math.abs(left_top.y) / level_depth) + 1] - if not process_level then process_level = process_level_6_position end + local process_level = levels[math_floor(math_abs(left_top.y) / level_depth) + 1] + if not process_level then process_level = levels[#levels] end for y = 0, 31, 1 do for x = 0, 31, 1 do local p = {x = left_top.x + x, y = left_top.y + y} @@ -458,19 +687,23 @@ local function rock_chunk(surface, left_top) if #markets > 0 then local position = markets[math_random(1, #markets)] if surface.count_entities_filtered{area = {{position.x - 96, position.y - 96}, {position.x + 96, position.y + 96}}, name = "market", limit = 1} == 0 then - local market = mountain_market(surface, position, math.abs(position.y) * 0.004) + local market = Market.mountain_market(surface, position, math_abs(position.y) * 0.004) market.destructible = false end end - for _, p in pairs(treasure) do treasure_chest(surface, p) end + for _, p in pairs(treasure) do + local name = "wooden-chest" + if math_random(1, 6) == 1 then name = "iron-chest" end + Treasure(surface, p, name) + end - for _, e in pairs(entities) do - if game.entity_prototypes[e.name].type == "simple-entity" or game.entity_prototypes[e.name].type == "turret" then - surface.create_entity(e) + for _, entity in pairs(entities) do + if entity_functions[game.entity_prototypes[entity.name].type] then + entity_functions[game.entity_prototypes[entity.name].type](surface, entity) else - if surface.can_place_entity(e) then - surface.create_entity(e) + if surface.can_place_entity(entity) then + surface.create_entity(entity) end end end @@ -569,7 +802,7 @@ local function wall(surface, left_top, seed) local small_caves = get_noise("small_caves", p, seed) local cave_ponds = get_noise("cave_rivers", p, seed + 100000) if y > 9 + cave_ponds * 6 and y < 23 + small_caves * 6 then - if small_caves > 0.10 or cave_ponds > 0.10 then + if small_caves > 0.05 or cave_ponds > 0.05 then --surface.set_tiles({{name = "water-shallow", position = p}}) surface.set_tiles({{name = "deepwater", position = p}}) if math_random(1,48) == 1 then surface.create_entity({name = "fish", position = p}) end @@ -583,8 +816,12 @@ local function wall(surface, left_top, seed) surface.set_tiles({{name = "dirt-7", position = p}}) if surface.can_place_entity({name = "stone-wall", position = p, force = "enemy"}) then - if math_random(1,512) == 1 and y > 3 and y < 28 then - treasure_chest(surface, p) + if math_random(1,512) == 1 and y > 3 and y < 28 then + if math_random(1, 2) == 1 then + Treasure(surface, p, "wooden-chest") + else + Treasure(surface, p, "iron-chest") + end else if y < 5 or y > 26 then @@ -606,18 +843,18 @@ local function wall(surface, left_top, seed) if math_random(1, 16) == 1 then if surface.can_place_entity({name = "small-worm-turret", position = p, force = "enemy"}) then - wave_defense_set_worm_raffle(math.abs(p.y) * worm_level_modifier) - surface.create_entity({name = wave_defense_roll_worm_name(), position = p, force = "enemy"}) + Biters.wave_defense_set_worm_raffle(math_abs(p.y) * worm_level_modifier) + surface.create_entity({name = Biters.wave_defense_roll_worm_name(), position = p, force = "enemy"}) end end if math_random(1, 32) == 1 then if surface.can_place_entity({name = "gun-turret", position = p, force = "enemy"}) then local e = surface.create_entity({name = "gun-turret", position = p, force = "enemy"}) - if math.abs(p.y) < level_depth * 2.5 then - e.insert({name = "piercing-rounds-magazine", count = math.random(64, 128)}) + if math_abs(p.y) < level_depth * 2.5 then + e.insert({name = "piercing-rounds-magazine", count = math_random(64, 128)}) else - e.insert({name = "uranium-rounds-magazine", count = math.random(64, 128)}) + e.insert({name = "uranium-rounds-magazine", count = math_random(64, 128)}) end end end @@ -632,7 +869,7 @@ local function process_chunk(surface, left_top) if left_top.x >= 768 then return end if left_top.x < -768 then return end - if left_top.y % level_depth == 0 and left_top.y < 0 and left_top.y > level_depth * -6 then wall(surface, left_top, surface.map_gen_settings.seed) return end + if left_top.y % level_depth == 0 and left_top.y < 0 and left_top.y > level_depth * -10 then wall(surface, left_top, surface.map_gen_settings.seed) return end if left_top.y >= 0 then replace_water(surface, left_top) end if left_top.y > 32 then game.forces.player.chart(surface, {{left_top.x, left_top.y},{left_top.x + 31, left_top.y + 31}}) end @@ -671,5 +908,7 @@ local function on_chunk_generated(event) end local event = require 'utils.event' -event.on_nth_tick(4, process_chunk_queue) -event.add(defines.events.on_chunk_generated, on_chunk_generated) \ No newline at end of file +--event.on_nth_tick(4, process_chunk_queue) +event.add(defines.events.on_chunk_generated, on_chunk_generated) + +return level_depth \ No newline at end of file diff --git a/maps/mountain_fortress_v2/treasure.lua b/maps/mountain_fortress_v2/treasure.lua index e87ecd75..fe9dfec9 100644 --- a/maps/mountain_fortress_v2/treasure.lua +++ b/maps/mountain_fortress_v2/treasure.lua @@ -1,146 +1,161 @@ local math_random = math.random -function treasure_chest(surface, position) +local Public = {} + +function Public.treasure_chest(surface, position, container_name) local chest_raffle = {} local chest_loot = { - {{name = "submachine-gun", count = math_random(1,3)}, weight = 3, evo_min = 0.0, evo_max = 0.1}, - {{name = "slowdown-capsule", count = math_random(16,32)}, weight = 1, evo_min = 0.3, evo_max = 0.7}, - {{name = "poison-capsule", count = math_random(8,16)}, weight = 3, evo_min = 0.3, evo_max = 1}, - {{name = "uranium-cannon-shell", count = math_random(16,32)}, weight = 5, evo_min = 0.6, evo_max = 1}, - {{name = "cannon-shell", count = math_random(16,32)}, weight = 5, evo_min = 0.4, evo_max = 0.7}, - {{name = "explosive-uranium-cannon-shell", count = math_random(16,32)}, weight = 5, evo_min = 0.6, evo_max = 1}, - {{name = "explosive-cannon-shell", count = math_random(16,32)}, weight = 5, evo_min = 0.4, evo_max = 0.8}, - {{name = "shotgun", count = 1}, weight = 2, evo_min = 0.0, evo_max = 0.2}, - {{name = "shotgun-shell", count = math_random(16,32)}, weight = 5, evo_min = 0.0, evo_max = 0.2}, - {{name = "combat-shotgun", count = 1}, weight = 3, evo_min = 0.3, evo_max = 0.8}, - {{name = "piercing-shotgun-shell", count = math_random(16,32)}, weight = 10, evo_min = 0.2, evo_max = 1}, - {{name = "flamethrower", count = 1}, weight = 3, evo_min = 0.3, evo_max = 0.6}, - {{name = "flamethrower-ammo", count = math_random(16,32)}, weight = 5, evo_min = 0.3, evo_max = 1}, - {{name = "rocket-launcher", count = 1}, weight = 3, evo_min = 0.2, evo_max = 0.6}, - {{name = "rocket", count = math_random(16,32)}, weight = 5, evo_min = 0.2, evo_max = 0.7}, - {{name = "explosive-rocket", count = math_random(16,32)}, weight = 5, evo_min = 0.3, evo_max = 1}, - {{name = "land-mine", count = math_random(16,32)}, weight = 5, evo_min = 0.2, evo_max = 0.7}, - {{name = "grenade", count = math_random(16,32)}, weight = 5, evo_min = 0.0, evo_max = 0.5}, - {{name = "cluster-grenade", count = math_random(8,16)}, weight = 5, evo_min = 0.4, evo_max = 1}, - {{name = "firearm-magazine", count = math_random(32,128)}, weight = 5, evo_min = 0, evo_max = 0.3}, - {{name = "piercing-rounds-magazine", count = math_random(32,128)}, weight = 5, evo_min = 0.1, evo_max = 0.8}, - {{name = "uranium-rounds-magazine", count = math_random(32,128)}, weight = 5, evo_min = 0.5, evo_max = 1}, - {{name = "railgun", count = 1}, weight = 1, evo_min = 0.2, evo_max = 1}, - {{name = "railgun-dart", count = math_random(16,32)}, weight = 3, evo_min = 0.2, evo_max = 0.7}, - {{name = "defender-capsule", count = math_random(8,16)}, weight = 2, evo_min = 0.0, evo_max = 0.7}, - {{name = "distractor-capsule", count = math_random(8,16)}, weight = 2, evo_min = 0.2, evo_max = 1}, - {{name = "destroyer-capsule", count = math_random(8,16)}, weight = 2, evo_min = 0.3, evo_max = 1}, - {{name = "atomic-bomb", count = 1}, weight = 1, evo_min = 0.8, evo_max = 1}, - {{name = "light-armor", count = 1}, weight = 3, evo_min = 0, evo_max = 0.1}, - {{name = "heavy-armor", count = 1}, weight = 3, evo_min = 0.1, evo_max = 0.3}, - {{name = "modular-armor", count = 1}, weight = 3, evo_min = 0.2, evo_max = 0.6}, - {{name = "power-armor", count = 1}, weight = 2, evo_min = 0.4, evo_max = 1}, - {{name = "power-armor-mk2", count = 1}, weight = 1, evo_min = 0.9, evo_max = 1}, - {{name = "battery-equipment", count = 1}, weight = 2, evo_min = 0.3, evo_max = 0.7}, - {{name = "battery-mk2-equipment", count = 1}, weight = 2, evo_min = 0.7, evo_max = 1}, - {{name = "belt-immunity-equipment", count = 1}, weight = 1, evo_min = 0.5, evo_max = 1}, - {{name = "solar-panel-equipment", count = math_random(1,4)}, weight = 5, evo_min = 0.4, evo_max = 0.8}, - {{name = "discharge-defense-equipment", count = 1}, weight = 1, evo_min = 0.5, evo_max = 1}, - {{name = "energy-shield-equipment", count = math_random(1,2)}, weight = 2, evo_min = 0.3, evo_max = 0.8}, - {{name = "energy-shield-mk2-equipment", count = 1}, weight = 2, evo_min = 0.8, evo_max = 1}, - {{name = "exoskeleton-equipment", count = 1}, weight = 1, evo_min = 0.3, evo_max = 1}, - {{name = "fusion-reactor-equipment", count = 1}, weight = 1, evo_min = 0.8, evo_max = 1}, - {{name = "night-vision-equipment", count = 1}, weight = 1, evo_min = 0.3, evo_max = 0.8}, - {{name = "personal-laser-defense-equipment", count = 1}, weight = 1, evo_min = 0.7, evo_max = 1}, + {{name = "submachine-gun", count = math_random(1,3)}, weight = 3, d_min = 0.0, d_max = 0.1}, + {{name = "slowdown-capsule", count = math_random(16,32)}, weight = 1, d_min = 0.3, d_max = 0.7}, + {{name = "poison-capsule", count = math_random(8,16)}, weight = 3, d_min = 0.3, d_max = 1}, + {{name = "uranium-cannon-shell", count = math_random(16,32)}, weight = 5, d_min = 0.6, d_max = 1}, + {{name = "cannon-shell", count = math_random(16,32)}, weight = 5, d_min = 0.4, d_max = 0.7}, + {{name = "explosive-uranium-cannon-shell", count = math_random(16,32)}, weight = 5, d_min = 0.6, d_max = 1}, + {{name = "explosive-cannon-shell", count = math_random(16,32)}, weight = 5, d_min = 0.4, d_max = 0.8}, + {{name = "shotgun", count = 1}, weight = 2, d_min = 0.0, d_max = 0.2}, + {{name = "shotgun-shell", count = math_random(16,32)}, weight = 5, d_min = 0.0, d_max = 0.2}, + {{name = "combat-shotgun", count = 1}, weight = 3, d_min = 0.3, d_max = 0.8}, + {{name = "piercing-shotgun-shell", count = math_random(16,32)}, weight = 10, d_min = 0.2, d_max = 1}, + {{name = "flamethrower", count = 1}, weight = 3, d_min = 0.3, d_max = 0.6}, + {{name = "flamethrower-ammo", count = math_random(16,32)}, weight = 5, d_min = 0.3, d_max = 1}, + {{name = "rocket-launcher", count = 1}, weight = 3, d_min = 0.2, d_max = 0.6}, + {{name = "rocket", count = math_random(16,32)}, weight = 5, d_min = 0.2, d_max = 0.7}, + {{name = "explosive-rocket", count = math_random(16,32)}, weight = 5, d_min = 0.3, d_max = 1}, + {{name = "land-mine", count = math_random(16,32)}, weight = 5, d_min = 0.2, d_max = 0.7}, + {{name = "grenade", count = math_random(16,32)}, weight = 5, d_min = 0.0, d_max = 0.5}, + {{name = "cluster-grenade", count = math_random(8,16)}, weight = 5, d_min = 0.4, d_max = 1}, + {{name = "firearm-magazine", count = math_random(32,128)}, weight = 5, d_min = 0, d_max = 0.3}, + {{name = "piercing-rounds-magazine", count = math_random(32,128)}, weight = 5, d_min = 0.1, d_max = 0.8}, + {{name = "uranium-rounds-magazine", count = math_random(32,128)}, weight = 5, d_min = 0.5, d_max = 1}, + {{name = "railgun", count = 1}, weight = 1, d_min = 0.2, d_max = 1}, + {{name = "railgun-dart", count = math_random(16,32)}, weight = 3, d_min = 0.2, d_max = 0.7}, + {{name = "defender-capsule", count = math_random(8,16)}, weight = 2, d_min = 0.0, d_max = 0.7}, + {{name = "distractor-capsule", count = math_random(8,16)}, weight = 2, d_min = 0.2, d_max = 1}, + {{name = "destroyer-capsule", count = math_random(8,16)}, weight = 2, d_min = 0.3, d_max = 1}, + {{name = "atomic-bomb", count = 1}, weight = 1, d_min = 0.8, d_max = 1}, + {{name = "light-armor", count = 1}, weight = 3, d_min = 0, d_max = 0.1}, + {{name = "heavy-armor", count = 1}, weight = 3, d_min = 0.1, d_max = 0.3}, + {{name = "modular-armor", count = 1}, weight = 2, d_min = 0.2, d_max = 0.6}, + {{name = "power-armor", count = 1}, weight = 1, d_min = 0.4, d_max = 1}, + --{{name = "power-armor-mk2", count = 1}, weight = 1, d_min = 0.9, d_max = 1}, + {{name = "battery-equipment", count = 1}, weight = 2, d_min = 0.3, d_max = 0.7}, + --{{name = "battery-mk2-equipment", count = 1}, weight = 2, d_min = 0.7, d_max = 1}, + {{name = "belt-immunity-equipment", count = 1}, weight = 1, d_min = 0.5, d_max = 1}, + {{name = "solar-panel-equipment", count = math_random(1,4)}, weight = 5, d_min = 0.4, d_max = 0.8}, + {{name = "discharge-defense-equipment", count = 1}, weight = 1, d_min = 0.5, d_max = 1}, + {{name = "energy-shield-equipment", count = math_random(1,2)}, weight = 2, d_min = 0.3, d_max = 0.8}, + --{{name = "energy-shield-mk2-equipment", count = 1}, weight = 2, d_min = 0.8, d_max = 1}, + {{name = "exoskeleton-equipment", count = 1}, weight = 1, d_min = 0.3, d_max = 1}, + --{{name = "fusion-reactor-equipment", count = 1}, weight = 1, d_min = 0.8, d_max = 1}, + {{name = "night-vision-equipment", count = 1}, weight = 1, d_min = 0.3, d_max = 0.8}, + {{name = "personal-laser-defense-equipment", count = 1}, weight = 1, d_min = 0.7, d_max = 1}, - {{name = "personal-roboport-equipment", count = math_random(1,2)}, weight = 3, evo_min = 0.4, evo_max = 1}, - {{name = "personal-roboport-mk2-equipment", count = 1}, weight = 1, evo_min = 0.9, evo_max = 1}, - {{name = "logistic-robot", count = math_random(5,25)}, weight = 2, evo_min = 0.5, evo_max = 1}, - {{name = "construction-robot", count = math_random(5,25)}, weight = 5, evo_min = 0.4, evo_max = 1}, + {{name = "personal-roboport-equipment", count = math_random(1,2)}, weight = 3, d_min = 0.4, d_max = 1}, + --{{name = "personal-roboport-mk2-equipment", count = 1}, weight = 1, d_min = 0.9, d_max = 1}, + {{name = "logistic-robot", count = math_random(5,25)}, weight = 2, d_min = 0.5, d_max = 1}, + {{name = "construction-robot", count = math_random(5,25)}, weight = 5, d_min = 0.4, d_max = 1}, - {{name = "iron-gear-wheel", count = math_random(80,100)}, weight = 3, evo_min = 0.0, evo_max = 0.3}, - {{name = "copper-cable", count = math_random(100,200)}, weight = 3, evo_min = 0.0, evo_max = 0.3}, - {{name = "engine-unit", count = math_random(16,32)}, weight = 2, evo_min = 0.1, evo_max = 0.5}, - {{name = "electric-engine-unit", count = math_random(16,32)}, weight = 2, evo_min = 0.4, evo_max = 0.8}, - {{name = "battery", count = math_random(50,150)}, weight = 2, evo_min = 0.3, evo_max = 0.8}, - {{name = "advanced-circuit", count = math_random(50,150)}, weight = 3, evo_min = 0.3, evo_max = 1}, - {{name = "electronic-circuit", count = math_random(50,150)}, weight = 4, evo_min = 0.0, evo_max = 0.4}, - {{name = "processing-unit", count = math_random(50,150)}, weight = 3, evo_min = 0.7, evo_max = 1}, - {{name = "explosives", count = math_random(40,100)}, weight = 20, evo_min = 0.0, evo_max = 1}, - {{name = "lubricant-barrel", count = math_random(4,10)}, weight = 1, evo_min = 0.3, evo_max = 0.5}, - {{name = "rocket-fuel", count = math_random(4,10)}, weight = 2, evo_min = 0.3, evo_max = 0.7}, - --{{name = "computer", count = 1}, weight = 2, evo_min = 0, evo_max = 1}, - {{name = "steel-plate", count = math_random(25,75)}, weight = 2, evo_min = 0.1, evo_max = 0.3}, - {{name = "nuclear-fuel", count = 1}, weight = 2, evo_min = 0.7, evo_max = 1}, + {{name = "iron-gear-wheel", count = math_random(80,100)}, weight = 3, d_min = 0.0, d_max = 0.3}, + {{name = "copper-cable", count = math_random(100,200)}, weight = 3, d_min = 0.0, d_max = 0.3}, + {{name = "engine-unit", count = math_random(16,32)}, weight = 2, d_min = 0.1, d_max = 0.5}, + {{name = "electric-engine-unit", count = math_random(16,32)}, weight = 2, d_min = 0.4, d_max = 0.8}, + {{name = "battery", count = math_random(50,150)}, weight = 2, d_min = 0.3, d_max = 0.8}, + {{name = "advanced-circuit", count = math_random(50,150)}, weight = 3, d_min = 0.3, d_max = 1}, + {{name = "electronic-circuit", count = math_random(50,150)}, weight = 4, d_min = 0.0, d_max = 0.4}, + {{name = "processing-unit", count = math_random(50,150)}, weight = 3, d_min = 0.7, d_max = 1}, + {{name = "explosives", count = math_random(40,100)}, weight = 20, d_min = 0.0, d_max = 1}, + {{name = "lubricant-barrel", count = math_random(4,10)}, weight = 1, d_min = 0.3, d_max = 0.5}, + {{name = "rocket-fuel", count = math_random(4,10)}, weight = 2, d_min = 0.3, d_max = 0.7}, + --{{name = "computer", count = 1}, weight = 2, d_min = 0, d_max = 1}, + + {{name = "effectivity-module", count = math_random(1,4)}, weight = 2, d_min = 0.1, d_max = 1}, + {{name = "productivity-module", count = math_random(1,4)}, weight = 2, d_min = 0.1, d_max = 1}, + {{name = "speed-module", count = math_random(1,4)}, weight = 2, d_min = 0.1, d_max = 1}, + + {{name = "automation-science-pack", count = math_random(16,64)}, weight = 3, d_min = 0.0, d_max = 0.2}, + {{name = "logistic-science-pack", count = math_random(16,64)}, weight = 3, d_min = 0.1, d_max = 0.5}, + {{name = "military-science-pack", count = math_random(16,64)}, weight = 3, d_min = 0.2, d_max = 1}, + {{name = "chemical-science-pack", count = math_random(16,64)}, weight = 3, d_min = 0.3, d_max = 1}, + {{name = "production-science-pack", count = math_random(16,64)}, weight = 3, d_min = 0.4, d_max = 1}, + {{name = "utility-science-pack", count = math_random(16,64)}, weight = 3, d_min = 0.5, d_max = 1}, + {{name = "space-science-pack", count = math_random(16,64)}, weight = 3, d_min = 0.9, d_max = 1}, + + {{name = "steel-plate", count = math_random(25,75)}, weight = 2, d_min = 0.1, d_max = 0.3}, + {{name = "nuclear-fuel", count = 1}, weight = 2, d_min = 0.7, d_max = 1}, - {{name = "burner-inserter", count = math_random(8,16)}, weight = 3, evo_min = 0.0, evo_max = 0.1}, - {{name = "inserter", count = math_random(8,16)}, weight = 3, evo_min = 0.0, evo_max = 0.4}, - {{name = "long-handed-inserter", count = math_random(8,16)}, weight = 3, evo_min = 0.0, evo_max = 0.4}, - {{name = "fast-inserter", count = math_random(8,16)}, weight = 3, evo_min = 0.1, evo_max = 1}, - {{name = "filter-inserter", count = math_random(8,16)}, weight = 1, evo_min = 0.2, evo_max = 1}, - {{name = "stack-filter-inserter", count = math_random(4,8)}, weight = 1, evo_min = 0.4, evo_max = 1}, - {{name = "stack-inserter", count = math_random(4,8)}, weight = 3, evo_min = 0.3, evo_max = 1}, - {{name = "small-electric-pole", count = math_random(16,24)}, weight = 3, evo_min = 0.0, evo_max = 0.3}, - {{name = "medium-electric-pole", count = math_random(8,16)}, weight = 3, evo_min = 0.2, evo_max = 1}, - {{name = "big-electric-pole", count = math_random(4,8)}, weight = 3, evo_min = 0.3, evo_max = 1}, - {{name = "substation", count = math_random(2,4)}, weight = 3, evo_min = 0.5, evo_max = 1}, - {{name = "wooden-chest", count = math_random(8,16)}, weight = 3, evo_min = 0.0, evo_max = 0.2}, - {{name = "iron-chest", count = math_random(8,16)}, weight = 3, evo_min = 0.1, evo_max = 0.4}, - {{name = "steel-chest", count = math_random(8,16)}, weight = 3, evo_min = 0.3, evo_max = 1}, - {{name = "small-lamp", count = math_random(16,32)}, weight = 3, evo_min = 0.1, evo_max = 0.3}, - {{name = "rail", count = math_random(25,75)}, weight = 3, evo_min = 0.1, evo_max = 0.6}, - {{name = "assembling-machine-1", count = math_random(2,4)}, weight = 3, evo_min = 0.0, evo_max = 0.3}, - {{name = "assembling-machine-2", count = math_random(2,4)}, weight = 3, evo_min = 0.2, evo_max = 0.8}, - {{name = "assembling-machine-3", count = math_random(2,4)}, weight = 3, evo_min = 0.5, evo_max = 1}, - {{name = "accumulator", count = math_random(4,8)}, weight = 3, evo_min = 0.4, evo_max = 1}, - {{name = "offshore-pump", count = math_random(1,3)}, weight = 2, evo_min = 0.0, evo_max = 0.2}, - {{name = "beacon", count = 1}, weight = 3, evo_min = 0.7, evo_max = 1}, - {{name = "boiler", count = math_random(3,6)}, weight = 3, evo_min = 0.0, evo_max = 0.3}, - {{name = "steam-engine", count = math_random(2,4)}, weight = 3, evo_min = 0.0, evo_max = 0.5}, - {{name = "steam-turbine", count = math_random(1,2)}, weight = 2, evo_min = 0.6, evo_max = 1}, - {{name = "nuclear-reactor", count = 1}, weight = 1, evo_min = 0.7, evo_max = 1}, - {{name = "centrifuge", count = 1}, weight = 1, evo_min = 0.6, evo_max = 1}, - {{name = "heat-pipe", count = math_random(4,8)}, weight = 2, evo_min = 0.5, evo_max = 1}, - {{name = "heat-exchanger", count = math_random(2,4)}, weight = 2, evo_min = 0.5, evo_max = 1}, - {{name = "arithmetic-combinator", count = math_random(4,8)}, weight = 2, evo_min = 0.1, evo_max = 1}, - {{name = "constant-combinator", count = math_random(4,8)}, weight = 2, evo_min = 0.1, evo_max = 1}, - {{name = "decider-combinator", count = math_random(4,8)}, weight = 2, evo_min = 0.1, evo_max = 1}, - {{name = "power-switch", count = 1}, weight = 2, evo_min = 0.1, evo_max = 1}, - {{name = "programmable-speaker", count = math_random(2,4)}, weight = 1, evo_min = 0.1, evo_max = 1}, - {{name = "green-wire", count = math_random(50,99)}, weight = 4, evo_min = 0.1, evo_max = 1}, - {{name = "red-wire", count = math_random(50,99)}, weight = 4, evo_min = 0.1, evo_max = 1}, - {{name = "chemical-plant", count = math_random(1,3)}, weight = 3, evo_min = 0.3, evo_max = 1}, - {{name = "burner-mining-drill", count = math_random(2,4)}, weight = 3, evo_min = 0.0, evo_max = 0.2}, - {{name = "electric-mining-drill", count = math_random(2,4)}, weight = 3, evo_min = 0.2, evo_max = 1}, - {{name = "express-transport-belt", count = math_random(25,75)}, weight = 3, evo_min = 0.5, evo_max = 1}, - {{name = "express-underground-belt", count = math_random(4,8)}, weight = 3, evo_min = 0.5, evo_max = 1}, - {{name = "express-splitter", count = math_random(1,4)}, weight = 3, evo_min = 0.5, evo_max = 1}, - {{name = "fast-transport-belt", count = math_random(25,75)}, weight = 3, evo_min = 0.2, evo_max = 0.7}, - {{name = "fast-underground-belt", count = math_random(4,8)}, weight = 3, evo_min = 0.2, evo_max = 0.7}, - {{name = "fast-splitter", count = math_random(1,4)}, weight = 3, evo_min = 0.2, evo_max = 0.3}, - {{name = "transport-belt", count = math_random(25,75)}, weight = 3, evo_min = 0, evo_max = 0.3}, - {{name = "underground-belt", count = math_random(4,8)}, weight = 3, evo_min = 0, evo_max = 0.3}, - {{name = "splitter", count = math_random(1,4)}, weight = 3, evo_min = 0, evo_max = 0.3}, - --{{name = "oil-refinery", count = math_random(2,4)}, weight = 2, evo_min = 0.3, evo_max = 1}, - {{name = "pipe", count = math_random(30,50)}, weight = 3, evo_min = 0.0, evo_max = 0.3}, - {{name = "pipe-to-ground", count = math_random(4,8)}, weight = 1, evo_min = 0.2, evo_max = 0.5}, - {{name = "pumpjack", count = math_random(1,3)}, weight = 1, evo_min = 0.3, evo_max = 0.8}, - {{name = "pump", count = math_random(1,2)}, weight = 1, evo_min = 0.3, evo_max = 0.8}, - {{name = "solar-panel", count = math_random(3,6)}, weight = 3, evo_min = 0.4, evo_max = 0.9}, - {{name = "electric-furnace", count = math_random(2,4)}, weight = 3, evo_min = 0.5, evo_max = 1}, - {{name = "steel-furnace", count = math_random(4,8)}, weight = 3, evo_min = 0.2, evo_max = 0.7}, - {{name = "stone-furnace", count = math_random(8,16)}, weight = 3, evo_min = 0.0, evo_max = 0.2}, - {{name = "radar", count = math_random(1,2)}, weight = 1, evo_min = 0.1, evo_max = 0.4}, - {{name = "rail-signal", count = math_random(8,16)}, weight = 2, evo_min = 0.2, evo_max = 0.8}, - {{name = "rail-chain-signal", count = math_random(8,16)}, weight = 2, evo_min = 0.2, evo_max = 0.8}, - {{name = "stone-wall", count = math_random(33,99)}, weight = 3, evo_min = 0.0, evo_max = 0.7}, - {{name = "gate", count = math_random(16,32)}, weight = 3, evo_min = 0.0, evo_max = 0.7}, - {{name = "storage-tank", count = math_random(2,6)}, weight = 3, evo_min = 0.3, evo_max = 0.6}, - {{name = "train-stop", count = math_random(1,2)}, weight = 1, evo_min = 0.2, evo_max = 0.7}, - {{name = "express-loader", count = math_random(1,2)}, weight = 1, evo_min = 0.5, evo_max = 1}, - {{name = "fast-loader", count = math_random(1,2)}, weight = 1, evo_min = 0.2, evo_max = 0.7}, - {{name = "loader", count = math_random(1,2)}, weight = 1, evo_min = 0.0, evo_max = 0.5}, - {{name = "lab", count = math_random(1,2)}, weight = 2, evo_min = 0.0, evo_max = 0.3}, - {{name = "roboport", count = 1}, weight = 2, evo_min = 0.8, evo_max = 1}, - {{name = "flamethrower-turret", count = 1}, weight = 3, evo_min = 0.5, evo_max = 1}, - {{name = "laser-turret", count = math_random(3,6)}, weight = 3, evo_min = 0.5, evo_max = 1}, - {{name = "gun-turret", count = math_random(2,4)}, weight = 3, evo_min = 0.2, evo_max = 0.9}, + {{name = "burner-inserter", count = math_random(8,16)}, weight = 3, d_min = 0.0, d_max = 0.1}, + {{name = "inserter", count = math_random(8,16)}, weight = 3, d_min = 0.0, d_max = 0.4}, + {{name = "long-handed-inserter", count = math_random(8,16)}, weight = 3, d_min = 0.0, d_max = 0.4}, + {{name = "fast-inserter", count = math_random(8,16)}, weight = 3, d_min = 0.1, d_max = 1}, + {{name = "filter-inserter", count = math_random(8,16)}, weight = 1, d_min = 0.2, d_max = 1}, + {{name = "stack-filter-inserter", count = math_random(4,8)}, weight = 1, d_min = 0.4, d_max = 1}, + {{name = "stack-inserter", count = math_random(4,8)}, weight = 3, d_min = 0.3, d_max = 1}, + {{name = "small-electric-pole", count = math_random(16,24)}, weight = 3, d_min = 0.0, d_max = 0.3}, + {{name = "medium-electric-pole", count = math_random(8,16)}, weight = 3, d_min = 0.2, d_max = 1}, + {{name = "big-electric-pole", count = math_random(4,8)}, weight = 3, d_min = 0.3, d_max = 1}, + {{name = "substation", count = math_random(2,4)}, weight = 3, d_min = 0.5, d_max = 1}, + {{name = "wooden-chest", count = math_random(8,16)}, weight = 3, d_min = 0.0, d_max = 0.2}, + {{name = "iron-chest", count = math_random(8,16)}, weight = 3, d_min = 0.1, d_max = 0.4}, + {{name = "steel-chest", count = math_random(8,16)}, weight = 3, d_min = 0.3, d_max = 1}, + {{name = "small-lamp", count = math_random(16,32)}, weight = 3, d_min = 0.1, d_max = 0.3}, + {{name = "rail", count = math_random(25,75)}, weight = 3, d_min = 0.1, d_max = 0.6}, + {{name = "assembling-machine-1", count = math_random(2,4)}, weight = 3, d_min = 0.0, d_max = 0.3}, + {{name = "assembling-machine-2", count = math_random(2,4)}, weight = 3, d_min = 0.2, d_max = 0.8}, + {{name = "assembling-machine-3", count = math_random(2,4)}, weight = 3, d_min = 0.5, d_max = 1}, + {{name = "accumulator", count = math_random(4,8)}, weight = 3, d_min = 0.4, d_max = 1}, + {{name = "offshore-pump", count = math_random(1,3)}, weight = 2, d_min = 0.0, d_max = 0.2}, + {{name = "beacon", count = 1}, weight = 2, d_min = 0.7, d_max = 1}, + {{name = "boiler", count = math_random(3,6)}, weight = 3, d_min = 0.0, d_max = 0.3}, + {{name = "steam-engine", count = math_random(2,4)}, weight = 3, d_min = 0.0, d_max = 0.5}, + {{name = "steam-turbine", count = math_random(1,2)}, weight = 2, d_min = 0.6, d_max = 1}, + {{name = "nuclear-reactor", count = 1}, weight = 1, d_min = 0.7, d_max = 1}, + {{name = "centrifuge", count = 1}, weight = 1, d_min = 0.6, d_max = 1}, + {{name = "heat-pipe", count = math_random(4,8)}, weight = 2, d_min = 0.5, d_max = 1}, + {{name = "heat-exchanger", count = math_random(2,4)}, weight = 2, d_min = 0.5, d_max = 1}, + {{name = "arithmetic-combinator", count = math_random(4,8)}, weight = 2, d_min = 0.1, d_max = 1}, + {{name = "constant-combinator", count = math_random(4,8)}, weight = 2, d_min = 0.1, d_max = 1}, + {{name = "decider-combinator", count = math_random(4,8)}, weight = 2, d_min = 0.1, d_max = 1}, + {{name = "power-switch", count = 1}, weight = 2, d_min = 0.1, d_max = 1}, + {{name = "programmable-speaker", count = math_random(2,4)}, weight = 1, d_min = 0.1, d_max = 1}, + {{name = "green-wire", count = math_random(50,99)}, weight = 4, d_min = 0.1, d_max = 1}, + {{name = "red-wire", count = math_random(50,99)}, weight = 4, d_min = 0.1, d_max = 1}, + {{name = "chemical-plant", count = math_random(1,3)}, weight = 3, d_min = 0.3, d_max = 1}, + {{name = "burner-mining-drill", count = math_random(2,4)}, weight = 3, d_min = 0.0, d_max = 0.2}, + {{name = "electric-mining-drill", count = math_random(2,4)}, weight = 3, d_min = 0.2, d_max = 1}, + {{name = "express-transport-belt", count = math_random(25,75)}, weight = 3, d_min = 0.5, d_max = 1}, + {{name = "express-underground-belt", count = math_random(4,8)}, weight = 3, d_min = 0.5, d_max = 1}, + {{name = "express-splitter", count = math_random(1,4)}, weight = 3, d_min = 0.5, d_max = 1}, + {{name = "fast-transport-belt", count = math_random(25,75)}, weight = 3, d_min = 0.2, d_max = 0.7}, + {{name = "fast-underground-belt", count = math_random(4,8)}, weight = 3, d_min = 0.2, d_max = 0.7}, + {{name = "fast-splitter", count = math_random(1,4)}, weight = 3, d_min = 0.2, d_max = 0.3}, + {{name = "transport-belt", count = math_random(25,75)}, weight = 3, d_min = 0, d_max = 0.3}, + {{name = "underground-belt", count = math_random(4,8)}, weight = 3, d_min = 0, d_max = 0.3}, + {{name = "splitter", count = math_random(1,4)}, weight = 3, d_min = 0, d_max = 0.3}, + --{{name = "oil-refinery", count = math_random(2,4)}, weight = 2, d_min = 0.3, d_max = 1}, + {{name = "pipe", count = math_random(30,50)}, weight = 3, d_min = 0.0, d_max = 0.3}, + {{name = "pipe-to-ground", count = math_random(4,8)}, weight = 1, d_min = 0.2, d_max = 0.5}, + {{name = "pumpjack", count = math_random(1,3)}, weight = 1, d_min = 0.3, d_max = 0.8}, + {{name = "pump", count = math_random(1,2)}, weight = 1, d_min = 0.3, d_max = 0.8}, + {{name = "solar-panel", count = math_random(3,6)}, weight = 3, d_min = 0.4, d_max = 0.9}, + {{name = "electric-furnace", count = math_random(2,4)}, weight = 3, d_min = 0.5, d_max = 1}, + {{name = "steel-furnace", count = math_random(4,8)}, weight = 3, d_min = 0.2, d_max = 0.7}, + {{name = "stone-furnace", count = math_random(8,16)}, weight = 3, d_min = 0.0, d_max = 0.2}, + {{name = "radar", count = math_random(1,2)}, weight = 1, d_min = 0.1, d_max = 0.4}, + {{name = "rail-signal", count = math_random(8,16)}, weight = 2, d_min = 0.2, d_max = 0.8}, + {{name = "rail-chain-signal", count = math_random(8,16)}, weight = 2, d_min = 0.2, d_max = 0.8}, + {{name = "stone-wall", count = math_random(33,99)}, weight = 3, d_min = 0.0, d_max = 0.7}, + {{name = "gate", count = math_random(16,32)}, weight = 3, d_min = 0.0, d_max = 0.7}, + {{name = "storage-tank", count = math_random(2,6)}, weight = 3, d_min = 0.3, d_max = 0.6}, + {{name = "train-stop", count = math_random(1,2)}, weight = 1, d_min = 0.2, d_max = 0.7}, + {{name = "express-loader", count = math_random(1,2)}, weight = 1, d_min = 0.5, d_max = 1}, + {{name = "fast-loader", count = math_random(1,2)}, weight = 1, d_min = 0.2, d_max = 0.7}, + {{name = "loader", count = math_random(1,2)}, weight = 1, d_min = 0.0, d_max = 0.5}, + {{name = "lab", count = math_random(1,2)}, weight = 2, d_min = 0.0, d_max = 0.3}, + {{name = "roboport", count = 1}, weight = 2, d_min = 0.8, d_max = 1}, + {{name = "flamethrower-turret", count = 1}, weight = 3, d_min = 0.5, d_max = 1}, + {{name = "laser-turret", count = math_random(3,6)}, weight = 3, d_min = 0.5, d_max = 1}, + {{name = "gun-turret", count = math_random(2,4)}, weight = 3, d_min = 0.2, d_max = 0.9}, } local distance_to_center = (math.abs(position.y) + 1) * 0.0002 @@ -148,20 +163,19 @@ function treasure_chest(surface, position) for _, t in pairs (chest_loot) do for x = 1, t.weight, 1 do - if t.evo_min <= distance_to_center and t.evo_max >= distance_to_center then + if t.d_min <= distance_to_center and t.d_max >= distance_to_center then table.insert(chest_raffle, t[1]) end end end - - local name = "wooden-chest" - if distance_to_center > 0.5 then name = "iron-chest" end - if distance_to_center > 0.75 then name = "steel-chest" end - local e = surface.create_entity({name = name, position=position, force="neutral"}) + + local e = surface.create_entity({name = container_name, position=position, force="neutral"}) e.minable = false local i = e.get_inventory(defines.inventory.chest) for x = 1, math_random(2,6), 1 do local loot = chest_raffle[math_random(1,#chest_raffle)] i.insert(loot) end -end \ No newline at end of file +end + +return Public.treasure_chest \ No newline at end of file diff --git a/maps/overgrowth.lua b/maps/overgrowth.lua index e47b0ffa..232d6b23 100644 --- a/maps/overgrowth.lua +++ b/maps/overgrowth.lua @@ -18,6 +18,7 @@ require "modules.trees_randomly_die" require "maps.overgrowth_map_info" require "functions.soft_reset" +local rpg_t = require 'modules.rpg' local kaboom = require "functions.omegakaboom" require "modules.difficulty_vote" @@ -131,6 +132,7 @@ local function get_surface_settings() end function reset_map() + local rpg = rpg_t.get_table() global.trees_grow_chunk_next_visit = {} global.trees_grow_chunk_raffle = {} global.trees_grow_chunk_position = {} @@ -148,7 +150,7 @@ function reset_map() game.map_settings.enemy_evolution.time_factor = difficulties_votes_evo[4] - if global.rpg then rpg_reset_all_players() end + if rpg then rpg_reset_all_players() end end local function on_player_joined_game(event) diff --git a/maps/quarters.lua b/maps/quarters.lua index 48719e5e..e66078ec 100644 --- a/maps/quarters.lua +++ b/maps/quarters.lua @@ -1,31 +1,7 @@ require "modules.mineable_wreckage_yields_scrap" require "modules.wave_defense.main" -require "modules.map_info" -map_info = {} -map_info.main_caption = "4 Quarters" -map_info.sub_caption = "coal ++ iron ++ copper ++ stone" -map_info.text = table.concat({ - "Green energy ore may be found in the stone area.\n", - "Oil may be found in the coal area.\n", - "\n", - "Hold the door as long as possible.\n", - "Don't let them in!\n", -}) -map_info.main_caption_color = {r = 0, g = 120, b = 0} -map_info.sub_caption_color = {r = 255, g = 0, b = 255} - ---require "modules.biters_attack_moving_players" ---[[ -local difficulties_votes = { - [1] = {tick_increase = 4500, amount_modifier = 0.52, strength_modifier = 0.40, boss_modifier = 3.0}, - [2] = {tick_increase = 4100, amount_modifier = 0.76, strength_modifier = 0.65, boss_modifier = 4.0}, - [3] = {tick_increase = 3800, amount_modifier = 0.92, strength_modifier = 0.85, boss_modifier = 5.0}, - [4] = {tick_increase = 3600, amount_modifier = 1.00, strength_modifier = 1.00, boss_modifier = 6.0}, - [5] = {tick_increase = 3400, amount_modifier = 1.08, strength_modifier = 1.25, boss_modifier = 7.0}, - [6] = {tick_increase = 3100, amount_modifier = 1.24, strength_modifier = 1.75, boss_modifier = 8.0}, - [7] = {tick_increase = 2700, amount_modifier = 1.48, strength_modifier = 2.50, boss_modifier = 9.0} -} -]] +local Map = require "modules.map_info" +local WD = require "modules.wave_defense.table" local simplex_noise = require 'utils.simplex_noise'.d2 local spawn_size = 96 local wall_thickness = 3 @@ -129,34 +105,7 @@ local function get_quarter_name(position) end end end ---[[ -local function send_peace_quarter_biters() - local surface = game.surfaces[1] - local target = surface.find_nearest_enemy({position = {0, 0}, max_distance = 99999, force = "enemy"}) - if target then - target = target.position - else - target = {x = 0, y = 0} - end - local units_nw = {} - local units_se = {} - for _, unit in pairs(surface.find_entities_filtered({type = "unit"})) do - local quarter = get_quarter_name(unit.position) - if quarter == "NW" then units_nw[#units_nw + 1] = unit end - if quarter == "SE" then units_se[#units_se + 1] = unit end - end - if #units_nw > 2 then table.shuffle_table(units_nw) end - if #units_se > 2 then table.shuffle_table(units_se) end - for i = 1, 512, 1 do - if units_nw[i] then - units_nw[i].set_command({type=defines.command.attack_area, destination=target, radius=8, distraction=defines.distraction.by_anything}) - end - if units_se[i] then - units_se[i].set_command({type=defines.command.attack_area, destination=target, radius=8, distraction=defines.distraction.by_anything}) - end - end -end -]] + local function draw_borders(surface, left_top, area) if left_top.x == 0 or left_top.x == -32 then for x = 0, 31, 1 do @@ -205,14 +154,21 @@ local function on_chunk_generated(event) draw_borders(surface, left_top, event.area) - if left_top.x ^ 2 + left_top.y ^ 2 > 360000 then return end + if left_top.x > 512 then return end + if left_top.x < -512 then return end + if left_top.y > 512 then return end + if left_top.y < -512 then return end + game.forces.player.chart(surface, {{left_top.x, left_top.y},{left_top.x + 31, left_top.y + 31}}) end local function set_difficulty() - --20 Players for maximum difficulty - global.wave_defense.wave_interval = 7200 - #game.connected_players * 270 - if global.wave_defense.wave_interval < 1800 then global.wave_defense.wave_interval = 1800 end + local wave_defense_table = WD.get_table() + + wave_defense_table.threat_gain_multiplier = 2 + #game.connected_players * 0.1 + --20 Players for fastest wave_interval + wave_defense_table.wave_interval = 3600 - #game.connected_players * 90 + if wave_defense_table.wave_interval < 1800 then wave_defense_table.wave_interval = 1800 end end local function on_player_joined_game(event) @@ -223,53 +179,19 @@ local function on_player_left_game(event) set_difficulty() end ---[[ -local function tick(event) - local size = math.floor((8 + game.tick / difficulties_votes[global.difficulty_vote_index].tick_increase) * difficulties_votes[global.difficulty_vote_index].amount_modifier) - if size > 80 then size = 80 end - game.map_settings.enemy_expansion.settler_group_min_size = size - game.map_settings.enemy_expansion.settler_group_max_size = size * 2 - - game.map_settings.enemy_evolution.destroy_factor = global.enemy_evolution_destroy_factor * difficulties_votes[global.difficulty_vote_index].strength_modifier - game.map_settings.enemy_evolution.time_factor = global.enemy_evolution_time_factor * difficulties_votes[global.difficulty_vote_index].strength_modifier - game.map_settings.enemy_evolution.pollution_factor = global.enemy_evolution_pollution_factor * difficulties_votes[global.difficulty_vote_index].strength_modifier - - if game.tick % 240 == 0 then - game.forces.player.chart(game.surfaces[1], {{-192, -192},{160, 160}}) - end - - if game.tick % 18000 == 0 then - send_peace_quarter_biters() - end - --game.map_settings.enemy_expansion.min_expansion_cooldown = difficulties_votes[global.difficulty_vote_index].tick_increase - --game.map_settings.enemy_expansion.max_expansion_cooldown = difficulties_votes[global.difficulty_vote_index].tick_increase - - --local amount = 1 + game.tick / 120 - --if amount > 32 then amount = 32 end - --game.surfaces[1].pollute({-1 + math.random(0, 2), -1 + math.random(0, 2)}, amount) -end - - ---Flamethrower Turret Nerf -local function on_research_finished(event) - local research = event.research - local force_name = research.force.name - if research.name == "flamethrower" then - if not global.flamethrower_damage then global.flamethrower_damage = {} end - global.flamethrower_damage[force_name] = -0.6 - game.forces[force_name].set_turret_attack_modifier("flamethrower-turret", global.flamethrower_damage[force_name]) - game.forces[force_name].set_ammo_damage_modifier("flamethrower", global.flamethrower_damage[force_name]) - end - - if string.sub(research.name, 0, 18) == "refined-flammables" then - global.flamethrower_damage[force_name] = global.flamethrower_damage[force_name] + 0.05 - game.forces[force_name].set_turret_attack_modifier("flamethrower-turret", global.flamethrower_damage[force_name]) - game.forces[force_name].set_ammo_damage_modifier("flamethrower", global.flamethrower_damage[force_name]) - end -end -]] - local function on_init() + local T = Map.Pop_info() + T.main_caption = "4 Quarters" + T.sub_caption = "coal ++ iron ++ copper ++ stone" + T.text = table.concat({ + "Green energy ore may be found in the stone area.\n", + "Oil may be found in the coal area.\n", + "\n", + "Hold the door as long as possible.\n", + "Don't let them in!\n", + }) + T.main_caption_color = {r = 0, g = 120, b = 0} + T.sub_caption_color = {r = 255, g = 0, b = 255} for i, quarter in pairs({"coal", "iron-ore", "stone", "copper-ore"}) do local map_gen_settings = {} map_gen_settings.seed = math.random(1, 999999999) @@ -322,7 +244,7 @@ local event = require 'utils.event' --event.on_nth_tick(60, tick) event.on_init(on_init) event.add(defines.events.on_chunk_generated, on_chunk_generated) -event.add(defines.events.on_entity_died, on_entity_died) +--event.add(defines.events.on_entity_died, on_entity_died) --event.add(defines.events.on_research_finished, on_research_finished) event.add(defines.events.on_player_joined_game, on_player_joined_game) event.add(defines.events.on_player_left_game, on_player_left_game) diff --git a/maps/spooky_forest.lua b/maps/spooky_forest.lua index ebc47576..15bc785e 100644 --- a/maps/spooky_forest.lua +++ b/maps/spooky_forest.lua @@ -14,7 +14,6 @@ require "modules.biters_avoid_damage" require "modules.biters_double_damage" require "modules.spawners_contain_biters" require "modules.rocks_broken_paint_tiles" -require "modules.rocks_yield_ore" require "modules.rpg" require "modules.hunger" @@ -393,6 +392,7 @@ local ore_spawn_raffle = { } local function on_entity_died(event) + if not event.entity.valid then return end local surface = event.entity.surface if event.entity.name == "biter-spawner" or event.entity.name == "spitter-spawner" then @@ -448,7 +448,7 @@ local function on_player_joined_game(event) local turret_positions = {{6, 6}, {-5, -5}, {-5, 6}, {6, -5}} for _, pos in pairs(turret_positions) do local turret = surface.create_entity({name = "gun-turret", position = pos, force = "player"}) - turret.insert({name = "firearm-magazine", count = 32}) + turret.insert({name = "firearm-magazine", count = 64}) end local radius = 320 @@ -465,7 +465,6 @@ local function on_player_joined_game(event) player.insert({name = "land-mine", count = 2}) player.insert({name = "light-armor", count = 1}) player.insert({name = "firearm-magazine", count = 64}) - if global.show_floating_killscore then global.show_floating_killscore[player.name] = false end end local surface = game.surfaces["spooky_forest"] @@ -637,4 +636,7 @@ event.add(defines.events.on_player_mined_entity, on_player_mined_entity) event.add(defines.events.on_entity_died, on_entity_died) event.add(defines.events.on_chunk_generated, on_chunk_generated) event.add(defines.events.on_player_changed_position, on_player_changed_position) -event.add(defines.events.on_player_joined_game, on_player_joined_game) \ No newline at end of file +event.add(defines.events.on_player_joined_game, on_player_joined_game) + +require "modules.rocks_yield_ore" +global.rocks_yield_ore_base_amount = 100 \ No newline at end of file diff --git a/maps/unit_group_desync.lua b/maps/unit_group_desync.lua new file mode 100644 index 00000000..348c643d --- /dev/null +++ b/maps/unit_group_desync.lua @@ -0,0 +1,66 @@ +local function move_unit_groups() + print("move_unit_groups 1") + local surface = game.surfaces[1] + local entities = surface.find_entities_filtered({type = "character", limit = 1}) + if not entities[1] then return end + local character = entities[1] + + --local character = game.connected_players[1].character + --if not character then return end + --if not character.valid then return end + + print("move_unit_groups 2") + for key, group in pairs(global.unit_groups) do + if group.valid then + print("move_unit_groups 3") + group.set_command({ + type = defines.command.compound, + structure_type = defines.compound_command.return_last, + commands = { + { + type = defines.command.attack, + target = character, + distraction = defines.distraction.by_enemy, + }, + }, + }) + else + print("move_unit_groups 4") + global.unit_groups[key] = nil + end + end +end + +local function spawn_unit_group() + print("spawn_unit_group 1") + local surface = game.surfaces[1] + if not global.unit_groups then global.unit_groups = {} end + print("spawn_unit_group 2") + local unit = surface.create_entity({name = "small-biter", position = {0,48}, force = "enemy"}) + local unit_group = surface.create_unit_group({position = {0,48}, force = "enemy"}) + print("spawn_unit_group 3") + unit_group.add_member(unit) + + if global.table_insert then + table.insert(global.unit_groups, unit_group) + else + global.unit_groups[#global.unit_groups + 1] = unit_group + end + + print("spawn_unit_group 4") +end + +local function on_tick() + spawn_unit_group() + if game.tick % 120 == 0 then move_unit_groups() end +end + +local function on_player_created(event) + local player = game.players[event.player_index] + player.insert({name = "grenade", count = 1000}) + player.insert({name = "power-armor", count = 1}) +end + +local event = require 'utils.event' +event.on_nth_tick(30, on_tick) +event.add(defines.events.on_player_created, on_player_created) \ No newline at end of file diff --git a/maps/wave_defense.lua b/maps/wave_defense.lua index 6a1e8339..77f0e62d 100644 --- a/maps/wave_defense.lua +++ b/maps/wave_defense.lua @@ -1,26 +1,15 @@ --vanilla with wave_defense -require "modules.wave_defense.main" -require "modules.map_info" -map_info = {} -map_info.main_caption = "Wave Defense" -map_info.sub_caption = "~~~~~~" -map_info.text = table.concat({ - "Survive\n", - "as\n", - "long\n", - "as\n", - "possible.\n", -}) -map_info.main_caption_color = {r = 150, g = 0, b = 150} -map_info.sub_caption_color = {r = 100, g = 150, b = 0} +local WD = require "modules.wave_defense.main" +local Map = require "modules.map_info" local starting_items = {['pistol'] = 1, ['firearm-magazine'] = 16, ['iron-plate'] = 16, ['iron-gear-wheel'] = 8, ['raw-fish'] = 3,} local function set_difficulty() + local wave_defense_table = WD.get_table() --20 Players for maximum difficulty - global.wave_defense.wave_interval = 7200 - #game.connected_players * 270 - if global.wave_defense.wave_interval < 1800 then global.wave_defense.wave_interval = 1800 end + wave_defense_table.wave_interval = 7200 - #game.connected_players * 270 + if wave_defense_table.wave_interval < 1800 then wave_defense_table.wave_interval = 1800 end end local function on_player_joined_game(event) @@ -38,7 +27,19 @@ local function on_player_left_game(event) set_difficulty() end -local function on_init() +local function on_init() + local T = Map.Pop_info() + T.main_caption = "Wave Defense" + T.sub_caption = "~~~~~~" + T.text = table.concat({ + "Survive\n", + "as\n", + "long\n", + "as\n", + "possible.\n", + }) + T.main_caption_color = {r = 150, g = 0, b = 150} + T.sub_caption_color = {r = 100, g = 150, b = 0} game.surfaces[1].request_to_generate_chunks({0,0}, 16) game.surfaces[1].force_generate_chunk_requests() end diff --git a/maps/wave_of_death/game_status.lua b/maps/wave_of_death/game_status.lua index 7e1df2ea..6c366077 100644 --- a/maps/wave_of_death/game_status.lua +++ b/maps/wave_of_death/game_status.lua @@ -1,4 +1,5 @@ local game_status = {} +local Server = require 'utils.server' local function create_victory_gui(winning_lane) for _, player in pairs(game.connected_players) do @@ -16,8 +17,8 @@ game_status.restart_server = function() if global.server_restart_timer == 0 then game.print("Map is restarting!", {r=0.22, g=0.88, b=0.22}) local message = 'Map is restarting! ' - server_commands.to_discord_bold(table.concat{'*** ', message, ' ***'}) - server_commands.start_scenario('wave_of_death') + Server.to_discord_bold(table.concat{'*** ', message, ' ***'}) + Server.start_scenario('wave_of_death') global.server_restart_timer = nil return end diff --git a/modules/autohotbar.lua b/modules/autohotbar.lua index 7e6ffb6f..3f53837c 100644 --- a/modules/autohotbar.lua +++ b/modules/autohotbar.lua @@ -28,6 +28,7 @@ local function set_hotbar(player, item) end local function on_player_fast_transferred(event) + if not global.auto_hotbar_enabled[event.player_index] then return end local player = game.players[event.player_index] for name, count in pairs(player.get_main_inventory().get_contents()) do set_hotbar(player, name) @@ -35,17 +36,25 @@ local function on_player_fast_transferred(event) end local function on_player_crafted_item(event) + if not global.auto_hotbar_enabled[event.player_index] then return end set_hotbar(game.players[event.player_index], event.item_stack.name) end local function on_picked_up_item(event) + if not global.auto_hotbar_enabled[event.player_index] then return end set_hotbar(game.players[event.player_index], event.item_stack.name) end local function on_player_mined_entity(event) + if not global.auto_hotbar_enabled[event.player_index] then return end set_hotbar(game.players[event.player_index], event.entity.name) end +local function on_init() + global.auto_hotbar_enabled = {} +end + +event.on_init(on_init) event.add(defines.events.on_player_fast_transferred, on_player_fast_transferred) event.add(defines.events.on_player_crafted_item, on_player_crafted_item) event.add(defines.events.on_picked_up_item, on_picked_up_item) diff --git a/modules/biter_health_booster.lua b/modules/biter_health_booster.lua index 55617b19..bb369646 100644 --- a/modules/biter_health_booster.lua +++ b/modules/biter_health_booster.lua @@ -2,8 +2,15 @@ -- Use global.biter_health_boost to modify their health. -- 1 = vanilla health, 2 = 200% vanilla health -- do not use values below 1 +local math_floor = math.floor +local math_round = math.round +local Public = {} local function clean_table() + --Perform a table cleanup every 5000 boosts + global.biter_health_boost_count = global.biter_health_boost_count + 1 + if global.biter_health_boost_count % 5000 ~= 0 then return end + local units_to_delete = {} --Mark all health boost entries for deletion @@ -24,42 +31,88 @@ local function clean_table() end end +local function create_boss_healthbar(entity, size) + return rendering.draw_sprite({ + sprite="virtual-signal/signal-white", + tint={0, 200, 0}, + x_scale=size * 15, y_scale=size, render_layer="light-effect", + target=entity, target_offset={0, -2.5}, surface=entity.surface, + }) +end + +local function set_boss_healthbar(health, max_health, healthbar_id) + local m = health / max_health + local x_scale = rendering.get_y_scale(healthbar_id) * 15 + rendering.set_x_scale(healthbar_id, x_scale * m) + rendering.set_color(healthbar_id, {math_floor(255 - 255 * m), math_floor(200 * m), 0}) +end + +function Public.add_unit(unit, health_multiplier) + if not health_multiplier then health_multiplier = global.biter_health_boost end + global.biter_health_boost_units[unit.unit_number] = { + math_floor(unit.prototype.max_health * health_multiplier), + math_round(1 / health_multiplier, 5), + } + clean_table() +end + +function Public.add_boss_unit(unit, health_multiplier, health_bar_size) + if not health_multiplier then health_multiplier = global.biter_health_boost end + if not health_bar_size then health_bar_size = 0.5 end + local health = math_floor(unit.prototype.max_health * health_multiplier) + global.biter_health_boost_units[unit.unit_number] = { + health, + math_round(1 / health_multiplier, 5), + {max_health = health, healthbar_id = create_boss_healthbar(unit, health_bar_size), last_update = game.tick}, + } + clean_table() +end + local function on_entity_damaged(event) - if not event.entity.valid then return end - if event.entity.force.index ~= 2 then return end - if event.entity.type ~= "unit" then return end + local biter = event.entity + if not (biter and biter.valid) then return end + if biter.force.index ~= 2 then return end + if biter.type ~= "unit" then return end + + local biter_health_boost_units = global.biter_health_boost_units + + local unit_number = biter.unit_number --Create new health pool - if not global.biter_health_boost_units[event.entity.unit_number] then - global.biter_health_boost_units[event.entity.unit_number] = { - math.floor(event.entity.prototype.max_health * global.biter_health_boost), - math.round(1 / global.biter_health_boost, 5), - } - - --Perform a table cleanup every 5000 boosts - global.biter_health_boost_count = global.biter_health_boost_count + 1 - if global.biter_health_boost_count % 5000 == 0 then clean_table() end + local health_pool = biter_health_boost_units[unit_number] + if not health_pool then + Public.add_unit(biter, global.biter_health_boost) + health_pool = biter_health_boost_units[unit_number] + end + + --Process boss unit health bars + local boss = health_pool[3] + if boss then + if boss.last_update + 10 < game.tick then + set_boss_healthbar(health_pool[1], boss.max_health, boss.healthbar_id) + boss.last_update = game.tick + end end --Reduce health pool - global.biter_health_boost_units[event.entity.unit_number][1] = global.biter_health_boost_units[event.entity.unit_number][1] - event.final_damage_amount - + health_pool[1] = health_pool[1] - event.final_damage_amount + --Set entity health relative to health pool - event.entity.health = global.biter_health_boost_units[event.entity.unit_number][1] * global.biter_health_boost_units[event.entity.unit_number][2] - + biter.health = health_pool[1] * health_pool[2] + --Proceed to kill entity if health is 0 - if event.entity.health > 0 then return end - + if biter.health > 0 then return end + --Remove health pool - global.biter_health_boost_units[event.entity.unit_number] = nil - + biter_health_boost_units[unit_number] = nil + if event.cause then if event.cause.valid then - event.entity.die(event.entity.force, event.cause) + event.entity.die(event.cause.force, event.cause) return end end - event.entity.die(event.entity.force) + biter.die(biter.force) end local function on_init() @@ -70,4 +123,6 @@ end local event = require 'utils.event' event.on_init(on_init) -event.add(defines.events.on_entity_damaged, on_entity_damaged) \ No newline at end of file +event.add(defines.events.on_entity_damaged, on_entity_damaged) + +return Public \ No newline at end of file diff --git a/modules/biter_pets.lua b/modules/biter_pets.lua index 8bf7a4f6..8226c5bd 100644 --- a/modules/biter_pets.lua +++ b/modules/biter_pets.lua @@ -1,6 +1,8 @@ local math_random = math.random local nom_msg = {"munch", "munch", "yum"} +local Public = {} + local function feed_floaty_text(unit) unit.surface.create_entity({name = "flying-text", position = unit.position, text = nom_msg[math_random(1, #nom_msg)], color = {math_random(50, 100), 0, 255}}) end @@ -48,7 +50,7 @@ local function feed_pet(unit) return true end -function biter_pets_tame_unit(player, unit, forced) +function Public.biter_pets_tame_unit(player, unit, forced) if global.biter_pets[player.index] then return false end if not forced then if math_random(1, math.floor(unit.prototype.max_health * 0.01) + 1) ~= 1 then @@ -91,7 +93,7 @@ local function on_player_dropped_item(event) if event.entity.stack.name ~= "raw-fish" then return end local unit = find_unit(player, event.entity) if not unit then return end - if biter_pets_tame_unit(player, unit, false) then event.entity.destroy() return end + if Public.biter_pets_tame_unit(player, unit, false) then event.entity.destroy() return end if unit.force.index == player.force.index then feed_pet(unit) end end @@ -102,4 +104,6 @@ end local event = require 'utils.event' event.on_init(on_init) event.add(defines.events.on_player_dropped_item, on_player_dropped_item) -event.add(defines.events.on_player_changed_position, on_player_changed_position) \ No newline at end of file +event.add(defines.events.on_player_changed_position, on_player_changed_position) + +return Public \ No newline at end of file diff --git a/modules/difficulty_vote.lua b/modules/difficulty_vote.lua index d21fecbb..0ef6dc44 100644 --- a/modules/difficulty_vote.lua +++ b/modules/difficulty_vote.lua @@ -1,4 +1,5 @@ local event = require 'utils.event' +local Server = require 'utils.server' local difficulties = { [1] = {name = "Peaceful", value = 0.25, color = {r=0.00, g=0.45, b=0.00}, print_color = {r=0.00, g=0.8, b=0.00}}, @@ -70,7 +71,7 @@ local function set_difficulty() if global.difficulty_vote_index ~= new_index then local message = table.concat({">> Map difficulty has changed to ", difficulties[new_index].name, " difficulty!"}) game.print(message, difficulties[new_index].print_color) - server_commands.to_discord_embed(message) + Server.to_discord_embed(message) end global.difficulty_vote_index = new_index global.difficulty_vote_value = difficulties[new_index].value diff --git a/modules/explosives.lua b/modules/explosives.lua index 95e12864..8d6b3575 100644 --- a/modules/explosives.lua +++ b/modules/explosives.lua @@ -164,6 +164,7 @@ local function tick(event) global.explosion_cells[key] = nil end end + if game.tick % 216000 == 0 then global.explosion_cells_tiles = {} end end local function on_entity_died(event) @@ -182,7 +183,7 @@ local function on_entity_died(event) cell_birth(entity.surface.index, {x = entity.position.x, y = entity.position.y}, game.tick, {x = entity.position.x, y = entity.position.y}, amount * damage_per_explosive) end -local function on_init(surface) +local function on_init() global.explosion_cells = {} global.explosion_cells_vectors = {{density, 0}, {density * -1, 0}, {0, density}, {0, density * -1}} --global.explosion_cells_damage_dealt = 0 diff --git a/modules/floaty_chat.lua b/modules/floaty_chat.lua index 591b766f..ae4bedbd 100644 --- a/modules/floaty_chat.lua +++ b/modules/floaty_chat.lua @@ -7,7 +7,7 @@ local function on_console_chat(event) if not player.character then return end local y_offset = -4 - if global.rpg then y_offset = -4.5 end + if package.loaded['modules.rpg'] then y_offset = -4.5 end if global.player_floaty_chat[player.index] then rendering.destroy(global.player_floaty_chat[player.index]) diff --git a/modules/hunger.lua b/modules/hunger.lua index 3deb1b03..dca94d01 100644 --- a/modules/hunger.lua +++ b/modules/hunger.lua @@ -1,6 +1,7 @@ -- hunger module by mewmew -- local math_random = math.random +local P = require "player_modifiers" local starve_messages = {" ran out of foodstamps.", " starved.", " should not have skipped breakfast today."} @@ -121,7 +122,7 @@ function hunger_update(player, food_value) global.player_modifiers[player.index].character_running_speed_modifier["hunger"] = player_hunger_buff[global.player_hunger[player.name]] * 0.15 end global.player_modifiers[player.index].character_mining_speed_modifier["hunger"] = player_hunger_buff[global.player_hunger[player.name]] - update_player_modifiers(player) + P.update_player_modifiers(player) update_hunger_gui(player) end diff --git a/modules/map_info.lua b/modules/map_info.lua index 69be63aa..74da8594 100644 --- a/modules/map_info.lua +++ b/modules/map_info.lua @@ -1,71 +1,89 @@ -map_info = {} -map_info.main_caption = "Insert Main Caption" -map_info.main_caption_color = {r=0.6, g=0.3, b=0.99} -map_info.sub_caption = "Insert Sub Caption" -map_info.sub_caption_color = {r=0.2, g=0.9, b=0.2} -map_info.text = [[ -Add info text to map_info. -]] +local Global = require 'utils.global' +local Tabs = require 'comfy_panel.main' -local function create_map_intro(player, frame) +local map_info = { + main_caption = "Insert Main Caption", + main_caption_color = {r=0.6, g=0.3, b=0.99}, + sub_caption = "Insert Sub Caption", + sub_caption_color = {r=0.2, g=0.9, b=0.2}, + text = [[ + Add info text to map_info. + ]] +} + +Global.register( + map_info, + function(tbl) + map_info = tbl + end +) + +local Public = {} + +function Public.Pop_info() + return map_info +end + +local create_map_intro = (function (player, frame) frame.clear() frame.style.padding = 4 frame.style.margin = 0 - + local t = frame.add {type = "table", column_count = 1} - + local line = t.add { type = "line"} line.style.top_margin = 4 line.style.bottom_margin = 4 - + local l = t.add {type = "label", caption = map_info.main_caption} l.style.font = "heading-1" l.style.font_color = map_info.main_caption_color - l.style.minimal_width = 780 - l.style.horizontal_align = "center" - l.style.vertical_align = "center" - - local l = t.add {type = "label", caption = map_info.sub_caption} - l.style.font = "heading-2" - l.style.font_color = map_info.sub_caption_color l.style.minimal_width = 780 - l.style.horizontal_align = "center" + l.style.horizontal_align = "center" l.style.vertical_align = "center" - - local line = t.add { type = "line"} - line.style.top_margin = 4 - line.style.bottom_margin = 4 - + + local l_2 = t.add {type = "label", caption = map_info.sub_caption} + l_2.style.font = "heading-2" + l_2.style.font_color = map_info.sub_caption_color + l_2.style.minimal_width = 780 + l_2.style.horizontal_align = "center" + l_2.style.vertical_align = "center" + + local line_2 = t.add { type = "line"} + line_2.style.top_margin = 4 + line_2.style.bottom_margin = 4 + local scroll_pane = frame.add { type = "scroll-pane", name = "scroll_pane", direction = "vertical", horizontal_scroll_policy = "never", vertical_scroll_policy = "auto"} scroll_pane.style.maximal_height = 320 scroll_pane.style.minimal_height = 320 - - local l = scroll_pane.add {type = "label", caption = map_info.text} - l.style.font = "heading-2" - l.style.single_line = false - l.style.font_color = {r=0.85, g=0.85, b=0.88} - l.style.minimal_width = 780 - l.style.horizontal_align = "center" - l.style.vertical_align = "center" - + + local l_3 = scroll_pane.add {type = "label", caption = map_info.text} + l_3.style.font = "heading-2" + l_3.style.single_line = false + l_3.style.font_color = {r=0.85, g=0.85, b=0.88} + l_3.style.minimal_width = 780 + l_3.style.horizontal_align = "center" + l_3.style.vertical_align = "center" + local b = frame.add {type = "button", caption = "CLOSE", name = "close_map_intro"} b.style.font = "heading-2" b.style.padding = 2 b.style.top_margin = 3 b.style.left_margin = 333 - b.style.horizontal_align = "center" + b.style.horizontal_align = "center" b.style.vertical_align = "center" end +) -local function on_player_joined_game(event) +local function on_player_joined_game(event) local player = game.players[event.player_index] - if player.online_time == 0 then comfy_panel_call_tab(player, "Map Info") end + if player.online_time == 0 then Tabs.comfy_panel_call_tab(player, "Map Info") end end local function on_gui_click(event) if not event then return end if not event.element then return end - if not event.element.valid then return end + if not event.element.valid then return end if event.element.name == "close_map_intro" then game.players[event.player_index].gui.left.comfy_panel.destroy() return end end @@ -73,4 +91,6 @@ comfy_panel_tabs["Map Info"] = create_map_intro local event = require 'utils.event' event.add(defines.events.on_player_joined_game, on_player_joined_game) -event.add(defines.events.on_gui_click, on_gui_click) \ No newline at end of file +event.add(defines.events.on_gui_click, on_gui_click) + +return Public \ No newline at end of file diff --git a/modules/no_deconstruction_of_neutral_entities.lua b/modules/no_deconstruction_of_neutral_entities.lua index 7bd07a57..0221f273 100644 --- a/modules/no_deconstruction_of_neutral_entities.lua +++ b/modules/no_deconstruction_of_neutral_entities.lua @@ -2,6 +2,7 @@ local event = require 'utils.event' local function on_marked_for_deconstruction(event) if event.entity.force.name ~= "neutral" then return end + if event.entity.name == "item-on-ground" then return end event.entity.cancel_deconstruction(game.players[event.player_index].force.name) end diff --git a/modules/rocks_yield_ore.lua b/modules/rocks_yield_ore.lua index a1380e13..b4d5e778 100644 --- a/modules/rocks_yield_ore.lua +++ b/modules/rocks_yield_ore.lua @@ -1,5 +1,8 @@ --destroying and mining rocks yields ore -- load as last module -local max_spill = 48 +local max_spill = 40 +local math_random = math.random +local math_floor = math.floor +local math_sqrt = math.sqrt local rock_yield = { ["rock-big"] = 1, @@ -11,7 +14,7 @@ local rock_mining_chance_weights = { {"iron-ore", 25}, {"copper-ore",17}, {"coal",13}, - {"stone",9}, + {"stone",10}, {"uranium-ore",2} } @@ -39,8 +42,8 @@ for _, t in pairs (rock_mining_chance_weights) do end local function create_particles(surface, name, position, amount, cause_position) - local direction_mod = (-100 + math.random(0,200)) * 0.0004 - local direction_mod_2 = (-100 + math.random(0,200)) * 0.0004 + local direction_mod = (-100 + math_random(0,200)) * 0.0004 + local direction_mod_2 = (-100 + math_random(0,200)) * 0.0004 if cause_position then direction_mod = (cause_position.x - position.x) * 0.025 @@ -48,7 +51,7 @@ local function create_particles(surface, name, position, amount, cause_position) end for i = 1, amount, 1 do - local m = math.random(4, 10) + local m = math_random(4, 10) local m2 = m * 0.005 surface.create_entity({ @@ -58,15 +61,15 @@ local function create_particles(surface, name, position, amount, cause_position) vertical_speed = 0.130, height = 0, movement = { - (m2 - (math.random(0, m) * 0.01)) + direction_mod, - (m2 - (math.random(0, m) * 0.01)) + direction_mod_2 + (m2 - (math_random(0, m) * 0.01)) + direction_mod, + (m2 - (math_random(0, m) * 0.01)) + direction_mod_2 } }) end end local function get_amount(entity) - local distance_to_center = math.floor(math.sqrt(entity.position.x ^ 2 + entity.position.y ^ 2)) + local distance_to_center = math_floor(math_sqrt(entity.position.x ^ 2 + entity.position.y ^ 2)) local distance_modifier = 0.25 local base_amount = 35 @@ -78,9 +81,9 @@ local function get_amount(entity) local amount = base_amount + (distance_to_center * distance_modifier) if amount > maximum_amount then amount = maximum_amount end - local m = (70 + math.random(0, 60)) * 0.01 + local m = (70 + math_random(0, 60)) * 0.01 - amount = math.floor(amount * rock_yield[entity.name] * m) + amount = math_floor(amount * rock_yield[entity.name] * m) if amount < 1 then amount = 1 end return amount @@ -93,9 +96,9 @@ local function on_player_mined_entity(event) event.buffer.clear() - local ore = ore_raffle[math.random(1, #ore_raffle)] + local ore = ore_raffle[math_random(1, #ore_raffle)] local player = game.players[event.player_index] - + --[[ local inventory = player.get_inventory(defines.inventory.character_main) if not inventory.can_insert({name = ore, count = 1}) then local e = entity.surface.create_entity({name = entity.name, position = entity.position}) @@ -103,7 +106,7 @@ local function on_player_mined_entity(event) player.print("Inventory full.", {200, 200, 200}) return end - + ]] local count = get_amount(entity) local position = {x = entity.position.x, y = entity.position.y} @@ -131,7 +134,7 @@ local function on_entity_died(event) if not rock_yield[entity.name] then return end local surface = entity.surface - local ore = ore_raffle[math.random(1, #ore_raffle)] + local ore = ore_raffle[math_random(1, #ore_raffle)] local pos = {entity.position.x, entity.position.y} create_particles(surface, particles[ore], pos, 16, false) @@ -148,7 +151,7 @@ local function on_entity_died(event) --amount = math.ceil(amount * 0.1) --if amount > 12 then amount = 12 end entity.destroy() - surface.spill_item_stack(pos,{name = ore, count = math.random(8,12)}, true) + surface.spill_item_stack(pos,{name = ore, count = math_random(8,12)}, true) end local event = require 'utils.event' diff --git a/modules/rocks_yield_ore_veins.lua b/modules/rocks_yield_ore_veins.lua index 1f1f76ce..e3881861 100644 --- a/modules/rocks_yield_ore_veins.lua +++ b/modules/rocks_yield_ore_veins.lua @@ -34,12 +34,12 @@ local size_raffle = { } local ore_prints = { - ["coal"] = {"dark", "coal"}, - ["iron-ore"] = {"shiny", "iron"}, - ["copper-ore"] = {"glimmering", "copper"}, - ["uranium-ore"] = {"glowing", "uranium"}, - ["stone"] = {"solid", "stone"}, - ["mixed"] = {"glitter", "mixed ore"}, + ["coal"] = {"dark", "coal", "[img=entity/coal]"}, + ["iron-ore"] = {"shiny", "iron", "[img=entity/iron-ore]"}, + ["copper-ore"] = {"glimmering", "copper", "[img=entity/copper-ore]"}, + ["uranium-ore"] = {"glowing", "uranium", "[img=entity/uranium-ore]"}, + ["stone"] = {"solid", "stone", "[img=entity/stone]"}, + ["mixed"] = {"glitter", "mixed ore", " "}, } @@ -80,9 +80,11 @@ local function ore_vein(event) local player = game.players[event.player_index] for _, p in pairs(game.connected_players) do if p.index == player.index then - p.print("You notice something " .. ore_prints[ore][1] .. " underneath the rubble covered floor. It's a " .. size[1] .. " vein of " .. ore_prints[ore][2] .. "!!", { r=0.98, g=0.66, b=0.22}) + p.print("You notice something " .. ore_prints[ore][1] .. " underneath the rubble. It's a " .. size[1] .. " vein of " .. ore_prints[ore][2] .. "!! " .. ore_prints[ore][3], { r=0.80, g=0.80, b=0.80}) else - game.print(player.name .. " found a " .. size[1] .. " vein of " .. ore_prints[ore][2] .. "!", { r=0.98, g=0.66, b=0.22}) + game.print( + "[color=" .. player.chat_color.r .. "," .. player.chat_color.g .. "," .. player.chat_color.b .. "]" .. player.name + .. "[/color] found a " .. size[1] .. " vein of " .. ore_prints[ore][2] .. "! " .. ore_prints[ore][3], { r=0.80, g=0.80, b=0.80}) end end diff --git a/modules/rpg.lua b/modules/rpg.lua index 84885c71..8cb3c5c8 100644 --- a/modules/rpg.lua +++ b/modules/rpg.lua @@ -1,17 +1,22 @@ --[[ Character Experience Gain RPG by MewMew -STRENGTH > character_inventory_slots_bonus , character_mining_speed_modifier +STRENGTH > character_inventory_slots_bonus , character_mining_speed_modifier MAGIC > character_build_distance_bonus, character_item_drop_distance_bonus, character_reach_distance_bonus, - character_item_pickup_distance_bonus, character_loot_pickup_distance_bonus, + character_item_pickup_distance_bonus, character_loot_pickup_distance_bonus, DEXTERITY > character_running_speed_modifier, character_crafting_speed_modifier -VITALITY > character_health_bonus +VITALITY > character_health_bonus + +Modified by Gerkiz *-* ]] local math_random = math.random +local Global = require 'utils.global' +local Tabs = require "comfy_panel.main" +local P = require "player_modifiers" local visuals_delay = 1800 local level_up_floating_text_color = {0, 205, 0} local xp_floating_text_color = {157, 157, 157} @@ -21,6 +26,28 @@ for a = 1, 9999, 1 do end local gain_info_tooltip = "XP gain from mining, building, moving, crafting, repairing and combat." +local rpg_t = {} +local rpg_frame_icons = { + "entity/small-worm-turret", "entity/medium-worm-turret", "entity/big-worm-turret", "entity/behemoth-worm-turret", + "entity/small-biter", "entity/small-biter", "entity/small-spitter", "entity/medium-biter", "entity/medium-biter", + "entity/medium-spitter", "entity/big-biter", "entity/big-biter", "entity/big-spitter", "entity/behemoth-biter", "entity/behemoth-biter", + "entity/behemoth-spitter" +} + +Global.register( + {rpg_t=rpg_t, rpg_frame_icons=rpg_frame_icons}, + function(tbl) + rpg_t = tbl.rpg_t + rpg_frame_icons = tbl.rpg_frame_icons + end +) + +local Public = {} + +function Public.get_table() + return rpg_t +end + local classes = { ["engineer"] = "ENGINEER", ["strength"] = "MINER", @@ -40,13 +67,13 @@ local function level_up_effects(player) player.play_sound{path="utility/achievement_unlocked", volume_modifier=0.40} end -local function get_melee_modifier(player) return (global.rpg[player.index].strength - 10) * 0.10 end +local function get_melee_modifier(player) return (rpg_t[player.index].strength - 10) * 0.10 end -local function get_life_on_hit(player) return (global.rpg[player.index].vitality - 10) * 0.2 end +local function get_life_on_hit(player) return (rpg_t[player.index].vitality - 10) * 0.4 end local function get_one_punch_chance(player) - if global.rpg[player.index].strength < 100 then return 0 end - local chance = math.round(global.rpg[player.index].strength * 0.01, 1) + if rpg_t[player.index].strength < 100 then return 0 end + local chance = math.round(rpg_t[player.index].strength * 0.01, 1) if chance > 100 then chance = 100 end return chance end @@ -64,7 +91,7 @@ end local function update_char_button(player) if not player.gui.top.rpg then draw_gui_char_button(player) end - if global.rpg[player.index].points_to_distribute > 0 then + if rpg_t[player.index].points_to_distribute > 0 then player.gui.top.rpg.style.font_color = {245, 0, 0} else player.gui.top.rpg.style.font_color = {175,175,175} @@ -72,11 +99,11 @@ local function update_char_button(player) end local function update_player_stats(player) - local strength = global.rpg[player.index].strength - 10 + local strength = rpg_t[player.index].strength - 10 global.player_modifiers[player.index].character_inventory_slots_bonus["rpg"] = math.round(strength * 0.2, 3) global.player_modifiers[player.index].character_mining_speed_modifier["rpg"] = math.round(strength * 0.008, 3) - local magic = global.rpg[player.index].magic - 10 + local magic = rpg_t[player.index].magic - 10 local v = magic * 0.15 global.player_modifiers[player.index].character_build_distance_bonus["rpg"] = math.round(v, 3) global.player_modifiers[player.index].character_item_drop_distance_bonus["rpg"] = math.round(v, 3) @@ -85,22 +112,22 @@ local function update_player_stats(player) global.player_modifiers[player.index].character_item_pickup_distance_bonus["rpg"] = math.round(v * 0.25, 3) global.player_modifiers[player.index].character_resource_reach_distance_bonus["rpg"] = math.round(v * 0.15, 3) - local dexterity = global.rpg[player.index].dexterity - 10 + local dexterity = rpg_t[player.index].dexterity - 10 global.player_modifiers[player.index].character_running_speed_modifier["rpg"] = math.round(dexterity * 0.002, 3) global.player_modifiers[player.index].character_crafting_speed_modifier["rpg"] = math.round(dexterity * 0.015, 3) - global.player_modifiers[player.index].character_health_bonus["rpg"] = math.round((global.rpg[player.index].vitality - 10) * 6, 3) + global.player_modifiers[player.index].character_health_bonus["rpg"] = math.round((rpg_t[player.index].vitality - 10) * 6, 3) - update_player_modifiers(player) + P.update_player_modifiers(player) end local function get_class(player) - local average = (global.rpg[player.index].strength + global.rpg[player.index].magic + global.rpg[player.index].dexterity + global.rpg[player.index].vitality) / 4 + local average = (rpg_t[player.index].strength + rpg_t[player.index].magic + rpg_t[player.index].dexterity + rpg_t[player.index].vitality) / 4 local high_attribute = 0 local high_attribute_name = "" for _, attribute in pairs({"strength", "magic", "dexterity", "vitality"}) do - if global.rpg[player.index][attribute] > high_attribute then - high_attribute = global.rpg[player.index][attribute] + if rpg_t[player.index][attribute] > high_attribute then + high_attribute = rpg_t[player.index][attribute] high_attribute_name = attribute end end @@ -138,7 +165,7 @@ end local function add_gui_increase_stat(element, name, player, width) local sprite = "virtual-signal/signal-red" local symbol = "✚" - if global.rpg[player.index].points_to_distribute <= 0 then sprite = "virtual-signal/signal-black" end + if rpg_t[player.index].points_to_distribute <= 0 then sprite = "virtual-signal/signal-black" end local e = element.add({type = "sprite-button", name = name, caption = symbol, sprite = sprite}) e.style.maximal_height = 38 e.style.minimal_height = 38 @@ -165,10 +192,10 @@ end local function draw_gui(player, forced) if not forced then - if global.rpg[player.index].gui_refresh_delay > game.tick then return end + if rpg_t[player.index].gui_refresh_delay > game.tick then return end end - comfy_panel_clear_left_gui(player) + Tabs.comfy_panel_clear_left_gui(player) if player.gui.left.rpg then player.gui.left.rpg.destroy() end if not player.character then return end @@ -193,17 +220,17 @@ local function draw_gui(player, forced) t.style.cell_padding = 1 add_gui_description(t, "LEVEL", 80) - add_gui_stat(t, global.rpg[player.index].level, 80) + add_gui_stat(t, rpg_t[player.index].level, 80) add_gui_description(t, "EXPERIENCE", 100) - local e = add_gui_stat(t, math.floor(global.rpg[player.index].xp), 125) + local e = add_gui_stat(t, math.floor(rpg_t[player.index].xp), 125) e.tooltip = gain_info_tooltip add_gui_description(t, " ", 75) add_gui_description(t, " ", 75) add_gui_description(t, "NEXT LEVEL", 100) - local e = add_gui_stat(t, experience_levels[global.rpg[player.index].level + 1], 125) + local e = add_gui_stat(t, experience_levels[rpg_t[player.index].level + 1], 125) e.tooltip = gain_info_tooltip add_separator(frame, 400) @@ -217,33 +244,33 @@ local function draw_gui(player, forced) local tip = "Increases inventory slots and mining speed.\nIncreases melee damage." local e = add_gui_description(tt, "STRENGTH", w1) e.tooltip = tip - local e = add_gui_stat(tt, global.rpg[player.index].strength, w2) + local e = add_gui_stat(tt, rpg_t[player.index].strength, w2) e.tooltip = tip add_gui_increase_stat(tt, "strength", player) local tip = "Increases reach distance." local e = add_gui_description(tt, "MAGIC", w1) e.tooltip = tip - local e = add_gui_stat(tt, global.rpg[player.index].magic, w2) + local e = add_gui_stat(tt, rpg_t[player.index].magic, w2) e.tooltip = tip add_gui_increase_stat(tt, "magic", player) local tip = "Increases running and crafting speed." local e = add_gui_description(tt, "DEXTERITY", w1) e.tooltip = tip - local e = add_gui_stat(tt, global.rpg[player.index].dexterity, w2) + local e = add_gui_stat(tt, rpg_t[player.index].dexterity, w2) e.tooltip = tip add_gui_increase_stat(tt, "dexterity", player) local tip = "Increases health.\nIncreases melee life on-hit." local e = add_gui_description(tt, "VITALITY", w1) e.tooltip = tip - local e = add_gui_stat(tt, global.rpg[player.index].vitality, w2) + local e = add_gui_stat(tt, rpg_t[player.index].vitality, w2) e.tooltip = tip add_gui_increase_stat(tt, "vitality", player) add_gui_description(tt, "POINTS TO\nDISTRIBUTE", w1) - local e = add_gui_stat(tt, global.rpg[player.index].points_to_distribute, w2) + local e = add_gui_stat(tt, rpg_t[player.index].points_to_distribute, w2) e.style.font_color = {200, 0, 0} add_gui_description(tt, " ", w2) @@ -344,23 +371,23 @@ local function draw_gui(player, forced) add_separator(frame, 400) local t = frame.add({type = "table", column_count = 14}) for i = 1, 14, 1 do - local e = t.add({type = "sprite", sprite = global.rpg_frame_icons[i]}) + local e = t.add({type = "sprite", sprite = rpg_frame_icons[i]}) e.style.maximal_width = 24 e.style.maximal_height = 24 e.style.padding = 0 end add_separator(frame, 400) - global.rpg[player.index].gui_refresh_delay = game.tick + 60 + rpg_t[player.index].gui_refresh_delay = game.tick + 60 update_char_button(player) end local function draw_level_text(player) if not player.character then return end - if global.rpg[player.index].text then - rendering.destroy(global.rpg[player.index].text) - global.rpg[player.index].text = nil + if rpg_t[player.index].text then + rendering.destroy(rpg_t[player.index].text) + rpg_t[player.index].text = nil end local players = {} @@ -371,8 +398,8 @@ local function draw_level_text(player) end if #players == 0 then return end - global.rpg[player.index].text = rendering.draw_text{ - text = "lvl " .. global.rpg[player.index].level, + rpg_t[player.index].text = rendering.draw_text{ + text = "lvl " .. rpg_t[player.index].level, surface = player.surface, target = player.character, target_offset = {0, -3.25}, @@ -392,9 +419,9 @@ end local function level_up(player) local distribute_points_gain = 0 - for i = global.rpg[player.index].level + 1, #experience_levels, 1 do - if global.rpg[player.index].xp > experience_levels[i] then - global.rpg[player.index].level = i + for i = rpg_t[player.index].level + 1, #experience_levels, 1 do + if rpg_t[player.index].xp > experience_levels[i] then + rpg_t[player.index].level = i distribute_points_gain = distribute_points_gain + 5 else break @@ -402,36 +429,36 @@ local function level_up(player) end if distribute_points_gain == 0 then return end draw_level_text(player) - global.rpg[player.index].points_to_distribute = global.rpg[player.index].points_to_distribute + distribute_points_gain + rpg_t[player.index].points_to_distribute = rpg_t[player.index].points_to_distribute + distribute_points_gain update_char_button(player) - table.shuffle_table(global.rpg_frame_icons) + table.shuffle_table(rpg_frame_icons) if player.gui.left.rpg then draw_gui(player, true) end level_up_effects(player) end local function gain_xp(player, amount) amount = math.round(amount, 2) - global.rpg[player.index].xp = global.rpg[player.index].xp + amount - global.rpg[player.index].xp_since_last_floaty_text = global.rpg[player.index].xp_since_last_floaty_text + amount + rpg_t[player.index].xp = rpg_t[player.index].xp + amount + rpg_t[player.index].xp_since_last_floaty_text = rpg_t[player.index].xp_since_last_floaty_text + amount if player.gui.left.rpg then draw_gui(player, false) end - if not experience_levels[global.rpg[player.index].level + 1] then return end - if global.rpg[player.index].xp >= experience_levels[global.rpg[player.index].level + 1] then + if not experience_levels[rpg_t[player.index].level + 1] then return end + if rpg_t[player.index].xp >= experience_levels[rpg_t[player.index].level + 1] then level_up(player) return end - if global.rpg[player.index].last_floaty_text > game.tick then return end - player.create_local_flying_text{text="+" .. global.rpg[player.index].xp_since_last_floaty_text .. " xp", position=player.position, color=xp_floating_text_color, time_to_live=120, speed=2} - global.rpg[player.index].xp_since_last_floaty_text = 0 - global.rpg[player.index].last_floaty_text = game.tick + visuals_delay + if rpg_t[player.index].last_floaty_text > game.tick then return end + player.create_local_flying_text{text="+" .. rpg_t[player.index].xp_since_last_floaty_text .. " xp", position=player.position, color=xp_floating_text_color, time_to_live=120, speed=2} + rpg_t[player.index].xp_since_last_floaty_text = 0 + rpg_t[player.index].last_floaty_text = game.tick + visuals_delay end -function rpg_reset_player(player) +function Public.rpg_reset_player(player) if player.gui.left.rpg then player.gui.left.rpg.destroy() end if not player.character then player.set_controller({type=defines.controllers.god}) player.create_character() end - global.rpg[player.index] = { + rpg_t[player.index] = { level = 1, xp = 0, strength = 10, magic = 10, dexterity = 10, vitality = 10, points_to_distribute = 0, last_floaty_text = visuals_delay, xp_since_last_floaty_text = 0, rotated_entity_delay = 0, gui_refresh_delay = 0, last_mined_entity_position = {x = 0, y = 0}, @@ -442,12 +469,12 @@ function rpg_reset_player(player) update_player_stats(player) end -function rpg_reset_all_players() +function Public.rpg_reset_all_players() for _, p in pairs(game.players) do - global.rpg[p.index] = nil + rpg_t[p.index] = nil end for _, p in pairs(game.connected_players) do - rpg_reset_player(p) + Public.rpg_reset_player(p) end end @@ -474,25 +501,25 @@ local function on_gui_click(event) local index = element.name local player = game.players[event.player_index] - if not global.rpg[player.index][index] then return end + if not rpg_t[player.index][index] then return end if not player.character then return end if event.button == defines.mouse_button_type.right then for a = 1, 5, 1 do - if global.rpg[player.index].points_to_distribute <= 0 then draw_gui(player, false) return end - global.rpg[player.index].points_to_distribute = global.rpg[player.index].points_to_distribute - 1 - global.rpg[player.index][index] = global.rpg[player.index][index] + 1 + if rpg_t[player.index].points_to_distribute <= 0 then draw_gui(player, true) return end + rpg_t[player.index].points_to_distribute = rpg_t[player.index].points_to_distribute - 1 + rpg_t[player.index][index] = rpg_t[player.index][index] + 1 update_player_stats(player) end - draw_gui(player, false) + draw_gui(player, true) return end - if global.rpg[player.index].points_to_distribute <= 0 then draw_gui(player, false) return end - global.rpg[player.index].points_to_distribute = global.rpg[player.index].points_to_distribute - 1 - global.rpg[player.index][index] = global.rpg[player.index][index] + 1 + if rpg_t[player.index].points_to_distribute <= 0 then draw_gui(player, true) return end + rpg_t[player.index].points_to_distribute = rpg_t[player.index].points_to_distribute - 1 + rpg_t[player.index][index] = rpg_t[player.index][index] + 1 update_player_stats(player) - draw_gui(player, false) + draw_gui(player, true) end local xp_yield = { @@ -554,9 +581,23 @@ local get_cause_player = { } local function on_entity_died(event) - if not event.cause then return end - if not event.cause.valid then return end if not event.entity.valid then return end + + --Grant XP for hand placed land mines + if event.entity.last_user then + if event.entity.type == "land-mine" then + if event.cause then + if event.cause.valid then + if event.cause.force.index == event.entity.force.index then return end + end + end + gain_xp(event.entity.last_user, 1) + return + end + end + + if not event.cause then return end + if not event.cause.valid then return end if event.cause.force.index == event.entity.force.index then return end if not get_cause_player[event.cause.type] then return end @@ -564,6 +605,7 @@ local function on_entity_died(event) if not players then return end if not players[1] then return end + --Grant modified XP for health boosted units if global.biter_health_boost then if event.entity.type == "unit" then for _, player in pairs(players) do @@ -577,6 +619,7 @@ local function on_entity_died(event) end end + --Grant normal XP for _, player in pairs(players) do if xp_yield[event.entity.name] then gain_xp(player, xp_yield[event.entity.name]) @@ -646,12 +689,22 @@ local function on_entity_damaged(event) if event.cause.get_inventory(defines.inventory.character_ammo)[event.cause.selected_gun_index].valid_for_read and event.cause.get_inventory(defines.inventory.character_guns)[event.cause.selected_gun_index].valid_for_read then return end if not event.cause.player then return end - - event.entity.health = event.entity.health + event.final_damage_amount + + --Grant the player life-on-hit. event.cause.health = event.cause.health + get_life_on_hit(event.cause.player) - local damage = event.final_damage_amount + event.final_damage_amount * get_melee_modifier(event.cause.player) + --Calculate modified damage. + local damage = event.original_damage_amount + event.original_damage_amount * get_melee_modifier(event.cause.player) + if event.entity.prototype.resistances then + if event.entity.prototype.resistances.physical then + damage = damage - event.entity.prototype.resistances.physical.decrease + damage = damage - damage * event.entity.prototype.resistances.physical.percent + end + end + damage = math.round(damage, 3) + if damage < 1 then damage = 1 end + --Cause a one punch. if math_random(0,999) < get_one_punch_chance(event.cause.player) * 10 then one_punch(event.cause, event.entity, damage) if event.entity.valid then @@ -660,6 +713,7 @@ local function on_entity_damaged(event) return end + --Floating messages and particle effects. if math_random(1,7) == 1 then damage = damage * math_random(250, 350) * 0.01 event.cause.surface.create_entity({name = "flying-text", position = event.entity.position, text = "‼" .. math.floor(damage), color = {255, 0, 0}}) @@ -669,6 +723,26 @@ local function on_entity_damaged(event) event.cause.player.create_local_flying_text({text = math.floor(damage), position = event.entity.position, color = {150, 150, 150}, time_to_live = 90, speed = 2}) end + --Handle the custom health pool of the biter health booster, if it is used in the map. + if global.biter_health_boost then + local health_pool = global.biter_health_boost_units[event.entity.unit_number] + if health_pool then + health_pool[1] = health_pool[1] + event.final_damage_amount + health_pool[1] = health_pool[1] - damage + + --Set entity health relative to health pool + event.entity.health = health_pool[1] * health_pool[2] + + if health_pool[1] <= 0 then + global.biter_health_boost_units[event.entity.unit_number] = nil + event.entity.die(event.entity.force.name, event.cause) + end + return + end + end + + --Handle vanilla damage. + event.entity.health = event.entity.health + event.final_damage_amount event.entity.health = event.entity.health - damage if event.entity.health <= 0 then event.entity.die(event.entity.force.name, event.cause) @@ -685,8 +759,8 @@ end local function on_player_rotated_entity(event) local player = game.players[event.player_index] if not player.character then return end - if global.rpg[player.index].rotated_entity_delay > game.tick then return end - global.rpg[player.index].rotated_entity_delay = game.tick + 20 + if rpg_t[player.index].rotated_entity_delay > game.tick then return end + rpg_t[player.index].rotated_entity_delay = game.tick + 20 gain_xp(player, 0.20) end @@ -708,9 +782,9 @@ local function on_pre_player_mined_item(event) if not event.entity.valid then return end if building_and_mining_blacklist[event.entity.type] then return end local player = game.players[event.player_index] - if global.rpg[player.index].last_mined_entity_position.x == event.entity.position.x and global.rpg[player.index].last_mined_entity_position.y == event.entity.position.y then return end - global.rpg[player.index].last_mined_entity_position.x = event.entity.position.x - global.rpg[player.index].last_mined_entity_position.y = event.entity.position.y + if rpg_t[player.index].last_mined_entity_position.x == event.entity.position.x and rpg_t[player.index].last_mined_entity_position.y == event.entity.position.y then return end + rpg_t[player.index].last_mined_entity_position.x = event.entity.position.x + rpg_t[player.index].last_mined_entity_position.y = event.entity.position.y if event.entity.type == "resource" then gain_xp(player, 0.5) return end if event.entity.force.name == "neutral" then gain_xp(player, 1.5 + event.entity.prototype.max_health * 0.0035) return end gain_xp(player, 0.1 + event.entity.prototype.max_health * 0.0005) @@ -731,14 +805,14 @@ end local function on_player_respawned(event) local player = game.players[event.player_index] - if not global.rpg[player.index] then rpg_reset_player(player) return end + if not rpg_t[player.index] then Public.rpg_reset_player(player) return end update_player_stats(player) draw_level_text(player) end local function on_player_joined_game(event) local player = game.players[event.player_index] - if not global.rpg[player.index] then rpg_reset_player(player) end + if not rpg_t[player.index] then Public.rpg_reset_player(player) end for _, p in pairs(game.connected_players) do draw_level_text(p) end @@ -748,13 +822,7 @@ local function on_player_joined_game(event) end local function on_init(event) - global.rpg = {} - global.rpg_frame_icons = { - "entity/small-worm-turret", "entity/medium-worm-turret", "entity/big-worm-turret", "entity/behemoth-worm-turret", - "entity/small-biter", "entity/small-biter", "entity/small-spitter", "entity/medium-biter", "entity/medium-biter", - "entity/medium-spitter", "entity/big-biter", "entity/big-biter", "entity/big-spitter", "entity/behemoth-biter", "entity/behemoth-biter", "entity/behemoth-spitter" - } - table.shuffle_table(global.rpg_frame_icons) + table.shuffle_table(rpg_frame_icons) end local event = require 'utils.event' @@ -769,4 +837,6 @@ event.add(defines.events.on_player_joined_game, on_player_joined_game) event.add(defines.events.on_player_repaired_entity, on_player_repaired_entity) event.add(defines.events.on_player_respawned, on_player_respawned) event.add(defines.events.on_player_rotated_entity, on_player_rotated_entity) -event.add(defines.events.on_pre_player_mined_item, on_pre_player_mined_item) \ No newline at end of file +event.add(defines.events.on_pre_player_mined_item, on_pre_player_mined_item) + +return Public \ No newline at end of file diff --git a/modules/satellite_score.lua b/modules/satellite_score.lua index 2b3fb702..43bef7a4 100644 --- a/modules/satellite_score.lua +++ b/modules/satellite_score.lua @@ -1,6 +1,7 @@ -- level up ranks with launching satellites -- by mewmew local event = require 'utils.event' +local Server = require 'utils.server' local function get_rank() for i = #global.satellite_score, 1, -1 do @@ -83,7 +84,7 @@ local function on_rocket_launched(event) if (global.satellites_in_space < 10) or ((global.satellites_in_space < 50) and ((global.satellites_in_space % 5) == 0)) or ((global.satellites_in_space % 25) == 0) then local message = 'A satellite has been launched! Total count: ' .. global.satellites_in_space game.print(message) - server_commands.to_discord_embed(message) + Server.to_discord_embed(message) end end diff --git a/modules/trees_randomly_die.lua b/modules/trees_randomly_die.lua index 2d5fda3b..4fd4b6d7 100644 --- a/modules/trees_randomly_die.lua +++ b/modules/trees_randomly_die.lua @@ -81,7 +81,7 @@ local function kill_random_tree(surface) end local function tick(event) - local r = 16 + local r = 48 if global.difficulty_vote_index then r = difficulties_votes[global.difficulty_vote_index] end if math_random(1, r) ~= 1 then return end local surface = game.players[1].surface diff --git a/modules/wave_defense/biter_rolls.lua b/modules/wave_defense/biter_rolls.lua index 0b4657c5..2bdb685b 100644 --- a/modules/wave_defense/biter_rolls.lua +++ b/modules/wave_defense/biter_rolls.lua @@ -1,94 +1,105 @@ -function wave_defense_roll_biter_name() +local WD = require "modules.wave_defense.table" + +local Public = {} + +function Public.wave_defense_roll_biter_name() + local wave_defense_table = WD.get_table() local max_chance = 0 - for k, v in pairs(global.wave_defense.biter_raffle) do + for k, v in pairs(wave_defense_table.biter_raffle) do max_chance = max_chance + v end - local r = math.random(1, max_chance) + local r = math.random(0, math.floor(max_chance)) local current_chance = 0 - for k, v in pairs(global.wave_defense.biter_raffle) do + for k, v in pairs(wave_defense_table.biter_raffle) do current_chance = current_chance + v if r <= current_chance then return k end end end -function wave_defense_roll_spitter_name() +function Public.wave_defense_roll_spitter_name() + local wave_defense_table = WD.get_table() local max_chance = 0 - for k, v in pairs(global.wave_defense.spitter_raffle) do + for k, v in pairs(wave_defense_table.spitter_raffle) do max_chance = max_chance + v end - local r = math.random(1, max_chance) + local r = math.random(0, math.floor(max_chance)) local current_chance = 0 - for k, v in pairs(global.wave_defense.spitter_raffle) do + for k, v in pairs(wave_defense_table.spitter_raffle) do current_chance = current_chance + v if r <= current_chance then return k end end end -function wave_defense_set_unit_raffle(level) - global.wave_defense.biter_raffle = { +function Public.wave_defense_set_unit_raffle(level) + local wave_defense_table = WD.get_table() + wave_defense_table.biter_raffle = { ["small-biter"] = 1000 - level * 1.75, ["medium-biter"] = level, ["big-biter"] = 0, ["behemoth-biter"] = 0, } - global.wave_defense.spitter_raffle = { + wave_defense_table.spitter_raffle = { ["small-spitter"] = 1000 - level * 1.75, ["medium-spitter"] = level, ["big-spitter"] = 0, ["behemoth-spitter"] = 0, } if level > 500 then - global.wave_defense.biter_raffle["medium-biter"] = 500 - (level - 500) - global.wave_defense.spitter_raffle["medium-spitter"] = 500 - (level - 500) - global.wave_defense.biter_raffle["big-biter"] = (level - 500) * 2 - global.wave_defense.spitter_raffle["big-spitter"] = (level - 500) * 2 + wave_defense_table.biter_raffle["medium-biter"] = 500 - (level - 500) + wave_defense_table.spitter_raffle["medium-spitter"] = 500 - (level - 500) + wave_defense_table.biter_raffle["big-biter"] = (level - 500) * 2 + wave_defense_table.spitter_raffle["big-spitter"] = (level - 500) * 2 end if level > 800 then - global.wave_defense.biter_raffle["behemoth-biter"] = (level - 800) * 3 - global.wave_defense.spitter_raffle["behemoth-spitter"] = (level - 800) * 3 + wave_defense_table.biter_raffle["behemoth-biter"] = (level - 800) * 3 + wave_defense_table.spitter_raffle["behemoth-spitter"] = (level - 800) * 3 end - for k, v in pairs(global.wave_defense.biter_raffle) do - if global.wave_defense.biter_raffle[k] < 0 then global.wave_defense.biter_raffle[k] = 0 end + for k, v in pairs(wave_defense_table.biter_raffle) do + if wave_defense_table.biter_raffle[k] < 0 then wave_defense_table.biter_raffle[k] = 0 end end - for k, v in pairs(global.wave_defense.spitter_raffle) do - if global.wave_defense.spitter_raffle[k] < 0 then global.wave_defense.spitter_raffle[k] = 0 end + for k, v in pairs(wave_defense_table.spitter_raffle) do + if wave_defense_table.spitter_raffle[k] < 0 then wave_defense_table.spitter_raffle[k] = 0 end end end -function wave_defense_roll_worm_name() +function Public.wave_defense_roll_worm_name() + local wave_defense_table = WD.get_table() local max_chance = 0 - for k, v in pairs(global.wave_defense.worm_raffle) do + for k, v in pairs(wave_defense_table.worm_raffle) do max_chance = max_chance + v end - local r = math.random(1, max_chance) + local r = math.random(0, math.floor(max_chance)) local current_chance = 0 - for k, v in pairs(global.wave_defense.worm_raffle) do + for k, v in pairs(wave_defense_table.worm_raffle) do current_chance = current_chance + v if r <= current_chance then return k end end end -function wave_defense_set_worm_raffle(level) - global.wave_defense.worm_raffle = { +function Public.wave_defense_set_worm_raffle(level) + local wave_defense_table = WD.get_table() + wave_defense_table.worm_raffle = { ["small-worm-turret"] = 1000 - level * 1.75, ["medium-worm-turret"] = level, ["big-worm-turret"] = 0, ["behemoth-worm-turret"] = 0, } if level > 500 then - global.wave_defense.worm_raffle["medium-worm-turret"] = 500 - (level - 500) - global.wave_defense.worm_raffle["big-worm-turret"] = (level - 500) * 2 + wave_defense_table.worm_raffle["medium-worm-turret"] = 500 - (level - 500) + wave_defense_table.worm_raffle["big-worm-turret"] = (level - 500) * 2 end if level > 800 then - global.wave_defense.worm_raffle["behemoth-worm-turret"] = (level - 800) * 3 + wave_defense_table.worm_raffle["behemoth-worm-turret"] = (level - 800) * 3 end - for k, v in pairs(global.wave_defense.worm_raffle) do - if global.wave_defense.worm_raffle[k] < 0 then global.wave_defense.worm_raffle[k] = 0 end + for k, v in pairs(wave_defense_table.worm_raffle) do + if wave_defense_table.worm_raffle[k] < 0 then wave_defense_table.worm_raffle[k] = 0 end end end -function wave_defense_print_chances(tbl) +function Public.wave_defense_print_chances(tbl) for k, v in pairs(tbl) do game.print(k .. " chance = " .. v) end -end \ No newline at end of file +end + +return Public \ No newline at end of file diff --git a/modules/wave_defense/gui.lua b/modules/wave_defense/gui.lua index 6f2918a8..f33e856e 100644 --- a/modules/wave_defense/gui.lua +++ b/modules/wave_defense/gui.lua @@ -1,3 +1,5 @@ +local WD = require "modules.wave_defense.table" + local function create_gui(player) local frame = player.gui.top.add({ type = "frame", name = "wave_defense"}) frame.style.maximal_height = 38 @@ -18,23 +20,58 @@ local function create_gui(player) local line = frame.add({type = "line", direction = "vertical"}) line.style.left_padding = 4 line.style.right_padding = 4 - + local label = frame.add({ type = "label", caption = " ", name = "threat", tooltip = "high threat may empower biters"}) - label.style.font_color = {r=0.88, g=0.88, b=0.88} label.style.font = "default-bold" label.style.left_padding = 4 - label.style.right_padding = 4 + label.style.right_padding = 1 label.style.minimal_width = 10 - label.style.font_color = {r=0.99, g=0.0, b=0.5} + label.style.font_color = {r = 150, g = 0, b = 255} + + local label = frame.add({ type = "label", caption = " ", name = "threat_gains", tooltip = "gain / minute"}) + label.style.font = "default" + label.style.left_padding = 1 + label.style.right_padding = 1 +end + +--display threat gain/loss per minute during last 15 minutes +local function get_threat_gain() + local wave_defense_table = WD.get_table() + local past_index = wave_defense_table.threat_log_index - 900 + if past_index < 1 then past_index = 1 end + local gain = math.floor((wave_defense_table.threat_log[wave_defense_table.threat_log_index] - wave_defense_table.threat_log[past_index]) / 15) + return gain end local function update_gui(player) + local wave_defense_table = WD.get_table() if not player.gui.top.wave_defense then create_gui(player) end - player.gui.top.wave_defense.label.caption = "Wave: " .. global.wave_defense.wave_number - if global.wave_defense.wave_number == 0 then player.gui.top.wave_defense.label.caption = "First wave in " .. math.floor((global.wave_defense.next_wave - game.tick) / 60) + 1 end - local interval = global.wave_defense.next_wave - global.wave_defense.last_wave - player.gui.top.wave_defense.progressbar.value = 1 - (global.wave_defense.next_wave - game.tick) / interval - player.gui.top.wave_defense.threat.caption = "Threat: " .. math.floor(global.wave_defense.threat) + player.gui.top.wave_defense.label.caption = "Wave: " .. wave_defense_table.wave_number + if wave_defense_table.wave_number == 0 then player.gui.top.wave_defense.label.caption = "First wave in " .. math.floor((wave_defense_table.next_wave - game.tick) / 60) + 1 end + local interval = wave_defense_table.next_wave - wave_defense_table.last_wave + player.gui.top.wave_defense.progressbar.value = 1 - (wave_defense_table.next_wave - game.tick) / interval + + player.gui.top.wave_defense.threat.caption = "Threat: " .. math.floor(wave_defense_table.threat) + + if wave_defense_table.wave_number == 0 then + player.gui.top.wave_defense.threat_gains.caption = "" + return + end + + local gain = get_threat_gain() + local d = wave_defense_table.wave_number / 75 + + if gain >= 0 then + player.gui.top.wave_defense.threat_gains.caption = " (+" .. gain .. ")" + local g = 255 - math.floor(gain / d) + if g < 0 then g = 0 end + player.gui.top.wave_defense.threat_gains.style.font_color = {255, g, 0} + else + player.gui.top.wave_defense.threat_gains.caption = " (" .. gain .. ")" + local r = 255 - math.floor(math.abs(gain) / d) + if r < 0 then r = 0 end + player.gui.top.wave_defense.threat_gains.style.font_color = {r, 255, 0} + end end return update_gui \ No newline at end of file diff --git a/modules/wave_defense/main.lua b/modules/wave_defense/main.lua index 0c825a93..c891e243 100644 --- a/modules/wave_defense/main.lua +++ b/modules/wave_defense/main.lua @@ -1,209 +1,152 @@ require "modules.biter_health_booster" -require "modules.wave_defense.biter_rolls" -require "modules.wave_defense.threat_events" +local BiterRolls = require "modules.wave_defense.biter_rolls" +local SideTargets = require "modules.wave_defense.side_targets" +local ThreatEvent = require "modules.wave_defense.threat_events" local update_gui = require "modules.wave_defense.gui" local threat_values = require "modules.wave_defense.threat_values" -local math_random = math.random -local side_target_types = {"accumulator", "assembling-machine", "beacon", "boiler", "container", "furnace", "lamp", "lab", "logistic-container", "mining-drill", "container", "pump", "radar", "reactor", "roboport", "rocket-silo", "solar-panel", "storage-tank",} ---local side_target_types = {"assembling-machine", "electric-pole", "furnace", "mining-drill", "pump", "radar", "reactor", "roboport"} +local WD = require "modules.wave_defense.table" +local event = require 'utils.event' +local Public = {} local function debug_print(msg) - if not global.wave_defense.debug then return end - print("WaveDefense: " .. msg) + local wave_defense_table = WD.get_table() + if not wave_defense_table.debug then return end + print("WaveDefense: " .. msg) end local function is_unit_valid(biter) + local wave_defense_table = WD.get_table() if not biter.entity then debug_print("is_unit_valid - unit destroyed - does no longer exist") return false end if not biter.entity.valid then debug_print("is_unit_valid - unit destroyed - invalid") return false end if not biter.entity.unit_group then debug_print("is_unit_valid - unit destroyed - no unitgroup") return false end - if biter.spawn_tick + global.wave_defense.max_biter_age < game.tick then debug_print("is_unit_valid - unit destroyed - timed out") return false end + if biter.spawn_tick + wave_defense_table.max_biter_age < game.tick then debug_print("is_unit_valid - unit destroyed - timed out") return false end return true end local function refresh_active_unit_threat() - debug_print("refresh_active_unit_threat - current value " .. global.wave_defense.active_biter_threat) + local wave_defense_table = WD.get_table() + debug_print("refresh_active_unit_threat - current value " .. wave_defense_table.active_biter_threat) local active_biter_threat = 0 - for k, biter in pairs(global.wave_defense.active_biters) do + for k, biter in pairs(wave_defense_table.active_biters) do if biter.entity then if biter.entity.valid then active_biter_threat = active_biter_threat + threat_values[biter.entity.name] end end end - global.wave_defense.active_biter_threat = math.round(active_biter_threat * global.biter_health_boost, 2) - debug_print("refresh_active_unit_threat - new value " .. global.wave_defense.active_biter_threat) + wave_defense_table.active_biter_threat = math.round(active_biter_threat * global.biter_health_boost, 2) + debug_print("refresh_active_unit_threat - new value " .. wave_defense_table.active_biter_threat) end local function time_out_biters() - for k, biter in pairs(global.wave_defense.active_biters) do + local wave_defense_table = WD.get_table() + for k, biter in pairs(wave_defense_table.active_biters) do if not is_unit_valid(biter) then - global.wave_defense.active_biter_count = global.wave_defense.active_biter_count - 1 + wave_defense_table.active_biter_count = wave_defense_table.active_biter_count - 1 if biter.entity then if biter.entity.valid then - global.wave_defense.active_biter_threat = global.wave_defense.active_biter_threat - math.round(threat_values[biter.entity.name] * global.biter_health_boost, 2) + wave_defense_table.active_biter_threat = wave_defense_table.active_biter_threat - math.round(threat_values[biter.entity.name] * global.biter_health_boost, 2) if biter.entity.force.index == 2 then biter.entity.destroy() end end end - global.wave_defense.active_biters[k] = nil + wave_defense_table.active_biters[k] = nil end end end local function get_random_close_spawner(surface) - local spawners = surface.find_entities_filtered({type = "unit-spawner"}) + local wave_defense_table = WD.get_table() + local spawners = surface.find_entities_filtered({type = "unit-spawner"}) if not spawners[1] then return false end - local center = global.wave_defense.target.position - local spawner = spawners[math_random(1,#spawners)] - for i = 1, global.wave_defense.get_random_close_spawner_attempts, 1 do - local spawner_2 = spawners[math_random(1,#spawners)] - if (center.x - spawner_2.position.x) ^ 2 + (center.y - spawner_2.position.y) ^ 2 < (center.x - spawner.position.x) ^ 2 + (center.y - spawner.position.y) ^ 2 then spawner = spawner_2 end - end + local center = wave_defense_table.target.position + local spawner = spawners[math.random(1,#spawners)] + for i = 1, wave_defense_table.get_random_close_spawner_attempts, 1 do + local spawner_2 = spawners[math.random(1,#spawners)] + if (center.x - spawner_2.position.x) ^ 2 + (center.y - spawner_2.position.y) ^ 2 < (center.x - spawner.position.x) ^ 2 + (center.y - spawner.position.y) ^ 2 then spawner = spawner_2 end + end debug_print("get_random_close_spawner - Found at x" .. spawner.position.x .. " y" .. spawner.position.y) return spawner end -local function set_side_target_list() - local surface = game.surfaces[global.wave_defense.surface_index] - local position = false - local force = false - - if global.wave_defense.target then - if global.wave_defense.target.valid then - position = global.wave_defense.target.position - force = global.wave_defense.target.force - end - end - - if not position then - local r = math_random(1, #game.connected_players) - position = {x = game.connected_players[r].position.x, y = game.connected_players[r].position.y} - force = game.connected_players[r].force - end - - global.wave_defense.side_targets = surface.find_entities_filtered({ - area = { - {position.x - global.wave_defense.side_target_search_radius, position.y - global.wave_defense.side_target_search_radius}, - {position.x + global.wave_defense.side_target_search_radius, position.y + global.wave_defense.side_target_search_radius} - }, - force = force, - type = side_target_types, - }) - - debug_print("set_side_target_list -- " .. #global.wave_defense.side_targets .. " targets around position x" .. position.x .. " y" .. position.y .. " saved.") -end - -local function get_side_target() - if not global.wave_defense.side_targets then return false end - if #global.wave_defense.side_targets < 2 then return false end - local side_target = global.wave_defense.side_targets[math_random(1,#global.wave_defense.side_targets)] - if not side_target then return false end - if not side_target.valid then return false end - for _ = 1, 4, 1 do - local new_target = global.wave_defense.side_targets[math_random(1,#global.wave_defense.side_targets)] - if new_target then - if new_target.valid then - local side_target_distance = (global.wave_defense.target.position.x - side_target.position.x) ^ 2 + (global.wave_defense.target.position.y - side_target.position.y) ^ 2 - local new_target_distance = (global.wave_defense.target.position.x - new_target.position.x) ^ 2 + (global.wave_defense.target.position.y - new_target.position.y) ^ 2 - if new_target_distance > side_target_distance then side_target = new_target end - end - end - end - debug_print("get_side_target -- " .. side_target.name .. " at position x" .. side_target.position.x .. " y" .. side_target.position.y .. " selected.") - return side_target -end - ---[[ local function set_main_target() - if global.wave_defense.target then - if global.wave_defense.target.valid then return end + local wave_defense_table = WD.get_table() + if wave_defense_table.target then + if wave_defense_table.target.valid then return end end - local characters = {} - for i = 1, #game.connected_players, 1 do - if game.connected_players[i].character then - if game.connected_players[i].character.valid then - if game.connected_players[i].surface.index == global.wave_defense.surface_index then - characters[#characters + 1] = game.connected_players[i].character - end - end - end - end - if #characters == 0 then return end - global.wave_defense.target = characters[math_random(1, #characters)] -end -]] - -local function set_main_target() - if global.wave_defense.target then - if global.wave_defense.target.valid then return end - end - if not global.wave_defense.side_targets then return end - if #global.wave_defense.side_targets == 0 then return end - local target = global.wave_defense.side_targets[math_random(1, #global.wave_defense.side_targets)] + if not wave_defense_table.side_targets then return end + if #wave_defense_table.side_targets == 0 then return end + local target = wave_defense_table.side_targets[math.random(1, #wave_defense_table.side_targets)] if not target then return end - if not target.valid then return end - global.wave_defense.target = target + if not target.valid then return end + wave_defense_table.target = target debug_print("set_main_target -- New main target " .. target.name .. " at position x" .. target.position.x .. " y" .. target.position.y .. " selected.") end local function set_group_spawn_position(surface) + local wave_defense_table = WD.get_table() local spawner = get_random_close_spawner(surface) if not spawner then return end - local position = surface.find_non_colliding_position("rocket-silo", spawner.position, 48, 1) - if not position then return end - global.wave_defense.spawn_position = {x = math.floor(position.x), y = math.floor(position.y)} - debug_print("set_group_spawn_position -- Changed position to x" .. global.wave_defense.spawn_position.x .. " y" .. global.wave_defense.spawn_position.y .. ".") + local position = surface.find_non_colliding_position("electric-furnace", spawner.position, 64, 1) + if not position then return end + wave_defense_table.spawn_position = {x = position.x, y = position.y} + debug_print("set_group_spawn_position -- Changed position to x" .. wave_defense_table.spawn_position.x .. " y" .. wave_defense_table.spawn_position.y .. ".") end local function set_enemy_evolution() - local evolution_factor = global.wave_defense.wave_number * 0.001 + local wave_defense_table = WD.get_table() + local evolution_factor = wave_defense_table.wave_number * 0.001 local biter_health_boost = 1 --local damage_increase = 0 - + if evolution_factor > 1 then --damage_increase = damage_increase + (evolution_factor - 1) --biter_health_boost = biter_health_boost + (evolution_factor - 1) * 2 evolution_factor = 1 end - if global.wave_defense.threat > 0 then - biter_health_boost = math.round(biter_health_boost + global.wave_defense.threat * 0.00005, 3) - --damage_increase = math.round(damage_increase + global.wave_defense.threat * 0.0000025, 3) + if wave_defense_table.threat > 50000 then + biter_health_boost = math.round(biter_health_boost + (wave_defense_table.threat - 50000) * 0.000033, 3) + --damage_increase = math.round(damage_increase + wave_defense_table.threat * 0.0000025, 3) end global.biter_health_boost = biter_health_boost --game.forces.enemy.set_ammo_damage_modifier("melee", damage_increase) --game.forces.enemy.set_ammo_damage_modifier("biological", damage_increase) game.forces.enemy.evolution_factor = evolution_factor - + if global.biter_health_boost then - for _, player in pairs(game.connected_players) do + for _, player in pairs(game.connected_players) do --player.gui.top.wave_defense.threat.tooltip = "High threat may empower biters.\nBiter health " .. biter_health_boost * 100 .. "% | damage " .. (damage_increase + 1) * 100 .. "%" - player.gui.top.wave_defense.threat.tooltip = "High threat may empower biters.\nBiter health " .. biter_health_boost * 100 .. "%" + if player.gui.top.wave_defense then + player.gui.top.wave_defense.threat.tooltip = "High threat may empower biters.\nBiter health " .. biter_health_boost * 100 .. "%" + end end end end local function can_units_spawn() - if global.wave_defense.threat <= 0 then + local wave_defense_table = WD.get_table() + if wave_defense_table.threat <= 0 then debug_print("can_units_spawn - threat too low") - return false + return false end - if global.wave_defense.active_biter_count >= global.wave_defense.max_active_biters then + if wave_defense_table.active_biter_count >= wave_defense_table.max_active_biters then debug_print("can_units_spawn - active biter count too high") - return false + return false end - if global.wave_defense.active_biter_threat >= global.wave_defense.threat then - debug_print("can_units_spawn - active biter threat too high (" .. global.wave_defense.active_biter_threat .. ")") - return false + if wave_defense_table.active_biter_threat >= wave_defense_table.threat then + debug_print("can_units_spawn - active biter threat too high (" .. wave_defense_table.active_biter_threat .. ")") + return false end return true end local function get_active_unit_groups_count() + local wave_defense_table = WD.get_table() local count = 0 - for _, g in pairs(global.wave_defense.unit_groups) do + for _, g in pairs(wave_defense_table.unit_groups) do if g.valid then if #g.members > 0 then count = count + 1 @@ -217,84 +160,63 @@ local function get_active_unit_groups_count() end local function spawn_biter(surface) + local wave_defense_table = WD.get_table() if not can_units_spawn() then return end - + local name if math.random(1,100) > 73 then - name = wave_defense_roll_spitter_name() + name = BiterRolls.wave_defense_roll_spitter_name() else - name = wave_defense_roll_biter_name() + name = BiterRolls.wave_defense_roll_biter_name() end - local position = surface.find_non_colliding_position(name, global.wave_defense.spawn_position, 48, 2) - if not position then return false end - local biter = surface.create_entity({name = name, position = position, force = "enemy"}) + --local position = surface.find_non_colliding_position(name, wave_defense_table.spawn_position, 48, 2) + --if not position then return false end + local biter = surface.create_entity({name = name, position = wave_defense_table.spawn_position, force = "enemy"}) biter.ai_settings.allow_destroy_when_commands_fail = false biter.ai_settings.allow_try_return_to_spawner = false - global.wave_defense.active_biters[biter.unit_number] = {entity = biter, spawn_tick = game.tick} - global.wave_defense.active_biter_count = global.wave_defense.active_biter_count + 1 - global.wave_defense.active_biter_threat = global.wave_defense.active_biter_threat + math.round(threat_values[name] * global.biter_health_boost, 2) + wave_defense_table.active_biters[biter.unit_number] = {entity = biter, spawn_tick = game.tick} + wave_defense_table.active_biter_count = wave_defense_table.active_biter_count + 1 + wave_defense_table.active_biter_threat = wave_defense_table.active_biter_threat + math.round(threat_values[name] * global.biter_health_boost, 2) return biter end -local function spawn_unit_group() - if not can_units_spawn() then return end - if not global.wave_defense.target then return end - if not global.wave_defense.target.valid then return end - if get_active_unit_groups_count() >= global.wave_defense.max_active_unit_groups then return end - - wave_defense_set_unit_raffle(global.wave_defense.wave_number) - - local surface = game.surfaces[global.wave_defense.surface_index] - set_group_spawn_position(surface) - debug_print("Spawning unit group at x" .. global.wave_defense.spawn_position.x .." y" .. global.wave_defense.spawn_position.y) - local unit_group = surface.create_unit_group({position = global.wave_defense.spawn_position, force = "enemy"}) - for a = 1, global.wave_defense.group_size, 1 do - local biter = spawn_biter(surface) - if not biter then break end - unit_group.add_member(biter) - end - for i = 1, #global.wave_defense.unit_groups, 1 do - if not global.wave_defense.unit_groups[i] then - global.wave_defense.unit_groups[i] = unit_group - return true - end - end - global.wave_defense.unit_groups[#global.wave_defense.unit_groups + 1] = unit_group - return true -end - local function set_next_wave() - global.wave_defense.wave_number = global.wave_defense.wave_number + 1 - global.wave_defense.group_size = global.wave_defense.wave_number * 2 - if global.wave_defense.group_size > global.wave_defense.max_group_size then global.wave_defense.group_size = global.wave_defense.max_group_size end - global.wave_defense.threat = global.wave_defense.threat + math.floor(global.wave_defense.wave_number * global.wave_defense.threat_gain_multiplier) - global.wave_defense.last_wave = global.wave_defense.next_wave - global.wave_defense.next_wave = game.tick + global.wave_defense.wave_interval + local wave_defense_table = WD.get_table() + wave_defense_table.wave_number = wave_defense_table.wave_number + 1 + wave_defense_table.group_size = wave_defense_table.wave_number * 2 + if wave_defense_table.group_size > wave_defense_table.max_group_size then wave_defense_table.group_size = wave_defense_table.max_group_size end + + local threat_gain = wave_defense_table.wave_number * wave_defense_table.threat_gain_multiplier + if wave_defense_table.wave_number > 1000 then + threat_gain = threat_gain * (wave_defense_table.wave_number * 0.001) + end + + wave_defense_table.threat = wave_defense_table.threat + math.floor(threat_gain) + wave_defense_table.last_wave = wave_defense_table.next_wave + wave_defense_table.next_wave = game.tick + wave_defense_table.wave_interval end local function get_commmands(group) + local wave_defense_table = WD.get_table() local commands = {} local group_position = {x = group.position.x, y = group.position.y} - local step_length = global.wave_defense.unit_group_command_step_length - - if math_random(1,3) ~= 1 then - local side_target = false - for _ = 1, 3, 1 do - side_target = get_side_target() - if side_target then break end - end + local step_length = wave_defense_table.unit_group_command_step_length + + if math.random(1,2) == 1 then + local side_target = SideTargets.get_side_target() if side_target then - local target_position = side_target.position + debug_print("get_side_target -- " .. side_target.name .. " at position x" .. side_target.position.x .. " y" .. side_target.position.y .. " selected.") + local target_position = side_target.position local distance_to_target = math.floor(math.sqrt((target_position.x - group_position.x) ^ 2 + (target_position.y - group_position.y) ^ 2)) local steps = math.floor(distance_to_target / step_length) + 1 local vector = {math.round((target_position.x - group_position.x) / steps, 3), math.round((target_position.y - group_position.y) / steps, 3)} - - if global.wave_defense.debug then + + if wave_defense_table.debug then debug_print("get_commmands - to side_target x" .. side_target.position.x .. " y" .. side_target.position.y) debug_print("get_commmands - distance_to_target:" .. distance_to_target .. " steps:" .. steps) debug_print("get_commmands - vector " .. vector[1] .. "_" .. vector[2]) end - + for i = 1, steps, 1 do group_position.x = group_position.x + vector[1] group_position.y = group_position.y + vector[2] @@ -306,31 +228,31 @@ local function get_commmands(group) radius = 16, distraction = defines.distraction.by_anything } - end + end end - + commands[#commands + 1] = { type = defines.command.attack, target = side_target, distraction = defines.distraction.by_enemy, - } + } end end - - local target_position = global.wave_defense.target.position + + local target_position = wave_defense_table.target.position local distance_to_target = math.floor(math.sqrt((target_position.x - group_position.x) ^ 2 + (target_position.y - group_position.y) ^ 2)) local steps = math.floor(distance_to_target / step_length) + 1 local vector = {math.round((target_position.x - group_position.x) / steps, 3), math.round((target_position.y - group_position.y) / steps, 3)} - - if global.wave_defense.debug then + + if wave_defense_table.debug then debug_print("get_commmands - to main target x" .. target_position.x .. " y" .. target_position.y) debug_print("get_commmands - distance_to_target:" .. distance_to_target .. " steps:" .. steps) debug_print("get_commmands - vector " .. vector[1] .. "_" .. vector[2]) end - + for i = 1, steps, 1 do group_position.x = group_position.x + vector[1] - group_position.y = group_position.y + vector[2] + group_position.y = group_position.y + vector[2] local position = group.surface.find_non_colliding_position("small-biter", group_position, step_length, 1) if position then commands[#commands + 1] = { @@ -339,50 +261,85 @@ local function get_commmands(group) radius = 16, distraction = defines.distraction.by_anything } - end + end end - + commands[#commands + 1] = { type = defines.command.attack_area, destination = {x = target_position.x, y = target_position.y}, radius = 8, distraction = defines.distraction.by_enemy } - + commands[#commands + 1] = { type = defines.command.attack, - target = global.wave_defense.target, + target = wave_defense_table.target, distraction = defines.distraction.by_enemy, } - + return commands end local function command_unit_group(group) - if not global.wave_defense.unit_group_last_command[group.group_number] then - global.wave_defense.unit_group_last_command[group.group_number] = game.tick - (global.wave_defense.unit_group_command_delay + 1) + local wave_defense_table = WD.get_table() + if not wave_defense_table.unit_group_last_command[group.group_number] then + wave_defense_table.unit_group_last_command[group.group_number] = game.tick - (wave_defense_table.unit_group_command_delay + 1) + end + if wave_defense_table.unit_group_last_command[group.group_number] then + if wave_defense_table.unit_group_last_command[group.group_number] + wave_defense_table.unit_group_command_delay > game.tick then return end end - if global.wave_defense.unit_group_last_command[group.group_number] + global.wave_defense.unit_group_command_delay > game.tick then return end - global.wave_defense.unit_group_last_command[group.group_number] = game.tick group.set_command({ type = defines.command.compound, structure_type = defines.compound_command.return_last, commands = get_commmands(group) }) + + wave_defense_table.unit_group_last_command[group.group_number] = game.tick end local function give_commands_to_unit_groups() - if #global.wave_defense.unit_groups == 0 then return end - if not global.wave_defense.target then return end - if not global.wave_defense.target.valid then return end - for k, group in pairs(global.wave_defense.unit_groups) do + local wave_defense_table = WD.get_table() + if #wave_defense_table.unit_groups == 0 then return end + if not wave_defense_table.target then return end + if not wave_defense_table.target.valid then return end + for k, group in pairs(wave_defense_table.unit_groups) do if group.valid then command_unit_group(group) else - global.wave_defense.unit_groups[k] = nil + table.remove(wave_defense_table.unit_groups, k) + --wave_defense_table.unit_groups[k] = nil end + end +end + +local function spawn_unit_group() + local wave_defense_table = WD.get_table() + if not can_units_spawn() then return end + if not wave_defense_table.target then return end + if not wave_defense_table.target.valid then return end + if get_active_unit_groups_count() >= wave_defense_table.max_active_unit_groups then return end + + BiterRolls.wave_defense_set_unit_raffle(wave_defense_table.wave_number) + + local surface = game.surfaces[wave_defense_table.surface_index] + set_group_spawn_position(surface) + debug_print("Spawning unit group at x" .. wave_defense_table.spawn_position.x .." y" .. wave_defense_table.spawn_position.y) + local unit_group = surface.create_unit_group({position = wave_defense_table.spawn_position, force = "enemy"}) + for a = 1, wave_defense_table.group_size, 1 do + local biter = spawn_biter(surface) + if not biter then break end + unit_group.add_member(biter) end + table.insert(wave_defense_table.unit_groups, unit_group) + return true +end + +local function log_threat() + local wave_defense_table = WD.get_table() + wave_defense_table.threat_log_index = wave_defense_table.threat_log_index + 1 + wave_defense_table.threat_log[wave_defense_table.threat_log_index] = wave_defense_table.threat + if wave_defense_table.threat_log_index > 900 then wave_defense_table.threat_log[wave_defense_table.threat_log_index - 901] = nil end end local tick_tasks = { @@ -390,65 +347,32 @@ local tick_tasks = { [60] = set_enemy_evolution, [90] = spawn_unit_group, [120] = give_commands_to_unit_groups, - [150] = build_nest, - [180] = build_worm, - [1800] = set_side_target_list, + [150] = ThreatEvent.build_nest, + [180] = ThreatEvent.build_worm, [3600] = time_out_biters, [7200] = refresh_active_unit_threat, } local function on_tick() - if global.wave_defense.game_lost then return end - - for _, player in pairs(game.connected_players) do update_gui(player) end - - if game.tick > global.wave_defense.next_wave then set_next_wave() end + local wave_defense_table = WD.get_table() + if wave_defense_table.game_lost then return end + + if game.tick > wave_defense_table.next_wave then set_next_wave() end local t = game.tick % 300 local t2 = game.tick % 18000 - + if tick_tasks[t] then tick_tasks[t]() end if tick_tasks[t2] then tick_tasks[t2]() end -end - -function reset_wave_defense() - global.wave_defense = { - active_biter_count = 0, - active_biter_threat = 0, - active_biters = {}, - debug = false, - game_lost = false, - get_random_close_spawner_attempts = 5, - group_size = 2, - last_wave = game.tick, - max_active_biters = 1024, - max_active_unit_groups = 6, - max_biter_age = 3600 * 60, - max_group_size = 192, - nest_building_chance = 4, --high value = less chance - nest_building_density = 64, --lower values = more dense building - next_wave = game.tick + 3600 * 15, - side_target_search_radius = 768, - simple_entity_shredding_cost_modifier = 0.01, --threat cost for one health - spawn_position = {x = 0, y = 64}, - surface_index = 1, - threat = 0, - threat_gain_multiplier = 2, - unit_group_command_delay = 3600 * 15, - unit_group_command_step_length = 32, - unit_group_last_command = {}, - unit_groups = {}, - wave_interval = 3600, - wave_number = 0, - worm_building_chance = 3, --high value = less chance - worm_building_density = 16, --lower values = more dense building - } + + if game.tick % 60 == 0 then log_threat() end + for _, player in pairs(game.connected_players) do update_gui(player) end end local function on_init() - reset_wave_defense() + local wave_defense_table = WD.get_table() + wave_defense_table.reset_wave_defense() end -local event = require 'utils.event' event.on_nth_tick(30, on_tick) -event.on_init(on_init) \ No newline at end of file +return Public \ No newline at end of file diff --git a/modules/wave_defense/side_targets.lua b/modules/wave_defense/side_targets.lua new file mode 100644 index 00000000..aad7e870 --- /dev/null +++ b/modules/wave_defense/side_targets.lua @@ -0,0 +1,61 @@ +local WD = require "modules.wave_defense.table" +local Public = {} +local side_target_types = { + ["assembling-machine"] = true, + ["accumulator"] = true, + ["boiler"] = true, + ["furnace"] = true, + ["lab"] = true, + ["mining-drill"] = true, + ["radar"] = true, + ["reactor"] = true, + ["roboport"] = true, + ["rocket-silo"] = true, + ["solar-panel"] = true, +} + +local function get_random_target(wave_defense_table) + local r = math.random(1, wave_defense_table.side_target_count) + if not wave_defense_table.side_targets[r] then + table.remove(wave_defense_table.side_targets, r) + wave_defense_table.side_target_count = wave_defense_table.side_target_count - 1 + return + end + if not wave_defense_table.side_targets[r].valid then + table.remove(wave_defense_table.side_targets, r) + wave_defense_table.side_target_count = wave_defense_table.side_target_count - 1 + return + end + return wave_defense_table.side_targets[r] +end + +function Public.get_side_target() + local wave_defense_table = WD.get_table() + for _ = 1, 512, 1 do + if wave_defense_table.side_target_count == 0 then return end + local target = get_random_target(wave_defense_table) + if target then return target end + end +end + +local function add_entity(entity) + local wave_defense_table = WD.get_table() + table.insert(wave_defense_table.side_targets, entity) + wave_defense_table.side_target_count = wave_defense_table.side_target_count + 1 +end + +local function on_built_entity(event) + if not side_target_types[event.created_entity.type] then return end + add_entity(event.created_entity) +end + +local function on_robot_built_entity(event) + if not side_target_types[event.created_entity.type] then return end + add_entity(event.created_entity) +end + +local event = require 'utils.event' +event.add(defines.events.on_built_entity, on_built_entity) +event.add(defines.events.on_robot_built_entity, on_robot_built_entity) + +return Public \ No newline at end of file diff --git a/modules/wave_defense/table.lua b/modules/wave_defense/table.lua new file mode 100644 index 00000000..0e644ffc --- /dev/null +++ b/modules/wave_defense/table.lua @@ -0,0 +1,62 @@ +local Global = require 'utils.global' +local Event = require 'utils.event' + +local wave_defense = {} +local Public = {} + +Global.register( + wave_defense, + function(tbl) + wave_defense = tbl + end +) + +function Public.reset_wave_defense() + wave_defense.active_biter_count = 0 + wave_defense.active_biter_threat = 0 + wave_defense.active_biters = {} + wave_defense.biter_raffle = {} + wave_defense.debug = false + wave_defense.game_lost = false + wave_defense.get_random_close_spawner_attempts = 5 + wave_defense.group_size = 2 + wave_defense.last_wave = game.tick + wave_defense.max_active_biters = 1280 + wave_defense.max_active_unit_groups = 8 + wave_defense.max_biter_age = 3600 * 60 + wave_defense.max_group_size = 200 + wave_defense.nest_building_density = 48 + wave_defense.next_wave = game.tick + 3600 * 15 + wave_defense.side_targets = {} + wave_defense.side_target_count = 0 + wave_defense.simple_entity_shredding_cost_modifier = 0.005 + wave_defense.spawn_position = {x = 0, y = 64} + wave_defense.spitter_raffle = {} + wave_defense.surface_index = 1 + wave_defense.target = nil + wave_defense.threat = 0 + wave_defense.threat_gain_multiplier = 2 + wave_defense.threat_log = {} + wave_defense.threat_log_index = 0 + wave_defense.unit_group_command_delay = 3600 * 15 + wave_defense.unit_group_command_step_length = 80 + wave_defense.unit_group_last_command = {} + wave_defense.unit_groups = {} + wave_defense.wave_interval = 3600 + wave_defense.wave_number = 0 + wave_defense.worm_building_chance = 3 + wave_defense.worm_building_density = 16 + wave_defense.worm_raffle = {} +end + +function Public.get_table() + return wave_defense +end + +local on_init = function () + Public.reset_wave_defense() +end + +Event.on_init(on_init) + +return Public diff --git a/modules/wave_defense/threat_events.lua b/modules/wave_defense/threat_events.lua index 305a5863..4f3ed7ba 100644 --- a/modules/wave_defense/threat_events.lua +++ b/modules/wave_defense/threat_events.lua @@ -1,61 +1,76 @@ +local WD = require "modules.wave_defense.table" local threat_values = require "modules.wave_defense.threat_values" +local BiterRolls = require 'modules.wave_defense.biter_rolls' local math_random = math.random +local Public = {} + local function remove_unit(entity) - if not global.wave_defense.active_biters[entity.unit_number] then return end - global.wave_defense.active_biter_threat = global.wave_defense.active_biter_threat - math.round(threat_values[entity.name] * global.biter_health_boost, 2) - global.wave_defense.active_biter_count = global.wave_defense.active_biter_count - 1 - global.wave_defense.active_biters[entity.unit_number] = nil + local wave_defense_table = WD.get_table() + if not wave_defense_table.active_biters[entity.unit_number] then return end + wave_defense_table.active_biter_threat = wave_defense_table.active_biter_threat - math.round(threat_values[entity.name] * global.biter_health_boost, 2) + wave_defense_table.active_biter_count = wave_defense_table.active_biter_count - 1 + wave_defense_table.active_biters[entity.unit_number] = nil end -function build_nest() - if global.wave_defense.threat < 1000 then return end - if math_random(1, global.wave_defense.nest_building_chance) ~= 1 then return end - if #global.wave_defense.unit_groups == 0 then return end - local group = global.wave_defense.unit_groups[math_random(1, #global.wave_defense.unit_groups)] - if not group then return end - if not group.valid then return end - if not group.members then return end - if not group.members[1] then return end - local unit = group.members[math_random(1, #group.members)] - if not unit.valid then return end - local position = unit.surface.find_non_colliding_position("biter-spawner", unit.position, 16, 1) - if not position then return end - local r = global.wave_defense.nest_building_density - if unit.surface.count_entities_filtered({type = "unit-spawner", area = {{position.x - r, position.y - r},{position.x + r, position.y + r}}}) > 0 then return end - unit.surface.create_entity({name = "biter-spawner", position = position, force = unit.force}) - unit.surface.create_entity({name = "blood-explosion-huge", position = position}) - unit.surface.create_entity({name = "blood-explosion-huge", position = unit.position}) - remove_unit(unit) - unit.destroy() - global.wave_defense.threat = global.wave_defense.threat - 500 -end - -function build_worm() - if global.wave_defense.threat < 1000 then return end - if math_random(1, global.wave_defense.worm_building_chance) ~= 1 then return end - if #global.wave_defense.unit_groups == 0 then return end - local group = global.wave_defense.unit_groups[math_random(1, #global.wave_defense.unit_groups)] +local function place_nest_near_unit_group(wave_defense_table) + local group = wave_defense_table.unit_groups[math_random(1, #wave_defense_table.unit_groups)] if not group then return end if not group.valid then return end if not group.members then return end if not group.members[1] then return end local unit = group.members[math_random(1, #group.members)] if not unit.valid then return end - wave_defense_set_worm_raffle(global.wave_defense.wave_number) - local worm = wave_defense_roll_worm_name() - local position = unit.surface.find_non_colliding_position("assembling-machine-1", unit.position, 8, 1) + local name = "biter-spawner" + if math_random(1, 3) == 1 then name = "spitter-spawner" end + local position = unit.surface.find_non_colliding_position(name, unit.position, 12, 1) if not position then return end - local r = global.wave_defense.worm_building_density + local r = wave_defense_table.nest_building_density + if unit.surface.count_entities_filtered({type = "unit-spawner", area = {{position.x - r, position.y - r},{position.x + r, position.y + r}}}) > 0 then return end + unit.surface.create_entity({name = name, position = position, force = unit.force}) + unit.surface.create_entity({name = "blood-explosion-huge", position = position}) + unit.surface.create_entity({name = "blood-explosion-huge", position = unit.position}) + remove_unit(unit) + unit.destroy() + wave_defense_table.threat = wave_defense_table.threat - threat_values[name] + return true +end + +function Public.build_nest() + local wave_defense_table = WD.get_table() + if wave_defense_table.threat < 1024 then return end + if #wave_defense_table.unit_groups == 0 then return end + for _ = 1, 2, 1 do + if place_nest_near_unit_group(wave_defense_table) then return end + end +end + +function Public.build_worm() + local wave_defense_table = WD.get_table() + if wave_defense_table.threat < 512 then return end + if math_random(1, wave_defense_table.worm_building_chance) ~= 1 then return end + if #wave_defense_table.unit_groups == 0 then return end + local group = wave_defense_table.unit_groups[math_random(1, #wave_defense_table.unit_groups)] + if not group then return end + if not group.valid then return end + if not group.members then return end + if not group.members[1] then return end + local unit = group.members[math_random(1, #group.members)] + if not unit.valid then return end + local position = unit.surface.find_non_colliding_position("assembling-machine-1", unit.position, 8, 1) + BiterRolls.wave_defense_set_worm_raffle(wave_defense_table.wave_number) + local worm = BiterRolls.wave_defense_roll_worm_name() + if not position then return end + local r = wave_defense_table.worm_building_density if unit.surface.count_entities_filtered({type = "turret", area = {{position.x - r, position.y - r},{position.x + r, position.y + r}}}) > 0 then return end unit.surface.create_entity({name = worm, position = position, force = unit.force}) unit.surface.create_entity({name = "blood-explosion-huge", position = position}) unit.surface.create_entity({name = "blood-explosion-huge", position = unit.position}) remove_unit(unit) unit.destroy() - global.wave_defense.threat = global.wave_defense.threat - threat_values[worm] + wave_defense_table.threat = wave_defense_table.threat - threat_values[worm] end - +--[[ local function get_circle_vectors(radius) local vectors = {} for x = radius * -1, radius, 1 do @@ -69,17 +84,18 @@ local function get_circle_vectors(radius) end local acid_nova_entities = { - ["small-biter"] = {projectile = "acid-stream-worm-small", vectors = get_circle_vectors(3), amount = 8, threat_cost = 32}, - ["medium-biter"] = {projectile = "acid-stream-worm-medium", vectors = get_circle_vectors(4), amount = 8, threat_cost = 64}, - ["big-biter"] = {projectile = "acid-stream-worm-big", vectors = get_circle_vectors(5), amount = 8, threat_cost = 96}, - ["behemoth-biter"] = {projectile = "acid-stream-worm-behemoth", vectors = get_circle_vectors(6), amount = 8, threat_cost = 128}, + ["small-biter"] = {projectile = "acid-stream-worm-small", vectors = get_circle_vectors(3), threat_cost = 32}, + ["medium-biter"] = {projectile = "acid-stream-worm-medium", vectors = get_circle_vectors(4), threat_cost = 64}, + ["big-biter"] = {projectile = "acid-stream-worm-big", vectors = get_circle_vectors(5), threat_cost = 96}, + ["behemoth-biter"] = {projectile = "acid-stream-worm-behemoth", vectors = get_circle_vectors(6), threat_cost = 128}, } local function acid_nova(entity) + local wave_defense_table = WD.get_table() if not acid_nova_entities[entity.name] then return end - if global.wave_defense.threat < 100000 then return end - if math_random(1, 16) ~= 1 then return end - for _ = 1, acid_nova_entities[entity.name].amount, 1 do + if wave_defense_table.threat < 100000 then return end + if math.random(1, 32) ~= 1 then return end + for _ = 1, 8, 1 do local i = math_random(1, #acid_nova_entities[entity.name].vectors) entity.surface.create_entity({ name = acid_nova_entities[entity.name].projectile, @@ -91,16 +107,17 @@ local function acid_nova(entity) speed = 0.001 }) end - global.wave_defense.threat = global.wave_defense.threat - acid_nova_entities[entity.name].threat_cost + wave_defense_table.threat = wave_defense_table.threat - acid_nova_entities[entity.name].threat_cost return true end - +]] local function shred_simple_entities(entity) - if global.wave_defense.threat < 25000 then return end + local wave_defense_table = WD.get_table() + if wave_defense_table.threat < 25000 then return end local simple_entities = entity.surface.find_entities_filtered({type = "simple-entity", area = {{entity.position.x - 3, entity.position.y - 3},{entity.position.x + 3, entity.position.y + 3}}}) if #simple_entities == 0 then return end if #simple_entities > 1 then table.shuffle_table(simple_entities) end - local r = math.floor(global.wave_defense.threat * 0.00004) + local r = math.floor(wave_defense_table.threat * 0.00004) if r < 1 then r = 1 end local count = math.random(1, r) --local count = 1 @@ -115,25 +132,43 @@ local function shred_simple_entities(entity) end end if damage_dealt == 0 then return end - local threat_cost = math.floor(damage_dealt * global.wave_defense.simple_entity_shredding_cost_modifier) + local threat_cost = math.floor(damage_dealt * wave_defense_table.simple_entity_shredding_cost_modifier) if threat_cost < 1 then threat_cost = 1 end - global.wave_defense.threat = global.wave_defense.threat - threat_cost + wave_defense_table.threat = wave_defense_table.threat - threat_cost +end + +local function spawn_unit_spawner_inhabitants(wave_defense_table, entity) + if entity.type ~= "unit-spawner" then return end + local count = 8 + math.floor(wave_defense_table.wave_number * 0.02) + if count > 128 then count = 128 end + BiterRolls.wave_defense_set_unit_raffle(wave_defense_table.wave_number) + for _ = 1, count, 1 do + local position = {entity.position.x + (-4 + math.random(0, 8)), entity.position.y + (-4 + math.random(0, 8))} + if math.random(1,4) == 1 then + entity.surface.create_entity({name = BiterRolls.wave_defense_roll_spitter_name(), position = position, force = "enemy"}) + else + entity.surface.create_entity({name = BiterRolls.wave_defense_roll_biter_name(), position = position, force = "enemy"}) + end + end end local function on_entity_died(event) + local wave_defense_table = WD.get_table() local entity = event.entity if not entity.valid then return end if entity.type == "unit" then - global.wave_defense.threat = math.round(global.wave_defense.threat - threat_values[entity.name] * global.biter_health_boost, 2) + wave_defense_table.threat = math.round(wave_defense_table.threat - threat_values[entity.name] * global.biter_health_boost, 2) remove_unit(entity) - acid_nova(entity) + --acid_nova(entity) else if entity.force.index == 2 then if entity.health then if threat_values[entity.name] then - global.wave_defense.threat = global.wave_defense.threat - threat_values[entity.name] + wave_defense_table.threat = wave_defense_table.threat - threat_values[entity.name] end + + spawn_unit_spawner_inhabitants(wave_defense_table, entity) end end end @@ -150,4 +185,6 @@ local function on_entity_died(event) end local event = require 'utils.event' -event.add(defines.events.on_entity_died, on_entity_died) \ No newline at end of file +event.add(defines.events.on_entity_died, on_entity_died) + +return Public \ No newline at end of file diff --git a/modules/wave_defense/threat_values.lua b/modules/wave_defense/threat_values.lua index 4169b124..747b4ef9 100644 --- a/modules/wave_defense/threat_values.lua +++ b/modules/wave_defense/threat_values.lua @@ -1,17 +1,17 @@ local t = { - ["biter-spawner"] = 64, - ["spitter-spawner"] = 64, - ["behemoth-biter"] = 48, - ["behemoth-spitter"] = 48, - ["big-biter"] = 16, - ["big-spitter"] = 16, + ["biter-spawner"] = 128, + ["spitter-spawner"] = 128, + ["behemoth-biter"] = 36, + ["behemoth-spitter"] = 36, + ["big-biter"] = 12, + ["big-spitter"] = 12, ["medium-biter"] = 4, ["medium-spitter"] = 4, ["small-biter"] = 1, ["small-spitter"] = 1, - ["small-worm-turret"] = 16, - ["medium-worm-turret"] = 32, - ["big-worm-turret"] = 48, + ["small-worm-turret"] = 16, + ["medium-worm-turret"] = 32, + ["big-worm-turret"] = 48, ["behemoth-worm-turret"] = 64, } return t \ No newline at end of file diff --git a/player_modifiers.lua b/player_modifiers.lua index 7464311f..2a56f939 100644 --- a/player_modifiers.lua +++ b/player_modifiers.lua @@ -1,5 +1,7 @@ --Central to add all player modifiers together. +local Public = {} + local modifiers = { "character_build_distance_bonus", "character_crafting_speed_modifier", @@ -14,7 +16,7 @@ local modifiers = { "character_running_speed_modifier", } -function update_player_modifiers(player) +function Public.update_player_modifiers(player) for _, modifier in pairs(modifiers) do local sum_value = 0 for _, value in pairs(global.player_modifiers[player.index][modifier]) do @@ -40,4 +42,6 @@ end local event = require 'utils.event' event.on_init(on_init) -event.add(defines.events.on_player_joined_game, on_player_joined_game) \ No newline at end of file +event.add(defines.events.on_player_joined_game, on_player_joined_game) + +return Public \ No newline at end of file diff --git a/utils/core.lua b/utils/core.lua index 410332b6..5690752c 100644 --- a/utils/core.lua +++ b/utils/core.lua @@ -1,6 +1,7 @@ -- Dependencies local Game = require 'utils.game' local Color = require 'utils.color_presets' +local Server = require 'utils.server' -- localized functions local random = math.random @@ -59,7 +60,7 @@ function Module.print_admins(msg, source) chat_color = source.chat_color end else - source_name = 'server_commands' + source_name = 'Server' chat_color = Color.yellow end local formatted_msg = {'utils_core.print_admins',prefix, source_name, msg} @@ -76,7 +77,7 @@ function Module.get_actor() if game.player then return game.player.name end - return '' + return '' end function Module.cast_bool(var) @@ -205,7 +206,7 @@ function Module.action_warning(warning_prefix, msg) game.print(prefix .. msg, Color.yellow) msg = format('%s %s', warning_prefix, msg) log(msg) - server_commands_commands.to_discord_bold(msg) + Server.to_discord_bold(msg) end --- Takes msg and prints it to all players except provided player. Also prints to the log and discord @@ -216,7 +217,7 @@ function Module.silent_action_warning(warning_prefix, msg, player) Module.print_except(prefix .. msg, player, Color.yellow) msg = format('%s %s', warning_prefix, msg) log(msg) - server_commands.to_discord_bold(msg) + Server.to_discord_bold(msg) end -- add utility functions that exist in base factorio/util diff --git a/utils/debug/gui_data_view.lua b/utils/debug/gui_data_view.lua index 9011d656..796b10c5 100644 --- a/utils/debug/gui_data_view.lua +++ b/utils/debug/gui_data_view.lua @@ -130,7 +130,7 @@ local function draw_element_headers(element_panel, values, selected_index) ele_name = gui_name end - if ele_name:match('%d* %- features/gui/debug') then + if ele_name:match('%d* %- utils/debug') then goto continue end diff --git a/utils/debug/model.lua b/utils/debug/model.lua index 90be49de..557a64d4 100644 --- a/utils/debug/model.lua +++ b/utils/debug/model.lua @@ -71,6 +71,7 @@ local function inspect_process(item) return concat(luaEntity) elseif obj_type == 'LuaGuiElement' then local name = item.name + if gui_names == nil then return end luaGuiElement[2] = gui_names[name] or name or 'nil' return concat(luaGuiElement)