From d3e18890b08183fa7e254c26d269f95e6dd4652d Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Fri, 1 May 2020 01:02:56 +0200 Subject: [PATCH] junkyard changes --- maps/scrapyard/balance.lua | 183 ++++++++ maps/scrapyard/collapse.lua | 174 ++++++++ maps/scrapyard/comfylatron.lua | 54 ++- maps/scrapyard/icw/functions.lua | 50 +-- maps/scrapyard/icw/main.lua | 2 + maps/scrapyard/locomotive.lua | 1 + maps/scrapyard/loot.lua | 165 ++++++- maps/scrapyard/main.lua | 169 +++++-- .../mineable_wreckage_yields_scrap.lua | 15 +- maps/scrapyard/player_list.lua | 418 ++++++++++++++++++ maps/scrapyard/rpg.lua | 44 +- maps/scrapyard/table.lua | 18 +- maps/scrapyard/terrain.lua | 31 +- 13 files changed, 1213 insertions(+), 111 deletions(-) create mode 100644 maps/scrapyard/balance.lua create mode 100644 maps/scrapyard/collapse.lua create mode 100644 maps/scrapyard/player_list.lua diff --git a/maps/scrapyard/balance.lua b/maps/scrapyard/balance.lua new file mode 100644 index 00000000..952dee6f --- /dev/null +++ b/maps/scrapyard/balance.lua @@ -0,0 +1,183 @@ +--Hunger games balance things by Gerkiz -- +local Event = require 'utils.event' + +local player_ammo_starting_modifiers = { + ['artillery-shell'] = -0.75, + ['biological'] = -0.5, + ['bullet'] = -0.25, + ['cannon-shell'] = -0.75, + ['capsule'] = -0.5, + ['combat-robot-beam'] = -0.5, + ['combat-robot-laser'] = -0.5, + ['electric'] = -0.5, + ['flamethrower'] = -0.75, + ['grenade'] = -0.5, + ['landmine'] = -0.33, + ['laser-turret'] = -0.75, + ['melee'] = 2, + ['railgun'] = 1, + ['rocket'] = -0.75, + ['shotgun-shell'] = -0.20 +} + +local player_gun_speed_modifiers = { + ['artillery-shell'] = -0.75, + ['biological'] = -0.5, + ['bullet'] = -0.55, + ['cannon-shell'] = -0.75, + ['capsule'] = -0.5, + ['combat-robot-beam'] = -0.5, + ['combat-robot-laser'] = -0.5, + ['electric'] = -0.5, + ['flamethrower'] = -0.75, + ['grenade'] = -0.5, + ['landmine'] = -0.33, + ['laser-turret'] = -0.75, + ['melee'] = 1, + ['railgun'] = 0, + ['rocket'] = -0.75, + ['shotgun-shell'] = -0.50 +} + +local player_ammo_research_modifiers = { + ['artillery-shell'] = -0.75, + ['biological'] = -0.5, + ['bullet'] = -0.5, + ['cannon-shell'] = -0.85, + ['capsule'] = -0.5, + ['combat-robot-beam'] = -0.5, + ['combat-robot-laser'] = -0.5, + ['electric'] = -0.6, + ['flamethrower'] = -0.75, + ['grenade'] = -0.5, + ['landmine'] = -0.5, + ['laser-turret'] = -0.75, + ['melee'] = -0.5, + ['railgun'] = -0.5, + ['rocket'] = -0.5, + ['shotgun-shell'] = -0.20 +} + +local player_turrets_research_modifiers = { + ['gun-turret'] = -0.75, + ['laser-turret'] = -0.75, + ['flamethrower-turret'] = -0.75 +} + +local enemy_ammo_starting_modifiers = { + ['artillery-shell'] = 3, + ['biological'] = 3, + ['bullet'] = 2, + ['cannon-shell'] = 0, + ['capsule'] = 0, + ['combat-robot-beam'] = 0, + ['combat-robot-laser'] = 0, + ['electric'] = 0, + ['flamethrower'] = 0, + ['grenade'] = 0, + ['landmine'] = 0, + ['laser-turret'] = 3, + ['melee'] = 1, + ['railgun'] = 0, + ['rocket'] = 0, + ['shotgun-shell'] = 0 +} + +local enemy_ammo_evolution_modifiers = { + ['artillery-shell'] = 1, + ['biological'] = 2, + ['bullet'] = 1, + --['cannon-shell'] = 1, + --['capsule'] = 1, + --['combat-robot-beam'] = 1, + --['combat-robot-laser'] = 1, + --['electric'] = 1, + ['flamethrower'] = 2, + --['grenade'] = 1, + --['landmine'] = 1, + ['laser-turret'] = 2, + ['melee'] = 2 + --['railgun'] = 1, + --['rocket'] = 1, + --['shotgun-shell'] = 1 +} + + + +local function init_player_weapon_damage(force) + for k, v in pairs(player_ammo_starting_modifiers) do + force.set_ammo_damage_modifier(k, v) + end + + for k, v in pairs(player_gun_speed_modifiers) do + force.set_gun_speed_modifier(k, v) + end +end + +local function init_enemy_weapon_damage() + local e_force, scrap, scrap_defense = game.forces["enemy"], game.forces["scrap"], game.forces["scrap_defense"] + + for k, v in pairs(enemy_ammo_starting_modifiers) do + e_force.set_ammo_damage_modifier(k, v) + scrap.set_ammo_damage_modifier(k, v) + scrap_defense.set_ammo_damage_modifier(k, v) + end +end + +local function enemy_weapon_damage() + local e, s, sd = game.forces.enemy, game.forces.scrap, game.forces.scrap_defense + + 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 + e.set_ammo_damage_modifier(k, new) + s.set_ammo_damage_modifier(k, new) + sd.set_ammo_damage_modifier(k, new) + end +end + +local function research_finished(event) + local r = event.research + local p_force = r.force + + for _, e in ipairs(r.effects) do + local t = e.type + + if t == 'ammo-damage' then + local category = e.ammo_category + local factor = player_ammo_research_modifiers[category] + + if factor then + local current_m = p_force.get_ammo_damage_modifier(category) + local m = e.modifier + p_force.set_ammo_damage_modifier(category, current_m + factor * m) + end + elseif t == 'turret-attack' then + local category = e.turret_id + local factor = player_turrets_research_modifiers[category] + + if factor then + local current_m = p_force.get_turret_attack_modifier(category) + local m = e.modifier + p_force.set_turret_attack_modifier(category, current_m + factor * m) + end + elseif t == 'gun-speed' then + local category = e.ammo_category + local factor = player_gun_speed_modifiers[category] + + if factor then + local current_m = p_force.get_gun_speed_modifier(category) + local m = e.modifier + p_force.set_gun_speed_modifier(category, current_m + factor * m) + end + end + end +end + + +Event.on_init(init_enemy_weapon_damage) +Event.on_nth_tick(18000, enemy_weapon_damage) +--Event.add(defines.events.on_research_finished, research_finished) \ No newline at end of file diff --git a/maps/scrapyard/collapse.lua b/maps/scrapyard/collapse.lua new file mode 100644 index 00000000..86e0dc1c --- /dev/null +++ b/maps/scrapyard/collapse.lua @@ -0,0 +1,174 @@ +local Global = require 'utils.global' +local Public = {} + +local math_floor = math.floor +local table_shuffle_table = table.shuffle_table + +local collapse = {} +Global.register( + collapse, + function(tbl) + collapse = tbl + end +) + +local directions = { + ["north"] = function(position) + local width = collapse.surface.map_gen_settings.width + if width > collapse.max_line_size then width = collapse.max_line_size end + local a = width * 0.5 + 1 + collapse.vector = {0, -1} + collapse.area = {{position.x - a, position.y - 1}, {position.x + a, position.y}} + end, + ["south"] = function(position) + local width = collapse.surface.map_gen_settings.width + if width > collapse.max_line_size then width = collapse.max_line_size end + local a = width * 0.5 + 1 + collapse.vector = {0, 1} + collapse.area = {{position.x - a, position.y}, {position.x + a, position.y + 1}} + end, + ["west"] = function(position) + local width = collapse.surface.map_gen_settings.height + if width > collapse.max_line_size then width = collapse.max_line_size end + local a = width * 0.5 + 1 + collapse.vector = {-1, 0} + collapse.area = {{position.x - 1, position.y - a}, {position.x, position.y + a}} + end, + ["east"] = function(position) + local width = collapse.surface.map_gen_settings.height + if width > collapse.max_line_size then width = collapse.max_line_size end + local a = width * 0.5 + 1 + collapse.vector = {1, 0} + collapse.area = {{position.x, position.y - a}, {position.x + 1, position.y + a}} + end, +} + +local function print_debug(a) + print("Collapse error #" .. a) +end + +local function set_collapse_tiles(surface) + game.forces.player.chart(surface, collapse.area) + collapse.tiles = surface.find_tiles_filtered({area = collapse.area}) + if not collapse.tiles then return end + collapse.size_of_tiles = #collapse.tiles + if collapse.size_of_tiles > 0 then table_shuffle_table(collapse.tiles) end + collapse.position = {x = collapse.position.x + collapse.vector[1], y = collapse.position.y + collapse.vector[2]} + local v = collapse.vector + local area = collapse.area + collapse.area = {{area[1][1] + v[1], area[1][2] + v[2]}, {area[2][1] + v[1], area[2][2] + v[2]}} + game.forces.player.chart(surface, collapse.area) +end + +local function progress() + local surface = collapse.surface + + if not collapse.start_now then return end + + local tiles = collapse.tiles + if not tiles then + set_collapse_tiles(surface) + tiles = collapse.tiles + end + if not tiles then return end + + for _ = 1, collapse.amount, 1 do + local tile = tiles[collapse.size_of_tiles] + if not tile then collapse.tiles = nil return end + collapse.size_of_tiles = collapse.size_of_tiles - 1 + if not tile.valid then return end + if collapse.kill then + local position = {tile.position.x + 0.5, tile.position.y + 0.5} + for _, e in pairs(surface.find_entities_filtered({area = {{position[1] - 2, position[2] - 2}, {position[1] + 2, position[2] + 2}}})) do + if e.valid and e.health then e.die() end + end + end + surface.set_tiles({{name = "out-of-map", position = tile.position}}, true) + end +end + +function Public.set_surface(surface) + if not surface then print_debug(1) return end + if not surface.valid then print_debug(2) return end + if not game.surfaces[surface.index] then print_debug(3) return end + collapse.surface = surface +end + +function Public.set_direction(direction) + if not directions[direction] then print_debug(11) return end + directions[direction](collapse.position) +end + +function Public.set_speed(speed) + if not speed then print_debug(8) return end + speed = math_floor(speed) + if speed < 1 then speed = 1 end + collapse.speed = speed +end + +function Public.set_amount(amount) + if not amount then print_debug(9) return end + amount = math_floor(amount) + if amount < 0 then amount = 0 end + collapse.amount = amount +end + +function Public.set_position(position) + if not position then print_debug(4) return end + if not position.x and not position[1] then print_debug(5) return end + if not position.y and not position[2] then print_debug(6) return end + local x = 0 + local y = 0 + if position[1] then x = position[1] end + if position[2] then y = position[2] end + if position.x then x = position.x end + if position.y then y = position.y end + collapse.position = {x = x, y = y} +end + +function Public.get_position() + return collapse.position +end + +function Public.start_now(status) + if status == "start" then + collapse.start_now = true + elseif status == "stop" then + collapse.start_now = false + end + return collapse.start_now +end + +function Public.set_max_line_size(size) + if not size then print_debug(22) return end + size = math_floor(size) + if size <= 0 then print_debug(21) return end + collapse.max_line_size = size +end + +function Public.set_kill_entities(a) + collapse.kill = a +end + +local function on_init() + Public.set_surface(game.surfaces.nauvis) + Public.set_position({0, 32}) + Public.set_max_line_size(256) + Public.set_direction("north") + Public.set_kill_entities(true) + collapse.tiles = nil + collapse.speed = 1 + collapse.amount = 8 + collapse.start_now = false +end + +local function on_tick() + if game.tick % collapse.speed ~= 0 then return end + progress() +end + +local Event = require 'utils.event' +Event.on_init(on_init) +Event.add(defines.events.on_tick, on_tick) + +return Public \ No newline at end of file diff --git a/maps/scrapyard/comfylatron.lua b/maps/scrapyard/comfylatron.lua index 3112a150..9417cc2d 100644 --- a/maps/scrapyard/comfylatron.lua +++ b/maps/scrapyard/comfylatron.lua @@ -114,7 +114,6 @@ end local function is_target_inside_habitat(pos, surface) local this = Scrap_table.get_table() - if surface.name ~= surface then return false end 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 @@ -134,8 +133,7 @@ end local function visit_player() local this = Scrap_table.get_table() - local unit_number = this.locomotive.unit_number - local surface = game.surfaces[tostring(unit_number)] + 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) @@ -362,22 +360,42 @@ local function spawn_comfylatron(surface, x, y) if not this.comfylatron_last_player_visit then this.comfylatron_last_player_visit = 0 end if not this.comfylatron_habitat then this.comfylatron_habitat = { - left_top = {x = -18, y = 3}, - right_bottom = {x = 17, y = 67} + left_top = {x = -512, y = -512}, + right_bottom = {x = 512, y = 512} } end - this.comfylatron = surface.create_entity({ + 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 = player.surface.find_non_colliding_position("compilatron", player.position, 16, 1) + if not position then return false end + this.comfylatron = player.surface.create_entity({ name = "compilatron", - position = {x,y + math_random(0,26)}, - force = "neutral", - create_build_effect_smoke = false + 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() - local unit_number = this.locomotive.unit_number - local surface = game.surfaces[tostring(unit_number)] + 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, 0, 26) end return end @@ -398,6 +416,19 @@ local function on_entity_damaged(event) 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 +end + local function on_tick() if game.tick % 1200 == 600 then heartbeat() @@ -405,4 +436,5 @@ local function on_tick() end Event.add(defines.events.on_entity_damaged, on_entity_damaged) +Event.add(defines.events.on_entity_died, on_entity_died) Event.add(defines.events.on_tick, on_tick) diff --git a/maps/scrapyard/icw/functions.lua b/maps/scrapyard/icw/functions.lua index 92b31960..245e969b 100644 --- a/maps/scrapyard/icw/functions.lua +++ b/maps/scrapyard/icw/functions.lua @@ -327,7 +327,7 @@ function Public.create_wagon_room(icw, wagon) e.destructible = false e.minable = false - e2 = surface.create_entity({ + local e2 = surface.create_entity({ name = "logistic-chest-passive-provider", position = {position[1] + v[1], position[2] + v[2]}, force = "neutral", @@ -353,7 +353,7 @@ function Public.create_wagon(icw, created_entity) surface = Public.create_room_surface(icw, created_entity.unit_number), doors = {}, entity_count = 0, - } + } Public.create_wagon_room(icw, icw.wagons[created_entity.unit_number]) Public.request_reconstruction(icw) return icw.wagons[created_entity.unit_number] @@ -361,9 +361,9 @@ 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 + if not wagon then return end wagon.entity_count = wagon.entity_count + 1 - wagon.entity.minable = false + wagon.entity.minable = true end function Public.subtract_wagon_entity_count(icw, removed_entity) @@ -404,17 +404,17 @@ function Public.use_cargo_wagon_door(icw, player, door) player.teleport(position, surface) player_data.state = 2 player.driving = true - Public.kill_minimap(player) + Public.kill_minimap(player) else player.teleport(position, surface) - Public.kill_minimap(player) + 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 + 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)} @@ -429,30 +429,30 @@ function Public.use_cargo_wagon_door(icw, player, door) end function Public.move_room_to_train(icw, train, wagon) - if not wagon then return end - + if not wagon then return end + table_insert(train.wagons, wagon.entity.unit_number) - + 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)} } - + train.top_y = destination_area.right_bottom.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 - + kill_wagon_doors(icw, wagon) - + 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 end - + wagon.surface.clone_area({ source_area = wagon.area, destination_area = destination_area, @@ -464,27 +464,27 @@ function Public.move_room_to_train(icw, train, wagon) clear_destination_decoratives = true, expand_map = true, }) - + for player_index, position in pairs(player_positions) do local player = game.players[player_index] - player.teleport(position, train.surface) + player.teleport(position, train.surface) end - + 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) - + wagon.surface = train.surface wagon.area = destination_area wagon.transfer_entities = {} construct_wagon_doors(icw, wagon) - + 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) @@ -494,12 +494,12 @@ end function Public.construct_train(icw, carriages) local unit_number = carriages[1].unit_number - + 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 - + for k, carriage in pairs(carriages) do Public.move_room_to_train(icw, train, icw.wagons[carriage.unit_number]) end diff --git a/maps/scrapyard/icw/main.lua b/maps/scrapyard/icw/main.lua index 89f4e952..77aa1bc8 100644 --- a/maps/scrapyard/icw/main.lua +++ b/maps/scrapyard/icw/main.lua @@ -1,6 +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 Public = {} local math_round = math.round @@ -32,6 +33,7 @@ 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) end diff --git a/maps/scrapyard/locomotive.lua b/maps/scrapyard/locomotive.lua index 11227f18..fc29ee71 100644 --- a/maps/scrapyard/locomotive.lua +++ b/maps/scrapyard/locomotive.lua @@ -123,6 +123,7 @@ end local function rebuild_energy_loco(data, destroy) local this = data.this local icw_table = data.icw_table + if not this.locomotive.valid then return end local unit_surface = this.locomotive.unit_number local loco_surface = game.surfaces[icw_table.wagons[unit_surface].surface.index] local pos = {x=-19, y=3} diff --git a/maps/scrapyard/loot.lua b/maps/scrapyard/loot.lua index acd14d96..518e0902 100644 --- a/maps/scrapyard/loot.lua +++ b/maps/scrapyard/loot.lua @@ -20,7 +20,6 @@ function Public.add(surface, position, chest) {{name = "rocket-launcher", count = 1}, weight = 3, d_min = 0.2, d_max = 0.6}, {{name = "rocket", count = math_random(16,32)}, weight = 5, d_min = 0.2, d_max = 0.7}, {{name = "explosive-rocket", count = math_random(16,32)}, weight = 5, d_min = 0.3, d_max = 1}, - {{name = "land-mine", count = math_random(16,32)}, weight = 5, d_min = 0.2, d_max = 0.7}, {{name = "grenade", count = math_random(16,32)}, weight = 5, d_min = 0.0, d_max = 0.5}, {{name = "cluster-grenade", count = math_random(8,16)}, weight = 5, d_min = 0.4, d_max = 1}, {{name = "firearm-magazine", count = math_random(32,128)}, weight = 5, d_min = 0, d_max = 0.3}, @@ -163,4 +162,168 @@ function Public.add(surface, position, chest) 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}, + } + + local distance_to_center = (math.abs(position.y) + 1) * 0.0002 + if distance_to_center > 1 then distance_to_center = 1 end + + for _, t in pairs (chest_loot) do + for x = 1, t.weight, 1 do + if t.d_min <= distance_to_center and t.d_max >= distance_to_center then + table.insert(chest_raffle, t[1]) + end + end + end + + local e = surface.create_entity({name = chest, position=position, force="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 \ No newline at end of file diff --git a/maps/scrapyard/main.lua b/maps/scrapyard/main.lua index ed1f2d2b..683cbdd4 100644 --- a/maps/scrapyard/main.lua +++ b/maps/scrapyard/main.lua @@ -1,3 +1,4 @@ + require "on_tick_schedule" require "modules.dynamic_landfill" require "modules.difficulty_vote" @@ -33,10 +34,18 @@ local Locomotive = require "maps.scrapyard.locomotive".locomotive_spawn local render_train_hp = require "maps.scrapyard.locomotive".render_train_hp local Score = require "comfy_panel.score" local Poll = require "comfy_panel.poll" +local Collapse = require "maps.scrapyard.collapse" local Public = {} local math_random = math.random local math_floor = math.floor +local math_abs = math.abs + +function Public.print(msg) + if _DEBUG then + game.print(serpent.block(msg)) + end +end 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"} @@ -47,6 +56,12 @@ local treasure_chest_messages = { "We has found the precious!", } +local rare_treasure_chest_messages = { + "Your magic improves. You have found a chest that is filled with rare treasure!", + "Oh wonderful magic. You found a chest underneath the broken rocks. It's filled with rare goodies!", + "You're a wizard Harry! We has found the rare precious!", +} + local function shuffle(tbl) local size = #tbl for i = size, 1, -1 do @@ -86,6 +101,11 @@ local function set_difficulty() -- threat gain / wave wave_defense_table.threat_gain_multiplier = 2 + player_count * 0.1 + local amount = player_count * 0.25 + 2 + amount = math.floor(amount) + if amount > 8 then amount = 8 end + Collapse.set_amount(amount) + --20 Players for fastest wave_interval wave_defense_table.wave_interval = 3600 - player_count * 90 @@ -144,6 +164,15 @@ function Public.reset_map() game.difficulty_settings.technology_price_multiplier = 0.6 + Collapse.set_kill_entities(false) + Collapse.set_speed(8) + Collapse.set_amount(1) + Collapse.set_max_line_size(Terrain.level_depth) + Collapse.set_surface(surface) + Collapse.set_position({0, 290}) + Collapse.set_direction("north") + Collapse.start_now(false) + surface.ticks_per_day = surface.ticks_per_day * 2 surface.min_brightness = 0.08 surface.daytime = 0.7 @@ -316,34 +345,29 @@ local function change_tile(surface, pos, steps) return surface.set_tiles{{name = colors[math_floor(steps * 0.5) % 7 + 1], position=pos}} end ---local function change_tile(surface,pos) --- local colors = {"black", "orange", "red", "yellow", "acid", "brown", "blue"} --- surface.set_tiles{{name = colors[math_random(1, #colors)].. "-refined-concrete", position=pos}} ---end - local function on_player_changed_position(event) local this = Scrap_table.get_table() local player = game.players[event.player_index] if string.sub(player.surface.name, 0, 9) ~= "scrapyard" then return end local position = player.position local surface = game.surfaces[this.active_surface_index] - if position.x >= 960 * 0.5 then return end - if position.x < 960 * -0.5 then return end + if position.x >= Terrain.level_depth * 0.5 then return end + if position.x < Terrain.level_depth * -0.5 then return end if position.y < 5 then if not this.players[player.index].tiles_enabled then goto continue end - for x = -1,1 do - for y = -1,1 do - local _pos = {position.x+x,position.y+y} + --for x = -1,1 do + --for y = -1,1 do + --local _pos = {position.x+x,position.y+y} local steps = this.players[player.index].steps - local shallow, deepwater = surface.get_tile(_pos).name == "water-shallow", surface.get_tile(_pos).name == "deepwater-green" - if shallow or deepwater then goto continue end - change_tile(surface, _pos, steps) - if this.players[player.index].steps > 5000 then + local shallow, deepwater, oom = surface.get_tile(position).name == "water-shallow", surface.get_tile(position).name == "deepwater-green", surface.get_tile(position).name == "out-of-map" + if shallow or deepwater or oom then goto continue end + change_tile(surface, position, steps) + if this.players[player.index].steps > 5000 then this.players[player.index].steps = 0 end this.players[player.index].steps = this.players[player.index].steps + 1 - end - end + --end + --end end ::continue:: if position.y < 5 then Terrain.reveal(player) end @@ -419,8 +443,16 @@ local function hidden_biter_pet(event) end local function hidden_treasure(event) + local player = game.players[event.player_index] + local rpg_t = RPG.get_table() + local magic = rpg_t[player.index].magic if math.random(1, 320) ~= 1 then return end - game.players[event.player_index].print(treasure_chest_messages[math.random(1, #treasure_chest_messages)], {r=0.98, g=0.66, b=0.22}) + if magic > 50 then + player.print(rare_treasure_chest_messages[math.random(1, #rare_treasure_chest_messages)], {r=0.98, g=0.66, b=0.22}) + Loot.add(event.entity.surface, event.entity.position, "wooden-chest", magic) + return + end + player.print(treasure_chest_messages[math.random(1, #treasure_chest_messages)], {r=0.98, g=0.66, b=0.22}) Loot.add(event.entity.surface, event.entity.position, "wooden-chest") end @@ -516,6 +548,14 @@ function Public.loco_died() local this = Scrap_table.get_table() local surface = game.surfaces[this.active_surface_index] local wave_defense_table = WD.get_table() + if not this.locomotive.valid then + wave_defense_table.game_lost = true + wave_defense_table.target = nil + game.print("[color=blue]Grandmaster:[/color] Oh noooeeeew, the void destroyed my train!", {r = 1, g = 0.5, b = 0.1}) + game.print("[color=blue]Grandmaster:[/color] Better luck next time.", {r = 1, g = 0.5, b = 0.1}) + Public.reset_map() + return + end this.locomotive_health = 0 this.locomotive.color = {0.49, 0, 255, 1} rendering.set_text(this.health_text, "HP: " .. this.locomotive_health .. " / " .. this.locomotive_max_health) @@ -524,18 +564,10 @@ function Public.loco_died() game.print("[color=blue]Grandmaster:[/color] Oh noooeeeew, they destroyed my train!", {r = 1, g = 0.5, b = 0.1}) game.print("[color=blue]Grandmaster:[/color] Better luck next time.", {r = 1, g = 0.5, b = 0.1}) game.print("[color=blue]Grandmaster:[/color] Game will soft-reset shortly.", {r = 1, g = 0.5, b = 0.1}) - for i = 1, 12, 1 do - surface.create_entity({name = "big-artillery-explosion", position = this.locomotive.position}) - end - for i = 1, 12, 1 do - surface.create_entity({name = "big-artillery-explosion", position = this.locomotive_cargo.position}) - end - for i = 1, 12, 1 do - surface.create_entity({name = "big-artillery-explosion", position = this.locomotive_cargo.position}) - end - for i = 1, 12, 1 do - surface.create_entity({name = "big-artillery-explosion", position = this.locomotive_cargo.position}) - end + + local fake_shooter = surface.create_entity({name = "character", position = this.locomotive.position, force = "enemy"}) + surface.create_entity({name = "atomic-rocket", position = this.locomotive.position, force = "enemy", speed = 1, max_range = 800, target = this.locomotive, source = fake_shooter}) + surface.spill_item_stack(this.locomotive.position,{name = "coin", count = 512}, false) surface.spill_item_stack(this.locomotive_cargo.position,{name = "coin", count = 512}, false) this.game_reset_tick = game.tick + 1800 @@ -698,18 +730,18 @@ local on_init = function() } end -local function darkness(this) +local function darkness(data) local rnd = math.random - local surface = game.surfaces[this.active_surface_index] + local surface = data.surface if rnd(1, 64) == 1 then if surface.freeze_daytime then return end game.print("[color=blue]Grandmaster:[/color] Darkness has surrounded us!", {r = 1, g = 0.5, b = 0.1}) game.print("[color=blue]Grandmaster:[/color] Builds some lamps!", {r = 1, g = 0.5, b = 0.1}) - surface.min_brightness = 0.10 + surface.min_brightness = 0 surface.brightness_visual_weights = {0.90, 0.90, 0.90} surface.daytime = 0.42 surface.freeze_daytime = true - surface.solar_power_multiplier = 1 + surface.solar_power_multiplier = 0 return elseif rnd(1, 32) == 1 then if not surface.freeze_daytime then return end @@ -724,7 +756,8 @@ local function darkness(this) end -local function scrap_randomness(this) +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 @@ -741,14 +774,59 @@ local function scrap_randomness(this) end end +local function transfer_pollution(data) + local surface = data.surface + local this = data.this + if not surface then return end + local pollution = surface.get_total_pollution() * (3 / (4 / 3 + 1)) * global.difficulty_vote_value + game.surfaces[this.active_surface_index].pollute(this.locomotive.position, pollution) + surface.clear_pollution() +end + +local tick_minute_functions = { + [300 * 2] = scrap_randomness, + [300 * 3 + 30 * 0] = darkness, + [300 * 3 + 30 * 1] = transfer_pollution, +} + local on_tick = function() local this = Scrap_table.get_table() + local surface = game.surfaces[this.active_surface_index] + local wave_defense_table = WD.get_table() + local tick = game.tick + local key = tick % 3600 + local data = { + this = this, + surface = surface + } + if not this.locomotive.valid then + Public.loco_died() + end + if Collapse.start_now() == true then goto continue end + if this.left_top.y % Terrain.level_depth == 0 and this.left_top.y < 0 and this.left_top.y > Terrain.level_depth * -10 then + if not Collapse.start_now() then + this.o_left_top = this.left_top + Collapse.start_now(true) + end + end + ::continue:: if game.tick % 30 == 0 then if game.tick % 1800 == 0 then + local position = surface.find_non_colliding_position("stone-furnace", Collapse.get_position(), 128, 1) + if position then + wave_defense_table.spawn_position = position + end + end + end + 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.game_reset_tick then if this.game_reset_tick < game.tick then this.game_reset_tick = nil @@ -761,20 +839,20 @@ end commands.add_command( 'rainbow_mode', 'This will prevent new tiles from spawning when walking', - function(cmd) + function() local player = game.player local this = Scrap_table.get_table() if player and player.valid then - if this.players[player.index].tiles_enabled == false then - this.players[player.index].tiles_enabled = true - player.print("Rainbow mode: ON", Color.green) - return - end - if this.players[player.index].tiles_enabled == true then - this.players[player.index].tiles_enabled = false - player.print("Rainbow mode: OFF", Color.warning) - return - end + if this.players[player.index].tiles_enabled == false then + this.players[player.index].tiles_enabled = true + player.print("Rainbow mode: ON", Color.green) + return + end + if this.players[player.index].tiles_enabled == true then + this.players[player.index].tiles_enabled = false + player.print("Rainbow mode: OFF", Color.warning) + return + end end end) @@ -810,5 +888,6 @@ Event.add(defines.events.on_player_changed_position, on_player_changed_position) Event.add(defines.events.on_research_finished, on_research_finished) require "maps.scrapyard.mineable_wreckage_yields_scrap" +require "maps.scrapyard.balance" return Public \ No newline at end of file diff --git a/maps/scrapyard/mineable_wreckage_yields_scrap.lua b/maps/scrapyard/mineable_wreckage_yields_scrap.lua index 4025d370..0d3f69dc 100644 --- a/maps/scrapyard/mineable_wreckage_yields_scrap.lua +++ b/maps/scrapyard/mineable_wreckage_yields_scrap.lua @@ -34,10 +34,6 @@ end local function mining_chances_scrap() local data = { - {name = "iron-ore", chance = 570}, - {name = "copper-ore", chance = 570}, - {name = "stone", chance = 550}, - {name = "coal", chance = 500}, {name = "iron-plate", chance = 400}, {name = "iron-gear-wheel", chance = 390}, {name = "copper-plate", chance = 400}, @@ -107,10 +103,6 @@ end local function scrap_yield_amounts() local data = { - ["iron-ore"] = 10, - ["copper-ore"] = 10, - ["stone"] = 8, - ["coal"] = 9, ["iron-plate"] = 12, ["iron-gear-wheel"] = 12, ["iron-stick"] = 12, @@ -160,7 +152,6 @@ local function scrap_yield_amounts() ["defender-capsule"] = 2, ["destroyer-capsule"] = 0.3, ["distractor-capsule"] = 0.3, - ["uranium-ore"] = 1, ["mineable-wreckage"] = 1, } return data @@ -188,6 +179,7 @@ local function get_amount(data) local entity = data.entity local this = data.this local scrap = data.scrap + local scrap_amount = scrap_yield_amounts() local distance_to_center = math_floor(math_sqrt(entity.position.x ^ 2 + entity.position.y ^ 2)) local distance_modifier = 0.25 @@ -203,8 +195,8 @@ local function get_amount(data) local m = (70 + math_random(0, 60)) * 0.01 if this.scrap_enabled then local amount_bonus = (game.forces.enemy.evolution_factor * 2) + (game.forces.player.mining_drill_productivity_bonus * 2) - local r1 = math.ceil(scrap_yield_amounts()[scrap] * (0.3 + (amount_bonus * 0.3))) - local r2 = math.ceil(scrap_yield_amounts()[scrap] * (1.7 + (amount_bonus * 1.7))) + local r1 = math.ceil(scrap_amount[scrap] * (0.3 + (amount_bonus * 0.3))) + local r2 = math.ceil(scrap_amount[scrap] * (1.7 + (amount_bonus * 1.7))) if not r1 or not r2 then return end amount = math.random(r1, r2) else @@ -219,6 +211,7 @@ local function scrap_randomness(data) local entity = data.entity local this = data.this local player = data.player + local scrap --if this.scrap_enabled[player.index] then -- scrap = scrap_raffle_scrap[math.random(1, size_of_scrap_raffle)] diff --git a/maps/scrapyard/player_list.lua b/maps/scrapyard/player_list.lua new file mode 100644 index 00000000..6420cb82 --- /dev/null +++ b/maps/scrapyard/player_list.lua @@ -0,0 +1,418 @@ +--[[ +Hello there! + +This will add a player list with "ranks" to your server. +Oh.. and you can also "poke" a player. +pokemessages = 80% by redlabel + +To install, add: require "player_list" +to your scenario control.lua. + +---MewMew--- + +Minor changes by ~~~Gerkiz~~~ +--]] + +local event = require 'utils.event' +local play_time = require 'utils.session_data' +local Tabs = require 'comfy_panel.main' +local RPG = require 'maps.scrapyard.rpg' + +local symbol_asc = "▲" +local symbol_desc = "▼" + +local pokemessages = {"a stick", "a leaf", "a moldy carrot", "a crispy slice of bacon", "a french fry", "a realistic toygun", "a broomstick", "a thirteen inch iron stick", "a mechanical keyboard", "a fly fishing cane", + "a selfie stick", "an oversized fidget spinner", "a thumb extender", "a dirty straw", "a green bean", "a banana", "an umbrella", "grandpa's walking stick", "live firework", "a toilet brush", "a fake hand", + "an undercooked hotdog", "a slice of yesterday's microwaved pizza", "bubblegum", "a biter leg", "grandma's toothbrush", "charred octopus", "a dollhouse bathtub", "a length of copper wire", + "a decommissioned nuke", "a smelly trout", "an unopened can of deodorant", "a stone brick", "a half full barrel of lube", "a half empty barrel of lube", "an unexploded cannon shell", "a blasting programmable speaker", + "a not so straight rail", "a mismatched pipe to ground", "a surplus box of landmines", "decommissioned yellow rounds", "an oily pumpjack shaft", "a melted plastic bar in the shape of the virgin mary", + "a bottle of watermelon vitamin water", "a slice of watermelon", "a stegosaurus tibia", "a basking musician's clarinet", "a twig", "an undisclosed pokey item", "a childhood trophy everyone else got","a dead starfish", + "a titanium toothpick", "a nail file","a stamp collection","a bucket of lego","a rolled up carpet","a rolled up WELCOME doormat","Bobby's favorite bone","an empty bottle of cheap vodka","a tattooing needle", + "a peeled cucumber","a stack of cotton candy","a signed baseball bat","that 5 dollar bill grandma sent for christmas","a stack of overdue phone bills","the 'relax' section of the white pages", + "a bag of gym clothes which never made it to the washing machine","a handful of peanut butter","a pheasant's feather","a rusty pickaxe","a diamond sword","the bill of rights of a banana republic", + "one of those giant airport Toblerone's", "a long handed inserter", "a wiimote","an easter chocolate rabbit","a ball of yarn the cat threw up","a slightly expired but perfectly edible cheese sandwich", + "conclusive proof of lizard people existence","a pen drive full of high res wallpapers","a pet hamster","an oversized goldfish","a one foot extension cord","a CD from Walmart's 1 dollar bucket","a magic wand","a list of disappointed people who believed in you","murder exhibit no. 3","a paperback copy of 'Great Expectations'", "a baby biter", "a little biter fang", "the latest diet fad","a belt that no longer fits you","an abandoned pet rock","a lava lamp", "some spirit herbs","a box of fish sticks found at the back of the freezer","a bowl of tofu rice", "a bowl of ramen noodles", "a live lobster!", "a miniature golf cart","dunce cap","a fully furnished x-mas tree", "an orphaned power pole", "an horphaned power pole","an box of overpriced girl scout cookies","the cheapest item from the yard sale","a Sharpie","a glowstick","a thick unibrow hair","a very detailed map of Kazakhstan","the official Factorio installation DVD","a Liberal Arts degree","a pitcher of Kool-Aid","a 1/4 pound vegan burrito","a bottle of expensive wine","a hamster sized gravestone","a counterfeit Cuban cigar","an old Nokia phone","a huge inferiority complex","a dead real state agent","a deck of tarot cards","unreleased Wikileaks documents","a mean-looking garden dwarf","the actual mythological OBESE cat","a telescope used to spy on the MILF next door","a fancy candelabra","the comic version of the Kama Sutra","an inflatable 'Netflix & chill' doll","whatever it is redlabel gets high on","Obama's birth certificate","a deck of Cards Against Humanity","a copy of META MEME HUMOR for Dummies","an abandoned, not-so-young-anymore puppy","one of those useless items advertised on TV","a genetic blueprint of a Japanese teen idol" } + +local function get_formatted_playtime(x) + local time_one = 216000 + local time_two = 3600 + + if x < 5184000 then + local y = x / 216000 + y = tostring(y) + local h = "" + for i=1,10,1 do + local z = string.sub(y, i, i) + + if z == "." then + break + else + h = h .. z + end + end + + local m = x % 216000 + m = m / 3600 + m = math.floor(m) + m = tostring(m) + + if h == "0" then + local str = m .. " minutes" + return str + else + local str = h .. " hours " + str = str .. m + str = str .. " minutes" + return str + end + else + local y = x / 5184000 + y = tostring(y) + local h = "" + for i=1,10,1 do + local z = string.sub(y, i, i) + + if z == "." then + break + else + h = h .. z + end + end + + local m = x % 5184000 + m = m / 216000 + m = math.floor(m) + m = tostring(m) + + if h == "0" then + local str = m .. " days" + return str + else + local str = h .. " days " + str = str .. m + str = str .. " hours" + return str + end + end +end + +local function get_rank(player) + local play_table = play_time.get_session_table() + local t = 0 + if play_table then + if play_table[player.name] then t = play_table[player.name] end + end + + local m = (player.online_time + t) / 3600 + + local ranks = { + "item/burner-mining-drill","item/burner-inserter","item/stone-furnace","item/light-armor","item/steam-engine", + "item/inserter", "item/transport-belt", "item/underground-belt", "item/splitter","item/assembling-machine-1","item/long-handed-inserter","item/electronic-circuit","item/electric-mining-drill","item/dummy-steel-axe", + "item/heavy-armor","item/steel-furnace","item/gun-turret","item/fast-transport-belt", "item/fast-underground-belt", "item/fast-splitter","item/assembling-machine-2","item/fast-inserter","item/radar","item/filter-inserter", + "item/defender-capsule","item/pumpjack","item/chemical-plant","item/solar-panel","item/advanced-circuit","item/modular-armor","item/accumulator", "item/construction-robot", + "item/distractor-capsule","item/stack-inserter","item/electric-furnace","item/express-transport-belt","item/express-underground-belt", "item/express-splitter","item/assembling-machine-3","item/processing-unit","item/power-armor","item/logistic-robot","item/laser-turret", + "item/stack-filter-inserter","item/destroyer-capsule","item/power-armor-mk2","item/flamethrower-turret","item/beacon", + "item/steam-turbine","item/centrifuge","item/nuclear-reactor" + } + + --52 ranks + + local time_needed = 240 -- in minutes between rank upgrades + m = m / time_needed + m = math.floor(m) + m = m + 1 + + if m > #ranks then m = #ranks end + + return ranks[m] +end + +local comparators = { + ["pokes_asc"] = function (a, b) return a.pokes > b.pokes end, + ["pokes_desc"] = function (a, b) return a.pokes < b.pokes end, + ["total_time_played_asc"] = function (a,b) return a.total_played_ticks < b.total_played_ticks end, + ["total_time_played_desc"] = function (a,b) return a.total_played_ticks > b.total_played_ticks end, + ["time_played_asc"] = function (a,b) return a.played_ticks < b.played_ticks end, + ["time_played_desc"] = function (a,b) return a.played_ticks > b.played_ticks end, + ["rpg_asc"] = function (a,b) return a.rpg_level < b.rpg_level end, + ["rpg_desc"] = function (a,b) return a.rpg_level > b.rpg_level end, + ["name_asc"] = function (a,b) return a.name:lower() < b.name:lower() end, + ["name_desc"] = function (a,b) return a.name:lower() > b.name:lower() end +} + +local function get_comparator(sort_by) + return comparators[sort_by] +end + +local function get_sorted_list(sort_by) + local play_table = play_time.get_session_table() + local rpg_t = RPG.get_table() + local player_list = {} + for i, player in pairs(game.connected_players) do + player_list[i] = {} + player_list[i].rank = get_rank(player) + player_list[i].name = player.name + + local t = 0 + if play_table[player.name] then t = play_table[player.name] end + + player_list[i].rpg_level = rpg_t[player.index].level + + player_list[i].total_played_time = get_formatted_playtime(t + player.online_time) + player_list[i].total_played_ticks = t + player.online_time + + player_list[i].played_time = get_formatted_playtime(player.online_time) + player_list[i].played_ticks = player.online_time + + player_list[i].pokes = global.player_list.pokes[player.index] + player_list[i].player_index = player.index + end + + local comparator = get_comparator(sort_by) + table.sort(player_list, comparator) + + return player_list +end + + + +local function player_list_show(player, frame, sort_by) + -- Frame management + frame.clear() + frame.style.padding = 8 + + -- Header management + local t = frame.add { type = "table", name = "player_list_panel_header_table", column_count = 6 } + local column_widths = {tonumber(40), tonumber(150), tonumber(150), tonumber(150), tonumber(150), tonumber(100)} + for _, w in ipairs(column_widths) do + local label = t.add { type = "label", caption = "" } + label.style.minimal_width = w + label.style.maximal_width = w + end + + local headers = { + [1] = "[color=0.1,0.7,0.1]" -- green + .. tostring(#game.connected_players) + .. "[/color]", + [2] = "Online" + .. " / " + .. "[color=0.7,0.1,0.1]" -- red + .. tostring(#game.players - #game.connected_players) + .. "[/color]" + .. " Offline", + [3] = "RPG level", + [4] = "Total Time", + [5] = "Current Time", + [6] = "Poke" + } + local header_modifier = { + ["name_asc"] = function (h) h[2] = symbol_asc .. h[2] end, + ["name_desc"] = function (h) h[2] = symbol_desc .. h[2] end, + ["rpg_asc"] = function (h) h[3] = symbol_asc .. h[3] end, + ["rpg_desc"] = function (h) h[3] = symbol_desc .. h[3] end, + ["total_time_played_asc"] = function (h) h[4] = symbol_asc .. h[4] end, + ["total_time_played_desc"] = function (h) h[4] = symbol_desc .. h[4] end, + ["time_played_asc"] = function (h) h[5] = symbol_asc .. h[5] end, + ["time_played_desc"] = function (h) h[5] = symbol_desc .. h[5] end, + ["pokes_asc"] = function (h) h[6] = symbol_asc .. h[6] end, + ["pokes_desc"] = function (h) h[6] = symbol_desc .. h[6] end + } + + if sort_by then + global.player_list.sorting_method[player.index] = sort_by + else + sort_by = global.player_list.sorting_method[player.index] + end + + header_modifier[sort_by](headers) + + for k, v in ipairs(headers) do + local label = t.add { + type = "label", + name = "player_list_panel_header_" .. k, + caption = v + } + label.style.font = "default-bold" + label.style.font_color = { r=0.98, g=0.66, b=0.22 } + end + + -- special style on first header + local label = t["player_list_panel_header_1"] + label.style.minimal_width = 36 + label.style.maximal_width = 36 + label.style.horizontal_align = "right" + + -- List management + local player_list_panel_table = frame.add { type = "scroll-pane", name = "scroll_pane", direction = "vertical", horizontal_scroll_policy = "never", vertical_scroll_policy = "auto"} + player_list_panel_table.style.maximal_height = 530 + + player_list_panel_table = player_list_panel_table.add { type = "table", name = "player_list_panel_table", column_count = 6 } + + local player_list = get_sorted_list(sort_by) + for i = 1, #player_list, 1 do + -- Icon + local sprite = player_list_panel_table.add { type = "sprite", name = "player_rank_sprite_" .. i, sprite = player_list[i].rank } + sprite.style.minimal_width = column_widths[1] + sprite.style.maximal_width = column_widths[1] + + -- Name + local label = player_list_panel_table.add { type = "label", name = "player_list_panel_player_names_" .. i, caption = player_list[i].name } + label.style.font = "default" + label.style.font_color = { + r = .4 + game.players[player_list[i].player_index].color.r * 0.6, + g = .4 + game.players[player_list[i].player_index].color.g * 0.6, + b = .4 + game.players[player_list[i].player_index].color.b * 0.6, + } + label.style.minimal_width = column_widths[2] + label.style.maximal_width = column_widths[2] + + -- RPG level + local label = player_list_panel_table.add { type = "label", name = "player_list_panel_RPG_level_" .. i, caption = player_list[i].rpg_level } + label.style.minimal_width = column_widths[3] + label.style.maximal_width = column_widths[3] + + -- Total time + local label = player_list_panel_table.add { type = "label", name = "player_list_panel_player_total_time_played_" .. i, caption = player_list[i].total_played_time } + label.style.minimal_width = column_widths[4] + label.style.maximal_width = column_widths[4] + + -- Current time + local label = player_list_panel_table.add { type = "label", name = "player_list_panel_player_time_played_" .. i, caption = player_list[i].played_time } + label.style.minimal_width = column_widths[5] + label.style.maximal_width = column_widths[5] + + -- Poke + local flow = player_list_panel_table.add { type = "flow", name = "button_flow_" .. i, direction = "horizontal" } + flow.add { type = "label", name = "button_spacer_" .. i, caption = "" } + local button = flow.add { type = "button", name = "poke_player_" .. player_list[i].name, caption = player_list[i].pokes } + button.style.font = "default" + label.style.font_color = { r=0.83, g=0.83, b=0.83} + button.style.minimal_height = 30 + button.style.minimal_width = 30 + button.style.maximal_height = 30 + button.style.maximal_width = 30 + button.style.top_padding = 0 + button.style.left_padding = 0 + button.style.right_padding = 0 + button.style.bottom_padding = 0 + end +end + +local function on_gui_click(event) + if not event then return end + if not event.element then return end + if not event.element.valid then return end + if not event.element.name then return end + local player = game.players[event.element.player_index] + + local frame = Tabs.comfy_panel_get_active_frame(player) + if not frame then return end + if frame.name ~= "Players" then return end + + local name = event.element.name + local actions = { + ["player_list_panel_header_2"] = function () + if string.find(event.element.caption, symbol_desc) then + player_list_show(player, frame, "name_asc") + else + player_list_show(player, frame,"name_desc") + end + end, + + ["player_list_panel_header_3"] = function () + if string.find(event.element.caption, symbol_desc) then + player_list_show(player, frame,"rpg_asc") + else + player_list_show(player, frame,"rpg_desc") + end + end, + + ["player_list_panel_header_4"] = function () + if string.find(event.element.caption, symbol_desc) then + player_list_show(player, frame,"total_time_played_asc") + else + player_list_show(player, frame,"total_time_played_desc") + end + end, + + ["player_list_panel_header_5"] = function () + if string.find(event.element.caption, symbol_desc) then + player_list_show(player, frame,"time_played_asc") + else + player_list_show(player, frame,"time_played_desc") + end + end, + + ["player_list_panel_header_6"] = function () + if string.find(event.element.caption, symbol_desc) then + player_list_show(player, frame,"pokes_asc") + else + player_list_show(player, frame,"pokes_desc") + end + end, + } + + if actions[name] then + actions[name]() + return + end + + if not event.element.valid then return end + --Poke other players + if string.sub(event.element.name, 1, 11) == "poke_player" then + local poked_player = string.sub(event.element.name, 13, string.len(event.element.name)) + if player.name == poked_player then return end + if global.player_list.last_poke_tick[event.element.player_index] + 300 < game.tick then + local str = ">> " + str = str .. player.name + str = str .. " has poked " + str = str .. poked_player + str = str .. " with " + local z = math.random(1,#pokemessages) + str = str .. pokemessages[z] + str = str .. " <<" + game.print(str) + global.player_list.last_poke_tick[event.element.player_index] = game.tick + local p = game.players[poked_player] + global.player_list.pokes[p.index] = global.player_list.pokes[p.index] + 1 + end + end +end + +local function refresh() + for _, player in pairs(game.connected_players) do + local frame = Tabs.comfy_panel_get_active_frame(player) + if frame then + if frame.name ~= "Players" then return end + player_list_show(player, frame, global.player_list.sorting_method[player.index]) + end + end +end + +local function on_player_joined_game(event) + local player = game.players[event.player_index] + if not global.player_list.last_poke_tick[event.player_index] then + global.player_list.pokes[event.player_index] = 0 + global.player_list.last_poke_tick[event.player_index] = 0 + global.player_list.sorting_method[event.player_index] = "total_time_played_desc" + end + refresh() +end + +local function on_player_left_game(event) + refresh() +end + +local on_init = function() + global.player_list = {} + global.player_list.last_poke_tick = {} + global.player_list.pokes = {} + global.player_list.sorting_method = {} +end + +comfy_panel_tabs["Players"] = {gui = player_list_show, admin = false} + +event.on_init(on_init) +event.add(defines.events.on_player_joined_game, on_player_joined_game) +event.add(defines.events.on_player_left_game, on_player_left_game) +event.add(defines.events.on_gui_click, on_gui_click) \ No newline at end of file diff --git a/maps/scrapyard/rpg.lua b/maps/scrapyard/rpg.lua index fc5661a2..50e7e354 100644 --- a/maps/scrapyard/rpg.lua +++ b/maps/scrapyard/rpg.lua @@ -18,6 +18,7 @@ require "player_modifiers" local math_random = math.random local Global = require 'utils.global' local Tabs = require "comfy_panel.main" +local Color = require 'utils.color_presets' local P = require "player_modifiers" local visuals_delay = 1800 local level_up_floating_text_color = {0, 205, 0} @@ -38,6 +39,10 @@ local rpg_frame_icons = { "entity/behemoth-spitter" } +local math_sqrt = math.sqrt +local math_floor = math.floor +local math_random = math.random + Global.register( {rpg_t=rpg_t, rpg_frame_icons=rpg_frame_icons}, function(tbl) @@ -109,7 +114,7 @@ local function update_player_stats(player) 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.15 + 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) @@ -453,7 +458,14 @@ local function level_up(player) end local function gain_xp(player, amount) - amount = math.round(amount, 2) + local fee + if rpg_t[player.index].xp > 50 then + fee = math.ceil(rpg_t[player.index].xp * 0.01, 0) / 6 + 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 @@ -468,6 +480,25 @@ local function gain_xp(player, amount) rpg_t[player.index].last_floaty_text = game.tick + visuals_delay end +function global_pool() + local pool = rpg_t.global_pool + local player_count = #game.connected_players + local share = pool / player_count + 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} + 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 + 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 @@ -541,7 +572,7 @@ local function on_gui_click(event) if not player.character then return end if event.button == defines.mouse_button_type.right then - for a = 1, 5, 1 do + 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 @@ -843,7 +874,9 @@ end local function on_player_crafted_item(event) if not event.recipe.energy then return end local player = game.players[event.player_index] - gain_xp(player, event.recipe.energy * 0.20) + if not player.valid then return end + local amount = math_floor(math_random(0.40, 4)) + gain_xp(player, event.recipe.energy * amount) end local function on_player_respawned(event) @@ -855,7 +888,7 @@ 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 + 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 @@ -865,6 +898,7 @@ local function on_player_joined_game(event) 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) end diff --git a/maps/scrapyard/table.lua b/maps/scrapyard/table.lua index f5cb581e..11c4d9a5 100644 --- a/maps/scrapyard/table.lua +++ b/maps/scrapyard/table.lua @@ -16,7 +16,15 @@ local this = { scrap_enabled = true, rocks_yield_ore_maximum_amount = 500, rocks_yield_ore_base_amount = 50, - rocks_yield_ore_distance_modifier = 0.020 + rocks_yield_ore_distance_modifier = 0.020, + left_top = { + x = 0, + y = 0 + }, + o_left_top = { + x = 0, + y = 0 + } } local Public = {} @@ -43,6 +51,14 @@ function Public.reset_table() this.cargo_max_health = 10000 this.revealed_spawn = 0 this.scrap_enabled = true + this.left_top = { + x = 0, + y = 0 + } + this.o_left_top = { + x = 0, + y = 0 + } end function Public.get_table() diff --git a/maps/scrapyard/terrain.lua b/maps/scrapyard/terrain.lua index d1a72137..b11d2dfd 100644 --- a/maps/scrapyard/terrain.lua +++ b/maps/scrapyard/terrain.lua @@ -9,12 +9,15 @@ local map_functions = require "tools.map_functions" local Scrap_table = require "maps.scrapyard.table" local shapes = require "tools.shapes" local Loot = require 'maps.scrapyard.loot' + +local Public = {} + local insert = table.insert local math_random = math.random local math_floor = math.floor local math_abs = math.abs local uncover_radius = 10 -local level_depth = 960 +Public.level_depth = 960 local worm_level_modifier = 0.18 local rock_raffle = {"sand-rock-big","sand-rock-big", "rock-big","rock-big","rock-big","rock-big","rock-big","rock-big","rock-big","rock-big","rock-huge"} @@ -39,7 +42,7 @@ local noises = { ["scrapyard"] = {{modifier = 0.005, weight = 1}, {modifier = 0.01, weight = 0.35}, {modifier = 0.05, weight = 0.23}, {modifier = 0.1, weight = 0.11}}, } -local Public = {} + local function get_noise(name, pos, seed) local noise = 0 @@ -68,7 +71,7 @@ local function place_random_scrap_entity(surface, position) end if r < 75 then local e = surface.create_entity({name = "gun-turret", position = position, force = "scrap_defense"}) - if math_abs(position.y) < level_depth * 2.5 then + if math_abs(position.y) < Public.level_depth * 2.5 then e.insert({name = "piercing-rounds-magazine", count = math_random(64, 128)}) else e.insert({name = "uranium-rounds-magazine", count = math_random(64, 128)}) @@ -165,7 +168,7 @@ local function wall(surface, left_top, seed) if math_random(1, 32) == 1 then if surface.can_place_entity({name = "gun-turret", position = p, force = "enemy"}) then local e = surface.create_entity({name = "gun-turret", position = p, force = "enemy"}) - if math_abs(p.y) < level_depth * 2.5 then + if math_abs(p.y) < Public.level_depth * 2.5 then e.insert({name = "piercing-rounds-magazine", count = math_random(64, 128)}) else e.insert({name = "uranium-rounds-magazine", count = math_random(64, 128)}) @@ -613,7 +616,7 @@ local function process_level_1_position(surface, p, seed, tiles, entities, fishe if math_random(1,100) > 30 then entities[#entities + 1] = {name = "mineable-wreckage", position = p} end end -local levels = { +Public.levels = { process_level_1_position, process_level_2_position, process_level_3_position, @@ -637,8 +640,8 @@ function Public.reveal_area(x, y, surface, max_radius) local entities = {} local markets = {} local treasure = {} - local process_level = levels[math_floor(math_abs(y) / level_depth) + 1] - if not process_level then process_level = levels[#levels] end + 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} @@ -695,8 +698,8 @@ function Public.reveal(player) local entities = {} local markets = {} local treasure = {} - local process_level = levels[math_floor(math_abs(position.y) / level_depth) + 1] - if not process_level then process_level = levels[#levels] end + 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 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} @@ -915,8 +918,8 @@ local function on_chunk_generated(event) if string.sub(event.surface.name, 0, 9) ~= "scrapyard" then return end local surface = event.surface local left_top = event.area.left_top - if left_top.x >= level_depth * 0.5 then out_of_map(surface, left_top) return end - if left_top.x < level_depth * -0.5 then out_of_map(surface, left_top) return end + if left_top.x >= Public.level_depth * 0.5 then out_of_map(surface, left_top) return end + if left_top.x < Public.level_depth * -0.5 then out_of_map(surface, left_top) return end if surface.name ~= event.surface.name then return end if this.revealed_spawn > game.tick then @@ -935,7 +938,11 @@ local function on_chunk_generated(event) end end - if left_top.y % level_depth == 0 and left_top.y < 0 and left_top.y > level_depth * -10 then wall(surface, left_top, surface.map_gen_settings.seed) return end + if left_top.y % Public.level_depth == 0 and left_top.y < 0 and left_top.y > Public.level_depth * -10 then + this.left_top = event.area.left_top + wall(surface, left_top, surface.map_gen_settings.seed) + return + end if left_top.y > 268 then out_of_map(surface, left_top) return end if left_top.y >= 0 then replace_water(surface, left_top) end