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

Merge pull request #27 from M3wM3w/master

update from main
This commit is contained in:
hanakocz 2020-08-07 20:49:56 +02:00 committed by GitHub
commit 820ddde9d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 2121 additions and 445 deletions

View File

@ -8,10 +8,12 @@ local Global = require 'utils.global'
local Utils = require 'utils.core'
local Color = require 'utils.color_presets'
local Server = require 'utils.server'
local Jail = require 'utils.jail_data'
local Public = {}
local match = string.match
local capsule_bomb_threshold = 8
local de = defines.events
local format = string.format
@ -23,14 +25,20 @@ local this = {
corpse_history = {},
cancel_crafting_history = {},
whitelist_types = {},
permission_group_editing = {},
players_warned = {},
damage_history = {},
punish_cancel_craft = false,
log_tree_harvest = false,
do_not_check_trusted = true,
enable_autokick = true,
enable_autokick = false,
enable_autoban = false,
enable_jail = false,
enable_capsule_warning = false,
enable_capsule_cursor_warning = false
enable_capsule_cursor_warning = false,
required_playtime = 2592000,
damage_entity_threshold = 20,
explosive_threshold = 16
}
local blacklisted_types = {
@ -67,9 +75,14 @@ Global.register(
end
)
local function increment(t, k, v)
--[[
local function increment_key(t, k, v)
t[k][#t[k] + 1] = (v or 1)
end
]]
local function increment(t, v)
t[#t + 1] = (v or 1)
end
local function get_entities(item_name, entities)
local set = {}
@ -145,7 +158,9 @@ local function do_action(player, prefix, msg, ban_msg, kill)
end
elseif this.players_warned[player.index] == 1 then
this.players_warned[player.index] = 2
if this.enable_autokick then
if this.enable_jail then
Jail.try_ul_data(player, true, 'script')
elseif this.enable_autokick then
game.kick_player(player, msg)
end
else
@ -159,7 +174,7 @@ local function on_marked_for_deconstruction(event)
if not event.player_index then
return
end
local player = game.players[event.player_index]
local player = game.get_player(event.player_index)
if player.admin then
return
end
@ -172,7 +187,7 @@ local function on_marked_for_deconstruction(event)
playtime = player.online_time + tracker[player.name]
end
if playtime < 2592000 then
event.entity.cancel_deconstruction(game.players[event.player_index].force.name)
event.entity.cancel_deconstruction(game.get_player(event.player_index).force.name)
player.print('You have not grown accustomed to this technology yet.', {r = 0.22, g = 0.99, b = 0.99})
end
end
@ -180,7 +195,7 @@ end
local function on_player_ammo_inventory_changed(event)
local tracker = session.get_session_table()
local trusted = session.get_trusted_table()
local player = game.players[event.player_index]
local player = game.get_player(event.player_index)
if player.admin then
return
end
@ -204,7 +219,7 @@ local function on_player_ammo_inventory_changed(event)
end
local function on_player_joined_game(event)
local player = game.players[event.player_index]
local player = game.get_player(event.player_index)
if match(player.name, '^[Ili1|]+$') then
Server.ban_sync(player.name, '', '<script>') -- No reason given, to not give them any hints to change their name
end
@ -218,18 +233,18 @@ local function on_player_built_tile(event)
then
return
end
local player = game.players[event.player_index]
local player = game.get_player(event.player_index)
local surface = event.surface_index
--landfill history--
if not this.landfill_history[player.index] then
this.landfill_history[player.index] = {}
if not this.landfill_history then
this.landfill_history = {}
end
if #this.landfill_history[player.index] > 100 then
this.landfill_history[player.index] = {}
if #this.landfill_history > 1000 then
this.landfill_history = {}
end
local t = math.abs(math.floor((game.tick) / 3600))
local str = '[' .. t .. '] '
@ -239,7 +254,7 @@ local function on_player_built_tile(event)
str = str .. placed_tiles[1].position.y
str = str .. ' '
str = str .. 'surface:' .. surface
increment(this.landfill_history, player.index, str)
increment(this.landfill_history, str)
end
local function on_built_entity(event)
@ -250,7 +265,7 @@ local function on_built_entity(event)
end
if event.created_entity.type == 'entity-ghost' then
local player = game.players[event.player_index]
local player = game.get_player(event.player_index)
if player.admin then
return
@ -274,7 +289,7 @@ end
--Capsule History and Antigrief
local function on_player_used_capsule(event)
local trusted = session.get_trusted_table()
local player = game.players[event.player_index]
local player = game.get_player(event.player_index)
if trusted[player.name] and this.do_not_check_trusted then
return
@ -332,11 +347,11 @@ local function on_player_used_capsule(event)
msg = player.name .. ' used ' .. name
end
if not this.capsule_history[player.index] then
this.capsule_history[player.index] = {}
if not this.capsule_history then
this.capsule_history = {}
end
if #this.capsule_history[player.index] > 100 then
this.capsule_history[player.index] = {}
if #this.capsule_history > 1000 then
this.capsule_history = {}
end
local t = math.abs(math.floor((game.tick) / 3600))
@ -348,10 +363,137 @@ local function on_player_used_capsule(event)
str = str .. math.floor(position.y)
str = str .. ' '
str = str .. 'surface:' .. player.surface.index
increment(this.capsule_history, player.index, str)
increment(this.capsule_history, str)
end
end
-- Damage things
local function on_entity_damaged(event)
local cause = event.cause
if not cause or not cause.valid or cause.force.index ~= 1 then
return
end
local force = event.force
if not force.index == 1 then
return
end
if cause.name ~= 'character' then
return
end
local entity = event.entity
if not entity or not entity.valid then
return
end
if entity.force.index ~= 1 then
return
end
local trusted = session.get_trusted_table()
local tracker = session.get_session_table()
local player = game.get_player(event.cause.player.index)
if player.admin then
return
end
if trusted[player.name] and this.do_not_check_trusted then
return
end
local name = entity.name
local e_type = entity.type
local position = entity.position
local msg
local playtime = player.online_time
if tracker[player.name] then
playtime = player.online_time + tracker[player.name]
end
if playtime > this.required_playtime then
return
end
if this.enable_capsule_warning then
if not this.damage_history[player.index] then
this.damage_history[player.index] = {}
this.damage_history[player.index].targets = ''
this.damage_history[player.index].count = 0
end
if name ~= 'entity-ghost' and name ~= 'character' and not blacklisted_types[e_type] then
if chests[e_type] then
local inv = entity.get_inventory(1)
local contents = inv.get_contents()
if next(contents) == nil then
return
else
for n, count in pairs(contents) do
if n == 'explosives' then
if count < this.explosive_threshold then
return
end
end
end
end
end
name = name:gsub('-', ' ')
local index = this.damage_history[player.index].targets:find(name)
if not index then
this.damage_history[player.index].targets = this.damage_history[player.index].targets .. name .. ', '
end
this.damage_history[player.index].count = this.damage_history[player.index].count + 1
end
if this.damage_history[player.index].count <= this.damage_entity_threshold then
return
end
local target_names = this.damage_history[player.index].targets
local prefix = '{Friendly Fire}'
msg =
format(
player.name .. ' damaged: %s counted times: %s',
target_names,
this.damage_history[player.index].count
)
local ban_msg =
format(
'Damaged: %s counted times: %s. This action was performed automatically. Visit getcomfy.eu/discord for forgiveness',
target_names,
this.damage_history[player.index].count
)
do_action(player, prefix, msg, ban_msg, true)
else
msg = player.name .. ' damaged ' .. name
end
this.damage_history[player.index].count = 0
this.damage_history[player.index].targets = ''
if not this.friendly_fire_history then
this.friendly_fire_history = {}
end
if #this.friendly_fire_history > 1000 then
this.friendly_fire_history = {}
end
local t = math.abs(math.floor((game.tick) / 3600))
local str = '[' .. t .. '] '
str = str .. msg
str = str .. ' at X:'
str = str .. math.floor(position.x)
str = str .. ' Y:'
str = str .. math.floor(position.y)
str = str .. ' '
str = str .. 'surface:' .. player.surface.index
increment(this.friendly_fire_history, str)
end
--Friendly Fire History
local function on_entity_died(event)
local cause = event.cause
@ -364,12 +506,12 @@ local function on_entity_died(event)
local player = cause.player
name = player.name
if not this.friendly_fire_history[cause.player.index] then
this.friendly_fire_history[cause.player.index] = {}
if not this.friendly_fire_history then
this.friendly_fire_history = {}
end
if #this.friendly_fire_history[cause.player.index] > 100 then
this.friendly_fire_history[cause.player.index] = {}
if #this.friendly_fire_history > 1000 then
this.friendly_fire_history = {}
end
local chest
@ -381,12 +523,17 @@ local function on_entity_died(event)
for n, count in pairs(contents) do
if n == 'explosives' then
item_types = item_types .. n .. ' count: ' .. count .. '. '
item_types = item_types .. '[color=yellow]' .. n .. '[/color] count: ' .. count .. ' '
end
end
chest = event.entity.name .. ' with content ' .. item_types
if string.len(item_types) > 0 then
chest = event.entity.name .. ' with content ' .. item_types
else
chest = '[color=yellow]' .. event.entity.name .. '[/color]'
end
else
chest = event.entity.name
chest = '[color=yellow]' .. event.entity.name .. '[/color]'
end
local t = math.abs(math.floor((game.tick) / 3600))
@ -399,7 +546,7 @@ local function on_entity_died(event)
str = str .. math.floor(event.entity.position.y)
str = str .. ' '
str = str .. 'surface:' .. event.entity.surface.index
increment(this.friendly_fire_history, player.index, str)
increment(this.friendly_fire_history, str)
elseif not blacklisted_types[event.entity.type] and this.whitelist_types[event.entity.type] then
if cause then
if cause.force.name ~= 'player' then
@ -413,7 +560,7 @@ local function on_entity_died(event)
else
str = str .. 'someone destroyed '
end
str = str .. event.entity.name
str = str .. '[color=yellow]' .. event.entity.name .. '[/color]'
str = str .. ' at X:'
str = str .. math.floor(event.entity.position.x)
str = str .. ' Y:'
@ -422,28 +569,16 @@ local function on_entity_died(event)
str = str .. 'surface:' .. event.entity.surface.index
if cause and cause.name == 'character' and cause.player then
if not this.friendly_fire_history[cause.player.index] then
this.friendly_fire_history[cause.player.index] = {}
end
if #this.friendly_fire_history[cause.player.index] > 100 then
this.friendly_fire_history[cause.player.index] = {}
end
increment(this.friendly_fire_history, cause.player.index, str)
increment(this.friendly_fire_history, str)
else
if not this.friendly_fire_history[99999] then
this.friendly_fire_history[99999] = {}
end
if #this.friendly_fire_history[99999] > 100 then
this.friendly_fire_history[99999] = {}
end
increment(this.friendly_fire_history, 99999, str)
increment(this.friendly_fire_history, str)
end
end
end
--Mining Thieves History
local function on_player_mined_entity(event)
local player = game.players[event.player_index]
local player = game.get_player(event.player_index)
if not player or not player.valid then
return
end
@ -454,23 +589,23 @@ local function on_player_mined_entity(event)
end
if this.whitelist_types[entity.type] then
if not this.mining_history[player.index] then
this.mining_history[player.index] = {}
if not this.mining_history then
this.mining_history = {}
end
if #this.mining_history[player.index] > 100 then
this.mining_history[player.index] = {}
if #this.mining_history > 1000 then
this.mining_history = {}
end
local t = math.abs(math.floor((game.tick) / 3600))
local str = '[' .. t .. '] '
str = str .. player.name .. ' mined '
str = str .. entity.name
str = str .. '[color=yellow]' .. entity.name .. '[/color]'
str = str .. ' at X:'
str = str .. math.floor(entity.position.x)
str = str .. ' Y:'
str = str .. math.floor(entity.position.y)
str = str .. ' '
str = str .. 'surface:' .. entity.surface.index
increment(this.mining_history, player.index, str)
increment(this.mining_history, str)
return
end
@ -486,25 +621,25 @@ local function on_player_mined_entity(event)
if blacklisted_types[event.entity.type] then
return
end
if not this.mining_history[player.index] then
this.mining_history[player.index] = {}
if not this.mining_history then
this.mining_history = {}
end
if #this.mining_history[player.index] > 100 then
this.mining_history[player.index] = {}
if #this.mining_history > 1000 then
this.mining_history = {}
end
local t = math.abs(math.floor((game.tick) / 3600))
local str = '[' .. t .. '] '
str = str .. player.name .. ' mined '
str = str .. event.entity.name
str = str .. '[color=yellow]' .. event.entity.name .. '[/color]'
str = str .. ' at X:'
str = str .. math.floor(event.entity.position.x)
str = str .. ' Y:'
str = str .. math.floor(event.entity.position.y)
str = str .. ' '
str = str .. 'surface:' .. event.entity.surface.index
increment(this.mining_history, player.index, str)
increment(this.mining_history, str)
end
local function on_gui_opened(event)
@ -514,8 +649,8 @@ local function on_gui_opened(event)
if event.entity.name ~= 'character-corpse' then
return
end
local player = game.players[event.player_index]
local corpse_owner = game.players[event.entity.character_corpse_player_index]
local player = game.get_player(event.player_index)
local corpse_owner = game.get_player(event.entity.character_corpse_player_index)
if not corpse_owner then
return
end
@ -531,29 +666,29 @@ local function on_gui_opened(event)
if player.name ~= corpse_owner.name then
Utils.action_warning('{Corpse}', player.name .. ' is looting ' .. corpse_owner.name .. '´s body.')
if not this.corpse_history[player.index] then
this.corpse_history[player.index] = {}
if not this.corpse_history then
this.corpse_history = {}
end
if #this.corpse_history[player.index] > 100 then
this.corpse_history[player.index] = {}
if #this.corpse_history > 1000 then
this.corpse_history = {}
end
local t = math.abs(math.floor((game.tick) / 3600))
local str = '[' .. t .. '] '
str = str .. player.name .. ' opened '
str = str .. corpse_owner.name .. ' body'
str = str .. '[color=yellow]' .. corpse_owner.name .. '[/color] body'
str = str .. ' at X:'
str = str .. math.floor(event.entity.position.x)
str = str .. ' Y:'
str = str .. math.floor(event.entity.position.y)
str = str .. ' '
str = str .. 'surface:' .. event.entity.surface.index
increment(this.corpse_history, player.index, str)
increment(this.corpse_history, str)
end
end
local function on_pre_player_mined_item(event)
local player = game.players[event.player_index]
local player = game.get_player(event.player_index)
if not player or not player.valid then
return
@ -568,7 +703,7 @@ local function on_pre_player_mined_item(event)
return
end
local corpse_owner = game.players[entity.character_corpse_player_index]
local corpse_owner = game.get_player(entity.character_corpse_player_index)
if not corpse_owner then
return
end
@ -582,31 +717,31 @@ local function on_pre_player_mined_item(event)
end
if player.name ~= corpse_owner.name then
Utils.action_warning('{Corpse}', player.name .. ' has looted ' .. corpse_owner.name .. '´s body.')
if not this.corpse_history[player.index] then
this.corpse_history[player.index] = {}
if not this.corpse_history then
this.corpse_history = {}
end
if #this.corpse_history[player.index] > 100 then
this.corpse_history[player.index] = {}
if #this.corpse_history > 1000 then
this.corpse_history = {}
end
local t = math.abs(math.floor((game.tick) / 3600))
local str = '[' .. t .. '] '
str = str .. player.name .. ' mined '
str = str .. corpse_owner.name .. ' body'
str = str .. '[color=yellow]' .. corpse_owner.name .. '[/color] body'
str = str .. ' at X:'
str = str .. math.floor(entity.position.x)
str = str .. ' Y:'
str = str .. math.floor(entity.position.y)
str = str .. ' '
str = str .. 'surface:' .. entity.surface.index
increment(this.corpse_history, player.index, str)
increment(this.corpse_history, str)
end
end
local function on_player_cursor_stack_changed(event)
local tracker = session.get_session_table()
local trusted = session.get_trusted_table()
local player = game.players[event.player_index]
local player = game.get_player(event.player_index)
if player.admin then
return
end
@ -645,7 +780,7 @@ local function on_player_cursor_stack_changed(event)
end
local function on_player_cancelled_crafting(event)
local player = game.players[event.player_index]
local player = game.get_player(event.player_index)
local crafting_queue_item_count = event.items.get_item_count()
local free_slots = player.get_main_inventory().count_empty_stacks()
@ -671,17 +806,17 @@ local function on_player_cancelled_crafting(event)
)
end
if not this.cancel_crafting_history[player.index] then
this.cancel_crafting_history[player.index] = {}
if not this.cancel_crafting_history then
this.cancel_crafting_history = {}
end
if #this.cancel_crafting_history[player.index] > 100 then
this.cancel_crafting_history[player.index] = {}
if #this.cancel_crafting_history > 1000 then
this.cancel_crafting_history = {}
end
local t = math.abs(math.floor((game.tick) / 3600))
local str = '[' .. t .. '] '
str = str .. player.name .. ' canceled '
str = str .. ' item ' .. event.recipe.name
str = str .. ' item [color=yellow]' .. event.recipe.name .. '[/color]'
str = str .. ' count was a total of: ' .. crafting_queue_item_count
str = str .. ' at X:'
str = str .. math.floor(player.position.x)
@ -689,7 +824,7 @@ local function on_player_cancelled_crafting(event)
str = str .. math.floor(player.position.y)
str = str .. ' '
str = str .. 'surface:' .. player.surface.index
increment(this.cancel_crafting_history, player.index, str)
increment(this.cancel_crafting_history, str)
end
end
@ -710,7 +845,81 @@ local function on_init()
end
end
--- This will reset the table of this
local function on_permission_group_added(event)
local player = game.get_player(event.player_index)
if not player or not player.valid then
return
end
local group = event.group
if group then
Utils.log_msg('{Permission_Group}', player.name .. ' added ' .. group.name)
end
end
local function on_permission_group_deleted(event)
local player = game.get_player(event.player_index)
if not player or not player.valid then
return
end
local name = event.group_name
local id = event.id
if name then
Utils.log_msg('{Permission_Group}', player.name .. ' deleted ' .. name .. ' with ID: ' .. id)
end
end
local function on_permission_group_edited(event)
local player = game.get_player(event.player_index)
if not player or not player.valid then
return
end
local group = event.group
if group then
local action = ''
for k, v in pairs(defines.input_action) do
if event.action == v then
action = k
end
end
Utils.log_msg(
'{Permission_Group}',
player.name .. ' edited ' .. group.name .. ' with type: ' .. event.type .. ' with action: ' .. action
)
end
if event.other_player_index then
local other_player = game.get_player(event.other_player_index)
if other_player and other_player.valid then
Utils.log_msg(
'{Permission_Group}',
player.name ..
' moved ' .. other_player.name .. ' with type: ' .. event.type .. ' to group: ' .. group.name
)
end
end
local old_name = event.old_name
local new_name = event.new_name
if old_name and new_name then
Utils.log_msg(
'{Permission_Group}',
player.name .. ' renamed ' .. group.name .. '. New name: ' .. new_name .. '. Old Name: ' .. old_name
)
end
end
local function on_permission_string_imported(event)
local player = game.get_player(event.player_index)
if not player or not player.valid then
return
end
Utils.log_msg('{Permission_Group}', player.name .. ' imported a permission string')
end
--- This will reset the table of antigrief
function Public.reset_tables()
this.landfill_history = {}
this.capsule_history = {}
@ -771,27 +980,57 @@ function Public.enable_capsule_cursor_warning(value)
return this.enable_capsule_cursor_warning
end
--- If the script should jail a person instead of kicking them
---@param value <string>
function Public.enable_jail(value)
if value then
this.enable_jail = value
end
return this.enable_jail
end
--- Defines what the threshold for amount of explosives in chest should be - logged or not.
---@param value <string>
function Public.explosive_threshold(value)
if value then
this.explosive_threshold = value
end
return this.explosive_threshold
end
--- Defines what the threshold for amount of times before the script should take action.
---@param value <string>
function Public.damage_entity_threshold(value)
if value then
this.damage_entity_threshold = value
end
return this.damage_entity_threshold
end
--- This is used for the RPG module, when casting capsules.
---@param player <LuaPlayer>
---@param position <EventPosition>
---@param msg <string>
function Public.insert_into_capsule_history(player, position, msg)
if not this.capsule_history[player.index] then
this.capsule_history[player.index] = {}
if not this.capsule_history then
this.capsule_history = {}
end
if #this.capsule_history[player.index] > 100 then
this.capsule_history[player.index] = {}
if #this.capsule_history > 1000 then
this.capsule_history = {}
end
local t = math.abs(math.floor((game.tick) / 3600))
local str = '[' .. t .. '] '
str = str .. msg
str = str .. '[color=yellow]' .. msg .. '[/color]'
str = str .. ' at X:'
str = str .. math.floor(position.x)
str = str .. ' Y:'
str = str .. math.floor(position.y)
str = str .. ' '
str = str .. 'surface:' .. player.surface.index
increment(this.capsule_history, player.index, str)
increment(this.capsule_history, str)
end
--- Returns the table.
@ -805,17 +1044,22 @@ function Public.get(key)
end
Event.on_init(on_init)
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_built_entity, on_built_entity)
Event.add(defines.events.on_gui_opened, on_gui_opened)
Event.add(defines.events.on_marked_for_deconstruction, on_marked_for_deconstruction)
Event.add(defines.events.on_player_ammo_inventory_changed, on_player_ammo_inventory_changed)
Event.add(defines.events.on_player_built_tile, on_player_built_tile)
Event.add(defines.events.on_pre_player_mined_item, on_pre_player_mined_item)
Event.add(defines.events.on_player_used_capsule, on_player_used_capsule)
Event.add(defines.events.on_player_cursor_stack_changed, on_player_cursor_stack_changed)
Event.add(defines.events.on_player_cancelled_crafting, on_player_cancelled_crafting)
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
Event.add(de.on_player_mined_entity, on_player_mined_entity)
Event.add(de.on_entity_died, on_entity_died)
Event.add(de.on_entity_damaged, on_entity_damaged)
Event.add(de.on_built_entity, on_built_entity)
Event.add(de.on_gui_opened, on_gui_opened)
Event.add(de.on_marked_for_deconstruction, on_marked_for_deconstruction)
Event.add(de.on_player_ammo_inventory_changed, on_player_ammo_inventory_changed)
Event.add(de.on_player_built_tile, on_player_built_tile)
Event.add(de.on_pre_player_mined_item, on_pre_player_mined_item)
Event.add(de.on_player_used_capsule, on_player_used_capsule)
Event.add(de.on_player_cursor_stack_changed, on_player_cursor_stack_changed)
Event.add(de.on_player_cancelled_crafting, on_player_cancelled_crafting)
Event.add(de.on_player_joined_game, on_player_joined_game)
Event.add(de.on_permission_group_added, on_permission_group_added)
Event.add(de.on_permission_group_deleted, on_permission_group_deleted)
Event.add(de.on_permission_group_edited, on_permission_group_edited)
Event.add(de.on_permission_string_imported, on_permission_string_imported)
return Public

View File

@ -270,38 +270,19 @@ local function draw_events(data)
}
)
scroll_pane.style.maximal_height = 200
scroll_pane.style.minimal_width = 790
end
local target_player_name = frame['admin_player_select'].items[frame['admin_player_select'].selected_index]
if game.players[target_player_name] then
local target_player = game.players[target_player_name].index
if not history_index or not history_index[history] or #history_index[history] <= 0 then
return
end
for _, value in pairs(history_index[history][target_player]) do
if search_text then
local success = contains_text(value, nil, search_text)
if not success then
goto continue
end
end
frame.datalog.add(
{
type = 'label',
caption = value,
tooltip = 'Click to open mini camera.'
}
)
::continue::
end
else
for key, value in pairs(history_index[history]) do
for t = 1, #value do
for i = #history_index[history], 1, -1 do
if history_index[history][i]:find(target_player_name) then
if search_text then
local success = contains_text(value, t, search_text)
local success = contains_text(history_index[history][i], nil, search_text)
if not success then
goto continue
end
@ -310,13 +291,31 @@ local function draw_events(data)
frame.datalog.add(
{
type = 'label',
caption = history_index[history][key][t],
caption = history_index[history][i],
tooltip = 'Click to open mini camera.'
}
)
::continue::
end
end
else
for i = #history_index[history], 1, -1 do
if search_text then
local success = contains_text(history_index[history][i], nil, search_text)
if not success then
goto continue
end
end
frame.datalog.add(
{
type = 'label',
caption = history_index[history][i],
tooltip = 'Click to open mini camera.'
}
)
::continue::
end
end
end

