From d164a28986d712fc3bf2d3fc409cabd2ccaa7e19 Mon Sep 17 00:00:00 2001 From: 1brucben <1benjbruce@gmail.com> Date: Tue, 6 May 2025 03:53:03 +0200 Subject: [PATCH] sam build improvement --- src/core/execution/FakeHumanExecution.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/core/execution/FakeHumanExecution.ts b/src/core/execution/FakeHumanExecution.ts index 59f6dd87e..3e4b8cdbf 100644 --- a/src/core/execution/FakeHumanExecution.ts +++ b/src/core/execution/FakeHumanExecution.ts @@ -666,8 +666,8 @@ export class FakeHumanExecution implements Execution { const silos = this.player.units(UnitType.MissileSilo); for (const silo of silos) { - if (this.builtSAMNearSilo.has(silo)) { - continue; + if (this.hasLiveSAMNearSilo(silo)) { + continue; // Skip if there's already a SAM nearby } const siloTile = silo.tile(); @@ -677,7 +677,6 @@ export class FakeHumanExecution implements Execution { this.mg.ownerID(t) === this.player.smallID() && this.player.canBuild(UnitType.SAMLauncher, t) ) { - // Build immediately on the first valid tile this.mg.addExecution( new ConstructionExecution( this.player.id(), @@ -685,12 +684,18 @@ export class FakeHumanExecution implements Execution { UnitType.SAMLauncher, ), ); - this.builtSAMNearSilo.add(silo); - return; // Only build 1 SAM per handleUnits + return; // Build only one per tick } } } } + private hasLiveSAMNearSilo(silo: Unit): boolean { + const radiusSq = 40 * 40; + return this.player.units(UnitType.SAMLauncher).some((sam) => { + const distSq = this.mg.euclideanDistSquared(silo.tile(), sam.tile()); + return distSq <= radiusSq; + }); + } private maybeSpawnStructure(type: UnitType, maxNum: number) { const units = this.player.units(type);