-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move area tracking into a client player class
- Loading branch information
Showing
4 changed files
with
51 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import {Player} from "./Player"; | ||
import {TerritoryTransaction} from "../transaction/TerritoryTransaction"; | ||
import {onNeighbors} from "../../util/MathUtil"; | ||
import {HSLColor} from "../../util/HSLColor"; | ||
import {areaCalculator} from "../../map/area/AreaCalculator"; | ||
import {territoryManager} from "../TerritoryManager"; | ||
|
||
let areaIndex: Uint16Array; | ||
|
||
export class ClientPlayer extends Player { | ||
constructor(id: number, name: string, baseColor: HSLColor) { | ||
super(id, name, baseColor); | ||
|
||
areaIndex = new Uint16Array(areaCalculator.preprocessMap()); | ||
} | ||
|
||
addTile(tile: number, transaction: TerritoryTransaction) { | ||
super.addTile(tile, transaction); | ||
|
||
onNeighbors(tile, neighbor => { | ||
if (territoryManager.isWater(neighbor)) { | ||
areaIndex[areaCalculator.areaIndex[neighbor]]++; | ||
} | ||
}); | ||
} | ||
|
||
removeTile(tile: number, transaction: TerritoryTransaction) { | ||
super.removeTile(tile, transaction); | ||
|
||
onNeighbors(tile, neighbor => { | ||
if (territoryManager.isWater(neighbor)) { | ||
areaIndex[areaCalculator.areaIndex[neighbor]]--; | ||
} | ||
}); | ||
} | ||
} | ||
|
||
/** | ||
* Check if a player has territory neighboring a specific area. | ||
* This is used to determine whether an area needs to be checked for potential attacks or boat placements. | ||
* @param area The area to check | ||
*/ | ||
export function hasTerritoryNear(area: number): boolean { | ||
return areaIndex[area] > 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters