Add Elevator Number to Elevators
[cs356-p1-elevator.git] / elevator.cpp
index e50ee2e..4a5eb37 100644 (file)
@@ -1,21 +1,23 @@
 #include "elevator.hpp"
 
-Elevator::Elevator ()
+Elevator::Elevator (int elevator_number)
        : state_(STATE_IDLE)
        , wait_(0)
        , direction_(IDLE)
        , position_()
        , stops_()
+       , number_(elevator_number)
 {
        // Intentionally Left Empty
 }
 
-Elevator::Elevator (int starting_floor)
+Elevator::Elevator (int starting_floor, int elevator_number)
        : state_(STATE_IDLE)
        , wait_(0)
        , direction_(IDLE)
        , position_(starting_floor)
        , stops_()
+       , number_(elevator_number)
 {
        // Intentionally Left Empty
 }
@@ -92,6 +94,23 @@ float Elevator::distance_from (Position &pos) const
        return pos - position_;
 }
 
+float Elevator::distance_from (Stop &s) const
+{
+       Direction d = s.getDirection();
+       Position  p = s.getPosition ();
+
+       /* If direction doesn't matter, then only position does */
+       if (d == ALL || direction_ == IDLE)
+               return distance_from (p);
+
+       /* If we're not in the same direction, then we're "really far" away */
+       if (d != direction_)
+               return INT_MAX;
+
+       /* We must be in the correct direction, so pure distance is fine */
+       return distance_from (p);
+}
+
 void Elevator::transition_move_up ()
 {
        direction_ = UP;
@@ -145,7 +164,7 @@ void Elevator::transition_open_door ()
        else
                stops_.remove (Stop(position_, direction_));
 
-       // TODO: Call into GUI to open the door
+       // TODO: Call into the GUI to open the door
        std::cout << "Opening Door" << std::endl;
 }