2021-03-24 19:22:45 +02:00
--luacheck: ignore
2020-10-10 05:52:47 +02:00
local Constants = require ' maps.cave_miner_v2.constants '
2020-10-10 01:33:11 +02:00
local Event = require ' utils.event '
2021-03-24 17:46:00 +02:00
local Explosives = require ' modules.explosives_2 '
local Autostash = require ' modules.autostash '
2020-10-10 01:33:11 +02:00
local Functions = require ' maps.cave_miner_v2.functions '
local Global = require ' utils.global '
2020-10-10 05:52:47 +02:00
local Market = require ' maps.cave_miner_v2.market '
2020-10-10 01:33:11 +02:00
local Server = require ' utils.server '
2020-10-10 05:52:47 +02:00
local Terrain = require ' maps.cave_miner_v2.terrain '
2021-03-24 17:46:00 +02:00
local Map_info = require ' modules.map_info '
2020-10-10 01:33:11 +02:00
2021-03-24 17:46:00 +02:00
require ' modules.satellite_score '
require ' modules.hunger '
2020-10-10 15:30:30 +02:00
require ' modules.no_deconstruction_of_neutral_entities '
2021-03-24 17:46:00 +02:00
require ' modules.rocks_broken_paint_tiles '
require ' modules.rocks_heal_over_time '
require ' modules.rocks_yield_ore_veins '
2020-10-10 15:30:30 +02:00
2020-10-10 01:33:11 +02:00
local math_floor = math.floor
local cave_miner = { }
Global.register (
cave_miner ,
function ( tbl )
cave_miner = tbl
end
)
local function on_player_joined_game ( event )
2021-03-24 17:46:00 +02:00
--print mining chances
--for k, v in pairs(table.get_random_weighted_chances(Functions.mining_events)) do game.print(Functions.mining_events[k][3] .. " | " .. math.round(v, 4) .. " | 1 in " .. math_floor(1 / v)) end
local player = game.players [ event.player_index ]
Functions.create_top_gui ( player )
Functions.update_top_gui ( cave_miner )
local tick = game.ticks_played
if tick == 0 then
if player.character and player.character . valid then
player.character . destroy ( )
return
end
end
if player.online_time > 0 then
return
end
for name , count in pairs ( Constants.starting_items ) do
player.insert ( { name = name , count = count } )
end
2020-10-10 01:33:11 +02:00
end
local function on_player_changed_position ( event )
2021-03-24 17:46:00 +02:00
local player = game.players [ event.player_index ]
if not player.character then
return
end
if not player.character . valid then
return
end
Functions.reveal ( cave_miner , game.surfaces . nauvis , game.surfaces . cave_miner_source , { x = math_floor ( player.position . x ) , y = math_floor ( player.position . y ) } , 11 )
2020-10-10 01:33:11 +02:00
end
local function on_chunk_generated ( event )
2021-03-24 17:46:00 +02:00
local surface = event.surface
if surface.index == 1 then
Terrain.out_of_map ( event )
return
end
if surface.name == ' cave_miner_source ' then
Terrain.generate_cave ( event )
return
end
2020-10-10 01:33:11 +02:00
end
2020-10-10 03:43:49 +02:00
local function on_market_item_purchased ( event )
2021-03-24 17:46:00 +02:00
Market.offer_bought ( event , cave_miner )
2020-10-10 03:43:49 +02:00
end
2020-10-10 15:30:30 +02:00
local function on_player_mined_entity ( event )
2021-03-24 17:46:00 +02:00
local entity = event.entity
if not entity then
return
end
if not entity.valid then
return
end
local surface = entity.surface
local position = entity.position
if entity.type == ' simple-entity ' then
cave_miner.rocks_broken = cave_miner.rocks_broken + 1
local f = table.get_random_weighted ( Functions.mining_events )
f ( cave_miner , entity , event.player_index )
end
2020-10-10 15:30:30 +02:00
end
local function on_entity_died ( event )
2021-03-24 17:46:00 +02:00
local entity = event.entity
if not entity then
return
end
if not entity.valid then
return
end
if Functions.on_entity_died [ entity.type ] then
Functions.on_entity_died [ entity.type ] ( cave_miner , entity )
end
2020-10-10 15:30:30 +02:00
end
local function on_entity_spawned ( event )
2021-03-24 17:46:00 +02:00
local spawner = event.spawner
local unit = event.entity
local surface = spawner.surface
Functions.spawn_random_biter ( surface , unit.position , 1 )
unit.destroy ( )
2020-10-10 15:30:30 +02:00
end
2020-10-10 01:33:11 +02:00
local function init ( cave_miner )
2021-03-24 17:46:00 +02:00
local tick = game.ticks_played
if tick % 60 ~= 0 then
return
end
Terrain.roll_source_surface ( )
local surface = game.surfaces . nauvis
surface.min_brightness = 0.08
surface.brightness_visual_weights = { 0.92 , 0.92 , 0.92 }
surface.daytime = 0.43
surface.freeze_daytime = true
surface.solar_power_multiplier = 3
cave_miner.last_reroll_player_name = ' '
cave_miner.reveal_queue = { }
cave_miner.darkness = { }
cave_miner.rocks_broken = 0
cave_miner.pickaxe_tier = 1
local force = game.forces . player
Functions.set_mining_speed ( cave_miner , force )
force.technologies [ ' steel-axe ' ] . enabled = false
force.technologies [ ' landfill ' ] . enabled = false
force.technologies [ ' spidertron ' ] . enabled = false
force.technologies [ ' artillery ' ] . enabled = false
force.technologies [ ' artillery-shell-range-1 ' ] . enabled = false
force.technologies [ ' artillery-shell-speed-1 ' ] . enabled = false
force.character_inventory_slots_bonus = 0
cave_miner.gamestate = ' spawn_players '
2020-10-10 01:33:11 +02:00
end
local function spawn_players ( cave_miner )
2021-03-24 17:46:00 +02:00
local tick = game.ticks_played
if tick % 60 ~= 0 then
return
end
Functions.reveal ( cave_miner , game.surfaces . nauvis , game.surfaces . cave_miner_source , { x = 0 , y = 0 } , 8 )
Market.spawn ( cave_miner )
for _ , player in pairs ( game.connected_players ) do
Functions.spawn_player ( player )
end
cave_miner.gamestate = ' game_in_progress '
2020-10-10 01:33:11 +02:00
end
2020-10-19 19:35:32 +02:00
local game_tasks = {
2021-03-24 17:46:00 +02:00
[ 15 ] = Functions.update_top_gui ,
[ 30 ] = function ( )
local reveal = cave_miner.reveal_queue [ 1 ]
if not reveal then
return
end
local brush_size = 3
if Constants.reveal_chain_brush_sizes [ reveal [ 1 ] ] then
brush_size = Constants.reveal_chain_brush_sizes [ reveal [ 1 ] ]
end
Functions.reveal ( cave_miner , game.surfaces . nauvis , game.surfaces . cave_miner_source , { x = reveal [ 2 ] , y = reveal [ 3 ] } , brush_size )
table.remove ( cave_miner.reveal_queue , 1 )
end ,
[ 45 ] = Functions.darkness
2020-10-19 19:35:32 +02:00
}
2020-10-10 01:33:11 +02:00
local function game_in_progress ( cave_miner )
2021-03-24 17:46:00 +02:00
local tick = game.ticks_played % 60
if not game_tasks [ tick ] then
return
end
game_tasks [ tick ] ( cave_miner )
2020-10-10 01:33:11 +02:00
end
local gamestates = {
2021-03-24 17:46:00 +02:00
[ ' init ' ] = init ,
[ ' spawn_players ' ] = spawn_players ,
[ ' game_in_progress ' ] = game_in_progress
2020-10-10 01:33:11 +02:00
}
local function on_tick ( )
2021-03-24 17:46:00 +02:00
gamestates [ cave_miner.gamestate ] ( cave_miner )
2020-10-10 01:33:11 +02:00
end
local function on_init ( )
2021-03-24 17:46:00 +02:00
cave_miner.reset_counter = 0
cave_miner.gamestate = ' init '
cave_miner.mining_speed_bonus = 100
cave_miner.pickaxe_tier = 1
cave_miner.rocks_broken = 0
cave_miner.reveal_queue = { }
cave_miner.buildings_raffle = { }
local types = { ' furnace ' , ' assembling-machine ' , ' reactor ' , ' artillery-turret ' , ' boiler ' , ' beacon ' , ' generator ' , ' storage-tank ' , ' roboport ' }
for _ , e in pairs ( game.entity_prototypes ) do
for _ , t in pairs ( types ) do
if e.type == t then
table.insert ( cave_miner.buildings_raffle , e.name )
end
end
end
global.rocks_yield_ore_maximum_amount = 256
global.rocks_yield_ore_base_amount = 16
global.rocks_yield_ore_distance_modifier = 0.0064
Explosives.set_destructible_tile ( ' out-of-map ' , 5000 )
Explosives.set_destructible_tile ( ' water ' , 2000 )
Explosives.set_destructible_tile ( ' water-green ' , 2000 )
Explosives.set_destructible_tile ( ' deepwater-green ' , 2500 )
Explosives.set_destructible_tile ( ' deepwater ' , 2500 )
Explosives.set_destructible_tile ( ' water-shallow ' , 1500 )
Explosives.set_destructible_tile ( ' water-mud ' , 1500 )
game.map_settings . enemy_evolution.destroy_factor = 0
game.map_settings . enemy_evolution.pollution_factor = 0
game.map_settings . enemy_evolution.time_factor = 0
global.rocks_yield_ore_veins . amount_modifier = 0.20
global.rocks_yield_ore_veins . chance = 1024
local T = Map_info.Pop_info ( )
T.localised_category = ' cave_miner '
T.main_caption_color = { r = 200 , g = 100 , b = 0 }
T.sub_caption_color = { r = 0 , g = 175 , b = 175 }
Autostash.insert_into_furnace ( true )
Autostash.insert_into_wagon ( true )
2020-10-10 01:33:11 +02:00
end
Event.on_init ( on_init )
Event.add ( defines.events . on_tick , on_tick )
Event.add ( defines.events . on_chunk_generated , on_chunk_generated )
Event.add ( defines.events . on_player_joined_game , on_player_joined_game )
2020-10-10 03:43:49 +02:00
Event.add ( defines.events . on_player_changed_position , on_player_changed_position )
Event.add ( defines.events . on_market_item_purchased , on_market_item_purchased )
2020-10-10 15:30:30 +02:00
Event.add ( defines.events . on_player_mined_entity , on_player_mined_entity )
Event.add ( defines.events . on_entity_spawned , on_entity_spawned )
Event.add ( defines.events . on_entity_died , on_entity_died )
2020-10-10 03:43:49 +02:00
2021-03-24 17:46:00 +02:00
require ' maps.cave_miner_v2.rocks_yield_ore '