1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-02-13 13:49:33 +02:00

Merge pull request #197 from ComfyFactory/chronotrain_commands_module

commands, automatic scenario reset, fixes for gui and events
This commit is contained in:
hanakocz 2021-12-22 06:40:52 +01:00 committed by GitHub
commit eae0378bf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 165 additions and 93 deletions

View File

@ -252,6 +252,15 @@ minimap_button_tooltip=Open or close Outside View window.
minimap_tooltip=LMB: Increase zoom level.\nRMB: Decrease zoom level.\nMMB: Toggle camera size.\nMap button on top to hide/show
map_on=Automatically show map ON
map_off=OFF
cmd_not_admin=You are not an admin! Only admins can run scenario commands!
cmd_game_restarting=Map is being reset...
cmd_reset_map_confirm=[Scenario] Are you sure? This will completely reset current run! Use the command again to proceed.
cmd_hardreset_disabled=[Scenario] Hard reset was disabled.
cmd_hardreset_enabled=[Scenario] Hard reset was enabled. The server will restart on next soft reset.
cmd_server_restarting=[Scenario] Server is restarting to load new changes.
cmd_hardreset_confirm=[Scenario] Are you sure? This will restart the server with new changes. Use the command again to proceed.
command_scenario=Restarts the run, or marks the server for hard reset. Parameters:\nresetmap\nhardreset\nhardresetnow
train_market=Market
train_repair_chest=Repair Chest

View File

@ -379,8 +379,8 @@ function Public.post_jump()
game.forces.player.technologies['power-armor-mk2'].enabled = true
end
end
script.raise_event(objective.events['update_upgrades_gui'], {})
script.raise_event(objective.events['update_world_gui'], {})
script.raise_event(Chrono_table.events['update_upgrades_gui'], {})
script.raise_event(Chrono_table.events['update_world_gui'], {})
end
function Public.message_on_arrival()

View File

@ -0,0 +1,68 @@
local Color = require 'utils.color_presets'
local Server = require 'utils.server'
local Chrono_table = require 'maps.chronosphere.table'
local function scenario(p, parameter)
local objective = Chrono_table.get_table()
if parameter == 'resetmap' then
if objective.restart_confirm == 'resetmap' then
game.print({'chronosphere.cmd_game_restarting'}, Color.warning)
objective.game_lost = true
script.raise_event(Chrono_table.events['reset_map'], {})
return
else
p({'chronosphere.cmd_reset_map_confirm'}, Color.warning)
objective.restart_confirm = 'resetmap'
return
end
elseif parameter == 'hardreset' then
if objective.restart_hard then
p({'chronosphere.cmd_hardreset_disabled'}, Color.success)
objective.restart_hard = false
return
else
p({'chronosphere.cmd_hardreset_enabled'}, Color.success)
objective.restart_hard = true
return
end
elseif parameter == 'hardresetnow' then
if objective.restart_confirm == 'hardreset' then
game.print({'chronosphere.cmd_server_restarting'}, Color.warning)
Server.start_scenario('Chronosphere')
return
else
p({'chronosphere.cmd_hardreset_confirm'}, Color.warning)
objective.restart_confirm = 'hardreset'
return
end
else
p({'chronosphere.command_scenario'}, Color.info)
objective.restart_confirm = nil
end
end
local function cmd_handler(cmd)
local command_name = cmd.name
local player = game.get_player(cmd.player_index)
local p
if not player or not player.valid then
p = log
else
p = player.print
if not player.admin then
p({'chronosphere.cmd_not_admin'}, Color.fail)
return
end
end
if command_name == 'scenario' then
scenario(p, cmd.parameter)
elseif command_name == 'chronojump' then
script.raise_event(Chrono_table.events['chronojump'], {cmd.parameter})
end
end
commands.add_command('scenario', {'chronosphere.command_scenario'}, function(cmd) cmd_handler(cmd) end)
if _DEBUG then
commands.add_command('chronojump', 'Weeeeee!', function(cmd) cmd_handler(cmd) end)
end

View File

