Important! The GRF search!

Discuss, get help with, or post new graphics for TTDPatch and OpenTTD, using the NewGRF system, here. Graphics for plain TTD also acceptable here.

Moderator: Graphics Moderators

Post Reply
User avatar
George
Tycoon
Tycoon
Posts: 4364
Joined: 16 Apr 2003 16:09
Skype: george-vb
Location: Varna, Bulgaria
Contact:

Important! The GRF search!

Post by George »

2 All the industry GRF developers!!!

We (me and belugas) found a serious discrepancy between the understanding of the documentation. So, we are looking for the GRF author, who already coded the GRF with following assumption for callback 35/29:

When industry var 93 is EQUAL to 4 (and 0-3 too, but it is not a question for discussion), that means the industry closure! (As belugas sees it)

If you see that industry var 93 is EQUAL to 0-3 means the industry closure, while value 4 does not mean it (As I see it), please, write it here too
Image Image Image Image
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Re: Important! The GRF search!

Post by DaleStan »

My view is that 04 does not indicate closure, and the documentation is misleading. A more correct statement would be "If this value [01] is returned when the production is a quarter of the default, the industry is closed instead, as if you returned 03."

What happens in TTDPatch? When it comes to GRF handling, the burden of proof is on the side that claims TTDPatch is wrong.

For more fun-and-games, during a recession, all production rates are divided by two, and the lower limit is reduced to 02.
To get a good answer, ask a Smart Question. Similarly, if you want a bug fixed, write a Useful Bug Report. No TTDPatch crashlog? Then follow directions.
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser
User avatar
George
Tycoon
Tycoon
Posts: 4364
Joined: 16 Apr 2003 16:09
Skype: george-vb
Location: Varna, Bulgaria
Contact:

Re: Important! The GRF search!

Post by George »

DaleStan wrote:My view is that 04 does not indicate closure, and the documentation is misleading. A more correct statement would be "If this value [01] is returned when the production is a quarter of the default, the industry is closed instead, as if you returned 03."
This exactly my point
DaleStan wrote:For more fun-and-games, during a recession, all production rates are divided by two, and the lower limit is reduced to 02.
Sorry, but my tests shows that this is not correct. It does not change the production level (var 93), but halves the output, and halves it AFTER it was generated by the industry AFTER production callback. This is very impotant for ECS vectors, because the industries uses this behaviour and do not need to provide additional handling for recession. If var 93 would change (/2) during recession, I would need to rewrite every industry code :roll:
Image Image Image Image
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Re: Important! The GRF search!

Post by DaleStan »

Well then, I stand corrected. At least I remembered the "halved" bit correctly. I just forgot when the halving happens.
To get a good answer, ask a Smart Question. Similarly, if you want a bug fixed, write a Useful Bug Report. No TTDPatch crashlog? Then follow directions.
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser
User avatar
belugas
OpenTTD Developer
OpenTTD Developer
Posts: 1507
Joined: 05 Apr 2005 01:48
Location: Deep down the deepest blue
Contact:

Re: Important! The GRF search!

Post by belugas »

I would like to bring in my side of the situation.

The var 93 (OTTD = industry->prod_level, TTDP = industry.prodmultiplier) is used for controlling the production of the industry.
It is been re-evaluated once every month. During the evaluation, callbacks are been fired and results will affect var 93.

In OTTD and in TTDP, from what we have seen code wise, if ever the var 93 reaches 4, at the end of the evaluation procedure, the system will lower the var 93 to 0 and leaves. This means that during the evaluation of the next month, the system will effectively close that industry. So it basically gives a full month for the industry to close.

Code: Select all

TTDPatch:
.decrease:
.decloop:
	cmp byte [esi+industry.prodmultiplier],4
	je .closedown
	shr byte [esi+industry.prodmultiplier],1
	add byte [esi+industry.prodrates],1
	sbb byte [esi+industry.prodrates],0
	shr byte [esi+industry.prodrates],1
	add byte [esi+industry.prodrates+1],1
	sbb byte [esi+industry.prodrates+1],0
	shr byte [esi+industry.prodrates+1],1
	loop .decrease

OpenTTD:
	/* Decrease if needed */
	while (div-- != 0 && !closeit) {
		if (i->prod_level == 4) {
			closeit = true;
		} else {
			i->prod_level >>= 1;
			i->production_rate[0] = (i->production_rate[0] + 1) >> 1;
			i->production_rate[1] = (i->production_rate[1] + 1) >> 1;
			if (str == STR_NULL) str = indspec->production_down_text;
		}
	}
I post in here the code OTTD uses for this purpose:

Code: Select all

