Patch: fix calculation of convoi length February 23, 2010, 07:48:11 pm .. this patch fixes the calculation of convoi length, that is: in depot window the length of the convoi is sometimes incorrect (aka required station length). That means that convois that should fit in 1 station tile actually need 2 station tiles sometimes (for instance the early road trains in pakBritain 4 vehicles with len=4, but also train with locomotive len=8 and 8 wagons len=7 needs 5 tiles instead of 4, which a convoi with 8 vehicles of len=8 needs). This is partly due to the behavior discussed here:http://forum.simutrans.com/index.php?topic=3376.0This fix is only presentational. It now shows the maximum number of station tiles really needed. Quote Selected Last Edit: February 26, 2010, 03:55:49 pm by IgorTekton
Re: Patch: fix calculation of convoi length Reply #1 – February 23, 2010, 09:50:12 pm That is a pure bugfix. Incorporated, thanks! Quote Selected
Re: Patch: fix calculation of convoi length Reply #2 – February 24, 2010, 01:13:01 am shouldn't this be return (tiles*16 + 256-16 + 127)/256;rather than return (tiles*16 + 256-1 + 127)/256;? Quote Selected
Re: Patch: fix calculation of convoi length Reply #3 – February 24, 2010, 06:19:30 am No. The following train needs 3 station tiles, but your suggestion would calculate 2: four vehicles with lengths 9,8,8,X. Driving north/west this train needs 3 tiles in a station. Quote Selected
Re: Patch: fix calculation of convoi length Reply #4 – February 24, 2010, 11:28:43 am Well, the formula used to calculate the loading length is much simpler.count all stations tiles => tilemultiply by 16.substrate next cars length until is below zeroThus a road train of four vehicles needs one tile.A 9+8+8+X train need always only two tiles for X<=7.A 8+8+0+0 train needs one tile (that was wrong in the old calculation)(see simconvoi.cc 2357)Thus the calculation should be:Code: [Select]sint16 tiles=16, no_of_tiles=1;// the last vehicle does not count!for(sint8 i=0; i<anz_vehikel-1; i++) { tiles -= fahr[i]->get_besch()->get_length(); if( tiles<0 ) { tiles += 16; number_of_tiles ++; }}This should do the same stuff as the station hat_gehalten() code. It works without any 127tel Quote Selected
Re: Patch: fix calculation of convoi length Reply #5 – February 24, 2010, 12:03:53 pm I dont get it. Is the routine (as it is now in trunk) wrong or not??Quote from: prissi – on February 24, 2010, 11:28:43 amThus a road train of four vehicles needs one tile.A 9+8+8+X train need always only two tiles for X<=7.A 8+8+0+0 train needs one tile (that was wrong in the old calculation)(see simconvoi.cc 2357)Actually, this is how it should be (lengths are added and divided by 16). But the reality (the movement code) is different!At first, the last vehicle does not count, that is a train 9+8+8+X always needs the same station tiles regardless what value X has. (This can be cured by adding a 0-length wagon to each convoi.) Second, convois driving north/west when entering a station need a halt tile more (precisely 127/256 of a tile). This is where your proposed code fails.The result is the following:(a) a train 8-8 needs one tile (regardless of driving direction)(b) a train 8-8-0 needs two tiles if driving n/w, now the second wagon counts! ( I did not test this. The third wagon is behind the second (obviously), that is if driving n/w it is on the second station tile)(c) a (road) train 4-4-4 needs one tile(d) a (road) train 4-4-4-4 needs two tiles if driving n/w, now the second wagon counts! When driving s/e one tile suffices.(e) the 9-8-8-X needs 3 station tiles when driving n/w Quote Selected
Re: Patch: fix calculation of convoi length Reply #6 – February 24, 2010, 02:23:54 pm The loading is not based on the movement code. It is solely based on the above calculations. This was explicitely introduced to avoid convois loading more vehicles in one direction compared to the other as it happenend in old games with vehicle length!=8. It will even load vehicles which sees to be not in station to avoid different loading length. See simconvoi_t::hat_gehalten().The road trains from pak-britain should get always loaded. There was a bug report half a year ago or so where I changed the loading to correct for this error. As such, the current display routine is wrong (but the old one was wrong too ). Quote Selected
Re: Patch: fix calculation of convoi length Reply #7 – February 24, 2010, 02:58:34 pm Ah, I understand now.But the new display routine should be right in showing the needed station tiles such that the whole convoi fits into the station and does not reserve a tile behind the station. Which is the case for instance for the 4x4 pak.Britain road trains. Quote Selected
Re: Patch: fix calculation of convoi length Reply #8 – February 24, 2010, 09:33:26 pm That cannot be solved properly. The indicator is showing the station tiles for loading. I think one cannot win this: either car are not loaded but are in the station or everything will be loaded as expected, but they will be in unexpected positions sometimes. Quote Selected