Skip to content

Commit

Permalink
RnD Miner (#2541)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lexanx authored Jul 26, 2024
1 parent 040660b commit 115818d
Show file tree
Hide file tree
Showing 12 changed files with 308 additions and 3 deletions.
2 changes: 1 addition & 1 deletion code/modules/modular_computers/hardware/hard_drive.dm
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,4 @@
return null

return sanitizeSafe(D.stored_data, max_length = MAX_LNAME_LEN)
//SIERRA-ADD] - MODPACK_RND
//[SIERRA-ADD] - MODPACK_RND
16 changes: 16 additions & 0 deletions code/modules/research/rdconsole.dm
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,14 @@ won't update every console in existence) but it's more of a hassle to do. Also,
if(disk)
var/datum/computer_file/binary/design/file = locate(href_list["download_disk_design"]) in disk.stored_files
files.AddDesign2Known(file.design)

if(href_list["download_disk_science"]) // User is attempting to download (disk->rdconsole) a science from the disk.
if(disk)
var/datum/computer_file/binary/sci/file = locate(href_list["download_disk_science"]) in disk.stored_files
var/savedpionts = files.AddSciPoints(file)
files.research_points += savedpionts
to_chat(usr, "<span class='notice'>[savedpionts] new science points downloaded from the [file.filename].</span>")

if(href_list["upload_disk_design"]) // User is attempting to upload (rdconsole->disk) a design to the disk.
if(disk)
var/datum/design/D = locate(href_list["upload_disk_design"]) in files.known_designs
Expand Down Expand Up @@ -620,6 +628,14 @@ won't update every console in existence) but it's more of a hassle to do. Also,
var/datum/design/D = i
known_designs += list(list("name" = D.shortname, "id" = "\ref[D]"))
data["known_designs"] = known_designs

var/list/disk_science = list()
var/list/disk_sciecne_files = disk.find_files_by_type(/datum/computer_file/binary/sci)
for(var/f in disk_sciecne_files)
var/datum/computer_file/binary/sci/s_file = f
disk_science += list(list("name" = s_file.filename, "id" = "\ref[s_file]"))
data["disk_science"] = disk_science

// All the info needed for displaying tech trees
if(screen == "tech_trees")
var/list/line_list = list()
Expand Down
1 change: 1 addition & 0 deletions code/modules/research/research.dm
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@ The tech datums are the actual "tech trees" that you improve through researching

var/datum/experiment_data/experiments
var/research_points = 0
var/list/uniquekeys = list()
//[/SIERRA-EDIT] - MODPACK_RND
1 change: 1 addition & 0 deletions mods/RnD/_RnD.dme
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "code/tech_robotics.dm"
#include "code/binary.dm"
#include "code/design.dm"
#include "code/sciefolder.dm"


#endif
14 changes: 14 additions & 0 deletions mods/RnD/code/design.dm
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,17 @@
var/list/data = design.ui_data()
data["filename"] = filename
return data

/datum/computer_file/binary/sci
filetype = "SF" // Science Folded
size = 1
var/uniquekey

/datum/computer_file/binary/sci/proc/set_filename(new_name)
filename = sanitizeFileName("folded_science [new_name]")


/datum/computer_file/binary/sci/clone()
var/datum/computer_file/binary/sci/F = ..()
F.uniquekey = uniquekey
return F
8 changes: 8 additions & 0 deletions mods/RnD/code/research.dm
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ var/global/list/explosion_watcher_list = list()
T.shown = TRUE
return


/datum/research/proc/AddSciPoints(datum/computer_file/binary/sci/D)
if(D.uniquekey in uniquekeys)
return 0
uniquekeys += D.uniquekey
return (rand(500, 1000) * D.size)


/datum/tech //Datum of individual technologies.
var/name = "name" //Name of the technology.
var/shortname = "name"
Expand Down
209 changes: 209 additions & 0 deletions mods/RnD/code/sciefolder.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
#define MINIMUM_SCIENCE_INTERVAL 120
#define MAXIMUM_SCIENCE_INTERVAL 180
#define MINIMUM_FOLDING_EVENT_INTERVAL 90
#define MAXIMUM_FOLDING_EVENT_INTERVAL 150
#define PROGRAM_STATUS_CRASHED 0
#define PROGRAM_STATUS_RUNNING 1
#define PROGRAM_STATUS_RUNNING_WARM 2
#define PROGRAM_STATUS_RUNNING_SCALDING 3

/datum/computer_file/program/folding
filename = "fldng"
filedesc = "FOLDING@SCIENCE"
extended_desc = "This program uses processor cycles for science"
program_icon_state = "generic"
program_key_state = "generic_key"
size = 6
available_on_ntnet = TRUE
usage_flags = PROGRAM_ALL
nanomodule_path = /datum/nano_module/program/folding
category = PROG_UTIL
requires_ntnet = TRUE
required_access = access_research

var/started_on = 0 // When the program started some science.
var/current_interval = 1 // How long the current interval will be.
var/next_event = 0 // in world timeofday, when the next event is scheduled to pop.
var/program_status = PROGRAM_STATUS_RUNNING // Program periodically needs a restart, increases crash chance slightly over time.
var/crashed_at = 0 // When the program crashed.
var/message = ""
var/saved_file_num = 0
var/percentage
var/GQ = 1

/datum/proc/get_recursive(mob/living/user)
SHOULD_CALL_PARENT(FALSE)
return user

/datum/computer_file/program/folding/Topic(href, href_list)
. = ..()
if(.)
return
. = TOPIC_REFRESH

if(href_list["fix_crash"] && program_status == PROGRAM_STATUS_CRASHED)
started_on += world.timeofday - crashed_at
program_status = PROGRAM_STATUS_RUNNING

if(href_list["start"] && started_on == 0)

started_on = world.timeofday
current_interval = ((rand(MINIMUM_SCIENCE_INTERVAL, MAXIMUM_SCIENCE_INTERVAL) * GQ) / get_speed()) SECONDS
next_event = ((rand(MINIMUM_FOLDING_EVENT_INTERVAL, MAXIMUM_FOLDING_EVENT_INTERVAL) * get_speed()) SECONDS) + world.timeofday

if(href_list["save"] && started_on > 0 && program_status != PROGRAM_STATUS_CRASHED)
if(started_on + current_interval > world.timeofday)
return TOPIC_HANDLED
var/obj/item/stock_parts/computer/hard_drive/HDD = computer.get_component(PART_HDD)
var/datum/computer_file/binary/sci/file = new
file.uniquekey = (rand(0,999) + rand(0,999) + rand(0,999) + rand(0,999))
file.size = GQ
file.set_filename(++saved_file_num)
HDD.create_file(file)

started_on = 0
current_interval = 1

if(href_list["gq"] && started_on == 0)
var/a = input("Please input preferable GQ size for computing. Between 1 and 16") as num
if(!a)
GQ = 1
if(a > 16)
GQ = 16
return
if(a < 1)
GQ = 1
return
else
GQ = a


/datum/computer_file/program/folding/process_tick() //Every 50-100 seconds, gives you a 1/3 chance of the program crashing.
. = ..()
if(!started_on)
return
var/obj/item/stock_parts/computer/processor_unit/CPU = computer.get_component(PART_CPU)
var/obj/item/stock_parts/computer/network_card/NTCARD = computer.get_component(PART_NETWORK)
var/obj/item/stock_parts/computer/hard_drive/HDD = computer.get_component(PART_HDD)
if(!istype(CPU) || !CPU.check_functionality() || !istype(HDD) || !HDD.check_functionality())
message = "A fatal hardware error has been detected."
return
if(!istype(NTCARD))
message = "Network card not connected to the device. Operation aborted."
return

if(world.timeofday < next_event) //Checks if it's time for the next crash chance.
return

var/host = computer.get_physical_host()

var/mob/living/h = holder.loc.loc

if(program_status > PROGRAM_STATUS_CRASHED)
if(PROGRAM_STATUS_RUNNING_SCALDING >= program_status)
switch(rand(PROGRAM_STATUS_RUNNING,program_status))
if(PROGRAM_STATUS_RUNNING) //Guaranteed 1 tick without crashing.
to_chat(h, SPAN_WARNING("\The [host] starts to get very warm."))
if (program_status == PROGRAM_STATUS_RUNNING)
program_status = PROGRAM_STATUS_RUNNING_WARM
if(PROGRAM_STATUS_RUNNING_WARM) //50% chance on subsequent ticks to make the program able to crash.
to_chat(h, SPAN_WARNING("\The [host] gets scaldingly hot"))
if(h.type in typesof(/mob/living/carbon/human))
h.take_overall_damage(0, 0.45) //It checks holder? so that it doesn't cause a runtime error if no one is holding it.
if (program_status == PROGRAM_STATUS_RUNNING_WARM)
program_status = PROGRAM_STATUS_RUNNING_SCALDING
if(PROGRAM_STATUS_RUNNING_SCALDING) //1/3 chance on all following ticks for the program to crash.
to_chat(h, SPAN_WARNING("\The [host] pings an error chime."))
program_status = PROGRAM_STATUS_CRASHED
crashed_at = world.timeofday
else
program_status = PROGRAM_STATUS_CRASHED
crashed_at = world.timeofday
next_event = (rand(MINIMUM_FOLDING_EVENT_INTERVAL, MAXIMUM_FOLDING_EVENT_INTERVAL) SECONDS) + world.timeofday //Sets the next crash chance 50-100 seconds from now


/datum/computer_file/program/folding/on_shutdown()
started_on = 0
current_interval = 0
program_status = PROGRAM_STATUS_RUNNING
. = ..()

/datum/nano_module/program/folding
name = "FOLDING@SCIENCE"
var/static/list/science_strings = list(
"Extruding Mesh Terrain",
"Virtualizing Microprocessor",
"Reticulating Splines",
"Inserting Chaos Generator",
"Reversing Polarity",
"Unfolding Proteins",
"Simulating Alien Abductions",
"Scanning Pigeons",
"Iterating Chaos Array",
"Abstracting Supermatter",
"Adjusting Social Network",
"Quantizing Gravity Wells",
"Embedding Quantum Flux",
"Decompressing Hypercubes",
"Regenerating Fractal Forests",
"Optimizing Meta-Paths",
"Coding Celestial Bodies",
"Surfing Wave Functions",
"Folding Orbital Trajectories",
"Reconfiguring Crystal Lattices",
"Iterating Temporal Loops",
"Projecting Sonic Landscapes",
"Transcribing Quantum Entanglements",
"Polarizing Helical Structures",
"Calibrating Orbital Resonance",
"Encoding Fractal Algorithms",
"Inverting Quantum Flux Capacitors",
"Decoding Sonic Blueprints",
"Disentangling Quantum Foils",
"Tessellating Crystalline Arrays",
"Stabilizing Wormhole Dynamics",
"Quantizing Psycho-Social Fields",
"Rerouting Neural Pathways",
)

/datum/computer_file/program/folding/proc/get_speed()
var/skill_speed_modifier = 1 + (operator_skill - SKILL_TRAINED)/(SKILL_MAX - SKILL_MIN)
var/obj/item/stock_parts/computer/processor_unit/CPU = computer.get_component(PART_CPU)
return CPU.processing_power * skill_speed_modifier

/datum/nano_module/program/folding/ui_interact(mob/user, ui_key = "main", datum/nanoui/ui = null, force_open = 1)
var/list/data = host.initial_data()
var/datum/computer_file/program/folding/PRG = program
PRG.operator_skill = user.get_skill_value(SKILL_COMPUTER)
if(!PRG.computer)
return

if(PRG.message)
data["message"] = PRG.message
data["computing"] = !!PRG.started_on
data["time_remaining"] = ((PRG.started_on + PRG.current_interval) - world.timeofday) / 10
data["completed"] = PRG.started_on + PRG.current_interval <= world.timeofday
data["crashed"] = (PRG.program_status <= PROGRAM_STATUS_CRASHED)
data["gq"] = PRG.GQ
data["paspmin"] = (500 * PRG.GQ)
data["paspmax"] = (1000 * PRG.GQ)
var/time_left = ((PRG.started_on + PRG.current_interval) - world.timeofday)
if(time_left > 1)
data["science_string"] = pick(science_strings)
if(PRG.current_interval > 0)
PRG.percentage = ((PRG.current_interval-time_left) / PRG.current_interval) * 100
var/list/strings[0]
for(var/j, j<10, j++)
var/string = ""
for(var/i, i<20, i++)
string = "[string][prob(PRG.percentage)]"
strings.Add(string)
data["dos_strings"] = strings

ui = SSnano.try_update_ui(user, src, ui_key, ui, data, force_open)
if (!ui)
ui = new(user, src, ui_key, "mods-sciencefolding.tmpl", name, 550, 400)
ui.auto_update_layout = 1
ui.set_initial_data(data)
ui.set_auto_update(1)
ui.open()
Binary file added nano/images/uiBackground-NTsci.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 10 additions & 1 deletion nano/js/nano_base_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ NanoBaseHelpers = function () {
$('#uiTitleFluff').css("background-repeat", "no-repeat")
return ''
},

ntscieMode: function () {
$('body').css("background-color","#502a42")
$('body').css("background-image","url('uiBackground-NTsci.png')")
$('body').css("background-position","50% 0")
$('body').css("background-repeat","repeat-x")
$('#uiTitleFluff').css("background-image","url('uiTitleFluff.png')")
$('#uiTitleFluff').css("background-position","50% 50%")
$('#uiTitleFluff').css("background-repeat", "no-repeat")
return ''
},
link: function (text, icon, parameters, status, elementClass, elementId) {
var iconHtml = ''
var iconClass = 'noIcon'
Expand Down
2 changes: 1 addition & 1 deletion nano/templates/access_decrypter.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
</div>
{{/for}}
</div>
{{/if}}
{{/if}}
37 changes: 37 additions & 0 deletions nano/templates/mods/sciencefolding.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{{:helper.ntscieMode()}}
{{if data.crashed}}
<div class="block">
FOLDING@SCIENCE has stopped responding. The application may respond again if you wait.<br>
<i>Do you want to try and resume this process?</i>
<div class="item">
{{:helper.link('Restart Program', null, { "fix_crash": 1 })}}
</div>
</div>
{{else data.computing}}
<div class="block">
<center><h2>{{:data.science_string}}</h2></center>
</div>
{{for data.dos_strings}}
<center>{{:value}}</center>
{{/for}}
{{if data.completed}}
Computation complete!<br>
<div class="item">
{{:helper.link('Save', null, { "save": 1 })}}
</div>
{{else}}
<center>Time Remaining: {{:data.time_remaining}} seconds<br></center>
{{/if}}
{{else}}
<div class="block">
Science going ain't like you planned? Not using that dusty old computer? Donate your processor cycles to SCIENCE!
</div>
<div class="item">
{{:helper.link('GQ', null, { 'gq' : value })}}
[{{:data.gq}}]
<right> Possible amount of scientific research equals [{{:data.paspmin}} - {{:data.paspmax}}]</right>
</div>
<div class="item">
{{:helper.link('Fold Some Space Science', null, { "start": 1 })}}
</div>
{{/if}}
10 changes: 10 additions & 0 deletions nano/templates/rdconsole.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,16 @@
{{empty}}
<div class="item">The disk has no accessible design files stored on it.</div>
{{/for}}
Detected SF:
{{for data.disk_science}}
<div class="item">
{{:value.name}}
{{:helper.link("", 'trash', {'delete_disk_file' : value.id})}}
{{:helper.link("", 'arrowthick-1-e', {'download_disk_science' : value.id})}}
</div>
{{empty}}
<div class="item">The disk has no accessible science files stored on it.</div>
{{/for}}
</div>
</td>

Expand Down

0 comments on commit 115818d

Please sign in to comment.