verticopolis_engine/economy/
films.rs1use serde::Serialize;
16
17use super::screens::running_screens;
18use super::tickets::{TicketPrice, MODERN_TICKET_PRICES};
19use super::visitors::{
20 set_audience, FADING_FILM_DRAW, FILM_SPENT_DAYS, NEW_FILM_DRAW, NEW_FILM_FULL_DRAW_DAYS,
21 SPENT_FILM_DRAW,
22};
23use crate::clock::GameMode;
24use crate::facilities::Kind;
25use crate::tower::{Extras, Unit};
26
27pub const NEW_FILM_PRICE: f64 = 300_000.0;
29pub const CLASSIC_FILM_PRICE: f64 = 150_000.0;
31pub const MODERN_REVIVAL_PRICE: f64 = 60_000.0;
33pub const MODERN_FEATURE_PRICE: f64 = 120_000.0;
34pub const MODERN_BLOCKBUSTER_PRICE: f64 = 300_000.0;
35pub const BLOCKBUSTER_INCOME_MULT: f64 = 2.2;
37pub const REVIVAL_INCOME_MULT: f64 = 0.6;
39pub const FADING_INCOME_SHARE: f64 = 0.6;
42pub const SPENT_INCOME_SHARE: f64 = 0.25;
43pub const MODERN_FULL_DRAW_DAYS: i64 = 28;
45pub const MODERN_SPENT_DAYS: i64 = 42;
46
47#[derive(Clone, Copy, Debug, PartialEq, Eq)]
50pub enum FilmTier {
51 New,
52 Classic,
53 Blockbuster,
54}
55
56impl FilmTier {
57 pub const ALL: [FilmTier; 3] = [FilmTier::New, FilmTier::Classic, FilmTier::Blockbuster];
59
60 pub const fn key(self) -> &'static str {
62 match self {
63 FilmTier::New => "new",
64 FilmTier::Classic => "classic",
65 FilmTier::Blockbuster => "blockbuster",
66 }
67 }
68
69 pub fn showing(extras: &Extras) -> FilmTier {
71 if extras.film_classic {
72 FilmTier::Classic
73 } else if extras.film_blockbuster {
74 FilmTier::Blockbuster
75 } else {
76 FilmTier::New
77 }
78 }
79}
80
81#[derive(Clone, Copy, Debug, PartialEq, Eq)]
83pub enum FilmStage {
84 Full,
85 Fading,
86 Spent,
87}
88
89#[derive(Clone, Copy, Debug, PartialEq, Eq)]
91pub struct FilmRun {
92 pub full_draw_days: i64,
94 pub spent_days: i64,
96}
97
98impl FilmRun {
99 pub fn stage(self, days_shown: i64) -> FilmStage {
101 if days_shown < self.full_draw_days {
102 FilmStage::Full
103 } else if days_shown < self.spent_days {
104 FilmStage::Fading
105 } else {
106 FilmStage::Spent
107 }
108 }
109
110 pub fn draw(self, days_shown: i64, tier: FilmTier) -> i64 {
114 let draw = match self.stage(days_shown) {
115 FilmStage::Full => NEW_FILM_DRAW,
116 FilmStage::Fading => FADING_FILM_DRAW,
117 FilmStage::Spent => SPENT_FILM_DRAW,
118 };
119 if tier == FilmTier::Classic {
120 draw.min(FADING_FILM_DRAW)
121 } else {
122 draw
123 }
124 }
125}
126
127#[derive(Clone, Copy, Debug, PartialEq, Serialize)]
129#[serde(rename_all = "camelCase")]
130pub struct FilmOffer {
131 #[serde(skip)]
132 pub tier: FilmTier,
133 pub key: &'static str,
135 pub label: &'static str,
137 pub price: f64,
139 #[serde(skip)]
141 pub opening: &'static str,
142 #[serde(skip)]
145 pub income_mult: f64,
146}
147
148#[derive(Clone, Copy, Debug, PartialEq, Serialize)]
152#[serde(rename_all = "camelCase")]
153pub struct FilmRebook {
154 pub policy: &'static str,
156 pub film: Option<&'static str>,
158 #[serde(skip)]
159 pub tier: Option<FilmTier>,
160}
161
162#[derive(Debug)]
164pub struct FilmRules {
165 pub offers: &'static [FilmOffer],
167 pub run: FilmRun,
168 pub blockbuster_tier: FilmTier,
170 pub rebooks: &'static [FilmRebook],
174 pub rebook_default: Option<&'static str>,
177 pub income_follows_film: bool,
180 pub ticket_prices: &'static [TicketPrice],
183}
184
185impl FilmRules {
186 pub fn offer(&self, tier: FilmTier) -> Option<&'static FilmOffer> {
188 self.offers.iter().find(|o| o.tier == tier)
189 }
190
191 pub fn rebooked(&self, policy: Option<&str>) -> Option<FilmTier> {
195 let listed = |p: &str| self.rebooks.iter().find(|r| r.policy == p);
196 policy
197 .and_then(listed)
198 .or_else(|| self.rebook_default.and_then(listed))
199 .and_then(|r| r.tier)
200 }
201}
202
203pub static CLASSIC_FILMS: FilmRules = FilmRules {
204 offers: &[
205 FilmOffer {
206 tier: FilmTier::New,
207 key: "new",
208 label: "New film",
209 price: NEW_FILM_PRICE,
210 opening: "A new film",
211 income_mult: 1.0,
212 },
213 FilmOffer {
214 tier: FilmTier::Classic,
215 key: "classic",
216 label: "Classic film",
217 price: CLASSIC_FILM_PRICE,
218 opening: "A classic film",
219 income_mult: 1.0,
220 },
221 ],
222 run: FilmRun {
223 full_draw_days: NEW_FILM_FULL_DRAW_DAYS,
224 spent_days: FILM_SPENT_DAYS,
225 },
226 blockbuster_tier: FilmTier::New,
227 rebooks: &[],
228 rebook_default: None,
229 income_follows_film: false,
230 ticket_prices: &[],
231};
232
233pub static MODERN_FILMS: FilmRules = FilmRules {
234 offers: &[
235 FilmOffer {
236 tier: FilmTier::Classic,
237 key: "classic",
238 label: "Revival",
239 price: MODERN_REVIVAL_PRICE,
240 opening: "A revival",
241 income_mult: REVIVAL_INCOME_MULT,
242 },
243 FilmOffer {
244 tier: FilmTier::New,
245 key: "new",
246 label: "Feature",
247 price: MODERN_FEATURE_PRICE,
248 opening: "A feature",
249 income_mult: 1.0,
250 },
251 FilmOffer {
252 tier: FilmTier::Blockbuster,
253 key: "blockbuster",
254 label: "Blockbuster",
255 price: MODERN_BLOCKBUSTER_PRICE,
256 opening: "A blockbuster",
257 income_mult: BLOCKBUSTER_INCOME_MULT,
258 },
259 ],
260 run: FilmRun {
261 full_draw_days: MODERN_FULL_DRAW_DAYS,
262 spent_days: MODERN_SPENT_DAYS,
263 },
264 blockbuster_tier: FilmTier::Blockbuster,
265 rebooks: &[
266 FilmRebook {
267 policy: "off",
268 film: None,
269 tier: None,
270 },
271 FilmRebook {
272 policy: "revival",
273 film: Some("classic"),
274 tier: Some(FilmTier::Classic),
275 },
276 FilmRebook {
277 policy: "feature",
278 film: Some("new"),
279 tier: Some(FilmTier::New),
280 },
281 FilmRebook {
282 policy: "blockbuster",
283 film: Some("blockbuster"),
284 tier: Some(FilmTier::Blockbuster),
285 },
286 ],
287 rebook_default: Some("feature"),
288 income_follows_film: true,
289 ticket_prices: &MODERN_TICKET_PRICES,
290};
291
292#[derive(Debug, Clone, Copy, PartialEq)]
294pub enum FilmRefusal {
295 Unavailable,
297 NotTheater,
299 Closed,
301 NoScreen,
303 Funds {
305 cost: f64,
307 },
308}
309
310impl FilmRefusal {
311 pub fn reason(&self) -> &'static str {
313 match self {
314 FilmRefusal::Unavailable => "unavailable",
315 FilmRefusal::NotTheater => "notTheater",
316 FilmRefusal::Closed => "closed",
317 FilmRefusal::NoScreen => "noScreen",
318 FilmRefusal::Funds { .. } => "funds",
319 }
320 }
321}
322
323pub(crate) fn fills_blockbuster_slot(mode: GameMode, u: &Unit) -> bool {
326 let films = mode.films();
327 running_screens(mode, u).any(|film| {
328 film.tier == films.blockbuster_tier && films.run.stage(film.days_shown()) == FilmStage::Full
329 })
330}
331
332pub(crate) fn theater_audience(mode: GameMode, u: &Unit) -> i64 {
335 let run = mode.films().run;
336 let (mut total, mut count) = (0, 0);
337 for film in running_screens(mode, u) {
338 let draw = run.draw(film.days_shown(), film.tier);
339 total += set_audience(Kind::Cinema, draw).unwrap_or(0);
340 count += 1;
341 }
342 if count == 0 {
343 0
344 } else {
345 total / count
346 }
347}
348
349pub(crate) fn film_income_mult(mode: GameMode, u: &Unit, in_slot: bool) -> f64 {
354 let films = mode.films();
355 if !films.income_follows_film {
356 return if in_slot {
357 BLOCKBUSTER_INCOME_MULT
358 } else {
359 1.0
360 };
361 }
362 let (mut total, mut count) = (0.0, 0.0);
363 for film in running_screens(mode, u) {
364 let peak = films.offer(film.tier).map_or(1.0, |o| o.income_mult);
365 let share = match films.run.stage(film.days_shown()) {
366 FilmStage::Full => 1.0,
367 FilmStage::Fading => FADING_INCOME_SHARE,
368 FilmStage::Spent => SPENT_INCOME_SHARE,
369 };
370 total += peak * share;
371 count += 1.0;
372 }
373 if count == 0.0 {
374 1.0
375 } else {
376 total / count
377 }
378}
379
380#[cfg(test)]
381#[path = "films_tests.rs"]
382pub(crate) mod films_tests;
383
384#[cfg(test)]
385#[path = "films_modern_tests.rs"]
386mod films_modern_tests;