1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-01-18 03:21:47 +02:00

Merge pull request #242 from iltar/stone-void-chest

Added stone void chest that sends stone to surface
This commit is contained in:
Valansch 2018-10-19 15:01:42 +02:00 committed by GitHub
commit 0d1d98f438
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 211 additions and 38 deletions

View File

@ -173,14 +173,24 @@ local Config = {
stone_to_surface_amount = 50, stone_to_surface_amount = 50,
currency_item = 'stone', currency_item = 'stone',
-- locations where chests will be automatically cleared from currency_item
void_chest_tiles = {
{x = -1, y = 5}, {x = 0, y = 5}, {x = 1, y = 5},
},
-- every x ticks it will clear y currency_item
void_chest_frequency = 307,
unlockables = { unlockables = {
{stone = 50, type = 'buff', prototype = {name = 'mining_speed', value = 10}}, {stone = 50, type = 'buff', prototype = {name = 'mining_speed', value = 10}},
{stone = 50, type = 'buff', prototype = {name = 'inventory_slot', value = 3}}, {stone = 50, type = 'buff', prototype = {name = 'inventory_slot', value = 3}},
{stone = 50, type = 'market', prototype = {price = 50, name = 'raw-fish'}}, {stone = 50, type = 'market', prototype = {price = 50, name = 'raw-fish'}},
{stone = 50, type = 'market', prototype = {price = 175, name = 'steel-axe'}}, {stone = 50, type = 'market', prototype = {price = 175, name = 'steel-axe'}},
{stone = 50, type = 'buff', prototype = {name = 'stone_automation', value = 10}},
{stone = 250, type = 'buff', prototype = {name = 'mining_speed', value = 5}}, {stone = 250, type = 'buff', prototype = {name = 'mining_speed', value = 5}},
{stone = 250, type = 'buff', prototype = {name = 'inventory_slot', value = 2}}, {stone = 250, type = 'buff', prototype = {name = 'inventory_slot', value = 2}},
{stone = 250, type = 'buff', prototype = {name = 'stone_automation', value = 5}},
{stone = 250, type = 'market', prototype = {price = 50, name = 'small-electric-pole'}}, {stone = 250, type = 'market', prototype = {price = 50, name = 'small-electric-pole'}},
{stone = 250, type = 'market', prototype = {price = 50, name = 'small-lamp'}}, {stone = 250, type = 'market', prototype = {price = 50, name = 'small-lamp'}},
{stone = 250, type = 'market', prototype = {price = 25, name = 'stone-brick'}}, {stone = 250, type = 'market', prototype = {price = 25, name = 'stone-brick'}},
@ -188,99 +198,148 @@ local Config = {
{stone = 450, type = 'buff', prototype = {name = 'mining_speed', value = 5}}, {stone = 450, type = 'buff', prototype = {name = 'mining_speed', value = 5}},
{stone = 450, type = 'buff', prototype = {name = 'inventory_slot', value = 2}}, {stone = 450, type = 'buff', prototype = {name = 'inventory_slot', value = 2}},
{stone = 450, type = 'buff', prototype = {name = 'stone_automation', value = 5}},
{stone = 450, type = 'market', prototype = {price = 850, name = 'submachine-gun'}}, {stone = 450, type = 'market', prototype = {price = 850, name = 'submachine-gun'}},
{stone = 450, type = 'market', prototype = {price = 50, name = 'firearm-magazine'}}, {stone = 450, type = 'market', prototype = {price = 50, name = 'firearm-magazine'}},
{stone = 450, type = 'market', prototype = {price = 500, name = 'light-armor'}}, {stone = 450, type = 'market', prototype = {price = 500, name = 'light-armor'}},
{stone = 750, type = 'buff', prototype = {name = 'mining_speed', value = 5}}, {stone = 750, type = 'buff', prototype = {name = 'mining_speed', value = 5}},
{stone = 750, type = 'buff', prototype = {name = 'inventory_slot', value = 1}}, {stone = 750, type = 'buff', prototype = {name = 'inventory_slot', value = 1}},
{stone = 750, type = 'buff', prototype = {name = 'stone_automation', value = 5}},
{stone = 1250, type = 'buff', prototype = {name = 'mining_speed', value = 5}}, {stone = 1250, type = 'buff', prototype = {name = 'mining_speed', value = 5}},
{stone = 1250, type = 'buff', prototype = {name = 'inventory_slot', value = 1}}, {stone = 1250, type = 'buff', prototype = {name = 'inventory_slot', value = 1}},
{stone = 1250, type = 'buff', prototype = {name = 'stone_automation', value = 2}},
{stone = 1750, type = 'buff', prototype = {name = 'mining_speed', value = 5}}, {stone = 1750, type = 'buff', prototype = {name = 'mining_speed', value = 5}},
{stone = 1750, type = 'buff', prototype = {name = 'inventory_slot', value = 1}}, {stone = 1750, type = 'buff', prototype = {name = 'inventory_slot', value = 1}},
{stone = 1750, type = 'buff', prototype = {name = 'stone_automation', value = 2}},
{stone = 2500, type = 'buff', prototype = {name = 'mining_speed', value = 5}}, {stone = 2500, type = 'buff', prototype = {name = 'mining_speed', value = 5}},
{stone = 2500, type = 'buff', prototype = {name = 'inventory_slot', value = 1}}, {stone = 2500, type = 'buff', prototype = {name = 'inventory_slot', value = 1}},
{stone = 2500, type = 'buff', prototype = {name = 'stone_automation', value = 2}},
{stone = 4000, type = 'buff', prototype = {name = 'mining_speed', value = 5}}, {stone = 4000, type = 'buff', prototype = {name = 'mining_speed', value = 5}},
{stone = 4000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}}, {stone = 4000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}},
{stone = 4000, type = 'buff', prototype = {name = 'stone_automation', value = 2}},
{stone = 6500, type = 'buff', prototype = {name = 'mining_speed', value = 5}}, {stone = 6500, type = 'buff', prototype = {name = 'mining_speed', value = 5}},
{stone = 6500, type = 'buff', prototype = {name = 'inventory_slot', value = 1}}, {stone = 6500, type = 'buff', prototype = {name = 'inventory_slot', value = 1}},
{stone = 6500, type = 'buff', prototype = {name = 'stone_automation', value = 2}},
{stone = 8000, type = 'buff', prototype = {name = 'mining_speed', value = 5}}, {stone = 8000, type = 'buff', prototype = {name = 'mining_speed', value = 5}},
{stone = 8000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}}, {stone = 8000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}},
{stone = 8000, type = 'buff', prototype = {name = 'stone_automation', value = 2}},
{stone = 10000, type = 'buff', prototype = {name = 'mining_speed', value = 5}}, {stone = 10000, type = 'buff', prototype = {name = 'mining_speed', value = 5}},
{stone = 10000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}}, {stone = 10000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}},
{stone = 10000, type = 'buff', prototype = {name = 'stone_automation', value = 2}},
{stone = 10000, type = 'market', prototype = {price = 750, name = 'heavy-armor'}}, {stone = 10000, type = 'market', prototype = {price = 750, name = 'heavy-armor'}},
{stone = 15000, type = 'buff', prototype = {name = 'mining_speed', value = 2}}, {stone = 15000, type = 'buff', prototype = {name = 'mining_speed', value = 2}},
{stone = 15000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}}, {stone = 15000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}},
{stone = 25000, type = 'buff', prototype = {name = 'mining_speed', value = 2}}, {stone = 25000, type = 'buff', prototype = {name = 'mining_speed', value = 2}},
{stone = 25000, type = 'buff', prototype = {name = 'stone_automation', value = 2}},
{stone = 25000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}}, {stone = 25000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}},
{stone = 35000, type = 'buff', prototype = {name = 'mining_speed', value = 2}}, {stone = 35000, type = 'buff', prototype = {name = 'mining_speed', value = 2}},
{stone = 35000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}}, {stone = 35000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}},
{stone = 35000, type = 'buff', prototype = {name = 'stone_automation', value = 2}},
{stone = 35000, type = 'market', prototype = {price = 100, name = 'piercing-rounds-magazine'}}, {stone = 35000, type = 'market', prototype = {price = 100, name = 'piercing-rounds-magazine'}},
{stone = 35000, type = 'market', prototype = {price = 1500, name = 'modular-armor'}}, {stone = 35000, type = 'market', prototype = {price = 1500, name = 'modular-armor'}},
{stone = 50000, type = 'buff', prototype = {name = 'mining_speed', value = 2}}, {stone = 50000, type = 'buff', prototype = {name = 'mining_speed', value = 2}},
{stone = 50000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}}, {stone = 50000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}},
{stone = 50000, type = 'buff', prototype = {name = 'stone_automation', value = 2}},
{stone = 75000, type = 'buff', prototype = {name = 'mining_speed', value = 2}}, {stone = 75000, type = 'buff', prototype = {name = 'mining_speed', value = 2}},
{stone = 75000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}}, {stone = 75000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}},
{stone = 75000, type = 'buff', prototype = {name = 'stone_automation', value = 2}},
{stone = 100000, type = 'buff', prototype = {name = 'mining_speed', value = 2}}, {stone = 100000, type = 'buff', prototype = {name = 'mining_speed', value = 2}},
{stone = 100000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}}, {stone = 100000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}},
{stone = 100000, type = 'buff', prototype = {name = 'stone_automation', value = 2}},
{stone = 125000, type = 'buff', prototype = {name = 'mining_speed', value = 2}}, {stone = 125000, type = 'buff', prototype = {name = 'mining_speed', value = 2}},
{stone = 125000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}}, {stone = 125000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}},
{stone = 125000, type = 'buff', prototype = {name = 'stone_automation', value = 2}},
{stone = 150000, type = 'buff', prototype = {name = 'mining_speed', value = 2}}, {stone = 150000, type = 'buff', prototype = {name = 'mining_speed', value = 2}},
{stone = 150000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}}, {stone = 150000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}},
{stone = 150000, type = 'buff', prototype = {name = 'stone_automation', value = 2}},
{stone = 175000, type = 'buff', prototype = {name = 'mining_speed', value = 2}}, {stone = 175000, type = 'buff', prototype = {name = 'mining_speed', value = 2}},
{stone = 175000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}}, {stone = 175000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}},
{stone = 175000, type = 'buff', prototype = {name = 'stone_automation', value = 2}},
{stone = 200000, type = 'buff', prototype = {name = 'mining_speed', value = 2}}, {stone = 200000, type = 'buff', prototype = {name = 'mining_speed', value = 2}},
{stone = 200000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}}, {stone = 200000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}},
{stone = 200000, type = 'buff', prototype = {name = 'stone_automation', value = 2}},
{stone = 225000, type = 'buff', prototype = {name = 'mining_speed', value = 2}}, {stone = 225000, type = 'buff', prototype = {name = 'mining_speed', value = 2}},
{stone = 225000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}}, {stone = 225000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}},
{stone = 225000, type = 'buff', prototype = {name = 'stone_automation', value = 2}},
{stone = 250000, type = 'buff', prototype = {name = 'mining_speed', value = 2}}, {stone = 250000, type = 'buff', prototype = {name = 'mining_speed', value = 2}},
{stone = 250000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}}, {stone = 250000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}},
{stone = 250000, type = 'buff', prototype = {name = 'stone_automation', value = 2}},
{stone = 275000, type = 'buff', prototype = {name = 'mining_speed', value = 2}}, {stone = 275000, type = 'buff', prototype = {name = 'mining_speed', value = 2}},
{stone = 275000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}}, {stone = 275000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}},
{stone = 275000, type = 'buff', prototype = {name = 'stone_automation', value = 2}},
{stone = 300000, type = 'buff', prototype = {name = 'mining_speed', value = 2}}, {stone = 300000, type = 'buff', prototype = {name = 'mining_speed', value = 2}},
{stone = 300000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}}, {stone = 300000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}},
{stone = 300000, type = 'buff', prototype = {name = 'stone_automation', value = 2}},
{stone = 350000, type = 'buff', prototype = {name = 'mining_speed', value = 2}}, {stone = 350000, type = 'buff', prototype = {name = 'mining_speed', value = 2}},
{stone = 350000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}}, {stone = 350000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}},
{stone = 2500, type = 'buff', prototype = {name = 'stone_automation', value = 2}},
{stone = 400000, type = 'buff', prototype = {name = 'mining_speed', value = 2}}, {stone = 400000, type = 'buff', prototype = {name = 'mining_speed', value = 2}},
{stone = 400000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}}, {stone = 400000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}},
{stone = 400000, type = 'buff', prototype = {name = 'stone_automation', value = 2}},
{stone = 500000, type = 'buff', prototype = {name = 'mining_speed', value = 2}}, {stone = 500000, type = 'buff', prototype = {name = 'mining_speed', value = 2}},
{stone = 500000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}}, {stone = 500000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}},
{stone = 500000, type = 'buff', prototype = {name = 'stone_automation', value = 2}},
{stone = 600000, type = 'buff', prototype = {name = 'mining_speed', value = 2}}, {stone = 600000, type = 'buff', prototype = {name = 'mining_speed', value = 2}},
{stone = 600000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}}, {stone = 600000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}},
{stone = 600000, type = 'buff', prototype = {name = 'stone_automation', value = 2}},
{stone = 700000, type = 'buff', prototype = {name = 'mining_speed', value = 2}}, {stone = 700000, type = 'buff', prototype = {name = 'mining_speed', value = 2}},
{stone = 700000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}}, {stone = 700000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}},
{stone = 700000, type = 'buff', prototype = {name = 'stone_automation', value = 2}},
{stone = 800000, type = 'buff', prototype = {name = 'mining_speed', value = 2}}, {stone = 800000, type = 'buff', prototype = {name = 'mining_speed', value = 2}},
{stone = 800000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}}, {stone = 800000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}},
{stone = 800000, type = 'buff', prototype = {name = 'stone_automation', value = 2}},
{stone = 800000, type = 'market', prototype = {price = 250, name = 'uranium-rounds-magazine'}}, {stone = 800000, type = 'market', prototype = {price = 250, name = 'uranium-rounds-magazine'}},
{stone = 900000, type = 'buff', prototype = {name = 'mining_speed', value = 2}}, {stone = 900000, type = 'buff', prototype = {name = 'mining_speed', value = 2}},
{stone = 900000, type = 'buff', prototype = {name = 'stone_automation', value = 2}},
{stone = 1000000, type = 'buff', prototype = {name = 'mining_speed', value = 2}}, {stone = 1000000, type = 'buff', prototype = {name = 'mining_speed', value = 2}},
{stone = 1000000, type = 'buff', prototype = {name = 'stone_automation', value = 2}},
{stone = 1250000, type = 'buff', prototype = {name = 'mining_speed', value = 2}}, {stone = 1250000, type = 'buff', prototype = {name = 'mining_speed', value = 2}},
{stone = 1250000, type = 'buff', prototype = {name = 'stone_automation', value = 2}},
{stone = 1500000, type = 'buff', prototype = {name = 'mining_speed', value = 2}}, {stone = 1500000, type = 'buff', prototype = {name = 'mining_speed', value = 2}},
{stone = 1500000, type = 'buff', prototype = {name = 'stone_automation', value = 2}},
{stone = 1750000, type = 'buff', prototype = {name = 'mining_speed', value = 2}}, {stone = 1750000, type = 'buff', prototype = {name = 'mining_speed', value = 2}},
{stone = 1750000, type = 'buff', prototype = {name = 'stone_automation', value = 2}},
{stone = 2000000, type = 'buff', prototype = {name = 'mining_speed', value = 2}}, {stone = 2000000, type = 'buff', prototype = {name = 'mining_speed', value = 2}},
{stone = 2000000, type = 'buff', prototype = {name = 'stone_automation', value = 2}},
{stone = 2500000, type = 'buff', prototype = {name = 'mining_speed', value = 2}}, {stone = 2500000, type = 'buff', prototype = {name = 'mining_speed', value = 2}},
{stone = 2500000, type = 'buff', prototype = {name = 'stone_automation', value = 2}},
{stone = 3000000, type = 'buff', prototype = {name = 'mining_speed', value = 2}}, {stone = 3000000, type = 'buff', prototype = {name = 'mining_speed', value = 2}},
{stone = 3000000, type = 'buff', prototype = {name = 'stone_automation', value = 2}},
}, },
}, },
}, },

