engineer(e),
train(t)
{
- set_size(200, 120);
+ set_size(200, 145);
GLtk::Label *label;
add(*(label=new GLtk::Label(res, "Train properties")));
add(*(ent_name=new GLtk::Entry(res)));
ent_name->set_geometry(GLtk::Geometry(10, geom.h-75, geom.w-20, 20));
+ add(*(drp_priority=new GLtk::Dropdown(res)));
+ drp_priority->set_geometry(GLtk::Geometry(10, geom.h-100, geom.w-20, 20));
+ drp_priority->append("Standard freight");
+ drp_priority->append("Express freight");
+ drp_priority->append("Unspecified");
+ drp_priority->append("Standard passenger");
+ drp_priority->append("Express passenger");
+ drp_priority->set_selected_index(train->get_priority()+2);
+
if(train)
{
ent_addr->set_text(lexical_cast(train->get_address()));
}
train->set_name(ent_name->get_text());
+ train->set_priority(drp_priority->get_selected_index()-2);
}
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())
{
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()));
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())
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);
const LocoType &loco_type;
unsigned address;
std::string name;
+ int priority;
std::vector<Vehicle *> vehicles;
std::list<BlockRef> cur_blocks;
std::list<BlockRef> rsv_blocks;
unsigned get_address() const { return address; }
void set_name(const std::string &);
const std::string &get_name() const { return name; }
+ void set_priority(int);
+ int get_priority() const { return priority; }
ControlModel &get_control() const { return *control; }
Vehicle &get_vehicle(unsigned);