From 2f86d4a2f8b011e708f7b9940cef24f9e268d182 Mon Sep 17 00:00:00 2001 From: phosit Date: Thu, 25 Sep 2025 11:47:19 +0200 Subject: [PATCH] Don't write entity-metadata when deserializing The metadata where written every the turn of deserialization. When on the non rejoining client it was only written when that AI makes a turn and handles the events. --- .../mods/public/simulation/ai/petra/baseManager.js | 13 ++++++++----- .../mods/public/simulation/ai/petra/basesManager.js | 13 +++++++------ .../mods/public/simulation/ai/petra/headquarters.js | 2 +- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/binaries/data/mods/public/simulation/ai/petra/baseManager.js b/binaries/data/mods/public/simulation/ai/petra/baseManager.js index cdf6513716..1819962bbf 100644 --- a/binaries/data/mods/public/simulation/ai/petra/baseManager.js +++ b/binaries/data/mods/public/simulation/ai/petra/baseManager.js @@ -114,7 +114,7 @@ BaseManager.prototype.assignEntity = function(gameState, ent) this.assignResourceToDropsite(gameState, ent, false); }; -BaseManager.prototype.setAnchor = function(gameState, anchorEntity) +BaseManager.prototype.setAnchor = function(gameState, anchorEntity, deserialize = false) { if (!anchorEntity.hasClass("CivCentre")) { @@ -125,10 +125,12 @@ BaseManager.prototype.setAnchor = function(gameState, anchorEntity) { this.anchor = anchorEntity; this.anchorId = anchorEntity.id(); - this.anchor.setMetadata(PlayerID, "baseAnchor", true); + if (!deserialize) + this.anchor.setMetadata(PlayerID, "baseAnchor", true); this.basesManager.resetBaseCache(); } - anchorEntity.setMetadata(PlayerID, "base", this.ID); + if (!deserialize) + anchorEntity.setMetadata(PlayerID, "base", this.ID); this.buildings.updateEnt(anchorEntity); this.accessIndex = getLandAccess(gameState, anchorEntity); return true; @@ -144,7 +146,7 @@ BaseManager.prototype.anchorLost = function(gameState) }; /** Set a building of an anchorless base */ -BaseManager.prototype.setAnchorlessEntity = function(gameState, ent) +BaseManager.prototype.setAnchorlessEntity = function(gameState, ent, deserialize = false) { if (!this.buildings.hasEntities()) { @@ -162,7 +164,8 @@ BaseManager.prototype.setAnchorlessEntity = function(gameState, ent) getLandAccess(gameState, ent)); } - ent.setMetadata(PlayerID, "base", this.ID); + if (!deserialize) + ent.setMetadata(PlayerID, "base", this.ID); this.buildings.updateEnt(ent); return true; }; diff --git a/binaries/data/mods/public/simulation/ai/petra/basesManager.js b/binaries/data/mods/public/simulation/ai/petra/basesManager.js index 44689da1fc..59c5d1362d 100644 --- a/binaries/data/mods/public/simulation/ai/petra/basesManager.js +++ b/binaries/data/mods/public/simulation/ai/petra/basesManager.js @@ -27,7 +27,7 @@ export function BasesManager(Config) this.baseManagers = []; } -BasesManager.prototype.init = function(gameState) +BasesManager.prototype.init = function(gameState, deserialize = false) { // Initialize base map. Each pixel is a base ID, or 0 if not or not accessible. this.basesMap = new InfoMap(gameState.sharedScript, "territory"); @@ -38,9 +38,9 @@ BasesManager.prototype.init = function(gameState) for (const cc of gameState.getOwnStructures().filter(filters.byClass("CivCentre")).values()) if (cc.foundationProgress() === undefined) - this.createBase(gameState, cc, BaseManager.STATE_WITH_ANCHOR); + this.createBase(gameState, cc, BaseManager.STATE_WITH_ANCHOR, deserialize); else - this.createBase(gameState, cc, BaseManager.STATE_UNCONSTRUCTED); + this.createBase(gameState, cc, BaseManager.STATE_UNCONSTRUCTED, deserialize); }; /** @@ -73,7 +73,8 @@ BasesManager.prototype.postinit = function(gameState) * Otherwise create a new one. * TODO when buildings, criteria should depend on distance */ -BasesManager.prototype.createBase = function(gameState, ent, type = BaseManager.STATE_WITH_ANCHOR) +BasesManager.prototype.createBase = function(gameState, ent, type = BaseManager.STATE_WITH_ANCHOR, + deserialize = false) { const access = getLandAccess(gameState, ent); let newbase; @@ -120,9 +121,9 @@ BasesManager.prototype.createBase = function(gameState, ent, type = BaseManager. newbase.reset(type); if (type !== BaseManager.STATE_ANCHORLESS) - newbase.setAnchor(gameState, ent); + newbase.setAnchor(gameState, ent, deserialize); else - newbase.setAnchorlessEntity(gameState, ent); + newbase.setAnchorlessEntity(gameState, ent, deserialize); return newbase; }; diff --git a/binaries/data/mods/public/simulation/ai/petra/headquarters.js b/binaries/data/mods/public/simulation/ai/petra/headquarters.js index 55d1f2a8d0..a2bd842ef7 100644 --- a/binaries/data/mods/public/simulation/ai/petra/headquarters.js +++ b/binaries/data/mods/public/simulation/ai/petra/headquarters.js @@ -2416,7 +2416,7 @@ Headquarters.prototype.Deserialize = function(gameState, data) this.basesManager = new BasesManager(this.Config); - this.basesManager.init(gameState); + this.basesManager.init(gameState, true); this.basesManager.Deserialize(gameState, data.basesManager); this.navalManager = new NavalManager(this.Config);