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

dungeons fixes (should work on 1.1+ now) + glob table

This commit is contained in:
hanakocz 2021-03-09 02:58:52 +01:00
parent c369f1e01b
commit da93894188
16 changed files with 546 additions and 264 deletions

View File

@ -1,5 +1,6 @@
local Functions = require "maps.dungeons.functions" local Functions = require "maps.dungeons.functions"
local BiterRaffle = require "functions.biter_raffle" local BiterRaffle = require "functions.biter_raffle"
local DungeonsTable = require 'maps.dungeons.table'
local table_shuffle_table = table.shuffle_table local table_shuffle_table = table.shuffle_table
local table_insert = table.insert local table_insert = table.insert
@ -10,15 +11,17 @@ local math_sqrt = math.sqrt
local math_floor = math.floor local math_floor = math.floor
local function add_enemy_units(surface, room) local function add_enemy_units(surface, room)
local dungeontable = DungeonsTable.get_dungeontable()
for _, tile in pairs(room.room_tiles) do for _, tile in pairs(room.room_tiles) do
if math_random(1, 2) == 1 then if math_random(1, 2) == 1 then
local name = BiterRaffle.roll("spitter", Functions.get_dungeon_evolution_factor(surface.index) * 1.5) local name = BiterRaffle.roll("spitter", Functions.get_dungeon_evolution_factor(surface.index) * 1.5)
local unit = surface.create_entity({name = name, position = tile.position, force = global.enemy_forces[surface.index]}) local unit = surface.create_entity({name = name, position = tile.position, force = dungeontable.enemy_forces[surface.index]})
end end
end end
end end
local function acid_zone(surface, room) local function acid_zone(surface, room)
local dungeontable = DungeonsTable.get_dungeontable()
for _, tile in pairs(room.path_tiles) do for _, tile in pairs(room.path_tiles) do
surface.set_tiles({{name = "concrete", position = tile.position}}, true) surface.set_tiles({{name = "concrete", position = tile.position}}, true)
end end
@ -32,13 +35,13 @@ local function acid_zone(surface, room)
surface.create_entity({name = "uranium-ore", position = tile.position, amount = Functions.get_common_resource_amount(surface.index)}) surface.create_entity({name = "uranium-ore", position = tile.position, amount = Functions.get_common_resource_amount(surface.index)})
end end
if math_random(1, 96) == 1 then if math_random(1, 96) == 1 then
surface.create_entity({name = Functions.roll_worm_name(surface.index), position = tile.position, force = global.enemy_forces[surface.index]}) surface.create_entity({name = Functions.roll_worm_name(surface.index), position = tile.position, force = dungeontable.enemy_forces[surface.index]})
end end
if math_random(1, 128) == 1 then if math_random(1, 128) == 1 then
Functions.crash_site_chest(surface, tile.position) Functions.crash_site_chest(surface, tile.position)
end end
if key % 128 == 1 and math_random(1, 3) == 1 then if key % 128 == 1 and math_random(1, 3) == 1 then
Functions.set_spawner_tier(surface.create_entity({name = "spitter-spawner", position = tile.position, force = global.enemy_forces[surface.index]}), surface.index) Functions.set_spawner_tier(surface.create_entity({name = "spitter-spawner", position = tile.position, force = dungeontable.enemy_forces[surface.index]}), surface.index)
end end
end end

View File

@ -1,5 +1,6 @@
local Functions = require "maps.dungeons.functions" local Functions = require "maps.dungeons.functions"
local BiterRaffle = require "functions.biter_raffle" local BiterRaffle = require "functions.biter_raffle"
local DungeonsTable = require 'maps.dungeons.table'
local table_shuffle_table = table.shuffle_table local table_shuffle_table = table.shuffle_table
local table_insert = table.insert local table_insert = table.insert
@ -10,15 +11,17 @@ local math_sqrt = math.sqrt
local math_floor = math.floor local math_floor = math.floor
local function add_enemy_units(surface, room) local function add_enemy_units(surface, room)
local dungeontable = DungeonsTable.get_dungeontable()
for _, tile in pairs(room.room_tiles) do for _, tile in pairs(room.room_tiles) do
if math_random(1, 2) == 1 then if math_random(1, 2) == 1 then
local name = BiterRaffle.roll("biter", Functions.get_dungeon_evolution_factor(surface.index) * 1.5) local name = BiterRaffle.roll("biter", Functions.get_dungeon_evolution_factor(surface.index) * 1.5)
local unit = surface.create_entity({name = name, position = tile.position, force = global.enemy_forces[surface.index]}) local unit = surface.create_entity({name = name, position = tile.position, force = dungeontable.enemy_forces[surface.index]})
end end
end end
end end
local function concrete(surface, room) local function concrete(surface, room)
local dungeontable = DungeonsTable.get_dungeontable()
for _, tile in pairs(room.path_tiles) do for _, tile in pairs(room.path_tiles) do
surface.set_tiles({{name = "concrete", position = tile.position}}, true) surface.set_tiles({{name = "concrete", position = tile.position}}, true)
end end
@ -35,7 +38,7 @@ local function concrete(surface, room)
Functions.crash_site_chest(surface, tile.position) Functions.crash_site_chest(surface, tile.position)
end end
if key % 128 == 1 and math_random(1, 3) == 1 then if key % 128 == 1 and math_random(1, 3) == 1 then
Functions.set_spawner_tier(surface.create_entity({name = "biter-spawner", position = tile.position, force = global.enemy_forces[surface.index]}), surface.index) Functions.set_spawner_tier(surface.create_entity({name = "biter-spawner", position = tile.position, force = dungeontable.enemy_forces[surface.index]}), surface.index)
end end
end end

View File

