mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-31 05:03:06 +00:00
Add territory renderer fallback controller
This commit is contained in:
@@ -692,6 +692,7 @@ export class GameImpl implements Game {
|
||||
owner._lastTileChange = this._ticks;
|
||||
this.updateBorders(tile);
|
||||
this._map.setFallout(tile, false);
|
||||
this.updateDefendedStateForTileChange(tile, owner);
|
||||
this.recordTileUpdate(tile);
|
||||
}
|
||||
|
||||
@@ -710,6 +711,9 @@ export class GameImpl implements Game {
|
||||
|
||||
this._map.setOwnerID(tile, 0);
|
||||
this.updateBorders(tile);
|
||||
if (this._map.isDefended(tile)) {
|
||||
this._map.setDefended(tile, false);
|
||||
}
|
||||
this.recordTileUpdate(tile);
|
||||
}
|
||||
|
||||
@@ -971,9 +975,18 @@ export class GameImpl implements Game {
|
||||
}
|
||||
}
|
||||
updateUnitTile(u: Unit) {
|
||||
if (u.type() === UnitType.DefensePost) {
|
||||
this.updateDefendedStateForDefensePost(u.tile(), u.owner() as PlayerImpl);
|
||||
}
|
||||
this.unitGrid.updateUnitCell(u);
|
||||
}
|
||||
|
||||
refreshDefensePostDefendedState(u: Unit) {
|
||||
if (u.type() === UnitType.DefensePost) {
|
||||
this.updateDefendedStateForDefensePost(u.tile(), u.owner() as PlayerImpl);
|
||||
}
|
||||
}
|
||||
|
||||
hasUnitNearby(
|
||||
tile: TileRef,
|
||||
searchRange: number,
|
||||
@@ -1254,6 +1267,49 @@ export class GameImpl implements Game {
|
||||
gold: goldCaptured,
|
||||
});
|
||||
}
|
||||
|
||||
private updateDefendedStateForDefensePost(
|
||||
center: TileRef,
|
||||
owner: PlayerImpl,
|
||||
) {
|
||||
const range = this.config().defensePostRange();
|
||||
const rangeSq = range * range;
|
||||
|
||||
for (const tile of owner._borderTiles) {
|
||||
if (this._map.euclideanDistSquared(center, tile) <= rangeSq) {
|
||||
const wasDefended = this._map.isDefended(tile);
|
||||
const isDefended = this.unitGrid.hasUnitNearby(
|
||||
tile,
|
||||
range,
|
||||
UnitType.DefensePost,
|
||||
owner.id(),
|
||||
);
|
||||
if (wasDefended !== isDefended) {
|
||||
this._map.setDefended(tile, isDefended);
|
||||
this.recordTileUpdate(tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private updateDefendedStateForTileChange(tile: TileRef, owner: PlayerImpl) {
|
||||
const wasDefended = this._map.isDefended(tile);
|
||||
const isDefended = this.unitGrid.hasUnitNearby(
|
||||
tile,
|
||||
this.config().defensePostRange(),
|
||||
UnitType.DefensePost,
|
||||
owner.id(),
|
||||
);
|
||||
if (wasDefended !== isDefended) {
|
||||
this._map.setDefended(tile, isDefended);
|
||||
}
|
||||
|
||||
if (
|
||||
this.unitGrid.hasUnitNearby(tile, 0, UnitType.DefensePost, owner.id())
|
||||
) {
|
||||
this.updateDefendedStateForDefensePost(tile, owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Or a more dynamic approach that will catch new enum values:
|
||||
|
||||
Reference in New Issue
Block a user