how to determine refit cost?

Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.

Moderator: OpenTTD Developers

Post Reply
User avatar
Kev!
Engineer
Engineer
Posts: 37
Joined: 21 Jun 2011 16:30
Location: In Da House!
Contact:

how to determine refit cost?

Post by Kev! »

Howdy,
I am trying to build a plane and refit it for mail but sometimes I only have enough money for the plane and not the refit and then I have the wrong plane flying around.

I tried test mode + accounting but i get precondition fail error on the refit.


Please advise,
Kev!
?( ;(
I DO like a nice caboose...
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: how to determine refit cost?

Post by Zuu »

As far as I know, this is a design problem with the NewGRF spec, that the cost to refit an engine may not be the same as refitting the actual built vehicle. Some may call it a feature rather than a design problem, however it produces problems like the one you have experienced.

Without seeing your code, I can't say if you made any error on your side regarding doing the cost estimation. (regardless of the issue stated above)

What I think you should do is to sell the aircraft again if the refit fails. This might need some back-off mechanism in order to the AI not get into a repetitive behavior. This repetitive behavior could cost a few money units each time (loss of vehicle value between the tick when they are bought and when they are sold 2 ticks later).
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5602
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: how to determine refit cost?

Post by PikkaBird »

Zuu wrote:As far as I know, this is a design problem with the NewGRF spec, that the cost to refit an engine may not be the same as refitting the actual built vehicle.
While many grf authors wish that refit cost was subject to advanced fiddling-with via callback, this is not actually currently the case.
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 988
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: how to determine refit cost?

Post by frosch »

Kev:
It would have been easier if you had posted some code. So, I can only guess what you tried.

It sounds as if you entered testmode, then build a vehicle in test mode and tried to refit that one.
That won't work. The vehicle is not actually built in test mode, so you cannot refit it.

The only solution is, as Zuu said, to build the vehicle, try to refit it, and if that fails, sell the vehicle again.

Btw. the same happens to humans. Coincidently just yesterday I started a game with an train set I never played before, built a first route and had barely enough money to purchase the train. Then I discovered that refitting the wagons cost 5 times more than purchasing them. So I was bankrupt :p
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
User avatar
Kev!
Engineer
Engineer
Posts: 37
Joined: 21 Jun 2011 16:30
Location: In Da House!
Contact:

Re: how to determine refit cost?

Post by Kev! »

Howdy,

Frosch is correct. That is exactly what I was trying to do. Thank you. :bow:

Wow, is an AIEngine.GetRefitCost(engine_id) too much to ask? :x I suppose I could, each time I build a plane, enter testmode and accounting mode, try to refit, get the cost and remember it in case I need it later? :roll: Dang, that's not too much trouble! :?


Kev!
I DO like a nice caboose...
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: how to determine refit cost?

Post by planetmaker »

Kev! wrote: Wow, is an AIEngine.GetRefitCost(engine_id) too much to ask? :x
It is.

It could depend on date, day of month, year, player number, cargo type, track type, all at once, subject to change on a daily basis. NewGRFs can do what they want in that arena, no way to reliably predict it.
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 988
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: how to determine refit cost?

Post by frosch »

Well, as Pikka said. The cost is actually known.

However, the capacity is unknown, which is usually the next thing which is asked for :)

At some point OTTD will likely learn to do these test-purchases itself. It is also needed for other non-AI stuff, like purchase+refit for human players, templated autoreplace, and more... but not now :)
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 40 guests