mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-08-16 21:22:00 +00:00
Enhance nuke alliance breaking logic to account for allied structures in blast radius 💣 (#2887)
## Description: Doesn't need a description :D https://github.com/user-attachments/assets/8de576fd-050b-4b35-8526-e4c88d1a9f25 https://github.com/user-attachments/assets/c99147a1-efdf-426b-96d1-e996e01f89aa ## Please complete the following: - [X] I have added screenshots for all UI updates - [X] I process any text displayed to the user through translateText() and I've added it to the en.json file - [X] I have added relevant tests to the test directory - [X] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: FloPinguin
This commit is contained in:
@@ -225,4 +225,45 @@ export class UnitGrid {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Return true if any unit of the given types matches the predicate
|
||||
anyUnitNearby(
|
||||
tile: TileRef,
|
||||
searchRange: number,
|
||||
types: readonly UnitType[],
|
||||
predicate: (unit: Unit | UnitView) => boolean,
|
||||
playerId?: PlayerID,
|
||||
includeUnderConstruction: boolean = false,
|
||||
): boolean {
|
||||
const { startGridX, endGridX, startGridY, endGridY } = this.getCellsInRange(
|
||||
tile,
|
||||
searchRange,
|
||||
);
|
||||
const rangeSquared = searchRange * searchRange;
|
||||
for (let cy = startGridY; cy <= endGridY; cy++) {
|
||||
for (let cx = startGridX; cx <= endGridX; cx++) {
|
||||
for (const type of types) {
|
||||
const unitSet = this.grid[cy][cx].get(type);
|
||||
if (unitSet === undefined) continue;
|
||||
for (const unit of unitSet) {
|
||||
if (
|
||||
!this.unitIsInRange(
|
||||
unit,
|
||||
tile,
|
||||
rangeSquared,
|
||||
playerId,
|
||||
includeUnderConstruction,
|
||||
)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
if (predicate(unit)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user