tarinai/js/world.js

121 lines
4 KiB
JavaScript
Raw Normal View History

2026-06-20 20:29:44 +09:00
"use strict";
2026-06-19 14:00:48 +09:00
2026-06-21 14:09:35 +09:00
class World { constructor() {
2026-06-19 14:00:48 +09:00
this.w = 1000;
this.h = 720;
this.viewportW = 1000;
this.viewportH = 720;
this.time = 0;
this.day = 1;
this.paused = false;
this.speed = 1;
this.tool = "observe";
this.toolSize = "medium";
this.toolSizes = {};
2026-07-15 14:44:29 +09:00
this.toolPickMode = "free";
2026-06-25 22:30:35 +09:00
this.toolAngles = {};
2026-07-09 16:08:11 +09:00
this.tarinaiPopulationLimit = 0;
this.objectLimit = 0;
2026-07-01 14:41:05 +09:00
this.resetRuntimeCollections();
this.pointer = { x: 0, y: 0, inside: false, motion: 0 };
2026-06-27 21:50:05 +09:00
this.hoverGrabTarget = null;
this.hoverDeleteTarget = null;
2026-07-11 21:13:39 +09:00
this.hoverGiveTarget = null;
2026-07-15 14:44:29 +09:00
this.hoverPokeTarget = null;
2026-06-27 21:50:05 +09:00
this.shootCursorActive = false;
this.shootPointerRawX = 0;
this.shootPointerRawY = 0;
this.shootCursorOffsetX = 0;
this.shootCursorOffsetY = 0;
this.lastShootAt = -999;
2026-06-19 14:00:48 +09:00
this.lastPhase = "";
this.weather = "sunny";
2026-06-29 16:21:58 +09:00
this.worldSeed = window.TarinaiSeedFactory.createWorldSeed() || `w${Date.now().toString(36)}`;
2026-06-25 22:30:35 +09:00
this.birthSerial = 0;
2026-06-19 14:00:48 +09:00
this.fieldType = "garden";
2026-06-25 14:51:58 +09:00
this.groundType = "soil";
2026-06-19 14:00:48 +09:00
this.fieldZoom = 1;
this.cameraX = 0;
this.cameraY = 0;
2026-06-21 14:09:35 +09:00
this.shakeTimer = 0;
this.shakeDuration = 0;
this.shakeStrength = 0;
2026-06-19 14:00:48 +09:00
this.nextWeatherChange = rand(CONFIG.weatherChangeMin, CONFIG.weatherChangeMax);
2026-06-30 10:57:06 +09:00
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;
2026-06-19 14:00:48 +09:00
this.spatial = new SpatialGrid(96);
2026-06-20 23:27:39 +09:00
this.spatialItemScratch = [];
this.spatialTarinaiScratch = [];
2026-06-21 14:09:35 +09:00
this.spatialAntScratch = [];
this.spatialObstacleScratch = [];
this.spatialFoodScratch = [];
this.spatialHazardScratch = [];
this.spatialVersion = 0;
this.spatialDirty = true;
this.terrainDirty = true;
this.terrainVersion = 1;
this.terrainDirtyReason = "init";
this.terrainLastDirtyAt = 0;
this.lastTerrainSignature = "";
2026-06-19 14:00:48 +09:00
this.drawList = [];
this.itemCounts = {};
this.effectCounts = {};
2026-06-28 13:40:41 +09:00
this.colonyMood = { id: "relaxed", label: "\u5b89\u5b9a", description: "\u6a19\u6e96\u72b6\u614b", effects: { personality: {} } };
2026-06-19 14:00:48 +09:00
this.updateItemCounts();
this.updateEffectCounts();
2026-06-21 14:09:35 +09:00
this.markTerrainDirty?.("reset");
this.rebuildSpatial(true);
2026-06-19 14:00:48 +09:00
}
2026-07-01 14:41:05 +09:00
resetRuntimeCollections() {
this.tarinai = [];
this.items = [];
this.ants = [];
this.effects = [];
this.logs = [];
this.events = window.TarinaiEvents || null;
this.eventCounters = {};
this.countsTimer = 0;
this.compactTimer = 0;
this.drawSortTimer = 0;
this.drawListDirty = true;
this.antUpdatePhase = 0;
this.selected = null;
2026-07-11 21:13:39 +09:00
this.hoverGiveTarget = null;
2026-07-15 14:44:29 +09:00
this.hoverPokeTarget = null;
2026-07-01 14:41:05 +09:00
this.deadCount = 0;
2026-07-10 16:40:06 +09:00
this.birthEventCount = 0;
2026-07-15 14:44:29 +09:00
this.achievementNaturalSlaveGenerations = [];
this.achievementNaturalKingGenerations = [];
this.achievementPlayerPlacementCount = 0;
this.achievementDirectFeedCount = 0;
this.achievementRobotCleanCount = 0;
this.achievementEnemyAntKills = 0;
this.achievementLastTarinaiDamageAt = -Infinity;
this.achievementSelfSufficientStartAt = -1;
this.achievementLastDirectFeedAt = -Infinity;
this.achievementLastInterventionAt = 0;
this.achievementNoDeathStartAt = -1;
this.achievementHappyStartAt = -1;
2026-07-01 14:41:05 +09:00
this.liveIdNext = 1;
this.liveIdSerial = 0;
this.liveTarinai = new Map();
this.lastBirthAt = -999;
2026-07-16 22:12:03 +09:00
this.lastColonyMoodPopulation = NaN;
this.nextColonyMoodEvalAt = 0;
2026-07-01 14:41:05 +09:00
this.maxGeneration = 1;
this.family = {};
this.familyVersion = 0;
this.familyTreeDirty = true;
this.relationNotices = {};
this.resolvedFightIds = {};
this.fightPairCooldowns = {};
}
2026-06-19 14:00:48 +09:00
}
2026-06-21 14:09:35 +09:00
if (typeof window !== "undefined") window.World = World;
if (typeof globalThis !== "undefined") globalThis.World = World;