mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-24 08:25:02 +00:00
add nuke button
This commit is contained in:
@@ -7,6 +7,10 @@ export function manhattanDist(c1: Cell, c2: Cell): number {
|
||||
return Math.abs(c1.x - c2.x) + Math.abs(c1.y - c2.y);
|
||||
}
|
||||
|
||||
export function euclideanDist(c1: Cell, c2: Cell): number {
|
||||
return Math.sqrt(Math.pow(c1.x - c2.x, 2) + Math.pow(c1.y - c2.y, 2));
|
||||
}
|
||||
|
||||
export function manhattanDistWrapped(c1: Cell, c2: Cell, width: number): number {
|
||||
// Calculate x distance
|
||||
let dx = Math.abs(c1.x - c2.x);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {Cell, Execution, MutableGame, MutablePlayer, PlayerID, Tile} from "../game/Game";
|
||||
import {bfs, dist} from "../Util";
|
||||
import {PseudoRandom} from "../PseudoRandom";
|
||||
import {bfs, dist, euclideanDist, manhattanDist} from "../Util";
|
||||
|
||||
export class NukeExecution implements Execution {
|
||||
|
||||
@@ -22,12 +23,17 @@ export class NukeExecution implements Execution {
|
||||
this.mg = mg
|
||||
this.sender = mg.player(this.senderID)
|
||||
if (this.magnitude == null) {
|
||||
this.magnitude = 50
|
||||
this.magnitude = 70
|
||||
}
|
||||
const rand = new PseudoRandom(mg.ticks())
|
||||
const tile = mg.tile(this.cell)
|
||||
this.toDestroy = bfs(tile, dist(tile, this.magnitude))
|
||||
this.toDestroy = bfs(tile, (n: Tile) => {
|
||||
const d = euclideanDist(tile.cell(), n.cell())
|
||||
return (d <= this.magnitude || rand.chance(2)) && d <= this.magnitude + 30
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
tick(ticks: number): void {
|
||||
for (const tile of this.toDestroy) {
|
||||
const owner = tile.owner()
|
||||
|
||||
Reference in New Issue
Block a user