1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2024-12-26 22:56:43 +02:00
darkness tweaks
reveal terrain around broken container
This commit is contained in:
MewMew 2020-10-26 22:27:46 +01:00
parent bc9517b8d8
commit 2f8137daea
4 changed files with 101 additions and 69 deletions

View File

@ -25,6 +25,41 @@ function Public.roll_biter_amount()
end
end
--lab-dark-1 > position has been copied
--lab-dark-2 > position has been visited
function Public.reveal(cave_miner, surface, source_surface, position, brushsize)
local tile = source_surface.get_tile(position)
if tile.name == "lab-dark-2" then return end
local tiles = {}
local copied_tiles = {}
local i = 0
local brushsize_square = brushsize ^ 2
for _, tile in pairs(source_surface.find_tiles_filtered({area = {{position.x - brushsize, position.y - brushsize}, {position.x + brushsize, position.y + brushsize}}})) do
local tile_position = tile.position
if tile.name ~= "lab-dark-2" and tile.name ~= "lab-dark-1" and (position.x - tile_position.x) ^ 2 + (position.y - tile_position.y) ^ 2 < brushsize_square then
i = i + 1
copied_tiles[i] = {name = "lab-dark-1", position = tile.position}
tiles[i] = {name = tile.name, position = tile.position}
end
end
surface.set_tiles(tiles, true, false, false, false)
source_surface.set_tiles(copied_tiles, false, false, false, false)
for _, entity in pairs(source_surface.find_entities_filtered({area = {{position.x - brushsize, position.y - brushsize}, {position.x + brushsize, position.y + brushsize}}})) do
local entity_position = entity.position
if (position.x - entity_position.x) ^ 2 + (position.y - entity_position.y) ^ 2 < brushsize_square then
entity.clone({position = entity_position, surface = surface})
if entity.force.index == 2 then
table.insert(cave_miner.reveal_queue, {entity.type, entity.position.x, entity.position.y})
end
entity.destroy()
end
end
source_surface.set_tiles({{name = "lab-dark-2", position = position}}, false)
source_surface.request_to_generate_chunks(position, 3)
end
function Public.spawn_player(player)
if not player.character then
player.create_character()
@ -149,17 +184,73 @@ local function is_entity_in_darkness(entity)
return true
end
local function darkness_event(cave_miner, entity)
local index = tostring(entity.unit_number)
local darkness = cave_miner.darkness
if darkness[index] then
darkness[index] = darkness[index] + 1
else
darkness[index] = -3
end
if darkness[index] <= 0 then return end
local position = entity.position
local d = math_sqrt(position.x ^ 2 + position.y ^ 2) * 0.0001
local count = math_floor(darkness[index] * 0.33) + 1
if count > 16 then count = 16 end
for c = 1, count, 1 do
Esq.add_to_queue(game.tick + 10 * c, entity.surface, {name = BiterRaffle.roll("mixed", d), position = position, force = "enemy"}, 8)
end
entity.damage(darkness[index] * 2, "neutral", "poison")
end
function Public.darkness(cave_miner)
for _, player in pairs(game.connected_players) do
local character = player.character
if character and character.valid then
character.disable_flashlight()
if is_entity_in_darkness(character) then
local d = math_sqrt(character.position.x ^ 2 + character.position.y ^ 2) * 0.0001
Esq.add_to_queue(game.tick + 60, player.surface, {name = BiterRaffle.roll("mixed", d), position = character.position, force = "enemy"}, 8)
darkness_event(cave_miner, character)
else
cave_miner.darkness[tostring(character.unit_number)] = nil
end
end
end
end
Public.on_entity_died = {
["unit"] = function(cave_miner, entity)
local position = entity.position
local surface = entity.surface
if math.random(1, 8) == 1 then
surface.spill_item_stack(position, {name = "raw-fish", count = 1}, true)
end
end,
["unit-spawner"] = function(cave_miner, entity)
local position = entity.position
local surface = entity.surface
local a = 64 * 0.0001
local b = math.sqrt(position.x ^ 2 + position.y ^ 2)
local c = math_floor(a * b) + 1
for _ = 1, c, 1 do
Public.spawn_random_biter(surface, position, 1)
end
end,
["simple-entity"] = function(cave_miner, entity)
local position = entity.position
cave_miner.rocks_broken = cave_miner.rocks_broken + 1
if math.random(1, 4) == 1 then
Public.rock_spawns_biters(cave_miner, position)
end
end,
["container"] = function(cave_miner, entity)
local position = entity.position
Public.reveal(cave_miner, game.surfaces.nauvis, game.surfaces.cave_miner_source, position, 16)
end,
}
return Public

View File

