Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Spaceship.stop_integrity_check(spaceship)
- spaceship.check_flash_alpha = nil
- spaceship.is_doing_check = nil
- spaceship.is_doing_check_slowly = nil
- spaceship.check_stage = nil
- spaceship.pending_tiles = nil
- spaceship.streamline = nil
- if spaceship.integrity_valid and spaceship.check_tiles then
- -- success
- spaceship.count_empty_tiles = spaceship.check_count_empty_tiles
- spaceship.check_count_empty_tiles = nil
- spaceship.known_tiles = table.deepcopy(spaceship.check_tiles)
- spaceship.check_tiles = nil
- -- get the average for surface transfer
- local min_x = nil
- local max_x = nil
- local min_y = nil
- local max_y = nil
- local floor_tiles = 0
- local bulkhead_tiles = 0
- local front_tiles = {} -- x:y
- for x, x_tiles in pairs(spaceship.known_tiles) do
- if min_x == nil or x < min_x then min_x = x end
- if max_x == nil or x > max_x then max_x = x end
- for y, status in pairs(x_tiles) do
- if status == Spaceship.tile_status.floor_console_connected
- or status == Spaceship.tile_status.bulkhead_console_connected then
- if min_y == nil or y < min_y then min_y = y end
- if max_y == nil or y > max_y then max_y = y end
- if status == Spaceship.tile_status.floor_console_connected then
- floor_tiles = floor_tiles + 1
- else
- bulkhead_tiles = bulkhead_tiles + 1
- end
- if (not front_tiles[x]) or y < front_tiles[x] then
- front_tiles[x] = y
- end
- end
- end
- end
- max_x = max_x + 1 -- whole tile
- max_y = max_y + 1 -- whole tile
- spaceship.known_floor_tiles = floor_tiles
- spaceship.known_bulkhead_tiles = bulkhead_tiles
- spaceship.known_bounds = {left_top = {x = min_x, y = min_y}, right_bottom={x = max_x, y = max_y}}
- spaceship.known_tiles_average_x = math.floor((min_x + max_x)/2)
- spaceship.known_tiles_average_y = math.floor((min_y + max_y)/2)
- local front_tiles_by_y = {} -- y:count
- local front_tiles_by_y_left = {} -- y:count
- local front_tiles_by_y_right = {} -- y:count
- local max_flat = 0
- for x, y in pairs(front_tiles) do
- front_tiles_by_y[y] = (front_tiles_by_y[y] or 0) + 1
- if front_tiles_by_y[y] > max_flat then
- max_flat = front_tiles_by_y[y]
- end
- if x < spaceship.known_tiles_average_x then
- front_tiles_by_y_left[y] = (front_tiles_by_y_left[y] or 0) + 1
- else
- front_tiles_by_y_right[y] = (front_tiles_by_y_right[y] or 0) + 1
- end
- end
- local width = max_x - min_x
- -- max_flat == width = 0
- -- max_flat == width / 3 = 1
- local streamline_flatness = math.min(1, (1 - (max_flat-2) / (width-2)) * 1.5)
- local streamline_left = math.min(1, 2 * (table_size(front_tiles_by_y_left)-1) / (math.max(0.5, (width-1) / 2.5)))
- local streamline_right = math.min(1, 2 * (table_size(front_tiles_by_y_right)-1) / (math.max(0.5, (width-1) / 2.5)))
- spaceship.streamline = (streamline_flatness + streamline_left + streamline_right
- + 3 * math.min(streamline_flatness, math.min(streamline_left, streamline_right))) / 6
- --spaceship.streamline = math.min(1, 3.5 * (table_size(front_tiles_by_y)-1) / width)
- -- if it is symetrical then 1/2 would be max (excluding the -1)
- -- use 1/3.5 as max so there can be a few flat areas
- Log.trace("streamline flat "..streamline_flatness.." left "..streamline_left.." right "..streamline_right)
- --Log.trace("streamline "..spaceship.streamline )
- if Spaceship.is_on_own_surface(spaceship) then
- Spaceship.find_own_surface_engines(spaceship)
- end
- else
- spaceship.integrity_valid = false
- spaceship.check_tiles = nil
- spaceship.check_message = {"space-exploration.spaceship-check-message-failed-empty"}
- end
- --spaceship.check_message = nil
- if spaceship.console and spaceship.console.valid then
- --spaceship.console.force.print("Spaceship integrity check complete.")
- end
- Spaceship.check_integrity_stress(spaceship)
- if spaceship.is_launching then
- Spaceship.launch(spaceship)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment