was there a train bug in depot?

OpenTTD is a fully open-sourced reimplementation of TTD, written in C++, boasting improved gameplay and many new features.

Moderator: OpenTTD Developers

Post Reply
User avatar
Korenn
Tycoon
Tycoon
Posts: 1735
Joined: 26 Mar 2004 01:27
Location: Netherlands
Contact:

was there a train bug in depot?

Post by Korenn »

I think I remember reading this, but I'm not sure.

was there a bug that under some situations made the train appear about 20 squares away from depot?
Patchman
Tycoon
Tycoon
Posts: 7575
Joined: 02 Oct 2002 18:57
Location: Ithaca, New York
Contact:

Post by Patchman »

There was and is a bug which happens if you click on the "pass red signal" button while a train is halfway into the depot.

I don't think it's serious enough to need fixing, basically, people just have to not push this button :)

[edit] Oops, I didn't notice this was the OpenTTD forum... so the above bug exists in TTD, and depending how closely OpenTTD follows its code, may or may not exist there.
BobXP
Tycoon
Tycoon
Posts: 2720
Joined: 04 May 2003 11:00
Location: Torquay, England
Contact:

Post by BobXP »

The bug was that the train would go out as soon as it went in, not that it appears 20 squares away. Anyway this should be fixed, cos whenever I press it when the train is sitting at a red light one square away from the depot it does this. I then can't get it to go in the depot and if you have limited space you can do nothing other than crash the damn train and wait for the wreckage to go away. Which f***s up your ratings. :evil: :evil:
<!-- End Of Post !-->
Image
User avatar
dominik81
OpenTTD Developer
OpenTTD Developer
Posts: 768
Joined: 16 Aug 2003 12:55
Location: Bonn, Germany

Post by dominik81 »

Could you upload a savegame along with a description to the buglist on Sourceforge? This way it'll get fixed soon.
User avatar
Korenn
Tycoon
Tycoon
Posts: 1735
Joined: 26 Mar 2004 01:27
Location: Netherlands
Contact:

Post by Korenn »

I ask this because there's a macro in ottd that seems to be to wrong to me...

it has to do with calculating coordinates

#define TILE_FROM_XY(x,y) (((((y) & ~0xF) << 8) + (x)) >> 4)

this a bit of bit shifting going on here...

~0xf is the bit pattern 1111111111110000 thus masks the last 4 bits.

then the result of the mask gets shifted left 8 places

so there are 12 zeros at the end.... for a map size of 256 that should be 8.

so that's an erroneous multiplication by 16...

am I wrong?
Bjarni
Tycoon
Tycoon
Posts: 2088
Joined: 08 Mar 2004 13:10

Post by Bjarni »

Korenn wrote:I ask this because there's a macro in ottd that seems to be to wrong to me...

it has to do with calculating coordinates

#define TILE_FROM_XY(x,y) (((((y) & ~0xF) << 8) + (x)) >> 4)

this a bit of bit shifting going on here...

~0xf is the bit pattern 1111111111110000 thus masks the last 4 bits.

then the result of the mask gets shifted left 8 places

so there are 12 zeros at the end.... for a map size of 256 that should be 8.

so that's an erroneous multiplication by 16...

am I wrong?
it is because x and y are not tiles, but 1/16 tile. Removing the last 4 bits makes it tile coordinates
User avatar
Korenn
Tycoon
Tycoon
Posts: 1735
Joined: 26 Mar 2004 01:27
Location: Netherlands
Contact:

Post by Korenn »

well duuh read my post thoroughly before answering please.

the y coordinate at the end is in total shifted by 12

8 because of the shift, and 4 because the last 4 bits are masked.
Patchman
Tycoon
Tycoon
Posts: 7575
Joined: 02 Oct 2002 18:57
Location: Ithaca, New York
Contact:

Post by Patchman »

Note that in the end it's again shifted 4 to the right (check the parens!) and that's exactly right. It becomes the upper byte of a 16 bit value, with the lower byte being the x tile coordinate.

I.e. 0xxx, 0yyy becomes yyxx, with the last 4 bits of each (the position within the tile) being discarded.
User avatar
Korenn
Tycoon
Tycoon
Posts: 1735
Joined: 26 Mar 2004 01:27
Location: Netherlands
Contact:

Post by Korenn »

oooooh the y value is also shifted right!

ofc.... d'oh!
Post Reply

Return to “General OpenTTD”

Who is online

Users browsing this forum: Google [Bot], ZaphodB and 18 guests