mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-30 10:12:14 +00:00
Merge branch 'main' of https://github.com/openfrontio/OpenFrontIO
This commit is contained in:
@@ -190,7 +190,7 @@ export class TransformHandler {
|
||||
this.scale /= zoomFactor;
|
||||
|
||||
// Clamp the scale to prevent extreme zooming
|
||||
this.scale = Math.max(0.5, Math.min(20, this.scale));
|
||||
this.scale = Math.max(0.2, Math.min(20, this.scale));
|
||||
|
||||
const canvasRect = this.boundingRect();
|
||||
const canvasX = event.x - canvasRect.left;
|
||||
|
||||
@@ -379,6 +379,7 @@ export class EventsDisplay extends LitElement implements Layer {
|
||||
>
|
||||
<table
|
||||
class="w-full border-collapse bg-black bg-opacity-60 text-white shadow-lg lg:text-xl text-xs"
|
||||
style="pointer-events: auto;"
|
||||
>
|
||||
<tbody>
|
||||
${this.events.map(
|
||||
|
||||
@@ -66,7 +66,7 @@ export class TerritoryLayer implements Layer {
|
||||
this.game.updatesSinceLastTick()[GameUpdateType.Unit].forEach((u) => {
|
||||
const update = u as UnitUpdate;
|
||||
if (update.unitType == UnitType.DefensePost && update.isActive) {
|
||||
const tile = this.game.ref(update.pos.x, update.pos.y);
|
||||
const tile = update.pos;
|
||||
this.game
|
||||
.bfs(
|
||||
tile,
|
||||
|
||||
@@ -27,7 +27,7 @@ export class MirvExecution implements Execution {
|
||||
private nuke: Unit;
|
||||
|
||||
private mirvRange = 1500;
|
||||
private warheadCount = 500;
|
||||
private warheadCount = 350;
|
||||
|
||||
private random: PseudoRandom;
|
||||
|
||||
@@ -94,10 +94,10 @@ export class MirvExecution implements Execution {
|
||||
|
||||
private separate() {
|
||||
const dsts: TileRef[] = [this.dst];
|
||||
let attempts = 10000;
|
||||
let attempts = 1000;
|
||||
while (attempts > 0 && dsts.length < this.warheadCount) {
|
||||
attempts--;
|
||||
const potential = this.randomLand(this.dst);
|
||||
const potential = this.randomLand(this.dst, dsts);
|
||||
if (potential == null) {
|
||||
continue;
|
||||
}
|
||||
@@ -135,9 +135,9 @@ export class MirvExecution implements Execution {
|
||||
this.nuke.delete(false);
|
||||
}
|
||||
|
||||
randomLand(ref: TileRef): TileRef | null {
|
||||
randomLand(ref: TileRef, taken: TileRef[]): TileRef | null {
|
||||
let tries = 0;
|
||||
while (tries < 25) {
|
||||
while (tries < 100) {
|
||||
tries++;
|
||||
const x = this.random.nextInt(
|
||||
this.mg.x(ref) - this.mirvRange,
|
||||
@@ -150,6 +150,7 @@ export class MirvExecution implements Execution {
|
||||
if (!this.mg.isValidCoord(x, y)) {
|
||||
continue;
|
||||
}
|
||||
console.log(`got coord ${x}, ${y}`);
|
||||
const tile = this.mg.ref(x, y);
|
||||
if (!this.mg.isLand(tile)) {
|
||||
continue;
|
||||
@@ -160,8 +161,14 @@ export class MirvExecution implements Execution {
|
||||
if (this.mg.owner(tile) != this.targetPlayer) {
|
||||
continue;
|
||||
}
|
||||
for (const t of taken) {
|
||||
if (this.mg.manhattanDist(tile, t) < 25) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return tile;
|
||||
}
|
||||
console.log("could find place giving up");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -104,13 +104,13 @@ export class NukeExecution implements Execution {
|
||||
let magnitude;
|
||||
switch (this.type) {
|
||||
case UnitType.MIRVWarhead:
|
||||
magnitude = { inner: 20, outer: 25 };
|
||||
magnitude = { inner: 25, outer: 30 };
|
||||
break;
|
||||
case UnitType.AtomBomb:
|
||||
magnitude = { inner: 15, outer: 40 };
|
||||
magnitude = { inner: 12, outer: 30 };
|
||||
break;
|
||||
case UnitType.HydrogenBomb:
|
||||
magnitude = { inner: 120, outer: 140 };
|
||||
magnitude = { inner: 110, outer: 130 };
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
Tick,
|
||||
UnitType,
|
||||
} from "./Game";
|
||||
import { TileUpdate } from "./GameMap";
|
||||
import { TileRef, TileUpdate } from "./GameMap";
|
||||
|
||||
export interface GameUpdateViewData {
|
||||
tick: number;
|
||||
@@ -63,8 +63,8 @@ export interface UnitUpdate {
|
||||
id: number;
|
||||
ownerID: number;
|
||||
// TODO: make these tilerefs
|
||||
pos: MapPos;
|
||||
lastPos: MapPos;
|
||||
pos: TileRef;
|
||||
lastPos: TileRef;
|
||||
isActive: boolean;
|
||||
health?: number;
|
||||
constructionType?: UnitType;
|
||||
|
||||
@@ -34,7 +34,7 @@ import { DefenseGrid } from "./DefensePostGrid";
|
||||
|
||||
export class UnitView {
|
||||
public _wasUpdated = true;
|
||||
public lastPos: MapPos[] = [];
|
||||
public lastPos: TileRef[] = [];
|
||||
|
||||
constructor(
|
||||
private gameView: GameView,
|
||||
@@ -48,14 +48,14 @@ export class UnitView {
|
||||
}
|
||||
|
||||
lastTiles(): TileRef[] {
|
||||
return this.lastPos.map((pos) => this.gameView.ref(pos.x, pos.y));
|
||||
return this.lastPos;
|
||||
}
|
||||
|
||||
lastTile(): TileRef {
|
||||
if (this.lastPos.length == 0) {
|
||||
return this.gameView.ref(this.data.pos.x, this.data.pos.y);
|
||||
return this.data.pos;
|
||||
}
|
||||
return this.gameView.ref(this.lastPos[0].x, this.lastPos[0].y);
|
||||
return this.lastPos[0];
|
||||
}
|
||||
|
||||
update(data: UnitUpdate) {
|
||||
@@ -75,7 +75,7 @@ export class UnitView {
|
||||
return this.data.troops;
|
||||
}
|
||||
tile(): TileRef {
|
||||
return this.gameView.ref(this.data.pos.x, this.data.pos.y);
|
||||
return this.data.pos;
|
||||
}
|
||||
owner(): PlayerView {
|
||||
return this.gameView.playerBySmallID(this.data.ownerID) as PlayerView;
|
||||
|
||||
@@ -35,8 +35,8 @@ export class UnitImpl implements Unit {
|
||||
troops: this._troops,
|
||||
ownerID: this._owner.smallID(),
|
||||
isActive: this._active,
|
||||
pos: { x: this.mg.x(this._tile), y: this.mg.y(this._tile) },
|
||||
lastPos: { x: this.mg.x(this._lastTile), y: this.mg.y(this._lastTile) },
|
||||
pos: this._tile,
|
||||
lastPos: this._lastTile,
|
||||
health: this.hasHealth() ? this._health : undefined,
|
||||
constructionType: this._constructionType,
|
||||
};
|
||||
|
||||
@@ -131,6 +131,11 @@ export class GameServer {
|
||||
(c) => c.clientID != client.clientID,
|
||||
);
|
||||
});
|
||||
client.ws.on("error", (error: Error) => {
|
||||
if ((error as any).code === "WS_ERR_UNEXPECTED_RSV_1") {
|
||||
client.ws.close(1002);
|
||||
}
|
||||
});
|
||||
|
||||
// In case a client joined the game late and missed the start message.
|
||||
if (this._hasStarted) {
|
||||
|
||||
@@ -183,6 +183,11 @@ wss.on("connection", (ws, req) => {
|
||||
console.log(`errror handling websocket message: ${error}`);
|
||||
}
|
||||
});
|
||||
ws.on("error", (error: Error) => {
|
||||
if ((error as any).code === "WS_ERR_UNEXPECTED_RSV_1") {
|
||||
ws.close(1002);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function runGame() {
|
||||
|
||||
Reference in New Issue
Block a user