diff --git a/maps/scrapyard/balance.lua b/maps/scrapyard/balance.lua index 3600e0f0..f73344f4 100644 --- a/maps/scrapyard/balance.lua +++ b/maps/scrapyard/balance.lua @@ -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) diff --git a/maps/scrapyard/comfylatron.lua b/maps/scrapyard/comfylatron.lua index 328ce9ee..001c0315 100644 --- a/maps/scrapyard/comfylatron.lua +++ b/maps/scrapyard/comfylatron.lua @@ -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) diff --git a/maps/scrapyard/gui.lua b/maps/scrapyard/gui.lua new file mode 100644 index 00000000..a5b97dcf --- /dev/null +++ b/maps/scrapyard/gui.lua @@ -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 diff --git a/maps/scrapyard/icw/functions.lua b/maps/scrapyard/icw/functions.lua index 4451d9fe..bba3b57f 100644 --- a/maps/scrapyard/icw/functions.lua +++ b/maps/scrapyard/icw/functions.lua @@ -1,604 +1,723 @@ local Public = {} -local Constants = require "maps.scrapyard.icw.constants" +local Constants = require 'maps.scrapyard.icw.constants' local table_insert = table.insert local table_remove = table.remove local math_random = math.random function Public.request_reconstruction(icw) - icw.rebuild_tick = game.tick + 30 + icw.rebuild_tick = game.tick + 30 end local function delete_empty_surfaces(icw) - for k, surface in pairs(icw.surfaces) do - if not icw.trains[tonumber(surface.name)] then - game.delete_surface(surface) - table_remove(icw.surfaces, k) - end - end -end + for k, surface in pairs(icw.surfaces) do + if not icw.trains[tonumber(surface.name)] then + game.delete_surface(surface) + table_remove(icw.surfaces, k) + end + end +end local function connect_power_pole(entity, wagon_area_left_top_y) - local surface = entity.surface - local max_wire_distance = entity.prototype.max_wire_distance - local area = { - {entity.position.x - max_wire_distance, entity.position.y - max_wire_distance}, - {entity.position.x + max_wire_distance, entity.position.y - 1}, - } - for _, pole in pairs(surface.find_entities_filtered({area = area, name = entity.name})) do - if pole.position.y < wagon_area_left_top_y then - entity.connect_neighbour(pole) - return - end - end + local surface = entity.surface + local max_wire_distance = entity.prototype.max_wire_distance + local area = { + {entity.position.x - max_wire_distance, entity.position.y - max_wire_distance}, + {entity.position.x + max_wire_distance, entity.position.y - 1} + } + for _, pole in pairs(surface.find_entities_filtered({area = area, name = entity.name})) do + if pole.position.y < wagon_area_left_top_y then + entity.connect_neighbour(pole) + return + end + end end local function equal_fluid(source_tank, target_tank) - local source_fluid = source_tank.fluidbox[1] - if not source_fluid then return end - - local target_fluid = target_tank.fluidbox[1] - local source_fluid_amount = source_fluid.amount - - local amount - if target_fluid then - amount = source_fluid_amount - ((target_fluid.amount + source_fluid_amount) * 0.5) - else - amount = source_fluid.amount * 0.5 - end - - if amount <= 0 then return end - - local inserted_amount = target_tank.insert_fluid({name = source_fluid.name, amount = amount, temperature = source_fluid.temperature}) - if inserted_amount > 0 then source_tank.remove_fluid({name = source_fluid.name, amount = inserted_amount}) end + local source_fluid = source_tank.fluidbox[1] + if not source_fluid then + return + end + + local target_fluid = target_tank.fluidbox[1] + local source_fluid_amount = source_fluid.amount + + local amount + if target_fluid then + amount = source_fluid_amount - ((target_fluid.amount + source_fluid_amount) * 0.5) + else + amount = source_fluid.amount * 0.5 + end + + if amount <= 0 then + return + end + + local inserted_amount = + target_tank.insert_fluid({name = source_fluid.name, amount = amount, temperature = source_fluid.temperature}) + if inserted_amount > 0 then + source_tank.remove_fluid({name = source_fluid.name, amount = inserted_amount}) + end end local function divide_fluid(wagon, storage_tank) - local fluid_wagon = wagon.entity - equal_fluid(fluid_wagon, storage_tank) - equal_fluid(storage_tank, fluid_wagon) + local fluid_wagon = wagon.entity + equal_fluid(fluid_wagon, storage_tank) + equal_fluid(storage_tank, fluid_wagon) end local function input_filtered(wagon_inventory, chest, chest_inventory, free_slots) - local request_stacks = {} - local prototypes = game.item_prototypes - for slot_index = 1, 4, 1 do - local stack = chest.get_request_slot(slot_index) - if stack then - request_stacks[stack.name] = 10 * prototypes[stack.name].stack_size - end - end - for i = 1, wagon_inventory.get_bar() - 1, 1 do - if free_slots <= 0 then return end - local stack = wagon_inventory[i] - if stack.valid_for_read then - local request_stack = request_stacks[stack.name] - if request_stack and request_stack > chest_inventory.get_item_count(stack.name) then - chest_inventory.insert(stack) - stack.clear() - free_slots = free_slots - 1 - end - end - end + local request_stacks = {} + local prototypes = game.item_prototypes + for slot_index = 1, 4, 1 do + local stack = chest.get_request_slot(slot_index) + if stack then + request_stacks[stack.name] = 10 * prototypes[stack.name].stack_size + end + end + for i = 1, wagon_inventory.get_bar() - 1, 1 do + if free_slots <= 0 then + return + end + local stack = wagon_inventory[i] + if stack.valid_for_read then + local request_stack = request_stacks[stack.name] + if request_stack and request_stack > chest_inventory.get_item_count(stack.name) then + chest_inventory.insert(stack) + stack.clear() + free_slots = free_slots - 1 + end + end + end end local function input_cargo(wagon, chest) - if not chest.request_from_buffers then return end - - local wagon_entity = wagon.entity - if not wagon_entity.valid then - wagon.transfer_entities = nil - return - end - - local wagon_inventory = wagon_entity.get_inventory(defines.inventory.cargo_wagon) - if wagon_inventory.is_empty() then return end - - local chest_inventory = chest.get_inventory(defines.inventory.chest) - local free_slots = 0 - for i = 1, chest_inventory.get_bar() - 1, 1 do - if not chest_inventory[i].valid_for_read then free_slots = free_slots + 1 end - end - - if chest.get_request_slot(1) then input_filtered(wagon_inventory, chest, chest_inventory, free_slots) return end - - for i = 1, wagon_inventory.get_bar() - 1, 1 do - if free_slots <= 0 then return end - if wagon_inventory[i].valid_for_read then - chest_inventory.insert(wagon_inventory[i]) - wagon_inventory[i].clear() - free_slots = free_slots - 1 - end - end + if not chest.request_from_buffers then + return + end + + local wagon_entity = wagon.entity + if not wagon_entity.valid then + wagon.transfer_entities = nil + return + end + + local wagon_inventory = wagon_entity.get_inventory(defines.inventory.cargo_wagon) + if wagon_inventory.is_empty() then + return + end + + local chest_inventory = chest.get_inventory(defines.inventory.chest) + local free_slots = 0 + for i = 1, chest_inventory.get_bar() - 1, 1 do + if not chest_inventory[i].valid_for_read then + free_slots = free_slots + 1 + end + end + + if chest.get_request_slot(1) then + input_filtered(wagon_inventory, chest, chest_inventory, free_slots) + return + end + + for i = 1, wagon_inventory.get_bar() - 1, 1 do + if free_slots <= 0 then + return + end + if wagon_inventory[i].valid_for_read then + chest_inventory.insert(wagon_inventory[i]) + wagon_inventory[i].clear() + free_slots = free_slots - 1 + end + end end local function output_cargo(wagon, passive_chest) - local passive_chest_inventory = passive_chest.get_inventory(defines.inventory.cargo_wagon) - if passive_chest_inventory.is_empty() then return end - local wagon_inventory = wagon.entity.get_inventory(defines.inventory.cargo_wagon) - local free_slots = 0 - for i = 1, wagon_inventory.get_bar() - 1, 1 do - if not wagon_inventory[i].valid_for_read and not wagon_inventory.get_filter(i) then free_slots = free_slots + 1 end - end - for i = 1, passive_chest_inventory.get_bar() - 1, 1 do - if free_slots <= 0 then return end - if passive_chest_inventory[i].valid_for_read then - wagon_inventory.insert(passive_chest_inventory[i]) - passive_chest_inventory[i].clear() - free_slots = free_slots - 1 - end - end + local passive_chest_inventory = passive_chest.get_inventory(defines.inventory.cargo_wagon) + if passive_chest_inventory.is_empty() then + return + end + local wagon_inventory = wagon.entity.get_inventory(defines.inventory.cargo_wagon) + local free_slots = 0 + for i = 1, wagon_inventory.get_bar() - 1, 1 do + if not wagon_inventory[i].valid_for_read and not wagon_inventory.get_filter(i) then + free_slots = free_slots + 1 + end + end + for i = 1, passive_chest_inventory.get_bar() - 1, 1 do + if free_slots <= 0 then + return + end + if passive_chest_inventory[i].valid_for_read then + wagon_inventory.insert(passive_chest_inventory[i]) + passive_chest_inventory[i].clear() + free_slots = free_slots - 1 + end + end end local transfer_functions = { - ["storage-tank"] = divide_fluid, - ["logistic-chest-requester"] = input_cargo, - ["logistic-chest-passive-provider"] = output_cargo, + ['storage-tank'] = divide_fluid, + ['logistic-chest-requester'] = input_cargo, + ['logistic-chest-passive-provider'] = output_cargo } local function get_wagon_for_entity(icw, entity) - local train = icw.trains[tonumber(entity.surface.name)] - if not train then return end - local position = entity.position - for k, unit_number in pairs(train.wagons) do - local wagon = icw.wagons[unit_number] - if wagon then - local left_top = wagon.area.left_top - local right_bottom = wagon.area.right_bottom - if position.x >= left_top.x and position.y >= left_top.y and position.x <= right_bottom.x and position.y <= right_bottom.y then - return wagon - end - end - end - return false + local train = icw.trains[tonumber(entity.surface.name)] + if not train then + return + end + local position = entity.position + for k, unit_number in pairs(train.wagons) do + local wagon = icw.wagons[unit_number] + if wagon then + local left_top = wagon.area.left_top + local right_bottom = wagon.area.right_bottom + if + position.x >= left_top.x and position.y >= left_top.y and position.x <= right_bottom.x and + position.y <= right_bottom.y + then + return wagon + end + end + end + return false end local function kill_wagon_doors(icw, wagon) - for k, e in pairs(wagon.doors) do - icw.doors[e.unit_number] = nil - e.destroy() - wagon.doors[k] = nil - end + for k, e in pairs(wagon.doors) do + icw.doors[e.unit_number] = nil + e.destroy() + wagon.doors[k] = nil + end end local function construct_wagon_doors(icw, wagon) - local area = wagon.area - local surface = wagon.surface - - for _, x in pairs({area.left_top.x - 0.55, area.right_bottom.x + 0.55}) do - local e = surface.create_entity({ - name = "car", - position = {x, area.left_top.y + ((area.right_bottom.y - area.left_top.y) * 0.5)}, - force = "neutral", - create_build_effect_smoke = false - }) - e.get_inventory(defines.inventory.fuel).insert({name = "wood", count = 1}) - e.destructible = false - e.minable = false - e.operable = false - icw.doors[e.unit_number] = wagon.entity.unit_number - table_insert(wagon.doors, e) - end + local area = wagon.area + local surface = wagon.surface + + for _, x in pairs({area.left_top.x - 0.55, area.right_bottom.x + 0.55}) do + local e = + surface.create_entity( + { + name = 'car', + position = {x, area.left_top.y + ((area.right_bottom.y - area.left_top.y) * 0.5)}, + force = 'neutral', + create_build_effect_smoke = false + } + ) + e.get_inventory(defines.inventory.fuel).insert({name = 'wood', count = 1}) + e.destructible = false + e.minable = false + e.operable = false + icw.doors[e.unit_number] = wagon.entity.unit_number + table_insert(wagon.doors, e) + end end local function get_player_data(icw, player) - local player_data = icw.players[player.index] - if icw.players[player.index] then return player_data end - - icw.players[player.index] = { - zoom = 0.30, - map_size = 360, - } - return icw.players[player.index] + local player_data = icw.players[player.index] + if icw.players[player.index] then + return player_data + end + + icw.players[player.index] = { + zoom = 0.30, + map_size = 360 + } + return icw.players[player.index] end function Public.kill_minimap(player) - local element = player.gui.left.icw_map - if element then element.destroy() end + local element = player.gui.left.icw_map + if element then + element.destroy() + end end function Public.kill_wagon(icw, entity) - if not Constants.wagon_types[entity.type] then return end - local wagon = icw.wagons[entity.unit_number] - local surface = wagon.surface - kill_wagon_doors(icw, wagon) - for _, e in pairs(surface.find_entities_filtered({area = wagon.area})) do - if e.name == "character" and e.player then - local p = wagon.entity.surface.find_non_colliding_position("character", wagon.entity.position, 128, 0.5) - if p then - e.player.teleport(p, wagon.entity.surface) - else - e.player.teleport(wagon.entity.position, wagon.entity.surface) - end - Public.kill_minimap(e.player) - else - e.die() - end - end - for _, tile in pairs(surface.find_tiles_filtered({area = wagon.area})) do - surface.set_tiles({{name = "out-of-map", position = tile.position}}, true) - end - wagon.entity.force.chart(surface, wagon.area) - icw.wagons[entity.unit_number] = nil - Public.request_reconstruction(icw) + if not Constants.wagon_types[entity.type] then + return + end + local wagon = icw.wagons[entity.unit_number] + local surface = wagon.surface + kill_wagon_doors(icw, wagon) + for _, e in pairs(surface.find_entities_filtered({area = wagon.area})) do + if e.name == 'character' and e.player then + local p = wagon.entity.surface.find_non_colliding_position('character', wagon.entity.position, 128, 0.5) + if p then + e.player.teleport(p, wagon.entity.surface) + else + e.player.teleport(wagon.entity.position, wagon.entity.surface) + end + Public.kill_minimap(e.player) + else + e.die() + end + end + for _, tile in pairs(surface.find_tiles_filtered({area = wagon.area})) do + surface.set_tiles({{name = 'out-of-map', position = tile.position}}, true) + end + wagon.entity.force.chart(surface, wagon.area) + icw.wagons[entity.unit_number] = nil + Public.request_reconstruction(icw) end function Public.create_room_surface(icw, unit_number) - if game.surfaces[tostring(unit_number)] then return game.surfaces[tostring(unit_number)] end - local map_gen_settings = { - ["width"] = 2, - ["height"] = 2, - ["water"] = 0, - ["starting_area"] = 1, - ["cliff_settings"] = {cliff_elevation_interval = 0, cliff_elevation_0 = 0}, - ["default_enable_all_autoplace_controls"] = true, - ["autoplace_settings"] = { - ["entity"] = {treat_missing_as_default = false}, - ["tile"] = {treat_missing_as_default = true}, - ["decorative"] = {treat_missing_as_default = false}, - }, - } - local surface = game.create_surface(unit_number, map_gen_settings) - surface.freeze_daytime = true - surface.daytime = 0.1 - surface.request_to_generate_chunks({16, 16}, 2) - surface.force_generate_chunk_requests() - for _, tile in pairs(surface.find_tiles_filtered({area = {{-2, -2}, {2, 2}}})) do - surface.set_tiles({{name = "out-of-map", position = tile.position}}, true) - end - table_insert(icw.surfaces, surface) - return surface + if game.surfaces[tostring(unit_number)] then + return game.surfaces[tostring(unit_number)] + end + local map_gen_settings = { + ['width'] = 2, + ['height'] = 2, + ['water'] = 0, + ['starting_area'] = 1, + ['cliff_settings'] = {cliff_elevation_interval = 0, cliff_elevation_0 = 0}, + ['default_enable_all_autoplace_controls'] = true, + ['autoplace_settings'] = { + ['entity'] = {treat_missing_as_default = false}, + ['tile'] = {treat_missing_as_default = true}, + ['decorative'] = {treat_missing_as_default = false} + } + } + local surface = game.create_surface(unit_number, map_gen_settings) + surface.freeze_daytime = true + surface.daytime = 0.1 + surface.request_to_generate_chunks({16, 16}, 2) + surface.force_generate_chunk_requests() + for _, tile in pairs(surface.find_tiles_filtered({area = {{-2, -2}, {2, 2}}})) do + surface.set_tiles({{name = 'out-of-map', position = tile.position}}, true) + end + table_insert(icw.surfaces, surface) + return surface end function Public.create_wagon_room(icw, wagon) - local surface = wagon.surface - local area = wagon.area - - local main_tile_name = "tutorial-grid" - --if wagon.entity.type == "locomotive" then - -- main_tile_name = "lab-dark-2" - --end - - local tiles = {} - for x = -3, 2, 1 do - table_insert(tiles, {name = "hazard-concrete-right", position = {x, area.left_top.y}}) - table_insert(tiles, {name = "hazard-concrete-right", position = {x, area.right_bottom.y - 1}}) - end - for x = area.left_top.x, area.right_bottom.x - 1, 1 do - for y = area.left_top.y + 2, area.right_bottom.y - 3, 1 do - table_insert(tiles, {name = main_tile_name, position = {x, y}}) - end - end - for x = -3, 2, 1 do - for y = 1, 3, 1 do - table_insert(tiles, {name = main_tile_name, position = {x,y}}) - end - for y = area.right_bottom.y - 4, area.right_bottom.y - 2, 1 do - table_insert(tiles, {name = main_tile_name, position = {x,y}}) - end - end - - if wagon.entity.type == "locomotive" then - for x = -3, 2, 1 do - for y = 10, 12, 1 do - table_insert(tiles, {name = "water", position = {x, y}}) - end - end - end - - surface.set_tiles(tiles, true) - - construct_wagon_doors(icw, wagon) - - if wagon.entity.type == "fluid-wagon" then - local height = area.right_bottom.y - area.left_top.y - local positions = { - {area.right_bottom.x, area.left_top.y + height * 0.25}, - {area.right_bottom.x, area.left_top.y + height * 0.75}, - {area.left_top.x - 1, area.left_top.y + height * 0.25}, - {area.left_top.x - 1, area.left_top.y + height * 0.75}, - } - table.shuffle_table(positions) - local e = surface.create_entity({ - name = "storage-tank", - position = positions[1], - force = "neutral", - create_build_effect_smoke = false - }) - e.destructible = false - e.minable = false - wagon.transfer_entities = {e} - return - end - - if wagon.entity.type == "cargo-wagon" then - local vectors = {{0, -1}, {0, 1}, {-1, 0}, {1, 0}} - local v = vectors[math_random(1, 4)] - local position = {math_random(area.left_top.x + 4, area.right_bottom.x - 4), math_random(area.left_top.y + 6, area.right_bottom.y - 6)} - - local e = surface.create_entity({ - name = "logistic-chest-requester", - position = position, - force = "neutral", - create_build_effect_smoke = false - }) - e.destructible = false - e.minable = false - - local e2 = surface.create_entity({ - name = "logistic-chest-passive-provider", - position = {position[1] + v[1], position[2] + v[2]}, - force = "neutral", - create_build_effect_smoke = false - }) - e2.destructible = false - e2.minable = false - - wagon.transfer_entities = {e, e2} - return - end + local surface = wagon.surface + local area = wagon.area + + local main_tile_name = 'tutorial-grid' + --if wagon.entity.type == "locomotive" then + -- main_tile_name = "lab-dark-2" + --end + + local tiles = {} + for x = -3, 2, 1 do + table_insert(tiles, {name = 'hazard-concrete-right', position = {x, area.left_top.y}}) + table_insert(tiles, {name = 'hazard-concrete-right', position = {x, area.right_bottom.y - 1}}) + end + for x = area.left_top.x, area.right_bottom.x - 1, 1 do + for y = area.left_top.y + 2, area.right_bottom.y - 3, 1 do + table_insert(tiles, {name = main_tile_name, position = {x, y}}) + end + end + for x = -3, 2, 1 do + for y = 1, 3, 1 do + table_insert(tiles, {name = main_tile_name, position = {x, y}}) + end + for y = area.right_bottom.y - 4, area.right_bottom.y - 2, 1 do + table_insert(tiles, {name = main_tile_name, position = {x, y}}) + end + end + + if wagon.entity.type == 'locomotive' then + for x = -3, 2, 1 do + for y = 10, 12, 1 do + table_insert(tiles, {name = 'water', position = {x, y}}) + end + end + end + + surface.set_tiles(tiles, true) + + construct_wagon_doors(icw, wagon) + + if wagon.entity.type == 'fluid-wagon' then + local height = area.right_bottom.y - area.left_top.y + local positions = { + {area.right_bottom.x, area.left_top.y + height * 0.25}, + {area.right_bottom.x, area.left_top.y + height * 0.75}, + {area.left_top.x - 1, area.left_top.y + height * 0.25}, + {area.left_top.x - 1, area.left_top.y + height * 0.75} + } + table.shuffle_table(positions) + local e = + surface.create_entity( + { + name = 'storage-tank', + position = positions[1], + force = 'neutral', + create_build_effect_smoke = false + } + ) + e.destructible = false + e.minable = false + wagon.transfer_entities = {e} + return + end + + if wagon.entity.type == 'cargo-wagon' then + local vectors = {{0, -1}, {0, 1}, {-1, 0}, {1, 0}} + local v = vectors[math_random(1, 4)] + local position = { + math_random(area.left_top.x + 4, area.right_bottom.x - 4), + math_random(area.left_top.y + 6, area.right_bottom.y - 6) + } + + local e = + surface.create_entity( + { + name = 'logistic-chest-requester', + position = position, + force = 'neutral', + create_build_effect_smoke = false + } + ) + e.destructible = false + e.minable = false + + local e2 = + surface.create_entity( + { + name = 'logistic-chest-passive-provider', + position = {position[1] + v[1], position[2] + v[2]}, + force = 'neutral', + create_build_effect_smoke = false + } + ) + e2.destructible = false + e2.minable = false + + wagon.transfer_entities = {e, e2} + return + end end function Public.create_wagon(icw, created_entity, delay_surface) - if not created_entity.unit_number then return end - if icw.trains[tonumber(created_entity.surface.name)] or icw.wagons[tonumber(created_entity.surface.name)] then return end - if not Constants.wagon_types[created_entity.type] then return end - local wagon_area = Constants.wagon_areas[created_entity.type] - - icw.wagons[created_entity.unit_number] = { - entity = created_entity, - area = {left_top = {x = wagon_area.left_top.x, y = wagon_area.left_top.y}, right_bottom = {x = wagon_area.right_bottom.x, y = wagon_area.right_bottom.y}}, - doors = {}, - entity_count = 0, - } - local wagon = icw.wagons[created_entity.unit_number] - - if not delay_surface then - wagon.surface = Public.create_room_surface(icw, created_entity.unit_number) - Public.create_wagon_room(icw, icw.wagons[created_entity.unit_number]) - end - - Public.request_reconstruction(icw) - return wagon + if not created_entity.unit_number then + return + end + if icw.trains[tonumber(created_entity.surface.name)] or icw.wagons[tonumber(created_entity.surface.name)] then + return + end + if not Constants.wagon_types[created_entity.type] then + return + end + local wagon_area = Constants.wagon_areas[created_entity.type] + + icw.wagons[created_entity.unit_number] = { + entity = created_entity, + area = { + left_top = {x = wagon_area.left_top.x, y = wagon_area.left_top.y}, + right_bottom = {x = wagon_area.right_bottom.x, y = wagon_area.right_bottom.y} + }, + doors = {}, + entity_count = 0 + } + local wagon = icw.wagons[created_entity.unit_number] + + if not delay_surface then + wagon.surface = Public.create_room_surface(icw, created_entity.unit_number) + Public.create_wagon_room(icw, icw.wagons[created_entity.unit_number]) + end + + Public.request_reconstruction(icw) + return wagon end function Public.add_wagon_entity_count(icw, added_entity) - local wagon = get_wagon_for_entity(icw, added_entity) - if not wagon then return end - wagon.entity_count = wagon.entity_count + 1 - wagon.entity.minable = false + local wagon = get_wagon_for_entity(icw, added_entity) + if not wagon then + return + end + wagon.entity_count = wagon.entity_count + 1 + wagon.entity.minable = false end -function Public.subtract_wagon_entity_count(icw, removed_entity) - local wagon = get_wagon_for_entity(icw, removed_entity) - if not wagon then return end - wagon.entity_count = wagon.entity_count - 1 - if wagon.entity_count > 0 then return end - wagon.entity.minable = true +function Public.subtract_wagon_entity_count(icw, removed_entity) + local wagon = get_wagon_for_entity(icw, removed_entity) + if not wagon then + return + end + wagon.entity_count = wagon.entity_count - 1 + if wagon.entity_count > 0 then + return + end + wagon.entity.minable = true end -function Public.use_cargo_wagon_door(icw, player, door) - local player_data = get_player_data(icw, player) - if player_data.state then - player_data.state = player_data.state - 1 - if player_data.state == 0 then - player_data.state = nil - end - return - end +function Public.use_cargo_wagon_door(icw, player, door) + local player_data = get_player_data(icw, player) + if player_data.state then + player_data.state = player_data.state - 1 + if player_data.state == 0 then + player_data.state = nil + end + return + end - if not door then return end - if not door.valid then return end - local doors = icw.doors - local wagons = icw.wagons - - local wagon = false - if doors[door.unit_number] then wagon = wagons[doors[door.unit_number]] end - if wagons[door.unit_number] then wagon = wagons[door.unit_number] end - if not wagon then return end + if not door then + return + end + if not door.valid then + return + end + local doors = icw.doors + local wagons = icw.wagons - if wagon.entity.surface.name ~= player.surface.name then - local surface = wagon.entity.surface - local x_vector = (door.position.x / math.abs(door.position.x)) * 2 - local position = {wagon.entity.position.x + x_vector, wagon.entity.position.y} - local position = surface.find_non_colliding_position("character", position, 128, 0.5) - if not position then return end - if wagon.entity.type == "locomotive" then - player.teleport(position, surface) - player_data.state = 2 - player.driving = true - Public.kill_minimap(player) - else - player.teleport(position, surface) - Public.kill_minimap(player) - end - else - local surface = wagon.surface - local area = wagon.area - local x_vector = door.position.x - player.position.x - local position - if x_vector > 0 then - position = {area.left_top.x + 0.5, area.left_top.y + ((area.right_bottom.y - area.left_top.y) * 0.5)} - else - position = {area.right_bottom.x - 0.5, area.left_top.y + ((area.right_bottom.y - area.left_top.y) * 0.5)} - end - local p = surface.find_non_colliding_position("character", position, 128, 0.5) - if p then - player.teleport(p, surface) - else - player.teleport(position, surface) - end - end + local wagon = false + if doors[door.unit_number] then + wagon = wagons[doors[door.unit_number]] + end + if wagons[door.unit_number] then + wagon = wagons[door.unit_number] + end + if not wagon then + return + end + + if wagon.entity.surface.name ~= player.surface.name then + local surface = wagon.entity.surface + local x_vector = (door.position.x / math.abs(door.position.x)) * 2 + local position = {wagon.entity.position.x + x_vector, wagon.entity.position.y} + local position = surface.find_non_colliding_position('character', position, 128, 0.5) + if not position then + return + end + if wagon.entity.type == 'locomotive' then + player.teleport(position, surface) + player_data.state = 2 + player.driving = true + Public.kill_minimap(player) + else + player.teleport(position, surface) + Public.kill_minimap(player) + end + else + local surface = wagon.surface + local area = wagon.area + local x_vector = door.position.x - player.position.x + local position + if x_vector > 0 then + position = {area.left_top.x + 0.5, area.left_top.y + ((area.right_bottom.y - area.left_top.y) * 0.5)} + else + position = {area.right_bottom.x - 0.5, area.left_top.y + ((area.right_bottom.y - area.left_top.y) * 0.5)} + end + local p = surface.find_non_colliding_position('character', position, 128, 0.5) + if p then + player.teleport(p, surface) + else + player.teleport(position, surface) + end + end end local function move_room_to_train(icw, train, wagon) - if not wagon then return end - - table_insert(train.wagons, wagon.entity.unit_number) + if not wagon then + return + end - local destination_area = { - left_top = {x = wagon.area.left_top.x, y = train.top_y}, - right_bottom = {x = wagon.area.right_bottom.x, y = train.top_y + (wagon.area.right_bottom.y - wagon.area.left_top.y)} - } + table_insert(train.wagons, wagon.entity.unit_number) - train.top_y = destination_area.right_bottom.y + local destination_area = { + left_top = {x = wagon.area.left_top.x, y = train.top_y}, + right_bottom = { + x = wagon.area.right_bottom.x, + y = train.top_y + (wagon.area.right_bottom.y - wagon.area.left_top.y) + } + } - if destination_area.left_top.x == wagon.area.left_top.x and destination_area.left_top.y == wagon.area.left_top.y and wagon.surface.name == train.surface.name then return end + train.top_y = destination_area.right_bottom.y - kill_wagon_doors(icw, wagon) + if + destination_area.left_top.x == wagon.area.left_top.x and destination_area.left_top.y == wagon.area.left_top.y and + wagon.surface.name == train.surface.name + then + return + end - local player_positions = {} - for _, e in pairs(wagon.surface.find_entities_filtered({name = "character", area = wagon.area})) do - local player = e.player - if player then - player_positions[player.index] = {player.position.x, player.position.y + (destination_area.left_top.y - wagon.area.left_top.y)} - player.teleport({0,0}, game.surfaces.nauvis) - end - end + kill_wagon_doors(icw, wagon) - wagon.surface.clone_area({ - source_area = wagon.area, - destination_area = destination_area, - destination_surface = train.surface, - clone_tiles = true, - clone_entities = true, - clone_decoratives = true, - clear_destination_entities = true, - clear_destination_decoratives = true, - expand_map = true, - }) + local player_positions = {} + for _, e in pairs(wagon.surface.find_entities_filtered({name = 'character', area = wagon.area})) do + local player = e.player + if player then + player_positions[player.index] = { + player.position.x, + player.position.y + (destination_area.left_top.y - wagon.area.left_top.y) + } + player.teleport({0, 0}, game.surfaces.nauvis) + end + end - for player_index, position in pairs(player_positions) do - local player = game.players[player_index] - player.teleport(position, train.surface) - end + wagon.surface.clone_area( + { + source_area = wagon.area, + destination_area = destination_area, + destination_surface = train.surface, + clone_tiles = true, + clone_entities = true, + clone_decoratives = true, + clear_destination_entities = true, + clear_destination_decoratives = true, + expand_map = true + } + ) - for _, tile in pairs(wagon.surface.find_tiles_filtered({area = wagon.area})) do - wagon.surface.set_tiles({{name = "out-of-map", position = tile.position}}, true) - end - wagon.entity.force.chart(wagon.surface, wagon.area) + for player_index, position in pairs(player_positions) do + local player = game.players[player_index] + player.teleport(position, train.surface) + end - wagon.surface = train.surface - wagon.area = destination_area - wagon.transfer_entities = {} - construct_wagon_doors(icw, wagon) + for _, tile in pairs(wagon.surface.find_tiles_filtered({area = wagon.area})) do + wagon.surface.set_tiles({{name = 'out-of-map', position = tile.position}}, true) + end + wagon.entity.force.chart(wagon.surface, wagon.area) - local left_top_y = wagon.area.left_top.y - for _, e in pairs(wagon.surface.find_entities_filtered({type = "electric-pole", area = wagon.area})) do - connect_power_pole(e, left_top_y) - end + wagon.surface = train.surface + wagon.area = destination_area + wagon.transfer_entities = {} + construct_wagon_doors(icw, wagon) - for _, e in pairs(wagon.surface.find_entities_filtered({area = wagon.area, force = "neutral"})) do - if transfer_functions[e.name] then - table_insert(wagon.transfer_entities, e) - end - end + local left_top_y = wagon.area.left_top.y + for _, e in pairs(wagon.surface.find_entities_filtered({type = 'electric-pole', area = wagon.area})) do + connect_power_pole(e, left_top_y) + end + + for _, e in pairs(wagon.surface.find_entities_filtered({area = wagon.area, force = 'neutral'})) do + if transfer_functions[e.name] then + table_insert(wagon.transfer_entities, e) + end + end end function Public.construct_train(icw, carriages) - local unit_number = carriages[1].unit_number + local unit_number = carriages[1].unit_number - if icw.trains[unit_number] then return end + if icw.trains[unit_number] then + return + end - local train = {surface = Public.create_room_surface(icw, unit_number), wagons = {}, top_y = 0} - icw.trains[unit_number] = train + local train = {surface = Public.create_room_surface(icw, unit_number), wagons = {}, top_y = 0} + icw.trains[unit_number] = train - for k, carriage in pairs(carriages) do - move_room_to_train(icw, train, icw.wagons[carriage.unit_number]) - end + for k, carriage in pairs(carriages) do + move_room_to_train(icw, train, icw.wagons[carriage.unit_number]) + end end function Public.reconstruct_all_trains(icw) - icw.trains = {} - for unit_number, wagon in pairs(icw.wagons) do - if not wagon.entity or not wagon.entity.valid then - icw.wagons[unit_number] = nil - Public.request_reconstruction(icw) - return - end - - if not wagon.surface then - wagon.surface = Public.create_room_surface(icw, unit_number) - Public.create_wagon_room(icw, wagon) - end - - local carriages = wagon.entity.train.carriages - Public.construct_train(icw, carriages) - end - delete_empty_surfaces(icw) + icw.trains = {} + for unit_number, wagon in pairs(icw.wagons) do + if not wagon.entity or not wagon.entity.valid then + icw.wagons[unit_number] = nil + Public.request_reconstruction(icw) + return + end + + if not wagon.surface then + wagon.surface = Public.create_room_surface(icw, unit_number) + Public.create_wagon_room(icw, wagon) + end + + local carriages = wagon.entity.train.carriages + Public.construct_train(icw, carriages) + end + delete_empty_surfaces(icw) end function Public.item_transfer(icw) - for _, wagon in pairs(icw.wagons) do - if not wagon and not wagon.valid then return end - if wagon.transfer_entities then - for k, e in pairs(wagon.transfer_entities) do - transfer_functions[e.name](wagon, e) - end - end - end + for _, wagon in pairs(icw.wagons) do + if not wagon and not wagon.valid then + return + end + if wagon.transfer_entities then + if not wagon and not wagon.valid then + return + end + + for k, e in pairs(wagon.transfer_entities) do + transfer_functions[e.name](wagon, e) + end + end + end end function Public.draw_minimap(icw, player, surface, position) - local element = player.gui.left.icw_map - if not element then - local player_data = get_player_data(icw, player) - element = player.gui.left.add({ - type = "camera", - name = "icw_map", - position = position, - surface_index = surface.index, - zoom = player_data.zoom, - tooltip = "LMB: Increase zoom level.\nRMB: Decrease zoom level.\nMMB: Toggle camera size." - }) - element.style.margin = 1 - element.style.minimal_height = player_data.map_size - element.style.minimal_width = player_data.map_size - return - end - element.position = position + local element = player.gui.left.icw_map + if not element then + local player_data = get_player_data(icw, player) + element = + player.gui.left.add( + { + type = 'camera', + name = 'icw_map', + position = position, + surface_index = surface.index, + zoom = player_data.zoom, + tooltip = 'LMB: Increase zoom level.\nRMB: Decrease zoom level.\nMMB: Toggle camera size.' + } + ) + element.style.margin = 1 + element.style.minimal_height = player_data.map_size + element.style.minimal_width = player_data.map_size + return + end + element.position = position end function Public.update_minimap(icw) - for k, player in pairs(game.connected_players) do - if player.character and player.character.valid then - local wagon = get_wagon_for_entity(icw, player.character) - if wagon then - Public.draw_minimap(icw, player, wagon.entity.surface, wagon.entity.position) - end - end - end + for k, player in pairs(game.connected_players) do + if player.character and player.character.valid then + local wagon = get_wagon_for_entity(icw, player.character) + if wagon then + Public.draw_minimap(icw, player, wagon.entity.surface, wagon.entity.position) + end + end + end end function Public.toggle_minimap(icw, event) - local element = event.element - if not element then return end - if not element.valid then return end - if element.name ~= "icw_map" then return end - local player = game.players[event.player_index] - local player_data = get_player_data(icw, player) - if event.button == defines.mouse_button_type.right then - player_data.zoom = player_data.zoom - 0.07 - if player_data.zoom < 0.07 then player_data.zoom = 0.07 end - element.zoom = player_data.zoom - return - end - if event.button == defines.mouse_button_type.left then - player_data.zoom = player_data.zoom + 0.07 - if player_data.zoom > 2 then player_data.zoom = 2 end - element.zoom = player_data.zoom - return - end - if event.button == defines.mouse_button_type.middle then - player_data.map_size = player_data.map_size + 50 - if player_data.map_size > 650 then player_data.map_size = 250 end - element.style.minimal_height = player_data.map_size - element.style.minimal_width = player_data.map_size - element.style.maximal_height = player_data.map_size - element.style.maximal_width = player_data.map_size - return - end + local element = event.element + if not element then + return + end + if not element.valid then + return + end + if element.name ~= 'icw_map' then + return + end + local player = game.players[event.player_index] + local player_data = get_player_data(icw, player) + if event.button == defines.mouse_button_type.right then + player_data.zoom = player_data.zoom - 0.07 + if player_data.zoom < 0.07 then + player_data.zoom = 0.07 + end + element.zoom = player_data.zoom + return + end + if event.button == defines.mouse_button_type.left then + player_data.zoom = player_data.zoom + 0.07 + if player_data.zoom > 2 then + player_data.zoom = 2 + end + element.zoom = player_data.zoom + return + end + if event.button == defines.mouse_button_type.middle then + player_data.map_size = player_data.map_size + 50 + if player_data.map_size > 650 then + player_data.map_size = 250 + end + element.style.minimal_height = player_data.map_size + element.style.minimal_width = player_data.map_size + element.style.maximal_height = player_data.map_size + element.style.maximal_width = player_data.map_size + return + end end -return Public \ No newline at end of file +return Public diff --git a/maps/scrapyard/icw/main.lua b/maps/scrapyard/icw/main.lua index 77aa1bc8..1c2803f9 100644 --- a/maps/scrapyard/icw/main.lua +++ b/maps/scrapyard/icw/main.lua @@ -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 \ No newline at end of file +return Public diff --git a/maps/scrapyard/locomotive.lua b/maps/scrapyard/locomotive.lua index 011cee7e..8588a508 100644 --- a/maps/scrapyard/locomotive.lua +++ b/maps/scrapyard/locomotive.lua @@ -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) diff --git a/maps/scrapyard/loot.lua b/maps/scrapyard/loot.lua index 26c6280c..ded4d51a 100644 --- a/maps/scrapyard/loot.lua +++ b/maps/scrapyard/loot.lua @@ -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 diff --git a/maps/scrapyard/main.lua b/maps/scrapyard/main.lua index a35d0ae0..ebc29e98 100644 --- a/maps/scrapyard/main.lua +++ b/maps/scrapyard/main.lua @@ -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 diff --git a/maps/scrapyard/mineable_wreckage_yields_scrap.lua b/maps/scrapyard/mineable_wreckage_yields_scrap.lua index 79eab32d..4feb154d 100644 --- a/maps/scrapyard/mineable_wreckage_yields_scrap.lua +++ b/maps/scrapyard/mineable_wreckage_yields_scrap.lua @@ -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] diff --git a/maps/scrapyard/rpg.lua b/maps/scrapyard/rpg.lua index 8f0831b1..f00821d0 100644 --- a/maps/scrapyard/rpg.lua +++ b/maps/scrapyard/rpg.lua @@ -12,12 +12,11 @@ VITALITY > character_health_bonus Modified by Gerkiz *-* ]] - -require "player_modifiers" +require 'player_modifiers' local Global = require 'utils.global' -local Tabs = require "comfy_panel.main" -local P = require "player_modifiers" +local Tabs = require 'comfy_panel.main' +local P = require 'player_modifiers' local math_floor = math.floor local math_random = math.random @@ -29,24 +28,34 @@ local level_up_floating_text_color = {0, 205, 0} local xp_floating_text_color = {157, 157, 157} local experience_levels = {0} for a = 1, 9999, 1 do - experience_levels[#experience_levels + 1] = experience_levels[#experience_levels] + a * 8 + experience_levels[#experience_levels + 1] = experience_levels[#experience_levels] + a * 8 end -local gain_info_tooltip = "XP gain from mining, moving, crafting, repairing and combat." -local reset_tooltip = "ONE-TIME reset if you picked the wrong path (this will keep your points)" -local reset_not_available = "Available after level 20." +local gain_info_tooltip = 'XP gain from mining, moving, crafting, repairing and combat.' +local reset_tooltip = 'ONE-TIME reset if you picked the wrong path (this will keep your points)' +local reset_not_available = 'Available after level 20.' local rpg_t = {} local rpg_frame_icons = { - "entity/small-worm-turret", "entity/medium-worm-turret", "entity/big-worm-turret", "entity/behemoth-worm-turret", - "entity/small-biter", "entity/small-biter", "entity/small-spitter", "entity/medium-biter", "entity/medium-biter", - "entity/medium-spitter", "entity/big-biter", "entity/big-biter", "entity/big-spitter", "entity/behemoth-biter", "entity/behemoth-biter", - "entity/behemoth-spitter" + 'entity/small-worm-turret', + 'entity/medium-worm-turret', + 'entity/big-worm-turret', + 'entity/behemoth-worm-turret', + 'entity/small-biter', + 'entity/small-biter', + 'entity/small-spitter', + 'entity/medium-biter', + 'entity/medium-biter', + 'entity/medium-spitter', + 'entity/big-biter', + 'entity/big-biter', + 'entity/big-spitter', + 'entity/behemoth-biter', + 'entity/behemoth-biter', + 'entity/behemoth-spitter' } - - Global.register( - {rpg_t=rpg_t, rpg_frame_icons=rpg_frame_icons}, + {rpg_t = rpg_t, rpg_frame_icons = rpg_frame_icons}, function(tbl) rpg_t = tbl.rpg_t rpg_frame_icons = tbl.rpg_frame_icons @@ -56,874 +65,1129 @@ Global.register( local Public = {} function Public.get_table() - return rpg_t + return rpg_t end local classes = { - ["engineer"] = "ENGINEER", - ["strength"] = "MINER", - ["magic"] = "SORCERER", - ["dexterity"] = "ROGUE", - ["vitality"] = "TANK", + ['engineer'] = 'ENGINEER', + ['strength'] = 'MINER', + ['magic'] = 'SORCERER', + ['dexterity'] = 'ROGUE', + ['vitality'] = 'TANK' } local function level_up_effects(player) - local position = {x = player.position.x - 0.75, y = player.position.y - 1} - player.surface.create_entity({name = "flying-text", position = position, text = "+LVL ", color = level_up_floating_text_color}) - local b = 0.75 - for a = 1, 5, 1 do - local p = {(position.x + 0.4) + (b * -1 + math_random(0, b * 20) * 0.1), position.y + (b * -1 + math_random(0, b * 20) * 0.1)} - player.surface.create_entity({name = "flying-text", position = p, text = "✚", color = {255, math_random(0, 100), 0}}) - end - player.play_sound{path="utility/achievement_unlocked", volume_modifier=0.40} + local position = {x = player.position.x - 0.75, y = player.position.y - 1} + player.surface.create_entity( + {name = 'flying-text', position = position, text = '+LVL ', color = level_up_floating_text_color} + ) + local b = 0.75 + for a = 1, 5, 1 do + local p = { + (position.x + 0.4) + (b * -1 + math_random(0, b * 20) * 0.1), + position.y + (b * -1 + math_random(0, b * 20) * 0.1) + } + player.surface.create_entity( + {name = 'flying-text', position = p, text = '✚', color = {255, math_random(0, 100), 0}} + ) + end + player.play_sound {path = 'utility/achievement_unlocked', volume_modifier = 0.40} end -local function get_melee_modifier(player) return (rpg_t[player.index].strength - 10) * 0.10 end +local function get_melee_modifier(player) + return (rpg_t[player.index].strength - 10) * 0.10 +end -local function get_life_on_hit(player) return (rpg_t[player.index].vitality - 10) * 0.4 end +local function get_life_on_hit(player) + return (rpg_t[player.index].vitality - 10) * 0.4 +end local function get_one_punch_chance(player) - if rpg_t[player.index].strength < 100 then return 0 end - local chance = math.round(rpg_t[player.index].strength * 0.01, 1) - if chance > 100 then chance = 100 end - return chance + if rpg_t[player.index].strength < 100 then + return 0 + end + local chance = math.round(rpg_t[player.index].strength * 0.01, 1) + if chance > 100 then + chance = 100 + end + return chance end local function draw_gui_char_button(player) - if player.gui.top.rpg then return end - local b = player.gui.top.add({type = "sprite-button", name = "rpg", caption = "CHAR"}) - b.style.font_color = {165,165,165} - b.style.font = "heading-1" - b.style.minimal_height = 38 - b.style.minimal_width = 60 - b.style.padding = 0 - b.style.margin = 0 + if player.gui.top.rpg then + return + end + local b = player.gui.top.add({type = 'sprite-button', name = 'rpg', caption = 'CHAR'}) + b.style.font_color = {165, 165, 165} + b.style.font = 'heading-1' + b.style.minimal_height = 38 + b.style.minimal_width = 60 + b.style.padding = 0 + b.style.margin = 0 end local function update_char_button(player) - if not player.gui.top.rpg then draw_gui_char_button(player) end - if rpg_t[player.index].points_to_distribute > 0 then - player.gui.top.rpg.style.font_color = {245, 0, 0} - else - player.gui.top.rpg.style.font_color = {175,175,175} - end + if not player.gui.top.rpg then + draw_gui_char_button(player) + end + if rpg_t[player.index].points_to_distribute > 0 then + player.gui.top.rpg.style.font_color = {245, 0, 0} + else + player.gui.top.rpg.style.font_color = {175, 175, 175} + end end local function update_player_stats(player) - local player_modifiers = P.get_table() - local strength = rpg_t[player.index].strength - 10 - player_modifiers[player.index].character_inventory_slots_bonus["rpg"] = math.round(strength * 0.2, 3) - player_modifiers[player.index].character_mining_speed_modifier["rpg"] = math.round(strength * 0.008, 3) - - local magic = rpg_t[player.index].magic - 10 - local v = magic * 0.22 - player_modifiers[player.index].character_build_distance_bonus["rpg"] = math.round(v, 3) - player_modifiers[player.index].character_item_drop_distance_bonus["rpg"] = math.round(v, 3) - player_modifiers[player.index].character_reach_distance_bonus["rpg"] = math.round(v, 3) - player_modifiers[player.index].character_loot_pickup_distance_bonus["rpg"] = math.round(v * 0.5, 3) - player_modifiers[player.index].character_item_pickup_distance_bonus["rpg"] = math.round(v * 0.25, 3) - player_modifiers[player.index].character_resource_reach_distance_bonus["rpg"] = math.round(v * 0.15, 3) - - local dexterity = rpg_t[player.index].dexterity - 10 - player_modifiers[player.index].character_running_speed_modifier["rpg"] = math.round(dexterity * 0.002, 3) - player_modifiers[player.index].character_crafting_speed_modifier["rpg"] = math.round(dexterity * 0.015, 3) - - player_modifiers[player.index].character_health_bonus["rpg"] = math.round((rpg_t[player.index].vitality - 10) * 6, 3) + local player_modifiers = P.get_table() + local strength = rpg_t[player.index].strength - 10 + player_modifiers[player.index].character_inventory_slots_bonus['rpg'] = math.round(strength * 0.2, 3) + player_modifiers[player.index].character_mining_speed_modifier['rpg'] = math.round(strength * 0.008, 3) - P.update_player_modifiers(player) + local magic = rpg_t[player.index].magic - 10 + local v = magic * 0.22 + player_modifiers[player.index].character_build_distance_bonus['rpg'] = math.round(v, 3) + player_modifiers[player.index].character_item_drop_distance_bonus['rpg'] = math.round(v, 3) + player_modifiers[player.index].character_reach_distance_bonus['rpg'] = math.round(v, 3) + player_modifiers[player.index].character_loot_pickup_distance_bonus['rpg'] = math.round(v * 0.5, 3) + player_modifiers[player.index].character_item_pickup_distance_bonus['rpg'] = math.round(v * 0.25, 3) + player_modifiers[player.index].character_resource_reach_distance_bonus['rpg'] = math.round(v * 0.15, 3) + + local dexterity = rpg_t[player.index].dexterity - 10 + player_modifiers[player.index].character_running_speed_modifier['rpg'] = math.round(dexterity * 0.002, 3) + player_modifiers[player.index].character_crafting_speed_modifier['rpg'] = math.round(dexterity * 0.015, 3) + + player_modifiers[player.index].character_health_bonus['rpg'] = + math.round((rpg_t[player.index].vitality - 10) * 6, 3) + + P.update_player_modifiers(player) end local function get_class(player) - local average = (rpg_t[player.index].strength + rpg_t[player.index].magic + rpg_t[player.index].dexterity + rpg_t[player.index].vitality) / 4 - local high_attribute = 0 - local high_attribute_name = "" - for _, attribute in pairs({"strength", "magic", "dexterity", "vitality"}) do - if rpg_t[player.index][attribute] > high_attribute then - high_attribute = rpg_t[player.index][attribute] - high_attribute_name = attribute - end - end - if high_attribute < average + average * 0.25 then high_attribute_name = "engineer" end - return classes[high_attribute_name] + local average = + (rpg_t[player.index].strength + rpg_t[player.index].magic + rpg_t[player.index].dexterity + + rpg_t[player.index].vitality) / + 4 + local high_attribute = 0 + local high_attribute_name = '' + for _, attribute in pairs({'strength', 'magic', 'dexterity', 'vitality'}) do + if rpg_t[player.index][attribute] > high_attribute then + high_attribute = rpg_t[player.index][attribute] + high_attribute_name = attribute + end + end + if high_attribute < average + average * 0.25 then + high_attribute_name = 'engineer' + end + return classes[high_attribute_name] end local function add_gui_description(element, value, width) - local e = element.add({type = "label", caption = value}) - e.style.single_line = false - e.style.maximal_width = width - e.style.minimal_width = width - e.style.maximal_height = 40 - e.style.minimal_height = 38 - e.style.font = "default-bold" - e.style.font_color = {175, 175, 200} - e.style.horizontal_align = "right" - e.style.vertical_align = "center" - return e + local e = element.add({type = 'label', caption = value}) + e.style.single_line = false + e.style.maximal_width = width + e.style.minimal_width = width + e.style.maximal_height = 40 + e.style.minimal_height = 38 + e.style.font = 'default-bold' + e.style.font_color = {175, 175, 200} + e.style.horizontal_align = 'right' + e.style.vertical_align = 'center' + return e end local function add_gui_stat(element, value, width) - local e = element.add({type = "sprite-button", caption = value}) - e.style.maximal_width = width - e.style.minimal_width = width - e.style.maximal_height = 38 - e.style.minimal_height = 38 - e.style.font = "default-bold" - e.style.font_color = {222, 222, 222} - e.style.horizontal_align = "center" - e.style.vertical_align = "center" - return e + local e = element.add({type = 'sprite-button', caption = value}) + e.style.maximal_width = width + e.style.minimal_width = width + e.style.maximal_height = 38 + e.style.minimal_height = 38 + e.style.font = 'default-bold' + e.style.font_color = {222, 222, 222} + e.style.horizontal_align = 'center' + e.style.vertical_align = 'center' + return e end local function add_gui_increase_stat(element, name, player, width) - local sprite = "virtual-signal/signal-red" - local symbol = "✚" - if rpg_t[player.index].points_to_distribute <= 0 then sprite = "virtual-signal/signal-black" end - local e = element.add({type = "sprite-button", name = name, caption = symbol, sprite = sprite}) - e.style.maximal_height = 38 - e.style.minimal_height = 38 - e.style.maximal_width = 38 - e.style.minimal_width = 38 - e.style.font = "default-large-semibold" - e.style.font_color = {0,0,0} - e.style.horizontal_align = "center" - e.style.vertical_align = "center" - e.style.padding = 0 - e.style.margin = 0 - e.tooltip = "Right-click to allocate 3 points." - - return e + local sprite = 'virtual-signal/signal-red' + local symbol = '✚' + if rpg_t[player.index].points_to_distribute <= 0 then + sprite = 'virtual-signal/signal-black' + end + local e = element.add({type = 'sprite-button', name = name, caption = symbol, sprite = sprite}) + e.style.maximal_height = 38 + e.style.minimal_height = 38 + e.style.maximal_width = 38 + e.style.minimal_width = 38 + e.style.font = 'default-large-semibold' + e.style.font_color = {0, 0, 0} + e.style.horizontal_align = 'center' + e.style.vertical_align = 'center' + e.style.padding = 0 + e.style.margin = 0 + e.tooltip = 'Right-click to allocate 3 points.' + + return e end local function add_separator(element, width) - local e = element.add({type = "line"}) - e.style.maximal_width = width - e.style.minimal_width = width - e.style.minimal_height = 12 - return e + local e = element.add({type = 'line'}) + e.style.maximal_width = width + e.style.minimal_width = width + e.style.minimal_height = 12 + return e end local function draw_gui(player, forced) - if not forced then - if rpg_t[player.index].gui_refresh_delay > game.tick then return end - end - - Tabs.comfy_panel_clear_left_gui(player) - - if player.gui.left.rpg then player.gui.left.rpg.destroy() end - if not player.character then return end - - local frame = player.gui.left.add({type = "frame", name = "rpg", direction = "vertical"}) - frame.style.maximal_width = 425 - frame.style.minimal_width = 425 - frame.style.margin = 6 - - add_separator(frame, 400) - - local t = frame.add({type = "table", column_count = 2}) - local e = add_gui_stat(t, player.name, 200) - e.style.font_color = player.chat_color - e.style.font = "default-large-bold" - local e = add_gui_stat(t, get_class(player), 200) - e.style.font = "default-large-bold" - - add_separator(frame, 400) - - local t = frame.add({type = "table", column_count = 4}) - t.style.cell_padding = 1 - - add_gui_description(t, "LEVEL", 80) - local e = add_gui_stat(t, rpg_t[player.index].level, 80) - e.tooltip = gain_info_tooltip + if not forced then + if rpg_t[player.index].gui_refresh_delay > game.tick then + return + end + end - add_gui_description(t, "EXPERIENCE", 100) - local e = add_gui_stat(t, math.floor(rpg_t[player.index].xp), 125) - e.tooltip = gain_info_tooltip + Tabs.comfy_panel_clear_left_gui(player) - if not rpg_t[player.index].reset then - add_gui_description(t, "RESET", 80) - local e = add_gui_stat(t, rpg_t[player.index].reset, 80) - if rpg_t[player.index].level <= 19 then - e.tooltip = reset_not_available - else - e.tooltip = reset_tooltip - end - else - add_gui_description(t, " ", 75) - add_gui_description(t, " ", 75) - end + if player.gui.left.rpg then + player.gui.left.rpg.destroy() + end + if not player.character then + return + end - add_gui_description(t, "NEXT LEVEL", 100) - local e = add_gui_stat(t, experience_levels[rpg_t[player.index].level + 1], 125) - e.tooltip = gain_info_tooltip - - add_separator(frame, 400) - - local t = frame.add({type = "table", column_count = 2}) - local tt = t.add({type = "table", column_count = 3}) - tt.style.cell_padding = 1 - local w1 = 85 - local w2 = 63 - - local tip = "Increases inventory slots and mining speed.\nIncreases melee damage." - local e = add_gui_description(tt, "STRENGTH", w1) - e.tooltip = tip - local e = add_gui_stat(tt, rpg_t[player.index].strength, w2) - e.tooltip = tip - add_gui_increase_stat(tt, "strength", player) - - local tip = "Increases reach distance." - local e = add_gui_description(tt, "MAGIC", w1) - e.tooltip = tip - local e = add_gui_stat(tt, rpg_t[player.index].magic, w2) - e.tooltip = tip - add_gui_increase_stat(tt, "magic", player) - - local tip = "Increases running and crafting speed." - local e = add_gui_description(tt, "DEXTERITY", w1) - e.tooltip = tip - local e = add_gui_stat(tt, rpg_t[player.index].dexterity, w2) - e.tooltip = tip - add_gui_increase_stat(tt, "dexterity", player) - - local tip = "Increases health.\nIncreases melee life on-hit." - local e = add_gui_description(tt, "VITALITY", w1) - e.tooltip = tip - local e = add_gui_stat(tt, rpg_t[player.index].vitality, w2) - e.tooltip = tip - add_gui_increase_stat(tt, "vitality", player) - - add_gui_description(tt, "POINTS TO\nDISTRIBUTE", w1) - local e = add_gui_stat(tt, rpg_t[player.index].points_to_distribute, w2) - e.style.font_color = {200, 0, 0} - add_gui_description(tt, " ", w2) - - add_gui_description(tt, " ", w1) - add_gui_description(tt, " ", w2) - add_gui_description(tt, " ", w2) - - add_gui_description(tt, "LIFE", w1) - add_gui_stat(tt, math.floor(player.character.health), w2) - add_gui_stat(tt, math.floor(player.character.prototype.max_health + player.character_health_bonus + player.force.character_health_bonus), w2) + local frame = player.gui.left.add({type = 'frame', name = 'rpg', direction = 'vertical'}) + frame.style.maximal_width = 425 + frame.style.minimal_width = 425 + frame.style.margin = 6 - local shield = 0 - local shield_max = 0 - local i = player.character.get_inventory(defines.inventory.character_armor) - if not i.is_empty() then - if i[1].grid then - shield = math.floor(i[1].grid.shield) - shield_max = math.floor(i[1].grid.max_shield) - end - end - add_gui_description(tt, "SHIELD", w1) - add_gui_stat(tt, shield, w2) - add_gui_stat(tt, shield_max, w2) - - - local tt = t.add({type = "table", column_count = 3}) - tt.style.cell_padding = 1 - local w0 = 2 - local w1 = 80 - local w2 = 80 - - add_gui_description(tt, " ", w0) - add_gui_description(tt, "MINING\nSPEED", w1) - local value = math_round((player.force.manual_mining_speed_modifier + player.character_mining_speed_modifier + 1) * 100) .. "%" - add_gui_stat(tt, value, w2) - - add_gui_description(tt, " ", w0) - add_gui_description(tt, "SLOT\nBONUS", w1) - local value = "+ " .. math_round(player.force.character_inventory_slots_bonus + player.character_inventory_slots_bonus) - add_gui_stat(tt, value, w2) - - add_gui_description(tt, " ", w0) - add_gui_description(tt, "MELEE\nDAMAGE", w1) - local value = math_round(100 * (1 + get_melee_modifier(player))) .. "%" - local e = add_gui_stat(tt, value, w2) - e.tooltip = "Life on-hit: " .. get_life_on_hit(player) .. "\nOne punch chance: " .. get_one_punch_chance(player) .. "%" - - local e = add_gui_description(tt, "", w0) - e.style.maximal_height = 10 - local e = add_gui_description(tt, "", w0) - e.style.maximal_height = 10 - local e = add_gui_description(tt, "", w0) - e.style.maximal_height = 10 - - local value = "+ " .. (player.force.character_reach_distance_bonus + player.character_reach_distance_bonus) - local tooltip = "" - tooltip = tooltip .. "Reach distance bonus: " .. player.character_reach_distance_bonus - tooltip = tooltip .. "\nBuild distance bonus: " .. player.character_build_distance_bonus - tooltip = tooltip .. "\nItem drop distance bonus: " .. player.character_item_drop_distance_bonus - tooltip = tooltip .. "\nLoot pickup distance bonus: " .. player.character_loot_pickup_distance_bonus - tooltip = tooltip .. "\nItem pickup distance bonus: " .. player.character_item_pickup_distance_bonus - tooltip = tooltip .. "\nResource reach distance bonus: " .. player.character_resource_reach_distance_bonus - add_gui_description(tt, " ", w0) - local e = add_gui_description(tt, "REACH\nDISTANCE", w1) - e.tooltip = tooltip - local e = add_gui_stat(tt, value, w2) - e.tooltip = tooltip - - local e = add_gui_description(tt, "", w0) - e.style.maximal_height = 10 - local e = add_gui_description(tt, "", w0) - e.style.maximal_height = 10 - local e = add_gui_description(tt, "", w0) - e.style.maximal_height = 10 - - add_gui_description(tt, " ", w0) - add_gui_description(tt, "CRAFTING\nSPEED", w1) - local value = math_round((player.force.manual_crafting_speed_modifier + player.character_crafting_speed_modifier + 1) * 100) .. "%" - add_gui_stat(tt, value, w2) - - add_gui_description(tt, " ", w0) - add_gui_description(tt, "RUNNING\nSPEED", w1) - local value = math_round((player.force.character_running_speed_modifier + player.character_running_speed_modifier + 1) * 100) .. "%" - add_gui_stat(tt, value, w2) - - local e = add_gui_description(tt, "", w0) - e.style.maximal_height = 10 - local e = add_gui_description(tt, "", w0) - e.style.maximal_height = 10 - local e = add_gui_description(tt, "", w0) - e.style.maximal_height = 10 - - add_gui_description(tt, " ", w0) - add_gui_description(tt, "HEALTH\nBONUS", w1) - local value = "+ " .. math_round((player.force.character_health_bonus + player.character_health_bonus)) - add_gui_stat(tt, value, w2) - - add_separator(frame, 400) - local t = frame.add({type = "table", column_count = 14}) - for i = 1, 14, 1 do - local e = t.add({type = "sprite", sprite = rpg_frame_icons[i]}) - e.style.maximal_width = 24 - e.style.maximal_height = 24 - e.style.padding = 0 - end - add_separator(frame, 400) - - rpg_t[player.index].gui_refresh_delay = game.tick + 60 - update_char_button(player) + add_separator(frame, 400) + + local t = frame.add({type = 'table', column_count = 2}) + local e = add_gui_stat(t, player.name, 200) + e.style.font_color = player.chat_color + e.style.font = 'default-large-bold' + local e = add_gui_stat(t, get_class(player), 200) + e.style.font = 'default-large-bold' + + add_separator(frame, 400) + + local t = frame.add({type = 'table', column_count = 4}) + t.style.cell_padding = 1 + + add_gui_description(t, 'LEVEL', 80) + local e = add_gui_stat(t, rpg_t[player.index].level, 80) + e.tooltip = gain_info_tooltip + + add_gui_description(t, 'EXPERIENCE', 100) + local e = add_gui_stat(t, math.floor(rpg_t[player.index].xp), 125) + e.tooltip = gain_info_tooltip + + if not rpg_t[player.index].reset then + add_gui_description(t, 'RESET', 80) + local e = add_gui_stat(t, rpg_t[player.index].reset, 80) + if rpg_t[player.index].level <= 19 then + e.tooltip = reset_not_available + else + e.tooltip = reset_tooltip + end + else + add_gui_description(t, ' ', 75) + add_gui_description(t, ' ', 75) + end + + add_gui_description(t, 'NEXT LEVEL', 100) + local e = add_gui_stat(t, experience_levels[rpg_t[player.index].level + 1], 125) + e.tooltip = gain_info_tooltip + + add_separator(frame, 400) + + local t = frame.add({type = 'table', column_count = 2}) + local tt = t.add({type = 'table', column_count = 3}) + tt.style.cell_padding = 1 + local w1 = 85 + local w2 = 63 + + local tip = 'Increases inventory slots and mining speed.\nIncreases melee damage.' + local e = add_gui_description(tt, 'STRENGTH', w1) + e.tooltip = tip + local e = add_gui_stat(tt, rpg_t[player.index].strength, w2) + e.tooltip = tip + add_gui_increase_stat(tt, 'strength', player) + + local tip = 'Increases reach distance.' + local e = add_gui_description(tt, 'MAGIC', w1) + e.tooltip = tip + local e = add_gui_stat(tt, rpg_t[player.index].magic, w2) + e.tooltip = tip + add_gui_increase_stat(tt, 'magic', player) + + local tip = 'Increases running and crafting speed.' + local e = add_gui_description(tt, 'DEXTERITY', w1) + e.tooltip = tip + local e = add_gui_stat(tt, rpg_t[player.index].dexterity, w2) + e.tooltip = tip + add_gui_increase_stat(tt, 'dexterity', player) + + local tip = 'Increases health.\nIncreases melee life on-hit.' + local e = add_gui_description(tt, 'VITALITY', w1) + e.tooltip = tip + local e = add_gui_stat(tt, rpg_t[player.index].vitality, w2) + e.tooltip = tip + add_gui_increase_stat(tt, 'vitality', player) + + add_gui_description(tt, 'POINTS TO\nDISTRIBUTE', w1) + local e = add_gui_stat(tt, rpg_t[player.index].points_to_distribute, w2) + e.style.font_color = {200, 0, 0} + add_gui_description(tt, ' ', w2) + + add_gui_description(tt, ' ', w1) + add_gui_description(tt, ' ', w2) + add_gui_description(tt, ' ', w2) + + add_gui_description(tt, 'LIFE', w1) + add_gui_stat(tt, math.floor(player.character.health), w2) + add_gui_stat( + tt, + math.floor( + player.character.prototype.max_health + player.character_health_bonus + player.force.character_health_bonus + ), + w2 + ) + + local shield = 0 + local shield_max = 0 + local i = player.character.get_inventory(defines.inventory.character_armor) + if not i.is_empty() then + if i[1].grid then + shield = math.floor(i[1].grid.shield) + shield_max = math.floor(i[1].grid.max_shield) + end + end + add_gui_description(tt, 'SHIELD', w1) + add_gui_stat(tt, shield, w2) + add_gui_stat(tt, shield_max, w2) + + local tt = t.add({type = 'table', column_count = 3}) + tt.style.cell_padding = 1 + local w0 = 2 + local w1 = 80 + local w2 = 80 + + add_gui_description(tt, ' ', w0) + add_gui_description(tt, 'MINING\nSPEED', w1) + local value = + math_round((player.force.manual_mining_speed_modifier + player.character_mining_speed_modifier + 1) * 100) .. + '%' + add_gui_stat(tt, value, w2) + + add_gui_description(tt, ' ', w0) + add_gui_description(tt, 'SLOT\nBONUS', w1) + local value = + '+ ' .. math_round(player.force.character_inventory_slots_bonus + player.character_inventory_slots_bonus) + add_gui_stat(tt, value, w2) + + add_gui_description(tt, ' ', w0) + add_gui_description(tt, 'MELEE\nDAMAGE', w1) + local value = math_round(100 * (1 + get_melee_modifier(player))) .. '%' + local e = add_gui_stat(tt, value, w2) + e.tooltip = + 'Life on-hit: ' .. get_life_on_hit(player) .. '\nOne punch chance: ' .. get_one_punch_chance(player) .. '%' + + local e = add_gui_description(tt, '', w0) + e.style.maximal_height = 10 + local e = add_gui_description(tt, '', w0) + e.style.maximal_height = 10 + local e = add_gui_description(tt, '', w0) + e.style.maximal_height = 10 + + local value = '+ ' .. (player.force.character_reach_distance_bonus + player.character_reach_distance_bonus) + local tooltip = '' + tooltip = tooltip .. 'Reach distance bonus: ' .. player.character_reach_distance_bonus + tooltip = tooltip .. '\nBuild distance bonus: ' .. player.character_build_distance_bonus + tooltip = tooltip .. '\nItem drop distance bonus: ' .. player.character_item_drop_distance_bonus + tooltip = tooltip .. '\nLoot pickup distance bonus: ' .. player.character_loot_pickup_distance_bonus + tooltip = tooltip .. '\nItem pickup distance bonus: ' .. player.character_item_pickup_distance_bonus + tooltip = tooltip .. '\nResource reach distance bonus: ' .. player.character_resource_reach_distance_bonus + add_gui_description(tt, ' ', w0) + local e = add_gui_description(tt, 'REACH\nDISTANCE', w1) + e.tooltip = tooltip + local e = add_gui_stat(tt, value, w2) + e.tooltip = tooltip + + local e = add_gui_description(tt, '', w0) + e.style.maximal_height = 10 + local e = add_gui_description(tt, '', w0) + e.style.maximal_height = 10 + local e = add_gui_description(tt, '', w0) + e.style.maximal_height = 10 + + add_gui_description(tt, ' ', w0) + add_gui_description(tt, 'CRAFTING\nSPEED', w1) + local value = + math_round((player.force.manual_crafting_speed_modifier + player.character_crafting_speed_modifier + 1) * 100) .. + '%' + add_gui_stat(tt, value, w2) + + add_gui_description(tt, ' ', w0) + add_gui_description(tt, 'RUNNING\nSPEED', w1) + local value = + math_round((player.force.character_running_speed_modifier + player.character_running_speed_modifier + 1) * 100) .. + '%' + add_gui_stat(tt, value, w2) + + local e = add_gui_description(tt, '', w0) + e.style.maximal_height = 10 + local e = add_gui_description(tt, '', w0) + e.style.maximal_height = 10 + local e = add_gui_description(tt, '', w0) + e.style.maximal_height = 10 + + add_gui_description(tt, ' ', w0) + add_gui_description(tt, 'HEALTH\nBONUS', w1) + local value = '+ ' .. math_round((player.force.character_health_bonus + player.character_health_bonus)) + add_gui_stat(tt, value, w2) + + add_separator(frame, 400) + local t = frame.add({type = 'table', column_count = 14}) + for i = 1, 14, 1 do + local e = t.add({type = 'sprite', sprite = rpg_frame_icons[i]}) + e.style.maximal_width = 24 + e.style.maximal_height = 24 + e.style.padding = 0 + end + add_separator(frame, 400) + + rpg_t[player.index].gui_refresh_delay = game.tick + 60 + update_char_button(player) end local function draw_level_text(player) - if not player.character then return end - - if rpg_t[player.index].text then - rendering.destroy(rpg_t[player.index].text) - rpg_t[player.index].text = nil - end + if not player.character then + return + end - local players = {} - for _, p in pairs(game.players) do - if p.index ~= player.index then - players[#players + 1] = p.index - end - end - if #players == 0 then return end - - rpg_t[player.index].text = rendering.draw_text{ - text = "lvl " .. rpg_t[player.index].level, - surface = player.surface, - target = player.character, - target_offset = {0, -3.25}, - color = { - r = player.color.r * 0.6 + 0.25, - g = player.color.g * 0.6 + 0.25, - b = player.color.b * 0.6 + 0.25, - a = 1 - }, - players = players, - scale = 1.00, - font = "default-large-semibold", - alignment = "center", - scale_with_zoom = false - } + if rpg_t[player.index].text then + rendering.destroy(rpg_t[player.index].text) + rpg_t[player.index].text = nil + end + + local players = {} + for _, p in pairs(game.players) do + if p.index ~= player.index then + players[#players + 1] = p.index + end + end + if #players == 0 then + return + end + + rpg_t[player.index].text = + rendering.draw_text { + text = 'lvl ' .. rpg_t[player.index].level, + surface = player.surface, + target = player.character, + target_offset = {0, -3.25}, + color = { + r = player.color.r * 0.6 + 0.25, + g = player.color.g * 0.6 + 0.25, + b = player.color.b * 0.6 + 0.25, + a = 1 + }, + players = players, + scale = 1.00, + font = 'default-large-semibold', + alignment = 'center', + scale_with_zoom = false + } end local function level_up(player) - local distribute_points_gain = 0 - for i = rpg_t[player.index].level + 1, #experience_levels, 1 do - if rpg_t[player.index].xp > experience_levels[i] then - rpg_t[player.index].level = i - distribute_points_gain = distribute_points_gain + 3 - else - break - end - end - if distribute_points_gain == 0 then return end - draw_level_text(player) - rpg_t[player.index].points_to_distribute = rpg_t[player.index].points_to_distribute + distribute_points_gain - update_char_button(player) - table.shuffle_table(rpg_frame_icons) - if player.gui.left.rpg then draw_gui(player, true) end - level_up_effects(player) + local distribute_points_gain = 0 + for i = rpg_t[player.index].level + 1, #experience_levels, 1 do + if rpg_t[player.index].xp > experience_levels[i] then + rpg_t[player.index].level = i + distribute_points_gain = distribute_points_gain + 3 + else + break + end + end + if distribute_points_gain == 0 then + return + end + draw_level_text(player) + rpg_t[player.index].points_to_distribute = rpg_t[player.index].points_to_distribute + distribute_points_gain + update_char_button(player) + table.shuffle_table(rpg_frame_icons) + if player.gui.left.rpg then + draw_gui(player, true) + end + level_up_effects(player) end function Public.gain_xp(player, amount) - local fee - if rpg_t[player.index].xp > 50 then - fee = amount * 0.3 - else - fee = 0 - end - amount = math_round(amount, 2) - fee - rpg_t.global_pool = rpg_t.global_pool + fee - rpg_t[player.index].xp = rpg_t[player.index].xp + amount - rpg_t[player.index].xp_since_last_floaty_text = rpg_t[player.index].xp_since_last_floaty_text + amount - if player.gui.left.rpg then draw_gui(player, false) end - if not experience_levels[rpg_t[player.index].level + 1] then return end - if rpg_t[player.index].xp >= experience_levels[rpg_t[player.index].level + 1] then - level_up(player) - return - end - if rpg_t[player.index].last_floaty_text > game.tick then return end - player.create_local_flying_text{text="+" .. math_round(rpg_t[player.index].xp_since_last_floaty_text) .. " xp", position=player.position, color=xp_floating_text_color, time_to_live=120, speed=2} - rpg_t[player.index].xp_since_last_floaty_text = 0 - rpg_t[player.index].last_floaty_text = game.tick + visuals_delay + local fee + if rpg_t[player.index].xp > 50 then + fee = amount * 0.3 + else + fee = 0 + end + amount = math_round(amount, 2) - fee + rpg_t.global_pool = rpg_t.global_pool + fee + rpg_t[player.index].xp = rpg_t[player.index].xp + amount + rpg_t[player.index].xp_since_last_floaty_text = rpg_t[player.index].xp_since_last_floaty_text + amount + if player.gui.left.rpg then + draw_gui(player, false) + end + if not experience_levels[rpg_t[player.index].level + 1] then + return + end + if rpg_t[player.index].xp >= experience_levels[rpg_t[player.index].level + 1] then + level_up(player) + return + end + if rpg_t[player.index].last_floaty_text > game.tick then + return + end + player.create_local_flying_text { + text = '+' .. math_round(rpg_t[player.index].xp_since_last_floaty_text) .. ' xp', + position = player.position, + color = xp_floating_text_color, + time_to_live = 120, + speed = 2 + } + rpg_t[player.index].xp_since_last_floaty_text = 0 + rpg_t[player.index].last_floaty_text = game.tick + visuals_delay end local function global_pool() - local pool = rpg_t.global_pool - if pool <= 5000 then return end - local player_count = #game.connected_players - local share = pool / player_count - if player_count <= 20 then - share = share / 3 - end - rpg_t.global_pool = 0 - for _, p in pairs(game.connected_players) do - if rpg_t[p.index].level < 10 and p.online_time < 50000 then - local s = share * 2 - p.create_local_flying_text{text="+" .. s .. " xp", position=p.position, color=xp_floating_text_color, time_to_live=240, speed=1} - Public.gain_xp(p, s * 2) - else - p.create_local_flying_text{text="+" .. share .. " xp", position=p.position, color=xp_floating_text_color, time_to_live=240, speed=1} - rpg_t[p.index].xp_since_last_floaty_text = 0 - Public.gain_xp(p, share) - end - end - return + local pool = rpg_t.global_pool + if pool <= 5000 then + return + end + local player_count = #game.connected_players + local share = pool / player_count + if player_count <= 20 then + share = share / 3 + end + rpg_t.global_pool = 0 + for _, p in pairs(game.connected_players) do + if rpg_t[p.index].level < 10 and p.online_time < 50000 then + local s = share * 2 + p.create_local_flying_text { + text = '+' .. s .. ' xp', + position = p.position, + color = xp_floating_text_color, + time_to_live = 240, + speed = 1 + } + Public.gain_xp(p, s * 2) + else + p.create_local_flying_text { + text = '+' .. share .. ' xp', + position = p.position, + color = xp_floating_text_color, + time_to_live = 240, + speed = 1 + } + rpg_t[p.index].xp_since_last_floaty_text = 0 + Public.gain_xp(p, share) + end + end + return end function Public.rpg_reset_player(player, one_time_reset) - if player.gui.left.rpg then player.gui.left.rpg.destroy() end - if not player.character then - player.set_controller({type=defines.controllers.god}) - player.create_character() - end - if one_time_reset then - local total = rpg_t[player.index].total - local old_level = rpg_t[player.index].level - local old_xp = rpg_t[player.index].xp - rpg_t[player.index] = { - level = 1, xp = 0, strength = 10, magic = 10, dexterity = 10, vitality = 10, points_to_distribute = 0, - last_floaty_text = visuals_delay, xp_since_last_floaty_text = 0, reset = true, bonus = 1, - rotated_entity_delay = 0, gui_refresh_delay = 0, last_mined_entity_position = {x = 0, y = 0}, - } - rpg_t[player.index].points_to_distribute = total - rpg_t[player.index].xp = old_xp - rpg_t[player.index].level = old_level - else - rpg_t[player.index] = { - level = 1, xp = 0, strength = 10, magic = 10, dexterity = 10, vitality = 10, points_to_distribute = 0, - last_floaty_text = visuals_delay, xp_since_last_floaty_text = 0, reset = false, total = 0, bonus = 1, - rotated_entity_delay = 0, gui_refresh_delay = 0, last_mined_entity_position = {x = 0, y = 0}, - } - end - draw_gui_char_button(player) - draw_level_text(player) - update_char_button(player) - update_player_stats(player) + if player.gui.left.rpg then + player.gui.left.rpg.destroy() + end + if not player.character then + player.set_controller({type = defines.controllers.god}) + player.create_character() + end + if one_time_reset then + local total = rpg_t[player.index].total + local old_level = rpg_t[player.index].level + local old_xp = rpg_t[player.index].xp + rpg_t[player.index] = { + level = 1, + xp = 0, + strength = 10, + magic = 10, + dexterity = 10, + vitality = 10, + points_to_distribute = 0, + last_floaty_text = visuals_delay, + xp_since_last_floaty_text = 0, + reset = true, + bonus = 1, + rotated_entity_delay = 0, + gui_refresh_delay = 0, + last_mined_entity_position = {x = 0, y = 0} + } + rpg_t[player.index].points_to_distribute = total + rpg_t[player.index].xp = old_xp + rpg_t[player.index].level = old_level + else + rpg_t[player.index] = { + level = 1, + xp = 0, + strength = 10, + magic = 10, + dexterity = 10, + vitality = 10, + points_to_distribute = 0, + last_floaty_text = visuals_delay, + xp_since_last_floaty_text = 0, + reset = false, + total = 0, + bonus = 1, + rotated_entity_delay = 0, + gui_refresh_delay = 0, + last_mined_entity_position = {x = 0, y = 0} + } + end + draw_gui_char_button(player) + draw_level_text(player) + update_char_button(player) + update_player_stats(player) end function Public.rpg_reset_all_players() - for _, p in pairs(game.players) do - rpg_t[p.index] = nil - end - for _, p in pairs(game.connected_players) do - Public.rpg_reset_player(p) - end + for _, p in pairs(game.players) do + rpg_t[p.index] = nil + end + for _, p in pairs(game.connected_players) do + Public.rpg_reset_player(p) + end end local function on_gui_click(event) - if not event.element then return end - if not event.element.valid then return end - local element = event.element - local player = game.players[event.player_index] - - if element.type ~= "sprite-button" then return end - - if element.caption == "CHAR" then - if element.name == "rpg" then - if player.gui.left.rpg then - player.gui.left.rpg.destroy() - return - end - draw_gui(player, true) - end - end + if not event.element then + return + end + if not event.element.valid then + return + end + local element = event.element + local player = game.players[event.player_index] - if element.caption == "false" then - if rpg_t[player.index].level <= 19 then return end - rpg_t[player.index].reset = true - Public.rpg_reset_player(player, true) - return - end - - if element.caption ~= "✚" then return end - if element.sprite ~= "virtual-signal/signal-red" then return end - - local index = element.name - if not rpg_t[player.index][index] then return end - if not player.character then return end - - if event.button == defines.mouse_button_type.right then - for a = 1, 3, 1 do - if rpg_t[player.index].points_to_distribute <= 0 then draw_gui(player, true) return end - if not rpg_t[player.index].reset then - rpg_t[player.index].total = rpg_t[player.index].total + 1 - end - rpg_t[player.index].points_to_distribute = rpg_t[player.index].points_to_distribute - 1 - rpg_t[player.index][index] = rpg_t[player.index][index] + 1 - update_player_stats(player) - end - draw_gui(player, true) - return - end - - if rpg_t[player.index].points_to_distribute <= 0 then draw_gui(player, true) return end - if not rpg_t[player.index].reset then - rpg_t[player.index].total = rpg_t[player.index].total + 1 - end - rpg_t[player.index].points_to_distribute = rpg_t[player.index].points_to_distribute - 1 - rpg_t[player.index][index] = rpg_t[player.index][index] + 1 - update_player_stats(player) - draw_gui(player, true) + if element.type ~= 'sprite-button' then + return + end + + if element.caption == 'CHAR' then + if element.name == 'rpg' then + if player.gui.left.rpg then + player.gui.left.rpg.destroy() + return + end + draw_gui(player, true) + end + end + + if element.caption == 'false' then + if rpg_t[player.index].level <= 19 then + return + end + rpg_t[player.index].reset = true + Public.rpg_reset_player(player, true) + return + end + + if element.caption ~= '✚' then + return + end + if element.sprite ~= 'virtual-signal/signal-red' then + return + end + + local index = element.name + if not rpg_t[player.index][index] then + return + end + if not player.character then + return + end + + if event.button == defines.mouse_button_type.right then + for a = 1, 3, 1 do + if rpg_t[player.index].points_to_distribute <= 0 then + draw_gui(player, true) + return + end + if not rpg_t[player.index].reset then + rpg_t[player.index].total = rpg_t[player.index].total + 1 + end + rpg_t[player.index].points_to_distribute = rpg_t[player.index].points_to_distribute - 1 + rpg_t[player.index][index] = rpg_t[player.index][index] + 1 + update_player_stats(player) + end + draw_gui(player, true) + return + end + + if rpg_t[player.index].points_to_distribute <= 0 then + draw_gui(player, true) + return + end + if not rpg_t[player.index].reset then + rpg_t[player.index].total = rpg_t[player.index].total + 1 + end + rpg_t[player.index].points_to_distribute = rpg_t[player.index].points_to_distribute - 1 + rpg_t[player.index][index] = rpg_t[player.index][index] + 1 + update_player_stats(player) + draw_gui(player, true) end local xp_yield = { - ["behemoth-biter"] = 16, - ["behemoth-spitter"] = 16, - ["behemoth-worm-turret"] = 64, - ["big-biter"] = 8, - ["big-spitter"] = 8, - ["big-worm-turret"] = 48, - ["biter-spawner"] = 64, - ["character"] = 16, - ["gun-turret"] = 8, - ["laser-turret"] = 16, - ["medium-biter"] = 4, - ["medium-spitter"] = 4, - ["medium-worm-turret"] = 32, - ["small-biter"] = 1, - ["small-spitter"] = 1, - ["small-worm-turret"] = 16, - ["spitter-spawner"] = 64, + ['behemoth-biter'] = 16, + ['behemoth-spitter'] = 16, + ['behemoth-worm-turret'] = 64, + ['big-biter'] = 8, + ['big-spitter'] = 8, + ['big-worm-turret'] = 48, + ['biter-spawner'] = 64, + ['character'] = 16, + ['gun-turret'] = 8, + ['laser-turret'] = 16, + ['medium-biter'] = 4, + ['medium-spitter'] = 4, + ['medium-worm-turret'] = 32, + ['small-biter'] = 1, + ['small-spitter'] = 1, + ['small-worm-turret'] = 16, + ['spitter-spawner'] = 64 } -local function train_type_cause(cause) - local players = {} - if cause.train.passengers then - for _, player in pairs(cause.train.passengers) do - players[#players + 1] = player - end - end - return players +local function train_type_cause(cause) + local players = {} + if cause.train.passengers then + for _, player in pairs(cause.train.passengers) do + players[#players + 1] = player + end + end + return players end local get_cause_player = { - ["character"] = function(cause) - if not cause.player then return end - return {cause.player} - end, - ["combat-robot"] = function(cause) - if not cause.last_user then return end - if not game.players[cause.last_user.index] then return end - return {game.players[cause.last_user.index]} - end, - ["car"] = function(cause) - local players = {} - local driver = cause.get_driver() - if driver then - if driver.player then players[#players + 1] = driver.player end - end - local passenger = cause.get_passenger() - if passenger then - if passenger.player then players[#players + 1] = passenger.player end - end - return players - end, - ["locomotive"] = train_type_cause, - ["cargo-wagon"] = train_type_cause, - ["artillery-wagon"] = train_type_cause, - ["fluid-wagon"] = train_type_cause, + ['character'] = function(cause) + if not cause.player then + return + end + return {cause.player} + end, + ['combat-robot'] = function(cause) + if not cause.last_user then + return + end + if not game.players[cause.last_user.index] then + return + end + return {game.players[cause.last_user.index]} + end, + ['car'] = function(cause) + local players = {} + local driver = cause.get_driver() + if driver then + if driver.player then + players[#players + 1] = driver.player + end + end + local passenger = cause.get_passenger() + if passenger then + if passenger.player then + players[#players + 1] = passenger.player + end + end + return players + end, + ['locomotive'] = train_type_cause, + ['cargo-wagon'] = train_type_cause, + ['artillery-wagon'] = train_type_cause, + ['fluid-wagon'] = train_type_cause } local function on_entity_died(event) - if not event.entity.valid then return end - - --Grant XP for hand placed land mines - if event.entity.last_user then - if event.entity.type == "land-mine" then - if event.cause then - if event.cause.valid then - if event.cause.force.index == event.entity.force.index then return end - end - end - Public.gain_xp(event.entity.last_user, 1) - return - end - end - - if not event.cause then return end - if not event.cause.valid then return end - if event.cause.force.index == event.entity.force.index then return end - if not get_cause_player[event.cause.type] then return end - - local players = get_cause_player[event.cause.type](event.cause) - if not players then return end - if not players[1] then return end - - --Grant modified XP for health boosted units - if global.biter_health_boost then - if event.entity.type == "unit" then - for _, player in pairs(players) do - if xp_yield[event.entity.name] then - Public.gain_xp(player, xp_yield[event.entity.name] * global.biter_health_boost) - else - Public.gain_xp(player, 0.5 * global.biter_health_boost) - end - end - return - end - end - - --Grant normal XP - for _, player in pairs(players) do - if xp_yield[event.entity.name] then - Public.gain_xp(player, xp_yield[event.entity.name]) - else - Public.gain_xp(player, 0.5) - end - end + if not event.entity.valid then + return + end + + --Grant XP for hand placed land mines + if event.entity.last_user then + if event.entity.type == 'land-mine' then + if event.cause then + if event.cause.valid then + if event.cause.force.index == event.entity.force.index then + return + end + end + end + Public.gain_xp(event.entity.last_user, 1) + return + end + end + + if not event.cause then + return + end + if not event.cause.valid then + return + end + if event.cause.force.index == event.entity.force.index then + return + end + if not get_cause_player[event.cause.type] then + return + end + + local players = get_cause_player[event.cause.type](event.cause) + if not players then + return + end + if not players[1] then + return + end + + --Grant modified XP for health boosted units + if global.biter_health_boost then + if event.entity.type == 'unit' then + for _, player in pairs(players) do + if xp_yield[event.entity.name] then + Public.gain_xp(player, xp_yield[event.entity.name] * global.biter_health_boost) + else + Public.gain_xp(player, 0.5 * global.biter_health_boost) + end + end + return + end + end + + --Grant normal XP + for _, player in pairs(players) do + if xp_yield[event.entity.name] then + Public.gain_xp(player, xp_yield[event.entity.name]) + else + Public.gain_xp(player, 0.5) + end + end end --Melee damage modifier local function one_punch(character, target, damage) - local base_vector = {target.position.x - character.position.x, target.position.y - character.position.y} - - local vector = {base_vector[1], base_vector[2]} - vector[1] = vector[1] * 1000 - vector[2] = vector[2] * 1000 - - character.surface.create_entity({name = "flying-text", position = {character.position.x + base_vector[1] * 0.5, character.position.y + base_vector[2] * 0.5}, text = "ONE PUNCH", color = {255, 0, 0}}) - character.surface.create_entity({name = "blood-explosion-huge", position = target.position}) - character.surface.create_entity({name = "big-artillery-explosion", position = {target.position.x + vector[1] * 0.5, target.position.y + vector[2] * 0.5}}) - - if math.abs(vector[1]) > math.abs(vector[2]) then - local d = math.abs(vector[1]) - if math.abs(vector[1]) > 0 then vector[1] = vector[1] / d end - if math.abs(vector[2]) > 0 then vector[2] = vector[2] / d end - else - local d = math.abs(vector[2]) - if math.abs(vector[2]) > 0 then vector[2] = vector[2] / d end - if math.abs(vector[1]) > 0 and d > 0 then vector[1] = vector[1] / d end - end - - vector[1] = vector[1] * 1.5 - vector[2] = vector[2] * 1.5 + local base_vector = {target.position.x - character.position.x, target.position.y - character.position.y} - local a = 0.25 + local vector = {base_vector[1], base_vector[2]} + vector[1] = vector[1] * 1000 + vector[2] = vector[2] * 1000 - for i = 1, 16, 1 do - for x = i * -1 * a, i * a, 1 do - for y = i * -1 * a, i * a, 1 do - local p = {character.position.x + x + vector[1] * i, character.position.y + y + vector[2] * i} - character.surface.create_trivial_smoke({name="train-smoke", position=p}) - for _, e in pairs(character.surface.find_entities({{p[1] - a, p[2] - a},{p[1] + a, p[2] + a}})) do - if e.valid then - if e.health then - if e.destructible and e.minable and e.force.index ~= 3 then - if e.force.index ~= character.force.index then - e.health = e.health - damage * 0.05 - if e.health <= 0 then - e.die(e.force.name, character) - end - end - end - end - end - end - end - end - end + character.surface.create_entity( + { + name = 'flying-text', + position = {character.position.x + base_vector[1] * 0.5, character.position.y + base_vector[2] * 0.5}, + text = 'ONE PUNCH', + color = {255, 0, 0} + } + ) + character.surface.create_entity({name = 'blood-explosion-huge', position = target.position}) + character.surface.create_entity( + { + name = 'big-artillery-explosion', + position = {target.position.x + vector[1] * 0.5, target.position.y + vector[2] * 0.5} + } + ) + + if math.abs(vector[1]) > math.abs(vector[2]) then + local d = math.abs(vector[1]) + if math.abs(vector[1]) > 0 then + vector[1] = vector[1] / d + end + if math.abs(vector[2]) > 0 then + vector[2] = vector[2] / d + end + else + local d = math.abs(vector[2]) + if math.abs(vector[2]) > 0 then + vector[2] = vector[2] / d + end + if math.abs(vector[1]) > 0 and d > 0 then + vector[1] = vector[1] / d + end + end + + vector[1] = vector[1] * 1.5 + vector[2] = vector[2] * 1.5 + + local a = 0.25 + + for i = 1, 16, 1 do + for x = i * -1 * a, i * a, 1 do + for y = i * -1 * a, i * a, 1 do + local p = {character.position.x + x + vector[1] * i, character.position.y + y + vector[2] * i} + character.surface.create_trivial_smoke({name = 'train-smoke', position = p}) + for _, e in pairs(character.surface.find_entities({{p[1] - a, p[2] - a}, {p[1] + a, p[2] + a}})) do + if e.valid then + if e.health then + if e.destructible and e.minable and e.force.index ~= 3 then + if e.force.index ~= character.force.index then + e.health = e.health - damage * 0.05 + if e.health <= 0 then + e.die(e.force.name, character) + end + end + end + end + end + end + end + end + end end local function on_entity_damaged(event) - if not event.cause then return end - if not event.cause.valid then return end - if event.cause.force.index == 2 then return end - if event.cause.name ~= "character" then return end - if event.damage_type.name ~= "physical" then return end - if not event.entity.valid then return end - if event.cause.get_inventory(defines.inventory.character_ammo)[event.cause.selected_gun_index].valid_for_read - and event.cause.get_inventory(defines.inventory.character_guns)[event.cause.selected_gun_index].valid_for_read then return end - if not event.cause.player then return end - - --Grant the player life-on-hit. - event.cause.health = event.cause.health + get_life_on_hit(event.cause.player) - - --Calculate modified damage. - local damage = event.original_damage_amount + event.original_damage_amount * get_melee_modifier(event.cause.player) - if event.entity.prototype.resistances then - if event.entity.prototype.resistances.physical then - damage = damage - event.entity.prototype.resistances.physical.decrease - damage = damage - damage * event.entity.prototype.resistances.physical.percent - end - end - damage = math.round(damage, 3) - if damage < 1 then damage = 1 end - - --Cause a one punch. - if math_random(0,999) < get_one_punch_chance(event.cause.player) * 10 then - one_punch(event.cause, event.entity, damage) - if event.entity.valid then - event.entity.die(event.entity.force.name, event.cause) - end - return - end - - --Floating messages and particle effects. - if math_random(1,7) == 1 then - damage = damage * math_random(250, 350) * 0.01 - event.cause.surface.create_entity({name = "flying-text", position = event.entity.position, text = "‼" .. math.floor(damage), color = {255, 0, 0}}) - event.cause.surface.create_entity({name = "blood-explosion-huge", position = event.entity.position}) - else - damage = damage * math_random(100, 125) * 0.01 - event.cause.player.create_local_flying_text({text = math.floor(damage), position = event.entity.position, color = {150, 150, 150}, time_to_live = 90, speed = 2}) - end - - --Handle the custom health pool of the biter health booster, if it is used in the map. - if global.biter_health_boost then - local health_pool = global.biter_health_boost_units[event.entity.unit_number] - if health_pool then - health_pool[1] = health_pool[1] + event.final_damage_amount - health_pool[1] = health_pool[1] - damage + if not event.cause then + return + end + if not event.cause.valid then + return + end + if event.cause.force.index == 2 then + return + end + if event.cause.name ~= 'character' then + return + end + if event.damage_type.name ~= 'physical' then + return + end + if not event.entity.valid then + return + end + if + event.cause.get_inventory(defines.inventory.character_ammo)[event.cause.selected_gun_index].valid_for_read and + event.cause.get_inventory(defines.inventory.character_guns)[event.cause.selected_gun_index].valid_for_read + then + return + end + if not event.cause.player then + return + end - --Set entity health relative to health pool - event.entity.health = health_pool[1] * health_pool[2] + --Grant the player life-on-hit. + event.cause.health = event.cause.health + get_life_on_hit(event.cause.player) - if health_pool[1] <= 0 then - global.biter_health_boost_units[event.entity.unit_number] = nil - event.entity.die(event.entity.force.name, event.cause) - end - return - end - end - - --Handle vanilla damage. - event.entity.health = event.entity.health + event.final_damage_amount - event.entity.health = event.entity.health - damage - if event.entity.health <= 0 then - event.entity.die(event.entity.force.name, event.cause) - end + --Calculate modified damage. + local damage = event.original_damage_amount + event.original_damage_amount * get_melee_modifier(event.cause.player) + if event.entity.prototype.resistances then + if event.entity.prototype.resistances.physical then + damage = damage - event.entity.prototype.resistances.physical.decrease + damage = damage - damage * event.entity.prototype.resistances.physical.percent + end + end + damage = math.round(damage, 3) + if damage < 1 then + damage = 1 + end + + --Cause a one punch. + if math_random(0, 999) < get_one_punch_chance(event.cause.player) * 10 then + one_punch(event.cause, event.entity, damage) + if event.entity.valid then + event.entity.die(event.entity.force.name, event.cause) + end + return + end + + --Floating messages and particle effects. + if math_random(1, 7) == 1 then + damage = damage * math_random(250, 350) * 0.01 + event.cause.surface.create_entity( + { + name = 'flying-text', + position = event.entity.position, + text = '‼' .. math.floor(damage), + color = {255, 0, 0} + } + ) + event.cause.surface.create_entity({name = 'blood-explosion-huge', position = event.entity.position}) + else + damage = damage * math_random(100, 125) * 0.01 + event.cause.player.create_local_flying_text( + { + text = math.floor(damage), + position = event.entity.position, + color = {150, 150, 150}, + time_to_live = 90, + speed = 2 + } + ) + end + + --Handle the custom health pool of the biter health booster, if it is used in the map. + if global.biter_health_boost then + local health_pool = global.biter_health_boost_units[event.entity.unit_number] + if health_pool then + health_pool[1] = health_pool[1] + event.final_damage_amount + health_pool[1] = health_pool[1] - damage + + --Set entity health relative to health pool + event.entity.health = health_pool[1] * health_pool[2] + + if health_pool[1] <= 0 then + global.biter_health_boost_units[event.entity.unit_number] = nil + event.entity.die(event.entity.force.name, event.cause) + end + return + end + end + + --Handle vanilla damage. + event.entity.health = event.entity.health + event.final_damage_amount + event.entity.health = event.entity.health - damage + if event.entity.health <= 0 then + event.entity.die(event.entity.force.name, event.cause) + end end local function on_player_repaired_entity(event) - if math_random(1, 4) ~= 1 then return end - local player = game.players[event.player_index] - if not player.character then return end - Public.gain_xp(player, 0.40) + if math_random(1, 4) ~= 1 then + return + end + local player = game.players[event.player_index] + if not player.character then + return + end + Public.gain_xp(player, 0.40) end local function on_player_rotated_entity(event) - local player = game.players[event.player_index] - if not player.character then return end - if rpg_t[player.index].rotated_entity_delay > game.tick then return end - rpg_t[player.index].rotated_entity_delay = game.tick + 20 - Public.gain_xp(player, 0.20) + local player = game.players[event.player_index] + if not player.character then + return + end + if rpg_t[player.index].rotated_entity_delay > game.tick then + return + end + rpg_t[player.index].rotated_entity_delay = game.tick + 20 + Public.gain_xp(player, 0.20) end local function distance(player) - local distance_to_center = math_floor(math_sqrt(player.position.x ^ 2 + player.position.y ^ 2)) - local location = distance_to_center - if location < 950 then return end - local min = 960 * rpg_t[player.index].bonus - local max = 965 * rpg_t[player.index].bonus - local min_times = location >= min - local max_times = location <= max - if min_times and max_times then - rpg_t[player.index].bonus = rpg_t[player.index].bonus + 1 - player.print("[color=blue]Grandmaster:[/color] Survivor! Well done.") - Public.gain_xp(player, 300 * rpg_t[player.index].bonus) - return - end + local distance_to_center = math_floor(math_sqrt(player.position.x ^ 2 + player.position.y ^ 2)) + local location = distance_to_center + if location < 950 then + return + end + local min = 960 * rpg_t[player.index].bonus + local max = 965 * rpg_t[player.index].bonus + local min_times = location >= min + local max_times = location <= max + if min_times and max_times then + local level = rpg_t[player.index].bonus + rpg_t[player.index].bonus = rpg_t[player.index].bonus + 1 + player.print('[color=blue]Grandmaster:[/color] Survivor! Well done. You have completed level: ' .. level) + Public.gain_xp(player, 300 * rpg_t[player.index].bonus) + return + end end local function on_player_changed_position(event) - local player = game.players[event.player_index] - if string.sub(player.surface.name, 0, 9) ~= "scrapyard" then return end - distance(player) - if math_random(1, 64) ~= 1 then return end - if not player.character then return end - if player.character.driving then return end - Public.gain_xp(player, 1.0) + local player = game.players[event.player_index] + if string.sub(player.surface.name, 0, 9) ~= 'scrapyard' then + return + end + distance(player) + if math_random(1, 64) ~= 1 then + return + end + if not player.character then + return + end + if player.character.driving then + return + end + Public.gain_xp(player, 1.0) end local building_and_mining_blacklist = { - ["tile-ghost"] = true, - ["entity-ghost"] = true, - ["item-entity"] = true, + ['tile-ghost'] = true, + ['entity-ghost'] = true, + ['item-entity'] = true } local function on_pre_player_mined_item(event) - local entity = event.entity - if not entity.valid then return end - if building_and_mining_blacklist[entity.type] then return end - if entity.force.index ~= 3 then return end - local player = game.players[event.player_index] - - if rpg_t[player.index].last_mined_entity_position.x == event.entity.position.x and rpg_t[player.index].last_mined_entity_position.y == event.entity.position.y then return end - rpg_t[player.index].last_mined_entity_position.x = entity.position.x - rpg_t[player.index].last_mined_entity_position.y = entity.position.y - - if entity.type == "resource" then Public.gain_xp(player, 0.5) return end - --if entity.force.index == 3 then - Public.gain_xp(player, 0.75 + event.entity.prototype.max_health * 0.0013) - --return - --end - --Public.gain_xp(player, 0.1 + event.entity.prototype.max_health * 0.0005) + local entity = event.entity + if not entity.valid then + return + end + if building_and_mining_blacklist[entity.type] then + return + end + if entity.force.index ~= 3 then + return + end + local player = game.players[event.player_index] + + if + rpg_t[player.index].last_mined_entity_position.x == event.entity.position.x and + rpg_t[player.index].last_mined_entity_position.y == event.entity.position.y + then + return + end + rpg_t[player.index].last_mined_entity_position.x = entity.position.x + rpg_t[player.index].last_mined_entity_position.y = entity.position.y + + if entity.type == 'resource' then + Public.gain_xp(player, 0.5) + return + end + --if entity.force.index == 3 then + Public.gain_xp(player, 0.75 + event.entity.prototype.max_health * 0.0013) + --return + --end + --Public.gain_xp(player, 0.1 + event.entity.prototype.max_health * 0.0005) end local function on_player_crafted_item(event) - if not event.recipe.energy then return end - local player = game.players[event.player_index] - if not player.valid then return end - local amount = math_floor(math_random(0.40, 4)) - Public.gain_xp(player, event.recipe.energy * amount) + if not event.recipe.energy then + return + end + local player = game.players[event.player_index] + if not player.valid then + return + end + local amount = math_floor(math_random(0.40, 4)) + Public.gain_xp(player, event.recipe.energy * amount) end local function on_player_respawned(event) - local player = game.players[event.player_index] - if not rpg_t[player.index] then Public.rpg_reset_player(player) return end - update_player_stats(player) - draw_level_text(player) + local player = game.players[event.player_index] + if not rpg_t[player.index] then + Public.rpg_reset_player(player) + return + end + update_player_stats(player) + draw_level_text(player) end local function on_player_joined_game(event) - local player = game.players[event.player_index] - if not rpg_t[player.index] then Public.rpg_reset_player(player) end - for _, p in pairs(game.connected_players) do - draw_level_text(p) - end - draw_gui_char_button(player) - if not player.character then return end - update_player_stats(player) + local player = game.players[event.player_index] + if not rpg_t[player.index] then + Public.rpg_reset_player(player) + end + for _, p in pairs(game.connected_players) do + draw_level_text(p) + end + draw_gui_char_button(player) + if not player.character then + return + end + update_player_stats(player) end local function on_init(event) - if not rpg_t.global_pool then rpg_t.global_pool = 0 end - table.shuffle_table(rpg_frame_icons) + if not rpg_t.global_pool then + rpg_t.global_pool = 0 + end + table.shuffle_table(rpg_frame_icons) end local function tick() @@ -944,4 +1208,4 @@ event.add(defines.events.on_player_rotated_entity, on_player_rotated_entity) event.add(defines.events.on_pre_player_mined_item, on_pre_player_mined_item) event.on_nth_tick(nth_tick, tick) -return Public \ No newline at end of file +return Public diff --git a/maps/scrapyard/table.lua b/maps/scrapyard/table.lua index e7596927..71b2b492 100644 --- a/maps/scrapyard/table.lua +++ b/maps/scrapyard/table.lua @@ -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 diff --git a/maps/scrapyard/terrain.lua b/maps/scrapyard/terrain.lua index 58936e02..360faeb6 100644 --- a/maps/scrapyard/terrain.lua +++ b/maps/scrapyard/terrain.lua @@ -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