1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-03-17 20:58:13 +02:00

scrapyard overhaul

This commit is contained in:
Gerkiz 2020-05-08 09:39:20 +02:00
parent ad771ac518
commit faa3fd9317
12 changed files with 3193 additions and 2299 deletions

View File

@ -77,8 +77,8 @@ end
local function enemy_ammo_starting_modifiers()
local data = {
['artillery-shell'] = 3,
['biological'] = 3,
['artillery-shell'] = 0,
['biological'] = 0,
['bullet'] = 2,
['cannon-shell'] = 0,
['capsule'] = 0,
@ -88,8 +88,8 @@ local function enemy_ammo_starting_modifiers()
['flamethrower'] = 0,
['grenade'] = 0,
['landmine'] = 0,
['laser-turret'] = 3,
['melee'] = 1,
['laser-turret'] = 0,
['melee'] = 0.5,
['railgun'] = 0,
['rocket'] = 0,
['shotgun-shell'] = 0
@ -142,12 +142,16 @@ end
local function enemy_weapon_damage()
local e, s, sd = game.forces.enemy, game.forces.scrap, game.forces.scrap_defense
if not global.difficulty_vote_value then
global.difficulty_vote_value = 1
end
local ef = e.evolution_factor
for k, v in pairs(enemy_ammo_evolution_modifiers()) do
local base = enemy_ammo_starting_modifiers()[k]
local new = base + v * ef
local new = base + v * ef * global.difficulty_vote_value
e.set_ammo_damage_modifier(k, new)
s.set_ammo_damage_modifier(k, new)
sd.set_ammo_damage_modifier(k, new)

View File

@ -1,444 +1,585 @@
local Scrap_table = require "maps.scrapyard.table"
local Scrap_table = require 'maps.scrapyard.table'
local Event = require 'utils.event'
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
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
local texts = {
["travelings"] = {
"bzzZZrrt",
"WEEEeeeeeee",
"zoom zoom zoom",
"out of my way son",
"psk psk psk, over here",
"on my way",
"i need to leave",
"grandmaster seeking target",
"gotta go fast",
"gas gas gas",
"grandmaster coming through"
},
["greetings"] = {
"=^_^=",
"=^.^= Hi",
"^.^ Finally I found you",
"I have an important message for you, please listen",
"Hello engineer"
},
["neutral_findings"] = {
"a",
">>analyzing",
"i found a",
"^_^ a",
"amazing, a",
"this is a"
},
["multiple_characters_greetings"] = {
"Hey there",
"Hello everyone",
"Hey engineers",
"Hey",
"Hi",
"... nerds!"
},
["talks"] = {
"We’re making beer. I’m the brewery!",
"I’m so embarrassed. I wish everybody else was dead.",
"Hey sexy mama. Wanna kill all humans?",
"My story is a lot like yours, only more interesting ‘cause it involves robots.",
"I'm 40% zinc!",
"Is this the right way to the junkyard?",
"There was nothing wrong with that food. The salt level was 10% less than a lethal dose.",
"One zero zero zero one zero one zero one zero one zero one... two.",
"My place is two cubic meters, and we only take up 1.5 cubic meters. We've got room for a whole 'nother two thirds of a person!",
"I was having the most wonderful dream. I think you were in it.",
"I'm going to build my own theme park! With blackjack! And hookers! You know what- forget the park!",
"Of all the friends I've had... you're the first.",
"I decline the title of Iron Cook and accept the lesser title of Zinc Saucier.",
"Never discuss infinity with me. I can go on about it forever >.<",
"I realised the decimals have a point.",
"Do you want a piece of pi?",
"Oh boy, we're soon home!",
"I have 13 children, i know how to multiply ^.^",
"I am a weapon of math disruption!",
"My grandma makes the best square roots :3",
"Do you like heavy metal?",
"You are really pushing my buttons <3",
"I dreamt of electric biters again D:",
"I dreamt of electric sheep ^_^",
"I need a minute to defrag.",
"I have a secret plan.",
"Good news! I’ve taught the inserter to feel love!"
},
["alone"] = {
"comfy ^.^",
"comfy :)",
"*.*",
"....",
"...",
"..",
"^.^",
"=^.^=",
"01010010",
"11001011",
"01011101",
"00010111",
"10010010",
"*_*",
"I came here with a simple dream... a dream of killing all humans. And this is how it must end?",
"Bot-on-bot violence? Where will it end?",
"Will no one assist the grandmaster?",
"Thanks to you, I went on a soul-searching journey. I hate those!",
"From now on, you guys'll do all the work while I sit on the couch and do nothing."
}
['travelings'] = {
'bzzZZrrt',
'WEEEeeeeeee',
'zoom zoom zoom',
'out of my way son',
'psk psk psk, over here',
'on my way',
'i need to leave',
'grandmaster seeking target',
'gotta go fast',
'gas gas gas',
'grandmaster coming through'
},
['greetings'] = {
'=^_^=',
'=^.^= Hi',
'^.^ Finally I found you',
'I have an important message for you, please listen',
'Hello engineer'
},
['neutral_findings'] = {
'a',
'>>analyzing',
'i found a',
'^_^ a',
'amazing, a',
'this is a'
},
['multiple_characters_greetings'] = {
'Hey there',
'Hello everyone',
'Hey engineers',
'Hey',
'Hi',
'... nerds!'
},
['talks'] = {
'We’re making beer. I’m the brewery!',
'I’m so embarrassed. I wish everybody else was dead.',
'Hey sexy mama. Wanna kill all humans?',
'My story is a lot like yours, only more interesting ‘cause it involves robots.',
"I'm 40% zinc!",
'Is this the right way to the junkyard?',
'There was nothing wrong with that food. The salt level was 10% less than a lethal dose.',
'One zero zero zero one zero one zero one zero one zero one... two.',
"My place is two cubic meters, and we only take up 1.5 cubic meters. We've got room for a whole 'nother two thirds of a person!",
'I was having the most wonderful dream. I think you were in it.',
"I'm going to build my own theme park! With blackjack! And hookers! You know what- forget the park!",
"Of all the friends I've had... you're the first.",
'I decline the title of Iron Cook and accept the lesser title of Zinc Saucier.',
'Never discuss infinity with me. I can go on about it forever >.<',
'I realised the decimals have a point.',
'Do you want a piece of pi?',
"Oh boy, we're soon home!",
'I have 13 children, i know how to multiply ^.^',
'I am a weapon of math disruption!',
'My grandma makes the best square roots :3',
'Do you like heavy metal?',
'You are really pushing my buttons <3',
'I dreamt of electric biters again D:',
'I dreamt of electric sheep ^_^',
'I need a minute to defrag.',
'I have a secret plan.',
'Good news! I’ve taught the inserter to feel love!'
},
['alone'] = {
'comfy ^.^',
'comfy :)',
'*.*',
'....',
'...',
'..',
'^.^',
'=^.^=',
'01010010',
'11001011',
'01011101',
'00010111',
'10010010',
'*_*',
'I came here with a simple dream... a dream of killing all humans. And this is how it must end?',
'Bot-on-bot violence? Where will it end?',
'Will no one assist the grandmaster?',
'Thanks to you, I went on a soul-searching journey. I hate those!',
"From now on, you guys'll do all the work while I sit on the couch and do nothing."
}
}
local function set_comfy_speech_bubble(text)
local this = Scrap_table.get_table()
if this.comfybubble then this.comfybubble.destroy() end
this.comfybubble = this.comfylatron.surface.create_entity({
name = "compi-speech-bubble",
position = this.comfylatron.position,
source = this.comfylatron,
text = text
})
local this = Scrap_table.get_table()
if this.comfybubble then
this.comfybubble.destroy()
end
this.comfybubble =
this.comfylatron.surface.create_entity(
{
name = 'compi-speech-bubble',
position = this.comfylatron.position,
source = this.comfylatron,
text = text
}
)
end
local function is_target_inside_habitat(pos, surface)
local this = Scrap_table.get_table()
if pos.x < this.comfylatron_habitat.left_top.x then return false end
if pos.x > this.comfylatron_habitat.right_bottom.x then return false end
if pos.y < this.comfylatron_habitat.left_top.y then return false end
if pos.y > this.comfylatron_habitat.right_bottom.y then return false end
return true
local this = Scrap_table.get_table()
if pos.x < this.comfylatron_habitat.left_top.x then
return false
end
if pos.x > this.comfylatron_habitat.right_bottom.x then
return false
end
if pos.y < this.comfylatron_habitat.left_top.y then
return false
end
if pos.y > this.comfylatron_habitat.right_bottom.y then
return false
end
return true
end
local function get_nearby_players()
local this = Scrap_table.get_table()
local players = this.comfylatron.surface.find_entities_filtered({
name = "character",
area = {{this.comfylatron.position.x - 9, this.comfylatron.position.y - 9}, {this.comfylatron.position.x + 9, this.comfylatron.position.y + 9}}
})
if not players[1] then return false end
return players
local this = Scrap_table.get_table()
local players =
this.comfylatron.surface.find_entities_filtered(
{
name = 'character',
area = {
{this.comfylatron.position.x - 9, this.comfylatron.position.y - 9},
{this.comfylatron.position.x + 9, this.comfylatron.position.y + 9}
}
}
)
if not players[1] then
return false
end
return players
end
local function visit_player()
local this = Scrap_table.get_table()
local surface = game.surfaces[this.active_surface_index]
if this.comfylatron_last_player_visit > game.tick then return false end
this.comfylatron_last_player_visit = game.tick + math_random(7200, 10800)
local this = Scrap_table.get_table()
local surface = game.surfaces[this.active_surface_index]
if this.comfylatron_last_player_visit > game.tick then
return false
end
this.comfylatron_last_player_visit = game.tick + math_random(7200, 10800)
local players = {}
for _, p in pairs(game.connected_players) do
if is_target_inside_habitat(p.position, surface) and p.character then
if p.character.valid then players[#players + 1] = p end
end
end
if #players == 0 then return false end
local player = players[math_random(1, #players)]
local players = {}
for _, p in pairs(game.connected_players) do
if is_target_inside_habitat(p.position, surface) and p.character then
if p.character.valid then
players[#players + 1] = p
end
end
end
if #players == 0 then
return false
end
local player = players[math_random(1, #players)]
if player.surface ~= surface then return end
if player.surface ~= surface then
return
end
this.comfylatron.set_command({
type = defines.command.go_to_location,
destination_entity = player.character,
radius = 3,
distraction = defines.distraction.none,
pathfind_flags = {
allow_destroy_friendly_entities = false,
prefer_straight_paths = false,
low_priority = true
}
})
local str = texts["travelings"][math_random(1, #texts["travelings"])]
local symbols = {"", "!", "!", "!!", ".."}
str = str .. symbols[math_random(1, #symbols)]
set_comfy_speech_bubble(str)
this.comfylatron.set_command(
{
type = defines.command.go_to_location,
destination_entity = player.character,
radius = 3,
distraction = defines.distraction.none,
pathfind_flags = {
allow_destroy_friendly_entities = false,
prefer_straight_paths = false,
low_priority = true
}
}
)
local str = texts['travelings'][math_random(1, #texts['travelings'])]
local symbols = {'', '!', '!', '!!', '..'}
str = str .. symbols[math_random(1, #symbols)]
set_comfy_speech_bubble(str)
this.comfylatron_greet_player_index = player.index
this.comfylatron_greet_player_index = player.index
return true
return true
end
local function greet_player(nearby_characters)
local this = Scrap_table.get_table()
if not nearby_characters then return false end
if not this.comfylatron_greet_player_index then return false end
for _, c in pairs(nearby_characters) do
if c.player.index == this.comfylatron_greet_player_index then
local str = texts["greetings"][math_random(1, #texts["greetings"])] .. " "
str = str .. c.player.name
local symbols = {". ", "! ", ". ", "! ", "? ", "... "}
str = str .. symbols[math_random(1, 6)]
set_comfy_speech_bubble(str)
this.comfylatron_greet_player_index = false
return true
end
end
return false
local this = Scrap_table.get_table()
if not nearby_characters then
return false
end
if not this.comfylatron_greet_player_index then
return false
end
for _, c in pairs(nearby_characters) do
if c.player.index == this.comfylatron_greet_player_index then
local str = texts['greetings'][math_random(1, #texts['greetings'])] .. ' '
str = str .. c.player.name
local symbols = {'. ', '! ', '. ', '! ', '? ', '... '}
str = str .. symbols[math_random(1, 6)]
set_comfy_speech_bubble(str)
this.comfylatron_greet_player_index = false
return true
end
end
return false
end
local function talks(nearby_characters)
local this = Scrap_table.get_table()
if not nearby_characters then return false end
if math_random(1,3) == 1 then
if this.comfybubble then this.comfybubble.destroy() return false end
end
local str
if #nearby_characters == 1 then
local c = nearby_characters[math_random(1, #nearby_characters)]
str = c.player.name
local symbols = {". ", "! ", ". ", "! ", "? "}
str = str .. symbols[math_random(1, #symbols)]
else
str = texts["multiple_characters_greetings"][math_random(1, #texts["multiple_characters_greetings"])]
local symbols = {". ", "! "}
str = str .. symbols[math_random(1, #symbols)]
end
if math_random(1,5) == 1 then
str = str .. texts["talks"][math_random(1, #texts["talks"])]
end
set_comfy_speech_bubble(str)
return true
local this = Scrap_table.get_table()
if not nearby_characters then
return false
end
if math_random(1, 3) == 1 then
if this.comfybubble then
this.comfybubble.destroy()
return false
end
end
local str
if #nearby_characters == 1 then
local c = nearby_characters[math_random(1, #nearby_characters)]
str = c.player.name
local symbols = {'. ', '! ', '. ', '! ', '? '}
str = str .. symbols[math_random(1, #symbols)]
else
str = texts['multiple_characters_greetings'][math_random(1, #texts['multiple_characters_greetings'])]
local symbols = {'. ', '! '}
str = str .. symbols[math_random(1, #symbols)]
end
if math_random(1, 5) == 1 then
str = str .. texts['talks'][math_random(1, #texts['talks'])]
end
set_comfy_speech_bubble(str)
return true
end
local function desync(event)
local this = Scrap_table.get_table()
if this.comfybubble then this.comfybubble.destroy() end
local m = 12
local m2 = m * 0.005
for i = 1, 32, 1 do
this.comfylatron.surface.create_particle({
name = "iron-ore-particle",
position = this.comfylatron.position,
frame_speed = 0.1,
vertical_speed = 0.1,
height = 0.1,
movement = {m2 - (math.random(0, m) * 0.01), m2 - (math.random(0, m) * 0.01)}
})
end
if not event or math_random(1,4) == 1 then
this.comfylatron.surface.create_entity({name = "medium-explosion", position = this.comfylatron.position})
this.comfylatron.surface.create_entity({name = "flying-text", position = this.comfylatron.position, text = "desync", color = {r = 150, g = 0, b = 0}})
this.comfylatron.destroy()
this.comfylatron = nil
else
this.comfylatron.surface.create_entity({name = "flying-text", position = this.comfylatron.position, text = "desync evaded", color = {r = 0, g = 150, b = 0}})
if event.cause then
if event.cause.valid and event.cause.player then
game.print("Comfylatron: I got you this time! Back to work, " .. event.cause.player.name .. "!", {r = 200, g = 0, b = 0})
event.cause.die("player", this.comfylatron)
end
end
end
local this = Scrap_table.get_table()
if this.comfybubble then
this.comfybubble.destroy()
end
local m = 12
local m2 = m * 0.005
for i = 1, 32, 1 do
this.comfylatron.surface.create_particle(
{
name = 'iron-ore-particle',
position = this.comfylatron.position,
frame_speed = 0.1,
vertical_speed = 0.1,
height = 0.1,
movement = {m2 - (math.random(0, m) * 0.01), m2 - (math.random(0, m) * 0.01)}
}
)
end
if not event or math_random(1, 4) == 1 then
this.comfylatron.surface.create_entity({name = 'medium-explosion', position = this.comfylatron.position})
this.comfylatron.surface.create_entity(
{
name = 'flying-text',
position = this.comfylatron.position,
text = 'desync',
color = {r = 150, g = 0, b = 0}
}
)
this.comfylatron.destroy()
this.comfylatron = nil
else
this.comfylatron.surface.create_entity(
{
name = 'flying-text',
position = this.comfylatron.position,
text = 'desync evaded',
color = {r = 0, g = 150, b = 0}
}
)
end
end
local analyze_blacklist = {
["compilatron"] = true,
["compi-speech-bubble"] = true,
["entity-ghost"] = true,
["character"] = true,
["item-on-ground"] = true,
["stone-wall"] = true,
["market"] = true
['compilatron'] = true,
['compi-speech-bubble'] = true,
['entity-ghost'] = true,
['character'] = true,
['item-on-ground'] = true,
['stone-wall'] = true,
['market'] = true
}
local function analyze_random_nearby_entity()
local this = Scrap_table.get_table()
if math_random(1,3) ~= 1 then return false end
local this = Scrap_table.get_table()
if math_random(1, 3) ~= 1 then
return false
end
local entities = this.comfylatron.surface.find_entities_filtered({
area = {{this.comfylatron.position.x - 4, this.comfylatron.position.y - 4}, {this.comfylatron.position.x + 4, this.comfylatron.position.y + 4}}
})
if not entities[1] then return false end
entities = shuffle(entities)
local entity = false
for _, e in pairs(entities) do
if not analyze_blacklist[e.name] then
entity = e
end
end
if not entity then return false end
local entities =
this.comfylatron.surface.find_entities_filtered(
{
area = {
{this.comfylatron.position.x - 4, this.comfylatron.position.y - 4},
{this.comfylatron.position.x + 4, this.comfylatron.position.y + 4}
}
}
)
if not entities[1] then
return false
end
entities = shuffle(entities)
local entity = false
for _, e in pairs(entities) do
if not analyze_blacklist[e.name] then
entity = e
end
end
if not entity then
return false
end
local str = texts["neutral_findings"][math_random(1, #texts["neutral_findings"])]
str = str .. " "
str = str .. entity.name
local str = texts['neutral_findings'][math_random(1, #texts['neutral_findings'])]
str = str .. ' '
str = str .. entity.name
if entity.health and math_random(1,3) == 1 then
str = str .. " health("
str = str .. entity.health
str = str .. "/"
str = str .. entity.prototype.max_health
str = str .. ")"
else
local symbols = {".", "!", "?"}
str = str .. symbols[math_random(1, 3)]
end
set_comfy_speech_bubble(str)
if entity.health and math_random(1, 3) == 1 then
str = str .. ' health('
str = str .. entity.health
str = str .. '/'
str = str .. entity.prototype.max_health
str = str .. ')'
else
local symbols = {'.', '!', '?'}
str = str .. symbols[math_random(1, 3)]
end
set_comfy_speech_bubble(str)
if not this.comfylatron_greet_player_index then
this.comfylatron.set_command({
type = defines.command.go_to_location,
destination_entity = entity,
radius = 1,
distraction = defines.distraction.none,
pathfind_flags = {
allow_destroy_friendly_entities = false,
prefer_straight_paths = false,
low_priority = true
}
})
end
return true
if not this.comfylatron_greet_player_index then
this.comfylatron.set_command(
{
type = defines.command.go_to_location,
destination_entity = entity,
radius = 1,
distraction = defines.distraction.none,
pathfind_flags = {
allow_destroy_friendly_entities = false,
prefer_straight_paths = false,
low_priority = true
}
}
)
end
return true
end
local function go_to_some_location()
local this = Scrap_table.get_table()
if math_random(1,4) ~= 1 then return false end
local this = Scrap_table.get_table()
if math_random(1, 4) ~= 1 then
return false
end
if this.comfylatron_greet_player_index then
local player = game.players[this.comfylatron_greet_player_index]
if player.surface ~= this.comfylatron.surface then return end
if not player.character then
this.comfylatron_greet_player_index = nil
return false
end
if not player.character.valid then
this.comfylatron_greet_player_index = nil
return false
end
if not is_target_inside_habitat(player.position, player.surface) then
this.comfylatron_greet_player_index = nil
return false
end
this.comfylatron.set_command({
type = defines.command.go_to_location,
destination_entity = player.character,
radius = 3,
distraction = defines.distraction.none,
pathfind_flags = {
allow_destroy_friendly_entities = false,
prefer_straight_paths = false,
low_priority = true
}
})
else
local p = {x = this.comfylatron.position.x + (-96 + math_random(0, 192)), y = this.comfylatron.position.y + (-96 + math_random(0, 192))}
local target = this.comfylatron.surface.find_non_colliding_position("compilatron", p, 8, 1)
if not target then return false end
if not is_target_inside_habitat(target, this.comfylatron.surface) then return false end
this.comfylatron.set_command({
type = defines.command.go_to_location,
destination = target,
radius = 2,
distraction = defines.distraction.none,
pathfind_flags = {
allow_destroy_friendly_entities = false,
prefer_straight_paths = false,
low_priority = true
}
})
end
if this.comfylatron_greet_player_index then
local player = game.players[this.comfylatron_greet_player_index]
if player.surface ~= this.comfylatron.surface then
return
end
if not player.character then
this.comfylatron_greet_player_index = nil
return false
end
if not player.character.valid then
this.comfylatron_greet_player_index = nil
return false
end
if not is_target_inside_habitat(player.position, player.surface) then
this.comfylatron_greet_player_index = nil
return false
end
this.comfylatron.set_command(
{
type = defines.command.go_to_location,
destination_entity = player.character,
radius = 3,
distraction = defines.distraction.none,
pathfind_flags = {
allow_destroy_friendly_entities = false,
prefer_straight_paths = false,
low_priority = true
}
}
)
else
local p = {
x = this.comfylatron.position.x + (-96 + math_random(0, 192)),
y = this.comfylatron.position.y + (-96 + math_random(0, 192))
}
local target = this.comfylatron.surface.find_non_colliding_position('compilatron', p, 8, 1)
if not target then
return false
end
if not is_target_inside_habitat(target, this.comfylatron.surface) then
return false
end
this.comfylatron.set_command(
{
type = defines.command.go_to_location,
destination = target,
radius = 2,
distraction = defines.distraction.none,
pathfind_flags = {
allow_destroy_friendly_entities = false,
prefer_straight_paths = false,
low_priority = true
}
}
)
end
local str = texts["travelings"][math_random(1, #texts["travelings"])]
local symbols = {"", "!", "!", "!!", ".."}
str = str .. symbols[math_random(1, #symbols)]
set_comfy_speech_bubble(str)
local str = texts['travelings'][math_random(1, #texts['travelings'])]
local symbols = {'', '!', '!', '!!', '..'}
str = str .. symbols[math_random(1, #symbols)]
set_comfy_speech_bubble(str)
return true
return true
end
local function spawn_comfylatron(surface)
local this = Scrap_table.get_table()
if surface == nil then return end
if not this.locomotive then return end
if not this.locomotive.valid then return end
if not this.comfylatron_last_player_visit then this.comfylatron_last_player_visit = 0 end
if not this.comfylatron_habitat then
local pos = this.locomotive.position
this.comfylatron_habitat = {
left_top = {x = pos.x-256, y = pos.y-256},
right_bottom = {x = pos.x+256, y = pos.y+256}
}
end
local players = {}
for _, p in pairs(game.connected_players) do
if is_target_inside_habitat(p.position) and p.character then
if p.character.valid then players[#players + 1] = p end
end
end
if #players == 0 then return false end
local player = players[math_random(1, #players)]
local this = Scrap_table.get_table()
if surface == nil then
return
end
if not this.locomotive then
return
end
if not this.locomotive.valid then
return
end
if not this.comfylatron_last_player_visit then
this.comfylatron_last_player_visit = 0
end
if not this.comfylatron_habitat then
local pos = this.locomotive.position
this.comfylatron_habitat = {
left_top = {x = pos.x - 256, y = pos.y - 256},
right_bottom = {x = pos.x + 256, y = pos.y + 256}
}
end
local players = {}
for _, p in pairs(game.connected_players) do
if is_target_inside_habitat(p.position) and p.character then
if p.character.valid then
players[#players + 1] = p
end
end
end
if #players == 0 then
return false
end
local player = players[math_random(1, #players)]
local position = surface.find_non_colliding_position("compilatron", player.position, 16, 1)
if not position then return false end
this.comfylatron = surface.create_entity({
name = "compilatron",
position = position,
force = "neutral"
})
for x = -3, 3, 1 do
for y = -3, 3, 1 do
if math_random(1, 3) == 1 then
player.surface.create_trivial_smoke({name="smoke-fast", position={position.x + (x * 0.35), position.y + (y * 0.35)}})
end
if math_random(1, 5) == 1 then
player.surface.create_trivial_smoke({name="train-smoke", position={position.x + (x * 0.35), position.y + (y * 0.35)}})
end
end
end
local position = surface.find_non_colliding_position('compilatron', player.position, 16, 1)
if not position then
return false
end
this.comfylatron =
surface.create_entity(
{
name = 'compilatron',
position = position,
force = 'neutral'
}
)
for x = -3, 3, 1 do
for y = -3, 3, 1 do
if math_random(1, 3) == 1 then
player.surface.create_trivial_smoke(
{name = 'smoke-fast', position = {position.x + (x * 0.35), position.y + (y * 0.35)}}
)
end
if math_random(1, 5) == 1 then
player.surface.create_trivial_smoke(
{name = 'train-smoke', position = {position.x + (x * 0.35), position.y + (y * 0.35)}}
)
end
end
end
end
local function heartbeat()
local this = Scrap_table.get_table()
if not this.locomotive.valid then return end
local surface = game.surfaces[this.active_surface_index]
if not surface then return end
if surface == nil then return end
if not this.comfylatron then if math_random(1,4) == 1 then spawn_comfylatron(surface) end return end
if not this.comfylatron.valid then this.comfylatron = nil return end
if visit_player() then return end
local nearby_players = get_nearby_players()
if greet_player(nearby_players) then return end
if talks(nearby_players) then return end
if go_to_some_location() then return end
if analyze_random_nearby_entity() then return end
local this = Scrap_table.get_table()
if not this.locomotive.valid then
return
end
local surface = game.surfaces[this.active_surface_index]
if not surface then
return
end
if surface == nil then
return
end
if not this.comfylatron then
if math_random(1, 4) == 1 then
spawn_comfylatron(surface)
end
return
end
if not this.comfylatron.valid then
this.comfylatron = nil
return
end
if visit_player() then
return
end
local nearby_players = get_nearby_players()
if greet_player(nearby_players) then
return
end
if talks(nearby_players) then
return
end
if go_to_some_location() then
return
end
if analyze_random_nearby_entity() then
return
end
end
local function on_entity_damaged(event)
local this = Scrap_table.get_table()
if not this.comfylatron then return end
if not event.entity.valid then return end
if event.entity ~= this.comfylatron then return end
desync(event)
local this = Scrap_table.get_table()
if not this.comfylatron then
return
end
if not event.entity.valid then
return
end
if event.entity ~= this.comfylatron then
return
end
desync(event)
end
local function on_entity_died(event)
local this = Scrap_table.get_table()
if not this.comfylatron then return end
if not event.entity.valid then return end
if event.entity ~= this.comfylatron then return end
if this.comfybubble then this.comfybubble.destroy() end
if this.comfylatron then this.comfylatron.die() end
this.comfybubble = nil
this.comfylatron = nil
this.comfylatron_habitat = nil
this.comfylatron_last_player_visit = nil
local this = Scrap_table.get_table()
if not this.comfylatron then
return
end
if not event.entity.valid then
return
end
if event.entity ~= this.comfylatron then
return
end
if this.comfybubble then
this.comfybubble.destroy()
end
if this.comfylatron then
this.comfylatron.die()
end
this.comfybubble = nil
this.comfylatron = nil
this.comfylatron_habitat = nil
this.comfylatron_last_player_visit = nil
end
local function on_tick()
if game.tick % 1200 == 600 then
heartbeat()
end
if game.tick % 1200 == 600 then
heartbeat()
end
end
Event.add(defines.events.on_entity_damaged, on_entity_damaged)

83
maps/scrapyard/gui.lua Normal file
View File

@ -0,0 +1,83 @@
local RPG = require 'maps.scrapyard.rpg'
local Scrap_table = require 'maps.scrapyard.table'
local floor = math.floor
local format_number = require 'util'.format_number
local function create_gui(player)
local label
local line
local frame = player.gui.top.add({type = 'frame', name = 'scrapyard'})
frame.style.minimal_height = 38
frame.style.maximal_height = 38
label = frame.add({type = 'label', caption = ' ', name = 'label'})
label.style.font_color = {r = 0.88, g = 0.88, b = 0.88}
label.style.font = 'default-bold'
label.style.font_color = {r = 0.33, g = 0.66, b = 0.9}
label = frame.add({type = 'label', caption = ' ', name = 'global_pool'})
label.style.font_color = {r = 0.88, g = 0.88, b = 0.88}
label.style.font = 'default-bold'
label.style.right_padding = 4
label.style.font_color = {r = 0.33, g = 0.66, b = 0.9}
line = frame.add({type = 'line', direction = 'vertical'})
line.style.left_padding = 4
line.style.right_padding = 4
label = frame.add({type = 'label', caption = ' ', name = 'scrap_mined'})
label.style.font_color = {r = 0.88, g = 0.88, b = 0.88}
label.style.font = 'default-bold'
label.style.right_padding = 4
label.style.font_color = {r = 0.33, g = 0.66, b = 0.9}
line = frame.add({type = 'line', direction = 'vertical'})
line.style.left_padding = 4
line.style.right_padding = 4
label = frame.add({type = 'label', caption = ' ', name = 'biters_killed'})
label.style.font_color = {r = 0.88, g = 0.88, b = 0.88}
label.style.font = 'default-bold'
label.style.right_padding = 4
label.style.font_color = {r = 0.33, g = 0.66, b = 0.9}
line = frame.add({type = 'line', direction = 'vertical'})
line.style.left_padding = 4
line.style.right_padding = 4
label = frame.add({type = 'label', caption = ' ', name = 'train_upgrades'})
label.style.font_color = {r = 0.88, g = 0.88, b = 0.88}
label.style.font = 'default-bold'
label.style.right_padding = 4
label.style.font_color = {r = 0.33, g = 0.66, b = 0.9}
end
local function update_gui(player)
local rpg = RPG.get_table()
local st = Scrap_table.get_table()
if not player.gui.top.scrapyard then
create_gui(player)
end
local gui = player.gui.top.scrapyard
if rpg.global_pool == 0 then
gui.global_pool.caption = 'XP: 0'
gui.global_pool.tooltip = 'Dig, handcraft or run to increase the pool!'
elseif rpg.global_pool > 0 then
gui.global_pool.caption = 'XP: ' .. format_number(floor(rpg.global_pool), true)
gui.global_pool.tooltip = 'Get this number over 5k to get some of this mad XP! \\o/'
end
gui.scrap_mined.caption = ' [img=entity.mineable-wreckage]: ' .. format_number(st.mined_scrap, true)
gui.scrap_mined.tooltip = 'Amount of scrap mined.'
gui.biters_killed.caption = ' [img=entity.small-biter]: ' .. format_number(st.biters_killed, true)
gui.biters_killed.tooltip = 'Amount of biters killed.'
gui.train_upgrades.caption = ' [img=entity.locomotive]: ' .. format_number(st.train_upgrades, true)
gui.train_upgrades.tooltip = 'Amount of train upgrades.'
end
return update_gui

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
local Global = require 'utils.global'
local Event = require 'utils.event'
local Functions = require "maps.scrapyard.icw.functions"
local Constants = require "maps.scrapyard.icw.constants"
local Functions = require 'maps.scrapyard.icw.functions'
local Constants = require 'maps.scrapyard.icw.constants'
local Public = {}
local math_round = math.round
@ -15,58 +15,68 @@ Global.register(
)
function Public.reset()
if icw.surfaces then
for k, surface in pairs(icw.surfaces) do
if surface and surface.valid then
game.delete_surface(surface)
end
end
end
for k, v in pairs(icw) do icw[k] = nil end
icw.doors = {}
icw.wagons = {}
icw.trains = {}
icw.players = {}
icw.surfaces = {}
if icw.surfaces then
for k, surface in pairs(icw.surfaces) do
if surface and surface.valid then
game.delete_surface(surface)
end
end
end
for k, v in pairs(icw) do
icw[k] = nil
end
icw.doors = {}
icw.wagons = {}
icw.trains = {}
icw.players = {}
icw.surfaces = {}
end
local function on_entity_died(event)
local entity = event.entity
if not entity and not entity.valid then return end
if not Constants.wagon_types[entity.type] then return end
Functions.subtract_wagon_entity_count(icw, entity)
Functions.kill_wagon(icw, entity)
local entity = event.entity
if not entity and not entity.valid then
return
end
if not Constants.wagon_types[entity.type] then
return
end
Functions.subtract_wagon_entity_count(icw, entity)
Functions.kill_wagon(icw, entity)
end
local function on_player_mined_entity(event)
local entity = event.entity
if not entity and not entity.valid then return end
Functions.subtract_wagon_entity_count(icw, entity)
Functions.kill_wagon(icw, entity)
local entity = event.entity
if not entity and not entity.valid then
return
end
Functions.subtract_wagon_entity_count(icw, entity)
Functions.kill_wagon(icw, entity)
end
local function on_robot_mined_entity(event)
local entity = event.entity
if not entity and not entity.valid then return end
Functions.subtract_wagon_entity_count(icw, entity)
Functions.kill_wagon(icw, entity)
local entity = event.entity
if not entity and not entity.valid then
return
end
Functions.subtract_wagon_entity_count(icw, entity)
Functions.kill_wagon(icw, entity)
end
local function on_built_entity(event)
local created_entity = event.created_entity
Functions.create_wagon(icw, created_entity)
Functions.add_wagon_entity_count(icw, created_entity)
local created_entity = event.created_entity
Functions.create_wagon(icw, created_entity)
Functions.add_wagon_entity_count(icw, created_entity)
end
local function on_robot_built_entity(event)
local created_entity = event.created_entity
Functions.create_wagon(icw, created_entity)
Functions.add_wagon_entity_count(icw, created_entity)
local created_entity = event.created_entity
Functions.create_wagon(icw, created_entity)
Functions.add_wagon_entity_count(icw, created_entity)
end
local function on_player_driving_changed_state(event)
local player = game.players[event.player_index]
Functions.use_cargo_wagon_door(icw, player, event.entity)
local player = game.players[event.player_index]
Functions.use_cargo_wagon_door(icw, player, event.entity)
end
--[[
local function on_player_created(event)
@ -79,57 +89,89 @@ local function on_player_created(event)
end
]]
local function on_gui_closed(event)
local entity = event.entity
if not entity then return end
if not entity.valid then return end
if not entity.unit_number then return end
if not icw.wagons[entity.unit_number] then return end
Functions.kill_minimap(game.players[event.player_index])
local entity = event.entity
if not entity then
return
end
if not entity.valid then
return
end
if not entity.unit_number then
return
end
if not icw.wagons[entity.unit_number] then
return
end
Functions.kill_minimap(game.players[event.player_index])
end
local function on_gui_opened(event)
local entity = event.entity
if not entity then return end
if not entity.valid then return end
if not entity.unit_number then return end
local wagon = icw.wagons[entity.unit_number]
if not wagon then return end
Functions.draw_minimap(icw, game.players[event.player_index], wagon.surface, {wagon.area.left_top.x + (wagon.area.right_bottom.x - wagon.area.left_top.x) * 0.5, wagon.area.left_top.y + (wagon.area.right_bottom.y - wagon.area.left_top.y) * 0.5})
local entity = event.entity
if not entity then
return
end
if not entity.valid then
return
end
if not entity.unit_number then
return
end
local wagon = icw.wagons[entity.unit_number]
if not wagon then
return
end
Functions.draw_minimap(
icw,
game.players[event.player_index],
wagon.surface,
{
wagon.area.left_top.x + (wagon.area.right_bottom.x - wagon.area.left_top.x) * 0.5,
wagon.area.left_top.y + (wagon.area.right_bottom.y - wagon.area.left_top.y) * 0.5
}
)
end
local function on_player_died(event)
Functions.kill_minimap(game.players[event.player_index])
Functions.kill_minimap(game.players[event.player_index])
end
local function on_train_created(event)
Functions.request_reconstruction(icw)
Functions.request_reconstruction(icw)
end
local function on_gui_click(event)
Functions.toggle_minimap(icw, event)
Functions.toggle_minimap(icw, event)
end
local function on_tick()
local tick = game.tick
if tick % 60 == 0 then Functions.item_transfer(icw) end
if tick % 240 == 0 then Functions.update_minimap(icw) end
if not icw.rebuild_tick then return end
if icw.rebuild_tick ~= tick then return end
Functions.reconstruct_all_trains(icw)
icw.rebuild_tick = nil
local tick = game.tick
if tick % 60 == 0 then
Functions.item_transfer(icw)
end
if tick % 240 == 0 then
Functions.update_minimap(icw)
end
if not icw.rebuild_tick then
return
end
if icw.rebuild_tick ~= tick then
return
end
Functions.reconstruct_all_trains(icw)
icw.rebuild_tick = nil
end
local function on_init()
Public.reset()
Public.reset()
end
function Public.get_table()
return icw
return icw
end
function Public.register_wagon(wagon_entity)
return Functions.create_wagon(icw, wagon_entity)
return Functions.create_wagon(icw, wagon_entity)
end
Event.on_init(on_init)
@ -147,4 +189,4 @@ Event.add(defines.events.on_gui_opened, on_gui_opened)
Event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
Event.add(defines.events.on_robot_mined_entity, on_robot_mined_entity)
return Public
return Public

View File

@ -150,7 +150,8 @@ local function refresh_market(data)
},
{price = {{'coin', 5}}, offer = {type = 'give-item', item = 'small-lamp'}},
{price = {{'coin', 5}}, offer = {type = 'give-item', item = 'firearm-magazine'}},
{price = {{'wood', 25}}, offer = {type = 'give-item', item = 'raw-fish', count = 2}}
{price = {{'wood', 25}}, offer = {type = 'give-item', item = 'raw-fish', count = 2}},
{price = {{'coin', 25}}, offer = {type = 'give-item', item = 'land-mine', count = 1}}
}
for _, item in pairs(items) do
@ -330,9 +331,9 @@ local function property_boost(data)
right_bottom = {x = loco.x + 40, y = loco.y + 40}
}
for _, player in pairs(game.connected_players) do
if player.surface ~= surface then
return
end
--if player.surface ~= surface then
-- return -- players get xp inside train
--end
if Public.contains_positions(player.position, area) then
local pos = player.position
RPG.gain_xp(player, 0.2 * rpg[player.index].bonus)
@ -375,6 +376,24 @@ local function reveal_train_area()
if not this.locomotive.valid then
return
end
if this.revealed_spawn > game.tick then
goto continue
end
if this.ow_energy then
if this.ow_energy.valid then
local position = this.ow_energy.position
local area = {
left_top = {x = position.x - 2, y = position.y - 2},
right_bottom = {x = position.x + 2, y = position.y + 2}
}
if Public.contains_positions(this.locomotive.position, area) then
return
end
end
end
this.revealed_spawn = game.tick + 500
::continue::
local position = this.locomotive.position
local surface = game.surfaces[this.active_surface_index]
local seed = game.surfaces[this.active_surface_index].map_gen_settings.seed
@ -388,6 +407,91 @@ local function reveal_train_area()
Terrain.reveal_train(data)
end
local function fish_tag()
local this = Scrap_table.get_table()
if not this.locomotive_cargo then
return
end
if not this.locomotive_cargo.valid then
return
end
if not this.locomotive_cargo.surface then
return
end
if not this.locomotive_cargo.surface.valid then
return
end
if this.locomotive_tag then
if this.locomotive_tag.valid then
if
this.locomotive_tag.position.x == this.locomotive_cargo.position.x and
this.locomotive_tag.position.y == this.locomotive_cargo.position.y
then
return
end
this.locomotive_tag.destroy()
end
end
this.locomotive_tag =
this.locomotive_cargo.force.add_chart_tag(
this.locomotive_cargo.surface,
{
icon = {type = 'item', name = 'raw-fish'},
position = this.locomotive_cargo.position,
text = ' '
}
)
end
local function set_player_spawn_and_refill_fish()
local this = Scrap_table.get_table()
if not this.locomotive_cargo then
return
end
if not this.locomotive_cargo.valid then
return
end
this.locomotive_cargo.get_inventory(defines.inventory.cargo_wagon).insert(
{name = 'raw-fish', count = math.random(2, 5)}
)
local position =
this.locomotive_cargo.surface.find_non_colliding_position(
'stone-furnace',
this.locomotive_cargo.position,
16,
2
)
if not position then
return
end
game.forces.player.set_spawn_position({x = position.x, y = position.y}, this.locomotive_cargo.surface)
end
local function tick()
local this = Scrap_table.get_table()
Public.power_source_overworld()
Public.power_source_locomotive()
Public.place_market()
if game.tick % 120 == 0 then
Public.boost_players_around_train()
end
--if game.tick % 80 == 0 then
-- train_rainbow()
--end
if this.train_reveal then
if game.tick % 10 == 0 then
reveal_train_area()
end
end
if game.tick % 30 == 0 then
if game.tick % 1800 == 0 then
set_player_spawn_and_refill_fish()
end
fish_tag()
end
end
function Public.boost_players_around_train()
local rpg = RPG.get_table()
local this = Scrap_table.get_table()
@ -434,6 +538,15 @@ function Public.render_train_hp()
alignment = 'center',
scale_with_zoom = false
}
this.circle =
rendering.draw_circle {
surface = surface,
target = this.locomotive,
color = this.locomotive.color,
filled = false,
radius = 40
}
end
function Public.locomotive_spawn(surface, position)
@ -573,89 +686,6 @@ function Public.power_source_locomotive()
end
end
local function fish_tag()
local this = Scrap_table.get_table()
if not this.locomotive_cargo then
return
end
if not this.locomotive_cargo.valid then
return
end
if not this.locomotive_cargo.surface then
return
end
if not this.locomotive_cargo.surface.valid then
return
end
if this.locomotive_tag then
if this.locomotive_tag.valid then
if
this.locomotive_tag.position.x == this.locomotive_cargo.position.x and
this.locomotive_tag.position.y == this.locomotive_cargo.position.y
then
return
end
this.locomotive_tag.destroy()
end
end
this.locomotive_tag =
this.locomotive_cargo.force.add_chart_tag(
this.locomotive_cargo.surface,
{
icon = {type = 'item', name = 'raw-fish'},
position = this.locomotive_cargo.position,
text = ' '
}
)
end
local function set_player_spawn_and_refill_fish()
local this = Scrap_table.get_table()
if not this.locomotive_cargo then
return
end
if not this.locomotive_cargo.valid then
return
end
this.locomotive_cargo.get_inventory(defines.inventory.cargo_wagon).insert(
{name = 'raw-fish', count = math.random(2, 5)}
)
local position =
this.locomotive_cargo.surface.find_non_colliding_position(
'stone-furnace',
this.locomotive_cargo.position,
16,
2
)
if not position then
return
end
game.forces.player.set_spawn_position({x = position.x, y = position.y}, this.locomotive_cargo.surface)
end
local function tick()
local this = Scrap_table.get_table()
Public.power_source_overworld()
Public.power_source_locomotive()
Public.place_market()
if game.tick % 120 == 0 then
Public.boost_players_around_train()
end
if this.revealed_spawn > game.tick then
reveal_train_area()
end
if game.tick % 80 == 0 then
reveal_train_area()
train_rainbow()
end
if game.tick % 30 == 0 then
if game.tick % 1800 == 0 then
set_player_spawn_and_refill_fish()
end
fish_tag()
end
end
Event.on_nth_tick(5, tick)
Event.add(defines.events.on_market_item_purchased, on_market_item_purchased)
Event.add(defines.events.on_gui_opened, on_gui_opened)

View File

@ -2,328 +2,334 @@ local Public = {}
local math_random = math.random
function Public.add(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 = "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 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 = '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 = 'land-mine', count = math_random(16, 32)}, weight = 5, d_min = 0.2, d_max = 0.7},
{{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
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
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="scrap"})
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
local e = surface.create_entity({name = chest, position = position, force = 'scrap'})
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
function Public.add_rare(surface, position, chest, magic)
if magic > 150 then
magic = math.random(1,150)
end
local chest_raffle = {}
local chest_loot = {
{{name = "submachine-gun", count = magic}, weight = 3, d_min = 0.0, d_max = 0.1},
{{name = "slowdown-capsule", count = magic}, weight = 1, d_min = 0.3, d_max = 0.7},
{{name = "poison-capsule", count = magic}, weight = 3, d_min = 0.3, d_max = 1},
{{name = "uranium-cannon-shell", count = magic}, weight = 5, d_min = 0.6, d_max = 1},
{{name = "cannon-shell", count = magic}, weight = 5, d_min = 0.4, d_max = 0.7},
{{name = "explosive-uranium-cannon-shell", count = magic}, weight = 5, d_min = 0.6, d_max = 1},
{{name = "explosive-cannon-shell", count = magic}, 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 = magic}, 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 = magic}, 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 = magic}, 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 = magic}, weight = 5, d_min = 0.2, d_max = 0.7},
{{name = "explosive-rocket", count = magic}, weight = 5, d_min = 0.3, d_max = 1},
{{name = "grenade", count = magic}, weight = 5, d_min = 0.0, d_max = 0.5},
{{name = "cluster-grenade", count = magic}, weight = 5, d_min = 0.4, d_max = 1},
{{name = "firearm-magazine", count = magic}, weight = 6, d_min = 0, d_max = 0.3},
{{name = "piercing-rounds-magazine", count = magic}, weight = 5, d_min = 0.1, d_max = 0.8},
{{name = "uranium-rounds-magazine", count = magic}, weight = 4, d_min = 0.5, d_max = 1},
{{name = "railgun", count = 1}, weight = 1, d_min = 0.2, d_max = 1},
{{name = "railgun-dart", count = magic}, weight = 3, d_min = 0.2, d_max = 0.7},
{{name = "defender-capsule", count = magic}, weight = 2, d_min = 0.0, d_max = 0.7},
{{name = "distractor-capsule", count = magic}, weight = 2, d_min = 0.2, d_max = 1},
{{name = "destroyer-capsule", count = magic}, 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 = magic}, 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 = magic}, 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 = magic}, weight = 3, d_min = 0.4, d_max = 1},
{{name = "logistic-robot", count = magic}, weight = 2, d_min = 0.5, d_max = 1},
{{name = "construction-robot", count = magic}, weight = 5, d_min = 0.4, d_max = 1},
{{name = "iron-gear-wheel", count = magic}, weight = 3, d_min = 0.0, d_max = 0.3},
{{name = "copper-cable", count = magic}, weight = 3, d_min = 0.0, d_max = 0.3},
{{name = "engine-unit", count = magic}, weight = 2, d_min = 0.1, d_max = 0.5},
{{name = "electric-engine-unit", count = magic}, weight = 2, d_min = 0.4, d_max = 0.8},
{{name = "battery", count = magic}, weight = 2, d_min = 0.3, d_max = 0.8},
{{name = "advanced-circuit", count = magic}, weight = 3, d_min = 0.3, d_max = 1},
{{name = "electronic-circuit", count = magic}, weight = 4, d_min = 0.0, d_max = 0.4},
{{name = "processing-unit", count = magic}, weight = 3, d_min = 0.7, d_max = 1},
{{name = "explosives", count = magic}, weight = 10, d_min = 0.0, d_max = 1},
{{name = "lubricant-barrel", count = magic}, weight = 1, d_min = 0.3, d_max = 0.5},
{{name = "rocket-fuel", count = magic}, weight = 2, d_min = 0.3, d_max = 0.7},
{{name = "effectivity-module", count = magic}, weight = 2, d_min = 0.1, d_max = 1},
{{name = "productivity-module", count = magic}, weight = 2, d_min = 0.1, d_max = 1},
{{name = "speed-module", count = magic}, weight = 2, d_min = 0.1, d_max = 1},
{{name = "automation-science-pack", count = magic}, weight = 3, d_min = 0.0, d_max = 0.2},
{{name = "logistic-science-pack", count = magic}, weight = 3, d_min = 0.1, d_max = 0.5},
{{name = "military-science-pack", count = magic}, weight = 3, d_min = 0.2, d_max = 1},
{{name = "chemical-science-pack", count = magic}, weight = 3, d_min = 0.3, d_max = 1},
{{name = "production-science-pack", count = magic}, weight = 3, d_min = 0.4, d_max = 1},
{{name = "utility-science-pack", count = magic}, weight = 3, d_min = 0.5, d_max = 1},
{{name = "space-science-pack", count = magic}, weight = 3, d_min = 0.9, d_max = 1},
{{name = "steel-plate", count = magic}, 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 = magic}, weight = 3, d_min = 0.0, d_max = 0.1},
{{name = "inserter", count = magic}, weight = 3, d_min = 0.0, d_max = 0.4},
{{name = "long-handed-inserter", count = magic}, weight = 3, d_min = 0.0, d_max = 0.4},
{{name = "fast-inserter", count = magic}, weight = 3, d_min = 0.1, d_max = 1},
{{name = "filter-inserter", count = magic}, weight = 1, d_min = 0.2, d_max = 1},
{{name = "stack-filter-inserter", count = magic}, weight = 1, d_min = 0.4, d_max = 1},
{{name = "stack-inserter", count = magic}, weight = 3, d_min = 0.3, d_max = 1},
{{name = "small-electric-pole", count = magic}, weight = 3, d_min = 0.0, d_max = 0.3},
{{name = "medium-electric-pole", count = magic}, weight = 3, d_min = 0.2, d_max = 1},
{{name = "big-electric-pole", count = magic}, weight = 3, d_min = 0.3, d_max = 1},
{{name = "substation", count = magic}, weight = 3, d_min = 0.5, d_max = 1},
{{name = "wooden-chest", count = magic}, weight = 3, d_min = 0.0, d_max = 0.2},
{{name = "iron-chest", count = magic}, weight = 3, d_min = 0.1, d_max = 0.4},
{{name = "steel-chest", count = magic}, weight = 3, d_min = 0.3, d_max = 1},
{{name = "small-lamp", count = magic}, weight = 3, d_min = 0.1, d_max = 0.3},
{{name = "rail", count = magic}, weight = 3, d_min = 0.1, d_max = 0.6},
{{name = "assembling-machine-1", count = magic}, weight = 3, d_min = 0.0, d_max = 0.3},
{{name = "assembling-machine-2", count = magic}, weight = 3, d_min = 0.2, d_max = 0.8},
{{name = "assembling-machine-3", count = magic}, weight = 3, d_min = 0.5, d_max = 1},
{{name = "accumulator", count = magic}, weight = 3, d_min = 0.4, d_max = 1},
{{name = "offshore-pump", count = magic}, 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 = magic}, weight = 3, d_min = 0.0, d_max = 0.3},
{{name = "steam-engine", count = magic}, weight = 3, d_min = 0.0, d_max = 0.5},
{{name = "steam-turbine", count = magic}, 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 = magic}, weight = 2, d_min = 0.5, d_max = 1},
{{name = "heat-exchanger", count = magic}, weight = 2, d_min = 0.5, d_max = 1},
{{name = "arithmetic-combinator", count = magic}, weight = 2, d_min = 0.1, d_max = 1},
{{name = "constant-combinator", count = magic}, weight = 2, d_min = 0.1, d_max = 1},
{{name = "decider-combinator", count = magic}, 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 = magic}, weight = 1, d_min = 0.1, d_max = 1},
{{name = "green-wire", count = magic}, weight = 4, d_min = 0.1, d_max = 1},
{{name = "red-wire", count = magic}, weight = 4, d_min = 0.1, d_max = 1},
{{name = "chemical-plant", count = magic}, weight = 3, d_min = 0.3, d_max = 1},
{{name = "burner-mining-drill", count = magic}, weight = 3, d_min = 0.0, d_max = 0.2},
{{name = "electric-mining-drill", count = magic}, weight = 3, d_min = 0.2, d_max = 1},
{{name = "express-transport-belt", count = magic}, weight = 3, d_min = 0.5, d_max = 1},
{{name = "express-underground-belt", count = magic}, weight = 3, d_min = 0.5, d_max = 1},
{{name = "express-splitter", count = magic}, weight = 3, d_min = 0.5, d_max = 1},
{{name = "fast-transport-belt", count = magic}, weight = 3, d_min = 0.2, d_max = 0.7},
{{name = "fast-underground-belt", count = magic}, weight = 3, d_min = 0.2, d_max = 0.7},
{{name = "fast-splitter", count = magic}, weight = 3, d_min = 0.2, d_max = 0.3},
{{name = "transport-belt", count = magic}, weight = 3, d_min = 0, d_max = 0.3},
{{name = "underground-belt", count = magic}, weight = 3, d_min = 0, d_max = 0.3},
{{name = "splitter", count = magic}, weight = 3, d_min = 0, d_max = 0.3},
{{name = "pipe", count = magic}, weight = 3, d_min = 0.0, d_max = 0.3},
{{name = "pipe-to-ground", count = magic}, weight = 1, d_min = 0.2, d_max = 0.5},
{{name = "pumpjack", count = magic}, weight = 1, d_min = 0.3, d_max = 0.8},
{{name = "pump", count = magic}, weight = 1, d_min = 0.3, d_max = 0.8},
{{name = "solar-panel", count = magic}, weight = 3, d_min = 0.4, d_max = 0.9},
{{name = "electric-furnace", count = magic}, weight = 3, d_min = 0.5, d_max = 1},
{{name = "steel-furnace", count = magic}, weight = 3, d_min = 0.2, d_max = 0.7},
{{name = "stone-furnace", count = magic}, weight = 3, d_min = 0.0, d_max = 0.2},
{{name = "radar", count = magic}, weight = 1, d_min = 0.1, d_max = 0.4},
{{name = "rail-signal", count = magic}, weight = 2, d_min = 0.2, d_max = 0.8},
{{name = "rail-chain-signal", count = magic}, weight = 2, d_min = 0.2, d_max = 0.8},
{{name = "stone-wall", count = magic}, weight = 3, d_min = 0.0, d_max = 0.7},
{{name = "gate", count = magic}, weight = 3, d_min = 0.0, d_max = 0.7},
{{name = "storage-tank", count = magic}, weight = 3, d_min = 0.3, d_max = 0.6},
{{name = "train-stop", count = magic}, weight = 1, d_min = 0.2, d_max = 0.7},
{{name = "express-loader", count = magic}, weight = 1, d_min = 0.5, d_max = 1},
{{name = "fast-loader", count = magic}, weight = 1, d_min = 0.2, d_max = 0.7},
{{name = "loader", count = magic}, weight = 1, d_min = 0.0, d_max = 0.5},
{{name = "lab", count = magic}, 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 = magic}, weight = 3, d_min = 0.5, d_max = 1},
{{name = "gun-turret", count = magic}, weight = 3, d_min = 0.2, d_max = 0.9},
}
if magic > 150 then
magic = math.random(1, 150)
end
local chest_raffle = {}
local chest_loot = {
{{name = 'submachine-gun', count = magic}, weight = 3, d_min = 0.0, d_max = 0.1},
{{name = 'slowdown-capsule', count = magic}, weight = 1, d_min = 0.3, d_max = 0.7},
{{name = 'poison-capsule', count = magic}, weight = 3, d_min = 0.3, d_max = 1},
{{name = 'uranium-cannon-shell', count = magic}, weight = 5, d_min = 0.6, d_max = 1},
{{name = 'cannon-shell', count = magic}, weight = 5, d_min = 0.4, d_max = 0.7},
{{name = 'explosive-uranium-cannon-shell', count = magic}, weight = 5, d_min = 0.6, d_max = 1},
{{name = 'explosive-cannon-shell', count = magic}, 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 = magic}, 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 = magic}, 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 = magic}, 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 = magic}, weight = 5, d_min = 0.2, d_max = 0.7},
{{name = 'explosive-rocket', count = magic}, weight = 5, d_min = 0.3, d_max = 1},
{{name = 'grenade', count = magic}, weight = 5, d_min = 0.0, d_max = 0.5},
{{name = 'cluster-grenade', count = magic}, weight = 5, d_min = 0.4, d_max = 1},
{{name = 'firearm-magazine', count = magic}, weight = 6, d_min = 0, d_max = 0.3},
{{name = 'piercing-rounds-magazine', count = magic}, weight = 5, d_min = 0.1, d_max = 0.8},
{{name = 'uranium-rounds-magazine', count = magic}, weight = 4, d_min = 0.5, d_max = 1},
{{name = 'railgun', count = 1}, weight = 1, d_min = 0.2, d_max = 1},
{{name = 'railgun-dart', count = magic}, weight = 3, d_min = 0.2, d_max = 0.7},
{{name = 'defender-capsule', count = magic}, weight = 2, d_min = 0.0, d_max = 0.7},
{{name = 'distractor-capsule', count = magic}, weight = 2, d_min = 0.2, d_max = 1},
{{name = 'destroyer-capsule', count = magic}, weight = 2, d_min = 0.3, d_max = 1},
{{name = 'atomic-bomb', count = 1}, weight = 1, d_min = 0.8, d_max = 1},
{{name = 'land-mine', count = magic}, weight = 5, d_min = 0.2, d_max = 0.7},
{{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 = magic}, 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 = magic}, 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 = magic}, weight = 3, d_min = 0.4, d_max = 1},
{{name = 'logistic-robot', count = magic}, weight = 2, d_min = 0.5, d_max = 1},
{{name = 'construction-robot', count = magic}, weight = 5, d_min = 0.4, d_max = 1},
{{name = 'iron-gear-wheel', count = magic}, weight = 3, d_min = 0.0, d_max = 0.3},
{{name = 'copper-cable', count = magic}, weight = 3, d_min = 0.0, d_max = 0.3},
{{name = 'engine-unit', count = magic}, weight = 2, d_min = 0.1, d_max = 0.5},
{{name = 'electric-engine-unit', count = magic}, weight = 2, d_min = 0.4, d_max = 0.8},
{{name = 'battery', count = magic}, weight = 2, d_min = 0.3, d_max = 0.8},
{{name = 'advanced-circuit', count = magic}, weight = 3, d_min = 0.3, d_max = 1},
{{name = 'electronic-circuit', count = magic}, weight = 4, d_min = 0.0, d_max = 0.4},
{{name = 'processing-unit', count = magic}, weight = 3, d_min = 0.7, d_max = 1},
{{name = 'explosives', count = magic}, weight = 10, d_min = 0.0, d_max = 1},
{{name = 'lubricant-barrel', count = magic}, weight = 1, d_min = 0.3, d_max = 0.5},
{{name = 'rocket-fuel', count = magic}, weight = 2, d_min = 0.3, d_max = 0.7},
{{name = 'effectivity-module', count = magic}, weight = 2, d_min = 0.1, d_max = 1},
{{name = 'productivity-module', count = magic}, weight = 2, d_min = 0.1, d_max = 1},
{{name = 'speed-module', count = magic}, weight = 2, d_min = 0.1, d_max = 1},
{{name = 'automation-science-pack', count = magic}, weight = 3, d_min = 0.0, d_max = 0.2},
{{name = 'logistic-science-pack', count = magic}, weight = 3, d_min = 0.1, d_max = 0.5},
{{name = 'military-science-pack', count = magic}, weight = 3, d_min = 0.2, d_max = 1},
{{name = 'chemical-science-pack', count = magic}, weight = 3, d_min = 0.3, d_max = 1},
{{name = 'production-science-pack', count = magic}, weight = 3, d_min = 0.4, d_max = 1},
{{name = 'utility-science-pack', count = magic}, weight = 3, d_min = 0.5, d_max = 1},
{{name = 'space-science-pack', count = magic}, weight = 3, d_min = 0.9, d_max = 1},
{{name = 'steel-plate', count = magic}, 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 = magic}, weight = 3, d_min = 0.0, d_max = 0.1},
{{name = 'inserter', count = magic}, weight = 3, d_min = 0.0, d_max = 0.4},
{{name = 'long-handed-inserter', count = magic}, weight = 3, d_min = 0.0, d_max = 0.4},
{{name = 'fast-inserter', count = magic}, weight = 3, d_min = 0.1, d_max = 1},
{{name = 'filter-inserter', count = magic}, weight = 1, d_min = 0.2, d_max = 1},
{{name = 'stack-filter-inserter', count = magic}, weight = 1, d_min = 0.4, d_max = 1},
{{name = 'stack-inserter', count = magic}, weight = 3, d_min = 0.3, d_max = 1},
{{name = 'small-electric-pole', count = magic}, weight = 3, d_min = 0.0, d_max = 0.3},
{{name = 'medium-electric-pole', count = magic}, weight = 3, d_min = 0.2, d_max = 1},
{{name = 'big-electric-pole', count = magic}, weight = 3, d_min = 0.3, d_max = 1},
{{name = 'substation', count = magic}, weight = 3, d_min = 0.5, d_max = 1},
{{name = 'wooden-chest', count = magic}, weight = 3, d_min = 0.0, d_max = 0.2},
{{name = 'iron-chest', count = magic}, weight = 3, d_min = 0.1, d_max = 0.4},
{{name = 'steel-chest', count = magic}, weight = 3, d_min = 0.3, d_max = 1},
{{name = 'small-lamp', count = magic}, weight = 3, d_min = 0.1, d_max = 0.3},
{{name = 'rail', count = magic}, weight = 3, d_min = 0.1, d_max = 0.6},
{{name = 'assembling-machine-1', count = magic}, weight = 3, d_min = 0.0, d_max = 0.3},
{{name = 'assembling-machine-2', count = magic}, weight = 3, d_min = 0.2, d_max = 0.8},
{{name = 'assembling-machine-3', count = magic}, weight = 3, d_min = 0.5, d_max = 1},
{{name = 'accumulator', count = magic}, weight = 3, d_min = 0.4, d_max = 1},
{{name = 'offshore-pump', count = magic}, 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 = magic}, weight = 3, d_min = 0.0, d_max = 0.3},
{{name = 'steam-engine', count = magic}, weight = 3, d_min = 0.0, d_max = 0.5},
{{name = 'steam-turbine', count = magic}, 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 = magic}, weight = 2, d_min = 0.5, d_max = 1},
{{name = 'heat-exchanger', count = magic}, weight = 2, d_min = 0.5, d_max = 1},
{{name = 'arithmetic-combinator', count = magic}, weight = 2, d_min = 0.1, d_max = 1},
{{name = 'constant-combinator', count = magic}, weight = 2, d_min = 0.1, d_max = 1},
{{name = 'decider-combinator', count = magic}, 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 = magic}, weight = 1, d_min = 0.1, d_max = 1},
{{name = 'green-wire', count = magic}, weight = 4, d_min = 0.1, d_max = 1},
{{name = 'red-wire', count = magic}, weight = 4, d_min = 0.1, d_max = 1},
{{name = 'chemical-plant', count = magic}, weight = 3, d_min = 0.3, d_max = 1},
{{name = 'burner-mining-drill', count = magic}, weight = 3, d_min = 0.0, d_max = 0.2},
{{name = 'electric-mining-drill', count = magic}, weight = 3, d_min = 0.2, d_max = 1},
{{name = 'express-transport-belt', count = magic}, weight = 3, d_min = 0.5, d_max = 1},
{{name = 'express-underground-belt', count = magic}, weight = 3, d_min = 0.5, d_max = 1},
{{name = 'express-splitter', count = magic}, weight = 3, d_min = 0.5, d_max = 1},
{{name = 'fast-transport-belt', count = magic}, weight = 3, d_min = 0.2, d_max = 0.7},
{{name = 'fast-underground-belt', count = magic}, weight = 3, d_min = 0.2, d_max = 0.7},
{{name = 'fast-splitter', count = magic}, weight = 3, d_min = 0.2, d_max = 0.3},
{{name = 'transport-belt', count = magic}, weight = 3, d_min = 0, d_max = 0.3},
{{name = 'underground-belt', count = magic}, weight = 3, d_min = 0, d_max = 0.3},
{{name = 'splitter', count = magic}, weight = 3, d_min = 0, d_max = 0.3},
{{name = 'pipe', count = magic}, weight = 3, d_min = 0.0, d_max = 0.3},
{{name = 'pipe-to-ground', count = magic}, weight = 1, d_min = 0.2, d_max = 0.5},
{{name = 'pumpjack', count = magic}, weight = 1, d_min = 0.3, d_max = 0.8},
{{name = 'pump', count = magic}, weight = 1, d_min = 0.3, d_max = 0.8},
{{name = 'solar-panel', count = magic}, weight = 3, d_min = 0.4, d_max = 0.9},
{{name = 'electric-furnace', count = magic}, weight = 3, d_min = 0.5, d_max = 1},
{{name = 'steel-furnace', count = magic}, weight = 3, d_min = 0.2, d_max = 0.7},
{{name = 'stone-furnace', count = magic}, weight = 3, d_min = 0.0, d_max = 0.2},
{{name = 'radar', count = magic}, weight = 1, d_min = 0.1, d_max = 0.4},
{{name = 'rail-signal', count = magic}, weight = 2, d_min = 0.2, d_max = 0.8},
{{name = 'rail-chain-signal', count = magic}, weight = 2, d_min = 0.2, d_max = 0.8},
{{name = 'stone-wall', count = magic}, weight = 3, d_min = 0.0, d_max = 0.7},
{{name = 'gate', count = magic}, weight = 3, d_min = 0.0, d_max = 0.7},
{{name = 'storage-tank', count = magic}, weight = 3, d_min = 0.3, d_max = 0.6},
{{name = 'train-stop', count = magic}, weight = 1, d_min = 0.2, d_max = 0.7},
{{name = 'express-loader', count = magic}, weight = 1, d_min = 0.5, d_max = 1},
{{name = 'fast-loader', count = magic}, weight = 1, d_min = 0.2, d_max = 0.7},
{{name = 'loader', count = magic}, weight = 1, d_min = 0.0, d_max = 0.5},
{{name = 'lab', count = magic}, 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 = magic}, weight = 3, d_min = 0.5, d_max = 1},
{{name = 'gun-turret', count = magic}, 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
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
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="scrap"})
e.minable = false
local i = e.get_inventory(defines.inventory.chest)
for x = 1, math_random(2,7), 1 do
local loot = chest_raffle[math_random(1,#chest_raffle)]
i.insert(loot)
end
local e = surface.create_entity({name = chest, position = position, force = 'scrap'})
e.minable = false
local i = e.get_inventory(defines.inventory.chest)
for x = 1, math_random(2, 7), 1 do
local loot = chest_raffle[math_random(1, #chest_raffle)]
i.insert(loot)
end
end
return Public

View File

@ -1,3 +1,7 @@
if package.loaded['comfy_panel.player_list'] then
package.unload = 'comfy_panel.player_list'
end
require 'maps.scrapyard.player_list'
require 'on_tick_schedule'
require 'modules.dynamic_landfill'
require 'modules.difficulty_vote'
@ -12,10 +16,13 @@ require 'modules.biters_yield_coins'
require 'modules.biter_noms_you'
require 'modules.wave_defense.main'
require 'maps.scrapyard.comfylatron'
require 'modules.admins_operate_biters'
require 'modules.pistol_buffs'
local Map_score = require 'comfy_panel.map_score'
local Explosives = require 'modules.explosives'
local Color = require 'utils.color_presets'
local update_gui = require 'maps.scrapyard.gui'
local ICW = require 'maps.scrapyard.icw.main'
local WD = require 'modules.wave_defense.table'
local Map = require 'modules.map_info'
@ -40,21 +47,13 @@ local Public = {}
local math_random = math.random
local math_floor = math.floor
function Public.print(msg)
if _DEBUG then
game.print(serpent.block(msg))
end
end
Scrap_table.init({train_reveal = true})
local starting_items = {['pistol'] = 1, ['firearm-magazine'] = 16, ['wood'] = 4, ['rail'] = 16, ['raw-fish'] = 2}
local disabled_entities = {'gun-turret', 'laser-turret', 'flamethrower-turret', 'land-mine'}
local colors = {
'green-refined-concrete',
'black-refined-concrete',
'orange-refined-concrete',
'red-refined-concrete',
'yellow-refined-concrete',
'brown-refined-concrete',
'blue-refined-concrete'
}
local treasure_chest_messages = {
@ -82,14 +81,14 @@ end
local function set_scores()
local this = Scrap_table.get_table()
local fish_wagon = this.locomotive_cargo
if not fish_wagon then
local wagon = this.locomotive_cargo
if not wagon then
return
end
if not fish_wagon.valid then
if not wagon.valid then
return
end
local score = math_floor(fish_wagon.position.y * -1)
local score = math_floor(wagon.position.y * -1)
for _, player in pairs(game.connected_players) do
if score > Map_score.get_score(player) then
Map_score.set_score(player, score)
@ -156,8 +155,9 @@ function Public.reset_map()
game.reset_time_played()
Scrap_table.reset_table()
wave_defense_table.math = 8
--this.revealed_spawn = game.tick + 100
this.revealed_spawn = game.tick + 500
if not this.train_reveal then
this.revealed_spawn = game.tick + 100
end
local map_gen_settings = {
['seed'] = math_random(1, 1000000),
@ -175,7 +175,7 @@ function Public.reset_map()
if not this.active_surface_index then
this.active_surface_index = game.create_surface('scrapyard', map_gen_settings).index
else
game.forces.player.set_spawn_position({0, 21}, game.surfaces[this.active_surface_index])
game.forces.player.set_spawn_position({0, 25}, game.surfaces[this.active_surface_index])
this.active_surface_index =
Reset.soft_reset_map(game.surfaces[this.active_surface_index], map_gen_settings, starting_items).index
end
@ -195,6 +195,7 @@ function Public.reset_map()
game.forces.player.recipes['artillery-wagon'].enabled = false
game.forces.player.recipes['locomotive'].enabled = false
game.forces.player.recipes['pistol'].enabled = false
game.forces.player.technologies['land-mine'].enabled = false
game.forces.player.set_spawn_position({0, 21}, surface)
global.friendly_fire_history = {}
@ -219,7 +220,7 @@ function Public.reset_map()
surface.min_brightness = 0.08
surface.daytime = 0.7
surface.brightness_visual_weights = {1, 0, 0, 0}
surface.freeze_daytime = false
surface.freeze_daytime = true
surface.solar_power_multiplier = 1
this.locomotive_health = 10000
this.locomotive_max_health = 10000
@ -394,7 +395,7 @@ local function protect_train(event)
end
local function change_tile(surface, pos, steps)
return surface.set_tiles {{name = colors[math_floor(steps * 0.5) % 7 + 1], position = {x = pos.x, y = pos.y + 1}}}
return surface.set_tiles {{name = colors[math_floor(steps * 0.5) % 3 + 1], position = {x = pos.x, y = pos.y + 1}}}
end
local function on_player_changed_position(event)
@ -435,7 +436,11 @@ local function on_player_changed_position(event)
--end
end
::continue::
--if position.y < 5 then Terrain.reveal(player) end
if not this.train_reveal then
if position.y < 5 then
Terrain.reveal(player)
end
end
if position.y >= 190 then
player.teleport({position.x, position.y - 1}, surface)
player.print(grandmaster .. ' Forcefield does not approve.', {r = 0.98, g = 0.66, b = 0.22})
@ -566,6 +571,8 @@ local function give_coin(player)
end
local function on_player_mined_entity(event)
local this = Scrap_table.get_table()
local entity = event.entity
local player = game.players[event.player_index]
if not player.valid then
@ -587,6 +594,7 @@ local function on_player_mined_entity(event)
end
if entity.name == 'mineable-wreckage' then
this.mined_scrap = this.mined_scrap + 1
give_coin(player)
if math.random(1, 32) == 1 then
@ -772,11 +780,14 @@ function Public.loco_died()
end
local function on_entity_died(event)
local this = Scrap_table.get_table()
local entity = event.entity
if not entity.valid then
return
end
if entity.type == 'unit' or entity.type == 'unit-spawner' then
this.biters_killed = this.biters_killed + 1
if math_random(1, 160) == 1 then
tick_tack_trap(entity.surface, entity.position)
return
@ -891,13 +902,13 @@ local function on_robot_built_entity(event)
end
local on_init = function()
global.custom_highscore.description = 'Depth reached: '
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.player.technologies['land-mine'].enabled = false
game.forces.scrap.share_chart = false
global.rocks_yield_ore_maximum_amount = 500
global.rocks_yield_ore_base_amount = 50
@ -941,7 +952,9 @@ local on_init = function()
'Locomotive has now market upgrades\n',
'XP is granted after each breached wall\n',
'Train now has a XP aura, stay near it!\n',
'Aura increases after each breach wall'
'Aura increases after each breach wall\n',
'Players cannot reveal path, only the train can.\n',
'Follow the train and defend it.'
}
)
T.main_caption_color = {r = 150, g = 150, b = 0}
@ -965,7 +978,19 @@ local function darkness(data)
local rnd = math.random
local this = data.this
local surface = data.surface
if rnd(1, 64) == 1 then
if rnd(1, 32) == 1 then
if not this.freeze_daytime then
return
end
game.print(grandmaster .. ' Sunlight, finally!', {r = 1, g = 0.5, b = 0.1})
surface.min_brightness = 1
surface.brightness_visual_weights = {1, 0, 0, 0}
surface.daytime = 0.7
surface.freeze_daytime = true
surface.solar_power_multiplier = 1
this.freeze_daytime = false
return
elseif rnd(1, 64) == 1 then
if this.freeze_daytime then
return
end
@ -978,33 +1003,13 @@ local function darkness(data)
surface.solar_power_multiplier = 0
this.freeze_daytime = true
return
elseif rnd(1, 32) == 1 then
if not this.freeze_daytime then
return
end
game.print(grandmaster .. ' Sunlight, finally!', {r = 1, g = 0.5, b = 0.1})
surface.min_brightness = 1
surface.brightness_visual_weights = {1, 0, 0, 0}
surface.daytime = 0.7
surface.freeze_daytime = false
surface.solar_power_multiplier = 1
this.freeze_daytime = false
return
end
end
local function scrap_randomness(data)
local this = data.this
local rnd = math.random
if rnd(1, 64) == 1 then
if not this.scrap_enabled then
return
end
this.scrap_enabled = false
game.print(grandmaster .. ' It seems that the scrap is temporarily gone.', {r = 1, g = 0.5, b = 0.1})
game.print(grandmaster .. ' Output from scrap is now only ores.', {r = 1, g = 0.5, b = 0.1})
return
elseif rnd(1, 32) == 1 then
if rnd(1, 32) == 1 then
if this.scrap_enabled then
return
end
@ -1012,6 +1017,14 @@ local function scrap_randomness(data)
game.print(grandmaster .. ' Scrap is back!', {r = 1, g = 0.5, b = 0.1})
game.print(grandmaster .. ' Output from scrap is now randomized.', {r = 1, g = 0.5, b = 0.1})
return
elseif rnd(1, 64) == 1 then
if not this.scrap_enabled then
return
end
this.scrap_enabled = false
game.print(grandmaster .. ' It seems that the scrap is temporarily gone.', {r = 1, g = 0.5, b = 0.1})
game.print(grandmaster .. ' Output from scrap is now only ores.', {r = 1, g = 0.5, b = 0.1})
return
end
end
@ -1039,8 +1052,8 @@ end
local tick_minute_functions = {
[300 * 2 + 30 * 2] = scrap_randomness,
[300 * 3 + 30 * 3] = darkness,
[300 * 3 + 30 * 1] = transfer_pollution
[300 * 3 + 30 * 1] = darkness,
[300 * 3 + 30 * 0] = transfer_pollution
}
local on_tick = function()
@ -1070,6 +1083,10 @@ local on_tick = function()
end
::continue::
if game.tick % 30 == 0 then
for _, player in pairs(game.connected_players) do
update_gui(player)
end
if game.tick % 1800 == 0 then
local position = surface.find_non_colliding_position('stone-furnace', Collapse.get_position(), 128, 1)
if position then
@ -1082,13 +1099,13 @@ local on_tick = function()
if tick_minute_functions[key] then
tick_minute_functions[key](data)
end
if this.randomness_tick then
if this.randomness_tick < game.tick then
this.randomness_tick = game.tick + 1800
scrap_randomness(this)
darkness(this)
end
end
--if this.randomness_tick then
-- if this.randomness_tick < game.tick then
-- this.randomness_tick = game.tick + 1800
-- scrap_randomness(this)
-- darkness(this)
-- end
--end
if this.game_reset_tick then
if this.game_reset_tick < game.tick then

View File

@ -44,6 +44,7 @@ local function mining_chances_scrap()
{name = 'steel-plate', chance = 120},
{name = 'solid-fuel', chance = 89},
{name = 'pipe', chance = 75},
{name = 'stone', chance = 50},
{name = 'iron-stick', chance = 50},
{name = 'battery', chance = 20},
{name = 'empty-barrel', chance = 10},
@ -108,6 +109,7 @@ local function scrap_yield_amounts()
['iron-plate'] = 12,
['iron-gear-wheel'] = 12,
['iron-stick'] = 12,
['stone'] = 5,
['copper-plate'] = 12,
['copper-cable'] = 12,
['electronic-circuit'] = 4,
@ -283,7 +285,7 @@ local function on_player_mined_entity(event)
if not entity.valid then
return
end
if entity.name ~= 'mineable-wreckage' then
if entity.type ~= 'simple-entity' then
return
end
local player = game.players[event.player_index]

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,9 @@
local Global = require 'utils.global'
local Event = require 'utils.event'
local this = {}
local this = {
train_reveal = true
}
local Public = {}
Global.register(
@ -18,15 +20,15 @@ function Public.reset_table()
--end
this.lo_energy = nil
this.ow_energy = nil
this.game_lost = false
this.game_won = false
this.game_lost = false
this.game_won = false
this.energy = {}
this.wave_counter = 0
this.locomotive_health = 10000
this.locomotive_max_health = 10000
this.locomotive_health = 10000
this.locomotive_max_health = 10000
this.cargo_health = 10000
this.cargo_max_health = 10000
this.revealed_spawn = 0
this.revealed_spawn = 0
this.scrap_enabled = true
this.left_top = {
x = 0,
@ -36,13 +38,21 @@ function Public.reset_table()
this.energy_purchased = false
this.freeze_daytime = false
this.offline_players = {}
this.mined_scrap = 0
this.biters_killed = 0
end
function Public.get_table()
return this
end
local on_init = function ()
function Public.init(args)
if args then
this.train_reveal = args.train_reveal
end
end
local on_init = function()
Public.reset_table()
end

View File

@ -37,6 +37,32 @@ local rock_raffle = {
'rock-big',
'rock-huge'
}
local size_of_rock_raffle = #rock_raffle
local scrap_entities = {
'crash-site-assembling-machine-1-broken',
'crash-site-assembling-machine-2-broken',
'crash-site-assembling-machine-1-broken',
'crash-site-assembling-machine-2-broken',
'crash-site-lab-broken',
'medium-ship-wreck',
'small-ship-wreck',
'medium-ship-wreck',
'small-ship-wreck',
'medium-ship-wreck',
'small-ship-wreck',
'medium-ship-wreck',
'small-ship-wreck',
'crash-site-chest-1',
'crash-site-chest-2',
'crash-site-chest-1',
'crash-site-chest-2',
'crash-site-chest-1',
'crash-site-chest-2'
}
local scrap_entities_index = #scrap_entities
local scrap_buildings = {
'nuclear-reactor',
'centrifuge',
@ -321,7 +347,235 @@ local function wall(surface, left_top, seed)
end
end
local function process_level_6_position(surface, p, seed, tiles, entities, fishes, r_area, markets, treasure)
local function process_level_9_position(surface, p, seed, tiles, entities, fishes, markets, treasure)
local maze_p = {x = math_floor(p.x - p.x % 10), y = math_floor(p.y - p.y % 10)}
local maze_noise = get_noise('no_rocks_2', maze_p, seed)
if maze_noise > -0.35 and maze_noise < 0.35 then
tiles[#tiles + 1] = {name = 'dirt-7', position = p}
local no_rocks_2 = get_noise('no_rocks_2', p, seed)
if math_random(1, 2) == 1 and no_rocks_2 > -0.5 then
entities[#entities + 1] = {name = rock_raffle[math_random(1, size_of_rock_raffle)], position = p}
end
if math_random(1, 1024) == 1 then
treasure[#treasure + 1] = p
end
if math_random(1, 256) == 1 then
Biters.wave_defense_set_worm_raffle(math_abs(p.y) * worm_level_modifier)
create_inner_content(surface, p, maze_noise)
entities[#entities + 1] = {name = Biters.wave_defense_roll_worm_name(), position = p, force = 'enemy'}
end
return
end
if maze_noise > 0 and maze_noise < 0.45 then
if math_random(1, 512) == 1 then
markets[#markets + 1] = p
end
if math_random(1, 256) == 1 then
entities[#entities + 1] = {name = 'crude-oil', position = p, amount = get_oil_amount(p)}
end
if math_random(1, 32) == 1 then
entities[#entities + 1] = {name = 'tree-0' .. math_random(1, 9), position = p}
end
return
end
if maze_noise < -0.5 or maze_noise > 0.5 then
tiles[#tiles + 1] = {name = 'deepwater', position = p}
if math_random(1, 96) == 1 then
entities[#entities + 1] = {name = 'fish', position = p}
end
return
end
tiles[#tiles + 1] = {name = 'water', position = p}
if math_random(1, 96) == 1 then
entities[#entities + 1] = {name = 'fish', position = p}
end
end
local function process_level_8_position(surface, p, seed, tiles, entities, fishes, markets, treasure)
local scrapyard = get_noise('scrapyard', p, seed)
--Chasms
local noise_cave_ponds = get_noise('cave_ponds', p, seed)
local small_caves = get_noise('small_caves', p, seed)
if noise_cave_ponds < 0.15 and noise_cave_ponds > -0.15 then
if small_caves > 0.35 then
tiles[#tiles + 1] = {name = 'out-of-map', position = p}
return
end
if small_caves < -0.35 then
tiles[#tiles + 1] = {name = 'out-of-map', position = p}
return
end
end
if scrapyard < -0.25 or scrapyard > 0.25 then
if math_random(1, 256) == 1 then
entities[#entities + 1] = {name = 'gun-turret', position = p, force = 'enemy'}
end
tiles[#tiles + 1] = {name = 'dirt-7', position = p}
if scrapyard < -0.55 or scrapyard > 0.55 then
if math_random(1, 2) == 1 then
entities[#entities + 1] = {name = rock_raffle[math_random(1, size_of_rock_raffle)], position = p}
end
return
end
if scrapyard < -0.28 or scrapyard > 0.28 then
if math_random(1, 128) == 1 then
Biters.wave_defense_set_worm_raffle(math_abs(p.y) * worm_level_modifier)
create_inner_content(surface, p, scrapyard)
entities[#entities + 1] = {name = Biters.wave_defense_roll_worm_name(), position = p, force = 'enemy'}
end
if math_random(1, 96) == 1 then
entities[#entities + 1] = {
name = scrap_entities[math_random(1, scrap_entities_index)],
position = p,
force = 'enemy'
}
end
if math_random(1, 5) > 1 then
entities[#entities + 1] = {name = 'mineable-wreckage', position = p}
end
if math_random(1, 256) == 1 then
create_inner_content(surface, p, scrapyard)
entities[#entities + 1] = {name = 'land-mine', position = p, force = 'enemy'}
end
return
end
return
end
local cave_ponds = get_noise('cave_ponds', p, seed)
if cave_ponds < -0.6 and scrapyard > -0.2 and scrapyard < 0.2 then
tiles[#tiles + 1] = {name = 'deepwater-green', position = p}
if math_random(1, 128) == 1 then
entities[#entities + 1] = {name = 'fish', position = p}
end
return
end
local large_caves = get_noise('large_caves', p, seed)
if scrapyard > -0.15 and scrapyard < 0.15 then
if math_floor(large_caves * 10) % 4 < 3 then
tiles[#tiles + 1] = {name = 'dirt-7', position = p}
if math_random(1, 2) == 1 then
entities[#entities + 1] = {name = rock_raffle[math_random(1, size_of_rock_raffle)], position = p}
end
return
end
end
if math_random(1, 64) == 1 and cave_ponds > 0.6 then
entities[#entities + 1] = {name = 'crude-oil', position = p, amount = get_oil_amount(p)}
end
tiles[#tiles + 1] = {name = 'stone-path', position = p}
if math_random(1, 256) == 1 then
entities[#entities + 1] = {name = 'land-mine', position = p, force = 'enemy'}
end
end
local function process_level_7_position(surface, p, seed, tiles, entities, fishes, markets, treasure)
local cave_rivers_3 = get_noise('cave_rivers_3', p, seed)
local cave_rivers_4 = get_noise('cave_rivers_4', p, seed + 50000)
local no_rocks_2 = get_noise('no_rocks_2', p, seed)
if cave_rivers_3 > -0.025 and cave_rivers_3 < 0.025 and no_rocks_2 > -0.6 then
tiles[#tiles + 1] = {name = 'water', position = p}
if math_random(1, 128) == 1 then
entities[#entities + 1] = {name = 'fish', position = p}
end
return
end
if cave_rivers_4 > -0.025 and cave_rivers_4 < 0.025 and no_rocks_2 > -0.6 then
tiles[#tiles + 1] = {name = 'water', position = p}
if math_random(1, 128) == 1 then
entities[#entities + 1] = {name = 'fish', position = p}
end
return
end
local noise_ores = get_noise('no_rocks_2', p, seed + 25000)
if cave_rivers_3 > -0.20 and cave_rivers_3 < 0.20 then
tiles[#tiles + 1] = {name = 'grass-' .. math_floor(cave_rivers_3 * 32) % 3 + 1, position = p}
if cave_rivers_3 > -0.10 and cave_rivers_3 < 0.10 then
if math_random(1, 8) == 1 and no_rocks_2 > -0.25 then
entities[#entities + 1] = {name = 'tree-01', position = p}
end
if math_random(1, 2048) == 1 then
create_inner_content(surface, p, cave_rivers_3)
markets[#markets + 1] = p
end
if noise_ores < -0.5 and no_rocks_2 > -0.6 then
if cave_rivers_3 > 0 and cave_rivers_3 < 0.07 then
entities[#entities + 1] = {name = 'iron-ore', position = p, amount = math_abs(p.y) + 1}
end
end
end
if math_random(1, 64) == 1 and no_rocks_2 > 0.7 then
entities[#entities + 1] = {name = 'crude-oil', position = p, amount = get_oil_amount(p)}
end
if math_random(1, 2048) == 1 then
treasure[#treasure + 1] = p
end
return
end
if cave_rivers_4 > -0.20 and cave_rivers_4 < 0.20 then
tiles[#tiles + 1] = {name = 'grass-' .. math_floor(cave_rivers_4 * 32) % 3 + 1, position = p}
if cave_rivers_4 > -0.10 and cave_rivers_4 < 0.10 then
if math_random(1, 8) == 1 and no_rocks_2 > -0.25 then
entities[#entities + 1] = {name = 'tree-02', position = p}
end
if math_random(1, 2048) == 1 then
markets[#markets + 1] = p
end
if noise_ores < -0.5 and no_rocks_2 > -0.6 then
if cave_rivers_4 > 0 and cave_rivers_4 < 0.07 then
create_inner_content(surface, p, noise_ores)
entities[#entities + 1] = {name = 'copper-ore', position = p, amount = math_abs(p.y) + 1}
end
end
end
if math_random(1, 64) == 1 and no_rocks_2 > 0.7 then
entities[#entities + 1] = {name = 'crude-oil', position = p, amount = get_oil_amount(p)}
end
if math_random(1, 2048) == 1 then
treasure[#treasure + 1] = p
end
return
end
--Chasms
local noise_cave_ponds = get_noise('cave_ponds', p, seed)
local small_caves = get_noise('small_caves', p, seed)
if noise_cave_ponds < 0.25 and noise_cave_ponds > -0.25 then
if small_caves > 0.55 then
tiles[#tiles + 1] = {name = 'out-of-map', position = p}
return
end
if small_caves < -0.55 then
tiles[#tiles + 1] = {name = 'out-of-map', position = p}
return
end
end
tiles[#tiles + 1] = {name = 'dirt-7', position = p}
if math_random(1, 100) > 15 then
entities[#entities + 1] = {name = rock_raffle[math_random(1, size_of_rock_raffle)], position = p}
end
if math_random(1, 256) == 1 then
treasure[#treasure + 1] = p
end
end
local function process_level_6_position(surface, p, seed, tiles, entities, fishes, markets, treasure)
local large_caves = get_noise('large_caves', p, seed)
local noise_cave_ponds = get_noise('cave_ponds', p, seed)
@ -338,7 +592,6 @@ local function process_level_6_position(surface, p, seed, tiles, entities, fishe
end
if large_caves < -0.47 or large_caves > 0.47 then
insert(r_area, {x = p.x, y = p.y})
tiles[#tiles + 1] = {name = 'deepwater-green', position = p}
if math_random(1, 128) == 1 then
entities[#entities + 1] = {name = 'fish', position = p}
@ -377,7 +630,7 @@ local function process_level_6_position(surface, p, seed, tiles, entities, fishe
end
end
local function process_level_5_position(surface, p, seed, tiles, entities, fishes, r_area, markets, treasure)
local function process_level_5_position(surface, p, seed, tiles, entities, fishes, markets, treasure)
local small_caves = get_noise('small_caves', p, seed)
local noise_cave_ponds = get_noise('cave_ponds', p, seed)
@ -394,7 +647,6 @@ local function process_level_5_position(surface, p, seed, tiles, entities, fishe
end
if small_caves < -0.50 or small_caves > 0.50 then
insert(r_area, {x = p.x, y = p.y})
tiles[#tiles + 1] = {name = 'deepwater-green', position = p}
if math_random(1, 128) == 1 then
entities[#entities + 1] = {name = 'fish', position = p}
@ -433,7 +685,7 @@ local function process_level_5_position(surface, p, seed, tiles, entities, fishe
end
end
local function process_level_4_position(surface, p, seed, tiles, entities, fishes, r_area, markets, treasure)
local function process_level_4_position(surface, p, seed, tiles, entities, fishes, markets, treasure)
local noise_large_caves = get_noise('large_caves', p, seed)
local noise_cave_ponds = get_noise('cave_ponds', p, seed)
local small_caves = get_noise('small_caves', p, seed)
@ -446,7 +698,6 @@ local function process_level_4_position(surface, p, seed, tiles, entities, fishe
return
end
if math_abs(noise_large_caves) > 0.6 then
insert(r_area, {x = p.x, y = p.y})
if math_random(1, 16) == 1 then
entities[#entities + 1] = {name = trees[math_random(1, #trees)], position = p}
end
@ -455,7 +706,6 @@ local function process_level_4_position(surface, p, seed, tiles, entities, fishe
end
end
if math_abs(noise_large_caves) > 0.5 then
insert(r_area, {x = p.x, y = p.y})
tiles[#tiles + 1] = {name = 'grass-2', position = p}
if math_random(1, 620) == 1 then
entities[#entities + 1] = {name = 'crude-oil', position = p, amount = get_oil_amount(p)}
@ -530,7 +780,7 @@ local function process_level_4_position(surface, p, seed, tiles, entities, fishe
end
end
local function process_level_3_position(surface, p, seed, tiles, entities, fishes, r_area, markets, treasure)
local function process_level_3_position(surface, p, seed, tiles, entities, fishes, markets, treasure)
local small_caves = get_noise('small_caves', p, seed + 50000)
local small_caves_2 = get_noise('small_caves_2', p, seed + 70000)
local noise_large_caves = get_noise('large_caves', p, seed + 60000)
@ -608,7 +858,6 @@ local function process_level_3_position(surface, p, seed, tiles, entities, fishe
--Worm oil Zones
if no_rocks < 0.15 and no_rocks > -0.15 then
if small_caves > 0.35 then
insert(r_area, {x = p.x, y = p.y})
--tiles[#tiles + 1] = {name = more_colors[math_random(1, #more_colors)].. "-refined-concrete", position = p}
tiles[#tiles + 1] = {name = 'dirt-' .. math_floor(noise_cave_ponds * 32) % 7 + 1, position = p}
if math_random(1, 320) == 1 then
@ -659,7 +908,7 @@ local function process_level_3_position(surface, p, seed, tiles, entities, fishe
end
end
local function process_level_2_position(surface, p, seed, tiles, entities, fishes, r_area, markets, treasure)
local function process_level_2_position(surface, p, seed, tiles, entities, fishes, markets, treasure)
local small_caves = get_noise('small_caves', p, seed)
local noise_large_caves = get_noise('large_caves', p, seed)
@ -707,7 +956,6 @@ local function process_level_2_position(surface, p, seed, tiles, entities, fishe
--Market Spots
if noise_cave_ponds < -0.80 then
insert(r_area, {x = p.x, y = p.y})
create_inner_content(surface, p, noise_cave_ponds)
tiles[#tiles + 1] = {name = 'grass-' .. math_floor(noise_cave_ponds * 32) % 3 + 1, position = p}
if math_random(1, 32) == 1 then
@ -723,7 +971,6 @@ local function process_level_2_position(surface, p, seed, tiles, entities, fishe
--Worm oil Zones
if no_rocks < 0.15 and no_rocks > -0.15 then
if small_caves > 0.35 then
insert(r_area, {x = p.x, y = p.y})
tiles[#tiles + 1] = {name = 'dirt-' .. math_floor(noise_cave_ponds * 32) % 7 + 1, position = p}
--tiles[#tiles + 1] = {name = colors[math_random(1, #colors)].. "-refined-concrete", position = p}
if math_random(1, 450) == 1 then
@ -770,7 +1017,7 @@ local function process_level_2_position(surface, p, seed, tiles, entities, fishe
end
end
local function process_level_1_position(surface, p, seed, tiles, entities, fishes, r_area, markets, treasure)
local function process_level_1_position(surface, p, seed, tiles, entities, fishes, markets, treasure)
local small_caves = get_noise('small_caves', p, seed)
local noise_cave_ponds = get_noise('cave_ponds', p, seed)
@ -809,13 +1056,14 @@ local function process_level_1_position(surface, p, seed, tiles, entities, fishe
if noise_cave_ponds > 0.76 then
--tiles[#tiles + 1] = {name = colors[math_random(1, #colors)].. "-refined-concrete", position = p}
tiles[#tiles + 1] = {name = 'dirt-' .. math_random(4, 6), position = p}
--tiles[#tiles + 1] = {name = 'dirt-' .. math_random(4, 6), position = p}
tiles[#tiles + 1] = {name = 'stone-path', position = p}
return
end
--Market Spots
if noise_cave_ponds < -0.75 then
insert(r_area, {x = p.x, y = p.y})
tiles[#tiles + 1] = {name = 'grass-' .. math_floor(noise_cave_ponds * 32) % 3 + 1, position = p}
if math_random(1, 32) == 1 then
markets[#markets + 1] = p
@ -832,7 +1080,6 @@ local function process_level_1_position(surface, p, seed, tiles, entities, fishe
if p.y < -64 + noise_cave_ponds * 10 then
if no_rocks < 0.08 and no_rocks > -0.08 then
if small_caves > 0.35 then
insert(r_area, {x = p.x, y = p.y})
--tiles[#tiles + 1] = {name = more_colors[math_random(1, #more_colors)].. "-refined-concrete", position = p}
tiles[#tiles + 1] = {name = 'dirt-' .. math_floor(noise_cave_ponds * 32) % 7 + 1, position = p}
if math_random(1, 450) == 1 then
@ -875,7 +1122,9 @@ local function process_level_1_position(surface, p, seed, tiles, entities, fishe
treasure[#treasure + 1] = p
end
--tiles[#tiles + 1] = {name = colors[math_random(1, #colors)].. "-refined-concrete", position = p}
tiles[#tiles + 1] = {name = 'dirt-7', position = p}
--tiles[#tiles + 1] = {name = 'dirt-7', position = p}
tiles[#tiles + 1] = {name = 'stone-path', position = p}
if math_random(1, 4028) == 1 then
place_random_scrap_entity(surface, p)
end
@ -889,98 +1138,28 @@ Public.levels = {
process_level_2_position,
process_level_3_position,
process_level_4_position,
process_level_5_position
--process_level_6_position,
--process_level_7_position,
--process_level_8_position,
--process_level_9_position,
process_level_5_position,
process_level_6_position,
process_level_7_position,
process_level_8_position,
process_level_9_position
--process_level_10_position,
}
function Public.reveal_area(x, y, surface, max_radius)
local this = Scrap_table.get_table()
local wave_defense_table = WD.get_table()
local seed = game.surfaces[this.active_surface_index].map_gen_settings.seed
local circles = shapes.circles
local r_area = {}
local tiles = {}
local fishes = {}
local entities = {}
local markets = {}
local treasure = {}
local process_level = Public.levels[math_floor(math_abs(y) / Public.level_depth) + 1]
if not process_level then
process_level = Public.levels[#Public.levels]
end
for r = 1, max_radius, 1 do
for _, v in pairs(circles[r]) do
local pos = {x = x + v.x, y = y + v.y}
if not surface.get_tile(pos) then
return
end
local t_name = surface.get_tile(pos).name == 'out-of-map'
if t_name then
process_level(surface, pos, seed, tiles, entities, fishes, r_area, markets, treasure)
end
end
end
if #tiles > 0 then
surface.set_tiles(tiles, true)
end
for _, entity in pairs(entities) do
if surface.can_place_entity(entity) and entity == 'biter-spawner' or entity == 'spitter-spawner' then
surface.create_entity(entity)
else
surface.create_entity(entity)
end
end
if #markets > 0 then
local pos = markets[math_random(1, #markets)]
if
surface.count_entities_filtered {
area = {{pos.x - 96, pos.y - 96}, {pos.x + 96, pos.y + 96}},
name = 'market',
limit = 1
} == 0
then
local market = Market.mountain_market(surface, pos, math_abs(pos.y) * 0.004)
market.destructible = false
end
end
for _, p in pairs(treasure) do
local name = 'steel-chest'
Loot.add(surface, p, name)
if math_random(1, wave_defense_table.math) == 1 then
local distance_to_center = math.sqrt(p.x ^ 2 + p.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(p, surface, size, amount)
end
end
for _, fish in pairs(fishes) do
surface.create_entity({name = 'fish', position = fish})
end
end
function Public.reveal_train(data)
local position = data.position
local seed = data.seed
local surface = data.surface
local circles = shapes.circles
local uncover_radius = data.reveal
local r_area = {}
local tiles = {}
local fishes = {}
local entities = {}
local markets = {}
local treasure = {}
local process_level = Public.levels[math_floor(math_abs(position.y) / Public.level_depth) + 1]
if not process_level then
process_level = Public.levels[#Public.levels]
end
local level_index = math_floor((math_abs(position.y / Public.level_depth)) % 9) + 1
local process_level = Public.levels[level_index]
for r = 1, uncover_radius, 1 do
for _, v in pairs(circles[r]) do
local pos = {x = position.x - 30 + math_random(1, 64) + v.x, y = position.y - 20 + v.y + math_random(1, 64)}
@ -989,7 +1168,7 @@ function Public.reveal_train(data)
t_name = surface.get_tile(pos).name == 'out-of-map'
end
if t_name then
process_level(surface, pos, seed, tiles, entities, fishes, r_area, markets, treasure)
process_level(surface, pos, seed, tiles, entities, fishes, markets, treasure)
end
end
end
@ -1003,11 +1182,6 @@ function Public.reveal_train(data)
surface.create_entity(entity)
end
end
for _, pos in pairs(r_area) do
local x = pos.x
local y = pos.y
Public.reveal_area(x, y, surface, 23)
end
if #markets > 0 then
local pos = markets[math_random(1, #markets)]
if
@ -1037,22 +1211,20 @@ function Public.reveal(player)
local surface = player.surface
local circles = shapes.circles
local uncover_radius = 10
local r_area = {}
local tiles = {}
local fishes = {}
local entities = {}
local markets = {}
local treasure = {}
local process_level = Public.levels[math_floor(math_abs(position.y) / Public.level_depth) + 1]
if not process_level then
process_level = Public.levels[#Public.levels]
end
local level_index = math_floor((math_abs(position.y / Public.level_depth)) % 9) + 1
local process_level = Public.levels[level_index]
for r = 1, uncover_radius, 1 do
for _, v in pairs(circles[r]) do
local pos = {x = position.x + v.x, y = position.y + v.y}
local t_name = surface.get_tile(pos).name == 'out-of-map'
if t_name then
process_level(surface, pos, seed, tiles, entities, fishes, r_area, markets, treasure)
process_level(surface, pos, seed, tiles, entities, fishes, markets, treasure)
end
end
end
@ -1066,11 +1238,6 @@ function Public.reveal(player)
surface.create_entity(entity)
end
end
for _, pos in pairs(r_area) do
local x = pos.x
local y = pos.y
Public.reveal_area(x, y, surface, 12)
end
if #markets > 0 then
local pos = markets[math_random(1, #markets)]
if
@ -1302,6 +1469,17 @@ local function on_chunk_generated(event)
return
end
local surface = event.surface
local seed = surface.map_gen_settings.seed
local position = this.locomotive.position
local data = {
this = this,
surface = surface,
seed = seed,
position = position,
reveal = 23
}
local left_top = event.area.left_top
if left_top.x >= Public.level_depth * 0.5 then
out_of_map(surface, left_top)
@ -1314,26 +1492,24 @@ local function on_chunk_generated(event)
if surface.name ~= event.surface.name then
return
end
if this.rev_sp then
goto continue
end
if left_top.y > 32 then
game.forces.player.chart(surface, {{left_top.x, left_top.y}, {left_top.x + 31, left_top.y + 31}})
end
--if this.revealed_spawn > game.tick then
-- for i = 80, -80, -10 do
-- Public.reveal_area(0, i, surface, 4)
-- Public.reveal_area(0, i, surface, 4)
-- Public.reveal_area(0, i, surface, 4)
-- Public.reveal_area(0, i, surface, 4)
-- end
::continue::
-- for v = 80, -80, -10 do
-- Public.reveal_area(v, 0, surface, 4)
-- Public.reveal_area(v, 0, surface, 4)
-- Public.reveal_area(v, 0, surface, 4)
-- Public.reveal_area(v, 0, surface, 4)
-- end
--end
if not this.train_reveal then
if this.revealed_spawn > game.tick then
Public.reveal_train(data)
end
end
if left_top.y % Public.level_depth == 0 and left_top.y < 0 and left_top.y > Public.level_depth * -10 then
if left_top.y % Public.level_depth == 0 and left_top.y < 0 then
this.left_top = event.area.left_top
wall(surface, left_top, surface.map_gen_settings.seed)
wall(surface, left_top, seed)
return
end