Index: binaries/data/mods/public/simulation/ai/common-api/shared.js =================================================================== --- binaries/data/mods/public/simulation/ai/common-api/shared.js +++ binaries/data/mods/public/simulation/ai/common-api/shared.js @@ -115,18 +115,6 @@ this.accessibility = new m.Accessibility(); this.accessibility.init(state, this.terrainAnalyzer); - // Resource types: ignore = not used for resource maps - // abundant = abundant resource with small amount each - // sparse = sparse resource, but huge amount each - // The following maps are defined in TerrainAnalysis.js and are used for some building placement (cc, dropsites) - // They are updated by checking for create and destroy events for all resources - this.normalizationFactor = { "abundant": 50, "sparse": 90 }; - this.influenceRadius = { "abundant": 36, "sparse": 48 }; - this.ccInfluenceRadius = { "abundant": 60, "sparse": 120 }; - this.resourceMaps = {}; // Contains maps showing the density of resources - this.ccResourceMaps = {}; // Contains maps showing the density of resources, optimized for CC placement. - this.createResourceMaps(); - this.gameState = {}; for (let player of this._players) { @@ -389,13 +377,22 @@ descendant.prototype[p] = parent.prototype[p]; }; -/** creates a map of resource density */ -m.SharedScript.prototype.createResourceMaps = function() +/** + * Creates a map of resource density, updated by checking for create and destroy events for all resources. + */ +m.SharedScript.prototype.createResourceMaps = function(parameters) { + this.normalizationFactor = parameters.normalisationFactor; + this.influenceRadius = parameters.influenceRadius; + this.ccInfluenceRadius = parameters.ccInfluenceRadius; + + this.resourceMaps = {}; // Contains maps showing the density of resources + this.ccResourceMaps = {}; // Contains maps showing the density of resources, optimized for CC placement. + for (const resource of Resources.GetCodes()) { if (this.resourceMaps[resource] || - !(Resources.GetResource(resource).aiAnalysisInfluenceGroup in this.normalizationFactor)) + !this.normalizationFactor[resource]) continue; // We're creating them 8-bit. Things could go above 255 if there are really tons of resources // But at that point the precision is not really important anyway. And it saves memory. @@ -452,11 +449,10 @@ const cellSize = this.resourceMaps[resource].cellSize; const x = Math.floor(entPos[0] / cellSize); const y = Math.floor(entPos[1] / cellSize); - const grp = Resources.GetResource(resource).aiAnalysisInfluenceGroup; - const strength = multiplication * ent.resourceSupplyMax() / this.normalizationFactor[grp]; - this.resourceMaps[resource].addInfluence(x, y, this.influenceRadius[grp] / cellSize, strength / 2, "constant"); - this.resourceMaps[resource].addInfluence(x, y, this.influenceRadius[grp] / cellSize, strength / 2); - this.ccResourceMaps[resource].addInfluence(x, y, this.ccInfluenceRadius[grp] / cellSize, strength, "constant"); + const strength = multiplication * ent.resourceSupplyMax() / this.normalizationFactor[resource]; + this.resourceMaps[resource].addInfluence(x, y, this.influenceRadius[resource] / cellSize, strength / 2, "constant"); + this.resourceMaps[resource].addInfluence(x, y, this.influenceRadius[resource] / cellSize, strength / 2); + this.ccResourceMaps[resource].addInfluence(x, y, this.ccInfluenceRadius[resource] / cellSize, strength, "constant"); }; return m; Index: binaries/data/mods/public/simulation/ai/petra/config.js =================================================================== --- binaries/data/mods/public/simulation/ai/petra/config.js +++ binaries/data/mods/public/simulation/ai/petra/config.js @@ -159,6 +159,28 @@ }; this.garrisonHealthLevel = { "low": 0.4, "medium": 0.55, "high": 0.7 }; + + // The following values are used to make maps defined in TerrainAnalysis.js + // and are used for some building placement (cc, dropsites). + this.resources = { + // A lower value means more a abundant resource with smaller amount each. + // A higher value means a more sparse resource with larger amounts each. + "normalisationFactor": { + "metal": 90, + "stone": 90, + "wood": 50 + }, + "ccInfluenceRadius": { + "metal": 120, + "stone": 120, + "wood": 60 + }, + "influenceRadius": { + "metal": 48, + "stone": 48, + "wood": 36 + } + }; }; PETRA.Config.prototype.setConfig = function(gameState) Index: binaries/data/mods/public/simulation/ai/petra/headquarters.js =================================================================== --- binaries/data/mods/public/simulation/ai/petra/headquarters.js +++ binaries/data/mods/public/simulation/ai/petra/headquarters.js @@ -65,6 +65,8 @@ this.navalMap = false; this.navalRegions = {}; + gameState.sharedScript.createResourceMaps(this.Config.resources); + this.treasures = gameState.getEntities().filter(ent => ent.isTreasure()); this.treasures.registerUpdates(); this.currentPhase = gameState.currentPhase(); Index: binaries/data/mods/public/simulation/data/resources/food.json =================================================================== --- binaries/data/mods/public/simulation/data/resources/food.json +++ binaries/data/mods/public/simulation/data/resources/food.json @@ -10,6 +10,5 @@ "meat": "Meat" }, "properties": ["barterable", "tradable", "tributable"], - "truePrice": 100, - "aiAnalysisInfluenceGroup": "ignore" + "truePrice": 100 } Index: binaries/data/mods/public/simulation/data/resources/metal.json =================================================================== --- binaries/data/mods/public/simulation/data/resources/metal.json +++ binaries/data/mods/public/simulation/data/resources/metal.json @@ -8,6 +8,5 @@ "ruins": "Ruins" }, "properties": ["barterable", "tradable", "tributable"], - "truePrice": 100, - "aiAnalysisInfluenceGroup": "sparse" + "truePrice": 100 } Index: binaries/data/mods/public/simulation/data/resources/stone.json =================================================================== --- binaries/data/mods/public/simulation/data/resources/stone.json +++ binaries/data/mods/public/simulation/data/resources/stone.json @@ -8,6 +8,5 @@ "ruins": "Ruins" }, "properties": ["barterable", "tradable", "tributable"], - "truePrice": 100, - "aiAnalysisInfluenceGroup": "sparse" + "truePrice": 100 } Index: binaries/data/mods/public/simulation/data/resources/wood.json =================================================================== --- binaries/data/mods/public/simulation/data/resources/wood.json +++ binaries/data/mods/public/simulation/data/resources/wood.json @@ -8,6 +8,5 @@ "ruins": "Ruins" }, "properties": ["barterable", "tradable", "tributable"], - "truePrice": 100, - "aiAnalysisInfluenceGroup": "abundant" + "truePrice": 100 }