Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ship info screen shows wrong cargo capacity and usage. #5557

Closed
dhouseholder opened this issue Feb 20, 2023 · 6 comments · Fixed by #5635
Closed

Ship info screen shows wrong cargo capacity and usage. #5557

dhouseholder opened this issue Feb 20, 2023 · 6 comments · Fixed by #5635

Comments

@dhouseholder
Copy link

dhouseholder commented Feb 20, 2023

Observed behaviour

I have 16 tons of cargo in my hold.
The ship info screen says I have 8 tons of cargo capacity of which 0 are used.
image
image

Expected behaviour

16 tons of cargo in hold, 16 tons cargo capacity, 16 tons used.

Steps to reproduce

Issue is evident in this save file.
When starting the game I sold off some starter equipment. Not sure if that is related.
I am also wondering if this is the cause of #5554; could a police ship be trying to scan me but the cargo is corrupted?

vert.zip

My pioneer version (and OS):
e77da96 ; Windows and Steam Deck

@RaulMarq
Copy link

I think this may be related to #5534 and my comment on that issue, perhaps some kinda cargo corruption going on.

@impaktor
Copy link
Member

@dhouseholder can you confirm if the bug is only there after a save/load? (note: save/load bugs can behave differently depending on whether or not you close pioneer betwee the save/load).

@dhouseholder
Copy link
Author

@impaktor The bug persists across executions of Pioneer and when loading the save file on separate Windows and Linux machines.

@Max5377
Copy link
Contributor

Max5377 commented Sep 26, 2023

Related #5534
Two ship's properties totalCargo and usedCargo wasn't initialized beyond constructor after loading the game.
To fix it this lines can be added in CargoManager:Unserialize():


self.ship:setprop("totalCargo", self:GetTotalSpace())
self.ship:setprop("usedCargo", self.usedCargoSpace)

self.ship:UpdateEquipStats() - don't know if this line is needed here, I put it as in CargoManager:OnShipTypeChanged()

@sturnclaw
Copy link
Member

totalCargo and usedCargo are serialized in the body's PropertyMap and should be fully present when loading a saved game. They should already be initialized by loading the Body object from the save and if they are not that's a fairly major issue. I'd recommend digging deeper into the issue, as the problem is more likely to come from an inadvertent overwrite of those properties.

@Max5377
Copy link
Contributor

Max5377 commented Sep 27, 2023

Here I list all occurences of usedCargo and totalCargo I could find, looks line they are all used only when "operating" with ship.
The only occurences in C++ of usedCargo I could find is in static int l_ship_get_stats(lua_State *l) in LuaShip.cpp. No occurences of totalCargo at all in C++.
In the lua:
CargoManager:Constructor(ship):

-- Initialize property variables on owning ship for backwards compatibility
ship:setprop("totalCargo", self:GetTotalSpace())
ship:setprop("usedCargo", 0)

CargoManager:OnShipTypeChanged():

self.ship:setprop("totalCargo", self:GetTotalSpace())
self.ship:setprop("usedCargo", self.usedCargoSpace)

CargoManager:AddCommodity(type, count):

self.usedCargoSpace = self.usedCargoSpace + required_space
self.ship:setprop("usedCargo", self.usedCargoSpace)

CargoManager:RemoveCommodity(type, count):

self.usedCargoSpace = self.usedCargoSpace - freed_space
self.ship:setprop("usedCargo", self.usedCargoSpace)

EquipSet:__TriggerCallbacks(ship, slot):

ship:setprop("totalCargo", math.min(self.slots.cargo.__limit, ship.usedCargo+ship.freeCapacity))

Pirates.lua OnEnterSystem:

local probabilityPirateIsInterested = math.floor(player.usedCargo - discount) / math.max(1,  playerCargoCapacity - discount)

TradeShips\Debug.lua debugView.registerTab('debug-trade-ships', function():

if ship:exists() then
table.insert(ships, {
	...
	cargo = ship.usedCargo,
        ...
})

TradeShips\Trader.lua Trader.addEquip:

assert(ship.usedCargo == 0, "equipment is only installed on an empty ship")

target-scanner.lua:

local cargo = stats.usedCargo

01-ship-info.lua:

{ l.CARGO_SPACE..":", string.format("%dt (%dt "..l.MAX..")", player.totalCargo, shipDef.equipSlotCapacity.cargo) },
{ l.CARGO_SPACE_USED..":", string.format("%dt (%dt "..l.FREE..")", player.usedCargo, player.totalCargo - player.usedCargo) },

04-shipMarket.lua:

if def.equipSlotCapacity.cargo < player.usedCargo or def.capacity < (player.usedCargo + hdrive) then

system-view-ui.lua Windows.objectInfo:Show():

local body = obj.ref
...
elseif obj.ref:IsShip() then -- physical body
...
if player:GetEquipCountOccupied('target_scanner') > 0 or player:GetEquipCountOccupied('advanced_target_scanner') > 0 then
	...
	table.insert(data, { name = luc.CARGO, value = Format.MassTonnes(body:GetStats().usedCargo) })
end

Maybe we can get rid of them completely, since most of the time they can be replaced with an equivalent in CargoManager?
And also wanted to add. Looks like it's the usedCargo which wasn't initialized besides to 0 in the constructor of the CargoManager. And this happened to any ship present during save load. Looks like totalCargo was initialized normally.

Edit: basically, during creation of CargoManager's usedCargoSpace which needs to be assigned to Ship's usedCargo is zero. During loading, usedCargoSpace has some value, which is loaded from save, but it's never assigned to Ship's usedCargo. Because of that usedCargo has value of zero, unless you do something which assigns some value to usedCargo (add/remove commodity, change ship, etc.). totalCargo has normal value, because it is calculated from CargoManager fields and from Ship's definition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants