1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-03-11 14:49:24 +02:00
This commit is contained in:
Gerkiz 2020-06-05 23:53:58 +02:00
parent 5787381c68
commit ee1f80fb82
9 changed files with 562 additions and 150 deletions

View File

@ -0,0 +1,374 @@
local Event = require 'utils.event'
local Global = require 'utils.global'
local Gui = require 'utils.gui'
local Token = require 'utils.token'
local Color = require 'utils.color_presets'
local pairs = pairs
local next = next
local Public = {}
local active_alerts = {}
local id_counter = {0}
local alert_zoom_to_pos = Gui.uid_name()
local on_tick
Global.register(
{active_alerts = active_alerts, id_counter = id_counter},
function(tbl)
active_alerts = tbl.active_alerts
id_counter = tbl.id_counter
end,
'alert'
)
local alert_frame_name = Gui.uid_name()
local alert_container_name = Gui.uid_name()
local alert_progress_name = Gui.uid_name()
local close_alert_name = Gui.uid_name()
--- Apply this name to an element to have it close the alert when clicked.
-- Two elements in the same parent cannot have the same name. If you need your
-- own name you can use Public.close_alert(element)
Public.close_alert_name = close_alert_name
---Creates a unique ID for a alert message
local function autoincrement()
local id = id_counter[1] + 1
id_counter[1] = id
return id
end
---Attempts to get a alert based on the element, will traverse through parents to find it.
---@param element LuaGuiElement
local function get_alert(element)
if not element or not element.valid then
return nil
end
if element.name == alert_frame_name then
return element.parent
end
return get_alert(element.parent)
end
--- Closes the alert for the element.
--@param element LuaGuiElement
function Public.close_alert(element)
local alert = get_alert(element)
if not alert then
return
end
local data = Gui.get_data(alert)
active_alerts[data.alert_id] = nil
Gui.destroy(alert)
end
---Message to a specific player
---@param player LuaPlayer
---@param duration number in seconds
---@param sound string sound to play, nil to not play anything
local function alert_to(player, duration, sound)
local frame_holder = player.gui.left.add({type = 'flow'})
local frame =
frame_holder.add({type = 'frame', name = alert_frame_name, direction = 'vertical', style = 'captionless_frame'})
frame.style.width = 300
local container = frame.add({type = 'flow', name = alert_container_name, direction = 'horizontal'})
container.style.horizontally_stretchable = true
local progressbar = frame.add({type = 'progressbar', name = alert_progress_name})
local style = progressbar.style
style.width = 290
style.height = 4
style.color = Color.orange
progressbar.value = 1 -- it starts full
local id = autoincrement()
local tick = game.tick
if not duration then
duration = 15
end
Gui.set_data(
frame_holder,
{
alert_id = id,
progressbar = progressbar,
start_tick = tick,
end_tick = tick + duration * 60
}
)
if not next(active_alerts) then
Event.add_removable_nth_tick(2, on_tick)
end
active_alerts[id] = frame_holder
if sound then
player.play_sound({path = sound, volume_modifier = 0.80})
end
return container
end
local function zoom_to_pos(event)
local player = event.player
local element = event.element
local position = Gui.get_data(element)
player.zoom_to_world(position, 0.5)
end
local close_alert = Public.close_alert
local function on_click_close_alert(event)
close_alert(event.element)
end
Gui.on_click(alert_zoom_to_pos, zoom_to_pos)
Gui.on_click(alert_frame_name, on_click_close_alert)
Gui.on_click(alert_container_name, on_click_close_alert)
Gui.on_click(alert_progress_name, on_click_close_alert)
Gui.on_click(close_alert_name, on_click_close_alert)
local function update_alert(id, frame, tick)
if not frame.valid then
active_alerts[id] = nil
return
end
local data = Gui.get_data(frame)
local end_tick = data.end_tick
if tick > end_tick then
Gui.destroy(frame)
active_alerts[data.alert_id] = nil
else
local limit = end_tick - data.start_tick
local current = end_tick - tick
data.progressbar.value = current / limit
end
end
on_tick =
Token.register(
function(event)
if not next(active_alerts) then
Event.remove_removable_nth_tick(2, on_tick)
return
end
local tick = event.tick
for id, frame in pairs(active_alerts) do
update_alert(id, frame, tick)
end
end
)
---Message a specific player, template is a callable that receives a LuaGuiElement
---to add contents to and a player as second argument.
---@param player LuaPlayer
---@param duration table
---@param template function
---@param sound string sound to play, nil to not play anything
function Public.alert_player_template(player, duration, template, sound)
sound = sound or 'utility/new_objective'
local container = alert_to(player, duration, sound)
if container then
template(container, player)
end
end
---Message all players of the given force, template is a callable that receives a LuaGuiElement
---to add contents to and a player as second argument.
---@param force LuaForce
---@param duration number
---@param template function
---@param sound string sound to play, nil to not play anything
function Public.alert_force_template(force, duration, template, sound)
sound = sound or 'utility/new_objective'
local players = force.connected_players
for i = 1, #players do
local player = players[i]
template(alert_to(player, duration, sound), player)
end
end
---Message all players, template is a callable that receives a LuaGuiElement
---to add contents to and a player as second argument.
---@param duration number
---@param template function
---@param sound string sound to play, nil to not play anything
function Public.alert_all_players_template(duration, template, sound)
sound = sound or 'utility/new_objective'
local players = game.connected_players
for i = 1, #players do
local player = players[i]
template(alert_to(player, duration, sound), player)
end
end
---Message all players at a given location
---@param player LuaPlayer
---@param message string
---@param color string
function Public.alert_all_players_location(player, message, color)
Public.alert_all_players_template(
15,
function(container)
local sprite =
container.add {
type = 'sprite-button',
name = alert_zoom_to_pos,
sprite = 'utility/search_icon',
style = 'slot_button'
}
Gui.set_data(sprite, player.position)
local label =
container.add {
type = 'label',
name = Public.close_alert_name,
caption = message
}
local label_style = label.style
label_style.single_line = false
label_style.font_color = color or Color.comfy
end
)
end
---Message to a specific player
---@param player LuaPlayer
---@param duration number
---@param message string
---@param color string
function Public.alert_player(player, duration, message, color)
Public.alert_player_template(
player,
duration,
function(container)
local label = container.add({type = 'label', name = close_alert_name, caption = message})
label.style.single_line = false
label.style.font_color = color or Color.comfy
end
)
end
---Message to all players of a given force
---@param force LuaForce
---@param duration number
---@param message string
function Public.alert_force(force, duration, message)
local players = force.connected_players
for i = 1, #players do
local player = players[i]
Public.alert_player(player, duration, message)
end
end
---Message to all players
---@param duration number
---@param message string
---@param color string
function Public.alert_all_players(duration, message, color)
local players = game.connected_players
for i = 1, #players do
local player = players[i]
Public.alert_player(player, duration, message, color)
end
end
commands.add_command(
'notify_all_players',
'Usable only for admins - sends an alert message to all players!',
function(cmd)
local p
local player = game.player
local param = cmd.parameter
if player then
if player ~= nil then
p = player.print
if not player.admin then
p("[ERROR] You're not admin!", Color.fail)
return
end
if not param then
return p('Valid arguments are: message_to_print')
end
Public.alert_all_players_location(player, param)
else
p = log
if not param then
return p('Valid arguments are: message_to_print')
end
Public.alert_all_players(15, param)
end
end
end
)
commands.add_command(
'notify_player',
'Usable only for admins - sends an alert message to a player!',
function(cmd)
local p
local player = game.player
local param = cmd.parameter
if player then
if player ~= nil then
p = player.print
if not player.admin then
p("[ERROR] You're not admin!", Color.fail)
return
end
local t_player
local t_message
local target_player
local str = ''
if not param then
return p('[ERROR] Valid arguments are:\nplayer = player,\nmessage = message', Color.fail)
end
local t = {}
for i in string.gmatch(param, '%S+') do
table.insert(t, i)
end
t_player = t[1]
for i = 2, #t do
str = str .. t[i] .. ' '
t_message = str
end
if game.players[t_player] then
target_player = game.players[t_player]
else
return p('[ERROR] No player was provided', Color.fail)
end
if t_message then
local message = t_message
Public.alert_player(target_player, 15, message)
else
p('No message was provided', Color.fail)
end
end
end
end
)
return Public

