Fix border color changes edge cases (#754)

## Description:

Fixes a couple of bugs with the defended border color:
- When a defense post is destroyed it doesnt redraw defended border to
normal ones
- The distance to draw borders at unit update is not the same as
territory update
- When a defense post changes owner, only the directly touching borders
were redrawn. Had to refactor units a bit so it keeps track of the last
owner

## Gifs:
Before fix:

![image](https://github.com/user-attachments/assets/99b2763c-9c49-4d5d-8059-a9f938e8cef8)


After fix:

![capture](https://github.com/user-attachments/assets/4ebf388d-91e4-4e9e-bc96-9fe6e02cd9ea)

![destruct](https://github.com/user-attachments/assets/5a1204a8-d5c4-473f-8f4d-5cc46cd19080)



## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced
- [x] I understand that submitting code with bugs that could have been
caught through manual testing blocks releases and new features for all
contributors

## Please put your Discord username so you can be contacted if a bug or
regression is found:

VivaciousBox
This commit is contained in:
Vivacious Box
2025-05-15 11:48:18 -07:00
committed by GitHub
parent 3b9e94ddb9
commit c65c9a6ca8
5 changed files with 21 additions and 35 deletions
+5 -11
View File
@@ -3,11 +3,7 @@ import { Colord } from "colord";
import { Theme } from "../../../core/configuration/Config";
import { EventBus } from "../../../core/EventBus";
import { Cell, PlayerType, UnitType } from "../../../core/game/Game";
import {
euclDistFN,
manhattanDistFN,
TileRef,
} from "../../../core/game/GameMap";
import { euclDistFN, TileRef } from "../../../core/game/GameMap";
import { GameUpdateType, UnitUpdate } from "../../../core/game/GameUpdates";
import { GameView, PlayerView } from "../../../core/game/GameView";
import { PseudoRandom } from "../../../core/PseudoRandom";
@@ -64,17 +60,15 @@ export class TerritoryLayer implements Layer {
this.game.recentlyUpdatedTiles().forEach((t) => this.enqueueTile(t));
this.game.updatesSinceLastTick()[GameUpdateType.Unit].forEach((u) => {
const update = u as UnitUpdate;
if (update.unitType == UnitType.DefensePost && update.isActive) {
if (update.unitType == UnitType.DefensePost) {
const tile = update.pos;
this.game
.bfs(
tile,
manhattanDistFN(tile, this.game.config().defensePostRange()),
)
.bfs(tile, euclDistFN(tile, this.game.config().defensePostRange()))
.forEach((t) => {
if (
this.game.isBorder(t) &&
this.game.ownerID(t) == update.ownerID
(this.game.ownerID(t) == update.ownerID ||
this.game.ownerID(t) == update.lastOwnerID)
) {
this.enqueueTile(t);
}