@ -179,7 +179,7 @@ function Public.spawner_loot(surface, position)
local count = math_random(1, 1 + objective.chronojumps)
objective.research_tokens.weapons = objective.research_tokens.weapons + count
flying_text(surface, position, {'chronosphere.token_weapons_add', count}, {r = 0.8, g = 0.8, b = 0.8})
script.raise_event(objective.events['update_upgrades_gui'], {})
script.raise_event(Chrono_table.events['update_upgrades_gui'], {})
end
end
@ -190,13 +190,13 @@ function Public.research_loot(event)
bonus = 2
end
objective.research_tokens.tech = objective.research_tokens.tech + 5 * #event.research.research_unit_ingredients * bonus
script.raise_event(objective.events['update_upgrades_gui'], {})
script.raise_event(Chrono_table.events['update_upgrades_gui'], {})
end
function Public.tree_loot()
local objective = Chrono_table.get_table()
objective.research_tokens.ecology = objective.research_tokens.ecology + 1
script.raise_event(objective.events['update_upgrades_gui'], {})
script.raise_event(Chrono_table.events['update_upgrades_gui'], {})
end
function Public.choppy_loot(event)

View File

@ -187,44 +187,6 @@ local function update_upgrades_gui(player)
switch_upgrades(player, playertable.active_upgrades_gui[player.index])
end
local function world_gui(player)
local objective = Chrono_table.get_table()
if player.gui.screen['gui_world'] then
player.gui.screen['gui_world'].destroy()
return
end
local world = objective.world
local evolution = game.forces['enemy'].evolution_factor
local frame = player.gui.screen.add {type = 'frame', name = 'gui_world', caption = {'chronosphere.gui_world_button'}, direction = 'vertical'}
frame.location = {x = 650, y = 45}
frame.style.minimal_height = 300
frame.style.maximal_height = 500
frame.style.minimal_width = 200
frame.style.maximal_width = 400
frame.add({type = 'label', name = 'world_name', caption = {'chronosphere.gui_world_0', world.variant.name}})
frame.add({type = 'label', caption = {'chronosphere.gui_world_1'}})
local table0 = frame.add({type = 'table', name = 'world_ores', column_count = 3})
table0.add({type = 'sprite-button', name = 'iron-ore', sprite = 'item/iron-ore', enabled = false, number = world.variant.fe})
table0.add({type = 'sprite-button', name = 'copper-ore', sprite = 'item/copper-ore', enabled = false, number = world.variant.cu})
table0.add({type = 'sprite-button', name = 'coal', sprite = 'item/coal', enabled = false, number = world.variant.c})
table0.add({type = 'sprite-button', name = 'stone', sprite = 'item/stone', enabled = false, number = world.variant.s})
table0.add({type = 'sprite-button', name = 'uranium-ore', sprite = 'item/uranium-ore', enabled = false, number = world.variant.u})
table0.add({type = 'sprite-button', name = 'oil', sprite = 'fluid/crude-oil', enabled = false, number = world.variant.o})
frame.add({type = 'label', name = 'richness', caption = {'chronosphere.gui_world_2', world.ores.name}})
frame.add({type = 'label', name = 'world_time', caption = {'chronosphere.gui_world_5', world.dayspeed.name}})
frame.add({type = 'line'})
frame.add({type = 'label', name = 'world_biters', caption = {'chronosphere.gui_world_3', math_floor(evolution * 100, 1)}})
frame.add({type = 'label', name = 'world_biters2', caption = {'chronosphere.gui_world_4'}})
frame.add({type = 'label', name = 'world_biters3', caption = {'chronosphere.gui_world_4_1', objective.overstaycount * 2.5, objective.overstaycount * 10}})
frame.add({type = 'line'})
frame.add({type = 'label', name = 'overstay_time', caption = {'chronosphere.gui_world_7', 3}})
frame.add({type = 'line'})
local close = frame.add({type = 'button', name = 'close_world', caption = 'Close'})
close.style.horizontal_align = 'center'
end
local function ETA_seconds_until_full(power, storedbattery) -- in watts and joules
local objective = Chrono_table.get_table()
@ -322,15 +284,55 @@ local function update_world_gui(player)
end
end
local function world_gui(player)
if player.gui.screen['gui_world'] then
player.gui.screen['gui_world'].destroy()
return
end
local objective = Chrono_table.get_table()
local world = objective.world
local evolution = game.forces['enemy'].evolution_factor
local frame = player.gui.screen.add {type = 'frame', name = 'gui_world', caption = {'chronosphere.gui_world_button'}, direction = 'vertical'}
frame.location = {x = 650, y = 45}
frame.style.minimal_height = 300
frame.style.maximal_height = 500
frame.style.minimal_width = 200
frame.style.maximal_width = 400
frame.add({type = 'label', name = 'world_name', caption = {'chronosphere.gui_world_0', world.variant.name}})
frame.add({type = 'label', caption = {'chronosphere.gui_world_1'}})
local table0 = frame.add({type = 'table', name = 'world_ores', column_count = 3})
table0.add({type = 'sprite-button', name = 'iron-ore', sprite = 'item/iron-ore', enabled = false, number = world.variant.fe})
table0.add({type = 'sprite-button', name = 'copper-ore', sprite = 'item/copper-ore', enabled = false, number = world.variant.cu})
table0.add({type = 'sprite-button', name = 'coal', sprite = 'item/coal', enabled = false, number = world.variant.c})
table0.add({type = 'sprite-button', name = 'stone', sprite = 'item/stone', enabled = false, number = world.variant.s})
table0.add({type = 'sprite-button', name = 'uranium-ore', sprite = 'item/uranium-ore', enabled = false, number = world.variant.u})
table0.add({type = 'sprite-button', name = 'oil', sprite = 'fluid/crude-oil', enabled = false, number = world.variant.o})
frame.add({type = 'label', name = 'richness', caption = {'chronosphere.gui_world_2', world.ores.name}})
frame.add({type = 'label', name = 'world_time', caption = {'chronosphere.gui_world_5', world.dayspeed.name}})
frame.add({type = 'line'})
frame.add({type = 'label', name = 'world_biters', caption = {'chronosphere.gui_world_3', math_floor(evolution * 100, 1)}})
frame.add({type = 'label', name = 'world_biters2', caption = {'chronosphere.gui_world_4'}})
frame.add({type = 'label', name = 'world_biters3', caption = {'chronosphere.gui_world_4_1', objective.overstaycount * 2.5, objective.overstaycount * 10}})
frame.add({type = 'line'})
frame.add({type = 'label', name = 'overstay_time', caption = {'chronosphere.gui_world_7', 3}})
frame.add({type = 'line'})
local close = frame.add({type = 'button', name = 'close_world', caption = 'Close'})
close.style.horizontal_align = 'center'
update_world_gui(player)
end
function Public_gui.update_gui(player)
local objective = Chrono_table.get_table()
local difficulty = Difficulty.get().difficulty_vote_value
local playertable = Chrono_table.get_player_table()
if not player.gui.top.chronosphere then
create_gui(player)
end
local gui = player.gui.top.chronosphere
local guimode = objective.guimode
local guimode = playertable.guimode[player.index]
gui.jump_number.caption = objective.chronojumps
@ -351,7 +353,7 @@ function Public_gui.update_gui(player)
gui.timer_value.tooltip = ''
gui.timer2.caption = ''
gui.timer_value2.caption = ''
objective.guimode = 'warmup'
playertable.guimode[player.index] = 'warmup'
end
elseif objective.jump_countdown_start_time == -1 then
local powerobserved, storedbattery = 0, 0
@ -365,7 +367,7 @@ function Public_gui.update_gui(player)
gui.timer2.caption = {'chronosphere.gui_3_2'}
gui.timer2.style.font_color = {r = 0.98, g = 0, b = 0}
gui.timer_value2.style.font_color = {r = 0.98, g = 0, b = 0}
objective.guimode = 'nuclear'
playertable.guimode[player.index] = 'nuclear'
end
local nukecase = objective.dangertimer
gui.timer_value2.caption = math_floor(nukecase / 60) .. 'm' .. nukecase % 60 .. 's'
@ -378,7 +380,7 @@ function Public_gui.update_gui(player)
gui.timer2.caption = {'chronosphere.gui_3_1'}
gui.timer2.style.font_color = {r = 0, g = 200, b = 0}
gui.timer_value2.style.font_color = {r = 0, g = 200, b = 0}
objective.guimode = 'accumulators'
playertable.guimode[player.index] = 'accumulators'
end
local bestcase = math_floor(ETA_seconds_until_full(#objective.accumulators * 300000, storedbattery))
gui.timer_value2.caption = math_floor(bestcase / 60) .. 'm' .. bestcase % 60 .. 's (drawing ' .. #objective.accumulators * 0.3 .. 'MW)'
@ -398,7 +400,7 @@ function Public_gui.update_gui(player)
gui.timer_value.tooltip = ''
gui.timer2.caption = ''
gui.timer_value2.caption = ''
objective.guimode = 'countdown'
playertable.guimode[player.index] = 'countdown'
end
end
end

View File

@ -3,6 +3,7 @@
require 'modules.biter_noms_you'
require 'modules.biters_yield_coins'
require 'modules.no_deconstruction_of_neutral_entities'
local Server = require 'utils.server'
local Comfylatron = require 'maps.chronosphere.comfylatron'
local Ai = require 'maps.chronosphere.ai'
local Balance = require 'maps.chronosphere.balance'
@ -22,6 +23,7 @@ local Tick_functions = require 'maps.chronosphere.tick_functions'
local Upgrades = require 'maps.chronosphere.upgrades'
local Worlds = require 'maps.chronosphere.world_list'
require 'maps.chronosphere.config_tab'
require 'maps.chronosphere.commands'
local function generate_overworld(surface, optworld)
Worlds.determine_world(optworld)
@ -31,6 +33,11 @@ end
local function reset_map()
local objective = Chrono_table.get_table()
if objective.restart_hard then
game.print({'chronosphere.cmd_server_restarting'}, {r = 255, g = 255, b = 0})
Server.start_scenario('Chronosphere')
return
end
Chrono.reset_surfaces()
Worlds.determine_world(nil)
local world = objective.world
@ -79,6 +86,9 @@ local function chronojump(choice)
if objective.game_lost then
goto continue
end
if type(choice) == 'table' then
choice = choice[1]
end
if objective.chronojumps <= 24 then
Locomotive.award_coins(
@ -203,7 +213,7 @@ local function do_tick()
Tick_functions.train_pollution('countdown')
end
end
script.raise_event(objective.events['update_world_gui'], {})
script.raise_event(Chrono_table.events['update_world_gui'], {})
if tick % 120 == 0 then
Tick_functions.move_items()
Tick_functions.output_items()
@ -249,13 +259,6 @@ local function do_tick()
end
end
local function custom_event(name)
local objective = Chrono_table.get_table()
local id = script.generate_event_name()
objective.events[name] = id
return id
end
local function on_init()
local objective = Chrono_table.get_table()
local T = Map.Pop_info()
@ -277,10 +280,6 @@ local function on_init()
mgs.height = 16
game.surfaces['nauvis'].map_gen_settings = mgs
game.surfaces['nauvis'].clear()
Event.add(custom_event('update_gui'), Gui.update_all_player_gui)
Event.add(custom_event('update_world_gui'), Gui.update_all_player_world_gui)
Event.add(custom_event('update_upgrades_gui'), Gui.update_all_player_upgrades_gui)
Event.add(custom_event('comfylatron_damaged'), Comfylatron.comfylatron_damaged)
reset_map()
end
@ -308,29 +307,9 @@ Event.add(defines.events.on_gui_click, Gui.on_gui_click)
Event.add(defines.events.on_pre_player_died, On_Event.on_pre_player_died)
Event.add(defines.events.script_raised_revive, On_Event.script_raised_revive)
Event.add(defines.events.on_player_changed_surface, On_Event.on_player_changed_surface)
if _DEBUG then
local Session = require 'utils.datastore.session_data'
local Color = require 'utils.color_presets'
commands.add_command(
'chronojump',
'Weeeeee!',
function(cmd)
local player = game.player
local trusted = Session.get_trusted_table()
local param = tostring(cmd.parameter)
if player then
if player ~= nil then
if not trusted[player.name] then
if not player.admin then
player.print('[ERROR] Only admins and trusted weebs are allowed to run this command!', Color.fail)
return
end
end
end
end
chronojump(param)
end
)
end
Event.add(Chrono_table.events['comfylatron_damaged'], Comfylatron.comfylatron_damaged)
Event.add(Chrono_table.events['update_gui'], Gui.update_all_player_gui)
Event.add(Chrono_table.events['update_upgrades_gui'], Gui.update_all_player_upgrades_gui)
Event.add(Chrono_table.events['update_world_gui'], Gui.update_all_player_world_gui)
Event.add(Chrono_table.events['reset_map'], reset_map)
Event.add(Chrono_table.events['chronojump'], chronojump)

View File

@ -235,8 +235,7 @@ function Public.on_entity_damaged(event)
Event_functions.biter_immunities(event)
elseif force == 'player' then
if event.entity.name == 'compilatron' then
local objective = Chrono_table.get_table()
script.raise_event(objective.events['comfylatron_damaged'], event)
script.raise_event(Chrono_table.events['comfylatron_damaged'], event)
return
end
protect_entity(event)

View File

@ -9,6 +9,15 @@ local playersphere = {}
local productionsphere = {}
local Public = {}
Public.events = {
comfylatron_damaged = Event.generate_event_name('comfylatron_damaged'),
update_gui = Event.generate_event_name('update_gui'),
update_upgrades_gui = Event.generate_event_name('update_upgrades_gui'),
update_world_gui = Event.generate_event_name('update_world_gui'),
reset_map = Event.generate_event_name('reset_map'),
chronojump = Event.generate_event_name('chronojump'),
}
Global.register(
chronosphere,
function(tbl)
@ -58,6 +67,7 @@ function Public.reset_player_table()
playersphere.flame_boots = {}
playersphere.offline_players = {}
playersphere.active_upgrades_gui = {}
playersphere.guimode = {}
end
function Public.reset_schedule_table()
@ -126,11 +136,11 @@ function Public.reset_table()
chronosphere.last_artillery_event = 0
chronosphere.poison_mastery_unlocked = 0
chronosphere.gen_speed = 2
chronosphere.events = {}
chronosphere.guimode = nil
chronosphere.giftmas_enabled = true
chronosphere.giftmas_lamps = {}
chronosphere.giftmas_delivered = 0
chronosphere.restart_confirm = nil
chronosphere.restart_hard = false
end
function Public.get_table()

View File

@ -25,7 +25,7 @@ function Public.add_ammo_tokens(player)
end
local count = inventory.remove({name = 'pistol', count = 5})
objective.research_tokens.ammo = objective.research_tokens.ammo + count
script.raise_event(objective.events['update_upgrades_gui'], {})
script.raise_event(Chrono_table.events['update_upgrades_gui'], {})
end
function Public.coin_scaling()

View File

@ -324,7 +324,7 @@ local function process_upgrade(index)
upgrade_giftmas()
end
end
script.raise_event(objective.events['update_upgrades_gui'], {})
script.raise_event(Chrono_table.events['update_upgrades_gui'], {})
end
local function check_single_upgrade(index, coin_scaling)
@ -411,7 +411,7 @@ function Public.trigger_poison()
surface.create_entity({name = 'poison-capsule', position = objective.comfychests[i].position, force = 'player', target = objective.comfychests[i], speed = 1})
end
end
script.raise_event(objective.events['update_upgrades_gui'], {})
script.raise_event(Chrono_table.events['update_upgrades_gui'], {})
end
return Public

View File

@ -213,6 +213,7 @@ function Public.determine_world(optional_choice)
end
table.insert(choices.weights, weight)
end
::retry::
if Worlds[tonumber(optional_choice)] then
chosen_id = tonumber(optional_choice)
else
@ -225,6 +226,10 @@ function Public.determine_world(optional_choice)
table.insert(variant_choices.weights, variant.weight)
end
end
if #variant_choices.types < 1 then
optional_choice = nil
goto retry
end
chosen_variant_id = Rand.raffle(variant_choices.types, variant_choices.weights)
local modifiers = get_modifiers(chosen_id)
if modifiers.ores then