2020-07-29 21:28:48 +02:00
-- Deep dark dungeons by mewmew --
2021-03-24 17:46:00 +02:00
require ' modules.mineable_wreckage_yields_scrap '
require ' modules.satellite_score '
2020-07-29 21:28:48 +02:00
require ' modules.charging_station '
2022-04-23 12:21:45 +02:00
-- Tuning constants
local MIN_ROOMS_TO_DESCEND = 100
2021-03-24 17:46:00 +02:00
local MapInfo = require ' modules.map_info '
local Room_generator = require ' functions.room_generator '
2021-05-25 22:19:20 +02:00
local RPG = require ' modules.rpg.main '
2021-03-24 17:46:00 +02:00
local BiterHealthBooster = require ' modules.biter_health_booster_v2 '
local BiterRaffle = require ' functions.biter_raffle '
local Functions = require ' maps.dungeons.functions '
local Get_noise = require ' utils.get_noise '
2020-07-29 21:28:48 +02:00
local Alert = require ' utils.alert '
2022-02-19 10:33:12 +02:00
local Research = require ' maps.dungeons.research '
2021-03-09 03:58:52 +02:00
local DungeonsTable = require ' maps.dungeons.table '
2022-04-08 06:50:05 +02:00
local BottomFrame = require ' utils.gui.bottom_frame '
2022-02-23 06:19:24 +02:00
local Autostash = require ' modules.autostash '
2022-04-08 06:50:05 +02:00
local Panel = require ' utils.gui.config '
2022-03-14 06:23:29 +02:00
Panel.get ( ' gui_config ' ) . spaghett.noop = true
2022-03-07 09:40:37 +02:00
local Collapse = require ' modules.collapse '
2022-03-14 06:23:29 +02:00
local Changelog = require ' modules.changelog '
2020-07-29 21:28:48 +02:00
require ' maps.dungeons.boss_arena '
2022-02-23 13:52:27 +02:00
require ' modules.melee_mode '
2020-07-29 21:28:48 +02:00
local Biomes = { }
2021-03-24 17:46:00 +02:00
Biomes.dirtlands = require ' maps.dungeons.biome_dirtlands '
Biomes.desert = require ' maps.dungeons.biome_desert '
Biomes.red_desert = require ' maps.dungeons.biome_red_desert '
Biomes.grasslands = require ' maps.dungeons.biome_grasslands '
Biomes.concrete = require ' maps.dungeons.biome_concrete '
Biomes.doom = require ' maps.dungeons.biome_doom '
Biomes.deepblue = require ' maps.dungeons.biome_deepblue '
Biomes.glitch = require ' maps.dungeons.biome_glitch '
Biomes.acid_zone = require ' maps.dungeons.biome_acid_zone '
Biomes.rainbow = require ' maps.dungeons.biome_rainbow '
Biomes.treasure = require ' maps.dungeons.biome_treasure '
Biomes.market = require ' maps.dungeons.biome_market '
Biomes.laboratory = require ' maps.dungeons.biome_laboratory '
2020-07-29 21:28:48 +02:00
local math_random = math.random
local math_round = math.round
2022-02-22 07:46:06 +02:00
local function enable_hard_rooms ( position , surface_index )
2022-03-30 07:44:51 +02:00
local dungeon_table = DungeonsTable.get_dungeontable ( )
local floor = surface_index - dungeon_table.original_surface_index
2022-02-24 12:17:38 +02:00
-- can make it out to ~200 before hitting the "must explore more" limit
-- 140 puts hard rooms halfway between the only dirtlands and the edge
2022-03-30 07:44:51 +02:00
local floor_mindist = 140 - floor * 10
2022-02-22 07:46:06 +02:00
if floor_mindist < 80 then -- all dirtlands within this
return true
end
return position.x ^ 2 + position.y ^ 2 > floor_mindist ^ 2
end
2020-07-29 21:28:48 +02:00
local function get_biome ( position , surface_index )
2021-03-24 17:46:00 +02:00
--if not a then return "concrete" end
if position.x ^ 2 + position.y ^ 2 < 6400 then
return ' dirtlands '
end
local seed = game.surfaces [ surface_index ] . map_gen_settings.seed
local seed_addition = 100000
local a = 1
if Get_noise ( ' dungeons ' , position , seed + seed_addition * a ) > 0.66 then
return ' glitch '
end
2022-02-22 07:46:06 +02:00
if enable_hard_rooms ( position , surface_index ) then
2022-02-23 13:52:27 +02:00
a = a + 1
if Get_noise ( ' dungeons ' , position , seed + seed_addition * a ) > 0.60 then
return ' doom '
end
2022-02-22 07:46:06 +02:00
a = a + 1
if Get_noise ( ' dungeons ' , position , seed + seed_addition * a ) > 0.62 then
return ' acid_zone '
end
a = a + 1
if Get_noise ( ' dungeons ' , position , seed + seed_addition * a ) > 0.60 then
return ' concrete '
end
else
2022-02-23 13:52:27 +02:00
a = a + 3
2021-03-24 17:46:00 +02:00
end
a = a + 1
if Get_noise ( ' dungeons ' , position , seed + seed_addition * a ) > 0.71 then
return ' rainbow '
end
a = a + 1
if Get_noise ( ' dungeons ' , position , seed + seed_addition * a ) > 0.53 then
return ' deepblue '
end
a = a + 1
if Get_noise ( ' dungeons ' , position , seed + seed_addition * a ) > 0.22 then
return ' grasslands '
end
a = a + 1
if Get_noise ( ' dungeons ' , position , seed + seed_addition * a ) > 0.22 then
return ' desert '
end
a = a + 1
if Get_noise ( ' dungeons ' , position , seed + seed_addition * a ) > 0.22 then
return ' red_desert '
end
return ' dirtlands '
2020-07-29 21:28:48 +02:00
end
local function draw_arrows_gui ( )
2021-03-24 17:46:00 +02:00
for _ , player in pairs ( game.connected_players ) do
if not player.gui . top.dungeon_down then
player.gui . top.add ( { type = ' sprite-button ' , name = ' dungeon_down ' , sprite = ' utility/editor_speed_down ' , tooltip = { ' dungeons_tiered.descend ' } } )
end
if not player.gui . top.dungeon_up then
player.gui . top.add ( { type = ' sprite-button ' , name = ' dungeon_up ' , sprite = ' utility/editor_speed_up ' , tooltip = { ' dungeons_tiered.ascend ' } } )
end
end
2020-07-29 21:28:48 +02:00
end
local function draw_depth_gui ( )
2021-03-24 17:46:00 +02:00
local dungeontable = DungeonsTable.get_dungeontable ( )
local forceshp = BiterHealthBooster.get ( ' biter_health_boost_forces ' )
for _ , player in pairs ( game.connected_players ) do
local surface = player.surface
2022-02-19 10:33:12 +02:00
local techs = Research.techs_remain ( surface.index )
2021-03-24 17:46:00 +02:00
local enemy_force = dungeontable.enemy_forces [ surface.index ]
if player.gui . top.dungeon_depth then
player.gui . top.dungeon_depth . destroy ( )
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 ' } )
element.caption = { ' dungeons_tiered.depth ' , surface.index - dungeontable.original_surface_index , dungeontable.depth [ surface.index ] }
element.tooltip = {
' dungeons_tiered.depth_tooltip ' ,
Functions.get_dungeon_evolution_factor ( surface.index ) * 100 ,
forceshp [ enemy_force.index ] * 100 ,
math_round ( enemy_force.get_ammo_damage_modifier ( ' melee ' ) * 100 + 100 , 1 ) ,
2022-04-23 12:21:45 +02:00
Functions.get_base_loot_value ( surface.index ) ,
2021-03-24 17:46:00 +02:00
dungeontable.treasures [ surface.index ] ,
techs
}
local style = element.style
style.minimal_height = 38
style.maximal_height = 38
style.minimal_width = 236
style.top_padding = 2
style.left_padding = 4
style.right_padding = 4
style.bottom_padding = 2
style.font_color = { r = 0 , g = 0 , b = 0 }
style.font = ' default-large-bold '
end
2020-07-29 21:28:48 +02:00
end
local function expand ( surface , position )
2021-03-24 17:46:00 +02:00
local dungeontable = DungeonsTable.get_dungeontable ( )
local forceshp = BiterHealthBooster.get ( ' biter_health_boost_forces ' )
local room
local roll = math_random ( 1 , 100 )
if roll > 96 then
room = Room_generator.get_room ( surface , position , ' big ' )
elseif roll > 88 then
room = Room_generator.get_room ( surface , position , ' wide ' )
elseif roll > 80 then
room = Room_generator.get_room ( surface , position , ' tall ' )
elseif roll > 50 then
room = Room_generator.get_room ( surface , position , ' rect ' )
else
room = Room_generator.get_room ( surface , position , ' square ' )
end
if not room then
return
end
2022-04-23 12:21:45 +02:00
local treasure_room_one_in = 30 + 15 * dungeontable.treasures [ surface.index ]
2022-03-29 07:02:22 +02:00
if dungeontable.surface_size [ surface.index ] >= 225 and math.random ( 1 , treasure_room_one_in ) == 1 and room.room_tiles [ 1 ] then
2022-03-15 09:02:05 +02:00
log ( ' Found treasure room, change was 1 in ' .. treasure_room_one_in )
2021-03-24 17:46:00 +02:00
Biomes [ ' treasure ' ] ( surface , room )
if room.room_tiles [ 1 ] then
dungeontable.treasures [ surface.index ] = dungeontable.treasures [ surface.index ] + 1
game.print ( { ' dungeons_tiered.treasure_room ' , surface.index - dungeontable.original_surface_index } , { r = 0.88 , g = 0.22 , b = 0 } )
end
2022-02-19 10:33:12 +02:00
elseif Research.room_is_lab ( surface.index ) then
2021-03-24 17:46:00 +02:00
Biomes [ ' laboratory ' ] ( surface , room )
if room.room_tiles [ 1 ] then
2022-02-19 10:33:12 +02:00
Research.unlock_research ( surface.index )
2021-03-24 17:46:00 +02:00
end
elseif math_random ( 1 , 256 ) == 1 then
Biomes [ ' market ' ] ( surface , room )
else
local name = get_biome ( position , surface.index )
Biomes [ name ] ( surface , room )
end
if not room.room_tiles [ 1 ] then
return
end
dungeontable.depth [ surface.index ] = dungeontable.depth [ surface.index ] + 1
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 force = dungeontable.enemy_forces [ surface.index ]
force.evolution_factor = evo
if evo > 1 then
forceshp [ force.index ] = 3 + ( ( evo - 1 ) * 4 )
local damage_mod = ( evo - 1 ) * 0.35
force.set_ammo_damage_modifier ( ' melee ' , damage_mod )
force.set_ammo_damage_modifier ( ' biological ' , damage_mod )
force.set_ammo_damage_modifier ( ' artillery-shell ' , damage_mod )
force.set_ammo_damage_modifier ( ' flamethrower ' , damage_mod )
force.set_ammo_damage_modifier ( ' laser ' , damage_mod )
else
forceshp [ force.index ] = 1 + evo * 2
end
forceshp [ force.index ] = math_round ( forceshp [ force.index ] , 2 )
draw_depth_gui ( )
2020-07-29 21:28:48 +02:00
end
2020-08-08 13:17:36 +02:00
local function draw_light ( player )
2021-03-24 17:46:00 +02:00
if not player.character then
return
end
2021-05-25 22:19:20 +02:00
local rpg = RPG.get ( ' rpg_t ' )
2021-03-24 17:46:00 +02:00
local magicka = rpg [ player.index ] . magicka
local scale = 1
if magicka < 50 then
return
end
if magicka >= 100 then
scale = 2
end
if magicka >= 150 then
scale = 3
end
if magicka >= 200 then
scale = 4
end
rendering.draw_light (
{
sprite = ' utility/light_medium ' ,
scale = scale * 5 ,
intensity = scale ,
minimum_darkness = 0 ,
oriented = false ,
color = { 255 , 255 , 255 } ,
target = player.character ,
surface = player.surface ,
visible = true ,
only_in_alt_mode = false
}
)
if player.character . is_flashlight_enabled ( ) then
player.character . disable_flashlight ( )
end
2020-08-08 13:17:36 +02:00
end
2020-07-29 21:28:48 +02:00
local function init_player ( player , surface )
2021-03-24 17:46:00 +02:00
if surface == game.surfaces [ ' dungeons_floor0 ' ] then
if player.character then
2022-02-26 07:47:30 +02:00
player.disassociate_character ( player.character )
2021-03-24 17:46:00 +02:00
player.character . destroy ( )
end
2022-02-26 07:47:30 +02:00
if not player.connected then
log ( ' BUG Player ' .. player.name .. ' is not connected; how did we get here? ' )
end
2021-03-24 17:46:00 +02:00
2022-02-26 07:47:30 +02:00
player.set_controller ( { type = defines.controllers . god } )
2021-03-24 17:46:00 +02:00
player.teleport ( surface.find_non_colliding_position ( ' character ' , { 0 , 0 } , 50 , 0.5 ) , surface )
2022-02-26 07:47:30 +02:00
if not player.create_character ( ) then
log ( ' BUG: create_character for ' .. player.name .. ' failed ' )
end
2021-03-24 17:46:00 +02:00
player.insert ( { name = ' raw-fish ' , count = 8 } )
player.set_quick_bar_slot ( 1 , ' raw-fish ' )
player.insert ( { name = ' pistol ' , count = 1 } )
player.insert ( { name = ' firearm-magazine ' , count = 16 } )
else
if player.surface == surface then
player.teleport ( surface.find_non_colliding_position ( ' character ' , { 0 , 0 } , 50 , 0.5 ) , surface )
end
end
2020-07-29 21:28:48 +02:00
end
local function on_entity_spawned ( event )
2021-03-24 17:46:00 +02:00
local dungeontable = DungeonsTable.get_dungeontable ( )
local forceshp = BiterHealthBooster.get ( ' biter_health_boost_forces ' )
local spawner = event.spawner
local unit = event.entity
local surface = spawner.surface
local force = unit.force
local spawner_tier = dungeontable.spawner_tier
if not spawner_tier [ spawner.unit_number ] then
Functions.set_spawner_tier ( spawner , surface.index )
end
local e = Functions.get_dungeon_evolution_factor ( surface.index )
for _ = 1 , spawner_tier [ spawner.unit_number ] , 1 do
local name = BiterRaffle.roll ( ' mixed ' , e )
local non_colliding_position = surface.find_non_colliding_position ( name , unit.position , 16 , 1 )
local bonus_unit
if non_colliding_position then
bonus_unit = surface.create_entity ( { name = name , position = non_colliding_position , force = force } )
else
bonus_unit = surface.create_entity ( { name = name , position = unit.position , force = force } )
end
bonus_unit.ai_settings . allow_try_return_to_spawner = true
bonus_unit.ai_settings . allow_destroy_when_commands_fail = true
if math_random ( 1 , 256 ) == 1 then
BiterHealthBooster.add_boss_unit ( bonus_unit , forceshp [ force.index ] * 8 , 0.25 )
end
end
if math_random ( 1 , 256 ) == 1 then
BiterHealthBooster.add_boss_unit ( unit , forceshp [ force.index ] * 8 , 0.25 )
end
2020-07-29 21:28:48 +02:00
end
local function on_chunk_generated ( event )
2021-03-24 17:46:00 +02:00
local surface = event.surface
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 tiles = { }
local i = 1
for x = 0 , 31 , 1 do
for y = 0 , 31 , 1 do
local position = { x = left_top.x + x , y = left_top.y + y }
tiles [ i ] = { name = ' out-of-map ' , position = position }
i = i + 1
end
end
surface.set_tiles ( tiles , true )
local rock_positions = { }
2021-03-24 21:23:53 +02:00
-- local set_tiles = surface.set_tiles
-- local nauvis_seed = game.surfaces[surface.index].map_gen_settings.seed
-- local s = math_floor(nauvis_seed * 0.1) + 100
2021-03-24 17:46:00 +02:00
-- for a = 1, 7, 1 do
-- local b = a * s
-- local c = 0.0035 + a * 0.0035
-- local d = c * 0.5
-- local seed = nauvis_seed + b
-- if math_abs(Get_noise("dungeon_sewer", {x = left_top.x + 16, y = left_top.y + 16}, seed)) < 0.12 then
-- for x = 0, 31, 1 do
-- for y = 0, 31, 1 do
-- local position = {x = left_top.x + x, y = left_top.y + y}
-- local noise = math_abs(Get_noise("dungeon_sewer", position, seed))
-- if noise < c then
-- local tile_name = surface.get_tile(position).name
-- if noise > d and tile_name ~= "deepwater-green" then
-- set_tiles({{name = "water-green", position = position}}, true)
-- if math_random(1, 320) == 1 and noise > c - 0.001 then table_insert(rock_positions, position) end
-- else
-- set_tiles({{name = "deepwater-green", position = position}}, true)
-- if math_random(1, 64) == 1 then
-- surface.create_entity({name = "fish", position = position})
-- end
-- end
-- end
-- end
-- end
-- end
-- end
for _ , p in pairs ( rock_positions ) do
Functions.place_border_rock ( surface , p )
end
if left_top.x == 32 and left_top.y == 32 then
Functions.draw_spawn ( surface )
for _ , p in pairs ( game.connected_players ) do
init_player ( p , surface )
end
game.forces . player.chart ( surface , { { - 128 , - 128 } , { 128 , 128 } } )
end
2020-07-29 21:28:48 +02:00
end
local function on_player_joined_game ( event )
2021-03-24 17:46:00 +02:00
draw_arrows_gui ( )
draw_depth_gui ( )
if game.tick == 0 then
return
end
local player = game.players [ event.player_index ]
if player.online_time == 0 then
2022-02-26 05:42:24 +02:00
init_player ( player , game.surfaces [ ' dungeons_floor0 ' ] )
2021-03-24 17:46:00 +02:00
end
2022-02-26 07:47:30 +02:00
if player.character == nil and player.ticks_to_respawn == nil then
log ( ' BUG: ' .. player.name .. ' is missing associated character and is not waiting to respawn ' )
init_player ( player , game.surfaces [ ' dungeons_floor0 ' ] )
end
2021-03-24 17:46:00 +02:00
draw_light ( player )
2020-07-29 21:28:48 +02:00
end
local function spawner_death ( entity )
2021-03-24 17:46:00 +02:00
local dungeontable = DungeonsTable.get_dungeontable ( )
local tier = dungeontable.spawner_tier [ entity.unit_number ]
2020-07-29 21:28:48 +02:00
2021-03-24 17:46:00 +02:00
if not tier then
Functions.set_spawner_tier ( entity , entity.surface . index )
tier = dungeontable.spawner_tier [ entity.unit_number ]
end
2020-07-29 21:28:48 +02:00
2021-03-24 17:46:00 +02:00
for _ = 1 , tier * 2 , 1 do
Functions.spawn_random_biter ( entity.surface , entity.position )
end
2020-07-29 21:28:48 +02:00
2021-03-24 17:46:00 +02:00
dungeontable.spawner_tier [ entity.unit_number ] = nil
2020-07-29 21:28:48 +02:00
end
--make expansion rocks very durable against biters
local function on_entity_damaged ( event )
2021-03-24 17:46:00 +02:00
local dungeontable = DungeonsTable.get_dungeontable ( )
local entity = event.entity
if not entity.valid then
return
end
if entity.surface . name == ' nauvis ' or entity.surface . name == ' dungeons_floor_arena ' then
return
end
local size = dungeontable.surface_size [ entity.surface . index ]
if size < math.abs ( entity.position . y ) or size < math.abs ( entity.position . x ) then
if entity.name == ' rock-big ' then
entity.health = entity.health + event.final_damage_amount
end
return
end
if entity.force . index ~= 3 then
return
end --Neutral Force
if not event.cause then
return
end
if not event.cause . valid then
return
end
if event.cause . force.index ~= 2 then
return
end --Enemy Force
if math_random ( 1 , 256 ) == 1 then
return
end
if entity.name ~= ' rock-big ' then
return
end
entity.health = entity.health + event.final_damage_amount
2020-07-29 21:28:48 +02:00
end
local function on_player_mined_entity ( event )
2021-03-24 17:46:00 +02:00
local dungeontable = DungeonsTable.get_dungeontable ( )
local entity = event.entity
if not entity.valid then
return
end
if entity.name == ' rock-big ' then
local size = dungeontable.surface_size [ entity.surface . index ]
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.destroy ( )
2022-02-24 12:17:38 +02:00
local player = game.players [ event.player_index ]
2021-05-25 22:19:20 +02:00
RPG.gain_xp ( player , - 10 )
2021-03-24 17:46:00 +02:00
Alert.alert_player_warning ( player , 30 , { ' dungeons_tiered.too_small ' } , { r = 0.98 , g = 0.22 , b = 0 } )
event.buffer . clear ( )
return
end
end
if entity.type == ' simple-entity ' then
Functions.mining_events ( entity )
Functions.rocky_loot ( event )
end
if entity.name ~= ' rock-big ' then
return
end
expand ( entity.surface , entity.position )
2020-07-29 21:28:48 +02:00
end
local function on_entity_died ( event )
2021-05-25 22:19:20 +02:00
-- local rpg_extra = RPG.get('rpg_extra')
2021-03-24 21:23:53 +02:00
-- local hp_units = BiterHealthBooster.get('biter_health_boost_units')
2021-03-24 17:46:00 +02:00
local entity = event.entity
if not entity.valid then
return
end
if entity.type == ' unit-spawner ' then
spawner_death ( entity )
end
if entity.name ~= ' rock-big ' then
return
end
expand ( entity.surface , entity.position )
2020-07-29 21:28:48 +02:00
end
2021-07-17 21:57:24 +02:00
local function get_map_gen_settings ( )
local settings = {
2021-03-24 17:46:00 +02:00
[ ' seed ' ] = math_random ( 1 , 1000000 ) ,
[ ' water ' ] = 0 ,
[ ' starting_area ' ] = 1 ,
[ ' cliff_settings ' ] = { cliff_elevation_interval = 0 , cliff_elevation_0 = 0 } ,
[ ' default_enable_all_autoplace_controls ' ] = false ,
[ ' autoplace_settings ' ] = {
[ ' entity ' ] = { treat_missing_as_default = false } ,
[ ' tile ' ] = { treat_missing_as_default = false } ,
[ ' decorative ' ] = { treat_missing_as_default = false }
}
}
2021-07-17 21:57:24 +02:00
return settings
2020-07-29 21:28:48 +02:00
end
local function get_lowest_safe_floor ( player )
2021-03-24 17:46:00 +02:00
local dungeontable = DungeonsTable.get_dungeontable ( )
2021-05-25 22:19:20 +02:00
local rpg = RPG.get ( ' rpg_t ' )
2021-03-24 17:46:00 +02:00
local level = rpg [ player.index ] . level
local sizes = dungeontable.surface_size
local safe = dungeontable.original_surface_index
2022-04-23 12:21:45 +02:00
local min_size = 200 + MIN_ROOMS_TO_DESCEND / 4
2021-03-24 17:46:00 +02:00
for key , size in pairs ( sizes ) do
2022-04-23 12:21:45 +02:00
if size >= min_size and level >= ( key + 1 - dungeontable.original_surface_index ) * 10 and game.surfaces [ key + 1 ] then
2021-03-24 17:46:00 +02:00
safe = key + 1
else
break
end
end
if safe >= dungeontable.original_surface_index + 50 then
safe = dungeontable.original_surface_index + 50
end
return safe
2020-07-29 21:28:48 +02:00
end
local function descend ( player , button , shift )
2021-03-24 17:46:00 +02:00
local dungeontable = DungeonsTable.get_dungeontable ( )
2021-05-25 22:19:20 +02:00
local rpg = RPG.get ( ' rpg_t ' )
2021-03-24 17:46:00 +02:00
if player.surface . index >= dungeontable.original_surface_index + 50 then
player.print ( { ' dungeons_tiered.max_depth ' } )
return
end
if player.position . x ^ 2 + player.position . y ^ 2 > 400 then
player.print ( { ' dungeons_tiered.only_on_spawn ' } )
return
end
if rpg [ player.index ] . level < ( player.surface . index - dungeontable.original_surface_index ) * 10 + 10 then
player.print ( { ' dungeons_tiered.level_required ' , ( player.surface . index - dungeontable.original_surface_index ) * 10 + 10 } )
return
end
local surface = game.surfaces [ player.surface . index + 1 ]
if not surface then
2022-04-23 12:21:45 +02:00
if dungeontable.surface_size [ player.surface . index ] < 200 + MIN_ROOMS_TO_DESCEND / 4 then
player.print ( { ' dungeons_tiered.floor_size_required ' , MIN_ROOMS_TO_DESCEND } )
2021-03-24 17:46:00 +02:00
return
end
2021-07-17 21:57:24 +02:00
surface = game.create_surface ( ' dungeons_floor ' .. player.surface . index - dungeontable.original_surface_index + 1 , get_map_gen_settings ( ) )
2021-03-24 17:46:00 +02:00
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.force_generate_chunk_requests ( )
surface.daytime = 0.25 + 0.30 * ( surface.index / ( dungeontable.original_surface_index + 50 ) )
surface.freeze_daytime = true
surface.min_brightness = 0
surface.brightness_visual_weights = { 1 , 1 , 1 }
dungeontable.surface_size [ surface.index ] = 200
dungeontable.treasures [ surface.index ] = 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)
end
if button == defines.mouse_button_type . right then
surface = game.surfaces [ math.min ( get_lowest_safe_floor ( player ) , player.surface . index + 5 ) ]
end
if shift then
surface = game.surfaces [ get_lowest_safe_floor ( player ) ]
end
player.teleport ( surface.find_non_colliding_position ( ' character ' , { 0 , 0 } , 50 , 0.5 ) , surface )
--player.print({"dungeons_tiered.travel_down"})
2020-07-29 21:28:48 +02:00
end
local function ascend ( player , button , shift )
2021-03-24 17:46:00 +02:00
local dungeontable = DungeonsTable.get_dungeontable ( )
if player.surface . index <= dungeontable.original_surface_index then
player.print ( { ' dungeons_tiered.min_depth ' } )
return
end
if player.position . x ^ 2 + player.position . y ^ 2 > 400 then
player.print ( { ' dungeons_tiered.only_on_spawn ' } )
return
end
local surface = game.surfaces [ player.surface . index - 1 ]
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 [ dungeontable.original_surface_index ]
end
player.teleport ( surface.find_non_colliding_position ( ' character ' , { 0 , 0 } , 50 , 0.5 ) , surface )
--player.print({"dungeons_tiered.travel_up"})
2020-07-29 21:28:48 +02:00
end
2020-10-18 14:36:37 +02:00
local function on_built_entity ( event )
2021-03-24 17:46:00 +02:00
local dungeontable = DungeonsTable.get_dungeontable ( )
local entity = event.created_entity
if not entity or not entity.valid then
return
end
if entity.name == ' spidertron ' then
if entity.surface . index < dungeontable.original_surface_index + 20 then
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 ' } )
end
end
2020-10-18 14:36:37 +02:00
end
2020-07-29 21:28:48 +02:00
local function on_gui_click ( event )
2021-03-24 17:46:00 +02:00
if not event then
return
end
if not event.element then
return
end
if not event.element . valid then
return
end
local button = event.button
local shift = event.shift
local player = game.players [ event.element . player_index ]
if event.element . name == ' dungeon_down ' then
descend ( player , button , shift )
return
elseif event.element . name == ' dungeon_up ' then
ascend ( player , button , shift )
return
end
2020-07-29 21:28:48 +02:00
end
local function on_surface_created ( event )
2021-03-24 17:46:00 +02:00
local dungeontable = DungeonsTable.get_dungeontable ( )
local forceshp = BiterHealthBooster.get ( ' biter_health_boost_forces ' )
local force = game.create_force ( ' enemy ' .. event.surface_index )
dungeontable.enemy_forces [ event.surface_index ] = force
forceshp [ force.index ] = 1
dungeontable.depth [ event.surface_index ] = 100 * event.surface_index - ( dungeontable.original_surface_index * 100 )
BiterHealthBooster.set_surface_activity ( game.surfaces [ event.surface_index ] . name , true )
2020-07-29 21:28:48 +02:00
end
local function on_player_changed_surface ( event )
2021-03-24 17:46:00 +02:00
draw_depth_gui ( )
draw_light ( game.players [ event.player_index ] )
2020-08-08 13:17:36 +02:00
end
local function on_player_respawned ( event )
2021-03-24 17:46:00 +02:00
draw_light ( game.players [ event.player_index ] )
2020-07-29 21:28:48 +02:00
end
-- local function on_player_changed_position(event)
-- local player = game.players[event.player_index]
-- local position = player.position
-- local surface = player.surface
-- if surface.index < 2 then return end
2021-03-09 03:58:52 +02:00
-- local size = dungeontable.surface_size[surface.index]
2020-07-29 21:28:48 +02:00
-- 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})
-- end
-- end
local function transfer_items ( surface_index )
2021-03-24 17:46:00 +02:00
local dungeontable = DungeonsTable.get_dungeontable ( )
if surface_index > dungeontable.original_surface_index then
local inputs = dungeontable.transport_chests_inputs [ surface_index ]
local outputs = dungeontable.transport_chests_outputs [ surface_index - 1 ]
for i = 1 , 2 , 1 do
if inputs [ i ] . valid and outputs [ i ] . valid then
local input_inventory = inputs [ i ] . get_inventory ( defines.inventory . chest )
local output_inventory = outputs [ i ] . get_inventory ( defines.inventory . chest )
input_inventory.sort_and_merge ( )
output_inventory.sort_and_merge ( )
for ii = 1 , # input_inventory , 1 do
if input_inventory [ ii ] . valid_for_read then
local count = output_inventory.insert ( input_inventory [ ii ] )
input_inventory [ ii ] . count = input_inventory [ ii ] . count - count
end
end
end
end
end
2020-07-29 21:28:48 +02:00
end
local function transfer_signals ( surface_index )
2021-03-24 17:46:00 +02:00
local dungeontable = DungeonsTable.get_dungeontable ( )
if surface_index > dungeontable.original_surface_index then
local inputs = dungeontable.transport_poles_inputs [ surface_index - 1 ]
local outputs = dungeontable.transport_poles_outputs [ surface_index ]
for i = 1 , 2 , 1 do
if inputs [ i ] . valid and outputs [ i ] . valid then
local signals = inputs [ i ] . get_merged_signals ( defines.circuit_connector_id . electric_pole )
local combi = outputs [ i ] . get_or_create_control_behavior ( )
for ii = 1 , 15 , 1 do
if signals and signals [ ii ] then
combi.set_signal ( ii , signals [ ii ] )
else
combi.set_signal ( ii , nil )
end
end
end
end
end
2020-07-29 21:28:48 +02:00
end
-- local function setup_magic()
2021-05-25 22:19:20 +02:00
-- local rpg_spells = RPG.get("rpg_spells")
2020-07-29 21:28:48 +02:00
-- end
local function on_init ( )
2022-04-25 04:50:50 +02:00
-- dungeons depends on rpg.main depends on modules.explosives depends on modules.collapse
-- without disabling collapse, it starts logging lots of errors after ~1 week.
Collapse.start_now ( false )
2021-03-24 17:46:00 +02:00
local dungeontable = DungeonsTable.get_dungeontable ( )
local forceshp = BiterHealthBooster.get ( ' biter_health_boost_forces ' )
local force = game.create_force ( ' dungeon ' )
force.set_friend ( ' enemy ' , false )
force.set_friend ( ' player ' , false )
2021-07-17 21:57:24 +02:00
local surface = game.create_surface ( ' dungeons_floor0 ' , get_map_gen_settings ( ) )
2021-03-24 17:46:00 +02:00
surface.request_to_generate_chunks ( { 0 , 0 } , 2 )
surface.force_generate_chunk_requests ( )
surface.daytime = 0.25
surface.freeze_daytime = true
local nauvis = game.surfaces [ 1 ]
nauvis.daytime = 0.25
nauvis.freeze_daytime = true
2021-07-17 21:57:24 +02:00
local map_settings = nauvis.map_gen_settings
map_settings.height = 3
map_settings.width = 3
nauvis.map_gen_settings = map_settings
2021-03-24 17:46:00 +02:00
for chunk in nauvis.get_chunks ( ) do
nauvis.delete_chunk ( { chunk.x , chunk.y } )
end
game.forces . player.manual_mining_speed_modifier = 0.5
game.map_settings . enemy_evolution.destroy_factor = 0
game.map_settings . enemy_evolution.pollution_factor = 0
game.map_settings . enemy_evolution.time_factor = 0
game.map_settings . enemy_expansion.enabled = true
game.map_settings . enemy_expansion.max_expansion_cooldown = 18000
game.map_settings . enemy_expansion.min_expansion_cooldown = 3600
game.map_settings . enemy_expansion.settler_group_max_size = 128
game.map_settings . enemy_expansion.settler_group_min_size = 16
game.map_settings . enemy_expansion.max_expansion_distance = 16
game.map_settings . pollution.enemy_attack_pollution_consumption_modifier = 0.50
dungeontable.tiered = true
dungeontable.depth [ surface.index ] = 0
dungeontable.depth [ nauvis.index ] = 0
dungeontable.surface_size [ surface.index ] = 200
dungeontable.treasures [ surface.index ] = 0
dungeontable.item_blacklist = true
dungeontable.original_surface_index = surface.index
dungeontable.enemy_forces [ nauvis.index ] = game.forces . enemy
dungeontable.enemy_forces [ surface.index ] = game.create_force ( ' enemy ' .. surface.index )
forceshp [ game.forces . enemy.index ] = 1
forceshp [ dungeontable.enemy_forces [ surface.index ] . index ] = 1
BiterHealthBooster.set_surface_activity ( ' dungeons_floor0 ' , true )
game.forces . player.technologies [ ' land-mine ' ] . enabled = false
game.forces . player.technologies [ ' landfill ' ] . enabled = false
game.forces . player.technologies [ ' cliff-explosives ' ] . enabled = false
2022-02-19 10:33:12 +02:00
Research.Init ( dungeontable )
2022-02-23 06:19:24 +02:00
Autostash.insert_into_furnace ( true )
Autostash.insert_into_wagon ( false )
Autostash.bottom_button ( true )
2022-02-26 05:42:24 +02:00
Autostash.set_dungeons_initial_level ( surface.index )
2022-02-23 06:19:24 +02:00
BottomFrame.reset ( )
BottomFrame.activate_custom_buttons ( true )
2021-05-25 22:19:20 +02:00
RPG.set_surface_name ( ' dungeons_floor ' )
local rpg_table = RPG.get ( ' rpg_extra ' )
2021-03-24 17:46:00 +02:00
rpg_table.personal_tax_rate = 0
-- rpg_table.enable_mana = true
-- setup_magic()
local T = MapInfo.Pop_info ( )
T.localised_category = ' dungeons_tiered '
T.main_caption_color = { r = 0 , g = 0 , b = 0 }
T.sub_caption_color = { r = 150 , g = 0 , b = 20 }
2020-07-29 21:28:48 +02:00
end
local function on_tick ( )
2021-03-24 17:46:00 +02:00
local dungeontable = DungeonsTable.get_dungeontable ( )
if # dungeontable.transport_surfaces > 0 then
for _ , surface_index in pairs ( dungeontable.transport_surfaces ) do
transfer_items ( surface_index )
transfer_signals ( surface_index )
end
end
--[[
2020-07-29 21:28:48 +02:00
if game.tick % 4 ~= 0 then return end
local surface = game.surfaces [ " dungeons " ]
local entities = surface.find_entities_filtered ( { name = " rock-big " } )
if not entities [ 1 ] then return end
local entity = entities [ math_random ( 1 , # entities ) ]
surface.request_to_generate_chunks ( entity.position , 3 )
surface.force_generate_chunk_requests ( )
game.forces . player.chart ( surface , { { entity.position . x - 32 , entity.position . y - 32 } , { entity.position . x + 32 , entity.position . y + 32 } } )
entity.die ( )
] ]
end
local Event = require ' utils.event '
Event.on_init ( on_init )
2021-03-09 03:58:52 +02:00
Event.on_nth_tick ( 60 , on_tick )
2022-05-01 20:31:47 +02:00
Event.add ( defines.events . on_marked_for_deconstruction , Functions.on_marked_for_deconstruction )
2020-07-29 21:28:48 +02:00
Event.add ( defines.events . on_player_joined_game , on_player_joined_game )
Event.add ( defines.events . on_player_mined_entity , on_player_mined_entity )
2020-10-18 14:36:37 +02:00
Event.add ( defines.events . on_built_entity , on_built_entity )
2020-07-29 21:28:48 +02:00
-- Event.add(defines.events.on_player_changed_position, on_player_changed_position)
Event.add ( defines.events . on_chunk_generated , on_chunk_generated )
Event.add ( defines.events . on_entity_spawned , on_entity_spawned )
Event.add ( defines.events . on_entity_died , on_entity_died )
Event.add ( defines.events . on_entity_damaged , on_entity_damaged )
Event.add ( defines.events . on_surface_created , on_surface_created )
Event.add ( defines.events . on_gui_click , on_gui_click )
Event.add ( defines.events . on_player_changed_surface , on_player_changed_surface )
2020-08-08 13:17:36 +02:00
Event.add ( defines.events . on_player_respawned , on_player_respawned )
2022-03-14 06:23:29 +02:00
Changelog.SetVersions ( {
2022-04-23 12:21:45 +02:00
{ ver = ' next ' , date = ' the future ' , desc = ' Make suggestions in the comfy #dungeons discord channel ' } ,
{ ver = ' 1.1.1 ' , date = ' 2022-04-10 ' , desc = [ [
Balancing patch
* Evolution goes up faster with floor level 0.05 / level -> 0.06 / level ; e.g . floor 20 now like floor 24 before
* Now require 100 open rooms to descend
* Treasure rooms
* Occur less frequently as each subsequent one is found . was 1 in 30 + 10 * Nfound now 1 in 30 + 15 * Nfound
* Rebalanced ores to match end - game science needs . Was very low on copper
* Loot
* Ammo / follower robot frequency ~ 0.5 x previous
* Loot is calculated at floor evolution * 0.9
* Loot / box down by 0.75 x
* Rocks
* Ore from rocks from 25 + 25 * floor to 40 + 15 * floor capped at floor 15
* Rebalanced to include ~ 10 % more coal to give coal for power
* Require getting to room 100 before you can descend
* Science from rooms 40 - 160 + 2.5 * floor to 60 - 300 + 2.5 * floor
* Atomic bomb research moved to 40 - 50
] ] } ,
2022-03-14 06:23:29 +02:00
{ ver = ' 1.1 ' , date = ' 2022-03-13 ' , desc = [ [
* All research is now found at random .
* Red science floors 0 - 1
* Green on floors 1 - 5
* Gray on floors 5 - 10
* Blue on floors 8 - 13
* Blue / gray on floors 10 - 14
* Purple on floors 12 - 19
* Yellow on floors 14 - 21
* White on floors 20 - 25
* Atomic Bomb / Spidertron on floors 22 - 25
* Add melee mode toggle to top bar . Keeps weapons in main inventory if possible .
* Ore from rocks nerfed . Used to hit max value on floor 2 , now scales up from
floors 0 - 19 along with ore from rooms . After floor 20 ore from rooms scales up faster .
2022-03-15 09:02:05 +02:00
* Treasure rooms
* Rescaled to have similar total resources regardless of size
* Unlimited number of rooms but lower frequency
2022-03-29 07:06:02 +02:00
* Loot is limited to available loot 3 floors lower , but slightly more total value than before .
2022-03-14 06:23:29 +02:00
* Autostash and corpse clearing from Mountain Fortress enabled
* Harder rooms will occur somewhat farther out on the early floors .
* Spawners and worm counts bounded in early rooms .
] ] } ,
{ ver = ' 1.0 ' , date = ' past ' , desc = " Pre-changelog version of multi-floor dungeons " } ,
} )