From 1d8cc950e3432873a7a479c0b0fdf7f33c3edee9 Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Fri, 24 Apr 2020 21:07:41 +0200 Subject: [PATCH] minor changes to chronosphere one table to rule them all --- maps/chronosphere/ai.lua | 83 ++++++++------- maps/chronosphere/chrono.lua | 74 +++++++------ maps/chronosphere/chronobubles.lua | 4 +- maps/chronosphere/comfylatron.lua | 116 +++++++++++--------- maps/chronosphere/config_tab.lua | 18 ++-- maps/chronosphere/event_functions.lua | 43 ++++---- maps/chronosphere/gui.lua | 26 +++-- maps/chronosphere/locomotive.lua | 102 +++++++++--------- maps/chronosphere/main.lua | 142 +++++++++++++------------ maps/chronosphere/ores.lua | 10 +- maps/chronosphere/table.lua | 64 +++++++++++ maps/chronosphere/terrain.lua | 51 +++++---- maps/chronosphere/terrain_specials.lua | 12 ++- maps/chronosphere/tick_functions.lua | 69 ++++++------ maps/chronosphere/treasure.lua | 4 +- maps/chronosphere/upgrade_list.lua | 71 +++++++------ maps/chronosphere/upgrades.lua | 82 +++++++------- 17 files changed, 558 insertions(+), 413 deletions(-) create mode 100644 maps/chronosphere/table.lua diff --git a/maps/chronosphere/ai.lua b/maps/chronosphere/ai.lua index 8a3264d9..278250b2 100644 --- a/maps/chronosphere/ai.lua +++ b/maps/chronosphere/ai.lua @@ -1,3 +1,4 @@ +local Chrono_table = require 'maps.chronosphere.table' local Public = {} local math_random = math.random @@ -25,20 +26,22 @@ local size_of_vectors = #attack_vectors local function get_active_biter_count() + local objective = Chrono_table.get_table() local count = 0 - for _, biter in pairs(global.objective.active_biters) do + for _, biter in pairs(objective.active_biters) do count = count + 1 end return count end local function set_biter_raffle_table(surface) + local objective = Chrono_table.get_table() -- It's fine to only sample the middle local area = {left_top = {-400, -400}, right_bottom = {400, 400}} local biters = surface.find_entities_filtered({type = "unit", force = "enemy", area = area}) if not biters[1] then return end - local raffle = global.objective.biter_raffle + local raffle = objective.biter_raffle local i = 1 for key, e in pairs(biters) do if key % 5 == 0 then @@ -73,8 +76,9 @@ local function is_biter_inactive(biter, unit_number) end local function set_active_biters(group) + local objective = Chrono_table.get_table() if not group.valid then return end - local active_biters = global.objective.active_biters + local active_biters = objective.active_biters for _, unit in pairs(group.members) do if not active_biters[unit.unit_number] then @@ -84,7 +88,7 @@ local function set_active_biters(group) end Public.destroy_inactive_biters = function() - local objective = global.objective + local objective = Chrono_table.get_table() if objective.chronotimer < 100 then return end for _, group in pairs(objective.unit_groups) do set_active_biters(group) @@ -178,37 +182,38 @@ local function colonize(unit_group) end Public.send_near_biters_to_objective = function() + local objective = Chrono_table.get_table() if game.tick < 36000 then return end - if not global.locomotive then return end - if not global.locomotive_cargo[1] then return end - if not global.locomotive_cargo[2] then return end - if not global.locomotive_cargo[3] then return end - local targets = {global.locomotive, global.locomotive, global.locomotive_cargo[1], global.locomotive_cargo[2], global.locomotive_cargo[3]} + if not objective.locomotive then return end + if not objective.locomotive_cargo[1] then return end + if not objective.locomotive_cargo[2] then return end + if not objective.locomotive_cargo[3] then return end + local targets = {objective.locomotive, objective.locomotive, objective.locomotive_cargo[1], objective.locomotive_cargo[2], objective.locomotive_cargo[3]} local random_target = targets[math_random(1, #targets)] - if global.objective.game_lost then return end + if objective.game_lost then return end local surface = random_target.surface local pollution = surface.get_pollution(random_target.position) local success = false - if pollution > 200 * (1 / global.difficulty_vote_value) or global.objective.planet[1].name.id == 17 then - surface.pollute(random_target.position, -50 * (1 / global.difficulty_vote_value)) + if pollution > 200 * (1 / objective.difficulty_vote_value) or objective.planet[1].name.id == 17 then + surface.pollute(random_target.position, -50 * (1 / objective.difficulty_vote_value)) --game.print("sending objective wave") success = true else - if global.objective.chronojumps < 50 then - if math_random(1, 50 - global.objective.chronojumps) == 1 then success = true end + if objective.chronojumps < 50 then + if math_random(1, 50 - objective.chronojumps) == 1 then success = true end --game.print("not enough pollution for objective attack") else success = true end end if success then - game.surfaces[global.active_surface_index].set_multi_command({ + game.surfaces[objective.active_surface_index].set_multi_command({ command={ type=defines.command.attack, target=random_target, distraction=defines.distraction.none }, - unit_count = 16 + math_random(1, math_floor(1 + game.forces["enemy"].evolution_factor * 100)) * global.difficulty_vote_value, + unit_count = 16 + math_random(1, math_floor(1 + game.forces["enemy"].evolution_factor * 100)) * objective.difficulty_vote_value, force = "enemy", unit_search_distance=128 }) @@ -234,10 +239,10 @@ local function select_units_around_spawner(spawner) local biters = spawner.surface.find_enemy_units(spawner.position, 160, "player") if not biters[1] then return false end local valid_biters = {} - local objective = global.objective + local objective = Chrono_table.get_table() local unit_count = 0 - local max_unit_count = 128 * global.difficulty_vote_value + local max_unit_count = 128 * objective.difficulty_vote_value for _, biter in pairs(biters) do if unit_count >= max_unit_count then break end @@ -266,14 +271,15 @@ local function select_units_around_spawner(spawner) end local function send_group(unit_group, nearest_player_unit) + local objective = Chrono_table.get_table() - local targets = {global.locomotive, global.locomotive, nearest_player_unit, nearest_player_unit, nearest_player_unit, global.locomotive_cargo[1], global.locomotive_cargo[2], global.locomotive_cargo[3]} + local targets = {objective.locomotive, objective.locomotive, nearest_player_unit, nearest_player_unit, nearest_player_unit, objective.locomotive_cargo[1], objective.locomotive_cargo[2], objective.locomotive_cargo[3]} local target = targets[math_random(1, #targets)] if not target.valid then colonize(unit_group) return end local surface = target.surface local pollution = surface.get_pollution(target.position) - if pollution > 200 * (1 / global.difficulty_vote_value) or global.objective.planet[1].name.id == 17 then - surface.pollute(target.position, -50 * (1 / global.difficulty_vote_value)) + if pollution > 200 * (1 / objective.difficulty_vote_value) or objective.planet[1].name.id == 17 then + surface.pollute(target.position, -50 * (1 / objective.difficulty_vote_value)) --game.print("sending unit group attack") local commands = {} @@ -352,6 +358,7 @@ local function get_unit_group_position(surface, nearest_player_unit, spawner) end local function create_attack_group(surface) + local objective = Chrono_table.get_table() if 256 - get_active_biter_count() < 256 then return false end @@ -360,26 +367,27 @@ local function create_attack_group(surface) return false end local nearest_player_unit = surface.find_nearest_enemy({position = spawner.position, max_distance = 1024, force = "enemy"}) - if not nearest_player_unit then nearest_player_unit = global.locomotive end + if not nearest_player_unit then nearest_player_unit = objective.locomotive end local unit_group_position = get_unit_group_position(surface, nearest_player_unit, spawner) local units = select_units_around_spawner(spawner) if not units then return false end local unit_group = surface.create_unit_group({position = unit_group_position, force = "enemy"}) for _, unit in pairs(units) do unit_group.add_member(unit) end send_group(unit_group, nearest_player_unit) - global.objective.unit_groups[unit_group.group_number] = unit_group + objective.unit_groups[unit_group.group_number] = unit_group end -- Public.rogue_group = function() --- if global.objective.chronotimer < 100 then return end --- if not global.locomotive then return end --- local surface = game.surfaces[global.active_surface_index] +-- local objective = Chrono_table.get_table() +-- if objective.chronotimer < 100 then return end +-- if not objective.locomotive then return end +-- local surface = game.surfaces[objective.active_surface_index] -- local spawner = get_random_close_spawner(surface) -- if not spawner then -- return false -- end --- local position = {x = ((spawner.position.x + global.locomotive.position.x) * 0.5) , y = ((spawner.position.y + global.locomotive.position.y) * 0.5)} +-- local position = {x = ((spawner.position.x + objective.locomotive.position.x) * 0.5) , y = ((spawner.position.y + objective.locomotive.position.y) * 0.5)} -- local pos = surface.find_non_colliding_position("rocket-silo", position, 30, 1, true) -- if not pos then return end -- surface.set_multi_command({ @@ -396,22 +404,25 @@ end -- end Public.pre_main_attack = function() - if global.objective.chronotimer < 100 then return end - local surface = game.surfaces[global.active_surface_index] + local objective = Chrono_table.get_table() + if objective.chronotimer < 100 then return end + local surface = game.surfaces[objective.active_surface_index] set_biter_raffle_table(surface) end Public.perform_main_attack = function() - if global.objective.chronotimer < 100 then return end - local surface = game.surfaces[global.active_surface_index] - create_attack_group(surface) + local objective = Chrono_table.get_table() + if objective.chronotimer < 100 then return end + local surface = game.surfaces[objective.active_surface_index] + create_attack_group(surface) end Public.wake_up_sleepy_groups = function() - if global.objective.chronotimer < 100 then return end + local objective = Chrono_table.get_table() + if objective.chronotimer < 100 then return end local entity local unit_group - for unit_number, biter in pairs(global.objective.active_biters) do + for unit_number, biter in pairs(objective.active_biters) do entity = biter.entity if entity then if entity.valid then @@ -420,7 +431,7 @@ Public.wake_up_sleepy_groups = function() if unit_group.valid then if unit_group.state == defines.group_state.finished then local nearest_player_unit = entity.surface.find_nearest_enemy({position = entity.position, max_distance = 2048, force = "enemy"}) - if not nearest_player_unit then nearest_player_unit = global.locomotive end + if not nearest_player_unit then nearest_player_unit = objective.locomotive end local destination = unit_group.surface.find_non_colliding_position("rocket-silo", unit_group.position, 32, 1) if not destination then destination = {x = unit_group.position.x + math_random(-10,10), y = unit_group.position.y + math_random(-10,10)} end unit_group.set_command({ @@ -439,7 +450,7 @@ Public.wake_up_sleepy_groups = function() distraction = defines.distraction.by_enemy }) -- local nearest_player_unit = entity.surface.find_nearest_enemy({position = entity.position, max_distance = 2048, force = "enemy"}) - -- if not nearest_player_unit then nearest_player_unit = global.locomotive end + -- if not nearest_player_unit then nearest_player_unit = objective.locomotive end -- send_group(unit_group, nearest_player_unit) return end diff --git a/maps/chronosphere/chrono.lua b/maps/chronosphere/chrono.lua index 8e8421d9..ee5c9fcd 100644 --- a/maps/chronosphere/chrono.lua +++ b/maps/chronosphere/chrono.lua @@ -1,3 +1,4 @@ +local Chrono_table = require 'maps.chronosphere.table' local Public_chrono = {} local Server = require 'utils.server' @@ -24,8 +25,8 @@ function Public_chrono.get_map_gen_settings() end function Public_chrono.restart_settings() - local objective = global.objective - objective.max_health = 10000 + local objective = Chrono_table.get_table() + objective.max_health = 10000 objective.health = 10000 objective.poisontimeout = 0 objective.chronotimer = 0 @@ -40,27 +41,27 @@ function Public_chrono.restart_settings() objective.dangers = {} objective.looted_nukes = 0 objective.offline_players = {} - objective.nextsurface = nil + objective.nextsurface = nil for i = 1, 16, 1 do objective.upgrades[i] = 0 end objective.upgrades[10] = 2 --poison - global.outchests = {} - global.upgradechest = {} - global.fishchest = {} - global.acumulators = {} - global.comfychests = {} - global.comfychests2 = {} - global.locomotive_cargo = {} + objective.outchests = {} + objective.upgradechest = {} + objective.fishchest = {} + objective.acumulators = {} + objective.comfychests = {} + objective.comfychests2 = {} + objective.locomotive_cargo = {} for _, player in pairs(game.connected_players) do - global.flame_boots[player.index] = {fuel = 1, steps = {}} + objective.flame_boots[player.index] = {fuel = 1, steps = {}} end global.friendly_fire_history = {} global.landfill_history = {} global.mining_history = {} global.score = {} - global.difficulty_poll_closing_timeout = game.tick + 90000 - global.difficulty_player_votes = {} + global.difficulty_poll_closing_timeout = game.tick + 90000 + global.difficulty_player_votes = {} game.difficulty_settings.technology_price_multiplier = 0.6 game.map_settings.enemy_evolution.destroy_factor = 0.005 @@ -92,8 +93,6 @@ function Public_chrono.restart_settings() game.forces.player.technologies["power-armor-mk2"].enabled = false game.forces.player.technologies["railway"].researched = true game.forces.player.recipes["pistol"].enabled = false - - global.objective = objective end function Public_chrono.init_setup() @@ -101,34 +100,34 @@ function Public_chrono.init_setup() end function Public_chrono.objective_died() - local objective = global.objective + local objective = Chrono_table.get_table() if objective.game_lost == true then return end objective.health = 0 local surface = objective.surface game.print({"chronosphere.message_game_lost1"}) game.print({"chronosphere.message_game_lost2"}) for i = 1, 3, 1 do - surface.create_entity({name = "big-artillery-explosion", position = global.locomotive_cargo[i].position}) - global.locomotive_cargo[i].destroy() + surface.create_entity({name = "big-artillery-explosion", position = objective.locomotive_cargo[i].position}) + objective.locomotive_cargo[i].destroy() end - for i = 1, #global.comfychests,1 do - --surface.create_entity({name = "big-artillery-explosion", position = global.comfychests[i].position}) - global.comfychests[i].destroy() + for i = 1, #objective.comfychests,1 do + --surface.create_entity({name = "big-artillery-explosion", position = objective.comfychests[i].position}) + objective.comfychests[i].destroy() - if global.comfychests2 then global.comfychests2[i].destroy() end + if objective.comfychests2 then objective.comfychests2[i].destroy() end - --global.comfychests = {} + --objective.comfychests = {} end - global.acumulators = {} + objective.acumulators = {} objective.game_lost = true - global.game_reset_tick = game.tick + 1800 + objective.game_reset_tick = game.tick + 1800 for _, player in pairs(game.connected_players) do player.play_sound{path="utility/game_lost", volume_modifier=0.75} end end local function overstayed() - local objective = global.objective + local objective = Chrono_table.get_table() if objective.passivetimer > objective.chrononeeds * 0.75 and objective.chronojumps > 5 then objective.passivejumps = objective.passivejumps + 1 return true @@ -137,7 +136,7 @@ local function overstayed() end local function check_nuke_silos() - local objective = global.objective + local objective = Chrono_table.get_table() if objective.dangers and #objective.dangers > 1 then for i = 1, #objective.dangers, 1 do if objective.dangers[i].destroyed == true then @@ -148,7 +147,7 @@ local function check_nuke_silos() end function Public_chrono.process_jump(choice) - local objective = global.objective + local objective = Chrono_table.get_table() local overstayed = overstayed() objective.chronojumps = objective.chronojumps + 1 objective.chrononeeds = 2000 + 300 * objective.chronojumps @@ -180,10 +179,10 @@ function Public_chrono.process_jump(choice) if objective.planet[1].name.id == 19 then check_nuke_silos() end - global.objective = objective end function Public_chrono.get_wagons(start) + local objective = Chrono_table.get_table() local wagons = {} wagons[1] = {inventory = {}, bar = 0, filters = {}} wagons[2] = {inventory = {}, bar = 0, filters = {}} @@ -198,9 +197,9 @@ function Public_chrono.get_wagons(start) end else local inventories = { - one = global.locomotive_cargo[1].get_inventory(defines.inventory.cargo_wagon), - two = global.locomotive_cargo[2].get_inventory(defines.inventory.cargo_wagon), - three = global.locomotive_cargo[3].get_inventory(defines.inventory.cargo_wagon) + one = objective.locomotive_cargo[1].get_inventory(defines.inventory.cargo_wagon), + two = objective.locomotive_cargo[2].get_inventory(defines.inventory.cargo_wagon), + three = objective.locomotive_cargo[3].get_inventory(defines.inventory.cargo_wagon) } inventories.one.sort_and_merge() --inventories.two.sort_and_merge() @@ -221,7 +220,7 @@ function Public_chrono.get_wagons(start) end function Public_chrono.post_jump() - local objective = global.objective + local objective = Chrono_table.get_table() game.forces.enemy.reset_evolution() if objective.chronojumps + objective.passivejumps <= 40 and objective.planet[1].name.id ~= 17 then game.forces.enemy.evolution_factor = 0 + 0.025 * (objective.chronojumps + objective.passivejumps) @@ -229,9 +228,9 @@ function Public_chrono.post_jump() game.forces.enemy.evolution_factor = 1 end if objective.planet[1].name.id == 17 then - global.comfychests[1].insert({name = "space-science-pack", count = 1000}) + objective.comfychests[1].insert({name = "space-science-pack", count = 1000}) if objective.looted_nukes > 0 then - global.comfychests[1].insert({name = "atomic-bomb", count = objective.looted_nukes}) + objective.comfychests[1].insert({name = "atomic-bomb", count = objective.looted_nukes}) game.print({"chronosphere.message_fishmarket3"}, {r=0.98, g=0.66, b=0.22}) end objective.chrononeeds = 200000000 @@ -239,7 +238,7 @@ function Public_chrono.post_jump() objective.chronotimer = objective.chrononeeds - 1500 end for _, player in pairs(game.connected_players) do - global.flame_boots[player.index] = {fuel = 1, steps = {}} + objective.flame_boots[player.index] = {fuel = 1, steps = {}} end game.map_settings.enemy_evolution.time_factor = 7e-05 + 3e-06 * (objective.chronojumps + objective.passivejumps) @@ -249,12 +248,11 @@ function Public_chrono.post_jump() game.forces.enemy.set_ammo_damage_modifier("biological", 0.1 * objective.passivejumps) game.map_settings.pollution.enemy_attack_pollution_consumption_modifier = 0.8 if objective.chronojumps == 1 then - if global.difficulty_vote_value < 1 then + if objective.difficulty_vote_value < 1 then game.forces.player.technologies["fusion-reactor-equipment"].enabled = true game.forces.player.technologies["power-armor-mk2"].enabled = true end end - global.objective = objective end return Public_chrono diff --git a/maps/chronosphere/chronobubles.lua b/maps/chronosphere/chronobubles.lua index 9281f111..4f4d1d6c 100644 --- a/maps/chronosphere/chronobubles.lua +++ b/maps/chronosphere/chronobubles.lua @@ -1,3 +1,5 @@ +local Chrono_table = require 'maps.chronosphere.table' + local Public = {} local math_random = math.random --cumul_chance must be sum of this and all previous chances, add new planets at the end only, or recalculate @@ -60,7 +62,7 @@ local function roll(weight) end function Public.determine_planet(choice) - local objective = global.objective + local objective = Chrono_table.get_table() local weight = variants[#variants].cumul_chance local planet_choice = nil local ores = math_random(1, 9) diff --git a/maps/chronosphere/comfylatron.lua b/maps/chronosphere/comfylatron.lua index 774b9135..a251f3d8 100644 --- a/maps/chronosphere/comfylatron.lua +++ b/maps/chronosphere/comfylatron.lua @@ -1,3 +1,4 @@ +local Chrono_table = require 'maps.chronosphere.table' local event = require 'utils.event' local math_random = math.random @@ -111,36 +112,40 @@ local texts = { } local function set_comfy_speech_bubble(text) - if global.comfybubble then global.comfybubble.destroy() end - global.comfybubble = global.comfylatron.surface.create_entity({ + local objective = Chrono_table.get_table() + if objective.comfybubble then objective.comfybubble.destroy() end + objective.comfybubble = objective.comfylatron.surface.create_entity({ name = "compi-speech-bubble", - position = global.comfylatron.position, - source = global.comfylatron, + position = objective.comfylatron.position, + source = objective.comfylatron, text = text }) end local function is_target_inside_habitat(pos, surface) + local objective = Chrono_table.get_table() if surface.name ~= "cargo_wagon" then return false end - if pos.x < global.comfylatron_habitat.left_top.x then return false end - if pos.x > global.comfylatron_habitat.right_bottom.x then return false end - if pos.y < global.comfylatron_habitat.left_top.y then return false end - if pos.y > global.comfylatron_habitat.right_bottom.y then return false end + if pos.x < objective.comfylatron_habitat.left_top.x then return false end + if pos.x > objective.comfylatron_habitat.right_bottom.x then return false end + if pos.y < objective.comfylatron_habitat.left_top.y then return false end + if pos.y > objective.comfylatron_habitat.right_bottom.y then return false end return true end local function get_nearby_players() - local players = global.comfylatron.surface.find_entities_filtered({ + local objective = Chrono_table.get_table() + local players = objective.comfylatron.surface.find_entities_filtered({ name = "character", - area = {{global.comfylatron.position.x - 9, global.comfylatron.position.y - 9}, {global.comfylatron.position.x + 9, global.comfylatron.position.y + 9}} + area = {{objective.comfylatron.position.x - 9, objective.comfylatron.position.y - 9}, {objective.comfylatron.position.x + 9, objective.comfylatron.position.y + 9}} }) if not players[1] then return false end return players end local function visit_player() - if global.comfylatron_last_player_visit > game.tick then return false end - global.comfylatron_last_player_visit = game.tick + math_random(7200, 10800) + local objective = Chrono_table.get_table() + if objective.comfylatron_last_player_visit > game.tick then return false end + objective.comfylatron_last_player_visit = game.tick + math_random(7200, 10800) local players = {} for _, p in pairs(game.connected_players) do @@ -151,7 +156,7 @@ local function visit_player() if #players == 0 then return false end local player = players[math_random(1, #players)] - global.comfylatron.set_command({ + objective.comfylatron.set_command({ type = defines.command.go_to_location, destination_entity = player.character, radius = 3, @@ -167,22 +172,23 @@ local function visit_player() str = str .. symbols[math_random(1, #symbols)] set_comfy_speech_bubble(str) - global.comfylatron_greet_player_index = player.index + objective.comfylatron_greet_player_index = player.index return true end local function greet_player(nearby_characters) + local objective = Chrono_table.get_table() if not nearby_characters then return false end - if not global.comfylatron_greet_player_index then return false end + if not objective.comfylatron_greet_player_index then return false end for _, c in pairs(nearby_characters) do - if c.player.index == global.comfylatron_greet_player_index then + if c.player.index == objective.comfylatron_greet_player_index then local str = texts["greetings"][math_random(1, #texts["greetings"])] .. " " str = str .. c.player.name local symbols = {". ", "! ", ". ", "! ", "? ", "... "} str = str .. symbols[math_random(1, 6)] set_comfy_speech_bubble(str) - global.comfylatron_greet_player_index = false + objective.comfylatron_greet_player_index = false return true end end @@ -190,9 +196,10 @@ local function greet_player(nearby_characters) end local function talks(nearby_characters) + local objective = Chrono_table.get_table() if not nearby_characters then return false end if math_random(1,3) == 1 then - if global.comfybubble then global.comfybubble.destroy() return false end + if objective.comfybubble then objective.comfybubble.destroy() return false end end local str if #nearby_characters == 1 then @@ -215,13 +222,14 @@ local function talks(nearby_characters) end local function desync(event) - if global.comfybubble then global.comfybubble.destroy() end + local objective = Chrono_table.get_table() + if objective.comfybubble then objective.comfybubble.destroy() end local m = 12 local m2 = m * 0.005 for i = 1, 32, 1 do - global.comfylatron.surface.create_particle({ + objective.comfylatron.surface.create_particle({ name = "iron-ore-particle", - position = global.comfylatron.position, + position = objective.comfylatron.position, frame_speed = 0.1, vertical_speed = 0.1, height = 0.1, @@ -229,24 +237,25 @@ local function desync(event) }) end if not event or math_random(1,4) == 1 then - global.comfylatron.surface.create_entity({name = "medium-explosion", position = global.comfylatron.position}) - global.comfylatron.surface.create_entity({name = "flying-text", position = global.comfylatron.position, text = "desync", color = {r = 150, g = 0, b = 0}}) - global.comfylatron.destroy() - global.comfylatron = nil + objective.comfylatron.surface.create_entity({name = "medium-explosion", position = objective.comfylatron.position}) + objective.comfylatron.surface.create_entity({name = "flying-text", position = objective.comfylatron.position, text = "desync", color = {r = 150, g = 0, b = 0}}) + objective.comfylatron.destroy() + objective.comfylatron = nil else - global.comfylatron.surface.create_entity({name = "flying-text", position = global.comfylatron.position, text = "desync evaded", color = {r = 0, g = 150, b = 0}}) + objective.comfylatron.surface.create_entity({name = "flying-text", position = objective.comfylatron.position, text = "desync evaded", color = {r = 0, g = 150, b = 0}}) if event.cause then if event.cause.valid and event.cause.player then game.print("Comfylatron: I got you this time! Back to work, " .. event.cause.player.name .. "!", {r = 200, g = 0, b = 0}) - event.cause.die("player", global.comfylatron) + event.cause.die("player", objective.comfylatron) end end end end local function alone() + local objective = Chrono_table.get_table() if math_random(1,3) == 1 then - if global.comfybubble then global.comfybubble.destroy() return true end + if objective.comfybubble then objective.comfybubble.destroy() return true end end if math_random(1,128) == 1 then desync(nil) @@ -267,10 +276,11 @@ local analyze_blacklist = { } local function analyze_random_nearby_entity() + local objective = Chrono_table.get_table() if math_random(1,3) ~= 1 then return false end - local entities = global.comfylatron.surface.find_entities_filtered({ - area = {{global.comfylatron.position.x - 4, global.comfylatron.position.y - 4}, {global.comfylatron.position.x + 4, global.comfylatron.position.y + 4}} + local entities = objective.comfylatron.surface.find_entities_filtered({ + area = {{objective.comfylatron.position.x - 4, objective.comfylatron.position.y - 4}, {objective.comfylatron.position.x + 4, objective.comfylatron.position.y + 4}} }) if not entities[1] then return false end entities = shuffle(entities) @@ -298,8 +308,8 @@ local function analyze_random_nearby_entity() end set_comfy_speech_bubble(str) - if not global.comfylatron_greet_player_index then - global.comfylatron.set_command({ + if not objective.comfylatron_greet_player_index then + objective.comfylatron.set_command({ type = defines.command.go_to_location, destination_entity = entity, radius = 1, @@ -315,23 +325,24 @@ local function analyze_random_nearby_entity() end local function go_to_some_location() + local objective = Chrono_table.get_table() if math_random(1,4) ~= 1 then return false end - if global.comfylatron_greet_player_index then - local player = game.players[global.comfylatron_greet_player_index] + if objective.comfylatron_greet_player_index then + local player = game.players[objective.comfylatron_greet_player_index] if not player.character then - global.comfylatron_greet_player_index = nil + objective.comfylatron_greet_player_index = nil return false end if not player.character.valid then - global.comfylatron_greet_player_index = nil + objective.comfylatron_greet_player_index = nil return false end if not is_target_inside_habitat(player.position, player.surface) then - global.comfylatron_greet_player_index = nil + objective.comfylatron_greet_player_index = nil return false end - global.comfylatron.set_command({ + objective.comfylatron.set_command({ type = defines.command.go_to_location, destination_entity = player.character, radius = 3, @@ -343,11 +354,11 @@ local function go_to_some_location() } }) else - local p = {x = global.comfylatron.position.x + (-96 + math_random(0, 192)), y = global.comfylatron.position.y + (-96 + math_random(0, 192))} - local target = global.comfylatron.surface.find_non_colliding_position("compilatron", p, 8, 1) + local p = {x = objective.comfylatron.position.x + (-96 + math_random(0, 192)), y = objective.comfylatron.position.y + (-96 + math_random(0, 192))} + local target = objective.comfylatron.surface.find_non_colliding_position("compilatron", p, 8, 1) if not target then return false end - if not is_target_inside_habitat(target, global.comfylatron.surface) then return false end - global.comfylatron.set_command({ + if not is_target_inside_habitat(target, objective.comfylatron.surface) then return false end + objective.comfylatron.set_command({ type = defines.command.go_to_location, destination = target, radius = 2, @@ -369,17 +380,18 @@ local function go_to_some_location() end local function spawn_comfylatron(surface_index, x, y) + local objective = Chrono_table.get_table() local surface = game.surfaces[surface_index] if surface == nil then return end - if global.comfylatron_disabled then return false end - if not global.comfylatron_last_player_visit then global.comfylatron_last_player_visit = 0 end - if not global.comfylatron_habitat then - global.comfylatron_habitat = { + if objective.comfylatron_disabled then return false end + if not objective.comfylatron_last_player_visit then objective.comfylatron_last_player_visit = 0 end + if not objective.comfylatron_habitat then + objective.comfylatron_habitat = { left_top = {x = -32, y = -192}, right_bottom = {x = 32, y = 192} } end - global.comfylatron = surface.create_entity({ + objective.comfylatron = surface.create_entity({ name = "compilatron", position = {x,y + math_random(0,256)}, force = "player", @@ -388,11 +400,12 @@ local function spawn_comfylatron(surface_index, x, y) end local function heartbeat() + local objective = Chrono_table.get_table() if not game.surfaces["cargo_wagon"] then return end local surface = game.surfaces["cargo_wagon"].index if surface == nil then return end - if not global.comfylatron then if math_random(1,4) == 1 then spawn_comfylatron(game.surfaces["cargo_wagon"].index, 0, -128) end return end - if not global.comfylatron.valid then global.comfylatron = nil return end + if not objective.comfylatron then if math_random(1,4) == 1 then spawn_comfylatron(game.surfaces["cargo_wagon"].index, 0, -128) end return end + if not objective.comfylatron.valid then objective.comfylatron = nil return end if visit_player() then return end local nearby_players = get_nearby_players() if greet_player(nearby_players) then return end @@ -403,9 +416,10 @@ local function heartbeat() end local function on_entity_damaged(event) - if not global.comfylatron then return end + local objective = Chrono_table.get_table() + if not objective.comfylatron then return end if not event.entity.valid then return end - if event.entity ~= global.comfylatron then return end + if event.entity ~= objective.comfylatron then return end desync(event) end diff --git a/maps/chronosphere/config_tab.lua b/maps/chronosphere/config_tab.lua index 256d19ad..df551116 100644 --- a/maps/chronosphere/config_tab.lua +++ b/maps/chronosphere/config_tab.lua @@ -1,14 +1,16 @@ -- config tab for chronotrain-- local Tabs = require 'comfy_panel.main' +local Chrono_table = require 'maps.chronosphere.table' local functions = { ["comfy_panel_offline_accidents"] = function(event) + local objective = Chrono_table.get_table() if game.players[event.player_index].admin then if event.element.switch_state == "left" then - global.objective.config.offline_loot = true + objective.config.offline_loot = true else - global.objective.config.offline_loot = false + objective.config.offline_loot = false end else game.players[event.player_index].print("You are not admin!") @@ -16,11 +18,12 @@ local functions = { end, ["comfy_panel_danger_events"] = function(event) + local objective = Chrono_table.get_table() if game.players[event.player_index].admin then if event.element.switch_state == "left" then - global.objective.config.jumpfailure = true + objective.config.jumpfailure = true else - global.objective.config.jumpfailure = false + objective.config.jumpfailure = false end else game.players[event.player_index].print("You are not admin!") @@ -58,6 +61,7 @@ local function add_switch(element, switch_state, name, description_main, descrip end local build_config_gui = (function (player, frame) + local objective = Chrono_table.get_table() frame.clear() local line_elements = {} @@ -67,14 +71,14 @@ local build_config_gui = (function (player, frame) line_elements[#line_elements + 1] = frame.add({type = "line"}) local switch_state = "right" - if global.objective.config.offline_loot then switch_state = "left" end + if objective.config.offline_loot then switch_state = "left" end add_switch(frame, switch_state, "comfy_panel_offline_accidents", "Offline Accidents", "Disablesr enables dropping of inventory when player goes offline.\nTimer is 15 minutes.") line_elements[#line_elements + 1] = frame.add({type = "line"}) - if global.auto_hotbar_enabled then + if objective.auto_hotbar_enabled then local switch_state = "right" - if global.objective.config.jumpfailure then switch_state = "left" end + if objective.config.jumpfailure then switch_state = "left" end add_switch(frame, switch_state, "comfy_panel_danger_events", "Dangerous Events", "Disables or enables dangerous event maps\n(they require at least 2-4 capable players to survive)") line_elements[#line_elements + 1] = frame.add({type = "line"}) end diff --git a/maps/chronosphere/event_functions.lua b/maps/chronosphere/event_functions.lua index 79e22a66..738609c8 100644 --- a/maps/chronosphere/event_functions.lua +++ b/maps/chronosphere/event_functions.lua @@ -1,3 +1,4 @@ +local Chrono_table = require 'maps.chronosphere.table' local Public_event = {} local tick_tack_trap = require "functions.tick_tack_trap" @@ -8,8 +9,9 @@ local math_random = math.random local math_floor = math.floor local function get_ore_amount() - local scaling = 5 * global.objective.chronojumps - local amount = (30 + scaling ) * (1 + game.forces.player.mining_drill_productivity_bonus / 2) * global.objective.planet[1].ore_richness.factor + local objective = Chrono_table.get_table() + local scaling = 5 * objective.chronojumps + local amount = (30 + scaling ) * (1 + game.forces.player.mining_drill_productivity_bonus / 2) * objective.planet[1].ore_richness.factor if amount > 600 then amount = 600 end amount = math_random(math_floor(amount * 0.7), math_floor(amount * 1.3)) return amount @@ -42,10 +44,11 @@ function Public_event.biters_chew_rocks_faster(event) end function Public_event.isprotected(entity) + local objective = Chrono_table.get_table() if entity.surface.name == "cargo_wagon" then return true end - local protected = {global.locomotive, global.locomotive_cargo[1], global.locomotive_cargo[2], global.locomotive_cargo[3]} - for i = 1, #global.comfychests,1 do - table.insert(protected, global.comfychests[i]) + local protected = {objective.locomotive, objective.locomotive_cargo[1], objective.locomotive_cargo[2], objective.locomotive_cargo[3]} + for i = 1, #objective.comfychests,1 do + table.insert(protected, objective.comfychests[i]) end for i = 1, #protected do if protected[i] == entity then @@ -67,6 +70,7 @@ function Public_event.trap(entity, trap) end function Public_event.lava_planet(event) + local objective = Chrono_table.get_table() local player = game.players[event.player_index] if not player.character then return end if player.character.driving then return end @@ -76,8 +80,8 @@ function Public_event.lava_planet(event) for i = 1, 7, 1 do if pavement.name == safe[i] then return end end - if not global.flame_boots[player.index].steps then global.flame_boots[player.index].steps = {} end - local steps = global.flame_boots[player.index].steps + if not objective.flame_boots[player.index].steps then objective.flame_boots[player.index].steps = {} end + local steps = objective.flame_boots[player.index].steps local elements = #steps @@ -106,7 +110,7 @@ function Public_event.shred_simple_entities(entity) end function Public_event.spawner_loot(surface, position) - local objective = global.objective + local objective = Chrono_table.get_table() if math_random(1,20) == 1 then surface.spill_item_stack(position, {name = "railgun-dart", count = math_random(1, 1 + objective.chronojumps)}, true) end @@ -147,7 +151,8 @@ function Public_event.choppy_loot(event) end function Public_event.rocky_loot(event) - local surface = game.surfaces[global.active_surface_index] + local objective = Chrono_table.get_table() + local surface = game.surfaces[objective.active_surface_index] local player = game.players[event.player_index] surface.spill_item_stack(player.position,{name = "raw-fish", count = math_random(1,3)},true) local amount = get_ore_amount() @@ -163,6 +168,7 @@ function Public_event.rocky_loot(event) end function Public_event.swamp_loot(event) + local objective = Chrono_table.get_table() local ore_yield = { ["behemoth-biter"] = 5, ["behemoth-spitter"] = 5, @@ -179,7 +185,7 @@ function Public_event.swamp_loot(event) ["small-worm-turret"] = 2, ["spitter-spawner"] = 10, } - local surface = game.surfaces[global.active_surface_index] + local surface = game.surfaces[objective.active_surface_index] local amount = get_ore_amount() / 20 if ore_yield[event.entity.name] then amount = (get_ore_amount() * ore_yield[event.entity.name]) / 20 @@ -198,7 +204,7 @@ function Public_event.swamp_loot(event) end function Public_event.danger_silo(entity) - local objective = global.objective + local objective = Chrono_table.get_table() if objective.planet[1].name.id == 19 then if objective.dangers and #objective.dangers > 1 then for i = 1, #objective.dangers, 1 do @@ -222,8 +228,8 @@ function Public_event.danger_silo(entity) end function Public_event.biter_immunities(event) - local planet = global.objective.planet[1].name.id - local objective = global.objective + local objective = Chrono_table.get_table() + local planet = objective.planet[1].name.id if event.damage_type.name == "fire" then if planet == 14 then --lava planet event.entity.health = event.entity.health + event.final_damage_amount @@ -234,7 +240,7 @@ function Public_event.biter_immunities(event) end end -- else -- other planets - -- event.entity.health = math_floor(event.entity.health + event.final_damage_amount - (event.final_damage_amount / (1 + 0.02 * global.difficulty_vote_value * objective.chronojumps))) + -- event.entity.health = math_floor(event.entity.health + event.final_damage_amount - (event.final_damage_amount / (1 + 0.02 * objective.difficulty_vote_value * objective.chronojumps))) end elseif event.damage_type.name == "poison" then if planet == 18 then --swamp planet @@ -244,9 +250,9 @@ function Public_event.biter_immunities(event) end function Public_event.flamer_nerfs() - local objective = global.objective + local objective = Chrono_table.get_table() local flamer_power = 0 - local difficulty = global.difficulty_vote_value + local difficulty = objective.difficulty_vote_value if difficulty > 1 then difficulty = 1 + ((difficulty - 1) / 2) elseif difficulty < 1 then @@ -304,9 +310,10 @@ function Public_event.mining_buffs(event) end function Public_event.on_technology_effects_reset(event) + local objective = Chrono_table.get_table() if event.force.name == "player" then - game.forces.player.character_inventory_slots_bonus = game.forces.player.character_inventory_slots_bonus + global.objective.invupgradetier * 10 - game.forces.player.character_loot_pickup_distance_bonus = game.forces.player.character_loot_pickup_distance_bonus + global.objective.pickupupgradetier + game.forces.player.character_inventory_slots_bonus = game.forces.player.character_inventory_slots_bonus + objective.invupgradetier * 10 + game.forces.player.character_loot_pickup_distance_bonus = game.forces.player.character_loot_pickup_distance_bonus + objective.pickupupgradetier local fake_event = {} Public_event.mining_buffs(nil) diff --git a/maps/chronosphere/gui.lua b/maps/chronosphere/gui.lua index afef36ba..11ddd676 100644 --- a/maps/chronosphere/gui.lua +++ b/maps/chronosphere/gui.lua @@ -1,3 +1,4 @@ +local Chrono_table = require 'maps.chronosphere.table' local Public_gui = {} local math_floor = math.floor @@ -78,17 +79,18 @@ local function create_gui(player) end local function update_upgrades_gui(player) + local objective = Chrono_table.get_table() if not player.gui.screen["gui_upgrades"] then return end local upgrades = Upgrades.upgrades() local frame = player.gui.screen["gui_upgrades"] for i = 1, #upgrades, 1 do local t = frame["upgrades_table" .. i] - t["upgrade" .. i].number = global.objective.upgrades[i] + t["upgrade" .. i].number = objective.upgrades[i] t["upgrade" .. i].tooltip = upgrades[i].tooltip t["upgrade_label" .. i].tooltip = upgrades[i].tooltip - if global.objective.upgrades[i] == upgrades[i].max_level then + if objective.upgrades[i] == upgrades[i].max_level then t["maxed" .. i].visible = true t["jump_req" .. i].visible = false for index,_ in pairs(upgrades[i].cost) do @@ -107,8 +109,9 @@ local function update_upgrades_gui(player) end local function update_planet_gui(player) + local objective = Chrono_table.get_table() if not player.gui.screen["gui_planet"] then return end - local planet = global.objective.planet[1] + local planet = objective.planet[1] local evolution = game.forces["enemy"].evolution_factor local evo_color = { r = math_floor(255 * 1 * math_max(0, math_min(1, 1.2 - evolution * 2))), @@ -128,13 +131,13 @@ local function update_planet_gui(player) frame["planet_biters"].caption = {"chronosphere.gui_planet_3", math_floor(evolution * 1000) / 10} frame["planet_biters"].style.font_color = evo_color - frame["planet_biters3"].caption = {"chronosphere.gui_planet_4_1", global.objective.passivejumps * 2.5, global.objective.passivejumps * 10} + frame["planet_biters3"].caption = {"chronosphere.gui_planet_4_1", objective.passivejumps * 2.5, objective.passivejumps * 10} frame["planet_time"].caption = {"chronosphere.gui_planet_5", planet.day_speed.name} end function Public_gui.update_gui(player) - local objective = global.objective + local objective = Chrono_table.get_table() update_planet_gui(player) update_upgrades_gui(player) if not player.gui.top.chronosphere then create_gui(player) end @@ -171,7 +174,7 @@ function Public_gui.update_gui(player) gui.upgrades_button.caption = {"chronosphere.gui_upgrades_button"} local acus = 0 - if global.acumulators then acus = #global.acumulators end + if objective.acumulators then acus = #objective.acumulators end local bestcase = math_floor((objective.chrononeeds - objective.chronotimer) / (1 + math_floor(acus/10))) local nukecase = objective.dangertimer if objective.planet[1].name.id == 19 and objective.passivetimer > 31 then @@ -189,7 +192,7 @@ end local function upgrades_gui(player) if player.gui.screen["gui_upgrades"] then player.gui.screen["gui_upgrades"].destroy() return end - local objective = global.objective + local objective = Chrono_table.get_table() local upgrades = Upgrades.upgrades() local frame = player.gui.screen.add{type = "frame", name = "gui_upgrades", caption = "ChronoTrain Upgrades", direction = "vertical"} frame.location = {x = 350, y = 45} @@ -202,7 +205,7 @@ local function upgrades_gui(player) for i = 1, #upgrades, 1 do local upg_table = frame.add({type = "table", name = "upgrades_table" .. i, column_count = 10}) - upg_table.add({type = "sprite-button", name = "upgrade" .. i, enabled = false, sprite = upgrades[i].sprite, number = global.objective.upgrades[i], tooltip = upgrades[i].tooltip}) + upg_table.add({type = "sprite-button", name = "upgrade" .. i, enabled = false, sprite = upgrades[i].sprite, number = objective.upgrades[i], tooltip = upgrades[i].tooltip}) local name = upg_table.add({type = "label", name ="upgrade_label" .. i, caption = upgrades[i].name, tooltip = upgrades[i].tooltip}) name.style.width = 200 @@ -212,7 +215,7 @@ local function upgrades_gui(player) for index,item in pairs(upgrades[i].cost) do costs[index] = upg_table.add({type = "sprite-button", name = index .. "-" .. i, number = item.count, sprite = item.sprite, enabled = false, tooltip = {item.tt .. "." .. item.name}, visible = true}) end - if global.objective.upgrades[i] == upgrades[i].max_level then + if objective.upgrades[i] == upgrades[i].max_level then maxed.visible = true jumps.visible = false for index,_ in pairs(upgrades[i].cost) do @@ -230,8 +233,9 @@ local function upgrades_gui(player) end local function planet_gui(player) + local objective = Chrono_table.get_table() if player.gui.screen["gui_planet"] then player.gui.screen["gui_planet"].destroy() return end - local planet = global.objective.planet[1] + local planet = objective.planet[1] local evolution = game.forces["enemy"].evolution_factor local frame = player.gui.screen.add{type = "frame", name = "gui_planet", caption = "Planet Info", direction = "vertical"} frame.location = {x = 650, y = 45} @@ -253,7 +257,7 @@ local function planet_gui(player) frame.add({type = "line"}) frame.add({type = "label", name = "planet_biters", caption = {"chronosphere.gui_planet_3", math_floor(evolution * 1000) / 10}}) frame.add({type = "label", name = "planet_biters2", caption = {"chronosphere.gui_planet_4"}}) - frame.add({type = "label", name = "planet_biters3", caption = {"chronosphere.gui_planet_4_1", global.objective.passivejumps * 2.5, global.objective.passivejumps * 10}}) + frame.add({type = "label", name = "planet_biters3", caption = {"chronosphere.gui_planet_4_1", objective.passivejumps * 2.5, objective.passivejumps * 10}}) frame.add({type = "line"}) frame.add({type = "label", name = "planet_time", caption = {"chronosphere.gui_planet_5", planet.day_speed.name}}) frame.add({type = "line"}) diff --git a/maps/chronosphere/locomotive.lua b/maps/chronosphere/locomotive.lua index 474d8885..2b842787 100644 --- a/maps/chronosphere/locomotive.lua +++ b/maps/chronosphere/locomotive.lua @@ -1,3 +1,4 @@ +local Chrono_table = require 'maps.chronosphere.table' local Public = {} local Upgrades = require "maps.chronosphere.upgrade_list" local math_floor = math.floor @@ -7,7 +8,8 @@ local function math_sgn(x) end function Public.locomotive_spawn(surface, position, wagons) - if global.objective.planet[1].name.id == 17 then --fish market + local objective = Chrono_table.get_table() + if objective.planet[1].name.id == 17 then --fish market position.x = position.x - 960 position.y = position.y - 64 end @@ -15,11 +17,11 @@ function Public.locomotive_spawn(surface, position, wagons) local rail = {name = "straight-rail", position = {position.x, position.y + y}, force = "player", direction = 0} surface.create_entity({name = "straight-rail", position = {position.x, position.y + y}, force = "player", direction = 0}) end - global.locomotive = surface.create_entity({name = "locomotive", position = {position.x, position.y + -6}, force = "player"}) - global.locomotive.get_inventory(defines.inventory.fuel).insert({name = "wood", count = 100}) + objective.locomotive = surface.create_entity({name = "locomotive", position = {position.x, position.y + -6}, force = "player"}) + objective.locomotive.get_inventory(defines.inventory.fuel).insert({name = "wood", count = 100}) for i = 1, 3, 1 do - global.locomotive_cargo[i] = surface.create_entity({name = "cargo-wagon", position = {position.x, position.y + math_floor((i - 1) * 6.5)}, force = "player"}) - local inv = global.locomotive_cargo[i].get_inventory(defines.inventory.cargo_wagon) + objective.locomotive_cargo[i] = surface.create_entity({name = "cargo-wagon", position = {position.x, position.y + math_floor((i - 1) * 6.5)}, force = "player"}) + local inv = objective.locomotive_cargo[i].get_inventory(defines.inventory.cargo_wagon) if wagons[i].bar > 0 then inv.set_bar(wagons[i].bar) end for ii = 1, 40, 1 do inv.set_filter(ii, wagons[i].filters[ii]) @@ -27,14 +29,14 @@ function Public.locomotive_spawn(surface, position, wagons) inv.insert(wagons[i].inventory[ii]) end end - global.locomotive_cargo[i].minable = false + objective.locomotive_cargo[i].minable = false end - global.locomotive_cargo[1].operable = false - global.locomotive.color = {0, 255, 0} - global.locomotive.minable = false + objective.locomotive_cargo[1].operable = false + objective.locomotive.color = {0, 255, 0} + objective.locomotive.minable = false - --if not global.comfychests then global.comfychests = {} end - --if not global.acumulators then global.acumulators = {} end + --if not objective.comfychests then objective.comfychests = {} end + --if not objective.acumulators then objective.acumulators = {} end for i = 1, 24, 1 do local yi = 0 local xi = 5 @@ -61,21 +63,21 @@ function Public.locomotive_spawn(surface, position, wagons) local comfychest = surface.create_entity({name = "steel-chest", position = {position.x - 2 + xi, position.y - 2 + yi + i}, force = "player"}) comfychest.minable = false --comfychest.destructible = false - if not global.comfychests[i] then - table.insert(global.comfychests, comfychest) + if not objective.comfychests[i] then + table.insert(objective.comfychests, comfychest) else - global.comfychests[i] = comfychest + objective.comfychests[i] = comfychest end end rendering.draw_light({ sprite = "utility/light_medium", scale = 5.5, intensity = 1, minimum_darkness = 0, - oriented = true, color = {255,255,255}, target = global.locomotive, + oriented = true, color = {255,255,255}, target = objective.locomotive, surface = surface, visible = true, only_in_alt_mode = false, }) rendering.draw_light({ sprite = "utility/light_medium", scale = 5.5, intensity = 1, minimum_darkness = 0, - oriented = true, color = {255,255,255}, target = global.locomotive_cargo[3], + oriented = true, color = {255,255,255}, target = objective.locomotive_cargo[3], surface = surface, visible = true, only_in_alt_mode = false, }) @@ -84,18 +86,19 @@ end function Public.fish_tag() - if not global.locomotive_cargo[1] then return end - local cargo = global.locomotive_cargo[1] + local objective = Chrono_table.get_table() + if not objective.locomotive_cargo[1] then return end + local cargo = objective.locomotive_cargo[1] if not cargo.valid then return end if not cargo.surface then return end if not cargo.surface.valid then return end - if global.locomotive_tag then - if global.locomotive_tag.valid then - if global.locomotive_tag.position.x == cargo.position.x and global.locomotive_tag.position.y == cargo.position.y then return end - global.locomotive_tag.destroy() + if objective.locomotive_tag then + if objective.locomotive_tag.valid then + if objective.locomotive_tag.position.x == cargo.position.x and objective.locomotive_tag.position.y == cargo.position.y then return end + objective.locomotive_tag.destroy() end end - global.locomotive_tag = cargo.force.add_chart_tag( + objective.locomotive_tag = cargo.force.add_chart_tag( cargo.surface, {icon = {type = 'item', name = 'raw-fish'}, position = cargo.position, @@ -121,10 +124,11 @@ local market_offers = { } function Public.create_wagon_room() + local objective = Chrono_table.get_table() local width = 64 local height = 384 - global.comfychests2 = {} - global.acumulators = {} + objective.comfychests2 = {} + objective.acumulators = {} local map_gen_settings = { ["width"] = width, ["height"] = height + 128, @@ -270,7 +274,7 @@ function Public.create_wagon_room() local e = surface.create_entity({name = "steel-chest", position = {x,y}, force = "player", create_build_effect_smoke = false}) e.destructible = false e.minable = false - table.insert(global.comfychests2, e) + table.insert(objective.comfychests2, e) end end @@ -293,14 +297,14 @@ function Public.create_wagon_room() end acumulator.minable = false acumulator.destructible = false - table.insert(global.acumulators, acumulator) + table.insert(objective.acumulators, acumulator) end for k = 1, 4, 1 do local xx = x + 2 * k local acumulator = surface.create_entity({name = "accumulator", position = {xx,y}, force="player", create_build_effect_smoke = false}) acumulator.minable = false acumulator.destructible = false - table.insert(global.acumulators, acumulator) + table.insert(objective.acumulators, acumulator) end end @@ -315,13 +319,13 @@ function Public.create_wagon_room() local repairchest = surface.create_entity({name = "steel-chest", position = {-24, height * -0.5 + 3}, force = "player"}) repairchest.minable = false repairchest.destructible = false - global.upgradechest[0] = repairchest + objective.upgradechest[0] = repairchest rendering.draw_text{ text = "Repair chest", surface = surface, target = repairchest, target_offset = {0, -2.5}, - color = global.locomotive.color, + color = objective.locomotive.color, scale = 1.00, font = "default-game", alignment = "center", @@ -332,7 +336,7 @@ function Public.create_wagon_room() local e = surface.create_entity({name = "steel-chest", position = {-21 + i, height * -0.5 + 3}, force = "player"}) e.minable = false e.destructible = false - global.upgradechest[i] = e + objective.upgradechest[i] = e rendering.draw_sprite{ sprite = upgrades[i].sprite, surface = surface, @@ -348,7 +352,7 @@ function Public.create_wagon_room() surface = surface, target = market, target_offset = {0, -3.5}, - color = global.locomotive.color, + color = objective.locomotive.color, scale = 1.00, font = "default-game", alignment = "center", @@ -357,9 +361,9 @@ function Public.create_wagon_room() local upgrade_text = rendering.draw_text{ text = "Upgrades", surface = surface, - target = global.upgradechest[8], + target = objective.upgradechest[8], target_offset = {0, -3.5}, - color = global.locomotive.color, + color = objective.locomotive.color, scale = 1.00, font = "default-game", alignment = "center", @@ -368,9 +372,9 @@ function Public.create_wagon_room() local upgrade_sub_text = rendering.draw_text{ text = "Click [Upgrades] on top of screen", surface = surface, - target = global.upgradechest[8], + target = objective.upgradechest[8], target_offset = {0, -2.5}, - color = global.locomotive.color, + color = objective.locomotive.color, scale = 0.80, font = "default-game", alignment = "center", @@ -389,14 +393,14 @@ function Public.create_wagon_room() {x = width * 0.5 + 1.4, y = 0}, {x = width * 0.5 + 1.4, y = 128} } - global.car_exits = {} + objective.car_exits = {} for i = 1, 6, 1 do local e = surface.create_entity({name = "car", position = car_pos[i], force = "player", create_build_effect_smoke = false}) e.get_inventory(defines.inventory.fuel).insert({name = "wood", count = 16}) e.destructible = false e.minable = false e.operable = false - global.car_exits[i] = e + objective.car_exits[i] = e end --generate chests inside south wagon-- @@ -471,8 +475,9 @@ function Public.create_wagon_room() end function Public.set_player_spawn_and_refill_fish() - if not global.locomotive_cargo[1] then return end - local cargo = global.locomotive_cargo[1] + local objective = Chrono_table.get_table() + if not objective.locomotive_cargo[1] then return end + local cargo = objective.locomotive_cargo[1] if not cargo.valid then return end cargo.get_inventory(defines.inventory.cargo_wagon).insert({name = "raw-fish", count = math_random(1, 2)}) local position = cargo.surface.find_non_colliding_position("stone-furnace", cargo.position, 16, 2) @@ -481,14 +486,15 @@ function Public.set_player_spawn_and_refill_fish() end function Public.enter_cargo_wagon(player, vehicle) + local objective = Chrono_table.get_table() if not vehicle then log("no vehicle") return end if not vehicle.valid then log("vehicle invalid") return end if not game.surfaces["cargo_wagon"] then Public.create_wagon_room() end local wagon_surface = game.surfaces["cargo_wagon"] for i = 1, 3, 1 do - if not global.locomotive_cargo[i] then log("no cargo") return end - if not global.locomotive_cargo[i].valid then log("cargo invalid") return end - if vehicle == global.locomotive_cargo[i] then + if not objective.locomotive_cargo[i] then log("no cargo") return end + if not objective.locomotive_cargo[i].valid then log("cargo invalid") return end + if vehicle == objective.locomotive_cargo[i] then local x_vector = vehicle.position.x - player.position.x local position if x_vector > 0 then @@ -501,18 +507,18 @@ function Public.enter_cargo_wagon(player, vehicle) end end if player.surface.name == "cargo_wagon" and vehicle.type == "car" then - if global.flame_boots then - global.flame_boots[player.index] = {fuel = 1, steps = {}} + if objective.flame_boots then + objective.flame_boots[player.index] = {fuel = 1, steps = {}} end local used_exit = 0 for i = 1, 6, 1 do - if vehicle == global.car_exits[i] then + if vehicle == objective.car_exits[i] then used_exit = i break end end - local surface = global.locomotive_cargo[1].surface - local position = {x = global.locomotive_cargo[((used_exit - 1) % 3) + 1].position.x + math_sgn(used_exit - 3.5) * 2, y = global.locomotive_cargo[((used_exit - 1) % 3) + 1].position.y} + local surface = objective.locomotive_cargo[1].surface + local position = {x = objective.locomotive_cargo[((used_exit - 1) % 3) + 1].position.x + math_sgn(used_exit - 3.5) * 2, y = objective.locomotive_cargo[((used_exit - 1) % 3) + 1].position.y} local position2 = surface.find_non_colliding_position("character", position, 128, 0.5) if not position2 then return end player.teleport(position2, surface) diff --git a/maps/chronosphere/main.lua b/maps/chronosphere/main.lua index 6ebe0f5e..7ad4e8d9 100644 --- a/maps/chronosphere/main.lua +++ b/maps/chronosphere/main.lua @@ -1,7 +1,5 @@ -- chronosphere -- -global.objective = {} -global.objective.upgrades = {} require "modules.difficulty_vote" require "modules.biters_yield_coins" require "modules.no_deconstruction_of_neutral_entities" @@ -22,22 +20,20 @@ local Upgrades = require "maps.chronosphere.upgrades" local Tick_functions = require "maps.chronosphere.tick_functions" local Event_functions = require "maps.chronosphere.event_functions" local Chrono = require "maps.chronosphere.chrono" +local Chrono_table = require 'maps.chronosphere.table' local Locomotive = require "maps.chronosphere.locomotive" local Gui = require "maps.chronosphere.gui" local math_random = math.random local math_floor = math.floor local math_sqrt = math.sqrt -global.objective.config = {} -global.flame_boots = {} -global.comfylatron = nil -global.lab_cells = {} require "maps.chronosphere.config_tab" local starting_items = {['pistol'] = 1, ['firearm-magazine'] = 32, ['grenade'] = 4, ['raw-fish'] = 4, ['rail'] = 16, ['wood'] = 16} local function generate_overworld(surface, optplanet) + local objective = Chrono_table.get_table() Planets.determine_planet(optplanet) - local planet = global.objective.planet + local planet = objective.planet local message = {"chronosphere.planet_jump", planet[1].name.name, planet[1].ore_richness.name, planet[1].day_speed.name} game.print(message, {r=0.98, g=0.66, b=0.22}) local discordmessage = "Destination: "..planet[1].name.dname..", Ore Richness: "..planet[1].ore_richness.dname..", Daynight cycle: "..planet[1].day_speed.dname @@ -52,7 +48,7 @@ local function generate_overworld(surface, optplanet) end surface.min_brightness = 0 surface.brightness_visual_weights = {1, 1, 1} - global.objective.surface = surface + objective.surface = surface surface.daytime = planet[1].time local timer = planet[1].day_speed.timer if timer == 0 then @@ -93,14 +89,14 @@ local function generate_overworld(surface, optplanet) end local function render_train_hp() - local surface = game.surfaces[global.active_surface_index] - local objective = global.objective + local objective = Chrono_table.get_table() + local surface = game.surfaces[objective.active_surface_index] objective.health_text = rendering.draw_text{ text = "HP: " .. objective.health .. " / " .. objective.max_health, surface = surface, - target = global.locomotive, + target = objective.locomotive, target_offset = {0, -2.5}, - color = global.locomotive.color, + color = objective.locomotive.color, scale = 1.40, font = "default-game", alignment = "center", @@ -109,9 +105,9 @@ local function render_train_hp() objective.caption = rendering.draw_text{ text = "Comfylatron's ChronoTrain", surface = surface, - target = global.locomotive, + target = objective.locomotive, target_offset = {0, -4.25}, - color = global.locomotive.color, + color = objective.locomotive.color, scale = 1.80, font = "default-game", alignment = "center", @@ -121,27 +117,27 @@ end local function reset_map() + local objective = Chrono_table.get_table() for _,player in pairs(game.players) do if player.controller_type == defines.controllers.editor then player.toggle_map_editor() end end if game.surfaces["chronosphere"] then game.delete_surface(game.surfaces["chronosphere"]) end if game.surfaces["cargo_wagon"] then game.delete_surface(game.surfaces["cargo_wagon"]) end - local objective = global.objective for i = 13, 16, 1 do objective.upgrades[i] = 0 end objective.computermessage = 0 objective.chronojumps = 0 Planets.determine_planet(nil) - local planet = global.objective.planet - if not global.active_surface_index then - global.active_surface_index = game.create_surface("chronosphere", Chrono.get_map_gen_settings()).index + local planet = objective.planet + if not objective.active_surface_index then + objective.active_surface_index = game.create_surface("chronosphere", Chrono.get_map_gen_settings()).index else - game.forces.player.set_spawn_position({12, 10}, game.surfaces[global.active_surface_index]) - global.active_surface_index = Reset.soft_reset_map(game.surfaces[global.active_surface_index], Chrono.get_map_gen_settings(), starting_items).index + game.forces.player.set_spawn_position({12, 10}, game.surfaces[objective.active_surface_index]) + objective.active_surface_index = Reset.soft_reset_map(game.surfaces[objective.active_surface_index], Chrono.get_map_gen_settings(), starting_items).index end - local surface = game.surfaces[global.active_surface_index] + local surface = game.surfaces[objective.active_surface_index] generate_overworld(surface, planet) Chrono.restart_settings() @@ -160,11 +156,15 @@ local function reset_map() end local function on_player_joined_game(event) + local objective = Chrono_table.get_table() local player = game.players[event.player_index] - global.flame_boots[event.player_index] = {fuel = 1} - if not global.flame_boots[event.player_index].steps then global.flame_boots[event.player_index].steps = {} end + if not objective.flame_boots[event.player_index] then + objective.flame_boots[event.player_index] = {} + end + objective.flame_boots[event.player_index] = {fuel = 1} + if not objective.flame_boots[event.player_index].steps then objective.flame_boots[event.player_index].steps = {} end - local surface = game.surfaces[global.active_surface_index] + local surface = game.surfaces[objective.active_surface_index] if player.online_time == 0 then player.teleport(surface.find_non_colliding_position("character", game.forces.player.get_spawn_position(surface), 32, 0.5), surface) @@ -173,7 +173,7 @@ local function on_player_joined_game(event) end end - if player.surface.index ~= global.active_surface_index and player.surface.name ~= "cargo_wagon" then + if player.surface.index ~= objective.active_surface_index and player.surface.name ~= "cargo_wagon" then player.character = nil player.set_controller({type=defines.controllers.god}) player.create_character() @@ -192,17 +192,18 @@ local function on_player_joined_game(event) end local function on_pre_player_left_game(event) + local objective = Chrono_table.get_table() local player = game.players[event.player_index] if player.controller_type == defines.controllers.editor then player.toggle_map_editor() end if player.character then - global.objective.offline_players[#global.objective.offline_players + 1] = {index = event.player_index, tick = game.tick} + objective.offline_players[#objective.offline_players + 1] = {index = event.player_index, tick = game.tick} end end local function set_objective_health(final_damage_amount) if final_damage_amount == 0 then return end - local objective = global.objective + local objective = Chrono_table.get_table() objective.health = math_floor(objective.health - final_damage_amount) if objective.health > objective.max_health then objective.health = objective.max_health end @@ -216,27 +217,27 @@ local function set_objective_health(final_damage_amount) end local function chronojump(choice) - local objective = global.objective + local objective = Chrono_table.get_table() if objective.game_lost then return end Chrono.process_jump() - local oldsurface = game.surfaces[global.active_surface_index] + local oldsurface = game.surfaces[objective.active_surface_index] for _,player in pairs(game.players) do if player.surface == oldsurface then if player.controller_type == defines.controllers.editor then player.toggle_map_editor() end - local wagons = {global.locomotive_cargo[1], global.locomotive_cargo[2], global.locomotive_cargo[3]} + local wagons = {objective.locomotive_cargo[1], objective.locomotive_cargo[2], objective.locomotive_cargo[3]} Locomotive.enter_cargo_wagon(player, wagons[math_random(1,3)]) end end - global.lab_cells = {} - global.active_surface_index = game.create_surface("chronosphere" .. objective.chronojumps, Chrono.get_map_gen_settings()).index - local surface = game.surfaces[global.active_surface_index] + objective.lab_cells = {} + objective.active_surface_index = game.create_surface("chronosphere" .. objective.chronojumps, Chrono.get_map_gen_settings()).index + local surface = game.surfaces[objective.active_surface_index] log("seed of new surface: " .. surface.map_gen_settings.seed) local planet = nil if choice then Planets.determine_planet(choice) - planet = global.objective.planet + planet = objective.planet end generate_overworld(surface, planet) @@ -247,7 +248,7 @@ local function chronojump(choice) game.delete_surface(oldsurface) Chrono.post_jump() Event_functions.flamer_nerfs() - surface.pollute(global.locomotive.position, 150 * (4 / (objective.upgrades[2] / 2 + 1)) * (1 + global.objective.chronojumps) * global.difficulty_vote_value) + surface.pollute(objective.locomotive.position, 150 * (4 / (objective.upgrades[2] / 2 + 1)) * (1 + objective.chronojumps) * objective.difficulty_vote_value) end local tick_minute_functions = { @@ -266,10 +267,10 @@ local tick_minute_functions = { } local function tick() - local objective = global.objective + local objective = Chrono_table.get_table() local tick = game.tick if tick % 60 == 30 and objective.passivetimer < 64 then - local surface = game.surfaces[global.active_surface_index] + local surface = game.surfaces[objective.active_surface_index] if objective.planet[1].name.id == 17 then surface.request_to_generate_chunks({-800,0}, 3 + math_floor(objective.passivetimer / 5)) else @@ -304,7 +305,7 @@ local function tick() objective.chronotimer = objective.chronotimer + 1 objective.passivetimer = objective.passivetimer + 1 if objective.chronojumps > 0 then - game.surfaces[global.active_surface_index].pollute(global.locomotive.position, (0.5 * objective.chronojumps) * (4 / (objective.upgrades[2] / 2 + 1)) * global.difficulty_vote_value) + game.surfaces[objective.active_surface_index].pollute(objective.locomotive.position, (0.5 * objective.chronojumps) * (4 / (objective.upgrades[2] / 2 + 1)) * objective.difficulty_vote_value) end if objective.planet[1].name.id == 19 then Tick_functions.dangertimer() @@ -315,9 +316,9 @@ local function tick() Tick_functions.move_items() Tick_functions.output_items() end - if global.game_reset_tick then - if global.game_reset_tick < tick then - global.game_reset_tick = nil + if objective.game_reset_tick then + if objective.game_reset_tick < tick then + objective.game_reset_tick = nil reset_map() end return @@ -328,16 +329,17 @@ local function tick() end local function on_init() + local objective = Chrono_table.get_table() local T = Map.Pop_info() T.localised_category = "chronosphere" T.main_caption_color = {r = 150, g = 150, b = 0} T.sub_caption_color = {r = 0, g = 150, b = 0} - global.objective.game_lost = true - global.objective.game_won = false - global.objective.offline_players = {} + objective.game_lost = true + objective.game_won = false + objective.offline_players = {} - global.objective.config.offline_loot = true - global.objective.config.jumpfailure = true + objective.config.offline_loot = true + objective.config.jumpfailure = true game.create_force("scrapyard") local mgs = game.surfaces["nauvis"].map_gen_settings mgs.width = 16 @@ -355,16 +357,17 @@ end -- end local function protect_entity(event) + local objective = Chrono_table.get_table() if event.entity.force.index ~= 1 then return end --Player Force if Event_functions.isprotected(event.entity) then if event.cause then - if event.cause == global.comfylatron or event.entity == global.comfylatron then + if event.cause == objective.comfylatron or event.entity == objective.comfylatron then return end if event.cause.force.index == 2 or event.cause.force.name == "scrapyard" then set_objective_health(event.final_damage_amount) end - elseif global.objective.planet[1].name.id == 19 then + elseif objective.planet[1].name.id == 19 then set_objective_health(event.final_damage_amount) end if not event.entity.valid then return end @@ -384,7 +387,7 @@ local function on_entity_damaged(event) end local function pre_player_mined_item(event) - local objective = global.objective + local objective = Chrono_table.get_table() if objective.planet[1].name.id == 11 then --rocky planet if event.entity.name == "rock-huge" or event.entity.name == "rock-big" or event.entity.name == "sand-rock-big" then Event_functions.trap(event.entity, false) @@ -395,23 +398,25 @@ local function pre_player_mined_item(event) end local function on_player_mined_entity(event) + local objective = Chrono_table.get_table() local entity = event.entity if not entity.valid then return end - if entity.type == "tree" and global.objective.planet[1].name.id == 12 then --choppy planet + if entity.type == "tree" and objective.planet[1].name.id == 12 then --choppy planet Event_functions.trap(entity, false) Event_functions.choppy_loot(event) end if entity.name == "rock-huge" or entity.name == "rock-big" or entity.name == "sand-rock-big" then - if global.objective.planet[1].name.id ~= 11 and global.objective.planet[1].name.id ~= 16 then --rocky and maze planet + if objective.planet[1].name.id ~= 11 and objective.planet[1].name.id ~= 16 then --rocky and maze planet Ores.prospect_ores(entity, entity.surface, entity.position) elseif - global.objective.planet[1].name.id == 11 then event.buffer.clear() -- rocky planet + objective.planet[1].name.id == 11 then event.buffer.clear() -- rocky planet end end end local function on_entity_died(event) - if event.entity.type == "tree" and global.objective.planet[1].name.id == 12 then --choppy planet + local objective = Chrono_table.get_table() + if event.entity.type == "tree" and objective.planet[1].name.id == 12 then --choppy planet if event.cause then if event.cause.valid then if event.cause.force.name ~= "enemy" then @@ -428,24 +433,24 @@ local function on_entity_died(event) local entity = event.entity if not entity.valid then return end if entity.type == "unit" and entity.force == "enemy" then - global.objective.active_biters[entity.unit_number] = nil + objective.active_biters[entity.unit_number] = nil end if entity.type == "rocket-silo" and entity.force.name == "enemy" then Event_functions.danger_silo(entity) end if entity.force.name == "scrapyard" and entity.name == "gun-turret" then - if global.objective.planet[1].name.id == 19 or global.objective.planet[1].name.id == 16 then --danger + hedge maze + if objective.planet[1].name.id == 19 or objective.planet[1].name.id == 16 then --danger + hedge maze Event_functions.trap(entity, true) end end if entity.force.name == "enemy" then if entity.type == "unit-spawner" then Event_functions.spawner_loot(entity.surface, entity.position) - if global.objective.planet[1].name.id == 18 then + if objective.planet[1].name.id == 18 then Ores.prospect_ores(entity, entity.surface, entity.position) end else - if global.objective.planet[1].name.id == 18 then + if objective.planet[1].name.id == 18 then Event_functions.swamp_loot(event) end end @@ -511,7 +516,8 @@ end -- end local function on_player_changed_position(event) - if global.objective.planet[1].name.id == 14 then --lava planet + local objective = Chrono_table.get_table() + if objective.planet[1].name.id == 14 then --lava planet Event_functions.lava_planet(event) end end @@ -567,13 +573,13 @@ if _DEBUG then end --Time for the debug code. If any (not global.) globals are written to at this point, an error will be thrown. --eg, x = 2 will throw an error because it's not global.x or local x -setmetatable(_G, { - __newindex = function(_, n, v) - log("Desync warning: attempt to write to undeclared var " .. n) - -- game.print("Attempt to write to undeclared var " .. n) - global[n] = v; - end, - __index = function(_, n) - return global[n]; - end -}) +--setmetatable(_G, { +-- __newindex = function(_, n, v) +-- log("Desync warning: attempt to write to undeclared var " .. n) +-- -- game.print("Attempt to write to undeclared var " .. n) +-- global[n] = v; +-- end, +-- __index = function(_, n) +-- return global[n]; +-- end +--}) diff --git a/maps/chronosphere/ores.lua b/maps/chronosphere/ores.lua index 42d804cd..094062a8 100644 --- a/maps/chronosphere/ores.lua +++ b/maps/chronosphere/ores.lua @@ -1,3 +1,4 @@ +local Chrono_table = require 'maps.chronosphere.table' local Public_ores = {} local simplex_noise = require 'utils.simplex_noise'.d2 local math_random = math.random @@ -65,14 +66,16 @@ local function get_size_of_ore(ore, planet) end local function get_oil_amount(pos, oil_w, richness) + local objective = Chrono_table.get_table() local hundred_percent = 300000 - return (hundred_percent / 50) * (1+global.objective.chronojumps) * oil_w * richness + return (hundred_percent / 50) * (1+objective.chronojumps) * oil_w * richness end local function spawn_ore_vein(surface, pos, planet) + local objective = Chrono_table.get_table() local mixed = false if planet[1].name.id == 6 then mixed = true end --mixed planet - local richness = math_random(50 + 10 * global.objective.chronojumps, 100 + 10 * global.objective.chronojumps) * planet[1].ore_richness.factor + local richness = math_random(50 + 10 * objective.chronojumps, 100 + 10 * objective.chronojumps) * planet[1].ore_richness.factor if planet[1].name.id == 16 then richness = richness * 10 end --hedge maze local iron = {w = planet[1].name.iron, t = planet[1].name.iron} local copper = {w = planet[1].name.copper, t = iron.t + planet[1].name.copper} @@ -109,7 +112,8 @@ local function spawn_ore_vein(surface, pos, planet) end function Public_ores.prospect_ores(entity, surface, pos) - local planet = global.objective.planet + local objective = Chrono_table.get_table() + local planet = objective.planet local chance = 10 if entity then if entity.name == "rock-huge" then chance = 40 end diff --git a/maps/chronosphere/table.lua b/maps/chronosphere/table.lua new file mode 100644 index 00000000..6ac1d92f --- /dev/null +++ b/maps/chronosphere/table.lua @@ -0,0 +1,64 @@ +-- on table to rule them all! +local Global = require 'utils.global' +local Event = require 'utils.event' + +local chronosphere = {} +local Public = {} + +Global.register( + chronosphere, + function(tbl) + chronosphere = tbl + end +) + +function Public.reset_table() + for k, v in pairs(chronosphere) do + chronosphere[k] = nil + end + chronosphere.computermessage = 0 + chronosphere.config = {} + chronosphere.lab_cells = {} + chronosphere.flame_boots = {} + chronosphere.chronojumps = 0 + chronosphere.game_lost = true + chronosphere.game_won = false + chronosphere.max_health = 10000 + chronosphere.health = 10000 + chronosphere.poisontimeout = 0 + chronosphere.chronotimer = 0 + chronosphere.passivetimer = 0 + chronosphere.passivejumps = 0 + chronosphere.chrononeeds = 2000 + chronosphere.mainscore = 0 + chronosphere.active_biters = {} + chronosphere.unit_groups = {} + chronosphere.biter_raffle = {} + chronosphere.dangertimer = 1200 + chronosphere.dangers = {} + chronosphere.looted_nukes = 0 + chronosphere.offline_players = {} + chronosphere.nextsurface = nil + chronosphere.upgrades = {} + chronosphere.outchests = {} + chronosphere.upgradechest = {} + chronosphere.fishchest = {} + chronosphere.comfylatron = {} + chronosphere.acumulators = {} + chronosphere.comfychests = {} + chronosphere.comfychests2 = {} + chronosphere.locomotive_cargo = {} + chronosphere.planet = {} +end + +function Public.get_table() + return chronosphere +end + +local on_init = function () + Public.reset_table() +end + +Event.on_init(on_init) + +return Public diff --git a/maps/chronosphere/terrain.lua b/maps/chronosphere/terrain.lua index 6ef4ddcc..ba746703 100644 --- a/maps/chronosphere/terrain.lua +++ b/maps/chronosphere/terrain.lua @@ -1,5 +1,6 @@ --require "maps.chronosphere.ores" +local Chrono_table = require 'maps.chronosphere.table' local Ores = require "maps.chronosphere.ores" local Specials = require "maps.chronosphere.terrain_specials" local math_random = math.random @@ -96,9 +97,10 @@ local function get_size_of_ore(ore, planet) end local function get_path_connections_count(cell_pos) + local objective = Chrono_table.get_table() local connections = 0 for _, m in pairs(modifiers) do - if global.lab_cells[tostring(cell_pos.x + m.x) .. "_" .. tostring(cell_pos.y + m.y)] then + if objective.lab_cells[tostring(cell_pos.x + m.x) .. "_" .. tostring(cell_pos.y + m.y)] then connections = connections + 1 end end @@ -106,17 +108,18 @@ local function get_path_connections_count(cell_pos) end local function process_labyrinth_cell(pos, seed) - local cell_position = {x = pos.x / labyrinth_cell_size, y = pos.y / labyrinth_cell_size} + local objective = Chrono_table.get_table() + local cell_position = {x = pos.x / labyrinth_cell_size, y = pos.y / labyrinth_cell_size} local mazenoise = get_noise("hedgemaze", cell_position, seed) if mazenoise < lake_noise_value and math_sqrt((pos.x / 32)^2 + (pos.y / 32)^2) > 65 then return false end - global.lab_cells[tostring(cell_position.x) .. "_" .. tostring(cell_position.y)] = false + objective.lab_cells[tostring(cell_position.x) .. "_" .. tostring(cell_position.y)] = false for _, modifier in pairs(modifiers_diagonal) do - if global.lab_cells[tostring(cell_position.x + modifier.diagonal.x) .. "_" .. tostring(cell_position.y + modifier.diagonal.y)] then - local connection_1 = global.lab_cells[tostring(cell_position.x + modifier.connection_1.x) .. "_" .. tostring(cell_position.y + modifier.connection_1.y)] - local connection_2 = global.lab_cells[tostring(cell_position.x + modifier.connection_2.x) .. "_" .. tostring(cell_position.y + modifier.connection_2.y)] + if objective.lab_cells[tostring(cell_position.x + modifier.diagonal.x) .. "_" .. tostring(cell_position.y + modifier.diagonal.y)] then + local connection_1 = objective.lab_cells[tostring(cell_position.x + modifier.connection_1.x) .. "_" .. tostring(cell_position.y + modifier.connection_1.y)] + local connection_2 = objective.lab_cells[tostring(cell_position.x + modifier.connection_2.x) .. "_" .. tostring(cell_position.y + modifier.connection_2.y)] if not connection_1 and not connection_2 then return false end @@ -129,7 +132,7 @@ local function process_labyrinth_cell(pos, seed) if get_path_connections_count(cell_position) >= math_random(2, 3) then return false end - global.lab_cells[tostring(cell_position.x) .. "_" .. tostring(cell_position.y)] = true + objective.lab_cells[tostring(cell_position.x) .. "_" .. tostring(cell_position.y)] = true return true end @@ -365,8 +368,9 @@ local function process_forest_position(p, seed, tiles, entities, treasure, plane end local function process_river_position(p, seed, tiles, entities, treasure, planet) + local objective = Chrono_table.get_table() local biters = planet[1].name.biters - local richness = math_random(50 + 20 * global.objective.chronojumps, 100 + 20 * global.objective.chronojumps) * planet[1].ore_richness.factor * 0.5 + local richness = math_random(50 + 20 * objective.chronojumps, 100 + 20 * objective.chronojumps) * planet[1].ore_richness.factor * 0.5 local iron_size = get_size_of_ore("iron-ore", planet) * 3 local copper_size = get_size_of_ore("copper-ore", planet) * 3 local stone_size = get_size_of_ore("stone", planet) * 3 @@ -433,13 +437,14 @@ local function process_river_position(p, seed, tiles, entities, treasure, planet end local function process_biter_position(p, seed, tiles, entities, treasure, planet) + local objective = Chrono_table.get_table() local scrapyard = get_noise("scrapyard", p, seed) local noise_forest_location = get_noise("forest_location", p, seed) local large_caves = get_noise("large_caves", p, seed) local biters = planet[1].name.biters local ore_size = planet[1].ore_richness.factor local handicap = 0 - if global.objective.chronojumps < 5 then handicap = 150 end + if objective.chronojumps < 5 then handicap = 150 end if scrapyard < -0.75 or scrapyard > 0.75 then if math_random(1,52 - biters) == 1 and math_sqrt(p.x * p.x + p.y * p.y) > 150 + handicap then entities[#entities + 1] = {name = spawner_raffle[math_random(1, 4)], position = p} end @@ -462,8 +467,8 @@ local function process_biter_position(p, seed, tiles, entities, treasure, planet if scrapyard > -0.10 and scrapyard < 0.10 then if math_floor(large_caves * 10) % 4 < 3 then - local jumps = global.objective.chronojumps * 5 - if global.objective.chronojumps > 20 then jumps = 100 end + local jumps = objective.chronojumps * 5 + if objective.chronojumps > 20 then jumps = 100 end local roll = math_random(1,200 - jumps - biters) if math_sqrt(p.x * p.x + p.y * p.y) > 200 + handicap then if roll == 1 then @@ -480,7 +485,8 @@ local function process_biter_position(p, seed, tiles, entities, treasure, planet end local function process_scrapyard_position(p, seed, tiles, entities, treasure, planet) - local scrapyard = get_noise("scrapyard", p, seed) + local objective = Chrono_table.get_table() + local scrapyard = get_noise("scrapyard", p, seed) local biters = planet[1].name.biters --Chasms local noise_cave_ponds = get_noise("cave_ponds", p, seed) @@ -527,8 +533,8 @@ local function process_scrapyard_position(p, seed, tiles, entities, treasure, pl if scrapyard > -0.15 and scrapyard < 0.15 then if math_floor(large_caves * 10) % 4 < 3 then tiles[#tiles + 1] = {name = "dirt-7", position = p} - local jumps = global.objective.chronojumps * 5 - if global.objective.chronojumps > 20 then jumps = 100 end + local jumps = objective.chronojumps * 5 + if objective.chronojumps > 20 then jumps = 100 end if math_random(1,200 - jumps) == 1 and math_sqrt(p.x * p.x + p.y * p.y) > 150 then entities[#entities + 1] = {name = spawner_raffle[math_random(1, 4)], position = p} end return end @@ -677,8 +683,9 @@ local entity_functions = { Treasure(surface, entity.position, entity.name) end, ["lab"] = function(surface, entity) + local objective = Chrono_table.get_table() local e = surface.create_entity(entity) - local evo = 1 + math_min(math_floor(global.objective.chronojumps / 4), 4) + local evo = 1 + math_min(math_floor(objective.chronojumps / 4), 4) local research = { {"automation-science-pack", "logistic-science-pack"}, {"automation-science-pack", "logistic-science-pack", "military-science-pack"}, @@ -687,12 +694,13 @@ local entity_functions = { {"automation-science-pack", "logistic-science-pack", "military-science-pack", "chemical-science-pack", "production-science-pack", "utility-science-pack"} } for _,science in pairs(research[evo]) do - e.insert({name = science, count = math_random(math_min(32 + global.objective.chronojumps, 100), math_min(64 + global.objective.chronojumps, 200))}) + e.insert({name = science, count = math_random(math_min(32 + objective.chronojumps, 100), math_min(64 + objective.chronojumps, 200))}) end end, } local function get_replacement_tile(surface, position) + local objective = Chrono_table.get_table() for i = 1, 128, 1 do local vectors = {{0, i}, {0, i * -1}, {i, 0}, {i * -1, 0}} table.shuffle_table(vectors) @@ -701,7 +709,7 @@ local function get_replacement_tile(surface, position) if not tile.collides_with("resource-layer") then return tile.name end end end - if global.objective.planet[1].name.id == 18 then return "grass-2" end + if objective.planet[1].name.id == 18 then return "grass-2" end return "grass-1" end @@ -931,9 +939,10 @@ local function normal_chunk(surface, left_top, level, planet) end local function process_chunk(surface, left_top) - if not surface then return end - if not surface.valid then return end - local planet = global.objective.planet + local objective = Chrono_table.get_table() + if not surface then return end + if not surface.valid then return end + local planet = objective.planet if planet[1].name.id == 17 then level_depth = 2176 end if left_top.x >= level_depth * 0.5 or left_top.y >= level_depth * 0.5 then return end if left_top.x < level_depth * -0.5 or left_top.y < level_depth * -0.5 then return end @@ -943,7 +952,7 @@ local function process_chunk(surface, left_top) --if left_top.y >= 0 then replace_water(surface, left_top) end --if left_top.y > 32 then game.forces.player.chart(surface, {{left_top.x, left_top.y},{left_top.x + 31, left_top.y + 31}}) end -- if left_top.y == -128 and left_top.x == -128 then - -- local p = global.locomotive.position + -- local p = objective.locomotive.position -- for _, entity in pairs(surface.find_entities_filtered({area = {{p.x - 3, p.y - 4},{p.x + 3, p.y + 10}}, type = "simple-entity"})) do entity.destroy() end -- end diff --git a/maps/chronosphere/terrain_specials.lua b/maps/chronosphere/terrain_specials.lua index 61c34202..bb0e5d18 100644 --- a/maps/chronosphere/terrain_specials.lua +++ b/maps/chronosphere/terrain_specials.lua @@ -1,6 +1,9 @@ +local Chrono_table = require 'maps.chronosphere.table' + local Public_terrain = {} function Public_terrain.danger_event(surface, left_top) + local objective = Chrono_table.get_table() local silo = surface.create_entity({name = "rocket-silo", force = "enemy", position = {x = left_top.x + 16, y = left_top.y + 16}}) local pole = surface.create_entity({name = "medium-electric-pole", position = {x = left_top.x + 12, y = left_top.y + 11}, force = "scrapyard", create_build_effect_smoke = false}) local silo_text = rendering.draw_text{ @@ -52,10 +55,11 @@ function Public_terrain.danger_event(surface, left_top) pole.destructible = false acu.destructible = false - global.objective.dangers[#global.objective.dangers + 1] = {silo = silo, speaker = speaker, combinator = combinator, solar = solar,acu = acu, pole = pole, destroyed = false, text = silo_text, timer = countdown_text} + objective.dangers[#objective.dangers + 1] = {silo = silo, speaker = speaker, combinator = combinator, solar = solar,acu = acu, pole = pole, destroyed = false, text = silo_text, timer = countdown_text} end function Public_terrain.fish_market(surface, left_top) + local objective = Chrono_table.get_table() local market = surface.create_entity({name = "market", force = "player", position = {x = left_top.x + 16, y = left_top.y + 16}}) market.destructible = false market.operable = false @@ -65,7 +69,7 @@ function Public_terrain.fish_market(surface, left_top) surface = surface, target = market, target_offset = {0, -2.5}, - color = global.locomotive.color, + color = objective.locomotive.color, scale = 1.00, font = "default-game", alignment = "center", @@ -75,13 +79,13 @@ function Public_terrain.fish_market(surface, left_top) fishchest.destructible = false fishchest.minable = false fishchest.operable = false - global.fishchest = fishchest + objective.fishchest = fishchest local repair_text = rendering.draw_text{ text = "Deposit fish here", surface = surface, target = fishchest, target_offset = {0, -2.5}, - color = global.locomotive.color, + color = objective.locomotive.color, scale = 0.75, font = "default-game", alignment = "center", diff --git a/maps/chronosphere/tick_functions.lua b/maps/chronosphere/tick_functions.lua index 3d63ad79..4a014ead 100644 --- a/maps/chronosphere/tick_functions.lua +++ b/maps/chronosphere/tick_functions.lua @@ -1,3 +1,4 @@ +local Chrono_table = require 'maps.chronosphere.table' local Public_tick = {} local math_random = math.random @@ -6,7 +7,7 @@ local math_ceil = math.ceil local math_min = math.min function Public_tick.check_chronoprogress() - local objective = global.objective + local objective = Chrono_table.get_table() if objective.planet[1].name.id == 19 then if objective.passivetimer == 10 then game.print({"chronosphere.message_danger1"}, {r=0.98, g=0.66, b=0.22}) @@ -33,12 +34,12 @@ function Public_tick.check_chronoprogress() end function Public_tick.charge_chronosphere() - if not global.acumulators then return end - local objective = global.objective + local objective = Chrono_table.get_table() + if not objective.acumulators then return end if not objective.chronotimer then return end if objective.chronotimer < 20 then return end if objective.planet[1].name.id == 17 or objective.planet[1].name.id == 19 then return end - local acus = global.acumulators + local acus = objective.acumulators if #acus < 1 then return end for i = 1, #acus, 1 do if not acus[i].valid then return end @@ -46,35 +47,37 @@ function Public_tick.charge_chronosphere() if energy > 3010000 and objective.chronotimer < objective.chrononeeds - 182 and objective.chronotimer > 130 then acus[i].energy = acus[i].energy - 3000000 objective.chronotimer = objective.chronotimer + 1 - game.surfaces[global.active_surface_index].pollute(global.locomotive.position, (10 + 2 * objective.chronojumps) * (4 / (objective.upgrades[2] / 2 + 1)) * global.difficulty_vote_value) + game.surfaces[objective.active_surface_index].pollute(objective.locomotive.position, (10 + 2 * objective.chronojumps) * (4 / (objective.upgrades[2] / 2 + 1)) * objective.difficulty_vote_value) end end end function Public_tick.transfer_pollution() + local objective = Chrono_table.get_table() local surface = game.surfaces["cargo_wagon"] if not surface then return end - local pollution = surface.get_total_pollution() * (3 / (global.objective.upgrades[2] / 3 + 1)) * global.difficulty_vote_value - game.surfaces[global.active_surface_index].pollute(global.locomotive.position, pollution) + local pollution = surface.get_total_pollution() * (3 / (objective.upgrades[2] / 3 + 1)) * objective.difficulty_vote_value + game.surfaces[objective.active_surface_index].pollute(objective.locomotive.position, pollution) surface.clear_pollution() end function Public_tick.boost_evolution() - local objective = global.objective + local objective = Chrono_table.get_table() if objective.passivetimer > objective.chrononeeds * 0.50 and objective.chronojumps > 5 then local evolution = game.forces.enemy.evolution_factor - evolution = evolution + (evolution / 500) * global.difficulty_vote_value + evolution = evolution + (evolution / 500) * objective.difficulty_vote_value if evolution > 1 then evolution = 1 end game.forces.enemy.evolution_factor = evolution end end function Public_tick.move_items() - if not global.comfychests then return end - if not global.comfychests2 then return end - if global.objective.game_lost == true then return end - local input = global.comfychests - local output = global.comfychests2 + local objective = Chrono_table.get_table() + if not objective.comfychests then return end + if not objective.comfychests2 then return end + if objective.game_lost == true then return end + local input = objective.comfychests + local output = objective.comfychests2 for i = 1, 24, 1 do if not input[i].valid then return end if not output[i].valid then return end @@ -93,18 +96,19 @@ function Public_tick.move_items() end function Public_tick.output_items() - if global.objective.game_lost == true then return end - if not global.outchests then return end - if not global.locomotive_cargo[2] then return end - if not global.locomotive_cargo[3] then return end - if global.objective.upgrades[8] ~= 1 then return end + local objective = Chrono_table.get_table() + if objective.game_lost == true then return end + if not objective.outchests then return end + if not objective.locomotive_cargo[2] then return end + if not objective.locomotive_cargo[3] then return end + if objective.upgrades[8] ~= 1 then return end local wagon = { - [1] = global.locomotive_cargo[2].get_inventory(defines.inventory.cargo_wagon), - [2] = global.locomotive_cargo[3].get_inventory(defines.inventory.cargo_wagon) + [1] = objective.locomotive_cargo[2].get_inventory(defines.inventory.cargo_wagon), + [2] = objective.locomotive_cargo[3].get_inventory(defines.inventory.cargo_wagon) } for i = 1, 4, 1 do - if not global.outchests[i].valid then return end - local inv = global.outchests[i].get_inventory(defines.inventory.chest) + if not objective.outchests[i].valid then return end + local inv = objective.outchests[i].get_inventory(defines.inventory.chest) inv.sort_and_merge() for ii = 1, #inv, 1 do if inv[ii].valid_for_read then @@ -116,11 +120,11 @@ function Public_tick.output_items() end function Public_tick.repair_train() - local objective = global.objective + local objective = Chrono_table.get_table() if not game.surfaces["cargo_wagon"] then return 0 end if objective.game_lost == true then return 0 end local count = 0 - local inv = global.upgradechest[0].get_inventory(defines.inventory.chest) + local inv = objective.upgradechest[0].get_inventory(defines.inventory.chest) if objective.health < objective.max_health then count = inv.get_item_count("repair-pack") count = math_min(count, objective.upgrades[6] + 1, math_ceil((objective.max_health - objective.health) / 150)) @@ -130,7 +134,8 @@ function Public_tick.repair_train() end function Public_tick.spawn_poison() - local surface = game.surfaces[global.active_surface_index] + local objective = Chrono_table.get_table() + local surface = game.surfaces[objective.active_surface_index] local random_x = math_random(-460,460) local random_y = math_random(-460,460) local tile = surface.get_tile(random_x, random_y) @@ -145,13 +150,13 @@ function Public_tick.spawn_poison() end local function launch_nukes() - local surface = game.surfaces[global.active_surface_index] - local objective = global.objective + local objective = Chrono_table.get_table() + local surface = game.surfaces[objective.active_surface_index] if objective.dangers and #objective.dangers > 1 then for i = 1, #objective.dangers, 1 do if objective.dangers[i].destroyed == false then local fake_shooter = surface.create_entity({name = "character", position = objective.dangers[i].silo.position, force = "enemy"}) - surface.create_entity({name = "atomic-rocket", position = objective.dangers[i].silo.position, force = "enemy", speed = 1, max_range = 800, target = global.locomotive, source = fake_shooter}) + surface.create_entity({name = "atomic-rocket", position = objective.dangers[i].silo.position, force = "enemy", speed = 1, max_range = 800, target = objective.locomotive, source = fake_shooter}) game.print({"chronosphere.message_nuke"}, {r=0.98, g=0, b=0}) end end @@ -159,7 +164,7 @@ local function launch_nukes() end function Public_tick.dangertimer() - local objective = global.objective + local objective = Chrono_table.get_table() local timer = objective.dangertimer if timer == 0 then return end if objective.planet[1].name.id == 19 then @@ -188,11 +193,11 @@ function Public_tick.dangertimer() end function Public_tick.offline_players() - local objective = global.objective + local objective = Chrono_table.get_table() if objective.chronotimer > objective.chrononeeds - 182 or objective.passivetimer < 30 then return end local current_tick = game.tick local players = objective.offline_players - local surface = game.surfaces[global.active_surface_index] + local surface = game.surfaces[objective.active_surface_index] if #players > 0 then --log("nonzero offline players") local later = {} diff --git a/maps/chronosphere/treasure.lua b/maps/chronosphere/treasure.lua index 6c419feb..20775c5e 100644 --- a/maps/chronosphere/treasure.lua +++ b/maps/chronosphere/treasure.lua @@ -1,9 +1,11 @@ +local Chrono_table = require 'maps.chronosphere.table' local math_random = math.random local math_sqrt = math.sqrt local Public = {} function Public.treasure_chest(surface, position, container_name) + local objective = Chrono_table.get_table() local chest_raffle = {} local chest_loot = { @@ -164,7 +166,7 @@ function Public.treasure_chest(surface, position, container_name) {{name = "gun-turret", count = math_random(2,4)}, weight = 3, d_min = 0.2, d_max = 0.9}, } local jumps = 0 - if global.objective.chronojumps then jumps = global.objective.chronojumps end + if objective.chronojumps then jumps = objective.chronojumps end local distance_to_center = (jumps / 40) if distance_to_center > 1 then distance_to_center = 1 end diff --git a/maps/chronosphere/upgrade_list.lua b/maps/chronosphere/upgrade_list.lua index e7c7cc06..50b4fb83 100644 --- a/maps/chronosphere/upgrade_list.lua +++ b/maps/chronosphere/upgrade_list.lua @@ -1,3 +1,4 @@ +local Chrono_table = require 'maps.chronosphere.table' local Public = {} local math_floor = math.floor @@ -7,14 +8,14 @@ local math_abs = math.abs local math_ceil = math.ceil function Public.upgrades() - if not global.objective then global.objective = {} end - if not global.objective.upgrades then - global.objective.upgrades = {} + local objective = Chrono_table.get_table() + if not objective.upgrades then + objective.upgrades = {} for i = 1, 16, 1 do - global.objective.upgrades[i] = 0 + objective.upgrades[i] = 0 end end - if not global.difficulty_vote_value then global.difficulty_vote_value = 1 end + if not objective.difficulty_vote_value then objective.difficulty_vote_value = 1 end --Each upgrade is automatically added into gui. --name : visible name in gui (best if localized) @@ -29,10 +30,10 @@ function Public.upgrades() sprite = "recipe/locomotive", max_level = 36, message = {"chronosphere.upgrade_train_armor_message"}, - tooltip = {"chronosphere.upgrade_train_armor_tooltip", 36, global.objective.max_health}, - jump_limit = global.objective.upgrades[1], + tooltip = {"chronosphere.upgrade_train_armor_tooltip", 36, objective.max_health}, + jump_limit = objective.upgrades[1], cost = { - item1 = {name = "coin", tt = "item-name", sprite = "item/coin", count = 500 * (1 + global.objective.upgrades[1])}, + item1 = {name = "coin", tt = "item-name", sprite = "item/coin", count = 500 * (1 + objective.upgrades[1])}, item2 = {name = "copper-plate", tt = "item-name", sprite = "item/copper-plate", count = 1500}, } }, @@ -41,13 +42,13 @@ function Public.upgrades() sprite = "recipe/effectivity-module", max_level = 9, message = {"chronosphere.upgrade_filter_message"}, - tooltip = {"chronosphere.upgrade_filter_tooltip", math_floor(300/(global.objective.upgrades[2]/3+1) * global.difficulty_vote_value)}, - jump_limit = (1 + global.objective.upgrades[2]) * 3 or 0, + tooltip = {"chronosphere.upgrade_filter_tooltip", math_floor(300/(objective.upgrades[2]/3+1) * objective.difficulty_vote_value)}, + jump_limit = (1 + objective.upgrades[2]) * 3 or 0, cost = { item1 = {name = "coin", tt = "item-name", sprite = "item/coin", count = 5000}, - item2 = {name = "electronic-circuit", tt = "item-name", sprite = "item/electronic-circuit", count = math_min(1 + global.objective.upgrades[2], 3) * 500 + 500}, - item3 = {name = "advanced-circuit", tt = "item-name", sprite = "item/advanced-circuit", count = math_max(math_min(1 + global.objective.upgrades[2], 6) - 3, 0) * 500}, - item4 = {name = "processing-unit", tt = "item-name", sprite = "item/processing-unit", count = math_max(math_min(1 + global.objective.upgrades[2], 9) - 6, 0) * 500} + item2 = {name = "electronic-circuit", tt = "item-name", sprite = "item/electronic-circuit", count = math_min(1 + objective.upgrades[2], 3) * 500 + 500}, + item3 = {name = "advanced-circuit", tt = "item-name", sprite = "item/advanced-circuit", count = math_max(math_min(1 + objective.upgrades[2], 6) - 3, 0) * 500}, + item4 = {name = "processing-unit", tt = "item-name", sprite = "item/processing-unit", count = math_max(math_min(1 + objective.upgrades[2], 9) - 6, 0) * 500} } }, [3] = { @@ -56,10 +57,10 @@ function Public.upgrades() max_level = 24, message = {"chronosphere.upgrade_accumulators_message"}, tooltip = {"chronosphere.upgrade_accumulators_tooltip"}, - jump_limit = global.objective.upgrades[3], + jump_limit = objective.upgrades[3], cost = { - item1 = {name = "coin", tt = "item-name", sprite = "item/coin", count = 2000 * (1 + global.objective.upgrades[3] / 4)}, - item2 = {name = "battery", tt = "item-name", sprite = "item/battery", count = 100 * (1 + global.objective.upgrades[3])} + item1 = {name = "coin", tt = "item-name", sprite = "item/coin", count = 2000 * (1 + objective.upgrades[3] / 4)}, + item2 = {name = "battery", tt = "item-name", sprite = "item/battery", count = 100 * (1 + objective.upgrades[3])} } }, [4] = { @@ -67,10 +68,10 @@ function Public.upgrades() sprite = "recipe/long-handed-inserter", max_level = 4, message = {"chronosphere.upgrade_loot_pickup_message"}, - tooltip = {"chronosphere.upgrade_loot_pickup_tooltip", global.objective.upgrades[4]}, + tooltip = {"chronosphere.upgrade_loot_pickup_tooltip", objective.upgrades[4]}, jump_limit = 0, cost = { - item1 = {name = "coin", tt = "item-name", sprite = "item/coin", count = 1000 * (1 + global.objective.upgrades[4])}, + item1 = {name = "coin", tt = "item-name", sprite = "item/coin", count = 1000 * (1 + objective.upgrades[4])}, item2 = {name = "long-handed-inserter", tt = "entity-name", sprite = "recipe/long-handed-inserter", count = 400} } }, @@ -80,13 +81,13 @@ function Public.upgrades() max_level = 4, message = {"chronosphere.upgrade_inventory_size_message"}, tooltip = {"chronosphere.upgrade_inventory_size_tooltip"}, - jump_limit = (1 + global.objective.upgrades[5]) * 5, + jump_limit = (1 + objective.upgrades[5]) * 5, cost = { - item1 = {name = "coin", tt = "item-name", sprite = "item/coin", count = 2500 * (1 + global.objective.upgrades[5])}, - item2 = {name = "wooden-chest", tt = "entity-name", sprite = "item/wooden-chest", count = math_max(0, 250 - math_abs(global.objective.upgrades[5]) * 250)}, - item3 = {name = "iron-chest", tt = "entity-name", sprite = "item/iron-chest", count = math_max(0, 250 - math_abs(global.objective.upgrades[5] - 1) * 250)}, - item4 = {name = "steel-chest", tt = "entity-name", sprite = "item/steel-chest", count = math_max(0, 250 - math_abs(global.objective.upgrades[5] - 2) * 250)}, - item5 = {name = "logistic-chest-storage", tt = "entity-name", sprite = "item/logistic-chest-storage", count = math_max(0, 250 - math_abs(global.objective.upgrades[5] - 3) * 250)} + item1 = {name = "coin", tt = "item-name", sprite = "item/coin", count = 2500 * (1 + objective.upgrades[5])}, + item2 = {name = "wooden-chest", tt = "entity-name", sprite = "item/wooden-chest", count = math_max(0, 250 - math_abs(objective.upgrades[5]) * 250)}, + item3 = {name = "iron-chest", tt = "entity-name", sprite = "item/iron-chest", count = math_max(0, 250 - math_abs(objective.upgrades[5] - 1) * 250)}, + item4 = {name = "steel-chest", tt = "entity-name", sprite = "item/steel-chest", count = math_max(0, 250 - math_abs(objective.upgrades[5] - 2) * 250)}, + item5 = {name = "logistic-chest-storage", tt = "entity-name", sprite = "item/logistic-chest-storage", count = math_max(0, 250 - math_abs(objective.upgrades[5] - 3) * 250)} } }, [6] = { @@ -94,11 +95,11 @@ function Public.upgrades() sprite = "recipe/repair-pack", max_level = 4, message = {"chronosphere.upgrade_repair_message"}, - tooltip = {"chronosphere.upgrade_repair_tooltip", global.objective.upgrades[6]}, + tooltip = {"chronosphere.upgrade_repair_tooltip", objective.upgrades[6]}, jump_limit = 0, cost = { - item1 = {name = "coin", tt = "item-name", sprite = "item/coin", count = 1000 * (1 + global.objective.upgrades[6])}, - item2 = {name = "repair-pack", tt = "item-name", sprite = "recipe/repair-pack", count = 200 * (1 + global.objective.upgrades[6])} + item1 = {name = "coin", tt = "item-name", sprite = "item/coin", count = 1000 * (1 + objective.upgrades[6])}, + item2 = {name = "repair-pack", tt = "item-name", sprite = "recipe/repair-pack", count = 200 * (1 + objective.upgrades[6])} } }, [7] = { @@ -132,13 +133,13 @@ function Public.upgrades() max_level = 4, message = {"chronosphere.upgrade_storage_message"}, tooltip = {"chronosphere.upgrade_storage_tooltip"}, - jump_limit = (1 + global.objective.upgrades[9]) * 5, + jump_limit = (1 + objective.upgrades[9]) * 5, cost = { - item1 = {name = "coin", tt = "item-name", sprite = "item/coin", count = 2500 * (1 + global.objective.upgrades[9])}, - item2 = {name = "wooden-chest", tt = "entity-name", sprite = "item/wooden-chest", count = math_max(0, 250 - math_abs(global.objective.upgrades[9]) * 250)}, - item3 = {name = "iron-chest", tt = "entity-name", sprite = "item/iron-chest", count = math_max(0, 250 - math_abs(global.objective.upgrades[9] - 1) * 250)}, - item4 = {name = "steel-chest", tt = "entity-name", sprite = "item/steel-chest", count = math_max(0, 250 - math_abs(global.objective.upgrades[9] - 2) * 250)}, - item5 = {name = "logistic-chest-storage", tt = "entity-name", sprite = "item/logistic-chest-storage", count = math_max(0, 250 - math_abs(global.objective.upgrades[9] - 3) * 250)} + item1 = {name = "coin", tt = "item-name", sprite = "item/coin", count = 2500 * (1 + objective.upgrades[9])}, + item2 = {name = "wooden-chest", tt = "entity-name", sprite = "item/wooden-chest", count = math_max(0, 250 - math_abs(objective.upgrades[9]) * 250)}, + item3 = {name = "iron-chest", tt = "entity-name", sprite = "item/iron-chest", count = math_max(0, 250 - math_abs(objective.upgrades[9] - 1) * 250)}, + item4 = {name = "steel-chest", tt = "entity-name", sprite = "item/steel-chest", count = math_max(0, 250 - math_abs(objective.upgrades[9] - 2) * 250)}, + item5 = {name = "logistic-chest-storage", tt = "entity-name", sprite = "item/logistic-chest-storage", count = math_max(0, 250 - math_abs(objective.upgrades[9] - 3) * 250)} } }, [10] = { @@ -146,7 +147,7 @@ function Public.upgrades() sprite = "recipe/poison-capsule", max_level = 4, message = {"chronosphere.upgrade_poison_message"}, - tooltip = {"chronosphere.upgrade_poison_tooltip", math_ceil(global.objective.poisontimeout /6)}, + tooltip = {"chronosphere.upgrade_poison_tooltip", math_ceil(objective.poisontimeout /6)}, jump_limit = 0, cost = { item1 = {name = "coin", tt = "item-name", sprite = "item/coin", count = 1000}, @@ -209,7 +210,7 @@ function Public.upgrades() name = {"chronosphere.upgrade_computer3"}, sprite = "item/rocket-control-unit", max_level = 10, - message = {"chronosphere.upgrade_computer3_message", global.objective.upgrades[15] + 1}, + message = {"chronosphere.upgrade_computer3_message", objective.upgrades[15] + 1}, tooltip = {"chronosphere.upgrade_computer3_tooltip"}, jump_limit = 25, cost = { diff --git a/maps/chronosphere/upgrades.lua b/maps/chronosphere/upgrades.lua index 3f9e4861..3fbc1ef5 100644 --- a/maps/chronosphere/upgrades.lua +++ b/maps/chronosphere/upgrades.lua @@ -1,24 +1,24 @@ - +local Chrono_table = require 'maps.chronosphere.table' local Public = {} local math_floor = math.floor local Server = require 'utils.server' local Upgrades = require "maps.chronosphere.upgrade_list" local function check_win() - local objective = global.objective - if global.fishchest then - if global.fishchest.valid then - local inv = global.fishchest.get_inventory(defines.inventory.chest) + local objective = Chrono_table.get_table() + if objective.fishchest then + if objective.fishchest.valid then + local inv = objective.fishchest.get_inventory(defines.inventory.chest) local countfish = inv.get_item_count("raw-fish") - local enemies = game.surfaces[global.active_surface_index].count_entities_filtered{force = "enemy"} + local enemies = game.surfaces[objective.active_surface_index].count_entities_filtered{force = "enemy"} if countfish > 0 then inv.remove({name = "raw-fish", count = countfish}) objective.mainscore = objective.mainscore + countfish if enemies > 0 then game.print("Comfylatron: You delivered fish, but there is still " .. enemies .. " enemies left. Kill them all so fish are safe!", {r=0.98, g=0.66, b=0.22}) else - if not global.game_reset_tick then - global.game_reset_tick = game.tick + 18000 + if not objective.game_reset_tick then + objective.game_reset_tick = game.tick + 18000 objective.game_won = true objective.game_lost = true objective.chronotimer = 200000000 - 300 @@ -39,14 +39,16 @@ local function check_win() end local function upgrade_hp() - global.objective.max_health = 10000 + 2500 * global.objective.upgrades[1] - rendering.set_text(global.objective.health_text, "HP: " .. global.objective.health .. " / " .. global.objective.max_health) + local objective = Chrono_table.get_table() + objective.max_health = 10000 + 2500 * objective.upgrades[1] + rendering.set_text(objective.health_text, "HP: " .. objective.health .. " / " .. objective.max_health) end local function spawn_acumulators() + local objective = Chrono_table.get_table() local x = -28 local y = -252 - local yy = global.objective.upgrades[3] * 2 + local yy = objective.upgrades[3] * 2 local surface = game.surfaces["cargo_wagon"] if yy > 8 then yy = yy + 2 end if yy > 26 then yy = yy + 2 end @@ -55,7 +57,7 @@ local function spawn_acumulators() local acumulator = surface.create_entity({name = "accumulator", position = {x + 2 * i, y + yy}, force="player", create_build_effect_smoke = false}) acumulator.minable = false acumulator.destructible = false - table.insert(global.acumulators, acumulator) + table.insert(objective.acumulators, acumulator) end end @@ -78,20 +80,21 @@ local function upgrade_water() end local function upgrade_out() + local objective = Chrono_table.get_table() if not game.surfaces["cargo_wagon"] then return end - local positions = {{-16,-62},{15,-62},{-16,66},{15,66}} + local positions = {{-16,-62},{15,-62},{-16,66},{15,66}} local out = {} for i = 1, 4, 1 do local e = game.surfaces["cargo_wagon"].create_entity({name = "steel-chest", position = positions[i], force = "player"}) e.destructible = false e.minable = false - global.outchests[i] = e + objective.outchests[i] = e out[i] = rendering.draw_text{ text = "Output", surface = e.surface, target = e, target_offset = {0, -1.5}, - color = global.locomotive.color, + color = objective.locomotive.color, scale = 0.80, font = "default-game", alignment = "center", @@ -101,7 +104,7 @@ local function upgrade_out() end local function upgrade_storage() - local objective = global.objective + local objective = Chrono_table.get_table() if not game.surfaces["cargo_wagon"] then return end local chests = {} local positions = {x = {-33, 32}, y = {-189, -127, -61, 1, 67, 129}} @@ -144,21 +147,22 @@ local function upgrade_storage() end local function fusion_buy() - local objective = global.objective - if global.upgradechest[11] and global.upgradechest[11].valid then - local inv = global.upgradechest[14].get_inventory(defines.inventory.chest) + local objective = Chrono_table.get_table() + if objective.upgradechest[11] and objective.upgradechest[11].valid then + local inv = objective.upgradechest[14].get_inventory(defines.inventory.chest) inv.insert({name = "fusion-reactor-equipment", count = 1}) end end local function mk2_buy() - local objective = global.objective - if global.upgradechest[13] and global.upgradechest[13].valid then + local objective = Chrono_table.get_table() + if objective.upgradechest[13] and objective.upgradechest[13].valid then inv.insert({name = "power-armor-mk2", count = 1}) end end local function process_upgrade(index) + local objective = Chrono_table.get_table() if index == 1 then upgrade_hp() elseif index == 3 then @@ -178,28 +182,29 @@ local function process_upgrade(index) elseif index == 12 then mk2_buy() elseif index == 13 then - global.objective.computermessage = 2 + objective.computermessage = 2 elseif index == 14 then - global.objective.computermessage = 4 + objective.computermessage = 4 elseif index == 15 then - if global.objective.upgrades[15] == 10 then + if objective.upgrades[15] == 10 then game.print({"chronosphere.message_quest6"}, {r=0.98, g=0.66, b=0.22}) end end end local function check_single_upgrade(index) + local objective = Chrono_table.get_table() local upgrades = Upgrades.upgrades() - if global.upgradechest[index] and global.upgradechest[index].valid then - if index == 14 and (global.objective.upgrades[13] ~= 1 or global.objective.computermessage ~= 3) then + if objective.upgradechest[index] and objective.upgradechest[index].valid then + if index == 14 and (objective.upgrades[13] ~= 1 or objective.computermessage ~= 3) then return - elseif index == 15 and (global.objective.upgrades[14] ~= 1 or global.objective.computermessage ~= 5) then + elseif index == 15 and (objective.upgrades[14] ~= 1 or objective.computermessage ~= 5) then return - elseif index == 16 and global.objective.upgrades[15] ~= 10 then + elseif index == 16 and objective.upgrades[15] ~= 10 then return end - local inv = global.upgradechest[index].get_inventory(defines.inventory.chest) - if global.objective.upgrades[index] < upgrades[index].max_level and global.objective.chronojumps >= upgrades[index].jump_limit then + local inv = objective.upgradechest[index].get_inventory(defines.inventory.chest) + if objective.upgrades[index] < upgrades[index].max_level and objective.chronojumps >= upgrades[index].jump_limit then for _, item in pairs(upgrades[index].cost) do if inv.get_item_count(item.name) < item.count then return end end @@ -212,7 +217,7 @@ local function check_single_upgrade(index) inv.remove({name = item.name, count = item.count}) end end - global.objective.upgrades[index] = global.objective.upgrades[index] + 1 + objective.upgrades[index] = objective.upgrades[index] + 1 game.print(upgrades[index].message, {r=0.98, g=0.66, b=0.22}) process_upgrade(index) end @@ -226,32 +231,31 @@ local function check_all_upgrades() end function Public.check_upgrades() - local objective = global.objective - if not global.upgradechest then return end + local objective = Chrono_table.get_table() + if not objective.upgradechest then return end if objective.game_lost == true then return end check_all_upgrades() if objective.planet[1].name.id == 17 then - if global.fishchest then + if objective.fishchest then check_win() end end end function Public.trigger_poison() - local objective = global.objective + local objective = Chrono_table.get_table() if objective.game_lost then return end if objective.upgrades[10] > 0 and objective.poisontimeout == 0 then - local objective = global.objective objective.upgrades[10] = objective.upgrades[10] - 1 objective.poisontimeout = 120 - local objs = {global.locomotive, global.locomotive_cargo[1], global.locomotive_cargo[2], global.locomotive_cargo[3]} + local objs = {objective.locomotive, objective.locomotive_cargo[1], objective.locomotive_cargo[2], objective.locomotive_cargo[3]} local surface = objective.surface game.print({"chronosphere.message_poison_defense"}, {r=0.98, g=0.66, b=0.22}) for i = 1, 4, 1 do surface.create_entity({name = "poison-capsule", position = objs[i].position, force = "player", target = objs[i], speed = 1 }) end - for i = 1 , #global.comfychests, 1 do - surface.create_entity({name = "poison-capsule", position = global.comfychests[i].position, force = "player", target = global.comfychests[i], speed = 1 }) + for i = 1 , #objective.comfychests, 1 do + surface.create_entity({name = "poison-capsule", position = objective.comfychests[i].position, force = "player", target = objective.comfychests[i], speed = 1 }) end end end