@ -51,7 +51,7 @@ local function on_player_changed_position(event)
local player = game.players[event.player_index]
if not player.character then return end
if not player.character.valid then return end
Terrain.reveal(cave_miner, game.surfaces.nauvis, game.surfaces.cave_miner_source, {x = math_floor(player.position.x), y = math_floor(player.position.y)}, 11)
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)
end
local function on_chunk_generated(event)
@ -94,32 +94,8 @@ local function on_entity_died(event)
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 == "unit" then
if math.random(1, 8) == 1 then
surface.spill_item_stack(position, {name = "raw-fish", count = 1}, true)
end
return
end
if entity.type == "simple-entity" then
cave_miner.rocks_broken = cave_miner.rocks_broken + 1
if math.random(1, 4) == 1 then
Functions.rock_spawns_biters(cave_miner, position)
end
return
end
if entity.type == "unit-spawner" then
local a = 64 * 0.0001
local b = math.sqrt(entity.position.x ^ 2 + entity.position.y ^ 2)
local c = math_floor(a * b) + 1
for _ = 1, c, 1 do
Functions.spawn_random_biter(surface, position, 1)
end
return
if Functions.on_entity_died[entity.type] then
Functions.on_entity_died[entity.type](cave_miner, entity)
end
end
@ -145,6 +121,7 @@ local function init(cave_miner)
cave_miner.last_reroll_player_name = ""
cave_miner.reveal_queue = {}
cave_miner.darkness = {}
cave_miner.rocks_broken = 0
cave_miner.pickaxe_tier = 1
@ -164,7 +141,7 @@ end
local function spawn_players(cave_miner)
local tick = game.ticks_played
if tick % 60 ~= 0 then return end
Terrain.reveal(cave_miner, game.surfaces.nauvis, game.surfaces.cave_miner_source, {x = 0, y = 0}, 8)
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)
@ -179,7 +156,7 @@ local game_tasks = {
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
Terrain.reveal(
Functions.reveal(
cave_miner,
game.surfaces.nauvis,
game.surfaces.cave_miner_source,

View File

@ -24,7 +24,7 @@ local special_slots = {
local item_stacks = LootRaffle.roll(math.floor(tier ^ 3.65) + 8, 100, loot_blacklist)
local price = {}
for _, item_stack in pairs(item_stacks) do table.insert(price, {name = item_stack.name, amount = item_stack.count}) end
market.add_market_item({price = price, offer = {type = 'nothing', effect_description = 'Upgrade pickaxe tier to: ' .. pickaxe_tiers[tier]}})
market.add_market_item({price = price, offer = {type = 'nothing', effect_description = 'Upgrade pickaxe to tier ' .. tier .. ': ' .. pickaxe_tiers[tier]}})
else
market.add_market_item({price = price, offer = {type = 'nothing', effect_description = 'Maximum pickaxe upgrade reached!'}})
end

View File

@ -54,42 +54,6 @@ function Public.out_of_map(event)
event.surface.set_tiles(tiles, false)
end
--lab-dark-1 > position has been copied
--lab-dark-2 > position has been visited
function Public.reveal(cave_miner, surface, source_surface, position, brushsize)
local tile = source_surface.get_tile(position)
if tile.name == "lab-dark-2" then return end
local tiles = {}
local copied_tiles = {}
local i = 0
local brushsize_square = brushsize ^ 2
for _, tile in pairs(source_surface.find_tiles_filtered({area = {{position.x - brushsize, position.y - brushsize}, {position.x + brushsize, position.y + brushsize}}})) do
local tile_position = tile.position
if tile.name ~= "lab-dark-2" and tile.name ~= "lab-dark-1" and (position.x - tile_position.x) ^ 2 + (position.y - tile_position.y) ^ 2 < brushsize_square then
i = i + 1
copied_tiles[i] = {name = "lab-dark-1", position = tile.position}
tiles[i] = {name = tile.name, position = tile.position}
end
end
surface.set_tiles(tiles, true, false, false, false)
source_surface.set_tiles(copied_tiles, false, false, false, false)
for _, entity in pairs(source_surface.find_entities_filtered({area = {{position.x - brushsize, position.y - brushsize}, {position.x + brushsize, position.y + brushsize}}})) do
local entity_position = entity.position
if (position.x - entity_position.x) ^ 2 + (position.y - entity_position.y) ^ 2 < brushsize_square then
entity.clone({position = entity_position, surface = surface})
if entity.force.index == 2 then
table.insert(cave_miner.reveal_queue, {entity.type, entity.position.x, entity.position.y})
end
entity.destroy()
end
end
source_surface.set_tiles({{name = "lab-dark-2", position = position}}, false)
source_surface.request_to_generate_chunks(position, 3)
end
local biomes = {}
function biomes.oasis(surface, seed, position, square_distance, noise)