mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-25 15:12:43 +00:00
don't lose territory if surrounded at edge of map
This commit is contained in:
@@ -123,8 +123,9 @@ export class PlayerExecution implements Execution {
|
||||
const enemies = new Set<number>();
|
||||
for (const ref of cluster) {
|
||||
if (
|
||||
this.mg.isOceanShore(ref) ||
|
||||
this.mg.neighbors(ref).some((n) => !this.mg.hasOwner(n))
|
||||
this.mg.isOceanShore(tile) ||
|
||||
this.mg.isOnEdgeOfMap(tile) ||
|
||||
this.mg.neighbors(tile).some((n) => !this.mg.hasOwner(n))
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
@@ -145,7 +146,7 @@ export class PlayerExecution implements Execution {
|
||||
private isSurrounded(cluster: Set<TileRef>): boolean {
|
||||
let enemyTiles = new Set<TileRef>();
|
||||
for (const tr of cluster) {
|
||||
if (this.mg.isOceanShore(tr)) {
|
||||
if (this.mg.isOceanShore(tr) || this.mg.isOnEdgeOfMap(tr)) {
|
||||
return false;
|
||||
}
|
||||
this.mg
|
||||
|
||||
@@ -89,6 +89,9 @@ export class GameImpl implements Game {
|
||||
this._config.defensePostRange(),
|
||||
);
|
||||
}
|
||||
isOnEdgeOfMap(ref: TileRef): boolean {
|
||||
return this._map.isOnEdgeOfMap(ref);
|
||||
}
|
||||
|
||||
owner(ref: TileRef): Player | TerraNullius {
|
||||
return this.playerBySmallID(this.ownerID(ref));
|
||||
|
||||
@@ -27,6 +27,7 @@ export interface GameMap {
|
||||
setOwnerID(ref: TileRef, playerId: number): void;
|
||||
hasFallout(ref: TileRef): boolean;
|
||||
setFallout(ref: TileRef, value: boolean): void;
|
||||
isOnEdgeOfMap(ref: TileRef): boolean;
|
||||
isBorder(ref: TileRef): boolean;
|
||||
neighbors(ref: TileRef): TileRef[];
|
||||
isWater(ref: TileRef): boolean;
|
||||
@@ -185,6 +186,12 @@ export class GameMapImpl implements GameMap {
|
||||
}
|
||||
}
|
||||
|
||||
isOnEdgeOfMap(ref: TileRef): boolean {
|
||||
const x = this.x(ref);
|
||||
const y = this.y(ref);
|
||||
return x == 0 || x == this.width() - 1 || y == 0 || y == this.height() - 1;
|
||||
}
|
||||
|
||||
isBorder(ref: TileRef): boolean {
|
||||
return this.neighbors(ref).some(
|
||||
(tr) => this.ownerID(tr) != this.ownerID(ref),
|
||||
|
||||
@@ -240,6 +240,9 @@ export class GameView implements GameMap {
|
||||
};
|
||||
this.defensePostGrid = new DefenseGrid(_map, _config.defensePostRange());
|
||||
}
|
||||
isOnEdgeOfMap(ref: TileRef): boolean {
|
||||
return this._map.isOnEdgeOfMap(ref);
|
||||
}
|
||||
|
||||
public updatesSinceLastTick(): GameUpdates {
|
||||
return this.lastUpdate.updates;
|
||||
|
||||
Reference in New Issue
Block a user