The International Simutrans Forum

 

Author Topic: Fix incorrect "Out of funds" messages - assets value could be stale for TT_ALL  (Read 1373 times)

0 Members and 1 Guest are viewing this topic.

S_N_C

  • Guest
+The finance::has_money_or_assets method used for preventing bankrupt companies from using some tools uses the value of ATV_NON_FINANCIAL_ASSETS for TT_ALL, but this value is only correct if the finance history was recently recalculated, as book_new_vehicle doesn't keep it up to date. (Interestingly enough, update_assets - the only other method I can see that modifies a player's assets values - does.)

This meant that if you bought enough vehicles without doing something that would recalculate the history, e.g. opening the finance window or the month changing, the game could refuse to let you use some tools (e.g. terraforming) even though you did actually have some net wealth left.

Fix attached. I also changed has_money_or_assets to use the value of net wealth directly instead of recalculating it from account balance + assets apparently needlessly.

EDIT: I really should at least try compiling my patch first. :-[ Attached patch has been updated
« Last Edit: June 03, 2013, 07:14:26 PM by S_N_C »

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 9595
  • Languages: De,EN,JP
Thank you very much, incorporated.

S_N_C

  • Guest
Wait a second, I'm doubting myself here... shouldn't buying vehicles keep net wealth exactly the same, as assets goes up but balance goes down the same amount? (Their later deprecation over time is handled by update_assets).

If so, switching has_money_or_assets to read net wealth instead of balance + (stale) assets was enough to fix this bug. The line I added in book_new_vehicle to increase the net wealth is actually incorrect (not that it matters all that much, most everything calls calc_finance_history before reading it anyway, which will overwrite the incorrect value).

Sorry about that!

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 9595
  • Languages: De,EN,JP
Buying vehicles may reduce the net wealth as soon as they leave the depot, and the pakset implements the instand value reduction. But I would strive for keeping the numbers correct at all times.

S_N_C

  • Guest
Buying vehicles may reduce the net wealth as soon as they leave the depot, and the pakset implements the instand value reduction

Which is, I believe, handled later by update_assets (which already keeps net wealth correct)... book_new_vehicle deals solely with their initial purchase, and thus keeps net wealth exactly the same (new net wealth = old assets + vehicle cost + old money - vehicle cost = old assets + old money = old net wealth).

So removing the net wealth += price line should be enough to leave it consistent.