-/* $Id$
-
-This file is part of R²C²
-Copyright © 2006-2011 Mikkosoft Productions, Mikko Rasa
-Distributed under the GPL
-*/
-
#include <algorithm>
#include <cmath>
-#include <msp/strings/formatter.h>
+#include <msp/core/maputils.h>
+#include <msp/strings/format.h>
#include <msp/time/units.h>
#include <msp/time/utils.h>
#include "aicontrol.h"
overshoot_dist(false)
{
if(!loco_type.is_locomotive())
- throw InvalidParameterValue("Initial vehicle must be a locomotive");
+ throw invalid_argument("Train::Train");
unsigned speed_steps = layout.get_driver().get_protocol_speed_steps(protocol);
if(speed_steps)
void Train::remove_vehicle(unsigned i)
{
if(i>=vehicles.size())
- throw InvalidParameterValue("Vehicle index out of range");
+ throw out_of_range("Train::remove_vehicle");
if(i==0)
- throw InvalidParameterValue("Can't remove the locomotive");
+ throw logic_error("can't remove locomotive");
delete vehicles[i];
vehicles.erase(vehicles.begin()+i);
if(i<vehicles.size())
Vehicle &Train::get_vehicle(unsigned i)
{
if(i>=vehicles.size())
- throw InvalidParameterValue("Vehicle index out of range");
+ throw out_of_range("Train::get_vehicle");
return *vehicles[i];
}
const Vehicle &Train::get_vehicle(unsigned i) const
{
if(i>=vehicles.size())
- throw InvalidParameterValue("Vehicle index out of range");
+ throw out_of_range("Train::get_vehicle");
return *vehicles[i];
}
if(a==active)
return;
if(!a && controller->get_speed())
- throw InvalidState("Can't deactivate while moving");
+ throw logic_error("moving");
active = a;
if(active)
void Train::set_function(unsigned func, bool state)
{
if(!loco_type.get_functions().count(func))
- throw InvalidParameterValue("Invalid function");
+ throw invalid_argument("Train::set_function");
layout.get_driver().set_loco_function(address, func, state);
}
bool Train::divert(Track &from)
{
if(!from.get_turnout_id())
- throw InvalidParameterValue("Can't divert from a non-turnout");
+ throw invalid_argument("Train::divert");
if(routes.empty())
return false;
if(end!=routes.end())
break;
else if(!diversion->has_track(*track))
- throw LogicError("Pathfinder returned a bad route");
+ throw logic_error("bad diversion");
track = track.next(diversion->get_path(*track));
}
void Train::place(Block &block, unsigned entry)
{
if(controller->get_speed())
- throw InvalidState("Must be stopped before placing");
+ throw logic_error("moving");
release_blocks();
void Train::unplace()
{
if(controller->get_speed())
- throw InvalidState("Must be stopped before unplacing");
+ throw logic_error("moving");
release_blocks();
if(controller->get_reverse()!=reverse)
{
reverse = controller->get_reverse();
- driver.set_loco_reverse(address, reverse);
+ bool r = reverse;
+ if(loco_type.get_swap_direction())
+ r = !r;
+ driver.set_loco_reverse(address, r);
release_blocks(cur_blocks_end, blocks.end());
reverse_blocks(blocks);
if(addr==address)
{
current_speed_step = speed;
- if(rev!=reverse)
- layout.get_driver().set_loco_reverse(address, reverse);
+ bool r = reverse;
+ if(loco_type.get_swap_direction())
+ r = !r;
+ if(rev!=r)
+ layout.get_driver().set_loco_reverse(address, r);
speed_changing = false;
pure_speed = false;
}
Train *other_train = block->get_train();
int other_entry = other_train->get_entry_to_block(*block);
if(other_entry<0)
- throw LogicError("Block reservation inconsistency");
+ throw logic_error("block reservation inconsistency");
unsigned exit = block.reverse().entry();
unsigned other_exit = BlockIter(block.block(), other_entry).reverse().entry();
Train::Loader::Loader(Train &t):
- DataFile::BasicLoader<Train>(t),
+ DataFile::ObjectLoader<Train>(t),
prev_block(0),
blocks_valid(true)
{
{
blk = &obj.layout.get_block(id);
}
- catch(const KeyError &)
+ catch(const key_error &)
{
blocks_valid = false;
return;
{
prev_block = &obj.layout.get_block(id);
}
- catch(const KeyError &)
+ catch(const key_error &)
{
blocks_valid = false;
}