What controls the order in which vehicles are drawn in a convoy? February 28, 2009, 04:43:37 pm I am looking to add a feature to Simutrans-Experimental allowing trains to run backwards (i.e., with the last vehicle first), and have differential delays for reversing trains depending on whether they can run backwards or not. In order to do so, I need to know how the code determines the order in which to draw vehicles in a convoy; can anyone point me in the right direction? Quote Selected
Re: What controls the order in which vehicles are drawn in a convoy? Reply #1 – February 28, 2009, 05:20:53 pm In Simutrans everything is drawn tile-based. Individual members of a convoy are saved on different tiles. All vehicles are sorted on a tile to minimize drawing errors, see dingliste::intern_insert_moving(). Quote Selected
Re: What controls the order in which vehicles are drawn in a convoy? Reply #2 – February 28, 2009, 05:25:10 pm Dwachs,thank you for the information - most helpful. I am not quite sure what you mean by "all vehicles are sorted on a tile", though - can you elaborate a little?Edit: I cannot find dingliste::intern_insert_moving(), or indeed any string in the entire project containing "insert_moving"; is that the correct name?Edit 2: I have found Code: [Select]bool dingliste_t::intern_add_moving(ding_t* ding)but no call is made to that method in either simvehikel.cc or simconvoi.cc - are you sure that this method is used for ordering of vehicles in convoys? The comments in the code refer to citycars. Quote Selected Last Edit: February 28, 2009, 05:29:49 pm by jamespetts
Re: What controls the order in which vehicles are drawn in a convoy? Reply #3 – February 28, 2009, 08:08:58 pm This code add things to a tile. Moving things belong to convois, but could be citycars or pedetrians. This routine handles it all. It will do right also if you go backewards, as long as the ribis are ok. (However, the convoi routines would do much better, if you just reaarange the convoi when revering and set the first and last flag correctly.) Quote Selected
Re: What controls the order in which vehicles are drawn in a convoy? Reply #4 – February 28, 2009, 08:22:58 pm Prissi,thank you very much! I had already worked out about using a reversing algorithm to reverse the order of the vehicles in the convoy array, but was having many problems because I was not aware of the first and last flags, which I have now solved thanks to your post. You have been most helpful. For reference, here is the code:Code: [Select]voidconvoi_t::reverse_order(){ // Code snippet obtained and adapted from: // http://www.cprogramming.com/snippets/show.php?tip=15&count=30&page=0 // by John Shao (public domain work) uint8 a = 0; vehikel_t* reverse; uint8 b = anz_vehikel; fahr[0]->set_erstes(false); fahr[anz_vehikel - 1]->set_letztes(false); for(a;a<--b;a++) //increment a and decrement b until they meet eachother { reverse = fahr[a]; //put what's in a into swap space fahr[a] = fahr[b]; //put what's in b into a fahr[b] = reverse; //put what's in the swap (a) into b } fahr[0]->set_erstes(true); fahr[anz_vehikel - 1]->set_letztes(true);}Thank you again :-) Quote Selected
Re: What controls the order in which vehicles are drawn in a convoy? Reply #5 – February 28, 2009, 10:25:25 pm Before you do this, you should clear all reservations, because only the last vehicel will clear it. With this, reservations might be left. (But hard to guess from pseudocode.) Quote Selected
Re: What controls the order in which vehicles are drawn in a convoy? Reply #6 – February 28, 2009, 11:06:26 pm Thank you for that suggestion :-) I did initially have problems with reservations, but they went away when I reset the flags for leading and trailing vehicles. Quote Selected