Refactored script RAM usage to be calculated based on commands. Updated RAM on foreign servers to balance. Balnaced company wages

This commit is contained in:
Daniel Xie 2017-05-10 16:10:06 -05:00
parent 3808fe5a3f
commit 416f3e7b47
7 changed files with 66 additions and 24 deletions

@ -223,16 +223,16 @@ CompanyPositions = {
//Constructor: CompanyPosition(name, reqHack, reqStr, reqDef, reqDex, reqAgi, reqCha, reqRep, salary) //Constructor: CompanyPosition(name, reqHack, reqStr, reqDef, reqDex, reqAgi, reqCha, reqRep, salary)
//Software //Software
SoftwareIntern: new CompanyPosition("Software Engineering Intern", 1, 0, 0, 0, 0, 0, 0, 2), SoftwareIntern: new CompanyPosition("Software Engineering Intern", 1, 0, 0, 0, 0, 0, 0, 8),
JuniorDev: new CompanyPosition("Junior Software Engineer", 51, 0, 0, 0, 0, 0, 8000, 10), JuniorDev: new CompanyPosition("Junior Software Engineer", 51, 0, 0, 0, 0, 0, 8000, 20),
SeniorDev: new CompanyPosition("Senior Software Engineer", 251, 0, 0, 0, 0, 51, 32000, 40), SeniorDev: new CompanyPosition("Senior Software Engineer", 251, 0, 0, 0, 0, 51, 32000, 40),
LeadDev: new CompanyPosition("Lead Software Developer", 401, 0, 0, 0, 0, 151, 144000, 120), LeadDev: new CompanyPosition("Lead Software Developer", 401, 0, 0, 0, 0, 151, 144000, 120),
//TODO Through darkweb, maybe? //TODO Through darkweb, maybe?
FreelanceDeveloper: new CompanyPosition("Freelance Developer", 0, 0, 0, 0, 0, 0, 0, 0), FreelanceDeveloper: new CompanyPosition("Freelance Developer", 0, 0, 0, 0, 0, 0, 0, 0),
SoftwareConsultant: new CompanyPosition("Software Consultant", 51, 0, 0, 0, 0, 0, 0, 8), SoftwareConsultant: new CompanyPosition("Software Consultant", 51, 0, 0, 0, 0, 0, 0, 16),
SeniorSoftwareConsultant: new CompanyPosition("Senior Software Consultant", 251, 0, 0, 0, 0, 51, 0, 32), SeniorSoftwareConsultant: new CompanyPosition("Senior Software Consultant", 251, 0, 0, 0, 0, 51, 0, 35),
//IT //IT
ITIntern: new CompanyPosition("IT Intern", 1, 0, 0, 0, 0, 0, 0, 1.75), ITIntern: new CompanyPosition("IT Intern", 1, 0, 0, 0, 0, 0, 0, 1.75),
@ -250,25 +250,25 @@ CompanyPositions = {
CTO: new CompanyPosition("Chief Technology Officer", 751, 0, 0, 0, 0, 501, 4608000, 750), CTO: new CompanyPosition("Chief Technology Officer", 751, 0, 0, 0, 0, 501, 4608000, 750),
//Business //Business
BusinessIntern: new CompanyPosition("Business Intern", 1, 0, 0, 0, 0, 1, 0, 2.5), BusinessIntern: new CompanyPosition("Business Intern", 1, 0, 0, 0, 0, 1, 0, 10),
BusinessAnalyst: new CompanyPosition("Business Analyst", 6, 0, 0, 0, 0, 51, 8000, 15), BusinessAnalyst: new CompanyPosition("Business Analyst", 6, 0, 0, 0, 0, 51, 8000, 25),
BusinessManager: new CompanyPosition("Business Manager", 51, 0, 0, 0, 0, 101, 32000, 60), BusinessManager: new CompanyPosition("Business Manager", 51, 0, 0, 0, 0, 101, 32000, 60),
OperationsManager: new CompanyPosition("Operations Manager", 51, 0, 0, 0, 0, 226, 144000, 180), OperationsManager: new CompanyPosition("Operations Manager", 51, 0, 0, 0, 0, 226, 144000, 180),
CFO: new CompanyPosition("Chief Financial Officer", 76, 0, 0, 0, 0, 501, 576000, 600), CFO: new CompanyPosition("Chief Financial Officer", 76, 0, 0, 0, 0, 501, 576000, 600),
CEO: new CompanyPosition("Chief Executive Officer", 101, 0, 0, 0, 0, 751, 4608000, 1000), CEO: new CompanyPosition("Chief Executive Officer", 101, 0, 0, 0, 0, 751, 4608000, 1000),
BusinessConsultant: new CompanyPosition("Business Consultant", 6, 0, 0, 0, 0, 51, 0, 12), BusinessConsultant: new CompanyPosition("Business Consultant", 6, 0, 0, 0, 0, 51, 0, 20),
SeniorBusinessConsultant: new CompanyPosition("Senior Business Consultant", 51, 0, 0, 0, 0, 226, 0, 150), SeniorBusinessConsultant: new CompanyPosition("Senior Business Consultant", 51, 0, 0, 0, 0, 226, 0, 150),
//Non-tech/management jobs //Non-tech/management jobs
PartTimeWaiter: new CompanyPosition("Part-time Waiter", 0, 0, 0, 0, 0, 0, 0, 1.5), PartTimeWaiter: new CompanyPosition("Part-time Waiter", 0, 0, 0, 0, 0, 0, 0, 7),
PartTimeEmployee: new CompanyPosition("Part-time Employee", 0, 0, 0, 0, 0, 0, 0, 1.5), PartTimeEmployee: new CompanyPosition("Part-time Employee", 0, 0, 0, 0, 0, 0, 0, 7),
Waiter: new CompanyPosition("Waiter", 0, 0, 0, 0, 0, 0, 0, 2), Waiter: new CompanyPosition("Waiter", 0, 0, 0, 0, 0, 0, 0, 9),
Employee: new CompanyPosition("Employee", 0, 0, 0, 0, 0, 0, 0, 2), Employee: new CompanyPosition("Employee", 0, 0, 0, 0, 0, 0, 0, 9),
PoliceOfficer: new CompanyPosition("Police Officer", 11, 101, 101, 101, 101, 51, 8000, 25), PoliceOfficer: new CompanyPosition("Police Officer", 11, 101, 101, 101, 101, 51, 8000, 25),
PoliceChief: new CompanyPosition("Police Chief", 101, 301, 301, 301, 301, 151, 32000, 100), PoliceChief: new CompanyPosition("Police Chief", 101, 301, 301, 301, 301, 151, 32000, 100),
SecurityGuard: new CompanyPosition("Security Guard", 0, 51, 51, 51, 51, 1, 0, 10), SecurityGuard: new CompanyPosition("Security Guard", 0, 51, 51, 51, 51, 1, 0, 16),
SecurityOfficer: new CompanyPosition("Security Officer", 26, 151, 151, 151, 151, 51, 8000, 40), SecurityOfficer: new CompanyPosition("Security Officer", 26, 151, 151, 151, 151, 51, 8000, 40),
SecuritySupervisor: new CompanyPosition("Security Supervisor", 26, 251, 251, 251, 251, 101, 32000, 80), SecuritySupervisor: new CompanyPosition("Security Supervisor", 26, 251, 251, 251, 251, 101, 32000, 80),
HeadOfSecurity: new CompanyPosition("Head of Security", 51, 501, 501, 501, 501, 151, 144000, 250), HeadOfSecurity: new CompanyPosition("Head of Security", 51, 501, 501, 501, 501, 151, 144000, 250),

@ -28,10 +28,18 @@ CONSTANTS = {
//NeuroFlux Governor cost multiplier as you level up //NeuroFlux Governor cost multiplier as you level up
NeuroFluxGovernorLevelMult: 1.09, NeuroFluxGovernorLevelMult: 1.09,
/* Script related things */ /* Script related things */
//Time (ms) it takes to run one operation in Netscript. //Time (ms) it takes to run one operation in Netscript.
CodeInstructionRunTime: 1500, CodeInstructionRunTime: 1500,
//RAM Costs for differenc commands
ScriptWhileRamCost: 0.4,
ScriptForRamCost: 0.4,
ScriptIfRamCost: 0.1,
ScriptHackRamCost: 0.25,
ScriptGrowRamCost: 0.25,
//Server growth rate //Server growth rate
ServerGrowthRate: 1.00075, ServerGrowthRate: 1.00075,

@ -173,7 +173,7 @@ function PlayerObject() {
PlayerObject.prototype.init = function() { PlayerObject.prototype.init = function() {
/* Initialize Player's home computer */ /* Initialize Player's home computer */
var t_homeComp = new Server(); var t_homeComp = new Server();
t_homeComp.init(createRandomIp(), "home", "Home PC", true, true, true, true, 1); t_homeComp.init(createRandomIp(), "home", "Home PC", true, true, true, true, 2);
this.homeComputer = t_homeComp.ip; this.homeComputer = t_homeComp.ip;
this.currentServer = t_homeComp.ip; this.currentServer = t_homeComp.ip;
AddToAllServers(t_homeComp); AddToAllServers(t_homeComp);

@ -158,7 +158,23 @@ Script.prototype.updateNumInstructions = function() {
//Updates how much RAM the script uses when it is running. //Updates how much RAM the script uses when it is running.
Script.prototype.updateRamUsage = function() { Script.prototype.updateRamUsage = function() {
this.ramUsage = this.numInstructions * 0.5; var baseRam = 1; //Each script requires 1GB to run regardless
var codeCopy = this.code.repeat(1);
codeCopy = codeCopy.replace(/\s/g,''); //Remove all whitespace
var whileCount = numOccurrences(codeCopy, "while(");
var forCount = numOccurrences(codeCopy, "for(");
var ifCount = numOccurrences(codeCopy, "if(");
var hackCount = numOccurrences(codeCopy, "hack(");
var growCount = numOccurrences(codeCopy, "grow(");
this.ramUsage = baseRam +
((whileCount * CONSTANTS.ScriptWhileRamCost) +
(forCount * CONSTANTS.ScriptForRamCost) +
(ifCount * CONSTANTS.ScriptIfRamCost) +
(hackCount * CONSTANTS.ScriptHackRamCost) +
(growCount * CONSTANTS.ScriptGrowRamCost));
console.log("ram usage: " + this.ramUsage);
} }
Script.prototype.log = function(txt) { Script.prototype.log = function(txt) {

@ -402,19 +402,19 @@ initForeignServers = function() {
//"Low level" targets //"Low level" targets
var FoodNStuffServer = new Server(); var FoodNStuffServer = new Server();
FoodNStuffServer.init(createRandomIp(), "foodnstuff", "Food N Stuff Supermarket", true, false, false, false, 2); FoodNStuffServer.init(createRandomIp(), "foodnstuff", "Food N Stuff Supermarket", true, false, false, false, 4);
FoodNStuffServer.setHackingParameters(1, 500000, 10, 5); FoodNStuffServer.setHackingParameters(1, 500000, 10, 5);
FoodNStuffServer.setPortProperties(0); FoodNStuffServer.setPortProperties(0);
AddToAllServers(FoodNStuffServer); AddToAllServers(FoodNStuffServer);
var SigmaCosmeticsServer = new Server(); var SigmaCosmeticsServer = new Server();
SigmaCosmeticsServer.init(createRandomIp(), "sigma-cosmetics", "Sigma Cosmetics", true, false, false, false, 0); SigmaCosmeticsServer.init(createRandomIp(), "sigma-cosmetics", "Sigma Cosmetics", true, false, false, false, 4);
SigmaCosmeticsServer.setHackingParameters(5, 750000, 10, 10); SigmaCosmeticsServer.setHackingParameters(5, 750000, 10, 10);
SigmaCosmeticsServer.setPortProperties(0); SigmaCosmeticsServer.setPortProperties(0);
AddToAllServers(SigmaCosmeticsServer); AddToAllServers(SigmaCosmeticsServer);
var JoesGunsServer = new Server(); var JoesGunsServer = new Server();
JoesGunsServer.init(createRandomIp(), "joesguns", "Joe's Guns", true, false, false, false, 2); JoesGunsServer.init(createRandomIp(), "joesguns", "Joe's Guns", true, false, false, false, 4);
JoesGunsServer.setHackingParameters(10, 1000000, 20, 20); JoesGunsServer.setHackingParameters(10, 1000000, 20, 20);
JoesGunsServer.setPortProperties(0); JoesGunsServer.setPortProperties(0);
AddToAllServers(JoesGunsServer); AddToAllServers(JoesGunsServer);
@ -426,7 +426,7 @@ initForeignServers = function() {
AddToAllServers(Zer0NightclubServer); AddToAllServers(Zer0NightclubServer);
var NectarNightclubServer = new Server(); var NectarNightclubServer = new Server();
NectarNightclubServer.init(createRandomIp(), "nectar-net", "Nectar Nightclub Network", true, false, false, false, 2); NectarNightclubServer.init(createRandomIp(), "nectar-net", "Nectar Nightclub Network", true, false, false, false, 4);
NectarNightclubServer.setHackingParameters(20, 1200000, 20, 25); NectarNightclubServer.setHackingParameters(20, 1200000, 20, 25);
NectarNightclubServer.setPortProperties(0); NectarNightclubServer.setPortProperties(0);
AddToAllServers(NectarNightclubServer); AddToAllServers(NectarNightclubServer);
@ -444,19 +444,19 @@ initForeignServers = function() {
AddToAllServers(SilverHelixServer); AddToAllServers(SilverHelixServer);
var HongFangTeaHouseServer = new Server(); var HongFangTeaHouseServer = new Server();
HongFangTeaHouseServer.init(createRandomIp(), "hong-fang-tea", "HongFang Teahouse", true, false, false, false, 0); HongFangTeaHouseServer.init(createRandomIp(), "hong-fang-tea", "HongFang Teahouse", true, false, false, false, 4);
HongFangTeaHouseServer.setHackingParameters(30, 1500000, 15, 15); HongFangTeaHouseServer.setHackingParameters(30, 1500000, 15, 15);
HongFangTeaHouseServer.setPortProperties(0); HongFangTeaHouseServer.setPortProperties(0);
AddToAllServers(HongFangTeaHouseServer); AddToAllServers(HongFangTeaHouseServer);
var HaraKiriSushiBarServer = new Server(); var HaraKiriSushiBarServer = new Server();
HaraKiriSushiBarServer.setHackingParameters(40, 2000000, 15, 40); HaraKiriSushiBarServer.setHackingParameters(40, 2000000, 15, 40);
HaraKiriSushiBarServer.init(createRandomIp(), "harakiri-sushi", "HaraKiri Sushi Bar Network", true, false, false, false, 0); HaraKiriSushiBarServer.init(createRandomIp(), "harakiri-sushi", "HaraKiri Sushi Bar Network", true, false, false, false, 4);
HaraKiriSushiBarServer.setPortProperties(1); HaraKiriSushiBarServer.setPortProperties(1);
AddToAllServers(HaraKiriSushiBarServer); AddToAllServers(HaraKiriSushiBarServer);
var PhantasyServer = new Server(); var PhantasyServer = new Server();
PhantasyServer.init(createRandomIp(), "phantasy", "Phantasy Club", true, false, false, false, 4); PhantasyServer.init(createRandomIp(), "phantasy", "Phantasy Club", true, false, false, false, 0);
PhantasyServer.setHackingParameters(100, 25000000, 20, 35); PhantasyServer.setHackingParameters(100, 25000000, 20, 35);
PhantasyServer.setPortProperties(2); PhantasyServer.setPortProperties(2);
AddToAllServers(PhantasyServer); AddToAllServers(PhantasyServer);

@ -794,9 +794,9 @@ var Terminal = {
if (commandArray.length != 1) { if (commandArray.length != 1) {
post("Incorrect usage of free command. Usage: free"); return; post("Incorrect usage of free command. Usage: free"); return;
} }
post("Total: " + Player.getCurrentServer().maxRam.toString() + " GB"); post("Total: " + formatNumber(Player.getCurrentServer().maxRam, 2) + " GB");
post("Used: " + Player.getCurrentServer().ramUsed.toString() + " GB"); post("Used: " + formatNumber(Player.getCurrentServer().ramUsed, 2) + " GB");
post("Available: " + (Player.getCurrentServer().maxRam - Player.getCurrentServer().ramUsed).toString() + " GB"); post("Available: " + formatNumber(Player.getCurrentServer().maxRam - Player.getCurrentServer().ramUsed, 2) + " GB");
}, },
//First called when the "run [program]" command is called. Checks to see if you //First called when the "run [program]" command is called. Checks to see if you

@ -72,3 +72,21 @@ function formatNumber(num, numFractionDigits) {
maximumFractionDigits: numFractionDigits maximumFractionDigits: numFractionDigits
}); });
} }
//Counters the number of times a substring occurs in a string
function numOccurrences(string, subString) {
string += "";
subString += "";
if (subString.length <= 0) return (string.length + 1);
var n = 0, pos = 0, step = subString.length;
while (true) {
pos = string.indexOf(subString, pos);
if (pos >= 0) {
++n;
pos += step;
} else break;
}
return n;
}