1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-24 03:47:58 +02:00

scrapyard fixes

This commit is contained in:
Gerkiz 2020-04-30 11:44:57 +02:00
parent 89f8461403
commit b4bc0254a9
10 changed files with 521 additions and 286 deletions

View File

@ -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_running_speed_modifier["scrapyard"] = 0.3 - fullness
player_modifiers[player.index].character_mining_speed_modifier["scrapyard"] = 0.3 - fullness player_modifiers[player.index].character_mining_speed_modifier["scrapyard"] = 0.3 - fullness
Modifier.update_player_modifiers(player) 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) 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) player.print("Maybe you should drop some of that inventory to lessen the burden.", Color.red)
end end
end end

View File

@ -369,7 +369,7 @@ local function spawn_comfylatron(surface, x, y)
this.comfylatron = surface.create_entity({ this.comfylatron = surface.create_entity({
name = "compilatron", name = "compilatron",
position = {x,y + math_random(0,26)}, position = {x,y + math_random(0,26)},
force = "player", force = "neutral",
create_build_effect_smoke = false create_build_effect_smoke = false
}) })
end end

View File

@ -8,10 +8,10 @@ Public.wagon_types = {
} }
Public.wagon_areas = { Public.wagon_areas = {
["cargo-wagon"] = {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 = -18, y = 0}, right_bottom = {x = 18, y = 70}}, ["artillery-wagon"] = {left_top = {x = -20, y = 0}, right_bottom = {x = 20, y = 80}},
["fluid-wagon"] = {left_top = {x = -18, y = 0}, right_bottom = {x = 18, y = 70}}, ["fluid-wagon"] = {left_top = {x = -20, y = 0}, right_bottom = {x = 20, y = 80}},
["locomotive"] = {left_top = {x = -18, y = 0}, right_bottom = {x = 18, y = 70}}, ["locomotive"] = {left_top = {x = -20, y = 0}, right_bottom = {x = 20, y = 80}},
} }
return Public return Public

View File

@ -503,16 +503,20 @@ end
function Public.reconstruct_all_trains(icw) function Public.reconstruct_all_trains(icw)
icw.trains = {} icw.trains = {}
for unit_number, wagon in pairs(icw.wagons) do for unit_number, wagon in pairs(icw.wagons) do
if wagon.entity and wagon.entity.valid then 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 local carriages = wagon.entity.train.carriages
Public.construct_train(icw, carriages) Public.construct_train(icw, carriages)
end end
end
delete_empty_surfaces(icw) delete_empty_surfaces(icw)
end end
function Public.item_transfer(icw) function Public.item_transfer(icw)
for _, wagon in pairs(icw.wagons) do for _, wagon in pairs(icw.wagons) do
if not wagon and not wagon.valid then return end
if wagon.transfer_entities then if wagon.transfer_entities then
for k, e in pairs(wagon.transfer_entities) do for k, e in pairs(wagon.transfer_entities) do
transfer_functions[e.name](wagon, e) transfer_functions[e.name](wagon, e)

View File

