From 363e4b995e9c22bf5f7b75dbab518df69240364a Mon Sep 17 00:00:00 2001 From: Scott Anderson <662325+scottanderson@users.noreply.github.com> Date: Tue, 13 May 2025 02:35:48 -0400 Subject: [PATCH] fix --- src/core/Util.ts | 2 +- src/core/execution/WarshipExecution.ts | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/core/Util.ts b/src/core/Util.ts index 1ae6594e7..b3ebe93bd 100644 --- a/src/core/Util.ts +++ b/src/core/Util.ts @@ -293,7 +293,7 @@ export function createRandomName( name: string, playerType: string, ): string | null { - let randomName = null; + let randomName: string | null = null; if (playerType === "HUMAN") { const hash = simpleHash(name); const prefixIndex = hash % BOT_NAME_PREFIXES.length; diff --git a/src/core/execution/WarshipExecution.ts b/src/core/execution/WarshipExecution.ts index 1ad13dda2..a4b2c4695 100644 --- a/src/core/execution/WarshipExecution.ts +++ b/src/core/execution/WarshipExecution.ts @@ -72,6 +72,9 @@ export class WarshipExecution implements Execution { } private shoot() { + if (this.mg === null || this.warship === null || this.target === null) { + throw new Error("Warship not initialized"); + } const shellAttackRate = this.mg.config().warshipShellAttackRate(); if (this.mg.ticks() - this.lastShellAttack > shellAttackRate) { this.lastShellAttack = this.mg.ticks(); @@ -160,6 +163,7 @@ export class WarshipExecution implements Execution { !this.alreadySentShell.has(unit) && (unit.type() !== UnitType.TradeShip || (hasPort && + this.warship !== null && unit.dstPort()?.owner() !== this.warship.owner() && !unit.dstPort()?.owner().isFriendly(this.warship.owner()) && unit.isSafeFromPirates() !== true)), @@ -213,8 +217,8 @@ export class WarshipExecution implements Execution { if ( this.target === null || !this.target.isActive() || - this.target.owner() == this._owner || - this.target.isSafeFromPirates() == true + this.target.owner() === this._owner || + this.target.isSafeFromPirates() === true ) { // In case another warship captured or destroyed target, or the target escaped into safe waters this.target = null; @@ -268,6 +272,9 @@ export class WarshipExecution implements Execution { } randomTile(): TileRef { + if (this.mg === null) { + throw new Error("Warship not initialized"); + } let warshipPatrolRange = this.mg.config().warshipPatrolRange(); const maxAttemptBeforeExpand: number = warshipPatrolRange * 2; let attemptCount: number = 0; @@ -295,5 +302,6 @@ export class WarshipExecution implements Execution { } return tile; } + throw new Error("unreachable"); } }