From 74ede7d947dcad4f4df17316ac21177e76f2f7fd Mon Sep 17 00:00:00 2001 From: catloversg <152669316+catloversg@users.noreply.github.com> Date: Thu, 12 Dec 2024 18:11:58 +0700 Subject: [PATCH] BUGFIX: Game takes too long to process crime work with large number of cycles (#1821) --- src/Work/CrimeWork.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Work/CrimeWork.ts b/src/Work/CrimeWork.ts index 6dc980b75..ad3165f55 100644 --- a/src/Work/CrimeWork.ts +++ b/src/Work/CrimeWork.ts @@ -33,6 +33,12 @@ export class CrimeWork extends Work { } process(cycles = 1): boolean { + /** + * Crime work is processed in a loop. If the number of cycles is too large, the loop blocks the game engine for too + * long. 12960000 is the number of cycles in 30 days (5 * 3600 * 24 * 30). On a very old machine, the loop takes + * ~800-1000 ms to process the "shoplift" crime which is the fastest crime (faster crime = more iteration). + */ + cycles = Math.min(cycles, 12960000); this.cyclesWorked += cycles; const time = Object.values(Crimes).find((c) => c.type === this.crimeType)?.time ?? 0; this.unitCompleted += CONSTANTS.MilliPerCycle * cycles;