How do costs and running costs for ships work?

Discussions about the technical aspects of graphics development, including NewGRF tools and utilities.

Moderator: Graphics Moderators

Post Reply
SimYouLater
Chief Executive
Chief Executive
Posts: 676
Joined: 03 Apr 2016 20:19

How do costs and running costs for ships work?

Post by SimYouLater »

I'm having trouble with blueFISH. Here is what I know:

The following section provides the base values.

Code: Select all

basecost {
 	PR_RUNNING_SHIP: 0;
 	PR_BUILD_VEHICLE_SHIP: 0;
}
Both values have a range between -8 and 16.

The cost_factor and running_cost_factor properties are also involved, and have a range between 0 and 255.


What is the formula used in determining the costs? Or a table of all outcomes I can refer to? Thanks in advance.
Licenses for my work...
You automatically have my permission to re-license graphics or code by me if needed for use in any project that is not GPL v2, on the condition that if you release any derivatives of my graphics they're automatically considered as ALSO GPL v2 (code may remain unreleased, but please do provide it) and carry this provision in GPL v2 uses.
Please ask someone in-the-know to be sure that the graphics are done by me. Especially TTD-Scale, long story.

frosch
OpenTTD Developer
OpenTTD Developer
Posts: 980
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: How do costs and running costs for ships work?

Post by frosch »

