mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-03-11 14:49:24 +02:00
Kraken fixes
Changes: - Fixed an issue where touching 2 krakens at the same time would spawn 3 krakens. - Fixed an issue where sometimes 2 krakens would be placed under same tile in overworld (which made it look as if there was only single kraken).
This commit is contained in:
parent
7802c49ad9
commit
cc5153946e
@ -569,7 +569,7 @@ function Public.krakens_per_free_slot(overworldx)
|
||||
if rng < 0.0025 * multiplier then
|
||||
return 3
|
||||
elseif rng < 0.075 * multiplier then
|
||||
return 1
|
||||
return 2
|
||||
elseif rng < 0.5 * multiplier then
|
||||
return 1
|
||||
else
|
||||
|
@ -100,7 +100,7 @@ function Public.random_float_in_range(from, to)
|
||||
end
|
||||
|
||||
-- Returns vector in random direction.
|
||||
-- scalar: sets returned vector length. If nil, 1 will be chosen
|
||||
-- scalar: returned vector length. If nil, 1 will be chosen.
|
||||
function Public.random_vec(scalar)
|
||||
scalar = scalar or 1
|
||||
local random_angle = Public.random_float_in_range(0, 2 * Public.pi)
|
||||
@ -110,6 +110,41 @@ function Public.random_vec(scalar)
|
||||
}
|
||||
end
|
||||
|
||||
-- Returns unique contiguous array indices.
|
||||
-- array_size: size of contiguous array.
|
||||
-- count: amount of unique indices to take from the array (elements are taken in range [1, array_size]).
|
||||
--
|
||||
-- Example with {array_size = 5, count = 3}:
|
||||
-- - Possible return value: {4, 1, 5}
|
||||
--
|
||||
-- Idea taken from this big brained stranger https://stackoverflow.com/a/2380705
|
||||
function Public.random_unique_array_indices(array_size, count)
|
||||
if count > array_size then
|
||||
return nil
|
||||
end
|
||||
|
||||
local modified_indices = {}
|
||||
local result_indices = {}
|
||||
for i = 0, count - 1 do
|
||||
local curr_array_size = array_size - i
|
||||
local num = Public.random(curr_array_size)
|
||||
|
||||
if modified_indices[num] == nil then
|
||||
result_indices[#result_indices + 1] = num
|
||||
else
|
||||
result_indices[#result_indices + 1] = modified_indices[num]
|
||||
end
|
||||
|
||||
if modified_indices[curr_array_size] == nil then
|
||||
modified_indices[num] = curr_array_size
|
||||
else
|
||||
modified_indices[num] = modified_indices[curr_array_size]
|
||||
end
|
||||
end
|
||||
|
||||
return result_indices
|
||||
end
|
||||
|
||||
function Public.snap_to_grid(point)
|
||||
return {x = Public.ceil(point.x), y = Public.ceil(point.x)}
|
||||
end
|
||||
|
@ -495,22 +495,15 @@ function Public.generate_overworld_destination(p)
|
||||
-- end
|
||||
|
||||
if position_candidates then
|
||||
local positions_placed = {}
|
||||
local whilesafety = 0
|
||||
while whilesafety < 10 and (#positions_placed < Math.min(kraken_count, 10)) do
|
||||
local p_chosen, p_kraken
|
||||
local whilesafety2 = 0
|
||||
while whilesafety2 < 50 and ((not p_kraken) or Utils.contains(positions_placed, p_chosen)) do
|
||||
p_chosen = position_candidates[Math.random(#position_candidates)]
|
||||
p_kraken = Utils.psum{p_chosen, p}
|
||||
whilesafety2 = whilesafety2 + 1
|
||||
local random_indices = Math.random_unique_array_indices(#position_candidates, Math.min(kraken_count, 10))
|
||||
if random_indices then
|
||||
for _, idx in ipairs(random_indices) do
|
||||
local p_chosen = position_candidates[idx]
|
||||
local p_kraken = Utils.psum{p_chosen, p}
|
||||
Crowsnest.draw_kraken(p_kraken)
|
||||
memory.overworld_krakens[#memory.overworld_krakens + 1] = p_kraken
|
||||
end
|
||||
Crowsnest.draw_kraken(p_kraken)
|
||||
positions_placed[#positions_placed + 1] = p_kraken
|
||||
memory.overworld_krakens[#memory.overworld_krakens + 1] = p_kraken
|
||||
whilesafety = whilesafety + 1
|
||||
end
|
||||
-- game.print(#positions_placed .. ' krakens placed for' .. macro_p.x .. ', ' .. macro_p.y)
|
||||
end
|
||||
end
|
||||
|
||||
@ -577,16 +570,15 @@ end
|
||||
|
||||
function Public.check_for_kraken_collisions()
|
||||
local memory = Memory.get_crew_memory()
|
||||
local krakens = memory.overworld_krakens
|
||||
|
||||
for i, k in ipairs(krakens) do
|
||||
|
||||
for i = #memory.overworld_krakens, 1, -1 do
|
||||
local k = memory.overworld_krakens[i]
|
||||
local relativex = Crowsnest.platformrightmostedge + k.x - memory.overworldx
|
||||
local relativey = k.y - memory.overworldy
|
||||
|
||||
if (relativex <= 3.5 and relativex >= -3.5 and relativey >= -4 and relativey <= 4) then
|
||||
Kraken.try_spawn_kraken()
|
||||
memory.overworld_krakens = Utils.ordered_table_with_index_removed(krakens, i)
|
||||
memory.overworld_krakens = Utils.ordered_table_with_index_removed(memory.overworld_krakens, i)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user