Physics patches
Moderator: OpenTTD Developers
It doesn't seem that OpenTTD handles that callback correctly. In TTDPatch, you may be more limited in building mixed consists. But I doubt that this is the correct way of doing it.* The whole idea of having powered wagons is strange.
For now, I have left the code as it was in the previous version. I don't think it will lead to major problems or confusion. I will not (be able to) change it until there is a proper handling of powered wagons in mixed consists.
The first of the patch versions I post below does not contain new features, but contains a little clean-up of the code.
The second one is the same as the first one, but with an extra cheat option, to have road vehicles and trains ignore physical laws (like in curves and on hills) and speed limits (like on bridges, in stations and when entering depots). This cheat only works with realistic acceleration turned on, and the force equations will still apply (albeit without inclination forces). Currently, there is only one setting (on/off), but in the future there may be more finetuning (e.g. changing the curve, inclination, station, etc. handling independently).
NOTE: The cheat will not work with realistic acceleration disabled!
*I mean, from the perspective of grf, it is the correct way, since it is meant to be that way. In my opinion, EMUs and DMUs should come as units (like their names suggest), and not as a locomotive to which you have to add a certain amount of wagons.
For now, I have left the code as it was in the previous version. I don't think it will lead to major problems or confusion. I will not (be able to) change it until there is a proper handling of powered wagons in mixed consists.
The first of the patch versions I post below does not contain new features, but contains a little clean-up of the code.
The second one is the same as the first one, but with an extra cheat option, to have road vehicles and trains ignore physical laws (like in curves and on hills) and speed limits (like on bridges, in stations and when entering depots). This cheat only works with realistic acceleration turned on, and the force equations will still apply (albeit without inclination forces). Currently, there is only one setting (on/off), but in the future there may be more finetuning (e.g. changing the curve, inclination, station, etc. handling independently).
NOTE: The cheat will not work with realistic acceleration disabled!
*I mean, from the perspective of grf, it is the correct way, since it is meant to be that way. In my opinion, EMUs and DMUs should come as units (like their names suggest), and not as a locomotive to which you have to add a certain amount of wagons.
- Attachments
-
- patch_physics_with_cheat_r4815_10-05-2006.patch
- Physics patch with vehicle speed cheat - version 10-may-06 - r4815
- (138.68 KiB) Downloaded 395 times
-
- patch_physics_r4815_10-05-2006.patch
- Physics patch - version 10-may-06 - r4815
- (135.52 KiB) Downloaded 404 times
Kaboo Hahahein reports that this/these patch(es) has/have fallen out of sync with the trunk, and require(s) some conflict resolution. I'm willing to look at when I get the time, but you'd probably be a better person for that, as you know what your code is supposed to do.
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
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser
That "falling out of sync" happens all the time. Luckily there were only small conflicts this time; it took just a few minutes to fix them.
However, I managed to enable the cheat for the classic TTD acceleration as well. For realistic acceleration enabled, it works the same as the last version. If realistic acceleration is disabled, vehicles just behave as if curves and gradients do not exist, with the classic acceleration handling.
The cheat may behave a little bit differently* depending on whether RA is on or off. But since you will only use one of them (i.e. either on or off) at a time, this is probably not a great problem.
*This has something to do with engine/wagon speed limits and bridge speed limits.
However, I managed to enable the cheat for the classic TTD acceleration as well. For realistic acceleration enabled, it works the same as the last version. If realistic acceleration is disabled, vehicles just behave as if curves and gradients do not exist, with the classic acceleration handling.
The cheat may behave a little bit differently* depending on whether RA is on or off. But since you will only use one of them (i.e. either on or off) at a time, this is probably not a great problem.
*This has something to do with engine/wagon speed limits and bridge speed limits.
- Attachments
-
- patch_physics_with_cheat_r4942_21-05-2006.patch
- Physics patch with vehicle speed cheat - version 21-may-2006 - r4942
- (141.07 KiB) Downloaded 398 times
-
- patch_physics_r4942_21-05-2006.patch
- Physics patch - version 21-may-2006 - r4942
- (136.45 KiB) Downloaded 420 times
-
- Transport Coordinator
- Posts: 321
- Joined: 22 May 2006 18:25
- Location: London-ish.
- Contact:
There are a couple of issues that I've found with this, using the US .grf set. I'm not sure whether they're specific to my set of patches/build environment or whatever, but...in train_cmd.c,
Firstly, the following:
This can generate an assert in tile.h when the type of gp.new_tile isnt MP_RAILWAY. Try running a train across a level crossing to see what I mean. I changed it to the following:
That solved it for me. Also, there's another possible assert you can get; basically building certain wagons in the US Set, or possibly building wagons without an engine. That's in the following part of train_cmd.c:
Basically, it's possible for prev_engine_railtype to be invalid here. I changed it to the following:
I think there are better ways to get it working, but that seems to do the trick.
Also there's an issue which can be specific to certain GRF-sets with tenders and the like - at least I've found it with the USSet. Basically, there's a few lines with the following calculation:
It's possible for u.rail.cached_veh_weight to be zero, in my experience. I'm pretty sure it's contained solely in the 'Curve Handling' section of train_cmd.c, although I'm not sure what's the best way to deal with it - I've used solutions both of ignoring zero-mass wagons, and also setting the minimum mass to 1 - both work quite well even if they're not optimal.
Firstly, the following:
Code: Select all
if (HasSignalOnTrackdir(gp.new_tile, i)) {
v->u.rail.next_signal_tile = gp.new_tile;
v->u.rail.next_signal_dir = i;
} else {
v->u.rail.next_signal_dir = INVALID_TRACKDIR;
}
Code: Select all
if ((IsTileType(gp.new_tile, MP_RAILWAY)) && (HasSignalOnTrackdir(gp.new_tile, i))) {
v->u.rail.next_signal_tile = gp.new_tile;
v->u.rail.next_signal_dir = i;
} else {
v->u.rail.next_signal_dir = INVALID_TRACKDIR;
}
Code: Select all
if (IsBridgeTile(u->tile) && IsBridgeMiddle(u->tile) && DiagDirToAxis(DirToDiagDir(u->direction)) == GetBridgeAxis(u->tile)) {
if (!HasPowerOnRail(u->u.rail.railtype, GetRailTypeOnBridge(u->tile))) engine_has_power = false;
if (!HasPowerOnRail(prev_engine_railtype, GetRailTypeOnBridge(u->tile))) wagon_has_power = false;
} else if (IsLevelCrossingTile(u->tile)) {
if (!HasPowerOnRail(u->u.rail.railtype, GetRailTypeCrossing(u->tile))) engine_has_power = false;
if (!HasPowerOnRail(prev_engine_railtype, GetRailTypeCrossing(u->tile))) wagon_has_power = false;
} else {
if (!HasPowerOnRail(u->u.rail.railtype, GetRailType(u->tile))) engine_has_power = false;
if (!HasPowerOnRail(prev_engine_railtype, GetRailType(u->tile))) wagon_has_power = false;
}
Code: Select all
if (IsBridgeTile(u->tile) && IsBridgeMiddle(u->tile) && DiagDirToAxis(DirToDiagDir(u->direction)) == GetBridgeAxis(u->tile)) {
if (!HasPowerOnRail(u->u.rail.railtype, GetRailTypeOnBridge(u->tile))) engine_has_power = false;
if ((prev_engine_railtype >= RAILTYPE_END) || (!HasPowerOnRail(prev_engine_railtype, GetRailTypeOnBridge(u->tile)))) wagon_has_power = false;
} else if (IsLevelCrossingTile(u->tile)) {
if (!HasPowerOnRail(u->u.rail.railtype, GetRailTypeCrossing(u->tile))) engine_has_power = false;
if ((prev_engine_railtype >= RAILTYPE_END) || (!HasPowerOnRail(prev_engine_railtype, GetRailTypeCrossing(u->tile)))) wagon_has_power = false;
} else {
if (!HasPowerOnRail(u->u.rail.railtype, GetRailType(u->tile))) engine_has_power = false;
if ((prev_engine_railtype >= RAILTYPE_END) || (!HasPowerOnRail(prev_engine_railtype, GetRailType(u->tile)))) wagon_has_power = false;
}
Also there's an issue which can be specific to certain GRF-sets with tenders and the like - at least I've found it with the USSet. Basically, there's a few lines with the following calculation:
Code: Select all
... / u->u.rail.cached_veh_weight
Thank you for the information. These are errors that might only appear in some "exceptional" situations (i.e. some grf-sets). I will fix them as soon as possible.
About the second issue, the wagon power part, there are still some other problems taht need to be solved. Basically, I need an answer to the question: Do powered wagons in mixed consists (i.e. more than one engine type) inherit their properties from the front engine, or the most recent engine in the consist. (If it is the former, then we have to use the existing trunk code, otherwise some other things have to be sorted out on top of this patch code).
About the second issue, the wagon power part, there are still some other problems taht need to be solved. Basically, I need an answer to the question: Do powered wagons in mixed consists (i.e. more than one engine type) inherit their properties from the front engine, or the most recent engine in the consist. (If it is the former, then we have to use the existing trunk code, otherwise some other things have to be sorted out on top of this patch code).
If you want to make it use the last engine for livery overrides and powered wagon/power, only minor changes are needed to TrainConsistChanged() and its friends.
In the DBsetXL, it still doesn't work properly though, because they are not designed to be mixed.
In the DBsetXL, it still doesn't work properly though, because they are not designed to be mixed.
He's like, some kind of OpenTTD developer.
I've updated the physics patch for current trunk, which is rev5005. This version doesn't include the unit GUI changes and the airspeed part, but incorporates the fixes mentioned by Timberwolf.
-- Michael Lutz
-- Michael Lutz
- Attachments
-
- physics_patch_r5005b.patch
- For trunk revision 5005
- (112.37 KiB) Downloaded 464 times
Nice.
I had also made version*, but unfortunately I am not able to test it now, since the code won't compile properly (and that's not due to this patch). During the following week, I will have another look at it. Not tonight.
*I have rewritten the curve handling, and put it in a separate function. The main difference is that wagon lengths are counted, instead of number of wagons. For wagons which do not have the standard length, the old method does not always provide the proper length of the curve.
I had also made version*, but unfortunately I am not able to test it now, since the code won't compile properly (and that's not due to this patch). During the following week, I will have another look at it. Not tonight.
*I have rewritten the curve handling, and put it in a separate function. The main difference is that wagon lengths are counted, instead of number of wagons. For wagons which do not have the standard length, the old method does not always provide the proper length of the curve.
Sorry, it has been a while since I posted a version, for a number of reasons I will not bother you with*.
Unfortunately, someone decided to cut the bridge branch from the trunk. I had already simplified some of my own functions using functions from that branch. I have fixed that now: I replaced some of the code that I used before bridge was merged, and made some functions loosely based on the bridge branch myself, to protect myself from rewriting the acceleration controllers every time code is changed elsewhere.
I did not spend a lot of time testing (I've only tested that the bridge speeds were correct, with RA enabled and disabled), so there might be errors that slipped through. But my expectation is that it works fine (since it also did before, and not much has changed after all).
*Technical problems concerning the patch. And laziness
Unfortunately, someone decided to cut the bridge branch from the trunk. I had already simplified some of my own functions using functions from that branch. I have fixed that now: I replaced some of the code that I used before bridge was merged, and made some functions loosely based on the bridge branch myself, to protect myself from rewriting the acceleration controllers every time code is changed elsewhere.
I did not spend a lot of time testing (I've only tested that the bridge speeds were correct, with RA enabled and disabled), so there might be errors that slipped through. But my expectation is that it works fine (since it also did before, and not much has changed after all).
*Technical problems concerning the patch. And laziness

- Attachments
-
- patch_physics_r5177_08-06-2006.patch
- Physics patch - version 08-jun-2006 - r5177
- (136.03 KiB) Downloaded 448 times
- White Rabbit
- Tycoon
- Posts: 1734
- Joined: 22 Jun 2005 19:15
I got a lot of warnings when compiling with your patch and OTTD ihas become unstable, crashing without apparent reason. The patch is fully functional though and I'm quite impressed.
I would, however, like it if the TE units were in kNs, because that's what the Patch uses and is more accurate. For example, he DE-AC33C of the DB Set XL has a TE of 517kN, but OTTD displays it as '51 ton force'.

For SI units, the force units are displayed in kN. For standard imperial and standard metric units, it is currently displayed in (metric) ton force.White Rabbit wrote:I got a lot of warnings when compiling with your patch and OTTD ihas become unstable, crashing without apparent reason. The patch is fully functional though and I'm quite impressed.I would, however, like it if the TE units were in kNs, because that's what the Patch uses and is more accurate. For example, he DE-AC33C of the DB Set XL has a TE of 517kN, but OTTD displays it as '51 ton force'.
If you wish to change one of these to kilonewton, change the line(s)
Code: Select all
835, 13, STR_UNITS_FORCE_METRIC,
Code: Select all
1, 0, STR_UNITS_FORCE_SI,
I have not seen many unstabilities in my version of OpenTTD, at least not anything that could be related to the patch. Concerning the compiler warnings: I also get some warnings, and I don't really know how to get rid of them, but they don't seem to do any harm. Not to my version anyway.
If you have some warning that concerns you, please let me know what it is (and what compiler you use).
- White Rabbit
- Tycoon
- Posts: 1734
- Joined: 22 Jun 2005 19:15
Thanks for that information.
Now that I've played with the physics patch properly, two problems have cropped up: with the train speed limit turned on, engines never reach their maximum speed, but stop accelerating at 1km/h or 2km/h below the maximum; with the train speed limit turned off, engines reach speeds they were never capable of doing in real life (the Challenger locomotive, with its high HP, can reach way above 200km/h!), thus removing the realism. Are you aware of these issues?

Yes, I am aware of those issues.
The fact that engines never reach their maximum speed, is caused by the traction handling. I implemented some tolerance value, such that when the speed is above the maximum speed plus the tolerance value, the engine brakes, if the speed is below the maximum speed minus the tolerance value, then it accelerates, and if the speed is between those values, the engine goes into cruise control (acceleration is kept at 0 if possible). The tolerance is actually needed to prevent the speed from bouncing up and down when the maximum speed is reached.*
I will try to find a way to get the maximum speeds up a little. It has to be finely tuned, since we also do not want the engines to go a little faster than the maximum speed.
The option to exceed the speed limit makes some powerful engines to go far beyond their maximum speed. I actually finetuned the force parameters (i.e. the numbers that control air drag, rolling resistance, etc.) so that the standard vehicles are just able to reach their maximum speed (for trains: that is with some wagons and cargo; some fully loaded road vehicles and extremely heavy trains may not reach their maximum speed). I found that the engines in some newgrf sets are a lot more powerful than the engines in the original set. This is causing them to go way faster than they were designed for.
I am considering to change this option to a cheat.
Fiddling around with the constants may cause the game to be unplayable with the original set, so I will not do this.
*This is caused by the following: If the speed is a little below maximum speed, the engine accelerates, and the speed increase above the maximum speed, but then the brakes are applied, and the speed is decreased to below the maximum speed. Then the whole process starts over again.
The fact that engines never reach their maximum speed, is caused by the traction handling. I implemented some tolerance value, such that when the speed is above the maximum speed plus the tolerance value, the engine brakes, if the speed is below the maximum speed minus the tolerance value, then it accelerates, and if the speed is between those values, the engine goes into cruise control (acceleration is kept at 0 if possible). The tolerance is actually needed to prevent the speed from bouncing up and down when the maximum speed is reached.*
I will try to find a way to get the maximum speeds up a little. It has to be finely tuned, since we also do not want the engines to go a little faster than the maximum speed.
The option to exceed the speed limit makes some powerful engines to go far beyond their maximum speed. I actually finetuned the force parameters (i.e. the numbers that control air drag, rolling resistance, etc.) so that the standard vehicles are just able to reach their maximum speed (for trains: that is with some wagons and cargo; some fully loaded road vehicles and extremely heavy trains may not reach their maximum speed). I found that the engines in some newgrf sets are a lot more powerful than the engines in the original set. This is causing them to go way faster than they were designed for.
I am considering to change this option to a cheat.
Fiddling around with the constants may cause the game to be unplayable with the original set, so I will not do this.
*This is caused by the following: If the speed is a little below maximum speed, the engine accelerates, and the speed increase above the maximum speed, but then the brakes are applied, and the speed is decreased to below the maximum speed. Then the whole process starts over again.
I have fixed the problems with engines not reaching their maximum speed. At least they will accelerate to the maximum speed or 1 km/h below (due to round-off errors).
Also, I have changed the order of the unit systems, so that the first three unit systems coincide with those of the unpatched version, to prevent having the wrong unit set when loading a savegame from an unpatched version into the patched version.
I also fixed a number of small GUI problems. The purchase windows for road vehicles and trains are a little bit larger, and (for trains) the powered wagons data is now split to two lines (to avoid text overflow).
Maybe there are some more little changes, but I can't exactly remember which.
There are two versions. One is to be patched against trunk, the other against the MiniIN branch. They should behave exactly the same. (If they don't, then it's a mistake.)
Also, I have changed the order of the unit systems, so that the first three unit systems coincide with those of the unpatched version, to prevent having the wrong unit set when loading a savegame from an unpatched version into the patched version.
I also fixed a number of small GUI problems. The purchase windows for road vehicles and trains are a little bit larger, and (for trains) the powered wagons data is now split to two lines (to avoid text overflow).
Maybe there are some more little changes, but I can't exactly remember which.
There are two versions. One is to be patched against trunk, the other against the MiniIN branch. They should behave exactly the same. (If they don't, then it's a mistake.)
- Attachments
-
- patch_physics_r5317-miniin_19-06-2006.patch
- Physics patch - version 19-jun-06 - r5317-MiniIN
- (135.45 KiB) Downloaded 376 times
-
- patch_physics_r5317_19-06-2006.patch
- Physics patch - version 19-jun-06 - r5317
- (135.66 KiB) Downloaded 354 times
A little update: I changed the curve handling a bit. Now not only the weight of the last vehicle in the curve is used for computing the maximum speed, but the maximum of the weights of all locomotives and carriages in the curve. I discovered that previously the front engine was not counted at all (since it is never the last vehicle on a curve). As a side effect, trains seem to be slower in curves; this is of course caused by the large weight of the locomotive(s), which get counted all the way through the curve, not only at the end.
To balance gameplay, I have increased some of the curve constants to compensate for the heavier effect of the curve handling.
Again, there is a version for the trunk and a version for the MiniIN.
To balance gameplay, I have increased some of the curve constants to compensate for the heavier effect of the curve handling.
Again, there is a version for the trunk and a version for the MiniIN.
- Attachments
-
- patch_physics_r5656-miniin_30-07-2006.patch
- Physics patch - version 30-jul-2006 - r5656-MiniIN
- (136.13 KiB) Downloaded 363 times
-
- patch_physics_r5656_30-07-2006.patch
- Physics patch - version 30-jul-2006 - r5656 (trunk)
- (135.77 KiB) Downloaded 344 times
Very nice patch, hertogjan, tranins and road vehicles travel very "fluently" with it I must say. The hills do tire them down though. 
Quite realistic.
One question though - why do maglevs get slowed down on the hills (to such extent) - is it really >>all<< just air resistance?
At any rate - I have posted more about this in the MiniIN topic together with richk67's reply.
S/Z

Quite realistic.
One question though - why do maglevs get slowed down on the hills (to such extent) - is it really >>all<< just air resistance?

At any rate - I have posted more about this in the MiniIN topic together with richk67's reply.
S/Z
NewGRF: Oil Wells in Temperate terrain now can Increase production, Better vehicle names, Use-able default aircraft, Oil Rig for Snowland and Desert, Speed for Suspension bridges.
Patches (OpenTTD): Improved smooth_economy [in trunk], More (diesel) smoke [in trunk], Realistic_acceleration finetune.
Keep 'em rollin'!
Patches (OpenTTD): Improved smooth_economy [in trunk], More (diesel) smoke [in trunk], Realistic_acceleration finetune.
Keep 'em rollin'!
Who is online
Users browsing this forum: No registered users and 1 guest