File tree Expand file tree Collapse file tree 4 files changed +32
-17
lines changed Expand file tree Collapse file tree 4 files changed +32
-17
lines changed Original file line number Diff line number Diff line change @@ -482,8 +482,14 @@ let try_create_priority_shipment ?(force=false) v =
482
482
| _ -> None
483
483
484
484
let try_cancel_priority_shipments ?(force =false ) v =
485
- Player. cancel_priority ~force v.players ~cycle: v.cycle ~year: v.year v.region
486
- |> List. map (fun i -> PriorityShipmentCanceled {player= i})
485
+ (* Try to cancel and create corresponding messages *)
486
+ match Player. cancel_priority_shipment ~force v.players ~cycle: v.cycle ~year: v.year v.region with
487
+ | _ ::_ as players ->
488
+ let station_map = Station_map. clear_priority_shipment_for_all v.stations ~players in
489
+ [% upf v.stations < - station_map];
490
+ List. map (fun i -> PriorityShipmentCanceled {player= i}) players
491
+ | _ -> []
492
+
487
493
488
494
(* * Most time-based work happens here **)
489
495
let handle_cycle v =
@@ -529,7 +535,6 @@ let handle_cycle v =
529
535
else ui_msgs
530
536
in
531
537
(* Cancel any expired priority shipments *)
532
-
533
538
let ui_msgs = (try_cancel_priority_shipments v) @ ui_msgs in
534
539
535
540
(* adjust time *)
Original file line number Diff line number Diff line change @@ -385,23 +385,30 @@ let set_priority priority player = {player with priority}
385
385
386
386
let has_priority player = Option. is_some player.priority
387
387
388
- let check_cancel_priority player ~cycle ~year region =
388
+ let check_cancel_priority_shipment player ~cycle ~year region =
389
389
(* Priority shipments are cancelled when the bonus is < 20 *)
390
390
match player.priority with
391
391
| None -> false
392
392
| Some pr_data ->
393
393
Priority_shipment. should_be_cancelled pr_data ~cycle ~year region
394
394
395
- let cancel_priority ?(force =false ) players ~cycle ~year region =
395
+ let cancel_priority_shipment ?(force =false ) players ~cycle ~year region =
396
396
(* Cancel priority and let us know which players' were canceled *)
397
- Array. foldi (fun acc i player ->
398
- if has_priority player &&
399
- (check_cancel_priority player ~cycle ~year region || force) then (
400
- players.(i) < - {player with priority= None };
401
- i::acc
402
- ) else acc)
403
- []
404
- players
397
+ let cancel_players =
398
+ Array. foldi (fun acc i player ->
399
+ if has_priority player &&
400
+ (check_cancel_priority_shipment player ~cycle ~year region || force)
401
+ then i::acc else acc) []
402
+ players
403
+ in
404
+ List. iter (fun i ->
405
+ let player = players.(i) in
406
+ let trains = Trainmap. clear_priority_shipment player.trains in
407
+ let player = [% up {player with trains; priority= None }] in
408
+ players.(i) < - player
409
+ )
410
+ cancel_players;
411
+ cancel_players
405
412
406
413
let update players idx f =
407
414
let p = players.(idx) in
Original file line number Diff line number Diff line change @@ -143,13 +143,13 @@ let total_engine_value (v:t) =
143
143
let total_car_value (v :t ) =
144
144
C. car_cost * fold (fun acc train -> acc + Train. get_num_of_cars train) v ~init: 0
145
145
146
- let clear_priority_shipment_for_all v ~ players =
146
+ let clear_priority_shipment v =
147
147
(* Clear priority shipment holding for the given players *)
148
148
let open Train in
149
149
Vector. map_in_place (fun train ->
150
- if List. mem ~eq: Int. equal train.player players then
150
+ if Train. holds_priority_shipment train then
151
151
Train. set_priority_shipment train false
152
152
else train)
153
- v.trains
154
-
153
+ v.trains;
154
+ v
155
155
Original file line number Diff line number Diff line change @@ -39,3 +39,6 @@ val get_at_loc: Utils.loc -> t -> Id.t list
39
39
val total_engine_value : t -> int
40
40
41
41
val total_car_value : t -> int
42
+
43
+ val clear_priority_shipment : t -> t
44
+
You can’t perform that action at this time.
0 commit comments