#include "driver.h"
#include "layout.h"
#include "route.h"
-#include "simplephysics.h"
+#include "simplecontroller.h"
#include "timetable.h"
#include "tracktype.h"
#include "train.h"
address(a),
priority(0),
pending_block(0),
- control(new AIControl(*this, new SimplePhysics)),
+ controller(new AIControl(*this, new SimpleController)),
timetable(0),
active(false),
current_speed(0),
layout.get_driver().signal_halt.connect(sigc::mem_fun(this, &Train::halt_event));
- control->signal_control_changed.connect(sigc::mem_fun(this, &Train::control_changed));
+ controller->signal_control_changed.connect(sigc::mem_fun(this, &Train::control_changed));
}
Train::~Train()
{
- delete control;
+ delete controller;
delete timetable;
for(vector<Vehicle *>::iterator i=vehicles.begin(); i!=vehicles.end(); ++i)
delete *i;
void Train::set_control(const string &n, float v)
{
- control->set_control(n, v);
+ controller->set_control(n, v);
}
void Train::set_active(bool a)
{
if(a==active)
return;
- if(!a && control->get_speed())
+ if(!a && controller->get_speed())
throw InvalidState("Can't deactivate while moving");
active = a;
float Train::get_control(const string &ctrl) const
{
- return control->get_control(ctrl).value;
+ return controller->get_control(ctrl).value;
}
float Train::get_speed() const
{
- return control->get_speed();
+ return controller->get_speed();
}
bool Train::get_function(unsigned func) const
void Train::place(Block &block, unsigned entry)
{
- if(control->get_speed())
+ if(controller->get_speed())
throw InvalidState("Must be stopped before placing");
release_blocks(rsv_blocks);
else
{
const Block::Endpoint &bep = block.get_endpoints()[entry];
- vehicles.front()->place(bep.track, bep.track_ep, 0, Vehicle::BACK_BUFFER);
+ vehicles.back()->place(bep.track, bep.track_ep, 0, Vehicle::BACK_BUFFER);
}
}
if(timetable)
timetable->tick(t);
- control->tick(dt);
- float speed = control->get_speed();
+ controller->tick(dt);
+ float speed = controller->get_speed();
unsigned speed_notch = find_speed(speed);
- if(control->get_reverse()!=reverse)
+ if(controller->get_reverse()!=reverse)
{
- reverse = control->get_reverse();
+ reverse = controller->get_reverse();
driver.set_loco_reverse(address, reverse);
release_blocks(rsv_blocks);
unsigned entry = bep.track_ep;
bool found = false;
- float dist = veh.get_offset()-veh.get_type().get_length()/2;
+ float dist = veh.get_offset();
+ if(reverse)
+ dist = veh.get_track()->get_type().get_path_length(veh.get_track()->get_active_path())-dist;
+ dist -= veh.get_type().get_length()/2;
while(1)
{
if(track==veh.get_track())
}
}
-void Train::control_changed(const TrainControl &ctrl)
+void Train::control_changed(const Controller::Control &ctrl)
{
signal_control_changed.emit(ctrl.name, ctrl.value);
}