2024-09-10 11:29:44 +01:00
-- This file is part of thesixthroc's Pirate Ship softmod, licensed under GPLv3 and stored at https://github.com/ComfyFactory/ComfyFactorio and https://github.com/danielmartin0/ComfyFactorio-Pirates.
2022-06-01 19:50:36 +01:00
2021-10-13 09:21:53 +01:00
local Common = require ' maps.pirates.common '
local Balance = require ' maps.pirates.balance '
2022-03-19 21:20:55 +00:00
-- local Utils = require 'maps.pirates.utils_local'
-- local Math = require 'maps.pirates.math'
local _inspect = require ' utils.inspect ' . inspect
2021-10-13 09:21:53 +01:00
local Boats = require ' maps.pirates.structures.boats.boats '
local Memory = require ' maps.pirates.memory '
local Kraken = require ' maps.pirates.surfaces.sea.kraken '
local Public = { }
2022-03-19 21:20:55 +00:00
-- local GuiCommon = require 'maps.pirates.gui.common'
2021-10-13 09:21:53 +01:00
-- local button_sprites = {
-- ['small-biter'] = 0,
-- ['medium-biter'] = 0.2,
-- ['small-spitter'] = 0.25,
-- ['medium-spitter'] = 0.4,
-- ['big-spitter'] = 0.5,
-- ['big-biter'] = 0.501,
-- ['behemoth-spitter'] = 0.9,
-- ['behemoth-biter'] = 0.901
-- }
-- local function get_alien_name(evolution_factor)
-- local last_match = 'fish'
-- for name, alien_threshold in pairs(button_sprites) do
-- if evolution_factor == alien_threshold then
-- return name
-- end
-- -- next alien evolution_factor isn't reached
-- if alien_threshold > evolution_factor then
-- return last_match
-- end
-- -- surpassed this alien evolution_factor
-- if alien_threshold < evolution_factor then
-- last_match = name
-- end
-- end
-- return last_match
-- end
2022-03-13 01:44:32 +00:00
2022-03-19 21:20:55 +00:00
-- function Public.regular_update(player)
2022-03-13 01:44:32 +00:00
2022-03-19 21:20:55 +00:00
-- end
2022-03-13 01:44:32 +00:00
function Public . full_update ( player )
2022-03-20 11:41:23 +00:00
if Public.regular_update then Public.regular_update ( player ) end
2022-03-19 21:20:55 +00:00
2021-10-13 09:21:53 +01:00
local memory = Memory.get_crew_memory ( )
local pirates_flow = player.gui . top
local button = pirates_flow.evo_piratebutton_frame . evo_piratebutton
if button and button.valid then
2022-03-11 16:46:02 +00:00
local evo = memory.evolution_factor or 0
-- local evo = Math.floor(evo * 1000) * 0.001
2021-10-13 09:21:53 +01:00
-- local current_alien = get_alien_name(evolution_factor)
-- local sprite = 'entity/' .. current_alien
-- if evolution_factor == 0 or (memory.boat and (memory.boat.state == Boats.enum_state.ATSEA_SAILING or memory.boat.state == Boats.enum_state.ATSEA_LOADING_MAP)) then
-- button.number = 0
-- button.tooltip = 'Local biter evolution\n\n0'
-- else
2022-03-11 16:46:02 +00:00
local destination = Common.current_destination ( )
2022-03-19 21:20:55 +00:00
2022-09-13 22:09:25 +01:00
local evolution_leagues = 0
local evolution_kraken = 0
local evolution_time = 0
local evolution_silo = 0
local evolution_nests = 0
local evolution_sandwurms = 0
2022-03-19 21:20:55 +00:00
local evolution_total
2022-03-17 01:40:18 +00:00
local types = { ' leagues ' , ' kraken ' , ' time ' , ' silo ' , ' nests ' , ' sandwurms ' }
2022-07-26 21:59:42 +01:00
if Boats.is_boat_at_sea ( ) then
2022-03-11 16:46:02 +00:00
local krakens = false
if memory.active_sea_enemies and memory.active_sea_enemies . krakens then
for i = 1 , Kraken.kraken_slots do
if memory.active_sea_enemies . krakens [ i ] then krakens = true break end
2021-10-13 09:21:53 +01:00
end
2022-03-11 16:46:02 +00:00
end
if krakens then
2022-07-30 14:02:24 +01:00
evolution_leagues = evo - ( memory.dynamic_kraken_evo or 0 )
evolution_kraken = Balance.kraken_static_evo + ( memory.dynamic_kraken_evo or 0 )
evolution_total = evo + Balance.kraken_static_evo
2021-10-13 09:21:53 +01:00
else
2022-07-30 14:02:24 +01:00
evolution_leagues = evo
evolution_total = evo
2021-10-13 09:21:53 +01:00
end
2022-03-11 16:46:02 +00:00
else
2022-03-13 01:44:32 +00:00
if destination and destination.dynamic_data then
2022-03-17 01:40:18 +00:00
evolution_leagues = destination.dynamic_data . evolution_accrued_leagues
evolution_time = destination.dynamic_data . evolution_accrued_time
evolution_nests = destination.dynamic_data . evolution_accrued_nests
evolution_silo = destination.dynamic_data . evolution_accrued_silo
evolution_sandwurms = destination.dynamic_data . evolution_accrued_sandwurms
2022-03-13 01:44:32 +00:00
end
2022-07-30 14:02:24 +01:00
evolution_total = ( evolution_leagues or 0 ) + ( evolution_time or 0 ) + ( evolution_nests or 0 ) + ( evolution_silo or 0 ) + ( evolution_sandwurms or 0 ) + ( evolution_kraken or 0 )
2022-03-11 16:46:02 +00:00
end
2022-03-17 01:40:18 +00:00
2024-09-07 22:33:00 +01:00
---@type (string|table)[]
2022-06-04 14:43:08 +01:00
local str = { ' ' , { ' pirates.gui_evo_tooltip_1 ' , string.format ( ' %.2f ' , evolution_total ) } }
if evolution_leagues or evolution_time or evolution_nests or evolution_silo or evolution_sandwurms then
str [ # str + 1 ] = { ' ' , ' \n ' }
end
2022-05-29 12:36:27 +01:00
2022-03-17 01:40:18 +00:00
for _ , type in ipairs ( types ) do
if type == ' leagues ' then
if evolution_leagues then
2022-05-29 12:36:27 +01:00
str [ # str + 1 ] = { ' ' , ' \n ' , { ' pirates.gui_evo_tooltip_2 ' , string.format ( ' %.2f ' , evolution_leagues ) } }
2022-03-17 01:40:18 +00:00
end
elseif type == ' kraken ' then
if evolution_kraken then
2022-05-29 12:36:27 +01:00
str [ # str + 1 ] = { ' ' , ' \n ' , { ' pirates.gui_evo_tooltip_3 ' , string.format ( ' %.2f ' , evolution_kraken ) } }
2022-03-17 01:40:18 +00:00
end
elseif type == ' time ' then
if evolution_time then
2022-05-29 12:36:27 +01:00
str [ # str + 1 ] = { ' ' , ' \n ' , { ' pirates.gui_evo_tooltip_4 ' , string.format ( ' %.2f ' , evolution_time ) } }
2022-03-17 01:40:18 +00:00
end
elseif type == ' silo ' then
if evolution_silo then
2022-05-29 12:36:27 +01:00
str [ # str + 1 ] = { ' ' , ' \n ' , { ' pirates.gui_evo_tooltip_5 ' , string.format ( ' %.2f ' , evolution_silo ) } }
2022-03-17 01:40:18 +00:00
end
elseif type == ' nests ' then
if evolution_nests then
2022-05-29 12:36:27 +01:00
str [ # str + 1 ] = { ' ' , ' \n ' , { ' pirates.gui_evo_tooltip_6 ' , string.format ( ' %.2f ' , evolution_nests ) } }
2022-03-17 01:40:18 +00:00
end
elseif type == ' sandwurms ' then
if evolution_sandwurms then
2022-05-29 12:36:27 +01:00
str [ # str + 1 ] = { ' ' , ' \n ' , { ' pirates.gui_evo_tooltip_7 ' , string.format ( ' %.2f ' , evolution_sandwurms ) } }
2022-03-17 01:40:18 +00:00
end
end
end
button.number = evolution_total
button.tooltip = str
2022-09-13 22:09:25 +01:00
2022-07-30 14:02:24 +01:00
if evolution_total > 1.0 then
button.sprite = ' entity/behemoth-worm-turret '
elseif evolution_total >= 0.9 then
button.sprite = ' entity/behemoth-biter '
elseif evolution_total >= 0.5 then
button.sprite = ' entity/big-biter '
elseif evolution_total >= 0.4 then
button.sprite = ' entity/medium-spitter '
2022-07-31 10:23:59 +01:00
elseif evolution_total >= 0.25 then
button.sprite = ' entity/small-spitter '
2022-07-30 14:02:24 +01:00
elseif evolution_total >= 0.2 then
button.sprite = ' entity/medium-biter '
else
button.sprite = ' entity/small-biter '
end
2021-10-13 09:21:53 +01:00
end
end
return Public