Bug 163: Patch
Moderator: OpenTTD Developers
-
- Engineer
- Posts: 4
- Joined: 10 May 2006 15:38
Bug 163: Patch
When applied this patch modifies economy.c - DeliverGoods()
It will deliver the goods to the station/city, however will not pay the player as the origin station of their cargo no longer exists.
It will deliver the goods to the station/city, however will not pay the player as the origin station of their cargo no longer exists.
- Attachments
-
- DeliverGoods.patch
- Patch for DeliverGoods() function of economy.c
- (1.16 KiB) Downloaded 198 times
Don't you think that it would have been easier to just add the linewhere it makes sense (i.e. where your if statement is).
Would have saved you from adding all those extra indentation
Code: Select all
if (s_from->xy == 0) return 0;
Would have saved you from adding all those extra indentation

-
- Engineer
- Posts: 4
- Joined: 10 May 2006 15:38
It's not about saving memory, it's about maintainable code. StormDragoness is engaging in good programming practice by putting the return in a predictable place. A good compiler would probably optimise it to the same machine code, anyway.
PGP fingerprint: E66A 9D58 AA10 E967 41A6 474E E41D 10AE 082C F3ED
-
- Engineer
- Posts: 4
- Joined: 10 May 2006 15:38
It would be too resource consuming to do such a trivial task. To check whether there is some cargo from the station that is going to be removed, it would be required to check every wagon and every other station and compare the cargo roots.Maedhros wrote:How about turning it around and not deleting the station while there's still cargo that references it?
(Disclaimer - I haven't looked closely at this patch or the bug in question...)
That sounds reasonable if we store Tile ID instead of Station ID. Station can be accessed anyway as we have tile ID, and there will be no problem of ghost stations.why not change the source station into source tile? This would get rid of this bug, without the need for an ugly workaround.
On the other hand, maybye we're making too much trouble around such a small trouble. It isn't often that station disappears completly and vehicles are still up and running.
Anyone dares touching it?
It compiles, but half a second after running the game an assert pops up.
I know where it is, and I hope I'll find it, but I post this file for two reasons:
1)You know someone is working on it, so no doublework
2)Someone can give me tips about the code
I just lack in time right now to debug
It compiles, but half a second after running the game an assert pops up.
I know where it is, and I hope I'll find it, but I post this file for two reasons:
1)You know someone is working on it, so no doublework
2)Someone can give me tips about the code
I just lack in time right now to debug
- Attachments
-
- cargofix01.patch
- (9.03 KiB) Downloaded 170 times
So how does this actually compile?
Huh? That won't really work.
Code: Select all
Station *s_from, *s_to;
+ s_from = GetStationIndex(source);
TrueLight: "Did you bother to read any of the replies, or you just pressed 'Reply' and started typing?"
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
Allright, I know what's wrong with it.
It isn't savegame compatibile.
The assertion fails at start of the game because the vehicles from opntitle.dat still have StationID cargo_source instead of TileIndex.
The game works almost fine without opntitle.dat (there is an empty map visible on the menu screen).
It crashes, however, when the station is deleted... Too much coding, I'm discontinuing it, but if you really want, you can see the patch file.
In spite of that, I've got another idea how to fix that bug
It isn't savegame compatibile.
The assertion fails at start of the game because the vehicles from opntitle.dat still have StationID cargo_source instead of TileIndex.
The game works almost fine without opntitle.dat (there is an empty map visible on the menu screen).
It crashes, however, when the station is deleted... Too much coding, I'm discontinuing it, but if you really want, you can see the patch file.
In spite of that, I've got another idea how to fix that bug

