Ability to select the logic for Nanite rules (AND, OR) (#56542)

Added a button to the Nanite Cloud Controller Rules UI with two states:

- Meet all (default) - all rules must be met to run the program
- Meet any - any of the rules must be met to run the program

This change doesn't impact the default rule behavior, but gives an
ability to create more flexible rule setups when needed.
This commit is contained in:
Andrew
2021-02-01 20:03:40 +03:00
committed by GitHub
parent 1a6eb49ab6
commit 016ec5f523
3 changed files with 37 additions and 11 deletions
@@ -144,6 +144,7 @@
cloud_program["rules"] = rules
if(LAZYLEN(rules))
cloud_program["has_rules"] = TRUE
cloud_program["all_rules_required"] = P.all_rules_required
var/list/extra_settings = P.get_extra_settings_frontend()
cloud_program["extra_settings"] = extra_settings
@@ -233,6 +234,15 @@
investigate_log("[key_name(usr)] removed rule [rule.display()] from program [P.name] in cloud #[current_view]", INVESTIGATE_NANITES)
. = TRUE
if("toggle_rule_logic")
var/datum/nanite_cloud_backup/backup = get_backup(current_view)
if(backup)
playsound(src, 'sound/machines/terminal_prompt.ogg', 50, FALSE)
var/datum/component/nanites/nanites = backup.nanites
var/datum/nanite_program/P = nanites.programs[text2num(params["program_id"])]
P.all_rules_required = !P.all_rules_required
investigate_log("[key_name(usr)] edited rule logic for program [P.name] into [P.all_rules_required ? "All" : "Any"] in cloud #[current_view]", INVESTIGATE_NANITES)
. = TRUE
/datum/nanite_cloud_backup
var/cloud_id = 0
@@ -53,6 +53,7 @@
//Rules
//Rules that automatically manage if the program's active without requiring separate sensor programs
var/list/datum/nanite_rule/rules = list()
var/all_rules_required = TRUE //Whether all rules are required for positive condition or any of specified
/datum/nanite_program/New()
. = ..()
@@ -92,6 +93,7 @@
for(var/R in rules)
var/datum/nanite_rule/rule = R
rule.copy_to(target)
target.all_rules_required = all_rules_required
if(istype(target,src))
copy_extra_settings_to(target)
@@ -194,11 +196,15 @@
//If false, disables active and passive effects, but doesn't consume nanites
//Can be used to avoid consuming nanites for nothing
/datum/nanite_program/proc/check_conditions()
if (!LAZYLEN(rules))
return TRUE
for(var/R in rules)
var/datum/nanite_rule/rule = R
if(!rule.check_rule())
if(!all_rules_required && rule.check_rule())
return TRUE
if(all_rules_required && !rule.check_rule())
return FALSE
return TRUE
return all_rules_required ? TRUE : FALSE
//Constantly procs as long as the program is active
/datum/nanite_program/proc/active_effect()