speed_quantizer = new SpeedQuantizer(speed_steps);
vehicles.push_back(new Vehicle(layout, loco_type));
+ vehicles.back()->set_train(this);
layout.add_train(*this);
Vehicle *veh = new Vehicle(layout, vt);
vehicles.back()->attach_back(*veh);
vehicles.push_back(veh);
+ veh->set_train(this);
}
void Train::remove_vehicle(unsigned i)
Vehicle *veh = new Vehicle(obj.layout, vtype);
obj.vehicles.back()->attach_back(*veh);
obj.vehicles.push_back(veh);
+ veh->set_train(&obj);
}
} // namespace R2C2
Vehicle::Vehicle(Layout &l, const VehicleType &t):
Object(l),
type(t),
+ train(0),
next(0),
prev(0),
front_sensor(0),
return veh;
}
+void Vehicle::set_train(Train *t)
+{
+ train = t;
+}
+
void Vehicle::attach_back(Vehicle &veh)
{
if(next || veh.prev)
namespace R2C2 {
class Layout;
+class Train;
class attachment_error: public std::logic_error
{
};
const VehicleType &type;
+ Train *train;
Vehicle *next;
Vehicle *prev;
TrackPosition track_pos;
virtual Vehicle *clone(Layout * = 0) const;
virtual const VehicleType &get_type() const { return type; }
+ void set_train(Train *);
+ Train *get_train() const { return train; }
void attach_back(Vehicle &);
void attach_front(Vehicle &);
void detach_back();