def go_to_ladder(self): self.time_to_away = settings.PASSENGERS['TIME_TO_AWAY'] self.x = sign(self.x) * settings.BUILDING['LADDER_POSITION'] self.state = self.PASSENGER_STATE['moving_to_floor'] if self.elevator: if self in self.elevator.passengers: self.elevator.passengers.remove(self) self.elevator = None
def on_tick(self): if self.time_to_away == 0 and self.may_go_to_ladder(): self.go_to_ladder() return if self.may_go_to_ladder(): self.time_to_away -= 1 if self.state == self.PASSENGER_STATE['waiting_for_elevator']: if self.elevator: self.state = self.PASSENGER_STATE['moving_to_elevator'] return if self.state == self.PASSENGER_STATE['moving_to_elevator']: if self.elevator.floor == self.floor and self.elevator.is_filling(): if abs(self.x - self.elevator.x) >= self.speed: self.move(x=sign(self.elevator.x - self.x)) elif self.elevator.floor == self.from_floor and self.elevator.can_enter(): self.elevator.enter(self) self.state = self.PASSENGER_STATE['using_elevator'] else: self.elevator = None self.state = self.PASSENGER_STATE['returning'] else: self.elevator = None self.state = self.PASSENGER_STATE['returning'] return if self.state == self.PASSENGER_STATE['moving_to_floor']: dest_floor = self.dest_floor if self.y < dest_floor: self.move(y=1. / settings.PASSENGERS["SPEED"]["UP"]) elif self.y > dest_floor: self.move(y=-1. / settings.PASSENGERS["SPEED"]["DOWN"]) self.time_to_floor -= 1 if self.time_to_floor == 0: self.arrived_to_floor(dest_floor) return if self.state == self.PASSENGER_STATE['returning']: if self.elevator: self.state = self.PASSENGER_STATE['moving_to_elevator'] base_x = self.get_base_x() if abs(base_x - self.x) > self.speed: self.move(x=-sign(self.x - base_x)) else: self.x = base_x self.state = self.PASSENGER_STATE['waiting_for_elevator'] return if self.state == self.PASSENGER_STATE['using_elevator']: return if self.state == self.PASSENGER_STATE['exiting']: self.move_to_floor -= 1 if self.move_to_floor == 0: self.move_to_floor = settings.PASSENGERS['MOVE_TO_FLOOR'] if self.floor == 0 or len(self.floors_queue) == 0: self.state = self.PASSENGER_STATE['for_delete'] return self.state = self.PASSENGER_STATE['walking_on_floor'] self.from_floor = self.floor self.dest_floor = self.floors_queue.pop(0) return self.move(x=sign(self.x)) return if self.state == self.PASSENGER_STATE['walking_on_floor']: if self.walking_time == 0: self.walking_time = settings.PASSENGERS['WALKING_TIME'] self.state = self.PASSENGER_STATE['waiting_for_elevator'] self.time_to_away = settings.PASSENGERS['TIME_TO_AWAY'] self.x = self.get_base_x() self.elevator = None return self.walking_time -= 1 return