- Attachments
-
- cargofix02.patch
- (9.46 KiB) Downloaded 181 times
This patch needs saving/loading TileIndex cargo_source_tile, and creating one from StationID cargo_source if old savegame has been loaded (how?).
I don't know if I'll continue work on this - it is possible if I find info on the savegame versions and developers won't have anything against making new savegame version.
I don't know if I'll continue work on this - it is possible if I find info on the savegame versions and developers won't have anything against making new savegame version.
Something like this perhaps: http://bugs.openttd.org/task/163
The biggest problem was handling the bad/old cases of which I am not sure I have. The game might still crash when you load a game that already has a vehicle coming from a demolished station. Someone will have to take a deeper look into it.
The biggest problem was handling the bad/old cases of which I am not sure I have. The game might still crash when you load a game that already has a vehicle coming from a demolished station. Someone will have to take a deeper look into it.
TrueLight: "Did you bother to read any of the replies, or you just pressed 'Reply' and started typing?"
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
Excellent fix. Now I'll test it.
Edit: I have tested it:
Step 1: Save a game using the unpatched trunk
I created a small oil wells - oil rafinery line with one train. No sooner the train had left the station than I demolished it and saved the game. Just for testing purposes, I continued to play to see the payment - over 10000$$
Step 2: Load a game using patched trunk
I loaded the game and after a few seconds train approached the station and game crashed. Before entering the platform, I checked its properties and saw "30 000 litres of oil from unknown destination"
The game didn't crash in the gui part when checking cargo's destination.
It crashed, however, somewhere in economy.c. It could be DeliverGoods or LoadUnloadVehicle, I think
Edit: I have tested it:
Step 1: Save a game using the unpatched trunk
I created a small oil wells - oil rafinery line with one train. No sooner the train had left the station than I demolished it and saved the game. Just for testing purposes, I continued to play to see the payment - over 10000$$
Step 2: Load a game using patched trunk
I loaded the game and after a few seconds train approached the station and game crashed. Before entering the platform, I checked its properties and saw "30 000 litres of oil from unknown destination"
The game didn't crash in the gui part when checking cargo's destination.
It crashed, however, somewhere in economy.c. It could be DeliverGoods or LoadUnloadVehicle, I think
in LoadUnloadVehicle
/* unload? */
if (v->cargo_count != 0) {
if (v->cargo_source != st->xy && ge->waiting_acceptance & 0x8000 && !(u->current_order.flags & OF_TRANSFER)) {
// deliver goods to the station
Has v->cargo_source been converted to TileIndex? I'm afraid it could be still StationID
------------------------------------------------
in DeliverGoods
// Get station pointers.
s_from = GetStationByTile(source);
s_to = GetStation(dest);
// Check if a subsidy applies.
subsidised = CheckSubsidised(s_from, s_to, cargo_type);
Maybye it is CheckSubsidised that crashes?
/* unload? */
if (v->cargo_count != 0) {
if (v->cargo_source != st->xy && ge->waiting_acceptance & 0x8000 && !(u->current_order.flags & OF_TRANSFER)) {
// deliver goods to the station
Has v->cargo_source been converted to TileIndex? I'm afraid it could be still StationID
------------------------------------------------
in DeliverGoods
// Get station pointers.
s_from = GetStationByTile(source);
s_to = GetStation(dest);
// Check if a subsidy applies.
subsidised = CheckSubsidised(s_from, s_to, cargo_type);
Maybye it is CheckSubsidised that crashes?
Yes, s_from to CheckSubsidies is NULL, so that crashes.
The problem is now that behaviour has changed. You see that because v->source is not a StationID anymore, the moment you demolish the station the details window says 'unknown destination'. Even while in the old behaviour kept saying the old station as long as it was 'grey'.
This of course also removes any potential subsidies since those are handled by StationID as well... WTF, that's totally gay. Stations have nothing to do with subsidies, it's always town/industry <> town/industry.
Hmm..needs more thinking.
Ah, if a subsidy is serviced, it is given the Station as source and destination. Should this be turned into a TileIndex as well?
Just do the above to fix the crash;
The problem is now that behaviour has changed. You see that because v->source is not a StationID anymore, the moment you demolish the station the details window says 'unknown destination'. Even while in the old behaviour kept saying the old station as long as it was 'grey'.
This of course also removes any potential subsidies since those are handled by StationID as well... WTF, that's totally gay. Stations have nothing to do with subsidies, it's always town/industry <> town/industry.
Hmm..needs more thinking.
Ah, if a subsidy is serviced, it is given the Station as source and destination. Should this be turned into a TileIndex as well?
Code: Select all
subsidised = (s_from != NULL) ? CheckSubsidised(s_from, s_to, cargo_type) : false;
TrueLight: "Did you bother to read any of the replies, or you just pressed 'Reply' and started typing?"
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
Who is online
Users browsing this forum: No registered users and 5 guests