mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-04-13 11:30:40 +02:00
new module
This commit is contained in:
parent
c29ff02861
commit
96d554b0af
@ -135,6 +135,7 @@ require 'modules.autostash'
|
||||
--![[You fell in a dark cave, will you survive?]]--
|
||||
--require 'maps.cave_miner'
|
||||
--require 'maps.cave_choppy.cave_miner'
|
||||
--require 'maps.cave_miner_v2.main'
|
||||
|
||||
--![[Hungry boxes eat your items, but reward you with new territory to build.]]--
|
||||
--require 'maps.expanse.main'
|
||||
@ -201,7 +202,6 @@ require 'modules.autostash'
|
||||
--require 'maps.pitch_black.main'
|
||||
--require 'maps.cube'
|
||||
--require 'maps.mountain_race.main'
|
||||
--require 'maps.cave_miner_v2.main'
|
||||
--require 'maps.native_war.main'
|
||||
---------------------------------------------------------------
|
||||
|
||||
|
@ -3,6 +3,7 @@ local Public = {}
|
||||
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 math_sqrt = math.sqrt
|
||||
local math_random = math.random
|
||||
@ -41,7 +42,7 @@ function Public.spawn_player(player)
|
||||
end
|
||||
|
||||
function Public.set_mining_speed(cave_miner, force)
|
||||
force.manual_mining_speed_modifier = -0.50 + cave_miner.pickaxe_tier * 0.35
|
||||
force.manual_mining_speed_modifier = -0.50 + cave_miner.pickaxe_tier * 0.40
|
||||
return force.manual_mining_speed_modifier
|
||||
end
|
||||
|
||||
@ -66,6 +67,17 @@ function Public.spawn_random_biter(surface, position, multiplier)
|
||||
return unit
|
||||
end
|
||||
|
||||
function Public.rock_spawns_biters(cave_miner, position)
|
||||
local amount = Public.roll_biter_amount()
|
||||
local surface = game.surfaces.nauvis
|
||||
local d = math_sqrt(position.x ^ 2 + position.y ^ 2) * 0.0001
|
||||
local tick = game.tick
|
||||
for _ = 1, amount, 1 do
|
||||
tick = tick + math_random(30, 120)
|
||||
Esq.add_to_queue(tick, surface, {name = BiterRaffle.roll("mixed", d), position = position, force = "enemy"}, 8)
|
||||
end
|
||||
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)
|
||||
|
@ -76,11 +76,8 @@ local function on_player_mined_entity(event)
|
||||
local position = entity.position
|
||||
if entity.type == "simple-entity" then
|
||||
cave_miner.rocks_broken = cave_miner.rocks_broken + 1
|
||||
if math.random(1, 12) == 1 then
|
||||
local amount = Functions.roll_biter_amount()
|
||||
for _ = 1, amount, 1 do
|
||||
Functions.spawn_random_biter(surface, position, 1)
|
||||
end
|
||||
if math.random(1, 16) == 1 then
|
||||
Functions.rock_spawns_biters(cave_miner, position)
|
||||
return
|
||||
end
|
||||
if math.random(1, 1024) == 1 then
|
||||
@ -99,8 +96,8 @@ local function on_entity_died(event)
|
||||
local position = entity.position
|
||||
if entity.type == "simple-entity" then
|
||||
cave_miner.rocks_broken = cave_miner.rocks_broken + 1
|
||||
if math.random(1, 2) == 1 then
|
||||
Functions.spawn_random_biter(surface, position, 1)
|
||||
if math.random(1, 4) == 1 then
|
||||
Functions.rock_spawns_biters(cave_miner, position)
|
||||
end
|
||||
return
|
||||
end
|
||||
@ -146,6 +143,8 @@ local function init(cave_miner)
|
||||
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
|
||||
|
||||
cave_miner.gamestate = "spawn_players"
|
||||
end
|
||||
@ -163,6 +162,7 @@ end
|
||||
|
||||
local function game_in_progress(cave_miner)
|
||||
local tick = game.ticks_played
|
||||
|
||||
if tick % 60 ~= 0 then return end
|
||||
Functions.update_top_gui(cave_miner)
|
||||
|
||||
|
64
modules/entity_spawn_queue.lua
Normal file
64
modules/entity_spawn_queue.lua
Normal file
@ -0,0 +1,64 @@
|
||||
-- Queue entities to spawn at certain ticks -- mewmew
|
||||
-- Add entities via .add_to_queue(tick, surface, entity_data, non_colliding_position_search_radius)
|
||||
-- Example Esq.add_to_queue(3486, game.surfaces.nauvis, {name = "small-biter", position = {16, 17}, force = "player"}, false)
|
||||
|
||||
local Event = require 'utils.event'
|
||||
local Global = require 'utils.global'
|
||||
|
||||
local table_insert = table.insert
|
||||
|
||||
local Public = {}
|
||||
|
||||
local ESQ = {}
|
||||
Global.register(
|
||||
ESQ,
|
||||
function(tbl)
|
||||
ESQ = tbl
|
||||
end
|
||||
)
|
||||
|
||||
local function spawn_entity(surface_index, entity_data, non_colliding_position_search_radius)
|
||||
local surface = game.surfaces[surface_index]
|
||||
if not surface then return end
|
||||
if not surface.valid then return end
|
||||
if non_colliding_position_search_radius then
|
||||
local p = surface.find_non_colliding_position(entity_data.name, entity_data.position, non_colliding_position_search_radius, 0.5)
|
||||
if p then entity_data.position = p end
|
||||
end
|
||||
surface.create_entity(entity_data)
|
||||
end
|
||||
|
||||
function Public.add_to_queue(tick, surface, entity_data, non_colliding_position_search_radius)
|
||||
if not surface then return end
|
||||
if not surface.valid then return end
|
||||
if not entity_data then return end
|
||||
if not entity_data.position then return end
|
||||
if not entity_data.name then return end
|
||||
if not tick then return end
|
||||
|
||||
local queue = ESQ.queue
|
||||
local entity = {}
|
||||
|
||||
for k, v in pairs(entity_data) do entity[k] = v end
|
||||
|
||||
tick = tostring(tick)
|
||||
if not queue[tick] then queue[tick] = {} end
|
||||
table_insert(queue[tick], {surface.index, entity, non_colliding_position_search_radius})
|
||||
end
|
||||
|
||||
local function on_tick()
|
||||
local tick = tostring(game.tick)
|
||||
if not ESQ.queue[tick] then return end
|
||||
for _, v in pairs(ESQ.queue[tick]) do spawn_entity(v[1], v[2], v[3]) end
|
||||
ESQ.queue[tick] = nil
|
||||
end
|
||||
|
||||
local function on_init()
|
||||
ESQ.queue = {}
|
||||
end
|
||||
|
||||
Event.on_init(on_init)
|
||||
Event.add(defines.events.on_tick, on_tick)
|
||||
|
||||
return Public
|
||||
|
@ -72,6 +72,11 @@ local noises = {
|
||||
{modifier = 0.01, weight = 0.35},
|
||||
{modifier = 0.05, weight = 0.23},
|
||||
{modifier = 0.1, weight = 0.11}
|
||||
},
|
||||
['big_cave'] = {
|
||||
{modifier = 0.003, weight = 1},
|
||||
{modifier = 0.02, weight = 0.05},
|
||||
{modifier = 0.15, weight = 0.02}
|
||||
},
|
||||
['small_caves'] = {
|
||||
{modifier = 0.008, weight = 1},
|
||||
@ -93,7 +98,7 @@ local noises = {
|
||||
{modifier = 0.01, weight = 1},
|
||||
{modifier = 0.05, weight = 0.5},
|
||||
{modifier = 0.1, weight = 0.025}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
--returns a float number between -1 and 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user