2019-01-16 23:05:12 +02:00
|
|
|
local Event = require 'utils.event'
|
2019-01-16 23:14:52 +02:00
|
|
|
local Game = require 'utils.game'
|
2019-01-17 22:49:45 +02:00
|
|
|
local Command = require 'utils.command'
|
2019-01-18 22:56:16 +02:00
|
|
|
local Task = require 'utils.task'
|
|
|
|
local Token = require 'utils.token'
|
2019-01-16 23:05:12 +02:00
|
|
|
local Retailer = require 'features.retailer'
|
2019-01-17 22:49:45 +02:00
|
|
|
local round = math.round
|
2019-01-16 23:05:12 +02:00
|
|
|
local insert = table.insert
|
|
|
|
local remove = table.remove
|
|
|
|
|
2019-01-18 22:56:16 +02:00
|
|
|
local clean_energy_interface = Token.register(function (params)
|
|
|
|
local entity = params.entity
|
|
|
|
if not entity or not entity.valid then
|
|
|
|
-- already removed o.O
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
entity.destroy()
|
|
|
|
end)
|
|
|
|
|
2019-01-16 23:05:12 +02:00
|
|
|
if global.config.market.enabled then
|
|
|
|
local new_items = {
|
|
|
|
{
|
|
|
|
name = 'welcome-package',
|
|
|
|
name_label = 'Lazy bastard welcome package',
|
|
|
|
type = Retailer.item_types.item_package,
|
|
|
|
description = 'Contains some goodies to get started',
|
|
|
|
sprite = 'achievement/lazy-bastard',
|
|
|
|
stack_limit = 1,
|
|
|
|
player_limit = 1,
|
|
|
|
price = 0,
|
|
|
|
items = {
|
|
|
|
{name = 'solar-panel', count = 1},
|
|
|
|
{name = 'roboport', count = 1},
|
2019-01-17 22:49:45 +02:00
|
|
|
{name = 'coin', count = 30},
|
|
|
|
{name = 'small-electric-pole', count = 5},
|
2019-01-18 22:56:16 +02:00
|
|
|
{name = 'construction-robot', count = 2},
|
2019-01-16 23:05:12 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{price = 5, name = 'construction-robot'},
|
|
|
|
{price = 15, name = 'logistic-robot'},
|
|
|
|
{price = 50, name = 'roboport'},
|
2019-01-17 22:49:45 +02:00
|
|
|
{price = 5, name = 'logistic-chest-passive-provider'},
|
2019-01-18 22:56:16 +02:00
|
|
|
{price = 5, name = 'logistic-chest-active-provider'},
|
|
|
|
{price = 5, name = 'logistic-chest-buffer'},
|
|
|
|
{price = 5, name = 'logistic-chest-requester'},
|
2019-01-17 22:49:45 +02:00
|
|
|
{price = 5, name = 'logistic-chest-storage'},
|
2019-01-16 23:05:12 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
local market_items = require 'resources.market_items'
|
|
|
|
|
|
|
|
for i = #market_items, 1, -1 do
|
|
|
|
local name = market_items[i].name
|
|
|
|
-- cleanup items we don't need, construction bot has to be replaced for convenience
|
|
|
|
if name == 'temporary-mining-speed-bonus' or name == 'construction-robot' or name == 'steel-axe' then
|
|
|
|
remove(market_items, i)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
for i = 1, #new_items do
|
|
|
|
insert(market_items, i, new_items[i])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- disable pickaxes from the start
|
|
|
|
Event.on_init(function ()
|
|
|
|
local recipes = game.forces.player.recipes
|
|
|
|
recipes['iron-axe'].enabled = false
|
|
|
|
recipes['steel-axe'].enabled = false
|
|
|
|
end)
|
|
|
|
|
|
|
|
-- ensure the recipes are disabled all the time
|
|
|
|
Event.add(defines.events.on_research_finished, function (event)
|
|
|
|
local recipes = event.research.force.recipes
|
|
|
|
recipes['iron-axe'].enabled = false
|
|
|
|
recipes['steel-axe'].enabled = false
|
|
|
|
end)
|
|
|
|
|
|
|
|
-- players cannot build anything, just place ghosts
|
|
|
|
Event.add(defines.events.on_built_entity, function(event)
|
|
|
|
local entity = event.created_entity
|
|
|
|
if not entity or not entity.valid then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local name = entity.name
|
|
|
|
|
|
|
|
if name == 'entity-ghost' then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
-- replace the entity by a ghost
|
|
|
|
local direction = entity.direction
|
|
|
|
local position = entity.position
|
|
|
|
local surface = entity.surface
|
|
|
|
local force = entity.force
|
2019-01-17 22:49:45 +02:00
|
|
|
|
|
|
|
-- not every item has a ghost, this is the easiest way to prevent errors and stop replacement
|
|
|
|
pcall(function()
|
|
|
|
surface.create_entity({
|
|
|
|
name = 'entity-ghost',
|
|
|
|
inner_name = name,
|
|
|
|
direction = direction,
|
|
|
|
position = position,
|
|
|
|
force = force,
|
|
|
|
});
|
|
|
|
entity.destroy()
|
|
|
|
|
|
|
|
-- attempt to give the item back to the player
|
|
|
|
local player = Game.get_player_by_index(event.player_index)
|
|
|
|
if not player or not player.valid then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
player.insert(event.stack)
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
Command.add('lazy-bastard-bootstrap', {
|
|
|
|
description = 'Puts down the minimum requirements to get started',
|
|
|
|
admin_only = true,
|
|
|
|
}, function(_, player)
|
|
|
|
local surface = player.surface
|
|
|
|
local force = player.force
|
|
|
|
|
|
|
|
local pos = player.position
|
|
|
|
pos.y = round(pos.y - 4)
|
|
|
|
pos.x = round(pos.x)
|
|
|
|
|
|
|
|
local bot_count = 3
|
|
|
|
local create_entity = surface.create_entity
|
|
|
|
local templates = {
|
|
|
|
{name = 'medium-electric-pole', force = force, position = {x = pos.x - 2, y = pos.y - 1}},
|
|
|
|
{name = 'roboport', force = force, position = {x = pos.x, y = pos.y}},
|
|
|
|
{name = 'logistic-chest-storage', force = force, position = {x = pos.x + 1, y = pos.y + 1}},
|
|
|
|
{name = 'logistic-chest-storage', force = force, position = {x = pos.x - 2, y = pos.y + 1}},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i = 1, #templates do
|
|
|
|
local entity = create_entity(templates[i])
|
|
|
|
entity.minable = false
|
|
|
|
entity.destructible = false
|
2019-01-16 23:05:12 +02:00
|
|
|
end
|
|
|
|
|
2019-01-17 22:49:45 +02:00
|
|
|
for _ = 1, bot_count do
|
|
|
|
create_entity({name = 'construction-robot', force = force, position = pos})
|
|
|
|
end
|
2019-01-18 22:56:16 +02:00
|
|
|
|
|
|
|
local power_source = create_entity({name = 'hidden-electric-energy-interface', position = pos})
|
|
|
|
power_source.electric_buffer_size = 30000
|
|
|
|
power_source.power_production = 30000
|
2019-01-19 14:55:20 +02:00
|
|
|
power_source.destructible = false
|
|
|
|
power_source.minable = false
|
2019-01-18 22:56:16 +02:00
|
|
|
|
|
|
|
-- in 7 minutes, remove the power source
|
|
|
|
Task.set_timeout(420, clean_energy_interface, {entity = power_source})
|
2019-01-16 23:05:12 +02:00
|
|
|
end)
|