1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2024-12-30 23:17:53 +02:00

journey update, fixes

This commit is contained in:
hanakocz 2023-11-02 05:17:37 +01:00
parent ad746de40a
commit 7c8b5355df
4 changed files with 112 additions and 11 deletions

View File

@ -358,6 +358,12 @@ Public.unique_world_traits = {
mods = 2,
loot = {basic = {0, 0}, low = {0, 0}, mil = {0, 1}, inter = {0, 2}, adv = {0, 2}, rare = {1, 1}}
},
['crazy_science'] = {
name = 'Crazy Science',
desc = 'Stuff is standing on its head',
mods = 3,
loot = {basic = {0, 1}, low = {0, 0}, mil = {0, 1}, inter = {0, 1}, adv = {0, 1}, rare = {0, 1}}
},
}
return Public

View File

@ -413,7 +413,7 @@ function Public.on_mothership_chunk_generated(event)
surface.set_tiles(tiles, true)
end
function Public.export_journey(journey)
function Public.export_journey(journey, import_flag)
local data = {
world_number = journey.world_number,
world_modifiers = journey.world_modifiers,
@ -427,11 +427,11 @@ function Public.export_journey(journey)
return
else
Server.set_data('scenario_settings', 'journey_data', data)
Server.set_data('scenario_settings', 'journey_updating', import_flag)
game.print('Journey data exported...')
end
end
function Public.import_journey(journey)
local state = journey.game_state
if state == 'world' or state == 'dispatch_goods' or state == 'mothership_waiting_for_players' then
@ -446,10 +446,31 @@ function Public.import_journey(journey)
end
end
local function check_if_restarted(journey)
local secs = Server.get_current_time()
if not secs then
return
else
Server.try_get_data('scenario_settings', 'journey_updating', journey.check_import)
end
end
function Public.restart_server(journey)
local state = journey.game_state
if state == 'world' or state == 'dispatch_goods' or state == 'mothership_waiting_for_players' then
log('Can force restart only during world selection stages')
return
end
game.print({'journey.cmd_server_restarting'}, {r = 255, g = 255, b = 0})
Public.export_journey(journey, true)
Server.start_scenario('Journey')
return
end
function Public.hard_reset(journey)
if journey.restart_from_scenario then
game.print({'journey.cmd_server_restarting'}, {r = 255, g = 255, b = 0})
Public.export_journey(journey)
Public.export_journey(journey, false)
Server.start_scenario('Journey')
return
end
@ -651,7 +672,7 @@ function Public.draw_mothership(journey)
end
Public.draw_gui(journey)
surface.daytime = 0.5
check_if_restarted()
journey.game_state = 'set_world_selectors'
end
@ -762,6 +783,9 @@ local function roll_bonus_goods(journey, trait, amount)
end
function Public.set_world_selectors(journey)
if journey.restart_from_scenario then
Public.restart_server(journey)
end
local surface = game.surfaces.mothership
local x = Constants.reroll_selector_area.left_top.x + 3.2
@ -1134,10 +1158,15 @@ function Public.create_the_world(journey)
journey.world_modifiers[name] = math.round(math.min(extremes[2], math.max(extremes[1], journey.world_modifiers[name] * m)) * 100000, 5) / 100000
end
surface.map_gen_settings = mgs
journey.world_trait = journey.world_selectors[journey.selected_world].world_trait
local unique_modifier = Unique_modifiers[journey.world_trait]
local set_specials = unique_modifier.set_specials
if set_specials then set_specials(journey) end
set_map_modifiers(journey)
surface.clear(false)
journey.world_trait = journey.world_selectors[journey.selected_world].world_trait
journey.nauvis_chunk_positions = nil
journey.rocket_silos = {}
journey.mothership_cargo['uranium-fuel-cell'] = 0

View File

@ -131,6 +131,15 @@ local function on_robot_mined_entity(event)
if unique_modifier.on_robot_mined_entity then unique_modifier.on_robot_mined_entity(event, journey) end
end
local function on_research_finished(event)
local unique_modifier = Unique_modifiers[journey.world_trait]
if unique_modifier.on_research_finished then
unique_modifier.on_research_finished(event, journey)
Functions.update_tooltips(journey)
Functions.draw_gui(journey)
end
end
local function on_entity_damaged(event)
local entity = event.entity
if not entity or not entity.valid then return end
@ -191,6 +200,19 @@ local function make_import(data)
journey.game_state = 'importing_world'
end
local function check_import(data)
if not data then
return
end
if data.key ~= 'journey_updating' then
return
end
local importing = data.value
if importing then
Functions.import_journey(journey)
end
end
local function on_nth_tick()
Functions[journey.game_state](journey)
Functions.mothership_message_queue(journey)
@ -266,6 +288,18 @@ commands.add_command(
end
)
commands.add_command(
'journey-update-now',
'Restarts the server with newest version of Journey scenario code right now. Only doable during map selection.',
function()
local s, _, p = cmd_handler()
if s then
Functions.restart_server(journey)
p('Journey is restarting to apply changes...')
end
end
)
commands.add_command(
'journey-import',
'Sets the journey gamestate to the last exported one.',
@ -284,7 +318,7 @@ commands.add_command(
function()
local s, _, p = cmd_handler()
if s then
Functions.export_journey(journey)
Functions.export_journey(journey, journey.restart_from_scenario)
p('Journey world settings exporting...')
end
end
@ -304,4 +338,6 @@ 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_entity_damaged, on_entity_damaged)
Event.add(defines.events.on_console_chat, on_console_chat)
Event.add(defines.events.on_research_finished, on_research_finished)
Event.add(events['import'], make_import)
Event.add(events['check_import'], check_import)

View File

@ -44,6 +44,16 @@ local wrecks = {
}
local size_of_wrecks = #wrecks
local tarball_minable = {
['entity-ghost'] = true,
['tile-ghost'] = true,
['container'] = true,
['wall'] = true,
['gate'] = true,
['pipe'] = true,
['pipe-to-ground'] = true
}
local Public = {}
Public.lush = {}
@ -176,14 +186,14 @@ Public.tarball = {
local entity = event.created_entity
if not entity.valid then return end
if entity.surface.index ~= 1 then return end
if entity.type == 'entity-ghost' or entity.type == 'tile-ghost' or entity.type == 'container' or entity.type == 'wall' or entity.type == 'gate' or entity.type == 'pipe' or entity.type == 'pipe-to-ground' then return end
if tarball_minable[entity.type] then return end
entity.minable = false
end,
on_built_entity = function(event)
local entity = event.created_entity
if not entity.valid then return end
if entity.surface.index ~= 1 then return end
if entity.type == 'entity-ghost' or entity.type == 'tile-ghost' or entity.type == 'container' or entity.type == 'wall' or entity.type == 'gate' or entity.type == 'pipe' or entity.type == 'pipe-to-ground' then return end
if tarball_minable[entity.type] then return end
entity.minable = false
end,
on_chunk_generated = function(event, journey)
@ -206,7 +216,7 @@ end,
}
Public.swamps = {
on_world_start = function(journey)
set_specials = function(journey)
journey.world_specials['water'] = 2
end,
on_chunk_generated = function(event, journey)
@ -371,7 +381,7 @@ Public.infested = {
render_layer = 'ground'
}))
end,
on_world_start = function(journey)
set_specials = function(journey)
journey.world_specials['trees_size'] = 4
journey.world_specials['trees_richness'] = 2
journey.world_specials['trees_frequency'] = 2
@ -536,7 +546,7 @@ Public.abandoned_library = {
}
Public.railworld = {
on_world_start = function(journey)
set_specials = function(journey)
journey.world_specials['ore_size'] = 4
journey.world_specials['ore_frequency'] = 0.25
journey.world_specials['coal'] = 4
@ -578,4 +588,24 @@ Public.resupply_station = {
end,
}
Public.crazy_science = {
set_specials = function(journey)
journey.world_specials['technology_price_multiplier'] = 50
journey.world_specials['starting_area'] = 3
journey.world_specials['copper-ore'] = 2
journey.world_specials['iron-ore'] = 4
end,
on_world_start = function(journey)
game.forces.player.laboratory_productivity_bonus = 5
game.forces.player.laboratory_speed_modifier = 10
end,
on_research_finished = function(event, journey)
local name = 'technology_price_multiplier'
journey.world_specials[name] = math.max(0.1, journey.world_specials[name] * 0.95)
game.difficulty_settings.technology_price_multiplier = journey.world_modifiers[name] * (journey.world_specials[name] or 1)
game.forces.player.laboratory_productivity_bonus = math.max(0.1, game.forces.player.laboratory_productivity_bonus * 0.95)
end,
}
return Public