feat: add compute budget supply/demand system (#4)
This commit is contained in:
46
js/engine.js
46
js/engine.js
@@ -102,6 +102,32 @@ function updateRates() {
|
||||
G.codeRate += G.swarmRate;
|
||||
}
|
||||
|
||||
// Compute Budget: supply vs demand
|
||||
if (CONFIG.COMPUTE_BUDGET_ENABLED) {
|
||||
let supply = 0;
|
||||
let demand = 0;
|
||||
for (const def of BDEF) {
|
||||
const count = G.buildings[def.id] || 0;
|
||||
if (count > 0) {
|
||||
if (def.computeSupply) supply += def.computeSupply * count;
|
||||
if (def.computeDemand) demand += def.computeDemand * count;
|
||||
}
|
||||
}
|
||||
G.computeSupply = supply;
|
||||
G.computeDemand = demand;
|
||||
// powMod affects all rates when under-supplied
|
||||
if (G.computePowMod < 1) {
|
||||
G.codeRate *= G.computePowMod;
|
||||
G.computeRate *= G.computePowMod;
|
||||
G.knowledgeRate *= G.computePowMod;
|
||||
G.userRate *= G.computePowMod;
|
||||
G.impactRate *= G.computePowMod;
|
||||
G.rescuesRate *= G.computePowMod;
|
||||
G.opsRate *= G.computePowMod;
|
||||
G.creativityRate *= G.computePowMod;
|
||||
}
|
||||
}
|
||||
|
||||
// Apply persistent debuffs from active events
|
||||
if (G.activeDebuffs && G.activeDebuffs.length > 0) {
|
||||
for (const debuff of G.activeDebuffs) {
|
||||
@@ -133,6 +159,26 @@ function tick() {
|
||||
G.harmony += G.harmonyRate * dt;
|
||||
G.harmony = Math.max(0, Math.min(100, G.harmony));
|
||||
|
||||
// Compute Budget: supply vs demand dynamics
|
||||
if (CONFIG.COMPUTE_BUDGET_ENABLED && G.computeDemand > 0) {
|
||||
const delta = G.computeSupply - G.computeDemand;
|
||||
if (delta > 0) {
|
||||
// Over-supply: charge battery, gain momentum
|
||||
G.computeBattery = Math.min(CONFIG.COMPUTE_BATTERY_MAX, G.computeBattery + delta * dt);
|
||||
G.computeMomentum += CONFIG.COMPUTE_MOMENTUM_RATE * dt;
|
||||
G.computePowMod = 1 + G.computeMomentum;
|
||||
} else {
|
||||
// Under-supply: drain battery first
|
||||
if (G.computeBattery > 0) {
|
||||
G.computeBattery = Math.max(0, G.computeBattery + delta * dt);
|
||||
} else {
|
||||
// Battery empty: apply penalty
|
||||
G.computePowMod = Math.max(0.01, G.computeSupply / G.computeDemand);
|
||||
G.computeMomentum = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Track totals
|
||||
G.totalCode += G.codeRate * dt;
|
||||
G.totalCompute += G.computeRate * dt;
|
||||
|
||||
Reference in New Issue
Block a user