merge with main again

This commit is contained in:
1brucben
2025-04-26 19:31:52 +02:00
4 changed files with 17 additions and 24 deletions
+1 -1
View File
@@ -687,7 +687,7 @@ export class DefaultConfig implements Config {
}
structureMinDist(): number {
return 18;
return 12;
}
shellLifetime(): number {
@@ -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(),
+12 -22
View File
@@ -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,31 +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
// Delete warheads safely
this.warheadTargets.forEach((u) => {
if (u.isActive()) {
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 = [];
}
}
}
+1 -1
View File
@@ -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());
}