View File

@ -298,7 +298,9 @@ end
function Public.alphanumeric_only(value)
if value then
this.alphanumeric = value or false
this.alphanumeric = value
else
this.alphanumeric = false
end
end

View File

@ -226,7 +226,7 @@ local function redraw_poll_viewer_content(data)
local poll_enabled = do_remaining_time(poll, remaining_time_label)
local question_flow = poll_viewer_content.add {type = 'table', column_count = 2}
if trusted[player.name] or player.admin then
if player.admin then
local edit_button =
question_flow.add {
type = 'sprite-button',

View File

@ -1,2 +1,3 @@
require "commands.misc"
require "commands.jail"
require 'commands.misc'
require 'commands.jail'
require 'commands.where'

83
commands/where.lua Normal file
View File

@ -0,0 +1,83 @@
-- simply use /where ::LuaPlayerName to locate them
local Color = require 'utils.color_presets'
local Event = require 'utils.event'
local function validate_player(player)
if not player then
return false
end
if not player.valid then
return false
end
if not player.character then
return false
end
if not player.connected then
return false
end
if not game.players[player.index] then
return false
end
return true
end
local function create_mini_camera_gui(player, caption, position, surface)
if player.gui.center['where_camera'] then
player.gui.center['where_camera'].destroy()
end
local frame = player.gui.center.add({type = 'frame', name = 'where_camera', caption = caption})
surface = tonumber(surface)
local camera =
frame.add(
{
type = 'camera',
name = 'where_camera',
position = position,
zoom = 0.4,
surface_index = surface
}
)
camera.style.minimal_width = 740
camera.style.minimal_height = 580
end
commands.add_command(
'where',
'Locates a player',
function(cmd)
local player = game.player
if validate_player(player) then
if not cmd.parameter then
return
end
local target_player = game.players[cmd.parameter]
if validate_player(target_player) then
create_mini_camera_gui(player, target_player.name, target_player.position, target_player.surface.index)
else
player.print('Please type a name of a player who is connected.', Color.warning)
end
else
return
end
end
)
local function on_gui_click(event)
local player = game.players[event.player_index]
if not event.element.valid then
return
end
local name = event.element.name
if name == 'where_camera' then
player.gui.center['where_camera'].destroy()
return
end
end
Event.add(defines.events.on_gui_click, on_gui_click)

View File

@ -5,104 +5,215 @@ local table_remove = table.remove
local math_random = math.random
local room_spacing = 4
local room_spacing2 = room_spacing * 2
local function build_room(surface, position, vector, room_center_position, room_radius)
local function build_room_rect(surface, position, vector, room_center_position, room_size, offset)
local room = {}
local a = room_radius - 1
--local a = room_radius - 1
local room_area = {
left_top = {x = room_center_position.x - a, y = room_center_position.y - a},
right_bottom = {x = room_center_position.x + room_radius, y = room_center_position.y + room_radius}
left_top = {x = room_center_position.x - room_size.x +1, y = room_center_position.y - room_size.y+1},
right_bottom = {x = room_center_position.x + room_size.x, y = room_center_position.y + room_size.y}
}
room.room_tiles = surface.find_tiles_filtered({area = room_area})
room.path_tiles = {}
for d = 1, room_spacing, 1 do
local p = {position.x + vector[1] * d, position.y + vector[2] * d}
local p = {position.x + vector[1] * d + offset.x, position.y + vector[2] * d + offset.y}
local tile = surface.get_tile(p)
table_insert(room.path_tiles, tile)
end
room.entrance_tile = surface.get_tile({position.x + vector[1] * (room_spacing + 1), position.y + vector[2] * (room_spacing + 1)})
room.entrance_tile = surface.get_tile({position.x + offset.x + vector[1] * (room_spacing + 1), position.y + offset.y + vector[2] * (room_spacing + 1)})
room.room_border_tiles = {}
local left_top = {x = room_area.left_top.x - 1, y = room_area.left_top.y - 1}
local right_bottom = {x = room_area.right_bottom.x, y = room_area.right_bottom.y}
local t = room.room_border_tiles
for d = 1, room_radius * 2, 1 do
for d = 0, room_size.x * 2, 1 do
table_insert(t, surface.get_tile({left_top.x + d, left_top.y}))
table_insert(t, surface.get_tile({left_top.x, left_top.y + d}))
table_insert(t, surface.get_tile({right_bottom.x - d, right_bottom.y}))
table_insert(t, surface.get_tile({right_bottom.x, right_bottom.y - d}))
table_insert(t, surface.get_tile({left_top.x + d, right_bottom.y}))
end
for d = 1, room_size.y * 2-1, 1 do
table_insert(t, surface.get_tile({left_top.x , left_top.y + d}))
table_insert(t, surface.get_tile({right_bottom.x, left_top.y + d}))
end
table_insert(t, surface.get_tile(left_top))
table_insert(t, surface.get_tile(right_bottom))
table_insert(t, surface.get_tile({left_top.x + room_radius * 2, left_top.y + room_radius * 2}))
table_insert(t, surface.get_tile({right_bottom.x - (room_radius * 2), right_bottom.y - (room_radius * 2)}))
room.center = room_center_position
room.radius = room_radius
room.radius = math.min(room_size.x,room_size.y)
room.size = room_size
return room
end
local function scan_direction(surface, position, vector, room_radius)
local valid_tile_count = 0
for d = 1, room_radius * 2 + room_spacing * 2, 1 do
local p = {position.x + vector[1] * d, position.y + vector[2] * d}
local tile = surface.get_tile(p)
if not tile.collides_with("resource-layer") then
return false
end
end
local a = room_radius + room_spacing + 1
local b = room_radius + room_spacing
local room_center_position = {x = position.x + vector[1] * a, y = position.y + vector[2] * a}
local search_area = {
{x = room_center_position.x - b, y = room_center_position.y - b},
{x = room_center_position.x + b + 1, y = room_center_position.y + b + 1}
}
local function scan_area_empty(surface,search_area)
local tiles = surface.find_tiles_filtered({area = search_area})
for _, tile in pairs(tiles) do
if not tile.collides_with("resource-layer") then
return false
end
end
return build_room(surface, position, vector, room_center_position, room_radius)
return true
end
local function get_room_tiles(surface, position, room_radius)
local function scan_strip_empty(surface, position, vector, length)
for d = 0, length, 1 do
local p = {position.x + vector[1] * d, position.y + vector[2] * d}
local tile = surface.get_tile(p)
if not tile.collides_with("resource-layer") then
return false
end
end
return true
end
--Scans the X and Y independantly for best size
local function scan_direction_full(surface, position, vector, room_max,room_min)
local best = {x=room_min,y=room_min}
local a = room_min + room_spacing + 1
local room_center_pos = {x = position.x + vector[1] * a, y = position.y + vector[2] * a}
local search_area = {
{x = room_center_pos.x - best.x - room_spacing, y = room_center_pos.y - best.y - room_spacing},
{x = room_center_pos.x + best.x + room_spacing+ 1, y = room_center_pos.y + best.y + room_spacing + 1}
}
if not scan_area_empty(surface,search_area) then
return {x=0,y=0}
end
local x_end = false
local y_end = false
if vector[1] == 0 then
local yy = position.y + vector[2]
repeat
if not x_end then
if not scan_strip_empty(surface, {x = position.x + best.x + room_spacing + 1, y = yy}, vector, best.y*2 + room_spacing2) or
not scan_strip_empty(surface, {x = position.x - best.x - room_spacing - 1, y = yy}, vector, best.y*2 + room_spacing2) then
x_end = true
else
best.x = best.x + 1
end
if best.x >= room_max.x then x_end = true end
end
if not y_end then
local xx = position.x - best.x - room_spacing - 1
if not scan_strip_empty(surface, {x = xx, y = position.y + vector[2] * (best.y*2+room_spacing2+1)}, {1,0}, best.x*2 + room_spacing2) or
not scan_strip_empty(surface, {x = xx, y = position.y + vector[2] * (best.y*2+room_spacing2+2)}, {1,0}, best.x*2 + room_spacing2) then
y_end = true
else
best.y = best.y + 1
end
if best.y >= room_max.y then y_end = true end
end
until(x_end and y_end)
else
local xx = position.x + vector[1]
repeat
if not y_end then
if not scan_strip_empty(surface, {x = xx, y = position.y+best.y+room_spacing+1}, vector, best.x*2 + room_spacing2) or
not scan_strip_empty(surface, {x = xx, y = position.y-best.y-room_spacing-1}, vector, best.x*2 + room_spacing2) then
y_end = true
else
best.y = best.y + 1
end
if best.y >= room_max.y then y_end = true end
end
if not x_end then
local yy = position.y - best.y - room_spacing - 1
if not scan_strip_empty(surface, {x = position.x + vector[1] * (best.x*2+room_spacing2+1), y = yy}, {0,1}, best.y*2 + room_spacing2) or
not scan_strip_empty(surface, {x = position.x + vector[1] * (best.x*2+room_spacing2+2), y = yy}, {0,1}, best.y*2 + room_spacing2) then
x_end = true
else
best.x = best.x + 1
end
if best.x >= room_max.x then x_end = true end
end
until(x_end and y_end)
end
return best
end
--get room tiles and build a room with best fit and add a chance for offset
local function get_room_tiles_wiggle(surface, position, size, shape)
local vectors = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}}
table_shuffle_table(vectors)
for _, v in pairs(vectors) do
local room = scan_direction(surface, position, v, room_radius)
if room then
return room
end
local room_max = {x = size,y= size}
if shape == "wide" then
room_max.x = room_max.x +4
elseif shape == "tall" then
room_max.y = room_max.y +4
elseif shape == "big" then
room_max.x = room_max.x +3
room_max.y = room_max.y +3
end
for _, v in pairs(vectors) do
local room = scan_direction(surface, position, v, room_radius)
if room then
return room
local full = scan_direction_full(surface, position, v, room_max,3)
if full.x > 0 then
local new_pos = position
local offset = {x=0,y=0}
if v[1] == 0 then
if full.x > 6 then
local max_roll = math.abs(full.x*0.5)
if shape == "square" then max_roll = math.min(max_roll, math.abs(full.y*0.5)) end
local roll = math_random(1 - max_roll,max_roll - 1)
new_pos.x = new_pos.x + roll
offset.x = -roll
full.x = full.x - (1 + math.abs(roll * 0.5))
end
else
if full.y > 6 then
local max_roll = math.abs(full.y*0.5)
if shape == "square" then max_roll = math.min(max_roll, math.abs(full.x*0.5)) end
local roll = math_random(1 - max_roll,max_roll - 1)
new_pos.y = new_pos.y + roll
offset.y = -roll
full.y = full.y - (1 + math.abs(roll * 0.5))
end
end
if shape == "square" then
--game.print("forcing square")
if full.x > full.y then
full.x = full.y
else
full.y = full.x
end
end
local room_center_position = {x = new_pos.x + v[1] * (full.x + room_spacing + 1), y = new_pos.y + v[2] * (full.y + room_spacing + 1)}
return build_room_rect(surface, new_pos, v, room_center_position, full, offset)
end
end
end
local function expand_path_tiles_width(surface, room)
if not room then return end
local max_expansion_count = 0
if math_random(1, 3) == 1 then max_expansion_count = 1 end
if math_random(1, 9) == 1 then max_expansion_count = 2 end
if max_expansion_count == 0 then return end
local max_expansion_count = 1
if math_random(1, 4) == 1 then max_expansion_count = 2 end
if math_random(1, 16) == 1 then max_expansion_count = 3 end
--if max_expansion_count == 0 then return end
local path_tiles = room.path_tiles
local vectors = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}}
@ -218,32 +329,32 @@ local function build_bridge(surface, position)
end
function Public.get_room(surface, position)
local room_sizes = {}
for i = 1, 14, 1 do
room_sizes[i] = i + 1
function Public.get_room(surface, position, shape)
if not shape then
shape = "square"
end
table_shuffle_table(room_sizes)
local last_size = room_sizes[1]
for i = 1, #room_sizes, 1 do
if room_sizes[i] <= last_size then
last_size = room_sizes[i]
local room = get_room_tiles(surface, position, last_size)
expand_path_tiles_width(surface, room)
if room then
return room
end
end
local room_max = math_random(3,14)
local room = get_room_tiles_wiggle(surface, position, room_max, shape)
if room then
expand_path_tiles_width(surface, room)
return room
end
local room = build_bridge(surface, position)
expand_path_tiles_width(surface, room)
if room then return room end
if room then
expand_path_tiles_width(surface, room)
return room
end
end
function Public.draw_random_room(surface, position)
local room = Public.get_room(surface, position)
function Public.draw_random_room(surface, position,shape)
if not shape then
shape = "square"
end
local room = Public.get_room(surface, position,shape)
if not room then return end
for _, tile in pairs(room.path_tiles) do
@ -262,4 +373,4 @@ function Public.draw_random_room(surface, position)
end
end
return Public
return Public

