From 8b37cccbc38cabf800a9609a4ce322e788def6dd Mon Sep 17 00:00:00 2001 From: evan Date: Sat, 26 Apr 2025 09:31:17 -0700 Subject: [PATCH 1/4] cleanup SAMLauncher execution, warheadTargers & target local variable instead of field --- src/core/execution/SAMLauncherExecution.ts | 29 +++++++++------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/core/execution/SAMLauncherExecution.ts b/src/core/execution/SAMLauncherExecution.ts index 5e37cf9cd..c3ebbf54d 100644 --- a/src/core/execution/SAMLauncherExecution.ts +++ b/src/core/execution/SAMLauncherExecution.ts @@ -17,9 +17,6 @@ export class SAMLauncherExecution implements Execution { private mg: Game; private active: boolean = true; - private target: Unit = null; - private warheadTargets: Unit[] = []; - private searchRangeRadius = 80; // As MIRV go very fast we have to detect them very early but we only // shoot the one targeting very close (MIRVWarheadProtectionRadius) @@ -119,7 +116,7 @@ export class SAMLauncherExecution implements Execution { this.pseudoRandom = new PseudoRandom(this.sam.id()); } - this.warheadTargets = this.mg + const mirvWarheadTargets = this.mg .nearbyUnits( this.sam.tile(), this.MIRVWarheadSearchRadius, @@ -136,8 +133,9 @@ export class SAMLauncherExecution implements Execution { this.MIRVWarheadProtectionRadius, ); - if (this.warheadTargets.length == 0) { - this.target = this.getSingleTarget(); + let target: Unit | null = null; + if (mirvWarheadTargets.length == 0) { + target = this.getSingleTarget(); } if ( @@ -147,16 +145,14 @@ export class SAMLauncherExecution implements Execution { this.sam.setCooldown(false); } - const isSingleTarget = this.target && !this.target.targetedBySAM(); + const isSingleTarget = target && !target.targetedBySAM(); if ( - (isSingleTarget || this.warheadTargets.length > 0) && + (isSingleTarget || mirvWarheadTargets.length > 0) && !this.sam.isCooldown() ) { this.sam.setCooldown(true); const type = - this.warheadTargets.length > 0 - ? UnitType.MIRVWarhead - : this.target.type(); + mirvWarheadTargets.length > 0 ? UnitType.MIRVWarhead : target.type(); const random = this.pseudoRandom.next(); const hit = this.isHit(type, random); if (!hit) { @@ -166,26 +162,25 @@ export class SAMLauncherExecution implements Execution { this.sam.owner().id(), ); } else { - if (this.warheadTargets.length > 0) { + if (mirvWarheadTargets.length > 0) { // Message this.mg.displayMessage( - `${this.warheadTargets.length} MIRV warheads intercepted`, + `${mirvWarheadTargets.length} MIRV warheads intercepted`, MessageType.SUCCESS, this.sam.owner().id(), ); // Delete warheads - this.warheadTargets.forEach((u) => u.delete()); + mirvWarheadTargets.forEach((u) => u.delete()); } else { - this.target.setTargetedBySAM(true); + target.setTargetedBySAM(true); this.mg.addExecution( new SAMMissileExecution( this.sam.tile(), this.sam.owner(), this.sam, - this.target, + target, ), ); - this.warheadTargets = []; } } } From de70321c4b3bb666c07af7b02bbb714f5db93b47 Mon Sep 17 00:00:00 2001 From: evan Date: Sat, 26 Apr 2025 09:35:47 -0700 Subject: [PATCH 2/4] bugfix: remove unit before updating tile in UnitImpl.move(). This is because if a unit moves too fast or on border, UnitGrid will not find the existing unit, causing duplicate units --- src/core/game/UnitImpl.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/game/UnitImpl.ts b/src/core/game/UnitImpl.ts index 4ce55c37c..247e0eced 100644 --- a/src/core/game/UnitImpl.ts +++ b/src/core/game/UnitImpl.ts @@ -88,9 +88,9 @@ export class UnitImpl implements Unit { if (tile == null) { throw new Error("tile cannot be null"); } + this.mg.removeUnit(this); this._lastTile = this._tile; this._tile = tile; - this.mg.removeUnit(this); this.mg.addUnit(this); this.mg.addUpdate(this.toUpdate()); } From a509bc3b82ba4fa8b8c49f8f11242962b7e6da6d Mon Sep 17 00:00:00 2001 From: evan Date: Sat, 26 Apr 2025 09:43:42 -0700 Subject: [PATCH 3/4] reduce structureMinDist to 12, allow for some overlap --- src/core/configuration/DefaultConfig.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/configuration/DefaultConfig.ts b/src/core/configuration/DefaultConfig.ts index 541deaa27..62cbad4e5 100644 --- a/src/core/configuration/DefaultConfig.ts +++ b/src/core/configuration/DefaultConfig.ts @@ -671,7 +671,7 @@ export class DefaultConfig implements Config { } structureMinDist(): number { - return 18; + return 12; } shellLifetime(): number { From 8e3022720440a07982cd90daca41517129f2018d Mon Sep 17 00:00:00 2001 From: evan Date: Sat, 26 Apr 2025 09:49:30 -0700 Subject: [PATCH 4/4] disable defense post shooting ships for now --- src/core/execution/DefensePostExecution.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/core/execution/DefensePostExecution.ts b/src/core/execution/DefensePostExecution.ts index b3524e339..413cf93b4 100644 --- a/src/core/execution/DefensePostExecution.ts +++ b/src/core/execution/DefensePostExecution.ts @@ -80,6 +80,9 @@ export class DefensePostExecution implements Execution { this.target = null; } + // TODO: Reconsider how/if defense posts target ships. + return; + const ships = this.mg .nearbyUnits( this.post.tile(),