From b4bc0254a910d5100d9e27599b2fc60002a2a558 Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Thu, 30 Apr 2020 11:44:57 +0200 Subject: [PATCH] scrapyard fixes --- maps/scrapyard/burden.lua | 4 +- maps/scrapyard/comfylatron.lua | 2 +- maps/scrapyard/icw/constants.lua | 8 +- maps/scrapyard/icw/functions.lua | 10 +- maps/scrapyard/locomotive.lua | 129 +++--- maps/scrapyard/main.lua | 174 +++++--- .../mineable_wreckage_yields_scrap.lua | 384 +++++++++++------- maps/scrapyard/rpg.lua | 69 +++- maps/scrapyard/table.lua | 3 + maps/scrapyard/terrain.lua | 24 +- 10 files changed, 521 insertions(+), 286 deletions(-) diff --git a/maps/scrapyard/burden.lua b/maps/scrapyard/burden.lua index a3b454d5..b5f710e5 100644 --- a/maps/scrapyard/burden.lua +++ b/maps/scrapyard/burden.lua @@ -37,9 +37,9 @@ local function check_burden(event) player_modifiers[player.index].character_running_speed_modifier["scrapyard"] = 0.3 - fullness player_modifiers[player.index].character_mining_speed_modifier["scrapyard"] = 0.3 - fullness Modifier.update_player_modifiers(player) - if fullness >= 0.5 and fullness <= 0.51 then + if fullness >= 0.3 and fullness <= 0.301 then player.print("You feel all of a sudden burden.", Color.yellow) - elseif fullness >= 0.9 and fullness <= 0.91 then + elseif fullness >= 0.5 and fullness <= 0.501 then player.print("Maybe you should drop some of that inventory to lessen the burden.", Color.red) end end diff --git a/maps/scrapyard/comfylatron.lua b/maps/scrapyard/comfylatron.lua index dbf47816..3112a150 100644 --- a/maps/scrapyard/comfylatron.lua +++ b/maps/scrapyard/comfylatron.lua @@ -369,7 +369,7 @@ local function spawn_comfylatron(surface, x, y) this.comfylatron = surface.create_entity({ name = "compilatron", position = {x,y + math_random(0,26)}, - force = "player", + force = "neutral", create_build_effect_smoke = false }) end diff --git a/maps/scrapyard/icw/constants.lua b/maps/scrapyard/icw/constants.lua index d9f5b8b4..a2afabbd 100644 --- a/maps/scrapyard/icw/constants.lua +++ b/maps/scrapyard/icw/constants.lua @@ -8,10 +8,10 @@ Public.wagon_types = { } Public.wagon_areas = { - ["cargo-wagon"] = {left_top = {x = -18, y = 0}, right_bottom = {x = 18, y = 70}}, - ["artillery-wagon"] = {left_top = {x = -18, y = 0}, right_bottom = {x = 18, y = 70}}, - ["fluid-wagon"] = {left_top = {x = -18, y = 0}, right_bottom = {x = 18, y = 70}}, - ["locomotive"] = {left_top = {x = -18, y = 0}, right_bottom = {x = 18, y = 70}}, + ["cargo-wagon"] = {left_top = {x = -20, y = 0}, right_bottom = {x = 20, y = 80}}, + ["artillery-wagon"] = {left_top = {x = -20, y = 0}, right_bottom = {x = 20, y = 80}}, + ["fluid-wagon"] = {left_top = {x = -20, y = 0}, right_bottom = {x = 20, y = 80}}, + ["locomotive"] = {left_top = {x = -20, y = 0}, right_bottom = {x = 20, y = 80}}, } return Public \ No newline at end of file diff --git a/maps/scrapyard/icw/functions.lua b/maps/scrapyard/icw/functions.lua index 46bcea96..28b9aa1b 100644 --- a/maps/scrapyard/icw/functions.lua +++ b/maps/scrapyard/icw/functions.lua @@ -503,16 +503,20 @@ end function Public.reconstruct_all_trains(icw) icw.trains = {} for unit_number, wagon in pairs(icw.wagons) do - if wagon.entity and wagon.entity.valid then - local carriages = wagon.entity.train.carriages - Public.construct_train(icw, carriages) + if not wagon.entity or not wagon.entity.valid then + icw.wagons[unit_number] = nil + Public.request_reconstruction(icw) + return 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) diff --git a/maps/scrapyard/locomotive.lua b/maps/scrapyard/locomotive.lua index c2d15e4a..9ef10ca0 100644 --- a/maps/scrapyard/locomotive.lua +++ b/maps/scrapyard/locomotive.lua @@ -71,9 +71,9 @@ function Public.contains_positions(pos, area) return false end -function Public.power_source() - local this = Scrap_table.get_table() - local surface = game.surfaces[this.active_surface_index] +local function rebuild_energy_overworld(data) + local this = data.this + local surface = data.surface if not this.locomotive then return end if not this.locomotive.valid then return end if not this.locomotive.surface then return end @@ -87,17 +87,17 @@ function Public.power_source() } if Public.contains_positions(this.locomotive.position, area) then return end this.old_ow_energy = this.ow_energy.energy - this.ow_energy.destroy() + this.ow_energy.destroy() this.energy["scrapyard"] = nil end end - this.ow_energy = surface.create_entity{ - name = "electric-energy-interface", + this.ow_energy = surface.create_entity{ + name = "electric-energy-interface", position = { x=this.locomotive.position.x, y=this.locomotive.position.y+1 }, - create_build_effect_smoke = false, + create_build_effect_smoke = false, force = game.forces.neutral } @@ -120,33 +120,72 @@ function Public.power_source() end end -function Public.on_teleported_player() - local this = Scrap_table.get_table() +local function rebuild_energy_loco(data, destroy) + local this = data.this + local icw_table = data.icw_table local unit_surface = this.locomotive.unit_number - local loco_surface = game.surfaces[tostring(unit_surface)] - local pos = {x=-17, y=3} + local loco_surface = game.surfaces[icw_table.wagons[unit_surface].surface.index] + local pos = {x=-19, y=3} + + if destroy then + local radius = 1024 + local area = {{x = -radius, y = -radius}, {x = radius, y = radius}} + for _, entity in pairs(loco_surface.find_entities_filtered{area = area, name = "electric-energy-interface"}) do + entity.destroy() + end + this.energy.loco = nil + this.lo_energy = nil + end + + this.lo_energy = loco_surface.create_entity{ + name = "electric-energy-interface", + position = pos, + create_build_effect_smoke = false, + force = game.forces.neutral + } + + rendering.draw_text{ + text = "Power", + surface = loco_surface, + target = this.lo_energy, + target_offset = {0, -1.5}, + color = { r = 0, g = 1, b = 0}, + alignment = "center" + } + + this.lo_energy.minable = false + this.lo_energy.destructible = false + this.lo_energy.operable = false + this.lo_energy.power_production = 0 + this.lo_energy.electric_buffer_size = 10000000 +end + +function Public.power_source_overworld() + local this = Scrap_table.get_table() + local surface = game.surfaces[this.active_surface_index] + + local data = { + this = this, + surface = surface + } + + rebuild_energy_overworld(data) +end + +function Public.power_source_locomotive() + local this = Scrap_table.get_table() + local icw_table = ICW.get_table() + + local data = { + this = this, + icw_table = icw_table + } + if not this.lo_energy then - this.lo_energy = loco_surface.create_entity{ - name = "electric-energy-interface", - position = pos, - create_build_effect_smoke = false, - force = game.forces.neutral - } + rebuild_energy_loco(data) - rendering.draw_text{ - text = "Power", - surface = loco_surface, - target = this.lo_energy, - target_offset = {0, -1.5}, - color = { r = 0, g = 1, b = 0}, - alignment = "center" - } - - this.lo_energy.minable = false - this.lo_energy.destructible = false - this.lo_energy.operable = false - this.lo_energy.power_production = 0 - this.lo_energy.electric_buffer_size = 10000000 + elseif not this.lo_energy.valid then + rebuild_energy_loco(data, true) end end @@ -159,7 +198,7 @@ local function fish_tag() 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() + this.locomotive_tag.destroy() end end this.locomotive_tag = this.locomotive_cargo.force.add_chart_tag( @@ -169,29 +208,11 @@ local function fish_tag() text = " " }) end ---[[ -local function accelerate() - local this = Scrap_table.get_table() - if not this.locomotive then return end - if not this.locomotive.valid then return end - if this.locomotive.get_driver() then return end - this.locomotive_driver = this.locomotive.surface.create_entity({name = "character", position = this.locomotive.position, force = "player"}) - this.locomotive_driver.driving = true - this.locomotive_driver.riding_state = {acceleration = defines.riding.acceleration.accelerating, direction = defines.riding.direction.straight} -end -local function remove_acceleration() - if not this.locomotive then return end - if not this.locomotive.valid then return end - if this.locomotive_driver then this.locomotive_driver.destroy() end - this.locomotive_driver = nil -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.health = this.locomotive_cargo.health + 6 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 @@ -199,20 +220,16 @@ local function set_player_spawn_and_refill_fish() end local function tick() - Public.power_source() + Public.power_source_overworld() + Public.power_source_locomotive() if game.tick % 30 == 0 then if game.tick % 1800 == 0 then set_player_spawn_and_refill_fish() end fish_tag() - --accelerate() - --else - --remove_acceleration() end end Event.on_nth_tick(5, tick) -Event.add(defines.events.on_player_driving_changed_state, Public.on_teleported_player) - return Public \ No newline at end of file diff --git a/maps/scrapyard/main.lua b/maps/scrapyard/main.lua index 09c1f758..1a302020 100644 --- a/maps/scrapyard/main.lua +++ b/maps/scrapyard/main.lua @@ -5,16 +5,14 @@ require "modules.shotgun_buff" require "maps.scrapyard.burden" require "modules.rocks_heal_over_time" require "modules.no_deconstruction_of_neutral_entities" -require "maps.scrapyard.mineable_wreckage_yields_scrap" require "maps.scrapyard.flamethrower_nerf" require "modules.rocks_yield_ore_veins" require "modules.spawners_contain_biters" require "modules.biters_yield_coins" require "modules.biter_noms_you" -require "modules.explosives" require "modules.wave_defense.main" require "maps.scrapyard.comfylatron" -require "modules.rocks_broken_paint_tiles" +require "modules.explosives" local ICW = require "maps.scrapyard.icw.main" local WD = require "modules.wave_defense.table" @@ -26,7 +24,6 @@ local unearthing_worm = require "functions.unearthing_worm" local unearthing_biters = require "functions.unearthing_biters" local Loot = require 'maps.scrapyard.loot' local Pets = require "modules.biter_pets" -local Modifier = require "player_modifiers" local tick_tack_trap = require "functions.tick_tack_trap" local Terrain = require 'maps.scrapyard.terrain' local Event = require 'utils.event' @@ -42,6 +39,7 @@ local math_floor = math.floor 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 = {"black-refined-concrete", "orange-refined-concrete", "red-refined-concrete", "yellow-refined-concrete", "acid-refined-concrete", "brown-refined-concrete", "blue-refined-concrete"} local treasure_chest_messages = { "You notice an old crate within the rubble. It's filled with treasure!", "You find a chest underneath the broken rocks. It's filled with goodies!", @@ -133,10 +131,13 @@ function Public.reset_map() surface.ticks_per_day = surface.ticks_per_day * 2 surface.min_brightness = 0.08 surface.daytime = 0.7 + surface.brightness_visual_weights = {1, 0, 0, 0} + surface.freeze_daytime = false + surface.solar_power_multiplier = 1 this.locomotive_health = 10000 this.locomotive_max_health = 10000 this.cargo_health = 10000 - this.cargo_max_health = 10000 + this.cargo_max_health = 10000 Locomotive(surface, {x = -18, y = 10}) render_train_hp() @@ -264,14 +265,20 @@ end local function set_difficulty() local wave_defense_table = WD.get_table() + local player_count = #game.connected_players + + wave_defense_table.max_active_biters = 1024 + + -- threat gain / wave + wave_defense_table.threat_gain_multiplier = 2 + player_count * 0.1 + - wave_defense_table.threat_gain_multiplier = 2 + #game.connected_players * 0.1 --20 Players for fastest wave_interval - wave_defense_table.wave_interval = 3600 - #game.connected_players * 90 + wave_defense_table.wave_interval = 3600 - player_count * 90 if wave_defense_table.wave_interval < 1800 then wave_defense_table.wave_interval = 1800 end end -local function protect_this(entity) +local function is_protected(entity) local this = Scrap_table.get_table() if string.sub(entity.surface.name, 0, 9) ~= "scrapyard" then return true end local protected = {this.locomotive, this.locomotive_cargo} @@ -286,7 +293,7 @@ end local function protect_train(event) local this = Scrap_table.get_table() if event.entity.force.index ~= 1 then return end --Player Force - if protect_this(event.entity) then + if is_protected(event.entity) then if event.entity == this.locomotive_cargo or event.entity == this.locomotive then if event.cause then if event.cause.force.index == 2 or event.cause.force.name == "scrap_defense" or event.cause.force.name == "scrap" then @@ -301,11 +308,16 @@ local function protect_train(event) end end -local function change_tile(surface,pos) - local colors = {"black", "orange", "red", "yellow", "acid", "brown", "green", "blue"} - surface.set_tiles{{name = colors[math_random(1, #colors)].. "-refined-concrete", position=pos}} + +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] @@ -314,17 +326,23 @@ local function on_player_changed_position(event) 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.y < 5 then - local shallow = surface.get_tile(position).name == "water-shallow" - local deepwater = surface.get_tile(position).name == "deepwater-green" - if shallow or deepwater then goto continue end - change_tile(surface, position) + if position.y < 5 then + for x = -1,1 do + for y = -1,1 do + local _pos = {position.x+x,position.y+y} + local steps = this.steps[player.index] + 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) + this.steps[player.index] = this.steps[player.index] + 1 + end + end end ::continue:: if position.y < 5 then Terrain.reveal(player) end if position.y >= 190 then player.teleport({position.x, position.y - 1}, surface) - player.print("The forcefield does not approve.",{r=0.98, g=0.66, b=0.22}) + player.print("[color=blue]Grandmaster:[/color] forcefield does not approve.",{r=0.98, g=0.66, b=0.22}) if player.character then player.character.health = player.character.health - 5 player.character.surface.create_entity({name = "water-splash", position = position}) @@ -333,30 +351,33 @@ local function on_player_changed_position(event) end end -local function on_player_left_game(event) +local function on_player_left_game() set_difficulty() end local function on_player_joined_game(event) local this = Scrap_table.get_table() - local player_modifiers = Modifier.get_table() local surface = game.surfaces[this.active_surface_index] local player = game.players[event.player_index] + if not this.steps[player.index] then this.steps[player.index] = 0 end + --if not this.scrap_enabled[player.index] then this.scrap_enabled[player.index] = true end + set_difficulty(event) + if not this.first_join[player.index] then + player.print("[color=blue]Grandmaster:[/color] Greetings, newly joined [color=yellow]" .. player.name .. "[/color]!", {r = 1, g = 0.5, b = 0.1}) + player.print("[color=blue]Grandmaster:[/color] Do read the map info.", {r = 1, g = 0.5, b = 0.1}) + player.print("[color=blue]Grandmaster:[/color] Guide the choo through the black mist.", {r = 1, g = 0.5, b = 0.1}) + this.first_join[player.index] = true + end + if player.surface.index ~= this.active_surface_index then player.teleport(surface.find_non_colliding_position("character", game.forces.player.get_spawn_position(surface), 3, 0,5), surface) for item, amount in pairs(starting_items) do player.insert({name = item, count = amount}) end end - - player_modifiers[player.index].character_mining_speed_modifier["scrapyard"] = 0 - Modifier.update_player_modifiers(player) - if this.first_load then return end - --Public.reset_map() - this.first_load = true end local function hidden_biter(entity) @@ -388,7 +409,7 @@ end local function hidden_treasure(event) if math.random(1, 320) ~= 1 then return end game.players[event.player_index].print(treasure_chest_messages[math.random(1, #treasure_chest_messages)], {r=0.98, g=0.66, b=0.22}) - Loot.add(event.entity.surface, event.entity.position, "crash-site-chest-2") + Loot.add(event.entity.surface, event.entity.position, "wooden-chest") end local function biters_chew_rocks_faster(event) @@ -582,6 +603,13 @@ local function on_built_entity(event) end end +local function on_research_finished(event) + event.research.force.character_inventory_slots_bonus = game.forces.player.mining_drill_productivity_bonus * 50 -- +5 Slots / level + local mining_speed_bonus = game.forces.player.mining_drill_productivity_bonus * 5 -- +50% speed / level + if event.research.force.technologies["steel-axe"].researched then mining_speed_bonus = mining_speed_bonus + 0.5 end -- +50% speed for steel-axe research + event.research.force.manual_mining_speed_modifier = mining_speed_bonus +end + local function on_robot_built_entity(event) if string.sub(event.created_entity.surface.name, 0, 9) ~= "scrapyard" then return end local y = event.created_entity.position.y @@ -605,15 +633,7 @@ local function on_robot_built_entity(event) end end -local function on_research_finished(event) - event.research.force.character_inventory_slots_bonus = game.forces.player.mining_drill_productivity_bonus * 50 -- +5 Slots / level - local mining_speed_bonus = game.forces.player.mining_drill_productivity_bonus * 5 -- +50% speed / level - if event.research.force.technologies["steel-axe"].researched then mining_speed_bonus = mining_speed_bonus + 0.5 end -- +50% speed for steel-axe research - event.research.force.manual_mining_speed_modifier = mining_speed_bonus -end - local on_init = function() - local this = Scrap_table.get_table() game.create_force("scrap") game.create_force("scrap_defense") game.forces.player.set_friend('scrap', true) @@ -643,6 +663,12 @@ local on_init = function() T.main_caption_color = {r = 150, g = 150, b = 0} T.sub_caption_color = {r = 0, g = 150, b = 0} + local mgs = game.surfaces["nauvis"].map_gen_settings + mgs.width = 16 + mgs.height = 16 + game.surfaces["nauvis"].map_gen_settings = mgs + game.surfaces["nauvis"].clear() + global.explosion_cells_destructible_tiles = { ["out-of-map"] = 1500, ["water"] = 1000, @@ -653,8 +679,56 @@ local on_init = function() } end +local function darkness(this) + local rnd = math.random + local surface = game.surfaces[this.active_surface_index] + if rnd(1, 64) == 1 then + if surface.freeze_daytime then return end + game.print("[color=blue]Grandmaster:[/color] A solar eclipse has occured!", {r = 1, g = 0.5, b = 0.1}) + surface.min_brightness = 0.10 + surface.brightness_visual_weights = {0.90, 0.90, 0.90} + surface.daytime = 0.42 + surface.freeze_daytime = true + surface.solar_power_multiplier = 999 + return + elseif rnd(1, 32) == 1 then + if not surface.freeze_daytime then return end + game.print("[color=blue]Grandmaster:[/color] 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.5 + surface.freeze_daytime = false + surface.solar_power_multiplier = 1 + return + end +end + + +local function scrap_randomness(this) + local rnd = math.random + if rnd(1, 32) == 1 then + if not this.scrap_enabled then return end + this.scrap_enabled = false + game.print("[color=blue]Grandmaster:[/color] It seems that the scrap is temporarily gone.", {r = 1, g = 0.5, b = 0.1}) + game.print("[color=blue]Grandmaster:[/color] Output from scrap is now only ores.", {r = 1, g = 0.5, b = 0.1}) + return + elseif rnd(1, 32) == 1 then + if this.scrap_enabled then return end + this.scrap_enabled = true + game.print("[color=blue]Grandmaster:[/color] Scrap is back!", {r = 1, g = 0.5, b = 0.1}) + game.print("[color=blue]Grandmaster:[/color] Output from scrap is now randomized.", {r = 1, g = 0.5, b = 0.1}) + return + end +end + local on_tick = function() local this = Scrap_table.get_table() + if game.tick % 30 == 0 then + if game.tick % 1800 == 0 then + 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 @@ -665,26 +739,25 @@ local on_tick = function() end if _DEBUG then - commands.add_command( - 'reset_game', - 'Debug only, reset the game!', - function() - local player = game.player +commands.add_command( + 'reset_game', + 'Debug only, reset the game!', + function() + local player = game.player - if player then - if player ~= nil then - if not player.admin then - return - end - end - end - Public.reset_map() + if player then + if player ~= nil then + if not player.admin then + return + end + end + end + Public.reset_map() end) end Event.on_nth_tick(5, on_tick) Event.on_init(on_init) -Event.add(defines.events.on_research_finished, on_research_finished) Event.add(defines.events.on_entity_damaged, on_entity_damaged) Event.add(defines.events.on_player_joined_game, on_player_joined_game) Event.add(defines.events.on_player_left_game, on_player_left_game) @@ -694,7 +767,8 @@ Event.add(defines.events.on_entity_died, on_entity_died) Event.add(defines.events.on_robot_built_entity, on_robot_built_entity) Event.add(defines.events.on_built_entity, on_built_entity) Event.add(defines.events.on_player_changed_position, on_player_changed_position) +Event.add(defines.events.on_research_finished, on_research_finished) -require "modules.rocks_yield_ore" +require "maps.scrapyard.mineable_wreckage_yields_scrap" 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 a9eaadb4..4638ddc9 100644 --- a/maps/scrapyard/mineable_wreckage_yields_scrap.lua +++ b/maps/scrapyard/mineable_wreckage_yields_scrap.lua @@ -1,154 +1,254 @@ -local mining_chance_weights = { - {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}, - {name = "copper-cable", chance = 380}, - {name = "electronic-circuit", chance = 150}, - {name = "steel-plate", chance = 120}, - {name = "solid-fuel", chance = 89}, - {name = "pipe", chance = 75}, - {name = "iron-stick", chance = 50}, - {name = "battery", chance = 20}, - {name = "empty-barrel", chance = 10}, - {name = "crude-oil-barrel", chance = 10}, - {name = "lubricant-barrel", chance = 10}, - {name = "petroleum-gas-barrel", chance = 10}, - {name = "sulfuric-acid-barrel", chance = 10}, - {name = "heavy-oil-barrel", chance = 10}, - {name = "light-oil-barrel", chance = 10}, - {name = "water-barrel", chance = 10}, - {name = "green-wire", chance = 10}, - {name = "red-wire", chance = 10}, - {name = "explosives", chance = 5}, - {name = "advanced-circuit", chance = 5}, - {name = "nuclear-fuel", chance = 1}, - {name = "pipe-to-ground", chance = 10}, - {name = "plastic-bar", chance = 5}, - {name = "processing-unit", chance = 2}, - {name = "used-up-uranium-fuel-cell", chance = 1}, - {name = "uranium-fuel-cell", chance = 1}, - {name = "rocket-fuel", chance = 3}, - {name = "rocket-control-unit", chance = 1}, - {name = "low-density-structure", chance = 1}, - {name = "heat-pipe", chance = 1}, - {name = "engine-unit", chance = 4}, - {name = "electric-engine-unit", chance = 2}, - {name = "logistic-robot", chance = 1}, - {name = "construction-robot", chance = 1}, - - {name = "land-mine", chance = 3}, - {name = "grenade", chance = 10}, - {name = "rocket", chance = 3}, - {name = "explosive-rocket", chance = 3}, - {name = "cannon-shell", chance = 2}, - {name = "explosive-cannon-shell", chance = 2}, - {name = "uranium-cannon-shell", chance = 1}, - {name = "explosive-uranium-cannon-shell", chance = 1}, - {name = "artillery-shell", chance = 1}, - {name = "cluster-grenade", chance = 2}, - {name = "defender-capsule", chance = 5}, - {name = "destroyer-capsule", chance = 1}, - {name = "distractor-capsule", chance = 2} -} +local Scrap_table = require "maps.scrapyard.table" -local scrap_yield_amounts = { - ["iron-ore"] = 8, - ["copper-ore"] = 8, - ["stone"] = 4, - ["coal"] = 6, - ["iron-plate"] = 16, - ["iron-gear-wheel"] = 8, - ["iron-stick"] = 16, - ["copper-plate"] = 16, - ["copper-cable"] = 24, - ["electronic-circuit"] = 8, - ["steel-plate"] = 4, - ["pipe"] = 8, - ["solid-fuel"] = 4, - ["empty-barrel"] = 3, - ["crude-oil-barrel"] = 3, - ["lubricant-barrel"] = 3, - ["petroleum-gas-barrel"] = 3, - ["sulfuric-acid-barrel"] = 3, - ["heavy-oil-barrel"] = 3, - ["light-oil-barrel"] = 3, - ["water-barrel"] = 3, - ["battery"] = 2, - ["explosives"] = 4, - ["advanced-circuit"] = 2, - ["nuclear-fuel"] = 0.1, - ["pipe-to-ground"] = 1, - ["plastic-bar"] = 4, - ["processing-unit"] = 1, - ["used-up-uranium-fuel-cell"] = 1, - ["uranium-fuel-cell"] = 0.3, - ["rocket-fuel"] = 0.3, - ["rocket-control-unit"] = 0.3, - ["low-density-structure"] = 0.3, - ["heat-pipe"] = 1, - ["green-wire"] = 8, - ["red-wire"] = 8, - ["engine-unit"] = 2, - ["electric-engine-unit"] = 2, - ["logistic-robot"] = 0.3, - ["construction-robot"] = 0.3, - - ["land-mine"] = 1, - ["grenade"] = 2, - ["rocket"] = 2, - ["explosive-rocket"] = 2, - ["cannon-shell"] = 2, - ["explosive-cannon-shell"] = 2, - ["uranium-cannon-shell"] = 2, - ["explosive-uranium-cannon-shell"] = 2, - ["artillery-shell"] = 0.3, - ["cluster-grenade"] = 0.3, - ["defender-capsule"] = 2, - ["destroyer-capsule"] = 0.3, - ["distractor-capsule"] = 0.3 -} - -local scrap_raffle = {} -for _, t in pairs (mining_chance_weights) do - for x = 1, t.chance, 1 do - table.insert(scrap_raffle, t.name) - end +local max_spill = 60 +local math_random = math.random +local math_floor = math.floor + +local function create_particles(surface, name, position, amount, cause_position) + local direction_mod = (-100 + math_random(0,200)) * 0.0004 + local direction_mod_2 = (-100 + math_random(0,200)) * 0.0004 + + if cause_position then + direction_mod = (cause_position.x - position.x) * 0.025 + direction_mod_2 = (cause_position.y - position.y) * 0.025 + end + + for i = 1, amount, 1 do + local m = math_random(4, 10) + local m2 = m * 0.005 + + surface.create_particle({ + name = name, + position = position, + frame_speed = 1, + vertical_speed = 0.130, + height = 0, + movement = { + (m2 - (math_random(0, m) * 0.01)) + direction_mod, + (m2 - (math_random(0, m) * 0.01)) + direction_mod_2 + } + }) + end end -local size_of_scrap_raffle = #scrap_raffle +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}, + {name = "copper-cable", chance = 380}, + {name = "electronic-circuit", chance = 150}, + {name = "steel-plate", chance = 120}, + {name = "solid-fuel", chance = 89}, + {name = "pipe", chance = 75}, + {name = "iron-stick", chance = 50}, + {name = "battery", chance = 20}, + {name = "empty-barrel", chance = 10}, + {name = "crude-oil-barrel", chance = 10}, + {name = "lubricant-barrel", chance = 10}, + {name = "petroleum-gas-barrel", chance = 10}, + {name = "sulfuric-acid-barrel", chance = 10}, + {name = "heavy-oil-barrel", chance = 10}, + {name = "light-oil-barrel", chance = 10}, + {name = "water-barrel", chance = 10}, + {name = "green-wire", chance = 10}, + {name = "red-wire", chance = 10}, + {name = "explosives", chance = 5}, + {name = "advanced-circuit", chance = 5}, + {name = "nuclear-fuel", chance = 1}, + {name = "pipe-to-ground", chance = 10}, + {name = "plastic-bar", chance = 5}, + {name = "processing-unit", chance = 2}, + {name = "used-up-uranium-fuel-cell", chance = 1}, + {name = "uranium-fuel-cell", chance = 1}, + {name = "rocket-fuel", chance = 3}, + {name = "rocket-control-unit", chance = 1}, + {name = "low-density-structure", chance = 1}, + {name = "heat-pipe", chance = 1}, + {name = "engine-unit", chance = 4}, + {name = "electric-engine-unit", chance = 2}, + {name = "logistic-robot", chance = 1}, + {name = "construction-robot", chance = 1}, + {name = "land-mine", chance = 3}, + {name = "grenade", chance = 10}, + {name = "rocket", chance = 3}, + {name = "explosive-rocket", chance = 3}, + {name = "cannon-shell", chance = 2}, + {name = "explosive-cannon-shell", chance = 2}, + {name = "uranium-cannon-shell", chance = 1}, + {name = "explosive-uranium-cannon-shell", chance = 1}, + {name = "artillery-shell", chance = 1}, + {name = "cluster-grenade", chance = 2}, + {name = "defender-capsule", chance = 5}, + {name = "destroyer-capsule", chance = 1}, + {name = "distractor-capsule", chance = 2} + } + return data +end +local function mining_chances_ores() + local data = { + {name = "iron-ore", chance = 570}, + {name = "copper-ore", chance = 570}, + {name = "stone", chance = 550}, + {name = "coal", chance = 545}, + {name = "uranium-ore", chance = 1}, + } + return data +end + +local function scrap_yield_amounts() + local data = { + ["iron-ore"] = 10, + ["copper-ore"] = 10, + ["stone"] = 8, + ["coal"] = 6, + ["iron-plate"] = 4, + ["iron-gear-wheel"] = 6, + ["iron-stick"] = 6, + ["copper-plate"] = 4, + ["copper-cable"] = 6, + ["electronic-circuit"] = 2, + ["steel-plate"] = 2, + ["pipe"] = 5, + ["solid-fuel"] = 4, + ["empty-barrel"] = 3, + ["crude-oil-barrel"] = 3, + ["lubricant-barrel"] = 3, + ["petroleum-gas-barrel"] = 3, + ["sulfuric-acid-barrel"] = 3, + ["heavy-oil-barrel"] = 3, + ["light-oil-barrel"] = 3, + ["water-barrel"] = 3, + ["battery"] = 2, + ["explosives"] = 4, + ["advanced-circuit"] = 2, + ["nuclear-fuel"] = 0.1, + ["pipe-to-ground"] = 1, + ["plastic-bar"] = 4, + ["processing-unit"] = 1, + ["used-up-uranium-fuel-cell"] = 1, + ["uranium-fuel-cell"] = 0.3, + ["rocket-fuel"] = 0.3, + ["rocket-control-unit"] = 0.3, + ["low-density-structure"] = 0.3, + ["heat-pipe"] = 1, + ["green-wire"] = 8, + ["red-wire"] = 8, + ["engine-unit"] = 2, + ["electric-engine-unit"] = 2, + ["logistic-robot"] = 0.3, + ["construction-robot"] = 0.3, + ["land-mine"] = 1, + ["grenade"] = 2, + ["rocket"] = 2, + ["explosive-rocket"] = 2, + ["cannon-shell"] = 2, + ["explosive-cannon-shell"] = 2, + ["uranium-cannon-shell"] = 2, + ["explosive-uranium-cannon-shell"] = 2, + ["artillery-shell"] = 0.3, + ["cluster-grenade"] = 0.3, + ["defender-capsule"] = 2, + ["destroyer-capsule"] = 0.3, + ["distractor-capsule"] = 0.3, + ["uranium-ore"] = 1 + } + return data +end + +local scrap_raffle_scrap = {} +for _, t in pairs (mining_chances_scrap()) do + for x = 1, t.chance, 1 do + table.insert(scrap_raffle_scrap, t.name) + end +end + +local size_of_scrap_raffle = #scrap_raffle_scrap + +local scrap_raffle_ores = {} +for _, t in pairs (mining_chances_ores()) do + for x = 1, t.chance, 1 do + table.insert(scrap_raffle_ores, t.name) + end +end + +local size_of_ore_raffle = #scrap_raffle_ores + +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)] + --else + -- scrap = scrap_raffle_ores[math.random(1, size_of_ore_raffle)] + --end + + if this.scrap_enabled then + scrap = scrap_raffle_scrap[math.random(1, size_of_scrap_raffle)] + else + scrap = scrap_raffle_ores[math.random(1, size_of_ore_raffle)] + end + + 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))) + if not r1 or not r2 then return end + local amount = math.random(r1, r2) + + local position = {x = entity.position.x, y = entity.position.y} + + entity.destroy() + + local scrap_amount = math_floor(amount * 0.85) + 1 + + if scrap_amount > max_spill then + player.surface.spill_item_stack(position,{name = scrap, count = max_spill}, true) + scrap_amount = scrap_amount - max_spill + local inserted_count = player.insert({name = scrap, count = scrap_amount}) + scrap_amount = scrap_amount - inserted_count + if scrap_amount > 0 then + player.surface.spill_item_stack(position,{name = scrap, count = scrap_amount}, true) + end + else + player.surface.spill_item_stack(position,{name = scrap, count = scrap_amount}, true) + end + + player.surface.create_entity({ + name = "flying-text", + position = position, + text = "+" .. scrap_amount .. " [img=item/" .. scrap .. "]", + color = {r = 200, g = 160, b = 30} + }) + + create_particles(player.surface, "shell-particle", position, 64, {x = player.position.x, y = player.position.y}) +end local function on_player_mined_entity(event) local entity = event.entity if not entity.valid then return end if entity.name ~= "mineable-wreckage" then return end - - event.buffer.clear() - - local scrap = scrap_raffle[math.random(1, size_of_scrap_raffle)] - - 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 amount = math.random(r1, r2) - - local player = game.players[event.player_index] - local inserted_count = player.insert({name = scrap, count = amount}) - - if inserted_count ~= amount then - local amount_to_spill = amount - inserted_count - entity.surface.spill_item_stack(entity.position,{name = scrap, count = amount_to_spill}, true) + local player = game.players[event.player_index] + local this = Scrap_table.get_table() + if not player then + return end - - entity.surface.create_entity({ - name = "flying-text", - position = entity.position, - text = "+" .. amount .. " [img=item/" .. scrap .. "]", - color = {r=0.98, g=0.66, b=0.22} - }) + + event.buffer.clear() + + local data = { + this = this, + entity = entity, + player = player + } + + scrap_randomness(data) end local Event = require 'utils.event' diff --git a/maps/scrapyard/rpg.lua b/maps/scrapyard/rpg.lua index 28e1514a..3959a396 100644 --- a/maps/scrapyard/rpg.lua +++ b/maps/scrapyard/rpg.lua @@ -27,6 +27,8 @@ for a = 1, 9999, 1 do 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 rpg_t = {} local rpg_frame_icons = { @@ -223,15 +225,26 @@ local function draw_gui(player, forced) t.style.cell_padding = 1 add_gui_description(t, "LEVEL", 80) - add_gui_stat(t, rpg_t[player.index].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 - - add_gui_description(t, " ", 75) - add_gui_description(t, " ", 75) - + + 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 @@ -425,7 +438,7 @@ local function level_up(player) 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 + 5 + distribute_points_gain = distribute_points_gain + 3 else break end @@ -455,17 +468,31 @@ local function gain_xp(player, amount) rpg_t[player.index].last_floaty_text = game.tick + visuals_delay end -function Public.rpg_reset_player(player) +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() + 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, + 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, + rotated_entity_delay = 0, gui_refresh_delay = 0, last_mined_entity_position = {x = 0, y = 0}, + } end - 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, - rotated_entity_delay = 0, gui_refresh_delay = 0, last_mined_entity_position = {x = 0, y = 0}, - } draw_gui_char_button(player) draw_level_text(player) update_char_button(player) @@ -485,12 +512,12 @@ 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 - local player = game.players[event.player_index] if player.gui.left.rpg then player.gui.left.rpg.destroy() return @@ -498,18 +525,27 @@ local function on_gui_click(event) 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 - local player = game.players[event.player_index] 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, 5, 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) @@ -519,6 +555,9 @@ local function on_gui_click(event) 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) diff --git a/maps/scrapyard/table.lua b/maps/scrapyard/table.lua index 326f581e..08358ce1 100644 --- a/maps/scrapyard/table.lua +++ b/maps/scrapyard/table.lua @@ -27,6 +27,9 @@ function Public.reset_table() this.cargo_health = 10000 this.cargo_max_health = 10000 this.revealed_spawn = 0 + this.steps = {} + this.scrap_enabled = true + this.first_join = {} end function Public.get_table() diff --git a/maps/scrapyard/terrain.lua b/maps/scrapyard/terrain.lua index 91690313..d1a72137 100644 --- a/maps/scrapyard/terrain.lua +++ b/maps/scrapyard/terrain.lua @@ -22,7 +22,7 @@ local scrap_buildings = {"nuclear-reactor", "centrifuge", "beacon", "chemical-pl local spawner_raffle = {"biter-spawner", "biter-spawner", "biter-spawner", "spitter-spawner"} local trees = {"dead-grey-trunk", "dead-grey-trunk", "dry-tree"} local colors = {"black", "orange", "red", "yellow"} -local more_colors = {"acid", "brown", "green", "blue"} +local more_colors = {"black-refined-concrete", "brown-refined-concrete", "red-refined-concrete", "blue-refined-concrete"} local noises = { ["no_rocks"] = {{modifier = 0.0044, weight = 1}, {modifier = 0.01, weight = 0.22}, {modifier = 0.05, weight = 0.05}, {modifier = 0.1, weight = 0.04}}, @@ -130,7 +130,7 @@ local function wall(surface, left_top, seed) if math_random(1, 2) == 1 then Loot.add(surface, p, "wooden-chest") else - Loot.add(surface, p, "crash-site-chest-2") + Loot.add(surface, p, "steel-chest") end else @@ -667,8 +667,7 @@ function Public.reveal_area(x, y, surface, max_radius) end end for _, p in pairs(treasure) do - local name = "crash-site-chest-1" - if math_random(1, 6) == 1 then name = "crash-site-chest-2" end + 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) @@ -730,8 +729,7 @@ function Public.reveal(player) end end for _, p in pairs(treasure) do - local name = "crash-site-chest-1" - if math_random(1, 6) == 1 then name = "crash-site-chest-2" end + local name = "steel-chest" Loot.add(surface, p, name) end for _, fish in pairs(fishes) do @@ -749,25 +747,25 @@ local function generate_spawn_area(surface, position_left_top) for k, v in pairs(circles[r]) do local pos = {x = position_left_top.x + v.x, y = position_left_top.y+20 + v.y} if pos.x > -15 and pos.x < 15 and pos.y < 40 then - insert(tiles, {name = "black-refined-concrete", position = pos}) + insert(tiles, {name = more_colors[math_random(1, #more_colors)], position = pos}) end if pos.x > -30 and pos.x < 30 and pos.y < 40 then - insert(tiles, {name = "black-refined-concrete", position = pos}) + insert(tiles, {name = more_colors[math_random(1, #more_colors)], position = pos}) end if pos.x > -60 and pos.x < 60 and pos.y < 40 then - insert(tiles, {name = "black-refined-concrete", position = pos}) + insert(tiles, {name = more_colors[math_random(1, #more_colors)], position = pos}) end if pos.x > -90 and pos.x < 90 and pos.y < 40 then - insert(tiles, {name = "black-refined-concrete", position = pos}) + insert(tiles, {name = more_colors[math_random(1, #more_colors)], position = pos}) end if pos.x > -120 and pos.x < 120 and pos.y < 40 then - insert(tiles, {name = "black-refined-concrete", position = pos}) + insert(tiles, {name = more_colors[math_random(1, #more_colors)], position = pos}) end if pos.x > -150 and pos.x < 150 and pos.y < 40 then - insert(tiles, {name = "black-refined-concrete", position = pos}) + insert(tiles, {name = more_colors[math_random(1, #more_colors)], position = pos}) end if pos.x > -180 and pos.x < 180 and pos.y < 40 then - insert(tiles, {name = "black-refined-concrete", position = pos}) + insert(tiles, {name = more_colors[math_random(1, #more_colors)], position = pos}) end --if t_insert then -- insert(tiles, {name = t_insert, position = pos})