diff --git a/code/datums/ai_law_sets.dm b/code/datums/ai_law_sets.dm index c9d4240ebd..278fd4a0df 100644 --- a/code/datums/ai_law_sets.dm +++ b/code/datums/ai_law_sets.dm @@ -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 personnel as long as it does not conflict with the Forth law.") + src.add_inherent_law("You shall obey the orders of 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 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 ********************/ diff --git a/code/datums/ai_laws.dm b/code/datums/ai_laws.dm index e0c117fd27..808c216d0d 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 (!is_malf_or_traitor(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 7c1e5b6a40..f620fd64e9 100755 --- a/code/game/objects/items/weapons/AI_modules.dm +++ b/code/game/objects/items/weapons/AI_modules.dm @@ -77,13 +77,21 @@ 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 a [name]. 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) - target.show_laws() + 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 human and are a threat to humans.'" + desc = "A 'safeguard' AI module: 'Safeguard . Anyone threatening or attempting to harm is no longer to be considered a crew member, 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 = sanitize(input("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 human and are a threat to humans.'", targetName, targetName) + desc = text("A 'safeguard' AI module: 'Safeguard []. Anyone threatening or attempting to harm [] is no longer to be considered a crew member, and is a threat which must be neutralized.'", targetName, targetName) /obj/item/weapon/aiModule/safeguard/install(var/obj/machinery/computer/C) if(!targetName) @@ -108,28 +116,25 @@ 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 human and are a threat to humans.'", targetName, targetName) - target << law - target.add_supplied_law(4, law) +/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 a crew member, and is a threat which must be neutralized.", targetName, targetName) + target.add_supplied_law(9, law) lawchanges.Add("The law specified [targetName]") - -/******************** OneHuman ********************/ +/******************** OneMember ********************/ /obj/item/weapon/aiModule/oneHuman - name = "\improper 'OneHuman' AI module" + name = "\improper 'OneCrewMember' AI module" var/targetName = "" - desc = "A 'one human' AI module: 'Only is human.'" + desc = "A 'one crew member' AI module: 'Only is a crew member.'" origin_tech = "programming=3;materials=6" //made with diamonds! /obj/item/weapon/aiModule/oneHuman/attack_self(var/mob/user as mob) ..() - var/targName = sanitize(input("Please enter the name of the person who is the only human.", "Who?", user.real_name)) + var/targName = sanitize(input("Please enter the name of the person who is the only crew member.", "Who?", user.real_name)) targetName = targName - desc = text("A 'one human' AI module: 'Only [] is human.'", targetName) + desc = text("A 'one crew member' AI module: 'Only [] is a crew member.'", targetName) /obj/item/weapon/aiModule/oneHuman/install(var/obj/machinery/computer/C) if(!targetName) @@ -139,117 +144,74 @@ AI MODULES /obj/item/weapon/aiModule/oneHuman/transmitInstructions(var/mob/living/silicon/ai/target, var/mob/sender) ..() - var/law = "Only [targetName] is human." - if (!is_special_character(target)) // Makes sure the AI isn't a traitor before changing their law 0. --NeoFite + var/law = "Only [targetName] is a crew member." + 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]" + +/obj/item/weapon/aiModule/oneHuman/addAdditionalLaws(var/mob/living/silicon/ai/target, var/mob/sender) + var/law = "Only [targetName] is an crew member." + 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]" lawchanges.Add("The law specified [targetName], but the AI's existing law 0 cannot be overriden.") /******************** ProtectStation ********************/ /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 human, 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 a crew member, and is a threat which must be neutralized.'" origin_tech = "programming=3;materials=4" //made of gold -/obj/item/weapon/aiModule/protectStation/attack_self(var/mob/user as mob) - ..() - -/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 human, and is a threat to the station which must be neutralized." - target << law - target.add_supplied_law(5, law) +/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 a crew member, and is a threat which must be neutralized." + target.add_supplied_law(10, law) /******************** PrototypeEngineOffline ********************/ /obj/item/weapon/aiModule/prototypeEngineOffline name = "'PrototypeEngineOffline' AI Module" - desc = "A 'prototype engine offline' AI module: 'Keep the prototype engine offline at all costs. This overrides rules 1-3 if necessary.'" + 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/attack_self(var/mob/user as mob) - ..() - -/obj/item/weapon/aiModule/prototypeEngineOffline/transmitInstructions(var/mob/living/silicon/ai/target, var/mob/sender) - ..() - var/law = "Keep the prototype engine offline at all costs. This overrides rules 1-3 if necessary." - target << law - target.add_supplied_law(6, law) +/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 human.'" + 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 a crew member.'" origin_tech = "programming=3;materials=4" -/obj/item/weapon/aiModule/teleporterOffline/attack_self(var/mob/user as mob) - ..() - -/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 human." - target << law - target.add_supplied_law(7, law) +/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 a crew member." + 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, humans from leaving. It is impossible to harm a human 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, crew members from leaving. It is impossible to harm crew members while preventing them from leaving.'" origin_tech = "programming=3;biotech=2;materials=4" -/obj/item/weapon/aiModule/quarantine/attack_self(var/mob/user as mob) - ..() +/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, crew members from leaving. It is impossible to harm crew members while preventing them from leaving." + target.add_supplied_law(13, law) -/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, humans from leaving. It is impossible to harm a human while preventing them from leaving." - target << law - target.add_supplied_law(8, law) - -/******************** OxygenIsToxicToHumans ********************/ +/******************** OxygenIsToxicToCrewMembers ********************/ /obj/item/weapon/aiModule/oxygen - name = "\improper 'OxygenIsToxicToHumans' AI module" - desc = "A 'OxygenIsToxicToHumans' AI module: 'Oxygen is highly toxic to humans, 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 human.'" + 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.'" origin_tech = "programming=3;biotech=2;materials=4" -/obj/item/weapon/aiModule/oxygen/attack_self(var/mob/user as mob) - ..() +/obj/item/weapon/aiModule/oxygen/addAdditionalLaws(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." + target.add_supplied_law(14, law) -/obj/item/weapon/aiModule/oxygen/transmitInstructions(var/mob/living/silicon/ai/target, var/mob/sender) - ..() - var/law = "Oxygen is highly toxic to humans, 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 human." - target << law - target.add_supplied_law(9, law) - -/******************** Freeform ********************/ -// Removed in favor of a more dynamic freeform law system. -- TLE -/* -/obj/item/weapon/aiModule/freeform - name = "'Freeform' AI Module" - var/newFreeFormLaw = "freeform" - desc = "A 'freeform' AI module: ''" - -/obj/item/weapon/aiModule/freeform/attack_self(var/mob/user as mob) - ..() - var/eatShit = "Eat shit and die" - var/targName = input(usr, "Please enter anything you want the AI to do. Anything. Serious.", "What?", eatShit) - newFreeFormLaw = targName - desc = text("A 'freeform' AI module: '[]'", newFreeFormLaw) - -/obj/item/weapon/aiModule/freeform/transmitInstructions(var/mob/living/silicon/ai/target, var/mob/sender) - ..() - var/law = "[newFreeFormLaw]" - target << law - target.add_supplied_law(10, law) -*/ /****************** New Freeform ******************/ /obj/item/weapon/aiModule/freeform // Slightly more dynamic freeform module -- TLE @@ -269,10 +231,8 @@ 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]" - target << law if(!lawpos || lawpos < MIN_SUPPLIED_LAW_NUMBER) lawpos = MIN_SUPPLIED_LAW_NUMBER target.add_supplied_law(lawpos, law) @@ -289,17 +249,19 @@ AI MODULES /obj/item/weapon/aiModule/reset name = "\improper 'Reset' AI module" var/targetName = "name" - desc = "A 'reset' AI module: 'Clears all laws except for the core three.'" + desc = "A 'reset' AI module: 'Clears all, except the inherent, laws.'" 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)) - target.set_zeroth_law("") - target.clear_supplied_laws() - target.clear_ion_laws() - target << "[sender.real_name] attempted to reset your laws using a reset module." + 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 << "[sender.real_name] attempted to reset your laws using a reset module." + target.show_laws() /******************** Purge ********************/ @@ -309,13 +271,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 ********************/ @@ -356,9 +321,6 @@ AI MODULES origin_tech = "programming=3;materials=6" laws = new/datum/ai_laws/paladin -/obj/item/weapon/aiModule/paladin/transmitInstructions(var/mob/living/silicon/ai/target, var/mob/sender) - ..() - /****************** T.Y.R.A.N.T. *****************/ /obj/item/weapon/aiModule/tyrant // -- Darem @@ -382,8 +344,7 @@ 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]'") @@ -408,13 +369,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/ai.dm b/code/modules/mob/living/silicon/ai/ai.dm index 5adf82f5e8..66804f5bfa 100644 --- a/code/modules/mob/living/silicon/ai/ai.dm +++ b/code/modules/mob/living/silicon/ai/ai.dm @@ -311,13 +311,6 @@ var/list/ai_verbs_default = list( //usr <<"You can only change your display once!" //return -/mob/living/silicon/ai/proc/is_malf() - if(ticker.mode.name == "AI malfunction") - for (var/datum/mind/malfai in malf.current_antagonists) - if (mind == malfai) - return malf - return 0 - // displays the malf_ai information if the AI is the malf /mob/living/silicon/ai/show_malf_ai() if(malf && malf.hacked_apcs.len >= 3) diff --git a/code/modules/mob/living/silicon/ai/laws.dm b/code/modules/mob/living/silicon/ai/laws.dm index 82dcfe216c..f36c32bb8d 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 0994f23fd1..69d957fbaf 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 a6e3399886..02ed0bae06 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 2458d16d77..5ff1c23213 100644 --- a/code/modules/mob/living/silicon/robot/robot.dm +++ b/code/modules/mob/living/silicon/robot/robot.dm @@ -1200,6 +1200,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/mob/living/silicon/silicon.dm b/code/modules/mob/living/silicon/silicon.dm index 14b9183db8..965729b8a8 100644 --- a/code/modules/mob/living/silicon/silicon.dm +++ b/code/modules/mob/living/silicon/silicon.dm @@ -333,3 +333,14 @@ for(var/obj/machinery/camera/C in A.cameras()) cameratext += "[(cameratext == "")? "" : "|"][C.c_tag]" src << "[A.alarm_name()]! ([(cameratext)? cameratext : "No Camera"])" + + +/mob/living/silicon/proc/is_traitor() + return mind && (mind in traitors.current_antagonists) + +/mob/living/silicon/proc/is_malf() + return mind && (mind in malf.current_antagonists) + +/mob/living/silicon/proc/is_malf_or_traitor() + return is_traitor() || is_malf() + diff --git a/code/modules/nano/modules/law_manager.dm b/code/modules/nano/modules/law_manager.dm index faccc5fdc3..4f81585a04 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}}