View File

@ -78,9 +78,9 @@ end
@param position Position {x, y} @param position Position {x, y}
]] ]]
function Debug.print_grid_value(value, surface, position, scale, offset) function Debug.print_grid_value(value, surface, position, scale, offset)
local scale = scale or 1 scale = scale or 1
local offset = offset or 0 offset = offset or 0
local position = {x = position.x + offset, y = position.y + offset} position = {x = position.x + offset, y = position.y + offset}
local r = max(1, value) / scale local r = max(1, value) / scale
local g = 1 - abs(value) / scale local g = 1 - abs(value) / scale
local b = min(1, value) / scale local b = min(1, value) / scale

View File

@ -10,6 +10,7 @@ local Gui = require 'utils.gui'
local Debug = require 'map_gen.Diggy.Debug' local Debug = require 'map_gen.Diggy.Debug'
local Template = require 'map_gen.Diggy.Template' local Template = require 'map_gen.Diggy.Template'
local Global = require 'utils.global' local Global = require 'utils.global'
local insert = table.insert
-- this -- this
local MarketExchange = {} local MarketExchange = {}
@ -17,15 +18,23 @@ local MarketExchange = {}
local config = {} local config = {}
local stone_tracker = { local stone_tracker = {
first_time_market_item = nil,
stone_sent_to_surface = 0, stone_sent_to_surface = 0,
previous_stone_sent_to_surface = 0, previous_stone_sent_to_surface = 0,
} }
local stone_collecting = {
initial_value = 0,
active_modifier = 0,
research_modifier = 0,
market_modifier = 0,
}
local mining_efficiency = { local mining_efficiency = {
active_modifier = 0, active_modifier = 0,
research_modifier = 0, research_modifier = 0,
market_modifier = 0, market_modifier = 0,
} }
local inventory_slots = { local inventory_slots = {
active_modifier = 0, active_modifier = 0,
research_modifier = 0, research_modifier = 0,
@ -33,17 +42,31 @@ local inventory_slots = {
} }
Global.register({ Global.register({
stone_collecting = stone_collecting,
stone_tracker = stone_tracker, stone_tracker = stone_tracker,
mining_efficiency = mining_efficiency, mining_efficiency = mining_efficiency,
inventory_slots = inventory_slots, inventory_slots = inventory_slots,
}, function(tbl) }, function(tbl)
stone_collecting = tbl.stone_collecting
stone_tracker = tbl.stone_tracker stone_tracker = tbl.stone_tracker
mining_efficiency = tbl.mining_efficiency mining_efficiency = tbl.mining_efficiency
inventory_slots = tbl.inventory_slots inventory_slots = tbl.inventory_slots
end) end)
local function send_stone_to_surface(total)
stone_tracker.previous_stone_sent_to_surface = stone_tracker.stone_sent_to_surface
stone_tracker.stone_sent_to_surface = stone_tracker.stone_sent_to_surface + total
end
local on_market_timeout_finished = Token.register(function(params) local on_market_timeout_finished = Token.register(function(params)
Template.market(params.surface, params.position, params.player_force, params.currency_item, {}) Template.market(params.surface, params.position, params.player_force, params.currency_item, {})
local tiles = {}
for _, position in pairs(params.void_chest_tiles) do
insert(tiles, {name = 'tutorial-grid', position = position})
end
params.surface.set_tiles(tiles)
end) end)
local function update_mining_speed(force) local function update_mining_speed(force)
@ -68,37 +91,58 @@ local function update_inventory_slots(force)
force.character_inventory_slots_bonus = old_modifier + inventory_slots.active_modifier force.character_inventory_slots_bonus = old_modifier + inventory_slots.active_modifier
end end
local function update_stone_collecting()
-- remove the current buff
local old_modifier = stone_collecting.initial_value - stone_collecting.active_modifier
-- update the active modifier
stone_collecting.active_modifier = stone_collecting.research_modifier + stone_collecting.market_modifier
-- add the new active modifier to the non-buffed modifier
stone_collecting.initial_value = old_modifier + stone_collecting.active_modifier
end
local function update_market_contents(market) local function update_market_contents(market)
if (stone_tracker.previous_stone_sent_to_surface == stone_tracker.stone_sent_to_surface) then
return
end
local should_update_mining_speed = false local should_update_mining_speed = false
local should_update_inventory_slots = false local should_update_inventory_slots = false
local should_update_stone_collecting = false
if (nil ~= stone_tracker.first_time_market_item) then local add_market_item
market.add_market_item(stone_tracker.first_time_market_item) local print = game.print
stone_tracker.first_time_market_item = nil
end
for _, unlockable in pairs(config.unlockables) do for _, unlockable in pairs(config.unlockables) do
local is_in_range = unlockable.stone > stone_tracker.previous_stone_sent_to_surface and unlockable.stone <= stone_tracker.stone_sent_to_surface local is_in_range = unlockable.stone > stone_tracker.previous_stone_sent_to_surface and unlockable.stone <= stone_tracker.stone_sent_to_surface
-- only add the item to the market if it's between the old and new stone range -- only add the item to the market if it's between the old and new stone range
if (is_in_range and unlockable.type == 'market') then if (is_in_range and unlockable.type == 'market') then
add_market_item = add_market_item or market.add_market_item
local name = unlockable.prototype.name local name = unlockable.prototype.name
local price = unlockable.prototype.price local price = unlockable.prototype.price
game.print('Mining Foreman: New wares at the market! Come get your ' .. name .. ' for only ' .. price .. ' ' .. config.currency_item .. '!') print('Mining Foreman: New wares at the market! Come get your ' .. name .. ' for only ' .. price .. ' ' .. config.currency_item .. '!')
market.add_market_item({
add_market_item({
price = {{config.currency_item, price}}, price = {{config.currency_item, price}},
offer = {type = 'give-item', item = name, count = 1} offer = {type = 'give-item', item = name, count = 1}
}) })
elseif (is_in_range and unlockable.type == 'buff' and unlockable.prototype.name == 'mining_speed') then elseif (is_in_range and unlockable.type == 'buff' and unlockable.prototype.name == 'mining_speed') then
local value = unlockable.prototype.value local value = unlockable.prototype.value
game.print('Mining Foreman: Increased mining speed by ' .. value .. '%!') print('Mining Foreman: Increased mining speed by ' .. value .. '%!')
should_update_mining_speed = true should_update_mining_speed = true
mining_efficiency.market_modifier = mining_efficiency.market_modifier + (value / 100) mining_efficiency.market_modifier = mining_efficiency.market_modifier + (value / 100)
elseif (is_in_range and unlockable.type == 'buff' and unlockable.prototype.name == 'inventory_slot') then elseif (is_in_range and unlockable.type == 'buff' and unlockable.prototype.name == 'inventory_slot') then
local value = unlockable.prototype.value local value = unlockable.prototype.value
game.print('Mining Foreman: Increased inventory slots by ' .. value .. '!') print('Mining Foreman: Increased inventory slots by ' .. value .. '!')
should_update_inventory_slots = true should_update_inventory_slots = true
inventory_slots.market_modifier = inventory_slots.market_modifier + value inventory_slots.market_modifier = inventory_slots.market_modifier + value
elseif (is_in_range and unlockable.type == 'buff' and unlockable.prototype.name == 'stone_automation') then
local value = unlockable.prototype.value
print('Mining Foreman: sending stone to the surface automatically is now increased by ' .. value .. '!')
should_update_stone_collecting = true
stone_collecting.market_modifier = stone_collecting.market_modifier + value
end end
end end
@ -113,6 +157,10 @@ local function update_market_contents(market)
force = force or game.forces.player force = force or game.forces.player
update_inventory_slots(force) update_inventory_slots(force)
end end
if (should_update_stone_collecting) then
update_stone_collecting()
end
end end
local function on_research_finished(event) local function on_research_finished(event)
@ -126,20 +174,24 @@ local function on_research_finished(event)
end end
mining_efficiency.research_modifier = new_modifier mining_efficiency.research_modifier = new_modifier
inventory_slots.research_modifier = (force.mining_drill_productivity_bonus / 2) * 100 inventory_slots.research_modifier = force.mining_drill_productivity_bonus * 50 -- 1 per level
stone_collecting.research_modifier = force.mining_drill_productivity_bonus * 1250 -- 25 per level
update_inventory_slots(force) update_inventory_slots(force)
update_mining_speed(force) update_mining_speed(force)
update_stone_collecting()
end end
local function redraw_title(data) local function redraw_title(data)
data.frame.caption = stone_tracker.stone_sent_to_surface .. ' stone sent to the surface' data.frame.caption = stone_tracker.stone_sent_to_surface .. ' ' .. config.currency_item .. ' sent to the surface'
end end
local function redraw_list(data) local function redraw_list(data)
local market_scroll_pane = data.market_scroll_pane local market_scroll_pane = data.market_scroll_pane
Gui.clear(market_scroll_pane) Gui.clear(market_scroll_pane)
local add = market_scroll_pane.add
for _, unlockable in pairs(config.unlockables) do for _, unlockable in pairs(config.unlockables) do
local is_unlocked = unlockable.stone <= stone_tracker.stone_sent_to_surface local is_unlocked = unlockable.stone <= stone_tracker.stone_sent_to_surface
local message local message
@ -150,13 +202,15 @@ local function redraw_list(data)
message = 'Manual mining speed: +' .. unlockable.prototype.value .. '%' message = 'Manual mining speed: +' .. unlockable.prototype.value .. '%'
elseif (unlockable.type == 'buff' and unlockable.prototype.name == 'inventory_slot') then elseif (unlockable.type == 'buff' and unlockable.prototype.name == 'inventory_slot') then
message = 'Inventory slot: +' .. unlockable.prototype.value message = 'Inventory slot: +' .. unlockable.prototype.value
elseif (unlockable.type == 'buff' and unlockable.prototype.name == 'stone_automation') then
message = 'Automate stone to surface: +' .. unlockable.prototype.value
else else
Debug.print('failed getting a message for: ' .. serpent.line(unlockable)) Debug.print('failed getting a message for: ' .. serpent.line(unlockable))
end end
message = unlockable.stone .. ' stone: ' .. message message = unlockable.stone .. ' stone: ' .. message
local label = market_scroll_pane.add({type = 'label', caption = message}) local label = add({type = 'label', caption = message})
if (is_unlocked) then if (is_unlocked) then
label.style.font_color = {r = 1, g = 1, b = 1} label.style.font_color = {r = 1, g = 1, b = 1}
else else
@ -170,26 +224,22 @@ local function on_market_item_purchased(event)
return return
end end
stone_tracker.previous_stone_sent_to_surface = stone_tracker.stone_sent_to_surface send_stone_to_surface(config.stone_to_surface_amount * event.count)
stone_tracker.stone_sent_to_surface = stone_tracker.stone_sent_to_surface + (config.stone_to_surface_amount * event.count)
update_market_contents(event.market) update_market_contents(event.market)
local frame = game.players[event.player_index].gui.center['Diggy.MarketExchange.Frame']
if frame and frame.valid then
local data = Gui.get_data(frame)
redraw_title(data)
redraw_list(data)
end
end end
local function on_placed_entity(event) local function on_placed_entity(event)
if ('market' ~= event.entity.name) then local market = event.entity
if ('market' ~= market.name) then
return return
end end
update_market_contents(event.entity) market.add_market_item({
price = {{config.currency_item, 50}},
offer = {type = 'nothing', effect_description = 'Send ' .. config.stone_to_surface_amount .. ' ' .. config.currency_item .. ' to the surface'}
})
update_market_contents(market)
end end
function MarketExchange.get_extra_map_info(config) function MarketExchange.get_extra_map_info(config)
@ -245,6 +295,7 @@ function MarketExchange.on_init()
position = config.market_spawn_position, position = config.market_spawn_position,
player_force = game.forces.player, player_force = game.forces.player,
currency_item = config.currency_item, currency_item = config.currency_item,
void_chest_tiles = config.void_chest_tiles,
}) })
update_mining_speed(game.forces.player) update_mining_speed(game.forces.player)
@ -256,15 +307,74 @@ end
function MarketExchange.register(cfg) function MarketExchange.register(cfg)
config = cfg config = cfg
stone_tracker.first_time_market_item = {
price = {{config.currency_item, 50}},
offer = {type = 'nothing', effect_description = 'Send ' .. config.stone_to_surface_amount .. ' stone to the surface'}
}
Event.add(defines.events.on_research_finished, on_research_finished) Event.add(defines.events.on_research_finished, on_research_finished)
Event.add(defines.events.on_market_item_purchased, on_market_item_purchased) Event.add(defines.events.on_market_item_purchased, on_market_item_purchased)
Event.add(Template.events.on_placed_entity, on_placed_entity) Event.add(Template.events.on_placed_entity, on_placed_entity)
Event.add(defines.events.on_player_created, on_player_created) Event.add(defines.events.on_player_created, on_player_created)
local x_min
local y_min
local x_max
local y_max
for _, position in pairs(config.void_chest_tiles) do
local x = position.x
local y = position.y
if (nil == x_min or x < x_min) then
x_min = x
end
if (nil == x_max or x > x_max) then
x_max = x
end
if (nil == y_min or y < y_min) then
y_min = y
end
if (nil == y_max or y > y_max) then
y_max = y
end
end
local area = {{x_min, y_min}, {x_max + 1, y_max + 1}}
Event.on_nth_tick(config.void_chest_frequency, function ()
local send_to_surface = 0
local find_entities_filtered = game.surfaces.nauvis.find_entities_filtered
local chests = find_entities_filtered({area = area, type = {'container', 'logistics-container'}})
local to_fetch = stone_collecting.active_modifier
for _, chest in pairs(chests) do
local chest_contents = chest.get_inventory(defines.inventory.chest)
local stone_in_chest = chest_contents.get_item_count(config.currency_item)
local delta = to_fetch
if (stone_in_chest < delta) then
delta = stone_in_chest
end
if (delta > 0) then
chest_contents.remove({name = config.currency_item, count = delta})
send_to_surface = send_to_surface + delta
end
end
if (send_to_surface == 0) then
return
end
local markets = find_entities_filtered({name = 'market', position = config.market_spawn_position, limit = 1})
if (#markets == 0) then
Debug.printPosition(config.market_spawn_position, 'Unable to find a market')
return
end
send_stone_to_surface(send_to_surface)
update_market_contents(markets[1])
end)
end end
return MarketExchange return MarketExchange

View File

@ -39,24 +39,28 @@ function StartingZone.register(config)
local tiles = {} local tiles = {}
local rocks = {} local rocks = {}
local dirt_range = floor(starting_zone_size / 2)
local rock_range = starting_zone_size - 2
local stress_hack = floor(starting_zone_size / 10)
for x = -starting_zone_size, starting_zone_size do for x = -starting_zone_size, starting_zone_size do
for y = -starting_zone_size, starting_zone_size do for y = -starting_zone_size, starting_zone_size do
local distance = floor(sqrt(x * x + y * y)) local distance = floor(sqrt(x * x + y * y))
if (distance < starting_zone_size) then if (distance < starting_zone_size) then
if (distance > floor(starting_zone_size / 2)) then if (distance > dirt_range) then
insert(tiles, {name = 'dirt-' .. random(1, 7), position = {x = x, y = y}}) insert(tiles, {name = 'dirt-' .. random(1, 7), position = {x = x, y = y}})
else else
insert(tiles, {name = 'stone-path', position = {x = x, y = y}}) insert(tiles, {name = 'stone-path', position = {x = x, y = y}})
end end
if (distance > starting_zone_size - 2) then if (distance > rock_range) then
insert(rocks, {name = 'sand-rock-big', position = {x = x, y = y}}) insert(rocks, {name = 'sand-rock-big', position = {x = x, y = y}})
end end
-- hack to avoid starting area from collapsing -- hack to avoid starting area from collapsing
if (distance > floor(starting_zone_size / 10)) then if (distance > stress_hack) then
DiggyCaveCollapse.stress_map_add(surface, {x = x, y = y}, -0.3) DiggyCaveCollapse.stress_map_add(surface, {x = x, y = y}, -0.5)
end end
end end
end end