2026-03-20 08:11:31 +00:00
|
|
|
export enum TileType {
|
|
|
|
|
DEEP_WATER = 0,
|
|
|
|
|
SHALLOW_WATER = 1,
|
|
|
|
|
SAND = 2,
|
|
|
|
|
GRASS = 3,
|
|
|
|
|
DARK_GRASS = 4,
|
|
|
|
|
FOREST = 5,
|
|
|
|
|
ROCK = 6,
|
|
|
|
|
FLOOR = 7,
|
|
|
|
|
WALL = 8,
|
|
|
|
|
TILLED_SOIL = 9,
|
|
|
|
|
WATERED_SOIL = 10,
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 11:55:24 +00:00
|
|
|
/** Tiles that are always impassable regardless of what is on them. */
|
2026-03-20 08:11:31 +00:00
|
|
|
export const IMPASSABLE = new Set<number>([
|
|
|
|
|
TileType.DEEP_WATER,
|
|
|
|
|
TileType.SHALLOW_WATER,
|
|
|
|
|
TileType.WALL,
|
|
|
|
|
])
|
|
|
|
|
|
2026-03-23 11:55:24 +00:00
|
|
|
/**
|
|
|
|
|
* Terrain tiles whose passability depends on whether a resource
|
|
|
|
|
* (tree or rock) is currently placed on them.
|
|
|
|
|
* An empty FOREST tile is walkable forest floor; a ROCK tile without a
|
|
|
|
|
* rock resource is just rocky ground.
|
|
|
|
|
*/
|
|
|
|
|
export const RESOURCE_TERRAIN = new Set<number>([TileType.FOREST, TileType.ROCK])
|
|
|
|
|
|
2026-03-21 16:15:21 +00:00
|
|
|
/** Tiles on which tree seedlings may be planted. */
|
|
|
|
|
export const PLANTABLE_TILES = new Set<TileType>([TileType.GRASS, TileType.DARK_GRASS])
|
|
|
|
|
|
|
|
|
|
export type ItemId = 'wood' | 'stone' | 'wheat_seed' | 'carrot_seed' | 'wheat' | 'carrot' | 'tree_seed'
|
2026-03-20 08:11:31 +00:00
|
|
|
|
|
|
|
|
export type BuildingType = 'floor' | 'wall' | 'chest' | 'bed' | 'stockpile_zone'
|
|
|
|
|
|
|
|
|
|
export type CropKind = 'wheat' | 'carrot'
|
|
|
|
|
|
|
|
|
|
export type JobType = 'chop' | 'mine' | 'farm'
|
|
|
|
|
|
|
|
|
|
export type AIState = 'idle' | 'walking' | 'working' | 'sleeping'
|
|
|
|
|
|
|
|
|
|
export interface JobPriorities {
|
|
|
|
|
chop: number // 0 = disabled, 1 = highest, 4 = lowest
|
|
|
|
|
mine: number
|
|
|
|
|
farm: number
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface VillagerJob {
|
|
|
|
|
type: JobType
|
|
|
|
|
targetId: string
|
|
|
|
|
tileX: number
|
|
|
|
|
tileY: number
|
|
|
|
|
carrying: Partial<Record<ItemId, number>>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface VillagerState {
|
|
|
|
|
id: string
|
|
|
|
|
name: string
|
|
|
|
|
x: number
|
|
|
|
|
y: number
|
|
|
|
|
bedId: string | null
|
|
|
|
|
job: VillagerJob | null
|
|
|
|
|
priorities: JobPriorities
|
|
|
|
|
energy: number
|
|
|
|
|
aiState: AIState
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ResourceNodeState {
|
|
|
|
|
id: string
|
|
|
|
|
tileX: number
|
|
|
|
|
tileY: number
|
|
|
|
|
kind: 'tree' | 'rock'
|
|
|
|
|
hp: number
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface BuildingState {
|
|
|
|
|
id: string
|
|
|
|
|
tileX: number
|
|
|
|
|
tileY: number
|
|
|
|
|
kind: BuildingType
|
|
|
|
|
ownerId: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface CropState {
|
|
|
|
|
id: string
|
|
|
|
|
tileX: number
|
|
|
|
|
tileY: number
|
|
|
|
|
kind: CropKind
|
|
|
|
|
stage: number
|
|
|
|
|
maxStage: number
|
|
|
|
|
stageTimerMs: number
|
|
|
|
|
watered: boolean
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface PlayerState {
|
|
|
|
|
id: string
|
|
|
|
|
x: number
|
|
|
|
|
y: number
|
|
|
|
|
inventory: Partial<Record<ItemId, number>>
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-21 16:15:21 +00:00
|
|
|
export interface TreeSeedlingState {
|
|
|
|
|
id: string
|
|
|
|
|
tileX: number
|
|
|
|
|
tileY: number
|
|
|
|
|
/** Growth stage: 0 = sprout, 1 = sapling, 2 = mature (converts to resource). */
|
|
|
|
|
stage: number
|
|
|
|
|
/** Time remaining until next stage advance, in milliseconds. */
|
|
|
|
|
stageTimerMs: number
|
|
|
|
|
/** The tile type that was under the seedling when planted (GRASS or DARK_GRASS). */
|
|
|
|
|
underlyingTile: TileType
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-20 08:11:31 +00:00
|
|
|
export interface WorldState {
|
|
|
|
|
seed: number
|
|
|
|
|
tiles: number[]
|
|
|
|
|
resources: Record<string, ResourceNodeState>
|
|
|
|
|
buildings: Record<string, BuildingState>
|
|
|
|
|
crops: Record<string, CropState>
|
|
|
|
|
villagers: Record<string, VillagerState>
|
|
|
|
|
stockpile: Partial<Record<ItemId, number>>
|
2026-03-21 16:15:21 +00:00
|
|
|
/** Planted tree seedlings, keyed by ID. */
|
|
|
|
|
treeSeedlings: Record<string, TreeSeedlingState>
|
|
|
|
|
/**
|
|
|
|
|
* Recovery timers for DARK_GRASS tiles, keyed by "tileX,tileY".
|
|
|
|
|
* Value is remaining milliseconds until the tile reverts to GRASS.
|
|
|
|
|
*/
|
|
|
|
|
tileRecovery: Record<string, number>
|
2026-03-20 08:11:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface GameStateData {
|
|
|
|
|
version: number
|
|
|
|
|
world: WorldState
|
|
|
|
|
player: PlayerState
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type GameAction =
|
|
|
|
|
| { type: 'PLAYER_MOVE'; x: number; y: number }
|
|
|
|
|
| { type: 'HARVEST_RESOURCE'; resourceId: string; rewards: Partial<Record<ItemId, number>> }
|
|
|
|
|
| { type: 'CHANGE_TILE'; tileX: number; tileY: number; tile: TileType }
|
|
|
|
|
| { type: 'PLACE_BUILDING'; building: BuildingState; costs: Partial<Record<ItemId, number>> }
|
|
|
|
|
| { type: 'REMOVE_BUILDING'; buildingId: string }
|
|
|
|
|
| { type: 'ADD_ITEMS'; items: Partial<Record<ItemId, number>> }
|
|
|
|
|
| { type: 'PLANT_CROP'; crop: CropState; seedItem: ItemId }
|
|
|
|
|
| { type: 'WATER_CROP'; cropId: string }
|
|
|
|
|
| { type: 'HARVEST_CROP'; cropId: string; rewards: Partial<Record<ItemId, number>> }
|
|
|
|
|
| { type: 'SPAWN_VILLAGER'; villager: VillagerState }
|
|
|
|
|
| { type: 'VILLAGER_SET_JOB'; villagerId: string; job: VillagerJob | null }
|
|
|
|
|
| { type: 'VILLAGER_SET_AI'; villagerId: string; aiState: AIState }
|
|
|
|
|
| { type: 'VILLAGER_HARVEST_RESOURCE'; villagerId: string; resourceId: string }
|
|
|
|
|
| { type: 'VILLAGER_HARVEST_CROP'; villagerId: string; cropId: string }
|
|
|
|
|
| { type: 'VILLAGER_DEPOSIT'; villagerId: string }
|
|
|
|
|
| { type: 'UPDATE_PRIORITIES'; villagerId: string; priorities: JobPriorities }
|
2026-03-21 16:15:21 +00:00
|
|
|
| { type: 'PLANT_TREE_SEED'; seedling: TreeSeedlingState }
|
|
|
|
|
| { type: 'REMOVE_TREE_SEEDLING'; seedlingId: string }
|
|
|
|
|
| { type: 'SPAWN_RESOURCE'; resource: ResourceNodeState }
|
|
|
|
|
| { type: 'TILE_RECOVERY_START'; tileX: number; tileY: number }
|