Page 1 of 1

My first Newgrf: Enable power stations to close

Posted: 19 Dec 2008 20:04
by esel
Hello

I have for a long time been somewhat annoyed over power stations not closing after not being served for a long time, causing a map to have a lot of power stations.

After reading this thread, and frosch's manual industries, I decided to try to make something in newgrf to make a power station behave the same way as other similar industries (like factory or steel mill).

I have been using a GRF tool from this site: http://www.otenko.com/grf/ to make this grf. Since this is my first try for a GRF I would like to have some comments to what I have done.

I have changed the Industry production flag (0B) in Action0 to 4, making the power station a processing industry, but to prevent every power station disapear I had to make it produce goods (not the most realistic, but easy to do). To prevent it from making a lot of goods, I also added property 1C with value 00200000. This value did however not work as I expected. From the formula from the TTDPatch Wiki, I would expect 12 items of goods from 100 tons of coal, but I get something around 30 items of goods. Any ideas? (0020h = 32d, output=input*32/256 => 100*32/256=12,5, or am I missing something?)

I have tested this grf with 0.6.3 and r14648, and it seems to be working as intended.

I consider the side effect of having power stations to produce goods is OK, but it might be possible to add a new cargo "energy" to avoid it, but hey, this is my first try! :wink:

And the last question:
Is this something that is good enough to add to grfcrawler?

Re: My first Newgrf: Enable power stations to close

Posted: 19 Dec 2008 21:32
by michael blunck
esel wrote:[...] I had to make it produce goods.
That wouldn´t have been needed.

regards
Michael

Re: My first Newgrf: Enable power stations to close

Posted: 19 Dec 2008 22:38
by esel
Do you care to elaborate?

When I try without producing goods, power stations closes down even if they are serviced.

Re: My first Newgrf: Enable power stations to close

Posted: 19 Dec 2008 23:27
by Benny
Cool, goods from power stations! :D
It may need some more work and testing, but I think the final product will be worthy of a place on GRFcrawler. :)

Re: My first Newgrf: Enable power stations to close

Posted: 19 Dec 2008 23:39
by frosch
esel wrote:Any ideas? (0020h = 32d, output=input*32/256 => 100*32/256=12,5, or am I missing something?)
Not your fault :) One bug wrt. reading the property from the newgrf is fixed in r14696.
But there is another problem. When using gradual loading, vehicles only transfer very few cargo to the industry in one go, causing the above computation to be always zero :(
Without gradual loading it is also only slightly better.

Re: My first Newgrf: Enable power stations to close

Posted: 20 Dec 2008 13:56
by andythenorth
esel wrote:Hello
I have for a long time been somewhat annoyed over power stations not closing after not being served for a long time, causing a map to have a lot of power stations.
Hi Esel,

I've been working on similar code for an industry chain grf I am creating. I don't have it finished yet, but based on my tests, I think it will work. I am using the production callback: http://wiki.ttdpatch.net/tiki-index.php ... Industries

If it works, my code will:
- allow the power station to receive coal
- won't produce any cargo
- will show text in the industry window. Text will change depending how much coal is waiting to be processed. If no cargo is waiting, it will show 'Supply coal to generate electricity'. If cargo is waiting, it will show 'Generating electricity'.
- The industry will close if no cargo is supplied for n months (probably about 18 months, but I need to test it). Industry window text will indicate how many months remain before the industry will close.

I code directly in NFO and use grf-codec to encode the grf. I'd recommend working directly in NFO as you seem to understand the basics.

I'm not planning to work on this code today, but I'll post some NFO source here when I have it working.

cheers,

Andy

Re: My first Newgrf: Enable power stations to close

Posted: 20 Dec 2008 14:08
by Hyronymus
michael blunck wrote:
esel wrote:[...] I had to make it produce goods.
That wouldn´t have been needed.

regards
Michael
If you make a reply like that you leave people with the impression that you know the answer. It's considered polite to make a reply like you did and give the answer at the same time. Right now, your post is as valuable as any random off topic post.

Re: My first Newgrf: Enable power stations to close

Posted: 20 Dec 2008 14:27
by michael blunck
Hyronymus wrote:
michael blunck wrote:
esel wrote:[...] I had to make it produce goods.
That wouldn´t have been needed.

regards
Michael
If you make a reply like that you leave people with the impression that you know the answer. It's considered polite to make a reply like you did and give the answer at the same time. Right now, your post is as valuable as any random off topic post.
No, wrong.

Apparently the OP was under the false impression that his goal (modifying the power plant to be closed if not delivering any coal during xx months/years) wouldn´t be possible without producing some cargo. By my post I´ve already corrected this false assumption.

Indeed it´s quite easy to achieve this, and I´d have answered his question
esel wrote:Do you care to elaborate?
in any way, now that he´s asking for more information.

As usual, the answer can be found by reading the TTDPatch Wiki, newgrf specs section. Meanwhile andythenorth has offered to post some code snippets, so I´ll leave this to him.

Don´t interpret my posts in a false way, even if you´re speaking as a moderator, or was this your private opinion?

regards
Michael

Re: My first Newgrf: Enable power stations to close

Posted: 20 Dec 2008 14:57
by Hyronymus
Sometimes my private opinion is the same as that from my moderator character. Maybe that has something to do with them being one person, but I'm not quite sure that's indeed the underlying reason.

In the societies I live in it's considered impolite to correct people's (supposed) false assumptions but not helping them any further. It's also considered annoying. Just imagine how it would be if your false assumptions were corrected all the time but noone ever gave you a clue on how to move on.

Re: My first Newgrf: Enable power stations to close

Posted: 20 Dec 2008 15:21
by michael blunck
Hyronymus wrote: [...] In the societies I live in it's considered impolite to correct people's (supposed) false assumptions but not helping them any further. It's also considered annoying. Just imagine how it would be if your false assumptions were corrected all the time but noone ever gave you a clue on how to move on.
Oh please, spare me your moot reflections. I´ve been helping people with coding and drawing "problems" on this forums since a couple of years, and I´ll stick to my method. I.e., I usually don´t post a complete program if there´s no call for it. I rather work by "gradual increasing", giving people the chance to achieve own progress.

Don´t you have something other to do, today?[*]

regards
Michael

[*] @moderators: this is a polite question, not an insulting.

EOD

Re: My first Newgrf: Enable power stations to close

Posted: 20 Dec 2008 15:39
by Hyronymus
Dang, moot reflections 'r' me :( . Sorry for stepping on the toes of such a good helper, it's something I overlooked for years.

Back to drinking coffee.

Re: My first Newgrf: Enable power stations to close

Posted: 20 Dec 2008 17:24
by frosch
@esel: Try your grf again in next nightly :)

Re: My first Newgrf: Enable power stations to close

Posted: 23 Dec 2008 16:59
by esel
frosch: I will try that after I am done decorating for xmas..