(cost_factor) * (2^basecost) * (number from https://newgrf-specs.tt-wiki.net/wiki/N ... cost_table) * inflation

Usually you only set "cost_factor". "basecost" is for difficulty/boredom settings.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁

SimYouLater
Chief Executive
Chief Executive
Posts: 676
Joined: 03 Apr 2016 20:19

Re: How do costs and running costs for ships work?

Post by SimYouLater »

frosch wrote:(cost_factor) * (2^basecost) * (number from https://newgrf-specs.tt-wiki.net/wiki/N ... cost_table) * inflation

Usually you only set "cost_factor". "basecost" is for difficulty/boredom settings.
Thanks. What is the value for inflation if inflation is turned off in settings?

EDIT: I figured it out. The "inflation" rate with inflation turned off is 0.0029230769230769, in case anyone needs that information.
Licenses for my work...
You automatically have my permission to re-license graphics or code by me if needed for use in any project that is not GPL v2, on the condition that if you release any derivatives of my graphics they're automatically considered as ALSO GPL v2 (code may remain unreleased, but please do provide it) and carry this provision in GPL v2 uses.
Please ask someone in-the-know to be sure that the graphics are done by me. Especially TTD-Scale, long story.

SimYouLater
Chief Executive
Chief Executive
Posts: 676
Joined: 03 Apr 2016 20:19

Re: How do costs and running costs for ships work?

Post by SimYouLater »

After trying to use the formula I've been given, I've discovered that it cannot be correct.

If I am aiming for a ship cost of approximately £1,250,000 and a running cost of £73,000, the formula should work as follows...

(cost_factor) * (2^PR_BUILD_VEHICLE_SHIP) * 65000 * inflation = price
1 * 2^13 * 65000 * 0.0029230769230769 = 1556479.999999987712 (£1,556,480)

(running_cost_factor) * (2^PR_RUNNING_SHIP) * 5600 * inflation = running cost
1 * 2^12 * 5600 * 0.0029230769230769 = 67048.36923076870144 (£67,048)

...but instead I get this...
Unnamed, 1885-01-01.png
Unnamed, 1885-01-01.png (13.63 KiB) Viewed 2700 times
What gives?
Licenses for my work...
You automatically have my permission to re-license graphics or code by me if needed for use in any project that is not GPL v2, on the condition that if you release any derivatives of my graphics they're automatically considered as ALSO GPL v2 (code may remain unreleased, but please do provide it) and carry this provision in GPL v2 uses.
Please ask someone in-the-know to be sure that the graphics are done by me. Especially TTD-Scale, long story.

frosch
OpenTTD Developer
OpenTTD Developer
Posts: 980
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: How do costs and running costs for ships work?

Post by frosch »

I forgot some things:
* There are two advanced settings which scale construction and running cost. "Normal cost" has factor 1.
* There is always some offset to the exponent, which I believe is not listed in the wiki. In case of vehicle purchase and running cost it is -8,
* No inflation means factor "1".
* The internal currency is British pounds.

So for ship running cost with normal running cost setting and no inflation from game start, the formula is:
(cost_factor) * 2^(basecost-8) * 5600

I have no idea how you end up with 213, are you sure you set the properties to the values you meant to?
Anyway you should probably not change "basecost", but only "cost_factor".
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁

SimYouLater
Chief Executive
Chief Executive
Posts: 676
Joined: 03 Apr 2016 20:19

Re: How do costs and running costs for ships work?

Post by SimYouLater »

frosch wrote:I forgot some things:
* There is always some offset to the exponent, which I believe is not listed in the wiki. In case of vehicle purchase and running cost it is -8,
* No inflation means factor "1".
Ah, I see.
frosch wrote:So for ship running cost with normal running cost setting and no inflation from game start, the formula is:
(cost_factor) * 2^(basecost-8) * 5600

I have no idea how you end up with 213, are you sure you set the properties to the values you meant to?
I accidentally put a running_cost_foactor of 13. It should have been 12.
frosch wrote:Anyway you should probably not change "basecost", but only "cost_factor".
But if cost_factor is multiplied by 2^basecost, and basecost N = 1 - 8, then that should give a negative number. :?
Licenses for my work...
You automatically have my permission to re-license graphics or code by me if needed for use in any project that is not GPL v2, on the condition that if you release any derivatives of my graphics they're automatically considered as ALSO GPL v2 (code may remain unreleased, but please do provide it) and carry this provision in GPL v2 uses.
Please ask someone in-the-know to be sure that the graphics are done by me. Especially TTD-Scale, long story.

Transportman
Tycoon
Tycoon
Posts: 2729
Joined: 22 Feb 2011 18:34

Re: How do costs and running costs for ships work?

Post by Transportman »

SimYouLater wrote: But if cost_factor is multiplied by 2^basecost, and basecost N = 1 - 8, then that should give a negative number. :?
A negative exponent means 1/(2^positive value of the exponent), not that the basecosts go negative (would make the game quite easy if that would be the case :p).
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML

SimYouLater
Chief Executive
Chief Executive
Posts: 676
Joined: 03 Apr 2016 20:19

Re: How do costs and running costs for ships work?

Post by SimYouLater »

Transportman wrote:
SimYouLater wrote: But if cost_factor is multiplied by 2^basecost, and basecost N = 1 - 8, then that should give a negative number. :?
A negative exponent means 1/(2^positive value of the exponent), not that the basecosts go negative (would make the game quite easy if that would be the case :p).
I have set costs and maintenance to medium. I'm trying to get a cost of 2.5 million. I've calculated that should be impossible, so I'm aiming for 2.08 million, but the numbers still don't add up.

Code: Select all

cost_factor = 1
PR_BUILD_VEHICLE_SHIP = 13
PR_BUILD_VEHICLE_SHIP - 8 = 5
2^(PR_BUILD_VEHICLE_SHIP - 8) = 32

1 * 32 = 32
1 * 32 * 65,000 = 2,080,000

inflation = 1

1 * 32 * 65,000 * 1 = 2,080,000
Instead I get this:
Attachments
Unnamed, 1885-01-01#2.png
Unnamed, 1885-01-01#2.png (13.65 KiB) Viewed 2612 times
Licenses for my work...
You automatically have my permission to re-license graphics or code by me if needed for use in any project that is not GPL v2, on the condition that if you release any derivatives of my graphics they're automatically considered as ALSO GPL v2 (code may remain unreleased, but please do provide it) and carry this provision in GPL v2 uses.
Please ask someone in-the-know to be sure that the graphics are done by me. Especially TTD-Scale, long story.

phobos2077
Engineer
Engineer
Posts: 24
Joined: 13 Nov 2019 16:17

Re: How do costs and running costs for ships work?

Post by phobos2077 »

I got curious how exactly "Running costs" setting works. Reading through the engine source code I didn't find it being used directly for the final running costs calculation. But changing the setting, starting new game and comparing values I got these results:

- High is only about 12.5% higher than Medium
- Low is 25% lower than Medium

Does anyone knows how exactly this difficulty setting is implemented? I wanted to adjust running costs for my ships to make them about 50% more expensive and it seems to be not possible with how BaseCosts NewGRF does it (because bit-shift is used for multiplication, no floating point operation). I'd be great if I could just change the 12.5% increase to 50% increase on High setting if it's just some value edit in NewGRF and doesn't involve engine patching.

Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 2 guests