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

Incorrect substraction from in stock or demand when using +10% or -10% buttons from station's lobby #5585

Closed
Max5377 opened this issue May 18, 2023 · 6 comments · Fixed by #5628

Comments

@Max5377
Copy link
Contributor

Max5377 commented May 18, 2023

Observed behaviour

Selling or buying fuel in station's lobby using +10% or -10% buttons incorectly substracts it from in stock or demand respectively. For example, when I sell 3t of fuel it will subtract 2t from demand, and when buying 2t of fuel, it will substract 3t from in stock.

Expected behaviour

Selling fuel and buying fuel should correctly substract corresponding columns.

Steps to reproduce

  1. Go to commodity market;
  2. Remember Hydrogen in stock and demand;
  3. Go to lobby, watch how much fuel you have now;
  4. Sell or buy fuel using +10% or -10% buttons, watch how much it substract or adds it to you ship fuel;
  5. Compare this with in stock(buy) or demand(sell).

My pioneer version (and OS):
Latest master build (ac06900) (Windows 10 x64)

@Max5377 Max5377 changed the title Incorrect behaviour of buttons in station's lobby + little question(maybe bug) Incorrect behaviour of buttons in station's lobby + little question(maybe bug) (update in the comments) May 18, 2023
@Max5377 Max5377 changed the title Incorrect behaviour of buttons in station's lobby + little question(maybe bug) (update in the comments) Incorrect behaviour of buttons in station's lobby (update in the comments) May 18, 2023
@Max5377 Max5377 changed the title Incorrect behaviour of buttons in station's lobby (update in the comments) Incorrect substraction from in stock or demand when using +10% or -10% buttons from station's lobby May 18, 2023
@sturnclaw
Copy link
Member

Selling fuel reducing demand is correct, and is intentional to prevent market simulation exploits. Buying fuel from the market should not increase the amount of fuel in stock though, will look into that.

@Max5377
Copy link
Contributor Author

Max5377 commented May 23, 2023

@Web-eWorks My bad. Buying fuel correctly substracts it from in stock. But what's wrong is that for example, I have Coronatrix with 23t of fuel. I sell it using -10% button. This will substract 3t of fuel from my ship, but will substract 2t from demand instead of 3t(23t from my ship - 10% = 2,3). Same issue with +10% button, if for example I buy fuel using this button and it adds 2t of fuel to my ship, it will substract 3t of fuel from in stock(18t from my ship + 10% = 1,8).

@sturnclaw
Copy link
Member

This is most likely caused by an incorrect fractional value of stock being passed to SpaceStation:AddCommodityStock in SpaceStation.lua.

@Max5377
Copy link
Contributor Author

Max5377 commented Sep 13, 2023

@Web-eWorks
Pioneer\data\pigui\modules\station-view\01-lobby.lua in local refuelInternalTank
The problem really was with AddCommodityStock, more specifically, in this line in refuelInternalTank:

station:AddCommodityStock(Commodities.hydrogen, -math.ceil(mass))

math.ceil is rounding number up, so if this number is negative(ex. -2.3) it will be rounded to -2 because it is nearest value that greater or equal to -2.3. So the solution is to change above mentioned line to:

local commodityChangeAmount = mass < 0 and math.floor(mass) or math.ceil(mass) station:AddCommodityStock(Commodities.hydrogen, commodityChangeAmount)

Accepted answer by Guffa(albeit it's for javascript, but works the same way)

@impaktor
Copy link
Member

Good find. If you're interested in hacking pioneer's code, this is a good first pull request to learn the process. If not, we can push the fix.

@Max5377
Copy link
Contributor Author

Max5377 commented Sep 13, 2023

I'll try to do that.

Max5377 added a commit to Max5377/pioneer that referenced this issue Sep 13, 2023
sturnclaw pushed a commit that referenced this issue Sep 13, 2023
Fix for this issue #5585
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.

3 participants