Page 1 of 1

Patch: Counting died passengers

Posted: 27 Oct 2013 09:40
by Mister_X
I'm playing OpenTTD for many years, and want to add some improvements to the game.

My first one is a very small one to understand how the game works and try to apply the coding syntax correctly.
Crash.patch
(2.64 KiB) Downloaded 119 times
Is this a good start?
And what to do next?

Re: Patch: Counting died passengers

Posted: 27 Oct 2013 10:00
by Hyronymus
Sadly I lack any skill to apply a patch but the subject you choose is actually a nice one: the death toll could affect company rating.

Messages

Posted: 30 Oct 2013 13:54
by Mister_X
I made another small patch which makes to changes for displaying messages.

1.
When you click at a summary message, the full message appears. After closing this message, the message is still visible in the status bar. Sometimes it cost a lot of seconds before the next message is vissible.
After applying this patch, the message will be removed from the status bar and the next message will be visible directly.

2.
When a lot of messages are in the que to display, the latest messages aren't showed anymore because they are very old. (for example: When removing a road piece, a lot of vehicle lost messages will come up.)
After applying this patch, a third menu option is available in the News menu to skip all pending messages.

In the file strings.h the line static const StringID STR_NEWS_MENU_MESSAGE_SKIP_NEXT_MESSAGES = 0x15C; should be added, but I couln't make a patch for this file.
And apply both patch files:
Messages a.patch
(1.63 KiB) Downloaded 60 times
Messages b.patch
(2.35 KiB) Downloaded 59 times

Re: Messages

Posted: 30 Oct 2013 15:00
by planetmaker
Mister_X wrote:I made another small patch which makes to changes for displaying messages.

1.
When you click at a summary message, the full message appears. After closing this message, the message is still visible in the status bar. Sometimes it cost a lot of seconds before the next message is vissible.
After applying this patch, the message will be removed from the status bar and the next message will be visible directly.

2.
When a lot of messages are in the que to display, the latest messages aren't showed anymore because they are very old. (for example: When removing a road piece, a lot of vehicle lost messages will come up.)
After applying this patch, a third menu option is available in the News menu to skip all pending messages.

In the file strings.h the line static const StringID STR_NEWS_MENU_MESSAGE_SKIP_NEXT_MESSAGES = 0x15C; should be added, but I couln't make a patch for this file.
And apply both patch files:
Messages a.patch
Messages b.patch
strings.h is not edited manually. Just add your string to src/lang/english.txt and use it. strgen will take care of strings.h upon compilation.

Re: Patch: Counting died passengers

Posted: 30 Oct 2013 19:45
by Mister_X
Ah, I understand. Now It's clear why this file wasn't synchronized with SVN. :)

Show area

Posted: 03 Nov 2013 13:48
by Mister_X
I've a new patch. :)

The button "Area" is added onto the town window. This will show all tiles where the town is the local authority from.
The button "Area" is added onto the station window also. This will show the catchment area for acceptance for goods and passengers.
Show area.patch
(27.07 KiB) Downloaded 57 times
If you have some suggestions, please let me know. :)

Re: Patch: Counting died passengers

Posted: 03 Nov 2013 16:09
by Lord Aro
Adding a new byte into the map array to do this seems...wrong. very wrong.

Also, can you make your patches without spaces in the filenames? Makes it a bit easier for us unix types to apply :)

Re: Patch: Counting died passengers

Posted: 03 Nov 2013 18:08
by Mister_X
Lord Aro wrote:Adding a new byte into the map array to do this seems...wrong. very wrong.
I didn't like to add an extra variable there, but I read the file landscape_grid.html, and no bit was left which wasn't used by any tile type.
To not slow down the current game speed a search loop isn't a good idea, I think. So I need a global variable which is accessible when drawing the sprite.
Do you have a better idea to solve this issue?


OK, next time I don't use spaces in the file names. :)


Edit:
In landscape_grid.html I see that for each tile type at least one bit is available.
It is desirable to place this bit dependent on the tile type at different locations in the map?

Re: Patch: Counting died passengers

Posted: 04 Nov 2013 14:38
by adf88
Mister_X wrote:Do you have a better idea to solve this issue?
You have a set of rectangles and circles. Tiles are inside or outside them - perform this hit test on-demend, don't pre-calculate values for all tiles. When you have to decide whether to draw a tile highlight or not, then just check whether the tile is contained by any of rectangles/circles, something like this:

Code: Select all

for (uint i = 0; i < areas_to_highlight.Length(); i++) {
    if (areas_to_highlight[i].Contains(tile)) {
        DrawTileCoverage(i, tile);
        break;
    }
}
Optionally you can cache only some amount of hit test results and/or use better algorithms to perform the hit test. However, I see no point in doing so. Simple linear search will be fast enough until you want to show coverage for all stations/towns. Otherwise it may turn out that something better is required.

Re: Patch: Counting died passengers

Posted: 05 Nov 2013 21:24
by Mister_X
You are right. I tought that the process to draw the tiles was very slow, so I wouldn't make the draw process more slower than needed. Now I see that this process is fast enough to do an extra loop.
Your suggestion to do a raw rectangle check first is a good point. I added this into the patch and removed the extra byte in the map array. :)
ShowArea_V2.patch
(22.85 KiB) Downloaded 62 times