### Author Topic: Average speed logic error?  (Read 1978 times)

0 Members and 1 Guest are viewing this topic.

• Devotees (Inactive)
• Posts: 482
• Languages: EN, RU
##### Average speed logic error?
« on: October 23, 2010, 04:38:43 PM »
Suppose we have just arrived convoy.
Code: [Select]
`convoy.state = LOADING`somewhere.
Code: [Select]
` case LOADING:            laden();`Here
Code: [Select]
`void convoi_t::laden() //"load" (Babelfish){    //Calculate average speed    //@author: jamespetts    const uint32 journey_distance = accurate_distance(fahr[0]->get_pos().get_2d(), fahr[0]->last_stop_pos);    const double journey_time = (welt->get_zeit_ms() - last_departure_time) / 4096.0F;    const uint16 average_speed = ((double)journey_distance / journey_time) * 20.0;    book(average_speed, CONVOI_AVERAGE_SPEED);    last_departure_time = welt->get_zeit_ms();    // Recalculate comfort    book(get_comfort(), CONVOI_COMFORT);    for(uint8 i = 0; i < anz_vehikel; i++)    {        // Accumulate distance         slist_iterator_tpl<ware_t> iter_cargo(fahr[i]->get_fracht());        while(iter_cargo.next())        {            iter_cargo.access_current().add_distance(journey_distance);        }    }`All good.
So journey_time will be small (it just next cycle!), and average_speed will be very big. And it will be booked.

Maybe we need another state for this? (ARRIVED).
Edit: journey_distance for cargo will be added each time too.
« Last Edit: October 23, 2010, 04:48:23 PM by inkelyad »

#### jamespetts

• Simutrans-Extended project coordinator
• Moderator
• Posts: 18763
• Cake baker
• Languages: EN
##### Re: Average speed logic error?
« Reply #1 on: October 23, 2010, 05:22:02 PM »
Thank you very much for reporting this. Before I make big changes to try to fix it - can you reproduce the actual problem in practice?