void IndustryMonthlyLoop()
{
	Industry *i;
	PlayerID old_player = _current_player;
	_current_player = OWNER_NONE;

	FOR_ALL_INDUSTRIES(i) {
		UpdateIndustryStatistics(i);     <----- does not affect prod_level/ var 93
		if (i->prod_level == 0) {         <----- has it been declared for closure?
			delete i;                         <----- yes, close it now
		} else {                                 <-----  no, let';s evaluate it
			ChangeIndustryProduction(i, true);    <------  evaluation been performed in here. [0]
		}
	}
	...
[0] So, if prod_level == 4, it will be shifted to 0 right away, in orderto be able to be closed in next month loop.
The ChangeIndustryproduction function holds this code, near the end of it, that actually does the above mentionned behaviour

Code: Select all

	/* Close if needed and allowed */
	if (closeit && !CheckIndustryCloseDownProtection(i->type)) {
		i->prod_level = 0;
		str = indspec->closure_text;
	}
Unless otherwise proven, we are convinced TTDP does exactly the same process.
So, all in all, it means that if ever var 93 reaches 4, the industry will be closed next month.
If you are not ready to work a bit for your ideas, it means they don't count much for you.
OpenTTD and Realism? Well... Here are a few thoughs on the matter.
He he he he
------------------------------------------------------------
Music from the Bloody Time Zones
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Re: Important! The GRF search!

Post by DaleStan »

belugas wrote:In OTTD and in TTDP, from what we have seen code wise, if ever the var 93 reaches 4, at the end of the evaluation procedure, the system will lower the var 93 to 0 and leaves.
That's not what I see.

Code: Select all

TTDPatch:
.decrease:
.decloop:
	cmp byte [esi+industry.prodmultiplier],4
	je .closedown
	shr byte [esi+industry.prodmultiplier],1
Compare with 4, and then reduce the multiplier. So you can reduce it to 4, industry.prodmultiplier will not be zeroed, and the industry will stay open. At least until next time this code is seen.
As for "next time", the label name .decrease and the code that jumps to .decrease both make me very suspicious that .decrease is not executed unless the callback specified that the industry will get a production decrease.
And then there's the code in the loop; there's no code there to fail to change the production multiplier, so if it gets executed when a decrease is not intended, there's no way to undo the decrease. .increase, on the other hand, does not check to see if industry.prodmultiplier is 4, nor does .nothing or .error.
To get a good answer, ask a Smart Question. Similarly, if you want a bug fixed, write a Useful Bug Report. No TTDPatch crashlog? Then follow directions.
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser
User avatar
belugas
OpenTTD Developer
OpenTTD Developer
Posts: 1507
Joined: 05 Apr 2005 01:48
Location: Deep down the deepest blue
Contact:

Re: Important! The GRF search!

Post by belugas »

Thanks to frosch, glx and Dalestan, something a bit odd ( :oops: ) has been spotted in the 0D/0E result handling of callback 29/35.
On revision r11976, i've made a little change. I hope it will make a big difference.
The evaluation of the closure was not done properly and made it closing too quick.
I would appreciate feedbacks on it.
Thanks
If you are not ready to work a bit for your ideas, it means they don't count much for you.
OpenTTD and Realism? Well... Here are a few thoughs on the matter.
He he he he
------------------------------------------------------------
Music from the Bloody Time Zones
User avatar
belugas
OpenTTD Developer
OpenTTD Developer
Posts: 1507
Joined: 05 Apr 2005 01:48
Location: Deep down the deepest blue
Contact:

Re: Important! The GRF search!

Post by belugas »

So? Did it made the difference?
Was it worth it?
If you are not ready to work a bit for your ideas, it means they don't count much for you.
OpenTTD and Realism? Well... Here are a few thoughs on the matter.
He he he he
------------------------------------------------------------
Music from the Bloody Time Zones
User avatar
George
Tycoon
Tycoon
Posts: 4364
Joined: 16 Apr 2003 16:09
Skype: george-vb
Location: Varna, Bulgaria
Contact:

Re: Important! The GRF search!

Post by George »

belugas wrote:So? Did it made the difference?
Was it worth it?
Yes, the fix works fine at least in my tests. There were no bug reports about unexpected closure of the mines any more, so I hope it works fine for other users too. Thank you, Belugas :D
Image Image Image Image
Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Re: Important! The GRF search!

Post by Roujin »

It definately was worth it. After that fix, the issues i had with mines in george's ECS vectors dissolved :)

Thanks again ;)
* @Belugas wonders what is worst... a mom or a wife...
<Lakie> Well, they do the same thing but the code is different.

______________
My patches
check my wiki page (sticky button) for a complete list

ImageImage
ImageImageImageImageImageImageImage
Post Reply

Return to “Graphics Development”

Who is online

Users browsing this forum: Ahrefs [Bot] and 25 guests