/* passenger.h
 *
 * The passenger class.  A passenger appears at a source station with
 * a sequence of destination stations to which the passenger must
 * travel.  If the list has one station, the passenger leaves the
 * system at that station.  If the list has more than one station,
 * the passenger gets off the train and transfers at each intermediate
 * station.
 *
 * The passenger is initially added to a platform list, then
 * transferred to a train list, then transferred into a station upon
 * arrival.
 */


#ifndef PASSENGER_H
#define PASSENGER_H

#include "seq.h"
#include "train.h"
#include "main.h"

class Station;


class Passenger {

  friend class Statistics;

  static int nextIdent;		// for generating passenger idents

  Station* source;		// starting station
  Station* destination;		// ending station
  float startingTime;		// time of trip start
  int ident;			// unique passenger identifier

public:

  Station* nextStation;		// next station on route

  // Constructor

  Passenger( Station *src, Station* dest ) {

    source = src;
    destination = dest;
    ident = nextIdent++;
    startingTime = currentTime;
  }
  
  // Returns true iff the passenger wants to enter a particular train,
  // t, that has stopped at the platform.  This is the case if the
  // train is stopping at the passenger's next destination.

  bool wantsToEnterTrain( Train *t ) {
    return t->isStoppingAtStation( nextStation );
  }

  // Returns true iff the passenger wants to leave the train when it
  // arrives at a particular station, s.  This is the case if this
  // station is the passenger's next destination.

  bool wantsToLeaveTrain( Station *s ) {
    return s == nextStation;
  }
  
  // Access functions

  float startTime() { return startingTime; }
  Station * destStation() { return destination; }
  Station * sourceStation() { return source; }

  // Output operator

  friend ostream& operator << ( ostream& stream, Passenger const &p ) {
    stream << "P" << p.ident;
    return stream;
  }
};

#endif