View File

@ -1,6 +1,7 @@
local Price_raffle = require 'maps.expanse.price_raffle'
local Public = {}
local ores = {"copper-ore", "iron-ore", "stone", "coal"}
local price_modifiers = {
["unit-spawner"] = -256,
["unit"] = -16,
@ -163,6 +164,14 @@ function Public.expand(expanse, left_top)
surface.spill_item_stack({a, a + 2}, {name = "small-plane", count = 1}, false, nil, false)
surface.spill_item_stack({a + 0.5, a + 2.5}, {name = "small-plane", count = 1}, false, nil, false)
surface.spill_item_stack({a - 0.5, a + 2.5}, {name = "small-plane", count = 1}, false, nil, false)
for x = 0, square_size, 1 do
for y = 0, square_size, 1 do
if surface.can_place_entity({name = "wooden-chest", position = {x, y}}) and surface.can_place_entity({name = "coal", position = {x, y}, amount = 1}) then
surface.create_entity({name = ores[(x + y) % 4 + 1], position = {x, y}, amount = 1000})
end
end
end
end
end
@ -171,7 +180,7 @@ local function init_container(expanse, entity)
if not left_top then return end
local cell_value = get_cell_value(expanse, left_top)
local item_stacks = {}
local roll_count = 2
for _ = 1, roll_count, 1 do

View File

@ -1,7 +1,15 @@
-- a map where you feed hungry boxes, which unlocks new territory, with even more hungry boxes by mewmew
--CONFIGS
local override_nauvis = true -- adds custom mixed ores and raises frequency of resources
local cell_size = 15 -- size of each territory to unlock
local chance_to_receive_token = 0.50 -- chance of a hungry chest, dropping a token after unlocking, can be above 1 for multiple
require 'modules.satellite_score'
local Event = require 'utils.event'
local Functions = require 'maps.expanse.functions'
local GetNoise = require "utils.get_noise"
local Global = require 'utils.global'
local Map_info = require "modules.map_info"
@ -21,9 +29,9 @@ local function set_nauvis()
["stone"] = {frequency = 10, size = 0.7, richness = 0.5,},
["copper-ore"] = {frequency = 10, size = 0.7, richness = 0.75,},
["iron-ore"] = {frequency = 10, size = 0.7, richness = 1,},
["uranium-ore"] = {frequency = 10, size = 0.5, richness = 1,},
["crude-oil"] = {frequency = 25, size = 1.5, richness = 1.5,},
["trees"] = {frequency = 1.5, size = 1, richness = 1},
["uranium-ore"] = {frequency = 10, size = 0.7, richness = 1,},
["crude-oil"] = {frequency = 20, size = 1.5, richness = 1.5,},
["trees"] = {frequency = 1.75, size = 1.25, richness = 1},
["enemy-base"] = {frequency = 10, size = 2, richness = 1},
}
map_gen_settings.starting_area = 0.25
@ -59,7 +67,9 @@ local function reset()
}
game.create_surface("expanse", map_gen_settings)
--set_nauvis()
if override_nauvis then
set_nauvis()
end
local source_surface = game.surfaces[expanse.source_surface]
source_surface.request_to_generate_chunks({x = 0, y = 0}, 4)
@ -80,8 +90,43 @@ local function reset()
end
end
local ores = {"copper-ore", "iron-ore", "stone", "coal"}
local function generate_ore(surface, left_top)
local seed = game.surfaces[1].map_gen_settings.seed
local left_top_x = left_top.x
local left_top_y = left_top.y
--Draw the mixed ore patches.
for x = 0, 31, 1 do
for y = 0, 31, 1 do
local pos = {x = left_top_x + x, y = left_top_y + y}
if surface.can_place_entity({name = "iron-ore", position = pos}) then
local noise = GetNoise("smol_areas", pos, seed)
if math.abs(noise) > 0.78 then
local amount = 500 + math.sqrt(pos.x ^ 2 + pos.y ^ 2) * 2
local i = math.floor(noise * 40 + math.abs(pos.x) * 0.05) % 4 + 1
surface.create_entity({name = ores[i], position = pos, amount = amount})
end
end
end
end
end
local function on_chunk_generated(event)
if event.surface.name ~= "expanse" then return end
local surface = event.surface
if surface.name ~= "expanse" then
if override_nauvis then
if surface.index == 1 then
for _, e in pairs(surface.find_entities_filtered({area = event.area, name = {"iron-ore", "copper-ore", "coal", "stone", "uranium-ore"}})) do
surface.create_entity({name = e.name, position = e.position, amount = 500 + math.sqrt(e.position.x ^ 2 + e.position.y ^ 2) * 2})
e.destroy()
end
generate_ore(surface, event.area.left_top)
end
end
return
end
local left_top = event.area.left_top
local tiles = {}
local i = 1
@ -103,7 +148,7 @@ local function on_chunk_generated(event)
end
end
end
event.surface.set_tiles(tiles, true)
surface.set_tiles(tiles, true)
end
local function container_opened(event)
@ -184,10 +229,16 @@ local function on_init(event)
T.sub_caption_color = {r = 120, g = 120, b = 0}
if not expanse.source_surface then expanse.source_surface = "nauvis" end
if not expanse.token_chance then expanse.token_chance = 0.33 end
if not expanse.price_distance_modifier then expanse.price_distance_modifier = 0.004 end
if not expanse.token_chance then expanse.token_chance = chance_to_receive_token end
if not expanse.price_distance_modifier then expanse.price_distance_modifier = 0.006 end
if not expanse.max_ore_price_modifier then expanse.max_ore_price_modifier = 0.33 end
if not expanse.square_size then expanse.square_size = 16 end
if not expanse.square_size then expanse.square_size = cell_size end
game.map_settings.enemy_expansion.enabled = true
game.map_settings.enemy_expansion.max_expansion_cooldown = 1800
game.map_settings.enemy_expansion.min_expansion_cooldown = 1800
game.map_settings.enemy_expansion.settler_group_max_size = 8
game.map_settings.enemy_expansion.settler_group_min_size = 16
--[[
expanse.token_chance = 2.5

View File

@ -235,7 +235,8 @@ function Public.get_random_item(rarity, sell, buy)
['locomotive'] = true,
['artillery-wagon'] = true,
['fluid-wagon'] = true,
['land-mine'] = true
['land-mine'] = true,
['car'] = true
}
for i = 1, math.random(5, 10), 1 do

View File

@ -245,7 +245,7 @@ local function biters_chew_rocks_faster(event)
return
end --Enemy Force
event.entity.health = event.entity.health - event.final_damage_amount * 5
event.entity.health = event.entity.health - event.final_damage_amount * 7
end
local projectiles = {'grenade', 'explosive-rocket', 'grenade', 'explosive-rocket', 'explosive-cannon-projectile'}
@ -535,9 +535,9 @@ local function on_entity_damaged(event)
biters_chew_rocks_faster(event)
local wave_number = WD.get_wave()
local boss_wave_warning = WD.alert_boss_wave()
local much_time = WPT.get('much_time')
local munch_time = WPT.get('munch_time')
if much_time then
if munch_time then
if boss_wave_warning or wave_number >= 1500 then
if math.random(0, 512) == 1 then
boss_puncher(event)

View File

@ -372,6 +372,7 @@ Public.disable_destructible_callback =
function(entity)
if entity and entity.valid then
entity.destructible = false
entity.minable = false
end
end
)
@ -536,7 +537,7 @@ Public.magic_item_crafting_callback_weighted =
else
local furance_item = stack.furance_item
if furance_item then
local inv = entity.get_inventory(2) -- defines.inventory.furnace_source
local inv = entity.get_inventory(defines.inventory.furnace_result)
inv.insert(furance_item)
end
end

View File