View File

@ -3,13 +3,57 @@ local Terrain = require 'maps.mountain_fortress_v3.terrain'
local Balance = require 'maps.mountain_fortress_v3.balance'
local RPG = require 'maps.mountain_fortress_v3.rpg'
local WPT = require 'maps.mountain_fortress_v3.table'
local Alert = require 'maps.mountain_fortress_v3.alert'
local Event = require 'utils.event'
local Task = require 'utils.task'
local Token = require 'utils.token'
local raise_event = script.raise_event
local floor = math.floor
local sqrt = math.sqrt
local concat = table.concat
local keeper = '[color=blue]Mapkeeper:[/color] '
local keeper = '[color=blue]Mapkeeper:[/color] \n'
local collapse_message =
Token.register(
function(data)
local pos = data.position
local message = keeper .. 'Warning, collapse has begun!'
local collapse_position = {
position = pos
}
Alert.alert_all_players_location(collapse_position, message)
end
)
local zone_complete =
Token.register(
function(data)
local bonus = data.bonus
local player = data.player
local message = keeper .. 'Survivor! Well done. You have completed zone: ' .. bonus
Alert.alert_player(player, 10, message)
end
)
local first_player_to_zone =
Token.register(
function(data)
local player = data.player
local breached_wall = data.breached_wall
local message = concat {keeper .. player.name .. ' was the first to reach zone ' .. breached_wall .. '.'}
Alert.alert_all_players(10, message)
end
)
local artillery_warning =
Token.register(
function()
local message = keeper .. 'Warning, Artillery have been spotted north!'
Alert.alert_all_players(10, message)
end
)
local function distance(player)
local rpg_t = RPG.get_table()
@ -33,19 +77,30 @@ local function distance(player)
rpg_extra.reward_new_players = 150 * rpg_extra.breached_walls
WPT.get().breached_wall = breached_wall + 1
raise_event(Balance.events.breached_wall, {})
game.print(keeper .. player.name .. ' was the first to reach zone ' .. breached_wall .. '.')
local data = {
player = player,
breached_wall = breached_wall
}
Task.set_timeout_in_ticks(360, first_player_to_zone, data)
if breached_wall == 5 then
game.print(keeper .. 'Warning, Artilleries have been spotted north!')
Task.set_timeout_in_ticks(360, artillery_warning)
end
end
if not Collapse.start_now() then
Collapse.start_now(true)
game.print(keeper .. 'Warning, collapse has begun!')
local data = {
position = Collapse.get_position()
}
Task.set_timeout_in_ticks(550, collapse_message, data)
end
rpg_t[player.index].bonus = bonus + 1
player.print(keeper .. 'Survivor! Well done. You have completed zone: ' .. bonus)
local data = {
player = player,
bonus = bonus
}
Task.set_timeout_in_ticks(1, zone_complete, data)
RPG.gain_xp(player, 150 * bonus)
return
end
end

