2020-04-04 04:55:05 +02:00
-- Deep dark dungeons by mewmew --
2020-04-03 22:40:42 +02:00
2020-04-04 00:40:04 +02:00
require " modules.mineable_wreckage_yields_scrap "
2020-04-04 19:07:08 +02:00
local MapInfo = require " modules.map_info "
2020-04-04 04:55:05 +02:00
local Room_generator = require " functions.room_generator "
2020-04-04 20:24:05 +02:00
local RPG = require " modules.rpg "
2020-04-04 10:21:39 +02:00
local BiterHealthBooster = require " modules.biter_health_booster "
2020-04-06 21:41:56 +02:00
local BiterRaffle = require " functions.biter_raffle "
2020-04-05 02:23:03 +02:00
local Functions = require " maps.dungeons.functions "
2020-04-04 04:55:05 +02:00
local Biomes = { }
Biomes.dirtlands = require " maps.dungeons.biome_dirtlands "
2020-04-04 06:25:13 +02:00
Biomes.desert = require " maps.dungeons.biome_desert "
Biomes.red_desert = require " maps.dungeons.biome_red_desert "
2020-04-04 04:55:05 +02:00
Biomes.grasslands = require " maps.dungeons.biome_grasslands "
2020-04-04 06:25:13 +02:00
Biomes.concrete = require " maps.dungeons.biome_concrete "
Biomes.doom = require " maps.dungeons.biome_doom "
2020-04-04 04:55:05 +02:00
Biomes.glitch = require " maps.dungeons.biome_glitch "
2020-04-05 03:39:52 +02:00
Biomes.acid_zone = require " maps.dungeons.biome_acid_zone "
2020-04-04 04:55:05 +02:00
local Get_noise = require " utils.get_noise "
2020-04-04 00:40:04 +02:00
local table_shuffle_table = table.shuffle_table
2020-04-03 22:40:42 +02:00
local table_insert = table.insert
2020-04-04 00:40:04 +02:00
local table_remove = table.remove
2020-04-03 22:40:42 +02:00
local math_random = math.random
2020-04-04 01:13:48 +02:00
local math_abs = math.abs
2020-04-04 10:21:39 +02:00
local math_floor = math.floor
2020-04-03 22:40:42 +02:00
local disabled_for_deconstruction = {
[ " fish " ] = true ,
[ " rock-huge " ] = true ,
[ " rock-big " ] = true ,
[ " sand-rock-big " ] = true ,
[ " mineable-wreckage " ] = true
}
2020-04-04 04:55:05 +02:00
local function get_biome ( position )
2020-04-05 03:39:52 +02:00
if position.x ^ 2 + position.y ^ 2 < 1024 then return " dirtlands " end
2020-04-04 04:55:05 +02:00
local seed = game.surfaces [ 1 ] . map_gen_settings.seed
2020-04-04 06:25:13 +02:00
local seed_addition = 100000
2020-04-04 00:40:04 +02:00
2020-04-05 03:39:52 +02:00
if Get_noise ( " dungeons " , position , seed + seed_addition * 1 ) > 0.60 then return " glitch " end
2020-04-06 21:41:56 +02:00
if Get_noise ( " dungeons " , position , seed + seed_addition * 2 ) > 0.52 then return " doom " end
2020-04-05 03:39:52 +02:00
if Get_noise ( " dungeons " , position , seed + seed_addition * 3 ) > 0.62 then return " acid_zone " end
if Get_noise ( " dungeons " , position , seed + seed_addition * 4 ) > 0.60 then return " concrete " end
2020-04-06 21:41:56 +02:00
if Get_noise ( " dungeons " , position , seed + seed_addition * 5 ) > 0.27 then return " grasslands " end
if Get_noise ( " dungeons " , position , seed + seed_addition * 6 ) > 0.31 then return " red_desert " end
2020-04-05 03:39:52 +02:00
if Get_noise ( " dungeons " , position , seed + seed_addition * 7 ) > 0.25 then return " desert " end
2020-04-04 04:55:05 +02:00
return " dirtlands "
end
2020-04-04 06:25:13 +02:00
local function draw_depth_gui ( )
for _ , player in pairs ( game.connected_players ) do
if player.gui . top.dungeon_depth then player.gui . top.dungeon_depth . destroy ( ) end
2020-04-05 02:23:03 +02:00
local element = player.gui . top.add ( { type = " sprite-button " , name = " dungeon_depth " , caption = " Depth: " .. global.dungeons . depth , tooltip = " Increases whenever a new room is discovered. " } )
2020-04-04 06:25:13 +02:00
local style = element.style
style.minimal_height = 38
style.maximal_height = 38
style.minimal_width = 146
style.top_padding = 2
style.left_padding = 4
style.right_padding = 4
style.bottom_padding = 2
style.font_color = { r = 125 , g = 75 , b = 25 }
style.font = " default-large-bold "
end
end
2020-04-04 04:55:05 +02:00
local function expand ( surface , position )
local room = Room_generator.get_room ( surface , position )
if not room then return end
local name = get_biome ( position )
Biomes [ name ] ( surface , room )
2020-04-04 00:40:04 +02:00
2020-04-04 04:55:05 +02:00
if not room.room_tiles [ 1 ] then return end
global.dungeons . depth = global.dungeons . depth + 1
2020-04-04 06:25:13 +02:00
draw_depth_gui ( )
2020-04-03 22:40:42 +02:00
end
2020-04-04 01:13:48 +02:00
local function on_chunk_generated ( event )
local surface = event.surface
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 }
if math_abs ( position.x ) > 2 or math_abs ( position.y ) > 2 then
tiles [ i ] = { name = " out-of-map " , position = position }
i = i + 1
2020-04-04 04:55:05 +02:00
else
if math_abs ( position.x ) > 1 or math_abs ( position.y ) > 1 then
tiles [ i ] = { name = " black-refined-concrete " , position = position }
i = i + 1
else
tiles [ i ] = { name = " purple-refined-concrete " , position = position }
i = i + 1
end
2020-04-04 01:13:48 +02:00
end
end
end
surface.set_tiles ( tiles , true )
if left_top.x == 32 and left_top.y == 32 then
surface.create_entity ( { name = " rock-big " , position = { 0 , - 2 } } )
surface.create_entity ( { name = " rock-big " , position = { 0 , 2 } } )
surface.create_entity ( { name = " rock-big " , position = { - 2 , 0 } } )
surface.create_entity ( { name = " rock-big " , position = { 2 , 0 } } )
end
end
2020-04-04 10:21:39 +02:00
local function on_entity_spawned ( event )
2020-04-05 02:23:03 +02:00
game.forces . enemy.evolution_factor = global.dungeons . depth * 0.0005
global.biter_health_boost = 1 + global.dungeons . depth * 0.0005
2020-04-04 10:21:39 +02:00
local spawner = event.spawner
local unit = event.entity
2020-04-06 21:41:56 +02:00
local surface = spawner.surface
2020-04-05 02:23:03 +02:00
2020-04-04 10:21:39 +02:00
local spawner_tier = global.dungeons . spawner_tier
if not spawner_tier [ spawner.unit_number ] then
2020-04-06 21:41:56 +02:00
Functions.set_spawner_tier ( spawner )
2020-04-04 10:21:39 +02:00
end
2020-04-06 21:41:56 +02:00
local e = global.dungeons . depth * 0.0005
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 = " enemy " } )
else
bonus_unit = surface.create_entity ( { name = name , position = unit.position , force = " enemy " } )
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 , global.biter_health_boost * 8 , 0.25 )
end
2020-04-04 10:21:39 +02:00
end
2020-04-05 02:23:03 +02:00
2020-04-06 21:41:56 +02:00
if math_random ( 1 , 256 ) == 1 then
BiterHealthBooster.add_boss_unit ( unit , global.biter_health_boost * 8 , 0.25 )
2020-04-05 02:23:03 +02:00
end
2020-04-04 10:21:39 +02:00
end
2020-04-03 22:40:42 +02:00
local function on_player_joined_game ( event )
local player = game.players [ event.player_index ]
local surface = game.surfaces [ " dungeons " ]
if player.online_time == 0 then
player.teleport ( surface.find_non_colliding_position ( " character " , { 0 , 0 } , 50 , 0.5 ) , surface )
2020-04-06 21:41:56 +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 } )
2020-04-04 06:25:13 +02:00
end
draw_depth_gui ( )
2020-04-03 22:40:42 +02:00
end
2020-04-06 21:41:56 +02:00
local function spawner_death ( entity )
local tier = global.dungeons . spawner_tier [ entity.unit_number ]
if not tier then
Functions.set_spawner_tier ( entity )
tier = global.dungeons . spawner_tier [ entity.unit_number ]
end
for _ = 1 , tier * 2 , 1 do
Functions.spawn_random_biter ( entity.surface , entity.position )
end
global.dungeons . spawner_tier [ entity.unit_number ] = nil
end
2020-04-05 03:39:52 +02:00
local function mining_events ( entity )
if math_random ( 1 , 8 ) == 1 then Functions.spawn_random_biter ( entity.surface , entity.position ) return end
if math_random ( 1 , 16 ) == 1 then Functions.common_loot_crate ( entity.surface , entity.position ) return end
if math_random ( 1 , 64 ) == 1 then Functions.uncommon_loot_crate ( entity.surface , entity.position ) return end
if math_random ( 1 , 256 ) == 1 then Functions.rare_loot_crate ( entity.surface , entity.position ) return end
if math_random ( 1 , 1024 ) == 1 then Functions.epic_loot_crate ( entity.surface , entity.position ) return end
end
2020-04-03 22:40:42 +02:00
local function on_player_mined_entity ( event )
local entity = event.entity
2020-04-05 02:23:03 +02:00
if not entity.valid then return end
if entity.type == " simple-entity " then
2020-04-05 03:39:52 +02:00
mining_events ( entity )
2020-04-05 02:23:03 +02:00
end
2020-04-04 00:40:04 +02:00
if entity.name ~= " rock-big " then return end
2020-04-04 04:55:05 +02:00
expand ( entity.surface , entity.position )
2020-04-03 22:40:42 +02:00
end
2020-04-04 10:21:39 +02:00
local function on_entity_died ( event )
local entity = event.entity
2020-04-06 21:41:56 +02:00
if not entity.valid then return end
if entity.type == " unit-spawner " then
spawner_death ( entity )
2020-04-04 10:21:39 +02:00
end
2020-04-04 19:07:08 +02:00
if entity.name ~= " rock-big " then return end
expand ( entity.surface , entity.position )
2020-04-04 10:21:39 +02:00
end
2020-04-03 22:40:42 +02:00
local function on_marked_for_deconstruction ( event )
if disabled_for_deconstruction [ event.entity . name ] then
event.entity . cancel_deconstruction ( game.players [ event.player_index ] . force.name )
end
end
local function on_init ( )
2020-04-04 01:13:48 +02:00
local map_gen_settings = {
[ " 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 } ,
} ,
}
2020-04-03 22:40:42 +02:00
local surface = game.create_surface ( " dungeons " , map_gen_settings )
surface.request_to_generate_chunks ( { 0 , 0 } , 2 )
surface.force_generate_chunk_requests ( )
local surface = game.surfaces [ 1 ]
local map_gen_settings = surface.map_gen_settings
map_gen_settings.height = 3
map_gen_settings.width = 3
surface.map_gen_settings = map_gen_settings
for chunk in surface.get_chunks ( ) do
surface.delete_chunk ( { chunk.x , chunk.y } )
end
2020-04-05 03:39:52 +02:00
game.forces . player.manual_mining_speed_modifier = 0.5
2020-04-04 00:40:04 +02:00
2020-04-05 02:23:03 +02:00
game.map_settings . enemy_evolution.destroy_factor = 0
game.map_settings . enemy_evolution.pollution_factor = 0
game.map_settings . enemy_evolution.time_factor = 0
2020-04-04 04:55:05 +02:00
global.dungeons = { }
global.dungeons . depth = 0
2020-04-04 10:21:39 +02:00
global.dungeons . spawner_tier = { }
2020-04-06 21:41:56 +02:00
global.rocks_yield_ore_base_amount = 100
2020-04-04 10:21:39 +02:00
global.rocks_yield_ore_distance_modifier = 0.001
2020-04-04 19:07:08 +02:00
local T = MapInfo.Pop_info ( )
T.localised_category = " dungeons "
T.main_caption_color = { r = 0 , g = 0 , b = 0 }
T.sub_caption_color = { r = 75 , g = 0 , b = 0 }
2020-04-03 22:40:42 +02:00
end
local Event = require ' utils.event '
Event.on_init ( on_init )
2020-04-04 00:40:04 +02:00
Event.add ( defines.events . on_tick , on_tick )
2020-04-03 22:40:42 +02:00
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_mined_entity , on_player_mined_entity )
2020-04-04 10:21:39 +02:00
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 )
require " modules.rocks_yield_ore "