@ -31,9 +31,14 @@ local function do_tile(y, x, data, shape)
if type(tile) == 'table' then
do_tile_inner(data.tiles, tile.tile, pos)
local hidden_tile = tile.hidden_tile
if hidden_tile then
data.hidden_tiles[#data.hidden_tiles + 1] = {tile = hidden_tile, position = pos}
end
local entities = tile.entities
if entities then
for _, entity in pairs(entities) do
for _, entity in ipairs(entities) do
if not entity.position then
entity.position = pos
end
@ -43,7 +48,7 @@ local function do_tile(y, x, data, shape)
local buildings = tile.buildings
if buildings then
for _, entity in pairs(buildings) do
for _, entity in ipairs(buildings) do
if not entity.position then
entity.position = pos
end
@ -53,14 +58,14 @@ local function do_tile(y, x, data, shape)
local decoratives = tile.decoratives
if decoratives then
for _, decorative in pairs(decoratives) do
for _, decorative in ipairs(decoratives) do
data.decoratives[#data.decoratives + 1] = decorative
end
end
local markets = tile.markets
if markets then
for _, t in pairs(markets) do
for _, t in ipairs(markets) do
if not t.position then
t.position = pos
end
@ -70,7 +75,7 @@ local function do_tile(y, x, data, shape)
local treasure = tile.treasure
if treasure then
for _, t in pairs(treasure) do
for _, t in ipairs(treasure) do
if not t.position then
t.position = pos
end
@ -99,9 +104,14 @@ local function do_row(row, data, shape)
if type(tile) == 'table' then
do_tile_inner(tiles, tile.tile, pos)
local hidden_tile = tile.hidden_tile
if hidden_tile then
data.hidden_tiles[#data.hidden_tiles + 1] = {tile = hidden_tile, position = pos}
end
local entities = tile.entities
if entities then
for _, entity in pairs(entities) do
for _, entity in ipairs(entities) do
if not entity.position then
entity.position = pos
end
@ -111,7 +121,7 @@ local function do_row(row, data, shape)
local buildings = tile.buildings
if buildings then
for _, entity in pairs(buildings) do
for _, entity in ipairs(buildings) do
if not entity.position then
entity.position = pos
end
@ -121,7 +131,7 @@ local function do_row(row, data, shape)
local decoratives = tile.decoratives
if decoratives then
for _, decorative in pairs(decoratives) do
for _, decorative in ipairs(decoratives) do
if not decorative.position then
decorative.position = pos
end
@ -131,7 +141,7 @@ local function do_row(row, data, shape)
local markets = tile.markets
if markets then
for _, t in pairs(markets) do
for _, t in ipairs(markets) do
if not t.position then
t.position = pos
end
@ -141,7 +151,7 @@ local function do_row(row, data, shape)
local treasure = tile.treasure
if treasure then
for _, t in pairs(treasure) do
for _, t in ipairs(treasure) do
if not t.position then
t.position = pos
end
@ -163,7 +173,7 @@ local function do_place_treasure(data)
end
pcall(
function()
for _, e in pairs(data.treasure) do
for _, e in ipairs(data.treasure) do
if math.random(1, 6) == 1 then
e.chest = 'iron-chest'
end
@ -199,9 +209,19 @@ local function do_place_markets(data)
end
local function do_place_tiles(data)
local surface = data.surface
pcall(
function()
data.surface.set_tiles(data.tiles, true)
surface.set_tiles(data.tiles, true)
end
)
end
local function do_place_hidden_tiles(data)
local surface = data.surface
pcall(
function()
surface.set_tiles(data.hidden_tiles, true)
end
)
end
@ -228,7 +248,7 @@ local function do_place_buildings(data)
local callback
pcall(
function()
for _, e in pairs(data.buildings) do
for _, e in ipairs(data.buildings) do
if e.e_type then
local p = e.position
if
@ -272,7 +292,7 @@ local function do_place_entities(data)
local callback
pcall(
function()
for _, e in pairs(data.entities) do
for _, e in ipairs(data.entities) do
if e.collision then
if surface.can_place_entity(e) then
entity = surface.create_entity(e)
@ -388,26 +408,30 @@ local function map_gen_action(data)
data.y = 33
return true
elseif state == 33 then
do_place_entities(data)
do_place_hidden_tiles(data)
data.y = 34
return true
elseif state == 34 then
do_place_buildings(data)
do_place_entities(data)
data.y = 35
return true
elseif state == 35 then
do_place_markets(data)
do_place_buildings(data)
data.y = 36
return true
elseif state == 36 then
do_place_treasure(data)
do_place_markets(data)
data.y = 37
return true
elseif state == 37 then
do_place_decoratives(data)
do_place_treasure(data)
data.y = 38
return true
elseif state == 38 then
do_place_decoratives(data)
data.y = 39
return true
elseif state == 39 then
run_chart_update(data)
return false
end
@ -445,6 +469,7 @@ function Public.schedule_chunk(event)
top_y = area.left_top.y,
surface = surface,
tiles = {},
hidden_tiles = {},
entities = {},
buildings = {},
decoratives = {},
@ -483,6 +508,7 @@ function Public.do_chunk(event)
top_y = area.left_top.y,
surface = surface,
tiles = {},
hidden_tiles = {},
entities = {},
buildings = {},
decoratives = {},
@ -499,6 +525,7 @@ function Public.do_chunk(event)
end
do_place_tiles(data)
do_place_hidden_tiles(data)
do_place_entities(data)
do_place_buildings(data)
do_place_decoratives(data)

View File

@ -0,0 +1,675 @@
local Utils = require 'utils.core'
local Color = require 'utils.color_presets'
local Public = {}
function Public.request_reconstruction(ic)
ic.rebuild_tick = game.tick + 30
end
local function validate_entity(entity)
if not entity then
return false
end
if not entity.valid then
return false
end
return true
end
local function upperCase(str)
return (str:gsub('^%l', string.upper))
end
local function has_no_entity(t, entity)
for k, car in pairs(t) do
local unit_number = entity.unit_number
if car.name ~= entity.name then
local msg =
'The built entity is not the same as the saved one. ' ..
upperCase(car.name) .. ' is not equal to ' .. upperCase(entity.name) .. '.'
return false, msg
end
if car.entity == false then
t[unit_number] = car
t[unit_number].entity = entity
t[unit_number].transfer_entities = car.transfer_entities
t[k] = nil
end
end
return true
end
local function replace_doors(t, saved, entity)
for k, door in pairs(t) do
local unit_number = entity.unit_number
if saved == door then
t[k] = unit_number
end
end
end
local function save_surface(ic, entity, player)
local car = ic.cars[entity.unit_number]
car.entity = false
ic.saved_surfaces[player.index] = entity.unit_number
end
local function validate_player(player)
if not player then
return false
end
if not player.valid then
return false
end
if not player.character then
return false
end
if not player.connected then
return false
end
if not game.players[player.name] then
return false
end
return true
end
local function delete_empty_surfaces(ic)
for k, surface in pairs(ic.surfaces) do
if not ic.cars[tonumber(surface.name)] or ic.cars.entity == false then
game.delete_surface(surface)
ic.surfaces[k] = nil
end
end
end
local function kick_players_out_of_vehicles(car)
for _, player in pairs(game.connected_players) do
local character = player.character
if character and character.valid and character.driving then
if car.surface == player.surface then
character.driving = false
end
end
end
end
local function kick_player_from_surface(car)
for _, e in pairs(car.surface.find_entities_filtered({area = car.area})) do
if e and e.valid and e.name == 'character' and e.player then
local p = car.entity.surface.find_non_colliding_position('character', car.entity.position, 128, 0.5)
if p then
e.player.teleport(p, car.entity.surface)
else
e.player.teleport(car.entity.position, car.entity.surface)
end
end
end
end
local function input_filtered(car_inv, chest, chest_inv, free_slots)
local request_stacks = {}
local prototypes = game.item_prototypes
for slot_index = 1, 30, 1 do
local stack = chest.get_request_slot(slot_index)
if stack then
request_stacks[stack.name] = 10 * prototypes[stack.name].stack_size
end
end
for i = 1, #car_inv - 1, 1 do
if free_slots <= 0 then
return
end
local stack = car_inv[i]
if stack.valid_for_read then
local request_stack = request_stacks[stack.name]
if request_stack and request_stack > chest_inv.get_item_count(stack.name) then
chest_inv.insert(stack)
stack.clear()
free_slots = free_slots - 1
end
end
end
end
local function input_cargo(car, chest)
if not chest.request_from_buffers then
return
end
local car_entity = car.entity
if not validate_entity(car_entity) then
return
end
local car_inventory = car_entity.get_inventory(defines.inventory.car_trunk)
if car_inventory.is_empty() then
return
end
local chest_inventory = chest.get_inventory(defines.inventory.chest)
local free_slots = 0
for i = 1, chest_inventory.get_bar() - 1, 1 do
if not chest_inventory[i].valid_for_read then
free_slots = free_slots + 1
end
end
if chest.get_request_slot(1) then
input_filtered(car_inventory, chest, chest_inventory, free_slots)
return
end
for i = 1, #car_inventory - 1, 1 do
if free_slots <= 0 then
return
end
if car_inventory[i].valid_for_read then
chest_inventory.insert(car_inventory[i])
car_inventory[i].clear()
free_slots = free_slots - 1
end
end
end
local function output_cargo(car, passive_chest)
if not validate_entity(car.entity) then
return
end
if not passive_chest.valid then
return
end
local chest1 = passive_chest.get_inventory(defines.inventory.chest)
local chest2 = car.entity.get_inventory(defines.inventory.car_trunk)
for k, v in pairs(chest1.get_contents()) do
local t = {name = k, count = v}
local c = chest2.insert(t)
if (c > 0) then
chest1.remove({name = k, count = c})
end
end
end
local transfer_functions = {
['logistic-chest-requester'] = input_cargo,
['logistic-chest-passive-provider'] = output_cargo
}
local function construct_doors(ic, car)
local area = car.area
local surface = car.surface
local main_tile_name = 'black-refined-concrete'
for _, x in pairs({area.left_top.x - 1, area.right_bottom.x + 0.5}) do
local p
if car.name == 'car' then
p = {x, area.left_top.y + 10}
else
p = {x, area.left_top.y + 20}
end
surface.set_tiles({{name = main_tile_name, position = p}}, true)
local e =
surface.create_entity(
{
name = 'player-port',
position = {x, area.left_top.y + ((area.right_bottom.y - area.left_top.y) * 0.5)},
force = 'neutral',
create_build_effect_smoke = false
}
)
e.destructible = false
e.minable = false
e.operable = false
ic.doors[e.unit_number] = car.entity.unit_number
car.doors[#car.doors + 1] = e
end
end
local function get_player_data(ic, player)
local player_data = ic.players[player.index]
if ic.players[player.index] then
return player_data
end
ic.players[player.index] = {
surface = 1,
fallback_surface = 1
}
return ic.players[player.index]
end
function Public.save_car(ic, event)
local entity = event.entity
if not validate_entity(entity) then
return
end
local player = game.players[event.player_index]
if not validate_player(player) then
return
end
local entity_type = ic.entity_type
if not entity_type[entity.name] then
return
end
local car = ic.cars[entity.unit_number]
if not car then
return
end
kick_players_out_of_vehicles(car)
kick_player_from_surface(car)
if car.owner == player.index then
save_surface(ic, entity, player)
else
save_surface(ic, entity, game.players[car.owner])
Utils.action_warning('{Car}', player.name .. ' has looted ' .. game.players[car.owner].name .. '´s car.')
end
end
function Public.kill_car(ic, entity)
if not validate_entity(entity) then
return
end
local function kill_doors(car)
if not validate_entity(car.entity) then
return
end
for k, e in pairs(car.doors) do
ic.doors[e.unit_number] = nil
e.destroy()
car.doors[k] = nil
end
end
local entity_type = ic.entity_type
if not entity_type[entity.name] then
return
end
local car = ic.cars[entity.unit_number]
local surface = car.surface
kick_players_out_of_vehicles(car)
kill_doors(car)
kick_player_from_surface(car)
for _, tile in pairs(surface.find_tiles_filtered({area = car.area})) do
surface.set_tiles({{name = 'out-of-map', position = tile.position}}, true)
end
car.entity.force.chart(surface, car.area)
ic.cars[entity.unit_number] = nil
Public.request_reconstruction(ic)
end
function Public.create_room_surface(ic, unit_number)
if game.surfaces[tostring(unit_number)] then
return game.surfaces[tostring(unit_number)]
end
local map_gen_settings = {
['width'] = 2,
['height'] = 2,
['water'] = 0,
['starting_area'] = 1,
['cliff_settings'] = {cliff_elevation_interval = 0, cliff_elevation_0 = 0},
['default_enable_all_autoplace_controls'] = true,
['autoplace_settings'] = {
['entity'] = {treat_missing_as_default = false},
['tile'] = {treat_missing_as_default = true},
['decorative'] = {treat_missing_as_default = false}
}
}
local surface = game.create_surface(tostring(unit_number), map_gen_settings)
surface.freeze_daytime = true
surface.daytime = 0.1
surface.request_to_generate_chunks({16, 16}, 1)
surface.force_generate_chunk_requests()
for _, tile in pairs(surface.find_tiles_filtered({area = {{-2, -2}, {2, 2}}})) do
surface.set_tiles({{name = 'out-of-map', position = tile.position}}, true)
end
ic.surfaces[#ic.surfaces + 1] = surface
return surface
end
function Public.create_car_room(ic, car)
local surface = car.surface
local area = car.area
local main_tile_name = 'black-refined-concrete'
local tiles = {}
for x = area.left_top.x, area.right_bottom.x - 1, 1 do
for y = area.left_top.y + 2, area.right_bottom.y - 3, 1 do
tiles[#tiles + 1] = {name = main_tile_name, position = {x, y}}
end
end
for x = -3, 2, 1 do
for y = area.right_bottom.y - 4, area.right_bottom.y - 2, 1 do
tiles[#tiles + 1] = {name = main_tile_name, position = {x, y}}
end
end
local fishes = {}
if car.name == 'car' then
for x = -3, 2, 1 do
for y = 2, 3, 1 do
tiles[#tiles + 1] = {name = 'water', position = {x, y}}
fishes[#fishes + 1] = {name = 'fish', position = {x, y}}
end
end
else
for x = -4, 3, 1 do
for y = 2, 4, 1 do
tiles[#tiles + 1] = {name = 'water', position = {x, y}}
fishes[#fishes + 1] = {name = 'fish', position = {x, y}}
end
end
end
surface.set_tiles(tiles, true)
for _, fish in pairs(fishes) do
surface.create_entity(fish)
end
construct_doors(ic, car)
local entity_name = car.name
local car_areas = ic.car_areas
local c = car_areas[entity_name]
local lx, ly, rx, ry
if car.name == 'car' then
lx, ly, rx, ry = 4, 1, 5, 1
else
lx, ly, rx, ry = 4, 1, 5, 1
end
local position1 = {c.left_top.x + lx, c.left_top.y + ly}
local position2 = {c.right_bottom.x - rx, c.left_top.y + ry}
local e1 =
surface.create_entity(
{
name = 'logistic-chest-requester',
position = position1,
force = 'neutral',
create_build_effect_smoke = false
}
)
e1.destructible = false
e1.minable = false
local e2 =
surface.create_entity(
{
name = 'logistic-chest-passive-provider',
position = position2,
force = 'neutral',
create_build_effect_smoke = false
}
)
e2.destructible = false
e2.minable = false
car.transfer_entities = {e1, e2}
return
end
function Public.create_car(ic, event)
local created_entity = event.created_entity
if not validate_entity(created_entity) then
return
end
local player = game.get_player(event.player_index)
if not validate_player(player) then
return
end
local saved_surfaces = ic.saved_surfaces
local cars = ic.cars
local door = ic.doors
local entity_type = ic.entity_type
local car_areas = ic.car_areas
if not created_entity.unit_number then
return
end
if not entity_type[created_entity.name] then
return
end
if saved_surfaces[player.index] then
local index = saved_surfaces[player.index]
local success, msg = has_no_entity(cars, created_entity)
if not success then
player.print(msg, Color.warning)
created_entity.destroy()
return
end
replace_doors(door, index, created_entity)
saved_surfaces[player.index] = nil
return
end
for _, c in pairs(cars) do
if c.owner == player.index then
created_entity.destroy()
return player.print('You already have a portable vehicle.', Color.fail)
end
end
local car_area = car_areas[created_entity.name]
ic.cars[created_entity.unit_number] = {
entity = created_entity,
area = {
left_top = {x = car_area.left_top.x, y = car_area.left_top.y},
right_bottom = {x = car_area.right_bottom.x, y = car_area.right_bottom.y}
},
doors = {},
owner = player.index,
name = created_entity.name
}
local car = ic.cars[created_entity.unit_number]
car.surface = Public.create_room_surface(ic, created_entity.unit_number)
Public.create_car_room(ic, ic.cars[created_entity.unit_number])
Public.request_reconstruction(ic)
return car
end
function Public.teleport_players_around(ic)
for _, player in pairs(game.connected_players) do
if not validate_player(player) then
return
end
if player.surface.find_entity('player-port', player.position) then
local door = player.surface.find_entity('player-port', player.position)
if door and door.valid then
local doors = ic.doors
local cars = ic.cars
local car = false
if doors[door.unit_number] then
car = cars[doors[door.unit_number]]
end
if cars[door.unit_number] then
car = cars[door.unit_number]
end
if not car then
return
end
local player_data = get_player_data(ic, player)
if player_data.state then
player_data.state = player_data.state - 1
if player_data.state == 0 then
player_data.state = nil
end
return
end
if car.entity.surface.name ~= player.surface.name then
local surface = car.entity.surface
local x_vector = (door.position.x / math.abs(door.position.x)) * 2
local position = {car.entity.position.x + x_vector, car.entity.position.y}
local surface_position = surface.find_non_colliding_position('character', position, 128, 0.5)
if car.entity.type == 'car' then
player.teleport(surface_position, surface)
player_data.state = 2
player.driving = true
else
player.teleport(surface_position, surface)
end
player_data.surface = surface.index
elseif car.entity.type == 'car' and player.driving then
player.driving = false
else
local surface = car.surface
local area = car.area
local x_vector = door.position.x - player.position.x
local position
if x_vector > 0 then
position = {
area.left_top.x + 0.5,
area.left_top.y + ((area.right_bottom.y - area.left_top.y) * 0.5)
}
else
position = {
area.right_bottom.x - 0.5,
area.left_top.y + ((area.right_bottom.y - area.left_top.y) * 0.5)
}
end
local p = surface.find_non_colliding_position('character', position, 128, 0.5)
if p then
player.teleport(p, surface)
else
player.teleport(position, surface)
end
player_data.surface = surface.index
end
end
end
end
end
function Public.use_door_with_entity(ic, player, door)
local player_data = get_player_data(ic, player)
if player_data.state then
player_data.state = player_data.state - 1
if player_data.state == 0 then
player_data.state = nil
end
return
end
if not door then
return
end
if not door.valid then
return
end
local doors = ic.doors
local cars = ic.cars
local car = false
if doors[door.unit_number] then
car = cars[doors[door.unit_number]]
end
if cars[door.unit_number] then
car = cars[door.unit_number]
end
if not car then
return
end
player_data.fallback_surface = car.entity.surface.index
player_data.fallback_position = {car.entity.position.x, car.entity.position.y}
if car.entity.surface.name ~= player.surface.name then
local surface = car.entity.surface
local x_vector = (door.position.x / math.abs(door.position.x)) * 2
local position = {car.entity.position.x + x_vector, car.entity.position.y}
local surface_position = surface.find_non_colliding_position('character', position, 128, 0.5)
if not position then
return
end
if not surface_position then
surface.request_to_generate_chunks({-20, 22}, 1)
if player.character and player.character.valid and player.character.driving then
if car.surface == player.surface then
player.character.driving = false
end
end
return
end
if car.entity.type == 'car' then
player.teleport(surface_position, surface)
player_data.state = 2
player.driving = true
else
player.teleport(surface_position, surface)
end
player_data.surface = surface.index
else
local surface = car.surface
local area = car.area
local x_vector = door.position.x - player.position.x
local position
if x_vector > 0 then
position = {area.left_top.x + 0.5, area.left_top.y + ((area.right_bottom.y - area.left_top.y) * 0.5)}
else
position = {area.right_bottom.x - 0.5, area.left_top.y + ((area.right_bottom.y - area.left_top.y) * 0.5)}
end
local p = surface.find_non_colliding_position('character', position, 128, 0.5)
if p then
player.teleport(p, surface)
else
player.teleport(position, surface)
end
player_data.surface = surface.index
end
end
function Public.reconstruct_all_cars(ic)
for unit_number, car in pairs(ic.cars) do
if not validate_entity(car.entity) then
ic.cars[unit_number] = nil
Public.request_reconstruction(ic)
return
end
if not car.surface then
car.surface = Public.create_room_surface(ic, unit_number)
Public.create_car_room(ic, car)
end
end
delete_empty_surfaces(ic)
end
function Public.item_transfer(ic)
for _, car in pairs(ic.cars) do
if not validate_entity(car.entity) then
return
end
if car.transfer_entities then
for k, e in pairs(car.transfer_entities) do
transfer_functions[e.name](car, e)
end
end
end
end
return Public

View File

@ -0,0 +1,102 @@
local Event = require 'utils.event'
local Functions = require 'maps.mountain_fortress_v3.ic.functions'
local IC = require 'maps.mountain_fortress_v3.ic.table'
local Public = {}
Public.reset = IC.reset
Public.get_table = IC.get
local function on_entity_died(event)
local entity = event.entity
if not entity and not entity.valid then
return
end
if not entity.type == 'car' then
return
end
local ic = IC.get()
Functions.kill_car(ic, entity)
end
local function on_player_mined_entity(event)
local entity = event.entity
if not entity and not entity.valid then
return
end
if not entity.type == 'car' then
return
end
local ic = IC.get()
Functions.save_car(ic, event)
end
local function on_robot_mined_entity(event)
local entity = event.entity
if not entity and not entity.valid then
return
end
if not entity.type == 'car' then
return
end
local ic = IC.get()
Functions.kill_car(ic, entity)
end
local function on_built_entity(event)
local created_entity = event.created_entity
if not created_entity.type == 'car' then
return
end
local ic = IC.get()
Functions.create_car(ic, event)
end
local function on_player_driving_changed_state(event)
local ic = IC.get()
local player = game.players[event.player_index]
Functions.use_door_with_entity(ic, player, event.entity)
end
local function on_tick()
local ic = IC.get()
local tick = game.tick
if tick % 60 == 0 then
Functions.teleport_players_around(ic)
Functions.item_transfer(ic)
end
if not ic.rebuild_tick then
return
end
if ic.rebuild_tick ~= tick then
return
end
Functions.reconstruct_all_cars(ic)
ic.rebuild_tick = nil
end
local function on_init()
Public.reset()
end
Event.on_init(on_init)
Event.add(defines.events.on_tick, on_tick)
Event.add(defines.events.on_player_driving_changed_state, on_player_driving_changed_state)
Event.add(defines.events.on_entity_died, on_entity_died)
Event.add(defines.events.on_built_entity, on_built_entity)
Event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
Event.add(defines.events.on_robot_mined_entity, on_robot_mined_entity)
return Public

View File

@ -0,0 +1,56 @@
local Global = require 'utils.global'
local this = {}
Global.register(
this,
function(tbl)
this = tbl
end
)
local Public = {}
function Public.reset()
if this.surfaces then
for k, surface in pairs(this.surfaces) do
if surface and surface.valid then
game.delete_surface(surface)
end
end
end
for k, _ in pairs(this) do
this[k] = nil
end
this.doors = {}
this.cars = {}
this.saved_surfaces = {}
this.players = {}
this.surfaces = {}
this.entity_type = {
['car'] = true,
['tank'] = true
}
this.car_areas = {
['car'] = {left_top = {x = -20, y = 0}, right_bottom = {x = 20, y = 20}},
['tank'] = {left_top = {x = -30, y = 0}, right_bottom = {x = 30, y = 40}}
}
end
function Public.get(key)
if key then
return this[key]
else
return this
end
end
function Public.set_car_area(tbl)
if not tbl then
return
end
this.car_areas = tbl
end
return Public

View File

@ -55,11 +55,15 @@ local function kick_players_out_of_vehicles(wagon)
end
end
local function recreate_players()
for _, player in pairs(game.connected_players) do
if not player.character then
player.set_controller({type = defines.controllers.god})
player.create_character()
local function teleport_char(position, destination_area, wagon)
for _, e in pairs(wagon.surface.find_entities_filtered({name = 'character', area = wagon.area})) do
local player = e.player
if player then
position[player.index] = {
player.position.x,
player.position.y + (destination_area.left_top.y - wagon.area.left_top.y)
}
player.teleport({0, 0}, game.surfaces.nauvis)
end
end
end
@ -334,7 +338,6 @@ function Public.kill_wagon(icw, entity)
Public.kill_minimap(e.player)
else
e.destroy()
recreate_players()
end
end
for _, tile in pairs(surface.find_tiles_filtered({area = wagon.area})) do
@ -832,16 +835,7 @@ local function move_room_to_train(icw, train, wagon)
kick_players_out_of_vehicles(wagon)
local player_positions = {}
for _, e in pairs(wagon.surface.find_entities_filtered({name = 'character', area = wagon.area})) do
local player = e.player
if player then
player_positions[player.index] = {
player.position.x,
player.position.y + (destination_area.left_top.y - wagon.area.left_top.y)
}
player.teleport({0, 0}, game.surfaces.nauvis)
end
end
teleport_char(player_positions, destination_area, wagon)
kill_wagon_doors(icw, wagon)
@ -852,9 +846,7 @@ local function move_room_to_train(icw, train, wagon)
destination_surface = train.surface,
clone_tiles = true,
clone_entities = true,
clone_decoratives = true,
clear_destination_entities = true,
clear_destination_decoratives = true,
expand_map = true
}
)
@ -864,8 +856,6 @@ local function move_room_to_train(icw, train, wagon)
player.teleport(position, train.surface)
end
recreate_players()
for _, tile in pairs(wagon.surface.find_tiles_filtered({area = wagon.area})) do
wagon.surface.set_tiles({{name = 'out-of-map', position = tile.position}}, true)
end

View File

@ -1439,6 +1439,21 @@ local function on_console_chat(event)
shoo(event)
end
local function on_player_changed_surface(event)
local player = game.players[event.player_index]
if not validate_player(player) then
return
end
local map_name = 'mountain_fortress_v3'
if string.sub(player.surface.name, 0, #map_name) ~= map_name then
return Public.add_player_to_permission_group(player, 'locomotive')
else
return Public.add_player_to_permission_group(player, 'default')
end
end
function Public.close_gui_player(frame)
if not frame then
return
@ -1814,6 +1829,22 @@ function Public.get_items()
upgrade = false,
static = true
}
main_market_items['car'] = {
stack = 1,
value = 'coin',
price = 1000,
tooltip = 'Portable Car Surface\nCan be killed easily.',
upgrade = false,
static = true
}
main_market_items['tank'] = {
stack = 1,
value = 'coin',
price = 5000,
tooltip = 'Portable Tank Surface\nChonk tank, can resist heavy damage.',
upgrade = false,
static = true
}
main_market_items['tank-cannon'] = {
stack = 1,
value = 'coin',
@ -1894,14 +1925,14 @@ local function tick()
boost_players()
end
if ticker % 2500 == 0 then
pollute_area()
end
if ticker % 1800 == 0 then
if ticker % 1200 == 0 then
set_player_spawn()
refill_fish()
end
if ticker % 2500 == 0 then
pollute_area()
end
end
Public.place_market = place_market
@ -1920,5 +1951,6 @@ Event.add(defines.events.on_entity_died, on_player_and_robot_mined_entity)
Event.add(defines.events.on_pre_player_mined_item, on_player_and_robot_mined_entity)
Event.add(defines.events.on_robot_mined_entity, on_player_and_robot_mined_entity)
Event.add(defines.events.on_console_chat, on_console_chat)
Event.add(defines.events.on_player_changed_surface, on_player_changed_surface)
return Public

View File

@ -1,6 +1,7 @@
require 'maps.mountain_fortress_v3.generate'
require 'maps.mountain_fortress_v3.commands'
require 'maps.mountain_fortress_v3.breached_wall'
require 'maps.mountain_fortress_v3.ic.main'
require 'modules.rpg.main'
require 'modules.autofill'
@ -55,6 +56,8 @@ local disable_recipes = function()
local force = game.forces.player
force.recipes['cargo-wagon'].enabled = false
force.recipes['fluid-wagon'].enabled = false
force.recipes['car'].enabled = false
force.recipes['tank'].enabled = false
force.recipes['artillery-wagon'].enabled = false
force.recipes['locomotive'].enabled = false
force.recipes['pistol'].enabled = false
@ -69,6 +72,7 @@ local collapse_kill = {
['landmine'] = true,
['locomotive'] = true,
['cargo-wagon'] = true,
['car'] = true,
['assembling-machine'] = true,
['furnace'] = true,
['steel-chest'] = true
@ -87,6 +91,8 @@ end
local set_difficulty = function()
local Diff = Difficulty.get()
local wave_defense_table = WD.get_table()
local collapse_speed = WPT.get('collapse_speed')
local collapse_amount = WPT.get('collapcollapse_amountse_speed')
local player_count = #game.connected_players
if not Diff.difficulty_vote_value then
Diff.difficulty_vote_value = 0.1
@ -102,19 +108,85 @@ local set_difficulty = function()
if amount > 8 then
amount = 8
end
Collapse.set_amount(amount)
if player_count >= 8 and player_count <= 12 then
Collapse.set_speed(8)
elseif player_count >= 20 then
Collapse.set_speed(6)
elseif player_count >= 35 then
Collapse.set_speed(5)
local difficulty = Difficulty.get()
local name = difficulty.difficulties[difficulty.difficulty_vote_index].name
if name == 'Insane' then
Collapse.set_amount(15)
elseif collapse_amount then
Collapse.set_amount(collapse_amount)
else
Collapse.set_amount(amount)
end
wave_defense_table.wave_interval = 3600 - player_count * 60
if wave_defense_table.wave_interval < 1800 then
if name == 'Insane' then
Collapse.set_speed(5)
elseif collapse_speed then
Collapse.set_speed(collapse_speed)
else
if player_count >= 8 and player_count <= 12 then
Collapse.set_speed(8)
elseif player_count >= 20 then
Collapse.set_speed(6)
elseif player_count >= 35 then
Collapse.set_speed(5)
end
end
if name == 'Insane' then
wave_defense_table.wave_interval = 1800
else
wave_defense_table.wave_interval = 3600 - player_count * 60
if wave_defense_table.wave_interval < 1800 then
wave_defense_table.wave_interval = 1800
end
end
end
local biter_settings = function()
-- biter settings
local Diff = Difficulty.get()
if not Diff.difficulty_vote_value then
Diff.difficulty_vote_value = 0.1
end
local plus = ((game.forces.enemy.evolution_factor * 100) + 50) / (77 - Diff.difficulty_vote_value * 2)
local sub = (((1 - game.forces.enemy.evolution_factor) * 100) + 50) / (73 + Diff.difficulty_vote_value * 2)
local enemy_expansion = game.map_settings.enemy_expansion
local unit_group = game.map_settings.unit_group
local path_finder = game.map_settings.path_finder
unit_group.max_wait_time_for_late_members = 3600 * plus
unit_group.min_group_radius = 30 * plus
unit_group.max_group_radius = 60 * plus
unit_group.max_member_speedup_when_behind = 3 * plus
unit_group.member_disown_distance = 20 * plus
unit_group.max_gathering_unit_groups = 10 * plus
path_finder.max_work_done_per_tick = 6000 * plus
path_finder.max_steps_worked_per_tick = 20 + (100 * plus)
if path_finder.max_steps_worked_per_tick > 2000 then
path_finder.max_steps_worked_per_tick = 200
end
enemy_expansion.building_coefficient = 0.1 * sub
enemy_expansion.other_base_coefficient = 2.0 * sub
enemy_expansion.neighbouring_chunk_coefficient = 0.5 * sub
enemy_expansion.neighbouring_base_chunk_coefficient = 0.4 * sub
enemy_expansion.max_expansion_distance = 20 * plus
if enemy_expansion.max_expansion_distance > 20 then
enemy_expansion.max_expansion_distance = 20
end
enemy_expansion.friendly_base_influence_radius = 8 * plus
enemy_expansion.enemy_building_influence_radius = 3 * plus
enemy_expansion.settler_group_min_size = 5 * plus
if enemy_expansion.settler_group_min_size < 1 then
enemy_expansion.settler_group_min_size = 1
end
enemy_expansion.settler_group_max_size = 20 * plus
if enemy_expansion.settler_group_max_size > 50 then
enemy_expansion.settler_group_max_size = 50
end
end
@ -244,8 +316,10 @@ function Public.reset_map()
RPG_Settings.enable_stone_path(true)
RPG_Settings.enable_one_punch(true)
RPG_Settings.enable_one_punch_globally(false)
RPG_Settings.disable_cooldowns_on_spells()
Group.reset_groups()
Group.alphanumeric_only(false)
disable_tech()
@ -263,6 +337,9 @@ function Public.reset_map()
AntiGrief.whitelist_types('tree', true)
AntiGrief.enable_capsule_warning(true)
AntiGrief.enable_capsule_cursor_warning(false)
AntiGrief.enable_jail(true)
AntiGrief.damage_entity_threshold(20)
AntiGrief.explosive_threshold(32)
PL.show_roles_in_list(true)
@ -300,6 +377,7 @@ function Public.reset_map()
wave_defense_table.spawn_position = {x = 0, y = 100}
WD.alert_boss_wave(true)
WD.clear_corpses(false)
WD.remove_entities(true)
set_difficulty()
@ -313,6 +391,8 @@ function Public.reset_map()
Task.start_queue()
Task.set_queue_speed(32)
biter_settings()
this.chunk_load_tick = game.tick + 1200
--HD.enable_auto_init = false
@ -619,12 +699,13 @@ local boost_difficulty = function()
end
local difficulty = Difficulty.get()
local name = difficulty.difficulties[difficulty.difficulty_vote_index].name
if game.tick < difficulty.difficulty_poll_closing_timeout then
return
end
local rpg_extra = RPG_Settings.get('rpg_extra')
local name = difficulty.difficulties[difficulty.difficulty_vote_index].name
Difficulty.get().name = name
Difficulty.get().button_tooltip = difficulty.tooltip[difficulty.difficulty_vote_index]
@ -678,6 +759,20 @@ local boost_difficulty = function()
WPT.get().bonus_xp_on_join = 50
WD.set().next_wave = game.tick + 3600 * 10
WPT.get().difficulty_set = true
elseif name == 'Insane' then
rpg_extra.difficulty = 0
game.forces.player.manual_mining_speed_modifier = 0
force_mining_speed.speed = game.forces.player.manual_mining_speed_modifier
game.forces.player.character_running_speed_modifier = 0
game.forces.player.manual_crafting_speed_modifier = 0
WPT.get().coin_amount = 1
WPT.get('upgrades').flame_turret.limit = 0
WPT.get('upgrades').landmine.limit = 0
WPT.get().locomotive_health = 1000
WPT.get().locomotive_max_health = 1000
WPT.get().bonus_xp_on_join = 0
WD.set().next_wave = game.tick + 3600 * 5
WPT.get().difficulty_set = true
end
end
@ -694,9 +789,8 @@ end
local collapse_message =
Token.register(
function(data)
local keeper = '[color=blue]Mapkeeper:[/color] \n'
local pos = data.position
local message = keeper .. 'Warning, collapse has begun - wave limit has been reached!'
local message = data.message
local collapse_position = {
position = pos
}
@ -712,12 +806,27 @@ local collapse_after_wave_100 = function()
if Collapse.start_now() then
return
end
local difficulty = Difficulty.get()
local name = difficulty.difficulties[difficulty.difficulty_vote_index].name
local difficulty_set = WPT.get('difficulty_set')
if not difficulty_set and name == 'Insane' then
return
end
local wave_number = WD.get_wave()
if wave_number >= 100 then
if wave_number >= 100 or name == 'Insane' then
local keeper = '[color=blue]Mapkeeper:[/color] \n'
Collapse.start_now(true)
local data = {
position = Collapse.get_position()
}
if name == 'Insane' then
data.message = keeper .. 'Warning, Collapse has begun - god speed!'
else
data.message = keeper .. 'Warning, Collapse has begun - wave limit has been reached!'
end
Task.set_timeout_in_ticks(550, collapse_message, data)
end
end
@ -727,8 +836,13 @@ local on_tick = function()
local surface = game.surfaces[active_surface_index]
local wave_defense_table = WD.get_table()
local update_gui = Gui_mf.update_gui
local tick = game.tick
if game.tick % 60 == 0 then
if tick % 36000 == 0 then
biter_settings()
end
if tick % 60 == 0 then
for _, player in pairs(game.connected_players) do
update_gui(player)
end
@ -737,7 +851,7 @@ local on_tick = function()
has_the_game_ended()
chunk_load()
if game.tick % 1200 == 0 then
if tick % 1200 == 0 then
remove_offline_players()
boost_difficulty()
collapse_after_wave_100()
@ -771,6 +885,12 @@ local on_init = function()
[3] = {
name = 'Hard',
value = 1.5,
color = {r = 0.25, g = 0.25, b = 0.00},
print_color = {r = 0.4, g = 0.0, b = 0.00}
},
[4] = {
name = 'Insane',
value = 3,
color = {r = 0.25, g = 0.00, b = 0.00},
print_color = {r = 0.4, g = 0.0, b = 0.00}
}
@ -779,7 +899,8 @@ local on_init = function()
local tooltip = {
[1] = 'Wave Defense is based on amount of players.\nXP Extra reward points = 1.\nMining speed boosted = 1.5.\nRunning speed boosted = 0.2.\nCrafting speed boosted = 0.4.\nCoin amount per harvest = 2.\nFlame Turret limit = 25.\nLandmine limit = 100.\nLocomotive health = 20000.\nHidden Treasure has higher chance to spawn.\nGrace period: 20 minutes',
[2] = 'Wave Defense is based on amount of players.\nXP Extra reward points = 0.5.\nMining speed boosted = 1.\nRunning speed boosted = 0.1.\nCrafting speed boosted = 0.2.\nCoin amount per harvest = 1.\nFlame Turret limit = 10.\nLandmine limit = 50.\nLocomotive health = 10000.\nHidden Treasure has normal chance to spawn.\nGrace period: 15 minutes',
[3] = 'Wave Defense is based on amount of players.\nXP Extra reward points = 0.\nMining speed boosted = 0.\nRunning speed boosted = 0.\nCrafting speed boosted = 0.\nCoin amount per harvest = 1.\nFlame Turret limit = 3.\nLandmine limit = 10.\nLocomotive health = 5000.\nHidden Treasure has lower chance to spawn.\nGrace period: 10 minutes'
[3] = 'Wave Defense is based on amount of players.\nXP Extra reward points = 0.\nMining speed boosted = 0.\nRunning speed boosted = 0.\nCrafting speed boosted = 0.\nCoin amount per harvest = 1.\nFlame Turret limit = 3.\nLandmine limit = 10.\nLocomotive health = 5000.\nHidden Treasure has lower chance to spawn.\nGrace period: 10 minutes',
[4] = 'Wave Defense is based on amount of players.\nXP Extra reward points = 0.\nMining speed boosted = 0.\nRunning speed boosted = 0.\nCrafting speed boosted = 0.\nCoin amount per harvest = 1.\nFlame Turret limit = 0.\nLandmine limit = 0.\nLocomotive health = 1000.\nHidden Treasure has lower chance to spawn.\nGrace period: 5 minutes\nBiters are way more aggressive.\nCollapse starts after difficulty poll has ended.\nCollapse is much faster.'
}
Difficulty.set_difficulties(difficulties)

View File

@ -62,10 +62,10 @@ end
local function mining_chances_ores()
local data = {
{name = 'iron-ore', chance = 545},
{name = 'copper-ore', chance = 545},
{name = 'copper-ore', chance = 540},
{name = 'coal', chance = 545},
{name = 'stone', chance = 545},
{name = 'uranium-ore', chance = 50}
{name = 'uranium-ore', chance = 45}
}
return data
end
@ -73,7 +73,7 @@ end
local harvest_raffle_ores = {}
for _, t in pairs(mining_chances_ores()) do
for _ = 1, t.chance, 1 do
table.insert(harvest_raffle_ores, t.name)
harvest_raffle_ores[#harvest_raffle_ores + 1] = t.name
end
end

View File

@ -54,21 +54,21 @@ local ammo_loot = {
{
stack = {
recipe = 'piercing-rounds-magazine',
output = {item = 'piercing-rounds-magazine', min_rate = 0.5 / 8 / 60, distance_factor = 1 / 10 / 60 / 512}
output = {item = 'piercing-rounds-magazine', min_rate = 1 / 2 / 60, distance_factor = 1 / 10 / 60 / 512}
},
weight = 1
},
{
stack = {
recipe = 'firearm-magazine',
output = {item = 'firearm-magazine', min_rate = 1 / 4 / 60, distance_factor = 1 / 4 / 60 / 512}
output = {item = 'firearm-magazine', min_rate = 1 / 2 / 60, distance_factor = 1 / 4 / 60 / 512}
},
weight = 4
},
{
stack = {
recipe = 'shotgun-shell',
output = {item = 'shotgun-shell', min_rate = 0.5 / 8 / 60, distance_factor = 1 / 6 / 60 / 512}
output = {item = 'shotgun-shell', min_rate = 1 / 2 / 60, distance_factor = 1 / 8 / 60 / 512}
},
weight = 4
},
@ -86,7 +86,7 @@ local oil_loot = {
stack = {
recipe = 'basic-oil-processing',
output = {
min_rate = 0.5 / 8 / 60,
min_rate = 4.125 / 60,
distance_factor = 1 / 10 / 60 / 512,
item = 'petroleum-gas',
fluidbox_index = 2
@ -113,7 +113,7 @@ local oil_prod_loot = {
recipe = 'lubricant',
output = {
item = 'lubricant',
min_rate = 0.5 / 8 / 60,
min_rate = 2.825 / 60,
distance_factor = 1 / 10 / 60 / 512,
fluidbox_index = 2
}
@ -125,7 +125,7 @@ local oil_prod_loot = {
recipe = 'solid-fuel-from-light-oil',
output = {
item = 'solid-fuel',
min_rate = 1 / 4 / 60,
min_rate = 2 / 60,
distance_factor = 1 / 4 / 60 / 512
}
},
@ -136,8 +136,8 @@ local oil_prod_loot = {
recipe = 'sulfuric-acid',
output = {
item = 'sulfuric-acid',
min_rate = 0.5 / 8 / 60,
distance_factor = 1 / 6 / 60 / 512,
min_rate = 2.825 / 60,
distance_factor = 1 / 8 / 60 / 512,
fluidbox_index = 2
}
},
@ -148,7 +148,7 @@ local oil_prod_loot = {
recipe = 'battery',
output = {
item = 'battery',
min_rate = 0.5 / 8 / 60,
min_rate = 2 / 60,
distance_factor = 1 / 25 / 60 / 512
}
},
@ -159,7 +159,7 @@ local oil_prod_loot = {
recipe = 'sulfur',
output = {
item = 'sulfur',
min_rate = 0.5 / 8 / 60,
min_rate = 2.825 / 60,
distance_factor = 1 / 25 / 60 / 512
}
},
@ -170,7 +170,7 @@ local oil_prod_loot = {
recipe = 'plastic-bar',
output = {
item = 'plastic-bar',
min_rate = 0.5 / 8 / 60,
min_rate = 2 / 60,
distance_factor = 1 / 25 / 60 / 512
}
},
@ -182,126 +182,126 @@ local resource_loot = {
{
stack = {
recipe = 'stone-wall',
output = {item = 'stone-wall', min_rate = 1 / 4 / 60, distance_factor = 1 / 8 / 60 / 512}
output = {item = 'stone-wall', min_rate = 1.5 / 60, distance_factor = 1 / 6 / 60 / 512}
},
weight = 10
},
{
stack = {
recipe = 'iron-gear-wheel',
output = {item = 'iron-gear-wheel', min_rate = 1 / 4 / 60, distance_factor = 1 / 6 / 60 / 512}
output = {item = 'iron-gear-wheel', min_rate = 1.5 / 60, distance_factor = 1 / 6 / 60 / 512}
},
weight = 12
},
{
stack = {
recipe = 'inserter',
output = {item = 'inserter', min_rate = 1 / 4 / 60, distance_factor = 1 / 8 / 60 / 512}
output = {item = 'inserter', min_rate = 1.5 / 60, distance_factor = 1 / 6 / 60 / 512}
},
weight = 12
},
{
stack = {
recipe = 'transport-belt',
output = {item = 'transport-belt', min_rate = 1 / 4 / 60, distance_factor = 1 / 8 / 60 / 512}
output = {item = 'transport-belt', min_rate = 1.5 / 60, distance_factor = 1 / 6 / 60 / 512}
},
weight = 8
},
{
stack = {
recipe = 'underground-belt',
output = {item = 'underground-belt', min_rate = 1 / 4 / 60, distance_factor = 1 / 8 / 60 / 512}
output = {item = 'underground-belt', min_rate = 1.0 / 60, distance_factor = 1 / 6 / 60 / 512}
},
weight = 8
},
{
stack = {
recipe = 'small-electric-pole',
output = {item = 'small-electric-pole', min_rate = 1 / 4 / 60, distance_factor = 1 / 6 / 60 / 512}
output = {item = 'small-electric-pole', min_rate = 1.0 / 60, distance_factor = 1 / 6 / 60 / 512}
},
weight = 8
},
{
stack = {
recipe = 'fast-transport-belt',
output = {item = 'fast-transport-belt', min_rate = 1 / 4 / 60, distance_factor = 1 / 12 / 60 / 512}
output = {item = 'fast-transport-belt', min_rate = 1 / 4 / 60, distance_factor = 1 / 8 / 60 / 512}
},
weight = 5
},
{
stack = {
recipe = 'fast-underground-belt',
output = {item = 'fast-underground-belt', min_rate = 1 / 4 / 60, distance_factor = 1 / 12 / 60 / 512}
output = {item = 'fast-underground-belt', min_rate = 1 / 4 / 60, distance_factor = 1 / 8 / 60 / 512}
},
weight = 5
},
{
stack = {
recipe = 'solar-panel',
output = {item = 'solar-panel', min_rate = 1 / 4 / 60, distance_factor = 1 / 12 / 60 / 512}
output = {item = 'solar-panel', min_rate = 1 / 6 / 60, distance_factor = 1 / 8 / 60 / 512}
},
weight = 3
},
{
stack = {
recipe = 'productivity-module',
output = {item = 'productivity-module', min_rate = 1 / 4 / 60, distance_factor = 1 / 20 / 60 / 512}
output = {item = 'productivity-module', min_rate = 1 / 6 / 60, distance_factor = 1 / 8 / 60 / 512}
},
weight = 0.9
},
{
stack = {
recipe = 'effectivity-module',
output = {item = 'effectivity-module', min_rate = 1 / 4 / 60, distance_factor = 1 / 20 / 60 / 512}
output = {item = 'effectivity-module', min_rate = 1 / 6 / 60, distance_factor = 1 / 8 / 60 / 512}
},
weight = 0.9
},
{
stack = {
recipe = 'speed-module',
output = {item = 'speed-module', min_rate = 1 / 4 / 60, distance_factor = 1 / 20 / 60 / 512}
output = {item = 'speed-module', min_rate = 1 / 6 / 60, distance_factor = 1 / 8 / 60 / 512}
},
weight = 0.8
},
{
stack = {
recipe = 'productivity-module-2',
output = {item = 'productivity-module-2', min_rate = 1 / 4 / 60, distance_factor = 1 / 20 / 60 / 512}
output = {item = 'productivity-module-2', min_rate = 1 / 8 / 60, distance_factor = 1 / 8 / 60 / 512}
},
weight = 0.5
},
{
stack = {
recipe = 'effectivity-module-2',
output = {item = 'effectivity-module-2', min_rate = 1 / 4 / 60, distance_factor = 1 / 20 / 60 / 512}
output = {item = 'effectivity-module-2', min_rate = 1 / 8 / 60, distance_factor = 1 / 8 / 60 / 512}
},
weight = 0.5
},
{
stack = {
recipe = 'speed-module-2',
output = {item = 'speed-module-2', min_rate = 1 / 4 / 60, distance_factor = 1 / 20 / 60 / 512}
output = {item = 'speed-module-2', min_rate = 1 / 8 / 60, distance_factor = 1 / 8 / 60 / 512}
},
weight = 0.5
},
{
stack = {
recipe = 'productivity-module-3',
output = {item = 'productivity-module-3', min_rate = 1 / 4 / 60, distance_factor = 1 / 30 / 60 / 512}
output = {item = 'productivity-module-3', min_rate = 1 / 10 / 60, distance_factor = 1 / 8 / 60 / 512}
},
weight = 0.25
},
{
stack = {
recipe = 'effectivity-module-3',
output = {item = 'effectivity-module-3', min_rate = 1 / 4 / 60, distance_factor = 1 / 30 / 60 / 512}
output = {item = 'effectivity-module-3', min_rate = 1 / 10 / 60, distance_factor = 1 / 8 / 60 / 512}
},
weight = 0.25
},
{
stack = {
recipe = 'speed-module-3',
output = {item = 'speed-module-3', min_rate = 1 / 4 / 60, distance_factor = 1 / 30 / 60 / 512}
output = {item = 'speed-module-3', min_rate = 1 / 10 / 60, distance_factor = 1 / 8 / 60 / 512}
},
weight = 0.10
}
@ -311,21 +311,21 @@ local furnace_loot = {
{
stack = {
furance_item = 'iron-plate',
output = {item = 'iron-plate', min_rate = 1 / 4 / 60, distance_factor = 1 / 6 / 60 / 512}
output = {item = 'iron-plate', min_rate = 2.0 / 60, distance_factor = 1 / 6 / 60 / 512}
},
weight = 4
},
{
stack = {
furance_item = 'copper-plate',
output = {item = 'copper-plate', min_rate = 1 / 4 / 60, distance_factor = 1 / 6 / 60 / 512}
output = {item = 'copper-plate', min_rate = 2.0 / 60, distance_factor = 1 / 6 / 60 / 512}
},
weight = 4
},
{
stack = {
furance_item = 'steel-plate',
output = {item = 'steel-plate', min_rate = 0.5 / 8 / 60, distance_factor = 1 / 15 / 60 / 512}
output = {item = 'steel-plate', min_rate = 1.0 / 60, distance_factor = 1 / 8 / 60 / 512}
},
weight = 1
}

View File

@ -77,10 +77,10 @@ function Public.reset_table()
y = 0
}
this.traps = {}
this.much_time = true
this.munch_time = true
this.coin_amount = 1
this.difficulty_set = false
this.bonus_xp_on_join = 150
this.bonus_xp_on_join = 250
this.main_market_items = {}
this.spill_items_to_surface = false
this.outside_chests = {}

View File

@ -106,8 +106,12 @@ local function place_wagon(data)
placed_trains_in_zone = WPT.get('placed_trains_in_zone')
end
if placed_trains_in_zone.placed >= placed_trains_in_zone.limit then
return
end
local surface = data.surface
local tiles = data.tiles
local tiles = data.hidden_tiles
local entities = data.entities
local top_x = data.top_x
local top_y = data.top_y
@ -120,10 +124,6 @@ local function place_wagon(data)
callback = Functions.disable_destructible_callback
}
if placed_trains_in_zone.placed >= placed_trains_in_zone.limit then
return
end
local radius = 300
local area = {
left_top = {x = position.x - radius, y = position.y - radius},
@ -150,13 +150,8 @@ local function place_wagon(data)
end
for k, tile in pairs(location) do
if tile.collides_with('resource-layer') then
tiles[#tiles + 1] = {name = 'landfill', position = tile.position}
end
for _, e in pairs(surface.find_entities_filtered({position = tile.position, force = {'neutral', 'enemy'}})) do
e.destroy()
end
if tile.position.y % 2 == 0 and tile.position.x % 2 == 0 then
tiles[#tiles + 1] = {name = 'brown-refined-concrete', position = tile.position}
if tile.position.y % 1 == 0 and tile.position.x % 1 == 0 then
entities[#entities + 1] = {
name = 'straight-rail',
position = tile.position,
@ -222,7 +217,7 @@ local function wall(data)
local seed = data.seed
local p = {x = x + data.top_x, y = y + data.top_y}
local small_caves = get_noise('small_caves', p, seed + 12300)
local small_caves = get_noise('small_caves', p, seed + 300000)
local cave_ponds = get_noise('cave_rivers', p, seed + 150000)
if y > 9 + cave_ponds * 6 and y < 23 + small_caves * 6 then
if small_caves > 0.02 or cave_ponds > 0.02 then
@ -242,7 +237,7 @@ local function wall(data)
entities[#entities + 1] = {name = 'fish', position = p}
end
else
tiles[#tiles + 1] = {name = 'tutorial-grid', position = p}
tiles[#tiles + 1] = {name = 'brown-refined-concrete', position = p}
if math.random(1, 5) ~= 1 then
entities[#entities + 1] = {name = rock_raffle[math.random(1, #rock_raffle)], position = p}
@ -256,7 +251,7 @@ local function wall(data)
end
end
else
tiles[#tiles + 1] = {name = 'tutorial-grid', position = p}
tiles[#tiles + 1] = {name = 'brown-refined-concrete', position = p}
if
surface.can_place_entity(
@ -275,7 +270,7 @@ local function wall(data)
end
else
if y < 4 or y > 25 then
if y <= 24 then
if y <= 23 then
if math.random(1, y + 1) == 1 then
entities[#entities + 1] = {
name = 'stone-wall',
@ -369,6 +364,13 @@ local function process_level_13_position(x, y, data)
local noise_cave_ponds = get_noise('cave_ponds', p, seed)
local smol_areas = get_noise('smol_areas', p, seed + 70000)
--Resource Spots
if smol_areas < -0.72 then
if math.random(1, 8) == 1 then
Generate_resources(buildings, p, Public.level_depth)
end
end
if small_caves > -0.22 and small_caves < 0.22 then
tiles[#tiles + 1] = {name = 'dirt-3', position = p}
if math.random(1, 768) == 1 then
@ -395,15 +397,12 @@ local function process_level_13_position(x, y, data)
return
end
--Resource Spots
if smol_areas < -0.72 then
if math.random(1, 8) == 1 then
Generate_resources(buildings, p, Public.level_depth)
end
end
if small_caves > -0.40 and small_caves < 0.40 then
if noise_cave_ponds > 0.35 then
local success = place_wagon(data)
if success then
return
end
tiles[#tiles + 1] = {name = 'dirt-' .. math.random(1, 4), position = p}
if math.random(1, 256) == 1 then
treasure[#treasure + 1] = {position = p, chest = 'wooden-chest'}
@ -441,6 +440,13 @@ local function process_level_12_position(x, y, data)
local noise_2 = get_noise('no_rocks_2', p, seed + 20000)
local smol_areas = get_noise('smol_areas', p, seed + 60000)
--Resource Spots
if smol_areas < -0.72 then
if math.random(1, 8) == 1 then
Generate_resources(buildings, p, Public.level_depth)
end
end
if noise_1 > 0.65 then
if math.random(1, 100) > 88 then
entities[#entities + 1] = {name = 'tree-0' .. math.random(1, 9), position = p}
@ -456,6 +462,10 @@ local function process_level_12_position(x, y, data)
end
if noise_1 < -0.72 then
local success = place_wagon(data)
if success then
return
end
tiles[#tiles + 1] = {name = 'lab-dark-2', position = p}
if math.random(1, 100) > 88 then
entities[#entities + 1] = {name = 'tree-0' .. math.random(1, 9), position = p}
@ -478,13 +488,6 @@ local function process_level_12_position(x, y, data)
return
end
--Resource Spots
if smol_areas < -0.72 then
if math.random(1, 8) == 1 then
Generate_resources(buildings, p, Public.level_depth)
end
end
if math.random(1, 64) == 1 and noise_2 > 0.65 then
if math.random(1, 32) == 1 then
entities[#entities + 1] = {name = 'stone', position = p, amount = math.abs(p.y) + 1}
@ -531,6 +534,13 @@ local function process_level_11_position(x, y, data)
return
end
--Resource Spots
if smol_areas < -0.72 then
if math.random(1, 8) == 1 then
Generate_resources(buildings, p, Public.level_depth)
end
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}
@ -552,13 +562,6 @@ local function process_level_11_position(x, y, data)
return
end
--Resource Spots
if smol_areas < -0.72 then
if math.random(1, 8) == 1 then
Generate_resources(buildings, p, Public.level_depth)
end
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
@ -573,6 +576,11 @@ local function process_level_11_position(x, y, data)
}
end
local success = place_wagon(data)
if success then
return
end
tiles[#tiles + 1] = {name = 'tutorial-grid', position = p}
end
@ -616,6 +624,10 @@ local function process_level_10_position(x, y, data)
return
end
if math.abs(scrapyard) > 0.25 and math.abs(scrapyard) < 0.40 then
local success = place_wagon(data)
if success then
return
end
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'}
@ -670,6 +682,10 @@ local function process_level_9_position(x, y, data)
end
if maze_noise > 0 and maze_noise < 0.45 then
local success = place_wagon(data)
if success then
return
end
if math.random(1, 512) == 1 then
markets[#markets + 1] = p
end
@ -745,6 +761,10 @@ local function process_level_8_position(x, y, data)
return
end
if scrapyard < -0.28 or scrapyard > 0.28 then
local success = place_wagon(data)
if success then
return
end
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'}
@ -834,13 +854,6 @@ local function process_level_7_position(x, y, data)
return
end
--Resource Spots
if smol_areas < -0.72 then
if math.random(1, 8) == 1 then
Generate_resources(buildings, p, Public.level_depth)
end
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
@ -870,6 +883,10 @@ local function process_level_7_position(x, y, data)
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
local success = place_wagon(data)
if success then
return
end
if math.random(1, 8) == 1 and no_rocks_2 > -0.25 then
entities[#entities + 1] = {name = 'tree-02', position = p}
end
@ -967,6 +984,10 @@ local function process_level_6_position(x, y, data)
end
if cave_rivers > -0.1 and cave_rivers < 0.1 then
local success = place_wagon(data)
if success then
return
end
if math.random(1, 36) == 1 then
entities[#entities + 1] = {name = 'tree-0' .. math.random(1, 9), position = p}
end
@ -1041,6 +1062,10 @@ local function process_level_5_position(x, y, data)
if small_caves > -0.40 and small_caves < 0.40 then
if noise_cave_ponds > 0.35 then
local success = place_wagon(data)
if success then
return
end
tiles[#tiles + 1] = {name = 'dirt-' .. math.random(1, 4), position = p}
if math.random(1, 256) == 1 then
treasure[#treasure + 1] = {position = p, chest = 'wooden-chest'}
@ -1075,7 +1100,7 @@ local function process_level_4_position(x, y, data)
local noise_large_caves = get_noise('large_caves', p, seed)
local noise_cave_ponds = get_noise('cave_ponds', p, seed)
local small_caves = get_noise('small_caves', p, seed)
local small_caves = get_noise('dungeons', p, seed)
local smol_areas = get_noise('smol_areas', p, seed + 15000)
if math.abs(noise_large_caves) > 0.7 then
@ -1102,6 +1127,10 @@ local function process_level_4_position(x, y, data)
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
local success = place_wagon(data)
if success then
return
end
if math.random(1, 1024) == 1 then
treasure[#treasure + 1] = {position = p, chest = 'wooden-chest'}
end
@ -1182,12 +1211,19 @@ local function process_level_3_position(x, y, data)
local markets = data.markets
local treasure = data.treasure
local small_caves = get_noise('small_caves', p, seed + 50000)
local small_caves = get_noise('dungeons', p, seed + 50000)
local small_caves_2 = get_noise('small_caves_2', p, seed + 70000)
local noise_large_caves = get_noise('large_caves', p, seed + 60000)
local noise_cave_ponds = get_noise('cave_ponds', p, seed)
local smol_areas = get_noise('smol_areas', p, seed + 60000)
--Resource Spots
if smol_areas < -0.72 then
if math.random(1, 8) == 1 then
Generate_resources(buildings, p, Public.level_depth)
end
end
--Market Spots
if noise_cave_ponds < -0.77 then
if noise_cave_ponds > -0.79 then
@ -1205,13 +1241,6 @@ local function process_level_3_position(x, y, data)
return
end
--Resource Spots
if smol_areas < -0.72 then
if math.random(1, 8) == 1 then
Generate_resources(buildings, p, Public.level_depth)
end
end
if noise_large_caves > -0.15 and noise_large_caves < 0.15 or small_caves_2 > 0 then
--Green Water Ponds
if noise_cave_ponds > 0.80 then
@ -1296,6 +1325,10 @@ local function process_level_3_position(x, y, data)
--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
local success = place_wagon(data)
if success then
return
end
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] = {position = p, chest = 'wooden-chest'}
@ -1325,10 +1358,17 @@ local function process_level_2_position(x, y, data)
local markets = data.markets
local treasure = data.treasure
local small_caves = get_noise('small_caves', p, seed)
local small_caves = get_noise('dungeons', p, seed)
local noise_large_caves = get_noise('large_caves', p, seed)
local smol_areas = get_noise('smol_areas', p, seed + 15000)
--Resource Spots
if smol_areas < -0.72 then
if math.random(1, 8) == 1 then
Generate_resources(buildings, p, Public.level_depth)
end
end
if noise_large_caves > -0.75 and noise_large_caves < 0.75 then
local noise_cave_ponds = get_noise('cave_ponds', p, seed)
@ -1383,13 +1423,6 @@ local function process_level_2_position(x, y, data)
return
end
--Resource Spots
if smol_areas < -0.72 then
if math.random(1, 8) == 1 then
Generate_resources(buildings, p, Public.level_depth)
end
end
local no_rocks = get_noise('no_rocks', p, seed + 25000)
--Worm oil Zones
if no_rocks < 0.20 and no_rocks > -0.20 then
@ -1422,6 +1455,10 @@ local function process_level_2_position(x, y, data)
--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
local success = place_wagon(data)
if success then
return
end
tiles[#tiles + 1] = {name = 'grass-' .. math.random(1, 4), position = p}
if math.random(1, 512) == 1 then
treasure[#treasure + 1] = {position = p, chest = 'wooden-chest'}
@ -1451,9 +1488,16 @@ local function process_level_1_position(x, y, data)
local markets = data.markets
local treasure = data.treasure
local small_caves = get_noise('small_caves', p, seed)
local small_caves = get_noise('dungeons', p, seed)
local noise_cave_ponds = get_noise('cave_ponds', p, seed)
local smol_areas = get_noise('smol_areas', p, seed + 50000)
local smol_areas = get_noise('smol_areas', p, seed)
--Resource Spots
if smol_areas < -0.72 then
-- if math.random(1, 8) == 1 then
Generate_resources(buildings, p, Public.level_depth)
-- end
end
--Chasms
if noise_cave_ponds < 0.111 and noise_cave_ponds > -0.112 then
@ -1477,7 +1521,7 @@ local function process_level_1_position(x, y, data)
end
--Rivers
local cave_rivers = get_noise('cave_rivers', p, seed + 100000)
local cave_rivers = get_noise('cave_rivers', p, seed + 300000)
if cave_rivers < 0.042 and cave_rivers > -0.042 then
if noise_cave_ponds > 0 then
tiles[#tiles + 1] = {name = 'water-shallow', position = p}
@ -1512,14 +1556,7 @@ local function process_level_1_position(x, y, data)
return
end
--Resource Spots
if smol_areas < -0.72 then
-- if math.random(1, 8) == 1 then
Generate_resources(buildings, p, Public.level_depth)
-- end
end
local no_rocks = get_noise('no_rocks', p, seed + 25000)
local no_rocks = get_noise('no_rocks', p, seed + 50000)
--Worm oil Zones
if p.y < -64 + noise_cave_ponds * 10 then
if no_rocks < 0.12 and no_rocks > -0.12 then
@ -1551,6 +1588,10 @@ local function process_level_1_position(x, y, data)
--Main Rock Terrain
local no_rocks_2 = get_noise('no_rocks_2', p, seed + 75000)
if no_rocks_2 > 0.66 or no_rocks_2 < -0.66 then
local success = place_wagon(data)
if success then
return
end
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 = 'tree-0' .. math.random(1, 9), position = p}
@ -1571,10 +1612,10 @@ local function process_level_1_position(x, y, data)
end
Public.levels = {
process_level_2_position,
process_level_1_position,
process_level_2_position,
process_level_3_position,
process_level_5_position,
process_level_4_position,
process_level_6_position,
process_level_2_position,
process_level_3_position,
@ -1725,7 +1766,6 @@ function Public.heavy_functions(x, y, data)
if top_y < 0 then
process_bits(x, y, data)
place_wagon(data)
return
end

View File

@ -550,6 +550,7 @@ function Public.toggle(player, recreate)
end
local toggle = Public.toggle
Public.remove_main_frame = remove_main_frame
Gui.on_click(
draw_main_frame_name,

View File

@ -916,8 +916,6 @@ local function on_player_used_capsule(event)
if mana <= object.mana_cost then
return p('You don´t have enough mana to cast this spell.', Color.fail)
else
rpg_t[player.index].mana = rpg_t[player.index].mana - object.mana_cost
end
local target_pos
@ -945,6 +943,7 @@ local function on_player_used_capsule(event)
if object.obj_to_create == 'suicidal_comfylatron' then
Functions.suicidal_comfylatron(position, surface)
p('You wave your wand and ' .. object_name .. ' is on the run!', Color.success)
rpg_t[player.index].mana = rpg_t[player.index].mana - object.mana_cost
elseif object.obj_to_create == 'warp-gate' then
player.teleport(
surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 3, 0, 5),
@ -954,6 +953,7 @@ local function on_player_used_capsule(event)
player.character.health = 10
player.character.surface.create_entity({name = 'water-splash', position = player.position})
p('Warped home with minor bruises.', Color.info)
rpg_t[player.index].mana = rpg_t[player.index].mana - object.mana_cost
elseif projectile_types[obj_name] then
for i = 1, object.amount do
local damage_area = {
@ -968,13 +968,16 @@ local function on_player_used_capsule(event)
end
end
p('You wave your wand and ' .. object_name .. ' appears.', Color.success)
rpg_t[player.index].mana = rpg_t[player.index].mana - object.mana_cost
else
if object.target then
surface.create_entity({name = obj_name, position = position, force = force, target = target_pos, speed = 1})
p('You wave your wand and ' .. object_name .. ' appears.', Color.success)
rpg_t[player.index].mana = rpg_t[player.index].mana - object.mana_cost
elseif object.obj_to_create == 'fish' then
player.insert({name = 'raw-fish', count = object.amount})
p('You wave your wand and ' .. object_name .. ' appears.', Color.success)
rpg_t[player.index].mana = rpg_t[player.index].mana - object.mana_cost
elseif surface.can_place_entity {name = obj_name, position = position} then
if object.biter then
local e = surface.create_entity({name = obj_name, position = position, force = force})
@ -983,6 +986,7 @@ local function on_player_used_capsule(event)
surface.create_entity({name = obj_name, position = position, force = force})
end
p('You wave your wand and ' .. object_name .. ' appears.', Color.success)
rpg_t[player.index].mana = rpg_t[player.index].mana - object.mana_cost
else
p('Can´t create entity at given location.', Color.fail)
return

View File

@ -396,8 +396,7 @@ function Public.extra_settings(player)
}
)
local new_spells, names = RPG.rebuild_spells()
RPG.set_spells_table(new_spells)
local spells, names = RPG.rebuild_spells()
local conjure_label_style = conjure_label.style
conjure_label_style.horizontally_stretchable = true
@ -411,7 +410,7 @@ function Public.extra_settings(player)
conjure_gui_input =
create_input_element(conjure_input, 'dropdown', false, names, rpg_t[player.index].dropdown_select_index)
for _, entity in pairs(new_spells) do
for _, entity in pairs(spells) do
if entity.type == 'item' then
conjure_label.tooltip =
conjure_label.tooltip ..

View File

@ -286,22 +286,6 @@ function Public.conjure_items()
return spells
end
function Public.rebuild_spells()
local spells = Public.conjure_items()
local new_spells = {}
local spell_names = {}
for i = 1, #spells do
if spells[i].enabled then
new_spells[#new_spells + 1] = spells[i]
spell_names[#spell_names + 1] = spells[i].name
end
end
return new_spells, spell_names
end
Public.projectile_types = {
['explosives'] = {name = 'grenade', count = 0.5, max_range = 32, tick_speed = 1},
['land-mine'] = {name = 'grenade', count = 1, max_range = 32, tick_speed = 1},

View File

@ -7,7 +7,7 @@ local Gui = require 'utils.gui'
local this = {
rpg_extra = {},
rpg_t = {},
rpg_spells = {}
rpg_spells = Spells.conjure_items()
}
--! Gui Frames
@ -122,7 +122,6 @@ function Public.reset_table()
['small-worm-turret'] = 16,
['spitter-spawner'] = 64
}
this.rpg_spells = {}
end
--- Gets value from table
@ -275,36 +274,116 @@ function Public.enable_one_punch_globally(value)
return this.rpg_extra.enable_one_punch_globally
end
--- Retrieves the spell table.
--- Retrieves the spells table or a given spell.
---@param key <string>
function Public.get_spells(key)
if key then
if this.rpg_spells[key] then
return this.rpg_spells[key]
else
return this.rpg_spells
end
end
--- Disables a spell.
---@param key <string/table>
-- Table would look like:
-- Public.disable_spell({1, 2, 3, 4, 5, 6, 7, 8})
function Public.disable_spell(key)
if type(key) == 'table' then
for _, k in pairs(key) do
this.rpg_spells[k].enabled = false
end
elseif this.rpg_spells[key] then
this.rpg_spells[key].enabled = false
end
end
--- Clears the spell table.
function Public.clear_spell_table()
this.rpg_spells = {}
end
--- Adds a spell to the rpg_spells
---@param key <string>
---@param value <string>
function Public.set_spells(key, value)
if key and value then
this.rpg_spells[key] = value
return this.rpg_spells[key]
elseif key then
return this.rpg_spells[key]
else
return this.rpg_spells
---@param tbl <table>
function Public.set_new_spell(tbl)
if tbl then
if not tbl.name then
return error('A spell requires a name. <string>', 2)
end
if not tbl.obj_to_create then
return error('A spell requires an object to create. <string>', 2)
end
if not tbl.target then
return error('A spell requires position. <boolean>', 2)
end
if not tbl.amount then
return error('A spell requires an amount of creation. <integer>', 2)
end
if not tbl.range then
return error('A spell requires a range. <integer>', 2)
end
if not tbl.damage then
return error('A spell requires damage. <damage-area=true/false>', 2)
end
if not tbl.force then
return error('A spell requires a force. <string>', 2)
end
if not tbl.level then
return error('A spell requires a level. <integer>', 2)
end
if not tbl.type then
return error('A spell requires a type. <item/entity/special>', 2)
end
if not tbl.mana_cost then
return error('A spell requires mana_cost. <integer>', 2)
end
if not tbl.tick then
return error('A spell requires tick. <integer>', 2)
end
if not tbl.enabled then
return error('A spell requires enabled. <boolean>', 2)
end
this.rpg_spells[#this.rpg_spells + 1] = tbl
end
end
--- Defines the spell table
---@param tbl <table>
function Public.set_spells_table(tbl)
if tbl then
this.rpg_spells = tbl
--- This rebuilds all spells. Make sure to make changes on_init if you don't
-- want all spells enabled.
function Public.rebuild_spells()
local spells = this.rpg_spells
local new_spells = {}
local spell_names = {}
for i = 1, #spells do
if spells[i].enabled then
new_spells[#new_spells + 1] = spells[i]
spell_names[#spell_names + 1] = spells[i].name
end
end
this.rpg_spells = new_spells
return new_spells, spell_names
end
--- This will disable the cooldown of all spells.
function Public.disable_cooldowns_on_spells()
local spells = this.rpg_spells
local new_spells = {}
for i = 1, #spells do
if spells[i].enabled then
spells[i].tick = 0
new_spells[#new_spells + 1] = spells[i]
end
end
this.rpg_spells = new_spells
return new_spells
end
Public.get_projectiles = Spells.projectile_types
@ -314,7 +393,6 @@ Public.discard_button_name = discard_button_name
Public.draw_main_frame_name = draw_main_frame_name
Public.main_frame_name = main_frame_name
Public.settings_button_name = settings_button_name
Public.rebuild_spells = Spells.rebuild_spells
local on_init = function()
Public.reset_table()

View File

@ -44,6 +44,36 @@ local function shuffle_distance(tbl, position)
return tbl
end
local function remove_trees(entity)
local surface = entity.surface
local radius = 1.5
local pos = entity.position
local area = {{pos.x - radius, pos.y - radius}, {pos.x + radius, pos.y + radius}}
local trees = surface.find_entities_filtered{area = area, type = "tree"}
if #trees > 0 then
for i,tree in pairs(trees) do
if tree and tree.valid then
tree.die()
end
end
end
end
local function remove_rocks(entity)
local surface = entity.surface
local radius = 1.5
local pos = entity.position
local area = {{pos.x - radius, pos.y - radius}, {pos.x + radius, pos.y + radius}}
local rocks = surface.find_entities_filtered{area = area, type = "simple-entity"}
if #rocks > 0 then
for i,rock in pairs(rocks) do
if rock and rock.valid then
rock.die()
end
end
end
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
@ -212,6 +242,10 @@ local function spawn_biter(surface, is_boss_biter)
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
if wave_defense_table.remove_entities then
remove_trees(biter)
remove_rocks(biter)
end
if is_boss_biter then BiterHealthBooster.add_boss_unit(biter, global.biter_health_boost * 5, 0.35) end
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

View File

@ -51,6 +51,7 @@ function Public.reset_wave_defense()
wave_defense.worm_raffle = {}
wave_defense.clear_corpses = false
wave_defense.alert_boss_wave = false
wave_defense.remove_entities = false
end
function Public.get(key)
@ -89,6 +90,13 @@ function Public.alert_boss_wave(value)
return wave_defense.alert_boss_wave
end
function Public.remove_entities(value)
if value then
wave_defense.remove_entities = value
end
return wave_defense.remove_entities
end
local on_init = function()
Public.reset_wave_defense()
end

View File

@ -257,6 +257,14 @@ function Public.silent_action_warning(warning_prefix, msg, player)
Server.to_discord_bold(msg)
end
--- Takes msg and logs it.
-- @param msg <string> The message to print
-- @param warning_prefix <string> The name of the module/warning
function Public.log_msg(warning_prefix, msg)
msg = format('%s %s', warning_prefix, msg)
log(msg)
end
--- Takes a string, number, or LuaPlayer and returns a valid LuaPlayer or nil.
-- Intended for commands as there are extra checks in place.
-- @param <string|number|LuaPlayer>

View File

@ -507,6 +507,12 @@ function Event.generate_event_name(name)
return event_id
end
function Event.on_configuration_changed(func)
if type(func) == 'function' then
script.on_configuration_changed(func)
end
end
function Event.add_event_filter(event, filter)
local current_filters = script.get_event_filter(event)

View File

@ -88,9 +88,10 @@ local noises = {
local function get_noise(name, pos, seed)
local noise = 0
local d = 0
for _, n in pairs(noises[name]) do
noise = noise + simplex_noise(pos.x * n.modifier, pos.y * n.modifier, seed) * n.weight
d = d + n.weight
for i = 1, #noises[name] do
local mod = noises[name]
noise = noise + simplex_noise(pos.x * mod[i].modifier, pos.y * mod[i].modifier, seed) * mod[i].weight
d = d + mod[i].weight
seed = seed + 10000
end
noise = noise / d

View File

@ -81,7 +81,7 @@ local validate_args = function(player, griefer)
return false
end
if player.name == griefer then
if player.name == griefer and not player.admin then
Utils.print_to(player, 'You can´t select yourself.')
return false
end
@ -145,7 +145,6 @@ end
local jail = function(player, griefer)
player = player or 'script'
if jailed[griefer] then
Utils.print_to(player, griefer .. ' is already jailed!')
return false
end
@ -188,7 +187,6 @@ end
local free = function(player, griefer)
player = player or 'script'
if not jailed[griefer] then
Utils.print_to(player, griefer .. ' is not jailed!')
return false
end
@ -261,6 +259,10 @@ end
--- Tries to get data from the webpanel and updates the local table with values.
-- @param data_set player token
function Public.try_ul_data(key, value, player)
if type(key) == 'table' then
key = key.name
end
key = tostring(key)
local data = {
@ -314,6 +316,7 @@ Event.add(
function(event)
local cmd = event.command
local five_days = 25920000 -- 5 days
local twenty_days = 103680000 -- 20 days
if not valid_commands[cmd] then
return
@ -339,11 +342,11 @@ Event.add(
griefer = game.players[griefer].name
end
if not trusted or playtime <= five_days and not player.admin then
if not trusted and not player.admin or playtime <= five_days and not player.admin then
return Utils.print_to(player, 'You are not trusted enough to run this command.')
end
if trusted and playtime >= five_days and not player.admin then
if trusted and playtime >= five_days and playtime < twenty_days and not player.admin then
if cmd == 'jail' then
vote_to_jail(player, griefer)
return
@ -353,7 +356,7 @@ Event.add(
end
end
if player.admin then
if player.admin or playtime >= twenty_days then
if cmd == 'jail' then
Public.try_ul_data(griefer, true, player.name)
return

View File

@ -12,22 +12,27 @@ local error_offline = '[ERROR] Webpanel is offline.'
local session = {}
local online_track = {}
local trusted = {}
local settings = {
-- local trusted_value = 2592000 -- 12h
trusted_value = 5184000, -- 24h
nth_tick = 18000 -- nearest prime to 5 minutes in ticks
}
local set_data = Server.set_data
local try_get_data = Server.try_get_data
local concat = table.concat
local trusted_value = 2592000
local nth_tick = 18000 -- nearest prime to 5 minutes in ticks
Global.register(
{
session = session,
online_track = online_track,
trusted = trusted
trusted = trusted,
settings = settings
},
function(tbl)
session = tbl.session
online_track = tbl.online_track
trusted = tbl.trusted
settings = tbl.settings
end
)
@ -40,7 +45,7 @@ local try_download_data =
local value = data.value
if value then
session[key] = value
if value > trusted_value then
if value > settings.trusted_value then
trusted[key] = true
end
else
@ -182,13 +187,13 @@ Event.add(
end
)
Event.on_nth_tick(nth_tick, upload_data)
Event.on_nth_tick(settings.nth_tick, upload_data)
Server.on_data_set_changed(
session_data_set,
function(data)
session[data.key] = data.value
if data.value > trusted_value then
if data.value > settings.trusted_value then
trusted[data.key] = true
else
if trusted[data.key] then