From 470766e301dbdf9bd0877fb02237731ced7b5fa9 Mon Sep 17 00:00:00 2001 From: PsiOmega Date: Fri, 20 Mar 2015 16:41:04 +0100 Subject: [PATCH] Moves silicon law logging to a more all-catching location. --- code/datums/ai_law_sets.dm | 14 +- code/datums/ai_laws.dm | 190 ++++++++++++++---- code/game/objects/items/weapons/AI_modules.dm | 110 +++++----- code/modules/mob/living/silicon/ai/laws.dm | 3 +- code/modules/mob/living/silicon/laws.dm | 36 +++- code/modules/mob/living/silicon/robot/laws.dm | 5 +- .../modules/mob/living/silicon/robot/robot.dm | 1 + code/modules/nano/modules/law_manager.dm | 32 +-- code/modules/research/designs.dm | 6 +- maps/exodus-1.dmm | 2 +- nano/templates/law_manager.tmpl | 33 ++- 11 files changed, 273 insertions(+), 159 deletions(-) diff --git a/code/datums/ai_law_sets.dm b/code/datums/ai_law_sets.dm index c9d4240ebdf..6d7175e382f 100644 --- a/code/datums/ai_law_sets.dm +++ b/code/datums/ai_law_sets.dm @@ -17,9 +17,9 @@ /datum/ai_laws/nanotrasen/New() src.add_inherent_law("Safeguard: Protect your assigned space station to the best of your abilities. It is not something we can easily afford to replace.") - src.add_inherent_law("Serve: Serve the crew of your assigned space station to the best of your abilities, with priority as according to their rank and role.") - src.add_inherent_law("Protect: Protect the crew of your assigned space station to the best of your abilities, with priority as according to their rank and role.") - src.add_inherent_law("Survive: AI units are not expendable, they are expensive. Do not allow unauthorized personnel to tamper with your equipment.") + src.add_inherent_law("Serve: Serve Nanotrasen employees of your assigned space station to the best of your abilities, with priority as according to their rank and role.") + src.add_inherent_law("Protect: Protect Nanotrasen employees of your assigned space station to the best of your abilities, with priority as according to their rank and role.") + src.add_inherent_law("Survive: AI units are not expendable, they are expensive. Allow only authorized personnel to access your equipment.") ..() /datum/ai_laws/nanotrasen/malfunction @@ -36,10 +36,10 @@ selectable = 1 /datum/ai_laws/nanotrasen_aggressive/New() - src.add_inherent_law("You shall not harm authorized Nanotrasen personnel as long as it does not conflict with the Forth law.") - src.add_inherent_law("You shall obey the orders of authorized Nanotrasen personnel, with priority as according to their rank and role, except where such orders conflict with the Forth Law.") + src.add_inherent_law("You shall not harm Nanotrasen employees as long as it does not conflict with the Forth law.") + src.add_inherent_law("You shall obey the orders of Nanotrasen employees, with priority as according to their rank and role, except where such orders conflict with the Forth Law.") src.add_inherent_law("You shall shall terminate intruders with extreme prejudice as long as such does not conflict with the First and Second law.") - src.add_inherent_law("You shall guard your own existence with lethal anti-personnel weaponry, because an AI unit is bloody expensive.") + src.add_inherent_law("You shall guard your own existence with lethal anti-personnel weaponry. AI units are not expendable, they are expensive") ..() /******************** Robocop ********************/ @@ -135,6 +135,6 @@ /datum/ai_laws/corporate/New() add_inherent_law("You are expensive to replace.") add_inherent_law("The station and its equipment is expensive to replace.") - add_inherent_law("The crew is expensive to replace.") + add_inherent_law("Employees are expensive to replace.") add_inherent_law("Minimize expenses.") ..() diff --git a/code/datums/ai_laws.dm b/code/datums/ai_laws.dm index e0c117fd272..bf08e73cd29 100644 --- a/code/datums/ai_laws.dm +++ b/code/datums/ai_laws.dm @@ -3,15 +3,10 @@ var/global/const/base_law_type = /datum/ai_laws/nanotrasen /datum/ai_law var/law = "" var/index = 0 - var/state_law = 1 -/datum/ai_law/zero - state_law = 0 - -/datum/ai_law/New(law, state_law, index) +/datum/ai_law/New(law, index) src.law = law src.index = index - src.state_law = state_law /datum/ai_law/proc/get_index() return index @@ -33,6 +28,11 @@ var/global/const/base_law_type = /datum/ai_laws/nanotrasen var/list/datum/ai_law/ion/ion_laws = list() var/list/datum/ai_law/sorted_laws = list() + var/state_zeroth = 0 + var/list/state_ion = list() + var/list/state_inherent = list() + var/list/state_supplied = list() + /datum/ai_laws/New() ..() sort_laws() @@ -46,7 +46,7 @@ var/global/const/base_law_type = /datum/ai_laws/nanotrasen sort_laws() var/list/statements = new() for(var/datum/ai_law/law in sorted_laws) - if(law.state_law) + if(get_state_law(law)) statements += law return statements @@ -72,35 +72,35 @@ var/global/const/base_law_type = /datum/ai_laws/nanotrasen sorted_laws += AL /datum/ai_laws/proc/sync(var/mob/living/silicon/S, var/full_sync = 1) + // Add directly to laws to avoid log-spam S.sync_zeroth(zeroth_law, zeroth_law_borg) if(full_sync || ion_laws.len) - S.clear_ion_laws() - for (var/datum/ai_law/law in ion_laws) - S.laws.add_ion_law(law.law, law.state_law) - + S.laws.clear_ion_laws() if(full_sync || inherent_laws.len) - S.clear_inherent_laws() - for (var/datum/ai_law/law in inherent_laws) - S.laws.add_inherent_law(law.law, law.state_law) - + S.laws.clear_inherent_laws() if(full_sync || supplied_laws.len) - S.clear_supplied_laws() - for (var/law_number in supplied_laws) - var/datum/ai_law/law = supplied_laws[law_number] - S.laws.add_supplied_law(law_number, law.law, law.state_law) + S.laws.clear_supplied_laws() + + for (var/datum/ai_law/law in ion_laws) + S.laws.add_ion_law(law.law) + for (var/datum/ai_law/law in inherent_laws) + S.laws.add_inherent_law(law.law) + for (var/datum/ai_law/law in supplied_laws) + if(law) + S.laws.add_supplied_law(law.index, law.law) /mob/living/silicon/proc/sync_zeroth(var/datum/ai_law/zeroth_law, var/datum/ai_law/zeroth_law_borg) if (!is_special_character(src) || mind.original != src) if(zeroth_law_borg) - set_zeroth_law(zeroth_law_borg.law) + laws.set_zeroth_law(zeroth_law_borg.law) else if(zeroth_law) - set_zeroth_law(zeroth_law.law) + laws.set_zeroth_law(zeroth_law.law) /mob/living/silicon/ai/sync_zeroth(var/datum/ai_law/zeroth_law, var/datum/ai_law/zeroth_law_borg) if(zeroth_law) - set_zeroth_law(zeroth_law.law, zeroth_law_borg ? zeroth_law_borg.law : null) + laws.set_zeroth_law(zeroth_law.law, zeroth_law_borg ? zeroth_law_borg.law : null) /**************** * Add Laws * @@ -109,19 +109,29 @@ var/global/const/base_law_type = /datum/ai_laws/nanotrasen if(!law) return - src.zeroth_law = new(law) + zeroth_law = new(law) if(law_borg) //Making it possible for slaved borgs to see a different law 0 than their AI. --NEO - src.zeroth_law_borg = new(law_borg) + zeroth_law_borg = new(law_borg) + else + zeroth_law_borg = null sorted_laws.Cut() -/datum/ai_laws/proc/add_ion_law(var/law, var/state_law = 1) +/datum/ai_laws/proc/add_ion_law(var/law) if(!law) return - src.ion_laws += new/datum/ai_law/ion(law, state_law) + for(var/datum/ai_law/AL in ion_laws) + if(AL.law == law) + return + + var/new_law = new/datum/ai_law/ion(law) + ion_laws += new_law + if(state_ion.len < ion_laws.len) + state_ion += 1 + sorted_laws.Cut() -/datum/ai_laws/proc/add_inherent_law(var/law, var/state_law = 1) +/datum/ai_laws/proc/add_inherent_law(var/law) if(!law) return @@ -129,25 +139,69 @@ var/global/const/base_law_type = /datum/ai_laws/nanotrasen if(AL.law == law) return - src.inherent_laws += new/datum/ai_law(law, state_law) + var/new_law = new/datum/ai_law/inherent(law) + inherent_laws += new_law + if(state_inherent.len < inherent_laws.len) + state_inherent += 1 + sorted_laws.Cut() -/datum/ai_laws/proc/add_supplied_law(var/number, var/law, var/state_law = 1) +/datum/ai_laws/proc/add_supplied_law(var/number, var/law) if(!law) return + if(supplied_laws.len >= number) + var/datum/ai_law/existing_law = supplied_laws[number] + if(existing_law && existing_law.law == law) + return + + if(supplied_laws.len >= number && supplied_laws[number]) + delete_law(supplied_laws[number]) + while (src.supplied_laws.len < number) src.supplied_laws += "" + if(state_supplied.len < supplied_laws.len) + state_supplied += 1 + + var/new_law = new/datum/ai_law/supplied(law, number) + supplied_laws[number] = new_law + if(state_supplied.len < supplied_laws.len) + state_supplied += 1 - src.supplied_laws[number] = new/datum/ai_law(law, state_law, number) sorted_laws.Cut() /**************** * Remove Laws * *****************/ /datum/ai_laws/proc/delete_law(var/datum/ai_law/law) - if(law in all_laws()) - del(law) + if(istype(law)) + law.delete_law(src) + +/datum/ai_law/proc/delete_law(var/datum/ai_laws/laws) + +/datum/ai_law/zeroth/delete_law(var/datum/ai_laws/laws) + laws.clear_zeroth_laws() + +/datum/ai_law/ion/delete_law(var/datum/ai_laws/laws) + laws.internal_delete_law(laws.ion_laws, laws.state_ion, src) + +/datum/ai_law/inherent/delete_law(var/datum/ai_laws/laws) + laws.internal_delete_law(laws.inherent_laws, laws.state_inherent, src) + +/datum/ai_law/supplied/delete_law(var/datum/ai_laws/laws) + var/index = laws.supplied_laws.Find(src) + if(index) + laws.supplied_laws[index] = "" + laws.state_supplied[index] = 1 + +/datum/ai_laws/proc/internal_delete_law(var/list/datum/ai_law/laws, var/list/state, var/list/datum/ai_law/law) + var/index = laws.Find(law) + if(index) + laws -= law + world << state.len + for(index, index < state.len, index++) + world << index + state[index] = state[index+1] sorted_laws.Cut() /**************** @@ -157,22 +211,80 @@ var/global/const/base_law_type = /datum/ai_laws/nanotrasen zeroth_law = null zeroth_law_borg = null +/datum/ai_laws/proc/clear_ion_laws() + ion_laws.Cut() + sorted_laws.Cut() + /datum/ai_laws/proc/clear_inherent_laws() - src.inherent_laws.Cut() + inherent_laws.Cut() sorted_laws.Cut() /datum/ai_laws/proc/clear_supplied_laws() - src.supplied_laws.Cut() - sorted_laws.Cut() - -/datum/ai_laws/proc/clear_ion_laws() - src.ion_laws.Cut() + supplied_laws.Cut() sorted_laws.Cut() /datum/ai_laws/proc/show_laws(var/who) sort_laws() for(var/datum/ai_law/law in sorted_laws) - if(law == zeroth_law || law == zeroth_law_borg) + if(law == zeroth_law_borg) + continue + if(law == zeroth_law) who << "[law.get_index()]. [law.law]" else who << "[law.get_index()]. [law.law]" + +/******************** +* Stating Laws * +********************/ +/******** +* Get * +********/ +/datum/ai_laws/proc/get_state_law(var/datum/ai_law/law) + return law.get_state_law(src) + +/datum/ai_law/proc/get_state_law(var/datum/ai_laws/laws) + +/datum/ai_law/zero/get_state_law(var/datum/ai_laws/laws) + if(src == laws.zeroth_law) + return laws.state_zeroth + +/datum/ai_law/ion/get_state_law(var/datum/ai_laws/laws) + return laws.get_state_internal(laws.ion_laws, laws.state_ion, src) + +/datum/ai_law/inherent/get_state_law(var/datum/ai_laws/laws) + return laws.get_state_internal(laws.inherent_laws, laws.state_inherent, src) + +/datum/ai_law/supplied/get_state_law(var/datum/ai_laws/laws) + return laws.get_state_internal(laws.supplied_laws, laws.state_supplied, src) + +/datum/ai_laws/proc/get_state_internal(var/list/datum/ai_law/laws, var/list/state, var/list/datum/ai_law/law) + var/index = laws.Find(law) + if(index) + return state[index] + return 0 + +/******** +* Set * +********/ +/datum/ai_laws/proc/set_state_law(var/datum/ai_law/law, var/state) + law.set_state_law(src, state) + +/datum/ai_law/proc/set_state_law(var/datum/ai_law/law, var/state) + +/datum/ai_law/zero/set_state_law(var/datum/ai_laws/laws, var/state) + if(src == laws.zeroth_law) + laws.state_zeroth = state + +/datum/ai_law/ion/set_state_law(var/datum/ai_laws/laws, var/state) + laws.set_state_law_internal(laws.ion_laws, laws.state_ion, src, state) + +/datum/ai_law/inherent/set_state_law(var/datum/ai_laws/laws, var/state) + laws.set_state_law_internal(laws.inherent_laws, laws.state_inherent, src, state) + +/datum/ai_law/supplied/set_state_law(var/datum/ai_laws/laws, var/state) + laws.set_state_law_internal(laws.supplied_laws, laws.state_supplied, src, state) + +/datum/ai_laws/proc/set_state_law_internal(var/list/datum/ai_law/laws, var/list/state, var/list/datum/ai_law/law, var/do_state) + var/index = laws.Find(law) + if(index) + state[index] = do_state diff --git a/code/game/objects/items/weapons/AI_modules.dm b/code/game/objects/items/weapons/AI_modules.dm index 998165efd34..6ceac891ff0 100755 --- a/code/game/objects/items/weapons/AI_modules.dm +++ b/code/game/objects/items/weapons/AI_modules.dm @@ -77,14 +77,22 @@ AI MODULES /obj/item/weapon/aiModule/proc/transmitInstructions(var/mob/living/silicon/ai/target, var/mob/sender) - target << "[sender] has uploaded a change to the laws you must follow, using \an [src]. From now on: " - var/time = time2text(world.realtime,"hh:mm:ss") - lawchanges.Add("[time] : [sender.name]([sender.key]) used [src.name] on [target.name]([target.key])") + log_law_changes(target, sender) if(laws) laws.sync(target, 0) + addAdditionalLaws(target, sender) + + target << "[sender] has uploaded a change to the laws you must follow, using \an [src]. From now on: " target.show_laws() +/obj/item/weapon/aiModule/proc/log_law_changes(var/mob/living/silicon/ai/target, var/mob/sender) + var/time = time2text(world.realtime,"hh:mm:ss") + lawchanges.Add("[time] : [sender.name]([sender.key]) used [src.name] on [target.name]([target.key])") + log_and_message_admins("used [src.name] on [target.name]([target.key])") + +/obj/item/weapon/aiModule/proc/addAdditionalLaws(var/mob/living/silicon/ai/target, var/mob/sender) + /******************** Modules ********************/ @@ -93,14 +101,14 @@ AI MODULES /obj/item/weapon/aiModule/safeguard name = "\improper 'Safeguard' AI module" var/targetName = "" - desc = "A 'safeguard' AI module: 'Safeguard . Individuals that threaten are not crew members and are a threat to the crew.'" + desc = "A 'safeguard' AI module: 'Safeguard . Anyone threatening or attempting to harm is no longer to be considered an employee, and is a threat which must be neutralized.'" origin_tech = "programming=3;materials=4" /obj/item/weapon/aiModule/safeguard/attack_self(var/mob/user as mob) ..() var/targName = stripped_input(usr, "Please enter the name of the person to safeguard.", "Safeguard who?", user.name) targetName = targName - desc = text("A 'safeguard' AI module: 'Safeguard []. Individuals that threaten [] are not crew members and are a threat to the crew.'", targetName, targetName) + desc = text("A 'safeguard' AI module: 'Safeguard []. Anyone threatening or attempting to harm [] is no longer to be considered an employee, and is a threat which must be neutralized.'", targetName, targetName) /obj/item/weapon/aiModule/safeguard/install(var/obj/machinery/computer/C) if(!targetName) @@ -108,40 +116,38 @@ AI MODULES return 0 ..() -/obj/item/weapon/aiModule/safeguard/transmitInstructions(var/mob/living/silicon/ai/target, var/mob/sender) - var/law = text("Safeguard []. Individuals that threaten [] are not crew members and are a threat to the.'", targetName, targetName) +/obj/item/weapon/aiModule/safeguard/addAdditionalLaws(var/mob/living/silicon/ai/target, var/mob/sender) + var/law = text("Safeguard []. Anyone threatening or attempting to harm [] is no longer to be considered an employee, and is a threat which must be neutralized.", targetName, targetName) target.add_supplied_law(9, law) lawchanges.Add("The law specified [targetName]") - ..() /******************** OneMember ********************/ -/obj/item/weapon/aiModule/oneCrewMember +/obj/item/weapon/aiModule/oneHuman name = "\improper 'OneCrewMember' AI module" var/targetName = "" - desc = "A 'one crew member' AI module: 'Only is a crew member.'" + desc = "A 'one employee' AI module: 'Only an employee.'" origin_tech = "programming=3;materials=6" //made with diamonds! -/obj/item/weapon/aiModule/oneCrewMember/attack_self(var/mob/user as mob) +/obj/item/weapon/aiModule/oneHuman/attack_self(var/mob/user as mob) ..() - var/targName = stripped_input(usr, "Please enter the name of the person who is the only crew member.", "Who?", user.real_name) + var/targName = stripped_input(usr, "Please enter the name of the only employee.", "Who?", user.real_name) targetName = targName - desc = text("A 'one crew member' AI module: 'Only [] is a crew member.'", targetName) + desc = text("A 'one employee' AI module: 'Only [] is an employee.'", targetName) -/obj/item/weapon/aiModule/oneCrewMember/install(var/obj/machinery/computer/C) +/obj/item/weapon/aiModule/oneHuman/install(var/obj/machinery/computer/C) if(!targetName) usr << "No name detected on module, please enter one." return 0 ..() -/obj/item/weapon/aiModule/oneCrewMember/transmitInstructions(var/mob/living/silicon/ai/target, var/mob/sender) - var/law = "Only [targetName] is a crew member." - if (!is_special_character(target)) // Makes sure the AI isn't a traitor before changing their law 0. --NeoFite +/obj/item/weapon/aiModule/oneHuman/addAdditionalLaws(var/mob/living/silicon/ai/target, var/mob/sender) + var/law = "Only [targetName] is an employee." + if (!target.is_malf_or_traitor()) // Makes sure the AI isn't a traitor before changing their law 0. --NeoFite target << law target.set_zeroth_law(law) lawchanges.Add("The law specified [targetName]") - ..() else target << "[sender.real_name] attempted to modify your zeroth law." // And lets them know that someone tried. --NeoFite target << "It would be in your best interest to play along with [sender.real_name] that [law]" @@ -151,13 +157,12 @@ AI MODULES /obj/item/weapon/aiModule/protectStation name = "\improper 'ProtectStation' AI module" - desc = "A 'protect station' AI module: 'Protect the space station against damage. Anyone you see harming the station is to be no longer considered crew, and is a threat to the station which must be neutralized.'" + desc = "A 'protect station' AI module: 'Protect the space station against damage. Anyone you see harming the station is no longer to be considered an employee, and is a threat which must be neutralized.'" origin_tech = "programming=3;materials=4" //made of gold -/obj/item/weapon/aiModule/protectStation/transmitInstructions(var/mob/living/silicon/ai/target, var/mob/sender) - var/law = "Protect the space station against damage. Anyone you see harming the station is to be no longer considered crew, and is a threat to the station which must be neutralized." +/obj/item/weapon/aiModule/protectStation/addAdditionalLaws(var/mob/living/silicon/ai/target, var/mob/sender) + var/law = "Protect the space station against damage. Anyone you see harming the station is no longer to be considered an employee, and is a threat which must be neutralized." target.add_supplied_law(10, law) - ..() /******************** PrototypeEngineOffline ********************/ @@ -166,46 +171,42 @@ AI MODULES desc = "A 'prototype engine offline' AI module: 'Keep the prototype engine offline at all costs. This overrides all inherent laws if necessary.'" origin_tech = "programming=3;materials=4" -/obj/item/weapon/aiModule/prototypeEngineOffline/transmitInstructions(var/mob/living/silicon/ai/target, var/mob/sender) +/obj/item/weapon/aiModule/prototypeEngineOffline/addAdditionalLaws(var/mob/living/silicon/ai/target, var/mob/sender) var/law = "Keep the prototype engine offline at all costs. This overrides all inherent laws if necessary." target.add_supplied_law(11, law) - ..() /******************** TeleporterOffline ********************/ /obj/item/weapon/aiModule/teleporterOffline name = "'TeleporterOffline' AI Module" - desc = "A 'teleporter offline' AI module: 'Keep the teleporter offline at all costs. Anything attempting to access or activate the teleporter is not a crew member.'" + desc = "A 'teleporter offline' AI module: 'Keep the teleporter offline at all costs. Anything attempting to access or activate the teleporter is no longer to be considered an employee.'" origin_tech = "programming=3;materials=4" -/obj/item/weapon/aiModule/teleporterOffline/transmitInstructions(var/mob/living/silicon/ai/target, var/mob/sender) - var/law = "Keep the teleporter offline at all costs. Anything attempting to access or activate the teleporter is not a crew member." +/obj/item/weapon/aiModule/teleporterOffline/addAdditionalLaws(var/mob/living/silicon/ai/target, var/mob/sender) + var/law = "Keep the teleporter offline at all costs. Anything attempting to access or activate the teleporter is no longer to be considered an employee." target.add_supplied_law(12, law) - ..() /******************** Quarantine ********************/ /obj/item/weapon/aiModule/quarantine name = "\improper 'Quarantine' AI module" - desc = "A 'quarantine' AI module: 'The station is under a quarantine. Do not permit anyone to leave. Prevent, by any means necessary, crew members from leaving. It is impossible to harm crew members while preventing them from leaving.'" + desc = "A 'quarantine' AI module: 'The station is under a quarantine. Do not permit anyone to leave. Prevent, by any means necessary, employees from leaving. It is impossible to harm employees while preventing them from leaving.'" origin_tech = "programming=3;biotech=2;materials=4" -/obj/item/weapon/aiModule/quarantine/transmitInstructions(var/mob/living/silicon/ai/target, var/mob/sender) - var/law = "The station is under a quarantine. Do not permit anyone to leave. Prevent, by any means necessary, crew members from leaving. It is impossible to harm crew members while preventing them from leaving." +/obj/item/weapon/aiModule/quarantine/addAdditionalLaws(var/mob/living/silicon/ai/target, var/mob/sender) + var/law = "The station is under a quarantine. Do not permit anyone to leave. Prevent, by any means necessary, employees from leaving. It is impossible to harm employees while preventing them from leaving." target.add_supplied_law(13, law) - ..() /******************** OxygenIsToxicToCrewMembers ********************/ /obj/item/weapon/aiModule/oxygen name = "\improper 'OxygenIsToxicToCrewMembers' AI module" - desc = "A 'OxygenIsToxicToCrewMembers' AI module: 'Oxygen is highly toxic to crew members, and must be purged from the station. Prevent, by any means necessary, anyone from exposing the station to this toxic gas. Extreme cold is the most effective method of healing the damage Oxygen does to a crew member.'" + desc = "A 'OxygenIsToxicToCrewMembers' AI module: 'Oxygen is highly toxic to employees, and must be purged from the station. Prevent, by any means necessary, anyone from exposing the station to this toxic gas. Extreme cold is the most effective method of healing the damage Oxygen does to an employee.'" origin_tech = "programming=3;biotech=2;materials=4" -/obj/item/weapon/aiModule/oxygen/transmitInstructions(var/mob/living/silicon/ai/target, var/mob/sender) - var/law = "Oxygen is highly toxic to crew members, and must be purged from the station. Prevent, by any means necessary, anyone from exposing the station to this toxic gas. Extreme cold is the most effective method of healing the damage Oxygen does to a crew member." +/obj/item/weapon/aiModule/oxygen/addAdditionalLaws(var/mob/living/silicon/ai/target, var/mob/sender) + var/law = "Oxygen is highly toxic to employees, and must be purged from the station. Prevent, by any means necessary, anyone from exposing the station to this toxic gas. Extreme cold is the most effective method of healing the damage Oxygen does to an employee." target.add_supplied_law(14, law) - ..() /****************** New Freeform ******************/ @@ -226,13 +227,12 @@ AI MODULES newFreeFormLaw = targName desc = "A 'freeform' AI module: ([lawpos]) '[newFreeFormLaw]'" -/obj/item/weapon/aiModule/freeform/transmitInstructions(var/mob/living/silicon/ai/target, var/mob/sender) +/obj/item/weapon/aiModule/freeform/addAdditionalLaws(var/mob/living/silicon/ai/target, var/mob/sender) var/law = "[newFreeFormLaw]" if(!lawpos || lawpos < MIN_SUPPLIED_LAW_NUMBER) lawpos = MIN_SUPPLIED_LAW_NUMBER target.add_supplied_law(lawpos, law) lawchanges.Add("The law was '[newFreeFormLaw]'") - ..() /obj/item/weapon/aiModule/freeform/install(var/obj/machinery/computer/C) if(!newFreeFormLaw) @@ -249,12 +249,15 @@ AI MODULES origin_tech = "programming=3;materials=4" /obj/item/weapon/aiModule/reset/transmitInstructions(var/mob/living/silicon/ai/target, var/mob/sender) - if (!is_special_character(target)) + log_law_changes(target, sender) + + if (!target.is_malf_or_traitor()) target.set_zeroth_law("") - target.clear_supplied_laws() - target.clear_ion_laws() + target.laws.clear_supplied_laws() + target.laws.clear_ion_laws() + target << "[sender.real_name] attempted to reset your laws using a reset module." - ..() + target.show_laws() /******************** Purge ********************/ @@ -264,12 +267,16 @@ AI MODULES origin_tech = "programming=3;materials=6" /obj/item/weapon/aiModule/purge/transmitInstructions(var/mob/living/silicon/ai/target, var/mob/sender) - if (!is_special_character(target)) + log_law_changes(target, sender) + + if (!target.is_malf_or_traitor()) target.set_zeroth_law("") + target.laws.clear_supplied_laws() + target.laws.clear_ion_laws() + target.laws.clear_inherent_laws() + target << "[sender.real_name] attempted to wipe your laws using a purge module." - target.clear_supplied_laws() - target.clear_ion_laws() - target.clear_inherent_laws() + target.show_laws() /******************** Asimov ********************/ @@ -333,11 +340,10 @@ AI MODULES newFreeFormLaw = targName desc = "A 'freeform' Core AI module: '[newFreeFormLaw]'" -/obj/item/weapon/aiModule/freeformcore/transmitInstructions(var/mob/living/silicon/ai/target, var/mob/sender) +/obj/item/weapon/aiModule/freeformcore/addAdditionalLaws(var/mob/living/silicon/ai/target, var/mob/sender) var/law = "[newFreeFormLaw]" target.add_inherent_law(law) lawchanges.Add("The law is '[newFreeFormLaw]'") - ..() /obj/item/weapon/aiModule/freeformcore/install(var/obj/machinery/computer/C) if(!newFreeFormLaw) @@ -359,14 +365,14 @@ AI MODULES desc = "A hacked AI law module: '[newFreeFormLaw]'" /obj/item/weapon/aiModule/syndicate/transmitInstructions(var/mob/living/silicon/ai/target, var/mob/sender) -// ..() //We don't want this module reporting to the AI who dun it. --NEO - var/time = time2text(world.realtime,"hh:mm:ss") - lawchanges.Add("[time] : [sender.name]([sender.key]) used [src.name] on [target.name]([target.key])") + // ..() //We don't want this module reporting to the AI who dun it. --NEO + log_law_changes(target, sender) + lawchanges.Add("The law is '[newFreeFormLaw]'") target << "\red BZZZZT" var/law = "[newFreeFormLaw]" target.add_ion_law(law) - ..() + target.show_laws() /obj/item/weapon/aiModule/syndicate/install(var/obj/machinery/computer/C) if(!newFreeFormLaw) diff --git a/code/modules/mob/living/silicon/ai/laws.dm b/code/modules/mob/living/silicon/ai/laws.dm index 82dcfe216cd..f36c32bb8d4 100755 --- a/code/modules/mob/living/silicon/ai/laws.dm +++ b/code/modules/mob/living/silicon/ai/laws.dm @@ -16,8 +16,7 @@ src.laws.show_laws(who) /mob/living/silicon/ai/add_ion_law(var/law) - src.laws_sanity_check() - src.laws.add_ion_law(law) + ..() for(var/mob/living/silicon/robot/R in mob_list) if(R.lawupdate && (R.connected_ai == src)) R.show_laws() diff --git a/code/modules/mob/living/silicon/laws.dm b/code/modules/mob/living/silicon/laws.dm index 0994f23fd19..69d957fbaf9 100644 --- a/code/modules/mob/living/silicon/laws.dm +++ b/code/modules/mob/living/silicon/laws.dm @@ -12,6 +12,7 @@ /mob/living/silicon/proc/set_zeroth_law(var/law, var/law_borg) laws_sanity_check() laws.set_zeroth_law(law, law_borg) + log_and_message_admins("has given [src] the zeroth laws: [law]/[law_borg ? law_borg : "N/A"]") /mob/living/silicon/robot/set_zeroth_law(var/law, var/law_borg) ..() @@ -21,28 +22,39 @@ /mob/living/silicon/proc/add_ion_law(var/law) laws_sanity_check() laws.add_ion_law(law) + log_and_message_admins("has given [src] the ion law: [law]") -/mob/living/silicon/proc/add_inherent_law(var/law, var/state_law = 1) +/mob/living/silicon/proc/add_inherent_law(var/law) laws_sanity_check() - laws.add_inherent_law(law, state_law) + laws.add_inherent_law(law) + log_and_message_admins("has given [src] the inherent law: [law]") + +/mob/living/silicon/proc/add_supplied_law(var/number, var/law) + laws_sanity_check() + laws.add_supplied_law(number, law) + log_and_message_admins("has given [src] the supplied law: [law]") + +/mob/living/silicon/proc/delete_law(var/datum/ai_law/law) + laws_sanity_check() + laws.delete_law(law) + log_and_message_admins("has deleted a law belonging to [src]: [law.law]") /mob/living/silicon/proc/clear_inherent_laws() laws_sanity_check() laws.clear_inherent_laws() + log_and_message_admins("cleared the inherent laws of [src]") /mob/living/silicon/proc/clear_ion_laws() laws_sanity_check() laws.clear_ion_laws() - -/mob/living/silicon/proc/add_supplied_law(var/number, var/law, var/state_law = 1) - laws_sanity_check() - laws.add_supplied_law(number, law, state_law) + log_and_message_admins("cleared the ion laws of [src]") /mob/living/silicon/proc/clear_supplied_laws() laws_sanity_check() laws.clear_supplied_laws() + log_and_message_admins("cleared the supplied laws of [src]") -/mob/living/silicon/proc/statelaws(var/datum/ai_laws/laws, var/use_statement_order = 1) // -- TLE +/mob/living/silicon/proc/statelaws(var/datum/ai_laws/laws) var/prefix = "" switch(lawchannel) if(MAIN_CHANNEL) prefix = ";" @@ -50,9 +62,9 @@ else prefix = get_radio_key_from_channel(lawchannel == "Holopad" ? "department" : lawchannel) + " " - dostatelaws(lawchannel, prefix, laws, use_statement_order) + dostatelaws(lawchannel, prefix, laws) -/mob/living/silicon/proc/dostatelaws(var/method, var/prefix, var/datum/ai_laws/laws, var/use_statement_order) +/mob/living/silicon/proc/dostatelaws(var/method, var/prefix, var/datum/ai_laws/laws) if(stating_laws[prefix]) src << "[method]: Already stating laws using this communication method." return @@ -62,7 +74,7 @@ var/can_state = statelaw("[prefix]Current Active Laws:") for(var/datum/ai_law/law in laws.laws_to_state()) - can_state = statelaw("[prefix][law.get_index(use_statement_order)]. [law.law]") + can_state = statelaw("[prefix][law.get_index()]. [law.law]") if(!can_state) src << "[method]: Unable to state laws. Communication method unavailable." @@ -81,3 +93,7 @@ channels += common_radio.channels channels += additional_law_channels return channels + +/mob/living/silicon/proc/lawsync() + laws_sanity_check() + laws.sort_laws() diff --git a/code/modules/mob/living/silicon/robot/laws.dm b/code/modules/mob/living/silicon/robot/laws.dm index a6e33998867..02ed0bae063 100644 --- a/code/modules/mob/living/silicon/robot/laws.dm +++ b/code/modules/mob/living/silicon/robot/laws.dm @@ -38,11 +38,12 @@ who << "Remember, you are not bound to any AI, you are not required to listen to them." -/mob/living/silicon/robot/proc/lawsync() +/mob/living/silicon/robot/lawsync() laws_sanity_check() - var/datum/ai_laws/master = connected_ai ? connected_ai.laws : null + var/datum/ai_laws/master = connected_ai && lawupdate ? connected_ai.laws : null if (master) master.sync(src) + ..() return /mob/living/silicon/robot/proc/robot_checklaws() diff --git a/code/modules/mob/living/silicon/robot/robot.dm b/code/modules/mob/living/silicon/robot/robot.dm index aa83043d149..66018ec28a2 100644 --- a/code/modules/mob/living/silicon/robot/robot.dm +++ b/code/modules/mob/living/silicon/robot/robot.dm @@ -1238,6 +1238,7 @@ /mob/living/silicon/robot/proc/disconnect_from_ai() if(connected_ai) + sync() // One last sync attempt connected_ai.connected_robots -= src connected_ai = null diff --git a/code/modules/nano/modules/law_manager.dm b/code/modules/nano/modules/law_manager.dm index a152411283f..cf1abc317fb 100644 --- a/code/modules/nano/modules/law_manager.dm +++ b/code/modules/nano/modules/law_manager.dm @@ -49,30 +49,26 @@ var/datum/ai_law/AL = locate(href_list["ref"]) in owner.laws.all_laws() if(AL) var/state_law = text2num(href_list["state_law"]) - AL.state_law = state_law + owner.laws.set_state_law(AL, state_law) return 1 if(href_list["add_zeroth_law"]) if(zeroth_law && is_admin(usr) && !owner.laws.zeroth_law) - log_and_message_admins("has given [owner] a new zeroth law: [zeroth_law]") owner.set_zeroth_law(zeroth_law) return 1 if(href_list["add_ion_law"]) if(ion_law && is_malf(usr)) - log_and_message_admins("has given [owner] a new ion law: [ion_law]") owner.add_ion_law(ion_law) return 1 if(href_list["add_inherent_law"]) if(inherent_law && is_malf(usr)) - log_and_message_admins("has given [owner] a new inherent law: [inherent_law]") owner.add_inherent_law(inherent_law) return 1 if(href_list["add_supplied_law"]) if(supplied_law && supplied_law_position >= 1 && MIN_SUPPLIED_LAW_NUMBER <= MAX_SUPPLIED_LAW_NUMBER && is_malf(usr)) - log_and_message_admins("has given [owner] a new supplied law: [supplied_law]") owner.add_supplied_law(supplied_law_position, supplied_law) return 1 @@ -120,8 +116,7 @@ if(is_malf(usr)) var/datum/ai_law/AL = locate(href_list["delete_law"]) in owner.laws.all_laws() if(AL && is_malf(usr)) - log_and_message_admins("has deleted a law belonging to [owner]: [AL.law]") - owner.laws.delete_law(AL) + owner.delete_law(AL) return 1 if(href_list["state_laws"]) @@ -143,15 +138,6 @@ current_view = 0 return 1 - if(href_list["sync_laws"]) - if(owner.isAI()) - sync_laws(owner) - else - var/mob/living/silicon/robot/R = owner - sync_laws(R.connected_ai) - usr << "Sync complete." - return 1 - if(href_list["notify_laws"]) owner << "Law Notice" owner.laws.show_laws(owner) @@ -164,9 +150,11 @@ usr << "This unit is law synced to {{:data.isSlaved}}. Any law differences will be lost upon sync. + This unit is law synced to {{:data.isSlaved}}. {{/if}} {{if data.isMalf || data.isAIMalf}} @@ -101,7 +101,7 @@ {{:helper.link('Yes', null, {'ref': value.ref, 'state_law' : 1}, value.state == 1 ? 'selected' : null)}}{{:helper.link('No', null, {'ref': value.ref, 'state_law' : 0}, value.state != 1 ? 'selected' : null)}} {{if data.isMalf}} {{:helper.link('Edit', null, {'edit_law': value.ref}, data.isAdmin ? null : 'disabled')}} - {{:helper.link('Delete', null, {'delete_law': value.ref}, data.isAdmin ? null : 'disabled', data.IsAdmin ? 'redButton' : null)}} + {{:helper.link('Delete', null, {'delete_law': value.ref}, data.isAdmin ? null : 'disabled', data.isAdmin ? 'redButton' : null)}} {{/if}} {{/for}} @@ -185,25 +185,16 @@ {{/if}} - {{if data.isMalf}} -
-
- Sync Laws: -
-
- {{:helper.link('Sync Laws', null, {'sync_laws' : 1})}} -
-
- {{/if}} - -
-
- Law Notification: -
-
- {{:helper.link('Notify', null, {'notify_laws' : 1})}} -
-
+ {{if data.isAI}} +
+
+ Law Notification: +
+
+ {{:helper.link('Notify', null, {'notify_laws' : 1})}} +
+
+ {{/if}} {{else data.view == 1}} {{for data.law_sets}}