From c51f27fc17d6b7a1343901600de773581589409b Mon Sep 17 00:00:00 2001 From: "Fabian @ Blax Software" Date: Tue, 3 Nov 2026 09:37:07 +0100 Subject: [PATCH] feat: mock map: neighbours of every relation and size, barbarians of every size, a grown second own village, 61-field views Co-Authored-By: Claude Opus 5.5 --- app/mock/neighbours.ts | 69 ++++++++++++++++++++++++++++++++++++++++++ app/mock/server.ts | 52 ++++++++++++++++++++++++++----- 2 files changed, 114 insertions(+), 7 deletions(-) create mode 100644 app/mock/neighbours.ts diff --git a/app/mock/neighbours.ts b/app/mock/neighbours.ts new file mode 100644 index 0000000..d816be2 --- /dev/null +++ b/app/mock/neighbours.ts @@ -0,0 +1,69 @@ +// The mock's made-up neighbours: other players' villages round 0|0, so the map shows every +// kind of village (tribe mates, allies, a NAP, enemies, strangers) in every size from a few +// huts to a walled town. Each player holds a patch of land, like real players' villages +// 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'] + +/** Points from the lowest to the top of each of the map's five size tiers, and how common each is. */ +const TIERS: [number, number, number][] = [ + [0.3, 40, 149], + [0.55, 150, 499], + [0.75, 500, 1499], + [0.9, 1500, 4999], + [1, 5000, 12000], +] + +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 +} diff --git a/app/mock/server.ts b/app/mock/server.ts index d6afdfc..1cac171 100644 --- a/app/mock/server.ts +++ b/app/mock/server.ts @@ -69,6 +69,7 @@ import { atLevel, } from './catalog' import type { TradeReport } from '~/types/game' +import { neighbourAt, neighbourRef } from './neighbours' import { dropMarket, type MarketHost, marketEffects, marketHandlers, type MockMarket, nextMarketDue, processMarket, traderAt, traderRef, villageMarket } from './market' interface MockBuilding { @@ -764,11 +765,12 @@ const MAP_SIZE = 1000 const MAP_MIN = -MAP_SIZE / 2 const BARBARIAN_NAME = 'Barbarian village' -/** A barbarian made up from a hash of the field, around 0|0 only; a player village on the field wins. */ +/** A barbarian made up from a hash of the field, around 0|0 only; a player village on the field wins. Mostly small, a few grown big. */ function barbarianAt(x: number, y: number) { const r = (Math.imul(x * 73856093 ^ y * 19349663, 1274126177) >>> 0) / 4294967296 - const near = Math.abs(x) <= 25 && Math.abs(y) <= 25 && !traderAt(x, y) - return near && r < 0.08 ? { id: -((y - MAP_MIN) * MAP_SIZE + (x - MAP_MIN) + 1), name: BARBARIAN_NAME, points: 20 + Math.floor(r * 1000) } : null + const near = Math.abs(x) <= 30 && Math.abs(y) <= 30 && !traderAt(x, y) && !neighbourAt(x, y) + const size = (Math.imul(x * 19349663 ^ y * 83492791, 1274126177) >>> 0) / 4294967296 + return near && r < 0.08 ? { id: -((y - MAP_MIN) * MAP_SIZE + (x - MAP_MIN) + 1), name: BARBARIAN_NAME, points: 20 + Math.floor(size * size * 3000) } : null } /** The season's crown forts, barbarian in the mock, on the backend's ring round 0|0. */ @@ -781,8 +783,9 @@ function mapView(state: MockState, user: AuthUser, data: any): MapView { const own = state.villages.find((v) => v.world_id === Number(data.world_id) && v.user_id === user.id) const cx = Number.isFinite(Number(data.x)) && data.x !== undefined ? Number(data.x) : (own?.x ?? 0) const cy = Number.isFinite(Number(data.y)) && data.y !== undefined ? Number(data.y) : (own?.y ?? 0) - const w = Math.max(1, Math.min(41, Number(data.w) || 15)) - const h = Math.max(1, Math.min(41, Number(data.h) || 15)) + // The backend's world.map.max_view. + const w = Math.max(1, Math.min(61, Number(data.w) || 15)) + const h = Math.max(1, Math.min(61, Number(data.h) || 15)) const x0 = Math.max(MAP_MIN, Math.min(MAP_MIN + size - w, cx - Math.floor(w / 2))) const y0 = Math.max(MAP_MIN, Math.min(MAP_MIN + size - h, cy - Math.floor(h / 2))) const villages: MapVillage[] = [] @@ -816,6 +819,12 @@ function mapView(state: MockState, user: AuthUser, data: any): MapView { villages.push({ id: -900 - crown, x, y, name: 'Crown fort', points: 3000, continent: continentOf(x, y), player: null, own: false, crown: true, relation: 'barbarian' }) continue } + const neighbour = neighbourAt(x, y) + if (neighbour) { + const { player, ...village } = neighbour + villages.push({ ...village, continent: continentOf(x, y), player: { id: player.id, name: player.name, tribe: player.tribe }, own: false, crown: false, relation: player.relation }) + continue + } const barbarian = barbarianAt(x, y) if (barbarian) { villages.push({ ...barbarian, x, y, continent: continentOf(x, y), player: null, own: false, crown: false, relation: 'barbarian' }) @@ -859,7 +868,7 @@ const REPORTS_PER_PAGE = 25 const LOOTED = ['wood', 'clay', 'iron'] as const function villageRef(state: MockState, id: number): VillageRef { - const trader = traderRef(id) + const trader = traderRef(id) ?? neighbourRef(id) if (trader) return { ...trader } if (id < 0) return { id, name: BARBARIAN_NAME, x: ((-id - 1) % MAP_SIZE) + MAP_MIN, y: Math.floor((-id - 1) / MAP_SIZE) + MAP_MIN, player: null } const v = state.villages.find((v) => v.id === id) @@ -874,6 +883,8 @@ function villageAt(state: MockState, worldId: number, x: number, y: number): Vil if (v) return villageRef(state, v.id) const trader = traderAt(x, y) if (trader) return { ...trader } + const neighbour = neighbourAt(x, y) + if (neighbour) return villageRef(state, neighbour.id) const barbarian = barbarianAt(x, y) return barbarian ? villageRef(state, barbarian.id) : null } @@ -1250,7 +1261,7 @@ function createVillage(state: MockState, user: AuthUser, worldId: number, now: n const taken = new Set(state.villages.filter((v) => v.world_id === worldId).map((v) => `${v.x}|${v.y}`)) let x = 0 let y = 0 - while (taken.has(`${x}|${y}`) || traderAt(x, y)) { + while (taken.has(`${x}|${y}`) || traderAt(x, y) || neighbourAt(x, y)) { x = -25 + Math.floor(Math.random() * 51) y = -25 + Math.floor(Math.random() * 51) } @@ -1273,6 +1284,31 @@ function createVillage(state: MockState, user: AuthUser, worldId: number, now: n return v } +/** The player's second village a few fields from the first, its buildings grown to a town's (map size tier 3). */ +function grownVillage(state: MockState, user: AuthUser, first: MockVillage, now: number): MockVillage { + const taken = new Set(state.villages.filter((v) => v.world_id === first.world_id).map((v) => `${v.x}|${v.y}`)) + const free = ([dx, dy]: [number, number]) => { + const x = first.x + dx + const y = first.y + dy + return !taken.has(`${x}|${y}`) && !traderAt(x, y) && !neighbourAt(x, y) + } + const [dx, dy] = ([[4, -3], [-4, 3], [5, 2], [-3, -5], [2, 5]] as [number, number][]).find(free) ?? [6, 6] + const v: MockVillage = { ...createVillage(state, user, first.world_id, now), name: `${user.name}'s outpost`, x: first.x + dx, y: first.y + dy, buildings: [] } + const levels: [BuildingType, number][] = [ + ['headquarters', 20], + ['storage', 14], + ['farm', 14], + ['timber_camp', 12], + ['clay_pit', 12], + ['iron_mine', 12], + ['barracks', 10], + ['wall', 10], + ['rally_point', 1], + ] + for (const [type, level] of levels) v.buildings.push({ id: nextId(state), type, level, priority: DEFAULT_PRIORITY }) + return v +} + // WS intents. // A short copy of the quest lines with building goals only; the backend has the real book. @@ -1392,6 +1428,8 @@ const handlers: Record = { if (!v) { v = createVillage(state, user, world.id, now) state.villages.push(v) + // A second, long grown village nearby, so the map shows an own village besides the current one. + state.villages.push(grownVillage(state, user, v, now)) } return { village_id: v.id } },