"use strict"; class World { constructor() { this.w = 1000; this.h = 720; this.viewportW = 1000; this.viewportH = 720; this._worldSizeInitialized = false; this.time = 0; this._fixedSimulationAccumulator = 0; this.day = 1; this.elapsedDays = 0; this.paused = false; this.speed = 1; this.tool = "observe"; this.toolSize = "medium"; this.toolSizes = {}; this.toolPickMode = "free"; this.toolAngles = {}; this.tarinaiPopulationLimit = 0; this.objectLimit = 0; this.resetRuntimeCollections(); this.pointer = { x: 0, y: 0, inside: false, motion: 0 }; this.hoverGrabTarget = null; this.hoverDeleteTarget = null; this.hoverGiveTarget = null; this.hoverPokeTarget = null; this.shootCursorActive = false; this.shootPointerRawX = 0; this.shootPointerRawY = 0; this.shootCursorOffsetX = 0; this.shootCursorOffsetY = 0; this.lastShootAt = -999; this.lastPhase = ""; this.weather = "sunny"; this.worldSeed = window.TarinaiSeedFactory.createWorldSeed() || `w${Date.now().toString(36)}`; this.birthSerial = 0; this.fieldType = "garden"; this.groundType = "soil"; this.fieldZoom = 1; this.cameraX = 0; this.cameraY = 0; this.shakeTimer = 0; this.shakeDuration = 0; this.shakeStrength = 0; this.nextWeatherChange = rand(CONFIG.weatherChangeMin, CONFIG.weatherChangeMax); const tempAnnualUnit = typeof stableUnit === "function" ? stableUnit(`${this.worldSeed}:temperature`, "annual-range") : Math.random(); this.temperatureAuto = true; this.manualTemperature = 10; this.currentTemperature = 10; this.temperatureAnnualRange = 25 + tempAnnualUnit * 10; this.temperatureDailyRange = 0; this.spatial = new SpatialGrid(96); this.spatialItemScratch = []; this.spatialTarinaiScratch = []; this.spatialAntScratch = []; this.spatialObstacleScratch = []; this.spatialFoodScratch = []; this.spatialHazardScratch = []; this.spatialVersion = 0; this.routingObstacleVersion = 0; this.spatialDirty = true; this.terrainDirty = true; this.terrainVersion = 1; this.terrainDirtyReason = "init"; this.terrainLastDirtyAt = 0; this.lastTerrainSignature = ""; this.drawList = []; this.itemCounts = {}; this.effectCounts = {}; this.colonyMood = { id: "relaxed", label: "\u5b89\u5b9a", description: "\u6a19\u6e96\u72b6\u614b", effects: { personality: {} } }; this.updateItemCounts(); this.updateEffectCounts(); this.markTerrainDirty?.("reset"); this.rebuildSpatial(true); } resetRuntimeCollections() { this.tarinai = []; this.items = []; this.residues = []; this.residueById = new Map(); this.residueTypeBuckets = new Map(); this.residueCells = new Map(); this.residueSerial = 0; this.residueDecayAccumulator = 0; this.ants = []; this.effects = []; this.logs = []; this.memorialRequests = []; this.events = window.TarinaiEvents || null; this.eventCounters = {}; this.countsTimer = 0; this.compactTimer = 0; this.drawSortTimer = 0; this._maintenanceScheduleReady = false; this._nextTransientRuntimePruneAt = 0; this.drawListDirty = true; this.antUpdatePhase = 0; this.selected = null; this.hoverGiveTarget = null; this.hoverPokeTarget = null; this.deadCount = 0; this.birthEventCount = 0; this.achievementPlayerPlacedActiveCount = 0; this.achievementEnemyAntKills = 0; this.achievementSelfSufficientStartAt = -1; this.achievementLastInterventionAt = 0; this.achievementNoDeathStartAt = -1; this.achievementHappyStartAt = -1; this.achievementEliteFewStartAt = -1; this.achievementFightSessionSerial = 0; this.liveIdNext = 1; this.liveIdSerial = 0; this.liveTarinai = new Map(); this.lastBirthAt = -999; this.lastColonyMoodPopulation = NaN; this.nextColonyMoodEvalAt = 0; this.maxGeneration = 1; this.family = {}; this.familyVersion = 0; this.familyTreeDirty = true; this.relationNotices = {}; this.resolvedFightIds = {}; this.fightPairCooldowns = {}; this.ballCollisionMemo = new Map(); this.tarinaiCollisionMemo = new Map(); this.deadTarinaiSinceRuntimePrune = 0; this.tarinaiRuntimePrunePending = false; this._deadTarinaiIdsPendingCleanup = new Set(); // Hot colony counts are maintained by mutation hooks. Rebuild only after // bulk restore/reset paths that bypass the normal add/remove helpers. this._tarinaiCountCache = { alive: 0, zunchiSlaves: 0, tarinaiKings: 0 }; this._tarinaiCountDirty = false; this._colonyStatsDynamicCache = null; } } if (typeof window !== "undefined") window.World = World; if (typeof globalThis !== "undefined") globalThis.World = World;