mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-01-10 00:43:27 +02:00
commit
9346c1bfcf
@ -69,7 +69,8 @@ require "modules.autostash"
|
||||
--require "maps.mountain_fortress_v2.main"
|
||||
--require "maps.mountain_fortress"
|
||||
--require "maps.island_troopers.main"
|
||||
require "maps.biter_hatchery.main"
|
||||
--require "maps.biter_hatchery.main"
|
||||
require "maps.scrapyard.main"
|
||||
--require "maps.tank_conquest.tank_conquest"
|
||||
--require "maps.territorial_control"
|
||||
--require "maps.cave_choppy.cave_miner"
|
||||
|
93
maps/scrapyard/locomotive.lua
Normal file
93
maps/scrapyard/locomotive.lua
Normal file
@ -0,0 +1,93 @@
|
||||
local Public = {}
|
||||
|
||||
function Public.locomotive_spawn(surface, position)
|
||||
for y = -6, 6, 2 do
|
||||
surface.create_entity({name = "straight-rail", position = {position.x, position.y + y}, force = "player", direction = 0})
|
||||
end
|
||||
global.locomotive = surface.create_entity({name = "locomotive", position = {position.x, position.y + -3}, force = "player"})
|
||||
global.locomotive.get_inventory(defines.inventory.fuel).insert({name = "wood", count = 100})
|
||||
|
||||
global.locomotive_cargo = surface.create_entity({name = "cargo-wagon", position = {position.x, position.y + 3}, force = "player"})
|
||||
global.locomotive_cargo.get_inventory(defines.inventory.cargo_wagon).insert({name = "raw-fish", count = 8})
|
||||
|
||||
rendering.draw_light({
|
||||
sprite = "utility/light_medium", scale = 5.5, intensity = 1, minimum_darkness = 0,
|
||||
oriented = true, color = {255,255,255}, target = global.locomotive,
|
||||
surface = surface, visible = true, only_in_alt_mode = false,
|
||||
})
|
||||
|
||||
global.locomotive.color = {0, 255, 0}
|
||||
global.locomotive.minable = false
|
||||
global.locomotive_cargo.minable = false
|
||||
global.locomotive_cargo.operable = false
|
||||
end
|
||||
|
||||
|
||||
local function fish_tag()
|
||||
if not global.locomotive_cargo then return end
|
||||
if not global.locomotive_cargo.valid then return end
|
||||
if not global.locomotive_cargo.surface then return end
|
||||
if not global.locomotive_cargo.surface.valid then return end
|
||||
if global.locomotive_tag then
|
||||
if global.locomotive_tag.valid then
|
||||
if global.locomotive_tag.position.x == global.locomotive_cargo.position.x and global.locomotive_tag.position.y == global.locomotive_cargo.position.y then return end
|
||||
global.locomotive_tag.destroy()
|
||||
end
|
||||
end
|
||||
global.locomotive_tag = global.locomotive_cargo.force.add_chart_tag(
|
||||
global.locomotive_cargo.surface,
|
||||
{icon = {type = 'item', name = 'raw-fish'},
|
||||
position = global.locomotive_cargo.position,
|
||||
text = " "
|
||||
})
|
||||
end
|
||||
--[[
|
||||
local function accelerate()
|
||||
if not global.locomotive then return end
|
||||
if not global.locomotive.valid then return end
|
||||
if global.locomotive.get_driver() then return end
|
||||
global.locomotive_driver = global.locomotive.surface.create_entity({name = "character", position = global.locomotive.position, force = "player"})
|
||||
global.locomotive_driver.driving = true
|
||||
global.locomotive_driver.riding_state = {acceleration = defines.riding.acceleration.accelerating, direction = defines.riding.direction.straight}
|
||||
end
|
||||
|
||||
local function remove_acceleration()
|
||||
if not global.locomotive then return end
|
||||
if not global.locomotive.valid then return end
|
||||
if global.locomotive_driver then global.locomotive_driver.destroy() end
|
||||
global.locomotive_driver = nil
|
||||
end
|
||||
]]
|
||||
local function set_player_spawn_and_refill_fish()
|
||||
if not global.locomotive_cargo then return end
|
||||
if not global.locomotive_cargo.valid then return end
|
||||
global.locomotive_cargo.health = global.locomotive_cargo.health + 6
|
||||
global.locomotive_cargo.get_inventory(defines.inventory.cargo_wagon).insert({name = "raw-fish", count = math.random(2, 5)})
|
||||
local position = global.locomotive_cargo.surface.find_non_colliding_position("stone-furnace", global.locomotive_cargo.position, 16, 2)
|
||||
if not position then return end
|
||||
game.forces.player.set_spawn_position({x = position.x, y = position.y}, global.locomotive_cargo.surface)
|
||||
end
|
||||
|
||||
local function tick()
|
||||
if game.tick % 30 == 0 then
|
||||
if game.tick % 1800 == 0 then
|
||||
set_player_spawn_and_refill_fish()
|
||||
end
|
||||
if global.game_reset_tick then
|
||||
if global.game_reset_tick < game.tick then
|
||||
global.game_reset_tick = nil
|
||||
require "maps.scrapyard.main".reset_map()
|
||||
end
|
||||
return
|
||||
end
|
||||
fish_tag()
|
||||
--accelerate()
|
||||
else
|
||||
--remove_acceleration()
|
||||
end
|
||||
end
|
||||
|
||||
local event = require 'utils.event'
|
||||
event.on_nth_tick(5, tick)
|
||||
|
||||
return Public
|
166
maps/scrapyard/loot.lua
Normal file
166
maps/scrapyard/loot.lua
Normal file
@ -0,0 +1,166 @@
|
||||
local Public = {}
|
||||
local math_random = math.random
|
||||
|
||||
function Public.create_loot(surface, position, chest)
|
||||
local chest_raffle = {}
|
||||
local chest_loot = {
|
||||
{{name = "submachine-gun", count = math_random(1,3)}, weight = 3, d_min = 0.0, d_max = 0.1},
|
||||
{{name = "slowdown-capsule", count = math_random(16,32)}, weight = 1, d_min = 0.3, d_max = 0.7},
|
||||
{{name = "poison-capsule", count = math_random(8,16)}, weight = 3, d_min = 0.3, d_max = 1},
|
||||
{{name = "uranium-cannon-shell", count = math_random(16,32)}, weight = 5, d_min = 0.6, d_max = 1},
|
||||
{{name = "cannon-shell", count = math_random(16,32)}, weight = 5, d_min = 0.4, d_max = 0.7},
|
||||
{{name = "explosive-uranium-cannon-shell", count = math_random(16,32)}, weight = 5, d_min = 0.6, d_max = 1},
|
||||
{{name = "explosive-cannon-shell", count = math_random(16,32)}, weight = 5, d_min = 0.4, d_max = 0.8},
|
||||
{{name = "shotgun", count = 1}, weight = 2, d_min = 0.0, d_max = 0.2},
|
||||
{{name = "shotgun-shell", count = math_random(16,32)}, weight = 5, d_min = 0.0, d_max = 0.2},
|
||||
{{name = "combat-shotgun", count = 1}, weight = 3, d_min = 0.3, d_max = 0.8},
|
||||
{{name = "piercing-shotgun-shell", count = math_random(16,32)}, weight = 10, d_min = 0.2, d_max = 1},
|
||||
{{name = "flamethrower", count = 1}, weight = 3, d_min = 0.3, d_max = 0.6},
|
||||
{{name = "flamethrower-ammo", count = math_random(16,32)}, weight = 5, d_min = 0.3, d_max = 1},
|
||||
{{name = "rocket-launcher", count = 1}, weight = 3, d_min = 0.2, d_max = 0.6},
|
||||
{{name = "rocket", count = math_random(16,32)}, weight = 5, d_min = 0.2, d_max = 0.7},
|
||||
{{name = "explosive-rocket", count = math_random(16,32)}, weight = 5, d_min = 0.3, d_max = 1},
|
||||
{{name = "land-mine", count = math_random(16,32)}, weight = 5, d_min = 0.2, d_max = 0.7},
|
||||
{{name = "grenade", count = math_random(16,32)}, weight = 5, d_min = 0.0, d_max = 0.5},
|
||||
{{name = "cluster-grenade", count = math_random(8,16)}, weight = 5, d_min = 0.4, d_max = 1},
|
||||
{{name = "firearm-magazine", count = math_random(32,128)}, weight = 5, d_min = 0, d_max = 0.3},
|
||||
{{name = "piercing-rounds-magazine", count = math_random(32,128)}, weight = 5, d_min = 0.1, d_max = 0.8},
|
||||
{{name = "uranium-rounds-magazine", count = math_random(32,128)}, weight = 5, d_min = 0.5, d_max = 1},
|
||||
{{name = "railgun", count = 1}, weight = 1, d_min = 0.2, d_max = 1},
|
||||
{{name = "railgun-dart", count = math_random(16,32)}, weight = 3, d_min = 0.2, d_max = 0.7},
|
||||
{{name = "defender-capsule", count = math_random(8,16)}, weight = 2, d_min = 0.0, d_max = 0.7},
|
||||
{{name = "distractor-capsule", count = math_random(8,16)}, weight = 2, d_min = 0.2, d_max = 1},
|
||||
{{name = "destroyer-capsule", count = math_random(8,16)}, weight = 2, d_min = 0.3, d_max = 1},
|
||||
{{name = "atomic-bomb", count = 1}, weight = 1, d_min = 0.8, d_max = 1},
|
||||
{{name = "light-armor", count = 1}, weight = 3, d_min = 0, d_max = 0.1},
|
||||
{{name = "heavy-armor", count = 1}, weight = 3, d_min = 0.1, d_max = 0.3},
|
||||
{{name = "modular-armor", count = 1}, weight = 2, d_min = 0.2, d_max = 0.6},
|
||||
{{name = "power-armor", count = 1}, weight = 1, d_min = 0.4, d_max = 1},
|
||||
{{name = "battery-equipment", count = 1}, weight = 2, d_min = 0.3, d_max = 0.7},
|
||||
{{name = "belt-immunity-equipment", count = 1}, weight = 1, d_min = 0.5, d_max = 1},
|
||||
{{name = "solar-panel-equipment", count = math_random(1,4)}, weight = 5, d_min = 0.4, d_max = 0.8},
|
||||
{{name = "discharge-defense-equipment", count = 1}, weight = 1, d_min = 0.5, d_max = 1},
|
||||
{{name = "energy-shield-equipment", count = math_random(1,2)}, weight = 2, d_min = 0.3, d_max = 0.8},
|
||||
{{name = "exoskeleton-equipment", count = 1}, weight = 1, d_min = 0.3, d_max = 1},
|
||||
{{name = "night-vision-equipment", count = 1}, weight = 1, d_min = 0.3, d_max = 0.8},
|
||||
{{name = "personal-laser-defense-equipment", count = 1}, weight = 1, d_min = 0.7, d_max = 1},
|
||||
{{name = "personal-roboport-equipment", count = math_random(1,2)}, weight = 3, d_min = 0.4, d_max = 1},
|
||||
{{name = "logistic-robot", count = math_random(5,25)}, weight = 2, d_min = 0.5, d_max = 1},
|
||||
{{name = "construction-robot", count = math_random(5,25)}, weight = 5, d_min = 0.4, d_max = 1},
|
||||
{{name = "iron-gear-wheel", count = math_random(80,100)}, weight = 3, d_min = 0.0, d_max = 0.3},
|
||||
{{name = "copper-cable", count = math_random(100,200)}, weight = 3, d_min = 0.0, d_max = 0.3},
|
||||
{{name = "engine-unit", count = math_random(16,32)}, weight = 2, d_min = 0.1, d_max = 0.5},
|
||||
{{name = "electric-engine-unit", count = math_random(16,32)}, weight = 2, d_min = 0.4, d_max = 0.8},
|
||||
{{name = "battery", count = math_random(50,150)}, weight = 2, d_min = 0.3, d_max = 0.8},
|
||||
{{name = "advanced-circuit", count = math_random(50,150)}, weight = 3, d_min = 0.3, d_max = 1},
|
||||
{{name = "electronic-circuit", count = math_random(50,150)}, weight = 4, d_min = 0.0, d_max = 0.4},
|
||||
{{name = "processing-unit", count = math_random(50,150)}, weight = 3, d_min = 0.7, d_max = 1},
|
||||
{{name = "explosives", count = math_random(40,100)}, weight = 20, d_min = 0.0, d_max = 1},
|
||||
{{name = "lubricant-barrel", count = math_random(4,10)}, weight = 1, d_min = 0.3, d_max = 0.5},
|
||||
{{name = "rocket-fuel", count = math_random(4,10)}, weight = 2, d_min = 0.3, d_max = 0.7},
|
||||
{{name = "effectivity-module", count = math_random(1,4)}, weight = 2, d_min = 0.1, d_max = 1},
|
||||
{{name = "productivity-module", count = math_random(1,4)}, weight = 2, d_min = 0.1, d_max = 1},
|
||||
{{name = "speed-module", count = math_random(1,4)}, weight = 2, d_min = 0.1, d_max = 1},
|
||||
{{name = "automation-science-pack", count = math_random(16,64)}, weight = 3, d_min = 0.0, d_max = 0.2},
|
||||
{{name = "logistic-science-pack", count = math_random(16,64)}, weight = 3, d_min = 0.1, d_max = 0.5},
|
||||
{{name = "military-science-pack", count = math_random(16,64)}, weight = 3, d_min = 0.2, d_max = 1},
|
||||
{{name = "chemical-science-pack", count = math_random(16,64)}, weight = 3, d_min = 0.3, d_max = 1},
|
||||
{{name = "production-science-pack", count = math_random(16,64)}, weight = 3, d_min = 0.4, d_max = 1},
|
||||
{{name = "utility-science-pack", count = math_random(16,64)}, weight = 3, d_min = 0.5, d_max = 1},
|
||||
{{name = "space-science-pack", count = math_random(16,64)}, weight = 3, d_min = 0.9, d_max = 1},
|
||||
{{name = "steel-plate", count = math_random(25,75)}, weight = 2, d_min = 0.1, d_max = 0.3},
|
||||
{{name = "nuclear-fuel", count = 1}, weight = 2, d_min = 0.7, d_max = 1},
|
||||
{{name = "burner-inserter", count = math_random(8,16)}, weight = 3, d_min = 0.0, d_max = 0.1},
|
||||
{{name = "inserter", count = math_random(8,16)}, weight = 3, d_min = 0.0, d_max = 0.4},
|
||||
{{name = "long-handed-inserter", count = math_random(8,16)}, weight = 3, d_min = 0.0, d_max = 0.4},
|
||||
{{name = "fast-inserter", count = math_random(8,16)}, weight = 3, d_min = 0.1, d_max = 1},
|
||||
{{name = "filter-inserter", count = math_random(8,16)}, weight = 1, d_min = 0.2, d_max = 1},
|
||||
{{name = "stack-filter-inserter", count = math_random(4,8)}, weight = 1, d_min = 0.4, d_max = 1},
|
||||
{{name = "stack-inserter", count = math_random(4,8)}, weight = 3, d_min = 0.3, d_max = 1},
|
||||
{{name = "small-electric-pole", count = math_random(16,24)}, weight = 3, d_min = 0.0, d_max = 0.3},
|
||||
{{name = "medium-electric-pole", count = math_random(8,16)}, weight = 3, d_min = 0.2, d_max = 1},
|
||||
{{name = "big-electric-pole", count = math_random(4,8)}, weight = 3, d_min = 0.3, d_max = 1},
|
||||
{{name = "substation", count = math_random(2,4)}, weight = 3, d_min = 0.5, d_max = 1},
|
||||
{{name = "wooden-chest", count = math_random(8,16)}, weight = 3, d_min = 0.0, d_max = 0.2},
|
||||
{{name = "iron-chest", count = math_random(8,16)}, weight = 3, d_min = 0.1, d_max = 0.4},
|
||||
{{name = "steel-chest", count = math_random(8,16)}, weight = 3, d_min = 0.3, d_max = 1},
|
||||
{{name = "small-lamp", count = math_random(16,32)}, weight = 3, d_min = 0.1, d_max = 0.3},
|
||||
{{name = "rail", count = math_random(25,75)}, weight = 3, d_min = 0.1, d_max = 0.6},
|
||||
{{name = "assembling-machine-1", count = math_random(2,4)}, weight = 3, d_min = 0.0, d_max = 0.3},
|
||||
{{name = "assembling-machine-2", count = math_random(2,4)}, weight = 3, d_min = 0.2, d_max = 0.8},
|
||||
{{name = "assembling-machine-3", count = math_random(2,4)}, weight = 3, d_min = 0.5, d_max = 1},
|
||||
{{name = "accumulator", count = math_random(4,8)}, weight = 3, d_min = 0.4, d_max = 1},
|
||||
{{name = "offshore-pump", count = math_random(1,3)}, weight = 2, d_min = 0.0, d_max = 0.2},
|
||||
{{name = "beacon", count = 1}, weight = 2, d_min = 0.7, d_max = 1},
|
||||
{{name = "boiler", count = math_random(3,6)}, weight = 3, d_min = 0.0, d_max = 0.3},
|
||||
{{name = "steam-engine", count = math_random(2,4)}, weight = 3, d_min = 0.0, d_max = 0.5},
|
||||
{{name = "steam-turbine", count = math_random(1,2)}, weight = 2, d_min = 0.6, d_max = 1},
|
||||
{{name = "nuclear-reactor", count = 1}, weight = 1, d_min = 0.7, d_max = 1},
|
||||
{{name = "centrifuge", count = 1}, weight = 1, d_min = 0.6, d_max = 1},
|
||||
{{name = "heat-pipe", count = math_random(4,8)}, weight = 2, d_min = 0.5, d_max = 1},
|
||||
{{name = "heat-exchanger", count = math_random(2,4)}, weight = 2, d_min = 0.5, d_max = 1},
|
||||
{{name = "arithmetic-combinator", count = math_random(4,8)}, weight = 2, d_min = 0.1, d_max = 1},
|
||||
{{name = "constant-combinator", count = math_random(4,8)}, weight = 2, d_min = 0.1, d_max = 1},
|
||||
{{name = "decider-combinator", count = math_random(4,8)}, weight = 2, d_min = 0.1, d_max = 1},
|
||||
{{name = "power-switch", count = 1}, weight = 2, d_min = 0.1, d_max = 1},
|
||||
{{name = "programmable-speaker", count = math_random(2,4)}, weight = 1, d_min = 0.1, d_max = 1},
|
||||
{{name = "green-wire", count = math_random(50,99)}, weight = 4, d_min = 0.1, d_max = 1},
|
||||
{{name = "red-wire", count = math_random(50,99)}, weight = 4, d_min = 0.1, d_max = 1},
|
||||
{{name = "chemical-plant", count = math_random(1,3)}, weight = 3, d_min = 0.3, d_max = 1},
|
||||
{{name = "burner-mining-drill", count = math_random(2,4)}, weight = 3, d_min = 0.0, d_max = 0.2},
|
||||
{{name = "electric-mining-drill", count = math_random(2,4)}, weight = 3, d_min = 0.2, d_max = 1},
|
||||
{{name = "express-transport-belt", count = math_random(25,75)}, weight = 3, d_min = 0.5, d_max = 1},
|
||||
{{name = "express-underground-belt", count = math_random(4,8)}, weight = 3, d_min = 0.5, d_max = 1},
|
||||
{{name = "express-splitter", count = math_random(1,4)}, weight = 3, d_min = 0.5, d_max = 1},
|
||||
{{name = "fast-transport-belt", count = math_random(25,75)}, weight = 3, d_min = 0.2, d_max = 0.7},
|
||||
{{name = "fast-underground-belt", count = math_random(4,8)}, weight = 3, d_min = 0.2, d_max = 0.7},
|
||||
{{name = "fast-splitter", count = math_random(1,4)}, weight = 3, d_min = 0.2, d_max = 0.3},
|
||||
{{name = "transport-belt", count = math_random(25,75)}, weight = 3, d_min = 0, d_max = 0.3},
|
||||
{{name = "underground-belt", count = math_random(4,8)}, weight = 3, d_min = 0, d_max = 0.3},
|
||||
{{name = "splitter", count = math_random(1,4)}, weight = 3, d_min = 0, d_max = 0.3},
|
||||
{{name = "pipe", count = math_random(30,50)}, weight = 3, d_min = 0.0, d_max = 0.3},
|
||||
{{name = "pipe-to-ground", count = math_random(4,8)}, weight = 1, d_min = 0.2, d_max = 0.5},
|
||||
{{name = "pumpjack", count = math_random(1,3)}, weight = 1, d_min = 0.3, d_max = 0.8},
|
||||
{{name = "pump", count = math_random(1,2)}, weight = 1, d_min = 0.3, d_max = 0.8},
|
||||
{{name = "solar-panel", count = math_random(3,6)}, weight = 3, d_min = 0.4, d_max = 0.9},
|
||||
{{name = "electric-furnace", count = math_random(2,4)}, weight = 3, d_min = 0.5, d_max = 1},
|
||||
{{name = "steel-furnace", count = math_random(4,8)}, weight = 3, d_min = 0.2, d_max = 0.7},
|
||||
{{name = "stone-furnace", count = math_random(8,16)}, weight = 3, d_min = 0.0, d_max = 0.2},
|
||||
{{name = "radar", count = math_random(1,2)}, weight = 1, d_min = 0.1, d_max = 0.4},
|
||||
{{name = "rail-signal", count = math_random(8,16)}, weight = 2, d_min = 0.2, d_max = 0.8},
|
||||
{{name = "rail-chain-signal", count = math_random(8,16)}, weight = 2, d_min = 0.2, d_max = 0.8},
|
||||
{{name = "stone-wall", count = math_random(33,99)}, weight = 3, d_min = 0.0, d_max = 0.7},
|
||||
{{name = "gate", count = math_random(16,32)}, weight = 3, d_min = 0.0, d_max = 0.7},
|
||||
{{name = "storage-tank", count = math_random(2,6)}, weight = 3, d_min = 0.3, d_max = 0.6},
|
||||
{{name = "train-stop", count = math_random(1,2)}, weight = 1, d_min = 0.2, d_max = 0.7},
|
||||
{{name = "express-loader", count = math_random(1,2)}, weight = 1, d_min = 0.5, d_max = 1},
|
||||
{{name = "fast-loader", count = math_random(1,2)}, weight = 1, d_min = 0.2, d_max = 0.7},
|
||||
{{name = "loader", count = math_random(1,2)}, weight = 1, d_min = 0.0, d_max = 0.5},
|
||||
{{name = "lab", count = math_random(1,2)}, weight = 2, d_min = 0.0, d_max = 0.3},
|
||||
{{name = "roboport", count = 1}, weight = 2, d_min = 0.8, d_max = 1},
|
||||
{{name = "flamethrower-turret", count = 1}, weight = 3, d_min = 0.5, d_max = 1},
|
||||
{{name = "laser-turret", count = math_random(3,6)}, weight = 3, d_min = 0.5, d_max = 1},
|
||||
{{name = "gun-turret", count = math_random(2,4)}, weight = 3, d_min = 0.2, d_max = 0.9},
|
||||
}
|
||||
|
||||
local distance_to_center = (math.abs(position.y) + 1) * 0.0002
|
||||
if distance_to_center > 1 then distance_to_center = 1 end
|
||||
|
||||
for _, t in pairs (chest_loot) do
|
||||
for x = 1, t.weight, 1 do
|
||||
if t.d_min <= distance_to_center and t.d_max >= distance_to_center then
|
||||
table.insert(chest_raffle, t[1])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local e = surface.create_entity({name = chest, position=position, force="neutral"})
|
||||
e.minable = false
|
||||
local i = e.get_inventory(defines.inventory.chest)
|
||||
for x = 1, math_random(2,6), 1 do
|
||||
local loot = chest_raffle[math_random(1,#chest_raffle)]
|
||||
i.insert(loot)
|
||||
end
|
||||
end
|
||||
|
||||
return Public
|
398
maps/scrapyard/main.lua
Normal file
398
maps/scrapyard/main.lua
Normal file
@ -0,0 +1,398 @@
|
||||
require "on_tick_schedule"
|
||||
require "modules.dynamic_landfill"
|
||||
require "modules.mineable_wreckage_yields_ores"
|
||||
require "modules.rocks_heal_over_time"
|
||||
require "modules.spawners_contain_biters"
|
||||
require "modules.biters_yield_coins"
|
||||
require "modules.dangerous_goods"
|
||||
require "modules.wave_defense.main"
|
||||
|
||||
local WD = require "modules.wave_defense.table"
|
||||
local Map = require 'modules.map_info'
|
||||
local RPG = require 'modules.rpg'
|
||||
local Reset = require "functions.soft_reset"
|
||||
local BiterRolls = require "modules.wave_defense.biter_rolls"
|
||||
|
||||
local Loot = require 'maps.scrapyard.loot'
|
||||
local Pets = require "modules.biter_pets"
|
||||
local Modifier = require "player_modifiers"
|
||||
local tick_tack_trap = require "functions.tick_tack_trap"
|
||||
local Terrain = require 'maps.scrapyard.terrain'
|
||||
local Event = require 'utils.event'
|
||||
local math_random = math.random
|
||||
|
||||
local Locomotive = require "maps.scrapyard.locomotive".locomotive_spawn
|
||||
|
||||
local Public = {}
|
||||
|
||||
local disabled_for_deconstruction = {["fish"] = true, ["rock-huge"] = true, ["rock-big"] = true, ["sand-rock-big"] = true, ["mineable-wreckage"] = true}
|
||||
local starting_items = {['pistol'] = 1, ['firearm-magazine'] = 16, ['wood'] = 4, ['rail'] = 16, ['raw-fish'] = 2}
|
||||
|
||||
local treasure_chest_messages = {
|
||||
"You notice an old crate within the rubble. It's filled with treasure!",
|
||||
"You find a chest underneath the broken rocks. It's filled with goodies!",
|
||||
"We has found the precious!",
|
||||
}
|
||||
|
||||
function Public.reset_map()
|
||||
global.spawn_generated = false
|
||||
local wave_defense_table = WD.get_table()
|
||||
|
||||
local map_gen_settings = {
|
||||
["seed"] = math_random(1, 1000000),
|
||||
["water"] = 0.001,
|
||||
["starting_area"] = 1,
|
||||
["cliff_settings"] = {cliff_elevation_interval = 0, cliff_elevation_0 = 0},
|
||||
["default_enable_all_autoplace_controls"] = true,
|
||||
["autoplace_settings"] = {
|
||||
["entity"] = {treat_missing_as_default = false},
|
||||
["tile"] = {treat_missing_as_default = true},
|
||||
["decorative"] = {treat_missing_as_default = true},
|
||||
},
|
||||
}
|
||||
|
||||
if not global.active_surface_index then
|
||||
global.active_surface_index = game.create_surface("scrapyard", map_gen_settings).index
|
||||
else
|
||||
game.forces.player.set_spawn_position({0, 0}, game.surfaces[global.active_surface_index])
|
||||
global.active_surface_index = Reset.soft_reset_map(game.surfaces[global.active_surface_index], map_gen_settings, starting_items).index
|
||||
end
|
||||
|
||||
local surface = game.surfaces[global.active_surface_index]
|
||||
|
||||
surface.request_to_generate_chunks({0,0}, 2)
|
||||
surface.force_generate_chunk_requests()
|
||||
|
||||
|
||||
local p = surface.find_non_colliding_position("character-corpse", {2,-2}, 32, 2)
|
||||
surface.create_entity({name = "character-corpse", position = p})
|
||||
|
||||
game.forces.player.technologies["landfill"].enabled = false
|
||||
game.forces.player.technologies["optics"].researched = true
|
||||
game.forces.player.set_spawn_position({0, 0}, surface)
|
||||
|
||||
surface.ticks_per_day = surface.ticks_per_day * 2
|
||||
surface.min_brightness = 0.08
|
||||
surface.daytime = 0.7
|
||||
|
||||
Locomotive(surface, {x = -18, y = 10})
|
||||
|
||||
rendering.draw_text{
|
||||
text = "Welcome to Scrapyard!",
|
||||
surface = surface,
|
||||
target = {-0,30},
|
||||
color = { r=0.98, g=0.66, b=0.22},
|
||||
scale = 3,
|
||||
font = "heading-1",
|
||||
alignment = "center",
|
||||
scale_with_zoom = false
|
||||
}
|
||||
|
||||
rendering.draw_text{
|
||||
text = "▼",
|
||||
surface = surface,
|
||||
target = {-0,40},
|
||||
color = { r=0.98, g=0.66, b=0.22},
|
||||
scale = 3,
|
||||
font = "heading-1",
|
||||
alignment = "center",
|
||||
scale_with_zoom = false
|
||||
}
|
||||
rendering.draw_text{
|
||||
text = "▼",
|
||||
surface = surface,
|
||||
target = {-0,50},
|
||||
color = { r=0.98, g=0.66, b=0.22},
|
||||
scale = 3,
|
||||
font = "heading-1",
|
||||
alignment = "center",
|
||||
scale_with_zoom = false
|
||||
}
|
||||
rendering.draw_text{
|
||||
text = "▼",
|
||||
surface = surface,
|
||||
target = {-0,60},
|
||||
color = { r=0.98, g=0.66, b=0.22},
|
||||
scale = 3,
|
||||
font = "heading-1",
|
||||
alignment = "center",
|
||||
scale_with_zoom = false
|
||||
}
|
||||
rendering.draw_text{
|
||||
text = "▼",
|
||||
surface = surface,
|
||||
target = {-0,70},
|
||||
color = { r=0.98, g=0.66, b=0.22},
|
||||
scale = 3,
|
||||
font = "heading-1",
|
||||
alignment = "center",
|
||||
scale_with_zoom = false
|
||||
}
|
||||
rendering.draw_text{
|
||||
text = "▼",
|
||||
surface = surface,
|
||||
target = {-0,80},
|
||||
color = { r=0.98, g=0.66, b=0.22},
|
||||
scale = 3,
|
||||
font = "heading-1",
|
||||
alignment = "center",
|
||||
scale_with_zoom = false
|
||||
}
|
||||
rendering.draw_text{
|
||||
text = "▼",
|
||||
surface = surface,
|
||||
target = {-0,90},
|
||||
color = { r=0.98, g=0.66, b=0.22},
|
||||
scale = 3,
|
||||
font = "heading-1",
|
||||
alignment = "center",
|
||||
scale_with_zoom = false
|
||||
}
|
||||
rendering.draw_text{
|
||||
text = "▼",
|
||||
surface = surface,
|
||||
target = {-0,100},
|
||||
color = { r=0.98, g=0.66, b=0.22},
|
||||
scale = 3,
|
||||
font = "heading-1",
|
||||
alignment = "center",
|
||||
scale_with_zoom = false
|
||||
}
|
||||
rendering.draw_text{
|
||||
text = "▼",
|
||||
surface = surface,
|
||||
target = {-0,110},
|
||||
color = { r=0.98, g=0.66, b=0.22},
|
||||
scale = 3,
|
||||
font = "heading-1",
|
||||
alignment = "center",
|
||||
scale_with_zoom = false
|
||||
}
|
||||
rendering.draw_text{
|
||||
text = "Biters will attack this area.",
|
||||
surface = surface,
|
||||
target = {-0,120},
|
||||
color = { r=0.98, g=0.66, b=0.22},
|
||||
scale = 3,
|
||||
font = "heading-1",
|
||||
alignment = "center",
|
||||
scale_with_zoom = false
|
||||
}
|
||||
|
||||
WD.reset_wave_defense()
|
||||
wave_defense_table.surface_index = global.active_surface_index
|
||||
wave_defense_table.target = global.locomotive_cargo
|
||||
wave_defense_table.nest_building_density = 32
|
||||
wave_defense_table.game_lost = false
|
||||
wave_defense_table.spawn_position = {x=0,y=220}
|
||||
|
||||
surface.create_entity({name = "electric-beam", position = {-96, 190}, source = {-96, 190}, target = {96,190}})
|
||||
surface.create_entity({name = "electric-beam", position = {-96, 190}, source = {-96, 190}, target = {96,190}})
|
||||
|
||||
RPG.rpg_reset_all_players()
|
||||
end
|
||||
|
||||
local function protect_train(event)
|
||||
if event.entity.force.index ~= 1 then return end --Player Force
|
||||
if event.entity == global.locomotive_cargo then
|
||||
if event.cause then
|
||||
if event.cause.force.index == 2 then
|
||||
return
|
||||
end
|
||||
end
|
||||
event.entity.health = event.entity.health + event.final_damage_amount
|
||||
end
|
||||
end
|
||||
|
||||
local function on_player_changed_position(event)
|
||||
local player = game.players[event.player_index]
|
||||
local surface = game.surfaces[global.active_surface_index]
|
||||
if player.position.y < 20 then Terrain.reveal(player) end
|
||||
if player.position.y >= 190 then
|
||||
player.teleport({player.position.x, player.position.y - 1}, surface)
|
||||
player.print("The forcefield does not approve.",{r=0.98, g=0.66, b=0.22})
|
||||
if player.character then
|
||||
player.character.health = player.character.health - 5
|
||||
player.character.surface.create_entity({name = "water-splash", position = player.position})
|
||||
if player.character.health <= 0 then player.character.die("enemy") end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function on_marked_for_deconstruction(event)
|
||||
if disabled_for_deconstruction[event.entity.name] then
|
||||
event.entity.cancel_deconstruction(game.players[event.player_index].force.name)
|
||||
end
|
||||
end
|
||||
|
||||
local function on_player_joined_game(event)
|
||||
local surface = game.surfaces[global.active_surface_index]
|
||||
local player = game.players[event.player_index]
|
||||
|
||||
|
||||
if player.surface.index ~= global.active_surface_index then
|
||||
player.teleport(surface.find_non_colliding_position("character", game.forces.player.get_spawn_position(surface), 3, 0,5), surface)
|
||||
for item, amount in pairs(starting_items) do
|
||||
player.insert({name = item, count = amount})
|
||||
end
|
||||
end
|
||||
|
||||
global.player_modifiers[player.index].character_mining_speed_modifier["scrapyard"] = 0
|
||||
Modifier.update_player_modifiers(player)
|
||||
if global.first_load then return end
|
||||
Public.reset_map()
|
||||
global.first_load = true
|
||||
end
|
||||
|
||||
local function hidden_biter(entity)
|
||||
BiterRolls.wave_defense_set_unit_raffle(math.sqrt(entity.position.x ^ 2 + entity.position.y ^ 2) * 0.25)
|
||||
if math.random(1,3) == 1 then
|
||||
entity.surface.create_entity({name = BiterRolls.wave_defense_roll_spitter_name(), position = entity.position})
|
||||
else
|
||||
entity.surface.create_entity({name = BiterRolls.wave_defense_roll_biter_name(), position = entity.position})
|
||||
end
|
||||
end
|
||||
|
||||
local function hidden_worm(entity)
|
||||
BiterRolls.wave_defense_set_worm_raffle(math.sqrt(entity.position.x ^ 2 + entity.position.y ^ 2) * 0.25)
|
||||
entity.surface.create_entity({name = BiterRolls.wave_defense_roll_worm_name(), position = entity.position})
|
||||
end
|
||||
|
||||
local function hidden_biter_pet(event)
|
||||
if math.random(1, 2048) ~= 1 then return end
|
||||
BiterRolls.wave_defense_set_unit_raffle(math.sqrt(event.entity.position.x ^ 2 + event.entity.position.y ^ 2) * 0.25)
|
||||
local unit
|
||||
if math.random(1,3) == 1 then
|
||||
unit = event.entity.surface.create_entity({name = BiterRolls.wave_defense_roll_spitter_name(), position = event.entity.position})
|
||||
else
|
||||
unit = event.entity.surface.create_entity({name = BiterRolls.wave_defense_roll_biter_name(), position = event.entity.position})
|
||||
end
|
||||
Pets.biter_pets_tame_unit(game.players[event.player_index], unit, true)
|
||||
end
|
||||
|
||||
local function hidden_treasure(event)
|
||||
if math.random(1, 320) ~= 1 then return end
|
||||
game.players[event.player_index].print(treasure_chest_messages[math.random(1, #treasure_chest_messages)], {r=0.98, g=0.66, b=0.22})
|
||||
Loot.create_loot(event.entity.surface, event.entity.position, "wooden-chest")
|
||||
end
|
||||
|
||||
local function give_coin(player)
|
||||
player.insert({name = "coin", count = 1})
|
||||
end
|
||||
|
||||
|
||||
local function on_player_mined_entity(event)
|
||||
local entity = event.entity
|
||||
local player = game.players[event.player_index]
|
||||
if not player.valid then
|
||||
return
|
||||
end
|
||||
if not entity.valid then
|
||||
return
|
||||
end
|
||||
|
||||
if math_random(1,160) == 1 then tick_tack_trap(entity.surface, entity.position) return end
|
||||
|
||||
if entity.name == "mineable-wreckage" then
|
||||
give_coin(player)
|
||||
|
||||
if math.random(1,32) == 1 then
|
||||
hidden_biter(event.entity)
|
||||
return
|
||||
end
|
||||
if math.random(1,512) == 1 then
|
||||
hidden_worm(event.entity)
|
||||
return
|
||||
end
|
||||
hidden_biter_pet(event)
|
||||
hidden_treasure(event)
|
||||
|
||||
end
|
||||
|
||||
if entity.force.name ~= "scrap" then return end
|
||||
end
|
||||
|
||||
local function on_entity_damaged(event)
|
||||
if not event.entity.valid then return end
|
||||
protect_train(event)
|
||||
end
|
||||
|
||||
local function on_entity_died(event)
|
||||
local wave_defense_table = WD.get_table()
|
||||
local entity = event.entity
|
||||
if not entity.valid then
|
||||
return
|
||||
end
|
||||
|
||||
if event.entity == global.locomotive_cargo then
|
||||
game.print("Fools! The cargo was destroyed!")
|
||||
wave_defense_table.game_lost = true
|
||||
wave_defense_table.target = nil
|
||||
global.game_reset_tick = game.tick + 1800
|
||||
for _, player in pairs(game.connected_players) do
|
||||
player.play_sound{path="utility/game_lost", volume_modifier=0.75}
|
||||
end
|
||||
event.entity.surface.spill_item_stack(event.entity.position,{name = "raw-fish", count = 512}, false)
|
||||
return
|
||||
end
|
||||
|
||||
if math_random(1,160) == 1 then tick_tack_trap(entity.surface, entity.position) return end
|
||||
|
||||
if entity.name == "mineable-wreckage" then
|
||||
if math.random(1,32) == 1 then
|
||||
hidden_biter(event.entity)
|
||||
return
|
||||
end
|
||||
if math.random(1,512) == 1 then
|
||||
hidden_worm(event.entity)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function on_research_finished(event)
|
||||
event.research.force.character_inventory_slots_bonus = game.forces.player.mining_drill_productivity_bonus * 50 -- +5 Slots / level
|
||||
local mining_speed_bonus = game.forces.player.mining_drill_productivity_bonus * 5 -- +50% speed / level
|
||||
if event.research.force.technologies["steel-axe"].researched then mining_speed_bonus = mining_speed_bonus + 0.5 end -- +50% speed for steel-axe research
|
||||
event.research.force.manual_mining_speed_modifier = mining_speed_bonus
|
||||
end
|
||||
|
||||
local on_init = function()
|
||||
Public.reset_map()
|
||||
local T = Map.Pop_info()
|
||||
T.main_caption = "S c r a p y a r d"
|
||||
T.sub_caption = " ---defend the choo---"
|
||||
T.text = table.concat({
|
||||
"The biters have catched the scent of fish in the cargo wagon.\n",
|
||||
"Guide the choo through the black mist and protect it for as long as possible!\n",
|
||||
"This will not be an easy task however,\n",
|
||||
"since their strength and numbers increase over time.\n",
|
||||
"\n",
|
||||
"Delve deep for greater treasures, but also face increased dangers.\n",
|
||||
"Mining productivity research, will overhaul your mining equipment,\n",
|
||||
"reinforcing your pickaxe as well as increasing the size of your backpack.\n",
|
||||
"\n",
|
||||
"Good luck, over and out!"
|
||||
})
|
||||
T.main_caption_color = {r = 150, g = 150, b = 0}
|
||||
T.sub_caption_color = {r = 0, g = 150, b = 0}
|
||||
game.create_force("scrap")
|
||||
game.create_force("scrap_defense")
|
||||
game.forces.player.set_friend('scrap', true)
|
||||
game.forces.enemy.set_friend('scrap', true)
|
||||
game.forces.scrap.set_friend('player', true)
|
||||
game.forces.scrap.set_friend('enemy', true)
|
||||
game.forces.scrap.share_chart = false
|
||||
end
|
||||
|
||||
|
||||
Event.on_init(on_init)
|
||||
Event.add(defines.events.on_research_finished, on_research_finished)
|
||||
Event.add(defines.events.on_entity_damaged, on_entity_damaged)
|
||||
Event.add(defines.events.on_marked_for_deconstruction, on_marked_for_deconstruction)
|
||||
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
||||
Event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
|
||||
Event.add(defines.events.on_entity_died, on_entity_died)
|
||||
Event.add(defines.events.on_player_changed_position, on_player_changed_position)
|
||||
|
||||
return Public
|
53
maps/scrapyard/market.lua
Normal file
53
maps/scrapyard/market.lua
Normal file
@ -0,0 +1,53 @@
|
||||
local Public = {}
|
||||
local math_random = math.random
|
||||
|
||||
local function shuffle(tbl)
|
||||
local size = #tbl
|
||||
for i = size, 1, -1 do
|
||||
local rand = math_random(size)
|
||||
tbl[i], tbl[rand] = tbl[rand], tbl[i]
|
||||
end
|
||||
return tbl
|
||||
end
|
||||
|
||||
function Public.secret_shop(pos, surface)
|
||||
local secret_market_items = {
|
||||
{price = {{"coin", math_random(30,60)}}, offer = {type = 'give-item', item = 'construction-robot'}},
|
||||
{price = {{"coin", math_random(100,200)}}, offer = {type = 'give-item', item = 'loader'}},
|
||||
{price = {{"coin", math_random(200,300)}}, offer = {type = 'give-item', item = 'fast-loader'}},
|
||||
{price = {{"coin", math_random(300,500)}}, offer = {type = 'give-item', item = 'express-loader'}},
|
||||
{price = {{"coin", math_random(100,200)}}, offer = {type = 'give-item', item = 'locomotive'}},
|
||||
{price = {{"coin", math_random(75,150)}}, offer = {type = 'give-item', item = 'cargo-wagon'}},
|
||||
{price = {{"coin", math_random(2,3)}}, offer = {type = 'give-item', item = 'rail'}},
|
||||
{price = {{"coin", math_random(4,12)}}, offer = {type = 'give-item', item = 'small-lamp'}},
|
||||
{price = {{"coin", math_random(80,160)}}, offer = {type = 'give-item', item = 'car'}},
|
||||
{price = {{"coin", math_random(300,600)}}, offer = {type = 'give-item', item = 'electric-furnace'}},
|
||||
{price = {{"coin", math_random(80,160)}}, offer = {type = 'give-item', item = 'effectivity-module'}},
|
||||
{price = {{"coin", math_random(80,160)}}, offer = {type = 'give-item', item = 'productivity-module'}},
|
||||
{price = {{"coin", math_random(80,160)}}, offer = {type = 'give-item', item = 'speed-module'}},
|
||||
|
||||
{price = {{"coin", math_random(5,10)}}, offer = {type = 'give-item', item = 'wood', count = 50}},
|
||||
{price = {{"coin", math_random(5,10)}}, offer = {type = 'give-item', item = 'iron-ore', count = 50}},
|
||||
{price = {{"coin", math_random(5,10)}}, offer = {type = 'give-item', item = 'copper-ore', count = 50}},
|
||||
{price = {{"coin", math_random(5,10)}}, offer = {type = 'give-item', item = 'stone', count = 50}},
|
||||
{price = {{"coin", math_random(5,10)}}, offer = {type = 'give-item', item = 'coal', count = 50}},
|
||||
{price = {{"coin", math_random(8,16)}}, offer = {type = 'give-item', item = 'uranium-ore', count = 50}},
|
||||
|
||||
{price = {{'wood', math_random(10,12)}}, offer = {type = 'give-item', item = "coin"}},
|
||||
{price = {{'iron-ore', math_random(10,12)}}, offer = {type = 'give-item', item = "coin"}},
|
||||
{price = {{'copper-ore', math_random(10,12)}}, offer = {type = 'give-item', item = "coin"}},
|
||||
{price = {{'stone', math_random(10,12)}}, offer = {type = 'give-item', item = "coin"}},
|
||||
{price = {{'coal', math_random(10,12)}}, offer = {type = 'give-item', item = "coin"}},
|
||||
{price = {{'uranium-ore', math_random(8,10)}}, offer = {type = 'give-item', item = "coin"}}
|
||||
}
|
||||
secret_market_items = shuffle(secret_market_items)
|
||||
|
||||
local market = surface.create_entity {name = "market", position = pos}
|
||||
market.destructible = false
|
||||
|
||||
for i = 1, math_random(6, 8), 1 do
|
||||
market.add_market_item(secret_market_items[i])
|
||||
end
|
||||
end
|
||||
|
||||
return Public
|
446
maps/scrapyard/terrain.lua
Normal file
446
maps/scrapyard/terrain.lua
Normal file
@ -0,0 +1,446 @@
|
||||
local Event = require 'utils.event'
|
||||
local Market = require 'maps.scrapyard.market'
|
||||
local create_entity_chain = require "functions.create_entity_chain"
|
||||
local create_tile_chain = require "functions.create_tile_chain"
|
||||
local simplex_noise = require 'utils.simplex_noise'.d2
|
||||
local map_functions = require "tools.map_functions"
|
||||
local shapes = require "tools.shapes"
|
||||
local Loot = require 'maps.scrapyard.loot'
|
||||
local insert = table.insert
|
||||
local math_random = math.random
|
||||
local math_floor = math.floor
|
||||
local math_abs = math.abs
|
||||
local uncover_radius = 8
|
||||
|
||||
local rock_raffle = {"sand-rock-big","sand-rock-big", "rock-big","rock-big","rock-big","rock-big","rock-big","rock-big","rock-big","rock-big","rock-huge"}
|
||||
local enemies = {"small-biter", "medium-biter", "small-spitter", "small-worm-turret", "medium-spitter", "medium-worm-turret", "big-biter", "big-spitter", "big-worm-turret", "behemoth-biter", "behemoth-spitter"}
|
||||
local scrap_buildings = {"nuclear-reactor", "centrifuge", "beacon", "chemical-plant", "assembling-machine-1", "assembling-machine-2", "assembling-machine-3", "oil-refinery", "arithmetic-combinator", "constant-combinator", "decider-combinator", "programmable-speaker", "steam-turbine", "steam-engine", "chemical-plant", "assembling-machine-1", "assembling-machine-2", "assembling-machine-3", "oil-refinery", "arithmetic-combinator", "constant-combinator", "decider-combinator", "programmable-speaker", "steam-turbine", "steam-engine"}
|
||||
|
||||
local Public = {}
|
||||
|
||||
local function get_noise(name, pos)
|
||||
local seed = game.surfaces[global.active_surface_index].map_gen_settings.seed
|
||||
local noise_seed_add = 25000
|
||||
seed = seed + noise_seed_add
|
||||
if name == 1 then
|
||||
local noise = {}
|
||||
noise[1] = simplex_noise(pos.x * 0.005, pos.y * 0.005, seed)
|
||||
seed = seed + noise_seed_add
|
||||
noise[2] = simplex_noise(pos.x * 0.01, pos.y * 0.01, seed)
|
||||
seed = seed + noise_seed_add
|
||||
noise[3] = simplex_noise(pos.x * 0.05, pos.y * 0.05, seed)
|
||||
seed = seed + noise_seed_add
|
||||
noise[4] = simplex_noise(pos.x * 0.1, pos.y * 0.1, seed)
|
||||
local sum = noise[1] + noise[2] * 0.35 + noise[3] * 0.23 + noise[4] * 0.11
|
||||
return sum
|
||||
elseif name == 2 then
|
||||
local noise = {}
|
||||
noise[1] = simplex_noise(pos.x * 0.01, pos.y * 0.01, seed)
|
||||
local sum = noise[1]
|
||||
return sum
|
||||
elseif name == 3 then
|
||||
local noise = {}
|
||||
noise[1] = simplex_noise(pos.x * 0.05, pos.y * 0.05, seed)
|
||||
local sum = noise[1]
|
||||
return sum
|
||||
elseif name == 4 then
|
||||
local noise = {}
|
||||
noise[1] = simplex_noise(pos.x * 0.1, pos.y * 0.1, seed)
|
||||
local sum = noise[1]
|
||||
return sum
|
||||
elseif name == 5 then
|
||||
local noise = {}
|
||||
noise[1] = simplex_noise(pos.x * 0.045, pos.y * 0.045, seed)
|
||||
local sum = noise[1]
|
||||
return sum
|
||||
elseif name == 6 then
|
||||
local noise = {}
|
||||
noise[1] = simplex_noise(pos.x * 0.02, pos.y * 0.02, seed)
|
||||
local sum = noise[1]
|
||||
return sum
|
||||
elseif name == 7 then
|
||||
local noise = {}
|
||||
noise[1] = simplex_noise(pos.x * 0.005, pos.y * 0.005, seed)
|
||||
seed = seed + noise_seed_add
|
||||
noise[2] = simplex_noise(pos.x * 0.01, pos.y * 0.01, seed)
|
||||
seed = seed + noise_seed_add
|
||||
noise[3] = simplex_noise(pos.x * 0.05, pos.y * 0.05, seed)
|
||||
local sum = noise[1] + noise[2] + noise[3]
|
||||
return sum
|
||||
end
|
||||
end
|
||||
|
||||
local function place_random_scrap_entity(surface, position)
|
||||
local r = math_random(1, 100)
|
||||
if r < 15 then
|
||||
local e = surface.create_entity({name = scrap_buildings[math_random(1, #scrap_buildings)], position = position, force = "scrap"})
|
||||
if e.name == "nuclear-reactor" then
|
||||
create_entity_chain(surface, {name = "heat-pipe", position = position, force = "player"}, math_random(16,32), 25)
|
||||
end
|
||||
if e.name == "chemical-plant" or e.name == "steam-turbine" or e.name == "steam-engine" or e.name == "oil-refinery" then
|
||||
create_entity_chain(surface, {name = "pipe", position = position, force = "player"}, math_random(8,16), 25)
|
||||
end
|
||||
e.active = false
|
||||
return
|
||||
end
|
||||
if r < 100 then
|
||||
local e = surface.create_entity({name = "gun-turret", position = position, force = "scrap_defense"})
|
||||
e.insert({name = "piercing-rounds-magazine", count = math_random(8, 128)})
|
||||
return
|
||||
end
|
||||
|
||||
local e = surface.create_entity({name = "storage-tank", position = position, force = "scrap", direction = math_random(0, 3)})
|
||||
local fluids = {"crude-oil", "lubricant", "heavy-oil", "light-oil", "petroleum-gas", "sulfuric-acid", "water"}
|
||||
e.fluidbox[1] = {name = fluids[math_random(1, #fluids)], amount = math_random(15000, 25000)}
|
||||
create_entity_chain(surface, {name = "pipe", position = position, force = "player"}, math_random(6,8), 1)
|
||||
create_entity_chain(surface, {name = "pipe", position = position, force = "player"}, math_random(6,8), 1)
|
||||
create_entity_chain(surface, {name = "pipe", position = position, force = "player"}, math_random(15,30), 80)
|
||||
end
|
||||
|
||||
local function create_inner_content(surface, pos, noise)
|
||||
if math_random(1, 90000) == 1 then
|
||||
if noise < 0.3 or noise > -0.3 then
|
||||
map_functions.draw_noise_entity_ring(surface, pos, "laser-turret", "scrap_defense", 0, 2)
|
||||
map_functions.draw_noise_entity_ring(surface, pos, "accumulator", "scrap_defense", 2, 3)
|
||||
map_functions.draw_noise_entity_ring(surface, pos, "substation", "scrap_defense", 3, 4)
|
||||
map_functions.draw_noise_entity_ring(surface, pos, "solar-panel", "scrap_defense", 4, 6)
|
||||
map_functions.draw_noise_entity_ring(surface, pos, "stone-wall", "scrap_defense", 6, 7)
|
||||
|
||||
create_tile_chain(surface, {name = "concrete", position = pos}, math_random(16, 32), 50)
|
||||
create_tile_chain(surface, {name = "concrete", position = pos}, math_random(16, 32), 50)
|
||||
create_tile_chain(surface, {name = "stone-path", position = pos}, math_random(16, 32), 50)
|
||||
create_tile_chain(surface, {name = "stone-path", position = pos}, math_random(16, 32), 50)
|
||||
end
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local function get_noise_tile(pos)
|
||||
local noise = get_noise(1, pos)
|
||||
local tile_name
|
||||
|
||||
if noise > 0 then
|
||||
tile_name = "dirt-1"
|
||||
if noise > 0.5 then
|
||||
tile_name = "dirt-2"
|
||||
end
|
||||
else
|
||||
tile_name = "dirt-3"
|
||||
end
|
||||
|
||||
local noise2 = get_noise(2, pos)
|
||||
if noise2 > 0.71 then
|
||||
tile_name = "water"
|
||||
if noise > 0.78 then
|
||||
tile_name = "deepwater"
|
||||
end
|
||||
end
|
||||
|
||||
if noise < -0.76 then
|
||||
tile_name = "water-green"
|
||||
end
|
||||
|
||||
return tile_name
|
||||
end
|
||||
|
||||
local function get_entity(pos)
|
||||
local noise = get_noise(5, pos)
|
||||
local entity_name = false
|
||||
if noise > 0 then
|
||||
if math_random(1, 50) ~= 1 then
|
||||
|
||||
if noise > 0.6 then
|
||||
entity_name = rock_raffle[math_random(1, #rock_raffle)]
|
||||
if math_random(1, 24) == 1 then
|
||||
if pos.x > 32 or pos.x < -32 or pos.y > 32 or pos.y < -32 then
|
||||
local e = math.ceil(game.forces.enemy.evolution_factor*10)
|
||||
if e < 1 then e = 1 end
|
||||
entity_name = enemies[e][math_random(1, #enemies[e])]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
if math_random(1, 2048) == 1 then
|
||||
entity_name = "market"
|
||||
end
|
||||
|
||||
if math_random(1, 128) == 1 then
|
||||
local noise_spawners = get_noise(6, pos)
|
||||
if noise_spawners > 0.25 and pos.x^2 + pos.y^2 > 3000 then
|
||||
entity_name = "biter-spawner"
|
||||
if math_random(1,5) == 1 then
|
||||
entity_name = "spitter-spawner"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return entity_name
|
||||
end
|
||||
|
||||
function Public.reveal(player)
|
||||
local position = player.position
|
||||
local surface = player.surface
|
||||
local circles = shapes.circles
|
||||
local reveal_area = {}
|
||||
local tiles = {}
|
||||
local fishes = {}
|
||||
local entities = {}
|
||||
for r = uncover_radius -1, uncover_radius, 1 do
|
||||
for _, v in pairs(circles[r]) do
|
||||
local pos = {x = position.x + v.x, y = position.y + v.y}
|
||||
if surface.get_tile(pos).name == "out-of-map" then
|
||||
local rivers = get_noise(7, pos)
|
||||
local noise = get_noise(1, pos)
|
||||
local noise2 = get_noise(2, pos)
|
||||
local distance_to_center = math.sqrt(pos.x^2 + pos.y^2)
|
||||
insert(tiles, {name = "dirt-" .. math_random(1, 7), position = pos})
|
||||
if distance_to_center < 40 then
|
||||
insert(tiles, {name = "dirt-" .. math_random(1, 7), position = pos})
|
||||
else
|
||||
if noise > 0.43 or noise < -0.43 then
|
||||
if math_random(1,4) ~= 1 then
|
||||
insert(entities, {name = "mineable-wreckage", position = pos})
|
||||
else
|
||||
if math_random(1,512) == 1 then
|
||||
Loot.create_loot(surface, pos, "wooden-chest")
|
||||
else
|
||||
if math_random(1,512) == 1 then
|
||||
place_random_scrap_entity(surface, pos)
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif noise2 > 0.25 or noise2 < -0.25 then
|
||||
create_inner_content(surface, pos, noise)
|
||||
local tile_name = get_noise_tile(pos)
|
||||
insert(tiles, {name = tile_name, position = pos})
|
||||
if rivers < -0.3 then insert(tiles, {name = "water-shallow", position = pos}) end
|
||||
if tile_name == "water" or tile_name == "deepwater" or tile_name == "water-green" then
|
||||
if math_random(1, 24) == 1 then insert(fishes, pos) end
|
||||
else
|
||||
local entity = get_entity(pos)
|
||||
if entity then
|
||||
if entity == "market" then
|
||||
local area = {{pos.x - 64, pos.y - 64}, {pos.x + 64, pos.y + 64}}
|
||||
if surface.count_entities_filtered({name = "market", area = area}) == 0 then
|
||||
Market.secret_shop(pos, surface)
|
||||
end
|
||||
elseif math_floor(distance_to_center) > tonumber(128) then
|
||||
if entity == "biter-spawner" or entity == "spitter-spawner" then
|
||||
local area = {{pos.x - 16, pos.y - 16}, {pos.x + 16, pos.y + 16}}
|
||||
if surface.count_entities_filtered({name = "biter-spawner", area = area}) == 0 then
|
||||
insert(entities, {name = entity, position = pos})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if #tiles > 0 then
|
||||
surface.set_tiles(tiles, true)
|
||||
end
|
||||
for _, entity in pairs(entities) do
|
||||
surface.create_entity(entity)
|
||||
end
|
||||
for _, pos in pairs(reveal_area) do
|
||||
Public.reveal(surface, pos, 1, 16)
|
||||
end
|
||||
for _, fish in pairs(fishes) do
|
||||
surface.create_entity({name = "fish", position = fish})
|
||||
end
|
||||
end
|
||||
|
||||
local function generate_spawn_area(surface, position_left_top)
|
||||
if position_left_top.x > 32 then return end
|
||||
if position_left_top.y > 32 then return end
|
||||
if position_left_top.x < -32 then return end
|
||||
if position_left_top.y < -32 then return end
|
||||
|
||||
local entities = {}
|
||||
local tiles = {}
|
||||
local circles = shapes.circles
|
||||
|
||||
for r = 1, 12 do
|
||||
for k, v in pairs(circles[r]) do
|
||||
local t_insert = false
|
||||
local pos = {x = position_left_top.x + v.x, y = position_left_top.y + v.y}
|
||||
if pos.x > -15 and pos.x < 15 and pos.y > -15 and pos.y < 15 then
|
||||
t_insert = "stone-path"
|
||||
end
|
||||
if t_insert then
|
||||
insert(tiles, {name = t_insert, position = pos})
|
||||
end
|
||||
end
|
||||
end
|
||||
surface.set_tiles(tiles, true)
|
||||
|
||||
for _, entity in pairs(entities) do
|
||||
surface.create_entity(entity)
|
||||
end
|
||||
end
|
||||
|
||||
local function is_out_of_map(p)
|
||||
if p.x < 96 and p.x >= -96 then return end
|
||||
if p.y * 0.5 >= math_abs(p.x) then return end
|
||||
if p.y * -0.5 > math_abs(p.x) then return end
|
||||
return true
|
||||
end
|
||||
|
||||
local function border_chunk(surface, left_top)
|
||||
for x = 0, 31, 1 do
|
||||
for y = 0, 31, 1 do
|
||||
local pos = {x = left_top.x + x, y = left_top.y + y}
|
||||
if not is_out_of_map(pos) then
|
||||
if math_random(1, pos.y + 23) == 1 then
|
||||
surface.create_entity{
|
||||
name = "gun-turret-remnants", position = pos, amount = math_random(1, 1 + math.ceil(20 - y / 2))
|
||||
}
|
||||
end
|
||||
if math_random(1, pos.y + 2) == 1 then
|
||||
surface.create_decoratives{
|
||||
check_collision=false,
|
||||
decoratives={
|
||||
{name = "rock-small", position = pos, amount = math_random(1, 1 + math.ceil(20 - y / 2))}
|
||||
}
|
||||
}
|
||||
end
|
||||
if math_random(1, pos.y + 2) == 1 then
|
||||
surface.create_decoratives{
|
||||
check_collision=false,
|
||||
decoratives={
|
||||
{name = "rock-tiny", position = pos, amount = math_random(1, 1 + math.ceil(20 - y / 2))}
|
||||
}
|
||||
}
|
||||
end
|
||||
if math_random(1, pos.y + 22) == 1 then
|
||||
surface.create_entity{
|
||||
name = "wall-remnants", position = pos, amount = math_random(1, 1 + math.ceil(20 - y / 2))
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for _, e in pairs(surface.find_entities_filtered({area = {{left_top.x, left_top.y},{left_top.x + 32, left_top.y + 32}}, type = "cliff"})) do e.destroy() end
|
||||
end
|
||||
|
||||
local function replace_water(surface, left_top)
|
||||
for x = 0, 31, 1 do
|
||||
for y = 0, 31, 1 do
|
||||
local p = {x = left_top.x + x, y = left_top.y + y}
|
||||
if surface.get_tile(p).collides_with("resource-layer") then
|
||||
surface.set_tiles({{name = "dirt-" .. math_random(1,5), position = p}}, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function process(surface, left_top)
|
||||
local position_left_top = left_top
|
||||
local tiles = {}
|
||||
for x = 0, 31, 1 do
|
||||
for y = 0, 31, 1 do
|
||||
local tile_to_insert = "out-of-map"
|
||||
local pos = {x = position_left_top.x + x, y = position_left_top.y + y}
|
||||
local tile_name = surface.get_tile(pos).name
|
||||
if tile_name ~= "stone-path" then
|
||||
insert(tiles, {name = tile_to_insert, position = pos})
|
||||
end
|
||||
end
|
||||
end
|
||||
surface.set_tiles(tiles, true)
|
||||
for _, e in pairs (surface.find_entities_filtered({area = {{-50, -50},{50, 50}}})) do
|
||||
local distance_to_center = math.sqrt(e.position.x^2 + e.position.y^2)
|
||||
if e.valid then
|
||||
if distance_to_center < 8 and e.name == "mineable-wreckage" and math_random(1,5) ~= 1 then e.destroy() end
|
||||
end
|
||||
if e.valid then
|
||||
if distance_to_center < 30 and e.name == "gun-turret" then e.destroy() end
|
||||
end
|
||||
end
|
||||
if global.spawn_generated then return end
|
||||
if left_top.x < 96 then return end
|
||||
map_functions.draw_rainbow_patch_v2({x = 0, y = 0}, surface, 12, 2500)
|
||||
global.spawn_generated = true
|
||||
local decorative_names = {}
|
||||
for k,v in pairs(game.decorative_prototypes) do
|
||||
if v.autoplace_specification then
|
||||
decorative_names[#decorative_names+1] = k
|
||||
end
|
||||
end
|
||||
surface.regenerate_decorative(decorative_names, {position_left_top})
|
||||
|
||||
if math_random(1, 16) ~= 1 then return end
|
||||
local pos = {x = position_left_top.x * 32 + math_random(1,32), y = position_left_top.y * 32 + math_random(1,32)}
|
||||
local noise = get_noise(1, pos)
|
||||
if noise > 0.4 or noise < -0.4 then return end
|
||||
local distance_to_center = math.sqrt(pos.x^2 + pos.y^2)
|
||||
local size = 7 + math.floor(distance_to_center * 0.0075)
|
||||
if size > 20 then size = 20 end
|
||||
local amount = 500 + distance_to_center * 2
|
||||
map_functions.draw_rainbow_patch_v2(pos, surface, size, amount)
|
||||
end
|
||||
|
||||
local function out_of_map_area(event)
|
||||
local surface = event.surface
|
||||
local left_top = event.area.left_top
|
||||
for x = -1, 32, 1 do
|
||||
for y = -1, 32, 1 do
|
||||
local p = {x = left_top.x + x, y = left_top.y + y}
|
||||
if is_out_of_map(p) then
|
||||
surface.set_tiles({{name = "out-of-map", position = p}}, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function biter_chunk(surface, left_top)
|
||||
local tile_positions = {}
|
||||
for x = 0, 31, 1 do
|
||||
for y = 0, 31, 1 do
|
||||
local p = {x = left_top.x + x, y = left_top.y + y}
|
||||
tile_positions[#tile_positions + 1] = p
|
||||
end
|
||||
end
|
||||
|
||||
for i = 1, 1, 1 do
|
||||
local position = surface.find_non_colliding_position("biter-spawner", tile_positions[math_random(1, #tile_positions)], 16, 2)
|
||||
if position then
|
||||
local e = surface.create_entity({name = enemies[math_random(1, #enemies)], position = position, force = "enemy"})
|
||||
e.destructible = false
|
||||
e.active = false
|
||||
end
|
||||
end
|
||||
|
||||
for i = 1, 3, 1 do
|
||||
local position = surface.find_non_colliding_position("big-worm-turret", tile_positions[math_random(1, #tile_positions)], 16, 2)
|
||||
if position then
|
||||
local e = surface.create_entity({name = "big-worm-turret", position = position, force = "enemy"})
|
||||
e.destructible = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function on_chunk_generated(event)
|
||||
if event.surface.index == 1 then return end
|
||||
local surface = event.surface
|
||||
local left_top = event.area.left_top
|
||||
if surface.name ~= event.surface.name then return end
|
||||
local position_left_top = event.area.left_top
|
||||
|
||||
generate_spawn_area(surface, position_left_top)
|
||||
if left_top.y >= 0 then replace_water(surface, left_top) end
|
||||
if left_top.y > 210 then biter_chunk(surface, left_top) end
|
||||
if left_top.y >= 0 then border_chunk(surface, left_top) end
|
||||
if left_top.y < 0 then process(surface, left_top) end
|
||||
out_of_map_area(event)
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_chunk_generated, on_chunk_generated)
|
||||
|
||||
return Public
|
144
modules/mineable_wreckage_yields_ores.lua
Normal file
144
modules/mineable_wreckage_yields_ores.lua
Normal file
@ -0,0 +1,144 @@
|
||||
local Event = require 'utils.event'
|
||||
local max_spill = 40
|
||||
local math_random = math.random
|
||||
local math_floor = math.floor
|
||||
local math_sqrt = math.sqrt
|
||||
local insert = table.insert
|
||||
|
||||
local scrap_yeild = {
|
||||
["mineable-wreckage"] = 1
|
||||
}
|
||||
|
||||
local weights = {
|
||||
{"iron-ore", 25},
|
||||
{"copper-ore",17},
|
||||
{"coal",13},
|
||||
{"stone",10},
|
||||
{"uranium-ore",2}
|
||||
}
|
||||
|
||||
local texts = {
|
||||
["iron-ore"] = {"Iron ore", {r = 200, g = 200, b = 180}},
|
||||
["copper-ore"] = {"Copper ore", {r = 221, g = 133, b = 6}},
|
||||
["uranium-ore"] = {"Uranium ore", {r= 50, g= 250, b= 50}},
|
||||
["coal"] = {"Coal", {r = 0, g = 0, b = 0}},
|
||||
["stone"] = {"Stone", {r = 200, g = 160, b = 30}},
|
||||
}
|
||||
|
||||
local particles = {
|
||||
["iron-ore"] = "iron-ore-particle",
|
||||
["copper-ore"] = "copper-ore-particle",
|
||||
["uranium-ore"] = "coal-particle",
|
||||
["coal"] = "coal-particle",
|
||||
["stone"] = "stone-particle"
|
||||
}
|
||||
|
||||
local ore_raffle = {}
|
||||
for _, t in pairs (weights) do
|
||||
for x = 1, t[2], 1 do
|
||||
insert(ore_raffle, t[1])
|
||||
end
|
||||
end
|
||||
|
||||
local function create_particles(surface, name, position, amount, cause_position)
|
||||
local direction_mod = (-100 + math_random(0,200)) * 0.0004
|
||||
local direction_mod_2 = (-100 + math_random(0,200)) * 0.0004
|
||||
|
||||
if cause_position then
|
||||
direction_mod = (cause_position.x - position.x) * 0.025
|
||||
direction_mod_2 = (cause_position.y - position.y) * 0.025
|
||||
end
|
||||
|
||||
for i = 1, amount, 1 do
|
||||
local m = math_random(4, 10)
|
||||
local m2 = m * 0.005
|
||||
|
||||
surface.create_entity({
|
||||
name = name,
|
||||
position = position,
|
||||
frame_speed = 1,
|
||||
vertical_speed = 0.130,
|
||||
height = 0,
|
||||
movement = {
|
||||
(m2 - (math_random(0, m) * 0.01)) + direction_mod,
|
||||
(m2 - (math_random(0, m) * 0.01)) + direction_mod_2
|
||||
}
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
local function get_amount(entity)
|
||||
local distance_to_center = math_floor(math_sqrt(entity.position.x ^ 2 + entity.position.y ^ 2))
|
||||
|
||||
local distance_modifier = 0.25
|
||||
local base_amount = 35
|
||||
local maximum_amount = 100
|
||||
if global.rocks_yield_ore_distance_modifier then distance_modifier = global.rocks_yield_ore_distance_modifier end
|
||||
if global.rocks_yield_ore_base_amount then base_amount = global.rocks_yield_ore_base_amount end
|
||||
if global.rocks_yield_ore_maximum_amount then maximum_amount = global.rocks_yield_ore_maximum_amount end
|
||||
|
||||
local amount = base_amount + (distance_to_center * distance_modifier)
|
||||
if amount > maximum_amount then amount = maximum_amount end
|
||||
|
||||
local m = (70 + math_random(0, 60)) * 0.01
|
||||
|
||||
amount = math_floor(amount * scrap_yeild[entity.name] * m)
|
||||
if amount < 1 then amount = 1 end
|
||||
|
||||
return amount
|
||||
end
|
||||
|
||||
local function on_player_mined_entity(event)
|
||||
local entity = event.entity
|
||||
if not entity.valid then return end
|
||||
if not scrap_yeild[entity.name] then return end
|
||||
|
||||
event.buffer.clear()
|
||||
|
||||
local ore = ore_raffle[math_random(1, #ore_raffle)]
|
||||
local player = game.players[event.player_index]
|
||||
local count = get_amount(entity)
|
||||
local position = {x = entity.position.x, y = entity.position.y}
|
||||
|
||||
player.surface.create_entity({name = "flying-text", position = position, text = "+" .. count .. " [img=item/" .. ore .. "]", color = {r = 200, g = 160, b = 30}})
|
||||
create_particles(player.surface, particles[ore], position, 64, {x = player.position.x, y = player.position.y})
|
||||
|
||||
--entity.destroy()
|
||||
|
||||
if count > max_spill then
|
||||
player.surface.spill_item_stack(position,{name = ore, count = max_spill}, true)
|
||||
count = count - max_spill
|
||||
local inserted_count = player.insert({name = ore, count = count})
|
||||
count = count - inserted_count
|
||||
if count > 0 then
|
||||
player.surface.spill_item_stack(position,{name = ore, count = count}, true)
|
||||
end
|
||||
else
|
||||
player.surface.spill_item_stack(position,{name = ore, count = count}, true)
|
||||
end
|
||||
end
|
||||
|
||||
local function on_entity_died(event)
|
||||
local entity = event.entity
|
||||
if not entity.valid then return end
|
||||
if not scrap_yeild[entity.name] then return end
|
||||
|
||||
local surface = entity.surface
|
||||
local ore = ore_raffle[math_random(1, #ore_raffle)]
|
||||
local pos = {entity.position.x, entity.position.y}
|
||||
create_particles(surface, particles[ore], pos, 16, false)
|
||||
|
||||
if event.cause then
|
||||
if event.cause.valid then
|
||||
if event.cause.force.index == 2 or event.cause.force.index == 3 then
|
||||
entity.destroy()
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
entity.destroy()
|
||||
surface.spill_item_stack(pos,{name = ore, count = math_random(8,12)}, true)
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_entity_died, on_entity_died)
|
||||
Event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
|
Loading…
Reference in New Issue
Block a user