1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-02-03 13:12:11 +02:00
This commit is contained in:
MewMew 2020-10-27 01:28:24 +01:00
parent 2667562c1e
commit 8605e31a91
3 changed files with 45 additions and 15 deletions

View File

@ -4,6 +4,7 @@ local Constants = require 'maps.cave_miner_v2.constants'
local BiterRaffle = require "functions.biter_raffle"
local LootRaffle = require "functions.loot_raffle"
local Esq = require "modules.entity_spawn_queue"
local Pets = require "modules.biter_pets"
local math_sqrt = math.sqrt
local math_random = math.random
@ -115,7 +116,11 @@ end
function Public.loot_crate(surface, position, multiplier, slots, container_name)
local d = math_sqrt(position.x ^ 2 + position.y ^ 2)
local item_stacks = LootRaffle.roll(d * multiplier, slots, loot_blacklist)
local blacklist = LootRaffle.get_tech_blacklist(d * 0.0001 + 0.1)
blacklist["landfill"] = true
local item_stacks = LootRaffle.roll(d * multiplier, slots, blacklist)
local container = surface.create_entity({name = container_name, position = position, force = "neutral"})
for _, item_stack in pairs(item_stacks) do container.insert(item_stack) end
container.minable = false
@ -202,7 +207,7 @@ local function darkness_event(cave_miner, entity)
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)
Esq.add_to_queue(game.tick + math_random(5, 45) * c, entity.surface, {name = BiterRaffle.roll("mixed", d), position = position, force = "enemy"}, 8)
end
entity.damage(darkness[index] * 2, "neutral", "poison")
@ -211,7 +216,7 @@ end
function Public.darkness(cave_miner)
for _, player in pairs(game.connected_players) do
local character = player.character
if character and character.valid then
if character and character.valid and not character.driving then
character.disable_flashlight()
if is_entity_in_darkness(character) then
darkness_event(cave_miner, character)
@ -222,6 +227,20 @@ function Public.darkness(cave_miner)
end
end
Public.mining_events = {
{function(cave_miner, entity, player_index)
end, 100000, "Nothing"},
{function(cave_miner, entity, player_index)
Public.rock_spawns_biters(cave_miner, entity.position)
end, 6000, "Biters"},
{function(cave_miner, entity, player_index)
local position = entity.position
local surface = entity.surface
local unit = Public.spawn_random_biter(surface, position, 2)
Pets.biter_pets_tame_unit(game.players[player_index], unit, true)
end, 300, "Pet"},
}
Public.on_entity_died = {
["unit"] = function(cave_miner, entity)
local position = entity.position

View File

@ -7,7 +7,6 @@ local Global = require 'utils.global'
local Market = require 'maps.cave_miner_v2.market'
local Server = require 'utils.server'
local Terrain = require 'maps.cave_miner_v2.terrain'
local Pets = require "modules.biter_pets"
local Map_info = require "modules.map_info"
require "modules.satellite_score"
@ -75,18 +74,14 @@ local function on_player_mined_entity(event)
if not entity then return end
if not entity.valid then return end
local surface = entity.surface
local position = entity.position
local position = entity.position
if entity.type == "simple-entity" then
cave_miner.rocks_broken = cave_miner.rocks_broken + 1
if math.random(1, 16) == 1 then
Functions.rock_spawns_biters(cave_miner, position)
return
end
if math.random(1, 1024) == 1 then
local unit = Functions.spawn_random_biter(surface, position, 2)
Pets.biter_pets_tame_unit(game.players[event.player_index], unit, true)
return
end
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)
--print 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, 3)) end
end
end

View File

@ -99,6 +99,22 @@ local noises = {
{modifier = 0.05, weight = 0.5},
{modifier = 0.1, weight = 0.025}
},
['cave_miner_01'] = {
{modifier = 0.002, weight = 1},
{modifier = 0.003, weight = 0.5},
{modifier = 0.01, weight = 0.01},
{modifier = 0.1, weight = 0.015}
},
['cave_miner_02'] = {
{modifier = 0.006, weight = 1},
{modifier = 0.02, weight = 0.15},
{modifier = 0.25, weight = 0.025}
},
['cm_ocean'] = {
{modifier = 0.002, weight = 1},
{modifier = 0.004, weight = 1},
{modifier = 0.02, weight = 0.05},
},
}
--returns a float number between -1 and 1