From 3994c66ca110e10e5ff8bc8ce7ef290e80f07dbc Mon Sep 17 00:00:00 2001 From: Denis Malkin Date: Fri, 7 Jul 2017 21:23:11 +0300 Subject: [PATCH] ADD control 'load the farthest first' feature when '!' symbol is appended to line name or convoi name --- simhalt.cc | 16 +++++++++++++--- simhalt.h | 2 +- vehicle/simvehicle.cc | 11 +++++++++-- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/simhalt.cc b/simhalt.cc index 286153d..380b885 100644 --- a/simhalt.cc +++ b/simhalt.cc @@ -1873,7 +1873,7 @@ bool haltestelle_t::recall_ware( ware_t& w, uint32 menge ) -void haltestelle_t::fetch_goods( slist_tpl &load, const goods_desc_t *good_category, uint32 requested_amount, const vector_tpl& destination_halts) +void haltestelle_t::fetch_goods( slist_tpl &load, const goods_desc_t *good_category, uint32 requested_amount, const vector_tpl& destination_halts, bool load_nearest_first) { // prissi: first iterate over the next stop, then over the ware // might be a little slower, but ensures that passengers to nearest stop are served first @@ -1881,8 +1881,18 @@ void haltestelle_t::fetch_goods( slist_tpl &load, const goods_desc_t *go vector_tpl *warray = cargo[good_category->get_catg_index()]; if( warray && !warray->empty() ) { - for( uint32 i=0; i < destination_halts.get_count(); i++ ) { - halthandle_t plan_halt = destination_halts[i]; + //remove duplicated halts + vector_tpl halts_remove_dup(destination_halts.get_count()); + for (uint32 i = 0; i < destination_halts.get_count(); i++) { + halthandle_t halt = destination_halts[i]; + halts_remove_dup.append_unique(halt); + } + + for( uint32 i = 0; i < halts_remove_dup.get_count(); i++ ) { + sint32 ind = load_nearest_first ? i : halts_remove_dup.get_count() - 1 - i; + halthandle_t plan_halt = halts_remove_dup[ind]; + + dbg->message("tt", "halt %s\n", plan_halt->get_name()); // The random offset will ensure that all goods have an equal chance to be loaded. uint32 offset = simrand(warray->get_count()); diff --git a/simhalt.h b/simhalt.h index a0f5816..4c51496 100644 --- a/simhalt.h +++ b/simhalt.h @@ -638,7 +638,7 @@ public: * @param sp Company that's requesting the fetch. * @author Dwachs */ - void fetch_goods( slist_tpl &load, const goods_desc_t *good_category, uint32 requested_amount, const vector_tpl& destination_halts); + void fetch_goods( slist_tpl &load, const goods_desc_t *good_category, uint32 requested_amount, const vector_tpl& destination_halts, bool load_nearest_first = false); /* liefert ware an. Falls die Ware zu wartender Ware dazugenommen * werden kann, kann ware_t gelöscht werden! D.h. man darf ware nach diff --git a/vehicle/simvehicle.cc b/vehicle/simvehicle.cc index 53d0211..696ca8a 100644 --- a/vehicle/simvehicle.cc +++ b/vehicle/simvehicle.cc @@ -751,12 +751,19 @@ uint16 vehicle_t::load_cargo(halthandle_t halt, const vector_tpl& const uint16 capacity_left = desc->get_capacity() - total_freight; if (capacity_left > 0) { + const char* convoi_name = cnv ? cnv->get_name() : ""; + const char* line_name = cnv && cnv->get_line().is_bound() ? cnv->get_line()->get_name() : ""; + bool load_nearest_first = false; + if ( (strlen(convoi_name) && convoi_name[strlen(convoi_name)-1] == '!') || + (strlen(line_name) && line_name[strlen(line_name)-1] == '!')) + load_nearest_first = true; + slist_tpl freight_add; - halt->fetch_goods( freight_add, desc->get_freight_type(), capacity_left, destination_halts); + halt->fetch_goods( freight_add, desc->get_freight_type(), capacity_left, destination_halts, load_nearest_first); if( freight_add.empty() ) { // now empty, but usually, we can get it here ... - return 0; + return 0; } for( slist_tpl::iterator iter_z = freight_add.begin(); iter_z != freight_add.end(); ) { -- 2.7.4