X-Git-Url: https://irasnyder.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=elevator.cpp;h=d4e7cfb6c4d9eafcbd2614fb936e642864cf6f96;hb=0f2350d5ad9a6bc431bbcce84e8b61a784328bea;hp=e50ee2e4c0805085c5aa2e462baa5923c6b24044;hpb=7d98e6f33037bde7cd6d0cac4c1bfff5ba214e75;p=cs356-p1-elevator.git diff --git a/elevator.cpp b/elevator.cpp index e50ee2e..d4e7cfb 100644 --- a/elevator.cpp +++ b/elevator.cpp @@ -92,6 +92,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 +162,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; }