layout(l),
loco_type(t),
address(a),
+ priority(0),
pending_block(0),
control(new AIControl(*this, new SimplePhysics)),
timetable(0),
signal_name_changed.emit(name);
}
+void Train::set_priority(int p)
+{
+ priority = p;
+}
+
Vehicle &Train::get_vehicle(unsigned i)
{
if(i>=vehicles.size())
}
}
- if(active)
- reserve_more();
+ reserve_more();
signal_route_changed.emit(route);
}
{
st.push_back((DataFile::Statement("name"), name));
+ st.push_back((DataFile::Statement("priority"), priority));
+
for(vector<Vehicle *>::const_iterator i=vehicles.begin(); i!=vehicles.end(); ++i)
if(i!=vehicles.begin())
st.push_back((DataFile::Statement("vehicle"), (*i)->get_type().get_article_number()));
if(pure_speed)
{
- RealSpeed &rs = real_speed[current_speed];
- rs.add(travel_dist/travel_time_secs, travel_time_secs);
+ if(current_speed)
+ {
+ RealSpeed &rs = real_speed[current_speed];
+ rs.add(travel_dist/travel_time_secs, travel_time_secs);
+ }
set_status(format("Traveling %d kmh", get_travel_speed()));
}
unsigned Train::reserve_more()
{
+ if(!active)
+ return 0;
+
BlockRef *last = 0;
if(!rsv_blocks.empty())
last = &rsv_blocks.back();
else if(route && route->get_tracks().count(entry_ep.track))
cur_route = route;
- if(!link->reserve(this))
+ bool reserved = link->reserve(this);
+ if(!reserved)
{
- // If we found another train and it's not headed straight for us, we can keep the blocks we got
- int other_entry = link->get_train()->get_entry_to_block(*link);
- if(other_entry<0)
- throw LogicError("Block reservation inconsistency");
- if(static_cast<unsigned>(entry)!=link->traverse(other_entry))
+ // Ask a lesser priority train to free the block for us
+ if(link->get_train()->get_priority()<priority)
+ if(link->get_train()->free_block(*link))
+ reserved = link->reserve(this);
+
+ if(!reserved)
{
- good = last;
- good_sens = nsens;
+ // If we found another train and it's not headed straight for us, we can keep the blocks we got
+ int other_entry = link->get_train()->get_entry_to_block(*link);
+ if(other_entry<0)
+ throw LogicError("Block reservation inconsistency");
+ if(static_cast<unsigned>(entry)!=link->traverse(other_entry))
+ {
+ good = last;
+ good_sens = nsens;
+ }
+ pending_block = link;
+ break;
}
- pending_block = link;
- break;
}
if(link->get_turnout_id())
if(!high)
{
if(!low)
- return 0;
+ {
+ if(real)
+ return 3;
+ else
+ return 0;
+ }
return min(static_cast<unsigned>(low*real/real_speed[low].speed), 14U);
}
add("block", &Loader::block);
add("block_hint", &Loader::block_hint);
add("name", &Loader::name);
+ add("priority", &Train::priority);
add("real_speed", &Loader::real_speed);
add("route", &Loader::route);
add("timetable", &Loader::timetable);