/// <summary> /// Loads the passengers from this train. /// This method should be called only by the Station.loadPassengers() method. /// </summary> public void loadPassengers(Station from, int n) { Debug.Assert(_passenger == 0); Debug.Assert(n <= passengerCapacity); _passenger = n; // memorize the location where passengers are loaded passengerSourceState = this.head.State.asPlaced(); notifyListeners(); }
/// <summary> /// /// /// </summary> /// <returns></returns> public override Direction Guide() { Train.TrainCar car = (Train.TrainCar)Voxel.car; CarState.Placed state = car.State.asPlaced(); Direction d = state.asInside().direction; if (hasRail(d)) { if (!hasRail(d.left) && !hasRail(d.right)) { // straight is the only option return(d); } // we have an option to either go straight or turn. Train.TrainCar previous = car.previous; if (previous == null) { // if this is the head car, ask the controoler if (car.parent.controller.onJunction(car.parent, this) == JunctionRoute.Straight) { return(d); // Go straight } } else { // otherwise follow the previous car if (previous.State.asPlaced().location == state.location + d) { return(d); } } // make a turn if (hasRail(d.left)) { return(d.left); } else { return(d.right); } } else { Direction l = d.left; if (hasRail(l)) { return(l); } Debug.Assert(hasRail(d.right)); return(d.right); } }
/// <summary> /// Unloads the passengers from this train. /// This method should be called only by the Station.unloadPassengers() method. /// </summary> /// <returns>number of unloaded passengers</returns> public int unloadPassengers() { int r = _passenger; _passenger = 0; if (passengerSourceState != null) { // compute the distance between the source state and the current state int dist = passengerSourceState.location. getDistanceTo(this.head.State.asPlaced().location); // record the sales AccountManager.theInstance.earn( r * type.Fare * dist / 5000, AccountGenre.RailService); passengerSourceState = null; } notifyListeners(); return(r); }