mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-05 13:32:02 +00:00
wip
This commit is contained in:
@@ -30,7 +30,7 @@ export class SAMLauncherExecution implements Execution {
|
||||
private tile: TileRef,
|
||||
private sam: Unit | null = null,
|
||||
) {
|
||||
if (sam != null) {
|
||||
if (sam !== null) {
|
||||
this.tile = sam.tile();
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,7 @@ export class SAMLauncherExecution implements Execution {
|
||||
}
|
||||
|
||||
private getSingleTarget(): Unit | null {
|
||||
if (this.sam === null) return null;
|
||||
const nukes = this.mg
|
||||
.nearbyUnits(this.sam.tile(), this.searchRangeRadius, [
|
||||
UnitType.AtomBomb,
|
||||
@@ -80,11 +81,11 @@ export class SAMLauncherExecution implements Execution {
|
||||
}
|
||||
|
||||
private isHit(type: UnitType, random: number): boolean {
|
||||
if (type == UnitType.AtomBomb) {
|
||||
if (type === UnitType.AtomBomb) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (type == UnitType.MIRVWarhead) {
|
||||
if (type === UnitType.MIRVWarhead) {
|
||||
return random < this.mg.config().samWarheadHittingChance();
|
||||
}
|
||||
|
||||
@@ -130,14 +131,18 @@ export class SAMLauncherExecution implements Execution {
|
||||
(unit) =>
|
||||
unit.owner() !== this.player && !this.player.isFriendly(unit.owner()),
|
||||
)
|
||||
.filter(
|
||||
(unit) =>
|
||||
this.mg.manhattanDist(unit.detonationDst(), this.sam.tile()) <
|
||||
this.MIRVWarheadProtectionRadius,
|
||||
);
|
||||
.filter((unit) => {
|
||||
const dst = unit.detonationDst();
|
||||
return (
|
||||
this.sam !== null &&
|
||||
dst !== null &&
|
||||
this.mg.manhattanDist(dst, this.sam.tile()) <
|
||||
this.MIRVWarheadProtectionRadius
|
||||
);
|
||||
});
|
||||
|
||||
let target: Unit | null = null;
|
||||
if (mirvWarheadTargets.length == 0) {
|
||||
if (mirvWarheadTargets.length === 0) {
|
||||
target = this.getSingleTarget();
|
||||
}
|
||||
|
||||
@@ -155,7 +160,8 @@ export class SAMLauncherExecution implements Execution {
|
||||
) {
|
||||
this.sam.setCooldown(true);
|
||||
const type =
|
||||
mirvWarheadTargets.length > 0 ? UnitType.MIRVWarhead : target.type();
|
||||
mirvWarheadTargets.length > 0 ? UnitType.MIRVWarhead : target?.type();
|
||||
if (type === undefined) throw new Error("Unknown unit type");
|
||||
const random = this.pseudoRandom.next();
|
||||
const hit = this.isHit(type, random);
|
||||
if (!hit) {
|
||||
@@ -174,7 +180,7 @@ export class SAMLauncherExecution implements Execution {
|
||||
);
|
||||
// Delete warheads
|
||||
mirvWarheadTargets.forEach((u) => u.delete());
|
||||
} else {
|
||||
} else if (target !== null) {
|
||||
target.setTargetedBySAM(true);
|
||||
this.mg.addExecution(
|
||||
new SAMMissileExecution(
|
||||
@@ -184,6 +190,8 @@ export class SAMLauncherExecution implements Execution {
|
||||
target,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
throw new Error("target is null");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user