Merge pull request #1405 from danielyxie/dev

Fix growth miscalc
This commit is contained in:
hydroflame 2021-10-01 23:03:58 -04:00 committed by GitHub
commit 8e5abe4878
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 6 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -1083,7 +1083,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
throw makeRuntimeErrorMsg("growthAnalyze", `Invalid argument: growth must be numeric and >= 1, is ${growth}.`); throw makeRuntimeErrorMsg("growthAnalyze", `Invalid argument: growth must be numeric and >= 1, is ${growth}.`);
} }
return numCycleForGrowth(server, Number(growth), Player); return numCycleForGrowth(server, Number(growth), Player, server.cpuCores);
}, },
weaken: function (ip: any, { threads: requestedThreads }: any = {}): any { weaken: function (ip: any, { threads: requestedThreads }: any = {}): any {
updateDynamicRam("weaken", getRamCost("weaken")); updateDynamicRam("weaken", getRamCost("weaken"));

@ -45,7 +45,7 @@ export function safetlyCreateUniqueServer(params: IConstructorParams): Server {
* @param p - Reference to Player object * @param p - Reference to Player object
* @returns Number of "growth cycles" needed * @returns Number of "growth cycles" needed
*/ */
export function numCycleForGrowth(server: Server, growth: number, p: IPlayer): number { export function numCycleForGrowth(server: Server, growth: number, p: IPlayer, cores = 1): number {
let ajdGrowthRate = 1 + (CONSTANTS.ServerBaseGrowthRate - 1) / server.hackDifficulty; let ajdGrowthRate = 1 + (CONSTANTS.ServerBaseGrowthRate - 1) / server.hackDifficulty;
if (ajdGrowthRate > CONSTANTS.ServerMaxGrowthRate) { if (ajdGrowthRate > CONSTANTS.ServerMaxGrowthRate) {
ajdGrowthRate = CONSTANTS.ServerMaxGrowthRate; ajdGrowthRate = CONSTANTS.ServerMaxGrowthRate;
@ -53,9 +53,14 @@ export function numCycleForGrowth(server: Server, growth: number, p: IPlayer): n
const serverGrowthPercentage = server.serverGrowth / 100; const serverGrowthPercentage = server.serverGrowth / 100;
const coreBonus = 1 + (cores - 1) / 16;
const cycles = const cycles =
Math.log(growth) / Math.log(growth) /
(Math.log(ajdGrowthRate) * p.hacking_grow_mult * serverGrowthPercentage * BitNodeMultipliers.ServerGrowthRate); (Math.log(ajdGrowthRate) *
p.hacking_grow_mult *
serverGrowthPercentage *
BitNodeMultipliers.ServerGrowthRate *
coreBonus);
return cycles; return cycles;
} }
@ -84,7 +89,7 @@ export function processSingleServerGrowth(server: Server, threads: number, p: IP
// if there was any growth at all, increase security // if there was any growth at all, increase security
if (oldMoneyAvailable !== server.moneyAvailable) { if (oldMoneyAvailable !== server.moneyAvailable) {
//Growing increases server security twice as much as hacking //Growing increases server security twice as much as hacking
let usedCycles = numCycleForGrowth(server, server.moneyAvailable / oldMoneyAvailable, p); let usedCycles = numCycleForGrowth(server, server.moneyAvailable / oldMoneyAvailable, p, cores);
usedCycles = Math.max(0, usedCycles); usedCycles = Math.max(0, usedCycles);
server.fortify(2 * CONSTANTS.ServerFortifyAmount * Math.ceil(usedCycles)); server.fortify(2 * CONSTANTS.ServerFortifyAmount * Math.ceil(usedCycles));
} }