1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-12 10:04:40 +02:00

DOK2: add custom win module

This commit is contained in:
RedRafe 2023-10-04 10:15:48 +02:00
parent d75ddbef27
commit 8319bc95a1
3 changed files with 97 additions and 2 deletions

View File

@ -176,4 +176,5 @@ anti_grief_jail_reason=You have spilled too many items on the ground, contact an
biters_disabled=Launching the first [item=satellite] has killed all the biters. Launch __1__ [item=satellite] to win the map.
win=Congratulations! The map has been won. Restart the map with /restart
satellite_launch=Launch another __1__ [item=satellite] to win the map.
satellite_logger=Already launched __1__ [item=satellite]

View File

@ -0,0 +1,92 @@
local Event = require 'utils.event'
local RS = require 'map_gen.shared.redmew_surface'
local Server = require 'features.server'
local ShareGlobals = require 'map_gen.maps.danger_ores.modules.shared_globals'
return function(config)
ShareGlobals.data.biters_disabled = false
ShareGlobals.data.map_won = false
local win_satellite_count = config.win_satellite_count or 1000
local function disable_biters()
if ShareGlobals.data.biters_disabled then
return
end
ShareGlobals.data.biters_disabled = true
game.forces.enemy.kill_all_units()
for _, enemy_entity in pairs(RS.get_surface().find_entities_filtered({force = 'enemy'})) do
enemy_entity.destroy()
end
local message = table.concat {
'Launching the first satellite has killed all the biters. ',
'Launch ',
win_satellite_count,
' satellites to win the map.'
}
game.print({'danger_ores.biters_disabled', win_satellite_count})
Server.to_discord_bold(message)
end
local function print_satellite_message(count)
-- Just log the no. of satellite(s) launched
game.print({'danger_ores.satellite_logger', count})
Server.to_discord_bold('Already launched ' .. tostring(count) .. ' satellie(s)')
end
local function rocket_launched(event)
if ShareGlobals.data.map_won then
return
end
local entity = event.rocket
if not entity or not entity.valid or not entity.force == 'player' then
return
end
local inventory = entity.get_inventory(defines.inventory.rocket)
if not inventory or not inventory.valid then
return
end
local satellite_count = game.forces.player.get_item_launched('satellite')
if satellite_count == 0 then
return
end
if satellite_count == 1 then
disable_biters()
end
--if satellite_count == win_satellite_count then
-- win()
-- return
--end
if (satellite_count % 50) == 0 then
print_satellite_message(satellite_count)
end
end
local function win()
if ShareGlobals.data.map_won then
return
end
ShareGlobals.data.map_won = true
local message = 'Congratulations! The map has been won. Restart the map with /restart'
game.print({'danger_ores.win'})
Server.to_discord_bold(message)
end
local function on_transceiver_built(event)
if event.effect_id ~= "k2-transciever-activated" then return end
win()
end
Event.add(defines.events.on_rocket_launched, rocket_launched)
Event.add(defines.events.on_script_trigger_effect, on_transceiver_built)
end

View File

@ -182,8 +182,10 @@ local terraforming = require 'map_gen.maps.danger_ores.modules.terraforming'
terraforming({start_size = 8 * 32, min_pollution = 600, max_pollution = 24000, pollution_increment = 9})
--[[ Win condition in K2: build intergalactic transceiver ]]
-- local rocket_launched = require 'map_gen.maps.danger_ores.modules.rocket_launched_simple'
-- rocket_launched({win_satellite_count = 1000})
local rocket_launched = require 'map_gen.maps.danger_ores.modules.rocket_launched_krastorio2'
local win_condition = settings.startup['k2-danger-ores:win_condition']
local satellite_count = win_condition and win_condition.value or 1000
rocket_launched({win_satellite_count = satellite_count})
local restart_command = require 'map_gen.maps.danger_ores.modules.restart_command'
restart_command({scenario_name = 'danger-ore-krastorio2'})