-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPassenger.py
67 lines (52 loc) · 1.43 KB
/
Passenger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from __future__ import division;
import collections;
import math;
import random;
import Data;
import Service;
import Station;
class Passenger:
def __init__(self, pos):
self.pos = pos;
self.route = [];
self.MakeRoute();
def AddStop(self):
# the previous stop
last = self.route[-1];
# find a new train
departures = [x for x in last[1].DeparturesFrom(last[0])];
if len(departures) < 1:
return;
service = random.choice(departures);
# find all the stops after we can board
stops = [];
boarded = False;
for stop in Service.services[service].orders:
if last[1].HasPlatform(Data.places[Data.Place(stop[1])]):
boarded = True;
elif not boarded:
continue;
else:
stops.append(stop);
# if there are no stops after this, give up
if len(stops) < 1:
return;
# find a new station
new = random.choice(stops);
station = Data.nodes[Data.places[Data.Place(new[1])]].station;
# make sure we actually stop there
if station == None:
return;
self.route.append((new[0], station, service));
def MakeRoute(self):
self.route = [(Data.frameTime, self.pos, None)];
self.AddStop();
# about 4 stops (pos, next, approx 2 more)
while random.random() < 0.5:
self.AddStop();
def ShouldEmbark(self, train):
if len(self.route) == 1:
return False;
return self.route[1][2] in train.serviceNames;
def ShouldDisembark(self, node):
return node.station == self.route[0][1];