@@ -229,7 +229,8 @@ module Train_update = struct
229
229
delivery to station, print revenue
230
230
*)
231
231
232
- let _enter_station (v :t ) idx (train : rw Train.t ) station loc =
232
+ let _enter_station (v :t ) idx (train : rw Train.t ) stations loc =
233
+ let station = Station_map. get_exn loc stations in
233
234
(* TODO: income handling *)
234
235
let last_station, priority_stop, stop, train, _income, ui_msgs =
235
236
if Station. is_proper_station station then (
@@ -242,9 +243,9 @@ module Train_update = struct
242
243
train.last_station, train.priority_stop, train.stop, train, 0 , []
243
244
)
244
245
in
245
- {train with last_station; priority_stop; stop}, ui_msgs
246
+ {train with last_station; priority_stop; stop}, stations, ui_msgs
246
247
247
- let _exit_station ~idx ~cycle (v :t ) (train : rw Train.t ) (track :Track.t ) ((x , y ) as loc ) =
248
+ let _exit_station ~idx ~cycle (v :t ) (train : rw Train.t ) stations (track :Track.t ) ((x , y ) as loc ) =
248
249
let compute_dir_to_dest graph =
249
250
(* This is expensive *)
250
251
let dest = Train. get_dest train in
@@ -258,7 +259,7 @@ module Train_update = struct
258
259
dir
259
260
in
260
261
let dir = compute_dir_to_dest v.graph in
261
- let station = Station_map. get_exn loc v. stations in
262
+ let station = Station_map. get_exn loc stations in
262
263
(* Second check of this. No matter *)
263
264
let can_go, cancel_override = Station. can_train_go station dir in
264
265
if can_go then (
@@ -277,9 +278,9 @@ module Train_update = struct
277
278
state= Train. Traveling {speed= 0 ; target_speed= 4 ; traveling_past_station= true ; block}
278
279
}
279
280
in
280
- _update_train_target_speed v train track ~idx ~cycle ~x ~y ~dir
281
+ _update_train_target_speed v train track ~idx ~cycle ~x ~y ~dir , stations
281
282
) else (
282
- {train with state= Train. StoppedAtSignal dir}
283
+ {train with state= Train. StoppedAtSignal dir}, stations
283
284
)
284
285
285
286
let _handle_train_mid_tile ~idx ~cycle (v :t ) (train :rw Train.t ) stations ((x , y ) as loc ) =
@@ -297,24 +298,24 @@ module Train_update = struct
297
298
match track.kind with
298
299
| Station _ ->
299
300
(* TODO: remove override Proceed after one train *)
300
- let train, ui_msgs = match train.state with
301
+ let train, stations, ui_msgs = match train.state with
301
302
(* This is only when we've already processed the train *)
302
303
| Traveling s when s.traveling_past_station -> default_ret
303
304
304
305
(* This is before possibly entering the station *)
305
306
| Traveling s ->
306
307
Block_map. block_decr_train s.block v.blocks;
307
- let train, ui_msgs =
308
+ let train, stations, ui_msgs =
308
309
if train.hold_at_next_station then (
309
310
{train with state = HoldingAtStation }, stations, []
310
311
) else (
311
- let station = Station_map. get_exn loc stations in
312
- _enter_station v idx train station loc
312
+ _enter_station v idx train stations loc
313
313
)
314
314
in
315
315
if Train. is_traveling train then
316
316
(* No stopping at this station *)
317
- _exit_station ~idx ~cycle v train track loc, ui_msgs
317
+ let train, stations = _exit_station ~idx ~cycle v train stations track loc in
318
+ train, stations, ui_msgs
318
319
else
319
320
(* Some kind of stop. Exit later *)
320
321
train, stations, ui_msgs
@@ -327,22 +328,21 @@ module Train_update = struct
327
328
| LoadingAtStation _ ->
328
329
(* Done loading/unloading. Check if we can exit the station *)
329
330
let wait_at_stop, _ = Train. get_next_stop train in
330
- let train = match wait_at_stop with
331
+ let train, stations = match wait_at_stop with
331
332
| `Wait -> {train with state= Train. WaitingForFullLoad }
332
- | _ -> _exit_station ~idx ~cycle v train track loc
333
+ | _ -> _exit_station ~idx ~cycle v train stations track loc
333
334
in
334
- default_ret
335
+ train, stations, []
335
336
336
337
| WaitingForFullLoad when Train. is_full train ->
337
338
(* Done waiting for full load *)
338
- _exit_station ~idx ~cycle v train track loc, []
339
+ let train, stations = _exit_station ~idx ~cycle v train stations track loc in
340
+ train, stations, []
339
341
340
342
| WaitingForFullLoad ->
341
343
(* If we're not full, we need to see if we can offload more from the station *)
342
- let wait_time, cars =
343
- let station = Station_map. get_exn loc v.stations in
344
- let station_supply = Station. get_supply_exn station in
345
- Train_station. train_pickup_and_empty_station train.cars loc v.cycle station_supply
344
+ let wait_time, cars, stations =
345
+ Train_station. train_pickup_and_empty_station train.cars loc ~cycle: v.cycle stations
346
346
in
347
347
if wait_time > 0 then
348
348
(* We found stuff to load *)
@@ -357,16 +357,16 @@ module Train_update = struct
357
357
358
358
| HoldingAtStation ->
359
359
(* Hold happens before we enter the station *)
360
- let station = Station_map. get_exn loc stations in
361
- _enter_station v idx train station loc
360
+ _enter_station v idx train stations loc
362
361
363
362
| StoppedAtSignal dir ->
364
363
(* This happens after we've already 'exited' *)
365
364
let station = Station_map. get_exn loc v.stations in
366
365
(* Check here as well to avoid expensive computation *)
367
366
let can_go, _ = Station. can_train_go station dir in
368
367
if can_go then
369
- _exit_station ~idx ~cycle v train track loc, []
368
+ let train, stations = _exit_station ~idx ~cycle v train stations track loc in
369
+ train, stations, []
370
370
else
371
371
default_ret
372
372
in
0 commit comments