|
@@ -19,32 +19,11 @@ const TRAIN_CAPACITY = 50;
|
19
|
19
|
|
20
|
20
|
const trainTexts: PIXI.Text[] = [];
|
21
|
21
|
|
22
|
|
-const isPointDistant = (point: PIXI.Point, stations: Station[], minDistance: number): boolean => {
|
23
|
|
- for (const station of stations) {
|
24
|
|
- if (distance(point, station.location) < minDistance) {
|
25
|
|
- return false;
|
26
|
|
- }
|
27
|
|
- }
|
28
|
|
- return true;
|
29
|
|
-};
|
30
|
|
-
|
31
|
|
-const randomDistantPoint = (stations: Station[], minDistance: number): PIXI.Point | null => {
|
32
|
|
- let tries = 100;
|
33
|
|
- while (tries > 0) {
|
34
|
|
- const point = randomPoint();
|
35
|
|
- if (isPointDistant(point, stations, minDistance)) {
|
36
|
|
- return point;
|
37
|
|
- }
|
38
|
|
- tries -= 1;
|
39
|
|
- }
|
40
|
|
- return null;
|
41
|
|
-};
|
42
|
|
-
|
43
|
22
|
const initStations = (numStations: number): Station[] => {
|
44
|
23
|
const stations: Station[] = [];
|
45
|
24
|
for (let i = 0; i < numStations; i += 1) {
|
46
|
25
|
stations.push(new Station(
|
47
|
|
- randomDistantPoint(stations, 30),
|
|
26
|
+ Station.randomDistantPoint(stations, 30),
|
48
|
27
|
randomInt(300, 2000),
|
49
|
28
|
tinycolor.random()));
|
50
|
29
|
}
|
|
@@ -82,12 +61,15 @@ const moveTrains = (trains: Train[], stations: Station[]) => {
|
82
|
61
|
if (pointsAlmostEqual(train.location, train.destination.location)) {
|
83
|
62
|
train.speed = 0;
|
84
|
63
|
|
|
64
|
+ // average destination color with passenger color weighted by ratio
|
|
65
|
+ // (a simulation of culture mixing)
|
85
|
66
|
train.destination.color = tinycolor.mix(
|
86
|
67
|
train.destination.color,
|
87
|
68
|
train.origin.color,
|
88
|
69
|
Math.round((train.passengers / train.destination.population) * 100),
|
89
|
70
|
);
|
90
|
71
|
|
|
72
|
+ // transfer passengers to destination
|
91
|
73
|
train.destination.population += train.passengers;
|
92
|
74
|
train.passengers = 0;
|
93
|
75
|
|