**Motivations:** - Ensure lint config is not degraded and fix all lint errors for pousse workflow. **Root causes:** - Unused variables kept with _ prefix instead of removed (_row, _questReward, _i). - getAnimalBlockOrigin had 5 parameters (max 4). - use of continue statement (no-continue rule). **Correctifs:** - ESLint config verified; no eslint-disable in codebase. - Removed unused variable _row (biome-rules); removed dead function _questReward (quests); removed unused map param _i (state.js). - getAnimalBlockOrigin refactored to 4 params (pos object instead of x, y). - Replaced continue with if (cell) block in normalizeLoadedCells (state.js). - JSDoc param names aligned with _height, _y (biome-rules). **Evolutions:** - (none) **Pages affectées:** - web/js/biome-rules.js - web/js/quests.js - web/js/state.js - web/js/placement.js
37 lines
1.3 KiB
JavaScript
37 lines
1.3 KiB
JavaScript
import { LootTables } from "./loot-tables.js";
|
|
import { isOriginCell } from "./grid-utils.js";
|
|
import { getTotalAnimalValue } from "./income-value.js";
|
|
import { getOriginAnimalCount } from "./food.js";
|
|
|
|
/**
|
|
* Attractivity from value, species count, rarity and fill rate (before penalties).
|
|
* @param {import("./types.js").GameState} state
|
|
* @returns {{ valueNorm: number, speciesNorm: number, rarityNorm: number, fillNorm: number }}
|
|
*/
|
|
export function getAttractivityBase(state) {
|
|
const value = getTotalAnimalValue(state);
|
|
const originCount = getOriginAnimalCount(state);
|
|
const grid = state.grid;
|
|
const cellCount = grid.width * grid.height;
|
|
const fillRate = cellCount > 0 ? originCount / cellCount : 0;
|
|
const speciesSet = new Set();
|
|
let raritySum = 0;
|
|
for (const [key, cell] of Object.entries(state.grid.cells)) {
|
|
if (cell === null || cell === undefined || cell.kind !== "animal" || !isOriginCell(key, cell)) {
|
|
// skip
|
|
} else {
|
|
speciesSet.add(cell.id);
|
|
const def = LootTables.Animals[cell.id];
|
|
if (def) raritySum += def.rarityLevel ?? 1;
|
|
}
|
|
}
|
|
const speciesCount = speciesSet.size;
|
|
const avgRarity = originCount > 0 ? raritySum / originCount : 0;
|
|
return {
|
|
valueNorm: value * 0.001,
|
|
speciesNorm: speciesCount * 2,
|
|
rarityNorm: avgRarity * 0.5,
|
|
fillNorm: fillRate * 10,
|
|
};
|
|
}
|