2026-11-03 08:37:07 +00:00
|
|
|
// The mock's made-up neighbours: other players' villages round 0|0, so the map shows every
|
2026-11-03 09:17:53 +00:00
|
|
|
// kind of village (tribe mates, allies, a NAP, enemies, strangers) in every size from a
|
|
|
|
|
// hamlet to a walled town. Each player holds a patch of land, like real players' villages
|
2026-11-03 08:37:07 +00:00
|
|
|
// bunch up. Placeholders only: the backend places real players.
|
|
|
|
|
|
|
|
|
|
import type { MapRelationKind } from '~/types/map'
|
|
|
|
|
import type { VillageRef } from '~/types/game'
|
|
|
|
|
|
|
|
|
|
interface Neighbour {
|
|
|
|
|
id: number
|
|
|
|
|
name: string
|
|
|
|
|
tribe: { id: number; tag: string } | null
|
|
|
|
|
relation: MapRelationKind
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const KRN = { id: -51, tag: 'KRN' }
|
|
|
|
|
const RAB = { id: -54, tag: 'RAB' }
|
|
|
|
|
const PLAYERS: Neighbour[] = [
|
|
|
|
|
{ id: -201, name: 'Adalbert', tribe: KRN, relation: 'tribe' },
|
|
|
|
|
{ id: -202, name: 'Irmgard', tribe: KRN, relation: 'tribe' },
|
|
|
|
|
{ id: -203, name: 'Sigmund', tribe: { id: -52, tag: 'EIS' }, relation: 'ally' },
|
|
|
|
|
{ id: -204, name: 'Kunigunde', tribe: { id: -53, tag: 'MOR' }, relation: 'nap' },
|
|
|
|
|
{ id: -205, name: 'Gunther', tribe: RAB, relation: 'enemy' },
|
|
|
|
|
{ id: -206, name: 'Hildegard', tribe: RAB, relation: 'enemy' },
|
|
|
|
|
{ id: -207, name: 'Volkmar', tribe: null, relation: 'none' },
|
|
|
|
|
{ id: -208, name: 'Ermentrud', tribe: null, relation: 'none' },
|
|
|
|
|
]
|
|
|
|
|
const NAMES = ['Birkenhof', 'Dornach', 'Erlbach', 'Fichtau', 'Grauweiler', 'Haselgrund', 'Kalteneck', 'Lindwurm', 'Mühlstein', 'Nebelried', 'Ottersbach', 'Rotenfels']
|
|
|
|
|
|
2026-11-03 09:17:53 +00:00
|
|
|
/** Points from the lowest to the top of each of the map's six size tiers, and how common each is. */
|
2026-11-03 08:37:07 +00:00
|
|
|
const TIERS: [number, number, number][] = [
|
2026-11-03 09:17:53 +00:00
|
|
|
[0.28, 40, 299],
|
|
|
|
|
[0.5, 300, 999],
|
|
|
|
|
[0.7, 1000, 2999],
|
|
|
|
|
[0.84, 3000, 5999],
|
|
|
|
|
[0.93, 6000, 9999],
|
|
|
|
|
[1, 10000, 14000],
|
2026-11-03 08:37:07 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
const MAP_SIZE = 1000
|
|
|
|
|
const MAP_MIN = -MAP_SIZE / 2
|
|
|
|
|
const ID_BASE = -3_000_000
|
|
|
|
|
const RADIUS = 30
|
|
|
|
|
|
|
|
|
|
const rand = (x: number, y: number, seed: number) => (Math.imul((x * 73856093) ^ (y * 19349663) ^ (seed * 83492791), 1274126177) >>> 0) / 4294967296
|
|
|
|
|
|
|
|
|
|
/** A neighbour's village on a field, or null; the fields round 0|0 stay free for the player. */
|
|
|
|
|
export function neighbourAt(x: number, y: number) {
|
|
|
|
|
if (Math.abs(x) > RADIUS || Math.abs(y) > RADIUS || (Math.abs(x) <= 2 && Math.abs(y) <= 2)) return null
|
|
|
|
|
if (rand(x, y, 5) >= 0.16) return null
|
|
|
|
|
const player = PLAYERS[Math.floor(rand(Math.floor(x / 9), Math.floor(y / 9), 6) * PLAYERS.length)]!
|
|
|
|
|
const pick = rand(x, y, 7)
|
|
|
|
|
const [, lo, hi] = TIERS.find(([upTo]) => pick < upTo)!
|
|
|
|
|
return {
|
|
|
|
|
id: ID_BASE - ((y - MAP_MIN) * MAP_SIZE + (x - MAP_MIN)),
|
|
|
|
|
name: NAMES[Math.floor(rand(x, y, 8) * NAMES.length)]!,
|
|
|
|
|
x,
|
|
|
|
|
y,
|
|
|
|
|
points: lo + Math.floor(rand(x, y, 9) * (hi - lo)),
|
|
|
|
|
player,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** A neighbour's village by id, as the mock's other lookups want it. */
|
|
|
|
|
export function neighbourRef(id: number): VillageRef | null {
|
|
|
|
|
if (id > ID_BASE || id <= ID_BASE - MAP_SIZE * MAP_SIZE) return null
|
|
|
|
|
const n = ID_BASE - id
|
|
|
|
|
const v = neighbourAt((n % MAP_SIZE) + MAP_MIN, Math.floor(n / MAP_SIZE) + MAP_MIN)
|
|
|
|
|
return v ? { id: v.id, name: v.name, x: v.x, y: v.y, player: { id: v.player.id, name: v.player.name } } : null
|
|
|
|
|
}
|