mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-22 04:30:44 +01:00
Techwebs Backend Refactor - Removes references from techwebs and uses IDs instead (#40596)
Yeah yeah I know no opening too many WIP PRs but this one's [ready] and I want to make sure any furthur techweb development doesn't keep using the old reference system which will make refactoring it harder, and this makes it easier for coders to do stuff in theory (at least for me), standardizes getting a node/design, and makes stuff actually GC properly.
This commit is contained in:
@@ -5,12 +5,13 @@
|
||||
|
||||
//Techweb datums are meant to store unlocked research, being able to be stored on research consoles, servers, and disks. They are NOT global.
|
||||
/datum/techweb
|
||||
var/list/datum/techweb_node/researched_nodes = list() //Already unlocked and all designs are now available. Assoc list, id = datum
|
||||
var/list/datum/techweb_node/visible_nodes = list() //Visible nodes, doesn't mean it can be researched. Assoc list, id = datum
|
||||
var/list/datum/techweb_node/available_nodes = list() //Nodes that can immediately be researched, all reqs met. assoc list, id = datum
|
||||
var/list/datum/design/researched_designs = list() //Designs that are available for use. Assoc list, id = datum
|
||||
var/list/datum/techweb_node/boosted_nodes = list() //Already boosted nodes that can't be boosted again. node datum = path of boost object.
|
||||
var/list/datum/techweb_node/hidden_nodes = list() //Hidden nodes. id = datum. Used for unhiding nodes when requirements are met by removing the entry of the node.
|
||||
var/list/researched_nodes = list() //Already unlocked and all designs are now available. Assoc list, id = TRUE
|
||||
var/list/visible_nodes = list() //Visible nodes, doesn't mean it can be researched. Assoc list, id = TRUE
|
||||
var/list/available_nodes = list() //Nodes that can immediately be researched, all reqs met. assoc list, id = TRUE
|
||||
var/list/researched_designs = list() //Designs that are available for use. Assoc list, id = TRUE
|
||||
var/list/custom_designs = list() //Custom inserted designs like from disks that should survive recalculation.
|
||||
var/list/boosted_nodes = list() //Already boosted nodes that can't be boosted again. node id = path of boost object.
|
||||
var/list/hidden_nodes = list() //Hidden nodes. id = TRUE. Used for unhiding nodes when requirements are met by removing the entry of the node.
|
||||
var/list/deconstructed_items = list() //items already deconstructed for a generic point boost. path = list(point_type = points)
|
||||
var/list/research_points = list() //Available research points. type = number
|
||||
var/list/obj/machinery/computer/rdconsole/consoles_accessing = list()
|
||||
@@ -19,13 +20,14 @@
|
||||
var/largest_bomb_value = 0
|
||||
var/organization = "Third-Party" //Organization name, used for display.
|
||||
var/list/last_bitcoins = list() //Current per-second production, used for display only.
|
||||
var/list/tiers = list() //Assoc list, datum = number, 1 is available, 2 is all reqs are 1, so on
|
||||
var/list/tiers = list() //Assoc list, id = number, 1 is available, 2 is all reqs are 1, so on
|
||||
|
||||
/datum/techweb/New()
|
||||
SSresearch.techwebs += src
|
||||
for(var/i in SSresearch.techweb_nodes_starting)
|
||||
var/datum/techweb_node/DN = SSresearch.techweb_nodes_starting[i]
|
||||
var/datum/techweb_node/DN = SSresearch.techweb_node_by_id(i)
|
||||
research_node(DN, TRUE, FALSE)
|
||||
hidden_nodes = SSresearch.techweb_nodes_hidden
|
||||
hidden_nodes = SSresearch.techweb_nodes_hidden.Copy()
|
||||
return ..()
|
||||
|
||||
/datum/techweb/admin
|
||||
@@ -50,23 +52,24 @@
|
||||
researched_designs = null
|
||||
available_nodes = null
|
||||
visible_nodes = null
|
||||
custom_designs = null
|
||||
SSresearch.techwebs -= src
|
||||
return ..()
|
||||
|
||||
/datum/techweb/proc/recalculate_nodes(recalculate_designs = FALSE)
|
||||
/datum/techweb/proc/recalculate_nodes(recalculate_designs = FALSE, wipe_custom_designs = FALSE)
|
||||
var/list/datum/techweb_node/processing = list()
|
||||
for(var/i in researched_nodes)
|
||||
processing[i] = researched_nodes[i]
|
||||
for(var/i in visible_nodes)
|
||||
processing[i] = visible_nodes[i]
|
||||
for(var/i in available_nodes)
|
||||
processing[i] = available_nodes[i]
|
||||
for(var/i in processing)
|
||||
update_node_status(processing[i])
|
||||
if(recalculate_designs) //Wipes custom added designs like from design disks or anything like that!
|
||||
researched_designs = list()
|
||||
for(var/i in processing)
|
||||
var/datum/techweb_node/TN = processing[i]
|
||||
update_node_status(TN, FALSE)
|
||||
for(var/id in researched_nodes)
|
||||
processing[id] = TRUE
|
||||
for(var/id in visible_nodes)
|
||||
processing[id] = TRUE
|
||||
for(var/id in available_nodes)
|
||||
processing[id] = TRUE
|
||||
if(recalculate_designs)
|
||||
researched_designs = custom_designs.Copy()
|
||||
if(wipe_custom_designs)
|
||||
custom_designs = list()
|
||||
for(var/id in processing)
|
||||
update_node_status(SSresearch.techweb_node_by_id(id), FALSE)
|
||||
CHECK_TICK
|
||||
for(var/v in consoles_accessing)
|
||||
var/obj/machinery/computer/rdconsole/V = v
|
||||
@@ -156,21 +159,26 @@
|
||||
research_points[type] = max(0, research_points[type] - amount)
|
||||
return TRUE
|
||||
|
||||
/datum/techweb/proc/add_design_by_id(id)
|
||||
return add_design(get_techweb_design_by_id(id))
|
||||
/datum/techweb/proc/add_design_by_id(id, custom = FALSE)
|
||||
return add_design(SSresearch.techweb_design_by_id(id), custom)
|
||||
|
||||
/datum/techweb/proc/add_design(datum/design/design)
|
||||
/datum/techweb/proc/add_design(datum/design/design, custom = FALSE)
|
||||
if(!istype(design))
|
||||
return FALSE
|
||||
researched_designs[design.id] = design
|
||||
researched_designs[design.id] = TRUE
|
||||
if(custom)
|
||||
custom_designs[design.id] = TRUE
|
||||
return TRUE
|
||||
|
||||
/datum/techweb/proc/remove_design_by_id(id)
|
||||
return remove_design(get_techweb_design_by_id(id))
|
||||
/datum/techweb/proc/remove_design_by_id(id, custom = FALSE)
|
||||
return remove_design(SSresearch.techweb_design_by_id(id), custom)
|
||||
|
||||
/datum/techweb/proc/remove_design(datum/design/design)
|
||||
/datum/techweb/proc/remove_design(datum/design/design, custom = FALSE)
|
||||
if(!istype(design))
|
||||
return FALSE
|
||||
if(custom_designs[design.id] && !custom)
|
||||
return FALSE
|
||||
custom_designs -= design.id
|
||||
researched_designs -= design.id
|
||||
return TRUE
|
||||
|
||||
@@ -188,7 +196,7 @@
|
||||
return techweb_point_display_generic(research_points)
|
||||
|
||||
/datum/techweb/proc/research_node_id(id, force, auto_update_points)
|
||||
return research_node(get_techweb_node_by_id(id), force, auto_update_points)
|
||||
return research_node(SSresearch.techweb_node_by_id(id), force, auto_update_points)
|
||||
|
||||
/datum/techweb/proc/research_node(datum/techweb_node/node, force = FALSE, auto_adjust_cost = TRUE)
|
||||
if(!istype(node))
|
||||
@@ -199,12 +207,12 @@
|
||||
return FALSE
|
||||
if(auto_adjust_cost)
|
||||
remove_point_list(node.get_price(src))
|
||||
researched_nodes[node.id] = node //Add to our researched list
|
||||
for(var/i in node.unlocks)
|
||||
visible_nodes[i] = node.unlocks[i]
|
||||
update_node_status(node.unlocks[i])
|
||||
for(var/i in node.designs)
|
||||
add_design(node.designs[i])
|
||||
researched_nodes[node.id] = TRUE //Add to our researched list
|
||||
for(var/id in node.unlock_ids)
|
||||
visible_nodes[id] = TRUE
|
||||
update_node_status(SSresearch.techweb_node_by_id(id))
|
||||
for(var/id in node.design_ids)
|
||||
add_design_by_id(id)
|
||||
update_node_status(node)
|
||||
if(!istype(src, /datum/techweb/admin))
|
||||
var/datum/bank_account/D = SSeconomy.get_dep_account(ACCOUNT_SCI)
|
||||
@@ -213,7 +221,7 @@
|
||||
return TRUE
|
||||
|
||||
/datum/techweb/proc/unresearch_node_id(id)
|
||||
return unresearch_node(get_techweb_node_by_id(id))
|
||||
return unresearch_node(SSresearch.techweb_node_by_id(id))
|
||||
|
||||
/datum/techweb/proc/unresearch_node(datum/techweb_node/node)
|
||||
if(!istype(node))
|
||||
@@ -224,9 +232,9 @@
|
||||
/datum/techweb/proc/boost_with_path(datum/techweb_node/N, itempath)
|
||||
if(!istype(N) || !ispath(itempath))
|
||||
return FALSE
|
||||
LAZYINITLIST(boosted_nodes[N])
|
||||
LAZYINITLIST(boosted_nodes[N.id])
|
||||
for(var/i in N.boost_item_paths[itempath])
|
||||
boosted_nodes[N][i] = max(boosted_nodes[N][i], N.boost_item_paths[itempath][i])
|
||||
boosted_nodes[N.id][i] = max(boosted_nodes[N.id][i], N.boost_item_paths[itempath][i])
|
||||
if(N.autounlock_by_boost)
|
||||
hidden_nodes -= N.id
|
||||
update_node_status(N)
|
||||
@@ -241,13 +249,13 @@
|
||||
var/tier = 0
|
||||
if (!researched_nodes[node.id]) // researched is tier 0
|
||||
for (var/id in node.prereq_ids)
|
||||
var/prereq_tier = tiers[node.prerequisites[id]]
|
||||
var/prereq_tier = tiers[id]
|
||||
tier = max(tier, prereq_tier + 1)
|
||||
|
||||
if (tier != tiers[node])
|
||||
tiers[node] = tier
|
||||
for (var/id in node.unlocks)
|
||||
next += node.unlocks[id]
|
||||
if (tier != tiers[node.id])
|
||||
tiers[node.id] = tier
|
||||
for (var/id in node.unlock_ids)
|
||||
next += SSresearch.techweb_node_by_id(id)
|
||||
current = next
|
||||
|
||||
/datum/techweb/proc/update_node_status(datum/techweb_node/node, autoupdate_consoles = TRUE)
|
||||
@@ -257,8 +265,8 @@
|
||||
if(researched_nodes[node.id])
|
||||
researched = TRUE
|
||||
var/needed = node.prereq_ids.len
|
||||
for(var/i in node.prereq_ids)
|
||||
if(researched_nodes[i])
|
||||
for(var/id in node.prereq_ids)
|
||||
if(researched_nodes[id])
|
||||
visible = TRUE
|
||||
needed--
|
||||
if(!needed)
|
||||
@@ -269,15 +277,15 @@
|
||||
if(hidden_nodes[node.id]) //Hidden.
|
||||
return
|
||||
if(researched)
|
||||
researched_nodes[node.id] = node
|
||||
for(var/i in node.designs)
|
||||
add_design(node.designs[i])
|
||||
researched_nodes[node.id] = TRUE
|
||||
for(var/id in node.design_ids)
|
||||
add_design(SSresearch.techweb_design_by_id(id))
|
||||
else
|
||||
if(available)
|
||||
available_nodes[node.id] = node
|
||||
available_nodes[node.id] = TRUE
|
||||
else
|
||||
if(visible)
|
||||
visible_nodes[node.id] = node
|
||||
visible_nodes[node.id] = TRUE
|
||||
update_tiers(node)
|
||||
if(autoupdate_consoles)
|
||||
for(var/v in consoles_accessing)
|
||||
@@ -288,35 +296,34 @@
|
||||
//Laggy procs to do specific checks, just in case. Don't use them if you can just use the vars that already store all this!
|
||||
/datum/techweb/proc/designHasReqs(datum/design/D)
|
||||
for(var/i in researched_nodes)
|
||||
var/datum/techweb_node/N = researched_nodes[i]
|
||||
for(var/I in N.designs)
|
||||
if(D == N.designs[I])
|
||||
return TRUE
|
||||
var/datum/techweb_node/N = SSresearch.techweb_node_by_id(i)
|
||||
if(N.design_ids[D.id])
|
||||
return TRUE
|
||||
return FALSE
|
||||
|
||||
/datum/techweb/proc/isDesignResearched(datum/design/D)
|
||||
return isDesignResearchedID(D.id)
|
||||
|
||||
/datum/techweb/proc/isDesignResearchedID(id)
|
||||
return researched_designs[id]
|
||||
return researched_designs[id]? SSresearch.techweb_design_by_id(id) : FALSE
|
||||
|
||||
/datum/techweb/proc/isNodeResearched(datum/techweb_node/N)
|
||||
return isNodeResearchedID(N.id)
|
||||
|
||||
/datum/techweb/proc/isNodeResearchedID(id)
|
||||
return researched_nodes[id]
|
||||
return researched_nodes[id]? SSresearch.techweb_node_by_id(id) : FALSE
|
||||
|
||||
/datum/techweb/proc/isNodeVisible(datum/techweb_node/N)
|
||||
return isNodeResearchedID(N.id)
|
||||
|
||||
/datum/techweb/proc/isNodeVisibleID(id)
|
||||
return visible_nodes[id]
|
||||
return visible_nodes[id]? SSresearch.techweb_node_by_id(id) : FALSE
|
||||
|
||||
/datum/techweb/proc/isNodeAvailable(datum/techweb_node/N)
|
||||
return isNodeAvailableID(N.id)
|
||||
|
||||
/datum/techweb/proc/isNodeAvailableID(id)
|
||||
return available_nodes[id]
|
||||
return available_nodes[id]? SSresearch.techweb_node_by_id(id) : FALSE
|
||||
|
||||
/datum/techweb/specialized
|
||||
var/allowed_buildtypes = ALL
|
||||
@@ -339,11 +346,11 @@
|
||||
for(var/id in node_autounlock_ids)
|
||||
research_node_id(id, TRUE, FALSE)
|
||||
for(var/id in SSresearch.techweb_designs)
|
||||
var/datum/design/D = SSresearch.techweb_designs[id]
|
||||
var/datum/design/D = SSresearch.techweb_design_by_id(id)
|
||||
if(D.build_type & design_autounlock_buildtypes)
|
||||
for(var/i in D.category)
|
||||
if(i in design_autounlock_categories)
|
||||
add_design(D)
|
||||
add_design_by_id(D.id)
|
||||
break
|
||||
|
||||
/datum/techweb/specialized/autounlocking/autolathe
|
||||
|
||||
Reference in New Issue
Block a user