View File

@ -406,7 +406,7 @@ function Public.schedule_chunk(event)
local area = event.area
local data = {
yv = 0,
yv = -1,
xv = 0,
y = 0,
x = area.left_top.x,
@ -446,8 +446,8 @@ function Public.do_chunk(event)
local area = event.area
local data = {
yv = 0,
xv = 1,
yv = -0,
xv = 0,
area = area,
top_x = area.left_top.x,
top_y = area.left_top.y,

View File

@ -4,6 +4,7 @@ local ICW = require 'maps.mountain_fortress_v3.icw.main'
local WPT = require 'maps.mountain_fortress_v3.table'
local RPG = require 'maps.mountain_fortress_v3.rpg'
local Server = require 'utils.server'
local Alert = require 'maps.mountain_fortress_v3.alert'
local WD = require 'modules.wave_defense.table'
local format_number = require 'util'.format_number
@ -203,7 +204,7 @@ local function close_market_gui(player)
end
end
local function redraw_market_items(gui, player, search_text)
local function redraw_market_items(gui, player)
if not validate_player(player) then
return
end
@ -218,15 +219,6 @@ local function redraw_market_items(gui, player, search_text)
local slider_value = math.ceil(this.players[player.index].data.slider.slider_value)
for item, data in pairs(Public.get_items()) do
if not search_text then
goto continue
end
if not search_text.text then
goto continue
end
if not string.lower(item:gsub('-', ' ')):find(search_text.text) then
goto continue
end
local item_count = data.stack * slider_value
local item_cost = data.price * slider_value
@ -257,7 +249,6 @@ local function redraw_market_items(gui, player, search_text)
if player_item_count < item_cost then
button.enabled = false
end
::continue::
end
end
@ -304,7 +295,7 @@ local function slider_changed(event)
end
slider_value = math.ceil(slider_value)
this.players[player.index].data.text_input.text = slider_value
redraw_market_items(this.players[player.index].data.item_frame, player, this.players[player.index].data.search_text)
redraw_market_items(this.players[player.index].data.item_frame, player)
end
local function text_changed(event)
@ -323,13 +314,15 @@ local function text_changed(event)
return
end
local value = 0
tonumber(data.text_input.text)
local value = tonumber(data.text_input.text)
if not value then
return
end
data.slider.slider_value = value
redraw_market_items(data.item_frame, player, data.search_text)
this.players[player.index].data.slider.slider_value = value
redraw_market_items(data.item_frame, player)
end
local function gui_opened(event)
@ -418,13 +411,12 @@ local function gui_opened(event)
{
type = 'slider',
minimum_value = 1,
maximum_value = 1e3,
maximum_value = 5e3,
value = 1
}
)
slider.style.width = 115
text_input.style.width = 45
text_input.style.width = 60
local coinsleft = frame.add({type = 'flow'})
@ -442,7 +434,7 @@ local function gui_opened(event)
this.players[player.index].data.item_frame = pane
this.players[player.index].data.coins_left = coinsleft
redraw_market_items(pane, player, search_text)
redraw_market_items(pane, player)
end
local function gui_click(event)
@ -474,7 +466,7 @@ local function gui_click(event)
if slider_value > 1 then
data.slider.slider_value = slider_value - 1
data.text_input.text = data.slider.slider_value
redraw_market_items(data.item_frame, player, data.search_text)
redraw_market_items(data.item_frame, player)
end
return
elseif name == 'more' then
@ -482,7 +474,7 @@ local function gui_click(event)
if slider_value <= 1e3 then
data.slider.slider_value = slider_value + 1
data.text_input.text = data.slider.slider_value
redraw_market_items(data.item_frame, player, data.search_text)
redraw_market_items(data.item_frame, player)
end
return
end
@ -522,24 +514,22 @@ local function gui_click(event)
end
player.remove_item({name = item.value, count = cost})
game.print(
local message =
shopkeeper ..
' ' ..
player.name ..
' has bought the clear threat modifier for ' ..
cost .. ' coins. Threat level is reduced by 50%!',
{r = 0.98, g = 0.66, b = 0.22}
)
' ' ..
player.name ..
' has bought the clear threat modifier for ' .. cost .. ' coins.\nThreat level is reduced by 50%!'
Alert.alert_all_players(5, message)
Server.to_discord_bold(
table.concat {
player.name ..
' has bought the clear threat modifier for ' .. cost .. ' coins. Threat level is reduced by 50%!'
' has bought the clear threat modifier for ' .. cost .. ' coins.\nThreat level is reduced by 50%!'
}
)
this.threat_upgrades = this.threat_upgrades + item_count
wdt.threat = wdt.threat / 2 * item_count
redraw_market_items(data.item_frame, player, data.search_text)
redraw_market_items(data.item_frame, player)
redraw_coins_left(data.coins_left, player)
return
@ -547,19 +537,18 @@ local function gui_click(event)
if name == 'locomotive_max_health' then
player.remove_item({name = item.value, count = cost})
game.print(
local message =
shopkeeper ..
' ' ..
player.name ..
' has bought the locomotive health modifier for ' ..
cost .. ' coins. The train health is now buffed.',
{r = 0.98, g = 0.66, b = 0.22}
)
' ' ..
player.name ..
' has bought the locomotive health modifier for ' ..
cost .. ' coins.\nThe train health is now buffed.'
Alert.alert_all_players(5, message)
Server.to_discord_bold(
table.concat {
player.name ..
' has bought the locomotive health modifier for ' ..
cost .. ' coins. The train health is now buffed.'
cost .. ' coins.\nThe train health is now buffed.'
}
)
this.locomotive_max_health = this.locomotive_max_health + 2500 * item_count
@ -570,7 +559,7 @@ local function gui_click(event)
this.health_upgrades = this.health_upgrades + item_count
rendering.set_text(this.health_text, 'HP: ' .. this.locomotive_health .. ' / ' .. this.locomotive_max_health)
redraw_market_items(data.item_frame, player, data.search_text)
redraw_market_items(data.item_frame, player)
redraw_coins_left(data.coins_left, player)
return
@ -578,18 +567,16 @@ local function gui_click(event)
if name == 'locomotive_xp_aura' then
player.remove_item({name = item.value, count = cost})
game.print(
local message =
shopkeeper ..
' ' ..
player.name ..
' has bought the locomotive xp aura modifier for ' ..
cost .. ' coins. The XP aura is now buffed.',
{r = 0.98, g = 0.66, b = 0.22}
)
' ' ..
player.name ..
' has bought the locomotive xp aura modifier for ' .. cost .. ' coins.\nThe XP aura is now buffed.'
Alert.alert_all_players(5, message)
Server.to_discord_bold(
table.concat {
player.name ..
' has bought the locomotive xp aura modifier for ' .. cost .. ' coins. The XP aura is now buffed.'
' has bought the locomotive xp aura modifier for ' .. cost .. ' coins.\nThe XP aura is now buffed.'
}
)
this.locomotive_xp_aura = this.locomotive_xp_aura + 5
@ -609,7 +596,7 @@ local function gui_click(event)
only_in_alt_mode = true
}
redraw_market_items(data.item_frame, player, data.search_text)
redraw_market_items(data.item_frame, player)
redraw_coins_left(data.coins_left, player)
return
@ -618,24 +605,23 @@ local function gui_click(event)
if name == 'xp_points_boost' then
player.remove_item({name = item.value, count = cost})
game.print(
local message =
shopkeeper ..
' ' ..
player.name ..
' has bought the xp point modifier for ' .. cost .. ' coins. You now gain more XP points.',
{r = 0.98, g = 0.66, b = 0.22}
)
' ' ..
player.name ..
' has bought the xp point modifier for ' .. cost .. ' coins.\nYou now gain more XP points.'
Alert.alert_all_players(5, message)
Server.to_discord_bold(
table.concat {
player.name ..
' has bought the xp point modifier for ' .. cost .. ' coins. You now gain more XP points.'
' has bought the xp point modifier for ' .. cost .. ' coins.\nYou now gain more XP points.'
}
)
this.xp_points = this.xp_points + 0.5
this.xp_points_upgrade = this.xp_points_upgrade + item_count
this.train_upgrades = this.train_upgrades + item_count
redraw_market_items(data.item_frame, player, data.search_text)
redraw_market_items(data.item_frame, player)
redraw_coins_left(data.coins_left, player)
return
@ -644,23 +630,21 @@ local function gui_click(event)
if name == 'flamethrower_turrets' then
player.remove_item({name = item.value, count = cost})
if item_count >= 1 then
game.print(
shopkeeper .. ' ' .. player.name .. ' has bought a flamethrower-turret slot for ' .. cost .. ' coins.',
{r = 0.98, g = 0.66, b = 0.22}
)
local message =
shopkeeper .. ' ' .. player.name .. ' has bought a flamethrower-turret slot for ' .. cost .. ' coins.'
Alert.alert_all_players(5, message)
Server.to_discord_bold(
table.concat {
player.name .. ' has bought a flamethrower-turret slot for ' .. cost .. ' coins.'
}
)
else
game.print(
local message =
shopkeeper ..
' ' ..
player.name ..
' has bought ' .. item_count .. ' flamethrower-turret slots for ' .. cost .. ' coins.',
{r = 0.98, g = 0.66, b = 0.22}
)
' ' ..
player.name ..
' has bought ' .. item_count .. ' flamethrower-turret slots for ' .. cost .. ' coins.'
Alert.alert_all_players(5, message)
Server.to_discord_bold(
table.concat {
player.name ..
@ -671,7 +655,7 @@ local function gui_click(event)
this.upgrades.flame_turret.limit = this.upgrades.flame_turret.limit + item_count
this.upgrades.flame_turret.bought = this.upgrades.flame_turret.bought + item_count
redraw_market_items(data.item_frame, player, data.search_text)
redraw_market_items(data.item_frame, player)
redraw_coins_left(data.coins_left, player)
return
@ -680,17 +664,14 @@ local function gui_click(event)
player.remove_item({name = item.value, count = cost})
if item_count >= 1 then
game.print(
shopkeeper .. ' ' .. player.name .. ' has bought a landmine slot for ' .. cost .. ' coins.',
{r = 0.98, g = 0.66, b = 0.22}
)
local message = shopkeeper .. ' ' .. player.name .. ' has bought a landmine slot for ' .. cost .. ' coins.'
Alert.alert_all_players(3, message)
else
game.print(
local message =
shopkeeper ..
' ' .. player.name .. ' has bought ' .. item_count .. ' landmine slots for ' .. cost .. ' coins.',
{r = 0.98, g = 0.66, b = 0.22}
)
if cost > 5000 then
' ' .. player.name .. ' has bought ' .. item_count .. ' landmine slots for ' .. cost .. ' coins.'
Alert.alert_all_players(3, message)
if cost >= 5000 then
Server.to_discord_bold(
table.concat {
player.name .. ' has bought ' .. item_count .. ' landmine slots for ' .. cost .. ' coins.'
@ -702,7 +683,7 @@ local function gui_click(event)
this.upgrades.landmine.limit = this.upgrades.landmine.limit + item_count
this.upgrades.landmine.bought = this.upgrades.landmine.bought + item_count
redraw_market_items(data.item_frame, player, data.search_text)
redraw_market_items(data.item_frame, player)
redraw_coins_left(data.coins_left, player)
return
end
@ -717,7 +698,7 @@ local function gui_click(event)
player.insert({name = item.value, count = cost})
player.remove_item({name = name, count = inserted_count})
end
redraw_market_items(data.item_frame, player, data.search_text)
redraw_market_items(data.item_frame, player)
redraw_coins_left(data.coins_left, player)
end
end

View File

@ -19,6 +19,7 @@ local Poll = require 'comfy_panel.poll'
local Collapse = require 'modules.collapse'
local Difficulty = require 'modules.difficulty_vote'
local Task = require 'utils.task'
local Alert = require 'maps.mountain_fortress_v3.alert'
--local HD = require 'modules.hidden_dimension.main'
require 'maps.mountain_fortress_v3.generate'
@ -325,8 +326,8 @@ local function on_player_joined_game(event)
this.players[player.index] = {
data = {}
}
player.print('Greetings, ' .. player.name .. '!', {r = 0.98, g = 0.66, b = 0.22})
player.print('Please read the map info.', {r = 0.98, g = 0.66, b = 0.22})
local message = 'Greetings, ' .. player.name .. '!\nPlease read the map info.'
Alert.alert_player(player, 10, message)
for item, amount in pairs(starting_items) do
player.insert({name = item, count = amount})
end
@ -386,13 +387,13 @@ local function remove_offline_players()
end
if game.tick % 432000 == 0 then
this.offline_players_enabled = true
return
end
return
end
local offline_players = WPT.get('offline_players')
local active_surface_index = WPT.get('active_surface_index')
local surface = game.surfaces[active_surface_index]
local keeper = '[color=blue]Cleaner:[/color]'
local keeper = '[color=blue]Cleaner:[/color] \n'
local player_inv = {}
local items = {}
if #offline_players > 0 then
@ -441,10 +442,12 @@ local function remove_offline_players()
inv.insert(items[item])
end
end
game.print(
keeper .. ' ' .. name .. ' has left his goodies! [gps=' .. pos.x .. ',' .. pos.y .. ']',
{r = 0.98, g = 0.66, b = 0.22}
)
local message = keeper .. name .. ' has left his goodies!'
local data = {
position = pos
}
Alert.alert_all_players_location(data, message)
e.die('neutral')
else

View File

@ -139,20 +139,20 @@ local function get_oil_amount(p)
return (math_abs(p.y) * 200 + 10000) * math_random(75, 125) * 0.01
end
function Public.increment_value(tbl, key, max, target)
if target then
if tbl.yv == 31 then
tbl[key] = tbl[key] + 1
function Public.increment_value(tbl)
tbl.yv = tbl.yv + 1
if tbl.yv == 32 then
if tbl.xv == 32 then
tbl.xv = 0
end
else
tbl[key] = tbl[key] + 1
if tbl.yv == 32 then
tbl.yv = 0
end
tbl.xv = tbl.xv + 1
end
if tbl[key] == max then
tbl[key] = 0
end
return tbl[key]
return tbl.xv, tbl.yv
end
local function spawn_turret(entities, p, probability)
@ -173,8 +173,7 @@ local function wall(data)
local treasure = data.treasure
local stone_wall = {callback = Functions.disable_minable_callback}
local y = Public.increment_value(data, 'yv', 32)
local x = Public.increment_value(data, 'xv', 32, true)
local x, y = Public.increment_value(data)
local seed = data.seed
local p = {x = x + data.top_x, y = y + data.top_y}
@ -1436,8 +1435,7 @@ local function border_chunk(data)
local top_x = data.top_x
local top_y = data.top_y
local x = Public.increment_value(data, 'xv', 32)
local y = Public.increment_value(data, 'yv', 31)
local x, y = Public.increment_value(data)
local pos = {x = x + data.top_x, y = y + data.top_y}
@ -1471,11 +1469,13 @@ local function border_chunk(data)
end
end
local function biter_chunk(x, y, data)
local function biter_chunk(data)
local surface = data.surface
local entities = data.entities
local tile_positions = {}
local p = {x = x, y = y}
local x, y = Public.increment_value(data)
local p = {x = x + data.top_x, y = y + data.top_y}
tile_positions[#tile_positions + 1] = p
local disable_spawners = {
@ -1518,8 +1518,11 @@ local function biter_chunk(x, y, data)
end
local function out_of_map(x, y, data)
local surface = data.surface
surface.set_tiles({{name = 'out-of-map', position = {x = data.x, y = data.y}}})
local tiles = data.tiles
local p = {x = x, y = y}
tiles[#tiles + 1] = {name = 'out-of-map', position = p}
end
function Public.heavy_functions(x, y, data)
@ -1548,6 +1551,10 @@ function Public.heavy_functions(x, y, data)
return
end
if top_y > 32 then
game.forces.player.chart(surface, {{top_x, top_y}, {top_x + 31, top_y + 31}})
end
if top_y == -128 and top_x == -128 then
local pl = WPT.get().locomotive.position
for _, entity in pairs(
@ -1573,7 +1580,7 @@ function Public.heavy_functions(x, y, data)
end
if top_y > 75 then
biter_chunk(x, y, data)
biter_chunk(data)
return
end
@ -1583,30 +1590,4 @@ function Public.heavy_functions(x, y, data)
end
end
Event.add(
defines.events.on_chunk_generated,
function(e)
local surface = e.surface
local map_name = 'mountain_fortress_v3'
if string.sub(surface.name, 0, #map_name) ~= map_name then
return
end
local area = e.area
local left_top = area.left_top
if not surface then
return
end
if not surface.valid then
return
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
end
)
return Public

View File

@ -144,6 +144,7 @@ return {
gainsboro = {r = 220, g = 220, b = 220},
white_smoke = {r = 245, g = 245, b = 245},
white = {r = 255, g = 255, b = 255},
comfy = {r = 0.98, g = 0.66, b = 0.22},
jailed = {r = 255, g = 255, b = 255},
trusted = {r = 192, g = 192, b = 192},
regular = {r = 0.155, g = 0.540, b = 0.898},

View File

@ -1,6 +1,6 @@
local Debug = require 'utils.debug'
local is_closure = Debug.is_closure
local floor = math.floor
local getmetatable = getmetatable
local setmetatable = setmetatable
local PriorityQueue = {}
@ -26,15 +26,30 @@ end
function PriorityQueue.new(comparator)
if comparator == nil then
comparator = default_comparator
elseif is_closure(comparator) then
error('comparator cannot be a closure.', 2)
end
return {_comparator = comparator}
local mt = {comparator = comparator}
return setmetatable({}, mt)
end
function PriorityQueue.load(self, comparator)
if comparator == nil then
comparator = default_comparator
end
local mt = {comparator = comparator}
return setmetatable(self or {}, mt)
end
local function get_comparator(self)
local mt = getmetatable(self)
return mt.comparator
end
local function heapify_from_end_to_start(self)
local comparator = self._comparator
local comparator = get_comparator(self)
local pos = #self
while pos > 1 do
local parent = floor(pos * 0.5)
@ -49,7 +64,7 @@ local function heapify_from_end_to_start(self)
end
local function heapify_from_start_to_end(self)
local comparator = self._comparator
local comparator = get_comparator(self)
local parent = 1
local smallest = 1
local count = #self
@ -104,4 +119,4 @@ function PriorityQueue.peek(self)
return self[1]
end
return PriorityQueue
return PriorityQueue

View File

@ -42,6 +42,8 @@ Global.register(
callbacks = tbl.callbacks
task_queue = tbl.task_queue
primitives = tbl.primitives
PriorityQueue.load(callbacks, comparator)
end
)