]> git.tdb.fi Git - r2c2.git/commitdiff
Fix a compile error
authorMikko Rasa <tdb@tdb.fi>
Sat, 24 Apr 2010 18:04:08 +0000 (18:04 +0000)
committerMikko Rasa <tdb@tdb.fi>
Sat, 24 Apr 2010 18:04:08 +0000 (18:04 +0000)
Handle a null train properly in TrainProperties constructor
Print emergencies to stdout
Report sensor number in unreserved sensor triggers
Never update real_speed[0]
Return a nonzero value if no speeds are recorded yet

source/engineer/trainproperties.cpp
source/libmarklin/layout.cpp
source/libmarklin/train.cpp

index 748b0c9560ac5ec0a963d9ebd83893a9e0409855..4596000724a204bff97b9c53a685d973318cf511 100644 (file)
@@ -57,15 +57,18 @@ TrainProperties::TrainProperties(Engineer &e, const GLtk::Resources &r, Train *t
        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()));
                ent_name->set_text(train->get_name());
+               drp_priority->set_selected_index(train->get_priority()+2);
        }
        else
+       {
                ent_name->set_text(format("Train %d", engineer.get_layout().get_trains().size()+1));
+               drp_priority->set_selected_index(2);
+       }
 }
 
 void TrainProperties::on_ok_clicked()
index e67fbc26ebc0443440900293bd72555184e439f0..97297410c25d4188b7e54d6e13c5c7e77ee9d3ad 100644 (file)
@@ -9,6 +9,7 @@ Distributed under the GPL
 #include <msp/core/refptr.h>
 #include <msp/datafile/parser.h>
 #include <msp/datafile/writer.h>
+#include <msp/io/print.h>
 #include <msp/time/utils.h>
 #include "block.h"
 #include "catalogue.h"
@@ -216,6 +217,7 @@ void Layout::emergency(const string &msg)
 {
        if(driver)
                driver->halt(true);
+       IO::print("Emergency: %s\n", msg);
        signal_emergency.emit(msg);
 }
 
@@ -370,7 +372,7 @@ void Layout::sensor_event(unsigned addr, bool state)
                        if((*i)->get_sensor_id()==addr)
                        {
                                if(!(*i)->get_train())
-                                       emergency("Unreserved sensor triggered");
+                                       emergency(format("Unreserved sensor %d triggered", addr));
                                break;
                        }
        }
index 9f97c33182160b9053573cf0fa40115660189199..efe1a142cb6daefc29162f1a99bd578f55de7f9b 100644 (file)
@@ -523,8 +523,11 @@ void Train::sensor_event(unsigned addr, bool state)
 
                        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()));
                        }
 
@@ -630,7 +633,7 @@ void Train::block_reserved(const Block &block, const Train *train)
 unsigned Train::reserve_more()
 {
        if(!active)
-               return;
+               return 0;
 
        BlockRef *last = 0;
        if(!rsv_blocks.empty())
@@ -834,7 +837,12 @@ unsigned Train::find_speed(float real) const
        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);
        }