@ -71,9 +71,9 @@ function Public.contains_positions(pos, area)
return false return false
end end
function Public.power_source() local function rebuild_energy_overworld(data)
local this = Scrap_table.get_table() local this = data.this
local surface = game.surfaces[this.active_surface_index] local surface = data.surface
if not this.locomotive then return end if not this.locomotive then return end
if not this.locomotive.valid then return end if not this.locomotive.valid then return end
if not this.locomotive.surface then return end if not this.locomotive.surface then return end
@ -120,12 +120,23 @@ function Public.power_source()
end end
end end
function Public.on_teleported_player() local function rebuild_energy_loco(data, destroy)
local this = Scrap_table.get_table() local this = data.this
local icw_table = data.icw_table
local unit_surface = this.locomotive.unit_number local unit_surface = this.locomotive.unit_number
local loco_surface = game.surfaces[tostring(unit_surface)] local loco_surface = game.surfaces[icw_table.wagons[unit_surface].surface.index]
local pos = {x=-17, y=3} local pos = {x=-19, y=3}
if not this.lo_energy then
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{ this.lo_energy = loco_surface.create_entity{
name = "electric-energy-interface", name = "electric-energy-interface",
position = pos, position = pos,
@ -147,6 +158,34 @@ function Public.on_teleported_player()
this.lo_energy.operable = false this.lo_energy.operable = false
this.lo_energy.power_production = 0 this.lo_energy.power_production = 0
this.lo_energy.electric_buffer_size = 10000000 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
rebuild_energy_loco(data)
elseif not this.lo_energy.valid then
rebuild_energy_loco(data, true)
end end
end end
@ -169,29 +208,11 @@ local function fish_tag()
text = " " text = " "
}) })
end 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 function set_player_spawn_and_refill_fish()
local this = Scrap_table.get_table() local this = Scrap_table.get_table()
if not this.locomotive_cargo then return end if not this.locomotive_cargo then return end
if not this.locomotive_cargo.valid 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)}) 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) local position = this.locomotive_cargo.surface.find_non_colliding_position("stone-furnace", this.locomotive_cargo.position, 16, 2)
if not position then return end if not position then return end
@ -199,20 +220,16 @@ local function set_player_spawn_and_refill_fish()
end end
local function tick() local function tick()
Public.power_source() Public.power_source_overworld()
Public.power_source_locomotive()
if game.tick % 30 == 0 then if game.tick % 30 == 0 then
if game.tick % 1800 == 0 then if game.tick % 1800 == 0 then
set_player_spawn_and_refill_fish() set_player_spawn_and_refill_fish()
end end
fish_tag() fish_tag()
--accelerate()
--else
--remove_acceleration()
end end
end end
Event.on_nth_tick(5, tick) Event.on_nth_tick(5, tick)
Event.add(defines.events.on_player_driving_changed_state, Public.on_teleported_player)
return Public return Public

View File

