Skip to content

Commit 886f3ba

Browse files
committed
fix(misc): miscellaneous fixes
### YRV3 - Do not render factory features if the business has not been setup. - Fix warehouse autofill using wrong integer index. - Refactor: Add an update method to businesses and let them handle updating themselves. - Throttle business update tick in math thread. - Replace problematic asserts in the `Warehouse` module with simple if statements. - Do not populate Nightclub hubs if the player does not own a business hub. ### GUI - Always default to the first tab in the side bar. - Persist previous tab between category switches. - Fix text wrapping.
1 parent 520f919 commit 886f3ba

25 files changed

Lines changed: 418 additions & 173 deletions

SSV2/includes/features/YimResupplierV3.lua

Lines changed: 57 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
local SGSL = require("includes.services.SGSL")
1111
local Warehouse = require("includes.modules.businesses.Warehouse")
12-
local BikerBusiness = require("includes.modules.businesses.BikerBusiness")
12+
local Factory = require("SSV2.includes.modules.businesses.Factory")
1313
local Nightclub = require("includes.modules.businesses.Nightclub")
1414
local Clubhouse = require("includes.modules.businesses.Clubhouse")
1515
local CashSafe = require("includes.modules.businesses.CashSafe")
@@ -59,8 +59,8 @@ Enums.eYRState = {
5959
---@field safes array<CashSafe>
6060
---@field clubhouse? Clubhouse
6161
---@field hangar? Warehouse
62-
---@field bunker? BikerBusiness
63-
---@field acid_lab? BikerBusiness
62+
---@field bunker? Factory
63+
---@field acid_lab? Factory
6464
---@field nightclub? Nightclub
6565
---@field car_wash? CarWash
6666
---@field salvage_yard? SalvageYard
@@ -75,8 +75,9 @@ Enums.eYRState = {
7575
---@field private m_sell_script_disp_name string
7676
---@field private m_raw_data RawBusinessData
7777
---@field private m_businesses YRV3Businesses
78-
---@field private m_last_as_check_time milliseconds
78+
---@field private m_last_autosell_check_time milliseconds
7979
---@field private m_last_income_check_time milliseconds
80+
---@field private m_last_business_update_time milliseconds
8081
---@field private m_cooldown_state_dirty boolean
8182
---@field private m_initial_data_done boolean
8283
---@field private m_data_initialized boolean
@@ -92,20 +93,21 @@ function YRV3:init()
9293
return self
9394
end
9495

95-
self.m_total_sum = 0
96-
self.m_bhub_script_handle = 0
97-
self.m_last_as_check_time = 0
98-
self.m_last_income_check_time = 0
99-
self.m_state = Enums.eYRState.OFFLINE
100-
self.m_has_triggered_autosell = false
101-
self.m_sell_script_running = false
102-
self.m_initial_data_done = false
103-
self.m_data_initialized = false
104-
self.m_cooldown_state_dirty = true
105-
self.m_sell_script_name = nil
106-
self.m_sell_script_disp_name = "None"
107-
self.m_last_error = ""
108-
self.m_businesses = {
96+
self.m_total_sum = 0
97+
self.m_bhub_script_handle = 0
98+
self.m_last_autosell_check_time = 0
99+
self.m_last_income_check_time = 0
100+
self.m_last_business_update_time = 0
101+
self.m_state = Enums.eYRState.OFFLINE
102+
self.m_has_triggered_autosell = false
103+
self.m_sell_script_running = false
104+
self.m_initial_data_done = false
105+
self.m_data_initialized = false
106+
self.m_cooldown_state_dirty = true
107+
self.m_sell_script_name = nil
108+
self.m_sell_script_disp_name = "None"
109+
self.m_last_error = ""
110+
self.m_businesses = {
109111
warehouses = {},
110112
safes = {},
111113
}
@@ -131,18 +133,19 @@ function YRV3:init()
131133
end
132134

133135
function YRV3:Reset()
134-
self.m_total_sum = 0
135-
self.m_last_as_check_time = 0
136-
self.m_last_income_check_time = 0
137-
self.m_businesses = {
136+
self.m_total_sum = 0
137+
self.m_last_autosell_check_time = 0
138+
self.m_last_income_check_time = 0
139+
self.m_last_business_update_time = 0
140+
self.m_businesses = {
138141
warehouses = {},
139142
safes = {},
140143
}
141-
self.m_has_triggered_autosell = false
142-
self.m_sell_script_running = false
143-
self.m_initial_data_done = false
144-
self.m_data_initialized = false
145-
self.m_cooldown_state_dirty = true
144+
self.m_has_triggered_autosell = false
145+
self.m_sell_script_running = false
146+
self.m_initial_data_done = false
147+
self.m_data_initialized = false
148+
self.m_cooldown_state_dirty = true
146149
end
147150

148151
function YRV3:Reload()
@@ -235,12 +238,12 @@ function YRV3:GetCarWash()
235238
return self.m_businesses.car_wash
236239
end
237240

238-
---@return BikerBusiness?
241+
---@return Factory?
239242
function YRV3:GetBunker()
240243
return self.m_businesses.bunker
241244
end
242245

243-
---@return BikerBusiness?
246+
---@return Factory?
244247
function YRV3:GetAcidLab()
245248
return self.m_businesses.acid_lab
246249
end
@@ -343,7 +346,7 @@ function YRV3:PopulateBikerBusinesses()
343346
local eq_upg_mult = tunables.get_int("GR_MANU_PRODUCT_VALUE_EQUIPMENT_UPGRADE")
344347
local stf_upg_mult = tunables.get_int("GR_MANU_PRODUCT_VALUE_STAFF_UPGRADE")
345348

346-
self.m_businesses.bunker = BikerBusiness.new({
349+
self.m_businesses.bunker = Factory.new({
347350
id = 5,
348351
name = Game.GetGXTLabel(_F("MP_BUNKER_%d", gxt_idx)),
349352
coords = ref and ref.coords or vec3:zero(),
@@ -360,7 +363,7 @@ function YRV3:PopulateBikerBusinesses()
360363
and (stats.get_int("MPX_XM22_LAB_EQUIP_UPGRADED") == 1)
361364
local eq_upg_mult = tunables.get_int("BIKER_ACID_PRODUCT_VALUE_EQUIPMENT_UPGRADE")
362365

363-
self.m_businesses.acid_lab = BikerBusiness.new({
366+
self.m_businesses.acid_lab = Factory.new({
364367
id = 6,
365368
name = Game.GetGXTLabel("MP_BWH_ACID"),
366369
vpu_mult_1 = has_eq_upgrade and eq_upg_mult or 0,
@@ -554,27 +557,6 @@ function YRV3:InitializeData()
554557
self:PopulateNightclub()
555558
end
556559

557-
function YRV3:WarehouseAutofill()
558-
if (not self:CanAccess()) then
559-
return
560-
end
561-
562-
for _, wh in ipairs(self.m_businesses.warehouses) do
563-
wh:AutoFill()
564-
end
565-
end
566-
567-
function YRV3:HangarAutofill()
568-
if (not self:CanAccess()) then
569-
return
570-
end
571-
572-
local hangar = self.m_businesses.hangar
573-
if (hangar and hangar:IsValid()) then
574-
self.m_businesses.hangar:AutoFill()
575-
end
576-
end
577-
578560
function YRV3:FinishSaleOnCommand()
579561
if (not self:CanAccess()) then
580562
return
@@ -809,7 +791,7 @@ end
809791
local fadedOutTimer = Timer.new(1e4)
810792
fadedOutTimer:pause()
811793
function YRV3:SetupAutosell()
812-
if (Time.millis() - self.m_last_as_check_time < 1200) then
794+
if (Time.millis() - self.m_last_autosell_check_time < 1200) then
813795
return
814796
end
815797

@@ -858,7 +840,7 @@ function YRV3:SetupAutosell()
858840
fadedOutTimer:pause()
859841
end
860842

861-
self.m_last_as_check_time = Time.millis()
843+
self.m_last_autosell_check_time = Time.millis()
862844
end
863845

864846
function YRV3:AutoSellHandler()
@@ -927,46 +909,33 @@ function YRV3:MCT()
927909
end)
928910
end
929911

930-
function YRV3:AutoProduceHandler()
931-
for _, bb in ipairs(self.m_businesses.clubhouse:GetSubBusinesses()) do
932-
if (bb.fast_prod_enabled and not bb.fast_prod_running) then
933-
bb:LoopProduction()
934-
end
935-
end
936-
937-
local bunker = self.m_businesses.bunker
938-
if (bunker and bunker:IsValid()) then
939-
if (bunker.fast_prod_enabled and not bunker.fast_prod_running) then
940-
bunker:LoopProduction()
941-
end
942-
end
943-
944-
local acidlab = self.m_businesses.acid_lab
945-
if (acidlab and acidlab:IsValid()) then
946-
if (acidlab.fast_prod_enabled and not acidlab.fast_prod_running) then
947-
acidlab:LoopProduction()
948-
end
949-
end
950-
951-
if (not self.m_businesses.nightclub) then
912+
function YRV3:UpdateBusinesses()
913+
if (not self:CanAccess()) then
952914
return
953915
end
954916

955-
local hubs = self.m_businesses.nightclub:GetSubBusinesses()
956-
if (not hubs) then
917+
if (Time.millis() - self.m_last_business_update_time < 500) then
957918
return
958919
end
959920

960-
for _, hub in ipairs(hubs) do
961-
if (hub.fast_prod_enabled and not hub.fast_prod_running) then
962-
hub:LoopProduction()
921+
for key, business in pairs(self.m_businesses) do
922+
if (key == "safes" or key == "salvage_yard" or key == "car_wash") then
923+
goto continue
963924
end
925+
926+
if (key == "warehouses") then
927+
for _, wh in ipairs(business) do
928+
if (type(wh.Update) == "function") then
929+
wh:Update()
930+
end
931+
end
932+
elseif (type(business.Update) == "function") then
933+
business:Update()
934+
end
935+
::continue::
964936
end
965-
end
966937

967-
function YRV3:AutoFillHandler()
968-
self:HangarAutofill()
969-
self:WarehouseAutofill()
938+
self.m_last_business_update_time = Time.millis()
970939
end
971940

972941
---@param business BusinessBase|BasicBusiness
@@ -1046,11 +1015,11 @@ function YRV3:OnTick()
10461015
self.m_state = Enums.eYRState.RUNNING
10471016
self:SetLastError("")
10481017

1018+
self:UpdateBusinesses()
1019+
self:CalculateEstimatedIncome()
1020+
10491021
self:AutoSellHandler()
1050-
self:AutoFillHandler()
1051-
self:AutoProduceHandler()
10521022
self:CooldownHandler()
1053-
self:CalculateEstimatedIncome()
10541023
end
10551024

10561025
return YRV3

SSV2/includes/frontend/casino_ui.lua

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ local function drawGamblingTab()
1414
ImGui.SeparatorText(_T "CP_COOLDOWN_BYPASS")
1515
GVars.features.dunk.bypass_casino_bans, _ = GUI:CustomToggle(_T "CP_COOLDOWN_BYPASS_ENABLE",
1616
GVars.features.dunk.bypass_casino_bans, {
17-
tooltip = _T "CP_COOLDOWN_BYPASS_TOOLTIP",
18-
color = Color("#AA0000")
17+
tooltip = _T("CP_COOLDOWN_BYPASS_TOOLTIP"),
18+
color = Color("#AA0000")
1919
})
2020

2121
ImGui.SameLine()
@@ -25,9 +25,12 @@ local function drawGamblingTab()
2525

2626
ImGui.SeparatorText(_T "CP_POKER_SETTINGS")
2727
GVars.features.dunk.force_poker_cards, _ = GUI:CustomToggle(_T "CP_POKER_FORCE_ROYAL_FLUSH",
28-
GVars.features.dunk.force_poker_cards)
28+
GVars.features.dunk.force_poker_cards
29+
)
30+
2931
GVars.features.dunk.set_dealers_poker_cards, _ = GUI:CustomToggle(_T "CP_POKER_FORCE_BAD_BEAT",
30-
GVars.features.dunk.set_dealers_poker_cards)
32+
GVars.features.dunk.set_dealers_poker_cards
33+
)
3134

3235
ImGui.SeparatorText(_T "CP_BLACKJACK_SETTINGS")
3336
ImGui.BulletText(_T "CP_BLACKJACK_DEALER_FACE_DOWN_CARD")

SSV2/includes/frontend/yrv3_ui.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ local function drawWarehouse(warehouse, notOwnedLabel)
191191
ImGui.PopStyleVar()
192192
end
193193

194-
---@param bb? BikerBusiness
194+
---@param bb? Factory
195195
---@param notOwnedLabel? string Optional label to display if the business isn't owned
196196
local function drawBikerBusiness(bb, notOwnedLabel)
197197
if (not bb or not bb:IsValid()) then
@@ -202,6 +202,11 @@ local function drawBikerBusiness(bb, notOwnedLabel)
202202
return
203203
end
204204

205+
if (not bb:IsSetup()) then
206+
ImGui.Text(_T("YRV3_GENERIC_NOT_SETUP"))
207+
return
208+
end
209+
205210
local bulletWidth = measureBulletWidths({
206211
_T("YRV3_EQUIP_UPGDRADE"),
207212
_T("YRV3_STAFF_UPGDRADE"),

SSV2/includes/lib/translations/__hashmap.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,5 +563,6 @@
563563
"YRV3_CLUBHOUSE_NOT_OWNED": 3232489524,
564564
"YRV3_CASH_SAFE": 3656730806,
565565
"SY_ALWAYS_MAX_INCOME": 668681147,
566-
"SY_ALWAYS_MAX_INCOME_TT": 3152143970
566+
"SY_ALWAYS_MAX_INCOME_TT": 3152143970,
567+
"YRV3_GENERIC_NOT_SETUP": 2494197122
567568
}

SSV2/includes/lib/translations/de-DE.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,5 +563,6 @@ return {
563563
["SY_CD_ROB_TYPE_ERR"] = "Aktueller Raubüberfall konnte nicht abgerufen werden! Sind Sie sicher, dass Sie eines gestartet haben?",
564564
["YRV3_CLUBHOUSE_NOT_OWNED"] = "Sie besitzen keinen Motorradclub.",
565565
["SY_ALWAYS_MAX_INCOME_TT"] = "Verhindert, dass Ihre Einkommensgrenze mit der Zeit sinkt.",
566-
["SY_ALWAYS_MAX_INCOME"] = "Sperrschwelle"
566+
["SY_ALWAYS_MAX_INCOME"] = "Sperrschwelle",
567+
["YRV3_GENERIC_NOT_SETUP"] = "Dieses Unternehmen wurde noch nicht eingerichtet. Bitte kehren Sie nach Abschluss der Setup-Mission zurück."
567568
}

SSV2/includes/lib/translations/en-US.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ return {
220220
["YRV3_LSD_LAB_NOT_OWNED"] = "You don't own an acid lab.",
221221
["YRV3_CLUB_NOT_OWNED"] = "You don't own a nightclub.",
222222
["YRV3_GENERIC_NOT_OWNED"] = "You don't own this business.",
223+
["YRV3_GENERIC_NOT_SETUP"] = "This business has not been setup. Please return after finishing the setup mission.",
223224
["YRV3_CASH_SAFE"] = "Safe Cash",
224225
["YRV3_CARGO_AMT"] = "Cargo Held",
225226
["YRV3_CRATES_LABEL"] = "Crates",

SSV2/includes/lib/translations/es-ES.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,5 +563,6 @@ return {
563563
["SY_MAX_THRESHOLD"] = "Maximizar los ingresos",
564564
["YRV3_CASH_SAFE"] = "Efectivo seguro",
565565
["SY_ALWAYS_MAX_INCOME"] = "Umbral de bloqueo",
566-
["SY_ALWAYS_MAX_INCOME_TT"] = "Evita que su umbral de ingresos disminuya con el tiempo."
566+
["SY_ALWAYS_MAX_INCOME_TT"] = "Evita que su umbral de ingresos disminuya con el tiempo.",
567+
["YRV3_GENERIC_NOT_SETUP"] = "Este negocio no ha sido creado. Regrese después de finalizar la misión de configuración."
567568
}

SSV2/includes/lib/translations/fr-FR.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,5 +563,6 @@ return {
563563
["YRV3_CASH_SAFE"] = "Argent sécurisé",
564564
["SY_ROB_IN_PROGRESS"] = "En cours.",
565565
["SY_ALWAYS_MAX_INCOME_TT"] = "Empêche votre seuil de revenu de diminuer avec le temps.",
566-
["SY_ALWAYS_MAX_INCOME"] = "Seuil de verrouillage"
566+
["SY_ALWAYS_MAX_INCOME"] = "Seuil de verrouillage",
567+
["YRV3_GENERIC_NOT_SETUP"] = "Cette entreprise n'a pas été créée. Veuillez revenir après avoir terminé la mission de configuration."
567568
}

SSV2/includes/lib/translations/it-IT.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,5 +563,6 @@ return {
563563
["SY_CD_ROB_TYPE_ERR"] = "Impossibile ottenere la rapina in corso! Sei sicuro di averne iniziato uno?",
564564
["SY_INCOME_THRESHOLD"] = "Soglia di reddito",
565565
["SY_ALWAYS_MAX_INCOME"] = "Soglia di blocco",
566-
["SY_ALWAYS_MAX_INCOME_TT"] = "Evita che la tua soglia di reddito diminuisca nel tempo."
566+
["SY_ALWAYS_MAX_INCOME_TT"] = "Evita che la tua soglia di reddito diminuisca nel tempo.",
567+
["YRV3_GENERIC_NOT_SETUP"] = "Questa attività non è stata configurata. Si prega di tornare dopo aver terminato la missione di configurazione."
567568
}

SSV2/includes/lib/translations/ja-JP.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,5 +563,6 @@ return {
563563
["YRV3_CASH_SAFE"] = "安全な現金",
564564
["YRV3_CLUBHOUSE_NOT_OWNED"] = "あなたはオートバイクラブを所有していません。",
565565
["SY_ALWAYS_MAX_INCOME"] = "ロックしきい値",
566-
["SY_ALWAYS_MAX_INCOME_TT"] = "収入の基準値が時間の経過とともに低下するのを防ぎます。"
566+
["SY_ALWAYS_MAX_INCOME_TT"] = "収入の基準値が時間の経過とともに低下するのを防ぎます。",
567+
["YRV3_GENERIC_NOT_SETUP"] = "このビジネスは確立されていません。セットアップミッション終了後、お戻りください。"
567568
}

0 commit comments

Comments
 (0)