You've already forked ComfyFactorio
							
							
				mirror of
				https://github.com/ComfyFactory/ComfyFactorio.git
				synced 2025-10-30 23:47:41 +02:00 
			
		
		
		
	Mtn v3 - fix changes
This commit is contained in:
		| @@ -20,18 +20,32 @@ function Public.init_enemy_weapon_damage() | ||||
|     } | ||||
|  | ||||
|     local e = game.forces.enemy | ||||
|     local a = game.forces.aggressors | ||||
|     local af = game.forces.aggressors_frenzy | ||||
|  | ||||
|     e.technologies['refined-flammables-1'].researched = true | ||||
|     e.technologies['refined-flammables-2'].researched = true | ||||
|     e.technologies['energy-weapons-damage-1'].researched = true | ||||
|  | ||||
|     a.technologies['refined-flammables-1'].researched = true | ||||
|     a.technologies['refined-flammables-2'].researched = true | ||||
|     a.technologies['energy-weapons-damage-1'].researched = true | ||||
|  | ||||
|     af.technologies['refined-flammables-1'].researched = true | ||||
|     af.technologies['refined-flammables-2'].researched = true | ||||
|     af.technologies['energy-weapons-damage-1'].researched = true | ||||
|  | ||||
|     for k, v in pairs(data) do | ||||
|         e.set_ammo_damage_modifier(k, v) | ||||
|         a.set_ammo_damage_modifier(k, v) | ||||
|         af.set_ammo_damage_modifier(k, v) | ||||
|     end | ||||
| end | ||||
|  | ||||
| function Public.enemy_weapon_damage() | ||||
|     local e = game.forces.enemy | ||||
|     local a = game.forces.aggressors | ||||
|     local af = game.forces.aggressors_frenzy | ||||
|  | ||||
|     local data = { | ||||
|         ['artillery-shell'] = 0.05, | ||||
| @@ -50,8 +64,12 @@ function Public.enemy_weapon_damage() | ||||
|         local new = Difficulty.get().value * v | ||||
|  | ||||
|         local e_old = e.get_ammo_damage_modifier(k) | ||||
|         local a_old = a.get_ammo_damage_modifier(k) | ||||
|         local af_old = af.get_ammo_damage_modifier(k) | ||||
|  | ||||
|         e.set_ammo_damage_modifier(k, new + e_old) | ||||
|         a.set_ammo_damage_modifier(k, new + a_old) | ||||
|         af.set_ammo_damage_modifier(k, new + af_old) | ||||
|     end | ||||
| end | ||||
|  | ||||
|   | ||||
| @@ -1215,6 +1215,7 @@ local function show_mvps(player) | ||||
|             end | ||||
|             local time_played = Core.format_time(game.ticks_played) | ||||
|             local total_players = #game.players | ||||
|             local total_connected_players = #game.connected_players | ||||
|             local pickaxe_upgrades = Public.pickaxe_upgrades | ||||
|             local upgrades = Public.get('upgrades') | ||||
|             local pick_tier = pickaxe_upgrades[upgrades.pickaxe_tier] | ||||
| @@ -1265,6 +1266,11 @@ local function show_mvps(player) | ||||
|                 field7 = { | ||||
|                     text1 = 'Collapse Amount:', | ||||
|                     text2 = collapse_amount, | ||||
|                     inline = 'true' | ||||
|                 }, | ||||
|                 field8 = { | ||||
|                     text1 = 'Connected players:', | ||||
|                     text2 = total_connected_players, | ||||
|                     inline = 'true', | ||||
|                     emptyField = 'true', | ||||
|                     emptyInline = 'true' | ||||
|   | ||||
| @@ -1137,9 +1137,14 @@ end | ||||
| function Public.set_spawn_position() | ||||
|     local collapse_pos = Collapse.get_position() | ||||
|     local locomotive = Public.get('locomotive') | ||||
|     local final_battle = Public.get('final_battle') | ||||
|     if final_battle then | ||||
|         return | ||||
|     end | ||||
|     if not locomotive or not locomotive.valid then | ||||
|         return | ||||
|     end | ||||
|     --TODO check if final battle | ||||
|     local l = locomotive.position | ||||
|  | ||||
|     local retries = 0 | ||||
|   | ||||
| @@ -115,6 +115,22 @@ local reconstruct_all_trains = | ||||
|     end | ||||
| ) | ||||
|  | ||||
| local remove_non_migrated_doors_token = | ||||
|     Token.register( | ||||
|     function(data) | ||||
|         local icw = data.icw | ||||
|         for _, unit_data in pairs(icw.wagons) do | ||||
|             if not unit_data.migrated then | ||||
|                 for _, door in pairs(unit_data.doors) do | ||||
|                     if door and door.valid then | ||||
|                         door.destroy() | ||||
|                     end | ||||
|                 end | ||||
|             end | ||||
|         end | ||||
|     end | ||||
| ) | ||||
|  | ||||
| local function get_tile_name() | ||||
|     -- local main_tile_name = 'tutorial-grid' | ||||
|     -- local main_tile_name = 'stone-path' | ||||
| @@ -703,10 +719,12 @@ function Public.migrate_wagon(icw, source, target) | ||||
|         if unit_number == source_wagon then | ||||
|             unit_data.surface.name = tostring(target_wagon) | ||||
|             unit_data.entity = target | ||||
|             unit_data.migrated = true | ||||
|             icw.wagons[target_wagon] = deepcopy(unit_data) | ||||
|             return icw.wagons[target_wagon] | ||||
|         end | ||||
|     end | ||||
|  | ||||
|     Task.set_timeout_in_ticks(100, remove_non_migrated_doors_token, {icw = icw}) | ||||
| end | ||||
|  | ||||
| function Public.use_cargo_wagon_door_with_entity(icw, player, door) | ||||
| @@ -954,6 +972,11 @@ function Public.construct_train(icw, locomotive, carriages) | ||||
| end | ||||
|  | ||||
| function Public.reconstruct_all_trains(icw) | ||||
|     local final_battle = WPT.get('final_battle') | ||||
|     if final_battle then | ||||
|         return | ||||
|     end | ||||
|  | ||||
|     icw.trains = {} | ||||
|     for unit_number, wagon in pairs(icw.wagons) do | ||||
|         if not validate_entity(wagon.entity) then | ||||
|   | ||||
| @@ -2,6 +2,7 @@ local Server = require 'utils.server' | ||||
| local Session = require 'utils.datastore.session_data' | ||||
| local Modifers = require 'utils.player_modifiers' | ||||
| local Public = require 'maps.mountain_fortress_v3.table' | ||||
| local Event = require 'utils.event' | ||||
|  | ||||
| local mapkeeper = '[color=blue]Mapkeeper:[/color]' | ||||
|  | ||||
| @@ -48,7 +49,7 @@ local function teleport_players(surface) | ||||
| end | ||||
|  | ||||
| local function equip_players(player_starting_items, data) | ||||
|     for k, player in pairs(game.players) do | ||||
|     for _, player in pairs(game.players) do | ||||
|         if player.character and player.character.valid then | ||||
|             player.character.destroy() | ||||
|         end | ||||
| @@ -72,6 +73,55 @@ local function equip_players(player_starting_items, data) | ||||
|     end | ||||
| end | ||||
|  | ||||
| local function add_step(this) | ||||
|     if this.schedule_step ~= this.schedule_max_step then | ||||
|         this.schedule_step = this.schedule_step + 1 | ||||
|     end | ||||
| end | ||||
|  | ||||
| local function scheduled_surface_clearing() | ||||
|     local this = Public.get() | ||||
|     if not this.initial_tick then | ||||
|         return | ||||
|     end | ||||
|  | ||||
|     if this.initial_tick > game.tick then | ||||
|         return | ||||
|     end | ||||
|     local step = this.schedule_step | ||||
|     local schedule = this.schedule | ||||
|     if schedule[step] then | ||||
|         local surface = schedule[step].surface | ||||
|         if not surface.valid then | ||||
|             schedule[step] = nil | ||||
|             add_step(this) | ||||
|             return | ||||
|         end | ||||
|         if schedule[step].operation == 'player_clearing' then | ||||
|             local ent = surface.find_entities_filtered {force = 'player', limit = 1000} | ||||
|             for _, e in pairs(ent) do | ||||
|                 if e.valid then | ||||
|                     e.destroy() | ||||
|                 end | ||||
|             end | ||||
|             schedule[step] = nil | ||||
|             add_step(this) | ||||
|         elseif schedule[step].operation == 'clear' then | ||||
|             surface.clear() | ||||
|             schedule[step] = nil | ||||
|             add_step(this) | ||||
|         elseif schedule[step].operation == 'delete' then | ||||
|             game.delete_surface(surface) | ||||
|             schedule[step] = nil | ||||
|             add_step(this) | ||||
|         elseif schedule[step].operation == 'done' then | ||||
|             game.print(mapkeeper .. ' Done clearing old surface.') | ||||
|             schedule[step] = nil | ||||
|             add_step(this) | ||||
|         end | ||||
|     end | ||||
| end | ||||
|  | ||||
| function Public.soft_reset_map(old_surface, map_gen_settings, player_starting_items) | ||||
|     local this = Public.get() | ||||
|  | ||||
| @@ -91,7 +141,7 @@ function Public.soft_reset_map(old_surface, map_gen_settings, player_starting_it | ||||
|     teleport_players(new_surface) | ||||
|     equip_players(player_starting_items, this) | ||||
|  | ||||
|     game.delete_surface(old_surface) | ||||
|     Public.add_schedule_to_delete_surface(true) | ||||
|  | ||||
|     local radius = 512 | ||||
|     local area = {{x = -radius, y = -radius}, {x = radius, y = radius}} | ||||
| @@ -123,4 +173,47 @@ function Public.soft_reset_map(old_surface, map_gen_settings, player_starting_it | ||||
|     return new_surface | ||||
| end | ||||
|  | ||||
| function Public.add_schedule_to_delete_surface(remove_surface) | ||||
|     local this = Public.get() | ||||
|     local surface = game.get_surface(this.active_surface_index) | ||||
|     if not surface or not surface.valid then | ||||
|         return | ||||
|     end | ||||
|  | ||||
|     game.print(mapkeeper .. ' Preparing to remove old entites and clearing surface - this might lag the server a bit.') | ||||
|  | ||||
|     local step = this.schedule_max_step | ||||
|  | ||||
|     if not step then | ||||
|         this.schedule_step = 0 | ||||
|         this.schedule_max_step = 0 | ||||
|         this.schedule = {} | ||||
|         this.initial_tick = 0 | ||||
|         step = this.schedule_max_step | ||||
|     end | ||||
|  | ||||
|     local add = 1 | ||||
|     local count_scrap = surface.count_entities_filtered {force = 'player'} | ||||
|     for _ = 1, count_scrap, 1000 do | ||||
|         this.schedule[step + add] = {operation = 'player_clearing', surface = surface} | ||||
|         add = add + 1 | ||||
|     end | ||||
|     this.schedule[step + add] = {operation = 'clear', surface = surface} | ||||
|     add = add + 1 | ||||
|     if remove_surface then | ||||
|         this.schedule[step + add] = {operation = 'delete', surface = surface} | ||||
|         add = add + 1 | ||||
|     end | ||||
|     this.schedule[step + add] = {operation = 'done', surface = surface} | ||||
|     this.schedule_max_step = this.schedule_max_step + add | ||||
|     if this.schedule_step == step then | ||||
|         this.schedule_step = this.schedule_step + 1 | ||||
|     end | ||||
|     if this.initial_tick <= game.tick then | ||||
|         this.initial_tick = game.tick + 500 | ||||
|     end | ||||
| end | ||||
|  | ||||
| Event.on_nth_tick(10, scheduled_surface_clearing) | ||||
|  | ||||
| return Public | ||||
|   | ||||
| @@ -33,6 +33,16 @@ function Public.blueprint() | ||||
|         return | ||||
|     end | ||||
|  | ||||
|     local spawners = surface.find_entities_filtered({type = 'unit-spawner', area = {{position.x - 70, position.y - 70}, {position.x + 70, position.y + 70}}}) | ||||
|     if #spawners == 0 then | ||||
|         return | ||||
|     end | ||||
|     for _, e in pairs(spawners) do | ||||
|         if e and e.valid then | ||||
|             e.destroy() | ||||
|         end | ||||
|     end | ||||
|  | ||||
|     local success = item.stack.import_stack(bp) | ||||
|     if success <= 0 then | ||||
|         local ghosts = item.stack.build_blueprint {surface = surface, force = 'player', position = position, force_build = true} | ||||
|   | ||||
| @@ -5,6 +5,7 @@ local Token = require 'utils.token' | ||||
| local Public = require 'maps.mountain_fortress_v3.stateful.table' | ||||
|  | ||||
| local ceil = math.ceil | ||||
| local random = math.random | ||||
| local queue_task = Task.queue_task | ||||
| local tiles_per_call = 8 | ||||
| local total_calls = ceil(1024 / tiles_per_call) | ||||
| @@ -212,10 +213,19 @@ local function do_place_entities(data) | ||||
|                     if e.direction then | ||||
|                         entity.direction = e.direction | ||||
|                     end | ||||
|                     if e.active ~= nil then | ||||
|                     if e.active ~= nil and e.random_active == nil then | ||||
|                         entity.active = e.active | ||||
|                     end | ||||
|                     if e.destructible ~= nil then | ||||
|                     if e.random_active ~= nil then | ||||
|                         if random(1, 10) == 1 then | ||||
|                             entity.active = true | ||||
|                             entity.destructible = true | ||||
|                         else | ||||
|                             entity.active = false | ||||
|                             entity.destructible = false | ||||
|                         end | ||||
|                     end | ||||
|                     if e.destructible ~= nil and e.random_active == nil then | ||||
|                         entity.destructible = e.destructible | ||||
|                     end | ||||
|                     if e.force then | ||||
|   | ||||
| @@ -8,7 +8,10 @@ local Task = require 'utils.task' | ||||
| local Core = require 'utils.core' | ||||
| local Server = require 'utils.server' | ||||
| local LinkedChests = require 'maps.mountain_fortress_v3.icw.linked_chests' | ||||
| local Discord = require 'utils.discord' | ||||
| local format_number = require 'util'.format_number | ||||
|  | ||||
| local send_ping_to_channel = Discord.channel_names.mtn_channel | ||||
| local main_button_name = Gui.uid_name() | ||||
| local main_frame_name = Gui.uid_name() | ||||
| local boss_frame_name = Gui.uid_name() | ||||
| @@ -61,6 +64,69 @@ local spread_particles_token = | ||||
|     end | ||||
| ) | ||||
|  | ||||
| local function notify_won_to_discord() | ||||
|     local server_name_matches = Server.check_server_name('Mtn Fortress') | ||||
|     if not server_name_matches then | ||||
|         return | ||||
|     end | ||||
|  | ||||
|     local stateful = Public.get_stateful() | ||||
|  | ||||
|     local wave = WD.get_wave() | ||||
|     local date = Server.get_start_time() | ||||
|     game.server_save('Complete_Mtn_v3_' .. tostring(date) .. '_wave' .. tostring(wave)) | ||||
|  | ||||
|     local threat = WD.get('threat') | ||||
|     local time_played = Core.format_time(game.ticks_played) | ||||
|     local total_players = #game.players | ||||
|     local total_connected_players = #game.connected_players | ||||
|     local pickaxe_upgrades = Public.pickaxe_upgrades | ||||
|     local upgrades = Public.get('upgrades') | ||||
|     local pick_tier = pickaxe_upgrades[upgrades.pickaxe_tier] | ||||
|  | ||||
|     local text = { | ||||
|         title = 'Game won!', | ||||
|         description = 'Game statistics from the game is below', | ||||
|         color = 'success', | ||||
|         field1 = { | ||||
|             text1 = 'Time played:', | ||||
|             text2 = time_played, | ||||
|             inline = 'true' | ||||
|         }, | ||||
|         field2 = { | ||||
|             text1 = 'Rounds survived:', | ||||
|             text2 = stateful.rounds_survived, | ||||
|             inline = 'true' | ||||
|         }, | ||||
|         field3 = { | ||||
|             text1 = 'Total connected players:', | ||||
|             text2 = total_players, | ||||
|             inline = 'true', | ||||
|             emptyField = 'true', | ||||
|             emptyInline = 'true' | ||||
|         }, | ||||
|         field4 = { | ||||
|             text1 = 'Threat:', | ||||
|             text2 = format_number(threat, true), | ||||
|             inline = 'true' | ||||
|         }, | ||||
|         field5 = { | ||||
|             text1 = 'Pickaxe Upgrade:', | ||||
|             text2 = pick_tier .. ' (' .. upgrades.pickaxe_tier .. ')', | ||||
|             inline = 'true' | ||||
|         }, | ||||
|         field6 = { | ||||
|             text1 = 'Connected players:', | ||||
|             text2 = total_connected_players, | ||||
|             inline = 'true', | ||||
|             emptyField = 'true', | ||||
|             emptyInline = 'true' | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     Server.to_discord_named_parsed_embed(send_ping_to_channel, text) | ||||
| end | ||||
|  | ||||
| local function clear_all_frames() | ||||
|     Core.iter_players( | ||||
|         function(player) | ||||
| @@ -181,7 +247,7 @@ local function objective_frames(stateful, player_frame, objective, data) | ||||
|         right_flow.style.horizontal_align = 'right' | ||||
|         right_flow.style.horizontally_stretchable = true | ||||
|  | ||||
|         if stateful.objectives_completed.supplies then | ||||
|         if stateful.objectives_completed.supplies or stateful.objectives_completed.single_item then | ||||
|             data.supply_completed = right_flow.add({type = 'label', caption = ' [img=utility/check_mark_green]', tooltip = {'stateful.tooltip_completed'}}) | ||||
|         else | ||||
|             data.supply_completed = right_flow.add({type = 'label', caption = ' [img=utility/not_available]', tooltip = {'stateful.tooltip_not_completed'}}) | ||||
| @@ -620,7 +686,8 @@ local function update_data() | ||||
|                         single_item.total = single_item.count | ||||
|                     end | ||||
|                     single_item.count = single_item.total - count | ||||
|                     if single_item.count == 0 then | ||||
|                     if single_item.count <= 0 then | ||||
|                         single_item.count = 0 | ||||
|                         frame.number = nil | ||||
|                         frame.sprite = 'utility/check_mark_green' | ||||
|                     else | ||||
| @@ -779,7 +846,8 @@ local function update_raw() | ||||
|                 single_item.total = single_item.count | ||||
|             end | ||||
|             single_item.count = single_item.total - count | ||||
|             if single_item.count == 0 then | ||||
|             if single_item.count <= 0 then | ||||
|                 single_item.count = 0 | ||||
|                 if not stateful.objectives_completed.single_item then | ||||
|                     stateful.objectives_completed.single_item = true | ||||
|                     play_achievement_unlocked() | ||||
| @@ -799,6 +867,8 @@ local function update_raw() | ||||
|             if not collection.nuke_blueprint then | ||||
|                 collection.nuke_blueprint = true | ||||
|                 Public.stateful_blueprints.nuke_blueprint() | ||||
|                 WD.disable_spawning_biters(false) | ||||
|                 Server.to_discord_embed('Final battle starts now!') | ||||
|                 refresh_boss_frame() | ||||
|             end | ||||
|         end | ||||
| @@ -832,8 +902,10 @@ local function update_raw() | ||||
|                 collection.game_won_notified = true | ||||
|                 refresh_boss_frame() | ||||
|                 play_game_won() | ||||
|                 Server.to_discord_embed('Game won!') | ||||
|                 stateful.rounds_survived = stateful.rounds_survived + 1 | ||||
|                 Public.stateful.save_settings() | ||||
|                 notify_won_to_discord() | ||||
|                 local locomotive = Public.get('locomotive') | ||||
|                 if locomotive and locomotive.valid then | ||||
|                     locomotive.surface.spill_item_stack(locomotive.position, {name = 'coin', count = 512}, false) | ||||
| @@ -871,6 +943,8 @@ local function update_raw() | ||||
|         stateful.collection.gather_time = tick + 54000 | ||||
|         stateful.collection.gather_time_timer = tick + 54000 | ||||
|         play_achievement_unlocked() | ||||
|         WD.disable_spawning_biters(true) | ||||
|         WD.nuke_wave_gui() | ||||
|  | ||||
|         Core.iter_connected_players( | ||||
|             function(player) | ||||
|   | ||||
| @@ -30,7 +30,7 @@ Event.add( | ||||
| ) | ||||
|  | ||||
| Event.on_nth_tick( | ||||
|     200, | ||||
|     100, | ||||
|     function() | ||||
|         local final_battle = Public.get_stateful('final_battle') | ||||
|         if not final_battle then | ||||
|   | ||||
| @@ -35,19 +35,22 @@ Global.register( | ||||
| ) | ||||
|  | ||||
| local stateful_spawn_points = { | ||||
|     {{x = -186, y = -170}, {x = 177, y = 119}}, | ||||
|     {{x = -190, y = -200}, {x = 160, y = -160}}, | ||||
|     {{x = -186, y = -150}, {x = 177, y = 119}}, | ||||
|     {{x = -190, y = -150}, {x = 160, y = -155}}, | ||||
|     {{x = -190, y = -0}, {x = 160, y = -0}}, | ||||
|     {{x = -186, y = -170}, {x = 177, y = 119}}, | ||||
|     {{x = -160, y = -200}, {x = 160, y = -160}}, | ||||
|     {{x = 160, y = -200}, {x = 190, y = -160}}, | ||||
|     {{x = -186, y = -150}, {x = 177, y = 119}}, | ||||
|     {{x = -160, y = -150}, {x = 160, y = -155}}, | ||||
|     {{x = 160, y = -150}, {x = 190, y = -155}}, | ||||
|     {{x = 160, y = 0}, {x = 190, y = 0}}, | ||||
|     {{x = -186, y = -170}, {x = 177, y = 119}}, | ||||
|     {{x = 160, y = -160}, {x = 190, y = 160}}, | ||||
|     {{x = 160, y = 160}, {x = 190, y = 200}}, | ||||
|     {{x = -160, y = 160}, {x = 160, y = 200}}, | ||||
|     {{x = -190, y = 160}, {x = -160, y = 200}}, | ||||
|     {{x = -190, y = -160}, {x = -160, y = 160}} | ||||
|     {{x = -186, y = -150}, {x = 177, y = 119}}, | ||||
|     {{x = 160, y = 0}, {x = -160, y = 0}}, | ||||
|     {{x = 160, y = -155}, {x = 190, y = 155}}, | ||||
|     {{x = 160, y = 155}, {x = 190, y = 150}}, | ||||
|     {{x = -160, y = 0}, {x = 160, y = 0}}, | ||||
|     {{x = -160, y = 155}, {x = 160, y = 150}}, | ||||
|     {{x = -190, y = 155}, {x = -160, y = 150}}, | ||||
|     {{x = -160, y = 0}, {x = 160, y = 0}}, | ||||
|     {{x = -190, y = -155}, {x = -160, y = 155}} | ||||
| } | ||||
|  | ||||
| local function get_random_buff() | ||||
| @@ -663,6 +666,7 @@ function Public.allocate() | ||||
|     if stateful_locomotive and not stateful_locomotive_migrated then | ||||
|         Task.set_timeout_in_ticks(100, move_all_players_token, {}) | ||||
|  | ||||
|         Public.soft_reset.add_schedule_to_delete_surface() | ||||
|         Public.set_stateful('stateful_locomotive_migrated', true) | ||||
|         local locomotive = Public.get('locomotive') | ||||
|         local icw_data = ICW.migrate_wagon(locomotive, stateful_locomotive) | ||||
| @@ -696,7 +700,7 @@ function Public.allocate() | ||||
|  | ||||
|         collection.time_until_attack = 54000 + game.tick | ||||
|         collection.time_until_attack_timer = 54000 + game.tick | ||||
|         collection.survive_for = collection.time_until_attack_timer + scale(random(18000, 54000), 216000) | ||||
|         collection.survive_for = collection.time_until_attack_timer + scale(random(54000, 108000), 324000) | ||||
|         collection.survive_for_timer = collection.survive_for | ||||
|  | ||||
|         Public.set_target(stateful_locomotive, icw_data) | ||||
|   | ||||
| @@ -152,7 +152,7 @@ local function border_chunk(p, data) | ||||
|             name = 'spitter-spawner' | ||||
|         end | ||||
|         if enemy_spawn_positions(p) then | ||||
|             entities[#entities + 1] = {name = name, position = pos, force = 'enemy', collision = true, active = false, destructible = false} | ||||
|             entities[#entities + 1] = {name = name, position = pos, force = 'enemy', collision = true, active = false, destructible = false, random_active = true} | ||||
|         end | ||||
|     end | ||||
|  | ||||
|   | ||||
| @@ -269,6 +269,11 @@ function Public.reset_main_table() | ||||
|         rocks_yield_ore_distance_modifier = 0.020 | ||||
|     } | ||||
|  | ||||
|     this.schedule_step = 0 | ||||
|     this.schedule_max_step = 0 | ||||
|     this.schedule = {} | ||||
|     this.initial_tick = 0 | ||||
|  | ||||
|     for k, _ in pairs(this.players) do | ||||
|         this.players[k] = {} | ||||
|     end | ||||
|   | ||||
| @@ -24,7 +24,7 @@ local directions = { | ||||
|         end | ||||
|  | ||||
|         local surface = game.get_surface(surface_index) | ||||
|         if not surface.valid then | ||||
|         if not surface or not surface.valid then | ||||
|             return | ||||
|         end | ||||
|         local width = surface.map_gen_settings.width | ||||
| @@ -42,7 +42,7 @@ local directions = { | ||||
|         end | ||||
|  | ||||
|         local surface = game.get_surface(surface_index) | ||||
|         if not surface.valid then | ||||
|         if not surface or not surface.valid then | ||||
|             return | ||||
|         end | ||||
|         local width = surface.map_gen_settings.width | ||||
| @@ -60,7 +60,7 @@ local directions = { | ||||
|         end | ||||
|  | ||||
|         local surface = game.get_surface(surface_index) | ||||
|         if not surface.valid then | ||||
|         if not surface or not surface.valid then | ||||
|             return | ||||
|         end | ||||
|         local width = surface.map_gen_settings.height | ||||
| @@ -78,7 +78,7 @@ local directions = { | ||||
|         end | ||||
|  | ||||
|         local surface = game.get_surface(surface_index) | ||||
|         if not surface.valid then | ||||
|         if not surface or not surface.valid then | ||||
|             return | ||||
|         end | ||||
|         local width = surface.map_gen_settings.height | ||||
| @@ -125,7 +125,7 @@ local function progress() | ||||
|     end | ||||
|  | ||||
|     local surface = game.get_surface(surface_index) | ||||
|     if not surface.valid then | ||||
|     if not surface or not surface.valid then | ||||
|         return | ||||
|     end | ||||
|  | ||||
| @@ -183,7 +183,7 @@ function Public.set_surface_index(surface_index) | ||||
|     end | ||||
|  | ||||
|     local surface = game.get_surface(surface_index) | ||||
|     if not surface.valid then | ||||
|     if not surface or not surface.valid then | ||||
|         print_debug(2) | ||||
|         return | ||||
|     end | ||||
|   | ||||
| @@ -1,4 +1,5 @@ | ||||
| local Global = require 'utils.global' | ||||
| local Core = require 'utils.core' | ||||
| local Event = require 'utils.event' | ||||
|  | ||||
| local this = {} | ||||
| @@ -427,6 +428,17 @@ function Public.disable_spawning_biters(boolean) | ||||
|     this.game_lost = boolean or false | ||||
| end | ||||
|  | ||||
| ---Removes the player wave defense gui | ||||
| function Public.nuke_wave_gui() | ||||
|     Core.iter_players( | ||||
|         function(player) | ||||
|             if player.gui.top.wave_defense and player.gui.top.wave_defense.valid then | ||||
|                 player.gui.top.wave_defense.destroy() | ||||
|             end | ||||
|         end | ||||
|     ) | ||||
| end | ||||
|  | ||||
| --- Toggle debug - when you need to troubleshoot. | ||||
| -- @param <null> | ||||
| function Public.toggle_debug() | ||||
|   | ||||
| @@ -3,18 +3,26 @@ local Token = {} | ||||
| local tokens = {} | ||||
|  | ||||
| local counter = 200 | ||||
| local alternative_counter = 20000 | ||||
|  | ||||
| --- Assigns a unquie id for the given var. | ||||
| -- This function cannot be called after on_init() or on_load() has run as that is a desync risk. | ||||
| -- Typically this is used to register functions, so the id can be stored in the global table | ||||
| -- instead of the function. This is becasue closures cannot be safely stored in the global table. | ||||
| -- @param  var<any> | ||||
| -- @param  sarg<boolean> | ||||
| -- @return number the unique token for the variable. | ||||
| function Token.register(var) | ||||
| function Token.register(var, sarg) | ||||
|     if _LIFECYCLE == 8 then | ||||
|         error('Calling Token.register after on_init() or on_load() has run is a desync risk.', 2) | ||||
|     end | ||||
|  | ||||
|     if sarg then | ||||
|         alternative_counter = alternative_counter + 1 | ||||
|         tokens[alternative_counter] = var | ||||
|         return alternative_counter | ||||
|     end | ||||
|  | ||||
|     counter = counter + 1 | ||||
|  | ||||
|     tokens[counter] = var | ||||
|   | ||||
		Reference in New Issue
	
	Block a user