@ -1,5 +1,6 @@
local Functions = require "maps.dungeons.functions" local Functions = require "maps.dungeons.functions"
local BiterRaffle = require "functions.biter_raffle" local BiterRaffle = require "functions.biter_raffle"
local DungeonsTable = require 'maps.dungeons.table'
local table_shuffle_table = table.shuffle_table local table_shuffle_table = table.shuffle_table
local table_insert = table.insert local table_insert = table.insert
@ -164,6 +165,7 @@ local water_shapes = {
for _ = 1, 16, 1 do table_insert(water_shapes, squares) end for _ = 1, 16, 1 do table_insert(water_shapes, squares) end
local function biome(surface, room) local function biome(surface, room)
local dungeontable = DungeonsTable.get_dungeontable()
for _, tile in pairs(room.path_tiles) do for _, tile in pairs(room.path_tiles) do
surface.set_tiles({{name = "concrete", position = tile.position}}, true) surface.set_tiles({{name = "concrete", position = tile.position}}, true)
end end
@ -192,10 +194,10 @@ local function biome(surface, room)
Functions.crash_site_chest(surface, tile.position) Functions.crash_site_chest(surface, tile.position)
end end
if key % 64 == 1 and math_random(1, 2) == 1 then if key % 64 == 1 and math_random(1, 2) == 1 then
Functions.set_spawner_tier(surface.create_entity({name = Functions.roll_spawner_name(), position = tile.position, force = global.enemy_forces[surface.index]}), surface.index) Functions.set_spawner_tier(surface.create_entity({name = Functions.roll_spawner_name(), position = tile.position, force = dungeontable.enemy_forces[surface.index]}), surface.index)
end end
if math_random(1, 64) == 1 then if math_random(1, 64) == 1 then
surface.create_entity({name = Functions.roll_worm_name(surface.index), position = tile.position, force = global.enemy_forces[surface.index]}) surface.create_entity({name = Functions.roll_worm_name(surface.index), position = tile.position, force = dungeontable.enemy_forces[surface.index]})
end end
end end
end end

View File

@ -1,5 +1,6 @@
local Functions = require "maps.dungeons.functions" local Functions = require "maps.dungeons.functions"
local Get_noise = require "utils.get_noise" local Get_noise = require "utils.get_noise"
local DungeonsTable = require 'maps.dungeons.table'
local table_shuffle_table = table.shuffle_table local table_shuffle_table = table.shuffle_table
local table_insert = table.insert local table_insert = table.insert
@ -35,6 +36,7 @@ local function add_enemy_units(surface, room)
end end
local function desert(surface, room) local function desert(surface, room)
local dungeontable = DungeonsTable.get_dungeontable()
for _, tile in pairs(room.path_tiles) do for _, tile in pairs(room.path_tiles) do
surface.set_tiles({{name = "sand-2", position = tile.position}}, true) surface.set_tiles({{name = "sand-2", position = tile.position}}, true)
end end
@ -63,14 +65,14 @@ local function desert(surface, room)
end end
end end
if key % 128 == 1 and math_random(1, 3) == 1 then if key % 128 == 1 and math_random(1, 3) == 1 then
Functions.set_spawner_tier(surface.create_entity({name = Functions.roll_spawner_name(), position = tile.position, force = global.enemy_forces[surface.index]}), surface.index) Functions.set_spawner_tier(surface.create_entity({name = Functions.roll_spawner_name(), position = tile.position, force = dungeontable.enemy_forces[surface.index]}), surface.index)
end end
if math_random(1, 160) == 1 then if math_random(1, 160) == 1 then
surface.create_entity({name = Functions.roll_worm_name(surface.index), position = tile.position, force = global.enemy_forces[surface.index]}) surface.create_entity({name = Functions.roll_worm_name(surface.index), position = tile.position, force = dungeontable.enemy_forces[surface.index]})
end end
local noise = Get_noise("decoratives", tile.position, seed) local noise = Get_noise("decoratives", tile.position, seed)
if math_random(1, 3) > 1 and math_abs(noise) > 0.52 then if math_random(1, 3) > 1 and math_abs(noise) > 0.52 then
surface.create_entity({name = "mineable-wreckage", position = tile.position}) Functions.create_scrap(surface, tile.position)
end end
if math_random(1, 128) == 1 then if math_random(1, 128) == 1 then
surface.create_entity({name = "rock-huge", position = tile.position}) surface.create_entity({name = "rock-huge", position = tile.position})

View File

@ -1,5 +1,6 @@
local Functions = require "maps.dungeons.functions" local Functions = require "maps.dungeons.functions"
local Get_noise = require "utils.get_noise" local Get_noise = require "utils.get_noise"
local DungeonsTable = require 'maps.dungeons.table'
local table_shuffle_table = table.shuffle_table local table_shuffle_table = table.shuffle_table
local table_insert = table.insert local table_insert = table.insert
@ -35,6 +36,7 @@ local function add_enemy_units(surface, room)
end end
local function dirtlands(surface, room) local function dirtlands(surface, room)
local dungeontable = DungeonsTable.get_dungeontable()
local path_tile = "dirt-" .. math_random(1, 3) local path_tile = "dirt-" .. math_random(1, 3)
for _, tile in pairs(room.path_tiles) do for _, tile in pairs(room.path_tiles) do
surface.set_tiles({{name = path_tile, position = tile.position}}, true) surface.set_tiles({{name = path_tile, position = tile.position}}, true)
@ -55,14 +57,14 @@ local function dirtlands(surface, room)
surface.create_entity({name = trees[math_random(1, size_of_trees)], position = tile.position}) surface.create_entity({name = trees[math_random(1, size_of_trees)], position = tile.position})
end end
end end
if key % 128 == 1 and math_random(1, 2) == 1 and global.dungeons.depth[surface.index] > 8 then if key % 128 == 1 and math_random(1, 2) == 1 and dungeontable.depth[surface.index] > 8 then
Functions.set_spawner_tier(surface.create_entity({name = Functions.roll_spawner_name(), position = tile.position, force = global.enemy_forces[surface.index]}), surface.index) Functions.set_spawner_tier(surface.create_entity({name = Functions.roll_spawner_name(), position = tile.position, force = dungeontable.enemy_forces[surface.index]}), surface.index)
end end
if math_random(1, 320) == 1 and global.dungeons.depth[surface.index] > 8 then if math_random(1, 320) == 1 and dungeontable.depth[surface.index] > 8 then
surface.create_entity({name = Functions.roll_worm_name(surface.index), position = tile.position, force = global.enemy_forces[surface.index]}) surface.create_entity({name = Functions.roll_worm_name(surface.index), position = tile.position, force = dungeontable.enemy_forces[surface.index]})
end end
if math_random(1, 512) == 1 then if math_random(1, 512) == 1 then
surface.create_entity({name = "mineable-wreckage", position = tile.position}) Functions.create_scrap(surface, tile.position)
end end
if math_random(1, 256) == 1 then if math_random(1, 256) == 1 then
surface.create_entity({name = "rock-huge", position = tile.position}) surface.create_entity({name = "rock-huge", position = tile.position})

View File

@ -1,4 +1,5 @@
local Functions = require "maps.dungeons.functions" local Functions = require "maps.dungeons.functions"
local DungeonsTable = require 'maps.dungeons.table'
local table_shuffle_table = table.shuffle_table local table_shuffle_table = table.shuffle_table
local table_insert = table.insert local table_insert = table.insert
@ -14,6 +15,7 @@ local function add_enemy_units(surface, room)
end end
local function doom(surface, room) local function doom(surface, room)
local dungeontable = DungeonsTable.get_dungeontable()
for _, tile in pairs(room.path_tiles) do for _, tile in pairs(room.path_tiles) do
surface.set_tiles({{name = "refined-concrete", position = tile.position}}, true) surface.set_tiles({{name = "refined-concrete", position = tile.position}}, true)
end end
@ -25,7 +27,7 @@ local function doom(surface, room)
surface.create_entity({name = "copper-ore", position = tile.position, amount = Functions.get_common_resource_amount(surface.index)}) surface.create_entity({name = "copper-ore", position = tile.position, amount = Functions.get_common_resource_amount(surface.index)})
end end
if math_random(1, 16) == 1 then if math_random(1, 16) == 1 then
surface.create_entity({name = Functions.roll_worm_name(surface.index), position = tile.position, force = global.enemy_forces[surface.index]}) surface.create_entity({name = Functions.roll_worm_name(surface.index), position = tile.position, force = dungeontable.enemy_forces[surface.index]})
end end
if math_random(1, 320) == 1 then if math_random(1, 320) == 1 then
Functions.rare_loot_crate(surface, tile.position) Functions.rare_loot_crate(surface, tile.position)
@ -35,7 +37,7 @@ local function doom(surface, room)
end end
end end
if key % 12 == 1 and math_random(1, 2) == 1 then if key % 12 == 1 and math_random(1, 2) == 1 then
Functions.set_spawner_tier(surface.create_entity({name = Functions.roll_spawner_name(), position = tile.position, force = global.enemy_forces[surface.index]}), surface.index) Functions.set_spawner_tier(surface.create_entity({name = Functions.roll_spawner_name(), position = tile.position, force = dungeontable.enemy_forces[surface.index]}), surface.index)
end end
end end

View File

@ -1,4 +1,5 @@
local Functions = require "maps.dungeons.functions" local Functions = require "maps.dungeons.functions"
local DungeonsTable = require 'maps.dungeons.table'
local table_shuffle_table = table.shuffle_table local table_shuffle_table = table.shuffle_table
local table_insert = table.insert local table_insert = table.insert
@ -9,6 +10,7 @@ local math_abs = math.abs
local ores = {"iron-ore", "copper-ore", "coal", "stone"} local ores = {"iron-ore", "copper-ore", "coal", "stone"}
local function glitch(surface, room) local function glitch(surface, room)
local dungeontable = DungeonsTable.get_dungeontable()
for _, tile in pairs(room.path_tiles) do for _, tile in pairs(room.path_tiles) do
surface.set_tiles({{name = "lab-white", position = tile.position}}, true) surface.set_tiles({{name = "lab-white", position = tile.position}}, true)
end end
@ -22,7 +24,7 @@ local function glitch(surface, room)
surface.create_entity({name = ores[math_random(1, #ores)], position = tile.position, amount = Functions.get_common_resource_amount(surface.index)}) surface.create_entity({name = ores[math_random(1, #ores)], position = tile.position, amount = Functions.get_common_resource_amount(surface.index)})
end end
if math_random(1, 12) == 1 then if math_random(1, 12) == 1 then
surface.create_entity({name = Functions.roll_worm_name(surface.index), position = tile.position, force = global.enemy_forces[surface.index]}) surface.create_entity({name = Functions.roll_worm_name(surface.index), position = tile.position, force = dungeontable.enemy_forces[surface.index]})
end end
if math_random(1, 96) == 1 then if math_random(1, 96) == 1 then
Functions.common_loot_crate(surface, tile.position) Functions.common_loot_crate(surface, tile.position)

View File

@ -1,5 +1,6 @@
local Functions = require "maps.dungeons.functions" local Functions = require "maps.dungeons.functions"
local Get_noise = require "utils.get_noise" local Get_noise = require "utils.get_noise"
local DungeonsTable = require 'maps.dungeons.table'
local table_shuffle_table = table.shuffle_table local table_shuffle_table = table.shuffle_table
local table_insert = table.insert local table_insert = table.insert
@ -37,6 +38,7 @@ local function add_enemy_units(surface, room)
end end
local function grasslands(surface, room) local function grasslands(surface, room)
local dungeontable = DungeonsTable.get_dungeontable()
for _, tile in pairs(room.path_tiles) do for _, tile in pairs(room.path_tiles) do
surface.set_tiles({{name = "grass-1", position = tile.position}}, true) surface.set_tiles({{name = "grass-1", position = tile.position}}, true)
end end
@ -57,10 +59,10 @@ local function grasslands(surface, room)
end end
end end
if key % 128 == 1 and math_random(1, 3) == 1 then if key % 128 == 1 and math_random(1, 3) == 1 then
Functions.set_spawner_tier(surface.create_entity({name = Functions.roll_spawner_name(), position = tile.position, force = global.enemy_forces[surface.index]}), surface.index) Functions.set_spawner_tier(surface.create_entity({name = Functions.roll_spawner_name(), position = tile.position, force = dungeontable.enemy_forces[surface.index]}), surface.index)
end end
if math_random(1, 320) == 1 then if math_random(1, 320) == 1 then
surface.create_entity({name = Functions.roll_worm_name(surface.index), position = tile.position, force = global.enemy_forces[surface.index]}) surface.create_entity({name = Functions.roll_worm_name(surface.index), position = tile.position, force = dungeontable.enemy_forces[surface.index]})
end end
if math_random(1, 1024) == 1 then if math_random(1, 1024) == 1 then
surface.create_entity({name = "rock-huge", position = tile.position}) surface.create_entity({name = "rock-huge", position = tile.position})

View File

@ -1,4 +1,5 @@
local Functions = require "maps.dungeons.functions" local Functions = require "maps.dungeons.functions"
local DungeonsTable = require 'maps.dungeons.table'
local table_shuffle_table = table.shuffle_table local table_shuffle_table = table.shuffle_table
local table_insert = table.insert local table_insert = table.insert
@ -18,6 +19,7 @@ local function add_enemy_units(surface, room)
end end
local function red_desert(surface, room) local function red_desert(surface, room)
local dungeontable = DungeonsTable.get_dungeontable()
for _, tile in pairs(room.path_tiles) do for _, tile in pairs(room.path_tiles) do
surface.set_tiles({{name = "red-desert-0", position = tile.position}}, true) surface.set_tiles({{name = "red-desert-0", position = tile.position}}, true)
end end
@ -33,10 +35,10 @@ local function red_desert(surface, room)
end end
end end
if key % 16 == 0 and math_random(1, 32) == 1 then if key % 16 == 0 and math_random(1, 32) == 1 then
Functions.set_spawner_tier(surface.create_entity({name = Functions.roll_spawner_name(), position = tile.position, force = global.enemy_forces[surface.index]}), surface.index) Functions.set_spawner_tier(surface.create_entity({name = Functions.roll_spawner_name(), position = tile.position, force = dungeontable.enemy_forces[surface.index]}), surface.index)
end end
if math_random(1, 256) == 1 then if math_random(1, 256) == 1 then
surface.create_entity({name = Functions.roll_worm_name(surface.index), position = tile.position, force = global.enemy_forces[surface.index]}) surface.create_entity({name = Functions.roll_worm_name(surface.index), position = tile.position, force = dungeontable.enemy_forces[surface.index]})
end end
if math_random(1, 32) == 1 then if math_random(1, 32) == 1 then
surface.create_entity({name = "rock-huge", position = tile.position}) surface.create_entity({name = "rock-huge", position = tile.position})

View File

@ -1,8 +1,9 @@
local RPG_F = require 'modules.rpg.functions' local RPG_F = require 'modules.rpg.functions'
local RPG_T = require 'modules.rpg.table' local RPG_T = require 'modules.rpg.table'
--local RPG_S = require "modules.rpg.settings" --local RPG_S = require "modules.rpg.settings"
local BiterHealthBooster = require 'modules.biter_health_booster' local BiterHealthBooster = require 'modules.biter_health_booster_v2'
local Alert = require 'utils.alert' local Alert = require 'utils.alert'
local DungeonsTable = require 'maps.dungeons.table'
local math_floor = math.floor local math_floor = math.floor
local math_min = math.min local math_min = math.min
local math_random = math.random local math_random = math.random
@ -14,7 +15,8 @@ local arena_areas = {
[4] = {area = {{-74, -74}, {-54, -54}}, center = {-64, -64}, player = {-59, -64}, boss = {-69, -64}} [4] = {area = {{-74, -74}, {-54, -54}}, center = {-64, -64}, player = {-59, -64}, boss = {-69, -64}}
} }
local function create_arena(arena) local function create_arena(arena)
local surface = game.surfaces['nauvis'] local arenatable = DungeonsTable.get_arenatable()
local surface = game.surfaces['dungeons_floor_arena']
local area = arena_areas[arena].area local area = arena_areas[arena].area
surface.request_to_generate_chunks(arena_areas[arena].center, 2) surface.request_to_generate_chunks(arena_areas[arena].center, 2)
surface.force_generate_chunk_requests() surface.force_generate_chunk_requests()
@ -34,17 +36,19 @@ local function create_arena(arena)
e.destructible = false e.destructible = false
e.minable = false e.minable = false
end end
global.arena.created[arena] = true arenatable.created[arena] = true
end end
local function reset_arena(arena) local function reset_arena(arena)
global.arena.timer[arena] = -100 local arenatable = DungeonsTable.get_arenatable()
global.arena.active_player[arena] = nil arenatable.timer[arena] = -100
arenatable.active_player[arena] = nil
end end
local function wipedown_arena(arena) local function wipedown_arena(arena)
local player = global.arena.active_player[arena] local arenatable = DungeonsTable.get_arenatable()
local surface = game.surfaces['nauvis'] local player = arenatable.active_player[arena]
local surface = game.surfaces['dungeons_floor_arena']
local area = arena_areas[arena].area local area = arena_areas[arena].area
local acids = local acids =
surface.find_entities_filtered {area = {{area[1][1] - 5, area[1][2] - 5}, {area[2][1] + 5, area[2][2] + 5}}, type = 'fire'} surface.find_entities_filtered {area = {{area[1][1] - 5, area[1][2] - 5}, {area[2][1] + 5, area[2][2] + 5}}, type = 'fire'}
@ -94,9 +98,10 @@ local function calculate_dmg(level)
end end
local function draw_boss_gui() local function draw_boss_gui()
local arenatable = DungeonsTable.get_arenatable()
for _, player in pairs(game.connected_players) do for _, player in pairs(game.connected_players) do
if not player.gui.top.boss_arena then if not player.gui.top.boss_arena then
local level = global.arena.bosses[player.index] or 0 local level = arenatable.bosses[player.index] or 0
local tooltip = { local tooltip = {
'dungeons_tiered.boss_arena', 'dungeons_tiered.boss_arena',
level, level,
@ -110,10 +115,11 @@ local function draw_boss_gui()
end end
local function update_boss_gui(player) local function update_boss_gui(player)
local arenatable = DungeonsTable.get_arenatable()
if not player.gui.top.boss_arena then if not player.gui.top.boss_arena then
draw_boss_gui() draw_boss_gui()
end end
local level = global.arena.bosses[player.index] or 0 local level = arenatable.bosses[player.index] or 0
local tooltip = { local tooltip = {
'dungeons_tiered.boss_arena', 'dungeons_tiered.boss_arena',
level, level,
@ -125,19 +131,22 @@ local function update_boss_gui(player)
end end
local function arena_occupied(arena) local function arena_occupied(arena)
if global.arena.active_player[arena] then local arenatable = DungeonsTable.get_arenatable()
if arenatable.active_player[arena] then
return true return true
end end
if global.arena.active_boss[arena] then if arenatable.active_boss[arena] then
return true return true
end end
return false return false
end end
local function spawn_boss(arena, biter, level) local function spawn_boss(arena, biter, level)
local surface = game.surfaces['nauvis'] local forceshp = BiterHealthBooster.get('biter_health_boost_forces')
local force = game.forces[global.arena.enemies[arena].index] local arenatable = DungeonsTable.get_arenatable()
global.biter_health_boost_forces[force.index] = calculate_hp(level) local surface = game.surfaces['dungeons_floor_arena']
local force = game.forces[arenatable.enemies[arena].index]
forceshp[force.index] = calculate_hp(level)
force.set_ammo_damage_modifier('melee', calculate_dmg(level)) force.set_ammo_damage_modifier('melee', calculate_dmg(level))
force.set_ammo_damage_modifier('biological', calculate_dmg(level)) force.set_ammo_damage_modifier('biological', calculate_dmg(level))
local pos = {x = arena_areas[arena].center[1], y = arena_areas[arena].center[2]} local pos = {x = arena_areas[arena].center[1], y = arena_areas[arena].center[2]}
@ -145,7 +154,7 @@ local function spawn_boss(arena, biter, level)
pos.y = pos.y - 6 + math_random(0, 12) pos.y = pos.y - 6 + math_random(0, 12)
local boss = surface.create_entity({name = biter, position = pos, force = force}) local boss = surface.create_entity({name = biter, position = pos, force = force})
boss.ai_settings.allow_try_return_to_spawner = false boss.ai_settings.allow_try_return_to_spawner = false
global.arena.active_boss[arena] = boss arenatable.active_boss[arena] = boss
rendering.draw_text { rendering.draw_text {
text = 'Boss lvl ' .. level, text = 'Boss lvl ' .. level,
surface = surface, surface = surface,
@ -157,7 +166,7 @@ local function spawn_boss(arena, biter, level)
alignment = 'center', alignment = 'center',
scale_with_zoom = false scale_with_zoom = false
} }
BiterHealthBooster.add_boss_unit(boss, global.biter_health_boost_forces[force.index] * 8, 0.25) BiterHealthBooster.add_boss_unit(boss, forceshp[force.index] * 8, 0.25)
end end
local function hide_rpg(player, show) local function hide_rpg(player, show)
@ -187,26 +196,29 @@ local function hide_rpg(player, show)
end end
local function teleport_player_out(arena, player) local function teleport_player_out(arena, player)
local surface = global.arena.previous_position[arena].surface local arenatable = DungeonsTable.get_arenatable()
local position = global.arena.previous_position[arena].position local surface = arenatable.previous_position[arena].surface
local position = arenatable.previous_position[arena].position
local rpg = RPG_T.get('rpg_t') local rpg = RPG_T.get('rpg_t')
rpg[player.index].one_punch = true rpg[player.index].one_punch = true
hide_rpg(player, true) hide_rpg(player, true)
player.teleport(surface.find_non_colliding_position('character', position, 20, 0.5), surface) player.teleport(surface.find_non_colliding_position('character', position, 20, 0.5), surface)
global.arena.previous_position[arena].position = nil arenatable.previous_position[arena].position = nil
global.arena.previous_position[arena].surface = nil arenatable.previous_position[arena].surface = nil
reset_arena(arena) reset_arena(arena)
local group = game.permissions.get_group('Default') local group = game.permissions.get_group('Default')
group.add_player(player) group.add_player(player)
end end
local function teleport_player_in(arena, player) local function teleport_player_in(arena, player)
local surface = game.surfaces['nauvis'] local arenatable = DungeonsTable.get_arenatable()
global.arena.previous_position[arena].position = player.position local surface = game.surfaces['dungeons_floor_arena']
global.arena.previous_position[arena].surface = player.surface arenatable.previous_position[arena].position = player.position
global.arena.timer[arena] = game.tick arenatable.previous_position[arena].surface = player.surface
arenatable.timer[arena] = game.tick
local rpg = RPG_T.get('rpg_t') local rpg = RPG_T.get('rpg_t')
rpg[player.index].one_punch = false rpg[player.index].one_punch = false
rpg[player.index].enable_entity_spawn = false
hide_rpg(player, false) hide_rpg(player, false)
local pos = {x = arena_areas[arena].center[1], y = arena_areas[arena].center[2]} local pos = {x = arena_areas[arena].center[1], y = arena_areas[arena].center[2]}
@ -214,30 +226,31 @@ local function teleport_player_in(arena, player)
pos.y = pos.y - 6 + math_random(0, 12) pos.y = pos.y - 6 + math_random(0, 12)
player.teleport(surface.find_non_colliding_position('character', pos, 20, 0.5), surface) player.teleport(surface.find_non_colliding_position('character', pos, 20, 0.5), surface)
global.arena.active_player[arena] = player arenatable.active_player[arena] = player
local group = game.permissions.get_group('Arena') local group = game.permissions.get_group('Arena')
group.add_player(player) group.add_player(player)
end end
local function player_died(arena, player) local function player_died(arena, player)
local arenatable = DungeonsTable.get_arenatable()
wipedown_arena(arena) wipedown_arena(arena)
global.arena.active_player[arena] = nil arenatable.active_player[arena] = nil
if global.arena.active_boss[arena] and global.arena.active_boss[arena].valid then if arenatable.active_boss[arena] and arenatable.active_boss[arena].valid then
global.arena.active_boss[arena].destroy() arenatable.active_boss[arena].destroy()
end end
global.arena.active_boss[arena] = nil arenatable.active_boss[arena] = nil
global.arena.timer[arena] = -100 arenatable.timer[arena] = -100
teleport_player_out(arena, player) teleport_player_out(arena, player)
player.character.health = 5 player.character.health = 5
if not global.arena.won[arena] then --incase of death after victory if not arenatable.won[arena] then --incase of death after victory
local level = global.arena.bosses[player.index] local level = arenatable.bosses[player.index]
--game.print({"dungeons_tiered.player_lost", player.name, global.arena.bosses[player.index]}) --game.print({"dungeons_tiered.player_lost", player.name, arenatable.bosses[player.index]})
if level % 10 == 0 and level > 0 then if level % 10 == 0 and level > 0 then
Alert.alert_all_players( Alert.alert_all_players(
8, 8,
{'dungeons_tiered.player_lost', player.name, global.arena.bosses[player.index]}, {'dungeons_tiered.player_lost', player.name, arenatable.bosses[player.index]},
{r = 0.8, g = 0.2, b = 0}, {r = 0.8, g = 0.2, b = 0},
'entity/behemoth-biter', 'entity/behemoth-biter',
0.7 0.7
@ -246,7 +259,7 @@ local function player_died(arena, player)
Alert.alert_player( Alert.alert_player(
player, player,
8, 8,
{'dungeons_tiered.player_lost', player.name, global.arena.bosses[player.index]}, {'dungeons_tiered.player_lost', player.name, arenatable.bosses[player.index]},
{r = 0.8, g = 0.2, b = 0}, {r = 0.8, g = 0.2, b = 0},
'entity/behemoth-biter', 'entity/behemoth-biter',
0.7 0.7
@ -256,18 +269,19 @@ local function player_died(arena, player)
end end
local function boss_died(arena) local function boss_died(arena)
global.arena.active_boss[arena] = nil local arenatable = DungeonsTable.get_arenatable()
local player = global.arena.active_player[arena] arenatable.active_boss[arena] = nil
local level = global.arena.bosses[player.index] local player = arenatable.active_player[arena]
local level = arenatable.bosses[player.index]
wipedown_arena(arena) wipedown_arena(arena)
global.arena.won[arena] = true arenatable.won[arena] = true
global.arena.timer[arena] = game.tick - 30 arenatable.timer[arena] = game.tick - 30
--teleport_player_out(arena, player) --teleport_player_out(arena, player)
RPG_F.gain_xp(player, 4 + level, true) RPG_F.gain_xp(player, 4 + level, true)
if level % 10 == 0 and level > 0 then if level % 10 == 0 and level > 0 then
Alert.alert_all_players( Alert.alert_all_players(
8, 8,
{'dungeons_tiered.player_won', player.name, global.arena.bosses[player.index]}, {'dungeons_tiered.player_won', player.name, arenatable.bosses[player.index]},
{r = 0.8, g = 0.2, b = 0}, {r = 0.8, g = 0.2, b = 0},
'entity/behemoth-biter', 'entity/behemoth-biter',
0.7 0.7
@ -276,22 +290,23 @@ local function boss_died(arena)
Alert.alert_player( Alert.alert_player(
player, player,
8, 8,
{'dungeons_tiered.player_won', player.name, global.arena.bosses[player.index]}, {'dungeons_tiered.player_won', player.name, arenatable.bosses[player.index]},
{r = 0.8, g = 0.2, b = 0}, {r = 0.8, g = 0.2, b = 0},
'entity/behemoth-biter', 'entity/behemoth-biter',
0.7 0.7
) )
end end
--game.print({"dungeons_tiered.player_won", player.name, global.arena.bosses[player.index]}) --game.print({"dungeons_tiered.player_won", player.name, arenatable.bosses[player.index]})
global.arena.bosses[player.index] = global.arena.bosses[player.index] + 1 arenatable.bosses[player.index] = arenatable.bosses[player.index] + 1
--global.arena.active_player[arena] = nil --arenatable.active_player[arena] = nil
--global.arena.timer[arena] = -100 --arenatable.timer[arena] = -100
update_boss_gui(player) update_boss_gui(player)
end end
local function choose_arena() local function choose_arena()
local arenatable = DungeonsTable.get_arenatable()
for i = 1, 4, 1 do for i = 1, 4, 1 do
if not global.arena.created[i] then if not arenatable.created[i] then
create_arena(i) create_arena(i)
end end
if not arena_occupied(i) then if not arena_occupied(i) then
@ -302,10 +317,11 @@ local function choose_arena()
end end
local function enter_arena(player) local function enter_arena(player)
local arenatable = DungeonsTable.get_arenatable()
if not player.character then if not player.character then
return return
end end
if player.surface.name == 'nauvis' then if player.surface.name == 'dungeons_floor_arena' then
return return
end end
local chosen_arena = choose_arena() local chosen_arena = choose_arena()
@ -324,7 +340,7 @@ local function enter_arena(player)
return return
end end
local level = global.arena.bosses[player.index] local level = arenatable.bosses[player.index]
if level > 100 then if level > 100 then
Alert.alert_player_warning(player, 8, {'dungeons_tiered.arena_level_max'}) Alert.alert_player_warning(player, 8, {'dungeons_tiered.arena_level_max'})
return return
@ -332,14 +348,15 @@ local function enter_arena(player)
--local biter_names = {{"small-biter", "small-spitter"}, {"medium-biter", "medium-spitter"}, {"big-biter", "big-spitter"}, {"behemoth-biter", "behemoth-spitter"}} --local biter_names = {{"small-biter", "small-spitter"}, {"medium-biter", "medium-spitter"}, {"big-biter", "big-spitter"}, {"behemoth-biter", "behemoth-spitter"}}
--local biter = biter_names[math_min(1 + math_floor(level / 20), 4)][1 + level % 2] --local biter = biter_names[math_min(1 + math_floor(level / 20), 4)][1 + level % 2]
--spawn_boss(chosen_arena, biter, level) --spawn_boss(chosen_arena, biter, level)
global.arena.won[chosen_arena] = false arenatable.won[chosen_arena] = false
teleport_player_in(chosen_arena, player) teleport_player_in(chosen_arena, player)
end end
local function on_player_joined_game(event) local function on_player_joined_game(event)
local arenatable = DungeonsTable.get_arenatable()
draw_boss_gui() draw_boss_gui()
if not global.arena.bosses[event.player_index] then if not arenatable.bosses[event.player_index] then
global.arena.bosses[event.player_index] = 0 arenatable.bosses[event.player_index] = 0
end end
end end
@ -361,36 +378,39 @@ local function on_gui_click(event)
end end
local function on_pre_player_died(event) local function on_pre_player_died(event)
local arenatable = DungeonsTable.get_arenatable()
local player = game.players[event.player_index] local player = game.players[event.player_index]
if not player.valid then if not player.valid then
return return
end end
for i = 1, 4, 1 do for i = 1, 4, 1 do
if player == global.arena.active_player[i] then if player == arenatable.active_player[i] then
player_died(i, player) player_died(i, player)
end end
end end
end end
local function on_pre_player_left_game(event) local function on_pre_player_left_game(event)
local arenatable = DungeonsTable.get_arenatable()
local player = game.players[event.player_index] local player = game.players[event.player_index]
if not player.valid then if not player.valid then
return return
end end
for i = 1, 4, 1 do for i = 1, 4, 1 do
if player == global.arena.active_player[i] then if player == arenatable.active_player[i] then
player_died(i, player) player_died(i, player)
end end
end end
end end
local function on_entity_died(event) local function on_entity_died(event)
local arenatable = DungeonsTable.get_arenatable()
local entity = event.entity local entity = event.entity
if not entity.valid then if not entity.valid then
return return
end end
for i = 1, 4, 1 do for i = 1, 4, 1 do
if entity == global.arena.active_boss[i] then if entity == arenatable.active_boss[i] then
boss_died(i) boss_died(i)
end end
end end
@ -429,27 +449,28 @@ local function acid_spit(surface, biter, player, tier)
end end
local function boss_attacks(i) local function boss_attacks(i)
if not global.arena.active_boss[i] then local arenatable = DungeonsTable.get_arenatable()
if not arenatable.active_boss[i] then
return return
end end
if not global.arena.active_player[i] then if not arenatable.active_player[i] then
return return
end end
local biter = global.arena.active_boss[i] local biter = arenatable.active_boss[i]
local player = global.arena.active_player[i] local player = arenatable.active_player[i]
local surface = game.surfaces['nauvis'] local surface = game.surfaces['dungeons_floor_arena']
--if not biter.valid or not player.valid or not player.character or not player.character.valid then return end --if not biter.valid or not player.valid or not player.character or not player.character.valid then return end
if not biter or not player or not player.character then if not biter or not player or not player.character then
return return
end end
if global.arena.bosses[player.index] >= 80 then if arenatable.bosses[player.index] >= 80 then
slow(surface, biter, player) slow(surface, biter, player)
--shoot(surface, biter, player) --shoot(surface, biter, player)
end end
if global.arena.timer[i] + 3600 < game.tick and game.tick % 120 == 0 then if arenatable.timer[i] + 3600 < game.tick and game.tick % 120 == 0 then
slow(surface, biter, player) slow(surface, biter, player)
end end
if global.arena.timer[i] + 7200 < game.tick and game.tick % 120 == 0 then if arenatable.timer[i] + 7200 < game.tick and game.tick % 120 == 0 then
shoot(surface, biter, player) shoot(surface, biter, player)
end end
if biter.name == 'small-spitter' then if biter.name == 'small-spitter' then
@ -470,17 +491,18 @@ local function tick()
end end
local function arena_ticker() local function arena_ticker()
local arenatable = DungeonsTable.get_arenatable()
for i = 1, 4, 1 do for i = 1, 4, 1 do
if global.arena.timer[i] == game.tick - 90 then if arenatable.timer[i] == game.tick - 90 then
--game.print("I did a delay") --game.print("I did a delay")
local player = global.arena.active_player[i] local player = arenatable.active_player[i]
if player.valid then if player.valid then
if global.arena.won[i] then if arenatable.won[i] then
--game.print("You won, now get lost") --game.print("You won, now get lost")
teleport_player_out(i, player) teleport_player_out(i, player)
else else
local level = global.arena.bosses[player.index] local level = arenatable.bosses[player.index]
local biter_names = { local biter_names = {
{'small-biter', 'small-spitter'}, {'small-biter', 'small-spitter'},
@ -497,21 +519,13 @@ local function arena_ticker()
end end
local function on_init() local function on_init()
global.arena = {} local arenatable = DungeonsTable.get_arenatable()
global.arena.bosses = {}
global.arena.created = {[1] = false, [2] = false, [3] = false, [4] = false}
global.arena.active_player = {[1] = nil, [2] = nil, [3] = nil, [4] = nil}
global.arena.active_boss = {[1] = nil, [2] = nil, [3] = nil, [4] = nil}
global.arena.enemies = {[1] = nil, [2] = nil, [3] = nil, [4] = nil}
global.arena.timer = {[1] = -100, [2] = -100, [3] = -100, [4] = -100}
global.arena.won = {[1] = false, [2] = false, [3] = false, [4] = false}
global.arena.previous_position = {
[1] = {position = nil, surface = nil},
[2] = {position = nil, surface = nil},
[3] = {position = nil, surface = nil},
[4] = {position = nil, surface = nil}
}
local arena = game.permissions.create_group('Arena') local arena = game.permissions.create_group('Arena')
local arena_surface = game.create_surface('dungeons_floor_arena')
local map_gen_settings = arena_surface.map_gen_settings
map_gen_settings.height = 3
map_gen_settings.width = 3
arena_surface.map_gen_settings = map_gen_settings
arena.set_allows_action(defines.input_action.cancel_craft, false) arena.set_allows_action(defines.input_action.cancel_craft, false)
arena.set_allows_action(defines.input_action.edit_permission_group, false) arena.set_allows_action(defines.input_action.edit_permission_group, false)
arena.set_allows_action(defines.input_action.import_permissions_string, false) arena.set_allows_action(defines.input_action.import_permissions_string, false)
@ -523,7 +537,7 @@ local function on_init()
arena.set_allows_action(defines.input_action.alternative_copy, false) arena.set_allows_action(defines.input_action.alternative_copy, false)
arena.set_allows_action(defines.input_action.begin_mining, false) arena.set_allows_action(defines.input_action.begin_mining, false)
arena.set_allows_action(defines.input_action.begin_mining_terrain, false) arena.set_allows_action(defines.input_action.begin_mining_terrain, false)
arena.set_allows_action(defines.input_action.build_item, false) arena.set_allows_action(defines.input_action.build, false)
arena.set_allows_action(defines.input_action.build_rail, false) arena.set_allows_action(defines.input_action.build_rail, false)
arena.set_allows_action(defines.input_action.build_terrain, false) arena.set_allows_action(defines.input_action.build_terrain, false)
arena.set_allows_action(defines.input_action.copy, false) arena.set_allows_action(defines.input_action.copy, false)
@ -531,7 +545,7 @@ local function on_init()
arena.set_allows_action(defines.input_action.drop_item, false) arena.set_allows_action(defines.input_action.drop_item, false)
for i = 1, 4, 1 do for i = 1, 4, 1 do
local force = game.create_force('arena' .. i) local force = game.create_force('arena' .. i)
global.arena.enemies[i] = force arenatable.enemies[i] = force
force.maximum_following_robot_count = 100 force.maximum_following_robot_count = 100
force.following_robots_lifetime_modifier = 600 force.following_robots_lifetime_modifier = 600
force.set_ammo_damage_modifier('beam', 1) force.set_ammo_damage_modifier('beam', 1)

View File

@ -3,6 +3,8 @@ local Public = {}
local BiterRaffle = require "functions.biter_raffle" local BiterRaffle = require "functions.biter_raffle"
local LootRaffle = require "functions.loot_raffle" local LootRaffle = require "functions.loot_raffle"
local Get_noise = require "utils.get_noise" local Get_noise = require "utils.get_noise"
local DungeonsTable = require 'maps.dungeons.table'
local RPG_T = require 'modules.rpg.table'
local table_shuffle_table = table.shuffle_table local table_shuffle_table = table.shuffle_table
local table_insert = table.insert local table_insert = table.insert
@ -12,20 +14,22 @@ local math_abs = math.abs
local math_floor = math.floor local math_floor = math.floor
function Public.get_dungeon_evolution_factor(surface_index) function Public.get_dungeon_evolution_factor(surface_index)
local e = global.dungeons.depth[surface_index] * 0.0005 local dungeontable = DungeonsTable.get_dungeontable()
if global.dungeons.tiered then local e = dungeontable.depth[surface_index] * 0.0005
e = math.min(e, (surface_index - global.dungeons.original_surface_index) * 0.05 + 0.05) if dungeontable.tiered then
e = math.min(e, (surface_index - dungeontable.original_surface_index) * 0.05 + 0.05)
end end
return e return e
end end
local function blacklist(surface_index, special) local function blacklist(surface_index, special)
local dungeontable = DungeonsTable.get_dungeontable()
local evolution_factor = Public.get_dungeon_evolution_factor(surface_index) local evolution_factor = Public.get_dungeon_evolution_factor(surface_index)
local blacklist = {} local blacklist = {}
--general unused items on dungeons --general unused items on dungeons
blacklist["cliff-explosives"] = true blacklist["cliff-explosives"] = true
--items that would trivialize stuff if dropped too early --items that would trivialize stuff if dropped too early
if global.dungeons.item_blacklist and not special then if dungeontable.item_blacklist and not special then
if evolution_factor < 0.9 then if evolution_factor < 0.9 then
blacklist["discharge-defense-equipment"] = true blacklist["discharge-defense-equipment"] = true
blacklist["power-armor-mk2"] = true blacklist["power-armor-mk2"] = true
@ -58,6 +62,21 @@ local function blacklist(surface_index, special)
return blacklist return blacklist
end end
local function special_loot(value)
local items = {
[1] = {item = 'tank-machine-gun', value = 16384},
[2] = {item = 'tank-cannon', value = 32728},
[3] = {item = 'artillery-wagon-cannon', value = 65536}
}
if math_random(1, 20) == 1 then
local roll = math_random(1, #items)
if items[roll].value < value then
return {loot = {name = items[roll].item, count = 1}, value = value - items[roll].value}
end
end
return {loot = nil, value = value}
end
function Public.roll_spawner_name() function Public.roll_spawner_name()
if math_random(1, 3) == 1 then if math_random(1, 3) == 1 then
return "spitter-spawner" return "spitter-spawner"
@ -70,19 +89,26 @@ function Public.roll_worm_name(surface_index)
end end
function Public.get_crude_oil_amount(surface_index) function Public.get_crude_oil_amount(surface_index)
local dungeontable = DungeonsTable.get_dungeontable()
local amount = math_random(200000, 400000) + Public.get_dungeon_evolution_factor(surface_index) * 500000 local amount = math_random(200000, 400000) + Public.get_dungeon_evolution_factor(surface_index) * 500000
if global.dungeons.tiered then amount = amount / 4 end if dungeontable.tiered then amount = amount / 4 end
return amount return amount
end end
function Public.get_common_resource_amount(surface_index) function Public.get_common_resource_amount(surface_index)
local dungeontable = DungeonsTable.get_dungeontable()
local amount = math_random(350, 700) + Public.get_dungeon_evolution_factor(surface_index) * 16000 local amount = math_random(350, 700) + Public.get_dungeon_evolution_factor(surface_index) * 16000
if global.dungeons.tiered then amount = amount / 8 end if dungeontable.tiered then amount = amount / 8 end
return amount return amount
end end
local function get_loot_value(surface_index, multiplier)
local value = Public.get_dungeon_evolution_factor(surface_index) * 4000 * multiplier
return value
end
function Public.common_loot_crate(surface, position, special) function Public.common_loot_crate(surface, position, special)
local item_stacks = LootRaffle.roll(Public.get_dungeon_evolution_factor(surface.index) * 4000 + math_random(8, 16), 16, blacklist(surface.index, special)) local item_stacks = LootRaffle.roll(get_loot_value(surface.index, 1) + math_random(8, 16), 16, blacklist(surface.index, special))
local container = surface.create_entity({name = "wooden-chest", position = position, force = "neutral"}) local container = surface.create_entity({name = "wooden-chest", position = position, force = "neutral"})
for _, item_stack in pairs(item_stacks) do for _, item_stack in pairs(item_stacks) do
container.insert(item_stack) container.insert(item_stack)
@ -91,7 +117,7 @@ function Public.common_loot_crate(surface, position, special)
end end
function Public.uncommon_loot_crate(surface, position, special) function Public.uncommon_loot_crate(surface, position, special)
local item_stacks = LootRaffle.roll(Public.get_dungeon_evolution_factor(surface.index) * 8000 + math_random(32, 64), 16, blacklist(surface.index, special)) local item_stacks = LootRaffle.roll(get_loot_value(surface.index, 2) + math_random(32, 64), 16, blacklist(surface.index, special))
local container = surface.create_entity({name = "iron-chest", position = position, force = "neutral"}) local container = surface.create_entity({name = "iron-chest", position = position, force = "neutral"})
for _, item_stack in pairs(item_stacks) do for _, item_stack in pairs(item_stacks) do
container.insert(item_stack) container.insert(item_stack)
@ -100,7 +126,7 @@ function Public.uncommon_loot_crate(surface, position, special)
end end
function Public.rare_loot_crate(surface, position, special) function Public.rare_loot_crate(surface, position, special)
local item_stacks = LootRaffle.roll(Public.get_dungeon_evolution_factor(surface.index) * 16000 + math_random(128, 256), 32, blacklist(surface.index, special)) local item_stacks = LootRaffle.roll(get_loot_value(surface.index, 4) + math_random(128, 256), 32, blacklist(surface.index, special))
local container = surface.create_entity({name = "steel-chest", position = position, force = "neutral"}) local container = surface.create_entity({name = "steel-chest", position = position, force = "neutral"})
for _, item_stack in pairs(item_stacks) do for _, item_stack in pairs(item_stacks) do
container.insert(item_stack) container.insert(item_stack)
@ -109,8 +135,19 @@ function Public.rare_loot_crate(surface, position, special)
end end
function Public.epic_loot_crate(surface, position, special) function Public.epic_loot_crate(surface, position, special)
local item_stacks = LootRaffle.roll(Public.get_dungeon_evolution_factor(surface.index) * 32000 + math_random(512, 1024), 48, blacklist(surface.index, special)) local dungeontable = DungeonsTable.get_dungeontable()
local container = surface.create_entity({name = "steel-chest", position = position, force = "neutral"}) local loot_value = get_loot_value(surface.index, 8) + math_random(512, 1024)
local bonus_loot = nil
if dungeontable.tiered and loot_value > 32000 and Public.get_dungeon_evolution_factor(surface_index) > 1 then
local bonus = special_loot(loot_value)
bonus_loot = bonus.loot
loot_value = loot_value - bonus.value
end
local item_stacks = LootRaffle.roll(loot_value, 48, blacklist(surface.index, special))
local container = surface.create_entity({name = "blue-chest", position = position, force = "neutral"})
if bonus_loot then
container.insert(bonus_loot)
end
for _, item_stack in pairs(item_stacks) do for _, item_stack in pairs(item_stacks) do
container.insert(item_stack) container.insert(item_stack)
end end
@ -118,7 +155,7 @@ function Public.epic_loot_crate(surface, position, special)
end end
function Public.crash_site_chest(surface, position, special) function Public.crash_site_chest(surface, position, special)
local item_stacks = LootRaffle.roll(Public.get_dungeon_evolution_factor(surface.index) * 12000 + math_random(160, 320), 48, blacklist(surface.index, special)) local item_stacks = LootRaffle.roll(get_loot_value(surface.index, 3) + math_random(160, 320), 48, blacklist(surface.index, special))
local container = surface.create_entity({name = "crash-site-chest-" .. math_random(1, 2), position = position, force = "neutral"}) local container = surface.create_entity({name = "crash-site-chest-" .. math_random(1, 2), position = position, force = "neutral"})
for _, item_stack in pairs(item_stacks) do for _, item_stack in pairs(item_stacks) do
container.insert(item_stack) container.insert(item_stack)
@ -209,9 +246,10 @@ function Public.add_room_loot_crates(surface, room)
end end
function Public.set_spawner_tier(spawner, surface_index) function Public.set_spawner_tier(spawner, surface_index)
local dungeontable = DungeonsTable.get_dungeontable()
local tier = math_floor(Public.get_dungeon_evolution_factor(surface_index) * 8 - math_random(0, 8)) + 1 local tier = math_floor(Public.get_dungeon_evolution_factor(surface_index) * 8 - math_random(0, 8)) + 1
if tier < 1 then tier = 1 end if tier < 1 then tier = 1 end
global.dungeons.spawner_tier[spawner.unit_number] = tier dungeontable.spawner_tier[spawner.unit_number] = tier
--[[ --[[
rendering.draw_text{ rendering.draw_text{
text = "-Tier " .. tier .. "-", text = "-Tier " .. tier .. "-",
@ -228,13 +266,14 @@ function Public.set_spawner_tier(spawner, surface_index)
end end
function Public.spawn_random_biter(surface, position) function Public.spawn_random_biter(surface, position)
local dungeontable = DungeonsTable.get_dungeontable()
local name = BiterRaffle.roll("mixed", Public.get_dungeon_evolution_factor(surface.index)) local name = BiterRaffle.roll("mixed", Public.get_dungeon_evolution_factor(surface.index))
local non_colliding_position = surface.find_non_colliding_position(name, position, 16, 1) local non_colliding_position = surface.find_non_colliding_position(name, position, 16, 1)
local unit local unit
if non_colliding_position then if non_colliding_position then
unit = surface.create_entity({name = name, position = non_colliding_position, force = global.enemy_forces[surface.index]}) unit = surface.create_entity({name = name, position = non_colliding_position, force = dungeontable.enemy_forces[surface.index]})
else else
unit = surface.create_entity({name = name, position = position, force = global.enemy_forces[surface.index]}) unit = surface.create_entity({name = name, position = position, force = dungeontable.enemy_forces[surface.index]})
end end
unit.ai_settings.allow_try_return_to_spawner = false unit.ai_settings.allow_try_return_to_spawner = false
unit.ai_settings.allow_destroy_when_commands_fail = false unit.ai_settings.allow_destroy_when_commands_fail = false
@ -258,6 +297,83 @@ function Public.place_border_rock(surface, position)
surface.create_entity({name = "rock-big", position = pos}) surface.create_entity({name = "rock-big", position = pos})
end end
function Public.create_scrap(surface, position)
local scraps = {
"crash-site-spaceship-wreck-small-1",
"crash-site-spaceship-wreck-small-1",
"crash-site-spaceship-wreck-small-2",
"crash-site-spaceship-wreck-small-2",
"crash-site-spaceship-wreck-small-3",
"crash-site-spaceship-wreck-small-3",
"crash-site-spaceship-wreck-small-4",
"crash-site-spaceship-wreck-small-4",
"crash-site-spaceship-wreck-small-5",
"crash-site-spaceship-wreck-small-5",
"crash-site-spaceship-wreck-small-6"
}
surface.create_entity({name = scraps[math_random(1, #scraps)], position = position, force = "neutral"})
end
local function get_ore_amount(surface_index)
local dungeontable = DungeonsTable.get_dungeontable()
local scaling = game.forces.player.mining_drill_productivity_bonus
local amount = 5000 * Public.get_dungeon_evolution_factor(surface_index) * (1 + scaling)
if amount > 500 then amount = 500 end
amount = math_random(math_floor(amount * 0.7), math_floor(amount * 1.3))
if amount < 1 then amount = 1 end
return amount
end
local function reward_ores(amount, mined_loot, surface, player, entity)
local a = 0
if player then a = player.insert {name = mined_loot, count = amount} end
amount = amount - a
if amount > 0 then
if amount >= 50 then
for i = 1, math_floor(amount / 50), 1 do
local e = surface.create_entity{name = "item-on-ground", position = entity.position, stack = {name = mined_loot, count = 50}}
if e and e.valid then e.to_be_looted = true end
amount = amount - 50
end
end
if amount > 0 then
if amount < 5 then
surface.spill_item_stack(entity.position,{name = mined_loot, count = amount}, true)
else
local e = surface.create_entity{name = "item-on-ground", position = entity.position, stack = {name = mined_loot, count = amount}}
if e and e.valid then e.to_be_looted = true end
end
end
end
end
local function flying_text(surface, position, text, color)
surface.create_entity({
name = "flying-text",
position = {position.x, position.y - 0.5},
text = text,
color = color
})
end
function Public.rocky_loot(event)
if not event.entity or not event.entity.valid then return end
local allowed = {
["rock-big"] = true,
["rock-huge"] = true,
["sand-rock-big"] = true
}
if not allowed[event.entity.name] then return end
local player = game.players[event.player_index]
local amount = math.ceil(get_ore_amount(player.surface.index))
local rock_mining = {"iron-ore", "iron-ore", "iron-ore", "iron-ore", "copper-ore", "copper-ore", "copper-ore", "stone", "stone", "coal", "coal"}
local mined_loot = rock_mining[math_random(1,#rock_mining)]
local text = "+" .. amount .. " [item=" .. mined_loot .. "]"
flying_text(player.surface, player.position, text, {r = 0.98, g = 0.66, b = 0.22})
reward_ores(amount, mined_loot, player.surface, player, player)
event.buffer.clear()
end
function Public.mining_events(entity) function Public.mining_events(entity)
if math_random(1, 16) == 1 then Public.spawn_random_biter(entity.surface, entity.position) return end if math_random(1, 16) == 1 then Public.spawn_random_biter(entity.surface, entity.position) return end
if math_random(1, 24) == 1 then Public.common_loot_crate(entity.surface, entity.position) return end if math_random(1, 24) == 1 then Public.common_loot_crate(entity.surface, entity.position) return end
@ -267,7 +383,8 @@ function Public.mining_events(entity)
end end
function Public.draw_spawn(surface) function Public.draw_spawn(surface)
local spawn_size = global.dungeons.spawn_size local dungeontable = DungeonsTable.get_dungeontable()
local spawn_size = dungeontable.spawn_size
for _, e in pairs(surface.find_entities({{spawn_size * -1, spawn_size * -1}, {spawn_size, spawn_size}})) do for _, e in pairs(surface.find_entities({{spawn_size * -1, spawn_size * -1}, {spawn_size, spawn_size}})) do
e.destroy() e.destroy()
@ -379,35 +496,35 @@ function Public.draw_spawn(surface)
if k % 3 > 0 then surface.create_entity(e) end if k % 3 > 0 then surface.create_entity(e) end
end end
if global.dungeons.tiered then if dungeontable.tiered then
if surface.index > global.dungeons.original_surface_index then if surface.index > dungeontable.original_surface_index then
table.insert(global.dungeons.transport_surfaces, surface.index) table.insert(dungeontable.transport_surfaces, surface.index)
global.dungeons.transport_chests_inputs[surface.index] = {} dungeontable.transport_chests_inputs[surface.index] = {}
for i = 1, 2, 1 do for i = 1, 2, 1 do
local chest = surface.create_entity({name = "blue-chest", position = {-12 + i * 8, -4}, force = "player"}) local chest = surface.create_entity({name = "blue-chest", position = {-12 + i * 8, -4}, force = "player"})
global.dungeons.transport_chests_inputs[surface.index][i] = chest dungeontable.transport_chests_inputs[surface.index][i] = chest
chest.destructible = false chest.destructible = false
chest.minable = false chest.minable = false
end end
global.dungeons.transport_poles_outputs[surface.index] = {} dungeontable.transport_poles_outputs[surface.index] = {}
for i = 1, 2, 1 do for i = 1, 2, 1 do
local pole = surface.create_entity({name = "constant-combinator", position = {-15 + i * 10, -5}, force = "player"}) local pole = surface.create_entity({name = "constant-combinator", position = {-15 + i * 10, -5}, force = "player"})
global.dungeons.transport_poles_outputs[surface.index][i] = pole dungeontable.transport_poles_outputs[surface.index][i] = pole
pole.destructible = false pole.destructible = false
pole.minable = false pole.minable = false
end end
end end
global.dungeons.transport_chests_outputs[surface.index] = {} dungeontable.transport_chests_outputs[surface.index] = {}
for i = 1, 2, 1 do for i = 1, 2, 1 do
local chest = surface.create_entity({name = "red-chest", position = {-12 + i * 8, 4}, force = "player"}) local chest = surface.create_entity({name = "red-chest", position = {-12 + i * 8, 4}, force = "player"})
global.dungeons.transport_chests_outputs[surface.index][i] = chest dungeontable.transport_chests_outputs[surface.index][i] = chest
chest.destructible = false chest.destructible = false
chest.minable = false chest.minable = false
end end
global.dungeons.transport_poles_inputs[surface.index] = {} dungeontable.transport_poles_inputs[surface.index] = {}
for i = 1, 2, 1 do for i = 1, 2, 1 do
local pole = surface.create_entity({name = "medium-electric-pole", position = {-15 + i * 10, 5}, force = "player"}) local pole = surface.create_entity({name = "medium-electric-pole", position = {-15 + i * 10, 5}, force = "player"})
global.dungeons.transport_poles_inputs[surface.index][i] = pole dungeontable.transport_poles_inputs[surface.index][i] = pole
pole.destructible = false pole.destructible = false
pole.minable = false pole.minable = false
end end

View File

@ -10,6 +10,7 @@ local BiterHealthBooster = require "modules.biter_health_booster"
local BiterRaffle = require "functions.biter_raffle" local BiterRaffle = require "functions.biter_raffle"
local Functions = require "maps.dungeons.functions" local Functions = require "maps.dungeons.functions"
local Get_noise = require "utils.get_noise" local Get_noise = require "utils.get_noise"
local DungeonsTable = require 'maps.dungeons.table'
local Biomes = {} local Biomes = {}
Biomes.dirtlands = require "maps.dungeons.biome_dirtlands" Biomes.dirtlands = require "maps.dungeons.biome_dirtlands"
@ -36,7 +37,12 @@ local disabled_for_deconstruction = {
["rock-huge"] = true, ["rock-huge"] = true,
["rock-big"] = true, ["rock-big"] = true,
["sand-rock-big"] = true, ["sand-rock-big"] = true,
["mineable-wreckage"] = true ["crash-site-spaceship-wreck-small-1"] = true,
["crash-site-spaceship-wreck-small-2"] = true,
["crash-site-spaceship-wreck-small-3"] = true,
["crash-site-spaceship-wreck-small-4"] = true,
["crash-site-spaceship-wreck-small-5"] = true,
["crash-site-spaceship-wreck-small-6"] = true
} }
local function get_biome(position) local function get_biome(position)
@ -69,12 +75,13 @@ local function get_biome(position)
end end
local function draw_depth_gui() local function draw_depth_gui()
local dungeontable = DungeonsTable.get_dungeontable()
for _, player in pairs(game.connected_players) do for _, player in pairs(game.connected_players) do
local surface = player.surface local surface = player.surface
if player.gui.top.dungeon_depth then player.gui.top.dungeon_depth.destroy() end if player.gui.top.dungeon_depth then player.gui.top.dungeon_depth.destroy() end
if surface.name == "gulag" then return end if surface.name == "gulag" then return end
local element = player.gui.top.add({type = "sprite-button", name = "dungeon_depth"}) local element = player.gui.top.add({type = "sprite-button", name = "dungeon_depth"})
element.caption = {"dungeons.depth", global.dungeons.depth[surface.index]} element.caption = {"dungeons.depth", dungeontable.depth[surface.index]}
element.tooltip = { element.tooltip = {
"dungeons.depth_tooltip", "dungeons.depth_tooltip",
Functions.get_dungeon_evolution_factor(surface.index) * 100, Functions.get_dungeon_evolution_factor(surface.index) * 100,
@ -96,6 +103,7 @@ local function draw_depth_gui()
end end
local function expand(surface, position) local function expand(surface, position)
local dungeontable = DungeonsTable.get_dungeontable()
local room = Room_generator.get_room(surface, position) local room = Room_generator.get_room(surface, position)
if not room then return end if not room then return end
local name = get_biome(position) local name = get_biome(position)
@ -105,7 +113,7 @@ local function expand(surface, position)
local a = 2000 local a = 2000
global.dungeons.depth[surface.index] = global.dungeons.depth[surface.index] + 1 dungeontable.depth[surface.index] = dungeontable.depth[surface.index] + 1
local evo = Functions.get_dungeon_evolution_factor(surface.index) local evo = Functions.get_dungeon_evolution_factor(surface.index)
@ -147,11 +155,12 @@ local function init_player(player)
end end
local function on_entity_spawned(event) local function on_entity_spawned(event)
local dungeontable = DungeonsTable.get_dungeontable()
local spawner = event.spawner local spawner = event.spawner
local unit = event.entity local unit = event.entity
local surface = spawner.surface local surface = spawner.surface
local spawner_tier = global.dungeons.spawner_tier local spawner_tier = dungeontable.spawner_tier
if not spawner_tier[spawner.unit_number] then if not spawner_tier[spawner.unit_number] then
Functions.set_spawner_tier(spawner, surface.index) Functions.set_spawner_tier(spawner, surface.index)
end end
@ -246,18 +255,19 @@ local function on_player_joined_game(event)
end end
local function spawner_death(entity) local function spawner_death(entity)
local tier = global.dungeons.spawner_tier[entity.unit_number] local dungeontable = DungeonsTable.get_dungeontable()
local tier = dungeontable.spawner_tier[entity.unit_number]
if not tier then if not tier then
Functions.set_spawner_tier(entity, entity.surface.index) Functions.set_spawner_tier(entity, entity.surface.index)
tier = global.dungeons.spawner_tier[entity.unit_number] tier = dungeontable.spawner_tier[entity.unit_number]
end end
for _ = 1, tier * 2, 1 do for _ = 1, tier * 2, 1 do
Functions.spawn_random_biter(entity.surface, entity.position) Functions.spawn_random_biter(entity.surface, entity.position)
end end
global.dungeons.spawner_tier[entity.unit_number] = nil dungeontable.spawner_tier[entity.unit_number] = nil
end end
--make expansion rocks very durable against biters --make expansion rocks very durable against biters
@ -300,6 +310,7 @@ local function on_marked_for_deconstruction(event)
end end
local function on_init() local function on_init()
local dungeontable = DungeonsTable.get_dungeontable()
local force = game.create_force("dungeon") local force = game.create_force("dungeon")
force.set_friend("enemy", false) force.set_friend("enemy", false)
force.set_friend("player", false) force.set_friend("player", false)
@ -343,15 +354,10 @@ local function on_init()
game.map_settings.enemy_expansion.max_expansion_distance = 16 game.map_settings.enemy_expansion.max_expansion_distance = 16
game.map_settings.pollution.enemy_attack_pollution_consumption_modifier = 0.50 game.map_settings.pollution.enemy_attack_pollution_consumption_modifier = 0.50
global.dungeons = {} dungeontable.tiered = false
global.dungeons.tiered = false dungeontable.depth[1] = 0
global.dungeons.depth = {} dungeontable.depth[game.surfaces["dungeons"].index] = 0
global.dungeons.depth[1] = 0 dungeontable.enemy_forces[game.surfaces["dungeons"].index] = game.forces.enemy
global.dungeons.depth[game.surfaces["dungeons"].index] = 0
global.dungeons.spawn_size = 42
global.dungeons.spawner_tier = {}
global.enemy_forces = {}
global.enemy_forces[game.surfaces["dungeons"].index] = game.forces.enemy
global.rocks_yield_ore_base_amount = 100 global.rocks_yield_ore_base_amount = 100
global.rocks_yield_ore_distance_modifier = 0.001 global.rocks_yield_ore_distance_modifier = 0.001

77
maps/dungeons/table.lua Normal file
View File

@ -0,0 +1,77 @@
-- one table to rule them all!
local Global = require 'utils.global'
local Event = require 'utils.event'
local dungeontable = {}
local arenatable = {}
local Public = {}
Global.register(
dungeontable,
function(tbl)
dungeontable = tbl
end
)
Global.register(
arenatable,
function(tbl)
arenatable = tbl
end
)
function Public.reset_arenatable()
for k, _ in pairs(arenatable) do
arenatable[k] = nil
end
arenatable.bosses = {}
arenatable.created = {[1] = false, [2] = false, [3] = false, [4] = false}
arenatable.active_player = {[1] = nil, [2] = nil, [3] = nil, [4] = nil}
arenatable.active_boss = {[1] = nil, [2] = nil, [3] = nil, [4] = nil}
arenatable.enemies = {[1] = nil, [2] = nil, [3] = nil, [4] = nil}
arenatable.timer = {[1] = -100, [2] = -100, [3] = -100, [4] = -100}
arenatable.won = {[1] = false, [2] = false, [3] = false, [4] = false}
arenatable.previous_position = {
[1] = {position = nil, surface = nil},
[2] = {position = nil, surface = nil},
[3] = {position = nil, surface = nil},
[4] = {position = nil, surface = nil}
}
end
function Public.reset_dungeontable()
for k, _ in pairs(dungeontable) do
dungeontable[k] = nil
end
dungeontable.tiered = false
dungeontable.depth = {}
dungeontable.spawn_size = 42
dungeontable.spawner_tier = {}
dungeontable.transport_chests_inputs = {}
dungeontable.transport_chests_outputs = {}
dungeontable.transport_poles_inputs = {}
dungeontable.transport_poles_outputs = {}
dungeontable.transport_surfaces = {}
dungeontable.surface_size = {}
dungeontable.treasures = {}
dungeontable.mage_towers = {0, 0, 0, 0, 0, 0, 0, 0}
dungeontable.item_blacklist = false
dungeontable.original_surface_index = 1
dungeontable.enemy_forces = {}
end
function Public.get_arenatable()
return arenatable
end
function Public.get_dungeontable()
return dungeontable
end
local function on_init()
Public.reset_arenatable()
Public.reset_dungeontable()
end
Event.on_init(on_init)
return Public

View File

@ -9,11 +9,12 @@ local Room_generator = require "functions.room_generator"
require "modules.rpg.main" require "modules.rpg.main"
local RPG_F = require "modules.rpg.functions" local RPG_F = require "modules.rpg.functions"
local RPG_T = require 'modules.rpg.table' local RPG_T = require 'modules.rpg.table'
local BiterHealthBooster = require "modules.biter_health_booster" local BiterHealthBooster = require "modules.biter_health_booster_v2"
local BiterRaffle = require "functions.biter_raffle" local BiterRaffle = require "functions.biter_raffle"
local Functions = require "maps.dungeons.functions" local Functions = require "maps.dungeons.functions"
local Get_noise = require "utils.get_noise" local Get_noise = require "utils.get_noise"
local Alert = require 'utils.alert' local Alert = require 'utils.alert'
local DungeonsTable = require 'maps.dungeons.table'
require 'maps.dungeons.boss_arena' require 'maps.dungeons.boss_arena'
local Biomes = {} local Biomes = {}
@ -44,7 +45,12 @@ local disabled_for_deconstruction = {
["rock-huge"] = true, ["rock-huge"] = true,
["rock-big"] = true, ["rock-big"] = true,
["sand-rock-big"] = true, ["sand-rock-big"] = true,
["mineable-wreckage"] = true ["crash-site-spaceship-wreck-small-1"] = true,
["crash-site-spaceship-wreck-small-2"] = true,
["crash-site-spaceship-wreck-small-3"] = true,
["crash-site-spaceship-wreck-small-4"] = true,
["crash-site-spaceship-wreck-small-5"] = true,
["crash-site-spaceship-wreck-small-6"] = true
} }
local function get_biome(position, surface_index) local function get_biome(position, surface_index)
@ -116,26 +122,29 @@ local function draw_arrows_gui()
end end
local function get_surface_research(index) local function get_surface_research(index)
return locked_researches[index - global.dungeons.original_surface_index] local dungeontable = DungeonsTable.get_dungeontable()
return locked_researches[index - dungeontable.original_surface_index]
end end
local function draw_depth_gui() local function draw_depth_gui()
local dungeontable = DungeonsTable.get_dungeontable()
local forceshp = BiterHealthBooster.get("biter_health_boost_forces")
for _, player in pairs(game.connected_players) do for _, player in pairs(game.connected_players) do
local surface = player.surface local surface = player.surface
local techs = 0 local techs = 0
if get_surface_research(surface.index) and game.forces.player.technologies[get_surface_research(surface.index)].enabled == false then techs = 1 end if get_surface_research(surface.index) and game.forces.player.technologies[get_surface_research(surface.index)].enabled == false then techs = 1 end
local enemy_force = global.enemy_forces[surface.index] local enemy_force = dungeontable.enemy_forces[surface.index]
if player.gui.top.dungeon_depth then player.gui.top.dungeon_depth.destroy() end if player.gui.top.dungeon_depth then player.gui.top.dungeon_depth.destroy() end
if surface.name == "gulag" or surface.name == "nauvis" then return end if surface.name == "gulag" or surface.name == "nauvis" or surface.name == "dungeons_floor_arena" then return end
local element = player.gui.top.add({type = "sprite-button", name = "dungeon_depth"}) local element = player.gui.top.add({type = "sprite-button", name = "dungeon_depth"})
element.caption = {"dungeons_tiered.depth", surface.index - global.dungeons.original_surface_index, global.dungeons.depth[surface.index]} element.caption = {"dungeons_tiered.depth", surface.index - dungeontable.original_surface_index, dungeontable.depth[surface.index]}
element.tooltip = { element.tooltip = {
"dungeons_tiered.depth_tooltip", "dungeons_tiered.depth_tooltip",
Functions.get_dungeon_evolution_factor(surface.index) * 100, Functions.get_dungeon_evolution_factor(surface.index) * 100,
global.biter_health_boost_forces[enemy_force.index] * 100, forceshp[enemy_force.index] * 100,
math_round(enemy_force.get_ammo_damage_modifier("melee") * 100 + 100, 1), math_round(enemy_force.get_ammo_damage_modifier("melee") * 100 + 100, 1),
Functions.get_dungeon_evolution_factor(surface.index) * 2000, Functions.get_dungeon_evolution_factor(surface.index) * 2000,
global.dungeons.treasures[surface.index], dungeontable.treasures[surface.index],
techs techs
} }
@ -153,14 +162,17 @@ local function draw_depth_gui()
end end
local function unlock_researches(surface_index) local function unlock_researches(surface_index)
local dungeontable = DungeonsTable.get_dungeontable()
local tech = game.forces.player.technologies local tech = game.forces.player.technologies
if get_surface_research(surface_index) and tech[get_surface_research(surface_index)].enabled == false then if get_surface_research(surface_index) and tech[get_surface_research(surface_index)].enabled == false then
tech[get_surface_research(surface_index)].enabled = true tech[get_surface_research(surface_index)].enabled = true
game.print({"dungeons_tiered.tech_unlock", "[technology=" .. get_surface_research(surface_index) .. "]", surface_index - global.dungeons.original_surface_index}) game.print({"dungeons_tiered.tech_unlock", "[technology=" .. get_surface_research(surface_index) .. "]", surface_index - dungeontable.original_surface_index})
end end
end end
local function expand(surface, position) local function expand(surface, position)
local dungeontable = DungeonsTable.get_dungeontable()
local forceshp = BiterHealthBooster.get("biter_health_boost_forces")
local room local room
local roll = math_random(1,100) local roll = math_random(1,100)
if roll > 96 then if roll > 96 then
@ -175,13 +187,13 @@ local function expand(surface, position)
room = Room_generator.get_room(surface, position, "square") room = Room_generator.get_room(surface, position, "square")
end end
if not room then return end if not room then return end
if global.dungeons.treasures[surface.index] < 5 and global.dungeons.surface_size[surface.index] >= 225 and math.random(1,50) == 1 then if dungeontable.treasures[surface.index] < 5 and dungeontable.surface_size[surface.index] >= 225 and math.random(1,50) == 1 then
Biomes["treasure"](surface, room) Biomes["treasure"](surface, room)
if room.room_tiles[1] then if room.room_tiles[1] then
global.dungeons.treasures[surface.index] = global.dungeons.treasures[surface.index] + 1 dungeontable.treasures[surface.index] = dungeontable.treasures[surface.index] + 1
game.print({"dungeons_tiered.treasure_room", surface.index - global.dungeons.original_surface_index}, {r = 0.88, g = 0.22, b = 0}) game.print({"dungeons_tiered.treasure_room", surface.index - dungeontable.original_surface_index}, {r = 0.88, g = 0.22, b = 0})
end end
elseif global.dungeons.surface_size[surface.index] >= 225 and math.random(1,50) == 1 and get_surface_research(surface.index) and game.forces.player.technologies[get_surface_research(surface.index)].enabled == false then elseif dungeontable.surface_size[surface.index] >= 225 and math.random(1,50) == 1 and get_surface_research(surface.index) and game.forces.player.technologies[get_surface_research(surface.index)].enabled == false then
Biomes["laboratory"](surface, room) Biomes["laboratory"](surface, room)
if room.room_tiles[1] then if room.room_tiles[1] then
unlock_researches(surface.index) unlock_researches(surface.index)
@ -195,16 +207,16 @@ local function expand(surface, position)
if not room.room_tiles[1] then return end if not room.room_tiles[1] then return end
global.dungeons.depth[surface.index] = global.dungeons.depth[surface.index] + 1 dungeontable.depth[surface.index] = dungeontable.depth[surface.index] + 1
global.dungeons.surface_size[surface.index] = 200 + (global.dungeons.depth[surface.index] - 100 * (surface.index - global.dungeons.original_surface_index)) / 4 dungeontable.surface_size[surface.index] = 200 + (dungeontable.depth[surface.index] - 100 * (surface.index - dungeontable.original_surface_index)) / 4
local evo = Functions.get_dungeon_evolution_factor(surface.index) local evo = Functions.get_dungeon_evolution_factor(surface.index)
local force = global.enemy_forces[surface.index] local force = dungeontable.enemy_forces[surface.index]
force.evolution_factor = evo force.evolution_factor = evo
if evo > 1 then if evo > 1 then
global.biter_health_boost_forces[force.index] = 3 + ((evo - 1) * 4) forceshp[force.index] = 3 + ((evo - 1) * 4)
local damage_mod = (evo - 1) * 0.35 local damage_mod = (evo - 1) * 0.35
force.set_ammo_damage_modifier("melee", damage_mod) force.set_ammo_damage_modifier("melee", damage_mod)
force.set_ammo_damage_modifier("biological", damage_mod) force.set_ammo_damage_modifier("biological", damage_mod)
@ -212,10 +224,10 @@ local function expand(surface, position)
force.set_ammo_damage_modifier("flamethrower", damage_mod) force.set_ammo_damage_modifier("flamethrower", damage_mod)
force.set_ammo_damage_modifier("laser-turret", damage_mod) force.set_ammo_damage_modifier("laser-turret", damage_mod)
else else
global.biter_health_boost_forces[force.index] = 1 + evo * 2 forceshp[force.index] = 1 + evo * 2
end end
global.biter_health_boost_forces[force.index] = math_round(global.biter_health_boost_forces[force.index], 2) forceshp[force.index] = math_round(forceshp[force.index], 2)
draw_depth_gui() draw_depth_gui()
end end
@ -261,12 +273,14 @@ local function init_player(player, surface)
end end
local function on_entity_spawned(event) local function on_entity_spawned(event)
local dungeontable = DungeonsTable.get_dungeontable()
local forceshp = BiterHealthBooster.get("biter_health_boost_forces")
local spawner = event.spawner local spawner = event.spawner
local unit = event.entity local unit = event.entity
local surface = spawner.surface local surface = spawner.surface
local force = unit.force local force = unit.force
local spawner_tier = global.dungeons.spawner_tier local spawner_tier = dungeontable.spawner_tier
if not spawner_tier[spawner.unit_number] then if not spawner_tier[spawner.unit_number] then
Functions.set_spawner_tier(spawner, surface.index) Functions.set_spawner_tier(spawner, surface.index)
end end
@ -285,18 +299,18 @@ local function on_entity_spawned(event)
bonus_unit.ai_settings.allow_destroy_when_commands_fail = true bonus_unit.ai_settings.allow_destroy_when_commands_fail = true
if math_random(1, 256) == 1 then if math_random(1, 256) == 1 then
BiterHealthBooster.add_boss_unit(bonus_unit, global.biter_health_boost_forces[force.index] * 8, 0.25) BiterHealthBooster.add_boss_unit(bonus_unit, forceshp[force.index] * 8, 0.25)
end end
end end
if math_random(1, 256) == 1 then if math_random(1, 256) == 1 then
BiterHealthBooster.add_boss_unit(unit, global.biter_health_boost_forces[force.index] * 8, 0.25) BiterHealthBooster.add_boss_unit(unit, forceshp[force.index] * 8, 0.25)
end end
end end
local function on_chunk_generated(event) local function on_chunk_generated(event)
local surface = event.surface local surface = event.surface
if surface.name == "nauvis" or surface.name == "gulag" then return end if surface.name == "nauvis" or surface.name == "gulag" or surface.name == "dungeons_floor_arena" then return end
local left_top = event.area.left_top local left_top = event.area.left_top
@ -363,26 +377,28 @@ local function on_player_joined_game(event)
end end
local function spawner_death(entity) local function spawner_death(entity)
local tier = global.dungeons.spawner_tier[entity.unit_number] local dungeontable = DungeonsTable.get_dungeontable()
local tier = dungeontable.spawner_tier[entity.unit_number]
if not tier then if not tier then
Functions.set_spawner_tier(entity, entity.surface.index) Functions.set_spawner_tier(entity, entity.surface.index)
tier = global.dungeons.spawner_tier[entity.unit_number] tier = dungeontable.spawner_tier[entity.unit_number]
end end
for _ = 1, tier * 2, 1 do for _ = 1, tier * 2, 1 do
Functions.spawn_random_biter(entity.surface, entity.position) Functions.spawn_random_biter(entity.surface, entity.position)
end end
global.dungeons.spawner_tier[entity.unit_number] = nil dungeontable.spawner_tier[entity.unit_number] = nil
end end
--make expansion rocks very durable against biters --make expansion rocks very durable against biters
local function on_entity_damaged(event) local function on_entity_damaged(event)
local dungeontable = DungeonsTable.get_dungeontable()
local entity = event.entity local entity = event.entity
if not entity.valid then return end if not entity.valid then return end
if entity.surface.name == "nauvis" then return end if entity.surface.name == "nauvis" or entity.surface.name == "dungeons_floor_arena" then return end
local size = global.dungeons.surface_size[entity.surface.index] local size = dungeontable.surface_size[entity.surface.index]
if size < math.abs(entity.position.y) or size < math.abs(entity.position.x) then if size < math.abs(entity.position.y) or size < math.abs(entity.position.x) then
if entity.name == "rock-big" then if entity.name == "rock-big" then
entity.health = entity.health + event.final_damage_amount entity.health = entity.health + event.final_damage_amount
@ -399,11 +415,12 @@ local function on_entity_damaged(event)
end end
local function on_player_mined_entity(event) local function on_player_mined_entity(event)
local dungeontable = DungeonsTable.get_dungeontable()
local entity = event.entity local entity = event.entity
if not entity.valid then return end if not entity.valid then return end
local player = game.players[event.player_index] local player = game.players[event.player_index]
if entity.name == "rock-big" then if entity.name == "rock-big" then
local size = global.dungeons.surface_size[entity.surface.index] local size = dungeontable.surface_size[entity.surface.index]
if size < math.abs(entity.position.y) or size < math.abs(entity.position.x) then if size < math.abs(entity.position.y) or size < math.abs(entity.position.x) then
entity.surface.create_entity({name = entity.name, position = entity.position}) entity.surface.create_entity({name = entity.name, position = entity.position})
entity.destroy() entity.destroy()
@ -415,12 +432,15 @@ local function on_player_mined_entity(event)
end end
if entity.type == "simple-entity" then if entity.type == "simple-entity" then
Functions.mining_events(entity) Functions.mining_events(entity)
Functions.rocky_loot(event)
end end
if entity.name ~= "rock-big" then return end if entity.name ~= "rock-big" then return end
expand(entity.surface, entity.position) expand(entity.surface, entity.position)
end end
local function on_entity_died(event) local function on_entity_died(event)
local rpg_extra = RPG_T.get("rpg_extra")
local hp_units = BiterHealthBooster.get('biter_health_boost_units')
local entity = event.entity local entity = event.entity
if not entity.valid then return end if not entity.valid then return end
if entity.type == "unit-spawner" then if entity.type == "unit-spawner" then
@ -455,24 +475,26 @@ local function map_gen_settings()
end end
local function get_lowest_safe_floor(player) local function get_lowest_safe_floor(player)
local dungeontable = DungeonsTable.get_dungeontable()
local rpg = RPG_T.get("rpg_t") local rpg = RPG_T.get("rpg_t")
local level = rpg[player.index].level local level = rpg[player.index].level
local sizes = global.dungeons.surface_size local sizes = dungeontable.surface_size
local safe = global.dungeons.original_surface_index local safe = dungeontable.original_surface_index
for key, size in pairs(sizes) do for key, size in pairs(sizes) do
if size > 215 and level >= (key + 1 - global.dungeons.original_surface_index) * 10 and game.surfaces[key + 1] then if size > 215 and level >= (key + 1 - dungeontable.original_surface_index) * 10 and game.surfaces[key + 1] then
safe = key + 1 safe = key + 1
else else
break break
end end
end end
if safe >= global.dungeons.original_surface_index + 50 then safe = global.dungeons.original_surface_index + 50 end if safe >= dungeontable.original_surface_index + 50 then safe = dungeontable.original_surface_index + 50 end
return safe return safe
end end
local function descend(player, button, shift) local function descend(player, button, shift)
local dungeontable = DungeonsTable.get_dungeontable()
local rpg = RPG_T.get("rpg_t") local rpg = RPG_T.get("rpg_t")
if player.surface.index >= global.dungeons.original_surface_index + 50 then if player.surface.index >= dungeontable.original_surface_index + 50 then
player.print({"dungeons_tiered.max_depth"}) player.print({"dungeons_tiered.max_depth"})
return return
end end
@ -480,27 +502,27 @@ local function descend(player, button, shift)
player.print({"dungeons_tiered.only_on_spawn"}) player.print({"dungeons_tiered.only_on_spawn"})
return return
end end
if rpg[player.index].level < (player.surface.index - global.dungeons.original_surface_index) * 10 + 10 then if rpg[player.index].level < (player.surface.index - dungeontable.original_surface_index) * 10 + 10 then
player.print({"dungeons_tiered.level_required", (player.surface.index - global.dungeons.original_surface_index) * 10 + 10}) player.print({"dungeons_tiered.level_required", (player.surface.index - dungeontable.original_surface_index) * 10 + 10})
return return
end end
local surface = game.surfaces[player.surface.index + 1] local surface = game.surfaces[player.surface.index + 1]
if not surface then if not surface then
if global.dungeons.surface_size[player.surface.index] < 215 then if dungeontable.surface_size[player.surface.index] < 215 then
player.print({"dungeons_tiered.floor_size_required"}) player.print({"dungeons_tiered.floor_size_required"})
return return
end end
surface = game.create_surface("dungeons_floor" .. player.surface.index - global.dungeons.original_surface_index + 1, map_gen_settings()) surface = game.create_surface("dungeons_floor" .. player.surface.index - dungeontable.original_surface_index + 1, map_gen_settings())
if surface.index % 5 == global.dungeons.original_surface_index then global.dungeons.spawn_size = 60 else global.dungeons.spawn_size = 42 end if surface.index % 5 == dungeontable.original_surface_index then dungeontable.spawn_size = 60 else dungeontable.spawn_size = 42 end
surface.request_to_generate_chunks({0,0}, 2) surface.request_to_generate_chunks({0,0}, 2)
surface.force_generate_chunk_requests() surface.force_generate_chunk_requests()
surface.daytime = 0.25 + 0.30 * (surface.index / (global.dungeons.original_surface_index + 50)) surface.daytime = 0.25 + 0.30 * (surface.index / (dungeontable.original_surface_index + 50))
surface.freeze_daytime = true surface.freeze_daytime = true
surface.min_brightness = 0 surface.min_brightness = 0
surface.brightness_visual_weights = {1, 1, 1} surface.brightness_visual_weights = {1, 1, 1}
global.dungeons.surface_size[surface.index] = 200 dungeontable.surface_size[surface.index] = 200
global.dungeons.treasures[surface.index] = 0 dungeontable.treasures[surface.index] = 0
game.print({"dungeons_tiered.first_visit", player.name, rpg[player.index].level, surface.index - global.dungeons.original_surface_index}, {r = 0.8, g = 0.5, b = 0}) game.print({"dungeons_tiered.first_visit", player.name, rpg[player.index].level, surface.index - dungeontable.original_surface_index}, {r = 0.8, g = 0.5, b = 0})
--Alert.alert_all_players(15, {"dungeons_tiered.first_visit", player.name, rpg[player.index].level, surface.index - 2}, {r=0.8,g=0.2,b=0},"recipe/artillery-targeting-remote", 0.7) --Alert.alert_all_players(15, {"dungeons_tiered.first_visit", player.name, rpg[player.index].level, surface.index - 2}, {r=0.8,g=0.2,b=0},"recipe/artillery-targeting-remote", 0.7)
end end
@ -511,7 +533,8 @@ local function descend(player, button, shift)
end end
local function ascend(player, button, shift) local function ascend(player, button, shift)
if player.surface.index <= global.dungeons.original_surface_index then local dungeontable = DungeonsTable.get_dungeontable()
if player.surface.index <= dungeontable.original_surface_index then
player.print({"dungeons_tiered.min_depth"}) player.print({"dungeons_tiered.min_depth"})
return return
end end
@ -520,21 +543,27 @@ local function ascend(player, button, shift)
return return
end end
local surface = game.surfaces[player.surface.index - 1] local surface = game.surfaces[player.surface.index - 1]
if button == defines.mouse_button_type.right then surface = game.surfaces[math.max(global.dungeons.original_surface_index, player.surface.index - 5)] end if button == defines.mouse_button_type.right then surface = game.surfaces[math.max(dungeontable.original_surface_index, player.surface.index - 5)] end
if shift then surface = game.surfaces[global.dungeons.original_surface_index] end if shift then surface = game.surfaces[dungeontable.original_surface_index] end
player.teleport(surface.find_non_colliding_position("character", {0, 0}, 50, 0.5), surface) player.teleport(surface.find_non_colliding_position("character", {0, 0}, 50, 0.5), surface)
--player.print({"dungeons_tiered.travel_up"}) --player.print({"dungeons_tiered.travel_up"})
end end
local function on_built_entity(event) local function on_built_entity(event)
local dungeontable = DungeonsTable.get_dungeontable()
local entity = event.created_entity local entity = event.created_entity
if not entity or not entity.valid then return end if not entity or not entity.valid then return end
if entity.name == "spidertron" then if entity.name == "spidertron" then
if entity.surface.index < global.dungeons.original_surface_index + 20 then if entity.surface.index < dungeontable.original_surface_index + 20 then
entity.destroy()
local player = game.players[event.player_index] local player = game.players[event.player_index]
local try_mine = player.mine_entity(entity, true)
if not try_mine then
if entity.valid then
entity.destroy()
player.insert({name = "spidertron", count = 1})
end
end
Alert.alert_player_warning(player, 8, {"dungeons_tiered.spidertron_not_allowed"}) Alert.alert_player_warning(player, 8, {"dungeons_tiered.spidertron_not_allowed"})
player.insert({name = "spidertron", count = 1})
end end
end end
end end
@ -556,10 +585,12 @@ local function on_gui_click(event)
end end
local function on_surface_created(event) local function on_surface_created(event)
local dungeontable = DungeonsTable.get_dungeontable()
local forceshp = BiterHealthBooster.get("biter_health_boost_forces")
local force = game.create_force("enemy" .. event.surface_index) local force = game.create_force("enemy" .. event.surface_index)
global.enemy_forces[event.surface_index] = force dungeontable.enemy_forces[event.surface_index] = force
global.biter_health_boost_forces[force.index] = 1 forceshp[force.index] = 1
global.dungeons.depth[event.surface_index] = 100 * event.surface_index - (global.dungeons.original_surface_index * 100) dungeontable.depth[event.surface_index] = 100 * event.surface_index - (dungeontable.original_surface_index * 100)
end end
local function on_player_changed_surface(event) local function on_player_changed_surface(event)
@ -576,16 +607,17 @@ end
-- local position = player.position -- local position = player.position
-- local surface = player.surface -- local surface = player.surface
-- if surface.index < 2 then return end -- if surface.index < 2 then return end
-- local size = global.dungeons.surface_size[surface.index] -- local size = dungeontable.surface_size[surface.index]
-- if (size >= math.abs(player.position.y) and size < math.abs(player.position.y) + 1) or (size >= math.abs(player.position.x) and size < math.abs(player.position.x) + 1) then -- if (size >= math.abs(player.position.y) and size < math.abs(player.position.y) + 1) or (size >= math.abs(player.position.x) and size < math.abs(player.position.x) + 1) then
-- Alert.alert_player_warning(player, 30, {"dungeons_tiered.too_small"}, {r=0.98,g=0.22,b=0}) -- Alert.alert_player_warning(player, 30, {"dungeons_tiered.too_small"}, {r=0.98,g=0.22,b=0})
-- end -- end
-- end -- end
local function transfer_items(surface_index) local function transfer_items(surface_index)
if surface_index > global.dungeons.original_surface_index then local dungeontable = DungeonsTable.get_dungeontable()
local inputs = global.dungeons.transport_chests_inputs[surface_index] if surface_index > dungeontable.original_surface_index then
local outputs = global.dungeons.transport_chests_outputs[surface_index - 1] local inputs = dungeontable.transport_chests_inputs[surface_index]
local outputs = dungeontable.transport_chests_outputs[surface_index - 1]
for i = 1, 2, 1 do for i = 1, 2, 1 do
if inputs[i].valid and outputs[i].valid then if inputs[i].valid and outputs[i].valid then
local input_inventory = inputs[i].get_inventory(defines.inventory.chest) local input_inventory = inputs[i].get_inventory(defines.inventory.chest)
@ -604,9 +636,10 @@ local function transfer_items(surface_index)
end end
local function transfer_signals(surface_index) local function transfer_signals(surface_index)
if surface_index > global.dungeons.original_surface_index then local dungeontable = DungeonsTable.get_dungeontable()
local inputs = global.dungeons.transport_poles_inputs[surface_index - 1] if surface_index > dungeontable.original_surface_index then
local outputs = global.dungeons.transport_poles_outputs[surface_index] local inputs = dungeontable.transport_poles_inputs[surface_index - 1]
local outputs = dungeontable.transport_poles_outputs[surface_index]
for i = 1, 2, 1 do for i = 1, 2, 1 do
if inputs[i].valid and outputs[i].valid then if inputs[i].valid and outputs[i].valid then
local signals = inputs[i].get_merged_signals(defines.circuit_connector_id.electric_pole) local signals = inputs[i].get_merged_signals(defines.circuit_connector_id.electric_pole)
@ -629,6 +662,8 @@ end
local function on_init() local function on_init()
local dungeontable = DungeonsTable.get_dungeontable()
local forceshp = BiterHealthBooster.get("biter_health_boost_forces")
local force = game.create_force("dungeon") local force = game.create_force("dungeon")
force.set_friend("enemy", false) force.set_friend("enemy", false)
force.set_friend("player", false) force.set_friend("player", false)
@ -665,32 +700,18 @@ local function on_init()
game.map_settings.pollution.enemy_attack_pollution_consumption_modifier = 0.50 game.map_settings.pollution.enemy_attack_pollution_consumption_modifier = 0.50
game.difficulty_settings.technology_price_multiplier = 3 game.difficulty_settings.technology_price_multiplier = 3
global.dungeons = {} dungeontable.tiered = true
global.dungeons.tiered = true dungeontable.depth[surface.index] = 0
global.dungeons.depth = {} dungeontable.depth[nauvis.index] = 0
global.dungeons.depth[surface.index] = 0 dungeontable.surface_size[surface.index] = 200
global.dungeons.depth[nauvis.index] = 0 dungeontable.treasures[surface.index] = 0
global.dungeons.spawn_size = 42 dungeontable.item_blacklist = true
global.dungeons.spawner_tier = {} dungeontable.original_surface_index = surface.index
global.dungeons.transport_chests_inputs = {} dungeontable.enemy_forces[nauvis.index] = game.forces.enemy
global.dungeons.transport_chests_outputs = {} dungeontable.enemy_forces[surface.index] = game.create_force("enemy" .. surface.index)
global.dungeons.transport_poles_inputs = {} forceshp[game.forces.enemy.index] = 1
global.dungeons.transport_poles_outputs = {} forceshp[dungeontable.enemy_forces[surface.index].index] = 1
global.dungeons.transport_surfaces = {}
global.dungeons.surface_size = {}
global.dungeons.surface_size[surface.index] = 200
global.dungeons.treasures = {}
global.dungeons.treasures[surface.index] = 0
global.dungeons.item_blacklist = true
global.dungeons.original_surface_index = surface.index
global.enemy_forces = {}
global.enemy_forces[nauvis.index] = game.forces.enemy
global.enemy_forces[surface.index] = game.create_force("enemy" .. surface.index)
global.biter_health_boost_forces[game.forces.enemy.index] = 1
global.biter_health_boost_forces[global.enemy_forces[surface.index].index] = 1
global.rocks_yield_ore_base_amount = 50
global.rocks_yield_ore_distance_modifier = 0.001
game.forces.player.technologies["land-mine"].enabled = false game.forces.player.technologies["land-mine"].enabled = false
game.forces.player.technologies["landfill"].enabled = false game.forces.player.technologies["landfill"].enabled = false
game.forces.player.technologies["cliff-explosives"].enabled = false game.forces.player.technologies["cliff-explosives"].enabled = false
@ -710,14 +731,12 @@ local function on_init()
T.sub_caption_color = {r = 150, g = 0, b = 20} T.sub_caption_color = {r = 150, g = 0, b = 20}
end end
local function on_tick() local function on_tick()
if game.tick % 60 == 0 then local dungeontable = DungeonsTable.get_dungeontable()
if #global.dungeons.transport_surfaces > 0 then if #dungeontable.transport_surfaces > 0 then
for _,surface_index in pairs(global.dungeons.transport_surfaces) do for _,surface_index in pairs(dungeontable.transport_surfaces) do
transfer_items(surface_index) transfer_items(surface_index)
transfer_signals(surface_index) transfer_signals(surface_index)
end
end end
end end
--[[ --[[
@ -741,7 +760,7 @@ end
local Event = require 'utils.event' local Event = require 'utils.event'
Event.on_init(on_init) Event.on_init(on_init)
Event.add(defines.events.on_tick, on_tick) Event.on_nth_tick(60, on_tick)
Event.add(defines.events.on_marked_for_deconstruction, on_marked_for_deconstruction) Event.add(defines.events.on_marked_for_deconstruction, on_marked_for_deconstruction)
Event.add(defines.events.on_player_joined_game, on_player_joined_game) Event.add(defines.events.on_player_joined_game, on_player_joined_game)
Event.add(defines.events.on_player_mined_entity, on_player_mined_entity) Event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
@ -755,5 +774,3 @@ Event.add(defines.events.on_surface_created, on_surface_created)
Event.add(defines.events.on_gui_click, on_gui_click) Event.add(defines.events.on_gui_click, on_gui_click)
Event.add(defines.events.on_player_changed_surface, on_player_changed_surface) Event.add(defines.events.on_player_changed_surface, on_player_changed_surface)
Event.add(defines.events.on_player_respawned, on_player_respawned) Event.add(defines.events.on_player_respawned, on_player_respawned)
require "modules.rocks_yield_ore"

View File

@ -26,6 +26,7 @@ local this = {
biter_health_boost_count = 0, biter_health_boost_count = 0,
make_normal_unit_mini_bosses = false, make_normal_unit_mini_bosses = false,
active_surface = 'nauvis', active_surface = 'nauvis',
active_surfaces = {},
acid_lines_delay = {}, acid_lines_delay = {},
acid_nova = false, acid_nova = false,
boss_spawns_projectiles = false, boss_spawns_projectiles = false,
@ -181,6 +182,15 @@ local function clean_table()
end end
end end
for name, enabled in pairs(this.active_surfaces) do
local surface = game.surfaces[name]
if surface and surface.valid and enabled then
for _, unit in pairs(surface.find_entities_filtered({type = validTypes})) do
units_to_delete[unit.unit_number] = nil
end
end
end
local surface = game.surfaces[this.active_surface] local surface = game.surfaces[this.active_surface]
for _, unit in pairs(surface.find_entities_filtered({type = validTypes})) do for _, unit in pairs(surface.find_entities_filtered({type = validTypes})) do
@ -371,6 +381,7 @@ function Public.reset_table()
this.biter_health_boost_count = 0 this.biter_health_boost_count = 0
this.make_normal_unit_mini_bosses = false this.make_normal_unit_mini_bosses = false
this.active_surface = 'nauvis' this.active_surface = 'nauvis'
this.active_surfaces = {}
this.check_on_entity_died = false this.check_on_entity_died = false
this.acid_lines_delay = {} this.acid_lines_delay = {}
this.acid_nova = false this.acid_nova = false
@ -413,14 +424,25 @@ function Public.add_boss_unit(unit, health_multiplier, health_bar_size)
end end
--- This sets the active surface that we check and have the script active. --- This sets the active surface that we check and have the script active.
--- This deletes the list of surfaces if we use multiple, so use it only before setting more of them.
---@param string ---@param string
function Public.set_active_surface(str) function Public.set_active_surface(str)
if str and type(str) == 'string' then if str and type(str) == 'string' then
this.active_surfaces = {}
this.active_surface = str this.active_surface = str
end end
return this.active_surface return this.active_surface
end end
--- This sets if this surface is active, when we using multiple surfaces. The default active surface does not need to be added again
---@param string, boolean
function Public.set_surface_activity(name, value)
if name and type(name) == 'string' and type(value) == 'boolean' then
this.active_surfaces[name] = value
end
return this.active_surfaces
end
--- Enables that biter bosses (units with health bars) spawns acid on death. --- Enables that biter bosses (units with health bars) spawns acid on death.
---@param boolean ---@param boolean
function Public.acid_nova(boolean) function Public.acid_nova(boolean)

View File

@ -2,9 +2,9 @@
local mining_chance_weights = { local mining_chance_weights = {
{name = "iron-plate", chance = 1000}, {name = "iron-plate", chance = 1000},
{name = "iron-gear-wheel", chance = 750}, {name = "iron-gear-wheel", chance = 750},
{name = "copper-plate", chance = 750}, {name = "copper-plate", chance = 750},
{name = "copper-cable", chance = 500}, {name = "copper-cable", chance = 500},
{name = "electronic-circuit", chance = 300}, {name = "electronic-circuit", chance = 300},
{name = "steel-plate", chance = 200}, {name = "steel-plate", chance = 200},
{name = "solid-fuel", chance = 150}, {name = "solid-fuel", chance = 150},
@ -30,15 +30,15 @@ local mining_chance_weights = {
{name = "used-up-uranium-fuel-cell", chance = 1}, {name = "used-up-uranium-fuel-cell", chance = 1},
{name = "uranium-fuel-cell", chance = 1}, {name = "uranium-fuel-cell", chance = 1},
{name = "rocket-fuel", chance = 3}, {name = "rocket-fuel", chance = 3},
{name = "rocket-control-unit", chance = 1}, {name = "rocket-control-unit", chance = 1},
{name = "low-density-structure", chance = 1}, {name = "low-density-structure", chance = 1},
{name = "heat-pipe", chance = 1}, {name = "heat-pipe", chance = 1},
{name = "engine-unit", chance = 4}, {name = "engine-unit", chance = 4},
{name = "electric-engine-unit", chance = 2}, {name = "electric-engine-unit", chance = 2},
{name = "logistic-robot", chance = 1}, {name = "logistic-robot", chance = 1},
{name = "construction-robot", chance = 1}, {name = "construction-robot", chance = 1},
{name = "land-mine", chance = 3}, {name = "land-mine", chance = 3},
{name = "grenade", chance = 10}, {name = "grenade", chance = 10},
{name = "rocket", chance = 3}, {name = "rocket", chance = 3},
{name = "explosive-rocket", chance = 3}, {name = "explosive-rocket", chance = 3},
@ -90,7 +90,7 @@ local scrap_yield_amounts = {
["electric-engine-unit"] = 2, ["electric-engine-unit"] = 2,
["logistic-robot"] = 0.3, ["logistic-robot"] = 0.3,
["construction-robot"] = 0.3, ["construction-robot"] = 0.3,
["land-mine"] = 1, ["land-mine"] = 1,
["grenade"] = 2, ["grenade"] = 2,
["rocket"] = 2, ["rocket"] = 2,
@ -105,45 +105,54 @@ local scrap_yield_amounts = {
["destroyer-capsule"] = 0.3, ["destroyer-capsule"] = 0.3,
["distractor-capsule"] = 0.3 ["distractor-capsule"] = 0.3
} }
local scrap_raffle = {} local scrap_raffle = {}
for _, t in pairs (mining_chance_weights) do for _, t in pairs (mining_chance_weights) do
for x = 1, t.chance, 1 do for x = 1, t.chance, 1 do
table.insert(scrap_raffle, t.name) table.insert(scrap_raffle, t.name)
end end
end end
local size_of_scrap_raffle = #scrap_raffle local size_of_scrap_raffle = #scrap_raffle
local function on_player_mined_entity(event) local function on_player_mined_entity(event)
local scraps = {
["crash-site-spaceship-wreck-small-1"] = true,
["crash-site-spaceship-wreck-small-2"] = true,
["crash-site-spaceship-wreck-small-3"] = true,
["crash-site-spaceship-wreck-small-4"] = true,
["crash-site-spaceship-wreck-small-5"] = true,
["crash-site-spaceship-wreck-small-6"] = true,
["mineable-wreckage"] = true
}
local entity = event.entity local entity = event.entity
if not entity.valid then return end if not entity.valid then return end
if entity.name ~= "mineable-wreckage" then return end if not scraps[entity.name] then return end
event.buffer.clear() event.buffer.clear()
local scrap = scrap_raffle[math.random(1, size_of_scrap_raffle)] local scrap = scrap_raffle[math.random(1, size_of_scrap_raffle)]
local amount_bonus = (game.forces.enemy.evolution_factor * 2) + (game.forces.player.mining_drill_productivity_bonus * 2) local amount_bonus = (game.forces.enemy.evolution_factor * 2) + (game.forces.player.mining_drill_productivity_bonus * 2)
local r1 = math.ceil(scrap_yield_amounts[scrap] * (0.3 + (amount_bonus * 0.3))) local r1 = math.ceil(scrap_yield_amounts[scrap] * (0.3 + (amount_bonus * 0.3)))
local r2 = math.ceil(scrap_yield_amounts[scrap] * (1.7 + (amount_bonus * 1.7))) local r2 = math.ceil(scrap_yield_amounts[scrap] * (1.7 + (amount_bonus * 1.7)))
local amount = math.random(r1, r2) local amount = math.random(r1, r2)
local player = game.players[event.player_index] local player = game.players[event.player_index]
local inserted_count = player.insert({name = scrap, count = amount}) local inserted_count = player.insert({name = scrap, count = amount})
if inserted_count ~= amount then if inserted_count ~= amount then
local amount_to_spill = amount - inserted_count local amount_to_spill = amount - inserted_count
entity.surface.spill_item_stack(entity.position,{name = scrap, count = amount_to_spill}, true) entity.surface.spill_item_stack(entity.position,{name = scrap, count = amount_to_spill}, true)
end end
entity.surface.create_entity({ entity.surface.create_entity({
name = "flying-text", name = "flying-text",
position = entity.position, position = entity.position,
text = "+" .. amount .. " [img=item/" .. scrap .. "]", text = "+" .. amount .. " [img=item/" .. scrap .. "]",
color = {r=0.98, g=0.66, b=0.22} color = {r=0.98, g=0.66, b=0.22}
}) })
end end
local Event = require 'utils.event' local Event = require 'utils.event'
Event.add(defines.events.on_player_mined_entity, on_player_mined_entity) Event.add(defines.events.on_player_mined_entity, on_player_mined_entity)