From 60cc6e15d5b581d98df110fdab927f4ce07673eb Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Sun, 6 May 2018 03:27:16 -0400 Subject: [PATCH 1/3] added getScriptName --- doc/source/netscriptfunctions.rst | 6 ++++++ src/NetscriptFunctions.js | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/doc/source/netscriptfunctions.rst b/doc/source/netscriptfunctions.rst index 3b0dd2a13..7402830d9 100644 --- a/doc/source/netscriptfunctions.rst +++ b/doc/source/netscriptfunctions.rst @@ -779,6 +779,12 @@ scriptKill Kills all scripts with the specified filename on the target server specified by *hostname/ip*, regardless of arguments. Returns true if one or more scripts were successfully killed, and false if none were. +getScriptName +^^^^^^^^^^^^^ + +.. js:function:: getScriptName() + Returns the current script name + getScriptRam ^^^^^^^^^^^^ diff --git a/src/NetscriptFunctions.js b/src/NetscriptFunctions.js index 799ca02df..d833a99e9 100644 --- a/src/NetscriptFunctions.js +++ b/src/NetscriptFunctions.js @@ -1994,6 +1994,10 @@ function NetscriptFunctions(workerScript) { } return suc; }, + getScriptName : function() { + if (workerScript.checkingRam) {return 0;} + return workerScript.name; + }, getScriptRam : function (scriptname, ip) { if (workerScript.checkingRam) { if (workerScript.loadedFns.getScriptRam) { From 579a0aec55ba6da408c74be6ce523b60626b3f9a Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Sun, 6 May 2018 03:49:11 -0400 Subject: [PATCH 2/3] make script base cost a constant --- src/Constants.js | 1 + src/Script.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Constants.js b/src/Constants.js index 8c6aebfc0..6212c726f 100644 --- a/src/Constants.js +++ b/src/Constants.js @@ -40,6 +40,7 @@ let CONSTANTS = { /* Netscript Constants */ //RAM Costs for different commands + ScriptBaseRamCost: 1.4, ScriptWhileRamCost: 0.2, ScriptForRamCost: 0.2, ScriptIfRamCost: 0.15, diff --git a/src/Script.js b/src/Script.js index 5ccb5c05e..d4ca64dbb 100644 --- a/src/Script.js +++ b/src/Script.js @@ -417,7 +417,7 @@ function parseOnlyRamCalculate(server, code, workerScript) { // Finally, walk the reference map and generate a ram cost. The initial set of keys to scan // are those that start with __SPECIAL_INITIAL_MODULE__. - let ram = 1.4; + let ram = CONSTANTS.ScriptBaseRamCost; const unresolvedRefs = Object.keys(dependencyMap).filter(s => s.startsWith(initialModule)); const resolvedRefs = new Set(); while (unresolvedRefs.length > 0) { From e7b6150062ee74b6e31b8596fe61dffd53ff99ab Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Sun, 6 May 2018 03:53:34 -0400 Subject: [PATCH 3/3] added some documentation for hacknetnode api --- doc/source/netscripthacknetnodeapi.rst | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/doc/source/netscripthacknetnodeapi.rst b/doc/source/netscripthacknetnodeapi.rst index 73c0860c1..74b4c93f0 100644 --- a/doc/source/netscripthacknetnodeapi.rst +++ b/doc/source/netscripthacknetnodeapi.rst @@ -17,6 +17,22 @@ hacknetnodes accessed using *hacknetnodes[0]*. The fourth Hacknet Node you purchase will have the name "hacknet-node-3" and can be accessed using *hacknetnodes[3]*. +Purchasing Hacknet Nodes +^^^^^^^^^^^^^^^^^^^^^^^^ + +The following is a list of supported functions for purchasing Hacknet Nodes. + +.. js:function:: getNextHacknetNodeCost() + + Returns the cost of purchasing a new Hacknet Node + +.. js:function:: purchaseHacknetNode() + + Purchases a new Hacknet Node. Returns a number with the index of the Hacknet Node. This index is equivalent to the number at the + end of the Hacknet Node's name (e.g The Hacknet Node named 'hacknet-node-4' will have an index of 4). If the player cannot afford + to purchase a new Hacknet Node then the function will return false. + + Hacknet Node Member Variables ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,6 +41,11 @@ a value to these. Note that these must be called on an element inside the *hacknetnodes* array, not the array itself. +.. js:attribute:: hacknetnodes[i].name + + Returns the name of the corresponding Hacknet Node + + .. js:attribute:: hacknetnodes[i].level Returns the level of the corresponding Hacknet Node