Skip to content

Commit 4667290

Browse files
committed
Add priority shipment update functions for train and station
1 parent 39f1f4d commit 4667290

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/rails_lib/backend/station.ml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ type info = {
113113
rate_war: bool;
114114
rates: [`Normal | `Double | `Half];
115115
cargo_revenue: int Goods.Map.t; (* revenue for each cargo type at this station *)
116+
holds_priority_shipment: bool;
116117
} [@@deriving yojson]
117118

118119
let has_demand_for v good = Goods.Set.mem good v.demand
@@ -158,6 +159,14 @@ let with_info v f = match v.info with
158159
| Some x -> Some (f x)
159160
| _ -> None
160161

162+
let update_with_info v f = match v.info with
163+
(* None = don't update *)
164+
| Some x -> begin match f x with
165+
| Some _ as info -> {v with info}
166+
| None -> v
167+
end
168+
| _ -> v
169+
161170
let get_age v year = year - v.year
162171

163172
let color_of_signal = function
@@ -274,6 +283,7 @@ let make ~x ~y ~year ~city_xy ~city_name ~suffix ~kind ~player ~first =
274283
rate_war=false;
275284
rates=`Normal;
276285
cargo_revenue=Goods.Map.empty;
286+
holds_priority_shipment=false;
277287
} |> Option.some
278288
in
279289
let signals = default_signals in
@@ -438,4 +448,17 @@ let color_of_rates v = match v.info with
438448
end
439449
| _ -> failwith "Shouldn't get here"
440450

451+
let holds_priority_shipment v =
452+
Option.map_or
453+
~default:false
454+
(fun x -> x.holds_priority_shipment)
455+
v.info
456+
457+
let set_priority_shipment v x =
458+
update_with_info v
459+
(fun info ->
460+
if Bool.equal info.holds_priority_shipment x then
461+
None
462+
else
463+
Some {info with holds_priority_shipment = x})
441464

src/rails_lib/backend/train.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,4 +559,7 @@ let get_engine_cost v = v.engine.price
559559

560560
let get_num_of_cars v = List.length v.cars
561561

562+
let holds_priority_shipment v = v.holds_priority_shipment
563+
564+
let set_priority_shipment v x = {v with holds_priority_shipment=x}
562565

0 commit comments

Comments
 (0)