mirror of
https://github.com/VOREStation/VOREStation.git
synced 2026-07-17 10:05:27 +01:00
Optimizes reaction checks
This commit is contained in:
@@ -183,6 +183,24 @@
|
||||
return 0
|
||||
return 0
|
||||
|
||||
/datum/reagents/proc/has_any_reagent(var/list/check_reagents)
|
||||
for(var/datum/reagent/current in reagent_list)
|
||||
if(current.id in check_reagents)
|
||||
if(current.volume >= check_reagents[current.id])
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
return 0
|
||||
|
||||
/datum/reagents/proc/has_all_reagents(var/list/check_reagents)
|
||||
//this only works if check_reagents has no duplicate entries... hopefully okay since it expects an associative list
|
||||
var/missing = check_reagents.len
|
||||
for(var/datum/reagent/current in reagent_list)
|
||||
if(current.id in check_reagents)
|
||||
if(current.volume >= check_reagents[current.id])
|
||||
missing--
|
||||
return !missing
|
||||
|
||||
/datum/reagents/proc/clear_reagents()
|
||||
for(var/datum/reagent/current in reagent_list)
|
||||
del_reagent(current.id)
|
||||
|
||||
@@ -54,21 +54,16 @@
|
||||
|
||||
/datum/chemical_reaction/proc/can_happen(var/datum/reagents/holder)
|
||||
//check that all the required reagents are present
|
||||
for(var/reagent in required_reagents)
|
||||
if(!holder.has_reagent(reagent))
|
||||
return 0
|
||||
if(!holder.has_all_reagents(required_reagents))
|
||||
return 0
|
||||
|
||||
//check that all the required catalysts are present in the required amount
|
||||
for(var/reagent in catalysts)
|
||||
var/min_req_amt = catalysts[reagent]
|
||||
if(!holder.has_reagent(reagent, min_req_amt))
|
||||
return 0
|
||||
if(!holder.has_all_reagents(catalysts))
|
||||
return 0
|
||||
|
||||
//check that none of the inhibitors are present in the required amount
|
||||
for(var/reagent in inhibitors)
|
||||
var/min_req_amt = inhibitors[reagent]
|
||||
if(holder.has_reagent(reagent, min_req_amt))
|
||||
return 0
|
||||
if(holder.has_any_reagent(inhibitors))
|
||||
return 0
|
||||
|
||||
return 1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user