@ -5,16 +5,14 @@ require "modules.shotgun_buff"
require "maps.scrapyard.burden" require "maps.scrapyard.burden"
require "modules.rocks_heal_over_time" require "modules.rocks_heal_over_time"
require "modules.no_deconstruction_of_neutral_entities" require "modules.no_deconstruction_of_neutral_entities"
require "maps.scrapyard.mineable_wreckage_yields_scrap"
require "maps.scrapyard.flamethrower_nerf" require "maps.scrapyard.flamethrower_nerf"
require "modules.rocks_yield_ore_veins" require "modules.rocks_yield_ore_veins"
require "modules.spawners_contain_biters" require "modules.spawners_contain_biters"
require "modules.biters_yield_coins" require "modules.biters_yield_coins"
require "modules.biter_noms_you" require "modules.biter_noms_you"
require "modules.explosives"
require "modules.wave_defense.main" require "modules.wave_defense.main"
require "maps.scrapyard.comfylatron" require "maps.scrapyard.comfylatron"
require "modules.rocks_broken_paint_tiles" require "modules.explosives"
local ICW = require "maps.scrapyard.icw.main" local ICW = require "maps.scrapyard.icw.main"
local WD = require "modules.wave_defense.table" 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 unearthing_biters = require "functions.unearthing_biters"
local Loot = require 'maps.scrapyard.loot' local Loot = require 'maps.scrapyard.loot'
local Pets = require "modules.biter_pets" local Pets = require "modules.biter_pets"
local Modifier = require "player_modifiers"
local tick_tack_trap = require "functions.tick_tack_trap" local tick_tack_trap = require "functions.tick_tack_trap"
local Terrain = require 'maps.scrapyard.terrain' local Terrain = require 'maps.scrapyard.terrain'
local Event = require 'utils.event' 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 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 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 = { local treasure_chest_messages = {
"You notice an old crate within the rubble. It's filled with treasure!", "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!", "You find a chest underneath the broken rocks. It's filled with goodies!",
@ -133,6 +131,9 @@ function Public.reset_map()
surface.ticks_per_day = surface.ticks_per_day * 2 surface.ticks_per_day = surface.ticks_per_day * 2
surface.min_brightness = 0.08 surface.min_brightness = 0.08
surface.daytime = 0.7 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_health = 10000
this.locomotive_max_health = 10000 this.locomotive_max_health = 10000
this.cargo_health = 10000 this.cargo_health = 10000
@ -264,14 +265,20 @@ end
local function set_difficulty() local function set_difficulty()
local wave_defense_table = WD.get_table() 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 --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 if wave_defense_table.wave_interval < 1800 then wave_defense_table.wave_interval = 1800 end
end end
local function protect_this(entity) local function is_protected(entity)
local this = Scrap_table.get_table() local this = Scrap_table.get_table()
if string.sub(entity.surface.name, 0, 9) ~= "scrapyard" then return true end if string.sub(entity.surface.name, 0, 9) ~= "scrapyard" then return true end
local protected = {this.locomotive, this.locomotive_cargo} local protected = {this.locomotive, this.locomotive_cargo}
@ -286,7 +293,7 @@ end
local function protect_train(event) local function protect_train(event)
local this = Scrap_table.get_table() local this = Scrap_table.get_table()
if event.entity.force.index ~= 1 then return end --Player Force 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.entity == this.locomotive_cargo or event.entity == this.locomotive then
if event.cause 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 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
end end
local function change_tile(surface,pos)
local colors = {"black", "orange", "red", "yellow", "acid", "brown", "green", "blue"} local function change_tile(surface, pos, steps)
surface.set_tiles{{name = colors[math_random(1, #colors)].. "-refined-concrete", position=pos}} return surface.set_tiles{{name = colors[math_floor(steps * 0.5) % 7 + 1], position=pos}}
end 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 function on_player_changed_position(event)
local this = Scrap_table.get_table() local this = Scrap_table.get_table()
local player = game.players[event.player_index] local player = game.players[event.player_index]
@ -315,16 +327,22 @@ local function on_player_changed_position(event)
if position.x >= 960 * 0.5 then return end if position.x >= 960 * 0.5 then return end
if position.x < 960 * -0.5 then return end if position.x < 960 * -0.5 then return end
if position.y < 5 then if position.y < 5 then
local shallow = surface.get_tile(position).name == "water-shallow" for x = -1,1 do
local deepwater = surface.get_tile(position).name == "deepwater-green" 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 if shallow or deepwater then goto continue end
change_tile(surface, position) change_tile(surface, _pos, steps)
this.steps[player.index] = this.steps[player.index] + 1
end
end
end end
::continue:: ::continue::
if position.y < 5 then Terrain.reveal(player) end if position.y < 5 then Terrain.reveal(player) end
if position.y >= 190 then if position.y >= 190 then
player.teleport({position.x, position.y - 1}, surface) 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 if player.character then
player.character.health = player.character.health - 5 player.character.health = player.character.health - 5
player.character.surface.create_entity({name = "water-splash", position = position}) player.character.surface.create_entity({name = "water-splash", position = position})
@ -333,30 +351,33 @@ local function on_player_changed_position(event)
end end
end end
local function on_player_left_game(event) local function on_player_left_game()
set_difficulty() set_difficulty()
end end
local function on_player_joined_game(event) local function on_player_joined_game(event)
local this = Scrap_table.get_table() local this = Scrap_table.get_table()
local player_modifiers = Modifier.get_table()
local surface = game.surfaces[this.active_surface_index] local surface = game.surfaces[this.active_surface_index]
local player = game.players[event.player_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) 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 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) 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 for item, amount in pairs(starting_items) do
player.insert({name = item, count = amount}) player.insert({name = item, count = amount})
end end
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 end
local function hidden_biter(entity) local function hidden_biter(entity)
@ -388,7 +409,7 @@ end
local function hidden_treasure(event) local function hidden_treasure(event)
if math.random(1, 320) ~= 1 then return end 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}) 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 end
local function biters_chew_rocks_faster(event) local function biters_chew_rocks_faster(event)
@ -582,6 +603,13 @@ local function on_built_entity(event)
end end
end end
local function on_research_finished(event)
event.research.force.character_inventory_slots_bonus = game.forces.player.mining_drill_productivity_bonus * 50 -- +5 Slots / level
local mining_speed_bonus = game.forces.player.mining_drill_productivity_bonus * 5 -- +50% speed / level
if event.research.force.technologies["steel-axe"].researched then mining_speed_bonus = mining_speed_bonus + 0.5 end -- +50% speed for steel-axe research
event.research.force.manual_mining_speed_modifier = mining_speed_bonus
end
local function on_robot_built_entity(event) local function on_robot_built_entity(event)
if string.sub(event.created_entity.surface.name, 0, 9) ~= "scrapyard" then return end if string.sub(event.created_entity.surface.name, 0, 9) ~= "scrapyard" then return end
local y = event.created_entity.position.y local y = event.created_entity.position.y
@ -605,15 +633,7 @@ local function on_robot_built_entity(event)
end end
end end
local function on_research_finished(event)
event.research.force.character_inventory_slots_bonus = game.forces.player.mining_drill_productivity_bonus * 50 -- +5 Slots / level
local mining_speed_bonus = game.forces.player.mining_drill_productivity_bonus * 5 -- +50% speed / level
if event.research.force.technologies["steel-axe"].researched then mining_speed_bonus = mining_speed_bonus + 0.5 end -- +50% speed for steel-axe research
event.research.force.manual_mining_speed_modifier = mining_speed_bonus
end
local on_init = function() local on_init = function()
local this = Scrap_table.get_table()
game.create_force("scrap") game.create_force("scrap")
game.create_force("scrap_defense") game.create_force("scrap_defense")
game.forces.player.set_friend('scrap', true) 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.main_caption_color = {r = 150, g = 150, b = 0}
T.sub_caption_color = {r = 0, 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 = { global.explosion_cells_destructible_tiles = {
["out-of-map"] = 1500, ["out-of-map"] = 1500,
["water"] = 1000, ["water"] = 1000,
@ -653,8 +679,56 @@ local on_init = function()
} }
end 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 on_tick = function()
local this = Scrap_table.get_table() 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 then
if this.game_reset_tick < game.tick then if this.game_reset_tick < game.tick then
this.game_reset_tick = nil this.game_reset_tick = nil
@ -665,7 +739,7 @@ local on_tick = function()
end end
if _DEBUG then if _DEBUG then
commands.add_command( commands.add_command(
'reset_game', 'reset_game',
'Debug only, reset the game!', 'Debug only, reset the game!',
function() function()
@ -684,7 +758,6 @@ end
Event.on_nth_tick(5, on_tick) Event.on_nth_tick(5, on_tick)
Event.on_init(on_init) 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_entity_damaged, on_entity_damaged)
Event.add(defines.events.on_player_joined_game, on_player_joined_game) 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_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_robot_built_entity, on_robot_built_entity)
Event.add(defines.events.on_built_entity, on_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_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 return Public

View File

@ -1,4 +1,38 @@
local mining_chance_weights = { local Scrap_table = require "maps.scrapyard.table"
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 function mining_chances_scrap()
local data = {
{name = "iron-ore", chance = 570}, {name = "iron-ore", chance = 570},
{name = "copper-ore", chance = 570}, {name = "copper-ore", chance = 570},
{name = "stone", chance = 550}, {name = "stone", chance = 550},
@ -39,7 +73,6 @@ local mining_chance_weights = {
{name = "electric-engine-unit", chance = 2}, {name = "electric-engine-unit", chance = 2},
{name = "logistic-robot", chance = 1}, {name = "logistic-robot", chance = 1},
{name = "construction-robot", chance = 1}, {name = "construction-robot", chance = 1},
{name = "land-mine", chance = 3}, {name = "land-mine", chance = 3},
{name = "grenade", chance = 10}, {name = "grenade", chance = 10},
{name = "rocket", chance = 3}, {name = "rocket", chance = 3},
@ -53,21 +86,34 @@ local mining_chance_weights = {
{name = "defender-capsule", chance = 5}, {name = "defender-capsule", chance = 5},
{name = "destroyer-capsule", chance = 1}, {name = "destroyer-capsule", chance = 1},
{name = "distractor-capsule", chance = 2} {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 scrap_yield_amounts = { local function scrap_yield_amounts()
["iron-ore"] = 8, local data = {
["copper-ore"] = 8, ["iron-ore"] = 10,
["stone"] = 4, ["copper-ore"] = 10,
["stone"] = 8,
["coal"] = 6, ["coal"] = 6,
["iron-plate"] = 16, ["iron-plate"] = 4,
["iron-gear-wheel"] = 8, ["iron-gear-wheel"] = 6,
["iron-stick"] = 16, ["iron-stick"] = 6,
["copper-plate"] = 16, ["copper-plate"] = 4,
["copper-cable"] = 24, ["copper-cable"] = 6,
["electronic-circuit"] = 8, ["electronic-circuit"] = 2,
["steel-plate"] = 4, ["steel-plate"] = 2,
["pipe"] = 8, ["pipe"] = 5,
["solid-fuel"] = 4, ["solid-fuel"] = 4,
["empty-barrel"] = 3, ["empty-barrel"] = 3,
["crude-oil-barrel"] = 3, ["crude-oil-barrel"] = 3,
@ -96,7 +142,6 @@ local scrap_yield_amounts = {
["electric-engine-unit"] = 2, ["electric-engine-unit"] = 2,
["logistic-robot"] = 0.3, ["logistic-robot"] = 0.3,
["construction-robot"] = 0.3, ["construction-robot"] = 0.3,
["land-mine"] = 1, ["land-mine"] = 1,
["grenade"] = 2, ["grenade"] = 2,
["rocket"] = 2, ["rocket"] = 2,
@ -109,46 +154,101 @@ local scrap_yield_amounts = {
["cluster-grenade"] = 0.3, ["cluster-grenade"] = 0.3,
["defender-capsule"] = 2, ["defender-capsule"] = 2,
["destroyer-capsule"] = 0.3, ["destroyer-capsule"] = 0.3,
["distractor-capsule"] = 0.3 ["distractor-capsule"] = 0.3,
} ["uranium-ore"] = 1
}
return data
end
local scrap_raffle = {} local scrap_raffle_scrap = {}
for _, t in pairs (mining_chance_weights) do for _, t in pairs (mining_chances_scrap()) do
for x = 1, t.chance, 1 do for x = 1, t.chance, 1 do
table.insert(scrap_raffle, t.name) table.insert(scrap_raffle_scrap, t.name)
end end
end end
local size_of_scrap_raffle = #scrap_raffle 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 function on_player_mined_entity(event)
local entity = event.entity local entity = event.entity
if not entity.valid then return end if not entity.valid then return end
if entity.name ~= "mineable-wreckage" then return end if entity.name ~= "mineable-wreckage" then return end
local player = game.players[event.player_index]
local this = Scrap_table.get_table()
if not player then
return
end
event.buffer.clear() event.buffer.clear()
local scrap = scrap_raffle[math.random(1, size_of_scrap_raffle)] local data = {
this = this,
entity = entity,
player = player
}
local amount_bonus = (game.forces.enemy.evolution_factor * 2) + (game.forces.player.mining_drill_productivity_bonus * 2) scrap_randomness(data)
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)
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}
})
end end
local Event = require 'utils.event' local Event = require 'utils.event'

View File

@ -27,6 +27,8 @@ for a = 1, 9999, 1 do
experience_levels[#experience_levels + 1] = experience_levels[#experience_levels] + a * 8 experience_levels[#experience_levels + 1] = experience_levels[#experience_levels] + a * 8
end end
local gain_info_tooltip = "XP gain from mining, moving, crafting, repairing and combat." 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_t = {}
local rpg_frame_icons = { local rpg_frame_icons = {
@ -223,14 +225,25 @@ local function draw_gui(player, forced)
t.style.cell_padding = 1 t.style.cell_padding = 1
add_gui_description(t, "LEVEL", 80) 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) add_gui_description(t, "EXPERIENCE", 100)
local e = add_gui_stat(t, math.floor(rpg_t[player.index].xp), 125) local e = add_gui_stat(t, math.floor(rpg_t[player.index].xp), 125)
e.tooltip = gain_info_tooltip e.tooltip = gain_info_tooltip
if not rpg_t[player.index].reset then
add_gui_description(t, "RESET", 80)
local e = add_gui_stat(t, rpg_t[player.index].reset, 80)
if rpg_t[player.index].level <= 19 then
e.tooltip = reset_not_available
else
e.tooltip = reset_tooltip
end
else
add_gui_description(t, " ", 75) add_gui_description(t, " ", 75)
add_gui_description(t, " ", 75) add_gui_description(t, " ", 75)
end
add_gui_description(t, "NEXT LEVEL", 100) add_gui_description(t, "NEXT LEVEL", 100)
local e = add_gui_stat(t, experience_levels[rpg_t[player.index].level + 1], 125) local e = add_gui_stat(t, experience_levels[rpg_t[player.index].level + 1], 125)
@ -425,7 +438,7 @@ local function level_up(player)
for i = rpg_t[player.index].level + 1, #experience_levels, 1 do for i = rpg_t[player.index].level + 1, #experience_levels, 1 do
if rpg_t[player.index].xp > experience_levels[i] then if rpg_t[player.index].xp > experience_levels[i] then
rpg_t[player.index].level = i rpg_t[player.index].level = i
distribute_points_gain = distribute_points_gain + 5 distribute_points_gain = distribute_points_gain + 3
else else
break break
end end
@ -455,17 +468,31 @@ local function gain_xp(player, amount)
rpg_t[player.index].last_floaty_text = game.tick + visuals_delay rpg_t[player.index].last_floaty_text = game.tick + visuals_delay
end 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 player.gui.left.rpg then player.gui.left.rpg.destroy() end
if not player.character then if not player.character then
player.set_controller({type=defines.controllers.god}) player.set_controller({type=defines.controllers.god})
player.create_character() player.create_character()
end 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] = { rpg_t[player.index] = {
level = 1, xp = 0, strength = 10, magic = 10, dexterity = 10, vitality = 10, points_to_distribute = 0, 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, 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}, 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
draw_gui_char_button(player) draw_gui_char_button(player)
draw_level_text(player) draw_level_text(player)
update_char_button(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 then return end
if not event.element.valid then return end if not event.element.valid then return end
local element = event.element local element = event.element
local player = game.players[event.player_index]
if element.type ~= "sprite-button" then return end if element.type ~= "sprite-button" then return end
if element.caption == "CHAR" then if element.caption == "CHAR" then
if element.name == "rpg" then if element.name == "rpg" then
local player = game.players[event.player_index]
if player.gui.left.rpg then if player.gui.left.rpg then
player.gui.left.rpg.destroy() player.gui.left.rpg.destroy()
return return
@ -499,17 +526,26 @@ local function on_gui_click(event)
end end
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.caption ~= "" then return end
if element.sprite ~= "virtual-signal/signal-red" then return end if element.sprite ~= "virtual-signal/signal-red" then return end
local index = element.name local index = element.name
local player = game.players[event.player_index]
if not rpg_t[player.index][index] then return end if not rpg_t[player.index][index] then return end
if not player.character then return end if not player.character then return end
if event.button == defines.mouse_button_type.right then if event.button == defines.mouse_button_type.right then
for a = 1, 5, 1 do for a = 1, 5, 1 do
if rpg_t[player.index].points_to_distribute <= 0 then draw_gui(player, true) return end if rpg_t[player.index].points_to_distribute <= 0 then draw_gui(player, true) return end
if not rpg_t[player.index].reset then
rpg_t[player.index].total = rpg_t[player.index].total + 1
end
rpg_t[player.index].points_to_distribute = rpg_t[player.index].points_to_distribute - 1 rpg_t[player.index].points_to_distribute = rpg_t[player.index].points_to_distribute - 1
rpg_t[player.index][index] = rpg_t[player.index][index] + 1 rpg_t[player.index][index] = rpg_t[player.index][index] + 1
update_player_stats(player) update_player_stats(player)
@ -519,6 +555,9 @@ local function on_gui_click(event)
end end
if rpg_t[player.index].points_to_distribute <= 0 then draw_gui(player, true) return end if rpg_t[player.index].points_to_distribute <= 0 then draw_gui(player, true) return end
if not rpg_t[player.index].reset then
rpg_t[player.index].total = rpg_t[player.index].total + 1
end
rpg_t[player.index].points_to_distribute = rpg_t[player.index].points_to_distribute - 1 rpg_t[player.index].points_to_distribute = rpg_t[player.index].points_to_distribute - 1
rpg_t[player.index][index] = rpg_t[player.index][index] + 1 rpg_t[player.index][index] = rpg_t[player.index][index] + 1
update_player_stats(player) update_player_stats(player)

View File

@ -27,6 +27,9 @@ function Public.reset_table()
this.cargo_health = 10000 this.cargo_health = 10000
this.cargo_max_health = 10000 this.cargo_max_health = 10000
this.revealed_spawn = 0 this.revealed_spawn = 0
this.steps = {}
this.scrap_enabled = true
this.first_join = {}
end end
function Public.get_table() function Public.get_table()

View File

@ -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 spawner_raffle = {"biter-spawner", "biter-spawner", "biter-spawner", "spitter-spawner"}
local trees = {"dead-grey-trunk", "dead-grey-trunk", "dry-tree"} local trees = {"dead-grey-trunk", "dead-grey-trunk", "dry-tree"}
local colors = {"black", "orange", "red", "yellow"} 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 = { 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}}, ["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 if math_random(1, 2) == 1 then
Loot.add(surface, p, "wooden-chest") Loot.add(surface, p, "wooden-chest")
else else
Loot.add(surface, p, "crash-site-chest-2") Loot.add(surface, p, "steel-chest")
end end
else else
@ -667,8 +667,7 @@ function Public.reveal_area(x, y, surface, max_radius)
end end
end end
for _, p in pairs(treasure) do for _, p in pairs(treasure) do
local name = "crash-site-chest-1" local name = "steel-chest"
if math_random(1, 6) == 1 then name = "crash-site-chest-2" end
Loot.add(surface, p, name) Loot.add(surface, p, name)
if math_random(1,wave_defense_table.math) == 1 then if math_random(1,wave_defense_table.math) == 1 then
local distance_to_center = math.sqrt(p.x^2 + p.y^2) local distance_to_center = math.sqrt(p.x^2 + p.y^2)
@ -730,8 +729,7 @@ function Public.reveal(player)
end end
end end
for _, p in pairs(treasure) do for _, p in pairs(treasure) do
local name = "crash-site-chest-1" local name = "steel-chest"
if math_random(1, 6) == 1 then name = "crash-site-chest-2" end
Loot.add(surface, p, name) Loot.add(surface, p, name)
end end
for _, fish in pairs(fishes) do 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 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} 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 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 end
if pos.x > -30 and pos.x < 30 and pos.y < 40 then 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 end
if pos.x > -60 and pos.x < 60 and pos.y < 40 then 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 end
if pos.x > -90 and pos.x < 90 and pos.y < 40 then 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 end
if pos.x > -120 and pos.x < 120 and pos.y < 40 then 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 end
if pos.x > -150 and pos.x < 150 and pos.y < 40 then 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 end
if pos.x > -180 and pos.x < 180 and pos.y < 40 then 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 end
--if t_insert then --if t_insert then
-- insert(tiles, {name = t_insert, position = pos}) -- insert(tiles, {name = t_insert, position = pos})