mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-03-17 20:58:13 +02:00
new module
This commit is contained in:
parent
0aa0253d50
commit
185b21c7a5
@ -1,6 +1,7 @@
|
||||
require "functions.noise_vector_path"
|
||||
require "functions.boss_unit"
|
||||
require "maps.island_troopers.terrain"
|
||||
require "modules.shopping_chests"
|
||||
|
||||
local function set_next_level()
|
||||
global.alive_enemies = 0
|
||||
|
@ -4,7 +4,16 @@ local math_random = math.random
|
||||
local function get_vector()
|
||||
if global.current_stage == 1 then return {0, -1} end
|
||||
if global.current_stage == #global.stages then return {0, 1} end
|
||||
return {1, 0}
|
||||
local position = global.path_tiles[#global.path_tiles].position
|
||||
local island_size = global.stages[global.current_stage].size
|
||||
local y_modifier = 0
|
||||
if math.abs(position.y) < 32 + island_size * 3 then
|
||||
y_modifier = math.random(50, 100) * -0.01
|
||||
else
|
||||
y_modifier = math.random(50, 100) * 0.01
|
||||
end
|
||||
game.print(y_modifier)
|
||||
return {1, y_modifier}
|
||||
end
|
||||
|
||||
local function add_enemies(surface, position)
|
||||
@ -54,6 +63,12 @@ function draw_path_to_next_stage()
|
||||
--game.print(get_vector()[1] .. " " .. get_vector()[2])
|
||||
global.path_tiles = noise_vector_tile_path(surface, "grass-1", position, get_vector(), global.stages[global.current_stage].path_length, math.random(2, 5), draw_path_tile_whitelist)
|
||||
|
||||
if global.current_stage ~= #global.stages and global.current_stage > 1 then
|
||||
if math_random(1, 3) == 1 then
|
||||
noise_vector_tile_path(surface, "grass-1", position, {0, 1}, global.stages[#global.stages].path_length, math.random(2, 5), draw_path_tile_whitelist)
|
||||
end
|
||||
end
|
||||
|
||||
--for _, t in pairs(global.path_tiles) do
|
||||
-- global.level_tiles[#global.level_tiles + 1] = t
|
||||
--end
|
||||
@ -89,7 +104,7 @@ local function create_particles(surface, position)
|
||||
local particle = particles[math_random(1, #particles)]
|
||||
local m = math_random(10, 30)
|
||||
local m2 = m * 0.005
|
||||
for i = 1, 25, 1 do
|
||||
for i = 1, 8, 1 do
|
||||
surface.create_entity({
|
||||
name = particle,
|
||||
position = position,
|
||||
@ -105,7 +120,7 @@ function kill_the_level()
|
||||
local surface = game.surfaces[1]
|
||||
if not global.level_tiles then get_level_tiles(surface) end
|
||||
|
||||
local amount = global.current_level
|
||||
local amount = global.current_level * 2
|
||||
for i = #global.level_tiles, 1, -1 do
|
||||
if global.level_tiles[i] then
|
||||
for k, tile in pairs(global.level_tiles[i]) do
|
||||
|
105
modules/shopping_chests.lua
Normal file
105
modules/shopping_chests.lua
Normal file
@ -0,0 +1,105 @@
|
||||
local shop_list = {
|
||||
["iron-ore"] = 1,
|
||||
["copper-ore"] = 1,
|
||||
["uranium-ore"] = 3,
|
||||
["coal"] = 1,
|
||||
["stone"] = 1,
|
||||
["wood"] = 0.75,
|
||||
["crude-oil-barrel"] = 6,
|
||||
["empty-barrel"] = 5,
|
||||
["landfill"] = 2.5,
|
||||
}
|
||||
|
||||
function create_shopping_chest(surface, position, destructible)
|
||||
global.shopping_chests[#global.shopping_chests + 1] = surface.create_entity({name = "logistic-chest-requester", position = position, force = "shopping_chests"})
|
||||
global.shopping_chests[#global.shopping_chests].minable = false
|
||||
if not destructible then global.shopping_chests[#global.shopping_chests].destructible = false end
|
||||
end
|
||||
|
||||
function create_dump_chest(surface, position, destructible)
|
||||
global.dump_chests[#global.dump_chests + 1] = surface.create_entity({name = "logistic-chest-passive-provider", position = position, force = "shopping_chests"})
|
||||
global.dump_chests[#global.dump_chests].minable = false
|
||||
if not destructible then global.dump_chests[#global.dump_chests].destructible = false end
|
||||
end
|
||||
|
||||
local function get_affordable_item_count(name, count)
|
||||
if global.credits >= count * shop_list[name] then
|
||||
return count
|
||||
end
|
||||
count = math.floor(global.credits / shop_list[name])
|
||||
return count
|
||||
end
|
||||
|
||||
local function process_shopping_chest(k, chest)
|
||||
if not chest.valid then global.shopping_chests[k] = nil return end
|
||||
if global.credits <= 0 then return end
|
||||
local requested_item_stack = chest.get_request_slot(1)
|
||||
if not requested_item_stack then return end
|
||||
if not shop_list[requested_item_stack.name] then
|
||||
chest.surface.create_entity({name = "flying-text", position = {chest.position.x - 2, chest.position.y}, text = requested_item_stack.name .. " is not for sale", color = {r = 200, g = 160, b = 30}})
|
||||
return
|
||||
end
|
||||
local inventory = chest.get_inventory(defines.inventory.chest)
|
||||
--if not inventory.can_insert(requested_item_stack) then return end
|
||||
local current_count = inventory.get_item_count(requested_item_stack.name)
|
||||
if current_count >= requested_item_stack.count then return end
|
||||
local count = requested_item_stack.count - current_count
|
||||
count = get_affordable_item_count(requested_item_stack.name, count)
|
||||
if count < 1 then return end
|
||||
local inserted_amount = inventory.insert({name = requested_item_stack.name, count = count})
|
||||
if inserted_amount == 0 then return end
|
||||
local spent_credits = inserted_amount * shop_list[requested_item_stack.name]
|
||||
global.credits = global.credits - spent_credits
|
||||
chest.surface.create_entity({name = "flying-text", position = chest.position, text = "-" .. spent_credits .. " ø", color = {r = 200, g = 160, b = 30}})
|
||||
end
|
||||
|
||||
local function process_dump_chest(k, chest)
|
||||
if not chest.valid then global.dump_chests[k] = nil return end
|
||||
local inventory = chest.get_inventory(defines.inventory.chest)
|
||||
if inventory.is_empty() then return end
|
||||
for k, price in pairs(shop_list) do
|
||||
local removed = inventory.remove(k)
|
||||
global.credits = global.credits + (removed * shop_list[k])
|
||||
end
|
||||
end
|
||||
|
||||
local function gui()
|
||||
for _, player in pairs(game.connected_players) do
|
||||
if player.gui.top.credits_button then player.gui.top.credits_button.destroy() end
|
||||
local element = player.gui.top.add({type = "frame", name = "credits_button", caption = global.credits .. " ø", tooltip = "Credits of the factory."})
|
||||
local style = element.style
|
||||
style.minimal_height = 38
|
||||
style.maximal_height = 38
|
||||
style.minimal_width = 140
|
||||
style.top_padding = 2
|
||||
style.left_padding = 4
|
||||
style.right_padding = 4
|
||||
style.bottom_padding = 2
|
||||
style.font_color = {r = 155, g = 85, b = 25}
|
||||
style.font = "default-large-bold"
|
||||
end
|
||||
end
|
||||
|
||||
local function tick()
|
||||
for k, chest in pairs(global.shopping_chests) do
|
||||
process_shopping_chest(k, chest)
|
||||
end
|
||||
for k, chest in pairs(global.dump_chests) do
|
||||
process_dump_chest(k, chest)
|
||||
end
|
||||
gui()
|
||||
global.credits = global.credits + math.random(1,5)
|
||||
end
|
||||
|
||||
local function on_init()
|
||||
global.shopping_chests = {}
|
||||
global.dump_chests = {}
|
||||
global.credits = 0
|
||||
game.create_force("shopping_chests")
|
||||
game.forces.player.set_friend("shopping_chests", true)
|
||||
game.forces.shopping_chests.set_friend("player", true)
|
||||
end
|
||||
|
||||
local event = require 'utils.event'
|
||||
event.on_nth_tick(120, tick)
|
||||
event.on_init(on_init)
|
Loading…
x
Reference in New Issue
Block a user