1 #include "elevator.hpp"
10 // Intentionally Left Empty
13 bool Elevator::currently_at_stop () const
15 StopList::const_iterator it;
16 Stop current(current_position_, direction_);
18 for (it = stops_.begin (); it != stops_.end (); it++)
25 void Elevator::stop_at (Stop &stop)
27 StopList::iterator it;
29 /* If this is an "ALL" Stop, it supercedes all others */
30 if (stop.getDirection() == ALL)
33 stops_.push_back (stop);
37 /* Check if this stop already exists. If so, just leave */
38 for (it = stops_.begin(); it != stops_.end(); it++)
42 /* The stop did not already exist, so add it */
43 stops_.push_back (stop);
46 float Elevator::distance_from (Position &pos) const
48 if (current_position_ > pos)
49 return current_position_ - pos;
51 return pos - current_position_;
54 void Elevator::move ()
58 /* Wait around if we need to.
60 * This is an artificial delay to make the elevators work in a
61 * much more natural fashion. This allows some delay to leave the
62 * doors open, or for the user to press floor selection buttons
63 * before the elevator starts moving
71 /* close the door if it is open. This is a requirement to move */
79 if (currently_at_stop ())
81 wait = 10; // delay around for 10 steps
82 stops_.remove (Stop(current_position_, direction_));
83 open_door (); // call into the GUI to open the door
87 /* Calculate the number of Stops above and below our
89 StopList::const_iterator it;
90 Stop current = Stop(current_position_, direction_);
94 for (it = stops_.begin(); it != stops_.begin(); it++)
103 /* Check if we need to change direction */
104 if (direction_ == UP && stops_above == 0 && stops_below > 0)
107 if (direction_ == DOWN && stops_below == 0 && stops_above > 0)
110 if (stops_above == 0 && stops_below == 0)
114 /* Move in the correct direction */
120 current_position_ += ELEVATOR_STEP;
123 current_position_ -= ELEVATOR_STEP;
126 std::cout << __FILE__ << ":" << __LINE__ << " Unhandled Elevator Position" << std::endl;
130 /* Call the GUI with our updated position */
134 bool Elevator::is_idle () const
136 return direction_ == IDLE;
139 void Elevator::update_position () const
141 std::cout << "Updating the GUI with our position" << std::endl;
144 void Elevator::open_door () const
146 std::cout << "Opening Door" << std::endl;
149 void Elevator::close_door () const
151 std::cout << "Closing Door" << std::endl;
158 /* vim: set ts=4 sts=4 sw=4 noexpandtab textwidth=112: */